Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
function mailing($action, $task, $listId, $listType, $mailingId, $message)
{
    $showMailings = false;
    $db = JFactory::getDBO();
    switch ($task) {
        case 'edit':
            $issue_nb = JRequest::getInt('issue_nb', 1);
            $mailingType = JRequest::getVar('listype');
            $isEdit = JRequest::getVar('isEdit', true);
            $mySess = JFactory::getSession();
            $mySess->set('listype', $mailingType, 'LType');
            if (!empty($listId)) {
                $list = jNews_Lists::getOneList($listId);
            } else {
                $list = jNews_Lists::getListFirstEntry();
            }
            $new = empty($mailingId) || $mailingId == 0 ? true : false;
            $mailing = jNews_Mailing::getOneMailing($list, $mailingId, $issue_nb, $new, false, true);
            $mailing->mailing_type = $mailingType;
            //			if(empty($isEdit)) $isEdit = true;
            // set default mailing parameters
            $my = JFactory::getUser();
            $subscribers = jNews_Subscribers::getSubscriberInfoFromUserId($my->id);
            if (!isset($subscribers)) {
                $subscribers = new stdClass();
            }
            $subscribers->name = isset($subscribers->name) ? $subscribers->name : '';
            $subscribers->email = isset($subscribers->email) ? $subscribers->email : '';
            //			$mailing->fromname = ( !isset( $mailing->fromname ) || empty( $mailing->fromname ) ) ? $subscribers->name : $mailing->fromname;
            //			$mailing->fromemail = ( !isset( $mailing->fromemail ) || empty( $mailing->fromemail ) ) ? $subscribers->email : $mailing->fromemail;
            //			$mailing->frombounce = ( !isset( $mailing->frombounce ) || empty( $mailing->frombounce ) ) ? $GLOBALS[JNEWS.'sendmail_from'] : $mailing->frombounce;
            $show = jNews_ListType::showType($mailing->mailing_type, 'editmailing');
            if ($mailing->published != 1 or $mailing->mailing_type != 1 or isset($show['admin']) and $show['admin']) {
                $forms['main'] = " <form action='index.php' method='post' enctype='multipart/form-data' name='adminForm' id=\"adminForm\">";
                jNews_Mailing::_header($task, $action, $mailing->mailing_type, $message, 'edit');
                jNews_MailingsHTML::editMailing($mailing, $new, $listId, $forms, $show, $isEdit);
                $go[] = jnews::makeObj('act', $action);
                backHTML::formEnd($go);
            } else {
                $forms['main'] = " <form action='index.php' method='post' name='adminForm' id=\"adminForm\">";
                jNews_Mailing::_header($task, $action, $mailing->mailing_type, $message);
                //backHTML::formStart();
                jNews_MailingsHTML::viewMailing($mailing, $forms);
                $go[] = jnews::makeObj('act', 'mailing');
                $go[] = jnews::makeObj('task', 'viewmailing');
                $go[] = jnews::makeObj('mailingid', $mailing->id);
                backHTML::formEnd($go);
            }
            break;
        case 'new':
        case 'add':
            // check if atleast one list exist and published
            // if false then restrict entry
            $mailingType = JRequest::getVar('listype');
            $type = $mailingType == 2 ? 2 : 1;
            $result = jNews_Lists::checkListNotEmpty($type);
            if (!$result) {
                if ($type == 2) {
                    $disp = addslashes(_JNEWS_CHECKCAMPAIGNFOUND);
                } else {
                    $disp = addslashes(_JNEWS_CHECKLISTFOUND);
                }
                echo "<script> alert('" . $disp . "'); window.history.go(-1);</script>\n";
                break;
            }
            $mailingType = JRequest::getVar('listype');
            if (empty($listId)) {
                $listId = JRequest::getVar('listid');
            }
            if (!empty($listId)) {
                $mailingType = jNews_Lists::getListType($listId) == 2 ? 2 : 1;
            }
            JRequest::setVar('listype', $mailingType);
            $total = jNews_Mailing::countMailings($listId, $mailingType);
            $total++;
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&task=edit&mailingid=0&issue_nb=' . $total . '&listype=' . $mailingType . '&listid=' . $listId . '&isEdit=0');
            //mariap
            break;
        case 'saveSend':
            JRequest::checkToken() or die('Invalid Token');
            $mySess = JFactory::getSession();
            $mailingType = $mySess->get('listype', '', 'LType');
            $status = checkMailingSave($mailingType);
            if (!$status) {
                return false;
            }
            jNews_Mailing::saveMailing($mailingId, $listId);
        case 'sendready':
            //we update the senddate of the newsletter
            jNews_Mailing::updatesenddate($mailingId);
            jNews_MailingsHTML::sendReady($mailingId, $listId, $listType);
            break;
        case 'generate':
            if (class_exists('jNews_Auto')) {
                $still = false;
                $message = jnews::printYN(jNews_Auto::processQueue(true, true, $still, true), 'Queue processed', _JNEWS_ERROR);
                jNews_Auto::displayStatus();
            }
            return;
            break;
        case 'send':
            $queueC = new jNews_Queue();
            $queueC->checkForNewsletters($mailingId);
            $queueCount = jNews_Queue::getQueueCount($mailingId);
            $totalSub = JRequest::setVar('totalsend', $queueCount);
            $linkURL = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=continuesend&mailingid=' . $mailingId . '&totalsend=' . $totalSub, true, false, true);
            jNews_Tools::redirect($linkURL);
            break;
        case 'continuesend':
            $queueC = new jNews_Queue();
            //we update the senddate of the mailing to be now to be able to continue the sending and send it after we click continue
            //			$queueC->updateSenddateToNow($mailingId);
            $totalSend = JRequest::getVar('totalsend', 0, '', 'int');
            $alreadySent = JRequest::getVar('alreadysent', 0, '', 'int');
            $queueC->start = $alreadySent;
            $queueC->total = $totalSend;
            $queueC->pause = $GLOBALS[JNEWS . 'pause_time'];
            $queueC->sendQueue(false, $mailingId, false, true);
            ob_start();
            exit;
            break;
        case 'testspam':
            if (empty($message)) {
                $message = _JNEWS_MESSAGE_NOT;
            }
            $mailingId = $mailingId == 0 ? jNews_Mailing::getLastMailingId() : $mailingId;
            $my = JFactory::getUser();
            if ($listId > 0) {
                $archivemailing = jNews_Mailing::getMailingView($mailingId, $listId);
            } else {
                $archivemailing = jNews_Mailing::getMailingView($mailingId);
            }
            $mailing = new stdClass();
            $receivers = new stdClass();
            $receivers->email = '*****@*****.**';
            $receivers->name = $archivemailing->fromname;
            $receivers->receive_html = 1;
            $receivers->id = jNews_Subscribers::getSubscriberIdFromUserId($my->id);
            //if email are different we dont replace because we want to make sure the spam cehck count the fact that
            //sender and bounce back are different
            if ($archivemailing->fromemail == $archivemailing->frombounce) {
                $archivemailing->frombounce = $my->email;
            }
            $archivemailing->fromemail = $my->email;
            $mailerC = new jNews_ProcessMail();
            $status = $mailerC->send($archivemailing, $receivers);
            $message = jnews::printYN($status, _JNEWS_SPAMTEXT_MESSAGE_SENT_SUCCESSFULLY, $message);
            $link = 'http://www.joobi.co/index.php?option=com_jlinks&controller=redirect&link=SpamCheck&alt=jnewsdoc_glossary';
            $iFrame = '<iframe src="' . $link . '" width="100%" height="680px" scrolling="auto"></iframe>';
            echo $iFrame;
            break;
        case 'savePreview':
            JRequest::checkToken() or die('Invalid Token');
            $status = checkMailingSave($mailingType);
            if (!$status) {
                return false;
            }
            if ($mailingType == 7) {
                $mailing = JRequest::getVar('mailing', '');
                $ContentStatus = checkTag();
                if (!$ContentStatus) {
                    return false;
                }
            }
            jNews_Mailing::saveMailing($mailingId, $listId);
        case 'preview':
            $emailaddress = JRequest::getVar('emailaddress', '');
            $mailingId = $mailingId == 0 ? jNews_Mailing::getLastMailingId() : $mailingId;
            if (!empty($emailaddress)) {
                $status = jNews_Mailing::sendTestEmail($mailingId, $listId);
                if (empty($message)) {
                    $message = _JNEWS_MESSAGE_NOT;
                }
                $message = jnews::printYN($status, _JNEWS_MESSAGE_SENT_SUCCESSFULLY, $message);
            }
            if ($listId > 0) {
                $archivemailing = jNews_Mailing::getMailingView($mailingId, $listId);
            } else {
                $archivemailing = jNews_Mailing::getMailingView($mailingId);
            }
            $doc = JFactory::getDocument();
            $css = '.icon-48-preview{ background-image:url(' . JNEWS_PATH_ADMIN_IMAGES2 . 'header/preview.png)}';
            $doc->addStyleDeclaration($css, $type = 'text/css');
            $title = _JNEWS_PREVIEW_TITLE . ': ' . $archivemailing->subject;
            backHTML::_header(_JNEWS_PREVIEW_TITLE, 'preview.png', $message, $task, $action);
            //new view for the preview mailing
            echo '<table cellpadding="0" cellspacing="2" border="0" width="100%"><tr><td width="40%">';
            jNews_MailingsHTML::previewMailingHTML($mailingId, $listId, $listType, $archivemailing->html);
            echo '</td><td width="60%">';
            $forms['main'] = '';
            $list = jNews_Lists::getOneList($archivemailing->list_id);
            $textonly = '';
            $mailerC = new jNews_ProcessMail();
            $queueInfo = new stdClass();
            $queueInfo->mailingid = $mailingId;
            $queueInfo->listid = @$listId;
            $mailerC->getContent($archivemailing->images, $archivemailing->html, $archivemailing->textonly, $archivemailing->subject, false, true, $queueInfo);
            //new $archivemailing->subject
            if ($archivemailing->html == 1) {
                if (empty($template_id)) {
                    $template_id = $archivemailing->template_id;
                }
                if (!empty($template_id)) {
                    jNews_Templates::includeStyles($archivemailing->htmlcontent, $template_id);
                }
            } else {
                $archivemailing->textonly = jNews_ProcessMail::htmlToText($archivemailing->textonly);
            }
            //new view for the preview mailing
            jNews_MailingsHTML::viewHeading($archivemailing);
            echo '</td></tr><tr><td colspan="2">';
            jNews_MailingsHTML::viewMailing($archivemailing, $forms);
            echo '</td></tr></tbody></table>';
            if ($mailingId == 0) {
                JRequest::setVar('mailingid', $mailingId);
            }
            break;
        case 'view':
            $mailingType = JRequest::getVar('listype');
            if (!empty($mailingType)) {
                $mySess = JFactory::getSession();
                $mySess->set('listype', $mailingType, 'LType');
            }
            if ($mailingId != 0) {
                if ($listId > 0) {
                    $archivemailing = jNews_Mailing::getMailingView($mailingId, $listId);
                } else {
                    $archivemailing = jNews_Mailing::getMailingView($mailingId);
                }
                if (empty($template_id)) {
                    $template_id = $archivemailing->template_id;
                }
                if (!empty($template_id)) {
                    jNews_Templates::includeStyles($archivemailing->htmlcontent, $template_id);
                }
                $forms['main'] = "<form action='index.php?option=" . JNEWS_OPTION . "&act=mailing&listype=" . $listType . "&listid=" . $listId . "' method='post' name='adminForm' id=\"adminForm\">";
                jNews_Mailing::_header($task, $action, $listType, $message);
                backHTML::formStart('show_mailing', 0, '');
                jNews_MailingsHTML::viewMailing($archivemailing, $forms);
                $go[] = jnews::makeObj('act', 'mailing');
                $go[] = jnews::makeObj('task', 'viewmailing');
                $go[] = jnews::makeObj('listId', $archivemailing->list_id);
                //listid to listId--original
                backHTML::formEnd($go);
            }
            break;
        case 'deletequeue':
            //implement here what are we going to do with the delete queueu column on the mailing
            $mailingID = JRequest::getVar('mailingid');
            $mailingType = JRequest::getVar('listype');
            if (!empty($mailingID)) {
                $db = JFactory::getDBO();
                $db->setQuery('DELETE FROM `#__jnews_queue` WHERE `mailing_id` = ' . $mailingID);
                $db->query();
                $message = jnews::printYN(true, _JNEWS_MAILING_QUEUE_DELETED, _JNEWS_ERROR);
            } else {
                $message = jnews::printYN(false, _JNEWS_MAILING_QUEUE_DELETED, _JNEWS_ERROR);
            }
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType, $message);
            break;
        case 'deleteMailing':
            JRequest::checkToken() or die('Invalid Token');
            $d['mailing'] = jNews_Mailing::getOneMailing('', $mailingId, '', $new);
            $message = jnews::printYN(jNews_Mailing::delete($d), @constant($GLOBALS[JNEWS . 'listname' . $d['mailing']->list_type]) . '"' . $d['mailing']->subject . '"' . _JNEWS_SUCCESS_DELETED, _JNEWS_ERROR);
            $showMailings = true;
            break;
        case 'cancel':
            $url = 'index.php?option=' . JNEWS_OPTION . '&act=mailing&mailingid=' . $mailingId;
            $url .= (!empty($listId) ? '&listid=' . $listId : '') . '&listype=' . $mailingType;
            jNews_Tools::redirect($url);
            break;
        case 'copy':
            JRequest::checkToken() or die('Invalid Token');
            $message = jnews::printYN(jNews_Mailing::copyMailing($mailingId), _JNEWS_MAILING_COPY, _JNEWS_ERROR);
            $showMailings = true;
            break;
        case 'cancelMailing':
            $showMailings = true;
            break;
        case 'publishMailing':
            JRequest::checkToken() or die('Invalid Token');
            $mailing = jNews_Mailing::getOneMailing('', $mailingId, '', $new);
            $message = jnews::printYN(jNews_Mailing::publishMailing($mailingId), @constant($GLOBALS[JNEWS . 'listname' . $mailing->mailing_type]) . ' ' . _JNEWS_PUBLISHED, _JNEWS_ERROR);
            $mailingType = jNews_Mailing::getMailingInfoz($mailingId);
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType);
            break;
        case 'unpublishMailing':
            JRequest::checkToken() or die('Invalid Token');
            $mailing = jNews_Mailing::getOneMailing('', $mailingId, '', $new);
            $message = jnews::printYN(jNews_Mailing::unpublishMailing($mailingId), @constant($GLOBALS[JNEWS . 'listname' . $mailing->mailing_type]) . ' ' . _JNEWS_UNPUBLISHED, _JNEWS_ERROR);
            $mailingType = jNews_Mailing::getMailingInfoz($mailingId);
            jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType . '&listid=' . $listId);
            break;
        case 'cpanel':
            backHTML::controlPanel();
            break;
        case 'save':
            JRequest::checkToken() or die('Invalid Token');
            $subject = JRequest::getVar('subject', '');
            if (empty($subject)) {
                echo "<script> alert('subject needs to be not empty'); window.history.go(-1);</script>\n";
                return false;
            }
            if (!isset($mailingType)) {
                $mySess = JFactory::getSession();
                $mailingType = $mySess->get('listype', '', 'LType');
            }
            $status = checkMailingSave($mailingType);
            if ($mailingType == 7) {
                $mailing = JRequest::getVar('mailing', '');
                $ContentStatus = checkTag();
                if (!$ContentStatus) {
                    return false;
                }
            }
            if (!$status) {
                return false;
            }
            $message = jnews::printYN(jNews_Mailing::saveMailing($mailingId, $listId), _JNEWS_MAILING_SAVED, _JNEWS_ERROR);
            if (!empty($mailingtype)) {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType . '&listid=' . $listId);
            } else {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType . '&listid=' . $listId);
                $showMailings = true;
                unset($GLOBALS["task"]);
                unset($_REQUEST["task"]);
            }
            break;
        case 'apply':
            JRequest::checkToken() or die('Invalid Token');
            $mailingid = JRequest::getVar('mailingid', '0');
            if (!isset($mailingType)) {
                $mySess = JFactory::getSession();
                $mailingType = $mySess->get('listype', '', 'LType');
            }
            $status = checkMailingSave($mailingType);
            if ($mailingType == 7) {
                $mailing = JRequest::getVar('mailing', '');
                $ContentStatus = checkTag();
                if (!$ContentStatus) {
                    return false;
                }
            }
            if (!$status) {
                return false;
            }
            $message = jnews::printYN(jNews_Mailing::saveMailing($mailingId, $listId), _JNEWS_MAILING_SAVED, _JNEWS_ERROR);
            $mailingid = $mailingid == 0 ? jNews_Mailing::getLastMailingId() : $mailingid;
            if (!empty($mailingtype)) {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&task=edit&listype=' . $mailingType . '&mailingid=' . $mailingid . '&listid=' . $listId);
            } else {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&task=edit&listype=' . $mailingType . '&mailingid=' . $mailingid . '&listid=' . $listId);
                $showMailings = true;
                unset($GLOBALS["task"]);
                unset($_REQUEST["task"]);
            }
            break;
        case 'show':
            $id = JRequest::getVar('mailingid');
            $mySess = JFactory::getSession();
            $mailingType = JRequest::getVar('listype', 0);
            $listId = JRequest::getVar('listid', 0);
            $link = 'index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType . '&listid=' . $listId;
            jNews_Tools::redirect($link);
            $showMailings = true;
            break;
        case 'toggle':
            $listid = JRequest::getVar('listid');
            $column = JRequest::getVar('col');
            $mailingid = JRequest::getVar('mailingid');
            if (!empty($mailingid) && !empty($column)) {
                $passObj = new stdClass();
                $passObj->tableName = '#__jnews_mailings';
                $passObj->columnName = $column;
                $passObj->whereColumn = 'id';
                $passObj->whereColumnValue = $mailingid;
                jnews::toggle($passObj);
            }
            if ($listType == 1) {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listid=' . $listid . '&listype=1');
            } else {
                jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listid=' . $listid . '&listype=2');
            }
            break;
        default:
            $showMailings = true;
            break;
    }
    if ($showMailings) {
        if (empty($listType)) {
            $listType = JRequest::getVar('listype', 0);
        }
        if (empty($listId)) {
            $listId = JRequest::getVar('listid', 0);
        }
        $paginationStart = JRequest::getVar('pg');
        if (!empty($paginationStart)) {
            $limitstart = 0;
            $limitend = $paginationStart;
        } else {
            $app = JFactory::getApplication();
            $limitstart = $app->getUserStateFromRequest('limitstart', 'limitstart', 0, 'int');
            $limitend = $app->getUserStateFromRequest('limit', 'limit', 0, 'int');
        }
        $limittotal = jNews_Mailing::countMailings(0, $listType);
        $setLimit = new stdClass();
        $setLimit->total = !empty($limittotal) ? $limittotal : 0;
        $setLimit->start = !empty($limitstart) ? $limitstart : 0;
        $setLimit->end = !empty($limitend) ? $limitend : $limittotal;
        if ($setLimit->total == $setLimit->end) {
            $setLimit->start = 0;
        }
        jNews_Mailing::showMailings($task, $action, $listId, $listType, $message, true, _JNEWS_MENU_MAILING, $setLimit);
    }
    return true;
}
Ejemplo n.º 3
0
 static function sendUnsubcribeEmail($receiver, $subscriberId, $list)
 {
     $mailing = new stdClass();
     $qid[0] = $subscriberId;
     $mainframe = JFactory::getApplication();
     $adminName = $mainframe->getCfg('fromname');
     $adminEmail = $mainframe->getCfg('mailfrom');
     $message = '';
     $email = '';
     $type = '';
     $title = '';
     $author = '';
     $mailing->subject = _JNEWS_UNSUBSCRIBE_SUBJECT_MESS;
     $mailing->htmlcontent = $list->unsubscribemessage;
     $mailing->textonly = $list->unsubscribemessage;
     if (!$GLOBALS[JNEWS . 'minisendmail']) {
         $mailing->fromname = $list->sendername;
     }
     $mailing->fromemail = $list->senderemail;
     $mailing->frombounce = $list->bounceadres;
     $mailing->id = 0;
     $mailing->issue_nb = 0;
     $mailing->images = '';
     $mailing->attachments = '';
     $mailing->html = 1;
     //the unsubscription notification should be in html format
     $mailerC = new jNews_ProcessMail();
     if ($mailerC->send($mailing, $receiver)) {
         return '';
     } else {
         return 'Could not send the unsubscribe email, for list #:' . $list->id . ' , please contact the webmaster!';
     }
 }
