<?php if(!defined('BASEPATH')) exit('No direct script access allowed');

class Update_Vote_Model extends CI_Model
{
    function Update_Participant_Vote($participant_name,$edit_data,$ballot_name)
    {
        $participant_name=urldecode($participant_name);
        $participant_name=trim($participant_name);
        $array = array('participant_name' => $participant_name, 'ballot_name' => $ballot_name);
       
        $this->db->where($array); 
        $this->db->update('participants', $edit_data);
    
       if($this->db->affected_rows()>0)
       {    
            $array = array('ballot_name' => $ballot_name);
            $this->db->where($array); 
            $this->db->set('total_votes', 'total_votes+1', FALSE);
            $this->db->update('ballot');
            
            if($this->db->affected_rows()>0)
            {
                return $participant_name;
            }   
       }

       else
       {
           return false;
       }
    }

    function Update_Client_Vote_Status($client_id,$ballot_name,$name,$participant_name,$ip_address)
    {
        $client_id=urldecode($client_id);
        $client_id=trim($client_id);

        $array = array('client_id' => $client_id, 'ballot_name' => $ballot_name);
        
        $edit_data = array();
        $edit_data['vote']=1;
        $edit_data['name']=$name;
		$edit_data['participant_name']=$participant_name;
        date_default_timezone_set('Asia/Kolkata');
        $edit_data['vote_date_time']=date("Y/m/d h:i:sa");
        $edit_data['ip_address']=$ip_address;
        $this->db->where($array); 
        $this->db->update('ballot_status', $edit_data);
        
       // $query=$this->db->query("update user_details SET '$edit_data' where username='$username' ");

       if($this->db->affected_rows()>0)
       {    
               
             return $client_id;
       }

       else
       {
           return false;
       }
    }

    function Update_Client_Vote_Status_not($client_id,$ballot_name)
    {
        $client_id=urldecode($client_id);
        $client_id=trim($client_id);

        $array = array('client_id' => $client_id, 'ballot_name' => $ballot_name);
        
        $edit_data['vote']=0;
        
        $this->db->where($array); 
        $this->db->update('ballot_status', $edit_data);
       // $query=$this->db->query("update user_details SET '$edit_data' where username='$username' ");

       if($this->db->affected_rows()>0)
       {    
               
             return $client_id;
       }

       else
       {
           return false;
       }
    }

    function Update_Total_Votes($electoralid)
    {
        $username=urldecode($username);
        $username=trim($username);
        $this->db->where('username', $username);
        $this->db->update('user_details', $edit_data);
       // $query=$this->db->query("update user_details SET '$edit_data' where username='$username' ");

       if($this->db->affected_rows()>0)
       {    
             echo $username;   
             return $username;
       }

       else
       {
           return false;
       }
    }

}

?>
