pages/user/UserHandler.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 // $Id$
00017 
00018 
00019 import('handler.Handler');
00020 
00021 class UserHandler extends Handler {
00025    function UserHandler() {
00026       parent::Handler();
00027    }
00028 
00032    function index() {
00033       $this->validate();
00034 
00035       $user =& Request::getUser();
00036       $userId = $user->getId();
00037       
00038       $setupIncomplete = array();
00039       $submissionsCount = array();
00040       $isValid = array();
00041       $schedConfsToDisplay = array();
00042       $conferencesToDisplay = array();
00043 
00044       $roleDao =& DAORegistry::getDAO('RoleDAO');
00045       $schedConfDao =& DAORegistry::getDAO('SchedConfDAO');
00046 
00047       $this->setupTemplate();
00048       $templateMgr =& TemplateManager::getManager();
00049 
00050       $conference =& Request::getConference();
00051       $templateMgr->assign('helpTopicId', 'user.userHome');
00052       
00053       $allConferences = $allSchedConfs = array();
00054 
00055       if ($conference == null) { // Curently at site level
00056          unset($conference);
00057 
00058          // Show roles for all conferences
00059          $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
00060          $conferences =& $conferenceDao->getConferences();
00061 
00062          // Fetch the user's roles for each conference
00063          while ($conference =& $conferences->next()) {
00064             $conferenceId = $conference->getId();
00065             $schedConfId = 0;
00066             
00067             // First, the generic roles for this conference
00068             $roles =& $roleDao->getRolesByUserId($userId, $conferenceId, 0);
00069             if (!empty($roles)) {
00070                $conferencesToDisplay[$conferenceId] =& $conference;
00071                $rolesToDisplay[$conferenceId] =& $roles;
00072             }
00073 
00074             // Determine if conference setup is incomplete, to provide a message for JM
00075             $setupIncomplete[$conferenceId] = $this->checkIncompleteSetup($conference);
00076             
00077             $this->getRoleDataForConference($userId, $conferenceId, $schedConfId, $submissionsCount, $isValid);
00078 
00079             // Second, scheduled conference-specific roles
00080             // TODO: don't display scheduled conference roles if granted at conference level too?
00081             $schedConfs =& $schedConfDao->getSchedConfsByConferenceId($conferenceId);
00082             while ($schedConf =& $schedConfs->next()) {
00083                $schedConfId = $schedConf->getId();
00084 
00085                $schedConfRoles =& $roleDao->getRolesByUserId($userId, $conferenceId, $schedConfId);
00086                if(!empty($schedConfRoles)) {
00087                   $schedConfsToDisplay[$conferenceId][$schedConfId] =& $schedConf;
00088                   $this->getRoleDataForConference($userId, $conferenceId, $schedConfId, $submissionsCount, $isValid);
00089                }
00090                $allSchedConfs[$conference->getId()][$schedConf->getId()] =& $schedConf;
00091                unset($schedConf);
00092             }
00093             
00094             // If the user has Sched. Conf. roles and no Conf. roles, push the conf. object
00095             // into the conference array so it gets shown
00096             if(empty($roles) && !empty($schedConfsToDisplay[$conferenceId])) {
00097                $conferencesToDisplay[$conferenceId] =& $conference;
00098             }
00099             
00100             $allConferences[$conference->getId()] =& $conference;
00101             unset($schedConfs);
00102             unset($conference);
00103          }
00104 
00105          $templateMgr->assign('showAllConferences', 1);
00106          $templateMgr->assign_by_ref('userConferences', $conferencesToDisplay);
00107       } else {  // Currently within a conference's context
00108          $conferenceId = $conference->getId();
00109          $userConferences = array($conference);
00110          
00111          $this->getRoleDataForConference($userId, $conferenceId, 0, $submissionsCount, $isValid);
00112 
00113          $schedConfs =& $schedConfDao->getSchedConfsByConferenceId($conferenceId);
00114          while($schedConf =& $schedConfs->next()) {
00115             $schedConfId = $schedConf->getId();
00116             $schedConfRoles =& $roleDao->getRolesByUserId($userId, $conferenceId, $schedConfId);
00117             if(!empty($schedConfRoles)) {
00118                $this->getRoleDataForConference($userId, $conferenceId, $schedConfId, $submissionsCount, $isValid);
00119                $schedConfsToDisplay[$conferenceId][$schedConfId] =& $schedConf;
00120             }
00121 
00122             unset($schedConf);
00123          }
00124 
00125          $schedConf =& Request::getSchedConf();
00126          if ($schedConf) {
00127             import('schedConf.SchedConfAction');
00128             $templateMgr->assign('allowRegAuthor', SchedConfAction::allowRegAuthor($schedConf));
00129             $templateMgr->assign('allowRegReviewer', SchedConfAction::allowRegReviewer($schedConf));
00130             $templateMgr->assign('submissionsOpen', SchedConfAction::submissionsOpen($schedConf));
00131          }
00132 
00133          $templateMgr->assign_by_ref('userConferences', $userConferences);
00134       }
00135 
00136       $templateMgr->assign('isSiteAdmin', $roleDao->getRole(0, 0, $userId, ROLE_ID_SITE_ADMIN));
00137       $templateMgr->assign('allConferences', $allConferences);
00138       $templateMgr->assign('allSchedConfs', $allSchedConfs);
00139       $templateMgr->assign('userSchedConfs', $schedConfsToDisplay);
00140       $templateMgr->assign('isValid', $isValid);
00141       $templateMgr->assign('submissionsCount', $submissionsCount);
00142       $templateMgr->assign('setupIncomplete', $setupIncomplete); 
00143       $templateMgr->display('user/index.tpl');
00144    }
00145 
00154    function getRoleDataForConference($userId, $conferenceId, $schedConfId, &$submissionsCount, &$isValid) {
00155       if (Validation::isConferenceManager($conferenceId)) {
00156          $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
00157          $isValid["ConferenceManager"][$conferenceId][$schedConfId] = true;
00158       }
00159       if (Validation::isDirector($conferenceId, $schedConfId)) {
00160          $isValid["Director"][$conferenceId][$schedConfId] = true;
00161          $directorSubmissionDao =& DAORegistry::getDAO('DirectorSubmissionDAO');
00162          $submissionsCount["Director"][$conferenceId][$schedConfId] = $directorSubmissionDao->getDirectorSubmissionsCount($schedConfId);
00163       }
00164       if (Validation::isTrackDirector($conferenceId, $schedConfId)) {
00165          $trackDirectorSubmissionDao =& DAORegistry::getDAO('TrackDirectorSubmissionDAO');
00166          $submissionsCount["TrackDirector"][$conferenceId][$schedConfId] = $trackDirectorSubmissionDao->getTrackDirectorSubmissionsCount($userId, $schedConfId);
00167          $isValid["TrackDirector"][$conferenceId][$schedConfId] = true;
00168       }
00169       if (Validation::isReviewer($conferenceId, $schedConfId)) {
00170          $reviewerSubmissionDao =& DAORegistry::getDAO('ReviewerSubmissionDAO');
00171          $submissionsCount["Reviewer"][$conferenceId][$schedConfId] = $reviewerSubmissionDao->getSubmissionsCount($userId, $schedConfId);
00172          $isValid["Reviewer"][$conferenceId][$schedConfId] = true;
00173       } 
00174       if (Validation::isAuthor($conferenceId, $schedConfId)) {
00175          $authorSubmissionDao =& DAORegistry::getDAO('AuthorSubmissionDAO');
00176          $submissionsCount["Author"][$conferenceId][$schedConfId] = $authorSubmissionDao->getSubmissionsCount($userId, $schedConfId);
00177          $isValid["Author"][$conferenceId][$schedConfId] = true;
00178       }
00179    }
00180    
00186    function checkIncompleteSetup($conference) {
00187       if (
00188          $conference->getSetting('contactEmail') == '' ||  
00189          $conference->getSetting('contactName') == ''
00190       ) return true;
00191       return false;
00192    }
00193 
00198    function setLocale($args) {
00199       $setLocale = isset($args[0]) ? $args[0] : null;
00200 
00201       $site =& Request::getSite();
00202       $conference =& Request::getConference();
00203       if ($conference != null) {
00204          $conferenceSupportedLocales = $conference->getSetting('supportedLocales');
00205          if (!is_array($conferenceSupportedLocales)) {
00206             $conferenceSupportedLocales = array();
00207          }
00208       }
00209 
00210       if (AppLocale::isLocaleValid($setLocale) && (!isset($conferenceSupportedLocales) || in_array($setLocale, $conferenceSupportedLocales)) && in_array($setLocale, $site->getSupportedLocales())) {
00211          $session =& Request::getSession();
00212          $session->setSessionVar('currentLocale', $setLocale);
00213       }
00214 
00215       if(isset($_SERVER['HTTP_REFERER'])) {
00216          Request::redirectUrl($_SERVER['HTTP_REFERER']);
00217       }
00218 
00219       $source = Request::getUserVar('source');
00220       if (isset($source) && !empty($source)) {
00221          Request::redirectUrl(Request::getProtocol() . '://' . Request::getServerHost() . $source, false);
00222       }
00223 
00224       Request::redirect(null, null, 'index');
00225    }
00226 
00230    function become($args) {
00231       $this->addCheck(new HandlerValidatorConference($this));
00232       $this->addCheck(new HandlerValidatorSchedConf($this));
00233       $this->validate();
00234       $schedConf =& Request::getSchedConf();
00235       
00236       import('schedConf.SchedConfAction');
00237       $user =& Request::getUser();
00238       if (!$user) Request::redirect(null, null, 'index');
00239 
00240       $schedConfAction = new SchedConfAction();
00241 
00242       switch (array_shift($args)) {
00243          case 'author':
00244             $roleId = ROLE_ID_AUTHOR;
00245             $func = 'allowRegAuthor';
00246             $deniedKey = 'author.submit.authorRegistrationClosed';
00247             break;
00248          case 'reviewer':
00249             $roleId = ROLE_ID_REVIEWER;
00250             $func = 'allowRegReviewer';
00251             $deniedKey = 'user.noRoles.regReviewerClosed';
00252             break;
00253          default:
00254             Request::redirect(null, null, 'index');
00255       }
00256 
00257       if ($schedConfAction->$func($schedConf)) {
00258          $role = new Role();
00259          $role->setSchedConfId($schedConf->getId());
00260          $role->setConferenceId($schedConf->getConferenceId());
00261          $role->setRoleId($roleId);
00262          $role->setUserId($user->getId());
00263 
00264          $roleDao =& DAORegistry::getDAO('RoleDAO');
00265          $roleDao->insertRole($role);
00266          Request::redirectUrl(Request::getUserVar('source'));
00267       } else {
00268          $templateMgr =& TemplateManager::getManager();
00269          $templateMgr->assign('message', $deniedKey);
00270          return $templateMgr->display('common/message.tpl');
00271       }
00272    }
00273 
00279    function validate($loginCheck = true) {
00280       parent::validate();
00281 
00282       if ($loginCheck && !Validation::isLoggedIn()) {
00283          Validation::redirectLogin();
00284       }
00285 
00286       return true;
00287    }
00288 
00293    function setupTemplate($subclass = false) {
00294       parent::setupTemplate();
00295       AppLocale::requireComponents(array(LOCALE_COMPONENT_OCS_AUTHOR, LOCALE_COMPONENT_OCS_DIRECTOR, LOCALE_COMPONENT_OCS_MANAGER));
00296 
00297       $conference =& Request::getConference();
00298       $schedConf =& Request::getSchedConf();
00299       $templateMgr =& TemplateManager::getManager();
00300 
00301       $pageHierarchy = array();
00302 
00303       if ($schedConf) {
00304          $pageHierarchy[] = array(Request::url(null, null, 'index'), $schedConf->getFullTitle(), true);
00305       } elseif ($conference) {
00306          $pageHierarchy[] = array(Request::url(null, 'index', 'index'), $conference->getConferenceTitle(), true);
00307       }
00308 
00309       if ($subclass) {
00310          $pageHierarchy[] = array(Request::url(null, null, 'user'), 'navigation.user');
00311       }
00312 
00313       $templateMgr->assign('pageHierarchy', $pageHierarchy);
00314    }
00315 
00316    //
00317    // Captcha
00318    //
00319 
00320    function viewCaptcha($args) {
00321       $captchaId = (int) array_shift($args);
00322       import('captcha.CaptchaManager');
00323       $captchaManager = new CaptchaManager();
00324       if ($captchaManager->isEnabled()) {
00325          $captchaDao =& DAORegistry::getDAO('CaptchaDAO');
00326          $captcha =& $captchaDao->getCaptcha($captchaId);
00327          if ($captcha) {
00328             $captchaManager->generateImage($captcha);
00329             exit();
00330          }
00331       }
00332       Request::redirect(null, null, 'user');
00333    }
00334 }
00335 
00336 ?>

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