* @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 2002-03-02
* modified 2008-06-26, Frederic Schneider, add security fix
* modified 2008-08-29, Murat Purc, add new chain execution
* modified 2008-09-03, Hotfix recursive call more than 200 times exit script on hosteurope Timo.Trautmann (strRemakeTreeTableFindNext)
* modified 2008-10-29, delete from cat_tree only for one Cliente OliverL (strRemakeTreeTable)
* modified 2008-11-03, Add cat_tree only for one Cliente OliverL (strRemakeTreeTable)
* modified 2009-05-05, Timo Trautmann - optional use for copy label on copy proccess
* modified 2009-10-14, Dominik Ziegler - changed functionality of strMoveSubtree and strMoveCatTargetallowed to prevent crashing tree on moving
* modified 2009-10-23, Murat Purc, removed deprecated function (PHP 5.3 ready), commenting code and some formatting
* modified 2009-10-27, Murat Purc, fixed/modified CEC_Hook, see [#CON-256]
* modified 2010-01-30, Ingo van Peeren, modified strRemakeTreeTable() to pass only one INSERT statement to the database, see [#CON-299]
* modified 2010-03-12, Ingo van Peeren, fixed a bug with last change if more than one client exist [#CON-299]
* modified 2010-06-18, Ingo van Peeren, fixed some issues with next id and order of con_cat_tree entries
* modified 2010-09-17, Ingo van Peeren, fixed some issues wrong level information causing garbled tree [#CON-348]
* modified 2010-10-13, Dominik Ziegler, No copy label per default when copying articles or categories (CON-352)
*
* $Id$:
* }}
*
*/
if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
/* * *******************************************************************************
Functions
strNewTree($catname)
strNewCategory($tmp_parentid, $catname)
strOrderedPostTreeList ($idcat, $poststring)
strRemakeTreeTable()
strNextDeeper($tmp_idcat)
strNextPost($tmp_idcat)
strNextBackwards($tmp_idcat)
strRemakeTreeTableFindNext($tmp_idcat,$tmp_level)
strShowTreeTable()
strRenameCategory ($idcat, $lang, $newcategoryname)
strMakeVisible ($idcat, $lang, $visible)
strMakePublic ($idcat, $lang, $public)
strDeleteCategory ($idcat)
strMoveUpCategory ($idcat)
strMoveDownCategory ($idcat)
strMoveSubtree ($idcat, $parentid_new)
strMoveCatTargetallowed($idcat, $source)
* ****************************************************************************** */
cInclude("includes", "functions.con.php");
cInclude("includes", "functions.database.php");
global $db_str;
global $db_str2;
if (class_exists("DB_ConLite")) {
$db_str = new DB_ConLite();
$db_str2 = new DB_ConLite();
}
/**
* Creates a new category tree (root category item).
*
* @param string $catname The category name
* @param string $catalias Alias of category
* @param bool $bVisible Flag about visible status
* @param bool $bPublic Flag about public status
* @param int $iIdtplcfg Id of template configuration
* @return (int|void) Id of new generated category or nothing on failure
*/
function strNewTree($catname, $catalias = '', $bVisible = 0, $bPublic = 1, $iIdtplcfg = 0) {
global $db;
global $client;
global $lang;
global $cfg;
global $area_tree;
global $sess;
global $perm;
global $area_rights;
global $item_rights;
global $_SESSION;
// Flag to rebuild the category table
global $remakeCatTable;
global $remakeStrTable;
global $auth;
$remakeCatTable = true;
$remakeStrTable = true;
$db2 = new DB_ConLite;
if (trim($catname) == "") {
return;
}
$catalias = trim($catalias);
if ($catalias == "") {
$catalias = trim($catname);
}
$tmp_newid = $db->nextid($cfg["tab"]["cat"]);
if ($tmp_newid == 0) {
return;
}
if ($perm->have_perm_area_action("str_tplcfg", "str_tplcfg")) {
$iIdtplcfg = (int) $iIdtplcfg;
} else {
$iIdtplcfg = 0;
}
$bVisible = (int) $bVisible;
if (!(($bVisible == 0 || $bVisible == 1) && $perm->have_perm_area_action('str', "str_makevisible"))) {
$bVisible = 0;
}
$bPublic = (int) $bPublic;
if (!(($bPublic == 0 || $bPublic == 1) && $perm->have_perm_area_action('str', "str_makepublic"))) {
$bPublic = 1;
}
$sql = "SELECT idcat FROM " . $cfg["tab"]["cat"] . " WHERE parentid='0' AND postid='0' AND idclient='" . Contenido_Security::toInteger($client) . "'";
$db->query($sql);
$db->next_record();
$tmp_id = $db->f("idcat");
$a_languages[] = $lang;
if (is_array($a_languages)) {
if (!$tmp_id) {
//********** Entry in 'cat'-table ************
$sql = "INSERT INTO " . $cfg["tab"]["cat"] . " (idcat, preid, postid, idclient, author, created, lastmodified) VALUES('" . Contenido_Security::toInteger($tmp_newid) . "', '0', '0',
'" . Contenido_Security::toInteger($client) . "', '" . Contenido_Security::escapeDB($auth->auth['uname'], $db) . "', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d H:i:s") . "')";
$db->query($sql);
//********* enter name of cat in 'cat_lang'-table ******
foreach ($a_languages as $tmp_lang) {
if ($tmp_lang == $lang) {
$sql = "INSERT INTO " . $cfg["tab"]["cat_lang"] . " (idcatlang, idcat, idlang, name, visible, public, idtplcfg, urlname, author, created, lastmodified)
VALUES('" . Contenido_Security::toInteger($db->nextid($cfg["tab"]["cat_lang"])) . "', '" . Contenido_Security::toInteger($tmp_newid) . "', '" . Contenido_Security::toInteger($tmp_lang) . "',
'" . clHtmlSpecialChars($catname, ENT_QUOTES) . "', '" . Contenido_Security::toInteger($bVisible) . "', '" . Contenido_Security::toInteger($bPublic) . "', '0',
'" . clHtmlSpecialChars(capiStrCleanURLCharacters($catalias), ENT_QUOTES) . "', '" . Contenido_Security::escapeDB($auth->auth['uname'], $db) . "', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d H:i:s") . "')";
$db->query($sql);
} else {
$sql = "INSERT INTO " . $cfg["tab"]["cat_lang"] . " (idcatlang, idcat, idlang, name, visible, public, idtplcfg, urlname, author, created, lastmodified)
VALUES('" . Contenido_Security::toInteger($db->nextid($cfg["tab"]["cat_lang"])) . "', '" . Contenido_Security::toInteger($tmp_newid) . "', '" . Contenido_Security::toInteger($tmp_lang) . "',
'" . clHtmlSpecialChars($catname, ENT_QUOTES) . "', '" . Contenido_Security::toInteger($bVisible) . "', '" . Contenido_Security::toInteger($bPublic) . "', '0',
'" . clHtmlSpecialChars(capiStrCleanURLCharacters($catalias), ENT_QUOTES) . "', '" . Contenido_Security::escapeDB($auth->auth['uname'], $db) . "', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d H:i:s") . "')";
$db->query($sql);
}
}
} else {
//********** Entry in 'cat'-table ************
$sql = "UPDATE " . $cfg["tab"]["cat"] . " SET postid='$tmp_newid' WHERE idcat='" . Contenido_Security::toInteger($tmp_id) . "'";
$db->query($sql);
//********** Entry in 'cat'-table ************
$sql = "INSERT INTO " . $cfg["tab"]["cat"] . " (idcat, preid, postid, idclient, author, created, lastmodified) VALUES('" . Contenido_Security::toInteger($tmp_newid) . "', '" . Contenido_Security::toInteger($tmp_id) . "',
'0', '" . Contenido_Security::toInteger($client) . "', '" . Contenido_Security::escapeDB($auth->auth['uname'], $db) . "', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d H:i:s") . "')";
$db->query($sql);
//********* enter name of cat in 'cat_lang'-table ******
foreach ($a_languages as $tmp_lang) {
if ($tmp_lang == $lang) {
$sql = "INSERT INTO " . $cfg["tab"]["cat_lang"] . " (idcatlang, idcat, idlang, name, visible, public, idtplcfg, urlname, author, created, lastmodified)
VALUES('" . Contenido_Security::toInteger($db->nextid($cfg["tab"]["cat_lang"])) . "', '" . Contenido_Security::toInteger($tmp_newid) . "', '" . Contenido_Security::toInteger($tmp_lang) . "',
'" . clHtmlSpecialChars($catname, ENT_QUOTES) . "', '" . Contenido_Security::toInteger($bVisible) . "', '" . Contenido_Security::toInteger($bPublic) . "', '0',
'" . clHtmlSpecialChars(capiStrCleanURLCharacters($catalias), ENT_QUOTES) . "', '" . Contenido_Security::escapeDB($auth->auth['uname'], $db) . "', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d H:i:s") . "')";
$db->query($sql);
} else {
$sql = "INSERT INTO " . $cfg["tab"]["cat_lang"] . " (idcatlang, idcat, idlang, name, visible, public, idtplcfg, urlname, author, created, lastmodified)
VALUES('" . Contenido_Security::toInteger($db->nextid($cfg["tab"]["cat_lang"])) . "', '" . Contenido_Security::toInteger($tmp_newid) . "', '" . Contenido_Security::toInteger($tmp_lang) . "',
'" . clHtmlSpecialChars($catname, ENT_QUOTES) . "', '" . Contenido_Security::toInteger($bVisible) . "', '" . Contenido_Security::toInteger($bPublic) . "', '0',
'" . clHtmlSpecialChars(capiStrCleanURLCharacters($catalias), ENT_QUOTES) . "', '" . Contenido_Security::escapeDB($auth->auth['uname'], $db) . "', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d H:i:s") . "')";
$db->query($sql);
}
}
}
// set correct rights for element
cInclude("includes", "functions.rights.php");
foreach ($a_languages as $tmp_lang) {
createRightsForElement("str", $tmp_newid, $tmp_lang);
createRightsForElement("con", $tmp_newid, $tmp_lang);
}
}
/* Search for default template */
$templateCollection = new cApiTemplateCollection("defaulttemplate = '1' AND idclient = '" . Contenido_Security::toInteger($client) . "'");
if ($template = $templateCollection->next()) {
$idtpl = $template->get("idtpl");
if ($iIdtplcfg > 0) {
$idtpl = $iIdtplcfg;
}
/* Assign template, if default template exists */
$catCollection = new cApiCategoryLanguageCollection("idcat = '" . Contenido_Security::toInteger($tmp_newid) . "'");
while ($cat = $catCollection->next()) {
$cat->assignTemplate($idtpl);
}
} else {
//2008-06-25 timo.trautmann also set default template if it is selcted by user and there is no default template
if ($iIdtplcfg > 0) {
$idtpl = $iIdtplcfg;
$catCollection = new cApiCategoryLanguageCollection("idcat = '$tmp_newid'");
while ($cat = $catCollection->next()) {
$cat->assignTemplate($idtpl);
}
}
}
return ($tmp_newid);
}
/**
* Creates a new category.
*
* @param int $tmp_parentid Id of parent category
* @param string $catname The category name
* @param bool $remakeTree Flag to rebuild category tree structure
* @param string $catalias Alias of category
* @param bool $bVisible Flag about visible status
* @param bool $bPublic Flag about public status
* @param int $iIdtplcfg Id of template configuration
* @return (int|void) Id of new generated category or nothing on failure
*/
function strNewCategory($tmp_parentid, $catname, $remakeTree = true, $catalias = '', $bVisible = 0, $bPublic = 1, $iIdtplcfg = 0) {
global $db;
global $client;
global $lang;
global $cfg;
global $area_tree;
global $perm;
// Flag to rebuild the category table
global $remakeCatTable;
global $remakeStrTable;
global $auth;
global $tmp_area;
$db2 = new DB_ConLite;
if (trim($catname) == "") {
return;
}
$catalias = trim($catalias);
if ($catalias == "") {
$catalias = trim($catname);
}
if ($perm->have_perm_area_action("str_tplcfg", "str_tplcfg")) {
$iIdtplcfg = (int) $iIdtplcfg;
} else {
$iIdtplcfg = 0;
}
$bVisible = (int) $bVisible;
if (!(($bVisible == 0 || $bVisible == 1) && $perm->have_perm_area_action('str', "str_makevisible"))) {
$bVisible = 0;
}
$bPublic = (int) $bPublic;
if (!(($bPublic == 0 || $bPublic == 1) && $perm->have_perm_area_action('str', "str_makepublic"))) {
$bPublic = 1;
}
$tmp_newid = $db->nextid($cfg["tab"]["cat"]);
if ($tmp_newid == 0) {
return;
}
$remakeCatTable = true;
$remakeStrTable = true;
$sql = "SELECT idcat FROM " . $cfg["tab"]["cat"] . " WHERE parentid='" . Contenido_Security::toInteger($tmp_parentid) . "' AND postid=0";
$db->query($sql);
$db->next_record();
$tmp_id = $db->f("idcat");
if (!$tmp_id) {
//********** Entry in 'cat'-table ************
$sql = "INSERT INTO " . $cfg["tab"]["cat"] . " (idcat, parentid, preid, postid, idclient, author, created, lastmodified) VALUES('" . Contenido_Security::toInteger($tmp_newid) . "',
'" . Contenido_Security::toInteger($tmp_parentid) . "', '0', '0', '" . Contenido_Security::toInteger($client) . "', '" . Contenido_Security::escapeDB($auth->auth['uname'], $db) . "',
'" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d H:i:s") . "')";
$db->query($sql);
//********* enter name of cat in 'cat_lang'-table ******
$a_languages[] = $lang;
foreach ($a_languages as $tmp_lang) {
if ($tmp_lang == $lang) {
$sql = "INSERT INTO " . $cfg["tab"]["cat_lang"] . " (idcatlang, idcat, idlang, name, visible, public, idtplcfg, urlname, author, created, lastmodified)
VALUES('" . Contenido_Security::toInteger($db->nextid($cfg["tab"]["cat_lang"])) . "', '" . Contenido_Security::toInteger($tmp_newid) . "', '" . Contenido_Security::toInteger($tmp_lang) . "',
'" . clHtmlSpecialChars($catname, ENT_QUOTES) . "', '" . Contenido_Security::toInteger($bVisible) . "', '" . Contenido_Security::toInteger($bPublic) . "', '0',
'" . clHtmlSpecialChars(capiStrCleanURLCharacters($catalias), ENT_QUOTES) . "', '" . Contenido_Security::escapeDB($auth->auth['uname'], $db) . "', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d H:i:s") . "')";
$db->query($sql);
} else {
$sql = "INSERT INTO " . $cfg["tab"]["cat_lang"] . " (idcatlang, idcat, idlang, name, visible, public, idtplcfg, urlname, author, created, lastmodified)
VALUES('" . Contenido_Security::toInteger($db->nextid($cfg["tab"]["cat_lang"])) . "', '" . Contenido_Security::toInteger($tmp_newid) . "', '" . Contenido_Security::toInteger($tmp_lang) . "',
'" . clHtmlSpecialChars($catname, ENT_QUOTES) . "', '" . Contenido_Security::toInteger($bVisible) . "', '" . Contenido_Security::toInteger($bPublic) . "', '0',
'" . clHtmlSpecialChars(capiStrCleanURLCharacters($catalias), ENT_QUOTES) . "', '" . Contenido_Security::escapeDB($auth->auth['uname'], $db) . "', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d H:i:s") . "')";
$db->query($sql);
}
}
} else {
//********** Entry in 'cat'-table ************
$sql = "UPDATE " . $cfg["tab"]["cat"] . " SET postid='$tmp_newid', lastmodified = '" . date("Y-m-d H:i:s") . "' WHERE idcat='" . Contenido_Security::toInteger($tmp_id) . "'";
$db->query($sql);
//********** Entry in 'cat'-table ************
$sql = "INSERT INTO " . $cfg["tab"]["cat"] . " (idcat, parentid, preid, postid, idclient, author, created, lastmodified) VALUES('" . Contenido_Security::toInteger($tmp_newid) . "',
'" . Contenido_Security::toInteger($tmp_parentid) . "', '" . Contenido_Security::toInteger($tmp_id) . "', '0', '" . Contenido_Security::toInteger($client) . "',
'" . Contenido_Security::escapeDB($auth->auth['uname'], $db) . "', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d H:i:s") . "')";
$db->query($sql);
//********* enter name of cat in 'cat_lang'-table ******
$a_languages[] = $lang;
foreach ($a_languages as $tmp_lang) {
if ($tmp_lang == $lang) {
$sql = "INSERT INTO " . $cfg["tab"]["cat_lang"] . " (idcatlang, idcat, idlang, name, visible, public, idtplcfg, urlname, author, created, lastmodified)
VALUES('" . Contenido_Security::toInteger($db->nextid($cfg["tab"]["cat_lang"])) . "', '" . Contenido_Security::toInteger($tmp_newid) . "', '" . Contenido_Security::toInteger($tmp_lang) . "',
'" . clHtmlSpecialChars($catname, ENT_QUOTES) . "', '" . Contenido_Security::toInteger($bVisible) . "', '" . Contenido_Security::toInteger($bPublic) . "', '0',
'" . clHtmlSpecialChars(capiStrCleanURLCharacters($catalias), ENT_QUOTES) . "', '" . Contenido_Security::escapeDB($auth->auth['uname'], $db) . "', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d H:i:s") . "')";
$db->query($sql);
} else {
$sql = "INSERT INTO " . $cfg["tab"]["cat_lang"] . " (idcatlang, idcat, idlang, name, visible, public, idtplcfg, urlname, author, created, lastmodified)
VALUES('" . Contenido_Security::toInteger($db->nextid($cfg["tab"]["cat_lang"])) . "', '" . Contenido_Security::toInteger($tmp_newid) . "', '" . Contenido_Security::toInteger($tmp_lang) . "',
'" . clHtmlSpecialChars($catname, ENT_QUOTES) . "', '" . Contenido_Security::toInteger($bVisible) . "', '" . Contenido_Security::toInteger($bPublic) . "', '0',
'" . clHtmlSpecialChars(capiStrCleanURLCharacters($catalias), ENT_QUOTES) . "', '" . Contenido_Security::escapeDB($auth->auth['uname'], $db) . "', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d H:i:s") . "')";
$db->query($sql);
}
}
}
// set correct rights for element
cInclude("includes", "functions.rights.php");
foreach ($a_languages as $tmp_lang) {
copyRightsForElement("str", $tmp_parentid, $tmp_newid, $tmp_lang);
copyRightsForElement("con", $tmp_parentid, $tmp_newid, $tmp_lang);
}
if ($remakeTree == true) {
strRemakeTreeTable();
}
/* Search for default template */
$templateCollection = new cApiTemplateCollection("defaulttemplate = '1' AND idclient = '$client'");
if ($template = $templateCollection->next()) {
$idtpl = $template->get("idtpl");
if ($iIdtplcfg > 0) {
$idtpl = $iIdtplcfg;
}
/* Assign template, if default template exists */
$catCollection = new cApiCategoryLanguageCollection("idcat = '" . Contenido_Security::toInteger($tmp_newid) . "'");
while ($cat = $catCollection->next()) {
$cat->assignTemplate($idtpl);
}
} else {
//2008-06-25 timo.trautmann also set default template if it is selcted by user and there is no default template
if ($iIdtplcfg > 0) {
$idtpl = $iIdtplcfg;
$catCollection = new cApiCategoryLanguageCollection("idcat = '" . Contenido_Security::toInteger($tmp_newid) . "'");
while ($cat = $catCollection->next()) {
$cat->assignTemplate($idtpl);
}
}
}
return($tmp_newid);
}
function strOrderedPostTreeList($idcat, $poststring) {
global $db;
global $client;
global $lang;
global $cfg;
$sql = "SELECT idcat FROM " . $cfg["tab"]["cat"] . " WHERE parentid=0 AND preid='" . Contenido_Security::toInteger($idcat) . "' AND idcat!=0";
$db->query($sql);
if ($db->next_record()) {
$tmp_idcat = $db->f("idcat");
$poststring = $poststring . "," . $tmp_idcat;
$poststring = strOrderedPostTreeList($tmp_idcat, $poststring);
}
return $poststring;
}
/**
* Remakes the category tree structure in category tree table.
*
* @return void
*/
function strRemakeTreeTable() {
global $db;
global $client;
global $lang;
global $cfg;
// Flag to rebuild the category table
global $remakeCatTable;
global $remakeStrTable;
$remakeCatTable = true;
$remakeStrTable = true;
$poststring = "";
$sql = "SELECT idcat FROM " . $cfg["tab"]["cat"] . " WHERE idclient = '" . $client . "'";
$db->query($sql);
$idcats = array();
while ($db->next_record()) {
$idcats[] = $db->f("idcat");
}
$sql = "DELETE FROM " . $cfg["tab"]["cat_tree"] . " WHERE idcat IN ('" . implode("', '", $idcats) . "')"; // empty 'cat_tree'-table
$db->query($sql);
$sql = "DELETE FROM " . $cfg["tab"]["cat"] . " WHERE idcat='0'";
$db->query($sql);
$sql = "DELETE FROM " . $cfg["tab"]["cat_lang"] . " WHERE idcat='0'";
$db->query($sql);
$sql = "SELECT idcat, parentid, preid, postid FROM " . $cfg["tab"]["cat"] . " WHERE idclient = '" . $client . "' ORDER BY parentid ASC, preid ASC, postid ASC";
$db->query($sql);
// build cat_tree
$aCategories = array();
while ($db->next_record()) {
if ($db->f('parentid') == 0) {
$aCategories[0][$db->f('idcat')] = array(
'idcat' => $db->f('idcat'),
'parentid' => $db->f('parentid'),
'preid' => $db->f('preid'),
'postid' => $db->f('postid')
);
} else {
$aCategories[$db->f('parentid')][$db->f('idcat')] = array(
'idcat' => $db->f('idcat'),
'parentid' => $db->f('parentid'),
'preid' => $db->f('preid'),
'postid' => $db->f('postid')
);
}
}
$iNextTreeId = $db->nextid($cfg["tab"]["cat_tree"]);
// build INSERT statement
$sInsertQuery = "INSERT INTO " . $cfg["tab"]["cat_tree"] . " (idtree, idcat, level) VALUES ";
$sInsertQuery = recCats($aCategories[0], $sInsertQuery, $iNextTreeId, $aCategories);
$sInsertQuery = rtrim($sInsertQuery, " ,");
// lock db table and execute INSERT query
$db->lock($cfg["tab"]["cat_tree"]);
$db->query($sInsertQuery);
$db->nextid('cat_tree');
dbUpdateSequence($cfg["tab"]["sequence"], $cfg["tab"]["cat_tree"], $db);
$db->unlock($cfg["tab"]["cat_tree"]);
}
function sort_pre_post($arr) {
$firstElement = null;
foreach ($arr as $row) {
if ($row['preid'] == 0)
$firstElement = $row['idcat'];
}
$curId = $firstElement;
$array = array();
while ($curId != 0) {
$array[] = $arr[$curId];
$curId = $arr[$curId]['postid'];
}
return $array;
}
function recCats($aCats, $sInsertQuery, &$iNextTreeId, &$aAllCats, $iLevel = 0) {
if (is_array($aCats)) {
$aCats = sort_pre_post($aCats);
foreach ($aCats as $aCat) {
$sInsertQuery .= "(" . (int) $iNextTreeId . ", " . (int) $aCat['idcat'] . ", " . (int) $iLevel . "), ";
$iNextTreeId++;
if (is_array($aAllCats[$aCat['idcat']])) {
$iSubLevel = $iLevel + 1;
$sInsertQuery = recCats($aAllCats[$aCat['idcat']], $sInsertQuery, $iNextTreeId, $aAllCats, $iSubLevel);
}
}
}
return $sInsertQuery;
}
function strNextDeeper($tmp_idcat, $ignore_lang = false) {
global $cfg, $db_str, $lang;
$sql = "SELECT idcat FROM " . $cfg["tab"]["cat"] . " WHERE parentid='" . Contenido_Security::toInteger($tmp_idcat) . "' AND preid='0'";
$db_str->query($sql);
if ($db_str->next_record()) {
$midcat = $db_str->f("idcat");
if ($ignore_lang == true) {
return $midcat;
}
//******deeper element exists
/* Check for language dependent part */
$sql = "SELECT idcatlang FROM " . $cfg["tab"]["cat_lang"] . " WHERE idcat='" . Contenido_Security::toInteger($midcat) . "' AND idlang='" . Contenido_Security::toInteger($lang) . "'";
$db_str->query($sql);
if ($db_str->next_record()) {
return $midcat;
} else {
return 0;
}
} else {
//******deeper element does not exist
return 0;
}
}
/**
* Checks, if passed category cotains any articles
*
* @param int $tmp_idcat ID of category
* @return bool
*/
function strHasArticles($tmp_idcat) {
global $cfg, $db_str;
global $lang;
$sql = "SELECT b.idartlang AS idartlang FROM
" . $cfg["tab"]["cat_art"] . " AS a,
" . $cfg["tab"]["art_lang"] . " AS b
WHERE a.idcat='" . Contenido_Security::toInteger($tmp_idcat) . "' AND
a.idart = b.idart AND b.idlang = '" . Contenido_Security::toInteger($lang) . "'";
$db_str->query($sql);
if ($db_str->next_record()) { //******post element exists
return true;
} else { //******post element does not exist
return false;
}
}
function strNextPost($tmp_idcat) {
global $db;
global $cfg;
$sql = "SELECT idcat FROM " . $cfg["tab"]["cat"] . " WHERE preid='" . Contenido_Security::toInteger($tmp_idcat) . "'";
$db->query($sql);
if ($db->next_record()) { //******post element exists
$tmp_idcat = $db->f("idcat");
$sql = "SELECT parentid FROM " . $cfg["tab"]["cat"] . " WHERE idcat='" . Contenido_Security::toInteger($tmp_idcat) . "'";
$db->query($sql);
if ($db->next_record()) { //******parent from post must not be 0
$tmp_parentid = $db->f("parentid");
if ($tmp_parentid != 0) {
return $tmp_idcat;
} else {
return 0;
}
} else {
return 99;
}
} else { //******post element does not exist
return 0;
}
}
function strNextBackwards($tmp_idcat) {
global $db;
global $cfg;
$sql = "SELECT parentid FROM " . $cfg["tab"]["cat"] . " WHERE idcat='" . Contenido_Security::toInteger($tmp_idcat) . "'";
$db->query($sql);
if ($db->next_record()) { //******parent exists
$tmp_idcat = $db->f("parentid");
if ($tmp_idcat != 0) {
$sql = "SELECT idcat FROM " . $cfg["tab"]["cat"] . " WHERE preid='" . Contenido_Security::toInteger($tmp_idcat) . "'";
$db->query($sql);
if ($db->next_record()) { //******parent has post
$tmp_idcat = $db->f("idcat");
$sql = "SELECT parentid FROM " . $cfg["tab"]["cat"] . " WHERE idcat='" . Contenido_Security::toInteger($tmp_idcat) . "'";
$db->query($sql);
if ($db->next_record()) { //******parent from post must not be 0
$tmp_parentid = $db->f("parentid");
if ($tmp_parentid != 0) {
return $tmp_idcat;
} else {
return 0;
}
} else {
return 99;
}
} else { //******parent has no post
return strNextBackwards($tmp_idcat);
}
} else {
return 0;
}
} else { //******no parent
return 0;
}
}
/**
* Hotfix recursive call more than 200 times exit script on hosteurope Timo.Trautmann (strRemakeTreeTableFindNext)
* @deprecated
* */
function strRemakeTreeTableFindNext($tmp_idcat, $tmp_level) {
global $db;
global $cfg;
//************* Insert Element in 'cat_tree'-table **************
$sql = "INSERT INTO " . $cfg["tab"]["cat_tree"] . " (idtree, idcat, level) VALUES ('" . $db->nextid($cfg["tab"]["cat_tree"]) . "', '" . Contenido_Security::toInteger($tmp_idcat) . "', '" . Contenido_Security::toInteger($tmp_level) . "')";
$db->query($sql);
//************* dig deeper, if possible ******
$tmp = strNextDeeperAll($tmp_idcat, true);
foreach ($tmp as $iCurIdCat) {
if (count(strNextDeeperAll($iCurIdCat, true)) > 0) {
strRemakeTreeTableFindNext($iCurIdCat, ($tmp_level + 1));
} else {
$sql = "INSERT INTO " . $cfg["tab"]["cat_tree"] . " (idtree, idcat, level) VALUES ('" . $db->nextid($cfg["tab"]["cat_tree"]) . "', '" . Contenido_Security::toInteger($iCurIdCat) . "', '" . Contenido_Security::toInteger($tmp_level + 1) . "')";
$db->query($sql);
}
}
}
/**
Hotfix recursive call more than 200 times exit script on hosteurope Timo.Trautmann
* */
function strNextDeeperAll($tmp_idcat, $ignore_lang = false) {
global $cfg, $db_str, $db_str2, $lang;
$aCats = array();
$bLoop = true;
$sql = "SELECT idcat FROM " . $cfg["tab"]["cat"] . " WHERE parentid='" . Contenido_Security::toInteger($tmp_idcat) . "' and preid = 0";
#echo $sql.'
';
$db_str->query($sql);
if ($db_str->next_record()) {
while ($bLoop) {
$midcat = $db_str->f("idcat");
if ($ignore_lang == true) {
array_push($aCats, $midcat);
} else {
//******deeper element exists
/* Check for language dependent part */
$sql = "SELECT idcatlang FROM " . $cfg["tab"]["cat_lang"] . " WHERE idcat='" . Contenido_Security::toInteger($midcat) . "' AND idlang='" . Contenido_Security::toInteger($lang) . "'";
$db_str2->query($sql);
if ($db_str2->next_record()) {
array_push($aCats, $midcat);
}
}
$sql = "SELECT preid, postid, idcat FROM " . $cfg["tab"]["cat"] . " WHERE parentid='" . Contenido_Security::toInteger($tmp_idcat) . "' and preid = " . Contenido_Security::toInteger($midcat) . "";
$db_str->query($sql);
if (!$db_str->next_record()) {
$bLoop = false;
}
}
}
return $aCats;
}
/**
* Renders the category tree a HTML table
*
* @return void
*/
function strShowTreeTable() {
global $db;
global $sess;
global $client;
global $lang;
global $idcat;
global $cfg;
global $lngStr;
echo "
" . $tmp_id . " | " . $tmp_name . " | " . $tmp_level . " | "; echo "url("main.php?action=20&idcat=$tmp_id") . "\">" . $lngStr["actions"]["20"] . " | "; echo "url("main.php?action=30&idcat=$tmp_id") . "\">" . $lngStr["actions"]["30"] . " | "; echo "