Esempio n. 1
0
File: send.php Progetto: rodhoff/MNW
 public function ajax_sync_hotness()
 {
     $listId = JRequest::getVar('listId', '', 'post', 'string');
     $total = JRequest::getVar('total', '', 'post', 'string');
     $step = JRequest::getVar('step', '', 'post', 'string');
     $done = JRequest::getVar('done', '', 'post', 'string');
     $errors = JRequest::getVar('errors', '', 'post', 'string');
     $errorMsg = JRequest::getVar('errorMsg', '', 'post', 'string');
     $addedUsers = JRequest::getVar('addedUsers', '', 'post', 'string');
     $failed = JRequest::getVar('failed', array(), 'post', 'string');
     $offset = JRequest::getVar('offset', '', 'post', 'string');
     if ($done == 0) {
         $_SESSION['abortAJAX'] = 0;
         unset($_SESSION['addedUsers']);
         unset($_SESSION['HotnessExists']);
     }
     if ($_SESSION['abortAJAX'] == 1) {
         unset($_SESSION['addedUsers']);
         $response['addedUsers'] = '';
         $response['finished'] = 1;
         $response['abortAJAX'] = 1;
         echo json_encode($response);
         return;
     }
     $db = JFactory::getDBO();
     $MCerrorHandler = new MCerrorHandler();
     // retrieve hotness rating
     require_once JPATH_COMPONENT_ADMINISTRATOR . DS . '/libraries/joomailer/hotActivityComposite.php';
     $composite = new hotActivityComposite();
     $hotnessRating = $composite->getAllUserHotnessValue($listId);
     $exclude = isset($_SESSION['addedUsers']) ? $_SESSION['addedUsers'] : array();
     if (count($exclude)) {
         $failed = array_merge($exclude, $failed);
         $exclude = 'AND j.userid NOT IN ("' . implode('","', $failed) . '") ';
     } else {
         $exclude = '';
     }
     $data = $this->getModel('send')->getMcObject()->listMembers($listId, '', '', $offset, $step);
     if (count($data) > 0) {
         // determine if the interest group Hotness already exists, if not: create it
         if (!isset($_SESSION['HotnessExists'])) {
             $query = $db->getQuery(true)->select($db->qn('value'))->from('#__joomailermailchimpintegration_misc')->where($db->qn('type') . ' = ' . $db->q('hotness'))->where($db->qn('listid') . ' = ' . $db->q($listId));
             $db->setQuery($query);
             $hotnessId = $db->loadResult();
             if ($hotnessId == NULL) {
                 $result = $this->getModel('send')->getMcObject()->listInterestGroupingAdd($listId, JText::_('JM_HOTNESS_RATING'), 'hidden', array(1, 2, 3, 4, 5));
                 if (is_int($result)) {
                     $query = $db->getQuery(true)->insert('#__joomailermailchimpintegration_misc')->set($db->qn('type') . ' = ' . $db->q('hotness'))->set($db->qn('listid') . ' = ' . $db->q($listId))->set($db->qn('value') . ' = ' . $db->q($result));
                     $db->setQuery($query);
                     $db->execute();
                     $_SESSION['HotnessExists'] = $result;
                 }
             } else {
                 $_SESSION['HotnessExists'] = $hotnessId;
             }
         }
         $successCount = 0;
         for ($x = 0; $x < count($data); $x += $step) {
             if ($_SESSION['abortAJAX'] == 1) {
                 unset($_SESSION['addedUsers']);
                 break;
             }
             $k = 0;
             $batch = array();
             for ($y = $x; $y < $x + $step; $y++) {
                 if ($_SESSION['abortAJAX'] == 1) {
                     unset($_SESSION['addedUsers']);
                     break;
                 }
                 $dat = isset($data[$y]) ? $data[$y] : false;
                 if ($dat) {
                     $addedUsers[] = $dat['email'];
                     $batch[$k]['EMAIL'] = $dat['email'];
                     if (!isset($hotnessRating[$dat['email']])) {
                         $hotnessRating[$dat['email']] = 2;
                     }
                     $batch[$k]['GROUPINGS'][] = array('id' => $_SESSION['HotnessExists'], 'groups' => $hotnessRating[$dat['email']]);
                     $k++;
                 } else {
                     break;
                 }
             }
             if ($batch) {
                 $optin = false;
                 //yes, send optin emails
                 $up_exist = true;
                 // yes, update currently subscribed users
                 $replace_int = true;
                 // false = add interest, don't replace
                 $result = $this->getModel('send')->getMcObject()->listBatchSubscribe($listId, $batch, $optin, $up_exist, $replace_int);
                 $successCount += $result['success_count'];
                 if ($result['error_count']) {
                     foreach ($result['errors'] as $e) {
                         $tmp = new stdClass();
                         $tmp->errorCode = $e['code'];
                         $tmp->errorMessage = $e['message'];
                         $errorMsg .= '"' . $MCerrorHandler->getErrorMsg($tmp) . ' => ' . $e['row']['EMAIL'] . '", ';
                     }
                 }
             }
         }
         $addedUsers = array_unique($addedUsers);
         if (!count($data)) {
             $done = $total;
             unset($_SESSION['addedUsers']);
             $percent = 100;
         } else {
             $done = count($addedUsers);
             $_SESSION['addedUsers'] = $addedUsers;
             $percent = $done / $total * 100;
         }
         $response['msg'] = '<div id="bg"></div>' . '<div style="background:#FFFFFF none repeat scroll 0 0;border:10px solid #000000;height:100px;left:37%;position:relative;text-align:center;top:37%;width:300px; ">' . '<div style="margin: 35px auto 3px; width: 300px; text-align: center;">' . JText::_('adding users') . ' (' . $done . '/' . $total . ' ' . JText::_('done') . ')</div>' . '<div style="margin: auto; background: transparent url(' . JURI::root() . 'media/com_joomailermailchimpintegration/backend/images/progress_bar_grey.gif) repeat scroll 0% 0%; width: 190px; height: 14px; display: block;">' . '<div style="width: ' . $percent . '%; overflow: hidden;">' . '<img src="' . JURI::root() . 'media/com_joomailermailchimpintegration/backend/images/progress_bar.gif" style="margin: 0 5px 0 0;"/>' . '</div>' . '<div style="width: 190px; text-align: center; position: relative;top:-13px; font-weight:bold;">' . round($percent, 0) . ' %</div>' . '</div>' . '<a id="sbox-btn-close" style="text-indent:-5000px;right:-20px;top:-18px;outline:none;" href="javascript:void(0);joomlamailerJS.sync.abortAJAX(true);">abort</a>' . '</div>';
         $response['done'] = $done;
         $response['errors'] = count($failed);
         $response['errorMsg'] = $errorMsg;
         $response['addedUsers'] = array_values(array_unique($addedUsers));
         if ($done + count($failed) + $errors >= $total) {
             $response['finished'] = 1;
             $msg = $done . ' ' . JText::_('JM_USERS_SYNCHRONIZED') . '.';
             if ($errorMsg) {
                 $errorMsg = substr($errorMsg, 0, -2);
                 $msg .= ' (' . count($failed) . ' ' . JText::_('Errors') . ': ' . $errorMsg . ')';
             }
             $response['finalMessage'] = $msg;
         } else {
             $response['finished'] = 0;
             $response['finalMessage'] = '';
         }
         $response['abortAJAX'] = $_SESSION['abortAJAX'];
     } else {
         unset($_SESSION['addedUsers']);
         $response['addedUsers'] = '';
         $response['finalMessage'] = JText::_('JM_NO_USERS_FOUND');
         $response['finished'] = 1;
         $response['abortAJAX'] = $_SESSION['abortAJAX'];
     }
     echo json_encode($response);
 }
