| 1 | <?php |
| 2 | |
| 3 | function is_post_request() |
| 4 | { |
| 5 | if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') === 'POST') { |
| 6 | return true; |
| 7 | } else { |
| 8 | return false; |
| 9 | } |
| 10 | } |
| 11 | |
| 12 | function is_get_request() |
| 13 | { |
| 14 | if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') === 'GET') { |
| 15 | return true; |
| 16 | } else { |
| 17 | return false; |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | function chk_account($email) |
| 22 | { |
| 23 | global $connection; |
| 24 | $sql_pquery = "select count(NumCl) from CLIENTS where EmailCl = ?"; |
| 25 | $connection->prepare_query($sql_pquery); |
| 26 | $connection->prepared_query_bind_param("s", array($email)); |
| 27 | $connection->run_prepared_query(); |
| 28 | $connection->get_pquery_result(); |
| 29 | $row = $connection->get_result_array(); |
| 30 | $connection->close_prepared_query(); |
| 31 | if (!empty($row[0][0])) { |
| 32 | return true; |
| 33 | } else { |
| 34 | return false; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | function chk_password($email, $password) |
| 39 | { |
| 40 | global $connection; |
| 41 | $sql_pquery = "select PasswordCl from CLIENTS where EmailCl = ?"; |
| 42 | $connection->prepare_query($sql_pquery); |
| 43 | $connection->prepared_query_bind_param("s", array($email)); |
| 44 | $connection->run_prepared_query(); |
| 45 | $connection->get_pquery_result(); |
| 46 | $row = $connection->get_result_array(); |
| 47 | $connection->close_prepared_query(); |
| 48 | if (password_verify($password, $row[0][0])) { |
| 49 | return true; |
| 50 | } else { |
| 51 | return false; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | function get_client_id($email) |
| 56 | { |
| 57 | global $connection; |
| 58 | $sql_pquery = "select NumCl from CLIENTS where EmailCl = ?"; |
| 59 | $connection->prepare_query($sql_pquery); |
| 60 | $connection->prepared_query_bind_param("s", array($email)); |
| 61 | $connection->run_prepared_query(); |
| 62 | $connection->get_pquery_result(); |
| 63 | $row = $connection->get_result_array(); |
| 64 | $connection->close_prepared_query(); |
| 65 | return $row[0][0]; |
| 66 | } |
| 67 | |
| 68 | function nb_booked($client_id, $flight_id) |
| 69 | { |
| 70 | global $connection; |
| 71 | $sql_pquery = "select SUM(NbPlaces) from RESERVATIONS where NumCl = ? and NumVol = ?"; |
| 72 | $connection->prepare_query($sql_pquery); |
| 73 | $connection->prepared_query_bind_param("is", array($client_id, $flight_id)); |
| 74 | $connection->run_prepared_query(); |
| 75 | $connection->get_pquery_result(); |
| 76 | $row = $connection->get_result_array(); |
| 77 | $connection->close_prepared_query(); |
| 78 | return $row[0][0]; |
| 79 | } |
| 80 | |
| 81 | function chk_logged_in() |
| 82 | { |
| 83 | if (isset($_SESSION['email']) && isset($_SESSION['IP_address'])) { |
| 84 | return true; |
| 85 | } else { |
| 86 | return false; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | function redirect($url, $delay) |
| 91 | { |
| 92 | header("refresh:$delay; url=$url"); |
| 93 | } |
| 94 | |
| 95 | ?> |