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 | |
22 | |
23 | require_once("xorg.inc.php"); |
24 | new_skinned_page('referent.tpl',AUTH_COOKIE); |
25 | |
26 | $nb_max_resultats_total = 100; |
27 | $nb_max_resultats_par_page = 10; |
28 | $show_formulaire = true; |
29 | $page->assign_by_ref('show_formulaire', $show_formulaire); |
30 | $page->assign('show_resultat', false); |
31 | |
32 | |
33 | $secteur_selectionne = Post::get('secteur'); |
34 | $ss_secteur_selectionne = Post::get('ss_secteur'); |
35 | $pays_selectionne = Post::get('pays', '00'); |
36 | $expertise_champ = Post::get('expertise'); |
37 | |
38 | $page->assign('pays_selectionne',$pays_selectionne); |
39 | $page->assign('expertise_champ',$expertise_champ); |
40 | $page->assign('secteur_selectionne',$secteur_selectionne); |
41 | $page->assign('ss_secteur_selectionne',$ss_secteur_selectionne); |
42 | |
43 | //recuperation des noms de secteurs |
44 | $res = $globals->xdb->iterRow("SELECT id, label FROM emploi_secteur"); |
45 | $secteurs[''] = ''; |
46 | while (list($tmp_id, $tmp_label) = $res->next()) { |
47 | $secteurs[$tmp_id] = $tmp_label; |
48 | } |
49 | $page->assign_by_ref('secteurs', $secteurs); |
50 | |
51 | //on recupere les sous-secteurs si necessaire |
52 | $ss_secteurs[''] = ''; |
53 | if (!empty($secteur_selectionne)) |
54 | { |
55 | $res = $globals->xdb->iterRow("SELECT id, label FROM emploi_ss_secteur WHERE secteur = {?}", $secteur_selectionne); |
56 | while (list($tmp_id, $tmp_label) = $res->next()) { |
57 | $ss_secteurs[$tmp_id] = $tmp_label; |
58 | } |
59 | } |
60 | $page->assign_by_ref('ss_secteurs', $ss_secteurs); |
61 | |
62 | //recuperation des noms de pays |
63 | $res = $globals->xdb->iterRow("SELECT a2, pays FROM geoloc_pays WHERE pays <> '' ORDER BY pays"); |
64 | $pays['00'] = ''; |
65 | while (list($tmp_id, $tmp_label) = $res->next()) { |
66 | $pays[$tmp_id] = $tmp_label; |
67 | } |
68 | $page->assign_by_ref('pays', $pays); |
69 | |
70 | //On vient d'un formulaire |
71 | if (Env::has('Chercher')) { |
72 | |
73 | $champ_select = 'm.uid, a.prenom, a.nom, a.promo, l.alias, m.expertise'; |
74 | $champ_select = $champ_select.', mp.pid'; |
75 | $champ_select = $champ_select.', ms.secteur, ms.ss_secteur'; |
76 | |
77 | $clause_from = ' FROM mentor AS m |
78 | LEFT JOIN auth_user_md5 AS a ON(m.uid = a.user_id) |
79 | INNER JOIN aliases AS l ON (a.user_id=l.id AND FIND_IN_SET(\'bestalias\',l.flags)) |
80 | LEFT JOIN mentor_pays AS mp ON(m.uid = mp.uid) |
81 | LEFT JOIN mentor_secteurs AS ms ON(m.uid = ms.uid)'; |
82 | |
83 | $clause_where = ''; |
84 | |
85 | if ($pays_selectionne != '00') { |
86 | $clause_where = $clause_where." mp.pid = '".addslashes($pays_selectionne)."' AND"; |
87 | } |
88 | if ($secteur_selectionne) { |
89 | $clause_where = $clause_where." ms.secteur = '".addslashes($secteur_selectionne)."' AND"; |
90 | if($ss_secteur_selectionne) { |
91 | $clause_where = $clause_where." ms.ss_secteur = '".addslashes($ss_secteur_selectionne)."' AND"; |
92 | } |
93 | } |
94 | |
95 | if($expertise_champ) { |
96 | $clause_where = $clause_where." MATCH(m.expertise) AGAINST('".addslashes($expertise_champ)."') AND"; |
97 | } |
98 | |
99 | if($clause_where) { |
100 | |
101 | $show_formulaire = false; |
102 | $clause_where = substr($clause_where, 0, -3); //on vire le dernier AND |
103 | |
104 | $sql = "SELECT $champ_select $clause_from WHERE $clause_where GROUP BY uid ORDER BY RAND(".Session::getInt('uid').')'; |
105 | $res = $globals->xdb->iterRow($sql); |
106 | |
107 | if ($res->total() == 0) { |
108 | $page->assign('recherche_trop_large',true); |
109 | } else { |
110 | if (Env::has('page_courante')) { |
111 | $page_courante = Env::getInt('page_courante'); |
112 | } else { |
113 | $page_courante = 1; |
114 | } |
115 | |
116 | $current_uid = 0; |
117 | $nb_resultats = 0; |
118 | $page->assign('resultats',true); |
119 | $personnes = Array(); |
120 | $page->assign_by_ref('personnes',$personnes); |
121 | while( (list($uid, $prenom, $nom, $promo, $bestalias, |
122 | $expertise_bd, $pays_id, $secteur_id, $ss_secteur_id) = $res->next()) |
123 | || ($nb_resultats >= $nb_max_resultats_total)){ |
124 | if ($current_uid != $uid) { |
125 | $current_uid = $uid; |
126 | $page_correspondante = (int)($nb_resultats / $nb_max_resultats_par_page) +1; |
127 | $nb_resultats++; |
128 | if( $page_correspondante == $page_courante){ |
129 | $pers_trouve['nom'] = $nom; |
130 | $pers_trouve['prenom'] = $prenom; |
131 | $pers_trouve['promo'] = $promo; |
132 | $pers_trouve['bestalias'] = $bestalias; |
133 | $pers_trouve['expertise'] = $expertise_bd; |
134 | $personnes[] = $pers_trouve; |
135 | } |
136 | } |
137 | } |
138 | $nb_pages = (int) ($nb_resultats/$nb_max_resultats_par_page) + 1; |
139 | $page->assign('nb_pages_total', $nb_pages); |
140 | $page->assign('page_courante', $page_courante); |
141 | } |
142 | } |
143 | } |
144 | |
145 | if ($show_formulaire) { |
146 | $res = $globals->xdb->query("SELECT count(*) FROM mentor"); |
147 | $page->assign('mentors_number', $res->fetchOneCell()); |
148 | } |
149 | |
150 | $page->run(); |
151 | |
152 | ?> |