-
Notifications
You must be signed in to change notification settings - Fork 1
/
addalias_functions.php
78 lines (65 loc) · 1.65 KB
/
addalias_functions.php
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
<?php
include 'connect.php';
include 'user.php';
/*
criminal_ID
crime_ID
officer_ID
*/
session_start();
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header("Location: index.html");
exit();
}
function add_alias() {
User::checkPerm();
global $con;
$sql = "INSERT INTO `alias`(`alias_id`, `criminal_ID`, `alias`) VALUES (NULL, ?, ?)";
$criminal_ID = $_POST['criminal_ID'];
$alias = $_POST['new_alias'];
try {
$con->begin_transaction();
$stmt = $con->prepare($sql);
$stmt->bind_param(
"is",
$criminal_ID,
$alias,
);
$stmt->execute();
$con->commit();
header("location:popup.php?criminal_ID=$criminal_ID");
} catch (mysqli_sql_exception $exception) {
$con->rollback();
die($exception);
}
}
function delete_alias() {
User::checkPerm();
global $con;
// $officer_ID = array_key_exists('officer_ID', $_POST) ? $_POST['officer_ID'] : die("Officer ID required!");
$criminal_ID = $_POST['criminal_ID'];
$sql = "DELETE FROM alias WHERE alias_id = ?";
$alias_ID = $_POST['alias_ID'];
try {
$con->begin_transaction();
$stmt = $con->prepare($sql);
$stmt->bind_param("i", $alias_ID);
$stmt->execute();
$con->commit();
header("location:popup.php?criminal_ID=$criminal_ID");
} catch (mysqli_sql_exception $exception) {
$con->rollback();
die($exception);
}
}
if (isset($_POST['m'])) {
$method = $_POST['m'];
} else {
return;
}
if ($method == 'a') {
add_alias();
} else {
delete_alias();
}
?>