pages/user/EmailHandler.inc.php

00001 <?php
00002 
00015 //$Id$
00016 
00017 import('pages.user.UserHandler');
00018 
00019 class EmailHandler extends UserHandler {
00023    function EmailHandler() {
00024       parent::UserHandler();
00025    }
00026    function email($args) {
00027       $this->validate();
00028       $this->setupTemplate(true);
00029       
00030       $conference =& Request::getConference();
00031       $schedConf =& Request::getSchedConf();
00032       
00033       $templateMgr =& TemplateManager::getManager();
00034 
00035       $userDao =& DAORegistry::getDAO('UserDAO');
00036       $user =& Request::getUser();
00037 
00038       // See if this is the Director or Manager and an email template has been chosen
00039       $template = Request::getUserVar('template');
00040       if (  !$conference || empty($template) || (
00041          !Validation::isConferenceManager() &&
00042          !Validation::isDirector() &&
00043          !Validation::isTrackDirector())) {
00044          $template = null;
00045       }
00046 
00047       // Determine whether or not this account is subject to
00048       // email sending restrictions.
00049       $canSendUnlimitedEmails = Validation::isSiteAdmin();
00050       $unlimitedEmailRoles = array(
00051          ROLE_ID_CONFERENCE_MANAGER,
00052          ROLE_ID_DIRECTOR,
00053          ROLE_ID_TRACK_DIRECTOR
00054       );
00055       $roleDao =& DAORegistry::getDAO('RoleDAO');
00056       if ($conference) {
00057          $roles =& $roleDao->getRolesByUserId($user->getId(), $conference->getId());
00058          foreach ($roles as $role) {
00059             if (in_array($role->getRoleId(), $unlimitedEmailRoles)) $canSendUnlimitedEmails = true;
00060          }
00061       }
00062 
00063       // Check when this user last sent an email, and if it's too
00064       // recent, make them wait.
00065       if (!$canSendUnlimitedEmails) {
00066          $dateLastEmail = $user->getDateLastEmail();
00067          if ($dateLastEmail && strtotime($dateLastEmail) + ((int) Config::getVar('email', 'time_between_emails')) > strtotime(Core::getCurrentDate())) {
00068             $templateMgr->assign('pageTitle', 'email.compose');
00069             $templateMgr->assign('message', 'email.compose.tooSoon');
00070             $templateMgr->assign('backLink', 'javascript:history.back()');
00071             $templateMgr->assign('backLinkLabel', 'email.compose');
00072             return $templateMgr->display('common/message.tpl');
00073          }
00074       }
00075 
00076       $email = null;
00077       if ($paperId = Request::getUserVar('paperId')) {
00078          // This message is in reference to a paper.
00079          // Determine whether the current user has access
00080          // to the paper in some form, and if so, use an
00081          // PaperMailTemplate.
00082          $paperDao =& DAORegistry::getDAO('PaperDAO');
00083 
00084          $paper =& $paperDao->getPaper($paperId);
00085          $hasAccess = false;
00086 
00087          // First, conditions where access is OK.
00088          // 1. User is submitter
00089          if ($paper && $paper->getUserId() == $user->getId()) $hasAccess = true;
00090          // 2. User is director
00091          $editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
00092          $editAssignments =& $editAssignmentDao->getEditAssignmentsByPaperId($paperId);
00093          while ($editAssignment =& $editAssignments->next()) {
00094             if ($editAssignment->getDirectorId() === $user->getId()) $hasAccess = true;
00095          }
00096          if (Validation::isDirector()) $hasAccess = true;
00097          // 3. User is reviewer
00098          $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
00099          foreach ($reviewAssignmentDao->getReviewAssignmentsByPaperId($paperId) as $reviewAssignment) {
00100             if ($reviewAssignment->getReviewerId() === $user->getId()) $hasAccess = true;
00101          }
00102 
00103          // Last, "deal-breakers" -- access is not allowed.
00104          if ($paper && $paper->getSchedConfId() !== $schedConf->getId()) $hasAccess = false;
00105 
00106          if ($hasAccess) {
00107             import('mail.PaperMailTemplate');
00108             $email = new PaperMailTemplate($paperDao->getPaper($paperId));
00109          }
00110       }
00111 
00112       if ($email === null) {
00113          import('mail.MailTemplate');
00114          $email = new MailTemplate();
00115       }
00116 
00117       if (Request::getUserVar('send') && !$email->hasErrors()) {
00118          $recipients = $email->getRecipients();
00119          $ccs = $email->getCcs();
00120          $bccs = $email->getBccs();
00121 
00122          // Make sure there aren't too many recipients (to
00123          // prevent use as a spam relay)
00124          $recipientCount = 0;
00125          if (is_array($recipients)) $recipientCount += count($recipients);
00126          if (is_array($ccs)) $recipientCount += count($ccs);
00127          if (is_array($bccs)) $recipientCount += count($bccs);
00128 
00129          if (!$canSendUnlimitedEmails && $recipientCount > ((int) Config::getVar('email', 'max_recipients'))) {
00130             $templateMgr->assign('pageTitle', 'email.compose');
00131             $templateMgr->assign('message', 'email.compose.tooManyRecipients');
00132             $templateMgr->assign('backLink', 'javascript:history.back()');
00133             $templateMgr->assign('backLinkLabel', 'email.compose');
00134             return $templateMgr->display('common/message.tpl');
00135          }
00136 
00137          $email->send();
00138          $redirectUrl = Request::getUserVar('redirectUrl');
00139          if (empty($redirectUrl)) $redirectUrl = Request::url(null, null, 'user');
00140          $user->setDateLastEmail(Core::getCurrentDate());
00141          $userDao->updateObject($user);
00142          Request::redirectUrl($redirectUrl);
00143       } else {
00144          $email->displayEditForm(Request::url(null, null, null, 'email'), array('redirectUrl' => Request::getUserVar('redirectUrl'), 'paperId' => $paperId), null, array('disableSkipButton' => true));
00145       }
00146    }
00147 }
00148 
00149 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7