Merge branch 'master' of /home/git/platal into profile_edit
[platal.git] / modules / profile / get_mentor.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2007 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('geoloc.inc.php');
23 require_once('secteur.emploi.inc.php');
24
25 $max_mentor_pays = 10;
26 $max_mentor_secteurs = 10;
27
28 //recuperation de l'expertise
29 $res = XDB::query("SELECT expertise FROM mentor WHERE uid = {?}", S::v('uid',-1));
30
31 $mentor_expertise = $res->fetchOneCell();
32 $mentor_expertise_bd = $mentor_expertise;
33
34 //suppression eventuelle d'un pays
35 if(Post::v('mentor_pays_op', '') == 'retirer') {
36 if(Post::has('mentor_pays_id')) {
37 $id_supprimee = Post::v('mentor_pays_id', '00');
38 XDB::execute("DELETE FROM mentor_pays WHERE uid = {?} AND pid = {?} LIMIT 1", S::v('uid', -1), $id_supprimee);
39 }
40 }
41
42 //recuperation des pays
43 $res = XDB::iterRow("SELECT m.pid, p.pays
44 FROM mentor_pays AS m
45 LEFT JOIN geoloc_pays AS p ON(m.pid = p.a2) WHERE m.uid = {?} LIMIT {?}", S::v('uid', -1), $max_mentor_pays);
46 $nb_mentor_pays = $res->total();
47 $mentor_pid = $mentor_pays = Array();
48 for($i = 1; $i <= $nb_mentor_pays ; $i++) list($mentor_pid[$i], $mentor_pays[$i]) = $res->next();
49
50 //ajout eventuel d'un pays
51 if((Post::v('mentor_pays_op', '') == 'ajouter') && ($nb_mentor_pays < $max_mentor_pays)) {
52 if(Post::v('mentor_pays_id', '00') != '00') {
53 $id_ajoutee = Post::v('mentor_pays_id', '00');
54 XDB::execute("INSERT INTO mentor_pays(uid, pid) VALUES({?}, {?})", S::v('uid', -1), $id_ajoutee);
55 $nb_mentor_pays++;
56 $mentor_pid[$nb_mentor_pays] = $id_ajoutee;
57 $mentor_pays[$nb_mentor_pays] = Post::v('mentor_pays_name', '');
58 }
59 }
60
61
62
63 //suppression d'un secteur / ss-secteur
64 if(Post::v('mentor_secteur_op', '') == 'retirer') {
65 if(Post::has('mentor_secteur_id')) {
66 $id_supprimee = Post::v('mentor_secteur_id', '');
67 XDB::execute("DELETE FROM mentor_secteurs WHERE uid = {?} AND secteur = {?} LIMIT 1", S::v('uid', -1), $id_supprimee);
68 }
69 }
70
71 //recuperation des secteurs
72 $res = XDB::iterRow("SELECT m.secteur, s.label, m.ss_secteur, ss.label
73 FROM mentor_secteurs AS m
74 LEFT JOIN emploi_secteur AS s ON(m.secteur = s.id)
75 LEFT JOIN emploi_ss_secteur AS ss ON(s.id = ss.secteur AND m.ss_secteur = ss.id)
76 WHERE m.uid = {?}
77 LIMIT {?}", S::v('uid', -1), $max_mentor_pays);
78 $nb_mentor_secteurs = $res->total();
79 $mentor_sid = $mentor_secteur = $mentor_ssid = $mentor_ss_secteur = Array();
80 for($i = 1; $i <= $nb_mentor_secteurs ; $i++)
81 list($mentor_sid[$i], $mentor_secteur[$i], $mentor_ssid[$i], $mentor_ss_secteur[$i]) = $res->next();
82
83 //ajout d'un secteur
84 $mentor_secteur_id_new = '';
85 if((Post::v('mentor_secteur_op', '')== 'ajouter') && ($nb_mentor_secteurs < $max_mentor_secteurs)) {
86 if(Post::v('mentor_secteur_id', '') != '')
87 {
88 $sid_ajoutee = Post::v('mentor_secteur_id', '');
89 if(Post::has('mentor_ss_secteur_id'))
90 $ssid_ajoutee = Post::v('mentor_ss_secteur_id', '');
91 XDB::execute("INSERT INTO mentor_secteurs (uid, secteur, ss_secteur)
92 VALUES({?}, {?}, {?})", S::v('uid', -1), $sid_ajoutee, ($ssid_ajoutee == '')?null:$ssid_ajoutee);
93 $nb_mentor_secteurs++;
94 $mentor_sid[$nb_mentor_secteurs] = $sid_ajoutee;
95 $mentor_secteur[$nb_mentor_secteurs] = Post::v('mentor_secteur_name', '');
96 $mentor_ssid[$nb_mentor_secteurs] = $ssid_ajoutee;
97 $mentor_ss_secteur[$nb_mentor_secteurs] = Post::v('mentor_ss_secteur_name', '');
98 }
99 } elseif(Post::has('mentor_secteur_id_new')){
100 $mentor_secteur_id_new = Post::v('mentor_secteur_id_new', '');
101 }
102 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
103 ?>