<?php
/*
MailBeez Automatic Trigger Email Campaigns
http://www.mailbeez.com
Copyright (c) 2010 MailBeez
inspired and in parts based on
Copyright (c) 2003 osCommerce
Released under the GNU General Public License
v1.7
*/
// disable Gzip compression
define('GZIP_COMPRESSION', 'false');
define('GZIP_LEVEL', '0');
define('SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO_SUBJECT', 'Order--');
define('EMAIL_TEXT_DELIVERY_DATE', 'Delivery or Pickup Date:');
define('EMAIL_SEPARATOR', '------------------------------------------------------');
define('EMAIL_TEXT_SUBJECT', 'Order Update');
define('EMAIL_TEXT_ORDER_NUMBER', 'Order Number:');
define('EMAIL_TEXT_INVOICE_URL', 'Detailed Invoice:');
define('EMAIL_TEXT_STATUS_COMMENTS', 'Status Changed:');
define('EMAIL_TEXT_DATE_ORDERED', 'Date Ordered:');
define('EMAIL_TEXT_COMMENTS_UPDATE', '<em>The comments for your order are: </em>');
define('EMAIL_TEXT_STATUS_UPDATED', 'Your order has been updated to the following status:' . "\n");
define('EMAIL_TEXT_STATUS_LABEL', '<strong>New status:</strong> %s' . "\n\n");
define('EMAIL_TEXT_STATUS_PLEASE_REPLY', 'Please reply to this email if you have any questions.' . "\n");
define('EMAIL_TEXT_NEW_STATUS', 'New Order Status:');
//EMAIL_TEXT_NEW_STATUS EMAIL_TEXT_STATUS_COMMENTS EMAIL_CUSTOMERS_NAME SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO_SUBJECT
define('EMAIL_TEXT_STATUS_UPDATE', 'Your order has been updated to the following status.' . "\n\n" . 'New status: %s' . "\n\n" . 'Please reply to this email if you have any questions.' . "\n");
// define('STRICT_ERROR_REPORTING', true);
require('includes/application_top.php');
// zencart, xtcommerce
if (!defined('DIR_WS_HTTP_CATALOG')) define('DIR_WS_HTTP_CATALOG', DIR_WS_CATALOG);
define('TEXT_EMAIL_ALREADY_SEND', 'was already sent: ');
define('TEXT_EMAIL_SEND', 'successfully sent: ');
require_once(DIR_FS_CATALOG. 'mailhive/common/functions/compatibility.php');
require_once(DIR_FS_CATALOG. 'mailhive/common/classes/mailbeez.php');
require(DIR_FS_CATALOG . 'mailhive/common/classes/mailhive.php');
include(DIR_WS_CLASSES . 'order.php');
function zen_remove_order($order_id, $restock = false) {
global $db;
if ($restock == 'on') {
$order = $db->Execute("select products_id, products_quantity
from " . TABLE_ORDERS_PRODUCTS . "
where orders_id = '" . (int)$order_id . "'");
while (!$order->EOF) {
$db->Execute("update " . TABLE_PRODUCTS . "
set products_quantity = products_quantity + " . $order->fields['products_quantity'] . ", products_ordered = products_ordered - " . $order->fields['products_quantity'] . " where products_id = '" . (int)$order->fields['products_id'] . "'");
$order->MoveNext();
}
}
$db->Execute("delete from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");
$db->Execute("delete from " . TABLE_ORDERS_PRODUCTS . "
where orders_id = '" . (int)$order_id . "'");
$db->Execute("delete from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . "
where orders_id = '" . (int)$order_id . "'");
$db->Execute("delete from " . TABLE_ORDERS_STATUS_HISTORY . "
where orders_id = '" . (int)$order_id . "'");
$db->Execute("delete from " . TABLE_ORDERS_TOTAL . "
where orders_id = '" . (int)$order_id . "'");
}
function format_phone($num)
{
$num = ereg_replace('[^0-9]', '', $num);
$len = strlen($num);
if($len == 7)
$num = preg_replace('/([0-9]{3})([0-9]{4})/', '$1-$2', $num);
elseif($len == 10)
$num = preg_replace('/([0-9]{3})([0-9]{3})([0-9]{4})/', '($1) $2-$3', $num);
return $num;
}
function format_creditcard($cc)
{
// Clean out extra data that might be in the cc
$cc = str_replace(array('-',' '),'',$cc);
// Get the CC Length
$cc_length = strlen($cc);
// Initialize the new credit card to contian the last four digits
$newCreditCard = substr($cc,-4);
// Walk backwards through the credit card number and add a dash after every fourth digit
for($i=$cc_length-5;$i>=0;$i--){
// If on the fourth character add a dash
if((($i+1)-$cc_length)%4 == 0){
$newCreditCard = '-'.$newCreditCard;
}
// Add the current character to the new credit card
$newCreditCard = $cc[$i].$newCreditCard;
}
// Return the formatted credit card number
return $newCreditCard;
}
$red = (isset($_GET['red']) ? $_GET['red'] : '');
$monthyear = (isset($_GET['month_year']) ? $_GET['month_year'] : '');
$sales_term = (isset($_GET['sales_term']) ? $_GET['sales_term'] : 'pct_total');
//$sales_report = (isset($_GET['sales_report']) ? $_GET['month-year'] : '');
if ($red=='sales_report'){
//echo $display_header;
//$monthyear='2017-12';
//$sales_term ='pct_subtotal';
$order_results_raw = "select o.orders_id, o.customers_id, o.customers_name, o.delivery_street_address,o.order_total,
o.payment_method, o.shipping_method, DATE_FORMAT(o.date_purchased, '%m/%d %h:%i' ) as date_purchased, ot.value as order_subtotal
from " . TABLE_ORDERS . " o
left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id)
where ot.class = 'ot_subtotal'
AND DATE_FORMAT( o.date_purchased, '%Y-%m' ) = '" .$monthyear. "'
order by o.orders_id DESC";
$order_results = $db->Execute($order_results_raw);
//construct sale report
$report_info = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<header><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
table {
width: 100%;
font-size: 0.7em;
font-family: Arial, Helvetica, sans-serif;
margin-left:auto;
margin-right:auto;
border-collapse: collapse;
}
.dataTableContent {
font-size: 95%;
}
</style>
</header>
<BODY STYLE="font-family: Lucida Sans, sans-serif">
<u>
<h3> RED PASSION '. $monthyear . ' Order Report: ' . STORE_NAME . "</a></h3></u>" .
'<br><br><table border="1" width="100%" cellspacing="0" cellpadding="0">
<tr class="dataTableHeadingRow">
<th class="dataTableHeadingContent" align="left">ID</th>
<th class="dataTableHeadingContent" align="left">Name</th>
<th class="dataTableHeadingContent" align="left">Address</th>
<th class="dataTableHeadingContent" align="left">Total</th>
';
if ($sales_term =='pct_subtotal') {
$report_info .= '<th class="dataTableHeadingContent" align="left">SubTotal</th>';
}
$report_info .= '
<th class="dataTableHeadingContent" align="left">Date</th>
<th class="dataTableHeadingContent" align="left">Type</th>
<th class="dataTableHeadingContent" align="left">Paid</th>
</tr>
';
$mysubtotal = 0;
$total = 0;
$num_orders = 0;
//(!$today_orders->EOF)
//echo $report_info;
while (!$order_results->EOF) {
$shipping = explode (' ', $order_results->fields['shipping_method']);
$payment = explode (' ', $order_results->fields['payment_method']);
$report_info .= '
<tr class="dataTableRow" >
<td class="dataTableContent" align="left">' . $order_results->fields['orders_id'] . '</td>
<td class="dataTableContent" align="left">' . $order_results->fields['customers_name'] . '</td>
<td class="dataTableContent" align="left">' . $order_results->fields['delivery_street_address'] . '</td>
<td class="dataTableContent" align="left">' . $order_results->fields['order_total'] . '</td>
';
if ($sales_term =='pct_subtotal') {
$report_info .= '
<td class="dataTableContent" align="left">' . round($order_results->fields['order_subtotal'],2) . '</td>
';
}
$report_info .= '
<td class="dataTableContent" align="left">' . $order_results->fields['date_purchased'] . '</td>
<td class="dataTableContent" align="left">' . $shipping[0] . '</td>
<td class="dataTableContent" align="left">' . $payment[0] . '</td>
</tr>
';
$num_orders ++;
$mysubtotal += round($order_results->fields['order_subtotal'],2);
$total += $order_results->fields['order_total'];
$order_results->MoveNext();
}
$report_info .= '
<tr>
<td class="dataTableContent" align="left" colspan="3" >Order Counts: ' . $num_orders . '</td>
';
if ($sales_term =='pct_subtotal') {
$report_info .= '
<td class="dataTableContent" align="left" colspan="3" > Subtotal: $' . $mysubtotal . '</td>
';
}
$report_info .= '
<td class="dataTableContent" align="Right" colspan="3" >Total: $' . $total . '</td>
</tr>
';
$report_info .= '</table></body></html>';
//end of report
echo $report_info;
}
if ($red !='order'){exit;}
// prepare order-status pulldown list
$orders_statuses = array();
$orders_status_array = array();
$orders_status = $db->Execute("select orders_status_id, orders_status_name
from " . TABLE_ORDERS_STATUS . "
where language_id = '" . (int)$_SESSION['languages_id'] . "'");
while (!$orders_status->EOF) {
$orders_statuses[] = array('id' => $orders_status->fields['orders_status_id'],
'text' => $orders_status->fields['orders_status_name'] . ' [' . $orders_status->fields['orders_status_id'] . ']');
$orders_status_array[$orders_status->fields['orders_status_id']] = $orders_status->fields['orders_status_name'];
$orders_status->MoveNext();
}
$order_exists = false;
if (isset($_GET['oID']) && trim($_GET['oID']) == '') unset($_GET['oID']);
if (isset($_GET['oID'])) {
$my_option = explode("-", zen_db_prepare_input(trim($_GET['oID'])));
$oID = $my_option[0];
if ($oID =='last'){
$current_time= time();
$day_of_week = strtoupper(date(l,$current_time));
$c_day = date(d,$current_time);
$c_month = date(m,$current_time);
$c_year = date(Y,$current_time);
$store_start = constant('MODULE_SHIPPING_STOREHOURS_START_' . $day_of_week);
//$store_deliverystart = constant('MODULE_SHIPPING_DELIVERY_START_' . $day_of_week);
//$store_deliveryend = constant('MODULE_SHIPPING_DELIVERY_END_' . $day_of_week);
$store_end = constant('MODULE_SHIPPING_STOREHOURS_END_' . $day_of_week);
$isopen = constant('MODULE_SHIPPING_STOREHOURS_OPCL_' . $day_of_week);
list($starth,$startm ) = split("[:]",$store_start);
list($endh,$endm ) = split("[:]",$store_end);
$starttime=mktime($starth,$startm,0,$c_month,$c_day,$c_year);
$endtime=mktime($endh,$endm,0,$c_month,$c_day,$c_year);
//$delivery_starttime = 0; // set to begin of day by default
//$delivery_endtime = mktime(23,59,0,$c_month,$c_day,$c_year); ///set to end of day by default
//$open_delivery = 1;// we delivery
if ((($current_time > $starttime ) && ( $current_time < $endtime ) ) && ($isopen =='1')){ //in between store hours
$sql = "SELECT max(orders_id) oid FROM ". TABLE_ORDERS . " where orders_status < 3
and DATE(date_purchased) = CURDATE() ORDER BY orders_id ASC;
";
$queryResult = $db->Execute($sql);
if ($queryResult->RecordCount() <= 0) {
$oID = '0';
}else {
$oID = $queryResult->fields['oid'];
}
//$oID = $queryResult->fields['oid'];
}else {
$oID = '0';
}
}
//echo "JOe" .$oID ;
// $oID = zen_db_prepare_input($_GET['oID']);
$zf_insert_id = $oID;
if ($red !='order'){exit;}
if ($oID <1300){exit;}
$orders_check = $db->Execute("select * from " . TABLE_ORDERS . "
where orders_id = '" . (int)$oID . "'");
$order_exists = true;
$cvv = '000';
if ($orders_check->RecordCount() <= 0) {
$order_exists = false;
}else {
$order = new order($zf_insert_id);
$cvv = $orders_check->fields['cc_cvv'];
}
}else{
exit;
}
$mailHive= new mailHive;
$mailhive_token = MAILBEEZ_MAILHIVE_TOKEN;
// call external module action e.g. block
if ( isset($_GET['ma']) ) {
$module_action = $_GET['ma'];
$module = (isset($_GET['m'])) ? $_GET['m'] : false;
$module_params = (isset($_GET['mp'])) ? $_GET['mp'] : false;
$result = $mailHive->moduleAction($module, 'external_' .$module_action, $module_params);
}
//
if (isset($_GET[$mailhive_token]) ) {
$mpaction = $_GET[$mailhive_token];
} elseif (isset($_POST[$mailhive_token]) ) {
$mpaction = $_POST[$mailhive_token];
}
$output_plain = false;
if ($mpaction == 'view') {
$output_plain = true;
}
if ($output_plain == false) {
//use timezon setting //$current_time= time() - 60 * 60; // adjust tomezone server time is Easten time $orders_check->fields['cc_cvv']
$current_time = strtotime($order->info['date_purchased']);
$current_time_string = date('m/d D g:iA', $current_time);
//$pickup_asap = $current_time + 60 * 15;
$delivery_asap = $current_time + 60 * (int)(MODULE_SHIPPING_STOREHOURS_DELIVERY_DELAY);
$my_delivery = explode("::", zen_db_output($order->info['order_delivery_date']));
$delivery_text = "DELIVERY(外送):";
$delivery_time = "<b><font color=red size=3>Future(预订) </font></b>";
$pay_mathod = $order->info['payment_method'];
if ($order->info['shipping_module_code'] == 'storepickup') {
$delivery_text = "PICKUP(来拿):";
if (zen_db_output($order->info['order_delivery_date']) == 'NONE') { $delivery_time = "ASAP(尽快)"; }
}else {
if (zen_db_output($order->info['order_delivery_date']) == 'NONE') { $delivery_time = "ASAP(尽快)Before:". date('g:iA',$delivery_asap); }
//if (zen_db_output($order->info['order_delivery_date']) == 'NONE') { $delivery_time = "ASAP (尽快)"; }
}
$delivery_text .= ' ' . $pay_mathod;
$delivery_time .= ' ' . $my_delivery[2];
header('Content-Type: text/html; charset=UTF-8');
}
if (($mpaction == 'order') && ($order_exists)) {
//
$products_ordered_htm ='';
$products_ordered_htm_java ='';
for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
if ($order->products[$i]['qty'] >1) {
$products_ordered_htm .= ' <tr class="dataTableRow">' . "\n" .
' <td class="dataTableContent" valign="top" align="left" width="10%">' . $order->products[$i]['qty'] . ' </td>' . "\n" .
' <td valign="top" width="80%"><b><font FACE="Lucida Sans, sans-serif" size=3>' . $order->products[$i]['name'];
$products_ordered_htm_java .= ' <tr>' . "\n" .
' <td valign="top" align="left" width="10%">' . $order->products[$i]['qty'] . ' </td>' . "\n" .
' <td valign="top" width="80%"><span class="b3">' . $order->products[$i]['name'];
}else{
$products_ordered_htm .= ' <tr class="dataTableRow">' . "\n" .
' <td class="dataTableContent" valign="top" align="left" width="10%">' . ' </td>' . "\n" .
' <td valign="top" width="80%"><b><font FACE="Lucida Sans, sans-serif" size=3>' . $order->products[$i]['name'];
$products_ordered_htm_java .= ' <tr>' . "\n" .
' <td valign="top" align="left" width="10%">' . ' </td>' . "\n" .
' <td valign="top" width="80%"><span class="b3">' . $order->products[$i]['name'];
}
if (isset($order->products[$i]['attributes']) && (($k = sizeof($order->products[$i]['attributes'])) > 0)) {
for ($j = 0; $j < $k; $j++) {
if (nl2br(zen_output_string_protected($order->products[$i]['attributes'][$j]['value'])) !='None'){
// $products_ordered_htm .= '<br><small> <i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . nl2br(zen_output_string_protected($order->products[$i]['attributes'][$j]['value']));
if ($order->products[$i]['attributes'][$j]['option'] == 'Sp. Request:') {
$products_ordered_htm .= '<br><small> <i> *Customer asked: ' . nl2br(zen_output_string_protected($order->products[$i]['attributes'][$j]['value']));
$products_ordered_htm_java .= '<br><div class="customerask"> <i> *Customer asked: ' . nl2br(zen_output_string_protected($order->products[$i]['attributes'][$j]['value']));
if ($order->products[$i]['attributes'][$j]['price'] != '0') $products_ordered_htm .= ' (' . $order->products[$i]['attributes'][$j]['prefix'] . $currencies->format($order->products[$i]['attributes'][$j]['price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . ')';
$products_ordered_htm_java .= ' (' . $order->products[$i]['attributes'][$j]['prefix'] . $currencies->format($order->products[$i]['attributes'][$j]['price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . ')';
if ($order->products[$i]['attributes'][$j]['product_attribute_is_free'] == '1' and $order->products[$i]['product_is_free'] == '1') $products_ordered_htm .= TEXT_INFO_ATTRIBUTE_FREE;
$products_ordered_htm .= '</i></small>';
$products_ordered_htm_java .= '</i></div>';
}else {
$products_ordered_htm .= '<br><small> <i> ** ' . nl2br(zen_output_string_protected($order->products[$i]['attributes'][$j]['value']));
$products_ordered_htm_java .= '<br><div class="customerask"> <i> ** ' . nl2br(zen_output_string_protected($order->products[$i]['attributes'][$j]['value']));
if ($order->products[$i]['attributes'][$j]['price'] != '0') $products_ordered_htm .= ' (' . $order->products[$i]['attributes'][$j]['prefix'] . $currencies->format($order->products[$i]['attributes'][$j]['price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . ')';
$products_ordered_htm_java .= ' (' . $order->products[$i]['attributes'][$j]['prefix'] . $currencies->format($order->products[$i]['attributes'][$j]['price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . ')';
if ($order->products[$i]['attributes'][$j]['product_attribute_is_free'] == '1' and $order->products[$i]['product_is_free'] == '1') $products_ordered_htm .= TEXT_INFO_ATTRIBUTE_FREE;
$products_ordered_htm .= '</i></small>';
$products_ordered_htm_java .= '</i></div>';
}
}
}
}
$products_ordered_htm .= ' </font> </b></td>' ;
$products_ordered_htm_java .= ' </font> </b></td>' ;
$products_ordered_htm .=
' <td align="right" valign="top"><b>' .
$currencies->format(zen_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) .
($order->products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->format(zen_add_tax($order->products[$i]['onetime_charges'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) : '') .
'</b></td>' ;
$products_ordered_htm_java .=
' <td class="dataTableContent" align="right" valign="top"><b>' .
$currencies->format(zen_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) .
($order->products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->format(zen_add_tax($order->products[$i]['onetime_charges'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) : '') .
'</b></td>' ;
$products_ordered_htm .= ' </tr>';
$products_ordered_htm_java .= ' </tr>';
}
$my_site = explode("/", HTTP_SERVER);
$my_web = preg_replace('/www\./', '', $my_site[2]);
$refax_info = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<header>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</header>
<BODY STYLE="font-family: Lucida Sans, sans-serif">';
$direct_print = $refax_info ;
$direct_print .= '<style> body {width:280px; } </style>';
$display_header = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<header>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</header>
<BODY STYLE="font-family: Lucida Sans, sans-serif">';
$java_print = '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style>
body {
font-family: Lucida Sans, sans-serif;}
.b3 {font-weight: bold; font-size: 8px;}
.b2 {font-weight: bold; font-size: 6px;}
.b1 {font-weight: bold; font-size: 5px;}
.totalRow td {height: 6px; padding-bottom: 0px;padding-top: 0px;}
.customerask {font-size: 5px; font-weight: bold; font-style: italic;}
table {font-size: 6px; width:140px;border="0";cellspacing="0";}
</style>
</head>
<body><table><tr><td>
<div>RED PASSION: (8 8 8) 387-3312<br>';
$fax_info = ' <u><font size=3> RED PASSION: (8 8 8) 387-3312<br>' . " <a href=\"". HTTP_SERVER ."\">" . preg_replace('/\(.*?\)/', '', STORE_NAME) . "</a>" .
" # <a href=\"" . HTTP_SERVER . DIR_WS_CATALOG . 'show_order.php?red=order&oID=' . $zf_insert_id . "\">" . $zf_insert_id . "</a></font></u><br>" .
'<b><font size=4>' . $delivery_text . '</font><br> <font size=4>' . $delivery_time .
'</b><br> Order@:<b>' . $current_time_string .
'</font></b><table border="0" width="100%" cellspacing="0" cellpadding="2"><tr><td valign="top" width="100%">';
$java_print .= preg_replace('/\(.*?\)/', '', STORE_NAME) .' <span id="orderNum">'. $zf_insert_id . '</span></div>';
$direct_print .= ' <u><font size=2> RED PASSION: (8 8 8) 387-3312<br>' . " <a href=\"". HTTP_SERVER ."\">" . preg_replace('/\(.*?\)/', '', STORE_NAME) . "</a>" .
" # <a href=\"" . HTTP_SERVER . DIR_WS_CATALOG . 'show_order.php?red=order&oID=' . $zf_insert_id . "\">" . $zf_insert_id . "</a></font></u>" .
'<br><b><font size=3>' . $delivery_text . '</font><br> <font size=2>' . $delivery_time .
'</b><br> Order@:<b>' . $current_time_string .
'</font></b><table border="0" width="100%" cellspacing="0" cellpadding="2"><tr><td valign="top" width="100%">';
$java_print .= '<div class="b3">' . $delivery_text . '</div>
<div class="b2">'.$delivery_time.'<br></div>
<div>Order@:<span class="b2">'. $current_time_string . '</span></div>';
// ----------------------------<br>';
//Delivery address
if ($order->info['shipping_module_code'] != 'storepickup') {
$my_address = $order->delivery['delivery_company'] . " " . $order->delivery['street_address'] . " " .$order->delivery['suburb'] . ", " . $order->delivery['city'].", ". $order->delivery['state']." ". $order->delivery['postcode'] ;
$fax_info .= '--------------------'. '<br><strong><font FACE="Lucida Sans, sans-serif" size=4>' .
'<a href="https://maps.google.com?saddr=Current+Location&daddr='. urlencode($my_address).'&sensor=false&avoid=highways">' . $my_address . "</a></font></strong><br>";
$direct_print .= '--------------------'. '<br><strong><font FACE="Lucida Sans, sans-serif" size=3>' .
'<a href="https://maps.google.com?saddr=Current+Location&daddr='. urlencode($my_address).'&sensor=false&avoid=highways">' . $my_address . "</a></font></strong><br>";
$java_print .= '<div class="b3">' . $my_address. '</div>';
}
$fax_info .= $order->customer['telephone'].' <a href="mailto:'.$order->customer['email_address'] . '">' .
$order->customer['name'] . '</a> ' ;
$direct_print .= $order->customer['telephone'].' '. $order->customer['name'];
$java_print .= '<div>' . $order->customer['telephone']. ' '. $order->customer['name'] .'</div>';
$fax_info .= '</td></tr></table>';
$direct_print .= '</td></tr></table>';
/**
$fax_info .= '<hr><table border="0" width="100%" cellspacing="0" cellpadding="2">' .
'<tr>'. "\n" .
'<td align="left" valign="top" width="10%">QTY</td>' . "\n" .
'<td valign="top" align="left" width="80%">ITEMS</td>'. "\n" .
'<td valign="top" align="right" width="10%">PRICE</td></tr></table><hr>'. "\n" .
'<table border="0" width="100%" cellspacing="0" cellpadding="4">' .
$products_ordered_htm . '</table>';
**/
$fax_info .= '<hr>'. "\n" .
'<table border="0" width="100%" cellspacing="0" cellpadding="4">' .
$products_ordered_htm . '</table>';
$java_print .= '<table>
<tr><td colspan=3><hr></td></tr>' .$products_ordered_htm_java ;
$direct_print .= '<hr>'. "\n" .
'<table border="0" width="100%" cellspacing="0" cellpadding="4">' .
$products_ordered_htm . '</table>';
$fax_info .= '<table border="0" width="100%" cellspacing="0" cellpadding="2">' .
'<tr>'. "\n" .
'<td align="right" >' . ' ' . '</td> ' . "\n" . '<td></td><td align="right" nowrap="nowrap" colspan="2">' . '---------' .'</td> </tr>' . "\n" . '<tr>';
$direct_print .= '<table border="0" width="100%" cellspacing="0" cellpadding="2">' .
'<tr>'. "\n" .
'<td align="right" >' . ' ' . '</td> ' . "\n" . '<td></td><td align="right" nowrap="nowrap" colspan="2">' . '---------' .'</td> </tr>' . "\n" . '<tr>';
$java_print .= '<tr>
<td align="right" > </td>
<td align="right" nowrap="nowrap" colspan="2">-------------</td>
</tr>
<tr class="totalRow">';
$tip=0;
$total=0;
$shipping=0;
for ($i=0, $n=sizeof($order->totals); $i<$n; $i++) {
if ($order->totals[$i]['class'] == 'ot_tip'){$tip = preg_replace('/[\$,]/', '', $order->totals[$i]['text']);}
if ($order->totals[$i]['class'] == 'ot_shipping'){$shipping = $order->totals[$i]['value'];}
if ($order->totals[$i]['class'] == 'ot_total'){
$total = preg_replace('/[\$,]/', '', $order->totals[$i]['text']);
$fax_info .= '<td align="right" width="30%" ><font FACE="Lucida Sans, sans-serif" size=4></td><td align="right" nowrap="nowrap" width="20%"><font FACE="Lucida Sans, sans-serif" size=4> ' . $order->totals[$i]['title'] . '</font></td> ' . "\n" ;
$direct_print .= '<td align="right" width="30%" ><font FACE="Lucida Sans, sans-serif" size=2></td><td align="right" nowrap="nowrap" width="20%"><font FACE="Lucida Sans, sans-serif" size=2> ' . $order->totals[$i]['title'] . '</font></td> ' . "\n" ;
$java_print .= '<td align="right" nowrap="nowrap" colspan="2" ><span class="b2">'.$order->totals[$i]['title'] .'</span></td>';
}else {
$fax_info .= '<td></td><td align="right" nowrap="nowrap" colspam="2" ><font FACE="Lucida Sans, sans-serif" size=3> ' . $order->totals[$i]['title'] . '</font></td> ' . "\n" ;
$direct_print .= '<td></td><td align="right" nowrap="nowrap" colspam="2" ><font FACE="Lucida Sans, sans-serif" size=2> ' . $order->totals[$i]['title'] . '</font></td> ' . "\n" ;
$java_print .= '<td align="right" nowrap="nowrap" colspan="2" ><span class="b2">'.$order->totals[$i]['title'] .'</span></td>';
}
if (($order->totals[$i]['class'] == 'ot_tip') && ($tip == '0')) {
$fax_info .= '<td align="right" nowrap="nowrap" ><font szie=3> Pay Driver </font> </td> </tr>' . "\n" . '<tr>';
$direct_print .= '<td align="right" nowrap="nowrap" ><font szie=2> Pay Driver </font> </td> </tr>' . "\n" . '<tr>';
$java_print .= '<td align="right" nowrap="nowrap" ><span class="b3">Pay Driver</span></td><tr>';
}else {
$fax_info .= '<td align="right" nowrap="nowrap" ><font FACE="Lucida Sans, sans-serif" szie=3> <b>' .($order->totals[$i]['text']) .'</b> </font> </td> </tr>' . "\n" . '<tr>';
$direct_print .= '<td align="right" nowrap="nowrap" ><font FACE="Lucida Sans, sans-serif" szie=2> <b>' .($order->totals[$i]['text']) .'</b> </font> </td> </tr>' . "\n" . '<tr>';
$java_print .= '<td align="right" nowrap="nowrap" ><span class="b3">'.($order->totals[$i]['text']) .'</span></td><tr>';
}
}
$fax_info .= "</table>";
$direct_print .= "</table><hr>";
$java_print .= "</table>";
$before_tip = $total - $tip;
$subtotal_tax = $before_tip - $shipping;
$before_tip = '$'. $before_tip;
$subtotal_tax = '$'. $subtotal_tax;
//comments area
$fax_info .= '<table border="0" width="100%" cellspacing="0" cellpadding="2"> ' .
'<tr><td align="left" width="60%">';
$direct_print .= '<table border="0" width="100%" cellspacing="0" cellpadding="2"> ' .
'<tr><td align="left" width="60%">';
$java_print .='<table><tr><td><hr></td></tr> <tr><td align="left" width="60%">';
$orders_comment = $db->Execute("select comments
from " . TABLE_ORDERS_STATUS_HISTORY . "
where orders_id = '" . zen_db_input($oID) . "'
order by date_added ASC Limit 1");
//nl2br(zen_db_output($orders_comment->fields['comments']))
if ($orders_comment->fields['comments']) {
$fax_info .= zen_db_output($orders_comment->fields['comments']) . "\n";
$direct_print .= zen_db_output($orders_comment->fields['comments']) . "\n";
$java_print .= zen_db_output($orders_comment->fields['comments']) . "\n";
} else {
$fax_info .= 'Thanks';
$direct_print .= 'Thanks';
$java_print .= 'Thanks';
}
//$fax_info .= '</td><td class="order-totals-text" align="right" width="20%">Subtotal w Tax: ' .($subtotal_tax) . '</td> ' . "\n" .
//'<td class="order-totals-text" align="right" width="20%">Subtotal w/o Tip: ' .($before_tip) . '</td> </tr>' . "\n";
$fax_info .= "</table><hr><font size=3>";
$java_print .= '<tr><td><hr></td></tr></table><div>';
$direct_print .= "</table><hr><font size=3>";
$fax_info .= (isset($order->info['cc_type']) && $order->info['cc_type'] != '') ? $order->info['cc_type'] .
' <b>' . format_creditcard($order->info['cc_number']). "</b> Exp: <b>" . $order->info['cc_expires']."</b> CVV: <b>" . $cvv . '</b> Zip: <b>'. $order->billing['postcode'] ."</b></font><br>" : '';
$java_print .= (isset($order->info['cc_type']) && $order->info['cc_type'] != '') ? $order->info['cc_type'] .
' <b>' . format_creditcard($order->info['cc_number']). "</b> Exp: <b>" . $order->info['cc_expires']."</b> CVV: <b>" . $cvv . '</b> Zip: <b>'. $order->billing['postcode'] ."</b></div>" : '';
$direct_print .= (isset($order->info['cc_type']) && $order->info['cc_type'] != '') ? $order->info['cc_type'] .
' <b>' . format_creditcard($order->info['cc_number']). "</b> Exp: <b>" . $order->info['cc_expires']."</b> CVV: <b>" . $cvv . '</b> Zip: <b>'. $order->billing['postcode'] ."</b></font><br>" : '';
if ($order->info['shipping_module_code'] != 'storepickup') {
$fax_info .= '</b><font size=3>#' . $zf_insert_id . " " .'Subtotal w Tax:' . $subtotal_tax . " " . 'Subtotal w/o Tip:'. $before_tip .
' <b>Total: $' . $total .'</b></font>';
$direct_print .= '</b><font size=2>#' . $zf_insert_id . " " .'Subtotal w Tax:' . $subtotal_tax . " " . 'Subtotal w/o Tip:'. $before_tip .
' <b>Total: $' . $total .'</b></font>';
$java_print .= '<div>#' . $zf_insert_id . " " .'Subtotal w Tax:' . $subtotal_tax . " " . 'Subtotal w/o Tip:'. $before_tip .
' <b>Total: $' . $total .'</b></div>';
}
$direct_print .= '</td></tr></table></body>
<html>';
$java_print .= '</td></tr></table></body>
<html>';
//build redfax page
$refax_info .= $fax_info . '</body></html>'; ;
$JattachArray = array();
$attachFileTextContent = $refax_info;
//$this->JattachArray = array("raw_data" => $attachFileTextContent, "order_number" => $zf_insert_id );
$JattachArray['raw_data'] = $attachFileTextContent;
$JattachArray['mime_type'] = 'text/html';
$JattachArray['name'] = STORE_NAME . $zf_insert_id .'.html'; // filename that the $attachFileTextContent attachment will have inside the email
//set all options
//switch (MODULE_SHIPPING_ZIPSHIP_FAX_SERVER) {
$pieces = explode(",", SEND_EXTRA_ORDER_EMAILS_TO);
$MYPHONE = STORE_PHONE;
switch ($my_option[1]) {
case 'recall':
//just email to rcfax for fax
echo $display_header;
echo " <h3> Message was sent to customer.</h3>";
echo $fax_info;
if (STORE_PHONE != '') {
//$call_url = 'https://service.ringcentral.com/ringout.asp?cmd=call&username=18883873312&ext=101&password=Alena1129&from='. STORE_PHONE .'&to=2622047707&clid=8883873312&prompt=0';
//$dir_result = utf8_encode(file_get_contents($call_url));
require_once(DIR_FS_CATALOG.'ringcentral/ringcentral.phar');
try {
//RingCentral\SDK\SDK::SERVER_SANDBOX RingCentral\SDK\SDK::SERVER_PRODUCTION 8bTYD-nRRN65AYU0gH3cSg
//$sdk = new RingCentral\SDK\SDK('5Z9d86cFSniG5TB4NPvvuQ', 'WVd87RDkTfyMdeQF9X5OfwQ88AhG1RQaK-r65Dd92L5w', 'https://platform.devtest.ringcentral.com', 'Demo', '1.0.0');
$sdk = new RingCentral\SDK\SDK('Cv_ZTTp9Tk-M4cMXBFPBeQ', 'bQ2C_2PrSJOY_jPPki68UQMRGB5yoASbyHUXCQkYQxDQ', 'https://platform.ringcentral.com', 'redpassionPROD', '1.0.0');
//$sdk->platform()->login('12679304359', '101', 'Alena1129');
$sdk->platform()->login('18883873312', '101', 'Alena1129');
//$sdk->platform()->login('18883873312', '103', 'menu88$$');
//echo $message; 8477921688
$phone_table = preg_split("/[,]/" , STORE_PHONE);
$size = sizeof($phone_table);
for ($i=0; $i<$size; $i++) {
$apiResponse = $sdk->platform()->post('/account/~/extension/~/ring-out', array(
//'from' => array('phoneNumber' => '12679304359'),
//'from' => array('phoneNumber' => '18474816091'),
'from' => array('phoneNumber' => '12622047707'),
'to' => array('phoneNumber' =>$phone_table[$i]),
));
}
} catch (\RingCentral\SDK\Http\ApiException $e) {
$from = 'jhuang@redpassionhost.com';
$subject = 'Red Passion:'. (int)$zf_insert_id;
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$message = ' '. HTTP_SERVER . DIR_WS_CATALOG . 'show_order.php?red=order&oID=' . (int)$zf_insert_id .'-recall ';
$message .= $phone_table[0] . ' API Error: ' . $e->getMessage() . PHP_EOL;
mail('spancfreedom@gmail.com', $subject, $message, $headers);
}
}
break;
case 'fax':
//just email to rcfax for fax
echo $display_header;
echo " <h3> Message was sent to customer.</h3>";
echo $fax_info;
if ((MODULE_SHIPPING_ZIPSHIP_FAX_SERVER == 'rcfax.com') || (MODULE_SHIPPING_ZIPSHIP_FAX_SERVER == 'metrofax.com')) {
zen_mail('', MODULE_SHIPPING_STORE_FAX_NUMBER . '@rcfax.com', '',
'empty', STORE_NAME, 'sales@redpassionhost.com', $html_msg, 'checkout_extra', $JattachArray);
}elseif (MODULE_SHIPPING_ZIPSHIP_FAX_SERVER == 'eprint') {
zen_mail('', $pieces[1], MODULE_SHIPPING_STORE_FAX_NUMBER . EMAIL_ORDER_NUMBER_SUBJECT . $zf_insert_id,
'empty', STORE_NAME, 'spancfreedom@gmail.com', $html_msg, 'checkout_extra', $JattachArray);
}else {
zen_mail('', SEND_EXTRA_ORDER_EMAILS_TO, MODULE_SHIPPING_STORE_FAX_NUMBER . EMAIL_ORDER_NUMBER_SUBJECT . $zf_insert_id,
$email_order_owner . $extra_info['TEXT'], STORE_NAME, EMAIL_FROM, $html_msg, 'checkout_extra', $JattachArray, 'htmlonly', $refax_info);
}
break;
case 'rcfax':
//upload to rcfax
echo $display_header;
echo " <h3> Message was sent to customer.</h3>";
echo $fax_info;
if ((MODULE_SHIPPING_ZIPSHIP_FAX_SERVER == 'rcfax.com') || (MODULE_SHIPPING_ZIPSHIP_FAX_SERVER == 'metrofax.com')) {
$myurl = 'https://service.ringcentral.com/faxapi.asp'; // RingCentral FaxOut API URL
$RCUsername = "18883873312"; // RingCentral Fax Username (10-digit RC phone number)
$RCPassword = "Alena1129"; // RingCentral password (5-10 numeric digits)
$recipientFax = MODULE_SHIPPING_STORE_FAX_NUMBER; // Recipient 10-digit Fax number
//set data (in this example from post)
$mypostdata = array(
'Username' => $RCUsername,
'Password' => $RCPassword,
'Recipient' => $recipientFax,
'coverpage' => '0', //None =0
'Resolution' => '2' //Low =2
);
//sample image
$files['Attachment'] = $JattachArray['name'] ;
//ringcentral api
$api_result = do_post_request($myurl, $mypostdata, $refax_info, $files);
if ($api_result != '0') {$api_result = send_metrofax($zf_insert_id, $refax_info);};
}elseif (MODULE_SHIPPING_ZIPSHIP_FAX_SERVER == 'eprint') {
zen_mail('', $pieces[1], MODULE_SHIPPING_STORE_FAX_NUMBER . EMAIL_ORDER_NUMBER_SUBJECT . $zf_insert_id,
'empty', STORE_NAME, 'spancfreedom@gmail.com', $html_msg, 'checkout_extra', $JattachArray);
}else {
zen_mail('', SEND_EXTRA_ORDER_EMAILS_TO, MODULE_SHIPPING_STORE_FAX_NUMBER . EMAIL_ORDER_NUMBER_SUBJECT . $zf_insert_id,
$email_order_owner . $extra_info['TEXT'], STORE_NAME, EMAIL_FROM, $html_msg, 'checkout_extra', $JattachArray, 'htmlonly', $refax_info);
}
$db->Execute("update " . TABLE_ORDERS . "
set orders_status = '2', last_modified = now()
where orders_id = '" . (int)$zf_insert_id . "'");
break;
case 'metrofax':
//upload to metrofax
echo $display_header;
echo " <h3> Message was sent to customer.</h3>";
echo $fax_info;
if ((MODULE_SHIPPING_ZIPSHIP_FAX_SERVER == 'rcfax.com') || (MODULE_SHIPPING_ZIPSHIP_FAX_SERVER == 'metrofax.com')) {
$api_result = send_metrofax($zf_insert_id, $refax_info);
if ($api_result != '0') {echo '<h1> fax error: ' . $api_result. ' </h1>'; };
}elseif (MODULE_SHIPPING_ZIPSHIP_FAX_SERVER == 'eprint') {
zen_mail('', $pieces[1], MODULE_SHIPPING_STORE_FAX_NUMBER . EMAIL_ORDER_NUMBER_SUBJECT . $zf_insert_id,
'empty', STORE_NAME, 'spancfreedom@gmail.com', $html_msg, 'checkout_extra', $JattachArray);
}else {
zen_mail('', SEND_EXTRA_ORDER_EMAILS_TO, MODULE_SHIPPING_STORE_FAX_NUMBER . EMAIL_ORDER_NUMBER_SUBJECT . $zf_insert_id,
$email_order_owner . $extra_info['TEXT'], STORE_NAME, EMAIL_FROM, $html_msg, 'checkout_extra', $JattachArray, 'htmlonly', $refax_info);
}
break;
case 'upd':
echo $display_header;
echo " <h3> Message was sent to customer.</h3>";
if (isset($_GET['status']) && ($_GET['notify'] == 'on') && isset($_GET['comments'])) {
$status = zen_db_prepare_input($_GET['status']);
$comments = zen_db_prepare_input($_GET['comments']);
$notify = zen_db_prepare_input($_GET['notify']);
$order_updated = false;
// $check_status = $db->Execute("select customers_name, customers_email_address, orders_status,
// date_purchased, COWOA_order from " . TABLE_ORDERS . "
// where orders_id = '" . (int)$zf_insert_id . "'");
$check_status = $db->Execute("select customers_name, customers_email_address, orders_status, order_delivery_date,
date_purchased from " . TABLE_ORDERS . "
where orders_id = '" . (int)$zf_insert_id . "'");
if ($check_status->fields['order_delivery_date'] == 'NONE') {
$check_status->fields['order_delivery_date'] = 'ASAP';
}
/**
if ( ($check_status->fields['orders_status'] != $status) || zen_not_null($comments)) {
$db->Execute("update " . TABLE_ORDERS . "
set orders_status = '" . zen_db_input($status) . "', last_modified = now()
where orders_id = '" . (int)$zf_insert_id . "'");
}
**/
}
$notify_comments = '';
if (($_GET['notify'] == 'on') && zen_not_null($comments)) {
$notify_comments = EMAIL_TEXT_COMMENTS_UPDATE . $comments . "\n\n";
}
//send emails
$message = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" .
EMAIL_TEXT_ORDER_NUMBER . ' ' . $zf_insert_id . "\n\n";
if(!$check_status->fields['COWOA_order']) {
$message .= EMAIL_TEXT_INVOICE_URL . ' ' . zen_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . $zf_insert_id, 'SSL') . "\n\n";
}
$message .= EMAIL_TEXT_DATE_ORDERED . ' ' . date('m/d/y g:i A', strtotime($check_status->fields['date_purchased'])) . "\n\n" .
strip_tags($notify_comments) .
EMAIL_TEXT_STATUS_UPDATED . sprintf(EMAIL_TEXT_STATUS_LABEL, $orders_status_array[$status] ) .
EMAIL_TEXT_STATUS_PLEASE_REPLY;
$html_msg['EMAIL_CUSTOMERS_NAME'] = $check_status->fields['customers_name'];
$html_msg['EMAIL_TEXT_ORDER_NUMBER'] = EMAIL_TEXT_ORDER_NUMBER . ' ' . $zf_insert_id;
$html_msg['EMAIL_TEXT_INVOICE_URL'] = '<a href="' . zen_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . $zf_insert_id, 'SSL') .'">'.str_replace(':','',EMAIL_TEXT_INVOICE_URL).'</a>';
$html_msg['EMAIL_TEXT_DATE_ORDERED'] = EMAIL_TEXT_DATE_ORDERED . ' ' . date('m/d/y g:i A', strtotime($check_status->fields['date_purchased']));
//$html_msg['EMAIL_TEXT_DELIVERY_DATE'] = EMAIL_TEXT_DELIVERY_DATE . ' ' . date('m/d/y g:i A', strtotime($check_status->fields['order_delivery_date']));
$html_msg['EMAIL_TEXT_DELIVERY_DATE'] = EMAIL_TEXT_DELIVERY_DATE . ' ' . $check_status->fields['order_delivery_date'];
$html_msg['EMAIL_TEXT_STATUS_COMMENTS'] = nl2br($notify_comments);
$html_msg['EMAIL_TEXT_STATUS_UPDATED'] = str_replace('\n','', EMAIL_TEXT_STATUS_UPDATED);
$html_msg['EMAIL_TEXT_STATUS_LABEL'] = str_replace('\n','', sprintf(EMAIL_TEXT_STATUS_LABEL, $orders_status_array[$status] ));
$html_msg['EMAIL_TEXT_NEW_STATUS'] = $orders_status_array[$status];
$html_msg['EMAIL_TEXT_STATUS_PLEASE_REPLY'] = str_replace('\n','', EMAIL_TEXT_STATUS_PLEASE_REPLY);
$customer_notified = '0';
if ($notify == 'on') {
zen_mail($check_status->fields['customers_name'], $check_status->fields['customers_email_address'], EMAIL_TEXT_SUBJECT . ' #' . $zf_insert_id, $message, STORE_NAME, EMAIL_FROM, $html_msg, 'order_status');
$customer_notified = '1';
//send extra emails
// if (SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO_STATUS == '1' and SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO != '') {
zen_mail('', SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO, SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO_SUBJECT . $my_option[1] . ' ' . EMAIL_TEXT_SUBJECT . ' #' . $zf_insert_id, $message, STORE_NAME, EMAIL_FROM, $html_msg, 'order_status_extra');
// }
}
$db->Execute("insert into " . TABLE_ORDERS_STATUS_HISTORY . "
(orders_id, orders_status_id, date_added, customer_notified, comments)
values ('" . (int)$zf_insert_id . "',
'" . zen_db_input($status) . "',
now(),
'" . zen_db_input($customer_notified) . "',
'" . zen_db_input($comments) . "')");
$order_updated = true;
break;
case 'deliveried':
echo $display_header;
echo " <h3> Message was sent to customer.</h3>";
$status = '3';
$comments = 'Your delvery order is on the way.';
if ($my_option[2] =='callback'){
$comments = 'We could not reach you by phone please call Restaurant ' . format_phone($MYPHONE);
}
if ($my_option[2] =='badcredit'){
$comments = 'Your Credit card rejected pasyment. We could not reach you by phone please call Restaurant ' . format_phone($MYPHONE);
}
if ($my_option[2] =='driver'){
$comments = 'Driver is by your door. We could not reach you by phone please call Restaurant ' . format_phone($MYPHONE);
}
$notify = 'on';
$order_updated = false;
//shipping_module_code
$check_status = $db->Execute("select customers_name, customers_email_address, orders_status, shipping_module_code, order_delivery_date,
date_purchased from " . TABLE_ORDERS . "
where orders_id = '" . (int)$zf_insert_id . "'");
if (($check_status->fields['shipping_module_code'] !== 'zipship') && ($my_option[2] !=='callback')) {
$comments = 'Your order is ready for pickup.' ;
}
if ($check_status->fields['order_delivery_date'] == 'NONE') {
$check_status->fields['order_delivery_date'] = 'ASAP';
}
$notify_comments = '';
// if (($_GET['notify'] == 'on') && zen_not_null($comments)) {
$notify_comments = EMAIL_TEXT_COMMENTS_UPDATE . $comments . "\n\n";
// }
//send emails
$message = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" .
EMAIL_TEXT_ORDER_NUMBER . ' ' . $zf_insert_id . "\n\n";
if(!$check_status->fields['COWOA_order']) {
$message .= EMAIL_TEXT_INVOICE_URL . ' ' . zen_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . $zf_insert_id, 'SSL') . "\n\n";
}
$message .= EMAIL_TEXT_DATE_ORDERED . ' ' . date('m/d/y g:i A', strtotime($check_status->fields['date_purchased'])) . "\n\n" .
strip_tags($notify_comments) .
EMAIL_TEXT_STATUS_UPDATED . sprintf(EMAIL_TEXT_STATUS_LABEL, $orders_status_array[$status] ) .
EMAIL_TEXT_STATUS_PLEASE_REPLY;
$html_msg['EMAIL_CUSTOMERS_NAME'] = $check_status->fields['customers_name'];
$html_msg['EMAIL_TEXT_ORDER_NUMBER'] = EMAIL_TEXT_ORDER_NUMBER . ' ' . $zf_insert_id;
$html_msg['EMAIL_TEXT_INVOICE_URL'] = '<a href="' . zen_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . $zf_insert_id, 'SSL') .'">'.str_replace(':','',EMAIL_TEXT_INVOICE_URL).'</a>';
$html_msg['EMAIL_TEXT_DATE_ORDERED'] = EMAIL_TEXT_DATE_ORDERED . ' ' . date('m/d/y g:i A', strtotime($check_status->fields['date_purchased']));
$html_msg['EMAIL_TEXT_DELIVERY_DATE'] = EMAIL_TEXT_DELIVERY_DATE . ' ' . $check_status->fields['order_delivery_date'];
$html_msg['EMAIL_TEXT_STATUS_COMMENTS'] = nl2br($notify_comments);
$html_msg['EMAIL_TEXT_STATUS_UPDATED'] = str_replace('\n','', EMAIL_TEXT_STATUS_UPDATED);
$html_msg['EMAIL_TEXT_STATUS_LABEL'] = str_replace('\n','', sprintf(EMAIL_TEXT_STATUS_LABEL, $orders_status_array[$status] ));
$html_msg['EMAIL_TEXT_NEW_STATUS'] = $orders_status_array[$status];
$html_msg['EMAIL_TEXT_STATUS_PLEASE_REPLY'] = str_replace('\n','', EMAIL_TEXT_STATUS_PLEASE_REPLY);
$customer_notified = '0';
if ($notify == 'on') {
zen_mail($check_status->fields['customers_name'], $check_status->fields['customers_email_address'], EMAIL_TEXT_SUBJECT . ' #' . $zf_insert_id, $message, STORE_NAME, EMAIL_FROM, $html_msg, 'order_status');
$customer_notified = '1';
//send extra emails
// if (SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO_STATUS == '1' and SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO != '') {
zen_mail('', SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO, SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO_SUBJECT . $my_option[1] . $my_option[2] . ' ' . EMAIL_TEXT_SUBJECT . ' #' . $zf_insert_id, $message, STORE_NAME, EMAIL_FROM, $html_msg, 'order_status_extra');
// }
}
$db->Execute("insert into " . TABLE_ORDERS_STATUS_HISTORY . "
(orders_id, orders_status_id, date_added, customer_notified, comments)
values ('" . (int)$zf_insert_id . "',
'" . zen_db_input($status) . "',
now(),
'" . zen_db_input($customer_notified) . "',
'" . zen_db_input($comments) . "')");
$order_updated = true;
break;
case 'del':
echo $display_header;
echo " <h3> The order was deleted.</h3>";
echo $fax_info;
//send emails
$message = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" .
EMAIL_TEXT_ORDER_NUMBER . ' ' . $zf_insert_id . "\n\n";
$message .= EMAIL_TEXT_DATE_ORDERED . ' ' . date('m/d/y g:i A', strtotime($order->info['date_purchased'])) . "\n\n" .
'Order was caceled by customer or restaurant' .
EMAIL_TEXT_STATUS_UPDATED . sprintf(EMAIL_TEXT_STATUS_LABEL, 'Canceled' ) .
EMAIL_TEXT_STATUS_PLEASE_REPLY;
$html_msg['EMAIL_CUSTOMERS_NAME'] = $order->info['customers_name'];
$html_msg['EMAIL_TEXT_ORDER_NUMBER'] = EMAIL_TEXT_ORDER_NUMBER . ' ' . $zf_insert_id;
$html_msg['EMAIL_TEXT_INVOICE_URL'] = 'NONE';
$html_msg['EMAIL_TEXT_DATE_ORDERED'] = EMAIL_TEXT_DATE_ORDERED . ' ' . date('m/d/y g:i A', strtotime($order->info['date_purchased']));
$html_msg['EMAIL_TEXT_DELIVERY_DATE'] = EMAIL_TEXT_DELIVERY_DATE . ' ' . 'NONE';
$html_msg['EMAIL_TEXT_STATUS_COMMENTS'] = nl2br('Order was canceled by customer or restaurant.');
$html_msg['EMAIL_TEXT_STATUS_UPDATED'] = str_replace('\n','', EMAIL_TEXT_STATUS_UPDATED);
$html_msg['EMAIL_TEXT_STATUS_LABEL'] = str_replace('\n','', sprintf(EMAIL_TEXT_STATUS_LABEL, 'Canceled' ));
$html_msg['EMAIL_TEXT_NEW_STATUS'] = 'Canceled';
$html_msg['EMAIL_TEXT_STATUS_PLEASE_REPLY'] = str_replace('\n','', EMAIL_TEXT_STATUS_PLEASE_REPLY);
zen_mail($order->info['customers_name'], $order->info['customers_email_address'], EMAIL_TEXT_SUBJECT . ' #' . $zf_insert_id, $message, STORE_NAME, EMAIL_FROM, $html_msg, 'order_status');
//send extra emails
// if (SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO_STATUS == '1' and SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO != '') {
zen_mail('', SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO, SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO_SUBJECT . $my_option[1] . ' ' . EMAIL_TEXT_SUBJECT . ' #' . $zf_insert_id, $message, STORE_NAME, EMAIL_FROM, $html_msg, 'order_status_extra');
// }
zen_remove_order($zf_insert_id, $_POST['restock']);
break;
case 'confirm':
echo $display_header;
echo $fax_info;
//owner confirmed open the order
$status = '3'; //deliveried
$check_status = $db->Execute("select customers_name, customers_email_address, orders_status,
date_purchased from " . TABLE_ORDERS . "
where orders_id = '" . (int)$zf_insert_id . "'");
if ( ($check_status->fields['orders_status'] < $status) ) { //only return email when status = 1 or 2
zen_mail('', 'spanc07@gmail.com', MODULE_SHIPPING_STORE_FAX_NUMBER.' ' .'Opened & confirmed ' . $zf_insert_id,
'Owner opened this order.', STORE_NAME, EMAIL_FROM, $html_msg, 'checkout_extra', '');
// change to 3 so no more email
$db->Execute("update " . TABLE_ORDERS . "
set orders_status = '" . zen_db_input($status) . "', last_modified = now()
where orders_id = '" . (int)$zf_insert_id . "'");
}
break;
case 'directprint':
echo $direct_print;
//echo "<style> body {width:285px; } </style> " ;
//echo $fax_info;
//owner confirmed open the order
$status = '3'; //deliveried
$check_status = $db->Execute("select customers_name, customers_email_address, orders_status,
date_purchased from " . TABLE_ORDERS . "
where orders_id = '" . (int)$zf_insert_id . "'");
if ( ($check_status->fields['orders_status'] < $status) ) { //only return email when status = 1 or 2
zen_mail('', 'spanc07@gmail.com', MODULE_SHIPPING_STORE_FAX_NUMBER.' ' .'Opened & confirmed ' . $zf_insert_id,
'Owner opened this order.', STORE_NAME, EMAIL_FROM, $html_msg, 'checkout_extra', '');
// change to 3 so no more email
$db->Execute("update " . TABLE_ORDERS . "
set orders_status = '" . zen_db_input($status) . "', last_modified = now()
where orders_id = '" . (int)$zf_insert_id . "'");
}
break;
case 'javaprint':
echo $java_print;
$status = '3'; //deliveried
$check_status = $db->Execute("select customers_name, customers_email_address, orders_status,
date_purchased from " . TABLE_ORDERS . "
where orders_id = '" . (int)$zf_insert_id . "'");
if ( ($check_status->fields['orders_status'] < $status) ) { //only return email when status = 1 or 2
zen_mail('', 'spanc07@gmail.com', MODULE_SHIPPING_STORE_FAX_NUMBER.' ' .'Opened & confirmed ' . $zf_insert_id,
'Owner opened this order.', STORE_NAME, EMAIL_FROM, $html_msg, 'checkout_extra', '');
// change to 3 so no more email
$db->Execute("update " . TABLE_ORDERS . "
set orders_status = '" . zen_db_input($status) . "', last_modified = now()
where orders_id = '" . (int)$zf_insert_id . "'");
}
break;
case 'text':
//send order text to cell phone
require_once(DIR_FS_CATALOG.'ringcentral/ringcentral.phar');
echo $display_header;
echo " <h3> Message was sent to customer.</h3>";
echo $fax_info;
$orders_id = (int)$zf_insert_id;
//$message = $orders_id;
try {
//RingCentral\SDK\SDK::SERVER_SANDBOX RingCentral\SDK\SDK::SERVER_PRODUCTION 8bTYD-nRRN65AYU0gH3cSg
//$sdk = new RingCentral\SDK\SDK('v4EN2EL4QBuqyH-kNcf4Dw', 'nEVSLHU1R5istSxyoayrsQRviRiPnSSxCw8qcPY11F0Q', 'https://platform.devtest.ringcentral.com', 'Demo', '1.0.0');
$sdk = new RingCentral\SDK\SDK('8bTYD-nRRN65AYU0gH3cSg', 'PLqB6G1AQF-s88Lz3HN52AiM4c0XyRTQuJfFd8I7Wx0A', 'https://platform.ringcentral.com', 'PROD', '1.0.0');
//$sdk->platform()->login('12679304359', '101', 'Alena1129');
//$sdk->platform()->login('18883873312', '101', 'Alena1129');
$sdk->platform()->login('18883873312', '103', 'menu88$$');
//echo $message; 8477921688
$sms_table = preg_split("/[,]/" , STORE_TEXT_EMAIL);
$size = sizeof($sms_table);
$message = ' Red Passion 888-387-3312 Order '. (int)$orders_id . HTTP_SERVER . DIR_WS_CATALOG . 'show_order.php?red=order&oID=' . (int)$orders_id .
'-confirm';
for ($i=0; $i<$size; $i++) {
$smsnumber = preg_split("/[@]/" ,$sms_table[$i]);
$apiResponse = $sdk->platform()->post('/account/~/extension/~/sms', array(
//'from' => array('phoneNumber' => '12679304359'),
//'from' => array('phoneNumber' => '18474816091'),
'from' => array('phoneNumber' => '18477921688'),
'to' => array(
array('phoneNumber' => $smsnumber[0]),
),
'text' => $message ,
));
}
} catch (\RingCentral\SDK\Http\ApiException $e) {
$to = $this->owner_phone;
$from = 'jhuang@redpassionhost.com';
$subject = 'Red Passion:'. (int)$orders_id;
//begin of HTML message
//$message = ' '. HTTP_SERVER . DIR_WS_CATALOG . 'show_order.php?red=order&oID=' . (int)$orders_id .
//'-confirm Question? 8 8 8 387-3312';
$message = ' '. HTTP_SERVER . DIR_WS_CATALOG . 'show_order.php?red=order&oID=' . (int)$orders_id .
'-confirm ';
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $message, $headers);
$message .= $smsnumber[0] . ' API Error: ' . $e->getMessage() . PHP_EOL;
mail('spancfreedom@gmail.com', $subject, $message, $headers);
}
break;
case 'mail':
echo $display_header;
echo " <h3> Message was sent to customer.</h3>";
echo $fax_info;
$orders_id = (int)$zf_insert_id;
$to = SEND_EXTRA_ORDER_EMAILS_TO ;
$from = 'jhuang@redpassionhost.com';
$subject = 'Red Passion order:'. (int)$orders_id;
//begin of HTML message
//$message = ' '. HTTP_SERVER . DIR_WS_CATALOG . 'show_order.php?red=order&oID=' . (int)$orders_id .
//'-confirm Question? 8 8 8 387-3312';
$message = ' '. HTTP_SERVER . DIR_WS_CATALOG . 'show_order.php?red=order&oID=' . (int)$orders_id .
'-confirm ';
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $message, $headers);
//$message .= ' API Error: ' . $e->getMessage() . PHP_EOL;
//mail('spancfreedom@gmail.com', $subject, $message, $headers);
break;
case 'email':
echo $display_header;
echo $fax_info;
//owner confirmed open the order
$status = '3'; //deliveried
$check_status = $db->Execute("select customers_name, customers_email_address, orders_status,
date_purchased from " . TABLE_ORDERS . "
where orders_id = '" . (int)$zf_insert_id . "'");
if ( ($check_status->fields['orders_status'] < $status) ) { //only return email when status = 1 or 2
zen_mail('', 'spanc07@gmail.com', MODULE_SHIPPING_STORE_FAX_NUMBER.' ' .'Opened & confirmed ' . $zf_insert_id,
'Owner opened this order.', STORE_NAME, EMAIL_FROM, $html_msg, 'checkout_extra', '');
// change to 3 so no more email
$db->Execute("update " . TABLE_ORDERS . "
set orders_status = '" . zen_db_input($status) . "', last_modified = now()
where orders_id = '" . (int)$zf_insert_id . "'");
}
break;
case 'admin':
echo $display_header;
echo '<a href="show_order.php?red=order&oID='.(int)$zf_insert_id.'-rcfax" ><button style="background-color:red">Refax,Reprint,Email order</button></a>
<a href="show_order.php?red=order&oID='.(int)$zf_insert_id.'-text" ><button style="background-color:red">Text Order to Owner</button></a>
<br><br><a href="show_order.php?red=order&oID='.(int)$zf_insert_id.'-deliveried-callback" ><button style="background-color:orange">Ask Call Back 回电话</button></a>
<a href="show_order.php?red=order&oID='.(int)$zf_insert_id.'-deliveried-badcredit" ><button style="background-color:orange">Bad Credit坏信用卡</button></a>
<br><br><a href="show_order.php?red=order&oID='.(int)$zf_insert_id.'-deliveried-driver" ><button style="background-color:#9ACD32">Driver is by your door在门口.</button></a>
<a href="show_order.php?red=order&oID='.(int)$zf_insert_id.'-deliveried" ><button style="background-color:#9ACD32">Food is Ready 餐已做好</button></a><br>
';
echo $fax_info;
?>
<table border="0" cellspacing="0" cellpadding="2" class="noprint">
<tr>
<td><?php echo zen_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
</tr>
<tr>
<td class="main"><table border="1" cellspacing="0" cellpadding="5">
<tr>
<td class="smallText" align="center"><strong>Date Added</strong></td>
<td class="smallText" align="center"><strong>Notified</strong></td>
<td class="smallText" align="center"><strong>Status</strong></td>
<td class="smallText" align="center"><strong>Comments</strong></td>
</tr>
<?php
$orders_history = $db->Execute("select orders_status_id, date_added, customer_notified, comments
from " . TABLE_ORDERS_STATUS_HISTORY . "
where orders_id = '" . zen_db_input($oID) . "'
order by date_added");
//date('m/d/y g:i A', $orders_history->fields['date_added'])
if ($orders_history->RecordCount() > 0) {
while (!$orders_history->EOF) {
echo ' <tr>' . "\n" .
' <td class="smallText" align="center">' . date('m/d/y g:i A', strtotime($orders_history->fields['date_added'])) . '</td>' . "\n" .
' <td class="smallText" align="center">';
if ($orders_history->fields['customer_notified'] == '1') {
echo "Yes </td>\n";
} else {
echo " No </td>\n";
}
echo ' <td class="smallText">' . $orders_status_array[$orders_history->fields['orders_status_id']] . '</td>' . "\n";
echo ' <td class="smallText">' . nl2br(zen_db_output($orders_history->fields['comments'])) . ' </td>' . "\n" .
' </tr>' . "\n";
$orders_history->MoveNext();
}
} else {
echo ' <tr>' . "\n" .
' <td class="smallText" colspan="5">' . TEXT_NO_ORDER_HISTORY . '</td>' . "\n" .
' </tr>' . "\n";
}
//get store phone
$store_name_address = explode("\n", STORE_NAME_ADDRESS );
$MYPHONE = STORE_PHONE;
if ( $MYPHONE == '') {
for ($i=1, $n=sizeof($store_name_address); $i<=$n; $i++) {
// if (preg_match( "/(\(\d+\))?([\s-]?\d+)+/", $store_name_address[$i])) {
if (preg_match( "/(\d{3}-\d{4})/", $store_name_address[$i])) {
$MYPHONE = $store_name_address[$i] ;
break;
}
}
}
?>
</table></td>
</tr>
<tr>
<td class="smallText"><br /><strong> Comments </strong></td>
</tr>
<tr><?php echo zen_draw_form('edit_order', 'show_order.php', 'GET'); ?>
<input type="hidden" name="red" value="order" />
<input type="hidden" name="oID" value="<?php echo $zf_insert_id . '-upd'; ?>" />
<td class="smallText"><textarea name="comments" wrap="soft" cols="60" rows="5">
We couldn't reach you by phone please Call Restaurant <?php echo format_phone($MYPHONE); ?>. Thanks.</textarea> </td>
</tr>
<tr>
<td><?php echo zen_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
</tr>
<tr>
<td><table border="0" cellspacing="0" cellpadding="2" class="noprint">
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="2">
<tr>
<td class="smallText"><strong>Status:</strong> <?php echo zen_draw_pull_down_menu('status', $orders_statuses, $order->info['orders_status']); ?></td>
<td class="smallText"><strong>Notify Customer:</strong> <?php echo zen_draw_checkbox_field('notify', '', true); ?></td>
</tr>
</table>
</td>
<td valign="top"><input type="submit" value= "Update Order"></td>
</tr>
</table></td>
</form>
</tr>
</table>
<?php
break;
default:
//echo ' Wrong Option ';
echo $display_header;
echo $fax_info;
}
}
//if ($red !='order') {exit;}
if ($order_exists == false) {
$today_orders = $db->Execute("select orders_id,date_purchased from " . TABLE_ORDERS . "
where DATE(date_purchased) = DATE(NOW()) order by 1 desc");
//echo "<h2> Order# ". $oID. " is not exiting. Could be next order.</h2>";
if ($today_orders->EOF){
echo "<h2> No orders today. </h2>";
}else {
echo "<h2> Today's orders: Please click order number link to view order contents. </h2>";
}
while (!$today_orders->EOF) {
$myorderid = $today_orders->fields['orders_id'];
$date_purchased = date_format(date_create($today_orders->fields['date_purchased']), 'g:i A');
if ($my_option[1] == 'owner') {
echo "<h2> ".$date_purchased . " <a href=\"" . HTTP_SERVER . DIR_WS_CATALOG . 'show_order.php?red=order&oID=' . $myorderid . "-confirm\">" . $myorderid . "</a></h2>" ;
}else{
echo "<h2> ".$date_purchased . " <a href=\"" . HTTP_SERVER . DIR_WS_CATALOG . 'show_order.php?red=order&oID=' . $myorderid . "-admin\">" . $myorderid . "</a></h2>" ;
}
$today_orders->MoveNext();
}
?>
</body>
</html>
<?php
}
require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>