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

class Update_Voting extends CI_Controller {

	public function vote_update()
	{
        $participant_name= $this->input->get('participant_name');
        $ballot_name= $this->input->get('ballot_name');
        $ip_address= $this->input->get('ip_address');

		$datas=$this->session->userdata('client');
        $datas = urldecode($datas);
        $datas=trim($datas);

        $ballot_name = urldecode($ballot_name);
        $ballot_name=trim($ballot_name);

        $vote_count=0;

        $participant_name = urldecode($participant_name);
        $participant_name=trim($participant_name);

        $this->load->model('Show_Vote_Data_To_Update');

        if($this->Show_Vote_Data_To_Update->participant_vote($participant_name,$ballot_name))
            {   
                $vote_count=(int)$this->Show_Vote_Data_To_Update->participant_vote($participant_name,$ballot_name);  
            
                // echo $participant_name;
                // echo "<br>";
                // echo $vote_count;
                // echo "<br>";
                // echo $ballot_name;
            }    


        $this->load->model('Update_Vote_Model');
        //echo $ballot_name;
        $query = $this->db->select('name')->from('users')->where('cid',$datas)->get();
        $res= $query->result();
        $client_name=$res[0]->name;
        //print_r($res[0]->name);die();
        //print_r($this->Update_Vote_Model->Update_Client_Vote_Status($datas,$ballot_name,$client_name));die();
        if($this->Update_Vote_Model->Update_Client_Vote_Status($datas,$ballot_name,$client_name,$participant_name,$ip_address))
            {    
                
            }
        //  else
        //  {
        //      echo "not done 2";
        //  }       


        $this->load->model('Update_Vote_Model');
        
        $vote_date['vote']=$vote_count+1;

//print_r($this->Update_Vote_Model->Update_Participant_Vote($participant_name,$vote_date,$ballot_name));die();
        if($this->Update_Vote_Model->Update_Participant_Vote($participant_name,$vote_date,$ballot_name))
        {   
            $this->session->set_flashdata('vote_done','YOUR VOTE IS SUBMITTED , THANK YOU');
            redirect(base_url().'index.php/Show_Voting_Data_Client/VotingTitlesDataClient/'.$datas);

            //echo "DONE";
        }
        else
        {
            $this->Update_Vote_Model->Update_Client_Vote_Status($datas,$ballot_name,$datas,$participant_name,$ip_address);

            $this->session->set_flashdata('vote_done','YOUR VOTE IS NOT REGISTERED,TRY AGAIN');
            redirect(base_url().'index.php/Show_Voting_Data_Client/VotingTitlesDataClient/'.$datas);
        }    
    }
     


    
}

