-
Notifications
You must be signed in to change notification settings - Fork 0
/
points.php
71 lines (54 loc) · 1.62 KB
/
points.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?PHP
$message=null;
$pdo = new PDO('sqlite:'.getcwd().'/db/wims.sqlite');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$filters=array('collectionid'=>FILTER_SANITIZE_NUMBER_INT,'mapid'=>FILTER_SANITIZE_NUMBER_INT,'id'=>FILTER_SANITIZE_NUMBER_INT);
$input_type=($_SERVER['REQUEST_METHOD']=='POST') ? INPUT_POST : INPUT_GET;
$inputs=filter_input_array($input_type,$filters);
$conditions=array();
foreach(array_keys($filters) as $key)
{
if(isset($inputs[$key]))
{
array_push($conditions,'"'.$key.'" = "'.$inputs[$key].'"');
}
}
if(count($conditions)<1)
{
header("Location: collections.php");
exit;
}
$sql="SELECT * FROM point WHERE ".join(' and ',$conditions);
$points = $pdo->query($sql)->fetchAll();
$mapids=array("0"); // mapid can be null
foreach($points as $point)
{
if(isset($point['mapid'])){array_push($mapids,'id="'.$point['mapid'].'"');}
}
$sql="SELECT * FROM map WHERE ".join(' or ',$mapids);
$maps = $pdo->query($sql)->fetchAll();
$collectionids=array("0"); // collectionid can be null
foreach($points as $point)
{
if(isset($point['collectionid'])){array_push($collectionids,'id="'.$point['collectionid'].'"');}
}
$sql="SELECT * FROM collection WHERE ".join(' or ',$collectionids);
$collections = $pdo->query($sql)->fetchAll();
include 'vendor/autoload.php';
try
{
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader);
$template = $twig->loadTemplate('points.html');
echo $template->render(array (
'message' => $message,
'points' => $points,
'maps' => $maps,
'collections' => $collections,
));
}
catch (Exception $e)
{
die ('ERROR: ' . $e->getMessage());
}
?>