00001 <?php
00002
00016 import('mail.PKPMailTemplate');
00017
00018 class MailTemplate extends PKPMailTemplate {
00020 var $conference;
00021
00032 function MailTemplate($emailKey = null, $locale = null, $enableAttachments = null, $conference = null, $schedConf = null, $includeSignature = true, $ignorePostedData = false) {
00033 parent::PKPMailTemplate($emailKey, $locale, $enableAttachments, $includeSignature);
00034
00035
00036 if ($conference === null) $conference =& Request::getConference();
00037 if ($schedConf == null) $schedConf =& Request::getSchedConf();
00038
00039 if (isset($this->emailKey)) {
00040 $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
00041 $emailTemplate =& $emailTemplateDao->getEmailTemplate($this->emailKey, $this->locale, $conference == null ? 0 : $conference->getId());
00042 }
00043
00044 $userSig = '';
00045 $user =& Request::getUser();
00046 if ($user && $includeSignature) {
00047 $userSig = $user->getLocalizedSignature();
00048 if (!empty($userSig)) $userSig = "\n" . $userSig;
00049 }
00050
00051 if (isset($emailTemplate) && ($ignorePostedData || (Request::getUserVar('subject')==null && Request::getUserVar('body')==null))) {
00052 $this->setSubject($emailTemplate->getSubject());
00053 $this->setBody($emailTemplate->getBody() . $userSig);
00054 $this->enabled = $emailTemplate->getEnabled();
00055
00056 if (Request::getUserVar('usePostedAddresses')) {
00057 $to = Request::getUserVar('to');
00058 if (is_array($to)) {
00059 $this->setRecipients($this->processAddresses ($this->getRecipients(), $to));
00060 }
00061 $cc = Request::getUserVar('cc');
00062 if (is_array($cc)) {
00063 $this->setCcs($this->processAddresses ($this->getCcs(), $cc));
00064 }
00065 $bcc = Request::getUserVar('bcc');
00066 if (is_array($bcc)) {
00067 $this->setBccs($this->processAddresses ($this->getBccs(), $bcc));
00068 }
00069 }
00070 } else {
00071 $this->setSubject(Request::getUserVar('subject'));
00072 $body = Request::getUserVar('body');
00073 if (empty($body)) $this->setBody($userSig);
00074 else $this->setBody($body);
00075 $this->skip = (($tmp = Request::getUserVar('send')) && is_array($tmp) && isset($tmp['skip']));
00076 $this->enabled = true;
00077
00078 if (is_array($toEmails = Request::getUserVar('to'))) {
00079 $this->setRecipients($this->processAddresses ($this->getRecipients(), $toEmails));
00080 }
00081 if (is_array($ccEmails = Request::getUserVar('cc'))) {
00082 $this->setCcs($this->processAddresses ($this->getCcs(), $ccEmails));
00083 }
00084 if (is_array($bccEmails = Request::getUserVar('bcc'))) {
00085 $this->setBccs($this->processAddresses ($this->getBccs(), $bccEmails));
00086 }
00087 }
00088
00089
00090 $user =& Request::getUser();
00091 if ($user) {
00092 $this->setFrom($user->getEmail(), $user->getFullName());
00093 } elseif ($schedConf) {
00094 $this->setFrom($schedConf->getSetting('contactEmail'), $schedConf->getSetting('contactName'));
00095 } elseif ($conference) {
00096 $this->setFrom($conference->getSetting('contactEmail'), $conference->getSetting('contactName'));
00097 } else {
00098 $site =& Request::getSite();
00099 $this->setFrom($site->getLocalizedContactEmail(), $site->getLocalizedContactName());
00100 }
00101
00102 if ($schedConf && !Request::getUserVar('continued')) {
00103 $this->setSubject('[' . $schedConf->getLocalizedSetting('acronym') . '] ' . $this->getSubject());
00104 }
00105
00106 $this->conference =& $conference;
00107 }
00108
00114 function assignParams($paramArray = array()) {
00115
00116 $conference =& Request::getConference();
00117 $schedConf =& Request::getSchedConf();
00118
00119 if ($schedConf) {
00120 $paramArray['principalContactSignature'] = $schedConf->getSetting('contactName');
00121 } elseif ($conference) {
00122 $paramArray['principalContactSignature'] = $conference->getSetting('contactName');
00123 } else {
00124 $site =& Request::getSite();
00125 $paramArray['principalContactSignature'] = $site->getLocalizedContactName();
00126 }
00127
00128 if (isset($conference)) {
00129
00130 $paramArray['conferenceName'] = $conference->getConferenceTitle();
00131 }
00132 if (!isset($paramArray['conferenceUrl'])) $paramArray['conferenceUrl'] = Request::url(Request::getRequestedConferencePath(), Request::getRequestedSchedConfPath());
00133
00134 return parent::assignParams($paramArray);
00135 }
00136
00143 function displayEditForm($formActionUrl, $hiddenFormParams = null, $alternateTemplate = null, $additionalParameters = array()) {
00144 $templateMgr =& TemplateManager::getManager();
00145 $templateMgr->assign('helpTopicId', 'conference.generalManagement.emails');
00146
00147 parent::displayEditForm($formActionUrl, $hiddenFormParams, $alternateTemplate, $additionalParameters);
00148 }
00149
00156 function send($clearAttachments = true) {
00157 $schedConf =& Request::getSchedConf();
00158
00159 if($schedConf) {
00160 $envelopeSender = $schedConf->getSetting('envelopeSender');
00161 $emailSignature = $schedConf->getLocalizedSetting('emailSignature');
00162 }
00163
00164 if (isset($emailSignature)) {
00165
00166
00167
00168
00169
00170 $searchString = '{$templateSignature}';
00171 if (strstr($this->getBody(), $searchString) === false) {
00172 $this->setBody($this->getBody() . "\n" . $emailSignature);
00173 } else {
00174 $this->setBody(str_replace($searchString, $emailSignature, $this->getBody()));
00175 }
00176
00177 if (!empty($envelopeSender) && Config::getVar('email', 'allow_envelope_sender')) $this->setEnvelopeSender($envelopeSender);
00178 }
00179
00180 return parent::send($clearAttachments);
00181 }
00182 }
00183
00184 ?>