egroupware_official/phpgwapi/inc/class.nextmatchs.inc.php

860 lines
24 KiB
PHP
Raw Normal View History

<?php
/**************************************************************************\
2004-05-05 14:06:13 +02:00
* eGroupWare API - nextmatchs *
2003-05-23 01:20:08 +02:00
* Written by Joseph Engo <jengo@phpgroupware.org> *
* and Bettina Gille [ceb@phpgroupware.org] *
* Handles limiting number of rows displayed *
* Copyright (C) 2000, 2001 Joseph Engo *
2003-05-23 01:20:08 +02:00
* Copyright (C) 2002, 2003 Joseph Engo, Bettina Gille *
2004-01-02 07:04:35 +01:00
* ------------------------------------------------------------------------ *
2004-05-05 14:06:13 +02:00
* This library is part of the eGroupWare API *
* http://www.egroupware.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$ */
/* $Source$ */
/*!
@class nextmatchs
@abstract
*/
2001-09-28 23:27:40 +02:00
class nextmatchs
{
2001-09-28 23:27:40 +02:00
var $maxmatches;
var $action;
var $template;
var $extra_filters = array();
2001-09-28 23:27:40 +02:00
function nextmatchs($website=False)
2001-09-28 23:27:40 +02:00
{
if(!$website)
2002-04-28 00:32:18 +02:00
{
2005-08-23 19:49:49 +02:00
$this->template = createobject('phpgwapi.Template',EGW_TEMPLATE_DIR);
$this->template->set_file(array(
'_nextmatchs' => 'nextmatchs.tpl'
));
$this->template->set_block('_nextmatchs','nextmatchs');
$this->template->set_block('_nextmatchs','filter');
$this->template->set_block('_nextmatchs','form');
$this->template->set_block('_nextmatchs','icon');
$this->template->set_block('_nextmatchs','link');
$this->template->set_block('_nextmatchs','search');
$this->template->set_block('_nextmatchs','cats');
$this->template->set_block('_nextmatchs','search_filter');
$this->template->set_block('_nextmatchs','cats_search_filter');
}
2001-09-28 23:27:40 +02:00
2005-08-23 19:49:49 +02:00
if(isset($GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']) &&
(int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] > 0)
2001-09-28 23:27:40 +02:00
{
2005-08-23 19:49:49 +02:00
$this->maxmatches = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
2001-09-28 23:27:40 +02:00
}
else
{
$this->maxmatches = 15;
}
$this->_start = (int) get_var('start',array('GLOBAL','POST','GET'));
2005-08-23 19:49:49 +02:00
foreach(array('menuaction','filter','qfield','order','sort') as $name)
{
$var = '_'.$name;
$this->$var = get_var($name,array('GLOBAL','POST','GET'));
if (!preg_match('/^[a-z0-9_. -]*$/i',$this->$var))
{
$this->$var = '';
}
}
2005-08-23 19:49:49 +02:00
if (!is_object($GLOBALS['egw']->html))
{
2005-08-23 19:49:49 +02:00
$GLOBALS['egw']->html = CreateObject('phpgwapi.html');
}
}
2001-09-28 23:27:40 +02:00
/*!
@function set_icon
@abstract ?
@param $align ?
@param $img_src ?
@param $label ?
*/
function set_icon($align,$img,$label)
{
2001-09-28 23:27:40 +02:00
$var = array(
2001-12-25 03:58:49 +01:00
'align' => $align,
2005-08-23 19:49:49 +02:00
'img' => $GLOBALS['egw']->common->image('phpgwapi',$img),
2001-12-25 03:58:49 +01:00
'label' => lang($label),
'border' => 0
2001-09-28 23:27:40 +02:00
);
$this->template->set_var($var);
return $this->template->fp('out','link');
}
2001-09-28 23:27:40 +02:00
/*!
@function page
@abstract ?
*/
function page($extravars='')
{
2001-09-28 23:27:40 +02:00
if($extravars && is_string($extravars) && substr($extravars,0,1)!='&')
{
2001-09-28 23:27:40 +02:00
$extras = '&'.$extravars;
}
2001-09-28 23:27:40 +02:00
elseif($extravars && is_array($extravars))
{
2004-01-02 07:04:35 +01:00
foreach($extravars as $var => $value)
2001-08-08 09:44:27 +02:00
{
if($var != 'menuaction')
{
$t_extras[] = $var.'='.$value;
}
}
2001-09-28 23:27:40 +02:00
$extras = implode($t_extras,'&');
}
2001-09-28 23:27:40 +02:00
2005-08-23 19:49:49 +02:00
return $GLOBALS['egw']->link('/index.php','menuaction='.$this->_menuaction.$extras);
}
2001-09-28 23:27:40 +02:00
/*!
@function set_link
@abstract ?
@param $img_src ?
@param $label ?
@param $link ?
@param $extravars ?
*/
function set_link($align,$img,$link,$alt,$extravars)
{
2001-09-28 23:27:40 +02:00
$var = Array(
2001-12-25 03:58:49 +01:00
'align' => $align,
2005-08-23 19:49:49 +02:00
'action' => ($this->_menuaction?$this->page():$GLOBALS['egw']->link($link)),
2001-12-25 03:58:49 +01:00
'form_name' => $img,
2005-08-23 19:49:49 +02:00
'hidden' => $GLOBALS['egw']->html->input_hidden($extravars),
'img' => $GLOBALS['egw']->common->image('phpgwapi',$img),
2001-12-25 03:58:49 +01:00
'label' => $alt,
'border' => 0,
2001-12-25 03:58:49 +01:00
'start' => $extravars['start']
2001-09-28 23:27:40 +02:00
);
$this->template->set_var($var);
return $this->template->fp('out','form');
}
/*!
@function show_tpl
@abstract ?
@param $sn ?
@param $start ?
@param $total ?
@param $extra ?
@param $twidth ?
@param $bgtheme ?
@param $search_obj ?
@param $filter_obj ?
@param $showsearch ?
*/
function show_tpl($sn,$localstart,$total,$extra, $twidth, $bgtheme,$search_obj=0,$filter_obj=1,$showsearch=1,$yours=0,$cat_id=0,$cat_field='fcat_id')
2001-09-28 23:27:40 +02:00
{
2005-08-23 19:49:49 +02:00
if (!is_object($GLOBALS['egw']->categories))
{
2005-08-23 19:49:49 +02:00
$GLOBALS['egw']->categories = CreateObject('phpgwapi.categories');
}
2001-09-28 23:27:40 +02:00
$extravars = $this->split_extras($extravars,$extra);
$var = array(
2005-08-23 19:49:49 +02:00
'form_action' => ($this->_menuaction?$this->page($extra):$GLOBALS['egw']->link($sn, $extra)),
2001-12-25 03:58:49 +01:00
'lang_category' => lang('Category'),
'lang_all' => lang('All'),
'lang_select' => lang('Select'),
'cat_field' => $cat_field,
'categories' => $GLOBALS['egw']->categories->formatted_list('select','all',$cat_id,'True'),
2005-08-23 19:49:49 +02:00
'hidden' => $GLOBALS['egw']->html->input_hidden(array(
2004-08-23 20:44:37 +02:00
'filter' => $this->_filter,
'qfield' => $this->_qfield,
'start' => (int)$localstart,
'order' => $this->_order,
'sort' => $this->_sort,
'query' => $GLOBALS['query'],
)),
2005-08-23 19:49:49 +02:00
'query_value' => $GLOBALS['egw']->html->htmlspecialchars($GLOBALS['query']),
2001-12-25 03:58:49 +01:00
'table_width' => $twidth,
2005-08-23 19:49:49 +02:00
'th_bg' => $GLOBALS['egw_info']['theme']['th_bg'],
'left' => $this->left($sn,(int)$localstart,$total,$extra),
2001-12-25 03:58:49 +01:00
'search' => ($showsearch?$this->search($search_obj):''),
'filter' => ($filter_obj?$this->filter($filter_obj,$yours):''),
'right' => $this->right($sn,(int)$localstart,$total,$extra)
2001-09-28 23:27:40 +02:00
);
$this->template->set_var($var);
2001-12-25 03:58:49 +01:00
$this->template->parse('cats','cats');
2001-09-28 23:27:40 +02:00
$this->template->parse('cats_search_filter_data','cats_search_filter');
return $this->template->fp('out','nextmatchs');
}
function split_extras($extravars,$extradata)
{
if($extradata)
{
if(!is_array($extradata))
{
2004-08-23 11:40:53 +02:00
parse_str($extradata,$extradata);
2001-09-28 23:27:40 +02:00
}
foreach($extradata as $var => $value)
2001-09-28 23:27:40 +02:00
{
if($var != 'menuaction')
{
$extravars[$var] = $value;
}
else
{
$this->_menuaction = $value;
}
}
}
2001-09-28 23:27:40 +02:00
return $extravars;
}
2001-09-28 23:27:40 +02:00
function extras_to_string($extra)
{
2001-09-28 23:27:40 +02:00
if(is_array($extra))
2001-08-08 09:44:27 +02:00
{
2004-01-02 07:04:35 +01:00
foreach($extra as $var => $value)
2001-09-28 23:27:40 +02:00
{
$t_extras[] = $var . '=' . urlencode($value);
2001-09-28 23:27:40 +02:00
}
$extra_s = '&' . implode('&',$t_extras);
2001-08-08 09:44:27 +02:00
}
2001-09-28 23:27:40 +02:00
return $extra_s;
}
2001-09-28 23:27:40 +02:00
/*!
@function left
@abstract ?
@param $scriptname ?
@param $start ?
@param $total ?
@param $extradate ?
*/
function left($scriptname,$start,$total,$extradata = '')
{
$extravars = Array(
'order' => $this->_order,
'filter' => $this->_filter,
'q_field' => $this->_qfield,
'sort' => $this->_sort,
'query' => stripslashes(@$GLOBALS['query'])
2001-09-28 23:27:40 +02:00
);
2001-09-28 23:27:40 +02:00
$extravars = $this->split_extras($extravars,$extradata);
$ret_str = '';
$start = (int) $start;
if ($start != 0)
{
$extravars['start'] = 0;
$ret_str .= $this->set_link('left','first.png',$scriptname,lang('First page'),$extravars);
2001-09-28 23:27:40 +02:00
// Changing the sorting order screaws up the starting number
if (($start - $this->maxmatches) < 0)
2001-09-28 23:27:40 +02:00
{
$extravars['start'] = 0;
}
else
{
$extravars['start'] = ($start - $this->maxmatches);
}
$ret_str .= $this->set_link('left','left.png',$scriptname,lang('Previous page'),$extravars);
2001-09-28 23:27:40 +02:00
}
else
{
$ret_str .= $this->set_icon('left','first-grey.png',lang('First page'));
$ret_str .= $this->set_icon('left','left-grey.png',lang('Previous page'));
2001-09-28 23:27:40 +02:00
}
return $ret_str;
} /* left() */
/*!
@function right
@abstract ?
@param $scriptname ?
@param $start ?
@param $total ?
@param $extradate ?
*/
2001-09-28 23:27:40 +02:00
function right($scriptname,$start,$total,$extradata = '')
2001-08-08 09:44:27 +02:00
{
2001-09-28 23:27:40 +02:00
$extravars = Array(
'order' => $this->_order,
'filter' => $this->_filter,
'q_field' => $this->_qfield,
'sort' => $this->_sort,
'query' => stripslashes(@$GLOBALS['query'])
2001-09-28 23:27:40 +02:00
);
2001-08-08 09:44:27 +02:00
2001-09-28 23:27:40 +02:00
$extravars = $this->split_extras($extravars,$extradata);
$ret_str = '';
2005-08-23 19:49:49 +02:00
$start = (int) $start;
if (($total > $this->maxmatches) &&
2001-12-25 03:58:49 +01:00
($total > $start + $this->maxmatches))
2001-09-28 23:27:40 +02:00
{
$extravars['start'] = ($start + $this->maxmatches);
$ret_str .= $this->set_link('right','right.png',$scriptname,lang('Next page'),$extravars);
2001-09-28 23:27:40 +02:00
$extravars['start'] = ($total - $this->maxmatches);
$ret_str .= $this->set_link('right','last.png',$scriptname,lang('Last page'),$extravars);
2001-09-28 23:27:40 +02:00
}
else
{
$ret_str .= $this->set_icon('right','right-grey.png',lang('Next page'));
$ret_str .= $this->set_icon('right','last-grey.png',lang('Last page'));
2001-09-28 23:27:40 +02:00
}
return $ret_str;
} /* right() */
2001-09-28 23:27:40 +02:00
/*!
@function search_filter
@abstract ?
@param $search_obj default 0
*/
function search_filter($search_obj=0,$filter_obj=1,$yours=0,$link='',$extra='')
{
$var = array(
2005-08-23 19:49:49 +02:00
'form_action' => ($this->_menuaction?$this->page($extra):$GLOBALS['egw']->link($sn, $extra)),
'th_bg' => $GLOBALS['egw_info']['theme']['th_bg'],
'hidden' => $GLOBALS['egw']->html->input_hidden(array(
2004-08-23 20:44:37 +02:00
'filter' => $this->_filter,
'qfield' => $this->_qfield,
'start' => 0,
'order' => $this->_order,
'sort' => $this->_sort,
'query' => $GLOBALS['query'],
)),
2001-12-25 03:58:49 +01:00
'search' => $this->search($search_obj),
'filter' => ($filter_obj?$this->filter($filter_obj,$yours):'')
2001-09-28 23:27:40 +02:00
);
$this->template->set_var($var);
return $this->template->fp('out','search_filter');
}
/*!
@function cats_search_filter
@abstract ?
@param $search_obj default 0
*/
function cats_search_filter($search_obj=0,$filter_obj=1,$yours=0,$cat_id=0,$cat_field='fcat_id',$link='',$extra='')
{
2005-08-23 19:49:49 +02:00
if (!is_object($GLOBALS['egw']->categories))
{
2005-08-23 19:49:49 +02:00
$GLOBALS['egw']->categories = CreateObject('phpgwapi.categories');
}
2001-09-28 23:27:40 +02:00
$var = array(
2005-08-23 19:49:49 +02:00
'form_action' => ($this->_menuaction?$this->page($extra):$GLOBALS['egw']->link($sn, $extra)),
2001-12-25 03:58:49 +01:00
'lang_category' => lang('Category'),
'lang_all' => lang('All'),
'lang_select' => lang('Select'),
'cat_field' => $cat_field,
'categories' => $GLOBALS['egw']->categories->formatted_list('select','all',(int)$cat_id,'True'),
2005-08-23 19:49:49 +02:00
'hidden' => $GLOBALS['egw']->html->input_hidden(array(
2004-08-23 20:44:37 +02:00
'filter' => $this->_filter,
'qfield' => $this->_qfield,
'start' => 0,
'order' => $this->_order,
'sort' => $this->_sort,
'query' => $GLOBALS['query'],
)),
2005-08-23 19:49:49 +02:00
'th_bg' => $GLOBALS['egw_info']['theme']['th_bg'],
2001-12-25 03:58:49 +01:00
'search' => $this->search($search_obj),
'filter' => ($filter_obj?$this->filter($filter_obj,$yours):'')
2001-09-28 23:27:40 +02:00
);
$this->template->set_var($var);
return $this->template->fp('out','cats_search_filter');
}
/*!
@function search
@abstract ?
@param $search_obj default 0
*/
function search($search_obj=0)
{
if(is_array($search_obj))
{
$_query = stripslashes($search_obj['query']);
$search_obj = $search_obj['search_obj'];
}
else
{
$_query = stripslashes($GLOBALS['query']);
}
2004-01-02 07:04:35 +01:00
// If they place a '"' in their search, it will mess everything up
2001-09-28 23:27:40 +02:00
// Our only option is to remove it
2006-12-07 13:46:08 +01:00
if(strpos($_query,'"')!==false)
2001-09-28 23:27:40 +02:00
{
$_query = str_replace('"','',$_query);
2001-09-28 23:27:40 +02:00
}
$var = array
(
2005-08-23 19:49:49 +02:00
'query_value' => $GLOBALS['egw']->html->htmlspecialchars($_query),
2001-12-25 03:58:49 +01:00
'lang_search' => lang('Search')
2001-09-28 23:27:40 +02:00
);
if (is_array($search_obj))
{
$var['searchby'] = $this->searchby($search_obj);
}
2001-09-28 23:27:40 +02:00
$this->template->set_var($var);
return $this->template->fp('out','search');
} /* search() */
/*!
@function filterobj
@abstract ?
@param $filtertable
@param $indxfieldname ?
@param $strfieldname ?
*/
function filterobj($filtertable, $idxfieldname, $strfieldname)
2001-08-08 09:44:27 +02:00
{
2001-09-28 23:27:40 +02:00
$filter_obj = array(array('none','show all'));
$index = 0;
2001-03-25 00:19:39 +01:00
2005-08-23 19:49:49 +02:00
$GLOBALS['egw']->db->query("SELECT $idxfieldname, $strfieldname FROM $filtertable",__LINE__,__FILE__);
while($GLOBALS['egw']->db->next_record())
2001-09-28 23:27:40 +02:00
{
$index++;
2005-08-23 19:49:49 +02:00
$filter_obj[$index][0] = $GLOBALS['egw']->db->f($idxfieldname);
$filter_obj[$index][1] = $GLOBALS['egw']->db->f($strfieldname);
2001-09-28 23:27:40 +02:00
}
return $filter_obj;
} /* filterobj() */
2001-09-28 23:27:40 +02:00
/*!
@function searchby
@abstract ?
@param $search_obj ?
*/
function searchby($search_obj)
2001-08-08 09:44:27 +02:00
{
2001-09-28 23:27:40 +02:00
$str = '';
if (is_array($search_obj))
{
2001-09-28 23:27:40 +02:00
$indexlimit = count($search_obj);
for ($index=0; $index<$indexlimit; $index++)
{
if ($this->_qfield == '')
2001-09-28 23:27:40 +02:00
{
$this->_qfield = $search_obj[$index][0];
2001-09-28 23:27:40 +02:00
}
2004-08-23 20:44:37 +02:00
$str .= '<option value="' . $search_obj[$index][0] . '"' . ($this->_qfield == $search_obj[$index][0]?' selected':'') . '>' . lang($search_obj[$index][1]) . '</option>';
}
2001-09-28 23:27:40 +02:00
$str = '<select name="qfield">' . $str . '</select>' . "\n";
}
2001-09-28 23:27:40 +02:00
return $str;
} /* searchby() */
2001-09-28 23:27:40 +02:00
/*!
@function filter
@abstract ?
@param $filter_obj
*/
function filter($filter_obj,$yours=0)
2001-08-08 09:44:27 +02:00
{
if (is_array($yours))
{
$params = $yours;
$this->_filter = $params['filter'];
$yours = $params['yours'];
}
if (is_long($filter_obj))
2001-09-28 23:27:40 +02:00
{
if ($filter_obj == 1)
2001-08-08 09:44:27 +02:00
{
2005-08-23 19:49:49 +02:00
// $user_groups = $GLOBALS['egw']->accounts->membership($GLOBALS['egw_info']['user']['account_id']);
2001-09-28 23:27:40 +02:00
$indexlimit = count($user_groups);
if ($yours)
2001-09-28 23:27:40 +02:00
{
$filter_obj = array
(
array('none',lang('Show all')),
array('yours',lang('Only yours')),
array('private',lang('private'))
2001-09-28 23:27:40 +02:00
);
}
else
{
$filter_obj = array
(
array('none',lang('Show all')),
array('private',lang('private'))
2001-09-28 23:27:40 +02:00
);
}
while (is_array($this->extra_filters) && list(,$efilter) = each($this->extra_filters))
{
$filter_obj[] = $efilter;
}
for ($index=0; $index<$indexlimit; $index++)
2001-09-28 23:27:40 +02:00
{
$filter_obj[2+$index][0] = $user_groups[$index]['account_id'];
$filter_obj[2+$index][1] = 'Group - ' . $user_groups[$index]['account_name'];
}
2001-08-08 09:44:27 +02:00
}
2001-09-28 23:27:40 +02:00
}
if (is_array($filter_obj))
2001-09-28 23:27:40 +02:00
{
$str = '';
$indexlimit = count($filter_obj);
for ($index=0; $index<$indexlimit; $index++)
2001-08-08 09:44:27 +02:00
{
if ($this->_filter == '')
2001-09-28 23:27:40 +02:00
{
$this->_filter = $filter_obj[$index][0];
2001-09-28 23:27:40 +02:00
}
$str .= ' <option value="' . $filter_obj[$index][0] . '"'.($this->_filter == $filter_obj[$index][0]?' selected="1"':'') . '>' . $filter_obj[$index][1] . '</option>'."\n";
}
2001-09-28 23:27:40 +02:00
$str = ' <select name="filter" onChange="this.form.submit()">'."\n" . $str . ' </select>';
$this->template->set_var('select',$str);
$this->template->set_var('lang_filter',lang('Filter'));
}
2001-05-21 11:05:21 +02:00
2001-09-28 23:27:40 +02:00
return $this->template->fp('out','filter');
} /* filter() */
/* replacement for function filter */
function new_filter($data=0)
{
if(is_array($data))
{
$filter = (isset($data['filter'])?$data['filter']:'');
$format = (isset($data['format'])?$data['format']:'all');
}
else
{
//$filter = get_var('filter',Array('GET','POST'));
$filter = $data;
$format = 'all';
}
switch($format)
{
case 'yours':
$filter_obj = array
(
array('none',lang('show all')),
array('yours',lang('only yours'))
);
break;
case 'private':
$filter_obj = array
(
array('none',lang('show all')),
array('private',lang('only private'))
);
break;
default:
$filter_obj = array
(
array('none',lang('show all')),
array('yours',lang('only yours')),
array('private',lang('only private'))
);
}
$str = '';
$indexlimit = count($filter_obj);
for($index=0; $index<$indexlimit; $index++)
{
if($filter == '')
{
$filter = $filter_obj[$index][0];
}
$str .= ' <option value="' . $filter_obj[$index][0] . '"'.($filter == $filter_obj[$index][0]?' selected="1"':'') . '>' . $filter_obj[$index][1] . '</option>'."\n";
}
$str = ' <select name="filter" onChange="this.form.submit()">'."\n" . $str . ' </select>';
$this->template->set_var('select',$str);
$this->template->set_var('lang_filter',lang('Filter'));
return $this->template->fp('out','filter');
} /* filter() */
2002-09-26 05:58:21 +02:00
2001-09-28 23:27:40 +02:00
/*!
@function alternate_row_color
@abstract alternate row colour
@param $currentcolor default ''
@param $do_class boolean default False return the color-value or just the class-name
2001-09-28 23:27:40 +02:00
*/
function alternate_row_color($currentcolor = '',$do_class=False)
2001-08-08 09:44:27 +02:00
{
if (! $currentcolor)
2001-09-28 23:27:40 +02:00
{
$currentcolor = @$GLOBALS['tr_color'];
2001-09-28 23:27:40 +02:00
}
// this is for old apps relying on the old themes
$row_on_color = '" class="row_on';
$row_off_color = '" class="row_off';
if ($currentcolor == $row_on_color)
2001-08-08 09:44:27 +02:00
{
$GLOBALS['tr_color'] = $row_off_color;
$class='row_off';
2001-09-28 23:27:40 +02:00
}
else
{
$GLOBALS['tr_color'] = $row_on_color;
$class='row_on';
}
2001-05-21 11:05:21 +02:00
return $do_class ? $class : $GLOBALS['tr_color'];
2001-08-08 09:44:27 +02:00
}
2001-09-28 23:27:40 +02:00
// If you are using the common bgcolor="{tr_color}"
// This function is a little cleanier approch
/*!
@function template_alternate_row_color
@abstract ?
@param $tpl ?
*/
function template_alternate_row_color(&$tpl)
2001-08-08 09:44:27 +02:00
{
$tpl->set_var('tr_color',$this->alternate_row_color());
2001-08-08 09:44:27 +02:00
}
2001-09-28 23:27:40 +02:00
/*!
@function show_sort_order
@abstract ?
@param $sort ?
@param $var ?
@param $order ?
@param $program ?
@param $text ?
@param $extra default ''
*/
function show_sort_order($sort,$var,$order,$program,$text,$extra='',$build_a_href=True)
2001-08-08 09:44:27 +02:00
{
if ($order == $var)
2001-09-28 23:27:40 +02:00
{
$sort = $sort == 'ASC' ? 'DESC' : 'ASC';
2005-08-23 19:49:49 +02:00
$text = '<b>'.$text.'</b> <img border="0" src="'.$GLOBALS['egw']->common->image('phpgwapi',$sort=='ASC'?'up':'down').'">';
2001-09-28 23:27:40 +02:00
}
else
{
$sort = 'ASC';
}
if (is_array($extra))
2001-09-28 23:27:40 +02:00
{
$extra = $this->extras_to_string($extra);
}
2004-08-23 20:44:37 +02:00
$extravar = 'order='.$var.'&sort='.$sort.'&filter='.$this->_filter.'&qfield='.$this->_qfield.'&start='.$this->_start.'&query='.urlencode(stripslashes(@$GLOBALS['query'])).$extra;
2005-08-23 19:49:49 +02:00
$link = ($this->_menuaction?$this->page($extravar):$GLOBALS['egw']->link($program,$extravar));
if ($build_a_href)
2001-09-28 23:27:40 +02:00
{
return '<a href="' . $link . '">' . $text . '</a>';
}
else
{
return $link;
}
}
function show_hits($total_records='',$start=0)
{
if ($total_records > $this->maxmatches)
{
if ($start + $this->maxmatches > $total_records)
{
$end = $total_records;
}
else
{
$end = $start + $this->maxmatches;
}
2003-04-23 00:30:38 +02:00
return lang('showing %1 - %2 of %3',($start + 1),$end,$total_records);
}
else
{
2003-04-23 00:30:38 +02:00
return lang('showing %1',$total_records);
}
}
2001-09-28 23:27:40 +02:00
/*!
@function show_sort_order_imap
@abstract ?
@param $old_sort : the current sort value
@param $new_sort : the sort value you want if you click on this
@param $default_order : users preference for ordering list items (force this when a new [different] sorting is requested)
2001-09-28 23:27:40 +02:00
@param $order : the current order (will be flipped if old_sort = new_sort)
@param $program : script file name
@param $text : Text the link will show
@param $extra : any extra stuff you want to pass, url style
*/
function show_sort_order_imap($old_sort,$new_sort,$default_order,$order,$program,$text,$extra='')
{
if(is_array($extra))
{
2001-09-28 23:27:40 +02:00
$extra = $this->extras_to_string($extra);
}
if($old_sort == $new_sort)
{
2001-09-28 23:27:40 +02:00
// alternate order, like on outkrook, click on present sorting reverses order
if((int)$order == 1)
2001-09-28 23:27:40 +02:00
{
$our_order = 0;
}
elseif((int)$order == 0)
2001-09-28 23:27:40 +02:00
{
$our_order = 1;
}
else
{
// we should never get here
$our_order = 1;
}
}
else
{
//user has selected a new sort scheme, reset the order to users default
2001-09-28 23:27:40 +02:00
$our_order = $default_order;
}
2001-09-28 23:27:40 +02:00
$extravar = 'order='.$our_order.'&sort='.$new_sort.$extra;
2001-08-08 09:44:27 +02:00
2005-08-23 19:49:49 +02:00
$link = ($this->_menuaction?$this->page($extravar):$GLOBALS['egw']->link($program,$extravar));
2001-09-28 23:27:40 +02:00
return '<a href="' .$link .'">' .$text .'</a>';
}
/*!
@function nav_left_right_imap
@abstract same code as left and right (as of Dec 07, 2001) except all combined into one function
@param feed_vars : array with these elements: <br>
2004-01-02 07:04:35 +01:00
start
total
cmd_prefix
cmd_suffix
@return array, combination of functions left and right above, with these elements:
first_page
prev_page
next_page
last_page
@author: jengo, some changes by Angles
*/
function nav_left_right_imap($feed_vars)
{
$return_array = Array(
2001-12-25 03:58:49 +01:00
'first_page' => '',
'prev_page' => '',
'next_page' => '',
'last_page' => ''
);
$out_vars = array();
// things that might change
$out_vars['start'] = $feed_vars['start'];
// things that stay the same
$out_vars['common_uri'] = $feed_vars['common_uri'];
$out_vars['total'] = $feed_vars['total'];
// first page
if(($feed_vars['start'] != 0) &&
2001-12-25 03:58:49 +01:00
($feed_vars['start'] > $this->maxmatches))
{
$out_vars['start'] = 0;
$return_array['first_page'] = $this->set_link_imap('left','first.png',lang('First page'),$out_vars);
}
else
{
$return_array['first_page'] = $this->set_icon_imap('left','first-grey.png',lang('First page'));
}
// previous page
if($feed_vars['start'] != 0)
{
// Changing the sorting order screaws up the starting number
if(($feed_vars['start'] - $this->maxmatches) < 0)
2001-09-28 23:27:40 +02:00
{
$out_vars['start'] = 0;
2001-09-28 23:27:40 +02:00
}
else
{
$out_vars['start'] = ($feed_vars['start'] - $this->maxmatches);
2001-09-28 23:27:40 +02:00
}
$return_array['prev_page'] = $this->set_link_imap('left','left.png',lang('Previous page'),$out_vars);
}
else
{
$return_array['prev_page'] = $this->set_icon_imap('left','left-grey.png',lang('Previous page'));
}
2001-12-25 03:58:49 +01:00
// re-initialize the out_vars
// things that might change
$out_vars['start'] = $feed_vars['start'];
// next page
if(($feed_vars['total'] > $this->maxmatches) &&
2001-12-25 03:58:49 +01:00
($feed_vars['total'] > $feed_vars['start'] + $this->maxmatches))
{
$out_vars['start'] = ($feed_vars['start'] + $this->maxmatches);
$return_array['next_page'] = $this->set_link_imap('right','right.png',lang('Next page'),$out_vars);
}
else
{
$return_array['next_page'] = $this->set_icon_imap('right','right-grey.png',lang('Next page'));
}
// last page
if(($feed_vars['start'] != $feed_vars['total'] - $this->maxmatches) &&
2001-12-25 03:58:49 +01:00
(($feed_vars['total'] - $this->maxmatches) > ($feed_vars['start'] + $this->maxmatches)))
{
$out_vars['start'] = ($feed_vars['total'] - $this->maxmatches);
$return_array['last_page'] = $this->set_link_imap('right','last.png',lang('Last page'),$out_vars);
}
else
{
$return_array['last_page'] = $this->set_icon_imap('right','last-grey.png',lang('Last page'));
}
return $return_array;
}
/*!
@function set_link_imap
@abstract ?
@param $img_src ?
@param $label ?
@param $link ?
@param $extravars ?
*/
function set_link_imap($align,$img,$alt_text,$out_vars)
{
2005-08-23 19:49:49 +02:00
$img_full = $GLOBALS['egw']->common->image('phpgwapi',$img);
$image_part = '<img src="'.$img_full.'" border="0" alt="'.$alt_text.'" width="12" height="12">';
return '<a href="'.$out_vars['common_uri'].'&start='.$out_vars['start'].'">'.$image_part.'</a>';
}
function set_icon_imap($align,$img,$alt_text)
{
2005-08-23 19:49:49 +02:00
$img_full = $GLOBALS['egw']->common->image('phpgwapi',$img);
return '<img src="'.$img_full.'" border="0" width="12" height="12" alt="'.$alt_text.'">'."\r\n";
}
2001-09-28 23:27:40 +02:00
} // End of nextmatchs class
?>