* @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_menu.php 128 2019-07-03 11:58:28Z oldperl $:
* }}
*
*/
if(!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
##################################
# 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", "cl_newsletter"), "type" => "base,sort,search");
$aFields["created"] = array("field" => "created", "caption" => i18n("Created", "cl_newsletter"), "type" => "base,sort");
$aFields["status"] = array("field" => "status", "caption" => i18n("Status", "cl_newsletter"), "type" => "base,sort");
// Not needed, as no sort/search, but keep as memo: $aFields["cronjob"] = array("field" => "use_cronjob", "caption" => i18n("Use cronjob"), "type" => "base");
##################################
# Check external input
##################################
// Items per page (value stored per area in user property)
if (!isset($_REQUEST["elemperpage"]) || !is_numeric($_REQUEST["elemperpage"]) || $_REQUEST["elemperpage"] < 0) {
$_REQUEST["elemperpage"] = $oUser->getProperty("itemsperpage", $area);
}
if (!is_numeric($_REQUEST["elemperpage"])) {
// This is the case, if the user property has never been set (first time user)
$_REQUEST["elemperpage"] = 25;
}
if ($_REQUEST["elemperpage"] > 0) {
// -- All -- will not be stored, as it may be impossible to change this back to something more useful
$oUser->setProperty("itemsperpage", $area, $_REQUEST["elemperpage"]);
}
unset ($oUser);
$_REQUEST["page"] = (int)$_REQUEST["page"];
if ($_REQUEST["page"] <= 0 || $_REQUEST["elemperpage"] == 0) {
$_REQUEST["page"] = 1;
}
// Sort order
if ($_REQUEST["sortorder"] != "ASC") {
$_REQUEST["sortorder"] = "DESC"; // Note, default is DESC (as default sortby is "created" date)
}
// Check sort by and search in criteria
$bSortByFound = false;
$bSearchInFound = false;
foreach ($aFields as $sKey => $aData)
{
if ($aData["field"] == $_REQUEST["sortby"] && strpos($aData["type"], "sort") !== false) {
$bSortByFound = true;
}
if ($aData["field"] == $_REQUEST["searchin"] && strpos($aData["type"], "search") !== false) {
$bSearchInFound = true;
}
}
if (!$bSortByFound) {
$_REQUEST["sortby"] = "created"; // Default sort by field, possible values see above
}
if (!$bSearchInFound) {
$_REQUEST["searchin"] = "--all--";
}
// Author
if ($_REQUEST["selAuthor"] == "") {
$_REQUEST["selAuthor"] = $auth->auth["uid"];
}
// Free memory
unset($oUser);
##################################
# Get data
##################################
$oJobs->setWhere("idclient", $client);
$oJobs->setWhere("idlang", $lang);
$oJobs->setWhere("author", $_REQUEST["selAuthor"]);
if ($_REQUEST["filter"] != "")
{
if ($_REQUEST["searchin"] == "--all--" || $_REQUEST["searchin"] == "")
{
foreach ($aFields as $sKey => $aData)
{
if (strpos($aData["type"], "search") !== false) {
$oJobs->setWhereGroup("filter", $aData["field"], $_REQUEST["filter"], "LIKE");
}
}
$oJobs->setInnerGroupCondition("filter", "OR");
} else {
$oJobs->setWhere($_REQUEST["searchin"], $_REQUEST["filter"], "LIKE");
}
}
if ($_REQUEST["elemperpage"] > 0)
{
$oJobs->query();
// Getting item count without limit (for page function) - better idea anyone (performance)?
$iItemCount = $oJobs->count();
if ($_REQUEST["elemperpage"]*($_REQUEST["page"]) >= $iItemCount+$_REQUEST["elemperpage"] && $_REQUEST["page"] != 1) {
$_REQUEST["page"]--;
}
$oJobs->setLimit($_REQUEST["elemperpage"] * ($_REQUEST["page"] - 1), $_REQUEST["elemperpage"]);
} else {
$iItemCount = 0;
}
$oJobs->setOrder($_REQUEST["sortby"] . " " . $_REQUEST["sortorder"]);
$oJobs->query();
// Output data
$oMenu = new UI_Menu;
$iMenu = 0;
$sDateFormat = getEffectiveSetting("backend", "timeformat", "d.m.Y H:i");
// Store messages for repeated use (speeds performance, as i18n translation is only needed once)
$aMsg = array();
$aMsg["DelTitle"] = i18n("Delete dispatch job", "cl_newsletter");
$aMsg["DelDescr"] = i18n("Do you really want to delete the following newsletter dispatch job:
", "cl_newsletter");
$aMsg["SendTitle"] = i18n("Run job", "cl_newsletter");
$aMsg["SendDescr"] = i18n("Do you really want to run the following job:
", "cl_newsletter");
// Prepare "send link" template
$sTplSend = '';
while ($oJob = $oJobs->next())
{
$iMenu++;
$iID = $oJob->get("idnewsjob");
$sName = $oJob->get("name") . " (" . date($sDateFormat, strtotime($oJob->get("created"))) .")";
$oLnk = new cHTMLLink;
$oLnk->setMultiLink($area, "", $area, "");
$oLnk->setCustom("idnewsjob", $iID);
// Is at present redundant
// HerrB: No, it's just not used/set...
//$oMenu->setImage($iMenu, "images/newsletter_16.gif");
$oMenu->setTitle($iMenu, $sName);
switch ($oJob->get("status"))
{
case 1:
// Pending
if ($oJob->get("cronjob") == 0)
{
// Standard job can be run if user has the right to do so
if ($perm->have_perm_area_action($area, "news_job_run"))
{
$sLnkSend = str_replace('{ID}', $iID, $sTplSend);
$sLnkSend = str_replace('{NAME}', addslashes($sName), $sLnkSend);
$oMenu->setActions($iMenu, 'send', $sLnkSend);
}
} else if ($oJob->get("cronjob") == 1) {
// It's a cronjob job - no manual sending, show it blue
$oLnk->updateAttributes(array("style" => "color:#0000FF"));
}
if ($perm->have_perm_area_action($area, "news_job_delete")) {
// Job may be deleted, if user has the right to do so
$oMenu->setActions($iMenu, 'delete', '');
}
break;
case 2:
// Sending job
if ($perm->have_perm_area_action($area, "news_job_run"))
{
// User may try to start sending, again - if he has the right to do so
$sLnkSend = str_replace('{ID}', $iID, $sTplSend);
$sLnkSend = str_replace('{NAME}', addslashes($sName), $sLnkSend);
$oMenu->setActions($iMenu, 'send', $sLnkSend);
}
$oLnk->updateAttributes(array("style" => "color:#da8a00"));
$sDelete = '';
break;
case 9:
// Job finished, don't do anything
$oLnk->updateAttributes(array("style" => "color:#808080"));
if ($perm->have_perm_area_action($area, "news_job_delete")) {
// You have the right, but you can't delete the job after sending
$oMenu->setActions($iMenu, 'delete', '');
}
break;
}
$oMenu->setLink($iMenu, $oLnk);
}
$sExecScript = '
';
$oPage->setMargin(0);
// Messagebox JS has to be included before ExecScript!
$oPage->addScript('messagebox', '');
$oPage->addScript('exec', $sExecScript);
$oPage->addScript('parameterCollector.js', '');
//generate current content for Object Pager
$sPagerId = '0ed6d632-6adf-4f09-a0c6-1e38ab60e303';
$oPagerLink = new cHTMLLink;
$oPagerLink->setLink("main.php");
$oPagerLink->setTargetFrame('left_bottom');
$oPagerLink->setCustom("selAuthor", $_REQUEST["selAuthor"]);
$oPagerLink->setCustom("elemperpage", $_REQUEST["elemperpage"]);
$oPagerLink->setCustom("filter", $_REQUEST["filter"]);
$oPagerLink->setCustom("restrictgroup", $_REQUEST["restrictgroup"]);
$oPagerLink->setCustom("sortby", $_REQUEST["sortby"]);
$oPagerLink->setCustom("sortorder", $_REQUEST["sortorder"]);
$oPagerLink->setCustom("searchin", $_REQUEST["searchin"]);
$oPagerLink->setCustom("frame", $frame);
$oPagerLink->setCustom("area", $area);
$oPagerLink->enableAutomaticParameterAppend();
$oPagerLink->setCustom("contenido", $sess->id);
// Note, that after the "page" parameter no "pagerlink" parameter is specified -
// it is not used, as the JS below only uses the INNER html and the "pagerlink" parameter is
// set by ...left_top.html for the foldingrow itself
$oPager = new cObjectPager($sPagerId, $iItemCount, $_REQUEST["elemperpage"], $_REQUEST["page"], $oPagerLink, "page");
// Add slashes, to insert in javascript
$sPagerContent = $oPager->render(1);
$sPagerContent = str_replace('\\', '\\\\', $sPagerContent);
$sPagerContent = str_replace('\'', '\\\'', $sPagerContent);
// Send new object pager to left_top
$oPage->addScript('setpager', '');
$sRefreshPager = '
';
$oPage->addScript('refreshpager', $sRefreshPager);
//$oPage->setContent(array('