Advertisement
Guest User

Untitled

a guest
Aug 6th, 2015
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.26 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by deZender.Net
  5. * @ deZender (PHP5 Decoder for ionCube Loader)
  6. *
  7. * @ Version : 2.0.0.3
  8. * @ Author : DeZender
  9. * @ Release on : 06.05.2013
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. class Ophirah_Crmaddon_Adminhtml_CrmaddonController extends Mage_Adminhtml_Controller_Action {
  15.  
  16. const XML_PATH_CRMADDON_EMAIL_TEMPLATE = "qquoteadv_sales_representatives_messaging_crmaddon_container";
  17.  
  18. const CHECKBOX_ENABLED = "on";
  19.  
  20.  
  21. public function getRequired($option = null) {
  22. $return = array();
  23. $return["sendMail"] = array("crm_subject" => "subject", "crm_message" => "message");
  24. return $return[$option];
  25. }
  26.  
  27.  
  28. public function crmmessageAction() {
  29. $crmData = $this->getCrmdata();
  30. $quote_id = $crmData["crm_id"];
  31. Mage::dispatchEvent("ophirah_crmaddon_crmmessage_before", array($crmData));
  32. $required = $this->getRequired("sendMail");
  33. foreach ($crmData as $key => $value) {
  34. if (!($value == null || $value == "")) {
  35. continue;
  36. }
  37. if (!(array_key_exists($key, $required))) {
  38. continue;
  39. }
  40. $message = $this->__("Datafield %s is empty", $required[$key]);
  41. Mage::getSingleton("adminhtml/session")->addError($message);
  42. }
  43. $returnPath = $this->getBaseReturnPath($quote_id, $crmData) . "/crmaddon/1";
  44. if (!Mage::helper("qquoteadv/license")->validLicense("CRMaddon", $crmData["createHash"])) {
  45. $errorMsg = Ophirah_Crmaddon_Helper_Data::CRMADDON_UPGRADE_MESSAGE;
  46. $errorLink = Ophirah_Crmaddon_Helper_Data::CRMADDON_UPGRADE_LINK;
  47. Mage::getSingleton("adminhtml/session")->addError(__($errorMsg, $errorLink));
  48. $this->_redirect($returnPath);
  49. return null;
  50. }
  51. if (!(isset($errorMsg)) && !(isset($message))) {
  52. try {
  53. $sendMail = $this->sendEmail($crmData);
  54. if (empty($sendMail)) {
  55. $message = $this->__("CRM message couldn't be sent to the client");
  56. Mage::getSingleton("adminhtml/session")->addError($message);
  57. }
  58. }
  59. catch (Exception $e) {
  60. $message = $this->__("CRM message couldn't be sent to the client");
  61. Mage::log("Exception: " . $e->getMessage(), null, "c2q_exception.log", true);
  62. Mage::getSingleton("adminhtml/session")->addError($message);
  63. }
  64. }
  65. $this->_redirect($returnPath);
  66. Mage::dispatchEvent("ophirah_crmaddon_crmmessage_after", array($crmData));
  67. }
  68.  
  69.  
  70. public function getCrmdata() {
  71. $return["createHash"] = null;
  72. foreach ($this->getRequest()->getPost() as $key => $value) {
  73. if (substr($key, 0, 4) == "crm_" || $key == "createHash") {
  74. $return[$key] = $value;
  75. }
  76. if (!($key == "crm_notifyCustomer" && $value == self::CHECKBOX_ENABLED)) {
  77. continue;
  78. }
  79. $return[$key] = 1;
  80. }
  81. return $return;
  82. }
  83.  
  84.  
  85. public function sendEmail($crmData) {
  86. $vars = array();
  87. $storeId = $crmData["crm_storeId"];
  88. $vars["crmaddonBody"] = $crmData["crm_message"];
  89. $vars["message"] = $crmData["crm_message"];
  90. $saveData = $this->prepareSaveData($crmData);
  91. if (!(isset($saveData["customer_notified"]))) {
  92. $res = true;
  93. }
  94. else {
  95. if ($saveData["customer_notified"] == 1) {
  96. $template = Mage::helper("crmaddon")->getEmailTemplateModel();
  97. $default_template = Mage::getStoreConfig("qquoteadv_sales_representatives/messaging/crmaddon_container", $storeId);
  98. $disabledEmail = Ophirah_Crmaddon_Model_System_Config_Source_Email_Templatedisable::VALUE_DISABLED_EMAIL;
  99. if ($default_template != $disabledEmail) {
  100. $res = $this->sendEmailWithTemplate($crmData, $default_template, $storeId, $template, $vars, $saveData);
  101. }
  102. }
  103. }
  104. $qquote = Mage::getModel("qquoteadv/qqadvcustomer")->load($saveData["quote_id"]);
  105. $saveData["customer_id"] = (int)$qquote->getCustomerId();
  106. $saveData["user_id"] = (int)$qquote->getUserId();
  107. Mage::getModel("crmaddon/crmaddonmessages")->setData($saveData)->save();
  108. return $res;
  109. }
  110.  
  111.  
  112. public function loadtemplateAction() {
  113. $crmData = $this->getCrmdata();
  114. Mage::dispatchEvent("ophirah_crmaddon_loadtemplate_before", array($crmData));
  115. $msgtemplate = $crmData["crm_message_template"];
  116. $quote_id = $crmData["crm_id"];
  117. Mage::helper("crmaddon")->checkLicense(null, $crmData["createHash"]);
  118. $returnPath = $this->getBaseReturnPath($quote_id, $crmData) . "/crmtmpl/" . $msgtemplate;
  119. $this->_redirect($returnPath);
  120. Mage::dispatchEvent("ophirah_crmaddon_loadtemplate_after", array($crmData));
  121. }
  122.  
  123.  
  124. public function loadcrmtemplateAction() {
  125. $crmData = $this->getCrmdata();
  126. Mage::dispatchEvent("ophirah_crmaddon_loadcrmtemplate_before", array($crmData));
  127. $bodytemplate = $crmData["crm_bodyId"];
  128. $quote_id = $crmData["crm_id"];
  129. Mage::helper("crmaddon")->checkLicense(null, $crmData["createHash"]);
  130. $returnPath = $this->getBaseReturnPath($quote_id, $crmData) . "/crmbodytmpl/" . $bodytemplate;
  131. $this->_redirect($returnPath);
  132. Mage::dispatchEvent("ophirah_crmaddon_loadcrmtemplate_after", array($crmData));
  133. }
  134.  
  135.  
  136. public function savecrmtemplateAction() {
  137. $crmData = $this->getCrmdata();
  138. $quote_id = $crmData["crm_id"];
  139. $bodyTmplId = $crmData["crm_bodytemplateid"];
  140. Mage::dispatchEvent("ophirah_crmaddon_savecrmtemplate_before", array($crmData));
  141. Mage::helper("crmaddon")->checkLicense(null, $crmData["createHash"]);
  142. if (!(isset($crmData["crm_templatedefault"]))) {
  143. $crmData["crm_templatedefault"] = 0;
  144. }
  145. if ((int)$crmData["crm_templatedefault"] == 1) {
  146. $this->resetDefault();
  147. }
  148. $returnPath = $this->getBaseReturnPath($quote_id, $crmData) . "/crmbodytmpl/" . $bodyTmplId;
  149. $template = Mage::getModel("crmaddon/crmaddontemplates")->load($bodyTmplId);
  150. $saveData = $this->prepareSavetemplateData($crmData);
  151. $template->setData($saveData);
  152. $this->saveTemplate($template, $returnPath);
  153. Mage::dispatchEvent("ophirah_crmaddon_savecrmtemplate_after", array($crmData));
  154. }
  155.  
  156.  
  157. public function newcrmtemplateAction() {
  158. $crmData = $this->getCrmdata();
  159. $quote_id = $crmData["crm_id"];
  160. $bodyTmplId = $crmData["crm_bodytemplateid"];
  161. Mage::dispatchEvent("ophirah_crmaddon_newcrmtemplate_before", array($crmData));
  162. Mage::helper("crmaddon")->checkLicense(null, $crmData["createHash"]);
  163. if (!(isset($crmData["crm_templatedefault"]))) {
  164. $crmData["crm_templatedefault"] = 0;
  165. }
  166. if ((int)$crmData["crm_templatedefault"] == 1) {
  167. $this->resetDefault();
  168. }
  169. $returnPath = $this->getBaseReturnPath($quote_id, $crmData);
  170. $templateNames = Mage::helper("crmaddon")->getTemplates();
  171. foreach ($templateNames as $templateName) {
  172. if (!(trim($crmData["crm_templatename"]) == trim($templateName["name"]))) {
  173. continue;
  174. }
  175. $message = Mage::helper("crmaddon")->__("CRM template name allready exists");
  176. }
  177. if (isset($message)) {
  178. Mage::getSingleton("adminhtml/session")->addError($message);
  179. $this->_redirect($returnPath);
  180. }
  181. else {
  182. $saveData = $this->prepareSavetemplateData($crmData);
  183. unset($saveData["template_id"]);
  184. $save = Mage::getModel("crmaddon/crmaddontemplates")->setData($saveData);
  185. $this->saveTemplate($save, $returnPath, true);
  186. }
  187. Mage::dispatchEvent("ophirah_crmaddon_newcrmtemplate_after", array($crmData));
  188. }
  189.  
  190.  
  191. public function deletecrmtemplateAction() {
  192. $crmData = $this->getCrmdata();
  193. $quote_id = $crmData["crm_id"];
  194. ..........................................................................
  195. ........................................
  196. .............
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement