00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Adminhtml 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * System Template admin controller 00029 * 00030 * @category Mage 00031 * @package Mage_Adminhtml 00032 * @author Magento Core Team <core@magentocommerce.com> 00033 */ 00034 class Mage_Adminhtml_System_Email_TemplateController extends Mage_Adminhtml_Controller_Action 00035 { 00036 public function indexAction() 00037 { 00038 if ($this->getRequest()->getQuery('ajax')) { 00039 $this->_forward('grid'); 00040 return; 00041 } 00042 00043 $this->loadLayout(); 00044 $this->_setActiveMenu('system/email_template'); 00045 $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Transactional Emails'), Mage::helper('adminhtml')->__('Transactional Emails')); 00046 00047 $this->_addContent($this->getLayout()->createBlock('adminhtml/system_email_template', 'template')); 00048 $this->renderLayout(); 00049 } 00050 00051 public function gridAction() 00052 { 00053 $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/system_email_template_grid')->toHtml()); 00054 } 00055 00056 00057 public function newAction() 00058 { 00059 $this->loadLayout(); 00060 $this->_setActiveMenu('system/email_template'); 00061 $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Transactional Emails'), Mage::helper('adminhtml')->__('Transactional Emails'), $this->getUrl('*/*')); 00062 00063 if ($this->getRequest()->getParam('id')) { 00064 $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Edit Template'), Mage::helper('adminhtml')->__('Edit System Template')); 00065 } else { 00066 $this->_addBreadcrumb(Mage::helper('adminhtml')->__('New Template'), Mage::helper('adminhtml')->__('New System Template')); 00067 } 00068 00069 $this->_addContent($this->getLayout()->createBlock('adminhtml/system_email_template_edit', 'template_edit') 00070 ->setEditMode((bool)$this->getRequest()->getParam('id'))); 00071 $this->renderLayout(); 00072 } 00073 00074 public function editAction() 00075 { 00076 $this->_forward('new'); 00077 } 00078 00079 public function saveAction() 00080 { 00081 $request = $this->getRequest(); 00082 $template = Mage::getModel('core/email_template'); 00083 if ($id = (int)$request->getParam('id')) { 00084 $template->load($id); 00085 } 00086 00087 try { 00088 $template->setTemplateSubject($request->getParam('template_subject')) 00089 ->setTemplateCode($request->getParam('template_code')) 00090 /* 00091 ->setTemplateSenderEmail($request->getParam('sender_email')) 00092 ->setTemplateSenderName($request->getParam('sender_name')) 00093 */ 00094 ->setTemplateText($request->getParam('template_text')) 00095 ->setModifiedAt(Mage::getSingleton('core/date')->gmtDate()); 00096 00097 if (!$template->getId()) { 00098 $type = constant(Mage::getConfig()->getModelClassName('core/email_template') . "::TYPE_HTML"); 00099 $template->setTemplateType($type); 00100 } 00101 00102 if($this->getRequest()->getParam('_change_type_flag')) { 00103 $type = constant(Mage::getConfig()->getModelClassName('core/email_template') . "::TYPE_TEXT"); 00104 $template->setTemplateType($type); 00105 } 00106 00107 $template->save(); 00108 $this->_redirect('*/*'); 00109 } 00110 catch (Exception $e) { 00111 Mage::getSingleton('adminhtml/session')->setData('email_template_form_data', $this->getRequest()->getParams()); 00112 Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 00113 $this->_forward('new'); 00114 } 00115 00116 } 00117 00118 public function deleteAction() { 00119 00120 $template = Mage::getModel('core/email_template'); 00121 $id = (int)$this->getRequest()->getParam('id'); 00122 $template->load($id); 00123 if($template->getId()) { 00124 try { 00125 $template->delete(); 00126 } 00127 catch (Exception $e) { 00128 // Nothing 00129 } 00130 } 00131 $this->_redirect('*/*'); 00132 } 00133 00134 public function previewAction() 00135 { 00136 $this->loadLayout('systemPreview'); 00137 $this->renderLayout(); 00138 } 00139 00140 public function defaultTemplateAction() 00141 { 00142 $template = Mage::getModel('core/email_template'); 00143 00144 $template->loadDefault($this->getRequest()->getParam('code'), $this->getRequest()->getParam('locale')); 00145 00146 $this->getResponse()->setBody(Zend_Json::encode($template->getData())); 00147 } 00148 00149 protected function _isAllowed() 00150 { 00151 return Mage::getSingleton('admin/session')->isAllowed('system/email_template'); 00152 } 00153 }