-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
699 lines (639 loc) · 43.1 KB
/
index.php
File metadata and controls
699 lines (639 loc) · 43.1 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
<?php
session_start();
require_once 'excel-reader.php';
// Initialize Excel Manager
$excelManager = new ExcelManager();
$debugMessage = "";
// Get current active tab from session or default to 'files'
$activeTab = $_SESSION['active_tab'] ?? 'files';
// Handle form submissions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['action'])) {
// Store the action to determine which tab should be active
$action = $_POST['action'];
$_SESSION['active_tab'] = getTabForAction($action);
$activeTab = $_SESSION['active_tab'];
switch ($action) {
case 'add_files':
if (isset($_FILES['excel_files'])) {
$overwrite = isset($_POST['overwrite_files']) && $_POST['overwrite_files'] === 'true';
$result = $excelManager->addExcelFiles($_FILES['excel_files'], $overwrite);
$debugMessage = $result['message'];
}
break;
case 'search':
$searchTerm = $_POST['search_term'] ?? '';
$searchResults = $excelManager->search($searchTerm);
break;
case 'check_duplicates':
$type = $_POST['duplicate_type'] ?? 'files';
$duplicateResults = $excelManager->checkDuplicates($type);
$debugMessage = $duplicateResults['message'];
break;
case 'establishments':
$establishmentResults = $excelManager->getEstablishments();
break;
case 'list_all':
$files = $excelManager->getExcelFiles();
if (!empty($files)) {
$allData = $excelManager->getAllData();
}
break;
case 'archive':
$archiveType = $_POST['archive_type'] ?? 'create';
if ($archiveType === 'create') {
$result = $excelManager->createArchive();
$debugMessage = $result['message'];
}
break;
case 'delete_file':
$filename = $_POST['filename'] ?? '';
if ($filename) {
$result = $excelManager->deleteFile($filename);
$debugMessage = $result['message'];
}
break;
case 'update_file':
$filename = $_POST['filename'] ?? '';
if ($filename && isset($_FILES['updated_file'])) {
$result = $excelManager->updateFile($filename, $_FILES['updated_file']);
$debugMessage = $result['message'];
}
break;
case 'delete_archive':
$archiveName = $_POST['archive_name'] ?? '';
if ($archiveName) {
$result = $excelManager->deleteArchive($archiveName);
$debugMessage = $result['message'];
}
break;
}
}
} elseif (isset($_GET['tab'])) {
// Handle tab switching via GET
$activeTab = $_GET['tab'];
$_SESSION['active_tab'] = $activeTab;
}
// Auto-load data for list tab when it's active
if ($activeTab === 'list' && !isset($allData) && !isset($searchResults)) {
$files = $excelManager->getExcelFiles();
if (!empty($files)) {
$allData = $excelManager->getAllData();
}
}
// Get archived folders
$archivedFolders = $excelManager->getArchivedFolders();
// Extract years from archive names for filter
$archiveYears = [];
foreach ($archivedFolders as $archive) {
if (preg_match('/archive_(\d{4})-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}/', $archive, $matches)) {
$year = $matches[1];
if (!in_array($year, $archiveYears)) {
$archiveYears[] = $year;
}
}
}
rsort($archiveYears); // Sort years descending
// Get selected year from filter
$selectedYear = $_GET['archive_year'] ?? '';
// Filter archives by year if selected
$filteredArchives = $archivedFolders;
if (!empty($selectedYear)) {
$filteredArchives = array_filter($archivedFolders, function($archive) use ($selectedYear) {
return strpos($archive, $selectedYear) !== false;
});
}
// Helper function to determine which tab should be active based on action
function getTabForAction($action) {
$tabMap = [
'add_files' => 'files',
'search' => 'list',
'check_duplicates' => 'duplicate',
'establishments' => 'establishment',
'list_all' => 'list',
'archive' => 'archive',
'delete_file' => 'files',
'update_file' => 'files',
'delete_archive' => 'archive'
];
return $tabMap[$action] ?? 'files';
}
// Helper function to format file size
function formatFileSize($bytes) {
if ($bytes == 0) return '0 Bytes';
$k = 1024;
$sizes = ['Bytes', 'KB', 'MB', 'GB'];
$i = floor(log($bytes) / log($k));
return round($bytes / pow($k, $i), 2) . ' ' . $sizes[$i];
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gestionnaire Excel</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="cmd-container">
<!-- Header -->
<div class="cmd-header">
<div class="title-bar">
<div class="title-text">
<span class="title-icon">⚙️</span>
Excel-Manager - Version 2.6
</div>
<div class="window-controls">
<button class="control-btn minimize">−</button>
<button class="control-btn maximize">□</button>
<button class="control-btn close">×</button>
</div>
</div>
<!-- Debug Display -->
<div class="debug-display">
<span class="debug-label">DEBUG:</span>
<span class="debug-message"><?php echo htmlspecialchars($debugMessage); ?></span>
</div>
</div>
<!-- Main Content -->
<div class="cmd-content">
<!-- Navigation Menu -->
<div class="nav-menu">
<button class="nav-btn <?php echo $activeTab === 'files' ? 'active' : ''; ?>" data-tab="files">Gestion des Fichiers</button>
<button class="nav-btn <?php echo $activeTab === 'list' ? 'active' : ''; ?>" data-tab="list">Liste & Recherche</button>
<button class="nav-btn <?php echo $activeTab === 'duplicate' ? 'active' : ''; ?>" data-tab="duplicate">Doublons</button>
<button class="nav-btn <?php echo $activeTab === 'establishment' ? 'active' : ''; ?>" data-tab="establishment">Établissements</button>
<button class="nav-btn <?php echo $activeTab === 'archive' ? 'active' : ''; ?>" data-tab="archive">Archives</button>
</div>
<!-- Tab Content -->
<div class="tab-content">
<!-- Files Management Tab -->
<div id="files" class="tab-pane <?php echo $activeTab === 'files' ? 'active' : ''; ?>">
<h2>Gestion des Fichiers Excel</h2>
<!-- Add Files Section -->
<div class="section-card">
<h3>Ajouter des Fichiers Excel</h3>
<form method="post" enctype="multipart/form-data" class="upload-form" id="addForm">
<input type="hidden" name="action" value="add_files">
<input type="hidden" name="overwrite_files" id="overwriteFilesInput" value="false">
<div class="file-input-container">
<input type="file" name="excel_files[]" multiple accept=".xlsx,.xls,.csv" class="file-input" id="excelFiles">
<span class="file-input-label" id="fileInputLabel">Sélectionner les fichiers Excel</span>
</div>
<button type="submit" class="cmd-button">Importer les Fichiers</button>
</form>
</div>
<!-- File List Section -->
<div class="section-card">
<h3>Fichiers Existants</h3>
<!-- File Search -->
<div class="search-section" style="margin-bottom: 20px;">
<input type="text" id="fileSearchInput" placeholder="Rechercher un fichier..." class="search-input" style="flex: 1;">
<button onclick="searchFiles()" class="cmd-button">Rechercher</button>
<button onclick="clearFileSearch()" class="cmd-button secondary" style="margin-left: 10px;">Effacer</button>
</div>
<?php
$files = $excelManager->getExcelFiles();
if (!empty($files)):
?>
<div class="files-list">
<h4>Fichiers Excel (<?php echo count($files); ?>)</h4>
<div class="files-grid" id="filesGrid">
<?php foreach ($files as $file): ?>
<div class="file-item" data-filename="<?php echo htmlspecialchars($file); ?>">
<div class="file-info">
<span class="file-icon">📊</span>
<span class="file-name"><?php echo htmlspecialchars($file); ?></span>
<span class="file-size"><?php echo formatFileSize(filesize('excel/' . $file)); ?></span>
</div>
<div class="file-actions">
<!-- Update File Form -->
<form method="post" enctype="multipart/form-data" class="file-action-form update-form" style="display: none;" id="updateForm_<?php echo md5($file); ?>">
<input type="hidden" name="action" value="update_file">
<input type="hidden" name="filename" value="<?php echo htmlspecialchars($file); ?>">
<div class="file-update-input">
<input type="file" name="updated_file" accept=".xlsx,.xls,.csv" required>
<button type="submit" class="cmd-button small success">Mettre à jour</button>
<button type="button" class="cmd-button small secondary" onclick="cancelUpdate('<?php echo md5($file); ?>')">Annuler</button>
</div>
</form>
<!-- Action Buttons -->
<div class="action-buttons" id="actionButtons_<?php echo md5($file); ?>">
<button class="cmd-button small" onclick="showUpdateForm('<?php echo md5($file); ?>')">
<span class="update-icon">🔄</span> Modifier
</button>
<!-- SIMPLE DELETE FORM - NO CONFIRMATION -->
<form method="post" class="file-action-form">
<input type="hidden" name="action" value="delete_file">
<input type="hidden" name="filename" value="<?php echo htmlspecialchars($file); ?>">
<button type="submit" class="cmd-button small danger">
<span class="delete-icon">🗑️</span> Supprimer
</button>
</form>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php else: ?>
<p class="no-data">Aucun fichier Excel trouvé.</p>
<?php endif; ?>
</div>
</div>
<!-- List & Search Tab -->
<div id="list" class="tab-pane <?php echo $activeTab === 'list' ? 'active' : ''; ?>">
<h2>Liste Complète & Recherche</h2>
<?php
$files = $excelManager->getExcelFiles();
if (empty($files)):
?>
<div class="no-data-section">
<p class="no-data">Aucun fichier Excel trouvé. Veuillez d'abord ajouter des fichiers dans l'onglet "Gestion des Fichiers Excel".</p>
<button class="cmd-button" onclick="switchToTab('files')">
Aller à Gestion des Fichiers
</button>
</div>
<?php else: ?>
<!-- Search Form -->
<form method="post" class="search-form" id="searchForm" style="margin-bottom: 20px;">
<input type="hidden" name="action" value="search">
<input type="text" name="search_term" placeholder="Rechercher par nom, prénom, CIN, établissement..."
class="search-input" value="<?php echo isset($searchTerm) ? htmlspecialchars($searchTerm) : ''; ?>" style="flex: 1;">
<button type="submit" class="cmd-button">Rechercher</button>
<button type="button" onclick="resetSearch()" class="cmd-button secondary" style="margin-left: 10px;">Afficher Tout</button>
</form>
<?php if (isset($allData) || isset($searchResults)): ?>
<?php
// Determine which data to use
$displayData = isset($searchResults) ? $searchResults['data'] : $allData['data'];
$totalItems = count($displayData);
// Handle pagination - preserve search term
$currentPage = isset($_GET['page']) ? max(1, intval($_GET['page'])) : 1;
$itemsPerPage = isset($_GET['per_page']) ? intval($_GET['per_page']) : 10;
$totalPages = ceil($totalItems / $itemsPerPage);
// Apply pagination
$startIndex = ($currentPage - 1) * $itemsPerPage;
$paginatedData = array_slice($displayData, $startIndex, $itemsPerPage);
?>
<div class="statistics">
<h3>Statistiques</h3>
<div class="stats-grid">
<div class="stat-item">
<span class="stat-number"><?php echo $totalItems; ?></span>
<span class="stat-label">Étudiants Total</span>
</div>
<div class="stat-item">
<span class="stat-number"><?php echo isset($allData) ? $allData['total_establishments'] : (isset($establishmentResults) ? count($establishmentResults['data']) : 'N/A'); ?></span>
<span class="stat-label">Établissements</span>
</div>
<div class="stat-item">
<span class="stat-number"><?php echo isset($allData) ? $allData['total_files'] : count($excelManager->getExcelFiles()); ?></span>
<span class="stat-label">Fichiers Excel</span>
</div>
</div>
</div>
<!-- Pagination Controls -->
<?php if ($totalPages > 1): ?>
<div class="pagination" style="margin: 15px 0; display: flex; justify-content: space-between; align-items: center;">
<div>
Page <?php echo $currentPage; ?> sur <?php echo $totalPages; ?>
(<?php echo $totalItems; ?> élément(s))
</div>
<div class="pagination-buttons">
<?php if ($currentPage > 1): ?>
<a href="?tab=list&page=<?php echo $currentPage - 1; ?>&per_page=<?php echo $itemsPerPage; ?><?php echo isset($searchTerm) ? '&search=' . urlencode($searchTerm) : ''; ?>" class="cmd-button small">← Précédent</a>
<?php endif; ?>
<?php
// Show page numbers
$startPage = max(1, $currentPage - 2);
$endPage = min($totalPages, $currentPage + 2);
for ($i = $startPage; $i <= $endPage; $i++) {
echo '<a href="?tab=list&page=' . $i . '&per_page=' . $itemsPerPage;
if (isset($searchTerm)) {
echo '&search=' . urlencode($searchTerm);
}
echo '" class="cmd-button small' . ($i === $currentPage ? ' active' : '') . '">' . $i . '</a>';
}
?>
<?php if ($currentPage < $totalPages): ?>
<a href="?tab=list&page=<?php echo $currentPage + 1; ?>&per_page=<?php echo $itemsPerPage; ?><?php echo isset($searchTerm) ? '&search=' . urlencode($searchTerm) : ''; ?>" class="cmd-button small">Suivant →</a>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<div class="data-table-container">
<?php
// Display only paginated data
$tempData = $displayData;
$displayData = $paginatedData;
$excelManager->displayDataTable($displayData);
$displayData = $tempData; // Restore original data
?>
</div>
<?php if ($totalPages > 1): ?>
<div class="pagination" style="margin: 15px 0; display: flex; justify-content: center;">
<div class="pagination-buttons">
<?php if ($currentPage > 1): ?>
<a href="?tab=list&page=<?php echo $currentPage - 1; ?>&per_page=<?php echo $itemsPerPage; ?><?php echo isset($searchTerm) ? '&search=' . urlencode($searchTerm) : ''; ?>" class="cmd-button small">← Précédent</a>
<?php endif; ?>
<?php if ($currentPage < $totalPages): ?>
<a href="?tab=list&page=<?php echo $currentPage + 1; ?>&per_page=<?php echo $itemsPerPage; ?><?php echo isset($searchTerm) ? '&search=' . urlencode($searchTerm) : ''; ?>" class="cmd-button small">Suivant →</a>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<?php else: ?>
<p class="no-data">Aucune donnée à afficher. Utilisez le formulaire de recherche ou chargez des fichiers.</p>
<?php endif; ?>
<?php endif; ?>
</div>
<!-- Duplicate Tab -->
<div id="duplicate" class="tab-pane <?php echo $activeTab === 'duplicate' ? 'active' : ''; ?>">
<h2>Vérifier les Doublons</h2>
<form method="post" class="duplicate-form" id="duplicateForm">
<input type="hidden" name="action" value="check_duplicates">
<div class="radio-group">
<label>
<input type="radio" name="duplicate_type" value="files" checked>
Doublons de Fichiers
</label>
<label>
<input type="radio" name="duplicate_type" value="individuals">
Doublons d'Individus (Nom/CIN)
</label>
</div>
<button type="submit" class="cmd-button">Vérifier les Doublons</button>
</form>
<?php if (isset($duplicateResults)): ?>
<div class="results-container">
<h3>Résultats de Vérification des Doublons</h3>
<?php if (!empty($duplicateResults['data'])): ?>
<div class="duplicates-list">
<?php foreach ($duplicateResults['data'] as $duplicate): ?>
<div class="duplicate-item">
<?php if (isset($duplicate['file1'])): ?>
<p><strong>Doublon de fichier trouvé:</strong></p>
<p>Fichier 1: <?php echo htmlspecialchars($duplicate['file1']); ?></p>
<p>Fichier 2: <?php echo htmlspecialchars($duplicate['file2']); ?></p>
<?php else: ?>
<p><strong>Doublon d'individu trouvé:</strong></p>
<?php
// Enhanced field detection for better display
$nameFields = ['Nom', 'nom', 'Name', 'name', 'NOM', 'Last Name', 'last name'];
$firstNameFields = ['Prénom', 'prenom', 'Prenom', 'PRENOM', 'First Name', 'first name'];
$cinFields = ['CIN', 'cin', 'ID', 'id', 'Id', 'Identifiant', 'identifiant', 'CNE', 'cne', 'Numéro CIN', 'numéro cin', 'Carte Identité'];
$establishmentFields = ['Etablissement', 'etablissement', 'Establishment', 'establishment', 'School', 'school', 'Université', 'université'];
$lastName = 'N/A';
$firstName = 'N/A';
$cin = 'N/A';
$establishment = 'N/A';
// Find last name
foreach ($nameFields as $field) {
if (isset($duplicate['individual'][$field]) &&
$duplicate['individual'][$field] !== 'N/A' &&
!empty(trim($duplicate['individual'][$field]))) {
$lastName = $duplicate['individual'][$field];
break;
}
}
// Find first name
foreach ($firstNameFields as $field) {
if (isset($duplicate['individual'][$field]) &&
$duplicate['individual'][$field] !== 'N/A' &&
!empty(trim($duplicate['individual'][$field]))) {
$firstName = $duplicate['individual'][$field];
break;
}
}
// Find CIN - more comprehensive search
foreach ($cinFields as $field) {
if (isset($duplicate['individual'][$field]) &&
$duplicate['individual'][$field] !== 'N/A' &&
!empty(trim($duplicate['individual'][$field]))) {
$cin = $duplicate['individual'][$field];
break;
}
}
// If CIN still not found, search in all fields for ID-like values
if ($cin === 'N/A') {
foreach ($duplicate['individual'] as $key => $value) {
if ($key !== '_source_file' && $excelManager->looksLikeId($value)) {
$cin = $value;
break;
}
}
}
// Find establishment
foreach ($establishmentFields as $field) {
if (isset($duplicate['individual'][$field]) &&
$duplicate['individual'][$field] !== 'N/A' &&
!empty(trim($duplicate['individual'][$field]))) {
$establishment = $duplicate['individual'][$field];
break;
}
}
?>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px;">
<div><strong>Nom:</strong> <?php echo htmlspecialchars($lastName); ?></div>
<div><strong>Prénom:</strong> <?php echo htmlspecialchars($firstName); ?></div>
<div><strong>CIN:</strong> <?php echo htmlspecialchars($cin); ?></div>
<div><strong>Établissement:</strong> <?php echo htmlspecialchars($establishment); ?></div>
<div><strong>Fichiers:</strong> <?php echo implode(', ', array_unique($duplicate['files'])); ?></div>
</div>
<!-- Show additional fields for debugging -->
<details style="margin-top: 10px;">
<summary style="cursor: pointer; color: #666;">Afficher toutes les données de cet individu</summary>
<div style="margin-top: 10px; padding: 10px; background: #2a2a2a; border-radius: 4px;">
<?php foreach ($duplicate['individual'] as $key => $value): ?>
<?php if ($key !== '_source_file'): ?>
<p><strong><?php echo htmlspecialchars($key); ?>:</strong> <?php echo htmlspecialchars($value); ?></p>
<?php endif; ?>
<?php endforeach; ?>
</div>
</details>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<p class="no-data">Aucun doublon trouvé.</p>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<!-- Establishment Tab -->
<div id="establishment" class="tab-pane <?php echo $activeTab === 'establishment' ? 'active' : ''; ?>">
<h2>Établissements</h2>
<form method="post" id="establishmentForm">
<input type="hidden" name="action" value="establishments">
<div class="filter-section" style="margin-bottom: 15px;">
<label for="filiereFilter">Filtrer par Filière:</label>
<select name="filiere_filter" id="filiereFilter" class="filter-select">
<option value="">Toutes les filières</option>
<?php
// Get all unique filières for the filter
if (isset($establishmentResults)) {
$allFilieres = [];
foreach ($establishmentResults['data'] as $establishment) {
if (!empty($establishment['filières']) && is_array($establishment['filières'])) {
foreach ($establishment['filières'] as $filiere) {
if ($filiere !== 'N/A' && !empty(trim($filiere))) {
$allFilieres[] = $filiere;
}
}
}
}
$uniqueFilieres = array_unique($allFilieres);
sort($uniqueFilieres);
foreach ($uniqueFilieres as $filiere) {
$selected = (isset($_POST['filiere_filter']) && $_POST['filiere_filter'] === $filiere) ? 'selected' : '';
echo "<option value=\"" . htmlspecialchars($filiere) . "\" $selected>" . htmlspecialchars($filiere) . "</option>";
}
}
?>
</select>
</div>
<button type="submit" class="cmd-button">Afficher les Établissements</button>
</form>
<?php if (isset($establishmentResults)): ?>
<div class="establishments-list">
<h3>Liste des Établissements (<?php echo count($establishmentResults['data']); ?>)</h3>
<?php
$filteredEstablishments = $establishmentResults['data'];
// Apply filiere filter if set
if (isset($_POST['filiere_filter']) && !empty($_POST['filiere_filter'])) {
$selectedFiliere = $_POST['filiere_filter'];
$filteredEstablishments = array_filter($establishmentResults['data'], function($establishment) use ($selectedFiliere) {
if (!empty($establishment['filières']) && is_array($establishment['filières'])) {
return in_array($selectedFiliere, $establishment['filières']);
}
return false;
});
echo "<p style='margin-bottom: 15px;'><strong>Filtré par filière:</strong> " . htmlspecialchars($selectedFiliere) . " (" . count($filteredEstablishments) . " établissement(s))</p>";
}
?>
<?php foreach ($filteredEstablishments as $establishment): ?>
<div class="establishment-card">
<h3><?php echo htmlspecialchars($establishment['name']); ?></h3>
<p><strong>Étudiants:</strong> <?php echo $establishment['student_count']; ?></p>
<p><strong>Sigle:</strong> <?php echo htmlspecialchars($establishment['sigle'] ?? 'N/A'); ?></p>
<p><strong>Accrédité:</strong> <?php echo htmlspecialchars($establishment['accredited'] ?? 'N/A'); ?></p>
<p><strong>Filières:</strong>
<?php
if (!empty($establishment['filières']) && is_array($establishment['filières'])) {
$uniqueFilieres = array_unique(array_filter($establishment['filières'], function($filiere) {
return $filiere !== 'N/A' && !empty(trim($filiere));
}));
echo !empty($uniqueFilieres) ? implode(', ', $uniqueFilieres) : 'Aucune filière spécifiée';
} else {
echo 'Aucune filière spécifiée';
}
?>
</p>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<!-- Archive Tab -->
<div id="archive" class="tab-pane <?php echo $activeTab === 'archive' ? 'active' : ''; ?>">
<h2>Gestion des Archives</h2>
<!-- Create Archive -->
<div class="archive-section">
<h3>Créer une Archive</h3>
<form method="post">
<input type="hidden" name="action" value="archive">
<input type="hidden" name="archive_type" value="create">
<button type="submit" class="cmd-button" onclick="return confirm('Créer une archive des fichiers actuels? Les fichiers seront déplacés vers l\\'archive.')">
<span class="archive-icon">📦</span> Créer Archive Actuelle
</button>
</form>
<p class="help-text">Cette action va créer une archive de tous les fichiers Excel actuels et les supprimer du dossier principal.</p>
</div>
<!-- View Archives -->
<div class="archive-section">
<h3>Archives Existantes</h3>
<!-- Year Filter -->
<div class="filter-section" style="margin-bottom: 15px;">
<label for="yearFilter">Filtrer par Année:</label>
<select name="archive_year" id="yearFilter" class="filter-select" onchange="filterArchivesByYear(this.value)">
<option value="">Toutes les années</option>
<?php foreach ($archiveYears as $year): ?>
<option value="<?php echo $year; ?>" <?php echo $selectedYear === $year ? 'selected' : ''; ?>>
<?php echo $year; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<?php if (!empty($filteredArchives)): ?>
<div class="archives-grid">
<?php foreach ($filteredArchives as $archive): ?>
<div class="archive-item" data-archive="<?php echo htmlspecialchars($archive); ?>">
<div class="archive-info">
<span class="archive-icon">📁</span>
<span class="archive-name"><?php echo htmlspecialchars($archive); ?></span>
</div>
<div class="archive-actions">
<button class="cmd-button" onclick="viewArchive('<?php echo htmlspecialchars($archive); ?>')">
<span class="inspect-icon">🔍</span> Inspecter
</button>
<form method="post" class="archive-action-form">
<input type="hidden" name="action" value="delete_archive">
<input type="hidden" name="archive_name" value="<?php echo htmlspecialchars($archive); ?>">
<button type="submit" class="cmd-button danger" onclick="return confirm('Êtes-vous sûr de vouloir supprimer l\\'archive <?php echo htmlspecialchars($archive); ?> ?')">
<span class="delete-icon">🗑️</span> Supprimer
</button>
</form>
</div>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<p class="no-data">Aucune archive trouvée<?php echo !empty($selectedYear) ? " pour l'année $selectedYear" : ''; ?>.</p>
<?php endif; ?>
</div>
</div>
</div>
</div>
<!-- Footer -->
<div class="cmd-footer">
<div class="status-bar">
<span class="status-item">Prêt</span>
<span class="status-item">Fichiers: <?php echo count($excelManager->getExcelFiles()); ?></span>
<span class="status-item"><?php echo date('d/m/Y H:i:s'); ?></span>
</div>
</div>
</div>
<!-- Duplicate File Confirmation Modal -->
<div id="duplicateModal" class="modal" style="display: none;">
<div class="modal-content">
<h3>Fichiers en double détectés</h3>
<div id="duplicateFilesList"></div>
<div class="modal-actions">
<button id="cancelUpload" class="cmd-button danger">Annuler</button>
<button id="skipDuplicates" class="cmd-button">Ignorer les doublons</button>
<button id="overwriteFiles" class="cmd-button warning">Remplacer les fichiers</button>
</div>
</div>
</div>
<!-- Archive Inspection Modal -->
<div id="archiveModal" class="modal" style="display: none;">
<div class="modal-content" style="max-width: 800px; max-height: 80vh;">
<h3 id="archiveModalTitle">Inspection de l'Archive</h3>
<div class="search-section" style="margin-bottom: 15px;">
<input type="text" id="archiveSearchInput" placeholder="Rechercher dans l'archive..." class="search-input" style="width: 100%;">
<button onclick="searchInArchive()" class="cmd-button" style="margin-top: 10px;">Rechercher</button>
</div>
<div id="archiveContent" style="max-height: 400px; overflow-y: auto; margin-bottom: 15px;">
<!-- Archive content will be loaded here -->
</div>
<div class="modal-actions">
<button onclick="closeArchiveModal()" class="cmd-button">Fermer</button>
</div>
</div>
</div>
<script src="js/script.js"></script>
</body>
</html>