function select($where = "", $group_by = "", $order_by = "", $limit = "")
 {
     global $client;
     if ($where != "") {
         $where = $where . " AND idclient = '" . Contenido_Security::escapeDB($client, NULL) . "'";
     }
     return parent::select($where, $group_by, $order_by, $limit);
 }
 function set($idworkflowitem, $action)
 {
     $this->select("idworkflowitem = '" . Contenido_Security::escapeDB($idworkflowitem, NULL) . "' AND action = '" . Contenido_Security::escapeDB($action, NULL) . "'");
     if (!$this->next()) {
         $newitem = parent::create();
         $newitem->setField("idworkflowitem", $idworkflowitem);
         $newitem->setField("action", $action);
         $newitem->store();
     }
 }
function getGroupIDs(&$db)
{
    global $cfg, $sess, $auth, $group_id, $_arrGroupIDs_gGI;
    if (is_array($_arrGroupIDs_gGI)) {
        return $_arrGroupIDs_gGI;
    }
    $sql = "SELECT group_id FROM " . $cfg["tab"]["groupmembers"] . " WHERE user_id='" . Contenido_Security::escapeDB($auth->auth["uid"], $db) . "'";
    $db->query($sql);
    $_arrGroupIDs_gGI = array();
    while ($db->next_record()) {
        $_arrGroupIDs_gGI[] = $db->f('group_id');
    }
    return $_arrGroupIDs_gGI;
}
 /**
  * Overriden store()-Method to set modified and modifiedby data and
  * to ensure, that there is only one welcome newsletter
  */
 public function store()
 {
     global $client, $lang, $auth;
     $client = Contenido_Security::toInteger($client);
     $lang = Contenido_Security::toInteger($lang);
     $this->set("modified", date("Y-m-d H:i:s"), false);
     $this->set("modifiedby", $auth->auth["uid"]);
     if ($this->get("welcome") == 1) {
         $oItems = new NewsletterCollection();
         $oItems->setWhere("idclient", $client);
         $oItems->setWhere("idlang", $lang);
         $oItems->setWhere("welcome", 1);
         $oItems->setWhere("idnews", $this->get("idnews"), "<>");
         $oItems->query();
         while ($oItem = $oItems->next()) {
             $oItem->set("welcome", 0);
             $oItem->store();
         }
         unset($oItem);
         unset($oItems);
     }
     parent::store();
 }
 while ($db->next_record()) {
     if ($cronjob != true) {
         // Check userrights, if no cronjob
         $iCheck = cCatPerm($db->f("idcat"), $db2);
         if ($iCheck == true) {
             $aCats[] = Contenido_Security::toInteger($db->f("idcat"));
         }
     } else {
         $aCats[] = Contenido_Security::toInteger($db->f("idcat"));
     }
 }
 // Use SQL-WHERE if lang is not zero
 if ($langart != 0) {
     $sLang_where = "AND art.idlang = '" . Contenido_Security::toInteger($langart) . "' AND catName.idlang = '" . Contenido_Security::toInteger($langart) . "'";
 } elseif (!isset($langart)) {
     $sLang_where = "AND art.idlang = '" . Contenido_Security::toInteger($lang) . "' AND catName.idlang = '" . Contenido_Security::toInteger($lang) . "'";
 }
 if (!empty($aCats)) {
     // How many articles exists? [Text]
     $sql = "SELECT art.title, art.idlang, cat.idart, cat.idcat, catName.name AS namecat, con.value FROM " . $cfg['tab']['cat_art'] . " cat\n           LEFT JOIN " . $cfg['tab']['art_lang'] . " art ON (art.idart = cat.idart)\n           LEFT JOIN " . $cfg['tab']['cat_lang'] . " catName ON (catName.idcat = cat.idcat)\n           LEFT JOIN " . $cfg['tab']['content'] . " con ON (con.idartlang = art.idartlang)\n           WHERE (con.value LIKE '%action%' OR con.value LIKE '%data%' OR con.value LIKE '%href%' OR con.value LIKE '%src%')\n           AND cat.idcat IN (0, " . join(", ", $aCats) . ") AND cat.idcat != '0' " . $sLang_where . "\n           AND art.online = '1' AND art.redirect = '0'";
     $db->query($sql);
     while ($db->next_record()) {
         // Text decode
         $value = urldecode($db->f("value"));
         // Search the text
         searchLinks($value, $db->f("idart"), $db->f("title"), $db->f("idcat"), $db->f("namecat"), $db->f("idlang"));
         // Search front_content.php-links
         if ($_GET['mode'] != 2) {
             searchFrontContentLinks($value, $db->f("idart"), $db->f("title"), $db->f("idcat"), $db->f("namecat"));
         }
     }
function doWorkflowAction($idartlang, $action)
{
    global $cfg, $idcat;
    switch ($action) {
        case "last":
            $artAllocations = new WorkflowArtAllocations();
            $artAllocations->select("idartlang = '{$idartlang}'");
            if ($obj = $artAllocations->next()) {
                $usersequence = new WorkflowUserSequence();
                $usersequence->loadByPrimaryKey($obj->get("idusersequence"));
                $workflowitem = $usersequence->getWorkflowItem();
                $idworkflow = $workflowitem->get("idworkflow");
                $newpos = $workflowitem->get("position") - 1;
                if ($newpos < 1) {
                    $newpos = 1;
                }
                $workflowitems = new WorkflowItems();
                $workflowitems->select("idworkflow = '{$idworkflow}' AND position = '" . Contenido_Security::escapeDB($newpos, NULL) . "'");
                if ($nextObj = $workflowitems->next()) {
                    $userSequences = new WorkflowUserSequences();
                    $idworkflowitem = $nextObj->get("idworkflowitem");
                    $userSequences->select("idworkflowitem = '{$idworkflowitem}'");
                    if ($nextSeqObj = $userSequences->next()) {
                        $obj->set("lastusersequence", $obj->get("idusersequence"));
                        $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
                        $obj->set("laststatus", "last");
                        $obj->store();
                    }
                }
            }
            break;
        case "next":
            $artAllocations = new WorkflowArtAllocations();
            $artAllocations->select("idartlang = '{$idartlang}'");
            if ($obj = $artAllocations->next()) {
                $usersequence = new WorkflowUserSequence();
                $usersequence->loadByPrimaryKey($obj->get("idusersequence"));
                $workflowitem = $usersequence->getWorkflowItem();
                $idworkflow = $workflowitem->get("idworkflow");
                $newpos = $workflowitem->get("position") + 1;
                $workflowitems = new WorkflowItems();
                $workflowitems->select("idworkflow = '{$idworkflow}' AND position = '" . Contenido_Security::escapeDB($newpos, NULL) . "'");
                if ($nextObj = $workflowitems->next()) {
                    $userSequences = new WorkflowUserSequences();
                    $idworkflowitem = $nextObj->get("idworkflowitem");
                    $userSequences->select("idworkflowitem = '{$idworkflowitem}'");
                    if ($nextSeqObj = $userSequences->next()) {
                        $obj->set("lastusersequence", '10');
                        $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
                        $obj->set("laststatus", "confirm");
                        $obj->store();
                    }
                } else {
                    $workflowitems->select("idworkflow = '{$idworkflow}' AND position = '" . Contenido_Security::escapeDB($workflowitem->get("position"), NULL) . "'");
                    if ($nextObj = $workflowitems->next()) {
                        $userSequences = new WorkflowUserSequences();
                        $idworkflowitem = $nextObj->get("idworkflowitem");
                        $userSequences->select("idworkflowitem = '{$idworkflowitem}'");
                        if ($nextSeqObj = $userSequences->next()) {
                            $obj->set("lastusersequence", $obj->get("idusersequence"));
                            $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
                            $obj->set("laststatus", "confirm");
                            $obj->store();
                        }
                    }
                }
            }
            break;
        case "reject":
            $artAllocations = new WorkflowArtAllocations();
            $artAllocations->select("idartlang = '{$idartlang}'");
            if ($obj = $artAllocations->next()) {
                $usersequence = new WorkflowUserSequence();
                $usersequence->loadByPrimaryKey($obj->get("idusersequence"));
                $workflowitem = $usersequence->getWorkflowItem();
                $idworkflow = $workflowitem->get("idworkflow");
                $newpos = 1;
                $workflowitems = new WorkflowItems();
                $workflowitems->select("idworkflow = '{$idworkflow}' AND position = '" . Contenido_Security::escapeDB($newpos, NULL) . "'");
                if ($nextObj = $workflowitems->next()) {
                    $userSequences = new WorkflowUserSequences();
                    $idworkflowitem = $nextObj->get("idworkflowitem");
                    $userSequences->select("idworkflowitem = '{$idworkflowitem}'");
                    if ($nextSeqObj = $userSequences->next()) {
                        $obj->set("lastusersequence", $obj->get("idusersequence"));
                        $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
                        $obj->set("laststatus", "reject");
                        $obj->store();
                    }
                }
            }
            break;
        case "revise":
            $db = new DB_Contenido();
            $sql = "SELECT idart, idlang FROM " . $cfg["tab"]["art_lang"] . " WHERE idartlang = '" . Contenido_Security::escapeDB($idartlang, $db) . "'";
            $db->query($sql);
            $db->next_record();
            $idart = $db->f("idart");
            $idlang = $db->f("idlang");
            $newidart = conCopyArticle($idart, $idcat, "foo");
            break;
        default:
    }
}
if (!defined('CON_FRAMEWORK')) {
    die('Illegal call');
}
$plugin_name = "linkchecker";
$iWhitelist_timeout = 2592000;
// 30 days
global $perm;
if (!$perm->have_perm_area_action($plugin_name, $plugin_name)) {
    exit;
}
// Template-definition
$tpl->set('s', 'CONTENIDO_URL', $cfg['path']['contenido_fullhtml']);
$tpl->set('s', 'SID', $sess->id);
/* Whitelist: Delete */
if (!empty($_GET['url_to_delete'])) {
    $sql = "DELETE FROM " . $cfg['tab']['whitelist'] . " WHERE url = '" . Contenido_Security::escapeDB(base64_decode($_GET['url_to_delete']), $db) . "'";
    $db->query($sql);
}
// Get whitelist
$sql = "SELECT url, lastview FROM " . $cfg['tab']['whitelist'] . " WHERE lastview < " . (time() + $iWhitelist_timeout) . "\n\t\tAND lastview > " . (time() - $iWhitelist_timeout) . " ORDER BY lastview DESC";
$db->query($sql);
while ($db->next_record()) {
    $tpl2 = new Template();
    $tpl2->reset();
    $tpl2->set('s', 'CONTENIDO_URL', $cfg['path']['contenido_fullhtml']);
    $tpl2->set('s', 'SID', $sess->id);
    $tpl2->set('s', 'URL', $db->f("url"));
    $tpl2->set('s', 'URL_ENCODE', base64_encode($db->f("url")));
    $tpl2->set('s', 'ENTRY', strftime(i18n('%Y-%m-%d, %I:%M%S %p', $plugin_name), $db->f("lastview")));
    $aWhitelist .= $tpl2->generate($cfg['templates']['linkchecker_whitelist_urls'], 1);
}
function prepareWorkflowItems()
{
    global $action, $lang, $modidcat, $workflowSelectBox, $workflowworkflows, $client, $tpl, $cfg;
    $workflowworkflows = new Workflows();
    if ($action === 'workflow_inherit_down') {
        $tmp = strDeeperCategoriesArray($modidcat);
        $asworkflow = getWorkflowForCat($modidcat);
        $wfa = new WorkflowAllocations();
        foreach ($tmp as $tmp_cat) {
            $idcatlang = getCatLang($tmp_cat, $lang);
            if ($asworkflow == 0) {
                $wfa->select("idcatlang = '{$idcatlang}'");
                if ($item = $wfa->next()) {
                    $wfa->delete($item->get("idallocation"));
                    # delete user sequences for listing in tasklist for each included article
                    $oArticles = new ArticleCollection(array('idcat' => $idcatlang, 'start' => true, 'offline' => true));
                    while ($oArticle = $oArticles->nextArticle()) {
                        setUserSequence($oArticle->getField('idartlang'), -1);
                    }
                }
            } else {
                $wfa->select("idcatlang = '{$idcatlang}'");
                if ($item = $wfa->next()) {
                    $item->setWorkflow($asworkflow);
                    $item->store();
                } else {
                    $wfa->create($asworkflow, $idcatlang);
                    # generate user sequences for listing in tasklist for each included article
                    $oArticles = new ArticleCollection(array('idcat' => $tmp_cat, 'start' => true, 'offline' => true));
                    while ($oArticle = $oArticles->nextArticle()) {
                        setUserSequence($oArticle->getField('idartlang'), $asworkflow);
                    }
                }
            }
        }
    }
    if ($action == "workflow_cat_assign") {
        $seltpl = "wfselect" . $modidcat;
        $wfa = new WorkflowAllocations();
        $idcatlang = getCatLang($modidcat, $lang);
        #associate workflow with category
        if ($GLOBALS[$seltpl] != 0) {
            $wfa->select("idcatlang = '{$idcatlang}'");
            if ($item = $wfa->next()) {
                $item->setWorkflow($GLOBALS[$seltpl]);
                $item->store();
            } else {
                $wfa->create($GLOBALS[$seltpl], $idcatlang);
            }
            # generate user sequences for listing in tasklist for each included article
            $oArticles = new ArticleCollection(array('idcat' => $modidcat, 'start' => true, 'offline' => true));
            while ($oArticle = $oArticles->nextArticle()) {
                setUserSequence($oArticle->getField('idartlang'), $GLOBALS[$seltpl]);
            }
            #unlink workflow with category
        } else {
            $wfa->select("idcatlang = '{$idcatlang}'");
            if ($item = $wfa->next()) {
                $alloc = $item->get("idallocation");
            }
            $wfa->delete($alloc);
            # delete user sequences for listing in tasklist for each included article
            $oArticles = new ArticleCollection(array('idcat' => $modidcat, 'start' => true, 'offline' => true));
            while ($oArticle = $oArticles->nextArticle()) {
                setUserSequence($oArticle->getField('idartlang'), -1);
            }
        }
    }
    $workflowSelectBox = new cHTMLSelectElement("foo");
    $workflowSelectBox->setClass("text_medium");
    $workflowworkflows->select("idclient = '{$client}' AND idlang = '" . Contenido_Security::escapeDB($lang, null) . "'");
    $workflowOption = new cHTMLOptionElement("--- " . i18n("None", "workflow") . " ---", 0);
    $workflowSelectBox->addOptionElement(0, $workflowOption);
    while ($workflow = $workflowworkflows->next()) {
        $workflowOption = new cHTMLOptionElement($workflow->get("name"), $workflow->get("idworkflow"));
        $workflowSelectBox->addOptionElement($workflow->get("idworkflow"), $workflowOption);
    }
    $workflowSelectBox->updateAttributes(array("id" => "wfselect{IDCAT}"));
    $workflowSelectBox->updateAttributes(array("name" => "wfselect{IDCAT}"));
    $tpl->set('s', 'PLUGIN_WORKFLOW', $workflowSelectBox->render() . '<a href="javascript:setWorkflow({IDCAT}, \\\'wfselect{IDCAT}\\\')"><img src="' . $cfg["path"]["images"] . 'submit.gif" class="spaced"></a>');
    $tpl->set('s', 'PLUGIN_WORKFLOW_TRANSLATION', i18n("Inherit workflow down", "workflow"));
}
 /**
  * Creates a newsletter job
  * @param $name        string    Specifies the name of the newsletter, the same name may be used more than once
  * @param $idnews    integer Newsletter id
  */
 public function create($iIDNews, $iIDCatArt, $sName = "")
 {
     global $client, $lang, $cfg, $cfgClient, $auth;
     $oNewsletter = new Newsletter();
     if ($oNewsletter->loadByPrimaryKey($iIDNews)) {
         $iIDNews = Contenido_Security::toInteger($iIDNews);
         $iIDCatArt = Contenido_Security::toInteger($iIDCatArt);
         $lang = Contenido_Security::toInteger($lang);
         $client = Contenido_Security::toInteger($client);
         $sName = Contenido_Security::escapeDB($sName, null);
         $oItem = parent::create();
         $oItem->set("idnews", $iIDNews);
         $oItem->set("idclient", $client);
         $oItem->set("idlang", $lang);
         if ($sName == "") {
             $oItem->set("name", $oNewsletter->get("name"));
         } else {
             $oItem->set("name", $sName);
         }
         $oItem->set("type", $oNewsletter->get("type"));
         $oItem->set("use_cronjob", $oNewsletter->get("use_cronjob"));
         $oLang = new cApiLanguage($lang);
         $oItem->set("encoding", $oLang->get("encoding"));
         unset($oLang);
         $oItem->set("idart", $oNewsletter->get("idart"));
         $oItem->set("subject", $oNewsletter->get("subject"));
         // Precompile messages
         #$sPath = $cfgClient[$client]["path"]["htmlpath"]."front_content.php?changelang=".$lang."&idcatart=".$iIDCatArt."&";
         $sPath = Contenido_Url::getInstance()->build(array('idcatart' => $iIDCatArt, 'client' => $client, 'lang' => $lang), true);
         $sPath .= strpos($sPath, '?') === false ? '?' : '&';
         $sMessageText = $oNewsletter->get("message");
         // Preventing double lines in mail, you may wish to disable this function on windows servers
         if (!getSystemProperty("newsletter", "disable-rn-replacement")) {
             $sMessageText = str_replace("\r\n", "\n", $sMessageText);
         }
         $oNewsletter->_replaceTag($sMessageText, false, "unsubscribe", $sPath . "unsubscribe={KEY}");
         $oNewsletter->_replaceTag($sMessageText, false, "change", $sPath . "change={KEY}");
         $oNewsletter->_replaceTag($sMessageText, false, "stop", $sPath . "stop={KEY}");
         $oNewsletter->_replaceTag($sMessageText, false, "goon", $sPath . "goon={KEY}");
         $oItem->set("message_text", $sMessageText);
         if ($oNewsletter->get("type") == "text") {
             // Text newsletter, no html message
             $sMessageHTML = "";
         } else {
             // HTML newsletter, get article content
             $sMessageHTML = $oNewsletter->getHTMLMessage();
             if ($sMessageHTML) {
                 $oNewsletter->_replaceTag($sMessageHTML, true, "name", "MAIL_NAME");
                 $oNewsletter->_replaceTag($sMessageHTML, true, "number", "MAIL_NUMBER");
                 $oNewsletter->_replaceTag($sMessageHTML, true, "date", "MAIL_DATE");
                 $oNewsletter->_replaceTag($sMessageHTML, true, "time", "MAIL_TIME");
                 $oNewsletter->_replaceTag($sMessageHTML, true, "unsubscribe", $sPath . "unsubscribe={KEY}");
                 $oNewsletter->_replaceTag($sMessageHTML, true, "change", $sPath . "change={KEY}");
                 $oNewsletter->_replaceTag($sMessageHTML, true, "stop", $sPath . "stop={KEY}");
                 $oNewsletter->_replaceTag($sMessageHTML, true, "goon", $sPath . "goon={KEY}");
                 // Replace plugin tags by simple MAIL_ tags
                 if (getSystemProperty("newsletter", "newsletter-recipients-plugin") == "true") {
                     if (is_array($cfg['plugins']['recipients'])) {
                         foreach ($cfg['plugins']['recipients'] as $sPlugin) {
                             plugin_include("recipients", $sPlugin . "/" . $sPlugin . ".php");
                             if (function_exists("recipients_" . $sPlugin . "_wantedVariables")) {
                                 $aPluginVars = array();
                                 $aPluginVars = call_user_func("recipients_" . $sPlugin . "_wantedVariables");
                                 foreach ($aPluginVars as $sPluginVar) {
                                     $oNewsletter->_replaceTag($sMessageHTML, true, $sPluginVar, "MAIL_" . strtoupper($sPluginVar));
                                 }
                             }
                         }
                     }
                 }
             } else {
                 // There was a problem getting html message (maybe article deleted)
                 // Cancel job generation
                 return false;
             }
         }
         $oItem->set("message_html", $sMessageHTML);
         $oItem->set("newsfrom", $oNewsletter->get("newsfrom"));
         if ($oNewsletter->get("newsfromname") == "") {
             $oItem->set("newsfromname", $oNewsletter->get("newsfrom"));
         } else {
             $oItem->set("newsfromname", $oNewsletter->get("newsfromname"));
         }
         $oItem->set("newsdate", date("Y-m-d H:i:s"), false);
         //$oNewsletter->get("newsdate"));
         $oItem->set("dispatch", $oNewsletter->get("dispatch"));
         $oItem->set("dispatch_count", $oNewsletter->get("dispatch_count"));
         $oItem->set("dispatch_delay", $oNewsletter->get("dispatch_delay"));
         // Store "send to" info in serialized array (just info)
         $aSendInfo = array();
         $aSendInfo[] = $oNewsletter->get("send_to");
         switch ($oNewsletter->get("send_to")) {
             case "selection":
                 $oGroups = new RecipientGroupCollection();
                 $oGroups->setWhere("idnewsgroup", unserialize($oNewsletter->get("send_ids")), "IN");
                 $oGroups->setOrder("groupname");
                 $oGroups->query();
                 #$oGroups->select("idnewsgroup IN ('" . implode("','", unserialize($oNewsletter->get("send_ids"))) . "')", "", "groupname");
                 while ($oGroup = $oGroups->next()) {
                     $aSendInfo[] = $oGroup->get("groupname");
                 }
                 unset($oGroup);
                 unset($oGroups);
                 break;
             case "single":
                 if (is_numeric($oNewsletter->get("send_ids"))) {
                     $oRcp = new Recipient($oNewsletter->get("send_ids"));
                     if ($oRcp->get("name") == "") {
                         $aSendInfo[] = $oRcp->get("email");
                     } else {
                         $aSendInfo[] = $oRcp->get("name");
                     }
                     $aSendInfo[] = $oRcp->get("email");
                     unset($oRcp);
                 }
                 break;
             default:
         }
         $oItem->set("send_to", serialize($aSendInfo), false);
         $oItem->set("created", date("Y-m-d H:i:s"), false);
         $oItem->set("author", $auth->auth["uid"]);
         $oItem->set("authorname", $auth->auth["uname"]);
         unset($oNewsletter);
         // Not needed anymore
         // Adds log items for all recipients and returns recipient count
         $oLogs = new cNewsletterLogCollection();
         $iRecipientCount = $oLogs->initializeJob($oItem->get($oItem->primaryKey), $iIDNews);
         unset($oLogs);
         $oItem->set("rcpcount", $iRecipientCount);
         $oItem->set("sendcount", 0);
         $oItem->set("status", 1);
         // Waiting for sending; note, that status will be set to 9, if $iRecipientCount = 0 in store() method
         $oItem->store();
         return $oItem;
     } else {
         return false;
     }
 }
 function updateArtAllocation($idworkflowitem, $delete = false)
 {
     global $idworkflow, $cfg;
     $oDb = new DB_Contenido();
     $aUserSequences = array();
     $sSql = 'SELECT idusersequence FROM ' . $cfg["tab"]["workflow_user_sequences"] . ' WHERE idworkflowitem = ' . Contenido_Security::escapeDB($idworkflowitem, $oDb) . ';';
     $oDb->query($sSql);
     while ($oDb->next_record()) {
         array_push($aUserSequences, Contenido_Security::escapeDB($oDb->f('idusersequence'), $oDb));
     }
     $aIdArtLang = array();
     if (count($aUserSequences) > 0) {
         $sSql = 'SELECT idartlang FROM ' . $cfg["tab"]["workflow_art_allocation"] . ' WHERE idusersequence in (' . implode(',', $aUserSequences) . ');';
         $oDb->query($sSql);
         while ($oDb->next_record()) {
             array_push($aIdArtLang, $oDb->f('idartlang'));
         }
         $sSql = 'DELETE FROM ' . $cfg["tab"]["workflow_art_allocation"] . ' WHERE idusersequence in (' . implode(',', $aUserSequences) . ');';
         $oDb->query($sSql);
     }
     if ($delete) {
         parent::delete($idworkflowitem);
     }
     foreach ($aIdArtLang as $iIdArtLang) {
         setUserSequence($iIdArtLang, $idworkflow);
     }
 }
            case "Minutes":
                $maxtime = $starttime + $timelimit * 60;
                break;
            case "Hours":
                $maxtime = $starttime + $timelimit * 3600;
                break;
            case "Days":
                $maxtime = $starttime + $timelimit * 86400;
                break;
            case "Weeks":
                $maxtime = $starttime + $timelimit * 604800;
                break;
            case "Months":
                $maxtime = $starttime + $timelimit * 2678400;
                break;
            case "Years":
                $maxtime = $starttime + $timelimit * 31536000;
                break;
            default:
                $maxtime = $starttime + $timelimit;
        }
        if ($maxtime < time()) {
            $pos = $pos + 1;
            $workflowusersequences->select("idworkflowitem = '{$wfitem}' AND position = '" . Contenido_Security::escapeDB($pos, NULL) . "'");
            if ($wfobj = $workflowusersequences->next()) {
                $obj->set("idusersequence", $wfobj->get("idusersequence"));
                $obj->store();
            }
        }
    }
}
 function _increaseOrder($parentId = false, $fromOrder)
 {
     $sql = "UPDATE " . $this->table['pica_alloc'] . " SET sortorder = sortorder + 1 WHERE sortorder >= " . Contenido_Security::toInteger($fromOrder);
     if ($parentId === false) {
         $sql .= " AND parentid IS NULL";
     } else {
         $sql .= " AND parentid = " . Contenido_Security::toInteger($parentId);
     }
     $this->db->query($sql);
 }
    /**
     * build SQL query to find articles by catgories
     *
     */
    function _buildQuery_MatchingContentByCategories($aCategories, $iOffset, $iNumOfRows)
    {
        if (count($aCategories) > 0) {
            $sWHERE_Category_IN = " c.idcat IN (" . implode(',', $aCategories) . ") AND ";
        } else {
            $sWHERE_Category_IN = '';
        }
        if (is_integer($iNumOfRows) and $iNumOfRows > 0) {
            $sLimit = " LIMIT " . Contenido_Security::toInteger($iOffset) . ", " . Contenido_Security::toInteger($iNumOfRows);
        } else {
            $sLimit = '';
        }
        $sql = '
		SELECT
            a.idart, a.online, a.idartlang, c.idcat
        FROM
            ' . $this->table['art_lang'] . ' AS a,
            ' . $this->table['art'] . ' AS b,
            ' . $this->table['cat_art'] . ' AS c,
            ' . $this->table['cat_lang'] . ' AS d
        WHERE
			' . $sWHERE_Category_IN . '
            b.idclient = ' . Contenido_Security::toInteger($this->client) . ' AND
            a.idlang = ' . Contenido_Security::toInteger($this->lang) . ' AND
            a.idartlang != d.startidartlang AND
            a.online = 1 AND
			c.idcat = d.idcat AND
            b.idart = c.idart AND
            a.idart = b.idart
			' . $sLimit . ' ';
        if ($this->bDebug) {
            print "<!-- ";
            print $sql;
            print " -->";
        }
        return $sql;
    }
 /**
  * Returns all recipients in a single group
  * @param $idrecipientgroup int specifies the newsletter group
  * @param $asObjects boolean specifies if the function should return objects
  * @return array RecipientRecipient items
  */
 public function getRecipientsInGroup($idrecipientgroup, $asObjects = true)
 {
     $idrecipientgroup = Contenido_Security::toInteger($idrecipientgroup);
     $this->setWhere("idnewsgroup", $idrecipientgroup);
     $this->query();
     $aObjects = array();
     while ($oItem = $this->next()) {
         if ($asObjects) {
             $oRecipient = new Recipient();
             $oRecipient->loadByPrimaryKey($oItem->get("idnewsrcp"));
             $aObjects[] = $oRecipient;
         } else {
             $aObjects[] = $oItem->get("idnewsrcp");
         }
     }
     return $aObjects;
 }
}
// Exec actions
$oNewsletter = new Newsletter();
$oNewsletter->loadByPrimaryKey($idnewsletter);
if ($oNewsletter->virgin == false && $oNewsletter->get("idclient") == $client && $oNewsletter->get("idlang") == $lang) {
    // Check and set values
    if (!is_numeric($_REQUEST["selTemplate"])) {
        $_REQUEST["selTemplate"] = 0;
    }
    // Saving message changes; note, that if a user doesn't have the right to save the
    // text message he may still have the right to change the html article. To prevent
    // changing the html article, give the user only read access right for the newsletter
    // article category - the article will be shown also, if he doesn't have any rights at all...
    if ($action == "news_save" && $perm->have_perm_area_action("news", $action)) {
        // Changing e.g. \' back to ' (magic_quotes)
        $sMessage = Contenido_Security::unescapeDB($_REQUEST["txtMessage"]);
        $oNewsletter->set("message", $sMessage);
        if ($oNewsletter->get("template_idart") != $_REQUEST["selTemplate"]) {
            if ($oNewsletter->get("idart") > 0) {
                // Template has been changed: Delete old article
                // (this discards the current html content as it deletes the existing newsletter article)
                conDeleteArt($oNewsletter->get("idart"));
                $iIDArt = 0;
            }
            if ($_REQUEST["selTemplate"] > 0) {
                // Template has been changed, but specified: Store template article as new newsletter article
                $iIDArt = conCopyArticle($_REQUEST["selTemplate"], $oClientLang->getProperty("newsletter", "html_newsletter_idcat"), sprintf(i18n("Newsletter: %s", $plugin_name), $oNewsletter->get("name")));
                conMakeOnline($iIDArt, $lang);
                // Article has to be online for sending...
            }
            $oNewsletter->set("idart", $iIDArt);
 /**
  * setCatLang sets the idcatlang for the current item. Should
  * only be called by the create function.
  * @param int $idcatlang idcatlang to set.
  */
 function setCatLang($idcatlang)
 {
     global $cfg;
     $allocations = new WorkflowAllocations();
     $allocations->select("idcatlang = '{$idcatlang}'");
     if ($allocations->next() !== false) {
         $this->lasterror = i18n("Category already has a workflow assigned", "workflow");
         return false;
     }
     $db = new DB_Contenido();
     $sql = "SELECT idcatlang FROM " . $cfg["tab"]["cat_lang"] . " WHERE idcatlang = '" . Contenido_Security::toInteger($idcatlang) . "'";
     $db->query($sql);
     if (!$db->next_record()) {
         $this->lasterror = i18n("Category doesn't exist, assignment failed", "workflow");
         return false;
     }
     parent::setField("idcatlang", $idcatlang);
     parent::store();
     return true;
 }
 */
if (!defined('CON_FRAMEWORK')) {
    die('Illegal call');
}
$nav = new Contenido_Navigation();
$parentarea = getParentAreaID($area);
$sql = "SELECT\n                idarea\n            FROM\n                " . $cfg["tab"]["area"] . " AS a\n            WHERE\n                a.name = '" . Contenido_Security::escapeDB($parentarea, $db) . "' OR\n                a.parent_id = '" . Contenido_Security::escapeDB($parentarea, $db) . "'\n            ORDER BY\n                idarea";
$db->query($sql);
$in_str = "";
while ($db->next_record()) {
    $in_str .= $db->f('idarea') . ',';
}
$len = strlen($in_str) - 1;
$in_str = substr($in_str, 0, $len);
$in_str = '(' . $in_str . ')';
$sql = "SELECT\n                b.location AS location,\n                a.name AS name\n            FROM\n                " . $cfg["tab"]["area"] . " AS a,\n                " . $cfg["tab"]["nav_sub"] . " AS b\n            WHERE\n                b.idarea IN " . Contenido_Security::escapeDB($in_str, $db) . " AND\n                b.idarea = a.idarea AND\n                b.level = 1\n            ORDER BY\n                b.idnavs";
$db->query($sql);
while ($db->next_record()) {
    # Extract caption from
    # the xml language file
    $caption = $nav->getName($db->f("location"));
    $tmp_area = $db->f("name");
    # Set template data
    $tpl->set("d", "ID", 'c_' . $tpl->dyn_cnt[0]);
    $tpl->set("d", "CLASS", '');
    $tpl->set("d", "OPTIONS", '');
    $tpl->set("d", "CAPTION", '<a class="white" onclick="sub.clicked(this)" target="right_bottom" href="' . $sess->url("main.php?area={$tmp_area}&frame=4&idworkflow={$idworkflow}") . '">' . $caption . '</a>');
    if ($area == $tmp_area) {
        $tpl->set('s', 'DEFAULT', markSubMenuItem($tpl->dyn_cnt[0], true));
    }
    $tpl->next();
function checkLinks()
{
    global $auth, $cfgClient, $client, $cfg, $cronjob, $db, $aErrors, $lang, $langart, $whitelist;
    global $aSearchIDInfosArt, $aSearchIDInfosCat, $aSearchIDInfosCatArt, $aSearchIDInfosNonID;
    if (count($aSearchIDInfosArt) > 0) {
        // Checks idarts
        for ($i = 0; $i < count($aSearchIDInfosArt); $i++) {
            if ($i == 0) {
                $sSearch = Contenido_Security::toInteger($aSearchIDInfosArt[$i]['id']);
            } else {
                $sSearch .= ", " . Contenido_Security::toInteger($aSearchIDInfosArt[$i]['id']);
            }
        }
        // Check articles
        $aFind = array();
        $sql = "SELECT idart, online FROM " . $cfg['tab']['art_lang'] . " WHERE idart IN (" . $sSearch . ")";
        $db->query($sql);
        while ($db->next_record()) {
            $aFind[$db->f("idart")] = array("online" => $db->f("online"));
        }
        for ($i = 0; $i < count($aSearchIDInfosArt); $i++) {
            if (isset($aFind[$aSearchIDInfosArt[$i]['id']]) && $aFind[$aSearchIDInfosArt[$i]['id']]['online'] == 0) {
                $aErrors['art'][] = array_merge($aSearchIDInfosArt[$i], array("error_type" => "offline"));
            } elseif (!isset($aFind[$aSearchIDInfosArt[$i]['id']])) {
                $aErrors['art'][] = array_merge($aSearchIDInfosArt[$i], array("error_type" => "unknown"));
            }
        }
    }
    if (count($aSearchIDInfosCat) > 0) {
        // Checks idcats
        for ($i = 0; $i < count($aSearchIDInfosCat); $i++) {
            if ($i == 0) {
                $sSearch = $aSearchIDInfosCat[$i]['id'];
            } else {
                $sSearch .= ", " . $aSearchIDInfosCat[$i]['id'];
            }
        }
        // Check categorys
        $aFind = array();
        $sql = "SELECT idcat, startidartlang, visible FROM " . $cfg['tab']['cat_lang'] . " WHERE idcat IN (" . $sSearch . ") AND idlang = '" . Contenido_Security::toInteger($lang) . "'";
        $db->query($sql);
        while ($db->next_record()) {
            $aFind[$db->f("idcat")] = array("online" => $db->f("visible"), "startidart" => $db->f("startidartlang"));
        }
        for ($i = 0; $i < count($aSearchIDInfosCat); $i++) {
            if (is_array($aFind[$aSearchIDInfosCat[$i]['id']]) && $aFind[$aSearchIDInfosCat[$i]['id']]['startidart'] == 0) {
                $aErrors['cat'][] = array_merge($aSearchIDInfosCat[$i], array("error_type" => "startart"));
            } elseif (is_array($aFind[$aSearchIDInfosCat[$i]['id']]) && $aFind[$aSearchIDInfosCat[$i]['id']]['online'] == 0) {
                $aErrors['cat'][] = array_merge($aSearchIDInfosCat[$i], array("error_type" => "offline"));
            } elseif (!is_array($aFind[$aSearchIDInfosCat[$i]['id']])) {
                $aErrors['cat'][] = array_merge($aSearchIDInfosCat[$i], array("error_type" => "unknown"));
            }
            if (is_array($aFind[$aSearchIDInfosCat[$i]['id']]) && $aFind[$aSearchIDInfosCat[$i]['id']]['startidart'] != 0) {
                $sql = "SELECT idart FROM " . $cfg['tab']['art_lang'] . " WHERE idartlang = '" . $aFind[$aSearchIDInfosCat[$i]['id']]['startidart'] . "' AND online = '1'";
                $db->query($sql);
                if ($db->num_rows() == 0) {
                    $aErrors['cat'][] = array_merge($aSearchIDInfosCat[$i], array("error_type" => "startart"));
                }
            }
        }
    }
    if (count($aSearchIDInfosCatArt) > 0) {
        // Checks idcatarts
        for ($i = 0; $i < count($aSearchIDInfosCatArt); $i++) {
            if ($i == 0) {
                $sSearch = Contenido_Security::toInteger($aSearchIDInfosCatArt[$i]['id']);
            } else {
                $sSearch .= ", " . Contenido_Security::toInteger($aSearchIDInfosCatArt[$i]['id']);
            }
        }
        // Check articles
        $aFind = array();
        $sql = "SELECT idcatart FROM " . $cfg['tab']['cat_art'] . " WHERE idcatart IN (" . $sSearch . ")";
        $db->query($sql);
        while ($db->next_record()) {
            $aFind[] = $db->f("idcatart");
        }
        for ($i = 0; $i < count($aSearchIDInfosCatArt); $i++) {
            if (!in_array($aSearchIDInfosCatArt[$i]['id'], $aFind)) {
                $aErrors['art'][] = array_merge($aSearchIDInfosCatArt[$i], array("error_type" => "unknown"));
            }
        }
    }
    if (count($aSearchIDInfosNonID) != 0) {
        // Checks other links (e. g. http, www, dfbs)
        // Select userrights (is the user admin or sysadmin?)
        $sql = "SELECT username FROM " . $cfg['tab']['phplib_auth_user_md5'] . " WHERE user_id='" . Contenido_Security::escapeDB($auth->auth['uid'], $db) . "' AND perms LIKE '%admin%'";
        $db->query($sql);
        if ($db->num_rows() > 0 || $cronjob == true) {
            // User is admin when he is or when he run the cronjob
            $iAdmin = true;
        }
        for ($i = 0; $i < count($aSearchIDInfosNonID); $i++) {
            if (url_is_uri($aSearchIDInfosNonID[$i]['url'])) {
                if (substr($aSearchIDInfosNonID[$i]['url'], 0, strlen($aSearchIDInfosNonID[$i]['url'])) == $cfgClient[$client]['path']['htmlpath']) {
                    $iPing = @file_exists(str_replace($cfgClient[$client]['path']['htmlpath'], $cfgClient[$client]['path']['frontend'], $aSearchIDInfosNonID[$i]['url']));
                } else {
                    $iPing = @fopen($aSearchIDInfosNonID[$i]['url'], 'r');
                }
                if (!$iPing) {
                    if (url_is_image($aSearchIDInfosNonID[$i]['url'])) {
                        $aErrors['docimages'][] = array_merge($aSearchIDInfosNonID[$i], array("error_type" => "unknown"));
                    } else {
                        $aErrors['others'][] = array_merge($aSearchIDInfosNonID[$i], array("error_type" => "unknown"));
                    }
                }
            } elseif (substr($aSearchIDInfosNonID[$i]['url'], strlen($aSearchIDInfosNonID[$i]['url']) - 5, 5) == ".html") {
                $iPing = @file_exists($cfgClient[$client]['path']['htmlpath'] . $aSearchIDInfosNonID[$i]['url']);
                if (!$iPing) {
                    $aErrors['art'][] = array_merge($aSearchIDInfosNonID[$i], array("error_type" => "unknown"));
                }
            } elseif (substr($aSearchIDInfosNonID[$i]['url'], 0, 20) == "dbfs.php?file=dbfs:/") {
                $sDBurl = substr($aSearchIDInfosNonID[$i]['url'], 20, strlen($aSearchIDInfosNonID[$i]['url']));
                $iPos = strrpos($sDBurl, '/');
                $sDirname = substr($sDBurl, 0, $iPos);
                $sFilename = substr($sDBurl, $iPos + 1);
                // Check categorys
                $sql = "SELECT iddbfs FROM " . $cfg['tab']['dbfs'] . " WHERE dirname IN('" . $sDirname . "', '" . html_entity_decode($sDirname) . "', '" . urldecode($sDirname) . "') AND filename = '" . $sFilename . "'";
                $db->query($sql);
                if ($db->num_rows() == 0) {
                    $aErrors['docimages'][] = array_merge($aSearchIDInfosNonID[$i], array("error_type" => "dbfs"));
                }
            } else {
                if (!file_exists($cfgClient[$client]['path']['frontend'] . $aSearchIDInfosNonID[$i]['url'])) {
                    if (url_is_image($aSearchIDInfosNonID[$i]['url'])) {
                        $aErrors['docimages'][] = array_merge($aSearchIDInfosNonID[$i], array("error_type" => "unknown"));
                    } else {
                        $aErrors['others'][] = array_merge($aSearchIDInfosNonID[$i], array("error_type" => "unknown"));
                    }
                }
            }
        }
    }
    return $aErrors;
}
 /**
  * Overriden store function to send mails 
  * @param none
  */
 function store()
 {
     global $cfg, $encoding, $lang;
     $sMailhost = getSystemProperty('system', 'mail_host');
     if ($sMailhost == '') {
         $sMailhost = 'localhost';
     }
     //modified : 2008-06-25 - use php mailer class instead of mail()
     $oMail = new PHPMailer();
     $oMail->CharSet = isset($encoding[$lang]) ? $encoding[$lang] : 'UTF-8';
     $oMail->Host = $sMailhost;
     $oMail->IsHTML(0);
     $oMail->WordWrap = 1000;
     $oMail->IsMail();
     if (array_key_exists("idusersequence", $this->modifiedValues)) {
         $usersequence = new WorkflowUserSequence();
         $usersequence->loadByPrimaryKey($this->values["idusersequence"]);
         $email = $usersequence->get("emailnoti");
         $escal = $usersequence->get("escalationnoti");
         if ($email == 1 || $escal == 1) {
             /* Grab the required informations */
             $curEditor = getGroupOrUserName($usersequence->get("iduser"));
             $idartlang = $this->get("idartlang");
             $timeunit = $usersequence->get("timeunit");
             $timelimit = $usersequence->get("timelimit");
             $db = new DB_Contenido();
             $sql = "SELECT author, title, idart FROM " . $cfg["tab"]["art_lang"] . " WHERE idartlang = '" . Contenido_Security::escapeDB($idartlang, $db) . "'";
             $db->query($sql);
             if ($db->next_record()) {
                 $idart = $db->f("idart");
                 $title = $db->f("title");
                 $author = $db->f("author");
             }
             /* Extract category */
             $sql = "SELECT idcat FROM " . $cfg["tab"]["cat_art"] . " WHERE idart = '" . Contenido_Security::escapeDB($idart, $db) . "'";
             $db->query($sql);
             if ($db->next_record()) {
                 $idcat = $db->f("idcat");
             }
             $sql = "SELECT name FROM " . $cfg["tab"]["cat_lang"] . " WHERE idcat = '" . Contenido_Security::escapeDB($idcat, $db) . "'";
             $db->query($sql);
             if ($db->next_record()) {
                 $catname = $db->f("name");
             }
             $starttime = $this->get("starttime");
             $starttime = strtotime(substr_replace(substr(substr($starttime, 0, 2) . chunk_split(substr($starttime, 2, 6), 2, "-") . chunk_split(substr($starttime, 8), 2, ":"), 0, 19), " ", 10, 1));
             switch ($timeunit) {
                 case "Seconds":
                     $maxtime = $starttime + $timelimit;
                     break;
                 case "Minutes":
                     $maxtime = $starttime + $timelimit * 60;
                     break;
                 case "Hours":
                     $maxtime = $starttime + $timelimit * 3600;
                     break;
                 case "Days":
                     $maxtime = $starttime + $timelimit * 86400;
                     break;
                 case "Weeks":
                     $maxtime = $starttime + $timelimit * 604800;
                     break;
                 case "Months":
                     $maxtime = $starttime + $timelimit * 2678400;
                     break;
                 case "Years":
                     $maxtime = $starttime + $timelimit * 31536000;
                     break;
                 default:
                     $maxtime = $starttime + $timelimit;
             }
             if ($email == 1) {
                 $email = i18n("Hello %s,\n\n" . "you are assigned as the next editor for the Article %s.\n\n" . "More informations:\n" . "Article: %s\n" . "Category: %s\n" . "Editor: %s\n" . "Author: %s\n" . "Editable from: %s\n" . "Editable to: %s\n");
                 $filledMail = sprintf($email, $curEditor, $title, $title, $catname, $curEditor, $author, date("Y-m-d H:i:s", $starttime), date("Y-m-d H:i:s", $maxtime));
                 $user = new User();
                 if (isGroup($usersequence->get("iduser"))) {
                     $sql = "select idgroupuser, user_id FROM " . $cfg["tab"]["groupmembers"] . " WHERE\n            \t\t\t\t\t\tgroup_id = '" . Contenido_Security::escapeDB($usersequence->get("iduser"), $db) . "'";
                     $db->query($sql);
                     while ($db->next_record()) {
                         $user->loadUserByUserID($db->f("user_id"));
                         //modified : 2008-06-25 - use php mailer class instead of mail()
                         $oMail->AddAddress($user->getField("email"), "");
                         $oMail->Subject = stripslashes(i18n('Workflow notification', "workflow"));
                         $oMail->Body = $filledMail;
                         $oMail->Send();
                     }
                 } else {
                     $user->loadUserByUserID($usersequence->get("iduser"));
                     //modified : 2008-06-25 - use php mailer class instead of mail()
                     $oMail->AddAddress($user->getField("email"), "");
                     $oMail->Subject = stripslashes(i18n('Workflow notification', "workflow"));
                     $oMail->Body = $filledMail;
                     $oMail->Send();
                 }
             } else {
                 $email = "Hello %s,\n\n" . "you are assigned as the escalator for the Article %s.\n\n" . "More informations:\n" . "Article: %s\n" . "Category: %s\n" . "Editor: %s\n" . "Author: %s\n" . "Editable from: %s\n" . "Editable to: %s\n";
                 $filledMail = sprintf($email, $curEditor, $title, $title, $catname, $curEditor, $author, date("Y-m-d H:i:s", $starttime), date("Y-m-d H:i:s", $maxtime));
                 $user = new User();
                 if (isGroup($usersequence->get("iduser"))) {
                     $sql = "select idgroupuser, user_id FROM " . $cfg["tab"]["groupmembers"] . " WHERE\n            \t\t\t\t\t\tgroup_id = '" . Contenido_Security::escapeDB($usersequence->get("iduser"), $db) . "'";
                     $db->query($sql);
                     while ($db->next_record()) {
                         $user->loadUserByUserID($db->f("user_id"));
                         echo "mail to " . $user->getField("email") . "<br>";
                         //modified : 2008-06-25 - use php mailer class instead of mail()
                         $oMail->AddAddress($user->getField("email"), "");
                         $oMail->Subject = stripslashes(i18n('Workflow escalation', "workflow"));
                         $oMail->Body = $filledMail;
                         $oMail->Send();
                     }
                 } else {
                     $user->loadUserByUserID($usersequence->get("iduser"));
                     echo "mail to " . $user->getField("email") . "<br>";
                     //modified : 2008-06-25 - use php mailer class instead of mail()
                     $oMail->AddAddress($user->getField("email"), "");
                     $oMail->Subject = stripslashes(i18n('Workflow escalation', "workflow"));
                     $oMail->Body = $filledMail;
                     $oMail->Send();
                 }
             }
         }
     }
     return parent::store();
 }
 public function deleteJob($idnewsjob)
 {
     $idnewsjob = Contenido_Security::toInteger($idnewsjob);
     $this->setWhere("idnewsjob", $idnewsjob);
     $this->query();
     while ($oItem = $this->next()) {
         $this->delete($oItem->get($oItem->primaryKey));
     }
     return true;
 }
 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;
         }
// HTML Newsletter: Template and newsletter category
// Note, that in PHP 5 it is not possible to have a truely working copy of an object
// so, we are filling two almost identical objects with the same data ("clone" may work, but is not available in PHP4 ...)
$oSelHTMLTemplateIDCat = new cHTMLSelectElement("selHTMLTemplateCat");
$oSelHTMLTemplateIDCat->setStyle("width: 220px;");
$oSelHTMLNewsletterIDCat = new cHTMLSelectElement("selHTMLNewsletterCat");
$oSelHTMLNewsletterIDCat->setStyle("width: 220px;");
$oOptionTemplate = new cHTMLOptionElement("--" . i18n("Please select", $plugin_name) . "--", 0);
$oSelHTMLTemplateIDCat->addOptionElement(0, $oOptionTemplate);
$oOptionNewsletter = new cHTMLOptionElement("--" . i18n("Please select", $plugin_name) . "--", 0);
$oSelHTMLNewsletterIDCat->addOptionElement(0, $oOptionNewsletter);
$sSQL = "SELECT tblCat.idcat AS idcat, tblCatLang.name AS name, tblCatTree.level AS level, ";
$sSQL .= "tblCatLang.visible AS visible, tblCatLang.public AS public FROM ";
$sSQL .= $cfg["tab"]["cat"] . " AS tblCat, " . $cfg["tab"]["cat_lang"] . " AS tblCatLang, ";
$sSQL .= $cfg["tab"]["cat_tree"] . " AS tblCatTree ";
$sSQL .= "WHERE tblCat.idclient = '" . Contenido_Security::toInteger($client) . "' AND tblCatLang.idlang = '" . Contenido_Security::toInteger($lang) . "' AND ";
$sSQL .= "tblCatLang.idcat = tblCat.idcat AND tblCatTree.idcat = tblCat.idcat ";
$sSQL .= "ORDER BY tblCatTree.idtree";
$oDB->query($sSQL);
while ($oDB->next_record()) {
    $sSpaces = "&nbsp;&nbsp;";
    for ($i = 0; $i < $oDB->f("level"); $i++) {
        $sSpaces .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    }
    $oOptionTemplate = new cHTMLOptionElement($sSpaces . $oDB->f("name"), $oDB->f("idcat"));
    $oOptionNewsletter = new cHTMLOptionElement($sSpaces . $oDB->f("name"), $oDB->f("idcat"));
    if ($oDB->f("visible") == 0 || $oDB->f("public") == 0) {
        $oOptionTemplate->setStyle("color: #666666;");
        $oOptionNewsletter->setStyle("color: #666666;");
    }
    $oSelHTMLTemplateIDCat->addOptionElement($oDB->f("idcat"), $oOptionTemplate);
// check requests
Contenido_Security::checkRequests();
cInclude("includes", "functions.pathresolver.php");
function str_replace_recursive($array)
{
    if (!is_array($array)) {
        return false;
    }
    $result = array();
    foreach ($array as $value) {
        $result[] = str_replace("e", "", $value);
    }
    return $result;
}
// fetch idartlang for idart
$sql = "SELECT idartlang FROM " . $cfg['tab']['art_lang'] . " WHERE idart=" . Contenido_Security::toInteger($idart) . " AND idlang=" . Contenido_Security::toInteger($lang);
$db->query($sql);
$db->next_record();
$this_idartlang = $db->f('idartlang');
$oPage = new cPage();
$oPage->setMargin(10);
$oTree = new pApiContentAllocationComplexList('06bd456d-fe76-40cb-b041-b9ba90dc400a');
$oAlloc = new pApiContentAllocation();
if ($_POST['action'] == 'storeallocation') {
    $oAlloc->storeAllocations($this_idartlang, $_POST['allocation']);
}
if ($_GET['step'] == 'collapse') {
    $oTree->setTreeStatus($_GET['idpica_alloc']);
}
#build category path
$catString = '';
 /**
  * Deletes all corresponding informations to this workflow and delegate call to parent
  * @param integer $idWorkflow - id of workflow to delete
  */
 function delete($idWorkflow)
 {
     global $cfg;
     $oDb = new DB_Contenido();
     $aItemIdsDelete = array();
     $sSql = 'SELECT idworkflowitem FROM ' . $cfg["tab"]["workflow_items"] . ' WHERE idworkflow = ' . Contenido_Security::toInteger($idWorkflow) . ';';
     $oDb->query($sSql);
     while ($oDb->next_record()) {
         array_push($aItemIdsDelete, Contenido_Security::escapeDB($oDb->f('idworkflowitem'), $oDb));
     }
     $aUserSequencesDelete = array();
     $sSql = 'SELECT idusersequence FROM ' . $cfg["tab"]["workflow_user_sequences"] . ' WHERE idworkflowitem in (' . implode(',', $aItemIdsDelete) . ');';
     $oDb->query($sSql);
     while ($oDb->next_record()) {
         array_push($aUserSequencesDelete, Contenido_Security::escapeDB($oDb->f('idusersequence'), $oDb));
     }
     $sSql = 'DELETE FROM ' . $cfg["tab"]["workflow_user_sequences"] . ' WHERE idworkflowitem in (' . implode(',', $aItemIdsDelete) . ');';
     $oDb->query($sSql);
     $sSql = 'DELETE FROM ' . $cfg["tab"]["workflow_actions"] . ' WHERE idworkflowitem in (' . implode(',', $aItemIdsDelete) . ');';
     $oDb->query($sSql);
     $sSql = 'DELETE FROM ' . $cfg["tab"]["workflow_items"] . ' WHERE idworkflow = ' . Contenido_Security::toInteger($idWorkflow) . ';';
     $oDb->query($sSql);
     $sSql = 'DELETE FROM ' . $cfg["tab"]["workflow_allocation"] . ' WHERE idworkflow = ' . Contenido_Security::toInteger($idWorkflow) . ';';
     $oDb->query($sSql);
     $sSql = 'DELETE FROM ' . $cfg["tab"]["workflow_art_allocation"] . ' WHERE idusersequence in (' . implode(',', $aUserSequencesDelete) . ');';
     $oDb->query($sSql);
     parent::delete($idWorkflow);
 }
$tpl->set('s', 'TH_TEMPLATE', i18n("Template"));
$tpl->set('s', 'TH_ACTIONS', i18n("Actions"));
$tpl->set('s', 'TH_TITLE', i18n("Title"));
$tpl->set('s', 'TH_CHANGED', i18n("Changed"));
$tpl->set('s', 'TH_PUBLISHED', i18n("Published"));
$tpl->set('s', 'TH_WORKFLOW_STEP', i18n("Workflow Step", 'workflow'));
$tpl->set('s', 'TH_WORKFLOW_ACTION', i18n("Workflow Action", 'workflow'));
$tpl->set('s', 'TH_WORKFLOW_EDITOR', i18n("Workflow Editor", 'workflow'));
$tpl->set('s', 'TH_LAST_STATUS', i18n("Last status", 'workflow'));
$currentUserSequence = new WorkflowUserSequence();
if (is_array($isCurrent)) {
    foreach ($isCurrent as $key => $value) {
        if ($value == true) {
            $idartlang = Contenido_Security::toInteger($article[$key]);
            $lang = Contenido_Security::toInteger($lang);
            $client = Contenido_Security::toInteger($client);
            $sql = "SELECT B.idcat AS idcat, A.title AS title, A.created AS created, A.lastmodified AS changed, \n                       A.idart as idart, E.name as tpl_name, A.idartlang as idartlang, F.idcatlang as idcatlang,\n                       B.idcatart as idcatart, A.idlang as art_lang, F.startidartlang as startidartlang\n    \t\t\tFROM (" . $cfg["tab"]["art_lang"] . " AS A,\n                     " . $cfg["tab"]["cat_art"] . " AS B,\n \t\t\t\t\t " . $cfg["tab"]["art"] . " AS C)\n                      LEFT JOIN " . $cfg['tab']['tpl_conf'] . " as D ON A.idtplcfg = D.idtplcfg\n                      LEFT JOIN " . $cfg['tab']['tpl'] . " as E ON D.idtpl = E.`idtpl`\n                      LEFT JOIN " . $cfg['tab']['cat_lang'] . " as F ON B.idcat = F.`idcat`\n\t\t\t\t\t WHERE A.idartlang = '{$idartlang}' AND\n\t\t\t\t\t\t   A.idart = B.idart AND\n\t\t\t\t\t\t   A.idart = C.idart AND\n\t\t\t\t\t\t   A.idlang = '{$lang}' AND\n \t\t\t\t\t\t   C.idclient = '{$client}';";
            $db->query($sql);
            if ($db->next_record()) {
                global $area;
                //$area = "con";
                $idcat = $db->f("idcat");
                $idart = $db->f("idart");
                # create javascript multilink
                $tmp_mstr = '<a href="javascript://" onclick="javascript:conMultiLink(\'%s\', \'%s\', \'%s\', \'%s\')"  title="idart: ' . $db->f('idart') . ' idcatart: ' . $db->f('idcatart') . '" alt="idart: ' . $db->f('idart') . ' idcatart: ' . $db->f('idcatart') . '">%s</a>';
                $mstr = sprintf($tmp_mstr, 'right_top', $sess->url("main.php?area=con&frame=3&idcat={$idcat}&idtpl={$idtpl}"), 'right_bottom', $sess->url("main.php?area=con_editart&action=con_edit&frame=4&idcat={$idcat}&idtpl={$idtpl}&idart={$idart}"), $db->f("title"));
                $laststatus = getLastWorkflowStatus($idartlang);
                $username = getGroupOrUserName($userids[$key]);
                $actionSelect = piworkflowRenderColumn($idcat, $idart, $db->f('idartlang'), 'wfaction');
                $currentUserSequence->loadByPrimaryKey($usersequence[$key]);
                $workflowItem = $currentUserSequence->getWorkflowItem();