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