1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Adminhtml_Cms_BlockController extends Mage_Adminhtml_Controller_Action
36: {
37: 38: 39: 40: 41:
42: protected function _initAction()
43: {
44:
45: $this->loadLayout()
46: ->_setActiveMenu('cms/block')
47: ->_addBreadcrumb(Mage::helper('cms')->__('CMS'), Mage::helper('cms')->__('CMS'))
48: ->_addBreadcrumb(Mage::helper('cms')->__('Static Blocks'), Mage::helper('cms')->__('Static Blocks'))
49: ;
50: return $this;
51: }
52:
53: 54: 55:
56: public function indexAction()
57: {
58: $this->_title($this->__('CMS'))->_title($this->__('Static Blocks'));
59:
60: $this->_initAction();
61: $this->renderLayout();
62: }
63:
64: 65: 66:
67: public function newAction()
68: {
69:
70: $this->_forward('edit');
71: }
72:
73: 74: 75:
76: public function editAction()
77: {
78: $this->_title($this->__('CMS'))->_title($this->__('Static Blocks'));
79:
80:
81: $id = $this->getRequest()->getParam('block_id');
82: $model = Mage::getModel('cms/block');
83:
84:
85: if ($id) {
86: $model->load($id);
87: if (! $model->getId()) {
88: Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('This block no longer exists.'));
89: $this->_redirect('*/*/');
90: return;
91: }
92: }
93:
94: $this->_title($model->getId() ? $model->getTitle() : $this->__('New Block'));
95:
96:
97: $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
98: if (! empty($data)) {
99: $model->setData($data);
100: }
101:
102:
103: Mage::register('cms_block', $model);
104:
105:
106: $this->_initAction()
107: ->_addBreadcrumb($id ? Mage::helper('cms')->__('Edit Block') : Mage::helper('cms')->__('New Block'), $id ? Mage::helper('cms')->__('Edit Block') : Mage::helper('cms')->__('New Block'))
108: ->renderLayout();
109: }
110:
111: 112: 113:
114: public function saveAction()
115: {
116:
117: if ($data = $this->getRequest()->getPost()) {
118:
119: $id = $this->getRequest()->getParam('block_id');
120: $model = Mage::getModel('cms/block')->load($id);
121: if (!$model->getId() && $id) {
122: Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('This block no longer exists.'));
123: $this->_redirect('*/*/');
124: return;
125: }
126:
127:
128:
129: $model->setData($data);
130:
131:
132: try {
133:
134: $model->save();
135:
136: Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('cms')->__('The block has been saved.'));
137:
138: Mage::getSingleton('adminhtml/session')->setFormData(false);
139:
140:
141: if ($this->getRequest()->getParam('back')) {
142: $this->_redirect('*/*/edit', array('block_id' => $model->getId()));
143: return;
144: }
145:
146: $this->_redirect('*/*/');
147: return;
148:
149: } catch (Exception $e) {
150:
151: Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
152:
153: Mage::getSingleton('adminhtml/session')->setFormData($data);
154:
155: $this->_redirect('*/*/edit', array('block_id' => $this->getRequest()->getParam('block_id')));
156: return;
157: }
158: }
159: $this->_redirect('*/*/');
160: }
161:
162: 163: 164:
165: public function deleteAction()
166: {
167:
168: if ($id = $this->getRequest()->getParam('block_id')) {
169: $title = "";
170: try {
171:
172: $model = Mage::getModel('cms/block');
173: $model->load($id);
174: $title = $model->getTitle();
175: $model->delete();
176:
177: Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('cms')->__('The block has been deleted.'));
178:
179: $this->_redirect('*/*/');
180: return;
181:
182: } catch (Exception $e) {
183:
184: Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
185:
186: $this->_redirect('*/*/edit', array('block_id' => $id));
187: return;
188: }
189: }
190:
191: Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('Unable to find a block to delete.'));
192:
193: $this->_redirect('*/*/');
194: }
195:
196: 197: 198: 199: 200:
201: protected function _isAllowed()
202: {
203: return Mage::getSingleton('admin/session')->isAllowed('cms/block');
204: }
205: }
206: