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
');
34 APIError(array(new API_Error_Handler($message), 'user_cumulative
'));
36 $commentapi = new CommentAPI($bugsys);
37 $commentapi->set('commentid
', $input->in['commentid
']);
38 $commentapi->set_condition();
41 $comment =& $commentapi->record;
43 $bug = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $comment[bugid]");
45 if (!check_bug_permissions($bug))
47 $message->errorPermission();
50 // ###################################################################
52 if (empty($_REQUEST['do']))
54 $_REQUEST['do'] = 'edit
';
57 // ###################################################################
59 if ($_POST['do'] == 'kill
')
61 if (!can_perform('candeletedata
', $bug['product
']))
63 $message->errorPermission();
66 // get the last post (as in prior to deletion)
67 $lastpost = $db->queryFirst("SELECT commentid FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline DESC");
69 $commentapi->delete();
71 // check to see if we need to rebuild the lastpost information
72 if ($lastpost['commentid
'] == $comment['commentid
'])
74 $lastgoodpublic = $db->queryFirst("
75 SELECT comment.* AS comment, user.displayname AS username
76 FROM " . TABLE_PREFIX . "comment AS comment
77 LEFT JOIN " . TABLE_PREFIX . "user AS user
78 ON (user.userid = comment.userid)
79 WHERE bugid = $bug[bugid]
80 AND !hidden ORDER BY dateline DESC
82 $lastgoodprivate = $db->queryFirst("
83 SELECT comment.* AS comment, user.displayname AS username
84 FROM " . TABLE_PREFIX . "comment AS comment
85 LEFT JOIN " . TABLE_PREFIX . "user AS user
86 ON (user.userid = comment.userid)
87 WHERE bugid = $bug[bugid]
88 ORDER BY dateline DESC
91 UPDATE " . TABLE_PREFIX . "bug
92 SET hiddenlastposttime = $lastgoodpublic[dateline],
93 hiddenlastpostby = $lastgoodpublic[userid],
94 hiddenlastpostbyname = '" . $db->escape_string($lastgoodpublic['username']) . "',
95 lastposttime = $lastgoodprivate[dateline],
96 lastpostby = $lastgoodprivate[userid],
97 lastpostbyname = '" . $db->escape_string($lastgoodprivate['username']) . "'
98 WHERE bugid = $bug[bugid]"
102 $message->redirect(T('The comment has been deleted
. You will be redirected back to the bug
.'), 'showreport
.php
?bugid
=' . $bug['bugid
']);
105 // ###################################################################
107 if ($_REQUEST['do'] == 'delete
')
109 if (!can_perform('candeletedata
', $bug['product
']))
111 $message->errorPermission();
114 if ($bug['initialreport
'] == $comment['commentid
'])
116 $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
).'));
119 $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
']));
122 // ###################################################################
124 if ($_POST['do'] == 'update
')
126 if (!((can_perform('caneditownreply
', $bug['product
']) AND bugdar::$userinfo['userid
'] == $comment['userid
']) OR (can_perform('caneditotherreply
', $bug['product
']) AND bugdar::$userinfo['userid
'] != $comment['userid
'])))
128 $message->errorPermission();
131 $commentapi->set('comment
', $input->in['comment
']);
132 $commentapi->set('parselinks
', $input->in['parselinks
']);
133 $commentapi->set('hidden
', $input->in['hidden
']);
135 if ($input->in['commentid
'] == $bug['initialreport
'] AND $input->in['hidden
'])
137 $message->addError(T('You cannot hide the first comment
/initial report of a bug
. Instead
, hide the entire bug
.'));
140 if (!$message->hasErrors())
142 $commentapi->update();
145 require_once('./includes
/class_logging
.php
');
147 $log->set_bugid($bug['bugid
']);
148 $log->set_commentid($comment['commentid
']);
150 $log->add_data(true, $commentapi->record, array('comment
', 'hidden
'), false, 'comment
');
151 $log->add_data(false, $commentapi->values, array('comment
', 'hidden
'), false, 'comment
');
153 $lastgood = $db->queryFirst("
154 SELECT comment.* AS comment, user.displayname AS username
155 FROM " . TABLE_PREFIX . "comment AS comment
156 LEFT JOIN " . TABLE_PREFIX . "user AS user
157 ON (user.userid = comment.userid)
158 WHERE bugid = $bug[bugid]
159 AND !hidden ORDER BY dateline DESC
162 UPDATE " . TABLE_PREFIX . "bug
163 SET hiddenlastposttime = $lastgood[dateline],
164 hiddenlastpostby = $lastgood[userid],
165 hiddenlastpostbyname = '" . $db->escape_string($lastgood['username']) . "'
166 WHERE bugid = $bug[bugid]"
169 $log->update_history();
171 $message->redirect(T('The comment was modified successfully
.'), "showreport.php?bugid=$bug[bugid]");
175 $show['errors
'] = true;
176 $_REQUEST['do'] = 'edit
';
177 $comment['comment
'] = $input->in['comment
'];
178 $comment['hidden
'] = $input->in['hidden
'];
182 // ###################################################################
184 if ($_REQUEST['do'] == 'edit
')
186 if (!((can_perform('caneditownreply
', $bug['product
']) AND bugdar::$userinfo['userid
'] == $comment['userid
']) OR (can_perform('caneditotherreply
', $bug['product
']) AND bugdar::$userinfo['userid
'] != $comment['userid
'])))
188 $message->errorPermission();
191 $comment['posttime
'] = $datef->format(bugdar::$options['dateformat
'], $comment['dateline
']);
192 if ($comment['userid
'])
194 $commenter = new UserAPI($bugsys);
195 $commenter->set('userid
', $comment['userid
']);
196 $commenter->set_condition();
198 $commenter = $commenter->record;
200 $comment['postby
'] = construct_user_display($commenter);
201 $comment['comment
'] = $bugsys->sanitize($comment['comment
']);
202 $show['hide
'] = ($bug['initialreport
'] != $comment['commentid
'] ? true : false);
203 eval('$template->flush("' . $template->fetch('editcomment') . '");');
206 /*=====================================================================*\
207 || ###################################################################
210 || ###################################################################
211 \*=====================================================================*/