Example #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // action to execute
     $id = \SpoonFilter::getGetValue('id', null, 0);
     // no id's provided
     if (empty($id) || !BackendMailmotorModel::existsMailing($id)) {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=mailing-does-not-exist');
     } else {
         // get the mailing and reset some fields
         $mailing = BackendMailmotorModel::getMailing($id);
         $mailing['status'] = 'concept';
         $mailing['send_on'] = null;
         $mailing['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s');
         $mailing['edited_on'] = $mailing['created_on'];
         unset($mailing['recipients'], $mailing['id'], $mailing['cm_id'], $mailing['send_on_raw']);
         // set groups
         $groups = $mailing['groups'];
         unset($mailing['groups']);
         // create a new mailing based on the old one
         $newId = BackendMailmotorModel::insertMailing($mailing);
         // update groups for this mailing
         BackendMailmotorModel::updateGroupsForMailing($newId, $groups);
         // trigger event
         BackendModel::triggerEvent($this->getModule(), 'after_copy_mailing', array('item' => $mailing));
     }
     // redirect
     $this->redirect(BackendModel::createURLForAction('Index') . '&report=mailing-copied&var=' . $mailing['name']);
 }
Example #2
0
 /**
  * Get the data
  * If a revision-id was specified in the URL we load the revision and not the actual data
  */
 private function getData()
 {
     // get the record
     $this->record = (array) BackendMailmotorModel::getMailing($this->id);
     // no item found, throw an exceptions, because somebody is f*****g with our URL
     if (empty($this->record) || $this->record['status'] == 'sent') {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
 }
Example #3
0
 /**
  * Get the data
  */
 private function getData()
 {
     // get the record
     $this->record = (array) BackendMailmotorModel::getMailing($this->id);
     // get the template record for this mailing
     $this->template = BackendMailmotorModel::getTemplate($this->record['language'], $this->record['template']);
     // no item found, throw an exceptions, because somebody is f*****g with our URL
     if (empty($this->record)) {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
 }
Example #4
0
 /**
  * Gets all data needed for this page
  */
 private function getData()
 {
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if (!BackendMailmotorModel::existsMailing($this->id)) {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=mailing-does-not-exist');
     }
     // get mailing
     $this->mailing = BackendMailmotorModel::getMailing($this->id);
     // fetch the statistics
     $this->statistics = BackendMailmotorCMHelper::getStatistics($this->id, true);
     // no stats found
     if ($this->statistics === false) {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=no-statistics-loaded&var=' . str_replace('#', '', $this->mailing['name']));
     }
 }
Example #5
0
 /**
  * Gets all data needed for this page
  */
 private function getData()
 {
     // get parameters
     $id = $this->getParameter('mailing_id', 'int');
     // does the item exist
     if (!BackendMailmotorModel::existsMailing($id)) {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=mailing-does-not-exist');
     }
     // fetch the mailing
     $this->mailing = BackendMailmotorModel::getMailing($id);
     // fetch the bounces
     $this->bounces = BackendMailmotorCMHelper::getBounces($this->mailing['id']);
     // does the item exist
     if (empty($this->bounces)) {
         $this->redirect(BackendModel::createURLForAction('Statistics') . '&id=' . $this->mailing['id'] . '&error=no-bounces');
     }
 }
Example #6
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $id = \SpoonFilter::getPostValue('id', null, '', 'int');
     // validate
     if ($id == '' || !BackendMailmotorModel::existsMailing($id)) {
         $this->output(self::BAD_REQUEST, null, 'No mailing found.');
     } else {
         // get mailing record
         $mailing = BackendMailmotorModel::getMailing($id);
         /*
             mailing was already sent
             We use a custom status code 900 because we want to do more with JS than triggering an error
         */
         if ($mailing['status'] == 'sent') {
             $this->output(500, null, BL::err('MailingAlreadySent', $this->getModule()));
         } else {
             // make a regular date out of the send_on timestamp
             $mailing['delivery_date'] = date('Y-m-d H:i:s', $mailing['send_on']);
             // send the mailing
             try {
                 // only update the mailing if it was queued
                 if ($mailing['status'] == 'queued') {
                     BackendMailmotorCMHelper::updateMailing($mailing);
                 } else {
                     // send the mailing if it wasn't queued
                     BackendMailmotorCMHelper::sendMailing($mailing);
                 }
             } catch (\Exception $e) {
                 // stop the script and show our error
                 $this->output(500, null, $e->getMessage());
                 return;
             }
             // set status to 'sent'
             $item['id'] = $id;
             $item['status'] = $mailing['send_on'] > time() ? 'queued' : 'sent';
             // update the mailing record
             BackendMailmotorModel::updateMailing($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_mailing_status_' . $item['status'], array('item' => $item));
             // we made it \o/
             $this->output(self::OK, array('mailing_id' => $item['id']), BL::msg('MailingSent', $this->getModule()));
         }
     }
 }
 /**
  * Gets all data needed for this page
  */
 private function getData()
 {
     // get parameters
     $id = $this->getParameter('mailing_id', 'int');
     $this->linkURL = $this->getParameter('url');
     // does the item exist
     if (!BackendMailmotorModel::existsMailing($id)) {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=mailing-does-not-exist');
     }
     if ($this->linkURL == '') {
         $this->redirect(BackendModel::createURLForAction('Statistics') . '&id=' . $id . '&error=link-does-not-exist');
     }
     // fetch the statistics
     $this->statistics = BackendMailmotorCMHelper::getStatistics($id, true);
     // fetch the mailing
     $this->mailing = BackendMailmotorModel::getMailing($id);
     // no stats found
     if ($this->statistics === false) {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=no-statistics-loaded');
     }
 }
Example #8
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $mailingId = \SpoonFilter::getPostValue('mailing_id', null, '', 'int');
     $subject = \SpoonFilter::getPostValue('subject', null, '');
     $contentHTML = urldecode(\SpoonFilter::getPostValue('content_html', null, ''));
     $contentPlain = \SpoonFilter::getPostValue('content_plain', null, '');
     // validate mailing ID
     if ($mailingId == '') {
         $this->output(self::BAD_REQUEST, null, 'No mailing ID provided');
     } else {
         // get mailing record
         $this->mailing = BackendMailmotorModel::getMailing($mailingId);
         // check if record is empty
         if (empty($this->mailing)) {
             $this->output(self::BAD_REQUEST, null, BL::err('MailingDoesNotExist', $this->getModule()));
         } else {
             // validate subject
             if ($subject == '') {
                 $this->output(500, array('element' => 'subject', 'element_error' => BL::err('NoSubject', $this->getModule())), BL::err('FormError'));
             } else {
                 // set plain content
                 $contentPlain = empty($contentPlain) ? \SpoonFilter::stripHTML($contentHTML) : $contentPlain;
                 // add unsubscribe link
                 if (mb_strpos($contentPlain, '[unsubscribe]') === false) {
                     $contentPlain .= PHP_EOL . '[unsubscribe]';
                 }
                 // build data
                 $item['id'] = $this->mailing['id'];
                 $item['subject'] = $subject;
                 $item['content_plain'] = $contentPlain;
                 $item['content_html'] = $contentHTML;
                 $item['edited_on'] = date('Y-m-d H:i:s');
                 // update mailing in our database
                 BackendMailmotorModel::updateMailing($item);
                 /*
                     we should insert the draft into campaignmonitor here,
                     so we can use sendCampaignPreview in step 4.
                 */
                 $item['groups'] = $this->mailing['groups'];
                 $item['name'] = $this->mailing['name'];
                 $item['from_name'] = $this->mailing['from_name'];
                 $item['from_email'] = $this->mailing['from_email'];
                 $item['reply_to_email'] = $this->mailing['reply_to_email'];
                 try {
                     BackendMailmotorCMHelper::saveMailingDraft($item);
                 } catch (Exception $e) {
                     // CM did not receive a valid URL
                     if (strpos($e->getMessage(), 'HTML Content URL Required')) {
                         $message = BL::err('HTMLContentURLRequired', $this->getModule());
                     } elseif (strpos($e->getMessage(), 'Payment details required')) {
                         // no payment details were set for the CM client yet
                         $error = BL::err('PaymentDetailsRequired', $this->getModule());
                         $cmUsername = $this->get('fork.settings')->get($this->getModule(), 'cm_username');
                         $message = sprintf($error, $cmUsername);
                     } elseif (strpos($e->getMessage(), 'Duplicate Campaign Name')) {
                         // the campaign name already exists in CM
                         $message = BL::err('DuplicateCampaignName', $this->getModule());
                     } else {
                         // we received an unknown error
                         $message = $e->getMessage();
                     }
                     // stop the script and show our error
                     $this->output(500, null, $message);
                     return;
                 }
                 // trigger event
                 BackendModel::triggerEvent($this->getModule(), 'after_edit_mailing_step3', array('item' => $item));
                 // output
                 $this->output(self::OK, array('mailing_id' => $mailingId), BL::msg('MailingEdited', $this->getModule()));
                 return;
             }
         }
         // error
         $this->output(500, null, $message);
         return;
     }
 }