Guest User

code sample

a guest
Jan 6th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.19 KB | None | 0 0
  1. <?php
  2. /*LOAD MAIL CLASS*/
  3.  
  4. require_once('/var/www/restock/include/class.phpmailer.php');
  5.  
  6.     $order_mail                 = new PHPMailer(); 
  7.     $order_mail->IsSMTP();      //telling class to use SMTP
  8.     $order_mail->SMTPDebug      = 1;
  9.     $order_mail->Host           = "relay-hosting.secureserver.net";
  10.  
  11.     //$order_mail->AddReplyTo("[email protected]","Name");
  12.     //$order_mail->AddAddress("[email protected]","Name");
  13.     //$order_mail->AddAddress("[email protected]","Name");
  14.     $order_mail->AddAddress("[email protected]","Name");
  15.     $order_mail->SetFrom("[email protected]","Name");
  16.     $order_mail->Subject        = "New Order from " . $_SESSION['company_name'];
  17.  
  18.  
  19.     /*query to get the next order number*/
  20.     $query = "SELECT Auto_increment
  21.               FROM information_schema.tables
  22.               WHERE table_name='orderHead'";
  23.     $result = mysqli_query($mysqli_db, $query);
  24.     $new_order_num = mysqli_fetch_array($result);
  25.  
  26.     $order_mail->IsHTML(TRUE);
  27.     $body   =  "<style type='text/css'>h3, p, table td {font-family:arial;}</style>";
  28.     $body  .=  "<h3>Order " . $new_order_num[0]++ . " from " . $_SESSION['company_name'] . " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Epicor ID: " . $_SESSION['epicor_id'] ."</h3>";
  29.     //$body  .=  "<h3>PO 4510153722</h3>";
  30.     $body  .=  "<table>";
  31.     $body  .=  "<tr><td><u>SD Part Number</u></td><td><u>Quantity</u></td><td><u>UOM</u></td></tr>";
  32.  
  33.     foreach($_POST as $key => $value) {
  34.  
  35.     /*from $_POST only process the input boxes, ignoring the other $_POST variables*/
  36.         if (strpos($key, "input-final-qty-") !== FALSE) {
  37.             $quantity_to_order  = mysqli_real_escape_string($mysqli_db, (trim($value)));
  38.             $part_id = str_replace('input-final-qty-','', $key);
  39.  
  40.         //see if the matching rush checkbox was set (highlight rush parts)
  41.             $matching_rush_input_id = 'input-rush-' . $part_id;
  42.             $rush_part_style = (array_key_exists($matching_rush_input_id, $_POST)) ? "background-color:#fba7a7;" : "";
  43.  
  44.         //create query to get part number based on partID
  45.             $query = "SELECT partNumber, conversionFactor, UOMOrder
  46.                     FROM part
  47.                     WHERE partID = '" . $part_id . "'
  48.                     ORDER BY savedRush DESC, partID
  49.                     LIMIT 1";
  50.         //run query
  51.             $result = mysqli_query($mysqli_db, $query);
  52.         //get result
  53.             $row = mysqli_fetch_array($result);
  54.  
  55.             $quantity_to_order = $quantity_to_order * $row[1];
  56.  
  57.             $body    .= "<tr><td style='". $rush_part_style . "'>" . $row[0] . "</td> <td align='center' style='" . $rush_part_style . "'>" . $quantity_to_order . "</td> <td>" . $row[2] . "</td></tr>";
  58.  
  59.             mysqli_free_result($result);
  60.         }
  61.     }
  62.  
  63.     /*check for user typed note*/
  64.     $order_message = "";
  65.     if (isset($_POST['order-message-confirm'])) {  //user typed something
  66.         //sanitize input
  67.         $order_message = mysqli_real_escape_string($mysqli_db, trim($_POST['order-message-confirm']));
  68.  
  69.         //attach note to email if there was one
  70.         if ($order_message != "")   {
  71.             $body .= "</table><p style='font-size:10pt;'><br /><br /><u>Special Note / Comments / Request / Instructions</u><br />";
  72.             $body .= "<span style='font-weight:normal; font-size:12pt;'>" . $order_message . "</span></p>";
  73.         }
  74.         else {  $body .="</table>"; }
  75.     }
  76.     else {  $body .= "</table>"; }
  77.  
  78.     $order_mail->Body           = $body;
  79.  
  80.     /*SEND MAIL*/
  81.     if (!$order_mail->Send()) {
  82.         $order_sent = FALSE;
  83.     } else {
  84.         $order_sent = TRUE;
  85.     }
  86. ?>
Advertisement
Add Comment
Please, Sign In to add comment