Commit ecee29d117f181c681115bcdee09bbd12b21a8c2
1 parent
130016ca
api/client/ajouter 1/2
Showing
3 changed files
with
54 additions
and
6 deletions
Show diff stats
BDD.sql
1 | 1 | CREATE TABLE Utilisateurs ( |
2 | - -- loginLille1 char(30), | |
3 | - idCarte char(8), | |
4 | 2 | login char(30) PRIMARY KEY, |
5 | 3 | mdp char(255), |
4 | + idCarte char(8), | |
6 | 5 | droit integer DEFAULT '0' |
7 | 6 | ); |
8 | 7 | |
9 | 8 | CREATE TABLE Sessions ( |
10 | 9 | jeton char(30) PRIMARY KEY, |
11 | - utilisateur char(30) REFERENCES Utilisateurs(login)Temps de validité du jeton en secondes, | |
10 | + utilisateur char(30) REFERENCES Utilisateurs(login) | |
12 | 11 | date datetime DEFAULT CURRENT_TIMESTAMP |
13 | 12 | ); |
14 | 13 | |
15 | 14 | CREATE TABLE Clients ( |
16 | - -- loginLille1 char(30) PRIMARY KEY, | |
15 | + idCarte char(8) PRIMARY KEY, | |
17 | 16 | solde float(7,2), |
18 | - idCarte char(8), | |
19 | - credit boolean | |
17 | + decouvert boolean DEFAULT false | |
20 | 18 | ); |
21 | 19 | |
22 | 20 | ... | ... |
... | ... | @@ -0,0 +1,39 @@ |
1 | +<?php | |
2 | + | |
3 | +require_once("../commun.php"); | |
4 | + | |
5 | +verifierDroit(1); | |
6 | + | |
7 | +if (!(donne("idCarte") && donne("solde"))) { | |
8 | + retour("requete_malformee"); | |
9 | +} | |
10 | + | |
11 | +if (clientExiste(donne("idCarte"))) { | |
12 | + retour("client_existant"); | |
13 | +} | |
14 | + | |
15 | +if (donne("decouvert") && $_POST["decouvert"] != "false" && $_POST["decouvert"] != "0") { | |
16 | + verifierDroit(3); | |
17 | + $decouvert = true; | |
18 | +} else { | |
19 | + $decouvert = false; | |
20 | +} | |
21 | + | |
22 | +$solde = floatval($_POST["solde"]); | |
23 | + | |
24 | +if ($solde < 0 && !$decouvert) { | |
25 | + retour("solde_negatif"); | |
26 | +} | |
27 | + | |
28 | + | |
29 | +$requete = $db->prepare("INSERT INTO Clients (idCarte, solde, decouvert) VALUES (?, ?, ?)"); | |
30 | +$requete->bind_param("sss", $_POST["idCarte"], $_POST["solde"], $decouvert); | |
31 | +if (!$requete->execute()) { | |
32 | + retour("erreur_bdd", ["message" => $requete->error]); | |
33 | +} | |
34 | +$requete->close(); | |
35 | + | |
36 | + | |
37 | +retour("ok"); | |
38 | + | |
39 | +?> | ... | ... |
api/commun.php
... | ... | @@ -81,6 +81,17 @@ function utilisateurExiste($login) { |
81 | 81 | $requete->close(); |
82 | 82 | } |
83 | 83 | |
84 | +function clientExiste($idCarte) { | |
85 | + global $db; | |
86 | + $requete = $db->prepare("SELECT idCarte FROM Clients WHERE idCarte=?"); | |
87 | + $requete->bind_param("s", $idCarte); | |
88 | + if (!$requete->execute()) { | |
89 | + retour("erreur_bdd", ["message" => $requete->error]); | |
90 | + } | |
91 | + return $requete->fetch(); | |
92 | + $requete->close(); | |
93 | +} | |
94 | + | |
84 | 95 | // Variables globales |
85 | 96 | |
86 | 97 | $login = ""; | ... | ... |