-
Notifications
You must be signed in to change notification settings - Fork 0
/
staff_currencytrader.php
241 lines (231 loc) · 8.85 KB
/
staff_currencytrader.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
/**
* Currency Trader
* Copyright (C) Kyle
* All rights reserved.
*
* Do not remove this copyright header
*
* File: staff_currencytrader.php
* Date: Oct 25, 2014 4:57:19 PM
*/
include_once(__DIR__ . '/sglobals.php');
if($ir['userid'] != 1) {
echo "Get the hell out";
echo "<script>setTimeout(\"document.location='index.php';\",1500);</script>";
exit($h->endpage());
}
if (!isset($_GET['action'])) {
$_GET['action'] = 'index';
}
switch ($_GET['action']) {
case 'add':
add();
break;
case 'edit':
edit();
break;
case 'delete':
delete();
break;
default :
index();
}
function index() {
global $db;
$q = $db->query("select id, name, description from currency_trader");
echo "<table class='table' width='90%' cellpadding='3'>";
echo "<th colspan='100%' align='center'>Currency Trader</th>";
echo "<tr style='text-align:center;'><th> </th><th>Name</th><th>Description</th><th>Actions</th></tr>";
if (!$db->num_rows($q)) {
echo "<tr>";
echo "<td colspan='100%' style='text-align:center; font-weight:bold; color:#ff0000;'>Nothing to display</td>";
echo"</tr>";
}
else {
$i = 0;
while ($r = $db->fetch_row($q)) {
$i++;
echo "<tr>";
echo "<td>" . $i . "</td>";
echo "<td>" . $r["name"] . "</td>";
echo "<td>" . htmlentities($r["description"]) . "</td>";
echo "<td><a href='?action=edit&id=" . $r["id"] . "'>[Edit]</a> <a href='?action=delete&id=" . $r["id"] . "'>[Delete]</a></td>";
echo "</tr>";
echo "<tr'>";
}
}
echo "<th colspan='100%' style='width:100%; text-align:center;'><a href='?action=add'>[Add New]</a> <a href='staff.php'>[Back]</a</th>";
echo "</tr>";
echo "</table>";
}
function add() {
global $db;
echo "<table class='table' cellpadding='3'>";
if (isset($_POST['add_trade'])) {
$_POST['name'] = trim($db->escape(strip_tags(stripslashes($_POST['name']))));
$_POST['stat_name'] = trim($db->escape(strip_tags(stripslashes($_POST['stat_name']))));
$_POST['stat_name_cost'] = trim($_POST['stat_name_cost'] + 0);
$_POST['description'] = trim($db->escape(strip_tags(stripslashes($_POST['description']))));
$_POST['call_back'] = trim(htmlentities(strip_tags($_POST['call_back']), ENT_NOQUOTES, "UTF-8"));
$q = $db->query("select id from currency_trader where name = '{$_POST['name']}'");
if ($db->num_rows($q)) {
echo "<span style='color:red;'>You are making a duplicate</span";
}
else if (empty($_POST['name']) || empty($_POST['stat_name']) || empty($_POST['stat_name_cost'])) {
echo "<span style='color:red;'>Some of your required fields are blank</span>";
}
else {
$update = $db->query("insert into currency_trader values(NULL,'{$_POST['name']}','{$_POST['stat_name']}','{$_POST['stat_name_cost']}','{$_POST['description']}','{$_POST['call_back']}')");
if ($update) {
echo "<span style='color:green;'>A new trader was successfully created</span>";
}
else {
echo "<span style='color:red;'>There was an error inserting into the database</span>";
}
}
}
$name = (isset($_POST['name']) ? htmlentities($_POST['name']) : NULL);
$statName = (isset($_POST['stat_name']) ? htmlentities($_POST['stat_name']) : '');
$cost = (isset($_POST['stat_name_cost']) ? htmlentities($_POST['stat_name_cost']) : '');
$desc = (isset($_POST['description']) ? htmlentities($_POST['description']) : '');
$callBack = (isset($_POST['call_back']) ? htmlentities($_POST['call_back'], ENT_NOQUOTES, "UTF-8") : '');
echo "<form action='?action=add' method='POST'>";
echo "<th colspan='100%' align='center'>Add New Trade</th>";
echo "<tr>
<td>Name</td>
<td><input type='text' name='name' value='{$name}' /></td>
</tr>
<tr>
<td>Stat Name</td>
<td>" . usertable_dropdown("stat_name", $statName) . "<br />
</tr>
<tr>
<td>Stat Cost</td>
<td><input type='text' name='stat_name_cost' value='{$cost}' /></td>
</tr>
<tr>
<td>Description</td>
<td><textarea name='description' cols='80' rows='5'>{$desc}</textarea></td>
</tr>
<tr>
<td>Call Back</td>
<td><textarea name='call_back' cols='80' rows='5'>{$callBack}</textarea></td>
</tr>";
echo "<tr>
<th colspan='100%'><input type='submit' value='Add Trade' name='add_trade' /></th>
</tr>";
echo "</form></table>";
}
function edit() {
global $db;
$id = abs((int) $_REQUEST['id']);
$q = $db->query("select id from currency_trader where id = " . $id);
if (isset($_POST['edit_trade'])) {
$_POST['name'] = trim($db->escape(strip_tags(stripslashes($_POST['name']))));
$_POST['stat_name'] = trim($db->escape(strip_tags(stripslashes($_POST['stat_name']))));
$_POST['stat_name_cost'] = trim($_POST['stat_name_cost'] + 0);
$_POST['description'] = trim($db->escape(strip_tags(stripslashes($_POST['description']))));
$_POST['call_back'] = trim(htmlentities(strip_tags($_POST['call_back']), ENT_NOQUOTES, "UTF-8"));
if (!$db->num_rows($q)) {
echo "<span style='color:red;'>This trade doesnt exist</span>";
return;
}
else if (empty($_POST['name']) || empty($_POST['stat_name']) || empty($_POST['stat_name_cost'])) {
echo "<span style='color:red;'>Some of your required fields are blank</span>";
}
else {
$update = $db->query("update currency_trader set name = '{$_POST['name']}', stat_name = '{$_POST['stat_name']}', stat_name_cost = '{$_POST['stat_name_cost']}', description = '{$_POST['description']}', call_back = '{$_POST['call_back']}' where id = {$id}");
if ($update) {
echo "<span style='color:green;'>{$_POST['name']} successfully edited</span>";
}
else {
echo "<span style='color:red;'>There was an error inserting into the database</span>";
}
}
}
$q = $db->query("select id, name, stat_name, stat_name_cost, description, call_back from currency_trader where id = " . $id);
while ($r = $db->fetch_row($q)) {
echo "<table class='table' cellpadding='3'>";
echo "<th colspan='100%' align='center'>Editing: " . htmlentities($r['name']) . "</th>";
echo "<form action='?action=edit&id={$id}' method='POST'>";
echo "<input type='hidden' name='id' value='{$id}'/>";
echo "<tr>
<td>Name</td>
<td><input type='text' name='name' value='{$r['name']}' /></td>
</tr>
<tr>
<td>Stat Name</td>
<td>" . usertable_dropdown($ddname = "stat_name", $r['stat_name']) . "<br />
</tr>
<tr>
<td>Stat Cost</td>
<td><input type='text' name='stat_name_cost' value='{$r['stat_name_cost']}' /></td>
</tr>
<tr>
<td>Description</td>
<td><textarea name='description' cols='80' rows='5'>" . htmlentities($r['description']) . "</textarea></td>
</tr>
<tr>
<td>Call Back</td>
<td><textarea name='call_back' cols='80' rows='5'>" . html_entity_decode($r['call_back']) . "</textarea></td>
</tr>";
echo "<tr>
<th colspan='100%'><input type='submit' value='Add Trade' name='edit_trade' /></th>
</tr>";
echo "</form></table>";
}
}
function delete() {
global $db;
$id = abs((int) $_REQUEST['id']);
$q = $db->query("select id, name, stat_name from currency_trader where id = " . $id);
if(!$db->num_rows($q)) {
echo "<span style='color:red;'>This currency trade doesnt seem to exist</span>";
}
else {
$r = $db->fetch_row($q);
$delete = $db->query("delete from currency_trader where id = ".$id);
if($delete) {
echo "<span style='color:green;'>".htmlentities($r['name'])." was successfully deleted</span>";
}
else {
echo "<span style='color:red;'>There was an error deleting in from the database</span>";
}
}
index();
}
//I would maybe add this into your global funcs file
function usertable_dropdown($ddname = "stats", $selected = -1) {
global $db;
$ret = "<select name='$ddname' type='dropdown'>";
$q = $db->query("show columns from users");
if ($selected == -1) {
$first = 0;
}
else {
$first = 1;
}
while ($r = $db->fetch_row($q)) {
if ($r['Field'] != "userpass") {
$ret .= "\n<option value='{$r['Field']}'";
if ($selected == $r['Field'] || $first == 0) {
$ret .= " selected='selected'";
$first = 1;
}
$ret .= ">{$r['Field']}</option>";
}
}
$db->free_result($q);
$ret .= "\n</select>";
return $ret;
}
?>
<style type="text/css">
input[type=text] {
width: 98%;
}
select {
width: 98%;
}
</style>