<?php
include('session_admin.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>payment</title>
<style>
* {
    box-sizing: border-box;
}
.header {
    border: 1px solid green;
    padding: 15px;
}
.row::after {
    content: "";
    clear: both;
    display: table;
}

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
}

li {
    float: left;
}

li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

li a:hover {
    background-color: #111;
}

[class*="col-"] {
    float: left;
    padding: 15px;
    border: 3px solid blue;
}

/* This is allocating layout spaces for how the website is going to be allocated the spaces for different contencts. */

.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
}

li {
    float: left;
}

li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

li a:hover:not(.active) {
    background-color: #111;
}

.active {
    background-color: #4CAF50;
}

@import url(https://fonts.googleapis.com/css?family=Roboto:400,300,600,400italic);
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-font-smoothing: antialiased;
  -o-font-smoothing: antialiased;
  font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  font-family: "Roboto", Helvetica, Arial, sans-serif;
  font-weight: 100;
  font-size: 15px;
  line-height: 30px;
  color: #777;
  background: #ffffff;
}

.container {
  max-width: 400px;
  width: 100%;
  margin: 0 auto;
  position: relative;
}

#contact input[type="Airline"],
#contact input[type="Flight_Number"],
#contact input[type="Departure"],
#contact input[type="Arrival"],
#contact input[type="Time"],
#contact input[type="Morning_AfterNoon_Night"],
#contact input[type="Price"],
#contact button[type="submit"],
#contact button[type="First_Name"],
#contact button[type="Last_Name"] {
  font: 400 12px/16px "Roboto", Helvetica, Arial, sans-serif;
}

#contact {
  background: #F9F9F9;
  padding: 25px;
  margin: 15px 0;
  box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}

#contact h3 {
  display: block;
  font-size: 30px;
  font-weight: 300;
  margin-bottom: 10px;
}

#contact h4 {
  margin: 5px 0 15px;
  display: block;
  font-size: 13px;
  font-weight: 400;
}

fieldset {
  border: medium none !important;
  margin: 0 0 10px;
  min-width: 100%;
  padding: 0;
  width: 100%;
}

#contact input[type="Airline"],
#contact input[type="Flight_Number"],
#contact input[type="Departure"],
#contact input[type="Arrival"],
#contact input[type="Time"],
#contact input[type="Morning_AfterNoon_Night"],
#contact input[type="Price"],
#contact input[type="First_Name"],
#contact input[type="Last_Name"] {
  width: 100%;
  border: 1px solid #ccc;
  background: #FFF;
  margin: 0 0 5px;
  padding: 10px;
}

#contact input[type="Airline"]:hover,
#contact input[type="Flight_Number"]:hover,
#contact input[type="Departure"]:hover,
#contact input[type="Arrival"]:hover,
#contact input[type="Time"]:hover,
#contact input[type="Morning_AfterNoon_Night"]:hover,
#contact input[type="Price"]:hover,
#contact input[type="First_Name"]:hover,
#contact input[type="Last_Name"]:hover {
  -webkit-transition: border-color 0.3s ease-in-out;
  -moz-transition: border-color 0.3s ease-in-out;
  transition: border-color 0.3s ease-in-out;
  border: 1px solid #aaa;
}

#contact textarea {
  height: 100px;
  max-width: 100%;
  resize: none;
}

#contact button[type="submit"] {
  cursor: pointer;
  width: 100%;
  border: none;
  background: #4CAF50;
  color: #FFF;
  margin: 0 0 5px;
  padding: 10px;
  font-size: 20px;
}

#contact button[type="submit"]:hover {
  background: #43A047;
  -webkit-transition: background 0.3s ease-in-out;
  -moz-transition: background 0.3s ease-in-out;
  transition: background-color 0.3s ease-in-out;
}

#contact button[type="submit"]:active {
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
}

#contact input:focus,
#contact textarea:focus {
  outline: 0;
  border: 1px solid #aaa;
}

::-webkit-input-placeholder {
  color: #888;
}

:-moz-placeholder {
  color: #888;
}

::-moz-placeholder {
  color: #888;
}

:-ms-input-placeholder {
  color: #888;
}

</style>
</head>

<body>

<?php

