velov/index.php

85 lines
2.7 KiB
PHP
Raw Normal View History

2018-03-26 14:09:04 +00:00
<?php
2018-03-27 07:05:47 +00:00
/*
* Page displays in french because it will be mostly used by french. Feel free to add language system.
* TODO Cache the humongous API data
2018-03-27 07:36:12 +00:00
* TODO Sort the stations
2018-03-27 07:05:47 +00:00
*/
2018-03-27 07:36:12 +00:00
/* Form submit values if a filter is active or not */
2018-03-27 07:25:36 +00:00
$SEND_BUTTON = [
true => [ 'value' => '', 'text' => 'Tout afficher'],
false => [ 'value' => 'true', 'text' => 'Afficher la sélection'],
];
2018-03-27 07:05:47 +00:00
/* Fetching velov API in an associative array. This form is easier to use as keys are ids */
2018-03-26 14:09:04 +00:00
$data =
2018-03-27 07:05:47 +00:00
json_decode(
2018-06-12 15:32:43 +00:00
file_get_contents('https://api.jcdecaux.com/vls/v1/stations?apiKey=frifk0jbxfefqqniqez09tw4jvk37wyf823b5j1i&contract=lyon',
false
2018-03-27 07:05:47 +00:00
),
true
);
2018-06-12 15:32:43 +00:00
2018-03-27 07:05:47 +00:00
/* Check if a filter is enabled */
2018-03-27 06:46:52 +00:00
if(isset($_GET['filter'])){
if(htmlentities($_GET['filter']))
$filter = true;
else
2018-03-27 07:36:12 +00:00
$filter = false;
2018-03-27 06:46:52 +00:00
}else
$filter = false;
2018-03-26 14:09:04 +00:00
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
2018-03-27 07:25:36 +00:00
<link rel="stylesheet" type="text/css" href="style.css">
2018-03-26 14:09:04 +00:00
<title>Because velov map is too heavy</title>
</head>
<body>
2018-03-27 06:46:52 +00:00
<form action="" method="get">
2018-03-27 07:25:36 +00:00
<input type="hidden" name="filter" value="<?php echo $SEND_BUTTON[$filter]['value']; ?>" />
<input type="submit" value="<?php echo $SEND_BUTTON[$filter]['text']; ?>" />
2018-03-27 06:46:52 +00:00
<table>
2018-03-27 07:25:36 +00:00
<tr><th>Sélectionner</th><th>Nom</th><th>Vélos</th><th>Places Libres</th></tr>
2018-03-27 06:46:52 +00:00
<?php
2018-03-27 06:51:11 +00:00
foreach ($data as $key => $station){
2018-06-12 15:32:43 +00:00
if ( ! $filter || isset($_GET[$station['number']])){
2018-03-27 07:25:36 +00:00
echo '<tr>
<td>
2018-06-12 15:32:43 +00:00
<input type="checkbox" name="',$station['number'],'" ',(isset($_GET[$station['number']]) ? 'checked="checked"' : ''),' />
2018-03-27 07:25:36 +00:00
</td>
2018-06-12 15:32:43 +00:00
<td class="', ($station['status'] == 'OPEN' ? 'success' : 'danger' ) ,'" >'
2018-03-27 06:46:52 +00:00
,$station['name'],
'</td>
2018-06-12 15:32:43 +00:00
<td>',$station['available_bikes'], '</td>
<td>', $station['available_bike_stands'], '</td>
2018-03-27 06:46:52 +00:00
</tr>';
}
2018-03-27 06:51:11 +00:00
}
2018-03-27 06:46:52 +00:00
?>
</table>
2018-03-27 07:25:36 +00:00
<input type="submit" value="<?php echo $SEND_BUTTON[$filter]['text']; ?>" />
2018-03-27 06:46:52 +00:00
</form>
2018-03-27 07:05:47 +00:00
<p>
<h4>À quoi ça sert ?</h4>
À garder ses stations habituelles (et leurs voisines) dans un favoris de navigateur ! Plus besoin de se ballader sur une carte tous les jours ! Cet outil est également accessible sur tous les téléphones peu performants, contrairement au site officiel.
</p>
<p>
<h4>Pourquoi cette page est elle lente ?</h4>
2018-03-28 06:44:44 +00:00
Parce quil faut télécharger toutes les données relatives aux stations vélov à chaque chargement ! Nhésitez pas à améliorer cette page sur <a href="http://github.com/adrian-amaglio/velov">Github</a>
2018-03-27 07:05:47 +00:00
</p>
2018-03-27 07:25:36 +00:00
<p>
<h4>Pourquoi ces couleurs ?</h4>
Le <span class="success">vert</span> est réservé aux stations actives, le <span class="danger">rouge</span> est pour celles inutilisables.
</p>
2018-03-27 07:36:12 +00:00
<p>
<h4>Cest tout dans le désordre !</h4>
Oui.
</p>
2018-03-26 14:09:04 +00:00
</body>
</html>