##############################################################
## MOD Title: Report Posts
## MOD Author: wGEric < mods@best-dev.com > (Eric Faerber) http://mods.best-dev.com
## MOD Author: chatasos < chatasos@psclub.gr > (Tassos Chatzithomaoglou) http://www.psclub.gr
## MOD Description: This mod allows registered users to report posts to moderators. It adds a page where all reports can be displayed and the option to email the moderators when a report is made. Moderators can also write some comments about their actions on reported posts and full history of report actions is stored.
## MOD Version: 1.2.3c
## 
## Installation Level: Intermediate
## Installation Time: 20 minutes
## Files To Edit: admin/admin_board.php
##                includes/constants.php
##                viewtopic.php
##                includes/page_tail.php
##                language/lang_english/lang_main.php
##                templates/subSilver/admin/board_config_body.tpl
##                templates/subSilver/subSilver.cfg
##                templates/subSilver/viewtopic_body.tpl
##                templates/subSilver/overall_footer.tpl
## Included Files:
##               viewpost_reports.php
##               includes/functions_report.php
##               language/lang_english/email/report_posts.tpl
##               templates/subSilver/report_post.tpl
##               templates/subSilver/report_comment.tpl
##               templates/subSilver/reports_view.tpl
##               templates/subSilver/images/icon_report.gif
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2
##############################################################
## For security purposes, please check: http://www.phpbb.com/mods/
## for the latest version of this MOD. Although MODs are checked
## before being allowed in the MODs Database there is no guarantee
## that there are no security problems within the MOD. No support
## will be given for MODs not found within the MODs Database which
## can be found at http://www.phpbb.com/mods/
##############################################################
## Author Notes: 
##	- In the contrib folder you will find the following files:
##
##		1) put_report_CP_link_in_header.txt
##		   Contains instructions for putting the Report Control Panel link at the header instead of the footer.
##
##		2) update_102_to_123.txt
##		   Contains instructions for updating from wGEric's 1.0.2 version to 1.2.3.
##
##		3) viewtopic_body_and_other_mods.txt
##		   Contains instructions for changes in viewtopic_body.tpl when you have other mods installed that might conflict with this one.
##
##		4) report_posts_and_ch.txt
##		   Contains instructions when installing and you have CH (Categories Hierarchy) already installed
##
##	- Versions 1.2.3 (a,b,c) do not change anything since 1.2.3, so there is no need to update. You can see the history for details. 
##
##	- The original author (until 1.0.2) is wGEric. After that version, he gave me (chatasos) the permission to continue with his mod.
##
##############################################################
## MOD History:
##
##   2005-09-22 - Version 1.2.3c
##	- (There is no need to install over 1.2.3)
##	- Changed a template var in order not to mess while installing other mods in viewtopic.php
##	- Updated file "report_posts_and_ch.txt"
##
##   2005-08-30 - Version 1.2.3b
##	- (There is no need to install over 1.2.3)
##	- Changed some contrib files in order to follow mod-db guidelines
##
##   2005-08-26 - Version 1.2.3a
##	- (There is no need to install over 1.2.3)
##	- Corrected a tiny error in sql in file update_102_to_123.txt file
##	- Added instructions for avoiding conflicts in file viewtopic_body.tpl with other mods
##	- Added instructions when installing with CH already installed (not tested)
##
##   2005-08-17 - Version 1.2.3
##	- Added feature to automatically delete any leftover reports which are pointing to non-existent (deleted) posts
##	- Moved constants defined in functions_report.php into the phpbb constants.php file
##	- Moved the code for creating comments into a new function
##	- Minor changes in the main page template
##	- Added various array declarations where needed
##
##   2005-08-11 - Version 1.2.2
##	- Fixed bug where admins were getting emails although they had opted out
##	- Changed some opt-in/out sql code from "user_report_optout <> 1" to "user_report_optout = 0"
##	- Removed the "Display only" option from main page template since it wasn't needed
##	- Moved the action drop-down menu outside of the main table in main page template
##
##   2005-08-04 - Version 1.2.1
##	- Added colored link to report CP when open reports exist
##	- Optimized the code when showing reports
##	- Fixed cleanup error where reports from forums the users weren't moderators were deleted
##	- Fixed the number of reports shown at the bottom to show only the reports for the forums the users are moderators in
##	- Fixed some XHTML compliancy issues
##	- Fixed some template issues
##
##   2005-07-29 - Version 1.2.0a
##	- Fixed bug with 2 missing $lang vars
##	- Fixed bug with missing report link
##
##   2005-07-24 - Version 1.2.0
##	- (wGEric gave me the permission to continue on his mod)
##	- The moderators can write some comments when they perform an action on a single report
##	  On multiple reports selection (throught the checkbox & drop-down menu) a default comment is entered
##	- Only admins can delete the reports
##	- Users cannot report posts that are already reported
##	- Added some $lang vars in order to solve problems in specific languages (ex. Greek)
##	- Added different messages for number of open reports on report CP link
##	- Moved the report CP link outside the admin link
##	- Fixed return link (after user reports a post) so the reported post is shown instead of the topic
##	- Fixed bug when selecting action with no checkbox selected
##	- Fixed bug where the "select action" submit button was confused with "select display" submit button
##	- Fixed bug in templates where {S_ACTON} was written instead of {S_ACTION}
##	- Fixed report image size and transparency issues
##
##   2005-06-03 - Version 1.0.2
##	- Fixed message_die bug on posting screen (Thanks to the multiple people that reported this)
##	- Fixed bug where if you delete the post before the report (Thanks Mayhem)
##
##   2005-04-22 - Version 1.0.1
##	- Fixed implode bug (Thanks to the multiple people that reported this)
##	- Added flood interval (Thanks FuNEnD3R)
##	- Added language for Config page in ACP (Thanks bbcentral)
##	- Report post link displays the number of reports (Thanks Nuladion)
##
##   2005-04-12 - Version 1.0.0 
##      - First Stable release.
## 
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
##############################################################