Esempio n. 2
0
 public function resubscribe()
 {
     $params = JComponentHelper::getParams('com_joomailermailchimpintegration');
     $MCapi = $params->get('params.MCapi');
     $MC = new joomlamailerMCAPI($MCapi);
     $listId = JRequest::getVar('listid', 0, 'post', 'string');
     $emails = JRequest::getVar('emails', array(), 'post', 'array');
     $i = 0;
     if (isset($emails[0]) && $listId) {
         foreach ($emails as $email) {
             $memberInfo = $MC->listMemberInfo($listId, $email);
             $resubscribe = $MC->listSubscribe($listId, $email, $memberInfo, $memberInfo['email_type'], false, true, false, false);
             if (!$MC->errorCode) {
                 $i++;
             }
         }
     }
     if ($MC->errorCode) {
         $msg = MCerrorHandler::getErrorMsg($MC);
     } else {
         $msg = $i . ' ' . JText::_('JM_USER_RESUBSCRIBED');
     }
     $this->setRedirect('index.php?option=com_joomailermailchimpintegration&view=lists', $msg);
 }
Esempio n. 3
0
File: sync.php Progetto: rodhoff/MNW
 public function ajaxSyncAll()
 {
     $done = JRequest::getVar('done', '', 'POST', 'int');
     if ($done == 0) {
         $_SESSION['abortAJAX'] = 0;
         unset($_SESSION['addedUsers']);
     }
     if ($_SESSION['abortAJAX'] != 1) {
         $db = JFactory::getDBO();
         $params = JComponentHelper::getParams('com_joomailermailchimpintegration');
         $MCapi = $params->get('params.MCapi');
         $MC = new joomlamailerMCAPI($MCapi);
         $MCerrorHandler = new MCerrorHandler();
         $listId = JRequest::getVar('listId', '', 'POST', 'string');
         $total = JRequest::getVar('total', 0, 'POST', 'int');
         $errors = JRequest::getVar('errors', 0, 'POST', 'int');
         $step = JRequest::getVar('step', 100, 'POST', 'int');
         $failed = JRequest::getVar('failed', array(), 'POST');
         $addedUsers = JRequest::getVar('addedUsers', array(), 'POST');
         $errorMsg = JRequest::getVar('errorMsg', '', 'POST', 'string');
         if (!$addedUsers) {
             $addedUsers = array();
         }
         // create hidden signup date merge var if it doesn't exist
         $createSignupdateMerge = true;
         $mergeVars = $MC->listMergeVars($listId);
         foreach ($mergeVars as $mv) {
             if ($mv['tag'] == 'SIGNUPAPI') {
                 $createSignupdateMerge = false;
                 break;
             }
         }
         if ($createSignupdateMerge) {
             $MC->listMergeVarAdd($listId, 'SIGNUPAPI', 'date added (API)', array('date', false, false, true));
         }
         if (isset($_SESSION['addedUsers'])) {
             $exclude = $_SESSION['addedUsers'];
         } else {
             $exclude = array();
         }
         if (!$failed) {
             $failed = array();
         }
         if (count($failed)) {
             $exclude = array_merge($exclude, $failed);
         }
         $query = $db->getQuery(true)->select($db->qn(array('id', 'email')))->from($db->qn('#__users'))->where($db->qn('block') . ' = ' . $db->q(0))->where($db->qn('id') . ' NOT IN ("' . implode('","', $exclude) . '")');
         $db->setQuery($query, 0, $step);
         $users = $db->loadObjectList();
         $userIds = array();
         foreach ($users as $user) {
             $userIds[$user->email] = $user->id;
         }
         // gather custom fields data
         $query = $db->getQuery(true)->select('*')->from($db->qn('#__joomailermailchimpintegration_custom_fields'))->where($db->qn('listid') . ' = ' . $db->q($listId));
         $db->setQuery($query);
         $customFields = $db->loadObjectList();
         $m = $successCount = $errorcount = $msgErrorsCount = $counter = 0;
         $msg = $msgErrors = false;
         $ids = '';
         for ($x = 0; $x < count($users); $x += $step) {
             if ($_SESSION['abortAJAX'] == 1) {
                 unset($_SESSION['addedUsers']);
                 break;
             }
             $k = $errorcount = $msgErrorsCount = 0;
             $batch = array();
             for ($y = $x; $y < $x + $step; $y++) {
                 if ($_SESSION['abortAJAX'] == 1) {
                     unset($_SESSION['addedUsers']);
                     break;
                 }
                 $dat = isset($users[$y]) ? $users[$y] : false;
                 if ($dat) {
                     $user = $this->getModel('sync')->getUser($dat->id);
                     $addedUsers[] = $user[0]->id;
                     $batch[$k]['EMAIL'] = $user[0]->email;
                     // name
                     $names = explode(' ', $user[0]->name);
                     if (isset($names[0]) && isset($names[1])) {
                         $batch[$k]['FNAME'] = $names[0];
                         $batch[$k]['LNAME'] = '';
                         for ($i = 1; $i < count($names); $i++) {
                             $batch[$k]['LNAME'] .= $names[$i] . ' ';
                         }
                     } else {
                         $batch[$k]['FNAME'] = $user[0]->name;
                     }
                     if (count($customFields)) {
                         foreach ($customFields as $field) {
                             $query = $db->getQuery(true);
                             if ($field->framework == 'CB') {
                                 $query->select($db->qn($field->dbfield))->from($db->qn('#__comprofiler'))->where($db->qn('user_id') . ' = ' . $db->q($user[0]->id));
                             } else {
                                 $query->select($db->qn('value'))->from($db->qn('#__community_fields_values'))->where($db->qn('field_id') . ' = ' . $db->q($field->dbfield))->where($db->qn('user_id') . ' = ' . $db->q($user[0]->id));
                             }
                             $db->setQuery($query);
                             $fieldValue = $db->loadResult();
                             if ($field->framework == 'CB') {
                                 $fieldValue = str_replace('|*|', ',', $fieldValue);
                             }
                             if ($field->framework == 'JS') {
                                 if ($fieldValue == NULL) {
                                     $fieldValue = '';
                                 } else {
                                     $fieldValue = substr($fieldValue, strlen($fieldValue) - 1) == ',' ? $fieldValue = substr($fieldValue, 0, -1) : $fieldValue;
                                 }
                             }
                             if ($field->type == 'group') {
                                 $batch[$k]['GROUPINGS'][] = array('id' => $field->grouping_id, 'groups' => $fieldValue);
                             } else {
                                 $batch[$k][$field->grouping_id] = $fieldValue;
                             }
                         }
                     }
                     // add signup date
                     $batch[$k]['SIGNUPAPI'] = date('Y-m-d');
                     $query = $db->getQuery(true);
                     try {
                         $query->insert($db->qn('#__joomailermailchimpintegration'))->set($db->qn('userid') . ' = ' . $db->q($user[0]->id))->set($db->qn('email') . ' = ' . $db->q($user[0]->email))->set($db->qn('listid') . ' = ' . $db->q($listId));
                         $db->setQuery($query);
                         $db->execute();
                     } catch (Exception $e) {
                     }
                     $k++;
                 } else {
                     break;
                 }
             }
             if ($batch) {
                 $optin = false;
                 // do not send optin emails
                 $updateExisting = true;
                 // yes, update currently subscribed users
                 $replaceInterests = true;
                 // false = add interest, don't replace
                 $result = $MC->listBatchSubscribe($listId, $batch, $optin, $updateExisting, $replaceInterests);
                 $successCount = $successCount + $result['success_count'];
                 if ($result['error_count']) {
                     foreach ($result['errors'] as $e) {
                         $tmp = new stdClass();
                         $tmp->errorCode = $e['code'];
                         $tmp->errorMessage = $e['message'];
                         $errorMsg .= '"' . $MCerrorHandler->getErrorMsg($tmp) . ' => ' . $e['row']['EMAIL'] . '", ';
                         $query->getQuery(true);
                         $query->delete($db->qn('#__joomailermailchimpintegration'))->where($db->qn('listid') . ' = ' . $db->q($listId))->where($db->qn('email') . ' = ' . $db->q($e['row']['EMAIL']));
                         $db->setQuery($query, 0, 1);
                         $db->execute();
                         $addedUsers = array_diff($addedUsers, array($userIds[$e['row']['EMAIL']]));
                         $failed[] = $userIds[$e['row']['EMAIL']];
                         $errorcount++;
                     }
                     $msgErrorsCount += $result['error_count'];
                 }
             }
         }
         if (!count($users)) {
             $done = $total;
             unset($_SESSION['addedUsers']);
             $percent = 100;
         } else {
             $done = count($addedUsers);
             $_SESSION['addedUsers'] = $addedUsers;
             $percent = $done / $total * 100;
         }
         $response['msg'] = '<div id="bg"></div>' . '<div id="progressBarContainer">' . '<div id="progressBarTitle">' . JText::_('JM_ADDING_USERS') . ' (' . $done . '/' . $total . ' ' . JText::_('JM_DONE') . ')</div>' . '<div id="progressBarBg">' . '<div id="progressBarCompleted" style="width: ' . round($percent) . '%;"></div>' . '<div id="progressBarNumber">' . round($percent) . ' %</div>' . '</div>' . '<a id="sbox-btn-close" href="javascript:joomlamailerJS.sync.abortAJAX();">abort</a>' . '</div>';
         $response['done'] = $done;
         //	$msg = $successCount.' '.JText::_('JM_RECIPIENTS_SAVED').$msgErrors;
         $response['errors'] = count($failed);
         $response['errorMsg'] = $errorMsg;
         $response['addedUsers'] = array_values($addedUsers);
         $response['failed'] = $failed;
         if ($done + count($failed) + $errors >= $total) {
             $response['finished'] = 1;
             if ($errorMsg) {
                 $errorMsg = substr($errorMsg, 0, -2);
                 $msgErrors = ' (' . count($failed) . ' ' . JText::_('JM_ERRORS') . ': ' . $errorMsg . ')';
             }
             if (!$msg) {
                 $msg = $done . ' ' . JText::_('JM_RECIPIENTS_SAVED');
             }
             if ($msgErrors) {
                 $msg .= $msgErrors;
             }
             $response['finalMessage'] = $msg;
         } else {
             $response['finished'] = 0;
             $response['finalMessage'] = '';
         }
         $response['abortAJAX'] = $_SESSION['abortAJAX'];
         echo json_encode($response);
     } else {
         unset($_SESSION['addedUsers']);
         $response['finished'] = 1;
         $response['addedUsers'] = '';
         $response['abortAJAX'] = $_SESSION['abortAJAX'];
         echo json_encode($response);
     }
 }
 function remove()
 {
     $cid = JRequest::getVar('cid', '', 'post', 'array');
     $status = JRequest::getVar('filter_status', '', 'post', 'string');
     if (!$cid) {
         $msg = JText::_('JM_INVALID_CAMPAIGNID');
         $error = 'error';
     } else {
         $params =& JComponentHelper::getParams('com_joomailermailchimpintegration');
         $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : '';
         $error = '';
         if ($status == 'save') {
             jimport('joomla.filesystem.file');
             jimport('joomla.client.helper');
             JClientHelper::setCredentialsFromRequest('ftp');
             $archiveDir = $params->get($paramsPrefix . 'archiveDir', '/administrator/components/com_joomailermailchimpintegration/archive');
             $path = JPATH_SITE . $archiveDir . '/';
             foreach ($cid as $c) {
                 $db =& JFactory::getDBO();
                 $query = "SELECT name FROM #__joomailermailchimpintegration_campaigns WHERE creation_date = " . $c;
                 $db->setQuery($query);
                 $cName = $db->loadResult();
                 $cName = str_replace(' ', '_', $cName);
                 $cName = htmlentities($cName);
                 if (!JFile::delete($path . $cName . '.html') || !JFile::delete($path . $cName . '.txt')) {
                     $msg = JText::_('JM_DELETE_FAILED');
                     $error = 'error';
                 } else {
                     $query = "DELETE FROM #__joomailermailchimpintegration_campaigns WHERE creation_date = " . $c;
                     $db->setQuery($query);
                     $db->query();
                 }
             }
         } else {
             $MCapi = $params->get($paramsPrefix . 'MCapi');
             $MC = new joomlamailerMCAPI($MCapi);
             $MCerrorHandler = new MCerrorHandler();
             foreach ($cid as $c) {
                 $result = $MC->campaignDelete($c);
                 if (!$result) {
                     $msg = $MCerrorHandler->getErrorMsg($MC);
                     $error = 'error';
                     break;
                 }
             }
         }
         if (!$error) {
             if ($status == 'save') {
                 $msg = JText::_('JM_DRAFT_DELETED');
             } else {
                 $msg = JText::_('JM_CAMPAIGNS_DELETED');
             }
             $error = '';
         }
     }
     $link = 'index.php?option=com_joomailermailchimpintegration&view=campaignlist&filter_status=' . JRequest::getVar('type', 'sent');
     $this->setRedirect($link, $msg, $error);
 }
 function remove()
 {
     $db =& JFactory::getDBO();
     $MC = $this->MC_object();
     $listid = JRequest::getVar('listid', 0, '', 'string');
     $listName = JRequest::getVar('listName', 0, '', 'string');
     $cid = JRequest::getVar('cid', 0, '', 'array');
     foreach ($cid as $id) {
         $delete = $MC->listInterestGroupingDel($id);
         // remove field association from J! db
         $db =& JFactory::getDBO();
         $query = "DELETE FROM #__joomailermailchimpintegration_custom_fields WHERE grouping_id = '" . $id . "' LIMIT 1";
         $db->setQuery($query);
         $db->Query();
         if ($delete->errorCode) {
             $msg = MCerrorHandler::getErrorMsg($MC);
             $msgType = 'error';
             break;
         } else {
             $msg = JText::_('JM_CUSTOM_FIELD_DELETED');
             $msgType = '';
         }
     }
     $this->setRedirect('index.php?option=com_joomailermailchimpintegration&view=groups&listid=' . $listid . '&name=' . $listName, $msg, $msgType);
 }
