Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @ This file is created by deZender.Net
- * @ deZender (PHP5 Decoder for ionCube Loader)
- *
- * @ Version : 2.0.0.3
- * @ Author : DeZender
- * @ Release on : 06.05.2013
- * @ Official site : http://DeZender.Net
- *
- */
- class Ophirah_Crmaddon_Adminhtml_CrmaddonController extends Mage_Adminhtml_Controller_Action {
- const XML_PATH_CRMADDON_EMAIL_TEMPLATE = "qquoteadv_sales_representatives_messaging_crmaddon_container";
- const CHECKBOX_ENABLED = "on";
- public function getRequired($option = null) {
- $return = array();
- $return["sendMail"] = array("crm_subject" => "subject", "crm_message" => "message");
- return $return[$option];
- }
- public function crmmessageAction() {
- $crmData = $this->getCrmdata();
- $quote_id = $crmData["crm_id"];
- Mage::dispatchEvent("ophirah_crmaddon_crmmessage_before", array($crmData));
- $required = $this->getRequired("sendMail");
- foreach ($crmData as $key => $value) {
- if (!($value == null || $value == "")) {
- continue;
- }
- if (!(array_key_exists($key, $required))) {
- continue;
- }
- $message = $this->__("Datafield %s is empty", $required[$key]);
- Mage::getSingleton("adminhtml/session")->addError($message);
- }
- $returnPath = $this->getBaseReturnPath($quote_id, $crmData) . "/crmaddon/1";
- if (!Mage::helper("qquoteadv/license")->validLicense("CRMaddon", $crmData["createHash"])) {
- $errorMsg = Ophirah_Crmaddon_Helper_Data::CRMADDON_UPGRADE_MESSAGE;
- $errorLink = Ophirah_Crmaddon_Helper_Data::CRMADDON_UPGRADE_LINK;
- Mage::getSingleton("adminhtml/session")->addError(__($errorMsg, $errorLink));
- $this->_redirect($returnPath);
- return null;
- }
- if (!(isset($errorMsg)) && !(isset($message))) {
- try {
- $sendMail = $this->sendEmail($crmData);
- if (empty($sendMail)) {
- $message = $this->__("CRM message couldn't be sent to the client");
- Mage::getSingleton("adminhtml/session")->addError($message);
- }
- }
- catch (Exception $e) {
- $message = $this->__("CRM message couldn't be sent to the client");
- Mage::log("Exception: " . $e->getMessage(), null, "c2q_exception.log", true);
- Mage::getSingleton("adminhtml/session")->addError($message);
- }
- }
- $this->_redirect($returnPath);
- Mage::dispatchEvent("ophirah_crmaddon_crmmessage_after", array($crmData));
- }
- public function getCrmdata() {
- $return["createHash"] = null;
- foreach ($this->getRequest()->getPost() as $key => $value) {
- if (substr($key, 0, 4) == "crm_" || $key == "createHash") {
- $return[$key] = $value;
- }
- if (!($key == "crm_notifyCustomer" && $value == self::CHECKBOX_ENABLED)) {
- continue;
- }
- $return[$key] = 1;
- }
- return $return;
- }
- public function sendEmail($crmData) {
- $vars = array();
- $storeId = $crmData["crm_storeId"];
- $vars["crmaddonBody"] = $crmData["crm_message"];
- $vars["message"] = $crmData["crm_message"];
- $saveData = $this->prepareSaveData($crmData);
- if (!(isset($saveData["customer_notified"]))) {
- $res = true;
- }
- else {
- if ($saveData["customer_notified"] == 1) {
- $template = Mage::helper("crmaddon")->getEmailTemplateModel();
- $default_template = Mage::getStoreConfig("qquoteadv_sales_representatives/messaging/crmaddon_container", $storeId);
- $disabledEmail = Ophirah_Crmaddon_Model_System_Config_Source_Email_Templatedisable::VALUE_DISABLED_EMAIL;
- if ($default_template != $disabledEmail) {
- $res = $this->sendEmailWithTemplate($crmData, $default_template, $storeId, $template, $vars, $saveData);
- }
- }
- }
- $qquote = Mage::getModel("qquoteadv/qqadvcustomer")->load($saveData["quote_id"]);
- $saveData["customer_id"] = (int)$qquote->getCustomerId();
- $saveData["user_id"] = (int)$qquote->getUserId();
- Mage::getModel("crmaddon/crmaddonmessages")->setData($saveData)->save();
- return $res;
- }
- public function loadtemplateAction() {
- $crmData = $this->getCrmdata();
- Mage::dispatchEvent("ophirah_crmaddon_loadtemplate_before", array($crmData));
- $msgtemplate = $crmData["crm_message_template"];
- $quote_id = $crmData["crm_id"];
- Mage::helper("crmaddon")->checkLicense(null, $crmData["createHash"]);
- $returnPath = $this->getBaseReturnPath($quote_id, $crmData) . "/crmtmpl/" . $msgtemplate;
- $this->_redirect($returnPath);
- Mage::dispatchEvent("ophirah_crmaddon_loadtemplate_after", array($crmData));
- }
- public function loadcrmtemplateAction() {
- $crmData = $this->getCrmdata();
- Mage::dispatchEvent("ophirah_crmaddon_loadcrmtemplate_before", array($crmData));
- $bodytemplate = $crmData["crm_bodyId"];
- $quote_id = $crmData["crm_id"];
- Mage::helper("crmaddon")->checkLicense(null, $crmData["createHash"]);
- $returnPath = $this->getBaseReturnPath($quote_id, $crmData) . "/crmbodytmpl/" . $bodytemplate;
- $this->_redirect($returnPath);
- Mage::dispatchEvent("ophirah_crmaddon_loadcrmtemplate_after", array($crmData));
- }
- public function savecrmtemplateAction() {
- $crmData = $this->getCrmdata();
- $quote_id = $crmData["crm_id"];
- $bodyTmplId = $crmData["crm_bodytemplateid"];
- Mage::dispatchEvent("ophirah_crmaddon_savecrmtemplate_before", array($crmData));
- Mage::helper("crmaddon")->checkLicense(null, $crmData["createHash"]);
- if (!(isset($crmData["crm_templatedefault"]))) {
- $crmData["crm_templatedefault"] = 0;
- }
- if ((int)$crmData["crm_templatedefault"] == 1) {
- $this->resetDefault();
- }
- $returnPath = $this->getBaseReturnPath($quote_id, $crmData) . "/crmbodytmpl/" . $bodyTmplId;
- $template = Mage::getModel("crmaddon/crmaddontemplates")->load($bodyTmplId);
- $saveData = $this->prepareSavetemplateData($crmData);
- $template->setData($saveData);
- $this->saveTemplate($template, $returnPath);
- Mage::dispatchEvent("ophirah_crmaddon_savecrmtemplate_after", array($crmData));
- }
- public function newcrmtemplateAction() {
- $crmData = $this->getCrmdata();
- $quote_id = $crmData["crm_id"];
- $bodyTmplId = $crmData["crm_bodytemplateid"];
- Mage::dispatchEvent("ophirah_crmaddon_newcrmtemplate_before", array($crmData));
- Mage::helper("crmaddon")->checkLicense(null, $crmData["createHash"]);
- if (!(isset($crmData["crm_templatedefault"]))) {
- $crmData["crm_templatedefault"] = 0;
- }
- if ((int)$crmData["crm_templatedefault"] == 1) {
- $this->resetDefault();
- }
- $returnPath = $this->getBaseReturnPath($quote_id, $crmData);
- $templateNames = Mage::helper("crmaddon")->getTemplates();
- foreach ($templateNames as $templateName) {
- if (!(trim($crmData["crm_templatename"]) == trim($templateName["name"]))) {
- continue;
- }
- $message = Mage::helper("crmaddon")->__("CRM template name allready exists");
- }
- if (isset($message)) {
- Mage::getSingleton("adminhtml/session")->addError($message);
- $this->_redirect($returnPath);
- }
- else {
- $saveData = $this->prepareSavetemplateData($crmData);
- unset($saveData["template_id"]);
- $save = Mage::getModel("crmaddon/crmaddontemplates")->setData($saveData);
- $this->saveTemplate($save, $returnPath, true);
- }
- Mage::dispatchEvent("ophirah_crmaddon_newcrmtemplate_after", array($crmData));
- }
- public function deletecrmtemplateAction() {
- $crmData = $this->getCrmdata();
- $quote_id = $crmData["crm_id"];
- ..........................................................................
- ........................................
- .............
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement