<?php
include_once("../../corebot/_config_.php");
include_once("../../corebot/errorHandler.php");

$conf = new config();
function getAllVotes($id)  
 {  
 /** 
 Returns an array whose first element is votes_up and the second one is votes_down 
 **/  
 $votes = array();  
 $q = "SELECT cupn_vwui FROM copn_cpnbnks WHERE _frgn_ky = '".$id."'";  
 $r = mysql_query($q);  
 if(mysql_num_rows($r)==1)//id found in the table  
  {  
  $row = mysql_fetch_array($r);  
  $votes[0] = $row['cupn_vwui'];  
  
  }  
 return $votes;  
 }  
/// get input
$id = $_POST['id'];  
//$action = $_POST['action']; 
//get the current votes  
$cur_view = getAllVotes($id);  
  
//ok, now update the votes  
  

 $view_up = $cur_view[0]+1;  
 $q = "UPDATE copn_cpnbnks SET cupn_vwui = '".$view_up."' WHERE _frgn_ky = '".$id."'";  

 

$r = mysql_query($q);  
if($r) //voting done  
 {  
 //$effectiveVote = getEffectiveVotes($id);  
 //echo $effectiveVote." votes";  
 }  
elseif(!$r) //voting failed  
 {  
 //echo "Failed!";  
 }  

?>