Esempio n. 6
0
 public function remove()
 {
     $cid = JRequest::getVar('cid', '', 'post', 'array');
     $status = JRequest::getVar('filter_status', '', 'post', 'string');
     $msg = $status == 'save' ? JText::_('JM_DRAFT_DELETED') : JText::_('JM_CAMPAIGNS_DELETED');
     $msgType = 'message';
     if (!$cid) {
         $msg = JText::_('JM_INVALID_CAMPAIGNID');
         $msgType = 'error';
     } else {
         if ($status == 'save') {
             jimport('joomla.filesystem.file');
             jimport('joomla.client.helper');
             JClientHelper::setCredentialsFromRequest('ftp');
             $params = JComponentHelper::getParams('com_joomailermailchimpintegration');
             $archiveDir = $params->get('params.archiveDir', '/administrator/components/com_joomailermailchimpintegration/archive');
             $path = JPATH_SITE . $archiveDir . '/';
             foreach ($cid as $c) {
                 $db = JFactory::getDBO();
                 $query = $db->getQuery(true);
                 $query->select($db->qn('name'))->from('#__joomailermailchimpintegration_campaigns')->where($db->qn('creation_date') . ' = ' . $db->q($c));
                 $db->setQuery($query);
                 $cName = $db->loadResult();
                 $cName = str_replace(' ', '_', $cName);
                 $cName = htmlentities($cName);
                 if (JFile::exists($path . $cName . '.html') && !JFile::delete($path . $cName . '.html') || JFile::exists($path . $cName . '.txt') && !JFile::delete($path . $cName . '.txt')) {
                     $msg = JText::_('JM_DELETE_FAILED');
                     $error = 'error';
                 } else {
                     $query = $db->getQuery(true);
                     $query->delete('#__joomailermailchimpintegration_campaigns')->where($db->qn('creation_date') . ' = ' . $db->q($c));
                     $db->setQuery($query);
                     $db->execute();
                 }
             }
         } else {
             $MCerrorHandler = new MCerrorHandler();
             foreach ($cid as $c) {
                 $result = $this->getModel('campaignlist')->getMcObject()->campaignDelete($c);
                 if (!$result) {
                     $msg = $MCerrorHandler->getErrorMsg($this->getModel('campaignlist')->getMcObject());
                     $msgType = 'error';
                     break;
                 }
             }
         }
     }
     if ($msgType != 'error') {
         $this->getModel('main')->purgeCache();
     }
     $link = 'index.php?option=com_joomailermailchimpintegration&view=campaignlist&filter_status=' . JRequest::getVar('type', 'sent');
     $this->app->enqueueMessage($msg, $msgType);
     $this->app->redirect($link);
 }
 /**
  * remove record(s)
  * @return void
  */
 function remove()
 {
     $db =& JFactory::getDBO();
     $MC = $this->MC_object();
     $listid = JRequest::getVar('listid', 0, '', 'string');
     $cid = JRequest::getVar('cid', 0, '', 'array');
     foreach ($cid as $id) {
         $attribs = explode(';', $id);
         $tag = $attribs[1];
         $delete = $MC->listMergeVarDel($listid, $tag);
         // remove field association from J! db
         $db =& JFactory::getDBO();
         $query = "DELETE FROM #__joomailermailchimpintegration_custom_fields WHERE grouping_id = '" . $tag . "' LIMIT 1";
         $db->setQuery($query);
         $db->Query();
         if ($delete->errorCode) {
             $msg = MCerrorHandler::getErrorMsg($MC);
             $msgType = 'error';
             break;
         } else {
             $msg = JText::_('JM_MERGE_FIELDS_DELETED');
             $msgType = '';
         }
     }
     $this->setRedirect('index.php?option=com_joomailermailchimpintegration&view=fields&listid=' . $listid, $msg, $msgType);
 }
Esempio n. 8
0
 function ajax_sync_hotness()
 {
     $elements = JRequest::getVar('elements', '', 'request', 'string');
     $elements = json_decode($elements);
     if ($elements->done == 0) {
         $_SESSION['abortAJAX'] = 0;
         unset($_SESSION['addedUsers']);
         unset($_SESSION['HotnessExists']);
     }
     if ($_SESSION['abortAJAX'] != 1) {
         $db =& JFactory::getDBO();
         $model =& $this->getModel('sync');
         $params =& JComponentHelper::getParams('com_joomailermailchimpintegration');
         $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : '';
         $MCapi = $params->get($paramsPrefix . 'MCapi');
         $MC = new joomlamailerMCAPI($MCapi);
         $MCerrorHandler = new MCerrorHandler();
         $list_id = $elements->listid;
         $step = $elements->step;
         $offset = $elements->offset;
         // retrieve hotness rating
         require_once JPATH_COMPONENT_ADMINISTRATOR . DS . '/libraries/joomailer/hotActivityComposite.php';
         $composite = new hotActivityComposite();
         $hotnessRating = $composite->getAllUserHotnessValue($list_id);
         if (isset($_SESSION['addedUsers'])) {
             $exclude = $_SESSION['addedUsers'];
         } else {
             $exclude = array();
         }
         if (!$elements->failed) {
             $elements->failed = array();
         }
         $exclude = array_merge($exclude, $elements->failed);
         $exclude = implode('","', $exclude);
         $exclude = '"' . $exclude . '"';
         if (isset($exclude[0])) {
             $exclude = 'AND j.userid NOT IN (' . $exclude . ') ';
         } else {
             $exclude = '';
         }
         //		$data = array();
         //		$run = true;
         //		$page = 0;
         //		while($run){
         //		    $result = $MC->listMembers( $list_id, '', '', $page, '15000');
         //		    $page++;
         //		    if($result){
         //			$run = true;
         //			$data = array_merge($data, $result);
         //		    } else {
         //			$run = false;
         //		    }
         //		}
         $data = $MC->listMembers($list_id, '', '', $offset, $step);
         if (count($data) > 0) {
             // determine if the interest group Hotness already exists, if not: create it
             if (!isset($_SESSION['HotnessExists'])) {
                 $query = "SELECT value FROM #__joomailermailchimpintegration_misc WHERE type = 'hotness' AND listid = '" . $list_id . "' ";
                 $db->setQuery($query);
                 $hotnessId = $db->loadResult();
                 if ($hotnessId == NULL) {
                     $result = $MC->listInterestGroupingAdd($list_id, JText::_('JM_HOTNESS_RATING'), 'hidden', array(1, 2, 3, 4, 5));
                     if (is_int($result)) {
                         $query = "INSERT INTO #__joomailermailchimpintegration_misc (type, listid, value) VALUES ('hotness', '" . $list_id . "', '" . $result . "') ";
                         $db->setQuery($query);
                         $db->query();
                         $_SESSION['HotnessExists'] = $result;
                     }
                 } else {
                     $_SESSION['HotnessExists'] = $hotnessId;
                 }
             }
             /*
             		    $userIds = array();
             		    foreach($data as $dat){
             			$userIds[$dat->email] = $dat->id;
             		    }
             */
             $addedUsers = $elements->addedUsers;
             $m = 0;
             $successCount = 0;
             $errorcount = $msgErrorsCount = 0;
             $msg = $msgErrors = false;
             $counter = 0;
             $ids = '';
             $errorMsg = $elements->errorMsg;
             for ($x = 0; $x < count($data); $x += $step) {
                 if ($_SESSION['abortAJAX'] == 1) {
                     unset($_SESSION['addedUsers']);
                     break;
                 }
                 $k = 0;
                 $batch = array();
                 $errorcount = $msgErrorsCount = 0;
                 for ($y = $x; $y < $x + $step; $y++) {
                     if ($_SESSION['abortAJAX'] == 1) {
                         unset($_SESSION['addedUsers']);
                         break;
                     }
                     if (isset($data[$y])) {
                         $dat = $data[$y];
                     } else {
                         $dat = false;
                     }
                     if ($dat) {
                         $addedUsers[] = $dat['email'];
                         $batch[$k]['EMAIL'] = $dat['email'];
                         if (!isset($hotnessRating[$dat['email']])) {
                             $hotnessRating[$dat['email']] = 2;
                         }
                         $batch[$k]['GROUPINGS'][] = array('id' => $_SESSION['HotnessExists'], 'groups' => $hotnessRating[$dat['email']]);
                         $k++;
                     } else {
                         break;
                     }
                 }
                 if ($batch) {
                     $optin = false;
                     //yes, send optin emails
                     $up_exist = true;
                     // yes, update currently subscribed users
                     $replace_int = true;
                     // false = add interest, don't replace
                     $result = $MC->listBatchSubscribe($list_id, $batch, $optin, $up_exist, $replace_int);
                     $successCount = $successCount + $result['success_count'];
                     if ($result['error_count']) {
                         foreach ($result['errors'] as $e) {
                             $tmp = new stdClass();
                             $tmp->errorCode = $e['code'];
                             $tmp->errorMessage = $e['message'];
                             $errorMsg .= '"' . $MCerrorHandler->getErrorMsg($tmp) . ' => ' . $e['row']['EMAIL'] . '", ';
                             //  $addedUsers = array_diff($addedUsers, array($userIds[$e['row']['EMAIL']]));
                             //  $elements->failed[] = $userIds[$e['row']['EMAIL']];
                             $errorcount++;
                         }
                         $msgErrorsCount += $result['error_count'];
                     }
                 }
             }
             $addedUsers = array_unique($addedUsers);
             if (!count($data)) {
                 $done = $elements->total;
                 unset($_SESSION['addedUsers']);
                 $percent = 100;
             } else {
                 $done = count($addedUsers);
                 $_SESSION['addedUsers'] = $addedUsers;
                 $percent = $done / $elements->total * 100;
             }
             $response['msg'] = '<div id="bg"></div>' . '<div style="background:#FFFFFF none repeat scroll 0 0;border:10px solid #000000;height:100px;left:37%;position:relative;text-align:center;top:37%;width:300px; ">' . '<div style="margin: 35px auto 3px; width: 300px; text-align: center;">' . JText::_('adding users') . ' ( ' . $done . '/' . $elements->total . ' ' . JText::_('done') . ' )</div>' . '<div style="margin: auto; background: transparent url(' . JURI::root() . 'administrator/components/com_joomailermailchimpintegration/assets/images/progress_bar_grey.gif) repeat scroll 0% 0%; width: 190px; height: 14px; display: block;">' . '<div style="width: ' . $percent . '%; overflow: hidden;">' . '<img src="' . JURI::root() . 'administrator/components/com_joomailermailchimpintegration/assets/images/progress_bar.gif" style="margin: 0 5px 0 0;"/>' . '</div>' . '<div style="width: 190px; text-align: center; position: relative;top:-13px; font-weight:bold;">' . round($percent, 0) . ' %</div>' . '</div>' . '<a id="sbox-btn-close" style="text-indent:-5000px;right:-20px;top:-18px;outline:none;" href="javascript:abortAJAXnoRefresh();">abort</a>' . '</div>';
             $response['done'] = $done;
             $response['errors'] = count($elements->failed);
             $response['errorMsg'] = $errorMsg;
             $response['addedUsers'] = array_values(array_unique($addedUsers));
             //	    $response['failed']	    = $elements->failed;
             if ($done + count($elements->failed) + $elements->errors >= $elements->total) {
                 $response['finished'] = 1;
                 if ($errorMsg) {
                     $errorMsg = substr($errorMsg, 0, -2);
                     $msgErrors = ' ( ' . count($elements->failed) . ' ' . JText::_('Errors') . ': ' . $errorMsg . ' )';
                 }
                 if (!$msg) {
                     $msg = $done . ' ' . JText::_('JM_USERS_SYNCHRONIZED') . '.';
                 }
                 if ($msgErrors) {
                     $msg .= $msgErrors;
                 }
                 $response['finalMessage'] = $msg;
             } else {
                 $response['finished'] = 0;
                 $response['finalMessage'] = '';
             }
             $response['abortAJAX'] = $_SESSION['abortAJAX'];
         } else {
             unset($_SESSION['addedUsers']);
             $response['addedUsers'] = '';
             $response['finalMessage'] = JText::_('JM_NO_USERS_FOUND');
             $response['finished'] = 1;
             $response['abortAJAX'] = $_SESSION['abortAJAX'];
         }
         echo json_encode($response);
     } else {
         unset($_SESSION['addedUsers']);
         $response['addedUsers'] = '';
         $response['finished'] = 1;
         $response['abortAJAX'] = $_SESSION['abortAJAX'];
         echo json_encode($response);
     }
 }
