r765: Say hello to the GPL
[bugdar.git] / editcomment.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 $fetchtemplates = array(
23 'editcomment'
24 );
25
26 define('SVN', '$Id$');
27
28 $focus['showreport'] = 'focus';
29
30 require_once('./global.php');
31
32 $comment = $db->query_first("
33 SELECT comment.*, user.email, user.showemail, user.displayname
34 FROM " . TABLE_PREFIX . "comment AS comment
35 LEFT JOIN " . TABLE_PREFIX . "user AS user
36 ON (comment.userid = user.userid)
37 WHERE comment.commentid = " . intval($bugsys->in['commentid'])
38 );
39
40 if (!$comment)
41 {
42 $message->error($lang->getlex('error_invalid_id'));
43 }
44
45 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $comment[bugid]");
46
47 if (!((can_perform('caneditownreply', $bug['productid']) AND $bugsys->userinfo['userid'] == $comment['userid']) OR (can_perform('caneditotherreply', $bug['productid']) AND $bugsys->userinfo['userid'] != $comment['userid'])))
48 {
49 $message->error_permission();
50 }
51
52 if ($bug['hidden'] AND !can_perform('canviewhidden', $bug['productid']))
53 {
54 $message->error_permissison();
55 }
56
57 // ###################################################################
58
59 if (empty($_REQUEST['do']))
60 {
61 $_REQUEST['do'] = 'edit';
62 }
63
64 // ###################################################################
65
66 if ($_POST['do'] == 'update')
67 {
68 if (!$bugsys->in['comment'])
69 {
70 $message->items[] = $lang->string('You need to enter text into the comment field');
71 }
72
73 if ($bugsys->in['commentid'] == $bug['initialreport'] AND $bugsys->in['hidden'])
74 {
75 $message->items[] = $lang->string('You cannot hide the first comment/initial report of a bug. Instead, hide the entire bug.');
76 }
77
78 if (!$message->items)
79 {
80 $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
81
82 if (!$bugsys->options['allowhtml'])
83 {
84 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
85 }
86
87 $db->query("
88 UPDATE " . TABLE_PREFIX . "comment
89 SET comment = '" . $bugsys->in['comment'] . "',
90 comment_parsed = '" . nl2br($bugsys->in['comment_parsed']) . "',
91 hidden = " . intval($bugsys->in['hidden']) . "
92 WHERE commentid = $comment[commentid]"
93 );
94
95 // setup logging
96 require_once('./includes/class_history.php');
97 $log = new History();
98 $log->bugid = $bug['bugid'];
99 $log->commentid = $comment['commentid'];
100 $log->log($log->diff('comment ' . $comment['commentid'] . ' text', $comment['comment_parsed'], nl2br($bugsys->in['comment_parsed'])));
101 $log->log($log->diff('comment ' . $comment['commentid'] . ' hidden', $comment['hidden'], intval($bugsys->in['hidden'])));
102
103 $lastgood = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] AND !hidden ORDER BY dateline DESC");
104 $db->query("
105 UPDATE " . TABLE_PREFIX . "bug
106 SET hiddenlastposttime = $lastgood[dateline],
107 hiddenlastpostby = $lastgood[userid]
108 WHERE bugid = $bug[bugid]"
109 );
110
111 $message->redirect($lang->string('The comment was modified successfully.'), "showreport.php?bugid=$bug[bugid]");
112 }
113 else
114 {
115 $show['errors'] = true;
116 $_REQUEST['do'] = 'edit';
117 $message->error_list_process();
118 $comment['comment'] = $bugsys->in['comment'];
119 $comment['hidden'] = $bugsys->in['hidden'];
120 }
121 }
122
123 // ###################################################################
124
125 if ($_REQUEST['do'] == 'edit')
126 {
127 $comment['posttime'] = $datef->format($bugsys->options['dateformat'], $comment['dateline']);
128 $comment['postby'] = construct_user_display($comment);
129 $comment['comment'] = $bugsys->sanitize($comment['comment']);
130 $show['hide'] = ($bug['initialreport'] != $comment['commentid'] ? true : false);
131 eval('$template->flush("' . $template->fetch('editcomment') . '");');
132 }
133
134 /*=====================================================================*\
135 || ###################################################################
136 || # $HeadURL$
137 || # $Id$
138 || ###################################################################
139 \*=====================================================================*/
140 ?>