add rencontres php page

This commit is contained in:
mose 2019-08-27 10:43:39 +08:00
parent abce640396
commit e8f8a77d27

74
tools/wiki/rencontres.php Normal file
View file

@ -0,0 +1,74 @@
<?php
# copy this at the root of tiki
require 'db/local.php';
setlocale(LC_ALL, "fr_FR.UTF8");
$db = new mysqli('localhost', $user_tiki, $pass_tiki, $dbs_tiki);
if ($db->connect_errno) {
echo mysqli_connect_error();
exit;
}
$db->set_charset("utf8");
function getlist($query) {
global $db;
$result = $db->query($query);
$back = array();
while ($row = $result->fetch_row()) {
$back[$row[0]] = $row[1];
}
return $back;
}
$fields = array(
'3' => "titre",
'5' => "wikipage",
'7' => "lieu"
);
$data = array(
'avenir' => array(),
'passe' => array()
);
$avenir = "select itemId, value from tiki_tracker_item_fields where fieldId=1 and value > unix_timestamp(now()) order by value asc limit 5";
$passe = "select itemId, value from tiki_tracker_item_fields where fieldId=1 and value < unix_timestamp(now()) order by value desc limit 5";
function getevents($list) {
global $fields;
$back = array();
foreach ($list as $id => $date) {
$d = date_create();
date_timestamp_set($d, $date);
$event = array(
'id' => $id,
'date' => strftime("%A %e %B", $date)
);
$query = "select fieldId, value from tiki_tracker_item_fields where itemId=$id and fieldId in (".join(",", array_keys($fields)).")";
foreach (getlist($query) as $key => $value) {
$event[$fields[$key]] = $value;
}
$back[] = $event;
}
return $back;
}
$avenir = getevents(getlist($avenir));
$passe = getevents(getlist($passe));
$data = array(
"avenir" => $avenir,
"passe" => $passe
);
header('Content-Type: application/json');
$json = json_encode( (object) $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
if ($json === false) {
$json = json_encode(array("jsonError", json_last_error_msg()));
}
echo $json;