<?php 
/**
 * iCrew v4 LITE - Virtual Airline Crew Center
 * Copyright (c) 2017 iCrewSystems
 * 
 * This CrewCenter & and it's Modules (which are distinguished, and limited to unless specified)
 * are protected by copyright under Indian Copyright Act, 1957, with the 2012 amendments
 * No part of the website design or layout may be reproduced or transmitted in any form or by any other 
 * means electronic or mechanical to include photocopying, recording, reproducing, or electronic storage.
 * Any such act represents a copyright violation and theft of intellectual property owned by iCrewSystems. 
 * 
 * @author: Leonard Selvaraja
 * @copyright: Copyright (c) 2017, iCrewSystems
 * @link http://www.icrewsystems.com
 * @service name: iCrewSystems Virtual Airline Intermediate Services (with additions) 
 * Caution : NO SUPPORT WILL BE PROVIDED IF ANY MODULE / TEMPLATE IS FOUND TO BE TAMPERED WITH.
 */
?>
<div class="row">
	<div class="col-md-12">
		<div class="col-md-12">
        <div class="widget">
			<div class="widget-simple themed-background-dark">
				<a href="javascript:void(0)" class="widget-icon pull-right themed-background">
					<i class="gi gi-google_maps animation-floating"></i>
				</a>
				<h4 class="widget-content widget-content-light themed-color-default">
					<strong><?php echo SITE_NAME ?></strong>
					<small>Airport Information Service</small><br>
					                                                               
				</h4>
			</div>	
			                              
			<div class="widget-extra">
				<h4 class="sub-header"><Strong><?php echo $name->name; ?></Strong></h4>
				<table width="100%">
	<tr>
	<td colspan="4"></td>
	</tr>
    <tr>
        <td><strong>ICAO:</strong></td>
        <td><?php echo $name->icao; ?></td>
        <td><strong>Country:</strong></td>
        <td><?php echo $name->country; ?></td>
    </tr>
    <tr>
        <td><strong>Latitude:</strong></td>
        <td><?php echo $name->lat; ?></td>
         <td><strong>Longitude:</strong></td>
        <td><?php echo $name->lng; ?></td>
    </tr>
    <tr>
    <td colspan="4"></td>
    </tr>
    <tr>
    	<?php $icao = $name->icao;
	$params = array(
           'depicao'   => $icao,
           'accepted'  => '1'
          );
	$pireps = PIREPData::findPIREPS($params, 1);
	$deppirep = $pireps[0];
	$params = array(
           'arricao'   => $icao,
           'accepted'  => '1'
          );
	$pireps = PIREPData::findPIREPS($params, 1);
	$arrpirep = $pireps[0];
	?>
<?php $initialdep = substr($deppirep->firstname,0,1); ?>
<?php $initialarr = substr($arrpirep->firstname,0,1); ?>
        
    </tr>
    
	<tr>
		<td>Latest Arrival :</td>
		<td><a class="btn btn-success btn-md" data-toggle="tooltip" data-placement="top" title="<?php echo $arrpirep->firstname.' '.$arrpirep->lastname ?>" href="<?php echo SITE_URL?>/index.php/pireps/viewreport/<?php echo $arrpirep->pirepid;?>"><?php echo $arrpirep->code.$arrpirep->flightnum.' ('.$arrpirep->depicao.'-'.$arrpirep->arricao.')</a> '?></td>
		<td>Latest Departure :</td>
		<td><a class="btn btn-danger btn-md" data-toggle="tooltip" data-placement="top" title="<?php echo $deppirep->firstname.' '.$deppirep->lastname ?>" href="<?php echo SITE_URL?>/index.php/pireps/viewreport/<?php echo $deppirep->pirepid;?>"><?php echo $deppirep->code.$deppirep->flightnum.' ('.$deppirep->depicao.'-'.$deppirep->arricao.')</a> '?></td>
	</tr>
    <tr>
        <td class="apthead" colspan="4"></td>
    </tr>
    <tr>
    	<td colspan="4"><a target="_blank" href="<?php echo $name->chartlink;?>"></a></td>
    </tr>
</table>
<hr>
<p>
	<h3>
		<br>WX Capture<strong><sup class="text-danger btn btn-xs"><i>LIVE</i></sup></strong>
		<br><small>Data provided by noaa.gov | Fetched at <?php echo date("H:i:s"); ?></small>
	</h3>

