/**
  * Delete addresses
  */
 private function deleteCustomFields()
 {
     // 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 = '';
         }
     }
     // loop the fields
     foreach ($this->fields as $field) {
         // check if the passed field is in the group's field list
         if (isset($groupFields[$field])) {
             // delete the custom field in CM
             BackendMailmotorCMHelper::deleteCustomField('[' . $field . ']', $this->group['id']);
             // remove the field from the group's field listing
             unset($groupFields[$field]);
         }
     }
     // update custom fields for this group
     BackendMailmotorModel::updateCustomFields($groupFields, $this->group['id']);
     // redirect
     $this->redirect(BackendModel::createURLForAction('CustomFields') . '&group_id=' . $this->group['id'] . '&report=deleted-custom-fields&var=' . $this->group['name']);
 }
Example #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();
         // 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']);
         }
     }
 }
Example #3
0
 /**
  * Subscribes an e-mail address and send him/her to CampaignMonitor
  *
  * @param string $email        The emailaddress.
  * @param string $groupId      The group wherein the emailaddress should be added.
  * @param array  $customFields Any optional custom fields.
  * @return bool
  */
 public static function subscribe($email, $groupId = null, $customFields = null)
 {
     $db = BackendModel::getContainer()->get('database');
     $cm = self::getCM();
     $groupId = !empty($groupId) ? $groupId : BackendMailmotorModel::getDefaultGroupID();
     $groupCMId = self::getCampaignMonitorID('list', $groupId);
     // see if the name is present in the custom fields
     $name = self::getNameFieldValue($customFields);
     // group ID found
     if (BackendMailmotorModel::existsGroup($groupId) && $cm->subscribe($email, $name, $customFields, true, $groupCMId)) {
         $subscriber['email'] = $email;
         $subscriber['source'] = 'CMS';
         $subscriber['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s');
         $db->execute('INSERT INTO mailmotor_addresses(email, source, created_on)
                                         VALUES (?, ?, ?)
                                         ON DUPLICATE KEY UPDATE source = ?, created_on = ?', array($subscriber['email'], $subscriber['source'], $subscriber['created_on'], $subscriber['source'], $subscriber['created_on']));
         $subscriberGroup['email'] = $email;
         $subscriberGroup['group_id'] = $groupId;
         $subscriberGroup['status'] = 'subscribed';
         $subscriberGroup['subscribed_on'] = BackendModel::getUTCDate('Y-m-d H:i:s');
         // insert/update the user
         $db->execute('INSERT INTO mailmotor_addresses_groups(email, group_id, status, subscribed_on)
              VALUES (?, ?, ?, ?)
              ON DUPLICATE KEY UPDATE group_id = ?, status = ?, subscribed_on = ?', array($subscriberGroup['email'], $subscriberGroup['group_id'], $subscriberGroup['status'], $subscriberGroup['subscribed_on'], $subscriberGroup['group_id'], $subscriberGroup['status'], $subscriberGroup['subscribed_on']));
         // update custom fields for this subscriber/group
         if (!empty($customFields)) {
             BackendMailmotorModel::updateCustomFields($customFields, $groupId, $email);
         }
         return true;
     }
     return false;
 }