-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcharges_function.php
More file actions
140 lines (118 loc) · 3.7 KB
/
charges_function.php
File metadata and controls
140 lines (118 loc) · 3.7 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
<?php
include 'connect.php';
class Appeal
{
public $appeal_ID;
public $crime_ID;
public $filing_date;
public $hearing_date;
public $appeal_status;
public static function fromArrayOrResult($arrOrRes)
{
$appeal = new Appeal;
$appeal->appeal_ID = $arrOrRes['appeal_ID'];
$appeal->crime_ID = $arrOrRes['crime_ID'];
$appeal->filing_date = $arrOrRes['filing_date'];
$appeal->hearing_date = $arrOrRes['hearing_date'];
$appeal->appeal_status = $arrOrRes['appeal_status'];
return $appeal;
}
}
function get_appeal_info_from_db()
{
global $con;
$sql = "SELECT * FROM appeals WHERE crime_ID = ?";
$stmt = $con->prepare($sql);
$stmt->bind_param("i", $crime_ID);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
return Appeal::fromArrayOrResult($row);
}
function add_appeal()
{
global $con;
$criminal_ID = array_key_exists('criminal_ID', $_REQUEST) ? $_REQUEST['criminal_ID'] : die("Criminal ID required!");
$appeal_ID = filter_input(INPUT_POST, 'charge_ID', FILTER_VALIDATE_INT);
$crime_ID = $_POST['crime_ID'];
$crime_code = $_POST['crime_code'];
$charge_status = $_POST['charge_status'];
$fine_amount = $_POST['fine_amount'];
$court_fee = $_POST['court_fee'];
$amount_paid = $_POST['amount_paid'];
$pay_due_date = $_POST['pay_due_date'];
$sql = "INSERT INTO `crime_charges`(`charge_ID`, `crime_ID`, `crime_code`, `charge_status`, `fine_amount`, `court_fee`, `amount_paid`, `pay_due_date`) VALUES (?,?,?,?,?,?,?,?)";
try {
$con->begin_transaction();
$stmt = $con->prepare($sql);
$stmt->bind_param(
"iisss",
$ap
);
$stmt->execute();
$con->commit();
header("location:popup.php?criminal_ID=$criminal_ID");
} catch (mysqli_sql_exception $exception) {
$con->rollback();
die($exception);
}
}
function update_appeal()
{
global $con;
$criminal_ID = array_key_exists('criminal_ID', $_REQUEST) ? $_REQUEST['criminal_ID'] : die("Criminal ID required!");
$sql = "UPDATE `appeals` SET `appeal_ID`= ?, `crime_ID`= ?, `filing_date`= ?, `hearing_date`= ?, `appeal_status`= ? WHERE appeal_ID = ?";
$appeal = Appeal::fromArrayOrResult($_POST);
try {
$con->begin_transaction();
$stmt = $con->prepare($sql);
$stmt->bind_param(
"iisssi",
$appeal->appeal_ID,
$appeal->crime_ID,
$appeal->filing_date,
$appeal->hearing_date,
$appeal->appeal_status,
$appeal->appeal_ID
);
$stmt->execute();
$con->commit();
header("location:popup.php?criminal_ID=$criminal_ID");
} catch (mysqli_sql_exception $exception) {
$con->rollback();
die($exception);
}
}
function delete_appeal()
{
global $con;
$appeal_ID = array_key_exists('appeal_ID', $_POST) ? $_POST['appeal_ID'] : die("Appeal ID required!");
$criminal_ID = $_POST['criminal_ID'];
$sql = "DELETE FROM appeals WHERE appeal_ID = ?";
$con->begin_transaction();
try {
$stmt = $con->prepare($sql);
$stmt->bind_param("i", $appeal_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_appeal();
} elseif ($method == 'e') {
$appeal = get_appeal_info_from_db();
} elseif ($method == 'u') {
update_appeal();
} elseif ($method == 'd') {
delete_appeal();
}
?>