<?php include("../templates/header.php"); ?>

<?php
  include("../config/mysql_connect.php");

  $thai_day_arr=array("อาทิตย์","จันทร์","อังคาร","พุธ","พฤหัสบดี","ศุกร์","เสาร์");
  $thai_month_arr=array(
    "0"=>"",
    "1"=>"มกราคม",
    "2"=>"กุมภาพันธ์",
    "3"=>"มีนาคม",
    "4"=>"เมษายน",
    "5"=>"พฤษภาคม",
    "6"=>"มิถุนายน", 
    "7"=>"กรกฎาคม",
    "8"=>"สิงหาคม",
    "9"=>"กันยายน",
    "10"=>"ตุลาคม",
    "11"=>"พฤศจิกายน",
    "12"=>"ธันวาคม"                 
  );

  function thai_date($time){
    global $thai_day_arr,$thai_month_arr;
    $thai_date_return="วัน".$thai_day_arr[date("w",$time)];
    $thai_date_return.= "ที่ ".date("j",$time);
    $thai_date_return.=" ".$thai_month_arr[date("n",$time)];
    $thai_date_return.= " พ.ศ. ".(date("Y",$time)+543);
    return $thai_date_return;
  }

  $strSQL = "SELECT * FROM tb_account WHERE acc_id='$session_id'";
  $objQuery = mysqli_query($link,$strSQL);
  $Result_acc = mysqli_fetch_array($objQuery);
  $acc_commisssion = $Result_acc['acc_commission'];
  $rate1 = $Result_acc['rate1'];
  $rate2 = $Result_acc['rate2'];
  $rate3 = $Result_acc['rate3'];
  $rate4 = $Result_acc['rate4'];
  $rate5 = $Result_acc['rate5'];
  $rate6 = $Result_acc['rate6'];
  $acc_com5 = $Result_acc['acc_com5'];

  $strSQL = "SELECT * FROM setting_default";
  $objQuery = mysqli_query($link,$strSQL);
  $Result = mysqli_fetch_array($objQuery);
  $def_status = $Result['def_status'];
  $def_info = $Result['def_info'];

  if($def_info == 'On'){
  $straward = "SELECT * FROM tb_award ORDER BY awa_id DESC";
  $awardQuery = mysqli_query($link,$straward);
  $Resultaward = mysqli_fetch_array($awardQuery);
  $awa_6 = $Resultaward['awa_6'];
  $awa_2 = $Resultaward['awa_2'];
  $awa_date = $Resultaward['awa_date'];

  $awa_n6 = substr($awa_6 , -2);  // เลขท้าย 2 ตัว
  $awa_n3 = substr($awa_6 , -3);  // เลขท้าย 3 ตัว

  $e1 = substr($awa_n3 , -1, 1);  // X ตัว
  $e2 = substr($awa_n3 , -2, 1);  // X-X ตัว
  $e3 = substr($awa_n3 , -3, 1);  // X-X ตัว

  $e5 = substr($awa_2 , -1, 1);  // X ตัว
  $e6 = substr($awa_2 , -2, 1);  // X-X ตัว

  $set1 = "$e1$e2$e3";
  $set2 = "$e2$e3$e1";
  $set3 = "$e3$e1$e2";
  $set4 = "$e3$e2$e1";
  $set5 = "$e2$e1$e3";
  $set6 = "$e1$e3$e2";

  }
  else{
    $Resultaward = "";
  }

  ?>

