<?php

	require_once("../include/config.php");	
	require_once("../include/startup.php");
	require_once("../include/classes/validation.class.php");
	require_once("../include/check_admin_login.php");

	
	$validation = new Validation();
	$obj = new AllTables();
	
	$memberid	    				= $_POST['txtmemberid'];
	$membercompanyid	    		= $_POST['txtmembercompanyid'];
	$company_name	    				= $_POST['txturcompany_name'];
	$firstname	    				= $_POST['txtcustomerName'];
	$lastname	    				= $_POST['txtcustomerlastName'];
	$addline						= $_POST['txtaddline'];
	$addline1						= $_POST['txtAddline1'];
	$email		    				= $_POST['txtcustomerEmail'];
	$mobile		 					= $_POST['txtcustomerMobileno'];
	$customerTelephoneno			= $_POST['txtcustomerTelephoneno'];
	$password		 				= $_POST['txtpassword'];
	$DOB							= $_POST['txtDOB'];
	$gender							= $_POST['txtgender'];
	$pincode						= $_POST['txtpincode'];
	$state							= $_POST['txtstate'];
	$country						= $_POST['txtcountry'];
	$head_CityName					= $_POST['txthead_CityName'];


	
	//Check Validation
	$error_company_name 	= $validation->check_blank($company_name, 'Company Name');
	$error_firstname 	= $validation->check_blank($firstname, 'First Name');
	$error_lastname 	= $validation->check_blank($lastname, 'Last Name');
	$error_email 		= $validation->check_email($email, 'Email');
	$error_mobile 		= $validation->check_contact($mobile, 'Contact No');
	$error_password 	= $validation->check_password($password, 'Password');
	$error_address	 	= $validation->check_blank($addline, 'Address');
	$error_address1	 	= $validation->check_blank($addline1, 'Address');
	$error_pincode 	= $validation->check_pincode($pincode, 'Pincode');
	$error_city 		= $validation->check_blank($head_CityName	, 'City');
	$error_state 		= $validation->select_blank($state, 'State');
	$error_country 	= $validation->select_blank($country, 'Country');
	
	$errorarray = array();
	
	if($error_company_name){
			$array = array('txtcustomercompany_nameerror' => $error_company_name);
			array_push($errorarray , $array);
	}else{
			$array = array('txtcustomercompany_nameerror' => '');
			array_push($errorarray , $array);
	}

	if($error_firstname){
			$array = array('txtcustomerNameerror' => $error_firstname);
			array_push($errorarray , $array);
	}else{
			$array = array('txtcustomerNameerror' => '');
			array_push($errorarray , $array);
	}
	
	if($error_lastname){
			$array = array('txtcustomerlastNameerror' => $error_lastname);
			array_push($errorarray , $array);
	}else{
			$array = array('txtcustomerlastNameerror' => '');
			array_push($errorarray , $array);
	}
	
	if($error_email){
			$array = array('txtcustomerEmailerror' => $error_email);
			array_push($errorarray , $array);
	}else{
			$array = array('txtcustomerEmailerror' => '');
			array_push($errorarray , $array);
	}
	
	
	if($error_mobile){
			$array = array('txtcustomerMobilenoerror' => $error_mobile);
			array_push($errorarray , $array);
	}else{
			$array = array('txtcustomerMobilenoerror' => '');
			array_push($errorarray , $array);
	}
	
	if($error_mobile){
			$array = array('txtcustomerTelephonenoerror' => $error_telephone);
			array_push($errorarray , $array);
	}else{
			$array = array('txtcustomerTelephonenoerror' => '');
			array_push($errorarray , $array);
	}
	
	if($error_password){
			$array = array('txtpassworderror' => $error_password);
			array_push($errorarray , $array);
	}else{
			$array = array('txtpassworderror' => '');
			array_push($errorarray , $array);
	}
	
	
	if($error_address){
			$array = array('txtcustomerAddlineerror' => $error_address);
			array_push($errorarray , $array);
	}else{
			$array = array('txtcustomerAddlineerror' => '');
			array_push($errorarray , $array);
	}
	
	if($error_address1){
			$array = array('txtcustomerAddline1error' => $error_address1);
			array_push($errorarray , $array);
	}else{
			$array = array('txtcustomerAddline1error' => '');
			array_push($errorarray , $array);
	}
	
	
	if($error_pincode){
			$array = array('txtcustomerpinerror' => $error_pincode);
			array_push($errorarray , $array);
	}else{
			$array = array('txtcustomerpinerror' => '');
			array_push($errorarray , $array);
	}
	
	
	if($error_city){
			$array = array('custcityerror' => $error_city);
			array_push($errorarray , $array);
	}else{
			$array = array('custcityerror' => '');
			array_push($errorarray , $array);
	}
	
	
	/*if($error_state){
			$array = array('custstateerror' => $error_state);
			array_push($errorarray , $array);
	}else{
			$array = array('custstateerror' => '');
			array_push($errorarray , $array);
	}
	*/
	
	if($error_country){
			$array = array('custcountryerror' => $error_country);
			array_push($errorarray , $array);
	}else{
			$array = array('custcountryerror' => '');
			array_push($errorarray , $array);
	}
	
	$newArray = array();
	
	foreach($errorarray as $key => $value) {
		
	    foreach($value as $key2 => $value2) {
	    	
	        $newArray[$key2] = $value2;
	    }
	}
	
	$errorcount = 0;
	foreach($newArray as $key3 => $value3){
		if($value3 != ''){
			$errorcount ++;
		}
	}
	
	if($errorcount > 0)
	{
		echo json_encode($newArray);
	}else
	{
		/*$sql="SELECT * FROM trnuser_company where head_Email = '$email'";
		$checkemail = $obj-> getInfo("",$sql);
		
		if(count($checkemail) > 0){
		
		
				$errorarray = array('emailerror' => 'Email ID Already Exists !');
				echo json_encode($errorarray);
		}else{*/
			$memberid=$_POST['txtmemberid'];
			$edit_membercompanyid=$_POST['txtmembercompanyid'];
				$NewProduct['memberid']	    				= $_POST['txtmemberid'];
				$NewProduct['membercompanyid']	    		= $_POST['txtmembercompanyid'];
					
				$NewProduct['user_companyname']	    				= $_POST['txturcompany_name'];
				$NewProduct['MemberName']	    				= $_POST['txtcustomerName'];
				$NewProduct['MemberSurName']	    				= $_POST['txtcustomerlastName'];
				$NewProduct['head_Email']			    			= $_POST['txtcustomerEmail'];
				$NewProduct['head_Mob_no']		 				= $_POST['txtcustomerMobileno'];
				$NewProduct['user_password']		 				= $_POST['txtpassword'];
				$NewProduct['entry_date']		 		= date("Y-m-d");
				
				$NewProduct['dateofbirth']		    		= $_POST['txtDOB'];
				$NewProduct['Addline1']		    		= $_POST['txtaddline'];
				$NewProduct['Addline2']		    		= $_POST['txtAddline1'];
							
				
				$NewProduct['head_Pin']		    		= $_POST['txtpincode1'];
				$city 		= explode("-", $_POST['txthead_CityName']);
				$state 		= explode("-", $_POST['txtstate']);
				$country 	= explode("-", $_POST['txtcountry']);
				
				$NewProduct['head_CityName']			 	= $city[1];
				$NewProduct['head_Stateid']		 			= $state[0];
				$NewProduct['head_StateName']		 		= $state[1];
			
				$NewProduct['Country']		 			= $country[1];	
				
				//print_r($NewProduct);
				//echo $NewProduct;
				//$productadd = $obj-> AddInfo($NewProduct,"trnuser_company");
					$wherecondition = "membercompanyid = ".$edit_membercompanyid;
				$productadd = $obj -> EditInfo($NewProduct,$wherecondition,"trnuser_company");
				//echo $productadd;
				//print_r($productadd);
				//die();
				if($productadd){
						//$txtusername  	= $_POST['txtcustomerEmail'];
						//$txtpassword  	= $_POST['txtpassword'];
						//$checklogin  	= checkadminlogin($txtusername,$txtpassword);
						//if($checklogin)
					   //{		
					   		$errorarray = array('success' => 'success');
								echo json_encode($errorarray);						
					   //}
						//else
						//{
						//		$errorarray = array('loginerror' => 'Invalid Username Or Password !');
						//		echo json_encode($errorarray);
				      //}
				}else{
						$errorarray = array('loginerror' => 'Record not add!');
						echo json_encode($errorarray);
				}
				
		//}
	}
	
	
?>