Esempio n. 1
0
 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;
     }
 }
<?php

/** 
 * Copyright: dtbaker 2012
 * Licence: Please check CodeCanyon.net for licence details. 
 * More licence clarification available here:  http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ 
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
if (!module_change_request::can_i('delete', 'Change Requests')) {
    die('no perms');
}
$change_request_id = (int) $_REQUEST['change_request_id'];
$change_request = module_change_request::get_change_request($change_request_id);
if (!$change_request['website_id']) {
    die('no linked website');
}
$website_data = module_website::get_website($change_request['website_id']);
if (module_form::confirm_delete('change_request_id', "Really delete Change Request?", module_website::link_open($change_request['website_id']))) {
    module_change_request::delete_change_request($_REQUEST['change_request_id']);
    set_message("Change request deleted successfully");
    redirect_browser(module_website::link_open($change_request['website_id']));
}
Esempio n. 3
0
<?php

/** 
 * Copyright: dtbaker 2012
 * Licence: Please check CodeCanyon.net for licence details. 
 * More licence clarification available here:  http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ 
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
$website_id = (int) $_REQUEST['website_id'];
$website = module_website::get_website($website_id);
if ($website_id > 0 && $website['website_id'] == $website_id) {
    $module->page_title = module_config::c('project_name_single', 'Website') . ': ' . $website['name'];
} else {
    $module->page_title = module_config::c('project_name_single', 'Website') . ': ' . _l('New');
}
if ($website_id > 0 && $website) {
    if (class_exists('module_security', false)) {
        module_security::check_page(array('module' => $module->module_name, 'feature' => 'edit'));
    }
} else {
    if (class_exists('module_security', false)) {
        module_security::check_page(array('module' => $module->module_name, 'feature' => 'create'));
    }
    module_security::sanatise_data('website', $website);
}
?>

Esempio n. 4
0
 public static function invoice_html($invoice_id, $invoice_data, $mode = 'html')
 {
     if ($invoice_id && $invoice_data) {
         // spit out the invoice html into a file, then pass it to the pdf converter
         // to convert it into a PDF.
         ob_start();
         include module_theme::include_ucm('includes/plugin_invoice/template/invoice_print.php');
         module_template::init_template('invoice_print', ob_get_clean(), 'Used for printing out an invoice for the customer.', 'html');
         ob_start();
         include module_theme::include_ucm('includes/plugin_invoice/template/invoice_print_basic.php');
         module_template::init_template('invoice_print_basic', ob_get_clean(), 'Alternative template for printing out an invoice for the customer.', 'html');
         ob_start();
         include module_theme::include_ucm('includes/plugin_invoice/template/credit_note_pdf.php');
         module_template::init_template('credit_note_pdf', ob_get_clean(), 'Used for printing out a a credit note for the customer.', 'html');
         $invoice = $invoice_data;
         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']);
         }
         $job_data = module_job::get_job(current($invoice_data['job_ids']));
         $website_data = $job_data['website_id'] ? module_website::get_website($job_data['website_id']) : array();
         $website_data = array_merge($website_data, isset($invoice_data['website_id']) && $invoice_data['website_id'] ? module_website::get_website($invoice_data['website_id']) : array());
         $invoice_template = isset($invoice_data['invoice_template_print']) && strlen($invoice_data['invoice_template_print']) ? $invoice_data['invoice_template_print'] : module_config::c('invoice_template_print_default', 'invoice_print');
         $invoice_template_suffix = '';
         if ($invoice_template != 'invoice_print') {
             $invoice_template_suffix = str_replace('invoice_print', '', $invoice_template);
         }
         ob_start();
         include module_theme::include_ucm('includes/plugin_invoice/template/invoice_task_list.php');
         $task_list_html = ob_get_clean();
         ob_start();
         include module_theme::include_ucm('includes/plugin_invoice/template/invoice_payment_history.php');
         $payment_history = ob_get_clean();
         ob_start();
         include module_theme::include_ucm('includes/plugin_invoice/template/invoice_payment_methods.php');
         $payment_methods = ob_get_clean();
         $replace = self::get_replace_fields($invoice_id, $invoice_data);
         $replace['payment_history'] = $payment_history;
         $replace['payment_methods'] = $payment_methods;
         $replace['task_list'] = $task_list_html;
         $replace['external_invoice_template_html'] = '';
         //$external_invoice_template = module_template::get_template_by_key('external_invoice');
         $external_invoice_template = false;
         if (isset($invoice_template_suffix) && strlen($invoice_template_suffix) > 0) {
             $external_invoice_template = module_template::get_template_by_key('external_invoice' . $invoice_template_suffix);
             if (!$external_invoice_template->template_id) {
                 $external_invoice_template = false;
             }
         }
         if (!$external_invoice_template) {
             $external_invoice_template = module_template::get_template_by_key('external_invoice');
         }
         $external_invoice_template->assign_values($replace);
         $replace['external_invoice_template_html'] = $external_invoice_template->replace_content();
         if (isset($invoice_data['credit_note_id']) && $invoice_data['credit_note_id']) {
             if ($invoice_data['invoice_template_print']) {
                 $invoice_data['invoice_template_print'] = 'credit_note_pdf';
             }
             $invoice_template = 'credit_note_pdf';
         }
         ob_start();
         $template = module_template::get_template_by_key($invoice_template);
         if (!$template || $template->template_key != $invoice_template) {
             echo "Invoice template {$invoice_template} not found";
         } else {
             $template->assign_values($replace);
             echo $template->render('html');
         }
         $invoice_html = ob_get_clean();
         return $invoice_html;
     }
     return false;
 }
Esempio n. 5
0
 public static function save_job($job_id, $data)
 {
     if (isset($data['default_renew_auto']) && !isset($data['renew_auto'])) {
         $data['renew_auto'] = 0;
     }
     if (isset($data['default_renew_invoice']) && !isset($data['renew_invoice'])) {
         $data['renew_invoice'] = 0;
     }
     if (isset($data['total_percent_complete_override']) && $data['total_percent_complete_override'] != '' && $data['total_percent_complete_override'] <= 100) {
         $data['total_percent_complete_manual'] = 1;
         $data['total_percent_complete'] = $data['total_percent_complete_override'] / 100;
     } else {
         $data['total_percent_complete_manual'] = 0;
     }
     if (isset($data['customer_id']) && $data['customer_id'] > 0) {
         // check we have access to this customer from this job.
         $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 Job 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) $job_id > 0) {
         $original_job_data = self::get_job($job_id, false);
         if (!$original_job_data || $original_job_data['job_id'] != $job_id) {
             $original_job_data = array();
             $job_id = false;
         }
     } else {
         $original_job_data = array();
         $job_id = false;
     }
     if (!(int) $job_id && module_config::c('job_name_incrementing', 0)) {
         // incrememnt next job number on save.
         $job_number = module_config::c('job_name_incrementing_next', 1);
         module_config::save_config('job_name_incrementing_next', $job_number + 1);
     }
     $job_id = update_insert("job_id", $job_id, "job", $data);
     if ($job_id) {
         // save the job tax rates (copied from invoice.php)
         if (isset($data['tax_ids']) && isset($data['tax_names']) && $data['tax_percents']) {
             $existing_taxes = get_multiple('job_tax', array('job_id' => $job_id), 'job_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 job_tax table, we confirm this id matches this job.
                         $job_tax_id = $val;
                         unset($existing_taxes[$job_tax_id]);
                         // so we know which ones to remove from the end.
                     } else {
                         $job_tax_id = false;
                         // create new record
                     }
                     $job_tax_data = array('job_id' => $job_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);
                     $job_tax_id = update_insert('job_tax_id', $job_tax_id, 'job_tax', $job_tax_data);
                 }
             }
             foreach ($existing_taxes as $existing_tax) {
                 delete_from_db('job_tax', array('job_id', 'job_tax_id'), array($job_id, $existing_tax['job_tax_id']));
             }
         }
         module_cache::clear('job');
         $result = self::save_job_tasks($job_id, $data);
         $check_completed = true;
         switch ($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_job_completion_status($job_id);
         }
         if ($original_job_data) {
             // we check if the hourly rate has changed
             if (isset($data['hourly_rate']) && $data['hourly_rate'] != $original_job_data['hourly_rate']) {
                 // update all the task hours, but only for hourly tasks:
                 $sql = "UPDATE `" . _DB_PREFIX . "task` SET `amount` = 0 WHERE `hours` > 0 AND job_id = " . (int) $job_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 job assigned user id has changed.
             if (module_config::c('job_allow_staff_assignment', 1)) {
                 if (isset($data['user_id'])) {
                     // && $data['user_id'] != $original_job_data['user_id']){
                     // user id has changed! update any that were the old user id.
                     $sql = "UPDATE `" . _DB_PREFIX . "task` SET `user_id` = " . (int) $data['user_id'] . " WHERE (`user_id` = " . (int) $original_job_data['user_id'] . " OR user_id = 0) AND job_id = " . (int) $job_id;
                     query($sql);
                 }
             }
             // check if the due date has changed.
             if (isset($original_job_data['date_due']) && $original_job_data['date_due'] && isset($data['date_due']) && $data['date_due'] && $data['date_due'] != '0000-00-00' && $original_job_data['date_due'] != $data['date_due']) {
                 // the date has changed.
                 // update all the tasks with this new date.
                 $tasks = self::get_tasks($job_id);
                 foreach ($tasks as $task) {
                     if (!$task['date_due'] || $task['date_due'] == '0000-00-00') {
                         // no previously set task date. set it
                         update_insert('task_id', $task['task_id'], 'task', array('date_due' => $data['date_due']));
                     } else {
                         if ($task['date_due'] == $original_job_data['date_due']) {
                             // the date was the old date. do we change it?
                             // only change it on incompleted tasks.
                             $percentage = self::get_percentage($task);
                             if ($percentage < 1 || module_config::c('job_tasks_overwrite_completed_due_dates', 0) && $percentage == 1) {
                                 update_insert('task_id', $task['task_id'], 'task', array('date_due' => $data['date_due']));
                             }
                         } else {
                             // there's a new date
                             if (module_config::c('job_tasks_overwrite_diff_due_date', 0)) {
                                 update_insert('task_id', $task['task_id'], 'task', array('date_due' => $data['date_due']));
                             }
                         }
                     }
                 }
             }
         }
     }
     if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) {
         module_extra::save_extras('job', 'job_id', $job_id);
     }
     module_cache::clear('job');
     return $job_id;
 }
Esempio n. 6
0
 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";
                     }
                 }
             }
         }
     }
 }
Esempio n. 7
0
    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;
        }
    }
Esempio n. 8
0
 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;
 }
Esempio n. 9
0
            // find the groups for this website.
            $groups = module_group::get_groups_search(array('owner_table' => 'website', 'owner_id' => $website['website_id']));
            $g = array();
            foreach ($groups as $group) {
                $g[] = $group['name'];
            }
            echo htmlspecialchars(implode(', ', $g));
        }
    });
}
if (class_exists('module_extra', false)) {
    $table_manager->display_extra('website', function ($website) {
        module_extra::print_table_data('website', $website['website_id']);
    });
}
if (class_exists('module_subscription', false)) {
    $table_manager->display_subscription('website', function ($website) {
        module_subscription::print_table_data('website', $website['website_id']);
    });
}
$table_manager->set_columns($columns);
$table_manager->row_callback = function ($row_data) {
    // load the full vendor data before displaying each row so we have access to more details
    return module_website::get_website($row_data['website_id']);
};
$table_manager->set_rows($websites);
$table_manager->pagination = true;
$table_manager->print_table();
?>

</form>
Esempio n. 10
0
 public function external_hook($hook)
 {
     switch ($hook) {
         case 'public_signup_form':
             $signup_form = module_template::get_template_by_key('customer_signup_form_wrapper');
             $signup_form->page_title = $signup_form->description;
             $signup_form->assign_values(array('signup_form' => self::get_customer_signup_form_html()));
             echo $signup_form->render('pretty_html');
             exit;
         case 'public_signup':
             // sign out if testing.
             if (module_security::is_logged_in()) {
                 set_message('Logged out due to signup');
                 module_security::logout();
             }
             $result = array('messages' => array());
             function customer_signup_complete($result)
             {
                 if (isset($_REQUEST['via_ajax'])) {
                     echo json_encode($result);
                 } else {
                     echo implode('<br/>', $result['messages']);
                 }
                 exit;
             }
             if (!module_config::c('customer_signup_allowed', 0)) {
                 $result['error'] = 1;
                 $result['messages'][] = 'Customer signup disabled';
                 customer_signup_complete($result);
             }
             //recaptcha on signup form.
             if (module_config::c('captcha_on_signup_form', 0)) {
                 if (!module_captcha::check_captcha_form()) {
                     $result['error'] = 1;
                     $result['messages'][] = 'Captcha fail, please go back and enter correct captcha code.';
                     customer_signup_complete($result);
                 }
             }
             $customer = isset($_POST['customer']) && is_array($_POST['customer']) ? $_POST['customer'] : array();
             $contact = isset($_POST['contact']) && is_array($_POST['contact']) ? $_POST['contact'] : array();
             $contact_extra = isset($contact['extra']) && is_array($contact['extra']) ? $contact['extra'] : array();
             $contact_group = isset($contact['group_ids']) && is_array($contact['group_ids']) ? $contact['group_ids'] : array();
             $customer_extra = isset($customer['extra']) ? $customer['extra'] : array();
             $customer_group = isset($customer['group_ids']) && is_array($customer['group_ids']) ? $customer['group_ids'] : array();
             $address = isset($_POST['address']) ? $_POST['address'] : array();
             $website = isset($_POST['website']) ? $_POST['website'] : array();
             $website_extra = isset($website['extra']) ? $website['extra'] : array();
             $website_group = isset($website['group_ids']) && is_array($website['group_ids']) ? $website['group_ids'] : array();
             $job = isset($_POST['job']) ? $_POST['job'] : array();
             $job_extra = isset($job['extra']) ? $job['extra'] : array();
             $subscription = isset($_POST['subscription']) ? $_POST['subscription'] : array();
             // sanatise possibly problematic fields:
             // customer:
             $allowed = array('name', 'last_name', 'customer_name', 'email', 'phone', 'mobile', 'extra', 'type');
             foreach ($customer as $key => $val) {
                 if (!in_array($key, $allowed)) {
                     unset($customer[$key]);
                 }
             }
             if (isset($customer['type']) && $customer['type'] != _CUSTOMER_TYPE_NORMAL && $customer['type'] != _CUSTOMER_TYPE_LEAD) {
                 unset($customer['type']);
             }
             // added multiple contact support in the form of arrays.
             $contact_fields = array('name', 'last_name', 'email', 'phone');
             if (module_config::c('customer_signup_password', 0)) {
                 $contact_fields[] = 'password';
             }
             foreach ($contact_fields as $multi_value) {
                 if (isset($contact[$multi_value])) {
                     if (!is_array($contact[$multi_value])) {
                         $contact[$multi_value] = array($contact[$multi_value]);
                     }
                 } else {
                     if (isset($customer[$multi_value])) {
                         $contact[$multi_value] = array($customer[$multi_value]);
                     } else {
                         $contact[$multi_value] = array();
                     }
                 }
             }
             $valid_contact_email = false;
             $name_fallback = false;
             $primary_email = false;
             foreach ($contact['email'] as $contact_key => $email) {
                 if (!$name_fallback && isset($contact['name'][$contact_key])) {
                     $name_fallback = $contact['name'][$contact_key];
                 }
                 $contact['email'][$contact_key] = filter_var(strtolower(trim($email)), FILTER_VALIDATE_EMAIL);
                 if ($contact['email'][$contact_key]) {
                     $valid_contact_email = true;
                     if (!$primary_email) {
                         $primary_email = $contact['email'][$contact_key];
                         // set the primary contact details here by adding them to the master customer array
                         foreach ($contact_fields as $primary_contact_field) {
                             $customer[$primary_contact_field] = isset($contact[$primary_contact_field][$contact_key]) ? $contact[$primary_contact_field][$contact_key] : '';
                             unset($contact[$primary_contact_field][$contact_key]);
                         }
                     }
                 }
             }
             // start error checking / required fields
             if (!isset($customer['customer_name']) || !strlen($customer['customer_name'])) {
                 $customer['customer_name'] = $name_fallback;
             }
             if (!strlen($customer['customer_name'])) {
                 $result['error'] = 1;
                 $result['messages'][] = "Failed, please go back and provide a customer name.";
             }
             if (!$valid_contact_email || !$primary_email) {
                 $result['error'] = 1;
                 $result['messages'][] = "Failed, please go back and provide an email address.";
             }
             // check all posted required fields.
             function check_required($postdata, $messages = array())
             {
                 if (is_array($postdata)) {
                     foreach ($postdata as $key => $val) {
                         if (strpos($key, '_required') && strlen($val)) {
                             $required_key = str_replace('_required', '', $key);
                             if (!isset($postdata[$required_key]) || !$postdata[$required_key]) {
                                 $messages[] = 'Required field missing: ' . htmlspecialchars($val);
                             }
                         }
                         if (is_array($val)) {
                             $messages = check_required($val, $messages);
                         }
                     }
                 }
                 return $messages;
             }
             $messages = check_required($_POST);
             if (count($messages)) {
                 $result['error'] = 1;
                 $result['messages'] = array_merge($result['messages'], $messages);
             }
             if (isset($result['error'])) {
                 customer_signup_complete($result);
             }
             // end error checking / required fields.
             // check if this customer already exists in the system, based on email address
             $customer_id = false;
             $creating_new = true;
             $_REQUEST['user_id'] = 0;
             if (isset($customer['email']) && strlen($customer['email']) && !module_config::c('customer_signup_always_new', 0)) {
                 $users = module_user::get_contacts(array('email' => $customer['email']));
                 foreach ($users as $user) {
                     if (isset($user['customer_id']) && (int) $user['customer_id'] > 0) {
                         // this user exists as a customer! yey!
                         // add them to this listing.
                         $customer_id = $user['customer_id'];
                         $creating_new = false;
                         $_REQUEST['user_id'] = $user['user_id'];
                         // dont let signups update existing passwords.
                         if (isset($customer['password'])) {
                             unset($customer['password']);
                         }
                         if (isset($customer['new_password'])) {
                             unset($customer['new_password']);
                         }
                     }
                 }
             }
             $_REQUEST['extra_customer_field'] = array();
             $_REQUEST['extra_user_field'] = array();
             module_extra::$config['allow_new_keys'] = false;
             module_extra::$config['delete_existing_empties'] = false;
             // save customer extra fields.
             if (count($customer_extra)) {
                 // format the address so "save_customer" handles the save for us
                 foreach ($customer_extra as $key => $val) {
                     $_REQUEST['extra_customer_field'][] = array('key' => $key, 'val' => $val);
                 }
             }
             // save customer and customer contact details:
             $customer_id = $this->save_customer($customer_id, $customer);
             if (!$customer_id) {
                 $result['error'] = 1;
                 $result['messages'][] = 'System error: failed to create customer.';
                 customer_signup_complete($result);
             }
             $customer_data = module_customer::get_customer($customer_id);
             // todo - merge primary and secondary contact/extra/group saving into a single loop
             if (!$customer_data['primary_user_id']) {
                 $result['error'] = 1;
                 $result['messages'][] = 'System error: Failed to create customer contact.';
                 customer_signup_complete($result);
             } else {
                 $role_id = module_config::c('customer_signup_role', 0);
                 if ($role_id > 0) {
                     module_user::add_user_to_role($customer_data['primary_user_id'], $role_id);
                 }
                 // save contact extra data (repeated below for additional contacts)
                 if (isset($contact_extra[0]) && count($contact_extra[0])) {
                     $_REQUEST['extra_user_field'] = array();
                     foreach ($contact_extra[0] as $key => $val) {
                         $_REQUEST['extra_user_field'][] = array('key' => $key, 'val' => $val);
                     }
                     module_extra::save_extras('user', 'user_id', $customer_data['primary_user_id']);
                 }
                 // save contact groups
                 if (isset($contact_group[0]) && count($contact_group[0])) {
                     foreach ($contact_group[0] as $group_id => $tf) {
                         if ($tf) {
                             module_group::add_to_group($group_id, $customer_data['primary_user_id'], 'user');
                         }
                     }
                 }
             }
             foreach ($contact['email'] as $contact_key => $email) {
                 // add any additional contacts to the customer.
                 $users = module_user::get_contacts(array('email' => $email, 'customer_id' => $customer_id));
                 if (count($users)) {
                     // this contact already exists for this customer, dont update/change it.
                     continue;
                 }
                 $new_contact = array('customer_id' => $customer_id);
                 foreach ($contact_fields as $primary_contact_field) {
                     $new_contact[$primary_contact_field] = isset($contact[$primary_contact_field][$contact_key]) ? $contact[$primary_contact_field][$contact_key] : '';
                 }
                 // dont let additional contacts have passwords.
                 if (isset($new_contact['password'])) {
                     unset($new_contact['password']);
                 }
                 if (isset($new_contact['new_password'])) {
                     unset($new_contact['new_password']);
                 }
                 global $plugins;
                 $contact_user_id = $plugins['user']->create_user($new_contact, 'signup');
                 if ($contact_user_id) {
                     $role_id = module_config::c('customer_signup_role', 0);
                     if ($role_id > 0) {
                         module_user::add_user_to_role($contact_user_id, $role_id);
                     }
                     // save contact extra data  (repeated below for primary contacts)
                     if (isset($contact_extra[$contact_key]) && count($contact_extra[$contact_key])) {
                         $_REQUEST['extra_user_field'] = array();
                         foreach ($contact_extra[$contact_key] as $key => $val) {
                             $_REQUEST['extra_user_field'][] = array('key' => $key, 'val' => $val);
                         }
                         module_extra::save_extras('user', 'user_id', $contact_user_id);
                     }
                     // save contact groups
                     if (isset($contact_group[$contact_key]) && count($contact_group[$contact_key])) {
                         foreach ($contact_group[$contact_key] as $group_id => $tf) {
                             if ($tf) {
                                 module_group::add_to_group($group_id, $contact_user_id, 'user');
                             }
                         }
                     }
                 }
             }
             if (count($customer_group)) {
                 // format the address so "save_customer" handles the save for us
                 foreach ($customer_group as $group_id => $tf) {
                     if ($tf) {
                         module_group::add_to_group($group_id, $customer_id, 'customer');
                     }
                 }
             }
             $note_keys = array('customer', 'website', 'job', 'address', 'subscription');
             $note_text = _l('Customer signed up from Signup Form:');
             $note_text .= "\n\n";
             foreach ($note_keys as $note_key) {
                 $note_text .= "\n" . ucwords(_l($note_key)) . "\n";
                 if (isset($_POST[$note_key]) && is_array($_POST[$note_key])) {
                     foreach ($_POST[$note_key] as $post_key => $post_val) {
                         $note_text .= "\n - " . _l($post_key) . ": ";
                         if (is_array($post_val)) {
                             foreach ($post_val as $p => $v) {
                                 $note_text .= "\n  - - " . _l($p) . ': ' . $v;
                             }
                         } else {
                             $note_text .= $post_val;
                         }
                     }
                 }
             }
             $note_data = array('note_id' => false, 'owner_id' => $customer_id, 'owner_table' => 'customer', 'note_time' => time(), 'note' => $note_text, 'rel_data' => module_customer::link_open($customer_id), 'reminder' => 0, 'user_id' => 0);
             update_insert('note_id', false, 'note', $note_data);
             // save customer address fields.
             if (count($address)) {
                 $address_db = module_address::get_address($customer_id, 'customer', 'physical');
                 $address_id = $address_db && isset($address_db['address_id']) ? (int) $address_db['address_id'] : false;
                 $address['owner_id'] = $customer_id;
                 $address['owner_table'] = 'customer';
                 $address['address_type'] = 'physical';
                 // we have post data to save, write it to the table!!
                 module_address::save_address($address_id, $address);
             }
             // website:
             $allowed = array('url', 'name', 'extra', 'notes');
             foreach ($website as $key => $val) {
                 if (!in_array($key, $allowed)) {
                     unset($website[$key]);
                 }
             }
             $website['url'] = isset($website['url']) ? strtolower(trim($website['url'])) : '';
             $website_id = 0;
             if (count($website) && class_exists('module_website', false) && module_website::is_plugin_enabled()) {
                 if (strlen($website['url'])) {
                     // see if website already exists, don't create or update existing one for now.
                     $existing_websites = module_website::get_websites(array('customer_id' => $customer_id, 'url' => $website['url']));
                     foreach ($existing_websites as $existing_website) {
                         $website_id = $existing_website['website_id'];
                     }
                 }
                 //   echo $website_id;echo $website['url']; print_r($website_extra);exit;
                 if (!$website_id) {
                     $website_data = module_website::get_website($website_id);
                     $website_data['url'] = isset($website['url']) ? $website['url'] : 'N/A';
                     $website_data['name'] = isset($website['url']) ? $website['url'] : 'N/A';
                     $website_data['customer_id'] = $customer_id;
                     $website_id = update_insert('website_id', false, 'website', $website_data);
                     // save website extra data.
                     if ($website_id && count($website_extra)) {
                         $_REQUEST['extra_website_field'] = array();
                         foreach ($website_extra as $key => $val) {
                             $_REQUEST['extra_website_field'][] = array('key' => $key, 'val' => $val);
                         }
                         module_extra::save_extras('website', 'website_id', $website_id);
                     }
                     if ($website_id && isset($website['notes']) && strlen($website['notes'])) {
                         // add notes to this website.
                         $note_data = array('note_id' => false, 'owner_id' => $website_id, 'owner_table' => 'website', 'note_time' => time(), 'note' => $website['notes'], 'rel_data' => module_website::link_open($website_id), 'reminder' => 0, 'user_id' => $customer_data['primary_user_id']);
                         $note_id = update_insert('note_id', false, 'note', $note_data);
                     }
                 }
                 if ($website_id) {
                     if (count($website_group)) {
                         // format the address so "save_customer" handles the save for us
                         foreach ($website_group as $group_id => $tf) {
                             if ($tf) {
                                 module_group::add_to_group($group_id, $website_id, 'website');
                             }
                         }
                     }
                 }
             }
             // generate jobs for this customer.
             $job_created = array();
             if ($job && isset($job['type']) && is_array($job['type'])) {
                 if (module_config::c('customer_signup_any_job_type', 0)) {
                     foreach ($job['type'] as $type_name) {
                         // we have a match in our system. create the job.
                         $job_data = module_job::get_job(false);
                         $job_data['type'] = $type_name;
                         if (!$job_data['name']) {
                             $job_data['name'] = $type_name;
                         }
                         $job_data['website_id'] = $website_id;
                         $job_data['customer_id'] = $customer_id;
                         $job_id = update_insert('job_id', false, 'job', $job_data);
                         // todo: add default tasks for this job type.
                         $job_created[] = $job_id;
                     }
                 } else {
                     foreach (module_job::get_types() as $type_id => $type) {
                         foreach ($job['type'] as $type_name) {
                             if ($type_name == $type) {
                                 // we have a match in our system. create the job.
                                 $job_data = module_job::get_job(false);
                                 $job_data['type'] = $type;
                                 if (!$job_data['name']) {
                                     $job_data['name'] = $type;
                                 }
                                 $job_data['website_id'] = $website_id;
                                 $job_data['customer_id'] = $customer_id;
                                 $job_id = update_insert('job_id', false, 'job', $job_data);
                                 // todo: add default tasks for this job type.
                                 $job_created[] = $job_id;
                             }
                         }
                     }
                 }
                 if (count($job_created) && count($job_extra)) {
                     // save job extra data.
                     foreach ($job_created as $job_created_id) {
                         if ($job_created_id && count($job_extra)) {
                             $_REQUEST['extra_job_field'] = array();
                             foreach ($job_extra as $key => $val) {
                                 $_REQUEST['extra_job_field'][] = array('key' => $key, 'val' => $val);
                             }
                             module_extra::save_extras('job', 'job_id', $job_created_id);
                         }
                     }
                 }
             }
             // save files against customer
             $uploaded_files = array();
             if (isset($_FILES['customerfiles']) && isset($_FILES['customerfiles']['tmp_name'])) {
                 foreach ($_FILES['customerfiles']['tmp_name'] as $file_id => $tmp_file) {
                     if (is_uploaded_file($tmp_file)) {
                         // save to file module for this customer
                         $file_name = basename($_FILES['customerfiles']['name'][$file_id]);
                         if (strlen($file_name)) {
                             $file_path = 'includes/plugin_file/upload/' . md5(time() . $file_name);
                             if (move_uploaded_file($tmp_file, $file_path)) {
                                 // success! write to db.
                                 $file_data = array('customer_id' => $customer_id, 'job_id' => current($job_created), 'website_id' => $website_id, 'status' => module_config::c('file_default_status', 'Uploaded'), 'pointers' => false, 'description' => "Uploaded from Customer Signup form", 'file_time' => time(), 'file_name' => $file_name, 'file_path' => $file_path, 'file_url' => false);
                                 $file_id = update_insert('file_id', false, 'file', $file_data);
                                 $uploaded_files[] = $file_id;
                             }
                         }
                     }
                 }
             }
             // we create subscriptions for this customer/website (if none already exist)
             $subscription['subscription_name'] = array();
             $subscription['subscription_invoice'] = array();
             if (class_exists('module_subscription', false) && module_subscription::is_plugin_enabled() && isset($subscription['for']) && isset($subscription['subscriptions'])) {
                 if ($subscription['for'] == 'website' && $website_id > 0) {
                     $owner_table = 'website';
                     $owner_id = $website_id;
                 } else {
                     $owner_table = 'customer';
                     $owner_id = $customer_id;
                 }
                 $available_subscriptions = module_subscription::get_subscriptions();
                 $members_subscriptions = module_subscription::get_subscriptions_by($owner_table, $owner_id);
                 foreach ($subscription['subscriptions'] as $subscription_id => $tf) {
                     if (isset($available_subscriptions[$subscription_id])) {
                         if (isset($members_subscriptions[$subscription_id])) {
                             // we don't allow a member to sign up to the same subscription twice (just yet)
                         } else {
                             $subscription['subscription_name'][$subscription_id] = $available_subscriptions[$subscription_id]['name'];
                             $start_date = date('Y-m-d');
                             $start_modifications = module_config::c('customer_signup_subscription_start', '');
                             if ($start_modifications == 'hidden') {
                                 $start_modifications = isset($_REQUEST['customer_signup_subscription_start']) ? $_REQUEST['customer_signup_subscription_start'] : '';
                             }
                             if (!empty($start_modifications)) {
                                 $start_date = date('Y-m-d', strtotime($start_modifications));
                             }
                             $sql = "INSERT INTO `" . _DB_PREFIX . "subscription_owner` SET ";
                             $sql .= " owner_id = '" . (int) $owner_id . "'";
                             $sql .= ", owner_table = '" . mysql_real_escape_string($owner_table) . "'";
                             $sql .= ", subscription_id = '" . (int) $subscription_id . "'";
                             $sql .= ", start_date = '{$start_date}'";
                             query($sql);
                             module_subscription::update_next_due_date($subscription_id, $owner_table, $owner_id, true);
                             // and the same option here to send a subscription straight away upon signup
                             if (module_config::c('subscription_send_invoice_straight_away', 0)) {
                                 global $plugins;
                                 $plugins['subscription']->run_cron();
                                 // check if there are any invoices for this subscription
                                 $history = module_subscription::get_subscription_history($subscription_id, $owner_table, $owner_id);
                                 if (count($history) > 0) {
                                     foreach ($history as $h) {
                                         if ($h['invoice_id']) {
                                             $invoice_data = module_invoice::get_invoice($h['invoice_id']);
                                             if ($invoice_data['date_cancel'] != '0000-00-00') {
                                                 continue;
                                             }
                                             $subscription['subscription_invoice'][] = '<a href="' . module_invoice::link_public($h['invoice_id']) . '">' . _l('Invoice #%s for %s', htmlspecialchars($invoice_data['name']), dollar($invoice_data['total_amount'], true, $invoice_data['currency_id'])) . '</a>';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (!count($subscription['subscription_name'])) {
                 $subscription['subscription_name'][] = _l('N/A');
             }
             if (!count($subscription['subscription_invoice'])) {
                 $subscription['subscription_invoice'][] = _l('N/A');
             }
             $subscription['subscription_name'] = implode(', ', $subscription['subscription_name']);
             $subscription['subscription_invoice'] = implode(', ', $subscription['subscription_invoice']);
             // email the admin when a customer signs up.
             $values = array_merge($customer, $customer_extra, $website, $website_extra, $address, $subscription);
             $values['customer_name'] = $customer['customer_name'];
             $values['CUSTOMER_LINK'] = module_customer::link_open($customer_id);
             $values['CUSTOMER_NAME_LINK'] = module_customer::link_open($customer_id, true);
             if ($website_id) {
                 $values['WEBSITE_LINK'] = module_website::link_open($website_id);
                 $values['WEBSITE_NAME_LINK'] = module_website::link_open($website_id, true);
             } else {
                 $values['WEBSITE_LINK'] = _l('N/A');
                 $values['WEBSITE_NAME_LINK'] = _l('N/A');
             }
             $values['JOB_LINKS'] = '';
             if (count($job_created)) {
                 $values['JOB_LINKS'] .= 'The customer created ' . count($job_created) . ' jobs in the system: <br>';
                 foreach ($job_created as $job_created_id) {
                     $values['JOB_LINKS'] .= module_job::link_open($job_created_id, true) . "<br>\n";
                 }
             } else {
                 $values['JOB_LINKS'] = _l('N/A');
             }
             if (count($uploaded_files)) {
                 $values['uploaded_files'] = 'The customer uploaded ' . count($uploaded_files) . " files:<br>\n";
                 foreach ($uploaded_files as $uploaded_file) {
                     $values['uploaded_files'] .= module_file::link_open($uploaded_file, true) . "<br>\n";
                 }
             } else {
                 $values['uploaded_files'] = 'No files were uploaded';
             }
             $values['WEBSITE_NAME'] = isset($website['url']) ? $website['url'] : 'N/A';
             if (!$creating_new) {
                 $values['system_note'] = "Note: this signup updated the existing customer record in the system.";
             } else {
                 $values['system_note'] = "Note: this signup created a new customer record in the system.";
             }
             $customer_signup_template = module_config::c('customer_signup_email_admin_template', 'customer_signup_email_admin');
             if (isset($_REQUEST['customer_signup_email_admin_template'])) {
                 $customer_signup_template = $_REQUEST['customer_signup_email_admin_template'];
             }
             if ($customer_signup_template) {
                 $template = module_template::get_template_by_key($customer_signup_template);
                 if ($template->template_id) {
                     $template->assign_values($values);
                     $html = $template->render('html');
                     $email = module_email::new_email();
                     $email->replace_values = $values;
                     $email->set_subject($template->description);
                     $email->set_to_manual(module_config::c('customer_signup_admin_email', module_config::c('admin_email_address')));
                     // do we send images inline?
                     $email->set_html($html);
                     if ($email->send()) {
                         // it worked successfully!!
                     } else {
                         /// log err?
                     }
                 }
             }
             $customer_signup_template = module_config::c('customer_signup_email_welcome_template', 'customer_signup_email_welcome');
             if (isset($_REQUEST['customer_signup_email_welcome_template'])) {
                 $customer_signup_template = $_REQUEST['customer_signup_email_welcome_template'];
             }
             if ($customer_signup_template) {
                 $template = module_template::get_template_by_key($customer_signup_template);
                 if ($template->template_id) {
                     $template->assign_values($values);
                     $html = $template->render('html');
                     $email = module_email::new_email();
                     $email->customer_id = $customer_id;
                     $email->replace_values = $values;
                     $email->set_subject($template->description);
                     $email->set_to('user', $customer_data['primary_user_id']);
                     // do we send images inline?
                     $email->set_html($html);
                     if ($email->send()) {
                         // it worked successfully!!
                     } else {
                         /// log err?
                     }
                 }
             }
             //todo: optional redirect to url
             if (isset($_REQUEST['via_ajax'])) {
                 echo json_encode(array('success' => 1, 'customer_id' => $customer_id));
                 exit;
             }
             if (module_config::c('customer_signup_redirect', '')) {
                 redirect_browser(module_config::c('customer_signup_redirect', ''));
             }
             // load up the thank you template.
             $template = module_template::get_template_by_key('customer_signup_thank_you_page');
             $template->page_title = _l("Customer Signup");
             foreach ($values as $key => $val) {
                 if (!is_array($val)) {
                     $values[$key] = htmlspecialchars($val);
                 }
             }
             $template->assign_values($values);
             echo $template->render('pretty_html');
             exit;
             break;
     }
 }
Esempio n. 11
0
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();
}
$options = array('cancel_url' => module_email::link_open(false), 'complete_url' => module_email::link_open(false), 'customer_id' => $customer_id);
$options = module_email::get_email_compose_options($options);
?>

<?php 
if ($can_edit_emails) {
    ?>
<form action="" method="post" id="template_change_form">
    <input type="hidden" name="template_name" value="" id="template_name_change">
Esempio n. 12
0
 public static function get_replace_fields($website_id, $website_data = false)
 {
     if (!$website_data) {
         $website_data = self::get_website($website_id);
     }
     $data = array('website_name' => $website_data['name'], 'website_url' => self::urlify($website_data['url']));
     $data = array_merge($data, $website_data);
     if (class_exists('module_group', false)) {
         // get the website groups
         $g = array();
         if ($website_id > 0) {
             $website_data = module_website::get_website($website_id);
             foreach (module_group::get_groups_search(array('owner_table' => 'website', 'owner_id' => $website_id)) as $group) {
                 $g[$group['group_id']] = $group['name'];
             }
         }
         $data['website_group'] = implode(', ', $g);
     }
     // addition. find all extra keys for this website and add them in.
     // we also have to find any EMPTY extra fields, and add those in as well.
     $all_extra_fields = module_extra::get_defaults('website');
     foreach ($all_extra_fields as $e) {
         $data[$e['key']] = _l('N/A');
     }
     // and find the ones with values:
     $extras = module_extra::get_extras(array('owner_table' => 'website', 'owner_id' => $website_id));
     foreach ($extras as $e) {
         $data[$e['extra_key']] = $e['extra'];
     }
     return $data;
 }
Esempio n. 13
0
 public function save_ticket($ticket_id, $data)
 {
     if (isset($data['website_id']) && $data['website_id']) {
         $website = module_website::get_website($data['website_id']);
         $data['customer_id'] = $website['customer_id'];
     }
     if (isset($data['user_id']) && $data['user_id']) {
         $user = module_user::get_user($data['user_id'], false);
         if (!isset($data['customer_id']) || !$data['customer_id']) {
             $data['customer_id'] = $user['customer_id'];
         }
     }
     if ((int) $ticket_id > 0) {
         $existing_ticket_data = $this->get_ticket($ticket_id);
     } else {
         $existing_ticket_data = array();
     }
     if (isset($data['change_assigned_user_id']) && (int) $data['change_assigned_user_id'] > 0) {
         // check if we're realling changing the user.
         if ($ticket_id > 0) {
             if ($existing_ticket_data['assigned_user_id'] != $data['change_assigned_user_id']) {
                 // they are really changing the user
                 $data['assigned_user_id'] = $data['change_assigned_user_id'];
             }
         } else {
             $data['assigned_user_id'] = $data['change_assigned_user_id'];
         }
         module_cache::clear('ticket');
     }
     $ticket_id = update_insert("ticket_id", $ticket_id, "ticket", $data);
     if ($ticket_id) {
         // save any extra data
         if (isset($data['ticket_extra']) && is_array($data['ticket_extra'])) {
             $available_extra_fields = $this->get_ticket_extras_keys();
             foreach ($data['ticket_extra'] as $ticket_data_key_id => $ticket_data_key_value) {
                 if (strlen($ticket_data_key_value) > 0 && isset($available_extra_fields[$ticket_data_key_id])) {
                     // save this one!
                     // hack: addition for encryption module.
                     // bit nasty, but it works.
                     if (class_exists('module_encrypt', false) && isset($available_extra_fields[$ticket_data_key_id]['encrypt_key_id']) && $available_extra_fields[$ticket_data_key_id]['encrypt_key_id'] && strpos($ticket_data_key_value, 'encrypt:') === false && ($available_extra_fields[$ticket_data_key_id]['type'] == 'text' || $available_extra_fields[$ticket_data_key_id]['type'] == 'textarea')) {
                         // encrypt this value using this key.
                         $page_name = 'ticket_extras';
                         // match the page_name we have in ticket_extra_sidebar.php
                         $input_id = 'ticket_extras_' . $ticket_data_key_id;
                         // match the input id we have in ticket_extra_sidebar.php
                         $ticket_data_key_value = module_encrypt::save_encrypt_value($available_extra_fields[$ticket_data_key_id]['encrypt_key_id'], $ticket_data_key_value, $page_name, $input_id);
                     }
                     // check for existing
                     $existing = get_single('ticket_data', array('ticket_id', 'ticket_data_key_id'), array($ticket_id, $ticket_data_key_id));
                     if ($existing) {
                         update_insert('ticket_data_id', $existing['ticket_data_id'], 'ticket_data', array('value' => $ticket_data_key_value));
                     } else {
                         update_insert('ticket_data_id', 'new', 'ticket_data', array('ticket_data_key_id' => $ticket_data_key_id, 'ticket_id' => $ticket_id, 'value' => $ticket_data_key_value));
                     }
                 }
             }
         }
         $ticket_message_id = false;
         if (isset($data['new_ticket_message']) && strlen($data['new_ticket_message']) > 1) {
             // post a new reply to this message.
             // who are we replying to?
             $ticket_data = $this->get_ticket($ticket_id);
             if (isset($data['change_status_id']) && $data['change_status_id']) {
                 update_insert("ticket_id", $ticket_id, "ticket", array('status_id' => $data['change_status_id']));
             } else {
                 if ($ticket_data['status_id'] == _TICKET_STATUS_RESOLVED_ID || $ticket_data['status_id'] == 7) {
                     $data['change_status_id'] = _TICKET_STATUS_IN_PROGRESS_ID;
                     // change to in progress.
                 }
             }
             module_cache::clear('ticket');
             // it's either a reply from the admin, or from the user via the web interface.
             $ticket_data = $this->get_ticket($ticket_id);
             $logged_in_user = isset($data['force_logged_in_user_id']) ? $data['force_logged_in_user_id'] : false;
             if (!$logged_in_user) {
                 $logged_in_user = module_security::get_loggedin_id();
                 if (!$logged_in_user) {
                     $logged_in_user = $ticket_data['user_id'];
                 }
             }
             if (!$ticket_data['user_id'] && module_security::get_loggedin_id()) {
                 update_insert('ticket_id', $ticket_id, 'ticket', array('user_id' => module_security::get_loggedin_id()));
                 $ticket_data['user_id'] = module_security::get_loggedin_id();
             }
             $ticket_creator = $ticket_data['user_id'];
             // echo "creator: $ticket_creator logged in: $logged_in_user"; print_r($ticket_data);exit;
             //echo "Creator: ".$ticket_data['user_id'] . " logged in ".$logged_in_user;exit;
             if ($ticket_creator == $logged_in_user) {
                 // we are sending a reply back to the admin, from the end user.
                 self::mark_as_unread($ticket_id);
                 $ticket_message_id = $this->send_reply($ticket_id, $data['new_ticket_message'], $ticket_creator, $ticket_data['assigned_user_id'] ? $ticket_data['assigned_user_id'] : module_config::c('ticket_default_user_id', 1), 'end_user', '', array('private_message' => isset($data['private_message']) && $data['private_message']));
             } else {
                 // we are sending a reply back to the ticket user.
                 // admin is allowed to change the status of a message.
                 $from_user_id = $ticket_data['assigned_user_id'] ? $ticket_data['assigned_user_id'] : module_security::get_loggedin_id();
                 //echo "From $from_user_id to $ticket_creator ";exit;
                 $ticket_message_id = $this->send_reply($ticket_id, $data['new_ticket_message'], $from_user_id, $ticket_creator, 'admin', '', array('private_message' => isset($data['private_message']) && $data['private_message']));
                 // do we add cc/bcc here?
             }
             if ($ticket_message_id && isset($data['change_status_id']) && $data['change_status_id']) {
                 // store the ticket status change here.
                 update_insert("ticket_message_id", $ticket_message_id, "ticket_message", array('status_id' => $data['change_status_id']));
             }
         }
         if (isset($data['change_status_id']) && $data['change_status_id']) {
             // we only update this status if the sent reply or send reply and next buttons are clicked.
             if (isset($_REQUEST['newmsg']) || isset($_REQUEST['newmsg_next'])) {
                 update_insert("ticket_id", $ticket_id, "ticket", array('status_id' => $data['change_status_id']));
             }
         }
     }
     module_extra::save_extras('ticket', 'ticket_id', $ticket_id);
     // automaticall send notification email to assigned staff membeR?
     if (module_config::c('ticket_auto_notify_staff', 0)) {
         module_cache::clear('ticket');
         $new_ticket_data = self::get_ticket($ticket_id);
         if ($new_ticket_data['assigned_user_id'] && (!$existing_ticket_data || $existing_ticket_data['assigned_user_id'] != $new_ticket_data['assigned_user_id'])) {
             // copied from ticket_admin_notify.php
             // template for sending emails.
             // are we sending the paid one? or the dueone.
             $template = module_template::get_template_by_key('ticket_email_notify');
             $new_ticket_data['from_name'] = module_security::get_loggedin_name();
             $new_ticket_data['ticket_url'] = module_ticket::link_open($ticket_id);
             $new_ticket_data['ticket_subject'] = $new_ticket_data['subject'];
             // sending to the staff member.
             $replace_fields = self::get_replace_fields($new_ticket_data['ticket_id'], $new_ticket_data);
             $template->assign_values($replace_fields);
             $template->assign_values($new_ticket_data);
             $html = $template->render('html');
             $email = module_email::new_email();
             $email->replace_values = $new_ticket_data + $replace_fields;
             $email->set_subject($template->description);
             $email->set_to('user', $new_ticket_data['assigned_user_id']);
             // do we send images inline?
             $email->set_html($html);
             if ($email->send()) {
                 // it worked successfully!!
             } else {
                 /// log err?
             }
         }
     }
     module_cache::clear('ticket');
     return $ticket_id;
 }