changement d'annee pour les copyrights
[platal.git] / include / search.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2006 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
22 require_once('xorg.plugin.inc.php');
23 require_once("search/classes.inc.php");
24
25 // {{{ function advancedSearchFromInput
26 function getadr_join($table) {
27 return 'u.user_id='.$table.'.uid'.(Env::get('only_current',false)?' AND FIND_IN_SET(\'active\','.$table.'.statut)':'');
28 }
29 function advancedSearchFromInput()
30 {
31 if ($with_soundex = Env::has('with_soundex')) {
32 $nameField = new RefWithSoundexSField('name',array('rn.nom1_soundex','rn.nom2_soundex','rn.nom3_soundex'),'recherche_soundex','rn','u.matricule = rn.matricule');
33 $firstnameField = new RefWithSoundexSField('firstname',array('rp.prenom1_soundex','rp.prenom2_soundex'),'recherche_soundex','rp','u.matricule = rp.matricule');
34 } else {
35 $nameField = new NameSField('name',array('u.nom','u.nom_usage'),'');
36 $firstnameField = new StringSField('firstname',array('u.prenom'),'');
37 }
38 $nicknameField = new StringSField('nickname',array('q.profile_nick'),'');
39
40 $promo1Field = new PromoSField('promo1','egal1',array('u.promo'),'');
41 $promo2Field = new PromoSField('promo2','egal2',array('u.promo'),'');
42 $womanField = new RefSField('woman',array('FIND_IN_SET(u.flags,\'femme\')+1'),'','','');
43 $subscriberField = new RefSField('subscriber',array('!(u.perms IN (\'admin\',\'user\'))+1'),'','','');
44 $aliveField = new RefSField('alive',array('(u.deces!=0)+1'),'','','');
45
46 $townField = new RefSField('city',array('ac.city'),'adresses','ac',getadr_join('ac'),false);
47 $cityIdField = new RefSField('cityid',array('av.cityid'),'adresses','av',getadr_join('av'));
48 $countryField = new RefSField('country',array('ap.country'),'adresses','ap',getadr_join('ap'));
49 $regionField = new RefSField('region',array('ar.region'),'adresses','ar',getadr_join('ar'));
50 $mapField = new MapSField('mapid', array('gcim.map_id'), array('adresses','geoloc_city_in_maps'), array('am','gcim'), array(getadr_join('am'), 'am.cityid = gcim.city_id'));
51
52 $entrepriseField = new RefSField('entreprise',array('ee.entreprise'),'entreprises','ee','u.user_id=ee.uid',false);
53 $posteField = new RefSField('poste',array('ep.poste'),'entreprises','ep','u.user_id=ep.uid', false);
54 $fonctionField = new RefSField('fonction',array('en.fonction'),'entreprises','en','u.user_id=en.uid');
55 $secteurField = new RefSField('secteur',array('fm.secteur'),'entreprises','fm','u.user_id=fm.uid');
56 $cvField = new RefSField('cv',array('u.cv'),'','','',false);
57
58 $natField = new RefSField('nationalite',array('u.nationalite'),'','','');
59 $binetField = new RefSField('binet',array('b.binet_id'),'binets_ins','b','u.user_id=b.user_id');
60 $groupexField = new RefSField('groupex',array('g.gid'),'groupesx_ins','g','u.user_id=g.guid');
61 $sectionField = new RefSField('section',array('u.section'),'','','');
62 $schoolField = new RefSField('school',array('as.aid'),'applis_ins','`as`','u.user_id=as.uid');
63 $diplomaField = new RefSField('diploma',array('ad.type'),'applis_ins','ad','u.user_id=ad.uid');
64
65 $freeField = new RefSField('free',array('q.profile_freetext'),'','','',false);
66
67 return array(
68 $nameField, $firstnameField, $nicknameField, $promo1Field,
69 $promo2Field, $womanField, $subscriberField, $aliveField,
70 $townField, $countryField, $regionField, $entrepriseField,
71 $posteField, $secteurField, $cvField, $natField, $binetField,
72 $groupexField, $sectionField, $schoolField, $diplomaField,
73 $freeField, $fonctionField, $cityIdField, $mapField);
74 }
75
76 // }}}
77
78 // {{{ class XOrgSearch
79
80 class XOrgSearch extends XOrgPlugin
81 {
82 // {{{ properties
83
84 var $_get_vars = Array('offset', 'order', 'order_inv', 'rechercher');
85 var $limit = 20;
86 var $order_defaut = 'promo';
87 // type of orders : (field name, default ASC, text name, auth)
88 var $orders = array(
89 'nom' =>array('nom,prenom', true, 'nom', AUTH_PUBLIC),
90 'promo' =>array('promo,nom', false, 'promotion', AUTH_PUBLIC),
91 'date_mod' =>array('u.date,nom', false, 'dernière modification', AUTH_COOKIE)
92 );
93
94 // }}}
95 // {{{ function setNbLines()
96
97 function setNbLines($lines)
98 { $this->limit = $lines; }
99
100 // }}}
101 // {{{ function setAuth()
102
103 function setAuth()
104 {
105 foreach ($this->orders as $key=>$o) {
106 if ($o[3] == AUTH_COOKIE) {
107 $this->orders[$key][3] = logged();
108 } elseif ($o[3] == AUTH_PUBLIC) {
109 $this->orders[$key][3] = true;
110 } else {
111 $this->orders[$key][3] = identified();
112 }
113 }
114 }
115
116 // }}}
117 // {{{ function addOrder()
118
119 function addOrder($name, $field, $inv_order, $text, $auth, $defaut=false)
120 {
121 // reverse the array, to get the defaut order first
122 if ($defaut)
123 $this->orders = array_reverse($this->orders);
124 $this->orders[$name] = array($field, $inv_order, $text, $auth);
125 if ($defaut) {
126 $this->orders = array_reverse($this->orders);
127 $this->order_defaut = $name;
128 }
129 }
130
131 // }}}
132 // {{{ function show()
133
134 function show()
135 {
136 $this->setAuth();
137 global $page;
138
139 $offset = intval($this->get_value('offset'));
140 $tab = $this->orders[$this->get_value('order')];
141 if (!$tab || !$tab[3]) {
142 $tab = $this->orders[$this->order_defaut];
143 }
144 $order = $tab[0];
145 $order_inv = ($this->get_value('order_inv') != '') == $tab[1];
146
147 if ($order_inv && $order)
148 $sql_order = str_replace(",", " DESC,", $order)." DESC";
149 else $sql_order = $order;
150
151 list($list, $total) = call_user_func($this->_callback, $offset, $this->limit, $sql_order);
152
153 $page_max = intval(($total-1)/$this->limit);
154 if(!logged() && $page_max > $globals->search->public_max)
155 $page_max = $globals->search->public_max;
156
157 $links = Array();
158 if ($offset) {
159 $links[] = Array('u'=> $this->make_url(Array('offset'=>$offset-1)), 'i' => $offset-1, 'text' => 'précédent');
160 }
161 for ($i = 0; $i <= $page_max ; $i++) {
162 $links[] = Array('u'=>$this->make_url(Array('offset'=>$i)), 'i' => $i, 'text' => $i+1);
163 }
164 if ($offset < $page_max) {
165 $links[] = Array ('u' => $this->make_url(Array('offset'=>$offset+1)), 'i' => $offset+1, 'text' => 'suivant');
166 }
167
168 $page->assign('search_results', $list);
169 $page->assign('search_results_nb', $total);
170 $page->assign('search_page', $offset);
171 $page->assign('search_pages_nb', $page_max+1);
172 $page->assign('search_pages_link', $links);
173
174 $order_links = Array();
175 foreach ($this->orders as $key=>$o) if ($o[3]) {
176 $order_links[] = Array(
177 "text" => $o[2],
178 "url" => $this->make_url(Array('order' => $key, 'order_inv' => ($o[0] == $order) && ($order_inv != $o[1]))),
179 "asc" => ($o[0] == $order) && $order_inv,
180 "desc" => ($o[0] == $order) && !$order_inv
181 );
182 }
183 $page->assign('search_order_link', $order_links);
184
185 return $total;
186 }
187
188 // }}}
189 }
190
191 // }}}
192
193 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
194 ?>