<?php

error_reporting(0);

class Model_web_service extends CI_Model {

    function __construct() {
        $this->load->helper(array('form', 'url'));
        $this->load->helper('date');
        $this->load->helper('file');
        $this->load->helper('cookie');
        $this->load->helper('url');
        $this->load->library('email');
        parent::__construct();
    }

    //parent_login.
    function login($request) {

        $email = $request->email;
        $phone = $request->phone;
        $pass = md5($request->pass);
        $token = $request->token;
        $table = 'clients_tbl';
		if($phone != '')
			$query1 = $this->db->query("SELECT * FROM  clients_tbl where phone='$phone' AND password='$pass'");
		else
			$query1 = $this->db->query("SELECT * FROM  clients_tbl where email= '$email' AND password='$pass'");
		
        $result = $query1->row_array();
        if ($result) {
			$query = $this->db->query("update clients_tbl set token='$token' where client_id='" . $result['client_id'] . "'");
        }
        $total_count = $query1->num_rows();

        if (empty($result)) {
			if($phone != '')
				$query12 = $this->db->query("SELECT * FROM  attorneys_tbl where phone='$phone' AND password='$pass'");
			else
				$query12 = $this->db->query("SELECT * FROM  attorneys_tbl where email= '$email' AND password='$pass'");
			
            $result = $query12->row_array();
            $query = $this->db->query("update attorneys_tbl set token='$token' where attorney_id='" . $result['attorney_id'] . "'");
            $total_count2 = $query12->num_rows();
        }
          if ($total_count > 0) {
            $data['flag'] = 1;
            $data['ClientId'] = $result['client_id'];
            $data['UserName'] = $result['first_name'] . ' ' . $result['last_name'];
            $data['Email'] = $result['email'];
            $var[] = $data;
            return $var;
        } else if ($total_count2 > 0) {
            $data['flag'] = 2;
            $data['ContractorId'] = $result['attorney_id'];
            $data['UserName'] = $result['first_name'] . ' ' . $result['last_name'];
            $data['Email'] = $result['email'];
			$data['Paid Status'] = $result['paid_status'];
            $data['Paid Date'] = $result['paid_date'];
            $var[] = $data;
            return $var;
        } else {
            return false;
        }
    }

    //client registration.
    function client_registration($request) {
        $first_name = $request->first_name;
        $last_name = $request->last_name;
        $email = $request->email;
        $password = md5($request->password);
        $phone = $request->phone;
		$emergency_contact = $request->emergency_contact;
		$emergency_name = $request->emergency_name;
        $token = $request->token;
        $query1 = $this->db->query("SELECT email FROM  clients_tbl where email= '$email'");
        $result1 = $query1->row_array();
        $total_count = $query1->num_rows();
        $query12 = $this->db->query("SELECT email FROM  attorneys_tbl where email= '$email'");
        $result12 = $query12->row_array();

        $total_count12 = $query12->num_rows();
        if (($total_count > 0) || ($total_count12 > 0)) {
            return false;
        } else {
            $table = 'clients_tbl';
            $ins = array(
			   'emergency_contact' =>$emergency_contact,
			   'emergency_name' =>$emergency_name,
                'first_name' => $first_name,
                'last_name' => $last_name,
                'email' => $email,
                'password' => $password,
                'phone' => $phone,
                'token' => $token
            );
            $result = $this->db->insert($table, $ins);
            $last_id = $this->db->insert_id();
            if ($result) {
                $q = $this->db->query("select * from clients_tbl where client_id='" . $last_id . "'");
                $row = $q->row_array();

                $data['ClientId'] = $row['client_id'];
                $data['UserName'] = $row['first_name'] . ' ' . $row['last_name'];
                $data['Email'] = $row['email'];
                $var[] = $data;
                //echo '<pre>'; print_r($var); exit;
                return $var;
            } else {
                return false;
            }
        }
    }

