public static function save_quote($quote_id, $data) { if (isset($data['customer_id']) && $data['customer_id'] > 0) { // check we have access to this customer from this quote. $customer_check = module_customer::get_customer($data['customer_id']); if (!$customer_check || $customer_check['customer_id'] != $data['customer_id']) { unset($data['customer_id']); } } if (isset($data['website_id']) && $data['website_id']) { $website = module_website::get_website($data['website_id']); if ($website && (int) $website['website_id'] > 0 && $website['website_id'] == $data['website_id']) { // website exists. // make this one match the website customer_id, or set teh website customer_id if it doesn't have any. if ((int) $website['customer_id'] > 0) { if ($data['customer_id'] > 0 && $data['customer_id'] != $website['customer_id']) { set_message('Changed this Quote to match the Website customer'); } $data['customer_id'] = $website['customer_id']; } else { if (isset($data['customer_id']) && $data['customer_id'] > 0) { // set the website customer id to this as well. update_insert('website_id', $website['website_id'], 'website', array('customer_id' => $data['customer_id'])); } } } } if ((int) $quote_id > 0) { $original_quote_data = self::get_quote($quote_id, false); if (!$original_quote_data || $original_quote_data['quote_id'] != $quote_id) { $original_quote_data = array(); $quote_id = false; } } else { $original_quote_data = array(); $quote_id = false; } // check create permissions. if (!$quote_id && !self::can_i('create', 'Quotes')) { // user not allowed to create quotes. set_error('Unable to create new Quotes'); redirect_browser(self::link_open(false)); } if (!(int) $quote_id && module_config::c('quote_name_incrementing', 0)) { // incrememnt next quote number on save. $quote_number = module_config::c('quote_name_incrementing_next', 1); module_config::save_config('quote_name_incrementing_next', $quote_number + 1); } $quote_id = update_insert("quote_id", $quote_id, "quote", $data); $return = false; if ($quote_id) { hook_handle_callback('quote_save', $quote_id); // save the quote tax rates (copied from invoice.php) if (isset($data['tax_ids']) && isset($data['tax_names']) && $data['tax_percents']) { $existing_taxes = get_multiple('quote_tax', array('quote_id' => $quote_id), 'quote_tax_id', 'exact', 'order'); $order = 1; foreach ($data['tax_ids'] as $key => $val) { if (isset($data['tax_percents'][$key]) && $data['tax_percents'][$key] == 0) { // we are not saving this particular tax item because it has a 0% tax rate } else { if ((int) $val > 0 && isset($existing_taxes[$val])) { // this means we are trying to update an existing record on the quote_tax table, we confirm this id matches this quote. $quote_tax_id = $val; unset($existing_taxes[$quote_tax_id]); // so we know which ones to remove from the end. } else { $quote_tax_id = false; // create new record } $quote_tax_data = array('quote_id' => $quote_id, 'percent' => isset($data['tax_percents'][$key]) ? $data['tax_percents'][$key] : 0, 'amount' => 0, 'name' => isset($data['tax_names'][$key]) ? $data['tax_names'][$key] : 'TAX', 'order' => $order++, 'increment' => isset($data['tax_increment_checkbox']) && $data['tax_increment_checkbox'] ? 1 : 0); $quote_tax_id = update_insert('quote_tax_id', $quote_tax_id, 'quote_tax', $quote_tax_data); } } foreach ($existing_taxes as $existing_tax) { delete_from_db('quote_tax', array('quote_id', 'quote_tax_id'), array($quote_id, $existing_tax['quote_tax_id'])); } } module_cache::clear('quote'); $return = array('quote_id' => $quote_id, 'task_result' => self::save_quote_tasks($quote_id, $data)); $check_completed = true; switch ($return['task_result']['status']) { case 'created': // we added a new task. break; case 'deleted': // we deleted a task. break; case 'edited': // we changed a task (ie: completed?); break; default: // nothing changed. // $check_completed = false; break; } if ($check_completed) { self::update_quote_completion_status($quote_id); } if ($original_quote_data) { // we check if the hourly rate has changed if (isset($data['hourly_rate']) && $data['hourly_rate'] != $original_quote_data['hourly_rate']) { // update all the task hours, but only for hourly tasks: $sql = "UPDATE `" . _DB_PREFIX . "quote_task` SET `amount` = 0 WHERE `hours` > 0 AND quote_id = " . (int) $quote_id . " AND ( manual_task_type = " . _TASK_TYPE_HOURS_AMOUNT; if ($data['default_task_type'] == _TASK_TYPE_HOURS_AMOUNT) { $sql .= " OR manual_task_type = -1 "; } $sql .= " )"; query($sql); } // check if the quote assigned user id has changed. if (module_config::c('quote_allow_staff_assignment', 1)) { if (isset($data['user_id'])) { // && $data['user_id'] != $original_quote_data['user_id']){ // user id has changed! update any that were the old user id. $sql = "UPDATE `" . _DB_PREFIX . "quote_task` SET `user_id` = " . (int) $data['user_id'] . " WHERE (`user_id` = " . (int) $original_quote_data['user_id'] . " OR user_id = 0) AND quote_id = " . (int) $quote_id; query($sql); } } // check if the quote was approved. if (!isset($original_quote_data['date_approved']) || !$original_quote_data['date_approved'] || $original_quote_data['date_approved'] == '0000-00-00') { // original quote wasn't approved. if (isset($data['date_approved']) && !empty($data['date_approved']) && $data['date_approved'] != '0000-00-00') { // quote was approved! self::quote_approved($quote_id); } } } } if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) { module_extra::save_extras('quote', 'quote_id', $quote_id); } module_cache::clear('quote'); return $return; }
* Package Date: 2015-11-25 02:55:20 * IP Address: 67.79.165.254 */ if (!$invoice_safe) { die('failed'); } $invoice_id = isset($_REQUEST['invoice_id']) ? (int) $_REQUEST['invoice_id'] : false; if (isset($_REQUEST['go'])) { $invoice = module_invoice::get_invoice($invoice_id); // confirm customer access. if (!$invoice || $invoice['invoice_id'] != $invoice_id) { echo 'invalid invoice id'; exit; } if ($invoice && $invoice['customer_id']) { $customer_test = module_customer::get_customer($invoice['customer_id']); if (!$customer_test || $customer_test['customer_id'] != $invoice['customer_id']) { echo 'invalid customer id'; exit; } } if (isset($_REQUEST['htmlonly'])) { echo module_invoice::invoice_html($invoice_id, $invoice, 'pdf'); exit; } // send the actual invoice. // step1, generate the PDF for the invoice... $pdf_file = module_invoice::generate_pdf($invoice_id); if ($pdf_file && is_file($pdf_file)) { // copied from public_print hook @ob_end_clean();
public function external_hook($hook) { switch ($hook) { case 'popup': // popup not used any more. cross domain issues. // load up the full script to be injected into our clients website. $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $change_request_id = $change_id = isset($_REQUEST['change_id']) ? (int) $_REQUEST['change_id'] : false; $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false; $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : false; if ($type == 'popupjs') { @ob_end_clean(); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); header("Content-type: text/javascript"); } if ($website_id && $hash && module_change_request::link_popup($website_id, true) == $hash) { $change_history = module_change_request::get_remaining_changes($website_id); $step = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0; // get the change details out if ($change_request_id) { $change_request = module_change_request::get_change_request_by_website($website_id, $change_request_id); } else { $change_request = array(); } if (!$change_request) { $change_request = array('change_request_id' => 0, 'name' => '', 'request' => '', 'attachments' => array()); } switch ($type) { case 'save': // saving a change. $data = $_POST; $data['url'] = urldecode($data['url']); $data['website_id'] = $website_id; $data['change_request_id'] = $change_request['change_request_id']; if (isset($_REQUEST['completed_test'])) { if (!isset($_REQUEST['completed']) || !$_REQUEST['completed']) { $data['status'] = _CHANGE_REQUEST_STATUS_NEW; // not completed. } else { $data['status'] = _CHANGE_REQUEST_STATUS_COMPLETE; // completed! } } if (isset($_REQUEST['delete_request'])) { $data['status'] = _CHANGE_REQUEST_STATUS_DELETE; // deleted } $change_request_id = update_insert('change_request_id', $change_request['change_request_id'], 'change_request', $data); // redirect to send email page if we're logged in if (module_security::is_logged_in() && isset($_REQUEST['completed_send_email']) && $_REQUEST['completed_send_email'] && self::can_i('edit', 'Change Requests')) { // don't do the template, do the redirect to the email page (todo!) redirect_browser(self::link_open($change_request_id)); } else { // send email to administrator (everyone with change request edit permissions?) about this change request. $alert_users = module_user::get_users_by_permission(array('category' => 'Change Request', 'name' => 'Change Requests', 'module' => 'change_request', 'edit' => 1)); $email_data = get_single('change_request', 'change_request_id', $change_request_id); $customer_data = $website_data = array(); if ($website_id) { $website_data = module_website::get_website($website_id); $email_data['website_name'] = $website_data['name']; $email_data['website_link'] = module_website::link_open($website_id, true); if ($website_data && $website_data['customer_id']) { $customer_data = module_customer::get_customer($website_data['customer_id'], true); } } if (isset($email_data['request'])) { $email_data['request'] = nl2br($email_data['request']); // for the plain text emails. } foreach ($alert_users as $alert_user) { // todo: make sure this staff member has access to this website? // nfi how to figure this out. maybe we just look for staff members who are assigned jobs/tasks against this website? $template = module_template::get_template_by_key('change_request_alert_email'); $template->assign_values(array_merge($customer_data, $website_data, $email_data)); $html = $template->render('html'); // send an email to this user. $email = module_email::new_email(); $email->replace_values = array_merge($customer_data, $website_data, $email_data); $email->set_to('user', $alert_user['user_id']); $email->set_from('user', module_security::get_loggedin_id() ? module_security::get_loggedin_id() : isset($customer_data['primary_user_id']) ? $customer_data['primary_user_id'] : 0); $email->set_subject($template->description); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! // sweet. } else { /// log err? set_error(_l('Failed to send change notification email to User ID: %s Email: %s Status: %s Error: %s', $alert_user['user_id'], json_encode($email->to), $email->status, $email->error_text)); } } } // display thankyou template. module_template::init_template('change_request_submitted', '<h2>Change Request</h2> <p>Thank you. Your change request has been submitted successfully.</p> <p>Please <a href="{URL}">click here</a> to continue.</p> ', 'Displayed after a change request is created/updated.', 'code'); // correct! // load up the receipt template. $template = module_template::get_template_by_key('change_request_submitted'); $template->page_title = _l("Change Request"); foreach ($data as $key => $val) { if (!is_array($val)) { $data[$key] = htmlspecialchars($val); } } $template->assign_values($data); echo $template->render('pretty_html'); exit; break; case 'display_change': ob_start(); ?> <div class="title"> <?php _e('Change request'); ?> </div> <div class="content"> <p><?php echo nl2br(htmlspecialchars($change_request['request'])); ?> </p> <div class="wp3changerequest_actions"> <p> <!-- <strong><?php _e('Attachments:'); ?> </strong> <?php if (!$change_request['attachments']) { ?> - none - <?php } else { foreach ($change_request['attachments'] as $attachment) { ?> <a href="#"><?php echo htmlspecialchars($attachment->name); ?> </a> <?php } ?> <?php } ?> <br/>--> <strong><?php _e('Created by:'); ?> </strong> <?php echo htmlspecialchars($change_request['name']); ?> <br/> <strong><?php _e('Created on:'); ?> </strong> <?php echo print_date($change_request['date_created'], true); ?> <?php if (isset($change_request['job_id']) && $change_request['job_id']) { ?> <br/> <strong><?php _e('Converted to job:'); ?> </strong> <?php _e('This task has been converted to a Job'); ?> <?php } ?> </p> <?php if (!isset($change_request['job_id']) || !$change_request['job_id'] || self::can_i('edit', 'Change Requests')) { ?> <p align="center"> <input type="button" name="edit" value="<?php _e('Edit'); ?> " class="wp3changerequest_button wp3changerequest_button_small" onclick="dtbaker_changerequest.edit(<?php echo $change_request_id; ?> ); return false;"> </p> <?php } ?> </div> </div> <?php $change_request['html'] = preg_replace('/\\s+/', ' ', ob_get_clean()); // echo json_encode($change_request); // exit; @ob_end_clean(); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); header("Content-type: text/javascript"); ?> var t = dtbaker_changerequest; var change_id = <?php echo $change_request_id; ?> ; var msg = <?php echo json_encode($change_request); ?> ; jQuery('body').prepend('<div class="wp3changerequest_change" id="dtbaker_change_'+change_id+'" style="'+((!t.show_postits) ? 'display:none;':'')+'"></div>'); var box = jQuery('#dtbaker_change_'+change_id); box.html(msg.html); if(msg.status == 0){ box.addClass('wp3changerequest_change_pending'); }else if(msg.status == 2){ box.addClass('wp3changerequest_change_complete'); }else if(msg.status == 3){ box.addClass('wp3changerequest_change_deleted'); } box.css('top',msg.y+'px'); box.data('window_width',msg.window_width); box.data('left',msg.x); t.set_left(change_id); with({i:change_id}){ jQuery(window).resize(function () { t.set_left(i); }); } box.data('original_height',box.height()); box.css('overflow','hidden'); jQuery('.title',box).slideUp(); box.stop(true, true).animate({ height: t.min_height, width: t.min_width },500); box.hover(function(){ jQuery(this).addClass('wp3changerequest_change_active'); jQuery('.title',this).stop(true, true).slideDown(); jQuery(this).stop().animate({ width: t.max_width, height: jQuery(this).data('original_height'), opacity: 1 },500); },function(){ jQuery('.title',this).stop(true, true).slideUp(); jQuery(this).stop().animate({ width: t.min_width, height: t.min_height, opacity: 0.7 },500,function(){ jQuery(this).removeClass('wp3changerequest_change_active'); }); }) <?php break; default: @ob_end_clean(); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); header("Content-type: text/javascript"); ob_start(); include 'pages/popup.php'; $html = ob_get_clean(); $html = addcslashes($html, "'"); $html = preg_replace('#\\r|\\n#', "' +\n'", $html); // inject using javascript. fixes cross domain issues ?> if(!jQuery('#dtbaker_changerequest_inlinewizard').length){ // fix for jQuery 1.9+ jQuery('body').append('<div id="dtbaker_changerequest_inlinewizard" style="display:none;"></div>'); } jQuery('#dtbaker_changerequest_inlinewizard').html('<?php echo $html; ?> '); <?php } } exit; break; case 'script': // load up the full script to be injected into our clients website. $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false; @ob_end_clean(); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); header("Content-type: text/javascript"); if ($website_id && $hash && module_change_request::link_script($website_id, true) == $hash) { include "js/client.js"; $client_url = isset($_REQUEST['url']) ? $_REQUEST['url'] : false; if ($client_url) { $change_requests = self::get_change_requests(array('website_id' => $website_id, 'url' => $client_url)); // todo - option this out incase url causes issues. ie: old js check method ?> jQuery(function(){ <?php foreach ($change_requests as $change_request) { $displayed = false; if ($change_request['status'] == _CHANGE_REQUEST_STATUS_NEW) { $displayed = true; ?> dtbaker_changerequest.display_change(<?php echo $change_request['change_request_id']; ?> ); <?php } if (isset($_SESSION['_change_request_highlight']) && $_SESSION['_change_request_highlight'] == $change_request['change_request_id']) { ?> <?php if (!$displayed) { ?> dtbaker_changerequest.display_change(<?php echo $change_request['change_request_id']; ?> ); <?php } ?> dtbaker_changerequest.highlight(<?php echo (int) $_SESSION['_change_request_highlight']; ?> ); <?php unset($_SESSION['_change_request_highlight']); } } ?> }); <?php } else { // not posting the URL, some setups do not like this // get list of active change requests $change_requests = self::get_change_requests(array('website_id' => $website_id, 'status' => _CHANGE_REQUEST_STATUS_NEW)); // we also do completed ones because the change request highlight countbe in there $completed_change_requests = self::get_change_requests(array('website_id' => $website_id, 'status' => _CHANGE_REQUEST_STATUS_COMPLETE)); ?> jQuery(function(){ var current_url = window.location.href; <?php foreach ($change_requests as $change_request) { ?> if(current_url == '<?php echo addcslashes(htmlspecialchars($change_request['url']), "'"); ?> '){ // todo: do this better! dtbaker_changerequest.display_change(<?php echo $change_request['change_request_id']; ?> ); } <?php } ?> <?php // todo: do we display all previous change requests on the page or not? if (isset($_SESSION['_change_request_highlight']) && $_SESSION['_change_request_highlight']) { echo '// Checking for request: ' . (int) $_SESSION['_change_request_highlight']; foreach ($completed_change_requests as $complete_change_request) { if ($complete_change_request['change_request_id'] == $_SESSION['_change_request_highlight']) { // show this completed one as well. ?> dtbaker_changerequest.display_change(<?php echo $complete_change_request['change_request_id']; ?> ); <?php } } ?> dtbaker_changerequest.highlight(<?php echo (int) $_SESSION['_change_request_highlight']; ?> ); <?php // todo: move this unset over to the "display_change" callback so we only remove the session when we know it has been displayed. unset($_SESSION['_change_request_highlight']); } ?> }); <?php } } exit; break; case 'public': $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false; if ($website_id && $hash && module_change_request::link_public($website_id, true) == $hash) { // correct! // redirect to website with our "change_request" url parameter, that is picked up by the included text. $website = module_website::get_website($website_id); $change_request_website = get_single('change_request_website', 'website_id', $website_id); if ($change_request_website && $change_request_website['enabled']) { $url = module_website::urlify($website['url']); // todo - pass this to a (yet to be created) method in website that will deal with https:// or http:// based on user input. stop hardcoding http! if (isset($_REQUEST['change_request_id'])) { $selected_change_request = self::get_change_request_by_website($website_id, (int) $_REQUEST['change_request_id']); if ($selected_change_request && $selected_change_request['url']) { $url = $selected_change_request['url']; } //$url .= "&change_request_id=".(int)$_REQUEST['change_request_id']; $_SESSION['_change_request_highlight'] = (int) $_REQUEST['change_request_id']; } $url = $url . (strpos($url, '?') === false ? '?' : '&') . 'change_request=' . self::link_script($website_id, true); redirect_browser($url); } } echo "Change request disabled."; break; } }
public function get_data() { if (count($this->_get_data_cache)) { return $this->_get_data_cache; } $file = false; if ($this->file_id > 0) { $file = get_single("file", "file_id", $this->file_id); } // check user has permissions to view this file. // for now we just base this on the customer id check if ($file) { // staff listing $staff = get_multiple('file_user_rel', array('file_id' => $file['file_id']), 'user_id'); $file['staff_ids'] = array_keys($staff); $file['type'] = isset($file['file_url']) && $file['file_url'] ? 'remote' : (isset($file['bucket']) && $file['bucket'] ? 'bucket' : 'upload'); if ($this->do_permissions) { switch (module_file::get_file_data_access()) { case _FILE_ACCESS_ALL: // all files, no limits on SQL here break; case _FILE_ACCESS_JOBS: $jobs = module_job::get_jobs(array(), array('columns' => 'u.job_id AS id')); if (!$file['job_id'] || !isset($jobs[$file['job_id']])) { $file = false; } break; case _FILE_ACCESS_ME: if ($file['create_user_id'] != module_security::get_loggedin_id()) { $file = false; } break; case _FILE_ACCESS_ASSIGNED: if (!in_array(module_security::get_loggedin_id(), $file['staff_ids'])) { $file = false; } break; case _FILE_ACCESS_CUSTOMERS: default: if (class_exists('module_customer', false)) { //added for compat in newsletter system that doesn't have customer module $customer_permission_check = module_customer::get_customer($file['customer_id']); if ($customer_permission_check['customer_id'] != $file['customer_id']) { $file = false; } } } // file data access switch } } if (!$file) { $file = array('new' => true, 'type' => 'upload', 'file_id' => 0, 'customer_id' => isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : 0, 'job_id' => isset($_REQUEST['job_id']) ? $_REQUEST['job_id'] : 0, 'quote_id' => isset($_REQUEST['quote_id']) ? $_REQUEST['quote_id'] : 0, 'description' => '', 'status' => module_config::c('file_default_status', 'Uploaded'), 'file_name' => '', 'file_url' => '', 'staff_ids' => array(), 'bucket' => 0, 'bucket_parent_file_id' => 0, 'approved_time' => 0); } $this->_get_data_cache = $file; return $file; }
include module_theme::include_ucm('includes/plugin_quote/template/quote_task_list.php'); $public_html = ob_get_clean(); $quote['task_list'] = $public_html; /*ob_start(); $quote_data = $quote; $ignore_task_hook=true; $for_email=true; include('quote_public.php'); $quote['quote_tasks'] = ob_get_clean();*/ // generate the PDF ready for sending. $pdf = module_quote::generate_pdf($quote_id); // find available "to" recipients. // customer contacts. $to_select = false; if ($quote['customer_id']) { $customer = module_customer::get_customer($quote['customer_id']); $quote['customer_name'] = $customer['customer_name']; $to = module_user::get_contacts(array('customer_id' => $quote['customer_id'])); if ($quote['contact_user_id']) { $primary = module_user::get_user($quote['contact_user_id']); if ($primary) { $to_select = $primary['email']; } } else { if ($customer['primary_user_id']) { $primary = module_user::get_user($customer['primary_user_id']); if ($primary) { $to_select = $primary['email']; } } }
$_REQUEST['customer_id'] = $old_customer_id; } else { unset($_REQUEST['customer_id']); } } }); } if (class_exists('module_extra', false)) { // do extra before "table sorting" so that it can hook in with the table sort call $table_manager->display_extra('customer', function ($customer) { module_extra::print_table_data('customer', $customer['customer_id']); }, 'customer_id'); $table_manager->display_extra('user', function ($customer) { module_extra::print_table_data('user', $customer['primary_user_id']); }, 'primary_user_id'); } $table_manager->enable_table_sorting(array('table_id' => 'customer_list', 'sortable' => array('customer_name' => array('field' => 'customer_name'), 'primary_contact_name' => array('field' => 'primary_user_name'), 'primary_contact_email' => array('field' => 'primary_user_email'), 'customer_group' => array('group_sort' => true, 'owner_table' => 'customer', 'owner_id' => 'customer_id')))); if (module_customer::can_i('view', 'Export ' . $page_type)) { $table_manager->enable_export(array('name' => $page_type_single . ' Export', 'fields' => array($page_type_single . ' ID' => 'customer_id', $page_type_single . ' Name' => 'customer_name', 'Credit' => 'credit', 'Address Line 1' => 'line_1', 'Address Line 2' => 'line_2', 'Address Suburb' => 'suburb', 'Address Country' => 'country', 'Address State' => 'state', 'Address Region' => 'region', 'Address Post Code' => 'post_code', 'Primary Contact First Name' => 'primary_user_name', 'Primary Contact Last Name' => 'primary_user_last_name', 'Primary Phone' => 'primary_user_phone', 'Primary Email' => 'primary_user_email', 'Primary Fax' => 'primary_user_fax', 'Primary Mobile' => 'primary_user_mobile', 'Primary Language' => 'primary_user_language', 'Invoice Prefix' => 'default_invoice_prefix', 'Tax Name' => 'default_tax_name', 'Tax Rate' => 'default_tax', 'Staff' => 'customer_staff'), 'extra' => array(array('owner_table' => 'customer', 'owner_id' => 'customer_id'), array('owner_table' => 'user', 'owner_id' => 'primary_user_id')), 'group' => array(array('title' => $page_type_single . ' Group', 'owner_table' => 'customer', 'owner_id' => 'customer_id')))); } $table_manager->set_columns($columns); $table_manager->row_callback = function ($row_data) { // load the full customer data before displaying each row so we have access to more details return module_customer::get_customer($row_data['customer_id']); }; $table_manager->set_rows($customers); $table_manager->pagination = true; $table_manager->print_table(); /** END TABLE LAYOUT **/ ?> </form>
public static function hook_job_task_after($hook, $job_id, $task_id, $job_data, $task_data) { $comments = get_multiple('job_discussion', array('job_id' => $job_id, 'task_id' => $task_id), 'job_discussion_id', 'exact', 'job_discussion_id'); if ($job_data && isset($job_data['job_discussion']) && $job_data['job_discussion'] == 1) { // disabled & hidden. return; } if ($job_data && isset($job_data['job_discussion']) && $job_data['job_discussion'] == 2 && count($comments) == 0) { // disabled & shown. return; } if (isset($_POST['job_discussion_add_job_id']) && isset($_POST['job_discussion_add_task_id']) && $_POST['job_discussion_add_job_id'] == $job_id && $_POST['job_discussion_add_task_id'] == $task_id && isset($_POST['note']) && strlen($_POST['note'])) { $x = 0; while (ob_get_level() && $x++ < 10) { ob_end_clean(); } $current_user_id = module_security::get_loggedin_id(); $customer = module_customer::get_customer($job_data['customer_id']); if (!$current_user_id) { if ($job_data['customer_id'] && $customer['primary_user_id']) { $current_user_id = $customer['primary_user_id']; } } $result = array(); // adding a new note. $job_discussion_id = update_insert('job_discussion_id', 0, 'job_discussion', array('job_id' => $job_id, 'task_id' => $task_id, 'user_id' => $current_user_id, 'note' => $_POST['note'])); $result['job_discussion_id'] = $job_discussion_id; $result['count'] = count($comments) + 1; $tasks = module_job::get_tasks($job_id); $result['email_customer'] = array(); if (isset($_POST['sendemail_customer']) && is_array($_POST['sendemail_customer'])) { //$_POST['sendemail_customer'] == 'yes' && $customer['primary_user_id']){ // send email to customer primary user id. $customer_contacts = module_user::get_contacts(array('customer_id' => $job_data['customer_id'])); foreach ($_POST['sendemail_customer'] as $user_id) { $user_id = (int) $user_id; if ($user_id && isset($customer_contacts[$user_id])) { // we can email this user. $user = module_user::get_user($user_id, false); if ($user && $user['user_id'] == $user_id) { $values = array_merge($user, $job_data); $values['job_url'] = module_job::link_public($job_id); $values['job_url'] .= (strpos($values['job_url'], '?') === false ? '?' : '&') . 'discuss=' . $task_id . '#discuss' . $task_id; $values['job_name'] = $job_data['name']; $values['customer_name'] = $user['name'] . ' ' . $user['last_name']; $values['note'] = $_POST['note']; //todo: no order if no showning numbers $values['task_name'] = '#' . $tasks[$task_id]['task_order'] . ': ' . $tasks[$task_id]['description']; $template = module_template::get_template_by_key('job_discussion_email_customer'); $template->assign_values($values); $html = $template->render('html'); $email = module_email::new_email(); $email->replace_values = $values; $email->set_to('user', $user['user_id']); $email->set_from('user', $current_user_id); $email->set_subject($template->description); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! $result['email_customer'][] = $user['user_id']; } else { /// log err? } } } } /*$user = module_user::get_user($customer['primary_user_id'],false); if($user['user_id'] == $customer['primary_user_id']){ $values = array_merge($user,$job_data); $values['job_url'] = module_job::link_public($job_id); $values['job_url'] .= (strpos($values['job_url'],'?')===false ? '?' : '&').'discuss='.$task_id.'#discuss'.$task_id; $values['job_name'] = $job_data['name']; $values['customer_name'] = $user['name'].' '.$user['last_name']; $values['note'] = $_POST['note']; //todo: no order if no showning numbers $values['task_name'] = '#'.$tasks[$task_id]['task_order'].': '.$tasks[$task_id]['description']; $template = module_template::get_template_by_key('job_discussion_email_customer'); $template->assign_values($values); $html = $template->render('html'); $email = module_email::new_email(); $email->replace_values = $values; $email->set_to('user',$user['user_id']); $email->set_from('user',$current_user_id); $email->set_subject($template->description); // do we send images inline? $email->set_html($html); if($email->send()){ // it worked successfully!! $result['email_customer'] = 1; }else{ /// log err? $result['email_customer'] = 0; } }else{ // log error? $result['email_customer'] = 0; }*/ } if (isset($_POST['sendemail_staff']) && is_array($_POST['sendemail_staff'])) { // == 'yes' && $job_data['user_id'] // todo: handle the restul better when sending to multiple people $result['email_staff_list'] = $_POST['sendemail_staff']; foreach ($_POST['sendemail_staff'] as $staff_id) { // send email to staff $staff_id = (int) $staff_id; if (!$staff_id) { $result['nostaff'] = 1; continue; } if (isset($task_data['user_id']) && $task_data['user_id'] == $staff_id || isset($job_data['user_id']) && $job_data['user_id'] == $staff_id) { //$user = module_user::get_user($job_data['user_id'],false); $user = module_user::get_user($staff_id, false); if ($user['user_id'] == $staff_id) { $values = array_merge($user, $job_data); $values['job_url'] = module_job::link_public($job_id); $values['job_url'] .= (strpos($values['job_url'], '?') === false ? '?' : '&') . 'discuss=' . $task_id . '#discuss' . $task_id; $values['job_name'] = $job_data['name']; $values['staff_name'] = $user['name'] . ' ' . $user['last_name']; $values['note'] = $_POST['note']; //todo: no order if no showning numbers $values['task_name'] = '#' . $tasks[$task_id]['task_order'] . ': ' . $tasks[$task_id]['description']; $template = module_template::get_template_by_key('job_discussion_email_staff'); $template->assign_values($values); $html = $template->render('html'); $email = module_email::new_email(); $email->replace_values = $values; $email->set_to('user', $staff_id); $email->set_from('user', $current_user_id); $email->set_subject($template->description); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! $result['email_staff'] = 1; } else { /// log err? $result['email_staff'] = 0; } } else { // log error? $result['email_staff'] = 0; } } } } $x = 0; while ($x++ < 5 && ob_get_level()) { ob_end_clean(); } header("Content-type: text/javascript", true); echo json_encode($result); exit; } $label = htmlspecialchars(module_config::c('job_discussion_button_label', 'Task Comments')); ?> <a href="<?php echo self::link_public($job_id, $task_id); ?> " id="discuss<?php echo $task_id; ?> " class="task_job_discussion <?php echo $label ? 'with_text' : ''; ?> " title="<?php _e('View Discussion'); ?> "><span><?php echo count($comments) > 0 ? count($comments) : ''; ?> </span><?php echo $label; ?> </a> <div class="task_job_discussion_holder"<?php echo isset($_REQUEST['discuss']) && $_REQUEST['discuss'] == $task_id ? ' style="display:block;"' : ''; ?> > <?php if (isset($_REQUEST['discuss']) && $_REQUEST['discuss'] == $task_id) { $_REQUEST['t'] = $task_id; $_REQUEST['i'] = $job_id; $_REQUEST['hash'] = self::link_public($job_id, $task_id, true); self::external_hook('public'); } ?> </div> <?php }
public function save_user($user_id, $data, $from_public = false) { $use_master_key = $this->get_contact_master_key(); if ($from_public) { $user_id = 0; } else { if ($use_master_key && isset($data[$use_master_key]) && $data[$use_master_key]) { if (!module_user::can_i('edit', 'Contacts', 'Customer')) { set_error('Unable to edit contacts.'); return false; } } else { if (!self::can_i('edit', 'Users', 'Config')) { set_error('Unable to edit users.'); return false; } } $user_id = (int) $user_id; } $temp_user = array(); if ($user_id > 0) { // check permissions $temp_user = $this->get_user($user_id, true, false); if (!$temp_user || $temp_user['user_id'] != $user_id || isset($temp_user['_perms'])) { $user_id = false; } } if (!$user_id && !$from_public) { if ($use_master_key && isset($data[$use_master_key]) && $data[$use_master_key]) { if (!module_user::can_i('create', 'Contacts', 'Customer')) { set_error('Unable to create new contacts.'); return false; } } else { if (!self::can_i('create', 'Users', 'Config')) { set_error('Unable to create new users.'); return false; } } } else { if ($user_id == 1 && module_security::get_loggedin_id() != 1) { set_error('Sorry only the administrator can modify this account'); } } // check the customer id is valid assignment to someone who has these perms. if (!$from_public) { if (isset($data['customer_id']) && (int) $data['customer_id'] > 0) { $temp_customer = module_customer::get_customer($data['customer_id']); if (!$temp_customer || $temp_customer['customer_id'] != $data['customer_id']) { unset($data['customer_id']); } } if (isset($data['vendor_id']) && (int) $data['vendor_id'] > 0) { $temp_vendor = module_vendor::get_vendor($data['vendor_id']); if (!$temp_vendor || $temp_vendor['vendor_id'] != $data['vendor_id']) { unset($data['vendor_id']); } } } if (isset($data['password'])) { unset($data['password']); } // we do the password hash thing here. if (isset($data['password_new']) && strlen($data['password_new'])) { // an admin is trying to set the password for this account. // same permissions checks as on the user_admin_edit_login.php page if (!$user_id || isset($temp_user['password']) && !$temp_user['password'] || module_user::can_i('create', 'Users Passwords', 'Config') || isset($_REQUEST['reset_password']) && $_REQUEST['reset_password'] == module_security::get_auto_login_string($user_id)) { // we allow the admin to set a new password without typing in previous password. $data['password'] = $data['password_new']; } else { set_error('Sorry, no permissions to set a new password.'); } } else { if ($user_id && isset($data['password_new1']) && isset($data['password_new2']) && strlen($data['password_new1'])) { // the user is trying to change their password. // only do this if the user has edit password permissions and their password matches. if (module_user::can_i('edit', 'Users Passwords', 'Config') || $user_id == module_security::get_loggedin_id()) { if (isset($data['password_old']) && (md5($data['password_old']) == $temp_user['password'] || $data['password_old'] == $temp_user['password'])) { // correct old password // verify new password. if ($data['password_new1'] == $data['password_new2']) { $data['password'] = $data['password_new1']; } else { set_error('Verified password mismatch. Password unchanged.'); } } else { set_error('Old password does not match. Password unchanged.'); } } else { set_error('No permissions to change passwords'); } } } // and we finally hash our password if (isset($data['password']) && strlen($data['password']) > 0) { $data['password'] = md5($data['password']); // if you change md5 also change it in customer import. // todo - salt? meh. } $user_id = update_insert("user_id", $user_id, "user", $data); $use_master_key = $this->get_contact_master_key(); // this will be customer_id or supplier_id if ($use_master_key && (isset($data[$use_master_key]) && $data[$use_master_key])) { if ($user_id) { if (isset($data['customer_primary']) && $data['customer_primary']) { // update the customer/supplier to mark them as primary or not.. switch ($use_master_key) { case 'customer_id': module_customer::set_primary_user_id($data['customer_id'], $user_id); break; case 'vendor_id': module_vendor::set_primary_user_id($data['vendor_id'], $user_id); break; } } else { // check if this contact was the old customer/supplier primary and switch ($use_master_key) { case 'customer_id': $customer_data = module_customer::get_customer($data['customer_id']); if ($customer_data['primary_user_id'] == $user_id) { module_customer::set_primary_user_id($data['customer_id'], 0); } break; case 'vendor_id': $vendor_data = module_vendor::get_vendor($data['vendor_id']); if ($vendor_data['primary_user_id'] == $user_id) { module_vendor::set_primary_user_id($data['vendor_id'], 0); } break; } } } } if (!$from_public) { // hack for linked user accounts. if ($user_id && isset($data['link_customers']) && $data['link_customers'] == 'yes' && isset($data['link_user_ids']) && is_array($data['link_user_ids']) && isset($data['email']) && $data['email']) { $others = module_user::get_contacts(array('email' => $data['email'])); foreach ($data['link_user_ids'] as $link_user_id) { if (!(int) $link_user_id) { continue; } if ($link_user_id == $user_id) { continue; } // shouldnt happen foreach ($others as $other) { if ($other['user_id'] == $link_user_id) { // success! they'renot trying to hack us. $sql = "REPLACE INTO `" . _DB_PREFIX . "user_customer_rel` SET user_id = '" . (int) $link_user_id . "', customer_id = '" . (int) $other['customer_id'] . "', `primary` = " . (int) $user_id; query($sql); update_insert('user_id', $link_user_id, 'user', array('linked_parent_user_id' => $user_id)); } } } update_insert('user_id', $user_id, 'user', array('linked_parent_user_id' => $user_id)); } if ($user_id && isset($data['unlink']) && $data['unlink'] == 'yes') { $sql = "DELETE FROM `" . _DB_PREFIX . "user_customer_rel` WHERE user_id = '" . (int) $user_id . "'"; query($sql); update_insert('user_id', $user_id, 'user', array('linked_parent_user_id' => 0)); } handle_hook("address_block_save", $this, "physical", "user", "user_id", $user_id); handle_hook("address_block_save", $this, "postal", "user", "user_id", $user_id); if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) { module_extra::save_extras('user', 'user_id', $user_id); } // find current role / permissions $user_data = $this->get_user($user_id); $previous_user_roles = $user_data['roles']; $re_save_role_perms = false; // hack to support only 1 role (we may support multi-role in the future) // TODO: check we have permissions to set this role id, otherwise anyone can set their own role. if (isset($_REQUEST['role_id'])) { $sql = "DELETE FROM `" . _DB_PREFIX . "user_role` WHERE user_id = '" . (int) $user_id . "'"; query($sql); if ((int) $_REQUEST['role_id'] > 0) { if (!isset($previous_user_roles[$_REQUEST['role_id']])) { $re_save_role_perms = (int) $_REQUEST['role_id']; } $_REQUEST['role'] = array($_REQUEST['role_id'] => 1); } } // save users roles (support for multi roles in future - but probably will never happen) if (isset($_REQUEST['role']) && is_array($_REQUEST['role'])) { foreach ($_REQUEST['role'] as $role_id => $tf) { $this->add_user_to_role($user_id, $role_id); } } if ($re_save_role_perms) { // copy role permissiosn to user permissions $sql = "DELETE FROM `" . _DB_PREFIX . "user_perm` WHERE user_id = " . (int) $user_id; query($sql); // update - we are not relying on these permissions any more. // if the user has a role assigned, we use those permissions period // we ignore all permissions in the user_perm table if the user has a role. // if the user doesn't have a role, then we use these user_perm permissions. /*$security_role = module_security::get_security_role($re_save_role_perms); foreach($security_role['permissions'] as $security_permission_id => $d){ $sql = "INSERT INTO `"._DB_PREFIX."user_perm` SET user_id = ".(int)$user_id.", security_permission_id = '".(int)$security_permission_id."'"; foreach(module_security::$available_permissions as $perm){ $sql .= ", `".$perm."` = ".(int)$d[$perm]; } query($sql); }*/ } else { if (isset($_REQUEST['permission']) && is_array($_REQUEST['permission'])) { $sql = "DELETE FROM `" . _DB_PREFIX . "user_perm` WHERE user_id = '" . (int) $user_id . "'"; query($sql); // update permissions for this user. foreach ($_REQUEST['permission'] as $security_permission_id => $permissions) { $actions = array(); foreach (module_security::$available_permissions as $permission) { if (isset($permissions[$permission]) && $permissions[$permission]) { $actions[$permission] = 1; } } $sql = "REPLACE INTO `" . _DB_PREFIX . "user_perm` SET user_id = '" . (int) $user_id . "', security_permission_id = '" . (int) $security_permission_id . "' "; foreach ($actions as $permission => $tf) { $sql .= ", `" . mysql_real_escape_string($permission) . "` = 1"; } query($sql); } } } /*global $plugins; if($user_id && isset($data['user_type_id']) && $data['user_type_id'] == 1 && $data['site_id']){ // update the site. $plugins['site']->set_primary_user_id($data['site_id'],$user_id); }else{ //this use isn't (or isnt any more) the sites primary user. // unset this if he was the primary user before $site_data = $plugins['site']->get_site($data['site_id']); if(isset($site_data['primary_user_id']) && $site_data['primary_user_id'] == $user_id){ $plugins['site']->set_primary_user_id($data['site_id'],0); } }*/ // save the company information if it's available if (class_exists('module_company', false) && module_company::can_i('edit', 'Company') && module_company::is_enabled() && module_user::can_i('edit', 'User')) { if (isset($_REQUEST['available_user_company']) && is_array($_REQUEST['available_user_company'])) { $selected_companies = isset($_POST['user_company']) && is_array($_POST['user_company']) ? $_POST['user_company'] : array(); foreach ($_REQUEST['available_user_company'] as $company_id => $tf) { if (!isset($selected_companies[$company_id]) || !$selected_companies[$company_id]) { // remove user from this company module_company::delete_user($company_id, $user_id); } else { // add user to this company (if they are not already existing) module_company::add_user_to_company($company_id, $user_id); } } } } } module_cache::clear('user'); return $user_id; }
function listCalendarByRange($sd, $ed) { $ret = array(); $ret['events'] = array(); $ret["issort"] = true; $ret["start"] = php2JsTime($sd); $ret["end"] = php2JsTime($ed); $ret['error'] = null; $calendar_data_access = module_calendar::get_calendar_data_access(); // hook into things like jobs and stuff who want to return calendar entries. $hook_results = hook_handle_callback('calendar_events', $sd, $ed); if (is_array($hook_results) && count($hook_results)) { foreach ($hook_results as $hook_result) { if (is_array($hook_result)) { foreach ($hook_result as $result) { // format our hook results to match our bad (indexed) array, // will update that array in the future /*$calendar_events[] = array( 'subject' => $job['name'], 'customer_id' => $job['customer_id'], 'start_time' => $job['date_start'], 'user_id' => $job['user_id'], 'description' => 'Test Description', 'link' => module_job::link_open($job['job_id'],true,$job), );*/ $staff_names = array(); if (isset($result['staff_ids']) && count($result['staff_ids'])) { switch ($calendar_data_access) { case _CALENDAR_ACCESS_ALL: break; case _CALENDAR_ACCESS_ASSIGNED: default: $current_user = module_security::get_loggedin_id(); if (!in_array($current_user, $result['staff_ids'])) { continue 2; } break; } foreach ($result['staff_ids'] as $staff_id) { $staff_names[] = module_user::link_open($staff_id, true); } } $staff_names = implode(', ', $staff_names); $result[0] = false; // no calendar ID at the moment $result[1] = $result['subject']; $result[2] = php2JsTime($result['start_time']); $result[3] = php2JsTime(isset($result['end_time']) ? $result['end_time'] : $result['start_time']); $result[4] = !isset($result['all_day']) || $result['all_day']; $result[5] = 0; $result[6] = 0; $result[7] = 0; //col $result[8] = 2; $result[9] = 0; $result[10] = 0; $result[13] = $result['customer_id']; $result[12] = $result['link']; $result[14] = isset($_REQUEST['customer_id']) && $_REQUEST['customer_id'] != $result['customer_id'] ? 'chip-fade' : ''; $result['staff'] = $staff_names; $ret['events'][] = $result; } } } } try { $sql = "select * from `" . _DB_PREFIX . "calendar` where `start` >= '" . mysql_real_escape_string($sd) . "' AND `start` <= '" . mysql_real_escape_string($ed) . "'"; // echo $sql; $rows = qa($sql); foreach ($rows as $row) { //$ret['events'][] = $row; //$attends = $row->AttendeeNames; //if($row->OtherAttendee){ // $attends .= $row->OtherAttendee; //} //echo $row->StartTime; $more_than_1_day = date('Ymd', $row['start']) == date('Ymd', $row['end']) ? 0 : 1; $customer_name = $customer_link = ''; if ($row['customer_id'] > 0) { $customer_data = module_customer::get_customer($row['customer_id'], true, true); if (!$customer_data || $customer_data['customer_id'] != $row['customer_id']) { $row['customer_id'] = 0; } else { switch ($calendar_data_access) { case _CALENDAR_ACCESS_ALL: break; case _CALENDAR_ACCESS_ASSIGNED: default: if (isset($customer_data['_no_access'])) { continue 2; } break; } $customer_name = $customer_data['customer_name']; $customer_link = module_customer::link_open($row['customer_id'], true, $customer_data); } } $calendar_event = module_calendar::get_calendar($row['calendar_id']); $staff_names = array(); if (count($calendar_event['staff_ids'])) { switch ($calendar_data_access) { case _CALENDAR_ACCESS_ALL: break; case _CALENDAR_ACCESS_ASSIGNED: default: $current_user = module_security::get_loggedin_id(); if (!in_array($current_user, $calendar_event['staff_ids'])) { continue 2; } break; } foreach ($calendar_event['staff_ids'] as $staff_id) { $staff_names[] = module_user::link_open($staff_id, true); } } $staff_names = implode(', ', $staff_names); $ret['events'][] = array(0 => $row['calendar_id'], 1 => $row['subject'], 2 => php2JsTime($row['start']), 3 => php2JsTime($row['end']), 4 => $row['is_all_day'], 5 => $more_than_1_day, 6 => 0, 7 => $row['color'], 8 => 1, 9 => '', 10 => '', 11 => $customer_name, 12 => $customer_link, 13 => $row['customer_id'], 14 => isset($_REQUEST['customer_id']) && $_REQUEST['customer_id'] != $row['customer_id'] ? 'chip-fade' : '', 'staff' => $staff_names); } } catch (Exception $e) { $ret['error'] = $e->getMessage(); } // build bubble content based on event data: foreach ($ret['events'] as $event_id => $event) { if (!isset($event['bubble'])) { $ret['events'][$event_id]['bubble'] = '<div id="bbit-cs-buddle" style="z-index: 1080; width: 400px;visibility:hidden;" class="bubble"><table class="bubble-table" cellSpacing="0" cellPadding="0"><tbody><tr><td class="bubble-cell-side"><div id="tl1" class="bubble-corner"><div class="bubble-sprite bubble-tl"></div></div><td class="bubble-cell-main"><div class="bubble-top"></div><td class="bubble-cell-side"><div id="tr1" class="bubble-corner"><div class="bubble-sprite bubble-tr"></div></div> <tr><td class="bubble-mid" colSpan="3"><div style="overflow: hidden" id="bubbleContent1"><div><div></div><div class="cb-root"><table class="cb-table" cellSpacing="0" cellPadding="0"><tbody>' . '<tr>' . '<td class="cb-value"><div class="textbox-fill-wrapper"><div class="textbox-fill-mid"><div id="bbit-cs-what" title="' . htmlspecialchars(_l('View Details')) . '" class="textbox-fill-div lk" style="cursor:pointer;">' . htmlspecialchars($event[1]) . '</div></div></div></td></tr><tr><td class=cb-value><div id="bbit-cs-buddle-timeshow"></div></td>' . '</tr>' . '<tr><td class=cb-value><div id="bbit-cs-customer-link">' . _l('Customer: %s', $event[12] ? $event[12] : _l('N/A')) . '</div></td></tr>' . (isset($event['other_details']) && strlen($event['other_details']) ? '<tr><td class=cb-value><div id="bbit-cs-customer-link">' . $event['other_details'] . '</div></td></tr>' : '') . '<tr><td class=cb-value><div id="bbit-cs-staff-link">' . _l('Staff: %s', $event['staff'] ? $event['staff'] : _l('N/A')) . '</div></td></tr>' . '</tbody></table>' . ($event[8] == 1 ? '<div class="bbit-cs-split"><input id="bbit-cs-id" type="hidden" value=""/>' . (module_calendar::can_i('delete', 'Calendar') ? '[ <span id="bbit-cs-delete" class="lk">' . htmlspecialchars(_l('Delete')) . '</span> ] ' : '') . (module_calendar::can_i('edit', 'Calendar') ? ' <span id="bbit-cs-editLink" class="lk">' . htmlspecialchars(_l('Edit Event')) . ' </span>' : '') . '</div> ' : '') . '</div></div></div><tr><td><div id="bl1" class="bubble-corner"><div class="bubble-sprite bubble-bl"></div></div><td><div class="bubble-bottom"></div><td><div id="br1" class="bubble-corner"><div class="bubble-sprite bubble-br"></div></div></tr></tbody></table><div id="bubbleClose2" class="bubble-closebutton"></div><div id="prong1" class="prong"><div class=bubble-sprite></div></div></div>'; } } return $ret; }
"i_delete": "<?php _e('Delete'); ?> ", "day_plural": "<?php _e('days'); ?> ", "others": "<?php _e('Others'); ?> ", "item": "", "new_customer_name": "<?php if ($customer_id) { $customer_data = module_customer::get_customer($customer_id); if ($customer_data && $customer_data['customer_id'] == $customer_id) { echo addcslashes(htmlspecialchars($customer_data['customer_name']), '"'); } } ?> " } }); </script> <script src="<?php echo $base_path; ?> src/Plugins/jquery.calendar.js?ver=<?php echo _SCRIPT_VERSION; ?>
$can_edit_emails = true; } else { $can_edit_emails = false; // don't want to edit existing email } $current_template = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : 'email_template_blank'; $find_other_templates = 'email_template_'; $to = module_user::get_contacts(array('customer_id' => $customer_id)); $bcc = module_config::c('admin_email_address', ''); $headers = @unserialize($email['headers']); if ($current_template && !$email_id) { $template = module_template::get_template_by_key($current_template); //todo: replace fields. //$replace = module_invoice::get_replace_fields($invoice_id,$invoice); if ($email['customer_id']) { $customer_data = module_customer::get_customer($email['customer_id']); $replace = module_customer::get_replace_fields($email['customer_id'], false, $customer_data); $template->assign_values($replace); } if ($email['job_id']) { $job_data = module_job::get_job($email['job_id']); $replace = module_job::get_replace_fields($email['job_id'], $job_data); $template->assign_values($replace); } if ($email['website_id']) { $website_data = module_website::get_website($email['website_id']); $replace = module_website::get_replace_fields($email['website_id'], $website_data); $template->assign_values($replace); } $email['text_content'] = $template->render('html'); $email['subject'] = $template->replace_description();
$template_name = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : 'job_email'; $template = module_template::get_template_by_key($template_name); $job['total_amount_print'] = dollar($job['total_amount'], true, $job['currency_id']); $job['total_amount_due_print'] = dollar($job['total_amount_due'], true, $job['currency_id']); $job['job_name'] = $job['name']; $job['from_name'] = module_security::get_loggedin_name(); $job['job_url'] = module_job::link_public($job_id); ob_start(); $job_data = $job; $ignore_task_hook = true; $for_email = true; include 'job_public.php'; $job['job_tasks'] = ob_get_clean(); // find available "to" recipients. // customer contacts. $to_select = false; if ($job['customer_id']) { $customer = module_customer::get_customer($job['customer_id']); $job['customer_name'] = $customer['customer_name']; $to = module_user::get_contacts(array('customer_id' => $job['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(); } $template->assign_values($job); module_email::print_compose(array('title' => _l('Email Job: %s', $job['name']), 'find_other_templates' => 'job_email', 'current_template' => $template_name, 'customer_id' => $job['customer_id'], 'job_id' => $job['job_id'], 'debug_message' => 'Sending job 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_job::link_open($job_id), 'cancel_url' => module_job::link_open($job_id)));
public static function get_ticket($ticket_id, $full = true) { $cache_key_args = func_get_args(); $cache_key = self::_ticket_cache_key($ticket_id, $cache_key_args); $cache_timeout = module_config::c('cache_objects', 60); if ($cached_item = module_cache::get('ticket', $cache_key)) { return $cached_item; } $ticket_access = self::get_ticket_data_access(); $ticket_id = (int) $ticket_id; $ticket = false; if ($ticket_id > 0) { //$ticket = get_single("ticket","ticket_id",$ticket_id); $sql = "SELECT * FROM `" . _DB_PREFIX . "ticket` t WHERE t.ticket_id = {$ticket_id} "; switch ($ticket_access) { case _TICKET_ACCESS_ALL: break; case _TICKET_ACCESS_ASSIGNED: // we only want tickets assigned to me. //$sql .= " AND t.assigned_user_id = '".(int)module_security::get_loggedin_id()."'"; $sql .= " AND (t.assigned_user_id = '" . (int) module_security::get_loggedin_id() . "' OR t.assigned_user_id = 0)"; break; case _TICKET_ACCESS_CREATED: // we only want tickets I created. $sql .= " AND t.user_id = '" . (int) module_security::get_loggedin_id() . "'"; break; case _TICKET_ACCESS_CUSTOMER: $valid_customer_ids = module_security::get_customer_restrictions(); if (is_array($valid_customer_ids) && count($valid_customer_ids)) { $sql .= " AND ( "; foreach ($valid_customer_ids as $valid_customer_id) { $sql .= " t.customer_id = '" . (int) $valid_customer_id . "' OR "; } $sql = rtrim($sql, 'OR '); $sql .= " )"; } break; } $ticket = qa1($sql, false); } if ($full === 2) { module_cache::put('ticket', $cache_key, $ticket, $cache_timeout); return $ticket; } if (!$ticket) { $customer_id = $website_id = 0; $user_id = module_security::get_loggedin_id(); if (isset($_REQUEST['customer_id']) && $_REQUEST['customer_id']) { // $customer_id = (int) $_REQUEST['customer_id']; $customer = module_customer::get_customer($customer_id); if (!$customer || $customer['customer_id'] != $customer_id) { $customer_id = 0; } else { $user_id = $customer['primary_user_id']; } // find default website id to use. if (isset($_REQUEST['website_id'])) { $website_id = (int) $_REQUEST['website_id']; $website = module_website::get_website($website_id); if (!$website || $website['website_id'] != $website_id || $website['customer_id'] != $customer_id) { $website_id = 0; } } else { $website_id = 0; } } $position = self::ticket_position(); $ticket = array('ticket_id' => 'new', 'customer_id' => $customer_id, 'website_id' => $website_id, 'subject' => '', 'date_completed' => '', 'status_id' => _TICKET_STATUS_NEW_ID, 'user_id' => $user_id, 'assigned_user_id' => module_config::c('ticket_default_user_id', 1), 'ticket_account_id' => module_config::c('ticket_default_account_id', 0), 'last_message_timestamp' => 0, 'last_ticket_message_id' => 0, 'message_count' => 0, 'position' => $position['current'] + 1, 'priority' => 0, 'ticket_type_id' => module_config::c('ticket_type_id_default', 0), 'total_pending' => $position['total'] + 1, 'extra_data' => array(), 'invoice_id' => false, 'faq_product_id' => false); } else { // find the position of this ticket // the position is determined by the number of pending tickets // that have a last_message_timestamp earlier than this ticket. $position = self::ticket_position($ticket_id); $ticket['position'] = $position['current']; $ticket['total_pending'] = $position['total']; /*if($ticket['priority'] == _TICKET_PRIORITY_STATUS_ID){ $ticket['position'] = self::ticket_count('priority',$ticket['last_message_timestamp'],$ticket['ticket_id'],$ticket['priority']); }else{ $ticket['position'] = self::ticket_count('pending',$ticket['last_message_timestamp'],$ticket['ticket_id'],$ticket['priority']); } $ticket['total_pending'] = self::ticket_count('pending');*/ $messages = self::get_ticket_messages($ticket_id, true); //$ticket['message_count'] = count($messages); $ticket['message_count'] = mysql_num_rows($messages); //end($messages); if ($ticket['message_count'] > 0) { mysql_data_seek($messages, $ticket['message_count'] - 1); } //$last_message = current($messages); $last_message = mysql_fetch_assoc($messages); $ticket['last_ticket_message_id'] = $last_message['ticket_message_id']; $ticket['last_message_was_private'] = isset($last_message['private_message']) && $last_message['private_message']; // for passwords and website addresses.. $ticket['extra_data'] = self::get_ticket_extras($ticket_id); // hook into the envato module. // link any missing envato/faqproduct items together. if (class_exists('module_envato', false) && isset($_REQUEST['faq_product_envato_hack']) && (!$ticket['faq_product_id'] || $ticket['faq_product_id'] == $_REQUEST['faq_product_envato_hack'])) { $items = module_envato::get_items_by_ticket($ticket['ticket_id']); foreach ($items as $envato_item_id => $item) { // see if this item is linked to a product. if ($item['envato_item_id']) { $sql = "SELECT * FROM `" . _DB_PREFIX . "faq_product` WHERE envato_item_ids REGEXP '[|]*" . $envato_item_id . "[|]*'"; $res = qa1($sql); if ($res && $res['faq_product_id']) { // found a product matching this one. link her up. update_insert('ticket_id', $ticket_id, 'ticket', array('faq_product_id' => $res['faq_product_id'])); break; } } } } } module_cache::put('ticket', $cache_key, $ticket, $cache_timeout); return $ticket; }
public static function multisafepay_redirect($description, $amount, $user_id, $payment_id, $invoice_id, $currency_id) { $currency = module_config::get_currency($currency_id); if ($currency['code'] != 'EUR') { echo "Multisafepay only accepts currency in EUR"; } include 'MultiSafepay.combined.php'; $msp = new MultiSafepay(); /* * Merchant Settings */ $msp->test = self::is_sandbox(); $msp->merchant['account_id'] = module_config::c('payment_method_multisafepay_account', ''); $msp->merchant['site_id'] = module_config::c('payment_method_multisafepay_site_id', ''); $msp->merchant['site_code'] = module_config::c('payment_method_multisafepay_side_code', ''); $msp->merchant['notification_url'] = full_link(_EXTERNAL_TUNNEL . '?m=paymethod_multisafepay&h=ipn&method=multisafepay&type=initial'); $msp->merchant['cancel_url'] = module_invoice::link_public($invoice_id); // optional automatic redirect back to the shop: $msp->merchant['redirect_url'] = module_invoice::link_public($invoice_id); /* * Customer Details */ $invoice = $invoice_data = module_invoice::get_invoice($invoice_id); $customer = module_customer::get_customer($invoice_data['customer_id'], true); if (!$user_id) { $user_id = $customer['primary_user_id']; } $user = module_user::get_user($user_id, false); //$msp->customer['locale'] = 'nl'; $msp->customer['firstname'] = $user['name']; $msp->customer['lastname'] = $user['last_name']; $address = module_address::get_address($invoice_data['customer_id'], 'customer', 'physical'); $msp->customer['zipcode'] = isset($address['post_code']) ? $address['post_code'] : ''; $msp->customer['city'] = isset($address['region']) ? $address['region'] : ''; $msp->customer['country'] = isset($address['country']) ? $address['country'] : module_config::c('payment_method_multisafepay_country', ''); $msp->customer['phone'] = $user['phone']; $msp->customer['email'] = $user['email']; $msp->parseCustomerAddress(isset($address['line_1']) ? $address['line_1'] : ''); // or // $msp->customer['address1'] = 'Teststraat'; // $msp->customer['housenumber'] = '21'; /* * Transaction Details */ $msp->transaction['id'] = self::multisafepay_custom($user_id, $payment_id, $invoice_id); $msp->transaction['currency'] = $currency['code']; $msp->transaction['amount'] = $amount * 100; // cents $msp->transaction['description'] = $description; $msp->transaction['items'] = '<br/><ul>'; // copied from invoice_task_list.php foreach (module_invoice::get_invoice_items($invoice_id) as $invoice_item_id => $invoice_item_data) { // copy any changes here to template/invoice_task_list.php $task_hourly_rate = isset($invoice_item_data['hourly_rate']) && $invoice_item_data['hourly_rate'] != 0 ? $invoice_item_data['hourly_rate'] : $invoice_data['hourly_rate']; // if there are no hours logged against this task if (!$invoice_item_data['hours']) { //$task_hourly_rate=0; } // if we have a custom price for this task if ($invoice_item_data['amount'] != 0 && $invoice_item_data['amount'] != $invoice_item_data['hours'] * $task_hourly_rate) { $invoice_item_amount = $invoice_item_data['amount']; $task_hourly_rate = false; } else { if ($invoice_item_data['hours'] > 0) { $invoice_item_amount = $invoice_item_data['hours'] * $task_hourly_rate; } else { $invoice_item_amount = 0; $task_hourly_rate = false; } } $msp->transaction['items'] .= '<li>'; $msp->transaction['items'] .= $invoice_item_data['hours'] > 0 ? $invoice_item_data['hours'] . ' x ' : ''; $msp->transaction['items'] .= $invoice_item_data['custom_description'] ? htmlspecialchars($invoice_item_data['custom_description']) : htmlspecialchars($invoice_item_data['description']); $msp->transaction['items'] .= ' = ' . dollar($invoice_item_amount, true, $invoice['currency_id']); $msp->transaction['items'] .= '</li>'; } $msp->transaction['items'] .= '<li>Sub Total: ' . dollar($invoice_data['total_sub_amount'], true, $invoice_data['currency_id']) . '</li>'; if ($invoice_data['total_tax_rate'] > 0) { $msp->transaction['items'] .= '<li>' . $invoice['total_tax_name'] . ' ' . $invoice['total_tax_rate'] . '% = ' . dollar($invoice['total_tax'], true, $invoice['currency_id']) . '</li>'; } $msp->transaction['items'] .= '<li>Total: ' . dollar($invoice['total_amount'], true, $invoice['currency_id']) . '</li>'; $msp->transaction['items'] .= '</ul>'; // returns a payment url $url = $msp->startTransaction(); if ($msp->error) { echo "Error " . $msp->error_code . ": " . $msp->error; exit; } // redirect redirect_browser($url); /* $url = 'https://www.'. (self::is_sandbox()? 'sandbox.' : '') . 'multisafepay.com/cgi-bin/webscr?'; $fields = array( 'cmd' => '_xclick', 'business' => module_config::c('payment_method_multisafepay_email',_ERROR_EMAIL), 'currency_code' => $currency['code'], 'item_name' => $description, 'amount' => $amount, 'return' => module_invoice::link_open($invoice_id), 'notify_url' => full_link(_EXTERNAL_TUNNEL.'?m=paymethod_multisafepay&h=ipn&method=multisafepay'), 'custom' => self::multisafepay_custom($user_id,$payment_id,$invoice_id), ); foreach($fields as $key=>$val){ $url .= $key.'='.urlencode($val).'&'; } //echo '<a href="'.$url.'">'.$url.'</a>';exit; redirect_browser($url); */ }
private static function send_job_task_email($job_id, $task_id, $reason) { $return_messages = array(); if (module_config::c('job_send_staff_task_email_automatically', 0) && $reason == 'created') { // send the same emial as if going to job_admin_email_staff.php $task_data = self::get_task($job_id, $task_id); $job_data = self::get_job($job_id); if ($task_data['user_id'] > 0 && $task_data['user_id'] != module_security::get_loggedin_id()) { $staff = module_user::get_user($task_data['user_id']); if ($staff && $staff['user_id'] == $task_data['user_id'] && !(module_config::c('job_staff_email_skip_complete', 0) && $task_data['fully_completed'])) { $template = module_template::get_template_by_key('job_staff_email'); $job_data['job_name'] = $job_data['name']; $job_data['staff_name'] = $staff['name']; $job_data['job_url'] = module_job::link_open($job_id); $job_data['job_tasks'] = '<ul>'; $job_data['task_count'] = 0; //foreach($job_tasks as $job_task){ $job_task = $task_data; //if($job_task['user_id']!=$staff_id)continue; //if(module_config::c('job_staff_email_skip_complete',0)&&$job_task['fully_completed'])continue; $job_data['job_tasks'] .= '<li><strong>' . $job_task['description'] . '</strong>'; if ($job_task['fully_completed']) { $job_data['job_tasks'] .= ' <span style="color: #99cc00; font-weight:bold;">(' . _l('complete') . ')</span>'; } $job_data['job_tasks'] .= ' <br/>'; if ($job_task['long_description']) { $job_data['job_tasks'] .= _l('Notes:') . ' <em>' . $job_task['long_description'] . '</em><br/>'; } if ($job_task['date_due'] && $job_task['date_due'] != '0000-00-00') { $job_data['job_tasks'] .= _l('Date Due:') . ' ' . print_date($job_task['date_due']) . '<br/>'; } if ($job_task['hours']) { $job_data['job_tasks'] .= _l('Assigned Hours:') . ' ' . $job_task['hours'] . '<br/>'; } if ($job_task['completed']) { $job_data['job_tasks'] .= _l('Completed Hours:') . ' ' . $job_task['completed'] . '<br/>'; } $job_data['job_tasks'] .= '</li>'; $job_data['task_count']++; //} $job_data['job_tasks'] .= '</ul>'; // find available "to" recipients. // customer contacts. $to = array(); $to[] = array('name' => $staff['name'], 'email' => $staff['email']); $html = $template->render('html'); // send an email to this user. $email = module_email::new_email(); $email->replace_values = $job_data; $email->set_to('user', $staff['user_id']); $email->set_bcc_manual(module_config::c('admin_email_address', ''), ''); //$email->set_from('user',); // nfi $email->set_subject($template->description); // do we send images inline? $email->set_html($html); $email->job_id = $job_id; $email->prevent_duplicates = true; if ($email->send(false)) { self::add_history($job_id, _l('Job task emailed to staff successfully')); $return_messages[] = _l(' and email sent to staff %s', $staff['name']); } else { /// log err? } } } } if (module_config::c('job_send_task_completion_email_automatically', 0) && isset($_POST['confirm_job_task_email'])) { $task_data = self::get_task($job_id, $task_id); $job_data = self::get_job($job_id); if ($task_data['fully_completed'] && $job_data['customer_id']) { $template_name = 'job_task_completion_email'; /*if(class_exists('module_company',false) && isset($invoice_data['company_id']) && (int)$invoice_data['company_id']>0){ module_company::set_current_company_id($invoice_data['company_id']); }*/ $template = module_template::get_template_by_key($template_name); $replace = module_job::get_replace_fields($job_id, $job_data); $to_select = false; if ($job_data['customer_id']) { $customer = module_customer::get_customer($job_data['customer_id']); $replace['customer_name'] = $customer['customer_name']; $to = module_user::get_contacts(array('customer_id' => $job_data['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(); } $replace['job_name'] = $job_data['name']; $replace['task_description'] = $task_data['description']; $template->assign_values($replace); $html = $template->render('html'); // send an email to this user. $email = module_email::new_email(); $email->replace_values = $replace; // todo: send to all customer contacts ? if ($to_select) { $email->set_to_manual($to_select); } else { foreach ($to as $t) { $email->set_to_manual($t['email']); break; // only 1? todo: all? } } $email->set_bcc_manual(module_config::c('admin_email_address', ''), ''); //$email->set_from('user',); // nfi $email->set_subject($template->description); // do we send images inline? $email->set_html($html); $email->job_id = $job_id; $email->customer_id = $job_data['customer_id']; $email->prevent_duplicates = true; if ($email->send(false)) { // it worked successfully!! // record a log on the invoice when it's done. /*self::email_sent(array( 'invoice_id' => $invoice_id, 'template_name' => $template_name, ));*/ self::add_history($job_id, _l('Job task emailed to customer successfully')); $return_messages[] = _l(' and email sent to customer'); } else { // log err? } } } // if we are approving or rejecting job tasks with a message. if (isset($_POST['job_task'][$task_id]['approval_actioned']) && $_POST['job_task'][$task_id]['approval_actioned']) { $task_data = self::get_task($job_id, $task_id); $job_data = self::get_job($job_id); if ($task_data['user_id'] > 0) { $staff = module_user::get_user($task_data['user_id']); if ($staff && $staff['user_id'] == $task_data['user_id'] && !(module_config::c('job_staff_email_skip_complete', 0) && $task_data['fully_completed'])) { $template = module_template::get_template_by_key('job_task_approval'); $job_data['job_name'] = $job_data['name']; $job_data['staff_name'] = $staff['name']; $job_data['job_url'] = module_job::link_open($job_id); $job_data['approved_or_rejected'] = $_POST['job_task'][$task_id]['approval_required'] == 2 ? _l('Rejected') : _l('Approved'); $job_data['message'] = isset($_POST['job_task'][$task_id]['approval_message']) ? $_POST['job_task'][$task_id]['approval_message'] : _l('N/A'); $job_data['job_task'] = '<ul>'; $job_data['task_count'] = 0; //foreach($job_tasks as $job_task){ $job_task = $task_data; //if($job_task['user_id']!=$staff_id)continue; //if(module_config::c('job_staff_email_skip_complete',0)&&$job_task['fully_completed'])continue; $job_data['job_task'] .= '<li><strong>' . $job_task['description'] . '</strong>'; if ($job_task['fully_completed']) { $job_data['job_task'] .= ' <span style="color: #99cc00; font-weight:bold;">(' . _l('complete') . ')</span>'; } $job_data['job_task'] .= ' <br/>'; if ($job_task['long_description']) { $job_data['job_task'] .= _l('Notes:') . ' <em>' . $job_task['long_description'] . '</em><br/>'; } if ($job_task['date_due'] && $job_task['date_due'] != '0000-00-00') { $job_data['job_task'] .= _l('Date Due:') . ' ' . print_date($job_task['date_due']) . '<br/>'; } if ($job_task['hours']) { $job_data['job_task'] .= _l('Assigned Hours:') . ' ' . $job_task['hours'] . '<br/>'; } if (isset($job_task['completed']) && $job_task['completed']) { $job_data['job_task'] .= _l('Completed Hours:') . ' ' . (isset($job_task['completed']) ? $job_task['completed'] : '') . '<br/>'; } $job_data['job_task'] .= '</li>'; $job_data['task_count']++; //} $job_data['job_task'] .= '</ul>'; // find available "to" recipients. // customer contacts. $to = array(); $to[] = array('name' => $staff['name'], 'email' => $staff['email']); $template->assign_values($job_data); $html = $template->render('html'); // send an email to this user. $email = module_email::new_email(); $email->replace_values = $job_data; $email->set_to('user', $staff['user_id']); $email->set_bcc_manual(module_config::c('admin_email_address', ''), ''); //$email->set_from('user',); // nfi $email->set_subject($template->description); // do we send images inline? $email->set_html($html); $email->job_id = $job_id; $email->prevent_duplicates = true; if ($email->send(false)) { self::add_history($job_id, _l('Job task emailed to staff successfully')); $return_messages[] = _l(' and email sent to staff %s', $staff['name']); } else { /// log err? } } } } if (count($return_messages)) { return array('message' => implode(' ', $return_messages)); } return false; }
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 run_cron($debug = false) { // we only want to perform these cron actions if we're after a certain time of day // because we dont want to be generating these renewals and sending them at midnight, can get confusing $after_time = module_config::c('invoice_automatic_after_time', 7); $time_of_day = date('G'); if ($time_of_day < $after_time) { if ($debug) { echo "Not performing automatic subscription operations until after {$after_time}:00 - it is currently {$time_of_day}:" . date('i') . "<br>\n"; } return; } // find all automatic subscriptions and renew them (if applicable) $sql = "SELECT * FROM `" . _DB_PREFIX . "subscription` s "; $sql .= " WHERE s.automatic_renew = 1"; $subscriptions = qa($sql); foreach ($subscriptions as $subscription) { if ($subscription['automatic_renew']) { if ($debug) { echo "<br>\nProcessing subscription renewals for subscription " . module_subscription::link_open($subscription['subscription_id'], true) . "<br>\n<br>\n"; } // find all the members/customers from this subscription //$members = module_subscription::get_subscribed_members($subscription['subscription_id']); //$customers = module_subscription::get_subscribed_customers($subscription['subscription_id']); $owners = module_subscription::get_subscribed_owners($subscription['subscription_id']); foreach ($owners as $member) { if (!$member['next_generation_date'] || $member['next_generation_date'] == '0000-00-00') { continue; } if (!$member['next_due_date'] || $member['next_due_date'] == '0000-00-00') { continue; } if ($debug) { echo "Doing: " . $member['owner_table'] . " " . $member['owner_id'] . "<br>\n"; } // check permissions for logged in users, dont want the cron to run when someone is logged in and no access to this account. if (module_security::is_logged_in()) { switch ($member['owner_table']) { case 'website': $website_perm_check = module_website::get_website($member['owner_id']); if (!$website_perm_check || $website_perm_check['website_id'] != $member['owner_id']) { continue 2; } if ($debug) { echo "permission pass for website: " . $website_perm_check['website_id']; } break; case 'customer': $customer_perm_check = module_customer::get_customer($member['owner_id']); if (!$customer_perm_check || $customer_perm_check['customer_id'] != $member['owner_id']) { continue 2; } if ($debug) { echo "permission pass for customer: " . $customer_perm_check['customer_id']; } break; } } // is the last invoice unpaid? $history = self::get_subscription_history($subscription['subscription_id'], $member['owner_table'], $member['owner_id']); $next_due_time_invoice_created = false; $invoice_unpaid = false; if (isset($member['recur_limit']) && (int) $member['recur_limit'] > 0 && count($history) >= (int) $member['recur_limit']) { if ($debug) { echo " - not renewing this one because it has hit our recur limit of " . $member['recur_limit'] . "<br>\n"; } continue; } foreach ($history as $h) { $last_invoice = module_invoice::get_invoice($h['invoice_id']); if (!$last_invoice || $last_invoice['date_cancel'] != '0000-00-00') { continue; } // check the new 'next_due_date' entry in the db table if (isset($h['from_next_due_date']) && $h['from_next_due_date'] && $h['from_next_due_date'] != '0000-00-00') { // we're using the new method of checking when an invoice was generated, rather than the confusing invoice 'date_create' check below if ($debug) { echo " - checking if next_due_date " . print_date($member['next_due_date']) . " matches subscription history from_next_due_date for invoice " . module_invoice::link_open($h['invoice_id'], true, $last_invoice) . " from_next_due_date: " . print_date($h['from_next_due_date']) . " (invoice create_date: " . print_date($last_invoice['date_create']) . ")<br>\n"; } if (print_date($member['next_due_date']) == print_date($h['from_next_due_date'])) { //print_date($last_invoice['date_create'])){ // this invoice is for the next due date. $next_due_time_invoice_created = $last_invoice; } } else { if ($debug) { echo " - checking if next_generation_date (" . print_date($member['next_generation_date']) . ") or next_due_date (" . print_date($member['next_due_date']) . ") matches invoice " . module_invoice::link_open($h['invoice_id'], true, $last_invoice) . " created date (" . print_date($last_invoice['date_create']) . ") <br>\n"; } if (print_date($member['next_generation_date']) == print_date($last_invoice['date_create']) || print_date($member['next_due_date']) == print_date($last_invoice['date_create'])) { //print_date($last_invoice['date_create'])){ // this invoice is for the next due date. $next_due_time_invoice_created = $last_invoice; } } if ($last_invoice['total_amount_due'] > 0) { $invoice_unpaid = true; } } //self::generate_subscription_invoice($subscription_id, $customer_hack, $member_id, $date, $amount) $next_due_time = strtotime($member['next_generation_date']); if ($debug) { echo " - next subscription time is " . $member['next_generation_date'] . " <br>\n"; } if ($next_due_time <= strtotime(date('Y-m-d')) && !$next_due_time_invoice_created) { if ($debug) { echo " - Yes its time to generate an invoice!<br>\n"; } if (module_config::c('invoice_auto_renew_only_paid_invoices', 1) && $invoice_unpaid) { if ($debug) { echo " - skipping generating renewal for " . $member['owner_table'] . " " . $member['owner_id'] . " because a previous subscription is unpaid <br>\n"; } continue; } // time to generate! woo! if ($debug) { echo " - generating subscription renewal for " . $member['owner_table'] . " " . $member['owner_id'] . "<br>\n"; } $invoice_id = self::generate_subscription_invoice($subscription['subscription_id'], $member['owner_table'], $member['owner_id'], $member['next_generation_date'], $subscription['amount']); if ($debug) { echo " - generated invoice " . module_invoice::link_open($invoice_id, true) . " for subscription <br>\n"; } if ($subscription['automatic_email']) { if ($debug) { echo " - emailing invoice to " . $member['owner_table'] . "... <br>\n"; } if (module_invoice::email_invoice_to_customer($invoice_id, $debug)) { if ($debug) { echo "send successfully <br>\n"; } } else { echo " - failed to send invoice " . module_invoice::link_open($invoice_id, true) . " to " . $member['owner_table'] . " <br>\n"; } } } else { if ($debug) { echo " - skipping generating renewal for " . $member['owner_table'] . " " . $member['owner_id'] . " because the due date has already been generated <br>\n"; } } } } } }
$page_type = 'Customers'; $page_type_single = 'Customer'; $current_customer_type_id = module_customer::get_current_customer_type_id(); if ($current_customer_type_id > 0) { $customer_type = module_customer::get_customer_type($current_customer_type_id); if ($customer_type && !empty($customer_type['type_name'])) { $page_type = $customer_type['type_name_plural']; $page_type_single = $customer_type['type_name']; } } if (!module_customer::can_i('view', $page_type)) { redirect_browser(_BASE_HREF); } $customer_id = (int) $_REQUEST['customer_id']; $customer = array(); $customer = module_customer::get_customer($customer_id); if ($customer_id > 0 && $customer['customer_id'] == $customer_id) { $module->page_title = _l($page_type_single . ': %s', $customer['customer_name']); } else { $module->page_title = _l($page_type_single . ': %s', _l('New')); } // check permissions. if (class_exists('module_security', false)) { if ($customer_id > 0 && $customer['customer_id'] == $customer_id) { // if they are not allowed to "edit" a page, but the "view" permission exists // then we automatically grab the page and regex all the crap out of it that they are not allowed to change // eg: form elements, submit buttons, etc.. module_security::check_page(array('category' => 'Customer', 'page_name' => $page_type, 'module' => 'customer', 'feature' => 'Edit')); } else { module_security::check_page(array('category' => 'Customer', 'page_name' => $page_type, 'module' => 'customer', 'feature' => 'Create')); }
ob_start(); if (isset($user_id) && (int) $user_id > 0) { module_user::print_contact_summary($user_id, 'text', array('name', 'last_name', 'email')); } $short_user_details = ob_get_clean(); $fieldset_data = array('heading' => array('type' => 'h3', 'title' => isset($title) ? $title : 'Primary Contact Details', 'responsive' => array('title' => isset($title) ? $title : 'Primary Contact', 'summary' => htmlspecialchars($short_user_details))), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array()); /*if($customer['primary_user_id']){ $fieldset_data['heading']['button'] = array( 'title' => 'More', 'url' => module_user::link_open_contact($customer['primary_user_id'],false) ); }*/ if (isset($use_master_key) && ($use_master_key == 'customer_id' || $use_master_key == 'vendor_id') && isset($user[$use_master_key])) { $primary = false; if ($use_master_key == 'customer_id') { $customer_data = module_customer::get_customer($user[$use_master_key]); if ($customer_data['primary_user_id'] == $user_id) { $primary = true; } } else { if ($use_master_key == 'vendor_id') { $vendor_data = module_vendor::get_vendor($user[$use_master_key]); if ($vendor_data['primary_user_id'] == $user_id) { $primary = true; } } } if ($primary && !isset($hide_more_button)) { $fieldset_data['heading']['button'] = array('title' => 'More', 'url' => module_user::link_open_contact($user_id, false)); } $fieldset_data['elements']['primary'] = array('title' => 'Primary', 'fields' => array(array('type' => 'check', 'name' => 'customer_primary', 'value' => '1', 'checked' => $primary), _hr('This users details will be used as a primary point of contact for this customer. These details will display in the main customer listing for this customer. Also if you send an invoice or a newsletter to this "customer" then this email address will be used.')));
<?php foreach ($todo_list as $todo_item) { if ($todo_item['hours_completed'] > 0) { if ($todo_item['hours'] > 0) { $percentage = round($todo_item['hours_completed'] / $todo_item['hours'], 2); $percentage = min(1, $percentage); } else { $percentage = 1; } } else { $percentage = 0; } $job_data = module_job::get_job($todo_item['job_id'], false); if ($job_data && $job_data['job_id'] == $todo_item['job_id']) { if ($job_data['customer_id']) { $customer_data = module_customer::get_customer($job_data['customer_id']); if (!$customer_data || $customer_data['customer_id'] != $job_data['customer_id']) { continue; } } else { $customer_data = array(); } ?> <li><!-- Task item --> <a href="<?php echo module_job::link_open($todo_item['job_id'], false, $job_data); ?> "> <h3> <?php
public static function email_invoice_to_customer($invoice_id, $debug = false) { // this is a copy of some of the code in invoie_admin_email.php // used in the CRON job when sending out automated emails. $invoice = module_invoice::get_invoice($invoice_id); // template for sending emails. // are we sending the paid one? or the dueone. $template_name = ''; $template_prefix = isset($invoice['invoice_template_email']) && strlen($invoice['invoice_template_email']) ? $invoice['invoice_template_email'] : 'invoice_email'; if (isset($invoice['credit_note_id']) && $invoice['credit_note_id']) { $template_name = 'credit_note_email'; } else { if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') { $template_name = $template_prefix . '_paid'; } else { if ($invoice['overdue'] && $invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') { $template_name = $template_prefix . '_overdue'; } else { $template_name = $template_prefix . '_due'; } } } $template_name = hook_filter_var('invoice_email_template', $template_name, $invoice_id, $invoice); if (class_exists('module_company', false) && isset($invoice_data['company_id']) && (int) $invoice_data['company_id'] > 0) { module_company::set_current_company_id($invoice_data['company_id']); } $template = module_template::get_template_by_key($template_name); if (!$template || $template->template_key != $template_name) { // backup default templates incase someone has chosen a template that doesn't exist (eg: created invoice_email_MINE_due but not invoice_email_MINE_paid ) $template_prefix = 'invoice_email'; if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') { $template_name = $template_prefix . '_paid'; } else { if ($invoice['overdue'] && $invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') { $template_name = $template_prefix . '_overdue'; } else { $template_name = $template_prefix . '_due'; } } } $replace = module_invoice::get_replace_fields($invoice_id, $invoice); if (defined('_BLOCK_EMAILS') && _BLOCK_EMAILS) { $pdf = false; } else { $pdf = module_invoice::generate_pdf($invoice_id); } $send_email_to = array(); $to = array(); if ($invoice['customer_id']) { $customer = module_customer::get_customer($invoice['customer_id']); $replace['customer_name'] = $customer['customer_name']; if ($invoice['user_id']) { // this invoice has a manually assigned user, only send the invoice to this user. // todo: should we also send to accounts? not sure - see if peopel complain $primary = module_user::get_user($invoice['user_id']); if ($primary) { $send_email_to[] = $primary; } } 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! $send_email_to[] = $contact; } } } if (!count($send_email_to) && $customer['primary_user_id']) { $primary = module_user::get_user($customer['primary_user_id']); if ($primary) { $send_email_to[] = $primary; } } } } else { if ($invoice['member_id']) { $member = module_member::get_member($invoice['member_id']); $to = array($member); $replace['customer_name'] = $member['first_name']; } else { $to = array(); } } $template->assign_values($replace); $html = $template->render('html'); // send an email to this user. $email = module_email::new_email(); $email->replace_values = $replace; // todo: send to all customer contacts ? if ($send_email_to) { foreach ($send_email_to as $send_email_t) { if (!empty($send_email_t['user_id'])) { $email->set_to('user', $send_email_t['user_id']); } else { if (!empty($send_email_t['email'])) { $email->set_to_manual($send_email_t['email']); } } } } else { foreach ($to as $t) { if (!empty($t['user_id'])) { $email->set_to('user', $t['user_id']); } else { if (!empty($t['email'])) { $email->set_to_manual($t['email']); } } break; // only 1? todo: all? } } $email->set_bcc_manual(module_config::c('admin_email_address', ''), ''); //$email->set_from('user',); // nfi $email->set_subject($template->description); // do we send images inline? $email->set_html($html); if ($pdf) { $email->add_attachment($pdf); } $email->invoice_id = $invoice_id; $email->customer_id = $invoice['customer_id']; $email->prevent_duplicates = true; if ($email->send($debug)) { // it worked successfully!! // record a log on the invoice when it's done. self::email_sent(array('invoice_id' => $invoice_id, 'template_name' => $template_name)); return true; } else { /// log err? return false; } }
$template = module_template::get_template_by_key($template_name); $file['from_name'] = module_security::get_loggedin_name(); $file['file_url'] = module_file::link_public($file_id); if (class_exists('module_job', false) && $file['job_id']) { $job_data = module_job::get_job($file['job_id'], false); $file['job_name'] = htmlspecialchars($job_data['name']); $file['job_link'] = module_job::link_public($file['job_id']); } else { $file['job_name'] = _l('N/A'); $file['job_link'] = ''; } // 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');
$invoice_id = 0; $invoice = module_invoice::get_invoice($invoice_id); if (class_exists('module_security', false)) { module_security::check_page(array('category' => 'Invoice', 'page_name' => 'Invoices', 'module' => 'invoice', 'feature' => 'create')); } module_security::sanatise_data('invoice', $invoice); } $invoice_items = module_invoice::get_invoice_items($invoice_id, $invoice); $invoice_locked = $invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00' || $invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00'; if (isset($_REQUEST['as_deposit']) && isset($_REQUEST['job_id'])) { $invoice['deposit_job_id'] = (int) $_REQUEST['job_id']; } $discounts_allowed = !(isset($invoice['deposit_job_id']) && $invoice['deposit_job_id'] > 0); $customer_data = array(); if ($invoice['customer_id']) { $customer_data = module_customer::get_customer($invoice['customer_id']); } $show_task_dates = module_config::c('invoice_task_list_show_date', 1); $colspan = 2; if ($show_task_dates) { $colspan++; } if (isset($invoice['credit_note_id']) && $invoice['credit_note_id']) { // this invoice is a credit note. // display a slightly different layout. include module_theme::include_ucm("includes/plugin_invoice/pages/invoice_admin_credit.php"); return; } // find out all the payment methods. $payment_methods = handle_hook('get_payment_methods', $module); $x = 1;
echo ' '; echo '<a href="' . module_job::link_open($file['job_id'], false) . '">' . _l('Open Job »') . '</a>'; } })); } if (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; } } else { $file['quote_id'] = false; } } $fieldset_data['elements'][] = array('title' => 'Quote', 'fields' => array(array('type' => 'select', 'name' => 'quote_id', 'value' => $file['quote_id'], 'options' => $c), function () use(&$file) { if ($file['quote_id']) { echo ' '; echo '<a href="' . module_quote::link_open($file['quote_id'], false) . '">' . _l('Open Quote »') . '</a>'; } }));
function handle_hook($hook, $calling_module = false, $owner_table = false, $key_name = false, $key_value = false, $rel_data = false) { switch ($hook) { case "home_alerts": $alerts = array(); if (module_config::c('allow_note_reminders', 1)) { // find any jobs that are past the due date and dont have a finished date. $key = _l('Note Reminder'); if (class_exists('module_dashboard', false)) { module_dashboard::register_group($key, array('columns' => array('name' => _l('Reminder'), 'type' => _l('Type'), 'full_link' => _l('Link'), 'date' => _l('Date'), 'days' => _l('Date')))); } $sql = "SELECT * FROM `" . _DB_PREFIX . "note` n "; $sql .= " WHERE n.`reminder` = 1 AND n.note_time < " . (int) strtotime('+' . module_config::c('alert_days_in_future', 5) . ' days') . ""; $sql .= " AND ( n.`user_id` = 0 OR n.`user_id` = " . module_security::get_loggedin_id() . ")"; $sql .= " ORDER BY n.note_time ASC"; $tasks = qa($sql); foreach ($tasks as $task) { $alert_res = process_alert(date('Y-m-d', $task['note_time']), $key); if ($alert_res) { $alert_res['link'] = $task['rel_data']; // fix for linking when changing folder. $alert_res['type'] = _l(ucwords($task['owner_table'])); switch ($task['owner_table']) { case 'user': $user = module_user::get_user($task['owner_id']); if ($user['customer_id'] || $user['vendor_id']) { $alert_res['link'] = module_user::link_open_contact($task['owner_id'], false, $user); $alert_res['full_link'] = module_user::link_open_contact($task['owner_id'], true, $user); $alert_res['type'] = _l('Contact'); } else { $alert_res['link'] = module_user::link_open($task['owner_id'], false, $user); $alert_res['full_link'] = module_user::link_open($task['owner_id'], true, $user); } break; case 'invoice': $invoice_data = module_invoice::get_invoice($task['owner_id'], true); if (!$invoice_data || !isset($invoice_data['invoice_id']) || $invoice_data['invoice_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_invoice::link_open($task['owner_id'], false, $invoice_data); $alert_res['full_link'] = module_invoice::link_open($task['owner_id'], true, $invoice_data); break; case 'quote': $quote_data = module_quote::get_quote($task['owner_id'], true); if (!$quote_data || !isset($quote_data['quote_id']) || $quote_data['quote_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_quote::link_open($task['owner_id'], false, $quote_data); $alert_res['full_link'] = module_quote::link_open($task['owner_id'], true, $quote_data); break; case 'website': $website_data = module_website::get_website($task['owner_id']); if (!$website_data || !isset($website_data['website_id']) || $website_data['website_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_website::link_open($task['owner_id'], false); $alert_res['full_link'] = module_website::link_open($task['owner_id'], true); break; case 'customer': $customer_data = module_customer::get_customer($task['owner_id']); if (!$customer_data || !isset($customer_data['customer_id']) || $customer_data['customer_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_customer::link_open($task['owner_id'], false, $customer_data); $alert_res['full_link'] = module_customer::link_open($task['owner_id'], true, $customer_data); break; case 'vendor': $vendor_data = module_vendor::get_vendor($task['owner_id']); if (!$vendor_data || !isset($vendor_data['vendor_id']) || $vendor_data['vendor_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_vendor::link_open($task['owner_id'], false, $vendor_data); $alert_res['full_link'] = module_vendor::link_open($task['owner_id'], true, $vendor_data); break; case 'job': $job_data = module_job::get_job($task['owner_id']); if (!$job_data || !isset($job_data['job_id']) || $job_data['job_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_job::link_open($task['owner_id'], false, $job_data); $alert_res['full_link'] = module_job::link_open($task['owner_id'], true, $job_data); break; // todo - add others. } $alert_res['name'] = $task['note']; $alert_res['date'] = print_date($alert_res['date']); $alert_res['time'] = $task['note_time']; $alerts[] = $alert_res; } } } return $alerts; break; /*case "note_list": if($owner_id && $owner_id != 'new'){ $note_items = $this->get_notes(array("owner_table"=>$owner_table,"owner_id"=>$owner_id)); foreach($note_items as &$note_item){ // do it in loop here because of $this issues in static method below. // instead of include file below. $note_item['html'] = $this->print_note($note_item['note_id']); } include("pages/note_list.php"); }else{ echo 'Please save first before creating notes.'; } break;*/ /*case "note_list": if($owner_id && $owner_id != 'new'){ $note_items = $this->get_notes(array("owner_table"=>$owner_table,"owner_id"=>$owner_id)); foreach($note_items as &$note_item){ // do it in loop here because of $this issues in static method below. // instead of include file below. $note_item['html'] = $this->print_note($note_item['note_id']); } include("pages/note_list.php"); }else{ echo 'Please save first before creating notes.'; } break;*/ case "note_delete": // find the key we are saving this address against. $owner_id = (int) $key_value; if (!$owner_id || $owner_id == 'new') { // find one in the post data. if (isset($_REQUEST[$key_name])) { $owner_id = $_REQUEST[$key_name]; } } $note_hash = md5($owner_id . '|' . $owner_table); // just for posting unique arrays. if ($owner_table && $owner_id) { $this->note_delete($owner_table, $owner_id); } break; } }
You can view and modify this change request by <a href="{CHANGE_REQUEST_URL}">clicking here</a>.<br><br> Thank you,<br><br> {FROM_NAME} ', 'Change Request: {URL}', array('NAME' => 'Customers Name', 'URL' => 'Website address', 'REQUEST' => 'Change REquest', 'FROM_NAME' => 'Your name', 'CHANGE_REQUEST_URL' => 'Link to change request for customer')); // template for sending emails. // are we sending the paid one? or the dueone. //$template_name = 'change_request_email'; $template_name = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : 'change_request_email'; $template = module_template::get_template_by_key($template_name); $change_request['from_name'] = module_security::get_loggedin_name(); $change_request['change_request_url'] = module_change_request::link_public_change($website_data['website_id'], $change_request_id); ob_start(); $change_request['change_request_tasks'] = ob_get_clean(); // find available "to" recipients. // customer contacts. $to_select = false; if ($website_data['customer_id']) { $customer = module_customer::get_customer($website_data['customer_id']); $change_request['customer_name'] = $customer['customer_name']; $to = module_user::get_contacts(array('customer_id' => $website_data['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(); } $template->assign_values($change_request); module_email::print_compose(array('find_other_templates' => 'change_request_email', 'current_template' => $template_name, 'customer_id' => $website_data['customer_id'], 'change_request_id' => $change_request['change_request_id'], 'debug_message' => 'Sending change request 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_website::link_open($website_data['website_id']), 'cancel_url' => module_website::link_open($website_data['website_id'])));