Esempio n. 9
0
 public function remove()
 {
     $db = JFactory::getDBO();
     $listid = JRequest::getVar('listid', 0, '', 'string');
     $cid = JRequest::getVar('cid', 0, '', 'array');
     foreach ($cid as $id) {
         $attribs = explode(';', $id);
         $tag = $attribs[1];
         $this->getModel('fields')->getMcObject()->listMergeVarDel($listid, $tag);
         if ($this->getModel('fields')->getMcObject()->errorCode) {
             $msg = MCerrorHandler::getErrorMsg($this->getModel('fields')->getMcObject());
             $msgType = 'error';
             break;
         } else {
             // remove field association from J! db
             $query = $db->getQuery(true)->delete($db->qn('#__joomailermailchimpintegration_custom_fields'))->where($db->qn('grouping_id') . ' = ' . $db->q($tag));
             $db->setQuery($query);
             try {
                 $db->execute();
                 $msg = JText::_('JM_MERGE_FIELDS_DELETED');
                 $msgType = 'message';
             } catch (Exception $e) {
                 $msg = $e->getMessage();
                 $msgType = 'error';
                 break;
             }
         }
     }
     $link = 'index.php?option=com_joomailermailchimpintegration&view=fields&listid=' . $listid;
     $this->app->enqueueMessage($msg, $msgType);
     $this->app->redirect($link);
 }
 function resubscribe()
 {
     $params =& JComponentHelper::getParams('com_joomailermailchimpintegration');
     $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : '';
     $MCapi = $params->get($paramsPrefix . 'MCapi');
     $MC = new joomlamailerMCAPI($MCapi);
     $listId = JRequest::getVar('listid', 0, 'post', 'string');
     $emails = JRequest::getVar('emails', array(), 'post', 'array');
     $i = 0;
     if (isset($emails[0]) && $listId) {
         foreach ($emails as $email) {
             $email = explode(';', $email);
             $memberInfo = $MC->listMemberInfo($listId, $email[0]);
             $resubscribe = $MC->listSubscribe($listId, $email[0], $memberInfo, $memberInfo['email_type'], false, true, false, false);
             if (!$MC->errorCode) {
                 $i++;
             }
         }
     }
     if ($MC->errorCode) {
         $msg = MCerrorHandler::getErrorMsg($MC);
     } else {
         $msg = $i . ' ' . JText::_('JM_USER_RESUBSCRIBED');
     }
     $link = 'index.php?option=com_joomailermailchimpintegration&view=joomailermailchimpintegrations';
     $this->setRedirect($link, $msg);
 }