    //parent registration.
    function attorney_registration($request) {

        $first_name = $request->first_name;
        $last_name = $request->last_name;
        $email = $request->email;
        $password = md5($request->password);
        $phone = $request->phone;
        $attorney_number = $request->attorney_id;
        $token = $request->token;
        $profile_pic = base64_decode($request->profile_pic);

        $filename = uniqid() . '.png';
        $folder = FCPATH . 'upload/' . $filename;
        file_put_contents($folder, $profile_pic);
        $table = 'attorneys_tbl';
        $query1 = $this->db->query("SELECT email FROM  attorneys_tbl where email= '$email'");
        $result1 = $query1->row_array();

        $total_count = $query1->num_rows();

        $query12 = $this->db->query("SELECT email FROM  clients_tbl where email= '$email'");
        $result12 = $query12->row_array();
        $total_count2 = $query12->num_rows();
        if (($total_count > 0) || ($total_count12 > 0)) {
            return false;
        } else {

            $ins = array(
                'first_name' => $first_name,
                'last_name' => $last_name,
                'email' => $email,
                'password' => $password,
                'phone' => $phone,
                'token' => $token,
                'attorney_number' => $attorney_number,
                'image' => base_url() . 'upload/' . $filename
            );
            $result = $this->db->insert($table, $ins);
            $last_id = $this->db->insert_id();
            if ($result) {
                $q = $this->db->query("select * from attorneys_tbl where attorney_id='" . $last_id . "'");
                $row = $q->row_array();
                $data['ContractorId'] = $row['attorney_id'];
                $data['UserName'] = $row['first_name'] . ' ' . $row['last_name'];
                $data['Email'] = $row['email'];
                $var[] = $data;
                //echo '<pre>'; print_r($var); exit;
                return $var;
            } else {
                return false;
            }
        }
    }

    function add_jobInformation($request) {
        $job_id = $request->job_id;
        $job_title = $request->job_title;
        $job_type = $request->job_type;
        $hoursly_rate = $request->hoursly_rate;
        $description = $request->description;
        $start_date = $request->start_date;
        $end_date = $request->end_date;
        $table = 'jobdetails_tbl';
        $ins = array(
            'job_id' => $job_id,
            'job_title' => $job_title,
            'job_type' => $job_type,
            'hoursly_rate' => $hoursly_rate,
            'description' => $description,
            'start_date' => $start_date,
            'end_date' => $end_date
        );
        $result = $this->db->insert($table, $ins);
        if ($result > 0) {
            return true;
        } else {
            return false;
        }
    }

    function add_jobCategories($request) {
        $category_name = $request->category_name;
        $table = 'jobcategories_tbl';
        $ins = array(
            'category_name' => $category_name
        );
        $result = $this->db->insert($table, $ins);
        if ($result > 0) {
            return true;
        } else {
            return false;
        }
    }

    //forgot password
    function forgot_password($request) {
        $email = $request->email;
        $q = $this->db->query("select * from clients_tbl where email='" . $email . "'");
        $q1 = $this->db->query("select * from attorneys_tbl where email='" . $email . "'");

        if ($q->num_rows() > 0) {

            $r = $q->result();
            $user = $r[0];
            $this->load->helper('string');
            $password1 = random_string('alnum', 6);
            $password = md5($password1);
            $this->db->where('email', $user->email);
            $query = $this->db->query("update clients_tbl set password='$password' where email='" . $email . "'");
            $this->load->library('email');
            $this->email->from('johncollins0977@gmail.com', 'Contractor App');
            $this->email->to($user->email);
            $this->email->subject('Password reset');
            $this->email->message('You have requested the new password, Here is you new password:' . $password1);
            $this->email->send();
            return true;
        } else if ($q1->num_rows() > 0) {

            $r = $q1->result();
            $user = $r[0];
            $this->load->helper('string');
            $password1 = random_string('alnum', 6);
            $password = md5($password1);
            $this->db->where('email', $user->email);
            $query = $this->db->query("update attorneys_tbl set password='$password' where email='" . $email . "'");
            $this->load->library('email');
            $this->email->from('johncollins0977@gmail.com', 'Contractor App');
            $this->email->to($user->email);
            $this->email->subject('Password reset');
            $this->email->message('You have requested the new password, Here is you new password:' . $password1);
            $this->email->send();
            return true;
        } else {
            return false;
        }
    }
    // camp forgot password.

    function delete_client_record($request) {
        $client_id = $request->client_id;
        $this->db->where('client_id', $client_id);
        $result = $this->db->delete('clients_tbl');
        if ($result) {
            return true;
        } else {
            return false;
        }
    }

    function delete_contractor_record($request) {
        $contractor_id = $request->contractor_id;
        $this->db->where('attorney_id', $contractor_id);
        $result = $this->db->delete('attorneys_tbl');
        if ($result) {
            return true;
        } else {
            return false;
        }
    }

