<?php
class Model_admin extends CI_Model{
function __construct() {
parent::__construct();
}
    function login($data)
	   {
	     
			$username = $data['username'];
			$password = md5($data['password']);
			$this->db->where('username',$username);
			$this->db->where('password',$password);
			$query=$this->db->get('admin_login');
			$result = $query->result();
				 $num_rows = $query->num_rows();
			
		 
		    if($query->num_rows == 1)
				{
					$this->session->set_userdata('username-admin1',$data['username']);
					$user = $this->session->userdata('username-admin1');
					$user1 = "admin";
					return $user1;
			    }
			 else
				{
					  return 1;
				}
		}

		
//add Subscription details
	function add_subscription($data)
		{
		
		    $plan_title        = $_POST['plan_title'];
			$plan_id       = $_POST['plan_id'];
			$sub_interval        = $_POST['sub_interval'];
			$of_interval        = $_POST['of_interval'];
			$amount   = $_POST['amount'];
			$trial_days      = $_POST['trial_days'];
			$user_activate  = $_POST['user_activate'];
		  
		  	
		 $table  ='subscriptions_tbl';
		 $ins = array(
				        'plan_title'            => $plan_title,
						'plan_id'               => $plan_id,
						'subscription_interval' => $sub_interval,
						'of_intervals'          => $of_interval,
						'amount'                => $amount,
						'trial_period_days'     => $trial_days,
						'activate_user'        => $user_activate
                      	);
							 $result = $this->db->insert($table, $ins);
							 if($result){
								echo 1;
							}
				}
	
	function add_client($data){
		 $first_name        = $_POST['first_name'];
		 $last_name        = $_POST['last_name'];
		 $email        = $_POST['email'];
		 $phone        = $_POST['phone'];
		 $password        = $_POST['password'];
		 $table  ='	clients_tbl';
                 
                  
	  	  $this->db->where('email',$email);
                  $q = $this->db->get('clients_tbl');
                  
                    $this->db->where('email',$email);
                 $q1 = $this->db->get('contractors_tbl');
                 if ($q->num_rows() > 0 || $q1->num_rows() > 0){
                     echo 3;
                 }
                 else{
		 $ins = array(
				        'first_name' => $first_name,
						'last_name'  => $last_name,
						'email'      => $email,
						'password'   => $password,
						'phone'      => $phone
						);
							 $result = $this->db->insert($table, $ins);
							 if($result){
								echo 1;
							}
                 }
	  }
		
	
 //update client details
	function update_client_details($data)
	   {
		   
		     $first_name1 = $_POST['first_name1'];
                       $last_name1  = $_POST['last_name1'];
			 $email1      = $_POST['email1'];
			 $password1   = md5($_POST['password1']);
			 $phone1      = $_POST['phone1'];
			 $client_id   = $_POST['client_id'];
		     $table  = 'clients_tbl';
                     $query = $this->db->query("select * from clients_tbl where client_id='".$client_id."'");
                     $res = $query->row_array();
                    if($res['email']== $email1){
                       
	         $ins = array(
					              'first_name' => $first_name1,
							'last_name'  => $last_name1,
							'email'      => $email1,
							'password'   => $password1,
							'phone'      => $phone1
						);
			
			$this->db->where('client_id',$client_id); 
			$result = $this->db->update($table,$ins);
			
			if($result){
						  echo 1;
						}
                    }
                     else if($res['email']!= $email1){
                        
                     $query13 = $this->db->query("select * from contractors_tbl where email='".$email1."'");
                    
                     $query14 = $this->db->query("select * from clients_tbl where email='".$email1."'");
                    
                     
                      if($query13->num_rows()==0 && $query14->num_rows()==0){
                           $ins = array(
                                                        'first_name' => $first_name1,
							'last_name'  => $last_name1,
							'email'      => $email1,
							'password'   => $password1,
							'phone'      => $phone1
						);
			
			$this->db->where('client_id',$client_id); 
			$result = $this->db->update($table,$ins);
			
			if($result){
						  echo 1;
						}
                                               
		}
                  else {
                          echo 3;
                      }
                     }
                      else {
                          
                          echo 3;
                      }
           }
	
