From a86d0225dc7768a629ce59c325a1dcc739122ef9 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Mon, 5 Dec 2016 09:56:44 -0800 Subject: Locationinfo: Added Servertable --- modules-available/locationinfo/api.inc.php | 6 +- .../locationinfo/inc/locationinfo.inc.php | 28 +++ modules-available/locationinfo/install.inc.php | 21 ++- .../locationinfo/lang/de/template-tags.json | 16 +- .../locationinfo/lang/en/template-tags.json | 16 +- modules-available/locationinfo/page.inc.php | 108 +++++++++--- .../locationinfo/templates/config.html | 22 +++ .../locationinfo/templates/location-info.html | 187 ++++++++++++++++++++- .../locationinfo/templates/pcsubtable.html | 4 +- 9 files changed, 367 insertions(+), 41 deletions(-) create mode 100644 modules-available/locationinfo/inc/locationinfo.inc.php (limited to 'modules-available') diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php index f4f5c9c2..2642ec78 100644 --- a/modules-available/locationinfo/api.inc.php +++ b/modules-available/locationinfo/api.inc.php @@ -189,11 +189,7 @@ function getPcInfos($locationID, $coords) { $computer['y'] = $position['gridRow']; } - $computer['inUse'] = 0; - - if ($pc['logintime'] > 0) { - $computer['inUse'] = 1; - } + $computer['pcState'] = LocationInfo::getPcState((int)$computer['logintime'], (int)$computer['lastseen']); $pcs[] = $computer; } diff --git a/modules-available/locationinfo/inc/locationinfo.inc.php b/modules-available/locationinfo/inc/locationinfo.inc.php new file mode 100644 index 00000000..4f26519d --- /dev/null +++ b/modules-available/locationinfo/inc/locationinfo.inc.php @@ -0,0 +1,28 @@ + 864000) { + return 3; + } elseif ($NOW - $lastseen > 610) { + return 2; + } elseif ($logintime == 0) { + return 0; + } elseif ($logintime > 0) { + return 1; + } + return -1; + } +} diff --git a/modules-available/locationinfo/install.inc.php b/modules-available/locationinfo/install.inc.php index f94c725e..162f000c 100644 --- a/modules-available/locationinfo/install.inc.php +++ b/modules-available/locationinfo/install.inc.php @@ -3,7 +3,9 @@ $res = array(); $res[] = tableCreate('location_info', ' - `locationid` INT(11) NOT NULL, + `locationid` INT(11) NOT NULL, + `serverid` INT(11) NOT NULL, + `serverroomid` INT(11) NOT NULL, `hidden` BOOLEAN NOT NULL DEFAULT 0, `openingtime` VARCHAR(2000) NOT NULL, `config` VARCHAR(2000) NOT NULL, @@ -13,6 +15,7 @@ $res[] = tableCreate('location_info', ' $res[] = tableCreate('setting_location_info', ' `serverid` int(10) NOT NULL AUTO_INCREMENT, + `servername` VARCHAR(2000) NOT NULL, `serverurl` VARCHAR(2000) NOT NULL, `servertype` VARCHAR(100) NOT NULL, `login` VARCHAR(100) NOT NULL, @@ -46,6 +49,22 @@ if (!tableHasColumn('location_info', 'calendar')) { $res[] = UPDATE_DONE; } +if (!tableHasColumn('location_info', 'serverid')) { + $ret = Database::exec("ALTER TABLE `location_info` ADD `serverid` INT(11) NOT NULL AFTER `locationid`"); + if ($ret === false) { + finalResponse(UPDATE_FAILED, 'Adding serverid to location_info failed: ' . Database::lastError()); + } + $res[] = UPDATE_DONE; +} + +if (!tableHasColumn('location_info', 'serverroomid')) { + $ret = Database::exec("ALTER TABLE `location_info` ADD `serverroomid` INT(11) NOT NULL AFTER `serverid`"); + if ($ret === false) { + finalResponse(UPDATE_FAILED, 'Adding serverroomid to location_info failed: ' . Database::lastError()); + } + $res[] = UPDATE_DONE; +} + if (in_array(UPDATE_DONE, $res)) { finalResponse(UPDATE_DONE, 'Tables created successfully'); } diff --git a/modules-available/locationinfo/lang/de/template-tags.json b/modules-available/locationinfo/lang/de/template-tags.json index 3f782970..d43ab0f4 100644 --- a/modules-available/locationinfo/lang/de/template-tags.json +++ b/modules-available/locationinfo/lang/de/template-tags.json @@ -12,7 +12,7 @@ "lang_pcIP": "IP", "lang_pcX": "X", "lang_pcY": "Y", - "lang_pcInUse": "In Benutzung", + "lang_pcState": "PC Status", "lang_day": "Tag", "lang_openingTime": "Öffnungszeit", @@ -62,5 +62,17 @@ "lang_configupdateTooltip": "Zeit nachder die Einstellungen geupdated werden (in minuten)", "lang_min": "min", "lang_sec": "sec", - "lang_autoScale": "Auto skalierung" + "lang_autoScale": "Auto skalierung", + "lang_deleteConfirmation": "Bist du sicher?", + "lang_addServer": "Server", + "lang_serverTable": "Server Liste", + "lang_buildingTable": "Gebäude / Raum Liste", + "lang_serverUrl": "Url", + "lang_serverType": "Type", + "lang_serverUser": "Benutzer", + "lang_serverPassword": "Passwort", + "lang_serverID": "Server ID", + "lang_sID": "sID", + "lang_server": "Server", + "lang_serverRoomId": "Server: Raum ID" } diff --git a/modules-available/locationinfo/lang/en/template-tags.json b/modules-available/locationinfo/lang/en/template-tags.json index 07224987..9efeb2c4 100644 --- a/modules-available/locationinfo/lang/en/template-tags.json +++ b/modules-available/locationinfo/lang/en/template-tags.json @@ -12,7 +12,7 @@ "lang_pcIP": "IP", "lang_pcX": "X", "lang_pcY": "Y", - "lang_pcInUse": "In Use", + "lang_pcState": "PC state", "lang_day": "Day", "lang_openingTime": "Opening time", @@ -62,5 +62,17 @@ "lang_configupdateTooltip": "Time interval the config gets updated (in minutes)", "lang_min": "min", "lang_sec": "sec", - "lang_autoScale": "Auto scale" + "lang_autoScale": "Auto scale", + "lang_deleteConfirmation": "Are you sure?", + "lang_addServer": "Server", + "lang_serverTable": "Server List", + "lang_buildingTable": "Building / Room List", + "lang_serverUrl": "Url", + "lang_serverType": "Type", + "lang_serverUser": "User", + "lang_serverPassword": "Password", + "lang_serverID": "Server ID", + "lang_sID": "sID", + "lang_server": "Server", + "lang_serverRoomId": "Server: Room ID" } diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php index 271b15fc..9b0cf487 100644 --- a/modules-available/locationinfo/page.inc.php +++ b/modules-available/locationinfo/page.inc.php @@ -23,6 +23,10 @@ class Page_LocationInfo extends Page $this->updateOpeningTimeEasy(); } elseif ($this->action === 'updateConfig') { $this->updateConfig(); + } elseif ($this->action === 'updateServer') { + $this->updateServer(); + } elseif ($this->action === 'deleteServer') { + $this->deleteServer(); } } @@ -54,6 +58,27 @@ class Page_LocationInfo extends Page } + private function updateServer() { + $id = Request::post('id', 0, 'int'); + if ($id == 0) { + Database::exec("INSERT INTO `setting_location_info` (servername, serverurl, servertype, login, passwd) VALUES (:name, :url, :type, :login, :passwd)", + array('name' => Request::post('name', '', 'string'), 'url' => Request::post('url', '', 'string'), 'type' => Request::post('type', '', 'string'), + 'login' => Request::post('user', '', 'string'), 'passwd' => Request::post('password', '', 'string'))); + } else { + Database::exec("INSERT INTO `setting_location_info` (serverid, servername, servertype, serverurl, login, passwd) VALUES (:id, :name, :type, :url, :login, :passwd) + ON DUPLICATE KEY UPDATE servername=:name, serverurl=:url, servertype=:type, login=:login, passwd=:passwd", + array('id' => $id, 'name' => Request::post('name', '', 'string'), 'url' => Request::post('url', '', 'string'), 'type' => Request::post('type', '', 'string'), + 'login' => Request::post('user', '', 'string'), 'passwd' => Request::post('password', '', 'string'))); + } + Util::redirect('?do=locationinfo&action=infoscreen'); + } + + private function deleteServer() { + $id = Request::post('id', 0, 'int'); + Database::exec("DELETE FROM `setting_location_info` WHERE serverid=:id", array('id' => $id)); + Util::redirect('?do=locationinfo&action=infoscreen'); + } + private function updateConfig() { $result = array(); @@ -71,9 +96,12 @@ class Page_LocationInfo extends Page $result['calupdate'] = Request::post('calupdate', 30, 'int'); $result['roomupdate'] = Request::post('roomupdate', 30, 'int'); $result['configupdate'] = Request::post('configupdate', 180, 'int'); + $serverid = Request::post('serverid', 0, 'int'); + $serverroomid = Request::post('serverroomid', 0, 'int'); - Database::exec("INSERT INTO `location_info` VALUES (:id, :hidden, '', :config, '') ON DUPLICATE KEY UPDATE config=:config", - array('id' => $locationid, 'hidden' => false, 'config' => json_encode($result, true))); + Database::exec("INSERT INTO `location_info` (locationid, serverid, serverroomid, hidden, config) VALUES (:id, :serverid, :serverroomid, :hidden, :config) + ON DUPLICATE KEY UPDATE config=:config, serverid=:serverid, serverroomid=:serverroomid", + array('id' => $locationid, 'hidden' => false, 'config' => json_encode($result, true), 'serverid' => $serverid, 'serverroomid' => $serverroomid)); Message::addSuccess('config-saved'); Util::redirect('?do=locationinfo'); @@ -150,7 +178,7 @@ class Page_LocationInfo extends Page } } - Database::exec("INSERT INTO `location_info` VALUES (:id, :hidden, :openingtime, '', '') ON DUPLICATE KEY UPDATE openingtime=:openingtime", + Database::exec("INSERT INTO `location_info` (locationid, hidden, openingtime) VALUES (:id, :hidden, :openingtime) ON DUPLICATE KEY UPDATE openingtime=:openingtime", array('id' => $locationid, 'hidden' => false, 'openingtime' => json_encode($result, true))); if ($deleteCounter > 0) { @@ -184,7 +212,7 @@ class Page_LocationInfo extends Page $opt2['closingtime'] = $closingtime[2]; $result[] = $opt2; - Database::exec("INSERT INTO `location_info` VALUES (:id, :hidden, :openingtime, '', '') ON DUPLICATE KEY UPDATE openingtime=:openingtime", + Database::exec("INSERT INTO `location_info` (locationid, hidden, openingtime) VALUES (:id, :hidden, :openingtime) ON DUPLICATE KEY UPDATE openingtime=:openingtime", array('id' => $locationid, 'hidden' => false, 'openingtime' => json_encode($result, true))); Message::addSuccess('openingtime-updated'); @@ -192,7 +220,7 @@ class Page_LocationInfo extends Page } protected function toggleHidden($id, $val) { - Database::exec("INSERT INTO `location_info` VALUES (:id, :hidden, '', '', '') ON DUPLICATE KEY UPDATE hidden=:hidden", array('id' => $id, 'hidden' => $val)); + Database::exec("INSERT INTO `location_info` (locationid, hidden) VALUES (:id, :hidden) ON DUPLICATE KEY UPDATE hidden=:hidden", array('id' => $id, 'hidden' => $val)); $this->checkChildRecursive($id, $val); $this->checkParentRecursive($id); @@ -207,7 +235,7 @@ class Page_LocationInfo extends Page } foreach ($childs as $key) { - Database::exec("INSERT INTO `location_info` VALUES (:id, :hidden, '', '', '') ON DUPLICATE KEY UPDATE hidden=:hidden", array('id' => $key, 'hidden' => $val)); + Database::exec("INSERT INTO `location_info` (locationid, hidden) VALUES (:id, :hidden) ON DUPLICATE KEY UPDATE hidden=:hidden", array('id' => $key, 'hidden' => $val)); $this->checkChildRecursive($key, $val); } @@ -236,9 +264,9 @@ class Page_LocationInfo extends Page } if ($amountofzero == 0 AND $amountofnull == 0) { - Database::exec("INSERT INTO `location_info` VALUES (:id, :hidden, '', '', '') ON DUPLICATE KEY UPDATE hidden=:hidden", array('id' => $parent, 'hidden' => 1)); + Database::exec("INSERT INTO `location_info` (locationid, hidden) VALUES (:id, :hidden) ON DUPLICATE KEY UPDATE hidden=:hidden", array('id' => $parent, 'hidden' => 1)); } else { - Database::exec("INSERT INTO `location_info` VALUES (:id, :hidden, '', '', '') ON DUPLICATE KEY UPDATE hidden=:hidden", array('id' => $parent, 'hidden' => 0)); + Database::exec("INSERT INTO `location_info` (locationid, hidden) VALUES (:id, :hidden) ON DUPLICATE KEY UPDATE hidden=:hidden", array('id' => $parent, 'hidden' => 0)); } $this->checkParentRecursive($parent); @@ -246,9 +274,9 @@ class Page_LocationInfo extends Page } protected function getInfoScreenTable() { - $dbquery = Database::simpleQuery("SELECT l.locationname, l.locationid, li.hidden, m.inUse, m.total FROM `location_info` AS li + $dbquery = Database::simpleQuery("SELECT l.locationname, l.locationid, li.hidden, m.pcState, m.total FROM `location_info` AS li RIGHT JOIN `location` AS l ON li.locationid=l.locationid LEFT JOIN - (SELECT locationid, Count(case m.logintime WHEN NOT 1 THEN null else 1 end) AS inUse, Count(*) AS total FROM `machine` AS m + (SELECT locationid, Count(case m.logintime WHEN NOT 1 THEN null else 1 end) AS pcState, Count(*) AS total FROM `machine` AS m WHERE locationid IS NOT NULL GROUP BY locationid) AS m ON l.locationid=m.locationid"); $pcs = array(); @@ -273,8 +301,8 @@ class Page_LocationInfo extends Page $pcs[$locid]['hidden'] = $roominfo['hidden']; } - if ($roominfo['inUse'] != NULL) { - $pcs[$locid]['inUse'] = $roominfo['inUse']; + if ($roominfo['pcState'] != NULL) { + $pcs[$locid]['pcState'] = $roominfo['pcState']; } if ($roominfo['total'] != NULL) { $pcs[$locid]['total'] = $roominfo['total']; @@ -284,23 +312,29 @@ class Page_LocationInfo extends Page } } + $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']; + if ($db['servertype'] == 'HISinOne') { + $server['HISinOne'] = true; + $server['DAVINCI'] = false; + } elseif ($db['servertype'] == 'DAVINCI') { + $server['HISinOne'] = false; + $server['DAVINCI'] = true; + } + $server['url'] = $db['serverurl']; + $server['user'] = $db['login']; + $server['password'] = $db['passwd']; + $serverlist[] = $server; + } + Render::addTemplate('location-info', array( - 'list' => array_values($pcs), + 'list' => array_values($pcs), 'serverlist' => array_values($serverlist), )); } - private function getInUseStatus($logintime, $lastseen) { - if ($logintime == 0) { - return 0; - } elseif ($logintime > 0) { - return 1; - // TODO lastseen > 610 = OFF TODO DEFEKT! if ... - } elseif ($lastseen > 610) { - return 2; - } - return -1; - } - /** * AJAX */ @@ -323,6 +357,7 @@ class Page_LocationInfo extends Page } } +//TODO REMOVE FUNCTION. NOT NECCESSARY BUT AFTER TESTING pcSTATE private function ajaxShowLocation($id) { $dbquery = Database::simpleQuery("SELECT machineuuid, clientip, position, logintime, lastseen FROM `machine` WHERE locationid = :id", array('id' => $id)); @@ -333,7 +368,7 @@ class Page_LocationInfo extends Page $pc = array(); $pc['id'] = $dbdata['machineuuid']; $pc['ip'] = $dbdata['clientip']; - $pc['inUse'] = $this->getInUseStatus($dbdata['logintime'], $dbdata['lastseen']); + $pc['pcState'] = LocationInfo::getPcState($dbdata['logintime'], $dbdata['lastseen']); $position = json_decode($dbdata['position'], true); $pc['x'] = $position['gridRow']; @@ -399,13 +434,30 @@ class Page_LocationInfo extends Page private function ajaxConfig($id) { $array = array(); - $dbquery = Database::simpleQuery("SELECT config FROM `location_info` WHERE locationid = :id", array('id' => $id)); + + // Get Config data from db + $dbquery = Database::simpleQuery("SELECT config, serverid, serverroomid FROM `location_info` WHERE locationid = :id", array('id' => $id)); + $serverid; + $serverroomid; while($dbdata=$dbquery->fetch(PDO::FETCH_ASSOC)) { $array = json_decode($dbdata['config'], true); + $serverid = $dbdata['serverid']; + $serverroomid = $dbdata['serverroomid']; + } + + // get Server / ID list + $dbq = Database::simpleQuery("SELECT serverid, servername FROM `setting_location_info`"); + $serverList = array(); + while($dbd=$dbq->fetch(PDO::FETCH_ASSOC)) { + $d['sid'] = $dbd['serverid']; + $d['sname'] = $dbd['servername']; + $serverList[] = $d; } + echo Render::parse('config', array('id' => $id, 'language' => $array['language'], 'mode' => 'mode'.$array['mode'], 'vertical' => $array['vertical'], 'eco' => $array['eco'], 'daystoshow' => 'day'.$array['daystoshow'], 'scaledaysauto' => $array['scaledaysauto'], 'rotation' => 'rotation'.$array['rotation'], 'scale' => $array['scale'], 'switchtime' => $array['switchtime'], 'calupdate' => $array['calupdate'], - 'roomupdate' => $array['roomupdate'], 'configupdate' => $array['configupdate'])); + '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 a814077a..577f8f94 100644 --- a/modules-available/locationinfo/templates/config.html +++ b/modules-available/locationinfo/templates/config.html @@ -1,9 +1,29 @@
+ +
+ +
+
+ +
+ +
+
+ +
+ + +



+

+ + + + + {{id}} + + + + + + + + + + + + + + + + + + + + + +{{/serverlist}} +
+ + + + +
+ + +
+ + +


+ +
+
+ +

{{lang_buildingTable}}

@@ -17,7 +81,7 @@ - + diff --git a/modules-available/locationinfo/templates/pcsubtable.html b/modules-available/locationinfo/templates/pcsubtable.html index 22eea6f1..59aa28b2 100644 --- a/modules-available/locationinfo/templates/pcsubtable.html +++ b/modules-available/locationinfo/templates/pcsubtable.html @@ -6,7 +6,7 @@ - + {{#list}} @@ -15,7 +15,7 @@ - + {{/list}} -- cgit v1.2.3-55-g7522
{{#hasPcs}}{{/hasPcs}}{{locationname}}{{#hasPcs}}{{/hasPcs}}
[{{locationid}}]{{#hasPcs}}{{inUse}} / {{total}}{{/hasPcs}}{{#hasPcs}}{{pcState}} / {{total}}{{/hasPcs}} {{lang_pcIP}} {{lang_pcX}} {{lang_pcY}}{{lang_pcInUse}}{{lang_pcState}}
{{ip}} {{x}} {{y}}{{inUse}}{{pcState}}