    //client profile details
    function client_profile_details($request) {
        $user_id = $request->userid;
        $query = $this->db->query("SELECT * FROM  clients_tbl where client_id='" . $user_id . "'");
        if ($query->num_rows() > 0) {
            foreach ($query->result_array('news') as $row) {
                $data['ClientId'] = $row['client_id'];
                $data['Username'] = $row['first_name'] . ' ' . $row['last_name'];
                $data['Email'] = $row['email'];
                $data['Mobile Number'] = $row['phone'];
                $data['Location'] = $row['location'];
                $data['Perfered Language'] = $row['prefer_lang'];
                $data['Preactice Area'] = $row['preactice_area'];
				 //$data['Bio'] = $row['bio'];
                $data['Languages Spoken'] = $row['language'];
                $data['Profile Image'] = $row['profile_img'];
				$data['Emergency Contact'] = $row['emergency_contact'];
                $data['Emergency Name'] = $row['emergency_name'];
                $var[] = $data;
            }
            return $var;
        } else {
            return false;
        }
    }

    function contractor_profile_details($request) {
        $user_id = $request->userid;
        $query = $this->db->query("SELECT * FROM  attorneys_tbl where attorney_id='" . $user_id . "'");
        if ($query->num_rows() > 0) {
            foreach ($query->result_array('news') as $row) {
                $data['ContractorId'] = $row['attorney_id'];
                $data['Username'] = $row['first_name'] . ' ' . $row['last_name'];
                $data['Email'] = $row['email'];
                $data['Location'] = $row['location'];
                $data['Mobile Number'] = $row['phone'];
                $data['Perfered Language'] = $row['prefer_lang'];
                $data['Preactice Area'] = $row['preactice_area'];
				 $data['Bio'] = $row['bio'];
                $data['Languages Spoken'] = $row['language'];
                $data['Profile Image'] = $row['image'];
                $var[] = $data;
            }
            return $var;
        } else {
            return false;
        }
    }

//contractor profile details
    function update_client_profile($request) {
		
        $userid = $request->userid;
        $email = $request->email;
        $location = $request->location;
        $mobile_number = $request->mobile_number;
        $preferred_language = $request->preferred_language;
        $preactice_area = $request->preactice_area;
        $bio = $request->bio;
        $language = $request->language_spoken;
		
		$emergency_number = $request->emergency_number;
        $emergency_name = $request->emergency_name;
		
        $profile_pic1 = base64_decode($request->profile_pic);
        $filename = uniqid() . '.png';
        $folder = FCPATH . 'upload/' . $filename;
        file_put_contents($folder, $profile_pic1);

        $query = $this->db->query("SELECT * FROM  clients_tbl where client_id='" . $userid . "'");
		$res = $query->row_array();
		
		if(isset($res['profile_img'])){
		$query12 = $this->db->query("update clients_tbl set profile_img = '' where client_id='" . $userid . "'");	
		
		}
		 if ($query->num_rows() > 0) {

            $table = 'clients_tbl';
            $ins = array(
                'email' => $email,
                'location' => $location,
                'phone' => $mobile_number,
                'bio' => $bio,
                'preactice_area' => $preactice_area,
                'prefer_lang' => $preferred_language,
                'language' => $language,
				'emergency_contact' => $emergency_number,
				'emergency_name' => $emergency_name,
                'profile_img' => base_url() . 'upload/' . $filename
            );

            $this->db->where('client_id', $userid);
            $result = $this->db->update($table, $ins);
            if ($result) {
                return true;
            } else {
                return false;
            }
        }
    }

    function update_contractor_profile($request) {
        $userid = $request->userid;
        $email = $request->email;
        $location = $request->location;
        $mobile_number = $request->mobile_number;

        $preferred_language = $request->preferred_language;
        $preactice_area = $request->preactice_area;
        $bio = $request->bio;
        $language_spoken = $request->language_spoken;
        $profile_pic1 = base64_decode($request->profile_pic);

        $filename = uniqid() . '.png';
        $folder = FCPATH . 'upload/' . $filename;
        file_put_contents($folder, $profile_pic1);

        $query = $this->db->query("SELECT * FROM  attorneys_tbl where attorney_id='" . $userid . "'");
		$res = $query->row_array();
		
		if(isset($res['image'])){
		$query12 = $this->db->query("update attorneys_tbl set image = '' where attorney_id='" . $userid . "'");	
	}
        if ($query->num_rows() > 0) {
            $table = 'attorneys_tbl';
            $ins = array(
                'email' => $email,
                'location' => $location,
                'phone' => $mobile_number,
                'bio' => $bio,
                'preactice_area' => $preactice_area,
                'prefer_lang' => $preferred_language,
                'language' => $language_spoken,
                'image' => base_url() . 'upload/' . $filename
            );

            $this->db->where('attorney_id', $userid);
            $result = $this->db->update($table, $ins);
            if ($result) {
                return true;
            } else {
                return false;
            }
        }
    }

