			<?
   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";
    }


      ?>
<?
$cou = $_GET['id'];
if($cou == '33'){
 $countryb = '22';
}else if($cou == '22' || $cou == '47' | $cou == '54'){
  $countryb = '21';
}else if($cou == '4'){
  $countryb = '23';
}else if($cou == '32'){
  $countryb = '24';
}else if($cou == '5'){
  $countryb = '32';
}else if($cou == '21'){
  $countryb = '30';
}else{
 $countryb = $cou;
}
$ch = curl_init();
$url = "https://api.best-consortium.com/v1.1/series/$countryb";
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
$DATABEST= json_decode($result ,true);


if($cou == '7'){
 $countrylet = 'VN';
}else if($cou == '14'){
   $countrylet = 'TURK';
}else if($cou == '5'){
   $countrylet = 'KOR';
}else if($cou == '22'){
   $countrylet = 'EU';
}else if($cou == '18'){
   $countrylet = 'IDA';
}else if($cou == '29'){
   $countrylet = 'SIN';
}else if($cou == '53'){
   $countrylet = 'ITA';
}else if($cou == '54'){
   $countrylet = 'FRA';
}else if($cou == '47'){
   $countrylet = 'SWI';
}else if($cou == '32'){
   $countrylet = 'GGA';
}else if($cou == '23'){
   $countrylet = 'ENG';
}else{
 $countrylet = $cou;
}

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://www.zegoapi.com/v1.1/Lists/ProgramTour/Country/$countrylet",
 CURLOPT_RETURNTRANSFER => true,
 CURLOPT_ENCODING => "",
 CURLOPT_MAXREDIRS => 10,
 CURLOPT_TIMEOUT => 30,
 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
 CURLOPT_CUSTOMREQUEST => "GET",
 CURLOPT_HTTPHEADER => array(
  "Access-Control-Allow-Origin: *",
  "Cache-Control: no-cache",
  "accept: application/json",
  "auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MjlmMGMzYzRmYjIxMDRkMjgxOTgyNTEiLCJpYXQiOjE2NTQ1OTA1NDF9.ADcEdvCTW5Fud29l8w8KoODbS6XHGhSpEVNkQlMZAXg"
 ),
));
$response2 = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$DATALET = json_decode($response2, true);

   ?>
   		<section class="panel" style="color:red;">
							<header class="panel-heading">
									<!-- <a href="#" class="fa fa-caret-down"></a>
									<a href="#" class="fa fa-times"></a -->
								<a href="?url=programe_form" data-link="?url=program" class="btn btn-success with-shadow-success" style="position: absolute;right: 16px;top: 10px;">เพิ่มรายการทัวร์</a>
						
								<h1 class="panel-title">Program Tour (ต่างประเทศ)</h1>
							</header>
                         <header class="panel-heading">
            <div class="row">
            <div class="col-md-3">
                <label>Wholesale :</label>
                <select data-plugin-selectTwo  id='programe_wholesale' name="programe_wholesale"  data-rel="chosen" class="form-control populate placeholder wholesale-dropdown">
             <!--    <select class="form-control date-dropdown"> -->
                <option value="">All</option>
                <?$rc = $db->findAll('tb_wholesale')->execute();while($dbarr= mysql_fetch_array($rc)){?>
                <option value="<?=$dbarr[wholesale_name];?>"><?=$dbarr[wholesale_name];?></option>
                <?}?>
              </select>
            </div>

           <div class="col-md-3">
                <label>เดือนที่เดินทาง :</label>
                 <select data-plugin-selectTwo data-rel="chosen" class="form-control datego2-dropdown">
                <option value="">All</option>
                <option value="ม.ค.">ม.ค.</option>
                <option value="ก.พ.">ก.พ.</option>
                <option value="มี.ค.">มี.ค.</option>
                <option value="เม.ย.">เม.ย.</option>
                <option value="เม.ย.">พ.ค.</option>
                <option value="เม.ย.">มิ.ย.</option>
                <option value="เม.ย.">มิ.ย.</option>
                <option value="ก.ค.">ก.ค.</option>
                <option value="ส.ค.">ส.ค.</option>
                <option value="ก.ย.">ก.ย.</option>
                <option value="ต.ค.">ต.ค.</option>
                <option value="พ.ย.">พ.ย.</option>
                 <option value="ธ.ค.">ธ.ค.</option>
              </select>
            </div>
            <div class="col-md-2">
              <label>REAL TIME :</label><br>
             <label data-target="#tophead" class="btn btn-success"> <input type="checkbox" class="filter-checkbox-api" value="API"/> API </label>
            </div>
          </div>
          </header>
							<div class="panel-body">

								<table class="table table-bordered table-striped mb-none" id="datatable-iv">
									<thead>
										<tr>
											<th>NO</th>
											<!-- <th>Pic</th> -->
                      <th>รหัสทัวร์</th>
											<th>Program Tour</th>
											<th>Country</th>
											<th>Wholesale</th>
											<th>วันเดินทางไป</th>
                      <th>วันเดินทางกลับ</th>
                      <th>API</th>
                      <th>Status</th>
										</tr>
									</thead>
									<tbody>
								<?php
						   // $rs = $db->findorder('tb_programe,tbtrip,tbcountry,tbairline','
         //                   tb_programe.programe_id = tbtrip.trip_programe_code && tb_programe.programe_country = tbcountry.country_id && tb_programe.programe_airline = tbairline.airline_id','programe_id asc,programe_code')->execute();
