r1319: Show an error if a user does not have any favorites in his list but tries...
[bugdar.git] / favorite.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] 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 [#]gpl[#] 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 define('SVN', '$Id$');
23
24 if (empty($_REQUEST['do']))
25 {
26 $_REQUEST['do'] = 'manage';
27 }
28
29 $focus[ ($_REQUEST['do'] == 'handle' ? 'showreport' : 'favorites') ] = 'focus';
30
31 $fetchtemplates = array(
32 'favorites',
33 'trackerhome_bits'
34 );
35
36 require_once('./global.php');
37
38 // ###################################################################
39
40 if ($_REQUEST['do'] == 'handle')
41 {
42 $bugsys->input_clean('bugid', TYPE_UINT);
43 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . $bugsys->in['bugid']);
44 if (!check_bug_permissions($bug))
45 {
46 $message->error_permission();
47 }
48
49 if (!can_perform('cansubscribe', $bug['product']))
50 {
51 $message->error_permission();
52 }
53
54 if ($db->query_first("SELECT * FROM " . TABLE_PREFIX . "favorite WHERE userid = " . $bugsys->userinfo['userid'] . " AND bugid = " . $bugsys->in['bugid']))
55 {
56 $db->query("DELETE FROM " . TABLE_PREFIX . "favorite WHERE userid = " . $bugsys->userinfo['userid'] . " AND bugid = " . $bugsys->in['bugid']);
57 $message->redirect(_('This bug has been removed from your favorites list.'), "showreport.php?bugid=" . $bugsys->in['bugid']);
58 }
59 else
60 {
61 $db->query("INSERT INTO " . TABLE_PREFIX . "favorite (userid, bugid) VALUES (" . $bugsys->userinfo['userid'] . ", " . $bugsys->in['bugid'] . ")");
62 $message->redirect(_('This bug has been added to your favorites list.'), "showreport.php?bugid=" . $bugsys->in['bugid']);
63 }
64 }
65
66 // ###################################################################
67
68 if ($_REQUEST['do'] == 'manage')
69 {
70 if (!can_perform('canviewbugs'))
71 {
72 $message->error_permission();
73 }
74
75 $favorites = $db->query("
76 SELECT favorite.bugid, bug.* FROM " . TABLE_PREFIX . "favorite AS favorite
77 RIGHT JOIN " . TABLE_PREFIX . "bug AS bug
78 ON (favorite.bugid = bug.bugid)
79 WHERE favorite.userid = " . $bugsys->userinfo['userid'] . "
80 AND (!bug.hidden OR (bug.hidden AND bug.product IN (" . fetch_on_bits('canviewhidden') . "))" . (can_perform('canviewownhidden') ? " OR (bug.hidden AND bug.userid = " . $bugsys->userinfo['userid'] . " AND bug.product IN (" . fetch_on_bits('canviewownhidden') . "))" : "") . ")
81 ");
82
83 if ($db->num_rows($favorites) < 1)
84 {
85 $message->error(_('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.'));
86 }
87
88 while ($bug = $db->fetch_array($favorites))
89 {
90 $funct->exec_swap_bg($stylevar['alt_color'], '');
91 ProcessBugDataForDisplay(&$bug, $funct->bgcolour);
92 eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";');
93 }
94
95 eval('$template->flush("' . $template->fetch('favorites') . '");');
96 }
97
98 /*=====================================================================*\
99 || ###################################################################
100 || # $HeadURL$
101 || # $Id$
102 || ###################################################################
103 \*=====================================================================*/
104 ?>