<div class="row">
	<div class="col-md-12">
		<div class="content-header">
			<div class="header-section">
				<h1>
				 Roster <Strong>Generator</Strong><br><small><?php echo SITE_NAME ?> | Flight Operations &copy; <?php echo date("Y"); ?></small>
				</h1>
			</div>
		</div>
		
		


				<form id="rosterForm" action="<?php echo SITE_URL; ?>/index.php/schedules/generateRosters" method="post">
					<input type="hidden" name="depicao" value="<?php echo $_POST['depicao']; ?>" />
					<input type="hidden" name="equipment" value="<?php echo $_POST['equipment']; ?>" />
					<input type="hidden" name="count" value="<?php echo $_POST['count']; ?>" />
					<input type="hidden" name="duration" value="<?php echo $_POST['duration']; ?>" />
				</form>
			
		<div class="block">
			<div class="block-title">
				<h3><Strong>Avialable</Strong> Itienary</h3>
				<div class="block-options pull-right">
				<a href="<?php echo SITE_URL?>/index.php/schedules" class="btn btn-alt btn-sm btn-default">Go Back</a>
				<a href="javascript::void(0);" onclick="document.getElementById('rosterForm').submit();" id="rosterRefresh" class="btn btn-alt btn-sm btn-success">Refresh</a>
			</div>
			</div>
			
			<div class="alert alert-success">
				<strong>Attention</strong>
				<br> The Roster Generator algorithm generates the trips with the airline profit and the aircraft availability factor in mind. If you are not comfortable with the generated roster, you can always opt to regenerate.
				
			</div>
	<div class="progress progress-striped active">
		<div class="progress-bar progress-bar-success" id="rosterGenerationProgressmonitor" role="progressbar" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="height:24px;width:1%"></div>
	</div>
		<p id="myP"><span class="" id="parameter"></span></p>  



	
			<table id="itenaryTable" class="table table-hover" style="visibility: hidden;">
				  			<thead>
								<tr>
									<th><div align="center">Flight #</div></th>
									<th><div align="center">Departure</div></th>
									<th><div align="center">Arrival</div></th>
									<th><div align="center">Registration</div></th>
									<th><div align="center">Duration</div></th>
								</tr>
							</thead>
							
							<tbody>
								<?php 
								
									foreach ($roster as $ros) {
										$schedule = SchedulesData::getScheduleDetailed($ros);
										?>
										<tr class="text-center">
											<td><?php echo $schedule->code.$schedule->flightnum; ?></td>
											<td><?php echo $schedule->depicao; ?></td>
											<td><?php echo $schedule->arricao; ?></td>
											<td><?php echo $schedule->aircraft; ?></td>
											<td><?php echo $schedule->flighttime; ?></td>
										</tr>
										
										<?php
										$flighttime_s = $flighttime_s + $schedule->flighttime;
									}
							
							?>
						</tbody>
	
</table>  
<hr>
	<form style="visibility: hidden" id="bidButton" name="bidAll" id="bidAll" action="<?php echo SITE_URL?>/index.php/randomflights/bidAll" method="post">
		<?php
		for($i = 0; $i < count($schedules); $i++)
		{
		?>
		<input type="hidden" name="schedules[<?php echo $i;?>]" value="<?php echo $schedules[$i]->id;?>">
		<?php
		}
		?>		
		<input type="hidden" name="count" value = "<?php echo count($schedules);?>">
		<input type="hidden" name="pilotid" value="<?php echo Auth::$userinfo->pilotid;?>">	
	
		<center>	
		<span class="text-muted h3 text-center">
					Estimated flight time <?php echo $flighttime_s; ?> Hours
				</span>
					<br><br>
			<button type="submit" class="btn btn-block btn-success" name ="submit" value="">Bid this Roster</button>
		</center><br>
	
	</form>
		

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


<script>
function move() {
  var elem = document.getElementById("rosterGenerationProgressmonitor");   
  var width = 0;
  var rand = Math.round(Math.random() * (100 - 20)) + 20; 
  var id = setInterval(frame, rand);
  var parameter = document.getElementById("parameter");
  
  
  function frame() {
    if (width >= 100) {
      clearInterval(id);
      document.getElementById("myP").className = "h3 small text-muted";
      document.getElementById("itenaryTable").style.visibility = "visible";
      document.getElementById("bidButton").style.visibility = "visible";
      
      document.getElementById("rosterGenerationProgressmonitor").style.visibility = "invisible";
      document.getElementById("myP").innerHTML = "Completed, Instance ID " + "<?php echo base64_encode(date('H:i:s d/m/y').' '.Auth::$userinfo->firstname.' '.Auth::$userinfo->lastname); ?>";
    } 
    
    else if (width > 0 && width < 20) {
       width++; 
      elem.style.width = width + '%'; 
      parameter.innerHTML = "Initializing database and matching with requested parameters" ;
      parameter.className = "label label-warning";
    }
    
     else if (width > 30 && width < 45) {
       width++; 
      elem.style.width = width + '%'; 
      parameter.innerHTML = "Calculating profitable routes from <?php echo $_POST['depicao']; ?> with <?php echo $_POST['equipment']; ?> " ;
      parameter.className = "label label-warning";
    }
    
    else if (width > 50 && width < 70) {
       width++; 
      elem.style.width = width + '%'; 
      parameter.innerHTML = "<?php echo $_POST['depicao']; ?> profit index acquired, finding flights..." ;
      parameter.className = "label label-info";
    }
    
    else if (width > 80 && width < 90) {
       width++; 
      elem.style.width = width + '%'; 
      parameter.innerHTML = "Generating your itenary..." ;
      parameter.className = "label label-success";
    }
    
    else {
      width++; 
      elem.style.width = width + '%'; 
    }
  }
}

$(function() {
   move();
});
</script>