Esempio n. 11
0
 function ajax_sync_all()
 {
     //		jimport( 'joomla.html.html.behavior' );
     //		JHTMLBehavior::keepalive();
     $elements = JRequest::getVar('elements', '', 'request', 'string');
     $elements = json_decode($elements);
     if ($elements->done == 0) {
         $_SESSION['abortAJAX'] = 0;
         unset($_SESSION['addedUsers']);
     }
     if ($_SESSION['abortAJAX'] != 1) {
         $params =& JComponentHelper::getParams('com_joomailermailchimpintegration');
         $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : '';
         $MCapi = $params->get($paramsPrefix . 'MCapi');
         $MC = new joomlamailerMCAPI($MCapi);
         $MCerrorHandler = new MCerrorHandler();
         $list_id = $elements->listid;
         $step = $elements->step;
         $db =& JFactory::getDBO();
         $model =& $this->getModel('sync');
         if (isset($_SESSION['addedUsers'])) {
             $exclude = $_SESSION['addedUsers'];
         } else {
             $exclude = array();
         }
         if (!$elements->failed) {
             $elements->failed = array();
         }
         $exclude = array_merge($exclude, $elements->failed);
         $exclude = implode('","', $exclude);
         $exclude = '"' . $exclude . '"';
         $query = 'SELECT id,email FROM #__users WHERE id NOT IN (' . $exclude . ') AND block = 0 LIMIT ' . $step;
         $db->setQuery($query);
         $data = $db->loadObjectList();
         $userIds = array();
         foreach ($data as $dat) {
             $userIds[$dat->email] = $dat->id;
         }
         // gather custom fields data
         $db =& JFactory::getDBO();
         $query = "SELECT * FROM #__joomailermailchimpintegration_custom_fields WHERE listid = '" . $list_id . "' ";
         $db->setQuery($query);
         $custom_fields = $db->loadObjectList();
         if (!isset($custom_fields[0])) {
             $custom_fields = false;
         }
         $addedUsers = $elements->addedUsers;
         $m = 0;
         $successCount = 0;
         $errorcount = $msgErrorsCount = 0;
         $msg = $msgErrors = false;
         $counter = 0;
         $ids = '';
         $errorMsg = $elements->errorMsg;
         //	foreach ($data as $dat){
         for ($x = 0; $x < count($data); $x += $step) {
             if ($_SESSION['abortAJAX'] == 1) {
                 unset($_SESSION['addedUsers']);
                 break;
             }
             $k = 0;
             $batch = array();
             $errorcount = $msgErrorsCount = 0;
             for ($y = $x; $y < $x + $step; $y++) {
                 if ($_SESSION['abortAJAX'] == 1) {
                     unset($_SESSION['addedUsers']);
                     break;
                 }
                 if (isset($data[$y])) {
                     $dat = $data[$y];
                 } else {
                     $dat = false;
                 }
                 if ($dat) {
                     $user = $model->getUser($dat->id);
                     $addedUsers[] = $user[0]->id;
                     $batch[$k]['EMAIL'] = $user[0]->email;
                     // name
                     $names = explode(' ', $user[0]->name);
                     if (isset($names[0]) && isset($names[1])) {
                         $batch[$k]['FNAME'] = $names[0];
                         $batch[$k]['LNAME'] = '';
                         for ($i = 1; $i < count($names); $i++) {
                             $batch[$k]['LNAME'] .= $names[$i] . ' ';
                         }
                     } else {
                         $batch[$k]['FNAME'] = $user[0]->name;
                     }
                     $custom = array();
                     if ($custom_fields) {
                         foreach ($custom_fields as $field) {
                             if ($field->framework == 'CB') {
                                 $query = "SELECT " . $field->dbfield . " FROM #__comprofiler WHERE user_id = '" . $user[0]->id . "' ";
                             } else {
                                 $query = "SELECT value FROM #__community_fields_values WHERE field_id = " . $field->dbfield . " AND user_id = '" . $user[0]->id . "' ";
                             }
                             $db->setQuery($query);
                             $field_value = $db->loadResult();
                             if ($field->framework == 'CB') {
                                 $field_value = str_replace('|*|', ',', $field_value);
                             }
                             if ($field->framework == 'JS') {
                                 $field_value = substr($field_value, strlen($field_value) - 1) == ',' ? $field_value = substr($field_value, 0, -1) : $field_value;
                                 if ($field_value == NULL) {
                                     $field_value = '';
                                 }
                             }
                             if ($field->type == 'group') {
                                 $batch[$k]['GROUPINGS'][] = array('id' => $field->grouping_id, 'groups' => $field_value);
                             } else {
                                 $batch[$k][$field->grouping_id] = $field_value;
                             }
                             //	$batch[$k]['GROUPINGS'][] = array( 'id' => (int)$field->grouping_id, 'groups' => $field_value);
                         }
                     }
                     $query = 'INSERT INTO #__joomailermailchimpintegration (userid,email,listid) VALUES ("' . $user[0]->id . '", "' . $user[0]->email . '", "' . $list_id . '")';
                     $db->setQuery($query);
                     $db->query();
                     $k++;
                 } else {
                     break;
                 }
             }
             if ($batch) {
                 $optin = false;
                 //yes, send optin emails
                 $up_exist = true;
                 // yes, update currently subscribed users
                 $replace_int = true;
                 // false = add interest, don't replace
                 //				    var_dump($batch);die;
                 $result = $MC->listBatchSubscribe($list_id, $batch, $optin, $up_exist, $replace_int);
                 $successCount = $successCount + $result['success_count'];
                 if ($result['error_count']) {
                     foreach ($result['errors'] as $e) {
                         $tmp = new stdClass();
                         $tmp->errorCode = $e['code'];
                         $tmp->errorMessage = $e['message'];
                         $errorMsg .= '"' . $MCerrorHandler->getErrorMsg($tmp) . ' => ' . $e['row']['EMAIL'] . '", ';
                         $query = 'DELETE FROM #__joomailermailchimpintegration WHERE `listid` = "' . $list_id . '" AND `email` = "' . $e['row']['EMAIL'] . '" LIMIT 1';
                         $db->setQuery($query);
                         $db->query();
                         $addedUsers = array_diff($addedUsers, array($userIds[$e['row']['EMAIL']]));
                         $elements->failed[] = $userIds[$e['row']['EMAIL']];
                         $errorcount++;
                     }
                     $msgErrorsCount += $result['error_count'];
                 }
             }
         }
         if (!count($data)) {
             $done = $elements->total;
             unset($_SESSION['addedUsers']);
             $percent = 100;
         } else {
             $done = count($addedUsers);
             $_SESSION['addedUsers'] = $addedUsers;
             $percent = $done / $elements->total * 100;
         }
         //		$response['msg'] = $done.'/'.$elements->total.' users added';
         $response['msg'] = '<div id="bg"></div>' . '<div style="background:#FFFFFF none repeat scroll 0 0;border:10px solid #000000;height:100px;left:37%;position:relative;text-align:center;top:37%;width:300px; ">' . '<div style="margin: 35px auto 3px; width: 300px; text-align: center;">' . JText::_('JM_ADDING_USERS') . ' ( ' . $done . '/' . $elements->total . ' ' . JText::_('JM_DONE') . ' )</div>' . '<div style="margin: auto; background: transparent url(' . JURI::root() . 'administrator/components/com_joomailermailchimpintegration/assets/images/progress_bar_grey.gif) repeat scroll 0% 0%; width: 190px; height: 14px; display: block;">' . '<div style="width: ' . $percent . '%; overflow: hidden;">' . '<img src="' . JURI::root() . 'administrator/components/com_joomailermailchimpintegration/assets/images/progress_bar.gif" style="margin: 0 5px 0 0;"/>' . '</div>' . '<div style="width: 190px; text-align: center; position: relative;top:-13px; font-weight:bold;">' . round($percent, 0) . ' %</div>' . '</div>' . '<a id="sbox-btn-close" style="text-indent:-5000px;right:-20px;top:-18px;outline:none;" href="javascript:abortAJAX();">abort</a>' . '</div>';
         /*							
         		$response['msg'] = '<div style="width: 190px; text-align: center">'.JText::_( 'adding users' ).' ( '.$done.'/'.$elements->total.' '.JText::_( 'done' ).')</div>'
         				    .'<div style="background: transparent url('.JURI::root().'administrator/components/com_joomailermailchimpintegration/assets/images/progress_bar_grey.gif); width: 190px; height: 14px; display: block;">'
         				    .'<div style="width: '.$percent.'%; overflow: hidden; background: transparent url('.JURI::root().'administrator/components/com_joomailermailchimpintegration/assets/images/progress_bar.gif);">'
         				    .'</div>'
         				    .'<div style="width: 190px; text-align: center; position: relative;">'.round($percent,0).' %</div>'
         				    .'</div>';
         */
         $response['done'] = $done;
         //	$msg = $successCount.' '.JText::_( 'JM_RECIPIENTS_SAVED' ).$msgErrors;
         $response['errors'] = count($elements->failed);
         $response['errorMsg'] = $errorMsg;
         $response['addedUsers'] = array_values($addedUsers);
         $response['failed'] = $elements->failed;
         if ($done + count($elements->failed) + $elements->errors >= $elements->total) {
             $response['finished'] = 1;
             if ($errorMsg) {
                 $errorMsg = substr($errorMsg, 0, -2);
                 $msgErrors = ' ( ' . count($elements->failed) . ' ' . JText::_('JM_ERRORS') . ': ' . $errorMsg . ' )';
             }
             if (!$msg) {
                 $msg = $done . ' ' . JText::_('JM_RECIPIENTS_SAVED');
             }
             if ($msgErrors) {
                 $msg .= $msgErrors;
             }
             $response['finalMessage'] = $msg;
         } else {
             $response['finished'] = 0;
             $response['finalMessage'] = '';
         }
         $response['abortAJAX'] = $_SESSION['abortAJAX'];
         echo json_encode($response);
     } else {
         unset($_SESSION['addedUsers']);
         $response['finished'] = 1;
         $response['addedUsers'] = '';
         $response['abortAJAX'] = $_SESSION['abortAJAX'];
         echo json_encode($response);
     }
 }
