-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_ball.php
More file actions
119 lines (111 loc) · 3.6 KB
/
Copy pathedit_ball.php
File metadata and controls
119 lines (111 loc) · 3.6 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
<?php
//
require_once '../../includes/includes.php';
if (isset($_GET['id'])) {
if (isset($_GET['delete'])) {
$query = "DELETE FROM `ball` WHERE `id` = '" . $_GET['id'] . "'";
mysqli_query($_DB, $query);
if ($result === false) {
echo "DB ERROR: " . mysqli_error($_DB);
exit();
} else {
$_TEMPLATES['vars']['success'] = "Ball successfully deleted";
display_ball_listing();
}
}
if (isset($_POST['submit'])) {
if (!$_POST['pattern_name']) {
$errors['pattern_name'] = "Pattern name required";
}
if (isset($errors)) {
foreach ($errors as $field => $error_message) {
$_TEMPLATES['vars']['form_errors'][$field] = $error_message;
}
require_once $_TEMPLATES['location'] . 'balls/edit.tpl.php';
exit();
}
// if (isset($_FILES['userfile']['tmp_name']))
// move_uploaded_file($_FILES['userfile']['tmp_name'], '../../uploads/');
$query = "
UPDATE `balls` SET
'name'='" .$_POST['ball_name']."',
'filepath'= '" . $_POST['file']."',
'manufacturer'= '" . $_POST['manufacturer']."',
'symmetric'= '" . $_POST['symmetric']."',
'rg'= '" . $_POST['rg']."',
'differential'= '" . $_POST['differential']."',
'color'= '" . $_POST['color']."',
'stock'= '" . $_POST['stock']."',
`notes` = '" . $_POST['notes'] . "',
WHERE `id` = '" . $_GET['id'] . "'
";
$result = mysqli_query($_DB, $query);
if ($result === false) {
echo "DB ERROR: " . mysqli_error($_DB);
exit();
}
$_TEMPLATES['vars']['success'] = "Ball edited successfully";
display_ball_listing();
} else { // Display single listing edit form
$query = "
SELECT
`name`,
`manufacturer`,
`filepath`,
`symmetric`,
`rg`,
`differential`,
`color`,
`stock`,
`notes`
FROM `balls`
WHERE `id` = '" . $_GET['id'] . "'
";
$result = mysqli_query($_DB, $query);
if ($result === false) {
echo "DB ERROR: " . mysqli_error($_DB);
exit();
}
$data = mysqli_fetch_array($result, MYSQLI_ASSOC);
$_POST['ball_name'] = $data['name'];
$_POST['filepath'] = $data['filepath'];
$_POST['manufacturer'] = $data['manufacturer'];
$_POST['symmetric'] = $data['symmetric'];
$_POST['rg'] = $data['rg'];
$_POST['differential'] = $data['differential'];
$_POST['color'] = $data['color'];
$_POST['stock'] = $data['stock'];
$_POST['notes'] = $data['notes'];
require_once $_TEMPLATES['location'] . 'balls/edit.tpl.php';
exit();
}
} else {
display_ball_listing();
}
function display_ball_listing() {
global $_TEMPLATES, $_DB;
$query = "
SELECT
`id`,
`name`,
`manufacturer`,
`filepath`,
`symmetric`,
`rg`,
`differential`,
`color`,
`stock`,
`notes`
FROM `balls`
WHERE 1";
$result = mysqli_query($_DB, $query);
if ($result === false) {
echo "DB ERROR: " . mysqli_error($_DB);
exit();
}
while ($data = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$_TEMPLATES['vars']['balls'][] = $data;
}
require_once $_TEMPLATES['location'] . 'balls/listing.tpl.php';
exit();
}