r227: Dependency system is now finished. The tree has yet to be implemented, but...
[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 $dependencies = preg_split('#([^0-9].*?)#', $bugsys->in['dependency'], -1, PREG_SPLIT_NO_EMPTY);
78 $dependencies = ((count($dependencies) < 1) ? '' : implode(', ', $dependencies));
79
80 $db->query("
81 UPDATE " . TABLE_PREFIX . "bug
82 SET summary = '" . $bugsys->in['summary'] . "',
83 priority = " . intval($bugsys->in['priority']) . ",
84 status = " . intval($bugsys->in['status']) . ",
85 severity = " . intval($bugsys->in['severity']) . ",
86 resolution = " . intval($bugsys->in['resolution']) . ",
87 assignedto = " . intval($bugsys->in['assignedto']) . ",
88 duplicateof = " . intval($bugsys->in['duplicateof']) . ",
89 dependency = '$dependencies',
90 productid = " . $pcv['product'] . ",
91 componentid = " . $pcv['component'] . ",
92 versionid = " . $pcv['version'] . ",
93 hidden = " . intval($bugsys->in['hidden']) . "
94 WHERE bugid = $bug[bugid]"
95 );
96
97 // -------------------------------------------------------------------
98 // do diff history
99
100 $hist[1] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
101 $hist2[1] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
102
103 $diff[0] = array_diff_assoc($hist[0], $hist[1]);
104 $diff[1] = array_diff_assoc($hist[1], $hist[0]);
105
106 $lookupindex = array(
107 'status' => 'status',
108 'severity' => 'severity',
109 'priority' => 'priority',
110 'versionid' => 'version',
111 'assignedto' => 'assignto',
112 'resolution' => 'resolution',
113 'productid' => 'product',
114 'componentid' => 'product'
115 );
116
117 $log->language = 'log_update_bug';
118
119 foreach ($diff AS $num => $diffs)
120 {
121 foreach ($diffs AS $key => $value)
122 {
123 if (!isset($lookupindex["$key"]))
124 {
125 continue;
126 }
127
128 $ref = $lookupindex["$key"];
129 $temp =& $bugsys->datastore["$ref"]["$value"];
130 $thevalue = $temp["$ref"];
131 $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')';
132
133 if ($key == 'assignedto')
134 {
135 $thevalue = (($temp['userid']) ? construct_user_display($temp) : '');
136 $idbit = '';
137 }
138 else if ($key == 'productid' OR $key == 'componentid')
139 {
140 $ref = 'product';
141 $thevalue = $temp['title'];
142 }
143
144 $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : '');
145 }
146 }
147
148 foreach ($diff[1] AS $key => $value)
149 {
150 $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"]));
151 }
152
153 $diff2[0] = array_diff_assoc($hist2[0], $hist2[1]);
154 $diff2[1] = array_diff_assoc($hist2[1], $hist2[0]);
155
156 foreach ($diff2[1] AS $key => $value)
157 {
158 $log->log($log->diff('custom_' . $key, $diff2[0]["$key"], $diff2[1]["$key"]));
159 }
160
161 // -------------------------------------------------------------------
162 // process comment stuff
163
164 if (!$bugsys->in['firstcomment'])
165 {
166 $message->error('you need to enter some text in the first comment');
167 }
168
169 $bugsys->in['comment_parsed'] = $bugsys->in['firstcomment'];
170
171 if (!$bugsys->options['allowhtml'])
172 {
173 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
174 }
175
176 // we could pass this as a GET param, but that's unsafe
177 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
178
179 $db->query("
180 UPDATE " . TABLE_PREFIX . "comment
181 SET comment = '" . $bugsys->in['firstcomment'] . "',
182 comment_parsed = '" . nl2br($bugsys->in['comment_parsed']) . "'
183 WHERE commentid = $firstcomment[commentid]"
184 );
185
186 $message->redirect('done with update bug', "showreport.php?bugid=$bug[bugid]");
187 }
188
189 // ###################################################################
190
191 if ($_REQUEST['do'] == 'edit')
192 {
193 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
194
195 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
196 if (can_perform('canchangestatus'))
197 {
198 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $bug['priority']);
199 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $bug['status']);
200 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $bug['resolution']);
201 }
202
203 $show['assign'] = ((can_perform('canassign')) ? true : false);
204 if (can_perform('canassign'))
205 {
206 foreach ($bugsys->datastore['assignto'] AS $dev)
207 {
208 $value = $dev['userid'];
209 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
210 $label = construct_user_display($dev, false);
211 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
212 }
213 }
214
215 $pcv_select = construct_pcv_select("p$bug[productid]c$bug[componentid]v$bug[versionid]");
216
217 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
218
219 $customfields = construct_custom_fields($bug);
220
221 if ($bug['duplicateof'])
222 {
223 $duplicate = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
224 }
225
226 if ($bug['dependency'])
227 {
228 $dependencies = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
229 while ($dependency = $db->fetch_array($dependencies))
230 {
231 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" alt=\"$dependency[summary]\">$dependency[bugid]</a>";
232 }
233 $dependencies = implode(' ', $depends);
234 }
235
236 eval('$template->flush("' . $template->fetch('editreport') . '");');
237 }
238
239 /*=====================================================================*\
240 || ###################################################################
241 || # $HeadURL$
242 || # $Id$
243 || ###################################################################
244 \*=====================================================================*/
245 ?>