Beispiel #1
0
 public static function showType($listType, $screen)
 {
     $gid = !empty($GLOBALS[JNEWS . 'list_creatorfe']) ? $GLOBALS[JNEWS . 'list_creatorfe'] : 0;
     if (is_array($listType)) {
         $listType = array_pop($listType);
     }
     switch ($screen) {
         case 'editmailing':
             $className = JNEWS . (!isset($GLOBALS[JNEWS . 'classes' . $listType]) ? $GLOBALS[JNEWS . 'classes' . $listType] : '');
             if (class_exists($className)) {
                 $view = new $className();
                 $show = $view->editmailing();
             } else {
                 $show['sender_info'] = true;
                 $show['published'] = true;
                 $show['pub_date'] = true;
                 $show['hide'] = true;
                 $show['issuenb'] = true;
                 $show['delay'] = false;
                 $show['htmlcontent'] = true;
                 $show['textcontent'] = true;
                 $show['attachement'] = true;
                 $show['auto_option'] = true;
                 $show['images'] = true;
                 $show['sitecontent'] = true;
                 $show['admin'] = true;
             }
             break;
         case 'editlist':
             $show['access'] = $GLOBALS[JNEWS . 'level'] > 2 ? true : false;
             $className = JNEWS . (!isset($GLOBALS[JNEWS . 'classes' . $listType]) ? $GLOBALS[JNEWS . 'classes' . $listType] : '');
             if (class_exists($className)) {
                 $view = new $className();
                 $show = array_merge($show, $view->editlist());
             } else {
                 $show['sender_info'] = true;
                 $show['hide'] = true;
                 $show['auto_option'] = true;
                 $show['htmlmailing'] = true;
                 $show['auto_subscribe'] = true;
                 $show['email_unsubcribe'] = false;
                 $show['unsusbcribe'] = false;
             }
             break;
         case 'showMailings':
             $show['admin'] = jnews::checkPermissions('admin');
             $show['index'] = 'index2';
             $show['buttons'] = false;
             if ($show['admin']) {
                 if (empty($listType)) {
                     $listType = 1;
                 }
                 $className = JNEWS . (!isset($GLOBALS[JNEWS . 'classes' . $listType]) ? $GLOBALS[JNEWS . 'classes' . $listType] : '');
                 if (class_exists($className)) {
                     $view = new $className();
                     $show = array_merge($show, $view->showMailings());
                 } else {
                     $show['id'] = true;
                     $show['dropdown'] = true;
                     $show['select'] = true;
                     $show['issue'] = true;
                     $show['sentdate'] = true;
                     $show['delay'] = false;
                     $show['status'] = true;
                 }
             } else {
                 $show['id'] = false;
                 $show['dropdown'] = false;
                 $show['select'] = false;
                 $show['issue'] = true;
                 $show['sentdate'] = true;
                 $show['delay'] = false;
                 $show['status'] = false;
             }
             break;
         case 'showListsBack':
             if (jnews::checkPermissions('admin')) {
                 $show['id'] = true;
             } else {
                 $show['id'] = false;
             }
             $show['index'] = 'index2';
             $show['select'] = true;
             $show['published'] = true;
             $show['sender'] = true;
             $show['sender_email'] = false;
             $show['mailings_link'] = true;
             $show['mailings_sub'] = true;
             $show['list_type'] = true;
             $show['visible'] = true;
             $show['color'] = true;
             $show['buttons'] = false;
             $show['front'] = false;
             break;
         case 'showListsFront':
             $db = JFactory::getDBO();
             $query = 'SELECT * FROM `#__jnews_lists` WHERE `hidden` = 1 AND `published` = 1 AND ';
             if (is_array($listType)) {
                 $query .= '  `list_type` IN (' . jnews::implode(',', $listType) . ') ';
             } else {
                 $query .= ' `list_type`=' . intval($listType);
             }
             $db->setQuery($query);
             $lists = $db->loadObjectList();
             $access = false;
             $my = JFactory::getUser();
             foreach ($lists as $list) {
                 $bit = jnews::checkPermissions($list->acc_level);
                 if ($bit) {
                     $access = true;
                     break;
                 }
             }
             if (jnews::checkPermissions($gid) || $access && $my->id > 0) {
                 $show['id'] = true;
                 $show['published'] = true;
                 $show['sender'] = true;
                 $show['sender_email'] = false;
                 $show['list_type'] = true;
                 $show['visible'] = true;
                 $show['mailings_sub'] = false;
                 $show['color'] = true;
                 $show['mailings_link'] = true;
                 $show['front'] = true;
             } else {
                 $show['id'] = false;
                 $show['published'] = false;
                 $show['sender'] = false;
                 $show['sender_email'] = false;
                 $show['list_type'] = false;
                 $show['visible'] = false;
                 $show['mailings_sub'] = false;
                 $show['mailings_link'] = false;
                 $show['color'] = false;
                 $show['front'] = true;
             }
             $show['index'] = 'index';
             $show['select'] = false;
             $show['buttons'] = true;
             break;
         default:
             $show = '';
             break;
     }
     return $show;
 }
