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; }
// change between websites within this customer? // or websites all together? $res = module_website::get_websites(array('customer_id' => isset($_REQUEST['customer_id']) ? (int) $_REQUEST['customer_id'] : false)); //$res = module_website::get_websites(); while ($row = array_shift($res)) { $c[$row['website_id']] = $row['name']; } echo print_select_box($c, 'website_id', $job['website_id']); ?> <?php if ($job['website_id'] && module_website::can_i('view', 'Websites')) { ?> <a href="<?php echo module_website::link_open($job['website_id'], false); ?> "><?php _e('Open'); ?> </a> <?php } ?> <?php _h('This will be the ' . module_config::c('project_name_single', 'Website') . ' this job is assigned to - and therefor the customer. Every job should have a' . module_config::c('project_name_single', 'Website') . ' assigned. Clicking the open link will take you to the ' . module_config::c('project_name_single', 'Website')); ?> </td> </tr>
<?php } ?> </tr> <?php } ?> </tbody> </table> </div> <?php $fieldset_data['elements_before'] = ob_get_clean(); } echo module_form::generate_fieldset($fieldset_data); } } // and a hook for our new change request plugin hook_handle_callback('website_main', $website_id); } hook_handle_callback('layout_column_half', 'end'); $form_actions = array('class' => 'action_bar action_bar_center', 'elements' => array(array('type' => 'save_button', 'name' => 'butt_save', 'value' => _l('Save ' . module_config::c('project_name_single', 'Website'))), array('ignore' => !((int) $website_id && module_website::can_i('delete', 'Websites')), 'type' => 'delete_button', 'name' => 'butt_del', 'value' => _l('Delete')), array('type' => 'button', 'name' => 'cancel', 'value' => _l('Cancel'), 'class' => 'submit_button', 'onclick' => "window.location.href='" . module_website::link_open(false) . "';"))); echo module_form::generate_form_actions($form_actions); ?> </form>
public static function get_finance_recurring_items($hook, $search) { /** * next_due_date * url * type (i or e) * amount * currency_id * days * months * years * last_transaction_finance_id * account_name * categories * finance_recurring_id */ // find list of all members. // then go through and fine list of all upcoming subscription payments. // add these ones (and future ones up to (int)module_config::c('finance_recurring_months',6) months from todays date. $end_date = isset($search['date_to']) && !empty($search['date_to']) ? strtotime(input_date($search['date_to'])) : strtotime("+" . (int) module_config::c('finance_recurring_months', 6) . ' months'); /*$sql = "SELECT s.*, sm.*"; $sql .= " FROM `"._DB_PREFIX."subscription_member` sm "; $sql .= " LEFT JOIN `"._DB_PREFIX."subscription` s USING (subscription_id)"; $sql .= " WHERE sm.`deleted` = 0"; $members = qa($sql); $sql = "SELECT s.*, sc.*"; $sql .= " FROM `"._DB_PREFIX."subscription_customer` sc "; $sql .= " LEFT JOIN `"._DB_PREFIX."subscription` s USING (subscription_id)"; $sql .= " WHERE sc.`deleted` = 0"; $customers = qa($sql); $items = array_merge($members,$customers);*/ //$members = module_member::ge $sql = "SELECT s.*, so.*"; $sql .= " FROM `" . _DB_PREFIX . "subscription_owner` so "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "subscription` s USING (subscription_id)"; $sql .= " WHERE so.`deleted` = 0"; $sql .= " GROUP BY `owner_table`, `owner_id`"; $items = qa($sql); //$members = module_member::get_members(array()); $return = array(); foreach ($items as $member) { $subscriptions = module_subscription::get_subscriptions_by($member['owner_table'], $member['owner_id']); /*if(isset($member['member_id']) && $member['member_id']){ }else if(isset($member['customer_id']) && $member['customer_id']){ $subscriptions = module_subscription::get_subscriptions_by_customer($member['customer_id']); }else{ $subscriptions = array(); }*/ foreach ($subscriptions as $subscription) { $time = strtotime($subscription['next_generation_date'] ? $subscription['next_generation_date'] : $subscription['next_due_date']); if (!$time) { continue; } switch ($member['owner_table']) { case 'customer': $type = 'customer'; $member_name = module_customer::link_open($member['owner_id'], true); $subscription_invoices = self::get_subscription_history($subscription['subscription_id'], $member['owner_table'], $member['owner_id']); break; case 'website': $type = 'website'; $member_name = module_website::link_open($member['owner_id'], true); $subscription_invoices = self::get_subscription_history($subscription['subscription_id'], $member['owner_table'], $member['owner_id']); break; case 'member': $type = 'member'; $member_name = module_member::link_open($member['owner_id'], true); $subscription_invoices = self::get_subscription_history($subscription['subscription_id'], $member['owner_table'], $member['owner_id']); break; default: $subscription_invoices = array(); $member_name = 'unknown2'; $type = 'unknown2'; } $subscription_name = module_subscription::link_open($subscription['subscription_id'], true); foreach ($subscription_invoices as $subscription_invoice_id => $subscription_invoice) { if ($subscription_invoice['invoice_id']) { $subscription_invoices[$subscription_invoice_id] = array_merge($subscription_invoice, module_invoice::get_invoice($subscription_invoice['invoice_id'], 2)); } } $original = true; $c = 0; while ($time < $end_date) { if ($c++ > 200) { break; } $next_time = 0; if (!$subscription['days'] && !$subscription['months'] && !$subscription['years']) { // it's a once off.. // add it to the list but dont calculate the next one. } else { if (!$original) { // work out when the next one will be. $next_time = self::_calculate_next_time($time, $subscription); $time = $next_time; } else { $original = false; // it's the original one. $next_time = $time; } } if ($next_time) { // don't show it here if an invoice has already been generated. // because invoice will already be in the list as outstanding foreach ($subscription_invoices as $subscription_invoice) { if (isset($subscription_invoice['date_create']) && $subscription_invoice['date_create'] == date('Y-m-d', $next_time)) { //echo 'match'; continue 2; } } $return[] = array('next_due_date' => date('Y-m-d', $next_time), 'url' => _l('Subscription: %s', $member_name), 'type' => 'i', 'amount' => $subscription['amount'], 'currency_id' => $subscription['currency_id'], 'days' => $subscription['days'], 'months' => $subscription['months'], 'years' => $subscription['years'], 'last_transaction_finance_id' => 0, 'account_name' => '', 'categories' => '', 'finance_recurring_id' => 0, 'last_transaction_text' => '(see member page)', 'end_date' => '0000-00-00', 'start_date' => $subscription['start_date'], 'recurring_text' => _l('Payment from %s %s on subscription %s', $type, $member_name, $subscription_name)); } } } } return $return; }
<a href="<?php echo module_website::link_open($job['website_id'], false); ?> "><?php _e('Open'); ?> </a> <?php } ?> <?php _h('This will be the ' . module_config::c('project_name_single', 'Website') . ' this job is assigned to - and therefor the customer. Every job should have a' . module_config::c('project_name_single', 'Website') . ' assigned. Clicking the open link will take you to the ' . module_config::c('project_name_single', 'Website')); } else { if ($job['website_id']) { echo module_website::link_open($job['website_id'], true); } else { _e('N/A'); } } })); } else { if (!class_exists('module_website', false) && module_config::c('show_ucm_ads', 1)) { $fieldset_data['elements'][] = array('title' => module_config::c('project_name_single', 'Website'), 'fields' => array('(website option available in <a href="http://codecanyon.net/item/ultimate-client-manager-pro-edition/2621629?ref=dtbaker" target="_blank">UCM Pro Edition</a>)')); } } if (module_customer::can_i('view', 'Customers')) { $fieldset_data['elements'][] = array('title' => 'Customer', 'fields' => array(function () use(&$job) { $c = array(); $customers = module_customer::get_customers(); foreach ($customers as $customer) {
function handle_hook($hook, $calling_module = false, $owner_table = false, $key_name = false, $key_value = false, $rel_data = false) { switch ($hook) { case "home_alerts": $alerts = array(); if (module_config::c('allow_note_reminders', 1)) { // find any jobs that are past the due date and dont have a finished date. $key = _l('Note Reminder'); if (class_exists('module_dashboard', false)) { module_dashboard::register_group($key, array('columns' => array('name' => _l('Reminder'), 'type' => _l('Type'), 'full_link' => _l('Link'), 'date' => _l('Date'), 'days' => _l('Date')))); } $sql = "SELECT * FROM `" . _DB_PREFIX . "note` n "; $sql .= " WHERE n.`reminder` = 1 AND n.note_time < " . (int) strtotime('+' . module_config::c('alert_days_in_future', 5) . ' days') . ""; $sql .= " AND ( n.`user_id` = 0 OR n.`user_id` = " . module_security::get_loggedin_id() . ")"; $sql .= " ORDER BY n.note_time ASC"; $tasks = qa($sql); foreach ($tasks as $task) { $alert_res = process_alert(date('Y-m-d', $task['note_time']), $key); if ($alert_res) { $alert_res['link'] = $task['rel_data']; // fix for linking when changing folder. $alert_res['type'] = _l(ucwords($task['owner_table'])); switch ($task['owner_table']) { case 'user': $user = module_user::get_user($task['owner_id']); if ($user['customer_id'] || $user['vendor_id']) { $alert_res['link'] = module_user::link_open_contact($task['owner_id'], false, $user); $alert_res['full_link'] = module_user::link_open_contact($task['owner_id'], true, $user); $alert_res['type'] = _l('Contact'); } else { $alert_res['link'] = module_user::link_open($task['owner_id'], false, $user); $alert_res['full_link'] = module_user::link_open($task['owner_id'], true, $user); } break; case 'invoice': $invoice_data = module_invoice::get_invoice($task['owner_id'], true); if (!$invoice_data || !isset($invoice_data['invoice_id']) || $invoice_data['invoice_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_invoice::link_open($task['owner_id'], false, $invoice_data); $alert_res['full_link'] = module_invoice::link_open($task['owner_id'], true, $invoice_data); break; case 'quote': $quote_data = module_quote::get_quote($task['owner_id'], true); if (!$quote_data || !isset($quote_data['quote_id']) || $quote_data['quote_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_quote::link_open($task['owner_id'], false, $quote_data); $alert_res['full_link'] = module_quote::link_open($task['owner_id'], true, $quote_data); break; case 'website': $website_data = module_website::get_website($task['owner_id']); if (!$website_data || !isset($website_data['website_id']) || $website_data['website_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_website::link_open($task['owner_id'], false); $alert_res['full_link'] = module_website::link_open($task['owner_id'], true); break; case 'customer': $customer_data = module_customer::get_customer($task['owner_id']); if (!$customer_data || !isset($customer_data['customer_id']) || $customer_data['customer_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_customer::link_open($task['owner_id'], false, $customer_data); $alert_res['full_link'] = module_customer::link_open($task['owner_id'], true, $customer_data); break; case 'vendor': $vendor_data = module_vendor::get_vendor($task['owner_id']); if (!$vendor_data || !isset($vendor_data['vendor_id']) || $vendor_data['vendor_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_vendor::link_open($task['owner_id'], false, $vendor_data); $alert_res['full_link'] = module_vendor::link_open($task['owner_id'], true, $vendor_data); break; case 'job': $job_data = module_job::get_job($task['owner_id']); if (!$job_data || !isset($job_data['job_id']) || $job_data['job_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_job::link_open($task['owner_id'], false, $job_data); $alert_res['full_link'] = module_job::link_open($task['owner_id'], true, $job_data); break; // todo - add others. } $alert_res['name'] = $task['note']; $alert_res['date'] = print_date($alert_res['date']); $alert_res['time'] = $task['note_time']; $alerts[] = $alert_res; } } } return $alerts; break; /*case "note_list": if($owner_id && $owner_id != 'new'){ $note_items = $this->get_notes(array("owner_table"=>$owner_table,"owner_id"=>$owner_id)); foreach($note_items as &$note_item){ // do it in loop here because of $this issues in static method below. // instead of include file below. $note_item['html'] = $this->print_note($note_item['note_id']); } include("pages/note_list.php"); }else{ echo 'Please save first before creating notes.'; } break;*/ /*case "note_list": if($owner_id && $owner_id != 'new'){ $note_items = $this->get_notes(array("owner_table"=>$owner_table,"owner_id"=>$owner_id)); foreach($note_items as &$note_item){ // do it in loop here because of $this issues in static method below. // instead of include file below. $note_item['html'] = $this->print_note($note_item['note_id']); } include("pages/note_list.php"); }else{ echo 'Please save first before creating notes.'; } break;*/ case "note_delete": // find the key we are saving this address against. $owner_id = (int) $key_value; if (!$owner_id || $owner_id == 'new') { // find one in the post data. if (isset($_REQUEST[$key_name])) { $owner_id = $_REQUEST[$key_name]; } } $note_hash = md5($owner_id . '|' . $owner_table); // just for posting unique arrays. if ($owner_table && $owner_id) { $this->note_delete($owner_table, $owner_id); } break; } }
if ($subscription['subscription_owner_id']) { $subscription_owner = get_single('subscription_owner', 'subscription_owner_id', $subscription['subscription_owner_id']); if (count($subscription_owner)) { ob_start(); ?> <table border="0" cellspacing="0" cellpadding="2" class="tableclass tableclass_form tableclass_full"> <tbody> <tr> <td> <?php switch ($subscription_owner['owner_table']) { case 'member': $member_name = module_member::link_open($subscription_owner['owner_id'], true); break; case 'website': $member_name = module_website::link_open($subscription_owner['owner_id'], true); break; case 'customer': $member_name = module_customer::link_open($subscription_owner['owner_id'], true); break; } $subscription_name = module_subscription::link_open($subscription['subscription_id'], true); _e('This is a subscription payment for %s %s on the subscription: %s', $subscription_owner['owner_table'], $member_name, $subscription_name); ?> </td> </tr> </tbody> </table> <?php $fieldset_data = array('heading' => array('title' => _l('%s Subscription', _l(ucwords($subscription_owner['owner_table']))), 'type' => 'h3'), 'elements_before' => ob_get_clean()); echo module_form::generate_fieldset($fieldset_data);
"> <td> <?php echo module_job::link_open($job_data['job_id'], true, $job_data); ?> <?php if (isset($original_job_data['renew_from_job_id'])) { _e('(will renew on %s)', print_date($original_job_data['date_start'])); } ?> </td> <td> <?php echo module_website::link_open($original_job_data['website_id'], true); ?> </td> <td> <?php echo module_customer::link_open($job_data['customer_id'], true); ?> </td> <td> <?php echo htmlspecialchars($original_job_data['type']); ?> </td>
public function external_hook($hook) { switch ($hook) { case 'popup': // popup not used any more. cross domain issues. // load up the full script to be injected into our clients website. $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $change_request_id = $change_id = isset($_REQUEST['change_id']) ? (int) $_REQUEST['change_id'] : false; $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false; $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : false; if ($type == 'popupjs') { @ob_end_clean(); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); header("Content-type: text/javascript"); } if ($website_id && $hash && module_change_request::link_popup($website_id, true) == $hash) { $change_history = module_change_request::get_remaining_changes($website_id); $step = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0; // get the change details out if ($change_request_id) { $change_request = module_change_request::get_change_request_by_website($website_id, $change_request_id); } else { $change_request = array(); } if (!$change_request) { $change_request = array('change_request_id' => 0, 'name' => '', 'request' => '', 'attachments' => array()); } switch ($type) { case 'save': // saving a change. $data = $_POST; $data['url'] = urldecode($data['url']); $data['website_id'] = $website_id; $data['change_request_id'] = $change_request['change_request_id']; if (isset($_REQUEST['completed_test'])) { if (!isset($_REQUEST['completed']) || !$_REQUEST['completed']) { $data['status'] = _CHANGE_REQUEST_STATUS_NEW; // not completed. } else { $data['status'] = _CHANGE_REQUEST_STATUS_COMPLETE; // completed! } } if (isset($_REQUEST['delete_request'])) { $data['status'] = _CHANGE_REQUEST_STATUS_DELETE; // deleted } $change_request_id = update_insert('change_request_id', $change_request['change_request_id'], 'change_request', $data); // redirect to send email page if we're logged in if (module_security::is_logged_in() && isset($_REQUEST['completed_send_email']) && $_REQUEST['completed_send_email'] && self::can_i('edit', 'Change Requests')) { // don't do the template, do the redirect to the email page (todo!) redirect_browser(self::link_open($change_request_id)); } else { // send email to administrator (everyone with change request edit permissions?) about this change request. $alert_users = module_user::get_users_by_permission(array('category' => 'Change Request', 'name' => 'Change Requests', 'module' => 'change_request', 'edit' => 1)); $email_data = get_single('change_request', 'change_request_id', $change_request_id); $customer_data = $website_data = array(); if ($website_id) { $website_data = module_website::get_website($website_id); $email_data['website_name'] = $website_data['name']; $email_data['website_link'] = module_website::link_open($website_id, true); if ($website_data && $website_data['customer_id']) { $customer_data = module_customer::get_customer($website_data['customer_id'], true); } } if (isset($email_data['request'])) { $email_data['request'] = nl2br($email_data['request']); // for the plain text emails. } foreach ($alert_users as $alert_user) { // todo: make sure this staff member has access to this website? // nfi how to figure this out. maybe we just look for staff members who are assigned jobs/tasks against this website? $template = module_template::get_template_by_key('change_request_alert_email'); $template->assign_values(array_merge($customer_data, $website_data, $email_data)); $html = $template->render('html'); // send an email to this user. $email = module_email::new_email(); $email->replace_values = array_merge($customer_data, $website_data, $email_data); $email->set_to('user', $alert_user['user_id']); $email->set_from('user', module_security::get_loggedin_id() ? module_security::get_loggedin_id() : isset($customer_data['primary_user_id']) ? $customer_data['primary_user_id'] : 0); $email->set_subject($template->description); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! // sweet. } else { /// log err? set_error(_l('Failed to send change notification email to User ID: %s Email: %s Status: %s Error: %s', $alert_user['user_id'], json_encode($email->to), $email->status, $email->error_text)); } } } // display thankyou template. module_template::init_template('change_request_submitted', '<h2>Change Request</h2> <p>Thank you. Your change request has been submitted successfully.</p> <p>Please <a href="{URL}">click here</a> to continue.</p> ', 'Displayed after a change request is created/updated.', 'code'); // correct! // load up the receipt template. $template = module_template::get_template_by_key('change_request_submitted'); $template->page_title = _l("Change Request"); foreach ($data as $key => $val) { if (!is_array($val)) { $data[$key] = htmlspecialchars($val); } } $template->assign_values($data); echo $template->render('pretty_html'); exit; break; case 'display_change': ob_start(); ?> <div class="title"> <?php _e('Change request'); ?> </div> <div class="content"> <p><?php echo nl2br(htmlspecialchars($change_request['request'])); ?> </p> <div class="wp3changerequest_actions"> <p> <!-- <strong><?php _e('Attachments:'); ?> </strong> <?php if (!$change_request['attachments']) { ?> - none - <?php } else { foreach ($change_request['attachments'] as $attachment) { ?> <a href="#"><?php echo htmlspecialchars($attachment->name); ?> </a> <?php } ?> <?php } ?> <br/>--> <strong><?php _e('Created by:'); ?> </strong> <?php echo htmlspecialchars($change_request['name']); ?> <br/> <strong><?php _e('Created on:'); ?> </strong> <?php echo print_date($change_request['date_created'], true); ?> <?php if (isset($change_request['job_id']) && $change_request['job_id']) { ?> <br/> <strong><?php _e('Converted to job:'); ?> </strong> <?php _e('This task has been converted to a Job'); ?> <?php } ?> </p> <?php if (!isset($change_request['job_id']) || !$change_request['job_id'] || self::can_i('edit', 'Change Requests')) { ?> <p align="center"> <input type="button" name="edit" value="<?php _e('Edit'); ?> " class="wp3changerequest_button wp3changerequest_button_small" onclick="dtbaker_changerequest.edit(<?php echo $change_request_id; ?> ); return false;"> </p> <?php } ?> </div> </div> <?php $change_request['html'] = preg_replace('/\\s+/', ' ', ob_get_clean()); // echo json_encode($change_request); // exit; @ob_end_clean(); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); header("Content-type: text/javascript"); ?> var t = dtbaker_changerequest; var change_id = <?php echo $change_request_id; ?> ; var msg = <?php echo json_encode($change_request); ?> ; jQuery('body').prepend('<div class="wp3changerequest_change" id="dtbaker_change_'+change_id+'" style="'+((!t.show_postits) ? 'display:none;':'')+'"></div>'); var box = jQuery('#dtbaker_change_'+change_id); box.html(msg.html); if(msg.status == 0){ box.addClass('wp3changerequest_change_pending'); }else if(msg.status == 2){ box.addClass('wp3changerequest_change_complete'); }else if(msg.status == 3){ box.addClass('wp3changerequest_change_deleted'); } box.css('top',msg.y+'px'); box.data('window_width',msg.window_width); box.data('left',msg.x); t.set_left(change_id); with({i:change_id}){ jQuery(window).resize(function () { t.set_left(i); }); } box.data('original_height',box.height()); box.css('overflow','hidden'); jQuery('.title',box).slideUp(); box.stop(true, true).animate({ height: t.min_height, width: t.min_width },500); box.hover(function(){ jQuery(this).addClass('wp3changerequest_change_active'); jQuery('.title',this).stop(true, true).slideDown(); jQuery(this).stop().animate({ width: t.max_width, height: jQuery(this).data('original_height'), opacity: 1 },500); },function(){ jQuery('.title',this).stop(true, true).slideUp(); jQuery(this).stop().animate({ width: t.min_width, height: t.min_height, opacity: 0.7 },500,function(){ jQuery(this).removeClass('wp3changerequest_change_active'); }); }) <?php break; default: @ob_end_clean(); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); header("Content-type: text/javascript"); ob_start(); include 'pages/popup.php'; $html = ob_get_clean(); $html = addcslashes($html, "'"); $html = preg_replace('#\\r|\\n#', "' +\n'", $html); // inject using javascript. fixes cross domain issues ?> if(!jQuery('#dtbaker_changerequest_inlinewizard').length){ // fix for jQuery 1.9+ jQuery('body').append('<div id="dtbaker_changerequest_inlinewizard" style="display:none;"></div>'); } jQuery('#dtbaker_changerequest_inlinewizard').html('<?php echo $html; ?> '); <?php } } exit; break; case 'script': // load up the full script to be injected into our clients website. $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false; @ob_end_clean(); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); header("Content-type: text/javascript"); if ($website_id && $hash && module_change_request::link_script($website_id, true) == $hash) { include "js/client.js"; $client_url = isset($_REQUEST['url']) ? $_REQUEST['url'] : false; if ($client_url) { $change_requests = self::get_change_requests(array('website_id' => $website_id, 'url' => $client_url)); // todo - option this out incase url causes issues. ie: old js check method ?> jQuery(function(){ <?php foreach ($change_requests as $change_request) { $displayed = false; if ($change_request['status'] == _CHANGE_REQUEST_STATUS_NEW) { $displayed = true; ?> dtbaker_changerequest.display_change(<?php echo $change_request['change_request_id']; ?> ); <?php } if (isset($_SESSION['_change_request_highlight']) && $_SESSION['_change_request_highlight'] == $change_request['change_request_id']) { ?> <?php if (!$displayed) { ?> dtbaker_changerequest.display_change(<?php echo $change_request['change_request_id']; ?> ); <?php } ?> dtbaker_changerequest.highlight(<?php echo (int) $_SESSION['_change_request_highlight']; ?> ); <?php unset($_SESSION['_change_request_highlight']); } } ?> }); <?php } else { // not posting the URL, some setups do not like this // get list of active change requests $change_requests = self::get_change_requests(array('website_id' => $website_id, 'status' => _CHANGE_REQUEST_STATUS_NEW)); // we also do completed ones because the change request highlight countbe in there $completed_change_requests = self::get_change_requests(array('website_id' => $website_id, 'status' => _CHANGE_REQUEST_STATUS_COMPLETE)); ?> jQuery(function(){ var current_url = window.location.href; <?php foreach ($change_requests as $change_request) { ?> if(current_url == '<?php echo addcslashes(htmlspecialchars($change_request['url']), "'"); ?> '){ // todo: do this better! dtbaker_changerequest.display_change(<?php echo $change_request['change_request_id']; ?> ); } <?php } ?> <?php // todo: do we display all previous change requests on the page or not? if (isset($_SESSION['_change_request_highlight']) && $_SESSION['_change_request_highlight']) { echo '// Checking for request: ' . (int) $_SESSION['_change_request_highlight']; foreach ($completed_change_requests as $complete_change_request) { if ($complete_change_request['change_request_id'] == $_SESSION['_change_request_highlight']) { // show this completed one as well. ?> dtbaker_changerequest.display_change(<?php echo $complete_change_request['change_request_id']; ?> ); <?php } } ?> dtbaker_changerequest.highlight(<?php echo (int) $_SESSION['_change_request_highlight']; ?> ); <?php // todo: move this unset over to the "display_change" callback so we only remove the session when we know it has been displayed. unset($_SESSION['_change_request_highlight']); } ?> }); <?php } } exit; break; case 'public': $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false; if ($website_id && $hash && module_change_request::link_public($website_id, true) == $hash) { // correct! // redirect to website with our "change_request" url parameter, that is picked up by the included text. $website = module_website::get_website($website_id); $change_request_website = get_single('change_request_website', 'website_id', $website_id); if ($change_request_website && $change_request_website['enabled']) { $url = module_website::urlify($website['url']); // todo - pass this to a (yet to be created) method in website that will deal with https:// or http:// based on user input. stop hardcoding http! if (isset($_REQUEST['change_request_id'])) { $selected_change_request = self::get_change_request_by_website($website_id, (int) $_REQUEST['change_request_id']); if ($selected_change_request && $selected_change_request['url']) { $url = $selected_change_request['url']; } //$url .= "&change_request_id=".(int)$_REQUEST['change_request_id']; $_SESSION['_change_request_highlight'] = (int) $_REQUEST['change_request_id']; } $url = $url . (strpos($url, '?') === false ? '?' : '&') . 'change_request=' . self::link_script($website_id, true); redirect_browser($url); } } echo "Change request disabled."; break; } }
print_heading(array('type' => 'h2', 'main' => true, 'title' => _l('Customer ' . module_config::c('project_name_plural', 'Websites')), 'button' => $header_buttons)); ?> <form action="" method="post"> <?php $search_bar = array('elements' => array('name' => array('title' => _l('Name/URL:'), 'field' => array('type' => 'text', 'name' => 'search[generic]', 'value' => isset($search['generic']) ? $search['generic'] : '', 'size' => 30)), 'status' => array('title' => _l('Status:'), 'field' => array('type' => 'select', 'name' => 'search[status]', 'value' => isset($search['status']) ? $search['status'] : '', 'options' => module_website::get_statuses())))); echo module_form::search_bar($search_bar); /** START TABLE LAYOUT **/ $table_manager = module_theme::new_table_manager(); $columns = array(); $columns['website_name'] = array('title' => 'Name', 'callback' => function ($website) { echo module_website::link_open($website['website_id'], true, $website); }, 'cell_class' => 'row_action'); if (module_config::c('project_display_url', 1)) { $columns['website_url'] = array('title' => 'URL', 'callback' => function ($website) { if (strlen(trim($website['url'])) > 0) { ?> <a href="<?php echo module_website::urlify($website['url']); ?> " target="_blank"><?php echo module_website::urlify($website['url']); ?> </a> <?php }
function customer_admin_email_generate_invoice_list($invoices, $customer_id) { ob_start(); $colspan = 9; $colspan2 = 0; $invoice_total = array(); $invoice_total_due = array(); foreach ($invoices as $invoice) { if (!isset($invoice_total[$invoice['currency_id']])) { $invoice_total[$invoice['currency_id']] = 0; } if ($invoice['c_total_amount'] == 0) { $invoice = module_invoice::get_invoice($invoice['invoice_id']); } $invoice_total[$invoice['currency_id']] += $invoice['c_total_amount']; if (!isset($invoice_total_due[$invoice['currency_id']])) { $invoice_total_due[$invoice['currency_id']] = 0; } $invoice_total_due[$invoice['currency_id']] += $invoice['c_total_amount_due']; } $table_manager = module_theme::new_table_manager(); $columns = array(); $columns['invoice_number'] = array('title' => 'Invoice Number', 'callback' => function ($invoice) { //echo module_invoice::link_open($invoice['invoice_id'],true,$invoice); echo '<a href="' . module_invoice::link_public($invoice['invoice_id']) . '">' . htmlspecialchars($invoice['name']) . '</a>'; }, 'cell_class' => 'row_action'); $columns['invoice_status'] = array('title' => 'Status', 'callback' => function ($invoice) { echo htmlspecialchars($invoice['status']); }); $columns['invoice_create_date'] = array('title' => 'Create Date', 'callback' => function ($invoice) { if (!$invoice['date_create'] || $invoice['date_create'] == '0000-00-00') { //echo print_date($invoice['date_created']); } else { echo print_date($invoice['date_create']); } }); $columns['invoice_due_date'] = array('title' => 'Due Date', 'callback' => function ($invoice) { if ((!$invoice['date_paid'] || $invoice['date_paid'] == '0000-00-00') && strtotime($invoice['date_due']) < time()) { echo '<span class="error_text">'; echo print_date($invoice['date_due']); echo '</span>'; } else { echo print_date($invoice['date_due']); } }); $columns['invoice_sent_date'] = array('title' => 'Sent Date', 'callback' => function ($invoice) { if ($invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') { ?> <?php echo print_date($invoice['date_sent']); ?> <?php } else { ?> <span class="error_text"><?php _e('Not sent'); ?> </span> <?php } }); $columns['invoice_paid_date'] = array('title' => 'Paid Date', 'callback' => function ($invoice) { if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') { ?> <?php echo print_date($invoice['date_paid']); ?> <?php } else { if ($invoice['date_cancel'] && $invoice['date_cancel'] != '0000-00-00') { ?> <span class="error_text"><?php _e('Cancelled'); ?> </span> <?php } else { if ($invoice['overdue']) { ?> <span class="error_text" style="font-weight: bold; text-decoration: underline;"><?php _e('Overdue'); ?> </span> <?php } else { ?> <span class="error_text"><?php _e('Not paid'); ?> </span> <?php } } } }); if (class_exists('module_website', false) && module_website::is_plugin_enabled() && module_website::can_i('view', module_config::c('project_name_plural', 'Websites'))) { $colspan++; $columns['invoice_website'] = array('title' => module_config::c('project_name_single', 'Website'), 'callback' => function ($invoice) { if (isset($invoice['website_ids'])) { foreach ($invoice['website_ids'] as $website_id) { if ((int) $website_id > 0) { echo module_website::link_open($website_id, true); echo '<br/>'; } } } }); } $columns['invoice_job'] = array('title' => 'Job', 'callback' => function ($invoice) { foreach ($invoice['job_ids'] as $job_id) { if ((int) $job_id > 0) { //echo module_job::link_open($job_id,true); $job_data = module_job::get_job($job_id); echo '<a href="' . module_job::link_public($job_id) . '">' . htmlspecialchars($job_data['name']) . '</a>'; if ($job_data['date_start'] && $job_data['date_start'] != '0000-00-00' && $job_data['date_renew'] && $job_data['date_renew'] != '0000-00-00') { _e(' (%s to %s)', print_date($job_data['date_start']), print_date(strtotime("-1 day", strtotime($job_data['date_renew'])))); } echo "<br/>\n"; } } hook_handle_callback('invoice_admin_list_job', $invoice['invoice_id']); }); if (!isset($_REQUEST['customer_id']) && module_customer::can_i('view', 'Customers')) { $colspan++; $columns['invoice_customer'] = array('title' => 'Customer', 'callback' => function ($invoice) { echo module_customer::link_open($invoice['customer_id'], true); }); } $columns['c_invoice_total'] = array('title' => 'Invoice Total', 'callback' => function ($invoice) { echo dollar($invoice['total_amount'], true, $invoice['currency_id']); }); $columns['c_invoice_total_due'] = array('title' => 'Amount Due', 'callback' => function ($invoice) { echo dollar($invoice['total_amount_due'], true, $invoice['currency_id']); ?> <?php if ($invoice['total_amount_credit'] > 0) { ?> <span class="success_text"><?php echo _l('Credit: %s', dollar($invoice['total_amount_credit'], true, $invoice['currency_id'])); ?> </span> <?php } }); if (class_exists('module_extra', false)) { ob_start(); $colspan2 += module_extra::print_table_header('invoice'); // used in the footer calc. ob_end_clean(); $table_manager->display_extra('invoice', function ($invoice) { module_extra::print_table_data('invoice', $invoice['invoice_id']); }); } $table_manager->set_columns($columns); $table_manager->row_callback = function ($row_data) { // load the full vendor data before displaying each row so we have access to more details if (isset($row_data['invoice_id']) && (int) $row_data['invoice_id'] > 0) { return module_invoice::get_invoice($row_data['invoice_id']); } return array(); }; $table_manager->set_rows($invoices); if (module_config::c('invoice_list_show_totals', 1)) { $footer_rows = array(); foreach ($invoice_total + $invoice_total_due as $currency_id => $foo) { $currency = get_single('currency', 'currency_id', $currency_id); $footer_rows[] = array('invoice_number' => array('data' => '<strong>' . _l('%s Totals:', $currency && isset($currency['code']) ? $currency['code'] : '') . '</strong>', 'cell_colspan' => $colspan - 2, 'cell_class' => 'text-right'), 'c_invoice_total' => array('data' => '<strong>' . dollar(isset($invoice_total[$currency_id]) ? $invoice_total[$currency_id] : 0, true, $currency_id) . '</strong>'), 'c_invoice_total_due' => array('data' => '<strong>' . dollar(isset($invoice_total_due[$currency_id]) ? $invoice_total_due[$currency_id] : 0, true, $currency_id) . '</strong>'), 'row_bulk_action' => array('data' => ' ', 'cell_colspan' => $colspan2)); } $table_manager->set_footer_rows($footer_rows); } $table_manager->pagination = false; $table_manager->print_table(); return ob_get_clean(); }
foreach ($total_paid as $id => $t) { $total_paid[$id] = dollar($t, true, $id); } foreach ($total_unpaid as $id => $t) { $total_unpaid[$id] = dollar($t, true, $id); } ?> <tr> <td><?php switch ($subscribed_customer['owner_table']) { case 'customer': echo module_customer::link_open($subscribed_customer['owner_id'], true); break; case 'website': echo module_website::link_open($subscribed_customer['owner_id'], true); break; case 'member': echo module_member::link_open($subscribed_customer['owner_id'], true); break; } ?> </td> <td><?php echo print_date($subscribed_customer['start_date']); ?> </td> <td><?php echo print_date($subscribed_customer['next_due_date']); ?> </td>
public function external_hook($hook) { switch ($hook) { case 'public_signup_form': $signup_form = module_template::get_template_by_key('customer_signup_form_wrapper'); $signup_form->page_title = $signup_form->description; $signup_form->assign_values(array('signup_form' => self::get_customer_signup_form_html())); echo $signup_form->render('pretty_html'); exit; case 'public_signup': // sign out if testing. if (module_security::is_logged_in()) { set_message('Logged out due to signup'); module_security::logout(); } $result = array('messages' => array()); function customer_signup_complete($result) { if (isset($_REQUEST['via_ajax'])) { echo json_encode($result); } else { echo implode('<br/>', $result['messages']); } exit; } if (!module_config::c('customer_signup_allowed', 0)) { $result['error'] = 1; $result['messages'][] = 'Customer signup disabled'; customer_signup_complete($result); } //recaptcha on signup form. if (module_config::c('captcha_on_signup_form', 0)) { if (!module_captcha::check_captcha_form()) { $result['error'] = 1; $result['messages'][] = 'Captcha fail, please go back and enter correct captcha code.'; customer_signup_complete($result); } } $customer = isset($_POST['customer']) && is_array($_POST['customer']) ? $_POST['customer'] : array(); $contact = isset($_POST['contact']) && is_array($_POST['contact']) ? $_POST['contact'] : array(); $contact_extra = isset($contact['extra']) && is_array($contact['extra']) ? $contact['extra'] : array(); $contact_group = isset($contact['group_ids']) && is_array($contact['group_ids']) ? $contact['group_ids'] : array(); $customer_extra = isset($customer['extra']) ? $customer['extra'] : array(); $customer_group = isset($customer['group_ids']) && is_array($customer['group_ids']) ? $customer['group_ids'] : array(); $address = isset($_POST['address']) ? $_POST['address'] : array(); $website = isset($_POST['website']) ? $_POST['website'] : array(); $website_extra = isset($website['extra']) ? $website['extra'] : array(); $website_group = isset($website['group_ids']) && is_array($website['group_ids']) ? $website['group_ids'] : array(); $job = isset($_POST['job']) ? $_POST['job'] : array(); $job_extra = isset($job['extra']) ? $job['extra'] : array(); $subscription = isset($_POST['subscription']) ? $_POST['subscription'] : array(); // sanatise possibly problematic fields: // customer: $allowed = array('name', 'last_name', 'customer_name', 'email', 'phone', 'mobile', 'extra', 'type'); foreach ($customer as $key => $val) { if (!in_array($key, $allowed)) { unset($customer[$key]); } } if (isset($customer['type']) && $customer['type'] != _CUSTOMER_TYPE_NORMAL && $customer['type'] != _CUSTOMER_TYPE_LEAD) { unset($customer['type']); } // added multiple contact support in the form of arrays. $contact_fields = array('name', 'last_name', 'email', 'phone'); if (module_config::c('customer_signup_password', 0)) { $contact_fields[] = 'password'; } foreach ($contact_fields as $multi_value) { if (isset($contact[$multi_value])) { if (!is_array($contact[$multi_value])) { $contact[$multi_value] = array($contact[$multi_value]); } } else { if (isset($customer[$multi_value])) { $contact[$multi_value] = array($customer[$multi_value]); } else { $contact[$multi_value] = array(); } } } $valid_contact_email = false; $name_fallback = false; $primary_email = false; foreach ($contact['email'] as $contact_key => $email) { if (!$name_fallback && isset($contact['name'][$contact_key])) { $name_fallback = $contact['name'][$contact_key]; } $contact['email'][$contact_key] = filter_var(strtolower(trim($email)), FILTER_VALIDATE_EMAIL); if ($contact['email'][$contact_key]) { $valid_contact_email = true; if (!$primary_email) { $primary_email = $contact['email'][$contact_key]; // set the primary contact details here by adding them to the master customer array foreach ($contact_fields as $primary_contact_field) { $customer[$primary_contact_field] = isset($contact[$primary_contact_field][$contact_key]) ? $contact[$primary_contact_field][$contact_key] : ''; unset($contact[$primary_contact_field][$contact_key]); } } } } // start error checking / required fields if (!isset($customer['customer_name']) || !strlen($customer['customer_name'])) { $customer['customer_name'] = $name_fallback; } if (!strlen($customer['customer_name'])) { $result['error'] = 1; $result['messages'][] = "Failed, please go back and provide a customer name."; } if (!$valid_contact_email || !$primary_email) { $result['error'] = 1; $result['messages'][] = "Failed, please go back and provide an email address."; } // check all posted required fields. function check_required($postdata, $messages = array()) { if (is_array($postdata)) { foreach ($postdata as $key => $val) { if (strpos($key, '_required') && strlen($val)) { $required_key = str_replace('_required', '', $key); if (!isset($postdata[$required_key]) || !$postdata[$required_key]) { $messages[] = 'Required field missing: ' . htmlspecialchars($val); } } if (is_array($val)) { $messages = check_required($val, $messages); } } } return $messages; } $messages = check_required($_POST); if (count($messages)) { $result['error'] = 1; $result['messages'] = array_merge($result['messages'], $messages); } if (isset($result['error'])) { customer_signup_complete($result); } // end error checking / required fields. // check if this customer already exists in the system, based on email address $customer_id = false; $creating_new = true; $_REQUEST['user_id'] = 0; if (isset($customer['email']) && strlen($customer['email']) && !module_config::c('customer_signup_always_new', 0)) { $users = module_user::get_contacts(array('email' => $customer['email'])); foreach ($users as $user) { if (isset($user['customer_id']) && (int) $user['customer_id'] > 0) { // this user exists as a customer! yey! // add them to this listing. $customer_id = $user['customer_id']; $creating_new = false; $_REQUEST['user_id'] = $user['user_id']; // dont let signups update existing passwords. if (isset($customer['password'])) { unset($customer['password']); } if (isset($customer['new_password'])) { unset($customer['new_password']); } } } } $_REQUEST['extra_customer_field'] = array(); $_REQUEST['extra_user_field'] = array(); module_extra::$config['allow_new_keys'] = false; module_extra::$config['delete_existing_empties'] = false; // save customer extra fields. if (count($customer_extra)) { // format the address so "save_customer" handles the save for us foreach ($customer_extra as $key => $val) { $_REQUEST['extra_customer_field'][] = array('key' => $key, 'val' => $val); } } // save customer and customer contact details: $customer_id = $this->save_customer($customer_id, $customer); if (!$customer_id) { $result['error'] = 1; $result['messages'][] = 'System error: failed to create customer.'; customer_signup_complete($result); } $customer_data = module_customer::get_customer($customer_id); // todo - merge primary and secondary contact/extra/group saving into a single loop if (!$customer_data['primary_user_id']) { $result['error'] = 1; $result['messages'][] = 'System error: Failed to create customer contact.'; customer_signup_complete($result); } else { $role_id = module_config::c('customer_signup_role', 0); if ($role_id > 0) { module_user::add_user_to_role($customer_data['primary_user_id'], $role_id); } // save contact extra data (repeated below for additional contacts) if (isset($contact_extra[0]) && count($contact_extra[0])) { $_REQUEST['extra_user_field'] = array(); foreach ($contact_extra[0] as $key => $val) { $_REQUEST['extra_user_field'][] = array('key' => $key, 'val' => $val); } module_extra::save_extras('user', 'user_id', $customer_data['primary_user_id']); } // save contact groups if (isset($contact_group[0]) && count($contact_group[0])) { foreach ($contact_group[0] as $group_id => $tf) { if ($tf) { module_group::add_to_group($group_id, $customer_data['primary_user_id'], 'user'); } } } } foreach ($contact['email'] as $contact_key => $email) { // add any additional contacts to the customer. $users = module_user::get_contacts(array('email' => $email, 'customer_id' => $customer_id)); if (count($users)) { // this contact already exists for this customer, dont update/change it. continue; } $new_contact = array('customer_id' => $customer_id); foreach ($contact_fields as $primary_contact_field) { $new_contact[$primary_contact_field] = isset($contact[$primary_contact_field][$contact_key]) ? $contact[$primary_contact_field][$contact_key] : ''; } // dont let additional contacts have passwords. if (isset($new_contact['password'])) { unset($new_contact['password']); } if (isset($new_contact['new_password'])) { unset($new_contact['new_password']); } global $plugins; $contact_user_id = $plugins['user']->create_user($new_contact, 'signup'); if ($contact_user_id) { $role_id = module_config::c('customer_signup_role', 0); if ($role_id > 0) { module_user::add_user_to_role($contact_user_id, $role_id); } // save contact extra data (repeated below for primary contacts) if (isset($contact_extra[$contact_key]) && count($contact_extra[$contact_key])) { $_REQUEST['extra_user_field'] = array(); foreach ($contact_extra[$contact_key] as $key => $val) { $_REQUEST['extra_user_field'][] = array('key' => $key, 'val' => $val); } module_extra::save_extras('user', 'user_id', $contact_user_id); } // save contact groups if (isset($contact_group[$contact_key]) && count($contact_group[$contact_key])) { foreach ($contact_group[$contact_key] as $group_id => $tf) { if ($tf) { module_group::add_to_group($group_id, $contact_user_id, 'user'); } } } } } if (count($customer_group)) { // format the address so "save_customer" handles the save for us foreach ($customer_group as $group_id => $tf) { if ($tf) { module_group::add_to_group($group_id, $customer_id, 'customer'); } } } $note_keys = array('customer', 'website', 'job', 'address', 'subscription'); $note_text = _l('Customer signed up from Signup Form:'); $note_text .= "\n\n"; foreach ($note_keys as $note_key) { $note_text .= "\n" . ucwords(_l($note_key)) . "\n"; if (isset($_POST[$note_key]) && is_array($_POST[$note_key])) { foreach ($_POST[$note_key] as $post_key => $post_val) { $note_text .= "\n - " . _l($post_key) . ": "; if (is_array($post_val)) { foreach ($post_val as $p => $v) { $note_text .= "\n - - " . _l($p) . ': ' . $v; } } else { $note_text .= $post_val; } } } } $note_data = array('note_id' => false, 'owner_id' => $customer_id, 'owner_table' => 'customer', 'note_time' => time(), 'note' => $note_text, 'rel_data' => module_customer::link_open($customer_id), 'reminder' => 0, 'user_id' => 0); update_insert('note_id', false, 'note', $note_data); // save customer address fields. if (count($address)) { $address_db = module_address::get_address($customer_id, 'customer', 'physical'); $address_id = $address_db && isset($address_db['address_id']) ? (int) $address_db['address_id'] : false; $address['owner_id'] = $customer_id; $address['owner_table'] = 'customer'; $address['address_type'] = 'physical'; // we have post data to save, write it to the table!! module_address::save_address($address_id, $address); } // website: $allowed = array('url', 'name', 'extra', 'notes'); foreach ($website as $key => $val) { if (!in_array($key, $allowed)) { unset($website[$key]); } } $website['url'] = isset($website['url']) ? strtolower(trim($website['url'])) : ''; $website_id = 0; if (count($website) && class_exists('module_website', false) && module_website::is_plugin_enabled()) { if (strlen($website['url'])) { // see if website already exists, don't create or update existing one for now. $existing_websites = module_website::get_websites(array('customer_id' => $customer_id, 'url' => $website['url'])); foreach ($existing_websites as $existing_website) { $website_id = $existing_website['website_id']; } } // echo $website_id;echo $website['url']; print_r($website_extra);exit; if (!$website_id) { $website_data = module_website::get_website($website_id); $website_data['url'] = isset($website['url']) ? $website['url'] : 'N/A'; $website_data['name'] = isset($website['url']) ? $website['url'] : 'N/A'; $website_data['customer_id'] = $customer_id; $website_id = update_insert('website_id', false, 'website', $website_data); // save website extra data. if ($website_id && count($website_extra)) { $_REQUEST['extra_website_field'] = array(); foreach ($website_extra as $key => $val) { $_REQUEST['extra_website_field'][] = array('key' => $key, 'val' => $val); } module_extra::save_extras('website', 'website_id', $website_id); } if ($website_id && isset($website['notes']) && strlen($website['notes'])) { // add notes to this website. $note_data = array('note_id' => false, 'owner_id' => $website_id, 'owner_table' => 'website', 'note_time' => time(), 'note' => $website['notes'], 'rel_data' => module_website::link_open($website_id), 'reminder' => 0, 'user_id' => $customer_data['primary_user_id']); $note_id = update_insert('note_id', false, 'note', $note_data); } } if ($website_id) { if (count($website_group)) { // format the address so "save_customer" handles the save for us foreach ($website_group as $group_id => $tf) { if ($tf) { module_group::add_to_group($group_id, $website_id, 'website'); } } } } } // generate jobs for this customer. $job_created = array(); if ($job && isset($job['type']) && is_array($job['type'])) { if (module_config::c('customer_signup_any_job_type', 0)) { foreach ($job['type'] as $type_name) { // we have a match in our system. create the job. $job_data = module_job::get_job(false); $job_data['type'] = $type_name; if (!$job_data['name']) { $job_data['name'] = $type_name; } $job_data['website_id'] = $website_id; $job_data['customer_id'] = $customer_id; $job_id = update_insert('job_id', false, 'job', $job_data); // todo: add default tasks for this job type. $job_created[] = $job_id; } } else { foreach (module_job::get_types() as $type_id => $type) { foreach ($job['type'] as $type_name) { if ($type_name == $type) { // we have a match in our system. create the job. $job_data = module_job::get_job(false); $job_data['type'] = $type; if (!$job_data['name']) { $job_data['name'] = $type; } $job_data['website_id'] = $website_id; $job_data['customer_id'] = $customer_id; $job_id = update_insert('job_id', false, 'job', $job_data); // todo: add default tasks for this job type. $job_created[] = $job_id; } } } } if (count($job_created) && count($job_extra)) { // save job extra data. foreach ($job_created as $job_created_id) { if ($job_created_id && count($job_extra)) { $_REQUEST['extra_job_field'] = array(); foreach ($job_extra as $key => $val) { $_REQUEST['extra_job_field'][] = array('key' => $key, 'val' => $val); } module_extra::save_extras('job', 'job_id', $job_created_id); } } } } // save files against customer $uploaded_files = array(); if (isset($_FILES['customerfiles']) && isset($_FILES['customerfiles']['tmp_name'])) { foreach ($_FILES['customerfiles']['tmp_name'] as $file_id => $tmp_file) { if (is_uploaded_file($tmp_file)) { // save to file module for this customer $file_name = basename($_FILES['customerfiles']['name'][$file_id]); if (strlen($file_name)) { $file_path = 'includes/plugin_file/upload/' . md5(time() . $file_name); if (move_uploaded_file($tmp_file, $file_path)) { // success! write to db. $file_data = array('customer_id' => $customer_id, 'job_id' => current($job_created), 'website_id' => $website_id, 'status' => module_config::c('file_default_status', 'Uploaded'), 'pointers' => false, 'description' => "Uploaded from Customer Signup form", 'file_time' => time(), 'file_name' => $file_name, 'file_path' => $file_path, 'file_url' => false); $file_id = update_insert('file_id', false, 'file', $file_data); $uploaded_files[] = $file_id; } } } } } // we create subscriptions for this customer/website (if none already exist) $subscription['subscription_name'] = array(); $subscription['subscription_invoice'] = array(); if (class_exists('module_subscription', false) && module_subscription::is_plugin_enabled() && isset($subscription['for']) && isset($subscription['subscriptions'])) { if ($subscription['for'] == 'website' && $website_id > 0) { $owner_table = 'website'; $owner_id = $website_id; } else { $owner_table = 'customer'; $owner_id = $customer_id; } $available_subscriptions = module_subscription::get_subscriptions(); $members_subscriptions = module_subscription::get_subscriptions_by($owner_table, $owner_id); foreach ($subscription['subscriptions'] as $subscription_id => $tf) { if (isset($available_subscriptions[$subscription_id])) { if (isset($members_subscriptions[$subscription_id])) { // we don't allow a member to sign up to the same subscription twice (just yet) } else { $subscription['subscription_name'][$subscription_id] = $available_subscriptions[$subscription_id]['name']; $start_date = date('Y-m-d'); $start_modifications = module_config::c('customer_signup_subscription_start', ''); if ($start_modifications == 'hidden') { $start_modifications = isset($_REQUEST['customer_signup_subscription_start']) ? $_REQUEST['customer_signup_subscription_start'] : ''; } if (!empty($start_modifications)) { $start_date = date('Y-m-d', strtotime($start_modifications)); } $sql = "INSERT INTO `" . _DB_PREFIX . "subscription_owner` SET "; $sql .= " owner_id = '" . (int) $owner_id . "'"; $sql .= ", owner_table = '" . mysql_real_escape_string($owner_table) . "'"; $sql .= ", subscription_id = '" . (int) $subscription_id . "'"; $sql .= ", start_date = '{$start_date}'"; query($sql); module_subscription::update_next_due_date($subscription_id, $owner_table, $owner_id, true); // and the same option here to send a subscription straight away upon signup if (module_config::c('subscription_send_invoice_straight_away', 0)) { global $plugins; $plugins['subscription']->run_cron(); // check if there are any invoices for this subscription $history = module_subscription::get_subscription_history($subscription_id, $owner_table, $owner_id); if (count($history) > 0) { foreach ($history as $h) { if ($h['invoice_id']) { $invoice_data = module_invoice::get_invoice($h['invoice_id']); if ($invoice_data['date_cancel'] != '0000-00-00') { continue; } $subscription['subscription_invoice'][] = '<a href="' . module_invoice::link_public($h['invoice_id']) . '">' . _l('Invoice #%s for %s', htmlspecialchars($invoice_data['name']), dollar($invoice_data['total_amount'], true, $invoice_data['currency_id'])) . '</a>'; } } } } } } } } if (!count($subscription['subscription_name'])) { $subscription['subscription_name'][] = _l('N/A'); } if (!count($subscription['subscription_invoice'])) { $subscription['subscription_invoice'][] = _l('N/A'); } $subscription['subscription_name'] = implode(', ', $subscription['subscription_name']); $subscription['subscription_invoice'] = implode(', ', $subscription['subscription_invoice']); // email the admin when a customer signs up. $values = array_merge($customer, $customer_extra, $website, $website_extra, $address, $subscription); $values['customer_name'] = $customer['customer_name']; $values['CUSTOMER_LINK'] = module_customer::link_open($customer_id); $values['CUSTOMER_NAME_LINK'] = module_customer::link_open($customer_id, true); if ($website_id) { $values['WEBSITE_LINK'] = module_website::link_open($website_id); $values['WEBSITE_NAME_LINK'] = module_website::link_open($website_id, true); } else { $values['WEBSITE_LINK'] = _l('N/A'); $values['WEBSITE_NAME_LINK'] = _l('N/A'); } $values['JOB_LINKS'] = ''; if (count($job_created)) { $values['JOB_LINKS'] .= 'The customer created ' . count($job_created) . ' jobs in the system: <br>'; foreach ($job_created as $job_created_id) { $values['JOB_LINKS'] .= module_job::link_open($job_created_id, true) . "<br>\n"; } } else { $values['JOB_LINKS'] = _l('N/A'); } if (count($uploaded_files)) { $values['uploaded_files'] = 'The customer uploaded ' . count($uploaded_files) . " files:<br>\n"; foreach ($uploaded_files as $uploaded_file) { $values['uploaded_files'] .= module_file::link_open($uploaded_file, true) . "<br>\n"; } } else { $values['uploaded_files'] = 'No files were uploaded'; } $values['WEBSITE_NAME'] = isset($website['url']) ? $website['url'] : 'N/A'; if (!$creating_new) { $values['system_note'] = "Note: this signup updated the existing customer record in the system."; } else { $values['system_note'] = "Note: this signup created a new customer record in the system."; } $customer_signup_template = module_config::c('customer_signup_email_admin_template', 'customer_signup_email_admin'); if (isset($_REQUEST['customer_signup_email_admin_template'])) { $customer_signup_template = $_REQUEST['customer_signup_email_admin_template']; } if ($customer_signup_template) { $template = module_template::get_template_by_key($customer_signup_template); if ($template->template_id) { $template->assign_values($values); $html = $template->render('html'); $email = module_email::new_email(); $email->replace_values = $values; $email->set_subject($template->description); $email->set_to_manual(module_config::c('customer_signup_admin_email', module_config::c('admin_email_address'))); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! } else { /// log err? } } } $customer_signup_template = module_config::c('customer_signup_email_welcome_template', 'customer_signup_email_welcome'); if (isset($_REQUEST['customer_signup_email_welcome_template'])) { $customer_signup_template = $_REQUEST['customer_signup_email_welcome_template']; } if ($customer_signup_template) { $template = module_template::get_template_by_key($customer_signup_template); if ($template->template_id) { $template->assign_values($values); $html = $template->render('html'); $email = module_email::new_email(); $email->customer_id = $customer_id; $email->replace_values = $values; $email->set_subject($template->description); $email->set_to('user', $customer_data['primary_user_id']); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! } else { /// log err? } } } //todo: optional redirect to url if (isset($_REQUEST['via_ajax'])) { echo json_encode(array('success' => 1, 'customer_id' => $customer_id)); exit; } if (module_config::c('customer_signup_redirect', '')) { redirect_browser(module_config::c('customer_signup_redirect', '')); } // load up the thank you template. $template = module_template::get_template_by_key('customer_signup_thank_you_page'); $template->page_title = _l("Customer Signup"); foreach ($values as $key => $val) { if (!is_array($val)) { $values[$key] = htmlspecialchars($val); } } $template->assign_values($values); echo $template->render('pretty_html'); exit; break; } }
* IP Address: 67.79.165.254 */ if (!count($change_requests)) { return; } $jobs = module_job::get_jobs(array('website_id' => $website_id)); // pull out jobs that don't have an invoice. foreach ($jobs as $job_id => $job) { $invoices = module_invoice::get_invoices(array('job_id' => $job['job_id'])); if (count($invoices)) { unset($jobs[$job_id]); } } $h = array('type' => 'h3', 'title' => 'Customer Change Requests'); // find out how many changes are incomplete $link_toggle = module_website::link_open($website_id); $show_completed = isset($_REQUEST['show_completed_change_requests']) ? $_REQUEST['show_completed_change_requests'] : false; $num_completed = 0; foreach ($change_requests as $change_request) { if ($change_request['status'] == _CHANGE_REQUEST_STATUS_COMPLETE) { $num_completed++; } } if ($num_completed) { if ($show_completed) { $h['button'] = array('title' => _l('Hide %s completed changes', $num_completed), 'url' => $link_toggle .= '&show_completed_change_requests=0'); } else { $h['button'] = array('title' => _l('Show %s completed changes', $num_completed), 'url' => $link_toggle .= '&show_completed_change_requests=1'); } } //print_heading($h);
echo module_form::search_bar($search_bar); /** START TABLE LAYOUT **/ $table_manager = module_theme::new_table_manager(); $columns = array(); $columns['quote_title'] = array('title' => 'Quote Title', 'callback' => function ($quote) { echo module_quote::link_open($quote['quote_id'], true, $quote); }, 'cell_class' => 'row_action'); $columns['quote_start_date'] = array('title' => 'Create Date', 'callback' => function ($quote) { echo print_date($quote['date_create']); }); $columns['quote_completed_date'] = array('title' => 'Accepted Date', 'callback' => function ($quote) { echo print_date($quote['date_approved']); }); if (class_exists('module_website', false) && module_website::is_plugin_enabled()) { $columns['quote_website'] = array('title' => module_config::c('project_name_single', 'Website'), 'callback' => function ($quote) { echo module_website::link_open($quote['website_id'], true); }); } if (!isset($_REQUEST['customer_id']) && module_customer::can_i('view', 'Customers')) { $columns['quote_customer'] = array('title' => 'Customer', 'callback' => function ($quote) { echo module_customer::link_open($quote['customer_id'], true); }); } $columns['quote_type'] = array('title' => 'Type', 'callback' => function ($quote) { echo htmlspecialchars($quote['type']); }); $columns['quote_status'] = array('title' => 'Status', 'callback' => function ($quote) { echo htmlspecialchars($quote['status']); }); if (module_config::c('quote_allow_staff_assignment', 1)) { $columns['quote_staff'] = array('title' => 'Staff Member', 'callback' => function ($quote) {
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; }
$res = module_website::get_websites(array('customer_id' => isset($_REQUEST['customer_id']) ? (int) $_REQUEST['customer_id'] : ($invoice['customer_id'] ? $invoice['customer_id'] : false))); //$res = module_website::get_websites(); while ($row = array_shift($res)) { $c[$row['website_id']] = $row['name']; } echo print_select_box($c, 'website_id', $invoice['website_id']); } else { if ($invoice['website_id']) { echo module_website::link_open($invoice['website_id'], true); } else { _e('N/A'); } } foreach ($website_ids as $website_id) { if ($website_id) { echo ' ' . module_website::link_open($website_id, true); } } })); } else { if (!class_exists('module_website', false) && module_config::c('show_ucm_ads', 1)) { $fieldset_data['elements'][] = array('title' => module_config::c('project_name_single', 'Website'), 'fields' => array('(website option available in <a href="http://codecanyon.net/item/ultimate-client-manager-pro-edition/2621629?ref=dtbaker" target="_blank">UCM Pro Edition</a>)')); } } $fieldset_data['elements'][] = array('title' => 'Tax Type', 'field' => array('type' => 'select', 'blank' => false, 'options' => array('0' => _l('Tax Added'), 1 => _l('Tax Included')), 'name' => 'tax_type', 'value' => $invoice['tax_type'])); if ($discounts_allowed) { $fieldset_data['elements'][] = array('title' => 'Discount Amount', 'fields' => array(function () use($invoice_locked, $invoice_id, &$invoice) { echo $invoice_locked || !module_security::is_page_editable() ? '<span class="currency">' . dollar($invoice['discount_amount'], true, $invoice['currency_id']) . '</span>' : currency('<input type="text" name="discount_amount" value="' . number_out($invoice['discount_amount']) . '" class="currency">'); echo ' '; }, array('type' => 'html', 'value' => '', 'help' => 'Here you can apply a before tax discount to this invoice. You can name this anything, eg: DISCOUNT, CREDIT, REFUND, etc..'))); $fieldset_data['elements'][] = array('title' => 'Discount Name', 'fields' => array(function () use($invoice_id, &$invoice) {
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; }
<?php /** * Copyright: dtbaker 2012 * Licence: Please check CodeCanyon.net for licence details. * More licence clarification available here: http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca * Package Date: 2015-11-25 02:55:20 * IP Address: 67.79.165.254 */ if (!module_change_request::can_i('delete', 'Change Requests')) { die('no perms'); } $change_request_id = (int) $_REQUEST['change_request_id']; $change_request = module_change_request::get_change_request($change_request_id); if (!$change_request['website_id']) { die('no linked website'); } $website_data = module_website::get_website($change_request['website_id']); if (module_form::confirm_delete('change_request_id', "Really delete Change Request?", module_website::link_open($change_request['website_id']))) { module_change_request::delete_change_request($_REQUEST['change_request_id']); set_message("Change request deleted successfully"); redirect_browser(module_website::link_open($change_request['website_id'])); }
Thank you,<br><br> {FROM_NAME} ', 'Change Request: {URL}', array('NAME' => 'Customers Name', 'URL' => 'Website address', 'REQUEST' => 'Change REquest', 'FROM_NAME' => 'Your name', 'CHANGE_REQUEST_URL' => 'Link to change request for customer')); // template for sending emails. // are we sending the paid one? or the dueone. //$template_name = 'change_request_email'; $template_name = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : 'change_request_email'; $template = module_template::get_template_by_key($template_name); $change_request['from_name'] = module_security::get_loggedin_name(); $change_request['change_request_url'] = module_change_request::link_public_change($website_data['website_id'], $change_request_id); ob_start(); $change_request['change_request_tasks'] = ob_get_clean(); // find available "to" recipients. // customer contacts. $to_select = false; if ($website_data['customer_id']) { $customer = module_customer::get_customer($website_data['customer_id']); $change_request['customer_name'] = $customer['customer_name']; $to = module_user::get_contacts(array('customer_id' => $website_data['customer_id'])); if ($customer['primary_user_id']) { $primary = module_user::get_user($customer['primary_user_id']); if ($primary) { $to_select = $primary['email']; } } } else { $to = array(); } $template->assign_values($change_request); module_email::print_compose(array('find_other_templates' => 'change_request_email', 'current_template' => $template_name, 'customer_id' => $website_data['customer_id'], 'change_request_id' => $change_request['change_request_id'], 'debug_message' => 'Sending change request email', 'to' => $to, 'to_select' => $to_select, 'bcc' => module_config::c('admin_email_address', ''), 'content' => $template->render('html'), 'subject' => $template->replace_description(), 'success_url' => module_website::link_open($website_data['website_id']), 'cancel_url' => module_website::link_open($website_data['website_id'])));