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