54 changes: 40 additions & 14 deletions Sources/ModerationCenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ function ModerationMain($dont_call = false)
'closed' => array($txt['mc_reportedp_closed']),
),
),
'pm_reports' => array(
'label' => $txt['mc_reported_pms'],
'enabled' => $user_info['is_admin'],
'file' => 'ModerationCenter.php',
'function' => 'ReportedPosts',
'subsections' => array(
'open' => array($txt['mc_reportedp_active']),
'closed' => array($txt['mc_reportedp_closed']),
),
),
),
),
'groups' => array(
Expand Down Expand Up @@ -562,9 +572,17 @@ function ReportedPosts()
if ($user_info['mod_cache']['bq'] == '0=1')
isAllowedTo('moderate_forum');

// This should not be needed...
$show_pms = false;
if ($context['admin_area'] == 'pm_reports')
{
$show_pms = true;
isAllowedTo('admin_forum');
}

// Are they wanting to view a particular report?
if (!empty($_REQUEST['report']))
return ModReport();
return ModReport($show_pm);

// Set up the comforting bits...
$context['page_title'] = $txt['mc_reported_posts'];
Expand Down Expand Up @@ -594,7 +612,7 @@ function ReportedPosts()

// Time to update.
updateSettings(array('last_mod_report_action' => time()));
recountOpenReports();
recountOpenReports($show_pms);
}
elseif (isset($_POST['close']) && isset($_POST['close_selected']))
{
Expand All @@ -620,25 +638,27 @@ function ReportedPosts()

// Time to update.
updateSettings(array('last_mod_report_action' => time()));
recountOpenReports();
recountOpenReports($show_pms);
}
}

// How many entries are we viewing?
$request = $smcFunc['db_query']('', '
SELECT COUNT(*)
FROM {db_prefix}log_reported AS lr
WHERE lr.closed = {int:view_closed}
WHERE lr.closed = {int:view_closed}' . ($show_pms ? '' : '
AND id_pm = {int:not_a_pm}') . '
AND ' . ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1' ? $user_info['mod_cache']['bq'] : 'lr.' . $user_info['mod_cache']['bq']),
array(
'view_closed' => $context['view_closed'],
'not_a_pm' => 0,
)
);
list ($context['total_reports']) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

// So, that means we can page index, yes?
$context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=reports' . ($context['view_closed'] ? ';sa=closed' : ''), $_GET['start'], $context['total_reports'], 10);
$context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=' . $context['admin_area'] . ($context['view_closed'] ? ';sa=closed' : ''), $_GET['start'], $context['total_reports'], 10);
$context['start'] = $_GET['start'];

// By George, that means we in a position to get the reports, golly good.
Expand All @@ -648,12 +668,14 @@ function ReportedPosts()
IFNULL(mem.real_name, lr.membername) AS author_name, IFNULL(mem.id_member, 0) AS id_author
FROM {db_prefix}log_reported AS lr
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
WHERE lr.closed = {int:view_closed}
WHERE lr.closed = {int:view_closed}' . ($show_pms ? '' : '
AND id_pm = {int:not_a_pm}') . '
AND ' . ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1' ? $user_info['mod_cache']['bq'] : 'lr.' . $user_info['mod_cache']['bq']) . '
ORDER BY lr.time_updated DESC
LIMIT ' . $context['start'] . ', 10',
array(
'view_closed' => $context['view_closed'],
'not_a_pm' => 0,
)
);
$context['reports'] = array();
Expand All @@ -665,7 +687,7 @@ function ReportedPosts()
'id' => $row['id_report'],
'alternate' => $i % 2,
'topic_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
'report_href' => $scripturl . '?action=moderate;area=reports;report=' . $row['id_report'],
'report_href' => $scripturl . '?action=moderate;area=' . $context['admin_area'] . ';report=' . $row['id_report'],
'author' => array(
'id' => $row['id_author'],
'name' => $row['author_name'],
Expand Down Expand Up @@ -747,19 +769,21 @@ function ModerateGroups()
/**
* How many open reports do we have?
*/
function recountOpenReports()
function recountOpenReports($show_pms = false)
{
global $user_info, $context, $smcFunc;

$request = $smcFunc['db_query']('', '
SELECT COUNT(*)
FROM {db_prefix}log_reported
WHERE ' . $user_info['mod_cache']['bq'] . '
WHERE ' . $user_info['mod_cache']['bq'] . ($show_pms ? '' : '
AND id_pm = {int:not_a_pm}') . '
AND closed = {int:not_closed}
AND ignore_all = {int:not_ignored}',
array(
'not_closed' => 0,
'not_ignored' => 0,
'not_a_pm' => 0,
)
);
list ($open_reports) = $smcFunc['db_fetch_row']($request);
Expand All @@ -778,7 +802,7 @@ function recountOpenReports()
* Get details about the moderation report... specified in
* $_REQUEST['report'].
*/
function ModReport()
function ModReport($show_pm = false)
{
global $user_info, $context, $sourcedir, $scripturl, $txt, $smcFunc;

Expand All @@ -796,11 +820,13 @@ function ModReport()
IFNULL(mem.real_name, lr.membername) AS author_name, IFNULL(mem.id_member, 0) AS id_author
FROM {db_prefix}log_reported AS lr
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
WHERE lr.id_report = {int:id_report}
WHERE lr.id_report = {int:id_report}' . ($show_pms ? '' : '
AND id_pm = {int:not_a_pm}') . '
AND ' . ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1' ? $user_info['mod_cache']['bq'] : 'lr.' . $user_info['mod_cache']['bq']) . '
LIMIT 1',
array(
'id_report' => $_REQUEST['report'],
'not_a_pm' => 0,
)
);

Expand Down Expand Up @@ -836,7 +862,7 @@ function ModReport()
);

