}else{ $user_type_id = 2; } }*/ //include('user_admin_edit'.$user_type_id.'.php'); //include('user_admin_edit1.php'); 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 } } } ?>
_e('Add Comment'); ?> " class="task_job_discussion_add small_button" data-jobid="<?php echo $job_id; ?> " data-taskid="<?php echo $task_id; ?> "> <?php $send_to_customer_ids = array(); $send_to_staff_ids = array(); if (module_security::get_loggedin_id() && $job_data['customer_id'] && $customer['primary_user_id'] && $customer['primary_user_id'] != $current_user_id) { $send_to_customer_ids[$customer['primary_user_id']] = 1; // put the other customer contacts in here too. $customer_contacts = module_user::get_contacts(array('customer_id' => $job_data['customer_id'])); foreach ($customer_contacts as $contact) { $send_to_customer_ids[$contact['user_id']] = 1; } } if ($job_data['user_id'] && $job_data['user_id'] != $current_user_id && $job_data['user_id'] != $customer['primary_user_id']) { $send_to_staff_ids[$job_data['user_id']] = module_config::c('job_discussion_staff_checked', 1); } if ($task_data['user_id'] && $task_data['user_id'] != $current_user_id && $task_data['user_id'] != $customer['primary_user_id']) { $send_to_staff_ids[$task_data['user_id']] = module_config::c('job_discussion_staff_checked', 1); } if (!module_security::is_logged_in()) { echo '<div style="display:none;">'; } foreach ($send_to_customer_ids as $user_id => $tf) { // we are the admin, sending an email to customer
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; } }
public static function process_password_reset() { // grab our email template and send it to this email address. $email = trim(strtolower($_REQUEST['email'])); $success = false; if (strlen($email) > 4 && strpos($email, '@')) { $users = module_user::get_users(array('email' => $email)); $contacts = module_user::get_contacts(array('email' => $email)); $users = array_merge($users, $contacts); foreach ($users as $user) { // send auto login link for this user. if (strtolower($user['email']) == $email) { $template = module_template::get_template_by_key('password_reset'); $template->assign_values($user); if ($user['customer_id']) { $url = module_user::link_open_contact($user['user_id'], false, $user, true); } else { $url = module_user::link_open($user['user_id'], false, $user, true); } $url .= (strpos($url, '?') ? '&' : '?') . 'reset_password='******'user_id']); $url .= '&auto_login='******'user_id']); $template->assign_values(array('auto_login_url' => $url)); $html = $template->render('html'); $email = module_email::new_email(); $email->replace_values = $user; $email->set_to('user', $user['user_id']); $email->set_subject($template->description); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! $success = true; } else { /// log err? echo 'failed to send email, sorry'; exit; } } } } if ($success || !module_config::c('password_reset_debug', 0)) { set_message('Please check your email for password reset instructions.'); } else { echo 'No users found matching ' . htmlspecialchars($email); exit; } redirect_browser(_BASE_HREF); }
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 }
$quote['task_list'] = $public_html; /*ob_start(); $quote_data = $quote; $ignore_task_hook=true; $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();
<form action="" method="post"> <input type="hidden" name="_process" value="save_security_role" /> <input type="hidden" name="security_role_id" value="<?php echo $security_role_id; ?> " /> <?php /** ROLE DETAILS */ $fieldset_data = array('heading' => array('type' => 'h3', 'title' => 'Role Details'), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array()); $fieldset_data['elements']['name'] = array('title' => 'Name', 'fields' => array(array('type' => 'text', 'name' => 'name', 'value' => $security_role['name']))); if ((int) $security_role_id > 0) { $fieldset_data['elements']['users'] = array('title' => 'Name', 'fields' => array(function () use($security_role_id) { $users = module_user::get_users(array('security_role_id' => $security_role_id)); $contacts = module_user::get_contacts(array('security_role_id' => $security_role_id)); $url1 = module_user::link_open_contact(false); $url1 .= strpos($url1, '?') ? '&' : '?'; $url2 = module_user::link_open(false); $url2 .= strpos($url1, '?') ? '&' : '?'; _e('There are <a href="%s">%s customer contacts</a> and <a href="%s">%s system users</a> with this role.', $url1 . 'search[security_role_id]=' . (int) $security_role_id, count($contacts), $url2 . 'search[security_role_id]=' . (int) $security_role_id, count($users)); })); } $fieldset_data['elements']['defaults'] = array('title' => 'Load Defaults', 'fields' => array(array('type' => 'select', 'name' => 'load_defaults', 'value' => '', 'options' => array('{"Change Request|change_request|Change Requests|Permissions":["view"],"Customer|customer|Customers|Permissions":["view"],"Customer|user|Contacts|Permissions":["view","edit","create"],"Customer|customer|All Customer Contacts|Permissions":["view","edit"],"Invoice|invoice|Invoices|Permissions":["view"],"Job|job|Jobs|Permissions":["view"],"Job|job|Job Tasks|Permissions":["view"],"Ticket|ticket|Tickets|Permissions":["view","create"],"Website|website|Websites|Permissions":["view"],"Customer Data Access|config|Only customer I am assigned to as a contact|drop_down":["view"],"Job Data Access|config|Jobs from customers I have access to|drop_down":["view"],"Job Task Creation|config|Created tasks require admin approval|drop_down":["view"],"Ticket Access|config|Only tickets from my customer account|drop_down":["view"],"User Account Access|config|Only Contact Accounts|drop_down":["view"],"User Specific|config|Can User Login|checkbox":["view"]}' => _l('Customer View Only'), '{"Company|company|Company|Permissions":["view"],"Customer|customer|Customers|Permissions":["view","edit","create"],"Customer|user|Contacts|Permissions":["view","edit","create"],"Customer|customer|All Customer Notes|Permissions":["view","edit","create"],"Customer|customer|All Customer Contacts|Permissions":["view"],"Customer|customer|Customer Groups|Permissions":["view","edit","create"],"File|file|Files|Permissions":["view","edit","create"],"File|file|File Comments|Permissions":["view","create"],"Invoice|invoice|Invoices|Permissions":["view","edit","create"],"Invoice|invoice|Invoice Notes|Permissions":["view","edit","create"],"Invoice|invoice|Invoice Payments|Permissions":["edit","create"],"Job|job|Jobs|Permissions":["view","edit","create"],"Job|job|Job Notes|Permissions":["view","edit","create"],"Job|job|Job Tasks|Permissions":["view","edit","create"],"Job|job|Job Groups|Permissions":["view","edit","create"],"Job|job|Job Advanced|Permissions":["view"],"Job Discussion|job_discussion|Job Discussions|Permissions":["view"],"Pin|pin|Header Pin|Permissions":["view","edit","create","delete"],"Ticket|ticket|Tickets|Permissions":["view","edit","create"],"User|user|User Notes|Permissions":["view","edit","create"],"Website|website|Websites|Permissions":["view","edit","create"],"Website|website|Website Notes|Permissions":["view","edit","create"],"Website|website|Website Groups|Permissions":["view","edit","create"],"Company Data Access|config|Only companies I am assigned to in staff area|drop_down":["view"],"Customer Data Access|config|Only customers from companies I have access to|drop_down":["view"],"Invoice Data Access|config|Invoices from Jobs I have access to|drop_down":["view"],"Job Data Access|config|Only jobs I am assigned to|drop_down":["view"],"Job Task Creation|config|Created tasks do not require approval|drop_down":["view"],"Job Task Data Access|config|All tasks within a job|drop_down":["view"],"Ticket Access|config|Only tickets from my customer account|drop_down":["view"],"User Account Access|config|Only My Account|drop_down":["view"],"User Specific|config|Can User Login|checkbox":["view"],"User Specific|config|Show Quick Search|checkbox":["view"],"User Specific|config|Show Dashboard Alerts|checkbox":["view"],"User Specific|config|Show Dashboard Todo List|checkbox":["view"],"User Specific|config|Receive File Upload Alerts|checkbox":["view"]}' => _l('Staff Member'), '{"Company|company|Company|Permissions":["view"],"Customer|customer|Customers|Permissions":["view","edit","create"],"Customer|user|Contacts|Permissions":["view","edit","create"],"Customer|customer|All Customer Notes|Permissions":["view","edit","create"],"Customer|customer|All Customer Contacts|Permissions":["view","edit"],"Customer|customer|Customer Groups|Permissions":["view","edit","create"],"Customer|customer|All Lead Contacts|Permissions":["view","edit"],"Customer|customer|Lead Groups|Permissions":["view","edit","create"],"Customer|customer|All Lead Notes|Permissions":["view","edit","create"],"File|file|Files|Permissions":["view","edit","create"],"File|file|File Comments|Permissions":["view","create"],"Invoice|invoice|Invoices|Permissions":["view","edit","create"],"Invoice|invoice|Invoice Notes|Permissions":["view","edit","create"],"Invoice|invoice|Invoice Payments|Permissions":["edit","create"],"Job|job|Jobs|Permissions":["view","edit","create"],"Job|job|Job Notes|Permissions":["view","edit","create"],"Job|job|Job Tasks|Permissions":["view","edit","create"],"Job|job|Job Groups|Permissions":["view","edit","create"],"Job|job|Job Advanced|Permissions":["view"],"Job Discussion|job_discussion|Job Discussions|Permissions":["view"],"Pin|pin|Header Pin|Permissions":["view","edit","create","delete"],"Ticket|ticket|Tickets|Permissions":["view","edit","create"],"User|user|User Notes|Permissions":["view","edit","create"],"Vendor|user|Contacts|Permissions":["view","edit"],"Vendor|vendor|Vendors|Permissions":["view"],"Vendor|vendor|All Vendor Contacts|Permissions":["view"],"Website|website|Websites|Permissions":["view","edit","create"],"Website|website|Website Notes|Permissions":["view","edit","create"],"Website|website|Website Groups|Permissions":["view","edit","create"],"Calendar Data Access|config|Only from Customers or assigned items|drop_down":["view"],"Company Data Access|config|All companies in system|drop_down":["view"],"Customer Data Access|config|Only customers I am assigned to as a staff member|drop_down":["view"],"File Data Access|config|Only files from customers I have access to|drop_down":["view"],"Invoice Data Access|config|Invoices from customers I have access to|drop_down":["view"],"Job Data Access|config|Jobs from customers I have access to|drop_down":["view"],"Job Task Creation|config|Created tasks do not require approval|drop_down":["view"],"Job Task Data Access|config|All tasks within a job|drop_down":["view"],"Quote Data Access|config|Quotes from customers I have access to|drop_down":["view"],"Quote Task Creation|config|Created tasks do not require approval|drop_down":["view"],"Quote Task Data Access|config|All tasks within a quote|drop_down":["view"],"Ticket Access|config|Only tickets from my customer account|drop_down":["view"],"User Account Access|config|All Contact and User Accounts|drop_down":["view"],"Vendor Data Access|config|Only vendor I am assigned to as a contact|drop_down":["view"],"User Specific|config|Can User Login|checkbox":["view"],"User Specific|config|Show Quick Search|checkbox":["view"],"User Specific|config|Show Dashboard Alerts|checkbox":["view"],"User Specific|config|Show Dashboard Todo List|checkbox":["view"],"User Specific|config|Receive File Upload Alerts|checkbox":["view"],"User Specific|config|Receive File Comment Alerts|checkbox":["view"]}' => _l('Staff Member Improved'), '{"Calendar|calendar|Calendar|Permissions":["view","edit","create"],"Company|company|Company|Permissions":["view"],"Config|user|Users|Permissions":["view","edit"],"Config|user|Users Passwords|Permissions":["view","edit","create"],"Config|user|Staff Settings|Permissions":["edit"],"Customer|user|Contacts|Permissions":["view","edit","create","delete"],"Customer|customer|Customers|Permissions":["view","edit","create","delete"],"Customer|customer|Leads|Permissions":["view","edit","create"],"Customer|customer|All Customer Notes|Permissions":["view","edit","create","delete"],"Customer|customer|All Customer Contacts|Permissions":["view","edit"],"Customer|customer|Customer Groups|Permissions":["view","edit","create","delete"],"Customer|customer|Export Customers|Permissions":["view"],"Customer|customer|Import Customers|Permissions":["view"],"Customer|customer|Customer Staff|Permissions":["edit"],"Customer|customer|Customer Credit|Permissions":["edit"],"Customer|customer|Export Leads|Permissions":["view"],"Customer|customer|Import Leads|Permissions":["view"],"Customer|customer|All Lead Contacts|Permissions":["view","edit"],"Customer|customer|Lead Groups|Permissions":["view","delete"],"Customer|customer|All Lead Notes|Permissions":["delete"],"File|file|Files|Permissions":["view","edit","create","delete"],"File|file|File Comments|Permissions":["view","create","delete"],"File|file|File Approval|Permissions":["edit"],"Finance|finance|Dashboard Finance Summary|Permissions":["view"],"Invoice|invoice|Invoices|Permissions":["view","edit","create","delete"],"Invoice|invoice|Invoice Notes|Permissions":["view","edit","create","delete"],"Invoice|invoice|Invoice Payments|Permissions":["edit","create"],"Invoice|invoice|Export Invoices|Permissions":["view"],"Job|job|Jobs|Permissions":["view","edit","create","delete"],"Job|job|Job Notes|Permissions":["view","edit","create","delete"],"Job|job|Job Tasks|Permissions":["view","edit","create"],"Job|job|Job Groups|Permissions":["view","edit","create","delete"],"Job|job|Job Advanced|Permissions":["view"],"Job|job|Export Job Tasks|Permissions":["view"],"Job|job|Import Job Tasks|Permissions":["view"],"Job|job|Export Jobs|Permissions":["view"],"Job|job|Import Jobs|Permissions":["view"],"Job Discussion|job_discussion|Job Discussions|Permissions":["view"],"User|user|User Notes|Permissions":["view","edit","create"],"Website|website|Websites|Permissions":["view","edit","create","delete"],"Website|website|Website Notes|Permissions":["view","edit","create","delete"],"Website|website|Website Groups|Permissions":["view","edit","create","delete"],"Website|website|Export Websites|Permissions":["view"],"Website|website|Import Websites|Permissions":["view"],"Calendar Data Access|config|Only from Customers or assigned items|drop_down":["view"],"Company Data Access|config|Only companies I am assigned to in staff area|drop_down":["view"],"Customer Data Access|config|Only customers from companies I have access to|drop_down":["view"],"File Data Access|config|Only files from customers I have access to|drop_down":["view"],"Invoice Data Access|config|Invoices from customers I have access to|drop_down":["view"],"Job Data Access|config|Jobs from customers I have access to|drop_down":["view"],"Job Task Creation|config|Created tasks do not require approval|drop_down":["view"],"Job Task Data Access|config|All tasks within a job|drop_down":["view"],"Quote Data Access|config|Quotes from customers I have access to|drop_down":["view"],"Quote Task Creation|config|Created tasks do not require approval|drop_down":["view"],"Quote Task Data Access|config|All tasks within a quote|drop_down":["view"],"Ticket Access|config|Only tickets from my customer account|drop_down":["view"],"User Account Access|config|Only Contact Accounts|drop_down":["view"],"Vendor Data Access|config|Only vendors from companies I have access to|drop_down":["view"],"User Specific|config|Show Quick Search|checkbox":["view"],"User Specific|config|Show Dashboard Alerts|checkbox":["view"],"User Specific|config|Show Dashboard Todo List|checkbox":["view"],"User Specific|config|Receive File Upload Alerts|checkbox":["view"],"User Specific|config|Can User Login|checkbox":["view"],"User Specific|config|Receive File Comment Alerts|checkbox":["view"]}' => _l('Reseller')), 'help' => 'This will override any options selected below and replace them with defaults. You can change the selected permissions once the defaults are loaded'))); echo module_form::generate_fieldset($fieldset_data); unset($fieldset_data); /** PERMIOSSIONS */ ob_start(); hook_handle_callback('layout_column_half', 1); ?>
} hook_handle_callback('layout_column_half', 1); $hide_more_button = true; $title = 'Contact Details'; include module_theme::include_ucm('includes/plugin_user/pages/contact_admin_form.php'); if (class_exists('module_address', false) && module_config::c('users_have_address', 0)) { module_address::print_address_form($user_id, 'user', 'physical', 'Address'); } ?> <?php if ((int) $user_id > 0 && module_user::can_i('edit', 'Contacts', $contact_type) && strlen($user['email']) > 2 && $use_master_key == 'customer_id') { // check if contact exists under other customer accounts. $others = module_user::get_contacts(array('email' => $user['email'], "{$contact_module_name}_id" => 0)); if (count($others) > 1) { foreach ($others as $other_id => $other) { if ($other['user_id'] == $user['user_id']) { // this "other" person is from teh same customer as us. unset($others[$other_id]); } else { if (count($contact_links)) { // check if this one is already linked somewhere. foreach ($contact_links as $contact_link) { if ($contact_link['user_id'] == $other['user_id']) { unset($others[$other_id]); break; } } }
); } } echo module_form::generate_fieldset($fieldset_data); */ hook_handle_callback('layout_column_half', 2); if ($vendor_id && $vendor_id != 'new') { if (class_exists('module_group', false) && module_group::is_plugin_enabled()) { module_group::display_groups(array('title' => $page_type_single . ' Categories', 'owner_table' => 'vendor', 'owner_id' => $vendor_id, 'view_link' => $module->link_open($vendor_id))); } $note_summary_owners = array(); // generate a list of all possible notes we can display for this vendor. // display all the notes which are owned by all the sites we have access to // display all the notes which are owned by all the users we have access to foreach (module_user::get_contacts(array('vendor_id' => $vendor_id)) as $val) { $note_summary_owners['user'][] = $val['user_id']; } /*if(class_exists('module_website',false) && module_website::is_plugin_enabled()){ foreach(module_website::get_websites(array('vendor_id'=>$vendor_id)) as $val){ $note_summary_owners['website'][] = $val['website_id']; } } if(class_exists('module_job',false) && module_job::is_plugin_enabled()){ foreach(module_job::get_jobs(array('vendor_id'=>$vendor_id)) as $val){ $note_summary_owners['job'][] = $val['job_id']; foreach(module_invoice::get_invoices(array('job_id'=>$val['job_id'])) as $val){ $note_summary_owners['invoice'][$val['invoice_id']] = $val['invoice_id']; } } }
} $email = module_email::get_email($email_id); if (!count($email) || $email['email_id'] != $email_id) { $email_id = false; $email = false; } if (!$email_id) { // creating a new email $can_edit_emails = true; } else { $can_edit_emails = false; // don't want to edit existing email } $current_template = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : 'email_template_blank'; $find_other_templates = 'email_template_'; $to = module_user::get_contacts(array('customer_id' => $customer_id)); $bcc = module_config::c('admin_email_address', ''); $headers = @unserialize($email['headers']); if ($current_template && !$email_id) { $template = module_template::get_template_by_key($current_template); //todo: replace fields. //$replace = module_invoice::get_replace_fields($invoice_id,$invoice); if ($email['customer_id']) { $customer_data = module_customer::get_customer($email['customer_id']); $replace = module_customer::get_replace_fields($email['customer_id'], false, $customer_data); $template->assign_values($replace); } if ($email['job_id']) { $job_data = module_job::get_job($email['job_id']); $replace = module_job::get_replace_fields($email['job_id'], $job_data); $template->assign_values($replace);
public static function hook_filter_var_contact_list($call, $attributes) { if (!is_array($attributes)) { $attributes = array(); } foreach (module_user::get_contacts(array('customer_id' => isset($_REQUEST['customer_id']) ? (int) $_REQUEST['customer_id'] : false)) as $contact) { $attributes[$contact['user_id']] = $contact['name'] . ' ' . $contact['last_name']; } return $attributes; }
public static function handle_import($data, $add_to_group) { // woo! we're doing an import. // our first loop we go through and find matching vendors by their "vendor_name" (required field) // and then we assign that vendor_id to the import data. // our second loop through if there is a vendor_id we overwrite that existing vendor with the import data (ignoring blanks). // if there is no vendor id we create a new vendor record :) awesome. foreach ($data as $rowid => $row) { if (!isset($row['vendor_name']) || !trim($row['vendor_name'])) { unset($data[$rowid]); continue; } if (!isset($row['vendor_id']) || !$row['vendor_id']) { $data[$rowid]['vendor_id'] = 0; } } // now save the data. foreach ($data as $rowid => $row) { //module_cache::clear_cache(); $vendor_id = isset($row['vendor_id']) ? (int) $row['vendor_id'] : 0; // check if this ID exists. if ($vendor_id > 0) { $vendor = self::get_vendor($vendor_id); if (!$vendor || !isset($vendor['vendor_id']) || $vendor['vendor_id'] != $vendor_id) { $vendor_id = 0; } } if (!$vendor_id) { // search for a custoemr based on name. $vendor = get_single('vendor', 'vendor_name', $row['vendor_name']); //print_r($row); print_r($vendor);echo '<hr>'; if ($vendor && $vendor['vendor_id'] > 0) { $vendor_id = $vendor['vendor_id']; } } $vendor_id = update_insert("vendor_id", $vendor_id, "vendor", $row); // see if we're updating an old contact, or adding a new primary contact. // match on name since that's a required field. $users = module_user::get_contacts(array('vendor_id' => $vendor_id)); $user_match = 0; foreach ($users as $user) { if ($user['name'] == $row['primary_user_name']) { $user_match = $user['user_id']; break; } } $user_update = array('vendor_id' => $vendor_id); if (isset($row['primary_user_name'])) { $user_update['name'] = $row['primary_user_name']; } if (isset($row['primary_user_last_name'])) { $user_update['last_name'] = $row['primary_user_last_name']; } if (isset($row['primary_user_email'])) { $user_update['email'] = $row['primary_user_email']; } if (isset($row['primary_user_phone'])) { $user_update['phone'] = $row['primary_user_phone']; } if (isset($row['primary_user_fax'])) { $user_update['fax'] = $row['primary_user_fax']; } if (isset($row['primary_user_mobile'])) { $user_update['mobile'] = $row['primary_user_mobile']; } if (isset($row['primary_user_language'])) { $user_update['language'] = $row['primary_user_language']; } if (isset($row['password']) && strlen($row['password'])) { $user_update['password'] = md5(trim($row['password'])); } $user_match = update_insert("user_id", $user_match, "user", $user_update); if ($user_match && isset($row['role']) && strlen(trim($row['role']))) { // find this role name and assign it to this user. $role = module_security::get_roles(array('name' => $row['role'])); if ($role) { $user_role = array_shift($role); $role_id = $user_role['security_role_id']; module_user::add_user_to_role($user_match, $role_id); } } self::set_primary_user_id($vendor_id, $user_match); // do a hack to save address. $existing_address = module_address::get_address($vendor_id, 'vendor', 'physical'); $address_id = $existing_address && isset($existing_address['address_id']) ? (int) $existing_address['address_id'] : 'new'; $address = array_merge($row, array('owner_id' => $vendor_id, 'owner_table' => 'vendor', 'address_type' => 'physical')); module_address::save_address($address_id, $address); foreach ($add_to_group as $group_id => $tf) { module_group::add_to_group($group_id, $vendor_id, 'vendor'); } // 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) { // we handle extra importing for vendor extra fields and contact extra fields. // sort out which are which. // but they have to be unique names. for now. oh well that'll do. $sql = "SELECT `extra_key` as `id` FROM `" . _DB_PREFIX . "extra` WHERE owner_table = 'vendor' AND `extra_key` != '' GROUP BY `extra_key` ORDER BY `extra_key`"; $vendor_fields = qa($sql); $sql = "SELECT `extra_key` as `id` FROM `" . _DB_PREFIX . "extra` WHERE owner_table = 'user' AND `extra_key` != '' GROUP BY `extra_key` ORDER BY `extra_key`"; $contact_fields = qa($sql); foreach ($extra as $extra_key => $extra_val) { // does this one exist? if (isset($vendor_fields[$extra_key])) { // this is a vendor extra field. $existing_extra = module_extra::get_extras(array('owner_table' => 'vendor', 'owner_id' => $vendor_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' => 'vendor', 'owner_id' => $vendor_id); $extra_id = (int) $extra_id; update_insert('extra_id', $extra_id, 'extra', $extra_db); } else { if ($user_match && isset($contact_fields[$extra_key])) { // this is a primary contact extra field $existing_extra = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $user_match, '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' => 'user', 'owner_id' => $user_match); $extra_id = (int) $extra_id; update_insert('extra_id', $extra_id, 'extra', $extra_db); } } } } } }
} /*** ADDRESS **/ if (class_exists('module_address', false)) { module_address::print_address_form($customer_id, 'customer', 'physical', 'Address'); } /** ADVANCED AREA **/ hook_handle_callback('layout_column_half', 2); if ($customer_id && $customer_id != 'new') { if (class_exists('module_group', false) && module_group::is_plugin_enabled()) { module_group::display_groups(array('title' => $page_type_single . ' Groups', 'owner_table' => 'customer', 'owner_id' => $customer_id, 'view_link' => $module->link_open($customer_id))); } $note_summary_owners = array(); // generate a list of all possible notes we can display for this customer. // display all the notes which are owned by all the sites we have access to // display all the notes which are owned by all the users we have access to foreach (module_user::get_contacts(array('customer_id' => $customer_id)) as $val) { $note_summary_owners['user'][] = $val['user_id']; } if (class_exists('module_website', false) && module_website::is_plugin_enabled()) { foreach (module_website::get_websites(array('customer_id' => $customer_id)) as $val) { $note_summary_owners['website'][] = $val['website_id']; } } if (class_exists('module_job', false) && module_job::is_plugin_enabled()) { foreach (module_job::get_jobs(array('customer_id' => $customer_id)) as $val) { $note_summary_owners['job'][] = $val['job_id']; foreach (module_invoice::get_invoices(array('job_id' => $val['job_id'])) as $val) { $note_summary_owners['invoice'][$val['invoice_id']] = $val['invoice_id']; } } }
if ($quote['customer_id'] && module_customer::can_i('view', 'Customers')) { ?> <a href="<?php echo module_customer::link_open($quote['customer_id'], false); ?> "><?php _e('Open'); ?> </a> <?php } })); if ($quote['customer_id']) { $c = array(); $res = module_user::get_contacts(array('customer_id' => $quote['customer_id']), false, false); $primary_contact = false; while ($row = mysql_fetch_assoc($res)) { $c[$row['user_id']] = $row['name'] . ' ' . $row['last_name']; if ($row['primary_user_id'] == $row['user_id']) { $primary_contact = $row; } } $c[0] = _l('Primary (%s)', $primary_contact ? htmlspecialchars($primary_contact['name'] . ' ' . $primary_contact['last_name']) : _l('N/A')); if ($quote['contact_user_id'] > 0 && !isset($c[$quote['contact_user_id']])) { // this option isn't in the listing. add it in. $user_temp = module_user::get_user($quote['contact_user_id'], false); $c[$quote['contact_user_id']] = $user_temp['name'] . ' ' . $user_temp['last_name'] . ' ' . _l('(under different customer)'); } $fieldset_data['elements'][] = array('title' => 'Contact', 'field' => array('type' => 'select', 'name' => 'contact_user_id', 'value' => $quote['contact_user_id'] > 0 ? $quote['contact_user_id'] : 0, 'options' => $c, 'blank' => false)); }
$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'])) { $c = array(); if ($ticket['customer_id']) { $res = module_user::get_contacts(array('customer_id' => $ticket['customer_id'])); } else { $res = array(); } while ($row = array_shift($res)) { $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. }
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_customer::link_open($invoice['customer_id'], true); if (module_invoice::can_i('edit', 'Invoices')) { ?> <a href="<?php echo module_invoice::link_open($invoice['invoice_id']); ?> &change_customer"><?php _e('(change)'); ?> </a> <?php } } })); 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));
private static function send_job_task_email($job_id, $task_id, $reason) { $return_messages = array(); if (module_config::c('job_send_staff_task_email_automatically', 0) && $reason == 'created') { // send the same emial as if going to job_admin_email_staff.php $task_data = self::get_task($job_id, $task_id); $job_data = self::get_job($job_id); if ($task_data['user_id'] > 0 && $task_data['user_id'] != module_security::get_loggedin_id()) { $staff = module_user::get_user($task_data['user_id']); if ($staff && $staff['user_id'] == $task_data['user_id'] && !(module_config::c('job_staff_email_skip_complete', 0) && $task_data['fully_completed'])) { $template = module_template::get_template_by_key('job_staff_email'); $job_data['job_name'] = $job_data['name']; $job_data['staff_name'] = $staff['name']; $job_data['job_url'] = module_job::link_open($job_id); $job_data['job_tasks'] = '<ul>'; $job_data['task_count'] = 0; //foreach($job_tasks as $job_task){ $job_task = $task_data; //if($job_task['user_id']!=$staff_id)continue; //if(module_config::c('job_staff_email_skip_complete',0)&&$job_task['fully_completed'])continue; $job_data['job_tasks'] .= '<li><strong>' . $job_task['description'] . '</strong>'; if ($job_task['fully_completed']) { $job_data['job_tasks'] .= ' <span style="color: #99cc00; font-weight:bold;">(' . _l('complete') . ')</span>'; } $job_data['job_tasks'] .= ' <br/>'; if ($job_task['long_description']) { $job_data['job_tasks'] .= _l('Notes:') . ' <em>' . $job_task['long_description'] . '</em><br/>'; } if ($job_task['date_due'] && $job_task['date_due'] != '0000-00-00') { $job_data['job_tasks'] .= _l('Date Due:') . ' ' . print_date($job_task['date_due']) . '<br/>'; } if ($job_task['hours']) { $job_data['job_tasks'] .= _l('Assigned Hours:') . ' ' . $job_task['hours'] . '<br/>'; } if ($job_task['completed']) { $job_data['job_tasks'] .= _l('Completed Hours:') . ' ' . $job_task['completed'] . '<br/>'; } $job_data['job_tasks'] .= '</li>'; $job_data['task_count']++; //} $job_data['job_tasks'] .= '</ul>'; // find available "to" recipients. // customer contacts. $to = array(); $to[] = array('name' => $staff['name'], 'email' => $staff['email']); $html = $template->render('html'); // send an email to this user. $email = module_email::new_email(); $email->replace_values = $job_data; $email->set_to('user', $staff['user_id']); $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); $email->job_id = $job_id; $email->prevent_duplicates = true; if ($email->send(false)) { self::add_history($job_id, _l('Job task emailed to staff successfully')); $return_messages[] = _l(' and email sent to staff %s', $staff['name']); } else { /// log err? } } } } if (module_config::c('job_send_task_completion_email_automatically', 0) && isset($_POST['confirm_job_task_email'])) { $task_data = self::get_task($job_id, $task_id); $job_data = self::get_job($job_id); if ($task_data['fully_completed'] && $job_data['customer_id']) { $template_name = 'job_task_completion_email'; /*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); $replace = module_job::get_replace_fields($job_id, $job_data); $to_select = false; if ($job_data['customer_id']) { $customer = module_customer::get_customer($job_data['customer_id']); $replace['customer_name'] = $customer['customer_name']; $to = module_user::get_contacts(array('customer_id' => $job_data['customer_id'])); if ($customer['primary_user_id']) { $primary = module_user::get_user($customer['primary_user_id']); if ($primary) { $to_select = $primary['email']; } } } else { $to = array(); } $replace['job_name'] = $job_data['name']; $replace['task_description'] = $task_data['description']; $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 ($to_select) { $email->set_to_manual($to_select); } else { foreach ($to as $t) { $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); $email->job_id = $job_id; $email->customer_id = $job_data['customer_id']; $email->prevent_duplicates = true; if ($email->send(false)) { // 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, ));*/ self::add_history($job_id, _l('Job task emailed to customer successfully')); $return_messages[] = _l(' and email sent to customer'); } else { // log err? } } } // if we are approving or rejecting job tasks with a message. if (isset($_POST['job_task'][$task_id]['approval_actioned']) && $_POST['job_task'][$task_id]['approval_actioned']) { $task_data = self::get_task($job_id, $task_id); $job_data = self::get_job($job_id); if ($task_data['user_id'] > 0) { $staff = module_user::get_user($task_data['user_id']); if ($staff && $staff['user_id'] == $task_data['user_id'] && !(module_config::c('job_staff_email_skip_complete', 0) && $task_data['fully_completed'])) { $template = module_template::get_template_by_key('job_task_approval'); $job_data['job_name'] = $job_data['name']; $job_data['staff_name'] = $staff['name']; $job_data['job_url'] = module_job::link_open($job_id); $job_data['approved_or_rejected'] = $_POST['job_task'][$task_id]['approval_required'] == 2 ? _l('Rejected') : _l('Approved'); $job_data['message'] = isset($_POST['job_task'][$task_id]['approval_message']) ? $_POST['job_task'][$task_id]['approval_message'] : _l('N/A'); $job_data['job_task'] = '<ul>'; $job_data['task_count'] = 0; //foreach($job_tasks as $job_task){ $job_task = $task_data; //if($job_task['user_id']!=$staff_id)continue; //if(module_config::c('job_staff_email_skip_complete',0)&&$job_task['fully_completed'])continue; $job_data['job_task'] .= '<li><strong>' . $job_task['description'] . '</strong>'; if ($job_task['fully_completed']) { $job_data['job_task'] .= ' <span style="color: #99cc00; font-weight:bold;">(' . _l('complete') . ')</span>'; } $job_data['job_task'] .= ' <br/>'; if ($job_task['long_description']) { $job_data['job_task'] .= _l('Notes:') . ' <em>' . $job_task['long_description'] . '</em><br/>'; } if ($job_task['date_due'] && $job_task['date_due'] != '0000-00-00') { $job_data['job_task'] .= _l('Date Due:') . ' ' . print_date($job_task['date_due']) . '<br/>'; } if ($job_task['hours']) { $job_data['job_task'] .= _l('Assigned Hours:') . ' ' . $job_task['hours'] . '<br/>'; } if (isset($job_task['completed']) && $job_task['completed']) { $job_data['job_task'] .= _l('Completed Hours:') . ' ' . (isset($job_task['completed']) ? $job_task['completed'] : '') . '<br/>'; } $job_data['job_task'] .= '</li>'; $job_data['task_count']++; //} $job_data['job_task'] .= '</ul>'; // find available "to" recipients. // customer contacts. $to = array(); $to[] = array('name' => $staff['name'], 'email' => $staff['email']); $template->assign_values($job_data); $html = $template->render('html'); // send an email to this user. $email = module_email::new_email(); $email->replace_values = $job_data; $email->set_to('user', $staff['user_id']); $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); $email->job_id = $job_id; $email->prevent_duplicates = true; if ($email->send(false)) { self::add_history($job_id, _l('Job task emailed to staff successfully')); $return_messages[] = _l(' and email sent to staff %s', $staff['name']); } else { /// log err? } } } } if (count($return_messages)) { return array('message' => implode(' ', $return_messages)); } return false; }
$module->page_title = _l($contact_type_permission . ' Contacts'); if (!isset($search[$use_master_key]) || !$search[$use_master_key]) { // we are just showing a list of all customer contacts. $show_customer_details = true; // check they have permissions to view all customer contacts. if (class_exists('module_security', false)) { // if they are not allowed to "edit" a page, but the "view" permission exists // then we automatically grab the page and regex all the crap out of it that they are not allowed to change // eg: form elements, submit buttons, etc.. module_security::check_page(array('category' => $contact_type, 'page_name' => 'All ' . $contact_type_permission . ' Contacts', 'module' => $contact_module_name, 'feature' => 'view')); } //throw new Exception('Please create a user correctly'); } else { $show_customer_details = false; } $users = module_user::get_contacts($search, true, false); if (class_exists('module_group', false)) { module_group::enable_pagination_hook(array('fields' => array('owner_id' => 'user_id', 'owner_table' => 'user', 'name' => 'name', 'email' => 'email'))); } // hack to add a "export" option to the pagination results. if (class_exists('module_import_export', false) && module_user::can_i('view', 'Export ' . $contact_type_permission . ' Contacts')) { if (isset($_REQUEST['import_export_go'])) { $users = query_to_array($users); foreach ($users as $user_id => $user) { $users[$user_id]['is_primary'] = $user['is_primary'] == $user['user_id'] ? _l('Yes') : _l('No'); } } module_import_export::enable_pagination_hook(array('name' => $contact_type_permission . ' Contact Export', 'fields' => array($contact_type_permission . ' Contact ID' => 'user_id', 'First Name' => 'name', 'Last Name' => 'last_name', $contact_type_permission . ' ID' => $contact_module_name . '_id', $contact_type_permission . ' Name' => $contact_module_name . '_name', 'Primary Contact' => 'is_primary', 'Phone' => 'phone', 'Email' => 'email', 'Fax' => 'fax', 'Mobile' => 'mobile'), 'extra' => array('owner_table' => 'user', 'owner_id' => 'user_id'), 'group' => array(array('title' => 'Contact Group', 'owner_table' => 'user', 'owner_id' => 'user_id')))); } $heading = array('main' => true, 'type' => 'h2', 'title' => _l(($show_customer_details ? 'All ' : '') . $contact_type_permission . ' Contacts'), 'button' => array()); if (isset($search[$use_master_key]) && $search[$use_master_key] && module_user::can_i('create', 'Contacts', $contact_type_permission)) {
You can view and modify this change request by <a href="{CHANGE_REQUEST_URL}">clicking here</a>.<br><br> Thank you,<br><br> {FROM_NAME} ', 'Change Request: {URL}', array('NAME' => 'Customers Name', 'URL' => 'Website address', 'REQUEST' => 'Change REquest', 'FROM_NAME' => 'Your name', 'CHANGE_REQUEST_URL' => 'Link to change request for customer')); // template for sending emails. // are we sending the paid one? or the dueone. //$template_name = 'change_request_email'; $template_name = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : 'change_request_email'; $template = module_template::get_template_by_key($template_name); $change_request['from_name'] = module_security::get_loggedin_name(); $change_request['change_request_url'] = module_change_request::link_public_change($website_data['website_id'], $change_request_id); ob_start(); $change_request['change_request_tasks'] = ob_get_clean(); // find available "to" recipients. // customer contacts. $to_select = false; if ($website_data['customer_id']) { $customer = module_customer::get_customer($website_data['customer_id']); $change_request['customer_name'] = $customer['customer_name']; $to = module_user::get_contacts(array('customer_id' => $website_data['customer_id'])); if ($customer['primary_user_id']) { $primary = module_user::get_user($customer['primary_user_id']); if ($primary) { $to_select = $primary['email']; } } } else { $to = array(); } $template->assign_values($change_request); module_email::print_compose(array('find_other_templates' => 'change_request_email', 'current_template' => $template_name, 'customer_id' => $website_data['customer_id'], 'change_request_id' => $change_request['change_request_id'], 'debug_message' => 'Sending change request email', 'to' => $to, 'to_select' => $to_select, 'bcc' => module_config::c('admin_email_address', ''), 'content' => $template->render('html'), 'subject' => $template->replace_description(), 'success_url' => module_website::link_open($website_data['website_id']), 'cancel_url' => module_website::link_open($website_data['website_id'])));