| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- Lib::loadClass('RouteBase');
- Lib::loadClass('UI');
- 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();
- $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() {
- if (1 == V::get('event_sheduler_on', '', $_POST)) {
- $this->fixEventSheduler();
- }
- $dbEvents = DB::getPDO()->fetchFirst(" SHOW VARIABLES WHERE VARIABLE_NAME = 'event_scheduler' ");
- // DBG::nicePrint($dbEvents, '$dbEvents');
- // [Variable_name] => event_scheduler
- // [Value] => ON
- 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' => [
- 'event_sheduler_on' => 1
- ]
- ])
- ]
- ]
- ]);
- }
- public function fixEventSheduler() {
- DB::getPDO()->execSql(" SET GLOBAL event_scheduler='ON' ");
- }
- 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
- ) ;
- });
- 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
- ]);
- }
- }
|