*   modified 2008-06-27, Dominik Ziegler, add security fix
 *
 *   $Id$:
 * }}
 * 
 */
if (!defined('CON_FRAMEWORK')) {
    die('Illegal call');
}
$plugin_name = 'newsletter';
##################################
# Initialization
##################################
$oPage = new cPage();
$oMenu = new UI_Menu();
$oJobs = new cNewsletterJobCollection();
$oUser = new cApiUser($auth->auth["uid"]);
// Specify fields for search, sort and validation. Design makes enhancements
// using plugins possible (currently not implemented). If you are changing things here,
// remember to update include.newsletter_left_top.php, also.
// field:	Field name in the db
// caption:	Shown field name (-> user)
// base:	Elements from core code (other type may be: "plugin")
// sort: 	Element can be used to be sorted by
// search:	Element can be used to search in
$aFields = array();
$aFields["name"] = array("field" => "name", "caption" => i18n("Name", $plugin_name), "type" => "base,sort,search");
$aFields["created"] = array("field" => "created", "caption" => i18n("Created", $plugin_name), "type" => "base,sort");
$aFields["status"] = array("field" => "status", "caption" => i18n("Status", $plugin_name), "type" => "base,sort");
// Not needed, as no sort/search, but keep as memo: $aFields["cronjob"]	= array("field" => "use_cronjob", "caption" => i18n("Use cronjob", $plugin_name), "type" => "base");
##################################
            $oPage->addScript("Refresh", '<meta http-equiv="refresh" content="' . $oJob->get("dispatch_delay") . '; URL=' . $sPathNext . '">');
            $oForm->unsetActionButton("submit");
            $oForm->setActionButton("cancel", $cfg['path']['contenido_fullhtml'] . "images/but_cancel.gif", i18n("Stop sending", $plugin_name), "c");
        }
    } else {
        // All newsletters should have been sent
        $oForm = new UI_Table_Form("properties");
        $oForm->addHeader(i18n("Report:", $plugin_name));
        $oForm->add("", "");
        $oForm->add("", sprintf(i18n("The newsletter has been sent to %s recipients", $plugin_name), $oJob->get("sendcount")));
        $oPage->setReload();
    }
    $oPage->setContent($notis . $oForm->render(true));
} else {
    if ($action == "news_job_delete" && $perm->have_perm_area_action($area, $action) && is_numeric($_REQUEST["idnewsjob"])) {
        $oJobs = new cNewsletterJobCollection();
        $oJobs->delete($_REQUEST["idnewsjob"]);
        $oPage->setSubnav("blank", "news_jobs");
        $oPage->setReload();
        $oPage->setContent($notis);
    } else {
        if ($action == "news_job_details" || $action == "news_job_detail_delete") {
            // Show job details (recipients)
            $oLogs = new cNewsletterLogCollection();
            // Remove recipient from a job
            if ($action == "news_job_detail_delete" && is_numeric($_REQUEST["idnewslog"]) && $perm->have_perm_area_action($area, "news_job_detail_delete")) {
                $oLogs->delete($_REQUEST["idnewslog"]);
            }
            // Initialize
            $iNextPage = Contenido_Security::toInteger($_GET['nextpage']);
            if ($iNextPage <= 0) {