* @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 2003-03-28
* modified 2008-06-27, Dominik Ziegler, add security fix
* modified 2009-10-14, Dominik Ziegler - added some functionality for "cancel moving tree"
* modified 2009-10-15, Dominik Ziegler - removed unnecessary database query for selecting the level (level is already available)
* modified 2010-01-30, Ingo van Peeren, some optimization of the amount of db queries for template names and descriptions, see [CON-301]
* removed use of deprecated methods of class.template.php, see [CON-302]
* modified 2010-02-06, Ingo van Peeren, fixed small bug added by last modification
*
* $Id$:
* }}
*
*/
if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
$debug = FALSE;
$tmp_area = "str";
if ($action == "str_duplicate" &&
($perm->have_perm_area_action("str", "str_duplicate") ||
$perm->have_perm_area_action_item("str", "str_duplicate", $idcat))) {
strCopyTree($idcat, $parentid);
}
//Everybody is allowed to update aliases, if there is no Permission to update category names, this block updates category alias only
if (isset($_POST['newcategoryalias']) && isset($_POST['action']) && $_POST['action'] == 'str_renamecat') {
$iIdCat = (int) $_POST['idcat'];
if (!($perm->have_perm_area_action($tmp_area, "str_renamecat") || $perm->have_perm_area_action_item($tmp_area, "str_renamecat", $iIdCat))) {
if (trim($_POST['newcategoryalias']) != '') {
$sUrlName = capiStrCleanURLCharacters($_POST['newcategoryalias']);
$sql = "UPDATE {$cfg['tab']['cat_lang']} SET urlname = '" . Contenido_Security::escapeDB($sUrlName, $db) . "' WHERE idcat = '" . Contenido_Security::toInteger($iIdCat) . "' AND idlang = '" . Contenido_Security::toInteger($lang) . "'";
$db->query($sql);
} else {
//Use categoryname as default -> get it escape it save it as urlname
$sql = "SELECT name from {$cfg['tab']['cat_lang']} WHERE idcat = '" . Contenido_Security::toInteger($iIdCat) . "' AND idlang = '" . Contenido_Security::toInteger($lang) . "'";
$db->query($sql);
if ($db->next_record()) {
$sUrlName = capiStrCleanURLCharacters($db->f('name'));
$sql = "UPDATE {$cfg['tab']['cat_lang']} SET urlname = '" . $sUrlName . "' WHERE idcat = '" . Contenido_Security::toInteger($iIdCat) . "' AND idlang = '" . Contenido_Security::toInteger($lang) . "'";
$db->query($sql);
$lang = Contenido_Security::escapeDB($lang, null);
@unlink($cfgClient[$client]["path"]["frontend"] . "cache/locationstring-url-cache-$lang.txt");
}
}
}
}
$oDirectionDb = new DB_ConLite();
/**
* Build a Category select Box containg all categories which user is allowed to create new categories
*
* @return String HTML
*/
function buildCategorySelectRights() {
global $cfg, $client, $lang, $idcat, $perm, $tmp_area;
$db = new DB_ConLite();
$oHtmlSelect = new cHTMLSelectElement('idcat', "", "new_idcat");
$oHtmlSelectOption = new cHTMLOptionElement(i18n("Please choose"), '', true);
$oHtmlSelect->addOptionElement(0, $oHtmlSelectOption);
$sql = "SELECT a.idcat AS idcat, b.name AS name, c.level FROM
" . $cfg["tab"]["cat"] . " AS a, " . $cfg["tab"]["cat_lang"] . " AS b,
" . $cfg["tab"]["cat_tree"] . " AS c WHERE a.idclient = '" . Contenido_Security::toInteger($client) . "'
AND b.idlang = '" . Contenido_Security::toInteger($lang) . "' AND b.idcat = a.idcat AND c.idcat = a.idcat
ORDER BY c.idtree";
$db->query($sql);
$categories = array();
while ($db->next_record()) {
$categories[$db->f("idcat")]["name"] = $db->f("name");
$categories[$db->f("idcat")]["idcat"] = $db->f("idcat");
if ($perm->have_perm_area_action($tmp_area, "str_newcat") || $perm->have_perm_area_action_item($tmp_area, "str_newcat", $db->f("idcat"))) {
$categories[$db->f("idcat")]["perm"] = 1;
} else {
$categories[$db->f("idcat")]["perm"] = 0;
}
$categories[$db->f("idcat")]["level"] = $db->f("level");
}
$aCategoriesReversed = array_reverse($categories);
$iLevel = 0;
foreach ($aCategoriesReversed as $iKeyIdCat => $aValues) {
if ($aValues['level'] > $iLevel && $aValues['perm']) {
$iLevel = $aValues['level'];
} else if ($aValues['level'] < $iLevel) {
$iLevel = $aValues['level'];
} else {
if (!$aValues['perm']) {
unset($categories[$aValues["idcat"]]);
}
}
}
$j = 1;
foreach ($categories as $tmpidcat => $props) {
$spaces = " ";
for ($i = 0; $i < $props["level"]; $i ++) {
$spaces .= " ";
}
$sCategoryname = clHtmlSpecialChars($props["name"]);
$sCategoryname = capiStrTrimHard($sCategoryname, 30);
$oHtmlSelectOption = new cHTMLOptionElement($spaces . ">" . $sCategoryname, $tmpidcat, false, !$props["perm"]);
$oHtmlSelect->addOptionElement($j, $oHtmlSelectOption);
$j++;
}
return $oHtmlSelect->toHtml();
}
function getExpandCollapseButton($item, $catName) {
global $sess, $PHP_SELF, $frame, $area;
$selflink = "main.php";
$img = new cHTMLImage;
$img->updateAttributes(array("style" => "padding:4px;"));
if (count($item->subitems) > 0) {
if ($item->collapsed == true) {
$expandlink = $sess->url($selflink . "?area=$area&frame=$frame&expand=" . $item->id);
$img->setSrc($item->collapsed_icon);
$img->setAlt(i18n("Open category"));
return ('' . $img->render() . ' ' . '' . $catName . '');
} else {
$collapselink = $sess->url($selflink . "?area=$area&frame=$frame&collapse=" . $item->id);
$img->setSrc($item->expanded_icon);
$img->setAlt(i18n("Close category"));
return('' . $img->render() . ' ' . '' . $catName . '');
}
} else {
return ' ' . $catName;
}
}
function getTemplateSelect() {
global $client, $cfg, $db;
$oHtmlSelect = new cHTMLSelectElement('cat_template_select', "", "cat_template_select");
$oHtmlSelectOption = new cHTMLOptionElement('--- ' . i18n("none") . ' ---', 0, false);
$oHtmlSelect->addOptionElement(0, $oHtmlSelectOption);
$sql = "SELECT
idtpl,
name, defaulttemplate
FROM
" . $cfg['tab']['tpl'] . "
WHERE
idclient = '" . $client . "'
ORDER BY
name";
$i = 1;
if ($db->query($sql)) {
while ($db->next_record()) {
$bDefaultTemplate = $db->f('defaulttemplate');
$oHtmlSelectOption = new cHTMLOptionElement($db->f('name'), $db->f('idtpl'), $bDefaultTemplate);
$oHtmlSelect->addOptionElement($i, $oHtmlSelectOption);
$i++;
}
}
return $oHtmlSelect->toHtml();
}
getTemplateSelect();
$sess->register("remakeStrTable");
$sess->register("StrTableClient");
$sess->register("StrTableLang");
$cancel = $sess->url("main.php?area=$area&frame=$frame");
if (isset($force) && $force == 1) {
$remakeStrTable = true;
}
if ($StrTableClient != $client) {
unset($expandedList);
$remakeStrTable = true;
}
if ($StrTableLang != $lang) {
unset($expandedList);
$remakeStrTable = true;
}
$StrTableClient = $client;
$StrTableLang = $lang;
if (!isset($idcat))
$idcat = 0;
if (!isset($action))
$action = 0;
/*
function buildTree(&$rootItem, &$items) {
global $nextItem, $perm, $tmp_area;
while ($item_list = each($items)) {
list($key, $item) = $item_list;
unset($newItem);
$bCheck = false;
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, "str_newtree");
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, "str_newcat");
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, "str_makevisible");
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, "str_makepublic");
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, "str_deletecat");
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, "str_moveupcat");
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, "str_movedowncat");
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, "str_movesubtree");
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, "str_renamecat");
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action("str_tplcfg", "str_tplcfg");
}
if (!$bCheck) {
$bCheck = $perm->have_perm_item($tmp_area, $item['idcat']);
}
if ($bCheck) {
$newItem = new TreeItem($item['name'], $item['idcat'], true);
} else {
$newItem = new TreeItem($item['name'], $item['idcat'], false);
}
$newItem->collapsed_icon = 'images/open_all.gif';
$newItem->expanded_icon = 'images/close_all.gif';
$newItem->custom['idtree'] = $item['idtree'];
$newItem->custom['level'] = $item['level'];
$newItem->custom['idcat'] = $item['idcat'];
$newItem->custom['idtree'] = $item['idtree'];
$newItem->custom['parentid'] = $item['parentid'];
$newItem->custom['alias'] = $item['alias'];
$newItem->custom['preid'] = $item['preid'];
$newItem->custom['postid'] = $item['postid'];
$newItem->custom['visible'] = $item['visible'];
$newItem->custom['idtplcfg'] = $item['idtplcfg'];
$newItem->custom['public'] = $item['public'];
if ($perm->have_perm_item("str", $item['idcat'])) {
$newItem->custom['forcedisplay'] = 1;
}
if (array_key_exists($key + 1, $items)) {
$nextItem = $items[$key + 1];
} else {
$nextItem = 0;
}
if (array_key_exists($key - 1, $items)) {
$lastItem = $items[$key - 1];
} else {
$lastItem = 0;
}
$rootItem->addItem($newItem);
if ($nextItem['level'] > $item['level']) {
$oldRoot = $rootItem;
buildTree($newItem, $items);
$rootItem = $oldRoot;
}
if ($nextItem['level'] < $item['level']) {
return;
}
}
}
*
*/
function buildTree(&$rootItem, $itemsIterator) {
global $nextItem, $perm, $tmp_area;
while ($itemsIterator->valid()) {
$key = $itemsIterator->key();
$item = $itemsIterator->current();
$itemsIterator->next();
unset($newItem);
$bCheck = false;
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, 'str_newtree');
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, 'str_newcat');
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, 'str_makevisible');
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, 'str_makepublic');
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, 'str_deletecat');
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, 'str_moveupcat');
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, 'str_movedowncat');
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, 'str_movesubtree');
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action($tmp_area, 'str_renamecat');
}
if (!$bCheck) {
$bCheck = $perm->have_perm_area_action('str_tplcfg', 'str_tplcfg');
}
if (!$bCheck) {
$bCheck = $perm->have_perm_item($tmp_area, $item['idcat']);
}
if ($bCheck) {
$newItem = new TreeItem($item['name'], $item['idcat'], true);
} else {
$newItem = new TreeItem($item['name'], $item['idcat'], false);
}
$newItem->setCollapsedIcon('images/open_all.gif');
$newItem->setExpandedIcon('images/close_all.gif');
$newItem->setCustom('idtree', $item['idtree']);
$newItem->setCustom('level', $item['level']);
$newItem->setCustom('idcat', $item['idcat']);
$newItem->setCustom('idtree', $item['idtree']);
$newItem->setCustom('parentid', $item['parentid']);
$newItem->setCustom('alias', $item['alias']);
$newItem->setCustom('preid', $item['preid']);
$newItem->setCustom('postid', $item['postid']);
$newItem->setCustom('visible', $item['visible']);
$newItem->setCustom('idtplcfg', $item['idtplcfg']);
$newItem->setCustom('public', $item['public']);
if ($perm->have_perm_item('str', $item['idcat'])) {
$newItem->setCustom('forcedisplay', 1);
}
if ($itemsIterator->offsetExists($key + 1)) {
$nextItem = $itemsIterator->offsetGet($key + 1);
} else {
$nextItem = 0;
}
$rootItem->addItem($newItem);
if ($nextItem['level'] > $item['level']) {
$oldRoot = $rootItem;
buildTree($newItem, $itemsIterator);
$rootItem = $oldRoot;
}
if ($nextItem['level'] < $item['level']) {
return;
}
}
}
if ($perm->have_perm_area_action($area)) {
$sql = "SELECT
idtree, A.idcat, level, name, parentid, preid, postid, visible, public, idtplcfg, C.urlname as alias
FROM
" . $cfg["tab"]["cat_tree"] . " AS A,
" . $cfg["tab"]["cat"] . " AS B,
" . $cfg["tab"]["cat_lang"] . " AS C
WHERE
A.idcat = B.idcat AND
B.idcat = C.idcat AND
C.idlang = '" . Contenido_Security::toInteger($lang) . "' AND
B.idclient = '" . Contenido_Security::toInteger($client) . "'
ORDER BY
idtree";
# Debug info
if ($debug) {
echo "
"; echo $sql; echo ""; } $db->query($sql); $bIgnore = false; $iIgnoreLevel = 0; $items = array(); while ($db->next_record()) { $bSkip = false; if ($bIgnore == true && $iIgnoreLevel >= $db->f("level")) { $bIgnore = false; } if ($db->f("idcat") == $movesubtreeidcat) { $bIgnore = true; $iIgnoreLevel = $db->f("level"); $sMoveSubtreeCatName = $db->f("name"); } if ($iCurLevel == $db->f("level")) { if ($iCurParent != $db->f("parentid")) { $bSkip = true; } } else { $iCurLevel = $db->f("level"); $iCurParent = $db->f("parentid"); } if ($bIgnore == false && $bSkip == false) { $entry = array(); $entry['idtree'] = $db->f("idtree"); $entry['idcat'] = $db->f("idcat"); $entry['level'] = $db->f("level"); $entry['name'] = htmldecode($db->f("name")); $entry['alias'] = htmldecode($db->f("alias")); $entry['parentid'] = $db->f("parentid"); $entry['preid'] = $db->f("preid"); $entry['postid'] = $db->f("postid"); $entry['visible'] = $db->f("visible"); $entry['public'] = $db->f("public"); $entry['idtplcfg'] = $db->f("idtplcfg"); array_push($items, $entry); } } $rootStrItem = new TreeItem("root", -1); $rootStrItem->collapsed_icon = 'images/open_all.gif'; $rootStrItem->expanded_icon = 'images/close_all.gif'; $arrayObj = new ArrayObject($items); buildTree($rootStrItem, $arrayObj->getIterator()); $expandedList = unserialize($currentuser->getUserProperty("system", "cat_expandstate")); if (is_array($expandedList)) { $rootStrItem->markExpanded($expandedList); } if (isset($collapse) && is_numeric($collapse)) { $rootStrItem->markCollapsed($collapse); } if (isset($expand) && is_numeric($expand)) { $rootStrItem->markExpanded($expand); } if (isset($expand) && $expand == "all") { $rootStrItem->expandAll(-1); } if (isset($collapse) && $collapse == "all") { $rootStrItem->collapseAll(-1); } if ($action === "str_newcat") { $rootStrItem->markExpanded($idcat); } $expandedList = Array(); $objects = array(); $rootStrItem->traverse($objects); $rootStrItem->getExpandedList($expandedList); $currentuser->setUserProperty("system", "cat_expandstate", serialize($expandedList)); # Reset Template $tpl->reset(); $tpl->set('s', 'SID', $sess->id); $tpl->set('s', 'AREA', $area); $tpl->set('s', 'FRAME', $frame); $_cecIterator = $_cecRegistry->getIterator("Contenido.CategoryList.Columns"); $listColumns = array(); if ($_cecIterator->count() > 0) { while ($chainEntry = $_cecIterator->next()) { $tmplistColumns = $chainEntry->execute(array()); if (is_array($tmplistColumns)) { $listColumns = array_merge($listColumns, $tmplistColumns); } } foreach ($listColumns as $content) { // Header for additional columns $additionalheaders[] = '