Path : /var/www/html/main/ap/register/
File Upload :
Current File : /var/www/html/main/ap/register/index.php

<?php
session_start();

if($_GET['nu']=="apprint"){
  include('../../connDB.php');
}else{
  include('../../head.php');
}

$_GET['xcode'] = (isset($_GET['xcode']))?$_GET['xcode']:$_POST['code'];

$sql = "select * from ap_products where code='$_GET[xcode]'";
$query = mysqli_query($conn,$sql);
$rows = mysqli_fetch_array($query);
$num_rows = mysqli_num_rows($query);
$name = $rows['name'];
$info = $rows['info'];
$photo = $rows['photo'];
$linenotify = $rows['linenotify'];
$linegroup = $rows['linegroup'];
$limit = $rows['score'];
$xlimit = $rows['xlimit'];
$date = date('Ymd');
$dates = $rows['date_start'];
$datee = $rows['date_expire'];
$counters = $rows['counters'];

if(empty($counters)){
  $counters = 1;
}

$sql2 = "select * from ap_register where code='$_GET[xcode]'";
$query2 = mysqli_query($conn,$sql2);
$num_rows2 = mysqli_num_rows($query2);

$sql2x = "select * from ap_register where code='$_GET[xcode]' and id='$_GET[id]'";
$query2x = mysqli_query($conn,$sql2x);
$rows2x = mysqli_fetch_array($query2x);

