-
Notifications
You must be signed in to change notification settings - Fork 0
/
preview.php
49 lines (49 loc) · 2.47 KB
/
preview.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
$dirPWroot = str_repeat("../", substr_count($_SERVER["PHP_SELF"], "/")-1);
require($dirPWroot."resource/hpe/init_ps.php");
require_once($dirPWroot."resource/php/core/reload_settings.php");
require_once($dirPWroot."resource/php/core/config.php"); require($dirPWroot."resource/php/core/db_connect.php");
require($dirPWroot."resource/php/core/getip.php");
$return = array();
function escapeSQL($input) {
global $db;
return $db -> real_escape_string($input);
} // Constants
$fileCfg = array(
"mindmap" => "Mindmap",
"IS1-1" => "ใบงาน IS1-1",
"IS1-2" => "ใบงาน IS1-2",
"IS1-3" => "ใบงาน IS1-3",
"report-1" => "รายงานโครงงานบทที่ 1",
"report-2" => "รายงานโครงงานบทที่ 2",
"report-3" => "รายงานโครงงานบทที่ 3",
"report-4" => "รายงานโครงงานบทที่ 4",
"report-5" => "รายงานโครงงานบทที่ 5",
"report-all" => "รายงานฉบับสมบูรณ์",
"abstract" => "Abstract",
"poster" => "Poster"
); $fileExts = array("png", "jpg", "jpeg", "heic", "heif", "gif", "pdf");
// Variables
$self = $_SESSION["auth"]["user"] ?? null; $year = $_SESSION["stif"]["t_year"]; $grade = $_SESSION["auth"]["info"]["grade"]; $room = $_SESSION["auth"]["info"]["room"];
$cond = "year=$year AND grade=$grade AND room=$room";
$file = escapeSQL($_REQUEST["file"]); $filePos = array_search($file, array_keys($fileCfg));
// Execute
if (empty($self)) $redirect = "/$my_url"; else {
$get = $db -> query("SELECT code,year,grade,fileStatus,fileType FROM PBL_group WHERE year=$year AND $self IN(mbr1,mbr2,mbr3,mbr4,mbr5,mbr6,mbr7)");
if (!$get) $redirect = "/error/905";
else if (!$get -> num_rows)
$redirect = "/error/902";
else {
$read = $get -> fetch_array(MYSQLI_ASSOC);
$code = $read["code"];
if (intval($read["fileStatus"])&pow(2, $filePos)) {
$extension = explode(";", $read["fileType"])[$filePos];
$year = $read["year"]; $grade = $read["grade"];
$path = "resource/upload/PBL/$year/$file/$grade/$code.$extension";
$finder = $dirPWroot.$path;
$redirect = (file_exists($finder) ? "/_resx/service/view/file?furl=".urlencode($path)."&name=$code%20-%20$fileCfg[$file]" : "/error/900");
} else $redirect = "/error/900";
}
} $db -> close();
header("Location: $redirect"); exit(0);
?>