-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathliste_clients.html
More file actions
267 lines (242 loc) · 13.7 KB
/
Copy pathliste_clients.html
File metadata and controls
267 lines (242 loc) · 13.7 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
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HardLink - Liste des Clients</title>
<link rel="icon" type="image/svg+xml" href="img/favicon.svg">
<link rel="stylesheet" href="global.css?v=1.2">
<link rel="stylesheet" href="liste_clients.css?v=1.2">
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
<script src="js/auth_check.js"></script>
<script src="js/password_confirmation.js"></script>
<script src="js/delete_client_debug.js"></script>
</head>
<body>
<div class="container_lst_client">
<div class="header-title-group">
<h1>HardLink - Liste des Clients</h1>
</div>
<div class="controls">
<input type="text" id="search-input" placeholder="Rechercher un client...">
<button id="export-excel-btn" class="action-button action-buttons-export">
<svg viewBox="0 0 24 24" width="18" height="18" style="margin-right: 5px;" fill="currentColor"><path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z"/></svg>
Exp vers Excel
</button>
<input type="file" id="import-excel-input" accept=".xlsx, .xls" style="display: none;">
<button id="import-excel-btn" class="action-button action-buttons-import auth-button">
<svg viewBox="0 0 24 24" width="18" height="18" style="margin-right: 5px;" fill="currentColor"><path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm-1 10V9h-2v3H8l4 4 4-4h-3zm0-1H8v-2h3V9h2v2z"/></svg>
Imp depuis Excel
</button>
<button class="action-button add-button auth-button" onclick="window.location.href='client.html'">
<svg viewBox="0 0 24 24" width="18" height="18" style="margin-right: 5px;" fill="currentColor"><path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg>
Ajouter client
</button>
<button onclick="window.location.href='dashboard.html'" class="action-button back-btn">
<svg viewBox="0 0 24 24" width="18" height="18" style="margin-right: 5px;" fill="currentColor"><path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>
Retour Dashboard
</button>
</div>
<div class="table-container">
<table id="equipments-table">
<thead>
<tr>
<th>ID</th>
<th>Institution</th>
<th>Nom Client</th>
<th>Adresse</th>
<th>Téléphone</th>
<th>Email</th>
<th>Nom Contact</th>
<th>N° Contact</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="clientTableBody">
<!-- Les clients seront chargés ici par JavaScript -->
</tbody>
</table>
</div>
<footer class="main-footer">
<p>© 2025 HardLink - Tous droits réservés</p>
</footer>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const clientsTableBody = document.getElementById('clientTableBody');
const searchInput = document.getElementById('search-input');
async function loadClients(filteredClients = null) {
let clients = filteredClients;
if (!clients) {
try {
const response = await fetch('api/get_clients.php');
if (!response.ok) {
const errorText = await response.text();
throw new Error(`HTTP error! status: ${response.status}, body: ${errorText}`);
}
const data = await response.json();
if (data.success) {
clients = data.clients;
} else {
console.error('Erreur lors du chargement des clients:', data.message);
alert('Erreur lors du chargement des clients.');
}
} catch (error) {
console.error('Erreur réseau lors du chargement des clients:', error);
alert('Une erreur réseau est survenue lors du chargement des clients.');
}
}
clientsTableBody.innerHTML = ''; // Clear existing rows
if (clients) {
clients.forEach(client => {
const row = clientsTableBody.insertRow();
row.insertCell().textContent = client.id;
row.insertCell().textContent = (client.nomInstitution || '').toString().trim();
row.insertCell().textContent = (client.client || '').toString().trim();
row.insertCell().textContent = (client.adresse || '').toString().trim();
row.insertCell().textContent = (client.numeroTelephone || '').toString().trim();
row.insertCell().textContent = (client.emailClient || 'N/A').toString().trim();
row.insertCell().textContent = (client.nomContact || 'N/A').toString().trim();
row.insertCell().textContent = (client.numeroContact || 'N/A').toString().trim();
const actionsCell = row.insertCell();
actionsCell.classList.add('actions-cell');
const editButton = document.createElement('button');
editButton.textContent = 'Modifier';
editButton.classList.add('action-button', 'edit-button');
editButton.onclick = () => editClient(client.id);
actionsCell.appendChild(editButton);
const deleteButton = document.createElement('button');
deleteButton.textContent = 'Supprimer';
deleteButton.classList.add('action-button', 'delete-button');
deleteButton.onclick = () => deleteClient(client.id);
actionsCell.appendChild(deleteButton);
});
}
hideAdminElements(); // Appel de la fonction après le rendu des clients
}
function editClient(id) {
console.log('Modifier le client avec l\'ID :', id);
window.location.href = `modifier_client.html?id=${id}`;
}
function deleteClient(id) {
// Demander le mot de passe de confirmation avant la suppression
showPasswordConfirmationModal('supprimer ce client', async function() {
try {
const currentUser = JSON.parse(localStorage.getItem('currentUser'));
const username = currentUser ? currentUser.username : 'Administrateur';
const response = await fetch('api/delete_client.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ id: id, username: username })
});
const data = await response.json();
if (data.success) {
alert('Client supprimé avec succès !');
loadClients(); // Recharger la liste des clients après suppression
} else {
alert('Erreur lors de la suppression du client: ' + data.message);
}
} catch (error) {
console.error('Erreur réseau lors de la suppression:', error);
alert('Une erreur est survenue lors de la suppression du client.');
}
});
}
loadClients(); // Initial load of clients
const importExcelBtn = document.querySelector('#import-excel-btn');
const importExcelInput = document.querySelector('#import-excel-input');
importExcelBtn.addEventListener('click', () => {
importExcelInput.click(); // Déclenche le clic sur l'input de type fichier masqué
});
importExcelInput.addEventListener('change', (event) => {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = async (e) => {
const data = new Uint8Array(e.target.result);
const workbook = XLSX.read(data, { type: 'array' });
const firstSheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[firstSheetName];
const jsonClients = XLSX.utils.sheet_to_json(worksheet);
console.log('Données Excel lues (JSON):', jsonClients);
console.log('Données clients envoyées à l\'API:', JSON.stringify({ clients: jsonClients }));
// Envoyer les données au backend
try {
const currentUser = JSON.parse(localStorage.getItem('currentUser'));
const username = currentUser ? currentUser.username : 'Administrateur';
const response = await fetch('api/import_clients.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ clients: jsonClients, username: username })
});
const result = await response.json();
if (result.success) {
alert(result.message);
loadClients(); // Recharger la liste des clients après l'importation
} else {
alert('Erreur lors de l\'importation: ' + result.message);
console.error('Détails de l\'erreur:', result.errors);
}
} catch (error) {
console.error('Erreur réseau lors de l\'importation:', error);
alert('Une erreur réseau est survenue lors de l\'importation des clients.');
}
};
reader.readAsArrayBuffer(file);
}
});
searchInput.addEventListener('keyup', async (event) => {
const searchTerm = event.target.value.toLowerCase();
let allClients = [];
try {
const response = await fetch('api/get_clients.php');
const data = await response.json();
if (data.success) {
allClients = data.clients;
}
} catch (error) {
console.error('Erreur réseau lors de la recherche:', error);
}
const filteredClients = allClients.filter(client => {
const match = (
String(client.id).toLowerCase().includes(searchTerm) ||
String(client.nomInstitution).toLowerCase().includes(searchTerm) ||
String(client.client).toLowerCase().includes(searchTerm) ||
String(client.adresse).toLowerCase().includes(searchTerm) ||
String(client.numeroTelephone).toLowerCase().includes(searchTerm) ||
(client.emailClient && String(client.emailClient).toLowerCase().includes(searchTerm)) ||
(client.nomContact && String(client.nomContact).toLowerCase().includes(searchTerm)) ||
(client.numeroContact && String(client.numeroContact).toLowerCase().includes(searchTerm))
);
return match;
});
loadClients(filteredClients);
});
const exportExcelBtn = document.querySelector('#export-excel-btn');
exportExcelBtn.addEventListener('click', async () => {
let clients = [];
try {
const response = await fetch('api/get_clients.php');
const data = await response.json();
if (data.success) {
clients = data.clients;
}
} catch (error) {
console.error('Erreur réseau lors de l\'exportation:', error);
alert('Une erreur est survenue lors de la récupération des données pour l\'exportation.');
return;
}
const worksheet = XLSX.utils.json_to_sheet(clients);
const workbook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(workbook, worksheet, 'Clients');
XLSX.writeFile(workbook, 'clients.xlsx');
});
});
</script>
<script src="background-slider.js"></script>
</body>
</html>