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
|
<?php require_once(__DIR__ . '/../checkuser.php'); $root_ids = $_POST['student']['selected']; if (!empty($root_ids) && is_array($root_ids)) { Db\Util::transaction($dbh, function() use ($dbh, $root_ids) { $student_columns = Db\Util::columns($dbh, 'mis_student'); $in_values = array(); foreach ($root_ids as $root_id) { $in_values[] = '?'; } $in = implode(', ', $in_values); $sql = "SELECT * FROM `mis_student` WHERE `root_id` IN ($in) AND `is_latest` = ? FOR UPDATE"; $parameters = array_merge($root_ids, array(1)); $sth = Db\Util::execute($dbh, $sql, $parameters); $students = $sth->fetchAll(); foreach ($students as $student) { $new_student = $student; foreach (General::fields() as $field) { unset($new_student[$field]); } $new_student['deleted'] = 1; $student['is_latest'] = 0; Db\Util::update($dbh, 'mis_student', $student, $student_columns); $new_student['id'] = Db\Util::create($dbh, 'mis_student', $new_student, $student_columns); } }); $data = array( 'message' => 'Deleted', ); redirectAndExit(Util::link(__DIR__ . '/index.php') . '?' . http_build_query($data)); }
|