<?php
     include_once('connect.php');
    session_start(); 
    
    // Check if the user is logged in
    if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
         echo "<script type='text/javascript'>window.location.href = 'index.php';</script>"; // Redirect to login page
        exit();
    }
    
    
    include_once('head.php');
?>
<head>
  <style type="text/css">
    textarea{
      width: 400px;
      height: 110px;
      border-radius: var(--bs-border-radius);
    }
  </style>
</head>
<?php
    
    if(isset($_POST["btnAcademicsAdd"]))
    {
        
       $hid=$_POST['txtHid'];

      // FILE 1
      $filename = $_FILES["fileImg"]["name"];
      $tempname = $_FILES["fileImg"]["tmp_name"];
      $folder = $filename == "" ? $_POST['imagepath'] : "../uploads/" . $filename;
      if ($filename != "") {
          move_uploaded_file($tempname, $folder);
      }

      // FILE 2
      $filename1 = $_FILES["fileImg1"]["name"];
      $tempname1 = $_FILES["fileImg1"]["tmp_name"];
      $folder1 = $filename1 == "" ? $_POST['imagepath1'] : "../uploads/" . $filename1;
      if ($filename1 != "") {
          move_uploaded_file($tempname1, $folder1);
      }

      // FILE 3
      $filename2 = $_FILES["fileImg2"]["name"];
      $tempname2 = $_FILES["fileImg2"]["tmp_name"];
      $folder2 = $filename2 == "" ? $_POST['imagepath2'] : "../uploads/" . $filename2;
      if ($filename2 != "") {
          move_uploaded_file($tempname2, $folder2);
      }

      // FILE 4
      $filename3 = $_FILES["fileImg3"]["name"];
      $tempname3 = $_FILES["fileImg3"]["tmp_name"];
      $folder3 = $filename3 == "" ? $_POST['imagepath3'] : "../uploads/" . $filename3;
      if ($filename3 != "") {
          move_uploaded_file($tempname3, $folder3);
      }

      // FILE 5
      $filename4 = $_FILES["fileImg4"]["name"];
      $tempname4 = $_FILES["fileImg4"]["tmp_name"];
      $folder4 = $filename4 == "" ? $_POST['imagepath4'] : "../uploads/" . $filename4;
      if ($filename4 != "") {
          move_uploaded_file($tempname4, $folder4);
      }


        $insert1 = mysqli_query($con,"UPDATE `tbl_academics` SET `fee_structure`='$folder',`annual_calendar`='$folder1',`management_committee`='$folder2',`pta_members`='$folder3',`threeyear_result`='$folder4' WHERE academics_id=$hid");

         if($insert1) {
                
                echo "<script>alert('Result and Academics Updated');</script>";

            }
            else{
                echo "<script>alert('Updation Failed!');</script>";
            }    

    }
    ?>

  <main id="main" class="main">
    <div class="pagetitle">   
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="index.html">Home</a></li>
          <li class="breadcrumb-item active">Update Result and Academics</li>
        </ol>
      </nav>
    </div><!-- End Page Title -->    
     <section class="section">
      <div class="row">
        <div class="col-lg-1">
        </div>
        <div class="col-lg-10">
          <div class="card">
            <div class="card-body">
              <div class="row mb-3  bord-bottom">
             <div class="col-lg-5 "><h5 class="card-title">Update Result and Academics</h5></div>
              <div class="col-lg-5"><h5 class="card-title">
                <!-- <a href="view_academicsresult.php" class="btn btn-secondary">View Result and Academics</a> -->
              </h5>
              </div>
              </div>           
                <?php
                        $selres = mysqli_query($con,"SELECT * FROM tbl_academics");
                         while($rowres = mysqli_fetch_array($selres)) {                                
                ?>

                <!-- General Form Elements -->
                <form name="FormPromoter" method="post" enctype="multipart/form-data" class="pt-20">  
                  <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">FEE STRUCTURE OF THE SCHOOL</label>
                  <div class="col-sm-5">
                   <!--  <input class="form-control" type="file"  name="fileImg" id="fileImg"  > -->
                    <input type="text" id="txtHid" name="txtHid" class="form-control" value="<?php echo $rowres['academics_id']; ?>" hidden>

                    <input type="text" id="image_u" name="imagepath" class="form-control" value="<?php echo $rowres['fee_structure']; ?>" hidden>
                    <label><?php echo $rowres['fee_structure']; ?></label><br>
                    <input type="file" name="fileImg" id="fileImg" height="100"  value="">   
                  </div>
                </div>    
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">ANNUAL ACADEMIC CALENDER</label>
                  <div class="col-sm-5">
                    <input type="text" id="image_u" name="imagepath1" class="form-control" value="<?php echo $rowres['annual_calendar']; ?>" hidden>
                    <label><?php echo $rowres['annual_calendar']; ?></label><br>
                    <input class="form-control" type="file"  name="fileImg1" id="fileImg1"  >
                  </div>
                </div>  
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">LIST OF SCHOOL MANAGEMENT COMMITTEE (SMC)</label>
                  <div class="col-sm-5">
                    <input type="text" id="image_u" name="imagepath2" class="form-control" value="<?php echo $rowres['management_committee']; ?>" hidden>
                    <label><?php echo $rowres['management_committee']; ?></label><br>
                    <input class="form-control" type="file"  name="fileImg2" id="fileImg2"  >
                  </div>
                </div>  
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">LIST OF PARENTS TEACHERS ASSOCIATION (PTA) MEMBERS</label>
                  <div class="col-sm-5">
                    <input type="text" id="image_u" name="imagepath3" class="form-control" value="<?php echo $rowres['pta_members']; ?>" hidden>
                    <label><?php echo $rowres['pta_members']; ?></label><br>
                    <input class="form-control" type="file"  name="fileImg3" id="fileImg3"  >
                  </div>
                </div>  
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">LAST THREE-YEAR RESULT OF THE BOARD EXAMINATION AS PER APPLICABILITY</label>
                  <div class="col-sm-5">
                    <input type="text" id="image_u" name="imagepath4" class="form-control" value="<?php echo $rowres['threeyear_result']; ?>" hidden>
                    <label><?php echo $rowres['threeyear_result']; ?></label><br>
                    <input class="form-control" type="file"  name="fileImg4" id="fileImg4"  >
                  </div>
                </div>  
                
                <div class="row mb-3">
                  <label class="col-sm-3 col-form-label"></label>
                  <div class="col-sm-5 ">
                     <input type="submit" class="btn btn-primary btn-center" name="btnAcademicsAdd" id="btnAcademicsAdd" value="Update">
                    
                  </div>
                </div>

              </form><!-- End General Form Elements -->

              
                 <?php
                }
                ?>
            </div>
          </div>

        </div>
        <div class="col-lg-1">
        </div>
      </div>
    </section>

  </main><!-- End #main -->
  <?php
        include_once('footer.php');
   ?>