304 lines
11 KiB
PHP
304 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:50px; font-size:18px; font-weight:bold;}
|
|
.input { width: 200px; }
|
|
#Result { width: 95%; height: 84%; border: 1px outset black; overflow-y: scroll; }
|
|
.project_div { width: 95%; height: 20px; background-color: #a6c6e3; color: white; border: 1px solid black; margin-top: 5px; }
|
|
.div_det_ok, .div_det_nok, .div_nok, .div_error { width: 93%; margin-left: 2%; color: white; border: 1px solid black; border-top: 0px; }
|
|
.div_det_ok { background-color: green; }
|
|
.div_det_nok { background-color: red; }
|
|
.div_nok { background-color: orange; }
|
|
.div_error { background-color: orange; }
|
|
</style>
|
|
<?php
|
|
// Javascript
|
|
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....";
|
|
|
|
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
|
|
setTimeout('StartApp()', getElement('Interval').value);
|
|
}
|
|
}
|
|
</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 "<label for=\"Result\">Result</label><br>";
|
|
echo "<div id=\"Result\" class=\"textarea\"></div><br>";
|
|
|
|
echo "</body>";
|
|
echo "</html>";
|
|
}
|
|
else {
|
|
// Result
|
|
$result = "";
|
|
|
|
// Start
|
|
$start = microtime_float();
|
|
|
|
// Specific customer
|
|
$customer = "";
|
|
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" . $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, (2 * 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"));
|
|
|
|
// Get customer info
|
|
$project_cust = db_fetch_customer($project['klant'], 1);
|
|
|
|
$result .= "<div class=\"project_div\"> " . $project['naam'] . " (" . $project_cust['bedrijfsnaam'] . ")</div>";
|
|
|
|
if (is_array($project_equip)) {
|
|
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 .= "\"> " . $item['idcode'];
|
|
$result .= ", " . $item['serienr'];
|
|
$result .= ", Measurement: " . (($measurement) ? "ON" : "OFF");
|
|
$result .= ", Detection: " . (($detection) ? "OK" : "NOK");
|
|
$result .= ", Switch: " . (!$switchErr ? (($switch) ? "ON" : "OFF") : "ERROR" );
|
|
$result .= ", Keyswitch: ";
|
|
switch($key) {
|
|
case 1:
|
|
$result .= "On";
|
|
break;
|
|
case 2:
|
|
$result .= "Off";
|
|
break;
|
|
default:
|
|
$result .= "Operational";
|
|
break;
|
|
}
|
|
$result .= ", Battery main: " . $batt_main . " [V]";
|
|
$result .= ", Battery backup: " . $batt_backup . " [V]";
|
|
$result .= "</div>";
|
|
}
|
|
else {
|
|
$result .= "<div class=\"div_nok\"> " . $item['idcode'] . ": No status response withing 6 secs</div>";
|
|
}
|
|
}
|
|
else {
|
|
$result .= "<div class=\"div_error\"> " . $item['idcode'] . ": Error</div>";
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
$result .= "<div class=\"div_nok\"> No RC devices on this project</div>";
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
$result .= "<div>No released RC projects!!!</div>";
|
|
}
|
|
|
|
echo "<div>Date/Time: " . date('Y-m-d H:i:s') . "</div>";
|
|
$exec = (microtime_float() - $start);
|
|
echo "<div>Execution time: " . $exec . "</div><br>";
|
|
echo $result;
|
|
|
|
// Debug info
|
|
DBG("Booster Active; Execution time: " . $exec . ", Customer: " . (int)$_GET['customer'] . ", Project: " . (int)$_GET['project']);
|
|
}
|
|
?>
|