Advertisement
Guest User

Untitled

a guest
Jan 7th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.46 KB | None | 0 0
  1. function thanhtoan($session)
  2.     {
  3.         global  $oDb , $oSmarty;
  4.         $sTbl2 = "tblproduct";
  5.         $query = "SELECT * FROM $this->table t1 join {$sTbl2} t2 on(t1.product_id=t2.Product_ID) WHERE t1.sessionid='$session' and completed<>'1'  ORDER BY id ";
  6.         $result = $oDb->getAll($query);
  7.         $total = 0;
  8.         $count=0;
  9.         foreach ($result as $key => $value) {              
  10.             $subtotal = $value['Product_Price']*$value['quantity'];
  11.             $result[$key]['subtotal'] = $subtotal;         
  12.             $total = $total + $subtotal;
  13.             $count = $count+$value['quantity'];
  14.         }
  15.         if (isset($_SESSION['user_id'])) {
  16.             $user = $oDb->getRow("SELECT * FROM user WHERE id= {$_SESSION['user_id']}");
  17.             $oSmarty->assign('user',$user);
  18.         }
  19.        
  20.         if($_SERVER['REQUEST_METHOD']=='POST')
  21.         {
  22.            
  23.             //$to = "khanhnk@bsg.vn";
  24.             $info = array(
  25.                 "name"  => $_POST['shipping_name'],
  26.                 "email" => $_POST['shipping_emaill'],
  27.                 "address"   => $_POST['txt_address'],
  28.                 "phone"     => $_POST['shipping_phone'],
  29.                 "tour_name" => $tour['title'],
  30.             );
  31.            
  32.             $oSmarty->assign('info',$info);
  33.             $oSmarty->assign('cart',$result);
  34.             $oSmarty->assign('total',$total);
  35.             $content = $oSmarty->fetch('checkout_mail_content.tpl');
  36.             $subject = $oSmarty->get_config_vars('title_mail_shopping');
  37.            
  38.             $contacts = $this -> getContact();
  39.             if( $contacts )
  40.             {
  41.                 foreach( $contacts as $key => $val)
  42.                 {
  43.                     //@mail( $val['email'], $subject, $content, $headers );
  44.                 }
  45.             }
  46.             else
  47.             {
  48.                 $contact = getConfig('email_contact');
  49.                 //@mail( $contact, $subject, $content, $headers );
  50.             }
  51.            
  52.             /*  remove cart */
  53.                 $info_cart="<ul>";
  54.                 foreach($result as $key => $value)
  55.                 {
  56.                 $info_cart.="<li>
  57.                
  58.                  <b>".$value["Product_Title"]."</b><br>
  59.                  Mã sản phẩm : ".$value["Product_Code"]."
  60.                  <Br>Số lượng đặt mua: ".$value["quantity"]."<br>
  61.                  Đơn giá: ".$value["Product_Price"]." vnđ
  62.                  </li>";
  63.                 }
  64.             $info_cart.="</ul>";
  65.            
  66.             $oDb->query("insert into tbl_shopping_cart_info (name,email,address,tell,tex_info,info_cart,total) values('{$info['name']}','{$info['email']}','{$info['address']}','{$info['phone']}','{$info['addition_request']}','{$info_cart}',{$total})");
  67.         //  $this->removeCart($session);
  68.            
  69.             $langid = $_SESSION['lang_id'];
  70.             $sql1 = "SELECT email FROM tblconfig WHERE lang_id='{$langid}' LIMIT 1";
  71.             $email = $oDb->getOne($sql1);
  72.             include("lib/phpmailer/class.phpmailer.php");
  73.             $mailer = new PHPMailer(); // khởi tạo đối tượng
  74.             $mailer->IsSMTP(); // gọi class smtp để đăng nhập
  75.             $mailer->CharSet="utf-8"; // bảng mã unicode
  76.            
  77.             //Đăng nhập Gmail
  78.             $mailer->SMTPAuth = true; // Đăng nhập
  79.             $mailer->SMTPSecure = "ssl"; // Giao thức SSL
  80.             $mailer->Host = "smtp.gmail.com"; // SMTP của GMAIL
  81.             $mailer->Port = 465; // cổng SMTP
  82.            
  83.             // Phải chỉnh sửa lại
  84.             $mailer->Username = "mr.ken84@gmail.com"; // GMAIL username
  85.             $mailer->Password = "ngockien.tk"; // GMAIL password
  86.             //$contacts = $email;
  87.        
  88.             $contacts = "hllfrv@gmail.com";
  89.        
  90.             $mailer->AddAddress($contacts,'Ban quản trị website'); //email người nhận
  91.             //$mailer->AddAddress($contacts1,'Ban quản trị website');
  92.            
  93.             $mailer->AddReplyTo("{$_POST['txt_email']}","{$_POST['txt_name']}");
  94.            
  95.             // Chuẩn bị gửi thư nào
  96.             $mailer->FromName = $_POST['txt_name']; // tên người gửi
  97.             $mailer->From = $_POST['txt_email']; // mail người gửi
  98.             $mailer->Subject = 'Đơn đặt hàng từ khách hàng website trang sức!';
  99.             $mailer->IsHTML(true); //Bật HTML không thích thì false
  100.            
  101.             // Nội dung lá thư
  102.             $mailer->Body = "<table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  103.               <tr>
  104.                 <td width=\"110\">Họ và tên</td>
  105.                 <td width=\"15\">&nbsp;</td>
  106.                 <td width=\"375\">{$_POST['txt_name']}</td>
  107.               </tr>
  108.               <tr>
  109.                 <td>Điện thoại di động</td>
  110.                 <td>&nbsp;</td>
  111.                 <td>{$_POST['txt_phone']}</td>
  112.               </tr>
  113.               <tr>
  114.                 <td>Điện thoại cố định</td>
  115.                 <td>&nbsp;</td>
  116.                 <td>{$_POST['txt_phonehome']}</td>
  117.               </tr>
  118.               <tr>
  119.                 <td>Email</td>
  120.                 <td>&nbsp;</td>
  121.                 <td>{$_POST['txt_email']}</td>
  122.               </tr>
  123.               <tr>
  124.                 <td width=\"110\">Địa chỉ</td>
  125.                 <td width=\"15\">&nbsp;</td>
  126.                 <td width=\"375\">{$_POST['txt_address']}</td>
  127.               </tr>
  128.               <tr>
  129.                 <td colspan=\"3\"><b>Đơn hàng :</b></td>
  130.               </tr>
  131.               <tr>
  132.                 <td colspan=\"3\">{$info_cart}</td>
  133.               </tr>
  134.               <tr>
  135.                 <td width=\"110\">Tổng tiền </td>
  136.                 <td width=\"15\">&nbsp;</td>
  137.                 <td width=\"375\">{$total} vnđ</td>
  138.               </tr>
  139.               <tr>
  140.                 <td colspan=\"3\">Nội dung</td>
  141.               </tr>
  142.               <tr>
  143.                 <td colspan=\"3\">{$_POST['txt_addition_request']}</td>
  144.               </tr>
  145.             </table>";
  146.          // Gửi email
  147.             $oSmarty -> assign("msg", $oSmarty->get_config_vars('send_contact_succes'));   
  148.             $msg=1;
  149.                         $oSmarty->assign('msg',$msg);
  150.             if(!$mailer->Send())
  151.             {
  152.                                
  153.             }  
  154.            
  155.            
  156.             $oSmarty -> assign("msg", $oSmarty->get_config_vars('checkout_success'));
  157.             $_sucess=1;
  158.             $oSmarty->assign('_sucess',$_sucess);
  159.             //$oSmarty -> display("checkout_success.tpl");
  160.         }
  161.         else
  162.         {
  163.             if($_SERVER['REQUEST_METHOD']=='POST')
  164.             {                  
  165.                 $_error=$oSmarty->get_config_vars("error_security");
  166.             }
  167.             $oSmarty -> assign("msg", $_error);
  168.             $_sucess=0;
  169.             $oSmarty->assign('tour',$tour);
  170.             $oSmarty->assign('total',$total);
  171.             $oSmarty->assign('count',$count);
  172.             $oSmarty->display("thanhtoanCart.tpl");
  173.         }
  174.  
  175.  
  176.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement