<?php
/*!
* Copyright Anucha Puangpaka
* Contacts anucha.ppk@icloud.com 062-479-9836
*/
if($_GET['nu']==""){
include('../../head.php');
?>
<div class="container theme-showcase body-main-row-body" role="main">
<div class="breadcrumbx">
<?php
/* include('../../translate.php'); */
$sql = "select * from ap_catalogs where code='$_GET[catalogCode]'";
$query = mysqli_query($conn,$sql);
$rows = mysqli_fetch_array($query);
?>
<h2 align="center"><?php echo $rows['name']; ?></h2>
<p align="center"><?php echo $title; ?></p>
<div class="visible-lg visible-md">
<div class="input-group">
<label for="">กรุณาระบุคำค้น</label>
<input type="text" name="q" id="q" class="form-control" placeholder="กรุณาระบุคำค้น" onkeyup="APSearch()"/>
</div>
<hr>
<div class="table-responsive">
<table class="table table-striped" id="APTabel">
<thead>
<tr>
<th width="70"><?php echo $ap_num; ?></th>
<th><?php echo $ap_document; ?></th>
<th width="100"><?php echo $ap_stat; ?></th>
<th><?php echo $ap_date; ?></th>
<th><?php echo $ap_author; ?></th>
<th><?php echo $ap_filesize; ?></th>
</tr>
</thead>
<tbody>
<?php
$sql = "select * from ap_edms where lang='$_GET[lang]' and catalogCode='$_GET[catalogCode]' order by years desc, num asc";
$query = mysqli_query($conn,$sql);
$i = 0;
while($rows = mysqli_fetch_array($query)){
$fullPath = $_SERVER['DOCUMENT_ROOT'].'/'.$ap_folder.'contents/edms/'.$rows['files'];
if (is_file($fullPath)) {
$information = pathinfo($fullPath);
$type = $information['extension'];
}
$size = filesize($fullPath);
if ($size >= 1073741824) {
$size = round($size / 1073741824, 2) . " GB";
} elseif ($size >= 1048576) {
$size = round($size / 1048576, 2) . " MB";
} elseif ($size >= 1024) {
$size = round($size / 1024, 2) . " KB";
}
if($last!=$rows['years']){
$i = 0;
if($rows['years']!="-"){
?>
<tr>
<td colspan="6"><h3><?php echo $rows['years']; ?></h3></td>
</tr>
<?php
}
}
$last = $rows['years'];
$i++;
if(empty($rows['counters'])){
$rows['counters'] = 0;
}
?>
<tr>
<td><?php echo $i;?>.</td>
<td><a href="<?php echo $ap_site.$ap_folder; ?>ap/edms/?nu=downloads&id=<?php echo $rows['id'] ?>&type=<?php echo $type; ?>" target="_blank"><?php echo $rows['name'];?></a> <?php if(date('Y-m-d')==substr($rows['date_time'],0,10)){ echo "<img src=\"$ap_site$ap_folder"."contents/images/new2.gif\" width='30px'>"; } ?></td>
<td><?php echo number_format($rows['counters']) ?></td>
<td><?php echo dateThai($rows['date_time']);?></td>
<td><?php echo $rows['author'];?></td>
<td><?php echo $size;?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<?php
/*$_REQUEST['data'] = urlencode(substr("$ap_site",0,-1)."$_SERVER[REQUEST_URI]");
//$_REQUEST['data'] = "$ap_site$ap_folder";
$PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR;
$PNG_WEB_DIR = 'temp/';
if(!is_dir($PNG_WEB_DIR)) mkdir ($PNG_WEB_DIR);
include('../../qrcode/qrlib.php');
if(!file_exists($PNG_TEMP_DIR))
mkdir($PNG_TEMP_DIR);
$filename = $PNG_TEMP_DIR.'ap.png';
$errorCorrectionLevel = 'H';
if(isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H')))
$errorCorrectionLevel = $_REQUEST['level'];
$matrixPointSize = 10;
if(isset($_REQUEST['size']))
$matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10);
if(isset($_REQUEST['data'])) {
if(trim($_REQUEST['data']) == '')
die('Anucha Puangpaka');
$filename = $PNG_TEMP_DIR.'ap'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
QRcode::png($_REQUEST['data'], $filename, $errorCorrectionLevel, $matrixPointSize, 2);
}else{
QRcode::png('Anucha Puangpaka', $filename, $errorCorrectionLevel, $matrixPointSize, 2);
}
echo '<img class="p-3 bg-white rounded shadow-sm" src="'.$PNG_WEB_DIR.basename($filename).'" /><div class="pt-3"></div>';
echo $_REQUEST['data'];*/
?>
<img class="p-3 bg-white rounded shadow-sm" src="ap/qrcode/qrcode.php?data=<?php echo urlencode(substr("$ap_site",0,-1)."$_SERVER[REQUEST_URI]"); ?>&size=177x177&logo=<?php echo $logo ?>" border="0" alt="<?php echo $title ?>" title="<?php echo $title ?>" />
</div>
<div class="visible-sm visible-xs">
<?php
$sql = "select * from ap_edms where lang='$_GET[lang]' and catalogCode='$_GET[catalogCode]' order by years desc, num asc";
$query = mysqli_query($conn,$sql);
$i = 0;
while($rows = mysqli_fetch_array($query)){
$fullPath = "c:/inetpub/wwwroot/$ap_folder"."contents/edms/".$rows['files'];
if (is_file($fullPath)) {
$information = pathinfo($fullPath);
$type = $information['extension'];
}
$size = filesize($fullPath);
if ($size >= 1073741824) {
$size = round($size / 1073741824, 2) . " GB";
} elseif ($size >= 1048576) {
$size = round($size / 1048576, 2) . " MB";
} elseif ($size >= 1024) {
$size = round($size / 1024, 2) . " KB";
}
$i++;
if(empty($rows['counters'])){
$rows['counters'] = 0;
}
?>
<p><?php echo $i;?>. <a href="<?php echo $ap_site.$ap_folder; ?>ap/edms/?nu=downloads&id=<?php echo $rows['id'] ?>&type=<?php echo $type; ?>" target="_blank"><?php echo $rows['name'];?></a> [อ่าน <?php echo number_format($rows['counters']) ?>] [<?php echo dateThai($rows['date_time']);?>] <?php if(date('Y-m-d')==substr($rows[date_time],0,10)){ echo "<img src=\"$ap_site$ap_folder"."contents/images/new2.gif\" width='30px'>"; } ?></p>
<?php
}
?>
</div>
<?php /* ?><div class="row">
<div class="col-lg-8 col-md-8 col-sm-12">
<p><img src='https://arit.kpru.ac.th/ap/qrcode/qrcode.php?data=<?php echo htmlspecialchars("$ap_site$ap_folder$_SERVER[REQUEST_URI]"); ?>&size=114x114&logo=<?php echo $logo;?>' border='0' alt="QRCODE" /></p>
<p><a href="<?php echo "$ap_site$ap_folder$_SERVER[REQUEST_URI]"; ?>"><?php echo $ap_site.$ap_folder.$_SERVER['REQUEST_URI']; ?></a></p>
</div>
<div class="col-lg-4 col-md-4 col-sm-12">
<p align="right"><a href="javascript:open.Window();" onClick="MM_openBrWindow('https://www.facebook.com/sharer/sharer.php?u=<?php echo "$ap_site$ap_folder$_SERVER[REQUEST_URI]";?>','facebook','scrollbars=yes,resizable=yes,width=560,height=600')">
<img src="contents/images/facebook.png" width="45px" alt="Facebook">
</a>
<a href="javascript:open.Window();" onClick="MM_openBrWindow('https://twitter.com/share?url=<?php echo "$ap_site$ap_folder$_SERVER[REQUEST_URI]";?>','twitter','scrollbars=yes,resizable=yes,width=560,height=600')">
<img src="contents/images/twitter.png" width="45px" alt="Twitter">
</a>
<!-- <a href="https://plus.google.com/share?url=<?php echo "$ap_site$ap_folder$_SERVER[REQUEST_URI]"?>" target="google_window">
<img src="contents/images/google-plus.png" width="45px" alt="Google Plus">
</a> -->
<a href="javascript:open.Window();" onClick="MM_openBrWindow('https://lineit.line.me/share/ui?url=<?php echo "$ap_site$ap_folder$_SERVER[REQUEST_URI]";?>','LINE','scrollbars=yes,resizable=yes,width=560,height=600')">
<img src="contents/images/line.png" width="45px" alt="LINE">
</a></p>
</div>
</div><?php */ ?>
<script>
function APSearch() {
var input, filter, table, tr, td, i;
input = document.getElementById("q");
filter = input.value.toUpperCase();
table = document.getElementById("APTabel");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[2];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
</div>
<p></p>
</div><!-- /.container -->
<?php
include ('../../footText.php');
include ('../../foot.php');
}
if($_GET['nu']=="downloads"){
include('../../config.php');
$sql = "select * from ap_edms where id='$_GET[id]'";
$query = mysqli_query($conn,$sql);
$rows = mysqli_fetch_array($query);
$counter = $rows['counters']+1;
mysqli_query($conn, "update ap_edms set counters='$counter' where id='$rows[id]'");
header("Cache-Control: public");
header('Content-Description: '.$rows['name']);
if($_GET['type']=="pdf" || $_GET['type']=="PDF"){
/*header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='."$_GET[apf]");*/
if($rows['watermark']==""){
/*header('Content-type: application/pdf');
header('Pragma: no-cache');
header('Expires: 0');
header("Content-Transfer-Encoding: binary");
readfile("../../contents/edms/$rows[files]");*/
header("Location: $ap_site$ap_folder"."contents/edms/$rows[files]");
}else{
require_once('../../mpdf/mpdf.php');
$today = date('Y-m-d H:i:s');
$ap_expire = "หมดอายุวันที่ ";
/*$footer = "
<table width=\"100%\" style=\"font-size:10px;border-bottom: px solid #000000;\">
<tr>
<td valign='bottom'><img src='https://arit.kpru.ac.th/ap/qrcode/qrcode.php?data=$ap_site$ap_folder&size=78x78' border='0' /></td>
<td valign='bottom' align=\"right\">
<p><font style='color:#000000'>Date : ".date('Y-m-d H:i:s')."</font></p>
<p><font style='color:red'>Expires on : ".date('Y-m-d H:i:s',strtotime("$today +1 month"))."</font></p></td>
</tr>
</table>";*/
$footer = "
<table width=\"100%\" style=\"font-size:10px;border-bottom: px solid #000000;\">
<tr>
<td valign='bottom' align=\"right\">
<p><font style='color:#000000'>Date : ".date('Y-m-d H:i:s')."</font>
<font style='color:red'>Expires on : ".date('Y-m-d',strtotime("$today +1 month"))."</font></p></td>
</tr>
</table>"; /* <img src='https://arit.kpru.ac.th/ap/qrcode/qrcode.php?data=$ap_site$ap_folder&lang=$_GET[lang]&size=78x78' border='0' /> */
/*$pdf = new mPDF();*/
$pdf = new mPDF('th', 'A4', '0', '0', 20, 15, 0, 0);
$pdf->mirrorMargins = 1;
$pdf->SetDisplayMode('fullpage');
$stylesheet = file_get_contents('../../theme.css');
$pdf->WriteHTML($stylesheet,1);
$pdf->SetHTMLFooter($footer);
$pdf->SetHTMLFooter($footer,'E');
/*$pdf->SetWatermarkText("$ap_watermark");
$pdf->watermark_font = 'DejaVuSansCondensed';
$pdf->showWatermarkText = true;*/
$pdf->SetWatermarkImage('../../contents/images/arit-logo.png');
$pdf->showWatermarkImage = true;
$pdf->watermarkImageAlpha = 0.03;
$pdf->SetTitle("$rows[name]");
$pdf->SetAuthor("$rows[name]");
$pdf->SetCreator("$rows[author]");
$pdf->SetSubject("$rows[name]");
$pdf->SetKeywords("$rows[name]");
$pdf->SetImportUse();
$pagecount = $pdf->SetSourceFile("../../contents/edms/$rows[files]");
for ($i=1; $i<=($pagecount); $i++) {
$pdf->AddPage();
$import_page = $pdf->ImportPage($i);
$pdf->UseTemplate($import_page);
}
$tplId = $pdf->ImportPage($pagecount);
$pdf->UseTemplate($tplId);
$pdf->Output();
}
}elseif($_GET['type']=="jpg" || $_GET['type']=="JPG" || $_GET['type']=="jpeg" || $_GET['type']=="JPEG"){
/*header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='."$_GET[apf]");*/
header('Content-type: image/jpeg');
header('Pragma: no-cache');
header('Expires: 0');
header("Content-Transfer-Encoding: binary");
readfile("../../contents/edms/$rows[files]");
}elseif($_GET['type']=="png" || $_GET['type']=="PNG"){
/*header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='."$_GET[apf]");*/
header('Content-type: image/png');
header('Pragma: no-cache');
header('Expires: 0');
header("Content-Transfer-Encoding: binary");
readfile("../../contents/edms/$rows[files]");
}elseif($_GET['type']=="gif" || $_GET['type']=="GIF"){
/*header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='."$_GET[apf]");*/
header('Content-type: image/gif');
header('Pragma: no-cache');
header('Expires: 0');
header("Content-Transfer-Encoding: binary");
readfile("../../contents/edms/$rows[files]");
}else{
/*header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='."$rows[name].$_GET[type]");
header('Pragma: no-cache');
header('Expires: 0');
header("Content-Transfer-Encoding: binary");
readfile("../../contents/edms/$rows[files]");*/
header("Location: $ap_site$ap_folder"."contents/edms/$rows[files]");
}
include('logs.php');
mysqli_close($conn);
}
?>