<?php require_once(APPPATH.'views/diy_tour/public/header.php');?>
<title>International Flights Search Result</title>
<meta name="keywords" content="china flights, china flight, flights china"/>
<meta name="description" content="internal air ticket availability for flights within China"/>
<link type="text/css" rel="stylesheet" href="/min/f=/css/bootstrap/css/jquery-ui-1.10.0.custom.css,/css/bootstrap/css/jquery.suggest.css" />
<?php require_once(APPPATH.'views/diy_tour/public/nav.php');?>

<div id="content" class="container-fluid">
  <div class="row">
    
    <div class="col-sm-5 hidden">
      <div class="col-xs-24 btn-lg"></div>
      <h4><legend>Filter</legend></h4>
      <div class="col-xs-24 nopadding flight_filter">
        <strong>Stops</strong> 
        <div class="checkbox" data-flightitem="stop">
          <label>
            <input type="checkbox" value="Nonstop" class="checkbox_stop"> Nonstop
          </label>
          <label>
            <input type="checkbox" value="1 stop" class="checkbox_stop"> 1 Stop
          </label>
        </div>
      </div>
      
      <legend></legend>
      <div class="col-xs-24 nopadding flight_filter">
        <strong>Departure time</strong> 
        <div class="checkbox" data-flightitem="departuretime">
          <label>
            <input type="checkbox" value="6" class="checkbox_departure"> 00:00-06:00
          </label>
          <label>
            <input type="checkbox" value="12" class="checkbox_departure"> 06:00-12:00
          </label>
          <label>
            <input type="checkbox" value="18" class="checkbox_departure"> 12:00-18:00
          </label>
          <label>
            <input type="checkbox" value="24" class="checkbox_departure"> 18:00-24:00
          </label>
        </div>
      </div>
      <legend></legend>
      <div class="col-xs-24 nopadding flight_filter">
        <strong>Arrival time</strong> 
        <div class="checkbox" data-flightitem="arrivaltime">
          <label>
            <input type="checkbox" value="6" class="checkbox_arrival"> 00:00-06:00
          </label>
          <label>
            <input type="checkbox" value="12" class="checkbox_arrival"> 06:00-12:00
          </label>
          <label>
            <input type="checkbox" value="18" class="checkbox_arrival"> 12:00-18:00
          </label>
          <label>
            <input type="checkbox" value="24" class="checkbox_arrival"> 18:00-24:00
          </label>
        </div>
      </div>
    </div>
    <div class="col-sm-24" id="flight_container" style="background:#f3f5f7;margin-top:15px;">
      <div class="col-xs-24 btn-sm"></div>           
      <div class="col-xs-24 text-center hidden"><img src="http://www.diychinatours.com/image/loading.gif" id="search-loading-img"></div>
      <div id="flight_list_container">
        <table class="table">
          <?php 
            foreach ($result->FlightNO as $flight) { 
              $seat_arr=array();
              $f_az_arr=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
              $cabin_arr=array('Y'=>'Economy Class','C'=>'Business Class','F'=>'First Class');
              foreach (str_split($flight->f_az) as $key => $faz) 
              {
                if($faz!='-' && isset($f_az_arr[$key]))
                {
                  $seat_arr[$f_az_arr[$key]]=$faz;
                }
              }
              $first_price=array_shift($pricegroup[$flight->flight]);
          ?>
          <tbody 
            class="flight_item"
            data-departuretime="<?php echo date('G.i',strtotime($flight->tstar)); ?>" 
            data-arrivaltime="<?php echo date('G.i',strtotime($flight->tdest)); ?>"
            style="border:none;background:#fff;">
              <tr>
                <td>
                  <p style="line-height:30px;">
                    <span class="pull-left">
                      <img style="width:30px;padding-right:5px;" src="/image/airline_logos/<?php echo $flight->airlinecode;?>.png" >
                    </span>
                    <span class="pull-left" ><?php echo $flight->flight;?></span>
                  </p>
                </td>
                <td><?php echo substr($flight->tstar, -8,5);?><br><?php echo substr($flight->tdest, -8,5);?></td>
                <td><?php echo $flight->cstar;?><br><?php echo $flight->cdest;?></td>
                <td style="padding:25px 10px;">
                  <?php echo $cabin_arr[$first_price->bcabintype];?>
                  <?php if($first_price->discountRate<100) echo '<br>Save '.(100-$first_price->discountRate).'%';?>
                  <br><a href="javascript:void(0);" class="toggle_price" data-caret="hide" data-class="price_<?php echo $flight->flight; ?>">(All Classes<span class="caret"></span>)</a>
                </td>
                <td class="text-danger">￥<?php echo $first_price->singleprice;?><br><span class="text-muted"><?php if($seat_arr[$first_price->cabintype]!='A') echo '('.$seat_arr[$first_price->cabintype].' seat left)';?></span></td>
                <td><button class="btn btn-danger btn-sm" disabled="disabled">Book</button></td>
              </tr>
              <?php 
              
              foreach ($pricegroup[$flight->flight] as $price) {
              ?>
                <tr class="price_<?php echo $flight->flight; ?> hidden">
                  <td colspan="3" style="border:none;"></td>
                  <td><?php echo $cabin_arr[$price->bcabintype];?><?php if($price->discountRate<100) echo '<br>Save '.(100-$price->discountRate).'%';?></td>
                  <td class="text-danger">￥<?php echo $price->singleprice;?><br><span class="text-muted"><?php if($seat_arr[$price->cabintype]!='A') echo '('.$seat_arr[$price->cabintype].' seat left)';?></span></td>
                  <td><button class="btn btn-danger btn-sm" disabled="disabled">Book</button></td>
                </tr>
              <?php } ?>
          </tbody>
          <?php } ?>
        </table>
      </div>
      
    </div>
  </div>