$cosnum = $db->findByPK('tb_programe,tbtrip,tbcountry,tbairline',' tb_programe.programe_id = tbtrip.trip_programe_code && tb_programe.programe_country = tbcountry.country_id && tb_programe.programe_airline = tbairline.airline_id && trip_ex = 0 && programe_wholesale != 2 && country_id',$_GET['id'])->execute();

                			$i=0;
                		  while($dbarr= mysql_fetch_array($cosnum)){ 
     						      $file = $dbarr[programe_file];
                      $id = $dbarr[programe_wholesale];
                      $rp = $db->findByPK('tb_wholesale','wholesale_id',$id)->executeRow();
            				echo "<tr>";  $i++ ;
            				echo "    <td class='center'>$i</td>";
                    echo "    <td class='center'>$dbarr[programe_code]</td>";
            				// echo "    <td class='center'><img src='../upload/$dbarr[programe_img]' width='80'></td>";
            				echo "    <td><a href='https://www.imaginetourservice.com/newimagine/programdetail-$dbarr[programe_code].html' style='text-decoration: none;'  target='_blank'>$dbarr[programe_name]&nbsp;$dbarr[programe_time] </a> </td>";
            				echo "    <td class='center'>$dbarr[country_name]</td>"; 
                    echo "    <td class='center' style='color:red;font-size:12pt;'>$rp[wholesale_name]</td>"; 
            				// echo "    <td class='center'><a data-toggle='modal' data-target='#modalBootstrap'><span class='label label-success'>เพิ่ม PERIOD</span></a></td>";
                     echo "    <td class='center'>".DateThai($dbarr[trip_date_go])."</td>";
                     echo "    <td class='center'>".DateThai($dbarr[trip_date_back])."</td>";
                     echo "    <td class='center'>-</td>";
                    echo "<td class='center'>";
                       if($dbarr[programe_status] == '1'){
                        echo "<span class='label label-success'>เปิดการขาย</span>";
                       } else {
                        echo "<span class='label label-table'>ปิดการขาย</span>";
                       }
                    echo "</td>";
                    echo "</tr>";  
                     }