Ejemplo n.º 4
0
 public static function sendTestEmail($mailingId, $listId)
 {
     $list = new stdClass();
     $new = null;
     $mailing = jNews_Mailing::getOneMailing($list, $mailingId, '', $new);
     if ($listId > 0) {
         $list = jNews_Lists::getOneList($listId);
     } else {
         $list = jNews_Lists::getOneList($mailing->list_id);
     }
     $previewemailaddress = JRequest::getVar('emailaddress', '');
     $previewname = JRequest::getVar('name', '');
     $previewhtml = JRequest::getVar('html', '0');
     $receivers = new stdClass();
     $my = JFactory::getUser();
     $d['email'] = trim($previewemailaddress);
     $infos = jNews_Subscribers::getSubscriberIdFromEmail($d);
     if (empty($infos['subscriberId'])) {
         $d['email'] = $my->email;
         $infos = jNews_Subscribers::getSubscriberIdFromEmail($d);
     }
     if (!empty($infos['subscriberId'])) {
         $receivers = jNews_Subscribers::getSubscribersFromId(array($infos['subscriberId']));
     } else {
         $receivers->id = 0;
     }
     $receivers->email = $previewemailaddress;
     $receivers->name = $previewname;
     $receivers->receive_html = $previewhtml;
     $mailerC = new jNews_ProcessMail();
     return $mailerC->send($mailing, $receivers);
 }
