Example #1
0
 public static function showLists($subscriberId, $listId, $lisType, $action, $task)
 {
     $Itemid = JRequest::getInt('Itemid');
     if (empty($Itemid)) {
         $Itemid = $GLOBALS[JNEWS . 'itemidAca'];
     }
     // we initialize the listType with one
     if (empty($lisType)) {
         $lisType = 1;
     }
     $mainframe = JFactory::getApplication();
     $my = JFactory::getUser();
     $gid = !empty($GLOBALS[JNEWS . 'list_creatorfe']) ? $GLOBALS[JNEWS . 'list_creatorfe'] : 0;
     if (version_compare(JVERSION, '1.6.0', '<')) {
         $listsAddEdit = jNews_Lists::getIDswithacclevel($my->gid);
     } else {
         $groups = JAccess::getGroupsByUser($my->id);
         $listsAddEdit = jNews_Lists::getIDswithacclevel($groups);
     }
     if (!empty($my->id)) {
         $ownedlists = jNews_Lists::getOwnedlists($my->id);
         //UPDATE321
         $lists = jNews_Lists::getLists(0, 0, true);
         $access = false;
         foreach ($lists as $list) {
             $bit = jnews::checkPermissions($list->acc_level);
             if ($bit) {
                 $access = true;
                 break;
             }
         }
         if (!$access && empty($listsAddEdit) && empty($ownedlists) && !jnews::checkPermissions('admin') && !jnews::checkPermissions($gid)) {
             frontHTML::showPanel();
             return true;
         }
     }
     //for popup window
     JHTML::_('behavior.modal');
     switch ($task) {
         case 'new':
         case 'add':
             $access = 'admin';
             $id = 0;
             if ($GLOBALS[JNEWS . 'enable_jsub']) {
                 if (!empty($my->id)) {
                     $ownedlists = jNews_Lists::getOwnedlists($my->id);
                 }
                 if (!empty($ownedlists)) {
                     $access = strtolower($my->usertype);
                 }
                 $id = $my->id;
             }
             if (jnews::checkPermissions($access) || jnews::checkPermissions($gid)) {
                 //traces
                 $task = 'save';
                 $subscriber = jNews_Subscribers::getSubscriberInfoFromUserId($my->id);
                 if (version_compare(JVERSION, '1.6.0', '<')) {
                     //j15
                     $acl = JFactory::getACL();
                     $groups = $acl->get_group_children_tree(null, 'USERS', false);
                 } else {
                     //j16
                     $db = JFactory::getDBO();
                     $db->setQuery('SELECT a.*, a.title as text, a.id as value  FROM #__usergroups AS a ORDER BY a.lft ASC');
                     $groups = $db->loadObjectList();
                 }
                 $allGroupIds = array();
                 foreach ($groups as $oneGroup) {
                     $allGroupIds[] = $oneGroup->value;
                 }
                 $newList = new stdClass();
                 $newList->id = '';
                 $newList->html = 1;
                 $newList->new_letter = 1;
                 $newList->list_name = '';
                 $newList->list_desc = '';
                 if (empty($subscriber)) {
                     $newList->sendername = '';
                     $newList->senderemail = '';
                     $newList->bounceadres = '';
                     //$GLOBALS[JNEWS.'sendmail_from'];
                 } else {
                     $newList->sendername = $subscriber->name;
                     $newList->senderemail = $subscriber->email;
                     $newList->bounceadres = $subscriber->email;
                 }
                 $newList->hidden = 1;
                 $newList->auto_add = 0;
                 $newList->list_type = $lisType;
                 $newList->delay_min = 1;
                 $newList->delay_max = 7;
                 $newList->user_choose = 0;
                 $newList->cat_id = '0:0';
                 $newList->follow_up = '';
                 $newList->notify_id = 0;
                 $newList->owner = $my->id;
                 $newList->acc_level = '24,25,7,8';
                 $newList->acc_id = implode(',', $allGroupIds);
                 $newList->published = 1;
                 $newList->start_date = date('Y-m-d', jnews::getNow(0, true));
                 $newList->next_date = jnews::getNow(0, true);
                 $newList->subscribemessage = _JNEWS_DEFAULT_SUBSCRIBE_MESS;
                 $newList->unsubscribemessage = _JNEWS_DEFAULT_UNSUBSCRIBE_MESS;
                 $newList->notifyadminmsg = _JNEWS_UNSUBSCRIBE_ADMIN_NOTIFICATION;
                 $newList->subnotifymsg = _JNEWS_SUBSDEFAULT_NOTIFYMSG;
                 $newList->subnotifysend = 1;
                 $newList->unsubscribesend = 1;
                 $newList->unsubscribenotifyadmin = 1;
                 $newList->footer = 1;
                 $linkForm = 'option=' . JNEWS_OPTION;
                 $linkForm = jNews_Tools::completeLink($linkForm, false, false);
                 $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION);
                 $forms['main'] = "<form action='{$mainLink}' method='post' name='adminForm' enctype='multipart/form-data' onsubmit='submitbutton();return false;' id=\"adminForm\">";
                 $show = jNews_ListType::showType($lisType, 'editlist');
                 // menus for list edit
                 // menu save
                 $linkForm = jNews_Tools::completeLink($linkForm, true);
                 $linkForm = '#';
                 $menuSave = new stdClass();
                 $menuSave->popup = new stdClass();
                 $menuSave->popup->isPop = false;
                 $menuSave->link = $linkForm;
                 $menuSave->action = 'save';
                 $menuSave->onclick = new stdClass();
                 $menuSave->onclick->custom = false;
                 $menuSave->onclick->js = '';
                 $menuSave->title = _JNEWS_SAVE;
                 // menu cancel
                 $menuCancel = new stdClass();
                 $menuCancel->popup = new stdClass();
                 $menuCancel->popup->isPop = false;
                 $menuCancel->link = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=list&Itemid=' . $Itemid, false);
                 $menuCancel->action = 'cancel';
                 $menuCancel->onclick = new stdClass();
                 $menuCancel->onclick->custom = true;
                 $menuCancel->onclick->js = '';
                 $menuCancel->title = _JNEWS_CANCEL;
                 $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 = false;
                 $menuCpanel->onclick->js = '';
                 $menuCpanel->title = _JNEWS_MENU_CPANEL;
                 $menuA = array();
                 $menuA['save'] = $menuSave;
                 $menuA['cancel'] = $menuCancel;
                 $menuA['cpanel'] = $menuCpanel;
                 frontHTML::formStart(_JNEWS_EDIT_A . @constant($GLOBALS[JNEWS . 'listname' . $lisType]) . ' ' . _JNEWS_LIST, $newList->html, 'listedit', $menuA);
                 jNews_ListsHTML::editList($newList, $forms, $show, $lisType);
                 $go[] = jnews::makeObj('list_id', $newList->id);
                 $go[] = jnews::makeObj('act', $action);
                 $go[] = jnews::makeObj('task', '');
                 $go[] = jnews::makeObj('listype', JRequest::getInt('listype'));
                 frontHTML::formEndFN(null, $go);
             }
             break;
         case 'edit':
             $access = 'admin';
             $id = 0;
             if ($GLOBALS[JNEWS . 'enable_jsub']) {
                 if (!empty($my->id)) {
                     $ownedlists = jNews_Lists::getOwnedlists($my->id);
                 }
                 if (!empty($ownedlists)) {
                     $access = strtolower($my->usertype);
                 }
                 $id = $my->id;
             }
             if (jnews::checkPermissions($access) || jnews::checkPermissions($gid)) {
                 //traces
                 $task = 'update';
                 $list = jNews_Lists::getLists($listId, $lisType, $subscriberId, '', false, false, false);
                 $listEdit = $list[0];
                 $listEdit->new_letter = 0;
                 if (!empty($listEdit)) {
                     $linkForm = 'option=' . JNEWS_OPTION;
                     $linkForm = jNews_Tools::completeLink($linkForm, false, false);
                     $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION);
                     $forms['main'] = "<form action='{$mainLink}' method='post' name='adminForm' enctype='multipart/form-data' onsubmit='submitbutton();return false;' id=\"adminForm\">";
                     $show = jNews_ListType::showType($listEdit->list_type, 'editlist');
                     // menus for list edit
                     // menu save
                     $linkForm = 'option=' . JNEWS_OPTION . '&act=list&listid=' . $listId . '&listype=' . $lisType . '&siteend=1&Itemid=' . $Itemid;
                     $linkForm = jNews_Tools::completeLink($linkForm, false);
                     $menuSave = new stdClass();
                     $menuSave->popup = new stdClass();
                     $menuSave->popup->isPop = false;
                     $menuSave->link = $linkForm;
                     $menuSave->action = 'save';
                     $menuSave->onclick = new stdClass();
                     $menuSave->onclick->custom = false;
                     $menuSave->onclick->js = '';
                     $menuSave->title = _JNEWS_SAVE;
                     // menu cancel
                     $menuCancel = new stdClass();
                     $menuCancel->popup = new stdClass();
                     $menuCancel->popup->isPop = false;
                     $menuCancel->link = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=list&Itemid=' . $Itemid, false);
                     $menuCancel->action = 'cancel';
                     $menuCancel->onclick = new stdClass();
                     $menuCancel->onclick->custom = true;
                     $menuCancel->onclick->js = '';
                     $menuCancel->title = _JNEWS_CANCEL;
                     $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 = false;
                     $menuCpanel->onclick->js = '';
                     $menuCpanel->title = _JNEWS_MENU_CPANEL;
                     $menuA = array();
                     if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) {
                         if (class_exists('jNews_Social')) {
                             $menuA['save'] = $menuSave;
                             $menuA['cancel'] = $menuCancel;
                         }
                     }
                     $menuA['cpanel'] = $menuCpanel;
                     frontHTML::formStart(_JNEWS_EDIT_A . @constant($GLOBALS[JNEWS . 'listname' . $lisType]) . ' ' . _JNEWS_LIST, $listEdit->html, 'listedit', $menuA);
                     jNews_ListsHTML::editList($listEdit, $forms, $show, $lisType);
                     $go[] = jnews::makeObj('list_id', $listEdit->id);
                     $go[] = jnews::makeObj('act', $action);
                     $go[] = jnews::makeObj('task', 'update');
                     frontHTML::formEndFN(null, $go);
                 }
             }
             break;
         case 'save':
             JRequest::checkToken() or die('Invalid Token');
             if (empty($listId)) {
                 if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) {
                     if (class_exists('jNews_Social')) {
                         $status = jNews_Social::createFrontendList($action, $task, $lisType);
                     }
                 }
                 $msgtype = $status ? 'ok' : 'no';
                 $message = jnews::printYN($msgtype, _JNEWS_LIST_ADDED, _JNEWS_ERROR);
                 if ($mainframe->isAdmin()) {
                     jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=list&listype=' . $lisType . '&siteend=1');
                 } else {
                     $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION . '&act=list&listype=' . $lisType . '&siteend=1');
                     jNews_Tools::redirect($mainLink);
                 }
                 echo $message;
             } else {
                 $lisType = jNews_Lists::getListType($listId);
                 $message = jnews::printYN(jNews_Lists::updateListFromEdit($listId, '', false, $lisType), _JNEWS_LIST_UPDATED, _JNEWS_ERROR);
                 //						jNews_Tools::redirect('index.php?option='.JNEWS_OPTION.'&act=list&listype='.$lisType.'&siteend=1');
                 if ($mainframe->isAdmin()) {
                     jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=list&listype=' . $lisType . '&siteend=1');
                 } else {
                     $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION . '&act=list&listype=' . $lisType . '&siteend=1');
                     jNews_Tools::redirect($mainLink);
                 }
                 echo $message;
                 $listId = 0;
             }
             break;
         case 'ownerslists':
             $ownerid = JRequest::getVar('ownerid', 0);
             $item = JRequest::getInt('Itemid');
             $ownerslists = jNews_Lists::getSpecifiedLists(0, '', $ownerid);
             $module = new jnews_module();
             $module->lists = $ownerslists;
             $module->showListName = true;
             $module->defaultchecked = true;
             $module->dropdown = false;
             $module->shownamefield = true;
             $HTML = $module->create();
             echo $HTML;
             break;
         case 'make':
         case 'forms':
             if (class_exists('jNews_CreateForm')) {
                 jNews_CreateForm::taskOptions($task);
                 $showLists = false;
             } else {
                 $showLists = true;
             }
             break;
         case 'cpanel':
             jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION);
             break;
         default:
             $my = JFactory::getUser();
             $show = jNews_ListType::showType($lisType, 'showListsFront');
             $msgtype = JRequest::getVar('msg', '');
             if (!empty($msgtype)) {
                 if ($msgtype == 'no') {
                     echo jnews::printM($msgtype, _JNEWS_ERROR);
                 } else {
                     echo jnews::printM($msgtype, _JNEWS_LIST_ADDED);
                 }
             }
             $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION);
             $forms['main'] = '<form method="post" action="' . $mainLink . '" onsubmit="submitbutton();return false;" name="mosForm" >' . "\n\r";
             //$link
             $forms['main'] .= '<input type="hidden" name="Itemid" value="' . $Itemid . '" />';
             $order = 'listnameA';
             $id = 0;
             if ($GLOBALS[JNEWS . 'enable_jsub']) {
                 if (!empty($my->id)) {
                     $ownedlists = jNews_Lists::getOwnedlists($my->id);
                 }
                 if (!empty($ownedlists)) {
                     $id = $my->id;
                 }
             }
             if (jnews::checkPermissions('admin') || jnews::checkPermissions($gid) || !empty($listsAddEdit)) {
                 if ($mainframe->isAdmin()) {
                     $lists = jNews_Lists::getLists($listId, $lisType, $subscriberId, $order, false, false, false);
                 } else {
                     $lists = jNews_Lists::getLists($listId, $lisType, $subscriberId, $order, false, true, false, false, true);
                 }
             } else {
                 if ($mainframe->isAdmin()) {
                     if ($lisType == 0) {
                         $lists1 = jNews_Lists::getLists($listId, 1, $subscriberId, $order, false, true, false);
                         $lists2 = jNews_Lists::getLists($listId, 2, $subscriberId, $order, false, true, false);
                         $lists7 = jNews_Lists::getLists($listId, 7, $subscriberId, $order, false, true, false);
                         $lists = array_merge($lists1, $lists2, $lists7);
                     } elseif ($lisType == 1 or $lisType == 2 or $lisType == 7) {
                         $lists = jNews_Lists::getLists($listId, $lisType, $subscriberId, $order, false, true, false);
                     } else {
                         $lists = '';
                     }
                 } else {
                     if ($lisType == 0) {
                         //get the owned list of the logged user
                         $ownedlists = 0;
                         if ($GLOBALS[JNEWS . 'enable_jsub']) {
                             $my = JFactory::getUser();
                             if (!empty($my->id)) {
                                 $ownedlists = jNews_Lists::getOwnedlists($my->id);
                             }
                             if (!empty($ownedlists)) {
                                 $access = true;
                             }
                         }
                         $lists1 = jNews_Lists::getLists($listId, 1, $subscriberId, $order, false, true, false, false, true, '', '', $ownedlists, $my->id);
                         $lists2 = jNews_Lists::getLists($listId, 2, $subscriberId, $order, false, true, false, false, true);
                         $lists7 = jNews_Lists::getLists($listId, 7, $subscriberId, $order, false, true, false, false, true);
                         $lists = array_merge($lists1, $lists2, $lists7);
                     } elseif ($lisType == 1 or $lisType == 2 or $lisType == 7) {
                         $lists = jNews_Lists::getLists($listId, $lisType, $subscriberId, $order, false, true, false, false, true);
                     } else {
                         $lists = '';
                     }
                 }
             }
             if (!empty($lists) || jnews::checkPermissions($gid)) {
                 $menuA = null;
                 if ($my->id > 0) {
                     $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 = false;
                     $menuCpanel->onclick->js = '';
                     $menuCpanel->title = _JNEWS_MENU_CPANEL;
                     $menuShare = new stdClass();
                     $menuForms = new stdClass();
                     $menuNew = new stdClass();
                     $itemId = $GLOBALS[JNEWS . 'itemidAca'];
                     if ($GLOBALS[JNEWS . 'enable_jsub'] && !empty($ownedlists) || jnews::checkPermissions('admin') || jnews::checkPermissions($gid)) {
                         $linkShare = 'option=' . JNEWS_OPTION . '&act=list&task=ownerslists&ownerid=' . $my->id . '&Itemid=' . $itemId;
                         $linkShare = jNews_Tools::completeLink($linkShare, false);
                         $menuShare = new stdClass();
                         $menuShare->popup = new stdClass();
                         $menuShare->popup->isPop = false;
                         $menuShare->link = $linkShare;
                         $menuShare->action = 'share';
                         $menuShare->onclick = new stdClass();
                         $menuShare->onclick->custom = false;
                         $menuShare->onclick->js = '';
                         $menuShare->title = 'Share';
                         $menuBack = new stdClass();
                         $menuBack->popup = new stdClass();
                         $menuBack->popup = new stdClass();
                         $menuBack->popup->isPop = false;
                         $menuBack->link = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=list&Itemid=' . $Itemid, false);
                         $menuBack->action = 'back';
                         $menuBack->onclick = new stdClass();
                         $menuBack->onclick->custom = true;
                         $menuBack->onclick->js = '';
                         $menuBack->title = _JNEWS_MENU_BACK;
                         $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;
                         $menuForms = new stdClass();
                         $menuNew = new stdClass();
                         if ($GLOBALS[JNEWS . 'enable_jsub'] && !empty($ownedlists)) {
                             $linkForm = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=list&task=make', false, false, true);
                             $menuForms->link = $linkForm;
                             $menuForms->popup = new stdClass();
                             $menuForms->popup->isPop = true;
                             $menuForms->popup->rel = true;
                             $menuForms->popup->x = 750;
                             $menuForms->popup->y = 500;
                             $menuForms->action = 'form';
                             $menuForms->title = 'Create Form';
                             $linknew = 'option=com_jsubscription&view=jsubscription&task=listing&Itemid=' . $itemId;
                             $menuNew = new stdClass();
                             $menuNew->popup = new stdClass();
                             $menuNew->popup->isPop = false;
                             $menuNew->action = 'new';
                             $menuNew->onclick = new stdClass();
                             $menuNew->onclick->custom = true;
                             $menuNew->onclick->js = '';
                             $menuNew->title = 'New';
                             $menuNew->link = $linknew;
                         } else {
                             if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) {
                                 if (class_exists('jNews_Social')) {
                                     //									if($lisType == 1){
                                     $linkForm = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=list&task=make', true, false, true);
                                     $menuForms->link = $linkForm;
                                     $menuForms->popup = new stdClass();
                                     $menuForms->popup->isPop = true;
                                     $menuForms->popup->rel = true;
                                     $menuForms->popup->x = 750;
                                     $menuForms->popup->y = 500;
                                     $menuForms->action = 'form';
                                     $menuForms->title = 'Create Form';
                                     //										$linknew = 'option='.JNEWS_OPTION.'&act=list&task=new&listype='.$lisType.'&siteend=1&Itemid='.$itemId;
                                     $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION);
                                     $menuNew = new stdClass();
                                     $menuNew->popup = new stdClass();
                                     $menuNew->popup->isPop = false;
                                     //										$linknew = jNews_Tools::completeLink($linknew,false);
                                     $linknew = '#';
                                     // #
                                     $menuNew->action = 'new';
                                     $menuNew->onclick = new stdClass();
                                     $menuNew->onclick->custom = true;
                                     $menuNew->onclick->js = "javascript: submitbutton('new')";
                                     $menuNew->title = 'New';
                                     $menuNew->link = $linknew;
                                 }
                                 //								}
                             }
                         }
                         $menuUnpub = new stdClass();
                         $menuUnpub->popup = new stdClass();
                         $menuUnpub->popup->isPop = false;
                         $menuUnpub->link = '#';
                         $menuUnpub->action = 'unpublished';
                         $menuUnpub->onclick = new stdClass();
                         $menuUnpub->onclick->custom = true;
                         $menuUnpub->onclick->js = 'javascript:history.go(-1)';
                         $menuUnpub->title = 'Unpublished';
                         $menuPub = new stdClass();
                         $menuPub->popup = new stdClass();
                         $menuPub->popup->isPop = false;
                         $menuPub->link = '#';
                         $menuPub->action = 'published';
                         $menuPub->onclick = new stdClass();
                         $menuPub->onclick->custom = true;
                         $menuPub->onclick->js = 'javascript:history.go(-1)';
                         $menuPub->title = 'Published';
                         $menuCopy = new stdClass();
                         $menuCopy->popup = new stdClass();
                         $menuCopy->popup->isPop = false;
                         $menuCopy->link = '#';
                         $menuCopy->action = 'copy';
                         $menuCopy->onclick = new stdClass();
                         $menuCopy->onclick->custom = true;
                         $menuCopy->onclick->js = 'javascript:history.go(-1)';
                         $menuCopy->title = 'Copy';
                         $menuDivider = new stdClass();
                         $menuDivider->divider = true;
                     }
                     $menuA = array();
                     if ($lisType == '2') {
                         $menuA['new'] = $menuNew;
                         $menuA['cpanel'] = $menuCpanel;
                     } else {
                         if ($GLOBALS[JNEWS . 'enable_jsub']) {
                             $menuA['share'] = $menuShare;
                         }
                         $menuA['form'] = $menuForms;
                         $menuA['new'] = $menuNew;
                         $menuA['cpanel'] = $menuCpanel;
                     }
                 }
                 if ($lisType == 1) {
                     $title = _JNEWS_EMAIL_LISTS;
                 } else {
                     $title = 'Auto-responders';
                 }
                 if (empty($my->id)) {
                     $title = _JNEWS_SUBSCRIBE_LIST2;
                 }
                 if (empty($ownedlists) && !empty($my->id)) {
                     $title = _JNEWS_SUBSCRIBE_LIST2;
                 }
                 $gid = !empty($GLOBALS[JNEWS . 'list_creatorfe']) ? $GLOBALS[JNEWS . 'list_creatorfe'] : 0;
                 frontHTML::formStart($title, 0, '', $menuA);
                 frontHTML::FEmenu();
                 if ($show['list_type']) {
                     $show['list_type'] = jNews_ListType::checkOthers();
                 }
                 $setSort = new stdClass();
                 $setSort->orderDir = '';
                 $setSort->orderValue = '';
                 if (class_exists('jNews_Pro')) {
                     $id = 0;
                     if ($GLOBALS[JNEWS . 'enable_jsub']) {
                         if (!empty($my->id)) {
                             $ownedlists = jNews_Lists::getOwnedlists($my->id);
                         }
                         if (!empty($ownedlists)) {
                             $id = $my->id;
                         }
                     }
                     $access = false;
                     foreach ($lists as $list) {
                         $bit = jnews::checkPermissions($list->acc_level);
                         if ($bit) {
                             $access = true;
                             break;
                         }
                     }
                     $my = JFactory::getUser();
                     //owner of the list to access the list
                     if ($GLOBALS[JNEWS . 'enable_jsub']) {
                         if (!empty($my->id)) {
                             $ownedlists = jNews_Lists::getOwnedlists($my->id);
                         }
                         if (!empty($ownedlists)) {
                             $access = true;
                             $usertype = strtolower($my->usertype);
                         }
                     }
                     if ($access) {
                         jNews_Pro::showListingLists($lists, $action, 'edit', $forms, $show, $my->id);
                         $go[] = jnews::makeObj('listype', JRequest::getInt('listype'));
                     } else {
                         jNews_ListsHTML::showListingLists($lists, $action, 'edit', $forms, $show, '', 0, null, null, $setSort);
                         $go[] = jnews::makeObj('listype', JRequest::getInt('listype'));
                     }
                 } else {
                     jNews_ListsHTML::showListingLists($lists, $action, 'edit', $forms, $show, '', 0, null, null, $setSort);
                 }
                 $go[] = jnews::makeObj('act', $action);
                 frontHTML::formEnd('', $go);
             } else {
                 frontHTML::FEmenu();
             }
             break;
     }
 }
