r172: Removing from our echo; exit; error reporting system to Error::throw()
[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 $error->throw('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 $error->throw_permission();
37 }
38
39 // ###################################################################
40
41 if (empty($_REQUEST['do']))
42 {
43 $_REQUEST['do'] = 'edit';
44 }
45 /*
46 #*# do these later after we work out some kind of permission system
47 // ###################################################################
48
49 if ($_REQUEST['do'] == 'kill')
50 {
51 // run code to remove item in database
52 }
53
54 // ###################################################################
55
56 if ($_REQUEST['do'] == 'delete')
57 {
58 // display delete confirmation message
59 }*/
60
61 // ###################################################################
62
63 if ($_POST['do'] == 'update')
64 {
65 if (!$bugsys->in['comment'])
66 {
67 $error->throw('you need to enter some text');
68 }
69
70 $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
71
72 if (!$bugsys->options['allowhtml'])
73 {
74 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
75 }
76
77 $db->query("
78 UPDATE " . TABLE_PREFIX . "comment
79 SET comment = '" . $bugsys->in['comment'] . "',
80 comment_parsed = '" . nl2br($bugsys->in['comment_parsed']) . "'
81 WHERE commentid = $comment[commentid]"
82 );
83
84 // setup logging
85 require_once('./includes/class_history.php');
86 $log = new History();
87 $log->bugid = $bug['bugid'];
88 $log->language = 'log_update_comment';
89 $log->arguments = array($comment['commentid']);
90 $log->log();
91
92 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">comment saved</a>";
93 }
94
95 // ###################################################################
96
97 if ($_REQUEST['do'] == 'edit')
98 {
99 $comment['posttime'] = datelike('standard', $comment['dateline']);
100 $comment['postby'] = construct_user_display($comment);
101 $comment['comment'] = $bugsys->sanitize($comment['comment']);
102 eval('$template->flush("' . $template->fetch('editcomment') . '");');
103 }
104
105 /*=====================================================================*\
106 || ###################################################################
107 || # $HeadURL$
108 || # $Id$
109 || ###################################################################
110 \*=====================================================================*/
111 ?>