r208: Bugs can never be deleted, so remove the actions for it
[bugdar.git] / editreport.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # All parts of this file are ©2002-[#]year[#] Iris Studios, Inc. No # ||
7 || # part of this file may be reproduced in any way: part or whole. # ||
8 || # --------------------------------------------------------------- # ||
9 || # ©2002 - [#]year[#] Iris Studios, Inc. | http://www.iris-studios.com # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 $fetchtemplates = array(
14 'editreport',
15 'pcv_select_row'
16 );
17
18 require_once('./global.php');
19
20 $bug = $db->query_first("
21 SELECT bugvaluefill.*, bug.*, user.email, user.displayname, user.showemail
22 FROM " . TABLE_PREFIX . "bug AS bug
23 LEFT JOIN " . TABLE_PREFIX . "user AS user
24 ON (bug.userid = user.userid)
25 LEFT JOIN " . TABLE_PREFIX . "bugvaluefill AS bugvaluefill
26 ON (bug.bugid = bugvaluefill.bugid)
27 WHERE bug.bugid = " . intval($bugsys->in['bugid'])
28 );
29
30 if (!$bug)
31 {
32 $message->error('alert: bad bug');
33 }
34
35 if (!(((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) AND can_perform('caneditinfo')))
36 {
37 $message->error_permission();
38 }
39
40 if ($bug['hidden'] AND !can_perform('canviewhidden'))
41 {
42 $message->error_permission();
43 }
44
45 // setup logging
46 require_once('./includes/class_history.php');
47 $log = new History();
48 $log->bugid = $bug['bugid'];
49
50 // ###################################################################
51
52 if (empty($_REQUEST['do']))
53 {
54 $_REQUEST['do'] = 'edit';
55 }
56
57 // ###################################################################
58
59 if ($_POST['do'] == 'update')
60 {
61 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
62
63 if (!$bugsys->in['summary'])
64 {
65 $message->error('you need to enter a summary');
66 }
67 if (!$pcv)
68 {
69 $message->error('invalid product/component/version');
70 }
71
72 $hist[0] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
73 $hist2[0] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
74
75 process_custom_fields($bug['bugid']);
76
77 $db->query("
78 UPDATE " . TABLE_PREFIX . "bug
79 SET summary = '" . $bugsys->in['summary'] . "',
80 priority = " . intval($bugsys->in['priority']) . ",
81 status = " . intval($bugsys->in['status']) . ",
82 severity = " . intval($bugsys->in['severity']) . ",
83 resolution = " . intval($bugsys->in['resolution']) . ",
84 assignedto = " . intval($bugsys->in['assignedto']) . ",
85 productid = " . $pcv['product'] . ",
86 componentid = " . $pcv['component'] . ",
87 versionid = " . $pcv['version'] . ",
88 hidden = " . intval($bugsys->in['hidden']) . "
89 WHERE bugid = $bug[bugid]"
90 );
91
92 // -------------------------------------------------------------------
93 // do diff history
94
95 $hist[1] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
96 $hist2[1] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
97
98 $diff[0] = array_diff_assoc($hist[0], $hist[1]);
99 $diff[1] = array_diff_assoc($hist[1], $hist[0]);
100
101 $lookupindex = array(
102 'status' => 'status',
103 'severity' => 'severity',
104 'priority' => 'priority',
105 'versionid' => 'version',
106 'assignedto' => 'assignto',
107 'resolution' => 'resolution',
108 'productid' => 'product',
109 'componentid' => 'product'
110 );
111
112 $log->language = 'log_update_bug';
113
114 foreach ($diff AS $num => $diffs)
115 {
116 foreach ($diffs AS $key => $value)
117 {
118 if (!isset($lookupindex["$key"]))
119 {
120 continue;
121 }
122
123 $ref = $lookupindex["$key"];
124 $temp =& $bugsys->datastore["$ref"]["$value"];
125 $thevalue = $temp["$ref"];
126 $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')';
127
128 if ($key == 'assignedto')
129 {
130 $thevalue = (($temp['userid']) ? construct_user_display($temp) : '');
131 $idbit = '';
132 }
133 else if ($key == 'productid' OR $key == 'componentid')
134 {
135 $ref = 'product';
136 $thevalue = $temp['title'];
137 }
138
139 $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : '');
140 }
141 }
142
143 foreach ($diff[1] AS $key => $value)
144 {
145 $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"]));
146 }
147
148 $diff2[0] = array_diff_assoc($hist2[0], $hist2[1]);
149 $diff2[1] = array_diff_assoc($hist2[1], $hist2[0]);
150
151 foreach ($diff2[1] AS $key => $value)
152 {
153 $log->log($log->diff('custom_' . $key, $diff2[0]["$key"], $diff2[1]["$key"]));
154 }
155
156 // -------------------------------------------------------------------
157 // process comment stuff
158
159 if (!$bugsys->in['firstcomment'])
160 {
161 $message->error('you need to enter some text in the first comment');
162 }
163
164 $bugsys->in['comment_parsed'] = $bugsys->in['firstcomment'];
165
166 if (!$bugsys->options['allowhtml'])
167 {
168 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
169 }
170
171 // we could pass this as a GET param, but that's unsafe
172 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
173
174 $db->query("
175 UPDATE " . TABLE_PREFIX . "comment
176 SET comment = '" . $bugsys->in['firstcomment'] . "',
177 comment_parsed = '" . nl2br($bugsys->in['comment_parsed']) . "'
178 WHERE commentid = $firstcomment[commentid]"
179 );
180
181 $message->redirect('done with update bug', "showreport.php?bugid=$bug[bugid]");
182 }
183
184 // ###################################################################
185
186 if ($_REQUEST['do'] == 'edit')
187 {
188 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
189
190 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
191 if (can_perform('canchangestatus'))
192 {
193 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $bug['priority']);
194 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $bug['status']);
195 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $bug['resolution']);
196 }
197
198 $show['assign'] = ((can_perform('canassign')) ? true : false);
199 if (can_perform('canassign'))
200 {
201 foreach ($bugsys->datastore['assignto'] AS $dev)
202 {
203 $value = $dev['userid'];
204 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
205 $label = construct_user_display($dev, false);
206 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
207 }
208 }
209
210 $pcv_select = construct_pcv_select("p$bug[productid]c$bug[componentid]v$bug[versionid]");
211
212 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
213
214 $customfields = construct_custom_fields($bug);
215
216 eval('$template->flush("' . $template->fetch('editreport') . '");');
217 }
218
219 /*=====================================================================*\
220 || ###################################################################
221 || # $HeadURL$
222 || # $Id$
223 || ###################################################################
224 \*=====================================================================*/
225 ?>