예제 #1
0
function subscribers($action, $task, $userid, $listId, $cid, $front = false)
{
    $Itemid = JRequest::getInt('Itemid');
    $mainframe = JFactory::getApplication();
    $newSubscriber = null;
    $subscriberId = JRequest::getInt('subscriber_id');
    $message = JRequest::getVar('message', '');
    $css = '.icon-48-subscribers { background-image:url(' . JNEWS_PATH_ADMIN_IMAGES2 . 'header/subscribers.png)}';
    $doc = JFactory::getDocument();
    $doc->addStyleDeclaration($css, $type = 'text/css');
    $img = 'subscribers.png';
    $emailField = JRequest::getVar('email', '');
    $new = true;
    //new subscriber
    $my = JFactory::getUser();
    //START OF DATA FROM REQUEST
    $subscriber = new stdClass();
    $subscriber->user_id = JRequest::getInt('user_id');
    $subscriber->name = JRequest::getVar('name', '');
    $subscriber->email = JRequest::getVar('email', '', '', 'STRING');
    if (!jNews_Subscribers::validEmail($subscriber->email)) {
        $subscriber->email = '';
    }
    $subscriber->receive_html = JRequest::getInt('receive_html', 0);
    if (empty($subscriberId)) {
        //if it is a new user the confirmed depends if the require confirmation is turned on
        if ($GLOBALS[JNEWS . 'require_confirmation'] == '1') {
            $subscriber->confirmed = 0;
        } else {
            $subscriber->confirmed = JRequest::getInt('confirmed');
        }
    } else {
        $subscriber->confirmed = JRequest::getInt('confirmed');
    }
    $subscriber->blacklist = JRequest::getVar('blacklist', 0);
    $subscriber->timezone = JRequest::getVar('timezone', '');
    $subscriber->language_iso = JRequest::getVar('language_iso', '');
    if (empty($subscriber->ip)) {
        $subscriber->ip = jNews_Subscribers::getIP();
    }
    if ($subscriber->ip == '0.0.0.0') {
        $subscriber->ip = '0';
    }
    $subscriber->subscribe_date = time();
    $subscriber->params = JRequest::getVar('params', '');
    //column
    if ($GLOBALS[JNEWS . 'level'] > 2) {
        $subscriber->column1 = JRequest::getVar('column1', '');
        $subscriber->column2 = JRequest::getVar('column2', '');
        $subscriber->column3 = JRequest::getVar('column3', '');
        $subscriber->column4 = JRequest::getVar('column4', '');
        $subscriber->column5 = JRequest::getVar('column5', '');
    }
    //end check of version pro
    //END OF DATA FROM REQUEST
    $doShowSubscribers = true;
    switch ($task) {
        case 'updateOneSub':
            JRequest::checkToken() or die('Invalid Token');
            $doShowSubscribers = true;
            $new = false;
            //we addslashes the name incase an ' is entered in the name
            $subscriber->name = addslashes($subscriber->name);
            $message = jnews::printYN(jNews_Subscribers::saveSubscriber($subscriber, $subscriberId, $new), _JNEWS_UPDATED_SUCCESSFULLY, _JNEWS_ERROR);
            backHTML::_header(_JNEWS_MENU_SUBSCRIBERS, $img, $message, $task, $action);
            break;
        case 'deleteOneSub':
            JRequest::checkToken() or die('Invalid Token');
            $doShowSubscribers = true;
            $message = jnews::printYN(jNews_Subscribers::deleteSubscriber($subscriberId), _JNEWS_SUBSCRIBER_DELETED, _JNEWS_ERROR);
            backHTML::_header(_JNEWS_MENU_SUBSCRIBERS, $img, $message, $task, $action);
            break;
        case 'cancelSub':
            $doShowSubscribers = true;
            backHTML::_header(_JNEWS_MENU_SUBSCRIBERS, $img, $message, $task, $action);
            break;
        case 'edit':
            foreach ($cid as $id) {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=subscribers&task=show&userid=' . $id);
            }
            break;
        case 'show':
            $doShowSubscribers = false;
            $qid[0] = $userid;
            $subscriber = jNews_Subscribers::getSubscribersFromId($qid, false);
            $lists = jNews_Lists::getLists(0, 0, 1, '', false, false);
            $queues = jNews_ListsSubs::getSubscriberLists($userid);
            $forms['main'] = " <form action='index.php' method='post' name='adminForm' id=\"adminForm\">";
            backHTML::_header(_JNEWS_MENU_SUBSCRIBERS, $img, $message, $task, $action);
            backHTML::formStart('', 0, '');
            echo jNews_SubscribersHTML::editSubscriber($subscriber, $lists, $queues, $forms, jnews::checkPermissions('admin'), false, false);
            $go[] = jnews::makeObj('act', $action);
            $go[] = jnews::makeObj('subscriber_id', $subscriber->id);
            $go[] = jnews::makeObj('user_id', $subscriber->user_id);
            backHTML::formEnd($go);
            break;
        case 'new':
        case 'add':
            $doShowSubscribers = false;
            $newSubscriber = new stdClass();
            $newSubscriber->id = '';
            $newSubscriber->user_id = 0;
            $newSubscriber->name = '';
            $newSubscriber->email = '';
            $newSubscriber->ip = jNews_Subscribers::getIP();
            $newSubscriber->receive_html = 1;
            $newSubscriber->confirmed = 1;
            $newSubscriber->blacklist = 0;
            $newSubscriber->timezone = '00:00:00';
            $newSubscriber->language_iso = 'eng';
            $newSubscriber->params = '';
            $newSubscriber->subscribe_date = time();
            //column
            if ($GLOBALS[JNEWS . 'level'] > 2) {
                //check if the version of jnews is pro
                $newSubscriber->column1 = '';
                $newSubscriber->column2 = '';
                $newSubscriber->column3 = '';
                $newSubscriber->column4 = '';
                $newSubscriber->column5 = '';
            }
            $lists = jNews_Lists::getLists(0, 0, 1, '', false, false);
            $queues = '';
            $forms['main'] = " <form action='index.php' method='post' name=\"adminForm\" id=\"adminForm\">";
            if ($mainframe->isAdmin() || $GLOBALS[JNEWS . 'use_backendview']) {
                backHTML::_header(_JNEWS_MENU_SUBSCRIBERS, $img, $message, $task, $action);
                backHTML::formStart('addsubsback', 0, '');
                echo jNews_SubscribersHTML::editSubscriber($newSubscriber, $lists, $queues, $forms, jnews::checkPermissions('admin'), false, false);
            } else {
                backHTML::_header(_JNEWS_MENU_SUBSCRIBERS, $img, $message, $task, $action);
                backHTML::formStart('addsubsfront', 0, '');
                echo jNews_SubscribersHTML::editSubscriberFE($newSubscriber, $lists, $queues, $forms, jnews::checkPermissions('admin'), false, false);
            }
            $go[] = jnews::makeObj('act', $action);
            $go[] = jnews::makeObj('subscriber_id', $newSubscriber->id);
            $go[] = jnews::makeObj('user_id', $newSubscriber->user_id);
            backHTML::formEnd($go);
            break;
        case 'doNew':
            JRequest::checkToken() or die('Invalid Token');
            $doShowSubscribers = true;
            if ($mainframe->isAdmin() || $GLOBALS[JNEWS . 'use_backendview']) {
                $message = jnews::printYN(jNews_Subscribers::saveSubscriber($subscriber, $subscriberId, $new), _JNEWS_NEW_SUBSCRIBER, _JNEWS_ERROR);
                backHTML::_header(_JNEWS_MENU_SUBSCRIBERS, $img, $message, $task, $action);
            } else {
                $status = jNews_Subscribers::importBis();
                if ($mainframe->isAdmin()) {
                    jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=subscribers&mid=2');
                } else {
                    $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION . '&act=subscribers&mid=2');
                    jNews_Tools::redirect($mainLink);
                }
            }
            break;
        case 'delete':
            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;
                foreach ($cid as $id) {
                    if (!jNews_Subscribers::deleteSubscriber($id)) {
                        $status = false;
                    }
                }
                $message = jnews::printYN($status, _JNEWS_SUBSCRIBER_DELETED, _JNEWS_ERROR);
                backHTML::_header(_JNEWS_MENU_SUBSCRIBERS, $img, $message, $task, $action);
            }
            break;
        case 'update':
            JRequest::checkToken() or die('Invalid Token');
            if (!is_array($cid) || count($cid) < 1) {
                echo "<script> alert('Select an item to update'); window.history.go(-1);</script>\n";
                return false;
            } else {
                foreach ($cid as $id) {
                    $changes = JRequest::getVar($id, array(0));
                    if (!isset($changes['receive_html'])) {
                        $changes['receive_html'] = 0;
                    }
                    if (!isset($changes['confirmed'])) {
                        $changes['confirmed'] = 0;
                    }
                }
            }
            $message = jnews::print_message(_JNEWS_UPDATED_SUCCESSFULLY, 1);
            break;
        case 'export':
            $doShowSubscribers = false;
            backHTML::_header(_JNEWS_MENU_SUBSCRIBERS, $img, $message, $task, $action);
            jNews_SubscribersHTML::export($action, $listId);
            break;
        case 'doExport':
            $message = jnews::printYN(jNews_Subscribers::export($listId), _EXPORT, _JNEWS_ERROR);
            backHTML::_header(_JNEWS_MENU_SUBSCRIBERS, $img, $message, $task, $action);
            break;
        case 'import':
            $doShowSubscribers = false;
            backHTML::_header(_JNEWS_MENU_SUBSCRIBERS, $img, $message, $task, $action);
            $lists = jNews_Lists::getLists('', 0, '', '', false, true, true, false, false);
            jNews_SubscribersHTML::import($action, $lists, $listId);
            break;
        case 'doImport':
            JRequest::checkToken() or die('Invalid Token');
            $message = jNews_Subscribers::importBis();
            backHTML::_header(_JNEWS_MENU_SUBSCRIBERS, $img, $message, $task, $action);
            $message = !empty($message) && $message !== true ? $message : ($message === false ? 'Import failed' : _JNEWS_IMPORT_FINISHED);
            if ($mainframe->isAdmin()) {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=subscribers', $message);
            } else {
                $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION . '&act=subscribers&mid=2');
                jNews_Tools::redirect($mainLink);
            }
            break;
        case 'subscribeAll':
        case 'unsubscribeAll':
            JRequest::checkToken() or die('Invalid Token');
            break;
        case 'cancel':
            if ($listId != 0) {
                $listId = 0;
            } else {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION);
            }
            backHTML::_header(_JNEWS_MENU_SUBSCRIBERS, $img, $message, $task, $action);
            break;
        case 'cpanel':
            $mainframe = JFactory::getApplication();
            if ($mainframe->isAdmin()) {
                backHTML::controlPanel();
            } else {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION);
            }
            $doShowSubscribers = 0;
            break;
        case 'toggle':
            $subid = JRequest::getVar('subid');
            $column = JRequest::getVar('col');
            if (!empty($subid) && !empty($column)) {
                $passObj = new stdClass();
                $passObj->tableName = '#__jnews_subscribers';
                $passObj->columnName = $column;
                $passObj->whereColumn = 'id';
                $passObj->whereColumnValue = $subid;
                jnews::toggle($passObj);
                // change suspend status if column toggled is confirmed
                if ($column == 'confirmed') {
                    $passObj = new stdClass();
                    $passObj->tableName = '#__jnews_queue';
                    $passObj->columnName = 'suspend';
                    $passObj->whereColumn = 'subscriber_id';
                    $passObj->whereColumnValue = $subid;
                    jnews::toggle($passObj);
                }
            }
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=subscribers&listid=' . $listId);
            break;
        default:
            backHTML::_header(_JNEWS_MENU_SUBSCRIBERS, $img, $message, $task, $action);
            break;
    }
    if ($doShowSubscribers) {
        $limit = -1;
        $emailsearch = JRequest::getVar('emailsearch', '', '', 'STRING');
        $emailsearch = htmlentities($emailsearch, ENT_COMPAT, "UTF-8");
        $paginationStart = JRequest::getVar('pg');
        $lll = JRequest::getVar('limitstart');
        if (empty($lll)) {
            JRequest::setVar('limitstart', 0, 'int');
        }
        $app = JFactory::getApplication();
        $limitstart = $app->getUserStateFromRequest('limitstart', 'limitstart', 0, 'int');
        $limitend = $app->getUserStateFromRequest('limit', 'limit', 0, 'int');
        $subscirberTypeID = JRequest::getVar('subtype', 1);
        if (empty($listId) && in_array($subscirberTypeID, array(1, 2))) {
            $subscirberTypeID = 0;
        }
        if (!empty($listId) && in_array($subscirberTypeID, array(3, 4))) {
            $subscirberTypeID = 0;
        }
        if (!empty($my->id)) {
            $ownedlists = jNews_Lists::getOwnedlists($my->id);
        }
        $ztozto = null;
        $limittotal = jNews_Subscribers::getSubscribers(0, 0, $emailsearch, $ztozto, $listId, '', '', '', 'sub_dateD', '', $ownedlists, '', $subscirberTypeID, true);
        //added one parameter for mailid
        $setLimit = new stdClass();
        $setLimit->total = !empty($limittotal) ? $limittotal : 0;
        $setLimit->start = !empty($limitstart) ? $limitstart : 0;
        $setLimit->end = !empty($limitend) ? $limitend : 20;
        $setSort = new stdClass();
        $setSort->orderValue = $app->getUserStateFromRequest(JNEWS_OPTION . '.subscribers.filter_order', 'filter_order', 'subscribe_date', 'cmd');
        $setSort->orderDir = $app->getUserStateFromRequest(JNEWS_OPTION . '.subscribers.filter_order_Dir', 'filter_order_Dir', 'desc', 'word');
        if (empty($limitstart)) {
            $limitstart = 0;
        }
        if ($setLimit->end > 200) {
            $setLimit->end = 200;
        }
        if ($setLimit->total == $setLimit->end) {
            $setLimit->start = 0;
        }
        $subscribers = jNews_Subscribers::getSubscribers($setLimit->start, $setLimit->end, $emailsearch, $setLimit->total, $listId, '', '', '', 'sub_dateD', '', $ownedlists, $setSort, $subscirberTypeID);
        //added one parameter for mailid
        if ($listId != 0) {
            $showAdmin = true;
        } else {
            $showAdmin = false;
        }
        $dropDownList = jNews_ListType::getListsDropList(0, '', '');
        $subTypeA = array();
        $subTypeA[0] = new stdClass();
        $subTypeA[0]->id = 0;
        $subTypeA[0]->subtype = _JNEWS_SUB_LISTTYPE_ALL;
        if ($listId != 0) {
            $subTypeA[1] = new stdClass();
            $subTypeA[1]->id = 1;
            $subTypeA[1]->subtype = _JNEWS_SUB_LISTTYPE_ONLY_SUBCRIBED;
            $subTypeA[2] = new stdClass();
            $subTypeA[2]->id = 2;
            $subTypeA[2]->subtype = _JNEWS_SUB_LISTTYPE_ONLY_UNSUBCRIBED;
        } else {
            $subTypeA[3] = new stdClass();
            $subTypeA[3]->id = 3;
            $subTypeA[3]->subtype = _JNEWS_SUB_LISTTYPE_ONLY_WAITINGCONF;
            $subTypeA[4] = new stdClass();
            $subTypeA[4]->id = 4;
            $subTypeA[4]->subtype = _JNEWS_SUB_LISTTYPE_ONLY_BLOCKED;
        }
        $lists['listid'] = jnews::HTML_GenericList($dropDownList, 'listid', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'id', 'list_name', $listId);
        $lists['subscirberType'] = jnews::HTML_GenericList($subTypeA, 'subtype', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'id', 'subtype', $subscirberTypeID);
        if ($mainframe->isAdmin()) {
            $forms['main'] = " <form action='index.php' method='post' name=\"adminForm\" id=\"adminForm\">";
        } else {
            if (empty($setLimit->start)) {
                $setLimit->start = 0;
            }
            $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION);
            $forms['main'] = "<form action='" . $mainLink . "' method='post' name=\"adminForm\" id=\"adminForm\">";
        }
        $forms['select'] = " <form method='post' name='jNewsFilterForm'> \n";
        backHTML::formStart('show_mailing', 0, '');
        jNews_SubscribersHTML::showSubscribers($subscribers, $action, $listId, $lists, $setLimit->start, $setLimit->end, $setLimit->total, $showAdmin, $listId, $emailsearch, $forms, $setLimit, $front, $setSort);
    }
    return true;
}
예제 #2
0
    public static function attachement($mailingEdit, $lists, $show)
    {
        $js = "function deleteattach(rem, reml, url){\n\t";
        if (version_compare(JVERSION, '1.6.0', '<')) {
            //1.5
            $js .= "\n \t\t\t\tvar ajax = new Ajax(url,\n \t\t\t\t\t{data: 'rem='+rem+'&reml='+reml,\n \t\t\t\t\tmethod: 'POST',\n \t\t\t\t\tonComplete : function(result){\n \t\t\t\t\t\t\tvar myElement = document.getElementById(rem);\n\t\t\t\t\t\t\tmyElement.remove();\n\t\t\t\t\t\t}\n \t\t\t\t\t}\n \t\t\t\t);\n \t\t\t\tajax.request();\n \t\t\t";
        } else {
            $js .= "\n\t\tvar ajax = new Request({\n\t\turl : url,\n\t\tdata: 'rem='+rem+'&reml='+reml,\n\t\tmethod: 'POST',\n\t\tonComplete : function(result){\n\t\t\t\tvar myElement = document.getElementById(rem);\n\t\t\t\tmyElement.destroy();\n\t\t\t}\n\t\t});\n\t\tajax.send();\n \t\t\t";
        }
        $js .= "}";
        $urlcomm = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=deleteattach', false, false, true);
        $doc = JFactory::getDocument();
        $doc->addScriptDeclaration($js);
        foreach ($mailingEdit->attachments as $attach => $k) {
            $mailingEdit->attachments[$attach] = basename($k);
        }
        $path = JNEWS_JPATH_ROOT_NO_ADMIN . $GLOBALS[JNEWS . 'upload_url'];
        $arr = array(null);
        // Get the files and folders
        jimport('joomla.filesystem.folder');
        $files2 = JFolder::files($path, '.', true, true);
        $folders = JFolder::folders($path, '.', true, true);
        // Merge files and folders into one array
        if (!is_array($files2)) {
            $files = $folders;
        } else {
            $files = array_merge($files2, $folders);
        }
        // Sort them all
        if (!empty($files)) {
            asort($files);
        } else {
            $files = array();
        }
        // check deleted attachments
        $rem = JRequest::getVar('rem');
        if (!empty($rem)) {
            // get the lenght of the previous url
            $reml = JRequest::getVar('reml');
            jNews_Attachment::deleteAttachment($rem);
            jNews_Attachment::deleteAttachmentQuery($rem);
            if (version_compare(JVERSION, '1.6.0', '<')) {
                //j15
                // create delete link for attachment files
                $urlInstances = JURI::getInstance();
                $uri = $urlInstances->_uri;
            } else {
                $urlInstances = JURI::getInstance();
                $uri = $urlInstances->toString();
            }
            if (isset($uri) && !empty($uri)) {
                $url = $uri;
                $url = substr($url, 0, '-' . (int) $reml);
                // refresh or reload page with the extra url [previous]
                jNews_Tools::redirect($url);
            }
        }
        if (sizeof($files) > 0) {
            if (version_compare(JVERSION, '1.6.0', '<')) {
                //j15
                $delImgPath = JNEWS_JPATH_LIVE . DS . 'administrator' . DS . 'images' . DS . 'delete_f2.png';
            } else {
                //j16
                $delImgPath = JNEWS_JPATH_LIVE . DS . 'administrator' . DS . 'components' . DS . JNEWS_OPTION . DS . 'images' . DS . 'delete_queue.png';
            }
            $urlExtraLength = 0;
            foreach ($files as $file) {
                $file = basename($file);
                if (version_compare(JVERSION, '1.6.0', '<')) {
                    //j15
                    // create delete link for attachment files
                    $urlInstances = JURI::getInstance();
                    $uri = $urlInstances->_uri;
                } else {
                    //					$uri = JURI::getInstance()->toString();
                    $urlInstances = JURI::getInstance();
                    $uri = $urlInstances->toString();
                }
                if (!empty($uri)) {
                    $url = $uri;
                    $urlExtra = "&rem=" . $file . "&reml=";
                    $urlExtraMain = $urlExtra;
                    // we need to get the extra url length
                    $urlExtraLength = strlen($urlExtra);
                    // now we need to add the length count
                    $urlExtra .= $urlExtraLength;
                    // we need to get the extra url length again with its length count
                    $urlExtraLength = strlen($urlExtra);
                    // we need to set the length count again [ now with its full count] and set it as our final url
                    $url .= $urlExtraMain . $urlExtraLength;
                    $link = '<a href="' . $url . '">';
                } else {
                    $url = "Link Error";
                    $link = '<a href="' . $url . '" onClick="window.alert("wee");">';
                }
                if (in_array($file, $mailingEdit->attachments)) {
                    //					echo "<input name='attachments[]' type='checkbox' value='".$file."' checked> ". $file ." ". $link ." <img src='". $delImgPath ."'  title='Delete ". $file ."' style='width:16px;height:16px;'></a> <br>";
                    echo "<div id='" . $file . "'><input name='attachments[]' type='checkbox' value='" . $file . "' checked> " . $file . " " . " <img src='" . $delImgPath . "' onclick='deleteattach(\"" . $file . "\",\"" . $urlExtraLength . "\",\"" . $urlcomm . "\")'  title='Delete " . $file . "' style='width:16px;height:16px;'> </div>";
                } else {
                    //wwe comment this one this one because we ewill not show the index.html
                    //					echo "<input name='attachments[]' type='checkbox' value='".$file."'> ". $file ." ". $link ." <img src='". $delImgPath ."' title='Delete ". $file ."' style='width:16px;height:16px;'></a> <br>";
                }
            }
        }
        echo "<br><br>";
        ?>
		<script src="<?php 
        echo JNEWS_URL_INCLUDES;
        ?>
multifile.js"></script>

		<input id="my_file_element" type="file" name="file_1" >
		</input>

		<br /><b><?php 
        echo _JNEWS_FILES;
        ?>
:</b>

		<div id="files_list"></div>
		<script>

			var multi_selector = new MultiSelector( document.getElementById( 'files_list' ), 10 );
			multi_selector.addElement( document.getElementById( 'my_file_element' ) );
		</script>

	<?php 
    }
