Example #1
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;
 }
Example #2
0
 private function _handle_send_email()
 {
     $options = @unserialize(base64_decode($_REQUEST['options']));
     if (!$options) {
         $options = array();
     }
     $options = $this->get_email_compose_options($options);
     if (isset($_REQUEST['custom_to'])) {
         $custom_to = is_array($_REQUEST['custom_to']) ? $_REQUEST['custom_to'] : array($_REQUEST['custom_to']);
         $to = array();
         foreach ($custom_to as $ct) {
             $ct = explode('||', $ct);
             $ct['email'] = $ct[0];
             $ct['name'] = isset($ct[1]) ? $ct[1] : '';
             $ct['user_id'] = isset($ct[2]) ? (int) $ct[2] : 0;
             $to[] = $ct;
         }
     } else {
         $to = isset($options['to']) && is_array($options['to']) ? $options['to'] : array();
     }
     $email = $this->new_email();
     $email->subject = $options['subject'];
     foreach ($to as $t) {
         if (isset($t['user_id']) && $t['user_id'] > 0) {
             $email->set_to('user', $t['user_id'], $t['email'], $t['name'] . (isset($t['last_name']) && module_config::c('email_to_full_name', 1) ? ' ' . $t['last_name'] : ''));
         } else {
             $email->set_to_manual($t['email'], $t['name'] . (isset($t['last_name']) && module_config::c('email_to_full_name', 1) ? ' ' . $t['last_name'] : ''));
         }
     }
     // set from is the default from address.
     if (isset($options['from_email'])) {
         $email->set_from_manual($options['from_email'], isset($options['from_name']) ? $options['from_name'] : '');
         $email->set_bounce_address($options['from_email']);
     }
     if ($options['cc'] && is_array($options['cc'])) {
         foreach ($options['cc'] as $cc_details) {
             $bits = explode('||', $cc_details);
             if (count($bits) >= 2 && $bits[0]) {
                 $email->set_cc_manual($bits[0], $bits[1]);
             }
         }
     }
     if ($options['bcc']) {
         $bcc = explode(',', $options['bcc']);
         foreach ($bcc as $b) {
             $b = trim($b);
             if (strlen($b)) {
                 $email->set_bcc_manual($b, '');
             }
         }
     }
     if (isset($options['company_id'])) {
         $email->company_id = $options['company_id'];
     }
     if (isset($options['customer_id'])) {
         // todo: verify this is a legit customer id we can send emails to.
         $email->customer_id = $options['customer_id'];
         if ($options['customer_id'] > 0) {
             foreach (module_customer::get_replace_fields($options['customer_id']) as $key => $val) {
                 //echo "Replacing $key with $val <br>";
                 $email->replace($key, $val);
             }
         }
     }
     if (isset($options['newsletter_id'])) {
         $email->newsletter_id = $options['newsletter_id'];
     }
     if (isset($options['file_id'])) {
         $email->file_id = $options['file_id'];
     }
     if (isset($options['send_id'])) {
         $email->send_id = $options['send_id'];
     }
     if (isset($options['invoice_id'])) {
         $email->invoice_id = $options['invoice_id'];
         if ($options['invoice_id'] > 0) {
             foreach (module_invoice::get_replace_fields($options['invoice_id']) as $key => $val) {
                 $email->replace($key, $val);
             }
         }
     }
     if (isset($options['job_id'])) {
         $email->job_id = $options['job_id'];
         if ($options['job_id'] > 0) {
             foreach (module_job::get_replace_fields($options['job_id']) as $key => $val) {
                 $email->replace($key, $val);
             }
         }
     }
     if (isset($options['website_id'])) {
         $email->website_id = $options['website_id'];
         if ($options['website_id'] > 0) {
             foreach (module_website::get_replace_fields($options['website_id']) as $key => $val) {
                 $email->replace($key, $val);
             }
         }
     }
     if (isset($options['quote_id'])) {
         $email->quote_id = $options['quote_id'];
         if ($options['quote_id'] > 0) {
             foreach (module_quote::get_replace_fields($options['quote_id']) as $key => $val) {
                 $email->replace($key, $val);
             }
         }
     }
     // custom data integration
     if (class_exists('module_data', false) && module_config::c('custom_data_in_email', 1) && $options['customer_id'] > 0 && !empty($_REQUEST['custom_data_info']) && !empty($_REQUEST['custom_data_related'])) {
         global $plugins;
         // find all possible custom data entries
         $data_types = $plugins['data']->get_data_types();
         foreach ($data_types as $data_type) {
             switch ($data_type['data_type_menu']) {
                 case _CUSTOM_DATA_MENU_LOCATION_CUSTOMER:
                     if ($plugins['data']->can_i('view', $data_type['data_type_name'])) {
                         $search = array('customer_id' => $options['customer_id'], 'data_type_id' => $data_type['data_type_id']);
                         // we have to limit the data types to only those created by current user if they are not administration
                         $datas = $plugins['data']->get_datas($search);
                         if ($datas) {
                             // found some! does this exist in one of our inputs?
                             if (!empty($_REQUEST['custom_data_info'][$data_type['data_type_id']]) && !empty($_REQUEST['custom_data_related'][$data_type['data_type_id']])) {
                                 $data_record_id = $_REQUEST['custom_data_related'][$data_type['data_type_id']];
                                 $data_info = json_decode($_REQUEST['custom_data_info'][$data_type['data_type_id']], true);
                                 if (is_array($data_info) && isset($datas[$data_record_id])) {
                                     // we have a winner!
                                     $list_fields = array();
                                     $data_field_groups = $plugins['data']->get_data_field_groups($data_type['data_type_id']);
                                     foreach ($data_field_groups as $data_field_group) {
                                         $data_fields = $plugins['data']->get_data_fields($data_field_group['data_field_group_id']);
                                         foreach ($data_fields as $data_field) {
                                             if ($data_field['show_list']) {
                                                 $list_fields[$data_field['data_field_id']] = $data_field;
                                             }
                                         }
                                     }
                                     $list_data_items = $plugins['data']->get_data_items($data_record_id);
                                     foreach ($list_fields as $list_field) {
                                         $settings = @unserialize($list_data_items[$list_field['data_field_id']]['data_field_settings']);
                                         if (!isset($settings['field_type'])) {
                                             $settings['field_type'] = isset($list_field['field_type']) ? $list_field['field_type'] : false;
                                         }
                                         $value = false;
                                         if (isset($list_data_items[$list_field['data_field_id']])) {
                                             $value = $list_data_items[$list_field['data_field_id']]['data_text'];
                                         }
                                         if ($value) {
                                             $data_info['key'] = $value;
                                             break;
                                         }
                                     }
                                     $data_info['data_record_id'] = $data_record_id[$data_type['data_type_id']];
                                     $email->custom_data[$data_type['data_type_id']] = $data_info;
                                     $email->set_custom_data($data_type['data_type_id'], $data_record_id);
                                 }
                             }
                         }
                     }
             }
         }
     }
     // final override for first_name last_name if selected from the custom to drop down
     foreach ($to as $t) {
         if (isset($t['user_id']) && $t['user_id'] > 0) {
             $user = module_user::get_user($t['user_id']);
             if ($user) {
                 if (strpos($options['content'], '{AUTO_LOGIN_LINK}') !== false && $t['user_id'] != 1) {
                     $email->replace('AUTO_LOGIN_LINK', module_security::generate_auto_login_link($t['user_id']));
                 }
                 $email->replace('first_name', $user['name']);
                 $email->replace('last_name', $user['last_name']);
             }
         }
     }
     if (isset($options['note_id'])) {
         $email->note_id = $options['note_id'];
     }
     if (isset($options['debug_message'])) {
         $email->debug_message = $options['debug_message'];
     }
     $email->set_html($options['content']);
     foreach ($options['attachments'] as $attachment) {
         $email->AddAttachment($attachment['path'], $attachment['name']);
     }
     // new addition, manually added attachments.
     if (isset($_FILES['manual_attachment']) && isset($_FILES['manual_attachment']['tmp_name'])) {
         foreach ($_FILES['manual_attachment']['tmp_name'] as $key => $tmp_name) {
             if (is_uploaded_file($tmp_name) && isset($_FILES['manual_attachment']['name'][$key]) && strlen($_FILES['manual_attachment']['name'][$key])) {
                 $email->AddAttachment($tmp_name, $_FILES['manual_attachment']['name'][$key]);
             }
         }
     }
     if ($email->send()) {
         if (isset($options['success_callback_args']) && count($options['success_callback_args']) && $options['success_callback'] && is_callable($options['success_callback'])) {
             // new callback method using call_user_func_array
             $args = $options['success_callback_args'];
             $args['email_id'] = $email->email_id;
             if (preg_match('#module_\\w#', $options['success_callback'])) {
                 call_user_func($options['success_callback'], $args);
             }
         }
         /*else if($options['success_callback']){
               eval($options['success_callback']);
           }*/
         set_message('Email sent successfully');
         redirect_browser($options['complete_url']);
     } else {
         set_error('Sending email failed: ' . $email->error_text);
         redirect_browser($options['cancel_url']);
     }
 }
