Beispiel #1
0
 /**
  * Save the subscription
  *
  * @return void
  */
 public function save()
 {
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $appl = JFactory::getApplication();
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $chimp = new cmcHelperChimp();
     $input = JFactory::getApplication()->input;
     $form = $input->get('jform', '', 'array');
     $isAjax = $input->get('ajax');
     $mergeVars = CmcHelperList::mergeVars($form);
     $listId = $form['cmc']['listid'];
     $email = $mergeVars['EMAIL'];
     $chimp->listSubscribe($listId, $email, $mergeVars, 'html', true, true, true, false);
     if ($chimp->errorCode) {
         $response['html'] = $chimp->errorMessage;
         $response['error'] = true;
     } else {
         // Get the member info from mailchimp
         $memberInfo = $chimp->listMemberInfo($listId, $email);
         $status = 'applied';
         // User was found on list
         if ($memberInfo['success']) {
             $status = $memberInfo['data'][0]['status'];
         }
         // Check if the subscription is already present in the db
         if (CmcHelperUsers::getSubscription($email, $listId)) {
             $query->update('#__cmc_users')->set(array('list_id = ' . $db->quote($listId), 'email = ' . $db->quote($email), 'merges = ' . $db->quote(json_encode($mergeVars)), 'status = ' . $db->q($status)))->where('list_id = ' . $db->quote($listId))->where('email = ' . $db->quote($email));
             $html = 'updated';
         } else {
             $query->insert('#__cmc_users')->columns('list_id,email,merges,status')->values($db->quote($listId) . ',' . $db->quote($email) . ',' . $db->quote(json_encode($mergeVars)) . ',' . $db->q($status));
             $html = 'saved';
         }
         $db->setQuery($query);
         $db->execute();
         $response['html'] = $html;
         $response['error'] = false;
     }
     if ($isAjax) {
         echo json_encode($response);
         jexit();
     }
     $appl->enqueueMessage($response['html']);
     $appl->redirect($_SERVER['HTTP_REFERER']);
 }
Beispiel #2
0
 /**
  * Sends an email with information how to update the form
  *
  * @return bool
  */
 public function update()
 {
     $appl = JFactory::getApplication();
     $input = $appl->input;
     $listId = $input->getString('listid');
     $email = $input->getString('email');
     $mailer = JFactory::getMailer();
     $chimp = new cmcHelperChimp();
     if (!$listId && !$email) {
         $appl->enqueueMessage(JText::_('COM_CMC_INVALID_LIST_OR_EMAIL'));
         $appl->redirect($_SERVER['HTTP_REFERER']);
         return false;
     }
     $dc = "us1";
     if (strstr($chimp->api_key, "-")) {
         list($key, $dc) = explode("-", $chimp->api_key, 2);
         if (!$dc) {
             $dc = "us1";
         }
     }
     $account = $chimp->getAccountDetails();
     $memberInfo = $chimp->listMemberInfo($listId, $email);
     $listInfo = $chimp->lists(array('list_id' => $listId));
     $url = 'http://' . $account['username'] . '.' . $dc . '.list-manage.com/profile?u=' . $account['user_id'] . '&id=' . $listId . '&e=' . $memberInfo['data'][0]['euid'];
     $subject = JText::sprintf('COM_CMC_CHANGE_YOUR_SUBSCRIPTION_PREFERENCES_EMAIL_TITLE', $listInfo['data'][0]['name']);
     $text = JText::sprintf('COM_CMC_CHANGE_YOUR_SUBSCRIPTION_PREFERENCES_EMAIL_CONTENT', $listInfo['data'][0]['name'], $url);
     $config = JFactory::getConfig();
     if ($mailer->sendMail($config->get('mailfrom'), $config->get('fromname'), $email, $subject, $text, true)) {
         $appl->enqueueMessage(JText::sprintf('COM_CMC_EMAIL_WITH_FURTHER_INSTRUCTIONS_UPDATE', $email));
         $appl->redirect($_SERVER['HTTP_REFERER']);
         return true;
     }
     $appl->enqueueMessage(JText::_('COM_CMC_SOMETHING_WENT_WRONG'));
     $appl->redirect($_SERVER['HTTP_REFERER']);
     return false;
 }