    function change_client_password($request) {

        $userid = $request->userid;
        $oldpassword = md5($request->oldpassword);
        $newpassword = md5($request->newpassword);
        $query = $this->db->query("SELECT * FROM  clients_tbl where client_id='" . $userid . "' and password = '" . $oldpassword . "'");

        if ($query->num_rows() > 0) {
            $query12 = $this->db->query("update clients_tbl set password='" . $newpassword . "' where client_id='" . $userid . "'");
            if ($query12) {
                return true;
            } else {
                return false;
            }
        }
    }

    function change_attorney_password($request) {

        $userid = $request->userid;
        $oldpassword = md5($request->oldpassword);
        $newpassword = md5($request->newpassword);
        $query = $this->db->query("SELECT * FROM  attorneys_tbl where attorney_id='" . $userid . "' and password = '" . $oldpassword . "'");

        if ($query->num_rows() > 0) {
            $query12 = $this->db->query("update attorneys_tbl set password='" . $newpassword . "' where attorney_id='" . $userid . "'");
            if ($query12) {
                return true;
            } else {
                return false;
            }
        }
    }

    function payment($request) {
        $cardnumber = $request->cardnumber;
        $exp_date = $request->exp_date;
        $holder_name = $request->holder_name;
        $user_id = $request->user_id;
        $flag = $request->flag;

        $query = $this->db->query("SELECT payment_id  FROM  payment_tbl ORDER BY payment_id DESC");
        $res = $query->row_array();
        $unique_id = $res['payment_id'];
        $i = $unique_id + 1;
       $table = 'payment_tbl';
        $ins = array(
            'user_id' => $user_id,
            'holder_name' => $holder_name,
            'exp_date' => $exp_date,
            'card_number' => $cardnumber,
            'flag' => '1',
            'unique_card_id' => $i
        );
        $result = $this->db->insert($table, $ins);
        $last_id = $this->db->insert_id();
      
        if ($result > 0) {
            $query = $this->db->query("update payment_tbl set flag = '0' where payment_id !='" . $last_id . "' and user_id ='" . $user_id . "'");
           
            if ($query) {
                return true;
            }
        } else {
            return false;
        }
    }

    //cardList
    function delete_card($request) {
        $user_id = $request->user_id;
        $unique_id = $request->unique_id;
       $query = $this->db->query("delete from payment_tbl where unique_card_id ='" . $unique_id . "' and user_id ='" . $user_id . "'");
       
        if ($query) {
            return true;
        } else {
            return false;
        }
    }

    function cardList($request) {
        $user_id = $request->user_id;
        $query = $this->db->query("SELECT * FROM  payment_tbl where user_id='" . $user_id . "' and card_number !=''");
        if ($query->num_rows() > 0) {
            foreach ($query->result_array('news') as $row) {
                $data['UserId'] = $row['user_id'];
                $data['Card Number'] = $row['card_number'];
                $data['Holder Name'] = $row['holder_name'];
                $data['Expiry Date'] = $row['exp_date'];
                $data['Flag'] = $row['flag'];
                $data['UniqueId'] = $row['unique_card_id'];
                $var[] = $data;
            }
       return $var;
        } else {
            return false;
        }
    }

    function default_card($request) {

        $default_card_id = $request->unique_card_id;
        $user_id = $request->user_id;
        $query12 = $this->db->query("update payment_tbl set flag = '0' where unique_card_id !='" . $default_card_id . "' and user_id ='" . $user_id . "'");
        $query13 = $this->db->query("update payment_tbl set flag = '1' where unique_card_id ='" . $default_card_id . "'");
        $query = $this->db->query("SELECT * FROM  payment_tbl where user_id='" . $user_id . "'");

        if ($query->num_rows() > 0) {
            foreach ($query->result_array('news') as $row) {
                $data['UserId'] = $row['user_id'];
                $data['Card Number'] = $row['card_number'];
                $data['Holder Name'] = $row['holder_name'];
                $data['Expiry Date'] = $row['exp_date'];
                $data['Flag'] = $row['flag'];
                $data['UniqueId'] = $row['unique_card_id'];
               $var[] = $data;
            }
           return $var;
        } else {
            return false;
        }
    }

