Ejemplo n.º 1
0
 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;
 }