Initial commit - TPU Survey System with Google Forms & Certificate Generator
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Authentication Helper
|
||||
* TPU Survey System
|
||||
*/
|
||||
|
||||
session_start();
|
||||
|
||||
function isLoggedIn() {
|
||||
return isset($_SESSION['user_id']);
|
||||
}
|
||||
|
||||
function isAdmin() {
|
||||
return isset($_SESSION['role']) && $_SESSION['role'] === 'admin';
|
||||
}
|
||||
|
||||
function isTeacher() {
|
||||
return isset($_SESSION['role']) && $_SESSION['role'] === 'teacher';
|
||||
}
|
||||
|
||||
function requireLogin() {
|
||||
if (!isLoggedIn()) {
|
||||
http_response_code(401);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode(['error' => 'กรุณาเข้าสู่ระบบ']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function requireAdmin() {
|
||||
requireLogin();
|
||||
if (!isAdmin()) {
|
||||
http_response_code(403);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode(['error' => 'ไม่มีสิทธิ์เข้าถึง']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function getCurrentUser() {
|
||||
if (!isLoggedIn()) return null;
|
||||
return [
|
||||
'id' => $_SESSION['user_id'],
|
||||
'username' => $_SESSION['username'],
|
||||
'role' => $_SESSION['role'],
|
||||
'full_name' => $_SESSION['full_name']
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Database Configuration
|
||||
* TPU Survey System
|
||||
*/
|
||||
|
||||
define('DB_HOST', 'localhost');
|
||||
define('DB_NAME', 'tpu_survey_v2');
|
||||
define('DB_USER', 'root');
|
||||
define('DB_PASS', '');
|
||||
define('DB_CHARSET', 'utf8mb4');
|
||||
|
||||
function getDB() {
|
||||
static $pdo = null;
|
||||
if ($pdo === null) {
|
||||
try {
|
||||
$dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=" . DB_CHARSET;
|
||||
$pdo = new PDO($dsn, DB_USER, DB_PASS, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false
|
||||
]);
|
||||
} catch (PDOException $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => 'Database connection failed: ' . $e->getMessage()]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
function jsonResponse($data, $code = 200) {
|
||||
http_response_code($code);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getInput() {
|
||||
$json = file_get_contents('php://input');
|
||||
return json_decode($json, true) ?: [];
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Mail / SMTP Configuration
|
||||
* TPU Survey System
|
||||
*/
|
||||
|
||||
define('SMTP_HOST', 'smtp.gmail.com');
|
||||
define('SMTP_PORT', 587); // 587 for STARTTLS, 465 for SMTPS
|
||||
define('SMTP_USER', 'pongpon@tapee.ac.th'); // Change to your actual Tapi University email or Gmail
|
||||
define('SMTP_PASS', 'jteecfgwdegjhvai'); // Change to your actual SMTP / App Password
|
||||
define('SMTP_SECURE', 'tls'); // 'tls' or 'ssl'
|
||||
|
||||
define('MAIL_FROM_EMAIL', 'pongpon@tapee.ac.th');
|
||||
define('MAIL_FROM_NAME', 'มหาวิทยาลัยตาปี (Tapi University)');
|
||||
Reference in New Issue
Block a user