Example #3
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;
 }
Example #4
0
                }
            }
            /*
                                    $c = array();
                                    $res = module_user::get_users(array('customer_id'=>$ticket['customer_id']));
                                    while($row = array_shift($res)){
                                        $c[$row['user_id']] = $row['name'];
                                    }
                                    if(false && module_ticket::can_i('edit','Related to')){
                                        echo print_select_box($c,'user_id',$ticket['user_id']);
                                    }else if($ticket['user_id']){
                                        echo isset($c[$ticket['user_id']]) ? $c[$ticket['user_id']] : 'N/A';
                                    }*/
        }));
    }
    $res = module_website::get_websites(array('customer_id' => $ticket['customer_id']));
    if (count($res)) {
        $fieldset_data['elements'][] = array('title' => _l('' . module_config::c('project_name_single', 'Website')), 'fields' => array(function () use($res, $ticket) {
            $c = array();
            while ($row = array_shift($res)) {
                $c[$row['website_id']] = $row['name'];
            }
            echo print_select_box($c, 'website_id', $ticket['website_id']);
        }));
    }
    if ((int) $ticket_id > 0) {
        $fieldset_data['elements'][] = array('title' => _l('Public link'), 'fields' => array(function () use($ticket_id) {
            ?>
 <a href="<?php 
            echo module_ticket::link_public($ticket_id);
            ?>
Example #5
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;
     }
 }
Example #6
0
        // change between websites within this customer?
        // or websites all together?
        $res = module_website::get_websites(array('customer_id' => isset($_REQUEST['customer_id']) ? (int) $_REQUEST['customer_id'] : false));
        //$res = module_website::get_websites();
        while ($row = array_shift($res)) {
            $c[$row['website_id']] = $row['name'];
        }
        echo print_select_box($c, 'website_id', $job['website_id']);
        ?>

                        <?php 
        if ($job['website_id'] && module_website::can_i('view', 'Websites')) {
            ?>

                            <a href="<?php 
            echo module_website::link_open($job['website_id'], false);
            ?>
"><?php 
            _e('Open');
            ?>
</a>
                        <?php 
        }
        ?>

                        <?php 
        _h('This will be the ' . module_config::c('project_name_single', 'Website') . ' this job is assigned to - and therefor the customer. Every job should have a' . module_config::c('project_name_single', 'Website') . ' assigned. Clicking the open link will take you to the ' . module_config::c('project_name_single', 'Website'));
        ?>

                    </td>
                </tr>
Example #7
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;
 }
Example #8
0
    }
}
?>
        </td>
    </tr>
    <?php 
