| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- <?php
- Lib::loadClass('RouteBase');
- Lib::loadClass('UI');
- Lib::loadClass('Response');
- Lib::loadClass('SchemaFactory');
- class Route_Status extends RouteBase {
- public function defaultAction() {
- UI::gora();
- UI::startTag('div', ['class' => "container"]);
- echo UI::h('h1', [], [
- UI::h('a', ['href'=>"index.php"], "SE"),
- " » ",
- " Status systemu procesy5"
- ]);
- try {
- DB::getPDO();
- if ($postTask = V::get('_postTask', '', $_REQUEST)) {
- DBG::log($args, 'array', "exec '{$postTask}'");
- if (!method_exists($this, "{$postTask}PostTask")) throw new Exception("Post Task not exists!");
- ob_start();
- $this->{"{$postTask}PostTask"}($args);
- $outputPostTask = ob_get_clean();
- if ($outputPostTask) {
- echo UI::h('details', [], [
- UI::h('summary', [], "Wynik '{$postTask}' <i>(rozwiń)</i>"),
- $outputPostTask,
- ]);
- }
- }
- $this->viewStatusDatabase();
- if (in_array(User::get('ADM_ADMIN_LEVEL'), ['0', '1'])) {
- $this->viewStatusUsers();
- }
- // UI::table([
- // 'caption' => 'Baza danych',
- // 'rows' => DB::getPDO()->fetchAll(" SHOW VARIABLES ")
- // ]);
- } catch (Exception $e) {
- UI::alert('danger', $e->getMessage());
- }
- UI::endTag('div');// .container
- UI::dol();
- }
- public function viewStatusDatabase() {
- $dbEvents = DB::getPDO()->fetchFirst(" SHOW VARIABLES WHERE VARIABLE_NAME = 'event_scheduler' ");
- // DBG::nicePrint($dbEvents, '$dbEvents');
- // [Variable_name] => event_scheduler
- // [Value] => ON
- $aclObjectCacheExists = false;
- $objectStorage = SchemaFactory::loadDefaultObject('SystemObject');
- $aclCacheTableName = $objectStorage->getRootTableName();
- if ($aclCacheTableName) {
- try {
- $totalObjects = DB::getPDO()->fetchValue("select count(*) as cnt from `{$aclCacheTableName}`");
- if ($totalObjects > 0) $aclObjectCacheExists = true;
- } catch (Exception $e) {
- DBG::log($e);
- }
- }
- DBG::log($objectStorage, 'array', "\$objectStorage");
- DBG::log($objectStorage->getRootTableName(), 'array', "\$objectStorage->getRootTableName()");
- UI::table([
- 'caption' => UI::h('b', ['style' => "color:#000"], 'Baza danych'),
- 'rows' => [
- [
- 'nazwa' => "Event Scheduler (generowanie Grafika, itp.)",
- 'wartość' => ('ON' == $dbEvents['Value'])
- ? UI::h('span', ['class' => "label label-success"], "ON")
- : UI::h('span', ['class' => "label label-danger"], "OFF"),
- '#' => UI::hButtonPost("Włącz", [
- 'class' => "btn btn-xs btn-default",
- 'data' => [
- '_postTask' => 'fixEventSheduler',
- ]
- ])
- ],
- [
- 'nazwa' => "System obiektów (xsd)",
- 'wartość' => ($aclObjectCacheExists)
- ? UI::h('span', ['class' => "label label-success"], "ON")
- : UI::h('span', ['class' => "label label-danger"], "OFF"),
- '#' => UI::hButtonPost("Aktualizuj cache", [
- 'class' => "btn btn-xs btn-default",
- 'data' => [
- '_postTask' => 'updateObjectCache'
- ]
- ])
- ],
- ]
- ]);
- }
- public function fixEventShedulerPostTask() {
- DB::getPDO()->execSql(" SET GLOBAL event_scheduler='ON' ");
- }
- public function updateObjectCachePostTask() {
- DBG::log("updateObjectCachePostTask...");
- SchemaFactory::loadDefaultObject('SystemSource')->updateCache();
- SchemaFactory::loadDefaultObject('SystemObject')->updateCache();
- SchemaFactory::loadDefaultObject('SystemObjectField')->updateCache();
- UI::alert('info', "Lista obiketów zaktualizowana");
- }
- public function viewStatusUsers() {
- $nowMinus3Months = date("Y-m-d", mktime(0,0,0, date('m') - 1, date('d'), date('Y')));
- $sesUsers = DB::getPDO()->fetchAll("
- select c.ID, c.CONF_KEY, c.CONF_VAL
- from CRM_CONFIG c
- where c.CONF_KEY like 'acl_user_%_%_cache_update'
- and c.CONF_VAL > '{$nowMinus3Months}'
- ");
- $sesUsers = array_reduce( $sesUsers, function ($ret, $record) {
- // $format = "acl_user_{ID_USERS}_{ID_PROCES}_cache_update";
- list($idUser, $idProces) = explode('_', substr($record['CONF_KEY'], strlen('acl_user_'), -1 * strlen('_cache_update')));
- if (!array_key_exists($idUser, $ret)) {
- $ret[$idUser] = [
- 'idUser' => $idUser,
- 'lastUpdateAclCache' => $record['CONF_VAL'],
- 'log' => []
- ];
- } else {
- $ret[$idUser]['lastUpdateAclCache'] = ($record['CONF_VAL'] > $ret[$idUser]['lastUpdateAclCache'])
- ? $record['CONF_VAL']
- : $ret[$idUser]['lastUpdateAclCache'];
- }
- $ret[$idUser]['log'][] = [ 'ID_PROCES' => $idProces, 'data' => $record['CONF_VAL'] ];
- return $ret;
- }, [] );
- $sesUsers = array_map(function ($sesGroup) {
- return [
- 'idUser' => $sesGroup['idUser'],
- 'user' => DB::getPDO()->fetchValue("select u.ADM_ACCOUNT from ADMIN_USERS u where u.ID = {$sesGroup['idUser']}"),
- 'lastUpdateAclCache' => $sesGroup['lastUpdateAclCache'],
- 'log' => UI::h('span', [ 'style' => "color:#bbb" ], implode('<br>', array_map(function ($log) {
- return ($log['ID_PROCES'] > 0)
- ? "Filtr procesu {$log['ID_PROCES']} uruchomiony {$log['data']}"
- : "Filtr ogólny uruchomiony {$log['data']}";
- }, $sesGroup['log']))),
- ];
- }, $sesUsers);
- usort($sesUsers, function ($ua, $ub) {
- $a = $ua['lastUpdateAclCache'];
- $b = $ub['lastUpdateAclCache'];
- return ($a === $b)
- ? 0
- : ( ($a < $b)
- ? 1
- : -1
- ) ;
- });
- if ('0' == User::get('ADM_ADMIN_LEVEL')) {
- $sesUsers = array_map(function ($row) {
- $row['#'] = UI::h('div', [ 'style' => "display:inline-block", 'class' => "activateUserDebugBtn" . ( DBG::hasUserDebug($row['idUser'], User::getID()) ? ' active' : '' ) ], [
- UI::h('label', ['style' => "padding-right:6px; font-weight:normal"], "Debug"),
- UI::hButtonAjax("Włącz", "activateUserDebug", [
- 'class' => "btn btn-xs btn-default activateUserDebugBtn-activate",
- 'href' => $this->getLink('startUserDebugAjax'),
- 'data' => [ 'idUser' => $row['idUser'], 'do' => 'activate' ]
- ]),
- UI::hButtonAjax("Wyłącz", "activateUserDebug", [
- 'class' => "btn btn-xs btn-default activateUserDebugBtn-deactivate",
- 'href' => $this->getLink('startUserDebugAjax'),
- 'data' => [ 'idUser' => $row['idUser'], 'do' => 'deactivate' ]
- ]),
- ]);
- return $row;
- }, $sesUsers);
- }
- UI::table([
- 'caption' => UI::h('b', ['style' => "color:#000"], "Ostatnie logowania do aplikacji") . " <small>(update acl cache)</small>", // TODO: Aktualnie zalogowani użytkownicy
- 'rows' => $sesUsers
- ]);
- echo UI::h('style', ['type' => "text/css"], "
- .activateUserDebugBtn .activateUserDebugBtn-activate { display:inline }
- .activateUserDebugBtn .activateUserDebugBtn-deactivate { display:none }
- .activateUserDebugBtn.active .activateUserDebugBtn-activate { display:none }
- .activateUserDebugBtn.active .activateUserDebugBtn-deactivate { display:inline }
- ");
- echo UI::h('script', ['src'=>"static/vendor.js?_v=b636cab1", 'type'=>"text/javascript"]);
- echo UI::h('script', [], "
- (function (global) {
- if (!global.p5VendorJs.React) throw 'Missing p5VendorJs.React'
- if (!global.p5VendorJs.ReactDOM) throw 'Missing p5VendorJs.ReactDOM'
- if (!global.p5VendorJs.ToggleButton) throw 'Missing p5VendorJs.ToggleButton'
- if (!global.fetch) throw 'Missing global.fetch'
- var React = global.p5VendorJs.React
- var ReactDOM = global.p5VendorJs.ReactDOM
- var h = React.createElement
- function convertToReactToggle(n, activateBtn, deactivateBtn, isActive) {
- var toggleReact = document.createElement('div')
- toggleReact.style.display = 'inline-block'
- n.parentNode.insertBefore(toggleReact, n.nextSibling)
- deactivateBtn.style.display = 'none'
- activateBtn.style.display = 'none'
- function reactToggleBtnOnToggle(value) {
- if (value) {
- deactivateBtn.onclick()
- } else {
- activateBtn.onclick()
- }
- render_reactToggleBtn(!value)
- }
- function render_reactToggleBtn(state) {
- ReactDOM.render(
- h(global.p5VendorJs.ToggleButton, {
- value: state,
- onToggle: reactToggleBtnOnToggle
- })
- , toggleReact
- )
- }
- render_reactToggleBtn(isActive)
- }
- var toggles = document.querySelectorAll('.activateUserDebugBtn')
- for (var i = 0; i < toggles.length; i++) {
- var btns = toggles[i].querySelectorAll('a')
- if (2 !== btns.length) contiune;
- var activateBtn = btns[0]
- var deactivateBtn = btns[1]
- convertToReactToggle(toggles[i], activateBtn, deactivateBtn, toggles[i].classList.contains('active'))
- }
- })(window)
- ");
- UI::hButtonAjaxOnResponse("activateUserDebug", /* payload, n */ "
- p5UI__notifyAjaxCallback(payload)
- // console.log('activateUserDebug :: payload', payload)
- if ('success' !== payload.type) return false
- if (payload.body && 'active' in payload.body) {
- if (payload.body.active) {
- n.parentNode.classList.add('active')
- } else {
- n.parentNode.classList.remove('active')
- }
- }
- ");
- }
- public function startUserDebugAjaxAction() {
- Response::sendTryCatchJson(array($this, 'startUserDebugAjax'), $_POST);
- }
- public function startUserDebugAjax($args) {
- if ('0' !== (string)User::get('ADM_ADMIN_LEVEL')) throw new Exception("Access Denied");
- $idUser = V::get('idUser', 0, $args);
- if ($idUser <= 0) throw new Exception("Missing idUser");
- $do = V::get('do', 0, $args);
- if (!in_array($do, ['activate', 'deactivate'])) throw new Exception("Missing do");
- $hasDebug = DBG::hasUserDebug($idUser, User::getID());
- switch ($do) {
- case 'activate': DBG::startUserDebug($idUser, User::getID()); break;
- case 'deactivate': DBG::stopUserDebug($idUser, User::getID()); break;
- }
- return [
- 'type' => 'success',
- '__args' => $args,
- '__$hasDebug' => $hasDebug,
- 'body' => [
- 'active' => DBG::hasUserDebug($idUser, User::getID())
- ]
- ];
- }
- }
|