Exemple #1
0
 public static function delete_report($report_id)
 {
     $report_id = (int) $report_id;
     if (_DEMO_MODE && $report_id == 1) {
         return;
     }
     if ((int) $report_id > 0) {
         $original_report_data = self::get_report($report_id);
         if (!$original_report_data || $original_report_data['report_id'] != $report_id) {
             return false;
         }
     }
     if (!self::can_i('delete', 'reports')) {
         return false;
     }
     $sql = "DELETE FROM " . _DB_PREFIX . "report WHERE report_id = '" . $report_id . "' LIMIT 1";
     $res = query($sql);
     module_note::note_delete("report", $report_id);
     module_extra::delete_extras('report', 'report_id', $report_id);
 }
Exemple #2
0
 public function delete_product($product_id)
 {
     $product_id = (int) $product_id;
     $product = self::get_product($product_id);
     if ($product && $product['product_id'] == $product_id) {
         $sql = "DELETE FROM " . _DB_PREFIX . "product WHERE product_id = '" . $product_id . "' LIMIT 1";
         query($sql);
         module_extra::delete_extras('product', 'product_id', $product_id);
     }
 }
Exemple #3
0
 public static function delete_invoice($invoice_id)
 {
     $invoice_id = (int) $invoice_id;
     if ((int) $invoice_id > 0 && self::can_i('delete', 'Invoices')) {
         hook_handle_callback('invoice_deleted', $invoice_id);
         $invoice_data = self::get_invoice($invoice_id);
         $sql = "DELETE FROM " . _DB_PREFIX . "invoice WHERE invoice_id = '" . $invoice_id . "' LIMIT 1";
         $res = query($sql);
         $sql = "DELETE FROM " . _DB_PREFIX . "invoice_item WHERE invoice_id = '" . $invoice_id . "'";
         $res = query($sql);
         $sql = "DELETE FROM " . _DB_PREFIX . "invoice_tax WHERE invoice_id = '" . $invoice_id . "'";
         $res = query($sql);
         $sql = "DELETE FROM " . _DB_PREFIX . "invoice_payment WHERE invoice_id = '" . $invoice_id . "'";
         $res = query($sql);
         $sql = "UPDATE " . _DB_PREFIX . "invoice SET renew_invoice_id = 0 WHERE renew_invoice_id = '" . $invoice_id . "'";
         $res = query($sql);
         if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
             module_note::note_delete("invoice", $invoice_id);
         }
         if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) {
             module_extra::delete_extras('invoice', 'invoice_id', $invoice_id);
         }
         module_cache::clear('invoice');
         module_cache::clear('job');
         if ($invoice_data && $invoice_data['customer_id']) {
             module_customer::update_customer_status($invoice_data['customer_id']);
         }
     }
 }
Exemple #4
0
 public static function delete_job($job_id)
 {
     $job_id = (int) $job_id;
     if (_DEMO_MODE && $job_id == 1) {
         return;
     }
     if ((int) $job_id > 0) {
         $original_job_data = self::get_job($job_id);
         if (!$original_job_data || $original_job_data['job_id'] != $job_id) {
             return false;
         }
     }
     if (!self::can_i('delete', 'Jobs')) {
         return false;
     }
     $sql = "DELETE FROM " . _DB_PREFIX . "job WHERE job_id = '" . $job_id . "' LIMIT 1";
     $res = query($sql);
     $sql = "DELETE FROM " . _DB_PREFIX . "task WHERE job_id = '" . $job_id . "'";
     $res = query($sql);
     $sql = "DELETE FROM " . _DB_PREFIX . "task_log WHERE job_id = '" . $job_id . "'";
     $res = query($sql);
     $sql = "UPDATE " . _DB_PREFIX . "job SET renew_job_id = NULL WHERE renew_job_id = '" . $job_id . "'";
     $res = query($sql);
     if (class_exists('module_file', false)) {
         $sql = "UPDATE " . _DB_PREFIX . "file SET job_id = 0 WHERE job_id = '" . $job_id . "'";
         query($sql);
     }
     if (class_exists('module_group', false)) {
         module_group::delete_member($job_id, 'job');
     }
     foreach (module_invoice::get_invoices(array('job_id' => $job_id)) as $val) {
         // only delete this invoice if it has no tasks left
         // it could be a combined invoice with other jobs now.
         $invoice_items = module_invoice::get_invoice_items($val['invoice_id']);
         if (!count($invoice_items)) {
             module_invoice::delete_invoice($val['invoice_id']);
         }
     }
     if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
         module_note::note_delete("job", $job_id);
     }
     if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) {
         module_extra::delete_extras('job', 'job_id', $job_id);
     }
     hook_handle_callback('job_delete', $job_id);
     module_cache::clear('job');
 }
