diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8fce603 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +data/ diff --git a/README.md b/README.md index 87d5715..a1002d7 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,5 @@ DefiVelib ========= A website to compare travel times in Velib at Paris. + +Currently working on… diff --git a/index.php b/index.php new file mode 100644 index 0000000..9556c37 --- /dev/null +++ b/index.php @@ -0,0 +1,137 @@ +(int) $_POST['start'], "end"=>(int) $_POST['end'], "min"=>$min, "sec"=>$sec); + + $last_data = end($data); + + if($min != $last_data['min'] || $sec != $last_data['sec'] || $_POST['start'] != $last_data['start'] || $_POST['end'] != $last_data['end']) { + file_put_contents('data/data', base64_encode(gzdeflate(serialize($data)))); + } + } +?> + + + + + Vélibs à proximité + + + + +
+

DéfiVélib

+ + Définition du code de synchronisation.
+ Vous pouvez désormais mettre à jour la liste des stations en visitant l'adresse suivante (update URL) :
+ http://" . $_SERVER["SERVER_NAME"].$_SERVER['REQUEST_URI']."?update=1&code=".$code_synchro." +

+

+ Il est possible d'automatiser la tâche via une tâche cron. Par exemple (see README) :
+ * * * * * wget -q -O http://" . $_SERVER["SERVER_NAME"].$_SERVER['REQUEST_URI']."?update=1&code=".$code_synchro." #Commande de mise a jour des stations de velib +

"; + } + + if(!empty($_GET['update']) || !empty($code_synchro)) //If we want to make an update (or first run) + { + if(empty($code_synchro) && is_file('data/config')) //If not first run, get the synchronisation code from data file + { + $data = unserialize(gzinflate(base64_decode(file_get_contents('data/config')))); + $code_synchro = $data[0]; + } + + if(!empty($_GET['code']) && $_GET['code'] == $code_synchro) //Once we have the code and it is correct + { + $stations_xml = simplexml_load_file('http://www.velib.paris.fr/service/carto'); + + $liste_stations = array(); + foreach($stations_xml->markers->marker as $station) { + $liste_stations[(int) $station['number']] = array('name'=>(string) $station['name'], 'address'=>(string) $station['fullAddress'], 'lat'=>(float) $station['lat'], 'lng'=>(float) $station['lng']); + } + + file_put_contents('data/stations', base64_encode(gzdeflate(serialize($liste_stations)))); + + echo "

Mise à jour de la liste des stations effectuée avec succès (Update successful).

"; + } + else + { + echo "

Mauvais code de vérification (Error : bad synchronisation code). Veuillez réessayer la mise à jour. Se référer au README pour plus d'informations sur la mise à jour.

"; + } + echo "

Retourner à l'application (Back to index)

"; + exit(); + } + $liste_stations = unserialize(gzinflate(base64_decode(file_get_contents('data/stations')))); + ?> +

Ajouter un trajet

+
+

+ +

+

+ +

+

min s

+

+
+

Derniers trajets ajoutés

+ + + + + + + + "; + } + ?> +
DépartArrivéeTemps
".htmlspecialchars($liste_stations[$trajet['start']]['name'])."".htmlspecialchars($liste_stations[$trajet['end']]['name'])."".(int) $trajet['min']."min ".(int) $trajet['sec']."s
+ +

Aucun trajet enregistré.

+ +
+ + diff --git a/main.css b/main.css new file mode 100644 index 0000000..85c950b --- /dev/null +++ b/main.css @@ -0,0 +1,30 @@ +html, body { + margin: 0; + padding: 0; + width: 100%; + height: 100%; +} + +#main { + width: 50%; + min-height: 50%; + margin: auto; + text-align: center; + background-color: lightgrey; + padding: 1em; + -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; +} + +#main h1 { + margin: 0; +} + +table td, th { + padding: 0.5em; + border: 1px solid black; +} + +table { + border-collapse: collapse; + margin: auto; +}