Ejemplo n.º 5
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);
}
Ejemplo n.º 6
0
    /** Send element stored in the queue
     * @return bool if the queue still have values to be sent then return true ( for manual send ) otherwise return false
     */
    function sendQueue($showHTML = false, $mailingId = null, $onlyAutoRsponder = false, $manualSend = false)
    {
        $showHTML = true;
        $stillProcess = null;
        $maxTask = $manualSend ? $this->limitEmails : $this->maxQueue;
        if ($maxTask < 1) {
            $maxTask = 1;
        }
        if ($maxTask > 1000) {
            $maxTask = 1000;
        }
        //8889990
        $arPRiority = empty($GLOBALS[JNEWS . 'ar_prior']) ? 1 : $GLOBALS[JNEWS . 'ar_prior'];
        //get all the queue
        $query = 'SELECT A.qid,A.subscriber_id,A.attempt, A.params as `qparams`, A.delay as `qdelay`, B.* FROM `#__jnews_queue` as A';
        $query .= ' LEFT JOIN `#__jnews_mailings` as B on A.mailing_id = B.id ';
        $query .= ' WHERE A.send_date <= ' . time() . ' AND B.published > 0 AND A.type != 8 AND A.type != 99';
        if (!empty($mailingId)) {
            $query .= ' AND A.mailing_id = ' . $mailingId;
        }
        if ($onlyAutoRsponder && $GLOBALS[JNEWS . 'level'] > 1) {
            $query .= ' AND A.`priority` = ' . $arPRiority;
        }
        //do not select the suspend
        $query .= ' AND `suspend`= 0';
        //filter for unconfirmed subscribers
        $query .= ' AND `block` = 0';
        //filter the entries are still being processed from the last sending/processing of the queue
        $query .= ' ORDER BY A.`priority` ASC, A.send_date ASC';
        $query .= ' LIMIT ' . $maxTask;
        $this->db->setQuery($query);
        $allQueuedA = $this->db->loadObjectList();
        $error = $this->db->getErrorMsg();
        if (!empty($error)) {
            //prompt message if an error occured while retrieving entries from the queue
            echo '<br><br><span style="font-weight:bold; font-style:italic; color:blue;">' . _JNEWS_QUEUE_PROCESS_ERROR . '<span><br><br>';
            echo $error;
        }
        if (empty($allQueuedA)) {
            echo '<br><br><span style="font-weight:bold; font-style:italic; color:blue;">' . _JNEWS_NO_MAILINGS_YET . '<span>';
            // prompt message if there is nothing to send
            jNews_Queue::sendReport();
            return false;
        }
        //we update the retrieved allQueuedA to blocked so that  the entries will not be processed double
        foreach ($allQueuedA as $oneQueue) {
            $this->updateQueueBlock($oneQueue->qid, 1);
        }
        $totalSubscribers = count($allQueuedA);
        //make an array of all subscribers and all mailings
        $mySubcribersA = array();
        $subscribersPerMailingsA = array();
        foreach ($allQueuedA as $oneQueue) {
            $mySubcribersA[$oneQueue->subscriber_id] = true;
        }
        //get all the subcribers
        $query = 'SELECT A.`id`,A.`user_id`,A.`name`,A.`email`,A.`receive_html`,A.`confirmed`,A.`blacklist`, B.`id` AS \'user\' ';
        if ($GLOBALS[JNEWS . 'level'] > 2) {
            //check if the version of jnews is pro
            if ($GLOBALS[JNEWS . 'show_column1']) {
                $query .= ',A.`column1`';
            }
            if ($GLOBALS[JNEWS . 'show_column2']) {
                $query .= ',A.`column2`';
            }
            if ($GLOBALS[JNEWS . 'show_column3']) {
                $query .= ',A.`column3`';
            }
            if ($GLOBALS[JNEWS . 'show_column4']) {
                $query .= ',A.`column4`';
            }
            if ($GLOBALS[JNEWS . 'show_column5']) {
                $query .= ',A.`column5`';
            }
        }
        $query .= ' FROM `#__jnews_subscribers` AS A  ';
        $query .= ' LEFT JOIN  `#__users` AS B ON A.id=B.id';
        $query .= ' WHERE A.`id` IN (' . jnews::implode(',', array_keys($mySubcribersA)) . ' )';
        $this->db->setQuery($query);
        $allSubcribersA = $this->db->loadObjectList('id');
        if (empty($allSubcribersA)) {
            jNews_Queue::sendReport();
            return false;
        }
        $mailerC = new jNews_ProcessMail();
        $queueToBeDelted = array();
        $queueToBeAttempted = array();
        $queueSuccessfullySent = array();
        $addToStatisticsA = array();
        $log_detailed = '';
        $message = '';
        $screenMsg = '';
        $maxAttempt = $GLOBALS[JNEWS . 'max_attempts'] < 1 ? 1 : $GLOBALS[JNEWS . 'max_attempts'];
        if ($this->total == 0) {
            $this->total = jNews_Queue::getQueueCount($mailingId);
        }
        //for manual sending processing
        if ($manualSend) {
            if (!headers_sent() and ob_get_level() > 0) {
                @ob_end_flush();
            }
            $url = JURI::base() . jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=continuesend&mailingid=' . $mailingId . '&totalsend=' . $this->total . '&alreadysent=', true, false, true);
            $screenMsg = "<div style='position:fixed; top:3px;left:3px;color:orange; padding : 3px;'>";
            $screenMsg .= "<span id='waitinginfo' style='padding:10px;margin:5px;font-size:16px;font-weight:bold;display:none;background-color:#FFF8C6; color:red;'> </span>";
            $screenMsg .= '<i>' . _JNEWS_SENDING_EMAIL . ' <span id="emailcounter"/><strong>' . $this->start . '</strong></span> out of <strong>' . $this->total . '</strong>... </i>';
            $screenMsg .= "</div><div id='details' style='display:none; position:fixed; bottom:3px;left:3px;background-color : white; border : 1px solid grey; padding : 3px;'> </div><br /><br />";
            $screenMsg .= '<script type="text/javascript" language="javascript">';
            $screenMsg .= 'var myEmailCounter = document.getElementById("emailcounter");';
            $screenMsg .= 'var details = document.getElementById("details");
var waitinginfo = document.getElementById("waitinginfo");
function setDetails(message){ details.style.display = \'block\';details.innerHTML=message; }
function setWaitingInfo(waitingtime){ waitinginfo.style.display = \'\';waitinginfo.innerHTML="Waiting "+waitingtime+" seconds..."; }
function setEmailCounter(val){ myEmailCounter.innerHTML=val;}
var waitingtime = ' . intval($this->pause) . ';
function setWaitingTime(){
	setWaitingInfo(waitingtime);
	if(waitingtime > 0){
		waitingtime = waitingtime - 1;
		setTimeout(\'setWaitingTime()\',1000);
	}else{
		document.location.href=\'' . $url . '\'+myEmailCounter.innerHTML;
	}
}
</script>';
            echo $screenMsg;
            if (function_exists('ob_flush')) {
                @ob_flush();
            } else {
                @flush();
            }
        }
        //we assign counter for the current email being processed
        $counterEmail = $this->start;
        //we determine if the mailings on the queue is lesser than the limit given per batch of manual sending
        if (count($allQueuedA) < $maxTask) {
            $stillProcess = false;
        }
        //get the size of the queue
        foreach ($allQueuedA as $oneQueue) {
            $counterEmail++;
            if ($manualSend) {
                echo '<script type="text/javascript" language="javascript">setEmailCounter(' . $counterEmail . ')</script>';
                if (function_exists('ob_flush')) {
                    @ob_flush();
                }
                @flush();
            }
            //attachements
            if (!empty($oneQueue->attachments)) {
                $oneQueue->attachments = explode("\n", $oneQueue->attachments);
                if (count($oneQueue->attachments) != 0 && trim($oneQueue->attachments[count($oneQueue->attachments) - 1]) == "") {
                    array_pop($oneQueue->attachments);
                }
            } else {
                $oneQueue->attachments = array();
            }
            //images
            if (!empty($oneQueue->images)) {
                $oneQueue->images = explode("\n", $oneQueue->images);
            } else {
                $oneQueue->images = array();
            }
            //5 is maximun attempt
            if ($oneQueue->attempt >= $maxAttempt) {
                $queueToBeDelted[] = $oneQueue->qid;
                continue;
            }
            if (!isset($this->sentHTML[$oneQueue->id])) {
                $this->sentHTML[$oneQueue->id] = 0;
            }
            if (!isset($this->sentText[$oneQueue->id])) {
                $this->sentText[$oneQueue->id] = 0;
            }
            if (!isset($this->sentFailed[$oneQueue->id])) {
                $this->sentFailed[$oneQueue->id] = 0;
            }
            if (isset($allSubcribersA[$oneQueue->subscriber_id]) && is_object($allSubcribersA[$oneQueue->subscriber_id])) {
                $emailSentStatus = $mailerC->send($oneQueue, $allSubcribersA[$oneQueue->subscriber_id]);
                if ($emailSentStatus) {
                    //we update the senddate of the newsletter
                    jNews_Mailing::updatesenddate($oneQueue->id);
                }
            } else {
                continue;
            }
            if (!empty($allSubcribersA[$oneQueue->subscriber_id]->email)) {
                if ($GLOBALS[JNEWS . 'save_log']) {
                    if (!$emailSentStatus) {
                        $log_detailed .= '[' . $oneQueue->id . '] ' . $oneQueue->subject . ' : ' . $allSubcribersA[$oneQueue->subscriber_id]->email . ' -> ' . _JNEWS_MESSAGE_NOT . "\r\n" . _JNEWS_MAILER_ERROR . ': ' . $mailerC->ErrorInfo . "\r\n";
                    } else {
                        $log_detailed .= '[' . $oneQueue->id . '] ' . $oneQueue->subject . ' : ' . $allSubcribersA[$oneQueue->subscriber_id]->email . ' -> ' . _JNEWS_MESSAGE_SENT_SUCCESSFULLY . "\r\n";
                    }
                } else {
                    $log_detailed .= '[' . $oneQueue->id . '] ' . $oneQueue->subject . ' : ' . $allSubcribersA[$oneQueue->subscriber_id]->email . ' -> ' . _JNEWS_MESSAGE_SENT_SUCCESSFULLY . "\r\n";
                }
            }
            //Screen message for manual sending
            if ($manualSend) {
                if ($emailSentStatus) {
                    $message = '<strong><i>' . $oneQueue->subject . '</i></strong> ' . _JNEWS_MSG_SENT_SUCCESS . ' <strong><i>' . $allSubcribersA[$oneQueue->subscriber_id]->name . ' ( ' . $allSubcribersA[$oneQueue->subscriber_id]->email . ' )</i></strong>' . "\r\n";
                } else {
                    $message = '<i>' . _JNEWS_ATTEMPTED . ' ' . $oneQueue->subject . ' to ' . $allSubcribersA[$oneQueue->subscriber_id]->name . ' ( ' . $allSubcribersA[$oneQueue->subscriber_id]->email . ' )' . ".\r\n" . _JNEWS_RESCHEDULED . "\r\n\r\n" . _JNEWS_REACHED_MAX_ATTEMPT . "</i>\r\n\r\n";
                }
                $this->_displayDetails($message, $emailSentStatus, $counterEmail);
            }
            if ($emailSentStatus) {
                //succeess send
                $query = 'DELETE FROM `#__jnews_queue` WHERE `qid`=' . $oneQueue->qid;
                $this->db->setQuery($query);
                $this->db->query();
                if ($mailerC->html) {
                    $this->sentHTML[$oneQueue->id]++;
                } else {
                    $this->sentText[$oneQueue->id]++;
                }
                //user statistics
                if ($GLOBALS[JNEWS . 'enable_statistics'] && $GLOBALS[JNEWS . 'statistics_per_subscriber']) {
                    $addToStatisticsA[$oneQueue->id][$oneQueue->subscriber_id] = (int) $mailerC->html;
                }
                $this->sentSuccess++;
                $this->recurringError = 0;
                $queueSuccessfullySent[] = $oneQueue->qid;
                //we save the successfully sent qids so that we can differentiate from the allqueue what qids that were not processed because the max execution time has been reached
            } else {
                // failed send
                $queueToBeAttempted[] = $oneQueue->qid;
                $this->sentFailed[$oneQueue->id]++;
                $this->recurringError++;
            }
            $time = time();
            if ($this->maxExetime != 0 && $this->maxExetime <= $time) {
                $stillProcess = true;
                break;
            }
            if ($this->recurringError > 2 && $this->sentSuccess > 3) {
                $stillProcess = false;
                break;
            }
            if ($this->recurringError > 5 || connection_aborted()) {
                $stillProcess = false;
                break;
            }
        }
        //we close the processing of emails
        $mail = JFactory::getMailer();
        $mailerC->close($mail);
        if (!empty($this->total) && $counterEmail >= $this->total) {
            $stillProcess = false;
        }
        //update queue with try + 1;
        if (!empty($queueToBeAttempted)) {
            $query = 'UPDATE `#__jnews_queue` SET `attempt`=`attempt`+1,`send_date`=`send_date`+`attempt`*25299+4000, `block`= 0 WHERE `qid` IN (' . jnews::implode(',', $queueToBeAttempted) . ')';
            //we will also update the block to 0 so that it will be processed again
            $this->db->setQuery($query);
            $this->db->query();
        }
        //delete the queue when the emails are sent successfully after x number of attempts
        if (!empty($queueToBeDelted)) {
            $query = 'DELETE FROM `#__jnews_queue` WHERE `qid` IN (' . jnews::implode(',', $queueToBeDelted) . ')';
            $this->db->setQuery($query);
            $this->db->query();
        }
        //unblock again the queue that were not sent because the timeout has been reached so that they will be processed again
        if (!empty($allQueuedA)) {
            foreach ($allQueuedA as $oneQueue) {
                if (!in_array($oneQueue->qid, $queueSuccessfullySent)) {
                    $query = 'UPDATE `#__jnews_queue` SET `block` = 0 WHERE `qid` =' . $oneQueue->qid;
                    $this->db->setQuery($query);
                    $this->db->query();
                }
            }
        }
        //we update and increment the statistics
        if ($GLOBALS[JNEWS . 'enable_statistics']) {
            $this->_updateStatsGlobal($allQueuedA);
        }
        if (!empty($addToStatisticsA)) {
            $this->_insertStats($addToStatisticsA);
        }
        //we prompt message that the mailing has been sent successfully for each batch
        //		echo '<br><br><span style="font-weight:bold; font-style:italic; color:green;">'.$oneQueue->subject.' successfully sent to subscribers.'.'</span> ';
        //mailing reports
        $this->_writeLogs($log_detailed);
        if (isset($stillProcess)) {
            //manual sending
            if ($stillProcess && $manualSend) {
                echo '<script type="text/javascript" language="javascript">setWaitingTime();</script>';
            } else {
                echo '<br><br><span style="font-weight:bold; font-style:italic; color:green;">' . _JNEWS_THE_MAILING . $oneQueue->subject . _JNEWS_SENT_ALL . '</span> ';
                //					$subject = 'jNews Mailing Notification - Status: End';
                //					$content = 'The mailing '.$oneQueue->subject.' has been successfully sent.';
                //					if( version_compare(JVERSION,'1.6.0','<') ){ //j15
                //						$this->db->setQuery( "SELECT * FROM `#__users` WHERE `gid` = 25 ORDER BY `id` ASC LIMIT 1" );
                //					}else{
                //						$this->db->setQuery( "SELECT * FROM `#__users` AS U LEFT JOIN `#__user_usergroup_map` AS UGM ON U.id =UGM.user_id  WHERE `group_id` = 8 ORDER BY `id` ASC LIMIT 1" );
                //					}
                //					$admin = $this->db->loadObject();
                //
                //					JUTility::sendMail($admin->email, $admin->name, $admin->email, $subject, $content );
            }
            if (!$stillProcess) {
                jNews_Queue::sendReport();
            }
            return $stillProcess ? true : false;
        } else {
            //manual sending
            if ($manualSend && $maxTask < $this->total) {
                echo '<script type="text/javascript" language="javascript">setWaitingTime();</script>';
            } else {
                echo '<br><br><span style="font-weight:bold; font-style:italic; color:green;">' . _JNEWS_THE_MAILING . $oneQueue->subject . _JNEWS_SENT_ALL . '</span> ';
                //					$subject = 'jNews Mailing Notification - Status: End';
                //					$content = 'The mailing '.$oneQueue->subject.' has been successfully sent.';
                //					if( version_compare(JVERSION,'1.6.0','<') ){ //j15
                //						$this->db->setQuery( "SELECT * FROM `#__users` WHERE `gid` = 25 ORDER BY `id` ASC LIMIT 1" );
                //					}else{
                //						$this->db->setQuery( "SELECT * FROM `#__users` AS U LEFT JOIN `#__user_usergroup_map` AS UGM ON U.id =UGM.user_id  WHERE `group_id` = 8 ORDER BY `id` ASC LIMIT 1" );
                //					}
                //					$admin = $this->db->loadObject();
                //
                //					JUTility::sendMail($admin->email, $admin->name, $admin->email, $subject, $content );
            }
            if ($this->maxQueue > count($allQueuedA)) {
                jNews_Queue::sendReport();
            }
            return $this->maxQueue > count($allQueuedA) ? false : true;
        }
    }