src.dualinventive.com/mtinfo/dist/webroot/rc-4.05/include/fetch_info_live.php

474 lines
19 KiB
PHP

<?php
/** \file include\fetch_info_live.php
* \brief DI webinterface fetch info php => javascript needed for the live report
* \author Rob Schalken, Core|Vision
* \version 1.0
* \date 17-10-2008
*
*/
// Read only => Lock as less as possible
$_PAGE_INFO['session_read_only'] = TRUE;
/*
* Required pages
*/
require_once("core_xml.php");
// Extra right check
if ((db_ver_right_user($_SESSION[$_PAGE_INFO['id']]['login']['user']['id'], "login")) &&
(db_ver_rights_user_one_valid($_SESSION[$_PAGE_INFO['id']]['login']['user']['id'], "menu:rapportages&productie"))) {
// Retrieve ini file skin
$ini_file = get_all_files($_PAGE_INFO['base_path'] . SKIN_DIR . $_SESSION[$_PAGE_INFO['id']]['skin'] . "/", array("ini"));
$_PAGE_INFO['ini'] = parse_ini_file($ini_file[0], true);
/*
* Get online users
*/
if (isset($_POST['online_users'])) {
// Initial values
$sessions = array();
$user_info = array();
$valid_customers = array();
// Get all company down the pyramid
$customers = db_search_customers();
// Get all ids
if (is_array($customers)) {
foreach($customers as $customer) {
array_push($valid_customers, $customer['id']);
}
}
// Read session file content from database
$session_info = db_fetch_data("SELECT * FROM session");
if (is_array($session_info)) {
foreach($session_info as $session) {
// Find non-session char
if (stristr($session['id'], "_") === FALSE) {
// Decode session file content => Puts it in $_SESSION
session_decode($session['data']);
// Parse session
if (is_array($_SESSION)) {
foreach($_SESSION as $key => $info) {
// valid customer?
if (in_array($info['login']['customer']['id'], $valid_customers)) {
// Session accessed last 10 seconds
// Skip extended menu
if (($info['last_access'] > time()-10) && (!isset($info['extended_menu']))) {
// No duplicated sessions
if (!in_array($key, $sessions)) {
// Store session
array_push($sessions, $key);
// Store user
array_push($user_info, array('id' => $info['login']['user']['id'],
'customer' => $info['login']['customer']['id'],
'page' => $info['MTinfo_menu'],
'page_title' => $info['title'],
'last_access' => $info['last_access'],
'session' => $key,
'session_org' => (!isset($info['original_id'])) ? $key : $info['original_id']));
}
}
}
}
}
}
}
}
// Build table
echo "<table class=\"sortable\" id=\"online_users\">";
echo "<tr>";
echo "<th>" . _("Username") . "</th>";
echo "<th>" . _("Company") . "</th>";
echo "<th>" . _("Mobile number") . "</th>";
echo "<th>" . _("Page menu") . "</th>";
echo "<th>" . _("Session ID") . "</th>";
echo "<th>" . _("Session start") . "</th>";
echo "<th>" . _("Last access") . "</th>";
echo "</tr>";
if (!empty($user_info)) {
// Intial values
$count = 0;
$collected = array();
foreach($user_info as $user) {
// Get user/customer info
$c = db_fetch_customer($user['customer'], 1);
$u = db_fetch_user($user['id'], "", 1);
$s = db_fetch("log_gebruiker", "tijd,formdata", "gebruiker=" . $user['id'] . " AND menu='login' and session_id like '%_" . $user['session_org'] . "'");
// Get user info
$ip = "";
if (is_array($s)) {
$unserial_s = unserialize($s[0]['formdata']);
// Get correct $_SERVER value
$ip_settings = (isset($unserial_s['HTTP_X_FORWARDED_FOR'])) ? $unserial_s['HTTP_X_FORWARDED_FOR'] : $unserial_s['REMOTE_ADDR'];
$ip = " (" . $ip_settings . ")";
}
// Collect info
array_push($collected, array('username' => getUser($user['id']),
'customer' => $c['bedrijfsnaam'],
'mobile_number' => $u['mobielnr'],
'page' => $user['page_title'] ? $user['page_title'] : _("h:" . $user['page']),
'session' => $user['session'] . $ip,
'start_session' => ((is_array($s)) ? $s[0]['tijd'] : "-"),
'last_accessed' => convert_datetime($user['last_access'], TRUE)));
}
// Order
$collected = array_sort($collected, $_POST['order'], SORT_STRING, ($_POST['order_style'] == "SORT_DESC" ? SORT_DESC : SORT_ASC));
foreach($collected as $collected_item) {
// Create row
echo "<tr id=\"row" . ($count % 2) . "\">";
foreach($collected_item as $key => $item) {
echo "<td>" . ucfirst($item) . "</td>";
}
echo "</tr>";
// Increment counter
$count++;
}
}
echo "</table>";
}
/*
* Get last equipment status
*/
if (isset($_POST['status_equipment'])) {
// Initial values
$session = array();
$log_rt_info = array();
$collected = array();
// Get all equipment (down the pyramid)
$all_equipment = db_search_lances($_GET['device']);
if (is_array($all_equipment)) {
foreach($all_equipment as $equipment) {
// Get log realtime info
$e = db_fetch_cache($equipment['id'], "status");
// Catch exceptions
if (is_array($e)) {
// Store info
$log_rt = array('zkl' => $equipment['id'], 't' => $e['t'], 'interpreter_status' => $e);
array_push($log_rt_info, $log_rt);
}
}
}
// Build table
echo "<table class=\"sortable\" id=\"online_equipment\">";
echo "<tr>";
echo "<th>" . _("ID code") . " " . ucwords($_SESSION[$_PAGE_INFO['id']]['skin_name']) . "</th>";
echo "<th>" . _("ID code") . " " . _("owner") . "</th>";
// Device can measure?
if (db_check_system_device_capabilities($_GET['device'],array("meting"))) {
echo "<th>" . _("Measurement") . "</th>";
}
// Device can switch?
if (db_check_system_device_capabilities($_GET['device'],array("kortsluiting schakelen"))) {
echo "<th>" . ucfirst(_("switch")) . "</th>";
}
// Detection?
if (db_check_system_device_capabilities($_GET['device'],array("meting"))) {
echo "<th>" . ucfirst(_("detection")) . "</th>";
}
echo "<th style=\"width: 10.5ex;\">" . _("Last update") . "</th>";
echo "</tr>";
if (!empty($log_rt_info)) {
// Intial values
$count = 0;
// Collect info
foreach($log_rt_info as $log_rt) {
$e = db_fetch_lance($log_rt['zkl'], "", 1);
array_push($collected, array('idcode_di' => $e['serienr'],
'idcode_owner' => $e['idcode'],
'log_rt' => $log_rt,
'last_update' => $log_rt['t']));
}
// Order
switch($_POST['order']) {
case "last_update":
$collected = array_sort($collected, $_POST['order'], SORT_NUMERIC, ($_POST['order_style'] == "SORT_DESC" ? SORT_DESC : SORT_ASC));
break;
default:
$collected = array_sort($collected, $_POST['order'], SORT_STRING, ($_POST['order_style'] == "SORT_DESC" ? SORT_DESC : SORT_ASC));
break;
}
foreach($collected as $collected_item) {
// Create row
echo "<tr id=\"row" . ($count % 2) . "\">";
foreach($collected_item as $key => $item) {
switch($key) {
case "log_rt";
// Device can measure?
if (db_check_system_device_capabilities($_GET['device'],array("meting"))) {
if ($item['interpreter_status']['detection']['active']) {
echo "<td style=\"background-color:green;color:white\">ON</td>";
}
else {
echo "<td style=\"background-color:red;color:white\">OFF</td>";
}
}
// Device can switch?
if (db_check_system_device_capabilities($_GET['device'],array("kortsluiting schakelen"))) {
if (!$item['interpreter_status']['system']['error']['sw1w']) {
if ($item['interpreter_status']['switch3000']['on']) {
echo "<td style=\"background-color:green;color:white\">ON</td>";
}
else {
echo "<td style=\"background-color:red;color:white\">OFF</td>";
}
}
else {
echo "<td style=\"background-color:red;color:white\">UNKNOWN</td>";
}
}
// Detection?
if (db_check_system_device_capabilities($_GET['device'],array("meting"))) {
$condition = array();
array_push($condition, array("condition" => "kortsluiting", "value" => $item['interpreter_status']['detection']['ok']));
// Check switch status
if (!is_array($item['interpreter_status']['switch3000'])) {
// ZKL 3000
array_push($condition, array("condition" => "relais", "value" => !$item['interpreter_status']['relay']['enabled']));
}
else {
// ZKL 3000 + SWITCH 3000 (Check also the communication)
array_push($condition, array("condition" => "relais", "value" => ((!$item['interpreter_status']['system']['error']['sw1w']) ? $item['interpreter_status']['switch3000']['on'] : FALSE)));
}
// Get current status
$sts = db_fetch_system_device_status($_GET['device'], 'en', $condition, "");
if ( $sts !== false && $sts['status'] == "ok") {
echo "<td style=\"background-color:green;color:white\">OK</td>";
}
else {
echo "<td style=\"background-color:red;color:white\">NOK</td>";
}
}
break;
case "last_update";
// Timestamp to old?
if ($item > time()-(15 * 60)) {
echo "<td>" . convert_datetime($item, TRUE) . "</td>";
}
else {
echo "<td style=\"background-color:red;color:white\">" . convert_datetime($item, TRUE) . "</td>";
}
break;
default:
echo "<td>" . ucfirst($item) . "</td>";
break;
}
}
echo "</tr>";
// Increment counter
$count++;
}
}
else {
// Create empty row
echo "<tr>";
echo "<td>-</td>";
echo "<td>-</td>";
echo "<td>-</td>";
// Device can measure?
if (db_check_system_device_capabilities($_GET['device'],array("meting"))) {
echo "<td>-</td>";
}
// Device can switch?
if (db_check_system_device_capabilities($_GET['device'],array("kortsluiting schakelen"))) {
echo "<td>-</td>";
}
// Detection?
if (db_check_system_device_capabilities($_GET['device'],array("meting"))) {
echo "<td>-</td>";
}
echo "</tr>";
}
echo "</table>";
}
/*
* Get project status
*/
if (isset($_POST['projects'])) {
// Initial values
$session = array();
$collected = array();
// Get all unfinished projects
$all_projects = db_search_projects($_GET['project_type']);
// Build table
echo "<table class=\"sortable\" id=\"projects\">";
echo "<tr>";
echo "<th>" . _("Name") . "</th>";
echo "<th>" . _("Company") . "</th>";
if (strtolower($_GET['project_type']) == "rc") {
echo "<th>" . _("Design status") . "</th>";
}
echo "<th>" . _("Plan status") . "</th>";
echo "<th>" . _("Status") . "</th>";
if (strtolower($_GET['project_type']) == "rc") {
echo "<th style=\"width: 10.5ex\">" . _("First user planned") . "</th>";
}
echo "</tr>";
if (!empty($all_projects)) {
// Intial values
$count = 0;
$collected = array();
foreach($all_projects as $project) {
$next_planned = "";
$next_user = "";
// Get user
if (strtoupper($project['type']) == "RC") {
$project_users = db_fetch_data("SELECT project_gebruiker.* FROM project_gebruiker,project WHERE (project.id=" . $project['id'] . " or project.parent=" . $project['id'] . ") AND project_gebruiker.project=project.id AND project_gebruiker.rol='schakelen'");
if (!empty($project_users)) {
foreach($project_users as $user) {
if (!strlen($next_planned)) {
$next_planned = convert_datetime($user['begin']);
$next_user = getUser($user['gebruiker']);
}
else if ((convert_datetime($user['begin'])) < $next_planned) {
$next_planned = convert_datetime($user['begin']);
$next_user = getUser($user['gebruiker']);
}
}
}
}
// Get company
$project_company = db_fetch_customer($project['klant'], 1);
// Skip periods
array_push($collected, array(naam => $project['naam'],
company => $project_company['bedrijfsnaam'],
ostatus => ((strtoupper($project['type']) != "RC") ? "-" : _($project['ostatus'])),
pstatus => (((strtoupper($project['type']) != "RC") && ($project['pstatus'] != "concept")) ? _("gevalideerd") : _($project['pstatus'])),
sstatus => (((strtoupper($project['type']) != "RC") && ($project['pstatus'] != "concept")) ? _("vrijgegeven") : _($project['sstatus'])),
next_planned => (strlen($next_planned)) ? $next_planned : "-",
next_user => $next_user));
}
// Order
switch($_POST['order']) {
case "ostatus":
// Only applicable for rc projects
if (strtolower($_GET['project_type']) == "rc") {
$collected = array_sort($collected, $_POST['order'], SORT_STRING, ($_POST['order_style'] == "SORT_DESC" ? SORT_DESC : SORT_ASC));
}
else {
$collected = array_sort($collected, "naam", SORT_STRING, ($_POST['order_style'] == "SORT_DESC" ? SORT_DESC : SORT_ASC));
}
break;
case "next_planned":
// Only applicable for rc projects
if (strtolower($_GET['project_type']) == "rc") {
$collected = array_sort($collected, $_POST['order'], SORT_NUMERIC, ($_POST['order_style'] == "SORT_DESC" ? SORT_DESC : SORT_ASC));
}
else {
$collected = array_sort($collected, "naam", SORT_STRING, ($_POST['order_style'] == "SORT_DESC" ? SORT_DESC : SORT_ASC));
}
break;
default:
$collected = array_sort($collected, $_POST['order'], SORT_STRING, ($_POST['order_style'] == "SORT_DESC" ? SORT_DESC : SORT_ASC));
break;
}
foreach($collected as $project) {
// Create row
echo "<tr id=\"row" . ($count % 2) . "\">";
foreach($project as $key => $item) {
switch($key) {
case "ostatus":
// Only applicable for rc projects
if (strtolower($_GET['project_type']) == "rc") {
echo "<td>" . ucfirst($item) . "</td>";
}
break;
case "sstatus":
if (strtoupper($item) == strtoupper(_("vrijgegeven"))) {
echo "<td style=\"background-color:green;color:white;\">" . ucfirst($item) . "</td>";
}
else {
echo "<td style=\"background-color:red;color:white;\">" . ucfirst($item) . "</td>";
}
break;
case "next_planned":
// Only applicable for rc projects
if (strtolower($_GET['project_type']) == "rc") {
echo "<td>" . (($item != "-") ? convert_datetime($item, TRUE) : "-") . (($item != "-") ? "<br>(" . $project['next_user'] . ")" : "") . "</td>";
}
break;
case "next_user":
break;
default:
if (strlen($item) > 20) {
echo "<td onmouseover=\"Tip('" . ucfirst($item) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\" onmouseout=\"UnTip();\">" . ucfirst(substr($item, 0, 20)) . "..</td>";
}
else {
echo "<td>" . ucfirst($item) . "</td>";
}
break;
}
}
echo "</tr>";
// Increment counter
$count++;
}
}
else {
// Create empty row
echo "<tr>";
echo "<td>-</td>";
echo "<td>-</td>";
echo "<td>-</td>";
echo "<td>-</td>";
echo "</tr>";
}
echo "</table>";
}
}
else {
// Display logout message
$_SESSION[$_PAGE_INFO['id']]['login_info']['errormsg'] = _("No valid rights");
// Redirect page back to login page
echo "<script type=\"text/javascript\">\n";
echo "location.href='/?id=" . $_PAGE_INFO['id'] . "&href=" . PAGE_LOGIN. "'\n";
echo "</script>\n";
}
?>