예제 #3
0
function statistics($listId, $listType, $mailingId, $message, $task, $action)
{
    //From Specified fieldset
    $sDate = JRequest::getVar('startdate');
    $eDate = JRequest::getVar('enddate');
    if ($task == 'cpanel') {
        jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION);
    }
    //Predefined fieldset
    $currentInterval = JRequest::getVar('rptinterval');
    $currentRange = JRequest::getVar('rptrange');
    if (empty($currentRange)) {
        $currentRange = 'this-month';
    }
    if (empty($currentInterval)) {
        $currentInterval = 'weekly';
    }
    if ($sDate == '0000-00-00' && $eDate == '0000-00-00') {
        $sDate = 0;
        $eDate = 0;
    }
    if (!empty($sDate) && !empty($eDate)) {
        if ($sDate != '0000-00-00' && $eDate != '0000-00-00') {
            $sDate = strtotime($sDate);
            $sDate = $sDate - jnews::calculateOffset(JNEWS_TIME_OFFSET) + date('Z');
            $eDate = strtotime($eDate);
            $eDate = $eDate - jnews::calculateOffset(JNEWS_TIME_OFFSET) + date('Z');
        } elseif ($sDate != '0000-00-00' && $eDate == '0000-00-00') {
            $sDate = strtotime($sDate);
            $sDate = $sDate - jnews::calculateOffset(JNEWS_TIME_OFFSET) + date('Z');
            $eDate = time();
            // - JNEWS_TIME_OFFSET * 3600 ;
        } elseif ($sDate == '0000-00-00' && $eDate != '0000-00-00') {
            echo jnews::printM('warning', _JNEWS_REPORT_WARN_MESSAGE);
            $sDate = 0;
            $eDate = 0;
        }
    } else {
        //Set the correct startDateTime and endDateTime
        //Set also the correct intervals appropriate for each range
        //current datetime base on the website setting configuration
        $currDate = $eDate = time();
        // - JNEWS_TIME_OFFSET * 3600 ;
        switch ($currentRange) {
            case 'today':
                //today
                $sDate = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
                $eDate = mktime(23, 59, 59, date('m'), date('d'), date('Y'));
                $currentInterval = 'daily';
                break;
            case 'yesterday':
                //yesterday
                $sDate = mktime(0, 0, 0, date('m'), date('d') - 1, date('Y'));
                $eDate = mktime(23, 59, 59, date('m'), date('d') - 1, date('Y'));
                $currentInterval = 'daily';
                break;
            case 'this-week':
                //this week
                $sDate = mktime(0, 0, 0, date('n'), date('j'), date('Y')) - (date('N') - 1) * 3600 * 24;
                //if selected intervals is monthly or yearly
                if ($currentInterval == 'monthly' || $currentInterval == 'yearly') {
                    $currentInterval = 'weekly';
                }
                break;
            case 'last-week':
                //last week..start of the week is Monday at 00:00:00 and will end on Sunday at 23:59:59:
                $sDate = mktime(0, 0, 0, date('n'), date('j') - 6, date('Y')) - date('N') * 3600 * 24;
                $eDate = mktime(23, 59, 59, date('n'), date('j'), date('Y')) - date('N') * 3600 * 24;
                //if selected intervals is monthly or yearly
                if ($currentInterval == 'monthly' || $currentInterval == 'yearly') {
                    $currentInterval = 'weekly';
                }
                break;
            case 'last-2-weeks':
                //last 2 weeks
                $sDate = mktime(0, 0, 0, date('n'), date('j') - 13, date('Y')) - date('N') * 3600 * 24;
                $eDate = mktime(23, 59, 59, date('n'), date('j'), date('Y')) - date('N') * 3600 * 24;
                //if selected intervals is monthly or yearly
                if ($currentInterval == 'monthly' || $currentInterval == 'yearly') {
                    $currentInterval = 'weekly';
                }
                break;
            case 'last-month':
                //last month..starts at the first day to the last day
                $sDate = strtotime(date('m') - 1 . '/01/' . date('Y'), $currDate);
                $eDate = $sDate + 30 * 24 * 3600;
                //mktime(23, 59, 59, date('m'));
                if ($currentInterval == 'yearly') {
                    $currentInterval = 'weekly';
                }
                break;
            case 'this-year':
                //this year..starts
                $sDate = strtotime('01/01/' . date('Y'), $currDate);
                break;
            case 'last-year':
                //last year...starts jan 1 and ends dec 31
                $sDate = mktime(0, 0, 0, 1, 1, date('Y') - 1);
                $eDate = mktime(23, 59, 59, 12, 31, date('Y') - 1);
                break;
            case '2-years-ago':
                //2 Years ago
                if ($currentInterval == 'yearly') {
                    //if the interval is yearly
                    $sDate = mktime(0, 0, 0, 1, 1, date('Y') - 2);
                    //starts jan 1
                } else {
                    $eDate = mktime(23, 59, 59, 12, 31, date('Y') - 2);
                    //ends dec 31
                    $sDate = mktime(0, 0, 0, 1, 1, date('Y') - 2);
                    //starts jan 1
                }
                break;
            case '3-years-ago':
                //3 Years ago
                if ($currentInterval == 'yearly') {
                    //if the interval is yearly
                    $sDate = mktime(0, 0, 0, 1, 1, date('Y') - 3);
                    //starts jan 1
                } else {
                    $eDate = mktime(23, 59, 59, 12, 31, date('Y') - 3);
                    //ends dec 31
                    $sDate = mktime(0, 0, 0, 1, 1, date('Y') - 3);
                    //starts jan 1
                }
                break;
            case 'this-month':
                //this month
            //this month
            default:
                $sDate = strtotime(date('m') . '/01/' . date('Y'), $currDate);
                if ($currentInterval == 'yearly') {
                    $currentInterval = 'weekly';
                }
                break;
        }
    }
    //Still need to double check if there's really values on the start and end date
    if (!empty($sDate) && !empty($eDate)) {
        //Title header
        $doc = JFactory::getDocument();
        $css = '.icon-48-statistics_header { background-image:url(' . JNEWS_PATH_ADMIN_IMAGES2 . 'header/statistics.png)}';
        $doc->addStyleDeclaration($css, $type = 'text/css');
        $img = 'statistics_header.png';
        $message = '';
        $start = date('F j, Y', jnews::getNow(0, true, $sDate));
        $end = date('F j, Y', jnews::getNow(0, true, $eDate));
        if ($currentRange == 'today' || $currentRange == 'yesterday') {
            $title = _JNEWS_REPORT_HEADER . ': ' . $start;
            $fileNameExport = $start;
        } else {
            $title = _JNEWS_REPORT_HEADER . ': ' . $start . ' ' . _JNEWS_REPORT_HEADER_TO . ' ' . $end;
            $fileNameExport = $start . ' ' . _JNEWS_REPORT_HEADER_TO . ' ' . $end;
        }
        backHTML::_header($title, $img, $message, $task, $action);
    }
    $dateFormat = 'FROM_UNIXTIME(';
    switch ($currentInterval) {
        case 'yearly':
            //yearly
            $specialFormat = ',\'%Y\'';
            $dateFormat4DateNumber = 'FROM_UNIXTIME(';
            //.$columnModif.', \'' .substr($special, 10).'\'))';
            $specialNo = ',\'%Y\')';
            break;
        case 'weekly':
            //weekly
            $specialFormat = ',\'%M %d, %Y\'';
            $dateFormat4DateNumber = 'WEEK(' . $dateFormat;
            $dateFormat4DateNumber = 'WEEK(FROM_UNIXTIME(';
            //'dtfrmtweek%Y-%m-%d';	// WEEK(DATE_FORMAT(cdate, '%Y-%m-%d'))
            $specialNo = ',\'%Y-%m-%d\'))';
            break;
        case 'daily':
            //daily
            $specialFormat = ',\'%M %d, %Y\'';
            $dateFormat4DateNumber = 'FROM_UNIXTIME(';
            //'dateformat%Y%m%d';
            $specialNo = ',\'%Y%m%d\')';
            break;
        case 'monthly':
            //monthly
        //monthly
        default:
            $specialFormat = ',\'%M, %Y\'';
            $dateFormat4DateNumber = 'FROM_UNIXTIME(';
            //'dateformat%Y%m%d';
            $specialNo = ',\'%Y%m\')';
            break;
    }
    $queryfilters = array();
    $queryfilters['enddate'] = '\'' . $eDate . '\'';
    $queryfilters['startdate'] = '\'' . $sDate . '\'';
    $queryfilters['dateFormat'] = $dateFormat;
    $queryfilters['specialFormat'] = $specialFormat;
    $queryfilters['dateFormat4DateNumber'] = $dateFormat4DateNumber;
    $queryfilters['specialNo'] = $specialNo;
    $queryfilters['mailingId'] = $mailingId;
    $queryfilters['task'] = $task;
    //go to class.stats to display the view of stats
    require_once JNEWSPATH_CLASS . 'class.statistics.php';
    outputReportGraph::initIncludes();
    echo '<form action="index.php" method="post" name="adminForm" id="adminForm">';
    if ($task == 'graph') {
        $results = array();
        $results['subject'] = JRequest::getVar('subject', '');
        $results['html_sent'] = JRequest::getVar('html_sent', '0');
        $results['text_sent'] = JRequest::getVar('text_sent', '0');
        $results['html_views'] = JRequest::getVar('html_views', '0');
        $results['html_unread'] = JRequest::getVar('html_unread', '0');
        $results['pending'] = JRequest::getVar('pending', '0');
        //		$results['failed'] = JRequest::getVar( 'failed', '0' );
        //		$results['bounces'] = JRequest::getVar( 'bounces', '0' );
        $results['sent'] = JRequest::getVar('sent', '0');
        //		$results['sent'] = intval( $results['html_sent'] + $results['text_sent'] ); //fixed
        $results['id'] = JRequest::getVar('id');
        $queryfilters['startdate'] = '\'' . JRequest::getInt('startdate') . '\'';
        $queryfilters['enddate'] = '\'' . JRequest::getVar('enddate') . '\'';
        outputReportGraph::mailingSpecificGraph($results, $queryfilters);
    } else {
        outputReportGraph::headerFilter($currentInterval);
        if (empty($fileNameExport)) {
            $fileNameExport = null;
        }
        outputReportGraph::tabReports($queryfilters, $task, $fileNameExport);
    }
    echo '</form>';
    return true;
}
예제 #4
0
파일: frontend.php 프로젝트: naka211/kkvn
 public static function mailingOptions($action, $task, $listId, $mailingId, $subscriberId, $listType, $artId, $contentType, $blogId, $blogType, $dealId, $dealType, $tmplid, $flexiid, $flexitype, $captchaWidth = 80, $captchaHeight = 25, $captchaBGColor = '', $captchaFTColor = '')
 {
     $Itemid = JRequest::getInt('Itemid');
     if (empty($Itemid)) {
         $Itemid = $GLOBALS[JNEWS . 'itemidAca'];
     }
     if (empty($lisType)) {
         $lisType = 1;
     }
     $acl = JFactory::getACL();
     $database = JFactory::getDBO();
     $my = JFactory::getUser();
     $new = false;
     $gid = !empty($GLOBALS[JNEWS . 'list_creatorfe']) ? $GLOBALS[JNEWS . 'list_creatorfe'] : 0;
     $gids = array();
     $gids = explode(',', $gid);
     if (empty($gids)) {
         $gids = $gid;
     }
     if (version_compare(JVERSION, '1.6.0', '<')) {
         $listsAddEdit = jNews_Lists::getIDswithacclevel($my->gid);
     } else {
         $groups = JAccess::getGroupsByUser($my->id);
         $listsAddEdit = jNews_Lists::getIDswithacclevel($groups);
     }
     //for popup window
     JHTML::_('behavior.modal');
     if ($listType < 1) {
         $dropLlistPost = JRequest::getVar('droplist');
         if (!empty($dropLlistPost)) {
             $maliste = explode('-', $dropLlistPost);
             $listType = $maliste[0];
             $listId = $maliste[1];
         } elseif ($listId > 0) {
             $maliste = jNews_Lists::getLists($listId, 0, null, 'listnameA', false, false, false, false);
             $listType = $maliste[0]->list_type;
         }
     }
     switch ($task) {
         case 'refreshcaptcha':
             $newcode = jNews_Captcha::generateCode('5');
             $_SESSION['captcha'] = $newcode;
             $newesc = jNews_Captcha::encryptData($newcode, crypt($GLOBALS[JNEWS . 'captcha_code'], $GLOBALS[JNEWS . 'captcha_code']));
             $newdecrypt = jNews_Captcha::decryptData($newesc, crypt($GLOBALS[JNEWS . 'captcha_code'], $GLOBALS[JNEWS . 'captcha_code']));
             $newpath = JNEWS_JPATH_LIVE_NO_HTTPS . '/index.php?option=' . JNEWS_OPTION . '&act=captcha&tmpl=component&width=' . $captchaWidth . '&height=' . $captchaHeight . '&bgcolor=' . $captchaBGColor . '&ftcolor=' . $captchaFTColor . '&characters=5&esc=' . $newesc . '&encpwd=' . crypt($GLOBALS[JNEWS . 'captcha_code'], $GLOBALS[JNEWS . 'captcha_code']);
             echo '<div id="newcode">' . $newdecrypt . '</div>';
             echo '<div id="newesc">' . $newesc . '</div>';
             echo '<div id="newdecrypt">' . $newdecrypt . '</div>';
             echo '<div id="newpath">' . $newpath . '</div>';
             exit;
             break;
         case 'blogContent':
             $artId = $blogId;
             $contentType = $blogType;
         case 'flexicontent':
             $session =& JFactory::getSession();
             if ($flexitype == 'country') {
                 $flexCategoriesCountries = $session->get('flexi_countries', array(), 'JNEWLSETTER');
                 if (isset($flexCategoriesCountries[$flexiid])) {
                     unset($flexCategoriesCountries[$flexiid]);
                 } else {
                     $flexCategoriesCountries[$flexiid] = $flexiid;
                 }
                 //we set this value in the session
                 $session->set('flexi_countries', $flexCategoriesCountries, 'JNEWLSETTER');
             } else {
                 $flexCategoriesIndustries = $session->get('flexi_industries', array(), 'JNEWLSETTER');
                 if (isset($flexCategoriesIndustries[$flexiid])) {
                     unset($flexCategoriesIndustries[$flexiid]);
                 } else {
                     $flexCategoriesIndustries[$flexiid] = $flexiid;
                 }
                 //we set this value in the session
                 $session->set('flexi_industries', $flexCategoriesIndustries, 'JNEWLSETTER');
             }
             break;
         case 'articleContent':
             jNews_Mailing::getContent($artId, $contentType, $task, $tmplid);
             break;
         case 'dealContent':
             jNews_Mailing::getDeal($dealId, $dealType, $tmplid);
             break;
         case 'listpanel':
             $listType = JRequest::getVar('listype');
             if ($listType == 1 || $listType == 7) {
                 frontHTML::showPanel('list');
             }
             break;
         case 'cancel':
             frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING);
             break;
         case 'delete':
             JRequest::checkToken() or die('Invalid Token');
             if (empty($mailingId)) {
                 echo '<script> javascript:alert("' . _JNEWS_DELETE_MAILING . '"); javascript:history.go(-1); </script>';
             } else {
                 $d['mailing'] = jNews_Mailing::getOneMailing('', $mailingId, '', $new);
                 echo jnews::printYN(jNews_Mailing::delete($d), @constant($GLOBALS[JNEWS . 'listname' . $d['mailing']->list_type]) . _JNEWS_SUCCESS_DELETED, _JNEWS_ERROR);
                 frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING);
             }
             break;
         case 'togle':
             // defined toggle for publish and unpublish of mailings
             $id = JRequest::getVar('mailingid');
             $col = JRequest::getVar('col');
             $mailingId = !empty($id) && !empty($col) ? $id : $mailingId;
             $task = !empty($mailingId) && !empty($col) ? $col : $task;
             switch ($task) {
                 case 'publishMailing':
                     $mailing = jNews_Mailing::getOneMailing('', $mailingId, '', $new);
                     jNews_Mailing::publishMailing($mailingId);
                     break;
                 case 'unpublishMailing':
                     $mailing = jNews_Mailing::getOneMailing('', $mailingId, '', $new);
                     jNews_Mailing::unpublishMailing($mailingId);
                     break;
                 default:
                     break;
             }
             echo '<script> javascript:history.go(-1); </script>';
             break;
         case 'edit':
             if ($GLOBALS[JNEWS . 'enable_jsub']) {
                 if (!empty($my->id)) {
                     $ownedlists = jNews_Lists::getOwnedlists($my->id);
                 }
                 if (!empty($ownedlists) || jnews::checkPermissions('admin')) {
                     if (empty($mailingId)) {
                         echo '<script> javascript:alert("' . _JNEWS_SELECT_MAILING . '"); javascript:history.go(-1); </script>';
                     } else {
                         frontEnd::mailingEdit($subscriberId, $mailingId, $listId, $listType, 'mailing');
                         //savemailing
                     }
                 }
             } else {
                 //edit a mailing
                 $canAccess = false;
                 if (class_exists('jNews_Pro') && !empty($listId)) {
                     $list = jNews_Lists::getOneList($listId);
                     $accessAuthorizedA = explode(',', $list->acc_id);
                     if (!is_array($accessAuthorizedA) || $accessAuthorizedA[0] != 'all') {
                         if (version_compare(JVERSION, '1.6.0', '<')) {
                             //j15
                             $usergid = $my->gid;
                         } else {
                             //j16
                             $usergid = JAccess::getGroupsByUser($my->id, false);
                         }
                         if (is_array($accessAuthorizedA)) {
                             if (is_array($usergid)) {
                                 $canAccess = array_intersect($usergid, $accessAuthorizedA);
                             } else {
                                 if (!in_array($usergid, $accessAuthorizedA)) {
                                     $canAccess = false;
                                 }
                             }
                         } else {
                             if (is_array($usergid)) {
                                 $canAccess = array_intersect($usergid, $accessAuthorizedA);
                             } else {
                                 if ($usergid != $accessAuthorizedA) {
                                     $canAccess = false;
                                 }
                             }
                         }
                     }
                 }
                 //cehck if I am the owner of the list
                 $archivemailing = jNews_Mailing::getOneMailing(0, $mailingId, 0, $new);
                 if ($archivemailing->author_id == $my->id) {
                     $canAccess = true;
                 }
                 if ($canAccess || jnews::checkPermissions('admin') || jnews::checkPermissions($gid) || !empty($listsAddEdit)) {
                     if (empty($mailingId)) {
                         echo '<script> javascript:alert("' . _JNEWS_SELECT_MAILING . '"); javascript:history.go(-1); </script>';
                     } else {
                         frontEnd::mailingEdit($subscriberId, $mailingId, $listId, $listType, 'mailing', $canAccess);
                         //savemailing
                     }
                 }
             }
             break;
         case 'new':
         case 'add':
             if ($GLOBALS[JNEWS . 'enable_jsub']) {
                 if (!empty($my->id)) {
                     $ownedlists = jNews_Lists::getOwnedlists($my->id);
                 }
                 if (!empty($ownedlists) || jnews::checkPermissions('admin')) {
                     frontEnd::mailingEdit($subscriberId, $mailingId, $listId, $listType, 'mailing');
                     //savemailing
                 }
             } else {
                 //$list = jNews_Lists::getOneList($listId);
                 $canAccess = false;
                 if (class_exists('jNews_Pro') && !empty($listId)) {
                     $list = jNews_Lists::getOneList($listId);
                     $accessAuthorizedA = explode(',', $list->acc_id);
                     if (!is_array($accessAuthorizedA) || $accessAuthorizedA[0] != 'all') {
                         if (version_compare(JVERSION, '1.6.0', '<')) {
                             //j15
                             $usergid = $my->gid;
                         } else {
                             //j16
                             $usergid = JAccess::getGroupsByUser($my->id, false);
                         }
                         if (is_array($accessAuthorizedA)) {
                             if (is_array($usergid)) {
                                 $canAccess = array_intersect($usergid, $accessAuthorizedA);
                             } else {
                                 if (!in_array($usergid, $accessAuthorizedA)) {
                                     $canAccess = false;
                                 }
                             }
                         } else {
                             if (is_array($usergid)) {
                                 $canAccess = array_intersect($usergid, $accessAuthorizedA);
                             } else {
                                 if ($usergid != $accessAuthorizedA) {
                                     $canAccess = false;
                                 }
                             }
                         }
                     }
                 }
                 if ($canAccess || jnews::checkPermissions('admin') || jnews::checkPermissions($gid) || !empty($listsAddEdit)) {
                     frontEnd::mailingEdit($subscriberId, $mailingId, $listId, $listType, 'mailing', true);
                     //savemailing
                 }
             }
             break;
         case 'archive':
             if (class_exists('jNews_Pro')) {
                 $list = jNews_Lists::getOneList($listId);
                 $listIds = explode(',', $list->acc_id);
                 if (!is_array($listIds) || $listIds[0] != 'all') {
                     if (version_compare(JVERSION, '1.6.0', '<')) {
                         //j15
                         $usergid = $my->gid;
                     } else {
                         if (version_compare(JVERSION, '3.0.0', '>')) {
                             //j3.0
                             $usergid = JAccess::getGroupsByUser($my->id, false);
                             //this is huck for joomla >3.0 because if you check this link http://joomla.dev/administrator/index.php?option=com_config&view=component&component=com_users&return=aHR0cDovL2pvb21sYS5kZXYvYWRtaW5pc3RyYXRvci9pbmRleC5waHA%2Fb3B0aW9uPWNvbV91c2VycyZ2aWV3PWdyb3Vwcw%3D%3D
                             //you will see  Guest User Group = Public by default and into db table #__extensions where element == com_users => params => you will see guest_usergroup == 13
                             // but if you try to change user group in brovser to registered for example => save=>save again as public => check again db=> you will see guest_usergroup = 1
                             //i think it is joomla bug because if jommla woks fine needs to be 13
                             // thants why i created this "if"
                             if ($usergid[0] === '13') {
                                 $usergid[0] = '1';
                             }
                         } else {
                             //j16
                             $usergid = JAccess::getGroupsByUser($my->id, false);
                         }
                     }
                     if (is_array($listIds)) {
                         if (is_array($usergid)) {
                             $canAccess = array_intersect($usergid, $listIds);
                             if (empty($canAccess)) {
                                 break;
                             }
                         } else {
                             if (!in_array($usergid, $listIds)) {
                                 break;
                             }
                         }
                     } else {
                         if (is_array($usergid)) {
                             $canAccess = array_intersect($usergid, $listIds);
                             if (empty($canAccess)) {
                                 break;
                             }
                         } else {
                             if ($usergid != $listIds) {
                                 break;
                             }
                         }
                     }
                 }
             }
             frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, true, _JNEWS_MENU_VIEW_ARCHIVE . ' ');
             break;
         case 'save':
             JRequest::checkToken() or die('Invalid Token');
             $message = jnews::printYN(jNews_Mailing::saveMailing($mailingId, $listId), _JNEWS_MAILING_SAVED, _JNEWS_ERROR);
             frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING);
             break;
         case 'savepreview':
             JRequest::checkToken() or die('Invalid Token');
             $message = jnews::printYN(jNews_Mailing::saveMailing($mailingId, $listId), _JNEWS_MAILING_SAVED, _JNEWS_ERROR);
         case 'preview':
         case 'view':
             if ($mailingId != 0) {
                 if ($listId > 0) {
                     $archivemailing = jNews_Mailing::getMailingView($mailingId, $listId);
                 } else {
                     $archivemailing = jNews_Mailing::getMailingView($mailingId);
                 }
                 $list = jNews_Lists::getOneList($listId);
                 $acc_level = $list->acc_level;
                 jNews_ProcessMail::replaceClass($archivemailing->htmlcontent, $archivemailing->textonly);
                 if (!empty($archivemailing->template_id)) {
                     jNews_Templates::includeStyles($archivemailing->htmlcontent, $archivemailing->template_id);
                 }
                 $archivemailing->htmlcontent = str_replace('{tag:subscriptions}', '', $archivemailing->htmlcontent);
                 $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION);
                 $forms['main'] = '<form method="post" action="' . $mainLink . '" onsubmit="submitbutton();return false;" name="mosForm" >' . "\n\r";
                 $forms['main'] .= '<input type="hidden" name="Itemid" value="' . $Itemid . '" />';
                 //for view it online view
                 $currentUrl = JURI::current();
                 $gid = !empty($GLOBALS[JNEWS . 'list_creatorfe']) ? $GLOBALS[JNEWS . 'list_creatorfe'] : 0;
                 if (version_compare(JVERSION, '1.6.0', '<')) {
                     $listsAddEdit = jNews_Lists::getIDswithacclevel($my->gid);
                 } else {
                     $groups = JAccess::getGroupsByUser($my->id);
                     if (!$my->id) {
                         $listsAddEdit = array();
                     } else {
                         $listsAddEdit = jNews_Lists::getIDswithacclevel($groups);
                     }
                 }
                 if (jnews::checkPermissions('admin') || jnews::checkPermissions($gid) || !empty($listsAddEdit)) {
                     $menuA = array();
                     $onlyPreview = JRequest::getInt('onlypreview');
                     if (!$onlyPreview) {
                         //menu Preview
                         $menuNew = new stdClass();
                         $menuNew->popup = new stdClass();
                         $menuNew->popup->isPop = false;
                         $menuNew->action = 'view';
                         $linkBut = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=view&mailingid=' . $mailingId . '&onlypreview=1');
                         $menuNew->link = $linkBut;
                         $menuNew->onclick = new stdClass();
                         $menuNew->onclick->custom = true;
                         $menuNew->onclick->js = '';
                         $menuNew->title = _JNEWS_VIEW_BROWSER;
                         $menuA['view'] = $menuNew;
                         //menu edit
                         $menuNew = new stdClass();
                         $menuNew->popup = new stdClass();
                         $menuNew->popup->isPop = false;
                         $menuNew->action = 'edit';
                         $linkBut = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=edit&mailingid=' . $mailingId . '&listype=' . $listType);
                         $menuNew->link = $linkBut;
                         $menuNew->onclick = new stdClass();
                         $menuNew->onclick->custom = true;
                         $menuNew->onclick->js = '';
                         $menuNew->title = 'Edit';
                         $menuA['edit'] = $menuNew;
                         //menu send
                         $menuSend = new stdClass();
                         $menuSend->popup = new stdClass();
                         $menuSend->popup->isPop = true;
                         $menuSend->popup->rel = true;
                         $menuSend->popup->x = 750;
                         $menuSend->popup->y = 500;
                         $linkBut = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=sendready&mailingid=' . $mailingId . '&listype=' . $listType, true, false, true);
                         $menuSend->link = $linkBut;
                         $menuSend->action = 'sendready';
                         $menuSend->onclick = new stdClass();
                         $menuSend->onclick->custom = false;
                         $menuSend->onclick->js = "";
                         $menuSend->title = _JNEWS_MENU_SEND;
                         $menuA['sendready'] = $menuSend;
                         // menu back
                         $menuBack = new stdClass();
                         $menuBack->popup = new stdClass();
                         $menuBack->popup = new stdClass();
                         $menuBack->popup->isPop = false;
                         $menuBack->link = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing', false);
                         $menuBack->action = 'back';
                         $menuBack->onclick = new stdClass();
                         $menuBack->onclick->custom = true;
                         $menuBack->onclick->js = '';
                         $menuBack->title = _JNEWS_MENU_BACK;
                         $menuA['back'] = $menuBack;
                     }
                     frontHTML::formStart(_JNEWS_NEWSLETTER_ARCHIVE, 0, '', $menuA);
                 } else {
                     //can be improved where we check if user can edit
                     if (empty($archivemailing->visible) || empty($archivemailing->published) && $task == 'view') {
                         echo '<center>Access to this mailing is restricted!<center>';
                         break;
                     }
                     frontHTML::formStart(_JNEWS_NEWSLETTER_ARCHIVE, 0, '', null);
                 }
                 jNews_MailingsHTML::viewMailing($archivemailing, $forms);
                 $go[] = jnews::makeObj('act', 'mailing');
                 $go[] = jnews::makeObj('task', 'viewmailing');
                 $go[] = jnews::makeObj('listid', $archivemailing->list_id);
                 frontHTML::formEnd('', $go);
             } else {
                 frontHTML::FEmenu();
                 frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING);
             }
             break;
         case 'sendready':
             //we update the senddate of the newsletter
             jNews_Mailing::updatesenddate($mailingId);
             jNews_MailingsHTML::sendReady($mailingId, $listId, $listType);
             break;
         case 'send':
             if (!(require_once JNEWSPATH_CLASS . 'class.queue.php')) {
                 return false;
             }
             $queueC = new jNews_Queue();
             $queueC->checkForNewsletters($mailingId);
             $queueCount = jNews_Queue::getQueueCount($mailingId);
             $totalSub = JRequest::setVar('totalsend', $queueCount);
             $linkBut = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=continuesend&mailingid=' . $mailingId . '&totalsend=' . $totalSub, true, false, true);
             jNews_Tools::redirect($linkBut);
             //this line was commented out, we need this so that when we click the send button in the frontend the status of the sending will be displayed
             break;
         case 'continuesend':
             if (require_once JNEWSPATH_CLASS . 'class.queue.php') {
                 $queueC = new jNews_Queue();
                 $totalSend = JRequest::getVar('totalsend', 0, '', 'int');
                 $alreadySent = JRequest::getVar('alreadysent', 0, '', 'int');
                 $queueC->start = $alreadySent;
                 $queueC->total = $totalSend;
                 $queueC->pause = $GLOBALS[JNEWS . 'pause_time'];
                 $queueC->sendQueue(false, $mailingId, false, true);
             }
             ob_start();
             exit;
             break;
         case 'unpublished':
             JRequest::checkToken() or die('Invalid Token');
             jNews_Mailing::unpublishMailing($mailingId);
             frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING);
             break;
         case 'copy':
             JRequest::checkToken() or die('Invalid Token');
             $message = jnews::printYN(jNews_Mailing::copyMailing($mailingId), _JNEWS_MAILING_COPY, _JNEWS_ERROR);
             if (empty($listId) or $listId == 0) {
                 $lsid = jNews_Mailing::getListId($mailingId);
             }
             jNews_Mailing::insertListMailings($listId);
             frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING);
             break;
         case 'cpanel':
             jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION);
             break;
         default:
             //alex archive
             //				$viewarchive = false;
             //				if(empty($my->id)) $viewarchive = true;
             $viewarchive = true;
             frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, $viewarchive, _JNEWS_MENU_MAILING);
             break;
     }
     return true;
 }
