forked from cdwolfling/NexusPHP
-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.php
427 lines (369 loc) · 17.1 KB
/
log.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
<?php
require "include/bittorrent.php";
dbconn();
require_once(get_langfile_path());
loggedinorreturn();
if (get_user_class() < $log_class)
{
stderr($lang_log['std_sorry'],$lang_log['std_permission_denied_only'].get_user_class_name($log_class,false,true,true).$lang_log['std_or_above_can_view'],false);
}
function permissiondeny(){
global $lang_log;
stderr($lang_log['std_sorry'],$lang_log['std_permission_denied'],false);
}
function logmenu($selected = "dailylog"){
global $lang_log;
global $showfunbox_main;
begin_main_frame();
print ("<div id=\"lognav\"><ul id=\"logmenu\" class=\"menu\">");
print ("<li" . ($selected == "dailylog" ? " class=selected" : "") . "><a href=\"?action=dailylog\">".$lang_log['text_daily_log']."</a></li>");
print ("<li" . ($selected == "chronicle" ? " class=selected" : "") . "><a href=\"?action=chronicle\">".$lang_log['text_chronicle']."</a></li>");
if ($showfunbox_main == 'yes')
print ("<li" . ($selected == "funbox" ? " class=selected" : "") . "><a href=\"?action=funbox\">".$lang_log['text_funbox']."</a></li>");
print ("<li" . ($selected == "news" ? " class=selected" : "") . "><a href=\"?action=news\">".$lang_log['text_news']."</a></li>");
print ("<li" . ($selected == "poll" ? " class=selected" : "") . "><a href=\"?action=poll\">".$lang_log['text_poll']."</a></li>");
print ("</ul></div>");
end_main_frame();
}
function searchtable($title, $action, $opts = array()){
global $lang_log;
print("<table border=1 cellspacing=0 width=940 cellpadding=5>\n");
print("<tr><td class=colhead align=left>".$title."</td></tr>\n");
print("<tr><td class=toolbox align=left><form method=\"get\" action='" . $_SERVER['PHP_SELF'] . "'>\n");
print("<input type=\"text\" name=\"query\" style=\"width:500px\" value=\"".$_GET['query']."\">\n");
if ($opts) {
print($lang_log['text_in']."<select name=search>");
foreach($opts as $value => $text)
print("<option value='".$value."'". ($value == $_GET['search'] ? " selected" : "").">".$text."</option>");
print("</select>");
}
print("<input type=\"hidden\" name=\"action\" value='".$action."'> ");
print("<input type=submit value=" . $lang_log['submit_search'] . "></form>\n");
print("</td></tr></table><br />\n");
}
function additem($title, $action){
global $lang_log;
print("<table border=1 cellspacing=0 width=940 cellpadding=5>\n");
print("<tr><td class=colhead align=left>".$title."</td></tr>\n");
print("<tr><td class=toolbox align=left><form method=\"post\" action='" . $_SERVER['PHP_SELF'] . "'>\n");
print("<textarea name=\"txt\" style=\"width:500px\" rows=\"3\" >".$row["txt"]."</textarea>\n");
print("<input type=\"hidden\" name=\"action\" value=".$action.">");
print("<input type=\"hidden\" name=\"do\" value=\"add\">");
print("<input type=submit value=" . $lang_log['submit_add'] . "></form>\n");
print("</td></tr></table><br />\n");
}
function edititem($title, $action, $id){
global $lang_log;
$result = sql_query ("SELECT * FROM ".$action." where id = ".sqlesc($id)) or sqlerr(__FILE__, __LINE__);
if ($row = mysql_fetch_array($result)) {
print("<table border=1 cellspacing=0 width=940 cellpadding=5>\n");
print("<tr><td class=colhead align=left>".$title."</td></tr>\n");
print("<tr><td class=toolbox align=left><form method=\"post\" action='" . $_SERVER['PHP_SELF'] . "'>\n");
print("<textarea name=\"txt\" style=\"width:500px\" rows=\"3\" >".$row["txt"]."</textarea>\n");
print("<input type=\"hidden\" name=\"action\" value=".$action.">");
print("<input type=\"hidden\" name=\"do\" value=\"update\">");
print("<input type=\"hidden\" name=\"id\" value=".$id.">");
print("<input type=submit value=" . $lang_log['submit_okay'] . " style='height: 20px' /></form>\n");
print("</td></tr></table><br />\n");
}
}
$action = isset($_POST['action']) ? htmlspecialchars($_POST['action']) : (isset($_GET['action']) ? htmlspecialchars($_GET['action']) : '');
$allowed_actions = array("dailylog","chronicle","funbox","news","poll");
if (!$action)
$action='dailylog';
if (!in_array($action, $allowed_actions))
stderr($lang_log['std_error'], $lang_log['std_invalid_action']);
else {
switch ($action){
case "dailylog":
stdhead($lang_log['head_site_log']);
$query = mysql_real_escape_string(trim($_GET["query"]));
$search = $_GET["search"];
$addparam = "";
$wherea = "";
if (get_user_class() >= $confilog_class){
switch ($search)
{
case "mod": $wherea=" WHERE security_level = 'mod'"; break;
case "normal": $wherea=" WHERE security_level = 'normal'"; break;
case "all": break;
}
$addparam = ($wherea ? "search=".rawurlencode($search)."&" : "");
}
else{
$wherea=" WHERE security_level = 'normal'";
}
if($query){
$wherea .= ($wherea ? " AND " : " WHERE ")." txt LIKE '%$query%' ";
$addparam .= "query=".rawurlencode($query)."&";
}
logmenu('dailylog');
$opt = array (all => $lang_log['text_all'], normal => $lang_log['text_normal'], mod => $lang_log['text_mod']);
searchtable($lang_log['text_search_log'], 'dailylog',$opt);
$res = sql_query("SELECT COUNT(*) FROM sitelog".$wherea);
$row = mysql_fetch_array($res);
$count = $row[0];
$perpage = 50;
list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, "log.php?action=dailylog&".$addparam);
$res = sql_query("SELECT added, txt FROM sitelog $wherea ORDER BY added DESC $limit") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 0)
print($lang_log['text_log_empty']);
else
{
//echo $pagertop;
print("<table width=940 border=1 cellspacing=0 cellpadding=5>\n");
print("<tr><td class=colhead align=center><img class=\"time\" src=\"pic/trans.gif\" alt=\"time\" title=\"".$lang_log['title_time_added']."\" /></td><td class=colhead align=left>".$lang_log['col_event']."</td></tr>\n");
while ($arr = mysql_fetch_assoc($res))
{
$color = "";
if (strpos($arr['txt'],'was uploaded by')) $color = "green";
if (strpos($arr['txt'],'was deleted by')) $color = "red";
if (strpos($arr['txt'],'was added to the Request section')) $color = "purple";
if (strpos($arr['txt'],'was edited by')) $color = "blue";
if (strpos($arr['txt'],'settings updated by')) $color = "darkred";
print("<tr><td class=\"rowfollow nowrap\" align=center>".gettime($arr['added'],true,false)."</td><td class=rowfollow align=left><font color='".$color."'>".htmlspecialchars($arr['txt'])."</font></td></tr>\n");
}
print("</table>");
echo $pagerbottom;
}
print($lang_log['time_zone_note']);
stdfoot();
die;
break;
case "chronicle":
stdhead($lang_log['head_chronicle']);
$query = mysql_real_escape_string(trim($_GET["query"]));
if($query){
$wherea=" WHERE txt LIKE '%$query%' ";
$addparam = "query=".rawurlencode($query)."&";
}
else{
$wherea="";
$addparam = "";
}
logmenu("chronicle");
searchtable($lang_log['text_search_chronicle'], 'chronicle');
if (get_user_class() >= $chrmanage_class)
additem($lang_log['text_add_chronicle'], 'chronicle');
if ($_GET['do'] == "del" || $_GET['do'] == 'edit' || $_POST['do'] == "add" || $_POST['do'] == "update") {
$txt = $_POST['txt'];
if (get_user_class() < $chrmanage_class)
permissiondeny();
elseif ($_POST['do'] == "add")
sql_query ("INSERT INTO chronicle (userid,added, txt) VALUES ('".$CURUSER["id"]."', now(), ".sqlesc($txt).")") or sqlerr(__FILE__, __LINE__);
elseif ($_POST['do'] == "update"){
$id = 0 + $_POST['id'];
if (!$id) { header("Location: log.php?action=chronicle"); die();}
else sql_query ("UPDATE chronicle SET txt=".sqlesc($txt)." WHERE id=".$id) or sqlerr(__FILE__, __LINE__);}
else {$id = 0 + $_GET['id'];
if (!$id) { header("Location: log.php?action=chronicle"); die();}
elseif ($_GET['do'] == "del")
sql_query ("DELETE FROM chronicle where id = '".$id."'") or sqlerr(__FILE__, __LINE__);
elseif ($_GET['do'] == "edit")
edititem($lang_log['text_edit_chronicle'],'chronicle', $id);
}
}
$res = sql_query("SELECT COUNT(*) FROM chronicle".$wherea);
$row = mysql_fetch_array($res);
$count = $row[0];
$perpage = 50;
list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, "log.php?action=chronicle&".$addparam);
$res = sql_query("SELECT id, added, txt FROM chronicle $wherea ORDER BY added DESC $limit") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 0)
print($lang_log['text_chronicle_empty']);
else
{
//echo $pagertop;
print("<table width=940 border=1 cellspacing=0 cellpadding=5>\n");
print("<tr><td class=colhead align=center>".$lang_log['col_date']."</td><td class=colhead align=left>".$lang_log['col_event']."</td>".(get_user_class() >= $chrmanage_class ? "<td class=colhead align=center>".$lang_log['col_modify']."</td>" : "")."</tr>\n");
while ($arr = mysql_fetch_assoc($res))
{
$date = gettime($arr['added'],true,false);
print("<tr><td class=rowfollow align=center><nobr>$date</nobr></td><td class=rowfollow align=left>".format_comment($arr["txt"],true,false,true)."</td>".(get_user_class() >= $chrmanage_class ? "<td align=center nowrap><b><a href=\"".$PHP_SELF."?action=chronicle&do=edit&id=".$arr["id"]."\">".$lang_log['text_edit']."</a> | <a href=\"".$PHP_SELF."?action=chronicle&do=del&id=".$arr["id"]."\"><font color=red>".$lang_log['text_delete']."</font></a></b></td>" : "")."</tr>\n");
}
print("</table>");
echo $pagerbottom;
}
print($lang_log['time_zone_note']);
stdfoot();
die;
break;
case "funbox":
stdhead($lang_log['head_funbox']);
$query = mysql_real_escape_string(trim($_GET["query"]));
$search = $_GET["search"];
if($query){
switch ($search){
case "title": $wherea=" WHERE title LIKE '%$query%' AND status != 'banned'"; break;
case "body": $wherea=" WHERE body LIKE '%$query%' AND status != 'banned'"; break;
case "both": $wherea=" WHERE (body LIKE '%$query%' or title LIKE '%$query%') AND status != 'banned'" ; break;
}
$addparam = "search=".rawurlencode($search)."&query=".rawurlencode($query)."&";
}
else{
$wherea=" WHERE status != 'banned'";
$addparam = "";
}
logmenu("funbox");
$opt = array (title => $lang_log['text_title'], body => $lang_log['text_body'], both => $lang_log['text_both']);
searchtable($lang_log['text_search_funbox'], 'funbox', $opt);
$res = sql_query("SELECT COUNT(*) FROM fun ".$wherea);
$row = mysql_fetch_array($res);
$count = $row[0];
$perpage = 10;
list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, "log.php?action=funbox&".$addparam);
$res = sql_query("SELECT added, body, title, status FROM fun $wherea ORDER BY added DESC $limit") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 0)
print($lang_log['text_funbox_empty']);
else
{
//echo $pagertop;
while ($arr = mysql_fetch_assoc($res)){
$date = gettime($arr['added'],true,false);
print("<table width=940 border=1 cellspacing=0 cellpadding=5>\n");
print("<tr><td class=rowhead width='10%'>".$lang_log['col_title']."</td><td class=rowfollow align=left>".$arr["title"]." - <b>".$arr["status"]."</b></td></tr><tr><td class=rowhead width='10%'>".$lang_log['col_date']."</td><td class=rowfollow align=left>".$date."</td></tr><tr><td class=rowhead width='10%'>".$lang_log['col_body']."</td><td class=rowfollow align=left>".format_comment($arr["body"],false,false,true)."</td></tr>\n");
print("</table><br />");
}
echo $pagerbottom;
}
print($lang_log['time_zone_note']);
stdfoot();
die;
break;
case "news":
stdhead($lang_log['head_news']);
$query = mysql_real_escape_string(trim($_GET["query"]));
$search = $_GET["search"];
if($query){
switch ($search){
case "title": $wherea=" WHERE title LIKE '%$query%' "; break;
case "body": $wherea=" WHERE body LIKE '%$query%' "; break;
case "both": $wherea=" WHERE body LIKE '%$query%' or title LIKE '%$query%'" ; break;
}
$addparam = "search=".rawurlencode($search)."&query=".rawurlencode($query)."&";
}
else{
$wherea= "";
$addparam = "";
}
logmenu("news");
$opt = array (title => $lang_log['text_title'], body => $lang_log['text_body'], both => $lang_log['text_both']);
searchtable($lang_log['text_search_news'], 'news', $opt);
$res = sql_query("SELECT COUNT(*) FROM news".$wherea);
$row = mysql_fetch_array($res);
$count = $row[0];
$perpage = 20;
list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, "log.php?action=news&".$addparam);
$res = sql_query("SELECT id, added, body, title FROM news $wherea ORDER BY added DESC $limit") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 0)
print($lang_log['text_news_empty']);
else
{
//echo $pagertop;
while ($arr = mysql_fetch_assoc($res)){
$date = gettime($arr['added'],true,false);
print("<table width=940 border=1 cellspacing=0 cellpadding=5>\n");
print("<tr><td class=rowhead width='10%'>".$lang_log['col_title']."</td><td class=rowfollow align=left>".$arr["title"]."</td></tr><tr><td class=rowhead width='10%'>".$lang_log['col_date']."</td><td class=rowfollow align=left>".$date."</td></tr><tr><td class=rowhead width='10%'>".$lang_log['col_body']."</td><td class=rowfollow align=left>".format_comment($arr["body"],false,false,true)."</td></tr>\n");
print("</table><br />");
}
echo $pagerbottom;
}
print($lang_log['time_zone_note']);
stdfoot();
die;
break;
case "poll":
$do = $_GET["do"];
$pollid = $_GET["pollid"];
$returnto = htmlspecialchars($_GET["returnto"]);
if ($do == "delete")
{
if (get_user_class() < $chrmanage_class)
stderr($lang_log['std_error'], $lang_log['std_permission_denied']);
int_check($pollid,true);
$sure = $_GET["sure"];
if (!$sure)
stderr($lang_log['std_delete_poll'],$lang_log['std_delete_poll_confirmation'] .
"<a href=?action=poll&do=delete&pollid=$pollid&returnto=$returnto&sure=1>".$lang_log['std_here_if_sure'],false);
sql_query("DELETE FROM pollanswers WHERE pollid = $pollid") or sqlerr();
sql_query("DELETE FROM polls WHERE id = $pollid") or sqlerr();
$Cache->delete_value('current_poll_content');
$Cache->delete_value('current_poll_result', true);
if ($returnto == "main")
header("Location: " . get_protocol_prefix() . "$BASEURL");
else
header("Location: " . get_protocol_prefix() . "$BASEURL/log.php?action=poll&deleted=1");
die;
}
$rows = sql_query("SELECT COUNT(*) FROM polls") or sqlerr();
$row = mysql_fetch_row($rows);
$pollcount = $row[0];
if ($pollcount == 0)
stderr($lang_log['std_sorry'], $lang_log['std_no_polls']);
$polls = sql_query("SELECT * FROM polls ORDER BY id DESC LIMIT 1," . ($pollcount - 1 )) or sqlerr();
stdhead($lang_log['head_previous_polls']);
logmenu("poll");
print("<table border=1 cellspacing=0 width=940 cellpadding=5>\n");
//print("<tr><td class=colhead align=center>".$lang_log['text_previous_polls']."</td></tr>\n");
function srt($a,$b)
{
if ($a[0] > $b[0]) return -1;
if ($a[0] < $b[0]) return 1;
return 0;
}
while ($poll = mysql_fetch_assoc($polls))
{
$o = array($poll["option0"], $poll["option1"], $poll["option2"], $poll["option3"], $poll["option4"],
$poll["option5"], $poll["option6"], $poll["option7"], $poll["option8"], $poll["option9"],
$poll["option10"], $poll["option11"], $poll["option12"], $poll["option13"], $poll["option14"],
$poll["option15"], $poll["option16"], $poll["option17"], $poll["option18"], $poll["option19"]);
print("<tr><td align=center>\n");
print("<p class=sub>");
$added = gettime($poll['added'], true, false);
print($added);
if (get_user_class() >= $pollmanage_class)
{
print(" - [<a href=makepoll.php?action=edit&pollid=$poll[id]><b>".$lang_log['text_edit']."</b></a>]\n");
print(" - [<a href=?action=poll&do=delete&pollid=$poll[id]><b>".$lang_log['text_delete']."</b></a>]\n");
}
print("<a name=$poll[id]>");
print("</p>\n");
print("<table class=main border=1 cellspacing=0 cellpadding=5><tr><td class=text>\n");
print("<p align=center><b>" . $poll["question"] . "</b></p>");
$pollanswers = sql_query("SELECT selection FROM pollanswers WHERE pollid=" . $poll["id"] . " AND selection < 20") or sqlerr();
$tvotes = mysql_num_rows($pollanswers);
$vs = array(); // count for each option ([0]..[19])
$os = array(); // votes and options: array(array(123, "Option 1"), array(45, "Option 2"))
// Count votes
while ($pollanswer = mysql_fetch_row($pollanswers))
$vs[$pollanswer[0]] += 1;
reset($o);
for ($i = 0; $i < count($o); ++$i)
if ($o[$i])
$os[$i] = array($vs[$i], $o[$i]);
print("<table width=100% class=main border=0 cellspacing=0 cellpadding=0>\n");
$i = 0;
while ($a = $os[$i])
{
if ($tvotes > 0)
$p = round($a[0] / $tvotes * 100);
else
$p = 0;
print("<tr><td class=embedded>" . $a[1] . " </td><td class=\"embedded nowrap\">" .
"<img class=\"bar_end\" src=\"pic/trans.gif\" alt=\"\" /><img class=\"unsltbar\" src=\"pic/trans.gif\" style=\"width: " . ($p * 3) . "px\" /><img class=\"bar_end\" src=\"pic/trans.gif\" alt=\"\" /> $p%</td></tr>\n");
++$i;
}
print("</table>\n");
$tvotes = number_format($tvotes);
print("<p align=center>".$lang_log['text_votes']."$tvotes</p>\n");
print("</td></tr></table><br /><br />\n");
print("</p></td></tr>\n");
}
print("</table>");
print($lang_log['time_zone_note']);
stdfoot();
die;
break;
}
}
?>