Exemple #5
0
 public function delete_subscription($subscription_id)
 {
     $subscription_id = (int) $subscription_id;
     $subscription = self::get_subscription($subscription_id);
     if ($subscription && $subscription['subscription_id'] == $subscription_id) {
         $sql = "DELETE FROM " . _DB_PREFIX . "subscription WHERE subscription_id = '" . $subscription_id . "' LIMIT 1";
         query($sql);
         module_extra::delete_extras('subscription', 'subscription_id', $subscription_id);
     }
 }
Exemple #6
0
 public static function delete_quote($quote_id)
 {
     $quote_id = (int) $quote_id;
     if (_DEMO_MODE && $quote_id == 1) {
         return;
     }
     if ((int) $quote_id > 0) {
         $original_quote_data = self::get_quote($quote_id);
         if (!$original_quote_data || $original_quote_data['quote_id'] != $quote_id) {
             return false;
         }
     } else {
         return false;
     }
     if (!self::can_i('delete', 'Quotes')) {
         return false;
     }
     $sql = "DELETE FROM " . _DB_PREFIX . "quote WHERE quote_id = '" . $quote_id . "' LIMIT 1";
     $res = query($sql);
     $sql = "DELETE FROM " . _DB_PREFIX . "quote_tax WHERE quote_id = '" . $quote_id . "'";
     $res = query($sql);
     $sql = "DELETE FROM " . _DB_PREFIX . "quote_task WHERE quote_id = '" . $quote_id . "'";
     $res = query($sql);
     if (class_exists('module_file', false)) {
         $sql = "UPDATE " . _DB_PREFIX . "file SET quote_id = 0 WHERE quote_id = '" . $quote_id . "'";
         query($sql);
     }
     if (class_exists('module_group', false)) {
         module_group::delete_member($quote_id, 'quote');
     }
     if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
         module_note::note_delete("quote", $quote_id);
     }
     if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) {
         module_extra::delete_extras('quote', 'quote_id', $quote_id);
     }
     hook_handle_callback('quote_delete', $quote_id);
     module_cache::clear('quote');
 }
Exemple #7
0
 public function delete_member($member_id)
 {
     $member_id = (int) $member_id;
     $member = self::get_member($member_id);
     if ($member && $member['member_id'] == $member_id) {
         $sql = "DELETE FROM " . _DB_PREFIX . "member WHERE member_id = '" . $member_id . "' LIMIT 1";
         query($sql);
         module_extra::delete_extras('member', 'member_id', $member_id);
         if (class_exists('module_group', false)) {
             module_group::delete_member($member_id, 'member');
             module_group::delete_member($member_id, 'newsletter_subscription');
         }
         hook_handle_callback('member_deleted', $member_id);
     }
 }
Exemple #8
0
 public function delete_customer($customer_id, $remove_linked_data = true)
 {
     $customer_id = (int) $customer_id;
     if ($customer_id > 0) {
         if (_DEMO_MODE && $customer_id == 1) {
             set_error('Sorry this is a Demo Customer. It cannot be changed.');
             redirect_browser(self::link_open($customer_id));
         }
         $customer = self::get_customer($customer_id);
         if ($customer && $customer['customer_id'] == $customer_id) {
             // todo: Delete emails (wack these in this customer_deleted hook)
             hook_handle_callback('customer_deleted', $customer_id, $remove_linked_data);
             if (class_exists('module_group', false)) {
                 // remove the customer from his groups
                 module_group::delete_member($customer_id, 'customer');
             }
             if (class_exists('module_extra', false)) {
                 module_extra::delete_extras('customer', 'customer_id', $customer_id);
             }
             // remove the contacts from this customer
             foreach (module_user::get_contacts(array('customer_id' => $customer_id)) as $val) {
                 if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                     module_user::delete_user($val['user_id']);
                 }
             }
             // remove staff
             delete_from_db('customer_user_rel', 'customer_id', $customer_id);
             if (class_exists('module_note', false)) {
                 module_note::note_delete("customer", 'customer_id', $customer_id);
             }
             handle_hook("address_delete", $this, 'all', "customer", 'customer_id', $customer_id);
             // todo, check the 'delete' permission on each one of these 'delete' method calls
             // do that better when we remove each of these and put them into the customer delete hook
             if ($remove_linked_data) {
                 if (class_exists('module_website', false) && module_website::is_plugin_enabled()) {
                     foreach (module_website::get_websites(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             module_website::delete_website($val['website_id']);
                         }
                     }
                 }
                 if (class_exists('module_job', false) && module_job::is_plugin_enabled()) {
                     foreach (module_job::get_jobs(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             module_job::delete_job($val['job_id']);
                         }
                     }
                 }
                 if (class_exists('module_invoice', false) && module_invoice::is_plugin_enabled()) {
                     foreach (module_invoice::get_invoices(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             module_invoice::delete_invoice($val['invoice_id']);
                         }
                     }
                 }
                 if (class_exists('module_quote', false) && module_quote::is_plugin_enabled()) {
                     foreach (module_quote::get_quotes(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             module_quote::delete_quote($val['quote_id']);
                         }
                     }
                 }
                 //handle_hook("file_delete",$this,"customer",'customer_id',$customer_id);
             } else {
                 // instead of deleting these records we just update them to customer_id = 0
                 if (class_exists('module_website', false) && module_website::is_plugin_enabled()) {
                     foreach (module_website::get_websites(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             update_insert('website_id', $val['website_id'], 'website', array('customer_id' => 0));
                         }
                     }
                 }
                 if (class_exists('module_job', false) && module_job::is_plugin_enabled()) {
                     foreach (module_job::get_jobs(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             update_insert('job_id', $val['job_id'], 'job', array('customer_id' => 0));
                         }
                     }
                 }
                 if (class_exists('module_invoice', false) && module_invoice::is_plugin_enabled()) {
                     foreach (module_invoice::get_invoices(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             update_insert('invoice_id', $val['invoice_id'], 'invoice', array('customer_id' => 0));
                         }
                     }
                 }
                 if (class_exists('module_quote', false) && module_quote::is_plugin_enabled()) {
                     foreach (module_quote::get_quotes(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             update_insert('quote_id', $val['quote_id'], 'quote', array('customer_id' => 0));
                         }
                     }
                 }
                 if (class_exists('module_file', false) && module_file::is_plugin_enabled()) {
                     foreach (module_file::get_files(array('owner_id' => $customer_id, 'owner_table' => 'customer')) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             update_insert('file_id', $val['file_id'], 'file', array('owner_id' => 0, 'owner_table' => ''));
                         }
                     }
                 }
             }
             // finally delete the main customer record
             // (this is so the above code works with its sql joins)
             $sql = "DELETE FROM " . _DB_PREFIX . "customer WHERE customer_id = '" . $customer_id . "' LIMIT 1";
             query($sql);
         }
     }
 }
