<?PHP
if (!defined('IS_DEDI')) die();
include_once($cfg_dedi['dedi_path'].'inc/inc.init_external.php');
echo '<?xml version="1.0" encoding="iso-8859-1"?>';

$sql = "SELECT A.name, B.idcat, B.parent, B.sortindex FROM $dedi_db[cat_lang] AS A, $dedi_db[cat] AS B WHERE A.idcat=B.idcat AND B.idclient='$client' ORDER BY B.parent, B.sortindex";
$db->query($sql);
while ($db->next_record()){
	$cat[$db->f('idcat')] = $db->f('name');
	$tlo_tree[$db->f('parent')][$db->f('sortindex')] = $db->f('idcat');
}
tree_level_order_light();
$sql = "SELECT D.idcatside, D.idcat, D.sortindex, D.is_start, F.title FROM $dedi_db[cat_side] AS D, $dedi_db[side] AS E, $dedi_db[side_lang] AS F WHERE D.idside=E.idside AND E.idside=F.idside AND E.idclient='$client' AND F.idlang='$lang' ORDER BY D.idcatside";
$db->query($sql);
while ($db->next_record()){
	$side[$db->f('idcat')][$db->f('idcatside')]['name'] = $db->f('title');
	$side[$db->f('idcat')][$db->f('idcatside')]['idcatside'] = $db->f('idcatside');
	$side[$db->f('idcat')][$db->f('idcatside')]['is_start'] = $db->f('is_start');
	if($db->f('is_start') == 1){ $side['start'][$db->f('idcat')] = $db->f('idcatside'); }
	if(!is_array($side['sortarray'][$db->f('idcat')])){$side['sortarray'][$db->f('idcat')] = array(); }
	array_push($side['sortarray'][$db->f('idcat')],$db->f('sortindex'));
}
$tree = array();
foreach($catlist as $a){
	$temp['id'] = $a;
	$temp['name'] = $cat[$a];
	$temp['level'] = $catlist_level[$a];
	if(isset($side['start'][$a])){ $temp['typ'] = "o"; } else { $temp['typ'] = "i"; }
	array_push($tree, $temp);
	if(is_array($side[$a])){
		array_multisort($side['sortarray'][$a] , SORT_ASC , $side[$a] , SORT_ASC);
		foreach(array_keys($side[$a]) as $b){
			$temp['id'] = $side[$a][$b]['idcatside'];
			$temp['name'] = $side[$a][$b]['name'];
			$temp['level'] = $catlist_level[$a] + 1;
			$temp['typ'] = "s";
			array_push($tree, $temp);
		}
	}
}

$exp = array();
$sql = "SELECT idcat FROM $dedi_db[cat_expand] WHERE idusers = 1";
$db->query($sql);
while ($db->next_record()) { $exp[$db->f('idcat')] = true; }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Link eingeben</title>

		<base href="<?PHP echo $cfg_dedi['dedi_html_path'] . 'external/bbcode/'; ?>" />

		<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
		<link rel="stylesheet" type="text/css" href="<?PHP echo $bbcode; ?>form.css" />

		<script type="text/javascript" src="dtree.js"></script>
		<script type="text/javascript" src="form.js"></script>
		<script type="text/javascript">var formname = '<?PHP echo $_GET['formname']; ?>';</script>
	</head>
	<body onload="setfocus('dest');" onunload="savesize('link');">
		<div id="left">
			<form action="#" onsubmit="return link_build();">
				<label for="dest">Ziel:</label>
				<input type="text" id="dest" class="text" name="dest" value="http://" size="30" />
<?PHP if($_GET['notarget'] != '1') { ?>
				<label for="target">Zielframe:</label>
				<select id="target" size="1">
					<option value="">Selber Frame</option>
					<option value="_blank">Neues Fenster</option>
					<option value="_parent">Übergeordneter Frame</option>
					<option value="_top">Oberster Frame</option>
				</select>
<?PHP }; if($_GET['anchor'] == '1') { ?>
				<label for="anchor">Anker</label>
				<input type="text" class="text" id="anchor" name="anchor" size="30" />
<?PHP }; if($_GET['notext'] == '1') { ?>
				<input type="checkbox" class="checkbox" value="1" id="notext" name="notext" /><label for="notext" class="checkbox">Kein Linktext</label>
<?PHP }; ?>
				<input type="submit" class="submit" value="OK" />
			</form>
		</div>
    		<div id="right_dtree">
			<script type="text/javascript">
dtree = new dTree('a');
dtree.config.useCookies = false;
dtree.config.useSelection = false;
dtree.config.inOrder = true;
dtree.config.folderLinks = false;
dtree.icon.folder = 'img/cfolder.gif';
dtree.icon.folderOpen = 'img/ofolder.gif';
dtree.icon.folderOpen = 'img/ofolder.gif';
dtree.icon.node = 'img/dedi_side.gif';
dtree.add(0, -1, 'DeDi-Seitenstruktur');

<?PHP

$II = 0;
foreach($tlo_tree[0] as $a) {
  pTree_cat($a, 0);
}

function pTree_cat($ID, $PI) {
  global $II, $cat, $tlo_tree, $exp;

  $II++;
  $MI = $II;
  echo "dtree.add($II, $PI, '$cat[$ID]'" . (isset($exp[$ID]) ? ', null, null, null, null, null, true' : '') . ");\n";  pTree_side($ID, $MI);
  if(is_array($tlo_tree[$ID])) {
    foreach($tlo_tree[$ID] as $a) {
      pTree_cat($a, $MI);
    }
  }
}

function pTree_side($P, $PI) {
  global $II, $side;

  if(is_array($side[$P])) {
    foreach($side[$P] as $a) {
      $II++;
      echo "dtree.add($II, $PI, '" . $a['name'] . "', 'javascript:link_use(" . $a['idcatside'] . ")'".($a['is_start'] ? ", null, null, 'img/dedi_firstside.gif', 'img/dedi_firstside.gif'" : "").");\n";
    }
  }
}

?>

document.write(dtree);
			</script>
		</div>
	</body>
</html>