Ejemplo n.º 1
0
 function orderAction()
 {
     $yourCart = new Zend_Session_Namespace('cart');
     if ($this->_request->isPost()) {
         $itemProduct = $this->_arrParam['itemProduct'];
         if (count($itemProduct) > 0) {
             foreach ($itemProduct as $key => $val) {
                 if ($val == 0) {
                     unset($itemProduct[$key]);
                 }
             }
         }
         $yourCart->cart = $itemProduct;
     }
     //echo count ($yourCart->cart);
     $ssInfo = $yourCart->getIterator();
     //var_dump($ssInfo);
     $tblProduct = new Default_Model_Cart();
     $this->_arrParam['cart'] = $ssInfo['cart'];
     if (count($this->_arrParam['cart']) > 0) {
         $this->view->Items = $tblProduct->listcart($this->_arrParam);
         $this->view->cart = $ssInfo['cart'];
         $buy = "";
         foreach ($ssInfo['cart'] as $key => $val) {
             $item[] = $key;
             $demo[] = $val;
             //  echo $key;
             //  echo $val;
         }
         for ($i = 0; $i < count($ssInfo['cart']); $i++) {
             $id = $item[$i];
             $sl = $demo[$i];
             $buy = $buy . "{$id}" . "___" . "{$sl}" . "______";
         }
         $buy = substr($buy, 0, -6);
         // thanh toan
         $muser = new Default_Model_Cart();
         $captcha = new Zend_Captcha_Image();
         $vi = new Zend_View();
         $base = $vi->baseurl();
         if (!$this->_request->isPost()) {
             $captcha->setTimeout('300')->setWordLen('4')->setHeight('50')->setWidth('320')->setImgDir(APPLICATION_PATH . '/../public_html/captcha/images/')->setImgUrl($base . '/captcha/images/')->setFont(APPLICATION_PATH . '/../public_html/font/UTM-Avo.ttf');
             $captcha->generate();
             $this->view->captcha = $captcha->render($this->view);
             $this->view->captchaID = $captcha->getId();
             // Dua chuoi Captcha vao session
             $captchaSession = new Zend_Session_Namespace('Zend_Form_Captcha_' . $captcha->getId());
             $captchaSession->word = $captcha->getWord();
         } else {
             $captchaID = $this->_request->captcha_id;
             $captchaSession = new Zend_Session_Namespace('Zend_Form_Captcha_' . $captchaID);
             $captchaIterator = $captchaSession->getIterator();
             $captchaWord = $captchaIterator['word'];
             if ($this->_request->captcha == $captchaWord) {
                 $session = new Zend_Session_Namespace('identity');
                 $username = $session->username;
                 $this->view->purifier = Zend_Registry::get('purifier');
                 $conf = HTMLPurifier_Config::createDefault();
                 $purifier = new HTMLPurifier($conf);
                 $fullname = $purifier->purify($this->_request->getParam('fullname'));
                 $address = $purifier->purify($this->_request->getParam('address'));
                 $phone = $purifier->purify($this->_request->getParam('phone'));
                 $email = $purifier->purify($this->_request->getParam('email'));
                 $coment = $purifier->purify($this->_request->getParam('coment'));
                 $title = $purifier->purify($this->_request->getParam('title'));
                 $emaillh = "*****@*****.**";
                 $tinnhan = "\n\t\t\tHọ tên : {$fullname} <br>\n\t\t\tEmail : {$email}<br>\n\t\t\tĐịa chỉ : {$address}<br>\n\t\t\tĐiện thoại : {$phone}<br>\n\t\t\t\n\t\t\tNội dung : {$coment}<br>";
                 $to = $emaillh;
                 $subject = $title;
                 $message = $tinnhan;
                 $headers = 'Content-type: text/html;charset=utf-8';
                 mail($to, $subject, $message, $headers);
                 // Thiết lập SMTP Server
                 require 'ham/class.phpmailer.php';
                 require 'ham/class.pop3.php';
                 // nạp thư viện
                 $mailer = new PHPMailer();
                 // khởi tạo đối tượng
                 $mailer->IsSMTP();
                 // gọi class smtp để đăng nhập
                 $mailer->CharSet = "utf-8";
                 // bảng mã unicode
                 //Đăng nhập Gmail
                 $mailer->SMTPAuth = true;
                 // Đăng nhập
                 $mailer->SMTPSecure = "ssl";
                 // Giao thức SSL
                 $mailer->Host = "smtp.gmail.com";
                 // SMTP của GMAIL
                 $mailer->Port = 465;
                 // cổng SMTP
                 // Phải chỉnh sửa lại
                 $mailer->Username = "******";
                 // GMAIL username
                 $mailer->Password = "******";
                 // GMAIL password
                 $mailer->AddAddress("{$emaillh}", 'Recipient Name');
                 //email người nhận
                 // Chuẩn bị gửi thư nào
                 $mailer->FromName = "{$fullname}";
                 // tên người gửi
                 $mailer->From = "{$email}";
                 // mail người gửi
                 $mailer->Subject = "{$base}";
                 $mailer->IsHTML(true);
                 //Bật HTML không thích thì false
                 // Nội dung lá thư
                 $mailer->Body = "{$tinnhan}";
                 // Gửi email
                 if (!$mailer->Send()) {
                     // Gửi không được, đưa ra thông báo lỗi
                     echo "Không gửi được ";
                     echo "Lỗi: " . $mailer->ErrorInfo;
                 } else {
                     $muser->insert_order($address, $email, $phone, $coment, $username, $fullname, $buy);
                     Zend_Session::namespaceUnset('cart');
                     thongbao("Cảm ơn bạn đã liên hệ cho chúng tôi");
                     chuyen_trang($base);
                 }
             } else {
                 thongbao('Bạn nhập sai chuỗi Captcha');
                 trang_truoc();
             }
             $this->_helper->viewRenderer->setNoRender();
             $mask = APPLICATION_PATH . "/../public_html/captcha/images/*.png";
             array_map("unlink", glob($mask));
         }
     } else {
         //echo "Bạn chưa mua hàng";
     }
 }
Ejemplo n.º 2
0
 function Cart()
 {
     echo "<div class=\"title2\">\n<div style=\"padding-top:10px;\" align=\"center\">GIỎ HÀNG</div>\n</div>\n<div class=\"hotro\" align=\"center\">\n\n<BR />";
     $yourCart = new Zend_Session_Namespace('cart');
     $ssInfo = $yourCart->getIterator();
     // var_dump($ssInfo); exit;
     if (isset($ssInfo['cart'])) {
         $cart = new Default_Model_Cart();
         $cart->cart_order($ssInfo['cart']);
     } else {
         echo "Hiện chưa có sản phẩm nào trong giỏ hàng";
     }
     echo "</div>";
 }