-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess-return.php
More file actions
81 lines (67 loc) · 2.45 KB
/
Copy pathprocess-return.php
File metadata and controls
81 lines (67 loc) · 2.45 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
<?php
// ✅ process-return.php
// Serial no se student ko returned mark karta hai extended_logs mein
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
require_once 'db_connect.php';
if (!isset($_SESSION['staff_user'])) {
header('Location: login.php');
exit();
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('Location: manual-return-entry.php');
exit();
}
$serial_no = strtoupper(trim($_POST['serial_no'] ?? ''));
if (empty($serial_no)) {
$_SESSION['error'] = 'Serial number enter karein.';
header('Location: manual-return-entry.php');
exit();
}
// ── Record dhundo ─────────────────────────────────────────────
$stmt = mysqli_prepare($conn, "SELECT * FROM extended_logs WHERE serial_no = ? LIMIT 1");
mysqli_stmt_bind_param($stmt, 's', $serial_no);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$record = mysqli_fetch_assoc($result);
mysqli_stmt_close($stmt);
if (!$record) {
$_SESSION['error'] = "Serial no '$serial_no' nahi mila. Check karein.";
header('Location: manual-return-entry.php');
exit();
}
if ($record['status'] === 'Returned') {
$_SESSION['error'] = "$serial_no pehle se Returned mark hai. (Return time: "
. ($record['in_time'] ?? 'N/A') . ")";
header('Location: manual-return-entry.php');
exit();
}
// ── Update in_time and in_date ──────────────────────────
$now_time = date('H:i:s');
$now_date = date('Y-m-d');
$upd = mysqli_prepare($conn,
"UPDATE extended_logs SET status='Returned', in_time=?, in_date=? WHERE id=?"
);
mysqli_stmt_bind_param($upd, 'ssi', $now_time, $now_date, $record['id']);
$ok = mysqli_stmt_execute($upd);
mysqli_stmt_close($upd);
if (!$ok) {
$_SESSION['error'] = 'Update failed. Please try again.';
header('Location: manual-return-entry.php');
exit();
}
// ── Success: confirmation page dikhao ────────────────────────
$_SESSION['return_success'] = [
'serial_no' => $serial_no,
'student_name' => $record['student_name'],
'roll_no' => $record['roll_no'],
'out_date' => $record['out_date'],
'out_time' => $record['out_time'],
'in_time' => $now_time,
'in_date' => $now_date,
'pass_type' => $record['pass_type'],
];
header('Location: return-confirmed.php');
exit();
?>