X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=lib%2Futils.php;h=47c8bda2e0d0c1784fb129f09fb9709de4c99e1d;hb=33eb6f2ab954597a257e9eb8f793a9bc52dd9524;hp=d937db729cb9f78b9bd54109c811136289de9e18;hpb=65fc0194b3ae059f212c577db4f4a8fec43069d6;p=Project_webapp.git diff --git a/lib/utils.php b/lib/utils.php index d937db7..47c8bda 100644 --- a/lib/utils.php +++ b/lib/utils.php @@ -1,5 +1,7 @@ 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(); + if (!empty($row[0][0])) { + return true; + } else { + return false; + } +} + +function chk_password($email, $password) +{ + global $connection; + $sql_pquery = "select PasswordCl 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(); + 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'])) { + return true; + } else { + return false; + } +} + +function redirect($url, $delay) +{ + header("refresh:$delay; url=$url"); +} + ?>