</div>


<?php require_once(APPPATH.'views/diy_tour/public/footer.php');?>
<script type="text/javascript" src="/min/f=/css/bootstrap/js/jquery-ui-1.10.0.custom.min.js,/css/bootstrap/js/jquery.suggest.js"></script>    
<script type="text/javascript">
$(document).ready(function(){  
  $('#departing_date,#return_date').datepicker({
        inline: true,
        minDate: "<?php echo date("m/d/Y",strtotime("+3 day")); ?>",
        dateFormat: 'mm/dd/yy'
  });
  //价格列表显示隐藏
  $("#flight_container").on("click",".toggle_price",function(){
    var price_toggle_flag=$(this).attr('data-caret');
    var price_detail=$(this).attr('data-class');
    if (price_toggle_flag=='hide') {
      $('.'+price_detail).removeClass('hidden');
      $(this).attr('data-caret','show');
      $(this).html('(Hide<span class="caret_up"></span>)');
    }else{
      $('.'+price_detail).addClass('hidden');
      $(this).attr('data-caret','hide');
      $(this).html('(All Classes<span class="caret"></span>)');
    }
  });

  //帅选航班  是否中转、航空公司、起飞时间、到达时间
  $(".flight_filter>.checkbox>label>input").click(function(){
    filter_flight();
  });

});
function filter_flight() {
  var departure_arr=new Array();
  var arrival_arr=new Array();
  var dep_num=arrival_num=0;

  //选中的起飞时间
  $(".checkbox_departure").each(function(){
    if ($(this).attr('checked')) {
      departure_arr[dep_num]=$(this).val();
      dep_num++;
    };
  });
  //选中的到达时间
  $(".checkbox_arrival").each(function(){
    if ($(this).attr('checked')) {
      arrival_arr[arrival_num]=$(this).val();
      arrival_num++;
    };
  });

  //拼接过滤条件
  $(".flight_item").each(function(){
    //过滤条件中有起飞时间
    var dep_flag=false;
    if(departure_arr.length==0) {
      dep_flag=true;
    }else{
      for(var i=0;i<departure_arr.length;i++){
        var lg = Number(departure_arr[i]);
        var sm = Number(departure_arr[i])-6;
        var departuretime = Number($(this).attr('data-departuretime'));
        if (i==0 && (departuretime>sm && departuretime<=lg)) {
          dep_flag=true;
        }else if(i>0 && (dep_flag || (departuretime>sm && departuretime<=lg))){
          dep_flag=true;
        }
      }
    }

    //过滤条件中有到达时间
    var arrival_flag=false;
    if(arrival_arr.length==0) {
      arrival_flag=true;
    }else{
      for(var i=0;i<arrival_arr.length;i++){
        var lg = Number(arrival_arr[i]);
        var sm = Number(arrival_arr[i])-6;
        var arrivaltime = Number($(this).attr('data-arrivaltime'));
        if (i==0 && (arrivaltime>sm && arrivaltime<=lg)) {
          arrival_flag=true;
        }else if(i>0 && (arrival_flag || (arrivaltime>sm && arrivaltime<=lg))){
          arrival_flag=true;
        }
      }
    }

    if (dep_flag && arrival_flag) {
      $(this).show();
    }else{
      $(this).hide();
    }

  });

};
</script>