if (class_exists('module_website', false) && module_website::is_plugin_enabled()) {
    ?>
    <tr>
        <th><?php 
    _e('Related %s:', module_config::c('project_name_single', 'Website'));
    ?>
</th>
        <td>
            <?php 
    $websites = module_website::get_websites(array('customer_id' => $customer_id));
    if ($can_edit_emails) {
        echo print_select_box($websites, 'website_id', isset($email['website_id']) ? $email['website_id'] : false, '', true, 'name');
    } else {
        if (isset($email['website_id']) && $email['website_id']) {
            echo isset($websites[$email['website_id']]) ? htmlspecialchars($websites[$email['website_id']]['name']) : _l('Deleted');
        } else {
            _e('N/A');
        }
    }
    ?>
        </td>
    </tr>
    <?php 
}
?>
Example #9
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;
     }
 }
Example #10
0
if ($subscription['subscription_owner_id']) {
    $subscription_owner = get_single('subscription_owner', 'subscription_owner_id', $subscription['subscription_owner_id']);
    if (count($subscription_owner)) {
        ob_start();
        ?>
	    <table border="0" cellspacing="0" cellpadding="2" class="tableclass tableclass_form tableclass_full">
	        <tbody>
	        <tr>
	            <td>
	                <?php 
        switch ($subscription_owner['owner_table']) {
            case 'member':
                $member_name = module_member::link_open($subscription_owner['owner_id'], true);
                break;
            case 'website':
                $member_name = module_website::link_open($subscription_owner['owner_id'], true);
                break;
            case 'customer':
                $member_name = module_customer::link_open($subscription_owner['owner_id'], true);
                break;
        }
        $subscription_name = module_subscription::link_open($subscription['subscription_id'], true);
        _e('This is a subscription payment for %s %s on the subscription: %s', $subscription_owner['owner_table'], $member_name, $subscription_name);
        ?>
	            </td>
	        </tr>
	        </tbody>
	    </table>
		<?php 
        $fieldset_data = array('heading' => array('title' => _l('%s Subscription', _l(ucwords($subscription_owner['owner_table']))), 'type' => 'h3'), 'elements_before' => ob_get_clean());
        echo module_form::generate_fieldset($fieldset_data);
Example #11
0
 * IP Address: 67.79.165.254
 */
if (!count($change_requests)) {
    return;
}
$jobs = module_job::get_jobs(array('website_id' => $website_id));
// pull out jobs that don't have an invoice.
foreach ($jobs as $job_id => $job) {
    $invoices = module_invoice::get_invoices(array('job_id' => $job['job_id']));
    if (count($invoices)) {
        unset($jobs[$job_id]);
    }
}
$h = array('type' => 'h3', 'title' => 'Customer Change Requests');
// find out how many changes are incomplete
$link_toggle = module_website::link_open($website_id);
$show_completed = isset($_REQUEST['show_completed_change_requests']) ? $_REQUEST['show_completed_change_requests'] : false;
$num_completed = 0;
foreach ($change_requests as $change_request) {
    if ($change_request['status'] == _CHANGE_REQUEST_STATUS_COMPLETE) {
        $num_completed++;
    }
}
if ($num_completed) {
    if ($show_completed) {
        $h['button'] = array('title' => _l('Hide %s completed changes', $num_completed), 'url' => $link_toggle .= '&show_completed_change_requests=0');
    } else {
        $h['button'] = array('title' => _l('Show %s completed changes', $num_completed), 'url' => $link_toggle .= '&show_completed_change_requests=1');
    }
}
//print_heading($h);
}
/** ADVANCED AREA **/
hook_handle_callback('layout_column_half', 2);
if ($customer_id && $customer_id != 'new') {
    if (class_exists('module_group', false) && module_group::is_plugin_enabled()) {
        module_group::display_groups(array('title' => $page_type_single . ' Groups', 'owner_table' => 'customer', 'owner_id' => $customer_id, 'view_link' => $module->link_open($customer_id)));
    }
    $note_summary_owners = array();
    // generate a list of all possible notes we can display for this customer.
    // display all the notes which are owned by all the sites we have access to
    // display all the notes which are owned by all the users we have access to
    foreach (module_user::get_contacts(array('customer_id' => $customer_id)) as $val) {
        $note_summary_owners['user'][] = $val['user_id'];
    }
    if (class_exists('module_website', false) && module_website::is_plugin_enabled()) {
        foreach (module_website::get_websites(array('customer_id' => $customer_id)) as $val) {
            $note_summary_owners['website'][] = $val['website_id'];
        }
    }
    if (class_exists('module_job', false) && module_job::is_plugin_enabled()) {
        foreach (module_job::get_jobs(array('customer_id' => $customer_id)) as $val) {
            $note_summary_owners['job'][] = $val['job_id'];
            foreach (module_invoice::get_invoices(array('job_id' => $val['job_id'])) as $val) {
                $note_summary_owners['invoice'][$val['invoice_id']] = $val['invoice_id'];
            }
        }
    }
    if (class_exists('module_invoice', false) && module_invoice::is_plugin_enabled()) {
        foreach (module_invoice::get_invoices(array('customer_id' => $customer_id)) as $val) {
            $note_summary_owners['invoice'][$val['invoice_id']] = $val['invoice_id'];
        }
Example #13
0
 public static function hook_filter_var_website_list($call, $attributes)
 {
     if (!is_array($attributes)) {
         $attributes = array();
     }
     foreach (module_website::get_websites(array('customer_id' => isset($_REQUEST['customer_id']) ? (int) $_REQUEST['customer_id'] : false), array('columns' => 'u.website_id, u.name')) as $website) {
         $attributes[$website['website_id']] = $website['name'];
     }
     return $attributes;
 }
Example #14
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;
 }
Example #15
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";
                     }
                 }
             }
         }
     }
 }
        foreach ($total_paid as $id => $t) {
            $total_paid[$id] = dollar($t, true, $id);
        }
        foreach ($total_unpaid as $id => $t) {
            $total_unpaid[$id] = dollar($t, true, $id);
        }
        ?>

            <tr>
                <td><?php 
        switch ($subscribed_customer['owner_table']) {
            case 'customer':
                echo module_customer::link_open($subscribed_customer['owner_id'], true);
                break;
            case 'website':
                echo module_website::link_open($subscribed_customer['owner_id'], true);
                break;
            case 'member':
                echo module_member::link_open($subscribed_customer['owner_id'], true);
                break;
        }
        ?>