#
#-----[ COPY ]------------------------------------------
#
copy viewpost_reports.php to viewpost_reports.php
copy includes/functions_report.php to includes/functions_report.php
copy language/lang_english/email/report_post.tpl to language/lang_english/email/report_post.tpl
copy templates/subSilver/report_post.tpl to templates/subSilver/report_post.tpl
copy templates/subSilver/report_comment.tpl to templates/subSilver/report_comment.tpl
copy templates/subSilver/reports_view.tpl to templates/subSilver/reports_view.tpl
copy templates/subSilver/images/icon_report.gif to templates/subSilver/images/icon_report.gif
#
#-----[ SQL ]------------------------------------------
#

CREATE TABLE `phpbb_post_reports` (
  `report_id` mediumint(8) NOT NULL auto_increment,
  `post_id` mediumint(8) NOT NULL default '0',
  `reporter_id` mediumint(8) NOT NULL default '0',
  `report_status` tinyint(1) NOT NULL default '0',
  `report_time` int(11) NOT NULL default '0',
  `report_comments` text,
  `last_action_user_id` mediumint(8) default '0',
  `last_action_time` int(11) NOT NULL default '0',
  `last_action_comments` text,
  PRIMARY KEY  (`report_id`)
);

ALTER TABLE phpbb_users ADD user_report_optout TINYINT( 1 ) DEFAULT '0' NOT NULL ;

INSERT INTO phpbb_config ( config_name, config_value ) VALUES ('report_email', '1');

