* @license http://www.contenido.org/license/LIZENZ.txt * @link http://www.4fb.de * @link http://www.contenido.org * @since file available since contenido release <= 4.6 * * {@internal * created 2007-01-01, Bj�rn Behrens (HerrB) * modified 2008-06-27, Dominik Ziegler, add security fix * * $Id: include.newsletter_jobs_details.php 128 2019-07-03 11:58:28Z oldperl $: * }} * */ if (!defined('CON_FRAMEWORK')) { die('Illegal call'); } // 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 $oForm = new UI_Table_Form("properties", $sPathNext); $oForm->addHeader(i18n("Report:", "cl-newsletter")); $oForm->add("", ""); $oForm->add("", sprintf(i18n("Sending newsletter ... (chunk %s of %s, recipients: %s, sent: %s)", "cl-newsletter"), $iChunk, $iChunks, $oJob->get("rcpcount"), $oJob->get("sendcount"))); $oForm->setActionButton("cancel", $cfg['path']['contenido_fullhtml'] . "images/but_cancel.gif", i18n("Stop sending", "cl-newsletter"), "c"); $oForm->setActionButton("submit", $cfg['path']['contenido_fullhtml'] . "images/but_ok.gif", i18n("Send next chunk", "cl-newsletter"), "s", "news_job_run"); } else { // Send automatically $oForm = new UI_Table_Form("properties"); $oForm->addHeader(i18n("Report:", "cl-newsletter")); $oForm->add("", ""); $oForm->add("", sprintf(i18n("Sending newsletter ... (chunk %s of %s, recipients: %s, sent: %s)", "cl-newsletter"), $iChunk, $iChunks, $oJob->get("rcpcount"), $oJob->get("sendcount"))); $oPage->addScript("Refresh", ''); $oForm->unsetActionButton("submit"); $oForm->setActionButton("cancel", $cfg['path']['contenido_fullhtml'] . "images/but_cancel.gif", i18n("Stop sending", "cl-newsletter"), "c"); } } else { // All newsletters should have been sent $oForm = new UI_Table_Form("properties"); $oForm->addHeader(i18n("Report:", "cl-newsletter")); $oForm->add("", ""); $oForm->add("", sprintf(i18n("The newsletter has been sent to %s recipients", "cl-newsletter"), $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) { $iNextPage = 1; } if ($_REQUEST["sortmode"] !== "DESC") { $_REQUEST["sortmode"] = "ASC"; } $sDateFormat = getEffectiveSetting("backend", "timeformat", "d.m.Y H:i"); // Set default values $oUser = new cApiUser($auth->auth["uid"]); if (!isset($_REQUEST["elemperpage"]) || !is_numeric($_REQUEST["elemperpage"]) || $_REQUEST["elemperpage"] < 0) { $_REQUEST["elemperpage"] = $oUser->getProperty("itemsperpage", $area . "_job_details"); } if (!is_numeric($_REQUEST["elemperpage"])) { $_REQUEST["elemperpage"] = 50; } if ($_REQUEST["elemperpage"] > 0) { // - All - will not be saved $oUser->setProperty("itemsperpage", $area . "_job_details", $_REQUEST["elemperpage"]); } $oFrmOptions = new UI_Table_Form("frmOptions"); $oFrmOptions->setVar("contenido", $sess->id); $oFrmOptions->setVar("area", $area); $oFrmOptions->setVar("action", $action); $oFrmOptions->setVar("frame", $frame); $oFrmOptions->setVar("sortmode", $_REQUEST["sortmode"]); $oFrmOptions->setVar("sortby", $_REQUEST["sortby"]); $oFrmOptions->setVar("idnewsjob", $_REQUEST["idnewsjob"]); //$oFrmOptions->setVar("startpage", $startpage); //$oFrmOptions->setVar("appendparameters", $appendparameters); $oFrmOptions->addHeader(i18n("List options", "cl-newsletter")); $oSelElements = new cHTMLSelectElement("elemperpage"); $oSelElements->setEvent("onchange", "document.forms.frmOptions.submit();"); $aData = Array("0" => i18n("-All-", "cl-newsletter"), "50" => "50", "100" => "100", "250" => "250", "500" => "500"); foreach ($aData as $sKey => $sValue) { $oOption = new cHTMLOptionElement($sValue, $sKey); $oSelElements->addOptionElement($sKey, $oOption); } $oSelElements->setDefault($_REQUEST["elemperpage"]); //$oSelElements->setStyle('border:1px;border-style:solid;border-color:black;'); $oFrmOptions->add(i18n("Items per page:", "cl-newsletter"), $oSelElements->render()); // Ouput data $oList = new cScrollList(true, "news_job_details"); $oList->setCustom("idnewsjob", $_REQUEST["idnewsjob"]); $oList->setCustom("nextpage", $iNextPage); $oList->setCustom("elemperpage", $_REQUEST["elemperpage"]); $aCols = array("rcpname", "rcpemail", "", "status", "sent"); $oList->setHeader(i18n("Recipient", "cl-newsletter"), i18n("E-Mail", "cl-newsletter"), i18n("Type", "cl-newsletter"), i18n("Status", "cl-newsletter"), i18n("Sent", "cl-newsletter"), i18n("Actions", "cl-newsletter")); $oList->setSortable(0, true); $oList->setSortable(1, true); $oList->setSortable(2, false); $oList->setSortable(3, true); $oList->setSortable(4, true); // Get data $oLogs->resetQuery(); $oLogs->setWhere("idnewsjob", $_REQUEST["idnewsjob"]); $sBrowseLinks = "1"; if ($_REQUEST["elemperpage"] > 0) { // First, get total data count $oLogs->query(); $iRecipients = $oLogs->count(); // Getting item count without limit (for page function) - better idea anybody (performance)? if ($iRecipients > 0 && $iRecipients > $_REQUEST["elemperpage"]) { $sBrowseLinks = ""; for ($i = 1; $i <= ceil($iRecipients / $_REQUEST["elemperpage"]); $i++) { //$iNext = (($i - 1) * $_REQUEST["elemperpage"]) + 1; if ($sBrowseLinks !== "") { $sBrowseLinks .= " "; } if ($iNextPage == $i) { $sBrowseLinks .= $i . "\n"; // I'm on the current page, no link } else { $sBrowseLinks .= '' . $i . '' . "\n"; } } } $oLogs->setLimit($_REQUEST["elemperpage"] * ($iNextPage - 1), $_REQUEST["elemperpage"]); } if (!array_key_exists($_REQUEST["sortby"], $aCols)) { $_REQUEST["sortby"] = 0; // Sort by rcpname by default } $oLogs->setOrder($aCols[$_REQUEST["sortby"]] . " " . $_REQUEST["sortmode"]); $oLogs->query(); $oImgDelete = new cHTMLImage("images/delete.gif"); $oImgDelete->setAlt(i18n("Delete item", "cl-newsletter")); $sImgDelete = $oImgDelete->render(); unset($oImgDelete); $iCount = 0; $aNewsType[] = array(); // Performance $aNewsType[0] = i18n("Text only", "cl-newsletter"); $aNewsType[1] = i18n("HTML/Text", "cl-newsletter"); while ($oLog = $oLogs->next()) { $sName = $oLog->get("rcpname"); $sEMail = $oLog->get("rcpemail"); switch ($oLog->get("status")) { case "pending": $sStatus = i18n("Waiting for sending", "cl-newsletter"); break; case "sending": $sStatus = i18n("Sending", "cl-newsletter"); break; case "successful": $sStatus = i18n("Successful", "cl-newsletter"); break; default: $sStatus = sprintf(i18n("Error: %s", "cl-newsletter"), $oLog->get("status")); } if ($oLog->get("sent") == "0000-00-00 00:00:00") { $sSent = "-"; } else { $sSent = date($sDateFormat, strtotime($oLog->get("sent"))); } $sLnkRemove = ""; if ($oLog->get("status") == "pending" && $perm->have_perm_area_action($area, "news_job_detail_delete")) { $oLnkRemove = new cHTMLLink; $oLnkRemove->setCLink("news_jobs", 4, "news_job_detail_delete"); $oLnkRemove->setCustom("idnewsjob", $_REQUEST["idnewsjob"]); $oLnkRemove->setCustom("idnewslog", $oLog->get($oLog->primaryKey)); $oLnkRemove->setCustom("sortby", $_REQUEST["sortby"]); $oLnkRemove->setCustom("sortmode", $_REQUEST["sortmode"]); $oLnkRemove->setContent($sImgDelete); $sLnkRemove = $oLnkRemove->render(); } $oList->setData($iCount, $sName, $sEMail, $aNewsType[$oLog->get("rcpnewstype")], $sStatus, $sSent, $sLnkRemove); $iCount++; } // A little bit senseless, as the data is already sorted, but // we need the sortmode in the header link $oList->sort($_REQUEST["sortby"], $_REQUEST["sortmode"]); // HerrB: Hardcore UI for browsing elements ... sorry $sBrowseHTML = '
' . sprintf(i18n("Go to page: %s", "cl-newsletter"), $sBrowseLinks) . ' |