コード例 #1
0
    public function approvedAction()
    {
        $producturrency = new Admin_Model_DbTable_Countries();
        $modelAuthor = new Publisher_Model_DbTable_Publishers();
        $tempObj = new Model_DbTable_Checkout();
        $creditHistoryObj = new User_Model_DbTable_Chistory();
        $transactionHistoryObj = new User_Model_DbTable_Transactionhistory();
        $this->modelBooks = new Publisher_Model_DbTable_Books();
        $modelImage = new Publisher_Model_DbTable_BookImages();
        $modelStore = new Admin_Model_DbTable_Countries();
        $productPrice = new Publisher_Model_DbTable_BookPrices();
        $productPrice = new Publisher_Model_DbTable_BookPrices();
        $groupSubsObj = new Company_Model_DbTable_GroupSubscriptions();
        $UsersubObj = new Model_DbTable_Usersubscription();
        $userCompanyObj = new Company_Model_DbTable_Companies();
        $response = $_POST['xmlmsg'];
        $xml_string = $_POST['xmlmsg'];
        $parsedxml = simplexml_load_string(stripslashes($response));
        //echo "<pre>";
        //print_r($parsedxml);
        $formDataTransApproved = array();
        foreach ($parsedxml as $RESPONSENODE) {
            //echo $RESPONSENODE."<br/>";
            if ($RESPONSENODE->getName() == 'OrderID') {
                $orderId = $RESPONSENODE;
                $orderIdForPurchase = $RESPONSENODE;
                $orderIdss = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'TransactionType') {
                $transactionType = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'PAN') {
                $pan = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'PurchaseAmountScr') {
                $purchaseAmount = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'TranDateTime') {
                $tranDateTime = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'ResponseCode') {
                $responseCode = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'ResponseDescription') {
                $responseDescription = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'OrderStatusScr') {
                $orderStatus = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'ApprovalCode') {
                $approvalCode = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'MerchantTranID') {
                $merchantTranId = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'OrderDescription') {
                $orderDescription = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'ApprovalCodeScr') {
                $approvalCodeScr = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'CurrencyScr') {
                $currency = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'ThreeDSVerificaion') {
                $threeDsVerification = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'Brand') {
                $brandname = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'Name') {
                $card_holder_name = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'ThreeDSStatus') {
                $ThreeDSStatus = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'MerchantTranID') {
                $MerchantTranID = $RESPONSENODE;
            }
        }
        $formDataTransApproved = array("orderId" => $orderId, "transactionType" => $transactionType, "pan" => $pan, "purchaseAmount" => $purchaseAmount, "tranDateTime" => $tranDateTime, "responseCode" => $responseCode, "responseDescription" => $responseDescription, "orderStatus" => $orderStatus, "approvalCode" => $approvalCode, "approvalCode" => $approvalCode, "merchantTranId" => $merchantTranId, "orderDescription" => $orderDescription, "approvalCodeScr" => $approvalCodeScr, "currency" => $currency, "brand" => $brandname, "card_holder_name" => $card_holder_name, "ThreeDSStatus" => $ThreeDSStatus, "threeDsVerification" => $threeDsVerification, "transaction_xml" => $xml_string);
        $inserted_id = $transactionHistoryObj->insert($formDataTransApproved);
        ##############  update table ###########################
        if ($orderStatus == 'APPROVED') {
            $orderSt = 1;
        } else {
            $orderSt = 0;
        }
        $tempTransactionUpdate = array("payment_status" => $orderSt, "transaction_id" => $inserted_id);
        //$tempObj->update($tempTransactionUpdate,'user_id="'.$user_id.'"');
        $creditHistoryObj->update($tempTransactionUpdate, "order_id='" . $orderId . "'");
        ##########################################################
        $total_price = '';
        $tempData = $tempObj->fetchAll("order_id='" . $orderId . "' and is_purchase!='1'");
        //$tempData = $tempObj->fetchAll("order_id='38115' and is_purchase!='1'");
        $css1 = ' style="text-align:center;padding:5px;word-wrap:break-word;color:#fff;max-width: 150px;" ';
        $order_details = "<table cellpadding='4' cellpadding='1' width='100%' style='background:#656565;;color:#fff;border-collapse:collapse;' border='1' BORDERCOLOR='#000'><tr><td colspan='9'>Your reference Id</td></tr><tr><td colspan='9'>Order ID:" . $orderId . "</td></tr><tr><td colspan='9'>Transaction ID:" . $inserted_id . "</td></tr><tr><td" . $css1 . ">Item Image</td><td" . $css1 . ">Title</td><td" . $css1 . ">Subscribed users</td><td" . $css1 . ">Price</td><td" . $css1 . ">Subscription Details</td><td" . $css1 . ">Number of Issues</td><td" . $css1 . ">Start Date</td><td" . $css1 . ">End Date</td><td" . $css1 . ">Quantity</td></tr>";
        $array_new = array();
        $new_product_array = array();
        foreach ($tempData as $dataDet) {
            $publication_det = $this->modelBooks->fetchRow("id='" . $dataDet['product_id'] . "'");
            if (@in_array($publication_det['publisher_id'], $array_new)) {
                $new_product_array[$publication_det['publisher_id']][] = array("id" => $dataDet['id'], "product_id" => $dataDet['product_id'], "user_id" => $dataDet['user_id'], "user_type" => $dataDet['user_type'], "store_id" => $dataDet['store_id'], "quntity" => $dataDet['quntity'], "group_id" => $dataDet['group_id'], "order_id" => $dataDet['group_id']);
            } else {
                array_push($array_new, $publication_det['publisher_id']);
                $new_product_array[$publication_det['publisher_id']][] = array("id" => $dataDet['id'], "product_id" => $dataDet['product_id'], "user_id" => $dataDet['user_id'], "user_type" => $dataDet['user_type'], "store_id" => $dataDet['store_id'], "quntity" => $dataDet['quntity'], "group_id" => $dataDet['group_id'], "order_id" => $dataDet['group_id']);
            }
        }
        $modelSubscription = new Publisher_Model_DbTable_Subscriptions();
        foreach ($tempData as $dataDet) {
            $order_idsids = $dataDet['order_id'];
            $user_ids_mail[] = $dataDet['user_id'];
            $productPriceInfo = $productPrice->getPriceByStoreId($dataDet['product_id'], $dataDet['store_id']);
            $subscription_data = $modelSubscription->fetchAll('id="' . $dataDet['subscription_type'] . '"');
            if ($dataDet['group_id'] != '' && $dataDet['group_id'] != 0) {
                $arrayDataGroup = '';
                $dateTime = date('Y-m-d H:i:s');
                $price = $productPriceInfo['group_price'];
                $arrayDataGroup = array("publication_id" => $dataDet['product_id'], "group_id" => $dataDet['group_id'], "company_id" => $dataDet['user_id'], "assigned_date" => $dateTime);
                $groupSubsObj->insert($arrayDataGroup);
            } else {
                $price = $productPriceInfo['price'];
            }
            $product_details = $this->modelBooks->fetchRow("id='" . $dataDet['product_id'] . "'");
            $getBrandInfo = $this->modelBooks->getBrandInfo($product_details['title']);
            if (!empty($getBrandInfo) && is_numeric($this->{$product_details}['title'])) {
                $titleBrand = $getBrandInfo['brand'];
            } else {
                $titleBrand = $product_details['title'];
            }
            if (!empty($product_details['parent_brand_id']) && $product_details['cat_id'] != '3') {
                $productInfo = $this->modelBooks->fetchRow('id="' . $product_details['parent_brand_id'] . '"');
                $getParentBrandInfo = $this->modelBooks->getBrandInfo($productInfo->title);
                $authorInfo = $modelAuthor->getInfoByPublisherId($product_details['publisher_id']);
                if (!empty($getParentBrandInfo)) {
                    //$titleBrand=$titleBrand.' ('.$getParentBrandInfo['brand'].')';
                    //$titleBrand=$getParentBrandInfo['brand']." - ".$titleBrand."<br/>".$authorInfo['publisher'];
                    $titleBrand = $getParentBrandInfo['brand'] . "<br/>" . $authorInfo['publisher'];
                }
            }
            $getCurrencyName = $producturrency->getCurrencyCode($dataDet['store_id']);
            $authorInfo = $modelAuthor->getInfoByPublisherId($product_details['author_id']);
            $imageInfo = $modelImage->getImageInfoByProductId($product_details['id']);
            $sql1 = "update pclive_products set best_seller=best_seller+1 where id='" . $dataDet['product_id'] . "'";
            $result1 = $this->modelBooks->getAdapter()->query($sql1);
            $todaysdate = date('Y-m-d H:i:s');
            if ($dataDet['subscription_name'] == 'Weekly') {
                $date = new DateTime($todaysdate);
                $date->modify("+7 day");
                $end_date = $date->format("Y-m-d H:i:s");
            } else {
                if ($dataDet['subscription_name'] == 'Monthly') {
                    $date = new DateTime($todaysdate);
                    $date->modify("+30 day");
                    $end_date = $date->format("Y-m-d H:i:s");
                } else {
                    if ($dataDet['subscription_name'] == 'Quarterly') {
                        $date = new DateTime($todaysdate);
                        $date->modify("+90 day");
                        $end_date = $date->format("Y-m-d H:i:s");
                    } else {
                        if ($dataDet['subscription_name'] == 'Half Yearly') {
                            $date = new DateTime($todaysdate);
                            $date->modify("+182 day");
                            $end_date = $date->format("Y-m-d H:i:s");
                        } else {
                            if ($dataDet['subscription_name'] == 'Yearly') {
                                $date = new DateTime($todaysdate);
                                $date->modify("+365 day");
                                $end_date = $date->format("Y-m-d H:i:s");
                            }
                        }
                    }
                }
            }
            if (count($subscription_data) > 0) {
                $price_to_show = $dataDet['subscription_price'];
                $subtype = $dataDet['subscription_name'];
                $subscription_issues = $dataDet['subscription_issues'];
                $todaysdate = $todaysdate;
                $end_date = $end_date;
            } else {
                $price_to_show = $price;
                $subtype = "N/A";
                $subscription_issues = "N/A";
                $todaysdate = "N/A";
                $end_date = "N/A";
            }
            if ($dataDet['user_type'] == "1") {
                $finalsubprice = $price_to_show * $dataDet['quntity'];
            } else {
                $finalsubprice = $price_to_show;
            }
            if ($dataDet['group_id'] != '' && $dataDet['group_id'] != 0) {
                $subscriptiondatavalues = $UsersubObj->fetchAll('order_id=' . $dataDet['order_id'] . ' and product_id=' . $dataDet['product_id'] . '');
                $useremails = "";
                foreach ($subscriptiondatavalues as $userdata) {
                    $user_details = $userCompanyObj->fetchRow("id='" . $userdata['user_id'] . "'");
                    $useremails .= $user_details['user_email'] . ',';
                }
                $useremails = rtrim($useremails, ',');
            } else {
                $useremails = 'N/A';
            }
            $imageInfo = $modelImage->getImageInfoByProductId($dataDet['product_id']);
            $quntity_price = $finalsubprice;
            $price_quan = $producturrency->currencyconverter($getCurrencyName, "NGN", $quntity_price);
            $price_in = $producturrency->currencyconverter($getCurrencyName, "NGN", $price_to_show);
            $total_price = $total_price + $price_quan;
            //if($dataDet['is_purchase']!='1')
            //{
            $order_details .= '<tr>
									<td' . $css1 . '><img src="' . $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . "thumb1_" . $imageInfo['image_name'] . '"></td>
									<td' . $css1 . '>' . $titleBrand . '</td>
									<td' . $css1 . '>' . $useremails . '</td>
									<td' . $css1 . '>' . $price_in . '</td>
									<td' . $css1 . '>' . $subtype . '</td>
									<td' . $css1 . '>' . $subscription_issues . '</td>
									<td' . $css1 . '>' . $todaysdate . '</td>
									<td' . $css1 . '>' . $end_date . '</td>
									<td' . $css1 . '>' . $dataDet['quntity'] . '</td>
								</tr>
								';
            //}
            //if($dataDet['is_purchase']!='1')
            //{
            //$quntity_price = $dataDet['quntity']*$price;
            //$order_details.= "<tr><td>".$titleBrand."</td><td>".$producturrency->currencyconverter($getCurrencyName,"NGN",$price)."</td><td>".$dataDet['quntity']."</td></tr><tr><td colspan='3' align='left'>Sub Total: &#x20a6;".@mumber_format($producturrency->currencyconverter($getCurrencyName,"NGN",$quntity_price),2)."</td></tr>";
            //}
        }
        $order_details .= '<tr><td colspan="6" align="left">&nbsp;</td><td colspan="2">Sub Total :</td><td> &#x20a6;' . $price_quan . '</td></tr>';
        $order_details .= "<tr><td colspan='6'>&nbsp;</td><td colspan='2' >Total : </td><td>" . $total_price . "</td></tr>";
        $order_details .= "</table>";
        $tempObj->delete('order_id="' . $orderIdForPurchase . '"');
        //echo $order_details;
        //exit;
        ###########################################  mail action ############################
        $userCompanyObj = new Company_Model_DbTable_Companies();
        $storage_company = new Zend_Auth_Storage_Session('company_type');
        $company_data = $storage_company->read();
        $storage = new Zend_Auth_Storage_Session('account_type');
        $data = $storage->read();
        if ($data->id) {
            $user_id = $data->id;
        } elseif ($company_data->id) {
            $user_id = $company_data->id;
        }
        $user_details = $userCompanyObj->fetchRow("id='" . $user_id . "'");
        $mailhost = SMTP_SERVER;
        $mailconfig = array('ssl' => SMTP_SSL, 'port' => SMTP_PORT, 'auth' => SMTP_AUTH, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD);
        $transport = new Zend_Mail_Transport_Smtp($mailhost, $mailconfig);
        Zend_Mail::setDefaultTransport($transport);
        $message = '<!DOCTYPE html> 
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <title>Evendor</title>
    </head>
    <body style="font-family: \'Calibri\', arial;">
        <div id="container" style="width:80%; margin:0 auto;">
            <header id="heder">
                <div style="padding:15px 0px; background:#000000; color:#fff;">
                    <a href="' . $this->view->serverUrl() . $this->view->baseUrl() . '/" target="_blank">
                        <img src="' . $this->view->serverUrl() . $this->view->baseUrl() . '/public/css/default/images/logo.png" style="border:none;" alt="E-Vendor">
                    </a>
                </div>
            </header>
            <div style="background:#656565; padding:15px; min-height:200px;color:#fff;">                 
                <span >Hi ' . $user_details['first_name'] . ' ' . $user_details['last_name'] . ',<br/><br/>
                Your order has been successfully completed.Please check your order details.<br><br></span>
                ' . $order_details . '<table border="0" cellpadding="5" style="background:#656565;color:#fff;width:100%;" width="100%"><tr><td colspan="2">Transaction message:' . $responseDescription . '</td></tr>
                <tr><td>Masked PAN:' . $pan . '</td><td>Card Holder Name:' . $card_holder_name . '</td></tr>
                <tr><td>Transaction Date & Time:' . $tranDateTime . '</td><td>Transactions reference number(MerchantTranID):' . $MerchantTranID . '</td></tr>
                <tr><td>Transaction Amount:' . $purchaseAmount . '</td><td>Transaction Currency:' . $currency . '</td></tr>
                <tr><td>Authorization Code:' . $approvalCodeScr . '</td><td>Merchant Name:Evendor</td></tr>
                <tr><td colspan="2">Site Url : <a style="color:#fff;text-decoration:none;" href="' . $this->view->serverUrl() . $this->view->baseUrl() . '">' . $this->view->serverUrl() . $this->view->baseUrl() . '</a></td></tr></table><br/>
                <br/><br/><br/>
                Thank You<br/><br/>
                Evendor                 
            </div>

            <div style="background:#000000;  text-align:center; color:#FFFFFF; font-size:14px; padding:15px;">                
                &copy; Copyright ' . date("Y") . ' All Rights Reserved By Electronic Vendor Ltd.
            </div>

        </div>
    </body>
</html>';
        if ($user_details['user_email'] != '') {
            $mail = new Zend_Mail();
            $mail->addTo($user_details['user_email']);
            //$mail->addTo('*****@*****.**');
            $mail->setSubject("Order Approved message.");
            $mail->setBodyHtml($message);
            $mail->setFrom(SETFROM, SETNAME);
            $mail->send();
        }
        ##############################  admin Message ###################################
        $message_admin = '<!DOCTYPE html>
				<html>
				<head>
				<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
				<meta charset="utf-8">
				<meta name="viewport" content="width=device-width,initial-scale=1.0">
				<title>Evendor</title>
				</head>
				<body style="font-family: \'Calibri\', arial;">
				<div id="container" style="width:80%; margin:0 auto;">
				<header id="heder">
				<div style="padding:15px 0px; background:#000000;"><a href="' . $this->view->serverUrl() . $this->view->baseUrl() . '/" target="_blank"><img src="' . $this->view->serverUrl() . $this->view->baseUrl() . '/public/css/default/images/logo.png" style="border:none;" alt="E-Vendor"></a></div>
				</header>
				<div style="background:#656565; padding:15px; min-height:200px;color:#fff;">
					Hi,<br/><br/>' . $user_details['first_name'] . ' ' . $user_details['last_name'] . ' has been successfully ordered.Please see your order details.<br/><br/>
						' . $order_details . '<br/>Transaction message:' . $responseDescription . '
						<br/>Transaction Date & Time:' . $tranDateTime . '<br/>
						
						<br/>Transactions reference number(MerchantTranID):' . $MerchantTranID . '<br/>
						<br/>Transaction Amount:' . $purchaseAmount . '<br/>
						<br/>Transaction Currency:' . $currency . '<br/>
						<br/>Authorization Code:' . $approvalCodeScr . '<br/>
						<br/>Merchant Name:Evendor<br/>
						<br/>Site Url : <a style="color:#fff;" href="' . $this->view->serverUrl() . $this->view->baseUrl() . '">' . $this->view->serverUrl() . $this->view->baseUrl() . '</a><br/>
						<br/><br/><br/>
						Thank You<br/>
						Evendor 
				</div>

				<div style="background:#000000;  text-align:center; color:#FFFFFF; font-size:14px; padding:15px;">
				<br>
				&copy; Copyright ' . date("Y") . ' All Rights Reserved By Electronic Vendor Ltd.
				</div>

				</div>
				</body>
				</html>';
        //die($message_admin);
        ##################################################  end admin message #####################
        /*if ($user_details['user_email'] != '') {
              $mail = new Zend_Mail();
              //$mail->addTo($user_details['user_email']);
              $mail->addTo('*****@*****.**');
              $mail->setSubject("Order Approved message.");
              $mail->setBodyHtml($message);
              $mail->setFrom(SETFROM, SETNAME);
              $mail->send();
          }*/
        $get_registeration_id = mysql_query("select * from pclive_deviceID where user_publisher_id='" . $user_details['id'] . "' and reg_id!=''");
        while ($res_registeration_id = mysql_fetch_array($get_registeration_id)) {
            $reg = $res_registeration_id['reg_id'];
            $regID = array($reg);
            // $message="You have registerted successfully";
            $message = array("userID" => $user_details['id'], "msg" => "publication is ready to download", "email" => $user_details['user_email']);
            if ($res_registration_id['os_type'] == 0) {
                send_push_notification($regID, $message);
            } else {
                send_push_notification_ios($regID, $user_details['user_email'], $user_details['id'], "publication is ready to download");
            }
        }
        //$reg='APA91bEZVTcqtar_br_cipLae9TyYe26JhsE2jHHnV76K_zWSAAyly2ZW6SCd4-REMgY_lGtHLh-2VvObjlj-pRvHd2932KlKY7anEOKQMyviVLs1A1Y7RYDPNtXwuRqTY7rILdF_LcXvY4GntxKouBU1EUv8E1mCQ';
        if ($company_data->account_type == '1') {
            $subscriptiondatavalues = $UsersubObj->fetchAll('order_id=' . $orderId . ' and active_date IS NULL');
            foreach ($subscriptiondatavalues as $dataDetsubscribe) {
                $productdetails = $this->modelBooks->fetchRow("id='" . $dataDetsubscribe['product_id'] . "'");
                $getBrandInfo = $this->modelBooks->getBrandInfo($productdetails['title']);
                if (!empty($getBrandInfo) && is_numeric($productdetails['title'])) {
                    $titleBrand = $getBrandInfo['brand'];
                } else {
                    $titleBrand = $productdetails['title'];
                }
                if (!empty($productdetails['parent_brand_id']) && $productdetails['cat_id'] != '3') {
                    $productInfo = $this->modelBooks->fetchRow('id="' . $productdetails['parent_brand_id'] . '"');
                    $getParentBrandInfo = $this->modelBooks->getBrandInfo($productInfo->title);
                    $authorInfo = $modelAuthor->getInfoByPublisherId($productdetails['publisher_id']);
                    if (!empty($getParentBrandInfo)) {
                        //$titleBrand=$titleBrand.' ('.$getParentBrandInfo['brand'].')';
                        //$titleBrand=$getParentBrandInfo['brand']." - ".$titleBrand."<br/>".$authorInfo['publisher'];
                        $titleBrand = $getParentBrandInfo['brand'] . "<br/>" . $authorInfo['publisher'];
                    }
                }
                $user_details_all = $userCompanyObj->fetchRow("id='" . $dataDetsubscribe['user_id'] . "'");
                $message1 = 'Hi ' . $user_details_all['first_name'] . ' ' . $user_details_all['last_name'] . ', you have been subscribed for the ' . $dataDetsubscribe['subscription_name'] . ' subscription for the product ' . $titleBrand . '  in evendor. You can download ' . $dataDetsubscribe['number_of_issues'] . ' issues. Your subscription starts from ' . $dataDetsubscribe['start_date'] . ' and ends on ' . $dataDetsubscribe['end_date'] . '.Please see your order details.<br/><br/>
				' . $order_details . '';
                if ($user_details_all['user_email'] != '') {
                    $mail = new Zend_Mail();
                    $mail->addTo($user_details_all['user_email']);
                    //$mail->addTo('*****@*****.**');
                    $mail->setSubject("Order Approved message.");
                    $mail->setBodyHtml($message1);
                    $mail->setFrom(SETFROM, SETNAME);
                    $mail->send();
                }
                /* $mail = new Zend_Mail();
                   $mail->addTo('*****@*****.**');
                   $mail->setSubject("Order Approved message.");
                   $mail->setBodyHtml($message1);
                   $mail->setFrom(SETFROM, SETNAME);
                   $mail->send(); */
                $get_registeration_id = mysql_query("select * from pclive_deviceID where user_publisher_id='" . $user_details_all['id'] . "' and reg_id!=''");
                while ($res_registeration_id = mysql_fetch_array($get_registeration_id)) {
                    $reg = $res_registeration_id['reg_id'];
                    $regID = array($reg);
                    // $message="You have registerted successfully";
                    $message = array("userID" => $user_details_all['id'], "msg" => "publication is ready to download", "email" => $user_details_all['user_email']);
                    if ($res_registration_id['os_type'] == 0) {
                        send_push_notification($regID, $message);
                    } else {
                        send_push_notification_ios($regID, $user_details['user_email'], $user_details['id'], "publication is ready to download");
                    }
                    //send_push_notification($regID, $message);
                }
                //$reg='APA91bEZVTcqtar_br_cipLae9TyYe26JhsE2jHHnV76K_zWSAAyly2ZW6SCd4-REMgY_lGtHLh-2VvObjlj-pRvHd2932KlKY7anEOKQMyviVLs1A1Y7RYDPNtXwuRqTY7rILdF_LcXvY4GntxKouBU1EUv8E1mCQ';
                /* $reg='APA91bFkjucY1iaCcNprgfIZ_ajoQLv_Ky_jGIH8Y83a3by9fO_ych0yMqG7v9PpJzgttzzbwWZ5SOv6QQV1uYocH4OlyaAsPPi4vvOJILk9YVaVsx2xItJ83_0gXsVDM71LosYKoAqHpdQVx9hXuY5RGXr3LJuzWg';
                
                                  $regID = array($reg);
                                  // $message="You have registerted successfully";
                                  $message = array("userID" =>$user_details_all['id'],"msg" =>"publication is ready to download","email" =>$user_details_all['user_email'],);
                                  send_push_notification($regID, $message); */
            }
        }
        foreach ($new_product_array as $key => $pubVal) {
            $order_details_publisher = "<table cellpadding='1' width='100%' style='background:#656565;color:#fff;'>\n\t\t\t\t\t\t\t\t\t\t<tr><td>Item</td><td>Price</td><td>Quantity</td></tr>";
            foreach ($pubVal as $pub_order_det) {
                $productPriceInfo = $productPrice->getPriceByStoreId($pub_order_det['product_id'], $pub_order_det['store_id']);
                if ($pub_order_det['group_id'] != '' && $pub_order_det['group_id'] != 0) {
                    $arrayDataGroup = '';
                    $dateTime = date('Y-m-d H:i');
                    $price = $productPriceInfo['group_price'];
                } else {
                    $price = $productPriceInfo['price'];
                }
                $product_details = $this->modelBooks->fetchRow("id='" . $pub_order_det['product_id'] . "'");
                $getBrandInfo = $this->modelBooks->getBrandInfo($product_details['title']);
                if (!empty($getBrandInfo) && is_numeric($this->{$product_details}['title'])) {
                    $titleBrand = $getBrandInfo['brand'];
                } else {
                    $titleBrand = $product_details['title'];
                }
                if (!empty($product_details['parent_brand_id']) && $product_details['cat_id'] != '3') {
                    $productInfo = $this->modelBooks->fetchRow('id="' . $product_details['parent_brand_id'] . '"');
                    $getParentBrandInfo = $this->modelBooks->getBrandInfo($productInfo->title);
                    if (!empty($getParentBrandInfo)) {
                        //$titleBrand=$titleBrand.' ('.$getParentBrandInfo['brand'].')';
                        //$titleBrand=$getParentBrandInfo['brand']." - ".$titleBrand;
                        $titleBrand = $getParentBrandInfo['brand'];
                    }
                }
                $getCurrencyName = $producturrency->getCurrencyCode($pub_order_det['store_id']);
                $authorInfo = $modelAuthor->getInfoByPublisherId($product_details['author_id']);
                $imageInfo = $modelImage->getImageInfoByProductId($product_details['id']);
                if (count($subscription_data) > 0) {
                    if ($dataDet['group_id'] != '' && $dataDet['group_id'] != 0) {
                        $price_to_show = $subscription_data[0]->group_price_sub;
                    } else {
                        $price_to_show = $subscription_data[0]->individual_price;
                    }
                } else {
                    $price_to_show = $price;
                }
                if ($dataDet['user_type'] == "1") {
                    $finalsubprice = $price_to_show * $dataDet['quntity'];
                } else {
                    $finalsubprice = $price_to_show;
                }
                $quntity_price = $finalsubprice;
                $price_quan = $producturrency->currencyconverter($getCurrencyName, "NGN", $quntity_price);
                $price_in = $producturrency->currencyconverter($getCurrencyName, "NGN", $price_to_show);
                $total_price = $total_price + $price_quan;
                //if($dataDet['is_purchase']!='1')
                //{
                $order_details_publisher .= "<tr>\n\t\t\t\t\t\t\t\t\t\t<td>" . $titleBrand . "</td>\n\t\t\t\t\t\t\t\t\t\t<td>" . $price_in . "</td>\n\t\t\t\t\t\t\t\t\t\t<td>" . $pub_order_det['quntity'] . "</td>\n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td colspan='3' align='left'>Sub Total: &#x20a6;" . $price_quan . "</td></tr>";
            }
            $order_details_publisher .= "<tr><td colspan='3'>Total: " . $total_price . "</td></tr>";
            $order_details_publisher .= "</table>";
            $message_publisher = '<!DOCTYPE html>
				<html>
				<head>
				<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
				<meta charset="utf-8">
				<meta name="viewport" content="width=device-width,initial-scale=1.0">
				<title>Evendor</title>
				</head>
				<body style="font-family: \'Calibri\', arial;">
				<div id="container" style="width:80%; margin:0 auto;">
				<header id="heder">
				<div style="padding:15px 0px; background:#000000;"><a href="' . $this->view->serverUrl() . $this->view->baseUrl() . '/" target="_blank"><img src="' . $this->view->serverUrl() . $this->view->baseUrl() . '/public/css/default/images/logo.png" style="border:none;" alt="E-Vendor"></a></div>
				</header>
				<div style="background:#656565; padding:15px; min-height:200px;color:#fff;">
					Hi Publisher,<br/><br/>User has been successfully ordered.Please review order details.<br/><br/>
						' . $order_details . '<br/>Transaction message:' . $responseDescription . '
						<br/>Transaction Date & Time:' . $tranDateTime . '<br/>						
						<br/>Merchant Name:Evendor<br/>
						<br/>Site Url : <a style="color:#fff;" href="' . $this->view->serverUrl() . $this->view->baseUrl() . '">' . $this->view->serverUrl() . $this->view->baseUrl() . '</a><br/>
						<br/><br/><br/>
						Thank You<br/>
						Evendor
				</div>

				<div style="background:#000000;  text-align:center; color:#FFFFFF; font-size:14px; padding:15px;">
				<br>
				&copy; Copyright ' . date("Y") . ' All Rights Reserved By Electronic Vendor Ltd.
				</div>

				</div>
				</body>
				</html>';
            // die($message_publisher);
            $mail = new Zend_Mail();
            $mail->addTo('*****@*****.**');
            //$mail->addTo('*****@*****.**');
            $mail->setSubject("Order Approved message.");
            $mail->setBodyHtml($message_publisher);
            $mail->setFrom(SETFROM, SETNAME);
            $mail->send();
        }
        $this->_redirect('checkout/displayorder/orderid/' . $orderIdForPurchase);
        exit;
    }
