예제 #1
0
 public static function send_autoreply($ticket_id)
 {
     if (!module_config::c('ticket_autoreply_enabled', 1, array('plugin' => 'ticket', 'description' => 'Should autoreplies be sent to ticket messages?', 'type' => 'select', 'options' => get_yes_no(), 'default' => 1))) {
         return;
     }
     // send back an auto responder letting them know where they are in the queue.
     $ticket_data = self::get_ticket($ticket_id);
     $template = module_template::get_template_by_key('ticket_autoreply');
     $auto_reply_message = $template->content;
     $from_user_id = $ticket_data['assigned_user_id'] ? $ticket_data['assigned_user_id'] : module_config::c('ticket_default_user_id', 1);
     //if($ticket_data['user_id'] != $from_user_id){
     // check if we have sent an autoreply to this address in the past 5 minutes, if we have we dont send another one.
     // this stops autoresponder spam messages.
     $time = time() - 300;
     // 5 mins
     $sql = "SELECT * FROM `" . _DB_PREFIX . "ticket_message` tm WHERE to_user_id = '" . (int) $ticket_data['user_id'] . "' AND message_time > '" . $time . "' AND ( `cache` = 'autoreply' OR `message_type_id` = " . _TICKET_MESSAGE_TYPE_AUTOREPLY . " )";
     $res = qa($sql);
     if (!count($res)) {
         $send_autoreply = true;
         // other logic to check here???
         // see if this user has any 'ticket settings' extra fields, if we find a 'no_autoreply' value in here we don't send it.
         if (class_exists('module_extra', false)) {
             $extra_fields = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $ticket_data['user_id']));
             foreach ($extra_fields as $extra_field) {
                 if (stripos($extra_field['extra_key'], 'ticket settings') !== false) {
                     if (stripos($extra_field['extra'], 'no_autoreply') !== false) {
                         $send_autoreply = false;
                         break;
                     }
                 }
             }
         }
         if ($send_autoreply) {
             self::send_reply($ticket_id, $auto_reply_message, $from_user_id, $ticket_data['user_id'], 'admin', 'autoreply');
         }
     }
     //}
 }
예제 #2
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;
     }
 }
         <td align="center">
             <a href="{ITEM_PAYMENT_RECEIPT_URL}" target="_blank">{l:View Receipt}</a>
         </td>
     </tr>
 </table>
 <?php 
 module_template::init_template('invoice_payment_history_basic', ob_get_clean(), 'Used when displaying the invoice payment history in the basic invoice template.', 'code');
 $t = false;
 if (isset($invoice_template_suffix) && strlen($invoice_template_suffix) > 0) {
     $t = module_template::get_template_by_key('invoice_payment_history' . $invoice_template_suffix);
     if (!$t->template_id) {
         $t = false;
     }
 }
 if (!$t) {
     $t = module_template::get_template_by_key('invoice_payment_history');
 }
 $replace = array();
 if (!isset($mode) || $mode == 'html') {
     $replace['title'] = '<h3>' . _l('Payment History:') . '</h3>';
 } else {
     $replace['title'] = '<strong>' . _l('Payment History:') . '</strong><br/>';
 }
 if (preg_match('#<tr[^>]+data-item-row="true">.*</tr>#imsU', $t->content, $matches)) {
     $item_row_html = $matches[0];
     $t->content = str_replace($item_row_html, '{ITEM_ROW_CONTENT}', $t->content);
 } else {
     set_error('Please ensure a TR with data-item-row="true" is in the invoice_payment_history template');
     $item_row_html = '';
 }
 $all_item_row_html = '';
예제 #4
0
 public static function start_payment($invoice_id, $payment_amount, $invoice_payment_id, $user_id = false)
 {
     if ($invoice_id && $payment_amount && $invoice_payment_id) {
         // we are starting a payment via coinbase!
         // setup a pending payment and redirect to coinbase.
         $invoice_data = module_invoice::get_invoice($invoice_id);
         if (!$user_id) {
             $user_id = $invoice_data['user_id'];
         }
         if (!$user_id) {
             $user_id = isset($invoice_data['primary_user_id']) ? $invoice_data['primary_user_id'] : 0;
         }
         if (!$user_id) {
             $user_id = module_security::get_loggedin_id();
         }
         $user_data = module_user::get_user($user_id);
         if (!$user_data || !strpos($user_data['email'], '@')) {
             die('Please ensure your user account has a valid email address before paying with coinbase');
         }
         $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id);
         // we add the fee details to the invoice payment record so that the new invoice total can be calculated.
         $fee_percent = module_config::c('payment_method_coinbase_charge_percent', 0);
         $fee_amount = module_config::c('payment_method_coinbase_charge_amount', 0);
         $fee_description = module_config::c('payment_method_coinbase_charge_description', 'Coinbase Fee');
         $fee_total = 0;
         if ($fee_percent != 0 || $fee_amount != 0) {
             $fee_total = module_invoice::calculate_fee($invoice_id, $invoice_data, $payment_amount, array('percent' => $fee_percent, 'amount' => $fee_amount, 'description' => $fee_description));
             if ($fee_total != 0) {
                 // add this percent/amount to the invoice payment
                 $payment_amount = $payment_amount + $fee_total;
                 update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('fee_percent' => $fee_percent, 'fee_amount' => $fee_amount, 'fee_description' => $fee_description, 'fee_total' => $fee_total, 'amount' => $payment_amount));
             }
         }
         // we check if this payment is a recurring payment or a standard one off payment.
         if (module_config::c('payment_method_coinbase_subscriptions', 0)) {
             // we support subscriptions!
             // first check if the subscription module is active, and if this invoice is part of an active subscription.
             $is_subscription = false;
             if (class_exists('module_subscription', false)) {
                 $subscription_history = get_single('subscription_history', 'invoice_id', $invoice_id);
                 if ($subscription_history && $subscription_history['subscription_id']) {
                     // this invoice is for a subscription! woo!
                     // work out when we should bill for this subscription.
                     $subscription = module_subscription::get_subscription($subscription_history['subscription_id']);
                     $subscription_owner = module_subscription::get_subscription_owner($subscription_history['subscription_owner_id']);
                     if ($subscription_owner['owner_table'] && $subscription_owner['owner_id']) {
                         // work out when the next invoice will be generated for this subscription.
                         $members_subscriptions = module_subscription::get_subscriptions_by($subscription_owner['owner_table'], $subscription_owner['owner_id']);
                         if (isset($members_subscriptions[$subscription_history['subscription_id']])) {
                             $member_subscription = $members_subscriptions[$subscription_history['subscription_id']];
                             // everything checks out! good to go....
                             // for now we just do a basic "EVERY X TIME" subscription
                             // todo: work out how long until next generate date, and set that (possibly smaller) time period as the first portion of the subscription
                             /*echo '<pre>';
                               print_r($subscription_history);
                               print_r($subscription);
                               print_r($subscription_owner);
                               print_r($member_subscription);
                               exit;*/
                             $is_subscription = array();
                             if ($subscription['days'] > 0) {
                                 $is_subscription['days'] = $subscription['days'];
                             }
                             if ($subscription['months'] > 0) {
                                 $is_subscription['months'] = $subscription['months'];
                             }
                             if ($subscription['years'] > 0) {
                                 $is_subscription['years'] = $subscription['years'];
                             }
                             if (count($is_subscription)) {
                                 $is_subscription['name'] = $subscription['name'];
                                 $is_subscription['id'] = $subscription_history['subscription_id'];
                             }
                         }
                     }
                 }
             }
             // todo: check if this invoice has a manual renewal date, perform subscription feature as above.
             if ($is_subscription) {
                 // coinbase only supports these recurring methods:
                 // daily, weekly, every_two_weeks, monthly, quarterly, and yearly
                 // work out which one our days are at.
                 $days = isset($is_subscription['days']) ? $is_subscription['days'] : 0;
                 if (isset($is_subscription['months'])) {
                     $days += $is_subscription['months'] * 30;
                     unset($is_subscription['months']);
                 }
                 if (isset($is_subscription['years'])) {
                     $days += $is_subscription['years'] * 365;
                     unset($is_subscription['years']);
                 }
                 $is_subscription['days'] = $days;
                 if ($days == 1) {
                     $is_subscription['coinbase_period'] = 'daily';
                 } else {
                     if ($days == 7 || $days == 6 || $days == 8) {
                         $is_subscription['coinbase_period'] = 'weekly';
                     } else {
                         if ($days == 14 || $days == 13 || $days == 15) {
                             $is_subscription['coinbase_period'] = 'every_two_weeks';
                         } else {
                             if ($days == 29 || $days == 30 || $days == 31) {
                                 $is_subscription['coinbase_period'] = 'monthly';
                             } else {
                                 if ($days >= 87 && $days <= 95) {
                                     $is_subscription['coinbase_period'] = 'quarterly';
                                 } else {
                                     if ($days >= 363 && $days <= 370) {
                                         $is_subscription['coinbase_period'] = 'yearly';
                                     } else {
                                         send_error('Someone tried to pay with coinbase but coinbase does not support a recurring subscription period of ' . $days . ' days. Only:  daily, weekly, every_two_weeks, monthly, quarterly, and yearly ');
                                         $is_subscription = false;
                                         // not supported.
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($is_subscription && isset($is_subscription['coinbase_period'])) {
                 $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id);
                 if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) {
                     // existing subscription already!
                     // not really sure what to do here, just redirect to coinbase as if the user is doing it for the first time.
                     $_REQUEST['payment_subscription'] = true;
                     // hacks!
                 }
                 if (isset($_REQUEST['payment_subscription']) || module_config::c('payment_method_coinbase_force_subscription', 0)) {
                     // user is setting up a subscription! yes!!
                     // we create an entry in our database for this particular subscription
                     // or if one exists for this payment already then we just continue with that (ie: the user is going in again to redo it)
                     // setup a new subscription in the database for us.
                     if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) {
                         $invoice_payment_subscription_id = $invoice_payment_data['invoice_payment_subscription_id'];
                     } else {
                         $invoice_payment_subscription_id = update_insert('invoice_payment_subscription_id', false, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_PENDING, 'days' => isset($is_subscription['days']) ? $is_subscription['days'] : 0, 'months' => isset($is_subscription['months']) ? $is_subscription['months'] : 0, 'years' => isset($is_subscription['years']) ? $is_subscription['years'] : 0, 'date_start' => '0000-00-00', 'date_last_pay' => '0000-00-00', 'date_next' => '0000-00-00'));
                         update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('invoice_payment_subscription_id' => $invoice_payment_subscription_id));
                     }
                     $description = _l('Recurring payment for %s %s', $is_subscription['name'], _l(str_replace('_', ' ', $is_subscription['coinbase_period'])));
                     $subscription_name = $is_subscription['name'];
                     unset($is_subscription['name']);
                     // so reset/key cals below rosk.
                     $subscription_id = $is_subscription['id'];
                     unset($is_subscription['id']);
                     // so reset/key cals below rosk.
                     $currency = module_config::get_currency($invoice_payment_data['currency_id']);
                     $currency_code = $currency['code'];
                     include module_theme::include_ucm('includes/plugin_paymethod_coinbase/pages/coinbase_form.php');
                     exit;
                 } else {
                     if (isset($_REQUEST['payment_single'])) {
                         // use is choosing to continue payment as a once off amount
                     } else {
                         // give the user an option
                         $template = module_template::get_template_by_key('invoice_payment_subscription');
                         $template->page_title = htmlspecialchars($invoice_data['name']);
                         $template->assign_values($invoice_payment_data);
                         $template->assign_values(module_invoice::get_replace_fields($invoice_data['invoice_id'], $invoice_data));
                         $template->assign_values(array('invoice_payment_id' => $invoice_payment_id, 'payment_url' => module_invoice::link_public_pay($invoice_data['invoice_id']), 'payment_method' => 'paymethod_coinbase', 'payment_amount' => $payment_amount, 'pretty_payment_amount' => dollar($payment_amount, true, $invoice_data['currency_id']), 'subscription_period' => _l('%s days (%s)', $is_subscription['days'], $is_subscription['coinbase_period']), 'fee_amount' => dollar($fee_amount, true, $invoice_data['currency_id']), 'fee_total' => dollar($fee_total, true, $invoice_data['currency_id']), 'fee_percent' => $fee_percent, 'fee_description' => $fee_description));
                         echo $template->render('pretty_html');
                         exit;
                     }
                 }
             }
         }
         $description = _l('Payment for invoice %s', $invoice_data['name']);
         //self::coinbase_redirect($description,$payment_amount,$user_id,$invoice_payment_id,$invoice_id,$invoice_payment_data['currency_id']);
         $currency = module_config::get_currency($invoice_payment_data['currency_id']);
         $currency_code = $currency['code'];
         include module_theme::include_ucm('includes/plugin_paymethod_coinbase/pages/coinbase_form.php');
         /*$template = new module_template();
           ob_start();
           $template->content = ob_get_clean();
           echo $template->render('pretty_html');*/
         exit;
     }
     return false;
 }
