From 546a5549e96d553347da334d3e79f34ced026927 Mon Sep 17 00:00:00 2001 From: jeremy Date: Wed, 30 Oct 2024 21:46:05 +0100 Subject: [PATCH] ajout de la gestion des clients --- client_management.php | 96 +++++++++++++++++++++++++++++++++++++++++++ db.sql | 10 +++++ main.php | 1 + 3 files changed, 107 insertions(+) create mode 100644 client_management.php diff --git a/client_management.php b/client_management.php new file mode 100644 index 0000000..89395a6 --- /dev/null +++ b/client_management.php @@ -0,0 +1,96 @@ +prepare("INSERT INTO clients (name, client_code) VALUES (:name, :client_code)"); + $stmt->execute(['name' => $client_name, 'client_code' => $client_code]); +} + +// Modifier un client +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['edit_client'])) { + $client_id = $_POST['client_id']; + $client_name = $_POST['client_name']; + $client_code = strtoupper($_POST['client_code']); + $stmt = $pdo->prepare("UPDATE clients SET name = :name, client_code = :client_code WHERE id = :id"); + $stmt->execute(['name' => $client_name, 'client_code' => $client_code, 'id' => $client_id]); +} + +// Supprimer un client +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_client'])) { + $client_id = $_POST['client_id']; + $stmt = $pdo->prepare("DELETE FROM clients WHERE id = :id"); + $stmt->execute(['id' => $client_id]); +} + +// Récupérer tous les clients +$stmt = $pdo->query("SELECT * FROM clients"); +$clients = $stmt->fetchAll(); +?> + + + + + + + Manage Clients + + +

Manage Clients

+ + +

Add Client

+
+ + + +
+ +

Existing Clients

+ + + + + + + + + + + + + + + +
IDNameClient CodeActions
+ +
+ + + + +
+ +
+ + +
+
+ + diff --git a/db.sql b/db.sql index 5483c3a..ba6f3b6 100644 --- a/db.sql +++ b/db.sql @@ -44,3 +44,13 @@ CREATE TABLE language ( ); INSERT INTO language (name) VALUES ('bash'); + +CREATE TABLE clients ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(100) NOT NULL, + client_code CHAR(3) NOT NULL UNIQUE CHECK (client_code REGEXP '^[A-Z0-9]{3}$'), + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + + +INSERT INTO clients (name, client_code) VALUES ('Example Client', 'ABC'); diff --git a/main.php b/main.php index dc634ea..62cca30 100644 --- a/main.php +++ b/main.php @@ -28,6 +28,7 @@ $role = $_SESSION['role']; Gérer les systèmes d'exploitation Manage Programming Languages + Manage Clients