Beispiel #2
0
 public static function showMailingsFront($task, $action, $subscriberId, $listId, $listType = '', $viewArchive, $pageTile)
 {
     $Itemid = JRequest::getInt('Itemid');
     if (empty($Itemid)) {
         $Itemid = $GLOBALS[JNEWS . 'itemidAca'];
     }
     $gidAdmins = array(24, 25, 7, 8);
     $my = JFactory::getUser();
     if (version_compare(JVERSION, '1.6.0', '>=')) {
         //j16
         $usergid = JAccess::getGroupsByUser($my->id, false);
         $my->gid = $usergid[0];
     }
     $start = JRequest::getVar('start', '0');
     if (!$start) {
         $start = JRequest::getVar('limitstart', '0');
     }
     JRequest::setVar('limitstart', $start);
     $emailsearch = JRequest::getVar('emailsearch', '', '', 'STRING');
     $emailsearch = htmlentities($emailsearch, ENT_COMPAT, "UTF-8");
     $obj_for_order = new stdClass();
     if (version_compare(JVERSION, '3.0.0', '>=')) {
         //j16
         //alex filter
         if ($action === 'mailing') {
             $order = JRequest::getVar('filter_order', 'send_date');
             $obj_for_order->orderValue = $order;
             $obj_for_order->orderDir = JRequest::getVar('filter_order_Dir', 'desc');
         } else {
             $order = JRequest::getVar('filter_order', 'id');
             $obj_for_order->orderValue = $order;
             $obj_for_order->orderDir = JRequest::getVar('filter_order_Dir', 'asc');
         }
     } else {
         $order = JRequest::getVar('order', 'sendDateD');
     }
     $dropList = JRequest::getVar('droplist', 'ZZZZ');
     $my = JFactory::getUser();
     $accessGrant = false;
     $limit = JRequest::getInt('limit');
     if (empty($limit) || $limit > 100) {
         $limit = 20;
     }
     $total = 0;
     if ($dropList == 'ZZZZ') {
         $dropList = $listType . '-' . $listId;
     }
     $total = 0;
     $dropListValues = explode('-', $dropList);
     $listType = $dropListValues[0];
     $listId = $dropListValues[1];
     $id = 0;
     if ($GLOBALS[JNEWS . 'enable_jsub']) {
         if (!empty($my->id)) {
             $ownedlists = jNews_Lists::getOwnedlists($my->id);
         }
         if (!empty($ownedlists)) {
             $id = $my->id;
         }
     }
     $allowed = false;
     if (class_exists('jNews_Pro') && $listId > 0) {
         $list = jNews_Lists::getOneList($listId);
         $allowed = jnews::checkPermissions($list->acc_level);
     } elseif (class_exists('jNews_Pro') && empty($listId)) {
         //check all list
         $myQ = 'SELECT `acc_level` FROM `#__jnews_lists` ';
         $db = JFactory::getDBO();
         $db->setQuery($myQ);
         $listsAccessHere = $db->loadObjectList();
         $allowed = false;
         if (!empty($listsAccessHere)) {
             foreach ($listsAccessHere as $oneAcessL) {
                 if (jnews::checkPermissions($oneAcessL->acc_level)) {
                     $allowed = true;
                     break;
                 }
             }
             //endfoerach
         }
     } else {
         $allowed = in_array($my->gid, $gidAdmins);
     }
     if (!empty($my->id)) {
         $ownedlists = jNews_Lists::getOwnedlists($my->id);
     }
     $accessGrant = !empty($ownedlists) ? true : $allowed;
     if ($accessGrant || $GLOBALS[JNEWS . 'level'] > 2) {
         //we don't filter the newsletters by lists yet - 8889955
         if ($task === "archive") {
             $listType_old = $listType;
             $listType = 1;
         }
         if (empty($listType)) {
             $listType = 1;
         }
         $mailings = jNews_Mailing::getMailings($listId, $listType, $start, $limit, $emailsearch, $order, false, $viewArchive, $obj_for_order);
         $total = count(jNews_Mailing::getMailings($listId, $listType, '0', '100000000', $emailsearch, $order, false, $viewArchive, $obj_for_order));
         if ($task === "archive") {
             $listType = $listType_old;
         }
     } else {
         if ($listType == 1 || $listType == 2 || $listType == 7) {
             $mailings = jNews_Mailing::getMailings($listId, $listType, $start, $limit, $emailsearch, $order, true, $viewArchive, $obj_for_order);
             $total = count(jNews_Mailing::getMailings($listId, $listType, '0', '100000000', $emailsearch, $order, true, $viewArchive, $obj_for_order));
         } elseif ($listType == 0) {
             $mailings1 = jNews_Mailing::getMailings($listId, 1, $start, $limit, $emailsearch, $order, true, $viewArchive, $obj_for_order);
             $mailings2 = jNews_Mailing::getMailings($listId, 2, $start, $limit, $emailsearch, $order, true, $viewArchive, $obj_for_order);
             $mailings7 = jNews_Mailing::getMailings($listId, 7, $start, $limit, $emailsearch, $order, true, $viewArchive, $obj_for_order);
             $mailings = array_merge($mailings1, $mailings2, $mailings7);
             $totalmailings1 = jNews_Mailing::getMailings($listId, 1, '0', '100000000', $emailsearch, $order, true, $viewArchive, $obj_for_order);
             $totalmailings2 = jNews_Mailing::getMailings($listId, 2, '0', '100000000', $emailsearch, $order, true, $viewArchive, $obj_for_order);
             $totalmailings7 = jNews_Mailing::getMailings($listId, 7, '0', '100000000', $emailsearch, $order, true, $viewArchive, $obj_for_order);
             $totalmailings = array_merge($totalmailings1, $totalmailings2, $totalmailings7);
             $total = count($totalmailings);
         } else {
             $mailings = '';
         }
     }
     if ($listId == 0) {
         $lists['title'] = jNews_ListType::chooseType($task, $action, $listType, 'titles', '', _JNEWS_MENU_MAILING);
     } else {
         $listing = jNews_Lists::getLists($listId, 0, $subscriberId, '', false, false, true);
         $listType = $listType > 0 ? $listType : '0';
         $lists['title'] = _JNEWS_NEWSLETTER_ARCHIVE;
     }
     //we check if the user has access to addedit mailing to a list
     if (version_compare(JVERSION, '1.6.0', '<')) {
         $listsAddEdit = jNews_Lists::getIDswithacclevel($my->gid, $listId);
     } else {
         $groups = JAccess::getGroupsByUser($my->id);
         $listsAddEdit = jNews_Lists::getIDswithacclevel($groups, $listId);
     }
     $haveaccesstoList = true;
     $gid = !empty($GLOBALS[JNEWS . 'list_creatorfe']) ? $GLOBALS[JNEWS . 'list_creatorfe'] : 0;
     if (!$allowed && empty($listsAddEdit) && !empty($my->id) && !jnews::checkPermissions('admin') && !jnews::checkPermissions($gid)) {
         $haveaccesstoList = false;
     }
     if ($haveaccesstoList) {
         $dropDownList = jNews_ListType::getMailingDropList($listId, $listType, 'idA');
         // $order
         if (!empty($dropDownList)) {
             $lists['droplist'] = jnews::HTML_GenericList($dropDownList, 'droplist', 'class="inputbox" size="1" onchange="document.jNewsFilterForm.submit();"', 'id', 'name', $dropList);
         }
     }
     $linkMain = 'index.php?option=' . JNEWS_OPTION . '&act=' . $action;
     $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION);
     //alex pagination
     if (!empty($task)) {
         $mainLink .= '&task=' . $task;
     }
     if (!empty($action)) {
         $mainLink .= '&act=' . $action;
     }
     if (!empty($listType)) {
         $mainLink .= '&listype=' . $listType;
     }
     if (!empty($listId)) {
         $mainLink .= '&listid=' . $listId;
     }
     $forms['main'] = '<form method="post" action="' . $mainLink . '" enctype="multipart/form-data" onsubmit="submitbutton();return false;" name="adminForm" id="adminForm">' . "\n\r";
     $forms['select'] = '<form method="post" action="' . $linkMain . '"  name="jNewsFilterForm">' . "\n\r";
     $forms['main'] .= '<input type="hidden" name="Itemid" value="' . $Itemid . '" />';
     $forms['select'] .= '<input type="hidden" name="Itemid" value="' . $Itemid . '" />';
     $show = jNews_ListType::showType($listType, 'showMailings');
     $show['index'] = 'index';
     $show['select'] = false;
     $show['send'] = false;
     $show['buttons'] = true;
     if (class_exists('jNews_Pro') && !$viewArchive) {
         $show['admin'] = true;
         $show['status'] = true;
     }
     $mailingType = $listType == 7 ? 1 : $listType;
     $db = JFactory::getDBO();
     $query = 'SELECT * FROM `#__jnews_lists` WHERE `hidden` = 1 AND `published` = 1 AND ';
     if (is_array($mailingType)) {
         $query .= '  `list_type` IN (' . jnews::implode(',', $mailingType) . ') ';
     } else {
         $query .= ' `list_type`=' . intval($mailingType);
     }
     $db->setQuery($query);
     $lists = $db->loadObjectList();
     $access = false;
     foreach ($lists as $list) {
         $bit = jnews::checkPermissions($list->acc_level);
         if ($bit) {
             $access = true;
             break;
         }
     }
     $menuA = null;
     if ($my->id > 0 && jnews::checkPermissions('all') && $haveaccesstoList) {
         if ($GLOBALS[JNEWS . 'level'] > 2) {
             if ((empty($ownedlists) || !in_array($my->gid, $gidAdmins)) && !$access) {
                 $accessGrant = false;
             } else {
                 $accessGrant = true;
             }
             if ($accessGrant) {
                 $show['select'] = true;
                 $show['send'] = true;
                 // menu new
                 $link = 'option=' . JNEWS_OPTION . '&act=mailing&task=new&listid=' . $listId . '&listype=' . $listType . '&Itemid=' . $Itemid;
                 $link = jNews_Tools::completeLink($link, false);
                 $menuNew = new stdClass();
                 $menuNew->popup = new stdClass();
                 $menuNew->popup->isPop = false;
                 $menuNew->link = '#';
                 $menuNew->action = 'new';
                 $menuNew->onclick = new stdClass();
                 $menuNew->onclick->custom = false;
                 $menuNew->onclick->js = '';
                 $menuNew->title = _JNEWS_NEW;
                 //menu edit
                 $menuEdit = new stdClass();
                 $menuEdit->popup = new stdClass();
                 $menuEdit->popup->isPop = false;
                 $menuEdit->link = '#';
                 $menuEdit->action = 'edit';
                 $menuEdit->onclick = new stdClass();
                 $menuEdit->onclick->custom = false;
                 $menuEdit->onclick->js = '';
                 $menuEdit->title = _JNEWS_MENU_EDIT;
                 //menu delete
                 $menuDelete = new stdClass();
                 $menuDelete->popup = new stdClass();
                 $menuDelete->popup->isPop = false;
                 $menuDelete->link = '#';
                 $menuDelete->action = 'delete';
                 $menuDelete->onclick = new stdClass();
                 $menuDelete->onclick->custom = false;
                 $menuDelete->onclick->js = '';
                 $menuDelete->title = _JNEWS_DELETE;
                 $menuPreview = new stdClass();
                 $menuPreview->popup = new stdClass();
                 $menuPreview->popup->isPop = false;
                 $menuPreview->link = '#';
                 $menuPreview->action = 'preview';
                 $menuPreview->onclick = new stdClass();
                 $menuPreview->onclick->custom = true;
                 $menuPreview->onclick->js = 'javascript:if(document.adminForm.boxchecked.value==0){alert(\'Please make a selection from the mailings to preview\');}else{  submitbutton(\'preview\')}';
                 $menuPreview->title = 'Preview';
                 $menuCopy = new stdClass();
                 $menuCopy->popup = new stdClass();
                 $menuCopy->popup->isPop = false;
                 $menuCopy->link = '#';
                 $menuCopy->action = 'copy';
                 $menuCopy->onclick = new stdClass();
                 $menuCopy->onclick->custom = false;
                 $menuCopy->onclick->js = '';
                 $menuCopy->title = 'Copy';
                 $menuUnpub = new stdClass();
                 $menuUnpub->popup = new stdClass();
                 $menuUnpub->popup->isPop = false;
                 $menuUnpub->link = '#';
                 $menuUnpub->action = 'unpublished';
                 $menuUnpub->onclick = new stdClass();
                 $menuCopy->onclick->custom = false;
                 $menuUnpub->onclick->js = '';
                 $menuUnpub->title = 'Unpublished';
                 $menuDivider = new stdClass();
                 $menuDivider->divider = true;
             } else {
                 $menuNew = new stdClass();
                 $menuEdit = new stdClass();
                 $menuDelete = new stdClass();
                 $menuCopy = new stdClass();
                 $menuUnpub = new stdClass();
                 $menuSend = new stdClass();
                 $menuPreview = new stdClass();
                 $menuDivider = new stdClass();
             }
         } else {
             $menuNew = new stdClass();
             $menuEdit = new stdClass();
             $menuDelete = new stdClass();
             $menuCopy = new stdClass();
             $menuUnpub = new stdClass();
             $menuSend = new stdClass();
             $menuPreview = new stdClass();
             $menuDivider = new stdClass();
         }
         // menu cpanel
         $link = 'option=' . JNEWS_OPTION;
         $link = jNews_Tools::completeLink($link, false);
         $menuCpanel = new stdClass();
         $menuCpanel->popup = new stdClass();
         $menuCpanel->popup->isPop = false;
         $menuCpanel->popup->isPop = false;
         $menuCpanel->link = $link;
         $menuCpanel->action = 'cpanel';
         $menuCpanel->onclick = new stdClass();
         $menuCpanel->onclick->custom = true;
         $menuCpanel->onclick->js = "javascript: submitbutton('cpanel')";
         $menuCpanel->title = _JNEWS_MENU_CPANEL;
         $menuA = array();
         if ($listType != 7) {
             $menuA['unpublished'] = $menuUnpub;
         }
         $menuA['preview'] = $menuPreview;
         $menuA['new'] = $menuNew;
         $menuA['edit'] = $menuEdit;
         if ($listType != 7) {
             $menuA['copy'] = $menuCopy;
         }
         $menuA['delete'] = $menuDelete;
         //			$menuA['divider1'] = $menuDivider;
     }
     //menu back
     if ($listType == 2) {
         $link = 'option=' . JNEWS_OPTION . '&act=list&Itemid=' . $Itemid;
     }
     $link = 'option=' . JNEWS_OPTION . '&Itemid=' . $Itemid;
     $link = jNews_Tools::completeLink($link, false, false);
     $menuBack = new stdClass();
     $menuBack->popup = new stdClass();
     $menuBack->popup = new stdClass();
     $menuBack->popup->isPop = false;
     $menuBack->link = $link;
     $menuBack->action = 'back';
     $menuBack->onclick = new stdClass();
     $menuBack->onclick->custom = false;
     $menuBack->onclick->js = '';
     $menuBack->title = _JNEWS_MENU_BACK;
     $menuBack = new stdClass();
     $menuA['cpanel'] = $menuBack;
     $title = !empty($lists['title']) ? $lists['title'] : '';
     if (in_array($my->gid, $gidAdmins) or !empty($ownedlists) or $accessGrant) {
         if ($listType == 1) {
             $title = 'Newsletters';
         }
         if ($listType == 7) {
             $title = 'Smart-Newsletters';
         }
         if ($listType == 2) {
             $title = 'Auto-responders';
         }
     }
     $app = JFactory::getApplication();
     $setSort = new stdClass();
     if ($listType == '2') {
         //autoresponder
         $key = JNEWS_OPTION . '.mailing2';
         $column = 'delay';
         $direction = 'asc';
     } elseif ($listType == '7') {
         //smartnewsletter
         $key = JNEWS_OPTION . '.mailing7';
         $column = 'id';
         $direction = 'desc';
     } else {
         //newsletter
         $key = JNEWS_OPTION . '.mailing1';
         $column = 'send_date';
         $direction = 'desc';
     }
     $setSort->orderValue = $app->getUserStateFromRequest($key . 'filter_order', 'filter_order', $column, 'cmd');
     $setSort->orderDir = $app->getUserStateFromRequest($key . 'filter_order_Dir', 'filter_order_Dir', $direction, 'word');
     $setLimit = new stdClass();
     $setLimit->start = $start;
     $setLimit->end = $limit;
     $setLimit->total = $total;
     frontHTML::formStart($title, 0, 'show_mailing', $menuA);
     frontHTML::FEmenu();
     jNews_MailingsHTML::showMailingList($mailings, $lists, $start, $limit, $total, $emailsearch, $listId, $listType, $forms, $show, $action, $setLimit, $setSort);
     $go[] = jnews::makeObj('filter_order', $setSort->orderValue);
     $go[] = jnews::makeObj('filter_order_Dir', $setSort->orderDir);
     backHTML::formEnd($go);
     return true;
 }
