function show_ticket($id, $print = 'false', $search = FALSE)
{
    /* show specified ticket */
    global $iw_width, $istest, $zoom_tight, $nature, $disposition, $patient, $incident, $incidents, $col_width;
    // 12/3/10, 8/4/11
    $tickno = get_variable('serial_no_ap') == 0 ? "&nbsp;&nbsp;<I>(#{$id})</I>" : "";
    // 1/25/09, 2/18/12
    if ($istest) {
        print "GET<br />\n";
        dump($_GET);
        print "POST<br />\n";
        dump($_POST);
    }
    if ($id == '' or $id <= 0 or !check_for_rows("SELECT * FROM `{$GLOBALS['mysql_prefix']}ticket` WHERE id='{$id}'")) {
        /* sanity check */
        print "Invalid Ticket ID: '{$id}'<BR />";
        return;
    }
    //	Regions stuff	6/10/11
    function get_buttons($user_id)
    {
        //	5/3/11
        $regs_viewed = "";
        if (isset($_SESSION['viewed_groups'])) {
            $regs_viewed = explode(",", $_SESSION['viewed_groups']);
        }
        $query2 = "SELECT * FROM `{$GLOBALS['mysql_prefix']}allocates` WHERE `type`= 4 AND `resource_id` = '{$user_id}' ORDER BY `group`";
        //	5/3/11
        $result2 = mysql_query($query2) or do_error($query2, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
        $al_buttons = "";
        while ($row2 = stripslashes_deep(mysql_fetch_assoc($result2))) {
            //	5/3/11
            if (!empty($regs_viewed)) {
                if (in_array($row2['group'], $regs_viewed)) {
                    $al_buttons .= "<DIV style='display: block;'><INPUT TYPE='checkbox' CHECKED name='frm_group[]' VALUE='{$row2['group']}'></INPUT>" . get_groupname($row2['group']) . "&nbsp;&nbsp;</DIV>";
                } else {
                    $al_buttons .= "<DIV style='display: block;'><INPUT TYPE='checkbox' name='frm_group[]' VALUE='{$row2['group']}'></INPUT>" . get_groupname($row2['group']) . "&nbsp;&nbsp;</DIV>";
                }
            } else {
                $al_buttons .= "<DIV style='display: block;'><INPUT TYPE='checkbox' CHECKED name='frm_group[]' VALUE='{$row2['group']}'></INPUT>" . get_groupname($row2['group']) . "&nbsp;&nbsp;</DIV>";
            }
        }
        //		dump($al_buttons);
        return $al_buttons;
    }
    if (get_num_groups() && COUNT(get_allocates(4, $_SESSION['user_id'])) > 1) {
        //	6/10/11
        ?>
<SCRIPT>
		side_bar_html= "";
		side_bar_html+="<TABLE><TR class='even'><TD COLSPAN=99 CLASS='td_label' ><form name='region_form' METHOD='post' action='main.php'><DIV>";
		side_bar_html += "<?php 
        print get_buttons($_SESSION['user_id']);
        ?>
";
		side_bar_html+="</DIV></form></TD></TR><TR><TD>&nbsp;</TD></TR><TR><TD ALIGN='center'><INPUT TYPE='button' VALUE='Update' onClick='form_validate(document.region_form);'></TD></TR></TABLE>";
		if($("region_boxes")) {
			$("region_boxes").innerHTML = side_bar_html;
		}
</SCRIPT>		
<?php 
    }
    //	End of Regions stuff
    $restrict_ticket = get_variable('restrict_user_tickets') == 1 && !is_administrator() ? " AND owner={$_SESSION['user_id']}" : "";
    // 1/7/10
    $query = "SELECT *,\n\t\t`problemstart` AS `my_start`,\n\t\tFROM_UNIXTIME(UNIX_TIMESTAMP(problemstart)) AS `test`,\n\t\tUNIX_TIMESTAMP(problemstart) AS problemstart,\n\t\tUNIX_TIMESTAMP(problemend) AS problemend,\n\t\tUNIX_TIMESTAMP(date) AS date,\n\t\tUNIX_TIMESTAMP(booked_date) AS booked_date,\t\t\n\t\tUNIX_TIMESTAMP(`{$GLOBALS['mysql_prefix']}ticket`.`updated`) AS updated,\t\t\n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`description` AS `tick_descr`,\n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`street` AS `tick_street`,\n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`city` AS `tick_city`,\n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`state` AS `tick_state`,\t\t\n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`lat` AS `lat`,\t\t\n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`lng` AS `lng`,\n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`_by` AS `call_taker`,\n\t\t`{$GLOBALS['mysql_prefix']}facilities`.`name` AS `fac_name`,\t\t\n\t\t`rf`.`name` AS `rec_fac_name`,\n\t\t`{$GLOBALS['mysql_prefix']}facilities`.`lat` AS `fac_lat`,\t\t\n\t\t`{$GLOBALS['mysql_prefix']}facilities`.`lng` AS `fac_lng`,\t\t \n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`id` AS `tick_id`\n\t\tFROM `{$GLOBALS['mysql_prefix']}ticket` \n\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}in_types` `ty` ON (`{$GLOBALS['mysql_prefix']}ticket`.`in_types_id` = `ty`.`id`)\t\n\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}facilities` ON `{$GLOBALS['mysql_prefix']}facilities`.id = `{$GLOBALS['mysql_prefix']}ticket`.facility \n\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}facilities` rf ON `rf`.id = `{$GLOBALS['mysql_prefix']}ticket`.rec_facility \n\t\tWHERE `{$GLOBALS['mysql_prefix']}ticket`.`ID`= {$id} {$restrict_ticket}";
    // 7/16/09, 8/12/09
    $result = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
    if (!mysql_num_rows($result)) {
        //no tickets? print "error" or "restricted user rights"
        print "<FONT CLASS=\"warn\">Internal error " . basename(__FILE__) . "/" . __LINE__ . ".  Notify developers of this message.</FONT>";
        // 8/18/09
        exit;
    }
    $row = stripslashes_deep(mysql_fetch_array($result));
    $locale = get_variable('locale');
    // 10/29/09
    switch ($locale) {
        case "0":
            $grid_type = "&nbsp;&nbsp;&nbsp;&nbsp;USNG&nbsp;&nbsp;" . LLtoUSNG($row['lat'], $row['lng']);
            break;
        case "1":
            $grid_type = "&nbsp;&nbsp;&nbsp;&nbsp;OSGB&nbsp;&nbsp;" . LLtoOSGB($row['lat'], $row['lng']);
            // 8/23/08, 10/15/08, 8/3/09
            break;
        case "2":
            $coords = $row['lat'] . "," . $row['lng'];
            // 8/12/09
            $grid_type = "&nbsp;&nbsp;&nbsp;&nbsp;UTM&nbsp;&nbsp;" . toUTM($coords);
            // 8/23/08, 10/15/08, 8/3/09
            break;
        default:
            print "ERROR in " . basename(__FILE__) . " " . __LINE__ . "<BR />";
    }
    if ($print == 'true') {
        // 1/7/10
        print "<TABLE BORDER='0'ID='left' width='800px'>\n";
        //
        print "<TR CLASS='print_TD'><TD ALIGN='left' CLASS='td_data' COLSPAN=2 ALIGN='center'><B>{$incident}: <I>" . $row['scope'] . "</B>" . $tickno . "</TD></TR>\n";
        print "<TR CLASS='print_TD' ><TD ALIGN='left'>" . get_text("Priority") . ":</TD> \n\t\t\t\t\t<TD ALIGN='left'>" . get_severity($row['severity']);
        print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$nature}:&nbsp;&nbsp;" . get_type($row['in_types_id']);
        print "</TD></TR>\n";
        print "<TR CLASS='print_TD' ><TD ALIGN='left'>" . get_text("Protocol") . ":</TD> <TD ALIGN='left'>{$row['protocol']}</TD></TR>\n";
        // 7/16/09
        print "<TR CLASS='print_TD' ><TD ALIGN='left'>" . get_text("Addr") . ":</TD>\t\n\t\t\t\t<TD ALIGN='left'>" . $row['tick_street'] . "</TD></TR>\n";
        print "<TR CLASS='print_TD' ><TD ALIGN='left'>" . get_text("City") . ":</TD>\t\t\n\t\t\t\t<TD ALIGN='left'>" . $row['tick_city'];
        print "&nbsp;&nbsp;" . $row['tick_state'] . "</TD></TR>\n";
        print "<TR CLASS='print_TD'  VALIGN='top'><TD ALIGN='left'>" . get_text("Synopsis") . ":</TD>\n\t\t\t\t<TD ALIGN='left'>" . nl2br($row['tick_descr']) . "</TD></TR>\n";
        //	8/12/09
        print "<TR CLASS='print_TD'  VALIGN='top'><TD ALIGN='left'>" . get_text("911 Contacted") . ":</TD>\n\t\t\t\t<TD ALIGN='left'>" . nl2br($row['nine_one_one']) . "</TD></TR>\n";
        //	8/12/09
        $end_date = intval($row['problemend']) > 1 ? $row['problemend'] : time() - intval(get_variable('delta_mins')) * 60;
        $elapsed = my_date_diff($end_date, $end_date);
        print "<TR CLASS='print_TD'><TD ALIGN='left'>" . get_text("Status") . ":</TD>\t\n\t\t\t\t<TD ALIGN='left'>" . get_status($row['status']) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$elapsed}</TD></TR>\n";
        print "<TR CLASS='print_TD'><TD ALIGN='left'>" . get_text("Reported by") . ":</TD>\n\t\t\t\t<TD ALIGN='left'>" . $row['contact'] . "</TD></TR>\n";
        print "<TR CLASS='print_TD' ><TD ALIGN='left'>" . get_text("Phone") . ":</TD>\t\t\n\t\t\t\t<TD ALIGN='left'>" . format_phone($row['phone']) . "</TD></TR>\n";
        $by_str = $row['call_taker'] == 0 ? "" : "&nbsp;&nbsp;by " . get_owner($row['call_taker']) . "&nbsp;&nbsp;";
        // 1/7/10
        print "<TR CLASS='print_TD'><TD ALIGN='left'>" . get_text("Written") . ":</TD>\t\n\t\t\t\t<TD ALIGN='left'>" . format_date($row['date']) . $by_str;
        print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Updated:&nbsp;&nbsp;" . format_date($row['updated']) . "</TD></TR>\n";
        print empty($row['booked_date']) ? "" : "<TR CLASS='print_TD'><TD ALIGN='left'>Scheduled date:</TD>\t\n\t\t\t\t<TD ALIGN='left'>" . format_date($row['booked_date']) . "</TD></TR>\n";
        // 10/6/09
        print "<TR CLASS='print_TD' ><TD ALIGN='left' COLSPAN='2'>&nbsp;\n\t\t\t\t<TD ALIGN='left'></TR>\n";
        // separator
        print empty($row['fac_name']) ? "" : "<TR CLASS='print_TD' ><TD ALIGN='left'>{$incident} at Facility:</TD>\t\n\t\t\t\t<TD ALIGN='left'>" . $row['fac_name'] . "</TD></TR>\n";
        // 8/1/09, 3/27/10
        print empty($row['rec_fac_name']) ? "" : "<TR CLASS='print_TD' ><TD ALIGN='left'>Receiving Facility:</TD>\t\n\t\t\t\t<TD ALIGN='left'>" . $row['rec_fac_name'] . "</TD></TR>\n";
        // 10/6/09
        print empty($row['comments']) ? "" : "<TR CLASS='print_TD'  VALIGN='top'><TD ALIGN='left'>{$disposition}:</TD>\n\t\t\t\t<TD ALIGN='left'>" . replace_quotes(nl2br($row['comments'])) . "</TD></TR>\n";
        print "<TR CLASS='print_TD' ><TD ALIGN='left'>" . get_text("Run Start") . ":</TD>\t\t\t\t\n\t\t\t\t<TD ALIGN='left'>" . format_date($row['problemstart']);
        $elapsed_str = !empty($closed) ? $elapsed : "";
        print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End:&nbsp;&nbsp;" . format_date($row['problemend']) . "&nbsp;&nbsp;{$elapsed_str}</TD></TR>\n";
        $locale = get_variable('locale');
        // 08/03/09
        switch ($locale) {
            case "0":
                $grid_type = "&nbsp;&nbsp;&nbsp;&nbsp;USNG&nbsp;&nbsp;" . LLtoUSNG($row['lat'], $row['lng']);
                break;
            case "1":
                $grid_type = "&nbsp;&nbsp;&nbsp;&nbsp;OSGB&nbsp;&nbsp;" . LLtoOSGB($row['lat'], $row['lng']);
                // 8/23/08, 10/15/08, 8/3/09
                break;
            case "2":
                $coords = $row['lat'] . "," . $row['lng'];
                // 8/12/09
                $grid_type = "&nbsp;&nbsp;&nbsp;&nbsp;UTM&nbsp;&nbsp;" . toUTM($coords);
                // 8/23/08, 10/15/08, 8/3/09
                break;
            default:
                print "ERROR in " . basename(__FILE__) . " " . __LINE__ . "<BR />";
        }
        print "<TR CLASS='print_TD'><TD ALIGN='left' >" . get_text("Position") . ": </TD>\t\t\n\t\t\t\t<TD ALIGN='left'>" . get_lat($row['lat']) . "&nbsp;&nbsp;&nbsp;" . get_lng($row['lng']) . $grid_type . "</TD></TR>\n";
        // 9/13/08
        print "<TR><TD colspan=2 ALIGN='left'>";
        print show_log($row[0]);
        // log
        print "</TD></TR>";
        print "<TR STYLE = 'display:none;'><TD colspan=2><SPAN ID='oldlat'>" . $row['lat'] . "</SPAN><SPAN ID='oldlng'>" . $row['lng'] . "</SPAN></TD></TR>";
        print "</TABLE>\n";
        print show_actions($row['tick_id'], "date", FALSE, FALSE);
        // lists actions and patient data, print - 10/30/09
        // =============== 10/30/09
        function my_to_date($in_date)
        {
            // date_time format to user's spec
            //			$temp = mktime(substr($in_date,11,2),substr($in_date,14,2),substr($in_date,17,2),substr($in_date,5,2),substr($in_date,8,2),substr($in_date,0,4));
            $temp = mysql2timestamp($d1);
            // 9/29/10
            return good_date_time($in_date) ? date(get_variable("date_format"), $temp) : "";
            //
        }
        /*
        		$query = "SELECT * FROM `$GLOBALS[mysql_prefix]assigns` WHERE `facility_id` IS NOT NULL LIMIT 1";
        		$result_temp = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
        		$facilities = mysql_affected_rows()>0;		// set boolean in order to avoid waste space
        
        		$query = "SELECT * FROM `$GLOBALS[mysql_prefix]assigns` WHERE `start_miles` IS NOT NULL  LIMIT 1";
        		$result_temp = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
        		$miles = mysql_affected_rows()>0;		// set boolean in order to avoid waste space
        		unset($result_temp);
        
        		$query = "SELECT *,
        		UNIX_TIMESTAMP(as_of) AS as_of,
        		`$GLOBALS[mysql_prefix]assigns`.`id` AS `assign_id` ,
        		`$GLOBALS[mysql_prefix]assigns`.`comments` AS `assign_comments`,
        		`u`.`user` AS `theuser`,
        		`t`.`scope` AS `theticket`,
        		`t`.`description` AS `thetickdescr`,
        		`t`.`status` AS `thestatus`,
        		`t`.`_by` AS `call_taker`,
        		`r`.`id` AS `theunitid`,
        		`r`.`name` AS `theunit` ,
        		`f`.`name` AS `thefacility`,
        		`g`.`name` AS `the_rec_facility`,
        		`$GLOBALS[mysql_prefix]assigns`.`as_of` AS `assign_as_of`
        		FROM `$GLOBALS[mysql_prefix]assigns` 
        		LEFT JOIN `$GLOBALS[mysql_prefix]ticket`	 `t` ON (`$GLOBALS[mysql_prefix]assigns`.`ticket_id` = `t`.`id`)
        		LEFT JOIN `$GLOBALS[mysql_prefix]user`		 `u` ON (`$GLOBALS[mysql_prefix]assigns`.`user_id` = `u`.`id`)
        		LEFT JOIN `$GLOBALS[mysql_prefix]responder`	 `r` ON (`$GLOBALS[mysql_prefix]assigns`.`responder_id` = `r`.`id`)
        		LEFT JOIN `$GLOBALS[mysql_prefix]facilities` `f` ON (`$GLOBALS[mysql_prefix]assigns`.`facility_id` = `f`.`id`)
        		LEFT JOIN `$GLOBALS[mysql_prefix]facilities` `g` ON (`$GLOBALS[mysql_prefix]assigns`.`rec_facility_id` = `g`.`id`)
        		WHERE `$GLOBALS[mysql_prefix]assigns`.`ticket_id` = $id
        		ORDER BY `theunit` ASC ";																// 5/25/09, 1/16/08
        
        		$asgn_result = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
        		if (mysql_affected_rows()>0) {
        			print "<P><TABLE  CLASS='print_TD' BORDER = 1 CELLPADDING = 2 STYLE = 'border-collapse: collapse;'>\n";
        			print "<TR><TH>Unit</TH><TH>D</TH><TH>R</TH><TH>E</TH>";
        			print ($facilities)? "<TH>FE</TH><TH>FA</TH>": "";
        			print "<TH>C</TH>";
        			print ($miles)? "<TH>M/S</TH><TH>M/OS/E</TH>": "";
        			print "</TR>";
        			
        			while ( $asgn_row = stripslashes_deep(mysql_fetch_array($asgn_result))){
        				print "<TR>";			
        				print "<TD>" . shorten($asgn_row['theunit'], 24) . "</TD>";
        				print "<TD>" . my_to_date($asgn_row['dispatched']) . "</TD>";
        				print "<TD>" . my_to_date($asgn_row['responding']) . "</TD>";
        				print "<TD>" . my_to_date($asgn_row['on_scene']) . "</TD>";
        				print ($facilities)? "<TD>" . my_to_date($asgn_row['u2fenr']) . "</TD>": "";
        				print ($facilities)? "<TD>" . my_to_date($asgn_row['u2farr']) . "</TD>": "";
        				print "<TD>" . my_to_date($asgn_row['clear']) . "</TD>";
        				print ($miles)? "<TD>" . my_to_date($asgn_row['start_miles']) . "</TD>": "";
        				print ($miles)? "<TD>" . my_to_date($asgn_row['on_scene_miles']) . "</TD>": "";	// 12/9/10
        				print ($miles)? "<TD>" . my_to_date($asgn_row['end_miles']) . "</TD>": "";
        				print "</TR>\n";				
        				}		// end while () $asgn_row = ...
        			print "</TABLE>\n";
        			}				// end if (mysql_affected_rows()>0 
        */
        // ==============
        print "\n</BODY>\n</HTML>";
        return;
    }
    // end if ($print == 'true')
    ?>
	<TABLE BORDER="0" ID = "outer" ALIGN="left">
	<TR VALIGN="top"><TD CLASS="print_TD" ALIGN="left">
