function delete($VAR) { $db =& DB(); global $C_auth, $C_list; # set the id $id = $this->table . '_id'; # generate the list of ID's $id_list = ''; $account_id_list = ''; $discount_id_list = ''; $ii = 0; if (isset($VAR["delete_id"])) { $id = explode(',', $VAR["delete_id"]); } elseif (isset($VAR["id"])) { $id = explode(',', $VAR["id"]); } for ($i = 0; $i < count($id); $i++) { if ($id[$i] != '') { ### is current account auth to delete this account? ### Get any authorized groups: $db =& DB(); $sql = 'SELECT group_id FROM ' . AGILE_DB_PREFIX . 'account_group WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND account_id = ' . $db->qstr($id[$i]) . ' ORDER BY group_id'; $groups = $db->Execute($sql); while (!$groups->EOF) { $group[] = $groups->fields['group_id']; $groups->MoveNext(); } ### Verify the user has access to view this account: $delete_this = true; if (!empty($group) && is_array($group)) { for ($ix = 0; $ix < count($group); $ix++) { if (!$C_auth->auth_group_by_id($group[$ix])) { $delete_this = false; $ix = count($group); } } } unset($group); ### Verify this is not the admin account or the current user's account: if (SESS_ACCOUNT == $id[$i] || $id[$i] == '1') { $delete_this = false; } ### Generate the SQL if ($delete_this) { if ($i == 0) { $id_list .= " id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " "; $account_id_list .= " account_id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " "; $discount_id_list .= " account_id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " "; $ii++; } else { $id_list .= " OR id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " "; $account_id_list .= " OR account_id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " "; $discount_id_list .= " OR account_id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " "; $ii++; } #################################################################### ### Do any db_mapping #################################################################### $dbsql = "SELECT username FROM " . AGILE_DB_PREFIX . "account WHERE\n\t\t\t\t\t\t\t site_id = " . $db->qstr(DEFAULT_SITE) . " AND\n\t\t\t\t\t\t\t id = " . $db->qstr($id[$i]); $resultdb = $db->Execute($dbsql); $old_username = $resultdb->fields['username']; if ($C_list->is_installed('db_mapping')) { include_once PATH_MODULES . 'db_mapping/db_mapping.inc.php'; $db_map = new db_mapping(); $db_map->account_delete($id[$i], $old_username); } } } } $db =& DB(); if ($ii > 0) { # generate the full query (account) $q = "DELETE FROM " . AGILE_DB_PREFIX . "account\n\t\t\t\t WHERE {$id_list} AND site_id = " . $db->qstr(DEFAULT_SITE); $result = $db->Execute($q); # generate the full query (sessions) $q = "DELETE FROM " . AGILE_DB_PREFIX . "session\n\t\t\t\t WHERE {$account_id_list} AND site_id = " . $db->qstr(DEFAULT_SITE); $db->Execute($q); # generate the full query (account_billing) $q = "DELETE FROM " . AGILE_DB_PREFIX . "account_billing\n\t\t\t\t WHERE {$account_id_list} AND site_id = " . $db->qstr(DEFAULT_SITE); $db->Execute($q); # generate the full query (account_group) $q = "DELETE FROM " . AGILE_DB_PREFIX . "account_group\n\t\t\t\t WHERE {$account_id_list} AND site_id = " . $db->qstr(DEFAULT_SITE); $db->Execute($q); # generate the full query (cart) $q = "DELETE FROM " . AGILE_DB_PREFIX . "cart\n\t\t\t\t WHERE {$account_id_list} AND site_id = " . $db->qstr(DEFAULT_SITE); $db->Execute($q); # generate the full query (search) $q = "DELETE FROM " . AGILE_DB_PREFIX . "search\n\t\t\t\t WHERE {$account_id_list} AND site_id = " . $db->qstr(DEFAULT_SITE); $db->Execute($q); # generate the full query (staff) $q = "DELETE FROM " . AGILE_DB_PREFIX . "staff\n\t\t\t\t WHERE {$account_id_list} AND site_id = " . $db->qstr(DEFAULT_SITE); $db->Execute($q); # generate the full query (ticket) if ($C_list->is_installed('ticket')) { $q = "SELECT id FROM " . AGILE_DB_PREFIX . "ticket\n\t\t\t\t\t WHERE {$account_id_list} AND site_id = " . $db->qstr(DEFAULT_SITE); $ticket = $db->Execute($q); if ($ticket != false && $ticket->RecordCount() > 0) { while (!$ticket->EOF) { include_once PATH_MODULES . 'ticket/ticket.inc.php'; $tk = new ticket(); $arr['id'] = $ticket->fields['id']; $tk->delete($arr, $tk); $ticket->MoveNext(); } } } # generate the full query (affiliate) if ($C_list->is_installed('affiliate')) { $q = "DELETE FROM " . AGILE_DB_PREFIX . "affiliate\n\t\t\t\t\t WHERE {$account_id_list} AND site_id = " . $db->qstr(DEFAULT_SITE); $db->Execute($q); } # generate the full query (discount) $q = "DELETE FROM " . AGILE_DB_PREFIX . "discount\n\t\t\t\t WHERE {$discount_id_list} AND site_id = " . $db->qstr(DEFAULT_SITE); $db->Execute($q); # generate the full query (invoice) $q = "SELECT id FROM " . AGILE_DB_PREFIX . "invoice\n\t\t\t\t WHERE {$account_id_list} AND site_id = " . $db->qstr(DEFAULT_SITE); $invoice = $db->Execute($q); if ($invoice != false && $invoice->RecordCount() > 0) { while (!$invoice->EOF) { include_once PATH_MODULES . 'invoice/invoice.inc.php'; $inv = new invoice(); $arr['id'] = $invoice->fields['id']; $inv->delete($arr, $inv); $invoice->MoveNext(); } } # error reporting if ($result === false) { global $C_debug; $C_debug->error('account_admin.inc.php', 'delete', $db->ErrorMsg()); } else { # Alert delete message global $C_debug, $C_translate; $C_translate->value["CORE"]["module_name"] = $C_translate->translate('name', 'account_admin', ""); $message = $C_translate->translate('alert_delete_ids', "CORE", ""); $C_debug->alert($message); } } }