<?php include("db.php"); ?>
                <h3>Hostel Accommodation Form</h3>
                <hr/>
                <div class="container">
					<div class="row">
                    <form method="post" action="index.php?env=register-hostel" enctype="multipart/form-data">
                    <p style="font-size:13px;"><b>STUDENT PARTICULARS</b></p>
                   <div class="row form-group">
                       <div class="col-md-6">
                            <input type="text" name="surname" class="form-control" placeholder="Surname" required>
                       </div>
                       <div class="col-md-6">
                            <input type="text" name="othernames" class="form-control" placeholder="Other Names" required>
                       </div>
                   </div>
                   
                   <div class="row form-group">
                       <div class="col-md-6">
                       <select name="department_name" value="<?php if(isset($_POST['department_name'])){echo $_POST['department_name'];} ?>" id="" class="form-control" required>
									   <option value="">Select department</option>
											<?php
												$sql = mysqli_query($db, "SELECT * from department");
												while($row = mysqli_fetch_array($sql))
												{
													?>
													<option value="<?php echo htmlentities($row['department_name']); ?>"><?php echo htmlentities($row['department_name']); ?></option>

												<?php
													}
												?>
									   </select>
                       </div>
                       <div class="col-md-6">
                            <input type="date" name="dob" class="form-control" required>
                       </div>
                   </div>
                   
                   <div class="row form-group">
                       <div class="col-md-6">
                             <input type="text" name="residential_address" class="form-control" placeholder="Residential Address" required>
                       </div>
                       <div class="col-md-6">
                             <input type="text" name="postal_address" class="form-control" placeholder="Postal Address" required>
                       </div>
                   </div>
                   
                   <div class="row form-group">
                       <div class="col-md-6">
                             <input type="text" name="place_birth" class="form-control" placeholder="Place of Birth" required>
                       </div>
                       <div class="col-md-6">
                             <input type="text" name="state_origin" class="form-control" placeholder="State of Origin" required>
                       </div>
                   </div>
                   
                   <div class="row form-group">
                       <div class="col-md-6">
                             <input type="text" name="LGA" class="form-control" placeholder="L.G.A" required>
                       </div>
                       <div class="col-md-6">
                             <input type="text" name="blood_group" class="form-control" placeholder="Blood Group" required>
                       </div>
                   </div>
                   
                   <div class="row form-group">
                       <div class="col-md-6">
                             <input type="text" name="illness" class="form-control" placeholder="State known illness (if any)" required>
                       </div>
                       <div class="col-md-6">
                             <input type="tel" name="phone" class="form-control" placeholder="Phone Number" required>
                       </div>
                   </div>
                   
                   <div class="row form-group">
                       <div class="col-md-12">
                             <input type="email" name="email" class="form-control" placeholder="Email" required>
                             <p><b>HOSTEL ACCOMMODATION FEES: Only students who indicate and have made payments 
                                will be allocated bed spaces.</b></p>
                       </div>
                      
                   </div>
                   
                     <p style="font-size:13px;"><b>PARTICULARS OF PARENT/GUARDIAN</b></p>
                     <div class="row form-group">
                       <div class="col-md-6">
                             <input type="text" name="fname" class="form-control" placeholder="Name of Parents/Guardian: Father" required>
                       </div>
                       <div class="col-md-6">
                             <input type="tel" name="mother" class="form-control" placeholder="Mother" required>
                       </div>
                   </div> 
                   
                   <div class="row form-group">
                       <div class="col-md-6">
                             <input type="text" name="aaddress" class="form-control" placeholder="Address" required>
                       </div>
                       <div class="col-md-6">
                             <input type="tel" name="nameguardian" class="form-control" placeholder="Name of Guardian" required>
                       </div>
                   </div> 
                   
                   <div class="row form-group">
                       <div class="col-md-6">
                             <input type="text" name="occfather" class="form-control" placeholder="Occupation of Father" required>
                       </div>
                       <div class="col-md-6">
                             <input type="tel" name="occmother" class="form-control" placeholder="Occupation of Mother" required>
                       </div>
                   </div> 
                   
                   <div class="row form-group">
                       <div class="col-md-6">
                             <input type="text" name="occguardian" class="form-control" placeholder="Occupation of Guardian" required>
                       </div>
                       <div class="col-md-6">
                             <input type="tel" name="phoneall" class="form-control" placeholder="Phone Number: Father, Mother, Guardian" required>
                       </div>
                   </div> 
                   
                    <p style="font-size:13px;"><b>Contact Address</b></p>
                     <div class="row form-group">
                       <div class="col-md-6">
                             <input type="text" name="fathername" class="form-control" placeholder="Father" required>
                       </div>
                       <div class="col-md-6">
                            <input type="text" name="mothername" class="form-control" placeholder="Mother" required>
                       </div>
                   </div> 
                   
                   <div class="row form-group">
                       <div class="col-md-12">
                              <input type="text" name="guardian" class="form-control" placeholder="Guardian" required>
                       </div>
                   </div>

                   
                   <div class="row form-group">
                       <div class="col-md-6">
                        <label for="">Parent Passport</label>
                             <input type="file" name="parentpass" class="form-control" placeholder="Occupation of Guardian" required>
                       </div>
                       <div class="col-md-6">
                        <label for="">Student Passport</label>
                             <input type="file" name="Studentpass" class="form-control" placeholder="Phone Number: Father, Mother, Guardian" required>
                       </div>
                   </div>                                                             
                    <!--<input type="submit" name="submit" clas="btn btn-primary btn-block" value="Submit">-->
                    <button type="submit" name="hostelsubmit" class="btn btn-success btn-block">Submit</button>
                </form>
                    
					</div>
				</div>

                <div class="row" style="margin-top:50px;">
                        <div class="col-md-6">
                            <a href="index.php?env=hostel" style="color:#ffffff;text-decoration:none;"> 
                                <button type="button" class="btn btn-primary btn-block"><i class="fa fa-arrow-left"></i> Go back</button>
                            </a>
                        </div>
                        <div class="col-md-6">
                        
                        </div>
                    </div>