예제 #5
0
 foreach ($data_field_groups as $data_field_group) {
     $data_field_group_id = $data_field_group['data_field_group_id'];
     $data_field_group = $module->get_data_field_group($data_field_group_id);
     $data_fields = $module->get_data_fields($data_field_group_id);
     foreach ($data_fields as $data_field) {
         $data_field_id = $data_field['data_field_id'];
         if (isset($data_items[$data_field_id])) {
             $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());
     }
 }
 ob_end_clean();
 ob_start();
 $template = module_template::get_template_by_key($data_type['print_pdf_template']);
 if (!$template || $template->template_key != $data_type['print_pdf_template']) {
     echo "PDF template " . $data_type['print_pdf_template'] . " not found";
 } else {
     $template->assign_values($replace);
     echo $template->render('html');
 }
 $html_output = ob_get_clean();
 $pdf_name = basename(preg_replace('#[^a-zA-Z0-9_]#', '_', $data_type['data_type_name']));
 $html_file_name = _UCM_FOLDER . 'temp/data_' . $pdf_name . '.html';
 $pdf_file_name = _UCM_FOLDER . 'temp/data_' . $pdf_name . '.pdf';
 file_put_contents($html_file_name, $html_output);
 $pdf_file = convert_html2pdf($html_file_name, $pdf_file_name);
 @ob_end_clean();
 @ob_end_clean();
 // send pdf headers and prompt the user to download the PDF
예제 #6
0
 public static function hook_filter_var_invoice_email_template($callback, $template_name, $invoice_id, $invoice_data)
 {
     // we check if this invoice is part of a subscription
     if ($template_name) {
         $number_of_past_invoices = 0;
         $subscription_history_item = get_single('subscription_history', 'invoice_id', $invoice_id);
         if ($subscription_history_item && $subscription_history_item['subscription_owner_id']) {
             // we have an invoice that is on a subscription!
             $subscription_owner = module_subscription::get_subscription_owner($subscription_history_item['subscription_owner_id']);
             // check if there are unpaid invoices that were generated after this invoice.
             if ($subscription_owner['subscription_owner_id'] == $subscription_history_item['subscription_owner_id']) {
                 $history = get_multiple('subscription_history', array('subscription_owner_id' => $subscription_owner['subscription_owner_id']));
                 foreach ($history as $h) {
                     if (!$h['invoice_id']) {
                     } else {
                         $invoice_data = module_invoice::get_invoice($h['invoice_id']);
                         if ($invoice_data['date_cancel'] != '0000-00-00') {
                             continue;
                         }
                         $number_of_past_invoices++;
                     }
                 }
             }
             $template_test = module_template::get_template_by_key($template_name . '_' . $number_of_past_invoices);
             if ($template_test->template_id > 0) {
                 return $template_test->template_key;
             }
         }
     }
     return $template_name;
 }
예제 #7
0
        }
    }
} else {
    // show normal unsubscribe form. asking for their email address.
    if (isset($_REQUEST['email']) && trim($_REQUEST['email'])) {
        $email = htmlspecialchars(strtolower(trim($_REQUEST['email'])));
        if (!module_newsletter::unsubscribe_member_via_email($email)) {
            echo 'Unsubscribe failed... Please enter a valid email address.';
            exit;
        }
        // is the newsletter module giving us a subscription redirection?
        if (module_config::c('newsletter_unsubscribe_redirect', '')) {
            redirect_browser(module_config::c('newsletter_unsubscribe_redirect', ''));
        }
        // or display a message.
        $template = module_template::get_template_by_key('newsletter_unsubscribe_done');
        $data['email'] = $email;
        $template->page_title = htmlspecialchars(_l('Unsubscribe'));
        $template->assign_values($data);
        echo $template->render('pretty_html');
        exit;
    }
    $template = module_template::get_template_by_key('newsletter_unsubscribe');
    $data['email'] = '';
    // to be sure to be sure
    $template->page_title = htmlspecialchars(_l('Unsubscribe'));
    $template->assign_values($data);
    echo $template->render('pretty_html');
    exit;
}
// show different templates.
예제 #8
0
        <td></td>
        <td></td>
    </tr>
    {INVOICE_SUMMARY}
</table>
<?php 
module_template::init_template('invoice_task_list_basic', ob_get_clean(), 'Used when displaying the invoice tasks when invoice_print_basic template is used.', 'code');
$t = false;
if (isset($invoice_template_suffix) && strlen($invoice_template_suffix) > 0) {
    $t = module_template::get_template_by_key('invoice_task_list' . $invoice_template_suffix);
    if (!$t->template_id) {
        $t = false;
    }
}
if (!$t) {
    $t = module_template::get_template_by_key('invoice_task_list');
}
$replace = array();
if ($invoice['default_task_type'] == _TASK_TYPE_AMOUNT_ONLY) {
    $replace['title_qty_or_hours'] = '';
} else {
    if ($invoice['default_task_type'] == _TASK_TYPE_QTY_AMOUNT) {
        $replace['title_qty_or_hours'] = _l(module_config::c('task_qty_name', 'Qty'));
    } else {
        if ($invoice['default_task_type'] == _TASK_TYPE_HOURS_AMOUNT) {
            $replace['title_qty_or_hours'] = _l(module_config::c('task_hours_name', 'Hours'));
        }
    }
}
if ($invoice['default_task_type'] == _TASK_TYPE_AMOUNT_ONLY) {
    $replace['title_amount_or_rate'] = _l(module_config::c('invoice_amount_name', 'Amount'));
예제 #9
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;
     }
 }
예제 #10
0
 public static function banktransfer_redirect($description, $amount, $user_id, $payment_id, $invoice_id)
 {
     $invoice_data = module_invoice::get_invoice($invoice_id);
     $invoice_replace = module_invoice::get_replace_fields($invoice_id, $invoice_data);
     $bank_details = module_template::get_template_by_key('paymethod_banktransfer_details');
     $bank_details->assign_values($invoice_data + array('amount' => dollar($amount, true, $invoice_data['currency_id'])));
     $bank_details->assign_values($invoice_replace);
     $bank_details_html = $bank_details->render('html');
     // display a template with the bank details in it.
     $template = module_template::get_template_by_key('paymethod_banktransfer');
     $template->assign_values(array('bank_details' => $bank_details_html, 'link' => module_invoice::link_open($invoice_id)));
     $template->assign_values($invoice_replace);
     echo $template->render('pretty_html');
     exit;
 }
