Example #1
0
 function handle_hook($hook, $calling_module = false, $owner_table = false, $key_name = false, $key_value = false, $rel_data = false)
 {
     switch ($hook) {
         case "home_alerts":
             $alerts = array();
             if (module_config::c('allow_note_reminders', 1)) {
                 // find any jobs that are past the due date and dont have a finished date.
                 $key = _l('Note Reminder');
                 if (class_exists('module_dashboard', false)) {
                     module_dashboard::register_group($key, array('columns' => array('name' => _l('Reminder'), 'type' => _l('Type'), 'full_link' => _l('Link'), 'date' => _l('Date'), 'days' => _l('Date'))));
                 }
                 $sql = "SELECT * FROM `" . _DB_PREFIX . "note` n ";
                 $sql .= " WHERE n.`reminder` = 1 AND n.note_time < " . (int) strtotime('+' . module_config::c('alert_days_in_future', 5) . ' days') . "";
                 $sql .= " AND ( n.`user_id` = 0 OR n.`user_id` = " . module_security::get_loggedin_id() . ")";
                 $sql .= " ORDER BY n.note_time ASC";
                 $tasks = qa($sql);
                 foreach ($tasks as $task) {
                     $alert_res = process_alert(date('Y-m-d', $task['note_time']), $key);
                     if ($alert_res) {
                         $alert_res['link'] = $task['rel_data'];
                         // fix for linking when changing folder.
                         $alert_res['type'] = _l(ucwords($task['owner_table']));
                         switch ($task['owner_table']) {
                             case 'user':
                                 $user = module_user::get_user($task['owner_id']);
                                 if ($user['customer_id'] || $user['vendor_id']) {
                                     $alert_res['link'] = module_user::link_open_contact($task['owner_id'], false, $user);
                                     $alert_res['full_link'] = module_user::link_open_contact($task['owner_id'], true, $user);
                                     $alert_res['type'] = _l('Contact');
                                 } else {
                                     $alert_res['link'] = module_user::link_open($task['owner_id'], false, $user);
                                     $alert_res['full_link'] = module_user::link_open($task['owner_id'], true, $user);
                                 }
                                 break;
                             case 'invoice':
                                 $invoice_data = module_invoice::get_invoice($task['owner_id'], true);
                                 if (!$invoice_data || !isset($invoice_data['invoice_id']) || $invoice_data['invoice_id'] != $task['owner_id']) {
                                     continue 2;
                                 }
                                 $alert_res['link'] = module_invoice::link_open($task['owner_id'], false, $invoice_data);
                                 $alert_res['full_link'] = module_invoice::link_open($task['owner_id'], true, $invoice_data);
                                 break;
                             case 'quote':
                                 $quote_data = module_quote::get_quote($task['owner_id'], true);
                                 if (!$quote_data || !isset($quote_data['quote_id']) || $quote_data['quote_id'] != $task['owner_id']) {
                                     continue 2;
                                 }
                                 $alert_res['link'] = module_quote::link_open($task['owner_id'], false, $quote_data);
                                 $alert_res['full_link'] = module_quote::link_open($task['owner_id'], true, $quote_data);
                                 break;
                             case 'website':
                                 $website_data = module_website::get_website($task['owner_id']);
                                 if (!$website_data || !isset($website_data['website_id']) || $website_data['website_id'] != $task['owner_id']) {
                                     continue 2;
                                 }
                                 $alert_res['link'] = module_website::link_open($task['owner_id'], false);
                                 $alert_res['full_link'] = module_website::link_open($task['owner_id'], true);
                                 break;
                             case 'customer':
                                 $customer_data = module_customer::get_customer($task['owner_id']);
                                 if (!$customer_data || !isset($customer_data['customer_id']) || $customer_data['customer_id'] != $task['owner_id']) {
                                     continue 2;
                                 }
                                 $alert_res['link'] = module_customer::link_open($task['owner_id'], false, $customer_data);
                                 $alert_res['full_link'] = module_customer::link_open($task['owner_id'], true, $customer_data);
                                 break;
                             case 'vendor':
                                 $vendor_data = module_vendor::get_vendor($task['owner_id']);
                                 if (!$vendor_data || !isset($vendor_data['vendor_id']) || $vendor_data['vendor_id'] != $task['owner_id']) {
                                     continue 2;
                                 }
                                 $alert_res['link'] = module_vendor::link_open($task['owner_id'], false, $vendor_data);
                                 $alert_res['full_link'] = module_vendor::link_open($task['owner_id'], true, $vendor_data);
                                 break;
                             case 'job':
                                 $job_data = module_job::get_job($task['owner_id']);
                                 if (!$job_data || !isset($job_data['job_id']) || $job_data['job_id'] != $task['owner_id']) {
                                     continue 2;
                                 }
                                 $alert_res['link'] = module_job::link_open($task['owner_id'], false, $job_data);
                                 $alert_res['full_link'] = module_job::link_open($task['owner_id'], true, $job_data);
                                 break;
                                 // todo - add others.
                         }
                         $alert_res['name'] = $task['note'];
                         $alert_res['date'] = print_date($alert_res['date']);
                         $alert_res['time'] = $task['note_time'];
                         $alerts[] = $alert_res;
                     }
                 }
             }
             return $alerts;
             break;
             /*case "note_list":
             				if($owner_id && $owner_id != 'new'){
             
             					$note_items = $this->get_notes(array("owner_table"=>$owner_table,"owner_id"=>$owner_id));
             					foreach($note_items as &$note_item){
             						// do it in loop here because of $this issues in static method below.
             						// instead of include file below.
             						$note_item['html'] = $this->print_note($note_item['note_id']);
             					}
             					include("pages/note_list.php");
             				}else{
             					echo 'Please save first before creating notes.';
             				}
             				break;*/
         /*case "note_list":
         				if($owner_id && $owner_id != 'new'){
         
         					$note_items = $this->get_notes(array("owner_table"=>$owner_table,"owner_id"=>$owner_id));
         					foreach($note_items as &$note_item){
         						// do it in loop here because of $this issues in static method below.
         						// instead of include file below.
         						$note_item['html'] = $this->print_note($note_item['note_id']);
         					}
         					include("pages/note_list.php");
         				}else{
         					echo 'Please save first before creating notes.';
         				}
         				break;*/
         case "note_delete":
             // find the key we are saving this address against.
             $owner_id = (int) $key_value;
             if (!$owner_id || $owner_id == 'new') {
                 // find one in the post data.
                 if (isset($_REQUEST[$key_name])) {
                     $owner_id = $_REQUEST[$key_name];
                 }
             }
             $note_hash = md5($owner_id . '|' . $owner_table);
             // just for posting unique arrays.
             if ($owner_table && $owner_id) {
                 $this->note_delete($owner_table, $owner_id);
             }
             break;
     }
 }
