<?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 ( getSetting('portal','useRights',0) == 1 && IsUserLogin() ){
	if (isset($_REQUEST['command']) && ($_REQUEST['command'] == 'get') && isset($_REQUEST['oguid'])){
		$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);	
		}
		$lng = ( isset($_REQUEST['lang']) ? 'lang='.$_REQUEST['lang'] : '');
		$lngid = db_getLanguageID($cn, getLanguage());
		$contlng = $lng;
		$contlngid = $lngid;
		if (getSetting('portal','useRights',0) == 1){
			$contlng = 'lang='.db_getLanguageShortByID($cn, $_SESSION['user_idlanguagecontent']);
			$contlngid = $_SESSION['user_idlanguagecontent'];
		}
		$usrarr = GetUserIDs();
		if (isset($_REQUEST['rguid'])) {
			$rguid = $_REQUEST['rguid'];
		} else {
			$trSt =  db_getReportsToObject($cn, $oguid ,GetUserIDs(), $lngid, $contlng, $skbranch);
			$rguid = $trSt[0]['r_guid'];
			unset($trSt);
		}
		$userid = GetUserID();
		$trSt = db_getReportData($cn, $userid, $_REQUEST['oguid'], $rguid, $skbranch);
		$size=sizeof($trSt);
		if ($size == 0){
			echo'[{"rating":"0"}]';
		} else {
			echo'[{"rating":"'.$trSt[0]['rd_rating'].'"}]';
		}
		ob_end_flush();
		exit;
	} else {
		echo'[{"msg":"ошибка!"}]';
		ob_end_flush();
		exit;
	}
} else {
	echo"[{}]";
	ob_end_flush();
	exit;
}
?>