예제 #1
0
파일: frontend.php 프로젝트: naka211/kkvn
 public static function mailingOptions($action, $task, $listId, $mailingId, $subscriberId, $listType, $artId, $contentType, $blogId, $blogType, $dealId, $dealType, $tmplid, $flexiid, $flexitype, $captchaWidth = 80, $captchaHeight = 25, $captchaBGColor = '', $captchaFTColor = '')
 {
     $Itemid = JRequest::getInt('Itemid');
     if (empty($Itemid)) {
         $Itemid = $GLOBALS[JNEWS . 'itemidAca'];
     }
     if (empty($lisType)) {
         $lisType = 1;
     }
     $acl = JFactory::getACL();
     $database = JFactory::getDBO();
     $my = JFactory::getUser();
     $new = false;
     $gid = !empty($GLOBALS[JNEWS . 'list_creatorfe']) ? $GLOBALS[JNEWS . 'list_creatorfe'] : 0;
     $gids = array();
     $gids = explode(',', $gid);
     if (empty($gids)) {
         $gids = $gid;
     }
     if (version_compare(JVERSION, '1.6.0', '<')) {
         $listsAddEdit = jNews_Lists::getIDswithacclevel($my->gid);
     } else {
         $groups = JAccess::getGroupsByUser($my->id);
         $listsAddEdit = jNews_Lists::getIDswithacclevel($groups);
     }
     //for popup window
     JHTML::_('behavior.modal');
     if ($listType < 1) {
         $dropLlistPost = JRequest::getVar('droplist');
         if (!empty($dropLlistPost)) {
             $maliste = explode('-', $dropLlistPost);
             $listType = $maliste[0];
             $listId = $maliste[1];
         } elseif ($listId > 0) {
             $maliste = jNews_Lists::getLists($listId, 0, null, 'listnameA', false, false, false, false);
             $listType = $maliste[0]->list_type;
         }
     }
     switch ($task) {
         case 'refreshcaptcha':
             $newcode = jNews_Captcha::generateCode('5');
             $_SESSION['captcha'] = $newcode;
             $newesc = jNews_Captcha::encryptData($newcode, crypt($GLOBALS[JNEWS . 'captcha_code'], $GLOBALS[JNEWS . 'captcha_code']));
             $newdecrypt = jNews_Captcha::decryptData($newesc, crypt($GLOBALS[JNEWS . 'captcha_code'], $GLOBALS[JNEWS . 'captcha_code']));
             $newpath = JNEWS_JPATH_LIVE_NO_HTTPS . '/index.php?option=' . JNEWS_OPTION . '&act=captcha&tmpl=component&width=' . $captchaWidth . '&height=' . $captchaHeight . '&bgcolor=' . $captchaBGColor . '&ftcolor=' . $captchaFTColor . '&characters=5&esc=' . $newesc . '&encpwd=' . crypt($GLOBALS[JNEWS . 'captcha_code'], $GLOBALS[JNEWS . 'captcha_code']);
             echo '<div id="newcode">' . $newdecrypt . '</div>';
             echo '<div id="newesc">' . $newesc . '</div>';
             echo '<div id="newdecrypt">' . $newdecrypt . '</div>';
             echo '<div id="newpath">' . $newpath . '</div>';
             exit;
             break;
         case 'blogContent':
             $artId = $blogId;
             $contentType = $blogType;
         case 'flexicontent':
             $session =& JFactory::getSession();
             if ($flexitype == 'country') {
                 $flexCategoriesCountries = $session->get('flexi_countries', array(), 'JNEWLSETTER');
                 if (isset($flexCategoriesCountries[$flexiid])) {
                     unset($flexCategoriesCountries[$flexiid]);
                 } else {
                     $flexCategoriesCountries[$flexiid] = $flexiid;
                 }
                 //we set this value in the session
                 $session->set('flexi_countries', $flexCategoriesCountries, 'JNEWLSETTER');
             } else {
                 $flexCategoriesIndustries = $session->get('flexi_industries', array(), 'JNEWLSETTER');
                 if (isset($flexCategoriesIndustries[$flexiid])) {
                     unset($flexCategoriesIndustries[$flexiid]);
                 } else {
                     $flexCategoriesIndustries[$flexiid] = $flexiid;
                 }
                 //we set this value in the session
                 $session->set('flexi_industries', $flexCategoriesIndustries, 'JNEWLSETTER');
             }
             break;
         case 'articleContent':
             jNews_Mailing::getContent($artId, $contentType, $task, $tmplid);
             break;
         case 'dealContent':
             jNews_Mailing::getDeal($dealId, $dealType, $tmplid);
             break;
         case 'listpanel':
             $listType = JRequest::getVar('listype');
             if ($listType == 1 || $listType == 7) {
                 frontHTML::showPanel('list');
             }
             break;
         case 'cancel':
             frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING);
             break;
         case 'delete':
             JRequest::checkToken() or die('Invalid Token');
             if (empty($mailingId)) {
                 echo '<script> javascript:alert("' . _JNEWS_DELETE_MAILING . '"); javascript:history.go(-1); </script>';
             } else {
                 $d['mailing'] = jNews_Mailing::getOneMailing('', $mailingId, '', $new);
                 echo jnews::printYN(jNews_Mailing::delete($d), @constant($GLOBALS[JNEWS . 'listname' . $d['mailing']->list_type]) . _JNEWS_SUCCESS_DELETED, _JNEWS_ERROR);
                 frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING);
             }
             break;
         case 'togle':
             // defined toggle for publish and unpublish of mailings
             $id = JRequest::getVar('mailingid');
             $col = JRequest::getVar('col');
             $mailingId = !empty($id) && !empty($col) ? $id : $mailingId;
             $task = !empty($mailingId) && !empty($col) ? $col : $task;
             switch ($task) {
                 case 'publishMailing':
                     $mailing = jNews_Mailing::getOneMailing('', $mailingId, '', $new);
                     jNews_Mailing::publishMailing($mailingId);
                     break;
                 case 'unpublishMailing':
                     $mailing = jNews_Mailing::getOneMailing('', $mailingId, '', $new);
                     jNews_Mailing::unpublishMailing($mailingId);
                     break;
                 default:
                     break;
             }
             echo '<script> javascript:history.go(-1); </script>';
             break;
         case 'edit':
             if ($GLOBALS[JNEWS . 'enable_jsub']) {
                 if (!empty($my->id)) {
                     $ownedlists = jNews_Lists::getOwnedlists($my->id);
                 }
                 if (!empty($ownedlists) || jnews::checkPermissions('admin')) {
                     if (empty($mailingId)) {
                         echo '<script> javascript:alert("' . _JNEWS_SELECT_MAILING . '"); javascript:history.go(-1); </script>';
                     } else {
                         frontEnd::mailingEdit($subscriberId, $mailingId, $listId, $listType, 'mailing');
                         //savemailing
                     }
                 }
             } else {
                 //edit a mailing
                 $canAccess = false;
                 if (class_exists('jNews_Pro') && !empty($listId)) {
                     $list = jNews_Lists::getOneList($listId);
                     $accessAuthorizedA = explode(',', $list->acc_id);
                     if (!is_array($accessAuthorizedA) || $accessAuthorizedA[0] != 'all') {
                         if (version_compare(JVERSION, '1.6.0', '<')) {
                             //j15
                             $usergid = $my->gid;
                         } else {
                             //j16
                             $usergid = JAccess::getGroupsByUser($my->id, false);
                         }
                         if (is_array($accessAuthorizedA)) {
                             if (is_array($usergid)) {
                                 $canAccess = array_intersect($usergid, $accessAuthorizedA);
                             } else {
                                 if (!in_array($usergid, $accessAuthorizedA)) {
                                     $canAccess = false;
                                 }
                             }
                         } else {
                             if (is_array($usergid)) {
                                 $canAccess = array_intersect($usergid, $accessAuthorizedA);
                             } else {
                                 if ($usergid != $accessAuthorizedA) {
                                     $canAccess = false;
                                 }
                             }
                         }
                     }
                 }
                 //cehck if I am the owner of the list
                 $archivemailing = jNews_Mailing::getOneMailing(0, $mailingId, 0, $new);
                 if ($archivemailing->author_id == $my->id) {
                     $canAccess = true;
                 }
                 if ($canAccess || jnews::checkPermissions('admin') || jnews::checkPermissions($gid) || !empty($listsAddEdit)) {
                     if (empty($mailingId)) {
                         echo '<script> javascript:alert("' . _JNEWS_SELECT_MAILING . '"); javascript:history.go(-1); </script>';
                     } else {
                         frontEnd::mailingEdit($subscriberId, $mailingId, $listId, $listType, 'mailing', $canAccess);
                         //savemailing
                     }
                 }
             }
             break;
         case 'new':
         case 'add':
             if ($GLOBALS[JNEWS . 'enable_jsub']) {
                 if (!empty($my->id)) {
                     $ownedlists = jNews_Lists::getOwnedlists($my->id);
                 }
                 if (!empty($ownedlists) || jnews::checkPermissions('admin')) {
                     frontEnd::mailingEdit($subscriberId, $mailingId, $listId, $listType, 'mailing');
                     //savemailing
                 }
             } else {
                 //$list = jNews_Lists::getOneList($listId);
                 $canAccess = false;
                 if (class_exists('jNews_Pro') && !empty($listId)) {
                     $list = jNews_Lists::getOneList($listId);
                     $accessAuthorizedA = explode(',', $list->acc_id);
                     if (!is_array($accessAuthorizedA) || $accessAuthorizedA[0] != 'all') {
                         if (version_compare(JVERSION, '1.6.0', '<')) {
                             //j15
                             $usergid = $my->gid;
                         } else {
                             //j16
                             $usergid = JAccess::getGroupsByUser($my->id, false);
                         }
                         if (is_array($accessAuthorizedA)) {
                             if (is_array($usergid)) {
                                 $canAccess = array_intersect($usergid, $accessAuthorizedA);
                             } else {
                                 if (!in_array($usergid, $accessAuthorizedA)) {
                                     $canAccess = false;
                                 }
                             }
                         } else {
                             if (is_array($usergid)) {
                                 $canAccess = array_intersect($usergid, $accessAuthorizedA);
                             } else {
                                 if ($usergid != $accessAuthorizedA) {
                                     $canAccess = false;
                                 }
                             }
                         }
                     }
                 }
                 if ($canAccess || jnews::checkPermissions('admin') || jnews::checkPermissions($gid) || !empty($listsAddEdit)) {
                     frontEnd::mailingEdit($subscriberId, $mailingId, $listId, $listType, 'mailing', true);
                     //savemailing
                 }
             }
             break;
         case 'archive':
             if (class_exists('jNews_Pro')) {
                 $list = jNews_Lists::getOneList($listId);
                 $listIds = explode(',', $list->acc_id);
                 if (!is_array($listIds) || $listIds[0] != 'all') {
                     if (version_compare(JVERSION, '1.6.0', '<')) {
                         //j15
                         $usergid = $my->gid;
                     } else {
                         if (version_compare(JVERSION, '3.0.0', '>')) {
                             //j3.0
                             $usergid = JAccess::getGroupsByUser($my->id, false);
                             //this is huck for joomla >3.0 because if you check this link http://joomla.dev/administrator/index.php?option=com_config&view=component&component=com_users&return=aHR0cDovL2pvb21sYS5kZXYvYWRtaW5pc3RyYXRvci9pbmRleC5waHA%2Fb3B0aW9uPWNvbV91c2VycyZ2aWV3PWdyb3Vwcw%3D%3D
                             //you will see  Guest User Group = Public by default and into db table #__extensions where element == com_users => params => you will see guest_usergroup == 13
                             // but if you try to change user group in brovser to registered for example => save=>save again as public => check again db=> you will see guest_usergroup = 1
                             //i think it is joomla bug because if jommla woks fine needs to be 13
                             // thants why i created this "if"
                             if ($usergid[0] === '13') {
                                 $usergid[0] = '1';
                             }
                         } else {
                             //j16
                             $usergid = JAccess::getGroupsByUser($my->id, false);
                         }
                     }
                     if (is_array($listIds)) {
                         if (is_array($usergid)) {
                             $canAccess = array_intersect($usergid, $listIds);
                             if (empty($canAccess)) {
                                 break;
                             }
                         } else {
                             if (!in_array($usergid, $listIds)) {
                                 break;
                             }
                         }
                     } else {
                         if (is_array($usergid)) {
                             $canAccess = array_intersect($usergid, $listIds);
                             if (empty($canAccess)) {
                                 break;
                             }
                         } else {
                             if ($usergid != $listIds) {
                                 break;
                             }
                         }
                     }
                 }
             }
             frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, true, _JNEWS_MENU_VIEW_ARCHIVE . ' ');
             break;
         case 'save':
             JRequest::checkToken() or die('Invalid Token');
             $message = jnews::printYN(jNews_Mailing::saveMailing($mailingId, $listId), _JNEWS_MAILING_SAVED, _JNEWS_ERROR);
             frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING);
             break;
         case 'savepreview':
             JRequest::checkToken() or die('Invalid Token');
             $message = jnews::printYN(jNews_Mailing::saveMailing($mailingId, $listId), _JNEWS_MAILING_SAVED, _JNEWS_ERROR);
         case 'preview':
         case 'view':
             if ($mailingId != 0) {
                 if ($listId > 0) {
                     $archivemailing = jNews_Mailing::getMailingView($mailingId, $listId);
                 } else {
                     $archivemailing = jNews_Mailing::getMailingView($mailingId);
                 }
                 $list = jNews_Lists::getOneList($listId);
                 $acc_level = $list->acc_level;
                 jNews_ProcessMail::replaceClass($archivemailing->htmlcontent, $archivemailing->textonly);
                 if (!empty($archivemailing->template_id)) {
                     jNews_Templates::includeStyles($archivemailing->htmlcontent, $archivemailing->template_id);
                 }
                 $archivemailing->htmlcontent = str_replace('{tag:subscriptions}', '', $archivemailing->htmlcontent);
                 $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION);
                 $forms['main'] = '<form method="post" action="' . $mainLink . '" onsubmit="submitbutton();return false;" name="mosForm" >' . "\n\r";
                 $forms['main'] .= '<input type="hidden" name="Itemid" value="' . $Itemid . '" />';
                 //for view it online view
                 $currentUrl = JURI::current();
                 $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);
                     if (!$my->id) {
                         $listsAddEdit = array();
                     } else {
                         $listsAddEdit = jNews_Lists::getIDswithacclevel($groups);
                     }
                 }
                 if (jnews::checkPermissions('admin') || jnews::checkPermissions($gid) || !empty($listsAddEdit)) {
                     $menuA = array();
                     $onlyPreview = JRequest::getInt('onlypreview');
                     if (!$onlyPreview) {
                         //menu Preview
                         $menuNew = new stdClass();
                         $menuNew->popup = new stdClass();
                         $menuNew->popup->isPop = false;
                         $menuNew->action = 'view';
                         $linkBut = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=view&mailingid=' . $mailingId . '&onlypreview=1');
                         $menuNew->link = $linkBut;
                         $menuNew->onclick = new stdClass();
                         $menuNew->onclick->custom = true;
                         $menuNew->onclick->js = '';
                         $menuNew->title = _JNEWS_VIEW_BROWSER;
                         $menuA['view'] = $menuNew;
                         //menu edit
                         $menuNew = new stdClass();
                         $menuNew->popup = new stdClass();
                         $menuNew->popup->isPop = false;
                         $menuNew->action = 'edit';
                         $linkBut = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=edit&mailingid=' . $mailingId . '&listype=' . $listType);
                         $menuNew->link = $linkBut;
                         $menuNew->onclick = new stdClass();
                         $menuNew->onclick->custom = true;
                         $menuNew->onclick->js = '';
                         $menuNew->title = 'Edit';
                         $menuA['edit'] = $menuNew;
                         //menu send
                         $menuSend = new stdClass();
                         $menuSend->popup = new stdClass();
                         $menuSend->popup->isPop = true;
                         $menuSend->popup->rel = true;
                         $menuSend->popup->x = 750;
                         $menuSend->popup->y = 500;
                         $linkBut = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=sendready&mailingid=' . $mailingId . '&listype=' . $listType, true, false, true);
                         $menuSend->link = $linkBut;
                         $menuSend->action = 'sendready';
                         $menuSend->onclick = new stdClass();
                         $menuSend->onclick->custom = false;
                         $menuSend->onclick->js = "";
                         $menuSend->title = _JNEWS_MENU_SEND;
                         $menuA['sendready'] = $menuSend;
                         // menu back
                         $menuBack = new stdClass();
                         $menuBack->popup = new stdClass();
                         $menuBack->popup = new stdClass();
                         $menuBack->popup->isPop = false;
                         $menuBack->link = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing', false);
                         $menuBack->action = 'back';
                         $menuBack->onclick = new stdClass();
                         $menuBack->onclick->custom = true;
                         $menuBack->onclick->js = '';
                         $menuBack->title = _JNEWS_MENU_BACK;
                         $menuA['back'] = $menuBack;
                     }
                     frontHTML::formStart(_JNEWS_NEWSLETTER_ARCHIVE, 0, '', $menuA);
                 } else {
                     //can be improved where we check if user can edit
                     if (empty($archivemailing->visible) || empty($archivemailing->published) && $task == 'view') {
                         echo '<center>Access to this mailing is restricted!<center>';
                         break;
                     }
                     frontHTML::formStart(_JNEWS_NEWSLETTER_ARCHIVE, 0, '', null);
                 }
                 jNews_MailingsHTML::viewMailing($archivemailing, $forms);
                 $go[] = jnews::makeObj('act', 'mailing');
                 $go[] = jnews::makeObj('task', 'viewmailing');
                 $go[] = jnews::makeObj('listid', $archivemailing->list_id);
                 frontHTML::formEnd('', $go);
             } else {
                 frontHTML::FEmenu();
                 frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING);
             }
             break;
         case 'sendready':
             //we update the senddate of the newsletter
             jNews_Mailing::updatesenddate($mailingId);
             jNews_MailingsHTML::sendReady($mailingId, $listId, $listType);
             break;
         case 'send':
             if (!(require_once JNEWSPATH_CLASS . 'class.queue.php')) {
                 return false;
             }
             $queueC = new jNews_Queue();
             $queueC->checkForNewsletters($mailingId);
             $queueCount = jNews_Queue::getQueueCount($mailingId);
             $totalSub = JRequest::setVar('totalsend', $queueCount);
             $linkBut = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=continuesend&mailingid=' . $mailingId . '&totalsend=' . $totalSub, true, false, true);
             jNews_Tools::redirect($linkBut);
             //this line was commented out, we need this so that when we click the send button in the frontend the status of the sending will be displayed
             break;
         case 'continuesend':
             if (require_once JNEWSPATH_CLASS . 'class.queue.php') {
                 $queueC = new jNews_Queue();
                 $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 'unpublished':
             JRequest::checkToken() or die('Invalid Token');
             jNews_Mailing::unpublishMailing($mailingId);
             frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING);
             break;
         case 'copy':
             JRequest::checkToken() or die('Invalid Token');
             $message = jnews::printYN(jNews_Mailing::copyMailing($mailingId), _JNEWS_MAILING_COPY, _JNEWS_ERROR);
             if (empty($listId) or $listId == 0) {
                 $lsid = jNews_Mailing::getListId($mailingId);
             }
             jNews_Mailing::insertListMailings($listId);
             frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING);
             break;
         case 'cpanel':
             jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION);
             break;
         default:
             //alex archive
             //				$viewarchive = false;
             //				if(empty($my->id)) $viewarchive = true;
             $viewarchive = true;
             frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, $viewarchive, _JNEWS_MENU_MAILING);
             break;
     }
     return true;
 }
예제 #2
0
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;
}