</td>
                <td><?php 
        echo print_date($subscribed_customer['start_date']);
        ?>
</td>
                <td><?php 
        echo print_date($subscribed_customer['next_due_date']);
        ?>
</td>
Example #17
0
							    <a href="<?php 
                    echo module_website::link_open($job['website_id'], false);
                    ?>
"><?php 
                    _e('Open');
                    ?>
</a>
						    <?php 
                }
                ?>

						    <?php 
                _h('This will be the ' . module_config::c('project_name_single', 'Website') . ' this job is assigned to - and therefor the customer. Every job should have a' . module_config::c('project_name_single', 'Website') . ' assigned. Clicking the open link will take you to the ' . module_config::c('project_name_single', 'Website'));
            } else {
                if ($job['website_id']) {
                    echo module_website::link_open($job['website_id'], true);
                } else {
                    _e('N/A');
                }
            }
        }));
    } else {
        if (!class_exists('module_website', false) && module_config::c('show_ucm_ads', 1)) {
            $fieldset_data['elements'][] = array('title' => module_config::c('project_name_single', 'Website'), 'fields' => array('(website option available in <a href="http://codecanyon.net/item/ultimate-client-manager-pro-edition/2621629?ref=dtbaker" target="_blank">UCM Pro Edition</a>)'));
        }
    }
    if (module_customer::can_i('view', 'Customers')) {
        $fieldset_data['elements'][] = array('title' => 'Customer', 'fields' => array(function () use(&$job) {
            $c = array();
            $customers = module_customer::get_customers();
            foreach ($customers as $customer) {
Example #18
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>
Example #19
0
								    <?php 
                    }
                    ?>

							    </tr>
						    <?php 
                }
                ?>

						    </tbody>
					    </table>
				    </div>
			        <?php 
                $fieldset_data['elements_before'] = ob_get_clean();
            }
            echo module_form::generate_fieldset($fieldset_data);
        }
    }
    // and a hook for our new change request plugin
    hook_handle_callback('website_main', $website_id);
}
hook_handle_callback('layout_column_half', 'end');
$form_actions = array('class' => 'action_bar action_bar_center', 'elements' => array(array('type' => 'save_button', 'name' => 'butt_save', 'value' => _l('Save ' . module_config::c('project_name_single', 'Website'))), array('ignore' => !((int) $website_id && module_website::can_i('delete', 'Websites')), 'type' => 'delete_button', 'name' => 'butt_del', 'value' => _l('Delete')), array('type' => 'button', 'name' => 'cancel', 'value' => _l('Cancel'), 'class' => 'submit_button', 'onclick' => "window.location.href='" . module_website::link_open(false) . "';")));
echo module_form::generate_form_actions($form_actions);
?>




