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_Form extends Mage_Adminhtml_Block_Widget_Form
36: {
37: 38: 39: 40: 41: 42:
43: protected function _prepareLayout()
44: {
45: if ($head = $this->getLayout()->getBlock('head')) {
46: $head->addItem('js', 'prototype/window.js')
47: ->addItem('js_css', 'prototype/windows/themes/default.css')
48: ->addCss('lib/prototype/windows/themes/magento.css')
49: ->addItem('js', 'mage/adminhtml/variables.js');
50: }
51: return parent::_prepareLayout();
52: }
53:
54: 55: 56: 57: 58:
59: protected function _prepareForm()
60: {
61: $form = new Varien_Data_Form();
62:
63: $fieldset = $form->addFieldset('base_fieldset', array(
64: 'legend' => Mage::helper('adminhtml')->__('Template Information'),
65: 'class' => 'fieldset-wide'
66: ));
67:
68: $templateId = $this->getEmailTemplate()->getId();
69: if ($templateId) {
70: $fieldset->addField('used_currently_for', 'label', array(
71: 'label' => Mage::helper('adminhtml')->__('Used Currently For'),
72: 'container_id' => 'used_currently_for',
73: 'after_element_html' =>
74: '<script type="text/javascript">' .
75: (!$this->getEmailTemplate()->getSystemConfigPathsWhereUsedCurrently()
76: ? '$(\'' . 'used_currently_for' . '\').hide(); ' : '') .
77: '</script>',
78: ));
79: }
80:
81: if (!$templateId) {
82: $fieldset->addField('used_default_for', 'label', array(
83: 'label' => Mage::helper('adminhtml')->__('Used as Default For'),
84: 'container_id' => 'used_default_for',
85: 'after_element_html' =>
86: '<script type="text/javascript">' .
87: (!(bool)$this->getEmailTemplate()->getOrigTemplateCode()
88: ? '$(\'' . 'used_default_for' . '\').hide(); ' : '') .
89: '</script>',
90: ));
91: }
92:
93: $fieldset->addField('template_code', 'text', array(
94: 'name'=>'template_code',
95: 'label' => Mage::helper('adminhtml')->__('Template Name'),
96: 'required' => true
97:
98: ));
99:
100: $fieldset->addField('template_subject', 'text', array(
101: 'name'=>'template_subject',
102: 'label' => Mage::helper('adminhtml')->__('Template Subject'),
103: 'required' => true
104: ));
105:
106: $fieldset->addField('orig_template_variables', 'hidden', array(
107: 'name' => 'orig_template_variables',
108: ));
109:
110: $fieldset->addField('variables', 'hidden', array(
111: 'name' => 'variables',
112: 'value' => Zend_Json::encode($this->getVariables())
113: ));
114:
115: $fieldset->addField('template_variables', 'hidden', array(
116: 'name' => 'template_variables',
117: ));
118:
119: $insertVariableButton = $this->getLayout()
120: ->createBlock('adminhtml/widget_button', '', array(
121: 'type' => 'button',
122: 'label' => Mage::helper('adminhtml')->__('Insert Variable...'),
123: 'onclick' => 'templateControl.openVariableChooser();return false;'
124: ));
125:
126: $fieldset->addField('insert_variable', 'note', array(
127: 'text' => $insertVariableButton->toHtml()
128: ));
129:
130: $fieldset->addField('template_text', 'textarea', array(
131: 'name'=>'template_text',
132: 'label' => Mage::helper('adminhtml')->__('Template Content'),
133: 'title' => Mage::helper('adminhtml')->__('Template Content'),
134: 'required' => true,
135: 'style' => 'height:24em;',
136: ));
137:
138: if (!$this->getEmailTemplate()->isPlain()) {
139: $fieldset->addField('template_styles', 'textarea', array(
140: 'name'=>'template_styles',
141: 'label' => Mage::helper('adminhtml')->__('Template Styles'),
142: 'container_id' => 'field_template_styles'
143: ));
144: }
145:
146: if ($templateId) {
147: $form->addValues($this->getEmailTemplate()->getData());
148: }
149:
150: if ($values = Mage::getSingleton('adminhtml/session')->getData('email_template_form_data', true)) {
151: $form->setValues($values);
152: }
153:
154: $this->setForm($form);
155:
156: return parent::_prepareForm();
157: }
158:
159: 160: 161: 162: 163:
164: public function getEmailTemplate()
165: {
166: return Mage::registry('current_email_template');
167: }
168:
169: 170: 171: 172: 173:
174: public function getVariables()
175: {
176: $variables = array();
177: $variables[] = Mage::getModel('core/source_email_variables')
178: ->toOptionArray(true);
179: $customVariables = Mage::getModel('core/variable')
180: ->getVariablesOptionArray(true);
181: if ($customVariables) {
182: $variables[] = $customVariables;
183: }
184:
185: $template = Mage::registry('current_email_template');
186: if ($template->getId() && $templateVariables = $template->getVariablesOptionArray(true)) {
187: $variables[] = $templateVariables;
188: }
189: return $variables;
190: }
191: }
192: