<?php

require __dir__ . '/init.php';


if(isset($_POST['transfer'])){
    
	$image = help::process_image( $_FILES['image'] );
	
	if( $image['error_msg'] ) $msg = $image['error_msg'];
	
	else {
		
		$name = md5(basename($image['name'])) . "." . $image['extension'];
		$target = PANEL_DIR . "/uploads/KYC/{$name}";
		
		$SQL = sQuery::update('tbl_users', array('kyc_image' => $name), "email='{$__user['email']}'");
		
		$updated = $link->query( $SQL );
		$moved = move_uploaded_file($image['tmp_name'], $target); 

		$msg =  ($updated && $moved) ? "KYC submited successfully wait for approval!" : "The identification data was not uploaded!" ;
		$alert = ($updated && $moved ) ? "success" : "danger";
		
	};

} else $alert = null;


template::get_header();

?>

	<?php template::title("KYC Settings"); ?>
          
    <div class="row">
		<div class="col-lg-12">
			<div class="sparkline12-list shadow-reset mg-t-30 card">

				<div class="card-body">
					<div class="basic-login-form-ad">
					
						<div class="row">
							<div class="col-lg-12">
								<div class="all-form-element-inner">
                                            
									<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"  enctype="multipart/form-data">

										<?php template::alert( $msg, $alert ); ?>

										<div class="form-group-inner">
											<div class="row">
												<div class="col-lg-3">
													<label class="login2">National ID/Passport/Driver's license</label>
												</div>
												<div class="col-lg-6">
													<input type="file" class="form-control" name="image"  />
												</div>
											</div>
										</div>
										
										<div class="form-group-inner">
											<div class="login-btn-inner">
												<div class="row">
													<div class="col-lg-3"></div>
													<div class="col-lg-6">
														<div class="login-horizental cancel-wp pull-left mt-2">
															<button class="btn btn-sm btn-primary login-submit-cs" name="transfer" type="submit">
																Submit
															</button>
														</div>
													</div>
												</div>
											</div>
										</div>
										
									</form>     
									  
								</div>
							</div>
						</div>
						
					</div>
				</div>
               
			</div>
		</div>
	</div>
               

<?php template::get_footer(); ?>  