diff options
author | Simon Rettberg | 2017-12-21 13:23:18 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-12-21 13:23:18 +0100 |
commit | 8d8362dd7ce06c4f9771c619ec4f2625ff82b877 (patch) | |
tree | c8a60af19b3edc5ff430831a494da123049e4556 | |
parent | [locationinfo] Update translations (diff) | |
download | slx-admin-8d8362dd7ce06c4f9771c619ec4f2625ff82b877.tar.gz slx-admin-8d8362dd7ce06c4f9771c619ec4f2625ff82b877.tar.xz slx-admin-8d8362dd7ce06c4f9771c619ec4f2625ff82b877.zip |
[statistics] Properly mark disconnected sceens as such if the output name changed
-rw-r--r-- | modules-available/statistics/api.inc.php | 46 | ||||
-rw-r--r-- | modules-available/statistics/page.inc.php | 113 | ||||
-rw-r--r-- | modules-available/statistics/pages/projectors.inc.php | 58 | ||||
-rw-r--r-- | modules-available/statistics/templates/machine-main.html | 4 | ||||
-rw-r--r-- | modules-available/statistics/templates/page-replace.html | 104 | ||||
-rw-r--r-- | modules-available/statistics/templates/projector-list.html | 2 |
6 files changed, 239 insertions, 88 deletions
diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php index a614658a..3cb1e961 100644 --- a/modules-available/statistics/api.inc.php +++ b/modules-available/statistics/api.inc.php @@ -263,6 +263,7 @@ if ($type{0} === '~') { // `devicetype`, `devicename`, `subid`, `machineuuid` // Make sure all screens are in the general hardware table $hwids = array(); + $ports = array(); foreach ($screens as $port => $screen) { if (!array_key_exists('name', $screen)) continue; @@ -274,6 +275,7 @@ if ($type{0} === '~') { $hwids[$screen['name']] = $hwid; } // Now add new entries + $ports[] = $port; $machinehwid = Database::insertIgnore('machine_x_hw', 'machinehwid', array( 'hwid' => $hwid, 'machineuuid' => $uuid, @@ -302,30 +304,40 @@ if ($type{0} === '~') { Database::exec("DELETE FROM machine_x_hw_prop WHERE machinehwid = :machinehwid AND prop NOT LIKE '@%'", array('machinehwid' => $machinehwid)); } else { - $qs = '?' . str_repeat(',?', count($validProps) - 1); - array_unshift($validProps, $machinehwid); - Database::exec("DELETE FROM machine_x_hw_prop" - . " WHERE machinehwid = ? AND prop NOT LIKE '@%' AND prop NOT IN ($qs)", - $validProps); + Database::exec("DELETE FROM machine_x_hw_prop + WHERE machinehwid = :mhwid AND prop NOT LIKE '@%' AND prop NOT IN (:props)", array( + 'mhwid' => $machinehwid, + 'props' => array_values($validProps), + )); } } // Remove/disable stale entries - if (empty($hwids)) { + if (empty($ports)) { // No screens connected at all, purge all screen entries for this machine - Database::exec("UPDATE machine_x_hw x, statistic_hw h" - . " SET x.disconnecttime = UNIX_TIMESTAMP()" - . " WHERE x.machineuuid = :uuid AND x.hwid = h.hwid AND h.hwtype = :type AND x.disconnecttime = 0", + Database::exec("UPDATE machine_x_hw x, statistic_hw h + SET x.disconnecttime = UNIX_TIMESTAMP() + WHERE x.machineuuid = :uuid AND x.hwid = h.hwid AND h.hwtype = :type AND x.disconnecttime = 0", array('uuid' => $uuid, 'type' => DeviceType::SCREEN)); } else { // Some screens connected, make sure old entries get removed - $params = array_values($hwids); - array_unshift($params, $uuid); - array_unshift($params, DeviceType::SCREEN); - $qs = '?' . str_repeat(',?', count($hwids) - 1); - Database::exec("UPDATE machine_x_hw x, statistic_hw h" - . " SET x.disconnecttime = UNIX_TIMESTAMP()" - . " WHERE h.hwid = x.hwid AND x.disconnecttime = 0 AND h.hwtype = ? AND x.machineuuid = ? AND x.hwid NOT IN ($qs)", $params); - + Database::exec("UPDATE machine_x_hw x, statistic_hw h + SET x.disconnecttime = UNIX_TIMESTAMP() + WHERE h.hwid = x.hwid AND x.disconnecttime = 0 AND h.hwtype = :type + AND x.machineuuid = :uuid AND x.devpath NOT IN (:ports)", array( + 'ports' => array_values($ports), + 'uuid' => $uuid, + 'type' => DeviceType::SCREEN, + )); + if (!empty($hwids)) { + Database::exec("UPDATE machine_x_hw x, statistic_hw h + SET x.disconnecttime = UNIX_TIMESTAMP() + WHERE h.hwid = x.hwid AND x.disconnecttime = 0 AND h.hwtype = :type + AND x.machineuuid = :uuid AND x.hwid NOT IN (:hwids)", array( + 'hwids' => array_values($hwids), + 'uuid' => $uuid, + 'type' => DeviceType::SCREEN, + )); + } } } } else if ($type === '~suspend') { diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php index bd67123e..ea5b6f03 100644 --- a/modules-available/statistics/page.inc.php +++ b/modules-available/statistics/page.inc.php @@ -21,6 +21,11 @@ class Page_Statistics extends Page private $query; + /** + * @var bool whether we have a SubPage from the pages/ subdir + */ + private $haveSubpage; + /* PHP sucks, no static, const array definitions... Or am I missing something? */ public function initConstants() { @@ -125,53 +130,6 @@ class Page_Statistics extends Page /* TODO ... */ } - /* - * TODO: Move to separate unit... hardware configurator? - */ - - protected function handleProjector($action) - { - $hwid = Request::post('hwid', false, 'int'); - if ($hwid === false) { - Util::traceError('Param hwid missing'); - } - if ($action === 'addprojector') { - Database::exec('INSERT INTO statistic_hw_prop (hwid, prop, value)' - . ' VALUES (:hwid, :prop, :value)', array( - 'hwid' => $hwid, - 'prop' => 'projector', - 'value' => 'true', - )); - } else { - Database::exec('DELETE FROM statistic_hw_prop WHERE hwid = :hwid AND prop = :prop', array( - 'hwid' => $hwid, - 'prop' => 'projector', - )); - } - if (Module::isAvailable('sysconfig')) { - ConfigTgz::rebuildAllConfigs(); - } - Util::redirect('?do=statistics&show=projectors'); - } - - protected function showProjectors() - { - $res = Database::simpleQuery('SELECT h.hwname, h.hwid FROM statistic_hw h' - . " INNER JOIN statistic_hw_prop p ON (h.hwid = p.hwid AND p.prop = :projector)" - . " WHERE h.hwtype = :screen ORDER BY h.hwname ASC", array( - 'projector' => 'projector', - 'screen' => DeviceType::SCREEN, - )); - $data = array( - 'projectors' => $res->fetchAll(PDO::FETCH_ASSOC) - ); - Render::addTemplate('projector-list', $data); - } - - /* - * End TODO - */ - protected function doPreprocess() { $this->initConstants(); @@ -180,24 +138,42 @@ class Page_Statistics extends Page Message::addError('main.no-permission'); Util::redirect('?do=Main'); } - $action = Request::post('action'); - if ($action === 'setnotes') { - $uuid = Request::post('uuid', '', 'string'); - $text = Request::post('content', '', 'string'); - if (empty($text)) { - $text = null; + + $show = Request::any('show', 'stat', 'string'); + $show = preg_replace('/[^a-z0-9_\-]/', '', $show); + + if (file_exists('modules/statistics/pages/' . $show . '.inc.php')) { + + require_once 'modules/statistics/pages/' . $show . '.inc.php'; + $this->haveSubpage = true; + SubPage::doPreprocess(); + + } else { + + $action = Request::post('action'); + if ($action === 'setnotes') { + $uuid = Request::post('uuid', '', 'string'); + $text = Request::post('content', '', 'string'); + if (empty($text)) { + $text = null; + } + Database::exec('UPDATE machine SET notes = :text WHERE machineuuid = :uuid', array( + 'uuid' => $uuid, + 'text' => $text, + )); + Message::addSuccess('notes-saved'); + Util::redirect('?do=Statistics&uuid=' . $uuid); + } elseif ($action === 'delmachines') { + $this->deleteMachines(); + Util::redirect('?do=statistics', true); } - Database::exec('UPDATE machine SET notes = :text WHERE machineuuid = :uuid', array( - 'uuid' => $uuid, - 'text' => $text, - )); - Message::addSuccess('notes-saved'); - Util::redirect('?do=Statistics&uuid=' . $uuid); - } elseif ($action === 'addprojector' || $action === 'delprojector') { - $this->handleProjector($action); - } elseif ($action === 'delmachines') { - $this->deleteMachines(); - Util::redirect('?do=statistics', true); + + } + + if (Request::isPost()) { + // Make sure we don't render any content for POST requests - should be handled above and then + // redirected properly + Util::redirect('?do=statistics'); } } @@ -229,6 +205,11 @@ class Page_Statistics extends Page protected function doRender() { + if ($this->haveSubpage) { + SubPage::doRender(); + return; + } + $uuid = Request::get('uuid', false, 'string'); if ($uuid !== false) { $this->showMachine($uuid); @@ -236,10 +217,6 @@ class Page_Statistics extends Page } $show = Request::get('show', 'stat', 'string'); - if ($show === 'projectors') { - $this->showProjectors(); - return; - } /* read filter */ $this->query = Request::any('filters', false); diff --git a/modules-available/statistics/pages/projectors.inc.php b/modules-available/statistics/pages/projectors.inc.php new file mode 100644 index 00000000..cde542c6 --- /dev/null +++ b/modules-available/statistics/pages/projectors.inc.php @@ -0,0 +1,58 @@ +<?php + +class SubPage +{ + + public static function doPreprocess() + { + $action = Request::post('action', false, 'string'); + if ($action !== false) { + self::handleProjector($action); + } + } + + private static function handleProjector($action) + { + $hwid = Request::post('hwid', false, 'int'); + if ($hwid === false) { + Util::traceError('Param hwid missing'); + } + if ($action === 'addprojector') { + Database::exec('INSERT INTO statistic_hw_prop (hwid, prop, value)' + . ' VALUES (:hwid, :prop, :value)', array( + 'hwid' => $hwid, + 'prop' => 'projector', + 'value' => 'true', + )); + } else { + Database::exec('DELETE FROM statistic_hw_prop WHERE hwid = :hwid AND prop = :prop', array( + 'hwid' => $hwid, + 'prop' => 'projector', + )); + } + if (Module::isAvailable('sysconfig')) { + ConfigTgz::rebuildAllConfigs(); + } + Util::redirect('?do=statistics&show=projectors'); + } + + public static function doRender() + { + self::showProjectors(); + } + + private static function showProjectors() + { + $res = Database::simpleQuery('SELECT h.hwname, h.hwid FROM statistic_hw h' + . " INNER JOIN statistic_hw_prop p ON (h.hwid = p.hwid AND p.prop = :projector)" + . " WHERE h.hwtype = :screen ORDER BY h.hwname ASC", array( + 'projector' => 'projector', + 'screen' => DeviceType::SCREEN, + )); + $data = array( + 'projectors' => $res->fetchAll(PDO::FETCH_ASSOC) + ); + Render::addTemplate('projector-list', $data); + } + +}
\ No newline at end of file diff --git a/modules-available/statistics/templates/machine-main.html b/modules-available/statistics/templates/machine-main.html index 19deb8b3..d8f2c521 100644 --- a/modules-available/statistics/templates/machine-main.html +++ b/modules-available/statistics/templates/machine-main.html @@ -144,11 +144,11 @@ <tr> <td class="text-nowrap">{{lang_screens}}</td> <td> - <form method="post" action="?do=statistics" id="delprojector"> + <form method="post" action="?do=statistics&show=projectors" id="delprojector"> <input type="hidden" name="token" value="{{token}}"> <input type="hidden" name="action" value="delprojector"> </form> - <form method="post" action="?do=statistics" id="addprojector"> + <form method="post" action="?do=statistics&show=projectors" id="addprojector"> <input type="hidden" name="token" value="{{token}}"> <input type="hidden" name="action" value="addprojector"> </form> diff --git a/modules-available/statistics/templates/page-replace.html b/modules-available/statistics/templates/page-replace.html new file mode 100644 index 00000000..f87610a2 --- /dev/null +++ b/modules-available/statistics/templates/page-replace.html @@ -0,0 +1,104 @@ +<h1>{{lang_replaceMachinesHeading}}</h1> + +<style> + .reptable { + border-collapse: separate; + border-spacing: 2px; + } + .reptable td.a { + padding: 2px; + border:1px solid #ccc; + border-radius: 3px; + background: #eee; + vertical-align: top; + } + .reptable td.b { + font-size: 300%; + } +</style> + +<form method="post" action="?do=statistics&show=replace"> + <input type="hidden" name="token" value="{{token}}"> + <table class="reptable"> + <thead> + <tr> + <th>{{lang_replaceOld}}</th> + <th></th> + <th>{{lang_replaceNew}}</th> + <th></th> + </tr> + </thead> + <tbody> + {{#pairs}} + <tr> + <td class="a"> + <div><b>{{oldhost}}</b> {{oldip}}</div> + <div class="slx-bold">{{oldmodel}}</div> + <div class="small">{{oldmac}} – {{olduuid}}</div> + <div>{{lang_lastSeen}}: {{oldlastseen_s}}</div> + </td> + <td class="b">→</td> + <td class="a"> + <div><b>{{newhost}}</b> {{newip}}</div> + <div class="slx-bold">{{newmodel}}</div> + <div class="small">{{newmac}} – {{newuuid}}</div> + <div>{{lang_firstSeen}}: {{newfirstseen_s}}</div> + </td> + <td> + <div class="checkbox checkbox-inline"> + <input type="checkbox" name="replace[]" value="{{olduuid}}x{{newuuid}}"> + <label></label> + </div> + </td> + </tr> + {{/pairs}} + </tbody> + </table> + + <div class="text-right"> + <button type="button" class="btn btn-danger" name="action" value="replace" data-toggle="modal" data-target="#confirm-dialog"> + <span class="glyphicon glyphicon-floppy-disk"></span> + {{lang_replace}} + (<span id="rep-count">0</span>) + </button> + </div> + + <div class="modal fade" id="confirm-dialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> + <div class="modal-dialog" role="document"> + <div class="modal-content"> + <div class="modal-header"> + <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> + <h4 class="modal-title" id="myModalLabel">{{lang_replace}}</h4> + </div> + <div class="modal-body"> + {{lang_sureReplaceNoUndo}} + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-default" data-dismiss="modal">{{lang_cancel}}</button> + <button type="submit" name="action" value="replace" class="btn btn-danger"> + <span class="glyphicon glyphicon-floppy-disk"></span> + {{lang_replace}} + </button> + </div> + </div> + </div> + </div> +</form> + +<script type="application/javascript"><!-- + document.addEventListener('DOMContentLoaded', function () { + $('td.a').click(function () { + var $cb = $(this).parent().find('input:checkbox'); + $cb.prop('checked', !$cb.is(':checked')); + cbChanged(); + }); + $('input:checkbox').change(function () { + cbChanged(); + }); + function cbChanged() { + var cnt = $('input:checkbox:checked').length; + $('#rep-count').text(cnt).parent().prop('disabled', cnt === 0); + } + cbChanged(); + }); +//--></script>
\ No newline at end of file diff --git a/modules-available/statistics/templates/projector-list.html b/modules-available/statistics/templates/projector-list.html index bc9ecdbd..c33aae09 100644 --- a/modules-available/statistics/templates/projector-list.html +++ b/modules-available/statistics/templates/projector-list.html @@ -1,7 +1,7 @@ <div class="panel panel-default"> <div class="panel-heading">{{lang_projectors}}</div> <div class="panel-body"> - <form method="post" action="?do=statistics" id="delprojector"> + <form method="post" action="?do=statistics&show=projectors" id="delprojector"> <input type="hidden" name="token" value="{{token}}"> <input type="hidden" name="action" value="delprojector"> <p>{{lang_thoseAreProjectors}}</p> |