<?php 
    print do_ticket($row, $col_width, $search);
    // 2/25/09
    print show_actions($row['id'], "date", FALSE, TRUE);
    /* lists actions and patient data belonging to ticket */
    print "<TD ALIGN='left'>";
    print "<TABLE ID='theMap' BORDER=0><TR CLASS='odd' ><TD  ALIGN='center'>\n\t\t<DIV ID='map' STYLE='WIDTH:" . get_variable('map_width') . "px; HEIGHT: " . get_variable('map_height') . "PX'></DIV>\n\t\t<BR />\n\t\t<SPAN ID='grid_id' onClick='doGrid()'><U>Grid</U></SPAN>\n\t\t<SPAN ID='do_sv' onClick = 'sv_win(document.sv_form)' STYLE = 'margin-left: 20px' ><u>Street view</U></SPAN>";
    print $zoom_tight ? "<SPAN  onClick= 'zoom_in({$row['lat']}, {$row['lng']}, {$zoom_tight});' STYLE = 'margin-left:20px'><U>Zoom</U></SPAN>\n" : "";
    // 3/27/10
    print "</TD></TR>";
    // 11/29/08
    print "<FORM NAME='sv_form' METHOD='post' ACTION=''><INPUT TYPE='hidden' NAME='frm_lat' VALUE=" . $row['lat'] . ">";
    // 2/11/09
    print "<INPUT TYPE='hidden' NAME='frm_lng' VALUE=" . $row['lng'] . "></FORM>";
    print "<TR ID='pointl1' CLASS='print_TD' STYLE = 'display:none;'>\n\t\t<TD ALIGN='center'><B>Range:</B>&nbsp;&nbsp; <SPAN ID='range'></SPAN>&nbsp;&nbsp;<B>Brng</B>:&nbsp;&nbsp;\n\t\t\t<SPAN ID='brng'></SPAN></TD></TR>\n\n\t\t<TR ID='pointl2' CLASS='print_TD' STYLE = 'display:none;'>\n\t\t\t<TD ALIGN='center'><B>Lat:</B>&nbsp;<SPAN ID='newlat'></SPAN>\n\t\t\t&nbsp;<B>Lng:</B>&nbsp;&nbsp; <SPAN ID='newlng'></SPAN>&nbsp;&nbsp;<B>NGS:</B>&nbsp;<SPAN ID = 'newusng'></SPAN></TD></TR>\n\n\t\t<TR><TD ALIGN='center'><BR /><FONT SIZE='-1'>Click map point for distance information.</FONT></TD></TR>\n";
    print "</TABLE>\n";
    print "</TD></TR>";
    print "<TR CLASS='odd' ><TD COLSPAN='2' CLASS='print_TD'>";
    $lat = $row['lat'];
    $lng = $row['lng'];
    print show_actions($row['id'], "date", FALSE, TRUE);
    /* lists actions and patient data belonging to ticket */
    print "</TD></TR>\n";
    //	print "<TR><TD ALIGN='left'>";
    //	print show_log ($id);				// log as a table
    //	print "</TD></TR></TABLE>\n";
    print "</TABLE>\n";
    ?>
	<SCRIPT SRC='../js/usng.js' TYPE='text/javascript'></SCRIPT>
	<SCRIPT SRC="../js/graticule.js" type="text/javascript"></SCRIPT> 
	<SCRIPT>
	function isNull(val) {								// checks var stuff = null;
		return val === null;
		}

	var starting = false;

	function sv_win(theForm) {				// 2/11/09
		if(starting) {return;}				// dbl-click proof
		starting = true;

		var thelat = theForm.frm_lat.value;
		var thelng = theForm.frm_lng.value;
		var url = "street_view.php?thelat=" + thelat + "&thelng=" + thelng;
		newwindow_sl=window.open(url, "sta_log",  "titlebar=no, location=0, resizable=1, scrollbars, height=450,width=640,status=0,toolbar=0,menubar=0,location=0, left=100,top=300,screenX=100,screenY=300");
		if (!(newwindow_sl)) {
			alert ("Street view operation requires popups to be enabled. Please adjust your browser options - or else turn off the Call Board option.");
			return;
			}
		newwindow_sl.focus();
		starting = false;
		}		// end function sv win()

	var the_grid;
	var grid = false;
	function doGrid() {
		if (grid) {
			map.removeOverlay(the_grid);
			grid = false;
			}
		else {
			the_grid = new LatLonGraticule();
			map.addOverlay(the_grid);
			grid = true;
			}
		}

	function zoom_in (in_lat, in_lng, in_zoom) {				// 3/27/10
		map.setCenter(new GLatLng(in_lat, in_lng), in_zoom );
		var marker = new GMarker(map.getCenter());				// marker to map center
		var myIcon = new GIcon();
		myIcon.image = "./markers/sm_red.png";
		map.addOverlay(marker, myIcon);		 
		}				// end function zoom in ()		 		


	String.prototype.trim = function () {				// 9/14/08
		return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
		};

	String.prototype.parseDeg = function() {
		if (!isNaN(this)) return Number(this);								// signed decimal degrees without NSEW

		var degLL = this.replace(/^-/,'').replace(/[NSEW]/i,'');			// strip off any sign or compass dir'n
		var dms = degLL.split(/[^0-9.,]+/);									// split out separate d/m/s
		for (var i in dms) if (dms[i]=='') dms.splice(i,1);					// remove empty elements (see note below)
		switch (dms.length) {												// convert to decimal degrees...
			case 3:															// interpret 3-part result as d/m/s
				var deg = dms[0]/1 + dms[1]/60 + dms[2]/3600; break;
			case 2:															// interpret 2-part result as d/m
				var deg = dms[0]/1 + dms[1]/60; break;
			case 1:															// decimal or non-separated dddmmss
				if (/[NS]/i.test(this)) degLL = '0' + degLL;	// - normalise N/S to 3-digit degrees
				var deg = dms[0].slice(0,3)/1 + dms[0].slice(3,5)/60 + dms[0].slice(5)/3600; break;
			default: return NaN;
			}
		if (/^-/.test(this) || /[WS]/i.test(this)) deg = -deg; // take '-', west and south as -ve
		return deg;
		}
	Number.prototype.toRad = function() {  // convert degrees to radians
		return this * Math.PI / 180;
		}

	Number.prototype.toDeg = function() {  // convert radians to degrees (signed)
		return this * 180 / Math.PI;
		}
	Number.prototype.toBrng = function() {  // convert radians to degrees (as bearing: 0...360)
		return (this.toDeg()+360) % 360;
		}
	function brng(lat1, lon1, lat2, lon2) {
		lat1 = lat1.toRad(); lat2 = lat2.toRad();
		var dLon = (lon2-lon1).toRad();

		var y = Math.sin(dLon) * Math.cos(lat2);
		var x = Math.cos(lat1)*Math.sin(lat2) -
						Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
		return Math.atan2(y, x).toBrng();
		}

	distCosineLaw = function(lat1, lon1, lat2, lon2) {
		var R = 6371; // earth's mean radius in km
		var d = Math.acos(Math.sin(lat1.toRad())*Math.sin(lat2.toRad()) +
				Math.cos(lat1.toRad())*Math.cos(lat2.toRad())*Math.cos((lon2-lon1).toRad())) * R;
		return d;
		}
    var km2feet = 3280.83;
	var thisMarker = false;

	var map;
	var icons=[];						// note globals	- 1/29/09
	icons[<?php 
    print $GLOBALS['SEVERITY_NORMAL'];
    ?>
] = "./our_icons/blue.png";		// normal
	icons[<?php 
    print $GLOBALS['SEVERITY_MEDIUM'];
    ?>
] = "./our_icons/green.png";	// green
	icons[<?php 
    print $GLOBALS['SEVERITY_HIGH'];
    ?>
] =  "./our_icons/red.png";		// red
	icons[<?php 
    print $GLOBALS['SEVERITY_HIGH'];
    ?>
+1] =  "./our_icons/white.png";	// white - not in use

	var baseIcon = new GIcon();
	baseIcon.shadow = "./markers/sm_shadow.png";

	baseIcon.iconSize = new GSize(20, 34);
