-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_csv.php
92 lines (85 loc) · 4.35 KB
/
export_csv.php
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
<?php
// connexion à la base de données. Renseignez vos propres identifiants
include('fonction.php');
if(isset($_GET['key']) && test_id($_GET['key'])){
if(!isset($_GET['semaine']))$s = date('W', time());
else if(isset($_GET['semaine'][7]))$s = $_GET['semaine'][6].$_GET['semaine'][7];
else $s = $_GET['semaine'];
include('log_bdd.php');
$r = $pdo->query('SELECT rdv.date, rdv.durre, elleve.nom as e_nom, elleve.prenom as e_prenom, elleve.classe as e_classe, proph.nom as p_nom, proph.prenom as p_prenom, rdv.lieu, rdv.nom, rdv.couleur, rdv.abs FROM rdv, elleve, proph WHERE rdv.id_elleve = elleve.id and rdv.id_proph = proph.id ORDER BY rdv.date');
$tabeleves = [];
$tabeleves[] = ['DATE', 'DURRE', 'NOM ELEVES', 'PRENOM ELEVES', 'CLASSE ELEVES', 'NOM PROFS', 'PRENOM PROFS', 'LIEU', 'OBSERVATION', 'COULEUR', 'ABS'];
$tablarge = [];
$tablarge[] = ['DATE', 'DURRE', 'NOM ELEVES', 'PRENOM ELEVES', 'CLASSE ELEVES', 'NOM PROFS', 'PRENOM PROFS', 'LIEU', 'OBSERVATION', 'COULEUR', 'ABS'];
while($rs = $r->fetch(PDO::FETCH_ASSOC)){
if(date('W', strtotime($rs['date']))==$s){
if($rs['abs'] == -1) $abs = "Absent";
elseif($rs['abs'] == 2) $abs = "Anuller";
elseif($rs['abs'] == 4) $abs = "Formateur ABS";
elseif($rs['abs'] == 1) $abs = "Present";
else $abs = "NR";
$tabeleves[] = [$rs['date'], $rs['durre'],$rs['e_nom'],$rs['e_prenom'],$rs['e_classe'],$rs['p_nom'],$rs['p_prenom'],$rs['lieu'],$rs['nom'],$rs['couleur'], $abs];
}
if(isset($_POST['date_d']) && isset($_POST['date_f']) && date($rs['date']) >= date($_POST['date_d']) && date($rs['date']) <= date($_POST['date_f'])){
//print_r($rs);
if($rs['abs'] == -1) $abs = "Absent";
elseif($rs['abs'] == 2) $abs = "Anuller";
elseif($rs['abs'] == 4) $abs = "Formateur ABS";
elseif($rs['abs'] == 1) $abs = "Present";
else $abs = "NR";
$tablarge []= [$rs['date'], $rs['durre'],$rs['e_nom'],$rs['e_prenom'],$rs['e_classe'],$rs['p_nom'],$rs['p_prenom'],$rs['lieu'],$rs['nom'],$rs['couleur'], $abs];
}
}
$name = "export/export_S".$s.".csv";
$fichier_csv = fopen($name, "w+");
fprintf($fichier_csv, chr(0xEF).chr(0xBB).chr(0xBF));
foreach($tabeleves as $ligne){
fputcsv($fichier_csv, $ligne, ";");
}
fclose($fichier_csv);
$h = 'Location:'.$name;
if(isset($_POST['date_d']) && isset($_POST['date_f'])){
$namefull = "export/export_full".$s.".csv";
$fichier_csv_full = fopen($namefull, "w+");
fprintf($fichier_csv_full, chr(0xEF).chr(0xBB).chr(0xBF));
foreach($tablarge as $ligne1){
fputcsv($fichier_csv_full, $ligne1, ";");
}
fclose($fichier_csv_full);
}
?>
<html>
<head>
<link rel="stylesheet" href="all.css" />
<style>
h3{
text-align: center;
margin-top:9vh;
}
button{
display:block;
margin-left: auto;
margin-right: auto;
}
button.back{
width: 15% !important;
}
</style>
</head>
<body>
<?php echo('<a href="'.$name.'"><h3>Télecharger le Fichier Semaine</h3></a>'); ?>
<?php if(isset($_POST['date_d']) && isset($_POST['date_f'])){echo('<a href="'.$namefull.'"><h3>Télecharger le Fichier complet</h3></a>');} ?>
<h3>
<form action="" method="post">
<input type="date" name="date_d" value="<?php if(isset($_POST['date_d'])) echo $_POST['date_d']; ?>" />
<input type="date" name="date_f" value="<?php if(isset($_POST['date_f'])) echo $_POST['date_f']; ?>" />
<button type="submit">Generer Fichier</button>
</form>
</h3>
</br>
<form action="index.php?key=<?php echo($_GET['key']); ?>&semaine=<?php echo($s); ?>" method="POST">
<button class="back">RETOUR ACCUEIL</button>
</form>
</body>
</html>
<?php } ?>