Avoid the booking of full fligths.
[Project_webapp.git] / lib / utils.php
index 47c8bda2e0d0c1784fb129f09fb9709de4c99e1d..f8867162fb601c03aef41246a8c47015e729191a 100644 (file)
@@ -1,5 +1,9 @@
 <?php
 
+/**
+ * [is_post_request description]
+ * @return boolean [description]
+ */
 function is_post_request()
 {
     if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') === 'POST') {
@@ -9,6 +13,10 @@ function is_post_request()
     }
 }
 
+/**
+ * [is_get_request description]
+ * @return boolean [description]
+ */
 function is_get_request()
 {
     if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') === 'GET') {
@@ -18,6 +26,11 @@ function is_get_request()
     }
 }
 
+/**
+ * [chk_account description]
+ * @param  [type] $email [description]
+ * @return [type]        [description]
+ */
 function chk_account($email)
 {
     global $connection;
@@ -35,6 +48,12 @@ function chk_account($email)
     }
 }
 
+/**
+ * [chk_password description]
+ * @param  [type] $email    [description]
+ * @param  [type] $password [description]
+ * @return [type]           [description]
+ */
 function chk_password($email, $password)
 {
     global $connection;
@@ -52,6 +71,11 @@ function chk_password($email, $password)
     }
 }
 
+/**
+ * [get_client_id description]
+ * @param  [type] $email [description]
+ * @return [type]        [description]
+ */
 function get_client_id($email)
 {
     global $connection;
@@ -65,12 +89,18 @@ function get_client_id($email)
     return $row[0][0];
 }
 
-function nb_booked($client_id, $flight_id)
+/**
+ * [nb_booked description]
+ * @param  [type] $client_id [description]
+ * @param  [type] $flight_id [description]
+ * @return [type]            [description]
+ */
+function nb_booked($client_id, $flight_id, $class_name)
 {
     global $connection;
-    $sql_pquery = "select SUM(NbPlaces) from RESERVATIONS where NumCl = ? and NumVol = ?";
+    $sql_pquery = "select sum(NbPlaces) from RESERVATIONS where NumCl = ? and NumVol = ? and Classe = ?";
     $connection->prepare_query($sql_pquery);
-    $connection->prepared_query_bind_param("is", array($client_id, $flight_id));
+    $connection->prepared_query_bind_param("iss", array($client_id, $flight_id, $class_name));
     $connection->run_prepared_query();
     $connection->get_pquery_result();
     $row = $connection->get_result_array();
@@ -78,6 +108,10 @@ function nb_booked($client_id, $flight_id)
     return $row[0][0];
 }
 
+/**
+ * [chk_logged_in description]
+ * @return [type] [description]
+ */
 function chk_logged_in()
 {
     if (isset($_SESSION['email']) && isset($_SESSION['IP_address'])) {
@@ -87,6 +121,12 @@ function chk_logged_in()
     }
 }
 
+/**
+ * [redirect description]
+ * @param  [type] $url   [description]
+ * @param  [type] $delay [description]
+ * @return [type]        [description]
+ */
 function redirect($url, $delay)
 {
     header("refresh:$delay; url=$url");