r197: Changing the datastore foreach() loops that we can to use construct_datastore_s...
[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 $erorr->throw_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("UPDATE " . TABLE_PREFIX . "bug SET dateline = $time, initialreport = $initialreport, lastposttime = $time, lastpostby = " . $bugsys->userinfo['userid'] . " WHERE bugid = $bugid");
131
132 $message->redirect('bug is done!', "showreport.php?bugid=$bugid");
133 }
134
135 // ###################################################################
136
137 if ($_REQUEST['do'] == 'add')
138 {
139 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid');
140
141 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
142
143 if (can_perform('canchangestatus'))
144 {
145 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid');
146 $select['status'] = construct_datastore_select('status', 'status', 'statusid');
147 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid');
148 }
149
150 $show['assign'] = ((can_perform('canassign')) ? true : false);
151
152 if (can_perform('canassign'))
153 {
154 foreach ($bugsys->datastore['assignto'] AS $dev)
155 {
156 $value = $dev['userid'];
157 $label = construct_user_display($dev, false);
158 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
159 }
160 }
161
162 $pcv_select = construct_pcv_select();
163
164 eval('$template->flush("' . $template->fetch('newreport') . '");');
165 }
166
167 /*=====================================================================*\
168 || ###################################################################
169 || # $HeadURL$
170 || # $Id$
171 || ###################################################################
172 \*=====================================================================*/
173 ?>