2 /***************************************************************************
3 * Copyright (C) 2003-2004 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 require_once('xorg.plugin.inc.php');
23 require_once("search/classes.inc.php");
25 // {{{ class XOrgSearch
27 class XOrgSearch
extends XOrgPlugin
31 var $_get_vars = Array('offset', 'order', 'order_inv', 'rechercher');
33 var $order_defaut = 'promo';
34 // type of orders : (field name, default ASC, text name, auth)
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
)
42 // {{{ function setNbLines()
44 function setNbLines($lines)
45 { $this->limit
= $lines; }
48 // {{{ function setAuth()
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
;
58 $this->orders
[$key][3] = identified();
64 // {{{ function addOrder()
66 function addOrder($name, $field, $inv_order, $text, $auth, $defaut=false
)
68 // reverse the array, to get the defaut order first
70 $this->orders
= array_reverse($this->orders
);
71 $this->orders
[$name] = array($field, $inv_order, $text, $auth);
73 $this->orders
= array_reverse($this->orders
);
74 $this->order_defaut
= $name;
79 // {{{ function show()
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
];
92 $order_inv = ($this->get_value('order_inv') != '') == $tab[1];
94 if ($order_inv && $order)
95 $sql_order = str_replace(",", " DESC,", $order)." DESC";
96 else $sql_order = $order;
98 list($list, $total) = call_user_func($this->_callback
, $offset, $this->limit
, $sql_order);
100 $page_max = intval(($total-1)/$this->limit
);
101 if(!logged() && $page_max > $globals->search
->public_max
)
102 $page_max = $globals->search
->public_max
;
106 $links[] = Array('u'=> $this->make_url(Array('offset'=>$offset-1)), 'i' => $offset-1, 'text' => 'précédent');
108 for ($i = 0; $i <= $page_max ; $i++
) {
109 $links[] = Array('u'=>$this->make_url(Array('offset'=>$i)), 'i' => $i, 'text' => $i+
1);
111 if ($offset < $page_max) {
112 $links[] = Array ('u' => $this->make_url(Array('offset'=>$offset+
1)), 'i' => $offset+
1, 'text' => 'suivant');
115 $page->assign('search_results', $list);
116 $page->assign('search_results_nb', $total);
117 $page->assign('search_page', $offset);
118 $page->assign('search_pages_nb', $page_max+
1);
119 $page->assign('search_pages_link', $links);
121 $order_links = Array();
122 foreach ($this->orders
as $key=>$o) if ($o[3]) {
123 $order_links[] = Array(
125 "url" => $this->make_url(Array('order' => $key, 'order_inv' => ($o[0] == $order) && ($order_inv != $o[1]))),
126 "asc" => ($o[0] == $order) && $order_inv,
127 "desc" => ($o[0] == $order) && !$order_inv
130 $page->assign('search_order_link', $order_links);
140 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: