Example #1
0
function query($sql, $debug_message = '')
{
    if (class_exists('module_db', false) && is_callable('module_db::query')) {
        return module_db::query($sql, $debug_message);
    }
    //echo ''.$sql.'<br>';
    if (_DEBUG_MODE && defined('_DEBUG_SQL') && _DEBUG_SQL) {
        static $past_queries = array();
        if (!isset($past_queries[$sql])) {
            $past_queries[$sql] = 0;
        } else {
            $past_queries[$sql]++;
        }
        $sql_debug = $sql;
        if (strlen($sql_debug) > 60) {
            $sql_debug = htmlspecialchars(substr($sql_debug, 0, 60)) . '<a href="#" onclick="$(this).hide(); $(\'span\',$(this).parent()).show(); return false;">....</a><span style="display:none">' . htmlspecialchars(substr($sql, 60)) . '</span>';
        } else {
            $sql_debug = htmlspecialchars($sql);
        }
        if (class_exists('module_debug', false)) {
            module_debug::log(array('title' => 'SQL Query', 'file' => 'includes/database.php', 'data' => '(' . ($past_queries[$sql] > 0 ? '<span style="color:#FF0000; font-weight:bold;">' . $past_queries[$sql] . '</span>' : $past_queries[$sql]) . ') ' . $debug_message . $sql_debug, 'important' => $past_queries[$sql] > 0));
        }
    }
    $res = mysql_query($sql);
    //or die(mysql_error() . $sql);
    if (mysql_errno()) {
        set_error(_l('SQL Error: %s', mysql_error() . ' ' . $sql));
        set_error(_l('Try clicking the "Run Manual Upgrades" button to resolve SQL Errors.'));
        return false;
    }
    return $res;
}
Example #2
0
 public function init()
 {
     if (self::$start_time == 0) {
         self::$start_time = microtime(true);
     }
     $this->module_name = "debug";
     $this->module_position = 1;
     $this->version = 2.121;
     // 2.1 - 2013-08-30 - debug mode enhancements
     // 2.11 - 2013-09-15 - ID in debug column output
     // 2.12 - 2014-07-28 - more info in debug output and ?debug_only_bad url
     // 2.121 - 2014-10-07 - memory_get_usage fix
 }
Example #3
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 #4
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;
 }
