コード例 #1
0
ファイル: class.module.php プロジェクト: naka211/kkvn
 /**
  * we get the subscribers info using the the id of the user.
  * @param int $id id of the user
  * @retrun object $subscriber info of the subscriber
  */
 function _getSubscriberInfo($id)
 {
     $subscriber = '';
     $subscriber = jNews_Subscribers::getSubscriberInfoFromUserId($id);
     //we get subscriber info if this user is a subscriber of jnews
     if (empty($subscriber)) {
         //if there is no record for the user
         jNews_Subscribers::syncSubscribers(true);
         //we sync the user as subscriber
         $subscriber = jNews_Subscribers::getSubscriberInfoFromUserId($id);
         //we get the subscriber info
     }
     return $subscriber;
 }
コード例 #2
0
ファイル: frontend.php プロジェクト: naka211/kkvn
 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;
     }
 }
コード例 #3
0
ファイル: mailings.jnews.php プロジェクト: naka211/kkvn
function mailing($action, $task, $listId, $listType, $mailingId, $message)
{
    $showMailings = false;
    $db = JFactory::getDBO();
    switch ($task) {
        case 'edit':
            $issue_nb = JRequest::getInt('issue_nb', 1);
            $mailingType = JRequest::getVar('listype');
            $isEdit = JRequest::getVar('isEdit', true);
            $mySess = JFactory::getSession();
            $mySess->set('listype', $mailingType, 'LType');
            if (!empty($listId)) {
                $list = jNews_Lists::getOneList($listId);
            } else {
                $list = jNews_Lists::getListFirstEntry();
            }
            $new = empty($mailingId) || $mailingId == 0 ? true : false;
            $mailing = jNews_Mailing::getOneMailing($list, $mailingId, $issue_nb, $new, false, true);
            $mailing->mailing_type = $mailingType;
            //			if(empty($isEdit)) $isEdit = true;
            // set default mailing parameters
            $my = JFactory::getUser();
            $subscribers = jNews_Subscribers::getSubscriberInfoFromUserId($my->id);
            if (!isset($subscribers)) {
                $subscribers = new stdClass();
            }
            $subscribers->name = isset($subscribers->name) ? $subscribers->name : '';
            $subscribers->email = isset($subscribers->email) ? $subscribers->email : '';
            //			$mailing->fromname = ( !isset( $mailing->fromname ) || empty( $mailing->fromname ) ) ? $subscribers->name : $mailing->fromname;
            //			$mailing->fromemail = ( !isset( $mailing->fromemail ) || empty( $mailing->fromemail ) ) ? $subscribers->email : $mailing->fromemail;
            //			$mailing->frombounce = ( !isset( $mailing->frombounce ) || empty( $mailing->frombounce ) ) ? $GLOBALS[JNEWS.'sendmail_from'] : $mailing->frombounce;
            $show = jNews_ListType::showType($mailing->mailing_type, 'editmailing');
            if ($mailing->published != 1 or $mailing->mailing_type != 1 or isset($show['admin']) and $show['admin']) {
                $forms['main'] = " <form action='index.php' method='post' enctype='multipart/form-data' name='adminForm' id=\"adminForm\">";
                jNews_Mailing::_header($task, $action, $mailing->mailing_type, $message, 'edit');
                jNews_MailingsHTML::editMailing($mailing, $new, $listId, $forms, $show, $isEdit);
                $go[] = jnews::makeObj('act', $action);
                backHTML::formEnd($go);
            } else {
                $forms['main'] = " <form action='index.php' method='post' name='adminForm' id=\"adminForm\">";
                jNews_Mailing::_header($task, $action, $mailing->mailing_type, $message);
                //backHTML::formStart();
                jNews_MailingsHTML::viewMailing($mailing, $forms);
                $go[] = jnews::makeObj('act', 'mailing');
                $go[] = jnews::makeObj('task', 'viewmailing');
                $go[] = jnews::makeObj('mailingid', $mailing->id);
                backHTML::formEnd($go);
            }
            break;
        case 'new':
        case 'add':
            // check if atleast one list exist and published
            // if false then restrict entry
            $mailingType = JRequest::getVar('listype');
            $type = $mailingType == 2 ? 2 : 1;
            $result = jNews_Lists::checkListNotEmpty($type);
            if (!$result) {
                if ($type == 2) {
                    $disp = addslashes(_JNEWS_CHECKCAMPAIGNFOUND);
                } else {
                    $disp = addslashes(_JNEWS_CHECKLISTFOUND);
                }
                echo "<script> alert('" . $disp . "'); window.history.go(-1);</script>\n";
                break;
            }
            $mailingType = JRequest::getVar('listype');
            if (empty($listId)) {
                $listId = JRequest::getVar('listid');
            }
            if (!empty($listId)) {
                $mailingType = jNews_Lists::getListType($listId) == 2 ? 2 : 1;
            }
            JRequest::setVar('listype', $mailingType);
            $total = jNews_Mailing::countMailings($listId, $mailingType);
            $total++;
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&task=edit&mailingid=0&issue_nb=' . $total . '&listype=' . $mailingType . '&listid=' . $listId . '&isEdit=0');
            //mariap
            break;
        case 'saveSend':
            JRequest::checkToken() or die('Invalid Token');
            $mySess = JFactory::getSession();
            $mailingType = $mySess->get('listype', '', 'LType');
            $status = checkMailingSave($mailingType);
            if (!$status) {
                return false;
            }
            jNews_Mailing::saveMailing($mailingId, $listId);
        case 'sendready':
            //we update the senddate of the newsletter
            jNews_Mailing::updatesenddate($mailingId);
            jNews_MailingsHTML::sendReady($mailingId, $listId, $listType);
            break;
        case 'generate':
            if (class_exists('jNews_Auto')) {
                $still = false;
                $message = jnews::printYN(jNews_Auto::processQueue(true, true, $still, true), 'Queue processed', _JNEWS_ERROR);
                jNews_Auto::displayStatus();
            }
            return;
            break;
        case 'send':
            $queueC = new jNews_Queue();
            $queueC->checkForNewsletters($mailingId);
            $queueCount = jNews_Queue::getQueueCount($mailingId);
            $totalSub = JRequest::setVar('totalsend', $queueCount);
            $linkURL = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=continuesend&mailingid=' . $mailingId . '&totalsend=' . $totalSub, true, false, true);
            jNews_Tools::redirect($linkURL);
            break;
        case 'continuesend':
            $queueC = new jNews_Queue();
            //we update the senddate of the mailing to be now to be able to continue the sending and send it after we click continue
            //			$queueC->updateSenddateToNow($mailingId);
            $totalSend = JRequest::getVar('totalsend', 0, '', 'int');
            $alreadySent = JRequest::getVar('alreadysent', 0, '', 'int');
            $queueC->start = $alreadySent;
            $queueC->total = $totalSend;
            $queueC->pause = $GLOBALS[JNEWS . 'pause_time'];
            $queueC->sendQueue(false, $mailingId, false, true);
            ob_start();
            exit;
            break;
        case 'testspam':
            if (empty($message)) {
                $message = _JNEWS_MESSAGE_NOT;
            }
            $mailingId = $mailingId == 0 ? jNews_Mailing::getLastMailingId() : $mailingId;
            $my = JFactory::getUser();
            if ($listId > 0) {
                $archivemailing = jNews_Mailing::getMailingView($mailingId, $listId);
            } else {
                $archivemailing = jNews_Mailing::getMailingView($mailingId);
            }
            $mailing = new stdClass();
            $receivers = new stdClass();
            $receivers->email = '*****@*****.**';
            $receivers->name = $archivemailing->fromname;
            $receivers->receive_html = 1;
            $receivers->id = jNews_Subscribers::getSubscriberIdFromUserId($my->id);
            //if email are different we dont replace because we want to make sure the spam cehck count the fact that
            //sender and bounce back are different
            if ($archivemailing->fromemail == $archivemailing->frombounce) {
                $archivemailing->frombounce = $my->email;
            }
            $archivemailing->fromemail = $my->email;
            $mailerC = new jNews_ProcessMail();
            $status = $mailerC->send($archivemailing, $receivers);
            $message = jnews::printYN($status, _JNEWS_SPAMTEXT_MESSAGE_SENT_SUCCESSFULLY, $message);
            $link = 'http://www.joobi.co/index.php?option=com_jlinks&controller=redirect&link=SpamCheck&alt=jnewsdoc_glossary';
            $iFrame = '<iframe src="' . $link . '" width="100%" height="680px" scrolling="auto"></iframe>';
            echo $iFrame;
            break;
        case 'savePreview':
            JRequest::checkToken() or die('Invalid Token');
            $status = checkMailingSave($mailingType);
            if (!$status) {
                return false;
            }
            if ($mailingType == 7) {
                $mailing = JRequest::getVar('mailing', '');
                $ContentStatus = checkTag();
                if (!$ContentStatus) {
                    return false;
                }
            }
            jNews_Mailing::saveMailing($mailingId, $listId);
        case 'preview':
            $emailaddress = JRequest::getVar('emailaddress', '');
            $mailingId = $mailingId == 0 ? jNews_Mailing::getLastMailingId() : $mailingId;
            if (!empty($emailaddress)) {
                $status = jNews_Mailing::sendTestEmail($mailingId, $listId);
                if (empty($message)) {
                    $message = _JNEWS_MESSAGE_NOT;
                }
                $message = jnews::printYN($status, _JNEWS_MESSAGE_SENT_SUCCESSFULLY, $message);
            }
            if ($listId > 0) {
                $archivemailing = jNews_Mailing::getMailingView($mailingId, $listId);
            } else {
                $archivemailing = jNews_Mailing::getMailingView($mailingId);
            }
            $doc = JFactory::getDocument();
            $css = '.icon-48-preview{ background-image:url(' . JNEWS_PATH_ADMIN_IMAGES2 . 'header/preview.png)}';
            $doc->addStyleDeclaration($css, $type = 'text/css');
            $title = _JNEWS_PREVIEW_TITLE . ': ' . $archivemailing->subject;
            backHTML::_header(_JNEWS_PREVIEW_TITLE, 'preview.png', $message, $task, $action);
            //new view for the preview mailing
            echo '<table cellpadding="0" cellspacing="2" border="0" width="100%"><tr><td width="40%">';
            jNews_MailingsHTML::previewMailingHTML($mailingId, $listId, $listType, $archivemailing->html);
            echo '</td><td width="60%">';
            $forms['main'] = '';
            $list = jNews_Lists::getOneList($archivemailing->list_id);
            $textonly = '';
            $mailerC = new jNews_ProcessMail();
            $queueInfo = new stdClass();
            $queueInfo->mailingid = $mailingId;
            $queueInfo->listid = @$listId;
            $mailerC->getContent($archivemailing->images, $archivemailing->html, $archivemailing->textonly, $archivemailing->subject, false, true, $queueInfo);
            //new $archivemailing->subject
            if ($archivemailing->html == 1) {
                if (empty($template_id)) {
                    $template_id = $archivemailing->template_id;
                }
                if (!empty($template_id)) {
                    jNews_Templates::includeStyles($archivemailing->htmlcontent, $template_id);
                }
            } else {
                $archivemailing->textonly = jNews_ProcessMail::htmlToText($archivemailing->textonly);
            }
            //new view for the preview mailing
            jNews_MailingsHTML::viewHeading($archivemailing);
            echo '</td></tr><tr><td colspan="2">';
            jNews_MailingsHTML::viewMailing($archivemailing, $forms);
            echo '</td></tr></tbody></table>';
            if ($mailingId == 0) {
                JRequest::setVar('mailingid', $mailingId);
            }
            break;
        case 'view':
            $mailingType = JRequest::getVar('listype');
            if (!empty($mailingType)) {
                $mySess = JFactory::getSession();
                $mySess->set('listype', $mailingType, 'LType');
            }
            if ($mailingId != 0) {
                if ($listId > 0) {
                    $archivemailing = jNews_Mailing::getMailingView($mailingId, $listId);
                } else {
                    $archivemailing = jNews_Mailing::getMailingView($mailingId);
                }
                if (empty($template_id)) {
                    $template_id = $archivemailing->template_id;
                }
                if (!empty($template_id)) {
                    jNews_Templates::includeStyles($archivemailing->htmlcontent, $template_id);
                }
                $forms['main'] = "<form action='index.php?option=" . JNEWS_OPTION . "&act=mailing&listype=" . $listType . "&listid=" . $listId . "' method='post' name='adminForm' id=\"adminForm\">";
                jNews_Mailing::_header($task, $action, $listType, $message);
                backHTML::formStart('show_mailing', 0, '');
                jNews_MailingsHTML::viewMailing($archivemailing, $forms);
                $go[] = jnews::makeObj('act', 'mailing');
                $go[] = jnews::makeObj('task', 'viewmailing');
                $go[] = jnews::makeObj('listId', $archivemailing->list_id);
                //listid to listId--original
                backHTML::formEnd($go);
            }
            break;
        case 'deletequeue':
            //implement here what are we going to do with the delete queueu column on the mailing
            $mailingID = JRequest::getVar('mailingid');
            $mailingType = JRequest::getVar('listype');
            if (!empty($mailingID)) {
                $db = JFactory::getDBO();
                $db->setQuery('DELETE FROM `#__jnews_queue` WHERE `mailing_id` = ' . $mailingID);
                $db->query();
                $message = jnews::printYN(true, _JNEWS_MAILING_QUEUE_DELETED, _JNEWS_ERROR);
            } else {
                $message = jnews::printYN(false, _JNEWS_MAILING_QUEUE_DELETED, _JNEWS_ERROR);
            }
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType, $message);
            break;
        case 'deleteMailing':
            JRequest::checkToken() or die('Invalid Token');
            $d['mailing'] = jNews_Mailing::getOneMailing('', $mailingId, '', $new);
            $message = jnews::printYN(jNews_Mailing::delete($d), @constant($GLOBALS[JNEWS . 'listname' . $d['mailing']->list_type]) . '"' . $d['mailing']->subject . '"' . _JNEWS_SUCCESS_DELETED, _JNEWS_ERROR);
            $showMailings = true;
            break;
        case 'cancel':
            $url = 'index.php?option=' . JNEWS_OPTION . '&act=mailing&mailingid=' . $mailingId;
            $url .= (!empty($listId) ? '&listid=' . $listId : '') . '&listype=' . $mailingType;
            jNews_Tools::redirect($url);
            break;
        case 'copy':
            JRequest::checkToken() or die('Invalid Token');
            $message = jnews::printYN(jNews_Mailing::copyMailing($mailingId), _JNEWS_MAILING_COPY, _JNEWS_ERROR);
            $showMailings = true;
            break;
        case 'cancelMailing':
            $showMailings = true;
            break;
        case 'publishMailing':
            JRequest::checkToken() or die('Invalid Token');
            $mailing = jNews_Mailing::getOneMailing('', $mailingId, '', $new);
            $message = jnews::printYN(jNews_Mailing::publishMailing($mailingId), @constant($GLOBALS[JNEWS . 'listname' . $mailing->mailing_type]) . ' ' . _JNEWS_PUBLISHED, _JNEWS_ERROR);
            $mailingType = jNews_Mailing::getMailingInfoz($mailingId);
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType);
            break;
        case 'unpublishMailing':
            JRequest::checkToken() or die('Invalid Token');
            $mailing = jNews_Mailing::getOneMailing('', $mailingId, '', $new);
            $message = jnews::printYN(jNews_Mailing::unpublishMailing($mailingId), @constant($GLOBALS[JNEWS . 'listname' . $mailing->mailing_type]) . ' ' . _JNEWS_UNPUBLISHED, _JNEWS_ERROR);
            $mailingType = jNews_Mailing::getMailingInfoz($mailingId);
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType . '&listid=' . $listId);
            break;
        case 'cpanel':
            backHTML::controlPanel();
            break;
        case 'save':
            JRequest::checkToken() or die('Invalid Token');
            $subject = JRequest::getVar('subject', '');
            if (empty($subject)) {
                echo "<script> alert('subject needs to be not empty'); window.history.go(-1);</script>\n";
                return false;
            }
            if (!isset($mailingType)) {
                $mySess = JFactory::getSession();
                $mailingType = $mySess->get('listype', '', 'LType');
            }
            $status = checkMailingSave($mailingType);
            if ($mailingType == 7) {
                $mailing = JRequest::getVar('mailing', '');
                $ContentStatus = checkTag();
                if (!$ContentStatus) {
                    return false;
                }
            }
            if (!$status) {
                return false;
            }
            $message = jnews::printYN(jNews_Mailing::saveMailing($mailingId, $listId), _JNEWS_MAILING_SAVED, _JNEWS_ERROR);
            if (!empty($mailingtype)) {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType . '&listid=' . $listId);
            } else {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType . '&listid=' . $listId);
                $showMailings = true;
                unset($GLOBALS["task"]);
                unset($_REQUEST["task"]);
            }
            break;
        case 'apply':
            JRequest::checkToken() or die('Invalid Token');
            $mailingid = JRequest::getVar('mailingid', '0');
            if (!isset($mailingType)) {
                $mySess = JFactory::getSession();
                $mailingType = $mySess->get('listype', '', 'LType');
            }
            $status = checkMailingSave($mailingType);
            if ($mailingType == 7) {
                $mailing = JRequest::getVar('mailing', '');
                $ContentStatus = checkTag();
                if (!$ContentStatus) {
                    return false;
                }
            }
            if (!$status) {
                return false;
            }
            $message = jnews::printYN(jNews_Mailing::saveMailing($mailingId, $listId), _JNEWS_MAILING_SAVED, _JNEWS_ERROR);
            $mailingid = $mailingid == 0 ? jNews_Mailing::getLastMailingId() : $mailingid;
            if (!empty($mailingtype)) {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&task=edit&listype=' . $mailingType . '&mailingid=' . $mailingid . '&listid=' . $listId);
            } else {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&task=edit&listype=' . $mailingType . '&mailingid=' . $mailingid . '&listid=' . $listId);
                $showMailings = true;
                unset($GLOBALS["task"]);
                unset($_REQUEST["task"]);
            }
            break;
        case 'show':
            $id = JRequest::getVar('mailingid');
            $mySess = JFactory::getSession();
            $mailingType = JRequest::getVar('listype', 0);
            $listId = JRequest::getVar('listid', 0);
            $link = 'index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType . '&listid=' . $listId;
            jNews_Tools::redirect($link);
            $showMailings = true;
            break;
        case 'toggle':
            $listid = JRequest::getVar('listid');
            $column = JRequest::getVar('col');
            $mailingid = JRequest::getVar('mailingid');
            if (!empty($mailingid) && !empty($column)) {
                $passObj = new stdClass();
                $passObj->tableName = '#__jnews_mailings';
                $passObj->columnName = $column;
                $passObj->whereColumn = 'id';
                $passObj->whereColumnValue = $mailingid;
                jnews::toggle($passObj);
            }
            if ($listType == 1) {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listid=' . $listid . '&listype=1');
            } else {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listid=' . $listid . '&listype=2');
            }
            break;
        default:
            $showMailings = true;
            break;
    }
    if ($showMailings) {
        if (empty($listType)) {
            $listType = JRequest::getVar('listype', 0);
        }
        if (empty($listId)) {
            $listId = JRequest::getVar('listid', 0);
        }
        $paginationStart = JRequest::getVar('pg');
        if (!empty($paginationStart)) {
            $limitstart = 0;
            $limitend = $paginationStart;
        } else {
            $app = JFactory::getApplication();
            $limitstart = $app->getUserStateFromRequest('limitstart', 'limitstart', 0, 'int');
            $limitend = $app->getUserStateFromRequest('limit', 'limit', 0, 'int');
        }
        $limittotal = jNews_Mailing::countMailings(0, $listType);
        $setLimit = new stdClass();
        $setLimit->total = !empty($limittotal) ? $limittotal : 0;
        $setLimit->start = !empty($limitstart) ? $limitstart : 0;
        $setLimit->end = !empty($limitend) ? $limitend : $limittotal;
        if ($setLimit->total == $setLimit->end) {
            $setLimit->start = 0;
        }
        jNews_Mailing::showMailings($task, $action, $listId, $listType, $message, true, _JNEWS_MENU_MAILING, $setLimit);
    }
    return true;
}
コード例 #4
0
ファイル: jnews.php プロジェクト: naka211/kkvn
         $subscriber->params = '';
         $subscriber->admin_id = 62;
         //notice columns
         if ($GLOBALS[JNEWS . 'level'] > 2) {
             //check if the version of jnews is pro
             $subscriber->column1 = '';
             $subscriber->column2 = '';
             $subscriber->column3 = '';
             $subscriber->column4 = '';
             $subscriber->column5 = '';
         }
         //end if check if the version is pro
         //jNews_Subscribers::insertSubscriber($subscriber, $subscriberId);
         jNews_Subscribers::saveSubscriber($subscriber, $subscriberId, true, $listid);
         //get subscriber info by passing the user id
         $userInfo = jNews_Subscribers::getSubscriberInfoFromUserId($user->id);
     } else {
     }
     //end if
     //save the subscriber id and list to listssubscribers table
     $subscriber->id = $userInfo->id;
     $subscriber->list_id = $listid;
     $subscriber->flexicontentFlag = true;
     //a flag that the subscription is from a tenders subscription from the flexicontent module
     $subscriber->params = $params;
     jNews_ListsSubs::saveToListSubscribers($subscriber);
 }
 //clear jnews session
 $mySess->clear('flexi_countries', 'JNEWLSETTER');
 $mySess->clear('flexi_industries', 'JNEWLSETTER');
 $mySess->clear('modjnewsflexi_listid', 'JNEWLSETTER');
コード例 #5
0
ファイル: lists.jnews.php プロジェクト: naka211/kkvn
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;
    }
}