r873: Create a favourites list page
[bugdar.git] / favourite.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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' : 'favourites') ] = 'focus';
30
31 $fetchtemplates = array(
32 'favourites',
33 'trackerhome_bits'
34 );
35
36 require_once('./global.php');
37
38 // ###################################################################
39
40 if ($_REQUEST['do'] == 'handle')
41 {
42 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . intval($bugsys->in['bugid']));
43 if (!$bug OR (!can_perform('canviewhidden', $bug['productid']) AND $bug['hidden']))
44 {
45 $message->error($lang->getlex('error_invalid_id'));
46 }
47
48 if (!can_perform('cansubscribe', $bug['productid']) OR !can_perform('canviewbugs', $bug['productid']))
49 {
50 $message->error_permission();
51 }
52
53 if ($db->query_first("SELECT * FROM " . TABLE_PREFIX . "favourite WHERE userid = " . $bugsys->userinfo['userid'] . " AND bugid = " . intval($bugsys->in['bugid'])))
54 {
55 $db->query("DELETE FROM " . TABLE_PREFIX . "favourite WHERE userid = " . $bugsys->userinfo['userid'] . " AND bugid = " . intval($bugsys->in['bugid']));
56 $message->redirect($lang->string('This bug has been removed from your favourites list.'), "showreport.php?bugid=" . intval($bugsys->in['bugid']));
57 }
58 else
59 {
60 $db->query("INSERT INTO " . TABLE_PREFIX . "favourite (userid, bugid) VALUES (" . $bugsys->userinfo['userid'] . ", " . intval($bugsys->in['bugid']) . ")");
61 $message->redirect($lang->string('This bug has been added to your favourites list.'), "showreport.php?bugid=" . intval($bugsys->in['bugid']));
62 }
63 }
64
65 // ###################################################################
66
67 if ($_REQUEST['do'] == 'manage')
68 {
69 $favourites = $db->query("
70 SELECT favourite.bugid, bug.* FROM " . TABLE_PREFIX . "favourite AS favourite
71 RIGHT JOIN " . TABLE_PREFIX . "bug AS bug
72 ON (favourite.bugid = bug.bugid)
73 WHERE favourite.userid = " . $bugsys->userinfo['userid']
74 );
75 while ($bug = $db->fetch_array($favourites))
76 {
77 $funct->exec_swap_bg($stylevar['alt_colour'], '');
78 $bug['bgcolour'] = ($bugsys->userinfo['showcolours'] ? $bugsys->datastore['status']["$bug[status]"]['color'] : $funct->bgcolour);
79 $bug['product'] = $bugsys->datastore['product']["$bug[productid]"]['title'];
80 $bug['version'] = $bugsys->datastore['version']["$bug[versionid]"]['version'];
81 $bug['status'] = $bugsys->datastore['status']["$bug[status]"]['status'];
82 $bug['resolution'] = $bugsys->datastore['resolution']["$bug[resolution]"]['resolution'];
83 $bug['priority'] = $bugsys->datastore['priority']["$bug[priority]"]['priority'];
84 $bug['severity'] = $bugsys->datastore['severity']["$bug[severity]"]['severity'];
85
86 $bug['hiddendisplay'] = ((!can_perform('canviewhidden', $bug['productid']) AND $bug['hiddenlastposttime']) ? true : false);
87
88 $bug['lastposttime'] = ($bug['hiddendisplay'] ? $bug['hiddenlastposttime'] : $bug['lastposttime']);
89 $bug['lastpost'] = ($bug['hiddendisplay'] ? $bug['hiddenlastpostbyname'] : $bug['lastpostbyname']);
90
91 $bug['lastposttime'] = $datef->format($bugsys->options['dateformat'], $bug['lastposttime']);
92 eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";');
93 }
94
95 eval('$template->flush("' . $template->fetch('favourites') . '");');
96 }
97
98 /*=====================================================================*\
99 || ###################################################################
100 || # $HeadURL$
101 || # $Id$
102 || ###################################################################
103 \*=====================================================================*/
104 ?>