r775: Implementing the comment API
[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 require_once('./includes/api_comment.php');
32
33 $comment = $db->query_first("
34 SELECT comment.*, user.email, user.showemail, user.displayname
35 FROM " . TABLE_PREFIX . "comment AS comment
36 LEFT JOIN " . TABLE_PREFIX . "user AS user
37 ON (comment.userid = user.userid)
38 WHERE comment.commentid = " . intval($bugsys->in['commentid'])
39 );
40
41 if (!$comment)
42 {
43 $message->error($lang->getlex('error_invalid_id'));
44 }
45
46 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $comment[bugid]");
47
48 if (!((can_perform('caneditownreply', $bug['productid']) AND $bugsys->userinfo['userid'] == $comment['userid']) OR (can_perform('caneditotherreply', $bug['productid']) AND $bugsys->userinfo['userid'] != $comment['userid'])))
49 {
50 $message->error_permission();
51 }
52
53 if ($bug['hidden'] AND !can_perform('canviewhidden', $bug['productid']))
54 {
55 $message->error_permissison();
56 }
57
58 // ###################################################################
59
60 if (empty($_REQUEST['do']))
61 {
62 $_REQUEST['do'] = 'edit';
63 }
64
65 // ###################################################################
66
67 if ($_POST['do'] == 'update')
68 {
69 $commentapi = new CommentAPI($bugsys);
70 $commentapi->set('commentid', $bugsys->in['commentid']);
71 $commentapi->set_condition();
72 $commentapi->set('comment', $bugsys->in['comment']);
73 $commentapi->set('hidden', $bugsys->in['hidden']);
74
75 if ($bugsys->in['commentid'] == $bug['initialreport'] AND $bugsys->in['hidden'])
76 {
77 $message->items[] = $lang->string('You cannot hide the first comment/initial report of a bug. Instead, hide the entire bug.');
78 }
79
80 if (!$message->items)
81 {
82 $commentapi->update();
83
84 // setup logging
85 require_once('./includes/class_history.php');
86 $log = new History();
87 $log->bugid = $bug['bugid'];
88 $log->commentid = $comment['commentid'];
89 $log->log($log->diff('comment ' . $comment['commentid'] . ' text', $comment['comment_parsed'], nl2br($bugsys->in['comment_parsed'])));
90 $log->log($log->diff('comment ' . $comment['commentid'] . ' hidden', $comment['hidden'], intval($bugsys->in['hidden'])));
91
92 $lastgood = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] AND !hidden ORDER BY dateline DESC");
93 $db->query("
94 UPDATE " . TABLE_PREFIX . "bug
95 SET hiddenlastposttime = $lastgood[dateline],
96 hiddenlastpostby = $lastgood[userid]
97 WHERE bugid = $bug[bugid]"
98 );
99
100 $message->redirect($lang->string('The comment was modified successfully.'), "showreport.php?bugid=$bug[bugid]");
101 }
102 else
103 {
104 $show['errors'] = true;
105 $_REQUEST['do'] = 'edit';
106 $message->error_list_process();
107 $comment['comment'] = $bugsys->in['comment'];
108 $comment['hidden'] = $bugsys->in['hidden'];
109 }
110 }
111
112 // ###################################################################
113
114 if ($_REQUEST['do'] == 'edit')
115 {
116 $comment['posttime'] = $datef->format($bugsys->options['dateformat'], $comment['dateline']);
117 $comment['postby'] = construct_user_display($comment);
118 $comment['comment'] = $bugsys->sanitize($comment['comment']);
119 $show['hide'] = ($bug['initialreport'] != $comment['commentid'] ? true : false);
120 eval('$template->flush("' . $template->fetch('editcomment') . '");');
121 }
122
123 /*=====================================================================*\
124 || ###################################################################
125 || # $HeadURL$
126 || # $Id$
127 || ###################################################################
128 \*=====================================================================*/
129 ?>