summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/page.inc.php
diff options
context:
space:
mode:
authorJannik Schönartz2016-11-21 05:34:45 +0100
committerJannik Schönartz2016-11-21 05:34:45 +0100
commiteda3fac7c520e33228ef771767da652c0f94379e (patch)
tree1b49cfeaa2319cba39cc29ec0b8da6f9334fa628 /modules-available/locationinfo/page.inc.php
parentfirst commit of the frontend from locationinfo modul (diff)
downloadslx-admin-eda3fac7c520e33228ef771767da652c0f94379e.tar.gz
slx-admin-eda3fac7c520e33228ef771767da652c0f94379e.tar.xz
slx-admin-eda3fac7c520e33228ef771767da652c0f94379e.zip
Fixed from the Mail applied. Added OpeningTimes and stuff for the admin panel. new install.php should beexcecuted
Diffstat (limited to 'modules-available/locationinfo/page.inc.php')
-rw-r--r--modules-available/locationinfo/page.inc.php190
1 files changed, 169 insertions, 21 deletions
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)));
+ }
}