<?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["btnGeneralInfoAdd"]))
    {
        
       $hid=$_POST['txtHid'];
        $sname=$_POST['txtSchoolName'];
        $affili=$_POST['txtAffiliation'];
        $scode=$_POST['txtSchoolCode'];
        $address=$_POST['txtAddress'];
        $pname=$_POST['txtPname'];
        $pquali=$_POST['txtPQuali'];
        $email=$_POST['txtEmail'];
        $contact=$_POST['txtContact'];

        $insert1 = mysqli_query($con,"UPDATE `tbl_generalinfo` SET `school_name`='$sname',`affiliation_number`='$affili',`school_code`='$scode',`school_address`='$address',`principal_name`='$pname',`principal_qualification`='$pquali',`school_email`='$email',`school_contact`='$contact' WHERE generalinfo_id=$hid");

         if($insert1) {
                
                echo "<script>alert('General Information 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 General Information</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 General Information</h5></div>
              <div class="col-lg-5"><h5 class="card-title">
                <!-- <a href="view_academicsresult.php" class="btn btn-secondary">View General Information</a> -->
              </h5>
              </div>
              </div>           
                <?php
                        $selres = mysqli_query($con,"SELECT * FROM tbl_generalinfo");
                         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">NAME OF THE SCHOOL</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtHid" name="txtHid" class="form-control" value="<?php echo $rowres['generalinfo_id']; ?>" hidden>
                    <input type="text" id="txtSchoolName" name="txtSchoolName" class="form-control" value="<?php echo $rowres['school_name']; ?>">
                  </div>
                </div>
                <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">AFFILIATION NO</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtAffiliation" name="txtAffiliation" class="form-control" value="<?php echo $rowres['affiliation_number']; ?>" >
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">SCHOOL CODE</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtSchoolCode" name="txtSchoolCode" class="form-control" value="<?php echo $rowres['school_code']; ?>">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">COMPLETE ADDRESS WITH PIN CODE</label>
                  <div class="col-sm-5">
                    <textarea  id="txtAddress" name="txtAddress" ><?php echo $rowres['school_address']; ?></textarea>
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">PRINCIPAL NAME</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtPname" name="txtPname" 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">PRINCIPAL QUALIFICATION</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtPQuali" name="txtPQuali" class="form-control" value="<?php echo $rowres['principal_qualification']; ?>">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">SCHOOL EMAIL ID</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtEmail" name="txtEmail" class="form-control" value="<?php echo $rowres['school_email']; ?>">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">CONTACT DETAILS (LANDLINE/MOBILE)</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtContact" name="txtContact" class="form-control" value="<?php echo $rowres['school_contact']; ?>">
                  </div>
                </div>
                <div class="row mb-3">
                  <label class="col-sm-4 col-form-label"></label>
                  <div class="col-sm-5 ">
                     <input type="submit" class="btn btn-primary btn-center" name="btnGeneralInfoAdd" id="btnGeneralInfoAdd" 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');
   ?>