00001 <?php
00002
00019
00020
00021 import('form.Form');
00022
00023 class EmailTemplateForm extends Form {
00024
00026 var $emailKey;
00027
00029 var $conference;
00030
00035 function EmailTemplateForm($emailKey, $conference) {
00036 parent::Form('director/emails/emailTemplateForm.tpl');
00037
00038 $this->conference = $conference;
00039 $this->emailKey = $emailKey;
00040
00041
00042 $this->addCheck(new FormValidatorArray($this, 'subject', 'required', 'director.emails.form.subjectRequired'));
00043 $this->addCheck(new FormValidatorArray($this, 'body', 'required', 'director.emails.form.bodyRequired'));
00044 $this->addCheck(new FormValidatorPost($this));
00045 }
00046
00050 function display() {
00051 $templateMgr =& TemplateManager::getManager();
00052
00053 $conferenceId = $this->conference->getId();
00054
00055 $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
00056 $emailTemplate =& $emailTemplateDao->getBaseEmailTemplate($this->emailKey, $conferenceId);
00057 $templateMgr->assign('canDisable', $emailTemplate?$emailTemplate->getCanDisable():false);
00058 $templateMgr->assign('supportedLocales', $this->conference->getSupportedLocaleNames());
00059 $templateMgr->assign('helpTopicId','conference.generalManagement.emails');
00060 parent::display();
00061 }
00062
00066 function initData() {
00067 $conferenceId = $this->conference->getId();
00068 $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
00069
00070 $emailTemplate =& $emailTemplateDao->getLocaleEmailTemplate($this->emailKey, $conferenceId);
00071 $thisLocale = AppLocale::getLocale();
00072
00073 if ($emailTemplate) {
00074 $subject = array();
00075 $body = array();
00076 $description = array();
00077 foreach ($emailTemplate->getLocales() as $locale) {
00078 $subject[$locale] = $emailTemplate->getSubject($locale);
00079 $body[$locale] = $emailTemplate->getBody($locale);
00080 $description[$locale] = $emailTemplate->getDescription($locale);
00081 }
00082
00083 if ($emailTemplate != null) {
00084 $this->_data = array(
00085 'emailId' => $emailTemplate->getEmailId(),
00086 'emailKey' => $emailTemplate->getEmailKey(),
00087 'subject' => $subject,
00088 'body' => $body,
00089 'description' => isset($description[$thisLocale])?$description[$thisLocale]:null,
00090 'enabled' => $emailTemplate->getEnabled()
00091 );
00092 }
00093 } else {
00094 $this->_data = array('isNewTemplate' => true);
00095 }
00096 }
00097
00101 function readInputData() {
00102 $this->readUserVars(array('emailId', 'subject', 'body', 'enabled', 'conferenceId', 'eventId', 'emailKey'));
00103 }
00104
00108 function execute() {
00109 $conferenceId = $this->conference->getId();
00110
00111 $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
00112 $emailTemplate =& $emailTemplateDao->getLocaleEmailTemplate($this->emailKey, $conferenceId);
00113
00114 if (!$emailTemplate) {
00115 $emailTemplate = new LocaleEmailTemplate();
00116 $emailTemplate->setCustomTemplate(true);
00117 $emailTemplate->setCanDisable(false);
00118 $emailTemplate->setEnabled(true);
00119 $emailTemplate->setEmailKey($this->getData('emailKey'));
00120 } else {
00121 $emailTemplate->setEmailId($this->getData('emailId'));
00122 if ($emailTemplate->getCanDisable()) {
00123 $emailTemplate->setEnabled($this->getData('enabled'));
00124 }
00125 $foo = $emailTemplate->getEmailId();
00126 }
00127
00128 $emailTemplate->setConferenceId($conferenceId);
00129 $emailTemplate->setEventId($eventId);
00130
00131 $supportedLocales = $this->conference->getSupportedLocaleNames();
00132 if (!empty($supportedLocales)) {
00133 foreach ($conference->getSupportedLocaleNames() as $localeKey => $localeName) {
00134 $emailTemplate->setSubject($localeKey, $this->_data['subject'][$localeKey]);
00135 $emailTemplate->setBody($localeKey, $this->_data['body'][$localeKey]);
00136 }
00137 } else {
00138 $localeKey = AppLocale::getLocale();
00139 $emailTemplate->setSubject($localeKey, $this->_data['subject'][$localeKey]);
00140 $emailTemplate->setBody($localeKey, $this->_data['body'][$localeKey]);
00141 }
00142
00143 if ($emailTemplate->getEmailId() != null) {
00144 $emailTemplateDao->updateLocaleEmailTemplate($emailTemplate);
00145 } else {
00146 $emailTemplateDao->insertLocaleEmailTemplate($emailTemplate);
00147 }
00148 }
00149 }
00150
00151 ?>