3 if (!isset($_POST["players"]))
5 if (isset($_GET["restore"]) && $_GET["restore"])
8 if (!rename("../joueurs.csv.bak", "../joueurs.csv"))
11 // Retrieve all players
12 $handle = fopen("../joueurs.csv", "r");
15 $data = fgetcsv($handle); //skip header
16 while (($data = fgetcsv($handle)) !== FALSE)
18 $players[$row] = array(
21 "pdt" => count($data)>=3 ? $data[2] : 0,
22 "session" => count($data)>=4 ? $data[3] : 0,
23 "available" => count($data)>=5 ? $data[4] : 1,
28 echo json_encode($players);
32 copy("../joueurs.csv", "../joueurs.csv.bak"); //backup current checkpoint
33 // Write header + all players
34 $handle = fopen("../joueurs.csv", "w");
35 fputcsv($handle, ["prenom","nom","pdt","session","present"]);
36 $players = json_decode($_POST["players"]);
37 foreach ($players as $p)
38 fputcsv($handle, (array)$p);