<?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');
}
checkLanguage();
if ( getSetting('portal','useRights', 0) == 1 && !IsUserLogin()){
	ob_end_flush();
	exit;
}

echo '[ ';
$cn = db_connect();
if (isset($_REQUEST['idbranch'])) {
	$idbranch = $_REQUEST['idbranch'];
	$skbranch = db_getSKBranch($cn,$idbranch);	
} else if (isset($_REQUEST['skbranch'])) {
	$skbranch = $_REQUEST['skbranch'];
	$idbranch = db_getIDBranch($cn, $skbranch );	
} else {
	$skbranch = db_getMainSKBranch($cn);
	$idbranch = db_getMainIDBranch($cn);	
}
$user_idlanguagecontent = $_SESSION['user_idlanguagecontent'];
$user_idlanguageinterface = $_SESSION['user_idlanguageinterface'];
$trSt = db_getReportsToObject($cn, $_REQUEST['oguid'] ,GetUserIDs(), $user_idlanguagecontent, $skbranch);
$size=sizeof($trSt);
for($i=0; $i<$size; $i++){
	echo $i == 0 ? '{ ' : ', { ' ;
	echo ' "name":"'.str_replace('\\', "&frasr;", htmlentities($trSt[$i]['r_name'], ENT_QUOTES, 'UTF-8')).'",';
	echo ' "guid":"'.$trSt[$i]['r_guid'].'", ';
	echo ' "idreport":"'.$trSt[$i]['idreport'].'" ';
	echo '} ';
}
unset($trSt);
echo '] ';
db_disconnect($cn);
ob_end_flush();
?>