Example #5
0
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
switch ($display_mode) {
    case 'iframe':
        ?>

         </div> <!-- end .inner -->
         </div> <!-- end .outer -->
         </div> <!-- end .content -->
        </body>
        </html>
        <?php 
        module_debug::push_to_parent();
        break;
    case 'ajax':
        break;
    case 'normal':
    default:
        ?>


         </div> <!-- end .inner -->
         </div> <!-- end .outer -->
         </div> <!-- end .content -->

        </div>
        <!-- /#wrap -->
Example #6
0
/**
 * Take a full link <a href="adsf">afsdf</a>
 * and turn it into a popup link.
 * 
 * @param  $link
 * @param array $options
 * @return string
 */
function popup_link($link, $options = array())
{
    $hash = substr(md5($link . mt_rand(3, 8)), 4, 17);
    module_debug::log(array('title' => 'PopUp Link', 'file' => 'includes/functions.php', 'data' => "Converting {$link} into a popup link"));
    $width = isset($options['width']) ? $options['width'] : 400;
    $height = isset($options['height']) ? $options['height'] : 300;
    preg_match('#href="([^"]*)"#', $link, $matches);
    $url = $matches[1];
    if (!preg_match('/display_mode/', $url)) {
        $url .= (strpos($url, '?') ? '&' : '?') . 'display_mode=ajax';
    }
    //
    ob_start();
    if (isset($options['force']) && $options['force']) {
        $link = preg_replace('#<a href#', '<a onclick="$(\'#popup_link' . $hash . '\').dialog(\'open\'); return false;" href', $link);
        echo $link;
    } else {
        echo $link;
        ?>
        <a href="#" onclick="$('#popup_link<?php 
        echo $hash;
        ?>
').dialog('open'); return false;">(<?php 
        _e('popup');
        ?>
)</a>
    <?php 
    }
    ?>
    <div id="popup_link<?php 
    echo $hash;
    ?>
" title="<?php 
    echo isset($options['title']) ? htmlspecialchars($options['title']) : '';
    ?>
">
        <div class="modal_inner" style="height:100%;"></div>
    </div>
    <script type="text/javascript">
        $(function(){
            $("#popup_link<?php 
    echo $hash;
    ?>
").dialog({
                autoOpen: false,
                width: <?php 
    echo $width;
    ?>
,
                height: <?php 
    echo $height;
    ?>
,
                modal: true,
                buttons: {
					<?php 
    if (!isset($options['hide_close'])) {
        ?>
                    Close: function() {
                        $(this).dialog('close');
                    }
					<?php 
    }
    ?>
                },
                open: function(){
                    var t = this;
                    $.ajax({
                        type: "GET",
                        url: '<?php 
    echo $url;
    ?>
',
                        dataType: "html",
                        success: function(d){
                            $('.modal_inner',t).html(d);
                            $('input[name=_redirect]',t).val(window.location.href);
                            init_interface();
                            $('.modal_inner iframe.autosize',t).height($('.modal_inner',t).height()-41); // for firefox
                        }
                    });
                },
                close: function() {
                    $('.modal_inner',this).html('');
                }
            });
        });
    </script>
    <?php 
    return ob_get_clean();
}
Example #7
0
 public static function check_for_upgrades($requested_plugin = '', $get_file_contents = 0)
 {
     // compile a list of current plugins
     // along with the users installation code
     // send it to our server and get a response with a list of available updates for this user.
     $current_plugins = array();
     $current_files = array();
     global $plugins;
     if (_DEBUG_MODE) {
         module_debug::log(array('title' => 'Checking for upgrades:', 'data' => 'start'));
     }
     foreach ($plugins as $plugin_name => $p) {
         if ($requested_plugin && $requested_plugin != $plugin_name) {
             continue;
         }
         if (!$p->is_plugin_enabled()) {
             $p->init();
         }
         $current_plugins[$plugin_name] = $p->get_plugin_version();
         // find all the files related to this plugin.
         if (function_exists('getFilesFromDir') && module_config::c('upgrade_post_file_list', 1)) {
             $directory = 'includes/plugin_' . $plugin_name . '/';
             $files = getFilesFromDir($directory);
             $files = array_flip($files);
             foreach ($files as $file => $tf) {
                 // ignore certain files.
                 if (strpos($file, 'plugin_file/upload') !== false || strpos($file, 'plugin_data/upload') !== false || strpos($file, '/cache/') !== false || strpos($file, '/html2ps/') !== false || strpos($file, 'backup/backups/backup_') !== false || strpos($file, '/attachments/') !== false || strpos($file, '/temp/') !== false || strpos($file, '/tmp/') !== false) {
                     unset($files[$file]);
                 } else {
                     $d = preg_replace('#Envato:[^\\r\\n]*#', '', preg_replace('#Package Date:[^\\r\\n]*#', '', preg_replace('#IP Address:[^\\r\\n]*#', '', preg_replace('#Licence:[^\\r\\n]*#', '', file_get_contents($file)))));
                     $files[$file] = md5(base64_encode($d));
                 }
             }
             $current_files[$plugin_name] = $files;
         }
         if (_DEBUG_MODE) {
             module_debug::log(array('title' => 'Checking for upgrades:', 'data' => $plugin_name . ' done'));
         }
     }
     //print_r($current_files);exit;
     $available_updates = array();
     $post_fields = array('application' => _APPLICATION_ID, 'installation_code' => module_config::c('_installation_code'), 'current_version' => module_config::c('_admin_system_version', 2.1), 'current_plugins' => json_encode($current_plugins), 'current_files' => json_encode($current_files), 'client_ip' => $_SERVER['REMOTE_ADDR'], 'installation_location' => full_link('/'), 'requested_plugin' => $requested_plugin, 'get_file_contents' => $get_file_contents);
     $url = module_config::c('ucm_upgrade_url', 'http://api.ultimateclientmanager.com/upgrade.php');
     if ($url == 'http://ultimateclientmanager.com/api/upgrade.php') {
         $url = 'http://api.ultimateclientmanager.com/upgrade.php';
         // hack to use new update subdomain
     }
     if ($url != 'http://ultimateclientmanager.com/api/upgrade.php' && $url != 'http://api.ultimateclientmanager.com/upgrade.php') {
         set_error('Incorrect API url');
         redirect_browser(_BASE_HREF);
     }
     if (_DEBUG_MODE) {
         module_debug::log(array('title' => 'Checking for upgrades:', 'data' => 'Posting to API'));
     }
     if (!function_exists('curl_init')) {
         $postdata = http_build_query($post_fields);
         $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
         $context = stream_context_create($opts);
         $result = file_get_contents($url, false, $context);
     } else {
         //$url = 'http://localhost/ucm/web/api/upgrade.php';
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_HEADER, false);
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
         curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
         // fixes netregistr, may break others?
         $result = curl_exec($ch);
     }
     $data = json_decode($result, true);
     if (_DEBUG_MODE) {
         module_debug::log(array('title' => 'Checking for upgrades:', 'data' => 'Received response from API'));
     }
     if ($data && isset($data['available_updates']) && is_array($data['available_updates'])) {
         $available_updates = $data['available_updates'];
     }
     if ($data && isset($data['licence_codes']) && is_array($data['licence_codes'])) {
         // find out what the licence codes  are (url / name) so we can dispaly this under each code nicely.
         foreach ($data['licence_codes'] as $code => $foo) {
             if (strlen($code) > 10 && strlen($foo) > 10) {
                 module_config::save_config('_licence_code_' . $code, $foo);
                 // this might not be working
             }
         }
     }
     if (!$data) {
         echo $result;
     }
     //echo '<pre>';print_r($current_plugins);print_r($result);echo '</pre>';
     return $available_updates;
 }
