00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 class Mage_Adminhtml_Newsletter_TemplateController extends Mage_Adminhtml_Controller_Action
00034 {
00035
00036
00037
00038
00039 public function indexAction ()
00040 {
00041 if ($this->getRequest()->getQuery('ajax')) {
00042 $this->_forward('grid');
00043 return;
00044 }
00045 $this->loadLayout();
00046 $this->_setActiveMenu('newsletter/template');
00047 $this->_addBreadcrumb(Mage::helper('newsletter')->__('Newsletter Templates'), Mage::helper('newsletter')->__('Newsletter Templates'));
00048 $this->_addContent($this->getLayout()->createBlock('adminhtml/newsletter_template', 'template'));
00049 $this->renderLayout();
00050 }
00051
00052
00053
00054
00055
00056 public function gridAction ()
00057 {
00058 $this->loadLayout();
00059 $grid = $this->getLayout()->createBlock('adminhtml/newsletter_template_grid')
00060 ->toHtml();
00061 $this->getResponse()->setBody($grid);
00062 }
00063
00064
00065
00066
00067
00068 public function newAction ()
00069 {
00070 $this->_forward('edit');
00071 }
00072
00073
00074
00075
00076
00077 public function editAction ()
00078 {
00079 $model = Mage::getModel('newsletter/template');
00080 if ($id = $this->getRequest()->getParam('id')) {
00081 $model->load($id);
00082 }
00083
00084 Mage::register('_current_template', $model);
00085
00086 $this->loadLayout();
00087 $this->_setActiveMenu('newsletter/template');
00088
00089 if ($model->getId()) {
00090 $breadcrumbTitle = Mage::helper('newsletter')->__('Edit Template');
00091 $breadcrumbLabel = $breadcrumbTitle;
00092 }
00093 else {
00094 $breadcrumbTitle = Mage::helper('newsletter')->__('New Template');
00095 $breadcrumbLabel = Mage::helper('newsletter')->__('Create Newsletter Template');
00096 }
00097
00098 $this->_addBreadcrumb($breadcrumbLabel, $breadcrumbTitle);
00099
00100
00101 if ($values = $this->_getSession()->getData('newsletter_template_form_data', true)) {
00102 $model->addData($values);
00103 }
00104
00105 $content = $this->getLayout()
00106 ->createBlock('adminhtml/newsletter_template_edit', 'template_edit')
00107 ->setEditMode($model->getId() > 0);
00108 $this->_addContent($content);
00109 $this->renderLayout();
00110 }
00111
00112
00113
00114
00115
00116 public function saveAction ()
00117 {
00118 $request = $this->getRequest();
00119 $template = Mage::getModel('newsletter/template');
00120
00121 if ($id = (int)$request->getParam('id')) {
00122 $template->load($id);
00123 }
00124
00125 try {
00126 $template->addData($request->getParams())
00127 ->setTemplateSubject($request->getParam('subject'))
00128 ->setTemplateCode($request->getParam('code'))
00129 ->setTemplateSenderEmail($request->getParam('sender_email'))
00130 ->setTemplateSenderName($request->getParam('sender_name'))
00131 ->setTemplateText($request->getParam('text'))
00132 ->setModifiedAt(Mage::getSingleton('core/date')->gmtDate());
00133
00134 if (!$template->getId()) {
00135 $template->setTemplateType(Mage_Newsletter_Model_Template::TYPE_HTML);
00136 }
00137 if ($this->getRequest()->getParam('_change_type_flag')) {
00138 $template->setTemplateType(Mage_Newsletter_Model_Template::TYPE_TEXT);
00139 }
00140 if ($this->getRequest()->getParam('_save_as_flag')) {
00141 $template->setId(null);
00142 }
00143 $template->save();
00144 $this->_redirect('*/*');
00145 }
00146 catch (Mage_Core_Exception $e) {
00147 $this->_getSession()->addError(nl2br($e->getMessage()));
00148 $this->_getSession()->setData('newsletter_template_form_data',
00149 $this->getRequest()->getParams());
00150 }
00151 catch (Exception $e) {
00152 $this->_getSession()->addException($e, Mage::helper('adminhtml')->__('Error while saving this template. Please try again later.'));
00153 $this->_getSession()->setData('newsletter_template_form_data', $this->getRequest()->getParams());
00154 }
00155 $this->_forward('new');
00156 }
00157
00158
00159
00160
00161
00162 public function deleteAction ()
00163 {
00164 $template = Mage::getModel('newsletter/template')
00165 ->load($this->getRequest()->getParam('id'));
00166 if ($template->getId()) {
00167 try {
00168 $template->delete();
00169 }
00170 catch (Mage_Core_Exception $e) {
00171 $this->_getSession()->addError($e->getMessage());
00172 }
00173 catch (Exception $e) {
00174 $this->_getSession()->addException($e, Mage::helper('adminhtml')->__('Error while deleting this template. Please try again later.'));
00175 }
00176 }
00177 $this->_redirect('*/*');
00178 }
00179
00180
00181
00182
00183
00184 public function previewAction ()
00185 {
00186 $this->loadLayout('preview');
00187 $this->renderLayout();
00188 }
00189
00190
00191
00192
00193
00194 public function toqueueAction ()
00195 {
00196 $template = Mage::getModel('newsletter/template')
00197 ->load($this->getRequest()->getParam('id'));
00198 if (!$template->getIsSystem()) {
00199 $template->preprocess();
00200 $queue = Mage::getModel('newsletter/queue')
00201 ->setTemplateId($template->getId())
00202 ->setQueueStatus(Mage_Newsletter_Model_Queue::STATUS_NEVER)
00203 ->save();
00204 $template->save();
00205 $this->_redirect('*/newsletter_queue/edit', array('id' => $queue->getId()));
00206 }
00207 else {
00208 $this->_redirect('*/*');
00209 }
00210 }
00211
00212
00213
00214
00215
00216
00217 protected function _isAllowed ()
00218 {
00219 return Mage::getSingleton('admin/session')
00220 ->isAllowed('newsletter/template');
00221 }
00222 }