Example #2
0
 public function handle_hook($hook, &$calling_module = false)
 {
     switch ($hook) {
         case "home_alerts":
             $cache_key = "home_alerts_" . module_security::get_loggedin_id();
             $cache_timeout = module_config::c('cache_objects', 60);
             $alerts = array();
             if ($this->can_i('edit', 'Invoices') && module_config::c('invoice_alerts', 1)) {
                 // find any invoices that are past the due date and dont have a paid date.
                 $key = _l('Invoice Payment Due');
                 $key_overdue = _l('Invoice Payment Overdue');
                 if (class_exists('module_dashboard', false)) {
                     module_dashboard::register_group($key, array('columns' => array('invoice' => _l('Invoice #'), 'customer' => _l('Customer'), 'job' => _l('Job Title'), 'website' => module_config::c('project_name_single', 'Website'), 'last_sent' => _l('Last Sent'), 'date' => _l('Due Date'), 'days' => _l('Day Count'))));
                     module_dashboard::register_group($key_overdue, array('columns' => array('invoice' => _l('Invoice #'), 'customer' => _l('Customer'), 'job' => _l('Job Title'), 'website' => module_config::c('project_name_single', 'Website'), 'last_sent' => _l('Last Sent'), 'date' => _l('Due Date'), 'auto_email_date' => _l('Automatic Email'), 'days' => _l('Day Count'))));
                 }
                 if ($cached_alerts = module_cache::get('invoice', $cache_key . $key)) {
                     $alerts = array_merge($alerts, $cached_alerts);
                 } else {
                     $this_alerts = array();
                     /*$sql = "SELECT * FROM `"._DB_PREFIX."invoice` p ";
                       $sql .= " WHERE p.date_due != '0000-00-00' AND p.date_due <= '".date('Y-m-d',strtotime('+'.module_config::c('alert_days_in_future',5).' days'))."' AND p.date_paid = '0000-00-00'";
                       $invoice_items = qa($sql);*/
                     module_debug::log(array('title' => 'Invoice Home Alerts: ', 'data' => " starting: " . $key));
                     $invoices = self::get_invoices(array(), array('custom_where' => " AND u.date_due != '0000-00-00' AND u.date_due <= '" . date('Y-m-d', strtotime('+' . module_config::c('alert_days_in_future', 5) . ' days')) . "' AND u.date_paid = '0000-00-00'"));
                     foreach ($invoices as $invoice) {
                         // needs 'overdue' and stuff which are unfortunately calculated.
                         $invoice = self::get_invoice($invoice['invoice_id']);
                         if (!$invoice || $invoice['invoice_id'] != $invoice['invoice_id']) {
                             continue;
                         }
                         if (isset($invoice['date_cancel']) && $invoice['date_cancel'] != '0000-00-00') {
                             continue;
                         }
                         // is this invoice overdue?
                         if ($invoice['overdue']) {
                             $alert_res = process_alert($invoice['date_due'], $key_overdue);
                         } else {
                             $alert_res = process_alert($invoice['date_due'], $key);
                         }
                         if ($alert_res) {
                             $alert_res['link'] = $this->link_open($invoice['invoice_id'], false, $invoice);
                             $alert_res['name'] = $invoice['name'];
                             if ($invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') {
                                 $secs = date("U") - date("U", strtotime($invoice['date_sent']));
                                 $days = $secs / 86400;
                                 $days = floor($days);
                                 $alert_res['last_sent'] = _l('%s days ago', $days);
                             }
                             // new dashboard alert layout here:
                             $alert_res['time'] = strtotime($invoice['date_due']);
                             if ($invoice['overdue']) {
                                 $alert_res['group'] = $key_overdue;
                                 // work out when to send invoice overdue email
                                 if ($invoice['overdue_email_auto']) {
                                     // if you change this calculation make sure it is changed in the cron job below too
                                     if ($invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00' && strtotime($invoice['date_sent']) > strtotime($invoice['date_due'])) {
                                         // we have sent a reminder already (todo: this isn't correct logic, fix it up so it can tell for sure if we have sent a reminder already or not (eg: look through email history table)
                                         $last_invoice_sent = strtotime($invoice['date_sent']);
                                         if (module_config::c('overdue_email_auto_days_repeat', 7) <= 0) {
                                             continue;
                                             // skip sendin repeat reminders.
                                         }
                                         $send_email_on = strtotime('+' . module_config::c('overdue_email_auto_days_repeat', 7) . ' days', $last_invoice_sent);
                                         $alert_res['auto_email_date'] = print_date($send_email_on);
                                     } else {
                                         if ($invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') {
                                             $invoice_is_due = strtotime($invoice['date_due']);
                                             $send_email_on = strtotime('+' . module_config::c('overdue_email_auto_days', 3) . ' days', $invoice_is_due);
                                             $alert_res['auto_email_date'] = print_date($send_email_on);
                                         } else {
                                             $alert_res['auto_email_date'] = _l('N/A');
                                         }
                                     }
                                 } else {
                                     $alert_res['auto_email_date'] = _l('N/A');
                                 }
                             } else {
                                 $alert_res['group'] = $key;
                             }
                             $alert_res['invoice'] = $this->link_open($invoice['invoice_id'], true, $invoice);
                             $alert_res['job'] = '';
                             $alert_res['website'] = '';
                             foreach ($invoice['job_ids'] as $job_id) {
                                 $job = module_job::get_job($job_id);
                                 $alert_res['job'] .= module_job::link_open($job_id, true, $job) . ' ';
                                 $alert_res['website'] .= $job['website_id'] ? module_website::link_open($job['website_id'], true) . ' ' : '';
                             }
                             if (isset($invoice['website_id'])) {
                                 $alert_res['website'] .= $invoice['website_id'] ? module_website::link_open($invoice['website_id'], true) . ' ' : '';
                             }
                             $alert_res['customer'] = $invoice['customer_id'] ? module_customer::link_open($invoice['customer_id'], true) : _l('N/A');
                             $alert_res['date'] = print_date($alert_res['time']);
                             $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                             $this_alerts[] = $alert_res;
                         }
                     }
                     module_cache::put('invoice', $cache_key . $key, $this_alerts, $cache_timeout);
                     $alerts = array_merge($alerts, $this_alerts);
                 }
             }
             if (module_config::c('invoice_send_alerts', 1)) {
                 if ($this->can_i('edit', 'Invoices')) {
                     // find any invoices that haven't been sent
                     $key = _l('Invoice Not Sent');
                     if (class_exists('module_dashboard', false)) {
                         module_dashboard::register_group($key, array('columns' => array('invoice' => _l('Invoice #'), 'customer' => _l('Customer'), 'job' => _l('Job Title'), 'website' => module_config::c('project_name_single', 'Website'), 'date' => _l('Invoice Date'), 'days' => _l('Day Count'))));
                     }
                     if ($cached_alerts = module_cache::get('invoice', $cache_key . $key)) {
                         $alerts = array_merge($alerts, $cached_alerts);
                     } else {
                         module_debug::log(array('title' => 'Invoice Home Alerts: ', 'data' => " starting: " . $key));
                         $this_alerts = array();
                         $sql = "SELECT * FROM `" . _DB_PREFIX . "invoice` p ";
                         $sql .= " WHERE p.date_sent = '0000-00-00' AND p.date_paid = '0000-00-00'";
                         $invoice_items = qa($sql);
                         foreach ($invoice_items as $invoice_item) {
                             $invoice = self::get_invoice($invoice_item['invoice_id']);
                             if (!$invoice || $invoice['invoice_id'] != $invoice_item['invoice_id']) {
                                 continue;
                             }
                             $alert_res = process_alert($invoice['date_create'] != '0000-00-00' ? $invoice['date_create'] : date('Y-m-d'), $key);
                             if ($alert_res) {
                                 $alert_res['link'] = $this->link_open($invoice_item['invoice_id']);
                                 $alert_res['name'] = $invoice_item['name'];
                                 // new dashboard alert layout here:
                                 $alert_res['time'] = strtotime($invoice_item['date_create']);
                                 $alert_res['group'] = $key;
                                 $alert_res['invoice'] = $this->link_open($invoice_item['invoice_id'], true, $invoice);
                                 $alert_res['job'] = '';
                                 $alert_res['website'] = '';
                                 foreach ($invoice['job_ids'] as $job_id) {
                                     $job = module_job::get_job($job_id);
                                     $alert_res['job'] .= module_job::link_open($job_id, true, $job) . ' ';
                                     $alert_res['website'] .= $job['website_id'] ? module_website::link_open($job['website_id'], true) . ' ' : '';
                                 }
                                 if (isset($invoice['website_id'])) {
                                     $alert_res['website'] .= $invoice['website_id'] ? module_website::link_open($invoice['website_id'], true) . ' ' : '';
                                 }
                                 $alert_res['customer'] = $invoice['customer_id'] ? module_customer::link_open($invoice['customer_id'], true) : _l('N/A');
                                 $alert_res['date'] = print_date($alert_res['time']);
                                 $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                                 $this_alerts[] = $alert_res;
                             }
                         }
                         module_cache::put('invoice', $cache_key . $key, $this_alerts, $cache_timeout);
                         $alerts = array_merge($alerts, $this_alerts);
                     }
                 }
             }
             if ($this->can_i('edit', 'Invoices') && module_config::c('invoice_renew_alerts', 1)) {
                 // find any invoices that have a renew date soon and have not been renewed.
                 $key = _l('Invoice Renewal Pending');
                 $key_auto = _l('Automatic Invoice Renewal Pending');
                 if (class_exists('module_dashboard', false)) {
                     module_dashboard::register_group($key, array('columns' => array('invoice' => _l('Invoice #'), 'customer' => _l('Customer'), 'job' => _l('Job Title'), 'website' => module_config::c('project_name_single', 'Website'), 'period' => _l('Period'), 'date_create' => _l('Created Date'), 'date' => _l('Renewal Date'), 'days' => _l('Day Count'))));
                     module_dashboard::register_group($key_auto, array('columns' => array('invoice' => _l('Invoice #'), 'customer' => _l('Customer'), 'job' => _l('Job Title'), 'website' => module_config::c('project_name_single', 'Website'), 'period' => _l('Period'), 'date_create' => _l('Created Date'), 'date' => _l('Renewal Date'), 'auto_email' => _l('Automatic Email'), 'days' => _l('Day Count'))));
                 }
                 if ($cached_alerts = module_cache::get('invoice', $cache_key . $key)) {
                     $alerts = array_merge($alerts, $cached_alerts);
                 } else {
                     module_debug::log(array('title' => 'Invoice Home Alerts: ', 'data' => " starting: " . $key));
                     $this_alerts = array();
                     $sql = "SELECT p.* FROM `" . _DB_PREFIX . "invoice` p ";
                     $sql .= " WHERE p.date_renew != '0000-00-00'";
                     $sql .= " AND p.date_renew <= '" . date('Y-m-d', strtotime('+' . module_config::c('alert_days_in_future', 5) . ' days')) . "'";
                     $sql .= " AND (p.renew_invoice_id IS NULL OR p.renew_invoice_id = 0)";
                     $res = qa($sql);
                     foreach ($res as $r) {
                         $invoice = self::get_invoice($r['invoice_id']);
                         if (!$invoice || $invoice['invoice_id'] != $r['invoice_id']) {
                             continue;
                         }
                         if (isset($invoice['date_cancel']) && $invoice['date_cancel'] != '0000-00-00') {
                             continue;
                         }
                         if ($invoice['renew_auto']) {
                             // todo - ignore unpaid invoices because they will not be automatically renewed by the cron
                             $alert_res = process_alert($r['date_renew'], $key_auto);
                         } else {
                             $alert_res = process_alert($r['date_renew'], $key);
                         }
                         if ($alert_res) {
                             $alert_res['link'] = $this->link_open($r['invoice_id']);
                             $alert_res['name'] = $r['name'];
                             // work out renewal period
                             $alert_res['period'] = _l('N/A');
                             if ($r['date_create'] && $r['date_create'] != '0000-00-00') {
                                 $time_diff = strtotime($r['date_renew']) - strtotime($r['date_create']);
                                 if ($time_diff > 0) {
                                     $diff_type = 'day';
                                     $days = round($time_diff / 86400);
                                     if ($days >= 365) {
                                         $time_diff = round($days / 365, 1);
                                         $diff_type = 'year';
                                     } else {
                                         $time_diff = $days;
                                     }
                                     $alert_res['period'] = ' ' . _l('%s %s renewal', $time_diff, $diff_type);
                                 }
                             }
                             // new dashboard alert layout here:
                             $alert_res['time'] = strtotime($invoice['date_renew']);
                             if ($invoice['renew_auto']) {
                                 $alert_res['group'] = $key_auto;
                                 $alert_res['auto_email'] = $r['renew_email'] ? _l('Yes') : _l('No');
                             } else {
                                 $alert_res['group'] = $key;
                             }
                             $alert_res['invoice'] = $this->link_open($invoice['invoice_id'], true, $invoice);
                             $alert_res['job'] = '';
                             $alert_res['website'] = '';
                             foreach ($invoice['job_ids'] as $job_id) {
                                 $job = module_job::get_job($job_id);
                                 $alert_res['job'] .= module_job::link_open($job_id, true, $job) . ' ';
                                 $alert_res['website'] .= $job['website_id'] ? module_website::link_open($job['website_id'], true) . ' ' : '';
                             }
                             if (isset($invoice['website_id'])) {
                                 $alert_res['website'] .= $invoice['website_id'] ? module_website::link_open($invoice['website_id'], true) . ' ' : '';
                             }
                             $alert_res['customer'] = $invoice['customer_id'] ? module_customer::link_open($invoice['customer_id'], true) : _l('N/A');
                             $alert_res['date_create'] = print_date($invoice['date_create']);
                             $alert_res['date'] = print_date($invoice['date_renew']);
                             $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                             $this_alerts[] = $alert_res;
                         }
                     }
                     module_cache::put('invoice', $cache_key . $key, $this_alerts, $cache_timeout);
                     $alerts = array_merge($alerts, $this_alerts);
                 }
             }
             return $alerts;
             break;
     }
     return false;
 }
