Reporting system revised. Needs some major cleanup and is missig some functionality (assign report, some overviews, decent notifications) but the basics are there. More after the weekend :)

git-svn-id: file:///svn/phpbb/trunk@5601 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Bart van Bragt 2006-03-04 13:50:52 +00:00
parent 0525406c3b
commit 70b20a98f7
9 changed files with 1175 additions and 15 deletions

View file

@ -83,6 +83,10 @@ define('PRIVMSGS_OUTBOX', -2);
define('PRIVMSGS_SENTBOX', -1);
define('PRIVMSGS_INBOX', 0);
// Report Types
define('REPORT_POST', 1);
define('REPORT_GENERAL', 2);
// Full Folder Actions
define('FULL_FOLDER_NONE', -3);
define('FULL_FOLDER_DELETE', -2);

View file

@ -0,0 +1,591 @@
<?php
// -------------------------------------------------------------
//
// $Id$
//
// FILENAME : mcp_reports.php
// STARTED : Fri Nov 26, 2004
// COPYRIGHT : © 2004 phpBB Group
// WWW : http://www.phpbb.com/
// LICENCE : GPL vs2.0 [ see /docs/COPYING ]
//
// -------------------------------------------------------------
// TODO: Would be nice if a moderator could 'checkout' a topic with reports so
// other moderators know that this topic is already being handled.
/**
* @package module_install
*/
class mcp_reports_info
{
function module()
{
return array(
'filename' => 'mcp_reports',
'title' => 'MCP_REPORTS',
'version' => '1.0.0',
'modes' => array(
'front' => array('title' => 'MCP_REPORTS_FRONT', 'auth' => 'acl_m_'),
'reports_yours' => array('title' => 'MCP_REPORTS_YOURS', 'auth' => 'acl_m_'),
'reports_new' => array('title' => 'MCP_REPORTS_NEW', 'auth' => 'acl_m_'),
'reports_topics' => array('title' => 'MCP_REPORTS_TOPICS', 'auth' => 'acl_m_'),
'reports_view_topic' => array('title' => 'MCP_REPORTS_VIEW_TOPIC', 'auth' => 'acl_m_'),
'reports_view' => array('title' => 'MCP_REPORTS_VIEW', 'auth' => 'acl_m_')
),
);
}
function install()
{
}
function uninstall()
{
}
}
/**
* @package mcp
* mcp_report
* Handle reports about users or posts sent in by users
*/
class mcp_reports
{
var $p_master;
function mcp_main(&$p_master)
{
$this->p_master = &$p_master;
}
function main($id, $mode)
{
global $auth, $db, $user, $template;
global $config, $phpbb_root_path, $phpEx, $SID;
$action = request_var('action', array('' => ''));
switch ($mode)
{
case 'reports_yours':
$this->mcp_reports_list($id, $mode);
break;
case 'reports_new':
$this->mcp_reports_list($id, $mode);
break;
case 'reports_topics':
$this->mcp_reports_list($id, $mode);
break;
case 'reports_view_topic':
// View reports for one topic
$this->mcp_reports_list($id, $mode);
//$this->tpl_name = 'mcp_report_topic';
break;
case 'reports_view':
// View one report (not attached to a topic)
$this->mcp_report_view($id, $mode);
break;
default:
// Main page with an overview
$this->mcp_reports_list($id, $mode);
break;
}
}
// Overview of available reports
function mcp_reports_list($id, $mode)
{
global $auth, $db, $user, $template;
global $config, $phpbb_root_path, $phpEx, $SID;
$forum_id = request_var('f', 0);
$topic_id = request_var('t', 0);
$start = request_var('start', 0);
// Show report details for a specific topic if a topic has been selected.
if($topic_id != 0)
{
return $this->mcp_report_view('topic', $topic_id);
}
$forum_info = array();
$forum_list_report = get_forum_list('m_', false, true);
// Show all reports that this user is allowed to view or only the
// reports in one specific forum?
if ($mode == 'overview' || !$forum_id)
{
$forum_list = array();
foreach ($forum_list_report as $row)
{
$forum_list[] = $row['forum_id'];
}
if (!$forum_list = implode(', ', $forum_list))
{
trigger_error('NOT_MODERATOR');
}
$sql = 'SELECT SUM(forum_topics) as sum_forum_topics
FROM ' . FORUMS_TABLE . "
WHERE forum_id IN ($forum_list)";
$result = $db->sql_query($sql);
$forum_info['forum_topics'] = (int) $db->sql_fetchfield('sum_forum_topics', 0, $result);
$db->sql_freeresult($result);
}
else
{
$forum_info = get_forum_data(array($forum_id), 'm_approve');
if (!sizeof($forum_info))
{
trigger_error('NOT_MODERATOR');
}
$forum_info = $forum_info[$forum_id];
$forum_list = $forum_id;
}
$forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>';
foreach ($forum_list_report as $row)
{
$forum_options .= '<option value="' . $row['forum_id'] . '"' . (($forum_id == $row['forum_id']) ? ' selected="selected"' : '') . '>' . $row['forum_name'] . '</option>';
}
// Note: this query needs to be made compatible with non-MySQL DBMs
mcp_sorting('reports', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id);
$forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
$limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
$sql = 'SELECT count(*) as report_count, r.*, p.post_id, p.post_subject, u.username, t.topic_id, t.topic_title, f.forum_id, f.forum_name
FROM ' . REPORTS_TABLE . ' r, ' . REASONS_TABLE . ' rr,' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
LEFT JOIN ' . FORUMS_TABLE . ' f ON f.forum_id = p.forum_id
WHERE
r.report_status = 0
AND r.post_id = p.post_id
AND r.reason_id = rr.reason_id
AND p.topic_id = t.topic_id
AND r.user_id = u.user_id
AND t.topic_reported = 1
AND p.forum_id IN (' . (is_array($forum_list) ? implode(', ', $forum_list) : $forum_list) . ")
GROUP BY topic_id
ORDER BY $sort_order_sql";
$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
while ($row = $db->sql_fetchrow($result))
{
if ($row['poster_id'] == ANONYMOUS)
{
$poster = (!empty($row['post_username'])) ? $row['post_username'] : $user->lang['GUEST'];
}
else
{
$poster = $row['username'];
}
$s_checkbox = '<input type="checkbox" name="post_id_list[]" value="' . $row['post_id'] . '" />';
$template->assign_block_vars('report', array(
'U_FORUM' => "mcp.$phpEx$SID&amp;i=report&amp;mode=&amp;f={$row['forum_id']}",
// Q: Why accessing the topic by a post_id instead of its topic_id?
// A: To prevent the post from being hidden because of wrong encoding or different charset
'U_REPORT_TOPIC' => "mcp.$phpEx$SID&amp;i=report&amp;mode=report_view_topic&amp;t={$row['topic_id']}",
'U_VIEW_DETAILS'=> "mcp.$phpEx$SID&amp;i=queue&amp;start=$start&amp;mode=approve_details&amp;f={$forum_id}&amp;p={$row['post_id']}",
'U_VIEWPROFILE' => ($row['poster_id'] != ANONYMOUS) ? "memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u={$row['poster_id']}" : '',
'REPORT_COUNT' => $row['report_count'],
'FORUM_NAME' => $row['forum_name'],
'TOPIC_TITLE' => $row['topic_title'],
'POSTER' => $poster,
'REPORT_TIME' => $user->format_date($row['report_time']),
'S_CHECKBOX' => $s_checkbox)
);
}
$db->sql_freeresult($result);
// Now display the page
$template->assign_vars(array(
'L_DISPLAY_ITEMS' => ($mode == 'unapproved_posts') ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'],
'S_FORUM_OPTIONS' => $forum_options)
);
$this->tpl_name = 'mcp_reports_front';
}
// View the reports for one topic or view one topic.
function mcp_report_view($id, $mode)
{
global $phpbb_root_path, $config, $db, $phpEx;
global $user, $template, $auth;
//$this->tpl_name = 'mcp_reports';
if(!isset($_POST['feedback_submit']))
{
// Show the reports.
$topic_id = request_var('t', 0);
if ($topic_id == 0)
{
trigger_error('NO_TOPIC_SELECTED');
}
$topic_info = get_topic_data($topic_id, 'm_');
$topic_info = $topic_info[$topic_id];
$sql = "SELECT
r.report_id, r.report_time, r.report_text, r.report_status,
r.bbcode_uid as r_bbcode_uid, r.bbcode_bitfield as r_bbcode_bitfield,
rre.reply_id, rre.reply_text, ure_from.username as reply_from_username,
ure_to.username as reply_to_username,
p.post_id, p.topic_id, p.forum_id, p.post_time, p.post_subject, p.post_text,
p.bbcode_uid as p_bbcode_uid, p.bbcode_bitfield as p_bbcode_bitfield,
u1.user_id as reporter_user_id, u1.username as reporter_username,
u2.user_id as poster_user_id, u2.username as poster_username
FROM " .
REPORTS_TABLE . " r
LEFT JOIN " . REPORTS_REPLIES_TABLE . " rre USING (report_id)
LEFT JOIN " . USERS_TABLE . " ure_from ON (rre.from_user_id = ure_from.user_id)
LEFT JOIN " . USERS_TABLE . " ure_to ON (rre.to_user_id = ure_to.user_id), " .
POSTS_TABLE . " p, " .
USERS_TABLE . " u1, " .
USERS_TABLE . " u2
WHERE
r.user_id = u1.user_id
AND r.post_id = p.post_id
AND p.poster_id = u2.user_id
AND p.topic_id = $topic_id
ORDER BY post_id DESC, report_id DESC, reply_id ASC";
$result = $db->sql_query($sql);
include_once($phpbb_root_path . 'includes/bbcode.'.$phpEx);
$old_post_id = 0;
$old_report_id = 0;
while ($row = $db->sql_fetchrow($result))
{
if($old_report_id != $row['report_id'])
{
if($old_post_id != $row['post_id'])
{
// Process message, leave it uncensored
$message = $row['post_text'];
if ($row['p_bbcode_bitfield'])
{
$bbcode = new bbcode($row['p_bbcode_bitfield']);
$bbcode->bbcode_second_pass($message, $row['p_bbcode_uid'], $row['p_bbcode_bitfield']);
}
$message = smiley_text($message);
$template->assign_block_vars('postrow', array(
'POST_ID' => $row['post_id'],
'POST_SUBJECT' => $row['post_subject'],
'POSTER_USER_ID' => $row['poster_user_id'],
'POSTER_NAME' => $row['poster_username'],
'U_POSTER_PROFILE' => ($row['poster_id'] != ANONYMOUS) ? "memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u={$row['poster_id']}" : '',
'POST_DATE' => $user->format_date($row['post_time']),
'POST_PREVIEW' => $message,
'U_APPROVE_ACTION' => "{$phpbb_root_path}mcp.$phpEx$SID&amp;i=report&amp;mode=topic",
'U_EDIT' => ($auth->acl_get('m_edit', $row['forum_id'])) ? "{$phpbb_root_path}posting.$phpEx$SID&amp;mode=edit&amp;f={$row['forum_id']}&amp;p={$row['post_id']}" : '',
'U_VIEW' => "{$phpbb_root_path}viewtopic.$phpEx$SID&amp;f={$row['forum_id']}&amp;p={$row['post_id']}#{$row['post_id']}"
)
);
} // Start post row.
$old_post_id = $row['post_id'];
// Process message, leave it uncensored
$message = $row['report_text'];
if ($row['r_bbcode_bitfield'])
{
$bbcode = new bbcode($row['r_bbcode_bitfield']);
$bbcode->bbcode_second_pass($message, $row['r_bbcode_uid'], $row['r_bbcode_bitfield']);
}
$message = smiley_text($message);
$template->assign_block_vars('postrow.reportrow', array(
'REPORT_ID' => $row['report_id'],
'REPORT_TIME' => $user->format_date($row['report_time']),
'REPORT_TEXT' => $message,
'REPORT_STATUS' => $row['report_status'],
'U_REPORTERPROFILE' => ($row['poster_id'] != ANONYMOUS) ? "memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u={$row['reporter_user_id']}" : '',
'REPORTER_USER_ID' => $row['reporter_user_id'],
'REPORTER_USERNAME' => $row['reporter_username'],
'POSTER_USER_ID' => $row['poster_user_id'],
'POSTER_USERNAME' => $row['poster_username'],
)
);
}
$old_report_id = $row['report_id'];
if($row['reply_text'] != '')
{
$template->assign_block_vars('postrow.reportrow.replyrow', array(
'REPLY_ID' => $row['reply_id'],
'REPLY_FROMUSERNAME' => $row['reply_from_username'],
'REPLY_TOUSERNAME' => $row['reply_to_username'],
'REPLY_TEXT' => $row['reply_text']
));
}
}
$db->sql_freeresult($result);
// Set some vars
$poster = ($post_info['user_colour']) ? '<span style="color:#' . $post_info['user_colour'] . '">' . $post_info['username'] . '</span>' : $post_info['username'];
$template->assign_vars(array(
'TOPIC_TITLE' => $topic_info['topic_title'],
'U_TOPIC' => "viewtopic.$phpEx$SID&amp;t={$topic_info['topic_id']}",
'U_FEEDBACK_ACTION' => $_SERVER['REQUEST_URI']
)
);
$this->tpl_name = 'mcp_reports_topic';
//$this->display($user->lang['MCP_QUEUE'], 'mcp_topicreports.html');
} // No submit
else
{
// Send feedback and close selected reports
$selected_reports = request_var('sendfeedback', array('0'=>'0'));
$report_close = request_var('feedback_close', '');
$report_feedback = request_var('feedback_text', '');
$post_ids = array();
foreach($selected_reports as $key => $value)
{
$report_ids[] = $value;
}
if(count($report_ids) == 0)
{
// TODO: i18n
trigger_error('No reports selected.');
}
$sql = "SELECT
r.report_id, r.user_id, r.reason_id, r.post_id, r.report_text,
u.username, u.user_email, u.user_jabber, u.user_lang, u.user_notify_type, u.user_options,
rr.reason_name, rr.reason_description,
p.post_id, p.post_subject,
t.topic_title, t.forum_id
FROM " . REPORTS_TABLE . " r, " .
REASONS_TABLE . " rr, " .
USERS_TABLE . " u, " .
POSTS_TABLE . " p, " .
TOPICS_TABLE . " t
WHERE
r.reason_id = rr.reason_id
AND r.user_id = u.user_id
AND r.post_id = p.post_id
AND p.topic_id = t.topic_id
AND report_id IN (" . implode(', ', $report_ids) . ")";
$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result))
{
$feedback_data[$row['user_id']] = array(
'name' => $row['username'],
'email' => $row['user_email'],
'jabber'=> $row['user_jabber'],
'lang' => $row['user_lang'],
'notify_type' => $row['user_notify_type'],
'pm' => $user->optionget('report_pm_notify', $row['user_options']),
'report_id' => $row['report_id'],
'reporter' => $row['username'],
'moderator' => $user->data['username'],
'moderator_id' => $user->data['user_id'],
'reason' => $row['reason_desc'],
'report_feedback' => $report_feedback,
'text' => $row['report_text'],
'subject' => $row['topic_title'],
'view_post' => "viewtopic.$phpEx?f={$row['forum_id']}&amp;t={$row['topic_id']}&amp;p={$row['post_id']}&amp;#{$row['post_id']}"
);
$reported_posts[$row['post_id']]++;
}
// Only send feedback if there is feedback to send
if($report_feedback != '')
{
$this->report_feedback($feedback_data);
}
// See if we need to close the report, update notifications in viewforum/topic
// Start transaction
$db->sql_transaction('begin');
if ($report_close)
{
// Close the reports
$sql = 'UPDATE ' . REPORTS_TABLE . '
SET report_status = ' . REPORT_CLOSED . '
WHERE report_id IN (' . implode(', ', $report_ids) . ')';
$db->sql_query($sql);
}
// TODO: Should we remove the notification in viewforum/topic after feedback has been added to a report? Or should we introduce a 'report in progress' icon for viewforum/topic?
// Figure out what posts are without open reports after this update.
$sql = 'SELECT r.post_id, p.topic_id, sum(IF(report_status=1, 0, 1)) as open_reports
FROM ' . REPORTS_TABLE . ' r
LEFT JOIN ' . POSTS_TABLE . ' p USING (post_id)
WHERE r.post_id IN (' . implode(', ', array_keys($reported_posts)) . ')
GROUP BY r.post_id
HAVING open_reports = 0';
$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result))
{
$resolved_posts[] = $row['post_id'];
$resolved_topics[] = $row['topic_id'];
}
// Mark those posts as resolved
if(!empty($resolved_posts))
{
$sql = 'UPDATE ' . POSTS_TABLE . ' SET
post_reported = 0
WHERE post_id IN (' . implode(', ', $resolved_posts) . ')';
$db->sql_query($sql);
// Mark topic as resolved because a moderator has taken a look at it.
$sql = 'UPDATE ' . TOPICS_TABLE . ' SET
topic_reported = 0
WHERE topic_id IN (' . implode(', ', $resolved_topics) . ')';
$db->sql_query($sql);
}
// End transaction
$db->sql_transaction('commit');
// Say something nice to the moderator
trigger_error('These reports have been closed. Thank you :)<br /> <a href="'.$_SERVER['REQUEST_URI'].'">return</a>');
} // The form was submitted
}
// ----------------------------------------------------------------------------
// Reply to reports and notify reporters of this event.
function report_feedback($data)
{
global $config, $phpbb_root_path, $phpEx;
global $user, $db;
foreach ($data as $user_id => $reply_row)
{
// TODO: Include a subject?
$sql_data = array(
'report_id' => $reply_row['report_id'],
'reply_time' => time(),
'reply_text' => $reply_row['report_feedback'],
'from_user_id' => $reply_row['moderator_id'],
'to_user_id' => $user_id
);
$db->sql_query('INSERT INTO ' . REPORTS_REPLIES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data));
}
// Notify the recipient of this reply
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
$messenger = new messenger();
$email_sig = str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']);
$email_template = 'report_feedback';
foreach ($data as $user_id => $notify_row)
{
// Send notification by email
if (!$notify_row['pm'])
{
$messenger->to($notify_row['email'], $notify_row['name']);
$messenger->im($notify_row['jabber'], $notify_row['name']);
$messenger->replyto($config['board_email']);
$messenger->template($email_template, $notify_row['lang']);
$messenger->assign_vars(array(
'EMAIL_SIG' => $email_sig,
'SITENAME' => $config['sitename'],
'USERNAME' => $notify_row['name'],
'SUBJECT' => $notify_row['subject'],
'REPORTER' => $notify_row['reporter'],
'MODERATOR' => $notify_row['moderator'],
'REPORT_REASON' => $notify_row['reason'],
'REPORT_TEXT' => $notify_row['text'],
'REPORT_FEEDBACK' => $notify_row['report_feedback'],
'U_VIEW_POST' => generate_board_url() . '/' . $notify_row['view_post'])
);
$messenger->send($notify_row['notify_type']);
$messenger->reset();
//print "mail to " . $notify_row['email'] . "({$notify_row['notify_type']})";
if ($messenger->queue)
{
$messenger->queue->save();
}
}
else
{
// Use messenger for getting the correct message, we use the email template
$messenger->template($email_template, $notify_row['lang']);
$messenger->assign_vars(array(
'EMAIL_SIG' => $email_sig,
'SITENAME' => $config['sitename'],
'USERNAME' => $notify_row['name'],
'SUBJECT' => $notify_row['subject'],
'REPORTER' => $notify_row['reporter'],
'MODERATOR' => $notify_row['moderator'],
'REPORT_REASON' => $notify_row['reason'],
'REPORT_TEXT' => $notify_row['text'],
'REPORT_FEEDBACK' => $notify_row['report_feedback'],
'U_VIEW_POST' => generate_board_url() . '/' . $notify_row['view_post'])
);
// Parse message, don't send it.
$messenger->send(false, true);
// do not put in moderators outbox
$pm_data = array(
'address_list' => array('u' => array($user_id => 'to')),
'from_user_id' => $user->data['user_id'],
'from_user_ip' => $user->data['user_ip'],
'from_username' => $user->data['username'],
'icon_id' => 0,
'enable_bbcode' => 0,
'enable_html' => 0,
'enable_smilies' => 0,
'enable_urls' => 1,
'enable_sig' => 0,
'message_md5' => md5($messenger->msg),
'bbcode_bitfield' => 0,
'bbcode_uid' => 0,
'attachment_data' => array(),
'filename_data' => array(),
'message' => $messenger->msg
);
//function submit_pm($mode, $subject, &$data, $update_message, $put_in_outbox)
submit_pm('post', $notify_row['subject'], $pm_data, true, false);
// Break the sending process...
$messenger->reset();
//print "PM to " . $notify_row['name'];
}
// Add the feedback to the report
$message = $notify_row['report_feedback'];
}
unset($messenger);
}
}
?>