예제 #5
0
/**
* <p>Templates controller</p>
* <p>This function is the controller to view the templates view</p>
* @author Joobi Limited <wwww.joobi.co>
*/
function templates($action, $task, $template_id)
{
    $my = JFactory::getUser();
    $css = '.icon-48-templates { background-image:url(' . JNEWS_PATH_ADMIN_IMAGES2 . 'header/templates.png)}';
    $doc = JFactory::getDocument();
    $doc->addStyleDeclaration($css, $type = 'text/css');
    $img = 'templates.png';
    $templatesearch = JRequest::getVar('templatesearch', '');
    $showTemplates = true;
    // defined toggle for publish and unpublish of mailings
    $willRedirect = false;
    $checkToggle = false;
    $cid = JRequest::getVar('cid');
    if (empty($template_id)) {
        if (!empty($cid) && is_array($cid)) {
            $template_id = $cid[key($cid)];
        }
    } else {
        if (empty($cid)) {
            $cid[] = $template_id;
        }
    }
    if (!empty($task) && $task == 'togle') {
        $checkToggle = true;
        //		$id = JRequest::getVar( 'templateid' );
        $id = $template_id;
        $col = JRequest::getVar('col');
        $template_id = !empty($id) && !empty($col) ? $id : $template_id;
        $task = !empty($template_id) && !empty($col) ? $col : $task;
        $willRedirect = true;
    }
    switch ($task) {
        case 'new':
        case 'add':
            $showTemplates = false;
            $template = null;
            $form['main'] = " <form action='index.php' method='post' name='adminForm' enctype='multipart/form-data' id=\"adminForm\"> \n";
            $message = isset($message) ? $message : '';
            backHTML::_header(_JNEWS_TEMPLATES, 'templates.png', $message, $task, $action);
            backHTML::formStart('template', 0, '');
            echo jNews_TemplatesHTML::createTemplate($template, $form);
            $go[] = jnews::makeObj('act', $action);
            backHTML::formEnd($go);
            break;
        case 'edit':
            $showTemplates = false;
            $template = jNews_Templates::loadOneTemplate('*', $template_id);
            $form['main'] = " <form action='index.php' method='post' name='adminForm' enctype='multipart/form-data' id=\"adminForm\">";
            $message = isset($message) ? $message : '';
            backHTML::_header(_JNEWS_TEMPLATES, 'templates.png', $message, $task, $action);
            backHTML::formStart('template', 0, '');
            echo jNews_TemplatesHTML::createTemplate($template, $form);
            $go[] = jnews::makeObj('act', $action);
            $go[] = jnews::makeObj('template_id', $template_id);
            backHTML::formEnd($go);
            break;
        case 'save':
            JRequest::checkToken() or die('Invalid Token');
            $message = jnews::printYN(jNews_Templates::saveTemplate($task, $template_id), _JNEWS_TEMPLATE_SAVED, _JNEWS_ERROR);
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=templates', $message);
            break;
        case 'apply':
            JRequest::checkToken() or die('Invalid Token');
            $message = '';
            $message .= jnews::printYN(jNews_Templates::saveTemplate($task, $template_id), _JNEWS_TEMPLATE_SAVED, _JNEWS_ERROR);
            $id = empty($template_id) ? jNews_Templates::loadOneTemplate('template_id', '', 'template_id', 'DESC') : $template_id;
            $converMessage = JRequest::getVar('message', '', '', 'string', JREQUEST_ALLOWRAW);
            if (!empty($converMessage)) {
                $message .= '<br/>';
                $message .= implode("", $converMessage);
            }
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=templates&task=edit&template_id=' . $id, $message);
            break;
        case 'publish':
            if (!$checkToggle) {
                JRequest::checkToken() or die('Invalid Token');
            }
            $message = jnews::printYN(jNews_Templates::updateTemplate($cid, 'published', true), 'Successfully published template!', 'Error publishing the template!');
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=templates', $message);
            break;
        case 'unpublish':
            if (!$checkToggle) {
                JRequest::checkToken() or die('Invalid Token');
            }
            $condition = jNews_Templates::updateTemplate($cid, 'published', false);
            if ($condition) {
                $message = jnews::printM('ok', 'Successfully unpublished template!');
            } else {
                $message = jnews::printM('defaulterror', 'Unable to unpublished default template!');
            }
            //	   		$message = jnews::defaultYN( jNews_Templates::updateTemplate($template_id,'published', false) ,  'Successfully unpublished template!' , 'Unable to unpublished default  template!' );
            if ($willRedirect) {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=templates', $message);
            }
            break;
        case 'copy':
            JRequest::checkToken() or die('Invalid Token');
            $message = jnews::printYN(jNews_Templates::copyTemplate($template_id), _JNEWS_TEMPLATE . _JNEWS_SUCCESS_COPIED, _JNEWS_ERROR);
            $showTemplates = true;
            break;
        case 'default':
            $success = false;
            //set all the templates to premium = 0
            if (jNews_Templates::updateTemplate($template_id, 'default', false, false)) {
                $success = true;
            }
            //set the template published and premium
            if ($success) {
                jNews_Templates::updateTemplate($template_id, 'default', true, true);
            }
            $message = jnews::printYN($success, 'Successfully set the template to default!', 'Unable to set template to default!');
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=templates', $message);
            break;
        case 'delete':
            JRequest::checkToken() or die('Invalid Token');
            $showTemplates = true;
            $isDefault = jNews_Templates::loadOneTemplate('premium', $template_id);
            if (!$isDefault) {
                $message = jnews::printYN(jNews_Templates::deleteTemplate($cid), _JNEWS_TEMPLATE . _JNEWS_SUCCESS_DELETED, _JNEWS_ERROR);
            } else {
                $message = jnews::printM('red', _JNEWS_TEMPLATE_DEFAULT_NODEL);
            }
            break;
        case 'cpanel':
            backHTML::controlPanel();
            return true;
            break;
        case 'toggle':
            JRequest::checkToken() or die('Invalid Token');
            // main toggle for all usage
            $listid = JRequest::getVar('listid');
            $column = JRequest::getVar('col');
            if (!empty($listid) && !empty($column)) {
                $passObj = new stdClass();
                $passObj->tableName = '#__jnews_lists';
                $passObj->columnName = $column;
                $passObj->whereColumn = 'id';
                $passObj->whereColumnValue = $listid;
                jnews::toggle($passObj);
            }
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=templates');
            break;
        case 'tempupload':
            // HTML for upload template
            //			JRequest::checkToken() or die( 'Invalid Token' );
            $html = '<form action="index.php?option=' . JNEWS_OPTION . '&act=templates&task=upload" method="post" name="adminForm" enctype="multipart/form-data" id="adminForm">';
            $html .= '<table style="width:100%;padding:100px;">';
            $html .= '<tr>';
            $html .= '<td style="text-align:center;"> <input type="FILE" name="tempupload"> </td>';
            $html .= '</tr><tr">';
            $html .= '<td style="text-align:center;padding:20px;"> <input type="submit" value="Upload Template" style="width:130px;height:25px;"> </td>';
            $html .= '</tr>';
            $html .= '</table>';
            if (version_compare(JVERSION, '3.0.0', '<')) {
                $html .= JHTML::_('form.token');
            } else {
                $html .= JHtml::_('form.token');
            }
            $html .= '</form><br/><br/>';
            echo $html;
            $showTemplates = false;
            break;
        case 'sendtest':
            JRequest::checkToken() or die('Invalid Token');
            //we save first the template
            $saveStatus = jNews_Templates::saveTemplate($task, $template_id);
            //then we send it if the template is successfully saved
            if ($saveStatus) {
                $message = jnews::printM('ok', _JNEWS_TEMPLATE_SAVED);
                $my = JFactory::getUser();
                $mailing = new stdClass();
                $receiver = new stdClass();
                $status = false;
                $mailing->id = 1;
                $mailing->html = 1;
                $mailing->images = '';
                $mailing->attachments = '';
                $mailing->subject = jNews_Templates::loadOneTemplate('name', $template_id);
                $mailing->htmlcontent = jNews_Templates::loadOneTemplate('body', $template_id);
                $mailing->template_id = $template_id;
                $receiver->name = $my->name;
                $receiver->email = $my->email;
                $receiver->receive_html = 1;
                $receiver->user_id = $my->id;
                $mailerC = new jNews_ProcessMail();
                $sendStatus = $mailerC->send($mailing, $receiver);
                $success = 'Template ' . $mailing->subject . ' successfully sent to ' . $receiver->email;
                $error = 'There is a problem in sending the template ' . $mailing->subject . ' <br/>' . _JNEWS_SENDTEST_CONFIGERROR;
                $message = $sendStatus ? jnews::printM('ok', $success) : jnews::printM('error', $error);
            } else {
                //otherwise we give an error message
                $message = jnews::printM('error', _JNEWS_ERROR);
            }
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=templates&task=edit&template_id=' . $template_id, $message);
            break;
        case 'upload':
            JRequest::checkToken() or die('Invalid Token');
            $db = JFactory::getDBO();
            $fileName = $_FILES['tempupload']['name'];
            $folderName = substr($fileName, 0, -4);
            // explode to array to compare and check if the uploaded file is a zip file
            $type = $_FILES['tempupload']['type'];
            // if zip is not found then return to previous upload page
            if (strtolower($type) != 'application/zip') {
                if (strtolower(substr($fileName, -4)) != '.zip') {
                    if (version_compare(JVERSION, '1.6.0', '<')) {
                        //j15
                        echo "<script> alert('" . addslashes(_JNEWS_UPLOAD_ZIP_INVALID) . "'); document.location.href='index.php?option='.JNEWS_OPTION.'&act=templates';</script>";
                    } else {
                        if (version_compare(JVERSION, '3.0.0', '<')) {
                            echo "<script> alert('" . addslashes(_JNEWS_UPLOAD_ZIP_INVALID) . "'); window.parent.SqueezeBox.close();</script>";
                        } else {
                            echo "<script> alert('" . addslashes(_JNEWS_UPLOAD_ZIP_INVALID) . "');   jQuery(window.top.document).find(\"div.modal-backdrop\").click(); </script>";
                        }
                    }
                    break;
                }
            }
            $result = jNews_Templates::uploadTemplate();
            if ($result) {
                // if success
                // read index.html of file for template body content
                $tempPath = JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates' . DS;
                $file = fopen($tempPath . $folderName . DS . 'index.html', "r") or exit("Unable to open file!");
                $tempbody = array();
                while (!feof($file)) {
                    $tempbody[] = fgets($file);
                }
                //endwhile
                fclose($file);
                $tempbody = implode(' ', $tempbody);
                $standardCSSA = array();
                $extraCSSStyles = '';
                if (is_file($tempPath . $folderName . DS . 'css' . DS . 'style.css')) {
                    //new template package with style.css file
                    //we get here the css codes from the uploaded template
                    $cssfile = fopen($tempPath . $folderName . DS . 'css' . DS . 'style.css', "r") or exit("Unable to open file!");
                    $cssstyle = array();
                    while (!feof($cssfile)) {
                        $cssstyle[] = fgets($cssfile);
                    }
                    //endwhile
                    fclose($cssfile);
                    $cssstyle = implode(' ', $cssstyle);
                    $cleanCSSstyle = jNews_Templates::cleanCSSComments($cssstyle);
                    //cleancsscomments
                    @(require_once JNEWSPATH_CLASS . 'class.cssinlinestyles.php');
                    if (class_exists('CSSToInlineStyles')) {
                        $newCSSProcess = new CSSToInlineStyles();
                        $newCSSProcess->setCSS($cleanCSSstyle);
                        $newCSSProcess->processCSS();
                        //we define the predefined selectors for the css
                        $standardSelectorsA = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'a', 'ul', 'li', '.unsubscribe', '.subscriptions', '.content', '.title', '.readmore', '.online', '.aca_content', '.aca_title', '.aca_readmore', '.aca_online', '.aca_subscribe', '.aca_unsubscribe', '.aca_subscriptions');
                        $standardCSSA = $newCSSProcess->getStandardCSSTag($newCSSProcess->cssRules, $standardSelectorsA);
                        $extraCSSStyles = $newCSSProcess->getExtraCSSTag($newCSSProcess->cssRules, $standardSelectorsA);
                    }
                }
                // replace source image paths from 'images/' to 'media/.../templates/$FOLDERNAME/'
                $bodyImgA = JRequest::getVar('bodyImg');
                if (is_file($tempPath . $folderName . DS . 'css' . DS . 'style.css')) {
                    //new template package
                    //					$body = preg_replace('#images\/#', JNEWS_JPATH_LIVE . '/media/'. JNEWS_OPTION . '/templates/' . $folderName .'/images/', $tempbody);
                    $origin = '"images/';
                    $destination = '"' . JNEWS_JPATH_LIVE . '/media/' . JNEWS_OPTION . '/templates/' . $folderName . '/images/';
                    $body = str_replace($origin, $destination, $tempbody);
                } else {
                    //					$body = preg_replace('#images\/#', JNEWS_JPATH_LIVE . '/media/'. JNEWS_OPTION . '/templates/'. $folderName.'/' , $tempbody);
                    $origin = 'media/' . JNEWS_OPTION . '/templates/' . $folderName . '/';
                    $destination = JNEWS_JPATH_LIVE . '/media/' . JNEWS_OPTION . '/templates/' . $folderName . '/';
                    $body = str_replace($origin, $destination, $tempbody);
                }
                $template = null;
                $template->name = ucfirst($folderName);
                $template->description = '';
                $template->created = time();
                $template->body = addslashes($body);
                $template->altbody = '';
                $template->premium = 0;
                $template->namekey = $folderName;
                $template->published = 1;
                $template->styles = addslashes(serialize($standardCSSA));
                $template->csstyle = addslashes($extraCSSStyles);
                $template->thumbnail = '';
                $templateA = (array) $template;
                $query = 'SELECT * FROM `#__jnews_templates` WHERE `namekey` = \'' . $template->namekey . '\' ';
                $db->setQuery($query);
                $findresult = $db->loadObject();
                if (empty($findresult)) {
                    // store template
                    $status = jNews_Templates::storeTemplate($templateA);
                } else {
                    //update template
                    $query = 'UPDATE `#__jnews_templates` SET `body` = \'' . $template->body . '\' , `availability` = 1 WHERE `namekey`= \'' . $template->namekey . '\'  AND `template_id`=' . $findresult->template_id;
                    $db->setQuery($query);
                    $status = $db->query();
                }
                // upload success
                // display success message
                if ($status) {
                    if (version_compare(JVERSION, '1.6.0', '<')) {
                        //j15
                        echo "<script> alert('" . addslashes(_JNEWS_TEMPLATE_UPLOAD_SUCCESS) . "'); document.location.href='index.php?option=" . JNEWS_OPTION . "&act=templates';</script>";
                    } else {
                        //j16
                        echo "<script> alert('" . addslashes(_JNEWS_TEMPLATE_UPLOAD_SUCCESS) . "'); window.parent.location.reload();</script>";
                    }
                }
            } else {
                // failed uploading
                // display an error message
                if (version_compare(JVERSION, '1.6.0', '<')) {
                    //j15
                    echo "<script> alert('" . addslashes(_JNEWS_TEMPLATE_UPLOAD_FAIL) . "'); document.location.href='index.php?option=" . JNEWS_OPTION . "&act=templates';</script>";
                } else {
                    if (version_compare(JVERSION, '3.0.0', '<')) {
                        echo "<script> alert('" . addslashes(_JNEWS_TEMPLATE_UPLOAD_FAIL) . "'); window.parent.SqueezeBox.close();</script>";
                    } else {
                        echo "<script> alert('" . addslashes(_JNEWS_TEMPLATE_UPLOAD_FAIL) . "');   jQuery(window.top.document).find(\"div.modal-backdrop\").click(); </script>";
                    }
                }
            }
            $showTemplates = false;
            break;
        case 'preview':
            $forms['main'] = " <form action='index.php' method='post' name='adminForm' id=\"adminForm\">";
            $forms['filter'] = " <form name='jnewsFilterForm' method='POST' action='index.php'> \n";
            $id = JRequest::getInt('template_id', 0, 'request');
            $body = jNews_Templates::loadOneTemplate('body', $id);
            jNews_Templates::includeStyles($body, $id);
            jNews_TemplatesHTML::previewTemplate($body, $forms);
            $showTemplates = false;
            break;
        case 'assign':
            $templatesearch = JRequest::getVar('templatesearch', '');
            $linkTh = jNews_Tools::completeLink('option=' . JNEWS_OPTION, true, false, true);
            $forms['main'] = "<form action=" . $linkTh . " method='post' name='adminForm' id=\"adminForm\">";
            $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_Templates::countTemplates(1, 1);
            $setLimit = new stdClass();
            $setLimit->total = !empty($limittotal) ? $limittotal : 0;
            $setLimit->start = !empty($limitstart) ? $limitstart : 0;
            $setLimit->end = !empty($limitend) ? $limitend : 20;
            $templates = jNews_Templates::getTemplates(true, false, $templatesearch, $setLimit->start, $setLimit->end, null, 1);
            //first param to true to show only the published
            jNews_TemplatesHTML::assignTemplate($templates, $forms, $setLimit, $templatesearch);
            $showTemplates = false;
            break;
    }
    if ($showTemplates) {
        $start = JRequest::getVar('start', '0');
        $templatesearch = JRequest::getVar('templatesearch', '');
        $limit = -1;
        $message = isset($message) ? $message : '';
        backHTML::_header(_JNEWS_TEMPLATES, $img, $message, $task, $action);
        $forms['main'] = " <form action='index.php' method='post' name='adminForm' id=\"adminForm\">";
        $forms['filter'] = " <form name='jnewsFilterForm' method='POST' action='index.php'> \n";
        backHTML::formStart('show_template', '', '');
        // added this code for pagination ===========================
        $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');
        }
        $setSort = new stdClass();
        $setSort->orderValue = $app->getUserStateFromRequest(JNEWS_OPTION . '.templates.filter_order', 'filter_order', 'premium', 'cmd');
        $setSort->orderDir = $app->getUserStateFromRequest(JNEWS_OPTION . '.templates.filter_order_Dir', 'filter_order_Dir', 'desc', 'word');
        $limittotal = jNews_Templates::countTemplates();
        $setLimit = new stdClass();
        $setLimit->total = !empty($limittotal) ? $limittotal : 0;
        $setLimit->start = !empty($limitstart) ? $limitstart : 0;
        $setLimit->end = !empty($limitend) ? $limitend : $limittotal;
        // recheck start
        if ($setLimit->total == $setLimit->end) {
            $setLimit->start = 0;
        }
        $templates = jNews_Templates::getTemplates(false, false, $templatesearch, $setLimit->start, $setLimit->end, $setSort);
        //recheck limit total [pagination]
        if (isset($setLimit->total) && !empty($templatesearch)) {
            $setLimit->total = !empty($temps) ? count($templates) : $setLimit->total;
        }
        jNews_TemplatesHTML::displayTemplateList($templates, $forms, $setLimit->start, $setLimit->end, $templatesearch, $action, $setLimit, $setSort);
        $go[] = jnews::makeObj('act', 'templates');
        $go[] = jnews::makeObj('filter_order', $setSort->orderValue);
        $go[] = jnews::makeObj('filter_order_Dir', $setSort->orderDir);
        backHTML::formEnd($go);
    }
    return true;
}
예제 #6
0
function update($action, $task)
{
    require_once JNEWSPATH_CLASS . 'class.update.php';
    $update = new jNews_Update();
    $showListing = true;
    $showComplete = false;
    $message = JRequest::getVar('message', '');
    if (!ini_get('safe_mode')) {
        @set_time_limit(60 * $GLOBALS[JNEWS . 'script_timeout']);
    }
    //css injection for the images
    $doc = JFactory::getDocument();
    $css = '.icon-48-import { background-image:url(' . JNEWS_PATH_ADMIN_IMAGES2 . 'header/import.png)}';
    $doc->addStyleDeclaration($css, $type = 'text/css');
    switch ($task) {
        case 'doUpdate':
            backHTML::_header(_JNEWS_MENU_UPDATE, 'update', $message, $task, $action);
            $update->doUpdate();
            $showListing = false;
            $showComplete = false;
            break;
        case 'version':
            $update->getVersion();
            break;
        case 'complete':
            $showComplete = true;
            $showListing = false;
            break;
        case 'cancel':
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=update');
            $showListing = false;
            break;
        case 'cpanel':
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION);
            $showListing = false;
            break;
        case 'new1':
            backHTML::_header(_JNEWS_MENU_UPDATE, 'import.png', $message, $task, $action);
            $message = jnews::printYN(jnews::upgrade_News1(), '<br />' . _JNEWS_IMPORT_SUCCESS . ' Anjel data', _JNEWS_ERROR);
            jnews::resetUpgrade(1);
            echo '<br />' . $message;
            break;
        case 'new2':
            backHTML::_header(_JNEWS_MENU_UPDATE, 'import.png', $message, $task, $action);
            $message = jnews::printYN(jnews::upgrade_News2(), '<br />' . _JNEWS_IMPORT_SUCCESS . ' Letterman data', _JNEWS_ERROR);
            jnews::resetUpgrade(2);
            echo '<br />' . $message;
            break;
        case 'new3':
            backHTML::_header(_JNEWS_MENU_UPDATE, 'import.png', $message, $task, $action);
            $message = jnews::printYN(jnews::upgrade_News3(), '<br />' . _JNEWS_IMPORT_SUCCESS . ' YaNC data', _JNEWS_ERROR);
            jnews::resetUpgrade(3);
            echo '<br />' . $message;
            break;
    }
    if ($showListing) {
        backHTML::_header(_JNEWS_MENU_UPDATE, 'import.png', $message, $task, $action);
        backHTML::_upgrade();
        $forms['main'] = " <form action='index.php' method='post' name='adminForm' id=\"adminForm\">";
        echo $forms['main'];
        backHTML::formStart('', '', '');
        backHTML::showCompsList($update);
        $go[] = jnews::makeObj('act', $action);
        backHTML::formEnd($go);
    } elseif ($showComplete) {
        backHTML::_header(_JNEWS_MENU_UPDATE, 'import.png', $message, $task, $action);
        $forms['main'] = " <form action='index.php' method='post' name='adminForm' id=\"adminForm\">";
        echo $forms['main'];
        backHTML::formStart('', '', '');
        backHTML::showUpdateOptions($update);
        $go[] = jnews::makeObj('act', $action);
        backHTML::formEnd($go);
    }
}
예제 #7
0
파일: jnews.php 프로젝트: naka211/kkvn
         frontEnd::newSubscriberContinue($message_arr['newsubscriber']);
     }
     if ($GLOBALS[JNEWS . 'addEmailRedLink']) {
         if (strpos($redirectlink, '?')) {
             $redirectlink .= '&email=' . $email;
         } else {
             $redirectlink .= '?email=' . $email;
         }
         //endelse
     }
     $showMessage = JRequest::getVar('listname', 0);
     if (!empty($redirectlink)) {
         if (!$showMessage) {
             $message = '';
         }
         jNews_Tools::redirect($redirectlink, $message);
     } else {
         $showPanel = true;
     }
     break;
 case 'list':
     if (empty($listId)) {
         $listId = JRequest::getVar('list_id');
     }
     frontEnd::showLists($subscriberId, $listId, $lisType, $action, $task);
     break;
 case 'statistics':
     if (empty($listType)) {
         $listType = 1;
     }
     frontend::statisticsFE($action, $task, $listId, $listType, $mailingId, $message, $Itemid);
