<?php if(!defined('IN_PHPVMS') && IN_PHPVMS !== true) { die(); } ?>
<?php 
/**
 * iCrew v4 Premium - 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 Premium Services (with additions) 
 * Caution : NO SUPPORT WILL BE PROVIDED IF ANY MODULE / TEMPLATE IS FOUND TO BE TAMPERED WITH.
 * 
 */
 
 
 
 /*GENERAL IDEA 
	1. Get all the schedules based on the Pilot's Location.
	2. Display them from the Map. 
	3. When clicked, show a pop up (like vFleet Tracker) and add a href in that with GET method to the 
		schedules' UID and fetch Data.
 
 */
?>
<div class="mapcenter" align="center">
	<div id="routemap" style="width: 50%; height: 300px">
	  
	</div>
</div>

<script type="text/javascript">
var options= {
    mapTypeControlOptions: {
      mapTypeIds: []
    }, // here´s the array of controls
    disableDefaultUI: true, // a way to quickly hide all controls
    mapTypeControl: true,
    scaleControl: true,
    zoomControl: true,
    zoomControlOptions: {
      style: google.maps.ZoomControlStyle.LARGE 
    },
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    styles: [
    {
        "featureType": "all",
        "elementType": "all",
        "stylers": [
            {
                "invert_lightness": true
            },
            {
                "saturation": 10
            },
            {
                "lightness": 30
            },
            {
                "gamma": 0.5
            },
            {
                "hue": "#435158"
            }
        ]
    }
]

}

;


var map = new google.maps.Map(document.getElementById("routemap"), options);
var flightMarkers = [];

<?php 
$shown = array();
$allairports = OperationsData::GetAllAirports();
$last_location = PIREPData::getLastReports(Auth::$userinfo->pilotid, 1, PIREP_ACCEPTED);
      if(!$last_location)
      {
        $icao = Auth::$userinfo->hub;
      }
      else 
      {
        $icao = $last_location->arricao;  
      }
      
      $params = array('s.depicao' => $icao);
	  $schedules = SchedulesData::findSchedules($params, $count = '1');
      
	
		
foreach($schedules as $schedule)
{
	
$dep_airport = OperationsData::getAirportInfo($schedule->depicao);	
$arr_airport = OperationsData::getAirportInfo($schedule->arricao);	
?>

<?php /*To know the Current Airport's name*/
$currairport = OperationsData::getAirportInfo($last_location->arricao);
$curloc = $currairport->name;
?>


	dep_location = new google.maps.LatLng(<?php echo $dep_airport->lat?>, <?php echo $dep_airport->lng?>);
	arr_location = new google.maps.LatLng(<?php echo $arr_airport->lat?>, <?php echo $arr_airport->lng?>);
  /*cur_location = new google.maps.LatLng(<?php echo $currairport->lat; ?>, <?php echo $currairport->lng; ?>);*/
	
	
  
   // https://vamsys.io/assets/pages/img/bookFlight/
  var iconBase = ' http://dl.iflyva.in/img/maps/';
  var iconBase1 = 'http://maps.google.com/mapfiles/ms/micons/';
  
  flightMarkers[flightMarkers.length] = new google.maps.Marker({
    position: dep_location,
    map: map,
    title: '<?php echo $airport->icao.' '.$airport->name;?>',
    icon: iconBase + 'light_blue_marker_plane.png'
  });
  
  flightMarkers[flightMarkers.length] = new google.maps.Marker({
    position: arr_location,
    map: map,
    title: '<?php echo $airport->icao.' '.$airport->name;?>',
    icon: iconBase + 'light_blue_marker_plane.png'
  });
  
  var marker = new google.maps.Marker({
    position: dep_location,
    map: map,
    title: '<?php echo $last_location->arricao.' '.$curloc;  ?>',
    icon: iconBase1 + 'green-dot.png'
  });
  
  
	var flightPath = new google.maps.Polyline({
		path: [dep_location, arr_location],
		strokeColor: "#0095db",
		strokeOpacity: 0.6, 
		strokeWeight: 4,
		geodesic: true,
	}).setMap(map);
	
<?php
}
?>

if(flightMarkers.length > 0)
{
	var bounds = new google.maps.LatLngBounds();
	for(var i = 0; i < flightMarkers.length; i++) {
		bounds.extend(flightMarkers[i].position);
	}
}

map.fitBounds(bounds); 


</script>