Merge commit 'origin/fusionax' into account
[platal.git] / modules / search / search.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2008 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 dirname(__FILE__).'/classes.inc.php';
23
24 // {{{ function advancedSearchFromInput
25 function getadr_join($table) {
26 return 'u.user_id = ' . $table . '.uid' . (Env::v('only_current', false) ? ' AND FIND_IN_SET(\'active\', ' . $table . '.statut)' : '');
27 }
28 function advancedSearchFromInput()
29 {
30 if ($with_soundex = Env::has('with_soundex')) {
31 $nameField = new RefWithSoundexSField('name',array('rn.nom1_soundex','rn.nom2_soundex','rn.nom3_soundex'),'recherche_soundex','rn','u.matricule = rn.matricule');
32 $firstnameField = new RefWithSoundexSField('firstname',array('rp.prenom1_soundex','rp.prenom2_soundex'),'recherche_soundex','rp','u.matricule = rp.matricule');
33 } else {
34 $nameField = new NameSField('name', array('u.nom','u.nom_usage'), '');
35 $firstnameField = new StringSField('firstname', array('u.prenom'), '');
36 }
37 $nicknameField = new StringSField('nickname', array('q.profile_nick'), '');
38
39 $promo1Field = new PromoSField('promo1', 'egal1', array('u.promo'), '');
40 $promo2Field = new PromoSField('promo2', 'egal2', array('u.promo'), '');
41 $womanField = new RefSField('woman', array('FIND_IN_SET(\'femme\', u.flags) + 1'), '', '', '');
42 $subscriberField = new RefSField('subscriber', array('!(u.perms IN (\'admin\', \'user\')) + 1'), '', '', '');
43 $aliveField = new RefSField('alive', array('(u.deces != 0) + 1'), '', '', '');
44 if (Env::v('only_referent') == 'on') {
45 $referentField = new RefSField('only_referent', array('"on"'), 'mentor', 'mt', 'mt.expertise != "" AND mt.uid = u.user_id');
46 } else {
47 $referentField = null;
48 }
49
50 if (!Env::i('cityid')) {
51 $townField = new RefSField('city', array('ac.city', 'ac.postcode'), 'adresses', 'ac', getadr_join('ac'), false);
52 } else {
53 $townField = new RefSField('cityid', array('av.cityid', 'av.postcode'), 'adresses', 'av', getadr_join('av'));
54 }
55 $countryField = new RefSField('country', array('ap.country'), 'adresses', 'ap', getadr_join('ap'));
56 $regionField = new RefSField('region',array('ar.region'), 'adresses', 'ar', getadr_join('ar'));
57 $mapField = new MapSField('mapid', array('sgcim.map_id'), array('adresses', 'geoloc_city_in_maps'),
58 array('amp', 'sgcim'), array(getadr_join('amp'), 'amp.cityid = sgcim.city_id'));
59
60 $entrepriseField = new RefSField('entreprise', array('je.name'), '', '','');
61 $posteField = new RefSField('poste', array('ep.description'), 'profile_job', 'ep', 'u.user_id = ep.uid', false);
62 $fonctionField = new RefSField('fonction', array('en.fonction_fr'), 'fonctions_def', 'en',
63 'u.user_id = profile_job.uid AND fonctions_def.id = profile_job.functionid');
64 $secteurField = new RefSField('secteur', array('fm.sectorid'), 'profile_job', 'fm', 'u.user_id = fm.uid');
65 $cvField = new RefSField('cv', array('u.cv'), '', '', '', false);
66
67 $natField = new RefSField('nationalite', array('u.nationalite', 'u.nationalite2', 'u.nationalite3'), '', '', '');
68 $binetField = new RefSField('binet', array('b.binet_id'), 'binets_ins', 'b', 'u.user_id=b.user_id');
69 $groupexField = new RefSField('groupex', array('g.id'), array('groupex.asso', 'groupex.membres'), array('g', 'gm'),
70 array("(g.cat = 'GroupesX' OR g.cat = 'Institutions') AND g.pub = 'public'",
71 'gm.asso_id = g.id AND u.user_id = gm.uid'));
72 $sectionField = new RefSField('section', array('u.section'), '', '', '');
73 $schoolField = new RefSField('school', array('edu.eduid'), 'profile_education', 'edu', 'u.user_id = edu.uid');
74 $diplomaField = new RefSField('diploma', array('edd.degreeid'), 'profile_education', 'edd', 'u.user_id = edd.uid');
75
76 $freeField = new RefSField('free', array('q.profile_freetext'), '', '', '', false);
77
78 $nwAddressField = new RefSField('networking_address', array('nw.address'), 'profile_networking', 'nw', 'nw.uid=u.user_id', false);
79 if (Env::v('networking_address') == '') {
80 $nwTypeField = new IndexSField('networking_type', array('nwe.network_type'), array('profile_networking', 'profile_networking_enum'),
81 array('nw', 'nwe'), array('nw.uid = u.user_id', 'nwe.network_type = nw.network_type'));
82 } else {
83 $nwTypeField = new IndexSField('networking_type',
84 array('nwe.network_type'), 'profile_networking_enum', 'nwe', 'nwe.network_type = nw.network_type');
85 }
86 $nwPhoneField = new PhoneSField('phone_number', array('t.search_tel'), 'profile_phones', 't', 't.uid = u.user_id');
87 return array(
88 $nameField, $firstnameField, $nicknameField, $promo1Field,
89 $promo2Field, $womanField, $subscriberField, $aliveField,
90 $townField, $countryField, $regionField, $mapField, $entrepriseField,
91 $posteField, $secteurField, $cvField, $natField, $binetField,
92 $groupexField, $sectionField, $schoolField, $diplomaField,
93 $freeField, $fonctionField, $nwAddressField, $nwTypeField,
94 $nwPhoneField, $referentField);
95 }
96
97 // }}}
98
99 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
100 ?>