예제 #11
0
    $email = false;
}
if (!$email_id) {
    // creating a new email
    $can_edit_emails = true;
} else {
    $can_edit_emails = false;
    // don't want to edit existing email
}
$current_template = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : 'email_template_blank';
$find_other_templates = 'email_template_';
$to = module_user::get_contacts(array('customer_id' => $customer_id));
$bcc = module_config::c('admin_email_address', '');
$headers = @unserialize($email['headers']);
if ($current_template && !$email_id) {
    $template = module_template::get_template_by_key($current_template);
    //todo: replace fields.
    //$replace = module_invoice::get_replace_fields($invoice_id,$invoice);
    if ($email['customer_id']) {
        $customer_data = module_customer::get_customer($email['customer_id']);
        $replace = module_customer::get_replace_fields($email['customer_id'], false, $customer_data);
        $template->assign_values($replace);
    }
    if ($email['job_id']) {
        $job_data = module_job::get_job($email['job_id']);
        $replace = module_job::get_replace_fields($email['job_id'], $job_data);
        $template->assign_values($replace);
    }
    if ($email['website_id']) {
        $website_data = module_website::get_website($email['website_id']);
        $replace = module_website::get_replace_fields($email['website_id'], $website_data);
예제 #12
0
    public static function start_payment($invoice_id, $payment_amount, $invoice_payment_id, $user_id = false)
    {
        if ($invoice_id && $payment_amount && $invoice_payment_id) {
            // we are starting a payment via stripe!
            // setup a pending payment and redirect to stripe.
            $invoice_data = module_invoice::get_invoice($invoice_id);
            if (!$user_id) {
                $user_id = $invoice_data['user_id'];
            }
            if (!$user_id) {
                $user_id = isset($invoice_data['primary_user_id']) ? $invoice_data['primary_user_id'] : 0;
            }
            if (!$user_id) {
                $user_id = module_security::get_loggedin_id();
            }
            $user_data = module_user::get_user($user_id);
            if (!$user_data || !strpos($user_data['email'], '@')) {
                die('Please ensure your user account has a valid email address before paying with stripe');
            }
            $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id);
            // we add the fee details to the invoice payment record so that the new invoice total can be calculated.
            $fee_percent = module_config::c('payment_method_stripe_charge_percent', 0);
            $fee_amount = module_config::c('payment_method_stripe_charge_amount', 0);
            $fee_description = module_config::c('payment_method_stripe_charge_description', 'Stripe Fee');
            $fee_total = 0;
            if ($fee_percent != 0 || $fee_amount != 0) {
                $fee_total = module_invoice::calculate_fee($invoice_id, $invoice_data, $payment_amount, array('percent' => $fee_percent, 'amount' => $fee_amount, 'description' => $fee_description));
                if ($fee_total != 0) {
                    // add this percent/amount to the invoice payment
                    $payment_amount = $payment_amount + $fee_total;
                    update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('fee_percent' => $fee_percent, 'fee_amount' => $fee_amount, 'fee_description' => $fee_description, 'fee_total' => $fee_total, 'amount' => $payment_amount));
                }
            }
            // we check if this payment is a recurring payment or a standard one off payment.
            if (module_config::c('payment_method_stripe_subscriptions', 0)) {
                // we support subscriptions!
                // first check if the subscription module is active, and if this invoice is part of an active subscription.
                $is_subscription = false;
                if (class_exists('module_subscription', false)) {
                    $subscription_history = get_single('subscription_history', 'invoice_id', $invoice_id);
                    if ($subscription_history && $subscription_history['subscription_id']) {
                        // this invoice is for a subscription! woo!
                        // work out when we should bill for this subscription.
                        $subscription = module_subscription::get_subscription($subscription_history['subscription_id']);
                        $subscription_owner = module_subscription::get_subscription_owner($subscription_history['subscription_owner_id']);
                        if ($subscription_owner['owner_table'] && $subscription_owner['owner_id']) {
                            // work out when the next invoice will be generated for this subscription.
                            $members_subscriptions = module_subscription::get_subscriptions_by($subscription_owner['owner_table'], $subscription_owner['owner_id']);
                            if (isset($members_subscriptions[$subscription_history['subscription_id']])) {
                                $member_subscription = $members_subscriptions[$subscription_history['subscription_id']];
                                // everything checks out! good to go....
                                // for now we just do a basic "EVERY X TIME" subscription
                                // todo: work out how long until next generate date, and set that (possibly smaller) time period as the first portion of the subscription
                                /*echo '<pre>';
                                  print_r($subscription_history);
                                  print_r($subscription);
                                  print_r($subscription_owner);
                                  print_r($member_subscription);
                                  exit;*/
                                $is_subscription = array();
                                if ($subscription['days'] > 0) {
                                    $is_subscription['days'] = $subscription['days'];
                                }
                                if ($subscription['months'] > 0) {
                                    $is_subscription['months'] = $subscription['months'];
                                }
                                if ($subscription['years'] > 0) {
                                    $is_subscription['years'] = $subscription['years'];
                                }
                                if (count($is_subscription)) {
                                    $is_subscription['name'] = $subscription['name'];
                                    $is_subscription['id'] = $subscription_history['subscription_id'];
                                }
                            }
                        }
                    }
                }
                // todo: check if this invoice has a manual renewal date, perform subscription feature as above.
                if ($is_subscription) {
                    $bits = array();
                    if (isset($is_subscription['days']) && $is_subscription['days'] > 0) {
                        $bits[] = _l('%s days', $is_subscription['days']);
                    }
                    if (isset($is_subscription['months']) && $is_subscription['months'] > 0) {
                        $bits[] = _l('%s months', $is_subscription['months']);
                    }
                    if (isset($is_subscription['years']) && $is_subscription['years'] > 0) {
                        $bits[] = _l('%s years', $is_subscription['years']);
                    }
                    $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id);
                    if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) {
                        // existing subscription already!
                        // not really sure what to do here, just redirect to stripe as if the user is doing it for the first time.
                        $_REQUEST['payment_subscription'] = true;
                        // hacks!
                    }
                    if (isset($_REQUEST['payment_subscription']) || module_config::c('payment_method_stripe_force_subscription', 0)) {
                        // user is setting up a subscription! yes!!
                        // we create an entry in our database for this particular subscription
                        // or if one exists for this payment already then we just continue with that (ie: the user is going in again to redo it)
                        // setup a new subscription in the database for us.
                        if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) {
                            $invoice_payment_subscription_id = $invoice_payment_data['invoice_payment_subscription_id'];
                        } else {
                            $invoice_payment_subscription_id = update_insert('invoice_payment_subscription_id', false, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_PENDING, 'days' => isset($is_subscription['days']) ? $is_subscription['days'] : 0, 'months' => isset($is_subscription['months']) ? $is_subscription['months'] : 0, 'years' => isset($is_subscription['years']) ? $is_subscription['years'] : 0, 'date_start' => '0000-00-00', 'date_last_pay' => '0000-00-00', 'date_next' => '0000-00-00'));
                            update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('invoice_payment_subscription_id' => $invoice_payment_subscription_id));
                        }
                        $description = _l('Recurring payment for %s every %s', $is_subscription['name'], implode(', ', $bits));
                        $subscription_name = $is_subscription['name'];
                        unset($is_subscription['name']);
                        // so reset/key cals below rosk.
                        $subscription_id = $is_subscription['id'];
                        unset($is_subscription['id']);
                        // so reset/key cals below rosk.
                        $currency = module_config::get_currency($invoice_payment_data['currency_id']);
                        // if there are more than 1 recurring amounts then we convert it to weeks, as stripe only supports one time period.
                        if (count($is_subscription) > 1) {
                            $days = isset($is_subscription['days']) ? $is_subscription['days'] : 0;
                            if (isset($is_subscription['months'])) {
                                $days += $is_subscription['months'] * 30;
                                unset($is_subscription['months']);
                            }
                            if (isset($is_subscription['years'])) {
                                $days += $is_subscription['years'] * 365;
                                unset($is_subscription['years']);
                            }
                            $is_subscription['days'] = $days;
                        }
                        reset($is_subscription);
                        $time = key($is_subscription);
                        if ($time == 'days') {
                            // convert days to weeks
                            //$time = 'week';
                            $time = 'day';
                            $period = $is_subscription['days'];
                            //$period = max(1,floor($is_subscription['days'] / 7));
                        } else {
                            if ($time == 'months') {
                                $time = 'month';
                                $period = $is_subscription['months'];
                            } else {
                                if ($time == 'years') {
                                    $time = 'year';
                                    $period = $is_subscription['years'];
                                } else {
                                    die('Failed to create subscription, invalid settings');
                                }
                            }
                        }
                        $stripe_amount = $payment_amount * 100;
                        ini_set('display_errors', true);
                        ini_set('error_reporting', E_ALL);
                        // create or retrieve this subscription.
                        require_once 'includes/plugin_paymethod_stripe/stripe-php/lib/Stripe.php';
                        $stripe = array("secret_key" => module_config::c('payment_method_stripe_secret_key'), "publishable_key" => module_config::c('payment_method_stripe_publishable_key'));
                        Stripe::setApiKey($stripe['secret_key']);
                        $stripe_plan_id = 'sub_' . $subscription_id;
                        $stripe_plan = false;
                        if ($stripe_plan_id) {
                            // get this plan from stripe, and check it's still valid:
                            try {
                                $stripe_plan = Stripe_Plan::retrieve($stripe_plan_id);
                            } catch (Exception $e) {
                                //print_r($e);
                            }
                            if ($stripe_plan && $stripe_plan->interval == $time && $stripe_plan->interval_count == $period && $stripe_plan->amount == $stripe_amount) {
                                // still have a valid plan! yes!
                            } else {
                                // plan no longer exists or has changed
                                $stripe_plan = false;
                            }
                        }
                        if (!$stripe_plan) {
                            try {
                                $settings = array("amount" => $stripe_amount, "interval" => $time, 'interval_count' => $period, "name" => $subscription_name, "currency" => $currency['code'], "id" => $stripe_plan_id, 'metadata' => array('subscription_id' => $subscription_id));
                                $stripe_plan = Stripe_Plan::create($settings);
                            } catch (Exception $e) {
                                //print_r($e);
                            }
                            //                            print_r($stripe_plan);
                        }
                        if ($stripe_plan) {
                            // right to go!
                            // display the stripe payment form (same as stripe_form.php, just we do a subscription rather than once off payment)
                            //self::stripe_redirect($description,$payment_amount,$user_id,$invoice_payment_id,$invoice_id,$invoice_payment_data['currency_id']);
                            $currency = module_config::get_currency($invoice_payment_data['currency_id']);
                            $currency_code = $currency['code'];
                            $template = new module_template();
                            ob_start();
                            ?>
                                <h1><?php 
                            echo htmlspecialchars($description);
                            ?>
</h1>
                                <form action="<?php 
                            echo full_link(_EXTERNAL_TUNNEL . '?m=paymethod_stripe&h=pay_subscription&method=stripe');
                            ?>
" method="post">
                                    <input type="hidden" name="invoice_payment_subscription_id" value="<?php 
                            echo $invoice_payment_subscription_id;
                            ?>
">
                                    <input type="hidden" name="invoice_payment_id" value="<?php 
                            echo $invoice_payment_id;
                            ?>
">
                                    <input type="hidden" name="invoice_id" value="<?php 
                            echo $invoice_id;
                            ?>
">
                                    <input type="hidden" name="stripe_plan_id" value="<?php 
                            echo $stripe_plan_id;
                            ?>
">
                                    <input type="hidden" name="description" value="<?php 
                            echo htmlspecialchars($description);
                            ?>
">
                                    <input type="hidden" name="user_id" value="<?php 
                            echo htmlspecialchars($user_id);
                            ?>
">
                                  <script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
                                          data-key="<?php 
                            echo $stripe['publishable_key'];
                            ?>
"
                                          data-amount="<?php 
                            echo $payment_amount * 100;
                            ?>
"
                                          <?php 
                            if (isset($user_data['email']) && strlen($user_data['email'])) {
                                ?>
                                          data-email="<?php 
                                echo htmlspecialchars($user_data['email']);
                                ?>
"
                                            <?php 
                            }
                            ?>
                                          data-currency="<?php 
                            echo htmlspecialchars($currency_code);
                            ?>
"
                                          data-label="<?php 
                            _e('Pay %s by Credit Card', dollar($payment_amount, true, $invoice_payment_data['currency_id']));
                            ?>
"
                                          data-description="<?php 
                            echo htmlspecialchars($description);
                            ?>
"></script>
                                </form>

                                <p>&nbsp;</p>
                                <p>

                                <a href="<?php 
                            echo module_invoice::link_public($invoice_id);
                            ?>
"><?php 
                            _e("Cancel");
                            ?>
</a>
                                </p>
                                <?php 
                            $template->content = ob_get_clean();
                            echo $template->render('pretty_html');
                            exit;
                        } else {
                            die('Failed to create stripe plan. Please check settings: ' . var_export($stripe_plan, true));
                        }
                    } else {
                        if (isset($_REQUEST['payment_single'])) {
                            // use is choosing to continue payment as a once off amount
                        } else {
                            // give the user an option
                            module_template::init_template('invoice_payment_subscription', '<h2>Payment for Invoice {INVOICE_NUMBER}</h2>
                        <p>Please choose from the available payment options below:</p>
                        <form action="{PAYMENT_URL}" method="post">
                        <input type="hidden" name="invoice_payment_id" value="{INVOICE_PAYMENT_ID}">
                        <input type="hidden" name="payment_method" value="{PAYMENT_METHOD}">
                        <input type="hidden" name="payment_amount" value="{PAYMENT_AMOUNT}">
                        <p><input type="submit" name="payment_single" value="Pay a Once Off amount of {PRETTY_PAYMENT_AMOUNT}"></p>
                        <p><input type="submit" name="payment_subscription" value="Setup Automatic Payments of {PRETTY_PAYMENT_AMOUNT} every {SUBSCRIPTION_PERIOD}"></p>
                        </form>
                        ', 'Used when a customer tries to pay an invoice that has a subscription option.', 'code');
                            $template = module_template::get_template_by_key('invoice_payment_subscription');
                            $template->page_title = htmlspecialchars($invoice_data['name']);
                            $template->assign_values($invoice_payment_data);
                            $template->assign_values(module_invoice::get_replace_fields($invoice_data['invoice_id'], $invoice_data));
                            $template->assign_values(array('invoice_payment_id' => $invoice_payment_id, 'payment_url' => module_invoice::link_public_pay($invoice_data['invoice_id']), 'payment_method' => 'paymethod_stripe', 'payment_amount' => $payment_amount, 'pretty_payment_amount' => dollar($payment_amount, true, $invoice_data['currency_id']), 'subscription_period' => implode(', ', $bits), 'fee_amount' => dollar($fee_amount, true, $invoice_data['currency_id']), 'fee_total' => dollar($fee_total, true, $invoice_data['currency_id']), 'fee_percent' => $fee_percent, 'fee_description' => $fee_description));
                            echo $template->render('pretty_html');
                            exit;
                        }
                    }
                }
            }
            $description = _l('Payment for invoice %s', $invoice_data['name']);
            //self::stripe_redirect($description,$payment_amount,$user_id,$invoice_payment_id,$invoice_id,$invoice_payment_data['currency_id']);
            $currency = module_config::get_currency($invoice_payment_data['currency_id']);
            $currency_code = $currency['code'];
            $template = new module_template();
            ob_start();
            include module_theme::include_ucm('includes/plugin_paymethod_stripe/pages/stripe_form.php');
            $template->content = ob_get_clean();
            echo $template->render('pretty_html');
            exit;
        }
        return false;
    }