//	baseIcon.shadowSize = new GSize(37, 34);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
//	baseIcon.infoShadowAnchor = new GPoint(18, 25);

	map = new GMap2($("map"));		// create the map
<?php 
    $maptype = get_variable('maptype');
    // 08/02/09
    switch ($maptype) {
        case "1":
            break;
        case "2":
            ?>
		map.setMapType(G_SATELLITE_MAP);
<?php 
            break;
        case "3":
            ?>
		map.setMapType(G_PHYSICAL_MAP);
<?php 
            break;
        case "4":
            ?>
		map.setMapType(G_HYBRID_MAP);
<?php 
            break;
        default:
            print "ERROR in " . basename(__FILE__) . " " . __LINE__ . "<BR />";
    }
    ?>
//	map.addControl(new GSmallMapControl());
	map.setUIToDefault();									// 8/13/10
	map.addControl(new GMapTypeControl());
	map.addControl(new GOverviewMapControl());				// 12/24/08
<?php 
    if (get_variable('terrain') == 1) {
        ?>
	map.addMapType(G_PHYSICAL_MAP);
<?php 
    }
    if ($lat == 0.999999 && $lng == 0.999999) {
        // check for facilities entered in no maps mode 7/28/10
        ?>
	map.setCenter(new GLatLng(<?php 
        print get_variable('def_lat');
        ?>
, <?php 
        print get_variable('def_lng');
        ?>
),14);
	var icon = new GIcon(baseIcon);
	var icon_url = "./our_icons/question1.png";				// 7/28/10
	icon.image = icon_url;
	var point = new GLatLng(<?php 
        print get_variable('def_lat');
        ?>
, <?php 
        print get_variable('def_lng');
        ?>
);	// 1147
	map.addOverlay(new GMarker(point, icon));
	map.enableScrollWheelZoom();
<?php 
    } else {
        ?>
	map.setCenter(new GLatLng(<?php 
        print $lat;
        ?>
, <?php 
        print $lng;
        ?>
),14);
	var icon = new GIcon(baseIcon);
	icon.image = icons[<?php 
        print $row['severity'];
        ?>
];
	var point = new GLatLng(<?php 
        print $lat;
        ?>
, <?php 
        print $lng;
        ?>
);	// 1147
	map.addOverlay(new GMarker(point, icon));
	map.enableScrollWheelZoom();
<?php 
    }
    ?>
	
