Example #1
0
 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);
 }
// are we sending the paid one? or the dueone.
$template_name = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : 'quote_staff_email';
$template = module_template::get_template_by_key($template_name);
$quote['quote_name'] = $quote['name'];
$quote['staff_name'] = $staff['name'];
$quote['quote_url'] = module_quote::link_open($quote_id);
$quote['quote_tasks'] = '<ul>';
$quote['task_count'] = 0;
foreach ($quote_tasks as $quote_task) {
    if ($quote_task['user_id'] != $staff_id) {
        continue;
    }
    $quote['quote_tasks'] .= '<li><strong>' . $quote_task['description'] . '</strong>';
    $quote['quote_tasks'] .= ' <br/>';
    if ($quote_task['long_description']) {
        $quote['quote_tasks'] .= _l('Notes:') . ' <em>' . $quote_task['long_description'] . '</em><br/>';
    }
    if ($quote_task['hours']) {
        $quote['quote_tasks'] .= _l('Hours:') . ' ' . $quote_task['hours'] . '<br/>';
    }
    $quote['quote_tasks'] .= '</li>';
    $quote['task_count']++;
}
$quote['quote_tasks'] .= '</ul>';
// find available "to" recipients.
// customer contacts.
$to = array();
$to[] = array('name' => $staff['name'], 'email' => $staff['email']);
$template->assign_values($quote);
module_email::print_compose(array('title' => _l('Email Quote: %s', $quote['name']), 'find_other_templates' => 'quote_staff_email', 'current_template' => $template_name, 'quote_id' => $quote['quote_id'], 'debug_message' => 'Sending quote to staff', 'to' => $to, 'bcc' => module_config::c('admin_email_address', ''), 'content' => $template->render('html'), 'subject' => $template->replace_description(), 'success_url' => module_quote::link_open($quote_id), 'cancel_url' => module_quote::link_open($quote_id)));
    $fieldset_data['elements'][] = array('title' => 'Contact', 'field' => array('type' => 'select', 'name' => 'user_id', 'value' => $invoice['user_id'], 'options' => $c, 'blank' => false));
}
echo module_form::generate_fieldset($fieldset_data);
unset($fieldset_data);
if ((int) $invoice_id > 0) {
    hook_handle_callback('invoice_sidebar', $invoice_id);
}
if ($invoice_id && $invoice_id != 'new') {
    $note_summary_owners = array();
    // generate a list of all possible notes we can display for this invoice.
    // display all the notes which are owned by all the sites we have access to
    if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
        module_note::display_notes(array('title' => 'Invoice Notes', 'owner_table' => 'invoice', 'owner_id' => $invoice_id, 'view_link' => module_invoice::link_open($invoice_id), 'public' => array('enabled' => true, 'title' => 'Public', 'text' => 'Yes, show this note in invoice', 'help' => 'If this is ticked then this note will be available to the customer and will be included in the {INVOICE_NOTES} shortcode in the invoice template.')));
    }
    if (module_invoice::can_i('edit', 'Invoices')) {
        module_email::display_emails(array('title' => 'Invoice Emails', 'search' => array('invoice_id' => $invoice_id)));
    }
}
if ((int) $invoice_id > 0 && (!$invoice['date_sent'] || $invoice['date_sent'] == '0000-00-00') && module_security::is_page_editable()) {
    ob_start();
    ?>


            <div class="tableclass_form content">

                <p style="text-align: center;">
                    <input type="submit" name="butt_email" id="butt_email2" value="<?php 
    echo _l('Email Invoice');
    ?>
" class="submit_button" />
                    <?php 
Example #4
0
 public static function send_admin_alert($ticket_id, $message = '', $allow_to_cc_bcc = false)
 {
     module_cache::clear('ticket');
     $ticket_data = self::get_ticket($ticket_id);
     $ticket_account_data = self::get_ticket_account($ticket_data['ticket_account_id']);
     $ticket_number = self::ticket_number($ticket_id);
     if ($ticket_data['last_ticket_message_id']) {
         $last_message = self::get_ticket_message($ticket_data['last_ticket_message_id']);
         if (!$message) {
             $htmlmessage = trim($last_message['htmlcontent']);
             if ($htmlmessage) {
                 $message = $htmlmessage;
             } else {
                 $message = nl2br(htmlspecialchars(trim($last_message['content'])));
             }
         }
     } else {
         $last_message = false;
     }
     $to = module_config::c('ticket_admin_email_alert', _ERROR_EMAIL);
     $to_user_id = 0;
     $cc = false;
     if (module_config::c('ticket_auto_notify_staff', 0) && $ticket_data['assigned_user_id']) {
         $staff = module_user::get_user($ticket_data['assigned_user_id'], false);
         if ($staff && $staff['user_id'] == $ticket_data['assigned_user_id'] && $staff['email']) {
             $cc = $to;
             $to = $staff['email'];
             $to_user_id = $staff['user_id'];
         }
     }
     if (strlen($to) < 4) {
         return;
     }
     // do we only send this on first emails or not ?
     $first_only = module_config::c('ticket_admin_alert_first_only', 0);
     if ($first_only && $ticket_data['message_count'] > 1) {
         return;
     }
     $s = self::get_statuses();
     $reply_line = module_config::s('ticket_reply_line', '----- (Please reply above this line) -----');
     // autoreplies go back to the user - not our admin system:
     $from_user_a = module_user::get_user($ticket_data['user_id'], false);
     $reply_to_address = $from_user_a['email'];
     $reply_to_name = $from_user_a['name'];
     $template = module_template::get_template_by_key('ticket_admin_email');
     $template->assign_values(self::get_replace_fields($ticket_id, $ticket_data));
     $template->assign_values(array('ticket_number' => self::ticket_number($ticket_id), 'ticket_status' => $s[$ticket_data['status_id']], 'message' => $message, 'subject' => $ticket_data['subject'], 'position_current' => $ticket_data['position'], 'position_all' => $ticket_data['total_pending'], 'reply_line' => $reply_line, 'days' => module_config::c('ticket_turn_around_days', 5), 'url' => self::link_public($ticket_id), 'url_admin' => self::link_open($ticket_id), 'message_count' => $ticket_data['message_count'], 'ticket_url_cancel' => module_ticket::link_public_status($ticket_id, 7), 'ticket_url_resolved' => module_ticket::link_public_status($ticket_id, _TICKET_STATUS_RESOLVED_ID), 'ticket_url_inprogress' => module_ticket::link_public_status($ticket_id, 5), 'faq_product_id' => $ticket_data['faq_product_id']));
     $content = $template->replace_content();
     $email = module_email::new_email();
     $email->replace_values = $template->values;
     if ($to_user_id) {
         $email->set_to('user', $to_user_id);
     } else {
         $email->set_to_manual($to);
     }
     if ($cc) {
         $email->set_cc_manual($cc);
     }
     if ($ticket_account_data && $ticket_account_data['email']) {
         $email->set_from_manual($ticket_account_data['email'], $ticket_account_data['name']);
         $email->set_bounce_address($ticket_account_data['email']);
     } else {
         $email->set_from_manual($to, module_config::s('admin_system_name'));
         $email->set_bounce_address($to);
     }
     //$email->set_from('user',$from_user_id);
     //$email->set_from('foo','foo',$to,'Admin');
     $headers = $last_message ? @unserialize($last_message['cache']) : false;
     if ($allow_to_cc_bcc && $headers && is_array($headers)) {
         // we're right to do our cc/bcc hack
         if ($headers && isset($headers['to_emails'])) {
             foreach ($headers['to_emails'] as $to_emails) {
                 if (isset($to_emails['address']) && strlen($to_emails['address'])) {
                     $email->set_to_manual($to_emails['address'], isset($to_emails['name']) ? $to_emails['name'] : '');
                 }
             }
         }
         if ($headers && isset($headers['cc_emails'])) {
             foreach ($headers['cc_emails'] as $cc_emails) {
                 if (isset($cc_emails['address']) && strlen($cc_emails['address'])) {
                     $email->set_cc_manual($cc_emails['address'], isset($cc_emails['name']) ? $cc_emails['name'] : '');
                 }
             }
         }
         if ($headers && isset($headers['bcc_emails'])) {
             foreach ($headers['bcc_emails'] as $bcc_emails) {
                 if (isset($bcc_emails['address']) && strlen($bcc_emails['address'])) {
                     $email->set_bcc_manual($bcc_emails['address'], isset($bcc_emails['name']) ? $bcc_emails['name'] : '');
                 }
             }
         }
     }
     // do we reply to the user who created this, or to our ticketing system?
     if (module_config::c('ticket_admin_alert_postback', 1) && $ticket_account_data && $ticket_account_data['email']) {
         $email->set_reply_to($ticket_account_data['email'], $ticket_account_data['name']);
     } else {
         $email->set_reply_to($reply_to_address, $reply_to_name);
     }
     if ($last_message && $last_message['private_message']) {
         $email->set_subject(sprintf(module_config::c('ticket_private_message_email_subject', 'Private Support Ticket Message: [TICKET:%s]'), $ticket_number));
     } else {
         $email->set_subject(sprintf(module_config::c('ticket_admin_alert_subject', 'Support Ticket Updated: [TICKET:%s]'), $ticket_number));
     }
     $email->set_html($content);
     // check attachments:
     $attachments = self::get_ticket_message_attachments($ticket_data['last_ticket_message_id']);
     foreach ($attachments as $attachment) {
         $file_path = 'includes/plugin_ticket/attachments/' . $attachment['ticket_message_attachment_id'];
         $file_name = $attachment['file_name'];
         $email->AddAttachment($file_path, $file_name);
     }
     $email->send();
 }
Example #5
0
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
if (!module_config::can_i('view', 'Settings')) {
    redirect_browser(_BASE_HREF);
}
$settings = array(array('key' => 'email_smtp', 'default' => '0', 'type' => 'checkbox', 'description' => 'Use SMTP when sending emails from this system'), array('key' => 'email_smtp_hostname', 'default' => '', 'type' => 'text', 'description' => 'SMTP hostname (eg: mail.yoursite.com)'), array('key' => 'email_smtp_auth', 'default' => '', 'type' => 'select', 'options' => array('' => _l('Nothing (default)'), 'ssl' => _l('SSL'), 'tls' => _l('TLS (use for Google SMTP)')), 'description' => 'SMTP Security', 'help' => 'If the Nothing (default) option does not work, try using SSL or TLS.'), array('key' => 'email_smtp_authentication', 'default' => '0', 'type' => 'checkbox', 'description' => 'Use SMTP authentication'), array('key' => 'email_smtp_username', 'default' => '', 'type' => 'text', 'description' => 'SMTP Username'), array('key' => 'email_smtp_password', 'default' => '', 'type' => 'text', 'description' => 'SMTP Password'), array('key' => 'email_limit_amount', 'default' => '0', 'type' => 'text', 'description' => 'Limit number of emails', 'help' => 'How many emails you can send per day, hour or minute. Set to 0 for unlimited emails.'), array('key' => 'email_limit_period', 'default' => 'day', 'type' => 'select', 'options' => array('day' => _l('Per Day'), 'hour' => _l('Per Hour'), 'minute' => _l('Per Minute')), 'description' => 'Limit per', 'help' => 'How many emails you can send per day, hour or minute'));
$demo_email = module_config::c('admin_email_address');
if (isset($_REQUEST['email'])) {
    $demo_email = $_REQUEST['email'];
}
if (isset($_REQUEST['_email'])) {
    // send a test email and report any errors.
    $email = module_email::new_email();
    $email->set_subject('Test Email from ' . module_config::c('admin_system_name'));
    $email->set_to_manual($demo_email);
    $email->set_html('This is a test email from the "' . module_config::c('admin_system_name') . '" setup wizard.');
    if (!$email->send()) {
        ?>
        <div class="warning">
            Failed to send test email. Error message: <?php 
        echo $email->error_text;
        ?>
        </div>
        <?php 
    } else {
        ?>
        <strong>Test email sent successfully.</strong>
        <?php 
Example #6
0
 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;
     }
 }
Example #7
0
// find available "to" recipients.
// customer contacts.
$to_select = false;
if ($file['customer_id']) {
    $customer = module_customer::get_customer($file['customer_id']);
    $file['customer_name'] = $customer['customer_name'];
    $to = module_user::get_contacts(array('customer_id' => $file['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();
}
if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) {
    $all_extra_fields = module_extra::get_defaults('file');
    foreach ($all_extra_fields as $e) {
        $file[$e['key']] = _l('N/A');
    }
    // and find the ones with values:
    $extras = module_extra::get_extras(array('owner_table' => 'file', 'owner_id' => $file_id));
    foreach ($extras as $e) {
        $file[$e['extra_key']] = $e['extra'];
    }
}
$template->assign_values($file);
ob_start();
module_email::print_compose(array('title' => _l('Email File: %s', $file['file_name']), 'find_other_templates' => 'file_approval_email', 'current_template' => $template_name, 'customer_id' => $file['customer_id'], 'job_id' => $file['job_id'], 'file_id' => $file['file_id'], 'debug_message' => 'Sending file as email', 'to' => $to, 'to_select' => $to_select, 'bcc' => module_config::c('admin_email_address', ''), 'content' => $template->render('html'), 'subject' => $template->replace_description(), 'success_url' => module_file::link_open($file_id), 'success_callback' => 'module_file::email_sent', 'success_callback_args' => array('file_id' => $file_id), 'cancel_url' => module_file::link_open($file_id)));
Example #8
0
    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 
    }
            $invoices = module_invoice::get_invoices(array('customer_id' => $customer['customer_id'], 'date_paid' => '0000-00-00'));
            // remove cancelled invoices
            foreach ($invoices as $invoice_id => $invoice) {
                if ($invoice['date_cancel'] != '0000-00-00') {
                    unset($invoices[$invoice_id]);
                }
            }
            if (count($invoices)) {
                $fieldset_data = array('heading' => array('type' => 'h3', 'title' => _l('Unpaid Invoices')));
                $fieldset_data['elements_before'] = customer_admin_email_generate_invoice_list($invoices, $customer_id);
                $email_details .= module_form::generate_fieldset($fieldset_data);
            }
        }
    }
    $template->assign_values(array('email_details' => $email_details));
    module_email::print_compose(array('title' => _l('Email Customer: %s', $customer['customer_name']), 'find_other_templates' => 'customer_statement_email', 'current_template' => $template_name, 'customer_id' => $customer['customer_id'], 'debug_message' => 'Sending customer statement 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_customer::link_open($customer['customer_id']), 'cancel_url' => module_customer::link_open($customer['customer_id'])));
} else {
    ?>

<form action="" method="post" id="customer_form">
	<input type="hidden" name="customer_id" value="<?php 
    echo $customer_id;
    ?>
" />
	<input type="hidden" name="email" value="1" />
	<input type="hidden" name="preview_email" value="1" />

    <?php 
    module_form::prevent_exit(array('valid_exits' => array('.submit_button')));
    module_form::print_form_auth();
    $elements = array();
<?php

/** 
 * Copyright: dtbaker 2012
 * Licence: Please check CodeCanyon.net for licence details. 
 * More licence clarification available here:  http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ 
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
if (!$ticket_safe) {
    die('failed');
}
$ticket_id = (int) $_REQUEST['ticket_id'];
$ticket = module_ticket::get_ticket($ticket_id);
print_heading(_l('Notify Staff About Ticket: %s', module_ticket::ticket_number($ticket['ticket_id'])));
// template for sending emails.
// are we sending the paid one? or the dueone.
$template = module_template::get_template_by_key('ticket_email_notify');
$ticket['ticket_number'] = module_ticket::ticket_number($ticket['ticket_id']);
$ticket['from_name'] = module_security::get_loggedin_name();
$ticket['ticket_url'] = module_ticket::link_open($ticket_id);
$ticket['ticket_subject'] = $ticket['subject'];
// sending to the staff member.
$to = module_user::get_user($ticket['assigned_user_id']);
$ticket['staff_name'] = $to['name'] . ' ' . $to['last_name'];
$to = array($to);
$template->assign_values($ticket);
module_email::print_compose(array('to' => $to, 'bcc' => module_config::c('admin_email_address', ''), 'content' => $template->render('html'), 'subject' => $template->replace_description(), 'success_url' => module_ticket::link_open($ticket_id), 'cancel_url' => module_ticket::link_open($ticket_id)));
Example #11
0
 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;
     }
 }
Example #12
0
            $fieldset_data['elements'] = array(array('fields' => array(module_security::purify_html($quote['description']))));
        }
        echo module_form::generate_fieldset($fieldset_data);
        unset($fieldset_data);
    }
}
if ($quote_id && $quote_id != 'new') {
    $note_summary_owners = array();
    // generate a list of all possible notes we can display for this quote.
    // display all the notes which are owned by all the sites we have access to
    if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
        module_note::display_notes(array('title' => 'Quote Notes', 'owner_table' => 'quote', 'owner_id' => $quote_id, 'view_link' => module_quote::link_open($quote_id)));
    }
    if (class_exists('module_quote', false) && module_quote::is_plugin_enabled()) {
        if (module_quote::can_i('edit', 'Quotes')) {
            module_email::display_emails(array('title' => 'Quote Emails', 'search' => array('quote_id' => $quote_id)));
        }
    }
    if (class_exists('module_group', false) && module_group::is_plugin_enabled()) {
        module_group::display_groups(array('title' => 'Quote Groups', 'owner_table' => 'quote', 'owner_id' => $quote_id, 'view_link' => $module->link_open($quote_id)));
    }
}
if (module_quote::can_i('view', 'Quote Advanced')) {
    /***** QUOTE ADVANCED *****/
    $fieldset_data = array('id' => 'quote_advanced', 'heading' => array('type' => 'h3', 'title' => 'Advanced'), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array());
    if ((int) $quote_id > 0 && module_quote::can_i('edit', 'Quotes')) {
        $fieldset_data['elements'][] = array('title' => 'Customer Link', 'fields' => array('<a href="' . module_quote::link_public($quote_id) . '" target="_blank">' . _l('Click to view external link') . '</a>', _hr('You can send this link to the customer and they can view progress on their quote. They can also view a list of any invoices attached to this quote. This is VERY useful to stop customers asking you "how far along are you" with a quote because they can see exactly where you have logged up to in the system.')));
        $fieldset_data['elements'][] = array('title' => 'Email Staff', 'fields' => array(function () use(&$quote_tasks, $quote_id) {
            $allocated_staff_members = array();
            foreach ($quote_tasks as $quote_task) {
                if (!isset($allocated_staff_members[$quote_task['user_id']])) {
Example #13
0
 public static function subscribe_member($email_address, $newsletter_member_id = false)
 {
     // we're subscribing this email address.
     // check they're not already subscribed.
     $already_subscribed = false;
     if ($newsletter_member_id) {
         $newsletter_member = get_single('newsletter_member', 'newsletter_member_id', $newsletter_member_id);
         if ($newsletter_member && $newsletter_member['join_date'] && $newsletter_member['join_date'] != '0000-00-00') {
             // they're already subscribed.
             $already_subscribed = true;
         }
     }
     // send double opt in?
     if (!$already_subscribed && module_config::c('newsletter_double_opt_in', 1)) {
         // add this new member to the blacklist, this will be removed when they confirm.
         module_newsletter::unsubscribe_member_via_email($email_address, 'doubleoptin');
         $template = module_template::get_template_by_key('member_subscription_double_optin');
         $template->assign_values(array('email' => $email_address, 'link' => self::double_optin_confirmation_link($email_address)));
         $html = $template->render('html');
         $email = module_email::new_email();
         $email->replace_values = array('email' => $email_address, 'link' => self::double_optin_confirmation_link($email_address));
         $email->set_to_manual($email_address);
         $email->set_from_manual(module_config::c('newsletter_default_from_email', module_config::c('admin_email_address')), module_config::c('newsletter_default_from_name', module_config::c('admin_system_name')));
         $email->set_subject(module_config::c('newsletter_double_opt_in_subject', 'Please confirm your newsletter subscription'));
         // do we send images inline?
         $email->set_html($html);
         if ($email->send()) {
             // it worked successfully!!
             return true;
         } else {
             return false;
         }
     } else {
         // remove them from a blacklist and remove any bounce counters that could prevent us sending them emails.
         module_newsletter::unsubscribe_member_via_email($email_address, 'new_subscribe', true);
         if ($newsletter_member_id) {
             $sql = "UPDATE `" . _DB_PREFIX . "newsletter_member` SET bounce_count = 0, receive_email = 1, unsubscribe_send_id = 0 WHERE newsletter_member_id = " . (int) $newsletter_member_id . " LIMIT 1";
             query($sql);
             if (!$already_subscribed) {
                 $sql = "UPDATE `" . _DB_PREFIX . "newsletter_member` SET join_date = NOW() WHERE newsletter_member_id = " . (int) $newsletter_member_id . " LIMIT 1";
                 query($sql);
             }
         }
         return true;
         // dont need to do anything.
     }
 }
/** 
 * Copyright: dtbaker 2012
 * Licence: Please check CodeCanyon.net for licence details. 
 * More licence clarification available here:  http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ 
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
if (!isset($options) && isset($_REQUEST['options'])) {
    $options = unserialize(base64_decode($_REQUEST['options']));
}
if (!isset($options)) {
    $options = array();
}
$options = module_email::get_email_compose_options($options);
extract($options);
?>

<form action="" method="post" id="template_change_form">
    <input type="hidden" name="template_name" value="" id="template_name_change">
</form>

<?php 
ob_start();
?>
<form action="<?php 
echo full_link('email.email_compose_basic');
?>
" method="post" enctype="multipart/form-data">
    <input type="hidden" name="_process" value="send_email">
Example #15
0
?>


<form action="" method="post">

<?php 
module_form::print_form_auth();
?>

<?php 
$search_bar = array('elements' => array('name' => array('title' => _l('Email Subject:'), 'field' => array('type' => 'text', 'name' => 'search[generic]', 'value' => isset($search['generic']) ? $search['generic'] : '')), 'date' => array('title' => _l('Sent Date:'), 'fields' => array(array('type' => 'date', 'name' => 'search[date_from]', 'value' => isset($search['date_from']) ? $search['date_from'] : ''), _l('to'), array('type' => 'date', 'name' => 'search[date_to]', 'value' => isset($search['date_to']) ? $search['date_to'] : '')))));
echo module_form::search_bar($search_bar);
$table_manager = module_theme::new_table_manager();
$columns = array();
$columns['email_subject'] = array('title' => 'Email Subject', 'callback' => function ($email) {
    echo module_email::link_open($email['email_id'], true);
}, 'cell_class' => 'row_action');
$columns['email_date'] = array('title' => 'Sent Date', 'callback' => function ($email) {
    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);
});
Example #16
0
            $fieldset_data['elements'] = array(array('fields' => array(module_security::purify_html($job['description']))));
        }
        echo module_form::generate_fieldset($fieldset_data);
        unset($fieldset_data);
    }
}
if ($job_id && $job_id != 'new') {
    $note_summary_owners = array();
    // generate a list of all possible notes we can display for this job.
    // display all the notes which are owned by all the sites we have access to
    if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
        module_note::display_notes(array('title' => 'Job Notes', 'owner_table' => 'job', 'owner_id' => $job_id, 'view_link' => module_job::link_open($job_id)));
    }
    if (class_exists('module_job', false) && module_job::is_plugin_enabled()) {
        if (module_job::can_i('edit', 'Jobs')) {
            module_email::display_emails(array('title' => 'Job Emails', 'search' => array('job_id' => $job_id)));
        }
    }
    if (class_exists('module_group', false) && module_group::is_plugin_enabled()) {
        module_group::display_groups(array('title' => 'Job Groups', 'owner_table' => 'job', 'owner_id' => $job_id, 'view_link' => $module->link_open($job_id)));
    }
}
if (module_job::can_i('view', 'Job Advanced')) {
    /***** JOB ADVANCED *****/
    $fieldset_data = array('heading' => array('type' => 'h3', 'title' => 'Advanced'), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array(array('title' => 'Customer Link', 'field' => array('type' => 'html', 'value' => '<a href="' . module_job::link_public($job_id) . '" target="_blank">' . _l('Click to view external link') . '</a>', 'help' => 'You can send this link to the customer and they can view progress on their job. They can also view a list of any invoices attached to this job. This is VERY useful to stop customers asking you "how far along are you" with a job because they can see exactly where you have logged up to in the system.'))));
    if ((int) $job_id > 0 && module_job::can_i('edit', 'Jobs')) {
        $fieldset_data['elements'][] = array('title' => 'Email Job', 'field' => array('type' => 'html', 'value' => '<a href="' . module_job::link_generate($job_id, array('arguments' => array('email' => 1))) . '">' . _l('Email this Job to Customer') . '</a>', 'help' => 'You can email the customer a copy of this job. This can be a progress report or as an initial quote. '));
        $fieldset_data['elements'][] = array('title' => 'Email Staff', 'fields' => array(function () use(&$job_tasks, $job_id) {
            $allocated_staff_members = array();
            foreach ($job_tasks as $job_task) {
                if (!isset($allocated_staff_members[$job_task['user_id']])) {
Example #17
0
}
$fieldset_data['elements'][] = array('title' => 'Staff', 'fields' => array(array('type' => 'hidden', 'name' => 'staff_ids_save', 'value' => 1), '<div id="staff_ids_holder" style="float:left;">', array('type' => 'select', 'name' => 'staff_ids[]', 'options' => $staff_member_rel, 'multiple' => 'staff_ids_holder', 'values' => $file['staff_ids']), '</div>', function () use(&$file) {
    if ($file['quote_id']) {
        echo ' ';
        echo '<a href="' . module_quote::link_open($file['quote_id'], false) . '">' . _l('Open Quote &raquo;') . '</a>';
    }
}, array('type' => 'html', 'value' => '', 'help' => 'Assign a staff member to this file. Staff members are users who have EDIT permissions on Job Tasks. Click the plus sign to add more staff members. You can apply the "Only Assigned Staff" permission in User Role settings to restrict staff members to these files.<br><br>If there are assigned staff members then those members will be the only ones to receive notifications when a change is made to the file. If no staff are assigned to this file then anyone with the "Receive Alerts" permission will receive file change/comment alerts.')));
echo module_form::generate_fieldset($fieldset_data);
unset($fieldset_data);
hook_handle_callback('layout_column_half', 2);
$fieldset_data = array('heading' => array('title' => _l('Bucket Description'), 'type' => 'h3'), 'elements' => array(array('field' => array('type' => 'wysiwyg', 'name' => 'description', 'value' => $file['description']))));
echo module_form::generate_fieldset($fieldset_data);
unset($fieldset_data);
if ((int) $file_id > 0) {
    if (module_file::can_i('edit', 'Files')) {
        module_email::display_emails(array('title' => 'File Emails', 'search' => array('file_id' => $file_id)));
    }
    ob_start();
    $search = array();
    $search['bucket_parent_file_id'] = $file_id;
    $files = module_file::get_files($search);
    $table_manager = module_theme::new_table_manager();
    $columns = array();
    $columns['file_name'] = array('title' => 'File Name', 'callback' => function ($file) {
        echo module_file::link_open($file['file_id'], true);
        if (isset($file['file_url']) && strlen($file['file_url'])) {
            echo ' ';
            echo '<a href="' . htmlspecialchars($file['file_url']) . '">' . htmlspecialchars($file['file_url']) . '</a>';
        }
    }, 'cell_class' => 'row_action');
    $columns['file_description'] = array('title' => 'Description', 'callback' => function ($file) {
Example #18
0
                    $data_field['value'] = $data_items[$data_field_id]['data_text'];
                    // todo, could be data_number or data_varchar as well... hmmm
                }
                $replace[$data_field['title']] = $module->get_form_element($data_field, true, isset($data_record) ? $data_record : array());
            }
        }
        //$pdf = module_invoice::generate_pdf($invoice_id);
        // template for sending emails.
        // are we sending the paid one? or the dueone.
        $original_template_name = $template_name = $data_type['email_template'];
        $template_name = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : $template_name;
        $template = module_template::get_template_by_key($template_name);
        $template->assign_values($replace);
        $module->page_title = htmlspecialchars($data_type['data_type_name']);
        print_heading(array('main' => true, 'type' => 'h2', 'title' => htmlspecialchars($data_type['data_type_name'])));
        module_email::print_compose(array('title' => _l('Email: %s', htmlspecialchars($data_type['data_type_name'])), 'find_other_templates' => $original_template_name, 'current_template' => $template_name, 'customer_id' => isset($_REQUEST['customer_id']) ? (int) $_REQUEST['customer_id'] : 0, 'to' => array(), 'bcc' => module_config::c('admin_email_address', ''), 'content' => $template->render('html'), 'subject' => $template->replace_description(), 'success_url' => $module->link('', array('data_type_id' => $data_type_id, 'data_record_id' => $data_record_id, 'mode' => 'view')), 'cancel_url' => $module->link('', array('data_type_id' => $data_type_id, 'data_record_id' => $data_record_id, 'mode' => 'view'))));
        ?>
				<p>
				Available Template Keys:	</p>
					<ul>
					<?php 
        foreach ($replace as $key => $val) {
            if (strpos($val, 'encrypt_popup')) {
                continue;
            }
            ?>
					<li><strong>{<?php 
            echo strtoupper(htmlspecialchars($key));
            ?>
}</strong> = <?php 
            echo $val;
Example #19
0
    public function external_hook($hook)
    {
        switch ($hook) {
            case 'popup':
                // popup not used any more. cross domain issues.
                // load up the full script to be injected into our clients website.
                $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false;
                $change_request_id = $change_id = isset($_REQUEST['change_id']) ? (int) $_REQUEST['change_id'] : false;
                $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false;
                $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : false;
                if ($type == 'popupjs') {
                    @ob_end_clean();
                    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                    header("Cache-Control: no-cache");
                    header("Pragma: no-cache");
                    header("Content-type: text/javascript");
                }
                if ($website_id && $hash && module_change_request::link_popup($website_id, true) == $hash) {
                    $change_history = module_change_request::get_remaining_changes($website_id);
                    $step = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0;
                    // get the change details out
                    if ($change_request_id) {
                        $change_request = module_change_request::get_change_request_by_website($website_id, $change_request_id);
                    } else {
                        $change_request = array();
                    }
                    if (!$change_request) {
                        $change_request = array('change_request_id' => 0, 'name' => '', 'request' => '', 'attachments' => array());
                    }
                    switch ($type) {
                        case 'save':
                            // saving a change.
                            $data = $_POST;
                            $data['url'] = urldecode($data['url']);
                            $data['website_id'] = $website_id;
                            $data['change_request_id'] = $change_request['change_request_id'];
                            if (isset($_REQUEST['completed_test'])) {
                                if (!isset($_REQUEST['completed']) || !$_REQUEST['completed']) {
                                    $data['status'] = _CHANGE_REQUEST_STATUS_NEW;
                                    // not completed.
                                } else {
                                    $data['status'] = _CHANGE_REQUEST_STATUS_COMPLETE;
                                    // completed!
                                }
                            }
                            if (isset($_REQUEST['delete_request'])) {
                                $data['status'] = _CHANGE_REQUEST_STATUS_DELETE;
                                // deleted
                            }
                            $change_request_id = update_insert('change_request_id', $change_request['change_request_id'], 'change_request', $data);
                            // redirect to send email page if we're logged in
                            if (module_security::is_logged_in() && isset($_REQUEST['completed_send_email']) && $_REQUEST['completed_send_email'] && self::can_i('edit', 'Change Requests')) {
                                // don't do the template, do the redirect to the email page (todo!)
                                redirect_browser(self::link_open($change_request_id));
                            } else {
                                // send email to administrator (everyone with change request edit permissions?) about this change request.
                                $alert_users = module_user::get_users_by_permission(array('category' => 'Change Request', 'name' => 'Change Requests', 'module' => 'change_request', 'edit' => 1));
                                $email_data = get_single('change_request', 'change_request_id', $change_request_id);
                                $customer_data = $website_data = array();
                                if ($website_id) {
                                    $website_data = module_website::get_website($website_id);
                                    $email_data['website_name'] = $website_data['name'];
                                    $email_data['website_link'] = module_website::link_open($website_id, true);
                                    if ($website_data && $website_data['customer_id']) {
                                        $customer_data = module_customer::get_customer($website_data['customer_id'], true);
                                    }
                                }
                                if (isset($email_data['request'])) {
                                    $email_data['request'] = nl2br($email_data['request']);
                                    // for the plain text emails.
                                }
                                foreach ($alert_users as $alert_user) {
                                    // todo: make sure this staff member has access to this website?
                                    // nfi how to figure this out. maybe we just look for staff members who are assigned jobs/tasks against this website?
                                    $template = module_template::get_template_by_key('change_request_alert_email');
                                    $template->assign_values(array_merge($customer_data, $website_data, $email_data));
                                    $html = $template->render('html');
                                    // send an email to this user.
                                    $email = module_email::new_email();
                                    $email->replace_values = array_merge($customer_data, $website_data, $email_data);
                                    $email->set_to('user', $alert_user['user_id']);
                                    $email->set_from('user', module_security::get_loggedin_id() ? module_security::get_loggedin_id() : isset($customer_data['primary_user_id']) ? $customer_data['primary_user_id'] : 0);
                                    $email->set_subject($template->description);
                                    // do we send images inline?
                                    $email->set_html($html);
                                    if ($email->send()) {
                                        // it worked successfully!!
                                        // sweet.
                                    } else {
                                        /// log err?
                                        set_error(_l('Failed to send change notification email to User ID: %s Email: %s Status: %s Error: %s', $alert_user['user_id'], json_encode($email->to), $email->status, $email->error_text));
                                    }
                                }
                            }
                            // display thankyou template.
                            module_template::init_template('change_request_submitted', '<h2>Change Request</h2>
    <p>Thank you. Your change request has been submitted successfully.</p>
    <p>Please <a href="{URL}">click here</a> to continue.</p>
    ', 'Displayed after a change request is created/updated.', 'code');
                            // correct!
                            // load up the receipt template.
                            $template = module_template::get_template_by_key('change_request_submitted');
                            $template->page_title = _l("Change Request");
                            foreach ($data as $key => $val) {
                                if (!is_array($val)) {
                                    $data[$key] = htmlspecialchars($val);
                                }
                            }
                            $template->assign_values($data);
                            echo $template->render('pretty_html');
                            exit;
                            break;
                        case 'display_change':
                            ob_start();
                            ?>

                            <div class="title">
                                <?php 
                            _e('Change request');
                            ?>

                            </div>
                            <div class="content">
                                <p><?php 
                            echo nl2br(htmlspecialchars($change_request['request']));
                            ?>
</p>
                                <div class="wp3changerequest_actions">
                                    <p>
                                       <!-- <strong><?php 
                            _e('Attachments:');
                            ?>
</strong>
                                        <?php 
                            if (!$change_request['attachments']) {
                                ?>
 - none - <?php 
                            } else {
                                foreach ($change_request['attachments'] as $attachment) {
                                    ?>

                                            <a href="#"><?php 
                                    echo htmlspecialchars($attachment->name);
                                    ?>
</a>
                                            <?php 
                                }
                                ?>

                                        <?php 
                            }
                            ?>

                                        <br/>-->
                                        <strong><?php 
                            _e('Created by:');
                            ?>
</strong> <?php 
                            echo htmlspecialchars($change_request['name']);
                            ?>
 <br/>
                                        <strong><?php 
                            _e('Created on:');
                            ?>
</strong> <?php 
                            echo print_date($change_request['date_created'], true);
                            ?>

	                                    <?php 
                            if (isset($change_request['job_id']) && $change_request['job_id']) {
                                ?>
 <br/>
		                                    <strong><?php 
                                _e('Converted to job:');
                                ?>
</strong> <?php 
                                _e('This task has been converted to a Job');
                                ?>

	                                    <?php 
                            }
                            ?>

                                    </p>
                                    <?php 
                            if (!isset($change_request['job_id']) || !$change_request['job_id'] || self::can_i('edit', 'Change Requests')) {
                                ?>

                                    <p align="center">
                                        <input type="button" name="edit" value="<?php 
                                _e('Edit');
                                ?>
" class="wp3changerequest_button wp3changerequest_button_small"  onclick="dtbaker_changerequest.edit(<?php 
                                echo $change_request_id;
                                ?>
); return false;">
                                    </p>
	                                <?php 
                            }
                            ?>

                                </div>
                            </div>
                            <?php 
                            $change_request['html'] = preg_replace('/\\s+/', ' ', ob_get_clean());
                            //                                echo json_encode($change_request);
                            //                                exit;
                            @ob_end_clean();
                            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                            header("Cache-Control: no-cache");
                            header("Pragma: no-cache");
                            header("Content-type: text/javascript");
                            ?>


                            var t = dtbaker_changerequest;
                            var change_id = <?php 
                            echo $change_request_id;
                            ?>
;
                                var msg = <?php 
                            echo json_encode($change_request);
                            ?>
;

                            jQuery('body').prepend('<div class="wp3changerequest_change" id="dtbaker_change_'+change_id+'" style="'+((!t.show_postits) ? 'display:none;':'')+'"></div>');
                            var box = jQuery('#dtbaker_change_'+change_id);
                            box.html(msg.html);
                            if(msg.status == 0){
                                box.addClass('wp3changerequest_change_pending');
                            }else if(msg.status == 2){
                                box.addClass('wp3changerequest_change_complete');
                            }else if(msg.status == 3){
                                box.addClass('wp3changerequest_change_deleted');
                            }
                            box.css('top',msg.y+'px');
                            box.data('window_width',msg.window_width);
                            box.data('left',msg.x);
                            t.set_left(change_id);
                            with({i:change_id}){
                                jQuery(window).resize(function () {
                                    t.set_left(i);
                                });
                            }
                            box.data('original_height',box.height());
                            box.css('overflow','hidden');
                            jQuery('.title',box).slideUp();
                            box.stop(true, true).animate({
                                height: t.min_height,
                                width: t.min_width
                            },500);
                            box.hover(function(){
                                jQuery(this).addClass('wp3changerequest_change_active');
                                jQuery('.title',this).stop(true, true).slideDown();
                                jQuery(this).stop().animate({
                                    width: t.max_width,
                                    height: jQuery(this).data('original_height'),
                                    opacity: 1
                                },500);
                            },function(){
                                jQuery('.title',this).stop(true, true).slideUp();
                                jQuery(this).stop().animate({
                                    width: t.min_width,
                                    height: t.min_height,
                                    opacity: 0.7
                                },500,function(){
                                    jQuery(this).removeClass('wp3changerequest_change_active');
                                });
                            })


                                <?php 
                            break;
                        default:
                            @ob_end_clean();
                            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                            header("Cache-Control: no-cache");
                            header("Pragma: no-cache");
                            header("Content-type: text/javascript");
                            ob_start();
                            include 'pages/popup.php';
                            $html = ob_get_clean();
                            $html = addcslashes($html, "'");
                            $html = preg_replace('#\\r|\\n#', "' +\n'", $html);
                            // inject using javascript. fixes cross domain issues
                            ?>

                            if(!jQuery('#dtbaker_changerequest_inlinewizard').length){
                                // fix for jQuery 1.9+
                                jQuery('body').append('<div id="dtbaker_changerequest_inlinewizard" style="display:none;"></div>');
                            }
                            jQuery('#dtbaker_changerequest_inlinewizard').html('<?php 
                            echo $html;
                            ?>
');
                            <?php 
                    }
                }
                exit;
                break;
            case 'script':
                // load up the full script to be injected into our clients website.
                $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false;
                $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false;
                @ob_end_clean();
                header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                header("Cache-Control: no-cache");
                header("Pragma: no-cache");
                header("Content-type: text/javascript");
                if ($website_id && $hash && module_change_request::link_script($website_id, true) == $hash) {
                    include "js/client.js";
                    $client_url = isset($_REQUEST['url']) ? $_REQUEST['url'] : false;
                    if ($client_url) {
                        $change_requests = self::get_change_requests(array('website_id' => $website_id, 'url' => $client_url));
                        // todo - option this out incase url causes issues. ie: old js check method
                        ?>

                        jQuery(function(){
                            <?php 
                        foreach ($change_requests as $change_request) {
                            $displayed = false;
                            if ($change_request['status'] == _CHANGE_REQUEST_STATUS_NEW) {
                                $displayed = true;
                                ?>

                                    dtbaker_changerequest.display_change(<?php 
                                echo $change_request['change_request_id'];
                                ?>
);
                            <?php 
                            }
                            if (isset($_SESSION['_change_request_highlight']) && $_SESSION['_change_request_highlight'] == $change_request['change_request_id']) {
                                ?>

                                    <?php 
                                if (!$displayed) {
                                    ?>

                                    dtbaker_changerequest.display_change(<?php 
                                    echo $change_request['change_request_id'];
                                    ?>
);
                                    <?php 
                                }
                                ?>

                                    dtbaker_changerequest.highlight(<?php 
                                echo (int) $_SESSION['_change_request_highlight'];
                                ?>
);
                                    <?php 
                                unset($_SESSION['_change_request_highlight']);
                            }
                        }
                        ?>

                        });
                        <?php 
                    } else {
                        // not posting the URL, some setups do not like this
                        // get list of active change requests
                        $change_requests = self::get_change_requests(array('website_id' => $website_id, 'status' => _CHANGE_REQUEST_STATUS_NEW));
                        // we also do completed ones because the change request highlight countbe in there
                        $completed_change_requests = self::get_change_requests(array('website_id' => $website_id, 'status' => _CHANGE_REQUEST_STATUS_COMPLETE));
                        ?>


                        jQuery(function(){
                            var current_url = window.location.href;
                            <?php 
                        foreach ($change_requests as $change_request) {
                            ?>

                            if(current_url == '<?php 
                            echo addcslashes(htmlspecialchars($change_request['url']), "'");
                            ?>
'){
                                // todo: do this better!
                                dtbaker_changerequest.display_change(<?php 
                            echo $change_request['change_request_id'];
                            ?>
);
                            }
                            <?php 
                        }
                        ?>

                            <?php 
                        // todo: do we display all previous change requests on the page or not?
                        if (isset($_SESSION['_change_request_highlight']) && $_SESSION['_change_request_highlight']) {
                            echo '// Checking for request: ' . (int) $_SESSION['_change_request_highlight'];
                            foreach ($completed_change_requests as $complete_change_request) {
                                if ($complete_change_request['change_request_id'] == $_SESSION['_change_request_highlight']) {
                                    // show this completed one as well.
                                    ?>

                                        dtbaker_changerequest.display_change(<?php 
                                    echo $complete_change_request['change_request_id'];
                                    ?>
);
                                        <?php 
                                }
                            }
                            ?>

                            dtbaker_changerequest.highlight(<?php 
                            echo (int) $_SESSION['_change_request_highlight'];
                            ?>
);
                            <?php 
                            // todo: move this unset over to the "display_change" callback so we only remove the session when we know it has been displayed.
                            unset($_SESSION['_change_request_highlight']);
                        }
                        ?>

                        });
                        <?php 
                    }
                }
                exit;
                break;
            case 'public':
                $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false;
                $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false;
                if ($website_id && $hash && module_change_request::link_public($website_id, true) == $hash) {
                    // correct!
                    // redirect to website with our "change_request" url parameter, that is picked up by the included text.
                    $website = module_website::get_website($website_id);
                    $change_request_website = get_single('change_request_website', 'website_id', $website_id);
                    if ($change_request_website && $change_request_website['enabled']) {
                        $url = module_website::urlify($website['url']);
                        // todo - pass this to a (yet to be created) method in website that will deal with https:// or http:// based on user input. stop hardcoding http!
                        if (isset($_REQUEST['change_request_id'])) {
                            $selected_change_request = self::get_change_request_by_website($website_id, (int) $_REQUEST['change_request_id']);
                            if ($selected_change_request && $selected_change_request['url']) {
                                $url = $selected_change_request['url'];
                            }
                            //$url .= "&change_request_id=".(int)$_REQUEST['change_request_id'];
                            $_SESSION['_change_request_highlight'] = (int) $_REQUEST['change_request_id'];
                        }
                        $url = $url . (strpos($url, '?') === false ? '?' : '&') . 'change_request=' . self::link_script($website_id, true);
                        redirect_browser($url);
                    }
                }
                echo "Change request disabled.";
                break;
        }
    }
        $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!
                    $to_select = $contact['email'];
                }
            }
        }
        if (!$to_select && $customer['primary_user_id']) {
            $primary = module_user::get_user($customer['primary_user_id']);
            if ($primary) {
                $to_select = $primary['email'];
            }
        }
    }
} 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);
module_email::print_compose(array('title' => _l('Email Invoice: %s', $invoice['name']), 'find_other_templates' => 'invoice_email', 'current_template' => $template_name, 'customer_id' => $invoice['customer_id'], 'company_id' => isset($invoice['company_id']) ? $invoice['company_id'] : 0, 'to' => $to, 'to_select' => $to_select, 'bcc' => module_config::c('admin_email_address', ''), 'content' => $template->render('html'), 'subject' => $template->replace_description(), 'success_url' => module_invoice::link_open($invoice_id), 'success_callback' => 'module_invoice::email_sent', 'success_callback_args' => array('invoice_id' => $invoice_id, 'template_name' => $template_name), 'invoice_id' => $invoice_id, 'cancel_url' => module_invoice::link_open($invoice_id), 'attachments' => array(array('path' => $pdf, 'name' => basename($pdf), 'preview' => module_invoice::link_generate($invoice_id, array('arguments' => array('go' => 1, 'print' => 1), 'page' => 'invoice_admin', 'full' => false))))));
Example #21
0
 public static function quote_approved($quote_id)
 {
     module_cache::clear('quote');
     $quote_data = module_quote::get_quote($quote_id);
     hook_handle_callback('quote_approved', $quote_id);
     self::add_history($quote_id, 'Quote approved by ' . $quote_data['approved_by']);
     if (module_config::c('quote_approval_auto_email', 1) && $quote_data['user_id']) {
         // send an email to the assigned staff member letting them know the quote was approved.
         $template = module_template::get_template_by_key('quote_approved_email');
         $replace = module_quote::get_replace_fields($quote_id, $quote_data);
         if (defined('_BLOCK_EMAILS') && _BLOCK_EMAILS) {
             $pdf = false;
         } else {
             $pdf = module_quote::generate_pdf($quote_id);
         }
         $template->assign_values($replace);
         $html = $template->render('html');
         // send an email to this user.
         $email = module_email::new_email();
         $email->replace_values = $replace;
         $email->set_to('user', $quote_data['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);
         if ($pdf) {
             $email->add_attachment($pdf);
         }
         $email->quote_id = $quote_id;
         $email->customer_id = $quote_data['customer_id'];
         $email->prevent_duplicates = true;
         if ($email->send()) {
             // it worked successfully!!
             // record a log on the quote when it's done.
             self::add_history($quote_id, _l('Quote approval emailed to staff member'));
         } else {
             /// log err?
         }
     }
     module_cache::clear('quote');
 }
Example #22
0
 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);
         }
     }
 }
Example #23
0
 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;
 }
Example #24
0
include('quote_public.php');
$quote['quote_tasks'] = ob_get_clean();*/
// generate the PDF ready for sending.
$pdf = module_quote::generate_pdf($quote_id);
// find available "to" recipients.
// customer contacts.
$to_select = false;
if ($quote['customer_id']) {
    $customer = module_customer::get_customer($quote['customer_id']);
    $quote['customer_name'] = $customer['customer_name'];
    $to = module_user::get_contacts(array('customer_id' => $quote['customer_id']));
    if ($quote['contact_user_id']) {
        $primary = module_user::get_user($quote['contact_user_id']);
        if ($primary) {
            $to_select = $primary['email'];
        }
    } else {
        if ($customer['primary_user_id']) {
            $primary = module_user::get_user($customer['primary_user_id']);
            if ($primary) {
                $to_select = $primary['email'];
            }
        }
    }
} else {
    $to = array();
}
$template->assign_values($quote);
ob_start();
module_email::print_compose(array('title' => _l('Email Quote: %s', $quote['name']), 'find_other_templates' => 'quote_email', 'current_template' => $template_name, 'customer_id' => $quote['customer_id'], 'quote_id' => $quote['quote_id'], 'debug_message' => 'Sending quote as email', 'to' => $to, 'to_select' => $to_select, 'bcc' => module_config::c('admin_email_address', ''), 'content' => $template->render('html'), 'subject' => $template->replace_description(), 'success_url' => module_quote::link_open($quote_id), 'cancel_url' => module_quote::link_open($quote_id), 'attachments' => array(array('path' => $pdf, 'name' => basename($pdf), 'preview' => module_quote::link_public_print($quote_id)))));
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'])));