예제 #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.
     }
 }
    }
    ?>

        </div>
        <div class="ticket_message_text">


	        <script type="text/javascript">
		        var done_auto_insert = false;
		        function tinymce_focus() {
			        // if the user has entered a default reply, insert it here.
			        <?php 
    //module_template::init_template('ticket_reply_default','','Default reply text to appear when admin replies to a ticket');
    $template = module_template::get_template_by_key('ticket_reply_default_' . module_security::get_loggedin_id());
    if (!$template->template_id) {
        $template = module_template::get_template_by_key('ticket_reply_default');
    }
    if ($template->template_id) {
        ?>

			        if (!done_auto_insert) {
				        done_auto_insert = true;
				        ucm.ticket.add_to_message("<?php 
        echo preg_replace("#[\r\n]+#", '', addcslashes($template->content, '"'));
        ?>
");
			        }
			        <?php 
    }
    ?>
예제 #15
0
 public static function quote_html($quote_id, $quote_data, $mode = 'html')
 {
     if ($quote_id && $quote_data) {
         // spit out the quote html into a file, then pass it to the pdf converter
         // to convert it into a PDF.
         $quote = $quote_data;
         if (class_exists('module_company', false) && isset($quote_data['company_id']) && (int) $quote_data['company_id'] > 0) {
             module_company::set_current_company_id($quote_data['company_id']);
         }
         $quote_template = isset($quote_data['quote_template_print']) && strlen($quote_data['quote_template_print']) ? $quote_data['quote_template_print'] : module_config::c('quote_template_print_default', 'quote_pdf');
         $quote_template_suffix = '';
         if ($quote_template != 'quote_pdf') {
             $quote_template_suffix = str_replace('quote_pdf', '', $quote_template);
         }
         ob_start();
         include module_theme::include_ucm('includes/plugin_quote/template/quote_task_list.php');
         $task_list_html = ob_get_clean();
         $replace = self::get_replace_fields($quote_id, $quote_data);
         $replace['task_list'] = $task_list_html;
         $replace['quote_link'] = module_quote::link_public($quote_id);
         $replace['external_quote_template_html'] = '';
         $external_quote_template = module_template::get_template_by_key('quote_pdf');
         $external_quote_template->assign_values($replace);
         $replace['external_quote_template_html'] = $external_quote_template->replace_content();
         ob_start();
         $template = module_template::get_template_by_key($quote_template);
         $template->assign_values($replace);
         echo $template->render('html');
         $quote_html = ob_get_clean();
         return $quote_html;
     }
     return false;
 }
예제 #16
0
    public function external_hook($hook)
    {
        switch ($hook) {
            case 'subscribe_form':
                // handle subscriptions to the member database and also the newsletter system.
                // todo - tie in with "subscription" module to allow users to select which subscription they want as well.
            // handle subscriptions to the member database and also the newsletter system.
            // todo - tie in with "subscription" module to allow users to select which subscription they want as well.
            case 'subscribe':
                $member = isset($_REQUEST['member']) && is_array($_REQUEST['member']) ? $_REQUEST['member'] : false;
                $provided_member_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false;
                $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false;
                $member_id = false;
                if ($member) {
                    if (isset($member['email']) && $member['email']) {
                        // proceed with signup
                        $email = filter_var(strtolower(trim($member['email'])), FILTER_VALIDATE_EMAIL);
                        if (strlen($email) > 3) {
                            $adding_new_member = true;
                            // are we adding a new member to the system or updating an old one
                            if ($provided_member_id && $hash) {
                                $real_hash = $this->link_public_details($provided_member_id, true);
                                if ($real_hash == $hash) {
                                    $existing_member = get_single('member', 'email', $email);
                                    if ($existing_member && $existing_member['member_id'] != $provided_member_id) {
                                        // this user is trying to update their email address to a user who exists in the system already
                                        $template = module_template::get_template_by_key('member_subscription_error');
                                        $template->page_title = htmlspecialchars(_l('Subscription'));
                                        $template->assign_values(array('message' => _l('The email address %s is already linked to another member.', htmlspecialchars($email))));
                                        echo $template->render('pretty_html');
                                        exit;
                                    }
                                    $adding_new_member = false;
                                    // updating details in the system.
                                    update_insert("member_id", $provided_member_id, "member", $member);
                                    $member_id = $provided_member_id;
                                    // update extra fields...
                                }
                            }
                            if (!$member_id) {
                                // add member to system.
                                $existing_member = get_single('member', 'email', $email);
                                if ($existing_member && $existing_member['member_id'] > 0) {
                                    // todo: give them link to change details.
                                    $template = module_template::get_template_by_key('member_subscription_error');
                                    $template->page_title = htmlspecialchars(_l('Subscription'));
                                    $template->assign_values(array('message' => _l('The email address %s is already a member. Please click the link in our newsletter to modify your details.', htmlspecialchars($email))));
                                    echo $template->render('pretty_html');
                                    exit;
                                }
                                // todo - sanatise input here, this will allow anyone to insert member details:
                                $member_id = update_insert("member_id", 'new', "member", $member);
                            }
                            if ($member_id) {
                                // save extra fields against member.
                                $extra_fields = module_extra::get_defaults('member');
                                $extra_values = array();
                                foreach ($extra_fields as $extra_field) {
                                    // check if this field was submitted.
                                    if (isset($member[$extra_field['key']])) {
                                        $extra_values[$extra_field['key']] = array('val' => $member[$extra_field['key']], 'key' => $extra_field['key']);
                                    }
                                }
                                if (count($extra_values)) {
                                    $_REQUEST['extra_member_field'] = $extra_values;
                                    module_extra::save_extras('member', 'member_id', $member_id, false);
                                }
                                if (class_exists('module_newsletter', false)) {
                                    $newsletter_member_id = module_newsletter::member_from_email(array('email' => $email, 'member_id' => $member_id, 'data_callback' => 'module_member::get_newsletter_recipient', 'data_args' => $member_id), true, true);
                                    module_newsletter::subscribe_member($email, $newsletter_member_id);
                                    // now add thsi member to the grups they have selected.
                                    if (isset($member['group']) && is_array($member['group'])) {
                                        $group_items = module_group::get_groups('newsletter_subscription');
                                        $public_group_ids = array();
                                        foreach ($group_items as $group_item) {
                                            $public_group_ids[$group_item['group_id']] = true;
                                            // remove user group all these groups.
                                            module_group::delete_member($member_id, 'newsletter_subscription');
                                        }
                                        //print_r($member['group']);print_r($public_group_ids);exit;
                                        foreach ($member['group'] as $group_id => $tf) {
                                            if ($tf && isset($public_group_ids[$group_id])) {
                                                // add member to group - but only public group ids!
                                                module_group::add_to_group($group_id, $member_id);
                                            }
                                        }
                                    }
                                }
                                // is the newsletter module giving us a subscription redirection?
                                if ($adding_new_member) {
                                    if (module_config::c('newsletter_subscribe_redirect', '')) {
                                        redirect_browser(module_config::c('newsletter_subscribe_redirect', ''));
                                    }
                                    $template = module_template::get_template_by_key('member_subscription_success');
                                    $template->page_title = htmlspecialchars(_l('Subscription'));
                                    $template->assign_values(array('email' => $email));
                                    echo $template->render('pretty_html');
                                    exit;
                                } else {
                                    if (module_config::c('newsletter_update_details_redirect', '')) {
                                        redirect_browser(module_config::c('newsletter_update_details_redirect', ''));
                                    }
                                    $template = module_template::get_template_by_key('member_update_details_success');
                                    $template->page_title = htmlspecialchars(_l('Subscription'));
                                    $template->assign_values(array('email' => $email));
                                    echo $template->render('pretty_html');
                                    exit;
                                }
                            } else {
                                echo 'database failure.. please try again.';
                            }
                        } else {
                            $template = module_template::get_template_by_key('member_subscription_error');
                            $template->page_title = htmlspecialchars(_l('Subscription'));
                            $template->assign_values(array('message' => _l('Sorry please go back and complete all required fields (especially email address)')));
                            echo $template->render('pretty_html');
                            exit;
                        }
                    } else {
                        $template = module_template::get_template_by_key('member_subscription_error');
                        $template->page_title = htmlspecialchars(_l('Subscription'));
                        $template->assign_values(array('message' => _l('Sorry please go back and complete all required fields')));
                        echo $template->render('pretty_html');
                        exit;
                    }
                } else {
                    $template = module_template::get_template_by_key('member_subscription_form');
                    $template->page_title = htmlspecialchars(_l('Subscription'));
                    // we also treat this as a subscription modification form.
                    $newsletter_subscriptions = array();
                    $member = array('email' => '', 'first_name' => '', 'last_name' => '', 'business' => '', 'phone' => '', 'mobile' => '');
                    // extra fields:
                    $extra_fields = module_extra::get_defaults('member');
                    foreach ($extra_fields as $extra_field) {
                        $member[$extra_field['key']] = '';
                    }
                    if ($provided_member_id && $hash) {
                        $real_hash = $this->link_public_details($provided_member_id, true);
                        if ($real_hash == $hash) {
                            // we can load these details into the forum successfully.
                            $member = array_merge($member, $this->get_member($provided_member_id));
                            // get their fields:
                            $extra_fields = module_extra::get_extras(array('owner_table' => 'member', 'owner_id' => $provided_member_id));
                            foreach ($extra_fields as $extra_field) {
                                $member[$extra_field['extra_key']] = $extra_field['extra'];
                            }
                            // find out what newsletter subscriptions this member has.
                            if (class_exists('module_newsletter', false)) {
                                $newsletter_member_id = module_newsletter::member_from_email($member, true, true);
                                $newsletter_subscriptions = module_group::get_member_groups('newsletter_subscription', $provided_member_id);
                            }
                        }
                    }
                    $template->assign_values($member);
                    if (class_exists('module_newsletter', false)) {
                        $group_items = module_group::get_groups('newsletter_subscription');
                        ob_start();
                        foreach ($group_items as $group_item) {
                            ?>

                            <div class="group_select">
                                <input type="checkbox" name="member[group][<?php 
                            echo $group_item['group_id'];
                            ?>
]" value="1"<?php 
                            foreach ($newsletter_subscriptions as $newsletter_subscription) {
                                if ($newsletter_subscription['group_id'] == $group_item['group_id']) {
                                    echo ' checked';
                                }
                            }
                            ?>
 > <?php 
                            echo htmlspecialchars($group_item['name']);
                            ?>

                            </div>
                            <?php 
                        }
                        $template->assign_values(array('newsletter_options' => ob_get_clean()));
                    } else {
                        $template->assign_values(array('newsletter_options' => ''));
                    }
                    echo $template->render('pretty_html');
                    exit;
                }
                break;
        }
    }
예제 #17
0
파일: job.php 프로젝트: sgh1986915/php-crm
 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;
 }
