Ejemplo n.º 1
0
 /**
  * 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']);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         $fields = $this->frm->getFields();
         $fields['email']->isFilled(BL::err('FieldIsRequired'));
         if ($this->frm->isCorrect()) {
             //--Get the mail
             $mailing = BackendMailengineModel::get($this->id);
             //--Get the template
             $template = BackendMailengineModel::getTemplate($mailing['template_id']);
             //--Create basic mail
             $text = BackendMailengineModel::createMail($mailing, $template);
             $mailing['from_email'] = $template['from_email'];
             $mailing['from_name'] = html_entity_decode($template['from_name']);
             $mailing['reply_email'] = $template['reply_email'];
             $mailing['reply_name'] = html_entity_decode($template['reply_name']);
             $emails = explode(',', $fields['email']->getValue());
             if (!empty($emails)) {
                 foreach ($emails as $email) {
                     $email = trim($email);
                     if (\SpoonFilter::isEmail($email)) {
                         //--Send test mailing
                         BackendMailengineModel::sendMail(html_entity_decode($mailing['subject']), $text, $email, 'Test Recepient', $mailing);
                     }
                 }
             }
             //--Redirect
             \SpoonHTTP::redirect(BackendModel::createURLForAction('index', $this->module) . "&id=" . $this->id . "&report=TestEmailSend");
         }
     }
     $this->frm->parse($this->tpl);
 }
Ejemplo n.º 3
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     //--Get the id
     $id = \SpoonFilter::getGetValue('id', null, 0);
     //--Export users
     BackendMailengineModel::exportUsers($id);
 }
Ejemplo n.º 4
0
 /**
  * Load the item data
  */
 protected function loadData()
 {
     $this->id = $this->getParameter('id', 'int', null);
     if ($this->id == null || !BackendMailengineModel::existsStatsMail($this->id)) {
         $this->redirect(BackendModel::createURLForAction('stats') . '&error=non-existing');
     }
     $this->record = BackendMailengineModel::getStatsOverlay($this->id);
 }
Ejemplo n.º 5
0
 /**
  * Load the item data
  */
 protected function loadData()
 {
     $this->id = $this->getParameter('id', 'int', null);
     if ($this->id == null || !BackendMailengineModel::exists($this->id)) {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
     $this->record = BackendMailengineModel::getPreview($this->id);
     echo $this->record;
     die;
 }
Ejemplo n.º 6
0
 /**
  * Load the form
  */
 protected function loadForm()
 {
     // create form
     $this->frm = new BackendForm('settings');
     // get categories
     $groups = BackendMailengineModel::getAllGroupsForDropdown();
     $groups = array("0" => "") + $groups;
     // multiple categories?
     $default_group = BackendModel::getModuleSetting($this->URL->getModule(), 'default_group');
     $default_group = $default_group > 0 ? $default_group : 0;
     // create element
     $this->frm->addDropdown('default_group', $groups, BackendModel::getModuleSetting($this->URL->getModule(), 'default_group'));
 }
Ejemplo n.º 7
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendMailengineModel::existsTemplate($this->id)) {
         parent::execute();
         $this->record = (array) BackendMailengineModel::getTemplate($this->id);
         BackendMailengineModel::deleteTemplate($this->id);
         BackendModel::triggerEvent($this->getModule(), 'after_delete_template', array('id' => $this->id));
         $this->redirect(BackendModel::createURLForAction('templates') . '&report=deleted&var=' . urlencode($this->record['title']));
     } else {
         $this->redirect(BackendModel::createURLForAction('templates') . '&error=non-existing');
     }
 }
Ejemplo n.º 8
0
 protected function loadData()
 {
     $this->id = $this->getParameter('id', 'int', null);
     if ($this->id == null || !BackendMailengineModel::existsStatsMail($this->id)) {
         $this->redirect(BackendModel::createURLForAction('Stats') . '&error=non-existing');
     }
     $this->header->addJS('highcharts.js', 'Core', false);
     //--Get mail stats
     $this->record = BackendMailengineModel::getStatsMail($this->id);
     //--Get the opened mails by date
     $this->mailsOpenedByDayChart = BackendMailengineModel::getStatsMailOpenedByDay($this->id);
     //--Get the opened mails by date
     $this->mailsOpenedByHourChart = BackendMailengineModel::getStatsMailOpenedByHour($this->id);
     //--Get the clicked links
     $this->linksClickedTotalChart = BackendMailengineModel::getStatsLinksClickedTotal($this->id);
     //--Get the clicked links by day
     $this->linksClickedByDayChart = BackendMailengineModel::getStatsLinksClickedByDay($this->id);
 }
