<?php
class dojservices{
	function __construct($conn){
		$this->mySQLconn=$conn;
	}
	function dojoinsert($curdate){
	  $receivedid=$this->dojoinsertdetails($curdate);
	  $lastid=$receivedid;
	  if(is_numeric($lastid)){
		$agentinsertlastmsg=$this->dojocodegeneration($lastid);
		$lastid1=$agentinsertlastmsg;
		if(is_numeric($lastid1)){
		$agentinsertaddress=$this->dojoaddress($lastid1);
		if($agentinsertaddress==true){
			return true;
		}
		else{
		return false;	
		}
		}
		else{
			return $agentinsertlastmsg;
		}
	  }
	  else{
		return $receivedid; 
	  }	
	}
	
	
	
	function dojoinsert1($curdate){
	  $receivedid=$this->dojoinsertdetails1($curdate);
	  $lastid=$receivedid;
	  if(is_numeric($lastid)){
		$agentinsertlastmsg=$this->dojocodegeneration($lastid);
		$lastid1=$agentinsertlastmsg;
		if(is_numeric($lastid1)){
		$agentinsertaddress=$this->dojoaddress($lastid1);
		if($agentinsertaddress==true){
		$agentinsertname=$this->dojoname();
		if($agentinsertname==true){
			return true;
		}
		else{
			return $agentinsertname;
		}
		}
		else{
		return false;	
		}
		}
		else{
			return $agentinsertlastmsg;
		}
	  }
	  else{
		return $receivedid; 
	  }	
	}
	
	
	
	
	
	
	
	
	
	
	function dojoinsertdetails($curdate){
	
		
		$dojoname=str_replace("'","^",$_POST['dojoname']);
		$dojoweb=str_replace("'","^",$_POST['dojoweb']);
		/*$dojoAdd=str_replace("'","^",$_POST['dojoAdd']);
		$dojoAdd2=str_replace("'","^",$_POST['dojoAdd2']);
		$dojocity=str_replace("'","^",$_POST['dojocity']);
		$dojocode=str_replace("'","^",$_POST['dojocode']);*/
		$dojodmail=str_replace("'","^",$_POST['dojodmail']);
		$dojodmail2=str_replace("'","^",$_POST['dojodmail2']);
		$dojodcity=str_replace("'","^",$_POST['dojodcity']);
		$dojodcode=str_replace("'","^",$_POST['dojodcode']);
		$dojodmbl=str_replace("'","^",$_POST['dojodmbl']);
		$dojodmbl2=str_replace("'","^",$_POST['dojodmbl2']);
		$dojodemail=str_replace("'","^",$_POST['dojodemail']);
		$dojodcemail=str_replace("'","^",$_POST['dojodcemail']);
		$spractice=htmlspecialchars($_POST['spractice']);
		$spracticent=htmlspecialchars($_POST['spracticent']);
		$sassoc=str_replace("'","^",$_POST['sassoc']);
		$sassocnt=str_replace("'","^",$_POST['sassocnt']);
		$prmethod=str_replace("'","^",$_POST['prmethod']);
		$dojofirstname=str_replace("'","^",$_POST['dojofirstname']);
		$dojolastname=str_replace("'","^",$_POST['dojolastname']);
		$dojomainmbl=str_replace("'","^",$_POST['dojomainmbl']);
		$dojomainmbl2=str_replace("'","^",$_POST['dojomainmbl2']);
		$dojomainemail=str_replace("'","^",$_POST['dojomainemail']);
		$dojoinfirstname=str_replace("'","^",$_POST['dojoinfirstname']);
		$dojoinlastname=str_replace("'","^",$_POST['dojoinlastname']);
		$nccpdesig=str_replace("'","^",$_POST['nccpdesig']);
		$danlevel=str_replace("'","^",$_POST['danlevel']);
		$eventid=str_replace("'","^",$_POST['eventid']);
		
		$sql= "INSERT INTO tbl_dojoclient (dojo_name, dojo_website, dojo_mailaddr1, dojo_mailaddr2, dojo_mailcity, dojo_mail_pcode, dojo_mailphone1, dojo_mailphone2, dojo_mailemail, dojo_commemail, dojo_stylepractise, dojo_stylepractisent, styleassoc, styleassocnt, dojo_commmethod, dojo_firstname, dojo_lastname, dojo_mobile, dojo_mobile2, dojo_email, dojo_insfirstname, dojo_inslastname, dojo_nccp, dojo_danlevel, dojo_membership,created_by,create_date ) VALUES('".$dojoname."','".$dojoweb."','".$dojodmail."','".$dojodmail2."','".$dojodcity."','".$dojodcode."','".$dojodmbl."','".$dojodmbl2."','".$dojodemail."','".$dojodcemail."','".$spractice."','".$spracticent."','".$sassoc."','".$sassocnt."','".$prmethod."','".$dojofirstname."','".$dojolastname."','".$dojomainmbl."','".$dojomainmbl2."','".$dojomainemail."','".$dojoinfirstname."','".$dojoinlastname."','".$nccpdesig."','".$danlevel."','".$eventid."','".$dojofirstname."','".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 dojoinsertdetails1($curdate){
	
		
		$dojoname=str_replace("'","^",$_POST['dojonameins']);
		$dojoweb=str_replace("'","^",$_POST['dojoweb']);
		/*$dojoAdd=str_replace("'","^",$_POST['dojoAdd']);
		$dojoAdd2=str_replace("'","^",$_POST['dojoAdd2']);
		$dojocity=str_replace("'","^",$_POST['dojocity']);
		$dojocode=str_replace("'","^",$_POST['dojocode']);*/
		$dojodmail=str_replace("'","^",$_POST['dojodmail']);
		$dojodmail2=str_replace("'","^",$_POST['dojodmail2']);
		$dojodcity=str_replace("'","^",$_POST['dojodcity']);
		$dojodcode=str_replace("'","^",$_POST['dojodcode']);
		$dojodmbl=str_replace("'","^",$_POST['dojodmbl']);
		$dojodmbl2=str_replace("'","^",$_POST['dojodmbl2']);
		$dojodemail=str_replace("'","^",$_POST['dojodemail']);
		$dojodcemail=str_replace("'","^",$_POST['dojodcemail']);
		$spractice=htmlspecialchars($_POST['spractice']);
		$spracticent=htmlspecialchars($_POST['spracticent']);
		$sassoc=str_replace("'","^",$_POST['sassoc']);
		$sassocnt=str_replace("'","^",$_POST['sassocnt']);
		$prmethod=str_replace("'","^",$_POST['prmethod']);
		$dojofirstname=str_replace("'","^",$_POST['dojofirstname']);
		$dojolastname=str_replace("'","^",$_POST['dojolastname']);
		$dojomainmbl=str_replace("'","^",$_POST['dojomainmbl']);
		$dojomainmbl2=str_replace("'","^",$_POST['dojomainmbl2']);
		$dojomainemail=str_replace("'","^",$_POST['dojomainemail']);
		$dojoinfirstname=str_replace("'","^",$_POST['dojoinfirstname']);
		$dojoinlastname=str_replace("'","^",$_POST['dojoinlastname']);
		$nccpdesig=str_replace("'","^",$_POST['nccpdesig']);
		$danlevel=str_replace("'","^",$_POST['danlevel']);
		$eventid=str_replace("'","^",$_POST['eventid']);
		
		$sql= "INSERT INTO tbl_dojoclient (dojo_name, dojo_website, dojo_mailaddr1, dojo_mailaddr2, dojo_mailcity, dojo_mail_pcode, dojo_mailphone1, dojo_mailphone2, dojo_mailemail, dojo_commemail, dojo_stylepractise, dojo_stylepractisent, styleassoc, styleassocnt, dojo_commmethod, dojo_firstname, dojo_lastname, dojo_mobile, dojo_mobile2, dojo_email, dojo_insfirstname, dojo_inslastname, dojo_nccp, dojo_danlevel, dojo_membership,created_by,create_date ) VALUES('".$dojoname."','".$dojoweb."','".$dojodmail."','".$dojodmail2."','".$dojodcity."','".$dojodcode."','".$dojodmbl."','".$dojodmbl2."','".$dojodemail."','".$dojodcemail."','".$spractice."','".$spracticent."','".$sassoc."','".$sassocnt."','".$prmethod."','".$dojofirstname."','".$dojolastname."','".$dojomainmbl."','".$dojomainmbl2."','".$dojomainemail."','".$dojoinfirstname."','".$dojoinlastname."','".$nccpdesig."','".$danlevel."','".$eventid."','".$dojofirstname."','".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 dojocodegeneration($lastid){
		$code_sql= "update tbl_dojoclient set cus_code=concat('DOJO10','".$lastid."'),created_by=concat('DOJO10','".$lastid."') where djcl_id='".$lastid."'";
	    $code_exec_query=mysqli_query($this->mySQLconn, $code_sql);
		if($code_exec_query){
			return $lastid;
		}
		else{
			 return false;
		}
	}
	
	
	function dojoaddress($lastid1){	
	foreach ($_POST['benif_data'] as $key => $val) {
	
	$sql2= "INSERT INTO tbl_dojodetails (djcl_id,dojo_addr1,dojo_addr2,dojo_city,dojo_pcode) VALUES('".$lastid1."','".$val[0]."','".$val[1]."','".$val[2]."','".$val[3]."')";
	    $exec_query2=mysqli_query($this->mySQLconn, $sql2);
		}
		if($exec_query2){
			
			return true;
	}
	
	else{
		 return $sql2."Due to technical issue Details not registered";
	}
	
	
	}
	
	function dojoname(){
		$dojoname=str_replace("'","^",$_POST['dojonameins']);
		$code_sql= "insert into tbl_dojoname (dojo_Name) values('".$dojoname."')";
	    $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;
	}
	
}		
?>