예제 #18
0
                        <?php 
    if (module_config::c('ticket_allow_priority', 0)) {
        ?>

                        <tr>
                            <th class="width1">
                                <?php 
        echo _l('Priority Support');
        ?>

                            </th>
                            <td>
                                <?php 
        module_template::init_template('ticket_priority_support', '<em>New!</em> Need a <strong>fast</strong> reply? Priority support will place your ticket at the front of the support queue. <br/>Priority Support Cost: {COST}<br/>{CHECKBOX} <label for="do_priority">Yes, upgrade to <strong>priority support</strong> and move my ticket to position: {TICKET_POSITION}</label>', 'Displayed at the bottom of ticket support signup', 'code', array('cost' => 'Cost as defined by ticket_priority_code advanced setting', 'TICKET_POSITION' => 'displays the string (example) "1st out of 44"'));
        $template = module_template::get_template_by_key('ticket_priority_support');
        $template->assign_values(array('cost' => dollar(module_config::c('ticket_priority_cost', 10), true, module_config::c('ticket_priority_currency', 1)), 'TICKET_POSITION' => _l('%s out of %s', ordinal(module_ticket::ticket_count('priority') + 1), $ticket['total_pending']), 'CHECKBOX' => '<input type="checkbox" name="do_priority" id="do_priority" value="1">'));
        echo $template->replace_content();
        ?>


                            </td>
                        </tr>
                            <?php 
    }
    ?>

                        <?php 
    if (module_config::c('ticket_turn_around_days_show', 1)) {
        ?>
예제 #19
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);
 }
