00001 <?php
00002
00016
00017
00018
00019 import('form.Form');
00020
00021 class EmailTemplateForm extends Form {
00022
00024 var $emailKey;
00025
00030 function EmailTemplateForm($emailKey) {
00031 parent::Form('manager/emails/emailTemplateForm.tpl');
00032
00033 $this->emailKey = $emailKey;
00034
00035
00036 $this->addCheck(new FormValidatorArray($this, 'subject', 'required', 'manager.emails.form.subjectRequired'));
00037 $this->addCheck(new FormValidatorArray($this, 'body', 'required', 'manager.emails.form.bodyRequired'));
00038 $this->addCheck(new FormValidatorPost($this));
00039 }
00040
00044 function display() {
00045 $templateMgr = &TemplateManager::getManager();
00046
00047 $journal = &Request::getJournal();
00048 $emailTemplateDao = &DAORegistry::getDAO('EmailTemplateDAO');
00049 $emailTemplate = &$emailTemplateDao->getBaseEmailTemplate($this->emailKey, $journal->getJournalId());
00050 $templateMgr->assign('canDisable', $emailTemplate?$emailTemplate->getCanDisable():false);
00051 $templateMgr->assign('supportedLocales', $journal->getSupportedLocaleNames());
00052 $templateMgr->assign('helpTopicId','journal.managementPages.emails');
00053 parent::display();
00054 }
00055
00059 function initData() {
00060 $journal = &Request::getJournal();
00061 $emailTemplateDao = &DAORegistry::getDAO('EmailTemplateDAO');
00062 $emailTemplate = &$emailTemplateDao->getLocaleEmailTemplate($this->emailKey, $journal->getJournalId());
00063 $thisLocale = Locale::getLocale();
00064
00065 if ($emailTemplate) {
00066 $subject = array();
00067 $body = array();
00068 $description = array();
00069 foreach ($emailTemplate->getLocales() as $locale) {
00070 $subject[$locale] = $emailTemplate->getSubject($locale);
00071 $body[$locale] = $emailTemplate->getBody($locale);
00072 $description[$locale] = $emailTemplate->getDescription($locale);
00073 }
00074
00075 if ($emailTemplate != null) {
00076 $this->_data = array(
00077 'emailId' => $emailTemplate->getEmailId(),
00078 'emailKey' => $emailTemplate->getEmailKey(),
00079 'subject' => $subject,
00080 'body' => $body,
00081 'description' => isset($description[$thisLocale])?$description[$thisLocale]:null,
00082 'enabled' => $emailTemplate->getEnabled()
00083 );
00084 }
00085 } else {
00086 $this->_data = array('isNewTemplate' => true);
00087 }
00088 }
00089
00093 function readInputData() {
00094 $this->readUserVars(array('emailId', 'subject', 'body', 'enabled', 'journalId', 'emailKey'));
00095 }
00096
00100 function execute() {
00101 $journal = &Request::getJournal();
00102
00103 $emailTemplateDao = &DAORegistry::getDAO('EmailTemplateDAO');
00104 $emailTemplate = &$emailTemplateDao->getLocaleEmailTemplate($this->emailKey, $journal->getJournalId());
00105
00106 if (!$emailTemplate) {
00107 $emailTemplate = &new LocaleEmailTemplate();
00108 $emailTemplate->setCustomTemplate(true);
00109 $emailTemplate->setCanDisable(false);
00110 $emailTemplate->setEnabled(true);
00111 $emailTemplate->setEmailKey($this->getData('emailKey'));
00112 } else {
00113 $emailTemplate->setEmailId($this->getData('emailId'));
00114 if ($emailTemplate->getCanDisable()) {
00115 $emailTemplate->setEnabled($this->getData('enabled'));
00116 }
00117
00118 }
00119
00120 $emailTemplate->setJournalId($journal->getJournalId());
00121
00122 $supportedLocales = $journal->getSupportedLocaleNames();
00123 if (!empty($supportedLocales)) {
00124 foreach ($journal->getSupportedLocaleNames() as $localeKey => $localeName) {
00125 $emailTemplate->setSubject($localeKey, $this->_data['subject'][$localeKey]);
00126 $emailTemplate->setBody($localeKey, $this->_data['body'][$localeKey]);
00127 }
00128 } else {
00129 $localeKey = Locale::getLocale();
00130 $emailTemplate->setSubject($localeKey, $this->_data['subject'][$localeKey]);
00131 $emailTemplate->setBody($localeKey, $this->_data['body'][$localeKey]);
00132 }
00133
00134 if ($emailTemplate->getEmailId() != null) {
00135 $emailTemplateDao->updateLocaleEmailTemplate($emailTemplate);
00136 } else {
00137 $emailTemplateDao->insertLocaleEmailTemplate($emailTemplate);
00138 }
00139 }
00140 }
00141
00142 ?>