1 /* too complicated for now */ ) { report_data($data); } else { // expand 'data' or multiple data items $report_data = array(); // expand 'data' by dividing the 'value' into multiple lines for( $i = 0; $i < count($data['value']); $i++ ) { // reset line counter $line_nr = 0; $paragraphs = preg_split("/((\n|\n\r|\r\n|\r)|)/", $data['value'][$i]); foreach( $paragraphs as $str ) { // initialize, when needed if( $line_nr == count($report_data) ) $report_data[$line_nr] = array('value' => array()); do { if( is_array($data['cell_width']) ) $cell_width = $data['cell_width'][$i]; else $cell_width = 180; $max_len = ($cell_width * 5) / $data['font_size'][$i]; // appears to be about right $line_prefix = shorten_text($str, $max_len, SHORTEN_NARROW | SHORTEN_NO_SUFFIX, FALSE); $n = strlen($line_prefix); if( $n == strlen($str) || $n == 0 /* no expected; prevent problems below */ ) { // whole line $report_data[$line_nr++]['value'][$i] = $str; $str = NULL; // break out of the do/while loop } else { // find the last space, which may fall right behind the last word, hence the "+1" $n = strrpos(substr($str, 0, strlen($line_prefix) + 1), " "); if( !$n ) { // no space found; break at the number of characters found before $n = strlen($line_prefix); } // copy this line and remove it from the text $report_data[$line_nr++]['value'][$i] = substr($str, 0, $n); $str = substr($str, $n + 1); } } while( $str ); } } // print the data for( $i = 0; $i < count($report_data); $i++ ) { // copy the rest of the 'data' fields foreach( $data as $item => $value ) { // Determine cell height $height = (isset($data['height'])) ? $data['height'] : 16; // Remove bottom border when multiple lines! // Exception is EOF if (($item == 'border') && (($_PAGE_INFO['height'] - (2 * $height)) >= PDF_MARGIN_BOTTOM)) { $report_data[$i][$item] = ((($i + 1) >= count($report_data)) ? $value : str_replace("B", "", $value)); } else if( $item != 'value' ) $report_data[$i][$item] = $value; } // print it report_data($report_data[$i]); } } } /** * Fill in specific fields (rest filled up with empty space) * This function is specific created for CSV files */ function report_data_field($all_fields, $report_data, $items = NULL) { global $_PAGE_INFO; // Initial value $first = TRUE; $data = array(); if ((is_array($all_fields)) && (is_array($items))) { foreach($all_fields as $field) { // Field available? $pos = array_search($field, $items); if ($pos !== FALSE) { array_push($data, $report_data['value'][$pos]); } else { array_push($data, ""); } } // Generate data report_data(array(value => $data)); } } /** * report new page */ function report_new_page() { global $_PAGE_INFO; if (strtolower($_PAGE_INFO['report_type']) == "pdf") { pdf_page_new(); } } /** * Generate report */ function report_generate() { global $_PAGE_INFO; if (strtolower($_PAGE_INFO['report_type']) == "pdf") { // Download file $result = pdf_page_footer($_PAGE_INFO['file'], $_PAGE_INFO['dest']); } else if (strtolower($_PAGE_INFO['report_type']) == "csv") { if ($_PAGE_INFO['dest'] == "S") { $result = $_PAGE_INFO['document']; } } return $result; } /** * Empty line */ function empty_line($nmr = 1, $thick_line = 0) { for ($i = 0; $i < $nmr; $i++) { report_data(array(value => array("") , border => array("") , bold => "" , align => "" , font_size => "" , cell_width => "" , check_page_end => 0 , thick_line => $thick_line )); } } /** * Create the elektronics test result report */ function report_calibration($calib, $filename) { global $_PAGE_INFO; // Retrieve calibration info $lance = db_fetch_lance($calib['zkl'], "", 1); $user = db_fetch_user($calib['gebruiker'], "", 1); $customer = db_fetch_customer($user['klant'], 1); $type = db_fetch_system_devices($_PAGE_INFO['i18n'], $lance['device']); // Set file info $_PAGE_INFO['report_type'] = "pdf"; $_PAGE_INFO['dest'] = "S"; $_PAGE_INFO['file'] = $filename . ".pdf"; // Split up filename => create reference $file = split("-", $filename); // Create header info $idcode = ($lance['idcode'] == $lance['serienr']) ? $lance['idcode'] : $lance['idcode'] . " - " . $lance['serienr']; report_header(array(subject => "Elektronics test report" , header => _("Elektronics test report") . " - " . $type[0]['naam'] , data => array( array("Date", $calib['datum']) , array("ID code", $idcode) , array("Tester", getUser($user['id'])) , array("Reference", $file[0] . "-" . $lance['serienr'])))); // Test results header report_data(array(value => array(_("Elektronics test results") . " - " . $type[0]['naam']) , border => array("") , bold => array(1) , align => array("L") , font_size => array(16) , cell_width => "" , cell_height => 16 , check_page_end => 1 )); empty_line(); report_data(array(value => array("Description","Result","Remark") , border => array("B","LB","LB") , bold => array(1,1,1) , align => array("L","L","L") , font_size => array(8,8,8) , cell_width => array(60,50,70) , cell_height => 16 , check_page_end => 1 )); // Get all test results $tests = array(array("batt" , ""), array("led_batt_low" , ""), array("gsm_gprs" , ""), array("gps" , ""), array("sd_card" , ""), array("auto_calib_info" , ""), array("weerstand" , ""), array("detectie" , " < " . $calib['weerstand_ok'] . " mOhm"), array("meetdraad_links" , ""), array("meetdraad_rechts" , ""), array("kortsluitdraad" , ""), array("sleutelschakelaar", ""), array("led_meting" , "")); if (is_array($tests)) { $test_results = array(); foreach ($tests as $test) { switch($test[0]) { case "batt": for ($i = 0; $i < $type[0]['nr_batterijen']; $i++) { array_push($test_results, array(_("Battery") . " " . ($i + 1) . " " . _("contact"), $calib['batterijen'] & pow(2,$i) ? "ok" : "nok", "")); } break; case "led_batt_low": case "gsm_gprs": case "gps": case "sd_card": case "led_meting": case "sleutelschakelaar": if (strlen($calib[$test[0]])) { array_push($test_results, array($test[0], $calib[$test[0]], $test[1])); } break; case "auto_calib_info": if (db_check_system_device_capabilities($lance['device'],array("meting"))) { array_push($test_results, array($test[0], (((float)($calib['b_a'])) && ((float)($calib['freq']))) ? "b/a: " . $calib['b_a'] . ", freq: " . $calib['freq'] : "", $test[1])); } break; case "weerstand": case "meetdraad_links": case "meetdraad_rechts": case "kortsluitdraad": if (db_check_system_device_capabilities($lance['device'],array("meting"))) { array_push($test_results, array(_($test[0]) . " (mohm)", ((float)$calib[$test[0]]) ? $calib[$test[0]] : "", $test[1])); } break; case "detectie": if (db_check_system_device_capabilities($lance['device'],array("meting"))) { array_push($test_results, array(_("Threshold") . " (mohm)", ((float)$calib[$test[0]]) ? $calib[$test[0]] : "", $test[1])); } break; } } // Store values if (is_array($test_results)) { foreach($test_results as $test_result) { report_data(array(value => $test_result , border => array("B","LB","LB") , bold => array(0,0,0) , align => array("L","L","L") , font_size => array(8,8,8) , cell_width => array(60,50,70) , cell_height => 16 , check_page_end => 1 )); } } } empty_line(); // Overall result report_data(array(value => array(_("Electronics test result") . ":",$calib['algemene_status']), border => array("","") , bold => array(1,1) , align => array("L","L") , font_size => array(12,12) , cell_width => array(70,110) , cell_height => 16 , check_page_end => 1 )); empty_line(); // Print conclusion/remark/recommendation box report_data(array(value => array("Remarks / conclusion / Recommendations") , border => array("LBRT") , bold => array(1) , align => array("L") , font_size => array(9) , cell_width => array(180) , cell_height => 16 , check_page_end => 1 )); // Calculate number of lines $lines = nmr_lines($calib['commentaar'],115); // Fill array if (sizeof($lines) < 3) { do { array_push($lines, ""); } while(sizeof($lines) < 3); } for($i = 0; $i < sizeof($lines); $i++) { report_data(array(value => array($lines[$i]) , border => (($i + 1) == sizeof($lines)) ? array("LRB") : array("LR") , bold => array(0) , align => array("L") , font_size => array(9) , cell_width => array(180) , cell_height => 16 , check_page_end => 1 )); } // Generate document $result['document'] = report_generate(); $result['filename'] = $_PAGE_INFO['file']; return $result; } /** * Create the endcontrol/certificate result report */ function report_endcontrol_certificate($endcontrol, $calib, $filename) { global $_PAGE_INFO; // Retrieve calibration info $lance = db_fetch_lance($endcontrol['zkl'], "", 1); $user = db_fetch_user($endcontrol['gebruiker'], "", 1); $customer = db_fetch_customer($user['klant'], 1); $type = db_fetch_system_devices($_PAGE_INFO['i18n'], $lance['device']); // Set file info $_PAGE_INFO['report_type'] = "pdf"; $_PAGE_INFO['dest'] = "S"; $_PAGE_INFO['file'] = $filename . ".pdf"; // Split up filename => create reference $file = split("-", $filename); // Create header info $idcode = ($lance['idcode'] == $lance['serienr']) ? $lance['idcode'] : $lance['idcode'] . " - " . $lance['serienr']; report_header(array(subject => "Delivery report" , header => strtoupper(_("Delivery report")) . " - " . $type[0]['naam'] , data => array( array("Date", $endcontrol['datum']) , array("ID code", $idcode) , array("Tester", getUser($user['id'])) , array("Reference", $file[0] . "-" . $lance['serienr'])))); // Functional test results header report_data(array(value => array(_("Control function") . " " . $type[0]['naam']) , border => array("") , bold => array(1) , align => array("L") , font_size => array(12) , cell_width => "" , cell_height => 16 , check_page_end => 1 )); empty_line(); report_data(array(value => array("Description"," " . _("Agreement")," " . _("Remarks")) , border => array("","L","L") , bold => array(1,1,1) , align => array("L","L","L") , font_size => array(9,9,9) , cell_width => array(70,24,86) , cell_height => 12 , check_page_end => 1 )); report_data(array(value => array(""," " . _("Yes") . " / " . _("No"),"") , border => array("B","LB","LB") , bold => array(1,1,1) , align => array("L","L","L") , font_size => array(9,9,9) , cell_width => array(70,24,86) , cell_height => 16 , check_page_end => 1 )); // Get all test results $tests = array(array("led_meting" , ""), array("batt" , ""), array("arretering" , ""), array("afsluitbaar" , ""), array("gsm_gprs" , "")); if (is_array($tests)) { $test_results = array(); foreach ($tests as $test) { switch($test[0]) { case "led_meting": if (db_check_system_device_capabilities($lance['device'],array("meting","led"))) { array_push($test_results, array("Green led blinks by shortcircuit", ($endcontrol['led_meting'] == "ok") ? "x" : "", "", "", $test[1])); } break; case "batt": for ($i = 0; $i < $type[0]['nr_batterijen']; $i++) { array_push($test_results, array(_("Battery") . " " . ($i + 1) . " " . _("operates"), $calib['batterijen'] & pow(2,$i) ? "x" : "", "", "", $test[1])); } break; case "arretering": if (db_check_system_device_capabilities($lance['device'],array("afsluitbaar"))) { array_push($test_results, array(_("Detent") . " " . _("operates"), ($endcontrol['arretering'] == "ok") ? "x" : "", "", "", $test[1])); } break; case "afsluitbaar": if (db_check_system_device_capabilities($lance['device'],array("afsluitbaar"))) { array_push($test_results, array(_("The") . " " . $type[0]['naam'] . " " . _("is lockable"), ($endcontrol['afsluitbaar'] == "ok") ? "x" : "", "", "", $test[1])); } break; case "gsm_gprs": if (db_check_system_device_capabilities($lance['device'],array("afsluitbaar"))) { array_push($test_results, array("SMS" . " " . _("operates"), ($calib['gsm_gprs'] == "ok") ? "x" : "", "", "", $test[1])); } break; } } // Store values if (is_array($test_results)) { foreach($test_results as $test_result) { report_data(array(value => $test_result , border => array("B","LB","LB","LB") , bold => array(0,0,0,0) , align => array("L","C","C","L") , font_size => array(9,9,9) , cell_width => array(70,12,12,86) , cell_height => 16 , check_page_end => 1 )); } } } empty_line(); // Print conclusion/remark/recommendation box report_data(array(value => array("Remarks / conclusion / Recommendations") , border => array("LBRT") , bold => array(1) , align => array("L") , font_size => array(9) , cell_width => array(180) , cell_height => 16 , check_page_end => 1 )); // Calculate number of lines $lines = nmr_lines($endcontrol['commentaar'],115); // Fill array if (sizeof($lines) < 3) { do { array_push($lines, ""); } while(sizeof($lines) < 3); } for($i = 0; $i < sizeof($lines); $i++) { report_data(array(value => array($lines[$i]) , border => (($i + 1) == sizeof($lines)) ? array("LRB") : array("LR") , bold => array(0) , align => array("L") , font_size => array(9) , cell_width => array(180) , cell_height => 16 , check_page_end => 1 )); } empty_line(2); // Certificate report_data(array(value => array(_("Security certificate") . " " . $type[0]['naam']) , border => array("") , bold => array(1) , align => array("L") , font_size => array(12) , cell_width => "" , cell_height => 16 , check_page_end => 1 )); empty_line(); report_data(array(value => array(_("Safety declaration of the mentioned above") . " " . $type[0]['naam']), border => array("") , bold => array(1) , align => array("L") , font_size => array(9) , cell_width => "" , cell_height => 16 , check_page_end => 1 )); empty_line(); // Certificate text report_data(array(value => array(ucwords($_PAGE_INFO['skin_name']) . " " . _("announces that the") . " " . $type[0]['naam'] . " " . _("mentioned above confirms the requested security isues,")), border => array("") , bold => array(0) , align => array("L") , font_size => array(9) , cell_width => "" , cell_height => 12 , check_page_end => 1 )); if (db_check_system_device_capabilities($lance['device'],array("meting"))) { report_data(array(value => array("provided that the electronic housing has been sealed by at least two \"approved until\" stickers with identical"), border => array("") , bold => array(0) , align => array("L") , font_size => array(9) , cell_width => "" , cell_height => 12 , check_page_end => 1 )); report_data(array(value => array(_("non-expired data and that the") . " " . $type[0]['naam'] . " " . _("has been used as described in a valid user manual.")), border => array("") , bold => array(0) , align => array("L") , font_size => array(9) , cell_width => "" , cell_height => 12 , check_page_end => 1 )); } else { report_data(array(value => array(_("provided that the electronic housing has no visual damage and the") . " " . $type[0]['naam'] . " " . _("has been used as described in a valid user manual.")), border => array("") , bold => array(0) , align => array("L") , font_size => array(9) , cell_width => "" , cell_height => 12 , check_page_end => 1 )); } empty_line(); // Certificate requirements/Next calibration data if (db_check_system_device_capabilities($lance['device'],array("meting"))) { // which date comes first "next service" or "switch 3000 cells replace"? report_data(array(value => array("", "", "Security requirements", _("Next service date") . ": " . strip_time(NextService($lance['onderhoud'],$lance['sw3000_onderhoud']))), border => array("","","","") , bold => array(0,0,1,1) , align => array("L","L","L","L") , font_size => array(9,9,9,9) , cell_width => array(10,2,78,90) , cell_height => 12 , check_page_end => 1 )); } else { report_data(array(value => array("", "", "Security requirements") , border => array("","","") , bold => array(0,0,1) , align => array("L","L","L") , font_size => array(9,9,9) , cell_width => array(10,2,60) , cell_height => 12 , check_page_end => 1 )); } empty_line(); if (db_check_system_device_capabilities($lance['device'],array("meting"))) { report_data(array(value => array("", "", _("Measure value") . " < " . round($calib['weerstand_cert']) . " milliohm"), border => array("","B","B") , bold => array(0,0,0) , align => array("L","L","L") , font_size => array(9,9,9) , cell_width => array(10,2,60) , cell_height => 16 , check_page_end => 1 )); } report_data(array(value => array("", "", "89/336/EEG EMC-directives") , border => array("", "B", "B") , bold => array(0,0,0) , align => array("L","L","L") , font_size => array(9,9,9) , cell_width => array(10,2,60) , cell_height => 16 , check_page_end => 1 )); report_data(array(value => array("", "", "72/23/EEG Low voltage-directives") , border => array("","B","B") , bold => array(0,0) , align => array("L","L","L") , font_size => array(9,9,9) , cell_width => array(10,2,60) , cell_height => 16 , check_page_end => 1 )); report_data(array(value => array("", "","CE-Marking") , border => array("","B","B") , bold => array(0,0,0) , align => array("L","L","L") , font_size => array(9,9,9) , cell_width => array(10,2,60) , cell_height => 16 , check_page_end => 1 )); empty_line(); // Client declares report_data(array(value => array("The Client declares that:") , border => array("") , bold => array(1) , align => array("L") , font_size => array(9) , cell_width => "" , cell_height => 16 , check_page_end => 1 )); report_data(array(value => array("- " . _("the goods to be delivered have been examined and approved.")), border => array("") , bold => array(0) , align => array("L") , font_size => array(9) , cell_width => "" , cell_height => 16 , check_page_end => 1 )); report_data(array(value => array("- " . _("the Dual Inventive General Terms and Conditions 2010-08-26 on the website of Dual Inventive have been read and accepted.")), border => array("") , bold => array(0) , align => array("L") , font_size => array(9) , cell_width => "" , cell_height => 16 , check_page_end => 1 )); empty_line(); report_data(array(value => array("", "Name","Date") , border => array("","","") , bold => array(1,1,1) , align => array("L","L","L") , font_size => array(9,9,9) , cell_width => array(10,60,110) , cell_height => 16 , check_page_end => 1 )); // Generate document $result['document'] = report_generate(); $result['filename'] = $_PAGE_INFO['file']; return $result; } /** * Create the material overview */ function report_material_overview() { global $_PAGE_INFO; // Retrieve info $date = date('Y-m-d'); $datetime = date('Y-m-d / H:i:s'); $customer = db_fetch_customer($_PAGE_INFO['login']['customer']['id'], 1); $user = db_fetch_user($_PAGE_INFO['login']['user']['id'], "", 1); $projects = db_fetch_projects("", $_PAGE_INFO['login']['customer']['id'], 1); $double = db_fetch_project_double_assigned_lances($_PAGE_INFO['login']['customer']['id']); // Set file info $_PAGE_INFO['report_type'] = "pdf"; $_PAGE_INFO['dest'] = "D"; $_PAGE_INFO['file'] = _("Equip_overview") . "_" . strtoupper($customer['klantnaam']) . "_" . str_replace("-", "", $date) . ".pdf"; // Create header info report_header(array(subject => "Equipment overview" , header => _("Equipment overview") . " - " . $customer['bedrijfsnaam'] , data => array( array("Date", $datetime) , array("User", getUser($user['id']))))); if (is_array($projects)) { foreach($projects as $project) { // Add project to report report_data(array(value => array(_("Project") . ": " . $project['naam']) , border => array("LRBT") , bold => array(1) , align => array("L") , font_size => array(11) , cell_width => "" , cell_height => 16 , check_page_end => 1 )); // Retrieve all device types $types = db_fetch_system_devices($_PAGE_INFO['i18n']); // Determine amount per device type (non-rented & active!!) if (is_array($types)) { foreach($types as $type) { $equipement = db_fetch_project_lances($project['id'], $type['id'], "", 1, array("actief"), array("actief")); if (is_array($equipement)) { // Add equipment type to report report_data(array(value => array("", "-" . $type['naam']) , border => array("LT","RT") , bold => array(0,1) , align => array("L","L") , font_size => array(11,11) , cell_width => array(10,170) , cell_height => 16 , check_page_end => 1 )); foreach($equipement as $item) { $idcode = $item['idcode']; if (is_array($double)) { if (in_array($item['id'], $double)) { $idcode .= " (" . _("Multiple project assignments") . "!!)"; } } // Add idcode report_data(array(value => array("","", $idcode) , border => array("L","LRBT","RBT") , bold => array(0,0) , align => array("L","L") , font_size => array(8,8,8) , cell_width => array(20,5,155) , cell_height => 16 , check_page_end => 1 )); } } } // Fill up last line report_data(array(value => array("","", "") , border => array("T","T","T") , bold => array(0,0,0) , align => array("L","L","L") , font_size => "" , cell_width => "" , cell_height => 16 , check_page_end => 0 )); } } } // Generate document report_generate(); } /** * Create the equipment report */ function report_equipment($report_info) { GLOBAL $_PAGE_INFO; // Give the script some extra memory and execution time ini_set("memory_limit","2048M"); ini_set("max_execution_time","120"); // Definitions define("MEASUREMENT" ,0x00); define("DETECTION" ,0x01); define("GPS" ,0x02); define("BATTERY" ,0x03); define("SHORTCIRCUIT" ,0x04); define("SMS" ,0x05); define("KEYSWITCH" ,0x06); // Bitmasks! define("OK" ,0x00); define("UNFINISHED_BEG" ,0x01); define("UNFINISHED_END" ,0x02); define("SERVER_TIME_BEG" ,0x04); define("SERVER_TIME_END" ,0x08); define("CON_HICKUP" ,0x10); define("MEAS_HICKUP" ,0x20); define("FIND_BEGIN" ,0x00); define("FIND_END" ,0x01); define("FIND_EVENT" ,0x02); define("OPERATIONAL" ,0x00); define("ON" ,0x04); define("OFF" ,0x08); // Get log data from the "report" database db_connect("report", "log"); // Retreive customer/date(time) information $customer = db_fetch_customer($report_info['customer'], 1); $date = date('Y-m-d'); $datetime = date('Y-m-d H:i:s'); // Define begin and end of report period $begin_period = ""; $end_period = ""; if (strlen($report_info['begin_datum'])) { $begin_period = $report_info['begin_datum'] . " " . $report_info['begin_tijd'] . ":00"; } if (strlen($report_info['eind_datum'])) { $end_period = $report_info['eind_datum'] . " " . $report_info['eind_tijd'] . ":00"; } // Store original begin/end period $orig_begin_period = $begin_period; $orig_end_period = $end_period; // Define item period header $period = ((strlen($begin_period)) || (strlen($end_period))) ? " (" . _("period") . " " : ""; $period .= (strlen($begin_period)) ? _("from") . " " . $begin_period : ""; $period .= (strlen($end_period)) ? " " : ""; $period .= (strlen($end_period)) ? _("till") . " " . $end_period : ""; $period .= ((strlen($begin_period)) || (strlen($end_period))) ? ")" : ""; // Set output file info $_PAGE_INFO['report_type'] = $report_info['report_type']; $_PAGE_INFO['file'] = _("Equip_journal") . "_" . strtoupper($customer['klantnaam']) . "_" . str_replace("-", "",$date) . "." . $_PAGE_INFO['report_type']; $_PAGE_INFO['dest'] = $report_info['dest']; $_PAGE_INFO['document'] = ""; // Clear/delete array $_PAGE_INFO['delete'] = array(); // Clear/delete debug info if (isset($_SESSION[$_PAGE_INFO['id']]['log'])) { // Restart session SessionStart(); unset($_SESSION[$_PAGE_INFO['id']]['log']); // Stop session SessionStop(); } // Retrieve all device types $types = db_fetch_system_devices($report_info['i18n']); // Create header info if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_header(array(subject => "Log equipment" , header => _("Log equipment") . " - " . $customer['bedrijfsnaam'] , data => array( array("Date", str_replace(" ", " / ", $datetime)) , array("Timezone", ucfirst($customer['tz'])) , array("MTinfo", strtoupper((is_ReleaseCandidate() ? $_SESSION[$_PAGE_INFO['id']]['release_dir'] : VERSION))), array("User", getUser($_PAGE_INFO['login']['user']['id']))))); } else { // Define variables for first header $header_top_date = _('Date')." : ".$datetime; $header_top_timezone = _('Timezone')." : ".ucfirst($customer['tz']); $header_top_version = "MTinfo : ".VERSION.(is_ReleaseCandidate() ? " - " . $_SESSION[$_PAGE_INFO['id']]['release_dir'] : ""); $header_top_user = _('User')." : ".getUser($_PAGE_INFO['login']['user']['id']); $header_top_start = _('Start report period')." : ".$begin_period; $header_top_end = _('End report period')." : ".$end_period; // Define first header $header_top = array($header_top_date,$header_top_timezone,$header_top_version,$header_top_user,$header_top_start,$header_top_end); // Define second header $all_fields = array("Timestamp", "Company", _("ID code")." ".ucwords($_SESSION[$_PAGE_INFO['id']]['skin_name']), _("ID code")." "._("owner"), "Equipment type"); if (is_array($types)) { // Check if measurement is selected foreach($types as $type) { if (strlen($report_info[$type['id'] . "_left_ids"])) { if ((isset($report_info["switch_status_" . $type['id']])) && !(isset($header_measurement))) { array_push($all_fields, "Measurement",_('Duration')." ".strtolower(_('Measurement'))); $header_measurement = TRUE; } } } // Check if detection is selected foreach($types as $type) { if (strlen($report_info[$type['id'] . "_left_ids"])) { if ((isset($report_info["short_circuit_status_" . $type['id']])) && !(isset($header_detection))) { array_push($all_fields, "detection",_('Duration')." "._('detection')); $header_detection = TRUE; break; } } } // Check if short circuit is selected foreach($types as $type) { if (strlen($report_info[$type['id'] . "_left_ids"])) { if ((isset($report_info["relais_status_" . $type['id']])) && !(isset($header_short_circuit))) { array_push($all_fields, "short circuit"); $header_short_circuit = TRUE; break; } } } // Check if battery is selected foreach($types as $type) { if (strlen($report_info[$type['id'] . "_left_ids"])) { if ((isset($report_info["battery_status_" . $type['id']])) && !(isset($header_battery))) { array_push($all_fields, "Battery"); $header_battery = TRUE; break; } } } // Check if detection is selected because gps is linked to detection foreach($types as $type) { if (strlen($report_info[$type['id'] . "_left_ids"])) { if ((isset($report_info["short_circuit_status_" . $type['id']])) && !(isset($header_gps))) { array_push($all_fields, "Gps"); $header_gps = TRUE; break; } } } } // if nothing is set erase array $all_fields, so print nothing if (!isset($header_measurement) && !isset($header_detection) && !isset($header_short_circuit) && !isset($header_battery) && !isset($header_gps) ) { unset($all_fields); } else { // Capitalize second header $all_fields_cap = array(); foreach($all_fields as $field) { array_push($all_fields_cap, ucfirst(_($field))); } } // Create document header report_header(); // Create first line header foreach ($header_top as $header_top_item => $header_top_value) { report_data(array(value => array($header_top_value))); } // Empty line empty_line(); // Create second line header report_data(array(value => $all_fields_cap)); } // Initial values $first = TRUE; $log_time_overall = FALSE; $con_hickup_overall = FALSE; $meas_hickup_overall = FALSE; $log_rt = ""; $log_zkl = ""; if (is_array($types)) { foreach($types as $type) { if (strlen($report_info[$type['id'] . "_left_ids"])) { $items = split(",", $report_info[$type['id']. "_left_ids"]); if (is_array($items)) { foreach($items as $item) { // Clear data $csv_data = array(); // Check if equipment has valid status => needed for periodic reports!!! $lance_status = (db_ver_rights_user_one_valid($_PAGE_INFO['login']['user']['id'], "menu:rapportages:root")) ? array("service","productie","winkel","actief","afgeschreven","verloren") : array("service","winkel","actief"); $lance_status = (isset($_PAGE_INFO['login']['project']['id'])) ? array("actief") : $lance_status; $cust_status = (isset($_PAGE_INFO['login']['project']['id'])) ? array("actief") : ""; // Get lance info $lance = db_fetch_lance($item, "", 1); // Reset periods $begin_period = $orig_begin_period; $end_period = $orig_end_period; // Is this a rented device? => Then show only periods in which it was rented if (($lance['gebruiker'] == $_PAGE_INFO['login']['customer']['id']) && ($lance['eigenaar'] != $_PAGE_INFO['login']['customer']['id'])) { // Get last log_versienumber $log_versionnumber = db_fetch_lance_versionnumber($item, array(array("gebruiker")), TRUE); // Define new begin period if ((!strlen($begin_period)) || ($log_versionnumber['t'] > convert_datetime($begin_period))) { $begin_period = convert_datetime($log_versionnumber['t'], TRUE); } // Define new end period if ((strlen($end_period)) && ($log_versionnumber['t'] > convert_datetime($end_period))) { $end_period = convert_datetime($log_versionnumber['t'], TRUE); } } if ((in_array($lance['lans_status'], $lance_status)) && ((!is_array($cust_status)) || in_array($lance['klant_status'], $cust_status))) { // Skip first because the header print empty lines, so no new page needed if (!$first) { // New page report_new_page(); } // Reset first flag $first = FALSE; // Fetch valid logfiles used in this period if ((!isset($_SESSION[$_PAGE_INFO['id']]['table'])) || ($_SESSION[$_PAGE_INFO['id']]['table'] & 0x01)) { $log_files = db_fetch_lance_log_files($item, $begin_period, $end_period); // Save original log files(used with items which have only the log_zkl) $log_files_corrupt = $log_files; // Save non corrupted log files(used with items which have only the log_zkl) $log_files_non_corrupt = $log_files; } // Do not skip when only log_zkl has been used if ((!isset($_SESSION[$_PAGE_INFO['id']]['table'])) || ($_SESSION[$_PAGE_INFO['id']]['table'] != 0x01)) { // Skip corrupt logs (now handled by the log_realtime) $backup = $log_files; $log_files = ""; if (is_array($backup)) { foreach($backup as $log_file_item) { // Check for corrupt entries if (!db_check_lance_log_corrupted($item, $log_file_item['sdcard'], $log_file_item['rpgmcount'], $log_file_item['startup'])) { // Create array when not exits if (!is_array($log_files)) { $log_files = array(); } // Not corrupt => Add to array array_push($log_files, $log_file_item); } else { // Debug purposes DBG("corrupted log (zkl: " . $item . ", sdcard: " . $log_file_item['sdcard'] . ", rpgmcount: " . $log_file_item['rpgmcount'] . ", startup: " . $log_file_item['startup'] . ")"); } } } // Save non corrupted log files(used with items which have only the log_zkl) $log_files_non_corrupt = $log_files; } // Fetch valid log_realtime entries used in this period (non-interpreted) if ((!isset($_SESSION[$_PAGE_INFO['id']]['table'])) || ($_SESSION[$_PAGE_INFO['id']]['table'] & 0x02)) { // For debug purposes => Get execution times if ($_SESSION[$_PAGE_INFO['id']]['dbg']['mask'] & 0x01) { // Get starting time $log_start = microtime_float(); } $log_rt = db_fetch_lance_logrt($item, 0, $begin_period, $end_period, FALSE); // For debug purposes => store entries & logfiles if ($_SESSION[$_PAGE_INFO['id']]['dbg']['mask'] & 0x01) { // Get end time $log_end = microtime_float(); // Debug info DBG("Fetch " . $lance['idcode'] . " LOG_RT : " . ($log_end - $log_start) . "[s], items: " . sizeof($log_rt)); } } // Check next log_tcp and log_realtime entry (needed to detect end period) if ((is_array($log_rt)) && strlen($end_period)) { $next_log_rt = db_fetch_lance_logrt($item, 0, convert_datetime(convert_datetime($end_period)+1, TRUE), "", FALSE, 1); $next_log_tcp = db_fetch_lance_tcp_status($item, convert_datetime($log_rt[sizeof($log_rt)-1]['t'], TRUE), TRUE); } // Check previous log_tcp and log_realtime entry (needed to detect begin period) if ((is_array($log_rt)) && strlen($begin_period)) { $prev_log_rt = db_fetch_lance_logrt($item, 1, "", convert_datetime(convert_datetime($begin_period)-1, TRUE), FALSE, 1); $prev_log_tcp = db_fetch_lance_tcp_status($item, convert_datetime($log_rt[0]['t'], TRUE), FALSE); } // Init log_rt => Add first entry (needed for battery) to array? if ((is_array($log_rt)) && (is_array($prev_log_rt)) && (is_array($prev_log_tcp))) { // Previous log_tcp before previous log_realtime if ($prev_log_tcp['t'] < $prev_log_rt[0]['t']) { // Add entry $log_rt = array_merge(array($prev_log_rt[0]), $log_rt); // Adapt t value // We can do this because there must be a begin_period value otherwhise there was no prev_log_rt value $log_rt[0]['t'] = convert_datetime($begin_period); } } // For debug purposes => store entries & logfiles if ($_SESSION[$_PAGE_INFO['id']]['dbg']['mask'] & 0x01) { // Restart session SessionStart(); $_SESSION[$_PAGE_INFO['id']]['log']['log_files'] = $log_files; $_SESSION[$_PAGE_INFO['id']]['log']['prv_log_rt'] = $prev_log_rt; $_SESSION[$_PAGE_INFO['id']]['log']['next_log_rt'] = $next_log_rt; $_SESSION[$_PAGE_INFO['id']]['log']['prv_log_tcp'] = $prev_log_tcp; $_SESSION[$_PAGE_INFO['id']]['log']['next_log_tcp'] = $next_log_tcp; // Stop session SessionStop(); } /************************************/ /* Idcode/sts/owner/ect */ /************************************/ if (strtolower($_PAGE_INFO['report_type']) == "pdf") { // Get material info $info = db_fetch_lance($item, "", 1); // Get idcode/realtime remark $idcode = ($info['idcode'] == $info['serienr']) ? $info['idcode'] : $info['idcode'] . " - " . $info['serienr']; $idcode .= (strlen($info['rtstatus'])) ? " (" . $info['rtstatus'] . ")" : ""; report_data(array(value => array($idcode) , border => array("") , bold => array(1) , align => array("L") , font_size => array(11) , cell_width => array(70,110) , check_page_end => 0 , ishtml => array(array(type => "bookmark", data => $idcode, parent => 0, bold => 1)), nr_lines => 2 )); // Default table layout $report_data = array(border => array("LRBT","LRBT") , bold => array(0,0) , align => array("L","L") , font_size => array(8,8) , cell_width => array(70,110) , check_page_end => 1); // Type equipement report_data(array_merge($report_data, array(value => array("Equipment type", $type['naam'])))); // Owner $owner = db_fetch_customer($info['eigenaar'], 1); report_data(array_merge($report_data, array(value => array("Owner", ucfirst($owner['bedrijfsnaam']))))); // Status report_data(array_merge($report_data, array(value => array(_("Status") . " " . _("owner"), ucfirst(_($info['klant_status'])))))); // Device rented => Current user if (($info['eigenaar'] != $info['gebruiker']) && (strlen($info['gebruiker']))) { $rented_to = db_fetch_customer($info['gebruiker'], 1); report_data(array_merge($report_data, array(value => array("Rented to", $rented_to['bedrijfsnaam'])))); } // Next service date (which date comes first "next service" or "switch 3000 cells replace"?) report_data(array_merge($report_data, array(value => array("Next service date", strip_time(NextService($info['onderhoud'],$info['sw3000_onderhoud'])))))); // Last contact MTinfo $last_contact = ""; $last_log_zkl = db_fetch_lance_log_file_last_entry($item, "", "log_zkl"); $last_log_rt = db_fetch_lance_log_file_last_entry($item, "", "log_realtime"); if (is_array($last_log_zkl)) { // Valid timestamp? if (valid_gps_timestamp(convert_datetime($last_log_zkl['t'], TRUE))) { // Get last entry timestamp $last_contact['zkl'] = convert_datetime($last_log_zkl['t'], TRUE); } } if (is_array($last_log_rt)) { $last_contact['rt'] = convert_datetime($last_log_rt['t'], TRUE); // We now check the tcp connection during this period if (!is_array(db_fetch_lance_tcp_status($item, $last_contact['rt'], TRUE))) { // Session still active? $last_contact['rt'] = $datetime; } } // Detect the $use_table = (convert_datetime($last_contact['rt']) > convert_datetime($last_contact['zkl'])) ? "rt" : "zkl"; report_data(array_merge($report_data, array(value => array("Last contact MTinfo 3000", $last_contact[$use_table])))); } /************************************/ /* Last known status */ /************************************/ // Item selected? if (isset($report_info["last_status_" . $type['id']])) { if (strtolower($_PAGE_INFO['report_type']) == "pdf") { // Print empty line empty_line(); // Header report_data(array(value => array(_("Last known status") . " " . $info['idcode'] . $period), border => array("LRBT") , bold => array(1) , align => array("L") , font_size => array(9) , cell_width => "" , check_page_end => 1 , ishtml => array(array(type => "bookmark", data => _("Last known status") . " " . $info['idcode'], parent => $_PAGE_INFO['bookmark_handle'], bold => 0)), nr_lines => 2 )); // // Array containing last known status params // $LKS = array(array(item => MEASUREMENT, report_txt => "Measurement on/off", cap => "meting", param => "", def => "switched off", log_rt_sts => (is_array($log_rt)) ? interpret_log_rt($log_rt[sizeof($log_rt)-1]) : "", log_zkl_sts => (is_array($log_files)) ? db_fetch_lance_log_measurement_status($item, 0, 7, "", $end_period, array($log_files[sizeof($log_files)-1])) : ""), array(item => DETECTION, report_txt => "Detection status", cap => "meting", param => "", def => "nok", log_rt_sts => (is_array($log_rt)) ? interpret_log_rt($log_rt[sizeof($log_rt)-1]) : "", log_zkl_sts => (is_array($log_files)) ? db_fetch_lance_log_shortcircuit_status($item, 0, "", $end_period, array($log_files[sizeof($log_files)-1])) : ""), array(item => KEYSWITCH, report_txt => "Key switch", cap => "sleutelschakelaar", param => "", def => "Operational", log_rt_sts => (is_array($log_rt)) ? interpret_log_rt($log_rt[sizeof($log_rt)-1]) : "", log_zkl_sts => (is_array($log_files)) ? db_fetch_lance_log_keyswitch_status($item, 0, "", $end_period, array($log_files[sizeof($log_files)-1])) : ""), array(item => GPS, report_txt => "GPS position", cap => "gps", param => "", def => "", log_rt_sts => (is_array($log_rt)) ? interpret_log_rt($log_rt[sizeof($log_rt)-1]) : "", log_zkl_sts => (is_array($log_files)) ? db_fetch_lance_log_gps_info($item, 0, "", $end_period, 1, array($log_files[sizeof($log_files)-1])) : "")); // // Add number of batteries to LKS array // if ($type['nr_batterijen']) { for ($i = 0; $i < $type['nr_batterijen']; $i++) { array_push($LKS, array(item => BATTERY, report_txt => _("Battery") . " " . ($i+1) . " " . _("status"), cap => "", param => $i, def => "removed", log_rt_sts => (is_array($log_rt)) ? db_fetch("log_realtime", "*", "zkl='" . $item . "' and batt" . ($i + 1) . "_niveau is not NULL ORDER by id DESC LIMIT 1") : "", log_zkl_sts => (is_array($log_files)) ? array(array(status => db_fetch_lance_log_battery_status($item, $i, 1, "", $end_period, array($log_files[sizeof($log_files)-1])), V => db_fetch_lance_log_battery_info($item, $i, 1, "", $end_period, array($log_files[sizeof($log_files)-1])))) : "")); } } // For debug purposes => store entries & logfiles if ($_SESSION[$_PAGE_INFO['id']]['dbg']['mask'] & 0x01) { // Restart session SessionStart(); $_SESSION[$_PAGE_INFO['id']]['LKS'] = $LKS; // Stop session SessionStop(); } // Handle params item by item foreach($LKS as $LKS_item) { // Valid or no capability required if ((!strlen($LKS_item['cap'])) || (db_check_system_device_capabilities($type['id'], $LKS_item['cap']))) { // Initial values $status = ""; $timestamp = ""; $hyperlink = ""; $default = ""; // // LOG_ZKL (LKS) // if (is_array($LKS_item['log_zkl_sts'])) { // Check items foreach($LKS_item['log_zkl_sts'] as $log_zkl_sts) { switch($LKS_item['item']) { case MEASUREMENT: // Parse major switch($log_zkl_sts['major']) { case MAJ_MEAS_ON: $status['zkl'] = "switched on"; break; // This includes no measure log entry and power up entry default: $status['zkl'] = "switched off"; break; } break; case DETECTION: // Parse majors (not possible to detect only last because of skipping errors) switch($log_zkl_sts['major']) { case MAJ_SHORTCIR_OK: $status['zkl'] = "ok"; break; // Only for debug purposes case MAJ_SHORTCIR_ERROR: break; // This includes measurement faults default: $status['zkl'] = "nok"; break; } break; case KEYSWITCH: // Parse minors switch($log_zkl_sts['minor']) { case MIN_SWITCH3000_KEY_OP_ON: $status['zkl'] = "On (overruled)"; break; case MIN_SWITCH3000_KEY_OP_OFF: $status['zkl'] = "Off (overruled)"; break; default: $status['zkl'] = "Operational"; break; } break; case GPS: $status['zkl'] = $log_zkl_sts['latitude'] . ", " . $log_zkl_sts['longitude']; $hyperlink['zkl'] = array("",array(type => "link", data => GOOGLE_MAPS . "maps?q=" . $status['zkl'],"")); break; case BATTERY: if (is_array($log_zkl_sts['status'])) { $status['zkl'] = _($log_zkl_sts['status'][0]['status']); } else { $status['zkl'] = _($LKS_item['def']); // Set flag $default['zkl'] = TRUE; } if ($status['zkl'] != _("removed")) { if (is_array($log_zkl_sts['V'])) { $status['zkl'] .= " / " . $log_zkl_sts['V'][0]['niveau'] . " [V]"; } } break; default: break; } } // Fetch last log file entry $last_entry = db_fetch_lance_log_file_last_entry($item, $log_files[sizeof($log_files)-1]); // Valid timestamp => use log time if (valid_gps_timestamp(convert_datetime($last_entry['t'], TRUE))) { // Get last entry timestamp $timestamp['zkl'] = convert_datetime($last_entry['t'], TRUE); // Clear log time flag $log_time = FALSE; } else { // Get last entry timestamp $timestamp['zkl'] = convert_datetime($last_entry['t_log'], TRUE); // Set log time flag $log_time = TRUE; } // Exceed end of selected period? // We can do this because then the begin is before the end of selected period, otherwhise this log files was not selected if (strlen($end_period)) { if (convert_datetime($timestamp['zkl']) > convert_datetime($end_period)) { $timestamp['zkl'] = $end_period; } } } // // Perform extra action LOG_ZKL? // switch($LKS_item['item']) { case DETECTION: // Be sure that the measurement was on! if ((strlen($status['zkl'])) && ($status['zkl'] == "ok")) { // Find out if the measurement was on (last entry before the requested timestamp in the same log file) $measure_status = db_fetch_lance_log_measurement_status($item, 1, 7, "", $timestamp['zkl'], array($log_files[sizeof($log_files)-1])); // Check measurement status $status['zkl'] = ((is_array($measure_status)) && ($measure_status[0]['major'] == MAJ_MEAS_ON)) ? $status['zkl'] : "nok"; } // Be sure the switch was on! if ((strlen($status['zkl'])) && ($status['zkl'] == "ok") && (db_check_system_device_capabilities($type['id'], "kortsluiting schakelen"))) { // Find out if the switch 3000 was on (last entry before the requested timestamp) $switch_status = db_fetch_lance_switch3000_state($item, 1 , "", $timestamp['zkl']); // Check redundant sections $status['zkl'] = (($switch_status['state'] & 0x06 == 0x06) || ($switch_status['state'] & 0x09 == 0x09)) ? $status['zkl'] : "nok"; } // No break on purpose => handle also default state default: // No array in the last log file => Default value (when available) if ((is_array($log_files)) && (!is_array($LKS_item['log_zkl_sts']))) { if (strlen($LKS_item['def'])) { // Use default value $status['zkl'] = $LKS_item['def']; // Set flag $default['zkl'] = TRUE; // Fetch last log file entry $last_entry = db_fetch_lance_log_file_last_entry($item, $log_files[sizeof($log_files)-1]); // Valid timestamp => use log time if (valid_gps_timestamp(convert_datetime($last_entry['t'], TRUE))) { // Get last entry timestamp $timestamp['zkl'] = convert_datetime($last_entry['t'], TRUE); // Clear log time flag $log_time = FALSE; } else { // Get last entry timestamp $timestamp['zkl'] = convert_datetime($last_entry['t_log'], TRUE); // Set log time flag $log_time = TRUE; } } } break; } // // LOG_REALTIME (LKS) // if (is_array($LKS_item['log_rt_sts'])) { switch($LKS_item['item']) { case MEASUREMENT: $status['rt'] = $LKS_item['log_rt_sts']['detection']['active'] ? "switched on" : "switched off"; break; case DETECTION: $status['rt'] = ($LKS_item['log_rt_sts']['detection']['active'] && $LKS_item['log_rt_sts']['detection']['ok'] && (($LKS_item['log_rt_sts']['switch3000']['on']) || (!db_check_system_device_capabilities($type['id'], "kortsluiting schakelen")))) ? "ok" : "nok"; break; case KEYSWITCH: $status['rt'] = $LKS_item['def']; $status['rt'] = ($LKS_item['log_rt_sts']['switch3000']['key']['on']) ? "On (overruled)" : $status['rt']; $status['rt'] = ($LKS_item['log_rt_sts']['switch3000']['key']['off']) ? "Off (overruled)" : $status['rt']; // Default value used? if ((!$LKS_item['log_rt_sts']['switch3000']['key']['on']) && (!$LKS_item['log_rt_sts']['switch3000']['key']['off'])) { // Set flag $default['rt'] = TRUE; } break; case GPS: // Last entry log realtime has valid GPS? if (($LKS_item['log_rt_sts']['gps']['fix']) && ($LKS_item['log_rt_sts']['gps']['latitude']) && ($LKS_item['log_rt_sts']['gps']['longitude'])) { $status['rt'] = $LKS_item['log_rt_sts']['gps']['latitude'] . ", " . $LKS_item['log_rt_sts']['gps']['longitude']; $hyperlink['rt'] = array("",array(type => "link", data => GOOGLE_MAPS . "maps?q=" . $status['rt'],"")); } else { // We check for the last valid GPS foreach($log_rt as $log_rt_item) { if (($log_rt_item['gps_fix']) && ($log_rt_item['latitude']) && ($log_rt_item['longitude'])) { $status['rt'] = $log_rt_item['latitude'] . ", " . $log_rt_item['longitude']; $hyperlink['rt'] = array("",array(type => "link", data => GOOGLE_MAPS . "maps?q=" . $status['rt'],"")); } } } break; case BATTERY: if (is_array($LKS_item['log_rt_sts'][0])) { switch($LKS_item['param']) { case 0: $mask = 0x0F00; $shift = 8; break; case 1: $mask = 0xF000; $shift = 12; break; default: break; } switch(($LKS_item['log_rt_sts'][0]['mcu_state'] & $mask) >> $shift) { case 7: $status['rt'] = _("verwijderd"); break; case 3: $status['rt'] = _("leeg"); break; case 1: $status['rt'] = _("alarm"); break; case 0: $status['rt'] = _("ok"); break; default: break; } if ($status['rt'] != _("verwijderd")) { $status['rt'] .= " / " . $LKS_item['log_rt_sts'][0]["batt" . ($LKS_item['param'] + 1) . "_niveau"] . " [V]"; } } break; default: break; } if (strlen($status['rt'])) { // Get timestamp $timestamp['rt'] = convert_datetime($log_rt[sizeof($log_rt)-1]['t'], TRUE); // Next log_realtime entry available? if (is_array($next_log_rt)) { // Next log_tcp entry available? if ((!is_array($next_log_tcp)) || ($next_log_tcp['t'] > $next_log_rt[0]['t'])) { // No changes within this the session or session still active $timestamp['rt'] = (strlen($end_period)) ? $end_period : $datetime; } } else { // No next log_tcp entry available? if (!is_array($next_log_tcp)) { // No end selected if (!strlen($end_period)) { // Get last known tcp status $last_log_tcp = db_fetch_lance_tcp_status($item, $datetime, FALSE); if ($last_log_tcp['event'] == "connect") { // Session still active? $timestamp['rt'] = $datetime; } } else { // Session still active? $timestamp['rt'] = $end_period; } } } } } // // Perform extra action LOG_REALTIME? // switch($LKS_item['item']) { default: break; } // // Valid status/timestamp => Write data // if ((is_array($timestamp)) && (is_array($status))) { // Detect which is the newest, log_realtime or log_zkl // Most of the time the Log_realtime can be used, the exception are devices without sim card (uploading log files not yet implemented) // Real values are preferable above "default" values if ((is_array($default)) && (sizeof($default) == 1) && (strlen($timestamp['zkl'])) && (strlen($timestamp['rt']))) { if (isset($default['rt'])) { $use_table = "zkl"; } else { $use_table = "rt"; } } else if ((strlen($timestamp['zkl'])) && (strlen($timestamp['rt']))) { // log_zkl newer or a invalid timestamp? if ((convert_datetime($timestamp['zkl']) > convert_datetime($timestamp['rt'])) && ((convert_datetime($timestamp['zkl'])) < convert_datetime($datetime))) { $use_table = "zkl"; } else { $use_table = "rt"; } } else if (strlen($timestamp['rt'])) { $use_table = "rt"; } else if (strlen($timestamp['zkl'])) { $use_table = "zkl"; } // For debug purposes => store table which will be used for last known status items if ($_SESSION[$_PAGE_INFO['id']]['dbg']['mask'] & 0x01) { // Restart session SessionStart(); $_SESSION[$_PAGE_INFO['id']]['LKS']['use_table'][$LKS_item['item']] = $use_table; // Stop session SessionStop(); } // Check whether log file time was used if (($log_time) && ($use_table == "zkl")) { // Add note $timestamp[$use_table] .= "\xC2\xB9"; // Set overall flag (needed for footnote) $log_time_overall = TRUE; } // Write to report report_data(array(value => array($LKS_item['report_txt'], ucfirst(_($status[$use_table])), $timestamp[$use_table]), border => array("LRBT","LRBT","LRBT") , bold => array(0,0,0) , align => array("L","L","L") , font_size => array(8,8,8) , cell_width => array(70,55,55) , check_page_end => 1 , ishtml => $hyperlink[$use_table] )); } else { // No valid data => status unknown if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_data(array(value => array($LKS_item['report_txt'],"-","-") , border => array("LRBT","LRBT","LRBT") , bold => array(0,0,0) , align => array("L","L","L") , font_size => array(8,8,8) , cell_width => array(70,55,55) , check_page_end => 1 )); } } } } } } /************************************/ /* Owner history */ /************************************/ // Item selected? if (isset($report_info["history_" . $type['id']])) { if (strtolower($_PAGE_INFO['report_type']) == "pdf") { // Only owner can see this history if ($info['eigenaar'] == $_PAGE_INFO['login']['customer']['id']) { // Print empty line empty_line(); // Header if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_data(array(value => array(_("Owner") . " " . _("geschiedenis") . " " . $info['idcode'] . $period), border => array("LRBT") , bold => array(1) , align => array("L") , font_size => array(9) , cell_width => "" , check_page_end => 1 , ishtml => array(array(type => "bookmark", data => _("Owner") . " " . _("geschiedenis") . " " . $info['idcode'], parent => $_PAGE_INFO['bookmark_handle'], bold => 0)), nr_lines => 2 )); } // Default table layout $report_data = array(border => array("LRBT","LRBT","LRBT") , bold => array(0,0,0) , align => array("L","L","L") , font_size => array(8,8,8) , cell_width => array(63,62,55) , check_page_end => 1 ); if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_data(array_merge($report_data, array(value => array("Owner", "Rent to", "Timestamp"), bold => array(1,1,1), new_page_hdr => 1))); } // Initial values $owner_log = ""; $owner_report = ""; $user_log = ""; $user_begin = ""; $user_report = ""; $in_use = FALSE; $counter = 0; // Fetch all log_versienummer info $log_versionnumber = db_fetch_lance_versionnumber($info['id'], array(array("eigenaar", "gebruiker"))); if (is_array($log_versionnumber)) { foreach($log_versionnumber as $log) { $changes = explode(",", $log['wijzigingen']); if (is_array($changes)) { foreach($changes as $change) { switch($change) { case "eigenaar": // Check valid timestamp $converted_time = convert_timeperiod(convert_datetime($log['t'], TRUE), "", $begin_period, $end_period); if (is_array($converted_time)) { // We could miss first owner entry if ((!$counter) && (is_array($owner_log))) { // Check valid timestamp $converted_time_first = convert_timeperiod(convert_datetime($owner_log['t'], TRUE), convert_datetime($log['t'], TRUE), $begin_period, $end_period); if (is_array($converted_time_first)) { // Unassigned? if (!is_null($owner_log['eigenaar'])) { // Get customer info $cust = db_fetch_customer($owner_log['eigenaar'], 1); } // Write info to report if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_data(array_merge($report_data, array(value => array((is_null($owner_log['eigenaar'])) ? _("Unassigned") : $cust['bedrijfsnaam'], "", $converted_time_first[0]), ishtml => (($in_use) ? array(array(type => "image", left => 63, width => 25, filename => "rent_arrow_middle.png")) : "")))); } // Store owner id $owner_report = $owner_log['eigenaar']; // Increment counter $counter++; } } // Unassigned? if (!is_null($log['eigenaar'])) { // Get customer info $cust = db_fetch_customer($log['eigenaar'], 1); } // No duplicated entries if ($log['eigenaar'] != $owner_report) { // User became owner? if ((!$in_use) || ($user_log['gebruiker'] != $log['eigenaar'])) { // Write info to report if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_data(array_merge($report_data, array(value => array((is_null($log['eigenaar'])) ? _("Unassigned") : $cust['bedrijfsnaam'], "", $converted_time[0]), ishtml => (($in_use) ? array(array(type => "image", left => 63, width => 25, filename => "rent_arrow_middle.png")) : "")))); } } else { // Write info to report if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_data(array_merge($report_data, array(value => array($cust['bedrijfsnaam'], " " . _("Duration") . ": " . CalculateDuration(convert_datetime($user_begin, TRUE), convert_datetime($log['t'], TRUE)), $converted_time[0]), ishtml => array(array(type => "image", left => 47, width => 98, filename => "rent_arrow_end.png"))))); } // Clear flag $in_use = FALSE; } // Store owner id $owner_report = $log['eigenaar']; // Increment counter $counter++; } } // Store log $owner_log = $log; break; case "gebruiker": // Check valid timestamp $converted_time = convert_timeperiod(convert_datetime($log['t'], TRUE), "", $begin_period, $end_period); if (is_array($converted_time)) { // We could miss first owner entry if ((!$counter) && (is_array($owner_log))) { // Check valid timestamp $converted_time_first = convert_timeperiod(convert_datetime($owner_log['t'], TRUE), convert_datetime($log['t'], TRUE), $begin_period, $end_period); if (is_array($converted_time_first)) { // Unassigned? if (!is_null($owner_log['eigenaar'])) { // Get customer info $cust = db_fetch_customer($owner_log['eigenaar'], 1); } // Write info to report if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_data(array_merge($report_data, array(value => array((is_null($owner_log['eigenaar'])) ? _("Unassigned") : $cust['bedrijfsnaam'], "", $converted_time_first[0]), ishtml => (($in_use) ? array(array(type => "image", left => 63, width => 25, filename => "rent_arrow_middle.png")) : "")))); } // Store owner id $owner_report = $owner_log['eigenaar']; // Increment counter $counter++; } } // Unassigned? if (!is_null($log['gebruiker'])) { // Get customer info $cust = db_fetch_customer($log['gebruiker'], 1); } // No duplicated entries if ($log['gebruiker'] != $user_report) { // Write info to report if (!is_null($log['gebruiker'])) { if (!$in_use) { if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_data(array_merge($report_data, array(value => array("", " " . $cust['bedrijfsnaam'], $converted_time[0]), ishtml => array(array(type => "image", left => 0, width => 210, filename => "rent_arrow_start.png"))))); } // Set flag $in_use = TRUE; // Store timestamp $user_begin = $log['t']; } } else { if ($in_use) { if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_data(array_merge($report_data, array(value => array("", " " . _("Duration") . ": " . CalculateDuration(convert_datetime($user_begin, TRUE), convert_datetime($log['t'], TRUE)), $converted_time[0]), ishtml => array(array(type => "image", left => 47, width => 98, filename => "rent_arrow_end.png"))))); } // Clear flag $in_use = FALSE; } } // Store user id $user_report = $log['gebruiker']; // Increment counter $counter++; } } // Store log $user_log = $log; break; default: break; } } } } } // Still rented? => Adapt last entry if ($in_use) { if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_data(array_merge($report_data, array(value => array("", " " . _("Duration") . ": " . CalculateDuration(convert_datetime($user_begin, TRUE), $datetime), $datetime), ishtml => array(array(type => "image", left => 51, width => 98, filename => "rent_arrow_busy.png"))))); } } // Empty line if (!$counter) { if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_data(array_merge($report_data, array(value => array("-", "-", "-")))); } } } } } /************************************/ /* Overview changes */ /************************************/ if (strtolower($_PAGE_INFO['report_type']) == "pdf") { // Check if overview changes is selected if (isset($report_info["changes_" . $type['id']])) { // Print empty line empty_line(); // Header report_data(array(value => array(ucfirst(_("logbook")). " " . $info['idcode'] . $period), border => array("LRBT") , bold => array(1) , align => array("L") , font_size => array(9) , cell_width => "" , check_page_end => 1 , ishtml => array(array(type => "bookmark", data => ucfirst(_("logbook")). " " . $info['idcode'], parent => $_PAGE_INFO['bookmark_handle'], bold => 0)), nr_lines => 3 )); // Default table layout $report_data = array(border => array("LRBT","LRBT","LRBT","LRBT") , bold => array(0,0,0,0) , align => array("C","L","L","L") , font_size => array(8,8,8,8) , cell_width => array(15,40,70,55) , check_page_end => 1 ); report_data(array_merge($report_data, array(value => array("Index", "Change","Changed to","Timestamp"), bold => array(1,1,1,1), new_page_hdr => 1))); // Check if there is an end time. no end time take current time $end_time = (empty($orig_end_period)) ? convert_datetime($last_contact[$use_table]) : convert_datetime($orig_end_period); // Get all changes of the lance with $lance['id'] between begin and end time $zkl_changes = db_fetch_lance_log_versionnumber($lance['id'],convert_datetime($orig_begin_period), $end_time); // Check if there where changes if (!empty($zkl_changes)) { $counter_changes=1; // Loop by all changes foreach ( $zkl_changes as $zkl_change ) { // Split all changes $change_items= explode(",", $zkl_change['wijzigingen']); if (!empty($change_items)) { // Loop by multiple changes foreach ($change_items as $change_item) { // Switch to check if the change has to be printed switch ($change_item) { case 'eigenaar': case 'gebruiker': case 'secure_key': case 'bedrag': case 'valuta': case 'secure_server': case 'wavecom_versie': case 'wavecom_serienr': case 'wavecom_revisie': case 'mcu_revisie': case 'facturatie'; case 'device': case 'lans_status': case 'klant_status': case 'imsi': case 'gprs_apn': break; default: // Switch to get the correct translation for in the pdf switch ($change_item) { case 'serienr': $change_item_name = _('ID code')." ".ucfirst(_($owner['bedrijfsnaam'])); break; case 'fabrieksnr': $change_item_name = _('Factory number'); break; case 'productie': $change_item_name = _('Production date'); break; case 'mcu_versie': $change_item_name = _('Version MCU'); break; case 'wcpu_versie': $change_item_name = _('Version WCPU'); break; case 'pcb_versie': $change_item_name = _('Version PCB'); break; case 'pcb_revisie': $change_item_name = _('Revision PCB'); break; case 'mech_versie': $change_item_name = _('Version mechanic'); break; case 'sw3000_dversie': $change_item_name = _('Version SWITCH 3000 (D)'); break; case 'sw3000_mversie': $change_item_name = _('Version SWITCH 3000 (M)'); break; case 'ualfat_versie': $change_item_name = _('Version ualfat'); break; case 'idcode': $change_item_name = _('ID code'). " "._('owner'); break; case 'telefoonnr': $change_item_name = _('Telephone'); break; case 'sim': $change_item_name = _('Sim number'); break; case 'pin': $change_item_name = _('Pin'); break; case 'puk': $change_item_name = _('Puk'); break; case 'imei': $change_item_name = _('Modem IMEI'); break; case 'tcp_server': $change_item_name = _('Tcp-server'); break; case 'sms_server': $change_item_name = _('Sms-server'); break; case 'parent': $change_item_name = _('gateway'); break; case 'opmerking': $change_item_name = _('Remark'); break; case 'i18n': $change_item_name = _('SMS language'); break; case 'tz': $change_item_name = _('Timezone'); break; default: $change_item_name = _($change_item); break; } // Parse value? switch($change_item) { case 'tcp_server': case 'sms_server': $server = db_fetch("server", "*","id=" . $zkl_change[$change_item]); $value = (is_array($server)) ? $server[0]['adres'] : ""; break; case 'parent': $gateway = db_fetch_lance($zkl_change[$change_item], "" , 1); $value = (is_array($gateway)) ? $gateway['idcode'] : ""; break; case 'i18n': $value = ""; $languages = db_fetch_system_lang(); if (is_array($languages)) { $value = _($languages[$zkl_change[$change_item]]); } break; default: $value = $zkl_change[$change_item]; break; } // Calculate number of lines needed for the text $lines_changes = nmr_lines($value, 50); for ($j = 0; $j < sizeof($lines_changes); $j++) { // Get text $text_changes = $lines_changes[$j]; if (sizeof($lines_changes) > 1) { if (!$j) { report_data(array_merge($report_data, array(value => array(($counter_changes), $change_item_name ,$text_changes,convert_datetime($zkl_change['t'],1)), border => array("LRT","LRT","LRT","LRT"), nr_lines => sizeof($lines_changes)))); } else { if (($j + 1) == sizeof($lines_changes)) { report_data(array_merge($report_data, array(value => array("", "" ,$text_changes,""), border => array("LRB","LRB","LRB","LRB")))); } else { report_data(array_merge($report_data, array(value => array("", "" ,$text_changes,""), border => array("LR","LR","LR","LR")))); } } } else { report_data(array_merge($report_data, array(value => array(($counter_changes), $change_item_name ,$value ,convert_datetime($zkl_change['t'],1))))); } } $counter_changes++; break; } } } } } else { // No changes report_data(array_merge($report_data, array(value => array('1','-','-','-')))); } } } /************************************/ /* Overview measurement on/off */ /* detection ok/nok */ /* shortcircuit switching */ /* battery status */ /* sms */ /************************************/ // // Array containing report items // $report_items = array(array(item => MEASUREMENT, report_txt => "Overview measurement on", sel => "switch_status_" . $type['id'], period => TRUE, table => array("log_zkl", "log_realtime")), array(item => DETECTION, report_txt => "Overview detection status", sel => "short_circuit_status_" . $type['id'], period => TRUE, table => array("log_zkl", "log_realtime")), array(item => SHORTCIRCUIT, report_txt => "Overview short circuit switching", sel => "relais_status_" . $type['id'], period => FALSE, table => array("log_zkl", "log_realtime")), array(item => BATTERY, report_txt => "Overview battery status", sel => "battery_status_" . $type['id'], period => FALSE, table => array("log_zkl", "log_realtime")), array(item => SMS, report_txt => "Overview sms", sel => "sms_" . $type['id'], period => FALSE, table => array("log_zkl"))); foreach ($report_items as $report_item) { // Item selected? if (isset($report_info[$report_item['sel']])) { if ((strtolower($_PAGE_INFO['report_type']) == "pdf") || ($report_item['item'] != SMS)) { if (strtolower($_PAGE_INFO['report_type']) == "pdf") { // Print empty line empty_line(); } // For debug purposes => Get execution times if ($_SESSION[$_PAGE_INFO['id']]['dbg']['mask'] & 0x01) { // Determine log action switch($report_item['item']) { case MEASUREMENT: $log_action = "MEASUREMENT"; break; case DETECTION: $log_action = "DETECTION"; break; case SHORTCIRCUIT: $log_action = "SHORTCIRCUIT"; break; case BATTERY: $log_action = "BATTERY"; break; case SMS: $log_action = "SMS"; break; default: $log_action = ""; break; } } if (strtolower($_PAGE_INFO['report_type']) == "pdf") { // Header report_data(array(value => array(_($report_item['report_txt']) . " " . $info['idcode'] . $period), border => array("LRBT") , bold => array(1) , align => array("L") , font_size => array(9) , cell_width => "" , check_page_end => 1 , ishtml => array(array(type => "bookmark", data => _($report_item['report_txt']) . " " . $info['idcode'], parent => $_PAGE_INFO['bookmark_handle'], bold => 0)), nr_lines => 3 )); // Define table fields (index, timestamps, etc) switch($report_item['item']) { case MEASUREMENT: // Default table layout $report_data = array(border => array("LRBT","LRBT","LRBT","LRBT") , bold => array(0,0,0,0) , align => array("C","L","L","L") , font_size => array(8,8,8,8) , cell_width => array(15,55,55,55) , check_page_end => 1 ); report_data(array_merge($report_data, array(value => array("Index", "Measurement on", "Measurement off", "Duration"), bold => array(1,1,1,1), new_page_hdr => 1))); break; case DETECTION: // Gps capabilities? if (db_check_system_device_capabilities($type['id'],"gps")) { // Default table layout $report_data = array(border => array("LRBT","LRBT","LRBT","LRBT","LRBT") , bold => array(0,0,0,0,0) , align => array("C","L","L","L","L") , font_size => array(8,8,8,8,8) , cell_width => array(15,41,41,28,55) , check_page_end => 1 ); $ok_value = db_fetch_system_device_status($type['id'], $report_info['i18n'], "", "ok"); $nok_value = db_fetch_system_device_status($type['id'], $report_info['i18n'], "", "nok"); report_data(array_merge($report_data, array(value => array("Index", $ok_value['display'], $nok_value['display'], "Duration", "Coordinate"), bold => array(1,1,1,1,1), new_page_hdr => 1))); } else { // Default table layout $report_data = array(border => array("LRBT","LRBT","LRBT","LRBT") , bold => array(0,0,0,0) , align => array("C","L","L","L") , font_size => array(8,8,8,8) , cell_width => array(15,55,55,55) , check_page_end => 1 ); report_data(array_merge($report_data, array(value => array("Index", "Detection ok", "Detection nok", "Duration"), bold => array(1,1,1,1), new_page_hdr => 1))); } break; case SHORTCIRCUIT: // Default table layout $report_data = array(border => array("LRBT","LRBT","LRBT") , bold => array(0,0,0) , align => array("C","L","L") , font_size => array(8,8,8) , cell_width => array(15,110,55) , check_page_end => 1 ); report_data(array_merge($report_data, array(value => array("Index", "State", "Timestamp"), bold => array(1,1,1), new_page_hdr => 1))); break; case BATTERY: // Default table layout $value = array("Index"); $border = array("LRBT"); $bold_h = array(1); $bold_t = array(0); $align = array("C"); $font_size = array(8); $cell_width = array(15); $total_width = 110; $total = 0; for($i = 0; $i < $type['nr_batterijen']; $i++) { if ($i < ($type['nr_batterijen'] - 1)) { $width = round($total_width/$type['nr_batterijen']); } else { $width = $total_width - $total; } // Total width $total += $width; array_push($value , "Status" . " " . _("battery") . " " . ($i + 1)); array_push($border , "LRBT"); array_push($bold_h , 1); array_push($bold_t , 0); array_push($align , "L"); array_push($font_size , 8); array_push($cell_width , $width); } array_push($value , "Timestamp"); array_push($border , "LRBT"); array_push($bold_h , 1); array_push($bold_t , 0); array_push($align , "L"); array_push($font_size , 8); array_push($cell_width , 55); $report_data = array(value => $value , border => $border , bold => $bold_t , align => $align , font_size => $font_size , cell_width => $cell_width , check_page_end => 1 ); report_data(array_merge($report_data, array(value => $value, bold => $bold_h, new_page_hdr => 1))); break; case SMS: // Default table layout $report_data = array(border => array("LRBT","LRBT","LRBT","LRBT","LRBT") , bold => array(0,0,0,0,0) , align => array("C","L","L","L","L") , font_size => array(8,8,8,8,8) , cell_width => array(15,35,33,17,80) , check_page_end => 1 ); report_data(array_merge($report_data, array(value => array("Index", "Timestamp", "Telephone", "Status", ucfirst(_("message"))), bold => array(1,1,1,1,1), new_page_hdr => 1))); break; default: break; } } // When only log_zkl => use log_files_corrupt array (all log files included the corrupted ones) if ((in_array("log_zkl", $report_item['table'])) && (sizeof($report_item['table']) == 1)) { $log_files = $log_files_corrupt; } // Initial values $valid_entries = array(); $skip_first = FALSE; $remove_first = FALSE; // log_zkl settings $zkl['cnt'] = 0; $zkl['log'] = ""; // log_realtime settings $rt['begin'] = convert_datetime($begin_period); $rt['end'] = convert_datetime($end_period); // Valid data? if ((is_array($log_files)) || (is_array($log_rt))) { // Check whether log_realtime begins before log_zkl when both tables required if ((in_array("log_zkl", $report_item['table'])) && (in_array("log_realtime", $report_item['table']))) { if ((is_array($log_files)) && (is_array($log_rt))) { if ($log_files[0]['tmin'] > $log_rt[0]['t']) { // End of log_realtime is start of "first" log file $rt['end'] = $log_files[0]['tmin']; // Add dummy log_file entry to log_files array => and skip log files check $log_files = array_merge(array("Dummy"), $log_files); // Set skip and remove flag $skip_first = TRUE; $remove_first = TRUE; } } } // Parse log_files/log_realtime entries do { // "Reset" state // We can do this because a new log file was found $state = ($report_item['period']) ? FIND_BEGIN : FIND_EVENT; $sts = OK; $detection = FALSE; $measurement = FALSE; $switch3000 = (db_check_system_device_capabilities($type['id'], "kortsluiting schakelen")) ? FALSE : TRUE; $keyswitch = OPERATIONAL; $batt[$type['nr_batterijen']] = ""; $valid_entries = array(); // Initial values $stored_data = null; $overruled_time = FALSE; // // LOG_ZKL // if ((is_array($log_files)) && (in_array("log_zkl", $report_item['table'])) && (!$skip_first)) { // For debug purposes => Get execution times if ($_SESSION[$_PAGE_INFO['id']]['dbg']['mask'] & 0x01) { // Get starting time $log_start = microtime_float(); } // Retrieve data switch($report_item['item']) { case MEASUREMENT: $zkl['items'] = db_fetch_lance_log_measurement_status($item, 0, 7, "", "", array($log_files[$zkl['cnt']])); break; case DETECTION: // Fetch all short circuit status $zkl['items'] = db_fetch_lance_log_shortcircuit_status($item, 0, "", "", array($log_files[$zkl['cnt']])); // Fetch all measurement on/off and power up event $measurement_status = db_fetch_lance_log_measurement_status($item, 0, 7, "", "", array($log_files[$zkl['cnt']])); // Fetch all switch3000 on/off events if (db_check_system_device_capabilities($type['id'], "kortsluiting schakelen")) { $switch_status = db_fetch_lance_switch3000_state($item, 0, "", "", array($log_files[$zkl['cnt']])); } // Merge measurement events and sort on datetime if ((is_array($zkl['items'])) && (is_array($measurement_status))) { $zkl['items'] = array_sort(array_merge($zkl['items'], $measurement_status), "t"); } // Merge switch3000 events and sort on datetime if ((is_array($zkl['items'])) && (is_array($switch_status))) { $zkl['items'] = array_sort(array_merge($zkl['items'], $switch_status), "t"); } break; case SHORTCIRCUIT: // Fetch all key switch and switch 3000 changes $zkl['items'] = db_fetch_lance_log_switch3000_status($item, 0, "", "", array($log_files[$zkl['cnt']])); break; case BATTERY: // Fetch all battery changes $bat = array(); for($i = 0; $i < $type['nr_batterijen']; $i++) { array_push($bat, $i); } $zkl['items'] = db_fetch_lance_log_battery_status($item, $bat, 0, "", "", array($log_files[$zkl['cnt']])); break; case SMS: // Fetch all sms logged $zkl['items'] = db_fetch_lance_log_sms($item, 0, "", "", array($log_files[$zkl['cnt']])); break; default: break; } // For debug purposes => Get execution times if ($_SESSION[$_PAGE_INFO['id']]['dbg']['mask'] & 0x01) { // Get end time $log_end = microtime_float(); if (strlen($log_action)) { // Debug info DBG("Fetch " . $lance['idcode'] . " LOG_ZKL: " . $log_action . " " . ($log_end - $log_start) . "[s], items: " . sizeof($zkl['items'] . ", (sdcard: " . $log_files[$zkl['cnt']]['sdcard'] . ", startup: " . $log_files[$zkl['cnt']]['startup'] . ", rpgm: " . $log_files[$zkl['cnt']]['rpgmcount'] . ")")); } // Get starting time $log_start = microtime_float(); } if (is_array($zkl['items'])) { foreach($zkl['items'] as $zkl['item']) { switch($state) { // // Find begin event // case FIND_BEGIN: switch($report_item['item']) { // Find measurement on event case MEASUREMENT: $found = ($zkl['item']['major'] == MAJ_MEAS_ON); break; // Find detection ok event case DETECTION: switch($zkl['item']['major']) { case MAJ_SHORTCIR_OK: $detection = TRUE; break; case MAJ_SHORTCIR_ALARM: $detection = FALSE; break; case MAJ_MEAS_ON: $measurement = TRUE; break; case MAJ_MEAS_OFF: $measurement = FALSE; $detection = FALSE; break; case MAJ_SWITCH: $switch3000 = (($zkl['item']['state'] & 0x06 == 0x06) || ($zkl['item']['state'] & 0x09 == 0x09)); break; default: break; } // Detection ok? $found = ($detection && $measurement && $switch3000); break; default: $found = FALSE; break; } if ($found) { // Valid timestamp => use log time if (valid_gps_timestamp(convert_datetime($zkl['item']['t'], TRUE))) { // Get last entry timestamp $timestamp['begin'] = convert_datetime($zkl['item']['t'], TRUE); } else { // Get last entry timestamp $timestamp['begin'] = convert_datetime($zkl['item']['t_log'], TRUE); // Server time used $sts |= SERVER_TIME_BEG; } // Check for unfinished begin (check for unfinished begin) // We do this here because the END could be a log_realtime entry and then this check is skipped if ((!$zkl['cnt']) && (strlen($begin_period)) && (convert_datetime($begin_period) > convert_datetime($timestamp['begin']))) { $sts |= UNFINISHED_BEG; } // Store log file values (needed for the thick line!) $zkl['log'] = array(sdcard => $zkl['item']['sdcard'], startup => $zkl['item']['startup'], rpgmcount => $zkl['item']['rpgmcount']); // Next state => Find end $state = FIND_END; } break; // // Find end event // case FIND_END: switch($report_item['item']) { // Find measurement off event case MEASUREMENT: $found = ($zkl['item']['major'] == MAJ_MEAS_OFF); break; // Find detection nok event case DETECTION: switch($zkl['item']['major']) { case MAJ_SHORTCIR_OK: $detection = TRUE; break; case MAJ_SHORTCIR_ALARM: $detection = FALSE; break; case MAJ_MEAS_ON: $measurement = TRUE; break; case MAJ_MEAS_OFF: $measurement = FALSE; $detection = FALSE; break; case MAJ_SWITCH: $switch3000 = (($zkl['item']['state'] & 0x06 == 0x06) || ($zkl['item']['state'] & 0x09 == 0x09)); break; default: break; } // Detection nok? $found = (!$detection || !$measurement || !$switch3000); break; default: $found = FALSE; break; } if ($found) { // Valid timestamp => use log time if (valid_gps_timestamp(convert_datetime($zkl['item']['t'], TRUE))) { // Get last entry timestamp $timestamp['end'] = convert_datetime($zkl['item']['t'], TRUE); } else { // Get last entry timestamp $timestamp['end'] = convert_datetime($zkl['item']['t_log'], TRUE); // Server time used $sts |= SERVER_TIME_END; } // Begin time may not exceed end time previous entry // This to remove duplicated entries/timestamps if ((is_array($valid_entries)) && (!empty($valid_entries))) { $start_value = (convert_datetime($timestamp['begin']) >= convert_datetime($valid_entries[sizeof($valid_entries)-1]['end'])) ? $timestamp['begin'] : convert_datetime((convert_datetime($valid_entries[sizeof($valid_entries)-1]['end']) + 1), TRUE); } else { $start_value = $timestamp['begin']; } // Check begin/end times $converted_time = convert_timeperiod($start_value, $timestamp['end'], $begin_period, $end_period); if (is_array($converted_time)) { // valid timespan if (convert_datetime($converted_time[1]) > convert_datetime($converted_time[0])) { // Unfinished begin? if ((!$zkl['cnt']) && (strlen($begin_period)) && (convert_datetime($begin_period) > convert_datetime($timestamp['begin']))) { $sts |= UNFINISHED_BEG; } // Unfinished end? if ((strlen($end_period)) && (convert_datetime($timestamp['end']) < convert_datetime($converted_time[1]))) { $sts |= UNFINISHED_END; } // New times $timestamp['begin'] = $converted_time[0]; $timestamp['end'] = $converted_time[1]; // Store entry array_push($valid_entries, array(begin => $timestamp['begin'], end => $timestamp['end'], sts => $sts, log => $zkl['log'], src => "log_zkl")); } } // Reset status $sts = OK; // Next state => Find begin ("restart") $state = FIND_BEGIN; } break; // // Find (non-period) event // case FIND_EVENT: // Valid timestamp? timestamp does not exceed end time? if ((valid_gps_timestamp(convert_datetime($zkl['item']['t'], TRUE))) && ((!strlen($end_period)) || (convert_datetime($end_period) >= $zkl['item']['t']))) { switch($report_item['item']) { // Find switch on/off event case SHORTCIRCUIT: // Initial value $data = ""; // Determine status switch($zkl['item']['minor']) { case MIN_SWITCH3000_KEY_OFF: if ($key != OFF) { $data = ucfirst(_("short circuit")) . " " . _("switched off") . " (" . _("Key switch") . " " . _("off") . ")"; $key = OFF; $switch3000 = FALSE; } break; case MIN_SWITCH3000_KEY_ON: if ($key != ON) { $data = ucfirst(_("short circuit")) . " " . _("switched on") . " (" . _("Key switch") . " " . _("on") . ")"; $key = ON; $switch3000 = TRUE; } break; case MIN_SWITCH3000_MTINFO_OFF: if ($switch3000) { $data = ucfirst(_("short circuit")) . " " . _("switched off") . " (" . "MTinfo/RS3000" . ")"; $switch3000 = FALSE; } break; case MIN_SWITCH3000_MTINFO_ON: if (!$switch3000) { $data = ucfirst(_("short circuit")) . " " . _("switched on") . " (" . "MTinfo/RS3000" . ")"; $switch3000 = TRUE; } break; case MIN_SWITCH3000_REBOOT: if (!$switch3000) { $data = ucfirst(_("short circuit")) . " " . _("switched on") . " (" . "Reboot" . ")"; $switch3000 = TRUE; } break; default: break; } $found = (strlen($data)); break; // Find battery event case BATTERY: // Battery status changed? if ($batt[$zkl['item']['batterij']] != $zkl['item']['status']) { // Store new status $batt[$zkl['item']['batterij']] = $zkl['item']['status']; $found = TRUE; for($i=0; $i < $type['nr_batterijen']; $i++) { // All valid? $found = (strlen($batt[$i])) ? $found : FALSE; } } else { $found = FALSE; } // Last entry? and no other entries available? if (($zkl['item']['id'] == $zkl['items'][sizeof($zkl['items']) - 1]['id']) && (empty($valid_entries))) { if (!$found) { $found = TRUE; for($i=0; $i < $type['nr_batterijen']; $i++) { // All valid? $found = (strlen($batt[$i])) ? $found : FALSE; } } if ($found) { // Set flag $overruled_time = TRUE; } } // Parse status $data = $batt; break; // Find SMS event case SMS: // Store telephone number $data[0] = $zkl['item']['telefoonnr']; // Store status $data[1] = $zkl['item']['type']; // Store message $data[2] = utf8_encode($zkl['item']['tekst']); $found = TRUE; break; default: $found = FALSE; break; } if (($found) || ($overruled_time)) { // Valid timestamp => use log time if (valid_gps_timestamp(convert_datetime($zkl['item']['t'], TRUE))) { // Get last entry timestamp $timestamp['begin'] = convert_datetime($zkl['item']['t'], TRUE); } else { // Get last entry timestamp $timestamp['begin'] = convert_datetime($zkl['item']['t_log'], TRUE); // Server time used $sts |= SERVER_TIME_BEG; } // Store log file values (needed for the thick line!) $zkl['log'] = array(sdcard => $zkl['item']['sdcard'], startup => $zkl['item']['startup'], rpgmcount => $zkl['item']['rpgmcount']); // Store value, needed for the overruled time value if ($found) { // Event before if ((strlen($begin_period)) && (convert_datetime($timestamp['begin']) <= convert_datetime($begin_period))) { // Store values $stored_data['data'] = $data; $stored_data['log'] = $zkl['log']; $stored_data['sts'] = $sts; } } // Check time if (((!strlen($begin_period)) || (convert_datetime($timestamp['begin']) >= convert_datetime($begin_period))) && ((!strlen($end_period)) || (convert_datetime($timestamp['begin']) <= convert_datetime($end_period)))) { // Store entry array_push($valid_entries, array(begin => $timestamp['begin'], sts => $sts, data => $data, log => $zkl['log'], src => "log_zkl")); } // Overruled time? // For example no valid battery event during this period => Show last known before // We can do this because this log_file has been valid for a part of this period, otherwhise it won't be selected else if (($overruled_time) && (!is_null($stored_data))) { // Store entry array_push($valid_entries, array(begin => $begin_period, sts => $stored_data['sts'], data => $stored_data['data'], log => $stored_data['log'], src => "log_zkl")); } // Reset status $sts = OK; } } break; // // Undefined state // default: break; } } } // For debug purposes => Get execution times if ($_SESSION[$_PAGE_INFO['id']]['dbg']['mask'] & 0x01) { // Get end time $log_end = microtime_float(); if (strlen($log_action)) { // Debug info DBG("Parse " . $lance['idcode'] . " LOG_ZKL: " . $log_action . " " . ($log_end - $log_start) . "[s], (sdcard: " . $log_files[$zkl['cnt']]['sdcard'] . ", startup: " . $log_files[$zkl['cnt']]['startup'] . ", rpgm: " . $log_files[$zkl['cnt']]['rpgmcount'] . ")"); } } // Valid entries found? Or searching for the end? if ((!empty($valid_entries)) || ($state == FIND_END)) { // End of this log file is begin of log realtime $rt['begin'] = $log_files[$zkl['cnt']]['tmax']; } else { // No valid entries found => Retry with the log realtime, could be a "bug" $rt['begin'] = $log_files[$zkl['cnt']]['tmin']; } // Last log file => end of period, else begin of next log file $rt['end'] = (($zkl['cnt'] + 1) == sizeof($log_files)) ? convert_datetime($end_period) : $log_files[$zkl['cnt'] + 1]['tmin']; // Check if end is not before begin if ((strlen($rt['begin'])) && (strlen($rt['end']))) { $rt['end'] = ($rt['end'] > $rt['begin']) ? $rt['end'] : $rt['begin']; } } // Reset flag $skip_first = FALSE; // // LOG_REALTIME // if ((is_array($log_rt)) && (in_array("log_realtime", $report_item['table']))) { // For debug purposes => Get execution times if ($_SESSION[$_PAGE_INFO['id']]['dbg']['mask'] & 0x01) { // Get starting time $log_start = microtime_float(); } // Initial values $rt['last_valid'] = ""; for ($i = 0; (($i < sizeof($log_rt)) && !((strlen($rt['end'])) && ($log_rt[$i]['t'] > $rt['end']))); $i++) { // Valid timeframe? if ((($log_rt[$i]['t'] >= $rt['begin']) || (!$rt['begin'])) && (($log_rt[$i]['t'] <= $rt['end']) || (!$rt['end']))) { switch($state) { // // Find begin event // case FIND_BEGIN: switch($report_item['item']) { // Find measurement on event case MEASUREMENT: $found = ($log_rt[$i]['mcu_state'] & 0x0001); break; // Find detection ok event case DETECTION: // Measurement if ($log_rt[$i]['mcu_state'] & 0x0001) { $measurement = TRUE; } else { $measurement = FALSE; $detection = FALSE; } // Detection if ($log_rt[$i]['mcu_state'] & 0x0002) { $detection = TRUE; } else { $detection = FALSE; } // Switch 3000 (when supported) if ((!is_null($log_rt[$i]['sw3000_state'])) && ($log_rt[$i]['sw3000_state'])) { if ((($log_rt[$i]['sw3000_state'] & 0x06) == 0x06) || (($log_rt[$i]['sw3000_state'] & 0x09) == 0x09)) { $switch3000 = TRUE; } else { $switch3000 = FALSE; } } // Detection ok? $found = ($detection && $measurement && $switch3000); break; default: $found = FALSE; break; } if ($found) { // Store timestamp $timestamp['begin'] = convert_datetime($log_rt[$i]['t'], TRUE); // On going begin? // Only possible when starting with the log_realtime and the first entry valid if (($timestamp['begin'] == convert_datetime($log_rt[0]['t'], TRUE)) && (strlen($begin_period)) && (is_array($prev_log_rt)) && (is_array($prev_log_tcp))) { // Previous log_tcp before previous log_realtime if ($prev_log_tcp['t'] < $prev_log_rt[0]['t']) { // No changes within this the session $timestamp['begin'] = $begin_period; // On going at the begin $sts |= UNFINISHED_BEG; } } // Next state => Find end $state = FIND_END; } break; // // Find end event // case FIND_END: switch($report_item['item']) { // Find measurement off event case MEASUREMENT: $found = (!($log_rt[$i]['mcu_state'] & 0x0001)); break; // Find detection nok event case DETECTION: // Measurement if ($log_rt[$i]['mcu_state'] & 0x0001) { $measurement = TRUE; } else { $measurement = FALSE; $detection = FALSE; } // Detection if ($log_rt[$i]['mcu_state'] & 0x0002) { $detection = TRUE; } else { $detection = FALSE; } // Switch 3000 (when supported) if ((!is_null($log_rt[$i]['sw3000_state'])) && ($log_rt[$i]['sw3000_state'])) { if ((($log_rt[$i]['sw3000_state'] & 0x06) == 0x06) || (($log_rt[$i]['sw3000_state'] & 0x09) == 0x09)) { $switch3000 = TRUE; } else { $switch3000 = FALSE; } } // Detection nok? $found = (!$detection || !$measurement || !$switch3000); break; default: $found = FALSE; break; } if ($found) { // We now check the tcp connection during this period $log_tcp = db_fetch_lance_tcp_status($item, $timestamp['begin'], TRUE); if ((is_array($log_tcp)) && ($log_tcp['t'] < $log_rt[$i]['t'])) { // Connection hick-up => Mark $sts |= CON_HICKUP; } // Valid timestamp if ($log_rt[$i]['t'] > convert_datetime($timestamp['begin'])) { // Store entry array_push($valid_entries, array(begin => $timestamp['begin'], end => convert_datetime($log_rt[$i]['t'], TRUE), sts => $sts, log => $zkl['log'], src => "log_realtime")); } // Reset status $sts = OK; // Next state => Find begin ("restart") $state = FIND_BEGIN; } break; // // Find (non-periodic) event // case FIND_EVENT: switch($report_item['item']) { // Find shortcircuit event case SHORTCIRCUIT: // Initial values $data = ""; // Key changed? if (($log_rt[$i]['rc_state'] & 0x0C) != $key) { // Determine status switch($log_rt[$i]['rc_state'] & 0x0C) { case OFF: // Changed? if ($switch3000) { $data = ucfirst(_("short circuit")) . " " . _("switched off") . " (" . _("Key switch") . " " . _("off") . ")"; } $switch3000 = FALSE; break; case ON: // Changed? if (!$switch3000) { $data = ucfirst(_("short circuit")) . " " . _("switched on") . " (" . _("Key switch") . " " . _("on") . ")"; } $switch3000 = TRUE; break; default: break; } // Update key $key = ($log_rt[$i]['rc_state'] & 0x0C); } // Switch3000 on/off changed? else if (($log_rt[$i]['sw3000_state'] != 0xFFFF) && (((($log_rt[$i]['sw3000_state'] & 0x06) == 0x06) || (($log_rt[$i]['sw3000_state'] & 0x09) == 0x09)) != $switch3000)) { // Determine status switch((($log_rt[$i]['sw3000_state'] & 0x06) == 0x06) || (($log_rt[$i]['sw3000_state'] & 0x09) == 0x09)) { case FALSE: // Changed? if ($switch3000) { $data = ucfirst(_("short circuit")) . " " . _("switched off"); $data .= ($log_rt[$i]['rc_state'] & 0x01) ? " (" . "MTinfo/RS3000" . ")" : " (" . _("Key switch") . " " . _("off") . ")"; } $switch3000 = FALSE; break; case TRUE: // Changed? if (!$switch3000) { $data = ucfirst(_("short circuit")) . " " . _("switched on"); $data .= ($log_rt[$i]['rc_state'] & 0x01) ? " (" . "MTinfo/RS3000" . ")" : " (" . _("Key switch") . " " . _("on") . ")"; } $switch3000 = TRUE; break; default: break; } } $found = (strlen($data)); // Check first entry? Could be initial values if ((!$i) && (is_array($prev_log_rt))) { // Detection changed $found = (($prev_log_rt[0]['rc_state'] & 0x0C) != $key) ? $found : FALSE; // Switch3000 changed? $found = (($found) && (((($prev_log_rt[0]['sw3000_state'] & 0x06) == 0x06) || (($prev_log_rt[0]['sw3000_state'] & 0x09) == 0x09)) != $switch3000)) ? $found : FALSE; } break; case BATTERY: // Initial values $found = FALSE; for($j = 0; $j < $type['nr_batterijen']; $j++) { switch($j) { case 0: $mask = 0x0F00; $shift = 8; break; case 1: $mask = 0xF000; $shift = 12; break; default: break; } // Store old value $old_value = $batt[$j]; switch(($log_rt[$i]['mcu_state'] & $mask) >> $shift) { case 7: $batt[$j] = "verwijderd"; break; case 3: $batt[$j] = "leeg"; break; case 1: $batt[$j] = "alarm"; break; case 0: $batt[$j] = "ok"; break; default: break; } // Parse data $data[$j] = $batt[$j]; // Values changed/or first value (and no log_zkl values) $found = (($batt[$j] != $old_value) || ((!$i) && (empty($valid_entries)))) ? TRUE : $found; } break; default: $found = FALSE; break; } if ($found) { // Store entry array_push($valid_entries, array(begin => convert_datetime($log_rt[$i]['t'], TRUE), sts => $sts, data => $data, log => $zkl['log'], src => "log_realtime")); } // Reset status $sts = OK; break; // // Undefined state // default: break; } // Valid log realtime entry found $rt['last_valid'] = array(index => $i); } } // For debug purposes => Get execution times if ($_SESSION[$_PAGE_INFO['id']]['dbg']['mask'] & 0x01) { // Get end time $log_end = microtime_float(); if (strlen($log_action)) { // Debug info DBG("Parse " . $lance['idcode'] . " LOG_RT : " . $log_action . " " . ($log_end - $log_start) . "[s]"); } } } // Waiting for a measurement off/detecion nok event (only needed for period search)? // - Valid log_realtime entry after end of logfile (or no log file)? => Detect connection hickup // - No valid log_realtime entry after end of log file => use last log file entry if ($state == FIND_END) { // For debug purposes => Get execution times if ($_SESSION[$_PAGE_INFO['id']]['dbg']['mask'] & 0x01) { // Get starting time $log_start = microtime_float(); } // Valid log_realtime entry? if ((is_array($rt['last_valid'])) && (is_array($log_rt)) && (in_array("log_realtime", $report_item['table']))) { // Get timestamp last valid entry $timestamp['end'] = convert_datetime($log_rt[$rt['last_valid']['index']]['t'], TRUE); // We now check the tcp connection during this period $log_tcp = db_fetch_lance_tcp_status($item, $timestamp['begin'], TRUE); if ((is_array($log_tcp)) && ($log_tcp['t'] < $log_rt[$rt['last_valid']['index']]['t'])) { // Connection hick-up => Mark $sts |= CON_HICKUP; } // Last requested entry? if (($rt['last_valid']['index'] + 1) == sizeof($log_rt)) { // Next log_realtime entry available? if (is_array($next_log_rt)) { // Next log_tcp entry available? if ((!is_array($next_log_tcp)) || ($next_log_tcp['t'] > $next_log_rt[0]['t'])) { // No changes within this the session or session still active $timestamp['end'] = (strlen($end_period)) ? $end_period : $datetime; // On going $sts |= UNFINISHED_END; } } else { // No next log_tcp entry available? if (!is_array($next_log_tcp)) { // No end selected if (!strlen($end_period)) { // Get last known tcp status $last_log_tcp = db_fetch_lance_tcp_status($item, $datetime, FALSE); if ($last_log_tcp['event'] == "connect") { // Session still active? $timestamp['end'] = $datetime; // On going $sts |= UNFINISHED_END; } } else { // Session still active? $timestamp['end'] = $end_period; // On going $sts |= UNFINISHED_END; } } } } if (convert_datetime($timestamp['end']) > convert_datetime($timestamp['begin'])) { // Store entry array_push($valid_entries, array(begin => $timestamp['begin'], end => $timestamp['end'], sts => $sts, log => $zkl['log'], src => "log_realtime")); } } // No valid log_realtime entries => use end of log file else { // Fetch last log file entry $last_entry = db_fetch_lance_log_file_last_entry($item, $log_files[$zkl['cnt']]); // Valid timestamp => use log time if (valid_gps_timestamp(convert_datetime($last_entry['t'], TRUE))) { // Get last entry timestamp $timestamp['end'] = convert_datetime($last_entry['t'], TRUE); } else { // Get last entry timestamp $timestamp['end'] = convert_datetime($last_entry['t_log'], TRUE); // Server time used $sts |= SERVER_TIME; } // Check begin/end times $converted_time = convert_timeperiod($timestamp['begin'], $timestamp['end'], $begin_period, $end_period); if (is_array($converted_time)) { // valid timespan if (convert_datetime($converted_time[1]) > convert_datetime($converted_time[0])) { // Unfinished begin? if ((!$zkl['cnt']) && (strlen($begin_period)) && (convert_datetime($begin_period) > convert_datetime($timestamp['begin']))) { $sts |= UNFINISHED_BEG; } // Unfinished end? if ((strlen($end_period)) && (convert_datetime($timestamp['end']) < convert_datetime($converted_time[1]))) { $sts |= UNFINISHED_END; } // New times $timestamp['begin'] = $converted_time[0]; $timestamp['end'] = $converted_time[1]; // Store entry array_push($valid_entries, array(begin => $timestamp['begin'], end => $timestamp['end'], sts => $sts, log => $zkl['log'], src => "log_zkl")); } } } // For debug purposes => Get execution times if ($_SESSION[$_PAGE_INFO['id']]['dbg']['mask'] & 0x01) { // Get end time $log_end = microtime_float(); if (strlen($log_action)) { // Debug info DBG("Parse " . $lance['idcode'] . " FIND_END : " . $log_action . " " . ($log_end - $log_start) . "[s]"); } } } } while ((is_array($log_files)) && (++$zkl['cnt'] < sizeof($log_files))); } // Extra action? if ((is_array($valid_entries)) && (!empty($valid_entries))) { switch($report_item['item']) { case DETECTION: // Detect jitter => Alarm => Within second $saved_valid_entries = $valid_entries; $valid_entries = array(); // Initial values $begin = ""; for ($i=0; $i $begin, end => $end, sts => $sts, log => $log, src => $src)); } // New log file? else if ($saved_valid_entries[$i + 1]['log'] != $log) { array_push($valid_entries, array(begin => $begin, end => $end, sts => $sts, log => $log, src => $src)); // Clean up stored values $begin = ""; } // Next entry not within 3 seconds else if (abs(convert_datetime($saved_valid_entries[$i + 1]['begin']) - convert_datetime($end)) > 3) { array_push($valid_entries, array(begin => $begin, end => $end, sts => $sts, log => $log, src => $src)); // Clean up stored values $begin = ""; } else { // Add measure hickup to status $sts |= MEAS_HICKUP; } } break; default: break; } } // Valid entries? => Write to report if ((is_array($valid_entries)) && (!empty($valid_entries))) { // Initial values $offset_id = null; $offset_t = ""; for($i = 0; $i < sizeof($valid_entries); $i++) { // New log file => thick line if (($i) && ($valid_entries[$i]['log'] != $valid_entries[$i - 1]['log'])) { // Print thick line empty_line(1, 1); } // Calculate duration when possible if (strlen($valid_entries[$i]['begin']) && strlen($valid_entries[$i]['end'])) { $duration = CalculateDuration($valid_entries[$i]['begin'], $valid_entries[$i]['end']); } // Store begin/end values before actions are taken $begin = $valid_entries[$i]['begin']; $end = $valid_entries[$i]['end']; // Check whether log file time was used or an hickup in the data connection if ($valid_entries[$i]['sts'] != OK) { // Unfinished begin if ($valid_entries[$i]['sts'] & UNFINISHED_BEG) { $valid_entries[$i]['begin'] = "\x3C\x3C\x3C"; } // Unfinished end if ($valid_entries[$i]['sts'] & UNFINISHED_END) { $valid_entries[$i]['end'] = "\x3E\x3E\x3E"; } // Server time used begin if ($valid_entries[$i]['sts'] & SERVER_TIME_BEG) { $valid_entries[$i]['begin'] .= "\xC2\xB9"; $log_time_overall = TRUE; } // Server time used end if ($valid_entries[$i]['sts'] & SERVER_TIME_END) { $valid_entries[$i]['end'] .= "\xC2\xB9"; $log_time_overall = TRUE; } // Connection hickup if ($valid_entries[$i]['sts'] & CON_HICKUP) { $valid_entries[$i]['end'] .= "\xC2\xB2"; $con_hickup_overall = TRUE; } // Measurement hickup if ($valid_entries[$i]['sts'] & MEAS_HICKUP) { $valid_entries[$i]['end'] .= "\xC2\xB3"; $meas_hickup_overall = TRUE; } } $csv_serial_nr = db_fetch_lance($item, "", 1); $csv_owner = db_fetch_customer($info['eigenaar'], 1); $csv_info = db_fetch_lance($item, "", 1); switch($report_item['item']) { case MEASUREMENT: // Check if output is pdf or csv if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_data(array_merge($report_data, array(value => array(($i + 1), $valid_entries[$i]['begin'], $valid_entries[$i]['end'], $duration)))); } else if (strtolower($_PAGE_INFO['report_type']) == "csv") { // Check if there is a begin time and convert it to unix time $csv_time = ($valid_entries[$i]['begin'] != "\x3C\x3C\x3C") ? convert_datetime($valid_entries[$i]['begin']) : $valid_entries[$i]['begin']; // Add record for measurment on array_push($csv_data, array('Timestamp'=> $csv_time ,'Company'=> $csv_owner['bedrijfsnaam'],_("ID code"). " " .ucwords($_SESSION[$_PAGE_INFO['id']]['skin_name'])=> $csv_info['idcode'] ,_("ID code")." "._("owner")=> $csv_serial_nr['serienr'],'Equipment type'=> $type['naam'],'Measurement'=> ucfirst(_('on')),_('Duration')." ".strtolower(_('Measurement'))=> "" ,'detection'=> "" ,_('Duration')." "._('detection')=> "" ,'short circuit'=> "" , 'Battery'=> "" ,'Gps'=> "")); // Check if there is a end time and convert it to unix time $csv_time = ($valid_entries[$i]['end'] != "\x3E\x3E\x3E") ? convert_datetime($valid_entries[$i]['end']) : $valid_entries[$i]['end']; // Add record for measurment off array_push($csv_data, array('Timestamp'=> $csv_time ,'Company'=> $csv_owner['bedrijfsnaam'],_("ID code"). " " .ucwords($_SESSION[$_PAGE_INFO['id']]['skin_name'])=> $csv_info['idcode'] ,_("ID code")." "._("owner")=> $csv_serial_nr['serienr'],'Equipment type'=> $type['naam'],'Measurement'=> ucfirst(_('off')),_('Duration')." ".strtolower(_('Measurement'))=> $duration ,'detection'=> "" ,_('Duration')." "._('detection')=> "" ,'short circuit'=> "" , 'Battery'=> "" ,'Gps'=> "")); } break; case DETECTION: if (db_check_system_device_capabilities($type['id'],"gps")) { // Initial values $gps_info = "-"; $gps_info_link = ""; // Find next GPS coordinate & create link if ($valid_entries[$i]['src'] == "log_zkl") { $gps = db_fetch_lance_gps_entry_between($item, "", "", $offset_t, $end); } else { $gps = db_fetch_lance_log_gps_info($item, 1, "", $end, 1, "", TRUE, $offset_id); // Fix array offset $gps = $gps[0]; } // No new entry? if ((!is_array($gps)) && (is_array($stored_gps))) { $gps = $stored_gps; } else { // Starting id/time offset? $offset_id = $gps['id']; $offset_t = convert_datetime($gps['t'], TRUE); $stored_gps = $gps; } if (is_array($gps)) { $gps_info_link = GOOGLE_MAPS . "maps?q=" . $gps['latitude'] . ", " . $gps['longitude']; $gps_info = $gps['latitude'] . ", " . $gps['longitude']; } // Check if output is pdf or csv if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_data(array_merge($report_data, array(value => array(($i + 1), $valid_entries[$i]['begin'], $valid_entries[$i]['end'],$duration, $gps_info), ishtml => array("","","","", array(type => link, data => $gps_info_link))))); } else if (strtolower($_PAGE_INFO['report_type']) == "csv"){ // Check if there is a begin time and convert it to unix time $csv_time = ($valid_entries[$i]['begin'] != "\x3C\x3C\x3C") ? convert_datetime($valid_entries[$i]['begin']) : $valid_entries[$i]['begin']; // Add record for detection on array_push($csv_data, array('Timestamp'=> $csv_time ,'Company'=> $csv_owner['bedrijfsnaam'],_("ID code")." ".ucwords($_SESSION[$_PAGE_INFO['id']]['skin_name'])=> $csv_info['idcode'] ,_("ID code")." "._("owner")=> $csv_serial_nr['serienr'],'Equipment type'=> $type['naam'],'Measurement'=> "",_('Duration')." ".strtolower(_('Measurement'))=> "" ,'detection'=> ucfirst(_('on')) ,_('Duration')." "._('detection')=> "" ,'short circuit'=> "" ,'Battery'=> "" ,'Gps'=> $gps_info)); // Check if there is a end time and convert it to unix time $csv_time = ($valid_entries[$i]['end'] != "\x3E\x3E\x3E") ? convert_datetime($valid_entries[$i]['end']) : $valid_entries[$i]['end']; // Add record for detection off array_push($csv_data, array('Timestamp'=> $csv_time ,'Company'=> $csv_owner['bedrijfsnaam'],_("ID code"). " " .ucwords($_SESSION[$_PAGE_INFO['id']]['skin_name'])=> $csv_info['idcode'] ,_("ID code")." "._("owner")=> $csv_serial_nr['serienr'],'Equipment type'=> $type['naam'],'Measurement'=> "",_('Duration')." ".strtolower(_('Measurement'))=> "" ,'detection'=> ucfirst(_('off')) ,_('Duration')." "._('detection')=> $duration ,'short circuit'=> "" ,'Battery'=> "" ,'Gps'=> $gps_info)); } } else { report_data(array_merge($report_data, array(value => array(($i + 1), $valid_entries[$i]['begin'], $valid_entries[$i]['end'], $duration)))); } break; case SHORTCIRCUIT: // Check if output is pdf or csv if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_data(array_merge($report_data, array(value => array(($i + 1), $valid_entries[$i]['data'], $valid_entries[$i]['begin'])))); } else if (strtolower($_PAGE_INFO['report_type']) == "csv"){ // Check if there is a begin time and convert it to unix time $csv_time = ($valid_entries[$i]['begin'] != "\x3C\x3C\x3C") ? convert_datetime($valid_entries[$i]['begin']) : $valid_entries[$i]['begin']; // Get short circuit value $space_pos = strpos($valid_entries[$i]['data'], " "); $csv_shortcircuit=substr($valid_entries[$i]['data'],$space_pos + 1); // Add record for short circuit array_push($csv_data, array('Timestamp'=> $csv_time ,'Company'=> $csv_owner['bedrijfsnaam'],_("ID code"). " " .ucwords($_SESSION[$_PAGE_INFO['id']]['skin_name'])=> $csv_info['idcode'] ,_("ID code")." "._("owner")=> $csv_serial_nr['serienr'],'Equipment type'=> $type['naam'],'Measurement'=> "",_('Duration')." ".strtolower(_('Measurement'))=> "" ,'detection'=> "" ,_('Duration')." "._('detection')=> "" ,'short circuit'=> ucfirst($csv_shortcircuit) ,'Battery'=> "" ,'Gps'=> "")); } break; case BATTERY: // Check if output is pdf or csv if (strtolower($_PAGE_INFO['report_type']) == "pdf") { $value = array($i + 1); for($j = 0; $j < $type['nr_batterijen']; $j++) { array_push($value, $valid_entries[$i]['data'][$j]); } array_push($value, $valid_entries[$i]['begin']); report_data(array_merge($report_data, array(value => $value))); } else if (strtolower($_PAGE_INFO['report_type']) == "csv"){ // Check if there is a begin time and convert it to unix time $csv_time = ($valid_entries[$i]['begin'] != "\x3C\x3C\x3C") ? convert_datetime($valid_entries[$i]['begin']) : $valid_entries[$i]['begin']; $battery_status=""; for($j = 0; $j < $type['nr_batterijen']; $j++) { // Get Battery status $battery_status .= _('Battery')." ".$j.": ".$valid_entries[$i]['data'][$j]." "; } // Add record Battery status array_push($csv_data, array('Timestamp'=> $csv_time ,'Company'=> $csv_owner['bedrijfsnaam'],_("ID code"). " " .ucwords($_SESSION[$_PAGE_INFO['id']]['skin_name'])=> $csv_info['idcode'] ,_("ID code")." "._("owner")=> $csv_serial_nr['serienr'],'Equipment type'=> $type['naam'],'Measurement'=> "",_('Duration')." ".strtolower(_('Measurement'))=> "" ,'detection'=> "" ,_('Duration')." "._('detection')=> "" ,'short circuit'=> "" ,'Battery'=> $battery_status ,'Gps'=> "")); } break; case SMS: // Calculate number of lines needed for the text $lines = nmr_lines($valid_entries[$i]['data'][2], 48); for ($j = 0; $j < sizeof($lines); $j++) { // Get text $text = $lines[$j]; if (sizeof($lines) > 1) { if (!$j) { report_data(array_merge($report_data, array(value => array(($i + 1), $valid_entries[$i]['begin'], $valid_entries[$i]['data'][0], $valid_entries[$i]['data'][1], $text), border => array("LRT","LRT","LRT","LRT","LRT"), nr_lines => sizeof($lines)))); } else { if (($j + 1) == sizeof($lines)) { report_data(array_merge($report_data, array(value => array("", "", "", "", $text), border => array("LRB","LRB", "LRB","LRB","LRB")))); } else { report_data(array_merge($report_data, array(value => array("", "", "", "", $text), border => array("LR","LR", "LR","LR","LR")))); } } } else { report_data(array_merge($report_data, array(value => array(($i + 1), $valid_entries[$i]['begin'], $valid_entries[$i]['data'][0], $valid_entries[$i]['data'][1], $valid_entries[$i]['data'][2])))); } } break; default: break; } } } // No (valid) log files => No (valid) log_realtime entries => Nothing to display else if (empty($valid_entries)) { switch($report_item['item']) { case MEASUREMENT: if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_data(array_merge($report_data, array(value => array("1","-","-","-")))); } break; case DETECTION: if (strtolower($_PAGE_INFO['report_type']) == "pdf") { if (db_check_system_device_capabilities($type['id'],"gps")) { report_data(array_merge($report_data, array(value => array("1","-","-","-","-")))); } else { report_data(array_merge($report_data, array(value => array("1","-","-","-")))); } } break; case SHORTCIRCUIT: if (strtolower($_PAGE_INFO['report_type']) == "pdf") { report_data(array_merge($report_data, array(value => array("1","-","-")))); } break; case BATTERY: if (strtolower($_PAGE_INFO['report_type']) == "pdf") { $value = array("1"); for($i = 0; $i < $type['nr_batterijen']; $i++) { array_push($value, "-"); } array_push($value, "-"); report_data(array_merge($report_data, array(value => $value))); } break; case SMS: report_data(array_merge($report_data, array(value => array("1","-","-","-","-")))); break; default: break; } } // Clear new page header $_PAGE_INFO['new_page_hdr'] = ""; // Remove array entry when dummy was added if ($remove_first) { $log_files = array_slice($log_files, 1); // Clear flag $remove_first = FALSE; } // When only log_zkl => restore log_files_non_corrupt array (all log files excluded the corrupted ones) if ((in_array("log_zkl", $report_item['table'])) && (sizeof($report_item['table']) == 1)) { $log_files = $log_files_non_corrupt; } } } } // Print data to csv file // Check if output is csv if (strtolower($_PAGE_INFO['report_type']) == "csv") { if (is_array($csv_data) && !empty($csv_data)) { // Sort data at time ascending $csv_data = array_sort($csv_data, "Timestamp", SORT_NUMERIC, SORT_ASC); // Create array for the merged csv_data $csv_data_compared = array(); // Variable for how many the same timestamps there are behind each other $j=1; // If there is data at the same timestamp then merge the data for ($x=0; $x < sizeof($csv_data); $x++) { // The first element have nothing to compare with if ($x > 0) { // Compare if timestamp of element is the same as the timestamp of the element before and merge the data of the two elements if ($csv_data[$x]['Timestamp'] === $csv_data[$x-1]['Timestamp']) { $sameData=FALSE; // Copy Timestamp $csv_data_compared[$x-$j]['Timestamp'] = $csv_data[$x]['Timestamp']; // Copy Measurement only if Measurement in $csv_data_compared is empty or $csv_data contains Measurement data => make new record in $csv_data_compared if(empty($csv_data_compared[$x-$j]['Measurement'])){ $csv_data_compared[$x-$j]['Measurement'] = $csv_data[$x]['Measurement']; } else if(!empty($csv_data[$x]['Measurement'])){ // Only copy the first 5 elements of the array $csv_data_compared[$x-$j+1] = array_slice($csv_data_compared[$x-$j], 0, 5, true); $csv_data_compared[$x-$j+1]['Measurement'] = $csv_data[$x]['Measurement']; $sameData=TRUE; } // Copy Duration measurement only if Duration measurement in $csv_data_compared is empty or $csv_data contains Duration measurement data => make new record in $csv_data_compared if(empty($csv_data_compared[$x-$j][_('Duration')." ".strtolower(_('Measurement'))])){ $csv_data_compared[$x-$j][_('Duration')." ".strtolower(_('Measurement'))] = $csv_data[$x][_('Duration')." ".strtolower(_('Measurement'))]; } else if(!empty($csv_data[$x][_('Duration')." ".strtolower(_('Measurement'))])){ // Only copy the first 5 elements of the array $csv_data_compared[$x-$j+1] = array_slice($csv_data_compared[$x-$j], 0, 5, true); $csv_data_compared[$x-$j+1][_('Duration')." ".strtolower(_('Measurement'))] = $csv_data[$x][_('Duration')." ".strtolower(_('Measurement'))]; $sameData=TRUE; } // Copy detection only if detection in $csv_data_compared is empty or $csv_data contains detection data => make new record in $csv_data_compared if(empty($csv_data_compared[$x-$j]['detection'])){ $csv_data_compared[$x-$j]['detection'] = $csv_data[$x]['detection']; } else if(!empty($csv_data[$x]['detection'])){ // Only copy the first 5 elements of the array $csv_data_compared[$x-$j+1] = array_slice($csv_data_compared[$x-$j], 0, 5, true); $csv_data_compared[$x-$j+1]['detection'] = $csv_data[$x]['detection']; $sameData=TRUE; } // Copy Duration detection only if Duration detection in $csv_data_compared is empty or $csv_data contains Duration detection data => make new record in $csv_data_compared if(empty($csv_data_compared[$x-$j][_('Duration')." "._('detection')])){ $csv_data_compared[$x-$j][_('Duration')." "._('detection')] = $csv_data[$x][_('Duration')." "._('detection')]; } else if(!empty($csv_data[$x][_('Duration')." "._('detection')])){ // Only copy the first 5 elements of the array $csv_data_compared[$x-$j+1] = array_slice($csv_data_compared[$x-$j], 0, 5, true); $csv_data_compared[$x-$j+1][_('Duration')." "._('detection')] = $csv_data[$x][_('Duration')." "._('detection')]; $sameData=TRUE; } // Copy Battery only if Battery in $csv_data_compared is empty or $csv_data contains Battery data => make new record in $csv_data_compared if(empty($csv_data_compared[$x-$j]['Battery'])){ $csv_data_compared[$x-$j]['Battery'] = $csv_data[$x]['Battery']; } else if(!empty($csv_data[$x]['Battery'])){ // Only copy the first 5 elements of the array $csv_data_compared[$x-$j+1] = array_slice($csv_data_compared[$x-$j], 0, 5, true); $csv_data_compared[$x-$j+1]['Battery'] = $csv_data[$x]['Battery']; $sameData=TRUE; } // Copy short circuit only if short circuit in $csv_data_compared is empty or $csv_data contains short circuit data => make new record in $csv_data_compared if(empty($csv_data_compared[$x-$j]['short circuit'])){ $csv_data_compared[$x-$j]['short circuit'] = $csv_data[$x]['short circuit']; } else if(!empty($csv_data[$x]['short circuit'])){ // Only copy the first 5 elements of the array $csv_data_compared[$x-$j+1] = array_slice($csv_data_compared[$x-$j], 0, 5, true); $csv_data_compared[$x-$j+1]['short circuit'] = $csv_data[$x]['short circuit']; $sameData=TRUE; } if (!$sameData) { $j++; } // The fields : Company, ID Dual Inventive, Id relation, Equipement are always the same by the same equipment. // The field gps is linked to the field detection (gps won't change in the same timestamp) // Don't merge these fields } else { // Copy the csv_data in a new element of csv_data_compared $csv_data_compared[$x] = $csv_data[$x]; $j=1; } } else { // Copy the csv_data in a new element of csv_data_compared $csv_data_compared[$x] = $csv_data[$x]; } } foreach ($csv_data_compared as $cvs_value) { if ($cvs_value['Timestamp'] == '<<<') { $cvs_value['Timestamp'] = $begin_period; } else if ($cvs_value['Timestamp'] == '>>>') { $cvs_value['Timestamp'] = $end_period; } else { // Convert unix time to real time if timestamp is a unix time $cvs_value['Timestamp'] = (($cvs_value['Timestamp'] == '<<<') || ($cvs_value['Timestamp'] == '>>>')) ? $cvs_value['Timestamp'] :convert_datetime($cvs_value['Timestamp'],1); } $headers = array(); // Make the header foreach ($cvs_value as $key => $item_csv) { array_push($headers, $key); } // Use array_values() to make from an associative array an index array. report_data_field needs an index array report_data_field($all_fields, array(value => array_values($cvs_value)), $headers); } } } /************************************/ /* Overview gps */ /************************************/ if (isset($report_info["gps_" . $type['id']])) { if (strtolower($_PAGE_INFO['report_type']) == "pdf") { // Initial values $counter = 0; // Print empty line empty_line(); // Header report_data(array(value => array(_("Overview gps tracks") . " " . $info['idcode'] . $period), border => array("LRBT") , bold => array(1) , align => array("L") , font_size => array(9) , cell_width => "" , check_page_end => 1 , ishtml => array(array(type => "bookmark", data => _("Overview gps tracks") . " " . $info['idcode'], parent => $_PAGE_INFO['bookmark_handle'], bold => 0)), nr_lines => 3 )); // Only log_zkl used at the moment if (is_array($log_files_corrupt)) { // Get kml track include("kml.php"); } // Clear new page header $_PAGE_INFO['new_page_hdr'] = ""; // Add kml as attachment if ((isset($_PAGE_INFO['kml'])) && (file_exists($_PAGE_INFO['kml']))) { report_data(array(value => array(" Gps track kml " . _("attachment")) , border => array("LRBT") , bold => array(1) , align => array("L") , font_size => array(8) , cell_width => "" , check_page_end => 1 , ishtml => array(array(type => "attachment", data => "", filename => $_PAGE_INFO['kml'], mimetype => "application/vnd.google-earth.kml+xml")))); // Remove file (later on!) array_push($_PAGE_INFO['delete'], $_PAGE_INFO['kml']); unset($_PAGE_INFO['kml']); } else { report_data(array(value => array("-") , border => array("LRBT") , bold => array(0) , align => array("L") , font_size => array(8) , cell_width => array(180) , check_page_end => 1 )); } } } /************************************/ /* Overview temperatures */ /************************************/ if (isset($report_info["temp_" . $type['id']])) { if (strtolower($_PAGE_INFO['report_type']) == "pdf") { // Print empty line empty_line(); // Header report_data(array(value => array(_("Overview") . " " . _("temperature") . " " . $info['idcode'] . $period), border => array("LRBT") , bold => array(1) , align => array("L") , font_size => array(9) , cell_width => "" , check_page_end => 1 , ishtml => array(array(type => "bookmark", data => _("Overview") . " " . _("temperature") . " " . $info['idcode'], parent => $_PAGE_INFO['bookmark_handle'], bold => 0)), nr_lines => 27 )); if ((is_array($log_files)) || (is_array($log_rt))) { // Plot graph plot_temp_graph($info['id'], $begin_period, $end_period, $log_files, $log_rt, "temp_plot" . "_" . date('Y-m-d') . "_" . $info['id'] . ".png"); } if ((isset($_PAGE_INFO['plot_temp'])) && (file_exists($_PAGE_INFO['plot_temp']))) { pdf_print_image("temp_image", $_PAGE_INFO['plot_temp'], 432); // Remove file (later on!) array_push($_PAGE_INFO['delete'], $_PAGE_INFO['plot_temp']); unset($_PAGE_INFO['plot_temp']); } else { report_data(array(value => array("-") , border => array("LRBT") , bold => array(0) , align => array("L") , font_size => array(8) , cell_width => array(180) , check_page_end => 1 )); } } else if (strtolower($_PAGE_INFO['report_type']) == "csv") { for($i=0; $i < 2; $i++) { // on-board(0)/extern(1) switch($i) { case 0: $header = "temperature on-board"; $cap = "temperatuursensor on-board"; break; case 1: $header = "temperature external"; $cap = "temperatuursensor extern"; break; } // Check capability if ((db_check_system_device_capabilities($type['id'], $cap)) || ($cap == "temperatuursensor on-board") && !db_check_system_device_capabilities($type['id'],"temperatuursensor on-board") && db_check_system_device_capabilities($type['id'], "temperatuursensor extern") && db_system_device_nr_tempsensors($type['id']) > 1) { // Print empty line empty_line(); // Header report_data(array(value => array(_("Overview") . " " . _($header) . " " . $info['idcode'] . $period), border => array("LRBT") , bold => array(1) , align => array("L") , font_size => array(9) , cell_width => "" , check_page_end => 1 , ishtml => array(array(type => "bookmark", data => _("Overview") . " " . _($header) . " " . $info['idcode'], parent => $_PAGE_INFO['bookmark_handle'], bold => 0)), nr_lines => 3 )); // Fetch all temp $temp_status = db_fetch_lance_log_temp($item, $i, 0, "", ""); // Initial values $counter = 0; $store_log = ""; $last_value = -128; if (is_array($temp_status)) { foreach ($temp_status as $entry) { // Reset log_time $log_time = FALSE; // New valid value if (($last_value != (int)$entry['temp']) && (int)$entry['temp'] > (int)-10 && (int)$entry['temp'] < 50) { // Store value $last_value = $entry['temp']; // Valid gps time? $extra_comma = ""; if (valid_gps_timestamp(convert_datetime($entry['t'], TRUE))) { $timestamp = convert_datetime($entry['t'], TRUE); } else { $timestamp = convert_datetime($entry['t_log'], TRUE); $log_time = TRUE; } // Check begin/end times $converted_time = convert_timeperiod($timestamp, "", $begin_period, $end_period); if (is_array($converted_time)) { // New times $timestamp = $converted_time[0]; // Add comma? if ($log_time) { $extra_comma = ",\xC2\xB9"; $log_time_overall = TRUE; } // Get log_file info $start_log = array(sdcard => $entry['sdcard'], startup => $entry['startup'], rpgmcount => $entry['rpgmcount']); // New log file => thick line if (is_array($store_log)) { if ($store_log != $start_log) { // Print thick line empty_line(1, 1); } } // Store new start_log $store_log = $start_log; // Print new line report $value = array(++$counter, $last_value . " �C", $timestamp); array_push($value, $extra_comma); report_data(array(value => $value , border => array("LRBT","LRBT","LRBT") , bold => array(0,0,0) , align => array("C","L","L") , font_size => array(8,8,8) , cell_width => array(15,110,55) , check_page_end => 1 )); // Log time used? $log_time_overall = ($log_time) ? 1 : $log_time_overall; } } } } // No entries if (!$counter) { // Print new line report report_data(array(value => array(++$counter, "-", "-") , border => array("LRBT","LRBT","LRBT") , bold => array(0,0,0) , align => array("C","L","L") , font_size => array(8,8,8) , cell_width => array(15,110,55) , check_page_end => 1 )); } } // Clear new page header $_PAGE_INFO['new_page_hdr'] = ""; } } } /************************************/ /* Notes/remarks */ /************************************/ if (strtolower($_PAGE_INFO['report_type']) == "pdf") { if ($log_time_overall) { report_data(array(value => array("\xC2\xB9 Due an invalid GPS time, the database log time has been used"), border => array("") , bold => array(0) , align => array("L") , font_size => array(8) , cell_width => "" , check_page_end => 0 )); // Clear flag $log_time_overall = FALSE; } if ($con_hickup_overall) { report_data(array(value => array("\xC2\xB2 These results can differ, due limited data connections"), border => array("") , bold => array(0) , align => array("L") , font_size => array(8) , cell_width => "" , check_page_end => 0 )); // Clear flag $con_hickup_overall = FALSE; } if ($meas_hickup_overall) { report_data(array(value => array("\xC2\xB3 There has been a possible GSM interruption") , border => array("") , bold => array(0) , align => array("L") , font_size => array(8) , cell_width => "" , check_page_end => 0 )); // Clear flag $meas_hickup_overall = FALSE; } } } } } } } } // Restore database connection db_connect(); // Generate document return report_generate(); } /** * Create the gps track report */ function report_gps_track($report_info) { GLOBAL $_PAGE_INFO; // Initial values $equipment = array(); // Begin and end of report period $begin_period = ""; $end_period = ""; if (strlen($report_info['begin_datum'])) { $begin_period = $report_info['begin_datum'] . " " . $report_info['begin_tijd']; } if (strlen($report_info['eind_datum'])) { $end_period = $report_info['eind_datum'] . " " . $report_info['eind_tijd']; } if (strlen($report_info['speed'])) { $speed_post = "&speed"; } // Retrieve all device types $types = db_fetch_system_devices($_PAGE_INFO['i18n']); if (is_array($types)) { foreach($types as $type) { if (strlen($report_info[$type['id']])) { $items = split(",", $report_info[$type['id']]); if (is_array($items)) { foreach($items as $item) { array_push($equipment, $item); } } } } } // Generate kml file header("Location: ?id=" . $_PAGE_INFO['id'] . "&redirect=include/kml.php&begin_period=" . $begin_period . "&end_period=" . $end_period . $speed_post . "&equipment=" . implode("," ,$equipment) . ""); } /** * Create the mtinfo hierarchy overview */ function report_hierarchy() { global $_PAGE_INFO; // Retrieve info $date = date('Y-m-d'); $datetime = date('Y-m-d / H:i:s'); $user = db_fetch_user($_PAGE_INFO['login']['user']['id'], "", 1); $customer = db_fetch_customer($_PAGE_INFO['login']['customer']['id'], 1); // Set file info $_PAGE_INFO['report_type'] = "pdf"; $_PAGE_INFO['dest'] = "D"; $_PAGE_INFO['file'] = str_replace(" ", "_", _("MTinfo hierarchy")) . "_" . str_replace("-", "", $date) . ".pdf"; // Create header info report_header(array(subject => "MTinfo hierarchy" , header => _("MTinfo hierarchy") , data => array( array("Date", $datetime) , array("MTinfo", VERSION . (is_ReleaseCandidate() ? " - " . $_SESSION[$_PAGE_INFO['id']]['release_dir'] : "")), array("User", getUser($user['id']))))); // Determine all childs $relations = array(); $_PAGE_INFO['childs'] = array($customer); childs_recursive($_PAGE_INFO['login']['customer']['id']); /************************************/ /* Company hierarchy */ /************************************/ if (!empty($_PAGE_INFO['childs'])) { // Add title to report report_data(array(value => array("Company hierarchy") , border => array("B") , bold => array(1) , align => array("L") , font_size => array(11) , cell_width => "" , cell_height => 16 , check_page_end => 1 , ishtml => array(array(type => "bookmark", data => "Company hierarchy", parent => 0, bold => 1)),)); for($i=0; $i child? $parent = 0; if (($i + 1) < sizeof($_PAGE_INFO['childs'])) { $parent = ($_PAGE_INFO['childs'][$i+ 1]['primaire_klant'] == $_PAGE_INFO['childs'][$i]['id']) ? 1 : $parent; } // Add child report_data(array(value => array_merge($value ,array("",$_PAGE_INFO['childs'][$i]['bedrijfsnaam'] . " " . "(" . $_PAGE_INFO['childs'][$i]['klantnaam'] . ")")), border => array_merge($border ,(!$i) ? array("L","R") : array("","R")), bold => array_merge($bold ,array(0,0)) , align => array_merge($align ,array("L","L")) , font_size => array_merge($font_size ,array(9,9)) , cell_width => array_merge($cell_width ,array(4,176 - ($pos * 5))) , cell_height => 18 , check_page_end => 1 , ishtml => array(array(type => "image", left => 2 + ($pos * 5), width => 6, filename => ($parent) ? "icon_plus.png" : "dot.png")))); } // end line report_data(array(value => array("") , border => array("T") , bold => array(0) , align => array("L") , font_size => array(9) , cell_width => array(180) , cell_height => 16 , check_page_end => 0 )); } /************************************/ /* Company Info */ /************************************/ if (!empty($_PAGE_INFO['childs'])) { for($i=0; $i array($_PAGE_INFO['childs'][$i]['bedrijfsnaam'] . " " . "(" . $_PAGE_INFO['childs'][$i]['klantnaam'] . ")") , border => array("") , bold => array(1) , align => array("L") , font_size => array(11) , cell_width => "" , cell_height => 16 , check_page_end => 0 , ishtml => array(array(type => "bookmark", data => $_PAGE_INFO['childs'][$i]['bedrijfsnaam'] . " " . "(" . $_PAGE_INFO['childs'][$i]['klantnaam'] . ")", parent => 0, bold => 1)), nr_lines => 4 )); } /************************************/ /* Users */ /************************************/ if (db_ver_rights_user_one_valid($_PAGE_INFO['login']['user']['id'], "menu:gebruikers&menu:gebruikers:zoeken,menu:gebruikers:root")) { // Add child users $users = db_fetch_users($_PAGE_INFO['childs'][$i]['id']); // Fetch project leaders $project_leaders_id = array(); $project_leaders = db_fetch_projectleaders($_PAGE_INFO['childs'][$i]['id']); if (is_array($project_leaders)) { foreach($project_leaders as $project_leader) { array_push($project_leaders_id, $project_leader['id']); } } // Add user header report_data(array(value => array("Users") , border => array("LRBT") , bold => array(1) , align => array("LRBT") , font_size => array(9) , cell_width => array(180) , cell_height => 16 , check_page_end => 1 , ishtml => array(array(type => "bookmark", data => "Users", parent => $_PAGE_INFO['bookmark_handle'], bold => 1)), nr_lines => 3 )); // Add user header report_data(array(value => array("Username", "Initials", "First name", "Last name", "Alarm number", _("Project leader") . "(RC)"), border => array("LRBT","LRBT","LRBT","LRBT","LRBT", "LRBT") , bold => array(1,1,1,1,1,1) , align => array("L","L","L","L","L","C") , font_size => array(8,8,8,8,8,8) , cell_width => array(31,31,31,31,31,25) , cell_height => 16 , check_page_end => 1 , new_page_hdr => 1 )); if (is_array($users)) { foreach($users as $user) { // Add users report_data(array(value => array($user['gebruikersnaam'], $user['voorletters'], $user['voornaam'], $user['achternaam'], $user['alarmnr'], (in_array($user['id'],$project_leaders_id)) ? "X" : ""), border => array("LRBT","LRBT","LRBT","LRBT","LRBT", "LRBT") , bold => array(0,0,0,0,0,0) , align => array("L","L","L","L","L","C") , font_size => array(8,8,8,8,8,8) , cell_width => array(31,31,31,31,31,25) , cell_height => 16 , check_page_end => 1 )); } } else { report_data(array(value => array("-", "-", "-", "-", "-","-") , border => array("LRBT","LRBT","LRBT","LRBT", "LRBT", "LRBT") , bold => array(0,0,0,0,0) , align => array("L","L","L","L","L","C") , font_size => array(8,8,8,8,8,8) , cell_width => array(31,31,31,31,31,25) , cell_height => 16 , check_page_end => 1 )); } // end line report_data(array(value => array("") , border => array("T") , bold => array(0) , align => array("L") , font_size => array(18) , cell_width => array(180) , cell_height => 16 , check_page_end => 0 )); // Clear new page header $_PAGE_INFO['new_page_hdr'] = ""; } /************************************/ /* Equipment */ /************************************/ if (db_ver_rights_user_one_valid($_PAGE_INFO['login']['user']['id'], "menu:lansen&menu:lansen:offline_status,menu:lansen:root")) { // Add child lances (own equipment) $lances = db_fetch_lances($_PAGE_INFO['childs'][$i]['id'], "", "", 6); // Add equipment header report_data(array(value => array("Equipment") , border => array("LRBT") , bold => array(1) , align => array("LRBT") , font_size => array(9) , cell_width => array(180) , cell_height => 16 , check_page_end => 1 , ishtml => array(array(type => "bookmark", data => "Equipment", parent => $_PAGE_INFO['bookmark_handle'], bold => 1)), nr_lines => 3 )); // Add equipment header report_data(array(value => array("ID code", _("ID code") . " " . _("owner"), "Status", "Telephone", "Equipment type", "Rented"), border => array("LRBT","LRBT","LRBT","LRBT", "LRBT", "LRBT") , bold => array(1,1,1,1,1,1) , align => array("L","L","L","L","L","C") , font_size => array(8,8,8,8,8,8) , cell_width => array(31,31,31,31,31,25) , cell_height => 16 , check_page_end => 1 , new_page_hdr => 1 )); if (is_array($lances)) { foreach($lances as $lance) { // Add equipment $type = db_fetch_system_devices($_PAGE_INFO['i18n'],$lance['device']); $rented = (($lance['eigenaar'] == $lance['gebruiker']) || (is_null($lance['gebruiker']))) ? "" : "X"; report_data(array(value => array($lance['serienr'], $lance['idcode'], $lance['lans_status'], $lance['telefoonnr'], $type[0]['naam'], $rented), border => array("LRBT","LRBT","LRBT","LRBT", "LRBT", "LRBT") , bold => array(0,0,0,0,0,0) , align => array("L","L","L","L","L","C") , font_size => array(8,8,8,8,8,8) , cell_width => array(31,31,31,31,31,25) , cell_height => 16 , check_page_end => 1 )); } } else { report_data(array(value => array("-", "-", "-", "-", "-", "-") , border => array("LRBT","LRBT","LRBT","LRBT", "LRBT", "LRBT") , bold => array(0,0,0,0,0,0) , align => array("L","L","L","L","L","C") , font_size => array(8,8,8,8,8,8) , cell_width => array(31,31,31,31,31,25) , cell_height => 16 , check_page_end => 1 )); } // end line report_data(array(value => array("") , border => array("T") , bold => array(0) , align => array("L") , font_size => array(18) , cell_width => array(180) , cell_height => 16 , check_page_end => 0 )); // Clear new page header $_PAGE_INFO['new_page_hdr'] = ""; } } } // Generate document report_generate(); } /** * Create the users report */ function report_user() { GLOBAL $_PAGE_INFO; // Give the script some extra memory and execution time ini_set("memory_limit","2048M"); ini_set("max_execution_time","120"); // Define voor default action define("DEFAULT_EMPTY_VALUE" ,'-'); // Get log data from the "report" database db_connect("report", "log"); // Set file info $_PAGE_INFO['report_type'] = "csv"; $_PAGE_INFO['dest'] = "D"; $_PAGE_INFO['file'] = str_replace(" ", "_", _("User report")) . "_" . str_replace("-", "", date('Y-m-d')) . ".csv"; // Define header $all_fields = array("Timestamp", "User", "Company name", "Mobile number","Emergency number", "Interface","Page menu","Ip",_("ID code")." ".ucwords($_SESSION[$_PAGE_INFO['id']]['skin_name']),_("ID code")." "._("owner"),"GPS","Project","Action"); // An array for the log user data $array_log_user = array(); // Create document header report_header(); // Create first line header report_data(array(value => $all_fields)); // Search all users down the pyramid $users = db_search_users(); // Get all user info if (is_array($users)) { foreach ($users as $user) { // Get user company $company = db_fetch_customer($user['klant'], 1); // Get alarm number of the user $phone_nr = $user['alarmnr']; // Get mobile number of the user $mobile_number = $user['mobielnr']; if (empty($mobile_number)) { $mobile_number = DEFAULT_EMPTY_VALUE; } // Get user id $ids = $user['id']; // Initialisation values $session[$session_id]['RSID']=DEFAULT_EMPTY_VALUE; // Get log user entries for each user $log_users = db_fetch_user_log($ids); if (is_array($log_users)) { foreach ($log_users as $log_user) { // Get session_id $session_id = $log_user['session_id']; // Check if the log user have an session id if (!empty($session_id)) { // Get time $timestamp = $log_user['tijd']; // Get page $page_menu = $log_user['menu']; // Default value for action $action=DEFAULT_EMPTY_VALUE; // Get an action if menu is `menu:lans...`, `menu:klanten...`, `menu:gebruikers...`, `menu:projecten...` if (fnmatch('menu:lans*',$page_menu) || fnmatch('menu:projecten*',$page_menu)|| fnmatch('menu:lans:relais_aansturing*',$page_menu) || fnmatch('menu:realtime_status*',$page_menu)) { // Get the idcode $action = db_fetch_user_log_zkl($log_user['id']); if (!empty($action)) { $temp = ""; for ($i=0; $i= 0; $i--) { // Add line to report report_data_field($all_fields, array(value => $array_log_user[$i]), array("Timestamp", "User", "Company name","Mobile number", "Emergency number", "Interface","Page menu","Ip",_("ID code")." ".ucwords($_SESSION[$_PAGE_INFO['id']]['skin_name']),_("ID code")." "._("owner"),"GPS","Project","Action")); } } } // Generate document report_generate(); } /** * Get Page name */ function getPagename($pagename){ $result = _('h:'.$pagename); if ($result == 'h:'.$pagename){ $result=_('h2:'.$pagename); if($result == 'h2:'.$pagename){ $result = _($pagename); } } return $result; } /* * Determine childs recursive */ function childs_recursive($parent) { GLOBAL $_PAGE_INFO; $childs = db_fetch_customer_childs($parent); if (is_array($childs)) { // sort array $childs = array_sort($childs, "bedrijfsnaam"); foreach($childs as $child) { // Store result array_push($_PAGE_INFO['childs'], $child); // Find childs childs_recursive($child['id']); } } } /** * Create report overview */ function report_overview($params) { global $_PAGE_INFO; // Initial value $index = 0; // Find all equipment $equipment = db_fetch_all_lances(); // Retreive generic information $date = date('Y-m-d'); // Set file info $_PAGE_INFO['report_type'] = $params['report_type']; $_PAGE_INFO['dest'] = $params['dest']; $_PAGE_INFO['file'] = _("Report") . "_" . str_replace("-", "",$date) . "." . $_PAGE_INFO['report_type']; $_PAGE_INFO['document'] = ""; // Create header info (when required) report_header(); // Get requested items if (is_array($equipment)) { foreach ($equipment as $item) { // Is this equipment which can measure => New calibration if ((!isset($params['capability'])) || (db_check_system_device_capabilities($item['device'], $params['capability']))) { // Reset value $line = array(); $header = array(); // Add index array_push($header, "index"); array_push($line, ++$count); foreach ($item as $key => $value) { if ((!isset($params['ReqItems'])) || ((is_array($params['ReqItems'])) && (in_array($key, $params['ReqItems'])))) { switch($key) { case "onderhoud": // Check whether the sw3000_onderhoud has been filled $date = strip_time(NextService($value,$item['sw3000_onderhoud'])); array_push($header, $key); array_push($line, $date); break; case "device": if (!is_null($value)) { // Get all types $types = db_fetch_system_devices($params['i18n']); if (is_array($types)) { foreach($types as $type) { if ($type['id'] == $value) { array_push($header, "Device"); array_push($line, $type['naam']); break; } } } } else { array_push($header, "Device"); array_push($line, "-"); } break; case "eigenaar": // Get customer info $cust_info = db_fetch_customer($value, 1); array_push($header, $key); array_push($line, $cust_info['bedrijfsnaam']); break; case "gebruiker": if (!is_null($value)) { // Get customer info $cust_info = db_fetch_customer($value, 1); array_push($header, $key); array_push($line, $cust_info['bedrijfsnaam']); } else { array_push($header, $key); array_push($line, "-"); } break; case "idcode": array_push($header, "Relatie ID code"); array_push($line, $value); break; case "serienr": array_push($header, "Dual Inventive ID code "); array_push($line, $value); break; default: // Do nothing (no checks, conversions etc.) array_push($header, $key); array_push($line, $value); break; } } } // Add header if ($count == 1) { // Write info to report Report_Data(array(value => $header)); } // Write info to report Report_Data(array(value => $line)); } } } // Generate document return report_generate(); } /** * Create live report */ function report_live($params) { global $_PAGE_INFO; // Find all equipment $equipment = db_search_lances(); // Sort by id $equipment = array_sort($equipment, "id", SORT_NUMERIC); // Retreive generic information $date = date('Y-m-d'); // Set file info $_PAGE_INFO['report_type'] = $params['report_type']; $_PAGE_INFO['dest'] = $params['dest']; $_PAGE_INFO['file'] = ucfirst(_("live")) . "_" . strtolower(_("Report")) . "_" . (isset($params['customer']) ? strtoupper($params['customer']['klantnaam']) . "_" : "") . str_replace("-", "",$date) . "." . $_PAGE_INFO['report_type']; $_PAGE_INFO['report_separator'] = ';'; $_PAGE_INFO['document'] = ""; // Create header info (when required) report_header(); // Get requested items if (is_array($equipment)) { foreach ($equipment as $item) { // Is this equipment which can switch and measure? if (db_check_system_device_capabilities($item['device'], array("meting", "kortsluiting schakelen"))) { // Reset value $line = array(); // Fetch last log_rt entry $log_rt = db_fetch_lance_logrt($item['id']); // Fetch last detection ok from cache $det_ok = db_fetch_cache($item['id'], 'det ok'); foreach ($params['ReqItems'] as $req_item) { // Default value $value = ""; switch($req_item) { case "batt1_niveau": case "batt2_niveau": // Default value $value = "0,000"; if ((is_array($log_rt)) && (isset($log_rt[0][$req_item]))) { $value = str_replace('.', ',', $log_rt[0][$req_item]); } break; case "temp_onboard": // Default value $value = "0,0"; if ((is_array($log_rt)) && (isset($log_rt[0][$req_item]))) { $value = str_replace('.', ',', $log_rt[0][$req_item]); } break; case "t": // Default value $date = "1970-01-01"; $value = "00:00:00"; if ((is_array($log_rt)) && (isset($log_rt[0][$req_item]))) { $date = strip_time(convert_datetime($log_rt[0][$req_item], TRUE)); $value = strip_date(convert_datetime($log_rt[0][$req_item], TRUE), FALSE); } // Add date to line array_push($line, $date); break; case "det_ok_quality": $value = sprintf("%.2f", CalcShortCircuitQuality($det_ok['b_a_autocal'], $det_ok['b_a'])) . "%"; break; case "det_ok_b_a": // Default value $value = "0,000"; if ((is_array($det_ok)) && (isset($det_ok['b_a']))) { $value = str_replace('.', ',', $det_ok['b_a']); } break; case "det_ok_b_a_limit": // Default value $value = "0,000"; if ((is_array($det_ok)) && (isset($det_ok['b_a_autocal']))) { $value = str_replace('.', ',', $det_ok['b_a_autocal']); } break; case "det_ok_timestamp": // Default value $date = "1970-01-01"; $value = "00:00:00"; if ((is_array($det_ok)) && (isset($det_ok['t']))) { $date = strip_time(convert_datetime($det_ok['t'], TRUE)); $value = strip_date(convert_datetime($det_ok['t'], TRUE), FALSE); } // Add date to line array_push($line, $date); break; default: $value = $item[$req_item]; // Do nothing (no checks, conversions etc.) break; } // Add to line array_push($line, $value); } // Write info to report Report_Data(array(value => $line)); } } } // Generate document return report_generate(); } ?>