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);
            }
        }
    }
示例#2
0
 function invoice_cleanup($VAR)
 {
     # Load the account admin class
     include_once PATH_MODULES . 'invoice/invoice.inc.php';
     $invoice = new invoice();
     $exp = time() - 86400 * AGILE_INVOICE_CLEANUP_DAYS;
     # Get each account:
     $db =& DB();
     $sql = 'SELECT id FROM ' . AGILE_DB_PREFIX . 'invoice
                 WHERE
                 process_status  =  ' . $db->qstr(0) . '  AND
                 billing_status  =  ' . $db->qstr(0) . '  AND
                 billed_amt      <= ' . $db->qstr(0) . '  AND
                 date_last       <= ' . $db->qstr($exp) . '  AND
                 site_id         =  ' . $db->qstr(DEFAULT_SITE);
     $rs = $db->Execute($sql);
     while (!$rs->EOF) {
         $arr['id'] = $rs->fields['id'];
         $invoice->delete($arr, $invoice);
         $rs->MoveNext();
     }
 }
示例#3
0
        $invoice->save();
        $invoiceID = $invoice->get_id();
        $TPL["message_good"][] = "Invoice saved.";
        alloc_redirect($TPL["url_alloc_invoice"] . "invoiceID=" . $invoiceID . $extra);
    }
} else {
    if ($_POST["delete"] && $invoice->get_value("invoiceStatus") == "edit") {
        if ($invoiceItemIDs) {
            $db = new db_alloc();
            $q = prepare("DELETE FROM transaction WHERE invoiceItemID in (%s)", $invoiceItemIDs);
            $db->query($q);
            $q = prepare("DELETE FROM invoiceItem WHERE invoiceItemID in (%s)", $invoiceItemIDs);
            $db->query($q);
        }
        // should probablg delete/unlink the pdf docs
        $invoice->delete();
        $TPL["message_good"][] = "Invoice deleted.";
        alloc_redirect($TPL["url_alloc_invoiceList"]);
        // Saving editing individual invoiceItems
    } else {
        if (($_POST["invoiceItem_save"] || $_POST["invoiceItem_edit"] || $_POST["invoiceItem_delete"]) && $invoice->get_value("invoiceStatus") == "edit") {
            is_array($_POST["invoiceItem_edit"]) and $invoiceItemID = key($_POST["invoiceItem_edit"]);
            is_array($_POST["invoiceItem_delete"]) and $invoiceItemID = key($_POST["invoiceItem_delete"]);
            $invoiceItem = new invoiceItem();
            $invoiceItem->currency = $invoice->get_value("currencyTypeID");
            $invoiceItem->set_id($invoiceItemID);
            #echo $invoiceItem->get_id();
            $invoice->set_id($invoiceID);
            $invoice->select();
            #echo "<pre>".print_r($_POST,1)."</pre>";
            $_POST["iiTax"] or $_POST["iiTax"] = '';