#
#-----[ OPEN ]------------------------------------------
#
admin/admin_board.php
#
#-----[ FIND ]------------------------------------------
#
$smtp_no = ( !$new['smtp_delivery'] ) ? "checked=\"checked\"" : "";
#
#-----[ AFTER, ADD ]------------------------------------------
#
$report_email_yes = ( $new['report_email'] ) ? 'checked="checked"' : '';
$report_email_no = ( !$new['report_email'] ) ? 'checked="checked"' : '';
#
#-----[ FIND ]------------------------------------------
#
	"L_RESET" => $lang['Reset'],
#
#-----[ AFTER, ADD ]------------------------------------------
#
	'L_REPORT_EMAIL' => $lang['Report_email'],
	'REPORT_EMAIL_YES' => $report_email_yes,
	'REPORT_EMAIL_NO' => $report_email_no,
#
#-----[ OPEN ]------------------------------------------
#
includes/constants.php
#
#-----[ FIND ]------------------------------------------
#
// Table names
define('CONFIRM_TABLE', $table_prefix.'confirm');
#
#-----[ BEFORE, ADD ]------------------------------------------
#
/*******************
** MOD: Report Posts
*******************/
// BEGIN : BEFORE, ADD
// Report posts
define('REPORT_POST_NEW', 1);
define('REPORT_POST_CLOSED', 2);
// END : BEFORE, ADD

