]>
src.bluestatic.org Git - bugdar.git/blob - editcomment.php
2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2004-2009 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' );
33 $commentapi = new CommentAPI ();
34 $commentapi- > set ( 'commentid' , $input- > in
[ 'commentid' ]);
37 $comment = & $commentapi- > record
;
39 $bug = $db- > queryFirst ( "SELECT * FROM " . TABLE_PREFIX
. "bug WHERE bugid = $comment [bugid]" );
41 if (! check_bug_permissions ( $bug ))
43 $message- > errorPermission ();
46 // ###################################################################
48 if ( empty ( $_REQUEST [ 'do' ]))
50 $_REQUEST [ 'do' ] = 'edit' ;
53 // ###################################################################
55 if ( $_POST [ 'do' ] == 'kill' )
57 if (! can_perform ( 'candeletedata' , $bug [ 'product' ]))
59 $message- > errorPermission ();
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" );
65 $commentapi- > remove ();
67 // check to see if we need to rebuild the lastpost information
68 if ( $lastpost [ 'commentid' ] == $comment [ 'commentid' ])
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
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
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]"
98 $message- > redirect ( T ( 'The comment has been deleted. You will be redirected back to the bug.' ), 'showreport.php?bugid=' . $bug [ 'bugid' ]);
101 // ###################################################################
103 if ( $_REQUEST [ 'do' ] == 'delete' )
105 if (! can_perform ( 'candeletedata' , $bug [ 'product' ]))
107 $message- > errorPermission ();
110 if ( $bug [ 'initialreport' ] == $comment [ 'commentid' ])
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).' ));
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' ]));
118 // ###################################################################
120 if ( $_POST [ 'do' ] == 'update' )
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' ])))
124 $message- > errorPermission ();
127 $commentapi- > set ( 'comment' , $input- > in
[ 'comment' ]);
128 $commentapi- > set ( 'parselinks' , $input- > in
[ 'parselinks' ]);
129 $commentapi- > set ( 'hidden' , $input- > in
[ 'hidden' ]);
131 if ( $input- > in
[ 'commentid' ] == $bug [ 'initialreport' ] AND $input- > in
[ 'hidden' ])
133 $message- > addError ( T ( 'You cannot hide the first comment/initial report of a bug. Instead, hide the entire bug.' ));
136 if (! $message- > hasErrors ())
138 $commentapi- > update ();
141 require_once ( './includes/class_logging.php' );
143 $log- > setBugId ( $bug [ 'bugid' ]);
144 $log- > setCommentId ( $comment [ 'commentid' ]);
146 $log- > addData ( true , $commentapi- > record
, array ( 'comment' , 'hidden' ), false , 'comment' );
147 $log- > addData ( false , $commentapi- > values
, array ( 'comment' , 'hidden' ), false , 'comment' );
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
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]"
165 $log- > updateHistory ();
167 $message- > redirect ( T ( 'The comment was modified successfully.' ), "showreport.php?bugid= $bug [bugid]" );
171 $show [ 'errors' ] = true ;
172 $_REQUEST [ 'do' ] = 'edit' ;
173 $comment [ 'comment' ] = $input- > in
[ 'comment' ];
174 $comment [ 'hidden' ] = $input- > in
[ 'hidden' ];
178 // ###################################################################
180 if ( $_REQUEST [ 'do' ] == 'edit' )
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' ])))
184 $message- > errorPermission ();
187 $comment [ 'posttime' ] = $datef- > format ( bugdar
:: $options [ 'dateformat' ], $comment [ 'dateline' ]);
188 if ( $comment [ 'userid' ])
190 $commenter = new UserAPI ();
191 $commenter- > set ( 'userid' , $comment [ 'userid' ]);
193 $commenter = $commenter- > record
;
195 $comment [ 'postby' ] = construct_user_display ( $commenter );
196 $comment [ 'comment' ] = $input- > sanitize ( $comment [ 'comment' ]);
197 $show [ 'hide' ] = ( $bug [ 'initialreport' ] != $comment [ 'commentid' ]);
199 $tpl = new BSTemplate ( 'editcomment' );
201 'comment' => $comment ,
204 $tpl- > evaluate ()-> flush ();