2 /***************************************************************************
3 * Copyright (C) 2003-2006 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 // {{{ function advancedSearchFromInput
26 function getadr_join($table) {
27 return 'u.user_id='.$table.'.uid'.(Env
::v('only_current',false
)?
' AND FIND_IN_SET(\'active\','.$table.'.statut)':'');
29 function advancedSearchFromInput()
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');
35 $nameField = new NameSField('name',array('u.nom','u.nom_usage'),'');
36 $firstnameField = new StringSField('firstname',array('u.prenom'),'');
38 $nicknameField = new StringSField('nickname',array('q.profile_nick'),'');
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'),'','','');
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'));
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
);
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');
65 $freeField = new RefSField('free',array('q.profile_freetext'),'','','',false
);
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);
78 // {{{ class XOrgSearch
80 class XOrgSearch
extends XOrgPlugin
84 var $_get_vars = Array('offset', 'order', 'order_inv', 'rechercher');
86 var $order_defaut = 'promo';
87 // type of orders : (field name, default ASC, text name, auth)
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
)
95 // {{{ function setNbLines()
97 function setNbLines($lines)
98 { $this->limit
= $lines; }
101 // {{{ function setAuth()
105 foreach ($this->orders
as $key=>$o) {
106 if ($o[3] == AUTH_COOKIE
) {
107 $this->orders
[$key][3] = S
::logged();
108 } elseif ($o[3] == AUTH_PUBLIC
) {
109 $this->orders
[$key][3] = true
;
111 $this->orders
[$key][3] = S
::identified();
117 // {{{ function addOrder()
119 function addOrder($name, $field, $inv_order, $text, $auth, $defaut=false
)
121 // reverse the array, to get the defaut order first
123 $this->orders
= array_reverse($this->orders
);
124 $this->orders
[$name] = array($field, $inv_order, $text, $auth);
126 $this->orders
= array_reverse($this->orders
);
127 $this->order_defaut
= $name;
132 // {{{ function show()
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
];
145 $order_inv = ($this->get_value('order_inv') != '') == $tab[1];
147 if ($order_inv && $order)
148 $sql_order = str_replace(",", " DESC,", $order)." DESC";
149 else $sql_order = $order;
151 list($list, $total) = call_user_func($this->_callback
, $offset, $this->limit
, $sql_order);
153 $page_max = intval(($total-1)/$this->limit
);
154 if(!S
::logged() && $page_max > $globals->search
->public_max
)
155 $page_max = $globals->search
->public_max
;
159 $links[] = Array('u'=> $this->make_url(Array('offset'=>$offset-1)), 'i' => $offset-1, 'text' => 'précédent');
161 for ($i = 0; $i <= $page_max ; $i++
) {
162 $links[] = Array('u'=>$this->make_url(Array('offset'=>$i)), 'i' => $i, 'text' => $i+
1);
164 if ($offset < $page_max) {
165 $links[] = Array ('u' => $this->make_url(Array('offset'=>$offset+
1)), 'i' => $offset+
1, 'text' => 'suivant');
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);
174 $order_links = Array();
175 foreach ($this->orders
as $key=>$o) if ($o[3]) {
176 $order_links[] = Array(
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
183 $page->assign('search_order_link', $order_links);
193 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: