<?php
require('../../template-functions.php');
$id = $_GET['id']; 
$rating = $_GET['rating'];
$option = $_GET['option'];

  switch($option) {
    case "image":
    	$dbtable =  prefix('images');
    	break;
    case "album":
    	$dbtable =  prefix('albums');
    	break;
  }
  
if ($rating > 5) { 
  $rating = 5;
}
  
if(!checkIP($id,$option)) { 
  // fetch used_ips and add new ip
  $ip = $_SERVER['REMOTE_ADDR'];  
  $numbers = query_full_array("SELECT total_votes, total_value, used_ips FROM ".$dbtable." WHERE id='$id' ")or die(" Error: ".mysql_error());
  $checkIP = unserialize($numbers['used_ips']);
  ((is_array($checkIP)) ? array_push($checkIP,$ip) : $checkIP = array($ip));
  $insertip = serialize($checkIP);
  $update = query_single_row("UPDATE ".$dbtable." SET total_votes = total_votes + 1, total_value = total_value + ".$rating.", used_ips='".$insertip."' WHERE id = '".$id."'"); 
}
?>
