
<h3>Payment</h3>
<hr>

<?php


        if(!isset($_SESSION['sname'])){
            header("location:validation/index.php");
            exit();
        }


        $sname = $_SESSION["sname"];
        $query = "SELECT sname FROM portal WHERE sname = '$sname'";
        $query_result = $db->query($query);

        if($query_result->num_rows== 1){
            $row = $query_result->fetch_assoc();
        }

?>
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <form method="POST" action="index.php?env=payment" enctype="multipart/form-data">
            <h5>Upload Payment  Receipts </h5>
            <div class="row form-group">
                <div class="col-md-12">
                    <label for="">Payment For</label>
                <input name="pay" type="text" placeholder="Payment For" class="form-control" required> 
                </div>
            </div>
            <div class="row form-group">
                <div class="col-md-12">
                    <input name="paymentfiles" type="file" class="form-control" style="border:solid 1px #dddddd;padding:5%" required>
                </div>
            </div>
                <button class="btn-success btn-block" name="submitpayment" type="submit">Submit</button>
            </form>
        </div>
    </div>
</div>
<div class="row" style="margin-top:50px;">
                        <div class="col-md-6">
                            <a href="index.php?env=fees" style="color:#ffffff;text-decoration:none;"> 
                                <button type="button" class="btn btn-primary btn-block"><i class="fa fa-arrow-left"></i> Go back</button>
                            </a>
                        </div>
                        <div class="col-md-6">
                        
                        </div>
                    </div>
             
<?php

include("inc/db.php");

if(isset($_POST['submitpayment'])){
    
    //initialize your variable
    $pay= mysqli_real_escape_string($db,$_POST['pay']);
    
    // $sname=['sname'];

    //name of the uploaded file
$paymentfiles = $_FILES['paymentfiles']['name'];

// destination of the files on the server
$destination = 'upload/' .$paymentfiles;

// get the file extension
$extension = pathinfo($paymentfiles, PATHINFO_EXTENSION);

$file = $_FILES['paymentfiles'] ['tmp_name'];
$size = $_FILES['paymentfiles'] ['size'];

if(!in_array($extension, ['pdf'])){
    echo "<script>alert('your file extension must be .pdf only')</script>";
}elseif($_FILES['paymentfiles']['size'] > 2200000){
    echo "<script>alert('File too large')</script>";
}else{
    if(move_uploaded_file($file, $destination)){
    
   $query ="INSERT INTO payment(pay, paymentfiles, sname) 
    VALUES('$pay', '$paymentfiles', '$sname')";
    
    $query_result= mysqli_query($db, $query);
    if($query_result){
        echo "<script>alert('Proof of Payment uploaded successfully')</script>";
    }
}else{
        echo "<script>alert('not successful')</script>";
    }
}
}

?>


