<?php
class indservices{
	function __construct($conn){
		$this->mySQLconn=$conn;
	}
	function indiinsert($curdate){
	  $receivedid=$this->indinsertdetails($curdate);
	  $lastid=$receivedid;
	  if(is_numeric($lastid)){
		$agentinsertlastmsg=$this->indcodegeneration($lastid);
		if($agentinsertlastmsg==true){
			return true;
		}
		else{
			return false;
		}
	  }
	  else{
		return $receivedid; 
	  }	
	}
	function indinsertdetails($curdate){
	
		
		$firstname=str_replace("'","^",$_POST['firstname']);
		$lastname=str_replace("'","^",$_POST['lastname']);
		$gender=str_replace("'","^",$_POST['gender']);
		$dojoname=str_replace("'","^",$_POST['dojoname']);
		$dob=str_replace("'","^",$_POST['dob']);
		$addr=str_replace("'","^",$_POST['addr']);
		$addr2=str_replace("'","^",$_POST['addr2']);
		$city=str_replace("'","^",$_POST['city']);
		$province=str_replace("'","^",$_POST['province']);
		$pcode=str_replace("'","^",$_POST['pcode']);
		$phone=str_replace("'","^",$_POST['phone']);
		$phone2=str_replace("'","^",$_POST['phone2']);
		$pmail=str_replace("'","^",$_POST['pmail']);
		$dcemail=str_replace("'","^",$_POST['dcemail']);
		$gfirstname=htmlspecialchars($_POST['gfirstname']);
		$glastname=htmlspecialchars($_POST['glastname']);
		$gmbl=str_replace("'","^",$_POST['gmbl']);
		$gmbl2=str_replace("'","^",$_POST['gmbl2']);
		$gmail=str_replace("'","^",$_POST['gmail']);
		$ptype=str_replace("'","^",$_POST['ptype']);
		$para=str_replace("'","^",$_POST['para']);
		$elite=str_replace("'","^",$_POST['elite']);
		$belt=str_replace("'","^",$_POST['belt']);
		$participate=str_replace("'","^",$_POST['participate']);
		
		
		$sql= "INSERT INTO tbl_individualclient ( dojo_name, firstname, lastname, gender, dob, addr1, addr2, city, province, pcode, phone1, phone2, email, commemail, gfirstname, glastname, gphone1, gphone2, gemail, ptype, para, elite, belt, partype,created_by,create_date) VALUES('".$dojoname."','".$firstname."','".$lastname."','".$gender."',str_to_date('".$dob."','%m/%d/%Y'),'".$addr."','".$addr2."','".$city."','".$province."','".$pcode."','".$phone."','".$phone2."','".$pmail."','".$dcemail."','".$gfirstname."','".$glastname."','".$gmbl."','".$gmbl2."','".$gmail."','".$ptype."','".$para."','".$elite."','".$belt."','".$participate."','".$firstname."','".date('y-m-d')."')";
	    $exec_query=mysqli_query($this->mySQLconn, $sql);
		if($exec_query){
			$last_id=mysqli_insert_id($this->mySQLconn);
			return $last_id;
		}
		else{
			 return $sql;
		}
	}
	
	function indcodegeneration($lastid){
		$code_sql= "update tbl_individualclient set incus_code=concat('IND10','".$lastid."'),created_by=concat('IND10','".$lastid."') where incl_id='".$lastid."'";
	    $code_exec_query=mysqli_query($this->mySQLconn, $code_sql);
		if($code_exec_query){
			return true;
		}
		else{
			 return false;
		}
	}
		
	
	function agentautobind($empid){
		$customerData=array();
		$customer="SELECT *,group_concat(distinct t2.name separator ' / ') as city,
group_concat(distinct t3.name separator ' / ') as country,
group_concat(distinct t4.name separator ' / ') as state
FROM tbl_agents t1
inner join tbl_citiesname t2 on t1.ctid=t2.ctid
inner join tbl_countrysname t3 on t1.cid=t3.cid
inner join tbl_statesname t4 on t1.sid=t4.sid
where ag_id='".$empid."'";
		$customerquery=mysqli_query($this->mySQLconn,$customer);
		$rows=mysqli_num_rows($customerquery);
		if($rows>0){
			while($row=mysqli_fetch_array($customerquery,MYSQLI_ASSOC)){
				$customerData[]=str_replace("^","'",$row);		
			}
		}
		return $customerData;
	}
	function profileautobind(){
		$rdata=array();
		$IdCheck="select aboutus from tbl_clients_business where cl_id='".$_POST['clid']."'";
        $exec_IdCheck=mysqli_query($this->mySQLconn,$IdCheck);
		if($exec_IdCheck){
			$row=mysqli_fetch_array( $exec_IdCheck,MYSQLI_ASSOC);
			$aboutus=str_replace("^","'",html_entity_decode($row['aboutus']));
			$rdata[]=true;
			$rdata[]=$aboutus;
		}
		else{
				$rdata[]=false;
		}
		return $rdata;
	}
	
}		
?>