public function sendAction() { $store_id = Mage::app()->getStore()->getId(); if (!Mage::helper('rewardpoints')->moduleEnabled()) { $this->norouteAction(); return; } if (!Mage::helper('rewardpoints')->allowSendRewardPointsToFriend($store_id)) { $this->norouteAction(); return; } $this->_initLayoutMessages('customer/session'); $this->_initLayoutMessages('checkout/session'); if ($this->getRequest()->getPost()) { /*if($this->_getHelper()->enabledCapcha($store_id)){ $require = dirname(dirname(__FILE__))."/Helper/Capcha/Securimage.php"; require($require); $img = new Securimage(); $valid = $img->check($this->getRequest()->getPost("code")); }else{ $valid = true; }*/ $valid = true; if ($valid) { $_customer = Mage::getModel('rewardpoints/customer')->load($this->_getSession()->getCustomer()->getId()); //current customer $point = $this->getRequest()->getPost("amount"); if ($point < 0) { $point = -$point; } if ($_customer->getMwRewardPoint() >= $point) { //send reward point $website_id = Mage::getModel('core/store')->load($store_id)->getWebsiteId(); $customer = Mage::getModel('customer/customer')->setWebsiteId($website_id)->loadByEmail($this->getRequest()->getPost("email")); if ($customer->getId() != $_customer->getId()) { if ($customer->getId()) { //Add reward points to friend Mage::helper('rewardpoints/data')->checkAndInsertCustomerId($customer->getId(), 0); $mwCustomer = Mage::getModel('rewardpoints/customer')->load($customer->getId()); $mwCustomer->addRewardPoint($point); $results = Mage::helper('rewardpoints/data')->getTransactionExpiredPoints($point, $store_id); $expired_day = $results[0]; $expired_time = $results[1]; $point_remaining = $results[2]; $historyData = array('type_of_transaction' => MW_RewardPoints_Model_Type::RECIVE_FROM_FRIEND, 'amount' => $point, 'balance' => $mwCustomer->getMwRewardPoint(), 'transaction_detail' => $_customer->getId(), 'transaction_time' => Mage::getSingleton('core/date')->gmtDate(), 'expired_day' => $expired_day, 'expired_time' => $expired_time, 'point_remaining' => $point_remaining, 'status' => MW_RewardPoints_Model_Status::COMPLETE); $mwCustomer->saveTransactionHistory($historyData); // send mail when points changed Mage::helper('rewardpoints')->sendEmailCustomerPointChanged($customer->getId(), $historyData, $store_id); //Subtract reward points of current customer $_customer->addRewardPoint(-$point); $historyData = array('type_of_transaction' => MW_RewardPoints_Model_Type::SEND_TO_FRIEND, 'amount' => $point, 'balance' => $_customer->getMwRewardPoint(), 'transaction_detail' => $customer->getId(), 'transaction_time' => Mage::getSingleton('core/date')->gmtDate(), 'status' => MW_RewardPoints_Model_Status::COMPLETE); $_customer->saveTransactionHistory($historyData); // process expired points when spent point Mage::helper('rewardpoints/data')->processExpiredPointsWhenSpentPoints($_customer->getId(), $point); // send mail when points changed Mage::helper('rewardpoints')->sendEmailCustomerPointChanged($_customer->getId(), $historyData, $store_id); $this->_getSession()->addSuccess($this->__("Your reward points were sent successfuly")); $this->_redirect('rewardpoints/rewardpoints/index'); } else { //Subtract reward points of current customer $_customer->addRewardPoint(-$point); $historyData = array('type_of_transaction' => MW_RewardPoints_Model_Type::SEND_TO_FRIEND, 'amount' => $point, 'balance' => $_customer->getMwRewardPoint(), 'transaction_detail' => $this->getRequest()->getPost("email"), 'transaction_time' => Mage::getSingleton('core/date')->gmtDate(), 'status' => MW_RewardPoints_Model_Status::PENDING); $_customer->saveTransactionHistory($historyData); // process expired points when spent point Mage::helper('rewardpoints/data')->processExpiredPointsWhenSpentPoints($_customer->getId(), $point); // send mail when points changed Mage::helper('rewardpoints')->sendEmailCustomerPointChanged($_customer->getId(), $historyData, $store_id); //customer dose not exist $this->_getSession()->addSuccess($this->__("Your reward points were sent successfully")); } if (Mage::helper('rewardpoints')->allowSendEmailNotifications($store_id)) { //Send mail to frend $store_name = Mage::getStoreConfig('general/store_information/name', $store_id); $sender = Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $store_id); $mailto = $this->getRequest()->getPost('email'); $name = $this->getRequest()->getPost('name'); $template = self::EMAIL_TO_RECIPIENT_TEMPLATE_XML_PATH; $postObject = new Varien_Object(); $postObject->setData($this->getRequest()->getPost()); $postObject->setSender($_customer->getCustomerModel()); $postObject->setData('login_link', Mage::app()->getStore($store_id)->getUrl('customer/account/login')); $postObject->setData('customer_link', Mage::app()->getStore($store_id)->getUrl('rewardpoints/rewardpoints/index')); $postObject->setData('register_link', Mage::app()->getStore($store_id)->getUrl('customer/account/create')); $postObject->setStoreName($store_name); Mage::helper('rewardpoints')->_sendEmailTransaction($sender, $mailto, $name, $template, $postObject->getData(), $store_id); } /* if(Mage::helper('rewardpoints')->allowSendEmailToSender($store_id)) { //Send mail to sender $sender = Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $store_id); $mailto = $_customer->getCustomerModel()->getEmail(); $name = $_customer->getCustomerModel()->getName(); $template = self::EMAIL_TO_SEMDER_TEMPLATE_XML_PATH; $postObject = new Varien_Object(); $postObject->setData('amount',$this->getRequest()->getPost('amount')); $postObject->setData('name',$name); Mage::helper('rewardpoints')->_sendEmailTransaction($sender,$mailto, $name, $template, $postObject->getData(),$store_id); }*/ } else { $this->_getSession()->addError($this->__("You can not send reward points to yourself")); } } else { //Current total reward points do not enought to send $this->_getSession()->addError($this->__("You do not have enough points to send to your friend")); } } else { //return error $this->_getSession()->addError($this->__("Your security code is incorrect")); } } else { $this->_getSession()->addError($this->__("You do not have permission!")); } $this->_redirect('rewardpoints/rewardpoints/index'); }
public function inviteajaxAction() { $url = trim($_POST["url_link"]); $post = trim($_POST["email"]); $message = trim($_POST["message"]); if ($post == "" || $message == "") { header('content-type: text/javascript'); $mw_email = 1; $mw_message = 1; if ($post == "") { $mw_email = 0; } if ($message == "") { $mw_message = 0; } $jsondata = array("message" => $mw_message, "email" => $mw_email, "error" => 0, "success" => 0); echo json_encode($jsondata); die; } $post = trim($post, " ,"); $emails = explode(',', $post); $validator = new Zend_Validate_EmailAddress(); $error = array(); foreach ($emails as $email) { $name = $email; $_name = $this->getStringBetween($email, '"', '"'); $_email = $this->getStringBetween($email, '<', '>'); if ($_email !== false && $_name !== false) { $email = $_email; $name = $_name; } else { if ($_email !== false && $_name === false) { if (strpos($email, '"') === false) { $email = $_email; $name = $email; } } } $email = trim($email); if ($validator->isValid($email)) { // Send email to friend $store_id = Mage::app()->getStore()->getId(); $store_name = Mage::getStoreConfig('general/store_information/name', $store_id); $template = self::EMAIL_TO_RECIPIENT_TEMPLATE_XML_PATH; $postObject = new Varien_Object(); $customer = $this->_getSession()->getCustomer(); $postObject->setSender($customer); $postObject->setMessage($message); $postObject->setData('invitation_link', $url); $postObject->setStoreName($store_name); $this->_sendEmailTransaction($email, $name, $template, $postObject->getData()); } else { $error[] = $email; } } if (sizeof($error)) { $err = implode("<br>", $error); $mw_error = $this->__("These emails are invalid, the invitation message will not be sent to:<br>%s", $err); header('content-type: text/javascript'); $jsondata = array("message" => 1, "email" => 1, "error" => $mw_error, "success" => 0); echo json_encode($jsondata); die; } $msg = 1; if (sizeof($emails) > 1) { $msg = 2; } //$msg = "Your Emails were sent successfully"; if (sizeof($emails) > sizeof($error)) { header('content-type: text/javascript'); $jsondata = array("message" => 1, "email" => 1, "error" => 0, "success" => $msg); echo json_encode($jsondata); die; } }