Esempio n. 12
0
 public function remove()
 {
     $db = JFactory::getDBO();
     $db->transactionStart();
     $listid = JRequest::getVar('listid', 0, '', 'string');
     $listName = JRequest::getVar('listName', 0, '', 'string');
     $cid = JRequest::getVar('cid', 0, '', 'array');
     foreach ($cid as $id) {
         try {
             $this->getModel('groups')->getMcObject()->listInterestGroupingDel($id);
             if ($this->getModel('groups')->getMcObject()->errorCode) {
                 throw new Exception(MCerrorHandler::getErrorMsg($this->getModel('groups')->getMcObject()));
             }
             // remove field association from J! db
             $query = $db->getQuery(true);
             $query->delete('#__joomailermailchimpintegration_custom_fields')->where($db->qn('grouping_id') . ' = ' . $db->q($id));
             $db->setQuery($query);
             $db->execute();
             $msg = JText::_('JM_CUSTOM_FIELD_DELETED');
             $msgType = 'message';
         } catch (Exception $e) {
             $db->transactionRollback();
             $msg = $e->getMessage();
             $msgType = 'error';
             break;
         }
     }
     $db->transactionCommit();
     $this->app->enqueueMessage($msg, $msgType);
     $this->app->redirect('index.php?option=com_joomailermailchimpintegration&view=groups&listid=' . $listid . '&name=' . $listName);
 }