Ok i been working on the reports system as it really needs to be fixed and put in the svn so i come up with this, appears to work for me i would appreciate feedback if i don't recieve feedback then your just prolonging the next release of torrenttrader, we have a shit loads of things to do and this needs to be tested and put in so i can get some real work done rather than fixing shit that should of been implemented years ago :\
Go to admincp find the following:
Please note: If you get an error about a undefined function SQL_Query_exec change all of these in the above file to mysql_query
OK, so if that went smoothly you should be able to access it via admincp.php, u will see that u can either directly delete reports or mark them as completed, once reports have been marked as completed they cannot be unmarked and they cannot be marked again however u can delete them. I put two search inputs in there so u can toggle through the seperate report types, remember torrent comments & news comments come under comments.
Report back.
Go to admincp find the following:
if ($action=="reports" && $do=="view"){
stdhead("Reported Items");
navmenu();
begin_frame("Reported Items");
/* $type = $_GET["type"];
if ($type == "user")
$where = " WHERE type = 'user'";
else if ($type == "torrent")
$where = " WHERE type = 'torrent'";
else if ($type == "forum")
$where = " WHERE type = 'forum'";
else if ($type == "comment")
$where = " WHERE type = 'comment'";
else
$where = "";*/
$res = SQL_Query_exec("SELECT count(id) FROM reports WHERE complete='0'");
$row = mysql_fetch_array($res);
$count = $row[0];
$perpage = 25;
list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, basename(__FILE__) . "?type=" . $_GET["type"] . "&" );
echo "<BR><CENTER><b><a href=#>View Archived Reports</a></B></CENTER><BR>";
echo $pagertop;
print("<table border=1 cellspacing=0 cellpadding=1 align=center width=95% class=table_table>\n");
print("<tr><td class=table_head align=center>By</td><td class=table_head align=center>Reported</td><td class=table_head align=center>".T_("TYPE")."</td><td class=table_head align=center>Reason</td><td class=table_head align=center>Dealt With</td>");
print("</tr>");
$res = SQL_Query_exec("SELECT reports.id, reports.dealtwith,reports.dealtby, reports.addedby, reports.votedfor,reports.votedfor_xtra, reports.reason, reports.type, users.username, reports.complete FROM reports INNER JOIN users on reports.addedby = users.id WHERE complete = '0' ORDER BY id desc $limit");
while ($arr = mysql_fetch_assoc($res))
{
if ($arr[dealtwith])
{
$res3 = SQL_Query_exec("SELECT username FROM users WHERE id=$arr[dealtby]");
$arr3 = mysql_fetch_assoc($res3);
$dealtwith = "<font color=green><b>Yes - <a href=account-details.php?id=$arr[dealtby]><b>$arr3[username]</b></a></b></font>";
}
else
$dealtwith = "<font color=red><b>No</b></font>";
if ($arr[type] == "user")
{
$type = "account-details";
$res2 = SQL_Query_exec("SELECT username FROM users WHERE id=$arr[votedfor]");
$arr2 = mysql_fetch_assoc($res2);
$name = $arr2[username];
}
else if ($arr[type] == "forum")
{
$type = "forums";
$res2 = SQL_Query_exec("SELECT subject FROM forum_topics WHERE id=$arr[votedfor]");
$arr2 = mysql_fetch_assoc($res2);
$subject = $arr2[subject];
}
else if ($arr[type] == "comment")
{
$type = "comment";
$res2 = SQL_Query_exec("SELECT text FROM comments WHERE id=$arr[votedfor]");
$arr2 = mysql_fetch_assoc($res2);
$subject = format_comment($arr2[text]);
}
else if ($arr[type] == "torrent")
{
$type = "torrents-details";
$res2 = SQL_Query_exec("SELECT name FROM torrents WHERE id=$arr[votedfor]");
$arr2 = mysql_fetch_assoc($res2);
$name = $arr2[name];
if ($name == "")
$name = "<b>[Deleted]</b>";
}
if ($arr[type] == "forum")
{ print("<tr><td class=table_col1><a href=account-details.php?id=$arr[addedby]><b>$arr[username]</b></a></td><td align=left class=table_col2><a href=$type.php?action=viewtopic&topicid=$arr[votedfor]&page=p#$arr[votedfor_xtra]><b>$subject</b></a></td><td align=left class=table_col1>$arr[type]</td><td align=left class=table_col2>".htmlspecialchars($arr[reason])."</td><td align=left class=table_col1>$dealtwith</td></tr>\n");
}
else {
print("<tr><td class=table_col1><a href=account-details.php?id=$arr[addedby]><b>$arr[username]</b></a></td><td align=left class=table_col2><a href=$type.php?id=$arr[votedfor]><b>$name</b></a></td><td align=left class=table_col1>$arr[type]</td><td align=left class=table_col2>".htmlspecialchars($arr[reason])."</td><td align=left class=table_col1>$dealtwith</td>\n");
print("</tr>");
}}
print("</table>\n");
echo $pagerbottom;
end_frame();
stdfoot();
}Now delete that and copy below and paste it in its place.if ($action == "reports" && $do == "view") {
$page = 'admincp.php?action=reports&do=view&';
$pager[] = substr($page, 0, -1);
if ($_POST["mark"])
{
if (!@count($_POST["reports"])) show_error_msg("Error", "Nothing selected to mark.", 1);
$ids = array_map("intval", $_POST["reports"]);
$ids = implode(",", $ids);
SQL_Query_exec("UPDATE reports SET complete = '1', dealtwith = '1', dealtby = '$CURUSER[id]' WHERE id IN ($ids)");
header("Refresh: 2; url=admincp.php?action=reports&do=view");
show_error_msg("Success", "Entries marked completed.", 1);
}
if ($_POST["del"])
{
if (!@count($_POST["reports"])) show_error_msg("Error", "Nothing selected to delete.", 1);
$ids = array_map("intval", $_POST["reports"]);
$ids = implode(",", $ids);
SQL_Query_exec("DELETE FROM reports WHERE id IN ($ids)");
header("Refresh: 2; url=admincp.php?action=reports&do=view");
show_error_msg("Success", "Entries marked deleted.", 1);
}
$where = array();
switch ( $_GET["type"] )
{
case "user":
$where[] = "type = 'user'";
$pager[] = "type=user";
break;
case "torrent":
$where[] = "type = 'torrent'";
$pager[] = "type=torrent";
break;
case "comment":
$where[] = "type = 'comment'";
$pager[] = "type=comment";
break;
case "forum":
$where[] = "type = 'forum'";
$pager[] = "type=forum";
break;
default:
$where = null;
break;
}
switch ( $_GET["completed"] )
{
case 1:
$where[] = "complete = '1'";
$pager[] = "complete=1";
break;
default:
$where[] = "complete = '0'";
$pager[] = "complete=0";
break;
}
$where = implode(" AND ", $where);
$pager = implode("&", $pager);
$num = get_row_count("reports", "WHERE $where");
list($pagertop, $pagerbottom, $limit) = pager(25, $num, "$pager&");
$res = SQL_Query_exec("SELECT reports.id, reports.dealtwith, reports.dealtby, reports.addedby, reports.votedfor, reports.votedfor_xtra, reports.reason, reports.type, users.username, reports.complete FROM `reports` INNER JOIN users ON reports.addedby = users.id WHERE $where ORDER BY reports.id DESC $limit");
stdhead("Reported Items");
navmenu();
begin_frame("Reported Items");
?>
<table cellpadding="3" cellspacing="3" class="table_table" width="95%" align="center">
<tr>
<td colspan="6" align="right">
<form id='sort'>
<b>Type:</b>
<select name="type" onchange="window.location='<?php echo $page; ?>type='+this.options[this.selectedIndex].value+'&completed='+document.forms['sort'].completed.options[document.forms['sort'].completed.selectedIndex].value">
<option value="">All Types</option>
<option value="user" <?php echo ($_GET['type'] == "user" ? " selected" : ""); ?>>Users</option>
<option value="torrent" <?php echo ($_GET['type'] == "torrent" ? " selected" : ""); ?>>Torrents</option>
<option value="comment" <?php echo ($_GET['type'] == "comment" ? " selected" : ""); ?>>Comments</option>
<option value="forum" <?php echo ($_GET['type'] == "forum" ? " selected" : ""); ?>>Forum</option>
</select>
<b>Completed:</b>
<select name="completed" onchange="window.location='<?php echo $page; ?>completed='+this.options[this.selectedIndex].value+'&type='+document.forms['sort'].type.options[document.forms['sort'].type.selectedIndex].value">
<option value="0" <?php echo ($_GET['completed'] == 0 ? " selected" : ""); ?>>No</option>
<option value="1" <?php echo ($_GET['completed'] == 1 ? " selected" : ""); ?>>Yes</option>
</select>
</form>
</td>
</tr>
<form method="post" action="admincp.php?action=reports&do=view">
<tr>
<th class="table_head">Reported By</th>
<th class="table_head">Subject</th>
<th class="table_head">Type</th>
<th class="table_head">Reason</th>
<th class="table_head">Dealt With</th>
<th class="table_head">Mark</th>
</tr>
<?php if (!mysql_num_rows($res)): ?>
<tr>
<td class="table_col1" colspan="6" align="center">No reports found.</td>
</tr>
<?php endif; ?>
<?php
while ($row = mysql_fetch_assoc($res)):
$dealtwith = '<b>No</b>';
if ($row["dealtby"] > 0)
{
$q = SQL_Query_exec("SELECT username FROM users WHERE id = '$row[dealtby]'");
$r = mysql_fetch_assoc($q);
$dealtwith = 'By <a href="account-details.php?id='.$row['dealtby'].'">'.$r['username'].'</a>';
}
switch ( $row["type"] )
{
case "user":
$q = SQL_Query_exec("SELECT username FROM users WHERE id = '$row[votedfor]'");
break;
case "torrent":
$q = SQL_Query_exec("SELECT name FROM torrents WHERE id = '$row[votedfor]'");
break;
case "comment":
$q = SQL_Query_exec("SELECT text, news, torrent FROM comments WHERE id = '$row[votedfor]'");
break;
case "forum":
$q = SQL_Query_exec("SELECT subject FROM forum_topics WHERE id = '$row[votedfor]'");
break;
}
$r = mysql_fetch_row($q);
if ($row["type"] == "user")
$link = "account-details.php?id=$row[votedfor]";
else if ($row["type"] == "torrent")
$link = "torrents-details.php?id=$row[votedfor]";
else if ($row["type"] == "comment")
$link = "comments.php?type=".($r[1] > 0 ? "news" : "torrent")."&id=".($r[1] > 0 ? $r[1] : $r[2])."#$row[votedfor]";
else if ($row["type"] == "forum")
$link = "forums.php?action=viewtopic&topicid=$row[votedfor]&page=last#$row[votedfor_xtra]";
?>
<tr>
<td class="table_col1" align="center" width="10%"><a href="account-details.php?id=<?php echo $row['addedby']; ?>"><?php echo $row['username']; ?></a></td>
<td class="table_col2" align="center" width="15%"><a href="<?php echo $link; ?>"><?php echo CutName($r[0], 40); ?></a></td>
<td class="table_col1" align="center" width="10%"><?php echo $row['type']; ?></td>
<td class="table_col2" align="center" width="50%"><?php echo htmlspecialchars($row['reason']); ?></td>
<td class="table_col1" align="center" width="10%"><?php echo $dealtwith; ?></td>
<td class="table_col2" align="center" width="5%"><input type="checkbox" name="reports[]" value="<?php echo $row["id"]; ?>" /></td>
</tr>
<?php endwhile; ?>
<tr>
<td colspan="6" align="right">
<input type="button" value="Check All" onclick="this.value=check(form);" />
<?php if ($_GET["completed"] != 1): ?>
<input type="submit" name="mark" value="Mark Completed" />
<?php endif; ?>
<input type="submit" name="del" value="Delete" />
</td>
</tr>
</table>
</form>
<?php
print $pagerbottom;
end_frame();
stdfoot();
}
Open backend/functions.php add
SQL_Query_exec("DELETE FROM reports WHERE addedby = $userid");
to deleteaccount function
Find
print(T_("POSTED").": ".date("d-m-Y \\a\\t H:i:s", utc_to_tz_time($row['added']));
The above code is from the commenttable function.
And replace it with
print(T_("POSTED").": ".date("d-m-Y \\a\\t H:i:s", utc_to_tz_time($row['added'])) . "<a name='' id='$row[id]'></a>");Please note: If you get an error about a undefined function SQL_Query_exec change all of these in the above file to mysql_query
OK, so if that went smoothly you should be able to access it via admincp.php, u will see that u can either directly delete reports or mark them as completed, once reports have been marked as completed they cannot be unmarked and they cannot be marked again however u can delete them. I put two search inputs in there so u can toggle through the seperate report types, remember torrent comments & news comments come under comments.
Report back.