예제 #8
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;
}
예제 #9
0
파일: jnews.php 프로젝트: naka211/kkvn
function configuration($action, $task)
{
    $db = JFactory::getDBO();
    $config = array();
    $redirect = true;
    $xf = new jNews_Config();
    $message = JRequest::getVar('message', '');
    $clear_log = JRequest::getVar('clear_log', '0');
    switch ($task) {
        case 'syncUsers':
            echo jnews::printYN(jNews_Subscribers::syncSubscribers(), _JNEWS_SYNC_USERS_SUCCESS, _JNEWS_ERROR);
            backHTML::_header(_JNEWS_MENU_CONF, 'configuration.png', $message, $task, $action);
            jNews_ConfigHTML::showConfigEdit();
            break;
        case 'sendtest':
            $my = JFactory::getUser();
            $mailing = new stdClass();
            $status = false;
            $mailing->id = 1;
            $mailing->images = '';
            $mailing->attachments = '';
            $mailing->fromname = trim($GLOBALS[JNEWS . 'sendmail_name']);
            $mailing->fromemail = trim($GLOBALS[JNEWS . 'sendmail_email']);
            if (empty($mailing->fromemail)) {
                $mailing->fromemail = trim($GLOBALS[JNEWS . 'sendmail_from']);
            }
            ### create the mail
            $mail = jNews_ProcessMail::getMailer($mailing);
            ### create content
            $mail->IsHTML(true);
            $mail->Body = '<p>This message has been sent at ' . date('l, j F Y h:i:s', jnews::getNow(0, true)) . ' from ' . JNEWS_JPATH_LIVE . ' to test your mail configuration.</p><br/><p style="color:green;">' . _JNEWS_SENDTEST_CONFIGSUCC . '</p>';
            $mail->AddAddress($my->email, $my->name);
            $mail->Subject = 'Test Email from ' . JNEWS_JPATH_LIVE;
            $status = $mail->Send();
            $success = 'Email "' . $mail->Subject . '" successfully sent to ' . $my->name . ' (' . $my->email . ')';
            $error = 'Failed sending "' . $mail->Subject . '" to ' . $my->name . ' (' . $my->email . '). <br/>' . _JNEWS_SENDTEST_CONFIGERROR;
            $message = is_bool($status) && $status ? jnews::printM('ok', $success) : jnews::printM('error', $error);
            backHTML::_header(_JNEWS_MENU_CONF, 'configuration.png', $message, $task, $action);
            jNews_ConfigHTML::showConfigEdit();
            echo $message;
            break;
        case 'apply':
        case 'save':
            JRequest::checkToken() or die('Invalid Token');
            if ($clear_log != 0) {
                @unlink(JNEWS_JPATH_ROOT_NO_ADMIN . $GLOBALS[JNEWS . 'save_log_file']);
            }
            $config = JRequest::getVar('config');
            $message = jnews::printYN($xf->saveConfig($config), _JNEWS_CONFIG_UPDATED, _JNEWS_ERROR);
            $listCreator = JRequest::getVar('list_creatorfe', '', 'post');
            if (!empty($listCreator)) {
                $xf->update('list_creatorfe', $listCreator);
            }
            //we update the active list
            $xf->updateActiveList();
            if ($GLOBALS[JNEWS . 'level'] > 1) {
                //we require the cron controller
                require_once JNEWSPATH_ADMIN . 'controllers' . DS . 'cron.jnews.php';
                //we update the published/enabld of the jnews cron plugin according to what is selected
                if (version_compare(JVERSION, '1.6.0', '<')) {
                    //j15
                    $db->setQuery("UPDATE `#__plugins` SET `published` = " . $config['jnewscronplugin'] . " WHERE `element`='jnewscron' ");
                } else {
                    //j16
                    $db->setQuery("UPDATE `#__extensions` SET `enabled` = " . $config['jnewscronplugin'] . " WHERE `type` = 'plugin' AND `element`='jnewscron' ");
                }
                $db->query();
                //Joobi Cron System
                $cron = $GLOBALS[JNEWS . 'j_cron'];
                if ($cron == 2) {
                    joobiCron('Yes');
                } else {
                    joobiCron('No');
                }
            }
            if ($task == 'apply') {
                backHTML::_header(_JNEWS_MENU_CONF, 'configuration.png', $message, $task, $action);
                jNews_ConfigHTML::showConfigEdit();
                echo $message;
            } else {
                backHTML::controlPanel();
            }
            break;
        case 'cancel':
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION);
            break;
        case 'cpanel':
            backHTML::controlPanel();
            break;
        case 'acaupdate':
            // update jnews datas from acajoom
            $msg = jNews_TableUpdate::executeUpdate();
            echo $msg . '<br><br>';
        default:
            backHTML::_header(_JNEWS_MENU_CONF, 'configuration.png', $message, $task, $action);
            jNews_ConfigHTML::showConfigEdit();
            break;
    }
    return true;
}
예제 #10
0
/**
 * <p>Function to send/forward the mailings to a the friends</p>
 * @param object $mailing - the mailing object that will be sent. Its from a query
 * @param object $messagePlgin  - the messages in the parameter of the plugin
 * @param array $receiversNames - the name to whom the mail to be forwarded
 * @param array $receiversEmails - the emails where the mail to be forwarded
 * @param object $list - the list where the mailing belongs.
 */