Beispiel #3
0
 /**
  * This public static function is used to get the names of the lists where the mailing is sent to
  */
 public static function getMailingListName($listIds)
 {
     if (empty($listIds)) {
         return false;
     }
     $query = 'SELECT L.`list_name` FROM `#__jnews_lists` AS L LEFT JOIN `#__jnews_listmailings` AS LS ON L.`id` = LS.`list_id`';
     $query .= count($listIds) > 1 ? ' WHERE L.`id` IN (' . jnews::implode(',', $listIds) . ') ' : ' WHERE L.`id` = ' . $listIds[0];
     $query .= ' GROUP BY L.`id`';
     $db = JFactory::getDBO();
     $db->setQuery($query);
     $loadResultArray = $db->loadObjectList();
     $results = jnews::convertObjectList2Array($loadResultArray);
     return $results;
 }
Beispiel #4
0
 public static function getSpecifiedLists($listIds, $useAccess = true)
 {
     $db = JFactory::getDBO();
     $acl = JFactory::getACL();
     $my = JFactory::getUser();
     $mainframe = JFactory::getApplication();
     $myexplode = explode(',', $listIds);
     if (!empty($myexplode)) {
         foreach ($myexplode as $myexp) {
             $escapedArray[] = intval($myexp);
         }
     } else {
         $escapedArray = array();
         $escaped = '';
     }
     $escaped = jnews::implode(',', $escapedArray);
     if ($listIds == 0) {
         $query = "SELECT * FROM `#__jnews_lists` WHERE `published` = 1 ";
     } elseif (!empty($escaped)) {
         $query = "SELECT * FROM `#__jnews_lists` WHERE `id` IN ( {$escaped} ) AND `published` = 1 ";
     } else {
         return '';
     }
     if (!$mainframe->isAdmin()) {
         if (class_exists('jNews_Pro') && $useAccess) {
             if (version_compare(JVERSION, '1.6.0', '>=')) {
                 //j16
                 $my->gid = JAccess::getGroupsByUser($my->id, false);
             }
             if ($my->gid != 24 && $my->gid != 25 && ($my->gid != 7 && $my->gid != 8)) {
                 if (is_array($my->gid)) {
                     $where[] = " `acc_id` LIKE '%" . $my->gid[0] . ",%' ";
                 } else {
                     $where[] = " `acc_id` LIKE '%{$my->gid},%' ";
                 }
             }
         }
     }
     $gid = !empty($GLOBALS[JNEWS . 'list_creatorfe']) ? $GLOBALS[JNEWS . 'list_creatorfe'] : 0;
     $gids = array();
     $gids = explode(',', $gid);
     if (empty($gids)) {
         $gids = $gid;
     }
     $gidAdmins = array(24, 25, 7, 8);
     if (version_compare(JVERSION, '1.6.0', '>=')) {
         //j16
         $gid = JAccess::getGroupsByUser($my->id, false);
         $my->gid = $gid[0];
     }
     //we filter lists to show only lists having the access to be subscribed by a certain user access
     if (!empty($my->id) && !$mainframe->isAdmin() && !in_array($my->gid, $gidAdmins)) {
         $query .= " AND (`acc_id` LIKE '%{$my->gid},%' OR `acc_id` LIKE '%all%')";
     }
     $db->setQuery($query);
     $lists = $db->loadObjectList();
     if (!empty($lists)) {
         foreach ($lists as $key => $list) {
             $lists[$key]->list_name = stripslashes($lists[$key]->list_name);
             $lists[$key]->list_desc = stripslashes($lists[$key]->list_desc);
             $lists[$key]->layout = stripslashes($lists[$key]->layout);
             $lists[$key]->subscribemessage = stripslashes($lists[$key]->subscribemessage);
             $lists[$key]->unsubscribemessage = stripslashes($lists[$key]->unsubscribemessage);
             $lists[$key]->notifyadminmsg = stripslashes($lists[$key]->notifyadminmsg);
             $lists[$key]->subnotifysend = stripslashes($lists[$key]->subnotifysend);
             $lists[$key]->subnotifymsg = stripslashes($lists[$key]->subnotifymsg);
         }
     }
     return $lists;
 }
