From fbabdc19eecb52d4efe25a65808a6bfb72a9be69 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Sun, 18 Dec 2016 16:21:29 -0800 Subject: Backend: Added new servertype Frontend. Sends the url/serverroomid.json to the frontend. --- modules-available/locationinfo/api.inc.php | 51 +++++++--------------- modules-available/locationinfo/page.inc.php | 28 +++++++++++- .../locationinfo/templates/config.html | 2 +- .../locationinfo/templates/location-info.html | 23 ++++++++-- 4 files changed, 61 insertions(+), 43 deletions(-) (limited to 'modules-available/locationinfo') diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php index 106f6498..7c90c0f5 100644 --- a/modules-available/locationinfo/api.inc.php +++ b/modules-available/locationinfo/api.inc.php @@ -91,20 +91,27 @@ function updateCalendar($locationid, $serverid, $serverroomid) { } function getConfig($locationID) { - $dbquery = Database::simpleQuery("SELECT l.locationname, li.config FROM `location_info` AS li - RIGHT JOIN `location` AS l ON l.locationid=li.locationid WHERE l.locationid=:locationID", array('locationID' => $locationID)); + $dbquery = Database::simpleQuery("SELECT l.locationname, li.config, li.serverroomid, s.servertype, s.serverurl FROM `location_info` AS li + RIGHT JOIN `location` AS l ON l.locationid=li.locationid + LEFT JOIN `setting_location_info` AS s ON s.serverid=li.serverid + WHERE l.locationid=:locationID", array('locationID' => $locationID)); $config = array(); - while($dbresult=$dbquery->fetch(PDO::FETCH_ASSOC)) { - $config = json_decode($dbresult['config'], true); - $config['room'] = $dbresult['locationname']; - $date = getdate(); - $config['time'] = $date['year'] . "-" . $date['mon'] . "-" . $date['mday'] . " " . $date['hours'] . ":" . $date['minutes'] . ":" . $date['seconds']; + $dbresult=$dbquery->fetch(PDO::FETCH_ASSOC); + + $config = json_decode($dbresult['config'], true); + $config['room'] = $dbresult['locationname']; + $date = getdate(); + $config['time'] = $date['year'] . "-" . $date['mon'] . "-" . $date['mday'] . " " . $date['hours'] . ":" . $date['minutes'] . ":" . $date['seconds']; + + if($dbresult['servertype'] === "Frontend") { + $config['calendarqueryurl'] = $dbresult['serverurl'] . "/" . $dbresult['serverroomid'] . ".json"; } + if (empty($config)) { echo json_encode(array()); } else { - echo json_encode($config); + echo json_encode($config, JSON_UNESCAPED_SLASHES); } } @@ -230,31 +237,3 @@ function getPcInfos($locationID, $coords) { return $str; } -function fetchNewTimeTable($locationID){ - //Get room information - $dbquery1 = Database::simpleQuery("SELECT serverid, serverroomid FROM location_info WHERE locationid = :id", array('id' => $locationID)); - $dbd1=$dbquery1->fetch(PDO::FETCH_ASSOC); - $serverID = $dbd1['serverid']; - $roomID = $dbd1['serverroomid']; - //Get login data for the server - $dbquery2 = Database::simpleQuery("SELECT serverurl, servertype, login, passwd FROM `setting_location_info` WHERE serverid = :id", array('id' => $serverID)); - $dbd2=$dbquery2->fetch(PDO::FETCH_ASSOC); - $url = $dbd2['serverurl']; - $type = $dbd2['servetype']; - $lname = $dbd2['login']; - $passwd = $dbd2['passwd']; - //Return json with dates - if($type == 'HISinOne'){ - $array = file_get_contents($url . $roomID . '.json'); - $ttable = json_decode($array); - $results = count($ttable); - for ($r = 0; $r < $results; $r++){ - unset($ttable[$r]->allDay); - } - - } - else{ - $ttable = "{}"; - } - return json_encode($ttable); - } diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php index f855c5c5..e9ce1159 100644 --- a/modules-available/locationinfo/page.inc.php +++ b/modules-available/locationinfo/page.inc.php @@ -312,11 +312,34 @@ class Page_LocationInfo extends Page } } + $servertypes = array(); + $type['type'] = "HISinOne"; + $servertypes[] = $type; + $type['type'] = "DAVINCI"; + $servertypes[] = $type; + $type['type'] = "Frontend"; + $servertypes[] = $type; + $serverlist = array(); $dbquery2 = Database::simpleQuery("SELECT * FROM `setting_location_info`"); while($db=$dbquery2->fetch(PDO::FETCH_ASSOC)) { $server['id'] = $db['serverid']; $server['name'] = $db['servername']; + + $serverty = array(); + foreach ($servertypes as $type) { + $st = array(); + if ($type['type'] == $db['servertype']) { + $st['type'] = $type['type']; + $st['active'] = true; + } else { + $st['type'] = $type['type']; + $st['active'] = false; + } + $serverty[] = $st; + } + $server['types'] = $serverty; +/* if ($db['servertype'] == 'HISinOne') { $server['HISinOne'] = true; $server['DAVINCI'] = false; @@ -324,6 +347,7 @@ class Page_LocationInfo extends Page $server['HISinOne'] = false; $server['DAVINCI'] = true; } +*/ $server['url'] = $db['serverurl']; $server['user'] = $db['login']; $server['password'] = $db['passwd']; @@ -331,7 +355,7 @@ class Page_LocationInfo extends Page } Render::addTemplate('location-info', array( - 'list' => array_values($pcs), 'serverlist' => array_values($serverlist), + 'list' => array_values($pcs), 'serverlist' => array_values($serverlist), 'servertypelist' => array_values($servertypes), )); } @@ -460,5 +484,5 @@ class Page_LocationInfo extends Page 'roomupdate' => $array['roomupdate'], 'configupdate' => $array['configupdate'], 'serverlist' => array_values($serverList), 'serverid' => $serverid, 'serverroomid' => $serverroomid)); } - + } diff --git a/modules-available/locationinfo/templates/config.html b/modules-available/locationinfo/templates/config.html index 577f8f94..1cbcbe31 100644 --- a/modules-available/locationinfo/templates/config.html +++ b/modules-available/locationinfo/templates/config.html @@ -34,7 +34,7 @@

- diff --git a/modules-available/locationinfo/templates/location-info.html b/modules-available/locationinfo/templates/location-info.html index 534f7acb..98786934 100644 --- a/modules-available/locationinfo/templates/location-info.html +++ b/modules-available/locationinfo/templates/location-info.html @@ -24,9 +24,10 @@ {{id}} - + {{#types}} +