// ====================================Add Responding Units to Map 8/1/09================================================

	var icons=[];	
	icons[1] = "./our_icons/white.png";		// normal
	icons[2] = "./our_icons/black.png";	// green

	var baseIcon = new GIcon();
	baseIcon.shadow = "./markers/sm_shadow.png";

	baseIcon.iconSize = new GSize(20, 34);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);

	var unit_icon = new GIcon(baseIcon);
	unit_icon.image = icons[1];

function createMarker(unit_point, number) {		// Show this markers index in the info window when clicked
	var unit_marker = new GMarker(unit_point, unit_icon);	
	var html = number;
	GEvent.addListener(unit_marker, "click", function() {unit_marker.openInfoWindowHtml(html);});
	return unit_marker;
	}


<?php 
    $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}assigns` WHERE ticket_id='{$id}'";
    $result = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
    while ($row = mysql_fetch_array($result)) {
        $responder_id = $row['responder_id'];
        if ($row['clear'] == NULL) {
            $query_unit = "SELECT * FROM `{$GLOBALS['mysql_prefix']}responder` WHERE id='{$responder_id}'";
            $result_unit = mysql_query($query_unit) or do_error($query_unit, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
            while ($row_unit = mysql_fetch_array($result_unit)) {
                $unit_id = $row_unit['id'];
                $mobile = $row_unit['mobile'];
                if (my_is_float($row_unit['lat']) && my_is_float($row_unit['lng'])) {
                    if ($mobile == 1) {
                        echo "var unit_icon = new GIcon(baseIcon);\n";
                        echo "var unit_icon_url = \"./our_icons/gen_icon.php?blank=0&text=RU\";\n";
                        echo "unit_icon.image = unit_icon_url;\n";
                        echo "var unit_point = new GLatLng(" . $row_unit['lat'] . "," . $row_unit['lng'] . ");\n";
                        echo "var unit_marker = createMarker(unit_point, '" . addslashes($row_unit['name']) . "', unit_icon);\n";
                        echo "map.addOverlay(unit_marker);\n";
                        echo "\n";
                    } else {
                        echo "var unit_icon = new GIcon(baseIcon);\n";
                        echo "var unit_icon_url = \"./our_icons/gen_icon.php?blank=4&text=RU\";\n";
                        echo "unit_icon.image = unit_icon_url;\n";
                        echo "var unit_point = new GLatLng(" . $row_unit['lat'] . "," . $row_unit['lng'] . ");\n";
                        echo "var unit_marker = createMarker(unit_point, '" . addslashes($row_unit['name']) . "', unit_icon);\n";
                        echo "map.addOverlay(unit_marker);\n";
                        echo "\n";
                    }
                    // end inner if
                }
                // end middle if
            }
            // end outer if
        }
        // end inner while
    }
    //	end outer while
    // =====================================End of functions to show responding units========================================================================
    // ====================================Add Facilities to Map 8/1/09================================================
    ?>

	var icons=[];	
	var g=0;

	var fmarkers = [];

	var baseIcon = new GIcon();
	baseIcon.shadow = "./markers/sm_shadow.png";

	baseIcon.iconSize = new GSize(30, 30);
	baseIcon.iconAnchor = new GPoint(15, 30);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);

	var fac_icon = new GIcon(baseIcon);
	fac_icon.image = icons[1];

function createfacMarker(fac_point, fac_name, id, fac_icon) {
	var fac_marker = new GMarker(fac_point, fac_icon);
	// Show this markers index in the info window when it is clicked
	var fac_html = fac_name;
	fmarkers[id] = fac_marker;
	GEvent.addListener(fac_marker, "click", function() {fac_marker.openInfoWindowHtml(fac_html);});
	return fac_marker;
}


<?php 
    $query_fac = "SELECT *,UNIX_TIMESTAMP(updated) AS updated, `{$GLOBALS['mysql_prefix']}facilities`.id AS fac_id, `{$GLOBALS['mysql_prefix']}facilities`.description AS facility_description, `{$GLOBALS['mysql_prefix']}fac_types`.name AS fac_type_name, `{$GLOBALS['mysql_prefix']}facilities`.name AS facility_name FROM `{$GLOBALS['mysql_prefix']}facilities` LEFT JOIN `{$GLOBALS['mysql_prefix']}fac_types` ON `{$GLOBALS['mysql_prefix']}facilities`.type = `{$GLOBALS['mysql_prefix']}fac_types`.id LEFT JOIN `{$GLOBALS['mysql_prefix']}fac_status` ON `{$GLOBALS['mysql_prefix']}facilities`.status_id = `{$GLOBALS['mysql_prefix']}fac_status`.id ORDER BY `{$GLOBALS['mysql_prefix']}facilities`.type ASC";
    $result_fac = mysql_query($query_fac) or do_error($query_fac, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
    while ($row_fac = mysql_fetch_array($result_fac)) {
        $eols = array("\r\n", "\n", "\r");
        // all flavors of eol
        while ($row_fac = mysql_fetch_array($result_fac)) {
            $fac_name = $row_fac['facility_name'];
            //	10/8/09
            $fac_temp = explode("/", $fac_name);
            $fac_index = substr($fac_temp[count($fac_temp) - 1], -6, strlen($fac_temp[count($fac_temp) - 1]));
            // 3/19/11
            print "\t\tvar fac_sym = '{$fac_index}';\n";
            // for sidebar and icon 10/8/09
            $fac_id = $row_fac['id'];
            $fac_type = $row_fac['icon'];
            $f_disp_name = $row_fac['facility_name'];
            //	10/8/09
            $f_disp_temp = explode("/", $f_disp_name);
            $facility_display_name = $f_disp_temp[0];
            if (my_is_float($row_fac['lat']) && my_is_float($row_fac['lng'])) {
                $fac_tab_1 = "<TABLE CLASS='infowin'  width='{$iw_width}' >";
                $fac_tab_1 .= "<TR CLASS='even'><TD COLSPAN=2 ALIGN='center'><B>" . addslashes(shorten($facility_display_name, 48)) . "</B></TD></TR>";
                $fac_tab_1 .= "<TR CLASS='odd'><TD COLSPAN=2 ALIGN='center'><B>" . addslashes(shorten($row_fac['fac_type_name'], 48)) . "</B></TD></TR>";
                $fac_tab_1 .= "<TR CLASS='even'><TD ALIGN='right'>Description:&nbsp;</TD><TD ALIGN='left'>" . addslashes(str_replace($eols, " ", $row_fac['facility_description'])) . "</TD></TR>";
                $fac_tab_1 .= "<TR CLASS='odd'><TD ALIGN='right'>Status:&nbsp;</TD><TD ALIGN='left'>" . addslashes($row_fac['status_val']) . " </TD></TR>";
                $fac_tab_1 .= "<TR CLASS='even'><TD ALIGN='right'>Contact:&nbsp;</TD><TD ALIGN='left'>" . addslashes($row_fac['contact_name']) . "&nbsp;&nbsp;&nbsp;Email: " . addslashes($row_fac['contact_email']) . "</TD></TR>";
                $fac_tab_1 .= "<TR CLASS='odd'><TD ALIGN='right'>Phone:&nbsp;</TD><TD ALIGN='left'>" . addslashes($row_fac['contact_phone']) . " </TD></TR>";
                $fac_tab_1 .= "<TR CLASS='even'><TD ALIGN='right'>As of:&nbsp;</TD><TD ALIGN='left'>" . format_date($row_fac['updated']) . "</TD></TR>";
                $fac_tab_1 .= "</TABLE>";
                $fac_tab_2 = "<TABLE CLASS='infowin'  width='{$iw_width}' >";
                $fac_tab_2 .= "<TR CLASS='odd'><TD ALIGN='right'>Security contact:&nbsp;</TD><TD ALIGN='left'>" . addslashes($row_fac['security_contact']) . " </TD></TR>";
                $fac_tab_2 .= "<TR CLASS='even'><TD ALIGN='right'>Security email:&nbsp;</TD><TD ALIGN='left'>" . addslashes($row_fac['security_email']) . " </TD></TR>";
                $fac_tab_2 .= "<TR CLASS='odd'><TD ALIGN='right'>Security phone:&nbsp;</TD><TD ALIGN='left'>" . addslashes($row_fac['security_phone']) . " </TD></TR>";
                $fac_tab_2 .= "<TR CLASS='even'><TD ALIGN='right'>Access rules:&nbsp;</TD><TD ALIGN='left'>" . addslashes(str_replace($eols, " ", $row_fac['access_rules'])) . "</TD></TR>";
                $fac_tab_2 .= "<TR CLASS='odd'><TD ALIGN='right'>Security reqs:&nbsp;</TD><TD ALIGN='left'>" . addslashes(str_replace($eols, " ", $row_fac['security_reqs'])) . "</TD></TR>";
                $fac_tab_2 .= "<TR CLASS='even'><TD ALIGN='right'>Opening hours:&nbsp;</TD><TD ALIGN='left'>" . addslashes(str_replace($eols, " ", $row_fac['opening_hours'])) . "</TD></TR>";
                $fac_tab_2 .= "<TR CLASS='odd'><TD ALIGN='right'>Prim pager:&nbsp;</TD><TD ALIGN='left'>" . addslashes($row_fac['pager_p']) . " </TD></TR>";
                $fac_tab_2 .= "<TR CLASS='even'><TD ALIGN='right'>Sec pager:&nbsp;</TD><TD ALIGN='left'>" . addslashes($row_fac['pager_s']) . " </TD></TR>";
                $fac_tab_2 .= "</TABLE>";
                ?>
			var myfacinfoTabs = [
				new GInfoWindowTab("<?php 
                print nl2brr(addslashes(shorten($row_fac['facility_name'], 10)));
                ?>
", "<?php 
                print $fac_tab_1;
                ?>
"),
				new GInfoWindowTab("More ...", "<?php 
                print str_replace($eols, " ", $fac_tab_2);
                ?>
")
				];
<?php 
                echo "var fac_icon = new GIcon(baseIcon);\n";
                echo "var fac_type = {$fac_type};\n";
                ?>
		var origin = ((fac_sym.length)>3)? (fac_sym.length)-3: 0;								// pick low-order three chars 3/22/11
		var iconStr = fac_sym.substring(origin);
<?php 
                echo "var fac_icon_url = \"./our_icons/gen_fac_icon.php?blank={$fac_type}&text=\" + (iconStr) + \"\";\n";
                echo "fac_icon.image = fac_icon_url;\n";
                echo "var fac_point = new GLatLng(" . $row_fac['lat'] . "," . $row_fac['lng'] . ");\n";
                echo "var fac_marker = createfacMarker(fac_point, myfacinfoTabs, g, fac_icon);\n";
                echo "map.addOverlay(fac_marker);\n";
                echo "\n";
            }
            // end if my_is_float
            ?>
			g++;
<?php 
        }
        // end while
    }
    // ============================== End of functions to show facilities =======================================
    //	$street = empty($row['ticket_street'])? "" : $row['ticket_street'] . "<BR/>" . $row['ticket_city'] . " " . $row['ticket_state'] ;  2/21/09
    //	$tab_1 = "<TABLE CLASS='infowin'  width='{$iw_width}' >";
    //	$tab_1 .= "<TR CLASS='even'><TD COLSPAN=2 ALIGN='center'><B>" . shorten($row['scope'], 48)  . "</B></TD></TR>";
    //	$tab_1 .= "<TR CLASS='odd'><TD>As of:</TD><TD>" . format_date($row['updated']) . "</TD></TR>";
    //	$tab_1 .= "<TR CLASS='even'><TD>Reported by:</TD><TD>" . shorten($row['contact'], 32) . "</TD></TR>";
    //	$tab_1 .= "<TR CLASS='odd'><TD>Phone:</TD><TD>" . format_phone ($row['phone']) . "</TD></TR>";
    //	$tab_1 .= "<TR CLASS='even'><TD>Addr:</TD><TD>" . $street . " </TD></TR>";
    //	$tab_1 .= "</TABLE>";		// 11/6/08
    do_kml();
    // kml functions
    ?>
//	map.openInfoWindowHtml(point, "<?php 
    // print $tab_1;
    ?>
");

	GEvent.addListener(map, "click", function(marker, point) {
		if (point) {
			var baseIcon = new GIcon();
			baseIcon.iconSize=new GSize(32,32);
			baseIcon.iconAnchor=new GPoint(16,16);
			var cross = new GIcon(baseIcon, "./markers/crosshair.png", null);		// 10/13/08

			map.clearOverlays();
			var thisMarker = new GMarker(point, cross);
			map.addOverlay(thisMarker);
			$("newlat").innerHTML = point.lat().toFixed(6);
			$("newlng").innerHTML = point.lng().toFixed(6);

			var nlat = $("newlat").innerHTML ;
			var nlng = $("newlng").innerHTML ;
			var olat = $("oldlat").innerHTML ;
			var olng = $("oldlng").innerHTML ;

			var km=distCosineLaw(parseFloat(olat), parseFloat(olng), parseFloat(nlat), parseFloat(nlng));
			var dist = ((km * km2feet).toFixed(0)).toString();
			var dist1 = dist/5280;
			var dist2 = (dist>5280)? ((dist/5280).toFixed(2) + " mi") : dist + " ft" ;

			$("range").innerHTML	= dist2;
			$("brng").innerHTML	= (brng (parseFloat(olat), parseFloat(olng), parseFloat(nlat), parseFloat(nlng)).toFixed(0)) + ' degr';
			$("newusng").innerHTML= LLtoUSNG(nlat, nlng, 5);
			$("pointl1").style.display = "block";
			$("pointl2").style.display = "block";

			var point = new GLatLng(<?php 
    print $lat;
    ?>
, <?php 
    print $lng;
    ?>
);	// 1196
			map.addOverlay(new GMarker(point, icon));
			var polyline = new GPolyline([
			    new GLatLng(nlat, nlng),
			    new GLatLng(olat, olng)
				], "#FF0000", 2);
			map.addOverlay(polyline);
			}
		} )

	function lat2ddm(inlat) {				// 9/7/08
		var x = new Number(inlat);
		var y  = (inlat>0)?  Math.floor(x):Math.round(x);
		var z = ((Math.abs(x-y)*60).toFixed(1));
		var nors = (inlat>0.0)? " N":" S";
		return Math.abs(y) + '\260 ' + z +"'" + nors;
		}

	function lng2ddm(inlng) {
		var x = new Number(inlng);
		var y  = (inlng>0)?  Math.floor(x):Math.round(x);
		var z = ((Math.abs(x-y)*60).toFixed(1));
		var eorw = (inlng>0.0)? " E":" W";
		return Math.abs(y) + '\260 ' + z +"'" + eorw;
		}

	function do_coords(inlat, inlng) {  //9/14/08
		if(inlat.toString().length==0) return;								// 10/15/08
		var str = inlat + ", " + inlng + "\n";
		str += ll2dms(inlat) + ", " +ll2dms(inlng) + "\n";
		str += lat2ddm(inlat) + ", " +lng2ddm(inlng);
		alert(str);
		}

	function ll2dms(inval) {				// lat/lng to degr, mins, sec's - 9/9/08
		var d = new Number(inval);
		d  = (inval>0)?  Math.floor(d):Math.round(d);
		var mi = (inval-d)*60;
		var m = Math.floor(mi)				// min's
		var si = (mi-m)*60;
		var s = si.toFixed(1);
		return d + '\260 ' + Math.abs(m) +"' " + Math.abs(s) + '"';
		}

	</SCRIPT>
<?php 
}
			<BR />
			<SPAN CLASS="legend" STYLE="text-align: center; vertical-align: middle;">Units Legend:</SPAN><BR /><BR /><DIV CLASS="legend" ALIGN='center' VALIGN='middle' style='padding: 20px; text-align: center; vertical-align: middle; width: <?php 
    print get_variable('map_width');
    ?>
px;'>	<!-- 3/15/11 -->
<?php 
    print get_icon_legend();
    ?>

			</DIV>	<!-- 3/15/11 -->
			<BR /><BR />
<?php 
    if (!$show_tick_left) {
        // 11/27/09
        print "\n<DIV ID='the_ticket' STYLE='width: " . get_variable('map_width') . "'>\n";
        print do_ticket($row_ticket, $the_width, FALSE, FALSE);
        print "\n</DIV>\n";
    }
    ?>
			<DIV ID="directions" STYLE="width: <?php 
    print get_variable('map_width');
    ?>
px"></DIV>
		</TD></TR></TABLE><!-- end outer -->
	<DIV ID='bottom' STYLE='display:none'>
	<CENTER>
	<H3>Dispatching ... please wait ...</H3><BR /><BR /><BR />
	</DIV>

	
	<FORM NAME='can_Form' ACTION="main.php" ><!-- 8/30/10 -->
function do_aa_report($date_in, $func_in)
{
    // after action report $frm_date, $mode as params - 9/27/10
    global $types, $incident, $disposition;
    // 12/7/10
    global $w_tiny, $w_small, $w_medium, $w_large;
    // 4/14/11
    $the_width = 600;
    require_once './incs/functions_major.inc.php';
    // 7/28/10
    $from_to = date_range($date_in, $func_in);
    // get date range as array
    $where = " WHERE `problemstart` >= '{$from_to[0]}' AND `problemstart` < '{$from_to[1]}'";
    $query = "SELECT *,\n\t\t\tUNIX_TIMESTAMP(problemstart) AS problemstart,\n\t\t\tUNIX_TIMESTAMP(problemend) AS problemend,\n\t\t\tUNIX_TIMESTAMP(booked_date) AS booked_date,\t\t\n\t\t\tUNIX_TIMESTAMP(date) AS date,\n\t\t\tUNIX_TIMESTAMP(`{$GLOBALS['mysql_prefix']}ticket`.`updated`) AS updated,\n\t\t\t `{$GLOBALS['mysql_prefix']}ticket`.`description` AS `tick_descr`,\n\t\t\t `{$GLOBALS['mysql_prefix']}ticket`.`lat` AS `lat`,\n\t\t\t `{$GLOBALS['mysql_prefix']}ticket`.`lng` AS `lng`,\n\t\t\t `{$GLOBALS['mysql_prefix']}ticket`.`_by` AS `call_taker`,\n\t\t\t `{$GLOBALS['mysql_prefix']}ticket`.`street` AS `tick_street`,\n\t\t\t `{$GLOBALS['mysql_prefix']}ticket`.`city` AS `tick_city`,\n\t\t\t `{$GLOBALS['mysql_prefix']}ticket`.`state` AS `tick_state`,\t\t\t\t \n\t\t\t `{$GLOBALS['mysql_prefix']}facilities`.`name` AS `fac_name`,\n\t\t\t `rf`.`name` AS `rec_fac_name`,\n\t\t\t `rf`.`lat` AS `rf_lat`,\n\t\t\t `rf`.`lng` AS `rf_lng`,\n\t\t\t `{$GLOBALS['mysql_prefix']}facilities`.`lat` AS `fac_lat`,\n\t\t\t `{$GLOBALS['mysql_prefix']}facilities`.`lng` AS `fac_lng` FROM `{$GLOBALS['mysql_prefix']}ticket`  \n\t\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}in_types` `ty` ON (`{$GLOBALS['mysql_prefix']}ticket`.`in_types_id` = `ty`.`id`)\t\t\n\t\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}facilities` ON (`{$GLOBALS['mysql_prefix']}facilities`.`id` = `{$GLOBALS['mysql_prefix']}ticket`.`facility`)\n\t\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}facilities` `rf` ON (`rf`.`id` = `{$GLOBALS['mysql_prefix']}ticket`.`rec_facility`) \n\t\t\t{$where} ORDER BY `SEVERITY` ASC, `problemstart` ASC";
    $result = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
    if (mysql_affected_rows() == 0) {
        print "<BR /><BR /><SPAN STYLE='margin-left:300px;'><B>No incident data for this period</B></SPAN>";
    } else {
        $to_str = $func_in == "dr" ? "" : " to {$from_to[3]} " . substr($from_to[1], 0, 4);
        print "<BR /><SPAN STYLE='margin-left:160px;'><B>" . mysql_affected_rows() . " Incidents: " . $from_to[2] . $to_str . "</B></SPAN><BR /><BR />";
        print "<TABLE ALIGN='left' CELLSPACING = 2 CELLPADDING = 2  BORDER=0 width='800px'><TR><TD>";
        while ($row_ticket = stripslashes_deep(mysql_fetch_array($result))) {
            print do_ticket($row_ticket, $the_width, FALSE, FALSE);
            //		print "<TR><TD ALIGN='center'><HR COLOR='blue'><BR /></TD></TR>";
            print "<BR />";
        }
        // end while ()
        print "</TD></TR></TABLE>";
    }
    // end if/else
}
</SCRIPT>
<?php 
    // 1/7/10
    $query = "SELECT *,\n\t\tUNIX_TIMESTAMP(problemstart) AS problemstart,\n\t\tUNIX_TIMESTAMP(problemend) AS problemend,\n\t\tUNIX_TIMESTAMP(date) AS date,\n\t\tUNIX_TIMESTAMP(updated) AS updated,\n\t\t`_by` AS `call_taker`\n\t\tFROM {$GLOBALS['mysql_prefix']}ticket \n\t\tWHERE ID=" . $_GET['ticket_id'] . " LIMIT 1";
    // get Incident location
    $result = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
    $row_unit = stripslashes_deep(mysql_fetch_array($result));
    unset($result);
    ?>