// Redirect to prevent double submittion.
redirectexit($scripturl . '?action=moderate;area=reports;report=' . $_REQUEST['report']);
redirectexit($scripturl . '?action=moderate;area=' . $context['admin_area'] . ';report=' . $_REQUEST['report']);
}
}

Expand All @@ -847,7 +873,7 @@ function ModReport()
'message_id' => $row['id_msg'],
'message_href' => $scripturl . '?msg=' . $row['id_msg'],
'message_link' => '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>',
'report_href' => $scripturl . '?action=moderate;area=reports;report=' . $row['id_report'],
'report_href' => $scripturl . '?action=moderate;area=' . $context['admin_area'] . ';report=' . $row['id_report'],
'author' => array(
'id' => $row['id_author'],
'name' => $row['author_name'],
Expand Down Expand Up @@ -933,7 +959,7 @@ function ModReport()
'title' => $txt['mc_modreport_modactions'],
'items_per_page' => 15,
'no_items_label' => $txt['modlog_no_entries_found'],
'base_href' => $scripturl . '?action=moderate;area=reports;report=' . $context['report']['id'],
'base_href' => $scripturl . '?action=moderate;area=' . $context['admin_area'] . ';report=' . $context['report']['id'],
'default_sort_col' => 'time',
'get_items' => array(
'function' => 'list_getModLogEntries',
Expand Down
63 changes: 39 additions & 24 deletions Sources/PersonalMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3132,37 +3132,20 @@ function ReportMessage()

$context['pm_id'] = $pmsg;
$context['page_title'] = $txt['pm_report_title'];

// If we're here, just send the user to the template, with a few useful context bits.
if (!isset($_POST['report']))
{
$context['sub_template'] = 'report_message';
$context['sub_template'] = 'report_message';

// @todo I don't like being able to pick who to send it to. Favoritism, etc. sucks.
// Now, get all the administrators.
$request = $smcFunc['db_query']('', '
SELECT id_member, real_name
FROM {db_prefix}members
WHERE id_group = {int:admin_group} OR FIND_IN_SET({int:admin_group}, additional_groups) != 0
ORDER BY real_name',
array(
'admin_group' => 1,
)
);
$context['admins'] = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$context['admins'][$row['id_member']] = $row['real_name'];
$smcFunc['db_free_result']($request);

// How many admins in total?
$context['admin_count'] = count($context['admins']);
}
// Otherwise, let's get down to the sending stuff.
else
if (isset($_POST['report']))
{
// Check the session before proceeding any further!
checkSession('post');

$poster_comment = strtr($smcFunc['htmlspecialchars']($_POST['reason']), array("\r" => '', "\t" => ''));

if ($smcFunc['strlen']($poster_comment) > 254)
fatal_lang_error('post_too_long', false);

// First, pull out the message contents, and verify it actually went to them!
$request = $smcFunc['db_query']('', '
SELECT pm.subject, pm.body, pm.msgtime, pm.id_member_from, IFNULL(m.real_name, pm.from_name) AS sender_name
Expand All @@ -3185,6 +3168,38 @@ function ReportMessage()
list ($subject, $body, $time, $memberFromID, $memberFromName) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

$smcFunc['db_insert']('',
'{db_prefix}log_reported',
array(
'id_msg' => 'int', 'id_topic' => 'int', 'id_board' => 'int', 'id_pm' => 'int', 'id_member' => 'int', 'membername' => 'string',
'subject' => 'string', 'body' => 'string', 'time_started' => 'int', 'time_updated' => 'int',
'num_reports' => 'int', 'closed' => 'int', 'pm_time_sent' => 'int',
),
array(
0, 0, 0, $context['pm_id'], $memberFromID, $memberFromName,
$subject, $body , time(), time(), 1, 0, $time,
),
array('id_report')
);
$id_report = $smcFunc['db_insert_id']('{db_prefix}log_reported', 'id_report');

// Now just add the report...
if ($id_report)
{
$smcFunc['db_insert']('',
'{db_prefix}log_reported_comments',
array(
'id_report' => 'int', 'id_member' => 'int', 'membername' => 'string', 'email_address' => 'string',
'member_ip' => 'string', 'comment' => 'string', 'time_sent' => 'int',
),
array(
$id_report, $user_info['id'], $user_info['name'], $user_info['email'],
$user_info['ip'], $poster_comment, time(),
),
array('id_comment')
);
}

// Remove the line breaks...
$body = preg_replace('~<br ?/?' . '>~i', "\n", $body);

Expand Down
8 changes: 4 additions & 4 deletions Sources/SendTopic.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,13 @@ function ReportToModerator2()
$smcFunc['db_insert']('',
'{db_prefix}log_reported',
array(
'id_msg' => 'int', 'id_topic' => 'int', 'id_board' => 'int', 'id_member' => 'int', 'membername' => 'string',
'id_msg' => 'int', 'id_topic' => 'int', 'id_board' => 'int', 'id_pm' => 'int', 'id_member' => 'int', 'membername' => 'string',
'subject' => 'string', 'body' => 'string', 'time_started' => 'int', 'time_updated' => 'int',
'num_reports' => 'int', 'closed' => 'int',
'num_reports' => 'int', 'closed' => 'int', 'pm_time_sent' => 'int',
),
array(
$_POST['msg'], $message['id_topic'], $message['id_board'], $message['id_poster'], $message['real_name'],
$message['subject'], $message['body'] , time(), time(), 1, 0,
$_POST['msg'], $message['id_topic'], $message['id_board'], 0, $message['id_poster'], $message['real_name'],
$message['subject'], $message['body'] , time(), time(), 1, 0,, 0
),
array('id_report')
);
Expand Down
8 changes: 4 additions & 4 deletions Themes/default/ModerationCenter.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ function template_reported_posts()
<br />
<ul class="quickbuttons">
<li><a href="', $report['report_href'], '">', $details_button, '</a></li>
<li><a href="', $scripturl, '?action=moderate;area=reports', $context['view_closed'] ? ';sa=closed' : '', ';ignore=', (int) !$report['ignore'], ';rid=', $report['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '" ', !$report['ignore'] ? 'onclick="return confirm(\'' . $txt['mc_reportedp_ignore_confirm'] . '\');"' : '', '>', $report['ignore'] ? $unignore_button : $ignore_button, '</a></li>
<li><a href="', $scripturl, '?action=moderate;area=reports', $context['view_closed'] ? ';sa=closed' : '', ';close=', (int) !$report['closed'], ';rid=', $report['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '">', $close_button, '</a></li>
<li><a href="', $scripturl, '?action=moderate;area=', $context['admin_area'], $context['view_closed'] ? ';sa=closed' : '', ';ignore=', (int) !$report['ignore'], ';rid=', $report['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '" ', !$report['ignore'] ? 'onclick="return confirm(\'' . $txt['mc_reportedp_ignore_confirm'] . '\');"' : '', '>', $report['ignore'] ? $unignore_button : $ignore_button, '</a></li>
<li><a href="', $scripturl, '?action=moderate;area=', $context['admin_area'], $context['view_closed'] ? ';sa=closed' : '', ';close=', (int) !$report['closed'], ';rid=', $report['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '">', $close_button, '</a></li>
<li>', !$context['view_closed'] ? '<input type="checkbox" name="close[]" value="' . $report['id'] . '" class="input_check" />' : '', '</li>
</ul>
</div>
Expand Down Expand Up @@ -444,8 +444,8 @@ function template_viewmodreport()
$unignore_button = create_button('ignore.png', 'mc_reportedp_unignore', 'mc_reportedp_unignore', 'class="centericon"');

echo '
<a href="', $scripturl, '?action=moderate;area=reports;ignore=', (int) !$context['report']['ignore'], ';rid=', $context['report']['id'], ';', $context['session_var'], '=', $context['session_id'], '" ', !$context['report']['ignore'] ? 'onclick="return confirm(\'' . $txt['mc_reportedp_ignore_confirm'] . '\');"' : '', '>', $context['report']['ignore'] ? $unignore_button : $ignore_button, '</a>
<a href="', $scripturl, '?action=moderate;area=reports;close=', (int) !$context['report']['closed'], ';rid=', $context['report']['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $close_button, '</a>
<a href="', $scripturl, '?action=moderate;area=', $context['admin_area'], ';ignore=', (int) !$context['report']['ignore'], ';rid=', $context['report']['id'], ';', $context['session_var'], '=', $context['session_id'], '" ', !$context['report']['ignore'] ? 'onclick="return confirm(\'' . $txt['mc_reportedp_ignore_confirm'] . '\');"' : '', '>', $context['report']['ignore'] ? $unignore_button : $ignore_button, '</a>
<a href="', $scripturl, '?action=moderate;area=', $context['admin_area'], ';close=', (int) !$context['report']['closed'], ';rid=', $context['report']['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $close_button, '</a>
</span>
</h3>
</div>
Expand Down
19 changes: 0 additions & 19 deletions Themes/default/PersonalMessage.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -1489,25 +1489,6 @@ function template_report_message()
<div class="content">
<dl class="settings">';

// If there is more than one admin on the forum, allow the user to choose the one they want to direct to.
// @todo Why?
if ($context['admin_count'] > 1)
{
echo '
<dt>
<strong>', $txt['pm_report_admins'], ':</strong>
</dt>
<dd>
<select name="id_admin">
<option value="0">', $txt['pm_report_all_admins'], '</option>';
foreach ($context['admins'] as $id => $name)
echo '
<option value="', $id, '">', $name, '</option>';
echo '
</select>
</dd>';
}

echo '
<dt>
<strong>', $txt['pm_report_reason'], ':</strong>
Expand Down
1 change: 1 addition & 0 deletions Themes/default/languages/index.english.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@
$txt['mc_unapproved_attachments'] = 'Unapproved Attachments';
$txt['mc_unapproved_poststopics'] = 'Unapproved Posts and Topics';
$txt['mc_reported_posts'] = 'Reported Posts';
$txt['mc_reported_pms'] = 'Reported Personal Messages';
$txt['modlog_view'] = 'Moderation Log';
$txt['calendar_menu'] = 'View Calendar';

Expand Down
2 changes: 2 additions & 0 deletions other/install_2-1_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@ CREATE TABLE {$db_prefix}log_reported (
id_msg int(10) unsigned NOT NULL default '0',
id_topic mediumint(8) unsigned NOT NULL default '0',
id_board smallint(5) unsigned NOT NULL default '0',
id_pm int(10) unsigned NOT NULL default '0',
id_member mediumint(8) unsigned NOT NULL default '0',
membername varchar(255) NOT NULL default '',
subject varchar(255) NOT NULL default '',
Expand All @@ -1015,6 +1016,7 @@ CREATE TABLE {$db_prefix}log_reported (
num_reports mediumint(6) NOT NULL default '0',
closed tinyint(3) NOT NULL default '0',
ignore_all tinyint(3) NOT NULL default '0',
pm_time_sent int(10) NOT NULL default '0',
PRIMARY KEY (id_report),
KEY id_member (id_member),
KEY id_topic (id_topic),
Expand Down
2 changes: 2 additions & 0 deletions other/install_2-1_postgresql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,7 @@ CREATE TABLE {$db_prefix}log_reported (
id_msg int NOT NULL default '0',
id_topic int NOT NULL default '0',
id_board smallint NOT NULL default '0',
id_pm int NOT NULL default '0',
id_member int NOT NULL default '0',
membername varchar(255) NOT NULL,
subject varchar(255) NOT NULL,
Expand All @@ -1332,6 +1333,7 @@ CREATE TABLE {$db_prefix}log_reported (
num_reports int NOT NULL default '0',
closed smallint NOT NULL default '0',
ignore_all smallint NOT NULL default '0',
pm_time_sent int NOT NULL default '0',
PRIMARY KEY (id_report)
);

Expand Down
2 changes: 2 additions & 0 deletions other/install_2-1_sqlite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ CREATE TABLE {$db_prefix}log_reported (
id_msg int NOT NULL default '0',
id_topic int NOT NULL default '0',
id_board smallint NOT NULL default '0',
id_pm int NOT NULL default '0',
id_member int NOT NULL default '0',
membername varchar(255) NOT NULL,
subject varchar(255) NOT NULL,
Expand All @@ -1085,6 +1086,7 @@ CREATE TABLE {$db_prefix}log_reported (
num_reports int NOT NULL default '0',
closed smallint NOT NULL default '0',
ignore_all smallint NOT NULL default '0'
pm_time_sent int NOT NULL default '0',
);

#
Expand Down
11 changes: 11 additions & 0 deletions other/upgrade_2-1_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,14 @@ if (@$modSettings['smfVersion'] < '2.1')
}
---}
---#
/******************************************************************************/
--- Altering PM reports...
/******************************************************************************/
---# Adding new columns to log_reported...
ALTER TABLE {$db_prefix}log_reported
ADD COLUMN id_pm INT(10) unsigned NOT NULL DEFAULT '0' AFTER id_board,
ADD COLUMN pm_time_sent INT unsigned NOT NULL DEFAULT '0';
---}
---#
Loading