Example #2
0
function lists($action, $task, $listId, $listType)
{
    $db = JFactory::getDBO();
    $my = JFactory::getUser();
    $css = '.icon-48-lists { background-image:url(' . JNEWS_PATH_ADMIN_IMAGES2 . 'header/lists.png)}';
    $doc = JFactory::getDocument();
    $doc->addStyleDeclaration($css, $type = 'text/css');
    $img = 'lists.png';
    $listsearch = JRequest::getVar('listsearch', '');
    $message = '';
    $xf = new jNews_Config();
    $showLists = true;
    $checkToggle = false;
    // defined toggle for publish and unpublish of mailings
    if (!empty($task) && $task == 'togle') {
        $checkToggle = true;
        $id = JRequest::getVar('listid');
        $col = JRequest::getVar('col');
        $listId = !empty($id) && !empty($col) ? $id : $listId;
        $task = !empty($listId) && !empty($col) ? $col : $task;
    }
    switch ($task) {
        case 'new':
        case 'add':
            $subscriber = jNews_Subscribers::getSubscriberInfoFromUserId($my->id);
            if (version_compare(JVERSION, '1.6.0', '<')) {
                //j15
                $acl = JFactory::getACL();
                $groups = $acl->get_group_children_tree(null, 'USERS', false);
            } else {
                //j16
                $db = JFactory::getDBO();
                $db->setQuery('SELECT a.*, a.title as text, a.id as value  FROM #__usergroups AS a ORDER BY a.lft ASC');
                $groups = $db->loadObjectList();
            }
            $allGroupIds = array();
            foreach ($groups as $oneGroup) {
                $allGroupIds[] = $oneGroup->value;
            }
            $newList = new stdClass();
            $showLists = false;
            $newList->id = '';
            $newList->html = 1;
            $newList->new_letter = 1;
            $newList->list_name = '';
            $newList->list_desc = '';
            $newList->template = '';
            if (empty($subscriber)) {
                $newList->sendername = '';
                $newList->senderemail = '';
                $newList->bounceadres = '';
            } else {
                $newList->sendername = '';
                $newList->senderemail = '';
                $newList->bounceadres = '';
            }
            $newList->hidden = 1;
            $newList->auto_add = 0;
            $newList->list_type = $listType;
            $newList->delay_min = 1;
            $newList->delay_max = 7;
            $newList->user_choose = 0;
            $newList->cat_id = '0:0';
            $newList->follow_up = '';
            $newList->notify_id = 0;
            $newList->owner = $my->id;
            $newList->acc_level = '24,25,7,8';
            $newList->acc_id = implode(',', $allGroupIds);
            $newList->published = 1;
            $newList->start_date = date('Y-m-d', time());
            $newList->next_date = jnews::getNow();
            $newList->subscribemessage = _JNEWS_DEFAULT_SUBSCRIBE_MESS;
            $newList->unsubscribemessage = _JNEWS_DEFAULT_UNSUBSCRIBE_MESS;
            $newList->notifyadminmsg = _JNEWS_UNSUBSCRIBE_ADMIN_NOTIFICATION;
            $newList->subnotifymsg = _JNEWS_SUBSDEFAULT_NOTIFYMSG;
            $newList->subnotifysend = 1;
            $newList->unsubscribesend = 1;
            $newList->unsubscribenotifyadmin = 1;
            $newList->footer = 1;
            $forms['main'] = " <form action='index.php' method='post' name='adminForm' id=\"adminForm\">";
            $show = jNews_ListType::showType($newList->list_type, 'editlist');
            if ($listType == 1) {
                backHTML::_header(_JNEWS_NEW . ' ' . _JNEWS_LIST, $img, $message, $task, $action);
            } else {
                backHTML::_header(_JNEWS_NEW . ' ' . _JNEWS_AUTORESP . ' ' . _JNEWS_LIST, $img, $message, $task, $action);
            }
            backHTML::formStart('editlist', $newList->html, '');
            jNews_ListsHTML::editList($newList, $forms, $show, $listType);
            $go[] = jnews::makeObj('act', $action);
            $go[] = jnews::makeObj('listid', $newList->id);
            backHTML::formEnd($go);
            break;
        case 'doNew':
            JRequest::checkToken() or die('Invalid Token');
            $listname = JRequest::getVar('list_name', '');
            if (empty($listname)) {
                echo "<script> alert(' List name must be filled out. '); window.history.go(-1);</script>\n";
                return false;
            }
            $now = jnews::getNow();
            $query = "SELECT `id` FROM `#__jnews_lists` WHERE `list_name`= '" . addslashes($listname) . "' ";
            $db->setQuery($query);
            $lId = $db->loadResult();
            if ($lId > 0) {
                echo "<script> alert(' This list already exist, please choose another name. '); window.history.go(-1);</script>\n";
                return false;
            } else {
                $query = "INSERT INTO `#__jnews_lists` (`list_name`,`createdate`) VALUES ( '" . addslashes($listname) . "'  , '{$now}' )";
                $db->setQuery($query);
                $db->query();
            }
            $query = "SELECT * FROM `#__jnews_lists` WHERE `list_name`= '" . addslashes($listname) . "' ";
            $db->setQuery($query);
            $mynewlist = $db->loadObject();
            $mynewlist->list_name = stripslashes($mynewlist->list_name);
            $mynewlist->list_desc = stripslashes($mynewlist->list_desc);
            $mynewlist->template = $mynewlist->template;
            $mynewlist->layout = stripslashes($mynewlist->layout);
            $mynewlist->subscribemessage = stripslashes($mynewlist->subscribemessage);
            $mynewlist->unsubscribemessage = stripslashes($mynewlist->unsubscribemessage);
            $mynewlist->notifyadminmsg = stripslashes($mynewlist->notifyadminmsg);
            $mynewlist->subnotifysend = stripslashes($mynewlist->subnotifysend);
            $mynewlist->subnotifymsg = stripslashes($mynewlist->subnotifymsg);
            $listId = $mynewlist->id;
            $message = jnews::printYN(jNews_Lists::updateListFromEdit($listId, '', true, $listType), _JNEWS_LIST_ADDED, _JNEWS_ERROR);
            $xf->plus('totallist0', 1);
            $xf->plus('act_totallist0', 1);
            $xf->plus('totallist' . $listType, 1);
            $xf->plus('act_totallist' . $listType, 1);
            break;
        case 'edit':
            if ($listId == 0) {
                echo "<script> alert('" . addslashes(_JNEWS_SELECT_LIST) . "'); window.history.go(-1);</script>\n";
                return false;
            } else {
                $showLists = false;
                $query = 'SELECT * FROM `#__jnews_lists` WHERE `id` = ' . intval($listId);
                $db->setQuery($query);
                $listEdit = $db->loadObject();
                if ($listEdit->acc_id == 'all') {
                    if (version_compare(JVERSION, '1.6.0', '<')) {
                        //j15
                        $acl = JFactory::getACL();
                        $groups = $acl->get_group_children_tree(null, 'USERS', false);
                    } else {
                        //j16
                        $db = JFactory::getDBO();
                        $db->setQuery('SELECT a.*, a.title as text, a.id as value  FROM #__usergroups AS a ORDER BY a.lft ASC');
                        $groups = $db->loadObjectList();
                    }
                    $allGroupIds = array();
                    foreach ($groups as $oneGroup) {
                        $allGroupIds[] = $oneGroup->value;
                    }
                    $listEdit->acc_id = implode(',', $allGroupIds);
                }
                $listEdit->list_name = stripslashes($listEdit->list_name);
                $listEdit->list_desc = stripslashes($listEdit->list_desc);
                $listEdit->template = $listEdit->template;
                $listEdit->layout = stripslashes($listEdit->layout);
                $listEdit->subscribemessage = stripslashes($listEdit->subscribemessage);
                $listEdit->unsubscribemessage = stripslashes($listEdit->unsubscribemessage);
                $listEdit->notifyadminmsg = stripslashes($listEdit->notifyadminmsg);
                $listEdit->subnotifysend = stripslashes($listEdit->subnotifysend);
                $listEdit->subnotifymsg = stripslashes($listEdit->subnotifymsg);
                $listEdit->new_letter = 0;
                $forms['main'] = " <form action='index.php' method='post' name='adminForm' id=\"adminForm\">";
                $show = jNews_ListType::showType($listEdit->list_type, 'editlist');
                backHTML::_header(_JNEWS_EDIT_A . @constant($GLOBALS[JNEWS . 'listname' . $listEdit->list_type]) . ' ' . _JNEWS_LIST, $img, $message, $task, $action);
                backHTML::formStart('listedit', $listEdit->html, '');
                jNews_ListsHTML::editList($listEdit, $forms, $show, $listType);
                $go[] = jnews::makeObj('act', $action);
                $go[] = jnews::makeObj('listid', $listEdit->id);
                backHTML::formEnd($go);
            }
            break;
        case 'update':
            JRequest::checkToken() or die('Invalid Token');
            $message = jnews::printYN(jNews_Lists::updateListFromEdit($listId, '', false, $listType), _JNEWS_LIST_UPDATED, _JNEWS_ERROR);
            break;
        case 'delete':
            JRequest::checkToken() or die('Invalid Token');
            $query = "SELECT list_name FROM #__jnews_lists WHERE id = {$listId}";
            $db->setQuery($query);
            $listName = $db->loadResult();
            $message = jnews::printYN(jNews_Lists::deleteList($listId), '"' . $listName . '"' . _JNEWS_LIST . _JNEWS_SUCCESS_DELETED, _JNEWS_ERROR);
            break;
        case 'copy':
            JRequest::checkToken() or die('Invalid Token');
            $message = jnews::printYN(jNews_Lists::copyList($listId), _JNEWS_LIST_COPY, _JNEWS_ERROR);
            break;
        case 'publish':
            if (!$checkToggle) {
                JRequest::checkToken() or die('Invalid Token');
            }
            $message = jnews::printYN(jNews_Lists::updateListFromList($listId, true, false), _JNEWS_PUBLISHED, _JNEWS_ERROR);
            if ($listType == 1) {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=list&listype=' . $listType);
            } else {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=arlist&listype=' . $listType);
            }
            break;
        case 'unpublish':
            if (!$checkToggle) {
                JRequest::checkToken() or die('Invalid Token');
            }
            $message = jnews::printYN(jNews_Lists::updateListFromList($listId, false, false), _JNEWS_UNPUBLISHED, _JNEWS_ERROR);
            if ($listType == 1) {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=list&listype=' . $listType . '&listid=' . $listId);
            } else {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=arlist&listype=' . $listType . '&listid=' . $listId);
            }
            break;
        case 'forms':
        case 'make':
            if (class_exists('jNews_CreateForm')) {
                jNews_CreateForm::taskOptions($task);
                $showLists = false;
            } else {
                $showLists = true;
            }
            break;
        case 'cpanel':
            backHTML::controlPanel();
            return true;
            break;
        case 'toggle':
            $listid = JRequest::getVar('listid');
            $column = JRequest::getVar('col');
            if (!empty($listid) && !empty($column)) {
                $passObj = new stdClass();
                $passObj->tableName = '#__jnews_lists';
                $passObj->columnName = $column;
                $passObj->whereColumn = 'id';
                $passObj->whereColumnValue = $listid;
                jnews::toggle($passObj);
            }
            if ($listType == 1) {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=list&listype=1');
            } else {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=arlist&listype=2');
            }
            break;
    }
    if ($showLists) {
        $limit = -1;
        //Title header
        if ($listType == 1) {
            backHTML::_header(_JNEWS_MENU_LIST, $img, $message, $task, $action);
        } else {
            backHTML::_header(_JNEWS_ARLIST, $img, $message, $task, $action);
        }
        $show = jNews_ListType::showType(0, 'showListsBack');
        $forms['main'] = "<form action='index.php' method='post' name='adminForm' id=\"adminForm\">";
        backHTML::formStart('show_mailing', '', '');
        $paginationStart = JRequest::getVar('pg');
        $app = JFactory::getApplication();
        if (!empty($paginationStart)) {
            $limitstart = 0;
            $limitend = $paginationStart;
        } else {
            $limitstart = $app->getUserStateFromRequest('limitstart', 'limitstart', 0, 'int');
            $limitend = $app->getUserStateFromRequest('limit', 'limit', 0, 'int');
        }
        $limittotal = jNews_Lists::getListCount($listType);
        $limittotal = $limittotal[0];
        $setLimit = new stdClass();
        $setLimit->total = !empty($limittotal) ? $limittotal : 0;
        $setLimit->start = !empty($limitstart) ? $limitstart : 0;
        $setLimit->end = !empty($limitend) ? $limitend : $limittotal;
        // recheck start
        if ($setLimit->total == $setLimit->end) {
            $setLimit->start = 0;
        }
        $setSort = new stdClass();
        if ($listType == '2') {
            //autoresponder
            $key = JNEWS_OPTION . '.arlist';
            $column = 'id';
            $direction = 'desc';
        } else {
            //newsletter
            $key = JNEWS_OPTION . '.list';
            $column = 'list_name';
            $direction = 'asc';
        }
        $setSort->orderValue = $app->getUserStateFromRequest($key . 'filter_order', 'filter_order', $column, 'cmd');
        $setSort->orderDir = $app->getUserStateFromRequest($key . 'filter_order_Dir', 'filter_order_Dir', $direction, 'word');
        if ($listType == 2) {
            ?>
<script language="javascript" type="text/javascript">
	function submitbutton(pressbutton) {
		var form = document.adminForm;
		if (pressbutton == 'delete') {
			var $ok = confirm('Are you sure you want to delete?\r\nAll of the mailings attached in this auto-responder will be deleted as well.');
			if ( $ok == true ){
				form.action = 'index.php?option=<?php 
            echo JNEWS_OPTION;
            ?>
&act=arlist&task=delete';
			}else{
				return;
			}
		}
		submitform( pressbutton );
	}
</script>
<?php 
        }
        $listing = jNews_Lists::getLists(0, $listType, 1, '', false, false, false, false, false, $listsearch, $setLimit, $setSort);
        if (isset($setLimit->total) && !empty($listsearch)) {
            $lists = jNews_Lists::getLists(0, $listType, 1, '', false, false, false, false, false, $listsearch, $setSort);
            $setLimit->total = !empty($lists) ? count($lists) : $setLimit->total;
        }
        $totalSubs = array();
        $totalUnSubs = array();
        $db = JFactory::getDBO();
        if (!empty($listing)) {
            foreach ($listing as $list) {
                $totalSubs[] = jNews_Subscribers::getSubscribersCount($list->id, true);
                $totalUnSubs[] = jNews_Subscribers::getSubscribersCount($list->id, 2);
            }
        }
        jNews_ListsHTML::showListingLists($listing, $action, 'edit', $forms, $show, $listsearch, $setLimit->end, $setLimit, $totalSubs, $setSort, $totalUnSubs);
        $go[] = jnews::makeObj('act', $action);
        $go[] = jnews::makeObj('filter_order', $setSort->orderValue);
        $go[] = jnews::makeObj('filter_order_Dir', $setSort->orderDir);
        backHTML::formEnd($go);
        return true;
    }
}