		//delete parent record
	function delete_client($client_id)
	 {
		 $this->db->where('client_id', $client_id);
	     $query=$this->db->delete('clients_tbl');
	     if($query){
	                   return true;
                     }else{
	                    return false;
                   }
		}


 
 
// add provider details	
	function add_contractor($data)
	  {  
	     $first_name        = $_POST['first_name'];
		 $last_name        = $_POST['last_name'];
		 $email        = $_POST['email'];
		 $phone        = $_POST['phone'];
		 $password        = $_POST['password'];
		 $company_name        = $_POST['company_name'];
		 $table  ='contractors_tbl';
                 
                 $this->db->where('email',$email);
                 $q = $this->db->get('contractors_tbl');
                 
                 $this->db->where('email',$email);
                 $q1 = $this->db->get('clients_tbl');
                 
                 if ($q->num_rows() > 0 || $q1->num_rows() > 0){
                     echo 3;
                 }
                 else{
		 $ins = array(
				        'first_name' => $first_name,
						'last_name'  => $last_name,
						'email'      => $email,
						'password'   => $password,
						'phone'      => $phone,
						'company_name' => $company_name
						);
							 $result = $this->db->insert($table, $ins);
							 if($result){
								echo 1;
							}
                 }
		}
 //edit provider details
 function update_contractor_details($data)
	   {
		   
		        $first_name1     = $_POST['first_name1'];
                        $last_name1      = $_POST['last_name1'];
			 $email1          = $_POST['email1'];
			 $password1       = md5($_POST['password1']);
			 $phone1          = $_POST['phone1'];
			 $company_name1   = $_POST['company_name1'];
			 $contractor_id   = $_POST['contractor_id'];
		     $table  = 'contractors_tbl';
                     $query = $this->db->query("select * from contractors_tbl where contractor_id='".$contractor_id."'");
                     $res = $query->row_array();
                    if($res['email']== $email1){
                      $ins = array(
					                'first_name'   => $first_name1,
							'last_name'    => $last_name1,
							'email'        => $email1,
							'password'     => $password1,
							'phone'        => $phone1,
							'company_name' => $company_name1,
						);
			
			$this->db->where('contractor_id',$contractor_id); 
			$result = $this->db->update($table,$ins);
			if($result){
						  echo 1;
						
                        }    
                     }
                    else if($res['email']!= $email1){
                     $query13 = $this->db->query("select * from contractors_tbl where email='".$email1."'");
                    
                     $query14 = $this->db->query("select * from clients_tbl where email='".$email1."'");
                    
                     
                      if($query13->num_rows()==0 && $query14->num_rows()==0){
                           $ins = array(
					        'first_name'   => $first_name1,
							'last_name'    => $last_name1,
							'email'        => $email1,
							'password'     => $password1,
							'phone'        => $phone1,
							'company_name' => $company_name1,
						);
			
			$this->db->where('contractor_id',$contractor_id); 
			$result = $this->db->update($table,$ins);
			
			if($result){
						  echo 1;
						
                        }    
                          
                      }  
                      else {
                          echo 3;
                      }
                      
                    }
                        else {
                           
                            echo 3;
                        }
 
	   }
//delete provider record				
  function delete_contractor($contractor_id)
	 {
		$this->db->where('contractor_id', $contractor_id);
		$query = $this->db->delete('contractors_tbl');
		if($query){
					return true;
				  }else{
	                return false;
				 }
	}
// add cms details							
	function add_jobCategory($data)
	  {
		  $cat_name = $_POST['cat_name'];
		 
          $table  = 'jobcategories_tbl';
          $ins = array(
						 'category_name' => $cat_name
					 );
		  $result = $this->db->insert($table, $ins);
		  if($result){
						echo 1;
					 }
	  }
	  

// edit cms details					
	function update_jobCategoryDetails($data)
	   {
		 $cat_name1        = $data['cat_name1'];
	     $job_category_id  = $data['job_category_id'];
	     $table            ='jobcategories_tbl';
         $ins = array(
						'category_name' => $cat_name1
					 );
		$this->db->where('job_category_id',$job_category_id); 
		$result = $this->db->update($table,$ins);
		if($result){
						  echo 1;
						}
	  }
	  
	  //update camp details
	
	  
	  
// delete cms record				
	function delete_jobCategory($job_category_id)
	        {
			   $this->db->where('job_category_id', $job_category_id);
			   $query = $this->db->delete('jobcategories_tbl');
			   if($query){
							return true;
						 }else{
                           return false;
						      }
	   }
	//add feedback details	
   function add_jobsInfo($data)
	  {
		 $cat_name = $_POST['cat_name'];
		  $job_title = $_POST['job_title'];
		  $job_type    = $_POST['job_type'];
		  $hourly_rate   = $_POST['hourly_rate'];
		  $description  = $_POST['description'];
		  $start_date  = $_POST['start_date'];
		  $end_date  = $_POST['end_date'];
		  
          $table    = 'jobdetails_tbl';	
          $ins = array(
					     'job_id'  => $cat_name,
						 'job_type' => $job_type,
						 'job_title' => $job_title,
						 'hoursly_rate'    => $hourly_rate,
						 'description'   => $hourly_rate,
						 'start_date'  => $start_date,
						 'end_date' => $end_date
                      );
		  $result = $this->db->insert($table, $ins);
		  if($result){
						echo 1;
					 }
	  }
	  //edit feedback details
	function update_jobInfo_details($data)
	   {
		 $cat_name1 = $data['cat_name1'];
		 $job_title1    = $data['job_title1'];
		 $hourly_rate1   = $data['hourly_rate1'];
		 $description1  = $data['description1'];
		 $start_date1 = $data['start_date1'];
		 $end_date1 =  $data['end_date1'];
		 
	     $table       =' jobdetails_tbl';
         $ins = array(
						'category_name'  => $cat_name1,
						'job_title'     => $job_title1,
					    'hoursly_rate'    => $hourly_rate1,
						'description'   => $description1,
						'start_date' => $start_date1,
						'end_date' => $end_date1,
						
					 );
		$this->db->where('job_information_id',$job_information_id); 
		$result = $this->db->update($table,$ins);
	
		if($result){
						echo 1;
				   }
	  }
//delete feedback record	  
function delete_job_information($job_information_id)
	 {
			   $this->db->where('job_information_id', $job_information_id);
			   $query = $this->db->delete('jobdetails_tbl');
			   if($query){
							return true;
						 }else{
                           return false;
						      }
		   }
		   
		   
		function update_fee($data)
	   {
		 $application_fee        = $data['application_fee'];
	     $setting_id  = $data['setting_id'];
	     $table            ='setting_tbl';
         $ins = array(
						'contractor_application_fee' => $application_fee
					 );
		$this->db->where('setting_id',$setting_id); 
		$result = $this->db->update($table,$ins);
		if($result){
						  echo 1;
						}
	  }	   
		
		
	   

}		

?>