if($_GET['nu']!="apprint"){
?>
  <div class="body-main-row-body container theme-showcase" role="main">
    <div class="breadcrumbx">
    <?php
    if($_GET['nu']==""){
      if($date>=$dates && $date<=$datee){
        if($photo==""){
        ?>
          <p><p>
          <h3 align="center">ลงทะเบียน <?php echo $name;?></h3>
          <p></p>
          <hr>
          <div><?php echo $info; if(!empty($info)){ echo "<hr>"; } ?></div>
        <?php 
        }else{
        ?>
          <p><?php echo $name;?></p>
          <?php if(!empty($photo)){ ?><p><img width="100%" src="<?php echo $photo; ?>" alt="<?php echo $name; ?>" title="<?php echo $name; ?>"></p><?php } ?>
        <?php
        }

        if($num_rows2>0){
        ?>
          <p align="right"><a class="btn btn-info" href="ap/register/?nu=info&xcode=<?php echo $_GET['xcode']; ?>" target="_blank"><?php echo "รายชื่อเข้าร่วมทั้งหมด $num_rows2 คน";?></a></p>
        <?php 
        }
        if(($num_rows2>=$xlimit) && empty($_SESSION['user'])){
          echo "<p align='center'>ระบบปิด!!! แล้วครับ</p>";
        }else{
        ?>
        <form name="apform" method="post" action="ap/register/?nu=<?php if($_GET['id']==""){ echo "insert"; }else{ echo "update"; } ?>" enctype="multipart/form-data">
        <input type="hidden" name="id" value="<?php echo $_GET['id'] ?>">
        <input type="hidden" name="dateTime" value="<?php echo $rows2x['dateTime'] ?>">
        <input type="hidden" name="notify" value="<?php echo $rows2x['notify'] ?>">
        <input type="hidden" name="code" value="<?php echo $_GET['xcode'] ?>">
        <?php
        $sql = "select * from ap_register_form where regCode='$_GET[xcode]' order by regFieldCode asc";
        $query = mysqli_query($conn,$sql);
        $i = 0;
        while($rows = mysqli_fetch_array($query)){
        $i++;
          /*if($rows['regFieldCode']=="f1010"){
          ?>
          <label for=""><?php echo $rows['regNameFieldCode']; ?></label>
            <p><input type="file" class="form-control" name="<?php echo $rows['regFieldCode'] ?>" accept="image/*;capture=camera"></p>
          <?php
          }else{*/
          if($rows['regTypeFieldCode']=="text"){
          ?>
            <label for=""><?php echo $rows['regNameFieldCode']; ?></label>
            <p><input type="<?php echo $rows['regTypeFieldCode']; ?>" class="form-control" name="<?php echo $rows['regFieldCode']; ?>" value="<?php echo $rows2x[$rows['regFieldCode']]; ?>" placeholder="<?php echo $rows['regValueFieldCode']; ?>" <?php echo $rows['required']; ?>></p>
          <?php
          }
          if($rows['regTypeFieldCode']=="radio"){
          ?>
            <label for=""><?php echo $rows['regNameFieldCode']; ?></label>
            <p><input type="<?php echo $rows['regTypeFieldCode']; ?>" class="form-control" name="<?php echo $rows['regFieldCode']; ?>"></p>
          <?php
          }
          if($rows['regTypeFieldCode']=="checkbox"){
          ?>
            <div class="<?php echo $rows['regTypeFieldCode']; ?>">
              <label for=""><input type="<?php echo $rows['regTypeFieldCode']; ?>" name="<?php echo $rows['regFieldCode']; ?>" value="1"> <?php echo $rows['regNameFieldCode']; ?></label>
            </div>
          <?php
          }
        }
        ?>
        <p align="center"><input class="btn btn-success" type="submit" name="submit" value="<?php if($_GET['id']==""){ echo "ลงทะเบียน"; }else{ echo "ปรับปรุง"; } ?>" onclick="return confirm('พร้อมที่จะส่งข้อมูลแล้วใช่หรือไม่?');" ></p>
        </form>
      <?php
        }
      }else{
        echo "<p align='center'>ระบบปิด!!! แล้วครับ</p>";
      }
    }

    if($_GET['nu']=="insert"){
      if(($num_rows2>=$xlimit) && empty($_SESSION['user'])){
        echo "<p align='center'>ระบบปิด!!! แล้วครับ</p>";
      }else{
        /*$img = "f1010";
        if($_FILES[$img]['name']==''){
          $_POST[$img] = "";
        }else{
          $in = "../../contents/register/";
          $namefile = $_POST['code']."-".date('Ymd').time();
          if(strlen($_FILES[$img]['tmp_name'])!=0){
            move_uploaded_file($_FILES[$img]['tmp_name'], "$in$namefile" . strrchr($_FILES[$img]['name'], "."));
          }
          $_POST[$img] = $namefile.strrchr($_FILES[$img]['name'], ".");
        }*/
        $table = "ap_register";
        $_POST['dateTime'] = date('Y-m-d H:i:s');
        $query = mysqli_query($conn,"select * from $table");
        $num_fields = mysqli_num_fields($query);
        for($i=1; $i<$num_fields; $i++) {
            $field_name[$i] = mysqli_fetch_field_direct($query,$i)->name;
            $fields = $field_name[$i];

            $fields_1 .= "$fields, ";
            $fields_2 .= "'".mysqli_real_escape_string($conn,$_POST[$fields])."', ";
        }
        $field_1 = substr($fields_1,0,-2);
        $field_2 = substr($fields_2,0,-2);
      
        if($_POST['code']!=""){
          mysqli_query($conn,"insert into $table ($field_1) values ($field_2)");
        }

        echo "<br><CENTER><B>กรุณารอสักครู่</B></CENTER><br>";
        echo "<meta http-equiv='refresh' content='0;URL=$ap_site$ap_folder"."ap/register/?nu=success&xcode=$_POST[code]'>";
      }
    }

    if($_GET['nu']=="update"){
      login_($_SESSION['id'],$_SESSION['user'],$_SESSION['password']);

      $table = "ap_register";
      $field = "id";
      $field2 = $_POST['id'];
      $nr = mysqli_num_rows(mysqli_query($conn,"select * from $table where $field='$field2'"));
      if($nr<0){
        echo "<center><b>ไม่สามารถบันทึกข้อมูลได้</b></center>";
        echo "<meta http-equiv='refresh' content='1;URL=$ap_site$ap_folder"."ap/register/?nu=info&xcode=$_POST[code]'>";
      }else{
        $query = mysqli_query($conn,"select * from $table");
        $num_fields = mysqli_num_fields($query);
        $fields_ = '';
        for($i=1; $i < $num_fields; $i++) {
          $field_name[$i] = mysqli_fetch_field_direct($query,$i)->name;
          $fields = $field_name[$i];
          $fields_ .= "$fields='".mysqli_real_escape_string($conn,$_POST[$fields])."', ";
        }
        $fields_set = substr($fields_,0,-2);
        mysqli_query($conn,"update $table set $fields_set where $field='$field2' ");

        echo "<CENTER><B>กรุณารอสักครู่</B></CENTER>";
        echo "<meta http-equiv='refresh' content='1;URL=$ap_site$ap_folder"."ap/register/?nu=info&xcode=$_POST[code]'>";
      }
    }

    if($_GET['nu']=="delete"){
      $table = "ap_register";
      mysqli_query($conn,"delete from $table where id='$_GET[id]'");
      echo "<br><CENTER><B>กรุณารอสักครู่</B></CENTER><br>";
      echo "<meta http-equiv='refresh' content='1;URL=$ap_site$ap_folder"."ap/register/?nu=info&xcode=$_GET[xcode]'>";
    }

    if($_GET['nu']=="success"){
      ?>
      <p></p>
      <h3 align="center">ลงทะเบียน <?php echo $name;?> สำเร็จ</h3>
      <p align="center"><a class="btn btn-success" href="ap/register/?nu=&xcode=<?php echo $_GET['xcode']; ?>"><?php echo "หน้าลงทะเบียน";?></a> <a class="btn btn-info" href="ap/register/?nu=info&xcode=<?php echo $_GET['xcode']; ?>"><?php echo "รายชื่อผู้ลงทะเบียน";?></a></h3>
      <?php
      /*if(!empty($linenotify)){
        if($rows['photo']!=""){
          $img = "$ap_site$ap_folder"."register/$rows[photo]";
        }else{
          $img = "";
        }
        $message = array(
        'message' => "$name $rows[code] $rows[fullname] $img",
        'imageThumbnail' => '',
        'imageFullsize' => '',
        'stickerPackageId' => '',
        'stickerId' => ''
        );

        $token = $linenotify;
        line_notify3($message, $token);
      }*/
    }

    if($_GET['nu']=="info"){
      error_reporting(E_ALL);
      ini_set("display_errors", 0);
    ?>
      <script>
      // Modify Anucha Puangpaka
      $(document).ready(function(){
        setInterval(function(){
          results();
          resultsx();
        },30000);

        results();
        resultsx();
      });
      </script>
      <h3 align="center"><p><span class="glyphicon glyphicon-user"></span>รายชื่อเข้าร่วม</p><p><?php echo $name;?></p></h3>
      <p align="center"><?php if($num_rows2<$xlimit){ ?><a class="btn btn-success" href="ap/register/?nu=&xcode=<?php echo $_GET['xcode']?>" target="_blank"><span class="glyphicon glyphicon-edit"></span> ลงทะเบียน</a><?php }?> <a class="btn btn-info" href="ap/register/print.php?nu=listname&xcode=<?php echo $_GET['xcode']?>" target="_blank"><span class="glyphicon glyphicon-print"></span> พิมพ์ใบรายชื่อ</a> <a class="btn btn-info" href="ap/register/print.php?nu=&xcode=<?php echo $_GET['xcode']?>" target="_blank"><span class="glyphicon glyphicon-print"></span> พิมพ์ใบลงทะเบียน</a> <?php if($linegroup!="" && detect_devices()==1){ ?> <a class="btn btn-info" href="http://line.me/ti/g/<?php echo $linegroup ?>" target="_blank"><span class="glyphicon glyphicon-question-sign"></span> LINE</a><?php } ?></p>
      <hr>
      <div>
        <?php 
        echo $info; 
        if(!empty($counters)){
        ?>
          <div class="justify-content-center" id="results"></div>
          <script>
          // Modify Anucha Puangpaka
          function results(){
            (function($){
              $.fn.loaddata = function(options) {
                var settings = $.extend({ 
                  loading_gif_url : "../../contents/images/loader.gif",
                  end_record_text : '',
                  data_url : 'ap/register/fetch_counters.php',
                  xcode : '<?php echo $_GET['xcode'] ?>',
                  start_page : 1
                }, options);
                
                var el = this;
                loading  = false;
                end_record = false;
                contents(el, settings);
                
                $(window).scroll(function() {
                  if($(window).scrollTop() + $(window).height() >= $(document).height()){
                    contents(el, settings);
                  }
                });
              };
              
              function contents(el, settings){
                var load_img = $('<img/>').attr('src',settings.loading_gif_url).addClass('loading-image');
                var record_end_txt = $('<div/>').text(settings.end_record_text).addClass('end-record-info');
                
                if(loading == false && end_record == false){
                  loading = true;
                  //el.html(load_img);
                  $.post(settings.data_url, {'page': settings.start_page,'xcode': settings.xcode}, function(data){
                    if(data.trim().length == 0){
                      el.html(record_end_txt);
                      //load_img.remove();
                      end_record = true;
                      return;
                    }
                    loading = false;
                    //load_img.remove();
                    el.html(data);
                    settings.start_page ++;
                  })
                }
              }
            })(jQuery);

            $("#results").loaddata();
          }
          </script>
          <?php
          echo "<hr>"; 
        } 
        ?>
      </div>

      <div class="justify-content-center" id="resultsx"></div>
      <script>
      // Modify Anucha Puangpaka
      function resultsx(){
        (function($){
          $.fn.loaddata = function(options) {
            var settings = $.extend({ 
              loading_gif_url : "../../contents/images/loader.gif",
              end_record_text : '',
              data_url : 'ap/register/fetch_register.php',
              xcode : '<?php echo $_GET['xcode'] ?>',
              start_page : 1
            }, options);
            
            var el = this;
            loading  = false;
            end_record = false;
            contents(el, settings);
            
            $(window).scroll(function() {
              if($(window).scrollTop() + $(window).height() >= $(document).height()){
                contents(el, settings);
              }
            });
          };
          
          function contents(el, settings){
            var load_img = $('<img/>').attr('src',settings.loading_gif_url).addClass('loading-image');
            var record_end_txt = $('<div/>').text(settings.end_record_text).addClass('end-record-info');
            
            if(loading == false && end_record == false){
              loading = true;
              //el.html(load_img);
              $.post(settings.data_url, {'page': settings.start_page,'xcode': settings.xcode}, function(data){
                if(data.trim().length == 0){
                  el.html(record_end_txt);
                  //load_img.remove();
                  end_record = true;
                  return;
                }
                loading = false;
                //load_img.remove();
                el.html(data);
                settings.start_page ++;
              })
            }
          }
        })(jQuery);

        $("#resultsx").loaddata();
      }
      </script>
      <link rel="stylesheet" href="../../dist/css/bootstrap.min.css">
      <script src="../../js/jquery.min.js"></script>
      <script src="../../dist/js/bootstrap.min.js"></script>
      <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12">
          <div class="p-3 rounded shadow-sm">
            <div class="" id="countingdown"></div>
          </div>
          <script>
            var countDownDate = new Date("<?php echo date("Y/m/d 00:00:00",strtotime($datee)); ?>").getTime();

            var x = setInterval(function() {
              var now = new Date().getTime();
              var distance = countDownDate - now;
              var days = Math.floor(distance / (1000 * 60 * 60 * 24));
              var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
              var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
              var seconds = Math.floor((distance % (1000 * 60)) / 1000);
              document.getElementById("countingdown").innerHTML = "<span class=\"glyphicon glyphicon-bell\"></span>นับถอยหลังลงทะเบียน <?php echo $name;?> อีก <span class='glyphicon glyphicon-time'></span> <span class='label label-danger'>" + days + " วัน " + hours + " ชั่วโมง "+ minutes + " นาที " + seconds + " วินาที </span>";
              if (distance < 0) {
                clearInterval(x);
                document.getElementById("countingdown").innerHTML = "EXPIRED";
              }
            }, 1000);
          </script>
        </div>
      </div>
      <p></p>
    <?php
    }
    ?>
    <p align="center"><img src="https://arit.kpru.ac.th/ap/qrcode/qrcode.php?data=<?php echo $ap_site.$ap_folder; ?>ap/register/?xcode=<?php echo $_GET['xcode'] ?>&size=177x177&logo=<?php echo $logo; ?>" border="0" alt="<?php echo $title ?>" title="<?php echo $title ?>" /></p>
    </div>
    <p></p>
  </div>
  <?php

  include ('../../footText.php');
  include ('../../foot.php');
}