Ejemplo n.º 9
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     //--Get the mailings which are ready to send
     $mails = BackendMailengineModel::getWaitingMailings();
     if (!empty($mails)) {
         //--Loop the mails
         foreach ($mails as $mail) {
             //--Get mailer-email to send the mail to
             $arrFrom = BackendModel::getModuleSetting('Core', 'mailer_from');
             //--Create variables array
             $variables = array();
             $variables['sentOn'] = time();
             $variables['dateFormatLong'] = BackendModel::getModuleSetting('Core', 'date_format_long') . " " . BackendModel::getModuleSetting('Core', 'time_format');
             $variables['subject'] = $mail['subject'];
             //--Send start mail
             /* $message = \Common\Mailer\Message::newInstance(
                    'Mailing started "' . $mail['subject'] . '"'
                )
                    ->setFrom(array($arrFrom['email'] => $arrFrom['name']))
                    ->setTo(array($arrFrom['email']))
                    ->parseHtml(
                        BACKEND_MODULES_PATH . '/Modules/Mailengine/Layout/Templates/Mails/MailingStart.tpl',
                        $variables
                    )
                ;
                $this->get('mailer')->send($message);*/
             //				$this->get('mailer')->addEmail('Mailing started "' . $mail['subject'] . '"', BACKEND_PATH . '/Modules/Mailengine/Layout/Templates/Mails/MailingStart.tpl', $variables, $arrFrom["email"], $arrFrom["name"]);
             //--Insert mail in stats
             $data = array();
             $data['id'] = $mail['id'];
             $data['mail_id'] = $mail['mail_id'];
             $data['domain'] = $mail['domain'];
             $data['subject'] = $mail['subject'];
             $data['text'] = $mail['text'];
             $data['start_time'] = $mail['start_time'];
             $data['end_time'] = $mail['end_time'];
             $data['from_name'] = $mail['from_name'];
             $data['from_email'] = $mail['from_email'];
             $data['reply_name'] = $mail['reply_name'];
             $data['reply_email'] = $mail['reply_email'];
             BackendMailengineModel::insertMailToStats($data);
             $mail['from_name'] = html_entity_decode($mail['from_name']);
             $mail['reply_name'] = html_entity_decode($mail['reply_name']);
             //--Update status
             BackendMailengineModel::updateStatusMailing($mail['id'], array('status' => 'busy'));
             //--Get the users for the mailing
             $users = BackendMailengineModel::getUsersForWaitingMail($mail['id']);
             if (!empty($users)) {
                 $count = 0;
                 //--Loop the users
                 foreach ($users as $user) {
                     //--Translate the text and subject with the user-vars
                     $text = BackendMailengineModel::translateUserVars($mail['text'], $user);
                     $subject = BackendMailengineModel::translateUserVars($mail['subject'], $user);
                     //--Send the mail
                     if (BackendMailengineModel::sendMail(html_entity_decode($subject), $text, $user['email'], $user['name'], $mail)) {
                         $data = array();
                         $data['send_id'] = $mail['id'];
                         $data['user_id'] = $user['id'];
                         //--Save the send-data for the mails
                         BackendMailengineModel::insertMailUsers($data);
                     }
                     //--Add count
                     $count++;
                     //--Let the script sleep for an instant after sending x-numbers of mails
                     if ($count % 50 == 0) {
                         sleep(5);
                         set_time_limit(120);
                     }
                 }
                 //--Update status
                 BackendMailengineModel::updateStatusMailing($mail['id'], array('status' => 'finished', 'end_time' => BackendModel::getUTCDate()));
                 //--Create variables array
                 $variables = array();
                 $variables['sentOn'] = time();
                 $variables['dateFormatLong'] = BackendModel::getModuleSetting('Core', 'date_format_long') . " " . BackendModel::getModuleSetting('Core', 'time_format');
                 $variables['subject'] = $mail['subject'];
                 $variables['users'] = count($users);
                 /*$message = \Common\Mailer\Message::newInstance(
                       'Mailing ended "' . $mail['subject'] . '"'
                   )
                       ->setFrom(array($arrFrom['email'] => $arrFrom['name']))
                       ->setTo(array($arrFrom['email']))
                       ->parseHtml(
                           BACKEND_MODULES_PATH . '/Modules/Mailengine/Layout/Templates/Mails/MailingEnd.tpl',
                           $variables
                       )
                   ;
                   $this->get('mailer')->send($message);*/
                 //--Send start mail
                 //					$this->get('mailer')->addEmail('Mailing ended "' . $mail['subject'] . '"', BACKEND_PATH . '/Modules/Mailengine/Layout/Templates/Mails/MailingEnd.tpl', $variables, $arrFrom["email"], $arrFrom["name"]);
             }
         }
     }
 }
