<?php 
   Template::show('ICSTourAdmin/header');
   ?>
<div class="row">
   <div class="col-md-12">
      <div class="card">
         <div class="card-body mx-4">
         	<h3>Step 3 </h3>
         	<form class="form" action="<?php echo adminurl('ICSTourAdmin/process'); ?>" method="POST" enctype="multipart/form-data">
               
               <p>
               		You are adding legs for "<?php echo $title; ?>"
               </p>
               
               There are totally <?php echo $total_legs; ?> legs for this tour. 
               
            	
               
				
				<table class="table">
					<thead>
						<tr>
							<th>Leg ID#</th>
							<th>Departure</th>
							<th>Destination</th>
							<th>Sync</th>
						</tr>
					</thead>
					<tbody>
				<?php 
				
				
				
					for($i = 1; $i <= $total_legs; $i++) {
						 
						 $previous_arr = 'arr_'.($i - 1);
						 $dep = 'dep_'.$i;
						 $arr = 'arr_'.$i;
						?>
						<tr>
							<td>Leg #<?php echo $i; ?></td>
							<td>
								<input name="dep_<?php echo $i; ?>" required class="form-control" value="<?php echo $_POST[$dep]; ; ?>">
							</td>
							<td>
								<input name="arr_<?php echo $i; ?>" required class="form-control" value="<?php echo $_POST[$arr]; ; ?>">
							</td>
							<td>
								<?php 
								
								if($i != 1) {
									if($_POST[$previous_arr] == $_POST[$dep]) {
										echo "Airports are synchronized <i class='fa fa-check'></i>";
									} else {
										echo "Departure leg not synchronized";
									}
								} else {
										echo "First Leg";
								}
								?>
							</td>
						</tr>
						<?php
					}
				?>
					</tbody>
				</table>
               
               
               
                <script>
                     $(document).ready(function() {
                     $('.js-example-basic-single').select2();
                     });
                  </script>
               
               
               <div class="text-center mb-3">
               	<?php 
               		foreach ($_POST as $post => $key) {
               			if($post == 'action' || $post == 'submit') {
               				
               			} else {
               				echo $post.': '.$key;
               				echo "<br>";
               				?>
               				<input type="hidden" name="<?php echo $post; ?>" value="<?php echo $key; ?>" />
               				<?php
               			}
               		}
               	?>
               	
                  <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>
</div>