split() 8/3/09 explode() -> split() for gtrack and locateA functions 8/7/09 Revised function generate_date_dropdown to change display based on locale setting 8/9/09 revise glat() to handle non-Curl configurations 8/10/09 removed 'mobile = 1' from tracking select criteria, removed locale case "2" 8/20/09 added close_incident link 9/29/09 Added additional $Globals for new log events and Status Special 10/20/09 Added function remove_nls to strip new lines from database entries for use in JS tooltips. 11/7/09 E_DEPRECATED, is_email() redo for deprecated 11/20/09 revised show_log () for shortened field display and title 11/21/09 $_SESSION destroy added to logout 11/27/09 added no-edit option to function add_header() 12/13/09 force GLat badge hyphen 12/26/09 send 'logged in' flag 1/6/10 revised get_sess_key() to use userid in hash 1/7/10 added function my_date_diff() 1/8/10 NULL to user sid on logout 1/23/10 browser detect added 2/1/10 disallow guest email 2/6/10 moved get_status_sel() from FMP 2/7/10 correction for empty values - source TBD 2/8/10 added units and facilities color-coding and legend 2/18/10 'reply-to' correction 2/19/10 Set/Get_Cookie() added 3/8/10 added session vbls to show/hide facilities and unavailable units 3/13/10 added function is_phone () 3/21/10 added function get_unit_status_legend() 3/25/10 added function get_un_div_height (), log_codes.inc 3/30/10 relocated 'dispatch' link 4/4/10 session_start added 2 places 4/27/10 added show/hide unavailable units - per AF mail 4/29/10 session_destroy() to force CB frame reload on timeout, reload top frame 4/30/10 added addr string with ticket descr 5/2/10 added get_start(), get_end(), misc date functions 5/4/10 $_SESSION['internet'] added 5/13/10 re-do my_date_diff() 6/17/10 applied intval() to delta_mins 6/24/10 round instam speed 6/25/10 'member' login supported as guest 6/26/10 911 contact information added 7/2/10 functions is_member(), may_email() added, allow upper case email addr elements 7/5/10 smtp revised to accomodate security protocol- per Kurt Jack 7/6/10 function show_assigns() per AH 7/10/10 added function get_cb_height () 7/12/10 added level 'unit' 7/15/10 'NULL' corrections 7/21/10 remove dead 'reserved' tickets 7/26/10 unit login to term page 7/27/10 handle undefined session key 7/28/10 deletion error suppress 7/28/10 Added inclusion of startup.inc.php for checking of network status and setting of file name variables to support no-maps versions of scripts. 8/5/10 auto-detect new install - moved to index.php 8/10/10 logout user sql corrections applied, try/catch applied to cb/frame 8/13/10 glat hyphen drop 8/25/10 session housekeeping corrected, expires format changed to integer, logout() relocated to LIP 8/27/10 UK date format per AH, operator ticket edit test added 8/29/10 added get_disp_status() 9/22/10 has_admin()added 9/29/10 mysql2timestamp typecast and drop ldg zeros, added do_diff(), require_once => require 10/2/10 added function short_ts() - timestamp trimmer 10/5/10 added function set_u_updated () 10/19/10 u2fenr reference correction 11/14/10 fix occasional 'Undefined index: user_id' 11/16/10 added check for locale for UK/OZ phone number format. 11/24/10 added function get_dist_factor() 11/26/10 functions get_speed(), get_remote() added 11/29/10 locale == 2 handling added 11/26/10 added function get_remote() 11/30/10 added function get_hints() 12/03/10 added require status_cats.inc.php. 12/4/10 added GLOBALS['CLOUD_SQL_STR'] 3/15/11 added function replace quotes to replace double quotes with single in html strings to fix js complaint 3/15/11 revised text color on facility types yellow background to black from white. 3/15/11 Add function get_css to get css colors from table for revisable screen colors and day/night setting. 3/19/11 added function get_unit() 4/23/11 added JSON optional get_remote() param 5/22/11 added notify severity filter 5/25/11 log intrusion detection, shut_down() added 6/10/11 added functions for regional operation 7/6/11 OpenGTS, $GLOBALS['TRACK_NAMES' added 10/18/11 Added functions for receiving facility control on mobile page. 10/26/11 Added function is_admin - checks for administrator but not super. 3/11/12 added LOG_UNIT_TO_QUARTERS 3/22/12 added ICS 213 log entry 4/12/12 moved regions view control functions from individual files into FIP 6/18/12 added cases "S" and "T", and revised match string error notification 6/20/12 corrections to set_u_updated() re responder schema/sql 10/20/12 fixes to show_log()and get_disps() re handle, ordering 10/23/12 Additions to support message store and additional $GLOBALS for resource type in multi region allocations. 11/2/2012 corrects smtp address validation 11/13/2012 handle "U" as units list request 11/14/2012 realigned mail_it formal paramters to accommodate optional smsg_to_str 11/30/2012 significant re-do, dropping unixtimestamp in favor of strtotime. Also see FMP 12/14/2012 corrections to case "S", if/else for cell messages, date string handling in function mail_it 3/4/2013 corrections to function format_date_2() 3/27/2013 AS revisions - $GLOBALS['NM_LAT_VAL'], function get_maptype_str () - used with GMaps V3 4/10/13 revised calling of KML files for GMaps V3 5/11/2013 revised do_error() logging 5/11/2013 fix to remove '_on' from set_u_updated () sql 5/20/2013 - rewrote get_elapsed_time with its calls, added function now_ts() 5/23/2013 - replaced nl2br with replace_newline 5/31/2013 message selector string housekeeping added 6/10/2013 fix to set_u_updated () re _from 7/3/2013 function mail_it () subject line corrected 7/10/13 Revisions to function show_actions( to correct failure to show patients if no actions. 8/9/13 Added globals colors for Warn Locations 8/28/13 Added Mail list notifies to function notify user 9/6/13 Added tracking type - mobile tracker for mobile screen 9/10/13 Added function show_unit_log() and function list_files(...) 9/10/13 Added Xastir APR tracking 4/7/2014 ICS message code revised 5/8/14 Revised call to format_sb_date_2 in function show_log to correct incorrect display. */ error_reporting(E_ALL); // { -- dummy // // mysql2i shim removed — all code migrated to db_query() and mysqli require_once('istest.inc.php'); require_once('mysql.inc.php'); require_once(__DIR__ . '/db.inc.php'); // Secure database abstraction layer require_once(__DIR__ . '/security.inc.php'); // Security helpers (XSS, CSRF, etc.) set_security_headers(); // 3/14/26 - Deploy security headers globally require_once("phpcoord.php"); // UTM converter require_once("usng.inc.php"); // USNG converter 9/12/08 require_once("browser.inc.php"); // added 1/23/10 require_once("messaging.inc.php"); // added 10/23/12 require_once("member.inc.php"); // added 10/23/12 if ( !defined( 'E_DEPRECATED' ) ) { define( 'E_DEPRECATED',8192 );} // 11/7/09 error_reporting (E_ALL ^ E_DEPRECATED); define ('NOT_STR', '*not*'); define ('NA_STR', '*na*'); define ('ADM_STR', 'Admin'); define ('SUPR_STR', 'Super'); // added 6/16/08 /* constants - do NOT change */ $GLOBALS['STATUS_RESERVED'] = 0; // 10/24/08 $GLOBALS['STATUS_CLOSED'] = 1; $GLOBALS['STATUS_OPEN'] = 2; $GLOBALS['STATUS_SCHEDULED'] = 3; $GLOBALS['NOTIFY_ACTION'] = "Added Action/Patient"; $GLOBALS['NOTIFY_TICKET'] = 'Ticket Update'; $GLOBALS['ACTION_DESCRIPTION'] = 1; $GLOBALS['ACTION_OPEN'] = 2; $GLOBALS['ACTION_CLOSE'] = 3; $GLOBALS['PATIENT_OPEN'] = 4; $GLOBALS['PATIENT_CLOSE'] = 5; $GLOBALS['NOTIFY_TICKET_CHG'] = 0; // 10/22/08 $GLOBALS['NOTIFY_ACTION_CHG'] = 1; $GLOBALS['NOTIFY_PERSON_CHG'] = 2; $GLOBALS['NOTIFY_TICKET_OPEN'] = 3; $GLOBALS['NOTIFY_TICKET_CLOSE'] = 4; //$GLOBALS['ACTION_OWNER'] = 4; //$GLOBALS['ACTION_PROBLEMSTART'] = 5; //$GLOBALS['ACTION_PROBLEMEND'] = 6; //$GLOBALS['ACTION_AFFECTED'] = 7; //$GLOBALS['ACTION_SCOPE'] = 8; //$GLOBALS['ACTION_SEVERITY'] = 9; $GLOBALS['ACTION_COMMENT'] = 10; $GLOBALS['SEVERITY_NORMAL'] = 0; $GLOBALS['SEVERITY_MEDIUM'] = 1; $GLOBALS['SEVERITY_HIGH'] = 2; $GLOBALS['LEVEL_SUPER'] = 0; // 6/9/08 $GLOBALS['LEVEL_ADMINISTRATOR'] = 1; $GLOBALS['LEVEL_ADMINITRATOR'] = $GLOBALS['LEVEL_ADMINISTRATOR']; // legacy misspelling alias $GLOBALS['LEVEL_USER'] = 2; $GLOBALS['LEVEL_GUEST'] = 3; $GLOBALS['LEVEL_MEMBER'] = 4; // 12/15/08 $GLOBALS['LEVEL_UNIT'] = 5; // 7/8/09 $GLOBALS['LEVEL_STATS'] = 6; // 7/6/11 $GLOBALS['LEVEL_SERVICE_USER'] = 7; // 10/23/12 $GLOBALS['LEVEL_FACILITY'] = 8; // 04/08/12 $GLOBALS['LEVEL_MANAGER'] = 8; // 04/08/12 $GLOBALS['LOG_SIGN_IN'] = 1; $GLOBALS['LOG_SIGN_OUT'] = 2; $GLOBALS['LOG_COMMENT'] = 3; // misc comment $GLOBALS['LOG_INCIDENT_OPEN'] =10; $GLOBALS['LOG_INCIDENT_CLOSE'] =11; $GLOBALS['LOG_INCIDENT_CHANGE'] =12; $GLOBALS['LOG_ACTION_ADD'] =13; $GLOBALS['LOG_PATIENT_ADD'] =14; $GLOBALS['LOG_INCIDENT_DELETE'] =15; // added 6/4/08 $GLOBALS['LOG_ACTION_DELETE'] =16; // 8/7/08 $GLOBALS['LOG_PATIENT_DELETE'] =17; $GLOBALS['LOG_UNIT_STATUS'] =20; $GLOBALS['LOG_UNIT_COMPLETE'] =21; // run complete $GLOBALS['LOG_UNIT_CHANGE'] =22; $GLOBALS['LOG_UNIT_TO_QUARTERS'] =23; // 3/11/12 $GLOBALS['LOG_UNIT_COMMENT'] =24; // 3/18/15 $GLOBALS['LOG_MEMBER_STATUS'] =120; $GLOBALS['LOG_MEMBER_COMPLETE'] =121; $GLOBALS['LOG_MEMBER_CHANGE'] =122; $GLOBALS['LOG_MEMBER_ADD'] =123; $GLOBALS['LOG_MEMBER_TYPE'] =124; $GLOBALS['LOG_CALL_EDIT'] =29; // 6/17/11 $GLOBALS['LOG_CALL_DISP'] =30; // 1/20/09 $GLOBALS['LOG_CALL_RESP'] =31; $GLOBALS['LOG_CALL_ONSCN'] =32; $GLOBALS['LOG_CALL_CLR'] =33; $GLOBALS['LOG_CALL_RESET'] =34; // 7/7/09 $GLOBALS['LOG_CALL_REC_FAC_SET'] =35; // 9/29/09 $GLOBALS['LOG_CALL_REC_FAC_CHANGE'] =36; // 9/29/09 $GLOBALS['LOG_CALL_REC_FAC_UNSET'] =37; // 9/29/09 $GLOBALS['LOG_CALL_REC_FAC_CLEAR'] =38; // 9/29/09 $GLOBALS['LOG_FACILITY_ADD'] =40; // 9/22/09 $GLOBALS['LOG_FACILITY_CHANGE'] =41; // 9/22/09 $GLOBALS['LOG_FACILITY_STATUS'] = 4040; $GLOBALS['LOG_FACILITY_INCIDENT_OPEN'] =42; // 9/29/09 $GLOBALS['LOG_FACILITY_INCIDENT_CLOSE'] =43; // 9/29/09 $GLOBALS['LOG_FACILITY_INCIDENT_CHANGE']=44; // 9/29/09 $GLOBALS['LOG_CALL_U2FENR'] =45; // 9/29/09 $GLOBALS['LOG_CALL_U2FARR'] =46; // 9/29/09 $GLOBALS['LOG_FACILITY_DISP'] =47; // 9/22/09 $GLOBALS['LOG_FACILITY_RESP'] =48; // 9/22/09 $GLOBALS['LOG_FACILITY_ONSCN'] =49; // 9/22/09 $GLOBALS['LOG_FACILITY_CLR'] =50; // 9/22/09 $GLOBALS['LOG_FACILITY_RESET'] =51; // 9/22/09 $GLOBALS['LOG_ICS_MESSAGE_SEND'] =60; // 4/7/2014 $GLOBALS['LOG_ERROR'] =90; // 1/10/11 $GLOBALS['LOG_INTRUSION'] =91; // 5/25/11 $GLOBALS['LOG_ERRONEOUS'] =0; // 1/10/11 $GLOBALS['LOG_SMSGATEWAY_CONNECT'] =1000; // 10/23/12 $GLOBALS['LOG_SMSGATEWAY_SEND'] =1001; // 10/23/12 $GLOBALS['LOG_SMSGATEWAY_RECEIVE'] =1002; // 10/23/12 $GLOBALS['LOG_EMAIL_CONNECT'] =1010; // 10/23/12 $GLOBALS['LOG_EMAIL_SEND'] =1011; // 10/23/12 $GLOBALS['LOG_EMAIL_RECEIVE'] =1012; // 10/23/12 $GLOBALS['LOG_NEW_REQUEST'] =2010; // 26/7/13 $GLOBALS['LOG_EDIT_REQUEST'] =2011; // 26/7/13 $GLOBALS['LOG_CANCEL_REQUEST'] =3012; // 26/7/13 $GLOBALS['LOG_ACCEPT_REQUEST'] =3013; // 26/7/13 $GLOBALS['LOG_TENTATIVE_REQUEST'] =3014; // 26/7/13 $GLOBALS['LOG_DECLINE_REQUEST'] =3015; // 26/7/13 $GLOBALS['LOG_WARNLOCATION_ADD'] =4010; // 8/9/13 $GLOBALS['LOG_WARNLOCATION_CHANGE'] =4013; // 8/9/13 $GLOBALS['LOG_WARNLOCATION_DELETE'] =4014; // 8/9/13 $GLOBALS['LOG_BROADCAST_MESSAGE'] =5000; // 11/30/15 $GLOBALS['LOG_BROADCAST_ALERT'] =5001; // 11/30/15 $GLOBALS['LOG_BROADCAST_ERROR'] =5099; // 11/30/15 $GLOBALS['LOG_SYSTEM_MESSAGE'] =5999; // 07/06/16 $GLOBALS['SOCKET_MESSAGETYPE_STANDARD'] = 1; // 12/16/15 $GLOBALS['SOCKET_MESSAGETYPE_ERROR'] = 99; // 12/16/15 $GLOBALS['SOCKET_MESSAGETYPE_STARTSTOP'] = 199; // 12/16/15 $GLOBALS['SOCKET_MESSAGETYPE_INCUPDATE'] = 21; // 12/16/15 $GLOBALS['SOCKET_MESSAGETYPE_RESPUPDATE'] = 22; // 12/16/15 $GLOBALS['SOCKET_MESSAGETYPE_RESPSTATUS'] = 23; // 12/16/15 $GLOBALS['SOCKET_MESSAGETYPE_POSUPDATE'] = 24; // 12/16/15 $GLOBALS['SOCKET_MESSAGETYPE_FACPUPDATE'] = 25; // 12/16/15 $GLOBALS['SOCKET_MESSAGETYPE_CHATID'] = 26; // 12/16/15 $GLOBALS['SOCKET_MESSAGETYPE_DISPUPDATE'] = 27; // 12/16/15 $GLOBALS['SOCKET_MESSAGETYPE_REQUPDATE'] = 28; // 12/16/15 $GLOBALS['SOCKET_MESSAGETYPE_OSWUPDATE'] = 29; // 12/16/15 $GLOBALS['LOG_SPURIOUS'] =127; // 10/24/13 Added to catch failed logs $GLOBALS['icons'] = array("black.png", "blue.png", "green.png", "red.png", "white.png", "yellow.png", "gray.png", "lt_blue.png", "orange.png"); $GLOBALS['sm_icons'] = array("sm_black.png", "sm_blue.png", "sm_green.png", "sm_red.png", "sm_white.png", "sm_yellow.png", "sm_gray.png", "sm_lt_blue.png", "sm_orange.png"); $GLOBALS['fac_icons'] = array("square_red.png", "square_black.png", "square_white.png", "square_yellow.png", "square_blue.png", "square_green.png", "shield_red.png", "shield_grey.png", "shield_green.png", "shield_blue.png", "shield_orange.png"); $GLOBALS['sm_fac_icons'] = array("sm_square_red.png", "sm_square_black.png", "sm_square_white.png", "sm_square_yellow.png", "sm_square_blue.png", "sm_square_green.png", "sm_shield_red.png", "sm_shield_grey.png", "sm_shield_green.png", "sm_shield_blue.png", "sm_shield_orange.png"); $GLOBALS['SESSION_TIME_LIMIT'] = 60*480; // minutes of inactivity before logout is forced - 1/18/10 $GLOBALS['TOLERANCE'] = 180*60; // seconds of deviation from UTC before remotes sources considered not current - 3/25/09 $GLOBALS['TRACK_NONE'] =0; // 12/3/10 $GLOBALS['TRACK_APRS'] =1; // 7/8/09 $GLOBALS['TRACK_INSTAM'] =2; $GLOBALS['TRACK_GTRACK'] =3; $GLOBALS['TRACK_LOCATEA'] =4; $GLOBALS['TRACK_GLAT'] =5; $GLOBALS['TRACK_OGTS'] =6; // 7/6/11 $GLOBALS['TRACK_T_TRACKER'] =7; // 5/11/11 $GLOBALS['TRACK_MOBILE'] =8; // 9/6/13 $GLOBALS['TRACK_XASTIR'] =9; // 1/30/14 $GLOBALS['TRACK_FOLLOWMEE'] =10; $GLOBALS['TRACK_TRACCAR'] =11; $GLOBALS['TRACK_JAVAPRSSRVR'] =12; $GLOBALS['TRACK_2L'] = array("", "AP", "IN", "GT", "LO", "GL", "OG", "TT", "MT", "XA", "FM", "TR", "JA" ); // 7/6/11, 9/6/13, 1/30/14 $GLOBALS['TRACK_NAMES'] = array("", "APRS", "Instamapper", "GTrack", "LocateA", "Latitude", "OpenGTS", "Internal", "Mobile Tracker", "Xastir", "FollowMee", "Traccar", "Javaprssrvr" ); // 7/6/11, 9/16/13, 1/30/14 $GLOBALS['UNIT_TYPES_BG'] = array("#000000", "#5A59FF", "#63DB63", "#FF3C4A", "#FFFFFF", "#F7F363", "#C6C3C6", "#00FFFF"); // keyed to unit_types - 2/8/10 $GLOBALS['UNIT_TYPES_TEXT'] = array("#FFFFFF", "#FFFFFF", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000"); // 2/8/10 $GLOBALS['FACY_TYPES_BG'] = array("#E72429", "#000000", "#E7E3E7", "#E7E321", "#5269BD", "#52BE52", "#C60000", "#7B7D7B", "#005D00", "#1000EF"); // keyed to fac_types - 2/8/10 $GLOBALS['FACY_TYPES_TEXT'] = array("#000000", "#FFFFFF", "#000000", "#000000", "#FFFFFF", "#000000", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF"); // 2/8/10, 02/05/11 - revised text color on yellow background to black. $GLOBALS['CLOUD_SQL_STR'] = "`passwd` = '55606758fdb765ed015f0612112a6ca7'"; // 12/4/10 $GLOBALS['TYPE_TICKET'] = 1; // 10/23/12 $GLOBALS['TYPE_UNIT'] = 2; // 10/23/12 $GLOBALS['TYPE_FACILITY'] = 3; // 10/23/12 $GLOBALS['TYPE_USER'] = 4; // 10/23/12 $GLOBALS['MSGTYPE_OG_EMAIL'] = 1; // 10/23/12 $GLOBALS['MSGTYPE_IC_EMAIL'] = 2; // 10/23/12 $GLOBALS['MSGTYPE_OG_SMS'] = 3; // 10/23/12 $GLOBALS['MSGTYPE_IC_SMS'] = 4; // 10/23/12 $GLOBALS['MSGTYPE_IC_SMS_DR'] = 5; // 10/23/12 $GLOBALS['MSGTYPE_IC_SMS_DF'] = 6; // 10/23/12 $GLOBALS['NM_LAT_VAL'] = 0.999999; // 3/27/2013 $GLOBALS['LOC_TYPES_NAMES'] = array('Violence','Frequent','Health','Environmental','General'); $GLOBALS['LOC_TYPES'] = array(0,1,2,3,4); // 11/10/14 $GLOBALS['LOC_TYPES_BG'] = array('#FF0000','#000000','#FFFFFF','#FFFF00','#0000FF '); // 11/10/14 $GLOBALS['LOC_TYPES_TEXT'] = array('#FFFFFF','#FFFFFF','#000000','#000000','#FFFFFF'); // 11/10/14 $GLOBALS['wl_icons'] = array("square_red.png", "square_black.png", "square_white.png", "square_yellow.png", "square_blue.png"); $GLOBALS['wl_sm_icons'] = array("sm_square_red.png", "sm_square_black.png", "sm_square_white.png", "sm_square_yellow.png", "sm_square_blue.png"); $evenodd = array ("even", "odd", "heading"); // class names for alternating table row css colors /* connect to mysql database */ $GLOBALS['db_handle'] = mysqli_connect($GLOBALS['mysql_host'], $GLOBALS['mysql_user'], $GLOBALS['mysql_passwd'], $GLOBALS['mysql_db']); // MySQL 8.0+ strict mode compatibility: disable ONLY_FULL_GROUP_BY (legacy // queries use SELECT * with GROUP BY) and STRICT_TRANS_TABLES (legacy code // uses '' for DATETIME columns instead of NULL) if ($GLOBALS['db_handle']) { mysqli_query($GLOBALS['db_handle'], "SET SESSION sql_mode = 'ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'"); } /* if (!$connect) { die ("Connection attempt to MySQL failed - correction required in order to continue."); } */ /* if (!$db_selected) { print "Connection attempt to database failed. Please run install.php with valid database configuration information."; } */ /* if (!mysql_connect($GLOBALS['mysql_host'], $GLOBALS['mysql_user'], $GLOBALS['mysql_passwd'])) { die ("Connection attempt to MySQL failed - correction required in order to continue."); } if (!mysql_select_db($GLOBALS['mysql_db'])) { print "Connection attempt to database failed. Please run install.php with valid database configuration information."; exit(); } */ /* check for mysql tables, if non-existent, point to install.php */ $failed = 0; if (!mysql_table_exists("{$GLOBALS['mysql_prefix']}user")) { print "MySQL table '{$GLOBALS['mysql_prefix']}user' is missing
"; $failed = 1; } if ($failed) { print "One or more database tables is missing. Please run install.php with valid database configuration information."; exit(); } $expiry = expires(); // note global $timezone = (get_variable('timezone') != "") ? get_variable('timezone') : "America/New_York"; date_default_timezone_set($timezone); $internet = intval(get_variable("internet")); require_once ('login.inc.php'); require_once('status_cats.inc.php'); $useMdb = get_variable('use_mdb'); $useMdbContact = (get_mdb_variable('use_mdb_contact')) ? get_mdb_variable('use_mdb_contact'): 0; $useMdbStatus = (get_mdb_variable('use_mdb_status')) ? get_mdb_variable('use_mdb_status') : 0; $validStatuses = array(); $validFacStatuses = array(); $rows = db_fetch_all("SELECT * FROM `{$GLOBALS['mysql_prefix']}un_status`"); foreach ($rows as $row) { $validStatuses[$row['id']] = $row['status_val']; } $rows = db_fetch_all("SELECT * FROM `{$GLOBALS['mysql_prefix']}fac_status`"); foreach ($rows as $row) { $validFacStatuses[$row['id']] = $row['status_val']; } /** * Replace all newline characters in a string with spaces. * * Handles \r\n, \n, and \r newline variants. Used for cleaning * database entries for display in JavaScript tooltips. * * @param string $instr The input string potentially containing newlines. * @return string The string with all newlines replaced by spaces. * @since v3.0 */ function remove_nls($instr) { $nls = array("\r\n", "\n", "\r"); // note order return str_replace($nls, " ", $instr); } // end function /** * Check whether a MySQL table exists in the current database. * * @param string $name The table name to check for. * @return bool TRUE if the table exists, FALSE otherwise. * @since v3.0 */ function mysql_table_exists($name) { $escaped = mysqli_real_escape_string(db(), $name); $result = db_query("SHOW TABLES LIKE '{$escaped}'"); return boolVal($result->num_rows > 0); } /** * Print the date field of a ticket directly to output. * * Queries the ticket table for the given ID and prints its date value. * Produces no output if the ticket is not found. * * @param int $id The ticket ID. * @return void * @since v3.0 */ function get_issue_date($id){ $row = db_fetch_one("SELECT `date` FROM `{$GLOBALS['mysql_prefix']}ticket` WHERE `id` = ?", [intval($id)]); if ($row) { print $row['date']; } } /** * Check if a SQL query returns any rows. * * Executes the given query and returns the row count if rows exist, * or FALSE if no rows are found. Uses prepared statements via db_query(). * * @param string $query SQL query string with optional ? placeholders. * @param array $params Values to bind to the placeholders. * @return int|false Number of rows found, or FALSE if none. * @since v3.0 */ function check_for_rows($query, $params = []) { $sql = db_query($query, $params); if($sql && $sql->num_rows !== 0) return $sql->num_rows; else return false; } // } { -- dummy function get_disp_closure_summary($tick_id) { $eol = PHP_EOL; $string = ""; $rows = db_fetch_all("SELECT * FROM `{$GLOBALS['mysql_prefix']}assigns` WHERE `ticket_id` = ? AND ((`clear` IS NOT NULL) AND (DATE_FORMAT(`clear`,'%y') != '00')) ORDER BY `id` ASC", [intval($tick_id)]); // 6/25/10 if (count($rows) > 0) { foreach($rows as $row) { $string .= "Unit: " . get_responder($row['responder_id']) . chr(0x0D).chr(0x0A); $string .= "D: " . format_sb_date_2($row['dispatched']) . chr(0x0D).chr(0x0A); $string .= "R: " . format_sb_date_2($row['responding']) . chr(0x0D).chr(0x0A); $string .= "O: " . format_sb_date_2($row['on_scene']) . chr(0x0D).chr(0x0A); if($row['u2fenr'] != null && $row['u2fenr'] != "0000-00-00 00:00:00") { $string .= "FENR: " . format_sb_date_2($row['u2fenr']) . chr(0x0D).chr(0x0A); } if($row['u2farr'] != null && $row['u2farr'] != "0000-00-00 00:00:00") { $string .= "FARR: " . format_sb_date_2($row['u2farr']) . chr(0x0D).chr(0x0A); } $string .= "C: " . format_sb_date_2($row['clear']) . chr(0x0D).chr(0x0A); } } return $string; } function get_disps($tick_id, $resp_id) { // 7/4/10, 10/20/12 $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}assigns` WHERE `ticket_id`= ? AND `responder_id` = ? AND ((`dispatched` IS NOT NULL) AND (DATE_FORMAT(`dispatched`,'%y') != '00')) AND ((`responding` IS NULL) OR (DATE_FORMAT(`responding`,'%y') = '00')) AND ((`on_scene` IS NULL) OR (DATE_FORMAT(`on_scene`,'%y') = '00')) AND ((`clear` IS NULL) OR (DATE_FORMAT(`clear`,'%y') = '00')) ORDER BY `id` DESC LIMIT 1"; $result = db_query($query, [$tick_id, $resp_id]); if ($result->num_rows>0) { $row = $result->fetch_assoc(); return "dispatched " . substr ($row['dispatched'] ,11 ,5 ); } $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}assigns` WHERE `ticket_id`= ? AND `responder_id` = ? AND ((`responding` IS NOT NULL) AND (DATE_FORMAT(`responding`,'%y') != '00')) AND ((`on_scene` IS NULL) OR (DATE_FORMAT(`on_scene`,'%y') = '00')) AND ((`clear` IS NULL) OR (DATE_FORMAT(`clear`,'%y') = '00')) ORDER BY `id` DESC LIMIT 1"; $result = db_query($query, [$tick_id, $resp_id]); if ($result->num_rows>0) { $row = $result->fetch_assoc(); return "responding " . substr ($row['responding'] ,11 ,5 ); } $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}assigns` WHERE `ticket_id`= ? AND `responder_id` = ? AND ((`on_scene` IS NOT NULL) AND (DATE_FORMAT(`dispatched`,'%y') != '00')) AND (`clear` IS NULL OR DATE_FORMAT(`clear`,'%y') = '00') ORDER BY `id` DESC LIMIT 1"; $result = db_query($query, [$tick_id, $resp_id]); if ($result->num_rows>0) { $row = $result->fetch_assoc(); return "on_scene " . substr ($row['on_scene'] ,11 ,5 ); } return "???? "; } function show_assigns($which, $id_in){ // 10/20/12 global $evenodd; $which_ar = array ("ticket_id", "responder_id"); // $as_query = "SELECT *, dispatched AS dispatched_i, responding AS responding_i, on_scene AS on_scene_i, u2fenr AS u2fenr_i, u2farr AS u2farr_i, clear AS clear_i, start_miles AS start_m, on_scene_miles AS os_miles, end_miles AS end_m, miles AS miles, `a`.`comments` AS `assigns_comments`, `r`.`handle`, `t`.`problemstart` AS `problemstart_i` FROM `{$GLOBALS['mysql_prefix']}assigns` `a` LEFT JOIN `{$GLOBALS['mysql_prefix']}responder` `r` ON (`r`.`id` = `a`.`responder_id`) LEFT JOIN `{$GLOBALS['mysql_prefix']}ticket` `t` ON (`t`.`id` = `a`.`ticket_id`) WHERE `a`.`{$which_ar[$which]}` = ? ORDER BY `problemstart_i` DESC LIMIT 50"; $as_result = db_query($as_query, [$id_in]); $out_str = $the_handle = ""; $i=0; // line counter if ($as_result->num_rows){ // $tags_arr = explode("/", get_variable('disp_stat')); if (count($tags_arr)<6) {$tags_arr = explode("/", "Disp/Resp/OnS/FEnr/FArr/Clear");} // protect against bad user setting $out_str = "\n\n"; while($row = stripslashes_deep($as_result->fetch_assoc())) { $start_miles = ($row['start_m'] != null) ? $row['start_m'] : "NA"; $os_miles = ($row['os_miles'] != null) ? $row['os_miles'] : "NA"; $end_miles = ($row['end_m'] != null) ? $row['end_m'] : "NA"; $notes = $row['assigns_comments']; if($row['miles'] != null) { $tot_miles = $row['miles']; } elseif(($row['miles'] == null) && (($start_miles != "NA") && ($end_miles != "NA"))) { $tot_miles = intval($end_miles) - intval($start_miles); } else { $tot_miles = "NA"; } $out_str .= "\n"; $out_str .= "\n"; $i++; if (is_date($row['dispatched'])) { $delta = my_date_diff($row['problemstart_i'], $row['dispatched_i']); $out_str .= "\n"; $i++;} if (is_date($row['responding'])) { $delta = my_date_diff($row['problemstart_i'], $row['responding_i']); $out_str .= "\n"; $i++;} if (is_date($row['on_scene'])) { $delta = my_date_diff($row['problemstart_i'], $row['on_scene_i']); $out_str .= "\n"; $i++;} if (is_date($row['u2fenr'])) { $delta = my_date_diff($row['problemstart_i'], $row['u2fenr_i']); $out_str .= "\n"; $i++;} if (is_date($row['u2farr'])) { $delta = my_date_diff($row['problemstart_i'], $row['u2farr_i']); $out_str .= "\n"; $i++;} if (is_date($row['clear'])) { $delta = my_date_diff($row['problemstart_i'], $row['clear_i']); $out_str .= "\n"; $i++;} if($notes != "" && $notes != "New") { $out_str .= "\n"; $i++; } $out_str .= "\n"; $i++; // 1/28/13 $out_str .= "\n"; $i++; // 1/28/13 } $out_str .= "
" . get_text("Dispatch") . " history
" . $row['scope'] . "
Start" . format_date_2(strtotime($row['problemstart_i'])) . "
{$tags_arr[0]}" . format_date_2(strtotime($row['dispatched_i'])) . " (" . $delta . ")
{$tags_arr[1]}" . format_date_2(strtotime($row['responding_i'])) . " (" . $delta . ")
{$tags_arr[2]}" . format_date_2(strtotime($row['on_scene_i'])) . " (" . $delta . ")
{$tags_arr[3]}" . format_date_2(strtotime($row['u2fenr_i'])) . " (" . $delta . ")
{$tags_arr[4]}" . format_date_2(strtotime($row['u2farr_i'])) . " (" . $delta . ")
{$tags_arr[5]}" . format_date_2(strtotime($row['clear_i'])) . " (" . $delta . ")
Notes:" . $notes . "
Start Miles: {$start_miles}  On Scene Miles: {$os_miles}  End Miles: {$end_miles}
TOTAL MILES: {$tot_miles}
\n"; } return $out_str; } // end function show_assigns() function show_actions ($the_id, $theSort, $links, $display, $mode=0) { /* list actions and patient data belonging to ticket */ $print = ""; if(empty($theSort)) { $theSort = "date"; } $evenodd = array("even", "odd"); if($display) { $evenodd = array ("plain", "plain"); } $query = "SELECT `id`, `name`, `handle` FROM `{$GLOBALS['mysql_prefix']}responder`"; $result = db_query($query); $responderlist = array(); $responderlist[0] = "NA"; while ($act_row = stripslashes_deep($result->fetch_assoc())){ $responderlist[$act_row['id']] = $act_row['handle']; } $query = "SELECT *, `p`.`id` AS `pat_id` FROM `{$GLOBALS['mysql_prefix']}patient` `p` LEFT JOIN `{$GLOBALS['mysql_prefix']}insurance` `i` ON (`i`.`id` = `p`.`insurance_id` ) WHERE `ticket_id`= ? ORDER BY `date`"; // 7/10/13 $result = db_query($query, [$the_id]); $caption = get_text("Patients"); $pctr=0; $genders = array("", "M", "F", "T", "U"); if($result->num_rows > 0) { $print .= ""; // Patients Table $print .= ""; while ($pat_row = stripslashes_deep($result->fetch_assoc())){ $the_gender = ($pat_row['gender'] != 0) ? $genders[$pat_row['gender']] : $genders[4]; // 7/12/13 $tipstr = addslashes("Name: {$pat_row['name']}
Fullname: {$pat_row['fullname']}
DOB: {$pat_row['dob']}
Gender: {$the_gender}
Insurance_id: {$pat_row['ins_value']}
Facility_contact: {$pat_row['facility_contact']}
Date: {$pat_row['date']}
Description:{$pat_row['description']}"); $print .= ""; $print .= ""; $print .= ""; if ($links) { if($mode == 0) { $print .= ""; } elseif($mode ==1) { $print .= ""; } else { $print .= ""; } } else { $print .= ""; } $print .= ""; $caption = ""; // once only $pctr++; } $print .= "
{$caption}
{$pat_row['name']} Z ". format_date_2($pat_row['updated']) . " by ". get_owner($pat_row['user']); $print .= ($pat_row['action_type']!=$GLOBALS['ACTION_COMMENT'] ? "*" : "-")."" . shorten($pat_row['description'], 24) . " [edit | delete] [edit | delete] [edit | delete]  Y ({$genders[$pat_row['gender']]}) - {$pat_row['fullname']} - Z{$pat_row['dob']} A {$pat_row['ins_value']} - B{$pat_row['facility_contact']}
"; // End of Patients Table } /* list actions */ $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}action` WHERE `ticket_id` = ? ORDER BY `date`"; $result = db_query($query, [$the_id]); $caption = get_text("Actions"); $actr=0; if ($result->num_rows > 0) { $print .= ""; // Actions Table $print .= ""; while ($act_row = stripslashes_deep($result->fetch_assoc())){ $tipstr = addslashes(replace_newline($act_row['description'])); $print .= ""; $responders = explode (" ", trim($act_row['responder'])); // space-separated list to array $sep = $respstring = ""; for ($i=0 ;$i< count($responders);$i++) { // build string of responder names if (array_key_exists($responders[$i], $responderlist)) { $respstring .= $sep . "• " . $responderlist[$responders[$i]]; $sep = "
"; } else { $respstring .= " "; } } $print .= ""; // 3/15/11 $print .= ""; // 3/15/11 if ($links) { if($mode == 0) { $print .= ""; } elseif($mode ==1) { $print .= "\n"; } else { $print .= "\n"; } } $caption = ""; $actr++; } // end while (...) $print .= "
{$caption}
" . $respstring . " ". format_date_2($act_row['updated']) ." by ".get_owner($act_row['user'])." "; // 3/15/11 $print .= ($act_row['action_type']!=$GLOBALS['ACTION_COMMENT'])? '*' : '-'; $print .= "" . replace_newline($act_row['description']) . " [edit | delete] [edit | delete] [edit | delete]
"; // End of Actions Table } return $print; } // end function show_actions function list_messages($the_id, $theSort, $links, $display) { $print = ""; if(empty($theSort)) { $theSort = "date"; } if(get_variable('use_messaging') != 0) { $evenodd = array ("even", "odd"); // class names for display table row colors $actr=1; $print = ""; $print .= ""; $print .= ""; $actr++; $query_messages = "SELECT * FROM `{$GLOBALS['mysql_prefix']}messages` WHERE `ticket_id`= ? ORDER BY `" . preg_replace('/[^a-zA-Z0-9_]/', '', $theSort) . "` ASC;"; $result_messages = db_query($query_messages, [$the_id]); if($result_messages->num_rows == 0) { $print .= ""; } else { while ($row_messages = $result_messages->fetch_assoc()) { if ($row_messages['msg_type'] == 1) { $type_flag = "Outoging Email"; $type = 1; $color = "background-color: blue; color: white;"; } elseif ($row_messages['msg_type'] ==2) { $type_flag = "Incoming Email"; $type = 2; $color = "background-color: white; color: blue;"; } elseif ($row_messages['msg_type'] ==3) { $color = "background-color: orange; color: white;"; $type_flag = "Outgoing SMS"; $type = 3; } elseif (($row_messages['msg_type'] ==4) || ($row_messages['msg_type'] ==5) || ($row_messages['msg_type'] ==6)) { $color = "background-color: white; color: orange;"; $type_flag = "Incoming SMS"; $type = 4; } else { $color = ""; $type_flag = "?"; $type = 99; } $print .= ""; $print .= ""; $print .= ""; $print .= ""; $print .= ""; $print .= ""; $actr++; } } $print .= "
Messages
TypeToFromSubjectMessageDate
No Messages
" . $type_flag . "" . stripslashes_deep(shorten($row_messages['recipients'], 18)) . "" . $row_messages['fromname'] . "" . stripslashes_deep(shorten($row_messages['subject'], 18)) . "" . stripslashes_deep(shorten($row_messages['message'], 100)) . "" . format_date_2(strtotime($row_messages['date'])) . "
"; } return $print; } // End of function Show Messages function show_actions_orig ($the_id, $theSort, $links, $display) { /* list actions and patient data belonging to ticket */ if(empty($theSort)) { $theSort = "date"; } if ($display) { $evenodd = array ("even", "odd"); // class names for display table row colors } else { $evenodd = array ("plain", "plain"); // print } $query = "SELECT `id`, `name`, `handle` FROM `{$GLOBALS['mysql_prefix']}responder`"; $result = db_query($query); $responderlist = array(); $responderlist[0] = "NA"; while ($act_row = stripslashes_deep($result->fetch_assoc())){ $responderlist[$act_row['id']] = $act_row['handle']; } $print = ""; /* list patients */ $query = "SELECT *, `date` AS `date`, `updated` AS `updated`, `p`.`id` AS `patient_id` FROM `{$GLOBALS['mysql_prefix']}patient` `p` LEFT JOIN `{$GLOBALS['mysql_prefix']}insurance` `i` ON (`i`.`id` = `p`.`insurance_id` ) WHERE `ticket_id`= ? ORDER BY `date`"; $result = db_query($query, [$the_id]); $caption = get_text("Patient") . ":   "; $actr=0; // $genders = array("M", "F", "T", "U"); $genders = array("", "M", "F", "T", "U"); while ($act_row = stripslashes_deep($result->fetch_assoc())){ $the_gender = $genders[$act_row['gender']]; $the_patient_id = $act_row['patient_id']; $tipstr = addslashes("Name: {$act_row['name']}
Fullname: {$act_row['fullname']}
DOB: {$act_row['dob']}
Gender: {$the_gender}
Insurance_id: {$act_row['ins_value']}
Facility_contact: {$act_row['facility_contact']}
Date: {$act_row['date']}
Description: {$act_row['description']}"); $print .= ""; $print .= ""; $print .= ""; if ($links) { $print .= "\n"; } $caption = ""; // once only $actr++; } /* list actions */ $query = "SELECT *, `date` AS `date`, `updated` AS `updated` FROM `{$GLOBALS['mysql_prefix']}action` WHERE `ticket_id`= ? ORDER BY `date`"; $result = db_query($query, [$the_id]); if (($result->num_rows + $actr)==0) { // 8/6/08 return ""; } else { $caption = "Actions:   "; $pctr=0; while ($act_row = stripslashes_deep($result->fetch_assoc())){ $tipstr = safe_addslashes($act_row['description']); $print .= ""; $responders = explode (" ", trim($act_row['responder'])); // space-separated list to array $sep = $respstring = ""; for ($i=0 ;$i< count($responders);$i++) { // build string of responder names if (array_key_exists($responders[$i], $responderlist)) { $respstring .= $sep . "• " . $responderlist[$responders[$i]]; $sep = "
"; } } $print .= ""; // 3/15/11 $print .= ""; // 3/15/11 if ($links) { $print .= "\n"; } $caption = ""; $pctr++; } // end if/else (...) $print .= "
" . $caption . "" . $act_row['name'] . "". format_date_2($act_row['updated']) . " by ".get_owner($act_row['user']).""; $print .= ($act_row['action_type']!=$GLOBALS['ACTION_COMMENT'] ? "*" : "-")." " . shorten($act_row['description'], 24) . " [edit| delete]
$caption" . $respstring . "". format_date_2($act_row['updated']) ."by ".get_owner($act_row['user'])." "; // 3/15/11 $print .= ($act_row['action_type']!=$GLOBALS['ACTION_COMMENT'])? '*' : '-'; $print .= "" . replace_newline($act_row['description']) . " [edit| delete]
\n"; return $print; } // end else } // end function show_actions_orig // } { -- dummy function show_messages ($the_id, $theSort, $links, $display) { /* list messages belonging to ticket 10/23/12 */ global $evenodd; if(empty($theSort)) { $theSort = "date"; } $actr=0; $query = "SELECT `id`, `name`, `handle` FROM `{$GLOBALS['mysql_prefix']}responder`"; $result = db_query($query); $responderlist = array(); $responderlist[0] = "NA"; $caption = "Messages: "; while ($act_row = stripslashes_deep($result->fetch_assoc())){ $responderlist[$act_row['id']] = $act_row['handle']; } $print = ""; $print .= ""; $query = "SELECT *, `date` AS `date`, `_on` AS `_on`, `m`.`id` AS `message_id`, `m`.`message` AS `message` FROM `{$GLOBALS['mysql_prefix']}messages` `m` WHERE `ticket_id`= ? ORDER BY `date`"; $result = db_query($query, [$the_id]); if ($result->num_rows == 0) { print "No Messages"; // return ""; } else { $msgtr=0; while ($msg_row = stripslashes_deep($result->fetch_assoc())){ $the_message_id = $msg_row['message_id']; $the_responder = $msg_row['resp_id']; $resp_name = (isset($responderlist[$the_responder])) ? $responderlist[$the_responder] : ""; // $tipstr = addslashes("Name: {$act_row['name']}
Fullname: {$act_row['fullname']}
DOB: {$act_row['dob']}
Gender: {$the_gender}
Insurance_id: {$act_row['ins_value']}
Facility_contact: {$act_row['facility_contact']}
Date: {$act_row['date']}
Description: {$act_row['description']}"); $tipstr = addslashes("A Message"); $print .= ""; if($msg_row['recipients'] == null) { $respstring = $resp_name; } else { $responders = explode (" ", trim($msg_row['recipients'])); // space-separated list to array $sep = $respstring = ""; for ($i=0 ;$i< count($responders);$i++) { // build string of responder names if (array_key_exists($responders[$i], $responderlist)) { $respstring .= $sep . "• " . $responderlist[$responders[$i]]; $sep = "
"; } } } $print .= ""; $print .= ""; if ($msg_row['msg_type'] == 1) { $type_flag = "OE"; } elseif ($msg_row['msg_type'] ==2) { $type_flag = "IE"; } elseif ($msg_row['msg_type'] ==3) { $type_flag = "OS"; } elseif ($msg_row['msg_type'] ==4) { $type_flag = "IS"; } else { $type_flag = "?"; } $print .= ""; $print .= ""; if ($links) { $print .= "\n"; } $print .= ""; $caption = ""; // once only $msgtr++; } $print .= "
" . $caption . "
" . $respstring . "" . format_date_2($msg_row['_on']) ."by ".get_owner($msg_row['_by'])."" . $type_flag . "" . shorten($msg_row['message'], 24) . "[view| delete]
\n"; $print .= "

"; return $print; } // end else } // end function show_messages // } { -- dummy function get_un_status_name($id) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}un_status` WHERE `id` = ?"; $result = db_query($query, [$id]); if($result && $result->num_rows > 0) { $row = stripslashes_deep($result->fetch_assoc()); return $row['status_val']; } else { return "unk"; } } function get_un_status_cols($id) { $stat_cols = array(); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}un_status` WHERE `id` = ?"; $result = db_query($query, [$id]); if($result && $result->num_rows > 0) { $row = stripslashes_deep($result->fetch_assoc()); $stat_cols[0] = $row['bg_color']; $stat_cols[1] = $row['text_color']; } else { $stat_cols[0] = "#FFFFFF"; $stat_cols[1] = "#000000"; } return $stat_cols; } function get_fac_status_name($id) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}fac_status` WHERE `id` = ?"; $result = db_query($query, [$id]); if($result && $result->num_rows > 0) { $row = stripslashes_deep($result->fetch_assoc()); return $row['status_val']; } else { return "unk"; } } function get_fac_status_cols($id) { $stat_cols = array(); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}fac_status` WHERE `id` = ?"; $result = db_query($query, [$id]); if($result->num_rows > 0) { $row = stripslashes_deep($result->fetch_assoc()); $stat_cols[0] = $row['bg_color']; $stat_cols[1] = $row['text_color']; } else { $stat_cols[0] = "#FFFFFF"; $stat_cols[1] = "#000000"; } return $stat_cols; } function show_log($theid, $show_cfs=false) { // 11/20/09, 10/20/12, 5/8/14 global $evenodd ; // class names for alternating table row colors require('log_codes.inc.php'); // 9/29/10 $query = " SELECT `{$GLOBALS['mysql_prefix']}log`.`id` AS `log_id`, `{$GLOBALS['mysql_prefix']}log`.`who` AS `who`, `{$GLOBALS['mysql_prefix']}log`.`code` AS `code`, `{$GLOBALS['mysql_prefix']}log`.`when` AS `when`, `{$GLOBALS['mysql_prefix']}log`.`ticket_id` AS `ticket_id`, `{$GLOBALS['mysql_prefix']}log`.`responder_id` AS `responder_id`, `{$GLOBALS['mysql_prefix']}log`.`info` AS `info`, `{$GLOBALS['mysql_prefix']}log`.`from` AS `from`, `t`.`scope` AS `tickname`, `r`.`handle` AS `unitname`, `s`.`status_val` AS `theinfo`, `u`.`user` AS `thename` FROM `{$GLOBALS['mysql_prefix']}log` LEFT JOIN `{$GLOBALS['mysql_prefix']}ticket` t ON (`{$GLOBALS['mysql_prefix']}log`.`ticket_id` = `t`.`id`) LEFT JOIN `{$GLOBALS['mysql_prefix']}responder` r ON (`{$GLOBALS['mysql_prefix']}log`.`responder_id` = `r`.`id`) LEFT JOIN `{$GLOBALS['mysql_prefix']}un_status` s ON (`{$GLOBALS['mysql_prefix']}log`.`code` = `s`.`id`) LEFT JOIN `{$GLOBALS['mysql_prefix']}user` u ON (`{$GLOBALS['mysql_prefix']}log`.`who` = `u`.`id`) WHERE `{$GLOBALS['mysql_prefix']}log`.`ticket_id` = ? ORDER BY `when` ASC"; // 10/2/12 $result = db_query($query, [$theid]); $i = 0; $print = ""; while ($row = stripslashes_deep($result->fetch_assoc())) { $code = $row['code']; if ($i==0) { // 11/20/09 $print .= ""; $cfs_head = ($show_cfs)? "" : "" ; $print .= "" . $cfs_head . ""; } if($code ==3) {$theTitle = $row['info'];} else {$theTitle = $types[$row['code']];} $print .= "" . ""; if ($show_cfs) { $print .= ""; // 2009-11-07 22:37:41 - substr($row['when'], 11, 5) } $print .= ""; if($code == 20) { $print .= ""; } else { $print .= ""; } $print .= ""; $print .= ""; $print .= ""; ""; $i++; } $print .= "
Log: ". shorten($row['tickname'], 32) . "
CFS
CodeUnitStatusWhenByFrom
". shorten($types[$row['code']], 20) . "". shorten($row['tickname'], 16) . "". shorten($row['unitname'], 16) . "". shorten(get_un_status_name($row['info']), 16) . " ". format_date_2(strtotime($row['when'])) . "". $row['thename'] . "". $row['from'] . "
"; return $print; } // end function get_log () // } -- dummy function show_unit_log ($theid, $show_cfs=false) { // 9/10/13 global $evenodd ; // class names for alternating table row colors require('./incs/log_codes.inc.php'); $query = " SELECT *, `when` AS `when`, `l`.`id` AS `log_id`, `t`.`scope` AS `tickname`, `r`.`handle` AS `unitname`, `l`.`info` AS `comment`, `s`.`status_val` AS `theinfo`, `u`.`user` AS `thename` FROM `{$GLOBALS['mysql_prefix']}log` l LEFT JOIN `{$GLOBALS['mysql_prefix']}ticket` t ON (l.ticket_id = t.id) LEFT JOIN `{$GLOBALS['mysql_prefix']}responder` r ON (l.responder_id = r.id) LEFT JOIN `{$GLOBALS['mysql_prefix']}un_status` s ON (l.info = s.id) LEFT JOIN `{$GLOBALS['mysql_prefix']}user` u ON (l.who = u.id) WHERE `l`.`responder_id` = ? ORDER BY `when` DESC LIMIT 100"; // 10/2/12 $result = db_query($query, [$theid]); $i = 0; $print = ""; while ($row = stripslashes_deep($result->fetch_assoc())) { if ($i==0) { // 11/20/09 $print .= ""; $cfs_head = ($show_cfs)? "" : "" ; $print .= "" . $cfs_head . ""; } $print .= "" . // 11/20/09 ""; // if ($show_cfs) { $print .= ""; // 2009-11-07 22:37:41 - substr($row['when'], 11, 5) } $theComment = (!is_numeric($row['comment'])) ? $row['comment'] : ""; $print .= "". "". "". "". "". ""; $i++; } $print .= "
Log: ". shorten($row['tickname'], 32) . "
CFS
CodeUnitStatusCommentWhenBy
". shorten($types[$row['code']], 20) . "". shorten($row['tickname'], 16) . "". shorten($row['unitname'], 16) . "". shorten($row['theinfo'], 16) . "". shorten($theComment, 24) . "". format_date_2(strtotime($row['when'])) . "". shorten($row['thename'], 8) . "
"; return $print; } // end function show_unit_log () // } -- dummy function set_ticket_status($status,$id){ /* alter ticket status */ $query = "UPDATE `{$GLOBALS['mysql_prefix']}ticket` SET status= ? WHERE ID= ? LIMIT 1"; $result = db_query($query, [$status, $id]); } function get_allocates($type, $resource) { // 6/10/11 $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}allocates` WHERE `type`= ? AND `resource_id` = ? ORDER BY `group`;"; // 6/10/11 $result = db_query($query, [$type, $resource]); // 4/13/11 $al_groups = array(); if($result->num_rows == 0) { $query2 = "SELECT * FROM `{$GLOBALS['mysql_prefix']}region`;"; // 6/10/11 $result2 = db_query($query2); // 4/13/11 while ($row2 = stripslashes_deep($result->fetch_assoc())) { // 6/10/11 $al_groups[] = $row2['id']; } } else { while ($row = stripslashes_deep($result->fetch_assoc())) { // 6/10/11 $al_groups[] = $row['group']; } } return $al_groups; } function get_allocated_names($type, $resource) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}allocates` WHERE `type`= ? AND `resource_id` = ? ORDER BY `group`;"; $result = db_query($query, [$type, $resource]); $temp_ary = array(); if($result->num_rows != 0) { while($row = stripslashes_deep($result->fetch_assoc())) { $query2 = "SELECT * FROM `{$GLOBALS['mysql_prefix']}region` WHERE `id` = ?"; $result2 = db_query($query2, [$row['group']]); $row2 = stripslashes_deep($result2->fetch_assoc()); $temp_ary[] = $row2['group_name']; } $theReturn = "Allocated to regions " . implode(", ", $temp_ary); } else { $theReturn = ""; } return $theReturn; } function get_tickets_allocated($group) { // 6/10/11 $x=0; $cwi = get_variable('closed_interval'); // closed window interval in hours $time_back = mysql_format_date(time() - (intval(get_variable('delta_mins'))*60) - ($cwi*3600)); $params = [$GLOBALS['STATUS_OPEN'], $GLOBALS['STATUS_SCHEDULED'], $GLOBALS['STATUS_CLOSED'], $time_back]; $where = "WHERE `{$GLOBALS['mysql_prefix']}allocates`.`type`= 1 AND (`{$GLOBALS['mysql_prefix']}ticket`.`status`= ? OR (`{$GLOBALS['mysql_prefix']}ticket`.`status`= ? AND `{$GLOBALS['mysql_prefix']}ticket`.`booked_date` <= (NOW() + INTERVAL 2 DAY)) OR (`{$GLOBALS['mysql_prefix']}ticket`.`status`= ? AND `{$GLOBALS['mysql_prefix']}ticket`.`problemend` >= ?)) AND ("; $grp_placeholders = []; foreach($group as $grp) { $grp_placeholders[] = "`{$GLOBALS['mysql_prefix']}allocates`.`group` = ?"; $params[] = $grp; } $where .= implode(" OR ", $grp_placeholders) . ")"; $query = "SELECT *,`{$GLOBALS['mysql_prefix']}ticket`.`id` AS `tick_id` FROM `{$GLOBALS['mysql_prefix']}ticket` LEFT JOIN `{$GLOBALS['mysql_prefix']}allocates` ON `{$GLOBALS['mysql_prefix']}ticket`.id=`{$GLOBALS['mysql_prefix']}allocates`.`resource_id` LEFT JOIN `{$GLOBALS['mysql_prefix']}region` ON `{$GLOBALS['mysql_prefix']}allocates`.group=`{$GLOBALS['mysql_prefix']}region`.`id` $where GROUP BY tick_id ORDER BY `{$GLOBALS['mysql_prefix']}allocates`.`group`;"; // 6/10/11 $result = db_query($query, $params); // 4/13/11 $tickets = array(); while ($row = stripslashes_deep($result->fetch_assoc())) { // 6/10/11 $tickets[] = $row['tick_id']; } return $tickets; } function get_all_group_butts($curr_grps) { // 6/10/11 $query1 = "SELECT * FROM `{$GLOBALS['mysql_prefix']}region` ORDER BY `id` ASC"; // 6/10/11 $result1 = db_query($query1); $al_buttons=""; return $al_buttons; } function get_all_group_butts_chkd($curr_grps) { // 6/10/11 $query1 = "SELECT * FROM `{$GLOBALS['mysql_prefix']}region` ORDER BY `id` ASC"; // 6/10/11 $result1 = db_query($query1); $al_buttons=""; return $al_buttons; } function get_sub_group_butts($user_id, $resource, $resource_id) { // 6/10/11 $al_groups = array(); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}allocates` WHERE `type`= ? AND `resource_id` = ?;"; // 6/10/11 $result = db_query($query, [$resource, $resource_id]); while ($row = stripslashes_deep($result->fetch_assoc())) { $al_groups[] = $row['group']; } $query2 = "SELECT * FROM `{$GLOBALS['mysql_prefix']}allocates` WHERE `type`= 4 AND `resource_id` = ?;"; // 6/10/11 $result2 = db_query($query2, [$user_id]); $al_buttons=""; return $al_buttons; } function get_sub_group_butts_readonly($user_id, $resource, $resource_id) { // 6/10/11 $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}allocates` WHERE `type`= ? AND `resource_id` = ?;"; // 6/10/11 $result = db_query($query, [$resource, $resource_id]); while ($row = stripslashes_deep($result->fetch_assoc())) { $al_groups[] = $row['group']; } $query2 = "SELECT * FROM `{$GLOBALS['mysql_prefix']}allocates` WHERE `type`= 4 AND `resource_id` = ?;"; // 6/10/11 $result2 = db_query($query2, [$user_id]); $al_buttons=""; return $al_buttons; } function get_user_group_butts($user_id) { // 6/10/11 $query2 = "SELECT * FROM `{$GLOBALS['mysql_prefix']}allocates` WHERE `type`= 4 AND `resource_id` = ?"; // 6/10/11 $result2 = db_query($query2, [$user_id]); $al_buttons=""; return $al_buttons; } function get_user_group_butts_readonly($user_id) { // 6/10/11 $query2 = "SELECT * FROM `{$GLOBALS['mysql_prefix']}allocates` WHERE `type`= 4 AND `resource_id` = ?"; // 6/10/11 $result2 = db_query($query2, [$user_id]); $al_buttons=""; return $al_buttons; } function get_user_group_butts_no_regions($user_id) { // 6/10/11 $al_buttons=""; return $al_buttons; } function get_groupname($groupid) { // 6/10/11 $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}region` WHERE `id`= ?"; // 6/10/11 $result = db_query($query, [$groupid]); if($result->num_rows > 0) { while ($row = stripslashes_deep($result->fetch_assoc())) { $groupname = $row['group_name']; } } else { $groupname = "N/A"; } return $groupname; } function get_num_groups() { // 6/10/11 $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}region`"; // 6/10/11 $result = db_query($query); $num_rows = $result->num_rows; if($num_rows >= 2) { return true; } else { return false; } } function get_first_group($resource, $resource_id) { // 6/10/11 $query = "SELECT `{$GLOBALS['mysql_prefix']}allocates`.`group`, `{$GLOBALS['mysql_prefix']}allocates`.`type`, `{$GLOBALS['mysql_prefix']}region`.`group_name` FROM `{$GLOBALS['mysql_prefix']}allocates` LEFT JOIN `{$GLOBALS['mysql_prefix']}region` ON `{$GLOBALS['mysql_prefix']}allocates`.`group`=`{$GLOBALS['mysql_prefix']}region`.`id` WHERE `type`= ? AND `resource_id` = ? ORDER BY `type` LIMIT 1"; // 4/12/11 $result = db_query($query, [$resource, $resource_id]); while ($row = stripslashes_deep($result->fetch_assoc())) { $group = $row['group_name']; } return $group; } function get_regions_inuse($user) { // 6/10/11 if($user = 9999) { $where = ""; $params = []; } else { $where = "WHERE `type` = 4 AND `resource_id` = ?"; $params = [$user]; } $group = array(); $query = "SELECT DISTINCT `{$GLOBALS['mysql_prefix']}allocates`.`group`, `{$GLOBALS['mysql_prefix']}region`.`group_name` FROM `{$GLOBALS['mysql_prefix']}allocates` LEFT JOIN `{$GLOBALS['mysql_prefix']}region` ON `{$GLOBALS['mysql_prefix']}allocates`.`group`=`{$GLOBALS['mysql_prefix']}region`.`id` $where ORDER BY `{$GLOBALS['mysql_prefix']}region`.`group_name` ASC"; $result = db_query($query, $params); while ($row = stripslashes_deep($result->fetch_assoc())) { $group[] = $row['group_name']; } return $group; } function get_regions_inuse_numbers($user) { // 6/10/11 if($user == 9999) { $where = ""; $params = []; } else { $where = "WHERE `type` = 4 AND `resource_id` = ?"; $params = [$user]; } $group = array(); $query = "SELECT DISTINCT `{$GLOBALS['mysql_prefix']}allocates`.`group`, `{$GLOBALS['mysql_prefix']}region`.`group_name` FROM `{$GLOBALS['mysql_prefix']}allocates` LEFT JOIN `{$GLOBALS['mysql_prefix']}region` ON `{$GLOBALS['mysql_prefix']}allocates`.`group`=`{$GLOBALS['mysql_prefix']}region`.`id` $where ORDER BY `{$GLOBALS['mysql_prefix']}region`.`group_name` ASC"; $result = db_query($query, $params); while ($row = stripslashes_deep($result->fetch_assoc())) { $group[] = $row['group']; } return $group; } function test_allocates($resource, $al_group, $type) { // 6/10/11 $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}allocates` WHERE `resource_id` = ? AND `group` = ? AND `type` = ?"; $result = db_query($query, [$resource, $al_group, $type]); $found = $result->num_rows; if($found == 0) { return true; } else { return false; } } /** * Format a Unix timestamp according to the system's configured date format. * * Uses the 'date_format' setting from the database, or UK format (j/n/y H:i) * when locale is set to 1. Returns "TBD" for invalid or empty dates. * * @param string $date Unix timestamp as a string (10 digits). * @return string Formatted date string, or "TBD" if the date is invalid. * @since v3.0 */ function format_date($date){ if (good_date($date)) { if (get_variable('locale')==1) { return date("j/n/y H:i",$date); // 08/27/10 - Revised to show UK format for locale = 1 } else { return date(get_variable("date_format"),$date); //return date(get_variable("date_format"),strtotime($date)); } } else {return "TBD";} } // end function format date($date) function good_date($date) { // return (is_string ($date) && ((strlen($date)==10))); } // return (substr(inval, 5, 2) . substr(inval, 10, 6)); function format_sb_date($date){ /* format sidebar date Oct-30 07:46 */ if (is_string ($date) && strlen($date)==10) { return date("M-d H:i",$date);} //return date(get_variable("date_format"),strtotime($date)); else {return "TBD";} } // end function format_sb_date($date) /* 3/27/2013 function new_format_sb_date($date){ if (is_string ($date) && strlen($date)==19) {return (substr(inval, 5, 2) . substr(inval, 10, 6));} else {return "TBD";} } // end new_format_sb_date(); */ function new_format_sb_date($date){ // 1/19/2013 if (is_string ($date) && strlen($date)==19) {return substr($date, 8, 8);} /* 2013-01-19 21:18:19 */ else {return "TBD";} } // end new_format_sb_date(); function good_date_time($date) { // 2/15/09 return (is_string ($date) && (strlen($date)==19) && (!($date=="0000-00-00 00:00:00"))); } /** * Format a MySQL datetime string according to the configured date/time format. * * Delegates to format_date_2() for the actual formatting. * * @param string $date A MySQL-format datetime string (e.g., "2024-01-15 08:30:00"). * @return string The formatted date/time string. * @since v3.0 */ function format_date_time($date){ return format_date_2 ($date); } // end function format_date_time() /** * Convert a numeric status code to its display text. * * @param int $status Status code (1=Closed, 2=Open, 3=Scheduled). * @return string Human-readable status label, or "Status error" for unknown codes. * @since v3.0 */ function get_status($status){ switch($status) { case 1: return 'Closed'; break; case 2: return 'Open'; break; case 3: return 'Scheduled'; break; default: return 'Status error'; } } /** * Look up a user's login name by their numeric ID. * * Queries the user table and returns the 'user' field. Returns "unk?" if * the ID is not found, or "unk" on query failure. * * @param int $id User ID to look up. * @return string Username string, or "unk?"/"unk" if not found. * @since v3.0 */ function get_owner($id){ $query = "SELECT user FROM `{$GLOBALS['mysql_prefix']}user` WHERE `id`= ? LIMIT 1"; $result = db_query($query, [$id]); if($result) { $row = stripslashes_deep($result->fetch_assoc()); return ($result->num_rows==0 )? "unk?" : $row['user']; } else { return "unk"; } } function get_user_facility($id){ /* get owner facility from id */ $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}user` WHERE `id`= ? LIMIT 1"; $result = db_query($query, [$id]); $row = stripslashes_deep($result->fetch_assoc()); return ($result->num_rows==0 )? 0 : intval($row['facility_id']); } function get_reader($id){ /* Add in for Messaging 10/23/12 */ $query = "SELECT user FROM `{$GLOBALS['mysql_prefix']}user` WHERE `id`= ? LIMIT 1"; $result = db_query($query, [$id]); $row = stripslashes_deep($result->fetch_assoc()); return ($result->num_rows==0 )? "None" : $row['user']; } /** * Convert a numeric severity code to its display text. * * Uses global severity constants and the captions table for localized * labels (Normal, Medium, High). Returns "Severity error" for unknown codes. * * @param int $severity Severity code matching SEVERITY_NORMAL/MEDIUM/HIGH globals. * @return string Human-readable severity label. * @since v3.0 */ function get_severity($severity){ switch($severity) { case $GLOBALS['SEVERITY_NORMAL']: return get_text("Normal"); break; case $GLOBALS['SEVERITY_MEDIUM']: return get_text("Medium"); break; case $GLOBALS['SEVERITY_HIGH']: return get_text("High"); break; default: return "Severity error"; break; } } function get_severity_field($severity){ /* return severity string from value */ switch($severity) { case $GLOBALS['SEVERITY_NORMAL']: return get_text("Normal"); break; case $GLOBALS['SEVERITY_MEDIUM']: return get_text("Medium"); break; case $GLOBALS['SEVERITY_HIGH']: return get_text("High"); break; default: return "Severity error"; break; } } function get_responder($id){ /* return responder-type string from value */ $query = "SELECT `name` FROM `{$GLOBALS['mysql_prefix']}responder` WHERE id= ? LIMIT 1"; $result = db_query($query, [$id]); $row = stripslashes_deep($result->fetch_assoc()); return $row['name']; } function get_member($id){ /* return responder-type string from value */ $query = "SELECT `field1`, `field2`, `field4` FROM `{$GLOBALS['mysql_prefix']}member` WHERE `id` = ? LIMIT 1"; $result = db_query($query, [$id]); $row = stripslashes_deep($result->fetch_assoc()); return $row['field2'] . " " . $row['field1'] . " " . $row['field4']; } function strip_html($html_string) { /* strip HTML tags/special characters and fix custom ones to prevent bad HTML, CrossSiteScripting etc */ $html_string =strip_tags(htmlspecialchars($html_string)); //strip all "real" html and convert special characters first if (!get_variable('allow_custom_tags')){ //$html_string = str_replace('\[|\]', '', $html_string); //$html_string = str_replace('[b]', '', $html_string); //$html_string = str_replace('[/b]', '', $html_string); //$html_string = str_replace('[i]', '', $html_string); //$html_string = str_replace('[/i]', '', $html_string); return $html_string; } $html_string = str_replace('[b]', '', $html_string); //fix bolds $html_string = str_replace('[/b]', '', $html_string); $html_string = str_replace('[i]', '',$html_string); //fix italics $html_string = str_replace('[/i]', '', $html_string); return $html_string; } $variables = array(); /** * Retrieve a configuration value from the database settings table. * * Lazy-loads all settings into a static cache on the first call to avoid * repeated database queries. Subsequent calls read from the cache. * * @param string $which Setting name to look up (e.g. 'locale', 'date_format'). * @return string|false The setting value, or FALSE if the setting does not exist. * @since v3.0 */ function get_variable($which){ global $variables; if (empty($variables)) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}settings`"; $result = db_query($query); while ($row = stripslashes_deep($result->fetch_assoc())){ $name = $row['name']; $value=$row['value'] ; $variables[$name] = $value; } } return (array_key_exists($which, $variables))? $variables[$which] : false ; // return $variables[$which]; } /** * Get the current tile mode: 'online', 'proxy', or 'offline'. * Falls back to reading legacy 'local_maps' setting for pre-upgrade installs. */ function get_tile_mode() { $mode = get_variable('tile_mode'); if ($mode !== false && in_array($mode, array('online', 'proxy', 'offline'))) { return $mode; } // Fallback for installs that haven't upgraded yet $local = get_variable('local_maps'); return ($local == '1') ? 'offline' : 'online'; } /** * Get the Leaflet tile URL template based on the current tile mode. */ function get_tile_url() { $mode = get_tile_mode(); switch ($mode) { case 'proxy': return './tile_proxy.php?z={z}&x={x}&y={y}'; case 'offline': return './_osm/tiles/{z}/{x}/{y}.png'; case 'online': default: $url = get_variable('tile_server_url'); if ($url === false || trim($url) === '') { $url = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'; } return $url; } } /** * Get the User-Agent string for outbound tile requests. * Format: TicketsCAD/v3.43.0 */ function get_tile_user_agent() { // 3/14/26 - Include tile mode so proxy vs bulk-download have different identifiers. // This prevents bulk downloaders from getting the proxy user-agent banned. $mode = get_tile_mode(); $mode_tag = ($mode === 'proxy') ? 'proxy' : 'bulk'; if (isset($GLOBALS['tickets_current_version'])) { return 'TicketsCAD/' . $GLOBALS['tickets_current_version'] . ' (' . $mode_tag . ')'; } // Fallback if versions.inc.php hasn't been loaded $ver_file = __DIR__ . '/versions.inc.php'; if (is_readable($ver_file)) { require_once($ver_file); if (isset($GLOBALS['tickets_current_version'])) { return 'TicketsCAD/' . $GLOBALS['tickets_current_version'] . ' (' . $mode_tag . ')'; } } return 'TicketsCAD/unknown (' . $mode_tag . ')'; } $msg_variables = array(); function get_msg_variable($which){ /* get variable from db msg_settings table, returns FALSE if absent */ global $msg_variables; if (empty($msg_variables)) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}msg_settings`"; $result = db_query($query); while ($row = stripslashes_deep($result->fetch_assoc())){ $ms_name = $row['name']; $ms_value=$row['value'] ; $msg_variables[$ms_name] = $ms_value; } } return (array_key_exists($which, $msg_variables))? $msg_variables[$which] : false ; } $mdb_variables = array(); function get_mdb_variable($which){ /* get variable from db msg_settings table, returns FALSE if absent */ global $mdb_variables; if (empty($mdb_variables)) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}mdb_settings`"; $result = db_query($query); if(!$result) {return false;} while ($row = stripslashes_deep($result->fetch_assoc())){ $mdb_name = $row['name']; $mdb_value=$row['value'] ; $mdb_variables[$mdb_name] = $mdb_value; } } return (array_key_exists($which, $mdb_variables))? $mdb_variables[$which] : false ; } $css = array(); // 3/15/11 function get_css($element, $day_night){ /* get hex color string from db css colors table, returns FALSE if absent 3/15/11 */ global $css; if($day_night=="Day") { if (empty($css)) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}css_day`"; $result = db_query($query); while ($row = stripslashes_deep($result->fetch_assoc())){ $name = $row['name']; $value=$row['value'] ; $css[$name] = $value; } } } if($day_night=="Night") { if (empty($css)) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}css_night`"; $result = db_query($query); while ($row = stripslashes_deep($result->fetch_assoc())){ $name = $row['name']; $value=$row['value'] ; $css[$name] = $value; } } } return (array_key_exists($element, $css))? "#" . $css[$element] : false ; } /* raise an error event function do_error($err_function,$err,$custom_err='',$file='',$line=''){ print "An error occured in function '$err_function': '$err'
"; if ($file OR $line) print "Error occured in '$file' at line '$line'
"; if ($custom_err != '') print "Additional info: '$custom_err'
"; print '
Check your MySQL connection and if the problem persist, contact the author.
'; die('Execution stopped.
'); } */ /** * Report a fatal application error, log it, and terminate execution. * * Logs the error to the system log table (once per session to avoid flooding), * writes to the PHP error log, displays an HTML error message, and calls die(). * * @param string $err_function The name of the function where the error occurred. * @param string $err The error message or description. * @param string $custom_err Optional additional error information. Default ''. * @param string $file Optional source file where the error occurred. Default ''. * @param string $line Optional line number where the error occurred. Default ''. * @return void This function terminates execution via die(). * @since v3.0 */ function do_error($err_function, $err, $custom_err='', $file='', $line=''){ /* report an error event - revised 5/11/2013 */ @session_start(); // $log_message = substr ( "application error: {[$file]@[$line] [$err_function]", 0, 2048) ; if (!(array_key_exists ( $log_message, $_SESSION ))) { // limit to once per session $_SESSION[$log_message] = true; do_log($GLOBALS['LOG_ERROR'], 0, 0, $log_message); // visible in reports station log @error_log ($log_message); // to server log } print "An error occured in function '$err_function': '$err'
"; if ($file OR $line) print "Error occured in '$file' at line '$line'
"; if ($custom_err != '') print "Additional info: '$custom_err'
"; print '
Check your MySQL connection and if the problem persist, contact the author.
'; die('Execution stopped.
'); } function add_header($ticket_id, $no_edit = false, $show_ed_button = false) { // 11/27/09, 3/30/10, 8/27/10 $win_height = get_variable('map_height') + 240; $win_width = get_variable('map_width') + 80; print "This Call: "; print "" . get_text("Popup") . ""; // 7/3/10 if (can_edit()){ if($show_ed_button) { print "" . get_text("Edit") . ""; } if (!is_closed($ticket_id)) { print "+ " . get_text("Action") . ""; print "+ " . get_text("Patient") . ""; } print "" . get_text("Notify") . ""; } print "" . get_text("Print") . ""; if (!is_guest()) { // 2/1/10 print "" . get_text("E-mail") . ""; // 2/1/10 print "" . get_text("Contact Units") . ""; print "+ " . get_text("Note") . ""; // 10/8/08 if ((!(is_closed($ticket_id))) && (!is_unit())) { // 7/27/10 print "" . get_text("Close inc") . " "; // 8/20/09 } if (!is_unit()) { // 7/27/10 print "" . get_text("Dispatch") . ""; // 3/30/10 } } print ""; } // function add_header() function is_closed($id){/* is ticket closed? */ return check_for_rows("SELECT id,status FROM `{$GLOBALS['mysql_prefix']}ticket` WHERE id= ? AND status= ?", [$id, $GLOBALS['STATUS_CLOSED']]); } /** * Check if the current user has super-administrator privileges. * * @return bool TRUE if the session user's level equals LEVEL_SUPER. * @since v3.0 */ function is_super(){ return ((array_key_exists('level', $_SESSION)) && ($_SESSION['level'] == $GLOBALS['LEVEL_SUPER'])); // 5/11/10, 4/29/14 } /** * Check if the current user has administrator or super-admin privileges. * * Returns TRUE for both LEVEL_ADMINISTRATOR and LEVEL_SUPER users, * granting access to configuration and management features. * * @return bool TRUE if the session user is admin or super. * @since v3.0 */ function is_administrator(){ return ((array_key_exists('level', $_SESSION)) && (($_SESSION['level'] == $GLOBALS['LEVEL_ADMINISTRATOR']) || ($_SESSION['level'] == $GLOBALS['LEVEL_SUPER']))); // 5/11/10, 4/29/14 } /** * Check if the current user is an admin (but not super-admin). * * @return bool TRUE if session level equals LEVEL_ADMINISTRATOR only. * @since v3.0 */ function is_admin(){ /* is user admin but not super? */ return ((array_key_exists('level', $_SESSION)) && ($_SESSION['level'] == $GLOBALS['LEVEL_ADMINISTRATOR'])); // 10/26/11, 4/29/14 } /** * Check if the current user is a guest or member (lowest access levels). * * @return bool TRUE if session level is LEVEL_GUEST or LEVEL_MEMBER. * @since v3.0 */ function is_guest(){ /* is user guest? */ return ((array_key_exists('level', $_SESSION)) && (($_SESSION['level'] == $GLOBALS['LEVEL_GUEST']) || ($_SESSION['level'] == $GLOBALS['LEVEL_MEMBER']))); // 6/25/10, 4/29/14 } /** * Check if the current user is a member. * * @return bool TRUE if session level equals LEVEL_MEMBER. * @since v3.0 */ function is_member(){ /* is user member? */ return ((array_key_exists('level', $_SESSION)) && ($_SESSION['level'] == $GLOBALS['LEVEL_MEMBER'])); // 7/2/10, 4/29/14 } /** * Check if the current user is an operator/dispatcher. * * @return bool TRUE if session level equals LEVEL_USER. * @since v3.0 */ function is_user(){ /* is user operator/dispatcher? */ return ((array_key_exists('level', $_SESSION)) && ($_SESSION['level'] == $GLOBALS['LEVEL_USER'])); // 5/11/10, 4/29/14 } /** * Check if the current user is a unit (responder). * * @return bool TRUE if session level equals LEVEL_UNIT. * @since v3.0 */ function is_unit(){ /* is user unit? */ return ((array_key_exists('level', $_SESSION)) && ($_SESSION['level'] == $GLOBALS['LEVEL_UNIT'])); // 7/12/10, 4/29/14 } /** * Check if the current user is a facility. * * @return bool TRUE if session level equals LEVEL_FACILITY. * @since v3.0 */ function is_facility(){ /* is user facility? */ return ((array_key_exists('level', $_SESSION)) && ($_SESSION['level'] == $GLOBALS['LEVEL_FACILITY'])); // 5/26/16 } function is_statistics(){ /* is user statistics? */ return ((array_key_exists('level', $_SESSION)) && ($_SESSION['level'] == $GLOBALS['LEVEL_STATISTICS'])); // 10/23/12, 4/29/14 } function is_service_user(){ /* is user service user? */ return ((array_key_exists('level', $_SESSION)) && ($_SESSION['level'] == $GLOBALS['LEVEL_SERVICE_USER'])); // 10/23/12, 4/29/14 } function is_manager(){ /* is user service user? */ return ((array_key_exists('level', $_SESSION)) && ($_SESSION['level'] == $GLOBALS['LEVEL_MANAGER'])); // 10/23/12, 4/29/14 } function see_buttons() { return ((array_key_exists('level', $_SESSION)) && (($_SESSION['level'] == $GLOBALS['LEVEL_ADMINISTRATOR']) || ($_SESSION['level'] == $GLOBALS['LEVEL_SUPER']) || ($_SESSION['level'] == $GLOBALS['LEVEL_UNIT']) || ($_SESSION['level'] == $GLOBALS['LEVEL_USER']) || ($_SESSION['level'] == $GLOBALS['LEVEL_MEMBER']))); // 10/11/12, 4/29/14 } function may_email() { return (!(is_guest()) || (is_member() || is_unit())) ; // members, units allowed } /* print date and time in dropdown menus */ function has_admin() { return ((is_super()) || (is_administrator())) ; // 9/22/10 } function generate_date_dropdown($date_suffix,$default_date=0, $disabled=false) { // 'extra allows 'disabled' $dis_str = ($disabled)? " disabled" : "" ; $td = array ("E" => "5", "C" => "6", "M" => "7", "W" => "8"); // hours west of GMT $deltam = intval(get_variable('delta_mins')); // align server clock minutes $local = (time() - (intval(get_variable('delta_mins'))*60)); $default_date = ($default_date == 0) ? $local : $default_date; if ($default_date) { //default to current date/time if no values are given $year = date('Y',$default_date); $month = date('m',$default_date); $day = date('d',$default_date); $minute = date('i',$default_date); $meridiem = date('a',$default_date); if (get_variable('military_time')==1) $hour = date('H',$default_date); else $hour = date('h',$default_date);; } else { $year = date('Y', $local); $month = date('m', $local); $day = date('d', $local); $minute = date('i', $local); $meridiem = date('a', $local); if (get_variable('military_time')==1) $hour = date('H', $local); else $hour = date('h', $local); } $locale = get_variable('locale'); // Added use of Locale switch for Date entry pulldown to change display for locale 08/07/09 switch($locale) { case "0": print ""; print " \n \n  "; print "\n\n"; break; case "1": print ""; print " "; print " \n  "; print "\n\n"; break; case "2": // 11/29/10 print ""; print " "; print " \n  "; print "\n\n"; break; // 8/10/09 default: print "ERROR in " . basename(__FILE__) . " " . __LINE__ . "
"; } print "\n:"; print "\n"; $show_ampm = (!get_variable('military_time')==1); if ($show_ampm){ //put am/pm optionlist if not military time print "\n"; } } // end function generate_date_dropdown( function return_date_dropdown($date_suffix,$default_date=0, $disabled=false) { // 'extra allows 'disabled' $output = ""; $dis_str = ($disabled)? " disabled" : "" ; $td = array ("E" => "5", "C" => "6", "M" => "7", "W" => "8"); // hours west of GMT $deltam = intval(get_variable('delta_mins')); // align server clock minutes $local = (time() - (intval(get_variable('delta_mins'))*60)); $default_date = ($default_date == 0) ? $local : $default_date; if ($default_date) { //default to current date/time if no values are given $year = date('Y',$default_date); $month = date('m',$default_date); $day = date('d',$default_date); $minute = date('i',$default_date); $meridiem = date('a',$default_date); if (get_variable('military_time')==1) $hour = date('H',$default_date); else $hour = date('h',$default_date);; } else { $year = date('Y', $local); $month = date('m', $local); $day = date('d', $local); $minute = date('i', $local); $meridiem = date('a', $local); if (get_variable('military_time')==1) $hour = date('H', $local); else $hour = date('h', $local); } $locale = get_variable('locale'); // Added use of Locale switch for Date entry pulldown to change display for locale 08/07/09 switch($locale) { case "0": $output .= ":"; $output .= "\n"; $show_ampm = (!get_variable('military_time')==1); if ($show_ampm){ //put am/pm optionlist if not military time $output .= "\n"; for($i = date("Y")-70; $i < date("Y")+1; $i++){ print "" : print ">$i"; } print ""; print " \n \n  "; print "\n\n"; break; case "1": print ""; print " "; print " \n  "; print "\n\n"; break; case "2": // 11/29/10 print ""; print " "; print " \n  "; print "\n\n"; break; // 8/10/09 default: print "ERROR in " . basename(__FILE__) . " " . __LINE__ . "
"; } } // end function generate_dateonly_dropdown( function report_action($action_type,$ticket_id,$value1='',$value2=''){/* insert reporting actions */ if (!get_variable('reporting')) return; switch($action_type) { case $GLOBALS[ACTION_OPEN]: $description = "Action Opened"; break; case $GLOBALS[ACTION_CLOSED]: $description = "Action Closed"; break; case $GLOBALS[PATIENT_OPEN]: $description = get_text("Patient") . " Item Opened"; break; case $GLOBALS[PATIENT_CLOSED]: $description = get_text("Patient") . " Item Closed"; break; default: $description = "[unknown report value: $action_type]"; } $now = mysql_format_date(time() - (intval(get_variable('delta_mins'))*60)); $query = "INSERT INTO `{$GLOBALS['mysql_prefix']}action` (date,ticket_id,action_type,description,user) VALUES(?, ?, ?, ?, ?)"; $result = db_query($query, [$now, $ticket_id, $action_type, $description, $_SESSION['user_id']]); } /** * Debug dump a variable with backtrace, wrapped in HTML PRE tags. * * @param mixed $variable The variable to dump. * @return void * @since v3.0 */ function dumpp($variable) { echo "\n
";                // pretty it a bit
    var_dump(debug_backtrace());
    var_dump($variable) ;
    echo "
\n"; } /** * Debug dump a variable using var_dump, wrapped in HTML PRE tags. * * @param mixed $variable The variable to dump. * @return void * @since v3.0 */ function dump($variable) { echo "\n
\n";                // pretty it a bit - 2/23/2013
    var_dump($variable) ;
    echo "
\n"; } /** * Truncate a string to a maximum length, appending ".." if shortened. * * If the input is an array, it is first imploded with comma separators. * Null values are converted to an empty string. * * @param string|array|null $instring The input string (or array) to shorten. * @param int $limit Maximum allowed string length. * @return string The original or truncated string. * @since v3.0 */ function shorten($instring, $limit) { if (is_array($instring)) { $instring = implode(', ', $instring); } // 3/14/26 - handle array values gracefully $instring = (string)($instring ?? ''); return (strlen($instring) > $limit)? substr($instring, 0, $limit-4) . ".." : $instring ; // … } /** * Format a raw phone number string according to the configured locale. * * Locale 0 (US): formats as (xxx) xxx-xxxx. * Locale 1 (UK): formats as xxxxx xxxxxx. * Returns empty string if the input is blank after trimming. * * @param string $instr The raw phone number digits. * @return string The formatted phone number, or empty string if blank. * @since v3.0 */ function format_phone ($instr) { $locale = get_variable('locale'); $instr = (string)$instr; $temp = trim($instr); switch($locale) { case "0": return (!empty($temp))? "(" . substr ($instr, 0,3) . ") " . substr ($instr,3, 3) . "-" . substr ($instr,6, 4): ""; break; case "1": return (!empty($temp))? substr ($instr, 0,5) . " " . substr ($instr,5, 6): ""; break; case "2": // 11/29/10 return (!empty($temp))? substr ($instr, 0,5) . " " . substr ($instr,5, 6): ""; break; default: print "ERROR in " . basename(__FILE__) . " " . __LINE__ . "
"; } // end switch() } /** * Wrap occurrences of a search term with a highlight span. * * Uses case-insensitive replacement when available (str_ireplace), * falling back to case-sensitive str_replace. Matched terms are * wrapped in . * * @param string $term The search term to highlight. * @param string $string The text in which to highlight the term. * @return string The string with matching terms wrapped in highlight markup. * @since v3.0 */ function highlight($term, $string) { $replace = "" .$term . ""; if (function_exists('str_ireplace')) { return str_ireplace ((string)$term, $replace, (string)$string); } else { return str_replace ((string)$term, $replace, (string)$string); } } function replace_quotes($instring) { // 3/15/11 $search = array(chr(34)); $value = str_replace($search, " ", $instring); return $value; } /** * Recursively strip backslash escaping from a value or array of values. * * Handles nested arrays by recursively applying stripslashes to all * string elements. Non-string values are returned unchanged. * * @param string|array $value Value or array of values to un-escape. * @return string|array The un-escaped value(s). * @since v3.0 */ function stripslashes_deep($value) { if (is_array($value)) { return array_map('stripslashes_deep', $value); } else { return is_string($value) ? stripslashes($value) : $value; } } /** * Null-safe wrappers for PHP 8.2+ compatibility. * Prevent deprecation warnings when DB columns return null. * Compatible with PHP 7.2+. */ /** @return string */ function safe_addslashes($str) { return addslashes($str ?? ''); } /** @return string */ function safe_htmlentities($str, $flags = ENT_QUOTES, $encoding = 'UTF-8') { return htmlentities($str ?? '', $flags, $encoding); } /** @return int */ function safe_strlen($str) { return strlen($str ?? ''); } /** * @return int|false */ function safe_strtotime($datetime) { if ($datetime === null || $datetime === '') { return false; } return strtotime($datetime); } /** * Server-side required field validation. Returns array of errors (empty = valid). * Each error is ['field' => 'frm_name', 'message' => 'Field X is required']. * $rules: associative array of field_name => error_message. * $post_data: typically $_POST. * $select_fields: optional array of field names that are SELECT elements * (validated as value !== '0' and value !== '' instead of just non-empty). * Compatible with PHP 7.2+. 3/16/26 */ function validate_required_fields($rules, $post_data, $select_fields = array()) { $errors = array(); foreach ($rules as $field => $message) { $value = isset($post_data[$field]) ? trim($post_data[$field] ?? '') : ''; if (in_array($field, $select_fields)) { if ($value === '' || $value === '0') { $errors[] = array('field' => $field, 'message' => $message); } } else { if ($value === '') { $errors[] = array('field' => $field, 'message' => $message); } } } return $errors; } function trim_deep($value) { $value = is_array($value) ? array_map('trim_deep', $value) : trim($value ?? ''); return $value; } function mysql_real_escape_string_deep($value) { $value = is_array($value) ? array_map('mysql_real_escape_string_deep', $value) : mysqli_real_escape_string($GLOBALS['db_handle'], $value ?? ''); return $value; } function nl2brr($text) { return preg_replace("/\r\n|\n|\r/", "
", $text); } function get_level_text ($level) { switch ($level) { case $GLOBALS['LEVEL_SUPER'] : return "Super"; break; case $GLOBALS['LEVEL_ADMINISTRATOR'] : return "Admin"; break; case $GLOBALS['LEVEL_USER'] : return "Operator"; break; case $GLOBALS['LEVEL_GUEST'] : return "Guest"; break; case $GLOBALS['LEVEL_MEMBER'] : return "Member"; break; // 3/3/09 case $GLOBALS['LEVEL_UNIT'] : return "Unit"; break; // 7/12/10 case $GLOBALS['LEVEL_FACILITY'] : return "Facility"; break; // 4/8/16 case $GLOBALS['LEVEL_STATS'] : return "Statistics"; break; // 6/10/11 case $GLOBALS['LEVEL_SERVICE_USER'] : return "Service User"; break; // 10/23/12 case $GLOBALS['LEVEL_MANAGER'] : return "Manager"; break; default : return "level error"; break; } } //end function function got_gmaps() { // valid GMaps API key ? return (strlen(get_variable('gmaps_api_key'))==86); } /** * Convert a Unix timestamp to MySQL datetime format (Y-m-d H:i:s). * * If no timestamp is provided, uses the current time. * * @param int|string $indate Unix timestamp. Defaults to current time if empty. * @return string Date in "Y-m-d H:i:s" format. * @since v3.0 */ function mysql_format_date($indate="") { if (empty($indate)) {$indate = time();} return @date("Y-m-d H:i:s", $indate); } function is_date($DateEntry) { // returns true for valid non-zero date $DateEntry = (string)$DateEntry; $Date_Array = explode('-',$DateEntry); // "2007-00-00 00:00:00" if (count($Date_Array)!=3) return false; if((strlen($Date_Array[0])!=4)|| ($Date_Array[0]=="0000")) return false; else {return true;} } // end function Is_Date() function toUTM($coordsIn, $from = "") { // UTM converter - assume comma separator $temp = explode(",", $coordsIn); $coords = new LatLng(trim($temp[0]), trim($temp[1])); $utm = $coords->toUTMRef(); $temp = $utm->toString(); $temp1 = explode (" ", $temp); // parse by space $temp2 = explode (".", $temp1[1]); // parse by period $temp3 = explode (".", $temp1[2]); return $temp1[0] . " " . $temp2[0] . " " . $temp3[0]; } // end function toUTM () function get_type($id) { // returns incident type given its id if ($id == 0) {return "TBD";} // 1/11/09 $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}in_types` WHERE `id`= ? LIMIT 1"; $result_type = db_query($query, [$id]); $row_type = stripslashes_deep($result_type->fetch_assoc()); // unset ($result_type); return (isset($row_type['type']))? $row_type['type']: "?"; // 8/12/09 } function output_csv($data, $filename = false){ $csv = array(); foreach($data as $row){ $csv[] = implode(', ', $row); } $csv = sprintf('%s', implode("\n", $csv)); if ( !$filename ){ return $csv; } // Dumping output straight out to browser. // header('Content-Type: application/csv'); // header('Content-Disposition: attachment; filename=' . $filename); // echo $csv; // exit; } function mysql2timestamp($m) { // 9/29/10 // return mktime(substr($m,11,2),substr($m,14,2),substr($m,17,2),substr($m,5,2),substr($m,8,2),substr($m,0,4)); return mktime( (int) ltrim(substr((string)$m,11,2), "0"), (int) ltrim(substr((string)$m,14,2), "0"), (int) ltrim(substr((string)$m,17,2), "0"), (int) ltrim(substr((string)$m,5,2), "0"), (int) ltrim(substr((string)$m,8,2), "0"), (int) ltrim(substr((string)$m,0,4), "0") ); } require_once('remotes.inc.php'); // 8/21/10 /** * Write an entry to the system log table. * * Records an event with the current user, remote IP, timestamp (adjusted * by the system's delta_mins offset), and associated ticket/responder/facility info. * The info field is truncated to 2047 characters. * * @param string $code Log event code (e.g. LOG_LOGIN, LOG_INCIDENT_DELETE). * @param int $ticket_id Associated ticket ID, or 0 if not ticket-related. * @param int $responder_id Associated responder/unit ID, or 0. * @param string $info Free-text description of the event. * @param int $facility_id Associated facility ID, or 0. * @param int $rec_facility_id Receiving facility ID, or 0. * @param int $mileage Mileage value, or 0. * @return void * @since v3.0 */ function do_log($code, $ticket_id=0, $responder_id=0, $info="", $facility_id=0, $rec_facility_id=0, $mileage=0) { @session_start(); // 4/4/10 $who = (array_key_exists('user_id', $_SESSION))? $_SESSION['user_id']: 0; // 11/14/10 $info = substr($info, 0, 2047); $from = $_SERVER['REMOTE_ADDR']; $now = mysql_format_date(time() - (intval(get_variable('delta_mins'))*60)); $query = "INSERT INTO `{$GLOBALS['mysql_prefix']}log` (`who`,`from`,`when`,`code`,`ticket_id`,`responder_id`,`info`, `facility`, `rec_facility`, `mileage`) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $result = db_query($query, [trim($who), trim($from), trim($now), trim($code), trim($ticket_id), trim($responder_id), trim($info), trim($facility_id), trim($rec_facility_id), trim($mileage)]); unset($result); // 3/12/09 } /* 9/29 quotes line 355 11/02 corrections to list and show ticket to handle newlines in Description and Comments fields. 11/03 added function do_onload () frame jump prevention 11/06 revised function get_variable to return FALSE if argument is absent 11/9 added map under image 11/30 added function do_log() 12/15 revised log schema for consistency across codes */ // ===================================================================================== /** * Update the session expiry timestamp in the current user's database record. * * Writes the global $expiry timestamp (formatted as a MySQL datetime) * to the user's `expires` column. * * @global int $expiry The Unix timestamp when the session should expire. * @return void * @since v3.0 */ function set_sess_exp() { @session_start(); // 4/4/10 global $expiry; $the_date = mysql_format_date($expiry) ; $query = "UPDATE `{$GLOBALS['mysql_prefix']}user` SET `expires` = ? WHERE `id`= ? LIMIT 1"; // note no 'delta' $result = db_query($query, [$the_date, $_SESSION['user_id']]); } /** * Check whether the current user's session has expired. * * Compares the user's stored expiry timestamp in the database against * the current time (adjusted for the configured delta_mins). * * @return bool TRUE if the session has expired or is invalid, FALSE if still active. * @since v3.0 */ function expired() { if(empty($_SESSION)) {return true;} // $_SESSION = array(); ?? $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}user` WHERE `id` = ? LIMIT 1"; $result = db_query($query, [$_SESSION['user_id']]); if ($result->num_rows==1) { $row = stripslashes_deep($result->fetch_array()); $now = mysql_format_date(time() - (intval(get_variable('delta_mins'))*60)); if ($row['expires'] > $now) { return false; // NOT expired } else { return true; // expired } } // end mysql_affected_rows() ==1 else { dump (__LINE__ . " ?????????"); // ERROR ?????????????? return true; // expired } } // end expired() function get_sess_key($line="") { if(!(isset($_SESSION['id']))) return false; return $_SESSION['id']; } function totime($string){ // given a MySQL-format date/time, returns the unix equivalent return mktime(substr($string, 11 , 2), substr($string, 14 , 2), substr($string, 17 , 2), substr($string, 5 , 2), substr($string, 8 , 2), substr($string, 0 , 4)); } function LessExtension($strName) { $ext = strrchr($strName, '.'); return ($ext)? substr($strName, 0, -strlen($ext)):$strName ; } // end function LessExtension() function xml2php($xml) { $fils = 0; $tab = false; $array = array(); foreach($xml->children() as $key => $value) { $child = xml2php($value); foreach($node->attributes() as $ak=>$av) { // To deal with the attributes $child[$ak] = (string)$av; } if($tab==false && in_array($key,array_keys($array))) { // Let's see if the new child is not in the array $tmp = $array[$key]; // If this element is already in the array $array[$key] = null; // we will create an indexed array $array[$key][] = $tmp; $array[$key][] = $child; $tab = true; } elseif($tab == true) { $array[$key][] = $child; //Add an element in an existing array } else { //Add a simple element $array[$key] = $child; } $fils++; } if($fils==0) { return (string)$xml; } return $array; } function get_stuff($in_file) { // return file contents as string return file_get_contents($in_file);; } // end function get_stuff() function get_ext($filename) { // return extension in lower-case $exts = explode(".", $filename) ; // 8/2/09 return strtolower($exts[count($exts)-1]); } function get_field_index($table, $name) { $table_arr = array(); $i = 0; $safe_table = preg_replace('/[^a-zA-Z0-9_]/', '', $table); $query = "DESCRIBE `{$GLOBALS['mysql_prefix']}{$safe_table}`"; $result = db_query($query); while($row = $result->fetch_array()) { if($row[0] == $name) { return $i; } $i++; } } function get_field_type($table, $field) { $enum = "enum"; $safe_table = preg_replace('/[^a-zA-Z0-9_]/', '', $table); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}{$safe_table}`"; $result = db_query($query); $finfo = mysqli_fetch_field_direct($result, $field); $field_type = $finfo->type; $flags = $finfo->flags; // Convert mysqli type constants to old mysql_field_type strings $type_map = [MYSQLI_TYPE_TINY => 'int', MYSQLI_TYPE_SHORT => 'int', MYSQLI_TYPE_LONG => 'int', MYSQLI_TYPE_INT24 => 'int', MYSQLI_TYPE_FLOAT => 'real', MYSQLI_TYPE_DOUBLE => 'real', MYSQLI_TYPE_DECIMAL => 'real', MYSQLI_TYPE_NEWDECIMAL => 'real', MYSQLI_TYPE_DATETIME => 'datetime', MYSQLI_TYPE_DATE => 'date', MYSQLI_TYPE_BLOB => 'blob', MYSQLI_TYPE_STRING => 'string', MYSQLI_TYPE_VAR_STRING => 'string']; $field_type = isset($type_map[$field_type]) ? $type_map[$field_type] : 'string'; // Check for enum flag $is_enum = ($flags & MYSQLI_ENUM_FLAG) ? true : false; $is_not_null = ($flags & MYSQLI_NOT_NULL_FLAG) ? true : false; if ($is_enum) { $flags = $is_not_null ? "not_null enum" : "enum"; } else { $flags = ""; } if($field_type == "blob") { $field_type = "STRING"; } elseif($field_type == "real") { $field_type = "REAL"; } elseif($field_type == "int") { $field_type = "INT"; } elseif($field_type == "datetime") { $field_type = "DATETIME"; } elseif($field_type == "DATETIME") { $field_type = "DATETIME"; } elseif($field_type == "DATE") { $field_type = "DATE"; } elseif($field_type == "date") { $field_type = "DATE"; } elseif($field_type == "string" || $field_type == "STRING") { if($flags == "not_null enum" || $flags == "enum") { $field_type = "ENUM"; } else { $field_type = "STRING"; } } return $field_type; } function get_field_name($table, $field) { $safe_table = preg_replace('/[^a-zA-Z0-9_]/', '', $table); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}{$safe_table}`"; $result = db_query($query); $finfo = mysqli_fetch_field_direct($result, $field); $field_name = $finfo->name; return $field_name; } function get_field_size($table, $field) { $safe_table = preg_replace('/[^a-zA-Z0-9_]/', '', $table); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}{$safe_table}`"; $result = db_query($query); $finfo = mysqli_fetch_field_direct($result, $field); $field_size = $finfo->length; return $field_size; } function get_display_field_size($table, $field) { $safe_table = preg_replace('/[^a-zA-Z0-9_]/', '', $table); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}{$safe_table}`"; $result = db_query($query); $row = $result->fetch_array(); $field_size = $row['size']; return $field_size; } function wizard_field_exists($field) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}wizard_settings` WHERE `fieldname` = ?"; $result = db_query($query, [$field]); if($result->num_rows > 0) { return true; } else { return false; } } function get_wizard_field_select($current, $id = null) { $query = "DESCRIBE `{$GLOBALS['mysql_prefix']}ticket`"; $result = db_query($query); $row = $result->fetch_array(); if($id) { $output = ""; } else { $options = array(); $output = ""; } else { $output = ""; } } return $output; } function ezDate($d) { $temp = strtotime(str_replace("-","/",$d)); $ts = time() - $temp; if (($ts < 0) || ($ts > 315360000)) {return false;} // sanity check if($ts>31536000) $val = round($ts/31536000,0).' year'; else if($ts>2419200) $val = round($ts/2419200,0).' month'; else if($ts>604800) $val = round($ts/604800,0).' week'; else if($ts>86400) $val = round($ts/86400,0).' day'; else if($ts>3600) $val = round($ts/3600,0).' hour'; else if($ts>60) $val = round($ts/60,0).' minute'; else $val = $ts.' second'; if(!($val==1)) $val .= 's'; $val .= " ago"; return $val; } function isValidURL($url) { return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url); } function do_kml() { // emits JS for kml-type files in noted directory - added 5/23/08, 4/2/14 if(get_variable('kml_files') == "0") { return; } $dir = "./kml_files"; // required as directory if (is_dir($dir)){ $dh = opendir($dir); $temp = explode ("/", $_SERVER['REQUEST_URI']); $temp[count($temp)-1] = substr($dir, 2); // home subdir $server_str = "./kml_files/"; $i=1; while (false !== ($filename = readdir($dh))) { $temp = explode(".", $filename); $thefileName = $temp[0]; switch (get_ext($filename)) { // drop all other types, incl directories case "kml": case "kmz": case "xml": $url = $server_str . $filename; echo "map.attributionControl.setPrefix('');\n"; echo "var xml_" . $i ." = new L.KML('" . $url . "', {async: true});\n"; echo "map.addLayer(xml_" . $i . ");\n"; echo "layercontrol.addOverlay(xml_" . $i . ", '" . $thefileName . "');\n"; $i++; break; case "gpx": $url = $server_str . $filename; echo "map.attributionControl.setPrefix('');\n"; echo "var gpx_" . $i ." = new L.GPX('" . $url . "', {async: true});\n"; echo "map.addLayer(gpx_" . $i . ");\n"; echo "layercontrol.addOverlay(gpx_" . $i . ", '" . $thefileName . "');\n"; $i++; break; // --------------------------------- case "txt": $the_addr = "{$dir}/{$filename}"; $lines = file($the_addr ); foreach ($lines as $line_num => $line) { // Loop through our array. if(isValidURL( trim($line))) { echo "map.attributionControl.setPrefix('');\n"; echo "var xml_" . $i ." = new L.KML('" . $line . "', {async: true});\n"; echo "map.addLayer(xml_" . $i . ");\n"; echo "layercontrol.addOverlay(xml_" . $i . ", '" . $thefileName . "');\n"; } $i++; } break; // -------------------------------- } // end switch () } // end while () } // end is_dir() } // end function do_kml() function lat2dms($inlat) { // 9/9/08 both to degr, min, sec $nors = ($inlat<0.0)? "S.":"N."; $d = floor(abs($inlat)); // degrees $mu = (abs($inlat)-$d)*60; // min's unrounded $m = floor($mu); // min's $su = ($mu - $m)*60; // sec's unrounded $s = (round($su, 1)); // seconds return $d . '° ' . abs($m) . "' " . abs($s) . """ . $nors; } function lng2dms($inlng) { // 9/9/08 both to degr, min, sec $wore = ($inlng<0.0)? "W.":"E."; $d = floor(abs($inlng)); // degrees $mu = (abs($inlng)-$d)*60; // min's unrounded $m = floor($mu); // min's $su = ($mu - $m)*60; // sec's unrounded $s = (round($su, 1)); // seconds return $d . '° ' . abs($m) . "' " . abs($s) . """ . $wore; } function lat2ddm($inlat) { // to degr, dec mins 9/7/08 $nors = ($inlat<0.0)? "S.":"N."; $deg = floor(abs($inlat)); return $deg . '° ' . round(abs($inlat-$deg)*60, 1) . "' " . $nors; } function lng2ddm($inlng) { // to degr, dec mins 9/7/08 $wore = ($inlng<0.0)? "W.":"E."; $deg = floor(abs($inlng)); return $deg . '° ' . round((abs($inlng)-$deg)*60, 1) . "' " . $wore; } function get_lat($in_lat) { // 9/7/08 if (empty($in_lat)) {return"";} // 9/14/08 $format = get_variable('lat_lng'); switch ($format) { case 0: // decimal return $in_lat; break; case 1: // return ll2dms($in_lat); // dms return lat2dms($in_lat); // dms break; case 2: // cg format return lat2ddm($in_lat); break; } } // end function get_lat() function get_lng($in_lng) { // 9/7/08 if (empty($in_lng)) {return"";} // 9/14/08 $format = get_variable('lat_lng'); switch ($format) { case 0: // decimal return $in_lng; break; case 1: // return ll2dms($in_lng); // dms return lng2dms($in_lng); // dms break; case 2: // cg format return lng2ddm($in_lng); break; } } // end function get_lng() /* Subject A Incident B Title* Priority C Priority* Nature D Nature* Written E Written Updated F As of Reporte G By* Phone: H Phone: * Status: I Status:* Address J Location Descrip'n K Description* Dispos'n L Disposition Start/end M Map: " N Map: " * Actions O Patients P Host Q 911 contact R // 6/26/10 Ticket link S // 6/20/12 Facility T // 6/20/12 Handle U // 3/25/13 Scheduled V // 3/25/13 */ /** * Compose and send a notification message for a ticket. * * Builds a message body using a configurable letter-code template string * (msg_text_1/2/3/4 settings) that controls which ticket fields to include. * Either sends the message via do_send() or returns the text if $txt_only is TRUE. * * @param string $to_str Pipe-delimited email/cell/Twitter addresses. * @param string $smsg_to_str Comma-delimited SMS gateway addresses (or NULL/""). * @param string $text Subject text override or empty to use ticket scope. * @param int $ticket_id The ticket ID to build the message from. * @param int $text_sel Message template selector (1-4). Default 1. * @param bool $txt_only If TRUE, return message text instead of sending. Default FALSE. * @return string|void The composed message text when $txt_only is TRUE, otherwise void. * @since v3.0 */ function mail_it ($to_str, $smsg_to_str, $text, $ticket_id, $text_sel=1, $txt_only = false) { global $istest; // if (is_null($text_sel)) {$text_sel = 1;} // switch ($text_sel) { // 7/7/09 case null: // 11/15/2012 case 1: $match_str = strtoupper(get_variable("msg_text_1")); // note case break; case 2: $match_str = strtoupper(get_variable("msg_text_2")); break; case 3: $match_str = strtoupper(get_variable("msg_text_3")); break; case 4: $match_str = strtoupper(get_variable("msg_text_3")) . ",W"; break; } $match_str = preg_replace("/[^a-zA-Z]+/", "", $match_str); // drop ash/trash - 5/31/2013 if (empty($match_str)) {$match_str = " " . implode ("", range("A", "W"));} // empty get all - force non-zero hit $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}ticket` WHERE `id` = ? LIMIT 1"; $t_row = db_fetch_one($query, [intval($ticket_id)], 'i'); if (!$t_row) { return; } $the_scope = strlen(trim($t_row['scope']))>0? trim($t_row['scope']) : "[#{$ticket_id}]" ; // possibly empty $eol = PHP_EOL; $locale = get_variable('locale'); $message=""; $_end = (good_date_time($t_row['problemend']))? " End:" . $t_row['problemend'] : "" ; // for ($i = 0;$i< strlen($match_str); $i++) { if(!($match_str[$i]==" ")) { switch ($match_str[$i]) { case "A": break; case "B": $gt = get_text("Incident"); $message .= "{$gt}: {$the_scope}{$eol}"; break; case "C": $gt = get_text("Priority"); $message .= strtoupper(get_severity_field($t_row['severity'])) . $eol; break; case "D": $gt = get_text("Nature"); $message .= "{$gt}: " . get_type($t_row['in_types_id']) . $eol; break; case "J": $gt = get_text("Addr"); $str = ""; $str .= (empty($t_row['street']))? "" : $t_row['street'] . " " ; $str .= (empty($t_row['city']))? "" : $t_row['city'] . " " ; $str .= (empty($t_row['state']))? "" : $t_row['state']; $message .= empty($str) ? "" : $str . $eol; $gt = get_text("About Address"); $str2 = ""; $str2 .= (empty($t_row['address_about']))? "" : $t_row['address_about'] ; $message .= empty($str2) ? "" : $str2 . $eol; $gt = get_text("To Address"); $str3 = ""; $str3 .= (empty($t_row['to_address']))? "" : $t_row['to_address'] . " " ; $message .= empty($str3) ? "" : " " . $str3 . $eol; if (array_key_exists('lat', $t_row) && array_key_exists('lng', $t_row) && $GLOBALS['NM_LAT_VAL'] != $t_row['lat']) { // 1/4/2014 $message .= "http://maps.google.com/?q=loc:" . $t_row['lat'] . "," . $t_row['lng'] . $eol; } break; case "X": $gt = get_text("Addr"); $str = ""; $str .= (empty($t_row['street']))? "" : $t_row['street'] . " " ; $str .= (empty($t_row['city']))? "" : $t_row['city'] . " " ; $str .= (empty($t_row['state']))? "" : $t_row['state']; $message .= empty($str) ? "" : $str . $eol; $gt = get_text("About Address"); $str2 = ""; $str2 .= (empty($t_row['address_about']))? "" : $t_row['address_about'] ; $message .= empty($str2) ? "" : $str2 . $eol; $gt = get_text("To Address"); $str3 = ""; $str3 .= (empty($t_row['to_address']))? "" : $t_row['to_address'] . " " ; $message .= empty($str3) ? "" : " " . $str3 . $eol; break; case "K": $gt = get_text("Description"); $message .= (empty($t_row['description']))? "": "{$gt}: ". wordwrap($t_row['description']).$eol; break; case "G": $message .= "Call via: " . $t_row['contact'] . $eol; break; case "H": $gt = get_text("Phone"); $message .= (empty($t_row['phone']))? "": "{$gt}: " . format_phone ($t_row['phone']) . $eol; break; case "E": $gt = get_text("Written"); $message .= (empty($t_row['date']))? "": "{$gt}: " . format_date_2($t_row['date']) . $eol; break; case "F": $gt = get_text("Updated"); $message .= "{$gt}: " . format_date_2($t_row['updated']) . $eol; break; case "I": $gt = get_text("Status"); $message .= "{$gt}: ".get_status($t_row['status']).$eol; break; case "L": $gt = get_text("Disposition"); $message .= (empty($t_row['comments']))? "": "{$gt}: ".wordwrap($t_row['comments']).$eol; break; case "M": $gt = get_text("Run Start"); $message .= get_text("{$gt}") . ": " . format_date_2($t_row['problemstart']). $_end .$eol; break; case "N": $gt = get_text("Position"); if($locale == 0) { $usng = LLtoUSNG($t_row['lat'], $t_row['lng']); $message .= "{$gt}: " . $t_row['lat'] . " " . $t_row['lng'] . ", " . $usng . "\n"; } if($locale == 1) { $osgb = LLtoOSGB($t_row['lat'], $t_row['lng']); $message .= "{$gt}: " . $t_row['lat'] . " " . $t_row['lng'] . ", " . $osgb . "\n"; } if($locale == 2) { $utm = LLtoUTM($t_row['lat'], $t_row['lng']); $message .= "{$gt}: " . $t_row['lat'] . " " . $t_row['lng'] . ", " . $utm . "\n"; } break; case "P": $gt = get_text("Patient"); $query_p = "SELECT * FROM `{$GLOBALS['mysql_prefix']}patient` WHERE `ticket_id` = ?"; $pat_rows = db_fetch_all($query_p, [intval($ticket_id)], 'i'); if (count($pat_rows) > 0) { $message .= "\n{$gt}:\n"; foreach ($pat_rows as $pat_row) { $message .= $pat_row['name'] . ", " . $pat_row['updated'] . "- ". wordwrap($pat_row['description'], 70)."\n"; } } break; case "O": $gt = get_text("Actions"); $query_o = "SELECT * FROM `{$GLOBALS['mysql_prefix']}action` WHERE `ticket_id` = ?"; // 10/16/08 $act_rows = db_fetch_all($query_o, [intval($ticket_id)], 'i'); if (count($act_rows) > 0) { $message .= "\n{$gt}:\n"; foreach ($act_rows as $act_row) { $message .= $act_row['updated'] . " - ".wordwrap($act_row['description'], 70)."\n"; } } break; case "Q": $gt = get_text("Tickets host"); $message .= "{$gt}: ".get_variable('host').$eol; break; case "R": // 6/26/10 $gt = get_text("911 Contacted"); $message .= (empty($t_row['nine_one_one']))? "": "{$gt}: " . wordwrap($t_row['nine_one_one']).$eol; // 11/10/11 break; case "S": // 6/20/12 - 12/14/2012 $gt = get_text("Links"); $protocol = explode("/", $_SERVER["SERVER_PROTOCOL"]); $uri = explode("/", $_SERVER["REQUEST_URI"]); unset ($uri[count($uri)-1]); $uri = join("/", $uri); //$message .= "{$gt}: {$temp_arr[0]}://{$_SERVER['HTTP_HOST']}:{$_SERVER['SERVER_PORT']}/main.php?id={$ticket_id}"; $message .= "{$gt}: {$protocol[0]}//{$_SERVER["SERVER_ADDR"]}:{$_SERVER["SERVER_PORT"]}{$uri}?id={$ticket_id}"; break; case "T": // 6/20/12 $gt = get_text("Facility"); if ((intval($t_row['rec_facility'])>0) || (intval($t_row['facility'])>0)) { $the_facility = (intval($t_row['rec_facility'])>0)? intval($t_row['rec_facility']) : intval($t_row['facility']); $query_f = "SELECT * FROM `{$GLOBALS['mysql_prefix']}facilities` WHERE `id` = ? LIMIT 1"; $f_row = db_fetch_one($query_f, [$the_facility], 'i'); if ($f_row) { $message .= "{$gt}: {$f_row['handle']}\n"; $message .= "{$gt}: {$f_row['beds_info']}\n"; } } break; case "U": // 11/13/2012 $query_u = "SELECT `handle` FROM `{$GLOBALS['mysql_prefix']}assigns` `a` LEFT JOIN `{$GLOBALS['mysql_prefix']}responder` `r` ON (`a`.`responder_id` = `r`.`id`) WHERE `a`.`ticket_id` = ? AND (`clear` IS NULL OR DATE_FORMAT(`clear`,'%y') = '00') ORDER BY `handle` ASC"; // 5/25/09, 1/16/08 $u_rows = db_fetch_all($query_u, [intval($ticket_id)], 'i'); if (count($u_rows) > 0) { $gt = get_text("Units"); $units_resp = ""; foreach ($u_rows as $u_row) { if($units_resp != "") $units_resp .= " "; $units_resp .= "[{$u_row['handle']}]"; } $message .= $units_resp . $eol; // 4/1/2013 } break; case "V": if (is_date($t_row['booked_date'])) { $gt = get_text("Scheduled For"); $message .= get_text("{$gt}") . ": " . format_date_2($t_row['booked_date']). $_end .$eol; } break; case "W": $message .= get_disp_closure_summary($ticket_id) .$eol; break; default: // $message = "Match string error:" . $match_str[$i]. " " . $match_str . $eol ; @session_start(); $err_str = "mail error: '{$match_str[$i]}' @ " . __LINE__; // 6/18/12 if (!(array_key_exists ( $err_str, $_SESSION ))) { // limit to once per session do_log($GLOBALS['LOG_ERROR'], 0, 0, $err_str); $_SESSION[$err_str] = true; } } // end switch () } // end if(!($match_...)) } // end for ($i...) $message = str_replace("\n.", "\n..", $message); // see manual re mail win platform peculiarities // $subject = (strpos ($match_str, "A" ))? "": "Incident: {$the_scope}"; // 11/14/2012 - 11/14/2012 - don't duplicate $subject = ($text != "") ? $text : "{$the_scope}"; // 7/3/2013 if ($txt_only) { return $message; // 2/16/09 } else { $smsg_to_str = ($smsg_to_str == null) ? "" : $smsg_to_str; do_send ($to_str, $smsg_to_str, $subject, $message, $ticket_id, 0, null, null); // 10/23/12 } } // end function mail_it () // ________________________________________________________ function smtp ($my_to, $my_subject, $my_message, $my_params, $my_from) { require_once('smtp.inc.php'); // defer load until required - 8/2/10 real_smtp ($my_to, $my_subject, $my_message, $my_params, $my_from); } // end function smtp /** * Send a notification message via email, SMS cell gateways, and/or Twitter. * * Parses the pipe-delimited address string into email, cell-carrier, and * Twitter groups, then sends each via the appropriate transport (SMTP/mail * for email, chunked messages for cell, Twitter direct messages). * * @param string $to_str Pipe-delimited email/cell/Twitter addresses. * @param string|null $smsg_to_str Comma-delimited SMS gateway callsign addresses. * @param string $subject_str Email subject line. * @param string $text_str Message body text. * @param int $ticket_id Associated ticket ID. * @param int|string $responder_ids Pipe-delimited responder IDs, or 0. Default 0. * @param string|null $messageid Optional message ID for SMS gateway. Default NULL. * @param string|null $server Optional server identifier for SMS gateway. Default NULL. * @return string Count of total messages sent (as a string). * @since v3.0 */ function do_send ($to_str, $smsg_to_str, $subject_str, $text_str, $ticket_id, $responder_ids=0, $messageid=null, $server=null) { // print $to_str . "," . $smsg_to_str . "," . $subject_str . "," . $text_str . "," . $ticket_id . "," . $responder_ids . "
"; $the_resp_ids = ""; if($responder_ids != 0) { $the_responder_ids = explode("|", $responder_ids); $the_responders = ""; $sep = ""; $the_resp_ids = implode(",", $the_responder_ids); foreach($the_responder_ids as $val) { if($val == 0) { $the_responders = "Not Set"; } else { $the_responders = get_responder($val) . $sep; $sep = ","; } } $the_responders = substr($the_responders,0,-1); } else { $the_responders = ""; } $count_cells = $count_ll = $count_smsg = $count_tweets = 0;; // counters $theaddresses = ""; global $istest; require_once('smtp.inc.php'); // defer load until required - 8/2/10 require_once("messaging.inc.php"); // defer load until required - 4/24/12 $sleep = 4; // seconds delay between text messages $now = time() - (intval(intval(get_variable('delta_mins')))*60); $my_smtp_ary = explode ("/", trim(get_variable('smtp_acct'))); if ($to_str != "" && (count($my_smtp_ary)>1) && (count($my_smtp_ary)<5)) { // 4/19/11, 10/23/12, 11/2/12 do_log($GLOBALS['LOG_ERROR'], 0, 0, "Invalid smtp account information: " . trim(get_variable('smtp_acct'))); return; } $temp = explode("/", trim(get_variable('email_reply_to'))); if ($to_str != "" && !(is_email(trim($temp[0])))) { // accommodate possible /B do_log($GLOBALS['LOG_ERROR'], 0, 0, "Invalid email reply-to: " . trim(get_variable('email_reply_to'))); return ; } if(!function_exists('stripLabels')) { function stripLabels($sText){ $labels = array("Incident:", "Priority:", "Nature:", "Addr:", "Descr:", "Reported by:", "Phone:", "Written:", "Updated:", "Status:", "Disp:", "Run Start:", "Map:", "Patient:", "Actions:", "Tickets host:"); // 5/9/10 for ($x = 0; $x < count($labels); $x++) { $sText = str_replace($labels[$x] , '', $sText); } return $sText; } } $to_array = array_values(array_unique(explode ("|", ($to_str)))); // input is pipe-delimited string - 10/17/08 $to_smsg_array = ($smsg_to_str != null) ? array_values(array_unique(explode (",", ($smsg_to_str)))) : null; // input is comma string - 4/24/12 require_once("cell_addrs.inc.php"); // 10/22/08 $ary_cell_addrs = $ary_ll_addrs = $ary_twitter_addrs = array(); if($to_str != "") { if(count($to_array) > 0) { for ($i = 0; $i < count($to_array); $i++) { // walk down the input address string/array $isTwitter = (substr($to_array[$i], 0, 1) == "@") ? true : false; $temp = explode ( "@", $to_array[$i]); include('cell_addrs.inc.php'); // 10/22/08 if ($isTwitter) { $screen_name = substr($to_array[$i], 1); array_push ($ary_twitter_addrs, $screen_name); // yes } elseif(in_array(trim(strtolower($temp[1])), $cell_addrs)) { // cell addr? array_push ($ary_cell_addrs, $to_array[$i]); // yes } else { // no, land line addr array_push ($ary_ll_addrs, $to_array[$i]); } } // end for ($i = ...) $caption=""; $my_from_ary = explode("/", trim(get_variable('email_from'))); // note /B option $my_replyto_str = trim(get_variable('email_reply_to')); if (count($ary_ll_addrs)>0) { // got landline addee's? $theaddresses = implode(",", $ary_ll_addrs); if($the_responders == "") { $the_responders = $theaddresses;} // ($my_smtp_ary, $my_to_ary, $my_subject_str, $my_message_str, $my_from_ary, $my_replyto_str) if (count($my_smtp_ary)>1) { $count_ll = do_smtp_mail ($my_smtp_ary, $ary_ll_addrs, $subject_str, $text_str, $my_from_ary, $my_replyto_str ); store_email(1, $the_responders, "email", $subject_str, $text_str, $ticket_id, $the_resp_ids, date("Y/m/d H:i:s", $now), $my_replyto_str, 'Tickets'); // 7/9/12 } else { // ($my_smtp_ary, $my_to_ary, $my_subject_str, $my_message_str, $my_from_ary, $my_replyto_str) $count_ll = do_native_mail ($my_smtp_ary, $ary_ll_addrs, $subject_str, $text_str, $my_from_ary, $my_replyto_str ); store_email(1, $the_responders, "email", $subject_str, $text_str, $ticket_id, $the_resp_ids, date("Y/m/d H:i:s", $now), $my_replyto_str, 'Tickets'); // 7/9/12 } } if (count($ary_cell_addrs)>0) { // got cell addee's? $theaddressess = implode(",", $ary_cell_addrs); if($the_responders == "") { $the_responders = $theaddresses;} $lgth = 140; $ix = 0; $i = 1; $cell_text_str = stripLabels($text_str); // strip labels 5/10/10 while (substr($cell_text_str, $ix , $lgth )) { // chunk to $lgth-length strings $subject_ex = $subject_str . "/part " . $i . "/"; // 10/21/08 // ($my_smtp_ary, $my_to_ary, $my_subject_str, $my_message_str, $my_from_ary, $my_replyto_str) if (count($my_smtp_ary)>1) { $count_cells = do_smtp_mail ($my_smtp_ary, $ary_cell_addrs, $subject_ex, substr ($cell_text_str, $ix , $lgth ), $my_from_ary, $my_replyto_str); store_email(1, $the_responders, "email", $subject_str, $text_str, $ticket_id, $the_resp_ids, date("Y/m/d H:i:s", $now), $my_replyto_str, 'Tickets'); // 7/9/12 } else { // ($my_smtp_ary, $my_to_ary, $my_subject_str, $my_message_str, $my_from_ary, $my_replyto_str) $count_cells = do_native_mail ($my_smtp_ary, $ary_cell_addrs, $subject_ex, substr ($cell_text_str, $ix , $lgth ), $my_from_ary, $my_replyto_str); store_email(1, $the_responders, "email", $subject_str, $text_str, $ticket_id, $the_resp_ids, date("Y/m/d H:i:s", $now), $my_replyto_str, 'Tickets'); // 7/9/12 if($i>1) {sleep ($sleep);} // 10/17/08 } // end if/else (count($my_smtp_ary)>1)) // 12/13/2012 $ix+=$lgth; $i++; } // end while (substr($cell_text_...)) } // end if (count($ary_cell_addrs)>0) if (count($ary_twitter_addrs)>0) { for ($t = 0; $t < count($ary_twitter_addrs); $t++) { $theRet = send_tweet_direct($text_str, null, $ary_twitter_addrs[$t]); if(!is_int($theRet)) { print $theRet . "
"; } else { $count_tweets = $count_tweets + $theRet; } } } } // end if(count($to_array) > 0) } // end if($to_str != "") if($smsg_to_str != "") { if((get_variable('use_messaging') == 2) || (get_variable('use_messaging') == 3)) { if (count($to_smsg_array)>0) { // got sms gateway addresses? $addressess = ""; $cell_text_str = stripLabels($text_str); // strip labels 5/10/10 $count_smsg = do_smsg_send(get_msg_variable('smsg_orgcode'),get_msg_variable('smsg_apipin'),$subject_str,$cell_text_str,"CALLSIGNS",$smsg_to_str,"standard_priority",get_msg_variable('smsg_replyto'),"SENDXML", $ticket_id, $messageid, $server); } // end if (count($to_smsg_array)>0) } // end if((get_variable('use_messaging') == 2) || (get_variable('use_messaging') == 3)) } // end if($smsg_to_str != "") return (string) ($count_ll + $count_cells + $count_smsg + $count_tweets); } // end function do send () function is_email($email){ // validate email, code courtesy of Jerrett Taylor - 10/8/08, 7/2/10 if(!preg_match( "/^" . "[a-zA-Z0-9]+([_\\.-][a-zA-Z0-9]+)*" . //user "@" . "([a-zA-Z0-9]+([\.-][a-zA-Z0-9]+)*)+" . //domain "\\.[a-zA-Z]{2,}" . //sld, tld "$/", $email, $regs)) { return false; } else { return true; } } // end function is_email() function is_twitter($address) { $isTwitter = (substr($address, 0, 1) == "@") ? true : false; return $isTwitter; } function get_scope($id) { $query = "SELECT `scope` FROM `{$GLOBALS['mysql_prefix']}ticket` WHERE `id` = ? LIMIT 1"; $row = db_fetch_one($query, [intval($id)], 'i'); if (!$row) { return ""; } else { return $row['scope']; } } /** * Send notifications to subscribed users, facilities, and assigned units for a ticket event. * * Queries the notify table for matching subscriptions based on ticket ID, * action type, and severity. Also notifies facility contacts and * incident-type contacts based on configuration settings. * * @param int $ticket_id The ticket ID that triggered the notification. * @param int $action_id The notification action type constant. * @return array|false Array of subscriber email addresses, or FALSE if none/disabled. * @since v3.0 */ function notify_user($ticket_id, $action_id) { if (get_variable('allow_notify') != '1') return false; //should we notify? $actionText = ""; $query = "SELECT `scope`, `severity`, `facility`, `rec_facility`, `in_types_id` FROM `{$GLOBALS['mysql_prefix']}ticket` WHERE `id` = ? LIMIT 1"; $row = db_fetch_one($query, [intval($ticket_id)], 'i'); if (!$row) {return;} $scope = $row['scope']; $facility = $row['facility']; $rec_facility = $row['rec_facility']; $in_types_id = $row['in_types_id']; $fields = array(); $fields[$GLOBALS['NOTIFY_TICKET_CHG']] = "on_ticket"; $fields[$GLOBALS['NOTIFY_ACTION_CHG']] = "on_action"; $fields[$GLOBALS['NOTIFY_PERSON_CHG']] = "on_patient"; $fields[$GLOBALS['NOTIFY_TICKET_CLOSE']] = "on_ticket"; $fields[$GLOBALS['NOTIFY_TICKET_OPEN']] = "on_ticket"; $addrs = array(); // $facaddrs = array(); $assignsaddrs = array(); $assignssmsaddrs = array(); $intypeaddrs = array(); $severity_filter = (intval($row['severity']) == $GLOBALS['SEVERITY_NORMAL'])? "(`severities` = 1 )" : "((`severities`= 3) OR (`severities`= 1))"; // 5/22/11 // $fields[$action_id] is from a hardcoded whitelist (on_ticket, on_action, on_patient) - safe for db_escape $notify_field = db_escape($fields[$action_id]); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}notify` WHERE ( {$severity_filter} AND (`ticket_id` = ? OR `ticket_id` = 0) AND `{$notify_field}` = '1')"; // all notifies for given ticket - or any ticket 10/22/08 $notify_rows = db_fetch_all($query, [intval($ticket_id)], 'i'); foreach ($notify_rows as $row) { //is it the right action? if (is_email($row['email_address'])) { array_push($addrs, $row['email_address']); // save for emailing } if($row['mailgroup'] != 0) { // 8/28/13 Checks for maillist notifies $query_mg = "SELECT * FROM `{$GLOBALS['mysql_prefix']}mailgroup_x` WHERE `mailgroup` = ?"; $mg_rows = db_fetch_all($query_mg, [intval($row['mailgroup'])], 'i'); foreach ($mg_rows as $row_mg) { if($row_mg['contacts'] != 0) { $query_c = "SELECT * FROM `{$GLOBALS['mysql_prefix']}contacts` WHERE `id` = ? LIMIT 1"; $row_c = db_fetch_one($query_c, [intval($row_mg['contacts'])], 'i'); if ($row_c && is_email($row_c['email'])) { array_push($addrs, $row_c['email']); // save for emailing } } elseif($row_mg['responder'] != 0) { $addrs_arr = get_contact_via($row_mg['responder']); foreach($addrs_arr as $val) { if (is_email($val)) { array_push($addrs, $val); // save for emailing } } } } } } if((get_variable('notify_facilities') == "1") && (($facility != 0) || ($rec_facility != 0))) { // 8/28/13 $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}facilities` WHERE `id` = ? OR `id` = ?"; $result = db_query($query, [strip_tags($facility), strip_tags($rec_facility)]); while($row = stripslashes_deep($result->fetch_assoc())) { //is it the right action? $continue = false; if($row['notify_when'] == 1) { $continue = true; } elseif($row['notify_when'] == 2 && $action_id == $GLOBALS['NOTIFY_TICKET_OPEN']) { $continue = true; } elseif($row['notify_when'] == 3 && $action_id == $GLOBALS['NOTIFY_TICKET_CLOSE']) { $continue = true; } else { $continue = false; } if($continue) { if($row['notify_email'] != "") { if (is_email($row['notify_email'])) { array_push($facaddrs, $row['notify_email']); // save for emailing } } elseif($row['notify_mailgroup'] != 0) { // 8/28/13 Checks for maillist notifies $query_mg = "SELECT * FROM `{$GLOBALS['mysql_prefix']}mailgroup_x` WHERE `mailgroup` = ?"; $result_mg = db_query($query_mg, [$row['notify_mailgroup']]); while($row_mg = stripslashes_deep($result_mg->fetch_assoc())) { if($row_mg['contacts'] != 0) { $query_c = "SELECT * FROM `{$GLOBALS['mysql_prefix']}contacts` WHERE `id` = ? LIMIT 1"; $result_c = db_query($query_c, [$row_mg['contacts']]); $row_c = stripslashes_deep($result_c->fetch_assoc()); if (is_email($row_c['email'])) { array_push($facaddrs, $row_c['email']); // save for emailing } } elseif($row_mg['responder'] != 0) { $addrs_arr = get_contact_via($row_mg['responder']); foreach($addrs_arr as $val) { if (is_email($val)) { array_push($facaddrs, $val); // save for emailing } } } } } } } if ($facaddrs) { $theTo = implode("|", array_unique($facaddrs)); $theText = "You are being notified as your facility is involved in resolution of incident: " . $scope; mail_it ($theTo, "", $theText, $ticket_id, 1 ); } // end if ($addrs) } if(get_variable('notify_in_types') == "1") { // 9/10/13 $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}in_types` WHERE `id` = ?"; $result = db_query($query, [strip_tags($in_types_id)]); while($row = stripslashes_deep($result->fetch_assoc())) { //is it the right action? $theType = $row['type']; $theDescription = $row['description']; $continue = false; if($row['notify_when'] == 1) { $continue = true; } elseif($row['notify_when'] == 2 && $action_id == $GLOBALS['NOTIFY_TICKET_OPEN']) { $continue = true; } elseif($row['notify_when'] == 3 && $action_id == $GLOBALS['NOTIFY_TICKET_CLOSE']) { $continue = true; } else { $continue = false; } if($continue) { if($row['notify_email'] != "") { if (is_email($row['notify_email'])) { array_push($intypeaddrs, $row['notify_email']); // save for emailing } } elseif($row['notify_mailgroup'] != 0) { // 8/28/13 Checks for maillist notifies $query_mg = "SELECT * FROM `{$GLOBALS['mysql_prefix']}mailgroup_x` WHERE `mailgroup` = ?"; $result_mg = db_query($query_mg, [$row['notify_mailgroup']]); while($row_mg = stripslashes_deep($result_mg->fetch_assoc())) { if($row_mg['contacts'] != 0) { $query_c = "SELECT * FROM `{$GLOBALS['mysql_prefix']}contacts` WHERE `id` = ? LIMIT 1"; $result_c = db_query($query_c, [$row_mg['contacts']]); $row_c = stripslashes_deep($result_c->fetch_assoc()); if (is_email($row_c['email'])) { array_push($intypeaddrs, $row_c['email']); // save for emailing } } elseif($row_mg['responder'] != 0) { $addrs_arr = get_contact_via($row_mg['responder']); foreach($addrs_arr as $val) { if (is_email($val)) { array_push($intypeaddrs, $val); // save for emailing } } } } } } } if ($intypeaddrs) { $theTo = implode("|", array_unique($intypeaddrs)); $theText = "You are being notified as incident " . $scope . " has an incident type of " . $theType . " - " . $theDescription; mail_it ($theTo, "", $theText, $ticket_id, 1 ); } // end if ($addrs) } $notify_assigns = get_variable('notify_assigns'); $defaultSMS = get_msg_variable('default_sms'); // notify assigns options - 0 is off, 1 notify assigns on close, 2 notify on close and inc change, 3 notify on close, inc change and action or patient change, 4 notify changes only not close $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}assigns` WHERE `ticket_id` = ?"; $result = db_query($query, [strip_tags($ticket_id)]); while($row = stripslashes_deep($result->fetch_assoc())) { // Assignments this Ticket $responderID = $row['responder_id']; $tick_id = $row['ticket_id']; $addrs_arr = get_contact_via($responderID); $smsgaddrs_arr = get_smsgid($responderID); $continue = false; if($action_id == "0" || $action_id == "1" || $action_id == "2" || $action_id == "4") { switch ($action_id) { case ("0") : $actionText = "changed"; break; case ("1") : $actionText = "changed"; break; case ("2") : $actionText = "changed"; break; case ("3") : $actionText = ""; break; case ("4") : $actionText = "closed\r\n"; break; default: $actionText = "changed"; } switch ($notify_assigns) { // what types of incident changes to send notify to assigned units case ("0") : $continue = false; // off break; case ("1") : $continue = ($action_id == 4) ? true : false; // close only break; case ("2") : $continue = ($action_id == 0 || $action_id == 4) ? true : false; // Incident change and close break; case ("3") : $continue = ($action_id == 0 || $action_id == 1 || $action_id == 2 || $action_id == 3 || $action_id == 4) ? true : false; // all changes and close break; case ("4") : $continue = ($action_id == 0 || $action_id == 1 || $action_id == 2 || $action_id == 3) ? true : false; // changes only, not on close break; default: $continue = false; } if($continue) { foreach($smsgaddrs_arr as $val) { if($val != "") { array_push($assignssmsaddrs, $val); // save for SMS } } foreach($addrs_arr as $val2) { if (is_email($val2)) { array_push($assignsaddrs, $val2); // save for emailing } } } } } if($actionText != "") { if ($assignsaddrs) { $theTo = implode("|", array_unique($assignsaddrs)); $theSMSTo = implode(",", array_unique($assignssmsaddrs)); $theText = "Incident " . $scope . " has " . $actionText; mail_it ($theTo, $theSMSTo, $theText, $ticket_id, 4 ); } } $temp = array_values(array_unique($addrs)); // 5/22/10 return (empty($temp))? false: $temp; } function notify_newreq($svceuser_id) { // 10/23/12 if (get_variable('allow_notify') != '1') return false; $addrs = array(); // $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}user` WHERE `level` = '0' OR `level` = '1'"; // Get all users admin and super that have valid email address stored and save for emailing. $result = db_query($query); while($row = stripslashes_deep($result->fetch_assoc())) { if (is_email($row['email'])) { array_push($addrs, $row['email']); } else { if(is_email($row['email_s'])) { array_push($addrs, $row['email_s']); } } } $temp = array_values(array_unique($addrs)); return (empty($temp))? false: $temp; } /** * Write a debug snapshot entry to the snap database table. * * Inserts a source label and optional data for debugging purposes. * Automatically purges entries older than 1 day. If the source is * an array, it is converted to a summary string with the element count. * No-op if the snap table does not exist. * * @param string|array $source Identifying label for the snapshot origin. * @param string $stuff Optional additional data to record. Default "". * @return void * @since v3.0 */ function snap($source, $stuff = "") { global $snap_table; // defined in istest.inc.php if (mysql_table_exists($snap_table)) { $query = "DELETE FROM `$snap_table` WHERE `when`< (NOW() - INTERVAL 1 DAY)"; // first remove old $result = db_query($query); if (is_array ( $source )) {$source = "array (" . count($source) . ")";} $result = db_query("INSERT INTO `$snap_table` (`source`,`stuff`) VALUES(?,?)", [trim($source), trim($stuff)]); unset($result); } else { // dump(__LINE__); } } // end function snap() function isFloat($n){ // 1/23/09 return ( $n == strval(floatval($n)) )? true : false; } function quote_smart($value) { // 1/28/09 // if (@ get_magic_quotes_gpc()) { // Stripslashes // $value = stripslashes($value); // } if (!is_int($value)) { // Quote if not a number or a numeric string $value = "'" . mysqli_real_escape_string($GLOBALS['db_handle'], $value) . "'"; } return $value; } function quote_smart_deep($value) { // recursive array-capable version of the above $value = is_array($value) ? array_map('quote_smart_deep', $value) : quote_smart($value); return $value; } function db_insert($table, $fieldset){ // 2/4/09 return 'INSERT INTO ' . $table . '(' . implode(',', array_keys($fieldset)) . ') VALUES (' . implode(',', array_values($fieldset)) . ')'; } function db_delete($table, $where = ''){ return 'DELETE FROM ' . $table . ($where ? ' WHERE ' . $where : ''); } function db_update($table, $fieldset, $where = ''){ $set = array(); foreach($fieldset as $field=>$value) $set[] = $field . '=' . $value; return 'UPDATE ' . $table . ' SET ' . implode(',', $set) . ($where ? ' WHERE ' . $where : ''); } function my_is_float($n){ // 5/4/09 return ((($n == strval(floatval($n))) || ($n == floatval($n))) && (!($n==0)) )? true : false; // 6/10/13 } function my_is_int($n){ // 3/25/09 return ( $n == strval(intval($n)) )? true : false; } function LLtoOSGB($lat, $lng) { $ll2w = new LatLng($lat, $lng); $ll2w->WGS84ToOSGB36(); $os2w = $ll2w->toOSRef($lat, $lng); $osgrid = $os2w->toSixFigureString(); return $osgrid; } //end function LLtoOSGB function my_date_diff_u ($d1_in, $d2_in) { // end, start datetime strings in, returns string - 5/13/10 - 11/29/2012 $d1 = strtotime((string)$d1_in); // string to integer $d2 = strtotime((string)$d2_in); if ($d1 < $d2){ // check higher timestamp and switch if neccessary $temp = $d2; $d2 = $d1; $d1 = $temp; } else { $temp = $d1; //temp can be used for day count if required } $d1 = date_parse(date("Y-m-d H:i:s", (integer)$d1)); $d2 = date_parse(date("Y-m-d H:i:s", (integer)$d2)); if ($d1['second'] >= $d2['second']){ //seconds $diff['second'] = $d1['second'] - $d2['second']; } else { $d1['minute']--; $diff['second'] = 60-$d2['second']+$d1['second']; } if ($d1['minute'] >= $d2['minute']){ //minutes $diff['minute'] = $d1['minute'] - $d2['minute']; } else { $d1['hour']--; $diff['minute'] = 60-$d2['minute']+$d1['minute']; } if ($d1['hour'] >= $d2['hour']){ //hours $diff['hour'] = $d1['hour'] - $d2['hour']; } else { $d1['day']--; $diff['hour'] = 24-$d2['hour']+$d1['hour']; } if ($d1['day'] >= $d2['day']){ //days $diff['day'] = $d1['day'] - $d2['day']; } else { $d1['month']--; $diff['day'] = date("t",$temp)-$d2['day']+$d1['day']; } if ($d1['month'] >= $d2['month']){ //months $diff['month'] = $d1['month'] - $d2['month']; } else { $d1['year']--; $diff['month'] = 12-$d2['month']+$d1['month']; } $diff['year'] = $d1['year'] - $d2['year']; //years $out_str = ""; $plural = ($diff['year'] == 1)? "": "s"; // needless elegance $out_str .= empty($diff['year'])? "" : "{$diff['year']} yr{$plural}, "; $plural = ($diff['month'] == 1)? "": "s"; $out_str .= empty($diff['month'])? "" : "{$diff['month']} mo{$plural}, "; $plural = ($diff['day'] == 1)? "": "s"; $out_str .= empty($diff['day'])? "" : "{$diff['day']} day{$plural}, "; $plural = ($diff['hour'] == 1)? "": "s"; $out_str .= empty($diff['hour'])? "" : "{$diff['hour']} hr{$plural}, "; $plural = ($diff['minute'] == 1)? "": "s"; $out_str .= empty($diff['minute'])? "" : "{$diff['minute']} min{$plural}"; return $out_str; } function my_date_diff($d1_in, $d2_in) { // end, start datetime strings in, returns string - 5/13/10 - 11/29/2012 $d1 = strtotime((string)$d1_in); // string to integer $d2 = strtotime((string)$d2_in); if ($d1 < $d2){ // check higher timestamp and switch if neccessary $temp = $d2; $d2 = $d1; $d1 = $temp; } else { $temp = $d1; //temp can be used for day count if required } $d1 = date_parse(date("Y-m-d H:i:s", (integer)$d1)); $d2 = date_parse(date("Y-m-d H:i:s", (integer)$d2)); if ($d1['second'] >= $d2['second']){ //seconds $diff['second'] = $d1['second'] - $d2['second']; } else { $d1['minute']--; $diff['second'] = 60-$d2['second']+$d1['second']; } if ($d1['minute'] >= $d2['minute']){ //minutes $diff['minute'] = $d1['minute'] - $d2['minute']; } else { $d1['hour']--; $diff['minute'] = 60-$d2['minute']+$d1['minute']; } if ($d1['hour'] >= $d2['hour']){ //hours $diff['hour'] = $d1['hour'] - $d2['hour']; } else { $d1['day']--; $diff['hour'] = 24-$d2['hour']+$d1['hour']; } if ($d1['day'] >= $d2['day']){ //days $diff['day'] = $d1['day'] - $d2['day']; } else { $d1['month']--; $diff['day'] = date("t",$temp)-$d2['day']+$d1['day']; } if ($d1['month'] >= $d2['month']){ //months $diff['month'] = $d1['month'] - $d2['month']; } else { $d1['year']--; $diff['month'] = 12-$d2['month']+$d1['month']; } $diff['year'] = $d1['year'] - $d2['year']; //years $out_str = ""; $plural = ($diff['year'] == 1)? "": "s"; // needless elegance $out_str .= empty($diff['year'])? "" : "{$diff['year']} yr{$plural}, "; $plural = ($diff['month'] == 1)? "": "s"; $out_str .= empty($diff['month'])? "" : "{$diff['month']} mo{$plural}, "; $plural = ($diff['day'] == 1)? "": "s"; $out_str .= empty($diff['day'])? "" : "{$diff['day']} day{$plural}, "; $plural = ($diff['hour'] == 1)? "": "s"; $out_str .= empty($diff['hour'])? "" : "{$diff['hour']} hr{$plural}, "; $plural = ($diff['minute'] == 1)? "": "s"; $out_str .= empty($diff['minute'])? "" : "{$diff['minute']} min{$plural}"; return $out_str; } /* - 5/20/2013 function get_elapsed_time ($in_start, $in_end) { // datetime strings - 11/30/2012 if (!(good_date_time($in_end))) { // possibly open $in_end = date("Y-m-d H:i:00", (time() - (intval(get_variable('delta_mins'))*60))); // current local time to timestamp format return "(" . my_date_diff($in_start, $in_end) . ")"; // identify as 'now' time difference } else { return my_date_diff($in_start, $in_end); } } */ function get_elapsed_time ($in_row) { // ex: 2012-03-29 14:37:10 - 5/20/2013 if (!is_array($in_row)) { $in_row = array(); } $problemend = array_key_exists('problemend', $in_row) ? $in_row['problemend'] : null; $status = array_key_exists('status', $in_row) ? $in_row['status'] : null; $booked = array_key_exists('booked_date', $in_row) ? $in_row['booked_date'] : null; $problemstart = array_key_exists('problemstart', $in_row) ? $in_row['problemstart'] : now_ts(); $end_date = (good_date_time($problemend))? $problemend : now_ts(); // string $start_date = ($status == $GLOBALS['STATUS_SCHEDULED'] )? $booked : $problemstart; if(is_numeric($start_date)) $start_date = date("Y-m-d H:i:s", $start_date); return my_date_diff_u ( $start_date , $end_date); } function expires() { $deltamins = (get_variable('delta_mins') != "") ? intval(get_variable('delta_mins')) : 0; $now = time() - ($deltamins*60); $sessionTimeout = (intval(get_variable('session_timeout')) != 0) ? intval(get_variable('session_timeout')) : 60; return $now + (60*$sessionTimeout); } function get_unit_icon($id) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}responder` WHERE `id` = ?"; $result = db_query($query, [$id]); if($result->num_rows > 0) { $row = stripslashes_deep($result->fetch_assoc()); $icon_str = $row['icon_str']; } else { $icon_str = "UNK"; } return $icon_str; } function get_facility_icon($id) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}facilities` WHERE `id` = ?"; $result = db_query($query, [$id]); if($result->num_rows > 0) { $row = stripslashes_deep($result->fetch_assoc()); $icon_str = $row['icon_str']; } else { $icon_str = "UNK"; } return $icon_str; } function get_status_sel($unit_in, $status_val_in, $tbl_in) { // returns select list as click-able string - 2/6/10 $icon_str = ($tbl_in == "u") ? get_unit_icon($unit_in) : get_facility_icon($unit_in); switch ($tbl_in) { case ("u") : $tablename = "responder"; $link_field = "un_status_id"; $status_table = "un_status"; $status_field = "status_val"; break; case ("f") : $tablename = "facilities"; $link_field = "status_id"; $status_table = "fac_status"; $status_field = "status_val"; break; default: print "ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR "; } $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}{$tablename}`, `{$GLOBALS['mysql_prefix']}{$status_table}` WHERE `{$GLOBALS['mysql_prefix']}{$tablename}`.`id` = ? AND `{$GLOBALS['mysql_prefix']}{$status_table}`.`id` = `{$GLOBALS['mysql_prefix']}{$tablename}`.`{$link_field}` LIMIT 1" ; $result = db_query($query, [$unit_in]); if ($result->num_rows==0) { // 2/7/10 $init_bg_color = "transparent"; $init_txt_color = "black"; } else { $row = stripslashes_deep($result->fetch_assoc()); $init_bg_color = $row['bg_color']; $init_txt_color = $row['text_color']; } $guest = is_guest(); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}{$status_table}` ORDER BY `group` ASC, `sort` ASC, `{$status_field}` ASC"; $result_st = db_query($query); $dis = ($guest)? " DISABLED": ""; // 9/17/08 $the_grp = strval(rand()); // force initial OPTGROUP value $i = 0; $outstr = ($tbl_in == "u") ? "\t\t"; // 12/19/09, 1/1/10. 3/15/11 while ($row = stripslashes_deep($result_st->fetch_assoc())) { if ($the_grp != $row['group']) { $outstr .= ($i == 0)? "": "\t"; $the_grp = $row['group']; $outstr .= "\t\t"; } $sel = ($row['id']==$status_val_in)? " SELECTED": ""; $outstr .= "\t\t\t"; $i++; } // end while() $outstr .= "\t\t\t\t"; return $outstr; } function curr_regs() { // 10/18/11 Gets currently allocated or viewed regions $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}allocates` WHERE `type`= 4 AND `resource_id` = ?;"; // 10/18/11 $result = db_query($query, [$_SESSION['user_id']]); $al_groups = array(); while ($row = stripslashes_deep($result->fetch_assoc())) { $al_groups[] = $row['group']; } if(array_key_exists('viewed_groups', $_SESSION)) { $curr_viewed= explode(",",$_SESSION['viewed_groups']); } if(!isset($curr_viewed)) { if(empty($al_groups)) { // catch for errors - no entries in allocates for the user. // 5/30/13 $where = "WHERE `{$GLOBALS['mysql_prefix']}allocates`.`type` = 3"; } else { $x=0; // 6/10/11 $where = "WHERE ("; foreach($al_groups as $grp) { $where2 = (count($al_groups) > ($x+1)) ? " OR " : ")"; $where .= "`{$GLOBALS['mysql_prefix']}allocates`.`group` = '{$grp}'"; $where .= $where2; $x++; } $where .= "AND `{$GLOBALS['mysql_prefix']}allocates`.`type` = 3"; // sets the region allocations searched for to type = 3 - Facilities. } } else { if(empty($curr_viewed)) { // catch for errors - no entries in allocates for the user. // 5/30/13 $where = "WHERE `a`.`type` = 2"; } else { $x=0; // 6/10/11 $where = "WHERE ("; // 6/10/11 foreach($curr_viewed as $grp) { $where2 = (count($curr_viewed) > ($x+1)) ? " OR " : ")"; $where .= "`{$GLOBALS['mysql_prefix']}allocates`.`group` = '{$grp}'"; $where .= $where2; $x++; } $where .= "AND `{$GLOBALS['mysql_prefix']}allocates`.`type` = 3"; // sets the region allocations searched for to type = 3 - Facilities. } } return $where; } function get_recfac_sel($unit_in, $tickid, $assign_id) { // 10/18/11 - Gets select menu for receiving facility control on mobile page $where = curr_regs(); $query01 = "SELECT * FROM `{$GLOBALS['mysql_prefix']}assigns` WHERE `{$GLOBALS['mysql_prefix']}assigns`.`id` = ? LIMIT 1"; $result01 = db_query($query01, [$assign_id]); while ($row01 = stripslashes_deep($result01->fetch_assoc())) { $curr_fac = $row01['rec_facility_id']; } $query02 = "SELECT *, `{$GLOBALS['mysql_prefix']}facilities`.`id` AS `fac_id` FROM `{$GLOBALS['mysql_prefix']}facilities` LEFT JOIN `{$GLOBALS['mysql_prefix']}allocates` ON ( `{$GLOBALS['mysql_prefix']}facilities`.`id` = `{$GLOBALS['mysql_prefix']}allocates`.`resource_id` ) $where GROUP BY `{$GLOBALS['mysql_prefix']}facilities`.`id` ORDER BY `name` ASC"; $result02 = db_query($query02); $guest = is_guest(); $dis = ($guest)? " DISABLED": ""; $i = 0; $outstr = "\t\t"; return $outstr; } function get_units_legend() { // returns string as centered span - 2/8/10 $query = "SELECT DISTINCT `type`, `icon`, `{$GLOBALS['mysql_prefix']}unit_types`.`name` AS `mytype` FROM `{$GLOBALS['mysql_prefix']}responder` LEFT JOIN `{$GLOBALS['mysql_prefix']}unit_types` ON `{$GLOBALS['mysql_prefix']}unit_types`.`id` = `{$GLOBALS['mysql_prefix']}responder`.`type` ORDER BY `mytype`"; $result = db_query($query); $out_str = " Units Types:  "; while ($row = stripslashes_deep($result->fetch_assoc())) { $the_bg_color = array_key_exists($row['icon'], $GLOBALS['UNIT_TYPES_BG']) ? $GLOBALS['UNIT_TYPES_BG'][$row['icon']] : "#FFFFFF"; $the_text_color = array_key_exists($row['icon'], $GLOBALS['UNIT_TYPES_TEXT']) ? $GLOBALS['UNIT_TYPES_TEXT'][$row['icon']] : "000000"; $out_str .= " {$row['mytype']} "; } return $out_str .= ""; } // end function get_units_legend() function get_wl_legend() { // returns string as centered span - 2/8/10 $out_str = " Warn Location Types:  "; // 3/15/11 $warn_types = array(); foreach($GLOBALS['LOC_TYPES'] as $val) { $warn_types[$val] = $GLOBALS['LOC_TYPES_NAMES'][$val]; } foreach ($warn_types as $key => $value) { $the_bg_color = array_key_exists($key, $GLOBALS['LOC_TYPES_BG']) ? $GLOBALS['LOC_TYPES_BG'][$key]: "#FFFFFF"; $the_text_color = array_key_exists($key, $GLOBALS['LOC_TYPES_TEXT']) ? $GLOBALS['LOC_TYPES_TEXT'][$key] : "#000000"; $theName = array_key_exists($key, $GLOBALS['LOC_TYPES_NAMES']) ? $GLOBALS['LOC_TYPES_NAMES'][$key] : "Error"; $out_str .= " {$theName} "; } return $out_str .= ""; } // end function get_units_legend() function get_facilities_legend() { // returns string as centered row - 2/8/10 $query = "SELECT DISTINCT `type`, `icon`, `{$GLOBALS['mysql_prefix']}fac_types`.`name` AS `mytype` FROM `{$GLOBALS['mysql_prefix']}facilities` LEFT JOIN `{$GLOBALS['mysql_prefix']}fac_types` ON `{$GLOBALS['mysql_prefix']}fac_types`.`id` = `{$GLOBALS['mysql_prefix']}facilities`.`type` ORDER BY `mytype`"; $result = db_query($query); $out_str = " Facilitiy types:  "; // 3/15/11 while ($row = stripslashes_deep($result->fetch_array())) { $the_bg_color = array_key_exists($row['icon'], $GLOBALS['FACY_TYPES_BG']) ? $GLOBALS['FACY_TYPES_BG'][$row['icon']] : "#FFFFFF"; $the_text_color = array_key_exists($row['icon'], $GLOBALS['FACY_TYPES_TEXT']) ? $GLOBALS['FACY_TYPES_TEXT'][$row['icon']] : "#000000"; $out_str .= " {$row['mytype']}  "; } return $out_str .= ""; } // end function get_facilities_legend() function is_phone ($instr) { // 3/13/10 if(get_variable("locale")==0){ return ((strlen(trim($instr))==9) && (is_numeric($instr))) ; } else { return (is_numeric($instr)); } } function get_unit_status_legend() { // returns string as div - 3/21/10 $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}un_status` ORDER BY `status_val`"; $result = db_query($query); $out_str = "
Status legend:
 
"; while ($row = stripslashes_deep($result->fetch_assoc())) { $out_str .= "{$row['status_val']} "; } return $out_str .= "
"; } // end function get_unit_status_legend() function get_un_div_height ($in_max) { // compute pixels min 260, max .5 x screen height - 2/8/10 $min = 80 ; $max = round($in_max * $_SESSION['scr_height']); $query = "SELECT `id` FROM `{$GLOBALS['mysql_prefix']}responder`"; $result_unit = db_query($query); $num_units = $result_unit->num_rows; unset ($result_unit); $required = 96 + ($num_units*22); // 7/9/10 // $required = $num_units * 23; // pixels per line if ($required < $min) {return $min;} else {return ($required > $max)? $max: $required;} } // end function un_div_height () function get_sess_vbl ($in_str) { // $default = 'error'; @session_start(); return (array_key_exists ( $in_str, $_SESSION ))? $_SESSION [$in_str]: $default; } // end get_sess_vbl() function now_ts() { // returns date time as a timestamp - 5/19/2013 return mysql_format_date(time() - intval(get_variable('delta_mins'))*60); } function now() { // returns date as integer return (time() - intval(get_variable('delta_mins'))*60); } function monday() { // returns date return strtotime("last Monday"); } function day() { // returns number return date("d", now()); } function month() { // returns number return date("n", now()); } function year() { // returns number return date("Y", now()); } function get_start($local_func){ // 5/2/10 switch ($local_func) { case 1 : // Today return mysql_format_date(mktime( 0, 0, 0, month(), day(), year())); // m, d, y -- date ('D, M j', break; case 2 : // Yesterday+ return mysql_format_date(mktime(0,0,0, month(), (day()-1), year())); // m, d, y -- date ('D, M j', break; case 3 : // This week return mysql_format_date(monday()); // m, d, y -- date ('D, M j', break; case 4 : // Last week return mysql_format_date(monday() - 7*24*3600); // m, d, y -- monday a week ago break; case 5 : // Last week+ return mysql_format_date(monday() - 7*24*3600); // m, d, y -- monday a week ago break; case 6 : // This month return mysql_format_date(mktime(0,0,0, month(), 1, year())); // m, d, y -- date ('D, M j', break; case 7 : // Last month return mysql_format_date(mktime(0,0,0, (month()-1), 1, year())); // m, d, y -- date ('D, M j', break; case 8 : // This year return mysql_format_date(mktime(0,0,0, 1, 1, year())); // m, d, y -- date ('D, M j', break; case 9 : // Last year return mysql_format_date(mktime(0,0,0, 1, 1, (year()-1))); // m, d, y -- date ('D, M j', break; default: echo __LINE__ . " error error error error error \n"; } } // end function get_start function get_end($local_func){ switch ($local_func) { case 1 : // Today case 2 : // Yesterday+ case 3 : // This week case 5 : // Last week+ case 6 : // This month case 8 : // This year return mysql_format_date(mktime( 23,59,59, month(), day(), year())); // m, d, y -- date ('D, M j', // return mysql_format_date(now()); // m, d, y -- date ('D, M j', break; case 4 : // Last week return mysql_format_date(monday()-1); // m, d, y -- last monday break; case 7 : // Last month return mysql_format_date(mktime(0,0,0, month(), 1,year())); // m, d, y -- date ('D, M j', break; case 9 : // Last year return mysql_format_date(mktime(23,59,59, 12,31, (year()-1))); // m, d, y -- date ('D, M j', break; default: echo __LINE__ . " error error error error error \n"; } } // end function get_end function get_cb_height () { // returns pixel count for cb frame height based on no. of lines - 7/10/10 $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}assigns` WHERE `clear` IS NULL OR DATE_FORMAT(`clear`,'%y') = '00'"; // 2/12/09 $result = db_query($query); $lines = $result->num_rows; unset($result); $cb_per_line = 22; // via trial and error $cb_fixed_part = 60; $cb_min = 96; $cb_max = 300; $height = (($lines*$cb_per_line ) + $cb_fixed_part); $height = ($height<$cb_min)? $cb_min: $height; $height = ($height>$cb_max)? $cb_max: $height; return (integer) $height; } // function get_cb_height () $text_array = array(); /** * Retrieve a display caption/label from the database captions table. * * Lazy-loads all captions into a static cache on the first call. Used for * UI label customization — administrators can rename fields like "Severity" * to "Priority" etc. Returns the original key if no replacement is defined. * * @param string $which Caption key to look up (e.g. "Normal", "Medium", "High"). * @return string The replacement text, or the original key if not found. * @since v3.0 */ function get_text($which){ global $text_array; if (empty($text_array)) { // populate it to avoid hammering db $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}captions`"; $result = db_query($query); while ($row = stripslashes_deep($result->fetch_assoc())){ $capt = $row['capt']; $repl=$row['repl'] ; $text_array[$capt] = $repl; } } return (array_key_exists($which, $text_array))? $text_array[$which] : $which ; } $tips_array = array(); function get_tip($which){ /* get replacement text from db tips table, returns FALSE if absent */ global $tips_array; if (empty($tips_array)) { // populate it to avoid hammering db $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}tips`"; $result = db_query($query); while ($row = stripslashes_deep($result->fetch_assoc())){ $title = $row['title']; $tip = $row['tip'] ; $tips_array[$title] = $tip; } } return (array_key_exists($which, $tips_array))? $tips_array[$which] : $which ; } function can_edit() { $retval = false; if(is_administrator() || is_super() || is_manager()) { $retval = true; } elseif(is_user() && get_variable('oper_can_edit') == 1) { $retval = true; } elseif(is_unit() && get_variable('unit_can_edit') == 1) { $retval = true; } else { $retval = false; } return $retval; } // end function can_edit() function can_view() { $retval = false; if(is_administrator() || is_super() || is_manager() || is_user()) { $retval = true; } else { $retval = false; } return $retval; } // end function can_edit() function do_diff($indx, $row){ // returns diff in seconds from problemstart- 9/29/10 switch ($indx) { case 0: $temp = mysql2timestamp($row['dispatched']); break; case 1: $temp = mysql2timestamp($row['responding']); break; case 2: $temp = mysql2timestamp($row['on_scene']); break; case 3: $temp = mysql2timestamp($row['u2fenr']); // 10/19/10 break; case 4: $temp = mysql2timestamp($row['u2farr']); break; case 5: $temp = mysql2timestamp($row['clear']); break; case 6: $temp = mysql2timestamp($row['problemend']); break; default: dump($indx); // error error error error error } return $temp - mysql2timestamp($row['problemstart']); } function elapsed ($in_time) { // 4/26/11 $mins = (integer) (round ((now() - mysql2timestamp($in_time)) / 60.0)); return ($mins> 99)? 99: $mins; } // end function elapsed function get_disp_status ($row_in) { // 4/26/11 extract ($row_in); $tags_arr = explode("/", get_variable('disp_stat')); if (is_date($u2farr)) { return " {$tags_arr[4]} " . elapsed ($u2farr) . "";} if (is_date($u2fenr)) { return " {$tags_arr[3]} " . elapsed ($u2fenr) . "";} if (is_date($on_scene)) { return " {$tags_arr[2]} " . elapsed ($on_scene) . "";} if (is_date($responding)) { return " {$tags_arr[1]} " . elapsed ($responding) . "";} if (is_date($dispatched)) { return " {$tags_arr[0]} " . elapsed ($dispatched) . "";} } function auto_disp_status($disp_status, $responder, $tick_id=0) { // 8/22/13 $now = mysql_format_date(time() - (intval(get_variable('delta_mins'))*60)); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}auto_disp_status` WHERE `id` = ? LIMIT 1"; $result = db_query($query, [$disp_status]); if($result->num_rows >= 1) { $row = stripslashes_deep($result->fetch_assoc()); $the_val = intval($row['status_val']); $query2 = "UPDATE `{$GLOBALS['mysql_prefix']}responder` SET `un_status_id` = ?, `user_id` = '999999', `status_updated` = ?, `updated`= ? WHERE `id`= ?"; $result2 = db_query($query2, [$the_val, $now, $now, $responder]); if($result2) { $the_ret = $the_val; do_log($GLOBALS['LOG_UNIT_STATUS'], $tick_id, $responder, $the_val); } else { $the_ret = 0; } } else { $the_ret = 0; } return $the_ret; } // 5/11/2013 fix to remove '_on' change ' _by' to 'user_id' from set_u_updated () sql - 6/10/2013 function set_u_updated ($in_assign) { // given a disaptch record id, updates unit data - 9/1/10 $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}assigns` WHERE `id` = ? LIMIT 1"; $result = db_query($query, [$in_assign]); $row_temp = $result->fetch_assoc(); // $now = mysql_format_date(time() - (intval(get_variable('delta_mins'))*60)); // 9/1/10 $user = trim($_SESSION['user_id']); $result = db_query("UPDATE `{$GLOBALS['mysql_prefix']}responder` SET `updated`= ?, `user_id`= ? WHERE `id`= ?", [$now, $user, $row_temp['responder_id']]); unset($result); return true; } // end function set_u_updated ( function short_ts($in_str){ // ex:10/29/10 12:22 - 10/2/10 return substr($in_str, -5); } function get_dist_factor() { // returns distance conversion factor - 11/24/10 $factors = array("0.6214", "0.6214", "1.0"); // factors as strings return $factors[get_variable("locale")]; // US, UK, ROW } function get_speed ($instr, $inspeed) { // 11/26/10 if (!(is_int($inspeed))) {$the_class='unk';} elseif ($inspeed >= 50) {$the_class='fast'; } elseif ($inspeed == 0) {$the_class='stopped'; } else {$the_class='moving'; } return " {$instr} "; } function get_remote($url, $json=true) { // 11/26/10 , 4/23/11 if (function_exists("curl_init")) { $ch = curl_init(); $timeout = 10; curl_setopt($ch,CURLOPT_URL,$url); $verify_ssl = get_variable('verify_ssl') !== '0'; // Default: verify SSL. Set verify_ssl=0 in settings to disable. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verify_ssl); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $verify_ssl ? 2 : 0); curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); curl_setopt($ch,CURLOPT_TIMEOUT,$timeout); $data = curl_exec($ch); $curl_errno = curl_errno($ch); $curl_error = curl_error($ch); curl_close($ch); if ($curl_errno > 0) { print $curl_error . "
"; } } else { // no CURL $data = ""; if ($fp = @fopen($url, "r")) { while (!feof($fp) && (strlen($data)<9000)) $data .= fgets($fp, 128); fclose($fp); } } if($data) { if ($json) { // 4/23/11 $data = ($data) ? json_decode($data): false; // FALSE if fails } else { $data = ($data) ? $data: false; // FALSE if fails } return $data; } else { return false; } } // end function get remote() function get_hints($instr) { // returns associative array - 11/30/10 $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}hints` WHERE `form` = ? "; $result = db_query($query, [$instr]); $hints = array(); while ($row = stripslashes_deep($result->fetch_assoc())) { $hints[$row['ident']] = $row['title']; } return($hints); } // end function function get_regions_buttons($user_id) { // 4/12/12 global $evenodd; $regs_viewed = ""; if(array_key_exists('viewed_groups', $_SESSION)) { $regs_viewed= explode(",",$_SESSION['viewed_groups']); } $query2 = "SELECT * FROM `{$GLOBALS['mysql_prefix']}allocates` WHERE `type`= 4 AND `resource_id` = ? ORDER BY `group`"; // 5/3/11 $result2 = db_query($query2, [$user_id]); $al_buttons=""; $i = 1; while ($row2 = stripslashes_deep($result2->fetch_assoc())) { // 4/12/12 if(!empty($regs_viewed)) { if(in_array($row2['group'], $regs_viewed)) { $al_buttons.="" . get_groupname($row2['group']) . "
"; } else { $al_buttons.="" . get_groupname($row2['group']) . "
"; } } else { $al_buttons.="" . get_groupname($row2['group']) . "
"; } $i++; } return $al_buttons; } function get_regions_buttons2($user_id) { // 4/12/12 if(array_key_exists('viewed_groups', $_SESSION)) { $regs_viewed= explode(",",$_SESSION['viewed_groups']); } $query2 = "SELECT * FROM `{$GLOBALS['mysql_prefix']}allocates` WHERE `type`= 4 AND `resource_id` = ? ORDER BY `group`"; // 5/3/11 $result2 = db_query($query2, [$user_id]); $al_buttons=""; while ($row2 = stripslashes_deep($result2->fetch_assoc())) { // 5/3/11 if(!empty($regs_viewed)) { if(in_array($row2['group'], $regs_viewed)) { $al_buttons.="
" . get_groupname($row2['group']) . "  

"; } else { $al_buttons.="
" . get_groupname($row2['group']) . "  

"; } } else { $al_buttons.="
" . get_groupname($row2['group']) . "  

"; } } return $al_buttons; } function clean_string($value) { // 10/23/12 // if(@ get_magic_quotes_gpc()) { // $value = stripslashes($value); // } return mysqli_real_escape_string($GLOBALS['db_handle'], $value); } function get_buttons_inner(){ // 4/12/12, 4/2/14 if((get_num_groups()) && (COUNT(get_allocates(4, $_SESSION['user_id'])) > 1)) { // 6/10/11 ?> 1)) { // 6/10/11 ?> 0)) { return false; } else { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}responder` WHERE `id` = ? LIMIT 1"; $result = db_query($query, [$_SESSION['user_unit_id']]); if (($result->num_rows)==0) { unset($result); return false; } else { $row = stripslashes_deep($result->fetch_array()); $temp = explode("/", $row['name'] ); $index = substr($temp[count($temp) -1], -6,strlen($temp[count($temp) -1])); unset($result); return $index; } } // end if/else } // end function get_unit() function get_handle(){ // returns unit index string - 3/19/11 $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}responder` WHERE `id` = ? LIMIT 1"; $result = db_query($query, [$_SESSION['user_unit_id']]); if (($result->num_rows)==0) { unset($result); return "Mobile"; } else { $row = stripslashes_deep($result->fetch_array()); $handle = ($row['handle'] != "") ? $row['handle'] : "Mobile"; unset($result); return $handle; } // end if/else } // end function get_unit() function get_respondername($id) { if(!$id) {return "N/A";} $query = "SELECT `id`, `name`, `handle` FROM `{$GLOBALS['mysql_prefix']}responder` WHERE `id`= ? LIMIT 1"; $result = db_query($query, [$id]); if (($result->num_rows)==0) { $ret_val = "NA"; } else { $row = stripslashes_deep($result->fetch_array()); $ret_val = $row['handle']; } return $ret_val; } function like_ify($instr) { // 3/6/2015 -- converts non-alphanumerics to underscores for use with mysql 'like' return preg_replace("/[^a-zA-Z0-9]+/", "_", $instr); } function get_facilityname($id) { $query = "SELECT `id`, `name`, `handle` FROM `{$GLOBALS['mysql_prefix']}facilities` WHERE `id`= ? LIMIT 1"; $result = db_query($query, [$id]); if (($result->num_rows)==0) { $ret_val = "NA"; } else { $row = stripslashes_deep($result->fetch_array()); $temp = explode("/", $row['name']); $ret_val = $temp[0]; } return $ret_val; } function get_facilityhandle($id) { $query = "SELECT `id`, `name`, `handle` FROM `{$GLOBALS['mysql_prefix']}facilities` WHERE `id`= ? LIMIT 1"; $result = db_query($query, [$id]); if (($result->num_rows)==0) { $ret_val = "NA"; } else { $row = stripslashes_deep($result->fetch_array()); $temp = explode("/", $row['handle']); $ret_val = $temp[0]; } return $ret_val; } function get_state_abb($name) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}states_translator` WHERE `name` = ?"; $result = db_query($query, [$name]); if($result->num_rows > 0) { $row = stripslashes_deep($result->fetch_array()); return $row['code']; } else { return $name; } } function shut_down(){ // 5/25/11 do_log($GLOBALS['LOG_INTRUSION'],0); ?>

