src.dualinventive.com/mtinfo/dist/webroot/rc-4.05/scripts/page/menu_rt_info.php

493 lines
19 KiB
PHP

<?php
/** \file scripts\page\menu_rt_info.php
* \brief DI webinterface menu rt info
* \author Rob Schalken, Core|Vision
* \version 1.0
* \date 17-10-2008
*
* This file handles the second line info for the realtime status
*/
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n";
echo "<html lang=\"" . $_SESSION[$_PAGE_INFO['id']]['i18n'] . "\">\n\n";
echo "<head>\n";
echo "<script type=\"text/javascript\" src=\"" . JAVA_DIR . "java.js\"></script>\n";
echo "<script type=\"text/javascript\" src=\"" . JAVA_DIR . "xmlhttp_data.js\"></script>\n";
if (!is_tablet()) {
echo "<link href=\"" . CSS_DIR . "framework.css\" rel=\"stylesheet\" type=\"text/css\">\n";
}
else {
echo "<link href=\"" . CSS_DIR . "framework.css\" rel=\"stylesheet\" type=\"text/css\">\n";
echo "<link href=\"" . CSS_DIR . "framework_tablet.css\" rel=\"stylesheet\" type=\"text/css\">\n";
}
echo "<link href=\"" . CSS_DIR . "rtstatus.css\" rel=\"stylesheet\" type=\"text/css\">\n";
echo "<style type=\"text/css\">";
echo "body { background:white }";
echo "</style>";
echo "</head>\n";
echo "<body>\n";
echo "<div id=\"content_menu\">\n";
?>
<script type="text/javascript">
// global var
var equipment = new Array();
var TcpTimeout = (<?php echo TCP_TIMEOUT; ?> * 1000);
// Add line to rt status
function addline(icon, warning, idcode, info, time, detection) {
// local var
var class_id = '';
var color = '';
// Define background color
if (detection != undefined) {
switch(icon) {
case 'ok':
case 'ok_batt':
class_id = 'popup_cell_normal';
break;
case 'nok':
case 'nok_batt':
class_id = 'popup_cell_error';
break;
default:
if (!warning && info.search('<?PHP echo _("Sleep Mode") ?>') == -1) {
color = 'background:white;';
}
else {
color = 'background:yellow;';
}
break;
}
}
else {
if (!warning && info.search('<?PHP echo _("Sleep Mode") ?>') == -1) {
color = 'background:white;';
}
else {
color = 'background:yellow;';
}
}
// Adapt iframe height (Max 4 elements)
adapted = 0;
if ((parseInt(parent.getElement('iframe_info').height)) < (4 * 18)) {
parent.getElement('iframe_info').height = ((parseInt(parent.getElement('iframe_info').height)) + 18).toString();
// set adapted flag
adapted = 1;
}
getElement('content_menu').innerHTML = '<div class="' + class_id + '" style="' + color + 'overflow:hidden;height:15px;border:solid;border-color:grey;border-width:1px;margin-bottom:1px">' + '&nbsp;' + time + '&nbsp;&nbsp;&nbsp;' + idcode + '&nbsp;' + info + '</div>' + getElement('content_menu').innerHTML;
// Adapt map size?
if ((adapted) && (getURLParam('extended_view'))) {
parent.ContentSize();
}
}
// Callback function
var func_rt_info = function (zkl_status) {
// local var
var found;
var changed;
var info;
var time;
var server_time = '';
var currentTimer;
var startTimer;
var SleepMode;
try {
// Do something with the data. Check our 'magic-ID'. If it passes,
var offset = zkl_status.search("\/[*]ZKLsu1.0[*]\/");
// Magic code available?
if (offset != -1) {
// Evaluate result
zkl_status = eval(zkl_status.substring(offset));
// Handle received data
for (i in zkl_status) {
// Valid serial/idcode?
if ((parseInt(zkl_status[i].s_serialnr) > 0) && (zkl_status[i].s_idcode.length > 0)) {
// Reset var
info = '';
found = 0;
changed = 0;
warning = 0;
SleepMode = 0;
currentTimer = new Date();
startTimer = new Date();
// Get timestamp
time = zkl_status[i].s_time;
// Already added to equipment array?
for (j=0; ((found == 0) && (changed == 0)); j++) {
if ((typeof(equipment[j]) == 'undefined') || (equipment[j].s_serialnr == zkl_status[i].s_serialnr)) {
if (typeof(equipment[j]) != 'undefined') {
// Existing equipment
found = 1;
// Restore heartbeat variables
zkl_status[i].hbtimeout = equipment[j].hbtimeout;
zkl_status[i].hbhandled = equipment[j].hbhandled;
}
else {
// New equipment
changed = 1;
// Store heartbeat variables
zkl_status[i].hbtimeout = startTimer;
zkl_status[i].hbhandled = 0;
}
// Store heartbeat variables
startTimer = zkl_status[i].hbtimeout;
zkl_status[i].s_warning = "";
if (zkl_status[i].s_icon.split("&").length > 1) {
// Determine warning(s)
zkl_status[i].s_warning = (zkl_status[i].s_icon.split("&"))[1];
if ((changed == 0) &&
((equipment[j].s_warning == undefined) ||
((equipment[j].s_warning.search("sleepmode") != -1) && (zkl_status[i].s_warning.search("sleepmode") == -1)) ||
((equipment[j].s_warning.search("sleepmode") == -1) && (zkl_status[i].s_warning.search("sleepmode") != -1)))) {
// Set flag
changed = 1;
}
}
else if ((changed == 0) && (equipment[j].s_warning != undefined) && (equipment[j].s_warning.length > 0)) {
// Set flag
changed = 1;
}
// Remove warning(s) from icon
zkl_status[i].s_icon = (zkl_status[i].s_icon.split("&"))[0];
// Change in detection status
if ((changed == 0) && (equipment[j].s_icon != zkl_status[i].s_icon)) {
// Set flag
changed = 1;
}
// Available/unavailable
switch(zkl_status[i].s_icon) {
case 'ok':
case 'ok_batt':
// Detection?
if (zkl_status[i].s_detection == undefined) {
info += '<?PHP echo _("Available"); ?>';
}
break;
case 'nok':
case 'nok_batt':
// Detection?
if (zkl_status[i].s_detection == undefined) {
info += '<?PHP echo _("Available"); ?>';
}
break;
default:
// Ask server time when changed
if ((changed == 1) || (zkl_status[i].hbhandled == 0)) {
if ((zkl_status[i].s_warning != undefined) && (zkl_status[i].s_warning.search("sleepmode") != -1)) {
info += '<?PHP echo _("Sleep Mode") ?>';
// Sleepmode active
SleepMode = 1;
}
else {
info += '<?PHP echo _("Unavailable") ?>';
}
// Server time already asked?
if (server_time.length == 0) {
server_time = xmlhttp_data('','', 0,'<?php echo $_SESSION[$_PAGE_INFO['id']]['base']; ?>','<?php echo $_PAGE_INFO['id']; ?>','&get_datetime=1','&redirect=include/fetch_info.php');
}
time = server_time;
}
break;
}
if ((!SleepMode) && (zkl_status[i].s_icon != 'error')) {
// Measurement?
if (zkl_status[i].s_active != undefined) {
// Change in measurement on/off
if ((changed == 0) && (equipment[j].s_active != zkl_status[i].s_active)) {
// Set flag
changed = 1;
}
switch(zkl_status[i].s_active) {
case 'ACTIVE':
info += '<?PHP echo _("Measurement") . ": " . _("On"); ?>';
break;
case '!INACTIVE':
info += '<?PHP echo _("Measurement") . ": " . _("Off"); ?>';
break;
default:
break;
}
}
// Detection
switch(zkl_status[i].s_icon) {
case 'ok':
case 'ok_batt':
// Detection?
if (zkl_status[i].s_detection != undefined) {
info += '<?PHP echo ", " . ucfirst(_("detection")); ?>' + ': ' + zkl_status[i].s_detection.toUpperCase();
}
break;
case 'nok':
case 'nok_batt':
// Detection?
if (zkl_status[i].s_detection != undefined) {
info += '<?PHP echo ", " . ucfirst(_("detection")); ?>' + ': ' + zkl_status[i].s_detection.substr(1).toUpperCase();
}
break;
default:
break;
}
// Switch available?
if (zkl_status[i].s_switch != undefined) {
// Change in switch availability
if (changed == 0) {
if (equipment[j].s_switch != zkl_status[i].s_switch) {
// Set flag
changed = 1;
}
else if ((zkl_status[i].s_warning != equipment[j].s_warning) &&
(((zkl_status[i].s_warning.toUpperCase().search("SWITCH") != -1) && (equipment[j].s_warning.toUpperCase().search("SWITCH") == -1)) ||
((zkl_status[i].s_warning.toUpperCase().search("SWITCH") == -1) && (equipment[j].s_warning.toUpperCase().search("SWITCH") != -1)))) {
// Set flag
changed = 1;
}
}
if ((zkl_status[i].s_warning != undefined) && (zkl_status[i].s_warning.toUpperCase().search("SWITCH") != -1)) {
info += '<?PHP echo ", " . _("Switch") . ": " . _("Unknown"); ?>';
}
else {
switch(zkl_status[i].s_switch) {
case 'ACTIVE':
info += '<?PHP echo ", " . _("Switch") . ": " . _("On"); ?>';
break;
case '!INACTIVE':
info += '<?PHP echo ", " . _("Switch") . ": " . _("Off"); ?>';
break;
default:
break;
}
}
}
// Key switch?
if (zkl_status[i].s_sleutelschakelaar != undefined) {
// Change in key switch status
if ((changed == 0) && (equipment[j].s_sleutelschakelaar != zkl_status[i].s_sleutelschakelaar)) {
// Set flag
changed = 1;
}
switch(zkl_status[i].s_sleutelschakelaar) {
case '!SW_ACTIVE':
info += '<?PHP echo ", " . _("Key switch") . ": " . _("On (overruled)"); ?>';
break;
case '!SW_INACTIVE':
info += '<?PHP echo ", " . _("Key switch") . ": " . _("Off (overruled)"); ?>';
break;
case 'SW_OPER':
info += '<?PHP echo ", " . _("Key switch") . ": " . _("Operational"); ?>';
break;
default:
break;
}
}
var info_temp_onboard = "";
var info_temp_extern = "";
// Temperature on-board (only in extended view, unless a temperature alarm is set _and_ warning active)
if ((zkl_status[i].s_temp_onboard != undefined) && (zkl_status[i].s_temp_onboard.length > 0)) {
// Change in temp status
if ((changed == 0) && ((equipment[j].s_warning.search("temp_ext2") != -1) != (zkl_status[i].s_warning.search("temp_ext2") != -1))) {
// Set flag
changed = 1;
}
// Remove alarm threshold
var temp_info = (zkl_status[i].s_temp_onboard.split(':'));
var temp_onboard_display = temp_info[0];
var temp_onboard_alarm = '';
// Alarm? Remove '!'
if (temp_onboard_display.charAt(0) == '!') {
temp_onboard_display = temp_onboard_display.substring(1);
warning = 1;
// Status (only provided with an alarm is set and only displayed when in alarm state)
if( temp_info.length > 1 ) {
temp_onboard_alarm = ' ' + temp_info[1].split(',')[0].trim() + ': ';
}
}
if (getURLParam('extended_view') || (zkl_status[i].s_warning.search("temp_ext2") != -1)) {
info_temp_onboard = '<?PHP echo ", " . ucfirst(_("temperature")); ?>' + ' (' + zkl_status[i].nm_temp_onboard + '): ' + temp_onboard_alarm + temp_onboard_display;
}
}
// Temperature external (only in extended view, unless a temperature alarm is set _and_ warning active)
if ((zkl_status[i].s_temp_extern != undefined) && (zkl_status[i].s_temp_extern.length > 0)) {
// Change in temp status
if ((changed == 0) && ((equipment[j].s_warning.search("temp_ext1") != -1) != (zkl_status[i].s_warning.search("temp_ext1") != -1))) {
// Set flag
changed = 1;
}
// Remove alarm threshold
var temp_info = (zkl_status[i].s_temp_extern.split(':'));
var temp_extern_display = temp_info[0];
var temp_extern_alarm = '';
// Alarm? Remove '!'
if (temp_extern_display.charAt(0) == '!') {
temp_extern_display = temp_extern_display.substring(1);
warning = 1;
// Status (only provided with an alarm is set and only displayed when in alarm state)
if( temp_info.length > 1 ) {
temp_extern_alarm = ' ' + temp_info[1].split(',')[0].trim() + ': ';
}
}
if (getURLParam('extended_view') || (zkl_status[i].s_warning.search("temp_ext1") != -1)) {
info_temp_extern = '<?PHP echo ", " . ucfirst(_("temperature")); ?>' + ' (' + zkl_status[i].nm_temp_extern + '): ' + temp_extern_alarm + temp_extern_display;
}
}
if( zkl_status[i].sw_temp )
info += info_temp_extern + info_temp_onboard;
else
info += info_temp_onboard + info_temp_extern;
// battery changes (only in extended view)
if (getURLParam('extended_view')) {
var batt_valid = 1;
var batt_counter = 0;
do {
// Increment battery counter
batt_counter++;
// Valid battery?
if (zkl_status[i]['s_batt' + batt_counter] == undefined) {
batt_valid = 0;
}
// Change in battery status?
else {
if ((changed == 0) && (equipment[j]['s_batt' + batt_counter] != zkl_status[i]['s_batt' + batt_counter])) {
// Set flag
changed = 1;
}
var batt_status = zkl_status[i]['s_batt' + batt_counter].split(':');
batt_status = batt_status[batt_status.length - 1].trim();
if( batt_status.charAt(0) == '!' ) batt_status = batt_status.substring(1);
info += '<?PHP echo ", " . _("Battery"); ?>' + ' ' + batt_counter + ': ' + batt_status;
}
}
while (batt_valid);
}
}
if ((changed > 0) || (zkl_status[i].hbhandled == 0)) {
// Could be waiting for heartbeat sync
if ((zkl_status[i].hbhandled == 1) || (zkl_status[i].s_icon != 'error') || ((currentTimer.getTime() - startTimer.getTime()) >= TcpTimeout)) {
// Add line to rt status
addline(zkl_status[i].s_icon, warning, zkl_status[i].s_idcode, info, time, zkl_status[i].s_detection);
// set flag
zkl_status[i].hbhandled = 1;
}
}
// Update/add equipment
if (found == 1) {
// Update equipment
equipment[j] = zkl_status[i];
}
else {
// Add equipment
equipment.push(zkl_status[i]);
}
}
}
}
}
// Removed items?
backup = equipment;
equipment = new Array();
for (j in backup) {
// Reset vars
found = 0;
info = '';
class_id = '';
for (i=0; ((i<zkl_status.length) && (found == 0)); i++) {
if (backup[j].s_serialnr == zkl_status[i].s_serialnr) {
// Set flag
found = 1;
// Add to equipment array
equipment.push(zkl_status[i]);
}
}
// Not in zkl_status array
if (found == 0) {
// Display removed
info = '<?PHP echo _("removed"); ?>';
// Get server time (when not already asked)
if (server_time.length == 0) {
server_time = xmlhttp_data('','', 0,'<?php echo $_SESSION[$_PAGE_INFO['id']]['base']; ?>','<?php echo $_PAGE_INFO['id']; ?>','&get_datetime=1','&redirect=include/fetch_info.php');
}
time = server_time;
// Add line to rt status
addline("", 0, backup[j].s_idcode, info, time, backup[j].s_detection);
}
}
}
}
catch (ex) {
}
finally {
// Recursive function
setTimeout('start(func_rt_info, true)','500');
}
};
// Start rtstatus pump
function start(callback, blocking) {
// Async call
xmlhttp_data('','', 1,'<?php echo $_SESSION[$_PAGE_INFO['id']]['base']; ?>','<?php echo $_PAGE_INFO['id']; ?>','','&redirect=scripts/other/rtstatus_datapump.php&extended_info=1&blocking=' + blocking, callback);
}
// Initial call rtstatus pump
start(func_rt_info, false);
</script>
<?php
echo "</div>\n";
echo "</body>\n";
echo "</html>\n";
?>