📄 gacl_api.php
字号:
if ($return_value == NULL) { $where_query[] = '(a.return_value IS NULL)'; } else { $where_query[] = '(a.return_value='. $this->db->quote($return_value) .')'; } } if (count($where_query) > 0) { $query .= ' WHERE '. implode (' AND ', $where_query); } return $this->db->GetCol($query); } /** * append_acl() * * Appends objects on to a specific ACL. * * @return bool TRUE if successful, FALSE otherwise. * * @param int ACL ID # * @param array Associative array, item={Section Value}, key={Array of Object Values} i.e. ["<Section Value>" => ["<Value 1>", "<Value 2>", "<Value 3>"], ...] * @param array Array of Group IDs * @param array Associative array, item={Section Value}, key={Array of Object Values} i.e. ["<Section Value>" => ["<Value 1>", "<Value 2>", "<Value 3>"], ...] * @param array Array of Group IDs * @param array Associative array, item={Section Value}, key={Array of Object Values} i.e. ["<Section Value>" => ["<Value 1>", "<Value 2>", "<Value 3>"], ...] */ function append_acl($acl_id, $aro_array=NULL, $aro_group_ids=NULL, $axo_array=NULL, $axo_group_ids=NULL, $aco_array=NULL) { $this->debug_text("append_acl(): ACL_ID: $acl_id"); $update = 0; if (empty($acl_id)) { $this->debug_text("append_acl(): No ACL_ID specified! ACL_ID: $acl_id"); return false; } //Grab ACL data. $acl_array = &$this->get_acl($acl_id); //Append each object type seperately. if (is_array($aro_array) AND count($aro_array) > 0) { $this->debug_text("append_acl(): Appending ARO's"); while (list($aro_section_value,$aro_value_array) = @each($aro_array)) { foreach ($aro_value_array as $aro_value) { if ( count($acl_array['aro'][$aro_section_value]) != 0 ) { if (!in_array($aro_value, $acl_array['aro'][$aro_section_value])) { $this->debug_text("append_acl(): ARO Section Value: $aro_section_value ARO VALUE: $aro_value"); $acl_array['aro'][$aro_section_value][] = $aro_value; $update=1; } else { $this->debug_text("append_acl(): Duplicate ARO, ignoring... "); } } else { //Array is empty so add this aro value. $acl_array['aro'][$aro_section_value][] = $aro_value; $update = 1; } } } } if (is_array($aro_group_ids) AND count($aro_group_ids) > 0) { $this->debug_text("append_acl(): Appending ARO_GROUP_ID's"); while (list(,$aro_group_id) = @each($aro_group_ids)) { if (!is_array($acl_array['aro_groups']) OR !in_array($aro_group_id, $acl_array['aro_groups'])) { $this->debug_text("append_acl(): ARO Group ID: $aro_group_id"); $acl_array['aro_groups'][] = $aro_group_id; $update = 1; } else { $this->debug_text("append_acl(): Duplicate ARO_Group_ID, ignoring... "); } } } if (is_array($axo_array) AND count($axo_array) > 0) { $this->debug_text("append_acl(): Appending AXO's"); while (list($axo_section_value,$axo_value_array) = @each($axo_array)) { foreach ($axo_value_array as $axo_value) { if (!in_array($axo_value, $acl_array['axo'][$axo_section_value])) { $this->debug_text("append_acl(): AXO Section Value: $axo_section_value AXO VALUE: $axo_value"); $acl_array['axo'][$axo_section_value][] = $axo_value; $update = 1; } else { $this->debug_text("append_acl(): Duplicate AXO, ignoring... "); } } } } if (is_array($axo_group_ids) AND count($axo_group_ids) > 0) { $this->debug_text("append_acl(): Appending AXO_GROUP_ID's"); while (list(,$axo_group_id) = @each($axo_group_ids)) { if (!is_array($acl_array['axo_groups']) OR !in_array($axo_group_id, $acl_array['axo_groups'])) { $this->debug_text("append_acl(): AXO Group ID: $axo_group_id"); $acl_array['axo_groups'][] = $axo_group_id; $update = 1; } else { $this->debug_text("append_acl(): Duplicate ARO_Group_ID, ignoring... "); } } } if (is_array($aco_array) AND count($aco_array) > 0) { $this->debug_text("append_acl(): Appending ACO's"); while (list($aco_section_value,$aco_value_array) = @each($aco_array)) { foreach ($aco_value_array as $aco_value) { if (!in_array($aco_value, $acl_array['aco'][$aco_section_value])) { $this->debug_text("append_acl(): ACO Section Value: $aco_section_value ACO VALUE: $aco_value"); $acl_array['aco'][$aco_section_value][] = $aco_value; $update = 1; } else { $this->debug_text("append_acl(): Duplicate ACO, ignoring... "); } } } } if ($update == 1) { $this->debug_text("append_acl(): Update flag set, updating ACL."); //function edit_acl($acl_id, $aco_array, $aro_array, $aro_group_ids=NULL, $axo_array=NULL, $axo_group_ids=NULL, $allow=1, $enabled=1, $return_value=NULL, $note=NULL) { return $this->edit_acl($acl_id, $acl_array['aco'], $acl_array['aro'], $acl_array['aro_groups'], $acl_array['axo'], $acl_array['axo_groups'], $acl_array['allow'], $acl_array['enabled'], $acl_array['return_value'], $acl_array['note']); } //Return true if everything is duplicate and no ACL id updated. $this->debug_text("append_acl(): Update flag not set, NOT updating ACL."); return true; } /** * shift_acl() * * Opposite of append_acl(). Removes objects from a specific ACL. (named after PHP's array_shift()) * * @return bool TRUE if successful, FALSE otherwise. * * @param int ACL ID # * @param array Associative array, item={Section Value}, key={Array of Object Values} i.e. ["<Section Value>" => ["<Value 1>", "<Value 2>", "<Value 3>"], ...] * @param array Array of Group IDs * @param array Associative array, item={Section Value}, key={Array of Object Values} i.e. ["<Section Value>" => ["<Value 1>", "<Value 2>", "<Value 3>"], ...] * @param array Array of Group IDs * @param array Associative array, item={Section Value}, key={Array of Object Values} i.e. ["<Section Value>" => ["<Value 1>", "<Value 2>", "<Value 3>"], ...] */ function shift_acl($acl_id, $aro_array=NULL, $aro_group_ids=NULL, $axo_array=NULL, $axo_group_ids=NULL, $aco_array=NULL) { $this->debug_text("shift_acl(): ACL_ID: $acl_id"); $update = 0; if (empty($acl_id)) { $this->debug_text("shift_acl(): No ACL_ID specified! ACL_ID: $acl_id"); return false; } //Grab ACL data. $acl_array = &$this->get_acl($acl_id); //showarray($acl_array); //Remove each object type seperately. if (is_array($aro_array) AND count($aro_array) > 0) { $this->debug_text("shift_acl(): Removing ARO's"); while (list($aro_section_value,$aro_value_array) = @each($aro_array)) { foreach ($aro_value_array as $aro_value) { $this->debug_text("shift_acl(): ARO Section Value: $aro_section_value ARO VALUE: $aro_value"); //Only search if aro array contains data. if ( count($acl_array['aro'][$aro_section_value]) != 0 ) { $aro_key = array_search($aro_value, $acl_array['aro'][$aro_section_value]); if ($aro_key !== FALSE) { $this->debug_text("shift_acl(): Removing ARO. ($aro_key)"); unset($acl_array['aro'][$aro_section_value][$aro_key]); $update = 1; } else { $this->debug_text("shift_acl(): ARO doesn't exist, can't remove it."); } } } } } if (is_array($aro_group_ids) AND count($aro_group_ids) > 0) { $this->debug_text("shift_acl(): Removing ARO_GROUP_ID's"); while (list(,$aro_group_id) = @each($aro_group_ids)) { $this->debug_text("shift_acl(): ARO Group ID: $aro_group_id"); $aro_group_key = array_search($aro_group_id, $acl_array['aro_groups']); if ($aro_group_key !== FALSE) { $this->debug_text("shift_acl(): Removing ARO Group. ($aro_group_key)"); unset($acl_array['aro_groups'][$aro_group_key]); $update = 1; } else { $this->debug_text("shift_acl(): ARO Group doesn't exist, can't remove it."); } } } if (is_array($axo_array) AND count($axo_array) > 0) { $this->debug_text("shift_acl(): Removing AXO's"); while (list($axo_section_value,$axo_value_array) = @each($axo_array)) { foreach ($axo_value_array as $axo_value) { $this->debug_text("shift_acl(): AXO Section Value: $axo_section_value AXO VALUE: $axo_value"); $axo_key = array_search($axo_value, $acl_array['axo'][$axo_section_value]); if ($axo_key !== FALSE) { $this->debug_text("shift_acl(): Removing AXO. ($axo_key)"); unset($acl_array['axo'][$axo_section_value][$axo_key]); $update = 1; } else { $this->debug_text("shift_acl(): AXO doesn't exist, can't remove it."); } } } } if (is_array($axo_group_ids) AND count($axo_group_ids) > 0) { $this->debug_text("shift_acl(): Removing AXO_GROUP_ID's"); while (list(,$axo_group_id) = @each($axo_group_ids)) { $this->debug_text("shift_acl(): AXO Group ID: $axo_group_id"); $axo_group_key = array_search($axo_group_id, $acl_array['axo_groups']); if ($axo_group_key !== FALSE) { $this->debug_text("shift_acl(): Removing AXO Group. ($axo_group_key)"); unset($acl_array['axo_groups'][$axo_group_key]); $update = 1; } else { $this->debug_text("shift_acl(): AXO Group doesn't exist, can't remove it."); } } } if (is_array($aco_array) AND count($aco_array) > 0) { $this->debug_text("shift_acl(): Removing ACO's"); while (list($aco_section_value,$aco_value_array) = @each($aco_array)) { foreach ($aco_value_array as $aco_value) { $this->debug_text("shift_acl(): ACO Section Value: $aco_section_value ACO VALUE: $aco_value"); $aco_key = array_search($aco_value, $acl_array['aco'][$aco_section_value]); if ($aco_key !== FALSE) { $this->debug_text("shift_acl(): Removing ACO. ($aco_key)"); unset($acl_array['aco'][$aco_section_value][$aco_key]); $update = 1; } else { $this->debug_text("shift_acl(): ACO doesn't exist, can't remove it."); } } } } if ($update == 1) { //We know something was changed, so lets see if no ACO's or no ARO's are left assigned to this ACL, if so, delete the ACL completely. //$this->showarray($acl_array); $this->debug_text("shift_acl(): ACOs: ". $this->count_all($acl_array['aco']) ." AROs: ".$this->count_all($acl_array['aro']).""); if ( $this->count_all($acl_array['aco']) == 0 OR ( $this->count_all($acl_array['aro']) == 0 AND ( $this->count_all($acl_array['axo']) == 0 OR $acl_array['axo'] == FALSE) AND (count($acl_array['aro_groups']) == 0 OR $acl_array['aro_groups'] == FALSE) AND (count($acl_array['axo_groups']) == 0 OR $acl_array['axo_groups'] == FALSE) ) ) { $this->debug_text("shift_acl(): No ACOs or ( AROs AND AXOs AND ARO Groups AND AXO Groups) left assigned to this ACL (ID: $acl_id), deleting ACL."); return $this->del_acl($acl_id); } $this->debug_text("shift_acl(): Update flag set, updating ACL."); return $this->edit_acl($acl_id, $acl_array['aco'], $acl_array['aro'], $acl_array['aro_groups'], $acl_array['axo'], $acl_array['axo_groups'], $acl_array['allow'], $acl_array['enabled'], $acl_array['return_value'], $acl_array['note']); } //Return true if everything is duplicate and no ACL id updated. $this->debug_text("shift_acl(): Update flag not set, NOT updating ACL."); return true; } /** * get_acl() * * Grabs ACL data. * * @return mixed bool FALSE if not found, or Associative Array with the following items: * * - 'aco' => Associative array, item={Section Value}, key={Array of Object Values} i.e. ["<Section Value>" => ["<Value 1>", "<Value 2>", "<Value 3>"], ...] * - 'aro' => Associative array, item={Section Value}, key={Array of Object Values} i.e. ["<Section Value>" => ["<Value 1>", "<Value 2>", "<Value 3>"], ...] * - 'axo' => Associative array, item={Section Value}, key={Array of Object Values} i.e. ["<Section Value>" => ["<Value 1>", "<Value 2>", "<Value 3>"], ...] * - 'aro_groups' => Array of Group IDs * - 'axo_groups' => Array of Group IDs * - 'acl_id' => int ACL ID # * - 'allow' => int Allow flag * - 'enabled' => int Enabled flag * - 'return_value' => string Return Value * - 'note' => string Note * * @param int ACL ID # */ function get_acl($acl_id) { $this->debug_text("get_acl(): ACL_ID: $acl_id"); if (empty($acl_id)) { $this->debug_text("get_acl(): No ACL_ID specified! ACL_ID: $acl_id"); return false; } $acl_id = (int) $acl_id; //Grab ACL information $query = "select id, allow, enabled, return_value, note from ".$this->_db_table_prefix."acl where id = ".$acl_id.""; $acl_row = $this->db->GetRow($query); // return false if not found if (!$acl_row) { $this->debug_text("get_acl(): No ACL found for that ID! ACL_ID: $acl_id"); return false; } list($retarr['acl_id'], $retarr['allow'], $retarr['enabled'], $retarr['return_value'], $retarr['note']) = $acl_row; //Grab selected ACO's $query = "select distinct a.section_value, a.value, c.name, b.name from ".$this->_db_table_prefix."aco_map a, ".$this->_db_table_prefix."aco b, ".$this->_db_table_prefix."aco_sections c where ( a.section_value=b.section_value AND a.value = b.value) AND b.section_value=c.value AND a.acl_id = $acl_id"; $rs = $this->db->Execute($query); $rows = $rs->GetRows(); $retarr['aco'] = array(); while (list(,$row) = @each($rows)) { list($section_value, $value, $section, $aco) = $row; $this->debug_text("Section Value: $section_value Value: $value Section: $section ACO: $aco"); $retarr['aco'][$section_value][] = $value; } //showarray($aco); //Grab selected ARO's $query = "select distinct a.section_value, a.value, c.name, b.name from ".$this->_db_table_prefix."aro_map a, ".$this->_db_table_prefix."aro b, ".$this->_db_table_prefix."aro_sections c where ( a.section_value=b.section_value AND a.value = b.value) AND b.section_value=c.value AND a.acl_id = $acl_id"; $rs = $this->db->Execute($query); $rows = $rs->GetRows(); $retarr['aro'] = array(); while (list(,$row) = @each($rows)) { list($section_value, $value, $section, $aro) = $row; $this->debug_text("Section Value: $section_value Value: $value Section: $section ARO: $aro"); $retarr['aro'][$section_value][] = $value; } //showarray($options_aro); //Grab selected AXO's $query = "select distinct a.section_value, a.value, c.name, b.name from ".$this->_db_table_prefix."axo_map a, ".$this->_db_table_prefix."axo b, ".$this->_db_table_prefix."axo_sections c where ( a.section_value=b.section_value AND a.value = b.value) AND b.section_value=c.value AND a.acl_id = $acl_id"; $rs = $this->db->Execute($query); $rows = $rs->GetRows(); $retarr['axo'] = array(); while (list(,$row) = @each($rows)) { list($section_value, $value, $section, $axo) = $row; $this->debug_text("Section Value: $section_value Value: $value Section: $section AXO: $axo"); $retarr['axo'][$section_value][] = $value; } //showarray($options_aro); //Grab selected ARO groups. $retarr['aro_groups'] = array(); $query = "select distinct group_id from ".$this->_db_table_prefix."aro_groups_map where acl_id = $acl_id"; $retarr['aro_groups'] = $this->db->GetCol($query); //showarray($selected_groups); //Grab selected AXO groups. $retarr['axo_groups'] = array(); $query = "select distinct group_id from ".$this->_db_table_prefix."axo_groups_map where acl_id = $acl_id"; $retarr['axo_groups'] = $this->db->GetCol($query); //showarray($selected_groups); return $retarr; } /** * is_conflicting_acl() * * Checks for conflicts when adding a specific ACL. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -