<?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["btnStaffAdd"]))
    {
        
       $hid=$_POST['txtHid'];
       $pname=$_POST['txtPrincipal'];
       $teacherno=$_POST['txtTeacher'];
       $pgt=$_POST['txtPgt'];
       $tgt=$_POST['txtTgt'];
       $prt=$_POST['txtPrt'];
       $ratio=$_POST['txtRatio'];
       $educator=$_POST['txtEducator'];
       $counsellor=$_POST['txtCounsellor'];
      
        $insert1 = mysqli_query($con,"UPDATE `tbl_staff` SET `principal_name`='$pname',`teacher_no`='$teacherno',`pgt`='$pgt',`tgt`='$tgt',`prt`='$prt',`teacher_ratio`='$ratio',`educator`='$educator',`counsellor`='$counsellor' WHERE staff_id=$hid");

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

                <!-- General Form Elements -->
               <form name="Formmandatory" method="post" enctype="multipart/form-data" class="pt-20">
                <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">PRINCIPAL</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtHid" name="txtHid" class="form-control" value="<?php echo $rowres['staff_id']; ?>" hidden>
                    <input type="text" id="txtPrincipal" name="txtPrincipal" class="form-control" value="<?php echo $rowres['principal_name']; ?>">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">TOTAL NO. OF TEACHERS</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtTeacher" name="txtTeacher" class="form-control" value="<?php echo $rowres['teacher_no']; ?>">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">PGT</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtPgt" name="txtPgt" class="form-control" value="<?php echo $rowres['pgt']; ?>">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">TGT</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtTgt" name="txtTgt" class="form-control" value="<?php echo $rowres['tgt']; ?>">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">PRT</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtPrt" name="txtPrt" class="form-control" value="<?php echo $rowres['prt']; ?>">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">TEACHERS SECTION RATIO</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtRatio" name="txtRatio" class="form-control" value="<?php echo $rowres['teacher_ratio']; ?>">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">DETAILS OF SPECIAL EDUCATOR</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtEducator" name="txtEducator" class="form-control" value="<?php echo $rowres['educator']; ?>">
                  </div>
                </div> 
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">DETAILS OF COUNSELLOR AND WELLNESS TEACHER</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtCounsellor" name="txtCounsellor" class="form-control" value="<?php echo $rowres['counsellor']; ?>">
                  </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="btnStaffAdd" id="btnStaffAdd" 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');
   ?>