fetch_array($rs);
if( mysql_num_rows($rs) > 0 )
{
if ( $row['morderid']=='NULL' || $row['morderid']=='' ) {
$orderidvalue2= "001";
}
else
{
$orderidvalue2= $row["morderid"];
$orderidvalue2++;
}
}
else
{
$orderidvalue2= 1;
}
if ( $orderidvalue2 < 10 )
$orderidvalue = $orderidvalue1.'00'.$orderidvalue2;
else
if ( $orderidvalue2 > 10 && $orderidvalue2 < 99 )
$orderidvalue = $orderidvalue1.'0'.$orderidvalue2;
else if ( $orderidvalue2 > 99 )
$orderidvalue = $orderidvalue1.''.$orderidvalue2;
$nowday = date("d");
$nowmonth = date("m");
$nowyear = date("Y");
$rekeyform ="S".substr($_SERVER['SERVER_ADDR'],5,1).$nowday.substr($_SERVER['SERVER_ADDR'],4,1).md5(rand()).$nowmonth.substr($_SERVER['SERVER_ADDR'],0,3).md5($nowyear);
$sql = "INSERT INTO `tb_order_list` (
`member_id`
,`orderid`
,`orderdate`
,`orderkey`
,`s_firstname`
,`s_lastname`
,`s_company`
,`s_comment`
,`s_address`
,`s_country`
,`s_city`
,`s_province`
,`s_postal`
,`s_phone`
,`s_total_price`
,`s_order_date`
,`s_status`
,`repayranid`
)
VALUES (
'".escapeit($_SESSION['dcspare_id'])."'
, '".escapeit($orderidvalue)."'
, '".escapeit($orderidvalue1)."'
, '".escapeit($orderidvalue2)."'
, '".escapeit($s_firstname)."'
, '".escapeit($s_lastname)."'
, '".escapeit($s_company)."'
, '".escapeit($s_comment)."'
, '".escapeit($s_address)."'
, '".escapeit($s_country)."'
, '".escapeit($s_city)."'
, '".escapeit($s_province)."'
, '".escapeit($s_zip)."'
, '".escapeit($s_phone)."'
, '".escapeit($total_price)."'
, NOW()
, 'Pending'
, '".$rekeyform."'
)";
$db->query($sql);
$order_id=mysql_insert_id();
$_SESSION["order_id"] = $order_id;
$_SESSION['ppcid']=$order_id;
$j=1;
$max=count($_SESSION['enquiry_basket']);
for($i=0;$i<$max;$i++){
$pid=$_SESSION['enquiry_basket'][$i]['productid'];
$q=$_SESSION['enquiry_basket'][$i]['qty'];
$currency='HKD';
$pname=get_product_name($pid);
$price=get_price($pid,$currency);
//============ paypal
$all_item_number[$j] = $j;
$all_quantity[$j] = $q;
$all_item_name[$j] = $pname;
$all_amount[$j] = $price;
//============ paypal
$j++;
$sql = "INSERT INTO `tb_order_item_list` (
`order_id`
,`product_id`
,`quantity`
,`unit_price`
,`currency`
)
VALUES (
'".escapeit($order_id)."'
, '".escapeit($pid)."'
, '".escapeit($q)."'
, '".escapeit($price)."'
, '".escapeit($currency)."'
)";
$db->query($sql);
}
$alertmsg = "";
//if($is_submit == "Y"){
// echo "submit now";
/*
if ($_FILES["file"]["name"]!= ""){
$allowed = array('gif','png' ,'jpg', 'pdf','doc', 'docx');
$attachname = $_FILES["file"]["name"];
$ext = pathinfo($attachname, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed) ) {
$alertmsg .= "上載收據只限圖片或pdf檔案! ";
}
} else {
// $alertmsg .= "請上載收據! ";
}
*/
if($alertmsg == ""){
$id = $order_id;
$sql = "SELECT * FROM `tb_order_list` where id='".$id."'";
$row_data = $db->getrow($sql);
$sql_photo = "SELECT `path`,`upload_date`,`file_name`
FROM `tb_product_attachment`
WHERE `table_name` = 'tb_product_list'
AND `table_id` = '".$row_data['id']."'
AND `col_name` LIKE 'photo%'
ORDER BY `sorting`";
$row_photo = $db->getrow($sql_photo);
$email_content .= '
Item
Model
Quantity
Unit Price
Sub total
';
$sql2 = "SELECT *, (select name from `tb_product_list` where id=product_id) as iteamname, (select model from `tb_product_list` where id=product_id) as modelname FROM `tb_order_item_list` where 1 and order_id='".$id."'";
$rs = $db->query($sql2);
$count=1;
$temptotal=0;
while($row = $db->fetch_array($rs)){
// $photo = get_attachment("products",$row['id'],"photo");
$temptotal = $temptotal + $row["quantity"]*$row["unit_price"];
$email_content .= ''.$count.'
'.$row["iteamname"].'
'.$row["modelname"].'
'.$row["quantity"].'
USD $'.$row["unit_price"].'
USD $'.$row["quantity"]*$row["unit_price"].'
';
$count++;
}
$temptotal = $temptotal + $row_data["t_fee"];
$email_content .= '
Total:
USD $'.$temptotal.'
';
$sql = "SELECT * FROM `tb_order_list` where id='".$id."'";
$row_data = $db->getrow($sql);
$repayranid = $row_data["repayranid"];
$email_content .= '
Delivery Address
First Name '.$row_data["s_firstname"].'
Last Name '.$row_data["s_lastname"].'
Address '.$row_data["s_address"].'
City '.$row_data["s_city"].' '.$row_data[""].'
Country '.$row_data["s_country"].' '.$row_data[""].'
Postal/Zip Code '.$row_data["s_postal"].' '.$row_data[""].'
Phone No '.$row_data["s_phone"].' '.$row_data[""].'
Company '.$row_data["s_company"].' '.$row_data[""].'
Comments '.$row_data["s_comment"].' '.$row_data[""].'
';
$email = "info@dcspares.com.hk";
$email_title = "Order (".$orderidvalue.") from dcspares";
$mail = new PHPMailer();
/*
if ($_FILES["file"]["name"]!= ""){
$allowed = array('gif','png' ,'jpg', 'pdf','doc', 'docx');
$attachname = $_FILES["file"]["name"];
$ext = pathinfo($attachname, PATHINFO_EXTENSION);
if(in_array($ext,$allowed) ) {
$mail->AddAttachment($_FILES["file"]['tmp_name'], $attachname);//添加附件,需表明路
}
}
*/
$mail->Subject = $email_title;
$mail->Body = $email_content;
$mail->isHTML(true);
$mail->FromName = trim($email);//Sender email address
$mail->From = trim($email);//$email Sender email address
//$mail->AddAddress("kaze@smartinfo.com.hk");
$mail->AddAddress("info@dcspares.com.hk"); //receiver email address
$mail->AddBCC("jason@smartinfo.com.hk");
$mail->AddBCC("kaze@smartinfo.com.hk");
// $mail->AddAddress("jason@smartinfo.com.hk"); //receiver email address
$result = $mail->Send();
//--- End Send Contact information ---
//$successmsg = "已收到申請, 我們將盡快處理 !";
//unset($_SESSION['enquiry_basket']);
}
//}
//--- End Insert the donation ---
//--- List gender ---
$list_gender = "";
foreach($all_salutation_en as $salutation_id => $salutation_name){
$list_gender .= ' '.$salutation_name." ";
}
//--- End List gender ---
//header("Location: paypal.php?order_id=".mysql_insert_id()."&product_code=".$product_number."&product_name=".$product_name."&product_amount=".$product_price);
unset($_SESSION['enquiry_basket']);
echo "";
echo "";
?>