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