Commit | Line | Data |
---|---|---|
7a00c409 BA |
1 | <?php |
2 | ||
3 | if (!isset($_POST["players"])) | |
4 | { | |
5 | // Retrieve all players | |
6 | $handle = fopen("../joueurs.csv", "r"); | |
7 | $players = []; | |
8 | $row = 0; | |
9 | $data = fgetcsv($handle); //skip header | |
10 | while (($data = fgetcsv($handle)) !== FALSE) | |
11 | { | |
12 | $players[$row] = array( | |
13 | "prenom" => $data[0], | |
14 | "nom" => $data[1], | |
ade10194 BA |
15 | "pdt" => count($data)>=3 ? $data[2] : 0, |
16 | "session" => count($data)>=4 ? $data[3] : 0, | |
7a00c409 BA |
17 | "available" => count($data)>=5 ? $data[4] : 1, |
18 | ); | |
19 | $row++; | |
20 | } | |
21 | fclose($handle); | |
22 | echo json_encode($players); | |
23 | } | |
24 | else | |
25 | { | |
26 | // Write header + all players | |
27 | $handle = fopen("../joueurs.csv", "w"); | |
ade10194 | 28 | fputcsv($handle, ["prenom","nom","pdt","session","present"]); |
7a00c409 BA |
29 | $players = json_decode($_POST["players"]); |
30 | foreach ($players as $p) | |
31 | fputcsv($handle, (array)$p); | |
32 | fclose($handle); | |
33 | } | |
34 | ||
35 | ?> |