Switch the 'modify' code of admin/field.php to use templates
[bugdar.git] / index.php
index 845c8f2b47fa25409bdfc949977c5ae9dd534077..bd85cddffca5bb6997ff55b80ecff9539395f2a3 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,12 +1,12 @@
 <?php
 /*=====================================================================*\
 || ###################################################################
-|| # Bugdar [#]version[#]
-|| # Copyright ©2002-[#]year[#] Iris Studios, Inc.
+|| # 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
 $fetchtemplates = array(
        'trackerhome',
        'trackerhome_bits',
+       'list_head',
        'pagenav',
        'pagenav_bit'
 );
 
-define('SVN', '$Id$');
 
 $focus['index'] = 'focus';
 
 require_once('./global.php');
-require_once('./includes/class_pagination.php');
+require_once('./includes/class_sort.php');
 
 if (!can_perform('canviewbugs'))
 {
-       $message->error_permission();
+       $message->errorPermission();
 }
 
+$sort = new ListSorter('index');
+
+require_once 'includes/pagination.php';
+$pagination = new Pagination();
+$pagination->processIncomingData();
+
 // ###################################################################
 
-$pagination = new Pagination('p', 'pp');
-$count = $db->query_first("
+$count = $db->queryFirst("
        SELECT COUNT(*) AS count
        FROM " . TABLE_PREFIX . "bug
-       WHERE (!hidden OR (hidden AND productid IN (" . fetch_on_bits('canviewhidden') . ")))
-       AND productid IN (" . fetch_on_bits('canviewbugs') . ")" . ($bugsys->options['hidestatuses'] ? "
-       AND status NOT IN (" . $bugsys->options['hidestatuses'] . ")" : "")
+       WHERE (!hidden OR (hidden AND product IN (" . fetch_on_bits('canviewhidden') . "))" . (can_perform('canviewownhidden') ? " OR (hidden AND userid = " . bugdar::$userinfo['userid'] . " AND product IN (" . fetch_on_bits('canviewownhidden') . "))" : "") . ")
+       AND product IN (" . fetch_on_bits('canviewbugs') . ")" . ((bugdar::$options['hidestatuses'] OR isset(bugdar::$userinfo['hidestatuses'])) ? "
+       AND status NOT IN (" . (bugdar::$userinfo['hidestatuses'] != '' ? bugdar::$userinfo['hidestatuses'] : bugdar::$options['hidestatuses']) . ")" : "")
 );
 
-$pagination->total = $count['count'];
-$pagination->split_pages();
+if (!$count['count'])
+{
+       $message->error(T('There are no bugs to display. This could be because you do not have permission to view bugs, or there may be none in the database.'));
+}
+
+$pagination->setTotal($count['count']);
+$pagination->splitPages();
 
-$bugs_fetch = $db->query("
-       SELECT * FROM " . TABLE_PREFIX . "bug
-       WHERE productid IN (" . fetch_on_bits('canviewbugs') . ")
-               AND (!hidden OR (hidden AND productid IN (" . fetch_on_bits('canviewhidden') . ")))" . ($bugsys->options['hidestatuses'] ? "
-               AND status NOT IN (" . $bugsys->options['hidestatuses'] . ")" : "") . "
-       ORDER BY " . (can_perform('canviewhidden') ? "lastposttime" : "hiddenlastposttime") . " DESC
-       LIMIT " . $pagination->fetch_limit($pagination->page - 1) . ", " . $pagination->perpage
-);
+$bugs_fetch = $db->query($sort->fetchSqlQuery(null, $pagination->fetchLimit($pagination->getPage() - 1) . ", " . $pagination->getPerPage()));
 
-while ($bug = $db->fetch_array($bugs_fetch))
+foreach ($bugs_fetch as $bug)
 {
-       $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[productid]"]['title'];
-       $bug['version'] = $bugsys->datastore['version']["$bug[versionid]"]['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['productid']) 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') . '";');
+       BSFunctions::swap_css_classes('altcolor', '');  
+       $bug = ProcessBugDataForDisplay($bug, BSFunctions::$cssClass);
+       $bugs .= $sort->constructRow($bug);
 }
 
-$db->free_result($bugs_fetch);
+$bugs_fetch->free();
 
-$show['pagenav'] = (($pagination->pagecount > 1) ? true : false);
-$pagenav = $pagination->construct_page_nav('index.php');
+$columnHeads = $sort->constructColumnHeaders(true, 'p=' . $pagination->page . '&amp;pp=' . $pagination->perpage);
+$show['pagenav'] = ($pagination->getPageCount() > 1);
 
-eval('$template->flush("' . $template->fetch('trackerhome') . '");');
+$tpl = new BSTemplate('trackerhome');
+$tpl->vars = array(
+       'columnHeads'   => $columnHeads,
+       'bugs'                  => $bugs,
+       'pagenav'               => $pagination->constructPageNav($sort->fetchSortLink($sort->sortkey))
+);
+$tpl->evaluate()->flush();
 
-/*=====================================================================*\
-|| ###################################################################
-|| # $HeadURL$
-|| # $Id$
-|| ###################################################################
-\*=====================================================================*/
 ?>
\ No newline at end of file