hanze/iwa-panda2

index.php in map-leaflet
Repositories | Summary | Log | Files | README.md

index.php (2483B) download


 1<?php
 2
 3require_once "utils/autoloader.php";
 4
 5require_once "routing/login.php";
 6require_once "routing/user_add.php";
 7
 8session_start();
 9
10$templater = new Lollipop\Template(new Lollipop\TemplateMethods());
11$router = new Lollipop\Router($templater);
12
13//login
14$router->addRoute(["GET"], "/", "views/login.html");
15$router->addRoute(["POST"], "/login", $login);
16
17//logout
18$router->addRoute(["POST", "GET"], "/logout", $logout);
19
20if(isset($_SESSION['user_permissions']) && in_array(1, $_SESSION['user_permissions'])) {
21    //user
22    //add
23    $router->addRoute(["GET"], "/user/add", "views/add_user.html");
24    $router->addRoute(["POST"], "/user/add", $add_user);
25
26    //dashboard
27    $router->addRoute(["GET"], "/dashboard", function (&$vars) {
28        $vars += $_SESSION;
29        return "views/dashboard.html";
30    });
31
32    $router->addRoute(["GET"], "/map", "views/map.html");
33    $router->addRoute(["GET"], "/hdata", function (&$vars) {
34        $key = new Key();
35        if (isset($_GET['downloadXml'])) {
36            $filename = 'weather_data.xml'; // Specify the filename for the downloaded XML file
37
38            // Set the appropriate headers for file download
39            header('Content-Type: application/xml');
40            header('Content-Disposition: attachment; filename="' . $filename . '"');
41
42            // Retrieve the XML data
43            $humidityXml = $key->retrieveHumidityTable('ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684', true);
44            $hDataXml = $key->retrieveHData('ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684', true);
45
46            // Output the XML data directly to the browser
47            echo '<weather>' . $humidityXml . $hDataXml . '</weather>';
48            exit();
49        } else {
50            $vars["table"] = $key->retrieveHData('3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk');
51        }
52
53        return "views/hdata.html";
54    });
55}
56
57// static files //
58
59$router->addRoute(['GET'], '/css/dashboard.css', "css/dashboard.css");
60$router->addRoute(['GET'], '/css/login.css', "css/login.css");
61$router->addRoute(['GET'], '/css/hdata.css', "css/hdata.css");
62$router->addRoute(['GET'], '/css/map.css', "css/map.css");
63
64$router->addRoute(['GET'], '/img/big-logo.png', "img/big-logo.png");
65$router->addRoute(['GET'], '/img/small_logo.png', "img/small_logo.png");
66
67$router->addRoute(['GET'], '/js/panda.js', "js/panda.js");
68$router->addRoute(['GET'], '/js/map.js', "js/map.js");
69
70$router->route();