<address>
<strong>METAR :</strong>	<?php echo AirportData::getMetar($name->icao); ?><br><br>
<strong>TAF :</strong>	<?php echo AirportData::getTaf($name->icao); ?>
</address>

</p>

<br />
<h3> <strong>Runway Data</strong> for <?php echo $name->icao; ?><br>
	<small><span class="text-muted">Data provided by openaviationdata.com</span></small>
</h3>

<table class="table table-bordered table-striped">
<tr>
<th>Runway ID</th>
<th>Mag Var</th>
<th>Hdg</th>
<th>Length</th>
<th>Elevation</th>
<th>Surface</th>
<th>ILS Freq</th>
<th>ILS Id</th>
<th>ILS Slope</th>
</tr>
<?php $runways = AirportData::getrunwaysforairport($name->icao); ?>
<?php if($runways) foreach($runways as $runway) { ?>
<tr>
<td align="center"><?php echo $runway->RunwayID; ?></td>
<td align="center"><?php echo $runway->MagVar; ?></td>
<td align="center"><?php echo $runway->Hdg; ?>&deg;</td>
<td align="center"><?php echo $runway->Len; ?>&nbsp;ft</td>
<td align="center"><?php echo $runway->Altitude; ?>&nbsp;ft</td>
<td align="center"><?php echo $runway->Def; ?></td>
<?php if ($runway->ILSFreq == 0){ ?>
<td align="center">--</td>
<td align="center">--</td>
<td align="center">--</td>	
<?php } else {?>
<td align="center"><?php echo $runway->ILSFreq; ?></td>
<td align="center"><?php echo $runway->ILSid; ?></td>
<td align="center"><?php echo $runway->ILSslope; ?></td>
</tr>
<?php }} ?>
</tr>
</table>
<br />
<h3><strong><?php echo $name->name;?>, <?php echo $name->country; ?></strong><br>
	<small>Use only for reference purposes</small>
</h3>
</br>

<script type="text/javascript">
// var map;
// var gmarkers = [];
// var currentInfoWindow;
// var currentInfoWindow_airport;
// var icon = "<?php echo SITE_URL?>/core/templates/airportinfo/airport_runway.png"
// var icon_airport = "<?php echo SITE_URL?>/core/templates/airportinfo/airport_terminal.png"
// /* var bounds = new google.maps.LatLngBounds();  */

// function initialize() {
    
// var myLatlng = new google.maps.LatLng(<?php echo $name->lat; ?> , <?php echo $name->lng; ?>);
// var mapOptions = {
//             zoom: 14,
// 			zoomControlOptions: {style : google.maps.ZoomControlStyle.SMALL},
// 			center: myLatlng,
//             mapTypeId: google.maps.MapTypeId.SATELLITE
// }



// map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

// /* bounds.extend(myLatlng); */
	
// $.getJSON('<?php echo SITE_URL?>/runways/index.php?icao=<?php echo $name->icao; ?>', function(json1) {
//         $.each(json1, function(key, data) {
// 			/* if (data.ILSid == 0)  {
//             var contentString = data.icao + '\n' + data.ICAOName + '\n' + data.Country + '\nRunway: ' + data.RunwayID + "\nLen: " + data.Len + "\nElev: " + data.Altitude;
// 			} else {
//             var contentString = data.icao + '\n' + data.ICAOName + '\n' + data.Country + '\nRunway: ' + data.RunwayID + " (" + data.ILSid + ") \nFrequency: " + data.ILSFreq + "\nLen: " + data.Len + "\nElev: " + data.Altitude;
// 			} */
// 			var pos = new google.maps.LatLng(data.Latitude,data.Longitude);
//             var airport = new google.maps.Marker({
//                 position: pos,
// 				icon: icon_airport
// 				/* title: data.icao + '\n' + data.ICAOName + '\n' + data.Country + '\n' + data.RunwayID + " (" + data.ILSid + ") \nFrequency: " + data.ILSFreq + "\nLen: " + data.Len + "\nElev: " + data.Altitude
// 				title: contentString */
// 			});
			
// 			airport.setMap(map);
			
//             var latlng = new google.maps.LatLng(data.Lat,data.Lon);
			
