PageRenderTime 26ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit.php

https://bitbucket.org/kdms/sh-magento
PHP | 412 lines | 144 code | 23 blank | 245 comment | 9 complexity | fbae16d0066cfe57733ad3343403fd1a MD5 | raw file
  1. <?php
  2. /**
  3. * Magento Enterprise Edition
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Magento Enterprise Edition License
  8. * that is bundled with this package in the file LICENSE_EE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://www.magentocommerce.com/license/enterprise-edition
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Adminhtml
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://www.magentocommerce.com/license/enterprise-edition
  25. */
  26. /**
  27. * Adminhtml system template edit block
  28. *
  29. * @category Mage
  30. * @package Mage_Adminhtml
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Adminhtml_Block_System_Email_Template_Edit extends Mage_Adminhtml_Block_Widget
  34. {
  35. public function __construct()
  36. {
  37. parent::__construct();
  38. $this->setTemplate('system/email/template/edit.phtml');
  39. }
  40. protected function _prepareLayout()
  41. {
  42. $this->setChild('back_button',
  43. $this->getLayout()->createBlock('adminhtml/widget_button')
  44. ->setData(
  45. array(
  46. 'label' => Mage::helper('adminhtml')->__('Back'),
  47. 'onclick' => "window.location.href = '" . $this->getUrl('*/*') . "'",
  48. 'class' => 'back'
  49. )
  50. )
  51. );
  52. $this->setChild('reset_button',
  53. $this->getLayout()->createBlock('adminhtml/widget_button')
  54. ->setData(
  55. array(
  56. 'label' => Mage::helper('adminhtml')->__('Reset'),
  57. 'onclick' => 'window.location.href = window.location.href'
  58. )
  59. )
  60. );
  61. $this->setChild('delete_button',
  62. $this->getLayout()->createBlock('adminhtml/widget_button')
  63. ->setData(
  64. array(
  65. 'label' => Mage::helper('adminhtml')->__('Delete Template'),
  66. 'onclick' => 'templateControl.deleteTemplate();',
  67. 'class' => 'delete'
  68. )
  69. )
  70. );
  71. $this->setChild('to_plain_button',
  72. $this->getLayout()->createBlock('adminhtml/widget_button')
  73. ->setData(
  74. array(
  75. 'label' => Mage::helper('adminhtml')->__('Convert to Plain Text'),
  76. 'onclick' => 'templateControl.stripTags();',
  77. 'id' => 'convert_button'
  78. )
  79. )
  80. );
  81. $this->setChild('to_html_button',
  82. $this->getLayout()->createBlock('adminhtml/widget_button')
  83. ->setData(
  84. array(
  85. 'label' => Mage::helper('adminhtml')->__('Return Html Version'),
  86. 'onclick' => 'templateControl.unStripTags();',
  87. 'id' => 'convert_button_back',
  88. 'style' => 'display:none'
  89. )
  90. )
  91. );
  92. $this->setChild('toggle_button',
  93. $this->getLayout()->createBlock('adminhtml/widget_button')
  94. ->setData(
  95. array(
  96. 'label' => Mage::helper('adminhtml')->__('Toggle Editor'),
  97. 'onclick' => 'templateControl.toggleEditor();',
  98. 'id' => 'toggle_button'
  99. )
  100. )
  101. );
  102. $this->setChild('preview_button',
  103. $this->getLayout()->createBlock('adminhtml/widget_button')
  104. ->setData(
  105. array(
  106. 'label' => Mage::helper('adminhtml')->__('Preview Template'),
  107. 'onclick' => 'templateControl.preview();'
  108. )
  109. )
  110. );
  111. $this->setChild('save_button',
  112. $this->getLayout()->createBlock('adminhtml/widget_button')
  113. ->setData(
  114. array(
  115. 'label' => Mage::helper('adminhtml')->__('Save Template'),
  116. 'onclick' => 'templateControl.save();',
  117. 'class' => 'save'
  118. )
  119. )
  120. );
  121. $this->setChild('load_button',
  122. $this->getLayout()->createBlock('adminhtml/widget_button')
  123. ->setData(
  124. array(
  125. 'label' => Mage::helper('adminhtml')->__('Load Template'),
  126. 'onclick' => 'templateControl.load();',
  127. 'type' => 'button',
  128. 'class' => 'save'
  129. )
  130. )
  131. );
  132. $this->setChild('form',
  133. $this->getLayout()->createBlock('adminhtml/system_email_template_edit_form')
  134. );
  135. return parent::_prepareLayout();
  136. }
  137. public function getBackButtonHtml()
  138. {
  139. return $this->getChildHtml('back_button');
  140. }
  141. public function getToggleButtonHtml()
  142. {
  143. return $this->getChildHtml('toggle_button');
  144. }
  145. public function getResetButtonHtml()
  146. {
  147. return $this->getChildHtml('reset_button');
  148. }
  149. public function getToPlainButtonHtml()
  150. {
  151. return $this->getChildHtml('to_plain_button');
  152. }
  153. public function getToHtmlButtonHtml()
  154. {
  155. return $this->getChildHtml('to_html_button');
  156. }
  157. public function getSaveButtonHtml()
  158. {
  159. return $this->getChildHtml('save_button');
  160. }
  161. public function getPreviewButtonHtml()
  162. {
  163. return $this->getChildHtml('preview_button');
  164. }
  165. public function getDeleteButtonHtml()
  166. {
  167. return $this->getChildHtml('delete_button');
  168. }
  169. public function getLoadButtonHtml()
  170. {
  171. return $this->getChildHtml('load_button');
  172. }
  173. /**
  174. * Return edit flag for block
  175. *
  176. * @return boolean
  177. */
  178. public function getEditMode()
  179. {
  180. return $this->getEmailTemplate()->getId();
  181. }
  182. /**
  183. * Return header text for form
  184. *
  185. * @return string
  186. */
  187. public function getHeaderText()
  188. {
  189. if($this->getEditMode()) {
  190. return Mage::helper('adminhtml')->__('Edit Email Template');
  191. }
  192. return Mage::helper('adminhtml')->__('New Email Template');
  193. }
  194. /**
  195. * Return form block HTML
  196. *
  197. * @return string
  198. */
  199. public function getFormHtml()
  200. {
  201. return $this->getChildHtml('form');
  202. }
  203. /**
  204. * Return action url for form
  205. *
  206. * @return string
  207. */
  208. public function getSaveUrl()
  209. {
  210. return $this->getUrl('*/*/save', array('_current' => true));
  211. }
  212. /**
  213. * Return preview action url for form
  214. *
  215. * @return string
  216. */
  217. public function getPreviewUrl()
  218. {
  219. return $this->getUrl('*/*/preview');
  220. }
  221. public function isTextType()
  222. {
  223. return $this->getEmailTemplate()->isPlain();
  224. }
  225. /**
  226. * Return delete url for customer group
  227. *
  228. * @return string
  229. */
  230. public function getDeleteUrl()
  231. {
  232. return $this->getUrl('*/*/delete', array('_current' => true));
  233. }
  234. /**
  235. * Retrive email template model
  236. *
  237. * @return Mage_Core_Model_Email_Template
  238. */
  239. public function getEmailTemplate()
  240. {
  241. return Mage::registry('current_email_template');
  242. }
  243. public function getLocaleOptions()
  244. {
  245. return Mage::app()->getLocale()->getOptionLocales();
  246. }
  247. public function getTemplateOptions()
  248. {
  249. return Mage_Core_Model_Email_Template::getDefaultTemplatesAsOptionsArray();
  250. }
  251. public function getCurrentLocale()
  252. {
  253. return Mage::app()->getLocale()->getLocaleCode();
  254. }
  255. /**
  256. * Load template url
  257. *
  258. * @return string
  259. */
  260. public function getLoadUrl()
  261. {
  262. return $this->getUrl('*/*/defaultTemplate');
  263. }
  264. /**
  265. * Get paths of where current template is used as default
  266. *
  267. * @param bool $asJSON
  268. * @return string
  269. */
  270. public function getUsedDefaultForPaths($asJSON = true)
  271. {
  272. $paths = $this->getEmailTemplate()->getSystemConfigPathsWhereUsedAsDefault();
  273. $pathsParts = $this->_getSystemConfigPathsParts($paths);
  274. if($asJSON){
  275. return Mage::helper('core')->jsonEncode($pathsParts);
  276. }
  277. return $pathsParts;
  278. }
  279. /**
  280. * Get paths of where current template is currently used
  281. *
  282. * @param bool $asJSON
  283. * @return string
  284. */
  285. public function getUsedCurrentlyForPaths($asJSON = true)
  286. {
  287. $paths = $this->getEmailTemplate()->getSystemConfigPathsWhereUsedCurrently();
  288. $pathsParts = $this->_getSystemConfigPathsParts($paths);
  289. if($asJSON){
  290. return Mage::helper('core')->jsonEncode($pathsParts);
  291. }
  292. return $pathsParts;
  293. }
  294. /**
  295. * Convert xml config pathes to decorated names
  296. *
  297. * @param array $paths
  298. * @return array
  299. */
  300. protected function _getSystemConfigPathsParts($paths)
  301. {
  302. $result = $urlParams = $prefixParts = array();
  303. $scopeLabel = Mage::helper('adminhtml')->__('GLOBAL');
  304. if ($paths) {
  305. // create prefix path parts
  306. $prefixParts[] = array(
  307. 'title' => Mage::getSingleton('admin/config')->getMenuItemLabel('system'),
  308. );
  309. $prefixParts[] = array(
  310. 'title' => Mage::getSingleton('admin/config')->getMenuItemLabel('system/config'),
  311. 'url' => $this->getUrl('adminhtml/system_config/'),
  312. );
  313. $pathParts = $prefixParts;
  314. foreach ($paths as $id => $pathData) {
  315. list($sectionName, $groupName, $fieldName) = explode('/', $pathData['path']);
  316. $urlParams = array('section' => $sectionName);
  317. if (isset($pathData['scope']) && isset($pathData['scope_id'])) {
  318. switch ($pathData['scope']) {
  319. case 'stores':
  320. $store = Mage::app()->getStore($pathData['scope_id']);
  321. if ($store) {
  322. $urlParams['website'] = $store->getWebsite()->getCode();
  323. $urlParams['store'] = $store->getCode();
  324. $scopeLabel = $store->getWebsite()->getName() . '/' . $store->getName();
  325. }
  326. break;
  327. case 'websites':
  328. $website = Mage::app()->getWebsite($pathData['scope_id']);
  329. if ($website) {
  330. $urlParams['website'] = $website->getCode();
  331. $scopeLabel = $website->getName();
  332. }
  333. break;
  334. default:
  335. break;
  336. }
  337. }
  338. $pathParts[] = array(
  339. 'title' => Mage::getSingleton('adminhtml/config')->getSystemConfigNodeLabel($sectionName),
  340. 'url' => $this->getUrl('adminhtml/system_config/edit', $urlParams),
  341. );
  342. $pathParts[] = array(
  343. 'title' => Mage::getSingleton('adminhtml/config')->getSystemConfigNodeLabel($sectionName, $groupName)
  344. );
  345. $pathParts[] = array(
  346. 'title' => Mage::getSingleton('adminhtml/config')->getSystemConfigNodeLabel($sectionName, $groupName, $fieldName),
  347. 'scope' => $scopeLabel
  348. );
  349. $result[] = $pathParts;
  350. $pathParts = $prefixParts;
  351. }
  352. }
  353. return $result;
  354. }
  355. /**
  356. * Return original template code of current template
  357. *
  358. * @return string
  359. */
  360. public function getOrigTemplateCode()
  361. {
  362. return $this->getEmailTemplate()->getOrigTemplateCode();
  363. }
  364. }