r209: Allow comments to be hidden
[bugdar.git] / editcomment.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 $fetchtemplates = array(
14 'editcomment'
15 );
16
17 require_once('./global.php');
18
19 $comment = $db->query_first("
20 SELECT comment.*, user.email, user.showemail, user.displayname
21 FROM " . TABLE_PREFIX . "comment AS comment
22 LEFT JOIN " . TABLE_PREFIX . "user AS user
23 ON (comment.userid = user.userid)
24 WHERE comment.commentid = " . intval($bugsys->in['commentid'])
25 );
26
27 if (!$comment)
28 {
29 $message->error('alert: bad comment');
30 }
31
32 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $comment[bugid]");
33
34 if (!((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')))
35 {
36 $message->error_permission();
37 }
38
39 if ($bug['hidden'] AND !can_perform('canviewhidden'))
40 {
41 $message->error_permissison();
42 }
43
44 // ###################################################################
45
46 if (empty($_REQUEST['do']))
47 {
48 $_REQUEST['do'] = 'edit';
49 }
50 /*
51 #*# do these later after we work out some kind of permission system
52 // ###################################################################
53
54 if ($_REQUEST['do'] == 'kill')
55 {
56 // run code to remove item in database
57 }
58
59 // ###################################################################
60
61 if ($_REQUEST['do'] == 'delete')
62 {
63 // display delete confirmation message
64 }*/
65
66 // ###################################################################
67
68 if ($_POST['do'] == 'update')
69 {
70 if (!$bugsys->in['comment'])
71 {
72 $message->error('you need to enter some text');
73 }
74
75 $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
76
77 if (!$bugsys->options['allowhtml'])
78 {
79 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
80 }
81
82 $db->query("
83 UPDATE " . TABLE_PREFIX . "comment
84 SET comment = '" . $bugsys->in['comment'] . "',
85 comment_parsed = '" . nl2br($bugsys->in['comment_parsed']) . "',
86 hidden = " . intval($bugsys->in['hidden']) . "
87 WHERE commentid = $comment[commentid]"
88 );
89
90 // setup logging
91 require_once('./includes/class_history.php');
92 $log = new History();
93 $log->bugid = $bug['bugid'];
94 $log->language = 'log_update_comment';
95 $log->arguments = array($comment['commentid']);
96 $log->log();
97 $log->log($log->diff('hidden', $comment['hidden'], intval($bugsys->in['hidden'])));
98
99 $message->redirect('comment saved', "showreport.php?bugid=$bug[bugid]");
100 }
101
102 // ###################################################################
103
104 if ($_REQUEST['do'] == 'edit')
105 {
106 $comment['posttime'] = datelike('standard', $comment['dateline']);
107 $comment['postby'] = construct_user_display($comment);
108 $comment['comment'] = $bugsys->sanitize($comment['comment']);
109 eval('$template->flush("' . $template->fetch('editcomment') . '");');
110 }
111
112 /*=====================================================================*\
113 || ###################################################################
114 || # $HeadURL$
115 || # $Id$
116 || ###################################################################
117 \*=====================================================================*/
118 ?>