*
* Handles limiting number of rows displayed *
* Copyright (C) 2000, 2001 Joseph Engo *
* -------------------------------------------------------------------------*
* This library is part of the phpGroupWare API *
* http://www.phpgroupware.org/api *
* ------------------------------------------------------------------------ *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, *
* or any later version. *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
\**************************************************************************/
/* $Id$ */
class nextmatchs
{
// I split this up so it can be used in differant layouts.
function show($sn,$start,$total,$extra, $twidth, $bgtheme,
$search_obj=0,$filter_obj=1,$showsearch=1)
{
echo $this->tablestart($sn,$twidth, $bgtheme);
echo $this->left($sn,$start,$total,$extra);
if ($showsearch == 1)
{
echo $this->search($search_obj);
}
echo $this->filter($filter_obj);
echo $this->right($sn,$start,$total,$extra);
echo $this->tableend();
}
// --------------------------------------------------------------------
// same as show, only without direct output for use within templates
// *** the show function can be removed as soon as every program using
// nextmatch is converted to use template and show_tpl (loge)
// --------------------------------------------------------------------
function show_tpl($sn,$start,$total,$extra, $twidth, $bgtheme,
$search_obj=0,$filter_obj=1,$showsearch=1)
{
$var = $this->tablestart($sn,$twidth, $bgtheme);
$var .= $this->left($sn,$start,$total,$extra);
if ($showsearch == 1)
{
$var .= $this->search($search_obj);
}
$var .= $this->filter($filter_obj);
$var .= $this->right($sn,$start,$total,$extra);
$var .= $this->tableend();
return $var;
}
function tablestart($scriptname, $twidth="75%", $bgtheme="D3DCE3")
{
global $filter, $qfield, $start, $order, $sort, $query, $phpgw;
$str = "
\n";
if ($start != 0) {
// Changing the sorting order screaws up the starting number
if ( ($start - $maxmatchs) < 0)
$t_start = 0;
else
$t_start = ($start - $maxmatchs);
$str .= "
";
return $str;
} /* right() */
function alternate_row_color($currentcolor = "")
{
global $phpgw_info;
if (! $currentcolor) {
global $tr_color;
$currentcolor = $tr_color;
}
if ($currentcolor == $phpgw_info["theme"]["row_on"]) {
$tr_color = $phpgw_info["theme"]["row_off"];
} else {
$tr_color = $phpgw_info["theme"]["row_on"];
}
return $tr_color;
}
// If you are using the common bgcolor="{tr_color}"
// This function is a little cleanier approch
function template_alternate_row_color(&$tpl)
{
$tpl->set_var("tr_color",$this->alternate_row_color());
}
function show_sort_order($sort,$var,$order,$program,$text,$extra="")
{
global $phpgw, $filter, $qfield, $start, $query;
if (($order == $var) && ($sort == "ASC"))
$sort = "DESC";
else if (($order == $var) && ($sort == "DESC"))
$sort = "ASC";
else
$sort = "ASC";
return "link($program,"order=$var&sort=$sort"
. "&filter=$filter&qfield=$qfield"
. "&start=$start&query=$query".$extra)."\">$text";
}
// Postgre and MySQL switch the vars in limit. This will make it easier
// if there are any other databases that pull this.
function sql_limit($start)
{
global $phpgw_info;
$max = $phpgw_info["user"]["preferences"]["common"]["maxmatchs"];
switch ($phpgw_info["server"]["db_type"]) {
case "pgsql":
if ($start == 0)
$l = $max;
else
$l = "$max,$start";
return $l;
break;
case "mysql":
if ($start == 0)
$l = $max;
else
$l = "$start,$max";
return $l;
break;
case "oracle":
if ($start == 0)
$l = "rownum < $max";
else
$l = "rownum >= $start AND rownum <= $max";
// if ($new_where)
// return "WHERE $l";
// else
// return "AND $l";
break;
}
}
}