/**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @return \MUtil_Model_ModelAbstract
  */
 protected function createModel($detailed, $action)
 {
     // Make sure the user is loaded
     $user = $this->getSelectedUser();
     if ($user) {
         if (!($this->currentUser->hasPrivilege('pr.staff.see.all') || $this->currentUser->isAllowedOrganization($user->getBaseOrganizationId()))) {
             throw new \Gems_Exception($this->_('No access to page'), 403, null, sprintf($this->_('You have no right to access users from the organization %s.'), $user->getBaseOrganization()->getName()));
         }
     }
     return parent::createModel($detailed, $action);
 }
 /**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @return \MUtil_Model_ModelAbstract
  */
 public function createModel($detailed, $action)
 {
     $defaultOrgId = null;
     if ($detailed) {
         // Make sure the user is loaded
         $user = $this->getSelectedUser();
         if ($user) {
             if (!($this->currentUser->hasPrivilege('pr.staff.see.all') || $this->currentUser->isAllowedOrganization($user->getBaseOrganizationId()))) {
                 throw new \Gems_Exception($this->_('No access to page'), 403, null, sprintf($this->_('You have no right to access users from the organization %s.'), $user->getBaseOrganization()->getName()));
             }
             switch ($action) {
                 case 'create':
                 case 'show':
                 case 'mail':
                     break;
                 default:
                     if (!$user->hasAllowedRole()) {
                         throw new \Gems_Exception($this->_('No access to page'), 403, null, sprintf($this->_('As %s user you have no right to access users with the role %s.'), $this->currentUser->getRole(), $user->getRole()));
                     }
             }
             $defaultOrgId = $user->getBaseOrganizationId();
         }
     }
     // \MUtil_Model::$verbose = true;
     $model = $this->loader->getModels()->getStaffModel(!('deactivate' === $action || 'reactivate' === $action));
     $model->applySettings($detailed, $action, $defaultOrgId);
     return $model;
 }
 /**
  * Add a staff browse edit page to the menu,
  *
  * @param string $label
  * @param array $other
  * @return \Gems_Menu_SubMenuItem
  */
 public function addStaffPage($label, array $other = array())
 {
     if ($this->user->hasPrivilege('pr.staff.edit.all')) {
         $filter = array_keys($this->escort->getUtil()->getDbLookup()->getOrganizations());
     } else {
         $filter = array_keys($this->user->getAllowedOrganizations());
     }
     $page = $this->addPage($label, 'pr.staff', 'staff', 'index', $other);
     $page->addAutofilterAction();
     $createPage = $page->addCreateAction();
     $showPage = $page->addShowAction();
     $pages[] = $showPage->addEditAction();
     $pages[] = $showPage->addAction($this->_('Reset password'), 'pr.staff.edit', 'reset')->setModelParameters(1)->addParameterFilter('gsf_active', 1);
     $showPage->addAction($this->_('Send Mail'), 'pr.staff.edit', 'mail')->setModelParameters(1)->addParameterFilter('can_mail', 1, 'gsf_active', 1, 'gsf_id_organization', $filter);
     $pages = $pages + $showPage->addDeReactivateAction('gsf_active', 1, 0);
     // LOG CONTROLLER
     $logPage = $showPage->addPage($this->_('Activity overview'), 'pr.staff-log', 'staff-log', 'index')->setModelParameters(1)->addParameterFilter('gsf_id_organization', $filter);
     $logPage->addAutofilterAction();
     $logPage->addShowAction()->setModelParameters(1)->addNamedParameters('log', 'gla_id');
     $page->addExportAction();
     $page->addImportAction();
     if (!$this->user->hasPrivilege('pr.staff.edit.all')) {
         foreach ($pages as $sub_page) {
             $sub_page->addParameterFilter('gsf_id_organization', $filter, 'accessible_role', 1);
         }
     }
     return $page;
 }
 /**
  * Overrule default index for the case that the current
  * organization cannot have users.
  */
 public function indexAction()
 {
     if ($this->currentUser->hasPrivilege('pr.respondent.multiorg') || $this->currentOrganization->canHaveRespondents()) {
         parent::indexAction();
     } else {
         $this->addSnippet('Organization\\ChooseOrganizationSnippet');
     }
 }
 /**
  * Bulk email action
  */
 public function emailAction()
 {
     $model = $this->getModel();
     $model->setFilter($this->getSearchFilter(false));
     $sort = array('grs_email' => SORT_ASC, 'grs_first_name' => SORT_ASC, 'grs_surname_prefix' => SORT_ASC, 'grs_last_name' => SORT_ASC, 'gto_valid_from' => SORT_ASC, 'gto_round_order' => SORT_ASC, 'gsu_survey_name' => SORT_ASC);
     if ($tokensData = $model->load(true, $sort)) {
         $params['mailTarget'] = 'token';
         $params['menu'] = $this->menu;
         $params['model'] = $model;
         $params['identifier'] = $this->_getIdParam();
         $params['view'] = $this->view;
         $params['routeAction'] = array($this->getRequest()->getActionName() => 'index');
         $params['formTitle'] = sprintf($this->_('Send mail to: %s'), $this->getTopic());
         $params['templateOnly'] = !$this->currentUser->hasPrivilege('pr.token.mail.freetext');
         $params['multipleTokenData'] = $tokensData;
         $this->addSnippet('Mail_TokenBulkMailFormSnippet', $params);
     } else {
         $this->addMessage($this->_('No tokens found.'));
     }
 }
 /**
  *
  * @return boolean
  */
 protected function isTemplateOnly()
 {
     return !$this->currentUser->hasPrivilege('pr.token.mail.freetext');
 }