Receipt

[insert_php]

if (empty($_REQUEST[“cusid”])) { echo “no customer link”; $cusid = 0; }
else { $cusid = $_REQUEST[“cusid”]; }
if (empty($_REQUEST[“ptype”])) { $ptype = 1; }
else { $ptype = $_REQUEST[“ptype”]; }
if (empty($_REQUEST[“lastptype”])) { $lastptype = 99; }
else { $lastptype = $_REQUEST[“lastptype”]; }
if (empty($_REQUEST[“orderid”])) { $orderid = 0; }
else { $orderid = $_REQUEST[“orderid”]; }
if (empty($_POST[“subBTN”])) { $subBTN = ”; }
else { $subBTN = $_POST[“subBTN”]; }
if (empty($_REQUEST[“hpass”])) { $hpass = ”; }
else { $hpass = $_REQUEST[“hpass”]; }
if (empty($_REQUEST[“cuscomments”])) { $cuscomments = ”; }
else { $cuscomments = $_REQUEST[“cuscomments”]; }
if (empty($_REQUEST[“locname”])) { $locname = 0; }
else { $locname = $_REQUEST[“locname”]; }
if (empty($_REQUEST[“contactprod_1”])) { $contactprod_1 = 0; }
else { $contactprod_1 = $_REQUEST[“contactprod_1”]; }
if (empty($_REQUEST[“contactprod_2”])) { $contactprod_2 = 0; }
else { $contactprod_2 = $_REQUEST[“contactprod_2”]; }
if (empty($_REQUEST[“contactprod_3”])) { $contactprod_3 = 0; }
else { $contactprod_3 = $_REQUEST[“contactprod_3”]; }

$todaysdate = date(“Y-m-d H:n:s”);
$total = 0.00;
$cusgrp = ”;
$cusname = ”;
$body = ”;

