From eda3fac7c520e33228ef771767da652c0f94379e Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Sun, 20 Nov 2016 20:34:45 -0800 Subject: Fixed from the Mail applied. Added OpeningTimes and stuff for the admin panel. new install.php should beexcecuted --- modules-available/locationinfo/api.inc.php | 72 ++++++-- .../locationinfo/frontend/doorsign.html | 2 +- modules-available/locationinfo/install.inc.php | 4 +- .../locationinfo/lang/de/messages.json | 4 + .../locationinfo/lang/de/template-tags.json | 3 + .../locationinfo/lang/en/messages.json | 4 + .../locationinfo/lang/en/template-tags.json | 2 + modules-available/locationinfo/page.inc.php | 190 ++++++++++++++++++--- modules-available/locationinfo/style.css | 44 ----- .../locationinfo/templates/location-info.html | 168 ++++-------------- .../locationinfo/templates/pcsubtable.html | 6 +- .../locationinfo/templates/timetable.html | 64 +++++++ 12 files changed, 345 insertions(+), 218 deletions(-) create mode 100644 modules-available/locationinfo/lang/de/messages.json create mode 100644 modules-available/locationinfo/lang/en/messages.json create mode 100644 modules-available/locationinfo/templates/timetable.html diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php index be202546..31c574d9 100644 --- a/modules-available/locationinfo/api.inc.php +++ b/modules-available/locationinfo/api.inc.php @@ -3,32 +3,77 @@ HandleParameters(); function HandleParameters() { - $getAction = $_GET['action']; + $getAction = Request::get('action', 0, 'string'); if ($getAction == "roominfo") { - $getRoomID = $_GET['id']; - $getCoords = $_GET['coords']; - + $getRoomID = Request::get('id', 0, 'int'); + $getCoords = Request::get('coords', 0, 'string'); if (empty($getCoords)) { $getCoords = '0'; } getRoomInfoJson($getRoomID, $getCoords); + } elseif ($getAction == "openingtime") { + $getRoomID = Request::get('id', 0, 'int'); + getOpeningTimes($getRoomID); } } -function getRoomInfoJson($locationID, $coords) { - $error = false; - - $dbquery = Database::simpleQuery("SELECT hidden FROM `locationinfo` WHERE locationid = $locationID"); +function checkIfHidden($locationID) { + $dbquery = Database::simpleQuery("SELECT hidden FROM `location_info` WHERE locationid = :locationID", array('locationID' => $locationID)); while($roominfo=$dbquery->fetch(PDO::FETCH_ASSOC)) { $hidden = $roominfo['hidden']; if ($hidden === '0') { - $error = false; + return false; } else { - $error = true; + return true; } } +} + +function getOpeningTimes($locationID) { + $error = checkIfHidden($locationID); + if ($error == true) { + echo "ERROR"; + return; + } + $dbquery = Database::simpleQuery("SELECT openingtime FROM `location_info` WHERE locationid = :locationID", array('locationID' => $locationID)); + + $result = array(); + while($dbdata=$dbquery->fetch(PDO::FETCH_ASSOC)) { + $dbresult = json_decode($dbdata['openingtime'], true); + } + + $weekarray = array ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"); + + foreach ($weekarray as $d) { + $array = array(); + foreach ($dbresult as $day) { + foreach($day['days'] as $val) { + if ($val == $d) { + $arr = array(); + + $arr['HourOpen'] = $day['openingtime'][0] . $day['openingtime'][1]; + $arr['MinutesOpen'] = $day['openingtime'][3] . $day['openingtime'][4]; + + $arr['HourClose'] = $day['closingtime'][0] . $day['closingtime'][1]; + $arr['MinutesClose'] = $day['closingtime'][3] . $day['closingtime'][4]; + + $array[] = $arr; + } + } + if(!empty($array)) { + $result[$d] = $array; + } + } + } + + echo json_encode($result, true); +} + +function getRoomInfoJson($locationID, $coords) { + $error = checkIfHidden($locationID); + $pcs = getPcInfos($locationID, $coords); if (empty($pcs)) { @@ -43,13 +88,12 @@ function getRoomInfoJson($locationID, $coords) { } function getPcInfos($locationID, $coords) { - $dbquery; if ($coords === '1') { - $dbquery = Database::simpleQuery("SELECT machineuuid, position, logintime FROM `machine` WHERE locationid = $locationID"); + $dbquery = Database::simpleQuery("SELECT machineuuid, position, logintime FROM `machine` WHERE locationid = :locationID" , array('locationID' => $locationID)); } else { - $dbquery = Database::simpleQuery("SELECT machineuuid, logintime FROM `machine` WHERE locationid = $locationID"); + $dbquery = Database::simpleQuery("SELECT machineuuid, logintime FROM `machine` WHERE locationid = :locationID" , array('locationID' => $locationID)); } $pcs = array(); @@ -79,5 +123,3 @@ function getPcInfos($locationID, $coords) { return $str; } - -?> diff --git a/modules-available/locationinfo/frontend/doorsign.html b/modules-available/locationinfo/frontend/doorsign.html index 9db56fd8..fb621671 100755 --- a/modules-available/locationinfo/frontend/doorsign.html +++ b/modules-available/locationinfo/frontend/doorsign.html @@ -798,4 +798,4 @@ optional: - \ No newline at end of file + diff --git a/modules-available/locationinfo/install.inc.php b/modules-available/locationinfo/install.inc.php index 807e2826..e056fea1 100644 --- a/modules-available/locationinfo/install.inc.php +++ b/modules-available/locationinfo/install.inc.php @@ -2,10 +2,10 @@ $res = array(); -$res[] = tableCreate('locationinfo', ' +$res[] = tableCreate('location_info', ' `locationid` INT(11) NOT NULL, `hidden` BOOLEAN NOT NULL DEFAULT 0, - `computers` BLOB DEFAULT NULL, + `openingtime` VARCHAR(2000) NOT NULL, PRIMARY KEY (`locationid`) '); diff --git a/modules-available/locationinfo/lang/de/messages.json b/modules-available/locationinfo/lang/de/messages.json new file mode 100644 index 00000000..26822083 --- /dev/null +++ b/modules-available/locationinfo/lang/de/messages.json @@ -0,0 +1,4 @@ +{ + "no-days-selected": "Es wurden keine Tage ausgewählt.", + "added-x-entries": "Eintr\u00e4ge hinzugef\u00fcgt: {{0}}" +} diff --git a/modules-available/locationinfo/lang/de/template-tags.json b/modules-available/locationinfo/lang/de/template-tags.json index 843beb5a..d27d55e4 100644 --- a/modules-available/locationinfo/lang/de/template-tags.json +++ b/modules-available/locationinfo/lang/de/template-tags.json @@ -9,6 +9,7 @@ "lang_pcID": "ID", + "lang_pcIP": "IP", "lang_pcX": "X", "lang_pcY": "Y", "lang_pcInUse": "In Benutzung", @@ -16,6 +17,8 @@ "lang_day": "Tag", "lang_openingTime": "Öffnungszeit", "lang_closingTime": "Schließungszeit", + "lang_deleteAll": "Alles Löschen", + "lang_shortMonday": "Mo", "lang_shortTuesday": "Di", diff --git a/modules-available/locationinfo/lang/en/messages.json b/modules-available/locationinfo/lang/en/messages.json new file mode 100644 index 00000000..114cade7 --- /dev/null +++ b/modules-available/locationinfo/lang/en/messages.json @@ -0,0 +1,4 @@ +{ + "no-days-selected": "No days selected.", + "added-x-entries": "Entries added: {{0}}" +} diff --git a/modules-available/locationinfo/lang/en/template-tags.json b/modules-available/locationinfo/lang/en/template-tags.json index 4c4d1d38..a63751a8 100644 --- a/modules-available/locationinfo/lang/en/template-tags.json +++ b/modules-available/locationinfo/lang/en/template-tags.json @@ -9,6 +9,7 @@ "lang_pcID": "ID", + "lang_pcIP": "IP", "lang_pcX": "X", "lang_pcY": "Y", "lang_pcInUse": "In Use", @@ -16,6 +17,7 @@ "lang_day": "Day", "lang_openingTime": "Opening time", "lang_closingTime": "Closing time", + "lang_deleteAll": "Delete all", "lang_shortMonday": "Mon", "lang_shortTuesday": "Tue", diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php index f6b4b661..f946bee8 100644 --- a/modules-available/locationinfo/page.inc.php +++ b/modules-available/locationinfo/page.inc.php @@ -15,6 +15,11 @@ class Page_LocationInfo extends Page Message::addError('main.no-permission'); Util::redirect('?do=Main'); // does not return } + + $this->action = Request::post('action'); + if ($this->action === 'updateOpeningTime') { + $this->updateOpeningTime(); + } } /** @@ -44,33 +49,125 @@ class Page_LocationInfo extends Page } } + private function updateOpeningTime() + { + $existingDays = Request::post('existingdays'); + $days = Request::post('days'); + $locationid = Request::post('id'); + $openingtime = Request::post('openingtime'); + $closingtime = Request::post('closingtime'); + $delete = Request::post('delete'); + $dontadd = Request::post('dontadd'); + $count = 0; + $result = array(); + $resulttmp = array(); + + $dbquery = Database::simpleQuery("SELECT openingtime FROM `location_info` WHERE locationid = :id", array('id' => $locationid)); + while($dbdata=$dbquery->fetch(PDO::FETCH_ASSOC)) { + $resulttmp = json_decode($dbdata['openingtime'], true); + } + + $index = 0; + + foreach ($resulttmp as $day) { + $skip = false; + foreach ($delete as $del) { + if ($del == $index) { + $skip = true; + break; + } + } + if ($skip == true) { + $index++; + continue; + } + + $result[] = $day; + $index++; + } + + if (!empty($days) && !is_array($days)) { + Message::addError('no-days-selected'); + Util::redirect('?do=locationinfo'); + } else{ + + $dayz = array(); + $da = array(); + + foreach ($days as $d) { + if ($d != '-') { + $da[] = $d; + } else { + $dayz[$count] = $da; + $da = array(); + $count++; + } + } + + $optime = array(); + for ($x = 0; $x < $count; $x++) { + if ($dontadd[$x] == 'dontadd') { + continue; + } + $optime['days'] = $dayz[$x]; + $optime['openingtime'] = $openingtime[$x]; + $optime['closingtime'] = $closingtime[$x]; + $result[] = $optime; + } + } + + Database::exec("INSERT INTO `location_info` VALUES (:id, :hidden, :openingtime) ON DUPLICATE KEY UPDATE openingtime=:openingtime", + array('id' => $locationid, 'hidden' => false, 'openingtime' => json_encode($result, true))); + + Message::addSuccess('added-x-entries', $count); + Util::redirect('?do=locationinfo'); + } + + private function removeOpeningTime() { + Message::addError('wasd'); + } + protected function toggleHidden($id, $val) { - Database::exec("UPDATE `locationinfo` SET hidden = $val WHERE locationid = $id"); + Database::exec("INSERT INTO `location_info` VALUES (:id, :hidden, '') ON DUPLICATE KEY UPDATE hidden=:hidden", array('id' => $id, 'hidden' => $val)); } protected function getInfoScreenTable() { + $dbquery = Database::simpleQuery("SELECT l.locationname, l.locationid, li.hidden, m.inUse, 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 + WHERE locationid IS NOT NULL GROUP BY locationid) AS m ON l.locationid=m.locationid"); + $pcs = array(); - $dbquery = Database::simpleQuery("SELECT * FROM `locationinfo`"); + if (Module::isAvailable('locations')) { + foreach (Location::getLocations() as $loc) { + $data = array(); + $data['locationid'] = (int)$loc['locationid']; + $data['locationname'] = $loc['locationname']; + $data['depth'] = $loc['depth']; + $data['hidden'] = NULL; + $locid = (int)$loc['locationid']; + $pcs[$locid] = $data; + } + } - $pcs = array(); while($roominfo=$dbquery->fetch(PDO::FETCH_ASSOC)) { - $data = array(); - $data['locationid'] = $roominfo['locationid']; - $data['hidden'] = $roominfo['hidden']; + $locid = (int)$roominfo['locationid']; - $inUseCounter = 0; - $totalPcCounter = 0; - $data['computers'] = json_decode($roominfo['computers'], true); + if ($roominfo['hidden'] == NULL) { + $pcs[$locid]['hidden'] = 0; + } else { + $pcs[$locid]['hidden'] = $roominfo['hidden']; + } - foreach ($data['computers'] as $value) { - if ($value['inUse'] == 1) { - $inUseCounter++; - } - $totalPcCounter++; + if ($roominfo['inUse'] != NULL) { + $pcs[$locid]['inUse'] = $roominfo['inUse']; + } + if ($roominfo['total'] != NULL) { + $pcs[$locid]['total'] = $roominfo['total']; + $pcs[$locid]['hasPcs'] = true; + } else { + $pcs[$locid]['hasPcs'] = false; } - $data['inUse'] = $inUseCounter; - $data['totalPcs'] = $totalPcCounter; - $pcs[] = $data; } Render::addTemplate('location-info', array( @@ -85,6 +182,17 @@ class Page_LocationInfo extends Page } } + 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; + } + } + /** * AJAX */ @@ -98,22 +206,62 @@ class Page_LocationInfo extends Page if ($action === 'pcsubtable') { $id = Request::any('id'); $this->ajaxShowLocation($id); + } + if ($action === 'timetable') { + $id = Request::any('id'); + $this->ajaxTimeTable($id); } } private function ajaxShowLocation($id) { - $dbquery = Database::simpleQuery("SELECT * FROM `locationinfo` WHERE locationid = $id"); + $dbquery = Database::simpleQuery("SELECT machineuuid, clientip, position, logintime, lastseen FROM `machine` WHERE locationid = :id", array('id' => $id)); $data = array(); - while($roominfo=$dbquery->fetch(PDO::FETCH_ASSOC)) { - $data = json_decode($roominfo['computers'], true); + + while($dbdata=$dbquery->fetch(PDO::FETCH_ASSOC)) { + $pc = array(); + $pc['id'] = $dbdata['machineuuid']; + $pc['ip'] = $dbdata['clientip']; + $pc['inUse'] = $this->getInUseStatus($dbdata['logintime'], $dbdata['lastseen']); + + $position = array(); + $position = json_decode($dbdata['position'], true); + $pc['x'] = $position['gridRow']; + $pc['y'] = $position['gridCol']; + + + $data[] = $pc; } echo Render::parse('pcsubtable', array( - 'list' => array_values($data), + 'list' => array_values($data) )); } + private function ajaxTimeTable($id) { + $array = array(); + $dbquery = Database::simpleQuery("SELECT openingtime FROM `location_info` WHERE locationid = :id", array('id' => $id)); + while($dbdata=$dbquery->fetch(PDO::FETCH_ASSOC)) { + $db = array(); + $db = json_decode($dbdata['openingtime'], true); + $index = 0; + foreach ($db as $key) { + $str = "| "; + foreach ($key['days'] as $val) { + $str .= $val; + $str .= " | "; + } + $ar = array(); + $ar['days'] = $str; + $ar['openingtime'] = $key['openingtime']; + $ar['closingtime'] = $key['closingtime']; + $ar['index'] = $index; + $array[] = $ar; + $index++; + } + } + echo Render::parse('timetable', array('id' => $id, 'openingtimes' => array_values($array))); + } } diff --git a/modules-available/locationinfo/style.css b/modules-available/locationinfo/style.css index 2169efa2..c0b10cd9 100644 --- a/modules-available/locationinfo/style.css +++ b/modules-available/locationinfo/style.css @@ -1,47 +1,3 @@ -/* The Modal (background) */ -.modal { - display: none; /* Hidden by default */ - position: fixed; /* Stay in place */ - z-index: 1; /* Sit on top */ - left: 0; - top: 0; - width: 100%; /* Full width */ - height: 100%; /* Full height */ - overflow: auto; /* Enable scroll if needed */ - background-color: rgb(0,0,0); /* Fallback color */ - background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ -} - -/* Modal Content/Box */ -.modal-content { - background-color: #fefefe; - margin: 15% auto; /* 15% from the top and centered */ - padding: 20px; - border: 1px solid #888; - width: 40%; /* Could be more or less, depending on screen size */ -} - -/* The Close Button */ -.close { - color: #aaa; - float: right; - font-size: 28px; - font-weight: bold; -} - -.close:hover, -.close:focus { - color: black; - text-decoration: none; - cursor: pointer; -} - .tablerow:hover { background-color: #F2F2F2; } - -.divider{ - width:50px; - height:auto; - display:inline-block; -} diff --git a/modules-available/locationinfo/templates/location-info.html b/modules-available/locationinfo/templates/location-info.html index 9e4e886d..22a961b6 100644 --- a/modules-available/locationinfo/templates/location-info.html +++ b/modules-available/locationinfo/templates/location-info.html @@ -1,136 +1,34 @@

{{lang_mainHeader}}

- - - - - - + + + + {{#list}} - - - - - + + + + + + + + - - + -{{/list}} +{{/list}}
{{lang_locationID}}{{lang_locationInUse}}{{lang_locationName}}{{lang_locationID}}{{lang_locationInUse}} {{lang_locationIsHidden}} {{lang_locationSettings}}
-
- {{locationid}} -
{{inUse}} / {{totalPcs}}
{{#hasPcs}}{{/hasPcs}}{{locationname}}
{{locationid}}{{#hasPcs}}{{inUse}} / {{total}}{{/hasPcs}} {{lang_locationSettings}}
- diff --git a/modules-available/locationinfo/templates/pcsubtable.html b/modules-available/locationinfo/templates/pcsubtable.html index 0359813b..1a7ea81e 100644 --- a/modules-available/locationinfo/templates/pcsubtable.html +++ b/modules-available/locationinfo/templates/pcsubtable.html @@ -2,7 +2,8 @@
- + + @@ -10,7 +11,8 @@ {{#list}} - + + diff --git a/modules-available/locationinfo/templates/timetable.html b/modules-available/locationinfo/templates/timetable.html new file mode 100644 index 00000000..c06a70eb --- /dev/null +++ b/modules-available/locationinfo/templates/timetable.html @@ -0,0 +1,64 @@ +
+
+ + + + +
{{lang_pcID}}{{lang_pcID}}{{lang_pcIP}} {{lang_pcX}} {{lang_pcY}} {{lang_pcInUse}}
{{id}}{{id}}{{ip}} {{x}} {{y}} {{inUse}}
+ + + + + + + + {{#openingtimes}} + + + + + + {{/openingtimes}} + + +
{{lang_day}}{{lang_openingTime}}{{lang_closingTime}}{{lang_delete}}
{{days}}{{openingtime}}{{closingtime}} + +
+ +
+ {{lang_openingTime}} + +
+
+ + + +
+ + -- cgit v1.2.3-55-g7522