function sendtofriend($mailing = null, $messagePlgin = null, $receiversNames = '', $receiversEmails = '', $list = null)
{
    $message = '';
    $receivers = null;
    $inEmailMessageHTML = '<br/><div align="left" style="border: 1px solid rgb(239, 236, 186); padding: 5px; background-color: rgb(251, 250, 231); text-align: left;">';
    $replaceWhat = array('[FWDEMAIL]', '[FWDNAME]');
    $replaceBy = array($mailing->fromemail, $mailing->name);
    $inEmailMessageHTML .= str_replace($replaceWhat, $replaceBy, $messagePlgin->inEmail);
    $inEmailMessageHTML .= '</div><br/>';
    $body = $messagePlgin->dflt . '<br/>' . $inEmailMessageHTML . $mailing->htmlcontent;
    $textonly = $messagePlgin->dflt . $messagePlgin->inEmail . $mailing->textonly;
    $mailing->htmlcontent = $body;
    $mailing->textonly = $textonly;
    $receivers->receive_html = $list->html;
    $status = true;
    $successM = '';
    static $mailerC = null;
    if (!isset($mailerC)) {
        $mailerC = new jNews_ProcessMail();
    }
    foreach ($receiversNames as $key => $receiversName) {
        $receivers->name = $receiversName;
        $receivers->email = $receiversEmails[$key];
        //		$reWhat = array('[FWDEMAIL]','[FWDNAME]', '[NAME]','[FIRSTNAME]','[USERNAME]');
        $reWhat = array('[FWDEMAIL]', '[FWDNAME]', '{tag:name}', '{tag:firstname}', '{tag:username}');
        $reBy = array($mailing->fromemail, $mailing->name, $receiversName, $receiversName, $receiversName);
        $mailing->htmlcontent = str_replace($reWhat, $reBy, $mailing->htmlcontent);
        $mailing->textonly = str_replace($reWhat, $reBy, $mailing->textonly);
        if (!$mailerC->send($mailing, $receivers)) {
            $status = false;
        }
        if ($status) {
            $successM .= _JNEWS_FWDTOFRIEND_SUCCESS . $receiversName . '.<br>';
        } else {
            $successM .= _JNEWS_FWDTOFRIEND_FAILED . $receiversName . '.<br>';
        }
    }
    // 	$url = JURI::current().'?option='.JNEWS_OPTION.'&act=fwdtofriend&frmname='.base64_encode($mailing->fromname).'&frmemail='.base64_encode($mailing->fromemail).'&mailingid='.$mailing->id;
    $url = 'index.php?option=' . JNEWS_OPTION . '&act=fwdtofriend&frmname=' . base64_encode($mailing->fromname) . '&frmemail=' . base64_encode($mailing->fromemail) . '&mailingid=' . $mailing->id;
    jNews_Tools::redirect($url, $successM);
}
예제 #11
0
function lists($action, $task, $listId, $listType)
{
    $db = JFactory::getDBO();
    $my = JFactory::getUser();
    $css = '.icon-48-lists { background-image:url(' . JNEWS_PATH_ADMIN_IMAGES2 . 'header/lists.png)}';
    $doc = JFactory::getDocument();
    $doc->addStyleDeclaration($css, $type = 'text/css');
    $img = 'lists.png';
    $listsearch = JRequest::getVar('listsearch', '');
    $message = '';
    $xf = new jNews_Config();
    $showLists = true;
    $checkToggle = false;
    // defined toggle for publish and unpublish of mailings
    if (!empty($task) && $task == 'togle') {
        $checkToggle = true;
        $id = JRequest::getVar('listid');
        $col = JRequest::getVar('col');
        $listId = !empty($id) && !empty($col) ? $id : $listId;
        $task = !empty($listId) && !empty($col) ? $col : $task;
    }
    switch ($task) {
        case 'new':
        case 'add':
            $subscriber = jNews_Subscribers::getSubscriberInfoFromUserId($my->id);
            if (version_compare(JVERSION, '1.6.0', '<')) {
                //j15
                $acl = JFactory::getACL();
                $groups = $acl->get_group_children_tree(null, 'USERS', false);
            } else {
                //j16
                $db = JFactory::getDBO();
                $db->setQuery('SELECT a.*, a.title as text, a.id as value  FROM #__usergroups AS a ORDER BY a.lft ASC');
                $groups = $db->loadObjectList();
            }
            $allGroupIds = array();
            foreach ($groups as $oneGroup) {
                $allGroupIds[] = $oneGroup->value;
            }
            $newList = new stdClass();
            $showLists = false;
            $newList->id = '';
            $newList->html = 1;
            $newList->new_letter = 1;
            $newList->list_name = '';
            $newList->list_desc = '';
            $newList->template = '';
            if (empty($subscriber)) {
                $newList->sendername = '';
                $newList->senderemail = '';
                $newList->bounceadres = '';
            } else {
                $newList->sendername = '';
                $newList->senderemail = '';
                $newList->bounceadres = '';
            }
            $newList->hidden = 1;
            $newList->auto_add = 0;
            $newList->list_type = $listType;
            $newList->delay_min = 1;
            $newList->delay_max = 7;
            $newList->user_choose = 0;
            $newList->cat_id = '0:0';
            $newList->follow_up = '';
            $newList->notify_id = 0;
            $newList->owner = $my->id;
            $newList->acc_level = '24,25,7,8';
            $newList->acc_id = implode(',', $allGroupIds);
            $newList->published = 1;
            $newList->start_date = date('Y-m-d', time());
            $newList->next_date = jnews::getNow();
            $newList->subscribemessage = _JNEWS_DEFAULT_SUBSCRIBE_MESS;
            $newList->unsubscribemessage = _JNEWS_DEFAULT_UNSUBSCRIBE_MESS;
            $newList->notifyadminmsg = _JNEWS_UNSUBSCRIBE_ADMIN_NOTIFICATION;
            $newList->subnotifymsg = _JNEWS_SUBSDEFAULT_NOTIFYMSG;
            $newList->subnotifysend = 1;
            $newList->unsubscribesend = 1;
            $newList->unsubscribenotifyadmin = 1;
            $newList->footer = 1;
            $forms['main'] = " <form action='index.php' method='post' name='adminForm' id=\"adminForm\">";
            $show = jNews_ListType::showType($newList->list_type, 'editlist');
            if ($listType == 1) {
                backHTML::_header(_JNEWS_NEW . ' ' . _JNEWS_LIST, $img, $message, $task, $action);
            } else {
                backHTML::_header(_JNEWS_NEW . ' ' . _JNEWS_AUTORESP . ' ' . _JNEWS_LIST, $img, $message, $task, $action);
            }
            backHTML::formStart('editlist', $newList->html, '');
            jNews_ListsHTML::editList($newList, $forms, $show, $listType);
            $go[] = jnews::makeObj('act', $action);
            $go[] = jnews::makeObj('listid', $newList->id);
            backHTML::formEnd($go);
            break;
        case 'doNew':
            JRequest::checkToken() or die('Invalid Token');
            $listname = JRequest::getVar('list_name', '');
            if (empty($listname)) {
                echo "<script> alert(' List name must be filled out. '); window.history.go(-1);</script>\n";
                return false;
            }
            $now = jnews::getNow();
            $query = "SELECT `id` FROM `#__jnews_lists` WHERE `list_name`= '" . addslashes($listname) . "' ";
            $db->setQuery($query);
            $lId = $db->loadResult();
            if ($lId > 0) {
                echo "<script> alert(' This list already exist, please choose another name. '); window.history.go(-1);</script>\n";
                return false;
            } else {
                $query = "INSERT INTO `#__jnews_lists` (`list_name`,`createdate`) VALUES ( '" . addslashes($listname) . "'  , '{$now}' )";
                $db->setQuery($query);
                $db->query();
            }
            $query = "SELECT * FROM `#__jnews_lists` WHERE `list_name`= '" . addslashes($listname) . "' ";
            $db->setQuery($query);
            $mynewlist = $db->loadObject();
            $mynewlist->list_name = stripslashes($mynewlist->list_name);
            $mynewlist->list_desc = stripslashes($mynewlist->list_desc);
            $mynewlist->template = $mynewlist->template;
            $mynewlist->layout = stripslashes($mynewlist->layout);
            $mynewlist->subscribemessage = stripslashes($mynewlist->subscribemessage);
            $mynewlist->unsubscribemessage = stripslashes($mynewlist->unsubscribemessage);
            $mynewlist->notifyadminmsg = stripslashes($mynewlist->notifyadminmsg);
            $mynewlist->subnotifysend = stripslashes($mynewlist->subnotifysend);
            $mynewlist->subnotifymsg = stripslashes($mynewlist->subnotifymsg);
            $listId = $mynewlist->id;
            $message = jnews::printYN(jNews_Lists::updateListFromEdit($listId, '', true, $listType), _JNEWS_LIST_ADDED, _JNEWS_ERROR);
            $xf->plus('totallist0', 1);
            $xf->plus('act_totallist0', 1);
            $xf->plus('totallist' . $listType, 1);
            $xf->plus('act_totallist' . $listType, 1);
            break;
        case 'edit':
            if ($listId == 0) {
                echo "<script> alert('" . addslashes(_JNEWS_SELECT_LIST) . "'); window.history.go(-1);</script>\n";
                return false;
            } else {
                $showLists = false;
                $query = 'SELECT * FROM `#__jnews_lists` WHERE `id` = ' . intval($listId);
                $db->setQuery($query);
                $listEdit = $db->loadObject();
                if ($listEdit->acc_id == 'all') {
                    if (version_compare(JVERSION, '1.6.0', '<')) {
                        //j15
                        $acl = JFactory::getACL();
                        $groups = $acl->get_group_children_tree(null, 'USERS', false);
                    } else {
                        //j16
                        $db = JFactory::getDBO();
                        $db->setQuery('SELECT a.*, a.title as text, a.id as value  FROM #__usergroups AS a ORDER BY a.lft ASC');
                        $groups = $db->loadObjectList();
                    }
                    $allGroupIds = array();
                    foreach ($groups as $oneGroup) {
                        $allGroupIds[] = $oneGroup->value;
                    }
                    $listEdit->acc_id = implode(',', $allGroupIds);
                }
                $listEdit->list_name = stripslashes($listEdit->list_name);
                $listEdit->list_desc = stripslashes($listEdit->list_desc);
                $listEdit->template = $listEdit->template;
                $listEdit->layout = stripslashes($listEdit->layout);
                $listEdit->subscribemessage = stripslashes($listEdit->subscribemessage);
                $listEdit->unsubscribemessage = stripslashes($listEdit->unsubscribemessage);
                $listEdit->notifyadminmsg = stripslashes($listEdit->notifyadminmsg);
                $listEdit->subnotifysend = stripslashes($listEdit->subnotifysend);
                $listEdit->subnotifymsg = stripslashes($listEdit->subnotifymsg);
                $listEdit->new_letter = 0;
                $forms['main'] = " <form action='index.php' method='post' name='adminForm' id=\"adminForm\">";
                $show = jNews_ListType::showType($listEdit->list_type, 'editlist');
                backHTML::_header(_JNEWS_EDIT_A . @constant($GLOBALS[JNEWS . 'listname' . $listEdit->list_type]) . ' ' . _JNEWS_LIST, $img, $message, $task, $action);
                backHTML::formStart('listedit', $listEdit->html, '');
                jNews_ListsHTML::editList($listEdit, $forms, $show, $listType);
                $go[] = jnews::makeObj('act', $action);
                $go[] = jnews::makeObj('listid', $listEdit->id);
                backHTML::formEnd($go);
            }
            break;
        case 'update':
            JRequest::checkToken() or die('Invalid Token');
            $message = jnews::printYN(jNews_Lists::updateListFromEdit($listId, '', false, $listType), _JNEWS_LIST_UPDATED, _JNEWS_ERROR);
            break;
        case 'delete':
            JRequest::checkToken() or die('Invalid Token');
            $query = "SELECT list_name FROM #__jnews_lists WHERE id = {$listId}";
            $db->setQuery($query);
            $listName = $db->loadResult();
            $message = jnews::printYN(jNews_Lists::deleteList($listId), '"' . $listName . '"' . _JNEWS_LIST . _JNEWS_SUCCESS_DELETED, _JNEWS_ERROR);
            break;
        case 'copy':
            JRequest::checkToken() or die('Invalid Token');
            $message = jnews::printYN(jNews_Lists::copyList($listId), _JNEWS_LIST_COPY, _JNEWS_ERROR);
            break;
        case 'publish':
            if (!$checkToggle) {
                JRequest::checkToken() or die('Invalid Token');
            }
            $message = jnews::printYN(jNews_Lists::updateListFromList($listId, true, false), _JNEWS_PUBLISHED, _JNEWS_ERROR);
            if ($listType == 1) {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=list&listype=' . $listType);
            } else {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=arlist&listype=' . $listType);
            }
            break;
        case 'unpublish':
            if (!$checkToggle) {
                JRequest::checkToken() or die('Invalid Token');
            }
            $message = jnews::printYN(jNews_Lists::updateListFromList($listId, false, false), _JNEWS_UNPUBLISHED, _JNEWS_ERROR);
            if ($listType == 1) {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=list&listype=' . $listType . '&listid=' . $listId);
            } else {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=arlist&listype=' . $listType . '&listid=' . $listId);
            }
            break;
        case 'forms':
        case 'make':
            if (class_exists('jNews_CreateForm')) {
                jNews_CreateForm::taskOptions($task);
                $showLists = false;
            } else {
                $showLists = true;
            }
            break;
        case 'cpanel':
            backHTML::controlPanel();
            return true;
            break;
        case 'toggle':
            $listid = JRequest::getVar('listid');
            $column = JRequest::getVar('col');
            if (!empty($listid) && !empty($column)) {
                $passObj = new stdClass();
                $passObj->tableName = '#__jnews_lists';
                $passObj->columnName = $column;
                $passObj->whereColumn = 'id';
                $passObj->whereColumnValue = $listid;
                jnews::toggle($passObj);
            }
            if ($listType == 1) {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=list&listype=1');
            } else {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=arlist&listype=2');
            }
            break;
    }
    if ($showLists) {
        $limit = -1;
        //Title header
        if ($listType == 1) {
            backHTML::_header(_JNEWS_MENU_LIST, $img, $message, $task, $action);
        } else {
            backHTML::_header(_JNEWS_ARLIST, $img, $message, $task, $action);
        }
        $show = jNews_ListType::showType(0, 'showListsBack');
        $forms['main'] = "<form action='index.php' method='post' name='adminForm' id=\"adminForm\">";
        backHTML::formStart('show_mailing', '', '');
        $paginationStart = JRequest::getVar('pg');
        $app = JFactory::getApplication();
        if (!empty($paginationStart)) {
            $limitstart = 0;
            $limitend = $paginationStart;
        } else {
            $limitstart = $app->getUserStateFromRequest('limitstart', 'limitstart', 0, 'int');
            $limitend = $app->getUserStateFromRequest('limit', 'limit', 0, 'int');
        }
        $limittotal = jNews_Lists::getListCount($listType);
        $limittotal = $limittotal[0];
        $setLimit = new stdClass();
        $setLimit->total = !empty($limittotal) ? $limittotal : 0;
        $setLimit->start = !empty($limitstart) ? $limitstart : 0;
        $setLimit->end = !empty($limitend) ? $limitend : $limittotal;
        // recheck start
        if ($setLimit->total == $setLimit->end) {
            $setLimit->start = 0;
        }
        $setSort = new stdClass();
        if ($listType == '2') {
            //autoresponder
            $key = JNEWS_OPTION . '.arlist';
            $column = 'id';
            $direction = 'desc';
        } else {
            //newsletter
            $key = JNEWS_OPTION . '.list';
            $column = 'list_name';
            $direction = 'asc';
        }
        $setSort->orderValue = $app->getUserStateFromRequest($key . 'filter_order', 'filter_order', $column, 'cmd');
        $setSort->orderDir = $app->getUserStateFromRequest($key . 'filter_order_Dir', 'filter_order_Dir', $direction, 'word');
        if ($listType == 2) {
            ?>
<script language="javascript" type="text/javascript">
	function submitbutton(pressbutton) {
		var form = document.adminForm;
		if (pressbutton == 'delete') {
			var $ok = confirm('Are you sure you want to delete?\r\nAll of the mailings attached in this auto-responder will be deleted as well.');
			if ( $ok == true ){
				form.action = 'index.php?option=<?php 
            echo JNEWS_OPTION;
            ?>
&act=arlist&task=delete';
			}else{
				return;
			}
		}
		submitform( pressbutton );
	}
</script>
<?php 
        }
        $listing = jNews_Lists::getLists(0, $listType, 1, '', false, false, false, false, false, $listsearch, $setLimit, $setSort);
        if (isset($setLimit->total) && !empty($listsearch)) {
            $lists = jNews_Lists::getLists(0, $listType, 1, '', false, false, false, false, false, $listsearch, $setSort);
            $setLimit->total = !empty($lists) ? count($lists) : $setLimit->total;
        }
        $totalSubs = array();
        $totalUnSubs = array();
        $db = JFactory::getDBO();
        if (!empty($listing)) {
            foreach ($listing as $list) {
                $totalSubs[] = jNews_Subscribers::getSubscribersCount($list->id, true);
                $totalUnSubs[] = jNews_Subscribers::getSubscribersCount($list->id, 2);
            }
        }
        jNews_ListsHTML::showListingLists($listing, $action, 'edit', $forms, $show, $listsearch, $setLimit->end, $setLimit, $totalSubs, $setSort, $totalUnSubs);
        $go[] = jnews::makeObj('act', $action);
        $go[] = jnews::makeObj('filter_order', $setSort->orderValue);
        $go[] = jnews::makeObj('filter_order_Dir', $setSort->orderDir);
        backHTML::formEnd($go);
        return true;
    }
}
예제 #12
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;
}