From 961ba4f001fe0af7f91b93757cb27364eb1092df Mon Sep 17 00:00:00 2001
From: Ludovic Arnaud <ludovic_arnaud@users.sourceforge.net>
Date: Sun, 18 May 2003 22:26:18 +0000
Subject: [PATCH] Fixed: some stuff ;) Changed: users cannot report the same
 post twice. if an user tries to, s/he's invited to edit his/her report

git-svn-id: file:///svn/phpbb/trunk@4012 89ea8834-ac86-4346-8a33-228a782c2dd0
---
 phpBB/report.php                           | 68 +++++++++++++++++++---
 phpBB/templates/subSilver/report_body.html |  8 +--
 2 files changed, 62 insertions(+), 14 deletions(-)

diff --git a/phpBB/report.php b/phpBB/report.php
index b9f10a52ef..a37190cec0 100644
--- a/phpBB/report.php
+++ b/phpBB/report.php
@@ -35,7 +35,8 @@ $post_id = (!empty($_REQUEST['p'])) ? intval($_REQUEST['p']) : 0;
 $reason_id = (!empty($_REQUEST['reason_id'])) ? intval($_REQUEST['reason_id']) : 0;
 $notify = (!empty($_REQUEST['notify']) && $user->data['user_id'] != ANONYMOUS) ? TRUE : FALSE;
 $description = (!empty($_REQUEST['description'])) ? stripslashes($_REQUEST['description']) : '';
-
+$report_id = (!empty($_REQUEST['report_id'])) ? intval($_REQUEST['report_id']) : 0;
+$report_text = '';
 
 // Has the report been cancelled?
 if (isset($_POST['cancel']))
@@ -72,6 +73,40 @@ foreach ($acl_check_ary as $acl => $error)
 }
 unset($acl_check_ary);
 
+// Check if the user has already reported this post
+if ($user->data['user_id'] != ANONYMOUS)
+{
+	$result = $db->sql_query('SELECT * FROM ' . REPORTS_TABLE . " WHERE post_id = $post_id AND user_id = " . $user->data['user_id']);
+
+	if ($row = $db->sql_fetchrow($result))
+	{
+		if ($report_id)
+		{
+			if ($user->data['user_id'] == $row['user_id'])
+			{
+				$report_text = $row['report_text'];
+			}
+			else
+			{
+				$report_id = 0;
+			}
+		}
+		else
+		{
+			$report_id = intval($row['report_id']);
+			$reason_id = intval($row['reason_id']);
+
+			$return_topic = '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], "<a href=\"viewtopic.$phpEx$SID&amp;p=$post_id#$post_id\">", '</a>');
+			$return_report = '<br /><br />' . sprintf($user->lang['EDIT_REPORT'], "<a href=\"report.$phpEx$SID&amp;report_id=$report_id&amp;reason_id=$reason_id&amp;p=$post_id\">", '</a>');
+
+			trigger_error($user->lang['ALREADY_REPORTED'] . $return_report . $return_topic);
+		}
+	}
+}
+else
+{
+	$report_id = 0;
+}
 
 // Has the report been confirmed?
 if (!empty($_POST['reason_id']))
@@ -90,15 +125,25 @@ if (!empty($_POST['reason_id']))
 	$sql_ary = array(
 		'reason_id'		=>	(int) $reason_id,
 		'post_id'		=>	(int) $post_id,
-		'user_id'		=>	(int) $user->user_id,
+		'user_id'		=>	(int) $user->data['user_id'],
 		'user_notify'	=>	(int) $notify,
 		'report_time'	=>	(int) time(),
 		'report_text'	=>	(string) $description
 	);
 
-	$sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . 
-		$db->sql_build_array('INSERT', $sql_ary);
-	$db->sql_query($sql);
+	if ($report_id)
+	{
+		$sql = 'UPDATE ' . REPORTS_TABLE . '
+			SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
+			WHERE report_id = ' . $report_id;
+		$db->sql_query($sql);
+	}
+	else
+	{
+		$sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . 
+			$db->sql_build_array('INSERT', $sql_ary);
+		$db->sql_query($sql);
+	}
 
 	if (!$row['post_reported'])
 	{
@@ -142,11 +187,16 @@ while ($row = $db->sql_fetchrow($result))
 	$template->assign_block_vars('reason', array(
 		'ID'			=>	$row['reason_id'],
 		'NAME'			=>	htmlspecialchars($reason_name),
-		'DESCRIPTION'	=>	htmlspecialchars($reason_description))
-	);
+		'DESCRIPTION'	=>	htmlspecialchars($reason_description),
+		'S_SELECTED'	=>	($row['reason_id'] == $reason_id) ? TRUE : FALSE
+	));
 }
 
-$template->assign_var('S_CAN_NOTIFY', ($user->data['user_id'] == ANONYMOUS) ? FALSE : TRUE);
+$template->assign_vars(array(
+	'REPORT_TEXT'		=>	htmlspecialchars($report_text),
+	'S_REPORT_ACTION'	=>	"report.$phpEx$SID&amp;p=$post_id" . (($report_id) ? "&amp;report_id=$report_id" : ''),
+	'S_CAN_NOTIFY'		=>	($user->data['user_id'] == ANONYMOUS) ? FALSE : TRUE
+));
 
 
 generate_forum_nav($forum_data);
@@ -159,6 +209,6 @@ $template->set_filenames(array(
 	'body' => 'report_body.html')
 );
 
-page_tail();
+page_footer();
 
 ?>
\ No newline at end of file
diff --git a/phpBB/templates/subSilver/report_body.html b/phpBB/templates/subSilver/report_body.html
index e38baa303e..21a8e5a42e 100644
--- a/phpBB/templates/subSilver/report_body.html
+++ b/phpBB/templates/subSilver/report_body.html
@@ -1,8 +1,6 @@
 <!-- INCLUDE overall_header.html -->
 
-<form action="{S_POST_ACTION}" name="main" method="post">
-
-{ERROR_BOX}
+<form action="{S_REPORT_ACTION}" name="main" method="post">
 
 <table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
 	<tr>
@@ -19,7 +17,7 @@
 	</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}">{reason.DESCRIPTION}</option><!-- END reason --></select></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>
@@ -29,7 +27,7 @@
 	<!-- ENDIF -->
 	<tr>
 		<td class="row1" valign="top"><span class="gen"><b>{L_MORE_INFO}:</b></span><br /><span class="gensmall">{L_CAN_LEAVE_BLANK}</span></td>
-		<td class="row2"><textarea class="post" style="width:500px" name="description" rows="25" cols="40"  class="post">{MESSAGE}</textarea></td>
+		<td class="row2"><textarea class="post" style="width:500px" name="description" rows="25" cols="40"  class="post">{REPORT_TEXT}</textarea></td>
 	</tr>
 	<tr>
 		<td class="cat" colspan="2" align="center" height="28"><input type="submit" name="submit" class="mainoption" value="{L_SUBMIT}" />&nbsp;<input type="submit" name="cancel" class="liteoption" value="{L_CANCEL}"></td>