/** * Load the form */ private function loadForm() { // create form $this->frm = new BackendForm('add'); // fetch the campaigns $campaigns = BackendMailmotorModel::getCampaignsAsPairs(); // fetch the groups $groupIds = BackendMailmotorModel::getGroupIDs(); $groups = BackendMailmotorModel::getGroupsWithRecipientsForCheckboxes(); // no groups were made yet if (empty($groups) && empty($groupIds)) { $this->redirect(BackendModel::createURLForAction('AddGroup') . '&error=add-mailing-no-groups'); } elseif (empty($groups)) { // groups were made, but none have subscribers $this->redirect(BackendModel::createURLForAction('Addresses') . '&error=no-subscribers'); } // fetch the languages $languages = BackendMailmotorModel::getLanguagesForCheckboxes(); // settings $this->frm->addText('name'); if (count($campaigns) > 1) { $this->frm->addDropdown('campaign', $campaigns); } // sender $this->frm->addText('from_name', $this->get('fork.settings')->get($this->getModule(), 'from_name')); $this->frm->addText('from_email', $this->get('fork.settings')->get($this->getModule(), 'from_email')); // reply-to address $this->frm->addText('reply_to_email', $this->get('fork.settings')->get($this->getModule(), 'reply_to_email')); // groups - if there is only 1 group present, we select it by default $this->frm->addMultiCheckbox('groups', $groups, count($groups) == 1 && isset($groups[0]) ? $groups[0]['value'] : false); // languages $this->frm->addRadiobutton('languages', $languages, BL::getWorkingLanguage()); }
/** * Delete addresses */ private function deleteAddresses() { // no group set if ($this->groupId == '') { $this->groupId = null; } // get all groups $groupIds = BackendMailmotorModel::getGroupIDs(); // loop the emails foreach ($this->emails as $email) { // the group ID is not set if ($this->groupId == null) { // if no groups were set, break here if (empty($groupIds)) { break; } // loop the group IDs foreach ($groupIds as $groupId) { // try to unsubscribe this address try { BackendMailmotorCMHelper::unsubscribe($email, $groupId); } catch (\Exception $e) { // do nothing } } // delete all addresses BackendMailmotorModel::deleteAddresses($email); } else { // group ID was set, unsubscribe the address for this group BackendMailmotorCMHelper::unsubscribe($email, $this->groupId); } } // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete_addresses'); // redirect $this->redirect(BackendModel::createURLForAction('Addresses') . '&report=delete-addresses' . (!empty($this->groupId) ? '&group_id=' . $this->groupId : '')); }