* * Handles limiting number of rows displayed * * Copyright (C) 2000, 2001 Joseph Engo * * -------------------------------------------------------------------------* * This library is part of phpGroupWare (http://www.phpgroupware.org) * * 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 = "
link($scriptname) . "\"> "; $str .= "\n\n"; return $str; } function tableend() { $str = "\n
\n
"; $str .= "
"; return $str; } function left($scriptname,$start,$total,$extradata = "") { global $filter, $qfield, $order, $sort, $query, $phpgw_info, $phpgw; $str = ""; $maxmatchs = $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]; if (( $start != 0 ) && ( $start > $maxmatchs )) $str .= " link($scriptname,"start=0" . "&order=$order&filter=$filter&qfield=$qfield" . "&sort=$sort&query=$query".$extradata) . "\">\""\n"; else $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 .= "link($scriptname,"start=$t_start" . "&order=$order&filter=$filter&qfield=$qfield" . "&sort=$sort&query=$query".$extradata) . "\">\""\n"; } else $str .= "" . "\""\n"; return $str; } /* left() */ function search($search_obj=0) { global $query; $str = "" . "
" . " " . $this->searchby($search_obj) . "" . "
" . ""; return $str; } /* search() */ function filterobj($filtertable, $idxfieldname, $strfieldname) { global $phpgw; $filter_obj = array(array("none","show all")); $index = 0; $phpgw->db->query("SELECT $idxfieldname, $strfieldname from $filtertable",__LINE__,__FILE__); while($phpgw->db->next_record()) { $index++; $filter_obj[$index][0] = $phpgw->db->f("$idxfieldname"); $filter_obj[$index][1] = $phpgw->db->f("$strfieldname"); } return $filter_obj; } /* filterobj() */ function searchby($search_obj) { global $qfield, $phpgw, $phpgw_info; $str = ""; if (is_array($search_obj)) { $str .= "\n"; } return $str; } /* searchby() */ function filter($filter_obj) { global $filter, $phpgw, $phpgw_info; $str = ""; if (is_long($filter_obj)) { if ($filter_obj == 1) { $user_groups = $phpgw->accounts->read_group_names($phpgw_info["user"]["userid"]); $indexlimit = count($user_groups); $filter_obj = array(array("none",lang("show all")), array("private",lang("only yours"))); for ($index=0; $index<$indexlimit; $index++) { $filter_obj[2+$index][0] = $user_groups[$index][0]; $filter_obj[2+$index][1] = "Group - " . $user_groups[$index][1]; } } } if (is_array($filter_obj)) { $str .= "" . "\n"; $str .= "\n"; $str .= "\n"; } return $str; } /* filter() */ function right($scriptname,$start,$total,$extradata = "") { global $filter, $qfield, $order, $sort, $query, $phpgw_info, $phpgw; $maxmatchs = $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]; $str = ""; if (($total > $maxmatchs) && ($total > $start + $maxmatchs)) $str .= "link($scriptname,"start=".($start+$maxmatchs) . "&order=$order&filter=$filter&qfield=$qfield" . "&sort=$sort&query=$query".$extradata) . "\">\""\n"; else $str .= "\"".lang("Next\n"; if (($start != $total - $maxmatchs) && ( ($total - $maxmatchs) > ($start + $maxmatchs) )) $str .= "link($scriptname,"start=".($total-$maxmatchs) . "&order=$order&filter=$filter&qfield=$qfield" . "&sort=$sort&query=$query".$extradata) . "\">\"" \n"; else $str .= "\"".lang("Last "; 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; } 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; } } }