src.dualinventive.com/mtinfo/dist/webroot/rc-4.05/scripts/other/tasks/battery_check.php

147 lines
4.8 KiB
PHP

<?php
/** \file scripts/other/tasks/battery_check.php
* \brief DI webinterface task manager script, xxx
* \author Rob Schalken, Core|Vision
* \version $Revision: 26247 $
* \date $Date: 2016-02-29 10:40:22 +0100 (Mon, 29 Feb 2016) $
*
* Battery checker
*/
/************************************/
/* Main battery checker */
/************************************/
// Initial values
$battery_check = array();
$equipment = array();
// Default skin
$_PAGE_INFO['skin'] = "dualinventive";
// Get settings from ini file
$ini_file = get_all_files($_PAGE_INFO['base_path'] . SKIN_DIR . $_PAGE_INFO['skin'] . "/", array("ini"));
$_PAGE_INFO['ini'] = parse_ini_file($ini_file[0], true);
// Retrieve all device types
$types = db_fetch_system_devices($_PAGE_INFO['i18n']);
if (is_array($types)) {
foreach($types as $type) {
// Right capabilities?
if (($type['nr_batterijen'] > 1) &&(db_check_system_device_capabilities($type['id'], array("kortsluiting schakelen")))) {
// Find all equipment
$equipment_type = db_fetch_all_lances($type['id']);
if (is_array($equipment_type)) {
// Merge arrays
$equipment += $equipment_type;
}
}
}
}
// Check switch status (batteries and sections) and main battery
if (!empty($equipment)) {
foreach ($equipment as $item) {
// Active item?
if ($item['lans_status'] == "actief") {
// Initial values
$batt_status = "";
// Fetch last log_realtime entry
$status = db_fetch_lance_logrt($item['id']);
// Valid log entry?
if (is_array($status)) {
// Main battery almost empty or empty? => message
switch(($status[0]['mcu_state'] & 0xF000) >> 12) {
case 3:
$batt_status = "leeg";
break;
case 1:
$batt_status = "alarm";
break;
default:
break;
}
}
// Error detected?
if (!strlen($batt_status)) {
if (in_array($item['id'], $error)) {
// Remove from zkl_logerror table
db_delete("zkl_logerror", "zkl='" . $item['id'] . "' AND task_id='" . $task['id'] . "'");
}
}
else {
if (!in_array($item['id'], $error)) {
// Store in zkl_logerror table
db_store("zkl_logerror", array("zkl","tijd","task_id"), array($item['id'], $now, $task['id']));
array_push($battery_check, array(id => $item['id'], status => $batt_status));
}
}
}
}
}
if (!empty($battery_check)) {
foreach($battery_check as $item) {
// Initial values
$service_email = array();
// Fetch equipment info
$item_info = db_fetch_lance($item['id'], "", 1);
// Fetch owner info
$cust_info = db_fetch_customer($item_info['eigenaar'], 1);
// Set owner language (When service email has been selected => else default)
if (strlen($cust_info['service_email'])) {
array_push($service_email, array(i18n => $cust_info['i18n'], email => $cust_info['service_email'], cust_name => $cust_info['bedrijfsnaam']));
}
// Rented?
if ((!is_null($item_info['gebruiker'])) && ($item_info['eigenaar'] != $item_info['gebruiker'])) {
// Fetch customer who is renting
$rent_cust_info = db_fetch_customer($item_info['gebruiker'], 1);
if (strlen($rent_cust_info['service_email'])) {
array_push($service_email, array(i18n => $rent_cust_info['i18n'], email => $rent_cust_info['service_email'], cust_name => $rent_cust_info['bedrijfsnaam']));
}
}
if ((is_array($service_email)) && (!empty($service_email))) {
foreach($service_email as $mail) {
i18n_settext_language($mail['i18n'], $_PAGE_INFO['base_path'] . "locale/");
// Display rt status remark?
$item_value = $item_info['idcode'];
if (strlen($item_info['rtstatus'])) {
$item_value .= " / " . $item_info['rtstatus'];
}
// Define subject
$subject = "MTinfo" . " " . strtolower(_("Warning")) . ": " . $item_value . " (" . $mail['cust_name'] . ")";
// Define content
$content = "<p style=\"font-family:verdana;font-size:10pt\">";
$content .= _("Dear MTinfo user") . ",<br><br>";
$content .= _("The main battery of the following equipment has an distressed status") . " (" . _($item['status']) . ")";
$content .= ": " . $item_value . "<br>";
$content .= _("It is necessairy to replace this battery") . "!<br><br>";
$content .= _("Best regards") . ",<br><br>";
$content .= "MTinfo";
$content .= "</p>";
// Send mail (high priority)
send_mail($mail['email'], "", $_PAGE_INFO['ini']['comm']['batt_warning'], $_PAGE_INFO['ini']['report']['no-reply'], $subject, $content, "", "", 1);
}
}
}
}
// Set handled flag
$handled = 1;
?>