My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
--- admin_bans_save.php 2009-11-09 23:58:50.000000000 +0100
+++ admin_bans.php 2009-11-10 00:18:27.000000000 +0100
@@ -296,6 +296,115 @@
}


+// find a ban
+else if (isset($_POST['find_ban']))
+{
+ $form = $_POST['form'];
+ $form['username'] = $_POST['username'];
+
+ // trim() all elements in $form
+ $form = array_map('trim', $form);
+ $conditions = array();
+
+ $expire_after = trim($_POST['expire_after']);
+ $expire_before = trim($_POST['expire_before']);
+ $order_by = $_POST['order_by'];
+ $direction = $_POST['direction'];
+
+ // Try to convert date/time to timestamps
+ if ($expire_after != '')
+ $expire_after = strtotime($expire_after);
+ if ($expire_before != '')
+ $expire_before = strtotime($expire_before);
+
+ if ($expire_after == -1 || $expire_before == -1)
+ message('You entered an invalid date/time.');
+
+ if ($expire_after != '')
+ $conditions[] = 'expire>'.$expire_after;
+ if ($expire_before != '')
+ $conditions[] = 'expire<'.$expire_before;
+
+ $like_command = ($db_type == 'pgsql') ? 'ILIKE' : 'LIKE';
+ while (list($key, $input) = @each($form))
+ {
+ if ($input != '' && in_array($key, array('username', 'email', 'ip', 'message')))
+ $conditions[] = 'b.'.$db->escape($key).' '.$like_command.' \''.$db->escape(str_replace('*', '%', $input)).'\'';
+ }
+
+ if (empty($conditions))
+ message('You didn\'t enter any search terms.');
+
+ $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Bans';
+ require PUN_ROOT.'header.php';
+?>
+<div class="linkst">
+ <div class="inbox">
+ <div><a href="javascript:history.go(-1)">Go back</a></div>
+ </div>
+</div>
+
+<div id="bans1" class="blocktable">
+ <h2><span>Users</span></h2>
+ <div class="box">
+ <div class="inbox">
+ <table cellspacing="0">
+ <thead>
+ <tr>
+ <th class="tcl" scope="col">Username</th>
+ <th class="tc2" scope="col">E-mail</th>
+ <th class="tc3" scope="col">IP/IP-ranges</th>
+ <th class="tc4" scope="col">Reason</th>
+ <th class="tc5" scope="col">Banned by</th>
+ <th class="tc6" scope="col">Expire</th>
+ <th class="tcr" scope="col">Action</th>
+ </tr>
+ </thead>
+ <tbody>
+<?php
+
+ $result = $db->query('SELECT b.id, b.username, b.email, b.ip, b.message, b.expire, b.ban_creator, u.username AS ban_creator_username FROM '.$db->prefix.'bans AS b LEFT JOIN '.$db->prefix.'users AS u ON b.ban_creator=u.id WHERE '.implode(' AND ', $conditions).' ORDER BY '.$db->escape($order_by).' '.$db->escape($direction)) or error('Unable to fetch ban info', __FILE__, __LINE__, $db->error());
+ if ($db->num_rows($result))
+ {
+ while ($ban_data = $db->fetch_assoc($result))
+ {
+ $actions = '<a href="admin_bans.php?edit_ban=' . $ban_data['id'] . '">Edit</a> - <a href="admin_bans.php?del_ban=' . $ban_data['id'] . '">Remove</a>';
+ $expire = format_time($ban_data['expire'], true);
+
+?>
+ <tr>
+ <td class="tcl"><?php echo pun_htmlspecialchars($ban_data['username']) ?></td>
+ <td class="tc2"><?php echo $ban_data['email']; ?></td>
+ <td class="tc3"><?php echo $ban_data['ip']; ?></td>
+ <td class="tc4"><?php echo pun_htmlspecialchars($ban_data['message']) ?></td>
+ <td class="tc5"><a href="profile.php?id=<?php echo $ban_data['ban_creator'] ?>"><?php echo pun_htmlspecialchars($ban_data['ban_creator_username']) ?></a></td>
+ <td class="tc6"><?php echo $expire ?></td>
+ <td class="tcr"><?php echo $actions ?></td>
+ </tr>
+<?php
+
+ }
+ }
+ else
+ echo "\t\t\t\t".'<tr><td class="tcl" colspan="6">No match.</td></tr>'."\n";
+
+?>
+ </tbody>
+ </table>
+ </div>
+ </div>
+</div>
+
+<div class="linksb">
+ <div class="inbox">
+ <div><a href="javascript:history.go(-1)">Go back</a></div>
+ </div>
+</div>
+<?php
+ require PUN_ROOT.'footer.php';
+ die();
+}
+
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Bans';
$focus_element = array('bans', 'new_ban_user');
require PUN_ROOT.'header.php';
@@ -326,58 +435,62 @@
</form>
</div>