if($_GET['nu']=="apprint"){
  error_reporting(E_ALL);
  ini_set("display_errors", 1);

  include('../../ap.php');

  $sql = "select * from ap_settings";
  $query = mysqli_query($conn,$sql);
  $rows = mysqli_fetch_array($query);
  $title = $rows['title'];
  $title_en = $rows['title_en'];
  $logo = $rows['logo'];

  require_once('../../mpdf/mpdf.php');
  ob_start();
  $header = "
  <table width=\"100%\" style=\"border-bottom: 1px solid #000000; color: #000088;\">
  <tr>
    <td rowspan=\"2\" width=\"40\"><img src=\"$logo\" style=\"width: 40px\" alt=\"\"></td>
    <td><font class=\"style1\" style='font-family: TH SarabunPSK;color: #000000'>$title</font></td>
  </tr>
  <tr>
    <td><font class=\"style4\" style='color: #000000'>69 หมู่ 1 ต.นครชุม อ.เมือง จ.กำแพงเพชร 62000</font></td>
  </tr>
  </table>";
  $footer = "<div class=\"style4\" style='font-family: TH SarabunPSK;font-size:10px;color: #000000' align=\"right\">วันที่ : ".date('Y-m-d H:i:s')." หน้า {PAGENO}</div>";

  $sql = "select * from ap_register where id='$_GET[id]'";
  $query = mysqli_query($conn,$sql);
  $rows = mysqli_fetch_array($query);
  ?>
  <html>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
  <table width="100%" border="0" cellspacing="1" cellpadding="3">
  <tr>
    <td align="center"><div style="font-family: 'TH SarabunPSK';font-size: 16px; font-weight: bold;"><?php echo $name; ?></div></td>
  </tr>
  <!-- <tr>
    <td align="center"><div style="font-family: 'TH SarabunPSK';font-size: 14px;"></div></td>
  </tr> -->
  </table>
  <table bgcolor="#000000" width="100%" border="0" cellspacing="1" cellpadding="5" align="right">
  <tr bgcolor="#ffffff">
    <td>
        <table width="100%" border="0" cellspacing="0" cellpadding="3" bgcolor="">
        <tr>
          <td width="130"><font style="font-family: 'TH SarabunPSK';font-size: 12px;"><b>รหัสนักศึกษา</b> : </font></td>
          <td><font style="font-family: 'TH SarabunPSK';font-size: 12px;"><?php echo $rows['idcode'];?></font></td>
          <td rowspan="5" width="150"><?php if(!empty($rows['photo'])){ ?><img width="150" src="register/<?php echo $rows['photo'] ?>" alt="<?php echo $rows['fullname'] ?>"><?php } ?></td>
        </tr>
        <tr>
          <td><font style="font-family: 'TH SarabunPSK';font-size: 12px;"><b>ชื่อ-นามสกุล:</b> : </font></td>
          <td><font style="font-family: 'TH SarabunPSK';font-size: 12px;"><?php echo $rows['fullname'];?></font></td>
        </tr>
        <tr>
          <td><font style="font-family: 'TH SarabunPSK';font-size: 12px;"><b>โปรแกรมวิชา:</b></font></td>
          <td><font style="font-family: 'TH SarabunPSK';font-size: 12px;"><?php echo $rows['department'];?></font></td>
        </tr>
        <tr>
          <td><font style="font-family: 'TH SarabunPSK';font-size: 12px;"><b>โทรศัพท์:</b></font></td>
          <td><font style="font-family: 'TH SarabunPSK';font-size: 12px;"><?php echo $rows['phone'];?></font></td>
        </tr>
        <tr>
          <td><font style="font-family: 'TH SarabunPSK';font-size: 12px;"><b>อีเมล์:</b></font></td>
          <td><font style="font-family: 'TH SarabunPSK';font-size: 12px;"><?php echo $rows['email'];?></font></td>
        </tr>
        <tr>
        </table>
        <br><br>
        <table align="center" border="0" cellspacing="0" cellpadding="3">
        <tr>
            <td colspan="2" align="center"></td>
            <td></td>
        </tr>
        <tr>
            <td><p style="font-family: 'TH SarabunPSK';font-size: 12px;">ลงชื่อ</p></td>
            <td align="center"><p style="font-family: 'TH SarabunPSK';font-size: 14px;">.........................................</p></td>
            <td><p style="font-family: 'TH SarabunPSK';font-size: 12px;">วันที่ <?php echo $rows['dateTime'];?></p></td>
        </tr>
        <tr>
            <td></td>
            <td align="center"><p style="font-family: 'TH SarabunPSK';font-size: 12px;"><?php echo $rows['fullname'];?></p></td>
            <td></td>
        </tr>
        </table>
    </td>
  </tr>
  </table>
  <p></p>
  <table bgcolor="" width="100%" border="0" cellspacing="0" cellpadding="3" align="right">
  <?php /* ?><tr>
    <td><font style="font-family: 'TH SarabunPSK';font-size: 12px;"><b>กรุณาส่งใบสมัครมายัง</b> oleclick@hotmail.com</font>
    </td>
  </tr><?php */ ?>
  <tr>
    <td><font style="font-family: 'TH SarabunPSK';font-size: 12px;">ติดต่อสอบถาม เบอร์โทรศัพท์ 084-178-1404 โทรศัพท์ 055 706 555 ต่อ 3030</font>
    </td>
  </tr>
  <tr>
    <td><font style="font-family: 'TH SarabunPSK';font-size: 12px;color: red;">*** รับจำนวนจำกัด ***</font>
    </td>
  </tr>
  </table>
  <table bgcolor="" width="100%" border="0" cellspacing="0" cellpadding="5" align="right">
  <tr>
    <td><img src='https://arit.kpru.ac.th/ap/qrcode/qrcode.php?data=<?php echo $ap_site.$ap_folder;?>&size=74x74&logo=<?php echo $logo;?>' border='0' alt="QRCODE" /><!-- <barcode code="<?php echo "$ap_site$ap_folder";?>" size="0.8" type="QR" error="M" class="barcode" /> --><br><a href="<?php echo "$ap_site$ap_folder";?>"><?php echo "$ap_site$ap_folder";?></a></td>
  </tr>
  </table>
  </html>
  <?php
  $html = ob_get_contents();
  ob_end_clean();

  $pdf = new mPDF('th', 'A4', '0', '', 20, 15, 30, 20);
  $pdf->mirrorMargins = 1;
  $pdf->SetDisplayMode('fullpage');
  $stylesheet = file_get_contents('../../theme.css');
  $pdf->WriteHTML($stylesheet,1);
  $pdf->SetHTMLHeader($header);
  $pdf->SetHTMLHeader($header,'E');
  $pdf->SetHTMLFooter($footer);
  $pdf->SetHTMLFooter($footer,'E');
  $pdf->SetWatermarkText("$title_en");
  $pdf->watermark_font = 'DejaVuSansCondensed';
  $pdf->showWatermarkText = true;
  $pdf->SetTitle("$title");
  $pdf->SetAuthor("$title");
  $pdf->SetCreator("Anucha Puangpaka");
  $pdf->SetSubject("$title");
  $pdf->SetKeywords("$title");
  $pdf->WriteHTML($html, 2);
  $pdf->Output("../../contents/register/$_GET[id].pdf");
  $pdf->Output();

  include('logs.php');

  mysqli_close($conn);
}
?>