?>

      <?php 
      $ii =0; 
               $rs2 = $db->findorder('tb_programe,tbcountry,tbairline','
                        tb_programe.programe_country = tbcountry.country_id && tb_programe.programe_airline = tbairline.airline_id','programe_id asc,programe_code')->execute();
                     
                      while($dbarr= mysql_fetch_array($rs2)){ 
                        foreach($DATABEST as $pg) {
                          if($pg['code'] == $dbarr['programe_code']){ $x =0; while ($x <= $pg[period][$x][pid]) {
                       if ($dbarr['country_id'] == $_GET['id'] && $dbarr['programe_status'] == '1') {
                      $file = $dbarr[programe_file];
                      $id = $dbarr[programe_wholesale];
                      $rp = $db->findByPK('tb_wholesale','wholesale_id',$id)->executeRow();
                    echo "<tr>";  $ii++ ;
                    echo "    <td class='center'>$i</td>";
                    echo "    <td class='center'>$dbarr[programe_code] (API)</td>";
                    // echo "    <td class='center'><img src='../upload/$dbarr[programe_img]' width='80'></td>";
                    echo "    <td><a href='https://www.imaginetourservice.com/newimagine/programdetail-$dbarr[programe_code].html' style='text-decoration: none;'  target='_blank'>$dbarr[programe_name]&nbsp;$dbarr[programe_time] </a> </td>";
                    echo "    <td class='center'>$dbarr[country_name]</td>"; 
                    echo "    <td class='center' style='color:red;font-size:12pt;'>$rp[wholesale_name]</td>"; 
                    // echo "    <td class='center'><a data-toggle='modal' data-target='#modalBootstrap'><span class='label label-success'>เพิ่ม PERIOD</span></a></td>";
                     echo "    <td class='center'>".DateThai($pg[period][$x][dateGo])."</td>";
                     echo "    <td class='center'>".DateThai($pg[period][$x][dateBack])."</td>";
                     echo "    <td class='center'>API</td>";
                    echo "<td class='center'>";
  if($pg[period][$x][avbl]=="เต็ม" || $pg[period][$x][avbl]=="รอชำระเงิน" || $pg[period][$x][avbl]=="ปิดกรุ๊ป"){
    $allbook = 'เต็ม';
    }else{
    $allbook = $pg[period][$x][avbl];
    }
                    if($pg[period][$x][avbl]=="เต็ม" || $pg[period][$x][avbl]=="รอชำระเงิน" || $pg[period][$x][avbl]=="ปิดกรุ๊ป"){
                        echo "<a class='btn btn-danger btn-block' href='#'>$allbook</a>";
                      }else{
                        echo "<a class='btn btn-success btn-block' href='#'>$allbook</a>";
                      }
                       
                    echo "</td>";
                    echo "</tr>";  
                                       } $x++;  } }
                    } }//mysql_close($link);
?>



    <?php 
      $li =0; 
               $rs3 = $db->findorder('tb_programe,tbcountry,tbairline','
                        tb_programe.programe_country = tbcountry.country_id && tb_programe.programe_airline = tbairline.airline_id','programe_id asc,programe_code')->execute();
                     
                      while($dbarr= mysql_fetch_array($rs3)){
                        foreach($DATALET as $rlet){
                          if($rlet['ProductCode'] == $dbarr['programe_code']){ $xl =0; while ($xl < $rlet[Periods][$xl][PeriodID]) {
                       if ($dbarr['country_id'] == $_GET['id'] && $dbarr['programe_status'] == '1') {
                      $file = $dbarr[programe_file];
                      $id = $dbarr[programe_wholesale];
                      $rp = $db->findByPK('tb_wholesale','wholesale_id',$id)->executeRow();
                    echo "<tr>";  $li++ ;
                    echo "    <td class='center'>$i</td>";
                    echo "    <td class='center'>$dbarr[programe_code] (API)</td>";
                    // echo "    <td class='center'><img src='../upload/$dbarr[programe_img]' width='80'></td>";
                    echo "    <td><a href='https://www.imaginetourservice.com/newimagine/programdetail-$dbarr[programe_code].html' style='text-decoration: none;'  target='_blank'>$dbarr[programe_name]&nbsp;$dbarr[programe_time] </a> </td>";
                    echo "    <td class='center'>$dbarr[country_name]</td>"; 
                    echo "    <td class='center' style='color:red;font-size:12pt;'>$rp[wholesale_name]</td>"; 
                    // echo "    <td class='center'><a data-toggle='modal' data-target='#modalBootstrap'><span class='label label-success'>เพิ่ม PERIOD</span></a></td>";
                     echo "    <td class='center'>".DateThai($rlet[Periods][$xl][PeriodStartDate])."</td>";
                     echo "    <td class='center'>".DateThai($rlet[Periods][$xl][PeriodEndDate])."</td>";
                     echo "    <td class='center'>API</td>";
                    echo "<td class='center'>";
  if($rlet[Periods][$xl][Status]=="Soldout" || $rlet[Periods][$xl][Status]=="Close Group" || $rlet[Periods][$xl][Status]=="Waitlist" ){
    $allbook = 'เต็ม';
    }else{
    $allbook = $pg[Periods][$xl][avbl];
    }
                    if($rlet[Periods][$xl][Status]=="Soldout" || $rlet[Periods][$xl][Status]=="Close Group" || $rlet[Periods][$xl][Status]=="Waitlist" ){
                        echo "<a class='btn btn-danger btn-block' href='#'>FULL</a>";
                      }else{
                        echo "<a class='btn btn-success btn-block' href='#'>".$rlet[Periods][$xl][Seat]."</a>";
                      }
                       
                    echo "</td>";
                    echo "</tr>";  
                                       } $xl++;  } }
                    } }//mysql_close($link);
?>

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


<!--       <div class="modal fade" id="modalBootstrap2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
     <div class="modal-content">
     <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
       <h4 class="modal-title" id="myModalLabel">คุณต้องการที่จะลบ PERIOD <span class="del-item"></span></h4>
      </div>
    <div class="modal-footer" style="margin-top: 0;">
      <a href="#" class="mb-xs mt-xs mr-xs btn btn-default" data-dismiss="modal">Cancel</a>
      <a href="?url=period_delete" class="mb-xs mt-xs mr-xs btn btn-danger period_del" data-dismiss="modal">Delete</a>
    </div>
              </div>
              </div>
              </div> -->
