<?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: 100px;
      border-radius: var(--bs-border-radius);
    }
  </style>
</head>
<?php
    
    if(isset($_POST["btnInfraAdd"]))
    {
        $area=$_POST['txtArea'];
        $classno=$_POST['txtClassno'];
        $classsize=$_POST['txtClasssize'];
        $labno=$_POST['txtLabno'];
        $labsize=$_POST['txtLabsize'];
        $internet=$_POST['selInternet'];
        $gtoilet=$_POST['txtGToilet'];
        $btoilet=$_POST['txtBToilet'];
        $youtube=$_POST['txtYoutube'];

        $filename = $_FILES["fileImg"]["name"]; 
        $tempname = $_FILES["fileImg"]["tmp_name"];  
        if($filename!=""){
            $folder = "../uploads/".$filename; 
        }
        else{
            $folder = "";
        }
        
        $sql=mysqli_query($con,"INSERT INTO `tbl_infrastructure`(`campus_area`, `classroom_no`, `classroom_size`, `lab_no`, `lab_size`, `internet_facility`, `girss_toiletno`, `boys_toiletno`, `youtube_video`, `teacher_list`) VALUES ('$area','$classno','$classsize','$labno','$labsize','$internet','$gtoilet','$btoilet','$youtube','$folder')");
       
        //FOR uploading image from tempname to uploads/banners folder
        move_uploaded_file($tempname, $folder);
        if ($sql)  { 
                // $msg = "Image uploaded successfully"; 
                echo "<script>alert('School Infrastructure Added');</script>";
            
        }else{ 
             unlink($folder);
             echo "<script>alert('Failed!!');</script>";
        } 
        
        mysqli_close($con);
       
    }
    ?>


  <main id="main" class="main">

    <div class="pagetitle">
      <!-- <h1>Dashboard</h1> -->
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="index.html">Home</a></li>
          <li class="breadcrumb-item active">Add School Infrastructure</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">Add New School Infrastructure</h5></div>
              <div class="col-lg-5"><h5 class="card-title title-right"><a href="update_infrastructure.php" class="btn btn-secondary">Update School Infrastructure</a></h5></div>
              </div>
              <div class="row mb-3">  

              </div>
              <!-- General Form Elements -->
                <form name="Forminfra" method="post" enctype="multipart/form-data" class="pt-20">
                <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">TOTAL CAMPUS AREA OF THE SCHOOL (IN SQUARE MTR)</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtArea" name="txtArea" class="form-control">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">NO. AND SIZE OF THE CLASS ROOMS (IN SQ MTR)</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtClassno" name="txtClassno" class="form-control" placeholder="No of Classrooms">
                    <input type="text" id="txtClasssize" name="txtClasssize" class="form-control" placeholder="Size in Sq.mtr"  >
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">NO. AND SIZE OF LABORATORIES INCLUDING COMPUTER LABS (IN SQ MTR)</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtLabno" name="txtLabno" placeholder="No of Laboratories" class="form-control">
                    <input type="text" id="txtLabsize" name="txtLabsize" placeholder="Size in Sq.mtr" class="form-control">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">INTERNET FACILITY</label>
                  <div class="col-sm-5">
                    <select id="selInternet" name="selInternet"   class="form-control"  style="appearance: auto;">
                      <option value="" disabled="" selected="">--Select Internet Facility--</option>
                      <option value="Yes">Yes</option>
                      <option value="No">No</option>
                    </select>
                  </div>
                </div> 
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">NO. OF GIRLS TOILETS</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtGToilet" name="txtGToilet" class="form-control">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">NO. OF BOYS TOILETS</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtBToilet" name="txtBToilet" class="form-control">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">LINK OF YOUTUBE VIDEO OF THE INSPECTION OF SCHOOL COVERING THE INFRASTRUCTURE OF THE SCHOOL</label>
                  <div class="col-sm-5">
                    <input type="text" id="txtYoutube" name="txtYoutube" class="form-control">
                  </div>
                </div>
                 <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">UPLOAD TEACHER'S LIST</label>
                  <div class="col-sm-5">
                    <input class="form-control" type="file"  name="fileImg" id="fileImg" >
                  </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="btnInfraAdd" id="btnInfraAdd" value="Submit">
                      
                  </div>
                </div>

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

            </div>
          </div>

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

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