/**
  * 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 {
             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 : ''));
 }
Esempio n. 2
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();
         // get subscriptions
         if (!empty($this->subscriptions)) {
             $ddmGroups = $this->frm->getField('subscriptions');
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['email'] = $this->email;
             $item['groups'] = isset($_POST['groups']) ? $_POST['groups'] : array();
             // loop the fields
             foreach ($this->customFields as $field) {
                 // shorten the field
                 $txtField = $field['formElements']['txtField'];
                 // add the value to the custom fields to store
                 $this->record['custom_fields'][$this->group['id']][$field['label']] = $txtField->getValue();
             }
             /*
              * This is, in fact, an unsubscribe of the subscriber's current groups, and a re-subscribe of the
              * groups he requested. This is done because the CM API supports no updateSubscriber function, and it
              * overwrites the values of custom fields if you do an update for 1 list and don't provide values for another.
              *
              * NOTE: A user will still be in the suppression list if he is resubscribed, but he will receive e-mails.
              * 		 (see: http://www.campaignmonitor.com/forums/viewtopic.php?id=1761)
              */
             // the groups the user is currently subscribed to
             if (!empty($this->record['groups'])) {
                 // loop the groups
                 foreach ($this->record['groups'] as $group) {
                     // Check if this group is in the allowed list. If it is, it should not be unsubscribed
                     if (!empty($item['groups']) && in_array($group, $item['groups'])) {
                         continue;
                     }
                     // unsubscribe the user
                     BackendMailmotorCMHelper::unsubscribe($this->email, $group);
                 }
             }
             // the groups the user wants to keep
             if (!empty($item['groups'])) {
                 // loop the groups
                 foreach ($item['groups'] as $group) {
                     // continue looping if this group has no custom fields
                     $customFields = !empty($this->record['custom_fields'][$group]) ? $this->record['custom_fields'][$group] : null;
                     // resubscribe for this group
                     BackendMailmotorCMHelper::subscribe($this->email, $group, $customFields);
                 }
             }
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_address', array('item' => $this->record));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('addresses') . (!empty($this->subscriptions) ? '&group_id=' . $ddmGroups->getValue() : '') . '&report=edited&var=' . urlencode($item['email']) . '&highlight=email-' . $item['email']);
         }
     }
 }