src.dualinventive.com/mtinfo/dist/webroot/main/scripts/other/tasks/service_check.php

127 lines
4.2 KiB
PHP

<?php
/** \file scripts/other/tasks/service_check.php
* \brief DI webinterface task manager script, service date checker
* \author Rob Schalken, Core|Vision
* \version $Revision: 1.2 $
* \date $Date: 2013/03/13 17:11:35 $
*
* Service date checker
*/
/************************************/
/* Service date checker */
/************************************/
// Initial values
$service = array();
// Default skin
$_PAGE_INFO['skin'] = "dualinventive";
// Get report 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);
// Find all equipment
$equipment = db_fetch_all_lances();
// Check service date
if (is_array($equipment)) {
foreach ($equipment as $item) {
// Active item?
if ($item['lans_status'] == "actief") {
// Check date/time (which date comes first "next service" or "switch 3000 cells replace"?)
$next_service = strip_time(NextService($item['onderhoud'],$item['sw3000_onderhoud']));
if (strlen($next_service)) {
switch(convert_datetime($next_service) - convert_datetime(date('Y-m-d H:i') . ":00")) {
// Service date four weeks
case (28 * 24 * 60 * 60):
array_push($service, array(id => $item['id'], status => "4"));
break;
// Service date two weeks
case (14 * 24 * 60 * 60):
array_push($service, array(id => $item['id'], status => "2"));
break;
// Service date expired
case 0:
array_push($service, array(id => $item['id'], status => "expired"));
break;
// Do nothing
default:
break;
}
}
}
}
}
if (!empty($service)) {
foreach($service 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 => 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 user info
$user_info = db_fetch_customer($item_info['gebruiker'], 1);
if (strlen($user_info['service_email'])) {
array_push($service_email, array(i18n => $user_info['i18n'], email => $user_info['service_email'], cust_name => $user_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 service reminder") . ": " . $item_value . " (" . $mail['cust_name'] . ")";
// Define content
$content = "<p style=\"font-family:verdana;font-size:10pt\">";
$content .= _("Dear MTinfo user") . ",<br><br>";
switch($item['status']) {
case "expired":
$content .= _("The service date of the following equipment has been expired");
break;
case "4":
$content .= _("The service date of the following equipment expires in 4 weeks");
break;
case "2":
$content .= _("The service date of the following equipment expires in 2 weeks");
break;
}
$content .= ": " . $item_value . "<br><br>";
$content .= _("Best regards") . ",<br><br>";
$content .= "MTinfo";
$content .= "</p>";
// Send mail
send_mail($mail['email'], "", $_PAGE_INFO['ini']['comm']['dev_calib'], $_PAGE_INFO['ini']['report']['no-reply'], $subject, $content);
}
}
}
}
// Set handled flag
$handled = 1;
?>