forked from NB-Core/lotgd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewpetition.php
367 lines (343 loc) · 15 KB
/
viewpetition.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<?php
// translator ready
// addnews ready
// mail ready
require_once("common.php");
require_once("lib/commentary.php");
require_once("lib/http.php");
tlschema("petition");
check_su_access(SU_EDIT_PETITIONS);
addcommentary();
require_once("lib/superusernav.php");
superusernav();
//WHEN 0 THEN 2 WHEN 1 THEN 3 WHEN 2 THEN 7 WHEN 3 THEN 5 WHEN 4 THEN 1 WHEN 5 THEN 0 WHEN 6 THEN 4 WHEN 7 THEN 6
$statuses=array(
5=>"`\$Top Level`0",
4=>"`^Escalated`0",
0=>"`bUnhandled`b",
1=>"In-Progress",
6=>"`%Bug`0",
7=>"`#Awaiting Points`0",
3=>"`!Informational`0",
2=>"`iClosed`i",
);
$statuses = modulehook("petition-status", $statuses);
$statuses=translate_inline($statuses);
$op = httpget("op");
$id = httpget("id");
if (trim(httppost('insertcommentary'))!="") {
/* Update the bug if someone adds comments as well */
$sql = "UPDATE " . db_prefix("petitions") . " SET closeuserid='{$session['user']['acctid']}',closedate='".date("Y-m-d H:i:s")."' WHERE petitionid='$id'";
db_query($sql);
}
// Eric decide he didn't want petitions to be manually deleted
//
//if ($op=="del"){
// $sql = "DELETE FROM " . db_prefix("petitions") . " WHERE petitionid='$id'";
// db_query($sql);
// $sql = "DELETE FROM " . db_prefix("commentary") . " WHERE section='pet-$id'";
// db_query($sql);
// invalidatedatacache("petition_counts");
// $op="";
//}
page_header("Petition Viewer");
if ($op==""){
$sql = "DELETE FROM " . db_prefix("petitions") . " WHERE status=2 AND closedate<'".date("Y-m-d H:i:s",strtotime("-7 days"))."'";
db_query($sql);
$setstat = httpget("setstat");
invalidatedatacache("petition_counts");
if ($setstat!=""){
$sql = "SELECT status FROM " . db_prefix("petitions") . " WHERE petitionid='$id'";
$result = db_query($sql);
$row = db_fetch_assoc($result);
if ($row['status']!=$setstat){
$sql = "UPDATE " . db_prefix("petitions") . " SET status='$setstat',closeuserid='{$session['user']['acctid']}',closedate='".date("Y-m-d H:i:s")."' WHERE petitionid='$id'";
db_query($sql);
}
}
$sort = "";
$pos = 0;
foreach ($statuses as $key=>$val) {
$sort.=" WHEN $key THEN $pos";
$pos++;
}
$petitionsperpage = 50;
$sql = "SELECT count(petitionid) AS c from ".db_prefix("petitions");
$result = db_query($sql);
$row = db_fetch_assoc($result);
$totalpages = ceil($row['c']/$petitionsperpage);
$page = httpget("page");
if ($page == "") {
if (isset($session['petitionPage'])){
$page = (int)$session['petitionPage'];
}else{
$page = 1;
}
}
if ($page < 1) $page = 1;
if ($page > $totalpages) $page = $totalpages;
$session['petitionPage'] = $page;
// No need to show the pages if there is only one.
if ($totalpages != 1) {
addnav("Page");
for ($x=1; $x <= $totalpages; $x++){
if ($page == $x){
addnav(array("`b`#Page %s`0`b", $x),"viewpetition.php?page=$x");
}else{
addnav(array("Page %s", $x),"viewpetition.php?page=$x");
}
}
}
if ($page > 1){
$limit = (($page-1) * $petitionsperpage) . "," . $petitionsperpage;
}else{
$limit = "$petitionsperpage";
}
$sql =
"SELECT
petitionid,
".db_prefix("accounts").".name,
".db_prefix("petitions").".date,
".db_prefix("petitions").".status,
".db_prefix("petitions").".body,
".db_prefix("petitions").".closedate,
accts.name AS closer,
CASE status $sort END AS sortorder
FROM
".db_prefix("petitions")."
LEFT JOIN
".db_prefix("accounts")."
ON ".db_prefix("accounts").".acctid=".db_prefix("petitions").".author
LEFT JOIN
".db_prefix("accounts")." AS accts
ON accts.acctid=".db_prefix("petitions").".closeuserid
ORDER BY
sortorder ASC,
date ASC
LIMIT $limit";
$result = db_query($sql);
addnav("Petitions");
addnav("Refresh","viewpetition.php");
$num = translate_inline("Num");
$ops = translate_inline("Ops");
$from = translate_inline("From");
$sent = translate_inline("Sent");
$com = translate_inline("Com");
$last = translate_inline("Last Updater");
$when = translate_inline("Updated");
$view = translate_inline("View");
$close = translate_inline("Close");
$mark = translate_inline("Mark");
rawoutput("<table border='0'><tr class='trhead'><td>$num</td><td>$ops</td><td>$from</td><td>$sent</td><td>$com</td><td>$last</td><td>$when</td></tr>");
$i=0;
$laststatus=-1;
$catcount=array();
while($row = db_fetch_assoc($result)){
if (isset($catcount[$row['status']])) $catcount[$row['status']]++;
else $catcount[$row['status']]=1;
$i=!$i;
$sql = "SELECT count(commentid) AS c FROM ". db_prefix("commentary") . " WHERE section='pet-{$row['petitionid']}'";
$res = db_query($sql);
$counter = db_fetch_assoc($res);
if (array_key_exists('status', $row) && $row['status']!=$laststatus){
rawoutput("<tr class='".($i?"trlight":"trdark")."'>");
rawoutput("<td colspan='7' style='background-color:#FAA000'>");
output_notl("%s", $statuses[$row['status']],true);
rawoutput("</td></tr>");
$i=1;
$laststatus=$row['status'];
}
rawoutput("<tr class='".($i?"trlight":"trdark")."'>");
rawoutput("<td>");
output_notl("%s", $row['petitionid']);
rawoutput("</td>");
rawoutput("<td nowrap>[ ");
rawoutput("<a href='viewpetition.php?op=view&id={$row['petitionid']}'>$view</a>",true);
rawoutput(" | <a href='viewpetition.php?setstat=2&id={$row['petitionid']}'>$close</a>");
output_notl(" | %s: ", $mark);
output_notl("<a href='viewpetition.php?setstat=0&id={$row['petitionid']}'>`b`&U`0`b</a>/",true);
output_notl("<a href='viewpetition.php?setstat=1&id={$row['petitionid']}'>`7P`0</a>/",true);
//output_notl("<a href='viewpetition.php?setstat=3&id={$row['petitionid']}'>`!I`0</a>/",true);
output_notl("<a href='viewpetition.php?setstat=4&id={$row['petitionid']}'>`^E`0</a>",true);
//output_notl("<a href='viewpetition.php?setstat=5&id={$row['petitionid']}'>`\$T`0</a>/",true);
//output_notl("<a href='viewpetition.php?setstat=6&id={$row['petitionid']}'>`%B`0</a>/",true);
//output_notl("<a href='viewpetition.php?setstat=7&id={$row['petitionid']}'>`#A`0</a>",true);
rawoutput(" ]</td>");
addnav("","viewpetition.php?op=view&id={$row['petitionid']}");
addnav("","viewpetition.php?setstat=2&id={$row['petitionid']}");
addnav("","viewpetition.php?setstat=0&id={$row['petitionid']}");
addnav("","viewpetition.php?setstat=1&id={$row['petitionid']}");
//addnav("","viewpetition.php?setstat=3&id={$row['petitionid']}");
addnav("","viewpetition.php?setstat=4&id={$row['petitionid']}");
//addnav("","viewpetition.php?setstat=5&id={$row['petitionid']}");
//addnav("","viewpetition.php?setstat=6&id={$row['petitionid']}");
//addnav("","viewpetition.php?setstat=7&id={$row['petitionid']}");
rawoutput("<td>");
if ($row['name']==""){
$v = substr($row['body'],0,strpos($row['body'],"[email"));
$v = preg_replace("'\\[PHPSESSID\\] = .*'", "", $v);
$v = preg_replace("'[^a-zA-Z0-91234567890\\[\\]= @.!,?-]'","", $v);
// Make sure we don't get something too large.. 50 chars max
$v = substr($v, 0, 50);
output_notl("`\$%s`0", $v);
}else{
output_notl("`&%s`0", $row['name']);
}
rawoutput("</td>");
rawoutput("<td>");
output_notl("`7%s`0", reltime(strtotime($row['date'])));
rawoutput("</td>");
rawoutput("<td>");
output_notl("`#%s`0", $counter['c']);
rawoutput("</td>");
rawoutput("<td>");
output_notl("`^%s`0", $row['closer']);
rawoutput("</td>");
rawoutput("<td>");
if ($row['closedate'] != 0) output_notl("`7%s`0", reltime(strtotime($row['closedate'])));
rawoutput("</td>");
rawoutput("</tr>");
}
rawoutput("</table>");
//navlist with counter
if ($catcount!=array()) addnav("Overview");
foreach ($catcount as $categorynumber=>$amount) {
addnav(array("`t%s`t(%s)",$statuses[$categorynumber],$amount),"viewpetition.php?page=".((int)httpget('page')));
}
//end
output("`i(Closed petitions will automatically delete themselves when they have been closed for 7 days)`i");
output("`n`bKey:`b`n");
rawoutput("<ul><li>");
output("`\$T = Top Level`0 petitions are for petitions that only server operators can take care of.");
rawoutput("</li><li>");
output("`^E = Escalated`0 petitions deal with an issue you can't handle for yourself.");
output("Mark it escalated so someone with more permissions than you can deal with it.");
rawoutput("</li><li>");
output("`b`&U = Unhandled`0`b: No one is currently working on this problem, and it has not been dealt with yet.");
rawoutput("</li><li>");
output("P = In-Progress petitions are probably being worked on by someone else, so please leave them be unless they have been around for some time.");
rawoutput("</li><li>");
output("`%B = Bug/Suggestion`0 petitions are petitions that detail mistakes, bugs, misspellings, or suggestions for the game.");
rawoutput("</li><li>");
output("`#A = Awaiting Points`0 stuff wot is dun and needz teh points added (this is mostly for lotgd.net).");
rawoutput("</li><li>");
output("`!I = Informational`0 petitions are just around for others to view, either nothing needed to be done with them, or their issue has been dealt with, but you feel other admins could benefit from reading it.");
rawoutput("</li><li>");
output("`iClosed`i petitions are for you have dealt with an issue, these will auto delete when they have been closed for 7 days.");
modulehook("petitions-descriptions", array());
rawoutput("</li></ul>");
}elseif($op=="view"){
addnav("Petitions");
addnav("Details");
$viewpageinfo = (int)httpget("viewpageinfo");
if ($viewpageinfo==1){
addnav("Hide Details","viewpetition.php?op=view&id=$id}");
}else{
addnav("D?Show Details","viewpetition.php?op=view&id=$id&viewpageinfo=1");
}
addnav("Navigation");
addnav("V?Petition Viewer","viewpetition.php");
addnav("User Ops");
addnav("Petition Ops");
foreach ($statuses as $key=>$val){
$plain = full_sanitize($val);
addnav(array("%s?Mark %s", substr($plain,0,1), $val),
"viewpetition.php?setstat=$key&id=$id");
}
$sql = "SELECT " . db_prefix("accounts") . ".name," . db_prefix("accounts") . ".login," . db_prefix("accounts") . ".acctid," . "author,date,closedate,status,petitionid,ip,body,pageinfo," . "accts.name AS closer FROM " . db_prefix("petitions") . " LEFT JOIN " . db_prefix("accounts ") . "ON " . db_prefix("accounts") . ".acctid=author LEFT JOIN " . db_prefix("accounts") . " AS accts ON accts.acctid=". "closeuserid WHERE petitionid='$id' ORDER BY date ASC";
$result = db_query($sql);
$row = db_fetch_assoc($result);
addnav("User Ops");
if (isset($row['login'])) {
addnav("View User Biography","bio.php?char=" . $row['acctid']
. "&ret=%2Fviewpetition.php%3Fop%3Dview%26id=" . $id);
}
if ($row['acctid']>0 && $session['user']['superuser'] & SU_EDIT_USERS){
addnav("User Ops");
addnav("R?Edit User Record","user.php?op=edit&userid={$row['acctid']}&returnpetition=$id");
}
if ($row['acctid']>0 && $session['user']['superuser'] & SU_EDIT_DONATIONS){
addnav("User Ops");
addnav("Edit User Donations","donators.php?op=add1&name=".rawurlencode($row['login'])."&ret=".urlencode($_SERVER['REQUEST_URI']));
}
$write = translate_inline("Write Mail");
// We assume that petitions are handled in default language
$yourpeti = translate_mail("Your Petition",0);
$peti = translate_mail("Petition",0);
$row['body'] = str_replace("[charname]",translate_mail("[charname]",0),$row['body']);
$row['body'] = str_replace("[email]",translate_mail("[email]",0),$row['body']);
$row['body'] = str_replace("[description]",translate_mail("[description]",0),$row['body']);
// For email replies, make sure we don't overflow the URI buffer.
$reppet = substr(stripslashes($row['body']), 0, 2000);
//display given category, if any
$array_body=explode("\n",$row['body']);
$category_check="[problem_type] = ";
foreach ($array_body as $line) {
$catpos=strpos($line,$category_check);
if ($catpos!==false) {
//cat found
rawoutput("<h2>");
output("`2Category: %s`n",substr($line,strlen($category_check)-1));
rawoutput("</h2>");
}
}
output("`@From: ");
if ($row['login']>"") {
rawoutput("<a href=\"mail.php?op=write&to=".rawurlencode($row['login'])."&body=".rawurlencode("\n\n----- $yourpeti -----\n$reppet")."&subject=RE:+$peti\" target=\"_blank\" onClick=\"".popup("mail.php?op=write&to=".rawurlencode($row['login'])."&body=".rawurlencode("\n\n----- $yourpeti -----\n$reppet")."&subject=RE:+$peti").";return false;\"><img src='images/newscroll.GIF' width='16' height='16' alt='$write' border='0'></a>");
}
output_notl("`^`b%s`b`n", $row['name']);
output("`@Date: `^`b%s`b (%s)`n", $row['date'], reltime(strtotime($row['date'])));
output("`@Status: %s`n", $statuses[$row['status']]);
if ($row['closer']!='') output("`@Last Update: `^%s`@ on `^%s (%s)`n", $row['closer'], $row['closedate'], reltime(strtotime($row['closedate'])));
output("`@Body:`^`n");
output("`\$[ipaddress] `^= `#%s`^`n", $row['ip']);
$body = htmlentities(stripslashes($row['body']), ENT_COMPAT, getsetting("charset", "ISO-8859-1"));
$body = preg_replace("'([[:alnum:]_.-]+[@][[:alnum:]_.-]{2,}([.][[:alnum:]_.-]{2,})+)'i","<a href='mailto:\\1?subject=RE: $peti&body=".str_replace("+"," ",URLEncode("\n\n----- $yourpeti -----\n".stripslashes($row['body'])))."'>\\1</a>",$body);
$body = preg_replace("'([\\[][[:alnum:]_.-]+[\\]])'i","<span class='colLtRed'>\\1</span>",$body);
rawoutput("<span style='font-family: fixed-width'>".nl2br($body)."</span>");
//position tracking
if ($row['body']!='') {
$pos=strpos($row['body'],"[abuseplayer]")+16;
$endpos=strpos($row['body'],chr(10),$pos);
if ($pos!==false) {
$search=substr($row['body'],$pos,$endpos-$pos);
$search=(int) $search;
if ($search!=0) modulehook("petition-abuse",array("acctid"=>$search,"abused"=>$row['author']));
}
}
commentdisplay("`n`@Commentary:`0`n", "pet-$id","Add information",200);
if ($viewpageinfo){
output("`n`n`@Page Info:`&`n");
$row['pageinfo']=stripslashes($row['pageinfo']);
$body = HTMLEntities($row['pageinfo'], ENT_COMPAT, getsetting("charset", "ISO-8859-1"));
$body = preg_replace("'([[:alnum:]_.-]+[@][[:alnum:]_.-]{2,}([.][[:alnum:]_.-]{2,})+)'i","<a href='mailto:\\1?subject=RE: $peti&body=".str_replace("+"," ",URLEncode("\n\n----- $yourpeti -----\n".$row['body']))."'>\\1</a>",$body);
$body = preg_replace("'([\\[][[:alnum:]_.-]+[\\]])'i","<span class='colLtRed'>\\1</span>",$body);
rawoutput("<span style='font-family: fixed-width'>".nl2br($body)."</span>");
}
}
if ($id && $op != ""){
$prevsql="SELECT p1.petitionid, p1.status FROM ".db_prefix("petitions")." AS p1, ".db_prefix("petitions")." AS p2
WHERE p1.petitionid<'$id' AND p2.petitionid='$id' AND p1.status=p2.status ORDER BY p1.petitionid DESC LIMIT 1";
$prevresult=db_query($prevsql);
$prevrow=db_fetch_assoc($prevresult);
if ($prevrow){
$previd=$prevrow['petitionid'];
$s=$prevrow['status'];
$status=$statuses[$s];
addnav("Petitions");
addnav(array("Previous %s",$status),"viewpetition.php?op=view&id=$previd");
}
$nextsql="SELECT p1.petitionid, p1.status FROM ".db_prefix("petitions")." AS p1, ".db_prefix("petitions")." AS p2
WHERE p1.petitionid>'$id' AND p2.petitionid='$id' AND p1.status=p2.status ORDER BY p1.petitionid ASC LIMIT 1";
$nextresult=db_query($nextsql);
$nextrow=db_fetch_assoc($nextresult);
if ($nextrow){
$nextid=$nextrow['petitionid'];
$s=$nextrow['status'];
$status=$statuses[$s];
addnav("Petitions");
addnav(array("Next %s",$status),"viewpetition.php?op=view&id=$nextid");
}
}
page_footer();
?>