Intrusion attempt prevented!



Intrusion attempt prevented!

num_rows >=1)) { $print = ""; $print .= ""; while ($row = stripslashes_deep($result->fetch_assoc())){ $print .= ""; $filename = $row['filename']; $origfilename = $row['orig_filename']; $title = $row['title']; $print .= ""; $print .= ""; $print .= ""; $print .= ""; $bgcolor = ($bgcolor == "#EEEEEE") ? "#FEFEFE" : "#EEEEEE"; } // end while $print .= "
File NameUploaded ByDate
" . $row['title'] . "" . get_owner($row['_by']) . "" . format_date_2(strtotime($row['_on'])) . "
"; } else { $print = ""; $print .= ""; $print .="
 
No Files
"; } // end else return $print; } function add_sidebar($regions = true, $files = true, $messages = true, $controls = true, $more=false, $allowedit=false, $ticket_id = 0, $responder_id = 0, $facility_id = 0, $mi_id = 0) { $theHeight = $_SESSION['scr_height'] / 2.5; $theHeight2 = $theHeight * .8; $theHeight3 = $theHeight * .58; $use_twitter = (get_variable('twitter_consumerkey') != "" && get_variable('twitter_consumersecret') != "" && get_variable('twitter_accesstoken') != "" && get_variable('twitter_accesstokensecret') != "") ? true : false; $print = "
"; if((!(is_guest())) && $regions) { if(get_num_groups()) { $print .= "
Regions
"; } } if((!(is_guest())) && $files) { $print .= "
Files
"; } if((!(is_guest())) && $messages) { $print .= "
Messages
"; } if($controls) { $print .= "
Map Controls
"; } if((!(is_guest())) && $more && $use_twitter) { $print .= "
More
"; } $print .= "
"; return $print; } function do_tweet($message) { require_once '../lib/twitter/twitter.class.php'; $consumerKey = get_variable('twitter_consumerkey'); $consumerSecret = get_variable('twitter_consumersecret'); $accessToken = get_variable('twitter_accesstoken'); $accessTokenSecret = get_variable('twitter_accesstokensecret'); $twitter = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret); try { $tweet = $twitter->send($message); // you can add $imagePath as second argument return 1; } catch (TwitterException $e) { $log_message = "Error Sending Tweet. Error Details - " . $e->getMessage(); do_log($GLOBALS['LOG_ERROR'], 0, 0, $log_message); } } function show_tweets() { require_once './lib/twitter/twitter.class.php'; $consumerKey = get_variable('twitter_consumerkey'); $consumerSecret = get_variable('twitter_consumersecret'); $accessToken = get_variable('twitter_accesstoken'); $accessTokenSecret = get_variable('twitter_accesstokensecret'); $twitter = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret); $statuses = $twitter->load(Twitter::ME_AND_FRIENDS); $print = ""; $print .= ""; return $print; } function show_rec_direc($count = 20) { require_once './lib/twitter/twitter.class.php'; $consumerKey = get_variable('twitter_consumerkey'); $consumerSecret = get_variable('twitter_consumersecret'); $accessToken = get_variable('twitter_accesstoken'); $accessTokenSecret = get_variable('twitter_accesstokensecret'); $twitter = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret); $messages = $twitter->rec_direct($count); $print = ""; $print .= ""; return $print; } function show_sent_direc($count = 20) { require_once './lib/twitter/twitter.class.php'; $consumerKey = get_variable('twitter_consumerkey'); $consumerSecret = get_variable('twitter_consumersecret'); $accessToken = get_variable('twitter_accesstoken'); $accessTokenSecret = get_variable('twitter_accesstokensecret'); $twitter = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret); $messages = $twitter->sent_direct($count); $print = ""; $print .= ""; return $print; } function do_tweet_direct($message, $userid = null, $screenname = null) { require_once '../lib/twitter/twitter.class.php'; $consumerKey = get_variable('twitter_consumerkey'); $consumerSecret = get_variable('twitter_consumersecret'); $accessToken = get_variable('twitter_accesstoken'); $accessTokenSecret = get_variable('twitter_accesstokensecret'); $twitter = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret); if(($userid == null || $userid == "") && ($screenname == null || $screenname == "")) { return false; } else { try { $tweet = $twitter->direct($message, $userid, $screenname); return 1; } catch (TwitterException $e) { $log_message = "Error Sending Tweet. Error Details - " . $e->getMessage(); do_log($GLOBALS['LOG_ERROR'], 0, 0, $log_message); return $e->getMessage(); } } } function send_tweet_direct($message, $userid = null, $screenname = null) { require_once './lib/twitter/twitter.class.php'; $consumerKey = get_variable('twitter_consumerkey'); $consumerSecret = get_variable('twitter_consumersecret'); $accessToken = get_variable('twitter_accesstoken'); $accessTokenSecret = get_variable('twitter_accesstokensecret'); $twitter = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret); if(($userid == null || $userid == "") && ($screenname == null || $screenname == "")) { return false; } else { try { $tweet = $twitter->direct($message, $userid, $screenname); return 1; } catch (TwitterException $e) { $log_message = "Error Sending Tweet. Error Details - " . $e->getMessage(); do_log($GLOBALS['LOG_ERROR'], 0, 0, $log_message); return $e->getMessage(); } } } function is_dir_empty($dir) { if (!is_readable($dir)) return null; $handle = opendir($dir); while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { return false; } } return true; } function get_tile_bounds ($repository) { // Try cached bounds from database first to avoid expensive filesystem scan. // The 'bounds' setting is updated by update_localmap_boundary.php after tile // downloads and by recalculate_tile_bounds() after tile changes. 3/14/26 $cached = get_variable('bounds'); if (!empty($cached)) { $parts = explode(',', $cached); if (count($parts) === 4) { // bounds format: "bl_lat,bl_lon,tr_lat,tr_lon" → return [west, north, east, south] return array( floatval($parts[1]), // west (bl_lon) floatval($parts[2]), // north (tr_lat) floatval($parts[3]), // east (tr_lon) floatval($parts[0]) // south (bl_lat) ); } } // Fallback: scan filesystem (only reached if no cached bounds exist) return scan_tile_bounds($repository); } // end function /** * Scan the tile directory to compute geographic bounds from tile coordinates. * This is expensive I/O on large tile sets — results should be cached via * recalculate_tile_bounds(). All opendir() calls are guarded to prevent * PHP warnings from flooding the error log. 3/14/26 */ function scan_tile_bounds ($repository) { if(!is_dir($repository) || is_dir_empty($repository)) {return false;} if (!function_exists('tile2long')) { function tile2long( $x, $z) { $n = pow(2, $z); return $x / $n * 360.0 - 180.0; } } if (!function_exists('tile2lat')) { function tile2lat( $y, $z) { $n = pow(2, $z); return rad2deg(atan(sinh(pi() * (1 - 2 * $y / $n)))); } } if (!function_exists('low_high_dir')) { function low_high_dir ($path, $low = true) { $dh = @opendir($path); if ($dh === false) { return ($low) ? 99999 : 0; } // guard against missing dir if ($low) { // find min $return = 99999; // starter - see below while (false !== ($filename = readdir($dh)) ) { if ( intval($filename) > 0 && intval ($filename) < intval ($return ) ) { $return = $filename ; // retain extension if file } } // end while () } else { //find max $return = 0; // starter - see below while (false !== ($filename = readdir($dh)) ) { if ( intval($filename) > 0 && intval ($filename) > intval ($return ) ) { $return = $filename ; } } // end while () } // end else closedir($dh); return $return; } // end function } // 1. compute zoom $dir = $repository; $dh = @opendir($dir); if ($dh === false) { return false; } // guard against missing dir $zoom = 99; // starter - see below while (false !== ($filename = readdir($dh)) ) { if ( is_numeric ($filename ) && intval ($filename) < intval ($zoom ) ) { $zoom = intval ($filename) ; } } // end while () closedir($dh); if ($zoom === 99) { return false; } // no zoom directories found // 2. compute west and east longs $west = 99999; // set extremes $east = 0; $path = "{$dir}/{$zoom}"; $dh = @opendir($path); if ($dh === false) { return false; } // guard against missing zoom dir while (false !== ($filename = readdir($dh) ) ) { // walk down the selected zoom directory if (is_numeric ($filename) ) { if ( intval($filename ) < intval ($west) ) {$west = $filename;} // min if ( intval($filename ) > intval ($east) ) {$east = $filename;} // max } // end if (is_numeric () ) } // end while () closedir($dh); // 3. compute northwest tile - OK $path = "{$dir}/{$zoom}/{$west}"; $northwest = low_high_dir ($path, $low = true) ; // 4. compute southeast tile $path = "{$dir}/{$zoom}/{$east}"; $southeast = low_high_dir ($path, $low = false) ; $west_long = round (tile2long( $west, $zoom), 6) ; $north_lat = round (tile2lat( intval($northwest), $zoom), 6); $east_long = round (tile2long( $east + 1, $zoom), 6); // note + 1 $south_lat = round (tile2lat( intval($southeast) + 1, $zoom), 6); // note + 1 return array($west_long, $north_lat, $east_long, $south_lat ); } // end function scan_tile_bounds /** * Recalculate tile bounds from the filesystem and cache the result in the * database 'bounds' setting. Call this after tiles are added or removed. 3/14/26 */ function recalculate_tile_bounds ($repository) { $bounds = scan_tile_bounds($repository); if ($bounds === false) { // No tiles — clear the cached bounds $query = "UPDATE `{$GLOBALS['mysql_prefix']}settings` SET `value`= '' WHERE `name` = 'bounds'"; db_query($query); return false; } // Store as "south,west,north,east" (bl_lat,bl_lon,tr_lat,tr_lon) $boundsString = $bounds[3] . "," . $bounds[0] . "," . $bounds[1] . "," . $bounds[2]; $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}settings` WHERE `name`= 'bounds' LIMIT 1"; $result = db_query($query); if ($result && $result->num_rows > 0) { $query2 = "UPDATE `{$GLOBALS['mysql_prefix']}settings` SET `value`= ? WHERE `name` = 'bounds'"; db_query($query2, [$boundsString]); } return $bounds; } // end function recalculate_tile_bounds function checkColExists($table, $col) { $safe_table = preg_replace('/[^a-zA-Z0-9_]/', '', $table); $safe_col = preg_replace('/[^a-zA-Z0-9_]/', '', $col); $query = "SHOW COLUMNS FROM `{$GLOBALS['mysql_prefix']}{$safe_table}` LIKE '{$safe_col}'"; $result = db_query($query); if($result) { return true; } else { return false; } } function get_standard_messages() { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}std_msgs` ORDER BY `id` ASC"; $result = db_query($query); while ($row = stripslashes_deep($result->fetch_assoc())) { $ret_arr[$row['id']]['id'] = $row['id']; $ret_arr[$row['id']]['name'] = $row['name']; $ret_arr[$row['id']]['message'] = $row['message']; } return $ret_arr; } function get_standard_messages_sel() { $sms_provider = get_msg_variable('smsg_provider'); $count = 0; switch($sms_provider) { case "0": $chosen = ""; break; case "1": $chosen = "OR `smsresponder` = 1"; break; case "2": $chosen = "OR `txtlocal` = 1"; break; case "3": $chosen = "OR `mototrbo` = 1"; break; case "4": $chosen = "OR `smsbroadcast` = 1"; break; default: $chosen = ""; } $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}std_msgs` WHERE `email` = 1 {$chosen} ORDER BY `groupby`, `id` ASC"; $result = db_query($query); $ret = ""; $the_grp = ""; while ($row = stripslashes_deep($result->fetch_array())) { if ($the_grp != $row['groupby']) { if($the_grp != "") {$ret .= "";} $the_grp = $row['groupby']; $ret .= "\n"; } $ret .= "\t\n"; } // end while() $ret .= "\n\n"; return $ret; } function multi_array_key_exists($key, $array) { if (array_key_exists($key, $array)) { return true; } else { foreach ($array as $nested) { if (is_array($nested) && multi_array_key_exists($key, $nested)) { return true; } } } return false; } /* function valid_status($id) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}un_status` WHERE `id` = " . $id; $result = db_query($query); if($result->num_rows > 0) { return true; } else { return false; } } function valid_fac_status($id) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}fac_status` WHERE `id` = ?"; $result = db_query($query, [$id]); if($result->num_rows > 0) { return true; } else { return false; } } */ function get_roster($current=null) { // 9/6/13 $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}personnel` ORDER BY `person_identifier`"; $result = db_query($query); $the_ret = ""; return $the_ret; } function get_user_details($rosterID) { // 9/6/13 $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}personnel` WHERE `id` = ? LIMIT 1"; $result = db_query($query, [$rosterID]); if($result->num_rows != 0) { $row = stripslashes_deep($result->fetch_assoc()); $the_ret = "Name: " . $row['forenames'] . " " . $row['surname'] . "
"; $the_ret .= "Street: " . $row['address'] . "
"; $the_ret .= "State: " . $row['state'] . "
"; $the_ret .= "Email: " . $row['email'] . "
"; $the_ret .= "Home phone: " . $row['homephone'] . "
"; $the_ret .= "Work Phone: " . $row['workphone'] . "
"; $the_ret .= "Cellphone: " . $row['cellphone'] . "
"; } else { $the_ret = "N/A"; } return $the_ret; } function get_teamname($id) { $query = "SELECT `name` FROM `{$GLOBALS['mysql_prefix']}team` WHERE `id` = ? LIMIT 1"; $result = db_query($query, [$id]); $row = stripslashes_deep($result->fetch_assoc()); return ($result->num_rows==0 )? "Error?" : $row['name']; } function get_member_assigned($id, $responder) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}responder_x_member` WHERE `member_id` = ? AND `responder_id` = ? LIMIT 1"; $result = db_query($query, [$id, $responder]); if($result->num_rows == 1) { return 1; } else { return 0; } } function get_member_assigned_other($id, $responder) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}responder_x_member` WHERE `member_id` = ? AND `responder_id` <> ? LIMIT 1"; $result = db_query($query, [$id, $responder]); if($result) { return $result->num_rows; } else { return 0; } } function get_member_already_assigned($id) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}responder_x_member` WHERE `member_id` = ?"; $result = db_query($query, [$id]); if($result) { return $result->num_rows; } else { return 0; } } function get_member_assigned_addons($id, $responder) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}responder_x_member` WHERE `member_id` = ? AND `responder_id` = ? LIMIT 1"; $result = db_query($query, [$id, $responder]); $row = stripslashes_deep($result->fetch_assoc()); return $row; } function get_responder_members($id) { $output = "
"; if($id == null) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}member`"; $result = db_query($query); while($row = stripslashes_deep($result->fetch_assoc())) { $theFlag = (get_member_already_assigned($row['id']) > 0) ? "background-color: red; color: white;'" : ""; $output .= "" . get_member_name($row['id'], true) . "  "; $output .= "E"; $output .= "C"; $output .= "H"; $output .= "W"; $output .= "S
"; } } else { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}member` ORDER BY `field1` ASC, `field2` ASC"; $result = db_query($query); while ($row = stripslashes_deep($result->fetch_assoc())) { $theFlag = (get_member_assigned_other($row['id'], $id) > 0) ? "background-color: red; color: white;'" : ""; if(get_member_assigned($row['id'], $id) == 1) { $chkd_arr = get_member_assigned_addons($row['id'], $id); $chkd_email = ($chkd_arr['use_email'] == 1) ? "CHECKED" : ""; $chkd_cell = ($chkd_arr['use_cellphone'] == 1) ? "CHECKED" : ""; $chkd_homephone = ($chkd_arr['use_homephone'] == 1) ? "CHECKED" : ""; $chkd_workphone = ($chkd_arr['use_workphone'] == 1) ? "CHECKED" : ""; $chkd_smsgid = ($chkd_arr['use_smsg_id'] == 1) ? "CHECKED" : ""; $output .= "" . get_member_name($row['id'], true) . "  "; $output .= "E"; $output .= "C"; $output .= "H"; $output .= "W"; $output .= "S
"; } else { $output .= "" . get_member_name($row['id'], true) . "  "; $output .= "E"; $output .= "C"; $output .= "H"; $output .= "W"; $output .= "S
"; } } } $output .= "
"; return $output; } function get_member_contact_details($id) { $ret_arr = array(); $query = "SELECT `field1`, `field2`, `field24`, `field25`, `field26` FROM `{$GLOBALS['mysql_prefix']}member` WHERE `id` = ? LIMIT 1"; $result = db_query($query, [$id]); $row = stripslashes_deep($result->fetch_assoc()); foreach($row as $key => $val) { $fieldid = substr($key, 5); $fieldname = get_fieldlabel($fieldid); $ret_arr[$fieldname] = $val; } return $ret_arr; } function get_member_full_details($id) { $ret_arr = array(); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}member` WHERE `id` = ? LIMIT 1"; $result = db_query($query, [$id]); $row = stripslashes_deep($result->fetch_assoc()); foreach($row as $key => $val) { if($key != "_on" && $key != "_by" && $key != "_from" && $key != "id") { $fieldid = substr($key, 5); $fieldname = get_fieldlabel($fieldid); if($fieldname == "Team") { $ret_arr[$fieldname] = get_teamname($val); } elseif($fieldname == "Member Status") { $ret_arr[$fieldname] = get_status_name($id); } elseif($fieldname == "Picture") { if($val != "") { $ret_arr[$fieldname] = ""; } else { $ret_arr[$fieldname] = ""; } } else { $ret_arr[$fieldname] = $val; } } } return $ret_arr; } function get_mdb_email($id) { if(!get_mdb_variable('use_mdb_contact')) {return "";} $theReturn = false; $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}responder_x_member` WHERE `responder_id` = ? AND `use_email` = 1 LIMIT 1"; $result = db_query($query, [$id]); if($result && $result->num_rows > 0) { $row = stripslashes_deep($result->fetch_assoc()); $memberid = $row['member_id']; $field = preg_replace('/[^a-zA-Z0-9_]/', '', get_mdb_variable('mdb_contact_via_field')); $query2 = "SELECT `" . $field . "` FROM `{$GLOBALS['mysql_prefix']}member` WHERE `id` = ?"; $result2 = db_query($query2, [$memberid]); if($result2 && $result2->num_rows > 0) { $row2 = stripslashes_deep($result2->fetch_assoc()); if($row2[$field] != "") { $theReturn = $row2[$field]; } } } return $theReturn; } function get_contact_via($id) { global $useMdb, $useMdbContact; if($useMdb == "1" && $useMdbContact == "1") { $ret_arr = array(); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}responder_x_member` WHERE `responder_id` = ? AND `use_email` = 1"; $result = db_query($query, [$id]); if($result && $result->num_rows > 0) { // member(s) assigned to responder - use member details while($row = stripslashes_deep($result->fetch_assoc())) { $memberid = $row['member_id']; $field = get_mdb_variable('mdb_contact_via_field'); $query2 = "SELECT `" . preg_replace('/[^a-zA-Z0-9_]/', '', $field) . "` FROM `{$GLOBALS['mysql_prefix']}member` WHERE `id` = ?"; $result2 = db_query($query2, [$memberid]); if($result2 && $result2->num_rows > 0) { $row2 = stripslashes_deep($result2->fetch_assoc()); if($row2[$field] != "") { $ret_arr[] = $row2[$field]; } } } } else { // No member assigned, use information from responder table $query = "SELECT `contact_via` FROM `{$GLOBALS['mysql_prefix']}responder` WHERE `id` = ?"; $result = db_query($query, [$id]); if($result) { $row = stripslashes_deep($result->fetch_assoc()); $ret_arr[] = $row['contact_via']; } else { $ret_arr = ""; } } } else { $query = "SELECT `contact_via` FROM `{$GLOBALS['mysql_prefix']}responder` WHERE `id` = ?"; $result = db_query($query, [$id]); if($result) { $row = stripslashes_deep($result->fetch_assoc()); $temp = (strpos($row['contact_via'], "|")) ? explode(" | ", $row['contact_via']) : $row['contact_via']; if(is_array($temp)) { $ret_arr = $temp; } else { $ret_arr[] = $temp; } } else { $ret_arr = ""; } } return $ret_arr; } function get_smsgid($id) { global $useMdb, $useMdbContact; if($useMdb == "1" && $useMdbContact == "1") { $ret_arr = array(); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}responder_x_member` WHERE `responder_id` = ? AND `use_smsg_id` = 1"; $result = db_query($query, [$id]); if($result && $result->num_rows > 0) { // member(s) assigned to responder - use member details while($row = stripslashes_deep($result->fetch_assoc())) { $memberid = $row['member_id']; $field = get_mdb_variable('mdb_smsg_id_field'); $query2 = "SELECT `" . preg_replace('/[^a-zA-Z0-9_]/', '', $field) . "` FROM `{$GLOBALS['mysql_prefix']}member` WHERE `id` = ?"; $result2 = db_query($query2, [$memberid]); if($result2 && $result2->num_rows > 0) { $row2 = stripslashes_deep($result2->fetch_assoc()); if($row2[$field] != "") { $ret_arr[] = $row2[$field]; } } } } else { // No member assigned, use information from responder table $query = "SELECT `smsg_id` FROM `{$GLOBALS['mysql_prefix']}responder` WHERE `id` = ?"; $result = db_query($query, [$id]); $row = stripslashes_deep($result->fetch_assoc()); $ret_arr[] = $row['smsg_id']; } } else { $query = "SELECT `smsg_id` FROM `{$GLOBALS['mysql_prefix']}responder` WHERE `id` = ?"; $result = db_query($query, [$id]); $row = stripslashes_deep($result->fetch_assoc()); $ret_arr[] = $row['smsg_id']; $temp = (strpos($row['smsg_id'], "|")) ? explode(" | ", $row['smsg_id']) : $row['smsg_id']; if(is_array($temp)) { $ret_arr = $temp; } else { $ret_arr[] = $temp; } } return $ret_arr; } function get_member_count($id) { if(get_variable('use_mdb') == "0") {return 0;} $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}responder_x_member` WHERE `responder_id` = ?"; $result = db_query($query, [$id]); if($result) {return $result->num_rows;} else {return 0;} } function get_mdb_names($id) { global $useMdb, $useMdbContact; if($useMdb == "1" && $useMdbContact == "1") { $ret_arr = array(); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}responder_x_member` WHERE `responder_id` = ?"; $result = db_query($query, [$id]); if($result && $result->num_rows > 0) { // member(s) assigned to responder - use member details while($row = stripslashes_deep($result->fetch_assoc())) { $memberid = $row['member_id']; $query2 = "SELECT `field1`, `field2` FROM `{$GLOBALS['mysql_prefix']}member` WHERE `id` = ?"; $result2 = db_query($query2, [$memberid]); if($result2 && $result2->num_rows > 0) { $row2 = stripslashes_deep($result2->fetch_assoc()); if($row2['field1'] != "" && $row2['field2']) { $ret_arr[] = $row2['field2'] . " " . $row2['field1']; } } } } else { // No member assigned, use information from responder table $query = "SELECT `name` FROM `{$GLOBALS['mysql_prefix']}responder` WHERE `id` = ?"; $result = db_query($query, [$id]); $row = stripslashes_deep($result->fetch_assoc()); $temp = explode('/', $row['name']); $ret_arr[] = $temp[0]; } } else { $query = "SELECT `name` FROM `{$GLOBALS['mysql_prefix']}responder` WHERE `id` = ?"; $result = db_query($query, [$id]); $row = stripslashes_deep($result->fetch_assoc()); $temp1 = explode(',', $row['name']); if(is_array($temp1)) { foreach($temp1 as $val) { $temp2 = explode("/", $val); $ret_arr[] = $temp2[0]; } } else { $temp2 = explode("/", $temp1); $ret_arr[] = $temp2[0]; } } return $ret_arr; } function get_mdb_cell($id) { global $useMdb, $useMdbContact; if($useMdb == "1" && $useMdbContact == "1") { $ret_arr = array(); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}responder_x_member` WHERE `responder_id` = ? AND `use_smsg_id` = 1"; $result = db_query($query, [$id]); if($result && $result->num_rows > 0) { // member(s) assigned to responder - use member details while($row = stripslashes_deep($result->fetch_assoc())) { $memberid = $row['member_id']; $field = get_mdb_variable('mdb_cellphone_field'); $query2 = "SELECT `" . preg_replace('/[^a-zA-Z0-9_]/', '', $field) . "` FROM `{$GLOBALS['mysql_prefix']}member` WHERE `id` = ?"; $result2 = db_query($query2, [$memberid]); if($result2 && $result2->num_rows > 0) { $row2 = stripslashes_deep($result2->fetch_assoc()); if($row2[$field] != "") { $ret_arr[] = $row2[$field]; } } } } else { // No member assigned, use information from responder table $query = "SELECT `cellphone` FROM `{$GLOBALS['mysql_prefix']}responder` WHERE `id` = ?"; $result = db_query($query, [$id]); $row = stripslashes_deep($result->fetch_assoc()); $temp = explode(',', $row['cellphone']); foreach($temp as $val) { $ret_arr[] = $val; } } } else { $query = "SELECT `cellphone` FROM `{$GLOBALS['mysql_prefix']}responder` WHERE `id` = ?"; $result = db_query($query, [$id]); $row = stripslashes_deep($result->fetch_assoc()); $temp = explode(',', $row['cellphone']); foreach($temp as $val) { $ret_arr[] = $val; } } return $ret_arr; } function get_mdb_phone($id) { if(!get_mdb_variable('use_mdb_contact')) {return "";} global $useMdb, $useMdbContact; if($useMdb == "1" && $useMdbContact == "1") { $ret_arr = array(); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}responder_x_member` WHERE `responder_id` = ? AND `use_smsg_id` = 1"; $result = db_query($query, [$id]); if($result && $result->num_rows > 0) { // member(s) assigned to responder - use member details while($row = stripslashes_deep($result->fetch_assoc())) { $memberid = $row['member_id']; $field = get_mdb_variable('mdb_homephone_field'); $query2 = "SELECT `" . preg_replace('/[^a-zA-Z0-9_]/', '', $field) . "` FROM `{$GLOBALS['mysql_prefix']}member` WHERE `id` = ?"; $result2 = db_query($query2, [$memberid]); if($result2 && $result2->num_rows > 0) { $row2 = stripslashes_deep($result2->fetch_assoc()); if($row2[$field] != "") { $ret_arr[] = $row2[$field]; } } } } else { // No member assigned, use information from responder table $query = "SELECT `phone` FROM `{$GLOBALS['mysql_prefix']}responder` WHERE `id` = ?"; $result = db_query($query, [$id]); $row = stripslashes_deep($result->fetch_assoc()); $temp = explode(',', $row['phone']); foreach($temp as $val) { $ret_arr[] = $val; } } } else { $query = "SELECT `phone` FROM `{$GLOBALS['mysql_prefix']}responder` WHERE `id` = ?"; $result = db_query($query, [$id]); $row = stripslashes_deep($result->fetch_assoc()); $temp = explode(',', $row['phone']); if(is_array($temp)) { $ret_arr = $temp; } else { $ret_arr[] = $temp; } } return $ret_arr; } function get_members($id = null) { if(!get_mdb_variable('use_mdb_contact')) {return "";} global $useMdb, $useMdbContact; if($useMdb == "1" && $useMdbContact == "1" && $id != null) { $ret_arr = array(); $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}responder_x_member` WHERE `responder_id` = ? AND `use_smsg_id` = 1"; $result = db_query($query, [$id]); if($result && $result->num_rows > 0) { // member(s) assigned to responder - use member details while($row = stripslashes_deep($result->fetch_assoc())) { $memberid = $row['member_id']; $field = get_mdb_variable('mdb_smsg_id_field'); $query2 = "SELECT `" . preg_replace('/[^a-zA-Z0-9_]/', '', $field) . "` FROM `{$GLOBALS['mysql_prefix']}member` WHERE `id` = ?"; $result2 = db_query($query2, [$memberid]); if($result2 && $result2->num_rows > 0) { $row2 = stripslashes_deep($result2->fetch_assoc()); if($row2[$field] != "") { $ret_arr[] = $row2[$field]; } } } } else { // No member assigned, use information from responder table $query = "SELECT `smsg_id` FROM `{$GLOBALS['mysql_prefix']}responder` WHERE `id` = ?"; $result = db_query($query, [$id]); $row = stripslashes_deep($result->fetch_assoc()); $ret_arr[] = $row['smsg_id']; } } else { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}members`"; $result = db_query($query); while($row = stripslashes_deep($result->fetch_assoc())) { print "
" . get_member_name($row['id']) . "  
"; } } } function get_roadcondition_types() { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}conditions` ORDER BY `id`"; $result = db_query($query); if($result && $result->num_rows > 0) { return $result->num_rows; } else { return 0; } } function get_tickets_status_select($selectname, $selected=null) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}un_status`"; $result = $result = db_query($query); if($result->num_rows > 0) { $output = ""; } else { $output = "ERROR"; } return $output; } function get_mdb_status_select($selectname, $selected=null) { $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}member_status`"; $result = $result = db_query($query); if($result->num_rows > 0) { $output = ""; } else { $output = "ERROR"; } return $output; } if(checkColExists('std_msgs', 'name')) {$std_messages = get_standard_messages();} ?>