r172: Removing from our echo; exit; error reporting system to Error::throw()
[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 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 WHERE bug.bugid = " . intval($bugsys->in['bugid'])
26 );
27
28 if (!$bug)
29 {
30 $error->throw('alert: bad bug');
31 }
32
33 if (!(((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) AND can_perform('caneditinfo')))
34 {
35 $error->throw_permission();
36 }
37
38 // setup logging
39 require_once('./includes/class_history.php');
40 $log = new History();
41 $log->bugid = $bug['bugid'];
42
43 // ###################################################################
44
45 if (empty($_REQUEST['do']))
46 {
47 $_REQUEST['do'] = 'edit';
48 }
49
50 // ###################################################################
51 /*
52 #*# do these later once we have delete permissions figured out
53 if ($_REQUEST['do'] == 'kill')
54 {
55 // run code to remove item in database
56 }
57
58 // ###################################################################
59
60 if ($_REQUEST['do'] == 'delete')
61 {
62 // display delete confirmation message
63 }*/
64
65 // ###################################################################
66
67 if ($_POST['do'] == 'update')
68 {
69 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
70
71 if (!$bugsys->in['summary'])
72 {
73 $error->throw('you need to enter a summary');
74 }
75 if (!$pcv)
76 {
77 $error->throw('invalid product/component/version');
78 }
79
80 $hist[0] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
81
82 $db->query("
83 UPDATE " . TABLE_PREFIX . "bug
84 SET summary = '" . $bugsys->in['summary'] . "',
85 priority = " . intval($bugsys->in['priority']) . ",
86 status = " . intval($bugsys->in['status']) . ",
87 severity = " . intval($bugsys->in['severity']) . ",
88 resolution = " . intval($bugsys->in['resolution']) . ",
89 assignedto = " . intval($bugsys->in['assignedto']) . ",
90 productid = " . $pcv['product'] . ",
91 componentid = " . $pcv['component'] . ",
92 versionid = " . $pcv['version'] . "
93 WHERE bugid = $bug[bugid]"
94 );
95
96 $hist[1] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug 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 if (!$bugsys->in['firstcomment'])
149 {
150 $error->throw('you need to enter some text in the first comment');
151 }
152
153 $bugsys->in['comment_parsed'] = $bugsys->in['firstcomment'];
154
155 if (!$bugsys->options['allowhtml'])
156 {
157 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
158 }
159
160 // we could pass this as a GET param, but that's unsafe
161 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
162
163 $db->query("
164 UPDATE " . TABLE_PREFIX . "comment
165 SET comment = '" . $bugsys->in['firstcomment'] . "',
166 comment_parsed = '" . nl2br($bugsys->in['comment_parsed']) . "'
167 WHERE commentid = $firstcomment[commentid]"
168 );
169
170 if ($bugsys->in['changeproduct'])
171 {
172 $_REQUEST['do'] = 'editproduct';
173 }
174 else
175 {
176 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">done with update bug</a>";
177 }
178 }
179
180 // ###################################################################
181
182 if ($_REQUEST['do'] == 'edit')
183 {
184 foreach ($bugsys->datastore['severity'] AS $severity)
185 {
186 $value = $severity['severityid'];
187 $selected = (($severity['severityid'] == $bug['severity']) ? true : false);
188 $label = $severity['severity'];
189 eval('$select[severity] .= "' . $template->fetch('selectoption') . '";');
190 }
191
192 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
193 if (can_perform('canchangestatus'))
194 {
195 foreach ($bugsys->datastore['priority'] AS $priority)
196 {
197 $value = $priority['priorityid'];
198 $selected = (($priority['priorityid'] == $bug['priority']) ? true : false);
199 $label = $priority['priority'];
200 eval('$select[priority] .= "' . $template->fetch('selectoption') . '";');
201 }
202
203 foreach ($bugsys->datastore['status'] AS $status)
204 {
205 $value = $status['statusid'];
206 $selected = (($status['statusid'] == $bug['status']) ? true : false);
207 $label = $status['status'];
208 eval('$select[status] .= "' . $template->fetch('selectoption') . '";');
209 }
210
211 foreach ($bugsys->datastore['resolution'] AS $resolution)
212 {
213 $value = $resolution['resolutionid'];
214 $selected = (($resolution['resolutionid'] == $bug['resolution']) ? true : false);
215 $label = $resolution['resolution'];
216 eval('$select[resolution] .= "' . $template->fetch('selectoption') . '";');
217 }
218 }
219
220 $show['assign'] = ((can_perform('canassign')) ? true : false);
221 if (can_perform('canassign'))
222 {
223 foreach ($bugsys->datastore['assignto'] AS $dev)
224 {
225 $value = $dev['userid'];
226 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
227 $label = construct_user_display($dev, false);
228 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
229 }
230 }
231
232 $pcv_select = construct_pcv_select("p$bug[productid]c$bug[componentid]v$bug[versionid]");
233
234 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
235
236 eval('$template->flush("' . $template->fetch('editreport') . '");');
237 }
238
239 /*=====================================================================*\
240 || ###################################################################
241 || # $HeadURL$
242 || # $Id$
243 || ###################################################################
244 \*=====================================================================*/
245 ?>