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
00034
00035 class Mage_Adminhtml_Cms_BlockController extends Mage_Adminhtml_Controller_Action
00036 {
00037
00038
00039
00040
00041
00042 protected function _initAction()
00043 {
00044
00045 $this->loadLayout()
00046 ->_setActiveMenu('cms/block')
00047 ->_addBreadcrumb(Mage::helper('cms')->__('CMS'), Mage::helper('cms')->__('CMS'))
00048 ->_addBreadcrumb(Mage::helper('cms')->__('Static Blocks'), Mage::helper('cms')->__('Static Blocks'))
00049 ;
00050 return $this;
00051 }
00052
00053
00054
00055
00056 public function indexAction()
00057 {
00058 $this->_initAction()
00059 ->_addContent($this->getLayout()->createBlock('adminhtml/cms_block'))
00060 ->renderLayout();
00061 }
00062
00063
00064
00065
00066 public function newAction()
00067 {
00068
00069 $this->_forward('edit');
00070 }
00071
00072
00073
00074
00075 public function editAction()
00076 {
00077
00078 $id = $this->getRequest()->getParam('block_id');
00079 $model = Mage::getModel('cms/block');
00080
00081
00082 if ($id) {
00083 $model->load($id);
00084 if (! $model->getId()) {
00085 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('This block no longer exists'));
00086 $this->_redirect('*/*/');
00087 return;
00088 }
00089 }
00090
00091
00092 $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
00093 if (! empty($data)) {
00094 $model->setData($data);
00095 }
00096
00097
00098 Mage::register('cms_block', $model);
00099
00100
00101 $this->_initAction()
00102 ->_addBreadcrumb($id ? Mage::helper('cms')->__('Edit Block') : Mage::helper('cms')->__('New Block'), $id ? Mage::helper('cms')->__('Edit Block') : Mage::helper('cms')->__('New Block'))
00103 ->_addContent($this->getLayout()->createBlock('adminhtml/cms_block_edit')->setData('action', $this->getUrl('*/cms_block/save')))
00104 ->renderLayout();
00105 }
00106
00107
00108
00109
00110 public function saveAction()
00111 {
00112
00113 if ($data = $this->getRequest()->getPost()) {
00114
00115 $model = Mage::getModel('cms/block');
00116 $model->setData($data);
00117
00118
00119 try {
00120
00121 $model->save();
00122
00123 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('cms')->__('Block was successfully saved'));
00124
00125 Mage::getSingleton('adminhtml/session')->setFormData(false);
00126
00127
00128 if ($this->getRequest()->getParam('back')) {
00129 $this->_redirect('*/*/edit', array('block_id' => $model->getId()));
00130 return;
00131 }
00132
00133 $this->_redirect('*/*/');
00134 return;
00135
00136 } catch (Exception $e) {
00137
00138 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00139
00140 Mage::getSingleton('adminhtml/session')->setFormData($data);
00141
00142 $this->_redirect('*/*/edit', array('block_id' => $this->getRequest()->getParam('block_id')));
00143 return;
00144 }
00145 }
00146 $this->_redirect('*/*/');
00147 }
00148
00149
00150
00151
00152 public function deleteAction()
00153 {
00154
00155 if ($id = $this->getRequest()->getParam('block_id')) {
00156 $title = "";
00157 try {
00158
00159 $model = Mage::getModel('cms/block');
00160 $model->load($id);
00161 $title = $model->getTitle();
00162 $model->delete();
00163
00164 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('cms')->__('Block was successfully deleted'));
00165
00166 $this->_redirect('*/*/');
00167 return;
00168
00169 } catch (Exception $e) {
00170
00171 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00172
00173 $this->_redirect('*/*/edit', array('block_id' => $id));
00174 return;
00175 }
00176 }
00177
00178 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('Unable to find a block to delete'));
00179
00180 $this->_redirect('*/*/');
00181 }
00182
00183
00184
00185
00186
00187
00188 protected function _isAllowed()
00189 {
00190 return Mage::getSingleton('admin/session')->isAllowed('cms/block');
00191 }
00192 }