<?php 

if(isset($_POST['postReg'])){ $ref = $_SERVER['HTTP_REFERER'];
$selpassword = hash('sha256',collect('myPass'));
if($linkr->queryCount('customers',array('frm_phone'=>collect('eqPhone')))>0){
print "<script>swal({text:'email/phone already exists',type:'warning',title:'Duplicate Attempt'},function(){ });</script>"; 
}else{ $letters = code_generator(3); $country =collect('state'); $state =collect('lga');
 $insert_into_reg =QueryDB("INSERT INTO customers VALUES ('','".collect('eqName')."','".collect('eqPhone')."','".collect('eqEmail')."','".date('m')."','".date('Y')."','".date('Y-m-d')."','".time()."','online','".$_POST['eqSex']."','$letters','$country','$state','','','2','0','$selpassword') ");

//send SMS
$_SESSION['mycus'] = get_cus_id(collect('eqEmail'));
if(isset($_SESSION['directory'])){ $loc = $_SESSION['directory'].'.html';

	print "<script>swal({text:'Registration was Successful',type:'success',title:'Approved'},function(){ window.location = '$loc';});</script>"; 
}else{
print "<script>swal({text:'Customer captured',type:'success',title:'Approved'},function(){ window.location = '$ref';});</script>"; 	
}
}

}



//Post reviews
if(isset($_POST['sendreviews'])){
QueryDB("INSERT INTO reviews VALUES('','$webPID','".time()."','".$_SESSION['mycus']."','".collect('textMsg')."','".collect('rating')."',0) ");
print "<script>swal({text:'Thanks for your review',type:'success',title:'Approved'},function(){ window.location = '';});</script>"; 

}


//modify user Basic Information
if(isset($_POST['EditReg'])){
QueryDB("UPDATE customers SET frm_phone='".collect('eqPhone')."',country='".collect('pcountry')."',state='".collect('pstate')."',address ='".collect('eqAddress')."' where id='".$_SESSION['mycus']."' ");
print "<script>swal({text:'Detailed Modified',type:'success',title:'Approved'},function(){ window.location = 'home';});</script>"; 
}

//change Password
if(isset($_POST['chgPass'])){
if($results['password']==hash('sha256',$_POST['currPass'])){

if($_POST['newPass']==$_POST['newPass_']){ $new_set_password =hash('sha256',$_POST['newPass_']);
QueryDB("UPDATE customers SET password='$new_set_password' where id='".$_SESSION['mycus']."' ");
print "<script>swal({text:'Password Modified',type:'success',title:'Approved'},function(){ window.location = 'home';});</script>";
}else{
	print "<script>swal({text:'Passwords do not match',type:'warning',title:'Error'},function(){ });</script>"; 
}

}else{
	print "<script>swal({text:'Invalid',type:'warning',title:'Error'},function(){ window.location = 'home';});</script>"; 
}


}



//Update Billing
if(isset($_POST['order'])){
if(QueryDB("SELECT COUNT(*) FROM biller where receipt_id ='".collect('rowNumber')."' and user_id='".$_SESSION['mycus']."' ")->fetchColumn()>0){
//biller EXists
$getIt=QueryDB("SELECT * FROM payment where cus_id ='".$_SESSION['mycus']."' and pay_status=0 ");
$rhoda = $getIt->fetch(PDO::FETCH_ASSOC);
$biller = getBiller($rhoda['id']); $bill = explode(',',$biller['organization']);
$bill[0]=collect('receiver'); $bill[1]=collect('eqPhone'); $bill[2]=collect('email');
$bill[3]=collect('eqSex'); $bill[4]=collect('pcountry'); $bill[5]=collect('pstate');
$bill[6]=collect('landmark'); $bill[7]=collect('address'); $bill[8]=collect('note');

QueryDB("UPDATE biller SET organization='".implode(',',$bill)."',date_time='".date('Y-m-d H:i:s')."' where user_id='".$_SESSION['mycus']."' ");
QueryDB("UPDATE payment SET receipt_id='".$_SESSION['chargeCode']."',pay_mth='".collect('payment')."' where id='".collect('rowNumber')."' ");
$_SESSION['chargeEmail'] =collect('userEmail');
		$_SESSION['chargeAmount'] =collect('totalPay');
		$_SESSION['chargeCode'] =md5(code_generator(15));

		if(collect('payment')==1){
			//paystack
		}else{
			//flutterwave
		}

}else{
	//Biller Does not Exists
	$arrays =collect('receiver').','.collect('eqPhone').','.collect('email').','.collect('eqSex').','.collect('pcountry').','.collect('pstate').','.collect('landmark').','.collect('address').','.collect('note');
	QueryDB("INSERT INTO biller VALUES('','".$_SESSION['mycus']."','".collect('rowNumber')."','$arrays','".date('Y-m-d H:i:s')."',1,'','') ");

		$_SESSION['chargeEmail'] =collect('userEmail');
		$_SESSION['chargeAmount'] =collect('totalPay');
		$_SESSION['chargeCode'] =md5(code_generator(15));
	QueryDB("UPDATE payment SET receipt_id='".$_SESSION['chargeCode']."',pay_mth='".collect('payment')."' where id='".collect('rowNumber')."' ");
	if(collect('payment')==1){
			//paystack
		}else{
			//flutterwave
		}
}

print "<script>swal({text:'Click ok to Proceed',type:'success',title:'Payment'},function(){ window.location = '';});</script>"; 
 	


}











?>