Beispiel #5
0
    /** Send element stored in the queue
     * @return bool if the queue still have values to be sent then return true ( for manual send ) otherwise return false
     */
    function sendQueue($showHTML = false, $mailingId = null, $onlyAutoRsponder = false, $manualSend = false)
    {
        $showHTML = true;
        $stillProcess = null;
        $maxTask = $manualSend ? $this->limitEmails : $this->maxQueue;
        if ($maxTask < 1) {
            $maxTask = 1;
        }
        if ($maxTask > 1000) {
            $maxTask = 1000;
        }
        //8889990
        $arPRiority = empty($GLOBALS[JNEWS . 'ar_prior']) ? 1 : $GLOBALS[JNEWS . 'ar_prior'];
        //get all the queue
        $query = 'SELECT A.qid,A.subscriber_id,A.attempt, A.params as `qparams`, A.delay as `qdelay`, B.* FROM `#__jnews_queue` as A';
        $query .= ' LEFT JOIN `#__jnews_mailings` as B on A.mailing_id = B.id ';
        $query .= ' WHERE A.send_date <= ' . time() . ' AND B.published > 0 AND A.type != 8 AND A.type != 99';
        if (!empty($mailingId)) {
            $query .= ' AND A.mailing_id = ' . $mailingId;
        }
        if ($onlyAutoRsponder && $GLOBALS[JNEWS . 'level'] > 1) {
            $query .= ' AND A.`priority` = ' . $arPRiority;
        }
        //do not select the suspend
        $query .= ' AND `suspend`= 0';
        //filter for unconfirmed subscribers
        $query .= ' AND `block` = 0';
        //filter the entries are still being processed from the last sending/processing of the queue
        $query .= ' ORDER BY A.`priority` ASC, A.send_date ASC';
        $query .= ' LIMIT ' . $maxTask;
        $this->db->setQuery($query);
        $allQueuedA = $this->db->loadObjectList();
        $error = $this->db->getErrorMsg();
        if (!empty($error)) {
            //prompt message if an error occured while retrieving entries from the queue
            echo '<br><br><span style="font-weight:bold; font-style:italic; color:blue;">' . _JNEWS_QUEUE_PROCESS_ERROR . '<span><br><br>';
            echo $error;
        }
        if (empty($allQueuedA)) {
            echo '<br><br><span style="font-weight:bold; font-style:italic; color:blue;">' . _JNEWS_NO_MAILINGS_YET . '<span>';
            // prompt message if there is nothing to send
            jNews_Queue::sendReport();
            return false;
        }
        //we update the retrieved allQueuedA to blocked so that  the entries will not be processed double
        foreach ($allQueuedA as $oneQueue) {
            $this->updateQueueBlock($oneQueue->qid, 1);
        }
        $totalSubscribers = count($allQueuedA);
        //make an array of all subscribers and all mailings
        $mySubcribersA = array();
        $subscribersPerMailingsA = array();
        foreach ($allQueuedA as $oneQueue) {
            $mySubcribersA[$oneQueue->subscriber_id] = true;
        }
        //get all the subcribers
        $query = 'SELECT A.`id`,A.`user_id`,A.`name`,A.`email`,A.`receive_html`,A.`confirmed`,A.`blacklist`, B.`id` AS \'user\' ';
        if ($GLOBALS[JNEWS . 'level'] > 2) {
            //check if the version of jnews is pro
            if ($GLOBALS[JNEWS . 'show_column1']) {
                $query .= ',A.`column1`';
            }
            if ($GLOBALS[JNEWS . 'show_column2']) {
                $query .= ',A.`column2`';
            }
            if ($GLOBALS[JNEWS . 'show_column3']) {
                $query .= ',A.`column3`';
            }
            if ($GLOBALS[JNEWS . 'show_column4']) {
                $query .= ',A.`column4`';
            }
            if ($GLOBALS[JNEWS . 'show_column5']) {
                $query .= ',A.`column5`';
            }
        }
        $query .= ' FROM `#__jnews_subscribers` AS A  ';
        $query .= ' LEFT JOIN  `#__users` AS B ON A.id=B.id';
        $query .= ' WHERE A.`id` IN (' . jnews::implode(',', array_keys($mySubcribersA)) . ' )';
        $this->db->setQuery($query);
        $allSubcribersA = $this->db->loadObjectList('id');
        if (empty($allSubcribersA)) {
            jNews_Queue::sendReport();
            return false;
        }
        $mailerC = new jNews_ProcessMail();
        $queueToBeDelted = array();
        $queueToBeAttempted = array();
        $queueSuccessfullySent = array();
        $addToStatisticsA = array();
        $log_detailed = '';
        $message = '';
        $screenMsg = '';
        $maxAttempt = $GLOBALS[JNEWS . 'max_attempts'] < 1 ? 1 : $GLOBALS[JNEWS . 'max_attempts'];
        if ($this->total == 0) {
            $this->total = jNews_Queue::getQueueCount($mailingId);
        }
        //for manual sending processing
        if ($manualSend) {
            if (!headers_sent() and ob_get_level() > 0) {
                @ob_end_flush();
            }
            $url = JURI::base() . jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=continuesend&mailingid=' . $mailingId . '&totalsend=' . $this->total . '&alreadysent=', true, false, true);
            $screenMsg = "<div style='position:fixed; top:3px;left:3px;color:orange; padding : 3px;'>";
            $screenMsg .= "<span id='waitinginfo' style='padding:10px;margin:5px;font-size:16px;font-weight:bold;display:none;background-color:#FFF8C6; color:red;'> </span>";
            $screenMsg .= '<i>' . _JNEWS_SENDING_EMAIL . ' <span id="emailcounter"/><strong>' . $this->start . '</strong></span> out of <strong>' . $this->total . '</strong>... </i>';
            $screenMsg .= "</div><div id='details' style='display:none; position:fixed; bottom:3px;left:3px;background-color : white; border : 1px solid grey; padding : 3px;'> </div><br /><br />";
            $screenMsg .= '<script type="text/javascript" language="javascript">';
            $screenMsg .= 'var myEmailCounter = document.getElementById("emailcounter");';
            $screenMsg .= 'var details = document.getElementById("details");
var waitinginfo = document.getElementById("waitinginfo");
function setDetails(message){ details.style.display = \'block\';details.innerHTML=message; }
function setWaitingInfo(waitingtime){ waitinginfo.style.display = \'\';waitinginfo.innerHTML="Waiting "+waitingtime+" seconds..."; }
function setEmailCounter(val){ myEmailCounter.innerHTML=val;}
var waitingtime = ' . intval($this->pause) . ';
function setWaitingTime(){
	setWaitingInfo(waitingtime);
	if(waitingtime > 0){
		waitingtime = waitingtime - 1;
		setTimeout(\'setWaitingTime()\',1000);
	}else{
		document.location.href=\'' . $url . '\'+myEmailCounter.innerHTML;
	}
}
</script>';
            echo $screenMsg;
            if (function_exists('ob_flush')) {
                @ob_flush();
            } else {
                @flush();
            }
        }
        //we assign counter for the current email being processed
        $counterEmail = $this->start;
        //we determine if the mailings on the queue is lesser than the limit given per batch of manual sending
        if (count($allQueuedA) < $maxTask) {
            $stillProcess = false;
        }
        //get the size of the queue
        foreach ($allQueuedA as $oneQueue) {
            $counterEmail++;
            if ($manualSend) {
                echo '<script type="text/javascript" language="javascript">setEmailCounter(' . $counterEmail . ')</script>';
                if (function_exists('ob_flush')) {
                    @ob_flush();
                }
                @flush();
            }
            //attachements
            if (!empty($oneQueue->attachments)) {
                $oneQueue->attachments = explode("\n", $oneQueue->attachments);
                if (count($oneQueue->attachments) != 0 && trim($oneQueue->attachments[count($oneQueue->attachments) - 1]) == "") {
                    array_pop($oneQueue->attachments);
                }
            } else {
                $oneQueue->attachments = array();
            }
            //images
            if (!empty($oneQueue->images)) {
                $oneQueue->images = explode("\n", $oneQueue->images);
            } else {
                $oneQueue->images = array();
            }
            //5 is maximun attempt
            if ($oneQueue->attempt >= $maxAttempt) {
                $queueToBeDelted[] = $oneQueue->qid;
                continue;
            }
            if (!isset($this->sentHTML[$oneQueue->id])) {
                $this->sentHTML[$oneQueue->id] = 0;
            }
            if (!isset($this->sentText[$oneQueue->id])) {
                $this->sentText[$oneQueue->id] = 0;
            }
            if (!isset($this->sentFailed[$oneQueue->id])) {
                $this->sentFailed[$oneQueue->id] = 0;
            }
            if (isset($allSubcribersA[$oneQueue->subscriber_id]) && is_object($allSubcribersA[$oneQueue->subscriber_id])) {
                $emailSentStatus = $mailerC->send($oneQueue, $allSubcribersA[$oneQueue->subscriber_id]);
                if ($emailSentStatus) {
                    //we update the senddate of the newsletter
                    jNews_Mailing::updatesenddate($oneQueue->id);
                }
            } else {
                continue;
            }
            if (!empty($allSubcribersA[$oneQueue->subscriber_id]->email)) {
                if ($GLOBALS[JNEWS . 'save_log']) {
                    if (!$emailSentStatus) {
                        $log_detailed .= '[' . $oneQueue->id . '] ' . $oneQueue->subject . ' : ' . $allSubcribersA[$oneQueue->subscriber_id]->email . ' -> ' . _JNEWS_MESSAGE_NOT . "\r\n" . _JNEWS_MAILER_ERROR . ': ' . $mailerC->ErrorInfo . "\r\n";
                    } else {
                        $log_detailed .= '[' . $oneQueue->id . '] ' . $oneQueue->subject . ' : ' . $allSubcribersA[$oneQueue->subscriber_id]->email . ' -> ' . _JNEWS_MESSAGE_SENT_SUCCESSFULLY . "\r\n";
                    }
                } else {
                    $log_detailed .= '[' . $oneQueue->id . '] ' . $oneQueue->subject . ' : ' . $allSubcribersA[$oneQueue->subscriber_id]->email . ' -> ' . _JNEWS_MESSAGE_SENT_SUCCESSFULLY . "\r\n";
                }
            }
            //Screen message for manual sending
            if ($manualSend) {
                if ($emailSentStatus) {
                    $message = '<strong><i>' . $oneQueue->subject . '</i></strong> ' . _JNEWS_MSG_SENT_SUCCESS . ' <strong><i>' . $allSubcribersA[$oneQueue->subscriber_id]->name . ' ( ' . $allSubcribersA[$oneQueue->subscriber_id]->email . ' )</i></strong>' . "\r\n";
                } else {
                    $message = '<i>' . _JNEWS_ATTEMPTED . ' ' . $oneQueue->subject . ' to ' . $allSubcribersA[$oneQueue->subscriber_id]->name . ' ( ' . $allSubcribersA[$oneQueue->subscriber_id]->email . ' )' . ".\r\n" . _JNEWS_RESCHEDULED . "\r\n\r\n" . _JNEWS_REACHED_MAX_ATTEMPT . "</i>\r\n\r\n";
                }
                $this->_displayDetails($message, $emailSentStatus, $counterEmail);
            }
            if ($emailSentStatus) {
                //succeess send
                $query = 'DELETE FROM `#__jnews_queue` WHERE `qid`=' . $oneQueue->qid;
                $this->db->setQuery($query);
                $this->db->query();
                if ($mailerC->html) {
                    $this->sentHTML[$oneQueue->id]++;
                } else {
                    $this->sentText[$oneQueue->id]++;
                }
                //user statistics
                if ($GLOBALS[JNEWS . 'enable_statistics'] && $GLOBALS[JNEWS . 'statistics_per_subscriber']) {
                    $addToStatisticsA[$oneQueue->id][$oneQueue->subscriber_id] = (int) $mailerC->html;
                }
                $this->sentSuccess++;
                $this->recurringError = 0;
                $queueSuccessfullySent[] = $oneQueue->qid;
                //we save the successfully sent qids so that we can differentiate from the allqueue what qids that were not processed because the max execution time has been reached
            } else {
                // failed send
                $queueToBeAttempted[] = $oneQueue->qid;
                $this->sentFailed[$oneQueue->id]++;
                $this->recurringError++;
            }
            $time = time();
            if ($this->maxExetime != 0 && $this->maxExetime <= $time) {
                $stillProcess = true;
                break;
            }
            if ($this->recurringError > 2 && $this->sentSuccess > 3) {
                $stillProcess = false;
                break;
            }
            if ($this->recurringError > 5 || connection_aborted()) {
                $stillProcess = false;
                break;
            }
        }
        //we close the processing of emails
        $mail = JFactory::getMailer();
        $mailerC->close($mail);
        if (!empty($this->total) && $counterEmail >= $this->total) {
            $stillProcess = false;
        }
        //update queue with try + 1;
        if (!empty($queueToBeAttempted)) {
            $query = 'UPDATE `#__jnews_queue` SET `attempt`=`attempt`+1,`send_date`=`send_date`+`attempt`*25299+4000, `block`= 0 WHERE `qid` IN (' . jnews::implode(',', $queueToBeAttempted) . ')';
            //we will also update the block to 0 so that it will be processed again
            $this->db->setQuery($query);
            $this->db->query();
        }
        //delete the queue when the emails are sent successfully after x number of attempts
        if (!empty($queueToBeDelted)) {
            $query = 'DELETE FROM `#__jnews_queue` WHERE `qid` IN (' . jnews::implode(',', $queueToBeDelted) . ')';
            $this->db->setQuery($query);
            $this->db->query();
        }
        //unblock again the queue that were not sent because the timeout has been reached so that they will be processed again
        if (!empty($allQueuedA)) {
            foreach ($allQueuedA as $oneQueue) {
                if (!in_array($oneQueue->qid, $queueSuccessfullySent)) {
                    $query = 'UPDATE `#__jnews_queue` SET `block` = 0 WHERE `qid` =' . $oneQueue->qid;
                    $this->db->setQuery($query);
                    $this->db->query();
                }
            }
        }
        //we update and increment the statistics
        if ($GLOBALS[JNEWS . 'enable_statistics']) {
            $this->_updateStatsGlobal($allQueuedA);
        }
        if (!empty($addToStatisticsA)) {
            $this->_insertStats($addToStatisticsA);
        }
        //we prompt message that the mailing has been sent successfully for each batch
        //		echo '<br><br><span style="font-weight:bold; font-style:italic; color:green;">'.$oneQueue->subject.' successfully sent to subscribers.'.'</span> ';
        //mailing reports
        $this->_writeLogs($log_detailed);
        if (isset($stillProcess)) {
            //manual sending
            if ($stillProcess && $manualSend) {
                echo '<script type="text/javascript" language="javascript">setWaitingTime();</script>';
            } else {
                echo '<br><br><span style="font-weight:bold; font-style:italic; color:green;">' . _JNEWS_THE_MAILING . $oneQueue->subject . _JNEWS_SENT_ALL . '</span> ';
                //					$subject = 'jNews Mailing Notification - Status: End';
                //					$content = 'The mailing '.$oneQueue->subject.' has been successfully sent.';
                //					if( version_compare(JVERSION,'1.6.0','<') ){ //j15
                //						$this->db->setQuery( "SELECT * FROM `#__users` WHERE `gid` = 25 ORDER BY `id` ASC LIMIT 1" );
                //					}else{
                //						$this->db->setQuery( "SELECT * FROM `#__users` AS U LEFT JOIN `#__user_usergroup_map` AS UGM ON U.id =UGM.user_id  WHERE `group_id` = 8 ORDER BY `id` ASC LIMIT 1" );
                //					}
                //					$admin = $this->db->loadObject();
                //
                //					JUTility::sendMail($admin->email, $admin->name, $admin->email, $subject, $content );
            }
            if (!$stillProcess) {
                jNews_Queue::sendReport();
            }
            return $stillProcess ? true : false;
        } else {
            //manual sending
            if ($manualSend && $maxTask < $this->total) {
                echo '<script type="text/javascript" language="javascript">setWaitingTime();</script>';
            } else {
                echo '<br><br><span style="font-weight:bold; font-style:italic; color:green;">' . _JNEWS_THE_MAILING . $oneQueue->subject . _JNEWS_SENT_ALL . '</span> ';
                //					$subject = 'jNews Mailing Notification - Status: End';
                //					$content = 'The mailing '.$oneQueue->subject.' has been successfully sent.';
                //					if( version_compare(JVERSION,'1.6.0','<') ){ //j15
                //						$this->db->setQuery( "SELECT * FROM `#__users` WHERE `gid` = 25 ORDER BY `id` ASC LIMIT 1" );
                //					}else{
                //						$this->db->setQuery( "SELECT * FROM `#__users` AS U LEFT JOIN `#__user_usergroup_map` AS UGM ON U.id =UGM.user_id  WHERE `group_id` = 8 ORDER BY `id` ASC LIMIT 1" );
                //					}
                //					$admin = $this->db->loadObject();
                //
                //					JUTility::sendMail($admin->email, $admin->name, $admin->email, $subject, $content );
            }
            if ($this->maxQueue > count($allQueuedA)) {
                jNews_Queue::sendReport();
            }
            return $this->maxQueue > count($allQueuedA) ? false : true;
        }
    }