예제 #20
0
파일: faq.php 프로젝트: sgh1986915/php-crm
    public function external_hook($hook)
    {
        switch ($hook) {
            case 'public':
                $faq_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false;
                $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false;
                if ($faq_id && $hash) {
                    $correct_hash = $this->link_open_public($faq_id, true);
                    if ($correct_hash == $hash) {
                        $faq = array();
                        if ($faq_id > 0) {
                            $faq = $this->get_faq($faq_id);
                        }
                        if ($faq) {
                            $template = module_template::get_template_by_key('faq_item');
                            $faq['answer'] = self::html_faq($faq['answer']);
                            $faq['faq_back'] = $this->link_open_public(-1) . (isset($_REQUEST['faq_product_id']) ? '&faq_product_id=' . (int) $_REQUEST['faq_product_id'] : '');
                            $template->assign_values($faq);
                            $template->page_title = $faq['question'];
                            echo $template->render('pretty_html');
                        } else {
                            $template = module_template::get_template_by_key('faq_list');
                            $data = array();
                            ob_start();
                            include 'public/faq_listing.php';
                            $data['listing'] = ob_get_clean();
                            $template->assign_values($data);
                            $template->page_title = _l('FAQ');
                            echo $template->render('pretty_html');
                        }
                    }
                }
                break;
            case 'faq_list_json':
                @ob_end_clean();
                header("Content-type: text/javascript");
                $faq_id = isset($_REQUEST['faq_id']) ? (int) $_REQUEST['faq_id'] : false;
                if ($faq_id > 0) {
                    $faq = $this->get_faq($faq_id);
                    if ($faq) {
                        $faq['url'] = module_faq::link_open_public($faq_id, false);
                        echo json_encode($faq);
                        /*$template = module_template::get_template_by_key('faq_item');
                          $faq['answer'] = forum_text($faq['answer']);
                          $faq['faq_back'] = $this->link_open_public(-1).(isset($_REQUEST['faq_product_id']) ? '&faq_product_id='.(int)$_REQUEST['faq_product_id'] : '');
                          $template->assign_values($faq);
                          $template->page_title = $faq['question'];
                          echo $template->replace_content();*/
                    }
                    exit;
                }
                $faq_product_id = isset($_REQUEST['faq_product_id']) ? (int) $_REQUEST['faq_product_id'] : false;
                $faq_search = isset($_REQUEST['faq_search']) ? $_REQUEST['faq_search'] : false;
                $faqs = $this->get_faqs(array('faq_product_id' => $faq_product_id, 'question' => $faq_search));
                $faqs_json = array();
                $all_products = module_faq::get_faq_products_rel();
                foreach ($faqs as $faq) {
                    $faq = module_faq::get_faq($faq['faq_id']);
                    $faq_products = array();
                    foreach ($faq['faq_product_ids'] as $faq_product_id) {
                        $faq_products[$faq_product_id] = $all_products[$faq_product_id];
                    }
                    $faqs_json[$faq['faq_id']] = array('question' => $faq['question'], 'url' => module_faq::link_open_public($faq['faq_id'], false), 'products' => $faq_products);
                }
                echo json_encode($faqs_json);
                exit;
                break;
            case 'ticket_list':
                $faq_product_id = isset($_REQUEST['faq_product_id']) ? (int) $_REQUEST['faq_product_id'] : false;
                @ob_end_clean();
                header("Content-type: text/javascript");
                if ($faq_product_id) {
                    $product = $this->get_faq_product($faq_product_id);
                    // find the faq items that match this product id.
                    if ($product && $product['faq_product_id'] == $faq_product_id) {
                        $faqs = $this->get_faqs(array('faq_product_id' => $faq_product_id));
                        ob_start();
                        $x = 0;
                        $half = ceil(count($faqs) / 2);
                        ?>

                        <tr>
                            <th>
                                <?php 
                        _e('FAQ');
                        ?>

                            </th>
                            <td>
                                <?php 
                        _e('Please read through the below FAQ to see if the question has already been answered');
                        ?>

                        </tr>
                        <tr>
                            <td colspan="2">
                                <table width="100%" class="tableclass tableclass_full table_faq_class">
                                    <tbody>
                                    <tr>
                                        <td width="50%" valign="top">
                                            <ul><?php 
                        for (true; $x < $half; $x++) {
                            $data = array_shift($faqs);
                            $faq = module_faq::get_faq($data['faq_id']);
                            ?>

                                                    <li>
                                                        <a href="<?php 
                            echo module_faq::link_open_public($data['faq_id'], false);
                            ?>
" target="_blank"><?php 
                            echo htmlspecialchars($faq['question']);
                            ?>
</a>
                                                    </li>
                                                    <?php 
                        }
                        ?>

                                            </ul>
                                        </td>
                                        <td width="50%" valign="top">
                                            <ul><?php 
                        foreach ($faqs as $data) {
                            $faq = module_faq::get_faq($data['faq_id']);
                            ?>

                                                    <li>
                                                        <a href="<?php 
                            echo module_faq::link_open_public($data['faq_id'], false);
                            ?>
" target="_blank"><?php 
                            echo htmlspecialchars($faq['question']);
                            ?>
</a>
                                                    </li>
                                                    <?php 
                        }
                        ?>

                                            </ul>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>

                            </td>
                        </tr>
                        <?php 
                        $html = preg_replace('#\\s+#', ' ', ob_get_clean());
                        ?>

                        $('#faq_product_area').html('<?php 
                        echo addcslashes($html, "'");
                        ?>
');
                        <?php 
                        if ($product['default_type_id']) {
                            ?>

                            $('#ticket_type_id').val(<?php 
                            echo (int) $product['default_type_id'];
                            ?>
);
                        <?php 
                        }
                        // and now we have to set the ticket position.
                        if (module_config::c('ticket_show_position', 1)) {
                            $new_position = module_ticket::ticket_position(false, $faq_product_id);
                            ?>

                            $('#ticket_position_field').html('<?php 
                            echo addcslashes(_l('%s out of %s other support tickets', ordinal($new_position['current'] + 1), $new_position['total'] + 1), "'");
                            ?>
');
                            <?php 
                            if (module_config::c('ticket_allow_priority', 0)) {
                                $c = module_ticket::get_ticket_count($faq_product_id);
                                ?>

                                $('#priority_ticket_position').html('<?php 
                                _e('%s out of %s', ordinal($c['priority'] + 1), $new_position['total'] + 1);
                                ?>
');
                                <?php 
                            }
                        }
                        exit;
                    }
                }
                ?>
  $('#faq_product_area').html(''); <?php 
                if (module_config::c('ticket_show_position', 1)) {
                    $new_position = module_ticket::ticket_position();
                    ?>

                    $('#ticket_position_field').html('<?php 
                    echo addcslashes(_l('%s out of %s other support tickets', ordinal($new_position['current'] + 1), $new_position['total'] + 1), "'");
                    ?>
');
                    <?php 
                    if (module_config::c('ticket_allow_priority', 0)) {
                        ?>

                        $('#priority_ticket_position').html('<?php 
                        _e('%s out of %s', ordinal(module_ticket::ticket_count('priority') + 1), $new_position['total'] + 1);
                        ?>
');
                        <?php 
                    }
                }
                break;
        }
    }
예제 #21
0
파일: home.php 프로젝트: sgh1986915/php-crm
$widget_columns[1] = array(1 => array());
$widget_columns[2] = array(1 => array(), 2 => array());
$widget_columns[3] = array(1 => array(), 2 => array(), 3 => array());
// then display the welcome message:
module_template::init_template('welcome_message', '<p>
   Hi {USER_NAME}, and Welcome to {SYSTEM_NAME}
</p>', 'Welcome message on Dashboard', array('USER_NAME' => 'Current user name', 'SYSTEM_NAME' => 'System name from settings area'));
// check if there is a template for this user role.
$my_account = module_user::get_user(module_security::get_loggedin_id());
$security_role = current($my_account['roles']);
$template = false;
if ($security_role && isset($security_role['security_role_id'])) {
    $template = module_template::get_template_by_key('welcome_message_role_' . $security_role['security_role_id']);
}
if (!$template || !$template->template_key) {
    $template = module_template::get_template_by_key('welcome_message');
}
$template->assign_values(array('user_name' => htmlspecialchars($_SESSION['_user_name']), 'system_name' => htmlspecialchars(module_config::s('admin_system_name'))));
$widget_sort_json = @json_decode(module_config::c('dash_widgets_sort_' . module_security::get_loggedin_id()), true);
if (!is_array($widget_sort_json)) {
    $widget_sort_json = array();
}
$widget_sort_order = array();
$widget_sort_page_order = 1;
foreach ($widget_sort_json as $id => $vals) {
    $bits = explode('|', $vals);
    if (count($bits) == 3) {
        $widget_sort_order[$bits[2]] = array('column' => $bits[0], 'column_number' => $bits[1], 'page_order' => $widget_sort_page_order++);
    }
}
$widget_sort_id = 1;
예제 #22
0
<?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)));
예제 #23
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 
    }
예제 #24
0
 public static function start_payment($invoice_id, $payment_amount, $invoice_payment_id, $user_id = false)
 {
     if ($invoice_id && $payment_amount && $invoice_payment_id) {
         // we are starting a payment via paypal!
         // setup a pending payment and redirect to paypal.
         $invoice_data = module_invoice::get_invoice($invoice_id);
         if (!$user_id) {
             $user_id = $invoice_data['user_id'];
         }
         if (!$user_id) {
             $user_id = isset($invoice_data['primary_user_id']) ? $invoice_data['primary_user_id'] : 0;
         }
         $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id);
         // we add the fee details to the invoice payment record so that the new invoice total can be calculated.
         $fee_percent = module_config::c('payment_method_paypal_charge_percent', 0);
         $fee_amount = module_config::c('payment_method_paypal_charge_amount', 0);
         $fee_description = module_config::c('payment_method_paypal_charge_description', 'PayPal Fee');
         $fee_total = 0;
         if ($fee_percent != 0 || $fee_amount != 0) {
             $fee_total = module_invoice::calculate_fee($invoice_id, $invoice_data, $payment_amount, array('percent' => $fee_percent, 'amount' => $fee_amount, 'description' => $fee_description));
             if ($fee_total != 0) {
                 // add this percent/amount to the invoice payment
                 $payment_amount = $payment_amount + $fee_total;
                 update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('fee_percent' => $fee_percent, 'fee_amount' => $fee_amount, 'fee_description' => $fee_description, 'fee_total' => $fee_total, 'amount' => $payment_amount));
             }
         }
         // we check if this payment is a recurring payment or a standard one off payment.
         if (module_config::c('payment_method_paypal_subscriptions', 0)) {
             // we support subscriptions!
             // first check if the subscription module is active, and if this invoice is part of an active subscription.
             $is_subscription = false;
             if (class_exists('module_subscription', false)) {
                 $subscription_history = get_single('subscription_history', 'invoice_id', $invoice_id);
                 if ($subscription_history && $subscription_history['subscription_id']) {
                     // this invoice is for a subscription! woo!
                     // work out when we should bill for this subscription.
                     $subscription = module_subscription::get_subscription($subscription_history['subscription_id']);
                     $subscription_owner = module_subscription::get_subscription_owner($subscription_history['subscription_owner_id']);
                     if ($subscription_owner['owner_table'] && $subscription_owner['owner_id']) {
                         // work out when the next invoice will be generated for this subscription.
                         $members_subscriptions = module_subscription::get_subscriptions_by($subscription_owner['owner_table'], $subscription_owner['owner_id']);
                         if (isset($members_subscriptions[$subscription_history['subscription_id']])) {
                             $member_subscription = $members_subscriptions[$subscription_history['subscription_id']];
                             // everything checks out! good to go....
                             // for now we just do a basic "EVERY X TIME" subscription
                             // todo: work out how long until next generate date, and set that (possibly smaller) time period as the first portion of the subscription
                             /*echo '<pre>';
                               print_r($subscription_history);
                               print_r($subscription);
                               print_r($subscription_owner);
                               print_r($member_subscription);
                               exit;*/
                             $is_subscription = array();
                             if ($subscription['days'] > 0) {
                                 $is_subscription['days'] = $subscription['days'];
                             }
                             if ($subscription['months'] > 0) {
                                 $is_subscription['months'] = $subscription['months'];
                             }
                             if ($subscription['years'] > 0) {
                                 $is_subscription['years'] = $subscription['years'];
                             }
                             if (count($is_subscription)) {
                                 $is_subscription['name'] = $subscription['name'];
                             }
                         }
                     }
                 }
             }
             // todo: check if this invoice has a manual renewal date, perform subscription feature as above.
             if ($is_subscription) {
                 $bits = array();
                 if (isset($is_subscription['days']) && $is_subscription['days'] > 0) {
                     $bits[] = _l('%s days', $is_subscription['days']);
                 }
                 if (isset($is_subscription['months']) && $is_subscription['months'] > 0) {
                     $bits[] = _l('%s months', $is_subscription['months']);
                 }
                 if (isset($is_subscription['years']) && $is_subscription['years'] > 0) {
                     $bits[] = _l('%s years', $is_subscription['years']);
                 }
                 $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id);
                 if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) {
                     // existing subscription already!
                     // not really sure what to do here, just redirect to paypal as if the user is doing it for the first time.
                     $_REQUEST['payment_subscription'] = true;
                     // hacks!
                 }
                 if (isset($_REQUEST['payment_subscription']) || module_config::c('payment_method_paypal_force_subscription', 0)) {
                     // user is setting up a subscription! yes!!
                     // we create an entry in our database for this particular subscription
                     // or if one exists for this payment already then we just continue with that (ie: the user is going in again to redo it)
                     // setup a new subscription in the database for us.
                     if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) {
                         $invoice_payment_subscription_id = $invoice_payment_data['invoice_payment_subscription_id'];
                     } else {
                         $invoice_payment_subscription_id = update_insert('invoice_payment_subscription_id', false, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_PENDING, 'days' => isset($is_subscription['days']) ? $is_subscription['days'] : 0, 'months' => isset($is_subscription['months']) ? $is_subscription['months'] : 0, 'years' => isset($is_subscription['years']) ? $is_subscription['years'] : 0, 'date_start' => '0000-00-00', 'date_last_pay' => '0000-00-00', 'date_next' => '0000-00-00'));
                         update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('invoice_payment_subscription_id' => $invoice_payment_subscription_id));
                     }
                     $description = _l('Recurring payment for %s every %s', $is_subscription['name'], implode(', ', $bits));
                     unset($is_subscription['name']);
                     // so reset/key cals below rosk.
                     $currency = module_config::get_currency($invoice_payment_data['currency_id']);
                     $url = 'https://www.' . (self::is_sandbox() ? 'sandbox.' : '') . 'paypal.com/cgi-bin/webscr?';
                     // if there are more than 1 recurring amounts then we convert it to days, as paypal only supports one time period.
                     if (count($is_subscription) > 1) {
                         $days = isset($is_subscription['days']) ? $is_subscription['days'] : 0;
                         if (isset($is_subscription['months'])) {
                             $days += $is_subscription['months'] * 30;
                             unset($is_subscription['months']);
                         }
                         if (isset($is_subscription['years'])) {
                             $days += $is_subscription['years'] * 365;
                             unset($is_subscription['years']);
                         }
                         $is_subscription['days'] = $days;
                     }
                     reset($is_subscription);
                     $time = key($is_subscription);
                     if ($time == 'days') {
                         $time = 'D';
                     } else {
                         if ($time == 'months') {
                             $time = 'M';
                         } else {
                             if ($time == 'years') {
                                 $time = 'Y';
                             }
                         }
                     }
                     $fields = array('cmd' => '_xclick-subscriptions', 'business' => module_config::c('payment_method_paypal_email', _ERROR_EMAIL), 'currency_code' => $currency['code'], 'item_name' => $description, 'no_shipping' => 1, 'page_style' => module_config::c('paypal_page_style', ''), 'return' => module_invoice::link_public_payment_complete($invoice_id), 'rm' => 1, 'cancel_return' => module_invoice::link_public($invoice_id), 'notify_url' => full_link(_EXTERNAL_TUNNEL . '?m=paymethod_paypal&h=ipn&method=paypal'), 'custom' => self::paypal_custom($user_id, $invoice_payment_id, $invoice_id, $invoice_payment_subscription_id), 'a3' => $payment_amount, 'p3' => current($is_subscription), 't3' => $time, 'src' => 1, 'sra' => 1, 'no_note' => 1);
                     // is there a subscription trail period
                     if (isset($subscription['settings']['trial_period']) && $subscription['settings']['trial_period'] > 0) {
                         // we have to hacck the payment_amount here.
                         // $payment_amount will be the discounted amount (eg: $5 instead of $10)
                         // so we reverse that discounted amount for the real amount.
                         $real_amount = $payment_amount - $fee_amount - (isset($subscription['settings']['trial_price_adjust']) ? $subscription['settings']['trial_price_adjust'] : 0);
                         $real_fee_total = module_invoice::calculate_fee($invoice_id, $invoice_data, $real_amount, array('percent' => $fee_percent, 'amount' => $fee_amount, 'description' => $fee_description));
                         $real_amount += $real_fee_total;
                         $fields['a3'] = $real_amount;
                         $fields['a1'] = $payment_amount;
                         // $real_amount + (isset($subscription['settings']['trial_price_adjust']) ? $subscription['settings']['trial_price_adjust'] : 0);
                         $fields['p1'] = current($is_subscription);
                         // * $subscription['settings']['trial_period'];
                         $fields['t1'] = $time;
                     }
                     //echo '<pre>'; print_r($fields);exit;
                     foreach ($fields as $key => $val) {
                         $url .= $key . '=' . urlencode($val) . '&';
                     }
                     //echo '<a href="'.$url.'">'.$url.'</a>';exit;
                     redirect_browser($url);
                 } else {
                     if (isset($_REQUEST['payment_single'])) {
                         // use is choosing to continue payment as a once off amount
                     } else {
                         // give the user an option
                         module_template::init_template('invoice_payment_subscription', '<h2>Payment for Invoice {INVOICE_NUMBER}</h2>
                     <p>Please choose from the available payment options below:</p>
                     <form action="{PAYMENT_URL}" method="post">
                     <input type="hidden" name="invoice_payment_id" value="{INVOICE_PAYMENT_ID}">
                     <input type="hidden" name="payment_method" value="{PAYMENT_METHOD}">
                     <input type="hidden" name="payment_amount" value="{PAYMENT_AMOUNT}">
                     <p><input type="submit" name="payment_single" value="Pay a Once Off amount of {PRETTY_PAYMENT_AMOUNT}"></p>
                     <p><input type="submit" name="payment_subscription" value="Setup Automatic Payments of {PRETTY_PAYMENT_AMOUNT} every {SUBSCRIPTION_PERIOD}"></p>
                     </form>
                     ', 'Used when a customer tries to pay an invoice that has a subscription option.', 'code');
                         $template = module_template::get_template_by_key('invoice_payment_subscription');
                         $template->page_title = htmlspecialchars($invoice_data['name']);
                         $template->assign_values($invoice_payment_data);
                         $template->assign_values(module_invoice::get_replace_fields($invoice_data['invoice_id'], $invoice_data));
                         $template->assign_values(array('invoice_payment_id' => $invoice_payment_id, 'payment_url' => module_invoice::link_public_pay($invoice_data['invoice_id']), 'payment_method' => 'paymethod_paypal', 'payment_amount' => $payment_amount, 'pretty_payment_amount' => dollar($payment_amount, true, $invoice_data['currency_id']), 'subscription_period' => implode(', ', $bits), 'fee_amount' => dollar($fee_amount, true, $invoice_data['currency_id']), 'fee_total' => dollar($fee_total, true, $invoice_data['currency_id']), 'fee_percent' => $fee_percent, 'fee_description' => $fee_description));
                         echo $template->render('pretty_html');
                         exit;
                     }
                 }
             }
         }
         $description = _l('Payment for Invoice %s', $invoice_data['name']);
         self::paypal_redirect($description, $payment_amount, $user_id, $invoice_payment_id, $invoice_id, $invoice_payment_data['currency_id']);
         return true;
     }
     return false;
 }
