Exemple #1
0
    /**
     * This public static function is used for the view of sendReady for manual sending
     */
    public static function sendReady($mailingId, $listId, $listType)
    {
        ?>
		<div id="manualsend"></div>
		<?php 
        JHTML::_('behavior.modal');
        $formLink3 = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=send', true, false, true);
        ?>
		<form class="modal" action="<?php 
        echo $formLink3;
        ?>
" method="post" name="adminForm" autocomplete="off" id="adminForm">
			<div>
			<fieldset class="adminform">
			<legend>
				<?php 
        echo 'Sending Status';
        ?>
			</legend>
			<?php 
        $doc = JFactory::getDocument();
        $doc->addStyleSheet(JNEWS_URL_ADMIN . 'cssadmin/jnews.css');
        if (empty($mailingId) || $mailingId == 0) {
            $warning = 'Please select a newsletter to be sent.';
            jnews::displayInfo($warning, 'warning');
            return;
        }
        $queueCount = jNews_Queue::getQueueCount($mailingId);
        $new = false;
        $mailing = jNews_Mailing::getOneMailing('', $mailingId, '', $new);
        if (empty($queueCount)) {
            if (empty($listId)) {
                $listIds = jNews_Mailing::getMailingList($mailingId);
            }
            if (!empty($listIds)) {
                ?>
			<br/>
			<fieldset class="adminform">
			<legend>
				<?php 
                echo $mailing->subject . ' will be sent to ';
                ?>
			</legend>
			<br/>
				<table class="adminlist" cellspacing="1" align="center">
					<tbody>
						<?php 
                $listNames = jNews_Mailing::getMailingListName($listIds);
                foreach ($listNames as $key => $listName) {
                    if (isset($listIds[$key])) {
                        ?>
									<tr><td><?php 
                        echo $listName . ' ( ' . jNews_Subscribers::getSubscribersCount($listIds[$key], true, true, true) . ' subscribers ) ';
                        ?>
</td></tr>
								<?php 
                    }
                }
                ?>
					</tbody>
				</table>
				<br/>
			</fieldset>
			<?php 
            } else {
                $warning = $mailing->subject . ' will be sent to none of the created Lists.';
                jnews::displayInfo($warning, 'warning');
            }
        } else {
            $info = 'There are ' . $queueCount . ' in the queue for the Newsletter ' . $mailing->subject . ' <br/>Do you want to continue sending this newsletter?';
            jnews::displayInfo($info, 'info');
            ?>
<input type="hidden" name="totalsend" value="<?php 
            echo $queueCount;
            ?>
" />
			<?php 
        }
        ?>
			<br/>
			<input type="submit" value="<?php 
        echo empty($queueCount) ? _JNEWS_MENU_SEND : _JNEWS_MENU_CONTINUE;
        ?>
">
			<input type="hidden" name="mailingid" value="<?php 
        echo $mailingId;
        ?>
" />
			<input type="hidden" name="option" value="<?php 
        echo JNEWS_OPTION;
        ?>
" />
			<input type="hidden" name="task" value="<?php 
        echo empty($queueCount) ? 'send' : 'continuesend';
        ?>
" />
			<input type="hidden" name="act" value="mailing" />
		<?php 
        if (version_compare(JVERSION, '3.0.0', '<')) {
            echo JHTML::_('form.token');
        } else {
            echo JHtml::_('form.token');
        }
        ?>
		</div>
		</form>
		<?php 
    }
Exemple #2
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;
 }
