Status.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('UI');
  4. class Route_Status extends RouteBase {
  5. public function defaultAction() {
  6. UI::gora();
  7. UI::startTag('div', ['class' => "container"]);
  8. echo UI::h('h1', [], [
  9. UI::h('a', ['href'=>"index.php"], "SE"),
  10. " &raquo; ",
  11. " Status systemu procesy5"
  12. ]);
  13. try {
  14. DB::getPDO();
  15. $this->viewStatusDatabase();
  16. if (in_array(User::get('ADM_ADMIN_LEVEL'), ['0', '1'])) {
  17. $this->viewStatusUsers();
  18. }
  19. // UI::table([
  20. // 'caption' => 'Baza danych',
  21. // 'rows' => DB::getPDO()->fetchAll(" SHOW VARIABLES ")
  22. // ]);
  23. } catch (Exception $e) {
  24. UI::alert('danger', $e->getMessage());
  25. }
  26. UI::endTag('div');// .container
  27. UI::dol();
  28. }
  29. public function viewStatusDatabase() {
  30. if (1 == V::get('event_sheduler_on', '', $_POST)) {
  31. $this->fixEventSheduler();
  32. }
  33. $dbEvents = DB::getPDO()->fetchFirst(" SHOW VARIABLES WHERE VARIABLE_NAME = 'event_scheduler' ");
  34. // DBG::nicePrint($dbEvents, '$dbEvents');
  35. // [Variable_name] => event_scheduler
  36. // [Value] => ON
  37. UI::table([
  38. 'caption' => UI::h('b', ['style' => "color:#000"], 'Baza danych'),
  39. 'rows' => [
  40. [
  41. 'nazwa' => 'Event Scheduler (generowanie Grafika, itp.)',
  42. 'wartość' => ('ON' == $dbEvents['Value'])
  43. ? UI::h('span', ['class' => "label label-success"], "ON")
  44. : UI::h('span', ['class' => "label label-danger"], "OFF"),
  45. '#' => UI::hButtonPost("Włącz", [
  46. 'class' => "btn btn-xs btn-default",
  47. 'data' => [
  48. 'event_sheduler_on' => 1
  49. ]
  50. ])
  51. ]
  52. ]
  53. ]);
  54. }
  55. public function fixEventSheduler() {
  56. DB::getPDO()->execSql(" SET GLOBAL event_scheduler='ON' ");
  57. }
  58. public function viewStatusUsers() {
  59. $nowMinus3Months = date("Y-m-d", mktime(0,0,0, date('m') - 1, date('d'), date('Y')));
  60. $sesUsers = DB::getPDO()->fetchAll("
  61. select c.ID, c.CONF_KEY, c.CONF_VAL
  62. from CRM_CONFIG c
  63. where c.CONF_KEY like 'acl_user_%_%_cache_update'
  64. and c.CONF_VAL > '{$nowMinus3Months}'
  65. ");
  66. $sesUsers = array_reduce( $sesUsers, function ($ret, $record) {
  67. // $format = "acl_user_{ID_USERS}_{ID_PROCES}_cache_update";
  68. list($idUser, $idProces) = explode('_', substr($record['CONF_KEY'], strlen('acl_user_'), -1 * strlen('_cache_update')));
  69. if (!array_key_exists($idUser, $ret)) {
  70. $ret[$idUser] = [
  71. 'idUser' => $idUser,
  72. 'lastUpdateAclCache' => $record['CONF_VAL'],
  73. 'log' => []
  74. ];
  75. } else {
  76. $ret[$idUser]['lastUpdateAclCache'] = ($record['CONF_VAL'] > $ret[$idUser]['lastUpdateAclCache'])
  77. ? $record['CONF_VAL']
  78. : $ret[$idUser]['lastUpdateAclCache'];
  79. }
  80. $ret[$idUser]['log'][] = [ 'ID_PROCES' => $idProces, 'data' => $record['CONF_VAL'] ];
  81. return $ret;
  82. }, [] );
  83. $sesUsers = array_map(function ($sesGroup) {
  84. return [
  85. 'idUser' => $sesGroup['idUser'],
  86. 'user' => DB::getPDO()->fetchValue("select u.ADM_ACCOUNT from ADMIN_USERS u where u.ID = {$sesGroup['idUser']}"),
  87. 'lastUpdateAclCache' => $sesGroup['lastUpdateAclCache'],
  88. 'log' => UI::h('span', [ 'style' => "color:#bbb" ], implode('<br>', array_map(function ($log) {
  89. return ($log['ID_PROCES'] > 0)
  90. ? "Filtr procesu {$log['ID_PROCES']} uruchomiony {$log['data']}"
  91. : "Filtr ogólny uruchomiony {$log['data']}";
  92. }, $sesGroup['log']))),
  93. ];
  94. }, $sesUsers);
  95. usort($sesUsers, function ($ua, $ub) {
  96. $a = $ua['lastUpdateAclCache'];
  97. $b = $ub['lastUpdateAclCache'];
  98. return ($a === $b)
  99. ? 0
  100. : ( ($a < $b)
  101. ? 1
  102. : -1
  103. ) ;
  104. });
  105. UI::table([
  106. 'caption' => UI::h('b', ['style' => "color:#000"], "Ostatnie logowania do aplikacji") . " <small>(update acl cache)</small>", // TODO: Aktualnie zalogowani użytkownicy
  107. 'rows' => $sesUsers
  108. ]);
  109. }
  110. }