public function renew_invoice($invoice_id) { $invoice = $this->get_invoice($invoice_id); if (strtotime($invoice['date_renew']) <= strtotime('+' . module_config::c('alert_days_in_future', 5) . ' days')) { // /we are allowed to renew. unset($invoice['invoice_id']); // work out the difference in start date and end date and add that new renewl date to the new order. $time_diff = strtotime($invoice['date_renew']) - strtotime($invoice['date_create']); if ($time_diff > 0) { // our renewal date is something in the future. if (!$invoice['date_create'] || $invoice['date_create'] == '0000-00-00') { set_message('Please set a invoice create date before renewing'); redirect_browser($this->link_open($invoice_id)); } // if the time_diff is 28, 29, 30 or 31 days then we stick to the same day a month in the future. if (module_config::c('invoice_renew_monthly_fix', 1) && $time_diff >= 2419100 && $time_diff <= 2678500) { $new_renewal_date = date('Y-m-d', strtotime("+1 month", strtotime($invoice['date_renew']))); } else { // work out the next renewal date. $new_renewal_date = date('Y-m-d', strtotime($invoice['date_renew']) + $time_diff); } $invoice['name'] = self::new_invoice_number($invoice['customer_id']); $invoice['date_create'] = $invoice['date_renew']; $invoice['date_renew'] = $new_renewal_date; $invoice['date_sent'] = false; $invoice['date_paid'] = false; $invoice['deposit_job_id'] = 0; if (module_config::c('invoice_renew_discounts', 0)) { // keep the discounts from previous invoices. } else { // clear the discounts back to defaults. $invoice['discount_amount'] = 0; $invoice['discount_description'] = _l('Discount:'); $invoice['discount_type'] = !isset($invoice['discount_type']) ? module_config::c('invoice_discount_type', _DISCOUNT_TYPE_BEFORE_TAX) : $invoice['discount_type']; // 1 = After Tax } $invoice['tax_type'] = !isset($invoice['tax_type']) ? module_config::c('invoice_tax_type', 0) : $invoice['tax_type']; $invoice['date_due'] = date('Y-m-d', strtotime('+' . module_config::c('invoice_due_days', 30) . ' days', strtotime($invoice['date_create']))); $invoice['status'] = module_config::s('invoice_status_default', 'New'); // todo: copy the "more" listings over to the new invoice // todo: copy any notes across to the new listing. // hack to copy the 'extra' fields across to the new invoice. // save_invoice() does the extra handling, and if we don't do this // then it will move the extra fields from the original invoice to this new invoice. if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) { $owner_table = 'invoice'; // get extra fields from this invoice $extra_fields = module_extra::get_extras(array('owner_table' => $owner_table, 'owner_id' => $invoice_id)); $x = 1; foreach ($extra_fields as $extra_field) { $_REQUEST['extra_' . $owner_table . '_field']['new' . $x] = array('key' => $extra_field['extra_key'], 'val' => $extra_field['extra']); $x++; } } // taxes copy across if (isset($invoice['taxes']) && is_array($invoice['taxes'])) { $invoice['tax_ids'] = array(); $invoice['tax_names'] = array(); $invoice['tax_percents'] = array(); foreach ($invoice['taxes'] as $tax) { $invoice['tax_ids'][] = 0; $invoice['tax_names'][] = $tax['name']; $invoice['tax_percents'][] = $tax['percent']; if ($tax['increment']) { $invoice['tax_increment_checkbox'] = 1; } } } $new_invoice_id = $this->save_invoice('new', $invoice); if ($new_invoice_id) { // now we create the tasks $tasks = $this->get_invoice_items($invoice_id); foreach ($tasks as $task) { unset($task['invoice_item_id']); if ($task['custom_description']) { $task['description'] = $task['custom_description']; } if ($task['custom_long_description']) { $task['long_description'] = $task['custom_long_description']; } $task['invoice_id'] = $new_invoice_id; $task['date_done'] = $invoice['date_create']; update_insert('invoice_item_id', 'new', 'invoice_item', $task); } // link this up with the old one. update_insert('invoice_id', $invoice_id, 'invoice', array('renew_invoice_id' => $new_invoice_id)); } module_cache::clear('invoice'); return $new_invoice_id; } } return false; }
public function external_hook($hook) { switch ($hook) { case 'view': $file_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false; if ($file_id && $hash) { $correct_hash = $this->link_public($file_id, true); if ($correct_hash == $hash) { // all good to print a receipt for this payment. $file_data = $this->get_file($file_id, false); if ($file_data && $file_data['file_id'] == $file_id) { if (isset($_POST['save_file_comments'])) { if (isset($_POST['file_approve']) && isset($_POST['file_approve_go']) && isset($_POST['file_approve_name']) && strlen($_POST['file_approve_name']) > 0) { update_insert('file_id', $file_id, 'file', array('approved_time' => time(), 'approved_by' => $_POST['file_approve_name'])); // send email, same 'updated' email as before. $this->send_file_changed_notice($file_id, false, true); //redirect_browser($this->link_public($file_id)); $_REQUEST['new_comment_text'] = _l('File was approved at %s by %s', print_date(time(), true), htmlspecialchars($_POST['file_approve_name'])); } if (isset($_POST['pointers'])) { update_insert('file_id', $file_id, 'file', array('pointers' => $_POST['pointers'])); } $this->save_file_comments($file_id); redirect_browser($this->link_public($file_id)); } module_template::init_template('file_approval_view', '<h2>File Details</h2> File Name: <strong>{FILE_NAME}</strong> <br/> Download: <strong><a href="{FILE_DOWNLOAD_URL}">Click Here</a></strong> <br/> Status: <strong>{STATUS}</strong> <br/> Customer: <strong>{CUSTOMER_NAME}</strong> <br/> {if:JOB_NAME}Job: <strong>{JOB_NAME}</strong> <br/>{endif:JOB_NAME} {if:FILE_APPROVAL_PENDING} <h2>File Approval Pending</h2> <p>If you would like to approve this file please complete the form below:</p> <p>Your Name: <input type="text" name="file_approve_name"> </p> <p><input type="checkbox" name="file_approve_go" value="yes"> Yes, I approve this file. </p> <p><input type="submit" name="file_approve" value="Approve File" class="submit_button save_button"></p> {endif:FILE_APPROVAL_PENDING} {if:FILE_APPROVED} <h2>File Has Been Approved</h2> <p>Thank you, the file was approved by <strong>{APPROVED_BY}</strong> on <strong>{APPROVED_TIME}</strong>.</p> {endif:FILE_APPROVED} <h2>File Comments</h2> <p>Please feel free to add comments to this file using the form below.</p> {FILE_COMMENTS} {if:FILE_PREVIEW} <h2>File Preview</h2> <div style="overflow:scroll;">{FILE_PREVIEW}</div> {endif:FILE_PREVIEW} ', 'Used when displaying the file to a customer for approval.', 'code'); $template = module_template::get_template_by_key('file_approval_view'); // generate the html for the task output $job_data = $file_data['job_id'] ? module_job::get_replace_fields($file_data['job_id']) : array(); if (class_exists('module_quote', false)) { $quote_data = $file_data['quote_id'] ? module_quote::get_replace_fields($file_data['quote_id']) : array(); } $customer_data = $file_data['customer_id'] ? module_customer::get_replace_fields($file_data['customer_id']) : array(); $file_data['file_preview'] = module_file::generate_preview($file_id, $file_data['file_name'], $file_data); $file_data['FILE_DOWNLOAD_URL'] = module_file::link_public_view($file_id); if (isset($file_data['approved_time'])) { switch ($file_data['approved_time']) { case -1: $file_data['FILE_APPROVAL_PENDING'] = 1; break; case 0: break; default: $file_data['FILE_APPROVED'] = 1; $file_data['APPROVED_TIME'] = print_date($file_data['approved_time'], true); } } if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) { $all_extra_fields = module_extra::get_defaults('file'); foreach ($all_extra_fields as $e) { $file_data[$e['key']] = _l('N/A'); } // and find the ones with values: $extras = module_extra::get_extras(array('owner_table' => 'file', 'owner_id' => $file_id)); foreach ($extras as $e) { $file_data[$e['extra_key']] = $e['extra']; } } ob_start(); ?> <div id="file_notes"> <div style="border-top:1px dashed #CCCCCC; padding:3px; margin:3px 0;"> <textarea name="new_comment_text" style="width:100%;" class="no_permissions"></textarea> <div style="text-align: right;"> <input type="submit" name="butt_save_note" id="butt_save_note" value="<?php echo _l('Add Comment'); ?> " class="submit_button no_permissions"> </div> </div> <?php foreach (module_file::get_file_comments($file_id) as $item) { $note_text = forum_text($item['comment']); if (preg_match_all('/#(\\d+)/', $note_text, $matches)) { // foreach ($matches[1] as $digit) { $note_text = preg_replace('/#' . $digit . '([^\\d]*)/', '<span node_id=' . $digit . ' class="pointer-ids pointer-id-' . $digit . '">#' . $digit . '</span>$1', $note_text); } } ?> <div style="border-top:1px dashed #CCCCCC; padding:3px; margin:3px 0;"> <?php echo $note_text; ?> <div style="font-size:10px; text-align:right; color:#CCCCCC;">From <?php echo $item['create_user_id'] ? module_user::link_open($item['create_user_id'], true) : _l('Customer'); ?> on <?php echo print_date($item['date_created'], true); ?> </div> </div> <?php } ?> </div> <?php $file_data['file_comments'] = ob_get_clean(); $template->assign_values($file_data); $template->assign_values($customer_data); $template->assign_values($job_data); if (class_exists('module_quote', false)) { $quote_data['quote_approved_by'] = $quote_data['approved_by']; $quote_data['quote_date_approved'] = $quote_data['date_approved']; unset($quote_data['approved_by']); unset($quote_data['date_approved']); $template->assign_values($quote_data); } $template->page_title = $file_data['file_name']; $template->content = '<form action="" method="post"><input type="hidden" name="save_file_comments" value="1">' . $template->content . '</form>'; echo $template->render('pretty_html'); } } } break; case 'download_bucket': @ob_end_clean(); $file_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false; if ($file_id && $hash) { $correct_hash = $this->link_public_download_bucket($file_id, true); if ($correct_hash == $hash) { // all good to print a receipt for this payment. $file_data = $this->get_file($file_id, false); @ignore_user_abort(true); $search = array(); $search['bucket_parent_file_id'] = $file_id; $files = module_file::get_files($search); //Create ZIP $zip = new ZipArchive(); $zipName = "bucket-" . $file_id . "-" . md5($file_id . _UCM_SECRET) . ".zip"; if ($zip->open(_FILE_UPLOAD_PATH . $zipName, ZIPARCHIVE::CREATE) !== TRUE) { echo 'Failed to create bucket zip file'; exit; } foreach ($files as $file) { if (is_file($file['file_path'])) { $zip->addFromString($file['file_name'], file_get_contents($file['file_path'])); } } $zip->close(); //Set headers header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-type: application/octet-stream"); //header("Content-Disposition: attachment; filename='" . $zipName . "'"); header("Content-Disposition: attachment; filename=\"" . preg_replace("#[^a-zA-Z0-9]+#", "-", $file_data['file_name']) . ".zip\";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize(_FILE_UPLOAD_PATH . $zipName)); @clearstatcache(); //Make sure the file size isn't cached $size = @readfile(_FILE_UPLOAD_PATH . $zipName); if (!$size) { echo file_get_contents(_FILE_UPLOAD_PATH . $zipName); } @unlink(_FILE_UPLOAD_PATH . $zipName); } } exit; break; case 'download': @ob_end_clean(); $file_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false; if ($file_id && $hash) { $correct_hash = $this->link_public_view($file_id, true); if ($correct_hash == $hash) { // all good to print a receipt for this payment. $file_data = $this->get_file($file_id, false); if (isset($file_data['file_url']) && strlen($file_data['file_url'])) { redirect_browser($file_data['file_url']); } else { if (is_file($file_data['file_path'])) { 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: " . dtbaker_mime_type($file_data['file_name'], $file_data['file_path'])); if (!isset($_REQUEST['embed'])) { header("Content-Disposition: attachment; filename=\"" . $file_data['file_name'] . "\";"); header("Content-Transfer-Encoding: binary"); } header("Content-Length: " . filesize($file_data['file_path'])); //readfile($file_data['file_path']); $size = @readfile($file_data['file_path']); if (!$size) { echo file_get_contents($file_data['file_path']); } } else { echo 'Not found'; } } } } exit; break; } }
public static function get_default_tasks() { // we use the extra module for saving default task lists for now // why not? meh - use a new table later (similar to ticket default responses) $extra_fields = module_extra::get_extras(array('owner_table' => 'job_task_defaults', 'owner_id' => 1)); $responses = array(); foreach ($extra_fields as $extra) { $responses[$extra['extra_id']] = $extra['extra_key']; } return $responses; }
$to_select = false; $to = array(); if ($invoice['customer_id']) { $customer = module_customer::get_customer($invoice['customer_id']); $replace['customer_name'] = $customer['customer_name']; if ($invoice['user_id']) { $primary = module_user::get_user($invoice['user_id']); if ($primary) { $to_select = $primary['email']; } } else { $to = module_user::get_contacts(array('customer_id' => $invoice['customer_id'])); // hunt for 'accounts' extra field $field_to_find = strtolower(module_config::c('accounts_extra_field_name', 'Accounts')); foreach ($to as $contact) { $extras = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $contact['user_id'])); foreach ($extras as $e) { if (strtolower($e['extra_key']) == $field_to_find) { // this is the accounts contact - woo! $to_select = $contact['email']; } } } if (!$to_select && $customer['primary_user_id']) { $primary = module_user::get_user($customer['primary_user_id']); if ($primary) { $to_select = $primary['email']; } } } } else {
/** * @static * @param $args * @return array * * The newsletter system requests updated customer / user data from this group plugin. * It does this when building the member list, and also */ public static function newsletter_callback($args) { if (!isset($args['owner_table']) || !$args['owner_table']) { return array(); } switch ($args['owner_table']) { case 'user': if ((int) $args['owner_id'] > 0) { $sql = "SELECT c.customer_name AS company_name, c.customer_name AS customer_name"; $sql .= " , pu.user_id "; $sql .= " , c.customer_id "; $sql .= " ,c.credit "; $sql .= " , pu.name AS user_name, pu.name AS first_name, pu.last_name AS last_name, pu.phone AS phone, pu.`email` AS `email`, pu.`mobile` AS `mobile`"; $sql .= " , a.line_1, a.line_2, a.suburb, a.state, a.region, a.country, a.post_code "; $sql .= ' FROM `' . _DB_PREFIX . "user` pu"; $sql .= " LEFT JOIN `" . _DB_PREFIX . "customer` c ON pu.customer_id = c.customer_id"; $sql .= ' LEFT JOIN `' . _DB_PREFIX . "address` a ON c.customer_id = a.owner_id AND a.owner_table = 'customer' AND a.address_type = 'physical'"; $sql .= " WHERE pu.user_id = " . (int) $args['owner_id']; $user = qa1($sql); if (!is_array($user) || !isset($user['user_id']) || !$user['user_id']) { return false; } if (isset($args['basic']) && $args['basic']) { return $user; } // $name_parts = explode(" ",preg_replace('/\s+/',' ',$user['user_name'])); // $user['first_name'] = array_shift($name_parts); // $user['last_name'] = implode(' ',$name_parts); // get extras for the user. $extras = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $user['user_id'])); foreach ($extras as $extra) { if (!strlen(trim($extra['extra']))) { continue; } $key = $extra['extra_key']; $x = 1; while (isset($user[$key])) { $key = $extra['extra_key'] . $x; $x++; } $user[$key] = trim($extra['extra']); } // get extras for the customer. if (isset($user['customer_id']) && $user['customer_id'] > 0) { $extras = module_extra::get_extras(array('owner_table' => 'customer', 'owner_id' => $user['customer_id'])); foreach ($extras as $extra) { if (!strlen(trim($extra['extra']))) { continue; } $key = $extra['extra_key']; $x = 1; while (isset($user[$key])) { $key = $extra['extra_key'] . $x; $x++; } $user[$key] = trim($extra['extra']); } } if ($user['customer_id']) { $user['_edit_link'] = module_user::link_open_contact($user['user_id'], false, $user); } else { $user['_edit_link'] = module_user::link_open($user['user_id'], false, $user); } return $user; } break; case 'customer': if (module_config::c('newsletter_send_all_customer_contacts', 1)) { // update - we use the above 'user' callback and return a listing for each contact in the array. // using the special _multi flag hack to tell our newsletter plugin that this result contains multiple entries. $users = array('_multi' => true); $sql = "SELECT u.user_id FROM `" . _DB_PREFIX . "user` u WHERE u.customer_id = " . (int) $args['owner_id']; $contacts = qa($sql); foreach ($contacts as $contact) { $data_args = array('owner_id' => $contact['user_id'], 'owner_table' => 'user'); $users[$contact['user_id']] = self::newsletter_callback($data_args); if ($users[$contact['user_id']]) { $users[$contact['user_id']]['data_args'] = json_encode($data_args); } } return $users; } else { $sql = "SELECT c.customer_name AS company_name, c.customer_name AS customer_name"; $sql .= " ,c.credit "; $sql .= " , pu.user_id "; $sql .= " , c.customer_id "; $sql .= " , pu.name AS user_name, pu.name AS first_name, pu.last_name AS last_name, pu.phone AS phone, pu.`email` AS `email`, pu.`mobile` AS `mobile`"; $sql .= " , a.line_1, a.line_2, a.suburb, a.state, a.region, a.country, a.post_code "; $sql .= " FROM `" . _DB_PREFIX . "customer` c "; $sql .= ' LEFT JOIN `' . _DB_PREFIX . "address` a ON c.customer_id = a.owner_id AND a.owner_table = 'customer' AND a.address_type = 'physical'"; $sql .= ' LEFT JOIN `' . _DB_PREFIX . "user` pu ON c.primary_user_id = pu.user_id"; $sql .= " WHERE c.customer_id = " . (int) $args['owner_id']; $user = qa1($sql); if (!$user || !isset($user['customer_id'])) { return array(); } //$name_parts = explode(" ",preg_replace('/\s+/',' ',$user['user_name'])); //$user['first_name'] = array_shift($name_parts); //$user['last_name'] = implode(' ',$name_parts); if (isset($args['basic']) && $args['basic']) { return $user; } // get extras for the customer. $extras = module_extra::get_extras(array('owner_table' => 'customer', 'owner_id' => $user['customer_id'])); foreach ($extras as $extra) { if (!strlen(trim($extra['extra']))) { continue; } $key = $extra['extra_key']; $x = 1; while (isset($user[$key])) { $key = $extra['extra_key'] . $x; $x++; } $user[$key] = trim($extra['extra']); } if (isset($user['user_id']) && $user['user_id'] > 0) { // get extras for the user. $extras = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $user['user_id'])); foreach ($extras as $extra) { if (!strlen(trim($extra['extra']))) { continue; } $key = $extra['extra_key']; $x = 1; while (isset($user[$key])) { $key = $extra['extra_key'] . $x; $x++; } $user[$key] = trim($extra['extra']); } } $user['_edit_link'] = module_customer::link_open($user['customer_id'], false, $user); return $user; } case 'website': $sql = "SELECT c.customer_name AS company_name"; $sql .= " ,c.credit "; $sql .= " ,w.name AS website_name"; $sql .= " ,w.url AS website_url"; $sql .= " , pu.user_id "; $sql .= " , c.customer_id "; $sql .= " , pu.name AS user_name, pu.phone AS phone, pu.`email` AS `email`, pu.`mobile` AS `mobile`"; $sql .= " , a.line_1, a.line_2, a.suburb, a.state, a.region, a.country, a.post_code "; $sql .= " FROM `" . _DB_PREFIX . "website` w "; $sql .= ' LEFT JOIN `' . _DB_PREFIX . "customer` c ON w.customer_id = c.customer_id"; $sql .= ' LEFT JOIN `' . _DB_PREFIX . "address` a ON c.customer_id = a.owner_id AND a.owner_table = 'customer' AND a.address_type = 'physical'"; $sql .= ' LEFT JOIN `' . _DB_PREFIX . "user` pu ON c.primary_user_id = pu.user_id"; $sql .= " WHERE w.website_id = " . (int) $args['owner_id']; $user = qa1($sql); $name_parts = explode(" ", preg_replace('/\\s+/', ' ', $user['user_name'])); $user['first_name'] = array_shift($name_parts); $user['last_name'] = implode(' ', $name_parts); if (isset($args['basic']) && $args['basic']) { return $user; } // get extras for the website. $extras = module_extra::get_extras(array('owner_table' => 'website', 'owner_id' => $args['owner_id'])); foreach ($extras as $extra) { if (!strlen(trim($extra['extra']))) { continue; } $key = $extra['extra_key']; $x = 1; while (isset($user[$key])) { $key = $extra['extra_key'] . $x; $x++; } $user[$key] = trim($extra['extra']); } // then get extras for the company $extras = module_extra::get_extras(array('owner_table' => 'customer', 'owner_id' => $user['customer_id'])); foreach ($extras as $extra) { if (!strlen(trim($extra['extra']))) { continue; } $key = $extra['extra_key']; $x = 1; while (isset($user[$key])) { $key = $extra['extra_key'] . $x; $x++; } $user[$key] = trim($extra['extra']); } if (isset($user['user_id']) && $user['user_id'] > 0) { // get extras for the user. $extras = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $user['user_id'])); foreach ($extras as $extra) { if (!strlen(trim($extra['extra']))) { continue; } $key = $extra['extra_key']; $x = 1; while (isset($user[$key])) { $key = $extra['extra_key'] . $x; $x++; } $user[$key] = trim($extra['extra']); } } $user['_edit_link'] = module_customer::link_open($user['customer_id'], false, $user); return $user; case 'ticket': //echo 'Getting ticket for '.$args['owner_id'] . ' and basic is '.var_export($args['basic'],true);exit; return module_ticket::get_newsletter_recipient($args['owner_id'], isset($args['basic']) && $args['basic']); case 'member': return module_member::get_newsletter_recipient($args['owner_id'], isset($args['basic']) && $args['basic']); case 'newsletter_subscription': return module_member::get_newsletter_recipient($args['owner_id'], isset($args['basic']) && $args['basic']); } return array(); }
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 function external_hook($hook) { switch ($hook) { case 'subscribe_form': // handle subscriptions to the member database and also the newsletter system. // todo - tie in with "subscription" module to allow users to select which subscription they want as well. // handle subscriptions to the member database and also the newsletter system. // todo - tie in with "subscription" module to allow users to select which subscription they want as well. case 'subscribe': $member = isset($_REQUEST['member']) && is_array($_REQUEST['member']) ? $_REQUEST['member'] : false; $provided_member_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false; $member_id = false; if ($member) { if (isset($member['email']) && $member['email']) { // proceed with signup $email = filter_var(strtolower(trim($member['email'])), FILTER_VALIDATE_EMAIL); if (strlen($email) > 3) { $adding_new_member = true; // are we adding a new member to the system or updating an old one if ($provided_member_id && $hash) { $real_hash = $this->link_public_details($provided_member_id, true); if ($real_hash == $hash) { $existing_member = get_single('member', 'email', $email); if ($existing_member && $existing_member['member_id'] != $provided_member_id) { // this user is trying to update their email address to a user who exists in the system already $template = module_template::get_template_by_key('member_subscription_error'); $template->page_title = htmlspecialchars(_l('Subscription')); $template->assign_values(array('message' => _l('The email address %s is already linked to another member.', htmlspecialchars($email)))); echo $template->render('pretty_html'); exit; } $adding_new_member = false; // updating details in the system. update_insert("member_id", $provided_member_id, "member", $member); $member_id = $provided_member_id; // update extra fields... } } if (!$member_id) { // add member to system. $existing_member = get_single('member', 'email', $email); if ($existing_member && $existing_member['member_id'] > 0) { // todo: give them link to change details. $template = module_template::get_template_by_key('member_subscription_error'); $template->page_title = htmlspecialchars(_l('Subscription')); $template->assign_values(array('message' => _l('The email address %s is already a member. Please click the link in our newsletter to modify your details.', htmlspecialchars($email)))); echo $template->render('pretty_html'); exit; } // todo - sanatise input here, this will allow anyone to insert member details: $member_id = update_insert("member_id", 'new', "member", $member); } if ($member_id) { // save extra fields against member. $extra_fields = module_extra::get_defaults('member'); $extra_values = array(); foreach ($extra_fields as $extra_field) { // check if this field was submitted. if (isset($member[$extra_field['key']])) { $extra_values[$extra_field['key']] = array('val' => $member[$extra_field['key']], 'key' => $extra_field['key']); } } if (count($extra_values)) { $_REQUEST['extra_member_field'] = $extra_values; module_extra::save_extras('member', 'member_id', $member_id, false); } if (class_exists('module_newsletter', false)) { $newsletter_member_id = module_newsletter::member_from_email(array('email' => $email, 'member_id' => $member_id, 'data_callback' => 'module_member::get_newsletter_recipient', 'data_args' => $member_id), true, true); module_newsletter::subscribe_member($email, $newsletter_member_id); // now add thsi member to the grups they have selected. if (isset($member['group']) && is_array($member['group'])) { $group_items = module_group::get_groups('newsletter_subscription'); $public_group_ids = array(); foreach ($group_items as $group_item) { $public_group_ids[$group_item['group_id']] = true; // remove user group all these groups. module_group::delete_member($member_id, 'newsletter_subscription'); } //print_r($member['group']);print_r($public_group_ids);exit; foreach ($member['group'] as $group_id => $tf) { if ($tf && isset($public_group_ids[$group_id])) { // add member to group - but only public group ids! module_group::add_to_group($group_id, $member_id); } } } } // is the newsletter module giving us a subscription redirection? if ($adding_new_member) { if (module_config::c('newsletter_subscribe_redirect', '')) { redirect_browser(module_config::c('newsletter_subscribe_redirect', '')); } $template = module_template::get_template_by_key('member_subscription_success'); $template->page_title = htmlspecialchars(_l('Subscription')); $template->assign_values(array('email' => $email)); echo $template->render('pretty_html'); exit; } else { if (module_config::c('newsletter_update_details_redirect', '')) { redirect_browser(module_config::c('newsletter_update_details_redirect', '')); } $template = module_template::get_template_by_key('member_update_details_success'); $template->page_title = htmlspecialchars(_l('Subscription')); $template->assign_values(array('email' => $email)); echo $template->render('pretty_html'); exit; } } else { echo 'database failure.. please try again.'; } } else { $template = module_template::get_template_by_key('member_subscription_error'); $template->page_title = htmlspecialchars(_l('Subscription')); $template->assign_values(array('message' => _l('Sorry please go back and complete all required fields (especially email address)'))); echo $template->render('pretty_html'); exit; } } else { $template = module_template::get_template_by_key('member_subscription_error'); $template->page_title = htmlspecialchars(_l('Subscription')); $template->assign_values(array('message' => _l('Sorry please go back and complete all required fields'))); echo $template->render('pretty_html'); exit; } } else { $template = module_template::get_template_by_key('member_subscription_form'); $template->page_title = htmlspecialchars(_l('Subscription')); // we also treat this as a subscription modification form. $newsletter_subscriptions = array(); $member = array('email' => '', 'first_name' => '', 'last_name' => '', 'business' => '', 'phone' => '', 'mobile' => ''); // extra fields: $extra_fields = module_extra::get_defaults('member'); foreach ($extra_fields as $extra_field) { $member[$extra_field['key']] = ''; } if ($provided_member_id && $hash) { $real_hash = $this->link_public_details($provided_member_id, true); if ($real_hash == $hash) { // we can load these details into the forum successfully. $member = array_merge($member, $this->get_member($provided_member_id)); // get their fields: $extra_fields = module_extra::get_extras(array('owner_table' => 'member', 'owner_id' => $provided_member_id)); foreach ($extra_fields as $extra_field) { $member[$extra_field['extra_key']] = $extra_field['extra']; } // find out what newsletter subscriptions this member has. if (class_exists('module_newsletter', false)) { $newsletter_member_id = module_newsletter::member_from_email($member, true, true); $newsletter_subscriptions = module_group::get_member_groups('newsletter_subscription', $provided_member_id); } } } $template->assign_values($member); if (class_exists('module_newsletter', false)) { $group_items = module_group::get_groups('newsletter_subscription'); ob_start(); foreach ($group_items as $group_item) { ?> <div class="group_select"> <input type="checkbox" name="member[group][<?php echo $group_item['group_id']; ?> ]" value="1"<?php foreach ($newsletter_subscriptions as $newsletter_subscription) { if ($newsletter_subscription['group_id'] == $group_item['group_id']) { echo ' checked'; } } ?> > <?php echo htmlspecialchars($group_item['name']); ?> </div> <?php } $template->assign_values(array('newsletter_options' => ob_get_clean())); } else { $template->assign_values(array('newsletter_options' => '')); } echo $template->render('pretty_html'); exit; } break; } }
} // find available "to" recipients. // customer contacts. $to_select = false; if ($file['customer_id']) { $customer = module_customer::get_customer($file['customer_id']); $file['customer_name'] = $customer['customer_name']; $to = module_user::get_contacts(array('customer_id' => $file['customer_id'])); if ($customer['primary_user_id']) { $primary = module_user::get_user($customer['primary_user_id']); if ($primary) { $to_select = $primary['email']; } } } else { $to = array(); } if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) { $all_extra_fields = module_extra::get_defaults('file'); foreach ($all_extra_fields as $e) { $file[$e['key']] = _l('N/A'); } // and find the ones with values: $extras = module_extra::get_extras(array('owner_table' => 'file', 'owner_id' => $file_id)); foreach ($extras as $e) { $file[$e['extra_key']] = $e['extra']; } } $template->assign_values($file); ob_start(); module_email::print_compose(array('title' => _l('Email File: %s', $file['file_name']), 'find_other_templates' => 'file_approval_email', 'current_template' => $template_name, 'customer_id' => $file['customer_id'], 'job_id' => $file['job_id'], 'file_id' => $file['file_id'], 'debug_message' => 'Sending file as email', 'to' => $to, 'to_select' => $to_select, 'bcc' => module_config::c('admin_email_address', ''), 'content' => $template->render('html'), 'subject' => $template->replace_description(), 'success_url' => module_file::link_open($file_id), 'success_callback' => 'module_file::email_sent', 'success_callback_args' => array('file_id' => $file_id), 'cancel_url' => module_file::link_open($file_id)));
public function get_pins() { $pins = array(); // use the 'extra' module for now. $extra_fields = module_extra::get_extras(array('owner_table' => 'pin', 'owner_id' => module_security::get_loggedin_id())); foreach ($extra_fields as $extra) { $pins[$extra['extra_id']] = unserialize($extra['extra']); } return $pins; }
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; }
public static function get_replace_fields($user_id) { // do we use the primary contact or $contact_data = module_user::get_user($user_id); //print_r($contact_data);exit; if ($contact_data && $contact_data['user_id'] != $user_id) { $contact_data = array('user_id' => 0, 'customer_id' => 0, 'name' => '', 'last_name' => '', 'email' => '', 'password' => '', 'phone' => '', 'mobile' => '', 'fax' => ''); } $contact_data['password'] = ''; $contact_data['first_name'] = $contact_data['name']; // 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()) { // and the primary contact $all_extra_fields = module_extra::get_defaults('user'); foreach ($all_extra_fields as $e) { $contact_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) { $contact_data[$e['extra_key']] = $e['extra']; } } } return $contact_data; }
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; }
public static function get_saved_responses() { // we use the extra module for saving canned responses for now. // why not? meh - use a new table later when we start with a FAQ system. $extra_fields = module_extra::get_extras(array('owner_table' => 'ticket_responses', 'owner_id' => 1)); $responses = array(); foreach ($extra_fields as $extra) { $responses[$extra['extra_id']] = $extra['extra_key']; } return $responses; }