<?php
class Dashboard_model extends CI_Model {
	function __construct()
	{
		parent::__construct();

	}

	function change_user($user_id)
	{
		
		$this->db->where('user_id',$user_id);
		$this->db->where('status','active');
		//$this->db->join('patients', 'patients.username = users.username');	
		//$this->db->join('patients', 'patients.password = users.password');	
		$q=$this->db->get('users');
		
		if($q->num_rows>0)
		{
			$data=array(
				'id'=>$q->row('user_id'),
				//'patient_id'=>$q->row('patient_id'),
				'username'=>$q->row('username'),
				'role'=>$q->row('role'),
				'main_role'=>'agent',
				'name'=>$q->row('first_name').' '.$q->row('last_name'),				
				'logged_in'=>TRUE
				);
			$this->session->set_userdata($data);
     
			$role = $q->row('role');
			if ($role == 'patient') {
				$data1=array(				
				'patient_id'=>$q->row('patient_id')				
				);
			}else{
				$data1=array(				
				'patient_id'=>''			
				);
			}
			
			$this->session->set_userdata($data1);
			//print_r($this->session->userdata('patient_id'));exit();
			return true;
		}else{
			return false;
		}
	}

	public function get_competitor_list()
	{	//$searchtext, $column_name, $order_by
        $sql = "SELECT * FROM competitor where IsActive=0";
        $record = $this->db->query($sql);
        return $record->result_array();
	}
	
	public function save_compitator($post_data)
	{	
				$brand=$post_data['brand'];
				$data=array('brand'=>$brand);
				 return $this->db->insert('competitor',$data);
			
				
	}
	public function update_compitator($post_data)
	{	
				$brand=$post_data['brand'];
				$id=$post_data['id'];
				$data=array('brand'=>$brand);
				$this->db->where('id',$id);
				 return $this->db->update('competitor',$data);
			
				
	}
	
	public function delete_competitor($id)
	{	
				
				$data=array('IsActive'=>'1');
				$this->db->where('id',$id);
				 return $this->db->update('competitor',$data);
			
				
	}

}?>