2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright ©2002-2007 Blue Static
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 2 of the License.
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
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 \*=====================================================================*/
22 $fetchtemplates = array(
26 define('SVN', '$Id$');
28 $focus['showreport
'] = 'focus
';
30 require_once('./global.php
');
31 require_once('./includes
/api_comment
.php
');
33 require_once('./includes
/class_api_error
.php
');
35 $commentapi = new CommentAPI();
36 $commentapi->set('commentid
', $input->in['commentid
']);
39 $comment = &$commentapi->record;
41 $bug = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $comment[bugid]");
43 if (!check_bug_permissions($bug))
45 $message->errorPermission();
48 // ###################################################################
50 if (empty($_REQUEST['do']))
52 $_REQUEST['do'] = 'edit
';
55 // ###################################################################
57 if ($_POST['do'] == 'kill
')
59 if (!can_perform('candeletedata
', $bug['product
']))
61 $message->errorPermission();
64 // get the last post (as in prior to deletion)
65 $lastpost = $db->queryFirst("SELECT commentid FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline DESC");
67 $commentapi->remove();
69 // check to see if we need to rebuild the lastpost information
70 if ($lastpost['commentid
'] == $comment['commentid
'])
72 $lastgoodpublic = $db->queryFirst("
73 SELECT comment.* AS comment, user.displayname AS username
74 FROM " . TABLE_PREFIX . "comment AS comment
75 LEFT JOIN " . TABLE_PREFIX . "user AS user
76 ON (user.userid = comment.userid)
77 WHERE bugid = $bug[bugid]
78 AND !hidden ORDER BY dateline DESC
80 $lastgoodprivate = $db->queryFirst("
81 SELECT comment.* AS comment, user.displayname AS username
82 FROM " . TABLE_PREFIX . "comment AS comment
83 LEFT JOIN " . TABLE_PREFIX . "user AS user
84 ON (user.userid = comment.userid)
85 WHERE bugid = $bug[bugid]
86 ORDER BY dateline DESC
89 UPDATE " . TABLE_PREFIX . "bug
90 SET hiddenlastposttime = $lastgoodpublic[dateline],
91 hiddenlastpostby = $lastgoodpublic[userid],
92 hiddenlastpostbyname = '" . $db->escapeString($lastgoodpublic['username']) . "',
93 lastposttime = $lastgoodprivate[dateline],
94 lastpostby = $lastgoodprivate[userid],
95 lastpostbyname = '" . $db->escapeString($lastgoodprivate['username']) . "'
96 WHERE bugid = $bug[bugid]"
100 $message->redirect(T('The comment has been deleted
. You will be redirected back to the bug
.'), 'showreport
.php
?bugid
=' . $bug['bugid
']);
103 // ###################################################################
105 if ($_REQUEST['do'] == 'delete
')
107 if (!can_perform('candeletedata
', $bug['product
']))
109 $message->errorPermission();
112 if ($bug['initialreport
'] == $comment['commentid
'])
114 $message->error(T('You cannot delete this comment because it is attached to the bug
as the first comment
. You have to delete the entire bug
instead (which is not recommended unless it is spam
).'));
117 $message->confirm(T('Are you sure you want to delete this comment
? After you
do so
, the data
<strong
>will
</strong
> be lost forever
. We recommend only deleting spam comments
and nothing
else.'), 'editcomment
.php
', 'kill
', T('Delete Comment
'), 'showreport
.php
?bugid
=' . $bug['bugid
'], array('commentid
' => $comment['commentid
']));
120 // ###################################################################
122 if ($_POST['do'] == 'update
')
124 if (!((can_perform('caneditownreply
', $bug['product
']) AND bugdar::$userinfo['userid
'] == $comment['userid
']) OR (can_perform('caneditotherreply
', $bug['product
']) AND bugdar::$userinfo['userid
'] != $comment['userid
'])))
126 $message->errorPermission();
129 $commentapi->set('comment
', $input->in['comment
']);
130 $commentapi->set('parselinks
', $input->in['parselinks
']);
131 $commentapi->set('hidden
', $input->in['hidden
']);
133 if ($input->in['commentid
'] == $bug['initialreport
'] AND $input->in['hidden
'])
135 $message->addError(T('You cannot hide the first comment
/initial report of a bug
. Instead
, hide the entire bug
.'));
138 if (!$message->hasErrors())
140 $commentapi->update();
143 require_once('./includes
/class_logging
.php
');
145 $log->set_bugid($bug['bugid
']);
146 $log->set_commentid($comment['commentid
']);
148 $log->add_data(true, $commentapi->record, array('comment
', 'hidden
'), false, 'comment
');
149 $log->add_data(false, $commentapi->values, array('comment
', 'hidden
'), false, 'comment
');
151 $lastgood = $db->queryFirst("
152 SELECT comment.* AS comment, user.displayname AS username
153 FROM " . TABLE_PREFIX . "comment AS comment
154 LEFT JOIN " . TABLE_PREFIX . "user AS user
155 ON (user.userid = comment.userid)
156 WHERE bugid = $bug[bugid]
157 AND !hidden ORDER BY dateline DESC
160 UPDATE " . TABLE_PREFIX . "bug
161 SET hiddenlastposttime = $lastgood[dateline],
162 hiddenlastpostby = $lastgood[userid],
163 hiddenlastpostbyname = '" . $db->escapeString($lastgood['username']) . "'
164 WHERE bugid = $bug[bugid]"
167 $log->update_history();
169 $message->redirect(T('The comment was modified successfully
.'), "showreport.php?bugid=$bug[bugid]");
173 $show['errors
'] = true;
174 $_REQUEST['do'] = 'edit
';
175 $comment['comment
'] = $input->in['comment
'];
176 $comment['hidden
'] = $input->in['hidden
'];
180 // ###################################################################
182 if ($_REQUEST['do'] == 'edit
')
184 if (!((can_perform('caneditownreply
', $bug['product
']) AND bugdar::$userinfo['userid
'] == $comment['userid
']) OR (can_perform('caneditotherreply
', $bug['product
']) AND bugdar::$userinfo['userid
'] != $comment['userid
'])))
186 $message->errorPermission();
189 $comment['posttime
'] = $datef->format(bugdar::$options['dateformat
'], $comment['dateline
']);
190 if ($comment['userid
'])
192 $commenter = new UserAPI();
193 $commenter->set('userid
', $comment['userid
']);
195 $commenter = $commenter->record;
197 $comment['postby
'] = construct_user_display($commenter);
198 $comment['comment
'] = $input->sanitize($comment['comment
']);
199 $show['hide
'] = ($bug['initialreport
'] != $comment['commentid
']);
201 $tpl = new BSTemplate('editcomment
');
203 'comment
' => $comment,
206 $tpl->evaluate()->flush();
209 /*=====================================================================*\
210 || ###################################################################
213 || ###################################################################
214 \*=====================================================================*/