<?php
ob_start();
if(!(is_readable(realpath(dirname(__FILE__).'/../').'/include/includesroutines.inc'))) {
	die('Error - Could not open or read file '.realpath(dirname(__FILE__).'/../').'/include/includesroutines.inc');
} else {
	include_once(realpath(dirname(__FILE__).'/../').'/include/includesroutines.inc');
}

if(!(is_readable(realpath(dirname(__FILE__).'/../').'/classes/tree.php'))) {
	die('Error - Could not open or read file '.realpath(dirname(__FILE__).'/../').'/classes/tree.php');
} else {
	include_once(realpath(dirname(__FILE__).'/../').'/classes/tree.php');
}
checkLanguage();

if ( GetSetting('portal','useRights',0) == 1 && !IsUserLogin()){
	ob_end_flush();
	exit;
}

$idobj = 0;
$cn = db_connect();
if (isset($_REQUEST['idbranch'])) {
	$idbranch = $_REQUEST['idbranch'];
	$skbranch = db_getSKBranch($cn,$idbranch);	
} else if (isset($_REQUEST['skbranch'])) {
	$isBranchSet = true;
	$skbranch = $_REQUEST['skbranch'];
	$idbranch = db_getIDBranch($cn, $skbranch );	
} else {
	$skbranch = db_getMainSKBranch($cn);
	$idbranch = db_getMainIDBranch($cn);	
}
$ido = db_getIDObjectByGuid($cn, $_REQUEST['oguid']);
$user_idlanguagecontent = $_SESSION['user_idlanguagecontent'];
session_write_close();

$tr_arr = db_getPreparedObjectTreetoUser(
	$cn,
	$ido,
	GetUserIDs(),
	$user_idlanguagecontent, $skbranch);

$roots = db_getRootObjectTreeFromPreparetTree($cn, $skbranch);
$size = sizeof($tr_arr);
db_disconnect($cn);
$tree = new Tree();
for($i=0; $i<$size; $i++){
	if (in_array($tr_arr[$i]['idobject'], $roots)){
		$tree->addItem($tr_arr[$i]['idobject'], 0, $tr_arr[$i]);
	} else {
		$tree->addItem($tr_arr[$i]['idobject'], $tr_arr[$i]['parent_idobject'], $tr_arr[$i]);
	}
}
echo $tree->createServiceHtml(0);
unset($tr_arr);
unset($roots);
unset($tree);
ob_end_flush();
?>