44996913daaa170e089b8057561cf964ec81e240
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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 [#]gpl[#] of the License.
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
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 \*=====================================================================*/
22 // #*# add API for product.php
24 require_once('./global.php');
25 require_once('./includes/functions_datastore.php');
27 NavLinks
::productsAdd();
28 $navigator->set_focus('tab', 'products', null
);
30 if (!can_perform('canadminversions'))
35 function construct_option_list($type, $id, $edit, $addcomponent, $addversion, $delete, $displayorder)
39 $type_display = $type;
40 $type = strtolower($type);
41 $type = ($type == 'component' ?
'product' : $type);
42 $type_action = (($type == 'version') ?
'versionid' : 'productid');
46 $opt .= '<option value="product.php?do=edit' . $type . '&' . $type_action . '=' . $id . '">' . sprintf($bugsys->lang
->string('Edit %1$s'), $type_display) . '</option>';
51 $opt .= '<option value="product.php?do=delete' . $type . '&' . $type_action . '=' . $id . '">' . sprintf($bugsys->lang
->string('Delete %1$s'), $type_display) . '</option>';
56 $opt .= '<option value="product.php?do=addproduct&productid=' . $id . '">' . $bugsys->lang
->string('Add Component') . '</option>';
61 $opt .= '<option value="product.php?do=addversion&productid=' . $id . '">' . $bugsys->lang
->string('Add Version') . '</option>';
64 $type = strtolower($type);
66 $name = $type . '_' . $id;
68 $displayorder = (($displayorder != -1) ?
'<input type="text" name="displayorder[' . $name . ']" value="' . $displayorder . '" size="4" class="input" /> ' : '');
70 return $displayorder . '<select id="' . $name . '" name="' . $name . '" onchange="exec_action(\'' . $name . '\')" class="input">' . $opt . '</select> <input type="button" class="button" name="gobutton" value=" ' . $bugsys->lang
->string('Go') . ' " onclick="exec_action(\'' . $name . '\')" />';
73 // ###################################################################
75 if (empty($_REQUEST['do']))
77 $_REQUEST['do'] = 'modify';
80 // ###################################################################
82 if ($_REQUEST['do'] == 'killversion')
84 $bugsys->input_clean('versionid', TYPE_UINT
);
85 $db->query("DELETE FROM " . TABLE_PREFIX
. "version WHERE versionid = " . $bugsys->in
['versionid']);
86 $db->query("DELETE FROM " . TABLE_PREFIX
. "bug WHERE versionid = " . $bugsys->in
['versionid']);
90 $admin->redirect('product.php?do=modify');
93 // ###################################################################
95 if ($_REQUEST['do'] == 'deleteversion')
97 $admin->page_confirm($lang->string('Are you sure you want to delete this version? Doing so will do <strong>delete all the bugs with this version</strong>.'), 'product.php?do=killversion&versionid=' . $bugsys->input_clean('versionid', TYPE_UINT
));
100 // ###################################################################
102 if ($_REQUEST['do'] == 'insertversion')
104 $db->query("INSERT INTO " . TABLE_PREFIX
. "version (productid, version, displayorder) VALUES (" . $bugsys->input_clean('productid', TYPE_UINT
) . ", '" . $bugsys->in
['version'] . "', " . $bugsys->input_clean('displayorder', TYPE_UINT
) . ")");
106 $admin->redirect('product.php?do=modify');
109 // ###################################################################
111 if ($_REQUEST['do'] == 'addversion')
113 NavLinks
::productsEdit($bugsys->input_clean('productid', TYPE_UINT
));
114 $navigator->set_focus('link', 'products-edit-version', 'products-edit');
116 $admin->page_start($lang->string('Add Version'));
118 if ($bugsys->in
['productid'] != -1)
120 $product = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "product WHERE productid = " . $bugsys->in
['productid']);
121 if (!is_array($product))
123 $admin->error($lang->getlex('error_invalid_id'));
128 $bugsys->in
['productid'] = 0;
131 $admin->form_start('product.php', 'insertversion');
132 $admin->form_hidden_field('productid', $bugsys->in
['productid']);
133 $admin->table_start();
134 $admin->table_head($lang->string('Add New Version'));
135 $admin->row_input($lang->string('Version Number<div><dfn>This is the version string for this product.</dfn></div>'), 'version');
136 $admin->row_input($lang->string('Display Order<div><dfn>The order in which the versions are displayed.</dfn></div>'), 'displayorder');
137 $admin->row_submit();
144 // ###################################################################
146 if ($_REQUEST['do'] == 'updateversion')
148 if (empty($bugsys->in
['version']))
150 $admin->error($lang->string('Please fill in a version number.'));
153 $db->query("UPDATE " . TABLE_PREFIX
. "version SET version = '" . $bugsys->in
['version'] . "', displayorder = " . $bugsys->input_clean('displayorder', TYPE_UINT
) . " WHERE versionid = " . $bugsys->input_clean('versionid', TYPE_UINT
));
156 $admin->redirect('product.php?do=modify');
159 // ###################################################################
161 if ($_REQUEST['do'] == 'editversion')
163 $admin->page_start($lang->string('Edit Version'));
165 $version = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "version WHERE versionid = " . $bugsys->input_clean('versionid', TYPE_UINT
));
166 if (!is_array($version))
168 $admin->error($lang->getlex('error_invalid_id'));
171 $admin->form_start('product.php', 'updateversion');
172 $admin->form_hidden_field('versionid', $version['versionid']);
173 $admin->table_start();
174 $admin->table_head(sprintf($lang->string('Edit Version - %1$s'), $version['version']));
175 $admin->row_input($lang->string('Version Number<div><dfn>This is the version string for this product.</dfn></div>'), 'version', $version['version']);
176 $admin->row_input($lang->string('Display Order<div><dfn>The order in which the versions are displayed.</dfn></div>'), 'displayorder', $version['displayorder']);
177 $admin->row_submit();
184 // ###################################################################
186 if ($_REQUEST['do'] == 'killproduct')
188 $bugsys->input_clean('productid', TYPE_UINT
);
189 $allprods = $db->query("SELECT * FROM " . TABLE_PREFIX
. "product WHERE productid = " . $bugsys->in
['productid'] . " OR componentmother = " . $bugsys->in
['productid']);
190 while ($prod = $db->fetch_array($allprods))
192 $list[] = $prod['productid'];
195 $db->query("DELETE FROM " . TABLE_PREFIX
. "product WHERE productid IN (" . implode(', ', $list) . ")");
196 $db->query("DELETE FROM " . TABLE_PREFIX
. "version WHERE productid IN (" . implode(', ', $list) . ")");
197 $db->query("DELETE FROM " . TABLE_PREFIX
. "bug WHERE productid IN (" . implode(', ', $list) . ")");
201 $admin->redirect('product.php?do=modify');
204 // ###################################################################
206 if ($_REQUEST['do'] == 'deleteproduct')
208 $admin->page_confirm($lang->string('Are you sure you want to delete this product and all of it\'s versions and components <strong>and any bugs that have been assigned those products or components</strong>?'), 'product.php?do=killproduct&productid=' . $bugsys->input_clean('productid', TYPE_UINT
));
211 // ###################################################################
213 if ($_REQUEST['do'] == 'insertproduct')
215 if (empty($bugsys->in
['title']))
217 $admin->error($lang->string('Please go back and fill in the title field.'));
221 INSERT INTO " . TABLE_PREFIX
. "product
222 (title, componentmother, description, displayorder)
224 ('" . $bugsys->in
['title'] . "', " . $bugsys->input_clean('componentmother', TYPE_UINT
) . ",
225 '" . $bugsys->in
['description'] . "', " . $bugsys->input_clean('displayorder', TYPE_UINT
) . "
230 $admin->redirect('product.php?do=modify');
233 // ###################################################################
235 if ($_REQUEST['do'] == 'addproduct')
237 if ($bugsys->input_clean('productid', TYPE_UINT
))
239 NavLinks
::productsEdit($bugsys->in
['productid']);
243 NavLinks
::productsAdd();
245 $navigator->set_focus('link', 'products-add', 'products');
247 $admin->page_start($lang->string('Add New Product'));
249 $admin->form_start('product.php', 'insertproduct');
250 $admin->form_hidden_field('componentmother', $bugsys->in
['productid']);
251 $admin->table_start();
252 $admin->table_head($lang->string('Add Product'));
253 $admin->row_input($lang->string('Title'), 'title');
254 $admin->row_textarea($lang->string('Description<div><dfn>A short description of this product.</dfn></div>'), 'description');
255 $admin->row_input($lang->string('Display Order<div><dfn>The order in which the products are displayed.</dfn></div>'), 'displayorder');
256 $admin->row_submit();
263 // ###################################################################
265 if ($_REQUEST['do'] == 'updateproduct')
267 if (empty($bugsys->in
['title']))
269 $admin->error($lang->string('Please go back and fill in the title field.'));
272 if (empty($bugsys->in
['productid']))
274 $admin->error($lang->getlex('error_invalid_id'));
277 $db->query("UPDATE " . TABLE_PREFIX
. "product SET title = '" . $bugsys->in
['title'] . "', description = '" . $bugsys->in
['description'] . "', displayorder = " . $bugsys->input_clean('displayorder', TYPE_UINT
) . " WHERE productid = " . $bugsys->input_clean('productid', TYPE_UINT
));
280 $admin->redirect('product.php?do=modify');
283 // ###################################################################
285 if ($_REQUEST['do'] == 'editproduct')
287 NavLinks
::productsEdit($bugsys->input_clean('productid', TYPE_UINT
));
288 $navigator->set_focus('link', 'products-edit', 'products-edit');
290 $admin->page_start($lang->string('Edit Product'));
292 $product = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "product WHERE productid = " . $bugsys->in
['productid']);
293 if (!is_array($product))
295 $admin->error($lang->getlex('error_invalid_id'));
298 $admin->form_start('product.php', 'updateproduct');
299 $admin->form_hidden_field('productid', $product['productid']);
300 $admin->table_start();
301 $admin->table_head(sprintf($lang->string('Edit Product - %1$s'), $product['title']));
302 $admin->row_input($lang->string('Title'), 'title', $product['title']);
303 $admin->row_textarea($lang->string('Description<div><dfn>A short description of this product.</dfn></div>'), 'description', $product['description']);
304 $admin->row_input($lang->string('Display Order<div><dfn>The order in which the products are displayed.</dfn></div>'), 'displayorder', $product['displayorder']);
305 $admin->row_submit();
312 // ###################################################################
314 if ($_POST['do'] == 'displayorder')
316 $bugsys->input_clean('displayorder', TYPE_UINT
);
317 foreach ($bugsys->in
['displayorder'] AS $namebit => $displayorder)
319 $name = explode('_', $namebit);
320 if ($name[0] == 'product' OR $name[0] == 'version')
322 $id = $bugsys->clean($name[1], TYPE_UINT
);
323 $order = $displayorder;
324 $db->query("UPDATE " . TABLE_PREFIX
. "$name[0] SET displayorder = $order WHERE $name[0]id = $id");
329 $admin->redirect('product.php?do=modify');
332 // ###################################################################
334 if ($_REQUEST['do'] == 'modify')
336 $navigator->set_focus('link', 'products-manage', 'products');
338 $admin->page_start($lang->string('Products and Versions'));
341 <script type
="text/javascript">
343 function exec_action(name
)
345 window
.location
= document
.getElementById(name
).value
;
351 $admin->page_code($javascript);
353 $admin->form_start('product.php', 'displayorder');
355 $products = $db->query("SELECT * FROM " . TABLE_PREFIX
. "product ORDER BY displayorder ASC");
356 while ($prod = $db->fetch_array($products))
358 if (!$prod['componentmother'])
360 $product["$prod[productid]"] = $prod;
364 $component["$prod[componentmother]"][] = $prod;
366 $version["$prod[productid]"] = array();
368 $products = (array)$product;
370 $versions = $db->query("SELECT * FROM " . TABLE_PREFIX
. "version ORDER BY displayorder ASC");
371 while ($vers = $db->fetch_array($versions))
373 $version["$vers[productid]"]["$vers[versionid]"] = $vers;
375 $versions = (array)$version;
377 $admin->table_start();
378 $admin->table_head($lang->string('Products / Versions'));
380 // Handle our global versions
381 if (is_array($versions['0']))
383 $admin->row_text($lang->string('Global Versions'), construct_option_list($lang->string('Product'), -1, 0, 0, 1, 0, -1), 'middle', 2, 'alt3');
384 foreach ($versions['0'] AS $version)
386 $admin->row_text('-- ' . $version['version'], construct_option_list($lang->string('Version'), $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
390 // Now let's do the rest of the versions
391 foreach ($products AS $product)
394 $admin->row_text("<a href=\"product.php?do=editproduct&productid=$product[productid]\">$product[title]</a>", construct_option_list($lang->string('Product'), $product['productid'], 1, 1, 1, 1, $product['displayorder']), 'middle', 2, 'alt3');
397 foreach ($versions["$product[productid]"] AS $version)
399 $admin->row_text('-- ' . $version['version'], construct_option_list($lang->string('Version'), $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
403 foreach ((array)$component["$product[productid]"] AS $comp)
405 $admin->row_text("-- <a href=\"product.php?do=editproduct&productid=$comp[productid]\">$comp[title]</a>", construct_option_list($lang->string('Component'), $comp['productid'], 1, 0, 1, 1, $comp['displayorder']), 'middle', 2, 'alt1');
407 // Component versions
408 foreach ($versions["$comp[productid]"] AS $version)
410 $admin->row_text('---- ' . $version['version'], construct_option_list($lang->string('Version'), $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
415 $admin->row_submit(null
, $lang->string('Save Display Order'), null
);
424 /*=====================================================================*\
425 || ###################################################################
428 || ###################################################################
429 \*=====================================================================*/