</form>
            function customer_admin_email_generate_invoice_list($invoices, $customer_id)
            {
                ob_start();
                $colspan = 9;
                $colspan2 = 0;
                $invoice_total = array();
                $invoice_total_due = array();
                foreach ($invoices as $invoice) {
                    if (!isset($invoice_total[$invoice['currency_id']])) {
                        $invoice_total[$invoice['currency_id']] = 0;
                    }
                    if ($invoice['c_total_amount'] == 0) {
                        $invoice = module_invoice::get_invoice($invoice['invoice_id']);
                    }
                    $invoice_total[$invoice['currency_id']] += $invoice['c_total_amount'];
                    if (!isset($invoice_total_due[$invoice['currency_id']])) {
                        $invoice_total_due[$invoice['currency_id']] = 0;
                    }
                    $invoice_total_due[$invoice['currency_id']] += $invoice['c_total_amount_due'];
                }
                $table_manager = module_theme::new_table_manager();
                $columns = array();
                $columns['invoice_number'] = array('title' => 'Invoice Number', 'callback' => function ($invoice) {
                    //echo module_invoice::link_open($invoice['invoice_id'],true,$invoice);
                    echo '<a href="' . module_invoice::link_public($invoice['invoice_id']) . '">' . htmlspecialchars($invoice['name']) . '</a>';
                }, 'cell_class' => 'row_action');
                $columns['invoice_status'] = array('title' => 'Status', 'callback' => function ($invoice) {
                    echo htmlspecialchars($invoice['status']);
                });
                $columns['invoice_create_date'] = array('title' => 'Create Date', 'callback' => function ($invoice) {
                    if (!$invoice['date_create'] || $invoice['date_create'] == '0000-00-00') {
                        //echo print_date($invoice['date_created']);
                    } else {
                        echo print_date($invoice['date_create']);
                    }
                });
                $columns['invoice_due_date'] = array('title' => 'Due Date', 'callback' => function ($invoice) {
                    if ((!$invoice['date_paid'] || $invoice['date_paid'] == '0000-00-00') && strtotime($invoice['date_due']) < time()) {
                        echo '<span class="error_text">';
                        echo print_date($invoice['date_due']);
                        echo '</span>';
                    } else {
                        echo print_date($invoice['date_due']);
                    }
                });
                $columns['invoice_sent_date'] = array('title' => 'Sent Date', 'callback' => function ($invoice) {
                    if ($invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') {
                        ?>

				            <?php 
                        echo print_date($invoice['date_sent']);
                        ?>

				        <?php 
                    } else {
                        ?>

				            <span class="error_text"><?php 
                        _e('Not sent');
                        ?>
</span>
				        <?php 
                    }
                });
                $columns['invoice_paid_date'] = array('title' => 'Paid Date', 'callback' => function ($invoice) {
                    if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') {
                        ?>

				            <?php 
                        echo print_date($invoice['date_paid']);
                        ?>

				        <?php 
                    } else {
                        if ($invoice['date_cancel'] && $invoice['date_cancel'] != '0000-00-00') {
                            ?>

				            <span class="error_text"><?php 
                            _e('Cancelled');
                            ?>
</span>
				        <?php 
                        } else {
                            if ($invoice['overdue']) {
                                ?>

				            <span class="error_text" style="font-weight: bold; text-decoration: underline;"><?php 
                                _e('Overdue');
                                ?>
</span>
				        <?php 
                            } else {
                                ?>

				            <span class="error_text"><?php 
                                _e('Not paid');
                                ?>
</span>
				        <?php 
                            }
                        }
                    }
                });
                if (class_exists('module_website', false) && module_website::is_plugin_enabled() && module_website::can_i('view', module_config::c('project_name_plural', 'Websites'))) {
                    $colspan++;
                    $columns['invoice_website'] = array('title' => module_config::c('project_name_single', 'Website'), 'callback' => function ($invoice) {
                        if (isset($invoice['website_ids'])) {
                            foreach ($invoice['website_ids'] as $website_id) {
                                if ((int) $website_id > 0) {
                                    echo module_website::link_open($website_id, true);
                                    echo '<br/>';
                                }
                            }
                        }
                    });
                }
                $columns['invoice_job'] = array('title' => 'Job', 'callback' => function ($invoice) {
                    foreach ($invoice['job_ids'] as $job_id) {
                        if ((int) $job_id > 0) {
                            //echo module_job::link_open($job_id,true);
                            $job_data = module_job::get_job($job_id);
                            echo '<a href="' . module_job::link_public($job_id) . '">' . htmlspecialchars($job_data['name']) . '</a>';
                            if ($job_data['date_start'] && $job_data['date_start'] != '0000-00-00' && $job_data['date_renew'] && $job_data['date_renew'] != '0000-00-00') {
                                _e(' (%s to %s)', print_date($job_data['date_start']), print_date(strtotime("-1 day", strtotime($job_data['date_renew']))));
                            }
                            echo "<br/>\n";
                        }
                    }
                    hook_handle_callback('invoice_admin_list_job', $invoice['invoice_id']);
                });
                if (!isset($_REQUEST['customer_id']) && module_customer::can_i('view', 'Customers')) {
                    $colspan++;
                    $columns['invoice_customer'] = array('title' => 'Customer', 'callback' => function ($invoice) {
                        echo module_customer::link_open($invoice['customer_id'], true);
                    });
                }
                $columns['c_invoice_total'] = array('title' => 'Invoice Total', 'callback' => function ($invoice) {
                    echo dollar($invoice['total_amount'], true, $invoice['currency_id']);
                });
                $columns['c_invoice_total_due'] = array('title' => 'Amount Due', 'callback' => function ($invoice) {
                    echo dollar($invoice['total_amount_due'], true, $invoice['currency_id']);
                    ?>

				        <?php 
                    if ($invoice['total_amount_credit'] > 0) {
                        ?>

				        <span class="success_text"><?php 
                        echo _l('Credit: %s', dollar($invoice['total_amount_credit'], true, $invoice['currency_id']));
                        ?>
</span>
				            <?php 
                    }
                });
                if (class_exists('module_extra', false)) {
                    ob_start();
                    $colspan2 += module_extra::print_table_header('invoice');
                    // used in the footer calc.
                    ob_end_clean();
                    $table_manager->display_extra('invoice', function ($invoice) {
                        module_extra::print_table_data('invoice', $invoice['invoice_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
                    if (isset($row_data['invoice_id']) && (int) $row_data['invoice_id'] > 0) {
                        return module_invoice::get_invoice($row_data['invoice_id']);
                    }
                    return array();
                };
                $table_manager->set_rows($invoices);
                if (module_config::c('invoice_list_show_totals', 1)) {
                    $footer_rows = array();
                    foreach ($invoice_total + $invoice_total_due as $currency_id => $foo) {
                        $currency = get_single('currency', 'currency_id', $currency_id);
                        $footer_rows[] = array('invoice_number' => array('data' => '<strong>' . _l('%s Totals:', $currency && isset($currency['code']) ? $currency['code'] : '') . '</strong>', 'cell_colspan' => $colspan - 2, 'cell_class' => 'text-right'), 'c_invoice_total' => array('data' => '<strong>' . dollar(isset($invoice_total[$currency_id]) ? $invoice_total[$currency_id] : 0, true, $currency_id) . '</strong>'), 'c_invoice_total_due' => array('data' => '<strong>' . dollar(isset($invoice_total_due[$currency_id]) ? $invoice_total_due[$currency_id] : 0, true, $currency_id) . '</strong>'), 'row_bulk_action' => array('data' => ' ', 'cell_colspan' => $colspan2));
                    }
                    $table_manager->set_footer_rows($footer_rows);
                }
                $table_manager->pagination = false;
                $table_manager->print_table();
                return ob_get_clean();
            }
Example #21
0
echo module_form::search_bar($search_bar);
/** START TABLE LAYOUT **/
$table_manager = module_theme::new_table_manager();
$columns = array();
$columns['quote_title'] = array('title' => 'Quote Title', 'callback' => function ($quote) {
    echo module_quote::link_open($quote['quote_id'], true, $quote);
}, 'cell_class' => 'row_action');
$columns['quote_start_date'] = array('title' => 'Create Date', 'callback' => function ($quote) {
    echo print_date($quote['date_create']);
});
$columns['quote_completed_date'] = array('title' => 'Accepted Date', 'callback' => function ($quote) {
    echo print_date($quote['date_approved']);
});
if (class_exists('module_website', false) && module_website::is_plugin_enabled()) {
    $columns['quote_website'] = array('title' => module_config::c('project_name_single', 'Website'), 'callback' => function ($quote) {
        echo module_website::link_open($quote['website_id'], true);
    });
}
if (!isset($_REQUEST['customer_id']) && module_customer::can_i('view', 'Customers')) {
    $columns['quote_customer'] = array('title' => 'Customer', 'callback' => function ($quote) {
        echo module_customer::link_open($quote['customer_id'], true);
    });
}
$columns['quote_type'] = array('title' => 'Type', 'callback' => function ($quote) {
    echo htmlspecialchars($quote['type']);
});
$columns['quote_status'] = array('title' => 'Status', 'callback' => function ($quote) {
    echo htmlspecialchars($quote['status']);
});
if (module_config::c('quote_allow_staff_assignment', 1)) {
    $columns['quote_staff'] = array('title' => 'Staff Member', 'callback' => function ($quote) {
Example #22
0
">
        <td>
            <?php 
    echo module_job::link_open($job_data['job_id'], true, $job_data);
    ?>

            <?php 
    if (isset($original_job_data['renew_from_job_id'])) {
        _e('(will renew on %s)', print_date($original_job_data['date_start']));
    }
    ?>

        </td>
        <td>
            <?php 
    echo module_website::link_open($original_job_data['website_id'], true);
    ?>

        </td>
        <td>
            <?php 
    echo module_customer::link_open($job_data['customer_id'], true);
    ?>

        </td>
        <td>
            <?php 
    echo htmlspecialchars($original_job_data['type']);
    ?>

        </td>
Example #23
0
             $res = module_website::get_websites(array('customer_id' => isset($_REQUEST['customer_id']) ? (int) $_REQUEST['customer_id'] : ($invoice['customer_id'] ? $invoice['customer_id'] : false)));
             //$res = module_website::get_websites();
             while ($row = array_shift($res)) {
                 $c[$row['website_id']] = $row['name'];
             }
             echo print_select_box($c, 'website_id', $invoice['website_id']);
         } else {
             if ($invoice['website_id']) {
                 echo module_website::link_open($invoice['website_id'], true);
             } else {
                 _e('N/A');
             }
         }
         foreach ($website_ids as $website_id) {
             if ($website_id) {
                 echo ' ' . module_website::link_open($website_id, true);
             }
         }
     }));
 } else {
     if (!class_exists('module_website', false) && module_config::c('show_ucm_ads', 1)) {
         $fieldset_data['elements'][] = array('title' => module_config::c('project_name_single', 'Website'), 'fields' => array('(website option available in <a href="http://codecanyon.net/item/ultimate-client-manager-pro-edition/2621629?ref=dtbaker" target="_blank">UCM Pro Edition</a>)'));
     }
 }
 $fieldset_data['elements'][] = array('title' => 'Tax Type', 'field' => array('type' => 'select', 'blank' => false, 'options' => array('0' => _l('Tax Added'), 1 => _l('Tax Included')), 'name' => 'tax_type', 'value' => $invoice['tax_type']));
 if ($discounts_allowed) {
     $fieldset_data['elements'][] = array('title' => 'Discount Amount', 'fields' => array(function () use($invoice_locked, $invoice_id, &$invoice) {
         echo $invoice_locked || !module_security::is_page_editable() ? '<span class="currency">' . dollar($invoice['discount_amount'], true, $invoice['currency_id']) . '</span>' : currency('<input type="text" name="discount_amount" value="' . number_out($invoice['discount_amount']) . '" class="currency">');
         echo ' ';
     }, array('type' => 'html', 'value' => '', 'help' => 'Here you can apply a before tax discount to this invoice. You can name this anything, eg: DISCOUNT, CREDIT, REFUND, etc..')));
     $fieldset_data['elements'][] = array('title' => 'Discount Name', 'fields' => array(function () use($invoice_id, &$invoice) {
Example #24
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;
        }
    }
<?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']));
}
Thank you,<br><br>
{FROM_NAME}
', 'Change Request: {URL}', array('NAME' => 'Customers Name', 'URL' => 'Website address', 'REQUEST' => 'Change REquest', 'FROM_NAME' => 'Your name', 'CHANGE_REQUEST_URL' => 'Link to change request for customer'));
// template for sending emails.
// are we sending the paid one? or the dueone.
//$template_name = 'change_request_email';
$template_name = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : 'change_request_email';
$template = module_template::get_template_by_key($template_name);
$change_request['from_name'] = module_security::get_loggedin_name();
$change_request['change_request_url'] = module_change_request::link_public_change($website_data['website_id'], $change_request_id);
ob_start();
$change_request['change_request_tasks'] = ob_get_clean();
// find available "to" recipients.
// customer contacts.
$to_select = false;
if ($website_data['customer_id']) {
    $customer = module_customer::get_customer($website_data['customer_id']);
    $change_request['customer_name'] = $customer['customer_name'];
    $to = module_user::get_contacts(array('customer_id' => $website_data['customer_id']));
    if ($customer['primary_user_id']) {
        $primary = module_user::get_user($customer['primary_user_id']);
        if ($primary) {
            $to_select = $primary['email'];
        }
    }
} else {
    $to = array();
}
$template->assign_values($change_request);
module_email::print_compose(array('find_other_templates' => 'change_request_email', 'current_template' => $template_name, 'customer_id' => $website_data['customer_id'], 'change_request_id' => $change_request['change_request_id'], 'debug_message' => 'Sending change request email', 'to' => $to, 'to_select' => $to_select, 'bcc' => module_config::c('admin_email_address', ''), 'content' => $template->render('html'), 'subject' => $template->replace_description(), 'success_url' => module_website::link_open($website_data['website_id']), 'cancel_url' => module_website::link_open($website_data['website_id'])));