<?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: 270px;
      height: 110px;
      border-radius: var(--bs-border-radius);
    }
  </style>
</head>
<?php
    
    if(isset($_POST["btnTenth"]))
    {
        
       $hid=$_POST['txtHid'];
       $year=$_POST['txtYear'];
        $regstud=$_POST['txtRegStudent'];
        $passstud=$_POST['txtPassStudent'];
        $percent=$_POST['txtPercent'];
        $remarks=$_POST['txtRemarks'];
      
        $insert1 = mysqli_query($con,"UPDATE `tbl_tenresult` SET `year`='$year',`registered_student`='$regstud',`passed_student`='$passstud',`pass_percentage`='$percent',`remarks`='$remarks' WHERE tenresult_id=$hid");

         if($insert1) {
                
                echo "<script>alert('Result Class: X 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 Class: X</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 Class: X</h5></div>
              <div class="col-lg-5"><h5 class="card-title">
                <!-- <a href="view_academicsresult.php" class="btn btn-secondary">View Result Class: X</a> -->
              </h5>
              </div>
              </div>           
                <?php
                        $selres = mysqli_query($con,"SELECT * FROM tbl_tenresult");
                         while($rowres = mysqli_fetch_array($selres)) {                                
                ?>

                <!-- General Form Elements -->
               <form name="FormTenth" method="post" enctype="multipart/form-data" class="pt-20">
                <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">YEAR</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtHid" name="txtHid" class="form-control" value="<?php echo $rowres['tenresult_id']; ?>" hidden>
                    <input type="text" id="txtYear" name="txtYear" class="form-control" value="<?php echo $rowres['year']; ?>">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">NO. OF REGISTERED STUDENTS</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtRegStudent" name="txtRegStudent" class="form-control" value="<?php echo $rowres['registered_student']; ?>">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">NO. OF STUDENTS PASSED</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtPassStudent" name="txtPassStudent" class="form-control" value="<?php echo $rowres['passed_student']; ?>">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">PASS PERCENTAGE</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtPercent" name="txtPercent" class="form-control" value="<?php echo $rowres['pass_percentage']; ?>">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">REMARKS</label>
                  <div class="col-sm-5">
                    <textarea  id="txtRemarks" name="txtRemarks" ><?php echo $rowres['remarks']; ?></textarea>
                  </div>
                </div>
                 
                <div class="row mb-3 pt-20">
                  <label class="col-sm-4 col-form-label"></label>
                  <div class="col-sm-5 ">
                    <input type="submit" class="btn btn-primary  btn-center" name="btnTenth" id="btnTenth" value="Submit">
                    
                  </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');
   ?>