-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.php
More file actions
163 lines (151 loc) · 6.61 KB
/
Copy pathsettings.php
File metadata and controls
163 lines (151 loc) · 6.61 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
session_start();
require 'config.php';
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
$success = "";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['order_format'])) {
$format = $_POST['order_format'];
$stmt = $pdo->prepare("UPDATE settings SET setting_value = ? WHERE setting_key = 'order_format'");
$stmt->execute([$format]);
$success = "บันทึกรูปแบบเรียบร้อยแล้ว";
}
if (isset($_POST['current_year_input'])) {
$year_be = intval($_POST['current_year_input']);
$year_ad = $year_be - 543; // Convert BE to AD
$stmt = $pdo->prepare("UPDATE settings SET setting_value = ? WHERE setting_key = 'current_year'");
$stmt->execute([$year_ad]);
$success = "บันทึกปีทำการเรียบร้อยแล้ว";
}
}
// Get settings
$stmt = $pdo->query("SELECT setting_key, setting_value FROM settings");
$settings = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
$current_format = $settings['order_format'] ?? '{อบ.}{run_no}/{year}';
$current_year_ad = $settings['current_year'] ?? date('Y');
$current_year_be = $current_year_ad + 543;
?>
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ตั้งค่าระบบ - ODS</title>
<link rel="stylesheet" href="css/style.css">
<link href="https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;600&display=swap" rel="stylesheet">
<style>
.settings-section {
margin-bottom: 2rem;
padding-bottom: 2rem;
border-bottom: 1px solid rgba(0,0,0,0.05);
}
.settings-section:last-child {
border-bottom: none;
margin-bottom: 0;
padding-bottom: 0;
}
.settings-title {
font-size: 1.2rem;
font-weight: 700;
color: #1e3a8a;
margin-bottom: 1rem;
display: flex;
align-items: center;
gap: 0.5rem;
}
.input-group-lg input {
font-size: 1.5rem;
text-align: center;
font-weight: bold;
letter-spacing: 2px;
color: #2563eb;
background: #fff;
border: 2px solid #e2e8f0;
}
.input-group-lg input:focus {
border-color: #2563eb;
box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}
.alert {
padding: 1rem;
border-radius: 12px;
margin-bottom: 2rem;
font-weight: 600;
text-align: center;
}
.alert.success {
background: #d1fae5;
color: #065f46;
border: 1px solid #a7f3d0;
}
</style>
</head>
<body>
<nav class="navbar">
<div class="container">
<a href="admin.php" class="brand">
<span class="brand-icon">⚡</span> ODS Admin
</a>
<div class="burger-menu" onclick="toggleMenu()">☰</div>
<div class="nav-links" id="navLinks">
<a href="admin.php" class="nav-item">
<span>📋</span> จัดการคำสั่ง
</a>
<a href="settings.php" class="nav-item active">
<span>⚙️</span> ตั้งค่า
</a>
<a href="logout.php" class="nav-item btn-logout">
<span>🚪</span> ออกจากระบบ
</a>
</div>
</div>
</nav>
<script>
function toggleMenu() {
document.getElementById('navLinks').classList.toggle('active');
}
</script>
<div class="container content">
<div class="glass-card" style="padding: 3rem; max-width: 600px; margin: 0 auto;">
<h1 style="text-align: center; margin-bottom: 2rem; color: var(--text-color);">⚙️ ตั้งค่าระบบ</h1>
<?php if ($success) echo "<div class='alert success' style='margin-bottom: 2rem;'>$success</div>"; ?>
<!-- Section 1: Budget Year -->
<div class="settings-section">
<div class="settings-title">📅 ปีทำการ (Budget Year)</div>
<form method="POST">
<p class="order-desc" style="margin-bottom: 1rem;">
กำหนดปี พ.ศ. ปัจจุบันสำหรับการออกเลขคำสั่งใหม่
</p>
<div class="form-group input-group-lg">
<input type="number" name="current_year_input" value="<?php echo $current_year_be; ?>" required min="2400" max="3000" placeholder="2567">
</div>
<button type="submit" class="btn-primary" style="width: 100%;">บันทึกปีทำการ</button>
</form>
</div>
<!-- Section 2: Order Format -->
<div class="settings-section">
<div class="settings-title">🔢 รูปแบบเลขที่คำสั่ง</div>
<form method="POST">
<div class="form-group">
<label>Format Pattern</label>
<input type="text" name="order_format" value="<?php echo htmlspecialchars($current_format); ?>" required style="font-family: monospace; font-size: 1.1rem;">
<div class="order-desc" style="margin-top: 1rem; background: rgba(255,255,255,0.5); padding: 1rem; border-radius: 8px;">
<strong>ตัวแปรที่ใช้ได้:</strong><br>
<code>{run_no}</code> : เลขลำดับ (1, 2, 3...)<br>
<code>{year}</code> : ปี พ.ศ. (<?php echo $current_year_be; ?>)<br><br>
<strong>ตัวอย่างผลลัพธ์:</strong><br>
<span style="color: var(--primary-color); font-weight: bold; font-size: 1.2rem;">
<?php echo str_replace(['{run_no}', '{year}'], ['1', $current_year_be], $current_format); ?>
</span>
</div>
</div>
<button type="submit" class="btn-primary" style="width: 100%;">บันทึกรูปแบบ</button>
</form>
</div>
</div>
</div>
</body>
</html>