Ejemplo n.º 1
0
function list_responders($addon = '', $start)
{
    global $iw_width, $u_types, $tolerance;
    $assigns = array();
    // 08/8/3
    $tickets = array();
    // ticket id's
    // 7/18/10
    $query = "SELECT `{$GLOBALS['mysql_prefix']}assigns`.`ticket_id`, `{$GLOBALS['mysql_prefix']}assigns`.`responder_id`,\n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`scope` AS `ticket` \n\t\tFROM `{$GLOBALS['mysql_prefix']}assigns` \t\t\n\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}ticket` ON `{$GLOBALS['mysql_prefix']}assigns`.`ticket_id`=`{$GLOBALS['mysql_prefix']}ticket`.`id`\n\t\tWHERE ( `clear` IS NULL OR DATE_FORMAT(`clear`,'%y') = '00' )";
    $result_as = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
    while ($row_as = stripslashes_deep(mysql_fetch_array($result_as))) {
        $assigns[$row_as['responder_id']] = $row_as['ticket'];
        $tickets[$row_as['responder_id']] = $row_as['ticket_id'];
    }
    unset($result_as);
    $calls = array();
    // 6/17/08
    $calls_nr = array();
    $calls_time = array();
    $query = "SELECT * , UNIX_TIMESTAMP(packet_date) AS `packet_date` FROM `{$GLOBALS['mysql_prefix']}tracks` ORDER BY `packet_date` ASC";
    // 6/17/08
    $result = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), __FILE__, __LINE__);
    while ($row = mysql_fetch_array($result)) {
        if (isset($calls[$row['source']])) {
            // array_key_exists ( mixed key, array search )
            $calls_nr[$row['source']]++;
        } else {
            //			array_push ($calls, trim($row['source']));
            $calls[trim($row['source'])] = TRUE;
            $calls_nr[$row['source']] = 1;
        }
        $calls_time[$row['source']] = $row['packet_date'];
        // save latest - note query order
    }
    ?>

<SCRIPT >

var color=0;
	var colors = new Array ('odd', 'even');

	function hideDiv(div_area, hide_cont, show_cont) {	//	3/15/11
		if (div_area == "buttons_sh") {
			var controlarea = "hide_controls";
			}
		if (div_area == "resp_list_sh") {
			var controlarea = "resp_list";
			}
		if (div_area == "facs_list_sh") {
			var controlarea = "facs_list";
			}
		if (div_area == "incs_list_sh") {
			var controlarea = "incs_list";
			}
		if (div_area == "region_boxes") {
			var controlarea = "region_boxes";
			}			
		var divarea = div_area 
		var hide_cont = hide_cont 
		var show_cont = show_cont 
		if($(divarea)) {
			$(divarea).style.display = 'none';
			$(hide_cont).style.display = 'none';
			$(show_cont).style.display = '';
			} 
		var params = "f_n=" +controlarea+ "&v_n=h&sess_id=<?php 
    print get_sess_key(__LINE__);
    ?>
";
		var url = "persist2.php";
		sendRequest (url, gb_handleResult, params);			
		} 

	function showDiv(div_area, hide_cont, show_cont) {	//	3/15/11
		if (div_area == "buttons_sh") {
			var controlarea = "hide_controls";
			}
		if (div_area == "resp_list_sh") {
			var controlarea = "resp_list";
			}
		if (div_area == "facs_list_sh") {
			var controlarea = "facs_list";
			}
		if (div_area == "incs_list_sh") {
			var controlarea = "incs_list";
			}
		if (div_area == "region_boxes") {
			var controlarea = "region_boxes";
			}				
		var divarea = div_area
		var hide_cont = hide_cont 
		var show_cont = show_cont 
		if($(divarea)) {
			$(divarea).style.display = '';
			$(hide_cont).style.display = '';
			$(show_cont).style.display = 'none';
			}
		var params = "f_n=" +controlarea+ "&v_n=s&sess_id=<?php 
    print get_sess_key(__LINE__);
    ?>
";
		var url = "persist2.php";
		sendRequest (url, gb_handleResult, params);					
		} 	

	function hideGroup(color) {
		for (var i = 0; i < gmarkers.length; i++) {
			if (gmarkers[i]) {
				if (gmarkers[i].id == color) {
					gmarkers[i].show();
					}
				else {
					gmarkers[i].hide();
					}
				}		// end if (gmarkers[i])
			} 	// end for ()
		elem = $("allIcons");
		elem.style.visibility = "visible";
		}			// end function

	function showAll() {
		for (var i = 0; i < gmarkers.length; i++) {
			if (gmarkers[i]) {
				gmarkers[i].show();
				}
			} 	// end for ()
		elem = $("allIcons");
		elem.style.visibility = "hidden";

		}			// end function

	function checkArray(form, arrayName)	{	//	5/3/11
		var retval = new Array();
		for(var i=0; i < form.elements.length; i++) {
			var el = form.elements[i];
			if(el.type == "checkbox" && el.name == arrayName && el.checked) {
				retval.push(el.value);
			}
		}
	return retval;
	}		
		
	function checkForm(form)	{	//	6/10/11
		var errmsg="";
		var itemsChecked = checkArray(form, "frm_group[]");
		if(itemsChecked.length > 0) {
			var params = "f_n=viewed_groups&v_n=" +itemsChecked+ "&sess_id=<?php 
    print get_sess_key(__LINE__);
    ?>
";	//	3/15/11
			var url = "persist3.php";	//	3/15/11	
			sendRequest (url, fvg_handleResult, params);				
			form.submit();
		} else {
			errmsg+= "\tYou cannot Hide all the regions\n";
			if (errmsg!="") {
				alert ("Please correct the following and re-submit:\n\n" + errmsg);
				return false;
			}
		}
	}
	
	function fvg_handleResult(req) {	// 6/10/11	The persist callback function for viewed groups.
		document.region_form.submit();
		}
		
	function form_validate(theForm) {	//	5/3/11
//		alert("Validating");
		checkForm(theForm);
		}				// end function validate(theForm)			

	function sendRequest(url,callback,postData) {								// 2/14/09
		var req = createXMLHTTPObject();
		if (!req) return;
		var method = (postData) ? "POST" : "GET";
		req.open(method,url,true);
		req.setRequestHeader('User-Agent','XMLHTTP/1.0');
		if (postData)
			req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		req.onreadystatechange = function () {
			if (req.readyState != 4) return;
			if (req.status != 200 && req.status != 304) {
				return;
				}
			callback(req);
			}
		if (req.readyState == 4) return;
		req.send(postData);
		}

	var XMLHttpFactories = [
		function () {return new XMLHttpRequest()	},
		function () {return new ActiveXObject("Msxml2.XMLHTTP")	},
		function () {return new ActiveXObject("Msxml3.XMLHTTP")	},
		function () {return new ActiveXObject("Microsoft.XMLHTTP")	}
		];

	function createXMLHTTPObject() {
		var xmlhttp = false;
		for (var i=0;i<XMLHttpFactories.length;i++) {
			try {
				xmlhttp = XMLHttpFactories[i]();
				}
			catch (e) {
				continue;
				}
			break;
			}
		return xmlhttp;
		}		

	function createMarker(point,tabs, color, id, unit_id) {						// (point, myinfoTabs,<?php 
    print $row['type'];
    ?>
, i)
		points = true;
		var unit_id = unit_id;										// 2/13/09

		var icon = new GIcon(listIcon);
		
		var icon_url = "./our_icons/gen_icon.php?blank=" + color + "&text=" + unit_id;				// 1/5/09

		icon.image = icon_url;		// ./our_icons/gen_icon.php?blank=4&text=zz"

		var marker = new GMarker(point, icon);
		marker.id = color;				// for hide/unhide - unused

		GEvent.addListener(marker, "click", function() {		// here for both side bar and icon click
			if (marker) {
				map.closeInfoWindow();
				which = id;
				gmarkers[which].hide();
				marker.openInfoWindowTabsHtml(infoTabs[id]);

				setTimeout(function() {										// wait for rendering complete - 12/17/08
					if ($("detailmap")) {
						var dMapDiv = $("detailmap");
						var detailmap = new GMap2(dMapDiv);
						detailmap.addControl(new GSmallMapControl());
						detailmap.setCenter(point, 17);  						// larger # = closer
						detailmap.addOverlay(marker);
						}
					else {
	//					alert(62);
	//					alert($("detailmap"));
						}
					},4000);				// end setTimeout(...)

				}		// end if (marker)


			});			// end GEvent.add Listener()

		gmarkers[id] = marker;									// marker to array for side bar click function
		infoTabs[id] = tabs;									// tabs to array
		if (!(map_is_fixed)) {				// 4/3/09
			bounds.extend(point);
			}
		return marker;
		}				// end function create Marker()

	function createdummyMarker(point,tabs, color, id, unit_id) {						// (point, myinfoTabs,<?php 
    print $row['type'];
    ?>
, i)
		points = true;
		var unit_id = unit_id;										// 2/13/09

		var icon = new GIcon(listIcon);
		var icon_url = "./our_icons/question1.png";

		icon.image = icon_url;		// ./our_icons/gen_icon.php?blank=4&text=zz"

		var dummymarker = new GMarker(point, icon);
		dummymarker.id = color;				// for hide/unhide - unused

		GEvent.addListener(dummymarker, "click", function() {		// here for both side bar and icon click
			if (dummymarker) {
				map.closeInfoWindow();
				which = id;
				gmarkers[which].hide();
				dummymarker.openInfoWindowTabsHtml(infoTabs[id]);

				setTimeout(function() {										// wait for rendering complete - 12/17/08
					if ($("detailmap")) {
						var dMapDiv = $("detailmap");
						var detailmap = new GMap2(dMapDiv);
						detailmap.addControl(new GSmallMapControl());
						detailmap.setCenter(point, 17);  						// larger # = closer
						detailmap.addOverlay(dummymarker);
						}
					else {
	//					alert(62);
	//					alert($("detailmap"));
						}
					},4000);				// end setTimeout(...)

				}		// end if (marker)


			});			// end GEvent.add Listener()

		gmarkers[id] = dummymarker;									// marker to array for side bar click function
		infoTabs[id] = tabs;									// tabs to array
		if (!(map_is_fixed)) {				// 4/3/09
			bounds.extend(point);
			}
		return dummymarker;
		}				// end function create dummy Marker()		

	function do_sidebar (sidebar, id, the_class, sidebar_id) {
		var sidebar_id = sidebar_id;
		side_bar_html += "<TR CLASS='" + colors[(id)%2] +"'>";
		side_bar_html += "<TD WIDTH='5%' CLASS='" + the_class + "' onClick = myclick(" + id + "); >" + sidebar_id + sidebar +"</TD></TR>\n";		// 1/5/09, 3/4/09, 10/29/09 removed period
		}

	function do_sidebar_nm (sidebar, line_no, id, sidebar_id) {	
		var sidebar_id = sidebar_id;		
		side_bar_html += "<TR CLASS='" + colors[(line_no)%2] +"'>";
		side_bar_html += "<TD WIDTH='5%' onClick = myclick_nm(" + sidebar_id + "); >" + sidebar_id + sidebar +"</TD></TR>\n";		// 1/23/09, 10/29/09 removed period, 11/11/09
		}

	function myclick_nm(v_id) {				// Responds to sidebar click - view responder data
		document.view_form.id.value=v_id;
		document.view_form.submit();
		}

	function myclick(id) {					// Responds to sidebar click, then triggers listener above -  note [id]
		GEvent.trigger(gmarkers[id], "click");
		location.href = '#top';				// 11/11/09
		}

	function do_lat (lat) {
		document.forms[0].frm_lat.value=lat.toFixed(6);
		}
	function do_lng (lng) {
		document.forms[0].frm_lng.value=lng.toFixed(6);
		}
		
	function do_ngs() {											// LL to USNG
		var loc = <?php 
    print get_variable('locale');
    ?>
;
		document.forms[0].frm_ngs.disabled=false;
		if(loc == 0) {
			document.forms[0].frm_ngs.value = LLtoUSNG(document.forms[0].frm_lat.value, document.forms[0].frm_lng.value, 5);
			}
		if(loc == 1) {
			document.forms[0].frm_ngs.value = LLtoOSGB(document.forms[0].frm_lat.value, document.forms[0].frm_lng.value, 5);
			}
		if(loc == 2) {
			document.forms[0].frm_ngs.value = LLtoOSGB(document.forms[0].frm_lat.value, document.forms[0].frm_lng.value, 5);
			}			
		document.forms[0].frm_ngs.disabled=true;
		}		

	var icons=new Array;							// maps type to icon blank