#
#-----[ FIND ]------------------------------------------
#
define('VOTE_USERS_TABLE', $table_prefix.'vote_voters');
#
#-----[ AFTER, ADD ]------------------------------------------
#
/*******************
** MOD: Report Posts
*******************/
// BEGIN : AFTER, ADD
define('POST_REPORTS_TABLE', $table_prefix.'post_reports');
// END : AFTER, ADD
#
#-----[ OPEN ]------------------------------------------
#
viewtopic.php
#
#-----[ FIND ]------------------------------------------
#
if( $userdata['session_logged_in'] )
{
#
#-----[ AFTER, ADD ]------------------------------------------
#
	/*******************
	** MOD: Report Posts
	*******************/
	// BEGIN : AFTER, ADD
	if ( isset($HTTP_GET_VARS['report']) || isset($HTTP_POST_VARS['report']) )
	{
		include($phpbb_root_path . 'includes/functions_report.'.$phpEx);

		// check if the post has already been reported
		if ( report_exists($post_id) )
		{
			$template->assign_vars(array(
				'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id") . '">')
			);
			
			$message = $lang['Post_already_reported'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id") . '">', '</a>');
			message_die(GENERAL_MESSAGE, $message);
		}

		$comments = ( !empty($HTTP_POST_VARS['comments']) ) ? htmlspecialchars(trim($HTTP_POST_VARS['comments'])) : '';

		if ( empty($comments) )
		{
			// show form to add comments about topic
			$page_title = $lang['Report_post'] . ' - ' . $topic_title;
			include($phpbb_root_path . 'includes/page_header.'.$phpEx);

			$template->set_filenames(array(
				'report_post' => 'report_post.tpl')
			);

			$template->assign_vars(array(
				'TOPIC_TITLE'	=> $topic_title,
				'POST_ID'		=> $post_id,
				'U_VIEW_TOPIC'	=> append_sid($phpbb_root_path . 'viewtopic.'.$phpEx.'?' . POST_TOPIC_URL . '=' . $topic_id),

				'L_REPORT_POST'	=> $lang['Report_post'],
				'L_COMMENTS'	=> $lang['Comments'],
				'L_COMMENTS_EXPLAIN'	=> $lang['Comments_explain'],

				'L_SUBMIT'		=> $lang['Submit'],

				'S_ACTION'		=> append_sid($phpbb_root_path . 'viewtopic.'.$phpEx.'?report=true&amp;' . POST_POST_URL . '=' . $post_id))
			);

			$template->pparse('report_post');

			include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
			exit;
		}
		else
		{
			if ( !report_flood() )
			{
				message_die(GENERAL_MESSAGE, $lang['Flood_Error']);
			}
			
			// insert the report
			insert_report($post_id, $comments);

			// email the report if need to
			if ( $board_config['report_email'] )
			{
				email_report($forum_id, $post_id, $topic_title, $comments);
			}
	
			$template->assign_vars(array(
				'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id") . '">')
			);
			$message = $lang['Post_reported'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id") . '">', '</a>');
			message_die(GENERAL_MESSAGE, $message);
		}
	}
	// END : AFTER, ADD
#
#-----[ FIND ]------------------------------------------
#
	$template->assign_block_vars('postrow', array(
#
#-----[ BEFORE, ADD ]------------------------------------------
#
	/*******************
	** MOD: Report Posts
	*******************/
	// BEGIN : BEFORE, ADD
	if ( $userdata['session_logged_in'] )
	{
		$report_img = '<a href="' . append_sid($phpbb_root_path . 'viewtopic.'.$phpEx.'?report=true&amp;' . POST_POST_URL . '=' . $postrow[$i]['post_id']) . '"><img src="' . $images['icon_report'] . '" border="0" alt="' . $lang['Report_post'] . '" title="' . $lang['Report_post'] . '" /></a>';
	}
	else
	{
		$report_img = '';
	}
	// END : BEFORE, ADD
#
#-----[ AFTER, ADD ]------------------------------------------
#
		/*******************
		** MOD: Report Posts
		*******************/
		// BEGIN : AFTER, ADD
		'REPORT_IMG'	=> $report_img,
		// END : AFTER, ADD
#
#-----[ OPEN ]------------------------------------------
#
includes/page_tail.php
#
#-----[ FIND ]------------------------------------------
#
$admin_link = ( $userdata['user_level'] == ADMIN ) ? '<a href="admin/index.' . $phpEx . '?sid=' . $userdata['session_id'] . '">' . $lang['Admin_panel'] . '</a><br /><br />' : '';
#
#-----[ AFTER, ADD ]------------------------------------------
#
/*******************
** MOD: Report Posts
*******************/
// BEGIN : AFTER, ADD
include_once($phpbb_root_path . 'includes/functions_report.'.$phpEx);

if ( $userdata['user_level'] >= ADMIN )
{
	$open_reports = reports_count();
	if ( $open_reports == 0 )
	{
		$open_reports = sprintf($lang['Post_reports_none_cp'],$open_reports);
	}
	else 
	{
		$open_reports = sprintf(( ($open_reports == 1) ? $lang['Post_reports_one_cp'] : $lang['Post_reports_many_cp']), $open_reports);
		$open_reports = '<b style="color:#' . $theme['fontcolor2'] . '">' . $open_reports . '</b>';
	}

	$report_link = '&nbsp; <a href="' . append_sid($phpbb_root_path . 'viewpost_reports.'.$phpEx) . '">' . $open_reports . '</a> &nbsp;';
}
else
{
	$report_link = '';
}
// END : AFTER, ADD
#
#-----[ FIND ]------------------------------------------
#
	'ADMIN_LINK' => $admin_link)
#
#-----[ BEFORE, ADD ]------------------------------------------
#
/*******************
** MOD: Report Posts
*******************/
// BEGIN : BEFORE, ADD
	'REPORT_LINK' => $report_link,
// END : BEFORE, ADD
#
#-----[ OPEN ]------------------------------------------
#
language/lang_english/lang_main.php
#
#-----[ FIND ]------------------------------------------
#
//
// That's all, Folks!
#
#-----[ BEFORE, ADD ]------------------------------------------
#

/*******************
** MOD: Report Posts
*******************/
// BEGIN : BEFORE, ADD
$lang['Post_reports_none_cp'] = 'There aren\'t any open Reported Posts';
$lang['Post_reports_one_cp'] = 'There is %s open Reported Post';
$lang['Post_reports_many_cp'] = 'There are %s open Reported Posts';

$lang['All'] = 'All';
$lang['Display'] = 'Display only';
$lang['Report_post'] = 'Report Post';

$lang['Reporter'] = 'Reporter';
$lang['Status'] = 'Status';
$lang['Select_one'] = 'Select One';

$lang['Opt_in'] = 'Opt in to receive emails when a report is submitted';
$lang['Opt_out'] = 'Opt out so you don\'t receive emails when a report is submitted';

$lang['Post_reported'] = 'Post report submitted successfully.';
$lang['Close_success'] = 'Reports were Opened/Closed successfully.';
$lang['Opt_success'] = 'You have opt out/in successfully.';
$lang['Delete_success'] = 'Reports were deleted successfully.';
$lang['Click_return_reports'] = 'Click %shere%s to return to the Report Posts control panel.';
$lang['Report_email'] = 'Send Email when Post Reported';

$lang['Post_already_reported'] = 'This post has already been reported.';

$lang['Report_not_selected'] = 'You haven\'t selected any reports.';

$lang['Comments'] = 'Comments';
$lang['Last_action_comments'] = 'Comments from Moderators';
$lang['Last_action_comments_explain'] = 'Please write some comments about your action on this specific report';
$lang['Comments_explain'] = 'Please write some comments about your report on this specific post.';

$lang['Action'] = 'Action';
$lang['Report_comment'] = 'Comments regarding your action';
$lang['Previous_comments'] = 'Previous comments';

$lang['Last_action_checkbox'] = 'This action was done through the checkbox and drop down menu.';

$lang['Opened_by_user_on_date'] = 'Opened by %s on %s';
$lang['Closed_by_user_on_date'] = 'Closed by %s on %s';
$lang['Opened'] = 'Open';
$lang['Closed'] = 'Closed';
$lang['Open'] = 'Open';
$lang['Close'] = 'Close';

$lang['Non_existent_posts'] = 'Found and deleted %s leftover report(s) pointing to non-existent (deleted) posts';
// END : BEFORE, ADD

#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/admin/board_config_body.tpl
#
#-----[ FIND ]------------------------------------------
#
	<tr>
		<td class="row1">{L_ENABLE_PRUNE}</td>
		<td class="row2"><input type="radio" name="prune_enable" value="1" {PRUNE_YES} /> {L_YES}&nbsp;&nbsp;<input type="radio" name="prune_enable" value="0" {PRUNE_NO} /> {L_NO}</td>
	</tr>
#
#-----[ AFTER, ADD ]------------------------------------------
#
	<tr>
		<td class="row1">{L_REPORT_EMAIL}</td>
		<td class="row2"><input type="radio" name="report_email" value="1" {REPORT_EMAIL_YES} /> {L_YES}&nbsp;&nbsp;<input type="radio" name="report_email" value="0" {REPORT_EMAIL_NO} /> {L_NO}</td>
	</tr>
#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/subSilver.cfg
#
#-----[ FIND ]------------------------------------------
#
$images['voting_graphic'][4] = "$current_template_images/voting_bar.gif";
#
#-----[ AFTER, ADD ]------------------------------------------
#
$images['icon_report']	= "$current_template_images/icon_report.gif";
#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/viewtopic_body.tpl
#
#-----[ FIND ]------------------------------------------
#
				<td valign="top" nowrap="nowrap">{postrow.QUOTE_IMG} {postrow.EDIT_IMG} {postrow.DELETE_IMG} {postrow.IP_IMG}</td>
#
#-----[ IN-LINE FIND ]------------------------------------------
#
{postrow.IP_IMG}
#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
 {postrow.REPORT_IMG}
#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/overall_footer.tpl
#
#-----[ FIND ]------------------------------------------
#
<div align="center"><span class="copyright"><br />{ADMIN_LINK}<br />
#
#-----[ IN-LINE FIND ]------------------------------------------
#
{ADMIN_LINK}
#
#-----[ IN-LINE BEFORE, ADD ]------------------------------------------
#
{REPORT_LINK}<br /><br />
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM


