<?php
/*!
* Copyright Anucha Puangpaka
* Contact anucha.ppk@icloud.com 062-479-9836
*/
error_reporting(E_ALL);
ini_set("display_errors", 0);
session_start();
$_GET['page'] = filter_var($_POST['page'], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
if(!is_numeric($_GET['page'])){
header('HTTP/1.1 500 Invalid page number!');
exit;
}
include('../../config.php');
$_GET['xcode'] = $_POST['xcode'];
$sql = "select * from ap_products where code='$_GET[xcode]'";
$query = mysqli_query($conn,$sql);
$rows = mysqli_fetch_array($query);
$name = $rows['name'];
$linenotify = $rows['linenotify'];
function line_notify3($message, $token, $id){
if(!empty($id)){
$headers = array('Method: POST', 'Content-type: multipart/form-data', 'Authorization: Bearer '.$token);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://notify-api.line.me/api/notify");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $message);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if(curl_error($ch)) {
$error_ = array('status' => "Error",'massage' => curl_error($ch));
$result_ = json_decode($error_, true);
}else{
$result_ = json_decode($result, true);
}
curl_close($ch);
include('../../connDB.php');
mysqli_query($conn,"update ap_register set notify='1' where id='$id' ");
}
}
function mobile_replace($text) {
$text = str_replace('-', '', $text);
$textx = substr($text,0,3).'-';
$textx .= substr($text,3,3).'-';
$textx .= substr($text,6);
return $textx;
}
/*function dateThai2($str){
$strYear = (date("Y",strtotime($str)))+543;
$strMonth = date("n",strtotime($str));
$strDay = date("j",strtotime($str));
$strTime = date("H:i",strtotime($str));
$strMonthCut = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
$strMonthThai = $strMonthCut[$strMonth];
return "$strDay $strMonthThai $strYear $strTime";
}*/
?>
<div class="table-responsive">
<table class="table">
<thead>
<tr style="font-weight: bold;">
<td>ลำดับ</td>
<?php
$sql = "select * from ap_register_form where regCode='$_GET[xcode]' order by regFieldCode asc";
$query = mysqli_query($conn,$sql);
while($rows = mysqli_fetch_array($query)){
if($rows['regFieldCode']=="f1000" || $rows['regFieldCode']=="f1002" || $rows['regFieldCode']=="f1008"){
if($rows['regTypeFieldCode']=="text"){
?>
<td><?php echo $rows['regNameFieldCode']; ?></td>
<?php
}else{
?>
<td><?php echo $rows['regAlias']; ?></td>
<?php
}
}
}
?>
<td>วันที่ เวลา</td>
<?php /*if(!empty($_SESSION['user'])){ ?>
<td>เกียรติบัตร</td>
<?php }*/ ?>
</tr>
</thead>
<tbody>
<?php
$sql = "select * from ap_register where code='$_GET[xcode]' order by id desc";
$query = mysqli_query($conn,$sql);
$num_rows = mysqli_num_rows($query);
$i = 0;
while($rows = mysqli_fetch_array($query)){
$i++;
if($rows['notify']==""){
$message = array(
'message' => "\nลงทะเบียน $name ท่านที่ $num_rows\n$rows[f1002]\n$rows[f1001]\n$ap_site$ap_folder"."ap/register/?nu=info&xcode=$_GET[xcode]",
'imageThumbnail' => '',
'imageFullsize' => '',
'stickerPackageId' => '',
'stickerId' => ''
);
if(!empty($rows['f1002'])){
echo line_notify3($message, $linenotify, $rows['id']);
}
}
echo "<tr>";
echo "<td>";
if(!empty($_SESSION['user'])){
echo "<a href='ap/register/?nu=&id=$rows[id]&xcode=$_GET[xcode]'>แก้ไข</a> ";
echo " / <a href=\"ap/register/?nu=info&xcode=$_GET[xcode]#\" onclick=\"if (confirm('ยืนยันการลบ?')) location.href='ap/register/?nu=delete&id=$rows[id]&xcode=$_GET[xcode]';\">ลบ</a> ";
}
echo "$i.</td>";
$sql3 = "select * from ap_register_form where regCode='$_GET[xcode]' order by regFieldCode asc";
$query3 = mysqli_query($conn,$sql3);
while($rows3 = mysqli_fetch_array($query3)){
if($rows3['regFieldCode']=="f1000" || $rows3['regFieldCode']=="f1002" || $rows3['regFieldCode']=="f1008"){
if($rows3['regTypeFieldCode']=="text"){
if($rows3['regFieldCode']=="f1008"){
echo "<td>".mobile_replace($rows[$rows3['regFieldCode']])."</td>";
}else{
echo "<td>".$rows[$rows3['regFieldCode']]."</td>";
}
}
if($rows3['regTypeFieldCode']=="radio" || $rows3['regTypeFieldCode']=="checkbox"){
if($rows[$rows3['regFieldCode']]=="1"){
echo "<td><img src=\"../../contents/images/check.png\" width=\"16\" alt=\"\"></td>";
}else{
echo "<td></td>";
}
}
/*echo "<td><a href='/ap/register/?nu=apprint&xcode=".$rows['code']."&id=".$rows['id']."' target='_blank'>".$rows['fullname']."</a></td>";*/
/*echo "<td>".$rows['phone']."</td>";*/
/*echo "<td>".$rows['email']."</td>";*/
/*if($rows['photo']!=""){
echo "<td align='center'><a href='register/$rows[photo]' target='_blank'>คลิก</td>";
}else{
echo "<td align='center'>-</td>";
}*/
}
}
if(date('Y-m-d')==substr($rows['dateTime'],0,10)){
echo "<td><font size='3'><span class='label label-info'>".dateThai2($rows['dateTime'])."</sapn></font></td>";
}else{
echo "<td>".dateThai2($rows['dateTime'])."</td>";
}
/*if(!empty($_SESSION['user'])){
echo "<td><a href='/ap/register/certificate.php?nu=&id=$rows[id]&xcode=$_GET[xcode]' target='_blank'>พิมพ์</a></td>";
}*/
echo "</tr>";
}
?>
</tbody>
</table>
</div>
<?php
mysqli_close($conn);
?>