Switch the 'modify' code of admin/field.php to use templates
[bugdar.git] / favorite.php
index 5b58022fdd423328175e3c60db422e8936113c6b..7f86c025535fb6ac809c38b6b14048fe05546955 100644 (file)
@@ -1,12 +1,12 @@
 <?php
 /*=====================================================================*\
 || ###################################################################
-|| # Bugdar [#]version[#]
-|| # Copyright ©2002-[#]year[#] Blue Static
+|| # Bugdar
+|| # Copyright (c)2004-2009 Blue Static
 || #
 || # This program is free software; you can redistribute it and/or modify
 || # it under the terms of the GNU General Public License as published by
-|| # the Free Software Foundation; version [#]gpl[#] of the License.
+|| # the Free Software Foundation; version 2 of the License.
 || #
 || # This program is distributed in the hope that it will be useful, but
 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
@@ -19,7 +19,6 @@
 || ###################################################################
 \*=====================================================================*/
 
-define('SVN', '$Id$');
 
 if (empty($_REQUEST['do']))
 {
@@ -29,37 +28,39 @@ if (empty($_REQUEST['do']))
 $focus[ ($_REQUEST['do'] == 'handle' ? 'showreport' : 'favorites') ] = 'focus';
 
 $fetchtemplates = array(
-       'favourites',
-       'trackerhome_bits'
+       'favorites',
+       'trackerhome_bits',
+       'list_head'
 );
 
 require_once('./global.php');
+require_once('./includes/class_sort.php');
 
 // ###################################################################
 
 if ($_REQUEST['do'] == 'handle')
 {
-       $bugsys->input_clean('bugid', TYPE_UINT);
-       $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . $bugsys->in['bugid']);
-       if (!$bug OR (!can_perform('canviewhidden', $bug['product']) AND $bug['hidden']))
+       $input->inputClean('bugid', TYPE_UINT);
+       $bug = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . $input->in['bugid']);
+       if (!check_bug_permissions($bug))
        {
-               $message->error($lang->getlex('error_invalid_id'));
+               $message->errorPermission();
        }
        
-       if (!can_perform('cansubscribe', $bug['product']) OR !can_perform('canviewbugs', $bug['product']))
+       if (!can_perform('cansubscribe', $bug['product']))
        {
-               $message->error_permission();
+               $message->errorPermission();
        }
        
-       if ($db->query_first("SELECT * FROM " . TABLE_PREFIX . "favourite WHERE userid = " . $bugsys->userinfo['userid'] . " AND bugid = " . $bugsys->in['bugid']))
+       if ($db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "favorite WHERE userid = " . bugdar::$userinfo['userid'] . " AND bugid = " . $input->in['bugid']))
        {
-               $db->query("DELETE FROM " . TABLE_PREFIX . "favourite WHERE userid = " . $bugsys->userinfo['userid'] . " AND bugid = " . $bugsys->in['bugid']);
-               $message->redirect(_('This bug has been removed from your favorites list.'), "showreport.php?bugid=" . $bugsys->in['bugid']);
+               $db->query("DELETE FROM " . TABLE_PREFIX . "favorite WHERE userid = " . bugdar::$userinfo['userid'] . " AND bugid = " . $input->in['bugid']);
+               $message->redirect(T('This bug has been removed from your favorites list.'), "showreport.php?bugid=" . $input->in['bugid']);
        }
        else
        {
-               $db->query("INSERT INTO " . TABLE_PREFIX . "favourite (userid, bugid) VALUES (" . $bugsys->userinfo['userid'] . ", " . $bugsys->in['bugid'] . ")");
-               $message->redirect(_('This bug has been added to your favorites list.'), "showreport.php?bugid=" . $bugsys->in['bugid']);
+               $db->query("INSERT INTO " . TABLE_PREFIX . "favorite (userid, bugid) VALUES (" . bugdar::$userinfo['userid'] . ", " . $input->in['bugid'] . ")");
+               $message->redirect(T('This bug has been added to your favorites list.'), "showreport.php?bugid=" . $input->in['bugid']);
        }
 }
 
@@ -67,39 +68,41 @@ if ($_REQUEST['do'] == 'handle')
 
 if ($_REQUEST['do'] == 'manage')
 {
-       $favourites = $db->query("
-               SELECT favourite.bugid, bug.* FROM " . TABLE_PREFIX . "favourite AS favourite
+       if (!can_perform('canviewbugs'))
+       {
+               $message->errorPermission();
+       }
+       
+       $favorites = $db->query("
+               SELECT favorite.bugid, bug.* FROM " . TABLE_PREFIX . "favorite AS favorite
                RIGHT JOIN " . TABLE_PREFIX . "bug AS bug
-                       ON (favourite.bugid = bug.bugid)
-               WHERE favourite.userid = " . $bugsys->userinfo['userid']
-       );
-       while ($bug = $db->fetch_array($favourites))
+                       ON (favorite.bugid = bug.bugid)
+               WHERE favorite.userid = " . bugdar::$userinfo['userid'] . "
+               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') . "))" : "") . ")
+       ");
+       
+       if ($favorites->size() < 1)
        {
-               $funct->exec_swap_bg($stylevar['alt_colour'], '');
-               $bug['bgcolour'] = ($bugsys->userinfo['showcolours'] ? $bugsys->datastore['status']["$bug[status]"]['color'] : $funct->bgcolour);
-               $bug['product'] = $bugsys->datastore['product']["$bug[product]"]['title'];
-               $bug['version'] = $bugsys->datastore['version']["$bug[version]"]['version'];
-               $bug['status'] = $bugsys->datastore['status']["$bug[status]"]['status'];
-               $bug['resolution'] = $bugsys->datastore['resolution']["$bug[resolution]"]['resolution'];
-               $bug['priority'] = $bugsys->datastore['priority']["$bug[priority]"]['priority'];
-               $bug['severity'] = $bugsys->datastore['severity']["$bug[severity]"]['severity'];
-               
-               $bug['hiddendisplay'] = ((!can_perform('canviewhidden', $bug['product']) AND $bug['hiddenlastposttime']) ? true : false);
-               
-               $bug['lastposttime'] = ($bug['hiddendisplay'] ? $bug['hiddenlastposttime'] : $bug['lastposttime']);
-               $bug['lastpost'] = ($bug['hiddendisplay'] ? $bug['hiddenlastpostbyname'] : $bug['lastpostbyname']);
-               
-               $bug['lastposttime'] = $datef->format($bugsys->options['dateformat'], $bug['lastposttime']);
-               eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";');
+               $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.'));
        }
        
-       eval('$template->flush("' . $template->fetch('favourites') . '");');
+       $sort = new ListSorter('favorite');
+       
+       $headers = $sort->constructColumnHeaders(false);
+       
+       foreach ($favorites as $bug)
+       {
+               BSFunctions::swap_css_classes('altcolor', '');
+               $bug = ProcessBugDataForDisplay($bug, BSFunctions::$cssClass);
+               $bugs .= $sort->constructRow($bug);
+       }
+       
+       $tpl = new BSTemplate('favorites');
+       $tpl->vars = array(
+               'bugs'          => $bugs,
+               'headers'       => $headers
+       );
+       $tpl->evaluate()->flush();
 }
 
-/*=====================================================================*\
-|| ###################################################################
-|| # $HeadURL$
-|| # $Id$
-|| ###################################################################
-\*=====================================================================*/
 ?>
\ No newline at end of file