Add the flight search and booking features.
[Project_webapp.git] / lib / utils.php
index 8fdb0aa66d7834a235d0d8ce05d08a1d6e965df6..47c8bda2e0d0c1784fb129f09fb9709de4c99e1d 100644 (file)
@@ -28,7 +28,7 @@ function chk_account($email)
     $connection->get_pquery_result();
     $row = $connection->get_result_array();
     $connection->close_prepared_query();
-    if (!empty($row[0])) {
+    if (!empty($row[0][0])) {
         return true;
     } else {
         return false;
@@ -45,13 +45,39 @@ function chk_password($email, $password)
     $connection->get_pquery_result();
     $row = $connection->get_result_array();
     $connection->close_prepared_query();
-    if (password_verify($password, $row[0])) {
+    if (password_verify($password, $row[0][0])) {
         return true;
     } else {
         return false;
     }
 }
 
+function get_client_id($email)
+{
+    global $connection;
+    $sql_pquery = "select NumCl from CLIENTS where EmailCl = ?";
+    $connection->prepare_query($sql_pquery);
+    $connection->prepared_query_bind_param("s", array($email));
+    $connection->run_prepared_query();
+    $connection->get_pquery_result();
+    $row = $connection->get_result_array();
+    $connection->close_prepared_query();
+    return $row[0][0];
+}
+
+function nb_booked($client_id, $flight_id)
+{
+    global $connection;
+    $sql_pquery = "select SUM(NbPlaces) from RESERVATIONS where NumCl = ? and NumVol = ?";
+    $connection->prepare_query($sql_pquery);
+    $connection->prepared_query_bind_param("is", array($client_id, $flight_id));
+    $connection->run_prepared_query();
+    $connection->get_pquery_result();
+    $row = $connection->get_result_array();
+    $connection->close_prepared_query();
+    return $row[0][0];
+}
+
 function chk_logged_in()
 {
     if (isset($_SESSION['email']) && isset($_SESSION['IP_address'])) {