<!-- 
//============================================================================
-->

 <div class="jumbotron">
  <center>
  <?php

  if($def_info == 'On'){

  $eng_date =strtotime($awa_date); 
  $awa_date = thai_date($eng_date);

  echo"
  <h3><b>รางวัลประจำ$awa_date</b></h3>
  <h3><b>รางวัลที่ 1 ได้แก่เลข $awa_6</b></h3>
  <h3><b>เลขท้าย 2 ตัว ได้แก่เลข $awa_2</b></h3>";
  }
  else{

  echo"<h3><b>ยังไม่มีการประกาศรางวัล</b></h3>";

  //====================================>

  $sql_show = "select * from tb_locknum where loc_type='A' order by loc_num ASC"; 
  $objQuery = mysqli_query($link,$sql_show);
  $rowcount = mysqli_num_rows($objQuery);

    if($rowcount){
      echo "<div class='panel panel-primary'><div class='panel-body'>เลขที่ล็อค 2 ตัวบน ประจำงวดนนี้<br>";
      while($objResult = mysqli_fetch_array($objQuery)){
      $locid = $objResult['loc_id'];
      $locnum = $objResult['loc_num'];

      echo "<a href='#' class='numlock btn btn-danger btn-xs' disabled>$locnum</a> ";

      }
      echo "</div></div>";
    }
    else{

    }

  //====================================>

  $sql_show = "select * from tb_locknum where loc_type='B' order by loc_num ASC"; 
  $objQuery = mysqli_query($link,$sql_show);
  $rowcount = mysqli_num_rows($objQuery);

    if($rowcount){
      echo "<div class='panel panel-primary'><div class='panel-body'>เลขที่ล็อค 2 ตัวล่าง ประจำงวดนี้<br>";
      while($objResult = mysqli_fetch_array($objQuery)){
      $locid = $objResult['loc_id'];
      $locnum = $objResult['loc_num'];

      echo "<a href='#' class='numlock btn btn-danger btn-xs' disabled>$locnum</a> ";

      }
      echo "</div></div>";
    }
    else{

    }

  //====================================>

  $sql_show = "select * from tb_locknum where loc_type='C' order by loc_num ASC"; 
  $objQuery = mysqli_query($link,$sql_show);
  $rowcount = mysqli_num_rows($objQuery);

    if($rowcount){
      echo "<div class='panel panel-primary'><div class='panel-body'>เลขที่ล็อค 3 ตัวเต็ง ประจำงวดนี้<br>";
      while($objResult = mysqli_fetch_array($objQuery)){
      $locid = $objResult['loc_id'];
      $locnum = $objResult['loc_num'];

      echo "<a href='#' class='numlock btn btn-danger btn-xs' disabled>$locnum</a> ";

      }
      echo "</div></div>";
    }
    else{

    }

  //====================================>

  $sql_show = "select * from tb_locknum where loc_type='D' order by loc_num ASC"; 
  $objQuery = mysqli_query($link,$sql_show);
  $rowcount = mysqli_num_rows($objQuery);

    if($rowcount){
      echo "<div class='panel panel-primary'><div class='panel-body'>เลขที่ล็อค 3 ตัวโต็ด ประจำงวดนี้<br>";
      while($objResult = mysqli_fetch_array($objQuery)){
      $locid = $objResult['loc_id'];
      $locnum = $objResult['loc_num'];

      echo "<a href='#' class='numlock btn btn-danger btn-xs' disabled>$locnum</a> ";

      }
      echo "</div></div>";
    }
    else{

    }

  //====================================>

  $sql_show = "select * from tb_locknum where loc_type='E' order by loc_num ASC"; 
  $objQuery = mysqli_query($link,$sql_show);
  $rowcount = mysqli_num_rows($objQuery);

    if($rowcount){
      echo "<div class='panel panel-primary'><div class='panel-body'>เลขที่ล็อค 1 ตัววิ่งบน ประจำงวดนี้<br>";
      while($objResult = mysqli_fetch_array($objQuery)){
      $locid = $objResult['loc_id'];
      $locnum = $objResult['loc_num'];

      echo "<a href='#' class='numlock btn btn-danger btn-xs' disabled>$locnum</a> ";

      }
      echo "</div></div>";
    }
    else{

    }

  //====================================>

  $sql_show = "select * from tb_locknum where loc_type='F' order by loc_num ASC"; 
  $objQuery = mysqli_query($link,$sql_show);
  $rowcount = mysqli_num_rows($objQuery);

    if($rowcount){
      echo "<div class='panel panel-primary'><div class='panel-body'>เลขที่ล็อค 1 ตัววิ่งล่าง ประจำงวดนี้<br>";
      while($objResult = mysqli_fetch_array($objQuery)){
      $locid = $objResult['loc_id'];
      $locnum = $objResult['loc_num'];

      echo "<a href='#' class='numlock btn btn-danger btn-xs' disabled>$locnum</a> ";

      }
      echo "</div></div>";
    }
    else{

    }

  //====================================>

  } // esle

  ?>
  </center>
  </div><hr>

<!-- 
//============================================================================
-->

<?php include("show_tb1.php"); ?>
<?php include("show_tb2.php"); ?>
<?php include("show_tb3.php"); ?>
<?php include("show_tb4.php"); ?>
<?php include("show_tb5.php"); ?>

<!-- 
//============================================================================
-->

<?php include("../templates/footer.php"); ?>