]> src.bluestatic.org Git - bugdar.git/blob - editcomment.php
Renaming admin/setting.php to admin/settings.php
[bugdar.git] / editcomment.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-2009 Blue Static
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 2 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
27 $focus['showreport'] = 'focus';
28
29 require_once('./global.php');
30 require_once('./includes/api_comment.php');
31
32
33 $commentapi = new CommentAPI();
34 $commentapi->set('commentid', $input->in['commentid']);
35 $commentapi->fetch();
36
37 $comment = &$commentapi->record;
38
39 $bug = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $comment[bugid]");
40
41 if (!check_bug_permissions($bug))
42 {
43 $message->errorPermission();
44 }
45
46 // ###################################################################
47
48 if (empty($_REQUEST['do']))
49 {
50 $_REQUEST['do'] = 'edit';
51 }
52
53 // ###################################################################
54
55 if ($_POST['do'] == 'kill')
56 {
57 if (!can_perform('candeletedata', $bug['product']))
58 {
59 $message->errorPermission();
60 }
61
62 // get the last post (as in prior to deletion)
63 $lastpost = $db->queryFirst("SELECT commentid FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline DESC");
64
65 $commentapi->remove();
66
67 // check to see if we need to rebuild the lastpost information
68 if ($lastpost['commentid'] == $comment['commentid'])
69 {
70 $lastgoodpublic = $db->queryFirst("
71 SELECT comment.* AS comment, user.displayname AS username
72 FROM " . TABLE_PREFIX . "comment AS comment
73 LEFT JOIN " . TABLE_PREFIX . "user AS user
74 ON (user.userid = comment.userid)
75 WHERE bugid = $bug[bugid]
76 AND !hidden ORDER BY dateline DESC
77 ");
78 $lastgoodprivate = $db->queryFirst("
79 SELECT comment.* AS comment, user.displayname AS username
80 FROM " . TABLE_PREFIX . "comment AS comment
81 LEFT JOIN " . TABLE_PREFIX . "user AS user
82 ON (user.userid = comment.userid)
83 WHERE bugid = $bug[bugid]
84 ORDER BY dateline DESC
85 ");
86 $db->query("
87 UPDATE " . TABLE_PREFIX . "bug
88 SET hiddenlastposttime = $lastgoodpublic[dateline],
89 hiddenlastpostby = $lastgoodpublic[userid],
90 hiddenlastpostbyname = '" . $db->escapeString($lastgoodpublic['username']) . "',
91 lastposttime = $lastgoodprivate[dateline],
92 lastpostby = $lastgoodprivate[userid],
93 lastpostbyname = '" . $db->escapeString($lastgoodprivate['username']) . "'
94 WHERE bugid = $bug[bugid]"
95 );
96 }
97
98 $message->redirect(T('The comment has been deleted. You will be redirected back to the bug.'), 'showreport.php?bugid=' . $bug['bugid']);
99 }
100
101 // ###################################################################
102
103 if ($_REQUEST['do'] == 'delete')
104 {
105 if (!can_perform('candeletedata', $bug['product']))
106 {
107 $message->errorPermission();
108 }
109
110 if ($bug['initialreport'] == $comment['commentid'])
111 {
112 $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).'));
113 }
114
115 $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']));
116 }
117
118 // ###################################################################
119
120 if ($_POST['do'] == 'update')
121 {
122 if (!((can_perform('caneditownreply', $bug['product']) AND bugdar::$userinfo['userid'] == $comment['userid']) OR (can_perform('caneditotherreply', $bug['product']) AND bugdar::$userinfo['userid'] != $comment['userid'])))
123 {
124 $message->errorPermission();
125 }
126
127 $commentapi->set('comment', $input->in['comment']);
128 $commentapi->set('parselinks', $input->in['parselinks']);
129 $commentapi->set('hidden', $input->in['hidden']);
130
131 if ($input->in['commentid'] == $bug['initialreport'] AND $input->in['hidden'])
132 {
133 $message->addError(T('You cannot hide the first comment/initial report of a bug. Instead, hide the entire bug.'));
134 }
135
136 if (!$message->hasErrors())
137 {
138 $commentapi->update();
139
140 // setup logging
141 require_once('./includes/class_logging.php');
142 $log = new Logging;
143 $log->setBugId($bug['bugid']);
144 $log->setCommentId($comment['commentid']);
145
146 $log->addData(true, $commentapi->record, array('comment', 'hidden'), false, 'comment');
147 $log->addData(false, $commentapi->values, array('comment', 'hidden'), false, 'comment');
148
149 $lastgood = $db->queryFirst("
150 SELECT comment.* AS comment, user.displayname AS username
151 FROM " . TABLE_PREFIX . "comment AS comment
152 LEFT JOIN " . TABLE_PREFIX . "user AS user
153 ON (user.userid = comment.userid)
154 WHERE bugid = $bug[bugid]
155 AND !hidden ORDER BY dateline DESC
156 ");
157 $db->query("
158 UPDATE " . TABLE_PREFIX . "bug
159 SET hiddenlastposttime = $lastgood[dateline],
160 hiddenlastpostby = $lastgood[userid],
161 hiddenlastpostbyname = '" . $db->escapeString($lastgood['username']) . "'
162 WHERE bugid = $bug[bugid]"
163 );
164
165 $log->updateHistory();
166
167 $message->redirect(T('The comment was modified successfully.'), "showreport.php?bugid=$bug[bugid]");
168 }
169 else
170 {
171 $show['errors'] = true;
172 $_REQUEST['do'] = 'edit';
173 $comment['comment'] = $input->in['comment'];
174 $comment['hidden'] = $input->in['hidden'];
175 }
176 }
177
178 // ###################################################################
179
180 if ($_REQUEST['do'] == 'edit')
181 {
182 if (!((can_perform('caneditownreply', $bug['product']) AND bugdar::$userinfo['userid'] == $comment['userid']) OR (can_perform('caneditotherreply', $bug['product']) AND bugdar::$userinfo['userid'] != $comment['userid'])))
183 {
184 $message->errorPermission();
185 }
186
187 $comment['posttime'] = $datef->format(bugdar::$options['dateformat'], $comment['dateline']);
188 if ($comment['userid'])
189 {
190 $commenter = new UserAPI();
191 $commenter->set('userid', $comment['userid']);
192 $commenter->fetch();
193 $commenter = $commenter->record;
194 }
195 $comment['postby'] = construct_user_display($commenter);
196 $comment['comment'] = $input->sanitize($comment['comment']);
197 $show['hide'] = ($bug['initialreport'] != $comment['commentid']);
198
199 $tpl = new BSTemplate('editcomment');
200 $tpl->vars = array(
201 'comment' => $comment,
202 'bug' => $bug
203 );
204 $tpl->evaluate()->flush();
205 }
206
207 ?>