<?php 
    $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}unit_types` ORDER BY `id`";
    // types in use
    $result = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
    $icons = $GLOBALS['icons'];
    while ($row = stripslashes_deep(mysql_fetch_assoc($result))) {
        // map type to blank icon id
        $blank = $row['icon'];
        print "\ticons[" . $row['id'] . "] = " . $blank . ";\n";
        //
    }
    unset($result);
    $dzf = get_variable('def_zoom_fixed');
    print "\tvar map_is_fixed = ";
    print my_is_int($dzf) && $dzf == 2 || my_is_int($dzf) && $dzf == 3 ? "true;\n" : "false;\n";
    ?>
	var map;
	var side_bar_html = "<TABLE border=0 CLASS='sidebar' WIDTH = '100%' >";

	side_bar_html += "<TR class='even'>	<TD></TD><TD ALIGN='left'><B>Unit</B></TD><TD ALIGN='left'><B>Handle</B></TD><TD ALIGN='left'><B>Dispatch</B></TD><TD ALIGN='left'><B>Status</B></TD><TD ALIGN='left'><B>M</B></TD><TD ALIGN='left'><B>As of</B></TD></TR>";
	var gmarkers = [];
	var infoTabs = [];
	var which;
	var i = <?php 
    print $start;
    ?>
;					// sidebar/icon index
	var points = false;								// none
	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());					// 10/6/08
	map.setUIToDefault();										// 8/13/10

	map.addControl(new GMapTypeControl());
<?php 
    if (get_variable('terrain') == 1) {
        ?>
	map.addMapType(G_PHYSICAL_MAP);
<?php 
    }
    ?>

	map.setCenter(new GLatLng(<?php 
    echo get_variable('def_lat');
    ?>
, <?php 
    echo get_variable('def_lng');
    ?>
), <?php 
    echo get_variable('def_zoom');
    ?>
);
	mapBounds=new GLatLngBounds(map.getBounds().getSouthWest(), map.getBounds().getNorthEast());		// 4/4/09

	var bounds = new GLatLngBounds();						// create  bounding box
	map.enableScrollWheelZoom();

	var listIcon = new GIcon();
	listIcon.image = "./markers/yellow.png";	// yellow.png - 16 X 28
	listIcon.shadow = "./markers/sm_shadow.png";
	listIcon.iconSize = new GSize(20, 34);
	listIcon.shadowSize = new GSize(37, 34);
	listIcon.iconAnchor = new GPoint(8, 28);
	listIcon.infoWindowAnchor = new GPoint(9, 2);
	listIcon.infoShadowAnchor = new GPoint(18, 25);

	GEvent.addListener(map, "infowindowclose", function() {		// re-center after  move/zoom
		map.addOverlay(gmarkers[which])
		});
	
	do_landb();				// 8/1/11 - show scribbles	
//-----------------------BOUNDARIES STUFF--------------------6/10/11

	var thepoint;
	var points = new Array();
	var boundary = new Array();	
	var bound_names = new Array();

	GEvent.addListener(map, "click", function(overlay,boundpoint) {
		for (var n = 0; n < boundary.length; n++) {
			if (boundary[n].Contains(boundpoint)) {
				map.openInfoWindowHtml(boundpoint,"This is " + bound_names[n]);
				}
			}
		});			
<?php 
    $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}allocates` WHERE `type`= 4 AND `resource_id` = '{$_SESSION['user_id']}' ORDER BY `id` ASC;";
    //	6/10/11
    $result = mysql_query($query);
    //	6/10/11
    $a_gp_bounds = array();
    $gp_bounds = array();
    while ($row = stripslashes_deep(mysql_fetch_assoc($result))) {
        //	6/10/11
        $al_groups[] = $row['group'];
        $query2 = "SELECT * FROM `{$GLOBALS['mysql_prefix']}region` WHERE `id`= '{$row['group']}';";
        //	6/10/11
        $result2 = mysql_query($query2);
        // 4/18/11
        while ($row2 = stripslashes_deep(mysql_fetch_assoc($result2))) {
            //	//	6/10/11
            if ($row2['boundary'] != 0) {
                $a_gp_bounds[] = $row2['boundary'];
            }
        }
    }
    if (isset($_SESSION['viewed_groups'])) {
        //	6/10/11
        foreach (explode(",", $_SESSION['viewed_groups']) as $val_vg) {
            $query3 = "SELECT * FROM `{$GLOBALS['mysql_prefix']}region` WHERE `id`= '{$val_vg}';";
            $result3 = mysql_query($query3);
            //	6/10/11
            while ($row3 = stripslashes_deep(mysql_fetch_assoc($result3))) {
                if ($row3['boundary'] != 0) {
                    $gp_bounds[] = $row3['boundary'];
                }
            }
        }
    } else {
        $gp_bounds = $a_gp_bounds;
    }
    foreach ($gp_bounds as $value) {
        //	6/10/11
        ?>
		var points = new Array();
<?php 
        if ($value != 0) {
            $query_bn = "SELECT * FROM `{$GLOBALS['mysql_prefix']}mmarkup` WHERE `id`='{$value}'";
            $result_bn = mysql_query($query_bn) or do_error($query_bn, mysql_error(), basename(__FILE__), __LINE__);
            while ($row_bn = stripslashes_deep(mysql_fetch_assoc($result_bn))) {
                extract($row_bn);
                $bn_name = $row_bn['line_name'];
                $points = explode(";", $line_data);
                for ($i = 0; $i < count($points); $i++) {
                    $coords = explode(",", $points[$i]);
                    ?>
					thepoint = new GLatLng(parseFloat(<?php 
                    print $coords[0];
                    ?>
), parseFloat(<?php 
                    print $coords[1];
                    ?>
));
					points.push(thepoint);
<?php 
                }
                // end for ($i = 0 ... )
                ?>

<?php 
                if (intval($filled) == 1) {
                    //	6/10/11
                    ?>
				var polyline = new GPolygon(points, add_hash("<?php 
                    print $line_color;
                    ?>
"), <?php 
                    print $line_width;
                    ?>
, <?php 
                    print $line_opacity;
                    ?>
, add_hash("<?php 
                    print $fill_color;
                    ?>
"), <?php 
                    print $fill_opacity;
                    ?>
, {clickable:false});
				boundary.push(polyline);
				bound_names.push("<?php 
                    print $bn_name;
                    ?>
"); 			
				<?php 
                } else {
                    ?>
				var polyline = new GPolyline(points, add_hash("<?php 
                    print $line_color;
                    ?>
"), <?php 
                    print $line_width;
                    ?>
, <?php 
                    print $line_opacity;
                    ?>
, , 0, {clickable:false});
				boundary.push(polyline);
				bound_names.push("<?php 
                    print $bn_name;
                    ?>
"); 			
<?php 
                }
                ?>
				map.addOverlay(polyline);
<?php 
            }
            //	End while
        }
        //	end if $value !=0
    }
    //	end foreach $gp_bounds
    //-------------------------END OF BOUNDARIES STUFF-------------------------
    function can_do_dispatch($the_row)
    {
        if (intval($the_row['multi']) == 1) {
            return TRUE;
        }
        $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}assigns` WHERE `responder_id` = {$the_row['id']}";
        // all dispatches this unit
        $result_temp = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
        while ($row_temp = stripslashes_deep(mysql_fetch_array($result_temp))) {
            // check any open runs this unit
            if (!is_date($row_temp['clear'])) {
                // if  clear is empty, then NOT dispatch-able
                unset($result_temp, $row_temp);
                return FALSE;
            }
        }
        // end while ($row_temp ...)
        unset($result_temp, $row_temp);
        return TRUE;
        // none found, can dispatch
    }
    // end function can do_dispatch()
    $eols = array("\r\n", "\n", "\r");
    // all flavors of eol
    $bulls = array(0 => "", 1 => "red", 2 => "green", 3 => "white", 4 => "black");
    $status_vals = array();
    // build array of $status_vals
    $status_vals[''] = $status_vals['0'] = "TBD";
    $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}un_status` ORDER BY `id`";
    $result_st = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
    while ($row_st = stripslashes_deep(mysql_fetch_array($result_st))) {
        $temp = $row_st['id'];
        $status_vals[$temp] = $row_st['status_val'];
    }
    unset($result_st);
    $query_al = "SELECT * FROM `{$GLOBALS['mysql_prefix']}allocates` WHERE `type`= 4 AND `resource_id` = '{$_SESSION['user_id']}';";
    //	6/10/11
    $result_al = mysql_query($query_al);
    // 6/10/11
    $al_groups = array();
    while ($row_al = stripslashes_deep(mysql_fetch_assoc($result_al))) {
        //	6/10/11
        $al_groups[] = $row_al['group'];
    }
    if (isset($_SESSION['viewed_groups'])) {
        //	6/10/11
        $curr_viewed = explode(",", $_SESSION['viewed_groups']);
    }
    if (!isset($curr_viewed)) {
        $x = 0;
        //	6/10/11
        $where2 = "WHERE (";
        //	6/10/11
        foreach ($al_groups as $grp) {
            //	6/10/11
            $where3 = count($al_groups) > $x + 1 ? " OR " : ")";
            $where2 .= "`a`.`group` = '{$grp}'";
            $where2 .= $where3;
            $x++;
        }
    } else {
        $x = 0;
        //	6/10/11
        $where2 = "WHERE (";
        //	6/10/11
        foreach ($curr_viewed as $grp) {
            //	6/10/11
            $where3 = count($curr_viewed) > $x + 1 ? " OR " : ")";
            $where2 .= "`a`.`group` = '{$grp}'";
            $where2 .= $where3;
            $x++;
        }
    }
    $where2 .= "AND `a`.`type` = 2";
    //	6/10/11
    //-----------------------UNIT RING FENCE STUFF--------------------6/10/11
    ?>
	var thepoint;
	var points = new Array();
		
<?php 
    $query_bn = "SELECT * FROM `{$GLOBALS['mysql_prefix']}mmarkup` `l`\n\t\t\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}responder` `r` ON ( `l`.`id` = `r`.`ring_fence`)\n\t\t\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}allocates` `a` ON ( `r`.`id` = `a`.`resource_id` )\t\n\t\t\t\t{$where2} AND `use_with_u_rf`=1 GROUP BY `l`.`id`";
    $result_bn = mysql_query($query_bn) or do_error($query_bn, mysql_error(), basename(__FILE__), __LINE__);
    while ($row_bn = stripslashes_deep(mysql_fetch_assoc($result_bn))) {
        extract($row_bn);
        $bn_name = $row_bn['line_name'];
        $all_boundaries[] = $row_bn['ring_fence'];
        $points = explode(";", $line_data);
        for ($i = 0; $i < count($points); $i++) {
            $coords = explode(",", $points[$i]);
            ?>
			thepoint = new GLatLng(parseFloat(<?php 
            print $coords[0];
            ?>
), parseFloat(<?php 
            print $coords[1];
            ?>
));
			points.push(thepoint);
<?php 
        }
        // end for ($i = 0 ... )
        if (intval($filled) == 1) {
            //	6/10/11
            ?>
			var polyline = new GPolygon(points, add_hash("<?php 
            print $line_color;
            ?>
"), <?php 
            print $line_width;
            ?>
, <?php 
            print $line_opacity;
            ?>
, add_hash("<?php 
            print $fill_color;
            ?>
"), <?php 
            print $fill_opacity;
            ?>
, {clickable:false, id:"ringfence"});
			boundary.push(polyline);
			bound_names.push("<?php 
            print $bn_name;
            ?>
"); 
<?php 
        } else {
            ?>
			var polyline = new GPolyline(points, add_hash("<?php 
            print $line_color;
            ?>
"), <?php 
            print $line_width;
            ?>
, <?php 
            print $line_opacity;
            ?>
, , 0, {clickable:false, id:"ringfence"});
			boundary.push(polyline);
			bound_names.push("<?php 
            print $bn_name;
            ?>
"); 
<?php 
        }
        ?>
			map.addOverlay(polyline);
<?php 
    }
    //	End while
    //-------------------------END OF UNIT RING FENCE STUFF-------------------------
    //-----------------------UNIT EXCLUSION ZONE STUFF--------------------6/10/11
    ?>
	var thepoint;
	var points = new Array();
		
<?php 
    $query_bn = "SELECT * FROM `{$GLOBALS['mysql_prefix']}mmarkup` `l`\n\t\t\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}responder` `r` ON ( `l`.`id` = `r`.`excl_zone`)\n\t\t\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}allocates` `a` ON ( `r`.`id` = `a`.`resource_id` )\t\n\t\t\t\t{$where2} AND `use_with_u_ex`=1 GROUP BY `l`.`id`";
    $result_bn = mysql_query($query_bn) or do_error($query_bn, mysql_error(), basename(__FILE__), __LINE__);
    while ($row_bn = stripslashes_deep(mysql_fetch_assoc($result_bn))) {
        extract($row_bn);
        $bn_name = $row_bn['line_name'];
        $all_boundaries[] = $row_bn['ring_fence'];
        $points = explode(";", $line_data);
        for ($i = 0; $i < count($points); $i++) {
            $coords = explode(",", $points[$i]);
            ?>
			thepoint = new GLatLng(parseFloat(<?php 
            print $coords[0];
            ?>
), parseFloat(<?php 
            print $coords[1];
            ?>
));
			points.push(thepoint);
<?php 
        }
        // end for ($i = 0 ... )
        if (intval($filled) == 1) {
            //	6/10/11
            ?>
			var polyline = new GPolygon(points, add_hash("<?php 
            print $line_color;
            ?>
"), <?php 
            print $line_width;
            ?>
, <?php 
            print $line_opacity;
            ?>
, add_hash("<?php 
            print $fill_color;
            ?>
"), <?php 
            print $fill_opacity;
            ?>
, {clickable:false, id:"ringfence"});
			boundary.push(polyline);
			bound_names.push("<?php 
            print $bn_name;
            ?>
"); 
<?php 
        } else {
            ?>
			var polyline = new GPolyline(points, add_hash("<?php 
            print $line_color;
            ?>
"), <?php 
            print $line_width;
            ?>
, <?php 
            print $line_opacity;
            ?>
, , 0, {clickable:false, id:"ringfence"});
			boundary.push(polyline);
			bound_names.push("<?php 
            print $bn_name;
            ?>
"); 
<?php 
        }
        ?>
			map.addOverlay(polyline);
<?php 
    }
    //	End while
    //-------------------------END OF UNIT EXCLUSION ZONE STUFF-------------------------
    $query = "SELECT *, UNIX_TIMESTAMP(updated) AS `updated`,\n\t\t`t`.`id` AS `type_id`,\n\t\t`r`.`id` AS `unit_id`,\n\t\t`r`.`name` AS `name`,\n\t\t`s`.`description` AS `stat_descr`,\n\t\t`r`.`description` AS `unit_descr`, \n\t\t`r`.`ring_fence` AS `ring_fence`,\t\n\t\t`r`.`excl_zone` AS `excl_zone`,\t\t\n\t\t(SELECT  COUNT(*) as numfound FROM `{$GLOBALS['mysql_prefix']}assigns` \n\t\tWHERE `{$GLOBALS['mysql_prefix']}assigns`.`responder_id` = unit_id  AND  (`clear` IS NULL OR DATE_FORMAT(`clear`,'%y') = '00' )) AS `nr_assigned` \n\t\tFROM `{$GLOBALS['mysql_prefix']}responder` `r` \n\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}allocates` `a` ON ( `r`.`id` = a.resource_id )\t\t\t\n\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}unit_types` `t` ON ( `r`.`type` = t.id )\t\n\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}un_status` `s` ON ( `r`.`un_status_id` = s.id ) \t\t\n\t\t{$where2}  GROUP BY unit_id ORDER BY `nr_assigned` DESC,  `handle` ASC, `r`.`name` ASC ";
    // 2/1/10, 3/15/10, 6/10/11
    $result = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
    $num_units = mysql_affected_rows();
    $i = 0;
    // counter
    // =============================================================================
    $bulls = array(0 => "", 1 => "red", 2 => "green", 3 => "white", 4 => "black");
    $utc = gmdate("U");
    //									 ==========  major while() for RESPONDER ==========
    while ($row = stripslashes_deep(mysql_fetch_assoc($result))) {
        $ringfence = $row['ring_fence'];
        $resp_gps = get_allocates(2, $row['unit_id']);
        //	6/10/11
        $grp_names = "Groups Assigned: ";
        //	6/10/11
        $y = 0;
        //	6/10/11
        foreach ($resp_gps as $value) {
            //	6/10/11
            $counter = count($resp_gps) > $y + 1 ? ", " : "";
            $grp_names .= get_groupname($value);
            $grp_names .= $counter;
            $y++;
        }
        $grp_names .= " / ";
        $track_type = get_remote_type($row);
        $index = $row['icon_str'];
        // 4/28/11
        $the_on_click = my_is_float($row['lat']) ? " onClick = myclick({$i}); " : " onClick = myclick_nm({$row['unit_id']}); ";
        $the_bg_color = $GLOBALS['UNIT_TYPES_BG'][$row['icon']];
        // 2/1/10
        $the_text_color = $GLOBALS['UNIT_TYPES_TEXT'][$row['icon']];
        // 2/1/10
        $do_dispatch = can_do_dispatch($row);
        // 11/17/09
        $got_point = FALSE;
        print "\n\t\tvar i={$i};\n";
        $tofac = is_guest() ? "" : "&nbsp;&nbsp;<A HREF='{$_SESSION['unitsfile']}?func=responder&view=true&dispfac=true&id=" . $row['unit_id'] . "'><U>To Facility</U></A>&nbsp;&nbsp;";
        // 10/6/09
        $todisp = is_guest() || !can_do_dispatch($row) ? "" : "&nbsp;&nbsp;<A HREF='{$_SESSION['unitsfile']}?func=responder&view=true&disp=true&id=" . $row['unit_id'] . "'><U>Dispatch</U></A>&nbsp;&nbsp;&nbsp;";
        // 08/8/02, 9/19/09
        $toedit = !can_edit() ? "" : "&nbsp;&nbsp;<A HREF='{$_SESSION['unitsfile']}?func=responder&edit=true&id=" . $row['unit_id'] . "'><U>Edit</U></A>&nbsp;&nbsp;&nbsp;&nbsp;";
        // 5/11/10
        $totrack = intval($row['mobile']) == 0 || empty($row['callsign']) ? "" : "&nbsp;&nbsp;<SPAN onClick = do_track('" . $row['callsign'] . "');><B><U>Tracks</B></U></SPAN>";
        $temp = $row['un_status_id'];
        // 2/24/09
        $the_status = array_key_exists($temp, $status_vals) ? $status_vals[$temp] : "??";
        // 2/2/09
        $row_track = FALSE;
        if ($track_type > 0) {
            // get most recent position data
            $do_legend = TRUE;
            $query = "SELECT *,UNIX_TIMESTAMP(packet_date) AS `packet_date`, UNIX_TIMESTAMP(updated) AS `updated` FROM \n\t\t\t\t`{$GLOBALS['mysql_prefix']}tracks`\n\t\t\t\tWHERE `source`= '{$row['callsign']}' ORDER BY `packet_date` DESC LIMIT 1";
            // newest
            $result_tr = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
            $row_track = mysql_affected_rows() > 0 ? stripslashes_deep(mysql_fetch_assoc($result_tr)) : FALSE;
            $aprs_updated = $row_track['updated'];
            $aprs_speed = $row_track['speed'];
            if ($row_track && my_is_float($row_track['latitude'])) {
                if ($row['lat'] == 0.999999 && $row['lng'] == 0.999999) {
                    echo "\t\tvar point = new GLatLng(" . get_variable('def_lat') . ", " . get_variable('def_lng') . ");\n";
                } else {
                    echo "\t\tvar point = new GLatLng(" . $row_track['latitude'] . ", " . $row_track['longitude'] . "); // 677\n";
                }
                $got_point = TRUE;
            }
            unset($result_tr);
        }
        if (!$got_point && my_is_float($row['lat'])) {
            if ($row['lat'] == 0.999999 && $row['lng'] == 0.999999) {
                echo "\t\tvar point = new GLatLng(" . get_variable('def_lat') . ", " . get_variable('def_lng') . ");\n";
            } else {
                echo "\t\tvar point = new GLatLng(" . $row['lat'] . ", " . $row['lng'] . ");\t// " . __LINE__ . "\n";
            }
            $got_point = TRUE;
        }
        $update_error = strtotime('now - 6 hours');
        // set the time for silent setting
        //			if ($instam_updated < $update_error) {$the_bull = "<FONT COLOR = 'black'><B>{$GLOBALS['TRACK_2L'][$track_type]}</B></FONT>";}
        // end bullet stuff
        // name, handle
        $handle = htmlentities($row['handle'], ENT_QUOTES);
        // 7/7/11
        $sidebar_line = "<TD WIDTH='15%' TITLE = '{$handle}' {$the_on_click}><NOBR>{$handle}</NOBR></TD>";
        $name = htmlentities($row['name'], ENT_QUOTES);
        $sidebar_line .= "<TD WIDTH='20%' TITLE = '{$name}' {$the_on_click}><U><SPAN STYLE='width: 30%; background-color:{$the_bg_color};  opacity: .7; color:{$the_text_color};'><NOBR>" . addslashes(shorten($row['name'], 14)) . "</NOBR></SPAN></U></TD>";
        // 10/8/09
        // assignments 3/16/09, 3/15/10 - 8/30/10
        $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}assigns` \n\t\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}ticket` `t` ON (`{$GLOBALS['mysql_prefix']}assigns`.`ticket_id` = `t`.`id`)\n\t\t\tWHERE `responder_id` = '{$row['unit_id']}' AND (`clear` IS NULL OR DATE_FORMAT(`clear`,'%y') = '00' )";
        $result_as = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
        $row_assign = mysql_affected_rows() == 0 ? FALSE : stripslashes_deep(mysql_fetch_assoc($result_as));
        switch ($row_assign['severity']) {
            //color tickets by severity
            case $GLOBALS['SEVERITY_MEDIUM']:
                $severityclass = 'severity_medium';
                break;
            case $GLOBALS['SEVERITY_HIGH']:
                $severityclass = 'severity_high';
                break;
            default:
                $severityclass = 'severity_normal';
                break;
        }
        switch (mysql_affected_rows()) {
            // 8/29/10
            case 0:
                $the_disp_str = "";
                break;
            case 1:
                $the_disp_str = get_disp_status($row_assign) . "&nbsp;";
                break;
            default:
                // multiples
                $the_disp_str = "<SPAN CLASS='disp_stat'>&nbsp;" . mysql_affected_rows() . "&nbsp;</SPAN>&nbsp;";
                break;
        }
        // end switch()
        $onclick = mysql_affected_rows() > 0 ? " onClick = 'open_tick_window ({$row_assign['ticket_id']})'" : "";
        $ass_td = mysql_affected_rows() > 0 ? "<TD WIDTH='20%' CLASS='{$severityclass}' TITLE = '{$row_assign['scope']}'  {$onclick} ><NOBR>{$the_disp_str}" . shorten($row_assign['scope'], 24) . "</NOBR></TD>" : "<TD WIDTH='20%'>na</TD>";
        unset($result_as);
        $sidebar_line .= $row['nr_assigned'] . $row_assign ? $ass_td : "<TD WIDTH='20%'>na</TD>";
        //  status, mobility  - 4/14/10
        $sidebar_line .= "<TD WIDTH='20%' TITLE = '" . addslashes($the_status) . "'> " . get_status_sel($row['unit_id'], $row['un_status_id'], "u") . ($the_bull = "");
        // define the bullet
        if ($row_track['speed'] > 50) {
            $the_bull = "<FONT COLOR = 'white'><B>{$GLOBALS['TRACK_2L'][$track_type]}</B></FONT>";
        }
        if ($row_track['speed'] < 50) {
            $the_bull = "<FONT COLOR = 'green'><B>{$GLOBALS['TRACK_2L'][$track_type]}</B></FONT>";
        }
        if ($row_track['speed'] == 0) {
            $the_bull = "<FONT COLOR = 'red'><B>{$GLOBALS['TRACK_2L'][$track_type]}</B></FONT>";
        }
        $tip = htmlentities($row['callsign'], ENT_QUOTES);
        $tip_str = "onMouseover=\\\"Tip('{$tip}')\\\" onmouseout=\\\"UnTip();\\\" ";
        $sidebar_line .= "<TD WIDTH='2%' {$tip_str}>{$the_bull}</TD>";
        // 4/14/10
        // as of
        $the_time = $row['updated'];
        $the_class = "";
        $strike = $strike_end = "";
        $the_flag = $name . "_flag";
        if ($track_type > 0 && abs($utc - $the_time) > $GLOBALS['TOLERANCE']) {
            // attempt to identify  non-current values
            $strike = "<STRIKE>";
            $strike_end = "</STRIKE>";
        }
        $sidebar_line .= "<TD WIDTH='18%' CLASS='{$the_class}'> {$strike}<SPAN id = '" . $name . "'><NOBR>" . format_sb_date($the_time) . "</NOBR></SPAN>{$strike_end}&nbsp;&nbsp;<SPAN ID = '" . $the_flag . "'></SPAN></TD>";
        // 6/17/08
        // tab 1
        if (my_is_float($row['lat'])) {
            // position data? 4/29/09
            $temptype = $u_types[$row['type_id']];
            $the_type = $temptype[0];
            // 1/1/09
            $tab_1 = "<TABLE CLASS='infowin' width='{$iw_width}'>";
            $tab_1 .= "<TR CLASS='even'><TD COLSPAN=2 ALIGN='center'><B>" . addslashes(shorten($row['name'], 48)) . "</B> - " . $the_type . "</TD></TR>";
            $tab_1 .= "<TR CLASS='odd'><TD>Description:</TD><TD>" . addslashes(shorten(str_replace($eols, " ", $row['description']), 32)) . "</TD></TR>";
            $tab_1 .= "<TR CLASS='even'><TD>Status:</TD><TD>" . $the_status . " </TD></TR>";
            $tab_1 .= "<TR CLASS='odd'><TD>Contact:</TD><TD>" . addslashes($row['contact_name']) . " Via: " . addslashes($row['contact_via']) . "</TD></TR>";
            $tab_1 .= "<TR CLASS='even'><TD>As of:</TD><TD>" . format_date($the_time) . "</TD></TR>";
            // 4/11/10
            if (array_key_exists($row['unit_id'], $assigns)) {
                $tab_1 .= "<TR CLASS='even'><TD CLASS='emph'>Dispatched to:</TD><TD CLASS='emph'><A HREF='main.php?id=" . $tickets[$row['unit_id']] . "'>" . addslashes(shorten($assigns[$row['unit_id']], 20)) . "</A></TD></TR>";
            }
            $tab_1 .= "<TR CLASS='odd'><TD COLSPAN=2 ALIGN='center'>" . $tofac . $todisp . $totrack . $toedit . "&nbsp;&nbsp;<A HREF='{$_SESSION['unitsfile']}?func=responder&view=true&id=" . $row['unit_id'] . "'><U>View</U></A></TD></TR>";
            // 08/8/02
            $tab_1 .= "</TABLE>";
            // tab 2
            if ($row_track) {
                // do all three tabs
                $tab_2 = "<TABLE CLASS='infowin' width='{$iw_width}'>";
                $tab_2 .= "<TR CLASS='even'><TD COLSPAN=2 ALIGN='center'><B>" . $row_track['source'] . "</B></TD></TR>";
                $tab_2 .= "<TR CLASS='odd'><TD>Course: </TD><TD>" . $row_track['course'] . ", Speed:  " . $row_track['speed'] . ", Alt: " . $row_track['altitude'] . "</TD></TR>";
                $tab_2 .= "<TR CLASS='even'><TD>Closest city: </TD><TD>" . $row_track['closest_city'] . "</TD></TR>";
                $tab_2 .= "<TR CLASS='odd'><TD>Status: </TD><TD>" . $row_track['status'] . "</TD></TR>";
                if (array_key_exists('packet_date', $row_track)) {
                    $tab_2 .= "<TR CLASS='even'><TD>As of: </TD><TD> {$strike}" . format_date($row_track['packet_date']) . "{$strike_end} (UTC)</TD></TR></TABLE>";
                }
                ?>
			var myinfoTabs = [
				new GInfoWindowTab("<?php 
                print nl2brr(addslashes(shorten($row['name'], 10)));
                ?>
", "<?php 
                print $tab_1;
                ?>
"),
				new GInfoWindowTab("<?php 
                print $GLOBALS['TRACK_2L'][$track_type];
                ?>
 <?php 
                print addslashes(substr($row_track['source'], -3));
                ?>
", "<?php 
                print $tab_2;
                ?>
"),
				new GInfoWindowTab("Zoom", "<div id='detailmap' class='detailmap'></div>")
				];
<?php 
            } else {
                // two tabs
                ?>
			var myinfoTabs = [
				new GInfoWindowTab("<?php 
                print nl2brr(addslashes(shorten($row['name'], 10)));
                ?>
", "<?php 
                print $tab_1;
                ?>
"),
				new GInfoWindowTab("Zoom", "<div id='detailmap' class='detailmap'></div>")
				];
<?php 
            }
            // end if/else  ($row_track)
            if ($row['lat'] == 0.999999 && $row['lng'] == 0.999999) {
                // check for no maps mode entries 7/28/10
                ?>
		var the_class = ((map_is_fixed) && (!(mapBounds.containsLatLng(point))))? "emph" : "td_label";		// 4/3/09
		do_sidebar ("<?php 
                print $sidebar_line;
                ?>
", i, the_class, "<?php 
                print $row['icon_str'];
                ?>
");
		var dummymarker = createdummyMarker(point, myinfoTabs,<?php 
                print $row['icon'];
                ?>
, i, "<?php 
                print $index;
                ?>
");	// 771 (point,tabs, color, id)
		map.addOverlay(dummymarker);
<?php 
            } else {
                ?>
		var the_class = ((map_is_fixed) && (!(mapBounds.containsLatLng(point))))? "emph" : "td_label";		// 4/3/09
		do_sidebar ("<?php 
                print $sidebar_line;
                ?>
", i, the_class, "<?php 
                print $index;
                ?>
");
		var marker = createMarker(point, myinfoTabs,<?php 
                print $row['icon'];
                ?>
, i, "<?php 
                print $index;
                ?>
");	// 771 (point,tabs, color, id)
		map.addOverlay(marker);
<?php 
            }
        } else {
            print "\tdo_sidebar_nm (\" {$sidebar_line} \" , i, {$row['id']}, '{$index}');\n";
            // sidebar only - no map, 11/11/09, 5/12/10
        }
        $i++;
        // zero-based
    }
    // end  ==========  while() for RESPONDER ==========
    $source_legend = isset($do_legend) ? "<TD CLASS='emph' ALIGN='left'>Source time</TD>" : "<TD></TD>";
    // if any remote data/time 3/24/09
    ?>
	if (!(map_is_fixed)) {		// 4/3/09
		if (!points) {		// any?
			map.setCenter(new GLatLng(<?php 
    echo get_variable('def_lat');
    ?>
, <?php 
    echo get_variable('def_lng');
    ?>
), <?php 
    echo get_variable('def_zoom');
    ?>
);
			}
		else {
			center = bounds.getCenter();
			zoom = map.getBoundsZoomLevel(bounds);
			map.setCenter(center,zoom);
			}
		}

	side_bar_html+= "<TR CLASS='" + colors[i%2] +"'><TD COLSPAN=6>&nbsp;</TD><?php 
    print $source_legend;
    ?>
</TR>";
<?php 
    if (!empty($addon)) {
        print "\n\tside_bar_html +=\"" . $addon . "\"\n";
    }
    ?>
	side_bar_html +="</TABLE>\n";
	$("side_bar").innerHTML += side_bar_html;	// append the assembled side_bar_html contents to the side bar div
	$("num_units").innerHTML = <?php 
    print $num_units;
    ?>
;		

<?php 
    //	print "<TABLE BORDER = 4 >{$buttons}</TABLE>";
    do_kml();
    ?>

</SCRIPT>

<?php 
}
function list_responders($addon = '', $start)
{
    //	global {$_SESSION['fip']}, $fmp, {$_SESSION['editfile']}, {$_SESSION['addfile']}, {$_SESSION['unitsfile']}, {$_SESSION['facilitiesfile']}, {$_SESSION['routesfile']},	{$_SESSION['facroutesfile']};
    global $iw_width, $u_types, $tolerance;
    $assigns = array();
    // 08/8/3
    $tickets = array();
    // ticket id's
    $query = "SELECT `{$GLOBALS['mysql_prefix']}assigns`.`ticket_id`, `{$GLOBALS['mysql_prefix']}assigns`.`responder_id`,\n\t\t`{$GLOBALS['mysql_prefix']}ticket`.`scope` AS `ticket` \n\t\tFROM `{$GLOBALS['mysql_prefix']}assigns` \n\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}ticket` ON `{$GLOBALS['mysql_prefix']}assigns`.`ticket_id`=`{$GLOBALS['mysql_prefix']}ticket`.`id`\n\t\tWHERE ( `clear` IS NULL OR DATE_FORMAT(`clear`,'%y') = '00' )";
    $result_as = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
    while ($row_as = stripslashes_deep(mysql_fetch_array($result_as))) {
        $assigns[$row_as['responder_id']] = $row_as['ticket'];
        $tickets[$row_as['responder_id']] = $row_as['ticket_id'];
    }
    unset($result_as);
    $calls = array();
    // 6/17/08
    $calls_nr = array();
    ?>

<SCRIPT >

var color=0;
	var colors = new Array ('odd', 'even');

	function hideDiv(div_area, hide_cont, show_cont) {	//	3/15/11
		if (div_area == "buttons_sh") {
			var controlarea = "hide_controls";
			}
		if (div_area == "resp_list_sh") {
			var controlarea = "resp_list";
			}
		if (div_area == "facs_list_sh") {
			var controlarea = "facs_list";
			}
		if (div_area == "incs_list_sh") {
			var controlarea = "incs_list";
			}
		if (div_area == "region_boxes") {
			var controlarea = "region_boxes";
			}			
		var divarea = div_area 
		var hide_cont = hide_cont 
		var show_cont = show_cont 
		if($(divarea)) {
			$(divarea).style.display = 'none';
			$(hide_cont).style.display = 'none';
			$(show_cont).style.display = '';
			} 
		var params = "f_n=" +controlarea+ "&v_n=h&sess_id=<?php 
    print get_sess_key(__LINE__);
    ?>
";
		var url = "persist2.php";
		sendRequest (url, gb_handleResult, params);			
		} 

	function showDiv(div_area, hide_cont, show_cont) {	//	3/15/11
		if (div_area == "buttons_sh") {
			var controlarea = "hide_controls";
			}
		if (div_area == "resp_list_sh") {
			var controlarea = "resp_list";
			}
		if (div_area == "facs_list_sh") {
			var controlarea = "facs_list";
			}
		if (div_area == "incs_list_sh") {
			var controlarea = "incs_list";
			}
		if (div_area == "region_boxes") {
			var controlarea = "region_boxes";
			}				
		var divarea = div_area
		var hide_cont = hide_cont 
		var show_cont = show_cont 
		if($(divarea)) {
			$(divarea).style.display = '';
			$(hide_cont).style.display = '';
			$(show_cont).style.display = 'none';
			}
		var params = "f_n=" +controlarea+ "&v_n=s&sess_id=<?php 
    print get_sess_key(__LINE__);
    ?>
";
		var url = "persist2.php";
		sendRequest (url, gb_handleResult, params);					
		} 	

	function checkArray(form, arrayName)	{	//	5/3/11
		var retval = new Array();
		for(var i=0; i < form.elements.length; i++) {
			var el = form.elements[i];
			if(el.type == "checkbox" && el.name == arrayName && el.checked) {
				retval.push(el.value);
			}
		}
	return retval;
	}		
		
	function checkForm(form)	{	//	6/10/11
		var errmsg="";
		var itemsChecked = checkArray(form, "frm_group[]");
		if(itemsChecked.length > 0) {
			var params = "f_n=viewed_groups&v_n=" +itemsChecked+ "&sess_id=<?php 
    print get_sess_key(__LINE__);
    ?>
";	//	3/15/11
			var url = "persist3.php";	//	3/15/11	
			sendRequest (url, fvg_handleResult, params);				
//			form.submit();
		} else {
			errmsg+= "\tYou cannot Hide all the regions\n";
			if (errmsg!="") {
				alert ("Please correct the following and re-submit:\n\n" + errmsg);
				return false;
			}
		}
	}
	
	function fvg_handleResult(req) {	// 6/10/11	The persist callback function for viewed groups.
		document.region_form.submit();
		}
		
	function form_validate(theForm) {	//	5/3/11
//		alert("Validating");
		checkForm(theForm);
		}				// end function validate(theForm)			

	function do_sidebar (sidebar, id, the_class, unit_id, index) {
		var unit_id = unit_id;
		side_bar_html += "<TR CLASS='" + colors[(id)%2] +"' >";		
		side_bar_html += "<TD CLASS='" + the_class + "' onClick = 'myclick(" + unit_id + ");'>" + index + "</TD>" + sidebar +"</TD></TR>\n";	// 1/5/09, 3/4/09, 10/29/09 removed period
		}

	function myclick(unit_id) {				// Responds to sidebar click - view responder data
		document.view_form.id.value=unit_id;
		document.view_form.submit();
		}
		
	function myclick_nm(v_id) {				// Responds to sidebar click - view responder data
		document.view_form.id.value=v_id;
		document.view_form.submit();
		}

<?php 
    $dzf = get_variable('def_zoom_fixed');
    print "\tvar map_is_fixed = ";
    print my_is_int($dzf) && $dzf == 2 || my_is_int($dzf) && $dzf == 3 ? "true;\n" : "false;\n";
    ?>
	var side_bar_html = "<TABLE border=0 CLASS='sidebar' WIDTH = <?php 
    print max(320, intval($_SESSION['scr_width'] * 0.6));
    ?>
 >";
	side_bar_html += "<TR class='even'>	<TD></TD><TD ALIGN='left'><B>Unit</B></TD><TD ALIGN='left'><B>Handle</B></TD><TD ALIGN='left'><B>Dispatch</B></TD><TD ALIGN='left'><B>Status</B></TD><TD ALIGN='left'><B>M</B></TD><TD ALIGN='left'><B>As of</B></TD></TR>";
	var which;
	var i = <?php 
    print $start;
    ?>
;					// sidebar/icon index
	var points = false;								// none

<?php 
    function can_do_dispatch($the_row)
    {
        if (intval($the_row['multi']) == 1) {
            return TRUE;
        }
        $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}assigns` WHERE `responder_id` = {$the_row['id']}";
        // all dispatches this unit
        $result_temp = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
        while ($row_temp = stripslashes_deep(mysql_fetch_array($result_temp))) {
            // check any open runs this unit
            if (!is_date($row_temp['clear'])) {
                // if  clear is empty, then NOT dispatch-able
                unset($result_temp, $row_temp);
                return FALSE;
            }
        }
        // end while ($row_temp ...)
        unset($result_temp, $row_temp);
        return TRUE;
        // none found, can dispatch
    }
    // end function can_do_dispatch()
    $eols = array("\r\n", "\n", "\r");
    // all flavors of eol
    $bulls = array(0 => "", 1 => "red", 2 => "green", 3 => "white", 4 => "black");
    $status_vals = array();
    // build array of $status_vals
    $status_vals[''] = $status_vals['0'] = "TBD";
    $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}un_status` ORDER BY `id`";
    $result_st = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
    while ($row_st = stripslashes_deep(mysql_fetch_array($result_st))) {
        $temp = $row_st['id'];
        $status_vals[$temp] = $row_st['status_val'];
    }
    unset($result_st);
    $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}allocates` WHERE `type`= 4 AND `resource_id` = '{$_SESSION['user_id']}';";
    //	6/10/11
    $result = mysql_query($query);
    // 4/13/11
    $al_groups = array();
    while ($row = stripslashes_deep(mysql_fetch_assoc($result))) {
        //	6/10/11
        $al_groups[] = $row['group'];
    }
    if (isset($_SESSION['viewed_groups'])) {
        //	6/10/11
        $curr_viewed = explode(",", $_SESSION['viewed_groups']);
    }
    if (!isset($curr_viewed)) {
        $x = 0;
        //	6/10/11
        $where2 = "WHERE (";
        //	6/10/11
        foreach ($al_groups as $grp) {
            //	6/10/11
            $where3 = count($al_groups) > $x + 1 ? " OR " : ")";
            $where2 .= "`a`.`group` = '{$grp}'";
            $where2 .= $where3;
            $x++;
        }
    } else {
        $x = 0;
        //	6/10/11
        $where2 = "WHERE (";
        //	6/10/11
        foreach ($curr_viewed as $grp) {
            //	6/10/11
            $where3 = count($curr_viewed) > $x + 1 ? " OR " : ")";
            $where2 .= "`a`.`group` = '{$grp}'";
            $where2 .= $where3;
            $x++;
        }
    }
    $where2 .= "AND `a`.`type` = 2";
    //	6/10/11
    $query = "SELECT *, UNIX_TIMESTAMP(updated) AS `updated`,\n\t\t`t`.`id` AS `type_id`,\n\t\t`r`.`id` AS `unit_id`,\n\t\t`r`.`name` AS `name`,\n\t\t`s`.`description` AS `stat_descr`,\n\t\t`r`.`description` AS `unit_descr`, \n\t\t(SELECT  COUNT(*) as numfound FROM `{$GLOBALS['mysql_prefix']}assigns` \n\t\tWHERE `{$GLOBALS['mysql_prefix']}assigns`.`responder_id` = unit_id  AND `clear` IS NULL OR DATE_FORMAT(`clear`,'%y') = '00' ) AS `nr_assigned` \n\t\tFROM `{$GLOBALS['mysql_prefix']}responder` `r` \n\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}allocates` `a` ON ( `r`.`id` = a.resource_id )\t\t\t\n\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}unit_types` `t` ON ( `r`.`type` = t.id )\t\n\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}un_status` `s` ON ( `r`.`un_status_id` = s.id ) \t\t\n\t\t{$where2}  GROUP BY unit_id ORDER BY `nr_assigned` DESC,  `handle` ASC, `r`.`name` ASC ";
    // 2/1/10, 3/15/10, 6/10/11
    $result = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
    $num_units = mysql_affected_rows();
    $aprs = FALSE;
    $instam = FALSE;
    $locatea = FALSE;
    // 7/23/09
    $gtrack = FALSE;
    // 7/23/09
    $glat = FALSE;
    // 7/23/09
    $i = 0;
    // counter
    // =============================================================================
    $bulls = array(0 => "", 1 => "red", 2 => "green", 3 => "white", 4 => "black");
    $utc = gmdate("U");
    //									 ==========  major while() for RESPONDER ==========
    while ($row = stripslashes_deep(mysql_fetch_assoc($result))) {
        $resp_gps = get_allocates(2, $row['unit_id']);
        //	6/10/11
        $grp_names = "Groups Assigned: ";
        //	6/10/11
        $y = 0;
        //	6/10/11
        foreach ($resp_gps as $value) {
            //	6/10/11
            $counter = count($resp_gps) > $y + 1 ? ", " : "";
            $grp_names .= get_groupname($value);
            $grp_names .= $counter;
            $y++;
        }
        $grp_names .= " / ";
        $aprs = $instam = $locatea = $gtrack = $glat = $t_tracker = FALSE;
        // all trackers off, 5/11/11 added internal Tickets Tracker
        $temp = explode("/", $row['name']);
        $index = substr($temp[count($temp) - 1], -6, strlen($temp[count($temp) - 1]));
        // 3/19/11
        $the_on_click = my_is_float($row['lat']) ? " onClick = myclick({$row['unit_id']}); " : " onClick = myclick_nm({$row['unit_id']}); ";
        $the_bg_color = $GLOBALS['UNIT_TYPES_BG'][$row['icon']];
        // 2/1/10
        $the_text_color = $GLOBALS['UNIT_TYPES_TEXT'][$row['icon']];
        // 2/1/10
        $index = $row['icon_str'];
        // 4/28/11
        $track_type = get_remote_type($row);
        // 7/6/11
        $do_dispatch = can_do_dispatch($row);
        // 11/17/09
        $got_point = FALSE;
        print "\n\t\tvar i={$i};\n";
        $tofac = is_guest() ? "" : "&nbsp;&nbsp;<A HREF='{units_nm.php?func=responder&view=true&dispfac=true&id=" . $row['unit_id'] . "'><U>To Facility</U></A>&nbsp;&nbsp;";
        // 10/6/09
        $todisp = is_guest() || !can_do_dispatch($row) ? "" : "&nbsp;&nbsp;<A HREF='" . basename(__FILE__) . "?func=responder&view=true&disp=true&id=" . $row['unit_id'] . "'><U>Dispatch</U></A>&nbsp;&nbsp;&nbsp;";
        // 08/8/02, 9/19/09
        $toedit = is_guest() ? "" : "&nbsp;&nbsp;<A HREF='" . basename(__FILE__) . "?func=responder&edit=true&id=" . $row['unit_id'] . "'><U>Edit</U></A>&nbsp;&nbsp;&nbsp;&nbsp;";
        // 10/8/08
        $temp = $row['un_status_id'];
        // 2/24/09
        $the_status = array_key_exists($temp, $status_vals) ? $status_vals[$temp] : "??";
        // 2/2/09
        $the_bull = "";
        // define the bullet
        $update_error = strtotime('now - 6 hours');
        // set the time for silent setting
        if ($track_type > 0) {
            // get most recent position data
            $do_legend = TRUE;
        }
        // name, handle
        $name = addslashes(shorten($row['name'], 40));
        //	10/8/09
        $handle = addslashes($row['handle']);
        $sidebar_line = "<TD TITLE = '{$handle}' {$the_on_click}><U><SPAN STYLE='background-color:{$the_bg_color};  opacity: .7; color:{$the_text_color};'>{$handle}</SPAN></U></TD>";
        // 10/8/09
        $sidebar_line .= "<TD TITLE = '" . addslashes($row['name']) . "' {$the_on_click}><U>{$name}</TD>";
        // 10/8/09
        // assignments 3/16/09, 3/15/10
        $query = "SELECT * FROM `{$GLOBALS['mysql_prefix']}assigns` \n\t\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}ticket` `t` ON (`{$GLOBALS['mysql_prefix']}assigns`.`ticket_id` = `t`.`id`)\n\t\t\tWHERE `responder_id` = '{$row['unit_id']}' AND (`clear` IS NULL OR DATE_FORMAT(`clear`,'%y') = '00' )";
        $result_as = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
        $row_assign = mysql_affected_rows() == 0 ? FALSE : stripslashes_deep(mysql_fetch_assoc($result_as));
        switch ($row_assign['severity']) {
            //color tickets by severity
            case $GLOBALS['SEVERITY_MEDIUM']:
                $severityclass = 'severity_medium';
                break;
            case $GLOBALS['SEVERITY_HIGH']:
                $severityclass = 'severity_high';
                break;
            default:
                $severityclass = 'severity_normal';
                break;
        }
        switch (mysql_num_rows($result_as)) {
            // 10/4/10
            case 0:
                $the_disp_stat = "";
                break;
            case 1:
                $the_disp_stat = get_disp_status($row_assign) . "&nbsp;";
                break;
            default:
                // multiples
                $the_disp_stat = "<SPAN CLASS='disp_stat'>&nbsp;" . mysql_affected_rows() . "&nbsp;</SPAN>&nbsp;";
                break;
        }
        // end switch()
        $tick_ct = mysql_affected_rows() > 1 ? "(" . mysql_num_rows($result_as) . ") " : "";
        $ass_td = mysql_affected_rows() > 0 ? "<TD CLASS='{$severityclass}' TITLE = '{$row_assign['scope']}' STYLE = 'white-space:nowrap;' >{$the_disp_stat}" . shorten($row_assign['scope'], 24) . "</TD>" : "<TD>na</TD>";
        $sidebar_line .= $row_assign ? $ass_td : "<TD>na</TD>";
        // status, mobility  - 9/11/10
        $sidebar_line .= "<TD TITLE = '" . addslashes($the_status) . "'> " . get_status_sel($row['unit_id'], $row['un_status_id'], "u") . "</TD>";
        $sidebar_line .= "<TD TITLE ='{$row['callsign']}'>&nbsp;{$GLOBALS['TRACK_2L'][$track_type]}&nbsp;{$the_bull}</TD>";
        // 4/14/10
        // as of
        $strike = $strike_end = "";
        $the_time = $row['updated'];
        // 7/6/11
        $the_class = "";
        if ($row['mobile'] == 1 && abs($utc - $the_time) > $GLOBALS['TOLERANCE']) {
            // identify  non-current values
            $strike = "<STRIKE>";
            $strike_end = "</STRIKE>";
        }
        $sidebar_line .= "<TD CLASS='{$the_class}'> {$strike}" . format_sb_date($the_time) . "{$strike_end}</TD>";
        // 6/17/08
        ?>
		var unit_id = "<?php 
        print $index;
        ?>
";	//	10/8/09
	
		var the_class = "td_label";		// 4/3/09
		var handle = "<?php 
        print substr($row['handle'], 1);
        ?>
";
		var longhandle = "<?php 
        print $row['handle'];
        ?>
";
<?php 
        print "\tdo_sidebar(\" {$sidebar_line} \" , i, {$row['id']}, {$row['unit_id']}, unit_id);\n";
        // sidebar only - no map, 11/11/09
        $i++;
        // zero-based
    }
    // end  ==========  while() for RESPONDER ==========
    $source_legend = isset($do_legend) ? "<TD CLASS='emph' ALIGN='left'>Source time</TD>" : "<TD></TD>";
    // if any remote data/time 3/24/09
    ?>
	side_bar_html+= "<TR CLASS='" + colors[i%2] +"'><TD COLSPAN=5>&nbsp;</TD><?php 
    print $source_legend;
    ?>
</TR>";
<?php 
    if (!empty($addon)) {
        print "\n\tside_bar_html +=\"" . $addon . "\"\n";
    }
    ?>
	side_bar_html +="</TABLE>\n";
	$("side_bar").innerHTML += side_bar_html;	// append the assembled side_bar_html contents to the side bar div
	$("num_units").innerHTML = <?php 
    print $num_units;
    ?>
;			

</SCRIPT>

<?php 
}