ajout de la gestion des clients
This commit is contained in:
96
client_management.php
Normal file
96
client_management.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
session_start();
|
||||
require 'db_con.php'; // Inclure la connexion à la base de données
|
||||
|
||||
// Vérifiez si l'utilisateur est connecté
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Vérifiez le rôle de l'utilisateur
|
||||
$role = $_SESSION['role'];
|
||||
if ($role !== 'admin' && $role !== 'chef') {
|
||||
header("Location: main.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Ajouter un client
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_client'])) {
|
||||
$client_name = $_POST['client_name'];
|
||||
$client_code = strtoupper($_POST['client_code']); // Assurer que le code client est en majuscules
|
||||
$stmt = $pdo->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();
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Manage Clients</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Manage Clients</h1>
|
||||
|
||||
<!-- Formulaire pour ajouter un client -->
|
||||
<h2>Add Client</h2>
|
||||
<form method="POST">
|
||||
<input type="text" name="client_name" required placeholder="Client Name">
|
||||
<input type="text" name="client_code" required placeholder="Client Code (3 chars)">
|
||||
<button type="submit" name="add_client">Add</button>
|
||||
</form>
|
||||
|
||||
<h2>Existing Clients</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Client Code</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
<?php foreach ($clients as $client): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($client['id']); ?></td>
|
||||
<td><?php echo htmlspecialchars($client['name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($client['client_code']); ?></td>
|
||||
<td>
|
||||
<!-- Formulaire pour modifier un client -->
|
||||
<form method="POST" style="display:inline;">
|
||||
<input type="hidden" name="client_id" value="<?php echo $client['id']; ?>">
|
||||
<input type="text" name="client_name" value="<?php echo htmlspecialchars($client['name']); ?>" required>
|
||||
<input type="text" name="client_code" value="<?php echo htmlspecialchars($client['client_code']); ?>" required>
|
||||
<button type="submit" name="edit_client">Edit</button>
|
||||
</form>
|
||||
<!-- Formulaire pour supprimer un client -->
|
||||
<form method="POST" style="display:inline;">
|
||||
<input type="hidden" name="client_id" value="<?php echo $client['id']; ?>">
|
||||
<button type="submit" name="delete_client" onclick="return confirm('Are you sure you want to delete this client?');">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
10
db.sql
10
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');
|
||||
|
1
main.php
1
main.php
@ -28,6 +28,7 @@ $role = $_SESSION['role'];
|
||||
<?php if ($role === 'admin' || $role === 'chef'): ?>
|
||||
<a href="os_management.php">Gérer les systèmes d'exploitation</a>
|
||||
<a href="language_management.php">Manage Programming Languages</a>
|
||||
<a href="client_management.php">Manage Clients</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($role === 'admin'): ?>
|
||||
|
Reference in New Issue
Block a user