📄 gacl_api.php
字号:
return false; } if (count($aro_array) == 0 AND count($aro_group_ids) == 0) { $this->debug_text("edit_acl(): Must select at least one Access Request Object or Group"); return false; } if (empty($allow)) { $allow=0; } if (empty($enabled)) { $enabled=0; } //if ($this->add_acl($aco_array, $aro_array, $group_ids, $allow, $enabled, $acl_id)) { if ($this->add_acl($aco_array, $aro_array, $aro_group_ids, $axo_array, $axo_group_ids, $allow, $enabled, $return_value, $note, $section_value, $acl_id)) { return true; } else { $this->debug_text("edit_acl(): error in add_acl()"); return false; } } /** * del_acl() * * Deletes a given ACL * * @return bool Returns TRUE if successful, FALSE otherwise. * * @param int ACL ID # to delete */ function del_acl($acl_id) { $this->debug_text("del_acl(): ID: $acl_id"); if (empty($acl_id) ) { $this->debug_text("del_acl(): ACL_ID ($acl_id) is empty, this is required"); return false; } $this->db->BeginTrans(); // Delete all mappings to the ACL first foreach (array('aco_map', 'aro_map', 'axo_map', 'aro_groups_map', 'axo_groups_map') as $map) { $query = 'DELETE FROM '. $this->_db_table_prefix . $map .' WHERE acl_id='. (int) $acl_id; $rs = $this->db->Execute($query); if (!is_object($rs)) { $this->debug_db('del_acl'); $this->db->RollBackTrans(); return false; } } // Delete the ACL $query = 'DELETE FROM '. $this->_db_table_prefix .'acl WHERE id='. (int) $acl_id; $this->debug_text('delete query: '. $query); $rs = $this->db->Execute($query); if (!is_object($rs)) { $this->debug_db('del_acl'); $this->db->RollBackTrans(); return false; } $this->debug_text("del_acl(): deleted ACL ID: $acl_id"); $this->db->CommitTrans(); if ($this->_caching == TRUE AND $this->_force_cache_expire == TRUE) { //Expire all cache. $this->Cache_Lite->clean('default'); } return TRUE; } /* * * Groups * */ /** * sort_groups() * * Grabs all the groups from the database doing preliminary grouping by parent * * @return array Returns 2-Dimensional array: $array[<parent_id>][<group_id>] = <group_name> * * @param string Group Type, either 'ARO' or 'AXO' */ function sort_groups($group_type='ARO') { switch(strtolower(trim($group_type))) { case 'axo': $table = $this->_db_table_prefix .'axo_groups'; break; default: $table = $this->_db_table_prefix .'aro_groups'; break; } //Grab all groups from the database. $query = 'SELECT id, parent_id, name FROM '. $table .' ORDER BY parent_id, name'; $rs = $this->db->Execute($query); if (!is_object($rs)) { $this->debug_db('sort_groups'); return false; } /* * Save groups in an array sorted by parent. Should be make it easier for later on. */ $sorted_groups = array(); while ($row = $rs->FetchRow()) { $id = &$row[0]; $parent_id = &$row[1]; $name = &$row[2]; $sorted_groups[$parent_id][$id] = $name; } return $sorted_groups; } /** * format_groups() * * Takes the array returned by sort_groups() and formats for human * consumption. Recursively calls itself to produce the desired output. * * @return array Array of formatted text, ordered by group id, formatted according to $type * * @param array Output from gacl_api->sorted_groups($group_type) * @param array Output type desired, either 'TEXT', 'TEXT_ASSOC', 'HTML', 'ARRAY' or 'ASSOC' * @param int Root of tree to produce * @param int Current level of depth * @param array Pass the current formatted groups object for appending via recursion. */ function format_groups($sorted_groups, $type='TEXT', $root_id=0, $level=0, $formatted_groups=NULL) { if ( !is_array ($sorted_groups) ) { return FALSE; } if ( !is_array ($formatted_groups) ) { $formatted_groups = array (); } $type = strtoupper($type); //$this->showarray($formatted_groups); //while (list($id,$name) = @each($sorted_groups[$root_id])) { if (isset($sorted_groups[$root_id])) { $temp = array_keys( $sorted_groups[$root_id] ); $last_id = end( $temp ); foreach ($sorted_groups[$root_id] as $id => $name) { switch ($type) { case 'TEXT': case 'TEXT_ASSOC': /* * Formatting optimized for TEXT (combo box) output. */ if ( is_numeric($level) ) { $level = str_repeat(' ', $level); } if ( strlen($level) >= 8 ) { if ( $id == $last_id ) { $spacing = substr($level, 0, -8) .'\'- '; $level = substr($level, 0, -8) .' '; } else { $spacing = substr($level, 0, -8) .'|- '; } } else { $spacing = $level; } $next = $level .'| '; if ($type == 'TEXT_ASSOC') { $formatted_groups[] = array( 'value'=>$id, 'text'=>$spacing.$name ); } else { $formatted_groups[$id] = $spacing.$name; } break; case 'HTML': /* * Formatting optimized for HTML (tables) output. */ $width = $level * 12; $spacing = "<img src=\"images/blank.png\" width=\"$width\" height=\"0\" alt=\"\" />"; $next = $level + 1; $formatted_groups[$id] = $spacing." ".$name; break; case 'ARRAY': $next = $level; $formatted_groups[$id] = $name; break; case 'ASSOC': /* * Formatting optimized for HTML: <option value="value">text</option>. */ $next = $level; $formatted_groups[] = array( 'value'=>$id, 'text'=>$name, 'level'=>$level ); break; default: return FALSE; } /* * Recurse if we can. */ //if (isset($sorted_groups[$id]) AND count($sorted_groups[$id]) > 0) { if (isset($sorted_groups[$id]) ) { //$this->debug_text("format_groups(): Recursing! Level: $level"); $formatted_groups = $this->format_groups($sorted_groups, $type, $id, $next, $formatted_groups); } else { //$this->debug_text("format_groups(): Found last branch!"); } } } //$this->debug_text("format_groups(): Returning final array."); return $formatted_groups; } /** * get_group_id() * * Gets the group_id given the name or value. * * Will only return one group id, so if there are duplicate names, it will return false. * * @return int Returns Group ID if found and Group ID is unique in database, otherwise, returns FALSE * * @param string Group Value * @param string Group Name * @param string Group Type, either 'ARO' or 'AXO' */ function get_group_id($value = NULL, $name = NULL, $group_type = 'ARO') { $this->debug_text("get_group_id(): Value: $value, Name: $name, Type: $group_type" ); switch(strtolower(trim($group_type))) { case 'axo': $table = $this->_db_table_prefix .'axo_groups'; break; default: $table = $this->_db_table_prefix .'aro_groups'; break; } $name = trim($name); $value = trim($value); if (empty($name) AND $value === '') { $this->debug_text("get_group_id(): name and value, at least one is required"); return false; } $query = 'SELECT id FROM '. $table .' WHERE '; if ($value !== '') { $query .= ' value='. $this->db->quote($value); } else { $query .= ' name='. $this->db->quote($name); } $this->db->setQuery( $query ); $rows = $this->db->loadResultArray(); if ($this->db->getErrorNum()) { $this->debug_db('get_group_id'); return false; } $row_count = count( $rows ); if ($row_count > 1) { $this->debug_text("get_group_id(): Returned $row_count rows, can only return one. Please make your names unique."); return false; } if ($row_count == 0) { $this->debug_text("get_group_id(): Returned $row_count rows"); return false; } //Return the ID. return $rows[0]; } /** * get_group_children() * * Gets a groups child IDs * * @return array Array of Child ID's of the referenced group * * @param int Group ID # * @param int Group Type, either 'ARO' or 'AXO' * @param string Either 'RECURSE' or 'NO_RECURSE', to recurse while fetching group children. */ function get_group_children($group_id, $group_type = 'ARO', $recurse = 'NO_RECURSE') { $this->debug_text("get_group_children(): Group_ID: $group_id Group Type: $group_type Recurse: $recurse"); switch (strtolower(trim($group_type))) { case 'axo': $group_type = 'axo'; $table = $this->_db_table_prefix .'axo_groups'; break; default: $group_type = 'aro'; $table = $this->_db_table_prefix .'aro_groups'; } if (empty($group_id)) { $this->debug_text("get_group_children(): ID ($group_id) is empty, this is required"); return FALSE; } $query = ' SELECT g1.id FROM '. $table .' g1'; //FIXME-mikeb: Why is group_id in quotes? switch (strtoupper($recurse)) { case 'RECURSE': $query .= ' LEFT JOIN '. $table .' g2 ON g2.lft<g1.lft AND g2.rgt>g1.rgt WHERE g2.id='. (int) $group_id; break; default: $query .= ' WHERE g1.parent_id='. (int) $group_id; } $query .= ' ORDER BY g1.value'; return $this->db->GetCol($query); } /** * get_group_data() * * Gets the group data given the GROUP_ID. * * @return array Returns numerically indexed array with the following columns: * - array[0] = (int) Group ID # * - array[1] = (int) Parent Group ID # * - array[2] = (string) Group Value * - array[3] = (string) Group Name * - array[4] = (int) lft MPTT Value * - array[5] = (int) rgt MPTT Value * * @param int Group ID # * @param string Group Type, either 'ARO' or 'AXO' */ function get_group_data($group_id, $group_type = 'ARO') { $this->debug_text("get_group_data(): Group_ID: $group_id Group Type: $group_type"); switch(strtolower(trim($group_type))) { case 'axo': $group_type = 'axo'; $table = $this->_db_table_prefix .'axo_groups'; break; default: $group_type = 'aro'; $table = $this->_db_table_prefix .'aro_groups'; break; } if (empty($group_id) ) { $this->debug_text("get_group_data(): ID ($group_id) is empty, this is required"); return false; } $query = 'SELECT id, parent_id, value, name, lft, rgt FROM '. $table .' WHERE id='. (int) $group_id; //$rs = $this->db->Execute($query); $row = $this->db->GetRow($query); if ($row) { return $row;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -