-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.php
More file actions
1296 lines (977 loc) · 39.9 KB
/
agent.php
File metadata and controls
1296 lines (977 loc) · 39.9 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style1.css" />
<script src="fichier.js"></script>
<title>Agent d'accueil</title>
</head>
<body>
<div class="header">
<a href="site.php">
<img class="logo" src="images/banque.png" alt="Logo" title="Logo">
</a>
<h1 class="title"> Agent d'accueil</h1>
<button class="logout-btn" onclick="logout()">Déconnexion</button>
</div>
<?php
require 'connect.php'; // Inclure le fichier de connexion
// Création de la connexion avec les constantes définies
$conn = new mysqli(SERVEUR, USER, PASSWORD, BDD);
$conn->close();
?>
<!-- Menu du site -->
<div class="container">
<div class="tabs">
<button class="tab active" onclick="openTab(event, 'gestion')">Gestion des clients</button>
<button class="tab" onclick="openTab(event, 'synthese')"> Synthèse clients </button>
<button class="tab" onclick="openTab(event, 'operations')"> Opérations bancaires</button>
<button class="tab" onclick="openTab(event, 'rendezvous')">Prise de rendez-vous</button>
<button class="tab" onclick="openTab(event, 'recherche')">Recherche de clients</button>
</div>
<!-- Modifier certaines informations du client -->
<div id="gestion" class="tab-content active">
<h2>Modifier certaines informations du client </h2>
<br>
<form id="formulaireCli" method="POST">
<div class="form-group">
<label>Identifiant du client </label>
<input type="number" id="id_du_clients" name="id_du_clients" required>
</div>
<button class="btn-secondary" type="reset" name="delete_btn" id="delete_btn">Effacer</button>
<button class="btn-primary" type="submit" id="send_btn" name="send_btn">Envoyer</button>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Connexion à la base de données
$conn = new mysqli(SERVEUR, USER, PASSWORD, BDD);
if ($conn->connect_error) {
die("Échec de la connexion : " . $conn->connect_error);
}
// Récupération et sécurisation des entrées
$id_du_cli = isset($_POST['id_du_clients']) ? $_POST['id_du_clients'] : '';
if (!empty($id_du_cli) && isset($_POST['send_btn'])) {
// Récupération des informations du client
$sql = "SELECT IdClient, NomCl, PrenomCl, DateN, Mail, NumTel, Adresse, SituationFam, DateInscription FROM Client WHERE IdClient = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $id_du_cli);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
echo '<div class="form-container">';
echo '<form method="post">';
// Affichage des informations non modifiables
echo '<label for="id">Identifiant :</label>';
echo '<input type="number" name="id" id="id" value="'.$row['IdClient'].'" readonly> <br><br>';
echo '<label for="nom">Nom complet :</label>';
echo '<input type="text" name="nom" id="nom" value="' . $row['NomCl'] . ' ' . $row['PrenomCl'] . '" readonly> <br><br>';
// Affichage des informations modifiables
echo '<label for="date_naissance">Date de naissance :</label>';
echo '<input type="date" name="date_naissance" id="date_naissance" value="'.$row['DateN'].'" readonly> <br><br>';
echo '<label for="email">Email :</label>';
echo '<input type="email" name="email" id="email" value="'.$row['Mail'].'"> <br><br>';
echo '<label for="telephone">Téléphone :</label>';
echo '<input type="text" name="telephone" id="telephone" value="'.$row['NumTel'].'"> <br><br>';
echo '<label for="telephone">Adresse :</label>';
echo '<input type="text" name="adresse" id="adresse" value="'.$row['Adresse'].'"> <br><br>';
echo '<label for="telephone">Situation familiale :</label>';
echo '<input type="text" name="situationF" id="situationF" value="'.$row['SituationFam'].'"> <br><br>';
echo '<label for="date_inscription">Date d\'inscription :</label>';
echo '<input type="date" name="date_inscription" id="date_inscription" value="'.$row['DateInscription'].'"> <br><br>';
echo '<input type="submit" name="modify_btn" id="modify_btn"value="Modifier">';
echo '</form>';
echo '</div>';
} else {
echo "<p> <div class='form-container'><div class='NoResultat'>Aucun compte trouvé pour ce client.</p></div></div>";
}
$stmt->close();
} elseif (isset($_POST['modify_btn'])) {
// Récupération des données du formulaire de modification
$date_naissance = $_POST['date_naissance'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$address = $_POST['adresse'];
$Sfamiliale= $_POST['situationF'];
$date_inscription = $_POST['date_inscription'];
$id = $_POST['id'];
// Préparation de la requête SQL pour mettre à jour les informations
$sql = "UPDATE Client SET DateN = ?, Mail = ?, NumTel = ?, Adresse = ?, DateInscription = ?, SituationFam=? WHERE IdClient = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssssssi", $date_naissance, $email, $telephone, $address, $date_inscription, $Sfamiliale, $id);
if ($stmt->execute()) {
echo '<div class="success-message" id="modifCli"> Les informations du client ont été mises à jour avec succès! </div>
<script>
setTimeout(() => {
document.getElementById("modifCli").style.display = "none";}, 2000);
</script>';
} else {
echo "<div class='failure-message' id='modifClis'>Erreur lors de la mise à jour des informations du client.</div>
<script>
setTimeout(() => {
document.getElementById('modifClis').style.display = 'none';}, 2000);
</script>";
}
$stmt->close();
}
// Fermeture de la connexion
$conn->close();
}
?>
</div>
<!-- consulter la synthèse d'un client -->
<div id="synthese" class="tab-content">
<h2> Consulter la synthèse d'un client</h2>
<br>
<form id="syntheseCli" method="POST">
<div class="form-group">
<label>Identifiant du Client</label>
<input type="text" id="id_clients" name="id_clients" required>
</div>
<button type="submit" class="btn" id="synthese_clients" name="synthese_clients">Rechercher</button>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$conn = new mysqli(SERVEUR, USER, PASSWORD, BDD);
if ($conn->connect_error) {
die("Échec de la connexion : " . $conn->connect_error);
}
$identifiant = isset($_POST['id_clients']) ? intval($_POST['id_clients']) : 0;
if (!empty($identifiant) && isset($_POST['synthese_clients'])) {
// Connexion à la base de données
$conn = new mysqli(SERVEUR, USER, PASSWORD, BDD);
if ($conn->connect_error) {
die("Échec de la connexion : " . $conn->connect_error);
}
// Recherche des informations complètes du client
$sql = "SELECT IdClient, NomCl, PrenomCl, DateN, Adresse, NumTel, Mail, SituationFam, NomConseiller, PrenomConseiller
FROM Client
LEFT JOIN Conseiller ON Client.IdConseiller = Conseiller.IdConseiller
WHERE Client.IdClient = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $identifiant);
$stmt->execute();
$result = $stmt->get_result();
echo '<style>
.resultatsCli {
font-family: Arial, sans-serif;
max-width: 900px;
margin: 20px auto;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
background-color: #f9f9f9;
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);
text-align: left;
}
.resultatsCli h2 {
text-align: center;
}
.table-container {
width: 100%;
border-collapse: collapse;
}
.table-container th, .table-container td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
.table-container th {
background-color: #e3f2fd;
color: black;
}
.NoResultat {
color: white;
background-color: red;
padding: 10px;
border-radius: 5px;
font-weight: bold;
text-align: center;
margin-top: 10px;
}
</style>';
echo '<div class="resultatsCli">';
if ($result->num_rows > 0) {
echo '<h2>Informations du client</h2>';
echo '<table class="table-container">
<tr>
<th>ID</th>
<th>Nom</th>
<th>Prénom</th>
<th>Date de naissance</th>
<th>Adresse</th>
<th>Téléphone</th>
<th>Email</th>
<th>Situation familiale</th>
<th>Conseiller</th>
</tr>';
while ($row = $result->fetch_assoc()) {
echo '<tr>
<td>' . ($row['IdClient']) . '</td>
<td>' . ($row['NomCl']) . '</td>
<td>' . ($row['PrenomCl']) . '</td>
<td>' . ($row['DateN']) . '</td>
<td>' . ($row['Adresse']) . '</td>
<td>' . ($row['NumTel']) . '</td>
<td>' . ($row['Mail']) . '</td>
<td>' . ($row['SituationFam']) . '</td>
<td>' . ($row['NomConseiller']) . ' ' . ($row['PrenomConseiller']) . '</td>
</tr>';
}
echo '</table>';
} else {
echo '<div class="NoResultat">Aucun client trouvé avec cet identifiant.</div>';
}
// Requête pour récupérer les informations des comptes du client
$sql_comptes = "SELECT IdClient,Compte.IdCompte, NumeroCompte, TypeCompte, DateOuverture, Solde, MontantDec
FROM Compte
INNER JOIN Appartenir ON Compte.IdCompte = Appartenir.IdCompte
WHERE IdClient = ?";
$stmt_comptes = $conn->prepare($sql_comptes);
$stmt_comptes->bind_param("i", $identifiant);
$stmt_comptes->execute();
$result_comptes = $stmt_comptes->get_result();
// Affichage des informations des comptes
if ($result_comptes->num_rows > 0) {
echo '<h2>Comptes du client</h2>';
echo '<table class="table-container">
<tr>
<th>ID Client</th>
<th>Numéro de compte</th>
<th>Identifiant de compte</th>
<th>Type de compte</th>
<th>Date d\'ouverture</th>
<th>Solde</th>
<th>Découvert autorisé</th>
</tr>';
while ($row = $result_comptes->fetch_assoc()) {
echo '<tr>
<td>' . ($row['IdClient']) . '</td>
<td>' . ($row['NumeroCompte']) . '</td>
<td>' . ($row['IdCompte']) . '</td>
<td>' . ($row['TypeCompte']) . '</td>
<td>' . ($row['DateOuverture']) . '</td>
<td>' . ($row['Solde']) . '</td>
<td>' . ($row['MontantDec']) . '</td>
</tr>';
}
echo '</table>';
}
// Requête pour récupérer les informations des contrats du client
$sql_contrats = "SELECT IdClient, NumeroContrat, TypeContrat, DateDebut, TarifMensuel
FROM Contrat
INNER JOIN Detenir ON Contrat.IdContrat = Detenir.IdContrat
WHERE IdClient = ?";
$stmt_contrats = $conn->prepare($sql_contrats);
$stmt_contrats->bind_param("i", $identifiant);
$stmt_contrats->execute();
$result_contrats = $stmt_contrats->get_result();
// Affichage des informations des contrats
if ($result_contrats->num_rows > 0) {
echo '<h2>Contrats du client</h2>';
echo '<table class="table-container">
<tr>
<th>ID Client</th>
<th>Numéro de contrat</th>
<th>Type de contrat</th>
<th>Date de début</th>
<th>Tarif mensuel</th>
</tr>';
while ($row = $result_contrats->fetch_assoc()) {
echo '<tr>
<td>' . ($row['IdClient']) . '</td>
<td>' . ($row['NumeroContrat']) . '</td>
<td>' . ($row['TypeContrat']) . '</td>
<td>' . ($row['DateDebut']) . '</td>
<td>' . ($row['TarifMensuel']) . '</td>
</tr>';
}
echo '</table>';
}
echo '</div>';
$stmt->close();
$stmt_comptes->close();
$stmt_contrats->close();
$conn->close();
}
}
?>
</div>
<!-- Effectuer des dépôts ou retraits sur le compte d'un client -->
<div id="operations" class="tab-content">
<h2> Effectuer des dépôts ou retraits sur le compte d'un client</h2>
<br>
<form id="depotretraits" method="POST">
<div class="form-group">
<label>Identifiant du client </label>
<input type="number" id="id_du_cpt" name="id_du_cpt" required>
</div>
<button class="btn-secondary" type="reset" name="Effacer_btn" id="filter">Effacer</button>
<button class="btn-primary" type="submit" id="transc" name="transc">Envoyer</button>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Connexion à la base de données
$conn = new mysqli(SERVEUR, USER, PASSWORD, BDD);
if ($conn->connect_error) {
die("Échec de la connexion : " . $conn->connect_error);
}
echo '<style>
.form-container {
font-family: Arial, sans-serif;
max-width: 500px;
margin: 20px auto;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
background-color: #f9f9f9;
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);
text-align: center;
}
select, input {
width: 100%;
padding: 8px;
margin: 5px 0;
border-radius: 3px;
border: 1px solid #ccc;
}
input[type="submit"] {
background-color: #007bff;
color: white;
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #0056b3;
}
.NoResultat {
color: white;
background-color: red;
padding: 10px;
border-radius: 5px;
font-weight: bold;
text-align: center;
margin-top: 10px;
}
</style>';
// Récupération et sécurisation des entrées
$id_client = isset($_POST['id_du_cpt']) ? $_POST['id_du_cpt'] : 0;
if (!empty($id_client) && isset($_POST['transc'])) {
// Récupération des comptes du client
$sql = "SELECT Appartenir.IdCompte, IdClient, TypeCompte
FROM Appartenir
INNER JOIN Compte ON Appartenir.IdCompte=Compte.IdCompte
WHERE IdClient = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $id_client);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
echo '<div class="form-container">';
echo '<form method="post">';
echo '<input type="hidden" name="id_du_cpt" value="' . $id_client . '">'; // Champ caché pour IdClient
echo '<label for="compte">Sélectionnez un compte :</label>';
echo '<select name="compte" id="compte">';
while ($row = $result->fetch_assoc()) {
echo "<option value='" . $row['IdCompte'] . "'>" . $row['TypeCompte'] . "</option>";
}
echo '</select><br><br>';
echo '<label for="operation">Type d\'opération :</label>';
echo '<select name="operation" id="operation">';
echo '<option value="debit">Débit</option>';
echo '<option value="credit">Crédit</option>';
echo '</select><br><br>';
echo '<label for="montant">Montant :</label>';
echo '<input type="number" name="montant" id="montant" required><br><br>';
echo '<button type="submit" class="btn-primary">'."Effectuer".'<button>';
echo '</form>';
echo '</div>';
} else {
echo "<p> <div class='form-container'><div class='NoResultat'>Aucun compte trouvé pour ce client.</p></div></div>";
}
$stmt->close();
}
// Fermeture de la connexion
$conn->close();
}
// Traitement de la transaction
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['compte']) && isset($_POST['operation']) && isset($_POST['montant'])) {
$id_client = isset($_POST['id_du_cpt']) ? $_POST['id_du_cpt'] : 0;
$compte_id = $_POST['compte'];
$operation = $_POST['operation'];
$montant = $_POST['montant'];
// Connexion à la base de données
$conn = new mysqli(SERVEUR, USER, PASSWORD, BDD);
if ($conn->connect_error) {
die("Échec de la connexion : " . $conn->connect_error);
}
// Récupération du solde actuel et de la limite de découvert
$sql = "SELECT Solde, MontantDec FROM Appartenir WHERE IdClient =? AND IdCompte = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ii", $id_client, $compte_id);
$stmt->execute();
$stmt->bind_result($Solde, $MontantDec);
$stmt->fetch();
$stmt->close();
// Calcul du nouveau solde
if ($operation == 'debit') {
$nouveau_solde = $Solde - $montant;
} else {
$nouveau_solde = $Solde + $montant;
}
// Vérification de la limite de découvert
if ($nouveau_solde < -$MontantDec) {
echo "<div class='form-container'><div class='NoResultat'>Erreur : La transaction dépasse la limite de découvert autorisé.</div></div>";
} else {
// Mise à jour du solde
$sql = "UPDATE Appartenir SET Solde = ? WHERE IdClient = ? AND IdCompte = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("dii", $nouveau_solde, $id_client, $compte_id);
$stmt->execute();
$stmt->close();
echo "<div class='form-container'><div class='NoResultat' style='background-color: green;'>Transaction effectuée avec succès.</div></div>";
}
// Fermeture de la connexion
$conn->close();
}
?>
</div>
<!-- prendre un rdv pour un client avec son conseiller< -->
<div id="rendezvous" class="tab-content">
<h2> Prendre un rdv pour un client avec son conseiller</h2>
<br>
<section class="search-section">
<form id="agendaPlanning" method="POST" class="search-form">
<div class="form-group">
<label>Rechercher un chargé client : </label>
<input type="number" id="id_du_cli" name="id_du_cli" required>
</div>
<div class="form-group">
<label for="semaine">Semaine :</label>
<input type="date" id="semaine1" name="semaine1" required>
</div>
<button type="submit" name="envoyerPlanning" id="envoyerPlanning" class="btn-primary">Afficher</button>
</form>
</section>
<!-- Liste des motifs en php pour le modal-->
<?php
// Connexion à la base de données
$conn = new mysqli(SERVEUR, USER, PASSWORD, BDD);
if ($conn->connect_error) {
die("Échec de la connexion : " . $conn->connect_error);
}
$sql = "SELECT IdMotif, NomMotif FROM Motif";
$result = $conn->query($sql);
$motifs = [];
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$motifs[] = $row; // Stocker chaque motif dans un tableau
}
}
$conn->close();
?>
<!-- Liste des Agents en php pour le modal-->
<?php
// Connexion à la base de données
$conn = new mysqli(SERVEUR, USER, PASSWORD, BDD);
if ($conn->connect_error) {
die("Échec de la connexion : " . $conn->connect_error);
}
// Requête SQL pour récupérer la liste des agents
$sql = "SELECT IdAgent, NomAgent, PrenomAgent FROM Agent";
$result = $conn->query($sql);
$agents = []; // Tableau pour stocker les agents
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$agents[] = $row; // Stocker chaque agent dans le tableau
}
}
$conn->close(); // Fermer la connexion
?>
<!-- Liste des clients en php pour le modal-->
<?php
// Connexion à la base de données
$conn = new mysqli(SERVEUR, USER, PASSWORD, BDD);
if ($conn->connect_error) {
die("Échec de la connexion : " . $conn->connect_error);
}
// Requête SQL pour récupérer la liste des clients
$sql = "SELECT IdClient, NomCl, PrenomCl FROM Client";
$result = $conn->query($sql);
$clients = []; // Tableau pour stocker les clients
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$clients[] = $row; // Stocker chaque client dans le tableau
}
}
$conn->close(); // Fermer la connexion
?>
<!-- Section pour afficher le planning -->
<section id="planning-section" class="planning-section">
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Connexion à la base de données
$conn = new mysqli(SERVEUR, USER, PASSWORD, BDD);
if ($conn->connect_error) {
die("Échec de la connexion : " . $conn->connect_error);
}
echo '<style>
.calendar-container {
display: flex;
justify-content: center;
align-items: center;
width: 80%; /* Ajustez la largeur selon vos besoins */
margin: 0 auto; /* Centre le conteneur horizontalement */
}
.NoResultat {
color: white;
background-color: red;
padding: 10px;
border-radius: 5px;
font-weight: bold;
text-align: center;
margin-top: 10px;
}
.form-container {
font-family: Arial, sans-serif;
max-width: 400px;
margin: 20px auto;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
background-color: #f9f9f9;
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);
text-align: center;
}
.calendar {
width: 100%;
border-collapse: collapse;
}
.calendar th, .calendar td {
border: 1px solid #ddd;
padding: 10px;
text-align: center;
}
.calendar th {
background-color: #ecf0f1;
font-weight: 600;
color: black;
font-weight: bold;
}
.hour-slot {
height: 60px;
color: black;
}
.free {
background-color: #d5f5e3;
cursor: pointer;
}
.occupied {
background-color: #fadbd8;
}
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.5);
}
.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 500px;
border-radius: 10px;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
</style>';
// Récupérer les rendez-vous pour une semaine donnée
if (isset($_POST['id_du_cli']) && isset($_POST['envoyerPlanning']) && isset($_POST['semaine1'])) {
$id_charge_client = $_POST['id_du_cli'];
$date_entree = date('Y-m-d', strtotime($_POST['semaine1']));
$date_debut = date('Y-m-d', strtotime('monday this week', strtotime($date_entree)));
$date_fin = date('Y-m-d', strtotime('friday this week', strtotime($date_entree)));
// Vérifier si le conseiller existe dans la base de données
$sql_check_conseiller = "SELECT IdConseiller, NomConseiller, PrenomConseiller FROM Conseiller WHERE IdConseiller = ?";
$stmt_check = $conn->prepare($sql_check_conseiller);
$stmt_check->bind_param("i", $id_charge_client);
$stmt_check->execute();
$result_check = $stmt_check->get_result();
if ($result_check->num_rows > 0) {
// Récupérer les informations du conseiller
$conseiller = $result_check->fetch_assoc();
$nom_conseiller = $conseiller['NomConseiller'];
$prenom_conseiller = $conseiller['PrenomConseiller'];
// Formater les dates de début et de fin au format JJ/MM/YYYY
$date_debut_formatee = date('d/m/Y', strtotime($date_debut));
$date_fin_formatee = date('d/m/Y', strtotime($date_fin));
// Récupérer les rendez-vous
$sql = "SELECT
r.IdRdv,
c.NomCl,
c.PrenomCl,
m.NomMotif,
r.HeureRdv,
r.DateRdv,
GROUP_CONCAT(p.NomPiece SEPARATOR ', ') AS Pieces
FROM Rendezvous r
LEFT JOIN Client c ON r.IdClient = c.IdClient
LEFT JOIN Motif m ON r.IdMotif = m.IdMotif
LEFT JOIN Requerir req ON m.IdMotif = req.IdMotif
LEFT JOIN Piece p ON req.IdPiece = p.IdPiece
LEFT JOIN Conseiller co ON r.IdConseiller = co.IdConseiller OR c.IdConseiller = co.IdConseiller
LEFT JOIN Employe e ON co.IdEmp = e.IdEmp
WHERE e.Role = 'Conseiller'
AND co.IdConseiller = ?
AND r.DateRdv BETWEEN ? AND ?
GROUP BY r.IdRdv
ORDER BY r.DateRdv, r.HeureRdv";
$stmt = $conn->prepare($sql);
$stmt->bind_param("iss", $id_charge_client, $date_debut, $date_fin);
$stmt->execute();
$result = $stmt->get_result();
$rendezvous = [];
$rdv_details = [];
while ($rdv = $result->fetch_assoc()) {
$jour = date('N', strtotime($rdv['DateRdv'])); // 1 (Lundi) à 7 (Dimanche)
$heure = date('H:i', strtotime($rdv['HeureRdv'])); // Assure un formatage correct de l'heure
$planning[$jour][$heure] = $rdv['NomMotif'];
// Stocker les détails complets pour chaque rendez-vous
$rdv_details[$jour][$heure] = [
'NomCl' => $rdv['NomCl'],
'PrenomCl' => $rdv['PrenomCl'],
'NomMotif' => $rdv['NomMotif'],
'Pieces' => $rdv['Pieces'],
'IdRdv' => $rdv['IdRdv']
];
}
// Définir les jours de la semaine et les heures de travail
$jours = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi'];
$heures = ['09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00'];
// Afficher le planning
echo '<div class="calendar-container">';
echo '<table class="calendar">';
echo '<thead>';
echo '<tr>';
echo '<th colspan="6"> Planning de ' . $nom_conseiller . ' ' . $prenom_conseiller . ' : ' . $date_debut_formatee . ' au ' . $date_fin_formatee . '</th>';
echo '</tr>';
echo '<tr>';
echo '<th>Heure</th>';
foreach ($jours as $jour) {
echo '<th>' . $jour . '</th>';
}
echo '</tr>';
echo '</thead>';
echo '<tbody id="calendar-body">';
foreach ($heures as $heure) {
echo '<tr>';
echo '<th>' . $heure . '</th>';
for ($i = 1; $i <= 5; $i++) { // 1 = Lundi, 5 = Vendredi
$date_rdv = date('Y-m-d', strtotime($date_debut . " + " . ($i - 1) . " days"));
if (isset($planning[$i][$heure])) {
echo '<td class="hour-slot occupied" data-date="' . $date_rdv . '" data-time="' . $heure . '" onclick="showModal(\'' . $i . '\', \'' . $heure . '\')">' . ($planning[$i][$heure]) . '</td>';} else {
echo '<td class="hour-slot free" data-date="' . $date_rdv . '" data-time="' . $heure . '" onclick="openModal(this)"></td>';
}
}
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
echo '</div>';
echo'<div id="modal-synthese" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal()">×</span>
<h2 style="color: red;">Ce créneau est déjà occupé.</h2>
<br>
<h3>Synthèse du rendez-vous</h3>
<p><strong>Nom :</strong> <span id="modal-nom-client"></span></p>
<p><strong>Prénom :</strong> <span id="modal-prenom-client"></span></p>
<p><strong>Motif :</strong> <span id="modal-motif"></span></p>
<p><strong>Pièces :</strong> <span id="modal-pieces"></span></p>
<p><strong>ID Rendez-vous :</strong> <span id="modal-id-rdv"></span></p>
</div>
</div>';
// Ajout du formulaire en modal
echo '
<div id="modal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal1()">×</span>
<h2>Ajouter un rendez-vous</h2>
<form id="appointmentForm" method="POST">
<input type="hidden" name="dateRdv" id="dateRdv">
<input type="hidden" name="HeureRv" id="HeureRv">
<div class="form-group">
<label>Motif</label>
<select id="motifName" name="motifName" required>
<option value="">Sélectionnez un motif</option>';
foreach ($motifs as $motif) {
echo '<option value="' . $motif['IdMotif'] . '">' . $motif['NomMotif'] . '</option>';
}
echo '
</select>
</div>
<div class="form-group">
<label>Agent</label>
<select id="agentName" name="agentName" required>
<option value="">Sélectionnez un agent</option>';
foreach ($agents as $agent) {
echo '<option value="' . $agent['IdAgent'] . '">' . $agent['NomAgent'] . ' ' . $agent['PrenomAgent'] . '</option>';
}
echo '
</select>
</div>
<div class="form-group">
<label>Client</label>
<select id="clientName" name="clientName" required>
<option value="">Sélectionnez un client</option>';
foreach ($clients as $client) {
echo '<option value="' . $client['IdClient'] . '">' . $client['NomCl'] . ' ' . $client['PrenomCl'] . '</option>';
}
echo '
</select>
</div>
<button type="submit" name="bouton_rdv" id="bouton_rdv">Enregistrer</button>
</form>
</div>
</div>';
// Ajout du script pour gérer le modal
echo '
<script>
function openModal(element) {
document.getElementById("modal").style.display = "block";
document.getElementById("dateRdv").value = element.getAttribute("data-date");
document.getElementById("HeureRv").value = element.getAttribute("data-time");
}
function closeModal1() {
document.getElementById("modal").style.display = "none";
}