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