<?php
/*
 ########################################################################
#                                                                        #
#           Version 4       /                        /   /               #
#          -----------__---/__---__------__----__---/---/-               #
#           | /| /  /___) /   ) (_ `   /   ) /___) /   /                 #
#          _|/_|/__(___ _(___/_(__)___/___/_(___ _/___/___               #
#                       Free Content / Management System                 #
#                                   /                                    #
#                                                                        #
#                                                                        #
#   Copyright 2005-2006 by webspell.org                                  #
#                                                                        #
#   visit webSPELL.org, webspell.info to get webSPELL for free           #
#   - Script runs under the GNU GENERAL PUBLIC LICENSE                   #
#   - It's NOT allowed to remove this copyright-tag                      #
#   -- http://www.fsf.org/licensing/licenses/gpl.html                    #
#                                                                        #
#   Code based on WebSPELL Clanpackage (Michael Gruber - webspell.at),   #
#   Far Development by Development Team - webspell.org                   #
#                                                                        #
#   visit webspell.org                                                   #
#                                                                        #
 ########################################################################
*/

include("_mysql.php");
include("_settings.php");
include("_functions.php");
$table="0";
$key="0";
if(!$userID) die('No access!');

$rating = $_POST['rating'];
settype($rating, "integer");

$type =$_POST['type'];
$id =$_POST['id'];

if($type=="ar") {
    $table="articles";
	$key="articlesID";
}
elseif($type=="de") {
    $table="demos";
	$key="demoID";
}
elseif($type=="fi") {
    $table="files";
	$key="fileID";
}
elseif($type=="ga") {
    $table="gallery_pictures";
	$key="picID";
}

safe_query("UPDATE ".PREFIX."$table SET votes=votes+1, points=points+$rating WHERE $key='$id'");
$ergebnis=safe_query("SELECT votes, points FROM ".PREFIX."$table WHERE $key='$id'");
$ds=mysql_fetch_array($ergebnis);
$rate=round($ds[points] / $ds[votes]);
safe_query("UPDATE ".PREFIX."$table SET rating='$rate' WHERE $key='$id'");

$getarticles=safe_query("SELECT $table FROM ".PREFIX."user WHERE userID='$userID'");
if(mysql_num_rows($getarticles)) {
    $ga=mysql_fetch_array($getarticles);
	if($ga[$table]=="") $array[]=$id;
	else {
	    $string=$ga[$table];
		$array=explode(":", $string);
    	$array[]=$id;
	}
	$string_new=implode(":", $array);
	safe_query("UPDATE ".PREFIX."user SET $table='$string_new' WHERE userID='$userID'");
}

if($table=="gallery_pictures") $table="gallery&picID=".$id;

redirect("index.php?site=".$table,"",0);
?>