- <h2 class="block2"><span>Existing bans</span></h2>
+ <h2 class="block2"><span>Ban search</span></h2>
<div class="box">
- <div class="fakeform">
-<?php
-
-$result = $db->query('SELECT b.id, b.username, b.ip, b.email, b.message, b.expire, b.ban_creator, u.username AS ban_creator_username FROM '.$db->prefix.'bans AS b LEFT JOIN '.$db->prefix.'users AS u ON b.ban_creator=u.id ORDER BY b.id') or error('Unable to fetch ban list', __FILE__, __LINE__, $db->error());
-if ($db->num_rows($result))
-{
- while ($cur_ban = $db->fetch_assoc($result))
- {
- $expire = format_time($cur_ban['expire'], true);
-
-?>
+ <form id="find_ban" method="post" action="admin_bans.php?action=find_ban">
+ <p class="submittop"><input type="submit" name="find_ban" value="Submit search" tabindex="1" /></p>
<div class="inform">
<fieldset>
- <legend>Ban expires: <?php echo $expire ?></legend>
+ <legend>Enter search criteria</legend>
<div class="infldset">
- <table cellspacing="0">
-<?php if ($cur_ban['username'] != ''): ?> <tr>
- <th>Username</th>
- <td><?php echo pun_htmlspecialchars($cur_ban['username']) ?></td>
- </tr>
-<?php endif; ?><?php if ($cur_ban['email'] != ''): ?> <tr>
- <th>E-mail</th>
- <td><?php echo $cur_ban['email'] ?></td>
- </tr>
-<?php endif; ?><?php if ($cur_ban['ip'] != ''): ?> <tr>
- <th>IP/IP-ranges</th>
- <td><?php echo $cur_ban['ip'] ?></td>
- </tr>
-<?php endif; ?><?php if ($cur_ban['message'] != ''): ?> <tr>
- <th>Reason</th>
- <td><?php echo pun_htmlspecialchars($cur_ban['message']) ?></td>
- </tr>
-<?php endif; ?><?php if (!empty($cur_ban['ban_creator_username'])): ?> <tr>
- <th>Banned by</th>
- <td><a href="profile.php?id=<?php echo $cur_ban['ban_creator'] ?>"><?php echo pun_htmlspecialchars($cur_ban['ban_creator_username']) ?></a></td>
+ <p>Search for bans in the database. You can enter one or more terms to search for. Wildcards in the form of asterisks (*) are accepted.</p>
+ <table class="aligntop" cellspacing="0">
+ <tr>
+ <th scope="row">Username</th>
+ <td><input type="text" name="username" size="25" maxlength="25" tabindex="2" /></td>
+ </tr>
+ <tr>
+ <th scope="row">E-mail</th>
+ <td><input type="text" name="form[email]" size="25" maxlength="25" tabindex="3" /></td>
+ </tr>
+ <tr>
+ <th scope="row">IP/IP-ranges</th>
+ <td><input type="text" name="form[ip]" size="25" maxlength="25" tabindex="4" /></td>
+ </tr>
+ <tr>
+ <th scope="row">Reason</th>
+ <td><input type="text" name="form[message]" size="25" maxlength="25" tabindex="5" /></td>
+ </tr>
+ <tr>
+ <th scope="row">Expire after</th>
+ <td><input type="text" name="expire_after" size="24" maxlength="19" tabindex="6" />
+ <span>(yyyy-mm-dd hh:mm:ss)</span></td>
</tr>
-<?php endif; ?> </table>
- <p class="linkactions"><a href="admin_bans.php?edit_ban=<?php echo $cur_ban['id'] ?>">Edit</a> - <a href="admin_bans.php?del_ban=<?php echo $cur_ban['id'] ?>">Remove</a></p>
+ <tr>
+ <th scope="row">Expire before</th>
+ <td><input type="text" name="expire_before" size="24" maxlength="19" tabindex="7" />
+ <span>(yyyy-mm-dd hh:mm:ss)</span></td>
+ </tr>
+ <tr>
+ <th scope="row">Order by</th>
+ <td>
+ <select name="order_by" tabindex="8">
+ <option value="username" selected="selected">username</option>
+ <option value="email">e-mail</option>
+ <option value="ip">ip</option>
+ <option value="expire">expire</option>
+ </select>&nbsp;&nbsp;&nbsp;<select name="direction" tabindex="9">
+ <option value="ASC" selected="selected">ascending</option>
+ <option value="DESC">descending</option>
+ </select>
+ </td>
+ </tr>
+ </table>
</div>
</fieldset>
</div>
-<?php
-
- }
-}
-else
- echo "\t\t\t\t".'<p>No bans in list.</p>'."\n";
-
-?>
- </div>
+ <p class="submitend"><input type="submit" name="find_ban" value="Submit search" tabindex="10" /></p>
+ </form>
</div>
</div>
<div class="clearer"></div>

Change log

r49 by guillaume.duhamel on Nov 9, 2009   Diff
Better bans for 1.4
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 8356 bytes, 225 lines
Powered by Google Project Hosting