<?php

if(isset($_POST['hostelsubmit'])){
    $surname = mysqli_real_escape_string($db, $_POST['surname']);
    $othernames = mysqli_real_escape_string($db, $_POST['othernames']);
    $department_name = mysqli_real_escape_string($db, $_POST['department_name']);
    $dob = mysqli_real_escape_string($db, $_POST['dob']);
    $residential_address = mysqli_real_escape_string($db, $_POST['residential_address']);
    
    $postal_address = mysqli_real_escape_string($db, $_POST['postal_address']);
    $place_birth = mysqli_real_escape_string($db, $_POST['place_birth']);
    $state_origin = mysqli_real_escape_string($db, $_POST['state_origin']);
    
    $LGA = mysqli_real_escape_string($db, $_POST['LGA']);
    $blood_group = mysqli_real_escape_string($db, $_POST['blood_group']);
    $illness = mysqli_real_escape_string($db, $_POST['illness']);
    
    $phone = mysqli_real_escape_string($db, $_POST['phone']);
    $email = mysqli_real_escape_string($db, $_POST['email']);
    
     $fname = mysqli_real_escape_string($db, $_POST['fname']);
    $mother = mysqli_real_escape_string($db, $_POST['mother']);
     $aaddress = mysqli_real_escape_string($db, $_POST['aaddress']);
    $nameguardian = mysqli_real_escape_string($db, $_POST['nameguardian']);
    
     $occfather = mysqli_real_escape_string($db, $_POST['occfather']);
    $occmother = mysqli_real_escape_string($db, $_POST['occmother']);
    
    $occguardian = mysqli_real_escape_string($db, $_POST['occguardian']);
    $phoneall = mysqli_real_escape_string($db, $_POST['phoneall']);
     $fathername = mysqli_real_escape_string($db, $_POST['fathername']);
    $mothername = mysqli_real_escape_string($db, $_POST['mothername']);
    
     $guardian = mysqli_real_escape_string($db, $_POST['guardian']);
     
   //name of the uploaded file
$parentpass = $_FILES['parentpass']['name'];

// destination of the files on the server
$destination = 'upload/' .$parentpass;

// get the file extension
$extension = pathinfo($parentpass, PATHINFO_EXTENSION);
$file = $_FILES['parentpass'] ['tmp_name'];
$size = $_FILES['parentpass'] ['size'];

if(!in_array($extension, ['png', 'jpg', 'jpeg'])){
    echo "your file extension must be .png, .jpeg, .jpg";
}elseif($_FILES['parentpass']['size'] > 100000){
    echo "File too large";
}else{
    if(move_uploaded_file($file,$destination)){

          //name of the uploaded file
$Studentpass = $_FILES['Studentpass']['name'];

// destination of the files on the server
$destination = 'upload/' .$Studentpass;

// get the file extension
$extension = pathinfo($Studentpass, PATHINFO_EXTENSION);
$file = $_FILES['Studentpass'] ['tmp_name'];
$size = $_FILES['Studentpass'] ['size'];

if(!in_array($extension, ['png', 'jpg', 'jpeg'])){
    echo "your file extension must be .png, .jpeg, .jpg";
}elseif($_FILES['Studentpass']['size'] > 100000){
    echo "File too large";
}else{
    if(move_uploaded_file($file,$destination)){

   
     $query = "INSERT INTO hostel_table (surname, othernames, department_name, dob, residential_address, postal_address, place_birth, state_origin, LGA, blood_group, illness, phone, email, fname, mother, aaddress, nameguardian, occfather, occmother, occguardian, phoneall, fathername, mothername, guardian,parentpass,Studentpass) 
VALUES('$surname', '$othernames', '$department_name', '$dob', '$residential_address', '$postal_address', '$place_birth', '$state_origin', '$LGA', '$blood_group', '$illness', '$phone', '$email', '$fname', '$mother', '$aaddress', '$nameguardian', '$occfather', '$occmother', '$occguardian', '$phoneall', '$fathername', '$mothername', '$guardian','$parentpass','$Studentpass')";
       if (mysqli_query($db, $query)) {
        echo "<script>alert('Hostel Application Successfully')</script>";  
      
   } else {
      echo "<script>alert('Hostel Application Not Successfully')</script>";  
   }
    }
}
    }
}
}
?>