src.dualinventive.com/mtinfo/dist/webroot/support/booster2.php

301 lines
11 KiB
PHP

<?php
/*
* Definitions
*/
define("REL_PATH", "../");
define("RELEASE" , "");
define("ABS_PATH", "support/");
/*
* Required pages
*/
require_once(REL_PATH . "include/utilities.php");
require_once(REL_PATH . "include/db.php");
require_once(REL_PATH . "include/tcpclient.php");
if (!isset($_GET['status'])) {
/*
* Page build-up
*/
echo "<html>";
echo "<head>";
// CSS definitions
?>
<style>
.button { width: 200px; height:20px; font-size:16px; font-weight:bold;}
.input { width: 200px; }
#Result { width: 100%; }
.project_div { width: 99%; height: 20px; background-color: #6c757d; color: #fff; margin-top: 4px; }
.div_det_ok, .div_det_nok, .div_nok, .div_error { width: 97%; margin-left: 1%; color: white; border: 1px solid black; border-top: 0px; }
.div_det_ok { background-color: #28a745; color: #fff; }
.div_det_nok { background-color: #dc3545; color: #fff; }
.div_nok { background-color: #ffc107; color: #343a40; }
.div_error { background-color: #ffc107; color: #343a40; }
</style>
<?php
// Javascript
echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>';
echo "<script type=\"text/javascript\" src=\"" . REL_PATH . JAVA_DIR . "java.js\"></script>\n";
echo "<script type=\"text/javascript\" src=\"" . REL_PATH . JAVA_DIR . "xmlhttp_data.js\"></script>\n";
?>
<script type="text/javascript">
// Global variables
var Active = false;
// Hanlde starting/stopping of application
function HandleStartStop() {
// Invert value
Active = !Active;
// Restart application
if (Active) {
StartApp();
}
// Change caption/disable items
getElement('StartStop').value = (Active) ? "Stop boosting" : "Start boosting";
getElement('Interval').readOnly = Active;
}
// Interval check
function IntervalCheck() {
if (Number(getElement('Interval').value)) {
if ((parseInt(getElement('Interval').value)) < 1000) {
getElement('Interval').value = "1000";
}
}
else {
getElement('Interval').value = "5000";
}
}
// Project check
function ProjectCheck() {
// Clean all projects
getElement('Project').options.length = 0;
var x = getElement('HiddenProject');
for (var i = 0; i < x.options.length; i++) {
if ((getElement('Customer').value == '-1') ||
(ProjectByCust[i] == getElement('Customer').value) ||
(ProjectByCust[i] == '-1')) {
var option = x.options[i];
var index = getElement('Project').options.length;
getElement('Project').options[index] = new Option(option.text, option.value);
getElement('Project').options[index].id = option.id;
getElement('Project').options[index].onmouseover = option.onmouseover;
getElement('Project').options[index].onmouseout = option.onmouseout;
}
}
}
// Main loop app
function StartApp() {
// Active application application?
if (Active) {
// clear old result
//getElement('Result').innerHTML = "Request for new info....";
$.get("<?php echo $_DEFAULT['base'] . RELEASE . ABS_PATH . basename(__FILE__) . '?status=1&customer="+getElement(\'Customer\').value+"&project="+getElement(\'Project\').value'; ?>, function(dat) {
$('#Result').html(dat);
})
.always(function() {
setTimeout('StartApp()', getElement('Interval').value);
});
// try {
// xmlhttp request => Result
// xmlhttp_data('<?php echo RELEASE . ABS_PATH . basename(__FILE__);?>','Result', 0,'<?php echo $_DEFAULT['base']; ?>','','','&status=1&customer=' + getElement('Customer').value + '&project=' + getElement('Project').value);
// }
//catch (e) { /* Silent exception */ }
// Reload
}
}
</script>
<?php
echo "</head>";
echo "<body onload=\"StartApp();\">";
echo "<table><tr><td>";
echo "<input type=\"button\" class=\"button\" id=\"StartStop\" value=\"Start boosting\" onClick=\"HandleStartStop();\"><br>";
echo "</td><td>";
echo "<label for=\"Interval\">Interval</label><br>";
echo "<input type=\"text\" class=\"input\" id=\"Interval\" value=\"5000\" onChange=\"IntervalCheck()\"><br>";
$customers = array_sort(db_fetch_customers_all(), "bedrijfsnaam");
if (is_array($customers)) {
echo "</td><td>";
echo "<label for=\"Customer\">Customer</label><br>";
echo "<select class=\"input\" id=\"Customer\" onChange=\"ProjectCheck()\">";
echo "<option value=\"-1\">All customers</option>";
foreach($customers as $customer) {
echo "<option value=\"" . $customer['id'] . "\">" . $customer['bedrijfsnaam'] . " (" . $customer['id'] . ")</option>";
}
echo "</select>";
}
$projects = array_sort(db_fetch("project", '*', "sstatus='vrijgegeven' AND type='RC' AND parent IS NULL"), "naam");
if (is_array($projects)) {
echo "</td><td>";
echo "<label for=\"Project\">Project</label><br>";
echo "<select class=\"input\" id=\"Project\">";
echo "<option value=\"-1\">All projects</option>";
foreach($projects as $project) {
echo "<option value=\"" . $project['id'] . "\">" . $project['naam'] . " (" . $project['id'] . ")</option>";
}
echo "</select>";
// Hidden object
echo "<select class=\"input\" id=\"HiddenProject\" style=\"visibility:hidden\">";
echo "<option value=\"-1\">All projects</option>";
foreach($projects as $project) {
echo "<option value=\"" . $project['id'] . "\">" . $project['naam'] . " (" . $project['id'] . ")</option>";
}
echo "</select>";
// Fill javascript array
echo "<script type=\"text/javascript\">";
echo "var ProjectByCust = new Array();";
echo "ProjectByCust.push('-1');";
foreach($projects as $project) {
echo "ProjectByCust.push('" . $project['klant'] . "');";
}
echo " </script>";
}
echo "</td></tr></table>";
echo "<div id=\"Result\" class=\"textarea\"></div><br>";
echo "</body>";
echo "</html>";
}
else {
// Result
$result = "";
// Start
$start = microtime_float();
// Specific customer, remove DIPB and IB Luik
$customer = " AND klant NOT IN(20,76)";
if ((isset($_GET['customer'])) && ($_GET['customer'] != -1)) {
$customer .= " AND klant=" . (int)$_GET['customer'];
}
// Specific project
$project = "";
if ((isset($_GET['project'])) && ($_GET['project'] != -1)) {
$project = " AND id=" . (int)$_GET['project'];
}
// Get all released/ready for releas rc projects
$projects = array_sort(db_fetch("project", '*', "(sstatus='vrijgegeven' OR sstatus='verzoek tot vrijgeven') AND type='RC' AND parent IS NULL AND status != 'afgesloten'" . $customer . $project), "naam");
if (is_array($projects)) {
$equip = array();
$equip_id = array();
// Collect all devices
foreach($projects as $project) {
// Retrieve available active equipment on this project
$project_equip = db_fetch_project_lances($project['id'], "", array(array("gsm","gprs"),"kortsluiting schakelen","meting"), 1, array("actief"), array("actief"));
if (is_array($project_equip)) {
foreach($project_equip as $item) {
if (!in_array($item['id'], $equip_id)) {
array_push($equip, $item);
array_push($equip_id, $item['id']);
}
}
}
}
// Get non-cached status
$equip = tcpclient_non_cached_status($equip, FALSE, (3 * TCP_TIMEOUT));
foreach($projects as $project) {
// Retrieve available active equipment on this project
$project_equip = db_fetch_project_lances($project['id'], "", array(array("gsm","gprs"),"kortsluiting schakelen","meting"), 1, array("actief"), array("actief"));
if (!is_array($project_equip)) {
// no RC devices on this project
continue;
}
// Get customer info
$project_cust = db_fetch_customer($project['klant'], 1);
$result .= "<div class=\"project_div\">&nbsp;" . $project['naam'] . " (" . $project_cust['bedrijfsnaam'] . ")</div>";
foreach($project_equip as $item) {
$pos = array_search($item['id'], $equip_id);
if ($pos !== FALSE) {
if ($equip[$pos]['found']) {
// Get measurement
$measurement = ($equip[$pos]['status']['mcu']['status'] & 0x0001) == 0x0001;
// Get switch status (Switch = 1 => Short circuit = 1!!!! (non-inverted))
$switch = $equip[$pos]['status']['switch3000']['on'];
$switchErr = (($equip[$pos]['status']['mcu']['switch3000 status'] & 0xF0) != 0);
// Get key (0: operational, 1: on, 2:off)
$key = ($equip[$pos]['status']['switch3000']['key']['on']) ? 1 : (($equip[$pos]['status']['switch3000']['key']['off']) ? 2 : 0);
// Get battery values
$batt_main = $equip[$pos]['status']['batt']['1']['V'];
$batt_backup = $equip[$pos]['status']['batt']['0']['V'];
// Detection?
switch(($equip[$pos]['status']['detection']['ok']) . $switch) {
case "11":
$detection = 1;
break;
default:
$detection = 0;
break;
}
$result .= "<div class=\"";
$result .= (($detection) ? "div_det_ok" : "div_det_nok");
$result .= "\">&nbsp;&nbsp;&nbsp;&nbsp;" . $item['idcode'];
$result .= ", " . $item['serienr'];
$result .= (($equip[$pos]['status']['mcu']['persistent'] & 0x80) ? ', released' : ', NOT RELEASED');
$result .= ", Meas.: " . (($measurement) ? "ON" : "OFF");
$result .= ", Det.: " . (($detection) ? "OK" : "NOK");
$result .= ", Sw.: " . (!$switchErr ? (($switch) ? "ON" : "OFF") : "ERROR" );
$result .= ", Keysw.: ";
switch($key) {
case 1:
$result .= "On";
break;
case 2:
$result .= "Off";
break;
default:
$result .= "Oper";
break;
}
$result .= ", Bat. main: " . round($batt_main, 2) . " V";
$result .= ", Bat. bckp: " . round($batt_backup, 2) . " V";
$result .= "</div>";
}
else {
$result .= "<div class=\"div_nok\">&nbsp;&nbsp;&nbsp;&nbsp;" . $item['idcode'] . ": No status response withing 6 secs</div>";
}
}
else {
$result .= "<div class=\"div_error\">&nbsp;&nbsp;&nbsp;&nbsp;" . $item['idcode'] . ": Error</div>";
}
}
}
}
else {
$result .= "<div>No released RC projects!!!</div>";
}
$exec = (microtime_float() - $start);
echo "Date/Time: " . date('Y-m-d H:i:s') . ", Execution time: " . $exec . "<br>";
echo $result;
}