r200: - Show edit fields on editreport.php and editreport.tpl
[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 // setup logging
41 require_once('./includes/class_history.php');
42 $log = new History();
43 $log->bugid = $bug['bugid'];
44
45 // ###################################################################
46
47 if (empty($_REQUEST['do']))
48 {
49 $_REQUEST['do'] = 'edit';
50 }
51
52 // ###################################################################
53 /*
54 #*# do these later once we have delete permissions figured out
55 if ($_REQUEST['do'] == 'kill')
56 {
57 // run code to remove item in database
58 }
59
60 // ###################################################################
61
62 if ($_REQUEST['do'] == 'delete')
63 {
64 // display delete confirmation message
65 }*/
66
67 // ###################################################################
68
69 if ($_POST['do'] == 'update')
70 {
71 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
72
73 if (!$bugsys->in['summary'])
74 {
75 $message->error('you need to enter a summary');
76 }
77 if (!$pcv)
78 {
79 $message->error('invalid product/component/version');
80 }
81
82 $hist[0] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
83
84 process_custom_fields($bug['bugid']);
85
86 $db->query("
87 UPDATE " . TABLE_PREFIX . "bug
88 SET summary = '" . $bugsys->in['summary'] . "',
89 priority = " . intval($bugsys->in['priority']) . ",
90 status = " . intval($bugsys->in['status']) . ",
91 severity = " . intval($bugsys->in['severity']) . ",
92 resolution = " . intval($bugsys->in['resolution']) . ",
93 assignedto = " . intval($bugsys->in['assignedto']) . ",
94 productid = " . $pcv['product'] . ",
95 componentid = " . $pcv['component'] . ",
96 versionid = " . $pcv['version'] . "
97 WHERE bugid = $bug[bugid]"
98 );
99
100 $hist[1] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
101
102 $diff[0] = array_diff_assoc($hist[0], $hist[1]);
103 $diff[1] = array_diff_assoc($hist[1], $hist[0]);
104
105 $lookupindex = array(
106 'status' => 'status',
107 'severity' => 'severity',
108 'priority' => 'priority',
109 'versionid' => 'version',
110 'assignedto' => 'assignto',
111 'resolution' => 'resolution',
112 'productid' => 'product',
113 'componentid' => 'product'
114 );
115
116 $log->language = 'log_update_bug';
117
118 foreach ($diff AS $num => $diffs)
119 {
120 foreach ($diffs AS $key => $value)
121 {
122 if (!isset($lookupindex["$key"]))
123 {
124 continue;
125 }
126
127 $ref = $lookupindex["$key"];
128 $temp =& $bugsys->datastore["$ref"]["$value"];
129 $thevalue = $temp["$ref"];
130 $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')';
131
132 if ($key == 'assignedto')
133 {
134 $thevalue = (($temp['userid']) ? construct_user_display($temp) : '');
135 $idbit = '';
136 }
137 else if ($key == 'productid' OR $key == 'componentid')
138 {
139 $ref = 'product';
140 $thevalue = $temp['title'];
141 }
142
143 $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : '');
144 }
145 }
146
147 foreach ($diff[1] AS $key => $value)
148 {
149 $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"]));
150 }
151
152 if (!$bugsys->in['firstcomment'])
153 {
154 $message->error('you need to enter some text in the first comment');
155 }
156
157 $bugsys->in['comment_parsed'] = $bugsys->in['firstcomment'];
158
159 if (!$bugsys->options['allowhtml'])
160 {
161 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
162 }
163
164 // we could pass this as a GET param, but that's unsafe
165 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
166
167 $db->query("
168 UPDATE " . TABLE_PREFIX . "comment
169 SET comment = '" . $bugsys->in['firstcomment'] . "',
170 comment_parsed = '" . nl2br($bugsys->in['comment_parsed']) . "'
171 WHERE commentid = $firstcomment[commentid]"
172 );
173
174 $message->redirect('done with update bug', "showreport.php?bugid=$bug[bugid]");
175 }
176
177 // ###################################################################
178
179 if ($_REQUEST['do'] == 'edit')
180 {
181 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
182
183 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
184 if (can_perform('canchangestatus'))
185 {
186 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $bug['priority']);
187 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $bug['status']);
188 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $bug['resolution']);
189 }
190
191 $show['assign'] = ((can_perform('canassign')) ? true : false);
192 if (can_perform('canassign'))
193 {
194 foreach ($bugsys->datastore['assignto'] AS $dev)
195 {
196 $value = $dev['userid'];
197 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
198 $label = construct_user_display($dev, false);
199 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
200 }
201 }
202
203 $pcv_select = construct_pcv_select("p$bug[productid]c$bug[componentid]v$bug[versionid]");
204
205 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
206
207 $customfields = construct_custom_fields($bug);
208
209 eval('$template->flush("' . $template->fetch('editreport') . '");');
210 }
211
212 /*=====================================================================*\
213 || ###################################################################
214 || # $HeadURL$
215 || # $Id$
216 || ###################################################################
217 \*=====================================================================*/
218 ?>