function listCalendarByRange($sd, $ed) { $ret = array(); $ret['events'] = array(); $ret["issort"] = true; $ret["start"] = php2JsTime($sd); $ret["end"] = php2JsTime($ed); $ret['error'] = null; $calendar_data_access = module_calendar::get_calendar_data_access(); // hook into things like jobs and stuff who want to return calendar entries. $hook_results = hook_handle_callback('calendar_events', $sd, $ed); if (is_array($hook_results) && count($hook_results)) { foreach ($hook_results as $hook_result) { if (is_array($hook_result)) { foreach ($hook_result as $result) { // format our hook results to match our bad (indexed) array, // will update that array in the future /*$calendar_events[] = array( 'subject' => $job['name'], 'customer_id' => $job['customer_id'], 'start_time' => $job['date_start'], 'user_id' => $job['user_id'], 'description' => 'Test Description', 'link' => module_job::link_open($job['job_id'],true,$job), );*/ $staff_names = array(); if (isset($result['staff_ids']) && count($result['staff_ids'])) { switch ($calendar_data_access) { case _CALENDAR_ACCESS_ALL: break; case _CALENDAR_ACCESS_ASSIGNED: default: $current_user = module_security::get_loggedin_id(); if (!in_array($current_user, $result['staff_ids'])) { continue 2; } break; } foreach ($result['staff_ids'] as $staff_id) { $staff_names[] = module_user::link_open($staff_id, true); } } $staff_names = implode(', ', $staff_names); $result[0] = false; // no calendar ID at the moment $result[1] = $result['subject']; $result[2] = php2JsTime($result['start_time']); $result[3] = php2JsTime(isset($result['end_time']) ? $result['end_time'] : $result['start_time']); $result[4] = !isset($result['all_day']) || $result['all_day']; $result[5] = 0; $result[6] = 0; $result[7] = 0; //col $result[8] = 2; $result[9] = 0; $result[10] = 0; $result[13] = $result['customer_id']; $result[12] = $result['link']; $result[14] = isset($_REQUEST['customer_id']) && $_REQUEST['customer_id'] != $result['customer_id'] ? 'chip-fade' : ''; $result['staff'] = $staff_names; $ret['events'][] = $result; } } } } try { $sql = "select * from `" . _DB_PREFIX . "calendar` where `start` >= '" . mysql_real_escape_string($sd) . "' AND `start` <= '" . mysql_real_escape_string($ed) . "'"; // echo $sql; $rows = qa($sql); foreach ($rows as $row) { //$ret['events'][] = $row; //$attends = $row->AttendeeNames; //if($row->OtherAttendee){ // $attends .= $row->OtherAttendee; //} //echo $row->StartTime; $more_than_1_day = date('Ymd', $row['start']) == date('Ymd', $row['end']) ? 0 : 1; $customer_name = $customer_link = ''; if ($row['customer_id'] > 0) { $customer_data = module_customer::get_customer($row['customer_id'], true, true); if (!$customer_data || $customer_data['customer_id'] != $row['customer_id']) { $row['customer_id'] = 0; } else { switch ($calendar_data_access) { case _CALENDAR_ACCESS_ALL: break; case _CALENDAR_ACCESS_ASSIGNED: default: if (isset($customer_data['_no_access'])) { continue 2; } break; } $customer_name = $customer_data['customer_name']; $customer_link = module_customer::link_open($row['customer_id'], true, $customer_data); } } $calendar_event = module_calendar::get_calendar($row['calendar_id']); $staff_names = array(); if (count($calendar_event['staff_ids'])) { switch ($calendar_data_access) { case _CALENDAR_ACCESS_ALL: break; case _CALENDAR_ACCESS_ASSIGNED: default: $current_user = module_security::get_loggedin_id(); if (!in_array($current_user, $calendar_event['staff_ids'])) { continue 2; } break; } foreach ($calendar_event['staff_ids'] as $staff_id) { $staff_names[] = module_user::link_open($staff_id, true); } } $staff_names = implode(', ', $staff_names); $ret['events'][] = array(0 => $row['calendar_id'], 1 => $row['subject'], 2 => php2JsTime($row['start']), 3 => php2JsTime($row['end']), 4 => $row['is_all_day'], 5 => $more_than_1_day, 6 => 0, 7 => $row['color'], 8 => 1, 9 => '', 10 => '', 11 => $customer_name, 12 => $customer_link, 13 => $row['customer_id'], 14 => isset($_REQUEST['customer_id']) && $_REQUEST['customer_id'] != $row['customer_id'] ? 'chip-fade' : '', 'staff' => $staff_names); } } catch (Exception $e) { $ret['error'] = $e->getMessage(); } // build bubble content based on event data: foreach ($ret['events'] as $event_id => $event) { if (!isset($event['bubble'])) { $ret['events'][$event_id]['bubble'] = '<div id="bbit-cs-buddle" style="z-index: 1080; width: 400px;visibility:hidden;" class="bubble"><table class="bubble-table" cellSpacing="0" cellPadding="0"><tbody><tr><td class="bubble-cell-side"><div id="tl1" class="bubble-corner"><div class="bubble-sprite bubble-tl"></div></div><td class="bubble-cell-main"><div class="bubble-top"></div><td class="bubble-cell-side"><div id="tr1" class="bubble-corner"><div class="bubble-sprite bubble-tr"></div></div> <tr><td class="bubble-mid" colSpan="3"><div style="overflow: hidden" id="bubbleContent1"><div><div></div><div class="cb-root"><table class="cb-table" cellSpacing="0" cellPadding="0"><tbody>' . '<tr>' . '<td class="cb-value"><div class="textbox-fill-wrapper"><div class="textbox-fill-mid"><div id="bbit-cs-what" title="' . htmlspecialchars(_l('View Details')) . '" class="textbox-fill-div lk" style="cursor:pointer;">' . htmlspecialchars($event[1]) . '</div></div></div></td></tr><tr><td class=cb-value><div id="bbit-cs-buddle-timeshow"></div></td>' . '</tr>' . '<tr><td class=cb-value><div id="bbit-cs-customer-link">' . _l('Customer: %s', $event[12] ? $event[12] : _l('N/A')) . '</div></td></tr>' . (isset($event['other_details']) && strlen($event['other_details']) ? '<tr><td class=cb-value><div id="bbit-cs-customer-link">' . $event['other_details'] . '</div></td></tr>' : '') . '<tr><td class=cb-value><div id="bbit-cs-staff-link">' . _l('Staff: %s', $event['staff'] ? $event['staff'] : _l('N/A')) . '</div></td></tr>' . '</tbody></table>' . ($event[8] == 1 ? '<div class="bbit-cs-split"><input id="bbit-cs-id" type="hidden" value=""/>' . (module_calendar::can_i('delete', 'Calendar') ? '[ <span id="bbit-cs-delete" class="lk">' . htmlspecialchars(_l('Delete')) . '</span> ] ' : '') . (module_calendar::can_i('edit', 'Calendar') ? ' <span id="bbit-cs-editLink" class="lk">' . htmlspecialchars(_l('Edit Event')) . ' </span>' : '') . '</div> ' : '') . '</div></div></div><tr><td><div id="bl1" class="bubble-corner"><div class="bubble-sprite bubble-bl"></div></div><td><div class="bubble-bottom"></div><td><div id="br1" class="bubble-corner"><div class="bubble-sprite bubble-br"></div></div></tr></tbody></table><div id="bubbleClose2" class="bubble-closebutton"></div><div id="prong1" class="prong"><div class=bubble-sprite></div></div></div>'; } } return $ret; }
</td> <td> <?php switch ($invoice_payment_data['payment_type']) { case _INVOICE_PAYMENT_TYPE_NORMAL: echo htmlspecialchars($invoice_payment_data['method']); break; case _INVOICE_PAYMENT_TYPE_CREDIT: _e('Credit from customer %s', module_customer::link_open($invoice_payment_data['other_id'], true)); break; case _INVOICE_PAYMENT_TYPE_DEPOSIT: _e('Deposit from invoice %s', module_invoice::link_open($invoice_payment_data['other_id'], true)); break; case _INVOICE_PAYMENT_TYPE_OVERPAYMENT_CREDIT: _e('Assigning Credit to: %s', module_customer::link_open($invoice['customer_id'], true)); break; case _INVOICE_PAYMENT_TYPE_REFUND: _e('Refund: %s', htmlspecialchars($invoice_payment_data['method'])); break; case _INVOICE_PAYMENT_TYPE_SUBSCRIPTION_CREDIT: $subscription_owner = module_subscription::get_subscription_owner($invoice_payment_data['other_id']); _e('Subscription credit from %s', module_subscription::link_open($subscription_owner['subscription_id'], true)); break; } ?> </td> <td> <span class="currency"> <?php
echo module_user::link_open_contact($user['user_id'], true, $user); if ($user['is_primary'] == $user['user_id']) { echo ' *'; } }, 'cell_class' => 'row_action'); $columns['phone'] = array('title' => 'Phone Number', 'callback' => function ($user) { module_user::print_contact_summary($user['user_id'], 'html', array('phone|mobile')); }); $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);
echo module_quote::link_open($quote['quote_id'], true, $quote); }, 'cell_class' => 'row_action'); $columns['quote_start_date'] = array('title' => 'Create Date', 'callback' => function ($quote) { echo print_date($quote['date_create']); }); $columns['quote_completed_date'] = array('title' => 'Accepted Date', 'callback' => function ($quote) { echo print_date($quote['date_approved']); }); if (class_exists('module_website', false) && module_website::is_plugin_enabled()) { $columns['quote_website'] = array('title' => module_config::c('project_name_single', 'Website'), 'callback' => function ($quote) { echo module_website::link_open($quote['website_id'], true); }); } if (!isset($_REQUEST['customer_id']) && module_customer::can_i('view', 'Customers')) { $columns['quote_customer'] = array('title' => 'Customer', 'callback' => function ($quote) { echo module_customer::link_open($quote['customer_id'], true); }); } $columns['quote_type'] = array('title' => 'Type', 'callback' => function ($quote) { echo htmlspecialchars($quote['type']); }); $columns['quote_status'] = array('title' => 'Status', 'callback' => function ($quote) { echo htmlspecialchars($quote['status']); }); if (module_config::c('quote_allow_staff_assignment', 1)) { $columns['quote_staff'] = array('title' => 'Staff Member', 'callback' => function ($quote) { echo module_user::link_open($quote['user_id'], true); }); } if (module_job::can_i('view', 'Jobs')) { $job_ids = array();
function save_file_comments($file_id) { if (isset($_REQUEST['new_comment_text']) && strlen($_REQUEST['new_comment_text'])) { $file_data = $this->get_file($file_id); $item_data = array("file_id" => $file_id, "create_user_id" => module_security::get_loggedin_id(), "comment" => $_REQUEST['new_comment_text']); update_insert("file_comment_id", "new", "file_comment", $item_data); $file_data['comment'] = $_REQUEST['new_comment_text']; // do we schedule an alert for this file upload? if (module_security::can_user(module_security::get_loggedin_id(), _FILE_COMMENT_ALERT_STRING)) { // the current user is one who receives file alerts. // so for now we don't schedule this alert. // hmm - this might not work with a team environment, we'll send alerts no matter what :) } $alert_users = module_user::get_users_by_permission(array('category' => _LABEL_USER_SPECIFIC, 'name' => _FILE_COMMENT_ALERT_STRING, 'module' => 'config', 'view' => 1)); if (count($file_data['staff_ids'])) { foreach ($alert_users as $user_id => $alert_user) { if (!in_array($user_id, $file_data['staff_ids'])) { // this user has permissions to receive alerts, but they're not assigned. unset($alert_users[$user_id]); } } } else { if (isset($alert_users[1])) { unset($alert_users[1]); // skip admin for now until we can control that option } } // dont set a notification to ourselves. if (isset($alert_users[module_security::get_loggedin_id()])) { unset($alert_users[module_security::get_loggedin_id()]); } $file_data['customer_name'] = ''; $file_data['customer_link'] = ''; if (isset($file_data['customer_id']) && $file_data['customer_id']) { $customer_data = module_customer::get_customer($file_data['customer_id']); $file_data['customer_name'] = $customer_data['customer_name']; $file_data['customer_link'] = module_customer::link_open($file_data['customer_id']); } $file_data['file_link'] = self::link_open($file_id); foreach ($alert_users as $alert_user) { if (isset($alert_user['customer_id']) && $alert_user['customer_id'] > 0) { // only send this user an alert of the file is from this customer account. if (!isset($file_data['customer_id']) || $file_data['customer_id'] != $alert_user['customer_id']) { continue; // skip this user } } $notification_data = array('email_id' => 0, 'view_time' => 0, 'notification_type' => _FILE_NOTIFICATION_TYPE_COMMENTED, 'file_id' => $file_id, 'user_id' => $alert_user['user_id']); $template = module_template::get_template_by_key('file_comment_alert_email'); $template->assign_values($file_data); $html = $template->render('html'); // send an email to this user. $email = module_email::new_email(); $email->file_id = $file_id; $email->replace_values = $file_data; $email->set_to('user', $alert_user['user_id']); $email->set_from('user', module_security::get_loggedin_id()); $email->set_subject($template->description); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! // sweet. $notification_data['email_id'] = $email->email_id; } else { /// log err? set_error('Failed to send notification email to user id ' . $alert_users['user_id']); } update_insert('file_notification_id', 'new', 'file_notification', $notification_data); } } }
public static function get_finance_recurring_items($hook, $search) { /** * next_due_date * url * type (i or e) * amount * currency_id * days * months * years * last_transaction_finance_id * account_name * categories * finance_recurring_id */ // find list of all members. // then go through and fine list of all upcoming subscription payments. // add these ones (and future ones up to (int)module_config::c('finance_recurring_months',6) months from todays date. $end_date = isset($search['date_to']) && !empty($search['date_to']) ? strtotime(input_date($search['date_to'])) : strtotime("+" . (int) module_config::c('finance_recurring_months', 6) . ' months'); /*$sql = "SELECT s.*, sm.*"; $sql .= " FROM `"._DB_PREFIX."subscription_member` sm "; $sql .= " LEFT JOIN `"._DB_PREFIX."subscription` s USING (subscription_id)"; $sql .= " WHERE sm.`deleted` = 0"; $members = qa($sql); $sql = "SELECT s.*, sc.*"; $sql .= " FROM `"._DB_PREFIX."subscription_customer` sc "; $sql .= " LEFT JOIN `"._DB_PREFIX."subscription` s USING (subscription_id)"; $sql .= " WHERE sc.`deleted` = 0"; $customers = qa($sql); $items = array_merge($members,$customers);*/ //$members = module_member::ge $sql = "SELECT s.*, so.*"; $sql .= " FROM `" . _DB_PREFIX . "subscription_owner` so "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "subscription` s USING (subscription_id)"; $sql .= " WHERE so.`deleted` = 0"; $sql .= " GROUP BY `owner_table`, `owner_id`"; $items = qa($sql); //$members = module_member::get_members(array()); $return = array(); foreach ($items as $member) { $subscriptions = module_subscription::get_subscriptions_by($member['owner_table'], $member['owner_id']); /*if(isset($member['member_id']) && $member['member_id']){ }else if(isset($member['customer_id']) && $member['customer_id']){ $subscriptions = module_subscription::get_subscriptions_by_customer($member['customer_id']); }else{ $subscriptions = array(); }*/ foreach ($subscriptions as $subscription) { $time = strtotime($subscription['next_generation_date'] ? $subscription['next_generation_date'] : $subscription['next_due_date']); if (!$time) { continue; } switch ($member['owner_table']) { case 'customer': $type = 'customer'; $member_name = module_customer::link_open($member['owner_id'], true); $subscription_invoices = self::get_subscription_history($subscription['subscription_id'], $member['owner_table'], $member['owner_id']); break; case 'website': $type = 'website'; $member_name = module_website::link_open($member['owner_id'], true); $subscription_invoices = self::get_subscription_history($subscription['subscription_id'], $member['owner_table'], $member['owner_id']); break; case 'member': $type = 'member'; $member_name = module_member::link_open($member['owner_id'], true); $subscription_invoices = self::get_subscription_history($subscription['subscription_id'], $member['owner_table'], $member['owner_id']); break; default: $subscription_invoices = array(); $member_name = 'unknown2'; $type = 'unknown2'; } $subscription_name = module_subscription::link_open($subscription['subscription_id'], true); foreach ($subscription_invoices as $subscription_invoice_id => $subscription_invoice) { if ($subscription_invoice['invoice_id']) { $subscription_invoices[$subscription_invoice_id] = array_merge($subscription_invoice, module_invoice::get_invoice($subscription_invoice['invoice_id'], 2)); } } $original = true; $c = 0; while ($time < $end_date) { if ($c++ > 200) { break; } $next_time = 0; if (!$subscription['days'] && !$subscription['months'] && !$subscription['years']) { // it's a once off.. // add it to the list but dont calculate the next one. } else { if (!$original) { // work out when the next one will be. $next_time = self::_calculate_next_time($time, $subscription); $time = $next_time; } else { $original = false; // it's the original one. $next_time = $time; } } if ($next_time) { // don't show it here if an invoice has already been generated. // because invoice will already be in the list as outstanding foreach ($subscription_invoices as $subscription_invoice) { if (isset($subscription_invoice['date_create']) && $subscription_invoice['date_create'] == date('Y-m-d', $next_time)) { //echo 'match'; continue 2; } } $return[] = array('next_due_date' => date('Y-m-d', $next_time), 'url' => _l('Subscription: %s', $member_name), 'type' => 'i', 'amount' => $subscription['amount'], 'currency_id' => $subscription['currency_id'], 'days' => $subscription['days'], 'months' => $subscription['months'], 'years' => $subscription['years'], 'last_transaction_finance_id' => 0, 'account_name' => '', 'categories' => '', 'finance_recurring_id' => 0, 'last_transaction_text' => '(see member page)', 'end_date' => '0000-00-00', 'start_date' => $subscription['start_date'], 'recurring_text' => _l('Payment from %s %s on subscription %s', $type, $member_name, $subscription_name)); } } } } return $return; }
<td> <?php $c = array(); $customers = module_customer::get_customers(); foreach ($customers as $customer) { $c[$customer['customer_id']] = $customer['customer_name']; } echo print_select_box($c, 'customer_id', $job['customer_id']); ?> <?php if ($job['customer_id'] && module_customer::can_i('view', 'Customers')) { ?> <a href="<?php echo module_customer::link_open($job['customer_id'], false); ?> "><?php _e('Open'); ?> </a> <?php } ?> </td> </tr> <?php if (class_exists('module_quote', false) && module_quote::is_plugin_enabled() && module_quote::can_i('view', 'Quotes')) { ?>
module_form::set_required(array('fields' => array('subject' => 'Subject', 'start' => 'Start Date', 'end' => 'End Date'))); $customer_list = array(); $customers = module_customer::get_customers(); foreach ($customers as $customer) { $customer_list[$customer['customer_id']] = $customer['customer_name']; } $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']; } if (!isset($calendar['staff_ids']) || !is_array($calendar['staff_ids']) || !count($calendar['staff_ids'])) { $calendar['staff_ids'] = array(false); } // output our event information using the standard UCM form processor: $fieldset_data = array('heading' => false, 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array(array('title' => _l('Subject'), 'fields' => array('<div id="calendarcolor" style="float:right"></div><input id="colorvalue" name="color" type="hidden" value="' . (isset($calendar['color']) ? htmlspecialchars($calendar['color']) : '') . '" />', array('type' => 'text', 'name' => "subject", 'value' => isset($calendar['subject']) ? $calendar['subject'] : ''))), array('title' => _l('Start'), 'fields' => array(array('type' => 'date', 'name' => "start", 'value' => isset($calendar['start']) ? print_date($calendar['start']) : ''), '<span class="calendar_time">@</span>', array('type' => 'time', 'name' => "start_time", 'value' => isset($calendar['start']) ? date('g:ia', $calendar['start']) : '', 'class' => 'calendar_time'), array('type' => 'check', 'id' => "is_all_day", 'value' => 1, 'name' => "is_all_day", 'checked' => isset($calendar['is_all_day']) && $calendar['is_all_day'] ? true : false, 'label' => _l('All Day Event')))), array('title' => _l('End'), 'fields' => array(array('type' => 'date', 'name' => "end", 'value' => isset($calendar['end']) ? print_date($calendar['end']) : ''), '<span class="calendar_time">@</span>', array('type' => 'time', 'name' => "end_time", 'value' => isset($calendar['end']) ? date('g:ia', $calendar['end']) : '', 'class' => 'calendar_time'))), array('title' => _l('Customer'), 'fields' => array(array('type' => 'select', 'name' => 'customer_id', 'options' => $customer_list, 'value' => isset($calendar['customer_id']) ? $calendar['customer_id'] : 0), isset($calendar['customer_id']) && $calendar['customer_id'] ? '<a href="' . module_customer::link_open($calendar['customer_id'], false) . '" target="_blank">' . _l('Open') . '</a>' : '')), array('title' => module_config::c('customer_staff_name', 'Staff'), 'fields' => array('<div id="staff_ids_holder" style="float:left;">', array('type' => 'select', 'name' => 'staff_ids[]', 'options' => $staff_member_rel, 'multiple' => 'staff_ids_holder', 'values' => $calendar['staff_ids']), '</div>', _hr('Assign a staff member to this calendar event. Click the plus sign to add more staff members.'))), array('title' => _l('Description'), 'field' => array('type' => 'textarea', 'name' => "description", 'value' => isset($calendar['description']) ? $calendar['description'] : '')))); echo module_form::generate_fieldset($fieldset_data); /* $form_actions = array( 'class' => 'action_bar action_bar_center', 'elements' => array( array( 'type' => 'save_button', 'name' => 'butt_save', 'value' => _l('Save'), ), array( 'ignore' => !(module_calendar::can_i('delete','Calendar') && $calendar_id > 0), 'type' => 'delete_button', 'name' => 'butt_del', 'value' => _l('Delete'),
$total_unpaid[$subscription['currency_id']] += $h['amount']; } } foreach ($total_paid as $id => $t) { $total_paid[$id] = dollar($t, true, $id); } foreach ($total_unpaid as $id => $t) { $total_unpaid[$id] = dollar($t, true, $id); } ?> <tr> <td><?php switch ($subscribed_customer['owner_table']) { case 'customer': echo module_customer::link_open($subscribed_customer['owner_id'], true); break; case 'website': echo module_website::link_open($subscribed_customer['owner_id'], true); break; case 'member': echo module_member::link_open($subscribed_customer['owner_id'], true); break; } ?> </td> <td><?php echo print_date($subscribed_customer['start_date']); ?> </td> <td><?php
public function external_hook($hook) { switch ($hook) { case 'public_signup_form': $signup_form = module_template::get_template_by_key('customer_signup_form_wrapper'); $signup_form->page_title = $signup_form->description; $signup_form->assign_values(array('signup_form' => self::get_customer_signup_form_html())); echo $signup_form->render('pretty_html'); exit; case 'public_signup': // sign out if testing. if (module_security::is_logged_in()) { set_message('Logged out due to signup'); module_security::logout(); } $result = array('messages' => array()); function customer_signup_complete($result) { if (isset($_REQUEST['via_ajax'])) { echo json_encode($result); } else { echo implode('<br/>', $result['messages']); } exit; } if (!module_config::c('customer_signup_allowed', 0)) { $result['error'] = 1; $result['messages'][] = 'Customer signup disabled'; customer_signup_complete($result); } //recaptcha on signup form. if (module_config::c('captcha_on_signup_form', 0)) { if (!module_captcha::check_captcha_form()) { $result['error'] = 1; $result['messages'][] = 'Captcha fail, please go back and enter correct captcha code.'; customer_signup_complete($result); } } $customer = isset($_POST['customer']) && is_array($_POST['customer']) ? $_POST['customer'] : array(); $contact = isset($_POST['contact']) && is_array($_POST['contact']) ? $_POST['contact'] : array(); $contact_extra = isset($contact['extra']) && is_array($contact['extra']) ? $contact['extra'] : array(); $contact_group = isset($contact['group_ids']) && is_array($contact['group_ids']) ? $contact['group_ids'] : array(); $customer_extra = isset($customer['extra']) ? $customer['extra'] : array(); $customer_group = isset($customer['group_ids']) && is_array($customer['group_ids']) ? $customer['group_ids'] : array(); $address = isset($_POST['address']) ? $_POST['address'] : array(); $website = isset($_POST['website']) ? $_POST['website'] : array(); $website_extra = isset($website['extra']) ? $website['extra'] : array(); $website_group = isset($website['group_ids']) && is_array($website['group_ids']) ? $website['group_ids'] : array(); $job = isset($_POST['job']) ? $_POST['job'] : array(); $job_extra = isset($job['extra']) ? $job['extra'] : array(); $subscription = isset($_POST['subscription']) ? $_POST['subscription'] : array(); // sanatise possibly problematic fields: // customer: $allowed = array('name', 'last_name', 'customer_name', 'email', 'phone', 'mobile', 'extra', 'type'); foreach ($customer as $key => $val) { if (!in_array($key, $allowed)) { unset($customer[$key]); } } if (isset($customer['type']) && $customer['type'] != _CUSTOMER_TYPE_NORMAL && $customer['type'] != _CUSTOMER_TYPE_LEAD) { unset($customer['type']); } // added multiple contact support in the form of arrays. $contact_fields = array('name', 'last_name', 'email', 'phone'); if (module_config::c('customer_signup_password', 0)) { $contact_fields[] = 'password'; } foreach ($contact_fields as $multi_value) { if (isset($contact[$multi_value])) { if (!is_array($contact[$multi_value])) { $contact[$multi_value] = array($contact[$multi_value]); } } else { if (isset($customer[$multi_value])) { $contact[$multi_value] = array($customer[$multi_value]); } else { $contact[$multi_value] = array(); } } } $valid_contact_email = false; $name_fallback = false; $primary_email = false; foreach ($contact['email'] as $contact_key => $email) { if (!$name_fallback && isset($contact['name'][$contact_key])) { $name_fallback = $contact['name'][$contact_key]; } $contact['email'][$contact_key] = filter_var(strtolower(trim($email)), FILTER_VALIDATE_EMAIL); if ($contact['email'][$contact_key]) { $valid_contact_email = true; if (!$primary_email) { $primary_email = $contact['email'][$contact_key]; // set the primary contact details here by adding them to the master customer array foreach ($contact_fields as $primary_contact_field) { $customer[$primary_contact_field] = isset($contact[$primary_contact_field][$contact_key]) ? $contact[$primary_contact_field][$contact_key] : ''; unset($contact[$primary_contact_field][$contact_key]); } } } } // start error checking / required fields if (!isset($customer['customer_name']) || !strlen($customer['customer_name'])) { $customer['customer_name'] = $name_fallback; } if (!strlen($customer['customer_name'])) { $result['error'] = 1; $result['messages'][] = "Failed, please go back and provide a customer name."; } if (!$valid_contact_email || !$primary_email) { $result['error'] = 1; $result['messages'][] = "Failed, please go back and provide an email address."; } // check all posted required fields. function check_required($postdata, $messages = array()) { if (is_array($postdata)) { foreach ($postdata as $key => $val) { if (strpos($key, '_required') && strlen($val)) { $required_key = str_replace('_required', '', $key); if (!isset($postdata[$required_key]) || !$postdata[$required_key]) { $messages[] = 'Required field missing: ' . htmlspecialchars($val); } } if (is_array($val)) { $messages = check_required($val, $messages); } } } return $messages; } $messages = check_required($_POST); if (count($messages)) { $result['error'] = 1; $result['messages'] = array_merge($result['messages'], $messages); } if (isset($result['error'])) { customer_signup_complete($result); } // end error checking / required fields. // check if this customer already exists in the system, based on email address $customer_id = false; $creating_new = true; $_REQUEST['user_id'] = 0; if (isset($customer['email']) && strlen($customer['email']) && !module_config::c('customer_signup_always_new', 0)) { $users = module_user::get_contacts(array('email' => $customer['email'])); foreach ($users as $user) { if (isset($user['customer_id']) && (int) $user['customer_id'] > 0) { // this user exists as a customer! yey! // add them to this listing. $customer_id = $user['customer_id']; $creating_new = false; $_REQUEST['user_id'] = $user['user_id']; // dont let signups update existing passwords. if (isset($customer['password'])) { unset($customer['password']); } if (isset($customer['new_password'])) { unset($customer['new_password']); } } } } $_REQUEST['extra_customer_field'] = array(); $_REQUEST['extra_user_field'] = array(); module_extra::$config['allow_new_keys'] = false; module_extra::$config['delete_existing_empties'] = false; // save customer extra fields. if (count($customer_extra)) { // format the address so "save_customer" handles the save for us foreach ($customer_extra as $key => $val) { $_REQUEST['extra_customer_field'][] = array('key' => $key, 'val' => $val); } } // save customer and customer contact details: $customer_id = $this->save_customer($customer_id, $customer); if (!$customer_id) { $result['error'] = 1; $result['messages'][] = 'System error: failed to create customer.'; customer_signup_complete($result); } $customer_data = module_customer::get_customer($customer_id); // todo - merge primary and secondary contact/extra/group saving into a single loop if (!$customer_data['primary_user_id']) { $result['error'] = 1; $result['messages'][] = 'System error: Failed to create customer contact.'; customer_signup_complete($result); } else { $role_id = module_config::c('customer_signup_role', 0); if ($role_id > 0) { module_user::add_user_to_role($customer_data['primary_user_id'], $role_id); } // save contact extra data (repeated below for additional contacts) if (isset($contact_extra[0]) && count($contact_extra[0])) { $_REQUEST['extra_user_field'] = array(); foreach ($contact_extra[0] as $key => $val) { $_REQUEST['extra_user_field'][] = array('key' => $key, 'val' => $val); } module_extra::save_extras('user', 'user_id', $customer_data['primary_user_id']); } // save contact groups if (isset($contact_group[0]) && count($contact_group[0])) { foreach ($contact_group[0] as $group_id => $tf) { if ($tf) { module_group::add_to_group($group_id, $customer_data['primary_user_id'], 'user'); } } } } foreach ($contact['email'] as $contact_key => $email) { // add any additional contacts to the customer. $users = module_user::get_contacts(array('email' => $email, 'customer_id' => $customer_id)); if (count($users)) { // this contact already exists for this customer, dont update/change it. continue; } $new_contact = array('customer_id' => $customer_id); foreach ($contact_fields as $primary_contact_field) { $new_contact[$primary_contact_field] = isset($contact[$primary_contact_field][$contact_key]) ? $contact[$primary_contact_field][$contact_key] : ''; } // dont let additional contacts have passwords. if (isset($new_contact['password'])) { unset($new_contact['password']); } if (isset($new_contact['new_password'])) { unset($new_contact['new_password']); } global $plugins; $contact_user_id = $plugins['user']->create_user($new_contact, 'signup'); if ($contact_user_id) { $role_id = module_config::c('customer_signup_role', 0); if ($role_id > 0) { module_user::add_user_to_role($contact_user_id, $role_id); } // save contact extra data (repeated below for primary contacts) if (isset($contact_extra[$contact_key]) && count($contact_extra[$contact_key])) { $_REQUEST['extra_user_field'] = array(); foreach ($contact_extra[$contact_key] as $key => $val) { $_REQUEST['extra_user_field'][] = array('key' => $key, 'val' => $val); } module_extra::save_extras('user', 'user_id', $contact_user_id); } // save contact groups if (isset($contact_group[$contact_key]) && count($contact_group[$contact_key])) { foreach ($contact_group[$contact_key] as $group_id => $tf) { if ($tf) { module_group::add_to_group($group_id, $contact_user_id, 'user'); } } } } } if (count($customer_group)) { // format the address so "save_customer" handles the save for us foreach ($customer_group as $group_id => $tf) { if ($tf) { module_group::add_to_group($group_id, $customer_id, 'customer'); } } } $note_keys = array('customer', 'website', 'job', 'address', 'subscription'); $note_text = _l('Customer signed up from Signup Form:'); $note_text .= "\n\n"; foreach ($note_keys as $note_key) { $note_text .= "\n" . ucwords(_l($note_key)) . "\n"; if (isset($_POST[$note_key]) && is_array($_POST[$note_key])) { foreach ($_POST[$note_key] as $post_key => $post_val) { $note_text .= "\n - " . _l($post_key) . ": "; if (is_array($post_val)) { foreach ($post_val as $p => $v) { $note_text .= "\n - - " . _l($p) . ': ' . $v; } } else { $note_text .= $post_val; } } } } $note_data = array('note_id' => false, 'owner_id' => $customer_id, 'owner_table' => 'customer', 'note_time' => time(), 'note' => $note_text, 'rel_data' => module_customer::link_open($customer_id), 'reminder' => 0, 'user_id' => 0); update_insert('note_id', false, 'note', $note_data); // save customer address fields. if (count($address)) { $address_db = module_address::get_address($customer_id, 'customer', 'physical'); $address_id = $address_db && isset($address_db['address_id']) ? (int) $address_db['address_id'] : false; $address['owner_id'] = $customer_id; $address['owner_table'] = 'customer'; $address['address_type'] = 'physical'; // we have post data to save, write it to the table!! module_address::save_address($address_id, $address); } // website: $allowed = array('url', 'name', 'extra', 'notes'); foreach ($website as $key => $val) { if (!in_array($key, $allowed)) { unset($website[$key]); } } $website['url'] = isset($website['url']) ? strtolower(trim($website['url'])) : ''; $website_id = 0; if (count($website) && class_exists('module_website', false) && module_website::is_plugin_enabled()) { if (strlen($website['url'])) { // see if website already exists, don't create or update existing one for now. $existing_websites = module_website::get_websites(array('customer_id' => $customer_id, 'url' => $website['url'])); foreach ($existing_websites as $existing_website) { $website_id = $existing_website['website_id']; } } // echo $website_id;echo $website['url']; print_r($website_extra);exit; if (!$website_id) { $website_data = module_website::get_website($website_id); $website_data['url'] = isset($website['url']) ? $website['url'] : 'N/A'; $website_data['name'] = isset($website['url']) ? $website['url'] : 'N/A'; $website_data['customer_id'] = $customer_id; $website_id = update_insert('website_id', false, 'website', $website_data); // save website extra data. if ($website_id && count($website_extra)) { $_REQUEST['extra_website_field'] = array(); foreach ($website_extra as $key => $val) { $_REQUEST['extra_website_field'][] = array('key' => $key, 'val' => $val); } module_extra::save_extras('website', 'website_id', $website_id); } if ($website_id && isset($website['notes']) && strlen($website['notes'])) { // add notes to this website. $note_data = array('note_id' => false, 'owner_id' => $website_id, 'owner_table' => 'website', 'note_time' => time(), 'note' => $website['notes'], 'rel_data' => module_website::link_open($website_id), 'reminder' => 0, 'user_id' => $customer_data['primary_user_id']); $note_id = update_insert('note_id', false, 'note', $note_data); } } if ($website_id) { if (count($website_group)) { // format the address so "save_customer" handles the save for us foreach ($website_group as $group_id => $tf) { if ($tf) { module_group::add_to_group($group_id, $website_id, 'website'); } } } } } // generate jobs for this customer. $job_created = array(); if ($job && isset($job['type']) && is_array($job['type'])) { if (module_config::c('customer_signup_any_job_type', 0)) { foreach ($job['type'] as $type_name) { // we have a match in our system. create the job. $job_data = module_job::get_job(false); $job_data['type'] = $type_name; if (!$job_data['name']) { $job_data['name'] = $type_name; } $job_data['website_id'] = $website_id; $job_data['customer_id'] = $customer_id; $job_id = update_insert('job_id', false, 'job', $job_data); // todo: add default tasks for this job type. $job_created[] = $job_id; } } else { foreach (module_job::get_types() as $type_id => $type) { foreach ($job['type'] as $type_name) { if ($type_name == $type) { // we have a match in our system. create the job. $job_data = module_job::get_job(false); $job_data['type'] = $type; if (!$job_data['name']) { $job_data['name'] = $type; } $job_data['website_id'] = $website_id; $job_data['customer_id'] = $customer_id; $job_id = update_insert('job_id', false, 'job', $job_data); // todo: add default tasks for this job type. $job_created[] = $job_id; } } } } if (count($job_created) && count($job_extra)) { // save job extra data. foreach ($job_created as $job_created_id) { if ($job_created_id && count($job_extra)) { $_REQUEST['extra_job_field'] = array(); foreach ($job_extra as $key => $val) { $_REQUEST['extra_job_field'][] = array('key' => $key, 'val' => $val); } module_extra::save_extras('job', 'job_id', $job_created_id); } } } } // save files against customer $uploaded_files = array(); if (isset($_FILES['customerfiles']) && isset($_FILES['customerfiles']['tmp_name'])) { foreach ($_FILES['customerfiles']['tmp_name'] as $file_id => $tmp_file) { if (is_uploaded_file($tmp_file)) { // save to file module for this customer $file_name = basename($_FILES['customerfiles']['name'][$file_id]); if (strlen($file_name)) { $file_path = 'includes/plugin_file/upload/' . md5(time() . $file_name); if (move_uploaded_file($tmp_file, $file_path)) { // success! write to db. $file_data = array('customer_id' => $customer_id, 'job_id' => current($job_created), 'website_id' => $website_id, 'status' => module_config::c('file_default_status', 'Uploaded'), 'pointers' => false, 'description' => "Uploaded from Customer Signup form", 'file_time' => time(), 'file_name' => $file_name, 'file_path' => $file_path, 'file_url' => false); $file_id = update_insert('file_id', false, 'file', $file_data); $uploaded_files[] = $file_id; } } } } } // we create subscriptions for this customer/website (if none already exist) $subscription['subscription_name'] = array(); $subscription['subscription_invoice'] = array(); if (class_exists('module_subscription', false) && module_subscription::is_plugin_enabled() && isset($subscription['for']) && isset($subscription['subscriptions'])) { if ($subscription['for'] == 'website' && $website_id > 0) { $owner_table = 'website'; $owner_id = $website_id; } else { $owner_table = 'customer'; $owner_id = $customer_id; } $available_subscriptions = module_subscription::get_subscriptions(); $members_subscriptions = module_subscription::get_subscriptions_by($owner_table, $owner_id); foreach ($subscription['subscriptions'] as $subscription_id => $tf) { if (isset($available_subscriptions[$subscription_id])) { if (isset($members_subscriptions[$subscription_id])) { // we don't allow a member to sign up to the same subscription twice (just yet) } else { $subscription['subscription_name'][$subscription_id] = $available_subscriptions[$subscription_id]['name']; $start_date = date('Y-m-d'); $start_modifications = module_config::c('customer_signup_subscription_start', ''); if ($start_modifications == 'hidden') { $start_modifications = isset($_REQUEST['customer_signup_subscription_start']) ? $_REQUEST['customer_signup_subscription_start'] : ''; } if (!empty($start_modifications)) { $start_date = date('Y-m-d', strtotime($start_modifications)); } $sql = "INSERT INTO `" . _DB_PREFIX . "subscription_owner` SET "; $sql .= " owner_id = '" . (int) $owner_id . "'"; $sql .= ", owner_table = '" . mysql_real_escape_string($owner_table) . "'"; $sql .= ", subscription_id = '" . (int) $subscription_id . "'"; $sql .= ", start_date = '{$start_date}'"; query($sql); module_subscription::update_next_due_date($subscription_id, $owner_table, $owner_id, true); // and the same option here to send a subscription straight away upon signup if (module_config::c('subscription_send_invoice_straight_away', 0)) { global $plugins; $plugins['subscription']->run_cron(); // check if there are any invoices for this subscription $history = module_subscription::get_subscription_history($subscription_id, $owner_table, $owner_id); if (count($history) > 0) { foreach ($history as $h) { if ($h['invoice_id']) { $invoice_data = module_invoice::get_invoice($h['invoice_id']); if ($invoice_data['date_cancel'] != '0000-00-00') { continue; } $subscription['subscription_invoice'][] = '<a href="' . module_invoice::link_public($h['invoice_id']) . '">' . _l('Invoice #%s for %s', htmlspecialchars($invoice_data['name']), dollar($invoice_data['total_amount'], true, $invoice_data['currency_id'])) . '</a>'; } } } } } } } } if (!count($subscription['subscription_name'])) { $subscription['subscription_name'][] = _l('N/A'); } if (!count($subscription['subscription_invoice'])) { $subscription['subscription_invoice'][] = _l('N/A'); } $subscription['subscription_name'] = implode(', ', $subscription['subscription_name']); $subscription['subscription_invoice'] = implode(', ', $subscription['subscription_invoice']); // email the admin when a customer signs up. $values = array_merge($customer, $customer_extra, $website, $website_extra, $address, $subscription); $values['customer_name'] = $customer['customer_name']; $values['CUSTOMER_LINK'] = module_customer::link_open($customer_id); $values['CUSTOMER_NAME_LINK'] = module_customer::link_open($customer_id, true); if ($website_id) { $values['WEBSITE_LINK'] = module_website::link_open($website_id); $values['WEBSITE_NAME_LINK'] = module_website::link_open($website_id, true); } else { $values['WEBSITE_LINK'] = _l('N/A'); $values['WEBSITE_NAME_LINK'] = _l('N/A'); } $values['JOB_LINKS'] = ''; if (count($job_created)) { $values['JOB_LINKS'] .= 'The customer created ' . count($job_created) . ' jobs in the system: <br>'; foreach ($job_created as $job_created_id) { $values['JOB_LINKS'] .= module_job::link_open($job_created_id, true) . "<br>\n"; } } else { $values['JOB_LINKS'] = _l('N/A'); } if (count($uploaded_files)) { $values['uploaded_files'] = 'The customer uploaded ' . count($uploaded_files) . " files:<br>\n"; foreach ($uploaded_files as $uploaded_file) { $values['uploaded_files'] .= module_file::link_open($uploaded_file, true) . "<br>\n"; } } else { $values['uploaded_files'] = 'No files were uploaded'; } $values['WEBSITE_NAME'] = isset($website['url']) ? $website['url'] : 'N/A'; if (!$creating_new) { $values['system_note'] = "Note: this signup updated the existing customer record in the system."; } else { $values['system_note'] = "Note: this signup created a new customer record in the system."; } $customer_signup_template = module_config::c('customer_signup_email_admin_template', 'customer_signup_email_admin'); if (isset($_REQUEST['customer_signup_email_admin_template'])) { $customer_signup_template = $_REQUEST['customer_signup_email_admin_template']; } if ($customer_signup_template) { $template = module_template::get_template_by_key($customer_signup_template); if ($template->template_id) { $template->assign_values($values); $html = $template->render('html'); $email = module_email::new_email(); $email->replace_values = $values; $email->set_subject($template->description); $email->set_to_manual(module_config::c('customer_signup_admin_email', module_config::c('admin_email_address'))); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! } else { /// log err? } } } $customer_signup_template = module_config::c('customer_signup_email_welcome_template', 'customer_signup_email_welcome'); if (isset($_REQUEST['customer_signup_email_welcome_template'])) { $customer_signup_template = $_REQUEST['customer_signup_email_welcome_template']; } if ($customer_signup_template) { $template = module_template::get_template_by_key($customer_signup_template); if ($template->template_id) { $template->assign_values($values); $html = $template->render('html'); $email = module_email::new_email(); $email->customer_id = $customer_id; $email->replace_values = $values; $email->set_subject($template->description); $email->set_to('user', $customer_data['primary_user_id']); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! } else { /// log err? } } } //todo: optional redirect to url if (isset($_REQUEST['via_ajax'])) { echo json_encode(array('success' => 1, 'customer_id' => $customer_id)); exit; } if (module_config::c('customer_signup_redirect', '')) { redirect_browser(module_config::c('customer_signup_redirect', '')); } // load up the thank you template. $template = module_template::get_template_by_key('customer_signup_thank_you_page'); $template->page_title = _l("Customer Signup"); foreach ($values as $key => $val) { if (!is_array($val)) { $values[$key] = htmlspecialchars($val); } } $template->assign_values($values); echo $template->render('pretty_html'); exit; break; } }
echo module_ticket::link_open_account($ticket_account['ticket_account_id'], true); ?> </td> <td> <?php echo htmlspecialchars($ticket_account['email']); ?> </td> <td> <?php echo htmlspecialchars(isset($types[$ticket_account['default_type']]) ? $types[$ticket_account['default_type']]['name'] : $ticket_account['default_type']); ?> </td> <td> <?php echo module_customer::link_open($ticket_account['default_customer_id'], true); ?> </td> <td> <?php echo module_user::link_open($ticket_account['default_user_id'], true); ?> </td> <td> <?php echo print_date($ticket_account['last_checked']); ?> </td> </tr> <?php }
</ul> </td> <td> <?php $total_customers += count($subscription_report['customers']); echo count($subscription_report['customers']); ?> <br/> <ul> <?php foreach ($subscription_report['customers'] as $customer_id => $customer_data) { ?> <li> <?php echo module_customer::link_open($customer_id, true); ?> (<?php echo $customer_data['received_payments'] . ' = ' . dollar($customer_data['received_total']); ?> ) <?php if ($customer_data['unpaid_payments'] > 0) { ?> <strong><?php echo $customer_data['unpaid_payments']; ?> UNPAID! = <?php echo dollar($customer_data['unpaid_total']); ?>
} //todo: display a warning if the same email address is used within the same customer as a different contact //todo: display a warning if this email address is used as a main system "user" (similar to what we do in users anyway). } 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' => 'Contact 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' => 'Contact 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 ($use_master_key == 'vendor_id' && 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 Contact')), array('ignore' => !((int) $user_id > 1 && module_user::can_i('delete', 'Contacts', $contact_type)), 'type' => 'delete_button', 'name' => 'butt_del_contact', 'value' => _l('Delete')), array('type' => 'button', 'name' => 'cancel', 'value' => _l('Cancel'), 'class' => 'submit_button', 'onclick' => $use_master_key == 'customer_id' ? "window.location.href='" . module_customer::link_open($user['customer_id']) . "';" : "window.location.href='" . module_vendor::link_open($user['vendor_id']) . "';"))); echo module_form::generate_form_actions($form_actions); ?> </form>
//$data = $module->get_data_record($data['data_record_id']); $list_data_items = $module->get_data_items($data['data_record_id']); ?> <tr class="<?php echo $c++ % 2 ? "odd" : "even"; ?> "> <?php if (isset($_REQUEST['view_all'])) { ?> <td><?php foreach ($module->get_data_link_keys() as $key) { if (isset($data[$key]) && (int) $data[$key] > 0) { switch ($key) { case 'customer_id': echo module_customer::link_open($data[$key], true); break; case 'job_id': echo module_job::link_open($data[$key], true); break; case 'invoice_id': echo module_invoice::link_open($data[$key], true); break; case 'quote_id': echo module_quote::link_open($data[$key], true); break; case 'file_id': echo module_file::link_open($data[$key], true); break; } }
} if (isset($finance['finance_record']['linked_invoice_payments'])) { foreach ($finance['finance_record']['linked_invoice_payments'] as $f) { if (strlen($f['description'])) { $descriptions[preg_replace('#\\s+#', '', strip_tags($f['description']))] = $f['description']; } } } } echo implode('<br>', $descriptions); }); $columns['finance_customer'] = array('title' => 'Customer', 'callback' => function ($finance) { if (!isset($finance['transaction_date'])) { return false; } echo isset($finance['customer_id']) && $finance['customer_id'] ? module_customer::link_open($finance['customer_id'], true) : ''; }); $columns['sort_credit'] = array('title' => 'Credit', 'callback' => function ($finance) { $info = ''; if ($finance['credit'] > 0 && isset($finance['payment_type'])) { if ($finance['payment_type'] == _INVOICE_PAYMENT_TYPE_OVERPAYMENT_CREDIT || $finance['payment_type'] == _INVOICE_PAYMENT_TYPE_CREDIT) { // dont add these ones to the totals at thebottom, mark then with asterix so people know. $info = ' *'; } } if (!isset($finance['transaction_date'])) { return false; } ?> <span class="success_text"><?php echo $finance['credit'] > 0 ? '+' . dollar($finance['credit'], true, $finance['currency_id']) : '';
<?php echo mysql_num_rows($customers); ?> </h3> <p> <?php _e('Current %s', htmlspecialchars($customer_type['type_name_plural'])); ?> </p> </div> <div class="icon"><i class="fa fa-<?php echo htmlspecialchars($customer_type['menu_icon'] ? $customer_type['menu_icon'] : 'users'); ?> "></i></div> <a href="<?php $link = module_customer::link_open(false); echo $link . (strpos($link, '?') ? '&' : '?') . 'customer_type_id=' . $customer_type['customer_type_id']; ?> " class="small-box-footer"> <?php _e('View %s', htmlspecialchars($customer_type['type_name_plural'])); ?> <i class="fa fa-arrow-circle-right"></i> </a> </div> <?php $widgets[] = array('id' => 'open_customers_' . $customer_type['customer_type_id'], 'columns' => 4, 'raw' => true, 'content' => ob_get_clean()); } } }
public static function handle_import_row($row, $debug, $add_to_group, $extra_options) { $debug_string = ''; if (isset($row['job_id']) && (int) $row['job_id'] > 0) { // check if this ID exists. $job = self::get_job($row['job_id']); if (!$job || $job['job_id'] != $row['job_id']) { $row['job_id'] = 0; } } if (!isset($row['job_id']) || !$row['job_id']) { $row['job_id'] = 0; } if (!isset($row['name']) || !strlen($row['name'])) { $debug_string .= _l('No job data to import'); if ($debug) { echo $debug_string; } return false; } // duplicates. //print_r($extra_options);exit; if (isset($extra_options['duplicates']) && $extra_options['duplicates'] == 'ignore' && (int) $row['job_id'] > 0) { if ($debug) { $debug_string .= _l('Skipping import, duplicate of job %s', self::link_open($row['job_id'], true)); echo $debug_string; } // don't import duplicates return false; } $row['customer_id'] = 0; // todo - support importing of this id? nah if (isset($row['customer_name']) && strlen(trim($row['customer_name'])) > 0) { // check if this customer exists. $customer = get_single('customer', 'customer_name', $row['customer_name']); if ($customer && $customer['customer_id'] > 0) { $row['customer_id'] = $customer['customer_id']; $debug_string .= _l('Linked to customer %s', module_customer::link_open($row['customer_id'], true)) . ' '; } else { $debug_string .= _l('Create new customer: %s', htmlspecialchars($row['customer_name'])) . ' '; } } else { $debug_string .= _l('No customer') . ' '; } if ($row['job_id']) { $debug_string .= _l('Replace existing job: %s', self::link_open($row['job_id'], true)) . ' '; } else { $debug_string .= _l('Insert new job: %s', htmlspecialchars($row['name'])) . ' '; } if ($debug) { echo $debug_string; return true; } if (isset($extra_options['duplicates']) && $extra_options['duplicates'] == 'ignore' && $row['customer_id'] > 0) { // don't update customer record with new one. } else { if (isset($row['customer_name']) && strlen(trim($row['customer_name'])) > 0 || $row['customer_id'] > 0) { // update customer record with new one. $row['customer_id'] = update_insert('customer_id', $row['customer_id'], 'customer', $row); } } $job_id = (int) $row['job_id']; // check if this ID exists. $job = self::get_job($job_id); if (!$job || $job['job_id'] != $job_id) { $job_id = 0; } $job_id = update_insert("job_id", $job_id, "job", $row); // handle any extra fields. $extra = array(); foreach ($row as $key => $val) { if (!strlen(trim($val))) { continue; } if (strpos($key, 'extra:') !== false) { $extra_key = str_replace('extra:', '', $key); if (strlen($extra_key)) { $extra[$extra_key] = $val; } } } if ($extra) { foreach ($extra as $extra_key => $extra_val) { // does this one exist? $existing_extra = module_extra::get_extras(array('owner_table' => 'job', 'owner_id' => $job_id, 'extra_key' => $extra_key)); $extra_id = false; foreach ($existing_extra as $key => $val) { if ($val['extra_key'] == $extra_key) { $extra_id = $val['extra_id']; } } $extra_db = array('extra_key' => $extra_key, 'extra' => $extra_val, 'owner_table' => 'job', 'owner_id' => $job_id); $extra_id = (int) $extra_id; update_insert('extra_id', $extra_id, 'extra', $extra_db); } } foreach ($add_to_group as $group_id => $tf) { module_group::add_to_group($group_id, $job_id, 'job'); } return $job_id; }
function customer_admin_email_generate_invoice_list($invoices, $customer_id) { ob_start(); $colspan = 9; $colspan2 = 0; $invoice_total = array(); $invoice_total_due = array(); foreach ($invoices as $invoice) { if (!isset($invoice_total[$invoice['currency_id']])) { $invoice_total[$invoice['currency_id']] = 0; } if ($invoice['c_total_amount'] == 0) { $invoice = module_invoice::get_invoice($invoice['invoice_id']); } $invoice_total[$invoice['currency_id']] += $invoice['c_total_amount']; if (!isset($invoice_total_due[$invoice['currency_id']])) { $invoice_total_due[$invoice['currency_id']] = 0; } $invoice_total_due[$invoice['currency_id']] += $invoice['c_total_amount_due']; } $table_manager = module_theme::new_table_manager(); $columns = array(); $columns['invoice_number'] = array('title' => 'Invoice Number', 'callback' => function ($invoice) { //echo module_invoice::link_open($invoice['invoice_id'],true,$invoice); echo '<a href="' . module_invoice::link_public($invoice['invoice_id']) . '">' . htmlspecialchars($invoice['name']) . '</a>'; }, 'cell_class' => 'row_action'); $columns['invoice_status'] = array('title' => 'Status', 'callback' => function ($invoice) { echo htmlspecialchars($invoice['status']); }); $columns['invoice_create_date'] = array('title' => 'Create Date', 'callback' => function ($invoice) { if (!$invoice['date_create'] || $invoice['date_create'] == '0000-00-00') { //echo print_date($invoice['date_created']); } else { echo print_date($invoice['date_create']); } }); $columns['invoice_due_date'] = array('title' => 'Due Date', 'callback' => function ($invoice) { if ((!$invoice['date_paid'] || $invoice['date_paid'] == '0000-00-00') && strtotime($invoice['date_due']) < time()) { echo '<span class="error_text">'; echo print_date($invoice['date_due']); echo '</span>'; } else { echo print_date($invoice['date_due']); } }); $columns['invoice_sent_date'] = array('title' => 'Sent Date', 'callback' => function ($invoice) { if ($invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') { ?> <?php echo print_date($invoice['date_sent']); ?> <?php } else { ?> <span class="error_text"><?php _e('Not sent'); ?> </span> <?php } }); $columns['invoice_paid_date'] = array('title' => 'Paid Date', 'callback' => function ($invoice) { if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') { ?> <?php echo print_date($invoice['date_paid']); ?> <?php } else { if ($invoice['date_cancel'] && $invoice['date_cancel'] != '0000-00-00') { ?> <span class="error_text"><?php _e('Cancelled'); ?> </span> <?php } else { if ($invoice['overdue']) { ?> <span class="error_text" style="font-weight: bold; text-decoration: underline;"><?php _e('Overdue'); ?> </span> <?php } else { ?> <span class="error_text"><?php _e('Not paid'); ?> </span> <?php } } } }); if (class_exists('module_website', false) && module_website::is_plugin_enabled() && module_website::can_i('view', module_config::c('project_name_plural', 'Websites'))) { $colspan++; $columns['invoice_website'] = array('title' => module_config::c('project_name_single', 'Website'), 'callback' => function ($invoice) { if (isset($invoice['website_ids'])) { foreach ($invoice['website_ids'] as $website_id) { if ((int) $website_id > 0) { echo module_website::link_open($website_id, true); echo '<br/>'; } } } }); } $columns['invoice_job'] = array('title' => 'Job', 'callback' => function ($invoice) { foreach ($invoice['job_ids'] as $job_id) { if ((int) $job_id > 0) { //echo module_job::link_open($job_id,true); $job_data = module_job::get_job($job_id); echo '<a href="' . module_job::link_public($job_id) . '">' . htmlspecialchars($job_data['name']) . '</a>'; if ($job_data['date_start'] && $job_data['date_start'] != '0000-00-00' && $job_data['date_renew'] && $job_data['date_renew'] != '0000-00-00') { _e(' (%s to %s)', print_date($job_data['date_start']), print_date(strtotime("-1 day", strtotime($job_data['date_renew'])))); } echo "<br/>\n"; } } hook_handle_callback('invoice_admin_list_job', $invoice['invoice_id']); }); if (!isset($_REQUEST['customer_id']) && module_customer::can_i('view', 'Customers')) { $colspan++; $columns['invoice_customer'] = array('title' => 'Customer', 'callback' => function ($invoice) { echo module_customer::link_open($invoice['customer_id'], true); }); } $columns['c_invoice_total'] = array('title' => 'Invoice Total', 'callback' => function ($invoice) { echo dollar($invoice['total_amount'], true, $invoice['currency_id']); }); $columns['c_invoice_total_due'] = array('title' => 'Amount Due', 'callback' => function ($invoice) { echo dollar($invoice['total_amount_due'], true, $invoice['currency_id']); ?> <?php if ($invoice['total_amount_credit'] > 0) { ?> <span class="success_text"><?php echo _l('Credit: %s', dollar($invoice['total_amount_credit'], true, $invoice['currency_id'])); ?> </span> <?php } }); if (class_exists('module_extra', false)) { ob_start(); $colspan2 += module_extra::print_table_header('invoice'); // used in the footer calc. ob_end_clean(); $table_manager->display_extra('invoice', function ($invoice) { module_extra::print_table_data('invoice', $invoice['invoice_id']); }); } $table_manager->set_columns($columns); $table_manager->row_callback = function ($row_data) { // load the full vendor data before displaying each row so we have access to more details if (isset($row_data['invoice_id']) && (int) $row_data['invoice_id'] > 0) { return module_invoice::get_invoice($row_data['invoice_id']); } return array(); }; $table_manager->set_rows($invoices); if (module_config::c('invoice_list_show_totals', 1)) { $footer_rows = array(); foreach ($invoice_total + $invoice_total_due as $currency_id => $foo) { $currency = get_single('currency', 'currency_id', $currency_id); $footer_rows[] = array('invoice_number' => array('data' => '<strong>' . _l('%s Totals:', $currency && isset($currency['code']) ? $currency['code'] : '') . '</strong>', 'cell_colspan' => $colspan - 2, 'cell_class' => 'text-right'), 'c_invoice_total' => array('data' => '<strong>' . dollar(isset($invoice_total[$currency_id]) ? $invoice_total[$currency_id] : 0, true, $currency_id) . '</strong>'), 'c_invoice_total_due' => array('data' => '<strong>' . dollar(isset($invoice_total_due[$currency_id]) ? $invoice_total_due[$currency_id] : 0, true, $currency_id) . '</strong>'), 'row_bulk_action' => array('data' => ' ', 'cell_colspan' => $colspan2)); } $table_manager->set_footer_rows($footer_rows); } $table_manager->pagination = false; $table_manager->print_table(); return ob_get_clean(); }
<?php } ?> </td> <?php } ?> <?php if (!isset($_REQUEST['customer_id'])) { ?> <td> <?php echo module_customer::link_open($website['customer_id'], true); ?> </td> <?php } ?> </tr> <?php } ?> </tbody> </table> <?php
} echo print_select_box($c, 'customer_id', $invoice['customer_id']); if ($invoice['customer_id'] && module_customer::can_i('view', 'Customers')) { ?> <a href="<?php echo module_customer::link_open($invoice['customer_id'], false); ?> "><?php _e('Open'); ?> </a> <?php } } else { echo module_customer::link_open($invoice['customer_id'], true); } ?> </td> </tr> <?php if ($invoice['customer_id']) { ?> <tr> <th> <?php echo _l('Contact'); ?>
public static function get_finance_recurring_items($hook, $search) { /** * next_due_date * url * type (i or e) * amount * currency_id * days * months * years * last_transaction_finance_id * account_name * categories * finance_recurring_id */ // find any unpaid invoices. $invoices = self::get_invoices(array('date_paid' => '0000-00-00')); $return = array(); foreach ($invoices as $invoice) { // filter out invoices that haven't been sent yet? probably should... //$invoice = self::get_invoice($invoice['invoice_id']); if (isset($invoice['date_cancel']) && $invoice['date_cancel'] != '0000-00-00') { continue; } // check if this invoice is part of a subscription, put in some additional info for this subscriptions // 'recurring_text' if ($invoice['member_id']) { $member_name = module_member::link_open($invoice['member_id'], true); } else { if ($invoice['customer_id']) { $member_name = module_customer::link_open($invoice['customer_id'], true); } else { $member_name = _l('N/A'); } } $recurring_text = _l('Payment from %s', $member_name); if (class_exists('module_subscription', false) && isset($invoice['invoice_subscription_ids'])) { $sql = "SELECT sh.*, s.name FROM `" . _DB_PREFIX . "subscription_history` sh LEFT JOIN `" . _DB_PREFIX . "subscription` s USING (subscription_id) WHERE sh.invoice_id = " . (int) $invoice['invoice_id'] . ""; $res = qa1($sql); if ($res) { $subscription_name = module_subscription::link_open($res['subscription_id'], true, $res); $recurring_text = _l('Payment from %s on subscription %s', $member_name, $subscription_name); } } if (!isset($invoice['c_total_amount_due'])) { $invoice = module_invoice::get_invoice($invoice['invoice_id']); $invoice['c_total_amount_due'] = $invoice['total_amount_due']; } $return[$invoice['invoice_id']] = array('next_due_date' => $invoice['date_due'] && $invoice['date_due'] != '0000-00-00' ? $invoice['date_due'] : $invoice['date_created'], 'url' => module_invoice::link_open($invoice['invoice_id'], true, $invoice), 'type' => 'i', 'amount' => $invoice['c_total_amount_due'], 'currency_id' => $invoice['currency_id'], 'days' => 0, 'months' => 0, 'years' => 0, 'last_transaction_finance_id' => 0, 'account_name' => '', 'categories' => '', 'finance_recurring_id' => 0, 'recurring_text' => $recurring_text); } // find any automatically renewing invoices. $invoices = self::get_invoices(array('renewing' => 1)); foreach ($invoices as $invoice) { // filter out invoices that haven't been sent yet? probably should... //$invoice = self::get_invoice($invoice['invoice_id']); if (isset($invoice['date_cancel']) && $invoice['date_cancel'] != '0000-00-00') { continue; } // check if this invoice is part of a subscription, put in some additional info for this subscriptions // 'recurring_text' if ($invoice['member_id']) { $member_name = module_member::link_open($invoice['member_id'], true); } else { if ($invoice['customer_id']) { $member_name = module_customer::link_open($invoice['customer_id'], true); } else { $member_name = _l('N/A'); } } if ($invoice['renew_auto']) { $recurring_text = _l('Automatically Renewing invoice for %s', $member_name); } else { $recurring_text = _l('Manually Renewing invoice for %s', $member_name); } if (!isset($invoice['c_total_amount'])) { $invoice = module_invoice::get_invoice($invoice['invoice_id']); $invoice['c_total_amount'] = $invoice['total_amount']; } $return[] = array('next_due_date' => date('Y-m-d', strtotime('+' . module_config::c('invoice_due_days', 30) . ' days', strtotime($invoice['date_renew']))), 'url' => module_invoice::link_open($invoice['invoice_id'], true, $invoice), 'type' => 'i', 'amount' => $invoice['c_total_amount'], 'currency_id' => $invoice['currency_id'], 'days' => 0, 'months' => 0, 'years' => 0, 'last_transaction_finance_id' => 0, 'account_name' => '', 'categories' => '', 'finance_recurring_id' => 0, 'recurring_text' => $recurring_text); } return $return; }
echo print_date($email['sent_time']); }); $columns['email_to'] = array('title' => 'Sent To', 'callback' => function ($email) { $headers = unserialize($email['headers']); if (isset($headers['to']) && is_array($headers['to'])) { foreach ($headers['to'] as $to) { echo $to['email'] . ' '; } } }); $columns['email_from'] = array('title' => 'Sent By', 'callback' => function ($email) { echo module_user::link_open($email['create_user_id'], true); }); if (!isset($_REQUEST['customer_id'])) { $columns['email_customer'] = array('title' => 'Customer', 'callback' => function ($email) { echo module_customer::link_open($email['customer_id'], true); }); } $table_manager->set_columns($columns); $table_manager->row_callback = function ($row_data) { // load the full email data before displaying each row so we have access to more details if (isset($row_data['email_id']) && (int) $row_data['email_id'] > 0) { // not needed in this case //return module_email::get_email($row_data['email_id']); } return array(); }; $table_manager->set_rows($emails); $table_manager->pagination = true; $table_manager->print_table(); ?>
if (isset($user['customer_id']) && $user['customer_id'] || isset($user['vendor_id']) && $user['vendor_id']) { // we have a contact! die('Wrong file'); } else { $use_master_key = false; // we have a normal site user.. } // find a contact with matching email address. if (isset($user['email']) && strlen($user['email']) > 3) { $contacts = module_user::get_contacts(array('email' => $user['email'])); if (count($contacts) > 0) { foreach ($contacts as $c) { ?> <div class="warning"><?php _e('Warning: a contact from the Customer %s exists with this same email address: %s <br/>This may create problems when trying to login. <br/>We suggest you remove/change THIS user account and use the existing CONTACT account instead.', module_customer::link_open($c['customer_id'], true), module_user::link_open_contact($c['user_id'], true)); ?> </div> <?php } } } ?> <form action="" method="post" autocomplete="off"> <input type="hidden" name="_process" value="save_user" /> <!-- <input type="hidden" name="_redirect" value="<?php echo $module->link("", array("saved" => true, "user_id" => (int) $user_id ? $user_id : ''));
/** * @static * @param $args * @return array * * The newsletter system requests updated customer / user data from this group plugin. * It does this when building the member list, and also */ public static function newsletter_callback($args) { if (!isset($args['owner_table']) || !$args['owner_table']) { return array(); } switch ($args['owner_table']) { case 'user': if ((int) $args['owner_id'] > 0) { $sql = "SELECT c.customer_name AS company_name, c.customer_name AS customer_name"; $sql .= " , pu.user_id "; $sql .= " , c.customer_id "; $sql .= " ,c.credit "; $sql .= " , pu.name AS user_name, pu.name AS first_name, pu.last_name AS last_name, pu.phone AS phone, pu.`email` AS `email`, pu.`mobile` AS `mobile`"; $sql .= " , a.line_1, a.line_2, a.suburb, a.state, a.region, a.country, a.post_code "; $sql .= ' FROM `' . _DB_PREFIX . "user` pu"; $sql .= " LEFT JOIN `" . _DB_PREFIX . "customer` c ON pu.customer_id = c.customer_id"; $sql .= ' LEFT JOIN `' . _DB_PREFIX . "address` a ON c.customer_id = a.owner_id AND a.owner_table = 'customer' AND a.address_type = 'physical'"; $sql .= " WHERE pu.user_id = " . (int) $args['owner_id']; $user = qa1($sql); if (!is_array($user) || !isset($user['user_id']) || !$user['user_id']) { return false; } if (isset($args['basic']) && $args['basic']) { return $user; } // $name_parts = explode(" ",preg_replace('/\s+/',' ',$user['user_name'])); // $user['first_name'] = array_shift($name_parts); // $user['last_name'] = implode(' ',$name_parts); // get extras for the user. $extras = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $user['user_id'])); foreach ($extras as $extra) { if (!strlen(trim($extra['extra']))) { continue; } $key = $extra['extra_key']; $x = 1; while (isset($user[$key])) { $key = $extra['extra_key'] . $x; $x++; } $user[$key] = trim($extra['extra']); } // get extras for the customer. if (isset($user['customer_id']) && $user['customer_id'] > 0) { $extras = module_extra::get_extras(array('owner_table' => 'customer', 'owner_id' => $user['customer_id'])); foreach ($extras as $extra) { if (!strlen(trim($extra['extra']))) { continue; } $key = $extra['extra_key']; $x = 1; while (isset($user[$key])) { $key = $extra['extra_key'] . $x; $x++; } $user[$key] = trim($extra['extra']); } } if ($user['customer_id']) { $user['_edit_link'] = module_user::link_open_contact($user['user_id'], false, $user); } else { $user['_edit_link'] = module_user::link_open($user['user_id'], false, $user); } return $user; } break; case 'customer': if (module_config::c('newsletter_send_all_customer_contacts', 1)) { // update - we use the above 'user' callback and return a listing for each contact in the array. // using the special _multi flag hack to tell our newsletter plugin that this result contains multiple entries. $users = array('_multi' => true); $sql = "SELECT u.user_id FROM `" . _DB_PREFIX . "user` u WHERE u.customer_id = " . (int) $args['owner_id']; $contacts = qa($sql); foreach ($contacts as $contact) { $data_args = array('owner_id' => $contact['user_id'], 'owner_table' => 'user'); $users[$contact['user_id']] = self::newsletter_callback($data_args); if ($users[$contact['user_id']]) { $users[$contact['user_id']]['data_args'] = json_encode($data_args); } } return $users; } else { $sql = "SELECT c.customer_name AS company_name, c.customer_name AS customer_name"; $sql .= " ,c.credit "; $sql .= " , pu.user_id "; $sql .= " , c.customer_id "; $sql .= " , pu.name AS user_name, pu.name AS first_name, pu.last_name AS last_name, pu.phone AS phone, pu.`email` AS `email`, pu.`mobile` AS `mobile`"; $sql .= " , a.line_1, a.line_2, a.suburb, a.state, a.region, a.country, a.post_code "; $sql .= " FROM `" . _DB_PREFIX . "customer` c "; $sql .= ' LEFT JOIN `' . _DB_PREFIX . "address` a ON c.customer_id = a.owner_id AND a.owner_table = 'customer' AND a.address_type = 'physical'"; $sql .= ' LEFT JOIN `' . _DB_PREFIX . "user` pu ON c.primary_user_id = pu.user_id"; $sql .= " WHERE c.customer_id = " . (int) $args['owner_id']; $user = qa1($sql); if (!$user || !isset($user['customer_id'])) { return array(); } //$name_parts = explode(" ",preg_replace('/\s+/',' ',$user['user_name'])); //$user['first_name'] = array_shift($name_parts); //$user['last_name'] = implode(' ',$name_parts); if (isset($args['basic']) && $args['basic']) { return $user; } // get extras for the customer. $extras = module_extra::get_extras(array('owner_table' => 'customer', 'owner_id' => $user['customer_id'])); foreach ($extras as $extra) { if (!strlen(trim($extra['extra']))) { continue; } $key = $extra['extra_key']; $x = 1; while (isset($user[$key])) { $key = $extra['extra_key'] . $x; $x++; } $user[$key] = trim($extra['extra']); } if (isset($user['user_id']) && $user['user_id'] > 0) { // get extras for the user. $extras = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $user['user_id'])); foreach ($extras as $extra) { if (!strlen(trim($extra['extra']))) { continue; } $key = $extra['extra_key']; $x = 1; while (isset($user[$key])) { $key = $extra['extra_key'] . $x; $x++; } $user[$key] = trim($extra['extra']); } } $user['_edit_link'] = module_customer::link_open($user['customer_id'], false, $user); return $user; } case 'website': $sql = "SELECT c.customer_name AS company_name"; $sql .= " ,c.credit "; $sql .= " ,w.name AS website_name"; $sql .= " ,w.url AS website_url"; $sql .= " , pu.user_id "; $sql .= " , c.customer_id "; $sql .= " , pu.name AS user_name, pu.phone AS phone, pu.`email` AS `email`, pu.`mobile` AS `mobile`"; $sql .= " , a.line_1, a.line_2, a.suburb, a.state, a.region, a.country, a.post_code "; $sql .= " FROM `" . _DB_PREFIX . "website` w "; $sql .= ' LEFT JOIN `' . _DB_PREFIX . "customer` c ON w.customer_id = c.customer_id"; $sql .= ' LEFT JOIN `' . _DB_PREFIX . "address` a ON c.customer_id = a.owner_id AND a.owner_table = 'customer' AND a.address_type = 'physical'"; $sql .= ' LEFT JOIN `' . _DB_PREFIX . "user` pu ON c.primary_user_id = pu.user_id"; $sql .= " WHERE w.website_id = " . (int) $args['owner_id']; $user = qa1($sql); $name_parts = explode(" ", preg_replace('/\\s+/', ' ', $user['user_name'])); $user['first_name'] = array_shift($name_parts); $user['last_name'] = implode(' ', $name_parts); if (isset($args['basic']) && $args['basic']) { return $user; } // get extras for the website. $extras = module_extra::get_extras(array('owner_table' => 'website', 'owner_id' => $args['owner_id'])); foreach ($extras as $extra) { if (!strlen(trim($extra['extra']))) { continue; } $key = $extra['extra_key']; $x = 1; while (isset($user[$key])) { $key = $extra['extra_key'] . $x; $x++; } $user[$key] = trim($extra['extra']); } // then get extras for the company $extras = module_extra::get_extras(array('owner_table' => 'customer', 'owner_id' => $user['customer_id'])); foreach ($extras as $extra) { if (!strlen(trim($extra['extra']))) { continue; } $key = $extra['extra_key']; $x = 1; while (isset($user[$key])) { $key = $extra['extra_key'] . $x; $x++; } $user[$key] = trim($extra['extra']); } if (isset($user['user_id']) && $user['user_id'] > 0) { // get extras for the user. $extras = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $user['user_id'])); foreach ($extras as $extra) { if (!strlen(trim($extra['extra']))) { continue; } $key = $extra['extra_key']; $x = 1; while (isset($user[$key])) { $key = $extra['extra_key'] . $x; $x++; } $user[$key] = trim($extra['extra']); } } $user['_edit_link'] = module_customer::link_open($user['customer_id'], false, $user); return $user; case 'ticket': //echo 'Getting ticket for '.$args['owner_id'] . ' and basic is '.var_export($args['basic'],true);exit; return module_ticket::get_newsletter_recipient($args['owner_id'], isset($args['basic']) && $args['basic']); case 'member': return module_member::get_newsletter_recipient($args['owner_id'], isset($args['basic']) && $args['basic']); case 'newsletter_subscription': return module_member::get_newsletter_recipient($args['owner_id'], isset($args['basic']) && $args['basic']); } return array(); }
if(currentuser_key){ $('#change_user_id').append($("<option></option>") .attr("value", currentuser_key).text(currentuser_val)); $('#change_user_id').val(currentuser_key); } }, fail: function(){ alert('Changing customer failed, please refresh and try again.'); } }); }); }); </script> --> <?php } else { echo module_customer::link_open($ticket['customer_id'], true); } /*$c = array(); $res = module_customer::get_customers(); while($row = array_shift($res)){ $c[$row['customer_id']] = $row['customer_name']; } if(false && module_ticket::can_i('edit','Related to','Tickets')){ echo print_select_box($c,'customer_id',$ticket['customer_id']); }else if($ticket['customer_id']){ echo isset($c[$ticket['customer_id']]) ? $c[$ticket['customer_id']] : 'N/A'; }*/ })); if ($ticket['customer_id'] && $ticket_id > 0) { $fieldset_data['elements'][] = array('title' => _l('Contact'), 'fields' => array(function () use($ticket_id, $ticket) { if (module_ticket::can_edit_tickets() && isset($_REQUEST['show_change_contact'])) {
<?php if (isset($original_job_data['renew_from_job_id'])) { _e('(will renew on %s)', print_date($original_job_data['date_start'])); } ?> </td> <td> <?php echo module_website::link_open($original_job_data['website_id'], true); ?> </td> <td> <?php echo module_customer::link_open($job_data['customer_id'], true); ?> </td> <td> <?php echo htmlspecialchars($original_job_data['type']); ?> </td> <td> <?php echo print_date($original_job_data['date_start']); //is there a renewal date? if (isset($original_job_data['date_renew']) && $original_job_data['date_renew'] && $original_job_data['date_renew'] != '0000-00-00') { _e(' to %s', print_date(strtotime("-1 day", strtotime($original_job_data['date_renew']))));
data: { address_id: cust.address_id, address_hash: cust.address_hash, lat: results[0].geometry.location.lat(), lng: results[0].geometry.location.lng() }, dataType: "json", success: function(d){ } }); customer_address[index].marker = new google.maps.Marker({ map: map, position: results[0].geometry.location }); createInfoWindow(customer_address[index].marker,'Customer: <a href="<?php $link = module_customer::link_open(1); echo $link; echo strpos($link, '?') ? '&' : '?'; ?> customer_id='+ cust.customer_id + '">' + cust.customer_name + '</a><br/>' + address); bounds.extend(results[0].geometry.location); <?php if (empty($search['location'])) { ?> map.fitBounds(bounds); <?php } ?> } else { console.log('Address ' + address + ' not found: ' + status); }
} echo implode(', ', array_keys($dates)); ?> </td> <td> <a href="<?php echo $finance['url']; ?> "><?php echo !trim($finance['name']) ? 'N/A' : htmlspecialchars($finance['name']); ?> </a> </td> <td><?php echo $finance['customer_id'] ? module_customer::link_open($finance['customer_id'], true) : _l('N/A'); ?> </td> <td><?php if ($finance['invoice_id']) { $invoice_data = module_invoice::get_invoice($finance['invoice_id']); echo module_invoice::link_open($finance['invoice_id'], true, $invoice_data); } else { _e('N/A'); } ?> </td> <td><?php if (isset($finance['job_id']) && $finance['job_id']) { echo module_job::link_open($finance['job_id'], true); } else {
function handle_hook($hook, $calling_module = false, $owner_table = false, $key_name = false, $key_value = false, $rel_data = false) { switch ($hook) { case "home_alerts": $alerts = array(); if (module_config::c('allow_note_reminders', 1)) { // find any jobs that are past the due date and dont have a finished date. $key = _l('Note Reminder'); if (class_exists('module_dashboard', false)) { module_dashboard::register_group($key, array('columns' => array('name' => _l('Reminder'), 'type' => _l('Type'), 'full_link' => _l('Link'), 'date' => _l('Date'), 'days' => _l('Date')))); } $sql = "SELECT * FROM `" . _DB_PREFIX . "note` n "; $sql .= " WHERE n.`reminder` = 1 AND n.note_time < " . (int) strtotime('+' . module_config::c('alert_days_in_future', 5) . ' days') . ""; $sql .= " AND ( n.`user_id` = 0 OR n.`user_id` = " . module_security::get_loggedin_id() . ")"; $sql .= " ORDER BY n.note_time ASC"; $tasks = qa($sql); foreach ($tasks as $task) { $alert_res = process_alert(date('Y-m-d', $task['note_time']), $key); if ($alert_res) { $alert_res['link'] = $task['rel_data']; // fix for linking when changing folder. $alert_res['type'] = _l(ucwords($task['owner_table'])); switch ($task['owner_table']) { case 'user': $user = module_user::get_user($task['owner_id']); if ($user['customer_id'] || $user['vendor_id']) { $alert_res['link'] = module_user::link_open_contact($task['owner_id'], false, $user); $alert_res['full_link'] = module_user::link_open_contact($task['owner_id'], true, $user); $alert_res['type'] = _l('Contact'); } else { $alert_res['link'] = module_user::link_open($task['owner_id'], false, $user); $alert_res['full_link'] = module_user::link_open($task['owner_id'], true, $user); } break; case 'invoice': $invoice_data = module_invoice::get_invoice($task['owner_id'], true); if (!$invoice_data || !isset($invoice_data['invoice_id']) || $invoice_data['invoice_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_invoice::link_open($task['owner_id'], false, $invoice_data); $alert_res['full_link'] = module_invoice::link_open($task['owner_id'], true, $invoice_data); break; case 'quote': $quote_data = module_quote::get_quote($task['owner_id'], true); if (!$quote_data || !isset($quote_data['quote_id']) || $quote_data['quote_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_quote::link_open($task['owner_id'], false, $quote_data); $alert_res['full_link'] = module_quote::link_open($task['owner_id'], true, $quote_data); break; case 'website': $website_data = module_website::get_website($task['owner_id']); if (!$website_data || !isset($website_data['website_id']) || $website_data['website_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_website::link_open($task['owner_id'], false); $alert_res['full_link'] = module_website::link_open($task['owner_id'], true); break; case 'customer': $customer_data = module_customer::get_customer($task['owner_id']); if (!$customer_data || !isset($customer_data['customer_id']) || $customer_data['customer_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_customer::link_open($task['owner_id'], false, $customer_data); $alert_res['full_link'] = module_customer::link_open($task['owner_id'], true, $customer_data); break; case 'vendor': $vendor_data = module_vendor::get_vendor($task['owner_id']); if (!$vendor_data || !isset($vendor_data['vendor_id']) || $vendor_data['vendor_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_vendor::link_open($task['owner_id'], false, $vendor_data); $alert_res['full_link'] = module_vendor::link_open($task['owner_id'], true, $vendor_data); break; case 'job': $job_data = module_job::get_job($task['owner_id']); if (!$job_data || !isset($job_data['job_id']) || $job_data['job_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_job::link_open($task['owner_id'], false, $job_data); $alert_res['full_link'] = module_job::link_open($task['owner_id'], true, $job_data); break; // todo - add others. } $alert_res['name'] = $task['note']; $alert_res['date'] = print_date($alert_res['date']); $alert_res['time'] = $task['note_time']; $alerts[] = $alert_res; } } } return $alerts; break; /*case "note_list": if($owner_id && $owner_id != 'new'){ $note_items = $this->get_notes(array("owner_table"=>$owner_table,"owner_id"=>$owner_id)); foreach($note_items as &$note_item){ // do it in loop here because of $this issues in static method below. // instead of include file below. $note_item['html'] = $this->print_note($note_item['note_id']); } include("pages/note_list.php"); }else{ echo 'Please save first before creating notes.'; } break;*/ /*case "note_list": if($owner_id && $owner_id != 'new'){ $note_items = $this->get_notes(array("owner_table"=>$owner_table,"owner_id"=>$owner_id)); foreach($note_items as &$note_item){ // do it in loop here because of $this issues in static method below. // instead of include file below. $note_item['html'] = $this->print_note($note_item['note_id']); } include("pages/note_list.php"); }else{ echo 'Please save first before creating notes.'; } break;*/ case "note_delete": // find the key we are saving this address against. $owner_id = (int) $key_value; if (!$owner_id || $owner_id == 'new') { // find one in the post data. if (isset($_REQUEST[$key_name])) { $owner_id = $_REQUEST[$key_name]; } } $note_hash = md5($owner_id . '|' . $owner_table); // just for posting unique arrays. if ($owner_table && $owner_id) { $this->note_delete($owner_table, $owner_id); } break; } }
public function process() { if (_DEMO_MODE && isset($_REQUEST['user_id']) && (int) $_REQUEST['user_id'] > 0 && (int) $_REQUEST['user_id'] <= 4) { set_error('Sorry no changes to demo users. Please create a new user.'); redirect_browser($this->link_open($_REQUEST['user_id'])); } $errors = array(); if (isset($_REQUEST['butt_del_contact']) && $_REQUEST['butt_del_contact'] && $_REQUEST['user_id'] && $_REQUEST['user_id'] != 1 && self::can_i('delete', 'Contacts', 'Customer')) { $data = self::get_user($_REQUEST['user_id']); if (module_form::confirm_delete('user_id', "Really delete contact: " . $data['name'], self::link_open_contact($_REQUEST['user_id']))) { $this->delete_user($_REQUEST['user_id']); set_message("Contact deleted successfully"); redirect_browser(module_customer::link_open($data['customer_id'])); } } else { if (isset($_REQUEST['butt_del']) && $_REQUEST['butt_del'] && $_REQUEST['user_id'] && self::can_i('delete', 'Users', 'Config')) { $data = self::get_user($_REQUEST['user_id']); if (module_form::confirm_delete('user_id', "Really delete user: "******"User deleted successfully"); redirect_browser(self::link_open(false)); } } else { if ("save_user" == $_REQUEST['_process']) { $user_id = (int) $_REQUEST['user_id']; if ($user_id == 1 && module_security::get_loggedin_id() != 1) { set_error('Sorry, only the Administrator can access this page.'); redirect_browser(_UCM_HOST . _BASE_HREF); } // check create permissions. $use_master_key = $this->get_contact_master_key(); // are we creating or editing a user? if (!$user_id) { $method = 'create'; } else { $method = 'edit'; $existing_user = module_user::get_user($user_id, true, false); if (!$existing_user || $existing_user['user_id'] != $user_id) { $user_id = false; $method = 'create'; } } if (isset($_POST[$use_master_key]) && $_POST[$use_master_key]) { if (!module_user::can_i($method, 'Contacts', 'Customer')) { set_error('No permissions to ' . $method . ' contacts'); redirect_browser(module_customer::link_open($_POST['customer_id'])); } } else { if (!module_user::can_i($method, 'Users', 'Config')) { set_error('No permissions to ' . $method . ' users'); redirect_browser(module_user::link_open(false)); } } $user_id = $this->save_user($user_id, $_POST); if ($use_master_key && isset($_REQUEST[$use_master_key]) && $_REQUEST[$use_master_key]) { set_message("Customer contact saved successfully"); redirect_browser($this->link_open_contact($user_id)); } else { set_message("User saved successfully"); redirect_browser($this->link_open($user_id)); } } } } /*else if("save_contact" == $_REQUEST['_process']){ $user_id = $this->save_contact($_POST['user_id'],$_POST); $_REQUEST['_redirect'] = $this->link_open_contact(false); if($user_id){ set_message("Contact saved successfully"); }else{ // todo error creating contact } }*/ if (!count($errors)) { redirect_browser($_REQUEST['_redirect']); exit; } print_error($errors, true); }