protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); if ($this->frm->isCorrect()) { $groups = array(); $profilesAll = 0; $profileGroups = array(); $users = array(); //--Get all the groups $groups = $fields["groups"]->getValue(); //--Check if mailengine groups are selected if (!empty($groups)) { //--Get the users for the groups $usersTemp = BackendMailengineModel::getUniqueEmailsFromGroups($groups); //--Add the groups if (is_array($usersTemp)) { $users = array_merge($users, $usersTemp); } } //--Check if there are profile groups checked if (isset($fields["profile_groups"])) { //--Get all the groups $profileGroups = $fields["profile_groups"]->getValue(); if (!empty($profileGroups)) { //--Get the users for the groups $usersTemp = BackendMailengineModel::getUniqueEmailsFromProfileGroups($profileGroups); //--Add the groups if (is_array($usersTemp)) { $users = array_merge($users, $usersTemp); } } } //--Check if all profiles is selected if (isset($fields["profiles_all"])) { if ($fields['profiles_all']->getValue() == 1) { $profilesAll = 1; $usersTemp = BackendMailengineModel::getUniqueEmailsFromProfiles(); if (is_array($usersTemp)) { $users = array_merge($users, $usersTemp); } } } //--Loop all the users and set the e-mail as key to remove duplicate e-mails $usersTemp = array(); foreach ($users as $user) { if (!isset($usersTemp[$user['email']])) { $usersTemp[$user['email']] = $user; } } //--Reset users-array to the unduplicate array $users = $usersTemp; //--Count users $countUsers = count($users); //--Create label $labelUsers = $countUsers == 1 ? BL::lbl("User") : BL::lbl("Users"); $this->tpl->assign("users", $users); $this->tpl->assign("countUsers", $countUsers); $this->tpl->assign("labelUsers", $labelUsers); if ($countUsers == 0) { $this->tpl->assign("errorUsers", true); $this->tpl->assign("back", BackendModel::createURLForAction($this->action, $this->module) . "&id=" . $this->id); } //--Add hidden fields to form $this->frm_review->addHidden("groups", implode(",", $groups)); $this->frm_review->addHidden("profiles_all", $profilesAll); $this->frm_review->addHidden("profile_groups", implode(",", $profileGroups)); $this->frm_review->addHidden("start_date", $fields["start_date"]->getValue()); $this->frm_review->addHidden("start_time", $fields["start_time"]->getValue()); //--Parse Form Review $this->parseFormReview(); } else { //--Parse Form Preview $this->parseFormPreview(); } } elseif ($this->frm_review->isSubmitted()) { //--Check if form_review is submitted $fields = $this->frm_review->getFields(); if ($this->frm_review->isCorrect()) { //--Insert mailing in ready-to-send-database $readyToSendId = BackendMailengineModel::insertMailingInReadyToSendDatabase($this->id, BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($fields['start_date'], $fields['start_time']))); //--Insert users in ready-to-send-database $groups = $fields["groups"]->getValue(); $profilesAll = $fields["profiles_all"]->getValue(); $profileGroups = $fields["profile_groups"]->getValue(); BackendMailengineModel::insertUsersInReadyToSendDatabase($readyToSendId, $groups, $profileGroups, $profilesAll); //--Redirect \SpoonHTTP::redirect(BackendModel::createURLForAction($this->action, $this->module) . "&id=" . $this->id . "&ready=1"); } } else { //--Parse Form Preview $this->parseFormPreview(); } }