Bonjour tout le monde,
je viens vers vous a fin de trouver une solution à une recherche par sélection qui n'abouti pas , La sélection se fait par
Département , Classe , Etudiants , Séances , Depuis une date , jusqu'à une Date
si après la page ou je fais la recherche :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <!-- Project Card Example --> <div class="card shadow mb-4"> <div class="card-header py-3"> <h6 class="m-0 font-weight-bold text-primary">Listes Pointages</h6> <div class="row"> <div class="col-lg-2 mb-4"> Département<br /> <select name="IDDep" id="IDDep" class="form-control form-control-user" onchange="giveSelection(this.value)"> <option value="0">--Please choose an option--</option> <?php $sqlD = "SELECT * FROM Departement"; $statementD = $conn->query($sqlD); $publishersD = $statementD->fetchAll(PDO::FETCH_ASSOC); if ($publishersD) { // show the publishers foreach ($publishersD as $publisherD) { echo '<option value="' . $publisherD['IDDepartement'] . '">' . $publisherD['LibelleDepartement'] . '</option>'; } } ?> </select> </div> <div class="col-lg-2 mb-4"> Classe<br /> <select name="IDSer" id="IDSer" class="form-control form-control-user" onclick="giveSelection2(this.value)" onchange="giveSelection2(this.value)"> <option value="0">--Please choose an option--</option> <?php $sqlS = "SELECT * FROM Service,Departement WHERE Service.IDDepartement=Departement.IDDepartement"; $statementS = $conn->query($sqlS); $publishersS = $statementS->fetchAll(PDO::FETCH_ASSOC); if ($publishersS) { // show the publishers foreach ($publishersS as $publisherS) { echo '<option data-option="' . $publisherS['IDDepartement'] . '" value="' . $publisherS['IDService'] . '">' . $publisherS['LibelleService'] . '</option>'; } } ?> </select> </div> <script> var IDDep = document.querySelector('#IDDep'); var IDSer = document.querySelector('#IDSer'); var options2 = IDSer.querySelectorAll('option'); function giveSelection(selValue) { IDSer.innerHTML = ''; for (var i = 0; i < options2.length; i++) { if (options2[i].dataset.option === selValue) { IDSer.appendChild(options2[i]); } } } giveSelection(IDDep.value); </script> <div class="col-lg-2 mb-2"> Etudiants<br /> <select name="IDEmp" id="IDEmp" class="form-control form-control-user"> <option value="0">--Please choose an option--</option> <?php $sqlE = "SELECT * FROM Employes,Affectation,Service WHERE Employes.IDEmployes=Affectation.IDEmployes AND Affectation.IDService=Service.IDService"; $statementE = $conn->query($sqlE); $publishersE = $statementE->fetchAll(PDO::FETCH_ASSOC); if ($publishersE) { // show the publishers foreach ($publishersE as $publisherE) { echo '<option data-option="' . $publisherE['IDService'] . '" value="' . $publisherE['UIDEmployes'] . '">' . $publisherE['NomCompletEmployes'] . '</option>'; } } ?> </select> </div> <script> var IDSer = document.querySelector('#IDSer'); var IDEmp = document.querySelector('#IDEmp'); var options3 = IDEmp.querySelectorAll('option'); function giveSelection2(selValue) { IDEmp.innerHTML = ''; IDEmp.innerHTML = '<option value="T">Tous</option>'; for (var i = 0; i < options3.length; i++) { if (options3[i].dataset.option === selValue) { IDEmp.appendChild(options3[i]); } } } giveSelection2(IDSer.value); </script> </select> <div class="col-lg-2 mb-4"> Séances<br /> <select name="IDSea" id="IDSea" class="form-control form-control-user" > <option value="0">--Please choose an option--</option> <?php $sqlD = "SELECT distinct seances FROM historique"; $statementD = $conn->query($sqlD); $publishersD = $statementD->fetchAll(PDO::FETCH_ASSOC); if ($publishersD) { // show the publishers foreach ($publishersD as $publisherD) { echo '<option value="' . $publisherD['IDPointages'] . '">' . $publisherD['seances'] . '</option>'; } } ?> </div> <div class="col-lg-1 mb-4"> <div class="wrapper"> <div class="line"></div> <div class="wordwrapper"> <div class="word">OU</div> </div> </div> </div> <div class="col-lg-2 mb-4"> De<br /> <input type="date" class="form-control form-control-user" name="DateFrom" id="DateFrom"> </div> <div class="col-lg-2 mb-4"> A<br /> <input type="date" class="form-control form-control-user" name="DateTo" id="DateTo"> </div> </div> <div class="row"> <div class="col-lg-10 mb-4"> <div id="ResultatAff"> <?php $ErreurPontage = $_SESSION["ErreurPontage"] ?? ""; echo $ErreurPontage; ?> </div> </div> <div class="col-lg-2 mb-4" align="right"> <button onclick="showResult()" class="btn btn-success btn-icon-split"> <span class="icon text-white-50"><i class="fas fa-search"></i></span> <span class="text">Chercher</span> </button> <script> function isValid(value) { if (!value) return false; else return true; } function showResult() { $(document).ready(function() { $("#ModalLoad").modal('show'); }); ResultatAff.innerHTML = ''; var IDDep = document.getElementById("IDDep"); var NbIDDep = IDDep[IDDep.selectedIndex].value; var TxtIDDep = IDDep[IDDep.selectedIndex].text; var IDSer = document.getElementById("IDSer"); var NbIDSer = IDSer[IDSer.selectedIndex].value; var TxtIDSer = IDSer[IDSer.selectedIndex].text; var IDEmp = document.getElementById("IDEmp"); var NbIDEmp = IDEmp[IDEmp.selectedIndex].value; var TxtIDEmp = IDEmp[IDEmp.selectedIndex].text; var DateFrom = document.getElementById("DateFrom"); var NbDateFrom = DateFrom.value; var DateTo = document.getElementById("DateTo"); var NbDateTo = DateTo.value; var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("ResultatAff").innerHTML = this.responseText; } }; if (!NbDateFrom && !NbDateTo) { xmlhttp.open("GET", "control/F_ShowPointage.php?DepTxt=" + TxtIDDep + "&SeaTxt=" + TxtIDSea +"&SerTxt=" + TxtIDSer + "&EmpTxt=" + TxtIDEmp + "&Dep=" + NbIDDep + "&Ser=" + NbIDSer + "&Emp=" + NbIDEmp, true); } else if (!NbDateFrom && NbDateTo) { ResultatAff.innerHTML += '<div class="card border-left-danger shadow h-50 py-2"><div class="card-body"><div class="row no-gutters align-items-center"><div class="col mr-2"><div class="text-xs font-weight-bold text-danger text-uppercase mb-1">ERREUR</div><div class="row no-gutters align-items-center">Date From Indéfinie</div></div><div class="col-auto"><i class="fas fa-exclamation-triangle fa-2x text-red-300"></i></div></div></div></div>'; document.getElementById('ModalClose').click(); } else if (NbDateFrom && !NbDateTo) { ResultatAff.innerHTML += '<div class="card border-left-danger shadow h-50 py-2"><div class="card-body"><div class="row no-gutters align-items-center"><div class="col mr-2"><div class="text-xs font-weight-bold text-danger text-uppercase mb-1">ERREUR</div><div class="row no-gutters align-items-center">Date To Indéfinie</div></div><div class="col-auto"><i class="fas fa-exclamation-triangle fa-2x text-red-300"></i></div></div></div></div>'; document.getElementById('ModalClose').click(); } else { var d1 = new Date(NbDateFrom); var d2 = new Date(NbDateTo); var diff = d2.getTime() - d1.getTime(); var daydiff = diff / (1000 * 60 * 60 * 24); if (daydiff < 0) { ResultatAff.innerHTML += '<div class="card border-left-danger shadow h-50 py-2"><div class="card-body"><div class="row no-gutters align-items-center"><div class="col mr-2"><div class="text-xs font-weight-bold text-danger text-uppercase mb-1">ERREUR</div><div class="row no-gutters align-items-center">Incoérence entre les deux date</div></div><div class="col-auto"><i class="fas fa-exclamation-triangle fa-2x text-red-300"></i></div></div></div></div>'; } else { xmlhttp.open("GET", "control/F_ShowPointage.php?DepTxt=" + TxtIDDep + "&SeaTxt="+ TxtIDSea +"&SerTxt=" + TxtIDSer + "&EmpTxt=" + TxtIDEmp + "&Dep=" + NbIDDep + "&Ser=" + NbIDSer + "&Emp=" + NbIDEmp + "&DateFrom=" + NbDateFrom + "&DateTo=" + NbDateTo + "&DayDiff=" + daydiff, true); } } xmlhttp.send(); setTimeout(function() { document.getElementById("ResPo").innerHTML = document.getElementById("ResInput").value; document.getElementById('ModalClose').click(); }, 5000); } </script> </div> </div> </div> <div class="card-body"> <div class="table-responsive" id="ResPo"> </div> </div> </div> </div> </div> </div> <!-- /.container-fluid --> </div> <!-- End of Main Content -->
Ensuite la page qui affiche est F_ShowPointage.php :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 //debut de la session session_name('ZKTeco'); session_start(); $conn = OpenCon(); $myIniFile = parse_ini_file("../ini/Config.ini", TRUE); $host = $myIniFile["pointeurse"]["adr"]; $zk = new ZKLib($host, 4370); $DateFrom = null; $DateTo = null; //recuperation des valeurs $IDDep = $_GET['Dep'] ?? ""; $IDSer = $_GET['Ser'] ?? ""; $IDEmp = $_GET['Emp'] ?? ""; $TxtIDDep = $_GET['DepTxt'] ?? ""; $TxtIDSer = $_GET['SerTxt'] ?? ""; $TxtIDEmp = $_GET['EmpTxt'] ?? ""; if ($_GET['DateFrom'] ?? "") { $DateFrom = new DateTime($_GET['DateFrom'] ?? ""); } if ($_GET['DateTo'] ?? "") { $DateTo = new DateTime($_GET['DateTo'] ?? ""); } $DayDiff = $_GET['DayDiff'] ?? ""; $SqlRecherche = null; $Resultat = ""; $diff = null; if (!empty($DateFrom) && !empty($DateTo)) { if ($IDEmp == 'T') { $SqlRecherche = "SELECT DISTINCT * FROM Employes,Service,Departement,Affectation,historique WHERE Service.IDService=Affectation.IDService AND Employes.IDEmployes=historique.IDEmployePointages AND Service.IDDepartement=Departement.IDDepartement AND Employes.UIDEmployes=Affectation.IDEmployes AND ActiveEmp!=0 AND Service.IDService=".$IDSer." AND Departement.IDDepartement=".$IDDep." AND historique.DatePointages BETWEEN '".$DateFrom->format('Y-m-d')."' AND '".$DateTo->format('Y-m-d')."' "; } else { $SqlRecherche = "SELECT DISTINCT * FROM Employes,Service,Departement,Affectation,historique WHERE Service.IDService=Affectation.IDService AND Employes.IDEmployes=historique.IDEmployePointages AND Service.IDDepartement=Departement.IDDepartement AND Employes.UIDEmployes=Affectation.IDEmployes AND ActiveEmp!=0 AND Service.IDService=".$IDSer." AND Departement.IDDepartement=".$IDDep." AND Employes.IDEmployes=".$IDEmp." AND historique.DatePointages BETWEEN '".$DateFrom->format('Y-m-d')."' AND '".$DateTo->format('Y-m-d')."'"; } //echo $SqlRecherche."<br/>"; echo '<div class="card border-left-success shadow h-50 py-2"> <div class="card-body"> <div class="row no-gutters align-items-center"> <div class="col mr-2"> <div class="text-xs font-weight-bold text-success text-uppercase mb-1">Recherche </div> <div class="row no-gutters align-items-center"> Département : <b>' . $TxtIDDep . '</b> - Filière : <b>' . $TxtIDSer . '</b> - Employée : <b>' . $TxtIDEmp . '</b> | De : <b>' . $DateFrom->format('Y-m-d') . '</b> - A : <b>' . $DateTo->format('Y-m-d') . '</b> - Totale Jours : ' . $DayDiff . '</div> </div> <div class="col-auto"> <i class="fas fa-search fa-2x text-red-300"></i> </div> </div> </div> </div>'; $Resultat .= "<table class='table table-bordered' id='dataTable' width='100%' cellspacing='0'> <thead> <tr> <th>ID</th> <th>Nom</th> <!--th>N° Card</th!--> <th>Département</th> <th>Filière</th> <!--th>Pointage</th!--> <th>Date</th> <th>Heure</th> <!--th>Type</th!--> <th>Salle</th> <th>Statut</th> <th>Seances</th> </tr> </thead> <tbody >"; $statement = $conn->query($SqlRecherche); $publishers = $statement->fetchAll(PDO::FETCH_ASSOC); if ($publishers) { foreach ($publishers as $publisher) { $Resultat .= "<tr><td>" . $publisher['IDPointages'] . "</td><td>" . $publisher['NomCompletEmployes'] . "</td><td>" . $publisher['LibelleDepartement'] . "</td><td>" . $publisher['LibelleService'] . "</td><td>" . $publisher['DatePointages'] . "</td><td>" . $publisher['HeurPointages'] . "</td><td>" . $publisher['salle'] . "</td><td>" . $publisher['statut'] . "</td><td>" . $publisher['seances'] . "</td></tr>"; } } } else { if ($IDEmp == 'T') { $SqlRecherche = "SELECT * FROM Employes,Service,Departement,Affectation,historique WHERE Service.IDService=Affectation.IDService AND Employes.IDEmployes=historique.IDEmployePointages AND Service.IDDepartement=Departement.IDDepartement AND Employes.UIDEmployes=Affectation.IDEmployes AND ActiveEmp!=0 AND Service.IDService=".$IDSer." AND Departement.IDDepartement=".$IDDep."; "; } else { $SqlRecherche = "SELECT * FROM Employes,Service,Departement,Affectation,historique WHERE Service.IDService=Affectation.IDService AND Employes.IDEmployes=historique.IDEmployePointages AND Service.IDDepartement=Departement.IDDepartement AND Employes.UIDEmployes=Affectation.IDEmployes AND ActiveEmp!=0 AND Service.IDService=".$IDSer." AND Departement.IDDepartement=".$IDDep." AND Employes.IDEmployes=".$IDEmp.""; } //echo $SqlRecherche."<br/>"; echo '<div class="card border-left-success shadow h-50 py-2"> <div class="card-body"> <div class="row no-gutters align-items-center"> <div class="col mr-2"> <div class="text-xs font-weight-bold text-success text-uppercase mb-1">Recherche </div> <div class="row no-gutters align-items-center"> Département : <b>' . $TxtIDDep . '</b> - Filière : <b>' . $TxtIDSer . '</b> - Employée : <b>' . $TxtIDEmp . '</b></div> </div> <div class="col-auto"> <i class="fas fa-search fa-2x text-red-300"></i> </div> </div> </div> </div>'; $Resultat .= "<table class='table table-bordered' id='dataTable' width='100%' cellspacing='0'> <thead> <tr> <th>ID</th> <th>Nom</th> <!--th>N° Card</th!--> <th>Département</th> <th>Filière</th> <!--th>Pointage</th!--> <th>Date</th> <th>Heure</th> <!--th>Type</th!--> <th>Salle</th> <th>Statut</th> <th>Seances</th> </tr> </thead> <tbody >"; $statement = $conn->query($SqlRecherche); $publishers = $statement->fetchAll(PDO::FETCH_ASSOC); if ($publishers) { foreach ($publishers as $publisher) { $Resultat .= "<tr><td>" . $publisher['IDPointages'] . "</td><td>" . $publisher['NomCompletEmployes'] . "</td><td>" . $publisher['LibelleDepartement'] . "</td><td>" . $publisher['LibelleService'] . "</td><td>" . $publisher['DatePointages'] . "</td><td>" . $publisher['HeurPointages'] . "</td><td>" . $publisher['salle'] . "</td><td>" . $publisher['statut'] . "</td><td>" . $publisher['seances'] . "</td></tr>"; } } } //echo $SqlRecherche.'<br/>'; $Resultat .= " </tbody> </table>"; echo '<input type="text" id="ResInput" value="' . $Resultat . '" hidden/>';
Partager