<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once '../auth/auth.php';
require_once '../models/db_connection.php';
// require_once '../models/student_model.php';
// require_once '../models/course_model.php';
// require_once '../models/fee_model.php';
// $student =  new Student($conn);
// $course =  new Course($conn);
// $fee =  new Fee($conn);
// $coursesData =  $course->getAllCourses();
// $studentsData = $student->getAllStudents();




if (isset($_GET["id"])) {
        $paymentData = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM students LEFT JOIN student_payments ON student_payments.st_id = students.student_id WHERE student_payments.id = '$_GET[id]'"));

}

if (isset($_POST["edit"])) {
  $ammount = $_POST["ammount"];
  $editpay = mysqli_query($conn, "UPDATE student_payments SET amount = '$ammount' WHERE id ='$_POST[paymentId]'");
  if($editpay){
    echo "<script>
        alert('Payment editted successfully');
        window.location.href = 'view_payments.php';
    </script>";
  }
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
 <title>Payment | Edit Payment </title>
 <?php include("../templates/header.php"); ?>
</head>
<body>
  <div class="container-scroller">
    <!-- partial:partials/_navbar.html -->
    <?php include("../templates/nav.php"); ?>
    <!-- partial -->
    <div class="container-fluid page-body-wrapper">
      <!-- partial:partials/_sidebar.html -->
      <?php include("../templates/sidenav.php"); ?>
      <!-- partial -->
      <div class="main-panel">
        <div class="content-wrapper">
        <div class="col-md-6 grid-margin stretch-card">
              <div class="card">
                <div class="card-body">
                  <h4 class="card-title">Add Student Payment</h4>
                  <p class="card-description"> 
                    Add Students <code>Payments</code>                   
                  </p>
                  <form action="" method="POST">
                  <div class="form-group">
                    <label for="exampleFormControlSelect1">Student Name</label>
                    <input type="text" id="studentList" class="form-control" name="enID" value="<?= $paymentData['fullname'] ?>"  readonly>
                        
                  </div>
                  <div class="form-group">
                    <label for="exampleFormControlSelect2" >Ammount</label>
                    <input type="number" class="form-control" name="ammount" value="<?= $paymentData['amount'] ?>" required>
                        <input type="hidden" class="form-control" name="paymentId" value="<?= $_GET['id'] ?>" required>
                  </div>
                  
                  <div class="col-sm-9">
                          <button   type="submit" name="edit" class="btn btn-dark btn-lg ">Edit Payment</button>
                          </div>
                </div>
                
                </form>
              </div>
            </div>
        
        </div>
        <!-- content-wrapper ends -->
        <!-- partial:partials/_footer.html -->
        <?php include("../templates/footer.php"); ?>
        
        <!-- partial -->
      </div>
      <!-- main-panel ends -->
    </div>
    <!-- page-body-wrapper ends -->
  </div>
    <?php include("../templates/inc_scripts.php"); ?>
</body>

</html>