<!--	<BODY onLoad = "ck_frames()" onUnload='GUnload()'> -->
	<BODY onUnload='GUnload()'>
	<TABLE ID='outer' BORDER = 0>
	<TR><TD VALIGN='top'><DIV ID='side_bar' STYLE='width: 400px'></DIV>
		<BR>
			<DIV ID='the_ticket' style='width: 500px;'><?php 
    print do_ticket($row_unit, 500, FALSE, FALSE);
    ?>
</DIV>
		</TD>
		<TD VALIGN="top" ALIGN='center'>
			<DIV ID='map_canvas' style='width: <?php 
    print get_variable('map_width');
    ?>
px; height: <?php 
    print get_variable('map_height');
    ?>
px; border-style: outset'></DIV>
			<BR />
			<BR /><BR />Units:&nbsp;&nbsp;&nbsp;&nbsp;
				EMS: 	<IMG SRC = './markers/sm_yellow.png' 	BORDER=0>&nbsp;&nbsp;&nbsp;
				Fire: 		<IMG SRC = './markers/sm_red.png' 		BORDER=0>&nbsp;&nbsp;&nbsp;
function show_ticket($id, $print = 'false', $search = FALSE)
{
    /* show specified ticket */
    global $istest, $nature, $disposition, $patient, $incident, $incidents;
    // 12/3/10
    $can_edit = get_can_edit();
    $tickno = get_variable('serial_no_ap') == 0 ? "&nbsp;&nbsp;<I>(#{$id})</I>" : "";
    // 1/25/09
    if ($istest) {
        print "GET<br />\n";
        dump($_GET);
        print "POST<br />\n";
        dump($_POST);
    }
    if ($id == '' or $id <= 0 or !check_for_rows("SELECT * FROM `{$GLOBALS['mysql_prefix']}ticket` WHERE id='{$id}'")) {
        /* sanity check */
        print "Invalid Ticket ID: '{$id}'<BR />";
        return;
    }
    $restrict_ticket = get_variable('restrict_user_tickets') == 1 && !is_administrator() ? " AND owner={$_SESSION['user_id']}" : "";
    // 1/7/10
    $query = "SELECT *,\n\t\t`problemstart` AS `my_start`,\n\t\tFROM_UNIXTIME(UNIX_TIMESTAMP(problemstart)) AS `test`,\n\t\tUNIX_TIMESTAMP(problemstart) AS problemstart,\n\t\tUNIX_TIMESTAMP(problemend) AS problemend,\n\t\tUNIX_TIMESTAMP(date) AS date,\n\t\tUNIX_TIMESTAMP(booked_date) AS booked_date,\t\t\n\t\tUNIX_TIMESTAMP(`{$GLOBALS['mysql_prefix']}ticket`.`updated`) AS updated,\t\t\n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`description` AS `tick_descr`,\n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`street` AS `tick_street`,\n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`city` AS `tick_city`,\n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`state` AS `tick_state`,\t\t\n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`lat` AS `lat`,\t\t\n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`lng` AS `lng`,\n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`_by` AS `call_taker`,\n\t\t`{$GLOBALS['mysql_prefix']}facilities`.`name` AS `fac_name`,\t\t\n\t\t`rf`.`name` AS `rec_fac_name`,\n\t\t`{$GLOBALS['mysql_prefix']}facilities`.`lat` AS `fac_lat`,\t\t\n\t\t`{$GLOBALS['mysql_prefix']}facilities`.`lng` AS `fac_lng`,\t\t \n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`id` AS `tick_id`\n\t\tFROM `{$GLOBALS['mysql_prefix']}ticket` \n\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}in_types` `ty` ON (`{$GLOBALS['mysql_prefix']}ticket`.`in_types_id` = `ty`.`id`)\t\n\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}facilities` ON `{$GLOBALS['mysql_prefix']}facilities`.id = `{$GLOBALS['mysql_prefix']}ticket`.facility \n\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}facilities` rf ON `rf`.id = `{$GLOBALS['mysql_prefix']}ticket`.rec_facility \n\t\tWHERE `{$GLOBALS['mysql_prefix']}ticket`.`id`= {$id} {$restrict_ticket}";
    // 7/16/09, 8/12/09
    $result = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
    if (!mysql_num_rows($result)) {
        //no tickets? print "error" or "restricted user rights"
        print "<FONT CLASS=\"warn\">Internal error " . basename(__FILE__) . "/" . __LINE__ . ".  Notify developers of this message.</FONT>";
        // 8/18/09
        exit;
    }
    $row = stripslashes_deep(mysql_fetch_array($result));
    if ($print == 'true') {
        // 1/7/10 - 11/16/10
        print "<TABLE BORDER='0'ID='left' width='800px'>\n";
        //
        print "<TR CLASS='print_TD'><TD ALIGN='left' CLASS='td_data' COLSPAN=2 ALIGN='center'><B>{$patient}: <I>" . $row['scope'] . "</B>" . $tickno . "</TD></TR>\n";
        print "<TR CLASS='print_TD' ><TD ALIGN='left'>" . get_text("Priority") . ":</TD> \n\t\t\t\t\t<TD ALIGN='left'>" . get_severity($row['severity']);
        print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$nature}:&nbsp;&nbsp;" . get_type($row['in_types_id']);
        print "</TD></TR>\n";
        print "<TR CLASS='print_TD' ><TD ALIGN='left'>" . get_text("Protocol") . ":</TD> <TD ALIGN='left'>{$row['protocol']}</TD></TR>\n";
        // 7/16/09
        print "<TR CLASS='print_TD' ><TD ALIGN='left'>" . get_text("Addr") . ":</TD>\t\n\t\t\t\t<TD ALIGN='left'>" . $row['tick_street'] . "</TD></TR>\n";
        print "<TR CLASS='print_TD' ><TD ALIGN='left'>" . get_text("City") . ":</TD>\t\t\n\t\t\t\t<TD ALIGN='left'>" . $row['tick_city'];
        print "&nbsp;&nbsp;" . $row['tick_state'] . "</TD></TR>\n";
        print "<TR CLASS='print_TD'  VALIGN='top'><TD ALIGN='left'>" . get_text("Synopsis") . ":</TD>\n\t\t\t\t<TD ALIGN='left'>" . nl2br($row['tick_descr']) . "</TD></TR>\n";
        //	8/12/09
        print "<TR CLASS='print_TD'  VALIGN='top'><TD ALIGN='left'>" . get_text("911 Contacted") . ":</TD>\n\t\t\t\t<TD ALIGN='left'>" . nl2br($row['nine_one_one']) . "</TD></TR>\n";
        //	8/12/09
        $end_date = intval($row['problemend']) > 1 ? $row['problemend'] : time() - intval(get_variable('delta_mins')) * 60;
        $elapsed = my_date_diff($end_date, $end_date);
        print "<TR CLASS='print_TD'><TD ALIGN='left'>" . get_text("Status") . ":</TD>\t\n\t\t\t\t<TD ALIGN='left'>" . get_status($row['status']) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$elapsed}</TD></TR>\n";
        print "<TR CLASS='print_TD'><TD ALIGN='left'>" . get_text("Reported by") . ":</TD>\n\t\t\t\t<TD ALIGN='left'>" . $row['contact'] . "</TD></TR>\n";
        print "<TR CLASS='print_TD' ><TD ALIGN='left'>" . get_text("Phone") . ":</TD>\t\t\n\t\t\t\t<TD ALIGN='left'>" . format_phone($row['phone']) . "</TD></TR>\n";
        $by_str = $row['call_taker'] == 0 ? "" : "&nbsp;&nbsp;by " . get_owner($row['call_taker']) . "&nbsp;&nbsp;";
        // 1/7/10
        print "<TR CLASS='print_TD'><TD ALIGN='left'>" . get_text("Written") . ":</TD>\t\n\t\t\t\t<TD ALIGN='left'>" . format_date($row['date']) . $by_str;
        print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Updated:&nbsp;&nbsp;" . format_date($row['updated']) . "</TD></TR>\n";
        print empty($row['booked_date']) ? "" : "<TR CLASS='print_TD'><TD ALIGN='left'>Scheduled date:</TD>\t\n\t\t\t\t<TD ALIGN='left'>" . format_date($row['booked_date']) . "</TD></TR>\n";
        // 10/6/09
        print "<TR CLASS='print_TD' ><TD ALIGN='left' COLSPAN='2'>&nbsp;\n\t\t\t\t<TD ALIGN='left'></TR>\n";
        // separator
        print empty($row['fac_name']) ? "" : "<TR CLASS='print_TD' ><TD ALIGN='left'>" . $incident . " at Facility:</TD>\t\n\t\t\t\t<TD ALIGN='left'>" . $row['fac_name'] . "</TD></TR>\n";
        // 8/1/09, 3/27/10
        print empty($row['rec_fac_name']) ? "" : "<TR CLASS='print_TD' ><TD ALIGN='left'>Receiving Facility:</TD>\t\n\t\t\t\t<TD ALIGN='left'>" . $row['rec_fac_name'] . "</TD></TR>\n";
        // 10/6/09
        print empty($row['comments']) ? "" : "<TR CLASS='print_TD'  VALIGN='top'><TD ALIGN='left'>{$disposition}:</TD>\n\t\t\t\t<TD ALIGN='left'>" . nl2br($row['comments']) . "</TD></TR>\n";
        print "<TR CLASS='print_TD' ><TD ALIGN='left'>" . get_text("Run Start") . ":</TD>\t\t\t\t\n\t\t\t\t<TD ALIGN='left'>" . format_date($row['problemstart']);
        $elapsed_str = !empty($closed) ? $elapsed : "";
        print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End:&nbsp;&nbsp;" . format_date($row['problemend']) . "&nbsp;&nbsp;{$elapsed_str}</TD></TR>\n";
        $locale = get_variable('locale');
        // 08/03/09
        switch ($locale) {
            case "0":
                $grid_type = "&nbsp;&nbsp;&nbsp;&nbsp;USNG&nbsp;&nbsp;" . LLtoUSNG($row['lat'], $row['lng']);
                break;
            case "1":
                $grid_type = "&nbsp;&nbsp;&nbsp;&nbsp;OSGB&nbsp;&nbsp;" . LLtoOSGB($row['lat'], $row['lng']);
                // 8/23/08, 10/15/08, 8/3/09
                break;
            case "2":
                $coords = $row['lat'] . "," . $row['lng'];
                // 8/12/09
                $grid_type = "&nbsp;&nbsp;&nbsp;&nbsp;UTM&nbsp;&nbsp;" . toUTM($coords);
                // 8/23/08, 10/15/08, 8/3/09
                break;
            default:
                print "ERROR in " . basename(__FILE__) . " " . __LINE__ . "<BR />";
        }
        print "<TR CLASS='print_TD'><TD ALIGN='left' >" . get_text("Position") . ": </TD>\t\t\n\t\t\t\t<TD ALIGN='left'>" . get_lat($row['lat']) . "&nbsp;&nbsp;&nbsp;" . get_lng($row['lng']) . $grid_type . "</TD></TR>\n";
        // 9/13/08
        print "<TR><TD colspan=2 ALIGN='left'>";
        print show_log($row[0]);
        // log
        print "</TD></TR>";
        print "<TR STYLE = 'display:none;'><TD colspan=2><SPAN ID='oldlat'>" . $row['lat'] . "</SPAN><SPAN ID='oldlng'>" . $row['lng'] . "</SPAN></TD></TR>";
        print "</TABLE>\n";
        print show_actions($row['tick_id'], "date", FALSE, FALSE);
        // lists actions and patient data, print - 10/30/09
        // =============== 10/30/09
        function my_to_date($in_date)
        {
            // date_time format to user's spec
            //			$temp = mktime(substr($in_date,11,2),substr($in_date,14,2),substr($in_date,17,2),substr($in_date,5,2),substr($in_date,8,2),substr($in_date,0,4));
            $temp = mysql2timestamp($d1);
            // 9/29/10
            return good_date_time($in_date) ? date(get_variable("date_format"), $temp) : "";
            //
        }
        // ==============
        print "\n</BODY>\n</HTML>";
        return;
    }
    // end if ($print == 'true')
    ?>
	<TABLE BORDER="0" ID = "outer" ALIGN="left">
	<TR VALIGN="top"><TD CLASS="print_TD" ALIGN="left">
<?php 
    print do_ticket($row, max(320, intval($_SESSION['scr_width'] * 0.4)), $search);
    // 2/25/09
    print show_actions($row['id'], "date", FALSE, TRUE);
    /* lists actions and patient data belonging to ticket */
    print "</TR>";
    print "<TR CLASS='odd' ><TD COLSPAN='2' CLASS='print_TD'>";
    //  $lat = $row['lat']; $lng = $row['lng'];
    //	print show_actions($row['id'], "date", FALSE, TRUE);		/* lists actions and patient data belonging to ticket */
    print "</TD></TR>\n";
    print "</TABLE>\n";
    ?>
	<SCRIPT SRC='../js/usng.js' TYPE='text/javascript'></SCRIPT>
	<SCRIPT>
	function isNull(val) {								// checks var stuff = null;
		return val === null;
		}
	</SCRIPT>
<?php 
}