Exemple #3
0
    /** Send element stored in the queue
     * @return bool if the queue still have values to be sent then return true ( for manual send ) otherwise return false
     */
    function sendQueue($showHTML = false, $mailingId = null, $onlyAutoRsponder = false, $manualSend = false)
    {
        $showHTML = true;
        $stillProcess = null;
        $maxTask = $manualSend ? $this->limitEmails : $this->maxQueue;
        if ($maxTask < 1) {
            $maxTask = 1;
        }
        if ($maxTask > 1000) {
            $maxTask = 1000;
        }
        //8889990
        $arPRiority = empty($GLOBALS[JNEWS . 'ar_prior']) ? 1 : $GLOBALS[JNEWS . 'ar_prior'];
        //get all the queue
        $query = 'SELECT A.qid,A.subscriber_id,A.attempt, A.params as `qparams`, A.delay as `qdelay`, B.* FROM `#__jnews_queue` as A';
        $query .= ' LEFT JOIN `#__jnews_mailings` as B on A.mailing_id = B.id ';
        $query .= ' WHERE A.send_date <= ' . time() . ' AND B.published > 0 AND A.type != 8 AND A.type != 99';
        if (!empty($mailingId)) {
            $query .= ' AND A.mailing_id = ' . $mailingId;
        }
        if ($onlyAutoRsponder && $GLOBALS[JNEWS . 'level'] > 1) {
            $query .= ' AND A.`priority` = ' . $arPRiority;
        }
        //do not select the suspend
        $query .= ' AND `suspend`= 0';
        //filter for unconfirmed subscribers
        $query .= ' AND `block` = 0';
        //filter the entries are still being processed from the last sending/processing of the queue
        $query .= ' ORDER BY A.`priority` ASC, A.send_date ASC';
        $query .= ' LIMIT ' . $maxTask;
        $this->db->setQuery($query);
        $allQueuedA = $this->db->loadObjectList();
        $error = $this->db->getErrorMsg();
        if (!empty($error)) {
            //prompt message if an error occured while retrieving entries from the queue
            echo '<br><br><span style="font-weight:bold; font-style:italic; color:blue;">' . _JNEWS_QUEUE_PROCESS_ERROR . '<span><br><br>';
            echo $error;
        }
        if (empty($allQueuedA)) {
            echo '<br><br><span style="font-weight:bold; font-style:italic; color:blue;">' . _JNEWS_NO_MAILINGS_YET . '<span>';
            // prompt message if there is nothing to send
            jNews_Queue::sendReport();
            return false;
        }
        //we update the retrieved allQueuedA to blocked so that  the entries will not be processed double
        foreach ($allQueuedA as $oneQueue) {
            $this->updateQueueBlock($oneQueue->qid, 1);
        }
        $totalSubscribers = count($allQueuedA);
        //make an array of all subscribers and all mailings
        $mySubcribersA = array();
        $subscribersPerMailingsA = array();
        foreach ($allQueuedA as $oneQueue) {
            $mySubcribersA[$oneQueue->subscriber_id] = true;
        }
        //get all the subcribers
        $query = 'SELECT A.`id`,A.`user_id`,A.`name`,A.`email`,A.`receive_html`,A.`confirmed`,A.`blacklist`, B.`id` AS \'user\' ';
        if ($GLOBALS[JNEWS . 'level'] > 2) {
            //check if the version of jnews is pro
            if ($GLOBALS[JNEWS . 'show_column1']) {
                $query .= ',A.`column1`';
            }
            if ($GLOBALS[JNEWS . 'show_column2']) {
                $query .= ',A.`column2`';
            }
            if ($GLOBALS[JNEWS . 'show_column3']) {
                $query .= ',A.`column3`';
            }
            if ($GLOBALS[JNEWS . 'show_column4']) {
                $query .= ',A.`column4`';
            }
            if ($GLOBALS[JNEWS . 'show_column5']) {
                $query .= ',A.`column5`';
            }
        }
        $query .= ' FROM `#__jnews_subscribers` AS A  ';
        $query .= ' LEFT JOIN  `#__users` AS B ON A.id=B.id';
        $query .= ' WHERE A.`id` IN (' . jnews::implode(',', array_keys($mySubcribersA)) . ' )';
        $this->db->setQuery($query);
        $allSubcribersA = $this->db->loadObjectList('id');
        if (empty($allSubcribersA)) {
            jNews_Queue::sendReport();
            return false;
        }
        $mailerC = new jNews_ProcessMail();
        $queueToBeDelted = array();
        $queueToBeAttempted = array();
        $queueSuccessfullySent = array();
        $addToStatisticsA = array();
        $log_detailed = '';
        $message = '';
        $screenMsg = '';
        $maxAttempt = $GLOBALS[JNEWS . 'max_attempts'] < 1 ? 1 : $GLOBALS[JNEWS . 'max_attempts'];
        if ($this->total == 0) {
            $this->total = jNews_Queue::getQueueCount($mailingId);
        }
        //for manual sending processing
        if ($manualSend) {
            if (!headers_sent() and ob_get_level() > 0) {
                @ob_end_flush();
            }
            $url = JURI::base() . jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=continuesend&mailingid=' . $mailingId . '&totalsend=' . $this->total . '&alreadysent=', true, false, true);
            $screenMsg = "<div style='position:fixed; top:3px;left:3px;color:orange; padding : 3px;'>";
            $screenMsg .= "<span id='waitinginfo' style='padding:10px;margin:5px;font-size:16px;font-weight:bold;display:none;background-color:#FFF8C6; color:red;'> </span>";
            $screenMsg .= '<i>' . _JNEWS_SENDING_EMAIL . ' <span id="emailcounter"/><strong>' . $this->start . '</strong></span> out of <strong>' . $this->total . '</strong>... </i>';
            $screenMsg .= "</div><div id='details' style='display:none; position:fixed; bottom:3px;left:3px;background-color : white; border : 1px solid grey; padding : 3px;'> </div><br /><br />";
            $screenMsg .= '<script type="text/javascript" language="javascript">';
            $screenMsg .= 'var myEmailCounter = document.getElementById("emailcounter");';
            $screenMsg .= 'var details = document.getElementById("details");
var waitinginfo = document.getElementById("waitinginfo");
function setDetails(message){ details.style.display = \'block\';details.innerHTML=message; }
function setWaitingInfo(waitingtime){ waitinginfo.style.display = \'\';waitinginfo.innerHTML="Waiting "+waitingtime+" seconds..."; }
function setEmailCounter(val){ myEmailCounter.innerHTML=val;}
var waitingtime = ' . intval($this->pause) . ';
function setWaitingTime(){
	setWaitingInfo(waitingtime);
	if(waitingtime > 0){
		waitingtime = waitingtime - 1;
		setTimeout(\'setWaitingTime()\',1000);
	}else{
		document.location.href=\'' . $url . '\'+myEmailCounter.innerHTML;
	}
}
</script>';
            echo $screenMsg;
            if (function_exists('ob_flush')) {
                @ob_flush();
            } else {
                @flush();
            }
        }
        //we assign counter for the current email being processed
        $counterEmail = $this->start;
        //we determine if the mailings on the queue is lesser than the limit given per batch of manual sending
        if (count($allQueuedA) < $maxTask) {
            $stillProcess = false;
        }
        //get the size of the queue
        foreach ($allQueuedA as $oneQueue) {
            $counterEmail++;
            if ($manualSend) {
                echo '<script type="text/javascript" language="javascript">setEmailCounter(' . $counterEmail . ')</script>';
                if (function_exists('ob_flush')) {
                    @ob_flush();
                }
                @flush();
            }
            //attachements
            if (!empty($oneQueue->attachments)) {
                $oneQueue->attachments = explode("\n", $oneQueue->attachments);
                if (count($oneQueue->attachments) != 0 && trim($oneQueue->attachments[count($oneQueue->attachments) - 1]) == "") {
                    array_pop($oneQueue->attachments);
                }
            } else {
                $oneQueue->attachments = array();
            }
            //images
            if (!empty($oneQueue->images)) {
                $oneQueue->images = explode("\n", $oneQueue->images);
            } else {
                $oneQueue->images = array();
            }
            //5 is maximun attempt
            if ($oneQueue->attempt >= $maxAttempt) {
                $queueToBeDelted[] = $oneQueue->qid;
                continue;
            }
            if (!isset($this->sentHTML[$oneQueue->id])) {
                $this->sentHTML[$oneQueue->id] = 0;
            }
            if (!isset($this->sentText[$oneQueue->id])) {
                $this->sentText[$oneQueue->id] = 0;
            }
            if (!isset($this->sentFailed[$oneQueue->id])) {
                $this->sentFailed[$oneQueue->id] = 0;
            }
            if (isset($allSubcribersA[$oneQueue->subscriber_id]) && is_object($allSubcribersA[$oneQueue->subscriber_id])) {
                $emailSentStatus = $mailerC->send($oneQueue, $allSubcribersA[$oneQueue->subscriber_id]);
                if ($emailSentStatus) {
                    //we update the senddate of the newsletter
                    jNews_Mailing::updatesenddate($oneQueue->id);
                }
            } else {
                continue;
            }
            if (!empty($allSubcribersA[$oneQueue->subscriber_id]->email)) {
                if ($GLOBALS[JNEWS . 'save_log']) {
                    if (!$emailSentStatus) {
                        $log_detailed .= '[' . $oneQueue->id . '] ' . $oneQueue->subject . ' : ' . $allSubcribersA[$oneQueue->subscriber_id]->email . ' -> ' . _JNEWS_MESSAGE_NOT . "\r\n" . _JNEWS_MAILER_ERROR . ': ' . $mailerC->ErrorInfo . "\r\n";
                    } else {
                        $log_detailed .= '[' . $oneQueue->id . '] ' . $oneQueue->subject . ' : ' . $allSubcribersA[$oneQueue->subscriber_id]->email . ' -> ' . _JNEWS_MESSAGE_SENT_SUCCESSFULLY . "\r\n";
                    }
                } else {
                    $log_detailed .= '[' . $oneQueue->id . '] ' . $oneQueue->subject . ' : ' . $allSubcribersA[$oneQueue->subscriber_id]->email . ' -> ' . _JNEWS_MESSAGE_SENT_SUCCESSFULLY . "\r\n";
                }
            }
            //Screen message for manual sending
            if ($manualSend) {
                if ($emailSentStatus) {
                    $message = '<strong><i>' . $oneQueue->subject . '</i></strong> ' . _JNEWS_MSG_SENT_SUCCESS . ' <strong><i>' . $allSubcribersA[$oneQueue->subscriber_id]->name . ' ( ' . $allSubcribersA[$oneQueue->subscriber_id]->email . ' )</i></strong>' . "\r\n";
                } else {
                    $message = '<i>' . _JNEWS_ATTEMPTED . ' ' . $oneQueue->subject . ' to ' . $allSubcribersA[$oneQueue->subscriber_id]->name . ' ( ' . $allSubcribersA[$oneQueue->subscriber_id]->email . ' )' . ".\r\n" . _JNEWS_RESCHEDULED . "\r\n\r\n" . _JNEWS_REACHED_MAX_ATTEMPT . "</i>\r\n\r\n";
                }
                $this->_displayDetails($message, $emailSentStatus, $counterEmail);
            }
            if ($emailSentStatus) {
                //succeess send
                $query = 'DELETE FROM `#__jnews_queue` WHERE `qid`=' . $oneQueue->qid;
                $this->db->setQuery($query);
                $this->db->query();
                if ($mailerC->html) {
                    $this->sentHTML[$oneQueue->id]++;
                } else {
                    $this->sentText[$oneQueue->id]++;
                }
                //user statistics
                if ($GLOBALS[JNEWS . 'enable_statistics'] && $GLOBALS[JNEWS . 'statistics_per_subscriber']) {
                    $addToStatisticsA[$oneQueue->id][$oneQueue->subscriber_id] = (int) $mailerC->html;
                }
                $this->sentSuccess++;
                $this->recurringError = 0;
                $queueSuccessfullySent[] = $oneQueue->qid;
                //we save the successfully sent qids so that we can differentiate from the allqueue what qids that were not processed because the max execution time has been reached
            } else {
                // failed send
                $queueToBeAttempted[] = $oneQueue->qid;
                $this->sentFailed[$oneQueue->id]++;
                $this->recurringError++;
            }
            $time = time();
            if ($this->maxExetime != 0 && $this->maxExetime <= $time) {
                $stillProcess = true;
                break;
            }
            if ($this->recurringError > 2 && $this->sentSuccess > 3) {
                $stillProcess = false;
                break;
            }
            if ($this->recurringError > 5 || connection_aborted()) {
                $stillProcess = false;
                break;
            }
        }
        //we close the processing of emails
        $mail = JFactory::getMailer();
        $mailerC->close($mail);
        if (!empty($this->total) && $counterEmail >= $this->total) {
            $stillProcess = false;
        }
        //update queue with try + 1;
        if (!empty($queueToBeAttempted)) {
            $query = 'UPDATE `#__jnews_queue` SET `attempt`=`attempt`+1,`send_date`=`send_date`+`attempt`*25299+4000, `block`= 0 WHERE `qid` IN (' . jnews::implode(',', $queueToBeAttempted) . ')';
            //we will also update the block to 0 so that it will be processed again
            $this->db->setQuery($query);
            $this->db->query();
        }
        //delete the queue when the emails are sent successfully after x number of attempts
        if (!empty($queueToBeDelted)) {
            $query = 'DELETE FROM `#__jnews_queue` WHERE `qid` IN (' . jnews::implode(',', $queueToBeDelted) . ')';
            $this->db->setQuery($query);
            $this->db->query();
        }
        //unblock again the queue that were not sent because the timeout has been reached so that they will be processed again
        if (!empty($allQueuedA)) {
            foreach ($allQueuedA as $oneQueue) {
                if (!in_array($oneQueue->qid, $queueSuccessfullySent)) {
                    $query = 'UPDATE `#__jnews_queue` SET `block` = 0 WHERE `qid` =' . $oneQueue->qid;
                    $this->db->setQuery($query);
                    $this->db->query();
                }
            }
        }
        //we update and increment the statistics
        if ($GLOBALS[JNEWS . 'enable_statistics']) {
            $this->_updateStatsGlobal($allQueuedA);
        }
        if (!empty($addToStatisticsA)) {
            $this->_insertStats($addToStatisticsA);
        }
        //we prompt message that the mailing has been sent successfully for each batch
        //		echo '<br><br><span style="font-weight:bold; font-style:italic; color:green;">'.$oneQueue->subject.' successfully sent to subscribers.'.'</span> ';
        //mailing reports
        $this->_writeLogs($log_detailed);
        if (isset($stillProcess)) {
            //manual sending
            if ($stillProcess && $manualSend) {
                echo '<script type="text/javascript" language="javascript">setWaitingTime();</script>';
            } else {
                echo '<br><br><span style="font-weight:bold; font-style:italic; color:green;">' . _JNEWS_THE_MAILING . $oneQueue->subject . _JNEWS_SENT_ALL . '</span> ';
                //					$subject = 'jNews Mailing Notification - Status: End';
                //					$content = 'The mailing '.$oneQueue->subject.' has been successfully sent.';
                //					if( version_compare(JVERSION,'1.6.0','<') ){ //j15
                //						$this->db->setQuery( "SELECT * FROM `#__users` WHERE `gid` = 25 ORDER BY `id` ASC LIMIT 1" );
                //					}else{
                //						$this->db->setQuery( "SELECT * FROM `#__users` AS U LEFT JOIN `#__user_usergroup_map` AS UGM ON U.id =UGM.user_id  WHERE `group_id` = 8 ORDER BY `id` ASC LIMIT 1" );
                //					}
                //					$admin = $this->db->loadObject();
                //
                //					JUTility::sendMail($admin->email, $admin->name, $admin->email, $subject, $content );
            }
            if (!$stillProcess) {
                jNews_Queue::sendReport();
            }
            return $stillProcess ? true : false;
        } else {
            //manual sending
            if ($manualSend && $maxTask < $this->total) {
                echo '<script type="text/javascript" language="javascript">setWaitingTime();</script>';
            } else {
                echo '<br><br><span style="font-weight:bold; font-style:italic; color:green;">' . _JNEWS_THE_MAILING . $oneQueue->subject . _JNEWS_SENT_ALL . '</span> ';
                //					$subject = 'jNews Mailing Notification - Status: End';
                //					$content = 'The mailing '.$oneQueue->subject.' has been successfully sent.';
                //					if( version_compare(JVERSION,'1.6.0','<') ){ //j15
                //						$this->db->setQuery( "SELECT * FROM `#__users` WHERE `gid` = 25 ORDER BY `id` ASC LIMIT 1" );
                //					}else{
                //						$this->db->setQuery( "SELECT * FROM `#__users` AS U LEFT JOIN `#__user_usergroup_map` AS UGM ON U.id =UGM.user_id  WHERE `group_id` = 8 ORDER BY `id` ASC LIMIT 1" );
                //					}
                //					$admin = $this->db->loadObject();
                //
                //					JUTility::sendMail($admin->email, $admin->name, $admin->email, $subject, $content );
            }
            if ($this->maxQueue > count($allQueuedA)) {
                jNews_Queue::sendReport();
            }
            return $this->maxQueue > count($allQueuedA) ? false : true;
        }
    }
Exemple #4
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;
}
Exemple #5
0
function queue($action, $task, $listid, $mailingid, $lists, $cid)
{
    $db = JFactory::getDBO();
    $my = JFactory::getUser();
    $start = JRequest::getInt('start');
    $css = '.icon-48-queue { background-image:url(' . JNEWS_PATH_ADMIN_IMAGES2 . 'header/queue.png)}';
    $doc = JFactory::getDocument();
    $doc->addStyleDeclaration($css, $type = 'text/css');
    $img = 'queue.png';
    $message = '';
    $xf = new jNews_Config();
    $conf = JFactory::getConfig();
    $mail = new stdClass();
    $mail->Mailer = $conf->get('config.mailer');
    $mailingsearch = JRequest::getVar('mailingsearch', '');
    $start = JRequest::getInt('start');
    $limit = JRequest::getInt('limit', $conf->get('config.list_limit'));
    ?>

<script language="javascript" type="text/javascript">
function submitbutton(pressbutton) {
	var form = document.adminForm;
	if (pressbutton == 'cpanel') {
		form.action = 'index.php?option=<?php 
    echo JNEWS_OPTION;
    ?>
&act=queue&task=cpanel';
	}else if (pressbutton == 'pqueue') {
		var $ok = confirm('Are you sure you want to process queue?');
		if ( $ok == true ){
			form.action = 'index.php?option=<?php 
    echo JNEWS_OPTION;
    ?>
&act=queue&task=pqueue';
		}else{
			return;
		}
	}else if (pressbutton == 'stopqueue') {
		var $ok = confirm('Are you sure you want to stop the queue?');
		if ( $ok == true ){
			form.action = 'index.php?option=<?php 
    echo JNEWS_OPTION;
    ?>
&act=queue&task=stopqueue';
		}else{
			return;
		}
	}else if (pressbutton == 'startqueue') {
		var $ok = confirm('Are you sure you want to start the queue?');
		if ( $ok == true ){
			form.action = 'index.php?option=<?php 
    echo JNEWS_OPTION;
    ?>
&act=queue&task=startqueue';
		}else{
			return;
		}
	}else if (pressbutton == 'delq') {
		var $ok = confirm('Are you sure you want to delete?');
		if ( $ok == true ){
			form.action = 'index.php?option=<?php 
    echo JNEWS_OPTION;
    ?>
&act=queue&task=delq';
		}else{
			return;
		}
	}else if (pressbutton == 'cleanq') {
		var $ok = confirm('Are you sure you want to clear the queue?');
		if ( $ok == true ){
			form.action = 'index.php?option=<?php 
    echo JNEWS_OPTION;
    ?>
&act=queue&task=cleanq';
		}else{
			return;
		}
	}else if (pressbutton == 'block') {
		var $ok = confirm('Are you sure you want to block selected entries?');
		if ( $ok == true ){
			form.action = 'index.php?option=<?php 
    echo JNEWS_OPTION;
    ?>
&act=queue&task=block';
		}else{
			return;
		}
	}else if (pressbutton == 'unblock') {
		var $ok = confirm('Are you sure you want to unblock selected entries?');
		if ( $ok == true ){
			form.action = 'index.php?option=<?php 
    echo JNEWS_OPTION;
    ?>
&act=queue&task=unblock';
		}else{
			return;
		}
	}
	submitform( pressbutton );
}
</script>
	<?php 
    $message = JRequest::getVar('message', '');
    $showqueue = true;
    switch ($task) {
        case 'pqueue':
            if (!$GLOBALS[JNEWS . 'queue_status']) {
                //we start the processing of queue
                $xf->update('queue_status', 1);
                $GLOBALS[JNEWS . 'queue_status'] = 1;
            }
            //create smart-newsletter if necessary
            if (class_exists('jNews_Autonews')) {
                $SmartNewsMessageHTML = jNews_Autonews::createSmartNewsletters();
            } else {
                $SmartNewsMessageHTML = '';
            }
            $queueC = new jNews_Queue();
            $queuedMails = $queueC->queueStatus($mailingid);
            $nextQueuedMails = $queueC->queueStatus($mailingid);
            // , true
            if ($GLOBALS[JNEWS . 'level'] > 1) {
                $scheduledMails = $queueC->getScheduled();
            } else {
                $scheduledMails = null;
            }
            jNews_QueueHTML::processQueueHTML($queuedMails, $nextQueuedMails, $scheduledMails, $mailingid, false, $SmartNewsMessageHTML);
            return;
            break;
        case 'stopqueue':
            //we need to implement here how we can stop the queue
            $xf->update('queue_status', 0);
            //we start the processing of queue
            $GLOBALS[JNEWS . 'queue_status'] = 0;
            //we turn off the queue_process to make sure we only have one process going on
            //$xf->update('queue_process', 0);
            //$GLOBALS[JNEWS.'queue_process']=0;
            JToolBarHelper::custom('startqueue', 'start-queue.png', 'start-queue.png', _JNEWS_MENU_STARTQ, false);
            JToolBarHelper::spacer();
            $message = jnews::printYN(true, _JNEWS_MENU_STOPQ_MSG, $message);
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=queue' . $message);
            break;
        case 'startqueue':
            //we need to implement here how we can start back the queue
            $xf->update('queue_status', 1);
            //we stop the processing of queue
            $GLOBALS[JNEWS . 'queue_status'] = 1;
            //we turn off the queue_process to make sure we only have one process going on
            //$xf->update('queue_process', 0);
            //$GLOBALS[JNEWS.'queue_process']=0;
            JToolBarHelper::custom('stopqueue', 'stop-queue.png', 'stop-queue.png', _JNEWS_MENU_STOPQ, false);
            JToolBarHelper::spacer();
            $message = jnews::printYN(true, _JNEWS_MENU_STARTQ_MSG, $message);
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=queue' . $message);
            break;
        case 'cpanel':
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION);
            break;
        case 'delq':
            JRequest::checkToken() or die('Invalid Token');
            if (!is_array($cid) || count($cid) < 1) {
                echo "<script> alert('Select an item to delete'); window.history.go(-1);</script>\n";
                return false;
            } else {
                $status = true;
                if (!empty($cid)) {
                    $db = JFactory::getDBO();
                    $query = 'DELETE from `#__jnews_queue` where `qid` IN (' . implode(',', $cid) . ')';
                    $db->setQuery($query);
                    $db->query();
                }
                $message = jnews::printYN(true, 'Successfully deleted the mailing(s) in the queue.', _JNEWS_ERROR);
            }
            break;
        case 'block':
            JRequest::checkToken() or die('Invalid Token');
            if (!is_array($cid) || count($cid) < 1) {
                echo "<script> alert('Select an item to block'); window.history.go(-1);</script>\n";
                return false;
            } else {
                $status = true;
                if (!empty($cid)) {
                    $message = jnews::printYN(jNews_Queue::updateQueueBlock($cid, 1), 'Successfully blocked the mailing(s) in the queue.', _JNEWS_ERROR);
                }
            }
            break;
        case 'unblock':
            JRequest::checkToken() or die('Invalid Token');
            if (!is_array($cid) || count($cid) < 1) {
                echo "<script> alert('Select an item to unblock'); window.history.go(-1);</script>\n";
                return false;
            } else {
                $status = true;
                if (!empty($cid)) {
                    $message = jnews::printYN(jNews_Queue::updateQueueBlock($cid, 0), 'Successfully blocked the mailing(s) in the queue.', _JNEWS_ERROR);
                }
            }
            break;
        case 'cleanq':
            JRequest::checkToken() or die('Invalid Token');
            $db = JFactory::getDBO();
            $query = 'DELETE from `#__jnews_queue` WHERE `type` < 7';
            //do not delete the smartnewsletter type 7 and type 8
            $db->setQuery($query);
            $db->query();
            $message = jnews::printYN(true, ' Successfully cleared the mailings in the queue! ', _JNEWS_ERROR);
            break;
        default:
            if ($GLOBALS[JNEWS . 'queue_status'] == 1) {
                JToolBarHelper::custom('stopqueue', 'stop-queue.png', 'stop-queue.png', _JNEWS_MENU_STOPQ, false);
            } else {
                JToolBarHelper::custom('startqueue', 'start-queue.png', 'start-queue.png', _JNEWS_MENU_STARTQ, false);
            }
            JToolBarHelper::spacer();
    }
    if ($showqueue) {
        $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_Queue::getQueueCount($mailingid);
        $setLimit = new stdClass();
        $setLimit->total = !empty($limittotal) ? $limittotal : 0;
        $setLimit->start = !empty($limitstart) ? $limitstart : 0;
        $setLimit->end = !empty($limitend) ? $limitend : $limittotal;
        $setSort = new stdClass();
        $setSort->orderValue = $app->getUserStateFromRequest(JNEWS_OPTION . '.queue.filter_order', 'filter_order', 'q.send_date', 'cmd');
        $setSort->orderDir = $app->getUserStateFromRequest(JNEWS_OPTION . '.queue.filter_order_Dir', 'filter_order_Dir', 'asc', 'word');
        //count only the search result
        if (!empty($mailingsearch)) {
            $mailingq = jNews_Queue::getMailingqueue($mailingsearch, $mailingid, 0, 0, $setSort);
            $setLimit->total = count($mailingq);
        }
        // recheck start
        if ($setLimit->total <= $setLimit->start) {
            $setLimit->start = 0;
        }
        //perform query for all or specific search
        $mailingq = jNews_Queue::getMailingqueue($mailingsearch, $mailingid, $setLimit->start, $setLimit->end, $setSort);
        $form['main'] = " <form  name='adminForm' method='POST' action='index.php'  id=\"adminForm\">";
        $form['select'] = " <form name='jnewsFilterForm' method='POST' action='index.php'> \n";
        backHTML::_header('Mailing Queue', $img, $message, $task, $action);
        jNews_QueueHTML::showMailingQueue($mailingq, $lists, $form, $setLimit->start, $setLimit->end, $mailingsearch, $setLimit, $setSort);
        $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;
}