예제 #25
0
                <strong><?php 
            echo $payment_methods_of['name'];
            ?>
</strong><br/>
                <?php 
            echo $payment_methods_of['description'];
            ?>
            </li>
            <?php 
        }
        ?>
        </ul>
        <?php 
    }
    $payment_methods_offline_html = ob_get_clean();
    $template_invoice_payment_methods = module_template::get_template_by_key('invoice_payment_methods');
    $template_invoice_payment_methods->assign_values(array('PAYMENT_METHODS_ONLINE' => $payment_methods_online_html, 'PAYMENT_METHODS_OFFLINE' => $payment_methods_offline_html));
    $template_invoice_payment_methods->assign_values(module_invoice::get_replace_fields($invoice_id, $invoice_data));
    echo $template_invoice_payment_methods->replace_content();
} else {
    ?>

    <p align="center">
    <?php 
    $template_print = module_template::get_template_by_key('invoice_payment_in_full');
    echo $template_print->content;
    ?>
	</p>
    
<?php 
}
예제 #26
0
        </tr>
        {QUOTE_SUMMARY}
    </tfoot>
</table>

<?php 
module_template::init_template('quote_task_list', ob_get_clean(), 'Used when displaying the quote tasks.', 'code');
$t = false;
if (isset($quote_template_suffix) && strlen($quote_template_suffix) > 0) {
    $t = module_template::get_template_by_key('quote_task_list' . $quote_template_suffix);
    if (!$t->template_id) {
        $t = false;
    }
}
if (!$t) {
    $t = module_template::get_template_by_key('quote_task_list');
}
$replace = array();
if ($quote['default_task_type'] == _TASK_TYPE_AMOUNT_ONLY) {
    $replace['title_qty_or_hours'] = '';
} else {
    if ($quote['default_task_type'] == _TASK_TYPE_QTY_AMOUNT) {
        $replace['title_qty_or_hours'] = _l(module_config::c('task_qty_name', 'Qty'));
    } else {
        if ($quote['default_task_type'] == _TASK_TYPE_HOURS_AMOUNT) {
            $replace['title_qty_or_hours'] = _l(module_config::c('task_hours_name', 'Hours'));
        }
    }
}
if ($quote['default_task_type'] == _TASK_TYPE_AMOUNT_ONLY) {
    $replace['title_amount_or_rate'] = _l(module_config::c('quote_amount_name', 'Amount'));
예제 #27
0
파일: file.php 프로젝트: sgh1986915/php-crm
    public function external_hook($hook)
    {
        switch ($hook) {
            case 'view':
                $file_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false;
                $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false;
                if ($file_id && $hash) {
                    $correct_hash = $this->link_public($file_id, true);
                    if ($correct_hash == $hash) {
                        // all good to print a receipt for this payment.
                        $file_data = $this->get_file($file_id, false);
                        if ($file_data && $file_data['file_id'] == $file_id) {
                            if (isset($_POST['save_file_comments'])) {
                                if (isset($_POST['file_approve']) && isset($_POST['file_approve_go']) && isset($_POST['file_approve_name']) && strlen($_POST['file_approve_name']) > 0) {
                                    update_insert('file_id', $file_id, 'file', array('approved_time' => time(), 'approved_by' => $_POST['file_approve_name']));
                                    // send email, same 'updated' email as before.
                                    $this->send_file_changed_notice($file_id, false, true);
                                    //redirect_browser($this->link_public($file_id));
                                    $_REQUEST['new_comment_text'] = _l('File was approved at %s by %s', print_date(time(), true), htmlspecialchars($_POST['file_approve_name']));
                                }
                                if (isset($_POST['pointers'])) {
                                    update_insert('file_id', $file_id, 'file', array('pointers' => $_POST['pointers']));
                                }
                                $this->save_file_comments($file_id);
                                redirect_browser($this->link_public($file_id));
                            }
                            module_template::init_template('file_approval_view', '<h2>File Details</h2>
    File Name: <strong>{FILE_NAME}</strong> <br/>
    Download: <strong><a href="{FILE_DOWNLOAD_URL}">Click Here</a></strong> <br/>
    Status: <strong>{STATUS}</strong> <br/>
    Customer: <strong>{CUSTOMER_NAME}</strong> <br/>
    {if:JOB_NAME}Job: <strong>{JOB_NAME}</strong> <br/>{endif:JOB_NAME}
    {if:FILE_APPROVAL_PENDING}
    <h2>File Approval Pending</h2>
    <p>If you would like to approve this file please complete the form below:</p>
    <p>Your Name: <input type="text" name="file_approve_name"> </p>
    <p><input type="checkbox" name="file_approve_go" value="yes"> Yes, I approve this file. </p>
    <p><input type="submit" name="file_approve" value="Approve File" class="submit_button save_button"></p>
    {endif:FILE_APPROVAL_PENDING}
    {if:FILE_APPROVED}
    <h2>File Has Been Approved</h2>
    <p>Thank you, the file was approved by <strong>{APPROVED_BY}</strong> on <strong>{APPROVED_TIME}</strong>.</p>
    {endif:FILE_APPROVED}
    <h2>File Comments</h2>
    <p>Please feel free to add comments to this file using the form below.</p>
    {FILE_COMMENTS}
    {if:FILE_PREVIEW}
    <h2>File Preview</h2>
    <div style="overflow:scroll;">{FILE_PREVIEW}</div>
    {endif:FILE_PREVIEW}
    ', 'Used when displaying the file to a customer for approval.', 'code');
                            $template = module_template::get_template_by_key('file_approval_view');
                            // generate the html for the task output
                            $job_data = $file_data['job_id'] ? module_job::get_replace_fields($file_data['job_id']) : array();
                            if (class_exists('module_quote', false)) {
                                $quote_data = $file_data['quote_id'] ? module_quote::get_replace_fields($file_data['quote_id']) : array();
                            }
                            $customer_data = $file_data['customer_id'] ? module_customer::get_replace_fields($file_data['customer_id']) : array();
                            $file_data['file_preview'] = module_file::generate_preview($file_id, $file_data['file_name'], $file_data);
                            $file_data['FILE_DOWNLOAD_URL'] = module_file::link_public_view($file_id);
                            if (isset($file_data['approved_time'])) {
                                switch ($file_data['approved_time']) {
                                    case -1:
                                        $file_data['FILE_APPROVAL_PENDING'] = 1;
                                        break;
                                    case 0:
                                        break;
                                    default:
                                        $file_data['FILE_APPROVED'] = 1;
                                        $file_data['APPROVED_TIME'] = print_date($file_data['approved_time'], true);
                                }
                            }
                            if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) {
                                $all_extra_fields = module_extra::get_defaults('file');
                                foreach ($all_extra_fields as $e) {
                                    $file_data[$e['key']] = _l('N/A');
                                }
                                // and find the ones with values:
                                $extras = module_extra::get_extras(array('owner_table' => 'file', 'owner_id' => $file_id));
                                foreach ($extras as $e) {
                                    $file_data[$e['extra_key']] = $e['extra'];
                                }
                            }
                            ob_start();
                            ?>

                            <div id="file_notes">
                            <div style="border-top:1px dashed #CCCCCC; padding:3px; margin:3px 0;">
                                <textarea name="new_comment_text" style="width:100%;" class="no_permissions"></textarea>
                                <div style="text-align: right;">
                                <input type="submit" name="butt_save_note" id="butt_save_note" value="<?php 
                            echo _l('Add Comment');
                            ?>
" class="submit_button no_permissions">
                                    </div>
                            </div>
                            <?php 
                            foreach (module_file::get_file_comments($file_id) as $item) {
                                $note_text = forum_text($item['comment']);
                                if (preg_match_all('/#(\\d+)/', $note_text, $matches)) {
                                    //
                                    foreach ($matches[1] as $digit) {
                                        $note_text = preg_replace('/#' . $digit . '([^\\d]*)/', '<span node_id=' . $digit . ' class="pointer-ids pointer-id-' . $digit . '">#' . $digit . '</span>$1', $note_text);
                                    }
                                }
                                ?>

                                <div style="border-top:1px dashed #CCCCCC; padding:3px; margin:3px 0;">
                                    <?php 
                                echo $note_text;
                                ?>

                                    <div style="font-size:10px; text-align:right; color:#CCCCCC;">From <?php 
                                echo $item['create_user_id'] ? module_user::link_open($item['create_user_id'], true) : _l('Customer');
                                ?>
 on <?php 
                                echo print_date($item['date_created'], true);
                                ?>

                                    </div>
                                </div>

                                <?php 
                            }
                            ?>

                            </div>
                            <?php 
                            $file_data['file_comments'] = ob_get_clean();
                            $template->assign_values($file_data);
                            $template->assign_values($customer_data);
                            $template->assign_values($job_data);
                            if (class_exists('module_quote', false)) {
                                $quote_data['quote_approved_by'] = $quote_data['approved_by'];
                                $quote_data['quote_date_approved'] = $quote_data['date_approved'];
                                unset($quote_data['approved_by']);
                                unset($quote_data['date_approved']);
                                $template->assign_values($quote_data);
                            }
                            $template->page_title = $file_data['file_name'];
                            $template->content = '<form action="" method="post"><input type="hidden" name="save_file_comments" value="1">' . $template->content . '</form>';
                            echo $template->render('pretty_html');
                        }
                    }
                }
                break;
            case 'download_bucket':
                @ob_end_clean();
                $file_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false;
                $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false;
                if ($file_id && $hash) {
                    $correct_hash = $this->link_public_download_bucket($file_id, true);
                    if ($correct_hash == $hash) {
                        // all good to print a receipt for this payment.
                        $file_data = $this->get_file($file_id, false);
                        @ignore_user_abort(true);
                        $search = array();
                        $search['bucket_parent_file_id'] = $file_id;
                        $files = module_file::get_files($search);
                        //Create ZIP
                        $zip = new ZipArchive();
                        $zipName = "bucket-" . $file_id . "-" . md5($file_id . _UCM_SECRET) . ".zip";
                        if ($zip->open(_FILE_UPLOAD_PATH . $zipName, ZIPARCHIVE::CREATE) !== TRUE) {
                            echo 'Failed to create bucket zip file';
                            exit;
                        }
                        foreach ($files as $file) {
                            if (is_file($file['file_path'])) {
                                $zip->addFromString($file['file_name'], file_get_contents($file['file_path']));
                            }
                        }
                        $zip->close();
                        //Set headers
                        header("Pragma: public");
                        header("Expires: 0");
                        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                        header("Cache-Control: public");
                        header("Content-Description: File Transfer");
                        header("Content-type: application/octet-stream");
                        //header("Content-Disposition: attachment; filename='" . $zipName . "'");
                        header("Content-Disposition: attachment; filename=\"" . preg_replace("#[^a-zA-Z0-9]+#", "-", $file_data['file_name']) . ".zip\";");
                        header("Content-Transfer-Encoding: binary");
                        header("Content-Length: " . filesize(_FILE_UPLOAD_PATH . $zipName));
                        @clearstatcache();
                        //Make sure the file size isn't cached
                        $size = @readfile(_FILE_UPLOAD_PATH . $zipName);
                        if (!$size) {
                            echo file_get_contents(_FILE_UPLOAD_PATH . $zipName);
                        }
                        @unlink(_FILE_UPLOAD_PATH . $zipName);
                    }
                }
                exit;
                break;
            case 'download':
                @ob_end_clean();
                $file_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false;
                $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false;
                if ($file_id && $hash) {
                    $correct_hash = $this->link_public_view($file_id, true);
                    if ($correct_hash == $hash) {
                        // all good to print a receipt for this payment.
                        $file_data = $this->get_file($file_id, false);
                        if (isset($file_data['file_url']) && strlen($file_data['file_url'])) {
                            redirect_browser($file_data['file_url']);
                        } else {
                            if (is_file($file_data['file_path'])) {
                                header("Pragma: public");
                                header("Expires: 0");
                                header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                                header("Cache-Control: private", false);
                                header("Content-type: " . dtbaker_mime_type($file_data['file_name'], $file_data['file_path']));
                                if (!isset($_REQUEST['embed'])) {
                                    header("Content-Disposition: attachment; filename=\"" . $file_data['file_name'] . "\";");
                                    header("Content-Transfer-Encoding: binary");
                                }
                                header("Content-Length: " . filesize($file_data['file_path']));
                                //readfile($file_data['file_path']);
                                $size = @readfile($file_data['file_path']);
                                if (!$size) {
                                    echo file_get_contents($file_data['file_path']);
                                }
                            } else {
                                echo 'Not found';
                            }
                        }
                    }
                }
                exit;
                break;
        }
    }
예제 #28
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;
        }
    }
