public function sendAction()
 {
     $form = new Form_MessageUsers();
     $formData = $this->_request->getPost();
     $form->populate($formData);
     if (!$form->isValid($formData)) {
         return $this->_redirectFaultyForm($form);
     }
     $cc = $form->getValue('cc');
     $bccArr = array();
     if (trim($cc) != '') {
         $validator = new Zend_Validate_EmailAddress();
         $bccArr = explode(',', $cc);
         for ($i = 0; $i < count($bccArr); $i++) {
             $bccArr[$i] = trim($bccArr[$i]);
             if (!$validator->isValid($bccArr[$i])) {
                 foreach ($validator->getMessages() as $messageId => $message) {
                     $form->cc->addError($this->view->translate('CC field must be a comma-separated list of valid E-mails'));
                     return $this->_redirectFaultyForm($form);
                 }
             }
         }
     }
     $mail = self::getMail($form->getValue('subject'), $this->_getParam('messageType'), $this->_getParam('messageType') == 'plain' ? $form->getValue('bodyPlain') : $form->getValue('bodyHTML'));
     $mail->setSubject($form->getValue('subject'));
     if ($this->_getParam('messageType') == 'plain') {
         $mail->setBodyText($form->getValue('bodyPlain'));
     } else {
         $mail->setBodyHtml($form->getValue('bodyHTML'));
     }
     $users = new Users_Model_Users();
     // here we get the users emails stored in the users table, even if using LDAP, for performance reasons.
     // Do know however, that a user email is synced with the LDAP repository every time he logs in.
     foreach ($users->getUsers() as $user) {
         if ($user->role == Users_Model_User::ROLE_ADMIN) {
             continue;
         }
         $mail->addBcc($user->email);
     }
     foreach ($bccArr as $bcc) {
         $mail->addBcc($bcc);
     }
     try {
         $mail->send();
         $this->_helper->FlashMessenger->addMessage($this->view->translate('Message has been sent'));
     } catch (Zend_Mail_Protocol_Exception $e) {
         $this->_helper->FlashMessenger->addMessage($this->view->translate('There was an error trying to send the message'));
         if ($this->_config->logging->level == Zend_Log::DEBUG) {
             $this->_helper->FlashMessenger->addMessage($e->getMessage());
             return $this->_redirectFaultyForm($form);
         }
     }
     $this->_redirect('');
 }
 public function indexAction()
 {
     $this->_helper->viewRenderer->setNeverRender(true);
     $users = new Users_Model_Users();
     switch ($this->_getParam('filter')) {
         case 'confirmed':
             $where = "accepted_eula=1 AND role != '" . Users_Model_User::ROLE_ADMIN . "'";
             break;
         case 'unconfirmed':
             $where = "accepted_eula=0 AND role != '" . Users_Model_User::ROLE_ADMIN . "'";
             break;
         default:
             $where = false;
             break;
     }
     // This retrieves user data from the users table, even if using LDAP. This means the user's full name
     // might be out of sync with what it's in LDAP. No biggie since user's names rarely change ;)
     // However do know that a given user name is synced with LDAP every time he logs in.
     $usersRows = $users->getUsers($this->_getParam('startIndex'), $this->_getParam('results'), $this->_getParam('sort', 'registration'), $this->_getParam('dir', Users_Model_Users::DIR_DESC), $where, trim($this->_getParam('search')));
     $jsonObj = new StdClass();
     $jsonObj->recordsReturned = count($usersRows);
     $jsonObj->totalRecords = $users->getNumUsers($where, trim($this->_getParam('search')));
     $jsonObj->totalUsers = $users->getNumUsers();
     $jsonObj->totalUnconfirmedUsers = $users->getNumUnconfirmedUsers();
     $jsonObj->startIndex = $this->_getParam('startIndex');
     $jsonObj->sort = $this->_getParam('sort');
     $jsonObj->dir = $this->_getParam('dir');
     $jsonObj->records = array();
     foreach ($usersRows as $user) {
         if ($user->role == Users_Model_User::ROLE_ADMIN) {
             if ($this->_config->ldap->enabled && $user->username != $this->_config->ldap->admin) {
                 // this is the admin created during the installation, that is not used when ldap is enabled
                 continue;
             }
             $status = $this->view->translate('admin');
         } else {
             if ($user->accepted_eula) {
                 $status = $this->view->translate('confirmed');
             } else {
                 $status = $this->view->translate('unconfirmed');
             }
         }
         $jsonObjUser = new StdClass();
         $jsonObjUser->id = $user->id;
         $jsonObjUser->name = $user->getFullName();
         $jsonObjUser->registration = $user->registration_date;
         $jsonObjUser->role = $user->role;
         $jsonObjUser->status = $status;
         $jsonObjUser->reminders = $user->accepted_eula ? 0 : $user->reminders;
         $jsonObj->records[] = $jsonObjUser;
     }
     echo Zend_Json::encode($jsonObj);
 }
 /**
  * I need to fill the new profile_id field in the fields_values table, before being able to
  * add a foreign key to it
  */
 public function proceed()
 {
     $fieldsValues = new Model_FieldsValues();
     $users = new Users_Model_Users();
     foreach ($users->getUsers() as $user) {
         $profileId = $user->createDefaultProfile($this->_view);
         foreach ($fieldsValues->getForUser($user) as $fieldValue) {
             $fieldValue->profile_id = $profileId;
             $fieldValue->save();
         }
     }
     $this->_db->query('ALTER TABLE `fields_values` ADD FOREIGN KEY ( `profile_id` ) REFERENCES `profiles` (`id`) ON DELETE CASCADE');
 }