if ($invoice['total_amount_due'] > 0) { echo dollar($invoice['total_amount_due'], true, $invoice['currency_id']); echo ' ' . _l('due'); } else { echo _l('%s paid', dollar($invoice['total_amount'], true, $invoice['currency_id'])); } echo '</span>'; echo "<br>"; } } }); } } if (class_exists('module_group', false)) { $columns['group'] = array('title' => 'Group', 'callback' => function ($quote) { $groups = module_group::get_groups_search(array('owner_table' => 'quote', 'owner_id' => $quote['quote_id'])); $g = array(); foreach ($groups as $group) { $g[] = $group['name']; } echo implode(', ', $g); }); } $table_manager->set_columns($columns); $table_manager->row_callback = function ($row_data) { // load the full vendor data before displaying each row so we have access to more details return module_quote::get_quote($row_data['quote_id']); }; $table_manager->set_rows($quotes); if (class_exists('module_extra', false)) { $table_manager->display_extra('quote', function ($quote) {
}); if ($show_customer_details) { $columns['customer'] = array('title' => $contact_type_permission, 'callback' => function ($user) use($contact_module_name) { switch ($contact_module_name) { case 'customer': echo module_customer::link_open($user['customer_id'], true, $user); break; case 'vendor': echo module_vendor::link_open($user['vendor_id'], true, $user); break; } }); } if (class_exists('module_group', false) && module_user::can_i('view', 'Contact Groups')) { $columns['group'] = array('title' => 'Group', 'callback' => function ($user) { $groups = module_group::get_groups_search(array('owner_table' => 'user', 'owner_id' => $user['user_id'])); $g = array(); foreach ($groups as $group) { $g[] = $group['name']; } echo implode(', ', $g); }); } $table_manager->set_columns($columns); $table_manager->row_callback = function ($row_data) { // load the full vendor data before displaying each row so we have access to more details return $row_data; //module_user::get_user($row_data['user_id']); }; $table_manager->set_rows($users); if (class_exists('module_extra', false)) {
public static function run_pagination_hook(&$rows) { if (isset($_REQUEST['import_export_go']) && $_REQUEST['import_export_go'] == 'yes') { // we are posting back tot his script with a go! if (is_resource($rows)) { $new_rows = array(); while ($row = mysql_fetch_assoc($rows)) { $new_rows[] = $row; } $rows = $new_rows; } else { // rows stays the same. } // add these items to the import_export. if (is_array($rows) && count($rows)) { $fields = self::$pagination_options['fields']; // export as CSV file: ob_end_clean(); ob_start(); foreach ($fields as $key => $val) { echo '"' . str_replace('"', '""', $key) . '",'; } // check for extra fields. if (class_exists('module_extra', false) && isset(self::$pagination_options['extra']) && count(self::$pagination_options['extra'])) { if (isset(self::$pagination_options['extra']['owner_table'])) { self::$pagination_options['extra'] = array(self::$pagination_options['extra']); } foreach (self::$pagination_options['extra'] as $extra_field_id => $extra_field_settings) { $sql = "SELECT `extra_key` FROM `" . _DB_PREFIX . "extra` WHERE owner_table = '" . mysql_real_escape_string($extra_field_settings['owner_table']) . "' AND `extra_key` != '' GROUP BY `extra_key` ORDER BY `extra_key`"; self::$pagination_options['extra'][$extra_field_id]['extra_fields'] = qa($sql); foreach (self::$pagination_options['extra'][$extra_field_id]['extra_fields'] as $extra_field) { echo '"' . str_replace('"', '""', $extra_field['extra_key']) . '",'; } } } // check for group fields. if (class_exists('module_group', false) && isset(self::$pagination_options['group']) && self::$pagination_options['group']) { // find groups for this entry foreach (self::$pagination_options['group'] as $group_search) { echo '"' . str_replace('"', '""', $group_search['title']) . '",'; } } echo "\n"; foreach ($rows as $row) { foreach ($fields as $key => $val) { echo '"' . str_replace('"', '""', isset($row[$val]) ? $row[$val] : '') . '",'; } // check for extra fields. if (class_exists('module_extra', false) && isset(self::$pagination_options['extra']) && count(self::$pagination_options['extra'])) { foreach (self::$pagination_options['extra'] as $extra_field_id => $extra_field_settings) { $extra_vals = array(); if (isset($row[$extra_field_settings['owner_id']]) && $row[$extra_field_settings['owner_id']] > 0) { $sql = "SELECT `extra_key` AS `id`, `extra` FROM `" . _DB_PREFIX . "extra` WHERE owner_table = '" . mysql_real_escape_string($extra_field_settings['owner_table']) . "' AND `owner_id` = '" . (int) $row[$extra_field_settings['owner_id']] . "' ORDER BY `extra_key`"; $extra_vals = qa($sql); } foreach ($extra_field_settings['extra_fields'] as $extra_field) { echo '"'; echo isset($extra_vals[$extra_field['extra_key']]) ? str_replace('"', '""', $extra_vals[$extra_field['extra_key']]['extra']) : ''; echo '",'; } } } // check for group fields. if (class_exists('module_group', false) && isset(self::$pagination_options['group']) && self::$pagination_options['group']) { // find groups for this entry foreach (self::$pagination_options['group'] as $group_search) { $g = array(); $groups = module_group::get_groups_search(array('owner_table' => $group_search['owner_table'], 'owner_id' => isset($row[$group_search['owner_id']]) ? $row[$group_search['owner_id']] : 0)); foreach ($groups as $group) { $g[] = $group['name']; } echo '"' . str_replace('"', '""', implode(', ', $g)) . '",'; } } echo "\n"; } // is there a summary to add at the end of the export? if (isset(self::$pagination_options['summary']) && is_array(self::$pagination_options['summary'])) { foreach (self::$pagination_options['summary'] as $summary_row) { foreach ($fields as $key => $val) { echo '"'; if (isset($summary_row[$val])) { echo $summary_row[$val]; } echo '",'; } echo "\n"; } } $csv = ob_get_clean(); if (module_config::c('export_csv_debug', 0)) { echo '<pre>' . $csv . '</pre>'; exit; } header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Type: text/csv"); //todo: correct file name header("Content-Disposition: attachment; filename=\"" . (isset(self::$pagination_options['name']) ? self::$pagination_options['name'] . '.csv' : 'Export.csv') . "\";"); header("Content-Transfer-Encoding: binary"); // todo: calculate file size with ob buffering header("Content-Length: " . strlen($csv)); echo $csv; exit; } } }
/** * @param $invoice_id * @param $invoice_data * @return array * * todo: make this method call the other 'get_replace_fields' available in website/job/etc.. */ public static function get_replace_fields($invoice_id, $invoice_data = false) { if (!$invoice_data) { $invoice_data = self::get_invoice($invoice_id); } $customer_data = array(); if ($invoice_data['customer_id']) { $customer_data = module_customer::get_replace_fields($invoice_data['customer_id'], $invoice_data['user_id']); } if (!is_array($customer_data)) { $customer_data = array(); } $data = array_merge($customer_data, $invoice_data); // so we get total_amount_due and stuff. $data = array_merge($data, array('invoice_number' => htmlspecialchars($invoice_data['name']), 'project_type' => _l(module_config::c('project_name_single', 'Website')), 'print_link' => self::link_public_print($invoice_id), 'title' => module_config::s('admin_system_name'), 'invoice_paid' => $invoice_data['total_amount_due'] <= 0 ? '<p> <font style="font-size: 1.6em;"><strong>' . _l('INVOICE PAID') . '</strong></font> </p>' : '', 'is_invoice_paid' => $invoice_data['total_amount_due'] <= 0 ? 1 : '', 'date_create' => print_date($invoice_data['date_create']), 'due_date' => print_date($invoice_data['date_due']))); $data['total_amount'] = dollar($invoice_data['total_amount'], true, $invoice_data['currency_id']); $data['total_amount_due'] = dollar($invoice_data['total_amount_due'], true, $invoice_data['currency_id']); $data['total_amount_paid'] = dollar($invoice_data['total_amount_paid'], true, $invoice_data['currency_id']); $data['date_paid'] = print_date($invoice_data['date_paid']); $data['date_due'] = print_date($invoice_data['date_due']); $data['date_sent'] = print_date($invoice_data['date_sent']); $data['invoice_number'] = $invoice_data['name']; $data['invoice_url'] = module_invoice::link_public($invoice_id); $data['invoice_date_range'] = ''; if ($invoice_data['date_renew'] != '0000-00-00') { $data['invoice_date_range'] = _l('%s to %s', print_date($invoice_data['date_create']), print_date(strtotime("-1 day", strtotime($invoice_data['date_renew'])))); } if (isset($invoice_data['credit_note_id']) && $invoice_data['credit_note_id']) { $credit_invoice = module_invoice::get_invoice($invoice_data['credit_note_id'], true); $data['credit_invoice_number'] = htmlspecialchars($credit_invoice['name']); } $data['invoice_notes'] = ''; // grab any public notes if (class_exists('module_note', false) && module_note::is_plugin_enabled()) { $notes = module_note::get_notes(array('public' => 1, 'owner_table' => 'invoice', 'owner_id' => $invoice_id)); if (count($notes) > 1) { $data['invoice_notes'] .= '<ul>'; foreach ($notes as $note) { if ($note['public']) { $data['invoice_notes'] .= '<li>'; $data['invoice_notes'] .= htmlspecialchars($note['note']); $data['invoice_notes'] .= '</li>'; } } $data['invoice_notes'] .= '</ul>'; } else { $note = array_shift($notes); $data['invoice_notes'] .= htmlspecialchars($note['note']); } } $job_names = $website_url = $project_names = $project_names_and_url = array(); foreach ($invoice_data['job_ids'] as $job_id) { $job_data = module_job::get_job($job_id); if ($job_data && $job_data['job_id'] == $job_id) { $job_names[$job_data['job_id']] = $job_data['name']; if (module_config::c('job_invoice_show_date_range', 1)) { // check if this job is a renewable job. if ($job_data['date_renew'] != '0000-00-00') { $data['invoice_date_range'] = _l('%s to %s', print_date($job_data['date_start']), print_date(strtotime("-1 day", strtotime($job_data['date_renew'])))); } } $fields = module_job::get_replace_fields($job_id, $job_data); foreach ($fields as $key => $val) { if (!isset($data[$key]) || !$data[$key] && $val) { $data[$key] = $val; } } if ($job_data['website_id']) { $website_data = module_website::get_website($job_data['website_id']); if ($website_data && $website_data['website_id'] == $job_data['website_id']) { if (isset($website_data['url']) && $website_data['url']) { $website_url[$website_data['website_id']] = module_website::urlify($website_data['url']); $website_data['name_url'] = $website_data['name'] . ' (' . module_website::urlify($website_data['url']) . ')'; } else { $website_data['name_url'] = $website_data['name']; } $project_names[$website_data['website_id']] = $website_data['name']; $project_names_and_url[$website_data['website_id']] = $website_data['name_url']; $fields = module_website::get_replace_fields($website_data['website_id'], $website_data); foreach ($fields as $key => $val) { if (!isset($data[$key]) || !$data[$key] && $val) { $data[$key] = $val; } } } } } } if (isset($invoice_data['website_id']) && $invoice_data['website_id']) { $website_data = module_website::get_website($invoice_data['website_id']); if ($website_data && $website_data['website_id'] == $invoice_data['website_id']) { if (isset($website_data['url']) && $website_data['url']) { $website_url[$website_data['website_id']] = module_website::urlify($website_data['url']); $website_data['name_url'] = $website_data['name'] . ' (' . module_website::urlify($website_data['url']) . ')'; } else { $website_data['name_url'] = $website_data['name']; } $project_names[$website_data['website_id']] = $website_data['name']; $project_names_and_url[$website_data['website_id']] = $website_data['name_url']; $fields = module_website::get_replace_fields($website_data['website_id'], $website_data); foreach ($fields as $key => $val) { if (!isset($data[$key]) || !$data[$key] && $val) { $data[$key] = $val; } } } } $data['website_name'] = $data['project_name'] = forum_text(count($project_names) ? implode(', ', $project_names) : ''); $data['website_name_url'] = forum_text(count($project_names_and_url) ? implode(', ', $project_names_and_url) : ''); $data['website_url'] = forum_text(count($website_url) ? implode(', ', $website_url) : ''); $data['job_name'] = forum_text($job_names ? implode(', ', $job_names) : ''); if (class_exists('module_group', false)) { // get the job groups $wg = array(); $g = array(); foreach ($invoice_data['job_ids'] as $group_job_id) { $group_job_id = (int) trim($group_job_id); if ($group_job_id > 0) { $job_data = module_job::get_job($group_job_id); foreach (module_group::get_groups_search(array('owner_table' => 'job', 'owner_id' => $group_job_id)) as $group) { $g[$group['group_id']] = $group['name']; } // get the website groups if ($job_data['website_id']) { foreach (module_group::get_groups_search(array('owner_table' => 'website', 'owner_id' => $job_data['website_id'])) as $group) { $wg[$group['group_id']] = $group['name']; } } } } if (isset($invoice_data['website_id']) && $invoice_data['website_id']) { foreach (module_group::get_groups_search(array('owner_table' => 'website', 'owner_id' => $invoice_data['website_id'])) as $group) { $wg[$group['group_id']] = $group['name']; } } $data['job_group'] = implode(', ', $g); $data['website_group'] = implode(', ', $wg); } // addition. find all extra keys for this invoice and add them in. // we also have to find any EMPTY extra fields, and add those in as well. if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) { $all_extra_fields = module_extra::get_defaults('invoice'); foreach ($all_extra_fields as $e) { $data[$e['key']] = _l('N/A'); } // and find the ones with values: $extras = module_extra::get_extras(array('owner_table' => 'invoice', 'owner_id' => $invoice_id)); foreach ($extras as $e) { $data[$e['extra_key']] = $e['extra']; } } $new_data = hook_handle_callback('invoice_replace_fields', $invoice_id, $data); if (is_array($new_data)) { foreach ($new_data as $new_d) { $data = array_merge($data, $new_d); } } return $data; }
public static function get_replace_fields($job_id, $job_data = false) { if (!$job_data) { $job_data = self::get_job($job_id); } $data = array('job_number' => htmlspecialchars($job_data['name']), 'project_type' => _l(module_config::c('project_name_single', 'Website')), 'print_link' => self::link_public($job_id), 'title' => module_config::s('admin_system_name'), 'due_date' => print_date($job_data['date_due'])); // $customer_data = $job_data['customer_id'] ? module_customer::get_replace_fields($job_data['customer_id']) : array(); // $website_data = $job_data['website_id'] ? module_website::get_replace_fields($job_data['website_id']) : array(); // $data = array_merge($data,$customer_data,$website_data,$job_data); $data = array_merge($data, $job_data); if (class_exists('module_group', false) && module_group::is_plugin_enabled()) { // get the job groups $wg = array(); $g = array(); if ($job_id > 0) { $job_data = module_job::get_job($job_id); foreach (module_group::get_groups_search(array('owner_table' => 'job', 'owner_id' => $job_id)) as $group) { $g[$group['group_id']] = $group['name']; } /*// get the website groups foreach(module_group::get_groups_search(array( 'owner_table' => 'website', 'owner_id' => $job_data['website_id'], )) as $group){ $wg[$group['group_id']] = $group['name']; }*/ } $data['job_group'] = implode(', ', $g); /*$data['website_group'] = implode(', ',$wg);*/ } // addition. find all extra keys for this job and add them in. // we also have to find any EMPTY extra fields, and add those in as well. if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) { $all_extra_fields = module_extra::get_defaults('job'); foreach ($all_extra_fields as $e) { $data[$e['key']] = _l('N/A'); } // and find the ones with values: $extras = module_extra::get_extras(array('owner_table' => 'job', 'owner_id' => $job_id)); foreach ($extras as $e) { $data[$e['extra_key']] = $e['extra']; } } // also do this for customer fields /*if($job_data['customer_id']){ $all_extra_fields = module_extra::get_defaults('customer'); foreach($all_extra_fields as $e){ $data[$e['key']] = _l('N/A'); } $extras = module_extra::get_extras(array('owner_table'=>'customer','owner_id'=>$job_data['customer_id'])); foreach($extras as $e){ $data[$e['extra_key']] = $e['extra']; } }*/ return $data; }
} }); $columns['primary_contact_email'] = array('title' => 'Email Address', 'callback' => function ($customer) { if ($customer['primary_user_id']) { module_user::print_contact_summary($customer['primary_user_id'], 'html', array('email')); } else { echo ''; } }); if (class_exists('module_group', false) && module_customer::can_i('view', $page_type_single . ' Groups')) { $columns['customer_group'] = array('title' => 'Group', 'callback' => function ($customer) { if (isset($customer['group_sort_customer'])) { echo htmlspecialchars($customer['group_sort_customer']); } else { // find the groups for this customer. $groups = module_group::get_groups_search(array('owner_table' => 'customer', 'owner_id' => $customer['customer_id'])); $g = array(); foreach ($groups as $group) { $g[] = $group['name']; } echo htmlspecialchars(implode(', ', $g)); } }); } if (class_exists('module_invoice', false) && module_invoice::can_i('view', 'Invoices') && module_config::c('customer_list_show_invoices', 1)) { $columns['customer_invoices'] = array('title' => 'Invoices', 'callback' => function ($customer) { $invoices = module_invoice::get_invoices(array('customer_id' => $customer['customer_id'])); if (count($invoices)) { $total_due = 0; $total_paid = 0; foreach ($invoices as $invoice) {
public static function run_pagination_hook(&$rows, &$per_page) { if (self::$table_sort_options) { self::is_currently_sorting(); // loads the session data. $new_sort_column = $new_sort_direction = $new_sort_per_page = false; if (isset($_SESSION['_table_sort']) && isset($_SESSION['_table_sort'][self::$table_sort_options['table_id']]) && isset($_SESSION['_table_sort'][self::$table_sort_options['table_id']][0])) { $new_sort_column = $_SESSION['_table_sort'][self::$table_sort_options['table_id']][0]; } if (isset($_SESSION['_table_sort']) && isset($_SESSION['_table_sort'][self::$table_sort_options['table_id']]) && isset($_SESSION['_table_sort'][self::$table_sort_options['table_id']][1])) { $new_sort_direction = $_SESSION['_table_sort'][self::$table_sort_options['table_id']][1]; } if (isset($_SESSION['_table_sort']) && isset($_SESSION['_table_sort'][self::$table_sort_options['table_id']]) && isset($_SESSION['_table_sort'][self::$table_sort_options['table_id']][2])) { $new_sort_per_page = $_SESSION['_table_sort'][self::$table_sort_options['table_id']][2]; } // count how many results for the "per page" drop down below. self::$table_sort_options['row_count'] = is_resource($rows) ? mysql_num_rows($rows) : count($rows); if (!isset($_SESSION['_table_sort']) || !isset($_SESSION['_table_sort'][self::$table_sort_options['table_id']])) { return; } if ($new_sort_column && $new_sort_direction) { // clear defaults! time for a user defined one. foreach (self::$table_sort_options['sortable'] as $column_id => $options) { if (isset($options['current'])) { unset(self::$table_sort_options['sortable'][$column_id]['current']); } if ($column_id == $new_sort_column) { self::$table_sort_options['sortable'][$column_id]['current'] = $new_sort_direction; } } } if ($new_sort_per_page >= 1) { $per_page = $new_sort_per_page; } else { if ($new_sort_per_page == -2) { // special flag for "all" $per_page = false; } } if (!$new_sort_column) { return; } // sort results by selected option. if (is_resource($rows)) { $new_rows = array(); while ($row = mysql_fetch_assoc($rows)) { $new_rows[] = $row; } mysql_free_result($rows); $rows = $new_rows; } else { // rows stays the same. } if (is_array($rows) && count($rows)) { foreach (self::$table_sort_options['sortable'] as $column_id => $options) { if (isset($options['current'])) { // we have a sortable key! yay! // is this a special "group sort" ? if (isset($options['group_sort']) && $options['group_sort'] && $options['owner_table'] && $options['owner_id']) { // find the group(s) for EVERY row in the result set. // this is super slow, but only way to sort. // we also sort multiple groups in the same order that is selected here. if (class_exists('module_group', false)) { foreach ($rows as $row_id => $row) { if (!isset($row[$options['owner_id']]) || !$row[$options['owner_id']]) { continue; } // find the groups for this customer. $groups = module_group::get_groups_search(array('owner_table' => $options['owner_table'], 'owner_id' => $row[$options['owner_id']])); $g = array(); foreach ($groups as $group) { $g[] = $group['name']; } natcasesort($g); if ($options['current'] == 1) { // ascendine } else { // descenting $g = array_reverse($g); } $rows[$row_id]['group_sort_' . $options['owner_table']] = implode($g, ', '); } self::$sortables['group_sort_' . $options['owner_table']] = $options['current']; } } else { if (isset($options['extra_sort']) && $options['extra_sort'] && $options['owner_table'] && $options['owner_id']) { // find the extra(s) for EVERY row in the result set. // this is super slow, but only way to sort. // we also sort multiple extras in the same order that is selected here. if (class_exists('module_extra', false)) { foreach ($rows as $row_id => $row) { if (!isset($row[$options['owner_id']]) || !$row[$options['owner_id']]) { continue; } // find the extras for this customer. $extras = module_extra::get_extras(array('owner_table' => $options['owner_table'], 'owner_id' => $row[$options['owner_id']], 'extra_key' => $options['field'])); if (count($extras) == 1) { // found a match! $extra_val = current($extras); if (isset($options['field_type']) && $options['field_type'] == 'date') { $extra_val['extra'] = input_date($extra_val['extra']); } $rows[$row_id]['extra_header_' . $options['default_field_id']] = $extra_val['extra']; } } self::$sortables['extra_header_' . $options['default_field_id']] = $options['current']; } } else { // nope! yay! normal sort. self::$sortables[$options['field']] = $options['current']; } } } } uasort($rows, array('module_table_sort', 'dosort')); } // set the 'per page' value based on session setting. } }
public static function get_replace_fields($quote_id, $quote_data = false) { if (!$quote_data) { $quote_data = self::get_quote($quote_id); } $data = array('quote_number' => htmlspecialchars($quote_data['name']), 'quote_name' => htmlspecialchars($quote_data['name']), 'project_type' => _l(module_config::c('project_name_single', 'Website')), 'print_link' => self::link_public_print($quote_id), 'quote_url' => self::link_public($quote_id), 'title' => module_config::s('admin_system_name'), 'create_date' => print_date($quote_data['date_create'])); if (isset($quote_data['customer_id']) && $quote_data['customer_id']) { $customer_data = module_customer::get_replace_fields($quote_data['customer_id'], $quote_data['contact_user_id'] ? $quote_data['contact_user_id'] : false); $data = array_merge($data, $customer_data); // so we get total_amount_due and stuff. } $user_details = array('staff_first_name' => '', 'staff_last_name' => '', 'staff_email' => '', 'staff_phone' => '', 'staff_fax' => '', 'staff_mobile' => ''); if (isset($quote_data['user_id']) && $quote_data['user_id']) { $user_data = module_user::get_user($quote_data['user_id'], false); if ($user_data && $user_data['user_id'] == $quote_data['user_id']) { $user_details = array('staff_first_name' => $user_data['name'], 'staff_last_name' => $user_data['last_name'], 'staff_email' => $user_data['email'], 'staff_phone' => $user_data['phone'], 'staff_fax' => $user_data['fax'], 'staff_mobile' => $user_data['mobile']); } } $data = array_merge($data, $user_details); foreach ($quote_data as $key => $val) { if (strpos($key, 'date') !== false) { $quote_data[$key] = print_date($val); } } if (isset($quote_data['description'])) { $quote_data['description'] = module_security::purify_html($quote_data['description']); } // $customer_data = $quote_data['customer_id'] ? module_customer::get_replace_fields($quote_data['customer_id']) : array(); // $website_data = $quote_data['website_id'] ? module_website::get_replace_fields($quote_data['website_id']) : array(); // $data = array_merge($data,$customer_data,$website_data,$quote_data); $data = array_merge($data, $quote_data); $website_url = $project_names = $project_names_and_url = array(); if ($quote_data['website_id']) { $website_data = module_website::get_website($quote_data['website_id']); if ($website_data && $website_data['website_id'] == $quote_data['website_id']) { if (isset($website_data['url']) && $website_data['url']) { $website_url[$website_data['website_id']] = module_website::urlify($website_data['url']); $website_data['name_url'] = $website_data['name'] . ' (' . module_website::urlify($website_data['url']) . ')'; } else { $website_data['name_url'] = $website_data['name']; } $project_names[$website_data['website_id']] = $website_data['name']; $project_names_and_url[$website_data['website_id']] = $website_data['name_url']; $fields = module_website::get_replace_fields($website_data['website_id'], $website_data); foreach ($fields as $key => $val) { if (!isset($data[$key]) || !$data[$key] && $val) { $data[$key] = $val; } } } } $data['website_name'] = $data['project_name'] = forum_text(count($project_names) ? implode(', ', $project_names) : ''); $data['website_name_url'] = forum_text(count($project_names_and_url) ? implode(', ', $project_names_and_url) : ''); $data['website_url'] = forum_text(count($website_url) ? implode(', ', $website_url) : ''); if (class_exists('module_group', false) && module_group::is_plugin_enabled()) { // get the quote groups $wg = array(); $g = array(); if ($quote_id > 0) { $quote_data = module_quote::get_quote($quote_id); foreach (module_group::get_groups_search(array('owner_table' => 'quote', 'owner_id' => $quote_id)) as $group) { $g[$group['group_id']] = $group['name']; } /*// get the website groups foreach(module_group::get_groups_search(array( 'owner_table' => 'website', 'owner_id' => $quote_data['website_id'], )) as $group){ $wg[$group['group_id']] = $group['name']; }*/ } $data['quote_group'] = implode(', ', $g); /*$data['website_group'] = implode(', ',$wg);*/ } // addition. find all extra keys for this quote and add them in. // we also have to find any EMPTY extra fields, and add those in as well. if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) { $all_extra_fields = module_extra::get_defaults('quote'); foreach ($all_extra_fields as $e) { $data[$e['key']] = _l('N/A'); } // and find the ones with values: $extras = module_extra::get_extras(array('owner_table' => 'quote', 'owner_id' => $quote_id)); foreach ($extras as $e) { $data[$e['extra_key']] = $e['extra']; } } // also do this for customer fields /*if($quote_data['customer_id']){ $all_extra_fields = module_extra::get_defaults('customer'); foreach($all_extra_fields as $e){ $data[$e['key']] = _l('N/A'); } $extras = module_extra::get_extras(array('owner_table'=>'customer','owner_id'=>$quote_data['customer_id'])); foreach($extras as $e){ $data[$e['extra_key']] = $e['extra']; } }*/ return $data; }
} if (class_exists('module_group', false)) { $columns['member_group'] = array('title' => 'Group', 'callback' => function ($member) { // find the groups for this member. $g = array(); $groups = module_group::get_groups_search(array('owner_table' => 'member', 'owner_id' => $member['member_id'])); foreach ($groups as $group) { $g[] = $group['name']; } echo implode(', ', $g); }); if (class_exists('module_newsletter', false)) { $columns['member_newsletter'] = array('title' => 'Newsletter', 'callback' => function ($member) { // find the groups for this member. $g = array(); $groups = module_group::get_groups_search(array('owner_table' => 'newsletter_subscription', 'owner_id' => $member['member_id'])); foreach ($groups as $group) { $g[] = $group['name']; } echo implode(', ', $g); echo ' '; $newsletter_member_id = module_newsletter::member_from_email($member, false); if ($newsletter_member_id) { if ($res = module_newsletter::is_member_unsubscribed($newsletter_member_id, $member)) { if (isset($res['unsubscribe_send_id']) && $res['unsubscribe_send_id']) { // they unsubscribed from a send. $send_data = module_newsletter::get_send($res['unsubscribe_send_id']); _e('(unsubscribed %s)', print_date($res['time'])); } else { if (isset($res['reason']) && $res['reason'] == 'no_email') { _e('(do not send)');
echo $faq_product && isset($faq_product['name']) ? htmlspecialchars($faq_product['name']) : ''; } }); } if (class_exists('module_envato', false)) { $columns['ticket_envato'] = array('title' => _l('Envato%s', module_config::c('envato_show_ticket_earning', 0) ? ' (' . dollar($envato_count * 0.7) . ')' : ''), 'callback' => function ($ticket) { $items = module_envato::get_items_by_ticket($ticket['ticket_id']); foreach ($items as $item) { echo '<a href="' . $item['url'] . '">' . htmlspecialchars($item['name']) . '</a> '; } }); } if (class_exists('module_group', false) && module_config::c('ticket_enable_groups', 1) && module_group::groups_enabled()) { $columns['ticket_group'] = array('title' => 'Group', 'callback' => function ($ticket) { // find the groups for this customer. $groups = module_group::get_groups_search(array('owner_table' => 'ticket', 'owner_id' => $ticket['ticket_id'])); $g = array(); foreach ($groups as $group) { $g[] = $group['name']; } echo implode(', ', $g); }); } if (module_config::c('ticket_allow_priority', 0) && module_config::c('ticket_show_priority', 1)) { $columns['ticket_priority'] = array('title' => 'Priority', 'callback' => function ($ticket) use($priorities) { echo $priorities[$ticket['priority']]; }); } if (module_ticket::can_edit_tickets()) { $columns['ticket_action'] = array('title' => ' <input type="checkbox" name="bulk_operation_all" id="bulk_operation_all" value="yehaw" > ', 'callback' => function ($ticket) { echo '<input type="checkbox" name="bulk_operation[' . $ticket['ticket_id'] . ']" class="ticket_bulk_check" value="yes">';
} if (!isset($_REQUEST['customer_id']) && module_customer::can_i('view', 'Customers')) { $columns['website_customer'] = array('title' => 'Customer', 'callback' => function ($website) { echo module_customer::link_open($website['customer_id'], true); }); } $columns['website_status'] = array('title' => 'Status', 'callback' => function ($website) { echo htmlspecialchars($website['status']); }); if (class_exists('module_group', false)) { $columns['website_group'] = array('title' => 'Group', 'callback' => function ($website) { if (isset($website['group_sort_website'])) { echo htmlspecialchars($website['group_sort_website']); } else { // find the groups for this website. $groups = module_group::get_groups_search(array('owner_table' => 'website', 'owner_id' => $website['website_id'])); $g = array(); foreach ($groups as $group) { $g[] = $group['name']; } echo htmlspecialchars(implode(', ', $g)); } }); } if (class_exists('module_extra', false)) { $table_manager->display_extra('website', function ($website) { module_extra::print_table_data('website', $website['website_id']); }); } if (class_exists('module_subscription', false)) { $table_manager->display_subscription('website', function ($website) {
public static function get_replace_fields($customer_id, $primary_user_id = false) { $customer_data = module_customer::get_customer($customer_id); $address_combined = array(); if (isset($customer_data['customer_address'])) { foreach ($customer_data['customer_address'] as $key => $val) { if (strlen(trim($val))) { $address_combined[$key] = $val; } } } // do we use the primary contact or $contact_data = module_user::get_user($primary_user_id ? $primary_user_id : $customer_data['primary_user_id']); //print_r($contact_data);exit; if ($contact_data && $contact_data['customer_id'] != $customer_id && (!isset($contact_data['linked_parent_user_id']) || !$contact_data['linked_parent_user_id'])) { $contact_data = array('user_id' => 0, 'customer_id' => 0, 'name' => '', 'last_name' => '', 'email' => '', 'password' => '', 'phone' => '', 'mobile' => '', 'fax' => ''); } $data = array('customer_details' => ' - todo - ', 'customer_name' => isset($customer_data['customer_name']) ? htmlspecialchars($customer_data['customer_name']) : _l('N/A'), 'customer_address' => htmlspecialchars(implode(', ', $address_combined)), 'contact_name' => $contact_data['name'] != $contact_data['email'] ? htmlspecialchars($contact_data['name'] . ' ' . $contact_data['last_name']) : '', 'contact_first_name' => $contact_data['name'], 'contact_last_name' => $contact_data['last_name'], 'first_name' => $contact_data['name'], 'last_name' => $contact_data['last_name'], 'contact_email' => htmlspecialchars($contact_data['email']), 'contact_phone' => htmlspecialchars($contact_data['phone']), 'contact_mobile' => htmlspecialchars($contact_data['mobile']), 'customer_invoice_prefix' => isset($customer_data['default_invoice_prefix']) ? $customer_data['default_invoice_prefix'] : ''); $data = array_merge($customer_data, $data); foreach ($customer_data['customer_address'] as $key => $val) { $data['address_' . $key] = $val; } if (class_exists('module_group', false) && module_group::is_plugin_enabled()) { // get the customer groups $g = array(); if ((int) $customer_data['customer_id'] > 0) { foreach (module_group::get_groups_search(array('owner_table' => 'customer', 'owner_id' => $customer_data['customer_id'])) as $group) { $g[] = $group['name']; } } $data['customer_group'] = implode(', ', $g); // get the customer groups $g = array(); if ($customer_id > 0) { $customer_data = module_customer::get_customer($customer_id); foreach (module_group::get_groups_search(array('owner_table' => 'customer', 'owner_id' => $customer_id)) as $group) { $g[$group['group_id']] = $group['name']; } } $data['customer_group'] = implode(', ', $g); } // addition. find all extra keys for this customer and add them in. // we also have to find any EMPTY extra fields, and add those in as well. if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) { $all_extra_fields = module_extra::get_defaults('customer'); foreach ($all_extra_fields as $e) { $data[$e['key']] = _l('N/A'); } // and find the ones with values: $extras = module_extra::get_extras(array('owner_table' => 'customer', 'owner_id' => $customer_id)); foreach ($extras as $e) { $data[$e['extra_key']] = $e['extra']; } // and the primary contact $all_extra_fields = module_extra::get_defaults('user'); foreach ($all_extra_fields as $e) { $data[$e['key']] = _l('N/A'); } if ($contact_data && $contact_data['user_id']) { // and find the ones with values: $extras = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $contact_data['user_id'])); foreach ($extras as $e) { $data[$e['extra_key']] = $e['extra']; } } } return $data; }
if ($vendor['primary_user_id']) { module_user::print_contact_summary($vendor['primary_user_id'], 'html', array('email')); } else { echo ''; } }); $columns['address'] = array('title' => 'Address', 'callback' => function ($vendor) { module_address::print_address($vendor['vendor_id'], 'vendor', 'physical'); }); if (class_exists('module_group', false) && module_vendor::can_i('view', $page_type_single . ' Groups')) { $columns['vendor_group'] = array('title' => 'Group', 'callback' => function ($vendor) { if (isset($vendor['group_sort_vendor'])) { echo htmlspecialchars($vendor['group_sort_vendor']); } else { // find the groups for this vendor. $groups = module_group::get_groups_search(array('owner_table' => 'vendor', 'owner_id' => $vendor['vendor_id'])); $g = array(); foreach ($groups as $group) { $g[] = $group['name']; } echo htmlspecialchars(implode(', ', $g)); } }); } $table_manager->set_columns($columns); $table_manager->row_callback = function ($row_data) { // load the full vendor data before displaying each row so we have access to more details return module_vendor::get_vendor($row_data['vendor_id']); }; $table_manager->set_rows($vendors); if (class_exists('module_extra', false)) {
echo ' ' . _l('due'); } else { echo _l('%s paid', dollar($invoice['total_amount'], true, $invoice['currency_id'])); } echo '</span>'; echo "<br>"; } }); } if (class_exists('module_group', false)) { $columns['job_group'] = array('title' => 'Group', 'callback' => function ($job) { if (isset($job['group_sort_job'])) { echo htmlspecialchars($job['group_sort_job']); } else { // find the groups for this job. $groups = module_group::get_groups_search(array('owner_table' => 'job', 'owner_id' => $job['job_id'])); $g = array(); foreach ($groups as $group) { $g[] = $group['name']; } echo htmlspecialchars(implode(', ', $g)); } }); } if (class_exists('module_extra', false)) { $table_manager->display_extra('job', function ($job) { module_extra::print_table_data('job', $job['job_id']); }, 'job_id'); } $table_manager->enable_table_sorting(array('table_id' => 'job_list', 'sortable' => array('job_title' => array('field' => 'name', 'current' => 1), 'job_start_date' => array('field' => 'date_start'), 'job_due_date' => array('field' => 'date_due'), 'job_completed_date' => array('field' => 'date_completed'), 'job_website' => array('field' => 'website_name'), 'job_customer' => array('field' => 'customer_name'), 'job_type' => array('field' => 'type'), 'job_status' => array('field' => 'status'), 'job_progress' => array('field' => 'total_percent_complete'), 'job_total' => array('field' => 'total_amount'), 'job_total_amount_invoiced' => array('field' => 'total_amount_invoiced'), 'job_group' => array('group_sort' => true, 'owner_table' => 'job', 'owner_id' => 'job_id')))); if (class_exists('module_table_sort', false)) {
public static function get_replace_fields($website_id, $website_data = false) { if (!$website_data) { $website_data = self::get_website($website_id); } $data = array('website_name' => $website_data['name'], 'website_url' => self::urlify($website_data['url'])); $data = array_merge($data, $website_data); if (class_exists('module_group', false)) { // get the website groups $g = array(); if ($website_id > 0) { $website_data = module_website::get_website($website_id); foreach (module_group::get_groups_search(array('owner_table' => 'website', 'owner_id' => $website_id)) as $group) { $g[$group['group_id']] = $group['name']; } } $data['website_group'] = implode(', ', $g); } // addition. find all extra keys for this website and add them in. // we also have to find any EMPTY extra fields, and add those in as well. $all_extra_fields = module_extra::get_defaults('website'); foreach ($all_extra_fields as $e) { $data[$e['key']] = _l('N/A'); } // and find the ones with values: $extras = module_extra::get_extras(array('owner_table' => 'website', 'owner_id' => $website_id)); foreach ($extras as $e) { $data[$e['extra_key']] = $e['extra']; } return $data; }