/** * Validate the form */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); $fields['title']->isFilled(BL::err('FieldIsRequired')); if ($this->frm->isCorrect()) { $item['title'] = $fields['title']->getValue(); $item['id'] = BackendMailengineModel::insertGroup($item); //--Check if there are users if (isset($fields["users"])) { //--Get all the users $users = $fields["users"]->getValue(); foreach ($users as $key => $value) { $userGroup = array(); $userGroup["group_id"] = $item['id']; $userGroup["user_id"] = $value; //--Add user to the group BackendMailengineModel::insertUserToGroup($userGroup); } } BackendModel::triggerEvent($this->getModule(), 'after_add_group', $item); $this->redirect(BackendModel::createURLForAction('groups') . '&report=added&highlight=row-' . $item['id']); } } }
/** * 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']); } } }
/** * * 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; }