fiche.php
1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
require_once("../commun.php");
verifierJeton(donne("jeton"));
if (!donne("idCarte")) {
retour("requete_malformee");
}
// Informations sur l'utilisateur
$requete = $db->prepare("SELECT decouvert, solde FROM Clients WHERE idCarte=?");
if (!$requete) {
retour("erreur_bdd_preparee", ["message" => $db->error]);
}
$requete->bind_param("s", $_POST["idCarte"]);
if (!$requete->execute()) {
retour("erreur_bdd", ["message" => $requete->error]);
}
$requete->bind_result($decouvert, $solde);
if (!$requete->fetch()) {
retour("client_inconnu");
}
$requete->close();
// Transactions de l'utilisateur
$requete = $db->prepare("SELECT id, type, UNIX_TIMESTAMP(date), montant, quantite, utilisateur, valide FROM Transactions WHERE client=?");
if (!$requete) {
retour("erreur_bdd_preparee", ["message" => $db->error]);
}
$requete->bind_param("s", $_POST["idCarte"]);
if (!$requete->execute()) {
retour("erreur_bdd", ["message" => $requete->error]);
}
$requete->bind_result($id, $type, $date, $montant, $quantite, $utilisateur, $valide);
$transactions = [];
while($requete->fetch()) {
$transaction = ["id" => $id, "type" => $type, "client" => $_POST["idCarte"], "date" => $date, "montant" => $montant, "quantite" => $quantite, "utilisateur" => $utilisateur, "valide" => $valide];
$transactions[] = $transaction;
}
$requete->close();
$donnes = ["idCarte" => $_POST["idCarte"], "solde" => $solde, "transactions" => $transactions];
if ($droit >= 3) {
$donnes["decouvert"] = !!$decouvert;
}
retour("ok", $donnes);
?>