public function afterRegistry()
 {
     $this->user = $this->loader->getUserLoader()->getUserByStaffId($this->staffId);
     parent::afterRegistry();
     $this->user = $this->loader->getUserLoader()->getUserByStaffId($this->staffId);
     $mailFields = $this->user->getMailFields();
     $this->addMailFields($mailFields);
     $this->addTo($this->user->getEmailAddress(), $this->user->getFullName());
     $this->setLanguage($this->user->getLocale());
 }
 /**
  * Create the options for the Select
  */
 protected function createFromSelect($elementName = 'from', $label = '')
 {
     $valid = array();
     $invalid = array();
     $organization = $this->mailer->getOrganization();
     // The organization
     $key = 'organization';
     if ($name = $organization->getContactName()) {
         $extra = $organization->getName();
     } else {
         $name = $organization->getName();
         $extra = null;
     }
     if ($email = $organization->getEmail()) {
         $title = false;
         $valid[] = $key;
     } else {
         $title = $this->_('Organization does not have an e-mail address.');
         $invalid[] = $key;
     }
     $options[$key] = $this->createMultiOption(array(\MUtil_Model::REQUEST_ID => $organization->getId()), $name, $email, $extra, $title, array('controller' => 'organization', 'action' => 'edit'));
     $this->fromOptions[$key] = $email;
     //$name . ' <' . $email . '>';
     // The user
     $key = 'user';
     $name = $this->currentUser->getFullName();
     $extra = null;
     if ($email = $this->currentUser->getEmailAddress()) {
         $title = false;
         $valid[] = $key;
     } else {
         $title = $this->_('You do not have an e-mail address.');
         $invalid[] = $key;
     }
     $options[$key] = $this->createMultiOption(array(), $name, $email, $extra, $title, array('controller' => 'option', 'action' => 'edit'));
     $this->fromOptions[$key] = $email;
     //$name . ' <' . $email . '>';
     // As "the" application
     $key = 'application';
     $user = $this->loader->getCurrentUser();
     if ($user->hasPrivilege('pr.plan.mail-as-application') && isset($this->project->email['site'])) {
         if ($email = $this->project->email['site']) {
             $options['application'] = $this->createMultiOption(array(), $this->project->name, $email);
             $valid[] = 'application';
             $this->fromOptions[$key] = $email;
             //$this->project->name . ' <' . $email . '>';
         }
     }
     $firstSelectable = reset($valid);
     $element = $this->form->createElement('radio', $elementName, array('disable' => $invalid, 'escape' => !$this->view, 'label' => $label, 'multiOptions' => $options, 'required' => true, 'value' => $firstSelectable));
     $element->addValidator('InArray', false, array('haystack' => $valid));
     return $element;
 }
 /**
  * Return a password reset key
  *
  * @param \Gems_User_User $user The user to create a key for.
  * @return string
  */
 public function getPasswordResetKey(\Gems_User_User $user)
 {
     $model = new \MUtil_Model_TableModel('gems__staff');
     \Gems_Model::setChangeFieldsByPrefix($model, 'gsf', $user->getUserId());
     $data['gsf_id_user'] = $user->getUserId();
     $row = $model->loadFirst($data + array('DATE_ADD(gsf_reset_req, INTERVAL ' . $this->hoursResetKeyIsValid . ' HOUR) >= CURRENT_TIMESTAMP'));
     if ($row && $row['gup_reset_key']) {
         // Keep using the key.
         $data['gsf_reset_key'] = $row['gsf_reset_key'];
     } else {
         $data['gsf_reset_key'] = $this->hashPassword(time() . $user->getEmailAddress());
     }
     $data['gsf_reset_req'] = new \MUtil_Db_Expr_CurrentTimestamp();
     // Loop for case when hash is not unique
     while (true) {
         try {
             $model->save($data);
             // Old staff keys can by recognized because they start with 'os'
             return 'os' . $data['gsf_reset_key'];
         } catch (\Zend_Db_Exception $zde) {
             $data['gsf_reset_key'] = $this->hashPassword(time() . $user->getEmailAddress());
         }
     }
 }