function MailOrder($unicode_character_before, $unicode_character_after, $pref_sitename, $sender_name, $sender_email, $to_name, $to_email, $print_special_instr, $special_instr_text, $to_id, $email_info_level, $to_address1, $to_address2, $to_zipcode, $to_city, $to_telephone, $to_mobile, $email_additional_text) { //if(isset($_POST['email'])){ $check = TRUE; if ($check) { if ($error) { $message .= "<div style='text-align:center'><b>" . EASYSHOP_SHOP_60 . " " . $error . "</b></div>"; } else { $time_stamp = date('r', time()); $address = $to_email; // Provide multiple To: addresses separated with comma $pre_subject = isset($pref_sitename) ? "[" : ""; $post_subject = isset($pref_sitename) ? "]" : ""; $subject = $pre_subject . $pref_sitename . $post_subject . " " . ($_SESSION['sc_total']['quotation'] == 2 ? EASYSHOP_SHOP_94 : EASYSHOP_SHOP_62) . " " . date("Y-m-d"); $message = EASYSHOP_SHOP_58 . " " . $time_stamp . " " . ($_SESSION['sc_total']['quotation'] == 2 ? EASYSHOP_SHOP_95 : EASYSHOP_SHOP_59) . "<br />\n\t\t\t\t\t<div style='text-align:center;'>\n\t\t\t\t\t\t<table border='1' cellspacing='1'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td class='tbox'>" . EASYSHOP_SHOP_21 . "</td>\n\t\t\t\t\t\t\t<td class='tbox'>" . EASYSHOP_SHOP_22 . "</td>\n\t\t\t\t\t\t\t<td class='tbox'>" . EASYSHOP_SHOP_23 . "</td>\n\t\t\t\t\t\t\t<td class='tbox'>" . EASYSHOP_SHOP_24 . "</td>\n\t\t\t\t\t\t\t<td class='tbox'>" . EASYSHOP_SHOP_25 . "</td>\n\t\t\t\t\t\t\t<td class='tbox'>" . EASYSHOP_SHOP_26 . "</td>\n\t\t\t\t\t\t\t<td class='tbox'>" . EASYSHOP_SHOP_27 . "</td>\n\t\t\t\t\t\t</tr>"; // Fill the message with products from the basket $count_items = count($_SESSION['shopping_cart']); // Count number of different products in basket $sum_quantity = $_SESSION['sc_total']['items']; // Display cached sum of total quantity of items in basket $sum_shipping = $_SESSION['sc_total']['shipping']; // Display cached sum of shipping costs for 1st item $sum_shipping2 = $_SESSION['sc_total']['shipping2']; // Display cached sum of shipping costs for additional items (>1) $sum_handling = $_SESSION['sc_total']['handling']; // Display cached sum of handling costs $sum_shipping_handling = number_format($sum_shipping + $sum_shipping2 + $sum_handling, 2, '.', ''); // Calculate total handling and shipping price $sum_price = number_format($_SESSION['sc_total']['sum'] + $sum_shipping_handling, 2, '.', ''); // Display cached sum of total price of items in basket + shipping + handling costs $array = $_SESSION['shopping_cart']; // PayPal requires to pass multiple products in a sequence starting at 1; we do as well in the mail $cart_count = 1; // For each product in the shopping cart array write PayPal details foreach ($array as $id => $item) { $display_sku_number = $item['sku_number']; if ($item['sku_number'] == "") { $display_sku_number = " "; // Force a space in the cell for proper border display } $message .= "\n\t\t\t\t\t\t <tr>\n\t\t\t\t\t\t\t <td class='tbox'>" . $display_sku_number . "</td>\n\t\t\t\t\t\t\t <td class='tbox'>" . $item['item_name'] . "</td>\n\t\t\t\t\t\t\t <td class='tbox'>" . $unicode_character_before . $item['item_price'] . $unicode_character_after . "</td>\n\t\t\t\t\t\t\t <td class='tbox'>" . $item['quantity'] . "</td>\n\t\t\t\t\t\t\t <td class='tbox'>" . $unicode_character_before . $item['shipping'] . $unicode_character_after . "</td>\n\t\t\t\t\t\t\t <td class='tbox'>" . $unicode_character_before . $item['shipping2'] . $unicode_character_after . "</td>\n\t\t\t\t\t\t\t <td class='tbox'>" . $unicode_character_before . $item['handling'] . $unicode_character_after . "</td>\n\t\t\t\t\t\t </tr>"; $cart_count++; } $message .= "\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div style='text-align:left;'>\n\t\t\t\t\t<br />" . EASYSHOP_SHOP_16 . " " . $sum_quantity . "\n\t\t\t\t\t<br />" . EASYSHOP_SHOP_18 . " " . $unicode_character_before . $sum_price . $unicode_character_after . "\n\t\t\t\t\t\t"; if ($sum_shipping_handling > 0) { $message .= "<br />" . EASYSHOP_SHOP_20 . " " . $unicode_character_before . $sum_shipping_handling . $unicode_character_after; } // Add special instructions if ($print_special_instr == '1') { $message .= "<br /><br />" . EASYSHOP_SHOP_82 . ":<br />{$special_instr_text}<br />"; } // Add loggin in user info if (USER) { $message .= "<br /><br />" . EASYSHOP_SHOP_93 . ": <a href='" . SITEURL . "user.php?id." . $to_id . "'>" . USERNAME . "</a> (<a href='mailto:" . USEREMAIL . "'>" . USEREMAIL . "</a>)"; } // Add extra address info if (($email_info_level == 1 || $email_info_level == 2) && !USER) { $message .= "<br /><br />{$to_name}<br />\n\t\t\t\t\t\t {$to_address1}<br />\n\t\t\t\t\t\t {$to_address2}<br />\n\t\t\t\t\t\t {$to_zipcode} {$to_city}<br />\n\t\t\t\t\t\t " . EASYSHOP_SHOP_90 . ": {$to_telephone}\n\t\t\t\t\t\t " . EASYSHOP_SHOP_91 . ": {$to_mobile}<br /><br />"; } // Add extra admin info from seller if (strlen(trim($email_additional_text)) > 0) { $message .= "<br /><br />\n\t\t\t\t\t\t {$email_additional_text}\n\t\t\t\t\t\t <br /><br />"; } $message .= "</div><br /><br /><div style='text-align:center;'>© <a href='http://e107.webstartinternet.com/'>EasyShop</a></div>"; if (!ShopMail::easyshop_sendemail($address, $subject, $message, $header)) { $message = EASYSHOP_SHOP_55; // Order e-mail failed } else { // Send also a copy to the shop owner //$address = $sender_name." <".$sender_email.">"; $address = $sender_email; $message = EASYSHOP_SHOP_64 . " " . $to_name . " (<a href'" . $to_email . "'>" . $to_email . "</a>)<br /><br />" . $message; // Extra in admin mail: "Following mail has been send to" global $e107; $ip = $e107->getip(); $message .= "<br />" . EASYSHOP_SHOP_81 . ": " . $ip; // Add 'Send from IP address' to mail message if (!ShopMail::easyshop_sendemail($address, $subject, $message, $header)) { $message = EASYSHOP_SHOP_63; // Order e-mail to admin failed } else { $message = EASYSHOP_SHOP_56; // Order e-mail succeeded $mail_result = 1; } } // Send downloads ShopMail::easyshop_senddownloads($_SESSION['shopping_cart'], $to_email); } } else { $message = EASYSHOP_SHOP_57; // Please fill in all fields correctly } //} return array($message, $mail_result); }
function easyshop_sendalert($product_id, $newstock, $minimum_level, $alert_type) { // Determine admin e-mail address from e107 preferences global $pref; $to_email = !(isset($pref['siteadminemail']) && strlen($pref['siteadminemail']) == 0) ? $pref['replyto_email'] : $pref['siteadminemail']; // Keep 0.7.8 compatible // Retrieve product data $product_id = intval($product_id); $sql = new db(); $sql->db_Select(DB_TABLE_SHOP_ITEMS, "*", "item_id={$product_id}"); if ($row = $sql->db_Fetch()) { // Set subject and message for each alert type if ($alert_type == "1") { // Alert 1: stock is below minimum level of this product $subject = EASYSHOP_CLASS_06 . " " . $row['item_name']; $message = EASYSHOP_CLASS_08 . " <a href='" . SITEURL . e_PLUGIN . "easyshop/easyshop.php?prod." . $product_id . "'>" . $row['item_name'] . "</a>!<br /><br />\r\n\t\t\t\t\t" . EASYSHOP_CLASS_09 . ": {$minimum_level}<br />\r\n\t\t\t\t\t" . EASYSHOP_CLASS_10 . ": {$newstock}"; } if ($alert_type == "2") { // Alert 2: last buyer purchased more of this product than actual in stock $subject = EASYSHOP_CLASS_07 . " " . $row['item_name']; $message = EASYSHOP_CLASS_11 . " <a href='" . SITEURL . e_PLUGIN . "easyshop/easyshop.php?prod." . $product_id . "'>" . $row['item_name'] . "</a>!<br /><br />\r\n\t\t\t\t\t" . EASYSHOP_CLASS_09 . ": {$minimum_level}<br />\r\n\t\t\t\t\t" . EASYSHOP_CLASS_10 . ": {$newstock}"; } if ($alert_type == "3") { // Alert 3: product is out of stock $subject = EASYSHOP_CLASS_12 . " " . $row['item_name']; $message = EASYSHOP_CLASS_13 . " <a href='" . SITEURL . e_PLUGIN . "easyshop/easyshop.php?prod." . $product_id . "'>" . $row['item_name'] . "</a>!<br />"; } // Send alert ShopMail::easyshop_sendemail($to_email, $subject, $message, $header, $attachment_name); } }
function update_stock($txn_id = NULL, $phpsessionid = NULL) { global $pref; $sqlcheck = new db(); $trans_array = transaction($phpsessionid, 0, 0, "Completed"); $items_array = unserialize($trans_array['all_items']); $count = 1; $temp_array = ""; while ($items_array["db_id_" . $count]) { if ($sqlcheck->db_Select("easyshop_items", "*", "item_id = '" . $items_array["db_id_" . $count] . "'")) { while ($row = $sqlcheck->db_Fetch()) { if ($row['item_track_stock'] == 2) { // Is this a tracked stock item? if ($row['item_instock'] >= $items_array["quantity" . $count]) { $newstock = $row['item_instock'] - $items_array["quantity_" . $count]; if ($row['item_minimum'] == 0 || $row['item_minimum'] == NULL) { // Minimum level is flexible, but with bottom-level 1. $minimum_level = 1; } else { $minimum_level = $row['item_minimum']; } if ($newstock <= $minimum_level && $newstock != 0) { // Minimum level is reached; send e-mail alert ShopMail::easyshop_sendalert($row['item_id'], $newstock, $minimum_level, 1); // Alert-type = 1 } if ($newstock == 0) { $sqlcheck->db_Update("easyshop_items", "item_instock = '" . $newstock . "', item_out_of_stock = '2'\r\n\t\t\t\t\t\t\t\t\tWHERE item_id = '" . $items_array["db_id_" . $count] . "'"); ShopMail::easyshop_sendalert($row['item_id'], $newstock, $minimum_level, 3); // Alert-type = 3 } else { $sqlcheck->db_Update("easyshop_items", "item_instock = '" . $newstock . "'\r\n\t\t\t\t\t\t\t\t\tWHERE item_id = '" . $items_array["db_id_" . $count] . "'"); } } else { // There is a problem; client has paid for more items than are in stock // Raise out of stock flag and send email $sqlcheck->db_Update("easyshop_items", "item_instock = '0', item_out_of_stock = '2'\r\n\t\t\t\t\t\t\t\t\tWHERE item_id = '" . $items_array["db_id_" . $count] . "'"); ShopMail::easyshop_sendalert($row['item_id'], $newstock, $minimum_level, 2); // Alert-type = 2 } } if ($row['prod_promo_class'] != 255 && $row['prod_promo_class'] != 0 && $trans_array['ipn_user_id'] > 0) { // Auto promotion of user $sqlcheck2 = new db(); $sqlcheck3 = new db(); require_once e_HANDLER . 'userclass_class.php'; $promo_class_name = r_userclass_name($row['prod_promo_class']); $sqlcheck2->db_Select("user", "*", "user_id='" . $trans_array['ipn_user_id'] . "'"); if ($row2 = $sqlcheck2->db_Fetch()) { $user_name = $row2['user_name']; $class_extant = explode(',', $row2['user_class']); foreach ($class_extant as $key => $value) { if (intval($value) == 0) { unset($class_extant[$key]); } } if ($row['prod_promo_class'] != 255 && $row['prod_promo_class'] != 0 && !in_array($row['prod_promo_class'], $class_extant)) { $class_extant[] = $row['prod_promo_class']; } $new_array = array_unique($class_extant); sort($new_array); $class_list = implode(',', $new_array); $sqlcheck3->db_Update("user", "user_class='" . $class_list . "' where user_id='" . $trans_array['ipn_user_id'] . "'"); $mailto = !(isset($pref['siteadminemail']) && strlen($pref['siteadminemail']) == 0) ? $pref['replyto_email'] : $pref['siteadminemail']; // Keep 0.7.8 compatible $subject = $pref['sitename'] . ": " . EASYSHOP_IPN_30; // [USERNAME] upgraded to class [PROMOCLASS] $subject = str_replace("[USERNAME]", $user_name, $subject); $subject = str_replace("[PROMOCLASS]", $promo_class_name, $subject); $message = EASYSHOP_IPN_31 . "<br /><br />"; $message .= EASYSHOP_IPN_32 . "<br /><br />"; $message .= EASYSHOP_IPN_33 . "<br />"; $message .= "<br />" . EASYSHOP_IPN_34 . " " . $pref['siteurl']; $message .= "<br /><br />© " . date("Y") . " EasyShop"; $message = str_replace("[USERNAME]", $row2['user_name'], $message); $message = str_replace("[USERLINK]", SITEURL . "user.php?id." . $trans_array['ipn_user_id'], $message); $message = str_replace("[PROMOCLASS]", r_userclass_name($row['prod_promo_class']), $message); $message = str_replace("[TRANSACTIONID]", $trans_array['txn_id'], $message); $message = str_replace("[PRODUCTPRICE]", $items_array["amount_" . $count], $message); $message = str_replace("[PRODUCTQTY]", $items_array["quantity_" . $count], $message); $message = str_replace("[CURRENCY]", $trans_array['mc_currency'], $message); $message = str_replace("[GROSSAMOUNT]", $trans_array['mc_gross'], $message); $message = str_replace("[PAYMENTDATE]", $trans_array['payment_date'], $message); $message = str_replace("[PRODLINK]", SITEURL . e_PLUGIN . "easyshop/easyshop.php?prod." . $items_array["db_id_" . $count], $message); $message = str_replace("[PRODUCTNAME]", $items_array["item_name_" . $count], $message); $user_message = EASYSHOP_IPN_35; $user_message .= "<br />" . EASYSHOP_IPN_36; $user_message .= "<br />" . EASYSHOP_IPN_34 . " " . $pref['siteurl']; $user_message .= "<br /><br />© " . date("Y") . " EasyShop"; $user_message = str_replace("[PRODUCTNAME]", $items_array["item_name_" . $count], $user_message); $user_message = str_replace("[PROMOCLASS]", r_userclass_name($row['prod_promo_class']), $user_message); //ShopMail::easyshop_sendemail($mailto, $subject, $message, $headers2, $attachment_name); if ($row2['user_class'] != $class_list) { // Only send an e-mail if the user_class array actually changed ShopMail::easyshop_sendemail($mailto, $subject, $message, $headers2, $attachment_name); // Mail to admin ShopMail::easyshop_sendemail($row2['user_email'], $subject, $user_message, $headers2, $attachment_name); // Mail to user } } } $temp_array = array($row['item_id'] => array("item_name" => $items_array["item_name_" . $count], "db_id" => $row['item_id'])); } } else { // This item does not exist!!! //$sqlcheck -> db_Close(); return FALSE; } $count++; } // Send downloads $to_email = $trans_array['payer_email']; ShopMail::easyshop_senddownloads($temp_array, $to_email); //$sqlcheck -> db_Close(); return TRUE; }