r69: Removing our nasty iff() function in place of the beautiful ternary operator
[bugdar.git] / newreport.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 $fetchtemplates = array(
14 'newreport',
15 'pcv_select_row'
16 );
17
18 require_once('./global.php');
19
20 if (!can_perform('cansubmitbugs'))
21 {
22 echo 'NO permission';
23 exit;
24 }
25
26 // ###################################################################
27
28 if (empty($_REQUEST['do']))
29 {
30 $_REQUEST['do'] = 'add';
31 }
32
33 // ###################################################################
34
35 if ($_POST['do'] == 'insert')
36 {
37 sanitize(array(
38 'pcv_select' => STR,
39 'summary' => STR_NOHTML,
40 'severity' => INT,
41 'priority' => INT,
42 'status' => INT,
43 'resolution' => INT,
44 'assignedto' => INT,
45 'comment' => STR)
46 );
47
48 // -------------------------------------------------------------------
49 // check permissions on various input values
50 if (!can_perform('canchangestatus'))
51 {
52 $vars['priority'] = $bugsys->options['defaultpriority'];
53 $vars['status'] = $bugsys->options['defaultstatus'];
54 $vars['resolution'] = $bugsys->options['defaultresolve'];
55 }
56 else
57 {
58 if (!$bugsys->datastore['priority']["$vars[priority]"])
59 {
60 $vars['priority'] = $bugsys->options['defaultpriority'];
61 }
62 if (!$bugsys->datastore['status']["$vars[status]"])
63 {
64 $vars['status'] = $bugsys->options['defaultstatus'];
65 }
66 if (!$bugsys->datastore['resolution']["$vars[resolution]"])
67 {
68 $vars['resolution'] = $bugsys->options['defaultresolve'];
69 }
70 }
71 if (!can_perform('canassign'))
72 {
73 $vars['assignedto'] = $bugsys->options['defaultassign'];
74 }
75 else
76 {
77 // assigned person is not a dev or a valid user
78 if (!$bugsys->datastore['assignto']["$vars[assignedto]"]['userid'])
79 {
80 $vars['assignedto'] = $bugsys->options['defaultassign'];
81 }
82 }
83
84 // -------------------------------------------------------------------
85 // product/component/version stuff
86 $vars['pcv'] = parse_pcv_select($vars['pcv_select'], true);
87
88 print_r($vars);
89
90 // -------------------------------------------------------------------
91 // sanity checks
92 if (!$vars['pcv'])
93 {
94 echo 'there was a problem selecting the product, component, or version';
95 exit;
96 }
97 if (!$vars['summary'])
98 {
99 echo 'please enter a bug title';
100 exit;
101 }
102 if (!$vars['comment'])
103 {
104 echo 'please enter a bug description';
105 exit;
106 }
107
108 // -------------------------------------------------------------------
109 // data clean and insert
110 $vars['comment_parsed'] = $vars['comment'];
111
112 if (!$bugsys->options['allowhtml'])
113 {
114 $vars['comment_parsed'] = htmlspecialcharslike($vars['comment_parsed']);
115 }
116
117 // create the bug report
118 $db->query("
119 INSERT INTO " . TABLE_PREFIX . "bug
120 (userid, productid, componentid, versionid, summary, severity, priority, status, assignedto, resolution)
121 VALUES
122 (" . $bugsys->userinfo['userid'] . ", " . $vars['pcv']['product'] . ", " . $vars['pcv']['component'] . ", " . $vars['pcv']['version'] . ",
123 '" . addslasheslike($vars['summary']) . "', $vars[severity], $vars[priority], $vars[status], $vars[assignedto], $vars[resolution]
124 )"
125 );
126
127 $bugid = $db->insert_id();
128
129 $time = time();
130
131 // insert the comment to the database
132 $db->query("
133 INSERT INTO " . TABLE_PREFIX . "comment
134 (bugid, userid, dateline, comment, comment_parsed)
135 VALUES
136 ($bugid, " . $bugsys->userinfo['userid'] . ",
137 $time, '" . addslasheslike($vars['comment']) . "',
138 '" . addslasheslike(nl2br($vars['comment_parsed'])) . "'
139 )"
140 );
141
142 $initialreport = $db->insert_id();
143
144 $db->query("UPDATE " . TABLE_PREFIX . "bug SET dateline = $time, initialreport = $initialreport, lastposttime = $time, lastpostby = " . $bugsys->userinfo['userid'] . " WHERE bugid = $bugid");
145
146 echo "<a href=\"showreport.php?bugid=$bugid\">bug is done!</a>";
147 }
148
149 // ###################################################################
150
151 if ($_REQUEST['do'] == 'add')
152 {
153 foreach ($bugsys->datastore['severity'] AS $severity)
154 {
155 $value = $severity['severityid'];
156 $label = $severity['severity'];
157 eval('$select[severity] .= "' . $template->fetch('selectoption') . '";');
158 }
159
160 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
161
162 if (can_perform('canchangestatus'))
163 {
164 foreach ($bugsys->datastore['priority'] AS $priority)
165 {
166 $value = $priority['priorityid'];
167 $label = $priority['priority'];
168 eval('$select[priority] .= "' . $template->fetch('selectoption') . '";');
169 }
170
171 foreach ($bugsys->datastore['status'] AS $status)
172 {
173 $value = $status['statusid'];
174 $label = $status['status'];
175 eval('$select[status] .= "' . $template->fetch('selectoption') . '";');
176 }
177
178 foreach ($bugsys->datastore['resolution'] AS $resolution)
179 {
180 $value = $resolution['resolutionid'];
181 $label = $resolution['resolution'];
182 eval('$select[resolution] .= "' . $template->fetch('selectoption') . '";');
183 }
184 }
185
186 $show['assign'] = ((can_perform('canassign')) ? true : false);
187
188 if (can_perform('canassign'))
189 {
190 foreach ($bugsys->datastore['assignto'] AS $dev)
191 {
192 $value = $dev['userid'];
193 $label = construct_user_display($dev, false);
194 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
195 }
196 }
197
198 $pcv_select = construct_pcv_select();
199
200 eval('$template->flush("' . $template->fetch('newreport') . '");');
201 }
202
203 /*=====================================================================*\
204 || ###################################################################
205 || # $HeadURL$
206 || # $Id$
207 || ###################################################################
208 \*=====================================================================*/
209 ?>