Example #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendMailengineModel::existsUser($this->id)) {
         parent::execute();
         $this->record = (array) BackendMailengineModel::getUser($this->id);
         BackendMailengineModel::deleteUser($this->id);
         BackendMailengineModel::deleteGroupFromUser($this->id);
         BackendModel::triggerEvent($this->getModule(), 'after_delete_user', array('id' => $this->id));
         $this->redirect(BackendModel::createURLForAction('users') . '&report=deleted&var=' . urlencode($this->record['name']));
     } else {
         $this->redirect(BackendModel::createURLForAction('users') . '&error=non-existing');
     }
 }
Example #2
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         $fields['name']->isFilled(BL::err('FieldIsRequired'));
         $fields['email']->isFilled(BL::err('FieldIsRequired'));
         $fields['email']->isEmail(BL::err('EmailIsInvalid'));
         if ($this->frm->isCorrect()) {
             $item['name'] = $fields['name']->getValue();
             $item['email'] = $fields['email']->getValue();
             $item['active'] = $fields['active']->getValue();
             BackendMailengineModel::updateUser($this->id, $item);
             $item['id'] = $this->id;
             //--Delete users from the group
             BackendMailengineModel::deleteGroupFromUser($this->id);
             //--Check if there are groups
             if (isset($fields['groups'])) {
                 //--Get all the groups
                 $groups = $fields["groups"]->getValue();
                 foreach ($groups as $key => $value) {
                     $groupUser = array();
                     $groupUser["user_id"] = $this->id;
                     $groupUser["group_id"] = $value;
                     //--Add user to the group
                     BackendMailengineModel::insertUserToGroup($groupUser);
                 }
             }
             BackendModel::triggerEvent($this->getModule(), 'after_edit_user', $item);
             $this->redirect(BackendModel::createURLForAction('users') . '&report=edited&highlight=row-' . $item['id']);
         }
     }
 }