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

<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Query Search Up Page</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
  @import url(https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css);
  * {
      box-sizing: border-box;
  }

  .header {
      border: 1px solid #DE584F;
      padding: 15px;
  }

  .social a {
      text-align: center;
      width: 52px;
      height: 52px;
      float: left;
      background: #fff;
      border: 1px solid #ccc;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15), inset 0 0 50px rgba(0, 0, 0, 0.1);
      border-radius: 24px;
      margin: 0 10px 10px 0;
      padding: 6px;
      color: #000;
  }

  .twitter a:hover {
      background: #00acee;
      color: #fff;
  }

  .instagram a:hover {
      background: #3f729b;
      color: #fff;
  }

  .facebook a:hover {
      background: #3b5998;
      color: #fff;
  }

  .header {
      border: 1px solid #DE584F;
      padding: 15px;
  }

  .row::after {
      content: "";
      clear: both;
      display: table;
  }


  /* Paralax animation*/

  .parallax {
      height: 100vh;
      background-image: url(../Web-App/logo4-01.svg);
      background-attachment: fixed;
      background-repeat: no-repeat;
      background-position: center center;
  }

  .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;
  }


  /* 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: 0;
  }

  .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: 100%;
      text-align: center;
  }

  .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: #DE584F;
  }

  @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: 20px;
      line-height: 40px;
      color: #777;
      height: 200vh;
      background-image: linear-gradient(to top, gray, white 40%);
  }

  .container {
      max-width: 600px;
      margin: 0 auto;
      position: relative;
  }

  #search input[type="firstName"],
  #search input[type="lastName"],
  #search input[type="email"],
  #search button[type="submit"] {
      font: 400 12px/16px "Roboto", Helvetica, Arial, sans-serif;
  }

  #search {
      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);
  }

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

  #search 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%;
  }

  #search input[type="firstName"],
  #search input[type="lastName"],
  #search input[type="email"] {
    width: 100%;
    border: 1px solid #ccc;
    background: #FFF;
    margin: 0 0 5px;
    padding: 10px;
  }

  #search input[type="firstName"]:hover,
  #search input[type="lastName"]:hover,
  #search input[type="email"] {
    -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;
  }

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

  #search 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;
  }

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

  #search input:focus,
  #search 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;
  }

  [class*="button7"] {
      background-color: #DE584F;
  }

  .button7 {
      font-weight: 700;
      color: white;
      text-decoration: none;
      padding: .8em 2em calc(.8em + 3px);
      border-radius: 3px;
      background: #DE584F(64, 199, 129);
      box-shadow: 0 -3px #DE584F(53, 167, 110) inset;
      transition: 0.2s;
  }

  .button7:hover {
      background: #DE584F(206, 211, 208);
  }

  .button7:active {
      background: rgb(33, 147, 90);
      box-shadow: 0 3px rgb(33, 147, 90) inset;
  }
  </style>
</head>

<body>
  <?php
  $Subject = "";

  if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $Subject = test_input($_POST["Subject"]);
  }

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

  ?>

  <ul>
    <li><a href="index.php">Home</a></li>
  	<li><a href="booking_page.php">Booking</a></li>
  	<li><a href="contact.php">Contact</a></li>
  	<li><a class="active" href="user_login.php">Login</a></li>
    <li><a href="loginform_for_admin_2.php">Admin login</a></li>
    <li style="float:right"><a href="logout.php">Logout</a></li>
  </ul>

  <div class="container">
    <fieldset>
      <form id="search" method="post" action="<?php $PHP_SELF?>">
        <legend>
          <h1>Searching customer queries</h1>
        </legend>
        <legend>Please select your subject:</legend>
        <label for="firstName">First Name: </label>
        <input placeholder="First Name" type="firstName" name="firstName" tabindex="1" required autofocus/>
        <label for="lastName">Last Name: </label>
        <input placeholder="Last Name" type="lastName" name="lastName" tabindex="1" required autofocus/>
        <label for="email">Email: </label>
        <input placeholder="Email" type="email" name="email" tabindex="1" required autofocus/>
        <input type="hidden" name="flights" value="yes" />
        <input type="submit" name="submit" class="button7" value="Search" />
      </form>
      <?php
      $con = mysqli_connect(localhost, root, root, Airline_Booking, 8889);

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

      if ($_SERVER["REQUEST_METHOD"] == "POST") {
        $firstName = ($_POST["firstName"]);
        $lastName = ($_POST["lastName"]);
        $email = ($_POST["email"]);
      }

      $data = mysqli_query($con, "SELECT * FROM Passenger_Profile WHERE First_Name = '$firstName' AND Last_Name = '$lastName' AND Email_Address = '$email' ");

      $record = array();
      //And display the results
      while ($row = mysqli_fetch_array( $data )) {
        //echo "$row[1]". " " ."$row[2]". " " . "$row[3]". " " . "$row[4]". " ";
        $record[] = $row;

        foreach ($record as $rec) {
          //echo $rec['Profile_Id'];

          $data1 = mysqli_query($con, "SELECT * FROM Ticket_Info WHERE Profile_Id = '$rec[Profile_Id]'");
          $record1 = array();
          while ($row1 = mysqli_fetch_array( $data1 )) {
            //echo $row1[Flight_Id];
            $record1[] = $row1;

            foreach ($record1 as $rec1) {
              //echo $rec[Flight_Id]."<br>";

              $data2 = mysqli_query($con, "SELECT * FROM FlightData WHERE Flight_Id = '$rec1[Flight_Id]'");
              $record2 = array();
              while ($row2 = mysqli_fetch_array( $data2 )) {
                $record2[] = $row2;
                foreach ($record2 as $rec2) {
                  //echo $rec2[Airline];
                  echo $rec2['Airline'] . " | " . $rec2['Flight_Number'] . " | " . $rec2['Departure'] . " | " . $rec2['Arrival'] . " | " . $rec2['Departure_Time'] . " | " . $rec2['Arrival_Time'];
                  echo "<br>";
                }
              }

            }
          }

        }
      }





        //$data1 = mysqli_query($con, "SELECT * FROM Ticket_Info WHERE Profile_Id = '$ID'");

        // while($row1 = mysqli_fetch_array( $data1 )) {
          //echo "$row[1]". " " ."$row[2]". " " . "$row[3]". " " . "$row[4]". " ";
          // $ID1 = $row1[2];

          // $data2 = mysqli_query($con, "SELECT * FROM FlightData WHERE Flight_Id = '$ID1'");
          // if($row2 = mysqli_fetch_array( $data2 )) {
            //echo "$row[1]". " " ."$row[2]". " " . "$row[3]". " " . "$row[4]". " ";

      //$data1 = mysqli_query($con, "SELECT * FROM Ticket_Info WHERE Profile_Id = '$ID'");

      // while($row1 = mysqli_fetch_array( $data1 )) {
      //   //echo "$row[1]". " " ."$row[2]". " " . "$row[3]". " " . "$row[4]". " ";
      //   $ID1 = $row1[2];
      //
      //   $data2 = mysqli_query($con, "SELECT * FROM FlightData WHERE Flight_Id = '$ID1'");
      //   if($row2 = mysqli_fetch_array( $data2 )) {
      //     echo "$row[1]". " " ."$row[2]". " " . "$row[3]". " " . "$row[4]". " ";
      //   }


      //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";
      ?>
    </fieldset>
  </div>

  <!-- social media block -->
  <div class="social twitter">
    <a href="#" target="_blank"><i class="fa fa-twitter fa-2x"></i></a>
  </div>
  <div class="social instagram">
    <a href="#" target="_blank"><i class="fa fa-instagram fa-2x"></i></a>
  </div>
  <div class="social facebook">
    <a href="#" target="_blank"><i class="fa fa-facebook fa-2x"></i></a>
  </div>
</body>
</html>