// 			/* bounds.extend(latlng); */
                                                                                      
//             var marker = new google.maps.Marker({
//                 position: latlng,
// 				icon: icon
// 				/* title: data.icao + '\n' + data.ICAOName + '\n' + data.Country + '\n' + data.RunwayID + " (" + data.ILSid + ") \nFrequency: " + data.ILSFreq + "\nLen: " + data.Len + "\nElev: " + data.Altitude
// 				title: contentString */
// 			});
			
// 			marker.setMap(map);
// 			gmarkers.push(marker);
			
// 			var a = '<div class="iwapt"><table><tr><th>' + this.ICAOName + ' - ' + this.icao + '<\/th><\/tr>';
// 			a+= '<tr><td>' + this.City + ' (' + this.Country + ')<\/td><\/tr>';
// 			a+= '<\/table><\/div>';
// 			a+= '<table><tr><td>Runways: ' + gmarkers.length + '<\/tr><\/td><\/tr><\/table>';
// 			a+= '<table><tr><td>Elevation: ' + this.Altitude + ' ft<\/tr><\/td><\/tr><\/table>';
// 			a+= '<table><tr><td>Magvar: ' + this.MagVar + '<\/tr><\/td><\/tr><\/table>';
			
// var infowindow_airport = new google.maps.InfoWindow({
// content: a,
// shadowStyle: 0,  
// padding: 10, 
// backgroundColor: 'rgb(255,255,255)',  
// borderRadius: 0, 
// arrowSize: 10, 
// borderWidth: 3,  
// borderColor: '#009EE0', 
// disableAutoPan: true, 
// hideCloseButton: true, 
// arrowPosition: 50,  
// arrowStyle: 0, 
// disableAnimation: false,  
// minWidth :   300
// });

// google.maps.event.addListener(airport, 'mouseover', function() {
//   /*  if (currentInfoWindow_airport != null) {
//         currentInfoWindow_airport.close();
//     } */
//     infowindow_airport.open(map, this);
//     currentInfoWindow_airport = infowindow_airport;
// });	
// google.maps.event.addListener(airport, "mouseout", function () {
// 	currentInfoWindow_airport.close(map, this);
// 	currentInfoWindow_airport = infowindow_airport;
// });
			

// 			if (this.ILSid == 0)  {
// 			var content = '<div class="iwapt"><table><tr><th>' + this.ICAOName + ' - ' + this.icao + '<\/th><\/tr>';
// 			content+= '<tr><td>' + this.City + ' (' + this.Country + ')<\/td><\/tr>';
// 			content+= '<\/table><\/div>';
// 			content+= '<div class="iwils"><table><tr><th colspan="2">Runway: ' + this.RunwayID + '<\/th><\/tr>';
// 			content+= '<tr><td>Heading:<\/td>';
// 			content+= '<td>' + this.Hdg + ' °<\/td>';
// 			content+= '<tr><td>Elevation:<\/td>';
// 			content+= '<td>' + this.Altitude + ' ft<\/td>';
// 			content+= '<tr><td>Length:<\/td>';
// 			content+= '<td>' + this.Len + ' ft<\/td>';
// 			content+= '<\/tr><\/table><\/div>';
			
// 			/* var content = '<p style="color:blue;">' + this.icao + "<br>" + this.ICAOName+ "<br>" + this.Country + "<br>Runway: " + this.RunwayID + "<br>Len: " + this.Len + "<br>Elev: " + this.Altitude + '</p>'; */
			
// 			} else {
// 			var content = '<div class="iwapt"><table><tr><th>' + this.ICAOName + ' - ' + this.icao + '<\/th><\/tr>';
// 			content+= '<tr><td>' + this.City + ' (' + this.Country + ')<\/td><\/tr>';
// 			content+= '<\/table><\/div>';
// 			content+= '<div class="iwils"><table><tr><th colspan="2">Runway: ' + this.RunwayID + " - " + this.ILSid + '<\/th><\/tr>';
// 			content+= '<tr><td>Frequency:<\/td>';
// 			content+= '<td>' + this.ILSFreq + '<\/td><\/tr>';
// 			content+= '<tr><td>ILS Slope:<\/td>';
// 			content+= '<td>' + this.ILSslope + ' °<\/td>';
// 			content+= '<tr><td>Heading:<\/td>';
// 			content+= '<td>' + this.Hdg + ' °<\/td>';
// 			content+= '<tr><td>Elevation:<\/td>';
// 			content+= '<td>' + this.Altitude + ' ft<\/td>';
// 			content+= '<tr><td>Length:<\/td>';
// 			content+= '<td>' + this.Len + ' ft<\/td>';
// 			content+= '<\/tr><\/table><\/div>';
				
