source: trunk/phpgwapi/inc/class.nextmatchs.inc.php @ 2

Revision 2, 24.1 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /**************************************************************************\
3        * eGroupWare API - nextmatchs                                              *
4        * Written by Joseph Engo <jengo@phpgroupware.org>                          *
5        *        and Bettina Gille [ceb@phpgroupware.org]                          *
6        * Handles limiting number of rows displayed                                *
7        * Copyright (C) 2000, 2001 Joseph Engo                                     *
8        * Copyright (C) 2002, 2003 Joseph Engo, Bettina Gille                      *
9        * ------------------------------------------------------------------------ *
10        * This library is part of the eGroupWare API                               *
11        * http://www.egroupware.org                                                *
12        * ------------------------------------------------------------------------ *
13        * This library is free software; you can redistribute it and/or modify it  *
14        * under the terms of the GNU Lesser General Public License as published by *
15        * the Free Software Foundation; either version 2.1 of the License,         *
16        * or any later version.                                                    *
17        * This library is distributed in the hope that it will be useful, but      *
18        * WITHOUT ANY WARRANTY; without even the implied warranty of               *
19        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
20        * See the GNU Lesser General Public License for more details.              *
21        * You should have received a copy of the GNU Lesser General Public License *
22        * along with this library; if not, write to the Free Software Foundation,  *
23        * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
24        \**************************************************************************/
25
26        /*!
27        @class nextmatchs
28        @abstract
29        */
30        class nextmatchs
31        {
32                var $maxmatches;
33                var $action;
34                var $template;
35                var $extra_filters = array();
36
37                function nextmatchs($website=False)
38                {
39                        if(!$website)
40                        {
41                                $this->template = createobject('phpgwapi.Template',PHPGW_TEMPLATE_DIR);
42                                $this->template->set_file(array(
43                                        '_nextmatchs' => 'nextmatchs.tpl'
44                                ));
45                                $this->template->set_block('_nextmatchs','nextmatchs');
46                                $this->template->set_block('_nextmatchs','filter');
47                                $this->template->set_block('_nextmatchs','form');
48                                $this->template->set_block('_nextmatchs','icon');
49                                $this->template->set_block('_nextmatchs','link');
50                                $this->template->set_block('_nextmatchs','search');
51                                $this->template->set_block('_nextmatchs','cats');
52                                $this->template->set_block('_nextmatchs','search_filter');
53                                $this->template->set_block('_nextmatchs','cats_search_filter');
54                        }
55
56                        if(isset($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']) &&
57                                (int)$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0)
58                        {
59                                $this->maxmatches = (int)$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
60                        }
61                        else
62                        {
63                                $this->maxmatches = 15;
64                        }
65
66                        $this->_start = (int) get_var('start',array('GLOBAL','POST','GET'));
67                       
68                        foreach(array('menuaction','filter','qfield','order','sort') as $name)
69                        {
70                                $var = '_'.$name;
71                                $this->$var = get_var($name,array('GLOBAL','POST','GET'));
72                                if (!preg_match('/^[a-z0-9_. -]*$/i',$this->$var))
73                                {
74                                        $this->$var = '';
75                                }
76                        }
77                        if (!is_object($GLOBALS['phpgw']->html))
78                        {
79                                $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html');
80                        }
81                }
82
83                /*!
84                @function set_icon
85                @abstract ?
86                @param $align ?
87                @param $img_src ?
88                @param $label ?
89                */
90                function set_icon($align,$img,$label)
91                {
92                        $var = array(
93                                'align'  => $align,
94                                'img'    => $GLOBALS['phpgw']->common->image('phpgwapi',$img),
95                                'label'  => lang($label),
96                                'border' => 0
97                        );
98                        $this->template->set_var($var);
99                        return $this->template->fp('out','link');
100                }
101
102                /*!
103                @function page
104                @abstract ?
105                */
106                function page($extravars='')
107                {
108                        if($extravars && is_string($extravars) && substr($extravars,0,1)!='&')
109                        {
110                                $extras = '&'.$extravars;
111                        }
112                        elseif($extravars && is_array($extravars))
113                        {
114                                foreach($extravars as $var => $value)
115                                {
116                                        if($var != 'menuaction')
117                                        {
118                                                $t_extras[] = $var.'='.$value;
119                                        }
120                                }
121                                $extras = implode($t_extras,'&');
122                        }
123
124                        return $GLOBALS['phpgw']->link('/index.php','menuaction='.$this->_menuaction.$extras);
125                }
126
127                /*!
128                @function set_link
129                @abstract ?
130                @param $img_src ?
131                @param $label ?
132                @param $link ?
133                @param $extravars ?
134                */
135                function set_link($align,$img,$link,$alt,$extravars)
136                {
137                        $var = Array(
138                                'align'     => $align,
139                                'action'    => ($this->_menuaction?$this->page():$GLOBALS['phpgw']->link($link)),
140                                'form_name' => $img,
141                                'hidden'    => $GLOBALS['phpgw']->html->input_hidden($extravars),
142                                'img'       => $GLOBALS['phpgw']->common->image('phpgwapi',$img),
143                                'label'     => $alt,
144                                'border'    => 0,
145                                'start'     => $extravars['start']
146                        );
147                        $this->template->set_var($var);
148                        return $this->template->fp('out','form');
149                }
150
151                /*!
152                @function show_tpl
153                @abstract ?
154                @param $sn ?
155                @param $start ?
156                @param $total ?
157                @param $extra ?
158                @param $twidth ?
159                @param $bgtheme ?
160                @param $search_obj ?
161                @param $filter_obj ?
162                @param $showsearch ?
163                */
164                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')
165                {
166                        if (!is_object($GLOBALS['phpgw']->categories))
167                        {
168                                $GLOBALS['phpgw']->categories = CreateObject('phpgwapi.categories');
169                        }
170                        $extravars = $this->split_extras($extravars,$extra);
171
172                        $var = array(
173                                'form_action'   => ($this->_menuaction?$this->page($extra):$GLOBALS['phpgw']->link($sn, $extra)),
174                                'lang_category' => lang('Category'),
175                                'lang_all'      => lang('All'),
176                                'lang_select'   => lang('Select'),
177                                'cat_field'     => $cat_field,
178                                'categories'    => $GLOBALS['phpgw']->categories->formated_list('select','all',$cat_id,'True'),
179                                'hidden'       => $GLOBALS['phpgw']->html->input_hidden(array(
180                                        'filter' => $this->_filter,
181                                        'qfield' => $this->_qfield,
182                                        'start'  => (int)$localstart,
183                                        'order'  => $this->_order,
184                                        'sort'   => $this->_sort,
185                                        'query'  => $GLOBALS['query'],
186                                )),
187                                'query_value'   => $GLOBALS['phpgw']->html->htmlspecialchars($GLOBALS['query']),
188                                'table_width'   => $twidth,
189                                'th_bg'         => $GLOBALS['phpgw_info']['theme']['th_bg'],
190                                'left'          => $this->left($sn,(int)$localstart,$total,$extra),
191                                'search'        => ($showsearch?$this->search($search_obj):''),
192                                'filter'        => ($filter_obj?$this->filter($filter_obj,$yours):''),
193                                'right'         => $this->right($sn,(int)$localstart,$total,$extra)
194                        );
195                        $this->template->set_var($var);
196                        $this->template->parse('cats','cats');
197                        $this->template->parse('cats_search_filter_data','cats_search_filter');
198                        return $this->template->fp('out','nextmatchs');
199                }
200
201                function split_extras($extravars,$extradata)
202                {
203                        if($extradata)
204                        {
205                                if(!is_array($extradata))
206                                {
207                                        parse_str($extradata,$extradata);
208                                }
209                                foreach($extradata as $var => $value)
210                                {
211                                        if($var != 'menuaction')
212                                        {
213                                                $extravars[$var] = $value;
214                                        }
215                                        else
216                                        {
217                                                $this->_menuaction = $value;
218                                        }
219                                }
220                        }
221                        return $extravars;
222                }
223
224                function extras_to_string($extra)
225                {
226                        if(is_array($extra))
227                        {
228                                foreach($extra as $var => $value)
229                                {
230                                        $t_extras[] = $var . '=' . urlencode($value);
231                                }
232                                $extra_s = '&' . implode('&',$t_extras);
233                        }
234                        return $extra_s;
235                }
236
237                /*!
238                @function left
239                @abstract ?
240                @param $scriptname ?
241                @param $start ?
242                @param $total ?
243                @param $extradate ?
244                */
245                function left($scriptname,$start,$total,$extradata = '')
246                {
247                        $extravars = Array(
248                                'order'   => $this->_order,
249                                'filter'  => $this->_filter,
250                                'q_field' => $this->_qfield,
251                                'sort'    => $this->_sort,
252                                'query'   => urlencode(stripslashes(@$GLOBALS['query']))
253                        );
254
255                        $extravars = $this->split_extras($extravars,$extradata);
256                        $ret_str = '';
257
258                        $start = (int) $start;
259
260                        if ($start != 0)
261                        {
262                                $extravars['start'] = 0;
263                                $ret_str .= $this->set_link('left','first.png',$scriptname,lang('First page'),$extravars);
264                                // Changing the sorting order screaws up the starting number
265                                if (($start - $this->maxmatches) < 0)
266                                {
267                                        $extravars['start'] = 0;
268                                }
269                                else
270                                {
271                                        $extravars['start'] = ($start - $this->maxmatches);
272                                }
273                                $ret_str .= $this->set_link('left','left.png',$scriptname,lang('Previous page'),$extravars);
274                        }
275                        else
276                        {
277                                $ret_str .= $this->set_icon('left','first-grey.png',lang('First page'));
278                                $ret_str .= $this->set_icon('left','left-grey.png',lang('Previous page'));
279                        }
280                        return $ret_str;
281                } /* left() */
282
283                /*!
284                @function right
285                @abstract ?
286                @param $scriptname ?
287                @param $start ?
288                @param $total ?
289                @param $extradate ?
290                */
291                function right($scriptname,$start,$total,$extradata = '')
292                {
293                        $extravars = Array(
294                                'order'   => $this->_order,
295                                'filter'  => $this->_filter,
296                                'q_field' => $this->_qfield,
297                                'sort'    => $this->_sort,
298                                'query'   => urlencode(stripslashes(@$GLOBALS['query']))
299                        );
300
301                        $extravars = $this->split_extras($extravars,$extradata);
302                        $ret_str = '';
303                       
304                        $start = (int) $start;
305
306                        if (($total > $this->maxmatches) &&
307                                ($total > $start + $this->maxmatches))
308                        {
309                                $extravars['start'] = ($start + $this->maxmatches);
310                                $ret_str .= $this->set_link('right','right.png',$scriptname,lang('Next page'),$extravars);
311                                $extravars['start'] = ($total - $this->maxmatches);
312                                $ret_str .= $this->set_link('right','last.png',$scriptname,lang('Last page'),$extravars);
313                        }
314                        else
315                        {
316                                $ret_str .= $this->set_icon('right','right-grey.png',lang('Next page'));
317                                $ret_str .= $this->set_icon('right','last-grey.png',lang('Last page'));
318                        }
319                        return $ret_str;
320                } /* right() */
321
322                /*!
323                @function search_filter
324                @abstract ?
325                @param $search_obj default 0
326                */
327                function search_filter($search_obj=0,$filter_obj=1,$yours=0,$link='',$extra='')
328                {
329                        $var = array(
330                                'form_action'  => ($this->_menuaction?$this->page($extra):$GLOBALS['phpgw']->link($sn, $extra)),
331                                'th_bg'        => $GLOBALS['phpgw_info']['theme']['th_bg'],
332                                'hidden'       => $GLOBALS['phpgw']->html->input_hidden(array(
333                                        'filter' => $this->_filter,
334                                        'qfield' => $this->_qfield,
335                                        'start'  => 0,
336                                        'order'  => $this->_order,
337                                        'sort'   => $this->_sort,
338                                        'query'  => $GLOBALS['query'],
339                                )),
340                                'search'       => $this->search($search_obj),
341                                'filter'       => ($filter_obj?$this->filter($filter_obj,$yours):'')
342                        );
343                        $this->template->set_var($var);
344                        return $this->template->fp('out','search_filter');
345                }
346
347                /*!
348                @function cats_search_filter
349                @abstract ?
350                @param $search_obj default 0
351                */
352                function cats_search_filter($search_obj=0,$filter_obj=1,$yours=0,$cat_id=0,$cat_field='fcat_id',$link='',$extra='')
353                {
354                        if (!is_object($GLOBALS['phpgw']->categories))
355                        {
356                                $GLOBALS['phpgw']->categories  = CreateObject('phpgwapi.categories');
357                        }
358                        $var = array(
359                                'form_action'   => ($this->_menuaction?$this->page($extra):$GLOBALS['phpgw']->link($sn, $extra)),
360                                'lang_category' => lang('Category'),
361                                'lang_all'      => lang('All'),
362                                'lang_select'   => lang('Select'),
363                                'cat_field'     => $cat_field,
364                                'categories'    => $GLOBALS['phpgw']->categories->formated_list('select','all',(int)$cat_id,'True'),
365                                'hidden'       => $GLOBALS['phpgw']->html->input_hidden(array(
366                                        'filter' => $this->_filter,
367                                        'qfield' => $this->_qfield,
368                                        'start'  => 0,
369                                        'order'  => $this->_order,
370                                        'sort'   => $this->_sort,
371                                        'query'  => $GLOBALS['query'],
372                                )),
373                                'th_bg'         => $GLOBALS['phpgw_info']['theme']['th_bg'],
374                                'search'        => $this->search($search_obj),
375                                'filter'        => ($filter_obj?$this->filter($filter_obj,$yours):'')
376                        );
377                        $this->template->set_var($var);
378                        return $this->template->fp('out','cats_search_filter');
379                }
380
381                /*!
382                @function search
383                @abstract ?
384                @param $search_obj default 0
385                */
386                function search($search_obj=0)
387                {
388                        if(is_array($search_obj))
389                        {
390                                $params     = $search_obj;
391                                $s_query    = stripslashes($params['query']);
392                                $search_obj = $params['search_obj'];
393                        }
394                        else
395                        {
396                                $_query = stripslashes($GLOBALS['query']);
397                        }
398
399                        // If they place a '"' in their search, it will mess everything up
400                        // Our only option is to remove it
401                        if(strstr($query,'"'))
402                        {
403                                $_query = str_replace('"','',$_query);
404                        }
405                        $var = array
406                        (
407                                'query_value'   => $GLOBALS['phpgw']->html->htmlspecialchars($_query),
408                                'lang_search' => lang('Search')
409                        );
410
411                        if (is_array($search_obj))
412                        {
413                                $var['searchby'] = $this->searchby($search_obj);
414                        }
415
416                        $this->template->set_var($var);
417                        return $this->template->fp('out','search');
418                } /* search() */
419
420                /*!
421                @function filterobj
422                @abstract ?
423                @param $filtertable
424                @param $indxfieldname ?
425                @param $strfieldname ?
426                */
427                function filterobj($filtertable, $idxfieldname, $strfieldname)
428                {
429                        $filter_obj = array(array('none','show all'));
430                        $index = 0;
431
432                        $GLOBALS['phpgw']->db->query("SELECT $idxfieldname, $strfieldname FROM $filtertable",__LINE__,__FILE__);
433                        while($GLOBALS['phpgw']->db->next_record())
434                        {
435                                $index++;
436                                $filter_obj[$index][0] = $GLOBALS['phpgw']->db->f($idxfieldname);
437                                $filter_obj[$index][1] = $GLOBALS['phpgw']->db->f($strfieldname);
438                        }
439
440                        return $filter_obj;
441                } /* filterobj() */
442
443                /*!
444                @function searchby
445                @abstract ?
446                @param $search_obj ?
447                */
448                function searchby($search_obj)
449                {
450                        $str = '';
451                        if (is_array($search_obj))
452                        {
453                                $indexlimit = count($search_obj);
454                                for ($index=0; $index<$indexlimit; $index++)
455                                {
456                                        if ($this->_qfield == '')
457                                        {
458                                                $this->_qfield = $search_obj[$index][0];
459                                        }
460                                        $str .= '<option value="' . $search_obj[$index][0] . '"' . ($this->_qfield == $search_obj[$index][0]?' selected':'') . '>' . lang($search_obj[$index][1]) . '</option>';
461                                }
462                                $str = '<select name="qfield">' . $str . '</select>' . "\n";
463                        }
464                        return $str;
465                } /* searchby() */
466
467                /*!
468                @function filter
469                @abstract ?
470                @param $filter_obj
471                */
472                function filter($filter_obj,$yours=0)
473                {
474                        if (is_array($yours))
475                        {
476                                $params = $yours;
477                                $this->_filter = $params['filter'];
478                                $yours  = $params['yours'];
479                        }
480
481                        if (is_long($filter_obj))
482                        {
483                                if ($filter_obj == 1)
484                                {
485                                        //  $user_groups = $GLOBALS['phpgw']->accounts->membership($GLOBALS['phpgw_info']['user']['account_id']);
486                                        $indexlimit = count($user_groups);
487
488                                        if ($yours)
489                                        {
490                                                $filter_obj = array
491                                                (
492                                                        array('none',lang('Show all')),
493                                                        array('yours',lang('Only yours')),
494                                                        array('private',lang('private'))
495                                                );
496                                        }
497                                        else
498                                        {
499                                                $filter_obj = array
500                                                (
501                                                        array('none',lang('Show all')),
502                                                        array('private',lang('private'))
503                                                );
504                                        }
505
506                                        while (is_array($this->extra_filters) && list(,$efilter) = each($this->extra_filters))
507                                        {
508                                                $filter_obj[] = $efilter;
509                                        }
510
511                                        for ($index=0; $index<$indexlimit; $index++)
512                                        {
513                                                $filter_obj[2+$index][0] = $user_groups[$index]['account_id'];
514                                                $filter_obj[2+$index][1] = 'Group - ' . $user_groups[$index]['account_name'];
515                                        }
516                                }
517                        }
518
519                        if (is_array($filter_obj))
520                        {
521                                $str = '';
522                                $indexlimit = count($filter_obj);
523
524                                for ($index=0; $index<$indexlimit; $index++)
525                                {
526                                        if ($this->_filter == '')
527                                        {
528                                                $this->_filter = $filter_obj[$index][0];
529                                        }
530                                        $str .= '         <option value="' . $filter_obj[$index][0] . '"'.($this->_filter == $filter_obj[$index][0]?' selected="1"':'') . '>' . $filter_obj[$index][1] . '</option>'."\n";
531                                }
532
533                                $str = '        <select name="filter" onChange="this.form.submit()">'."\n" . $str . '        </select>';
534                                $this->template->set_var('select',$str);
535                                $this->template->set_var('lang_filter',lang('Filter'));
536                        }
537
538                        return $this->template->fp('out','filter');
539                } /* filter() */
540
541                /* replacement for function filter */
542                function new_filter($data=0)
543                {
544                        if(is_array($data))
545                        {
546                                $filter = (isset($data['filter'])?$data['filter']:'');
547                                $format = (isset($data['format'])?$data['format']:'all');
548                        }
549                        else
550                        {
551                                //$filter = get_var('filter',Array('GET','POST'));
552                                $filter = $data;
553                                $format = 'all';
554                        }
555
556                        switch($format)
557                        {
558                                case 'yours':
559                                        $filter_obj = array
560                                        (
561                                                array('none',lang('show all')),
562                                                array('yours',lang('only yours'))
563                                        );
564                                        break;
565                                case 'private':
566                                        $filter_obj = array
567                                        (
568                                                array('none',lang('show all')),
569                                                array('private',lang('only private'))
570                                        );
571                                        break;
572                                default:
573                                        $filter_obj = array
574                                        (
575                                                array('none',lang('show all')),
576                                                array('yours',lang('only yours')),
577                                                array('private',lang('only private'))
578                                        );
579                        }
580
581                        $str = '';
582                        $indexlimit = count($filter_obj);
583
584                        for($index=0; $index<$indexlimit; $index++)
585                        {
586                                if($filter == '')
587                                {
588                                        $filter = $filter_obj[$index][0];
589                                }
590                                $str .= '         <option value="' . $filter_obj[$index][0] . '"'.($filter == $filter_obj[$index][0]?' selected="1"':'') . '>' . $filter_obj[$index][1] . '</option>'."\n";
591                        }
592
593                        $str = '        <select name="filter" onChange="this.form.submit()">'."\n" . $str . '        </select>';
594                        $this->template->set_var('select',$str);
595                        $this->template->set_var('lang_filter',lang('Filter'));
596
597                        return $this->template->fp('out','filter');
598                } /* filter() */
599
600                /*!
601                @function alternate_row_color
602                @abstract alternate row colour
603                @param $currentcolor default ''
604                @param $do_class boolean default False return the color-value or just the class-name
605                */
606                function alternate_row_color($currentcolor = '',$do_class=False)
607                {
608                        if (! $currentcolor)
609                        {
610                                $currentcolor = @$GLOBALS['tr_color'];
611                        }
612
613                        if ($currentcolor == $GLOBALS['phpgw_info']['theme']['row_on'])
614                        {
615                                $GLOBALS['tr_color'] = $GLOBALS['phpgw_info']['theme'][$class='row_off'];
616                        }
617                        else
618                        {
619                                $GLOBALS['tr_color'] = $GLOBALS['phpgw_info']['theme'][$class='row_on'];
620                        }
621
622                        return $do_class ? $class : $GLOBALS['tr_color'];
623                }
624
625                // If you are using the common bgcolor="{tr_color}"
626                // This function is a little cleanier approch
627                /*!
628                @function template_alternate_row_color
629                @abstract ?
630                @param $tpl ?
631                */
632                function template_alternate_row_color(&$tpl)
633                {
634                        $tpl->set_var('tr_color',$this->alternate_row_color());
635                }
636
637                /*!
638                @function show_sort_order
639                @abstract ?
640                @param $sort ?
641                @param $var ?
642                @param $order ?
643                @param $program ?
644                @param $text ?
645                @param $extra default ''
646                */
647                function show_sort_order($sort,$var,$order,$program,$text,$extra='',$build_a_href=True)
648                {
649                        if ($order == $var)
650                        {
651                                $sort = $sort == 'ASC' ? 'DESC' : 'ASC';
652
653                                $text = '<b>'.$text.'</b> <img border="0" src="'.$GLOBALS['phpgw']->common->image('phpgwapi',$sort=='ASC'?'up':'down').'">';
654                        }
655                        else
656                        {
657                                $sort = 'ASC';
658                        }
659
660                        if (is_array($extra))
661                        {
662                                $extra = $this->extras_to_string($extra);
663                        }
664
665                        $extravar = 'order='.$var.'&sort='.$sort.'&filter='.$this->_filter.'&qfield='.$this->_qfield.'&start='.$this->_start.'&query='.urlencode(stripslashes(@$GLOBALS['query'])).$extra;
666
667                        $link = ($this->_menuaction?$this->page($extravar):$GLOBALS['phpgw']->link($program,$extravar));
668
669                        if ($build_a_href)
670                        {
671                                return '<a href="' . $link . '">' . $text . '</a>';
672                        }
673                        else
674                        {
675                                return $link;
676                        }
677                }
678
679                function show_hits($total_records='',$start=0)
680                {
681                        if ($total_records > $this->maxmatches)
682                        {
683                                if ($start + $this->maxmatches > $total_records)
684                                {
685                                        $end = $total_records;
686                                }
687                                else
688                                {
689                                        $end = $start + $this->maxmatches;
690                                }
691                                return lang('showing %1 - %2 of %3',($start + 1),$end,$total_records);
692                        }
693                        else
694                        {
695                                return lang('showing %1',$total_records);
696                        }
697                }
698
699                /*!
700                @function show_sort_order_imap
701                @abstract ?
702                @param $old_sort : the current sort value
703                @param $new_sort : the sort value you want if you click on this
704                @param $default_order : users preference for ordering list items (force this when a new [different] sorting is requested)
705                @param $order : the current order (will be flipped if old_sort = new_sort)
706                @param $program : script file name
707                @param $text : Text the link will show
708                @param $extra : any extra stuff you want to pass, url style
709                */
710                function show_sort_order_imap($old_sort,$new_sort,$default_order,$order,$program,$text,$extra='')
711                {
712                        if(is_array($extra))
713                        {
714                                $extra = $this->extras_to_string($extra);
715                        }
716                        if($old_sort == $new_sort)
717                        {
718                                // alternate order, like on outkrook, click on present sorting reverses order
719                                if((int)$order == 1)
720                                {
721                                        $our_order = 0;
722                                }
723                                elseif((int)$order == 0)
724                                {
725                                        $our_order = 1;
726                                }
727                                else
728                                {
729                                        // we should never get here
730                                        $our_order = 1;
731                                }
732                        }
733                        else
734                        {
735                                //user has selected a new sort scheme, reset the order to users default
736                                $our_order = $default_order;
737                        }
738
739                        $extravar = 'order='.$our_order.'&sort='.$new_sort.$extra;
740
741                        $link = ($this->_menuaction?$this->page($extravar):$GLOBALS['phpgw']->link($program,$extravar));
742                        return '<a href="' .$link .'">' .$text .'</a>';
743                }
744
745                /*!
746                @function nav_left_right_imap
747                @abstract same code as left and right (as of Dec 07, 2001) except all combined into one function
748                @param feed_vars : array with these elements: <br>
749                        start
750                        total
751                        cmd_prefix
752                        cmd_suffix
753                @return array, combination of functions left and right above, with these elements:
754                        first_page
755                        prev_page
756                        next_page
757                        last_page
758                @author: jengo, some changes by Angles
759                */
760                function nav_left_right_imap($feed_vars)
761                {
762                        $return_array = Array(
763                                'first_page' => '',
764                                'prev_page'  => '',
765                                'next_page'  => '',
766                                'last_page'  => ''
767                        );
768                        $out_vars = array();
769                        // things that might change
770                        $out_vars['start'] = $feed_vars['start'];
771                        // things that stay the same
772                        $out_vars['common_uri'] = $feed_vars['common_uri'];
773                        $out_vars['total'] = $feed_vars['total'];
774
775                        // first page
776                        if(($feed_vars['start'] != 0) &&
777                                ($feed_vars['start'] > $this->maxmatches))
778                        {
779                                $out_vars['start'] = 0;
780                                $return_array['first_page'] = $this->set_link_imap('left','first.png',lang('First page'),$out_vars);
781                        }
782                        else
783                        {
784                                $return_array['first_page'] = $this->set_icon_imap('left','first-grey.png',lang('First page'));
785                        }
786                        // previous page
787                        if($feed_vars['start'] != 0)
788                        {
789                                // Changing the sorting order screaws up the starting number
790                                if(($feed_vars['start'] - $this->maxmatches) < 0)
791                                {
792                                        $out_vars['start'] = 0;
793                                }
794                                else
795                                {
796                                        $out_vars['start'] = ($feed_vars['start'] - $this->maxmatches);
797                                }
798                                $return_array['prev_page'] = $this->set_link_imap('left','left.png',lang('Previous page'),$out_vars);
799                        }
800                        else
801                        {
802                                $return_array['prev_page'] = $this->set_icon_imap('left','left-grey.png',lang('Previous page'));
803                        }
804
805                        // re-initialize the out_vars
806                        // things that might change
807                        $out_vars['start'] = $feed_vars['start'];
808                        // next page
809                        if(($feed_vars['total'] > $this->maxmatches) &&
810                                ($feed_vars['total'] > $feed_vars['start'] + $this->maxmatches))
811                        {
812                                $out_vars['start'] = ($feed_vars['start'] + $this->maxmatches);
813                                $return_array['next_page'] = $this->set_link_imap('right','right.png',lang('Next page'),$out_vars);
814                        }
815                        else
816                        {
817                                $return_array['next_page'] = $this->set_icon_imap('right','right-grey.png',lang('Next page'));
818                        }
819                        // last page
820                        if(($feed_vars['start'] != $feed_vars['total'] - $this->maxmatches) &&
821                                (($feed_vars['total'] - $this->maxmatches) > ($feed_vars['start'] + $this->maxmatches)))
822                        {
823                                $out_vars['start'] = ($feed_vars['total'] - $this->maxmatches);
824                                $return_array['last_page'] = $this->set_link_imap('right','last.png',lang('Last page'),$out_vars);
825                        }
826                        else
827                        {
828                                $return_array['last_page'] = $this->set_icon_imap('right','last-grey.png',lang('Last page'));
829                        }
830                        return $return_array;
831                }
832
833                /*!
834                @function set_link_imap
835                @abstract ?
836                @param $img_src ?
837                @param $label ?
838                @param $link ?
839                @param $extravars ?
840                */
841                function set_link_imap($align,$img,$alt_text,$out_vars)
842                {
843                        $img_full = $GLOBALS['phpgw']->common->image('phpgwapi',$img);
844                        $image_part = '<img src="'.$img_full.'" border="0" alt="'.$alt_text.'" width="12" height="12">';
845                        return '<a href="'.$out_vars['common_uri'].'&start='.$out_vars['start'].'">'.$image_part.'</a>';
846                }
847
848                function set_icon_imap($align,$img,$alt_text)
849                {
850                        $img_full = $GLOBALS['phpgw']->common->image('phpgwapi',$img);
851                        return '<img src="'.$img_full.'" border="0" width="12" height="12" alt="'.$alt_text.'">'."\r\n";
852                }
853        } // End of nextmatchs class
854?>
Note: See TracBrowser for help on using the repository browser.