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: class Mage_Adminhtml_System_VariableController extends Mage_Adminhtml_Controller_Action
35: {
36: 37: 38: 39: 40:
41: protected function _initLayout()
42: {
43: $this->loadLayout()
44: ->_setActiveMenu('system/variable')
45: ->_addBreadcrumb(Mage::helper('adminhtml')->__('Custom Variables'), Mage::helper('adminhtml')->__('Custom Variables'));
46: return $this;
47: }
48:
49: 50: 51: 52: 53:
54: protected function _initVariable()
55: {
56: $this->_title($this->__('System'))->_title($this->__('Custom Variables'));
57:
58: $variableId = $this->getRequest()->getParam('variable_id', null);
59: $storeId = (int)$this->getRequest()->getParam('store', 0);
60:
61: $variable = Mage::getModel('core/variable');
62: if ($variableId) {
63: $variable->setStoreId($storeId)
64: ->load($variableId);
65: }
66: Mage::register('current_variable', $variable);
67: return $variable;
68: }
69:
70: 71: 72: 73:
74: public function indexAction()
75: {
76: $this->_title($this->__('System'))->_title($this->__('Custom Variables'));
77:
78: $this->_initLayout()
79: ->_addContent($this->getLayout()->createBlock('adminhtml/system_variable'))
80: ->renderLayout();
81: }
82:
83: 84: 85: 86:
87: public function newAction()
88: {
89: $this->_forward('edit');
90: }
91:
92: 93: 94: 95:
96: public function editAction()
97: {
98: $variable = $this->_initVariable();
99:
100: $this->_title($variable->getId() ? $variable->getCode() : $this->__('New Variable'));
101:
102: $this->_initLayout()
103: ->_addContent($this->getLayout()->createBlock('adminhtml/system_variable_edit'))
104: ->_addJs($this->getLayout()->createBlock('core/template', '', array(
105: 'template' => 'system/variable/js.phtml'
106: )))
107: ->renderLayout();
108: }
109:
110: 111: 112: 113:
114: public function validateAction()
115: {
116: $response = new Varien_Object(array('error' => false));
117: $variable = $this->_initVariable();
118: $variable->addData($this->getRequest()->getPost('variable'));
119: $result = $variable->validate();
120: if ($result !== true && is_string($result)) {
121: $this->_getSession()->addError($result);
122: $this->_initLayoutMessages('adminhtml/session');
123: $response->setError(true);
124: $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
125: }
126: $this->getResponse()->setBody($response->toJson());
127: }
128:
129: 130: 131: 132:
133: public function saveAction()
134: {
135: $variable = $this->_initVariable();
136: $data = $this->getRequest()->getPost('variable');
137: $back = $this->getRequest()->getParam('back', false);
138: if ($data) {
139: $data['variable_id'] = $variable->getId();
140: $variable->setData($data);
141: try {
142: $variable->save();
143: $this->_getSession()->addSuccess(
144: Mage::helper('adminhtml')->__('The custom variable has been saved.')
145: );
146: if ($back) {
147: $this->_redirect('*/*/edit', array('_current' => true, 'variable_id' => $variable->getId()));
148: } else {
149: $this->_redirect('*/*/', array());
150: }
151: return;
152: } catch (Exception $e) {
153: $this->_getSession()->addError($e->getMessage());
154: $this->_redirect('*/*/edit', array('_current' => true, ));
155: return;
156: }
157: }
158: $this->_redirect('*/*/', array());
159: return;
160: }
161:
162: 163: 164: 165:
166: public function deleteAction()
167: {
168: $variable = $this->_initVariable();
169: if ($variable->getId()) {
170: try {
171: $variable->delete();
172: $this->_getSession()->addSuccess(
173: Mage::helper('adminhtml')->__('The custom variable has been deleted.')
174: );
175: } catch (Exception $e) {
176: $this->_getSession()->addError($e->getMessage());
177: $this->_redirect('*/*/edit', array('_current' => true, ));
178: return;
179: }
180: }
181: $this->_redirect('*/*/', array());
182: return;
183: }
184:
185: 186: 187: 188:
189: public function wysiwygPluginAction()
190: {
191: $customVariables = Mage::getModel('core/variable')->getVariablesOptionArray(true);
192: $storeContactVariabls = Mage::getModel('core/source_email_variables')->toOptionArray(true);
193: $variables = array($storeContactVariabls, $customVariables);
194: $this->getResponse()->setBody(Zend_Json::encode($variables));
195: }
196:
197: 198: 199: 200: 201:
202: protected function _isAllowed()
203: {
204: return Mage::getSingleton('admin/session')->isAllowed('system/variable');
205: }
206: }
207: