} // now find any subscription invoices that are linked to this website. if (class_exists('module_subscription', false)) { $members_subscriptions = module_subscription::get_subscriptions_by('website', $website_id); foreach ($members_subscriptions as $subscription_id => $subscription_info) { $history = module_subscription::get_subscription_history($subscription_id, 'website', $website_id); foreach ($history as $h) { if (is_array($h) && isset($h['invoice_id']) && $h['invoice_id']) { $note_summary_owners['invoice'][$h['invoice_id']] = $h['invoice_id']; } } } } module_note::display_notes(array('title' => module_config::c('project_name_single', 'Website') . ' Notes', 'owner_table' => 'website', 'owner_id' => $website_id, 'view_link' => module_website::link_open($website_id), 'display_summary' => true, 'summary_owners' => $note_summary_owners)); } if (class_exists('module_quote', false) && module_quote::is_plugin_enabled() && module_quote::can_i('view', 'Quotes')) { // show the jobs linked to this website. $quotes = module_quote::get_quotes(array('website_id' => $website_id)); if (count($quotes) || module_quote::can_i('create', 'Quotes')) { $h = array('type' => 'h3', 'title' => module_config::c('project_name_single', 'Website') . ' Quotes'); if (module_quote::can_i('create', 'Quotes')) { $h['button'] = array('title' => 'New Quote', 'url' => module_quote::link_generate('new', array('arguments' => array('website_id' => $website_id)))); } $fieldset_data = array('heading' => $h); if (count($quotes)) { $c = 0; ob_start(); ?> <div class="content_box_wheader"> <table border="0" cellspacing="0" cellpadding="2"
$c[$file['job_id']] = _l('%s (from %s)', $related_job['name'], $related_customer['customer_name']); } else { $file['job_id'] = false; } } else { $file['job_id'] = false; } } $fieldset_data['elements'][] = array('title' => 'Job', 'fields' => array(array('type' => 'select', 'name' => 'job_id', 'value' => $file['job_id'], 'options' => $c), function () use(&$file) { if ($file['job_id']) { echo ' '; echo '<a href="' . module_job::link_open($file['job_id'], false) . '">' . _l('Open Job »') . '</a>'; } })); } if (!$is_bucket_file && class_exists('module_quote', false) && module_quote::is_plugin_enabled()) { $c = array(); $res = module_quote::get_quotes(array('customer_id' => $file['customer_id'])); foreach ($res as $row) { $c[$row['quote_id']] = $row['name']; } if ($file['quote_id'] && !isset($c[$file['quote_id']])) { // this file is related to another quote. from another customer. $related_quote = module_quote::get_quote($file['quote_id'], false, true); if ($related_quote && $related_quote['quote_id'] == $file['quote_id']) { $related_customer = module_customer::get_customer($related_quote['customer_id'], true); if ($related_customer && $related_customer['customer_id'] == $related_quote['customer_id']) { $c[$file['quote_id']] = _l('%s (from %s)', $related_quote['name'], $related_customer['customer_name']); } else { $file['quote_id'] = false; }
if (file_exists($file['file_path'])) { echo module_file::format_bytes(filesize($file['file_path'])); } } }); if (!isset($_REQUEST['customer_id'])) { $columns['file_customer'] = array('title' => 'Customer', 'callback' => function ($file) { echo module_customer::link_open($file['customer_id'], true); }); } if (class_exists('module_job', false)) { $columns['file_job'] = array('title' => 'Job', 'callback' => function ($file) { echo module_job::link_open($file['job_id'], true); }); } if (class_exists('module_quote', false) && module_quote::is_plugin_enabled()) { $columns['file_quote'] = array('title' => 'Quote', 'callback' => function ($file) { echo module_quote::link_open($file['quote_id'], true); }); } $columns['file_date_added'] = array('title' => 'Date Added', 'callback' => function ($file) { echo _l('%s by %s', print_date($file['date_created']), module_user::link_open($file['create_user_id'], true)); }); if (module_file::can_i('edit', 'Files')) { $columns['file_action'] = array('title' => ' ', 'callback' => function ($file) { echo '<input type="checkbox" name="bulk_operation[' . $file['file_id'] . ']" value="yes">'; }); } if (class_exists('module_extra', false)) { $table_manager->display_extra('file', function ($file) { module_extra::print_table_data('file', $file['file_id']);
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); } } }