Parcourir la source

fixed code style in Status

Piotr Labudda il y a 8 ans
Parent
commit
3fbd69c463
1 fichiers modifiés avec 206 ajouts et 205 suppressions
  1. 206 205
      SE/se-lib/Route/Status.php

+ 206 - 205
SE/se-lib/Route/Status.php

@@ -6,224 +6,225 @@ Lib::loadClass('Response');
 
 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();
+	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();
-      }
+			$this->viewStatusDatabase();
 
-      // 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();
-  }
+			if (in_array(User::get('ADM_ADMIN_LEVEL'), ['0', '1'])) {
+				$this->viewStatusUsers();
+			}
 
-  public function viewStatusDatabase() {
-    if (1 == V::get('event_sheduler_on', '', $_POST)) {
-      $this->fixEventSheduler();
-    }
+			// 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
+		$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' ");
-  }
+		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
-          ) ;
-    });
-    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
+	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 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)
-        }
+				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() {
+				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");
+		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())
-      ]
-    ];
+		$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())
+			]
+		];
 	}
 
 }