*   modified 2008-06-27, Dominik Ziegler, add security fix
 *
 *   $Id$:
 * }}
 * 
 */
if (!defined('CON_FRAMEWORK')) {
    die('Illegal call');
}
$plugin_name = 'newsletter';
// Initialization
$oPage = new cPage();
if ($action == "news_job_run" && $perm->have_perm_area_action($area, $action) && is_numeric($_REQUEST["idnewsjob"])) {
    // Run job
    $oJob = new cNewsletterJob($_REQUEST["idnewsjob"]);
    $iSendCount = $oJob->runJob();
    if ($oJob->get("dispatch") == 1 && $oJob->get("sendcount") < $oJob->get("rcpcount")) {
        // Send in chunks
        $sPathNext = $sess->url("main.php?area={$area}&action=news_job_run&frame=4&idnewsjob=" . $_REQUEST["idnewsjob"]);
        // Calculating some statistics
        $iChunk = ceil($oJob->get("sendcount") / $oJob->get("dispatch_count"));
        $iChunks = ceil($oJob->get("rcpcount") / $oJob->get("dispatch_count"));
        // Dispatch count > send/recipient count, set values to 1, at least
        if ($iChunk == 0) {
            $iChunk = 1;
        }
        if ($iChunks == 0) {
            $iChunks = 1;
        }
        if ($oJob->get("dispatch_delay") == 0) {
            // Send manually