    function updateAttorneyLocation($request) {
        $attorney_id = $request->attorney_id;
        $latitude = $request->latitude;
        $longitude = $request->longitude;
       $query = $this->db->query("SELECT *  FROM  attorneys_tbl where attorney_id = '" . $attorney_id . "' ");
        if ($query->num_rows() > 0) {
            $table = 'attorneys_tbl';
            $ins = array(
                'latitude' => $latitude,
                'longitude' => $longitude
            );

            $this->db->where('attorney_id', $attorney_id);
            $result = $this->db->update($table, $ins);
            if ($result) {
                return true;
            } else {
                return false;
            }
        }
    }
 
    function requestList($request) {
     $attorney_id = $request->attorney_id;
	 $current_date = date('Y-m-d H:i:s');
  
   $query = $this->db->query("SELECT rl.flag as accept_flag ,rl.*,ra.*  from request_list rl join requested_attorney_details ra on(ra.request_id=rl.request_id)where ra.attorney_id='" . $attorney_id . "' and ra.cancel='0' and ra.distance !='' and rl.request_date != '' and request_date >'$current_date' and ra.request_cancel_flag='0'");
  
  
 
	   $req_list = $query->result_array();
	  
	
	  if ($query->num_rows() > 0) {
		 foreach ($query->result_array('news') as $row) {
				if($row['accept_flag']==''){
			   $req_date = $row['request_date'];
				 //$new = date('D jS M H:i', strtotime($req_date));  
				 $new = date('M d, Y h:m a', strtotime($req_date));  
				 $dis = $row['distance'];
                $dis1 = round($dis,2);
                $data['Request_id'] = $row['request_id'];
                $data['Request Type'] = $row['request_type'];
                $data['UserId'] = $row['user_id'];
                $data['Latitude'] = $row['latitude'];
                $data['Longitude'] = $row['longitude'];
                $data['Pickup Address'] = $row['pickup_address'];
                 $data['Distance'] = $dis1.'KM';
                 $data['Description'] = $row['description'];
                 $data['Date and Time='] = $new;
                 $var[] = $data;
				}
           
		}
		 return $var;
        } else {
            return false;
        }
    }
    
   function ratingToAttorney($request) {
        $request_id = $request->request_id;
        $client_id = $request->client_id;
        $rating  = $request->rating;
        $query = $this->db->query("select * from request_list where request_id ='" . $request_id . "'");
        $res = $query->row_array();
        $real_client_id = $res['user_id'];
       $table = 'attorney_rating';
        $ins = array(
            'request_id' => $request_id,
            'rating_client_id' => $real_client_id,
            'client_id' => $client_id,
            'rating' => $rating
           
        );
        $result = $this->db->insert($table, $ins);
       if($result){
        
       
            return true;
        } else {
            return false;
        }
    }
   
   function receiptInformation($request) {
        $professionalism = $request->professionalism;
		$timelines = $request->timelines;
		$communication_skill = $request->communication_skill;
		$legal_knowledge = $request->legal_knowledge;
		$overall = $request->overall;
        $attorney_id = $request->attorney_id;
        $client_id = $request->client_id;
        $request_id  = $request->request_id;
		
		
        $current_date = date('Y-m-d H:i:s');
        $table = 'receipt_tbl';
		if($rating>5){
			 return false;
		}
		else{
        $ins = array(
            'professionalism_rating' => $professionalism,
			'timelines_rating' => $timelines,
			'communication_skill_rating' => $communication_skill,
			'legal_knowledge_rating' => $legal_knowledge,
			'overall_rating' => $overall,
            'attorney_id' => $attorney_id,
            'client_id' => $client_id,
            'request_id' => $request_id,
            'date_created' => $current_date
           
        );
        $result = $this->db->insert($table, $ins);
		}
        if ($result > 0) {
			
            return true;
        }
				else {
            return false;
        }
    }
     
   function tipsInformation($request) {
        $tips = $request->tips;
        $attorney_id = $request->attorney_id;
        $client_id = $request->client_id;
        $request_id  = $request->request_id;
        $current_date = date('Y-m-d H:i:s');
        $table = 'tips_tbl';
        $ins = array(
            'tips' => $tips,
            'attorney_id' => $attorney_id,
            'client_id' => $client_id,
            'request_id' => $request_id,
            'date_created' => $current_date
           
        );
        $result = $this->db->insert($table, $ins);
        if ($result > 0) {
			
            return true;
        } else {
            return false;
        }
    }
      