if ($orderid != 0) {

$result = mysql_query(“SELECT `cus-id`, `cus-company`, `cus-prpgroup` FROM sc_customer where `cus-id` = ‘$cusid’ and `cus-password` = ‘$hpass'”);
if(!mysql_num_rows($result)) { $cusid = 0; }
else { while($row = mysql_fetch_array($result)) {

$cusgrp = $row[‘cus-prpgroup’];
$cusname = $row[‘cus-company’];

}}

if($cusid != 0) {

$body = $body.”A new order has been placed by “.$cusname.” (Group #”.$cusgrp.”)”;
$body = $body.”\r\n\r\nThe order details are as follows:\r\n”;
$body = $body.”Order ID: “.$orderid.”\r\n”;

$result6 = mysql_query(“SELECT * FROM sc_order_items WHERE `orders-id` = ‘$orderid’ ORDER BY `order-items-id` ASC”);
if(!mysql_num_rows($result6)) { echo “No order items found”; }
else { while($row6 = mysql_fetch_array($result6)) {

$total = $total + $row6[‘line-total’];
$body = $body.”Product Number “.$row6[‘prd-number’].” – “.$row6[‘prd-name’];
$body = $body.” Qty “.$row6[‘quantity’].” “.$row6[‘prd-size’]. ” @ “.$row6[‘prd-price’].” = “.$row6[‘line-total’].”\r\n\r\n”;

}}
$formatted_total = number_format($total, 2, ‘.’, ”);

$body = $body.”\r\nOrder Total: “;
$body = $body.$formatted_total;

$body = $body.”\r\nDelivery Location: “;

$result6 = mysql_query(“SELECT * FROM sc_customer WHERE `cus-id` = ‘$cusid'”);
if(!mysql_num_rows($result6)) { }
else { while($row6 = mysql_fetch_array($result6)) {

if($locname == ‘1’) {
$body = $body.$row6[‘cus-del-locname’].”: “.$row6[‘cus-del-address1’].” “.$row6[‘cus-del-address2’].” “.$row6[‘cus-del-city’].” “.$row6[‘cus-del-state’].” “.$row6[‘cus-del-zip’].” “.$row6[‘cus-del-phone’];
}
else if($locname == ‘2’) {
$body = $body.$row6[‘cus-del2-locname’].”: “.$row6[‘cus-del2-address1’].” “.$row6[‘cus-del2-address2’].” “.$row6[‘cus-del2-city’].” “.$row6[‘cus-del2-state’].” “.$row6[‘cus-del2-zip’].” “.$row6[‘cus-del2-phone’];
}
else if($locname == ‘3’) {
$body = $body.$row6[‘cus-del3-locname’].”: “.$row6[‘cus-del3-address1’].” “.$row6[‘cus-del3-address2’].” “.$row6[‘cus-del3-city’].” “.$row6[‘cus-del3-state’].” “.$row6[‘cus-del3-zip’].” “.$row6[‘cus-del3-phone’];
}
else if($locname == ‘4’) {
$body = $body.$row6[‘cus-del4-locname’].”: “.$row6[‘cus-del4-address1’].” “.$row6[‘cus-del4-address2’].” “.$row6[‘cus-del4-city’].” “.$row6[‘cus-del4-state’].” “.$row6[‘cus-del4-zip’].” “.$row6[‘cus-del4-phone’];
}
else if($locname == ‘5’) {
$body = $body.$row6[‘cus-del5-locname’].”: “.$row6[‘cus-del5-address1’].” “.$row6[‘cus-del5-address2’].” “.$row6[‘cus-del5-city’].” “.$row6[‘cus-del5-state’].” “.$row6[‘cus-del5-zip’].” “.$row6[‘cus-del5-phone’];
}
else if($locname == ‘6’) {
$body = $body.$row6[‘cus-del6-locname’].”: “.$row6[‘cus-del6-address1’].” “.$row6[‘cus-del6-address2’].” “.$row6[‘cus-del6-city’].” “.$row6[‘cus-del6-state’].” “.$row6[‘cus-del6-zip’].” “.$row6[‘cus-del6-phone’];
}
else if($locname == ‘7’) {
$body = $body.$row6[‘cus-del7-locname’].”: “.$row6[‘cus-del7-address1’].” “.$row6[‘cus-del7-address2’].” “.$row6[‘cus-del7-city’].” “.$row6[‘cus-del7-state’].” “.$row6[‘cus-del7-zip’].” “.$row6[‘cus-del7-phone’];
}
else if($locname == ‘8’) {
$body = $body.$row6[‘cus-del8-locname’].”: “.$row6[‘cus-del8-address1’].” “.$row6[‘cus-del8-address2’].” “.$row6[‘cus-del8-city’].” “.$row6[‘cus-del8-state’].” “.$row6[‘cus-del8-zip’].” “.$row6[‘cus-del8-phone’];
}
else if($locname == ‘9’) {
$body = $body.$row6[‘cus-del9-locname’].”: “.$row6[‘cus-del9-address1’].” “.$row6[‘cus-del9-address2’].” “.$row6[‘cus-del9-city’].” “.$row6[‘cus-del9-state’].” “.$row6[‘cus-del9-zip’].” “.$row6[‘cus-del9-phone’];
}
else if($locname == ’10’) {
$body = $body.$row6[‘cus-del10-locname’].”: “.$row6[‘cus-del10-address1’].” “.$row6[‘cus-del10-address2’].” “.$row6[‘cus-del10-city’].” “.$row6[‘cus-del10-state’].” “.$row6[‘cus-del10-zip’].” “.$row6[‘cus-del10-phone’];
}

}}

$contactproducts = ”;

if($contactprod_1 != 0) {
$result6 = mysql_query(“SELECT * FROM sc_product WHERE `prd-number` = ‘$contactprod_1′”);
if(!mysql_num_rows($result6)) { }
else { while($row6 = mysql_fetch_array($result6)) {
$contactproducts = $contactproducts.$row6[‘prd-name’].”\r\n “;
}}
}

if($contactprod_2 != 0) {
$result6 = mysql_query(“SELECT * FROM sc_product WHERE `prd-number` = ‘$contactprod_2′”);
if(!mysql_num_rows($result6)) { }
else { while($row6 = mysql_fetch_array($result6)) {
$contactproducts = $contactproducts.$row6[‘prd-name’].”\r\n “;
}}
}

if($contactprod_3 != 0) {
$result6 = mysql_query(“SELECT * FROM sc_product WHERE `prd-number` = ‘$contactprod_3′”);
if(!mysql_num_rows($result6)) { }
else { while($row6 = mysql_fetch_array($result6)) {
$contactproducts = $contactproducts.$row6[‘prd-name’].”\r\n “;
}}
}
if($contactproducts != ”) {

$body = $body.”\r\nPlease contact this customer about pricing/availability of the following products that are not currently on their price list:”.$contactproducts;

}

$body = $body.”\r\nComments/Request: “.$cuscomments;

$body = $body.”\r\n\r\nRemember to mark this order complete when applicable.”;

$sql5 = “UPDATE sc_orders SET `total` = “.$formatted_total.”, `cus-comments` = ‘”.$cuscomments.”‘, `status` = ‘PENDING’, `order-cus-delloc` = ‘$locname’ WHERE `order-id` =”.$orderid;
$result5 = mysql_query($sql5) or die(“updatetotal”.mysql_error());

$to = ”;
$result6 = mysql_query(“SELECT `adm-email` FROM sc_admin”);
if(!mysql_num_rows($result6)) { }
else { while($row6 = mysql_fetch_array($result6)) {

/** wp_mail( ‘juliemmh@me.com’, ‘The subject’, ‘The message’ ); */
if($to == ”) {
$to = $row6[‘adm-email’];
}
else {
$to = $to.’, ‘.$row6[‘adm-email’];
}

/**if cusid is 9, only send to laura and julie for testing purposes*/
if($cusid == ‘9’) { $to = ‘laura@adura.net,julie@middlechildmedia.com’; }

$subject = ‘Notification of New Order #’.$orderid;

}}

if($to != ”) {

wp_mail( $to, $subject, $body);
}

/** wp_mail( ‘$to, $subject, $message, $headers, $attachments ); */

} /*end order id not 0 */

echo “Order # “.$orderid.” “;
echo $formatted_total;
echo ” has been sent. Thank you for your order.”;

echo “

“;
echo ““;
echo ““;
echo ““;
echo “”;

} /*end cusid not 0 */

[/insert_php]