merge
[platal.git] / include / search.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2004 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22require_once('xorg.plugin.inc.php');
23require_once("search/classes.inc.php");
24
25// {{{ class XOrgSearch
26
27class XOrgSearch extends XOrgPlugin
28{
29 // {{{ properties
30
31 var $_get_vars = Array('offset', 'order', 'order_inv', 'rechercher');
32 var $limit = 20;
33 var $order_defaut = 'promo';
34 // type of orders : (field name, default ASC, text name, auth)
35 var $orders = array(
36 'nom' =>array('nom,prenom', true, 'nom', AUTH_PUBLIC),
37 'promo' =>array('promo,nom', false, 'promotion', AUTH_PUBLIC),
38 'date_mod' =>array('u.date,nom', false, 'dernière modification', AUTH_COOKIE)
39 );
40
41 // }}}
42 // {{{ function setNbLines()
43
44 function setNbLines($lines)
45 { $this->limit = $lines; }
46
47 // }}}
48 // {{{ function setAuth()
49
50 function setAuth()
51 {
52 foreach ($this->orders as $key=>$o) {
53 if ($o[3] == AUTH_COOKIE) {
54 $this->orders[$key][3] = logged();
55 } elseif ($o[3] == AUTH_PUBLIC) {
56 $this->orders[$key][3] = true;
57 } else {
58 $this->orders[$key][3] = identified();
59 }
60 }
61 }
62
63 // }}}
64 // {{{ function addOrder()
65
66 function addOrder($name, $field, $inv_order, $text, $auth, $defaut=false)
67 {
68 // reverse the array, to get the defaut order first
69 if ($defaut)
70 $this->orders = array_reverse($this->orders);
71 $this->orders[$name] = array($field, $inv_order, $text, $auth);
72 if ($defaut) {
73 $this->orders = array_reverse($this->orders);
74 $this->order_defaut = $name;
75 }
76 }
77
78 // }}}
79 // {{{ function show()
80
81 function show()
82 {
83 $this->setAuth();
84 global $page;
85
86 $offset = intval($this->get_value('offset'));
87 $tab = $this->orders[$this->get_value('order')];
88 if (!$tab || !$tab[3]) {
89 $tab = $this->orders[$this->order_defaut];
90 }
91 $order = $tab[0];
92 $order_inv = ($this->get_value('order_inv') != '') == $tab[1];
93
94 if ($order_inv && $order)
95 $sql_order = str_replace(",", " DESC,", $order)." DESC";
96 else $sql_order = $order;
97
98 list($list, $total) = call_user_func($this->_callback, $offset, $this->limit, $sql_order);
99
100 $page_max = intval(($total-1)/$this->limit);
101
102 $links = Array();
103 if ($offset) {
104 $links[] = Array('u'=> $this->make_url(Array('offset'=>$offset-1)), 'i' => $offset-1, 'text' => 'précédent');
105 }
106 for ($i = 0; $i <= $page_max ; $i++) {
107 $links[] = Array('u'=>$this->make_url(Array('offset'=>$i)), 'i' => $i, 'text' => $i+1);
108 }
109 if ($offset < $page_max) {
110 $links[] = Array ('u' => $this->make_url(Array('offset'=>$offset+1)), 'i' => $offset+1, 'text' => 'suivant');
111 }
112
113 $page->assign('search_results', $list);
114 $page->assign('search_results_nb', $total);
115 $page->assign('search_page', $offset);
116 $page->assign('search_pages_nb', $page_max+1);
117 $page->assign('search_pages_link', $links);
118
119 $order_links = Array();
120 foreach ($this->orders as $key=>$o) if ($o[3]) {
121 $order_links[] = Array(
122 "text" => $o[2],
123 "url" => $this->make_url(Array('order' => $key, 'order_inv' => ($o[0] == $order) && ($order_inv != $o[1]))),
124 "asc" => ($o[0] == $order) && $order_inv,
125 "desc" => ($o[0] == $order) && !$order_inv
126 );
127 }
128 $page->assign('search_order_link', $order_links);
129
130 return $total;
131 }
132
133 // }}}
134}
135
136// }}}
137
138// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
139?>