View file

@ -0,0 +1,367 @@
<?php
/**
*
* @package ucp
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @package ucp
* ucp_reports
*/
class ucp_reports
{
function main($id, $mode)
{
global $config, $db, $user, $auth, $SID, $template, $phpbb_root_path, $phpEx;
switch ($mode)
{
case 'list':
$this->ucp_reports_list($id, $mode);
break;
case 'report':
$this->ucp_reports_report($id, $mode);
break;
}
}
function ucp_reports_list($id, $mode)
{
global $db, $user, $config, $template;
$sql = "SELECT
r.report_id, r.report_time, r.report_status,
p.post_id, p.poster_id,
t.topic_id, t.topic_title,
f.forum_id, f.forum_name,
u.username
FROM " .
REPORTS_TABLE . " r
LEFT JOIN " . POSTS_TABLE . " p USING (post_id)
LEFT JOIN " . TOPICS_TABLE . " t USING (topic_id)
LEFT JOIN " . FORUMS_TABLE . " f USING (forum_id)," .
REASONS_TABLE . " re, " .
USERS_TABLE . " u
WHERE
p.poster_id = u.user_id
&& r.reason_id = re.reason_id
&& r.user_id = " . $user->data['user_id'] . "
ORDER BY
report_time DESC";
$start = request_var('start', 0);
$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
while ($row = $db->sql_fetchrow($result))
{
if ($row['poster_id'] == ANONYMOUS)
{
$poster = (!empty($row['post_username'])) ? $row['post_username'] : $user->lang['GUEST'];
}
else
{
$poster = $row['username'];
}
$template->assign_block_vars('report', array(
'U_FORUM' => "mcp.$phpEx$SID&amp;i=report&amp;mode=&amp;f={$row['forum_id']}",
// Q: Why accessing the topic by a post_id instead of its topic_id?
// A: To prevent the post from being hidden because of wrong encoding or different charset
'U_REPORT_TOPIC' => "mcp.$phpEx$SID&amp;i=report&amp;mode=report_view_topic&amp;t={$row['topic_id']}",
'U_VIEW_DETAILS'=> "mcp.$phpEx$SID&amp;i=queue&amp;start=$start&amp;mode=approve_details&amp;f={$forum_id}&amp;p={$row['post_id']}",
'U_VIEWPROFILE' => ($row['poster_id'] != ANONYMOUS) ? "memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u={$row['poster_id']}" : '',
'REPORT_COUNT' => $row['report_count'],
'FORUM_NAME' => $row['forum_name'],
'TOPIC_TITLE' => $row['topic_title'],
'POSTER' => $poster,
'REPORT_TIME' => $user->format_date($row['report_time']),
)
);
}
$db->sql_freeresult($result);
$this->tpl_name = 'ucp_reports_list';
}
function ucp_reports_report($id, $mode)
{
global $db, $user, $config, $template, $auth;
$post_id = request_var('p', 0);
$report_type = ($post_id > 0) ? REPORT_POST : REPORT_GENERAL;
// Insert or update report in the database if a form has been submitted
if (isset($_POST['submit']))
{
$report_id = request_var('report_id', 0);
$reason_id = request_var('reason_id', 0);
$user_notify = (!empty($_REQUEST['notify']) && $user->data['is_registered']) ? true : false;
$report_text = request_var('report_text', '');
$sql = 'SELECT reason_name
FROM ' . REASONS_TABLE . "
WHERE reason_id = $reason_id";
$result = $db->sql_query($sql);
// TODO: 'other' is used as a special value. Make sure that you can't remove this in the admin.
if (!($row = $db->sql_fetchrow($result)) || (!$report_text && $row['reason_name'] == 'other'))
{
trigger_error('EMPTY_REPORT');
}
$db->sql_freeresult($result);
if (!empty($user->lang['report_reasons']['DESCRIPTION'][$row['reason_name']]))
{
$reason_desc = $user->lang['report_reasons']['DESCRIPTION'][$row['reason_name']];
}
else
{
$reason_desc = $row['reason_name'];
}
$sql_ary = array(
'reason_id' => (int) $reason_id,
'reason_type' => (int) $report_type,
'post_id' => (int) $post_id,
'user_id' => (int) $user->data['user_id'],
'user_notify' => (int) $user_notify,
'report_time' => (int) time(),
'report_text' => (string) $report_text // TODO: Add some BBcode magic
);
if ($report_id)
{
$sql = 'UPDATE ' . REPORTS_TABLE . '
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
WHERE report_id = ' . $report_id . ' user_id = ' . $user->data['user_id'];
$db->sql_query($sql);
if ($db->sql_affectedrows() == 0)
{
// TODO: i18n?
trigger_error("You tried to change a report that isn't yours.");
}
}
else
{
$sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' .
$db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
$report_id = $db->sql_nextid();
}
if (!$report_data['post_reported'])
{
$sql = 'UPDATE ' . POSTS_TABLE . '
SET post_reported = 1
WHERE post_id = ' . $id;
$db->sql_query($sql);
}
if (!$report_data['topic_reported'])
{
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_reported = 1
WHERE topic_id = ' . $report_data['topic_id'];
$db->sql_query($sql);
}
// Send Notifications
// All persons get notified about a new report, if notified by PM, send out email notifications too
// Send notifications to moderators
$acl_list = $auth->acl_get_list(false, array('m_', 'a_'), array(0, $report_data['forum_id']));
$notify_user = $acl_list[$report_data['forum_id']]['m_'];
$notify_user = array_unique(array_merge($notify_user, $acl_list[0]['a_']));
unset($acl_list);
// How to notify them?
$sql = 'SELECT user_id, username, user_options, user_lang, user_email, user_notify_type, user_jabber
FROM ' . USERS_TABLE . '
WHERE user_id IN (' . implode(', ', $notify_user) . ')';
$result = $db->sql_query($sql);
$notify_user = array();
while ($row = $db->sql_fetchrow($result))
{
$notify_user[$row['user_id']] = array(
'name' => $row['username'],
'email' => $row['user_email'],
'jabber'=> $row['user_jabber'],
'lang' => $row['user_lang'],
'notify_type' => $row['user_notify_type'],
'pm' => $user->optionget('report_pm_notify', $row['user_options'])
);
}
$db->sql_freeresult($result);
$report_data = array(
'id' => $id,
'report_id' => $report_id,
'reporter' => $user->data['username'],
'reason' => $reason_desc,
'text' => $report_text,
'subject' => $report_data['post_subject'],
'view_post' => ($report_type == REPORT_POST) ? "viewtopic.$phpEx?f={$report_data['forum_id']}&t={$report_data['topic_id']}&p=$id&e=$id" : ''
);
report_notification($notify_user, $report_type, $report_data);
meta_refresh(3, $redirect_url);
$message = $user->lang['POST_REPORTED_SUCCESS'] . '<br /><br />' . sprintf($user->lang[(($report_type == REPORT_POST) ? 'RETURN_TOPIC' : 'RETURN_PREVIOUS')], '<a href="' . $redirect_url . '">', '</a>');
trigger_error($message);
}
// Show the 'create report' form
// Report about a specific post or a general report (i.e. message to the mods)?
$post_id = (request_var('p', 0)) ? true : false;
if ($report_type == REPORT_POST)
{
$sql = 'SELECT
f.forum_id,
t.topic_id
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
WHERE p.post_id = $post_id
AND p.topic_id = t.topic_id
AND p.forum_id = f.forum_id";
$result = $db->sql_query($sql);
if (!($report_data = $db->sql_fetchrow($result)))
{
$message = $user->lang['POST_NOT_EXIST'];
trigger_error($message);
}
$forum_id = $report_data['forum_id'];
$topic_id = $report_data['topic_id'];
// Check required permissions
$acl_check_ary = array('f_list' => 'POST_NOT_EXIST', 'f_read' => 'USER_CANNOT_READ', 'f_report' => 'USER_CANNOT_REPORT');
foreach ($acl_check_ary as $acl => $error)
{
if (!$auth->acl_get($acl, $forum_id))
{
trigger_error($error);
}
}
unset($acl_check_ary);
// Check if the post has already been reported by this user
$sql = "SELECT
report_id, reason_id, post_id, user_notify, report_time, report_text, report_status,
bbcode_uid, bbcode_bitfield
FROM " . REPORTS_TABLE . "
WHERE post_id = $post_id
AND user_id = " . $user->data['user_id'];
$result = $db->sql_query($sql);
if ($row = $db->sql_fetchrow($result))
{
if ($user->data['is_registered'])
{
// A report exists, extract $row if we're going to display the form
if ($reason_id)
{
$report_id = (int) $row['report_id'];
}
else
{
// Overwrite set variables
$report_id = $row['report_id'];
$reason_id = $row['reason_id'];
$post_id = $row['post_id'];
$user_notify = $row['user_notify'];
$report_time = $row['report_time'];
$report_text = $row['report_text'];
$report_status = $row['report_status'];
$bbcode_uid = $row['bbcode_uid'];
$bbcode_bitfield= $row['bbcode_bitfield'];
}
}
else
{
// TODO: is this what we want?
trigger_error($user->lang['ALREADY_REPORTED'] . '<br /><br />' . sprintf($user->lang[(($report_type == REPORT_POST) ? 'RETURN_TOPIC' : 'RETURN_PREVIOUS')], '<a href="' . $redirect_url . '">', '</a>'));
}
}
else
{
$report_id = 0;
}
}
// Show create report form
// Generate the form
$sql = "SELECT *
FROM " . REASONS_TABLE . "
WHERE report_type = $report_type
ORDER BY reason_priority ASC";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$row['reason_name'] = strtoupper($row['reason_name']);
$reason_title = (!empty($user->lang['report_reasons']['TITLE'][$row['reason_name']])) ? $user->lang['report_reasons']['TITLE'][$row['reason_name']] : ucwords(str_replace('_', ' ', $row['reason_name']));
$reason_desc = (!empty($user->lang['report_reasons']['DESCRIPTION'][$row['reason_name']])) ? $user->lang['report_reasons']['DESCRIPTION'][$row['reason_name']] : $row['reason_description'];
$template->assign_block_vars('reason', array(
'ID' => $row['reason_id'],
'NAME' => htmlspecialchars($reason_title),
'DESCRIPTION' => htmlspecialchars($reason_desc),
'S_SELECTED' => ($row['reason_id'] == $reason_id) ? true : false)
);
}
$template->assign_vars(array(
'REPORT_TEXT' => $report_text,
'S_REPORT_ACTION' => "{$phpbb_root_path}report.$phpEx$SID&amp;p=$id" . (($report_id) ? "&amp;report_id=$report_id" : ''),
'S_NOTIFY' => (!empty($user_notify)) ? true : false,
'S_CAN_NOTIFY' => ($user->data['is_registered']) ? true : false,
'S_REPORT_POST' => ($report_type == REPORT_POST) ? true : false)
);
$this->tpl_name = 'ucp_reports_report';
}
}
/**
* @package module_install
*/
class ucp_reports_info
{
function module()
{
return array(
'filename' => 'ucp_reports',
'title' => 'UCP_REPORTS',
'version' => '1.0.0',
'modes' => array(
'list' => array('title' => 'UCP_REPORTS_LIST', 'auth' => ''),
'report' => array('title' => 'UCP_REPORTS_REPORT', 'auth' => ''),
),
);
}
function install()
{
}
function uninstall()
{
}
}
?>