Exemple #9
0
 public function delete_vendor($vendor_id, $remove_linked_data = true)
 {
     $vendor_id = (int) $vendor_id;
     if ($vendor_id > 0) {
         if (_DEMO_MODE && $vendor_id == 1) {
             set_error('Sorry this is a Demo Vendor. It cannot be changed.');
             redirect_browser(self::link_open($vendor_id));
         }
         $vendor = self::get_vendor($vendor_id);
         if ($vendor && $vendor['vendor_id'] == $vendor_id) {
             // todo: Delete emails (wack these in this vendor_deleted hook)
             hook_handle_callback('vendor_deleted', $vendor_id, $remove_linked_data);
             if (class_exists('module_group', false)) {
                 // remove the vendor from his groups
                 module_group::delete_member($vendor_id, 'vendor');
             }
             if (class_exists('module_extra', false)) {
                 module_extra::delete_extras('vendor', 'vendor_id', $vendor_id);
             }
             // remove the contacts from this vendor
             foreach (module_user::get_contacts(array('vendor_id' => $vendor_id)) as $val) {
                 if ($val['vendor_id'] && $val['vendor_id'] == $vendor_id) {
                     module_user::delete_user($val['user_id']);
                 }
             }
             if (class_exists('module_note', false)) {
                 module_note::note_delete("vendor", 'vendor_id', $vendor_id);
             }
             handle_hook("address_delete", $this, 'all', "vendor", 'vendor_id', $vendor_id);
             // finally delete the main vendor record
             // (this is so the above code works with its sql joins)
             $sql = "DELETE FROM " . _DB_PREFIX . "vendor WHERE vendor_id = '" . $vendor_id . "' LIMIT 1";
             query($sql);
         }
     }
 }
Exemple #10
0
 public static function delete_website($website_id)
 {
     $website_id = (int) $website_id;
     if (_DEMO_MODE && $website_id == 1) {
         set_error('Sorry this is a Demo Website. It cannot be deleted.');
         return;
     }
     if ((int) $website_id > 0) {
         $original_website_data = self::get_website($website_id);
         if (!$original_website_data || $original_website_data['website_id'] != $website_id) {
             return false;
         }
     }
     if (!self::can_i('delete', 'Websites')) {
         return false;
     }
     hook_handle_callback('website_deleted', $website_id);
     $sql = "DELETE FROM " . _DB_PREFIX . "website WHERE website_id = '" . $website_id . "' LIMIT 1";
     query($sql);
     if (class_exists('module_group', false)) {
         module_group::delete_member($website_id, 'website');
     }
     foreach (module_job::get_jobs(array('website_id' => $website_id)) as $val) {
         module_job::delete_job($val['website_id']);
     }
     module_note::note_delete("website", $website_id);
     module_extra::delete_extras('website', 'website_id', $website_id);
 }