예제 #29
0
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
if (!$quote_safe) {
    die('failed');
}
if (!module_quote::can_i('edit', 'Quotes')) {
    die('no perms');
}
$quote_id = (int) $_REQUEST['quote_id'];
$quote = module_quote::get_quote($quote_id);
// template for sending emails.
// are we sending the paid one? or the dueone.
//$template_name = 'quote_email';
$template_name = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : 'quote_email';
$template = module_template::get_template_by_key($template_name);
$quote['total_amount_print'] = dollar($quote['total_amount'], true, $quote['currency_id']);
$quote['total_amount_due_print'] = dollar($quote['total_amount_due'], true, $quote['currency_id']);
$quote['quote_name'] = $quote['name'];
$quote['from_name'] = module_security::get_loggedin_name();
$quote['quote_url'] = module_quote::link_public($quote_id);
ob_start();
include module_theme::include_ucm('includes/plugin_quote/template/quote_task_list.php');
$public_html = ob_get_clean();
$quote['task_list'] = $public_html;
/*ob_start();
$quote_data = $quote;
$ignore_task_hook=true;
$for_email=true;
include('quote_public.php');
$quote['quote_tasks'] = ob_get_clean();*/
예제 #30
0
    public static function start_payment($invoice_id, $payment_amount, $invoice_payment_id, $user_id = false)
    {
        if ($invoice_id && $payment_amount && $invoice_payment_id) {
            // we are starting a payment via authorize!
            // setup a pending payment and redirect to authorize.
            $invoice_data = module_invoice::get_invoice($invoice_id);
            if (!$user_id) {
                $user_id = $invoice_data['user_id'];
            }
            if (!$user_id) {
                $user_id = module_security::get_loggedin_id();
            }
            $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id);
            if ($invoice_payment_data && $invoice_payment_data['invoice_id'] == $invoice_data['invoice_id']) {
                //self::authorize_redirect($description,$payment_amount,$user_id,$invoice_payment_id,$invoice_id,$invoice_payment_data['currency_id']);
                $currency = module_config::get_currency($invoice_payment_data['currency_id']);
                $currency_code = $currency['code'];
                ob_start();
                include 'includes/plugin_paymethod_authorize/pages/authorize_form_default.php';
                module_template::init_template('authorize_credit_card_form', ob_get_clean(), 'Form displayed for payments via Authorize.net', 'code');
                $form = module_template::get_template_by_key('authorize_credit_card_form');
                //                $form = new module_template();
                //                $form->content = ob_get_clean();
                ob_start();
                ?>
                <form action="<?php 
                echo full_link(_EXTERNAL_TUNNEL . '?m=paymethod_authorize&h=pay&method=authorize');
                ?>
" method="POST" id="authorize-payment-form">
                <input type="hidden" name="invoice_payment_id" value="<?php 
                echo $invoice_payment_id;
                ?>
">
                <input type="hidden" name="invoice_id" value="<?php 
                echo $invoice_id;
                ?>
">
                <input type="hidden" name="invoice_num" value="<?php 
                echo htmlspecialchars($invoice_data['name']);
                ?>
">
                <input type="hidden" name="description" value="<?php 
                _e('Payment for Invoice #%', htmlspecialchars($invoice_data['name']));
                ?>
">
                    <?php 
                echo $form->content;
                ?>
                </form>
                <?php 
                $form->content = ob_get_clean();
                $form->assign_values(array('INVOICE_NUMBER' => $invoice_data['name'], 'AMOUNT' => dollar($invoice_payment_data['amount'], true, $invoice_payment_data['currency_id']), 'CANCEL_URL' => module_invoice::link_public($invoice_id)));
                // we also want to grab all the normal invoice replace fields and add those in as well.
                $form->assign_values(module_invoice::get_replace_fields($invoice_id, $invoice_data));
                echo $form->render('pretty_html');
            }
            exit;
        }
        return false;
    }