View file

@ -550,26 +550,42 @@ CREATE TABLE phpbb_ranks (
PRIMARY KEY (rank_id)
);
# Table: 'phpbb_reports'
CREATE TABLE `phpbb_reports` (
`report_id` smallint(5) unsigned NOT NULL auto_increment,
`report_type` tinyint(4) unsigned NOT NULL default '0',
`reason_id` smallint(5) unsigned NOT NULL default '0',
`post_id` mediumint(8) unsigned NOT NULL default '0',
`user_id` mediumint(8) unsigned NOT NULL default '0',
`user_notify` tinyint(1) NOT NULL default '0',
`report_time` int(10) unsigned NOT NULL default '0',
`report_text` text NOT NULL,
`report_status` tinyint(4) NOT NULL default '0',
`bbcode_uid` varchar(5) NOT NULL default '',
`bbcode_bitfield` int(11) NOT NULL default '0',
PRIMARY KEY (`report_id`)
);
# Table: 'phpbb_reports_reasons'
CREATE TABLE phpbb_reports_reasons (
reason_id smallint(6) NOT NULL auto_increment,
report_type tinyint(4) unsigned NOT NULL default '0',
reason_priority tinyint(4) DEFAULT '0' NOT NULL,
reason_name varchar(255) DEFAULT '' NOT NULL,
reason_description text NOT NULL,
PRIMARY KEY (reason_id)
);
# Table: 'phpbb_reports'
CREATE TABLE phpbb_reports (
report_id smallint(5) UNSIGNED NOT NULL auto_increment,
reason_id smallint(5) UNSIGNED DEFAULT '0' NOT NULL,
post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
msg_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_notify tinyint(1) DEFAULT '0' NOT NULL,
report_time int(10) UNSIGNED DEFAULT '0' NOT NULL,
report_text text NOT NULL,
PRIMARY KEY (report_id)
# Table: `phpbb_reports_replies`
CREATE TABLE `phpbb_reports_replies` (
`reply_id` mediumint(8) unsigned NOT NULL auto_increment,
`report_id` mediumint(8) unsigned NOT NULL default '0',
`reply_time` int(10) unsigned NOT NULL default '0',
`reply_text` text NOT NULL,
`from_user_id` mediumint(9) NOT NULL default '0',
`status` tinyint(4) NOT NULL default '0',
`to_user_id` mediumint(9) NOT NULL default '0',
PRIMARY KEY (`reply_id`)
);
# Table: 'phpbb_search_results'

View file

@ -754,10 +754,15 @@ INSERT INTO phpbb_search_wordmatch (word_id, post_id, title_match) VALUES (3, 1,
# MSSQL IDENTITY phpbb_reports_reasons ON #
# -- reasons
INSERT INTO phpbb_reports_reasons (reason_id, reason_priority, reason_name, reason_description) VALUES (1, 3, 'warez', 'The reported post contains links to pirated or illegal software');
INSERT INTO phpbb_reports_reasons (reason_id, reason_priority, reason_name, reason_description) VALUES (2, 2, 'spam', 'The reported post has for only purpose to advertise for a website or another product');
INSERT INTO phpbb_reports_reasons (reason_id, reason_priority, reason_name, reason_description) VALUES (3, 1, 'off_topic', 'The reported post is off topic');
INSERT INTO phpbb_reports_reasons (reason_id, reason_priority, reason_name, reason_description) VALUES (4, 0, 'other', 'The reported post does not fit into any other category, please use the description field');
INSERT INTO phpbb_reports_reasons (reason_id, reason_priority, reason_name, reason_description, report_type) VALUES (1, 0, 'other', 'The reported post does not fit into any other category (please use the description field)', 1);
INSERT INTO phpbb_reports_reasons (reason_id, reason_priority, reason_name, reason_description, report_type) VALUES (2, 90, 'warez', 'The reported post contains links to pirated or illegal software', 1);
INSERT INTO phpbb_reports_reasons (reason_id, reason_priority, reason_name, reason_description, report_type) VALUES (3, 60, 'spam', 'The reported post has for only purpose to advertise for a website or another product', 1);
INSERT INTO phpbb_reports_reasons (reason_id, reason_priority, reason_name, reason_description, report_type) VALUES (4, 20, 'off_topic', 'The reported post is off topic', 1);
INSERT INTO phpbb_reports_reasons (reason_id, reason_priority, reason_name, reason_description, report_type) VALUES (5, 0, 'other', 'Other reason (please use the description field)', 2);
INSERT INTO phpbb_reports_reasons (reason_id, reason_priority, reason_name, reason_description, report_type) VALUES (6, 40, 'bug', 'The forum is not behaving as I expected', 2);
INSERT INTO phpbb_reports_reasons (reason_id, reason_priority, reason_name, reason_description, report_type) VALUES (7, 30, 'email', 'I have a problem with receiving email.', 2);
INSERT INTO phpbb_reports_reasons (reason_id, reason_priority, reason_name, reason_description, report_type) VALUES (8, 20, 'user', 'I have a complaint about a user', 2);
# MSSQL IDENTITY phpbb_reports_reasons OFF #

View file

@ -0,0 +1,34 @@
<!-- INCLUDE mcp_header.html -->
<!-- $Id$ -->
<table class="tablebg" width="100%" cellspacing="1">
<tr>
<td class="row3" colspan="6" align="center"><b class="gen">{L_OPEN_REPORTS}</b></td>
</tr>
<tr>
<th>&nbsp;{L_NR}&nbsp;</th>
<th>&nbsp;{L_FORUM}&nbsp;</th>
<th>&nbsp;{L_TOPIC}&nbsp;</th>
<th>&nbsp;{L_USER}&nbsp;</th>
<th>&nbsp;{L_COUNT}&nbsp;</th>
<th>&nbsp;</th>
</tr>
<!-- BEGIN report -->
<tr>
<td class="row1" width="15%" valign="top"><span class="gen"><a href="{report.U_USER}"><a href="{report.U_REPORT_TOPIC}">{report.REPORT_COUNT}</a></span></td>
<td class="row1" width="15%" valign="top"><span class="gen"><a href="{report.U_USER}"><a href="{report.U_FORUM}">{report.FORUM_NAME}</a></span></td>
<td class="row2" width="15%" valign="top"><a class="gen" href="{report.U_TOPIC}">{report.TOPIC_TITLE}</a></td>
<td class="row1" width="15%" valign="top"><a class="gen" href="{report.U_VIEWPROFILE}">{report.POSTER}</a></span></td>
<td class="row2" width="15%" valign="top"><span class="gen">{report.REPORT_COUNT}</span></td>
<td class="row1" width="15%" valign="top"><span class="gen"> <input type="checkbox" /> </td>
</tr>
<!-- BEGINELSE -->
<tr>
<td class="row1" colspan="5" align="center"><span class="gen">{L_REPORTS_ZERO_TOTAL}</span></td>
</tr>
<!-- END report -->
</table>
<br clear="all" /><br />
<!-- INCLUDE mcp_footer.html -->

View file

@ -0,0 +1,77 @@
<!-- INCLUDE mcp_header.html -->
<form method="POST" action="{U_FEEDBACK_ACTION}">
<!-- BEGIN postrow -->
<a name="{postrow.POST_ID}"></a>
<table width="100%" cellpadding="3" cellspacing="1" border="0" class="tablebg">
<tr>
<th colspan="2" height="28" align="center">{L_POST_DETAILS}</th>
</tr>
<tr>
<td class="row1"><b class="gen">{L_POST_SUBJECT}: </b></td>
<td class="row2"><span class="gen"><a href="{postrow.U_VIEW}">{postrow.POST_SUBJECT}</a></span></td>
</tr>
<tr>
<td class="row1" width="20%" valign="top">
<b class="gen">{L_POSTER}:</b> <span class="gen"><a href="{U_POSTER_PROFILE}">{postrow.POSTER_NAME}</a></span><br />
<b class="gen">{L_POSTED}: </b> <span class="postdetails">{postrow.POST_DATE}</span>
</td>
<td class="row2" width="80%"><span class="gen">{postrow.POST_PREVIEW}</span></td>
</tr>
</table>
<table style="margin-left: 5%" width="100%">
<!-- BEGIN reportrow -->
<tr>
<th colspan="3">Report {postrow.reportrow.REPORT_ID}</th>
</tr>
<tr class="row1">
<!-- IF postrow.reportrow.REPORT_STATUS neq 1 -->
<td width="5%"><input type="checkbox" name="sendfeedback[]" value="{postrow.reportrow.REPORT_ID}" /></td>
<!-- ENDIF -->
<!-- Nesting IF/ELSE didn't work as expected -->
<!-- IF postrow.reportrow.REPORT_STATUS eq 1 -->
<td width="5%"><span style="color: red">RESOLVED</style></td>
<!-- ENDIF -->
<td width="15%" valign="top">
<b>Time:</b> <span class="postdetails">{postrow.reportrow.REPORT_TIME}</span><br />
<b>Reporter:</b> <span class="gen"><!-- IF postrow.reportrow.U_REPORTERPROFILE --><a href="{postrow.reportrow.U_REPORTERPROFILE}">{postrow.reportrow.REPORTER_USERNAME}</a><!-- ELSE -->{postrow.reportrow.REPORTER_USERNAME}<!-- ENDIF --></span>
</td>
<td valign="top"><span class="gen">{postrow.reportrow.REPORT_TEXT}</span></td>
</tr>
<!-- This needs some VERY serious cleaning up :) -->
<tr><td colspan="3">
<table style="margin-left: 10%" width="100%">
<!-- BEGIN replyrow -->
<tr>
<th colspan="2">Reply {postrow.reportrow.replyrow.REPLY_ID}</th>
</tr>
<tr class="row1">
<td width="15%" valign="top">
<b>Time:</b> <span class="postdetails">{postrow.reportrow.REPORT_TIME}</span><br />
<b>From:</b> <span class="gen">{postrow.reportrow.replyrow.REPLY_FROMUSERNAME}</span>
<b>To:</b> <span class="gen">{postrow.reportrow.replyrow.REPLY_TOUSERNAME}</span>
</td>
<td valign="top"><span class="gen">{postrow.reportrow.replyrow.REPLY_TEXT}</span></td>
</tr>
<!-- END replyrow -->
</table>
</td></tr>
<!-- BEGINELSE -->
<tr class="row1">
<td class="row1" colspan="6" height="30" align="center" valign="middle"><span class="gen">{L_NO_REPORTS}</span></td>
</tr>
<!-- END reportrow -->
</table>
<br />
<!-- END postrow -->
Send this comment to the selected reporters:<br />
<textarea name="feedback_text" style="width: 100%" cols="80" rows="5"></textarea>
{L_CLOSE_REPORT}<input type="checkbox" name="feedback_close">
<input type="submit" name="feedback_submit" value="{L_SUBMIT}"/></p>
</form>
<!-- INCLUDE mcp_footer.html -->

View file

@ -0,0 +1,32 @@
<!-- INCLUDE ucp_header.html -->
<!-- $Id$ -->
<table class="tablebg" width="100%" cellspacing="1">
<tr>
<td class="row3" colspan="6" align="center"><b class="gen">{L_YOUR_REPORTS}</b></td>
</tr>
<tr>
<th>&nbsp;{L_USER}&nbsp;</th>
<th>&nbsp;{L_TOPIC}&nbsp;</th>
<th>&nbsp;{L_FORUM}&nbsp;</th>
<th>&nbsp;{L_DATE}&nbsp;</th>
<th>&nbsp;{L_STATUS}&nbsp;</th>
</tr>
<!-- BEGIN report -->
<tr>
<td class="row1" width="15%" valign="top"><a class="gen" href="{report.U_VIEWPROFILE}">{report.POSTER}</a></span></td>
<td class="row2" width="15%" valign="top"><a class="gen" href="{report.U_TOPIC}">{report.TOPIC_TITLE}</a></td>
<td class="row1" width="15%" valign="top"><span class="gen"><a href="{report.U_USER}"><a href="{report.U_FORUM}">{report.FORUM_NAME}</a></span></td>
<td class="row2" width="15%" valign="top"><span class="gen">{report.REPORT_TIME}</span></td>
<td class="row1" width="15%" valign="top"><span class="gen">{report.REPORT_STATUS}</span></td>
</tr>
<!-- BEGINELSE -->
<tr>
<td class="row1" colspan="5" align="center"><span class="gen">{L_REPORTS_ZERO_TOTAL}</span></td>
</tr>
<!-- END report -->
</table>
<br clear="all" /><br />
<!-- INCLUDE ucp_footer.html -->

View file

@ -0,0 +1,34 @@
<!-- INCLUDE ucp_header.html -->
<!-- $Id$ -->
<form method="post" action="{S_REPORT_ACTION}" name="report">
<table class="tablebg" width="100%" cellspacing="1">
<tr>
<th colspan="2"><!-- IF S_REPORT_POST -->{L_REPORT_POST}<!-- ELSE -->{L_REPORT_GENERAL}<!-- ENDIF --></th>
</tr>
<tr>
<td class="row3" colspan="2"><span class="gensmall"><!-- IF S_REPORT_POST -->{L_REPORT_POST_EXPLAIN}<!-- ELSE -->{L_REPORT_GENERAL_EXPLAIN}<!-- ENDIF --></span></td>
</tr>
<tr>
<td class="row1" width="22%"><b class="gen">{L_REASON}:</b></td>
<td class="row2" width="78%"><select name="reason_id"><!-- BEGIN reason --><option value="{reason.ID}"<!-- IF reason.S_SELECTED --> selected="selected"<!-- ENDIF -->>{reason.DESCRIPTION}</option><!-- END reason --></select></td>
</tr>
<!-- IF S_CAN_NOTIFY -->
<tr>
<td class="row1"><span class="gen"><b>{L_REPORT_NOTIFY}:</b></span><br /><span class="gensmall">{L_REPORT_NOTIFY_EXPLAIN}</span></td>
<td class="row2"><span class="gen"><input type="radio" name="notify" value="1" <!-- IF S_NOTIFY -->checked="checked" <!-- ENDIF -->/> {L_YES} &nbsp;<input type="radio" name="notify" value="0" <!-- IF not S_NOTIFY -->checked="checked" <!-- ENDIF -->/> {L_NO}</span></td>
</tr>
<!-- ENDIF -->
<tr>
<td class="row1" valign="top"><span class="gen"><b>{L_REPORT_MORE_INFO}:</b></span><br /><span class="gensmall">{L_REPORT_CAN_LEAVE_BLANK}</span></td>
<td class="row2"><textarea class="post" style="width:500px" name="report_text" rows="25" cols="40" class="post">{REPORT_TEXT}</textarea></td>
</tr>
<tr>
<td class="cat" colspan="2" align="center"><input type="submit" name="submit" class="btnmain" value="{L_SUBMIT}" />&nbsp;<input type="submit" name="cancel" class="btnlite" value="{L_CANCEL}"></td>
</tr>
</table>
</form>
<!-- INCLUDE ucp_footer.html -->