/** * Fetches the campaign ID and sets its record */ private function getCampaign() { // get the active campaign $id = $this->getParameter('campaign', 'int'); // fetch the campaign record $this->campaign = BackendMailmotorModel::getCampaign($id); }
/** * 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']); }
/** * Execute the action */ public function execute() { parent::execute(); // get parameters $id = \SpoonFilter::getPostValue('id', null, '', 'int'); $name = trim(\SpoonFilter::getPostValue('value', null, '', 'string')); // validate if ($name == '') { $this->output(self::BAD_REQUEST, null, 'no name provided'); } else { // get existing id $existingId = BackendMailmotorModel::getCampaignId($name); // validate if ($existingId !== 0 && $id !== $existingId) { $this->output(self::ERROR, array('id' => $existingId, 'error' => true), BL::err('CampaignExists', $this->getModule())); } else { // build array $item = array(); $item['id'] = $id; $item['name'] = $name; $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); // get page $rows = BackendMailmotorModel::updateCampaign($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'edited_campaign', array('item' => $item)); // output if ($rows !== 0) { $this->output(self::OK, array('id' => $id), BL::msg('CampaignEdited', $this->getModule())); } else { $this->output(self::ERROR, null, BL::err('CampaignNotEdited', $this->getModule())); } } } }
/** * Execute the action */ public function execute() { parent::execute(); // action to execute $action = \SpoonFilter::getGetValue('action', array('delete'), ''); // get passed group ID $id = \SpoonFilter::getGetValue('group_id', null, 0, 'int'); // fetch group record $this->group = BackendMailmotorModel::getGroup($id); // set redirect URL $redirectURL = BackendModel::createURLForAction('CustomFields') . '&group_id=' . $this->group['id']; // no id's provided if (!$action) { $this->redirect($redirectURL . '&error=no-action-selected'); } if (!isset($_GET['fields'])) { $this->redirect($redirectURL . '&error=no-items-selected'); } if (empty($this->group)) { $this->redirect(BackendModel::createURLForAction('Groups') . '&error=non-existing'); } else { // redefine id's $this->fields = (array) $_GET['fields']; // evaluate $action, see what action was triggered switch ($action) { case 'delete': $this->deleteCustomFields(); break; } } }
/** * 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 $txtName = $this->frm->getField('name'); $rbtDefaultForLanguage = $this->frm->getField('default'); // validate fields if ($txtName->isFilled(BL::err('NameIsRequired'))) { // check if the group exists by name if (BackendMailmotorModel::existsGroupByName($txtName->getValue())) { $txtName->addError(BL::err('GroupAlreadyExists')); } } // no errors? if ($this->frm->isCorrect()) { // build item $item['name'] = $txtName->getValue(); $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); $item['language'] = $rbtDefaultForLanguage->getValue() === '0' ? null : $rbtDefaultForLanguage->getValue(); $item['is_default'] = $rbtDefaultForLanguage->getChecked() ? 'Y' : 'N'; // insert the item $item['id'] = BackendMailmotorCMHelper::insertGroup($item); // check if all default groups were set BackendMailmotorModel::checkDefaultGroups(); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_group', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Groups') . '&report=added&var=' . urlencode($item['name']) . '&highlight=id-' . $item['id']); } } }
/** * 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'); } }
/** * Load the form */ private function loadForm() { $this->frm = new BackendForm('add'); $this->frm->addText('email'); // fetch groups $groups = BackendMailmotorModel::getGroupsForCheckboxes(); // if no groups are found, redirect to overview if (empty($groups)) { $this->redirect(BackendModel::createURLForAction('Addresses') . '&error=no_groups'); } // add checkboxes for groups $this->frm->addMultiCheckbox('groups', $groups, $this->groupId); }
/** * Execute the action */ public function execute() { parent::execute(); // action to execute $id = \SpoonFilter::getGetValue('id', null, 0); // no id's provided if (!BackendMailmotorModel::existsCampaign($id)) { $this->redirect(BackendModel::createURLForAction('Campaigns') . '&error=campaign-does-not-exist'); } else { // at least one id BackendMailmotorModel::exportStatisticsByCampaignID($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() { 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'); // 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'); } }
/** * Gets all data needed for this page */ private function getData() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if (!BackendMailmotorModel::existsCampaign($this->id)) { $this->redirect(BackendModel::createURLForAction('Campaigns') . '&error=campaign-does-not-exist'); } // store mailing $this->campaign = BackendMailmotorModel::getCampaign($this->id); // fetch the statistics $this->statistics = BackendMailmotorCMHelper::getStatisticsByCampaignID($this->id, true); // no stats found if ($this->statistics === false || empty($this->statistics)) { $this->redirect(BackendModel::createURLForAction('Campaigns') . '&error=no-statistics-loaded'); } }
/** * Execute the action */ public function execute() { parent::execute(); // action to execute $action = \SpoonFilter::getGetValue('action', array('delete'), 'delete'); // no id's provided if (!isset($_GET['id'])) { $this->redirect(BackendModel::createURLForAction('Campaigns') . '&error=no-items-selected'); } else { // redefine id's $ids = (array) $_GET['id']; // delete comment(s) if ($action == 'delete') { BackendMailmotorModel::deleteCampaigns($ids); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete_campaigns', array('ids' => $ids)); } } // redirect $this->redirect(BackendModel::createURLForAction('Campaigns') . '&report=delete-campaigns'); }
/** * Loads the datagrid with the groups */ private function loadDataGrid() { // create datagrid $this->dataGrid = new BackendDataGridDB(BackendMailmotorModel::QRY_DATAGRID_BROWSE_GROUPS); $this->dataGrid->setColumnsHidden(array('language', 'is_default')); // sorting columns $this->dataGrid->setSortingColumns(array('name', 'created_on'), 'created_on'); $this->dataGrid->setSortParameter('desc'); // check if this action is allowed if (BackendAuthentication::isAllowedAction('Addresses')) { // set column URLs $this->dataGrid->setColumnURL('name', BackendModel::createURLForAction('Addresses') . '&group_id=[id]'); } // set the datagrid ID so we don't run into trouble with multiple datagrids that use mass actions $this->dataGrid->setAttributes(array('id' => 'dgGroups')); // add the multicheckbox column $this->dataGrid->setMassActionCheckboxes('checkbox', '[id]', BackendMailmotorModel::getDefaultGroupIds()); $this->dataGrid->setColumnsSequence('checkbox', 'name', 'created_on', 'language'); // add mass action dropdown $ddmMassAction = new \SpoonFormDropdown('action', array('delete' => BL::lbl('Delete')), 'delete'); $this->dataGrid->setMassAction($ddmMassAction); // set column functions $this->dataGrid->setColumnFunction(array(new BackendDataGridFunctions(), 'getTimeAgo'), array('[created_on]'), 'created_on', true); // check if this action is allowed if (BackendAuthentication::isAllowedAction('CustomFields')) { $this->dataGrid->addColumnAction('custom_fields', null, BL::lbl('CustomFields'), BackendModel::createURLForAction('CustomFields') . '&group_id=[id]', BL::lbl('CustomFields'), array('class' => 'button icon iconEdit linkButton')); } // check if this action is allowed if (BackendAuthentication::isAllowedAction('ExportAddresses')) { $this->dataGrid->addColumnAction('export', null, BL::lbl('Export'), BackendModel::createURLForAction('ExportAddresses') . '&id=[id]', BL::lbl('Export'), array('class' => 'button icon iconExport linkButton')); } // check if this action is allowed if (BackendAuthentication::isAllowedAction('EditGroup')) { $this->dataGrid->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('EditGroup') . '&id=[id]', BL::lbl('Edit')); } // add styles $this->dataGrid->setColumnAttributes('name', array('class' => 'title')); // set paging limit $this->dataGrid->setPagingLimit(self::PAGING_LIMIT); }
/** * 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'); } else { // validate date & time if ($sendOnDate == '' || $sendOnTime == '') { $this->output(self::BAD_REQUEST, null, 'Provide a valid send date date provided'); } else { // record is empty if (!BackendMailmotorModel::existsMailing($mailingId)) { $this->output(self::BAD_REQUEST, null, BL::err('MailingDoesNotExist', $this->getModule())); } else { // 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)); } } } }
/** * 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 $txtName = $this->frm->getField('name'); // validate fields $txtName->isFilled(BL::err('NameIsRequired')); // no errors? if ($this->frm->isCorrect()) { // build item $item['name'] = $txtName->getValue(); $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); // insert the item $item['id'] = BackendMailmotorModel::insertCampaign($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_campaign', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Campaigns') . '&report=added&var=' . urlencode($item['name']) . '&highlight=id-' . $item['id']); } } }
/** * Execute the action */ public function execute() { parent::execute(); // action to execute $id = \SpoonFilter::getGetValue('id', null, 0); // no id's provided if (empty($id)) { $this->redirect(BackendModel::createURLForAction('Groups') . '&error=no-items-selected'); } else { // at least one id // export all addresses if ($id == 'all') { // fetch records $records = BackendMailmotorModel::getAddresses(); // export records BackendMailmotorModel::exportAddresses($records); } else { // export addresses by group ID BackendMailmotorModel::exportAddressesByGroupID($id); } } // redirect $this->redirect(BackendModel::createURLForAction('Groups') . '&report=export-failed'); }
/** * 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']); } } }
/** * Load the form */ private function loadForm() { // create form $this->frm = new BackendForm('edit'); // create elements $this->frm->addText('email', $this->email); $this->frm->getField('email')->setAttribute('disabled', 'disabled'); // fetch groups for checkbox format $checkboxGroups = BackendMailmotorModel::getGroupsForCheckboxes(); // if no groups are found, redirect to overview if (empty($checkboxGroups)) { $this->redirect(BackendModel::createURLForAction('Addresses') . '&error=no-groups'); } // add checkboxes for groups $this->frm->addMultiCheckbox('groups', $checkboxGroups, $this->record['groups']); // add dropdown for subscriptions if (!empty($this->subscriptions)) { $this->frm->addDropdown('subscriptions', $this->subscriptions, $this->id); } }
/** * 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 $txtName = $this->frm->getField('name'); // validate fields if ($txtName->isFilled(BL::err('NameIsRequired'))) { if (in_array($txtName->getValue(), $this->group['custom_fields'])) { $txtName->addError(BL::err('CustomFieldExists')); } } // no errors? if ($this->frm->isCorrect()) { try { // add the new item to the custom fields list $this->group['custom_fields'][] = $txtName->getValue(); // set the group fields by flipping the custom fields array for this group $groupFields = array_flip($this->group['custom_fields']); // group custom fields found if (!empty($groupFields)) { // loop the group fields and empty every value foreach ($groupFields as &$field) { $field = ''; } } // addresses found and custom field delete with CM BackendMailmotorCMHelper::createCustomField($txtName->getValue(), $this->group['id']); // update custom fields for this group BackendMailmotorModel::updateCustomFields($groupFields, $this->group['id']); } catch (\Exception $e) { // redirect with a custom error $this->redirect(BackendModel::createURLForAction('CustomFields') . '&group_id=' . $this->group['id'] . '&error=campaign-monitor-error&var=' . urlencode($e->getMessage())); } // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('CustomFields') . '&group_id=' . $this->group['id'] . '&report=added&var=' . urlencode($txtName->getValue()) . '&highlight=id-' . $this->group['id']); } } }
/** * Updates a mailing * * @param array $item The mailing record to update. */ public static function updateMailing(array $item) { $local = $item; self::deleteMailings($item['id']); // fetch the CM IDs for each group if this field is not set yet if (!isset($item['group_cm_ids'])) { $item['group_cm_ids'] = self::getCampaignMonitorIDsForGroups($item['groups']); } // fetch the content URLs if (!isset($item['content_html_url'])) { $item['content_html_url'] = BackendMailmotorModel::getMailingPreviewURL($item['id'], 'html', true); } if (!isset($item['content_plain_url'])) { $item['content_plain_url'] = BackendMailmotorModel::getMailingPreviewURL($item['id'], 'plain', true); } // overwrite the name, because the previous one is taken -.- $item['name'] .= ' (#' . rand(0, 999) . ')'; // re-insert the mailing in CM self::insertMailing($item); // unset vars we don't need, save vars we need later $groups = $local['groups']; unset($local['cm_id'], $local['groups'], $local['recipients'], $local['delivery_date']); // serialize full content mailing $local['data'] = serialize($local['data']); // re-insert the mailing in our database $id = BackendMailmotorModel::insertMailing($local); // reinsert the groups for this mailing BackendMailmotorModel::updateGroupsForMailing($id, $groups); }
/** * 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; } }
/** * Sets the group record */ private function setGroup() { // set the passed group ID $id = \SpoonFilter::getGetValue('group_id', null, 0, 'int'); // group was set if (!empty($id)) { // get group record $this->group = BackendMailmotorModel::getGroup($id); // assign the group record $this->tpl->assign('group', $this->group); } }
/** * 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 $txtName = $this->frm->getField('name'); $txtFromName = $this->frm->getField('from_name'); $txtFromEmail = $this->frm->getField('from_email'); $txtReplyToEmail = $this->frm->getField('reply_to_email'); $chkGroups = $this->frm->getField('groups'); $rbtLanguages = $this->frm->getField('languages'); // validate fields $txtName->isFilled(BL::err('NameIsRequired')); $txtFromName->isFilled(BL::err('NameIsRequired')); $txtFromEmail->isFilled(BL::err('EmailIsRequired')); $txtReplyToEmail->isFilled(BL::err('EmailIsRequired')); // set form values $values = $this->frm->getValues(); // check if at least one recipient group is chosen if (empty($values['groups'])) { $chkGroups->addError(BL::err('ChooseAtLeastOneGroup')); } else { // fetch the recipients for these groups $recipients = BackendMailmotorModel::getAddressesByGroupID($values['groups']); // if no recipients were found, throw an error if (empty($recipients)) { $chkGroups->addError(BL::err('GroupsNoRecipients')); } } // check if at least one language is chosen if (empty($values['languages'])) { $rbtLanguages->isFilled(BL::err('FieldIsRequired')); } // no errors? if ($this->frm->isCorrect()) { // set values $item['name'] = $txtName->getValue(); $item['from_name'] = $txtFromName->getValue(); $item['from_email'] = $txtFromEmail->getValue(); $item['reply_to_email'] = $txtReplyToEmail->getValue(); $item['language'] = $rbtLanguages->getValue(); $item['status'] = 'concept'; $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); $item['edited_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); if (!empty($values['campaign'])) { $item['campaign_id'] = $this->frm->getField('campaign')->getValue(); } // insert the concept $item['id'] = BackendMailmotorModel::insertMailing($item); // update the groups for this mailing BackendMailmotorModel::updateGroupsForMailing($item['id'], $values['groups']); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_mailing_step1', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Edit') . '&id=' . $item['id'] . '&step=2'); } } }
/** * 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 $txtGroup = $this->frm->getField('group'); // validate fields if ($txtGroup->isFilled(BL::err('NameIsRequired'))) { if (BackendMailmotorModel::existsGroupByName($txtGroup->getValue())) { $txtGroup->addError(BL::err('GroupAlreadyExists')); } } // no errors? if ($this->frm->isCorrect()) { // build item $item['name'] = $txtGroup->getValue(); $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); // update the item $item['id'] = BackendMailmotorCMHelper::insertGroup($item); // loop the addresses foreach ($this->statistics['clicked_links_by'][$this->linkURL] as $clicker) { // subscribe the user to the created group BackendMailmotorCMHelper::subscribe($clicker['email'], $item['id']); } // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('StatisticsLink') . '&url=' . $this->linkURL . '&mailing_id=' . $this->mailing['id'] . '&report=group-added&var=' . urlencode($item['name']) . '&highlight=id-' . $this->mailing['id']); } } }
/** * Load the datagrid for unsubscriptions */ private function loadUnsubscriptions() { // get results $results = BackendMailmotorModel::getRecentUnsubscriptions(self::PAGING_LIMIT); // there are some results if (!empty($results)) { $dataGrid = new BackendDataGridArray($results); $dataGrid->setPaging(false); $dataGrid->setColumnFunction(array(new BackendDataGridFunctions(), 'getTimeAgo'), array('[unsubscribed_on]'), 'unsubscribed_on', true); // check if this action is allowed if (BackendAuthentication::isAllowedAction('EditAddress')) { $dataGrid->setColumnURL('email', BackendModel::createURLForAction('EditAddress', 'Mailmotor') . '&email=[email]'); } // parse the datagrid $this->tpl->assign('dgMailmotorUnsubscriptions', $dataGrid->getContent()); } }
/** * Sets a link to the campaign statistics if it contains sent mailings * * @param int $id The ID of the campaign. * @return string */ public static function setStatisticsLink($id) { // build the link HTML $html = '<a href="' . BackendModel::createURLForAction('StatisticsCampaign') . '&id=' . $id . '" class="button icon iconStats linkButton"><span>' . BL::lbl('Statistics') . '</span></a>'; // check if this campaign has sent mailings $hasSentMailings = BackendMailmotorModel::existsSentMailingsByCampaignID($id) > 0 ? true : false; // return the result return $hasSentMailings ? $html : ''; }
/** * Checks if any groups are made yet. Depending on the client that is linked to Fork, it will * create default groups if none were found in CampaignMonitor. If they were, the user is * presented with an overview to import all groups and their subscribers in Fork. */ private function checkForGroups() { // groups are already set if ($this->get('fork.settings')->get('Mailmotor', 'cm_groups_set')) { return false; } // no CM data found if (!BackendMailmotorCMHelper::checkAccount()) { return false; } // check if there are external groups present in CampaignMonitor if ($this->checkForExternalGroups()) { $this->redirect(BackendModel::createURLForAction('ImportGroups', 'Mailmotor')); } // fetch the default groups, language abbreviation is the array key $groups = BackendMailmotorModel::getDefaultGroups(); // loop languages foreach (BL::getActiveLanguages() as $language) { // this language does not have a default group set if (!isset($groups[$language])) { // set group record $group['name'] = 'Website (' . strtoupper($language) . ')'; $group['language'] = $language; $group['is_default'] = 'Y'; $group['created_on'] = date('Y-m-d H:i:s'); try { // insert the group in CampaignMonitor BackendMailmotorCMHelper::insertGroup($group); } catch (\CampaignMonitorException $e) { // ignore } } } // we have groups set, and default groups chosen $this->get('fork.settings')->set('Mailmotor', 'cm_groups_set', true); $this->get('fork.settings')->set('Mailmotor', 'cm_groups_defaults_set', true); }
/** * Validate the form for step 2 */ 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'); } } }
/** * 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(); // no errors? if ($this->frm->isCorrect()) { // the total amount of subscribers $subscribersTotal = 0; // loop all groups foreach ($this->externalGroups as $group) { // insert them in our database $groupID = $this->get('database')->insert('mailmotor_groups', array('name' => $group['name'], 'custom_fields' => $group['custom_fields'], 'created_on' => BackendModel::getUTCDate())); // insert the CM ID BackendMailmotorCMHelper::insertCampaignMonitorID('list', $group['id'], $groupID); // continue looping if this group has no subscribers if (empty($group['subscribers'])) { continue; } // add this groups subscribers amount to the total $subscribersTotal += $group['subscribers_amount']; // loop the subscribers for this group, and import them foreach ($group['subscribers'] as $subscriber) { // build new subscriber record $item = array(); $item['email'] = $subscriber['email']; $item['source'] = 'import'; $item['created_on'] = $subscriber['date']; // add an additional custom field 'name', if it was set in the subscriber record if (!empty($subscriber['name'])) { $subscriber['custom_fields']['Name'] = $subscriber['name']; } // save the subscriber in our database, and subscribe it to this group BackendMailmotorModel::saveAddress($item, $groupID, !empty($subscriber['custom_fields']) ? $subscriber['custom_fields'] : null); } } // at this point, groups are set $this->get('fork.settings')->set($this->getModule(), 'cm_groups_set', true); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_import_groups'); // redirect to the index $this->redirect(BackendModel::createURLForAction('Index', $this->getModule()) . '&report=groups-imported&var[]=' . count($this->externalGroups) . '&var[]=' . $subscribersTotal); } } }