r722: Error box for edit comment
[bugdar.git] / editcomment.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Bugdar [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 $fetchtemplates = array(
14 'editcomment'
15 );
16
17 define('SVN', '$Id$');
18
19 $focus['showreport'] = 'focus';
20
21 require_once('./global.php');
22
23 $comment = $db->query_first("
24 SELECT comment.*, user.email, user.showemail, user.displayname
25 FROM " . TABLE_PREFIX . "comment AS comment
26 LEFT JOIN " . TABLE_PREFIX . "user AS user
27 ON (comment.userid = user.userid)
28 WHERE comment.commentid = " . intval($bugsys->in['commentid'])
29 );
30
31 if (!$comment)
32 {
33 $message->error($lang->getlex('error_invalid_id'));
34 }
35
36 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $comment[bugid]");
37
38 if (!((can_perform('caneditownreply', $bug['productid']) AND $bugsys->userinfo['userid'] == $comment['userid']) OR (can_perform('caneditotherreply', $bug['productid']) AND $bugsys->userinfo['userid'] != $comment['userid'])))
39 {
40 $message->error_permission();
41 }
42
43 if ($bug['hidden'] AND !can_perform('canviewhidden', $bug['productid']))
44 {
45 $message->error_permissison();
46 }
47
48 // ###################################################################
49
50 if (empty($_REQUEST['do']))
51 {
52 $_REQUEST['do'] = 'edit';
53 }
54
55 // ###################################################################
56
57 if ($_POST['do'] == 'update')
58 {
59 if (!$bugsys->in['comment'])
60 {
61 $message->items[] = $lang->string('You need to enter text into the comment field');
62 }
63
64 if ($bugsys->in['commentid'] == $bug['initialreport'] AND $bugsys->in['hidden'])
65 {
66 $message->items[] = $lang->string('You cannot hide the first comment/initial report of a bug. Instead, hide the entire bug.');
67 }
68
69 if (!$message->items)
70 {
71 $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
72
73 if (!$bugsys->options['allowhtml'])
74 {
75 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
76 }
77
78 $db->query("
79 UPDATE " . TABLE_PREFIX . "comment
80 SET comment = '" . $bugsys->in['comment'] . "',
81 comment_parsed = '" . nl2br($bugsys->in['comment_parsed']) . "',
82 hidden = " . intval($bugsys->in['hidden']) . "
83 WHERE commentid = $comment[commentid]"
84 );
85
86 // setup logging
87 require_once('./includes/class_history.php');
88 $log = new History();
89 $log->bugid = $bug['bugid'];
90 $log->commentid = $comment['commentid'];
91 $log->log($log->diff('comment ' . $comment['commentid'] . ' text', $comment['comment_parsed'], nl2br($bugsys->in['comment_parsed'])));
92 $log->log($log->diff('comment ' . $comment['commentid'] . ' hidden', $comment['hidden'], intval($bugsys->in['hidden'])));
93
94 $lastgood = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] AND !hidden ORDER BY dateline DESC");
95 $db->query("
96 UPDATE " . TABLE_PREFIX . "bug
97 SET hiddenlastposttime = $lastgood[dateline],
98 hiddenlastpostby = $lastgood[userid]
99 WHERE bugid = $bug[bugid]"
100 );
101
102 $message->redirect($lang->string('The comment was modified successfully.'), "showreport.php?bugid=$bug[bugid]");
103 }
104 else
105 {
106 $show['errors'] = true;
107 $_REQUEST['do'] = 'edit';
108 $message->error_list_process();
109 $comment['comment'] = $bugsys->in['comment'];
110 $comment['hidden'] = $bugsys->in['hidden'];
111 }
112 }
113
114 // ###################################################################
115
116 if ($_REQUEST['do'] == 'edit')
117 {
118 $comment['posttime'] = $datef->format($bugsys->options['dateformat'], $comment['dateline']);
119 $comment['postby'] = construct_user_display($comment);
120 $comment['comment'] = $bugsys->sanitize($comment['comment']);
121 $show['hide'] = ($bug['initialreport'] != $comment['commentid'] ? true : false);
122 eval('$template->flush("' . $template->fetch('editcomment') . '");');
123 }
124
125 /*=====================================================================*\
126 || ###################################################################
127 || # $HeadURL$
128 || # $Id$
129 || ###################################################################
130 \*=====================================================================*/
131 ?>