<?php
/* Set e-mail recipient */
$myemail  = "paper@cervion.com, hunterballen@gmail.com, chris@cervion.com";

/* Check all form inputs using check_input function */
$business = check_input($_POST['business'], "Enter your business name");
$firstname = check_input($_POST['firstname'], "Enter your first name");
$lastname = check_input($_POST['lastname'], "Enter your last name");
$email    = check_input($_POST['email']);
$phone  = check_input($_POST['phone'], "Enter your phone number");
$contact  = check_input($_POST['contact'], "Do we need to contact you prior to shipping?");
$product1   = check_input($_POST['product1']);
$product2   = check_input($_POST['product2']);
$product3   = check_input($_POST['product3']);
$product4   = check_input($_POST['product4']);
$product5   = check_input($_POST['product5']);
$product6   = check_input($_POST['product6']);
$promocode   = check_input($_POST['promocode']);

$date = date("m/d/Y g:i A", time());
$ip = $_SERVER['REMOTE_ADDR'];


/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
    show_error("Enter a valid email address");
}

/* Let's prepare the message for the e-mail */
$header = "From: Cervion - Supply Order";
$subject = "Desktop: Supply Order Form Submission";
$message = "
---
SUPPLY ORDER FORM SUBMISSION
---

Customer Name: $firstname $lastname
Customer Company: $business
Order Date: $date
Customer IP: $ip
Submission Location: Desktop Site

Contact before placing order? $contact
Customer E-mail: $email
Customer Phone: $phone

---
ORDER INFORMATION
---

3 1/8' Thermal Paper - QTY: $product1
3' One Ply Paper - QTY: $product2
3' Two Ply Paper - QTY: $product3
3' Three Ply Paper - QTY: $product4
Remote Printer Ribbons - QTY: $product5
Manager Swipe Cards - QTY: $product6

Promo Code: $promocode

";

/* Send the message using mail() function */
mail($myemail, $subject, $message, $header);

/* Redirect visitor to the thank you page */
header('Location: http://customer.cervion.com/order-supplies/order-confirmation/');
exit();

/* Functions we used */
function check_input($data, $problem='')
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    if ($problem && strlen($data) == 0)
    {
        show_error($problem);
    }
    return $data;
}

function show_error($myError)
{
?>
    <html>
    <style type="text/css">
body {
	margin-top: 55px;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
	line-height: 19px;
}
.error {
	font-weight: bold;
	color: #F00; 
	text-transform: uppercase;
}

</style>
    <body>

    <div align="center"><b>Could you correct the following error before we submit your order?</b>
    <br /><br />
    ---------------------------------------------------------<br />
    <span class="error"><?php echo $myError; ?></span><br />
    ---------------------------------------------------------<br /><br />
    <em>Please use your browser's back button to continue.</em></div>
    </body>
    </html>
<?php
exit();
}
?>
