<?php 
   Template::show('ICSTourAdmin/header');
   //CodonEvent::Dispatch('pirep_filed', 'PIREPS');
   ?>
<div class="row">
   <div class="col-md-12">
      <div class="card">
         <div class="card-body mx-4">
         	<h3>Editing Leg # <?php echo $leg->legid; ?></h3>
            <!--Header-->
            <p>
            	Please be very careful about the airports. Sometimes you might break the continuity of the airports. 
            </p>
            <form class="form" action="<?php echo adminurl('ICSTourAdmin/edit_leg_airports_process'); ?>" method="POST" enctype="multipart/form-data">
             <div class="md-form">
                  <span class="input-text">Departure Airport</span>
                  <select name="depicao" required class="js-example-basic-single">
                     <?php 
                        foreach ($airports as $airport) {
                        	if($leg->depicao == $airport->icao){
                        		$selected = "selected";
                        	} else {
                        		$selected = "";
                        	}
                        	?>
                     <option value="<?php echo $airport->icao; ?>" <?php echo $selected; ?>><?php echo $airport->icao.' '.$airport->name; ?></option>
                     <?php
                        }
                        ?>
                  </select>
               </div>
               
               <div class="md-form">
                  <span class="input-text">Arrival Airport</span>
                   <select name="arricao" required class="js-example-basic-single">
                     <?php 
                        foreach ($airports as $airport) {
                        	if($leg->arricao == $airport->icao){
                        		$selected = "selected";
                        	} else {
                        		$selected = "";
                        	}
                        	?>
                     <option value="<?php echo $airport->icao; ?>" <?php echo $selected; ?>><?php echo $airport->icao.' '.$airport->name; ?></option>
                     <?php
                        }
                        ?>
                  </select>
               </div>
               
                <script>
                  $(document).ready(function() {
                  $('.js-example-basic-single').select2();
                  });
               </script>
               <div class="text-center mb-3">
                  <input type="hidden" name="id" value="<?php echo $leg->id; ?>" />
                  <input type="hidden" name="legid" value="<?php echo $leg->legid; ?>" />
                  <input type="hidden" name="tourid" value="<?php echo $leg->tourid; ?>" />
                  <input type="hidden" name="action" value="<?php echo $action; ?>" />
                  <input type="submit" name="submit" value="<?php echo $action; ?>" class="btn btn-success btn-md" />
                </form>
                    <button class="btn btn-danger btn-md" onclick="goBack();">Go back</button>
                <script>
                    function goBack() {
                    	window.history.back();
                    }
				</script>
               </div>
         </div>
      </div>
   </div>
</div>