/** * Execute the action */ public function execute() { parent::execute(); // get parameters $mailingId = SpoonFilter::getPostValue('mailing_id', null, '', 'int'); $sendOnDate = SpoonFilter::getPostValue('send_on_date', null, BackendModel::getUTCDate('d/m/Y')); $sendOnTime = SpoonFilter::getPostValue('send_on_time', null, BackendModel::getUTCDate('H:i')); $messageDate = $sendOnDate; // validate mailing ID if ($mailingId == '') { $this->output(self::BAD_REQUEST, null, 'Provide a valid mailing ID'); } if ($sendOnDate == '' || $sendOnTime == '') { $this->output(self::BAD_REQUEST, null, 'Provide a valid send date date provided'); } // record is empty if (!BackendMailmotorModel::existsMailing($mailingId)) { $this->output(self::BAD_REQUEST, null, BL::err('MailingDoesNotExist', 'mailmotor')); } // reverse the date and make it a proper $explodedDate = explode('/', $sendOnDate); $sendOnDate = $explodedDate[2] . '-' . $explodedDate[1] . '-' . $explodedDate[0]; // calc full send timestamp $sendTimestamp = strtotime($sendOnDate . ' ' . $sendOnTime); // build data $item['id'] = $mailingId; $item['send_on'] = BackendModel::getUTCDate('Y-m-d H:i:s', $sendTimestamp); $item['edited_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); // update mailing BackendMailmotorModel::updateMailing($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit_mailing_step4', array('item' => $item)); // output $this->output(self::OK, array('mailing_id' => $mailingId, 'timestamp' => $sendTimestamp), sprintf(BL::msg('SendOn', $this->getModule()), $messageDate, $sendOnTime)); }
/** * 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.'); } // 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(900, null, BL::err('MailingAlreadySent', $this->getModule())); } // 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 { BackendMailmotorCMHelper::sendMailing($mailing); } } catch (Exception $e) { // stop the script and show our error $this->output(902, null, $e->getMessage()); } // 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())); }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files 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, ''); $fullContentHTML = SpoonFilter::getPostValue('full_content_html', null, ''); // validate mailing ID if ($mailingId == '') { $this->output(self::BAD_REQUEST, null, 'No mailing ID provided'); } // get mailing record $this->mailing = BackendMailmotorModel::getMailing($mailingId); // record is empty if (empty($this->mailing)) { $this->output(self::BAD_REQUEST, null, BL::err('MailingDoesNotExist', $this->getModule())); } // validate other fields if ($subject == '') { $this->output(900, array('element' => 'subject', 'element_error' => BL::err('NoSubject', $this->getModule())), BL::err('FormError')); } // set full HTML $HTML = $this->getEmailContent($this->mailing['template'], $contentHTML, $fullContentHTML); // set plain content $contentPlain = empty($contentPlain) ? SpoonFilter::stripHTML($HTML) : $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['data'] = serialize(array('full_content_html' => $HTML)); $item['edited_on'] = date('Y-m-d H:i:s'); // update mailing BackendMailmotorModel::updateMailing($item); // 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())); }
/** * 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'); } // get mailing record $this->mailing = BackendMailmotorModel::getMailing($mailingId); // record is empty if (empty($this->mailing)) { $this->output(self::BAD_REQUEST, null, BL::err('MailingDoesNotExist', $this->getModule())); } // validate other fields if ($subject == '') { $this->output(900, array('element' => 'subject', 'element_error' => BL::err('NoSubject', $this->getModule())), BL::err('FormError')); } // 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')) { $error = BL::err('PaymentDetailsRequired', $this->getModule()); $cmUsername = BackendModel::getModuleSetting($this->getModule(), 'cm_username'); $message = sprintf($error, $cmUsername); } elseif (strpos($e->getMessage(), 'Duplicate Campaign Name')) { $message = BL::err('DuplicateCampaignName', $this->getModule()); } else { $message = $e->getMessage(); } // stop the script and show our error $this->output(902, null, $message); } // 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())); }
/** * Validate the form */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // shorten fields $ddmCampaigns = $this->frm->getField('campaigns'); // no errors? if ($this->frm->isCorrect()) { // build item $item['id'] = $this->id; $item['campaign_id'] = $ddmCampaigns->getValue(); // update the item BackendMailmotorModel::updateMailing($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit_mailing', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&var=' . urlencode($this->record['name']) . '&highlight=id-' . $item['id']); } } }
/** * Validate the form for step 2 * * @return void */ private function validateFormForStep2() { // is the form submitted? if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // shorten fields $rbtTemplates = $this->frm->getField('templates'); // set form values $values = $this->frm->getValues(); // check if at least one language is chosen if (empty($values['templates'])) { $rbtTemplates->isFilled(BL::err('TemplateIsRequired')); } // no errors? if ($this->frm->isCorrect()) { // set values $item['id'] = $this->id; $item['template'] = $rbtTemplates->getValue(); $item['edited_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); // update the concept BackendMailmotorModel::updateMailing($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit_mailing_step2', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $item['id'] . '&step=3'); } } }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files 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.'); } // 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(900, null, BL::err('MailingAlreadySent', $this->getModule())); } // 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 { BackendMailmotorCMHelper::sendMailing($mailing); } } catch (Exception $e) { // fetch campaign ID in CM $cmId = BackendMailmotorCMHelper::getCampaignMonitorID('campaign', $id); // check if the CM ID isn't false if ($cmId !== false) { // delete the mailing in CM BackendMailmotorCMHelper::getCM()->deleteCampaign($cmId); // delete the reference BackendModel::getDB(true)->delete('mailmotor_campaignmonitor_ids', 'cm_id = ?', $cmId); } // check what error we have switch ($e->getMessage()) { case 'HTML Content URL Required': $message = BL::err('HTMLContentURLRequired', $this->getModule()); break; case 'Payment details required': $message = sprintf(BL::err('PaymentDetailsRequired', $this->getModule()), BackendModel::getModuleSetting($this->getModule(), 'cm_username')); break; case 'Duplicate Campaign Name': $message = BL::err('DuplicateCampaignName', $this->getModule()); break; default: $message = $e->getMessage(); break; } // stop the script and show our error $this->output(902, null, $message); } // 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())); }