r271: Missed an instance of $error->throw_permission()
[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 $message->error_permission();
23 }
24
25 // ###################################################################
26
27 if (empty($_REQUEST['do']))
28 {
29 $_REQUEST['do'] = 'add';
30 }
31
32 // ###################################################################
33
34 if ($_POST['do'] == 'insert')
35 {
36 // -------------------------------------------------------------------
37 // check permissions on various input values
38 if (!can_perform('canchangestatus'))
39 {
40 $bugsys->in['priority'] = $bugsys->options['defaultpriority'];
41 $bugsys->in['status'] = $bugsys->options['defaultstatus'];
42 $bugsys->in['resolution'] = $bugsys->options['defaultresolve'];
43 }
44 else
45 {
46 if (!$bugsys->datastore['priority'][ $bugsys->in['priority'] ])
47 {
48 $bugsys->in['priority'] = $bugsys->options['defaultpriority'];
49 }
50 if (!$bugsys->datastore['status'][ $bugsys->in['status'] ])
51 {
52 $bugsys->in['status'] = $bugsys->options['defaultstatus'];
53 }
54 if (!$bugsys->datastore['resolution'][ $bugsys->in['resolution'] ])
55 {
56 $bugsys->in['resolution'] = $bugsys->options['defaultresolve'];
57 }
58 }
59 if (!can_perform('canassign'))
60 {
61 $bugsys->in['assignedto'] = $bugsys->options['defaultassign'];
62 }
63 else
64 {
65 // assigned person is not a dev or a valid user
66 if (!$bugsys->datastore['assignto'][ $bugsys->in['assignedto'] ]['userid'])
67 {
68 $bugsys->in['assignedto'] = $bugsys->options['defaultassign'];
69 }
70 }
71
72 // -------------------------------------------------------------------
73 // product/component/version stuff
74 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
75
76 print_r($vars);
77
78 // -------------------------------------------------------------------
79 // sanity checks
80 if (!$pcv)
81 {
82 $message->error('there was a problem selecting the product, component, or version');
83 }
84 if (!$bugsys->in['summary'])
85 {
86 $message->error('please enter a bug title');
87 }
88 if (!$bugsys->in['comment'])
89 {
90 $message->error('please enter a bug description');
91 }
92
93 // -------------------------------------------------------------------
94 // data clean and insert
95 $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
96
97 if (!$bugsys->options['allowhtml'])
98 {
99 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
100 }
101
102 // create the bug report
103 $db->query("
104 INSERT INTO " . TABLE_PREFIX . "bug
105 (userid, productid, componentid, versionid, summary, severity, priority, status, assignedto, resolution)
106 VALUES
107 (" . $bugsys->userinfo['userid'] . ", " . $pcv['product'] . ", " . $pcv['component'] . ", " . $pcv['version'] . ",
108 '" . $bugsys->in['summary'] . "', " . intval($bugsys->in['severity']) . ", " . intval($bugsys->in['priority']) . ",
109 " . intval($bugsys->in['status']) . ", " . intval($bugsys->in['assignedto']) . ", " . intval($bugsys->in['resolution']) . "
110 )"
111 );
112
113 $bugid = $db->insert_id();
114
115 $time = time();
116
117 // insert the comment to the database
118 $db->query("
119 INSERT INTO " . TABLE_PREFIX . "comment
120 (bugid, userid, dateline, comment, comment_parsed)
121 VALUES
122 ($bugid, " . $bugsys->userinfo['userid'] . ",
123 $time, '" . $bugsys->in['comment'] . "',
124 '" . nl2br($bugsys->in['comment_parsed']) . "'
125 )"
126 );
127
128 $initialreport = $db->insert_id();
129
130 $db->query("
131 UPDATE " . TABLE_PREFIX . "bug
132 SET dateline = $time,
133 initialreport = $initialreport,
134 lastposttime = $time,
135 lastpostby = " . $bugsys->userinfo['userid'] . ",
136 hiddenlastposttime = $time,
137 hiddenlastpostby = " . $bugsys->userinfo['userid'] . "
138 WHERE bugid = $bugid"
139 );
140
141 $message->redirect('bug is done!', "showreport.php?bugid=$bugid");
142 }
143
144 // ###################################################################
145
146 if ($_REQUEST['do'] == 'add')
147 {
148 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid');
149
150 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
151
152 if (can_perform('canchangestatus'))
153 {
154 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid');
155 $select['status'] = construct_datastore_select('status', 'status', 'statusid');
156 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid');
157 }
158
159 $show['assign'] = ((can_perform('canassign')) ? true : false);
160
161 if (can_perform('canassign'))
162 {
163 foreach ($bugsys->datastore['assignto'] AS $dev)
164 {
165 $value = $dev['userid'];
166 $label = construct_user_display($dev, false);
167 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
168 }
169 }
170
171 $pcv_select = construct_pcv_select();
172
173 eval('$template->flush("' . $template->fetch('newreport') . '");');
174 }
175
176 /*=====================================================================*\
177 || ###################################################################
178 || # $HeadURL$
179 || # $Id$
180 || ###################################################################
181 \*=====================================================================*/
182 ?>