<?php
    $rs = $db->findAll('tbbooking')->execute();
        function DateThai($strDate){
      $strYear = date("Y",strtotime($strDate))+543;
      $strMonth= date("n",strtotime($strDate));
      $strDay= date("j",strtotime($strDate));
      $strHour= date("H",strtotime($strDate));
      $strMinute= date("i",strtotime($strDate));
      $strSeconds= date("s",strtotime($strDate));
      $strMonthCut = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
      $strMonthThai=$strMonthCut[$strMonth];
      return "$strDay $strMonthThai $strYear";
    }

          function DateGoBack($DateGo,$DateBack){
      $strYear = date("Y",strtotime($DateBack))+543;
      $strMonth= date("n",strtotime($DateBack));
      $strDay = date("j",strtotime($DateBack));
      $strDay2 = date("j",strtotime($DateGo));
      $strMonth2= date("n",strtotime($DateGo));
      $strYear2 = date("Y",strtotime($DateGo))+543;
      // $strMonthCut = Array("","มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
      $strMonthCut = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
      $strMonthCut2 = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
      $strMonthThai=$strMonthCut[$strMonth];
      $strMonthThai2=$strMonthCut2[$strMonth2];

      return "$strDay2-$strDay $strMonthThai $strYear";
    }
 if ($_SESSION['admin_id'] == '48' || $_SESSION['admin_id'] == '51') {
   $sq = $db->findAll('tbbooking')->execute();
 }else{
   $sq = $db->findByAttributes('tbbooking',array('book_sale =' => $_SESSION['admin_nickname']))->execute();
 }

// $sq = $db->findorderdesc('tbbooking','book_status = 0 && book_sale = '.$_SESSION['admin_nickname'].'','book_id')->execute();
?>
<section class="panel panel-danger">
<header class="panel-heading">
<div class="panel-actions">
<a href="#" class="fa fa-caret-down"></a>
</div>
<h2 class="panel-title">ใบจองหน้าระบบ (<?=$_SESSION['admin_nickname'];?>)  <a class="btn btn-danger float-end" href="?url=booking">ใบจองยังไม่ติดต่อแล้ว</a></h2>
</header>
<div class="panel-body text-dark">
                    <table class="table table-bordered table-striped mb-none datatable" id="datatable-iv">
                      <thead>
                          <tr style="text-align:center;">
                            <th style="text-align:center;width:80px;">#</th>
                            <th style="text-align:center;">BookTime</th>
                            <th style="text-align:center;">Programe</th>
                            <th style="text-align:center;">Period</th>
                            <th style="text-align:center;width:250px;">ข้อมูลลูกค้า</th>
                            <th style="text-align:center;">จำนวน</th>
                            <th style="text-align:center;">Sale</th>
                            <th style="text-align:center;">จัดการ</th>
                          </tr>
                      </thead>
                          <tbody>
                       <?php
                       $i=0;
                        while($dbarr= mysql_fetch_array($sq)){ ?>

                          <?
                          if($dbarr['book_status'] == '1'){
                          ?>
                          <tr><?$i++;?>
                            <td style="text-align:center;"><?=$i;?></td>
                            <td style="text-align:center;line-height: 1.1;"><?=DateThai($dbarr['book_date']);?><br><?=$dbarr['book_time'];?></td>
                            <td style="text-align:center;"><b>
                              <a href="https://www.imaginetourservice.com/newimagine/programdetail-<?=$dbarr['programe_code'];?>.html" target="_blank"><?=$dbarr['programe_code'];?></b> : <?=$dbarr['programe_name'];?></a></td>
                            <td style="text-align:center;"><?=$dbarr['book_datego'];?> - <?=$dbarr['book_dateback'];?></td>
                            <td style="text-align:left;line-height: 1.3;"><?=$dbarr['book_name'];?> <br> <b>TEL :</b> <?=$dbarr['book_tel'];?> <b>LINE :</b> <?=$dbarr['book_line'];?><br><?=$dbarr['book_etc'];?></td>
                            <td style="text-align:center;"><?=$dbarr['book_total'];?></td>
                            <td style="text-align:center;"><?=$dbarr['book_sale'];?></td>
                            <?if($dbarr['book_status'] == '0'){?>
                              <td style="text-align:center;">
                              <a class='changestatus_book' href='#' status ='1' id='<?=$dbarr[book_id];?>'><span class='label label-dark' style='font-weight:400;'>ยังไม่ติดต่อ</span></a>
                              </td>
                            <?}else{?>
                              <td style="text-align:center;">
                              <span class="text-danger">ติดต่อแล้ว</span>
                            </td>
                            <?}?>
                          
                          </tr>
                          <?}?>
                         <? }?>

                         </tbody>
      </table>
</div>
</section>