<?php
/**************************************************************************************************
|
| iDocScript - Document Sharing Script
| http://www.idocscript.com
| webmaster@idocscript.com
|
|**************************************************************************************************
|
| By using this software you agree that you have read and acknowledged our End-User License 
| Agreement available at http://www.idocscript.com/eula.html and to be bound by it.
|
| Copyright (c) 2011 iDocScript.com. All rights reserved.
|**************************************************************************************************/
include("include/config.php");
include("include/functions/import.php");

$item_id = intval($_REQUEST['id']);
$rating = intval($_REQUEST['value']);
	
if ($_SESSION[USERID] != "" && $_SESSION[USERID] >= 0 && is_numeric($_SESSION[USERID]))
{
	if($rating > 0 && $item_id > 0)
	{
		$rating = $rating * 2;
		$alreadyvoted = ajax_rate_doc($item_id,$rating);
		
		$query="SELECT rating,ratingcount FROM docs WHERE DID='".mysql_real_escape_string($item_id)."'";
        $executequery=$conn->execute($query);
        $rate = $executequery->fields['rating'];
		$ratedby = $executequery->fields['ratingcount'];
		
		if(!$alreadyvoted)
		{
			$r = get_rating_stars($rate, $item_id);
			$msg = $lang['464'];
		}
		else
		{
			$r = get_rating_stars($rate, $item_id);
			$msg = "$ratedby ".$lang['463'];
		}
		
		echo '{"msg":"';
		echo $msg;
		echo '","rating_code":"<ul>\n';
		echo $r;
		echo '<\/ul>","rate":"';
		echo $rate;
		echo '","ratedby":"';
		echo $ratedby;
		echo '","debug":""}';
	}
}
else
{
	$query="SELECT rating,ratingcount FROM videos WHERE VIDEOID='".mysql_real_escape_string($item_id)."'";
	$executequery=$conn->execute($query);
	$rate = $executequery->fields[rating];
	$ratedby = $executequery->fields[ratingcount];
	
	$r = get_rating_stars($rate, $item_id);
	$msg = $lang['170'];
	
	echo '{"msg":"';
	echo $msg;
	echo '","rating_code":"<ul>\n';
	echo $r;
	echo '<\/ul>","rate":"';
	echo $rate;
	echo '","ratedby":"';
	echo $ratedby;
	echo '","debug":""}';
}
?>