2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2004-2009 Blue Static
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.
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 // TODO - 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_display, $type, $id, $edit, $addcomponent, $addversion, $delete, $displayorder)
39 $type = ($type == 'component' ? 'product' : $type);
40 $type_action = (($type == 'version') ? 'versionid' : 'productid');
44 $opt .= '<option value="product.php?do=edit' . $type . '&' . $type_action . '=' . $id . '">' . sprintf(T('Edit %1$s'), $type_display) . '</option
>';
49 $opt .= '<option value
="product.php?do=delete' . $type . '&' . $type_action . '=' . $id . '">' . sprintf(T('Delete %
1$s'), $type_display) . '</option>';
54 $opt .= '<option value="product.php?do=addproduct&productid=' . $id . '">' . T('Add Component') . '</option>';
59 $opt .= '<option value="product.php?do=addversion&productid=' . $id . '">' . T('Add Version') . '</option>';
62 $type = strtolower($type);
64 $name = $type . '_' . $id;
66 $displayorder = (($displayorder != -1) ? '<input type="text" name="displayorder[' . $name . ']" value="' . $displayorder . '" size="4" class="input" /> ' : '');
68 return $displayorder . '<select id="' . $name . '" name="' . $name . '" onchange="exec_action(\'' . $name . '\')" class="input">' . $opt . '</select> <input type="button" class="button" name="gobutton" value=" ' . T('Go') . ' " onclick="exec_action(\'' . $name . '\')" />';
71 // ###################################################################
73 if (empty($_REQUEST['do']))
75 $_REQUEST['do'] = 'modify';
78 // ###################################################################
80 if ($_REQUEST['do'] == 'killversion')
82 $input->inputClean('versionid', TYPE_UINT
);
83 $db->query("DELETE FROM " . TABLE_PREFIX
. "version WHERE versionid = " . $input->in
['versionid']);
84 $db->query("DELETE FROM " . TABLE_PREFIX
. "bug WHERE version = " . $input->in
['versionid']);
88 $admin->redirect('product.php?do=modify');
91 // ###################################################################
93 if ($_REQUEST['do'] == 'deleteversion')
95 $admin->page_confirm(T('Are you sure you want to delete this version? Doing so will do <strong>delete all the bugs with this version</strong>.'), 'product.php', 'killversion', array('versionid' => $input->inputClean('versionid', TYPE_UINT
)));
98 // ###################################################################
100 if ($_REQUEST['do'] == 'insertversion')
102 $db->query("INSERT INTO " . TABLE_PREFIX
. "version (productid, version, displayorder, obsolete) VALUES (" . $input->inputClean('productid', TYPE_UINT
) . ", '" . $bugsys->input_escape('version') . "', " . $input->inputClean('displayorder', TYPE_UINT
) . ", " . $input->inputClean('obsolete', TYPE_UINT
) . ")");
104 $admin->redirect('product.php?do=modify');
107 // ###################################################################
109 if ($_REQUEST['do'] == 'addversion')
111 NavLinks
::productsEdit($input->inputClean('productid', TYPE_UINT
));
112 $navigator->set_focus('link', 'products-edit-version', 'products-edit');
114 if ($input->in
['productid'] != -1)
116 $product = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX
. "product WHERE productid = " . $input->in
['productid']);
117 if (!is_array($product))
119 $admin->error(L_INVALID_ID
);
124 $input->in
['productid'] = 0;
127 $admin->page_start(T('Add Version'));
129 $admin->form_start('product.php', 'insertversion');
130 $admin->form_hidden_field('productid', $input->in
['productid']);
131 $admin->table_start();
132 $admin->table_head(T('Add New Version'));
133 $admin->row_input(T('Version Number<div><dfn>This is the version string for this product.</dfn></div>'), 'version');
134 $admin->row_input(T('Display Order<div><dfn>The order in which the versions are displayed.</dfn></div>'), 'displayorder');
135 $admin->row_yesno(T('Obsolete<div><dfn>An obsolete version cannot have new bugs filed against it, but existing ones can be set to it.</dfn></div>'), 'obsolete', false);
136 $admin->row_submit();
143 // ###################################################################
145 if ($_REQUEST['do'] == 'updateversion')
147 if (empty($input->in
['version']))
149 $admin->error(T('Please fill in a version number.'));
152 $db->query("UPDATE " . TABLE_PREFIX
. "version SET version = '" . $bugsys->input_escape('version') . "', displayorder = " . $input->inputClean('displayorder', TYPE_UINT
) . ", obsolete = " . $input->inputClean('obsolete', TYPE_UINT
) . " WHERE versionid = " . $input->inputClean('versionid', TYPE_UINT
));
155 $admin->redirect('product.php?do=modify');
158 // ###################################################################
160 if ($_REQUEST['do'] == 'editversion')
162 $admin->page_start(T('Edit Version'));
164 $version = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX
. "version WHERE versionid = " . $input->inputClean('versionid', TYPE_UINT
));
165 if (!is_array($version))
167 $admin->error(L_INVALID_ID
);
170 $admin->form_start('product.php', 'updateversion');
171 $admin->form_hidden_field('versionid', $version['versionid']);
172 $admin->table_start();
173 $admin->table_head(sprintf(T('Edit Version - %1$s'), $version['version
']));
174 $admin->row_input(T('Version Number
<div
><dfn
>This is the version
string for this product
.</dfn
></div
>'), 'version
', $version['version
']);
175 $admin->row_input(T('Display Order
<div
><dfn
>The order in which the versions are displayed
.</dfn
></div
>'), 'displayorder
', $version['displayorder
']);
176 $admin->row_yesno(T('Obsolete
<div
><dfn
>An obsolete version cannot have
new bugs filed against it
, but existing ones can be set to it
.</dfn
></div
>'), 'obsolete
', $version['obsolete
']);
177 $admin->row_submit();
184 // ###################################################################
186 if ($_REQUEST['do'] == 'killproduct
')
188 $input->inputClean('productid
', TYPE_UINT);
189 $allprods = $db->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . $input->in['productid
'] . " OR parentid = " . $input->in['productid
']);
190 foreach ($allprods as $prod)
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 product IN (" . implode(', ', $list) . ")");
201 $admin->redirect('product
.php
?do=modify
');
204 // ###################################################################
206 if ($_REQUEST['do'] == 'deleteproduct
')
208 $admin->page_confirm(T('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
', 'killproduct
', array('productid
' => $input->inputClean('productid
', TYPE_UINT)));
211 // ###################################################################
213 if ($_REQUEST['do'] == 'insertproduct
')
215 if (empty($input->in['title
']))
217 $admin->error(T('Please go back
and fill in the title field
.'));
221 INSERT INTO " . TABLE_PREFIX . "product
222 (title, parentid, description, displayorder)
224 ('" . $bugsys->input_escape('title') . "', " . $input->inputClean('parentid
', TYPE_UINT) . ",
225 '" . $bugsys->input_escape('description') . "', " . $input->inputClean('displayorder
', TYPE_UINT) . "
230 $admin->redirect('product
.php
?do=modify
');
233 // ###################################################################
235 if ($_REQUEST['do'] == 'addproduct
')
237 if ($input->inputClean('productid
', TYPE_UINT))
239 NavLinks::productsEdit($input->in['productid
']);
243 NavLinks::productsAdd();
245 $navigator->set_focus('link
', 'products
-add
', 'products
');
247 $admin->page_start(T('Add
New Product
'));
249 $admin->form_start('product
.php
', 'insertproduct
');
250 $admin->form_hidden_field('parentid
', $input->in['productid
']);
251 $admin->table_start();
252 $admin->table_head(T('Add Product
'));
253 $admin->row_input(T('Title
'), 'title
');
254 $admin->row_textarea(T('Description
<div
><dfn
>A short description of this product
.</dfn
></div
>'), 'description
');
255 $admin->row_input(T('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($input->in['title
']))
269 $admin->error(T('Please go back
and fill in the title field
.'));
272 if (empty($input->in['productid
']))
274 $admin->error(L_INVALID_ID);
277 $db->query("UPDATE " . TABLE_PREFIX . "product SET title = '" . $bugsys->input_escape('title') . "', description = '" . $bugsys->input_escape('description') . "', displayorder = " . $input->inputClean('displayorder
', TYPE_UINT) . " WHERE productid = " . $input->inputClean('productid
', TYPE_UINT));
280 $admin->redirect('product
.php
?do=modify
');
283 // ###################################################################
285 if ($_REQUEST['do'] == 'editproduct
')
287 NavLinks::productsEdit($input->inputClean('productid
', TYPE_UINT));
288 $navigator->set_focus('link
', 'products
-edit
', 'products
-edit
');
290 $admin->page_start(T('Edit Product
'));
292 $product = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . $input->in['productid
']);
293 if (!is_array($product))
295 $admin->error(L_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(T('Edit Product
- %
1$s'), $product['title']));
302 $admin->row_input(T('Title'), 'title', $product['title']);
303 $admin->row_textarea(T('Description<div><dfn>A short description of this product.</dfn></div>'), 'description', $product['description']);
304 $admin->row_input(T('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 $input->inputClean('displayorder', TYPE_UINT
);
317 if (is_array($input->in
['displayorder']))
319 foreach ($input->in
['displayorder'] AS $namebit => $displayorder)
321 $name = explode('_', $namebit);
322 if ($name[0] == 'product' OR $name[0] == 'version')
324 $id = $bugsys->clean($name[1], TYPE_UINT
);
325 $order = $displayorder;
326 $db->query("UPDATE " . TABLE_PREFIX
. "$name[0] SET displayorder = $order WHERE $name[0]id = $id");
332 $admin->redirect('product.php?do=modify');
335 // ###################################################################
337 if ($_REQUEST['do'] == 'modify')
339 $navigator->set_focus('link', 'products-manage', 'products');
341 $admin->page_start(T('Products and Versions'));
344 <script type="text
/javascript
">
346 function exec_action(name)
348 window.location = document.getElementById(name).value;
354 $admin->page_code($javascript);
356 $admin->form_start('product.php', 'displayorder');
358 $products_get = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "product ORDER BY displayorder ASC
");
360 foreach ($products_get as $prod)
362 if (!$prod['parentid'])
364 $products["$prod[productid
]"] = $prod;
368 $components["$prod[parentid
]"][] = $prod;
370 $version["$prod[productid
]"] = array();
373 $versions_get = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "version ORDER BY displayorder ASC
");
375 foreach ($versions_get as $vers)
377 $versions["$vers[productid
]"]["$vers[versionid
]"] = $vers;
380 $admin->table_start();
381 $admin->table_head(T('Products / Versions'));
383 // Handle our global versions
384 if (is_array($versions['0']))
386 $admin->row_text(T('Global Versions'), construct_option_list(T('Product'), 'product', -1, 0, 0, 1, 0, -1), 'middle', 2, 'alt3');
387 foreach ($versions['0'] AS $version)
389 $admin->row_text('-- ' . $version['version'], construct_option_list(T('Version'), 'version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
393 // Now let's do the rest of the versions
394 foreach ($products AS $product)
397 $admin->row_text("<a href
=\"product
.php
?do=editproduct
&
;productid
=$product[productid
]\">$product[title
]</a
>", construct_option_list(T('Product'), 'product', $product['productid'], 1, 1, 1, 1, $product['displayorder']), 'middle', 2, 'alt3');
400 if (is_array($versions["$product[productid
]"]))
402 foreach ($versions["$product[productid
]"] AS $version)
404 $admin->row_text('-- ' . $version['version'], construct_option_list(T('Version'), 'version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
409 if (is_array($components["$product[productid
]"]))
411 foreach ($components["$product[productid
]"] AS $comp)
413 $admin->row_text("-- <a href
=\"product
.php
?do=editproduct
&
;productid
=$comp[productid
]\">$comp[title
]</a
>", construct_option_list(T('Component'), 'component', $comp['productid'], 1, 0, 1, 1, $comp['displayorder']), 'middle', 2, 'alt1');
415 // Component versions
416 if (is_array($versions["$comp[productid
]"]))
418 foreach ($versions["$comp[productid
]"] AS $version)
420 $admin->row_text('---- ' . $version['version'], construct_option_list(T('Version'), 'version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
427 $admin->row_submit(null, T('Save Display Order'), null);