Templateize admin/userhelp.php
[bugdar.git] / favorite.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
23 if (empty($_REQUEST['do']))
24 {
25 $_REQUEST['do'] = 'manage';
26 }
27
28 $focus[ ($_REQUEST['do'] == 'handle' ? 'showreport' : 'favorites') ] = 'focus';
29
30 $fetchtemplates = array(
31 'favorites',
32 'trackerhome_bits',
33 'list_head'
34 );
35
36 require_once('./global.php');
37 require_once('./includes/class_sort.php');
38
39 // ###################################################################
40
41 if ($_REQUEST['do'] == 'handle')
42 {
43 $input->inputClean('bugid', TYPE_UINT);
44 $bug = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . $input->in['bugid']);
45 if (!check_bug_permissions($bug))
46 {
47 $message->errorPermission();
48 }
49
50 if (!can_perform('cansubscribe', $bug['product']))
51 {
52 $message->errorPermission();
53 }
54
55 if ($db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "favorite WHERE userid = " . bugdar::$userinfo['userid'] . " AND bugid = " . $input->in['bugid']))
56 {
57 $db->query("DELETE FROM " . TABLE_PREFIX . "favorite WHERE userid = " . bugdar::$userinfo['userid'] . " AND bugid = " . $input->in['bugid']);
58 $message->redirect(T('This bug has been removed from your favorites list.'), "showreport.php?bugid=" . $input->in['bugid']);
59 }
60 else
61 {
62 $db->query("INSERT INTO " . TABLE_PREFIX . "favorite (userid, bugid) VALUES (" . bugdar::$userinfo['userid'] . ", " . $input->in['bugid'] . ")");
63 $message->redirect(T('This bug has been added to your favorites list.'), "showreport.php?bugid=" . $input->in['bugid']);
64 }
65 }
66
67 // ###################################################################
68
69 if ($_REQUEST['do'] == 'manage')
70 {
71 if (!can_perform('canviewbugs'))
72 {
73 $message->errorPermission();
74 }
75
76 $favorites = $db->query("
77 SELECT favorite.bugid, bug.* FROM " . TABLE_PREFIX . "favorite AS favorite
78 RIGHT JOIN " . TABLE_PREFIX . "bug AS bug
79 ON (favorite.bugid = bug.bugid)
80 WHERE favorite.userid = " . bugdar::$userinfo['userid'] . "
81 AND (!bug.hidden OR (bug.hidden AND bug.product IN (" . fetch_on_bits('canviewhidden') . "))" . (can_perform('canviewownhidden') ? " OR (bug.hidden AND bug.userid = " . bugdar::$userinfo['userid'] . " AND bug.product IN (" . fetch_on_bits('canviewownhidden') . "))" : "") . ")
82 ");
83
84 if ($favorites->size() < 1)
85 {
86 $message->error(T('You do not have any favorites in your list. To add a bug to your list, while viewing the report, click the [Add to Favorites] link next to the bug\'s ID.'));
87 }
88
89 $sort = new ListSorter('favorite');
90
91 $headers = $sort->constructColumnHeaders(false);
92
93 foreach ($favorites as $bug)
94 {
95 BSFunctions::swap_css_classes('altcolor', '');
96 $bug = ProcessBugDataForDisplay($bug, BSFunctions::$cssClass);
97 $bugs .= $sort->constructRow($bug);
98 }
99
100 $tpl = new BSTemplate('favorites');
101 $tpl->vars = array(
102 'bugs' => $bugs,
103 'headers' => $headers
104 );
105 $tpl->evaluate()->flush();
106 }
107
108 ?>