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_Block_System_Email_Template_Edit extends Mage_Adminhtml_Block_Widget
36: {
37:
38:
39: public function __construct()
40: {
41: parent::__construct();
42: $this->setTemplate('system/email/template/edit.phtml');
43: }
44:
45: protected function _prepareLayout()
46: {
47: $this->setChild('back_button',
48: $this->getLayout()->createBlock('adminhtml/widget_button')
49: ->setData(
50: array(
51: 'label' => Mage::helper('adminhtml')->__('Back'),
52: 'onclick' => "window.location.href = '" . $this->getUrl('*/*') . "'",
53: 'class' => 'back'
54: )
55: )
56: );
57:
58:
59: $this->setChild('reset_button',
60: $this->getLayout()->createBlock('adminhtml/widget_button')
61: ->setData(
62: array(
63: 'label' => Mage::helper('adminhtml')->__('Reset'),
64: 'onclick' => 'window.location.href = window.location.href'
65: )
66: )
67: );
68:
69:
70: $this->setChild('delete_button',
71: $this->getLayout()->createBlock('adminhtml/widget_button')
72: ->setData(
73: array(
74: 'label' => Mage::helper('adminhtml')->__('Delete Template'),
75: 'onclick' => 'templateControl.deleteTemplate();',
76: 'class' => 'delete'
77: )
78: )
79: );
80:
81: $this->setChild('to_plain_button',
82: $this->getLayout()->createBlock('adminhtml/widget_button')
83: ->setData(
84: array(
85: 'label' => Mage::helper('adminhtml')->__('Convert to Plain Text'),
86: 'onclick' => 'templateControl.stripTags();',
87: 'id' => 'convert_button'
88: )
89: )
90: );
91:
92:
93: $this->setChild('to_html_button',
94: $this->getLayout()->createBlock('adminhtml/widget_button')
95: ->setData(
96: array(
97: 'label' => Mage::helper('adminhtml')->__('Return Html Version'),
98: 'onclick' => 'templateControl.unStripTags();',
99: 'id' => 'convert_button_back',
100: 'style' => 'display:none'
101: )
102: )
103: );
104:
105: $this->setChild('toggle_button',
106: $this->getLayout()->createBlock('adminhtml/widget_button')
107: ->setData(
108: array(
109: 'label' => Mage::helper('adminhtml')->__('Toggle Editor'),
110: 'onclick' => 'templateControl.toggleEditor();',
111: 'id' => 'toggle_button'
112: )
113: )
114: );
115:
116:
117: $this->setChild('preview_button',
118: $this->getLayout()->createBlock('adminhtml/widget_button')
119: ->setData(
120: array(
121: 'label' => Mage::helper('adminhtml')->__('Preview Template'),
122: 'onclick' => 'templateControl.preview();'
123: )
124: )
125: );
126:
127: $this->setChild('save_button',
128: $this->getLayout()->createBlock('adminhtml/widget_button')
129: ->setData(
130: array(
131: 'label' => Mage::helper('adminhtml')->__('Save Template'),
132: 'onclick' => 'templateControl.save();',
133: 'class' => 'save'
134: )
135: )
136: );
137:
138: $this->setChild('load_button',
139: $this->getLayout()->createBlock('adminhtml/widget_button')
140: ->setData(
141: array(
142: 'label' => Mage::helper('adminhtml')->__('Load Template'),
143: 'onclick' => 'templateControl.load();',
144: 'type' => 'button',
145: 'class' => 'save'
146: )
147: )
148: );
149:
150:
151: $this->setChild('form',
152: $this->getLayout()->createBlock('adminhtml/system_email_template_edit_form')
153: );
154: return parent::_prepareLayout();
155: }
156:
157: public function getBackButtonHtml()
158: {
159: return $this->getChildHtml('back_button');
160: }
161:
162: public function getToggleButtonHtml()
163: {
164: return $this->getChildHtml('toggle_button');
165: }
166:
167:
168: public function getResetButtonHtml()
169: {
170: return $this->getChildHtml('reset_button');
171: }
172:
173: public function getToPlainButtonHtml()
174: {
175: return $this->getChildHtml('to_plain_button');
176: }
177:
178: public function getToHtmlButtonHtml()
179: {
180: return $this->getChildHtml('to_html_button');
181: }
182:
183: public function getSaveButtonHtml()
184: {
185: return $this->getChildHtml('save_button');
186: }
187:
188: public function getPreviewButtonHtml()
189: {
190: return $this->getChildHtml('preview_button');
191: }
192:
193: public function getDeleteButtonHtml()
194: {
195: return $this->getChildHtml('delete_button');
196: }
197:
198: public function getLoadButtonHtml()
199: {
200: return $this->getChildHtml('load_button');
201: }
202:
203: 204: 205: 206: 207:
208: public function getEditMode()
209: {
210: return $this->getEmailTemplate()->getId();
211: }
212:
213: 214: 215: 216: 217:
218: public function ()
219: {
220: if($this->getEditMode()) {
221: return Mage::helper('adminhtml')->__('Edit Email Template');
222: }
223:
224: return Mage::helper('adminhtml')->__('New Email Template');
225: }
226:
227:
228: 229: 230: 231: 232:
233: public function getFormHtml()
234: {
235: return $this->getChildHtml('form');
236: }
237:
238: 239: 240: 241: 242:
243: public function getSaveUrl()
244: {
245: return $this->getUrl('*/*/save', array('_current' => true));
246: }
247:
248: 249: 250: 251: 252:
253: public function getPreviewUrl()
254: {
255: return $this->getUrl('*/*/preview');
256: }
257:
258: public function isTextType()
259: {
260: return $this->getEmailTemplate()->isPlain();
261: }
262:
263: 264: 265: 266: 267:
268: public function getDeleteUrl()
269: {
270: return $this->getUrl('*/*/delete', array('_current' => true));
271: }
272:
273: 274: 275: 276: 277:
278: public function getEmailTemplate()
279: {
280: return Mage::registry('current_email_template');
281: }
282:
283: public function getLocaleOptions()
284: {
285: return Mage::app()->getLocale()->getOptionLocales();
286: }
287:
288: public function getTemplateOptions()
289: {
290: return Mage_Core_Model_Email_Template::getDefaultTemplatesAsOptionsArray();
291: }
292:
293: public function getCurrentLocale()
294: {
295: return Mage::app()->getLocale()->getLocaleCode();
296: }
297:
298: 299: 300: 301: 302:
303: public function getLoadUrl()
304: {
305: return $this->getUrl('*/*/defaultTemplate');
306: }
307:
308: 309: 310: 311: 312: 313:
314: public function getUsedDefaultForPaths($asJSON = true)
315: {
316: $paths = $this->getEmailTemplate()->getSystemConfigPathsWhereUsedAsDefault();
317: $pathsParts = $this->_getSystemConfigPathsParts($paths);
318: if($asJSON){
319: return Mage::helper('core')->jsonEncode($pathsParts);
320: }
321: return $pathsParts;
322: }
323:
324: 325: 326: 327: 328: 329:
330: public function getUsedCurrentlyForPaths($asJSON = true)
331: {
332: $paths = $this->getEmailTemplate()->getSystemConfigPathsWhereUsedCurrently();
333: $pathsParts = $this->_getSystemConfigPathsParts($paths);
334: if($asJSON){
335: return Mage::helper('core')->jsonEncode($pathsParts);
336: }
337: return $pathsParts;
338: }
339:
340: 341: 342: 343: 344: 345:
346: protected function _getSystemConfigPathsParts($paths)
347: {
348: $result = $urlParams = $prefixParts = array();
349: $scopeLabel = Mage::helper('adminhtml')->__('GLOBAL');
350: if ($paths) {
351:
352: $prefixParts[] = array(
353: 'title' => Mage::getSingleton('admin/config')->getMenuItemLabel('system'),
354: );
355: $prefixParts[] = array(
356: 'title' => Mage::getSingleton('admin/config')->getMenuItemLabel('system/config'),
357: 'url' => $this->getUrl('adminhtml/system_config/'),
358: );
359:
360: $pathParts = $prefixParts;
361: foreach ($paths as $id => $pathData) {
362: list($sectionName, $groupName, $fieldName) = explode('/', $pathData['path']);
363: $urlParams = array('section' => $sectionName);
364: if (isset($pathData['scope']) && isset($pathData['scope_id'])) {
365: switch ($pathData['scope']) {
366: case 'stores':
367: $store = Mage::app()->getStore($pathData['scope_id']);
368: if ($store) {
369: $urlParams['website'] = $store->getWebsite()->getCode();
370: $urlParams['store'] = $store->getCode();
371: $scopeLabel = $store->getWebsite()->getName() . '/' . $store->getName();
372: }
373: break;
374: case 'websites':
375: $website = Mage::app()->getWebsite($pathData['scope_id']);
376: if ($website) {
377: $urlParams['website'] = $website->getCode();
378: $scopeLabel = $website->getName();
379: }
380: break;
381: default:
382: break;
383: }
384: }
385: $pathParts[] = array(
386: 'title' => Mage::getSingleton('adminhtml/config')->getSystemConfigNodeLabel($sectionName),
387: 'url' => $this->getUrl('adminhtml/system_config/edit', $urlParams),
388: );
389: $pathParts[] = array(
390: 'title' => Mage::getSingleton('adminhtml/config')->getSystemConfigNodeLabel($sectionName, $groupName)
391: );
392: $pathParts[] = array(
393: 'title' => Mage::getSingleton('adminhtml/config')->getSystemConfigNodeLabel($sectionName, $groupName, $fieldName),
394: 'scope' => $scopeLabel
395: );
396: $result[] = $pathParts;
397: $pathParts = $prefixParts;
398: }
399: }
400: return $result;
401: }
402:
403: 404: 405: 406: 407:
408: public function getOrigTemplateCode()
409: {
410: return $this->getEmailTemplate()->getOrigTemplateCode();
411: }
412: }
413: