|
se 'aro':
$object_type = 'aro';
$group_table = $this->_db_table_prefix .'aro_groups';
$map_table = $this->_db_table_prefix .'groups_aro_map';
break;
default:
$this->debug_text('get_object_groups(): Invalid Object Type: '. $object_type);
return FALSE;
}
if (empty($object_id)) {
$this->debug_text('get_object_groups(): Object ID: ('. $object_id .') is empty, this is required');
return FALSE;
}
if (strtoupper($option) == 'RECURSE') {
$query = '
SELECT DISTINCT g.id AS group_id
FROM '. $map_table .' gm
LEFT JOIN '. $group_table .' g1 ON g1.id=gm.group_id
LEFT JOIN '. $group_table .' g ON g.lft<=g1.lft AND g.rgt>=g1.rgt';
} else {
$query = '
SELECT gm.group_id
FROM '. $map_table .' gm';
}
$query .= '
WHERE gm.'. $object_type .'_id='. (int) $object_id;
$rs = $this->db->Execute($query);
if (!is_object($rs)) {
$this->debug_db('get_object_groups');
return FALSE;
}
$retarr = array();
while ($row = $rs->FetchRow()) {
$retarr[] = $row[0];
}
return $retarr;
}
/**
* add_object()
*
* Inserts a new object
*
* @return int Returns the ID # of the new object if successful, FALSE otherwise
*
* @param string Object Section Value
* @param string Object Name
* @param string Object Value
* @param int Display Order
* @param int Hidden Flag, either 1 to hide, or 0 to show.
* @param string Object Type, either 'ACO', 'ARO', or 'AXO'
*/
function add_object($section_value, $name, $value=0, $order=0, $hidden=0, $object_type=NULL) {
switch(strtolower(trim($object_type))) {
case 'aco':
$object_type = 'aco';
$table = $this->_db_table_prefix .'aco';
$object_sections_table = $this->_db_table_prefix .'aco_sections';
break;
case 'aro':
$object_type = 'aro';
$table = $this->_db_table_prefix .'aro';
$object_sections_table = $this->_db_table_prefix .'aro_sections';
break;
case 'axo':
$object_type = 'axo';
$table = $this->_db_table_prefix .'axo';
$object_sections_table = $this->_db_table_prefix .'axo_sections';
break;
default:
$this->debug_text('add_object(): Invalid Object Type: '. $object_type);
return FALSE;
}
$this->debug_text("add_object(): Section Value: $section_value Value: $value Order: $order Name: $name Object Type: $object_type");
$section_value = trim($section_value);
$name = trim($name);
$value = trim($value);
$order = (int) $order;
$hidden = (int) $hidden;
if ($order == NULL OR $order == '') {
$order = 0;
}
if (empty($name) OR empty($section_value) ) {
$this->debug_text("add_object(): name ($name) OR section value ($section_value) is empty, this is required");
return false;
}
if (strlen($name) >= 255 OR strlen($value) >= 230 ) {
$this->debug_text("add_object(): name ($name) OR value ($value) is too long.");
return false;
}
if (empty($object_type) ) {
$this->debug_text("add_object(): Object Type ($object_type) is empty, this is required");
return false;
}
// Test to see if the section is invalid or object already exists.
$query = '
SELECT CASE WHEN o.id IS NULL THEN 0 ELSE 1 END AS object_exists
FROM '. $object_sections_table .' s
LEFT JOIN '. $table .' o ON (s.value=o.section_value AND o.value='. $this->db->quote($value) .')
WHERE s.value='. $this->db->quote($section_value);
$rs = $this->db->Execute($query);
if (!is_object($rs)) {
$this->debug_db('add_object');
return FALSE;
}
if ($rs->RecordCount() != 1) {
// Section is invalid
$this->debug_text("add_object(): Section Value: $section_value Object Type ($object_type) does not exist, this is required");
return false;
}
$row = $rs->FetchRow();
if ($row[0] == 1) {
//Object is already created.
return true;
}
$insert_id = $this->db->GenID($table . '_seq', $this->_defaultGenID( $table ));
$query = "INSERT INTO $table (id,section_value,value,order_value,name,hidden) " .
"VALUES(". (int) $insert_id . "," . $this->db->quote($section_value) . "," .
$this->db->quote($value) . ",$order," . $this->db->quote($name) . ",$hidden)";
$rs = $this->db->Execute($query);
if (!is_object($rs)) {
$this->debug_db('add_object');
return false;
}
// Joomla/MySQL
$insert_id = $this->db->insertid();
$this->debug_text("add_object(): Added object as ID: $insert_id");
return $insert_id;
}
/**
* edit_object()
*
* Edits a given Object
*
* @return bool Returns TRUE if successful, FALSE otherwise
*
* @param int Object ID #
* @param string Object Section Value
* @param string Object Name
* @param string Object Value
* @param int Display Order
* @param int Hidden Flag, either 1 to hide, or 0 to show
* @param string Object Type, either 'ACO', 'ARO', or 'AXO'
*/
function edit_object($object_id, $section_value, $name, $value=0, $order=0, $hidden=0, $object_type=NULL) {
switch(strtolower(trim($object_type))) {
case 'aco':
$object_type = 'aco';
$table = $this->_db_table_prefix .'aco';
$object_map_table = $this->_db_table_prefix .'aco_map';
break;
case 'aro':
$object_type = 'aro';
$table = $this->_db_table_prefix .'aro';
$object_map_table = $this->_db_table_prefix .'aro_map';
break;
case 'axo':
$object_type = 'axo';
$table = $this->_db_table_prefix .'axo';
$object_map_table = $this->_db_table_prefix .'axo_map';
break;
}
$this->debug_text("edit_object(): ID: $object_id Section Value: $section_value Value: $value Order: $order Name: $name Object Type: $object_type");
$object_id = (int) $object_id;
$section_value = trim($section_value);
$name = trim($name);
$value = trim($value);
$order = (int) $order;
$hidden = (int) $hidden;
if (empty($object_id) OR empty($section_value) ) {
$this->debug_text("edit_object(): Object ID ($object_id) OR Section Value ($section_value) is empty, this is required");
return false;
}
if (empty($name) ) {
$this->debug_text("edit_object(): name ($name) is empty, this is required");
return false;
}
if (empty($object_type) ) {
$this->debug_text("edit_object(): Object Type ($object_type) is empty, this is required");
return false;
}
$this->db->BeginTrans();
//Get old value incase it changed, before we do the update.
$query = 'SELECT value, section_value FROM '. $table .' WHERE id='. $object_id;
$old = $this->db->GetRow($query);
$query = '
UPDATE '. $table .'
SET section_value='. $this->db->quote($section_value) .',
value='. $this->db->quote($value) .',
order_value='. $order .',
name='. $this->db->quote($name) .',
hidden='. $hidden .'
WHERE id='. $object_id;
$rs = $this->db->Execute($query);
if (!is_object($rs)) {
$this->debug_db('edit_object');
$this->db->RollbackTrans();
return false;
}
$this->debug_text('edit_object(): Modified '. strtoupper($object_type) .' ID: '. $object_id);
if ($old[0] != $value OR $old[1] != $section_value) {
$this->debug_text("edit_object(): Value OR Section Value Changed, update other tables.");
$query = '
UPDATE '. $object_map_table .'
SET value='. $this->db->quote($value) .',
section_value='. $this->db->quote($section_value) .'
WHERE section_value='. $this->db->quote($old[1]) .'
AND value='. $this->db->quote($old[0]);
$rs = $this->db->Execute($query);
if (!is_object($rs)) {
$this->debug_db('edit_object');
$this->db->RollbackTrans();
return FALSE;
}
$this->debug_text ('edit_object(): Modified Map Value: '. $value .' Section Value: '. $section_value);
}
$this->db->CommitTrans();
return TRUE;
}
/**
* del_object()
*
* Deletes a given Object and, if instructed to do so, erase all referencing objects
*
* ERASE feature by: Martino Piccinato
*
* @return bool Returns TRUE if successful, FALSE otherwise.
*
* @param int Object ID #
* @param string Object Type, either 'ACO', 'ARO', or 'AXO'
* @param bool Erases all referencing objects if TRUE, leaves them alone otherwise.
*/
function del_object($object_id, $object_type=NULL, $erase=FALSE) {
switch(strtolower(trim($object_type))) {
case 'aco':
$object_type = 'aco';
$table = $this->_db_table_prefix .'aco';
$object_map_table = $this->_db_table_prefix .'aco_map';
break;
case 'aro':
$object_type = 'aro';
$table = $this->_db_table_prefix .'aro';
$object_map_table = $this->_db_table_prefix .'aro_map';
$groups_map_table = $this->_db_table_prefix .'aro_groups_map';
$object_group_table = $this->_db_table_prefix .'groups_aro_map';
break;
case 'axo':
$object_type = 'axo';
$table = $this->_db_table_prefix .'axo';
$object_map_table = $this->_db_table_prefix .'axo_map';
$groups_map_table = $this->_db_table_prefix .'axo_groups_map';
$object_group_table = $this->_db_table_prefix .'groups_axo_map';
break;
default:
$this->debug_text('del_object(): Invalid Object Type: '. $object_type);
return FALSE;
}
$this->debug_text("del_object(): ID: $object_id Object Type: $object_type, Erase all referencing objects: $erase");
if (empty($object_id) ) {
$this->debug_text("del_object(): Object ID ($object_id) is empty, this is required");
return false;
}
if (empty($object_type) ) {
$this->debug_text("del_object(): Object Type ($object_type) is empty, this is required");
return false;
}
// sanitise input
$object_id = (int) $object_id;
$this->db->BeginTrans();
// Get Object section_value/value (needed to look for referencing objects)
$query = 'SELECT section_value,value FROM '. $table .' WHERE id='. $object_id;
$object = $this->db->GetRow($query);
if (empty($object)) {
$this->debug_text('del_object(): The specified object ('. strtoupper($object_type) .' ID: '. $object_id .') could not be found.');
$this->db->RollbackTrans();
return FALSE;
}
$section_value = $this->db->quote( $object[0] );
$value = $this->db->quote( $object[1] );
// Get ids of acl referencing the Object (if any)
$query = "SELECT acl_id FROM $object_map_table WHERE value=$value AND section_value=$section_value";
$acl_ids = $this->db->GetCol($query);
if ($erase) {
// We were asked to erase all acl referencing it
$this->debug_text("del_object(): Erase was set to TRUE, delete all referencing objects");
if ($object_type == "aro" OR $object_type == "axo") {
// The object can be referenced in groups_X_map tables
// in the future this branching may become useless because
// ACO might me "groupable" too
// Get rid of groups_map referencing the Object
$query = 'DELETE FROM '. $object_group_table .' WHERE '. $object_type .'_id='. $object_id;
$rs = $this->db->Execute($query);
if (!is_object($rs)) {
$this->debug_db('edit_object');
$this->db->RollBackTrans();
return false;
}
}
if (!empty($acl_ids)) {
//There are acls actually referencing the object
if ($object_type == 'aco') {
// I know it's extremely dangerous but
// if asked to really erase an ACO
// we should delete all acl referencing it
// (and relative maps)
// Do this below this branching
// where it uses $orphan_acl_ids as
// the array of the "orphaned" acl
// in this case all referenced acl are
// orhpaned acl
$orphan_acl_ids = $acl_ids;
} else {
// The object is not an ACO and might be referenced
// in still valid acls regarding also other object.
// In these cases the acl MUST NOT be deleted
// Get rid of $object_id map referencing erased objects
$query = "DELETE FROM $object_map_table WHERE section_value=$section_value AND value=$value";
$this->db->Execute($query);
if (!is_object($rs)) {
$this->debug_db('edit_object');
$this->db->RollBackTrans();
return false;
}
// Find the "orphaned" acl. I mean acl referencing the erased Object (map)
// not referenced anymore by other objects
$sql_acl_ids = implode(",", $acl_ids);
$query = '
SELECT a.id
FROM '. $this->_db_table_prefix .'acl a
LEFT JOIN '. $object_map_table .' b ON a.id=b.acl_id
LEFT JOIN '. $groups_map_table .' c ON a.id=c.acl_id
WHERE b.value IS NULL
AND b.section_value IS NULL
AND c.group_id IS NULL
AND a.id in ('. $sql_acl_ids .')';
$orphan_acl_ids = $this->db->GetCol($query);
} // End of else section of "if ($object_type == "aco")"
if ($orphan_acl_ids) {
// If there are orphaned acls get rid of them
foreach ($orphan_acl_ids as $acl) {
$this->del_acl($acl);
}
}
} // End of if ($acl_ids)
// Finally delete the Object itself
$query = "DELETE FROM $table WHERE id=$object_id";
$rs = $this->db->Execute($query);
if (!is_object($rs)) {
$this->debug_db('edit_object');
$this->db->RollBackTrans();
return false;
}
$this->db->CommitTrans();
return true;
} // End of "if ($erase)"
$groups_ids = FALSE;
if ($object_type == 'axo' OR $object_type == 'aro') {
// If the object is "groupable" (may become unnecessary,
// see above
// Get id of groups where the object is assigned:
// you must explicitly remove the object from its groups before
// deleting it (don't know if this is really needed, anyway it's safer ;-)
$query = 'SELECT group_id FROM '. $object_group_table .' WHERE '. $object_type .'_id='. $object_id;
$groups_ids = $this->db->GetCol($query);
}
if ( ( isset($acl_ids) AND !empty($acl_ids) ) OR ( isset($groups_ids) AND !empty($groups_ids) ) ) {
// The Object is referenced somewhere (group or acl), can't delete it
$this->debug_text("del_object(): Can't delete the object as it is being referenced by GROUPs (".@implode($groups_ids).") or ACLs (".@implode($acl_ids,",").")");
$this->db->RollBackTrans();
return false;
} else {
// The Object is NOT referenced anywhere, delete it
$query = "DELETE FROM $table WHERE id=$object_id";
$rs = $this->db->Execute($query);
if ( !is_object($rs) ) {
$this->debug_db('edit_object');
$this->db->RollBackTrans();
return false;
}
$this->db->CommitTrans();
return true;
}
$this->db->RollbackTrans();
return false;
}
/*
*
* Object Sections
*
*/
/**
* get_object_section_section_id()
*
* Gets the object_section_id given the name AND/OR value of the section.
*
* Will only return one section id, so if there are duplicate names it will return false.
*
* @return int Object Section ID if the object section is found AND is unique, or FALSE otherwise.
*
* @param string Object Name
* @param string Object Value
* @param string Object Type, either 'ACO', 'ARO', 'AXO', or 'ACL'
*
*/
function get_object_section_section_id($name = NULL, $value = NULL, $object_type = NULL) {
$this->debug_text("get_object_section_section_id(): Value: $value Name: $name Object Type: $object_type");
switch(strtolower(trim($object_type))) {
case 'aco':
case 'aro':
case 'axo':
case 'acl':
$object_type = strtolower(trim($object_type));
$table = $this->_db_table_prefix . $object_type;
$object_sections_table = $this->_db_table_prefix . $object_type .'_sections';
break;
default:
$this->debug_text('get_object_section_section_id(): Invalid Object Type ('. $object_type . ')');
return FALSE;
}
$name = trim($name);
$value = trim($value);
if (empty($name) AND $value === '') {
$this->debug_text('get_object_section_section_id(): Both Name ('. $name .') and Value ('. $value .') are empty, you must specify at least one.');
return FALSE;
}
$query = 'SELECT id FROM '. $object_sections_table;
$where = ' WHERE ';
// limit by value if specified
if ($value !== '') {
$query .= $where .'value='. $this->db->quote($value);
$where = ' AND ';
}
// only use name if asked, this is SLOW
if (!empty($name)) {
$query .= $where .'name='. $this->db->quote($name);
}
$rs = $this->db->Execute($query);
if (!is_object($rs)) {
$this->debug_db('get_object_section_section_id');
return FALSE;
}
$row_count = $rs->RecordCount();
// If only one row is returned
if ($row_count == 1) {
// Return only the ID in the first row.
$row = $rs->FetchRow();
return $row[0];
}
// If more than one row is returned
// should only ever occur when using name as values are unique.
if ($row_count > 1) {
$this->debug_text('get_object_section_section_id(): Returned '. $row_count .' rows, can only return one. Please search by value not name, or make your names unique.');
return FALSE;
}
// No rows returned, no matching section found
$this->debug_text('get_object_section_section_id(): Returned '. $row_count .' rows, no matching section found.');
return FALSE;
}
/**
* add_object_section()
*
* Inserts an object Section
*
* @return int Object Section ID of new section
*
* @param string Object Name
* @param string Object Value
* @param int Display Order
* @param int Hidden flag, hides section if 1, shows section if 0
* @param string Object Type, either 'ACO', 'ARO', 'AXO', or 'ACL'
*/
function add_object_section($name, $value=0, $order=0, $hidden=0, $object_type=NULL) {
switch(strtolower(trim($object_type))) {
case 'aco':
$object_type = 'aco';
$object_sections_table = $this->_db_table_prefix .'aco_sections';
break;
case 'aro':
$object_type = 'aro';
$object_sections_table = $this->_db_table_prefix .'aro_sections';
break;
case 'axo':
$object_type = 'axo';
$object_sections_table = $this->_db_table_prefix .'axo_sections';
break;
case 'acl':
$object_type = 'acl';
$object_sections_table = $this->_db_table_prefix .'acl_sections';
break;
}
$this->debug_text("add_object_section(): Value: $value Order: $order Name: $name Object Type: $object_type");
$name = trim($name);
$value = trim($value);
$order = (int) $order;
$hidden = (int) $hidden;
if ($order == NULL OR $order == '') {
$order = 0;
}
if (empty($name) ) {
$this->debug_text("add_object_section(): name ($name) is empty, this is required");
return false;
}
if (empty($object_type) ) {
$this->debug_text("add_object_section(): Object Type ($object_type) is empty, this is required");
return false;
}
$insert_id = $this->db->GenID($this->_db_table_prefix.$object_type.'_sections_seq',10);
$query = "insert into $object_sections_table (id,value,order_value,name,hidden) VALUES($insert_id, '$value', '$order', '$name', $hidden)";
$rs = $this->db->Execute($query);
if (!is_object($rs)) {
$this->debug_db('add_object_section');
return false;
} else {
$this->debug_text("add_object_section(): Added object_section as ID: $insert_id");
return $insert_id;
}
}
/**
* edit_object_section()
*
* Edits a given Object Section
*
* @return bool Returns TRUE if successful, FALSE otherwise
*
* @param int Object Section ID #
* @param string Object Section Name
* @param string Object Section Value
* @param int Display Order
* @param int Hidden Flag, hide object section if 1, show if 0
* @param string Object Type, either 'ACO', 'ARO', 'AXO', or 'ACL'
*/
function edit_object_section($object_section_id, $name, $value=0, $order=0, $hidden=0, $object_type=NULL) {
switch(strtolower(trim($object_type))) {
case 'aco':
$object_type = 'aco';
$table = $this->_db_table_prefix .'aco';
$object_sections_table = $this->_db_table_prefix .'aco_sections';
$object_map_table = $this->_db_table_prefix .'aco_map';
break;
case 'aro':
$object_type = 'aro';
$table = $this->_db_table_prefix .'aro';
$object_sections_table = $this->_db_table_prefix .'aro_sections';
$object_map_table = $this->_db_table_prefix .'aro_map';
break;
case 'axo':
$object_type = 'axo';
$table = $this->_db_table_prefix .'axo';
$object_sections_table = $this->_db_table_prefix .'axo_sections';
$object_map_table = $this->_db_table_prefix .'axo_map';
break;
case 'acl':
$object_type = 'acl';
$table = $this->_db_table_prefix .'acl';
$object_sections_table = $this->_db_table_prefix .'acl_sections';
break;
default:
$this->debug_text('edit_object_section(): Invalid Object Type: '. $object_type);
return FALSE;
}
$this->debug_text("edit_object_section(): ID: $object_section_id Value: $value Order: $order Name: $name Object Type: $object_type");
$name = trim($name);
$value = trim($value);
$order = (int) $order;
$hidden = (int) $hidden;
if (empty($object_section_id) ) {
$this->debug_text("edit_object_section(): Section ID ($object_section_id) is empty, this is required");
return false;
}
if (empty($name) ) {
$this->debug_text("edit_object_section(): name ($name) is empty, this is required");
return false;
}
if (empty($object_type) ) {
$this->debug_text("edit_object_section(): Object Type ($object_type) is empty, this is required");
return false;
}
// sanitise input
$object_section_id = (int) $object_section_id;
$this->db->BeginTrans();
//Get old value incase it changed, before we do the update.
$query = "select value from $object_sections_table where id=$object_section_id";
$old_value = $this->db->GetOne($query);
$query = "update $object_sections_table set
value=" . $this->db-quote($value) . "',
order_value=$order,
name=" . $this->db-quote($name) . ",
hidden=$hidden
where id=$object_section_id";
$rs = $this->db->Execute($query);
if (!is_object($rs)) {
$this->debug_db('edit_object_section');
$this->db->RollbackTrans();
return false;
} else {
$this->debug_text("edit_object_section(): Modified aco_section ID: $object_section_id");
if ($old_value != $value) {
$this->debug_text("edit_object_section(): Value Changed, update other tables.");
$query = "update $table set
section_value=" . $this->db-quote($value) . "
where section_value = " . $this->db-quote($old_value);
$rs = $this->db->Execute($query);
if (!is_object($rs)) {
$this->debug_db('edit_object_section');
$this->db->RollbackTrans();
return false;
} else {
if (!empty($object_map_table)) {
$query = "update $object_map_table set
section_value=" . $this->db-quote($value) . "
where section_value = " . $this->db-quote($old_value);
$rs = $this->db->Execute($query);
if ( !is_object($rs) ) {
$this->debug_db('edit_object_section');
$this->db->RollbackTrans();
return false;
} else {
$this->debug_text("edit_object_section(): Modified ojbect_map value: $value");
$this->db->CommitTrans();
return true;
}
} else {
//ACL sections, have no mapping table. Return true.
$this->db->CommitTrans();
return true;
}
}
}
$this->db->CommitTrans();
return true;
}
}
/**
* del_object_section()
*
* Deletes a given Object Section and, if explicitly asked, all the section objects
*
* ERASE feature by: Martino Piccinato
*
* @return bool Returns TRUE if successful, FALSE otherwise
*
* @param int Object Section ID # to delete
* @param string Object Type, either 'ACO', 'ARO', 'AXO', or 'ACL'
* @param bool Erases all section objects assigned to the section
*/
function del_object_section($object_section_id, $object_type=NULL, $erase=FALSE) {
switch(strtolower(trim($object_type))) {
case 'aco':
$object_type = 'aco';
$object_sections_table = $this->_db_table_prefix .'aco_sections';
break;
case 'aro':
$object_type = 'aro';
$object_sections_table = $this->_db_table_prefix .'aro_sections';
break;
case 'axo':
$object_type = 'axo';
$object_sections_table = $this->_db_table_prefix .'axo_sections';
break;
case 'acl':
$object_type = 'acl';
$object_sections_table = $this->_db_table_prefix .'acl_sections';
break;
}
$this->debug_text("del_object_section(): ID: $object_section_id Object Type: $object_type, Erase all: $erase");
if (empty($object_section_id) ) {
$this->debug_text("del_object_section(): Section ID ($object_section_id) is empty, this is required");
return false;
}
if (empty($object_type) ) {
$this->debug_text("del_object_section(): Object Type ($object_type) is empty, this is required");
return false;
}
// sanitise input
$object_section_id = (int) $object_section_id;
// Get the value of the section
$query="SELECT value FROM $object_sections_table WHERE id=$object_section_id";
$section_value = $this->db->GetOne($query);
// Get all objects ids in the section
$object_ids = $this->get_object($section_value, 1, $object_type);
if($erase) {
// Delete all objects in the section and for
// each object delete the referencing object
// (see del_object method)
if (is_array($object_ids)) {
foreach ($object_ids as $id) {
if ( $object_type === 'acl' ) {
$this->del_acl($id);
} else {
$this->del_object($id, $object_type, TRUE);
}
}
}
}
if($object_ids AND !$erase) {
// There are objects in the section and we
// were not asked to erase them: don't delete it
$this->debug_text("del_object_section(): Could not delete the section ($section_value) as it is not empty.");
return false;
} else {
// The section is empty (or emptied by this method)
$query = "DELETE FROM $object_sections_table where id=$object_section_id";
$rs = $this->db->Execute($query);
if (!is_object($rs)) {
$this->debug_db('del_object_section');
return false;
} else {
$this->debug_text("del_object_section(): deleted section ID: $object_section_id Value: $section_value");
return true;
}
}
return false;
}
/**
* get_section_data()
*
* Gets the section data given the Section Value
*
* @return array Returns numerically indexed array with the following columns:
* - array[0] = (int) Section ID #
* - array[1] = (string) Section Value
* - array[2] = (int) Section Order
* - array[3] = (string) Section Name
* - array[4] = (int) Section Hidden?
* @param string Section Value
* @param string Object Type, either 'ACO', 'ARO', or 'AXO'
*/
function get_section_data($section_value, $object_type=NULL) {
switch(strtolower(trim($object_type))) {
case 'aco':
$object_type = 'aco';
$table = $this->_db_table_prefix .'aco_sections';
break;
case 'aro':
$object_type = 'aro';
$table = $this->_db_table_prefix .'aro_sections';
break;
case 'axo':
$object_type = 'axo';
$table = $this->_db_table_prefix .'axo_sections';
break;
default:
$this->debug_text('get_section_data(): Invalid Object Type: '. $object_type);
return FALSE;
}
$this->debug_text("get_section_data(): Section Value: $section_value Object Type: $object_type");
if (empty($section_value) ) {
$this->debug_text("get_section_data(): Section Value ($section_value) is empty, this is required");
return false;
}
if (empty($object_type) ) {
$this->debug_text("get_section_data(): Object Type ($object_type) is empty, this is required");
return false;
}
$query = 'SELECT id, value, order_value, name, hidden FROM '. $table .' WHERE value='.$this->db->Quote( $section_value );
$row = $this->db->GetRow($query);
if ($row) {
return $row;
}
$this->debug_text("get_section_data(): Section does not exist.");
return false;
}
/**
* clear_database()
*
* Deletes all data from the phpGACL tables. USE WITH CAUTION.
*
* @return bool Returns TRUE if successful, FALSE otherwise
*
*/
function clear_database()
{
$tablesToClear = array(
$this->_db_table_prefix.'acl',
$this->_db_table_prefix.'aco',
$this->_db_table_prefix.'aco_map',
$this->_db_table_prefix.'aco_sections',
$this->_db_table_prefix.'aro',
$this->_db_table_prefix.'aro_groups',
$this->_db_table_prefix.'aro_groups_map',
$this->_db_table_prefix.'aro_map',
$this->_db_table_prefix.'aro_sections',
$this->_db_table_prefix.'axo',
$this->_db_table_prefix.'axo_groups',
$this->_db_table_prefix.'axo_groups_map',
$this->_db_table_prefix.'axo_map',
$this->_db_table_prefix.'axo_sections',
$this->_db_table_prefix.'groups_aro_map',
$this->_db_table_prefix.'groups_axo_map'
);
// Get all the table names and loop
$tableNames = $this->db->MetaTables('TABLES');
$query = array();
foreach ($tableNames as $key => $value){
if (in_array($value, $tablesToClear) ) {
$query[] = 'TRUNCATE TABLE '.$value.';';
}
}
// Loop the queries and return.
foreach ($query as $key => $value){
$result = $this->db->Execute($value);
}
return TRUE;
}
/**
* Calculates the start number for a sequence table
* @protected
* @param string The name of the table
* @return int The highest id plus one
*/
function _defaultGenID( $table ) {
$query = "SELECT MAX(id) from " . $table;
$id = $this->db->GetOne( $query ) + 1;
return $id;
}
}
Welcome to the Frontpage
Copyright © 2010 Cobra-motor. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License. |
PollsWho's OnlineWe have 1 guest onlineAdvertisement |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||



