function init() { $this->module_name = "language"; $language_code = basename(module_config::c('default_language')); if (module_security::is_logged_in()) { $user = module_user::get_user(module_security::get_loggedin_id(), false); if ($user && $user['user_id'] && isset($user['language']) && $user['language']) { $language_code = basename($user['language']); } } // language code, like en, gb, etc.. self::set_ui_language($language_code); }
if ($customer['primary_user_id']) { module_user::print_contact_summary($customer['primary_user_id'], 'html', array('phone|mobile')); } else { echo ''; } }); $columns['date_created'] = array('title' => 'Date Created', 'callback' => function ($customer) { if ($customer['primary_user_id']) { module_user::print_contact_summary($customer['primary_user_id'], 'html', array('date_created')); } else { echo ''; } }); $columns['primary_contact_email'] = array('title' => 'Email Address', 'callback' => function ($customer) { if ($customer['primary_user_id']) { module_user::print_contact_summary($customer['primary_user_id'], 'html', array('email')); } else { echo ''; } }); if (class_exists('module_group', false) && module_customer::can_i('view', $page_type_single . ' Groups')) { $columns['customer_group'] = array('title' => 'Group', 'callback' => function ($customer) { if (isset($customer['group_sort_customer'])) { echo htmlspecialchars($customer['group_sort_customer']); } else { // find the groups for this customer. $groups = module_group::get_groups_search(array('owner_table' => 'customer', 'owner_id' => $customer['customer_id'])); $g = array(); foreach ($groups as $group) { $g[] = $group['name']; }
$columns['email'] = array('title' => 'Email Address', 'callback' => function ($user) { module_user::print_contact_summary($user['user_id'], 'html', array('email')); }); if ($show_customer_details) { $columns['customer'] = array('title' => $contact_type_permission, 'callback' => function ($user) use($contact_module_name) { switch ($contact_module_name) { case 'customer': echo module_customer::link_open($user['customer_id'], true, $user); break; case 'vendor': echo module_vendor::link_open($user['vendor_id'], true, $user); break; } }); } if (class_exists('module_group', false) && module_user::can_i('view', 'Contact Groups')) { $columns['group'] = array('title' => 'Group', 'callback' => function ($user) { $groups = module_group::get_groups_search(array('owner_table' => 'user', 'owner_id' => $user['user_id'])); $g = array(); foreach ($groups as $group) { $g[] = $group['name']; } echo implode(', ', $g); }); } $table_manager->set_columns($columns); $table_manager->row_callback = function ($row_data) { // load the full vendor data before displaying each row so we have access to more details return $row_data; //module_user::get_user($row_data['user_id']); };
$for_email=true; include('quote_public.php'); $quote['quote_tasks'] = ob_get_clean();*/ // generate the PDF ready for sending. $pdf = module_quote::generate_pdf($quote_id); // find available "to" recipients. // customer contacts. $to_select = false; if ($quote['customer_id']) { $customer = module_customer::get_customer($quote['customer_id']); $quote['customer_name'] = $customer['customer_name']; $to = module_user::get_contacts(array('customer_id' => $quote['customer_id'])); if ($quote['contact_user_id']) { $primary = module_user::get_user($quote['contact_user_id']); if ($primary) { $to_select = $primary['email']; } } else { 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($quote); ob_start(); module_email::print_compose(array('title' => _l('Email Quote: %s', $quote['name']), 'find_other_templates' => 'quote_email', 'current_template' => $template_name, 'customer_id' => $quote['customer_id'], 'quote_id' => $quote['quote_id'], 'debug_message' => 'Sending quote as 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_quote::link_open($quote_id), 'cancel_url' => module_quote::link_open($quote_id), 'attachments' => array(array('path' => $pdf, 'name' => basename($pdf), 'preview' => module_quote::link_public_print($quote_id)))));
})); if ($invoice['customer_id']) { $c = array(); $res = module_user::get_contacts(array('customer_id' => $invoice['customer_id'])); if (isset($invoice['primary_user_id']) && $invoice['primary_user_id']) { $primary_contact = isset($res[$invoice['primary_user_id']]) ? $res[$invoice['primary_user_id']] : false; } else { $primary_contact = false; } $c[0] = _l('Primary (%s)', $primary_contact ? htmlspecialchars($primary_contact['name'] . ' ' . $primary_contact['last_name']) : _l('N/A')); while ($row = array_shift($res)) { $c[$row['user_id']] = $row['name'] . ' ' . $row['last_name']; } if ($invoice['user_id'] && !isset($c[$invoice['user_id']])) { // this option isn't in the listing. add it in. $user_temp = module_user::get_user($invoice['user_id'], false); $c[$invoice['user_id']] = $user_temp['name'] . ' ' . $user_temp['last_name'] . ' ' . _l('(under different customer)'); } $fieldset_data['elements'][] = array('title' => 'Contact', 'field' => array('type' => 'select', 'name' => 'user_id', 'value' => $invoice['user_id'], 'options' => $c, 'blank' => false)); } echo module_form::generate_fieldset($fieldset_data); unset($fieldset_data); if ((int) $invoice_id > 0) { hook_handle_callback('invoice_sidebar', $invoice_id); } if ($invoice_id && $invoice_id != 'new') { $note_summary_owners = array(); // generate a list of all possible notes we can display for this invoice. // display all the notes which are owned by all the sites we have access to if (class_exists('module_note', false) && module_note::is_plugin_enabled()) { module_note::display_notes(array('title' => 'Invoice Notes', 'owner_table' => 'invoice', 'owner_id' => $invoice_id, 'view_link' => module_invoice::link_open($invoice_id), 'public' => array('enabled' => true, 'title' => 'Public', 'text' => 'Yes, show this note in invoice', 'help' => 'If this is ticked then this note will be available to the customer and will be included in the {INVOICE_NOTES} shortcode in the invoice template.')));
public static function get_finances($search = array()) { // we have to search for recent transactions. this involves combining the "finance" table with the "invoice_payment" table // then sort the results by date $hide_invoice_payments = false; $sql = "SELECT f.* "; $sql .= " , fa.name AS account_name "; $sql .= " , GROUP_CONCAT(fc.`name` ORDER BY fc.`name` ASC SEPARATOR ', ') AS categories "; $sql .= " FROM `" . _DB_PREFIX . "finance` f "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance_account` fa USING (finance_account_id) "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance_category_rel` fcr ON f.finance_id = fcr.finance_id "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance_category` fc ON fcr.finance_category_id = fc.finance_category_id "; $where = " WHERE 1 "; if (isset($search['finance_account_id']) && is_array($search['finance_account_id'])) { $fo = array(); foreach ($search['finance_account_id'] as $val) { if ((int) $val > 0) { $fo[(int) $val] = true; } } if (count($fo) > 0) { $where .= " AND ( "; foreach ($fo as $f => $ff) { $where .= " f.finance_account_id = " . $f . ' OR'; } $where = rtrim($where, 'OR'); $where .= ' )'; $hide_invoice_payments = true; } } if (isset($search['finance_recurring_id']) && $search['finance_recurring_id']) { $where .= " AND f.finance_recurring_id = '" . (int) $search['finance_recurring_id'] . "'"; $hide_invoice_payments = true; } if (isset($search['finance_category_id']) && is_array($search['finance_category_id'])) { $fo = array(); foreach ($search['finance_category_id'] as $val) { if ((int) $val > 0) { $fo[(int) $val] = true; } } if (count($fo) > 0) { $where .= " AND EXISTS ( SELECT * FROM `" . _DB_PREFIX . "finance_category_rel` fcr2 WHERE fcr2.finance_id = f.finance_id AND ( "; foreach ($fo as $f => $ff) { $where .= " fcr2.finance_category_id = " . $f . ' OR'; } $where = rtrim($where, 'OR'); $where .= ' )'; $where .= ' )'; $hide_invoice_payments = true; } } if (isset($search['invoice_payment_id']) && $search['invoice_payment_id']) { $where .= " AND f.invoice_payment_id = '" . (int) $search['invoice_payment_id'] . "'"; $hide_invoice_payments = true; } // below 6 searches are repeated again below in invoice payments if (isset($search['job_id']) && (int) $search['job_id'] > 0) { $where .= " AND f.`job_id` = " . (int) $search['job_id']; } if (isset($search['invoice_id']) && (int) $search['invoice_id'] > 0) { $where .= " AND f.`invoice_id` = " . (int) $search['invoice_id']; } if (isset($search['customer_id']) && (int) $search['customer_id'] > 0) { $where .= " AND f.`customer_id` = " . (int) $search['customer_id']; } if (isset($search['company_id']) && (int) $search['company_id'] > 0) { // check this user can view this company id or not if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled()) { $companys = module_company::get_companys(); if (isset($companys[$search['company_id']])) { $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_customer` cc ON f.customer_id = cc.customer_id "; $where .= " AND ( cc.`company_id` = " . (int) $search['company_id'] . " OR f.`company_id` = " . (int) $search['company_id'] . " )"; } } } if (isset($search['generic']) && strlen(trim($search['generic']))) { $name = mysql_real_escape_string(trim($search['generic'])); $where .= " AND (f.`name` LIKE '%{$name}%' OR f.description LIKE '%{$name}%' )"; } if (isset($search['date_from']) && $search['date_from'] != '') { $where .= " AND f.transaction_date >= '" . input_date($search['date_from']) . "'"; } if (isset($search['date_to']) && $search['date_to'] != '') { $where .= " AND f.transaction_date <= '" . input_date($search['date_to']) . "'"; } if (isset($search['amount_from']) && $search['amount_from'] != '') { $where .= " AND f.amount >= '" . mysql_real_escape_string($search['amount_from']) . "'"; } if (isset($search['amount_to']) && $search['amount_to'] != '') { $where .= " AND f.amount <= '" . mysql_real_escape_string($search['amount_to']) . "'"; } if (isset($search['type']) && $search['type'] != '' && $search['type'] != 'ie') { $where .= " AND f.type = '" . mysql_real_escape_string($search['type']) . "'"; } // permissions from job module. /*switch(module_job::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 "; //u.user_id = ".(int)module_security::get_loggedin_id()." OR $where .= " AND (t.user_id = ".(int)module_security::get_loggedin_id().")"; break; case _JOB_ACCESS_CUSTOMER: break; }*/ // permissions from customer module. // 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 f.customer_id IN ( "; foreach ($valid_customer_ids as $valid_customer_id) { $where .= (int) $valid_customer_id . ", "; } $where = rtrim($where, ', '); $where .= " )"; } } $where .= " GROUP BY f.finance_id "; $where .= " ORDER BY f.transaction_date DESC "; $sql .= $where; $finances_from_finance_db_table = qa($sql); // invoice payments: $finance_from_invoice_payments = array(); $finance_from_job_staff_expenses = array(); if (!$hide_invoice_payments && (!isset($search['invoice_id']) || !(int) $search['invoice_id'] > 0)) { $sql = "SELECT j.*, f.finance_id AS existing_finance_id "; $sql .= " FROM `" . _DB_PREFIX . "job` j "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance` f ON j.job_id = f.job_id AND f.job_staff_expense > 0 "; $where = " WHERE 1 "; //j.date_completed != '0000-00-00' "; $where .= " AND j.`c_staff_total_amount` > 0 "; if (isset($search['job_id']) && (int) $search['job_id'] > 0) { $where .= " AND (j.`job_id` = " . (int) $search['job_id'] . " ) "; } if (isset($search['customer_id']) && (int) $search['customer_id'] > 0) { $where .= " AND j.`customer_id` = " . (int) $search['customer_id']; } /*if(isset($search['generic']) && strlen(trim($search['generic']))){ $name = mysql_real_escape_string(trim($search['generic'])); $where .= " AND (i.`name` LIKE '%$name%' OR p.method LIKE '%$name%' )"; }*/ if (isset($search['company_id']) && (int) $search['company_id'] > 0) { // check this user can view this company id or not if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled()) { $companys = module_company::get_companys(); if (isset($companys[$search['company_id']])) { $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_customer` cc ON j.customer_id = cc.customer_id "; $where .= " AND cc.`company_id` = " . (int) $search['company_id']; } } } if (isset($search['date_from']) && $search['date_from'] != '') { $where .= " AND j.date_completed >= '" . input_date($search['date_from']) . "'"; } if (isset($search['date_to']) && $search['date_to'] != '') { $where .= " AND j.date_completed <= '" . input_date($search['date_to']) . "'"; } if (isset($search['amount_from']) && $search['amount_from'] != '') { $where .= " AND j.c_staff_total_amount >= '" . mysql_real_escape_string($search['amount_from']) . "'"; } if (isset($search['amount_to']) && $search['amount_to'] != '') { $where .= " AND j.c_staff_total_amount <= '" . mysql_real_escape_string($search['amount_to']) . "'"; } switch (module_job::get_job_access_permissions()) { case _JOB_ACCESS_ALL: break; case _JOB_ACCESS_ASSIGNED: // only assigned jobs! $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON j.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. $valid_customer_ids = module_security::get_customer_restrictions(); if (count($valid_customer_ids)) { $where .= " AND j.customer_id IN ( "; foreach ($valid_customer_ids as $valid_customer_id) { $where .= (int) $valid_customer_id . ", "; } $where = rtrim($where, ', '); $where .= " )"; } break; } 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 IN ( "; foreach ($valid_customer_ids as $valid_customer_id) { $where .= (int) $valid_customer_id . ", "; } $where = rtrim($where, ', '); $where .= " )"; } } $sql .= $where . " GROUP BY j.job_id ORDER BY j.date_completed DESC "; //echo $sql; $finance_from_job_staff_expenses = array(); $res = qa($sql); foreach ($res as $finance) { // we have a job with staff expenses. split this up into gruops based on staff members. $staff_total_grouped = false; if (isset($finance['c_staff_total_grouped']) && strlen($finance['c_staff_total_grouped'])) { $staff_total_grouped = @unserialize($finance['c_staff_total_grouped']); } if ($staff_total_grouped === false) { // echo 'here: '; // var_dump($finance); // var_dump($staff_total_grouped); $job_data = module_job::get_job($finance['job_id']); $staff_total_grouped = $job_data['staff_total_grouped']; } if (is_array($staff_total_grouped)) { foreach ($staff_total_grouped as $staff_id => $staff_total) { $staff_member = module_user::get_user($staff_id); if ($staff_member && $staff_member['user_id'] == $staff_id) { // make sure this entry doesn't already exist in the database table for this job // there MAY be an existing entry if 'existing_finance_id' is set if ($finance['existing_finance_id'] > 0) { // check if it exists for this staff member. $existing = get_single('finance', array('job_id', 'job_staff_expense', 'amount'), array($finance['job_id'], $staff_id, $staff_total)); if ($existing) { // match exists already, skip adding this one to the list. continue; } } //$finance = self::_format_invoice_payment($finance, $finance); //$finance['url'] = module_job::link_open($finance['job_id'],false,$finance); $finance['url'] = module_finance::link_open('new', false) . '&job_staff_expense=' . $staff_id . '&from_job_id=' . $finance['job_id']; $finance['transaction_date'] = $finance['date_completed']; $finance['description'] = _l('Job Expense For Staff Member: %s', $staff_member['name'] . ' ' . $staff_member['last_name']); //"Exiting: ".$finance['existing_finance_id'].": ". $finance['amount'] = $staff_total; $finance['debit'] = $staff_total; $finance['sub_amount'] = $staff_total; $finance['taxable_amount'] = $staff_total; $finance['credit'] = 0; $finance['type'] = 'e'; $finance_from_job_staff_expenses[] = $finance; } } } } } if (!$hide_invoice_payments) { $sql = "SELECT p.*, i.customer_id "; if (module_config::c('finance_date_type', 'payment') == 'invoice') { // show entries by invoice create date, not payment date. $sql .= " , i.date_create AS transaction_date "; } else { // default, show by paid date. $sql .= " , p.date_paid AS transaction_date "; } $sql .= " FROM `" . _DB_PREFIX . "invoice_payment` p "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "invoice` i ON p.invoice_id = i.invoice_id "; $where = " WHERE p.date_paid != '0000-00-00' "; $where .= " AND p.`amount` != 0 "; $where .= " AND ( p.`payment_type` = " . _INVOICE_PAYMENT_TYPE_NORMAL . " OR p.`payment_type` = " . _INVOICE_PAYMENT_TYPE_REFUND . ' OR p.`payment_type` = ' . _INVOICE_PAYMENT_TYPE_OVERPAYMENT_CREDIT . ' OR p.`payment_type` = ' . _INVOICE_PAYMENT_TYPE_CREDIT . ')'; if (isset($search['job_id']) && (int) $search['job_id'] > 0) { $sql .= " LEFT JOIN `" . _DB_PREFIX . "invoice_item` ii ON i.invoice_id = ii.invoice_id"; $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON ii.task_id = t.task_id"; $where .= " AND (t.`job_id` = " . (int) $search['job_id'] . " OR i.`deposit_job_id` = " . (int) $search['job_id'] . " ) "; } if (isset($search['invoice_id']) && (int) $search['invoice_id'] > 0) { $where .= " AND p.`invoice_id` = " . (int) $search['invoice_id']; } if (isset($search['customer_id']) && (int) $search['customer_id'] > 0) { $where .= " AND i.`customer_id` = " . (int) $search['customer_id']; } /*if(isset($search['generic']) && strlen(trim($search['generic']))){ $name = mysql_real_escape_string(trim($search['generic'])); $where .= " AND (i.`name` LIKE '%$name%' OR p.method LIKE '%$name%' )"; }*/ if (isset($search['company_id']) && (int) $search['company_id'] > 0) { // check this user can view this company id or not if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled()) { $companys = module_company::get_companys(); if (isset($companys[$search['company_id']])) { $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_customer` cc ON i.customer_id = cc.customer_id "; $where .= " AND cc.`company_id` = " . (int) $search['company_id']; } } } if (isset($search['date_from']) && $search['date_from'] != '') { if (module_config::c('finance_date_type', 'payment') == 'invoice') { $where .= " AND i.date_create >= '" . input_date($search['date_from']) . "'"; } else { $where .= " AND p.date_paid >= '" . input_date($search['date_from']) . "'"; } } if (isset($search['date_to']) && $search['date_to'] != '') { if (module_config::c('finance_date_type', 'payment') == 'invoice') { $where .= " AND i.date_create <= '" . input_date($search['date_to']) . "'"; } else { $where .= " AND p.date_paid <= '" . input_date($search['date_to']) . "'"; } } if (isset($search['amount_from']) && $search['amount_from'] != '') { $where .= " AND p.amount >= '" . mysql_real_escape_string($search['amount_from']) . "'"; } if (isset($search['amount_to']) && $search['amount_to'] != '') { $where .= " AND p.amount <= '" . mysql_real_escape_string($search['amount_to']) . "'"; } if (isset($search['type']) && $search['type'] != '' && $search['type'] != 'ie') { if ($search['type'] == 'i') { $where .= " AND p.amount > 0"; } else { if ($search['type'] == 'e') { $where .= " AND p.amount < 0"; } } } 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 i.customer_id IN ( "; foreach ($valid_customer_ids as $valid_customer_id) { $where .= (int) $valid_customer_id . ", "; } $where = rtrim($where, ', '); $where .= " )"; } } $sql .= $where . " ORDER BY p.date_paid DESC "; //echo $sql; $finance_from_invoice_payments = qa($sql); foreach ($finance_from_invoice_payments as $finance_id => $finance) { // doesn't have an finance / account reference just yet. // but they can create one and this will become a child entry to it. $finance = self::_format_invoice_payment($finance, $finance); /*if(!isset($finance['customer_id']) || !$finance['customer_id']){ $invoice_data = module_invoice::get_invoice($finance['invoice_id'],2); $finance['customer_id'] = $invoice_data['customer_id']; }*/ // grab a new name/descriptino/etc.. from other plugins (at the moment only subscription) /*$new_finance = hook_handle_callback('finance_invoice_listing',$finance['invoice_id'],$finance); if(is_array($new_finance) && count($new_finance)){ foreach($new_finance as $n){ $finance = array_merge($finance,$n); } }*/ $finance_from_invoice_payments[$finance_id] = $finance; } if (isset($search['generic']) && strlen(trim($search['generic']))) { $name = mysql_real_escape_string(trim($search['generic'])); // $where .= " AND (i.`name` LIKE '%$name%' OR p.method LIKE '%$name%' )"; // we have to do a PHP search here because foreach ($finance_from_invoice_payments as $finance_id => $finance) { if (stripos($finance['name'], $name) === false && stripos($finance['description'], $name) === false) { unset($finance_from_invoice_payments[$finance_id]); } } } } $finances = array_merge($finances_from_finance_db_table, $finance_from_invoice_payments, $finance_from_job_staff_expenses); unset($finances_from_finance_db_table); unset($finance_from_invoice_payments); unset($finance_from_job_staff_expenses); // sort this if (!function_exists('sort_finance')) { function sort_finance($a, $b) { $t1 = strtotime($a['transaction_date']); $t2 = strtotime($b['transaction_date']); if ($t1 == $t2) { // sort by finance id, putting ones with a finance id first before others. then amount. if (isset($a['finance_id']) && !isset($b['finance_id'])) { // put $a before $b return -1; } else { if (!isset($a['finance_id']) && isset($b['finance_id'])) { // put $b before $a return 1; } else { return $a['amount'] > $b['amount']; } } } else { return $t1 < $t2; } } } uasort($finances, 'sort_finance'); foreach ($finances as $finance_id => $finance) { // we load each of these transactions // transaction can be a "transaction" or an "invoice_payment" // find out if this transaction is a child transaction to another transaction. // if it is a child transaction and we haven't already dispayed it in this listing // then we find the parent transaction and display it along with all it's children in this place. // this wont be perfect all the time but will be awesome in 99% of cases. if (isset($finance['finance_id']) && $finance['finance_id']) { // displayed before already? if (isset($displayed_finance_ids[$finance['finance_id']])) { $finances[$displayed_finance_ids[$finance['finance_id']]]['link_count']++; unset($finances[$finance_id]); continue; } $displayed_finance_ids[$finance['finance_id']] = $finance_id; if (isset($finance['invoice_payment_id']) && $finance['invoice_payment_id']) { $displayed_invoice_payment_ids[$finance['invoice_payment_id']] = $finance_id; // so we dont display again. } } else { if (isset($finance['invoice_payment_id']) && $finance['invoice_payment_id'] && isset($finance['invoice_id']) && $finance['invoice_id']) { // this is an invoice payment (incoming payment) // displayed before already? if (isset($displayed_invoice_payment_ids[$finance['invoice_payment_id']])) { $finances[$displayed_invoice_payment_ids[$finance['invoice_payment_id']]] = array_merge($finance, $finances[$displayed_invoice_payment_ids[$finance['invoice_payment_id']]]); $finances[$displayed_invoice_payment_ids[$finance['invoice_payment_id']]]['link_count']++; unset($finances[$finance_id]); continue; } $displayed_invoice_payment_ids[$finance['invoice_payment_id']] = $finance_id; // so we dont display again. } else { if (isset($finance['c_staff_total_amount'])) { // staff expense. } else { // nfi? unset($finances[$finance_id]); continue; } } } if (isset($finance['parent_finance_id']) && $finance['parent_finance_id']) { // check if it's parent finance id has been displayed already somewhere. if (isset($displayed_finance_ids[$finance['parent_finance_id']])) { $finances[$displayed_finance_ids[$finance['parent_finance_id']]]['link_count']++; unset($finances[$finance_id]); continue; // already done it on this page. } $displayed_finance_ids[$finance['parent_finance_id']] = $finance_id; // we haven't displayed the parent one yet. // display the parent one in this listing. $finance = self::get_finance($finance['parent_finance_id']); } /*if(isset($finance['invoice_payment_id']) && $finance['invoice_payment_id'] && isset($finance['invoice_id']) && $finance['invoice_id']){ // moved to above. }else*/ if (isset($finance['finance_id']) && $finance['finance_id']) { $finance['url'] = self::link_open($finance['finance_id'], false); $finance['credit'] = $finance['type'] == 'i' ? $finance['amount'] : 0; $finance['debit'] = $finance['type'] == 'e' ? $finance['amount'] : 0; if (!isset($finance['categories'])) { $finance['categories'] = ''; } if (!isset($finance['account_name'])) { $finance['account_name'] = ''; } } if (isset($finance['taxes']) && !isset($finance['sub_amount'])) { $finance['sub_amount'] = $finance['amount']; foreach ($finance['taxes'] as $tax) { if (isset($tax['amount'])) { $finance['sub_amount'] -= $tax['amount']; } } } $finance['link_count'] = 0; $finances[$finance_id] = $finance; } return $finances; }
public function external_hook($hook) { switch ($hook) { case 'view': $file_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false; if ($file_id && $hash) { $correct_hash = $this->link_public($file_id, true); if ($correct_hash == $hash) { // all good to print a receipt for this payment. $file_data = $this->get_file($file_id, false); if ($file_data && $file_data['file_id'] == $file_id) { if (isset($_POST['save_file_comments'])) { if (isset($_POST['file_approve']) && isset($_POST['file_approve_go']) && isset($_POST['file_approve_name']) && strlen($_POST['file_approve_name']) > 0) { update_insert('file_id', $file_id, 'file', array('approved_time' => time(), 'approved_by' => $_POST['file_approve_name'])); // send email, same 'updated' email as before. $this->send_file_changed_notice($file_id, false, true); //redirect_browser($this->link_public($file_id)); $_REQUEST['new_comment_text'] = _l('File was approved at %s by %s', print_date(time(), true), htmlspecialchars($_POST['file_approve_name'])); } if (isset($_POST['pointers'])) { update_insert('file_id', $file_id, 'file', array('pointers' => $_POST['pointers'])); } $this->save_file_comments($file_id); redirect_browser($this->link_public($file_id)); } module_template::init_template('file_approval_view', '<h2>File Details</h2> File Name: <strong>{FILE_NAME}</strong> <br/> Download: <strong><a href="{FILE_DOWNLOAD_URL}">Click Here</a></strong> <br/> Status: <strong>{STATUS}</strong> <br/> Customer: <strong>{CUSTOMER_NAME}</strong> <br/> {if:JOB_NAME}Job: <strong>{JOB_NAME}</strong> <br/>{endif:JOB_NAME} {if:FILE_APPROVAL_PENDING} <h2>File Approval Pending</h2> <p>If you would like to approve this file please complete the form below:</p> <p>Your Name: <input type="text" name="file_approve_name"> </p> <p><input type="checkbox" name="file_approve_go" value="yes"> Yes, I approve this file. </p> <p><input type="submit" name="file_approve" value="Approve File" class="submit_button save_button"></p> {endif:FILE_APPROVAL_PENDING} {if:FILE_APPROVED} <h2>File Has Been Approved</h2> <p>Thank you, the file was approved by <strong>{APPROVED_BY}</strong> on <strong>{APPROVED_TIME}</strong>.</p> {endif:FILE_APPROVED} <h2>File Comments</h2> <p>Please feel free to add comments to this file using the form below.</p> {FILE_COMMENTS} {if:FILE_PREVIEW} <h2>File Preview</h2> <div style="overflow:scroll;">{FILE_PREVIEW}</div> {endif:FILE_PREVIEW} ', 'Used when displaying the file to a customer for approval.', 'code'); $template = module_template::get_template_by_key('file_approval_view'); // generate the html for the task output $job_data = $file_data['job_id'] ? module_job::get_replace_fields($file_data['job_id']) : array(); if (class_exists('module_quote', false)) { $quote_data = $file_data['quote_id'] ? module_quote::get_replace_fields($file_data['quote_id']) : array(); } $customer_data = $file_data['customer_id'] ? module_customer::get_replace_fields($file_data['customer_id']) : array(); $file_data['file_preview'] = module_file::generate_preview($file_id, $file_data['file_name'], $file_data); $file_data['FILE_DOWNLOAD_URL'] = module_file::link_public_view($file_id); if (isset($file_data['approved_time'])) { switch ($file_data['approved_time']) { case -1: $file_data['FILE_APPROVAL_PENDING'] = 1; break; case 0: break; default: $file_data['FILE_APPROVED'] = 1; $file_data['APPROVED_TIME'] = print_date($file_data['approved_time'], true); } } if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) { $all_extra_fields = module_extra::get_defaults('file'); foreach ($all_extra_fields as $e) { $file_data[$e['key']] = _l('N/A'); } // and find the ones with values: $extras = module_extra::get_extras(array('owner_table' => 'file', 'owner_id' => $file_id)); foreach ($extras as $e) { $file_data[$e['extra_key']] = $e['extra']; } } ob_start(); ?> <div id="file_notes"> <div style="border-top:1px dashed #CCCCCC; padding:3px; margin:3px 0;"> <textarea name="new_comment_text" style="width:100%;" class="no_permissions"></textarea> <div style="text-align: right;"> <input type="submit" name="butt_save_note" id="butt_save_note" value="<?php echo _l('Add Comment'); ?> " class="submit_button no_permissions"> </div> </div> <?php foreach (module_file::get_file_comments($file_id) as $item) { $note_text = forum_text($item['comment']); if (preg_match_all('/#(\\d+)/', $note_text, $matches)) { // foreach ($matches[1] as $digit) { $note_text = preg_replace('/#' . $digit . '([^\\d]*)/', '<span node_id=' . $digit . ' class="pointer-ids pointer-id-' . $digit . '">#' . $digit . '</span>$1', $note_text); } } ?> <div style="border-top:1px dashed #CCCCCC; padding:3px; margin:3px 0;"> <?php echo $note_text; ?> <div style="font-size:10px; text-align:right; color:#CCCCCC;">From <?php echo $item['create_user_id'] ? module_user::link_open($item['create_user_id'], true) : _l('Customer'); ?> on <?php echo print_date($item['date_created'], true); ?> </div> </div> <?php } ?> </div> <?php $file_data['file_comments'] = ob_get_clean(); $template->assign_values($file_data); $template->assign_values($customer_data); $template->assign_values($job_data); if (class_exists('module_quote', false)) { $quote_data['quote_approved_by'] = $quote_data['approved_by']; $quote_data['quote_date_approved'] = $quote_data['date_approved']; unset($quote_data['approved_by']); unset($quote_data['date_approved']); $template->assign_values($quote_data); } $template->page_title = $file_data['file_name']; $template->content = '<form action="" method="post"><input type="hidden" name="save_file_comments" value="1">' . $template->content . '</form>'; echo $template->render('pretty_html'); } } } break; case 'download_bucket': @ob_end_clean(); $file_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false; if ($file_id && $hash) { $correct_hash = $this->link_public_download_bucket($file_id, true); if ($correct_hash == $hash) { // all good to print a receipt for this payment. $file_data = $this->get_file($file_id, false); @ignore_user_abort(true); $search = array(); $search['bucket_parent_file_id'] = $file_id; $files = module_file::get_files($search); //Create ZIP $zip = new ZipArchive(); $zipName = "bucket-" . $file_id . "-" . md5($file_id . _UCM_SECRET) . ".zip"; if ($zip->open(_FILE_UPLOAD_PATH . $zipName, ZIPARCHIVE::CREATE) !== TRUE) { echo 'Failed to create bucket zip file'; exit; } foreach ($files as $file) { if (is_file($file['file_path'])) { $zip->addFromString($file['file_name'], file_get_contents($file['file_path'])); } } $zip->close(); //Set headers header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-type: application/octet-stream"); //header("Content-Disposition: attachment; filename='" . $zipName . "'"); header("Content-Disposition: attachment; filename=\"" . preg_replace("#[^a-zA-Z0-9]+#", "-", $file_data['file_name']) . ".zip\";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize(_FILE_UPLOAD_PATH . $zipName)); @clearstatcache(); //Make sure the file size isn't cached $size = @readfile(_FILE_UPLOAD_PATH . $zipName); if (!$size) { echo file_get_contents(_FILE_UPLOAD_PATH . $zipName); } @unlink(_FILE_UPLOAD_PATH . $zipName); } } exit; break; case 'download': @ob_end_clean(); $file_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false; if ($file_id && $hash) { $correct_hash = $this->link_public_view($file_id, true); if ($correct_hash == $hash) { // all good to print a receipt for this payment. $file_data = $this->get_file($file_id, false); if (isset($file_data['file_url']) && strlen($file_data['file_url'])) { redirect_browser($file_data['file_url']); } else { if (is_file($file_data['file_path'])) { header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-type: " . dtbaker_mime_type($file_data['file_name'], $file_data['file_path'])); if (!isset($_REQUEST['embed'])) { header("Content-Disposition: attachment; filename=\"" . $file_data['file_name'] . "\";"); header("Content-Transfer-Encoding: binary"); } header("Content-Length: " . filesize($file_data['file_path'])); //readfile($file_data['file_path']); $size = @readfile($file_data['file_path']); if (!$size) { echo file_get_contents($file_data['file_path']); } } else { echo 'Not found'; } } } } exit; break; } }
}); } 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) { echo module_user::link_open($quote['user_id'], true); }); } if (module_job::can_i('view', 'Jobs')) { $job_ids = array(); $columns['job'] = array('title' => 'Job', 'callback' => function ($quote) use(&$job_ids) { $job_ids = array(); foreach (module_job::get_jobs(array('quote_id' => $quote['quote_id'])) as $job) { $job = module_job::get_job($job['job_id']); if (!$job) { continue; } echo module_job::link_open($job['job_id'], true); $job_ids[] = $job['job_id']; echo " "; echo '<span class="';
public function external_hook($hook) { switch ($hook) { case 'event_ipn': $body = @file_get_contents('php://input'); $event_json = json_decode($body); ob_start(); echo "UCM coinbase DEBUG:<br><br>JSON: <br>\n"; print_r($event_json); echo "<br><br>\n"; $success = false; $bits = explode(':', isset($event_json->order->custom) ? $event_json->order->custom : ''); if (count($bits) == 4) { // we have our custom bits, invoice_id, invoice_payment_id and hash // check they are right $invoice_id = (int) $bits[0]; $invoice_payment_id = (int) $bits[1]; $invoice_payment_subscription_id = (int) $bits[2]; $hash = $bits[3]; $correct_hash = self::get_payment_key($invoice_id, $invoice_payment_id, $invoice_payment_subscription_id, true); if ($invoice_id && $invoice_payment_id && $hash == $correct_hash) { // This will send receipts on succesful invoices // todo - coinbase doesnt sent this callback correctly just yet if ($event_json && isset($event_json->recurring_payment) && $invoice_payment_subscription_id) { // status changes on a recurring payment. $invoice_payment_subscription = get_single('invoice_payment_subscription', 'invoice_payment_subscription_id', $invoice_payment_subscription_id); if (!$invoice_payment_subscription['date_start'] || $invoice_payment_subscription['date_start'] == '0000-00-00') { // no start date yet, set the start date now. if ($event_json->recurring_payment->status == 'active') { update_insert('invoice_payment_subscription_id', $invoice_payment_subscription_id, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_ACTIVE, 'date_start' => date('Y-m-d'))); } } if ($event_json->recurring_payment->status == 'paused' || $event_json->recurring_payment->status == 'canceled') { update_insert('invoice_payment_subscription_id', $invoice_payment_subscription_id, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_FAILED)); } } if ($event_json && isset($event_json->order->status) && $event_json->order->status == 'completed' && isset($event_json->order->total_native) && isset($event_json->order->custom)) { // crab out the custom bits so we know what to deal with. $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); $currency = module_config::get_currency($invoice_payment_data['currency_id']); if ($invoice_payment_subscription_id) { // this API result is for a subscription payment. $invoice_payment_subscription = get_single('invoice_payment_subscription', 'invoice_payment_subscription_id', $invoice_payment_subscription_id); if ($invoice_payment_subscription && $invoice_payment_subscription['invoice_payment_subscription_id'] == $invoice_payment_subscription_id && $currency['code'] == $event_json->order->total_native->currency_iso) { if (!$invoice_payment_subscription['date_start'] || $invoice_payment_subscription['date_start'] == '0000-00-00') { // no start date yet, set the start date now (this should really happen in the above callback, but coinbase isn't working right now) update_insert('invoice_payment_subscription_id', $invoice_payment_subscription_id, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_ACTIVE, 'date_start' => date('Y-m-d'))); } // we have a subscription payment. woo! // this gets a bit tricky, we have to work out if the invoice has been generated for this subscription yet. // if this invoice hasn't been generated yet then we have to generate it. // pass this back to the invoice class so we can reuse this feature in the future. $data = module_invoice::create_new_invoice_for_subscription_payment($invoice_id, $invoice_payment_id, $invoice_payment_subscription_id); if ($data && $data['invoice_id'] && $data['invoice_payment_id']) { $next_time = time(); $next_time = strtotime('+' . abs((int) $invoice_payment_subscription['days']) . ' days', $next_time); $next_time = strtotime('+' . abs((int) $invoice_payment_subscription['months']) . ' months', $next_time); $next_time = strtotime('+' . abs((int) $invoice_payment_subscription['years']) . ' years', $next_time); update_insert('invoice_payment_subscription_id', $invoice_payment_subscription_id, 'invoice_payment_subscription', array('date_last_pay' => date('Y-m-d'), 'date_next' => date('Y-m-d', $next_time))); update_insert("invoice_payment_id", $data['invoice_payment_id'], "invoice_payment", array('date_paid' => date('Y-m-d'), 'amount' => $event_json->order->total_native->cents / 100, 'method' => self::get_payment_method_name() . ' (Subscription)', 'invoice_payment_subscription_id' => $invoice_payment_subscription_id)); self::add_payment_data($data['invoice_payment_id'], 'log', "Invoice Payment Subscription Received!"); self::add_payment_data($data['invoice_payment_id'], 'log', "API IP is " . $_SERVER['REMOTE_ADDR']); self::add_payment_data($data['invoice_payment_id'], 'log', "Received BTC: " . $event_json->order->total_btc->cents / 10000000); self::add_payment_data($data['invoice_payment_id'], 'log', "Received " . $event_json->order->total_native->currency_iso . ': ' . $event_json->order->total_native->cents / 100); self::add_payment_data($data['invoice_payment_id'], 'log', "Destination Address: " . $event_json->order->receive_address); self::add_payment_data($data['invoice_payment_id'], 'log', "Currency code matches, marking invoice as paid."); self::add_payment_data($data['invoice_payment_id'], 'log', "Raw Event Data: \n" . json_encode($event_json)); module_invoice::save_invoice($data['invoice_id'], array()); echo "Successful Subscription Payment!"; } else { send_error("Coinbase Subscription Error (failed to generate new invoice!) " . var_export($data, true)); } } else { send_error('Currency code missmatch on coinbase subscription payment'); } } else { // this is a normal once off payment. self::add_payment_data($invoice_payment_id, 'log', "API IP is " . $_SERVER['REMOTE_ADDR']); self::add_payment_data($invoice_payment_id, 'log', "Received BTC: " . $event_json->order->total_btc->cents / 10000000); self::add_payment_data($invoice_payment_id, 'log', "Received " . $event_json->order->total_native->currency_iso . ': ' . $event_json->order->total_native->cents / 100); self::add_payment_data($invoice_payment_id, 'log', "Destination Address: " . $event_json->order->receive_address); if ($currency['code'] == $event_json->order->total_native->currency_iso) { self::add_payment_data($invoice_payment_id, 'log', "Currency code matches, marking invoice as paid."); update_insert("invoice_payment_id", $invoice_payment_id, "invoice_payment", array('date_paid' => date('Y-m-d'), 'amount' => $event_json->order->total_native->cents / 100)); module_invoice::save_invoice($invoice_id, array()); echo "Successful Payment!"; $success = true; } else { self::add_payment_data($invoice_payment_id, 'log', "Currency code missmatch, please check settings!"); } self::add_payment_data($invoice_payment_id, 'log', "Raw Event Data: \n" . json_encode($event_json)); } } } } $debug = ob_get_clean(); if (module_config::c('coinbase_payment_debug', 0)) { send_error("Coinbase Debug: {$debug}"); } exit; break; case 'pay_subscription': $invoice_id = isset($_REQUEST['invoice_id']) ? $_REQUEST['invoice_id'] : false; $invoice_payment_id = isset($_REQUEST['invoice_payment_id']) ? $_REQUEST['invoice_payment_id'] : false; $invoice_payment_subscription_id = isset($_REQUEST['invoice_payment_subscription_id']) ? $_REQUEST['invoice_payment_subscription_id'] : false; $coinbase_plan_id = isset($_REQUEST['coinbase_plan_id']) ? $_REQUEST['coinbase_plan_id'] : false; $user_id = isset($_REQUEST['user_id']) ? $_REQUEST['user_id'] : false; if ($invoice_id && $invoice_payment_id && $coinbase_plan_id && $invoice_payment_subscription_id && $user_id && isset($_POST['coinbaseToken'])) { $user_data = module_user::get_user($user_id); $email = isset($_REQUEST['coinbaseEmail']) && strlen($_REQUEST['coinbaseEmail']) ? $_REQUEST['coinbaseEmail'] : $user_data['email']; if (!$email || !strpos($email, '@')) { die('Please ensure your user account has a valid email address before paying with coinbase'); } $invoice_payment = get_single('invoice_payment', 'invoice_payment_id', $invoice_payment_id); $invoice_payment_subscription = get_single('invoice_payment_subscription', 'invoice_payment_subscription_id', $invoice_payment_subscription_id); if (!$invoice_payment || !$invoice_payment_subscription || $invoice_payment['invoice_id'] != $invoice_id || $invoice_payment['invoice_payment_subscription_id'] != $invoice_payment_subscription_id) { die('Invalid invoice payment subscription id'); } $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); $invoice_data = module_invoice::get_invoice($invoice_id); if ($invoice_payment_data && $invoice_data && $invoice_id == $invoice_data['invoice_id'] && $invoice_payment_data['invoice_id'] == $invoice_data['invoice_id']) { $currency = module_config::get_currency($invoice_payment_data['currency_id']); $currency_code = $currency['code']; $description = isset($_REQUEST['description']) ? $_REQUEST['description'] : 'N/A'; $template = new module_template(); ob_start(); require_once 'includes/plugin_paymethod_coinbase/coinbase-php/lib/coinbase.php'; $coinbase = array("secret_key" => module_config::c('payment_method_coinbase_api_key'), "publishable_key" => module_config::c('payment_method_coinbase_secret_key')); coinbase::setApiKey($coinbase['secret_key']); try { // todo- search for existing customer based on email address??? // todo: check if adding new plan to existing customer work?? $coinbase_customer = coinbase_Customer::create(array("card" => $_POST['coinbaseToken'], "email" => $email, 'metadata' => array('user_id' => $user_id))); if ($coinbase_customer && $coinbase_customer->id) { //} && $coinbase_customer->subscriptions){ $coinbase_subscription = $coinbase_customer->subscriptions->create(array('plan' => $coinbase_plan_id)); if ($coinbase_subscription && $coinbase_subscription->id) { update_insert('invoice_payment_subscription_id', $invoice_payment_subscription_id, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_ACTIVE, 'date_start' => date('Y-m-d'), 'coinbase_customer' => $coinbase_customer->id, 'coinbase_subscription' => $coinbase_subscription->id)); module_paymethod_coinbase::add_payment_data($invoice_payment_id, 'log', "Started coinbase Subscription: " . var_export(array('customer.id' => $coinbase_customer->id, 'plan.id' => $coinbase_plan_id, 'subscription.id' => $coinbase_subscription->id), true)); // success! // redirect to receipt page. redirect_browser(module_invoice::link_public_payment_complete($invoice_id)); } else { echo 'Failed to create subscription with coinbase'; } } $error = "Something went wrong during coinbase payment. Please confirm invoice payment went through: " . htmlspecialchars($description); send_error($error); echo $error; } catch (coinbase_CardError $e) { // The card has been declined $body = $e->getJsonBody(); $err = $body['error']; $error = "Sorry: Payment failed. <br><br>\n\n" . htmlspecialchars($description) . ". <br><br>\n\n"; $error .= $err['message']; echo $error; $error .= "\n\n\n" . var_export($err, true); send_error($error); } catch (Exception $e) { $body = $e->getJsonBody(); $err = $body['error']; $error = "Sorry: Payment failed. <br><br>\n\n" . htmlspecialchars($description) . ". <br><br>\n\n"; $error .= $err['message']; echo $error; $error .= "\n\n\n" . var_export($err, true); send_error($error); } $template->content = ob_get_clean(); echo $template->render('pretty_html'); exit; } } echo 'Error paying via coinbase'; exit; } }
$home_widgets = array_merge($home_widgets, $home_widgets2); } // group the widgets into columsn. // the default columns is 3, but each widget can specify which column group they want to appear in. // layout the default widget structure in the order we want it to display on the page: $widget_columns = array(); $widget_columns[4] = array(1 => array(), 2 => array(), 3 => array(), 4 => array()); $widget_columns[1] = array(1 => array()); $widget_columns[2] = array(1 => array(), 2 => array()); $widget_columns[3] = array(1 => array(), 2 => array(), 3 => array()); // then display the welcome message: module_template::init_template('welcome_message', '<p> Hi {USER_NAME}, and Welcome to {SYSTEM_NAME} </p>', 'Welcome message on Dashboard', array('USER_NAME' => 'Current user name', 'SYSTEM_NAME' => 'System name from settings area')); // check if there is a template for this user role. $my_account = module_user::get_user(module_security::get_loggedin_id()); $security_role = current($my_account['roles']); $template = false; if ($security_role && isset($security_role['security_role_id'])) { $template = module_template::get_template_by_key('welcome_message_role_' . $security_role['security_role_id']); } if (!$template || !$template->template_key) { $template = module_template::get_template_by_key('welcome_message'); } $template->assign_values(array('user_name' => htmlspecialchars($_SESSION['_user_name']), 'system_name' => htmlspecialchars(module_config::s('admin_system_name')))); $widget_sort_json = @json_decode(module_config::c('dash_widgets_sort_' . module_security::get_loggedin_id()), true); if (!is_array($widget_sort_json)) { $widget_sort_json = array(); } $widget_sort_order = array(); $widget_sort_page_order = 1;
} if (module_job::can_i('view', 'Job Advanced')) { /***** JOB ADVANCED *****/ $fieldset_data = array('heading' => array('type' => 'h3', 'title' => 'Advanced'), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array(array('title' => 'Customer Link', 'field' => array('type' => 'html', 'value' => '<a href="' . module_job::link_public($job_id) . '" target="_blank">' . _l('Click to view external link') . '</a>', 'help' => 'You can send this link to the customer and they can view progress on their job. They can also view a list of any invoices attached to this job. This is VERY useful to stop customers asking you "how far along are you" with a job because they can see exactly where you have logged up to in the system.')))); if ((int) $job_id > 0 && module_job::can_i('edit', 'Jobs')) { $fieldset_data['elements'][] = array('title' => 'Email Job', 'field' => array('type' => 'html', 'value' => '<a href="' . module_job::link_generate($job_id, array('arguments' => array('email' => 1))) . '">' . _l('Email this Job to Customer') . '</a>', 'help' => 'You can email the customer a copy of this job. This can be a progress report or as an initial quote. ')); $fieldset_data['elements'][] = array('title' => 'Email Staff', 'fields' => array(function () use(&$job_tasks, $job_id) { $allocated_staff_members = array(); foreach ($job_tasks as $job_task) { if (!isset($allocated_staff_members[$job_task['user_id']])) { $allocated_staff_members[$job_task['user_id']] = 0; } $allocated_staff_members[$job_task['user_id']]++; } foreach ($allocated_staff_members as $staff_id => $count) { $staff = module_user::get_user($staff_id); ?> <a href="<?php echo module_job::link_generate($job_id, array('arguments' => array('email_staff' => 1, 'staff_id' => $staff_id))); ?> "><?php _e('Email staff (%s - %s tasks)', $staff['name'], $count); ?> </a> <br/> <?php } })); } if (class_exists('module_website', false) && module_website::is_plugin_enabled()) { $fieldset_data['elements'][] = array('title' => module_config::c('project_name_single', 'Website'), 'fields' => array(function () use(&$job) {
public function replace_content() { $content = $this->content; $this->add_tags($this->template_key, $this->values); // add todays date values if (!isset($this->values['day'])) { $this->values['day'] = date('d'); } if (!isset($this->values['month'])) { $this->values['month'] = date('m'); } if (!isset($this->values['year'])) { $this->values['year'] = date('y'); } if (!isset($this->values['current_user']) && module_security::is_logged_in()) { $this->values['current_user'] = module_security::get_loggedin_id(); $user_details = module_user::get_replace_fields(module_security::get_loggedin_id()); foreach ($user_details as $key => $val) { $this->values['current_' . $key . ''] = $val; } } // basic conditional tags - eg: {if:name}Dear {name},{else:name}Hello,{endif:name} // todo - support nested if - pass to template module. $debug = false; if (preg_match_all('#\\{if:([^\\}=]+)([^\\}]*)\\}(.*){endif:\\1\\}.*#imsU', $content, $matches)) { foreach ($matches[1] as $key => $template_tag) { // does this first if have a conditional statement (eg: {if:STATUS=New}sdfasdf{else}asdfasdf{/if:STATUS} $bits = preg_split('#{else[^\\}]*}#', $matches[3][$key]); preg_match_all('#\\{(else)?(if:([^\\}=]+)([^\\}]*))?\\}#ims', $matches[0][$key], $elseif_matches); $new_content = false; if ($debug) { echo $matches[0][$key] . "\n"; } if ($debug) { print_r($bits); } if ($debug) { print_r($elseif_matches); } foreach ($elseif_matches[0] as $elseif_key => $elseif_condition) { $template_tag_value = isset($this->values[strtolower($elseif_matches[3][$elseif_key])]) ? trim($this->values[strtolower($elseif_matches[3][$elseif_key])]) : ''; if (!strlen(trim($elseif_matches[3][$elseif_key]))) { // we are at the final {else} statement, this means all other checks before have failed. we use this content. if ($debug) { echo "Reached final {else} statement, using this value\n"; } $new_content = $bits[$elseif_key]; break; } else { if ($debug) { echo "Checking {$elseif_condition} against " . $elseif_matches[3][$elseif_key] . " which has the value: " . $template_tag_value . "\n"; } if (strlen($elseif_matches[4][$elseif_key]) && $elseif_matches[4][$elseif_key][0] == '=') { // the if/elseif tag is checking a condition, rather than just an "does exist" check $check_matching_value = ltrim(trim($elseif_matches[4][$elseif_key]), '='); if ($debug) { echo "Checking if it matches {$check_matching_value} \n"; } if ($check_matching_value == $template_tag_value) { if ($debug) { echo "YES WE HAVE A MATCH \n"; } // this first if statement matches this query! yes! // use its value in the final $new_content $new_content = $bits[$elseif_key]; break; } else { if ($debug) { echo "No match this time \n"; } } } else { // we're just checking if this value exists or not. if (strlen($template_tag_value) > 0 && $template_tag_value != '0000-00-00' && $template_tag_value != _l('N/A')) { // it's a match! $new_content = $bits[$elseif_key]; break; } else { // no match, move onto next bit. } } } } if ($debug) { echo "Final content to use will be: \n" . $new_content; } $content = str_replace($matches[0][$key], $new_content, $content); } } foreach ($this->values as $key => $val) { if (is_array($val)) { continue; } // if this isn't a html field we add newlines. if (!preg_match('#<[^>]+>#', $val)) { // raw text. nl2br $val = nl2br($val); } $content = str_replace('{' . strtoupper($key) . '}', $val, $content); // we perform some basic arithmetic on some replace fields. if (preg_match_all('#\\{(currency:)?' . preg_quote(strtoupper($key), '#') . '([*+-])([\\d\\.]+)\\}#', $content, $matches)) { // pull the "number" portion out of this string for math processing. // string could look like this: "$150.10 USD" $mathval = $originalval = $val; if (preg_match('#([\\d.,]+)#', $val, $mathvalmatches)) { $mathval = $originalval = $mathvalmatches[1]; } foreach ($matches[0] as $i => $v) { $mathval = $originalval; if ($matches[2][$i] == '-') { $mathval = $mathval - $matches[3][$i]; } else { if ($matches[2][$i] == '+') { $mathval = $mathval + $matches[3][$i]; } else { if ($matches[2][$i] == '*') { $mathval = $mathval * $matches[3][$i]; } } } if (strtolower($matches[1][$i]) == 'currency:') { $mathval = dollar($mathval, true, isset($this->values['currency_id']) ? $this->values['currency_id'] : false); } $newval = str_replace($originalval, $mathval, $val); $content = str_replace($v, $newval, $content); } } if (preg_match_all('#\\{currency:(' . preg_quote(strtoupper($key), '#') . ')\\}#', $content, $matches)) { foreach ($matches[0] as $i => $v) { $content = str_replace($v, dollar($val, true, isset($this->values['currency_id']) ? $this->values['currency_id'] : false), $content); } } // we perform some arithmetic on date fields. $matches = false; if (stripos($key, 'date') !== false && $val && strlen($val) > 6 && preg_match_all('#' . preg_quote('{' . strtoupper($key), '#') . '((?>[+-]\\d+[ymd])*)\\}#', $content, $matches)) { //$processed_date = (input_date($val)); $processed_date_timeo = $processed_date_time = strtotime(input_date($val)); foreach ($matches[0] as $i => $v) { if (preg_match_all('#([+-])(\\d+)([ymd])#', $matches[1][$i], $date_math)) { foreach ($date_math[1] as $di => $dv) { $period = $date_math[3][$di]; $period = $period == 'd' ? 'day' : ($period == 'm' ? 'month' : ($period == 'y' ? 'year' : 'days')); //echo $dv.$date_math[2][$di]." ".$period."\n"; $processed_date_time = strtotime($dv . $date_math[2][$di] . " " . $period, $processed_date_time); } $content = str_replace($v, print_date($processed_date_time), $content); //echo "Processing date: $val - $processed_date (time: $processed_date_timeo / ".print_date($processed_date_timeo).") with result of: ".print_date($processed_date_time); exit; } } } // we perform some date splitting $matches = false; if (stripos($key, 'date') !== false && $val && strlen($val) > 6 && preg_match_all('#' . preg_quote('{' . strtoupper($key), '#') . '-([ymdYMDjlSWFn])\\}#', $content, $matches)) { $processed_date_time = strtotime(input_date($val)); foreach ($matches[0] as $i => $v) { $content = str_replace($v, date($matches[1][$i], $processed_date_time), $content); } } //$val = str_replace(array('\\', '$'), array('\\\\', '\$'), $val); //$content = preg_replace('/\{'.strtoupper(preg_quote($key,'/')).'\}/',$val,$content); } if (preg_match_all('#\\{l:([^\\}]+)\\}#', $content, $matches)) { foreach ($matches[1] as $key => $label) { $content = str_replace($matches[0][$key], _l($label), $content); } } return $content; }
} } else { if ($use_master_key == 'vendor_id') { $vendor_data = module_vendor::get_vendor($user[$use_master_key]); if ($vendor_data['primary_user_id'] == $user_id) { $primary = true; } } } if ($primary && !isset($hide_more_button)) { $fieldset_data['heading']['button'] = array('title' => 'More', 'url' => module_user::link_open_contact($user_id, false)); } $fieldset_data['elements']['primary'] = array('title' => 'Primary', 'fields' => array(array('type' => 'check', 'name' => 'customer_primary', 'value' => '1', 'checked' => $primary), _hr('This users details will be used as a primary point of contact for this customer. These details will display in the main customer listing for this customer. Also if you send an invoice or a newsletter to this "customer" then this email address will be used.'))); } else { if (isset($show_more_button) && $show_more_button) { $fieldset_data['heading']['button'] = array('title' => 'More', 'url' => module_user::link_open_contact($user_id, false)); } } $fieldset_data['elements']['fname'] = array('title' => 'First Name', 'fields' => array(array('type' => 'text', 'name' => 'name', 'value' => $user['name']))); $fieldset_data['elements']['last_name'] = array('title' => 'Last Name', 'fields' => array(array('type' => 'text', 'name' => 'last_name', 'value' => $user['last_name']))); $fieldset_data['elements']['email'] = array('title' => 'Email Address', 'fields' => array(array('type' => 'text', 'name' => 'email', 'value' => $user['email']))); $fieldset_data['elements']['phone'] = array('title' => 'Phone', 'fields' => array(array('type' => 'text', 'name' => 'phone', 'value' => $user['phone']))); $fieldset_data['elements']['mobile'] = array('title' => 'Mobile', 'fields' => array(array('type' => 'text', 'name' => 'mobile', 'value' => $user['mobile']))); $fieldset_data['elements']['fax'] = array('title' => 'Fax', 'fields' => array(array('type' => 'text', 'name' => 'fax', 'value' => $user['fax']))); if (class_exists('module_language', false) && isset($user['language'])) { $attr = array(); foreach (module_language::get_languages_attributes() as $langauge) { $attr[$langauge['language_code']] = $langauge['language_name']; } $fieldset_data['elements']['language'] = array('title' => 'Language', 'fields' => array(array('type' => 'select', 'name' => 'language', 'options' => $attr, 'value' => $user['language']))); }
?> " class="note_edit note_options_link" rel="<?php echo $note_item['note_id']; ?> "> <?php echo $note_text; ?> </a> <?php } else { echo forum_text($note_item['note']); } }); $columns['info'] = array('title' => 'Info', 'width' => 40, 'callback' => function ($note_item) { if (module_config::c('note_show_creator', 1)) { $user_data = module_user::get_user($note_item['create_user_id']); echo $user_data['name']; } if ($note_item['display_summary'] && $note_item['rel_data'] && $note_item['owner_id']) { global $plugins; if (module_config::c('note_show_creator', 1)) { echo ' / '; } echo $plugins[$note_item['owner_table']]->link_open($note_item['owner_id'], true); } }); if ($can_delete) { $columns['del'] = array('title' => ' ', 'callback' => function ($note_item) { if ($note_item['can_delete']) { ?> <a href="<?php
public static function get_statistics_staff($search) { $staff_members = module_user::get_staff_members(); $statistics = array(); foreach ($staff_members as $staff_member) { $statistics[$staff_member['user_id']] = array('user_id' => $staff_member['user_id'], 'job_ids' => array(), 'job_count' => 0, 'task_count' => 0, 'task_ids' => array(), 'task_complete_ids' => array(), 'tasks_complete' => 0, 'hours_logged' => 0, 'hours_billed' => 0, 'amount_billed' => 0, 'amount_invoiced' => 0); $sql = "SELECT COUNT(j.job_id) AS job_count "; $sql .= " FROM `" . _DB_PREFIX . "job` j"; $sql .= " WHERE j.user_id = " . (int) $staff_member['user_id']; if (isset($search['date_from']) && $search['date_from']) { $sql .= " AND j.date_start >= '" . input_date($search['date_from']) . "'"; } if (isset($search['date_to']) && $search['date_to']) { $sql .= " AND j.date_start <= '" . input_date($search['date_to']) . "'"; } $res = qa1($sql); $statistics[$staff_member['user_id']]['job_count'] = $res['job_count']; $sql = "SELECT COUNT(t.task_id) AS task_count "; $sql .= " FROM `" . _DB_PREFIX . "task` t"; $sql .= " LEFT JOIN `" . _DB_PREFIX . "job` j ON t.job_id = j.job_id"; $sql .= " WHERE 1"; $sql .= " AND t.user_id = " . (int) $staff_member['user_id']; if (isset($search['date_from']) && $search['date_from']) { $sql .= " AND j.date_start >= '" . input_date($search['date_from']) . "'"; } if (isset($search['date_to']) && $search['date_to']) { $sql .= " AND j.date_start <= '" . input_date($search['date_to']) . "'"; } $res = qa1($sql); $statistics[$staff_member['user_id']]['task_count'] = $res['task_count']; // tasks completed on this date: $sql = "SELECT COUNT(t.task_id) AS task_count "; $sql .= " FROM `" . _DB_PREFIX . "task` t"; $sql .= " LEFT JOIN `" . _DB_PREFIX . "job` j ON t.job_id = j.job_id"; $sql .= " WHERE 1"; $sql .= " AND t.user_id = " . (int) $staff_member['user_id']; if (isset($search['date_from']) && $search['date_from']) { $sql .= " AND t.date_done >= '" . input_date($search['date_from']) . "'"; } if (isset($search['date_to']) && $search['date_to']) { $sql .= " AND t.date_done <= '" . input_date($search['date_to']) . "'"; } $res = qa1($sql); $statistics[$staff_member['user_id']]['tasks_complete'] = $res['task_count']; $sql = "SELECT t.task_id, tl.date_created, t.hours AS task_hours, t.amount, tl.hours AS hours_logged, p.job_id, p.hourly_rate "; $sql .= ", tl.create_user_id AS logged_user_id"; $sql .= " FROM `" . _DB_PREFIX . "task_log` tl "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON tl.task_id = t.task_id "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "job` p ON tl.job_id = p.job_id"; $sql .= " WHERE 1 "; $sql .= " AND ( tl.create_user_id = " . (int) $staff_member['user_id'] . " )"; //t.user_id = ".(int)$staff_member['user_id'] . " OR if (isset($search['date_from']) && $search['date_from']) { $sql .= " AND tl.log_time >= '" . strtotime(input_date($search['date_from']) . " 00:00:00") . "'"; } if (isset($search['date_to']) && $search['date_to']) { $sql .= " AND tl.log_time <= '" . strtotime(input_date($search['date_to']) . " 23:59:59") . "'"; } //echo $sql; $tasks = query($sql); while ($r = mysql_fetch_assoc($tasks)) { //print_r($r); $jobtasks = module_job::get_tasks($r['job_id']); $statistics[$staff_member['user_id']]['job_ids'][$r['job_id']] = true; $task = $jobtasks[$r['task_id']]; // this user has been assiged to this job individual task. if ($task['fully_completed']) { $statistics[$staff_member['user_id']]['task_complete_ids'][$r['task_id']] = true; $statistics[$staff_member['user_id']]['hours_billed'] += $r['task_hours']; if ($task['amount'] > 0) { $statistics[$staff_member['user_id']]['amount_billed'] += $task['amount']; } else { $statistics[$staff_member['user_id']]['amount_billed'] += $r['task_hours'] * $r['hourly_rate']; } $sql = "SELECT * FROM `" . _DB_PREFIX . "invoice_item` ii WHERE ii.task_id = " . (int) $r['task_id']; $task_invoice = qa1($sql); if ($task_invoice && $task_invoice['task_id'] == $r['task_id']) { if ($task_invoice['amount'] > 0) { $statistics[$staff_member['user_id']]['amount_invoiced'] += $task_invoice['amount']; } else { $statistics[$staff_member['user_id']]['amount_invoiced'] += $task_invoice['hours'] * $task_invoice['hourly_rate']; } } } $statistics[$staff_member['user_id']]['task_ids'][$r['task_id']] = true; $statistics[$staff_member['user_id']]['hours_logged'] += $r['hours_logged']; } //$statistics[$staff_member['user_id']]['job_count'] = count($statistics[$staff_member['user_id']]['job_ids']); } return $statistics; }
<?php if (module_security::getcred()) { ?> <div id="left"> <div class="media user-media"> <div class="media-body"> <h5 class="media-heading"><?php $user = module_user::get_user(module_security::get_loggedin_id()); _e('Welcome %s', htmlspecialchars($user['name'])); ?> </h5> <ul class="list-unstyled user-info"> <li><small><i class="fa fa-user"></i> <a href="<?php echo module_user::link_open($_SESSION['_user_id']); ?> "><?php _e('Edit Profile'); ?> </a></small></li> <?php $header_buttons = array(); if (module_security::is_logged_in()) { $header_buttons = hook_filter_var('header_buttons', $header_buttons); } foreach ($header_buttons as $header_button) { ?> <li> <small><i class="fa fa-<?php
public static function email_invoice_to_customer($invoice_id, $debug = false) { // this is a copy of some of the code in invoie_admin_email.php // used in the CRON job when sending out automated emails. $invoice = module_invoice::get_invoice($invoice_id); // template for sending emails. // are we sending the paid one? or the dueone. $template_name = ''; $template_prefix = isset($invoice['invoice_template_email']) && strlen($invoice['invoice_template_email']) ? $invoice['invoice_template_email'] : 'invoice_email'; if (isset($invoice['credit_note_id']) && $invoice['credit_note_id']) { $template_name = 'credit_note_email'; } else { if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') { $template_name = $template_prefix . '_paid'; } else { if ($invoice['overdue'] && $invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') { $template_name = $template_prefix . '_overdue'; } else { $template_name = $template_prefix . '_due'; } } } $template_name = hook_filter_var('invoice_email_template', $template_name, $invoice_id, $invoice); if (class_exists('module_company', false) && isset($invoice_data['company_id']) && (int) $invoice_data['company_id'] > 0) { module_company::set_current_company_id($invoice_data['company_id']); } $template = module_template::get_template_by_key($template_name); if (!$template || $template->template_key != $template_name) { // backup default templates incase someone has chosen a template that doesn't exist (eg: created invoice_email_MINE_due but not invoice_email_MINE_paid ) $template_prefix = 'invoice_email'; if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') { $template_name = $template_prefix . '_paid'; } else { if ($invoice['overdue'] && $invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') { $template_name = $template_prefix . '_overdue'; } else { $template_name = $template_prefix . '_due'; } } } $replace = module_invoice::get_replace_fields($invoice_id, $invoice); if (defined('_BLOCK_EMAILS') && _BLOCK_EMAILS) { $pdf = false; } else { $pdf = module_invoice::generate_pdf($invoice_id); } $send_email_to = array(); $to = array(); if ($invoice['customer_id']) { $customer = module_customer::get_customer($invoice['customer_id']); $replace['customer_name'] = $customer['customer_name']; if ($invoice['user_id']) { // this invoice has a manually assigned user, only send the invoice to this user. // todo: should we also send to accounts? not sure - see if peopel complain $primary = module_user::get_user($invoice['user_id']); if ($primary) { $send_email_to[] = $primary; } } else { $to = module_user::get_contacts(array('customer_id' => $invoice['customer_id'])); // hunt for 'accounts' extra field $field_to_find = strtolower(module_config::c('accounts_extra_field_name', 'Accounts')); foreach ($to as $contact) { $extras = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $contact['user_id'])); foreach ($extras as $e) { if (strtolower($e['extra_key']) == $field_to_find) { // this is the accounts contact - woo! $send_email_to[] = $contact; } } } if (!count($send_email_to) && $customer['primary_user_id']) { $primary = module_user::get_user($customer['primary_user_id']); if ($primary) { $send_email_to[] = $primary; } } } } else { if ($invoice['member_id']) { $member = module_member::get_member($invoice['member_id']); $to = array($member); $replace['customer_name'] = $member['first_name']; } else { $to = array(); } } $template->assign_values($replace); $html = $template->render('html'); // send an email to this user. $email = module_email::new_email(); $email->replace_values = $replace; // todo: send to all customer contacts ? if ($send_email_to) { foreach ($send_email_to as $send_email_t) { if (!empty($send_email_t['user_id'])) { $email->set_to('user', $send_email_t['user_id']); } else { if (!empty($send_email_t['email'])) { $email->set_to_manual($send_email_t['email']); } } } } else { foreach ($to as $t) { if (!empty($t['user_id'])) { $email->set_to('user', $t['user_id']); } else { if (!empty($t['email'])) { $email->set_to_manual($t['email']); } } break; // only 1? todo: all? } } $email->set_bcc_manual(module_config::c('admin_email_address', ''), ''); //$email->set_from('user',); // nfi $email->set_subject($template->description); // do we send images inline? $email->set_html($html); if ($pdf) { $email->add_attachment($pdf); } $email->invoice_id = $invoice_id; $email->customer_id = $invoice['customer_id']; $email->prevent_duplicates = true; if ($email->send($debug)) { // it worked successfully!! // record a log on the invoice when it's done. self::email_sent(array('invoice_id' => $invoice_id, 'template_name' => $template_name)); return true; } else { /// log err? return false; } }
$columns['file_customer'] = array('title' => 'Customer', 'callback' => function ($file) { echo module_customer::link_open($file['customer_id'], true); }); } if (class_exists('module_job', false)) { $columns['file_job'] = array('title' => 'Job', 'callback' => function ($file) { echo module_job::link_open($file['job_id'], true); }); } if (class_exists('module_quote', false) && module_quote::is_plugin_enabled()) { $columns['file_quote'] = array('title' => 'Quote', 'callback' => function ($file) { echo module_quote::link_open($file['quote_id'], true); }); } $columns['file_date_added'] = array('title' => 'Date Added', 'callback' => function ($file) { echo _l('%s by %s', print_date($file['date_created']), module_user::link_open($file['create_user_id'], true)); }); if (module_file::can_i('edit', 'Files')) { $columns['file_action'] = array('title' => ' ', 'callback' => function ($file) { echo '<input type="checkbox" name="bulk_operation[' . $file['file_id'] . ']" value="yes">'; }); } if (class_exists('module_extra', false)) { $table_manager->display_extra('file', function ($file) { module_extra::print_table_data('file', $file['file_id']); }); } $table_manager->set_columns($columns); $table_manager->row_callback = function ($row_data) { // load the full file data before displaying each row so we have access to more details if (isset($row_data['file_id']) && (int) $row_data['file_id'] > 0) {
} if ((int) $user_id > 0) { //handle_hook("note_list",$module,"user","user_id",$user_id); if (class_exists('module_note', false) && module_note::is_plugin_enabled()) { module_note::display_notes(array('title' => 'User Notes', 'owner_table' => 'user', 'owner_id' => $user_id, 'view_link' => $module->link_open($user_id))); } if (class_exists('module_group', false) && module_group::is_plugin_enabled()) { module_group::display_groups(array('title' => 'User Groups', 'owner_table' => 'user', 'owner_id' => $user_id, 'view_link' => module_user::link_open($user_id))); } } hook_handle_callback('layout_column_half', 2); if (is_file('includes/plugin_user/pages/user_admin_edit_login.php')) { include module_theme::include_ucm('includes/plugin_user/pages/user_admin_edit_login.php'); } if (is_file('includes/plugin_user/pages/user_admin_edit_staff.php')) { include module_theme::include_ucm('includes/plugin_user/pages/user_admin_edit_staff.php'); } if (is_file('includes/plugin_user/pages/user_admin_edit_company.php')) { include module_theme::include_ucm('includes/plugin_user/pages/user_admin_edit_company.php'); } 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 User')), array('ignore' => !($user_id != 1 && module_user::can_i('delete', 'Users', 'Config')), '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->link_open(false) . "';"))); echo module_form::generate_form_actions($form_actions); ?> </form>
</td> <?php } ?> </tr> <?php if ($show_split_hours) { ?> <tr class="task_editting task_row_<?php echo $task_id; ?> "> <td></td> <td style="text-align: right"> <?php _e('Staff Settings for: %s', module_user::link_open($task_data['user_id'], true)); ?> <input type="hidden" name="job_task[<?php echo $task_id; ?> ][staff_split]" value="1"> </td> <td> <?php if ($task_data['staff_hours'] != 0) { if ($task_data['manual_task_type'] == _TASK_TYPE_HOURS_AMOUNT && function_exists('decimal_time_out')) { $hours_value = decimal_time_out($task_data['staff_hours']); } else { $hours_value = number_out($task_data['staff_hours'], true); } } else {
</td> <td><?php echo htmlspecialchars($n['subject']); ?> </td> <td><?php $headers = unserialize($n['headers']); if (isset($headers['to']) && is_array($headers['to'])) { foreach ($headers['to'] as $to) { echo $to['email'] . ' '; } } ?> </td> <td><?php echo module_user::link_open($n['create_user_id'], true); ?> </td> </tr> <?php } ?> </tbody> </table> <div style="min-height: 10px;"> <?php echo $pagination['page_numbers'] > 1 ? $pagination['links'] : ''; ?> </div> </div> <?php
public static function hook_job_task_after($hook, $job_id, $task_id, $job_data, $task_data) { $comments = get_multiple('job_discussion', array('job_id' => $job_id, 'task_id' => $task_id), 'job_discussion_id', 'exact', 'job_discussion_id'); if ($job_data && isset($job_data['job_discussion']) && $job_data['job_discussion'] == 1) { // disabled & hidden. return; } if ($job_data && isset($job_data['job_discussion']) && $job_data['job_discussion'] == 2 && count($comments) == 0) { // disabled & shown. return; } if (isset($_POST['job_discussion_add_job_id']) && isset($_POST['job_discussion_add_task_id']) && $_POST['job_discussion_add_job_id'] == $job_id && $_POST['job_discussion_add_task_id'] == $task_id && isset($_POST['note']) && strlen($_POST['note'])) { $x = 0; while (ob_get_level() && $x++ < 10) { ob_end_clean(); } $current_user_id = module_security::get_loggedin_id(); $customer = module_customer::get_customer($job_data['customer_id']); if (!$current_user_id) { if ($job_data['customer_id'] && $customer['primary_user_id']) { $current_user_id = $customer['primary_user_id']; } } $result = array(); // adding a new note. $job_discussion_id = update_insert('job_discussion_id', 0, 'job_discussion', array('job_id' => $job_id, 'task_id' => $task_id, 'user_id' => $current_user_id, 'note' => $_POST['note'])); $result['job_discussion_id'] = $job_discussion_id; $result['count'] = count($comments) + 1; $tasks = module_job::get_tasks($job_id); $result['email_customer'] = array(); if (isset($_POST['sendemail_customer']) && is_array($_POST['sendemail_customer'])) { //$_POST['sendemail_customer'] == 'yes' && $customer['primary_user_id']){ // send email to customer primary user id. $customer_contacts = module_user::get_contacts(array('customer_id' => $job_data['customer_id'])); foreach ($_POST['sendemail_customer'] as $user_id) { $user_id = (int) $user_id; if ($user_id && isset($customer_contacts[$user_id])) { // we can email this user. $user = module_user::get_user($user_id, false); if ($user && $user['user_id'] == $user_id) { $values = array_merge($user, $job_data); $values['job_url'] = module_job::link_public($job_id); $values['job_url'] .= (strpos($values['job_url'], '?') === false ? '?' : '&') . 'discuss=' . $task_id . '#discuss' . $task_id; $values['job_name'] = $job_data['name']; $values['customer_name'] = $user['name'] . ' ' . $user['last_name']; $values['note'] = $_POST['note']; //todo: no order if no showning numbers $values['task_name'] = '#' . $tasks[$task_id]['task_order'] . ': ' . $tasks[$task_id]['description']; $template = module_template::get_template_by_key('job_discussion_email_customer'); $template->assign_values($values); $html = $template->render('html'); $email = module_email::new_email(); $email->replace_values = $values; $email->set_to('user', $user['user_id']); $email->set_from('user', $current_user_id); $email->set_subject($template->description); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! $result['email_customer'][] = $user['user_id']; } else { /// log err? } } } } /*$user = module_user::get_user($customer['primary_user_id'],false); if($user['user_id'] == $customer['primary_user_id']){ $values = array_merge($user,$job_data); $values['job_url'] = module_job::link_public($job_id); $values['job_url'] .= (strpos($values['job_url'],'?')===false ? '?' : '&').'discuss='.$task_id.'#discuss'.$task_id; $values['job_name'] = $job_data['name']; $values['customer_name'] = $user['name'].' '.$user['last_name']; $values['note'] = $_POST['note']; //todo: no order if no showning numbers $values['task_name'] = '#'.$tasks[$task_id]['task_order'].': '.$tasks[$task_id]['description']; $template = module_template::get_template_by_key('job_discussion_email_customer'); $template->assign_values($values); $html = $template->render('html'); $email = module_email::new_email(); $email->replace_values = $values; $email->set_to('user',$user['user_id']); $email->set_from('user',$current_user_id); $email->set_subject($template->description); // do we send images inline? $email->set_html($html); if($email->send()){ // it worked successfully!! $result['email_customer'] = 1; }else{ /// log err? $result['email_customer'] = 0; } }else{ // log error? $result['email_customer'] = 0; }*/ } if (isset($_POST['sendemail_staff']) && is_array($_POST['sendemail_staff'])) { // == 'yes' && $job_data['user_id'] // todo: handle the restul better when sending to multiple people $result['email_staff_list'] = $_POST['sendemail_staff']; foreach ($_POST['sendemail_staff'] as $staff_id) { // send email to staff $staff_id = (int) $staff_id; if (!$staff_id) { $result['nostaff'] = 1; continue; } if (isset($task_data['user_id']) && $task_data['user_id'] == $staff_id || isset($job_data['user_id']) && $job_data['user_id'] == $staff_id) { //$user = module_user::get_user($job_data['user_id'],false); $user = module_user::get_user($staff_id, false); if ($user['user_id'] == $staff_id) { $values = array_merge($user, $job_data); $values['job_url'] = module_job::link_public($job_id); $values['job_url'] .= (strpos($values['job_url'], '?') === false ? '?' : '&') . 'discuss=' . $task_id . '#discuss' . $task_id; $values['job_name'] = $job_data['name']; $values['staff_name'] = $user['name'] . ' ' . $user['last_name']; $values['note'] = $_POST['note']; //todo: no order if no showning numbers $values['task_name'] = '#' . $tasks[$task_id]['task_order'] . ': ' . $tasks[$task_id]['description']; $template = module_template::get_template_by_key('job_discussion_email_staff'); $template->assign_values($values); $html = $template->render('html'); $email = module_email::new_email(); $email->replace_values = $values; $email->set_to('user', $staff_id); $email->set_from('user', $current_user_id); $email->set_subject($template->description); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! $result['email_staff'] = 1; } else { /// log err? $result['email_staff'] = 0; } } else { // log error? $result['email_staff'] = 0; } } } } $x = 0; while ($x++ < 5 && ob_get_level()) { ob_end_clean(); } header("Content-type: text/javascript", true); echo json_encode($result); exit; } $label = htmlspecialchars(module_config::c('job_discussion_button_label', 'Task Comments')); ?> <a href="<?php echo self::link_public($job_id, $task_id); ?> " id="discuss<?php echo $task_id; ?> " class="task_job_discussion <?php echo $label ? 'with_text' : ''; ?> " title="<?php _e('View Discussion'); ?> "><span><?php echo count($comments) > 0 ? count($comments) : ''; ?> </span><?php echo $label; ?> </a> <div class="task_job_discussion_holder"<?php echo isset($_REQUEST['discuss']) && $_REQUEST['discuss'] == $task_id ? ' style="display:block;"' : ''; ?> > <?php if (isset($_REQUEST['discuss']) && $_REQUEST['discuss'] == $task_id) { $_REQUEST['t'] = $task_id; $_REQUEST['i'] = $job_id; $_REQUEST['hash'] = self::link_public($job_id, $task_id, true); self::external_hook('public'); } ?> </div> <?php }
$c[$row['user_id']] = $row['name'] . ' ' . $row['last_name']; } if ($ticket['user_id'] && !isset($c[$ticket['user_id']])) { // this option isn't in the listing. add it in. $user_temp = module_user::get_user($ticket['user_id'], false); $c[$ticket['user_id']] = $user_temp['name'] . ' ' . $user_temp['last_name']; if ($user_temp['customer_id'] >= 0) { $c[$ticket['user_id']] .= ' ' . _l('(under different customer)'); } else { // user not assigned to a customer. } } echo '<a name="#change_contact"></a>'; echo print_select_box($c, 'change_user_id', $ticket['user_id']); } else { echo module_user::link_open_contact($ticket['user_id'], true); if (module_ticket::can_edit_tickets()) { echo ' '; echo '<a href="' . module_ticket::link_open($ticket_id) . '&show_change_contact#change_contact">' . _l('Change') . '</a>'; } } /* $c = array(); $res = module_user::get_users(array('customer_id'=>$ticket['customer_id'])); while($row = array_shift($res)){ $c[$row['user_id']] = $row['name']; } if(false && module_ticket::can_i('edit','Related to')){ echo print_select_box($c,'user_id',$ticket['user_id']); }else if($ticket['user_id']){ echo isset($c[$ticket['user_id']]) ? $c[$ticket['user_id']] : 'N/A';
?> </th> </tr> </thead> <tbody> <?php $x = 1; $c = 1; $current_revision = array(); $last_revision_id = false; $next_revision_id = false; $previous_revision_id = false; $temp_revision_id = -1; $custom_highlight_fields = array(); foreach ($data_record_revisions as $data_record_revision) { $user = module_user::get_user($data_record_revision['create_user_id']); if ($previous_revision_id && !$next_revision_id) { $next_revision_id = $data_record_revision['data_record_revision_id']; } if ($data_record_revision['data_record_revision_id'] == $view_revision_id) { $current_revision = $data_record_revision; $current_revision['number'] = $x; $previous_revision_id = $temp_revision_id; } $temp_revision_id = $data_record_revision['data_record_revision_id']; ?> <tr class="<?php echo $c++ % 2 ? "odd" : "even"; ?> "> <td class="row_action"><a href="<?php
$total['job_count'] += $staff_report['job_count']; $total['task_count'] += $staff_report['task_count']; $total['tasks_complete'] += $staff_report['tasks_complete']; $total['hours_logged'] += $staff_report['hours_logged']; $total['hours_billed'] += $staff_report['hours_billed']; $total['amount_billed'] += $staff_report['amount_billed']; $total['amount_invoiced'] += $staff_report['amount_invoiced']; ?> <tr class="<?php echo $c++ % 2 ? "odd" : "even"; ?> "> <td> <?php echo module_user::link_open($staff_report['user_id'], true); ?> </td> <td> <?php echo $staff_report['job_count']; ?> </td> <td> <?php echo $staff_report['task_count']; ?> </td>
function get_form_element($element, $viewing_revision = false, $data_record = array()) { $has_write_access = !$viewing_revision; // convert our data field to an element. $element['name'] = isset($element['name']) && !empty($element['name']) ? $element['name'] : 'data_field[' . $element['data_field_id'] . ']'; $element['id'] = 'data_field_' . $element['data_field_id'] . ''; $element['type'] = $element['field_type']; if (!isset($element['value'])) { $element['value'] = ''; } if (!$has_write_access) { //$element['disabled'] = 'disabled'; $element['class'] = 'data_field_view'; } $highlight = false; $this->ajax_edit = false; $input_name = $element['name']; if (!$input_name) { return false; } if (isset($element['id']) && $element['id']) { $input_id = $element['id']; } else { $element['id'] = $input_name; $input_id = $input_name; } //if(!$value && isset($_REQUEST[$input_name]))$value = $_REQUEST[$input_name]; if (!$element['value']) { $element['value'] = $element['default']; } if (!is_array($element['value'])) { //$value=htmlspecialchars($value); } if (!isset($element['class'])) { $element['class'] = ''; } $attr = $attr_other = ''; if ($has_write_access) { if ($element['type'] == 'radio' || $element['type'] == 'checkbox_list') { // hacky! if ($element['required']) { $attr_other .= ' class="form_field form_field_required"'; } else { $attr_other .= ' class="form_field"'; } } else { $element['class'] .= " form_field"; if ($element['required']) { $element['class'] .= " form_field_required"; } } switch ($element['type']) { case 'date': $element['class'] .= " date_field"; if (!isset($element['size']) || !$element['size']) { $element['size'] = 8; } if (strtolower($element['value']) == 'now') { $element['value'] = print_date(time()); } break; case 'datetime': $element['class'] .= " date_time_field"; if (!isset($element['size']) || !$element['size']) { $element['size'] = 12; } if (strtolower($element['value']) == 'now') { $element['value'] = print_date(time(), true); } break; } } switch ($element['type']) { case 'checkbox_list': case 'radio': $element['attributes'] = array(); foreach (explode("\n", trim($element['field_data'])) as $line) { $line = trim($line); if (preg_match('/^attributes=/', $line)) { $line = preg_replace('/^attributes=/', '', $line); $element['attributes'] = explode("|", $line); break; } } break; case 'select': if (!isset($element['attributes']) || !is_array($element['attributes']) || !count($element['attributes'])) { $element['attributes'] = array(); foreach (explode("\n", trim($element['field_data'])) as $line) { $line = trim($line); if (preg_match('/^attributes=/', $line)) { $line = preg_replace('/^attributes=/', '', $line); if (preg_match('#hook:([\\w_]+)$#', $line, $matches)) { // see if we get anything back from this hook. $attributes = array(); $attributes = hook_filter_var($matches[1], $attributes, $element); if (is_array($attributes)) { $element['attributes'] = $attributes; } else { $element['attributes'] = array('Unable to call hook: ' . $matches[1]); } } else { $element['attributes'] = explode("|", $line); } break; } } } break; } if (!isset($element['style'])) { $element['style'] = ''; } // we have to apply some custom width/height styles if they exist. $width = $height = false; foreach (explode("\n", trim($element['field_data'])) as $line) { $line = trim($line); if (preg_match('/^width=/', $line)) { $line = preg_replace('/^width=/', '', $line); $width = (int) $line; } if (preg_match('/^height=/', $line)) { $line = preg_replace('/^height=/', '', $line); $height = (int) $line; } } if (!$height && $height < _MIN_INPUT_HEIGHT) { $height = _MIN_INPUT_HEIGHT; } switch ($element['type']) { case 'text': case 'date': case 'datetime': if ($width) { $element['style'] .= 'width:' . $width . 'px; '; } break; case 'radio': if ($width) { $attr_other .= ' style="width:' . $width . 'px; "'; } break; case 'textarea': case 'textbox': if ($width) { $element['style'] .= 'width:' . $width . 'px; '; } if ($has_write_access && $height) { $element['style'] .= 'height:' . $height . 'px; '; } break; } if (isset($element['width'])) { unset($element['width']); } if (isset($element['height'])) { unset($element['height']); } if (isset($element['multiple']) && $element['multiple']) { $element['multiple'] = true; // pass 'multiple' through to the UCM form builder which should handle everything $value_unserialize = @unserialize($element['value']); if (is_array($value_unserialize)) { $element['values'] = $value_unserialize; // 'values' is used in the UCM field generation tool } $element['name'] = $element['name'] . '[]'; } else { $element['multiple'] = false; } if (!$has_write_access && $element['multiple'] && isset($element['values']) && is_array($element['values'])) { $element['value'] = $element['values']; } if (is_array($element['value']) && count($element['value'])) { $all_values = $element['value']; } else { $all_values = array($element['value']); } if ($element['type'] == 'checkbox_list') { $test = @unserialize($element['value']); if (is_array($test) && count($test)) { $all_values = array($test); } else { $all_values = array($element['value']); } } if ($element['type'] == "cancel" && !isset($element['onclick'])) { $element['onclick'] = "history.go(-1);"; } if ($highlight) { $element['class'] .= " form_field_highlight"; } /*if(!$has_write_access){ $element['class'] .= ' form_disabled'; }*/ $attribute_keys = array('class', 'disabled', 'onclick', 'onfocus', 'onmouseup', 'onmousedown', 'onchange', 'size', 'cols', 'rows', 'width', 'style'); foreach ($element as $key => $val) { if (!is_array($val) && !trim($val)) { continue; } if (in_array(strtolower($key), $attribute_keys)) { if (in_array(strtolower($key), array('size', 'cols', 'rows', 'width', 'height')) && (int) $val == 0) { continue; } $attr .= ' ' . $key . '="' . $val . '"'; } } // check for default values, these are cleared when submitting the form if ($element['default']) { $has_default = true; } $real_input_id = $input_id; $real_input_name = $input_name; ob_start(); foreach ($all_values as $value_key => $value) { if (!$has_write_access) { // disabled. if (isset($width) && $width && $element['type'] != 'encrypted') { echo '<span ' . $attr; echo ' style="width:' . $width . 'px;"'; echo '> '; } // display value differently depending on value type. switch ($element['type']) { case 'checkbox_list': $other = ''; if (is_array($value)) { if (isset($value['other_val'])) { $other = $value['other_val']; unset($value['other_val']); } echo implode(', ', array_keys($value)); } echo ' ' . $other; break; case 'select': if (isset($element['attributes'])) { $attributes = $element['attributes']; } else { $attributes = array(); } if (isset($attributes[0])) { $new_attributes = array(); foreach ($attributes as $aid => $a) { $new_attributes[$aid + 1] = $a; } $attributes = $new_attributes; } if (isset($attributes[$value])) { echo $attributes[$value]; } break; case 'textarea': case 'textbox': echo nl2br(htmlspecialchars($value)); break; case 'file': if ($value) { $file_data = @unserialize($value); $file_link = 'includes/plugin_data/upload/' . $file_data['file']; if (is_file($file_link)) { $download_link = self::link_public_file_download($data_record['data_record_id'], $data_record['data_type_id'], $element['data_field_group_id'], $element['data_field_id']); echo '<a href="' . $download_link . '" target="_blank">' . $file_data['name'] . '</a>'; } else { echo 'File Not Found'; } } break; case 'wysiwyg': echo module_security::purify_html($value); break; case 'encrypted': if (class_exists('module_encrypt', false)) { ob_start(); $element['type'] = 'text'; module_form::generate_form_element($element); $enc_html = ob_get_clean(); echo module_encrypt::parse_html_input('custom_data', $enc_html, false); } break; case 'created_date_time': echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], true) : _l('N/A'); break; case 'created_date': echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], false) : _l('N/A'); break; case 'created_time': echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_created'])) : _l('N/A'); break; case 'updated_date_time': echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? print_date($data_record['date_updated'], true) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], true) : _l('N/A')); break; case 'updated_date': echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? print_date($data_record['date_updated'], false) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], false) : _l('N/A')); break; case 'updated_time': echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_updated'])) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_created'])) : _l('N/A')); break; case 'created_by': echo isset($data_record['create_user_id']) && (int) $data_record['create_user_id'] > 0 ? module_user::link_open($data_record['create_user_id'], true) : _l('N/A'); break; case 'updated_by': echo isset($data_record['update_user_id']) && (int) $data_record['update_user_id'] > 0 ? module_user::link_open($data_record['update_user_id'], true) : (isset($data_record['create_user_id']) && (int) $data_record['create_user_id'] > 0 ? module_user::link_open($data_record['create_user_id'], true) : _l('N/A')); break; case 'url': echo '<a href="' . htmlspecialchars($value) . '" target="_blank">' . htmlspecialchars($value) . '</a>'; break; default: echo htmlspecialchars($value); break; } if (isset($width) && $width && $element['type'] != 'encrypted') { echo ' </span>'; } } else { // update for UCM: use the ucm form generator if (isset($element['default']) && $element['default'] && !$element['value']) { $element['value'] = $element['default']; } switch ($element['type']) { case 'wysiwyg': $element['options']['inline'] = false; module_form::generate_form_element($element); break; case "radio": $has_val = false; foreach ($element['attributes'] as $attribute) { $this_input_id = $input_id . preg_replace('/[^a-zA-Z]/', '', $attribute); ?> <span class="field_radio"> <input type="radio" name="<?php echo $input_name; ?> " id="<?php echo $this_input_id; ?> " value="<?php echo htmlspecialchars($attribute); ?> "<?php if ($attribute == $value || strtolower($attribute) == 'other' && !$has_val) { // assumes "OTHER" is always last... fix with a separate loop before hand checking all vals if (strtolower($attribute) != 'other') { $has_val = true; } echo " checked"; } echo ' ' . $attr; if (strtolower($attribute) == 'other') { echo ' onmouseup="if(this.checked)$(\'#other_' . $this_input_id . '\')[0].focus();"'; echo ' onchange="if(this.checked)$(\'#other_' . $this_input_id . '\')[0].focus();"'; } ?> > <label for="<?php echo $this_input_id; ?> "><?php echo $attribute; ?> </label> <?php if (strtolower($attribute) == 'other') { ?> <span class="data_field_input"> <input type="text" name="other_<?php echo $input_name; ?> " id="other_<?php echo $this_input_id; ?> " value="<?php if (!$has_val) { echo htmlspecialchars($value); } ?> " onchange="$('input[type=radio]',$(this).parent())[0].checked = true;" <?php echo $attr . $attr_other; ?> > </span> <?php } ?> </span> <?php } break; case "checkbox_list": $has_val = false; if (!is_array($value)) { $value = array(); } foreach ($element['attributes'] as $attribute) { $this_input_id = $input_id . preg_replace('/[^a-zA-Z]/', '', $attribute); ?> <span class="field_radio"> <input type="checkbox" name="<?php echo $input_name; ?> [<?php echo htmlspecialchars($attribute); ?> ]" id="<?php echo $this_input_id; ?> " value="1"<?php if (isset($value[$attribute])) { if (strtolower($attribute) != 'other') { $has_val = true; } echo " checked"; } echo ' ' . $attr; if (strtolower($attribute) == 'other') { echo ' onmouseup="if(this.checked)$(\'#other_' . $this_input_id . '\')[0].focus();"'; echo ' onchange="if(this.checked)$(\'#other_' . $this_input_id . '\')[0].focus();"'; } ?> > <label for="<?php echo $this_input_id; ?> "><?php echo $attribute; ?> </label> <?php if (strtolower($attribute) == 'other') { ?> <span class="data_field_input"> <input type="text" name="<?php echo $input_name; ?> [other_val]" id="other_<?php echo $this_input_id; ?> " value="<?php echo isset($value['other_val']) ? htmlspecialchars($value['other_val']) : ''; ?> " onchange="$('input[type=radio]',$(this).parent())[0].checked = true;" <?php echo $attr . $attr_other; ?> > </span> <?php } ?> </span> <?php } break; case "file": $this->has_files = true; ?> <input type="file" name="<?php echo $input_name; ?> " id="<?php echo $input_id; ?> " value="<?php echo $value; ?> "<?php echo $attr; ?> > <?php break; case 'select': $attributes = isset($element['attributes']) ? $element['attributes'] : array(); if (isset($attributes[0])) { $new_attributes = array(); foreach ($attributes as $aid => $a) { $new_attributes[$aid + 1] = $a; } $attributes = $new_attributes; } $element['options'] = $attributes; module_form::generate_form_element($element); break; case 'encrypted': if (class_exists('module_encrypt', false)) { ob_start(); $element['type'] = 'text'; module_form::generate_form_element($element); $enc_html = ob_get_clean(); echo module_encrypt::parse_html_input('custom_data', $enc_html); } break; case 'created_date_time': echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], true) : _l('N/A'); break; case 'created_date': echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], false) : _l('N/A'); break; case 'created_time': echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_created'])) : _l('N/A'); break; case 'updated_date_time': echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? print_date($data_record['date_updated'], true) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], true) : _l('N/A')); break; case 'updated_date': echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? print_date($data_record['date_updated'], false) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], false) : _l('N/A')); break; case 'updated_time': echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_updated'])) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_created'])) : _l('N/A')); break; case 'created_by': echo isset($data_record['create_user_id']) && (int) $data_record['create_user_id'] > 0 ? module_user::link_open($data_record['create_user_id'], true) : _l('N/A'); break; case 'updated_by': echo isset($data_record['update_user_id']) && (int) $data_record['update_user_id'] > 0 ? module_user::link_open($data_record['update_user_id'], true) : (isset($data_record['create_user_id']) && (int) $data_record['create_user_id'] > 0 ? module_user::link_open($data_record['create_user_id'], true) : _l('N/A')); break; case 'url': $element['type'] = 'text'; module_form::generate_form_element($element); break; default: module_form::generate_form_element($element); } if (isset($element['after_link']) && $element['after_link']) { if (preg_match('/^https?:\\/\\//', $value) || ($have_www = preg_match('/^www\\./', $value) || ($have_www = preg_match('/\\.com/', $value) && !preg_match('/\\w@\\w/', $value)))) { // we have a url if ($have_www) { $value = "http://" . $value; } ?> <a href="<?php echo $value; ?> " target="_blank">»</a> <?php } if (preg_match('/\\w@\\w/', $value)) { ?> <a href="mailto:<?php echo $value; ?> ">»</a> <?php } } } // editable echo ' '; } // foreach all values //${$element_id} = ob_get_clean(); // we just print the html for now return ob_get_clean(); }
</td> </tr> <tr> <th> <?php _e('Last Decryption:'); ?> </th> <td> <?php $last = get_multiple('encrypt_access', array('encrypt_id' => $encrypt_id, 'status' => 2), 'encrypt_access_id', 'exact', 'encrypt_access_id DESC'); if (!$last) { _e('N/A'); } else { $last = array_shift($last); _e('By %s at %s from %s', module_user::link_open($last['create_user_id'], true), print_date($last['date_created'], true), preg_replace('#^(\\d*\\.\\d*).*$#', '$1.**.**', $last['create_ip_address'])); } ?> </td> </tr> <!-- <tr> <th> <?php _e('Raw Value:'); ?> </th> <td> <textarea name="data" rows="7" cols="60" id="raw_value"><?php echo $encrypt['data']; ?> </textarea>
/** * 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 (!$job_safe) { die('denied'); } $job_task_creation_permissions = module_job::get_job_task_creation_permissions(); $job_id = (int) $_REQUEST['job_id']; $job = module_job::get_job($job_id); $staff_members = module_user::get_staff_members(); $staff_member_rel = array(); foreach ($staff_members as $staff_member) { $staff_member_rel[$staff_member['user_id']] = $staff_member['name']; } $c = array(); $customers = module_customer::get_customers(); foreach ($customers as $customer) { $c[$customer['customer_id']] = $customer['customer_name']; } if (count($c) == 1) { $job['customer_id'] = key($c); } // check permissions. if (class_exists('module_security', false)) { module_security::check_page(array('category' => 'Job', 'page_name' => 'Jobs', 'module' => 'job', 'feature' => 'create'));
public static function print_note($note_id, $note_item, $display_summary = false, $can_edit = true, $can_delete = true, $options = array()) { if (!$note_item) { $note_item = self::get_note($note_id); } static $x = 0; global $plugins; $can_view = $can_edit = $can_create = $can_delete = false; // re-check permissions... if (isset($options) && isset($options['owner_table']) && $options['owner_table'] && isset($options['title']) && $options['title']) { $can_view = $plugins[$options['owner_table']]->can_i('view', $options['title']); $can_edit = $plugins[$options['owner_table']]->can_i('edit', $options['title']); $can_create = $plugins[$options['owner_table']]->can_i('create', $options['title']); $can_delete = $plugins[$options['owner_table']]->can_i('delete', $options['title']); } else { } if (!module_security::is_page_editable()) { //$can_edit=$can_create=$can_delete=false; } if (isset($options['summary_owners'])) { unset($options['summary_owners']); } if (isset($options['display_summary'])) { unset($options['display_summary']); } // if (!trim($note_item['note'])) { $note_item['note'] = 'none'; } ob_start(); /** START TABLE LAYOUT **/ $table_manager = module_theme::new_table_manager(); $columns = array(); $columns['date'] = array('title' => 'Date', 'width' => 60, 'callback' => function ($note_item) { if ($note_item['reminder']) { echo '<strong>'; } echo print_date($note_item['note_time']); if ($note_item['reminder']) { echo '</strong>'; } }); $columns['description'] = array('title' => 'Description', 'callback' => function ($note_item) { if (isset($note_item['public']) && $note_item['public']) { echo '* '; } if ($note_item['can_edit']) { $note_text = nl2br(htmlspecialchars(substr($note_item['note'], 0, module_config::c('note_trim_length', 35)))); $note_text .= strlen($note_item['note']) > module_config::c('note_trim_length', 35) ? '...' : ''; ?> <a href="<?php echo module_note::link_open($note_item['note_id'], false, $note_item['options']); ?> " data-options="<?php echo htmlspecialchars(base64_encode(serialize($note_item['options']))); ?> " class="note_edit note_options_link" rel="<?php echo $note_item['note_id']; ?> "> <?php echo $note_text; ?> </a> <?php } else { echo forum_text($note_item['note']); } }); $columns['info'] = array('title' => 'Info', 'width' => 40, 'callback' => function ($note_item) { if ($note_item['display_summary']) { if ($note_item['rel_data']) { global $plugins; echo $plugins[$note_item['owner_table']]->link_open($note_item['owner_id'], true); } } else { // find the user name who made thsi note. $user_data = module_user::get_user($note_item['create_user_id']); echo $user_data['name']; } }); if ($can_delete) { $columns['del'] = array('title' => ' ', 'callback' => function ($note_item) { if ($note_item['can_delete']) { ?> <a href="<?php echo module_note::link_open($note_item['note_id'], false, array_merge($note_item['options'], array('do_delete' => 'yes', 'note_id' => $note_item['note_id']))); ?> " data-options="<?php echo htmlspecialchars(base64_encode(serialize(array_merge($note_item['options'], array('do_delete' => 'yes', 'note_id' => $note_item['note_id']))))); ?> " rel="<?php echo $note_item['note_id']; ?> " onclick="if(confirm('<?php _e('Really Delete Note?'); ?> '))return true; else return false;" class="note_delete note_options_link delete ui-state-default ui-corner-all ui-icon ui-icon-trash">[x]</a> <?php } }); } $table_manager->set_columns($columns); $table_manager->inline_table = true; $table_manager->row_callback = function ($row_data, &$row_object) use($display_summary, $can_edit, $can_delete, &$options) { $row_data['display_summary'] = $display_summary; $row_data['can_edit'] = $can_edit; $row_data['can_delete'] = $can_delete; $row_data['options'] = $options; $row_object->row_id = 'note_' . $row_data['note_id']; return $row_data; }; $table_manager->print_row($note_item); /*?> <tr id="note_<?php echo $note_item['note_id'];?>" class="<?php echo ($x++%2)?'odd':'even';?>"> <td> <?php if($note_item['reminder'])echo '<strong>'; echo print_date($note_item['note_time']); if($note_item['reminder'])echo '</strong>'; ?> </td> <td> <?php if(isset($note_item['public']) && $note_item['public'])echo '* '; if($can_edit){ $note_text = nl2br(htmlspecialchars(substr($note_item['note'],0,module_config::c('note_trim_length',35)))); $note_text .= strlen($note_item['note']) > module_config::c('note_trim_length',35) ? '...' : ''; ?> <a href="<?php echo self::link_open($note_item['note_id'],false,$options);?>" data-options="<?php echo htmlspecialchars(base64_encode(serialize($options)));?>" class="note_edit note_options_link" rel="<?php echo $note_item['note_id'];?>"> <?php echo $note_text; ?> </a> <?php }else{ echo forum_text($note_item['note']); } ?> </td> <td nowrap="nowrap"> <?php if($display_summary){ if($note_item['rel_data']){ echo $plugins[$note_item['owner_table']]->link_open($note_item['owner_id'],true); } }else{ // find the user name who made thsi note. $user_data = module_user::get_user($note_item['create_user_id']); echo $user_data['name']; } ?> </td> <?php if($can_delete){ ?> <td><a href="<?php echo self::link_open($note_item['note_id'],false,array_merge($options,array('do_delete'=>'yes','note_id'=>$note_item['note_id'])));?>" data-options="<?php echo htmlspecialchars(base64_encode(serialize(array_merge($options,array('do_delete'=>'yes','note_id'=>$note_item['note_id'])))));?>" rel="<?php echo $note_item['note_id'];?>" onclick="if(confirm('<?php _e('Really Delete Note?');?>'))return true; else return false;" class="note_delete note_options_link delete ui-state-default ui-corner-all ui-icon ui-icon-trash">[x]</a></td> <?php } ?> </tr> <?php */ return ob_get_clean(); }
?> class="sendemail_customer"> <?php _e('Yes, send email to customer contact %s', module_user::link_open($user_id, true, array(), true)); ?> <?php echo $user_id == $customer['primary_user_id'] ? _l('(primary)') : ''; ?> <?php } foreach ($send_to_staff_ids as $staff_id => $checked) { // we are the admin, sending an email to assigned staff member ?> <br/> <input type="checkbox" name="sendemail_staff[]" value="<?php echo $staff_id; ?> " <?php echo $checked ? 'checked="checked"' : ''; ?> class="sendemail_staff"> <?php _e('Yes, send email to staff %s', module_user::link_open($staff_id, true, array(), true)); ?> <?php } if (!module_security::is_logged_in()) { echo '</div>'; } ?> </div> <?php }