/** * 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 * * @return void */ public function execute() { // set force compile on because we're using multiple forms on 1 page $this->tpl->setForceCompile(true); // get parameters $this->id = $this->getParameter('id', 'int'); // get the step $this->stepId = SpoonFilter::getGetValue('step', array(1, 2, 3, 4), 1, 'int'); // does the item exist if (BackendMailmotorModel::existsMailing($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // load jquery tiny $this->header->addJS('tiny_mce/jquery.tinymce.js', 'core'); // get all data for the item we want to edit $this->getData(); // load the wizard steps $this->loadWizardSteps(); // load the appropriate step $this->{'loadStep' . $this->stepId}(); // parse $this->parse(); // display the page $this->display(); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }
/** * 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']; $mailing['data'] = serialize($mailing['data']); 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']); }
/** * Execute the action */ public function execute() { // get parameters $this->id = $this->getParameter('mailing_id', 'int'); // does the item exist if (BackendMailmotorModel::existsMailing($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // fetch the mailing $mailing = BackendMailmotorModel::getMailing($this->id); // get all data for the user we want to edit $records = (array) BackendMailmotorCMHelper::getCM()->getCampaignBounces($mailing['cm_id']); // reset some data if (!empty($records)) { // loop the records foreach ($records as $record) { // only remove the hard bounces if ($record['bounce_type'] == 'Hard') { // remove the address BackendMailmotorModel::deleteAddresses($record['email']); } } } // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete_bounces'); // user was deleted, so redirect $this->redirect(BackendModel::createURLForAction('statistics') . '&id=' . $mailing['id'] . '&report=deleted-bounces'); } else { $this->redirect(BackendModel::createURLForAction('statistics') . '&error=no-bounces'); } }
/** * Execute the action */ public function execute() { $this->id = $this->getParameter('id', 'int'); // does the item exist if (BackendMailmotorModel::existsMailing($this->id)) { parent::execute(); $this->getData(); $this->parse(); $this->display(BACKEND_MODULE_PATH . '/layout/templates/edit_mailing_iframe.tpl'); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }
/** * Execute the action */ public function execute() { parent::execute(); // action to execute $id = SpoonFilter::getGetValue('id', null, 0); // no id's provided if (!BackendMailmotorModel::existsMailing($id)) { $this->redirect(BackendModel::createURLForAction('index') . '&error=mailing-does-not-exist'); } else { BackendMailmotorModel::exportStatistics($id); } // redirect $this->redirect(BackendModel::createURLForAction('groups') . '&report=export-failed'); }
/** * 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'])); } }
/** * Execute the action */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if (BackendMailmotorModel::existsMailing($this->id)) { parent::execute(); $this->getData(); $this->loadForm(); $this->validateForm(); $this->parse(); $this->display(); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }
/** * 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'); } }
/** * Execute the action * * @return void */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if (BackendMailmotorModel::existsMailing($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get all data for the item we want to edit $this->getData(); // parse $this->parse(); // display the page $this->display(BACKEND_MODULE_PATH . '/layout/templates/edit_mailing_iframe.tpl'); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }
/** * 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())); }
/** * 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'); } }
/** * Execute the action * * @return void */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if (BackendMailmotorModel::existsMailing($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get all data for the item we want to edit $this->getData(); // load the form $this->loadForm(); // validate the form $this->validateForm(); // parse the $this->parse(); // display the page $this->display(); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }
/** * 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())); }
/** * Returns the statistics for a given mailing * * @param int $id The id of the mailing. * @param bool[optional] $fetchClicks If the click-count should be included. * @param bool[optional] $fetchOpens If the open-count should be included. * @return array */ public static function getStatistics($id, $fetchClicks = false, $fetchOpens = false) { // check if the mailing exists if (!BackendMailmotorModel::existsMailing($id)) { throw new SpoonException('No mailing found for id ' . $id); } // fetch cmID $cmId = self::getCampaignMonitorID('campaign', $id); // fetch the CM ID if ($cmId) { // fetch the statistics $stats = self::getCM()->getCampaignSummary($cmId); // stop here if no recipients were found if ($stats['recipients'] == 0) { return false; } // reset the bounces to match the real ones $bounces = BackendMailmotorCMHelper::getBounces($id); // re-calculate base stats to match CM's $stats['bounces'] = count($bounces); $stats['recipients'] = $stats['recipients']; $stats['recipients_total'] = $stats['recipients']; $stats['unopens'] = $stats['recipients'] - $stats['unique_opens'] - $stats['bounces']; $stats['clicks_total'] = 0; // add percentages to these stats $stats['bounces_percentage'] = $stats['recipients'] == 0 ? 0 : floor($stats['bounces'] / $stats['recipients_total'] * 100) . '%'; $stats['recipients_percentage'] = $stats['recipients'] == 0 ? 0 : ceil($stats['recipients'] / $stats['recipients_total'] * 100) . '%'; $stats['unique_opens_percentage'] = $stats['recipients'] == 0 ? 0 : ceil($stats['unique_opens'] / $stats['recipients'] * 100) . '%'; $stats['unopens_percentage'] = $stats['recipients'] == 0 ? 0 : floor($stats['unopens'] / $stats['recipients'] * 100) . '%'; $stats['clicks_percentage'] = $stats['recipients'] == 0 ? 0 : ceil($stats['clicks'] / $stats['recipients'] * 100) . '%'; // fetch clicks or not? if ($fetchClicks) { // get detailed click reports $subscriberClicks = self::getCM()->getCampaignClicks($cmId); // links have been clicked if (!empty($subscriberClicks)) { // declare array $stats['clicked_links'] = array(); $stats['clicked_links_by'] = $subscriberClicks; // filter out the clicked links foreach ($subscriberClicks as $link => $clickers) { // count the clickers $clickerCount = count($clickers); $stats['clicked_links'][] = array('link' => $link, 'clicks' => $clickerCount); $stats['clicks_total'] += $clickerCount; } /* // re-loop so we can fix the keys foreach($stats['clicked_links'] as $link) { // store the link data $stats['clicked_links'][] = array('link' => urlencode($link['link'])); // unset the record with the link as key unset($stats['clicked_links'][$link['link']]); } // re-loop so we can fix the keys foreach($stats['clicked_links_by'] as $link => $clicks) { // loop the clicks foreach($clicks as $click) { // store the link data $stats['clicked_links_by'][$link][] = array('email' => $click['email']); // unset the record with the link as key unset($stats['clicked_links_by'][$link][$click['email']]); } } */ } } // fetch opened stats or not? if ($fetchOpens) { // fetch opens $stats['opens'] = self::getMailingOpens($cmId); } // return the results return $stats; } // at this point, return false return false; }