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