Example #8
0
<?php 
        if ($display_mode == 'iframe') {
            ?>


<div id="iframe">

<?php 
        } else {
            ?>


    <?php 
            if (_DEBUG_MODE) {
                module_debug::print_heading();
            }
            ?>


<?php 
            if (module_security::getcred()) {
                ?>

    <header class="navbar navbar-inverse navbar-top visible-xs" role="banner" id="responsive_mini_header">
      <div class="container" id="menu_copy_holder">
        <div class="navbar-header">
          <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#responsive_mini_header > div > nav">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
Example #9
0
 public static function get_cached_item($cache_key, $cache_item = '')
 {
     // todo - based on curretn session id so we can clear cache by logging out and back in again
     if (!module_config::c('cache_enabled', 1)) {
         return false;
     }
     if (isset(self::$cache_store[$cache_key])) {
         if (_DEBUG_MODE && module_config::c('cache_debug', 0)) {
             module_debug::log(array('title' => 'Return cache', 'data' => "For: {$cache_key} = " . substr($cache_item, 0, 50) . '...'));
         }
         return self::$cache_store[$cache_key];
     }
 }
    foreach ($invoices as $invoice) {
        if (!$invoice['invoice_id']) {
            continue;
        }
        module_debug::log(array('title' => 'Removing invoice: ', 'data' => $invoice['invoice_id']));
        $invoice_check = module_invoice::get_invoice($invoice['invoice_id']);
        module_debug::log(array('title' => 'Removing invoice: (2) ', 'data' => $invoice['invoice_id']));
        if ($invoice_check['invoice_id'] != $invoice['invoice_id']) {
            continue;
        }
        if ($invoice_check['total_amount_paid'] <= 0) {
            // remove this invoice
            module_debug::log(array('title' => 'Removing invoice: (3) ', 'data' => $invoice['invoice_id']));
            echo "Deleting invoice " . $invoice_check['name'] . " for " . dollar($invoice_check['total_amount_due'], true, $invoice_check['currency_id']) . " from " . print_date($invoice_check['date_create']) . " and ticket  " . module_ticket::link_open($invoice['ticket_id'], true, $invoice_check) . " <br>\n";
            module_invoice::delete_invoice($invoice['invoice_id']);
            module_debug::log(array('title' => 'Removing invoice: (done)', 'data' => $invoice['invoice_id']));
        }
    }
    echo "Done";
} else {
    if (isset($_POST['bulk_process_go']) && $_POST['bulk_process_go'] == 'true') {
        $bulk_at_a_time = 10;
        //    @apache_setenv('no-gzip', 1);
        //    @ini_set('zlib.output_compression', 0);
        //    @ini_set('implicit_flush', 1);
        for ($i = 0; $i < ob_get_level(); $i++) {
            ob_end_clean();
        }
        //    ob_implicit_flush(1);
        if (count($_SESSION['ticket_bulk_ticket_ids'])) {
            for ($x = 0; $x < $bulk_at_a_time; $x++) {
Example #11
0
 public static function include_ucm($include_page)
 {
     // what folder do we search for?
     // custom/includes/plugin_mobile/custom_layout/theme/$theme_name/$page
     // custom/includes/plugin_mobile/custom_layout/$page
     // custom/theme/$theme_name/$page
     // custom/$page
     // includes/plugin_mobile/custom_layout/theme/$theme_name/$page
     // includes/plugin_mobile/custom_layout/$page
     // theme/$theme_name/$page
     // $page
     // sanatise $page.
     $display_mode = get_display_mode();
     $check_files = array();
     $current_theme = basename(self::$current_theme);
     if (strlen($current_theme) > 2 && is_dir('includes/plugin_theme/themes/' . $current_theme . '/')) {
         // we have an active theme!
     } else {
         $current_theme = false;
     }
     // build up our file listing.
     if ($display_mode == 'mobile') {
         $check_files[] = 'custom/' . dirname($include_page) . '/mobile/' . basename($include_page);
     }
     $check_files[] = 'custom/' . $include_page;
     if ($display_mode == 'mobile') {
         //$check_files[] = 'includes/plugin_mobile/custom_layout/'.$page;
         $check_files[] = dirname($include_page) . '/mobile/' . basename($include_page);
     }
     if (self::$current_theme_settings && isset(self::$current_theme_settings['base_dir']) && strlen(self::$current_theme_settings['base_dir']) > 2 && is_dir(self::$current_theme_settings['base_dir'])) {
         // we have an active theme!
         $check_files[] = self::$current_theme_settings['base_dir'] . $include_page;
     }
     $check_files[] = $include_page;
     foreach ($check_files as $file) {
         module_debug::log(array('title' => 'IncludeUCM', 'file' => 'includes/plugin_theme/theme.php', 'data' => "Checking for include file: " . $file));
         if (is_file($file)) {
             module_debug::log(array('title' => 'IncludeUCM', 'file' => 'includes/plugin_theme/theme.php', 'data' => "FOUND FILE! " . $file));
             return $file;
         }
     }
     module_debug::log(array('title' => 'IncludeUCM', 'file' => 'includes/plugin_theme/theme.php', 'data' => "Warning: File not found " . $include_page));
     return $include_page;
     // as a defult, wont ever get here.
 }
Example #12
0
// awesome.
$inner_content = array();
$page_title_delim = ' &raquo; ';
$page_title = '';
$load_modules = isset($_REQUEST['m']) ? $_REQUEST['m'] : false;
$load_pages = isset($_REQUEST['p']) ? $_REQUEST['p'] : false;
if ((!isset($noredirect) || !$noredirect) && !$load_modules && !$load_pages && defined('_CUSTOM_UCM_HOMEPAGE')) {
    redirect_browser(_CUSTOM_UCM_HOMEPAGE);
}
if (!is_array($load_modules)) {
    $load_modules = array($load_modules);
}
if (!is_array($load_pages)) {
    $load_pages = array($load_pages);
}
if (!isset($_REQUEST['m'])) {
    $_REQUEST['m'] = array();
}
if (!isset($_REQUEST['p'])) {
    $_REQUEST['p'] = array();
}
if (!is_array($_REQUEST['m'])) {
    $_REQUEST['m'] = array($_REQUEST['m']);
}
if (!is_array($_REQUEST['p'])) {
    $_REQUEST['p'] = array($_REQUEST['p']);
}
$load_modules = array_reverse($load_modules, true);
if (_DEBUG_MODE) {
    module_debug::log(array('title' => 'Init Complete, loaded modules: ', 'data' => implode(', ', $load_modules)));
}
Example #13
0
    }
} catch (Exception $e) {
    $inner_content[] = 'Error: ' . $e->getMessage();
}
// combine any inner content together looking for place holders.
$page_title = trim(preg_replace('#' . preg_quote($page_title_delim, '#') . '\\s*$#', '', $page_title));
if (!trim($page_title)) {
    $page_title = htmlspecialchars(module_config::s('admin_system_name', 'Ultimate Client Manager'));
}
if ($page_unique_id && function_exists('newrelic_name_transaction')) {
    newrelic_name_transaction('Admin: ' . $page_unique_id);
    if (function_exists('newrelic_capture_params')) {
        newrelic_capture_params();
    }
}
if (_DEBUG_MODE) {
    module_debug::log(array('title' => 'Displaying contents: ', 'data' => ''));
}
require_once module_theme::include_ucm("design_header.php");
echo implode('', $inner_content);
require_once module_theme::include_ucm("design_footer.php");
if (_DEBUG_MODE) {
    module_debug::log(array('title' => 'Finished displaying contents, running finish hook ', 'data' => ''));
}
hook_finish();
if (_DEBUG_MODE) {
    module_debug::log(array('title' => 'Finished final hook ', 'data' => ''));
}
if (_DEBUG_MODE) {
    module_debug::print_footer();
}
    public function print_footer_row($row)
    {
        if (_DEBUG_MODE) {
            module_debug::log(array('title' => 'footer row'));
        }
        ?>
        <tr class="">
            <?php 
        foreach ($this->columns as $column_id => $column_data) {
            if (isset($row[$column_id])) {
                ?>
                    <td<?php 
                if (isset($row[$column_id]) && is_array($row[$column_id]) && isset($row[$column_id]['cell_class'])) {
                    echo ' class="' . $row[$column_id]['cell_class'] . '"';
                } else {
                    if (isset($column_data['cell_class'])) {
                        echo ' class="' . $column_data['cell_class'] . '"';
                    }
                }
                if (isset($row[$column_id]) && is_array($row[$column_id]) && isset($row[$column_id]['cell_colspan'])) {
                    echo ' colspan="' . $row[$column_id]['cell_colspan'] . '"';
                } else {
                    if (isset($column_data['cell_colspan'])) {
                        echo ' colspan="' . $column_data['cell_colspan'] . '"';
                    }
                }
                ?>
>
                        <?php 
                if (isset($row[$column_id]['data'])) {
                    echo $row[$column_id]['data'];
                } else {
                    _e('N/A');
                }
                ?>
                    </td>
                    <?php 
            }
        }
        ?>
        </tr>
        <?php 
    }
Example #15
0
 public static function render_page_finished()
 {
     if (self::$page_denied) {
         self::$page_denied = false;
         $null = ob_get_clean();
         // remove page content.
         echo self::$page_denied_message;
         self::$page_denied_message = '';
     } else {
         if (self::$process_editable_page) {
             module_debug::log(array('title' => 'Page Editable', 'file' => 'includes/plugin_security/security.php', 'data' => "User doesn't have edit permissions, time to remove all form elements."));
             self::$process_editable_page = false;
             $editable_content = ob_get_clean();
             //ob_clean();
             //$editable_content = preg_replace('#</?form[^>]*>#imsU','',$editable_content);
             //$editable_content = preg_replace('#<input[^>]*type="submit"[^>]*>#imsU','',$editable_content);
             //$editable_content = preg_replace('#<input[^>]*type="button"[^>]*>#imsU','',$editable_content);
             //$editable_content = preg_replace('#<input[^>]*type="radio"[^>]*>#imsU','',$editable_content);
             //$editable_content = preg_replace('#<input[^>]*type="hidden"[^>]*>#imsU','',$editable_content);
             // check if this is bad: disabling script. eg: file edit screen.
             //$editable_content = preg_replace('#<script[^>]*>.*</script>#imsU','',$editable_content);
             $editable_content = preg_replace('#<a[^>]+ui-icon-help[^>]*>[^<]*</a>#imsU', '', $editable_content);
             $editable_content = preg_replace('#<span[^>]class="button"[^>]*>.*</span>#imsU', '', $editable_content);
             if (preg_match_all('#<input[^>]*type="text"[^>]*>#imsU', $editable_content, $matches)) {
                 foreach ($matches[0] as $match) {
                     if (strpos($match, 'no_permissions') === false) {
                         $replace_with = '';
                         if (preg_match('#value="([^"]*)"#imsU', $match, $value)) {
                             $replace_with = $value[1];
                         }
                         $editable_content = preg_replace('#' . preg_quote($match, '#') . '#msU', $replace_with, $editable_content);
                     }
                 }
             }
             if (preg_match_all('#<input[^>]*type="checkbox"[^>]*>#imsU', $editable_content, $matches)) {
                 foreach ($matches[0] as $match) {
                     if (!strpos($match, 'disabled=')) {
                         if (strpos($match, 'no_permissions') === false) {
                             $replace_with = str_replace('type=', 'disabled="disabled" type=', $match);
                             $editable_content = preg_replace('#' . preg_quote($match, '#') . '#msU', $replace_with, $editable_content);
                         }
                     }
                 }
             }
             if (preg_match_all('#<textarea[^>]*>(.*)</textarea>#imsU', $editable_content, $matches)) {
                 foreach ($matches[0] as $match_key => $match) {
                     if (strpos($match, 'no_permissions') === false) {
                         $replace_with = $matches[1][$match_key];
                         $editable_content = preg_replace('#' . preg_quote($match, '#') . '#msU', $replace_with, $editable_content);
                     }
                 }
             }
             if (preg_match_all('#<select[^>]*>.*</select>#imsU', $editable_content, $matches)) {
                 foreach ($matches[0] as $match_key => $match) {
                     if (strpos($match, 'no_permissions') === false) {
                         // find out which <option> is selected.
                         $replace_with = '';
                         if (preg_match('#<option[^>]*selected[^>]*>(.*)</option>#imsU', $match, $options)) {
                             $replace_with = $options[1];
                         }
                         $editable_content = str_replace($match, $replace_with, $editable_content);
                         //$editable_content = preg_replace('#'.preg_quote($match,'#').'#msU',$replace_with,$editable_content);
                     }
                 }
             }
             // remove all input elements that do not have a class of "no_permissions"
             if (preg_match_all('#<input[^>]*>#imsU', $editable_content, $matches)) {
                 foreach ($matches[0] as $match) {
                     if (strpos($match, 'no_permissions') === false && strpos($match, 'type="text"') === false) {
                         $editable_content = preg_replace('#' . preg_quote($match, '#') . '#imsU', '', $editable_content);
                     }
                 }
             }
             echo $editable_content;
         }
     }
 }
Example #16
0
    redirect_browser(_BASE_HREF);
}
$module->page_title = 'Recurring';
$search = isset($_REQUEST['search']) ? $_REQUEST['search'] : array();
if (module_config::c('finance_recurring_show_finished', 0)) {
    $search['show_finished'] = true;
}
if (!isset($search['date_to'])) {
    $search['date_to'] = print_date(strtotime('+' . (int) module_config::c('finance_recurring_months', 6) . ' months'));
}
$balance = isset($_REQUEST['balance']) ? (double) $_REQUEST['balance'] : module_config::c('finance_recurring_start_balance', 0);
module_config::save_config('finance_recurring_start_balance', $balance);
$_SESSION['_finance_recurring_ids'] = array();
module_debug::log(array('title' => 'calling get_recurrings', 'data' => ''));
$upcoming_finances_unsorted = module_finance::get_recurrings($search);
module_debug::log(array('title' => 'finished calling get_recurrings', 'data' => 'count: ' . count($upcoming_finances_unsorted)));
$upcoming_finances = array();
$limit_timestamp = isset($search['date_to']) && !empty($search['date_to']) ? strtotime(input_date($search['date_to'])) : strtotime('+' . (int) module_config::c('finance_recurring_months', 6) . ' months');
$duplicate_limit = 30;
$upcoming_finance_key = 0;
foreach ($upcoming_finances_unsorted as $recurring) {
    $time = strtotime($recurring['next_due_date']);
    $original = true;
    $count = 0;
    while ($time < $limit_timestamp) {
        $next_time = 0;
        if ($count++ > $duplicate_limit) {
            break;
        }
        // we need a special case for the first one that hasn't had a last trasnaction
        // we need a specicl case for the last one that the due date is on the finish date.
Example #17
0
    public static function output_dashboard_alerts($ajax = false)
    {
        module_debug::log(array('title' => 'Outputting Dashboard Alerts', 'data' => ''));
        if ($ajax && module_config::c('dashboard_alerts_as_tabs', 1)) {
            $items_to_hide = json_decode(module_config::c('_dashboard_item_hide' . module_security::get_loggedin_id(), '{}'), true);
            if (!is_array($items_to_hide)) {
                $items_to_hide = array();
            }
            if (isset($_REQUEST['hide_item']) && strlen($_REQUEST['hide_item'])) {
                $items_to_hide[] = $_REQUEST['hide_item'];
                module_config::save_config('_dashboard_item_hide' . module_security::get_loggedin_id(), json_encode($items_to_hide));
            }
            $dashboard_alerts = array();
            include module_theme::include_ucm('includes/plugin_dashboard/pages/dashboard_alerts.php');
            // output some javascript that will load our ajax hooks and display in a tab one by one
            ?>

            <script type="text/javascript">
                $(function(){
                    setTimeout(function(){
                        //$('body').append('<scr'+'ipt type="text/javascript" src="<?php 
            echo _BASE_HREF;
            ?>
?m=dashboard&_process=ajax_dashboard_tabs"></scri'+'pt>');
                        var scriptObject = document.createElement('script');
                        scriptObject .type = 'text/javascript';
                        scriptObject .async = true;
                        scriptObject .src = "<?php 
            echo _BASE_HREF;
            ?>
?m=dashboard&_process=ajax_dashboard_tabs&<?php 
            echo isset($_REQUEST['show_hidden']) ? 'show_hidden' : '';
            ?>
";
                        document.getElementsByTagName('head')[0].appendChild(scriptObject );
                        $('#dashboard_tabs').before('<p id="tabs_loading"><?php 
            _e('Loading Alerts...');
            ?>
</p>');
                    }, 200);
                });
            </script>

            <?php 
        } else {
            // we collect alerts from various places using our UCM hooks:
            $dashboard_alerts = self::get_dashboard_alerts();
            include module_theme::include_ucm('includes/plugin_dashboard/pages/dashboard_alerts.php');
        }
    }
Example #18
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 #19
0
function hook_filter_var($hook)
{
    global $hooks;
    $argv = array();
    $tmp = func_get_args();
    // $argv[1] is the var we want to filter and return.
    foreach ($tmp as $key => $value) {
        $argv[$key] =& $tmp[$key];
    }
    // hack for php5.3.2
    if (is_array($hooks) && isset($hooks[$hook]) && is_array($hooks[$hook])) {
        foreach ($hooks[$hook] as $hook_callback) {
            module_debug::log(array('title' => 'calling hook filter var: ' . $hook, 'data' => 'callback: ' . $hook_callback . ' args: ' . var_export($argv, true)));
            $this_return = call_user_func_array($hook_callback, $argv);
            if ($this_return !== false && $this_return !== null) {
                module_debug::log(array('title' => 'calling hook filter var: ' . $hook . ' completed!', 'data' => 'got results! '));
                $argv[1] = $this_return;
            }
        }
    }
    return $argv[1];
}
Example #20
0
 public static function get_finance_summary($week_start, $week_end, $multiplyer = 1, $row_limit = 7)
 {
     $cache_key = 'finance_sum_' . md5(module_security::get_loggedin_id() . '_' . serialize(func_get_args()));
     $cache_timeout = module_config::c('cache_objects', 60);
     if ($cached_item = module_cache::get('finance', $cache_key)) {
         return $cached_item;
     }
     $base_href = module_finance::link_generate(false, array('full' => false, 'page' => 'dashboard_popup', 'arguments' => array('display_mode' => 'ajax')), array('foo'));
     $base_href .= '&';
     /*$base_href .= (strpos($base_href,'?')!==false) ? '&' : '?';
       $base_href .= 'display_mode=ajax&';
       $base_href .= 'home_page_stats=true&';*/
     // init structure:
     if ($multiplyer > 1) {
         $row_limit++;
     }
     for ($x = 0; $x < $row_limit; $x++) {
         //$time = strtotime("+$x days",strtotime($week_start));
         $time = strtotime("+" . $x * $multiplyer . " days", strtotime($week_start));
         $data[date("Ymd", $time)] = array("day" => $time, "hours" => 0, "amount" => 0, "amount_invoiced" => 0, "amount_paid" => 0, "amount_spent" => 0);
         if (class_exists('module_envato', false)) {
             $data[date("Ymd", $time)]['envato_earnings'] = 0;
         }
     }
     $data['total'] = array('day' => _l('Totals:'), 'week' => _l('Totals:'), 'hours' => 0, 'amount' => 0, 'amount_invoiced' => 0, 'amount_paid' => 0, 'amount_spent' => 0);
     if (class_exists('module_envato', false)) {
         $data['total']['envato_earnings'] = 0;
     }
     if (class_exists('module_job', false)) {
         module_debug::log(array('title' => 'Finance Dashboard Job', 'data' => ''));
         // find all task LOGS completed within these dayes
         $sql = "SELECT t.task_id, tl.date_created, t.hours AS task_hours, t.amount, tl.hours AS hours_logged, p.job_id, p.hourly_rate, t.date_done ";
         //            $sql .= " FROM `"._DB_PREFIX."task_log` tl ";
         //            $sql .= " LEFT JOIN `"._DB_PREFIX."task` t ON tl.task_id = t.task_id ";
         $sql .= " FROM `" . _DB_PREFIX . "task` t";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "task_log` tl ON t.task_id = tl.task_id ";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "job` p ON t.job_id = p.job_id";
         $sql .= " WHERE ( (tl.date_created >= '{$week_start}' AND tl.date_created < '{$week_end}') OR (t.fully_completed = 1 AND t.date_done >= '{$week_start}' AND t.date_done < '{$week_end}') )";
         $sql .= " AND t.job_id IN ( ";
         $valid_job_ids = module_job::get_valid_job_ids();
         if (count($valid_job_ids)) {
             foreach ($valid_job_ids as $valid_job_id) {
                 $sql .= (int) $valid_job_id['job_id'] . ", ";
             }
             $sql = rtrim($sql, ', ');
         } else {
             $sql .= ' NULL ';
         }
         $sql .= " ) ";
         //            echo $sql;
         $tasks = query($sql);
         $logged_tasks = array();
         while ($r = mysql_fetch_assoc($tasks)) {
             if (!$r['date_created']) {
                 $r['date_created'] = $r['date_done'];
             }
             if ($multiplyer > 1) {
                 $week_day = date('w', strtotime($r['date_created'])) - 1;
                 $r['date_created'] = date('Y-m-d', strtotime('-' . $week_day . ' days', strtotime($r['date_created'])));
             }
             $key = date("Ymd", strtotime($r['date_created']));
             if (!isset($data[$key])) {
                 // for some reason we're getting results here that shouldn't be in the list
                 // for now we just skip these results until I figure out why (only had 1 guy report this error, maybe misconfig)
                 continue;
             }
             // copied from dashboard_popup_hours_logged.php
             // needed get_tasks call to do the _JOB_TASK_ACCESS_ASSIGNED_ONLY permission check
             $jobtasks = module_job::get_tasks($r['job_id']);
             $task = isset($jobtasks[$r['task_id']]) ? $jobtasks[$r['task_id']] : false;
             if (!$task) {
                 continue;
             }
             if (!isset($task['manual_task_type']) || $task['manual_task_type'] < 0) {
                 $task['manual_task_type'] = $task['default_task_type'];
             }
             if (isset($r['hours_logged']) && $r['hours_logged'] > 0) {
                 if ($r['hours_logged'] == $task['completed']) {
                     // this listing is the only logged hours for this task.
                     if ($task['fully_completed']) {
                         // task complete, we show the final amount and hours.
                         if ($task['amount'] > 0) {
                             if ($task['manual_task_type'] == _TASK_TYPE_QTY_AMOUNT) {
                                 $display_amount = $task['amount'] * $task['hours'];
                             } else {
                                 $display_amount = $task['amount'];
                             }
                         } else {
                             $display_amount = $r['task_hours'] * $r['hourly_rate'];
                         }
                     } else {
                         // task isn't fully completed yet, just use hourly rate for now.
                         $display_amount = $r['hours_logged'] * $r['hourly_rate'];
                     }
                 } else {
                     // this is part of a bigger log of hours for this single task.
                     $display_amount = $r['hours_logged'] * $r['hourly_rate'];
                 }
                 $hours_logged = $r['task_hours'] > 0 ? $r['hours_logged'] : 0;
             } else {
                 // there are no logged hours for this particular task, but it is set to completed.
                 // we just assume it is completed on this day.
                 if ($task['amount'] > 0) {
                     if ($task['manual_task_type'] == _TASK_TYPE_QTY_AMOUNT) {
                         $display_amount = $task['amount'] * $task['hours'];
                     } else {
                         $display_amount = $task['amount'];
                     }
                 } else {
                     $display_amount = $r['task_hours'] * $r['hourly_rate'];
                 }
                 $hours_logged = $task['hours'];
             }
             $data[$key]['amount'] += $display_amount;
             $data['total']['amount'] += $display_amount;
             $data[$key]['hours'] += $hours_logged;
             $data['total']['hours'] += $hours_logged;
             /*$hourly_rate = $r['hourly_rate'];
               if($hours_logged > 0 && $r['amount'] > 0 && $hourly_rate > 0){
                   // there is a custom amount assigned to thsi task.
                   // only calculate this amount if the full hours is complete.
                   $hourly_rate = $r['amount'] / $r['task_hours'];
               }
               if($hours_logged > 0 && $hourly_rate > 0){
                   $data[$key]['amount'] += ($hours_logged * $hourly_rate);
                   $data['total']['amount'] += ($hours_logged * $hourly_rate);
               }*/
         }
     }
     module_debug::log(array('title' => 'Finance Dashboard Invoices', 'data' => ''));
     // find invoices sent this week.
     $sql = "SELECT i.* ";
     $sql .= " FROM `" . _DB_PREFIX . "invoice` i ";
     $sql .= " LEFT JOIN `" . _DB_PREFIX . "invoice_item` ii ON i.invoice_id = ii.invoice_id ";
     if (class_exists('module_job', false)) {
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON ii.task_id = t.task_id ";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "job` p ON t.job_id = p.job_id ";
     }
     $sql .= " WHERE (i.date_create >= '{$week_start}' AND i.date_create <= '{$week_end}')";
     $sql .= " GROUP BY i.invoice_id";
     // todo - sql in here to limit what they can see.
     $invoices = query($sql);
     // group invoices into days of the week.
     while ($invoice_data = mysql_fetch_assoc($invoices)) {
         //$invoice_data = module_invoice::get_invoice($i['invoice_id']);
         if ($invoice_data) {
             if ($multiplyer > 1) {
                 $week_day = date('w', strtotime($invoice_data['date_create'])) - 1;
                 $invoice_data['date_create'] = date('Y-m-d', strtotime('-' . $week_day . ' days', strtotime($invoice_data['date_create'])));
             }
             $key = date("Ymd", strtotime($invoice_data['date_create']));
             if (!isset($data[$key])) {
                 // for some reason we're getting results here that shouldn't be in the list
                 // for now we just skip these results until I figure out why (only had 1 guy report this error, maybe misconfig)
                 continue;
             }
             if (isset($data[$key])) {
                 $data[$key]['amount_invoiced'] += $invoice_data['c_total_amount'];
                 $data['total']['amount_invoiced'] += $invoice_data['c_total_amount'];
             }
         }
     }
     module_debug::log(array('title' => 'Finance Dashboard Finances', 'data' => ''));
     // find all payments made this week.
     // we also have to search for entries in the new "finance" table and make sure we dont double up here.
     $finance_records = module_finance::get_finances(array('date_from' => $week_start, 'date_to' => $week_end));
     foreach ($finance_records as $finance_record) {
         if (isset($finance_record['payment_type']) && ($finance_record['payment_type'] == _INVOICE_PAYMENT_TYPE_OVERPAYMENT_CREDIT || $finance_record['payment_type'] == _INVOICE_PAYMENT_TYPE_CREDIT)) {
             // CODE COPIED FROM FINANCE_LIST.PHP
             // dont add these ones to the totals on the dashboard
             continue;
         }
         if ($finance_record['credit'] > 0) {
             if ($multiplyer > 1) {
                 $week_day = date('w', strtotime($finance_record['transaction_date'])) - 1;
                 $finance_record['transaction_date'] = date('Y-m-d', strtotime('-' . $week_day . ' days', strtotime($finance_record['transaction_date'])));
             }
             $key = date("Ymd", strtotime($finance_record['transaction_date']));
             if (isset($data[$key])) {
                 $data[$key]['amount_paid'] += $finance_record['amount'];
                 $data['total']['amount_paid'] += $finance_record['amount'];
             }
         }
         if ($finance_record['debit'] > 0) {
             if ($multiplyer > 1) {
                 $week_day = date('w', strtotime($finance_record['transaction_date'])) - 1;
                 $finance_record['transaction_date'] = date('Y-m-d', strtotime('-' . $week_day . ' days', strtotime($finance_record['transaction_date'])));
             }
             $key = date("Ymd", strtotime($finance_record['transaction_date']));
             if (isset($data[$key])) {
                 $data[$key]['amount_spent'] += $finance_record['amount'];
                 $data['total']['amount_spent'] += $finance_record['amount'];
             }
         }
     }
     module_debug::log(array('title' => 'Finance Dashboard DONE!', 'data' => ''));
     /*$sql = "SELECT p.* ";
       $sql .= " FROM `"._DB_PREFIX."invoice_payment` p ";
       $sql .= " WHERE (p.date_paid >= '$week_start' AND p.date_paid <= '$week_end')";
       // todo - sql in here to limit what they can see.
       $payments = query($sql);
       // group invoices into days of the week.
       while($payment = mysql_fetch_assoc($payments)){
           //$invoice_data = module_invoice::get_invoice($i['invoice_id']);
           if($multiplyer > 1){
               $week_day = date('w',strtotime($payment['date_paid'])) - 1;
               $payment['date_paid'] = date('Y-m-d',strtotime('-'.$week_day.' days',strtotime($payment['date_paid'])));
           }
           $key = date("Ymd",strtotime($payment['date_paid']));
           if(isset($data[$key])){
               $data[$key]['amount_paid'] += $payment['amount'];
               $data['total']['amount_paid'] += $payment['amount'];
           }
       }*/
     if (class_exists('module_envato', false)) {
         $envato_currency = "USD";
         $envato = new envato_api();
         $local_currency = $envato->read_setting("local_currency", "AUD");
         $currency_convert_multiplier = $envato->currency_convert($envato_currency, $local_currency);
         // find summary of earnings between these dates in the envato statement.
         $week_start_time = strtotime($week_start);
         $week_end_time = strtotime($week_end);
         $sql = "SELECT * FROM `" . _DB_PREFIX . "envato_statement` s WHERE `time` >= '{$week_start_time}' AND `time` <= {$week_end_time}";
         $sql .= " AND ( `type` = 'sale' OR `type` = 'referral_cut' )";
         foreach (qa($sql) as $sale) {
             $sale_time = $sale['time'];
             if ($multiplyer > 1) {
                 $week_day = date('w', $sale_time) - 1;
                 $sale_time = strtotime('-' . $week_day . ' days', $sale_time);
             }
             $key = date("Ymd", $sale_time);
             if (!isset($data[$key])) {
                 continue;
             }
             $data[$key]['envato_earnings'] += round($currency_convert_multiplier * $sale['earnt'], 2);
             $data['total']['envato_earnings'] += round($currency_convert_multiplier * $sale['earnt'], 2);
             /*if($sale['type']=='sale'){
                   $sales_count++;
               }
               $sales_amount+= $sale['earnt'];*/
         }
     }
     if ($multiplyer > 1) {
         // dont want totals on previous weeks listing
         unset($data['total']);
     }
     foreach ($data as $data_id => $row) {
         //$row['amount'] = dollar($row['amount']);
         $row['chart_amount'] = $row['amount'];
         $row['amount'] = currency((int) $row['amount']);
         $row['chart_amount_invoiced'] = $row['amount_invoiced'];
         $row['amount_invoiced'] = currency((int) $row['amount_invoiced']);
         $row['chart_amount_paid'] = $row['amount_paid'];
         $row['amount_paid'] = currency((int) $row['amount_paid']);
         $row['chart_amount_spent'] = $row['amount_spent'];
         $row['amount_spent'] = currency((int) $row['amount_spent']);
         if (class_exists('module_envato', false)) {
             $row['chart_envato_earnings'] = $row['envato_earnings'];
             $row['envato_earnings'] = currency((int) $row['envato_earnings']);
         }
         // combine together
         $row['chart_hours'] = $row['hours'];
         $row['hours'] = sprintf('%s (%s)', $row['hours'], $row['amount']);
         if (is_numeric($row['day'])) {
             $time = $row['day'];
             $date = date('Y-m-d', $time);
             $row['date'] = $date;
             if ($multiplyer > 1) {
                 $date .= '|' . date('Y-m-d', strtotime('+' . $multiplyer . ' days', $time));
             }
             //$row['hours'] = '<a href="'.$base_href.'w=hours&date='.$date.'" class="summary_popup">'. _l('%s hours',$row['hours']) . '</a>';
             $row['hours_link'] = '<a href="' . $base_href . 'w=hours&date=' . $date . '" class="summary_popup">' . $row['hours'] . '</a>';
             $row['amount_link'] = '<a href="' . $base_href . 'w=hours&date=' . $date . '" class="summary_popup">' . $row['amount'] . '</a>';
             $row['amount_invoiced_link'] = '<a href="' . $base_href . 'w=amount_invoiced&date=' . $date . '" class="summary_popup">' . $row['amount_invoiced'] . '</a>';
             $row['amount_paid_link'] = '<a href="' . $base_href . 'w=amount_paid&date=' . $date . '" class="summary_popup">' . $row['amount_paid'] . '</a>';
             $row['amount_spent_link'] = '<a href="' . $base_href . 'w=amount_spent&date=' . $date . '" class="summary_popup">' . $row['amount_spent'] . '</a>';
             $row['day'] = _l(date('D', $time)) . ' ' . date('j', $time) . _l(date('S', $time));
             $row['week'] = _l(date('M', $time)) . ' ' . date('j', $time) . _l(date('S', $time));
             // if it's today.
             if ($time == strtotime(date("Y-m-d"))) {
                 $row['highlight'] = true;
             }
         } else {
         }
         $data[$data_id] = $row;
     }
     module_cache::put('finance', $cache_key, $data, $cache_timeout);
     return $data;
 }
Example #21
0
 private function _send_queued_email($email_id, $debug = false)
 {
     if (!$email_id) {
         return false;
     }
     $this->reset();
     $email_data = get_single('email', 'email_id', $email_id);
     if (!$email_data || $email_data['email_id'] != $email_id) {
         return false;
     }
     if (defined('_BLOCK_EMAILS') && _BLOCK_EMAILS) {
         if ($debug) {
             echo " - emails blocked for testing, fake send <br>\n ";
         }
         update_insert('email_id', $email_id, 'email', array('sent_time' => time(), 'status' => _MAIL_STATUS_SENT));
         $this->status = _MAIL_STATUS_SENT;
         return true;
     }
     $headers = unserialize($email_data['headers']);
     $attachments = unserialize($email_data['attachments']);
     try {
         require_once "class.phpmailer.php";
         $mail = new PHPMailer();
         //$mail -> Hostname = 'yoursite.com';
         $mail->CharSet = 'UTF-8';
         // turn on HTML emails
         $mail->isHTML(true);
         // SeT SMTP or php Mail method:
         if (module_config::c('email_smtp', 0)) {
             if (_DEBUG_MODE) {
                 module_debug::log(array('title' => 'Email Module', 'data' => 'Connecting via SMTP to: ' . module_config::c('email_smtp_hostname', '')));
             }
             $mail->IsSMTP();
             // turn on SMTP authentication
             $mail->SMTPSecure = module_config::c('email_smtp_auth', '');
             $mail->SMTPAuth = module_config::c('email_smtp_authentication', 0);
             $mail->Host = module_config::c('email_smtp_hostname', '');
             if ($mail->SMTPAuth) {
                 $mail->Username = module_config::c('email_smtp_username', '');
                 $mail->Password = module_config::c('email_smtp_password', '');
             }
         } else {
             $mail->IsMail();
         }
         // pull out the data from $email_data
         $mail->MessageID = $email_data['message_id'];
         $mail->Subject = $email_data['subject'];
         $mail->Body = $email_data['html_content'];
         $mail->AltBody = $email_data['text_content'];
         // from the headers:
         $mail->Sender = $headers['Sender'];
         if (isset($headers['ReplyToEmail'])) {
             $mail->AddReplyTo($headers['ReplyToEmail'], isset($headers['ReplyToName']) ? $headers['ReplyToName'] : '');
         }
         $mail->From = $headers['FromEmail'];
         $mail->FromName = $headers['FromName'];
         $test_to_str = '';
         foreach ($headers['to'] as $to) {
             $mail->AddAddress($to['email'], $to['name']);
             $test_to_str .= " TO: " . $to['email'] . ' - ' . $to['name'];
         }
         foreach ($headers['cc'] as $cc) {
             $mail->AddCC($cc['email'], $cc['name']);
         }
         foreach ($headers['bcc'] as $bcc) {
             $mail->AddBCC($bcc['email'], $bcc['name']);
         }
         // attachemnts
         foreach ($attachments as $file_path => $file_name) {
             if (is_file($file_path)) {
                 $mail->AddAttachment($file_path, $file_name);
             }
         }
         // debugging.
         //        $html = $this->message_html;
         //        $mail->ClearAllRecipients();
         //        $mail->AddAddress('*****@*****.**','David Test');
         //        $html = $test_to_str.$html;
         if (_DEBUG_MODE) {
             module_debug::log(array('title' => 'Email Module', 'data' => 'Sending to: ' . $test_to_str));
         }
         if (!$mail->Send()) {
             $this->error_text = $mail->ErrorInfo;
             // update sent times and status on success.
             update_insert('email_id', $email_id, 'email', array('status' => _MAIL_STATUS_FAILED));
             // TODO: delete email from the database insetad of letting it queue later.
             // todo: re-do this later to leave the email there for quing.
             delete_from_db('email', 'email_id', $email_id);
             $this->status = _MAIL_STATUS_FAILED;
             if (_DEBUG_MODE) {
                 module_debug::log(array('title' => 'Email Module', 'data' => 'Send failed: ' . $this->error_text));
             }
             if ($debug) {
                 echo "Failed to send email: " . $this->error_text;
             }
             // todo - send error to admin ?
         } else {
             // update sent times and status on success.
             update_insert('email_id', $email_id, 'email', array('sent_time' => time(), 'status' => _MAIL_STATUS_SENT));
             $this->status = _MAIL_STATUS_SENT;
             if (_DEBUG_MODE) {
                 module_debug::log(array('title' => 'Email Module', 'data' => 'Send success'));
             }
         }
         /*  echo '<hr>';
             echo $this->subject;
             print_r($this->from);
             print_r($this->to);echo $this->status;*/
         //$this->status=_MAIL_STATUS_OVER_QUOTA;//testing.
         // todo : incrase mail count so that it sits within our specified boundaries.
         // true on succes, false on fail.
         return $this->status == _MAIL_STATUS_SENT;
     } catch (Exception $e) {
         return false;
     }
 }