Switch the 'modify' code of admin/field.php to use templates
[bugdar.git] / explain.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-2009 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 $fetchtemplates = array(
23 'explain_product',
24 'explain_automation',
25 'explain_row'
26 );
27
28
29 $focus['showreport'] = 'focus';
30
31 require_once('./global.php');
32
33 // ###################################################################
34
35 if (empty($_REQUEST['do']))
36 {
37 $_REQUEST['do'] = 'products';
38 }
39
40 // ###################################################################
41
42 if ($_REQUEST['do'] == 'products')
43 {
44 if (!is_array(bugdar::$datastore['product']))
45 {
46 $message->error(T('There are no products set up.'));
47 }
48
49 foreach (bugdar::$datastore['product'] AS $product)
50 {
51 if ($product['parentid'])
52 {
53 $components["$product[componentmother]"]["$product[productid]"] = $product;
54 }
55 else
56 {
57 $products["$product[productid]"] = $product;
58 }
59 }
60
61 foreach (bugdar::$datastore['version'] AS $version)
62 {
63 $versions["$version[productid]"]["$version[versionid]"] = $version;
64 }
65
66 // global versions
67 if (is_array($versions['0']))
68 {
69 foreach ($versions['0'] as $version)
70 {
71 $tpl = new BSTemplate('explain_row');
72 $tpl->vars = array(
73 'left' => $version['version'],
74 );
75 $globalversions .= $tpl->evaluate()->getTemplate();
76 }
77 }
78
79 foreach ($products as $product)
80 {
81 $tpl = new BSTemplate('explain_row');
82 $tpl->vars = array(
83 'left' => $product['title'],
84 'right' => $product['description'],
85 'trextra' => ' class="altcolor"'
86 );
87 $productlist .= $tpl->evaluate()->getTemplate();
88
89 if (is_array($components["$product[productid]"]))
90 {
91 foreach ($components["$product[productid]"] as $component)
92 {
93 $tpl = new BSTemplate('explain_row');
94 $tpl->vars = array(
95 'left' => '&nbsp; &rsaquo; &nbsp; ' . $component['title'],
96 'right' => $component['description'],
97 );
98 $productlist .= $tpl->evaluate()->getTemplate();
99 }
100 }
101 }
102
103 $tpl = new BSTemplate('explain_product');
104 $tpl->vars = array(
105 'globalversions' => $globalversions,
106 'productlist' => $productlist
107 );
108 $tpl->evaluate()->flush();
109 }
110
111 // ###################################################################
112
113 if ($_REQUEST['do'] == 'automations')
114 {
115 $fields_fetch = $db->query("
116 SELECT bugfield.*, MAX(permission.mask) AS mask
117 FROM " . TABLE_PREFIX . "bugfield AS bugfield
118 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
119 ON (bugfield.fieldid = permission.fieldid)
120 WHERE (permission.mask = 2 OR permission.mask = 1)
121 AND permission.usergroupid IN (" . bugdar::$userinfo['usergroupid'] . (sizeof(bugdar::$userinfo['groupids']) != 0 ? ',' . implode(',', bugdar::$userinfo['groupids']) : '') . ")
122 GROUP BY (bugfield.fieldid)
123 ");
124 foreach ($fields_fetch as $field)
125 {
126 $fields["$field[fieldid]"] = $field;
127 }
128
129 if (is_array(bugdar::$datastore['automation']))
130 {
131 foreach (bugdar::$datastore['automation'] as $automation)
132 {
133 $automation['fieldchanges'] = unserialize($automation['fieldchanges']);
134
135 $tpl = new BSTemplate('explain_row');
136 $tpl->vars = array(
137 'left' => $automation['name'],
138 'right' => $automation['description'],
139 'trextra' => ' class="listinghead"'
140 );
141 $automations .= $tpl->evaluate()->getTemplate();
142
143 if ($automation['comment'])
144 {
145 $tpl = new BSTemplate('explain_row');
146 $tpl->vars = array(
147 'left' => T('Add Comment'),
148 'right' => $automation['comment'],
149 'trextra' => ' class="altcolor"'
150 );
151 $automations .= $tpl->evaluate()->getTemplate();
152 }
153
154 $trextra = '';
155
156 if (is_array($automation['fieldchanges']['builtin']))
157 {
158 foreach ($automation['fieldchanges']['builtin'] AS $name => $value)
159 {
160 $tpl = new BSTemplate('explain_row');
161 $tpl->vars = array(
162 'left' => $name,
163 'right' => bugdar::$datastore["$name"]["$value"]["$name"],
164 );
165 $automations .= $tpl->evaluate()->getTemplate();
166 }
167 }
168
169 if (is_array($automation['fieldchanges']['custom']))
170 {
171 foreach ($automation['fieldchanges']['custom'] AS $id => $value)
172 {
173 if (!$fields["$id"])
174 {
175 continue;
176 }
177
178 $tpl = new BSTemplate('explain_row');
179 $tpl->vars = array(
180 'left' => $fields["$id"]['name'] . ' ' . sprintf(T('(Custom #%1$d, type: %2$s)'), $id, $fields["$id"]['type']),
181 'right' => $value,
182 );
183 $automations .= $tpl->evaluate()->getTemplate();
184 }
185 }
186 }
187 }
188
189 $tpl = new BSTemplate('explain_automation');
190 $tpl->vars = array('automations' => $automations);
191 $tpl->evaluate()->flush();
192 }
193
194 ?>