Beispiel #1
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 
    }
Beispiel #2
0
    // 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']])) {
                    $allocated_staff_members[$job_task['user_id']] = 0;
                }
                $allocated_staff_members[$job_task['user_id']]++;
            }
            foreach ($allocated_staff_members as $staff_id => $count) {
                $staff = module_user::get_user($staff_id);
                ?>

						    <a href="<?php 
This email is regarding your file <strong>{FILE_NAME}</strong>{if:JOB_LINK} related to the job <a href="{JOB_LINK}">{JOB_NAME}</a>{endif:JOB_LINK}.<br><br>
Please view this file and comments online by <a href="{FILE_URL}">clicking here</a>.<br><br>
Thank you,<br><br>
{FROM_NAME}
', 'File for Approval: {FILE_NAME}', array('CUSTOMER_NAME' => 'Customers Name', 'FILE_NAME' => 'File Name', 'JOB_NAME' => 'Job Name', 'FROM_NAME' => 'Your name', 'FILE_URL' => 'Link to file for customer'));
// template for sending emails.
// are we sending the paid one? or the dueone.
//$template_name = 'file_email';
$template_name = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : 'file_approval_email';
$template = module_template::get_template_by_key($template_name);
$file['from_name'] = module_security::get_loggedin_name();
$file['file_url'] = module_file::link_public($file_id);
if (class_exists('module_job', false) && $file['job_id']) {
    $job_data = module_job::get_job($file['job_id'], false);
    $file['job_name'] = htmlspecialchars($job_data['name']);
    $file['job_link'] = module_job::link_public($file['job_id']);
} else {
    $file['job_name'] = _l('N/A');
    $file['job_link'] = '';
}
// 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'];
            function customer_admin_email_generate_invoice_list($invoices, $customer_id)
            {
                ob_start();
                $colspan = 9;
                $colspan2 = 0;
                $invoice_total = array();
                $invoice_total_due = array();
                foreach ($invoices as $invoice) {
                    if (!isset($invoice_total[$invoice['currency_id']])) {
                        $invoice_total[$invoice['currency_id']] = 0;
                    }
                    if ($invoice['c_total_amount'] == 0) {
                        $invoice = module_invoice::get_invoice($invoice['invoice_id']);
                    }
                    $invoice_total[$invoice['currency_id']] += $invoice['c_total_amount'];
                    if (!isset($invoice_total_due[$invoice['currency_id']])) {
                        $invoice_total_due[$invoice['currency_id']] = 0;
                    }
                    $invoice_total_due[$invoice['currency_id']] += $invoice['c_total_amount_due'];
                }
                $table_manager = module_theme::new_table_manager();
                $columns = array();
                $columns['invoice_number'] = array('title' => 'Invoice Number', 'callback' => function ($invoice) {
                    //echo module_invoice::link_open($invoice['invoice_id'],true,$invoice);
                    echo '<a href="' . module_invoice::link_public($invoice['invoice_id']) . '">' . htmlspecialchars($invoice['name']) . '</a>';
                }, 'cell_class' => 'row_action');
                $columns['invoice_status'] = array('title' => 'Status', 'callback' => function ($invoice) {
                    echo htmlspecialchars($invoice['status']);
                });
                $columns['invoice_create_date'] = array('title' => 'Create Date', 'callback' => function ($invoice) {
                    if (!$invoice['date_create'] || $invoice['date_create'] == '0000-00-00') {
                        //echo print_date($invoice['date_created']);
                    } else {
                        echo print_date($invoice['date_create']);
                    }
                });
                $columns['invoice_due_date'] = array('title' => 'Due Date', 'callback' => function ($invoice) {
                    if ((!$invoice['date_paid'] || $invoice['date_paid'] == '0000-00-00') && strtotime($invoice['date_due']) < time()) {
                        echo '<span class="error_text">';
                        echo print_date($invoice['date_due']);
                        echo '</span>';
                    } else {
                        echo print_date($invoice['date_due']);
                    }
                });
                $columns['invoice_sent_date'] = array('title' => 'Sent Date', 'callback' => function ($invoice) {
                    if ($invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') {
                        ?>

				            <?php 
                        echo print_date($invoice['date_sent']);
                        ?>

				        <?php 
                    } else {
                        ?>

				            <span class="error_text"><?php 
                        _e('Not sent');
                        ?>
</span>
				        <?php 
                    }
                });
                $columns['invoice_paid_date'] = array('title' => 'Paid Date', 'callback' => function ($invoice) {
                    if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') {
                        ?>

				            <?php 
                        echo print_date($invoice['date_paid']);
                        ?>

				        <?php 
                    } else {
                        if ($invoice['date_cancel'] && $invoice['date_cancel'] != '0000-00-00') {
                            ?>

				            <span class="error_text"><?php 
                            _e('Cancelled');
                            ?>
</span>
				        <?php 
                        } else {
                            if ($invoice['overdue']) {
                                ?>

				            <span class="error_text" style="font-weight: bold; text-decoration: underline;"><?php 
                                _e('Overdue');
                                ?>
</span>
				        <?php 
                            } else {
                                ?>

				            <span class="error_text"><?php 
                                _e('Not paid');
                                ?>
</span>
				        <?php 
                            }
                        }
                    }
                });
                if (class_exists('module_website', false) && module_website::is_plugin_enabled() && module_website::can_i('view', module_config::c('project_name_plural', 'Websites'))) {
                    $colspan++;
                    $columns['invoice_website'] = array('title' => module_config::c('project_name_single', 'Website'), 'callback' => function ($invoice) {
                        if (isset($invoice['website_ids'])) {
                            foreach ($invoice['website_ids'] as $website_id) {
                                if ((int) $website_id > 0) {
                                    echo module_website::link_open($website_id, true);
                                    echo '<br/>';
                                }
                            }
                        }
                    });
                }
                $columns['invoice_job'] = array('title' => 'Job', 'callback' => function ($invoice) {
                    foreach ($invoice['job_ids'] as $job_id) {
                        if ((int) $job_id > 0) {
                            //echo module_job::link_open($job_id,true);
                            $job_data = module_job::get_job($job_id);
                            echo '<a href="' . module_job::link_public($job_id) . '">' . htmlspecialchars($job_data['name']) . '</a>';
                            if ($job_data['date_start'] && $job_data['date_start'] != '0000-00-00' && $job_data['date_renew'] && $job_data['date_renew'] != '0000-00-00') {
                                _e(' (%s to %s)', print_date($job_data['date_start']), print_date(strtotime("-1 day", strtotime($job_data['date_renew']))));
                            }
                            echo "<br/>\n";
                        }
                    }
                    hook_handle_callback('invoice_admin_list_job', $invoice['invoice_id']);
                });
                if (!isset($_REQUEST['customer_id']) && module_customer::can_i('view', 'Customers')) {
                    $colspan++;
                    $columns['invoice_customer'] = array('title' => 'Customer', 'callback' => function ($invoice) {
                        echo module_customer::link_open($invoice['customer_id'], true);
                    });
                }
                $columns['c_invoice_total'] = array('title' => 'Invoice Total', 'callback' => function ($invoice) {
                    echo dollar($invoice['total_amount'], true, $invoice['currency_id']);
                });
                $columns['c_invoice_total_due'] = array('title' => 'Amount Due', 'callback' => function ($invoice) {
                    echo dollar($invoice['total_amount_due'], true, $invoice['currency_id']);
                    ?>

				        <?php 
                    if ($invoice['total_amount_credit'] > 0) {
                        ?>

				        <span class="success_text"><?php 
                        echo _l('Credit: %s', dollar($invoice['total_amount_credit'], true, $invoice['currency_id']));
                        ?>
</span>
				            <?php 
                    }
                });
                if (class_exists('module_extra', false)) {
                    ob_start();
                    $colspan2 += module_extra::print_table_header('invoice');
                    // used in the footer calc.
                    ob_end_clean();
                    $table_manager->display_extra('invoice', function ($invoice) {
                        module_extra::print_table_data('invoice', $invoice['invoice_id']);
                    });
                }
                $table_manager->set_columns($columns);
                $table_manager->row_callback = function ($row_data) {
                    // load the full vendor data before displaying each row so we have access to more details
                    if (isset($row_data['invoice_id']) && (int) $row_data['invoice_id'] > 0) {
                        return module_invoice::get_invoice($row_data['invoice_id']);
                    }
                    return array();
                };
                $table_manager->set_rows($invoices);
                if (module_config::c('invoice_list_show_totals', 1)) {
                    $footer_rows = array();
                    foreach ($invoice_total + $invoice_total_due as $currency_id => $foo) {
                        $currency = get_single('currency', 'currency_id', $currency_id);
                        $footer_rows[] = array('invoice_number' => array('data' => '<strong>' . _l('%s Totals:', $currency && isset($currency['code']) ? $currency['code'] : '') . '</strong>', 'cell_colspan' => $colspan - 2, 'cell_class' => 'text-right'), 'c_invoice_total' => array('data' => '<strong>' . dollar(isset($invoice_total[$currency_id]) ? $invoice_total[$currency_id] : 0, true, $currency_id) . '</strong>'), 'c_invoice_total_due' => array('data' => '<strong>' . dollar(isset($invoice_total_due[$currency_id]) ? $invoice_total_due[$currency_id] : 0, true, $currency_id) . '</strong>'), 'row_bulk_action' => array('data' => ' ', 'cell_colspan' => $colspan2));
                    }
                    $table_manager->set_footer_rows($footer_rows);
                }
                $table_manager->pagination = false;
                $table_manager->print_table();
                return ob_get_clean();
            }
