<?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'] == 'add') && isset($_REQUEST['oguid']) && isset($_REQUEST['rating'])){
		$cn = db_connect();
		if (isset($_REQUEST['skbranch'])) {
			$skbranch = $_REQUEST['skbranch'];
		} else {
			$skbranch = db_getMainSKBranch($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);
		}
		db_addRating_ReportData($cn, $usrarr[0], $_REQUEST['oguid'], $rguid, $_REQUEST['rating'], $skbranch);
		echo'Сохранили!';
		db_disconnect($cn);
		unset($usrarr);
		ob_end_flush();
		exit;
	} else {
		echo'Ошибка!';
		ob_end_flush();
		exit;
	}
} else {
	echo"[{}]";
	ob_end_flush();
	exit;
}
?>