1
0
Fork 0
cl-newsletter/includes/include.newsletter_jobs_details.php
2019-10-26 14:35:06 +02:00

379 Zeilen
Kein EOL
16 KiB
PHP

<?php
/**
* Project:
* Contenido Content Management System
*
* Description:
* Shows job details
*
* Requirements:
* @con_php_req 5.0
*
*
* @package Contenido Backend includes
* @version 1.0.0
* @author Bj<42>rn Behrens (HerrB)
* @copyright four for business AG <www.4fb.de>
* @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<42>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", '<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", "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 .= "&nbsp;";
}
if ($iNextPage == $i) {
$sBrowseLinks .= $i . "\n"; // I'm on the current page, no link
} else {
$sBrowseLinks .= '<a href="' . $sess->url("main.php?area=$area&action=$action&frame=$frame&idnewsjob=" .
$_REQUEST["idnewsjob"] . "&nextpage=$i&sortmode=" .
$_REQUEST["sortmode"] . "&sortby=" . $_REQUEST["sortby"]) . '">' . $i . '</a>' . "\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 = '<table width="100%" cellspacing="0" cellpadding="2" border="0">
<tr>
<td><img src="images/spacer.gif" width="1" height="10"></td>
</tr>
<tr class="text_medium" style="background-color: #ffffff;">
<td style="border: 1px; border-color: #B3B3B3; border-style: solid; background-color: #E2E2E2; color:#666666"> ' .
sprintf(i18n("Go to page: %s", "cl_newsletter"), $sBrowseLinks) . '</td>
</tr>
</table>';
$oPage->setContent($oFrmOptions->render() . "<br />" . $oList->render() . $sBrowseHTML);
} else {
// Just show the job data
$oJob = new cNewsletterJob($_REQUEST["idnewsjob"]);
$oForm = new UI_Table_Form("properties");
$oForm->setVar("frame", $frame);
$oForm->setVar("area", $area);
$oForm->setVar("action", "");
$oForm->setVar("idnewsjob", $idnewsjob);
$oForm->addHeader(i18n("Newsletter Dispatch Job", "cl_newsletter"));
$oForm->add(i18n("Name", "cl_newsletter"), $oJob->get("name"));
$sDateFormat = getEffectiveSetting("backend", "timeformat", "d.m.Y H:i");
switch ($oJob->get("status")) {
case 1:
$oForm->add(i18n("Status", "cl_newsletter"), i18n("Pending", "cl_newsletter"));
break;
case 2:
$oForm->add(i18n("Status", "cl_newsletter"), sprintf(i18n("Sending (started: %s)", "cl_newsletter"), date($sDateFormat, strtotime($oJob->get("started")))));
break;
case 9:
$oForm->add(i18n("Status", "cl_newsletter"), sprintf(i18n("Finished (started: %s, finished: %s)", "cl_newsletter"), date($sDateFormat, strtotime($oJob->get("started"))), date($sDateFormat, strtotime($oJob->get("finished")))));
break;
}
$oForm->add(i18n("Statistics", "cl_newsletter"), sprintf(i18n("Planned: %s, Send: %s", "cl_newsletter"), $oJob->get("rcpcount"), $oJob->get("sendcount")));
$oForm->add(i18n("From", "cl_newsletter"), $oJob->get("newsfrom") . " (" . $oJob->get("newsfromname") . ")");
$oForm->add(i18n("Subject", "cl_newsletter"), $oJob->get("subject"));
if ($oJob->get("type") == "html") {
$oForm->add(i18n("Type", "cl_newsletter"), i18n("HTML and text", "cl_newsletter"));
$txtMessageHTML = new cHTMLTextarea("txtMessageHTML", $oJob->get("message_html"), 80, 20);
$txtMessageHTML->setDisabled("disabled");
$oForm->add(i18n("HTML Message", "cl_newsletter"), $txtMessageHTML->render());
} else {
$oForm->add(i18n("Type", "cl_newsletter"), i18n("Text only", "cl_newsletter"));
}
$txtMessageText = new cHTMLTextarea("txtMessageText", $oJob->get("message_text"), 80, 20);
$txtMessageText->setDisabled("disabled");
$oForm->add(i18n("Text Message", "cl_newsletter"), $txtMessageText->render());
$aSendTo = unserialize($oJob->get("send_to"));
switch ($aSendTo[0]) {
case "all":
$sSendToInfo = i18n("Send newsletter to all recipients", "cl_newsletter");
break;
case "default":
$sSendToInfo = i18n("Send newsletter to the members of the default group", "cl_newsletter");
break;
case "selection":
$sSendToInfo = i18n("Send newsletter to the members of the selected group(s):", "cl_newsletter");
unset($aSendTo[0]);
foreach ($aSendTo as $sGroup) {
$sSendToInfo .= "<br />" . $sGroup;
}
break;
case "single":
$sSendToInfo = i18n("Send newsletter to single recipient:", "cl_newsletter");
$sSendToInfo .= "<br />" . $aSendTo[1] . " (" . $aSendTo[2] . ")";
break;
default:
}
unset($aSendTo);
$oForm->add(i18n("Recipients", "cl_newsletter"), $sSendToInfo);
if ($oJob->get("use_cronjob") == 1) {
$sOptionsInfo = i18n("Use cronjob: Enabled", "cl_newsletter");
} else {
$sOptionsInfo = i18n("Use cronjob: Not enabled", "cl_newsletter");
}
if ($oJob->get("dispatch")) {
$sOptionsInfo .= "<br />" . sprintf(i18n("Dispatch: Enabled (block size: %s, delay: %s sec.)", "cl_newsletter"), $oJob->get("dispatch_count"), $oJob->get("dispatch_delay"));
} else {
$sOptionsInfo .= "<br />" . i18n("Dispatch: Disabled", "cl_newsletter");
}
$oForm->add(i18n("Options", "cl_newsletter"), $sOptionsInfo);
$oForm->add(i18n("Author", "cl_newsletter"), $oJob->get("authorname"));
$oForm->add(i18n("Created", "cl_newsletter"), $oJob->get("created"));
// Just remove the "save changes" message (as it is not possible to remove the image completely in ui_table_form)
$oForm->setActionButton("submit", $cfg['path']['contenido_fullhtml'] . "images/but_ok.gif", "", "s");
$oPage->setContent($oForm->render(true));
}
$oPage->render();
?>