$First_Name = $Last_Name = $Flight_Number = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $First_Name = test_input($_POST["First_Name"]);
  $Last_Name = test_input($_POST["Last_Name"]);
  $Flight_Number = test_input($_POST["Flight_Number"]);

}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

?>

<div class="row">

<div class="container">
  <fieldset>
    <form id="contact" method="post" action="<?php $PHP_SELF?>">
      <legend><h1>Please enter customer's information</h1></legend>
      <legend>First Name:</legend>
      <input placeholder="First Name" type="First_Name" name="First_Name" tabindex="1" required autofocus/>
      <br>
      <legend>Last Name:</legend>
      <input placeholder="Last Name" type="Last_Name" name="Last_Name" tabindex="1" required autofocus/>
      <br>
      <legend>Fligh Number:</legend>
      <input placeholder="Flight Number" type="Flight_Number" name="Flight_Number" tabindex="2" required/>
      <br>
      <input type="submit" name="submit" value="Submit" />
    </form>

    <?php
        #echo "Insert new user";
		// connect to the database
    //$con = mysqli_connect(localhost,root, root, Airline_Booking, 8889);
    $con = mysqli_connect("anysql.itcollege.ee", "WT16", "iLtQlUerkT", "WT16");

    // Check connection
    if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

   //$data = mysqli_query($con, "SELECT Passenger_Id FROM Passenger_Profile WHERE First_Name = '$First_Name' AND Last_Name = '$Last_Name' AND Flight_Number = '$Flight_Number'");

   $data = mysqli_query($con, "SELECT Profile_Id FROM Passenger_Profile WHERE First_Name = '$First_Name' AND Last_Name = '$Last_Name'");
   //And display the results
   while($row = mysqli_fetch_array( $data )) {
     // echo "$row[0]". " ";
     // echo "<br>";
     $Profile_Id = $row[0];
     echo $Profile_Id;
   }

   $data2 = mysqli_query($con, "SELECT Flight_Id FROM FlightData WHERE Flight_Number = '$Flight_Number'");
   while($row2 = mysqli_fetch_array( $data2 )) {
     // echo "$row[0]". " ";
     // echo "<br>";
     $Flight_Id = $row2[0];
     echo $Flight_Id;
   }

   //And display the results
   // while($row = mysqli_fetch_array( $data )) {
   //   echo "$row[0]". " ";
   //   echo "<br>";
   //
   // }

   //This counts the number or results. If there aren't any, it gives the user a "no match" message
   $anymatches=mysqli_num_rows($data);
   if ($anymatches == 0) {
     echo "Sorry, but we can not find an entry to match your query<br><br>";
   }

   //And reminds the user what they searched for
   // echo "<b>Searched For:</b> " . "$find";
   // }

      //break;
//
// if (isset($_GET['Passenger_Id#
// '])) {
//
// 	$Passenger_Id = $_GET['Passenger_Id'];
// 	echo $Passenger_Id;

   // }
   echo "Your input:::::::::<br>";
   echo "".$First_Name. "<br>";
   echo "".$Last_Name. "<br>";
   echo "".$Flight_Number. "<br>";

   //sql to delete a record
   $data3 = mysqli_query($con, "DELETE FROM Passenger_Profile WHERE Profile_Id = '$Profile_Id'");
   if (mysqli_query($con, $data4)) {
       echo "Record deleted successfully";
   }
   else {
     echo "Error deleting record: " . mysqli_error($con);
   }

   $data4 = mysqli_query($con, "DELETE FROM Ticket_Info WHERE Profile_Id = '$Profile_Id' AND Flight_Id = '$Flight_Id'");
   if (mysqli_query($con, $data3)) {
       echo "Record deleted successfully";
   }
   else {
     echo "Error deleting record: " . mysqli_error($con);
   }

   // mysqli_query($con, "DELETE FROM Ticket_Info WHERE Passenger_fk = $row[0]");
   // printf("Affected rows (DELETE): %d\n", mysqli_affected_rows($con));
   // if (mysqli_query($con, $data)) {
   //     echo "Record deleted successfully";
   // } else {
   //     echo "Error deleting record: " . mysqli_error($con);
   // }

   mysqli_close($con);
   ?>
 </div>
</div>
</body>
</html>