Ejemplo n.º 10
0
 /**
  * Load the form.
  */
 private function loadForm()
 {
     // create form
     $this->frm = new BackendForm('filter', BackendModel::createURLForAction(), 'get');
     // add fields
     $this->frm->addText('email', $this->filter['email']);
     $this->frm->addText('name', $this->filter['name']);
     // get categories
     $groups = BackendMailengineModel::getAllGroupsForDropdown();
     $groups = array("0" => "") + $groups;
     // multiple categories?
     if (count($groups) > 1) {
         // create element
         $this->frm->addDropdown('group', $groups, $this->filter["group"]);
         $this->frm->getField('group')->setDefaultElement('');
     }
     // manually parse fields
     $this->frm->parse($this->tpl);
 }
Ejemplo n.º 11
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']);
         }
     }
 }
Ejemplo n.º 12
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;
 }
Ejemplo n.º 13
0
 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();
     }
 }
Ejemplo n.º 14
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         $fields['subject']->isFilled(BL::err('FieldIsRequired'));
         $fields['text']->isFilled(BL::err('FieldIsRequired'));
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             $item['meta_id'] = $this->meta->save();
             $item['subject'] = $fields['subject']->getValue();
             $item['text'] = $fields['text']->getValue();
             $item['hidden'] = $fields['hidden']->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['template_id'] = $fields['template_id']->getValue();
             $item['show_on_website'] = $fields['show_on_website']->getValue();
             BackendMailengineModel::update($this->id, $item);
             $item['id'] = $this->id;
             BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['subject'], 'text' => $item['text']));
             BackendModel::triggerEvent($this->getModule(), 'after_edit', $item);
             $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&highlight=row-' . $item['id']);
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         $fields['title']->isFilled(BL::err('FieldIsRequired'));
         $fields['from_email']->isFilled(BL::err('FieldIsRequired'));
         $fields['from_name']->isFilled(BL::err('FieldIsRequired'));
         $fields['reply_email']->isFilled(BL::err('FieldIsRequired'));
         $fields['reply_name']->isFilled(BL::err('FieldIsRequired'));
         $fields['template']->isFilled(BL::err('FieldIsRequired'));
         $fields['from_email']->isEmail(BL::err('EmailIsInvalid'));
         $fields['reply_email']->isEmail(BL::err('EmailIsInvalid'));
         if ($this->frm->isCorrect()) {
             $item['title'] = $fields['title']->getValue();
             $item['from_email'] = $fields['from_email']->getValue();
             $item['from_name'] = $fields['from_name']->getValue();
             $item['reply_email'] = $fields['reply_email']->getValue();
             $item['reply_name'] = $fields['reply_name']->getValue();
             $item['template'] = $fields['template']->getValue();
             $item['css'] = $fields['css']->getValue();
             $item['hidden'] = $fields['hidden']->getValue();
             BackendMailengineModel::updateTemplate($this->id, $item);
             $item['id'] = $this->id;
             BackendModel::triggerEvent($this->getModule(), 'after_edit_template', $item);
             $this->redirect(BackendModel::createURLForAction('templates') . '&report=edited&highlight=row-' . $item['id']);
         }
     }
 }
Ejemplo n.º 16
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     //--Export users
     BackendMailengineModel::exportDemo();
 }