<?php

require __dir__ . '/init.php';


if(isset($_POST['transfer'])){
	
	$image = help::process_image( $_FILES['image'] );
	
	if( $image['error_msg'] ):
	
		$msg = $image['error_msg'];
		
	else:
	
		$img_name = md5(basename($image['name'])) . "." . $image['extension'];
		$target = PANEL_DIR . "/uploads/cheques/{$img_name}";
		$cid = substr(md5(help::keygen() . uniqid()), 0, 10);
		
		$sql = sQuery::insert( 'md', array(
			"email" => $__user['email'],
			"account" => $__user['acctno'],
			"cheque" => $img_name,
			"cid" => $cid
		));
		
		$uploaded = $link->query( $sql );
		$moved = move_uploaded_file($image['tmp_name'], $target);
		
		$status = ($uploaded && $moved);
		$msg = $status ? "Cheque deposited successfully wait for approval!" : "The Cheque document was not uploaded!";
		   
	endif;
	
}


template::get_header();

?>

	<div class='mt-5'></div>
	
    <div class="card" >
		<div class="card-body">
		
			<ul class="nav nav-tabs custom-menu-wrap mb-3" style="background-color:#d3e3e8;color:black;">
				<li class='nav-item'>
					<a class='nav-link' href="payment.php">
						<i style="color:red; "  class="fa fa-refresh" aria-hidden="true"></i> History
					</a>
				</li>
				<li class='nav-item'>
					<a class='nav-link'  href="local.php">
						<i style="color:blue; "  class="fa fa-exchange" aria-hidden="true"></i> Domestic Transfer
					</a>
				</li>
				<li class='nav-item'>
					<a class='nav-link'  href="international.php">
						<i style="color:teal; "  class="fa fa-exchange" aria-hidden="true"></i> International Transfer
					</a>
				</li>
			</ul>

			<div class="row">
                <div class="col-lg-12">
                    <div class="sparkline12-list shadow-reset mg-t-30">
					
                        <div class="sparkline12-hd">
                            <div class="main-sparkline12-hd">
								<a href="local.php">
									<button class="btn btn-primary">Domestic Transfer</button>
								</a> &nbsp;&nbsp; 
								<a href="md.php">
									<button class="btn btn-primary">Mobile Deposit</button>
								</a>
                            </div>
                        </div>
						
						<hr>
						
                        <div class="sparkline12-graph">
                            <div class="basic-login-form-ad">
							
                                <div class="row">
                                    <div class="col-lg-12">
                                        <div class="all-form-element-inner">
										
                                            <form action="md.php" method="post"  enctype="multipart/form-data">
												
												<?php template::alert( $msg, $status ?? null ); ?>
												
												<div class="form-group">
                                                    <div class="row">
                                                        <div class="col-lg-3">
                                                            <label class="login2 pull-right pull-right-pro">Upload Cheque</label>
                                                        </div>
                                                        <div class="col-lg-6">
                                                            <input type="file" class="form-control" name="image"  />
                                                        </div>
                                                    </div>
                                                </div>
												
												<div class="form-group">
                                                    <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">
                                                                    
                                                                    <button class="btn btn-sm btn-primary login-submit-cs" name="transfer" type="submit">Deposit-Cheque</button>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
												
                                            </form>
											
                                        </div>
                                    </div>
                                </div>
							
							</div>
						</div>

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