Пример #1
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['language'] = BL::getWorkingLanguage();
             $item['id'] = BackendMailengineModel::insertUser($item);
             //--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"] = $item['id'];
                     $groupUser["group_id"] = $value;
                     //--Add user to the group
                     BackendMailengineModel::insertUserToGroup($groupUser);
                 }
             }
             BackendModel::triggerEvent($this->getModule(), 'after_add_user', $item);
             $this->redirect(BackendModel::createURLForAction('users') . '&report=added&highlight=row-' . $item['id']);
         }
     }
 }
Пример #2
0
 /**
  *
  * Process CSV file
  *
  * @param $csv
  * @param $groups
  *
  * @return array()
  */
 private function processCsv($csv, $groups, $language)
 {
     $errorEmail = 0;
     $errorAlreadyExists = 0;
     $successInserted = 0;
     foreach ($csv as $row) {
         set_time_limit(30);
         if (filter_var($row['email'], FILTER_VALIDATE_EMAIL)) {
             //--Get user from e-mail
             $user = BackendMailengineModel::getUserFromEmail($row['email']);
             if (empty($user)) {
                 $data = array();
                 $data['email'] = $row['email'];
                 $data['name'] = !isset($row['name']) || $row['name'] == '' ? $row['email'] : $row['name'];
                 $data['language'] = $language;
                 //--Add user
                 $user = array();
                 $user['id'] = BackendMailengineModel::insertUser($data);
                 //--Add count for ok
                 $successInserted++;
             } else {
                 //--Add count for already exists
                 $errorAlreadyExists++;
             }
             //--Loop all the groups and add the user to the group
             foreach ($groups as $value) {
                 //--Check if user is already linked to the group
                 if (!BackendMailengineModel::existsUserGroup($user['id'], $value)) {
                     $groupUser = array();
                     $groupUser["user_id"] = $user['id'];
                     $groupUser["group_id"] = $value;
                     //--Add user to the group
                     BackendMailengineModel::insertUserToGroup($groupUser);
                 }
             }
         } else {
             $errorEmail++;
         }
     }
     $return = array('errorEmail' => $errorEmail, 'errorAlreadyExists' => $errorAlreadyExists, 'successInserted' => $successInserted);
     return $return;
 }