コード例 #2
0
    public function activeAction()
    {
        $arrayids = array();
        $this->usersubscriptions = new Model_DbTable_Usersubscription();
        $this->userdetails = new Model_DbTable_Companies();
        $modelCategory = new Publisher_Model_DbTable_Books();
        $this->notifications = new Admin_Model_DbTable_Notifications();
        $modelImage = new Admin_Model_DbTable_ProductImages();
        $modelPrice = new Admin_Model_DbTable_ProductPrices();
        $creditHistoryObj = new User_Model_DbTable_Chistory();
        $this->modelBooks = new Publisher_Model_DbTable_Books();
        $notificationdata = $this->notifications->fetchAll('ntype="booksubscription" and status=1');
        $bookuploaddata = $this->notifications->fetchAll('ntype="bookupload" and status=1');
        $pid = $this->_request->getParam('pid', 0);
        $id = $this->_request->getParam('id', 0);
        $transactionHistoryObj = new User_Model_DbTable_Transactionhistory();
        if ($id > 0 && $this->modelPublications->isExist($id)) {
            $data['admin_approve'] = 1;
            $success = $this->modelPublications->update($data, 'id="' . $id . '"');
            if ($success) {
                $this->usersubscriptionsdata = $this->usersubscriptions->fetchAll('subscription_type >0
				 and publication_id=' . $pid . ' and start_date!="0000-00-00 00:00:00"');
                if (count($this->usersubscriptionsdata) > 0) {
                    if (count($bookuploaddata) > 0) {
                        foreach ($this->usersubscriptionsdata as $row_subdata) {
                            /*echo "publication id : - ".$pid;
                            		echo 'subscription_type >0
                            		AND number_of_issues > number_of_downloaded and product_id='.$id.' and user_id="'.$row_userids['id'].'"';
                            		die();*/
                            $product_details = $this->modelBooks->fetchRow("id='" . $id . "'");
                            $explode_product_addtime = @explode(" ", $product_details['add_time']);
                            $explode_start_date = @explode(" ", $row_subdata['start_date']);
                            $this->totalactivesubscription = $this->usersubscriptions->fetchAll('subscription_type >0
						 and publication_id=' . $pid . ' and user_id="' . $row_subdata['user_id'] . '" and start_date IS NULL');
                            $this->totalactivesubscription_with_startdate = $this->usersubscriptions->fetchAll('subscription_type >0
						AND number_of_issues > number_of_downloaded and publication_id=' . $pid . ' and user_id="' . $row_subdata['user_id'] . '" and start_date IS NOT NULL');
                            $totalactive = count($this->totalactivesubscription) + 1;
                            if ($this->totalactivesubscription_with_startdate[0]['number_of_issues'] > $totalactive && strtotime($product_details['add_time']) > strtotime($row_subdata['start_date'])) {
                                $this->userdata = $this->userdetails->fetchAll('id="' . $row_subdata['user_id'] . '" and status="1"');
                                $chk_subscription = $this->usersubscriptions->fetchAll('user_id="' . $row_subdata['user_id'] . '" and product_id="' . $id . '"');
                                if (count($chk_subscription) == 0) {
                                    $getBrandInfo = $this->modelBooks->getBrandInfo($product_details['title']);
                                    if (!empty($getBrandInfo) && is_numeric($product_details['title'])) {
                                        $titleBrand = $getBrandInfo['brand'];
                                    } else {
                                        $titleBrand = $product_details['title'];
                                    }
                                    if (!empty($product_details['parent_brand_id']) && $product_details['cat_id'] != '3') {
                                        $productInfo = $this->modelBooks->fetchRow('id="' . $product_details['parent_brand_id'] . '"');
                                        $getParentBrandInfo = $this->modelBooks->getBrandInfo($productInfo->title);
                                        if (!empty($getParentBrandInfo)) {
                                            $titleBrand = $getParentBrandInfo['brand'];
                                        }
                                    }
                                    $productInfo = $this->modelBooks->fetchRow('id="' . $product_details['parent_brand_id'] . '"');
                                    $getParentBrandInfo = $this->modelBooks->getBrandInfo($productInfo->title);
                                    if (!empty($getParentBrandInfo)) {
                                        //$titleBrand=$titleBrand.' ('.$getParentBrandInfo['brand'].')';
                                        //$titleBrand=$getParentBrandInfo['brand']." - ".$titleBrand;
                                        $titleBrand = $getParentBrandInfo['brand'];
                                    }
                                    $tempDatInsert = array();
                                    $formDataTransApproved = array();
                                    $getdata = $transactionHistoryObj->fetchRow('orderId=' . $row_subdata['order_id'] . '');
                                    $tempDatInsert['userid'] = $row_subdata['user_id'];
                                    $tempDatInsert['bookid'] = $id;
                                    $tempDatInsert['store_id'] = '226';
                                    $tempDatInsert['price'] = $row_subdata['subscription_price'];
                                    $tempDatInsert['quantity'] = '1';
                                    $tempDatInsert['transaction_id'] = $getdata->id;
                                    $tempDatInsert['book_name'] = $titleBrand;
                                    $tempDatInsert['add_date'] = date('Y-m-d H:i:s');
                                    $tempDatInsert['group_id'] = $this->userdata[0]['group_id'];
                                    $tempDatInsert['order_id'] = $row_subdata['order_id'];
                                    $tempDatInsert['payment_status'] = '1';
                                    $tempDatInsert['converted_price'] = $row_subdata['subscription_price'];
                                    $tempDatInsert['subscription_type'] = $row_subdata['subscription_type'];
                                    $tempDatInsert['subscription_store'] = $row_subdata['country'];
                                    $tempDatInsert['subscription_language'] = $row_subdata['language'];
                                    $tempDatInsert['subscription_name'] = $row_subdata['subscription_name'];
                                    $creditHistoryObj->insert($tempDatInsert);
                                    $formDataTransApproved = array("orderId" => $row_subdata['order_id'], "transactionType" => $getdata->transactionType, "pan" => $getdata->pan, "purchaseAmount" => $getdata->purchaseAmount, "tranDateTime" => $getdata->tranDateTime, "responseCode" => $getdata->responseCode, "responseDescription" => $getdata->responseDescription, "orderStatus" => $getdata->orderStatus, "approvalCode" => $getdata->approvalCode, "merchantTranId" => $getdata->merchantTranId, "orderDescription" => $getdata->orderDescription, "approvalCodeScr" => $getdata->approvalCodeScr, "currency" => $getdata->currency, "brand" => $getdata->brand, "card_holder_name" => $getdata->card_holder_name, "ThreeDSStatus" => $getdata->ThreeDSStatus, "threeDsVerification" => $getdata->threeDsVerification, "transaction_xml" => $getdata->transaction_xml);
                                    $inserted_id = $transactionHistoryObj->insert($formDataTransApproved);
                                    $insert_user_sub_details_array = array("order_id" => $row_subdata['order_id'], "product_id" => $id, "publisher_id" => $row_subdata['publisher_id'], "author_id" => $row_subdata['author_id'], "group_id" => $this->userdata[0]['group_id'], "user_id" => $row_subdata['user_id'], "subscription_type" => $row_subdata['subscription_type'], "subscription_name" => $row_subdata['subscription_name'], "subscription_price" => $row_subdata['subscription_price'], "country" => $row_subdata['country'], "language" => $row_subdata['language'], "publication_id" => $row_subdata['publication_id'], "company_id" => $this->userdata[0]['parent_id'], "active_date" => date('Y-m-d H:i:s'));
                                    $this->usersubscriptions->insert($insert_user_sub_details_array);
                                    $sql1 = "update pclive_products set best_seller=best_seller+1 where id='" . $id . "'";
                                    $result1 = $this->modelBooks->getAdapter()->query($sql1);
                                }
                                $publicationdetails = $this->modelPublications->fetchAll('id=' . $id . '');
                                $product_price = $modelPrice->fetchAll('product_id="' . $id . '" and country_id=226 and language_id=1');
                                $getproductimage = $modelImage->fetchAll('product_id="' . $publicationdetails[0]['id'] . '"');
                                $publisher_info_array = $this->modelPublications->getPublisherInfo($publicationdetails[0]['publisher_id']);
                                $author_info_array = $this->modelPublications->getAuthorInfo($publicationdetails[0]['author_id']);
                                $getBrandInfo = $modelCategory->getBrandInfo($publicationdetails[0]['title']);
                                if (!empty($getBrandInfo)) {
                                    $titleBrand = $getBrandInfo['brand'];
                                } else {
                                    $titleBrand = $publicationdetails[0]['title'];
                                }
                                $fullname = $this->userdata[0]['first_name'] . ' ' . $this->userdata[0]['last_name'];
                                $description_full = stripslashes($bookuploaddata[0]['message_body']);
                                $description_full = nl2br($description_full);
                                $description = str_replace("{name}", $fullname, $description_full);
                                $description = str_replace("{title}", $titleBrand, $description);
                                if (count($this->usersubscriptionsdata) > 0) {
                                    $description = str_replace("{price}", "N/A", $description);
                                } else {
                                    if (isset($product_price[0]['price']) && $product_price[0]['price'] != '') {
                                        $description = str_replace("{price}", "&#8358;" . $product_price[0]['price'], $description);
                                    }
                                }
                                if (count($getproductimage) > 0) {
                                    $linkdata = 'http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/catalogue/detail/id/' . $publicationdetails[0]['id'] . '/store/226/lang/1';
                                } else {
                                    $linkdata = "javascript:void(0);";
                                }
                                $description = str_replace("{link}", $linkdata, $description);
                                if (count($getproductimage) > 0) {
                                    $imagedata = 'http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/public/uploads/users/' . $getproductimage[0]['image_name_thumb'] . '';
                                } else {
                                    $imagedata = "";
                                }
                                $description = str_replace("{image}", $imagedata, $description);
                                $publishername = $publisher_info_array['first_name'] . " " . $publisher_info_array['last_name'];
                                $authorname = $author_info_array['first_name'] . " " . $author_info_array['last_name'];
                                $description = str_replace("{publisher}", $publishername, $description);
                                $description = str_replace("{desc}", $publicationdetails[0]['description'], $description);
                                $description = str_replace("{author}", $authorname, $description);
                                $mailhost = SMTP_SERVER;
                                $mailconfig = array('ssl' => SMTP_SSL, 'port' => SMTP_PORT, 'auth' => SMTP_AUTH, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD);
                                $transport = new Zend_Mail_Transport_Smtp($mailhost, $mailconfig);
                                Zend_Mail::setDefaultTransport($transport);
                                $mail = new Zend_Mail();
                                $mail->addTo($this->userdata[0]['user_email']);
                                $mail->setSubject(stripslashes($bookuploaddata[0]['title']));
                                $mail->setBodyHtml($description);
                                $mail->setFrom(SETFROM, SETNAME);
                                //$mail->send();
                                /*$reg='APA91bEZVTcqtar_br_cipLae9TyYe26JhsE2jHHnV76K_zWSAAyly2ZW6SCd4-REMgY_lGtHLh-2VvObjlj-pRvHd2932KlKY7anEOKQMyviVLs1A1Y7RYDPNtXwuRqTY7rILdF_LcXvY4GntxKouBU1EUv8E1mCQ';
                                
                                						$title = str_replace("_"," ",$title);
                                						$regID = array($reg);
                                						// $message="You have registerted successfully";
                                						$message = array("userID" =>$row_userids['id'],"msg" =>$bookuploaddata[0]['title']." is ready to download","email" =>$row_userids['user_email']);
                                						send_push_notification($regID, $message);*/
                                if (isset($publicationdetails[0]['file_name']) && $publicationdetails[0]['file_name'] != '' && count($getproductimage) > 0 && count($product_price) > 0) {
                                    $get_registeration_id = mysql_query("select * from pclive_deviceID where user_publisher_id='" . $this->userdata[0]['id'] . "' and reg_id!=''");
                                    $res_registeration_id = mysql_fetch_array($get_registeration_id);
                                    $reg = $res_registeration_id['reg_id'];
                                    $regID = array($reg);
                                    // $message="You have registerted successfully";
                                    $message = array("userID" => $this->userdata[0]['id'], "msg" => "publication is ready to download", "email" => $this->userdata[0]['user_email']);
                                    if ($res_registration_id['os_type'] == 0) {
                                        send_push_notification($regID, $message);
                                    } else {
                                        send_push_notification_ios($regID, $row_userids['user_email'], $this->userdata[0]['id'], "publication is ready to download");
                                    }
                                }
                            }
                        }
                    }
                }
                $this->_flashMessenger->addMessage('<div class="div-success">Product activated successfully</div>');
            } else {
                $this->_flashMessenger->addMessage('<div class="div-error">Sorry!, unable to activate product</div>');
            }
        }
        $this->_redirect('admin/publications/');
    }