	function default_payment($request) {
        $cardId = $request->cardId;
        $userid = $request->userid;
        $flag  = $request->flag ;
         if($flag=='1'){
          $query = $this->db->query("update payment_tbl set flag='0'");    
       }
      $table = 'payment_tbl';
        $ins = array(
            'user_id' => $userid,
            'cardId' => $cardId,
            'flag' => $flag
           
        );
        $result = $this->db->insert($table, $ins);
       
        if (($result > 0)&&($query)) {
            return true;
        } else {
            return false;
        }
    }
	
	//message information api
	function messageInformation($request) {
        $client_id = $request->client_id;
        $attorney_id = $request->attorney_id;
        $flag = $request->flag;
        $message  = $request->message;
        $current_date = date('Y-m-d H:i:s');
        $table = 'message_tbl';
        $ins = array(
            
            'attorney_id' => $attorney_id,
            'client_id' => $client_id,
            'message' => $message,
			'flag' => $flag,
            'date_time' => $current_date
           
        );
        $result = $this->db->insert($table, $ins);
        if ($result > 0) {
			
            return true;
        } else {
            return false;
        }
    }
	//get api for message List
	function messageList($request) {
		
        $attorney_id = $request->attorney_id;
		$client_id = $request->client_id;
        $query = $this->db->query("SELECT * FROM  message_tbl where attorney_id='" . $attorney_id . "'  and client_id ='".$client_id."'");
		$res = $query->result_array();

           if (isset($res)) {
           foreach ($res as $row) {
               
                $data['MessageId'] = $row['message_id'];
                $data['Attorney Id'] = $row['attorney_id'];
                $data['Client Id'] = $row['client_id'];
                $data['Message'] = $row['message'];
                $data['Flag'] = $row['flag'];
                $data['Date And Time'] = $row['date_time'];
                $var[] = $data;
			}
           return $var;
		   
        } else {
            return false;
        }
    }
	
	//retainer Agreement
	function retainerAgreement($request) {
        $attorneyId      = $request->attorney_id;
        $client_id       = $request->client_id;
        $request_id      = $request->request_id;
        $agreement_text  = $request->agreement_text ;
		$flag            = $request->flag ;
		
		$getcon_email   = $this->db->query("SELECT * FROM attorneys_tbl where attorney_id='" . $attorneyId . "'");
		$con_res        = $getcon_email->row_array();
		$attorney_name  = $con_res['first_name'].' '.$con_res['last_name'];
		$attorney_email = $con_res['email'];
		
		$getclient_email = $this->db->query("SELECT * FROM  clients_tbl where client_id='" . $client_id . "'");
		$client_res      = $getclient_email->row_array();
		$client_name     = $client_res['first_name'].' '.$client_res['last_name'];
		$client_email    = $client_res['email'];
		
	    $current_date = date('Y-m-d H:i:s');
        $table = 'retainerAgreement_tbl';
        $ins = array(
            'attorney_id'    => $attorneyId,
            'client_id'      => $client_id,
            'request_id'     => $request_id,
            'agreement_text' => $agreement_text,
			'flag'           => $flag,
            'date_time'      => $current_date
      );
        $result = $this->db->insert($table, $ins);
        if ($result > 0) {
					//for sending mail to attorney and client
		if(isset($client_email)){
		    $this->load->library('email');
            $this->email->from('support@asapesq.com', 'ContractorApp');
            $this->email->to($client_email);
            $this->email->subject('Retainer Agreement');
            $this->email->message($agreement_text);
            $this->email->send();
		}
		
		if(isset($attorney_email)){
		    $this->load->library('email');
            $this->email->from('support@asapesq.com', 'ContractorApp');
            $this->email->to($attorney_email);
			$this->email->subject('Retainer Agreement');
            $this->email->message($agreement_text);
            $this->email->send();
		}
		if($flag == 'client'){
			 $agree_query = $this->db->query("update request_list set agree_by_client='1' where request_id='".$request_id."'");
		}
		if($flag == 'contractor'){
		$agree_query = $this->db->query("update request_list set agree_by_attorney='1' where request_id='".$request_id."'");	
		}
			
            return true;
        } else {
            return false;
        }
    }
    
    }
    
    