// 			/* var content = '<p style="color:blue;">' + this.icao + "<br>" + this.ICAOName+ "<br>" + this.Country + "<br>Runway: " + this.RunwayID + " (" + this.ILSid + ") <br>Frequency: " + this.ILSFreq + "<br>Len: " + this.Len + "<br>Elev: " + this.Altitude + '</p>';*/
// 			}
			
// var infowindow = new google.maps.InfoWindow({
// content: content,
// shadowStyle: 0,  
// padding: 10, 
// backgroundColor: 'rgb(255,255,255)',  
// borderRadius: 0, 
// arrowSize: 10, 
// borderWidth: 3,  
// borderColor: '#009EE0', 
// disableAutoPan: true, 
// hideCloseButton: true, 
// arrowPosition: 50,  
// arrowStyle: 0, 
// disableAnimation: false,  
// minWidth :   300
// });

// /* if (gmarkers.length <= 2){
// 	 map.setZoom(14);
// }
// if (gmarkers.length >= 4){
// 	map.setZoom(9);
// } */
	

// google.maps.event.addListener(gmarkers[gmarkers.length - 1], 'click', function() {
//     if (currentInfoWindow != null) {
//         currentInfoWindow.close();
//     }
//     infowindow.open(map, this);
//     currentInfoWindow = infowindow;
// 	/* map.panTo(latlng); */
// });
	
// }); 
// });

// /* map.fitBounds(bounds);	 */

// }

// google.maps.event.addDomListener(window, 'load', initialize);

// function zoomTo(level) {
//         google.maps.event.addListener(map, 'zoom_changed', function () {
//             zoomChangeBoundsListener = google.maps.event.addListener(map, 'bounds_changed', function (event) {
//                 if (this.getZoom() > level && this.initialZoom == true) {
//                     this.setZoom(level);
//                     this.initialZoom = false;
//                 }
//                 google.maps.event.removeListener(zoomChangeBoundsListener);
//             });
//         });
// }

//   function initialize() {
//         var mapDiv = document.getElementById('map-canvas');
//         var map = new google.maps.Map(mapDiv, {
//           center: new google.maps.LatLng(<?php echo $name->lat; ?> , <?php echo $name->lng; ?>),
//           zoom: 14,
// 		  zoomControlOptions: {
// 		  style : google.maps.ZoomControlStyle.SMALL},
//           mapTypeId: google.maps.MapTypeId.SATELLITE
//         });
//   } 		


// google.maps.event.addDomListener(window, 'load', initialize);
</script>
<style type="text/css">
.cadre_carte{
   width:95%;
  /*height:690px;*/
  margin:0 auto;
  padding:5px;
  border-radius:5px;
  border:1px solid #CCC;
  box-shadow: 0 2px 4px 2px #CCC;
}
</style>
<!--<div class="cadre_carte">-->
<!--<div id="map-canvas" style="width:100%; height: 600px"></div>-->
<!--</div>-->

<div class="mapcenter" align="center">
	<div id="routemap" style="width: 80%; height: <?php echo Config::Get('MAP_HEIGHT')?>"></div>
</div>
<script src="<?php echo SITE_URL?>/lib/js/base_map.js"></script>
<script type="text/javascript">
 const map = createMap({
   	render_elem: 'routemap',
   	provider: '<?php echo Config::Get("MAP_TYPE"); ?>',
   });
   
   map.setView(new L.LatLng(<?php echo $name->lat; ?>, <?php echo $name->lng; ?>), 4);
	
	var airport_coords = {lat: <?php echo $name->lat; ?>, lng: <?php echo $name->lng; ?>};
 const marker = L.marker(airport_coords).addTo(map);
   
   

</script>
<hr>
<span class="text-muted">
	Not for navigational purposes. 
	<br><br>
</span>

				</div>
			</div>
		</div>
	</div>
</div>
		
			