Beispiel #5
0
Please find below details on your job request: {JOB_NAME}.<br><br>
You can also view this job online by <a href="{JOB_URL}">clicking here</a>.<br><br>
{JOB_TASKS}<br><br>
Thank you,<br><br>
{FROM_NAME}
', 'Job: {JOB_NAME}', array('CUSTOMER_NAME' => 'Customers Name', 'JOB_NAME' => 'Job Name', 'TOTAL_AMOUNT' => 'Total amount of job', 'TOTAL_AMOUNT_DUE' => 'Total amount of job remaining to be paid', 'FROM_NAME' => 'Your name', 'JOB_URL' => 'Link to job for customer', 'JOB_TASKS' => 'Output of job tasks similar to public link'));
// template for sending emails.
// are we sending the paid one? or the dueone.
//$template_name = 'job_email';
$template_name = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : 'job_email';
$template = module_template::get_template_by_key($template_name);
$job['total_amount_print'] = dollar($job['total_amount'], true, $job['currency_id']);
$job['total_amount_due_print'] = dollar($job['total_amount_due'], true, $job['currency_id']);
$job['job_name'] = $job['name'];
$job['from_name'] = module_security::get_loggedin_name();
$job['job_url'] = module_job::link_public($job_id);
ob_start();
$job_data = $job;
$ignore_task_hook = true;
$for_email = true;
include 'job_public.php';
$job['job_tasks'] = ob_get_clean();
// find available "to" recipients.
// customer contacts.
$to_select = false;
if ($job['customer_id']) {
    $customer = module_customer::get_customer($job['customer_id']);
    $job['customer_name'] = $customer['customer_name'];
    $to = module_user::get_contacts(array('customer_id' => $job['customer_id']));
    if ($customer['primary_user_id']) {
        $primary = module_user::get_user($customer['primary_user_id']);
Beispiel #6
0
echo _l('Advanced');
?>
</h3>
                    <table border="0" cellspacing="0" cellpadding="2" class="tableclass tableclass_form tableclass_full">
						<tbody>

                            <tr>
                                <th class="width1">
                                    <?php 
_e('Customer Link');
?>

                                </th>
                                <td>
                                    <a href="<?php 
echo module_job::link_public($job_id);
?>
" target="_blank"><?php 
echo _l('Click to view external link');
?>
</a>
                                    <?php 
_h('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.');
?>

                                </td>
                            </tr>
                            <?php 
if ((int) $job_id > 0 && module_job::can_i('edit', 'Jobs')) {
    ?>