2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)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(
27 $focus['showreport'] = 'focus';
29 require_once('./global.php');
30 require_once('./includes/api_comment.php');
32 require_once('./includes/class_api_error.php');
33 APIError(array(new API_Error_Handler($message), 'user_cumulative'));
35 $commentapi = new CommentAPI($bugsys);
36 $commentapi->set('commentid', $bugsys->in
['commentid']);
37 $commentapi->set_condition();
40 $comment =& $commentapi->objdata
;
42 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bug WHERE bugid = $comment[bugid]");
44 if (!check_bug_permissions($bug))
46 $message->errorPermission();
49 function update_lastpost_time($bug) {
51 $lastgoodpublic = $bugsys->db
->query_first("
52 SELECT comment.dateline, comment.userid, user.displayname AS username
53 FROM " . TABLE_PREFIX
. "comment AS comment
54 LEFT JOIN " . TABLE_PREFIX
. "user AS user
55 ON (user.userid = comment.userid)
56 WHERE bugid = $bug[bugid]
57 AND !hidden ORDER BY dateline DESC
59 $lastgoodprivate = $bugsys->db
->query_first("
60 SELECT comment.dateline, comment.userid, user.displayname AS username
61 FROM " . TABLE_PREFIX
. "comment AS comment
62 LEFT JOIN " . TABLE_PREFIX
. "user AS user
63 ON (user.userid = comment.userid)
64 WHERE bugid = $bug[bugid]
65 ORDER BY dateline DESC
68 UPDATE " . TABLE_PREFIX
. "bug
69 SET hiddenlastposttime = $lastgoodpublic[dateline],
70 hiddenlastpostby = $lastgoodpublic[userid],
71 hiddenlastpostbyname = '" . $bugsys->db
->escape_string($lastgoodpublic['username']) . "',
72 lastposttime = $lastgoodprivate[dateline],
73 lastpostby = $lastgoodprivate[userid],
74 lastpostbyname = '" . $bugsys->db
->escape_string($lastgoodprivate['username']) . "'
75 WHERE bugid = $bug[bugid]"
79 // ###################################################################
81 if (empty($_REQUEST['do']))
83 $_REQUEST['do'] = 'edit';
86 // ###################################################################
88 if ($_POST['do'] == 'kill')
90 if (!can_perform('candeletedata', $bug['product']))
92 $message->errorPermission();
95 // get the last post (as in prior to deletion)
96 $lastpost = $db->query_first("SELECT commentid FROM " . TABLE_PREFIX
. "comment WHERE bugid = $bug[bugid] ORDER BY dateline DESC");
98 $commentapi->delete();
100 // check to see if we need to rebuild the lastpost information
101 if ($lastpost['commentid'] == $comment['commentid'])
103 update_lastpost_time($bug);
106 $message->redirect(T('The comment has been deleted. You will be redirected back to the bug.'), 'showreport.php?bugid=' . $bug['bugid']);
109 // ###################################################################
111 if ($_REQUEST['do'] == 'delete')
113 if (!can_perform('candeletedata', $bug['product']))
115 $message->errorPermission();
118 if ($bug['initialreport'] == $comment['commentid'])
120 $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).'));
123 $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']));
126 // ###################################################################
128 if ($_POST['do'] == 'update')
130 if (!((can_perform('caneditownreply', $bug['product']) AND $bugsys->userinfo
['userid'] == $comment['userid']) OR (can_perform('caneditotherreply', $bug['product']) AND $bugsys->userinfo
['userid'] != $comment['userid'])))
132 $message->errorPermission();
135 $commentapi->set('comment', $bugsys->in
['comment']);
136 $commentapi->set('parselinks', $bugsys->in
['parselinks']);
137 $commentapi->set('hidden', $bugsys->in
['hidden']);
139 if ($bugsys->in
['commentid'] == $bug['initialreport'] AND $bugsys->in
['hidden'])
141 $message->addError(T('You cannot hide the first comment/initial report of a bug. Instead, hide the entire bug.'));
144 if (!$message->hasErrors())
146 $commentapi->update();
149 require_once('./includes/class_logging.php');
151 $log->set_bugid($bug['bugid']);
152 $log->set_commentid($comment['commentid']);
154 $log->add_data(true
, $commentapi->objdata
, array('comment', 'hidden'), false
, 'comment');
155 $log->add_data(false
, $commentapi->values
, array('comment', 'hidden'), false
, 'comment');
157 update_lastpost_time($bug);
158 $log->update_history();
159 $message->redirect(T('The comment was modified successfully.'), "showreport.php?bugid=$bug[bugid]");
163 $show['errors'] = true
;
164 $_REQUEST['do'] = 'edit';
165 $comment['comment'] = $bugsys->in
['comment'];
166 $comment['hidden'] = $bugsys->in
['hidden'];
170 // ###################################################################
172 if ($_REQUEST['do'] == 'edit')
174 if (!((can_perform('caneditownreply', $bug['product']) AND $bugsys->userinfo
['userid'] == $comment['userid']) OR (can_perform('caneditotherreply', $bug['product']) AND $bugsys->userinfo
['userid'] != $comment['userid'])))
176 $message->errorPermission();
179 $comment['posttime'] = $datef->format($bugsys->options
['dateformat'], $comment['dateline']);
180 if ($comment['userid'])
182 $commenter = new UserAPI($bugsys);
183 $commenter->set('userid', $comment['userid']);
184 $commenter->set_condition();
186 $commenter = $commenter->objdata
;
188 $comment['postby'] = construct_user_display($commenter);
189 $comment['comment'] = $bugsys->sanitize($comment['comment']);
190 $show['hide'] = ($bug['initialreport'] != $comment['commentid'] ? true
: false
);
191 eval('$template->flush("' . $template->fetch('editcomment') . '");');