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