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 $fetchtemplates = array(
28 // TODO - add API for product.php
30 require_once('./global.php');
31 require_once('./includes/functions_datastore.php');
33 if (!can_perform('canadminversions'))
38 function construct_option_list($type_display, $type, $id, $edit, $addcomponent, $addversion, $delete, $displayorder)
42 $type = ($type == 'component' ? 'product' : $type);
43 $type_action = (($type == 'version') ? 'versionid' : 'productid');
47 $opt .= '<option value="product.php?do=edit' . $type . '&' . $type_action . '=' . $id . '">' . sprintf(T('Edit %1$s'), $type_display) . '</option
>';
52 $opt .= '<option value
="product.php?do=delete' . $type . '&' . $type_action . '=' . $id . '">' . sprintf(T('Delete %
1$s'), $type_display) . '</option>';
57 $opt .= '<option value="product.php?do=addproduct&productid=' . $id . '">' . T('Add Component') . '</option>';
62 $opt .= '<option value="product.php?do=addversion&productid=' . $id . '">' . T('Add Version') . '</option>';
65 $type = strtolower($type);
67 $name = $type . '_' . $id;
69 $displayorder = (($displayorder != -1) ? '<input type="text" name="displayorder[' . $name . ']" value="' . $displayorder . '" size="4" class="input" style="width:25px" /> ' : '');
71 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 . '\')" />';
74 // ###################################################################
76 if (empty($_REQUEST['do']))
78 $_REQUEST['do'] = 'modify';
81 // ###################################################################
83 if ($_REQUEST['do'] == 'killversion')
85 $input->inputClean('versionid', TYPE_UINT
);
86 $db->query("DELETE FROM " . TABLE_PREFIX
. "version WHERE versionid = " . $input->in
['versionid']);
87 $db->query("DELETE FROM " . TABLE_PREFIX
. "bug WHERE version = " . $input->in
['versionid']);
91 $admin->redirect('product.php?do=modify');
94 // ###################################################################
96 if ($_REQUEST['do'] == 'deleteversion')
98 $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
)));
101 // ###################################################################
103 if ($_REQUEST['do'] == 'insertversion')
105 $db->query("INSERT INTO " . TABLE_PREFIX
. "version (productid, version, displayorder, obsolete) VALUES (" . $input->inputClean('productid', TYPE_UINT
) . ", '" . $input->input_escape('version') . "', " . $input->inputClean('displayorder', TYPE_UINT
) . ", " . $input->inputClean('obsolete', TYPE_UINT
) . ")");
107 $admin->redirect('product.php?do=modify');
110 // ###################################################################
112 if ($_REQUEST['do'] == 'addversion')
114 $product = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX
. "product WHERE productid = " . $input->inputClean('productid', TYPE_UINT
));
117 $admin->error(L_INVALID_ID
);
120 $tpl = new BSTemplate('version_edit');
121 $tpl->vars
['product'] = $product;
122 $tpl->evaluate()->flush();
125 // ###################################################################
127 if ($_REQUEST['do'] == 'updateversion')
129 if (empty($input->in
['version']))
131 $admin->error(T('Please fill in a version number.'));
134 $db->query("UPDATE " . TABLE_PREFIX
. "version SET version = '" . $input->inputEscape('version') . "', displayorder = " . $input->inputClean('displayorder', TYPE_UINT
) . ", obsolete = " . $input->inputClean('obsolete', TYPE_UINT
) . " WHERE versionid = " . $input->inputClean('versionid', TYPE_UINT
));
137 $admin->redirect('product.php?do=modify');
140 // ###################################################################
142 if ($_REQUEST['do'] == 'editversion')
144 $tpl = new BSTemplate('version_edit');
146 $tpl->vars
['version'] = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX
. "version WHERE versionid = " . $input->inputClean('versionid', TYPE_UINT
));
147 if (!$tpl->vars
['version'])
149 $admin->error(L_INVALID_ID
);
152 $tpl->evaluate()->flush();
155 // ###################################################################
157 if ($_REQUEST['do'] == 'killproduct')
159 $input->inputClean('productid', TYPE_UINT
);
160 $allprods = $db->query("SELECT * FROM " . TABLE_PREFIX
. "product WHERE productid = " . $input->in
['productid'] . " OR parentid = " . $input->in
['productid']);
161 foreach ($allprods as $prod)
163 $list[] = $prod['productid'];
166 $db->query("DELETE FROM " . TABLE_PREFIX
. "product WHERE productid IN (" . implode(', ', $list) . ")");
167 $db->query("DELETE FROM " . TABLE_PREFIX
. "version WHERE productid IN (" . implode(', ', $list) . ")");
168 $db->query("DELETE FROM " . TABLE_PREFIX
. "bug WHERE product IN (" . implode(', ', $list) . ")");
172 $admin->redirect('product.php?do=modify');
175 // ###################################################################
177 if ($_REQUEST['do'] == 'deleteproduct')
179 $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
)));
182 // ###################################################################
184 if ($_REQUEST['do'] == 'insertproduct')
186 if (empty($input->in
['title']))
188 $admin->error(T('Please go back and fill in the title field.'));
192 INSERT INTO " . TABLE_PREFIX
. "product
193 (title, parentid, description, displayorder)
195 ('" . $input->inputEscape('title') . "', " . $input->inputClean('parentid', TYPE_UINT
) . ",
196 '" . $input->inputEscape('description') . "', " . $input->inputClean('displayorder', TYPE_UINT
) . "
201 $admin->redirect('product.php?do=modify');
204 // ###################################################################
206 if ($_REQUEST['do'] == 'addproduct')
208 $tpl = new BSTemplate('product_edit');
209 $tpl->vars
['parent'] = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX
. "product WHERE productid = " . $input->inputClean('productid', TYPE_UINT
));
210 $tpl->evaluate()->flush();
213 // ###################################################################
215 if ($_REQUEST['do'] == 'updateproduct')
217 if (empty($input->in
['title']))
219 $admin->error(T('Please go back and fill in the title field.'));
222 if (empty($input->in
['productid']))
224 $admin->error(L_INVALID_ID
);
227 $db->query("UPDATE " . TABLE_PREFIX
. "product SET title = '" . $input->inputEscape('title') . "', description = '" . $input->inputEscape('description') . "', displayorder = " . $input->inputClean('displayorder', TYPE_UINT
) . " WHERE productid = " . $input->inputClean('productid', TYPE_UINT
));
230 $admin->redirect('product.php?do=modify');
233 // ###################################################################
235 if ($_REQUEST['do'] == 'editproduct')
237 $tpl = new BSTemplate('product_edit');
238 $tpl->vars
['product'] = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX
. "product WHERE productid = " . $input->in
['productid']);
239 if (!is_array($tpl->vars
['product']))
241 $admin->error(L_INVALID_ID
);
243 $tpl->vars
['parent'] = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX
. "product WHERE productid = {$tpl->vars['product']['parentid']}");
245 $tpl->evaluate()->flush();
248 // ###################################################################
250 if ($_POST['do'] == 'displayorder')
252 $input->inputClean('displayorder', TYPE_UINT
);
253 if (is_array($input->in
['displayorder']))
255 foreach ($input->in
['displayorder'] as $namebit => $order)
257 $name = explode('_', $namebit);
258 if ($name[0] == 'product' || $name[0] == 'version')
260 $id = $input->clean($name[1], TYPE_UINT
);
261 $db->query("UPDATE " . TABLE_PREFIX
. "$name[0] SET displayorder = $order WHERE $name[0]id = $id");
268 admin_flash_redirect('product.php?do=modify');
271 // ###################################################################
273 if ($_REQUEST['do'] == 'modify')
275 $tpl = new BSTemplate('product');
277 $products_get = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "product ORDER BY displayorder ASC
");
278 $tpl->vars['products'] = $tpl->vars['components'] = $tpl->vars['version'] = array();
279 foreach ($products_get as $prod)
281 if (!$prod['parentid'])
283 $tpl->vars['products'][$prod['productid']] = $prod;
287 $tpl->vars['components'][$prod['parentid']][] = $prod;
289 $tpl->vars['version'][$prod['productid']] = array();
292 $versions_get = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "version ORDER BY displayorder ASC
");
293 foreach ($versions_get as $vers)
295 $tpl->vars['versions'][$vers['productid']][$vers['versionid']] = $vers;
298 $tpl->evaluate()->flush();