| Server IP : 27.254.66.5 / Your IP : 216.73.217.39 Web Server : Apache/2 System : Linux cs82.hostneverdie.com 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64 User : technic2 ( 1951) PHP Version : 7.4.30 Disable Function : apache_child_terminate, apache_setenv, define_syslog_variables, escapeshellarg, escapeshellcmd,exec, fp, fput, highlight_file, ini_alter, ini_restore, inject_code, passthru,phpAds_remoteInfo, phpAds_XmlRpc,phpAds_xmlrpcDecode, phpAds_xmlrpcEncode, popen, posix_getpwuid, posix_kill, posix_mkfifo, posix_setpgid, posix_setsid,posix_setuid, posix_setuid, posix_uname,proc_open,proc_close, proc_get_status, proc_nice, proc_terminate, shell_exec, syslog, system, xmlrpc_entity_decode, show_source,sleep,pcntl_exec,virtual,suexec,dbmopen,dl,symlink,disk_free_space,diskfreespace,leak MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/technic2/domains/technicrayong.ac.th/public_html/rytc/tobe/admin/ |
Upload File : |
<?php
require_once __DIR__ . '/auth.php';
$id = (int)($_GET['id'] ?? 0);
$row = ['title'=>'','category'=>'พัฒนา EQ','detail'=>'','image'=>'','is_featured'=>0];
if ($id) {
$stmt = $pdo->prepare('SELECT * FROM activities WHERE id=?');
$stmt->execute([$id]);
$row = $stmt->fetch();
if (!$row) die('ไม่พบข้อมูล');
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = trim($_POST['title'] ?? '');
$category = trim($_POST['category'] ?? '');
$detail = trim($_POST['detail'] ?? '');
$is_featured = !empty($_POST['is_featured']) ? 1 : 0;
if ($title === '' || $category === '') die('กรุณากรอกชื่อกิจกรรมและหมวดหมู่');
$imageName = $row['image'] ?? '';
if (!empty($_FILES['image']['name'])) {
$allow = ['image/jpeg'=>'jpg','image/png'=>'png','image/webp'=>'webp','image/gif'=>'gif'];
$mime = mime_content_type($_FILES['image']['tmp_name']);
if (!isset($allow[$mime])) die('รองรับเฉพาะไฟล์รูปภาพ jpg, png, webp, gif');
$imageName = date('YmdHis') . '_' . bin2hex(random_bytes(4)) . '.' . $allow[$mime];
move_uploaded_file($_FILES['image']['tmp_name'], __DIR__ . '/../uploads/activities/' . $imageName);
}
if ($id) {
$stmt = $pdo->prepare('UPDATE activities SET title=?, category=?, detail=?, image=?, is_featured=? WHERE id=?');
$stmt->execute([$title,$category,$detail,$imageName,$is_featured,$id]);
} else {
$stmt = $pdo->prepare('INSERT INTO activities (title,category,detail,image,is_featured) VALUES (?,?,?,?,?)');
$stmt->execute([$title,$category,$detail,$imageName,$is_featured]);
}
redirect('activity_list.php?saved=1');
}
include __DIR__ . '/header.php';
?>
<div class="page-header"><div class="container"><h1 class="fw-bold"><?= $id?'แก้ไข':'เพิ่ม' ?>กิจกรรม</h1><p class="mb-0">ข้อมูลจะแสดงในหน้าเว็บไซต์</p></div></div>
<div class="container mb-5">
<div class="form-card">
<form method="post" enctype="multipart/form-data">
<div class="row g-3">
<div class="col-md-8"><label class="form-label">ชื่อกิจกรรม *</label><input type="text" name="title" class="form-control" value="<?= e($row['title']) ?>" required></div>
<div class="col-md-4"><label class="form-label">หมวดหมู่ *</label><select name="category" class="form-select" required><?php foreach(['พัฒนา EQ','ดนตรี','กีฬา','ศิลปะ','ร้องเพลง','เต้นรำ','Talk','DJ','อื่น ๆ'] as $c): ?><option <?= $row['category']===$c?'selected':'' ?>><?= e($c) ?></option><?php endforeach; ?></select></div>
<div class="col-12"><label class="form-label">รายละเอียด</label><textarea name="detail" class="form-control" rows="7"><?= e($row['detail']) ?></textarea></div>
<div class="col-md-8"><label class="form-label">รูปภาพกิจกรรม</label><input type="file" name="image" class="form-control" accept="image/*"><small class="text-muted">เว้นว่างไว้หากไม่ต้องการเปลี่ยนรูป</small></div>
<div class="col-md-4 d-flex align-items-end"><div class="form-check mb-2"><input class="form-check-input" type="checkbox" name="is_featured" value="1" id="featured" <?= $row['is_featured']?'checked':'' ?>><label class="form-check-label fw-bold" for="featured">แสดงเป็นกิจกรรมเด่น</label></div></div>
<?php if($row['image']): ?><div class="col-12"><img src="../uploads/activities/<?= e($row['image']) ?>" class="img-fluid rounded-4" style="max-height:260px"></div><?php endif; ?>
<div class="col-12"><button class="btn btn-gradient px-4">บันทึกข้อมูล</button> <a href="activity_list.php" class="btn btn-outline-secondary rounded-pill px-4">กลับ</a></div>
</div>
</form>
</div>
</div>
<?php include __DIR__ . '/footer.php'; ?>