|
@@ -0,0 +1,152 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+//documentation ici => https://github.com/baptistereb/php2ics
|
|
4
|
+
|
|
5
|
+class php2ics
|
|
6
|
+{
|
|
7
|
+ private static $ics;
|
|
8
|
+
|
|
9
|
+ public function __construct(string $organisation, string $product)
|
|
10
|
+ {
|
|
11
|
+ $organisation = htmlspecialchars($organisation);
|
|
12
|
+ $product = htmlspecialchars($product);
|
|
13
|
+
|
|
14
|
+ $this->Init($organisation,$product);
|
|
15
|
+ }
|
|
16
|
+
|
|
17
|
+ //fonction d'initialisation de l'ICS
|
|
18
|
+ private function Init(string $organisation, ?string $product): void
|
|
19
|
+ {
|
|
20
|
+ $organisation = htmlspecialchars($organisation);
|
|
21
|
+ if(isset($product)) {
|
|
22
|
+ $product = htmlspecialchars($product);
|
|
23
|
+ } else {
|
|
24
|
+ $product = "none";
|
|
25
|
+ }
|
|
26
|
+
|
|
27
|
+ $this::$ics .= "BEGIN:VCALENDAR\n";
|
|
28
|
+ $this::$ics .= "VERSION:2.0\n";
|
|
29
|
+ $this::$ics .= "PRODID:-//".$organisation."//NONSGML ".$product."\n";
|
|
30
|
+ $this::$ics .= "CALSCALE:GREGORIAN\n";
|
|
31
|
+ $this::$ics .= "METHOD:PUBLISH\n";
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ //fonction de création d'évenement
|
|
35
|
+ public function AddEvent(
|
|
36
|
+ string $title,
|
|
37
|
+ ?string $description,
|
|
38
|
+ int $begin_date,
|
|
39
|
+ int $end_date,
|
|
40
|
+ ?string $location,
|
|
41
|
+ ?string $url
|
|
42
|
+ ): void
|
|
43
|
+ {
|
|
44
|
+ $title = htmlspecialchars($title);
|
|
45
|
+ $begin_date = htmlspecialchars($begin_date);
|
|
46
|
+ $end_date = htmlspecialchars($end_date);
|
|
47
|
+
|
|
48
|
+ $this::$ics .= "BEGIN:VEVENT\n";
|
|
49
|
+ $this::$ics .= "SUMMARY:".$title."\n";
|
|
50
|
+ $this::$ics .= "DTSTART:".date('Ymd',$begin_date)."T".date('His',$begin_date)."\n";
|
|
51
|
+ $this::$ics .= "DTEND:".date('Ymd',$end_date)."T".date('His',$end_date)."\n";
|
|
52
|
+ if(isset($location)) {
|
|
53
|
+ $location = htmlspecialchars($location);
|
|
54
|
+ $this::$ics .= "LOCATION:".$location."\n";
|
|
55
|
+ }
|
|
56
|
+ if(isset($description)) {
|
|
57
|
+ $description = htmlspecialchars($description);
|
|
58
|
+ $this::$ics .= "DESCRIPTION:".$description."\n";
|
|
59
|
+ }
|
|
60
|
+ if(isset($url)) {
|
|
61
|
+ $url = htmlspecialchars($url);
|
|
62
|
+ $this::$ics .= "URL:".$url."\n";
|
|
63
|
+ }
|
|
64
|
+ $this::$ics .= "END:VEVENT\n";
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+ //fonction de fin d'ICS
|
|
68
|
+ public function End(): void
|
|
69
|
+ {
|
|
70
|
+ $this::$ics .= "END:VCALENDAR";
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+ //fonction qui permet de récupérer le code ICS
|
|
74
|
+ public function GetICS(): string
|
|
75
|
+ {
|
|
76
|
+ $getICS = $this::$ics;
|
|
77
|
+ return $getICS;
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ //fonction qui permet de télécharger le fichier ICS
|
|
81
|
+ public function DownloadICS(?string $fichier): void
|
|
82
|
+ {
|
|
83
|
+ if(!isset($fichier)) {
|
|
84
|
+ $fichier = 'calend.ics';
|
|
85
|
+ } else {
|
|
86
|
+ $fichier = htmlspecialchars($fichier);
|
|
87
|
+ }
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+ $fichier .= ".ics";
|
|
91
|
+
|
|
92
|
+ $dwn = str_replace("<br>","\n", $this::$ics);
|
|
93
|
+ $f = fopen($fichier, 'w+');
|
|
94
|
+ fputs($f, $this::$ics);
|
|
95
|
+ header('Location:'.$fichier);
|
|
96
|
+ exit;
|
|
97
|
+ }
|
|
98
|
+}
|
|
99
|
+
|
|
100
|
+if(isset($_POST['download_planning'])) {
|
|
101
|
+ $cal = new php2ics("accueil_insa", "voila les loustiks");
|
|
102
|
+
|
|
103
|
+ for($day = 1; $day <= 7; $day++) { //on tourne sur les 7 jours
|
|
104
|
+ $hours_beginning = (int) 7; //commence à 7h tout les matin
|
|
105
|
+ $day_beginning = (int) 5; //commence le 5 septembre (premier jour = 5 septembre)
|
|
106
|
+
|
|
107
|
+ $hours = $hours_beginning;
|
|
108
|
+ $minute = 0;
|
|
109
|
+
|
|
110
|
+ $reqcal = $db->prepare('SELECT id,title, description, length FROM planning_insa WHERE day = ? AND num_planning = ? ORDER BY order_start ASC');
|
|
111
|
+ $reqcal->execute(array($day, $planning));
|
|
112
|
+ while($c = $reqcal->fetch()) {
|
|
113
|
+ //le planning commence à $hours_beginning le $day_beginning et sous forme : date('Y-m-d H:i:s')
|
|
114
|
+ if($c['title'] == " ") { //si le titre est vide c'est qu'il n'y a rien
|
|
115
|
+ $time = (float) $c['length']/4.1;
|
|
116
|
+ $hours += floor($time);
|
|
117
|
+ $minute += 60*($time-floor($time));
|
|
118
|
+ } else {
|
|
119
|
+ $begin_hours = $hours;
|
|
120
|
+ $begin_min = $minute;
|
|
121
|
+ $time = (float) $c['length']/4.1;
|
|
122
|
+ $hours += floor($time);
|
|
123
|
+ $minute += round(60*($time-floor($time)),3);
|
|
124
|
+ while($minute >= 60) {
|
|
125
|
+ $minute -= 60;
|
|
126
|
+ $hours++;
|
|
127
|
+ }
|
|
128
|
+ while($hours >= 24) {
|
|
129
|
+ $hours --; //bon la on tronque entre les jours sinon c'est hyper relou à coder pour rien
|
|
130
|
+ }
|
|
131
|
+
|
|
132
|
+ //pour tester décommenter la ligne juste en dessous
|
|
133
|
+ //echo $c['title'].": ".$begin_hours.'h'.$begin_min.'m to :'.$hours.'h'.$minute.'m<br>';
|
|
134
|
+
|
|
135
|
+ //mktime => hours, minute, second, month, day, year
|
|
136
|
+ $btime = mktime($begin_hours, $begin_min, 0, 9, $day_beginning+$day-1, 2022);
|
|
137
|
+ $etime = mktime($hours, $minute, 0, 9, $day_beginning+$day-1, 2022);
|
|
138
|
+ $cal->AddEvent($c['title'], $c['description'], $btime, $etime, "INSA Toulouse", "https://etud.insa-toulouse.fr/~accueil_insa/planning.php");
|
|
139
|
+
|
|
140
|
+ }
|
|
141
|
+ }
|
|
142
|
+ }
|
|
143
|
+
|
|
144
|
+ $cal->End();
|
|
145
|
+
|
|
146
|
+ $req = $db->prepare('UPDATE planning_tmp_dl set planning = ?');
|
|
147
|
+ $req->execute(array($cal->GetICS()));
|
|
148
|
+
|
|
149
|
+ header('Location: assets/script/planning_tmp.php');
|
|
150
|
+}
|
|
151
|
+
|
|
152
|
+?>
|