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
 /**
  * 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);
 }
Example #3
0
 /**
  * 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');
         }
     }
 }