Example #3
0
if (!is_array($widget_sort_json)) {
    $widget_sort_json = array();
}
$widget_sort_order = array();
$widget_sort_page_order = 1;
foreach ($widget_sort_json as $id => $vals) {
    $bits = explode('|', $vals);
    if (count($bits) == 3) {
        $widget_sort_order[$bits[2]] = array('column' => $bits[0], 'column_number' => $bits[1], 'page_order' => $widget_sort_page_order++);
    }
}
$widget_sort_id = 1;
// then display the alerts list.
if (module_config::c('dashboard_new_layout', 1) && class_exists('module_dashboard', false) && module_security::can_user(module_security::get_loggedin_id(), 'Show Dashboard Alerts')) {
    ob_start();
    module_dashboard::output_dashboard_alerts(module_config::c('dashboard_alerts_ajax', 1));
    array_unshift($home_widgets, array('columns' => isset($widget_sort_order[$widget_sort_id]['column']) ? $widget_sort_order[$widget_sort_id]['column'] : 1, 'column_number' => isset($widget_sort_order[$widget_sort_id]['column_number']) ? $widget_sort_order[$widget_sort_id]['column_number'] : false, 'page_order' => isset($widget_sort_order[$widget_sort_id]['page_order']) ? $widget_sort_order[$widget_sort_id]['page_order'] : false, 'sort_id' => $widget_sort_id++, 'title' => _l('Alerts'), 'content' => ob_get_clean()));
}
array_unshift($home_widgets, array('columns' => isset($widget_sort_order[$widget_sort_id]['column']) ? $widget_sort_order[$widget_sort_id]['column'] : 1, 'column_number' => isset($widget_sort_order[$widget_sort_id]['column_number']) ? $widget_sort_order[$widget_sort_id]['column_number'] : false, 'page_order' => isset($widget_sort_order[$widget_sort_id]['page_order']) ? $widget_sort_order[$widget_sort_id]['page_order'] : false, 'sort_id' => $widget_sort_id++, 'title' => _l('Home Page'), 'content' => _DEMO_MODE ? strip_tags($template->replace_content()) : $template->replace_content()));
// now grab the widgets from the various modules and add those in:
$widget_columns_counter = array();
foreach ($home_widgets as $module_widgets) {
    if (isset($module_widgets['id']) || isset($module_widgets['sort_id'])) {
        $module_widgets = array($module_widgets);
    }
    foreach ($module_widgets as $module_widget) {
        if (isset($widget_sort_order[$widget_sort_id]['column'])) {
            $module_widget['columns'] = $widget_sort_order[$widget_sort_id]['column'];
        }
        if (isset($widget_sort_order[$widget_sort_id]['column_number'])) {
            $module_widget['column_number'] = $widget_sort_order[$widget_sort_id]['column_number'];
Example #4
0
 public function handle_hook($hook)
 {
     switch ($hook) {
         case "invoice_paid":
             $foo = func_get_args();
             $invoice_id = (int) $foo[1];
             if ($invoice_id > 0) {
                 // see if any subscriptions match this invoice.
                 //module_cache::clear_cache();
                 $invoice = module_invoice::get_invoice($invoice_id);
                 $subscription = get_single('subscription_history', 'invoice_id', $invoice_id);
                 if ($subscription) {
                     // mark subscription as paid and move onto the next date.
                     update_insert('subscription_history_id', $subscription['subscription_history_id'], 'subscription_history', array('paid_date' => $invoice['date_paid']));
                     $subscription_owner = get_single('subscription_owner', 'subscription_owner_id', $subscription['subscription_owner_id']);
                     $this->update_next_due_date($subscription['subscription_id'], $subscription_owner['owner_table'], $subscription_owner['owner_id']);
                     /*if($subscription['customer_id']){
                           $this->update_next_due_date($subscription['subscription_id'],$subscription['customer_id'],true);
                       }else{
                           $this->update_next_due_date($subscription['subscription_id'],$subscription['member_id'],false);
                       }*/
                 }
             }
             break;
         case "home_alerts":
             $alerts = array();
             if (module_config::c('subscription_alerts', 1) && self::can_i('view', 'Subscriptions')) {
                 // find renewals due in a certain time.
                 $time = date('Y-m-d', strtotime('+' . module_config::c('alert_days_in_future', 5) . ' days'));
                 $key = _l('Subscription Due');
                 if (class_exists('module_dashboard', false)) {
                     module_dashboard::register_group($key, array('columns' => array('full_link' => _l('Name'), 'type' => _l('Type'), 'subscription_name' => _l('Subscription'), 'automatic_renew' => _l('Automatic Renew'), 'automatic_email' => _l('Automatic Email'), 'next_due_date' => _l('Next Due Date'), 'days' => _l('Day Count'))));
                 }
                 $db_fields = get_fields('subscription');
                 $sql = "SELECT s.*, so.* ";
                 if (isset($db_fields['invoice_prior_days'])) {
                     $sql .= ", DATE_SUB(so.next_due_date, INTERVAL `invoice_prior_days` DAY) AS next_generation_date ";
                 }
                 $sql .= " FROM `" . _DB_PREFIX . "subscription_owner` so ";
                 $sql .= " LEFT JOIN `" . _DB_PREFIX . "subscription` s USING (subscription_id)";
                 if (isset($db_fields['invoice_prior_days'])) {
                     $sql .= " WHERE DATE_SUB(so.next_due_date, INTERVAL `invoice_prior_days` DAY) <= '" . $time . "'";
                 } else {
                     $sql .= " WHERE so.next_due_date <= '" . $time . "'";
                 }
                 $sql .= " AND so.`deleted` = 0";
                 //                    echo $sql;
                 $items = qa($sql);
                 foreach ($items as $item) {
                     //                        echo '<hr>';print_r($item);echo '<hr>';
                     $alert_res = process_alert(isset($item['next_generation_date']) ? $item['next_generation_date'] : $item['next_due_date'], $key);
                     if ($alert_res) {
                         switch ($item['owner_table']) {
                             case 'member':
                                 $permission_check = module_member::get_member($item['owner_id']);
                                 if (!$permission_check || $permission_check['member_id'] != $item['owner_id'] || !module_member::can_i('view', 'Members')) {
                                     continue 2;
                                 }
                                 $alert_res['full_link'] = module_member::link_open($item['owner_id'], true);
                                 break;
                             case 'website':
                                 $permission_check = module_website::get_website($item['owner_id']);
                                 if (!$permission_check || $permission_check['website_id'] != $item['owner_id'] || !module_website::can_i('view', 'Websites')) {
                                     continue 2;
                                 }
                                 $alert_res['full_link'] = module_website::link_open($item['owner_id'], true);
                                 break;
                             case 'customer':
                                 $permission_check = module_customer::get_customer($item['owner_id']);
                                 if (!$permission_check || $permission_check['customer_id'] != $item['owner_id'] || !module_customer::can_i('view', 'Customers')) {
                                     continue 2;
                                 }
                                 $alert_res['full_link'] = module_customer::link_open($item['owner_id'], true);
                                 break;
                         }
                         $alert_res['name'] = $item['name'];
                         $alert_res['link'] = '#';
                         if (preg_match('@href="([^"]+)"@', $alert_res['full_link'], $link_match)) {
                             $alert_res['link'] = $link_match[1];
                         }
                         $alert_res['type'] = $item['owner_table'];
                         $alert_res['subscription_name'] = module_subscription::link_open($item['subscription_id'], true);
                         $alert_res['next_due_date'] = isset($item['next_generation_date']) ? print_date($item['next_generation_date']) : print_date($item['next_due_date']);
                         $alert_res['automatic_renew'] = $item['automatic_renew'] ? _l('Yes') : _l('No');
                         $alert_res['automatic_email'] = $item['automatic_email'] ? _l('Yes') : _l('No');
                         $alerts[] = $alert_res;
                     }
                 }
             }
             return $alerts;
             break;
     }
 }
Example #5
0
 public function handle_hook($hook, &$calling_module = false, $show_all = false)
 {
     switch ($hook) {
         case 'dashboard_widgets':
             // see finance for example of widget usage.
             break;
         case "home_alerts":
             $cache_timeout = module_config::c('cache_objects', 60);
             $cache_key = 'home_alerts_' . module_security::get_loggedin_id();
             $alerts = array();
             /*if(module_config::c('job_task_alerts',1)){
                   // find out any overdue tasks or jobs.
                   $sql = "SELECT t.*,p.name AS job_name FROM `"._DB_PREFIX."task` t ";
                   $sql .= " LEFT JOIN `"._DB_PREFIX."job` p USING (job_id) ";
                   $sql .= " WHERE t.date_due != '0000-00-00' AND t.date_due <= '".date('Y-m-d',strtotime('+'.module_config::c('alert_days_in_future',5).' days'))."' AND ((t.hours = 0 AND t.completed = 0) OR t.completed < t.hours)";
                   $tasks = qa($sql);
                   foreach($tasks as $task){
                       $alert_res = process_alert($task['date_due'], _l('Job: %s',$task['job_name']));
                       if($alert_res){
                           $alert_res['link'] = $this->link_open($task['job_id']);
                           $alert_res['name'] = $task['description'];
                           $alerts[] = $alert_res;
                       }
                   }
               }*/
             if ($show_all || module_config::c('job_alerts', 1)) {
                 // find any jobs that are past the due date and dont have a finished date.
                 $key = _l('Incomplete Job');
                 if (class_exists('module_dashboard', false)) {
                     $columns = array('job' => _l('Job Title'), 'customer' => _l('Customer'), 'website' => module_config::c('project_name_single', 'Website'), 'progress' => _l('Job Progress'), 'assigned_staff' => _l('Staff'), 'date' => _l('Due Date'), 'days' => _l('Day Count'));
                     if (!class_exists('module_website', false) || !module_website::is_plugin_enabled()) {
                         unset($columns['website']);
                     }
                     if (!module_customer::can_i('view', 'Customers')) {
                         unset($columns['customer']);
                     }
                     module_dashboard::register_group($key, array('columns' => $columns, 'sort' => array('time' => 'DESC')));
                 }
                 if ($cached_alerts = module_cache::get('job', $cache_key . $key)) {
                     $alerts = array_merge($alerts, $cached_alerts);
                 } else {
                     module_debug::log(array('title' => 'Job Home Alerts: ', 'data' => " starting: " . $key));
                     $this_alerts = array();
                     //                        $sql = "SELECT * FROM `"._DB_PREFIX."job` p ";
                     //                        $sql .= " WHERE p.date_due != '0000-00-00' AND p.date_due <= '".date('Y-m-d',strtotime('+'.module_config::c('alert_days_in_future',5).' days'))."' AND p.date_completed = '0000-00-00'";
                     //                        $tasks = qa($sql);
                     $jobs = self::get_jobs(array(), array('custom_where' => " AND u.date_due != '0000-00-00' AND u.date_due <= '" . date('Y-m-d', strtotime('+' . module_config::c('alert_days_in_future', 5) . ' days')) . "' AND u.date_completed = '0000-00-00'"));
                     foreach ($jobs as $job_data) {
                         // permission check:
                         //                            $job_data = self::get_job($task['job_id']);
                         //                            if(!$job_data || $job_data['job_id']!=$task['job_id'])continue;
                         $alert_res = process_alert($job_data['date_due'], 'temp');
                         if ($alert_res) {
                             $alert_res['link'] = $this->link_open($job_data['job_id'], false, $job_data);
                             $alert_res['name'] = $job_data['name'];
                             // new dashboard alert layout here:
                             $alert_res['time'] = strtotime($alert_res['date']);
                             $alert_res['group'] = $key;
                             $alert_res['job'] = $this->link_open($job_data['job_id'], true, $job_data);
                             $alert_res['customer'] = $job_data['customer_id'] ? module_customer::link_open($job_data['customer_id'], true) : _l('N/A');
                             $alert_res['website'] = $job_data['website_id'] ? module_website::link_open($job_data['website_id'], true) : _l('N/A');
                             $alert_res['assigned_staff'] = $job_data['user_id'] ? module_user::link_open($job_data['user_id'], true) : _l('N/A');
                             $alert_res['progress'] = $job_data['total_percent_complete'] * 100 . '%';
                             $alert_res['date'] = print_date($alert_res['date']);
                             $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                             $this_alerts['jobincomplete' . $job_data['job_id']] = $alert_res;
                         }
                     }
                     module_debug::log(array('title' => 'Job Home Alerts: ', 'data' => " starting: " . $key . ' #2'));
                     // find any jobs that haven't started yet (ie: have a start date, but no completed tasks)
                     //                        $sql = "SELECT * FROM `"._DB_PREFIX."job` p ";
                     //                        $sql .= " WHERE p.date_completed = '0000-00-00' AND p.date_start != '0000-00-00' AND p.date_start <= '".date('Y-m-d',strtotime('+'.module_config::c('alert_days_in_future',5).' days'))."'";
                     //                        $jobs = qa($sql);
                     $jobs = self::get_jobs(array(), array('custom_where' => " AND u.date_completed = '0000-00-00' AND u.date_due = '0000-00-00' AND u.date_start != '0000-00-00' AND u.date_start <= '" . date('Y-m-d', strtotime('+' . module_config::c('alert_days_in_future', 5) . ' days')) . "'"));
                     foreach ($jobs as $job_data) {
                         //$job_data = self::get_job($job['job_id']);
                         //if(!$job_data || $job_data['job_id']!=$job['job_id'])continue;
                         /*$job_started=true;
                                                     if(module_config::c('job_start_alerts_old',0)){
                                                         $tasks = self::get_tasks($job['job_id']);
                                                         $job_started = false;
                                                         foreach($tasks as $task){
                                                             if($task['fully_completed']){
                                                                 $job_started = true;
                                                                 break;
                                                             }
                                                         }
                                                     }
                                                     if(!$job_started){
                         
                                                         $alert_res = process_alert($job['date_start'], _l('Job Not Started'));
                                                         if($alert_res){
                                                             $alert_res['link'] = $this->link_open($job['job_id'],false,$job);
                                                             $alert_res['name'] = $job['name'];
                                                             $alerts[] = $alert_res;
                                                         }
                                                     }else{*/
                         // do the same alert as above.
                         if (!isset($this_alerts['jobincomplete' . $job_data['job_id']])) {
                             $alert_res = process_alert($job_data['date_start'], $key);
                             if ($alert_res) {
                                 $alert_res['link'] = $this->link_open($job_data['job_id'], false, $job_data);
                                 $alert_res['name'] = $job_data['name'];
                                 // new dashboard alert layout here:
                                 $alert_res['time'] = strtotime($alert_res['date']);
                                 $alert_res['group'] = $key;
                                 $alert_res['job'] = $this->link_open($job_data['job_id'], true, $job_data);
                                 $alert_res['customer'] = $job_data['customer_id'] ? module_customer::link_open($job_data['customer_id'], true) : _l('N/A');
                                 $alert_res['website'] = $job_data['website_id'] ? module_website::link_open($job_data['website_id'], true) : _l('N/A');
                                 $alert_res['assigned_staff'] = $job_data['user_id'] ? module_user::link_open($job_data['user_id'], true) : _l('N/A');
                                 $alert_res['progress'] = $job_data['total_percent_complete'] * 100 . '%';
                                 $alert_res['date'] = print_date($alert_res['date']);
                                 $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                                 $this_alerts['jobincomplete' . $job_data['job_id']] = $alert_res;
                             }
                         }
                         /* }*/
                     }
                     module_cache::put('job', $cache_key . $key, $this_alerts, $cache_timeout);
                     $alerts = array_merge($alerts, $this_alerts);
                 }
             }
             if (module_config::c('job_allow_quotes', 0) && ($show_all || module_config::c('job_quote_alerts', 1))) {
                 // find any jobs that dont have a start date yet.
                 $key = _l('Pending Job Quote');
                 if (class_exists('module_dashboard', false)) {
                     $columns = array('job' => _l('Job Title'), 'customer' => _l('Customer'), 'website' => module_config::c('project_name_single', 'Website'), 'assigned_staff' => _l('Staff'), 'date' => _l('Quoted Date'), 'days' => _l('Day Count'));
                     if (!class_exists('module_website', false) || !module_website::is_plugin_enabled()) {
                         unset($columns['website']);
                     }
                     if (!module_customer::can_i('view', 'Customers')) {
                         unset($columns['customer']);
                     }
                     module_dashboard::register_group($key, array('columns' => $columns));
                 }
                 if ($cached_alerts = module_cache::get('job', $cache_key . $key)) {
                     $alerts = array_merge($alerts, $cached_alerts);
                 } else {
                     module_debug::log(array('title' => 'Job Home Alerts: ', 'data' => " starting: " . $key));
                     $this_alerts = array();
                     //$sql = "SELECT * FROM `"._DB_PREFIX."job` p ";
                     //$sql .= " WHERE p.date_quote != '0000-00-00' AND p.date_start = '0000-00-00'";
                     //$tasks = qa($sql);
                     $jobs = self::get_jobs(array('date_start' => '0000-00-00', 'date_quote' => '!0000-00-00'));
                     foreach ($jobs as $job_data) {
                         //$job_data = self::get_job($task['job_id']);
                         //if(!$job_data || $job_data['job_id']!=$task['job_id'])continue;
                         $alert_res = process_alert($job_data['date_quote'], $key);
                         if ($alert_res) {
                             $alert_res['link'] = $this->link_open($job_data['job_id'], false, $job_data);
                             $alert_res['name'] = $job_data['name'];
                             // new dashboard alert layout here:
                             $alert_res['time'] = strtotime($job_data['date_quote']);
                             $alert_res['group'] = $key;
                             $alert_res['job'] = $this->link_open($job_data['job_id'], true, $job_data);
                             $alert_res['customer'] = $job_data['customer_id'] ? module_customer::link_open($job_data['customer_id'], true) : _l('N/A');
                             $alert_res['website'] = $job_data['website_id'] ? module_website::link_open($job_data['website_id'], true) : _l('N/A');
                             $alert_res['assigned_staff'] = $job_data['user_id'] ? module_user::link_open($job_data['user_id'], true) : _l('N/A');
                             //$alert_res['progress'] = ($job_data['total_percent_complete'] * 100).'%';
                             $alert_res['date'] = print_date($alert_res['date']);
                             $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                             $this_alerts[] = $alert_res;
                         }
                     }
                     module_cache::put('job', $cache_key . $key, $this_alerts, $cache_timeout);
                     $alerts = array_merge($alerts, $this_alerts);
                 }
             }
             if ($show_all || module_config::c('job_invoice_alerts', 1)) {
                 // find any completed jobs that don't have an invoice.
                 $key = _l('Please Generate Invoice');
                 if (class_exists('module_dashboard', false)) {
                     $columns = array('job' => _l('Job Title'), 'customer' => _l('Customer'), 'website' => module_config::c('project_name_single', 'Website'), 'assigned_staff' => _l('Staff'), 'invoicable_amount' => _l('Invoiceable Amount'), 'date' => _l('Completed Date'), 'days' => _l('Day Count'));
                     if (!class_exists('module_website', false) || !module_website::is_plugin_enabled()) {
                         unset($columns['website']);
                     }
                     if (!module_customer::can_i('view', 'Customers')) {
                         unset($columns['customer']);
                     }
                     module_dashboard::register_group($key, array('columns' => $columns));
                 }
                 if ($cached_alerts = module_cache::get('job', $cache_key . $key)) {
                     $alerts = array_merge($alerts, $cached_alerts);
                 } else {
                     module_debug::log(array('title' => 'Job Home Alerts: ', 'data' => " starting: " . $key));
                     $this_alerts = array();
                     $sql = "SELECT j.* FROM `" . _DB_PREFIX . "job` j ";
                     $from = " LEFT JOIN `" . _DB_PREFIX . "task` t USING (job_id) ";
                     $from .= " LEFT JOIN `" . _DB_PREFIX . "invoice_item` ii ON t.task_id = ii.task_id ";
                     $from .= " LEFT JOIN `" . _DB_PREFIX . "invoice` i ON ii.invoice_id = i.invoice_id  ";
                     $where = " WHERE i.invoice_id IS NULL AND (j.date_completed != '0000-00-00')";
                     switch (self::get_job_access_permissions()) {
                         case _JOB_ACCESS_ALL:
                             break;
                         case _JOB_ACCESS_ASSIGNED:
                             // only assigned jobs!
                             //$from .= " LEFT JOIN `"._DB_PREFIX."task` t ON u.job_id = t.job_id ";
                             $where .= " AND (j.user_id = " . (int) module_security::get_loggedin_id() . " OR t.user_id = " . (int) module_security::get_loggedin_id() . ")";
                             break;
                         case _JOB_ACCESS_CUSTOMER:
                             // tie in with customer permissions to only get jobs from customers we can access.
                             $customers = module_customer::get_customers();
                             if (count($customers)) {
                                 $where .= " AND j.customer_id IN ( ";
                                 foreach ($customers as $customer) {
                                     $where .= $customer['customer_id'] . ', ';
                                 }
                                 $where = rtrim($where, ', ');
                                 $where .= " ) ";
                             }
                             break;
                     }
                     // tie in with customer permissions to only get jobs from customers we can access.
                     switch (module_customer::get_customer_data_access()) {
                         case _CUSTOMER_ACCESS_ALL:
                             // all customers! so this means all jobs!
                             break;
                         case _CUSTOMER_ACCESS_ALL_COMPANY:
                         case _CUSTOMER_ACCESS_CONTACTS:
                         case _CUSTOMER_ACCESS_TASKS:
                         case _CUSTOMER_ACCESS_STAFF:
                             $valid_customer_ids = module_security::get_customer_restrictions();
                             if (count($valid_customer_ids)) {
                                 $where .= " AND ( j.customer_id = 0 OR j.customer_id IN ( ";
                                 foreach ($valid_customer_ids as $valid_customer_id) {
                                     $where .= (int) $valid_customer_id . ", ";
                                 }
                                 $where = rtrim($where, ', ');
                                 $where .= " )";
                                 $where .= " )";
                             }
                     }
                     $res = qa($sql . $from . $where . " GROUP BY j.job_id");
                     foreach ($res as $job) {
                         if (!isset($job['c_total_amount_invoicable']) || $job['c_total_amount_invoicable'] < 0) {
                             $this->update_job_completion_status($job['job_id']);
                             // seed the cache
                             $job = $this->get_job($job['job_id']);
                         }
                         //$job = $this->get_job($r['job_id']);
                         //if($job && $job['job_id'] == $r['job_id'] && $job['total_amount_invoicable'] > 0 && module_invoice::can_i('create','Invoices')){
                         if (isset($job['c_total_amount_invoicable']) && $job['c_total_amount_invoicable'] > 0 && module_invoice::can_i('create', 'Invoices')) {
                             $alert_res = process_alert($job['date_completed'], $key);
                             if ($alert_res) {
                                 $alert_res['link'] = $this->link_open($job['job_id'], false, $job);
                                 $alert_res['name'] = $job['name'];
                                 // new dashboard alert layout here:
                                 $alert_res['time'] = strtotime($job['date_completed']);
                                 $alert_res['group'] = $key;
                                 $alert_res['job'] = $this->link_open($job['job_id'], true, $job);
                                 $alert_res['customer'] = $job['customer_id'] ? module_customer::link_open($job['customer_id'], true) : _l('N/A');
                                 $alert_res['website'] = $job['website_id'] ? module_website::link_open($job['website_id'], true) : _l('N/A');
                                 $alert_res['assigned_staff'] = $job['user_id'] ? module_user::link_open($job['user_id'], true) : _l('N/A');
                                 $alert_res['invoicable_amount'] = currency($job['c_total_amount_invoicable'], true, $job['currency_id']);
                                 //$alert_res['progress'] = ($job['total_percent_complete'] * 100).'%';
                                 $alert_res['date'] = print_date($alert_res['date']);
                                 $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                                 $this_alerts[] = $alert_res;
                             }
                         }
                     }
                     module_cache::put('job', $cache_key . $key, $this_alerts, $cache_timeout);
                     $alerts = array_merge($alerts, $this_alerts);
                 }
             }
             if ($show_all || module_config::c('job_renew_alerts', 1)) {
                 // find any jobs that have a renew date soon and have not been renewed.
                 $key = _l('Job Renewal Pending');
                 $key_auto = _l('Automatic Job Renewal Pending');
                 if (class_exists('module_dashboard', false)) {
                     $columns = array('job' => _l('Job Title'), 'customer' => _l('Customer'), 'website' => module_config::c('project_name_single', 'Website'), 'assigned_staff' => _l('Staff'), 'renewal_period' => _l('Period'), 'date_create' => _l('Created Date'), 'date' => _l('Renewal Date'), 'days' => _l('Day Count'));
                     if (!class_exists('module_website', false) || !module_website::is_plugin_enabled()) {
                         unset($columns['website']);
                     }
                     if (!module_customer::can_i('view', 'Customers')) {
                         unset($columns['customer']);
                     }
                     module_dashboard::register_group($key, array('columns' => $columns));
                     $columns = array('job' => _l('Job Title'), 'customer' => _l('Customer'), 'website' => module_config::c('project_name_single', 'Website'), 'assigned_staff' => _l('Staff'), 'renewal_period' => _l('Period'), 'date_create' => _l('Created Date'), 'date' => _l('Renewal Date'), 'renew_invoice' => _l('Automatic Invoice'), 'days' => _l('Day Count'));
                     if (!module_customer::can_i('view', 'Customers')) {
                         unset($columns['customer']);
                     }
                     module_dashboard::register_group($key_auto, array('columns' => $columns));
                 }
                 if ($cached_alerts = module_cache::get('job', $cache_key . $key)) {
                     $alerts = array_merge($alerts, $cached_alerts);
                 } else {
                     module_debug::log(array('title' => 'Job Home Alerts: ', 'data' => " starting: " . $key));
                     $this_alerts = array();
                     /*$sql = "SELECT p.* FROM `"._DB_PREFIX."job` p ";
                       $sql .= " WHERE p.date_renew != '0000-00-00'";
                       $sql .= " AND p.date_renew <= '".date('Y-m-d',strtotime('+'.module_config::c('alert_days_in_future',5).' days'))."'";
                       $sql .= " AND (p.renew_job_id IS NULL OR p.renew_job_id = 0)";
                       $res = qa($sql);*/
                     $res = self::get_jobs(array(), array('custom_where' => " AND  u.date_renew != '0000-00-00' AND u.date_renew <= '" . date('Y-m-d', strtotime('+' . module_config::c('alert_days_in_future', 5) . ' days')) . "' AND (u.renew_job_id IS NULL OR u.renew_job_id = 0)"));
                     foreach ($res as $job) {
                         //$job = self::get_job($r['job_id']);
                         //if(!$job || $job['job_id']!=$r['job_id'])continue;
                         if ($job['renew_auto']) {
                             $alert_res = process_alert($job['date_renew'], $key_auto);
                         } else {
                             $alert_res = process_alert($job['date_renew'], $key);
                         }
                         if ($alert_res) {
                             $alert_res['link'] = $this->link_open($job['job_id'], false, $job);
                             $alert_res['name'] = $job['name'];
                             $alert_res['renewal_period'] = _l('N/A');
                             // work out renewal period
                             if ($job['date_start'] && $job['date_start'] != '0000-00-00') {
                                 $time_diff = strtotime($job['date_renew']) - strtotime($job['date_start']);
                                 if ($time_diff > 0) {
                                     $diff_type = 'day';
                                     $days = round($time_diff / 86400);
                                     if ($days >= 365) {
                                         $time_diff = round($days / 365, 1);
                                         $diff_type = 'year';
                                     } else {
                                         $time_diff = $days;
                                     }
                                     $alert_res['renewal_period'] = $time_diff . ' ' . $diff_type;
                                 }
                             }
                             // new dashboard alert layout here:
                             $alert_res['time'] = strtotime($job['date_renew']);
                             if ($job['renew_auto']) {
                                 $alert_res['group'] = $key_auto;
                                 $alert_res['renew_invoice'] = $job['renew_invoice'] ? _l('Yes') : _l('No');
                             } else {
                                 $alert_res['group'] = $key;
                             }
                             $alert_res['job'] = $this->link_open($job['job_id'], true, $job);
                             $alert_res['customer'] = $job['customer_id'] ? module_customer::link_open($job['customer_id'], true) : _l('N/A');
                             $alert_res['website'] = $job['website_id'] ? module_website::link_open($job['website_id'], true) : _l('N/A');
                             $alert_res['assigned_staff'] = $job['user_id'] ? module_user::link_open($job['user_id'], true) : _l('N/A');
                             //$alert_res['progress'] = ($job['total_percent_complete'] * 100).'%';
                             $alert_res['date_create'] = print_date($job['date_start']);
                             $alert_res['date'] = print_date($job['date_renew']);
                             $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                             $this_alerts[] = $alert_res;
                         }
                     }
                     module_cache::put('job', $cache_key . $key, $this_alerts, $cache_timeout);
                     $alerts = array_merge($alerts, $this_alerts);
                 }
             }
             if ($show_all || module_config::c('job_approval_alerts', 1)) {
                 $job_task_creation_permissions = self::get_job_task_creation_permissions();
                 if ($job_task_creation_permissions == _JOB_TASK_CREATION_WITHOUT_APPROVAL) {
                     // find any jobs that have tasks requiring approval
                     $key = _l('Tasks Require Approval');
                     if (class_exists('module_dashboard', false)) {
                         $columns = array('job' => _l('Job Title'), 'customer' => _l('Customer'), 'website' => module_config::c('project_name_single', 'Website'), 'assigned_staff' => _l('Staff'), 'task_count' => _l('Tasks to Approve'), 'date' => _l('Task Date'), 'days' => _l('Day Count'));
                         if (!class_exists('module_website', false) || !module_website::is_plugin_enabled()) {
                             unset($columns['website']);
                         }
                         if (!module_customer::can_i('view', 'Customers')) {
                             unset($columns['customer']);
                         }
                         module_dashboard::register_group($key, array('columns' => $columns));
                     }
                     if ($cached_alerts = module_cache::get('job', $cache_key . $key)) {
                         $alerts = array_merge($alerts, $cached_alerts);
                     } else {
                         module_debug::log(array('title' => 'Job Home Alerts: ', 'data' => " starting: " . $key));
                         $this_alerts = array();
                         $sql = "SELECT p.job_id,p.name, t.date_updated, t.date_created, COUNT(t.task_id) AS approval_count FROM `" . _DB_PREFIX . "job` p ";
                         $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON p.job_id = t.job_id";
                         $sql .= " WHERE t.approval_required = 1";
                         $sql .= " GROUP BY p.job_id ";
                         $res = qa($sql);
                         foreach ($res as $r) {
                             $job = self::get_job($r['job_id']);
                             if (!$job || $job['job_id'] != $r['job_id']) {
                                 continue;
                             }
                             $alert_res = process_alert($r['date_updated'] && $r['date_updated'] != '0000-00-00' ? $r['date_updated'] : $r['date_created'], $key);
                             if ($alert_res) {
                                 $alert_res['link'] = $this->link_open($r['job_id'], false, $r);
                                 $alert_res['name'] = $r['name'];
                                 // new dashboard alert layout here:
                                 $alert_res['time'] = strtotime($r['date_updated'] && $r['date_updated'] != '0000-00-00' ? $r['date_updated'] : $r['date_created']);
                                 $alert_res['group'] = $key;
                                 $alert_res['job'] = $this->link_open($job['job_id'], true, $job);
                                 $alert_res['customer'] = $job['customer_id'] ? module_customer::link_open($job['customer_id'], true) : _l('N/A');
                                 $alert_res['website'] = $job['website_id'] ? module_website::link_open($job['website_id'], true) : _l('N/A');
                                 $alert_res['assigned_staff'] = $job['user_id'] ? module_user::link_open($job['user_id'], true) : _l('N/A');
                                 //$alert_res['progress'] = ($job['total_percent_complete'] * 100).'%';
                                 $alert_res['task_count'] = $r['approval_count'];
                                 $alert_res['date'] = print_date($alert_res['time']);
                                 $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                                 $this_alerts[] = $alert_res;
                             }
                         }
                         module_cache::put('job', $cache_key . $key, $this_alerts, $cache_timeout);
                         $alerts = array_merge($alerts, $this_alerts);
                     }
                 }
                 // find any rejected tasks
                 $key = _l('Tasks Have Been Rejected');
                 if (class_exists('module_dashboard', false)) {
                     $columns = array('job' => _l('Job Title'), 'customer' => _l('Customer'), 'website' => module_config::c('project_name_single', 'Website'), 'assigned_staff' => _l('Staff'), 'task_count' => _l('Tasks Rejected'), 'date' => _l('Task Date'), 'days' => _l('Day Count'));
                     if (!class_exists('module_website', false) || !module_website::is_plugin_enabled()) {
                         unset($columns['website']);
                     }
                     if (!module_customer::can_i('view', 'Customers')) {
                         unset($columns['customer']);
                     }
                     module_dashboard::register_group($key, array('columns' => $columns));
                 }
                 if ($cached_alerts = module_cache::get('job', $cache_key . $key)) {
                     $alerts = array_merge($alerts, $cached_alerts);
                 } else {
                     module_debug::log(array('title' => 'Job Home Alerts: ', 'data' => " starting: " . $key));
                     $this_alerts = array();
                     $sql = "SELECT p.job_id,p.name, t.date_updated, t.date_created, COUNT(t.task_id) AS approval_count FROM `" . _DB_PREFIX . "job` p ";
                     $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON p.job_id = t.job_id";
                     $sql .= " WHERE t.approval_required = 2";
                     $sql .= " GROUP BY p.job_id ";
                     $res = qa($sql);
                     foreach ($res as $r) {
                         $job = self::get_job($r['job_id']);
                         if (!$job || $job['job_id'] != $r['job_id']) {
                             continue;
                         }
                         $alert_res = process_alert($r['date_updated'] && $r['date_updated'] != '0000-00-00' ? $r['date_updated'] : $r['date_created'], $key);
                         if ($alert_res) {
                             $alert_res['link'] = $this->link_open($r['job_id'], false, $r);
                             $alert_res['name'] = $r['name'];
                             // new dashboard alert layout here:
                             $alert_res['time'] = strtotime($r['date_updated'] && $r['date_updated'] != '0000-00-00' ? $r['date_updated'] : $r['date_created']);
                             $alert_res['group'] = $key;
                             $alert_res['job'] = $this->link_open($job['job_id'], true, $job);
                             $alert_res['customer'] = $job['customer_id'] ? module_customer::link_open($job['customer_id'], true) : _l('N/A');
                             $alert_res['website'] = $job['website_id'] ? module_website::link_open($job['website_id'], true) : _l('N/A');
                             $alert_res['assigned_staff'] = $job['user_id'] ? module_user::link_open($job['user_id'], true) : _l('N/A');
                             //$alert_res['progress'] = ($job['total_percent_complete'] * 100).'%';
                             $alert_res['task_count'] = $r['approval_count'];
                             $alert_res['date'] = print_date($alert_res['time']);
                             $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                             $this_alerts[] = $alert_res;
                         }
                     }
                     module_cache::put('job', $cache_key . $key, $this_alerts, $cache_timeout);
                     $alerts = array_merge($alerts, $this_alerts);
                 }
             }
             if (module_security::can_user(module_security::get_loggedin_id(), 'Show Dashboard Todo List')) {
                 $key = _l('Job Todo');
                 if (class_exists('module_dashboard', false)) {
                     $columns = array('job' => _l('Job Title'), 'customer' => _l('Customer Name'), 'progress' => _l('Task Progress'), 'task' => _l('Task Description'), 'assigned_staff' => _l('Staff'), 'date' => _l('Due Date'), 'days' => _l('Day Count'));
                     if (!module_customer::can_i('view', 'Customers')) {
                         unset($columns['customer']);
                     }
                     module_dashboard::register_group($key, array('columns' => $columns));
                 }
                 if ($cached_alerts = module_cache::get('job', $cache_key . $key)) {
                     $alerts = array_merge($alerts, $cached_alerts);
                 } else {
                     module_debug::log(array('title' => 'Job Home Alerts: ', 'data' => " starting: " . $key));
                     $this_alerts = array();
                     $todo_list = self::get_tasks_todo();
                     $x = 0;
                     foreach ($todo_list as $todo_item) {
                         if ($todo_item['hours_completed'] > 0) {
                             if ($todo_item['hours'] > 0) {
                                 $percentage = round($todo_item['hours_completed'] / $todo_item['hours'], 2);
                                 $percentage = min(1, $percentage);
                             } else {
                                 $percentage = 1;
                             }
                         } else {
                             $percentage = 0;
                         }
                         $job_data = module_job::get_job($todo_item['job_id'], false);
                         $alert_res = process_alert($todo_item['date_due'], 'temp');
                         if ($alert_res) {
                             $alert_res['link'] = $this->link_open($todo_item['job_id'], false, $job_data);
                             $alert_res['name'] = $percentage * 100 . '% ' . $todo_item['description'];
                             $alert_res['item'] = $job_data['name'];
                             // new dashboard alert layout here:
                             $alert_res['time'] = strtotime($alert_res['date']);
                             $alert_res['group'] = $key;
                             $alert_res['job'] = $this->link_open($todo_item['job_id'], true, $job_data);
                             $alert_res['customer'] = $job_data['customer_id'] ? module_customer::link_open($job_data['customer_id'], true) : _l('N/A');
                             $alert_res['assigned_staff'] = $todo_item['user_id'] ? module_user::link_open($todo_item['user_id'], true) : _l('N/A');
                             $alert_res['progress'] = $percentage * 100 . '%';
                             $alert_res['task'] = htmlspecialchars($todo_item['description']);
                             $alert_res['date'] = $alert_res['warning'] ? '<span class="important">' . print_date($alert_res['date']) . '</span>' : print_date($alert_res['date']);
                             $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                             $this_alerts[] = $alert_res;
                         }
                     }
                     module_cache::put('job', $cache_key . $key, $this_alerts, $cache_timeout);
                     $alerts = array_merge($alerts, $this_alerts);
                 }
             }
             return $alerts;
             break;
     }
     return false;
 }
Example #6
0
 public function handle_hook($hook, &$calling_module = false, $show_all = false)
 {
     switch ($hook) {
         case 'dashboard_widgets':
             // see finance for example of widget usage.
             break;
         case "home_alerts":
             $cache_timeout = module_config::c('cache_objects', 60);
             $cache_key = 'home_alerts_' . module_security::get_loggedin_id();
             $alerts = array();
             if ($show_all || module_config::c('quote_alerts', 1)) {
                 // find any quotes that are past the due date and dont have a finished date.
                 $key = _l('Unapproved Quote');
                 if (class_exists('module_dashboard', false)) {
                     $columns = array('quote' => _l('Quote Title'), 'customer' => _l('Customer'), 'website' => module_config::c('project_name_single', 'Website'), 'assigned_staff' => _l('Staff'), 'date' => _l('Sent Date'), 'days' => _l('Day Count'));
                     if (!class_exists('module_website', false) || !module_website::is_plugin_enabled()) {
                         unset($columns['website']);
                     }
                     if (!module_customer::can_i('view', 'Customers')) {
                         unset($columns['customer']);
                     }
                     module_dashboard::register_group($key, array('columns' => $columns, 'sort' => array('time' => 'DESC')));
                 }
                 if ($cached_alerts = module_cache::get('quote', $cache_key . $key)) {
                     $alerts = array_merge($alerts, $cached_alerts);
                 } else {
                     module_debug::log(array('title' => 'Quote Home Alerts: ', 'data' => " starting: " . $key));
                     $this_alerts = array();
                     if (module_config::c('quote_dashboard_show_all_unapproved', 1)) {
                         $quotes = self::get_quotes(array(), array('custom_where' => " AND u.date_approved = '0000-00-00'"));
                     } else {
                         $quotes = self::get_quotes(array(), array('custom_where' => " AND u.date_approved = '0000-00-00' AND u.date_create <= '" . date('Y-m-d', strtotime('-' . module_config::c('alert_days_in_future', 5) . ' days')) . "'"));
                     }
                     foreach ($quotes as $quote_data) {
                         // permission check:
                         //                            $quote_data = self::get_quote($task['quote_id']);
                         //                            if(!$quote_data || $quote_data['quote_id']!=$task['quote_id'])continue;
                         $alert_res = process_alert($quote_data['date_create'], 'temp');
                         if ($alert_res) {
                             $alert_res['link'] = $this->link_open($quote_data['quote_id'], false, $quote_data);
                             $alert_res['name'] = $quote_data['name'];
                             // new dashboard alert layout here:
                             $alert_res['time'] = strtotime($alert_res['date']);
                             $alert_res['group'] = $key;
                             $alert_res['quote'] = $this->link_open($quote_data['quote_id'], true, $quote_data);
                             $alert_res['customer'] = $quote_data['customer_id'] ? module_customer::link_open($quote_data['customer_id'], true) : _l('N/A');
                             $alert_res['website'] = $quote_data['website_id'] ? module_website::link_open($quote_data['website_id'], true) : _l('N/A');
                             $alert_res['assigned_staff'] = $quote_data['user_id'] ? module_user::link_open($quote_data['user_id'], true) : _l('N/A');
                             $alert_res['date'] = print_date($alert_res['date']);
                             $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                             $this_alerts['quoteincomplete' . $quote_data['quote_id']] = $alert_res;
                         }
                     }
                     module_cache::put('quote', $cache_key . $key, $this_alerts, $cache_timeout);
                     $alerts = array_merge($alerts, $this_alerts);
                 }
             }
             return $alerts;
             break;
     }
     return false;
 }