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 | |
25 | require_once('user.func.inc.php'); |
26 | |
27 | function get_user_ax($uid, $raw=false) |
28 | { |
29 | require_once('webservices/ax/client.inc'); |
30 | |
31 | global $globals; |
32 | |
33 | $res = $globals->xdb->query( |
34 | "SELECT matricule_ax |
35 | FROM auth_user_md5 AS u |
36 | WHERE u.user_id = {?}", $uid); |
37 | $matricule_ax = $res->fetchOneCell(); |
38 | |
39 | $ancien = recupere_infos_ancien($matricule_ax); |
40 | |
41 | $userax = Array(); |
42 | $userax['matricule_ax'] = $matricule_ax; |
43 | $userax['uid'] = $uid; |
44 | |
45 | $userax['nom'] = $ancien->Nom_patr(); |
46 | $userax['nom_usage'] = $ancien->Nom_usuel(); |
47 | if ($userax['nom_usage'] == $userax['nom']) $userax['nom_usage'] = ''; |
48 | $userax['prenom'] = $ancien->Prenom(); |
49 | $userax['sexe'] = ($ancien->Civilite() != 'M')?1:0; |
50 | $userax['promo'] = $ancien->Promo(); |
51 | $userax['nationalite'] = $ancien->Nationalite(); |
52 | if ($userax['nationalite'] == 'F') $userax['nationalite'] = 'Français'; |
53 | //$userax['date'] = substr($ancien[12], 0, 10); |
54 | $userax['mobile'] = $ancien->Mobile(0); |
55 | if ($ancien->Corps() == 'D' || $ancien->Corps() == 'Z') { |
56 | $userax['applis_join'] = "pas un corps"; |
57 | } else { |
58 | $userax['applis_join'] = "Corps ".$ancien->Corps()." - ".$ancien->Grade(); |
59 | } |
60 | $userax['adr_pro'] = array(); |
61 | |
62 | for ($i = 0; $i < $ancien->Num_Activite(); $i++) { |
63 | $jobax = array(); |
64 | $jobax['entreprise'] = $ancien->Entreprise($i); |
65 | $jobax['fonction'] = $ancien->Fonction($i); |
66 | $jobax['adr1'] = $ancien->Adresse_act_adresse1($i); |
67 | $jobax['adr2'] = $ancien->Adresse_act_adresse2($i); |
68 | $jobax['adr3'] = $ancien->Adresse_act_adresse3($i); |
69 | $jobax['postcode'] = $ancien->Adresse_act_code_pst($i); |
70 | $jobax['city'] = $ancien->Adresse_act_ville($i); |
71 | $jobax['region'] = $ancien->Adresse_act_etat_region($i); |
72 | $jobax['country'] = $ancien->Adresse_act_pays($i); |
73 | $jobax['tel'] = $ancien->Adresse_act_tel($i); |
74 | $jobax['fax'] = $ancien->Adresse_act_fax($i); |
75 | $jobax['mobile'] = $ancien->Adresse_act_mobile($i); |
76 | $userax['adr_pro'][] = $jobax; |
77 | } |
78 | |
79 | $userax['adr'] = array(); |
80 | foreach ($array['dump']['adresse'] as $adr) { |
81 | $adrax = array(); |
82 | $adrax['adr1'] = $ancien->Adresse1($i); |
83 | $adrax['adr2'] = $ancien->Adresse2($i); |
84 | $adrax['adr3'] = $ancien->Adresse3($i); |
85 | $adrax['postcode'] = $ancien->Code_pst($i); |
86 | $adrax['city'] = $ancien->Ville($i); |
87 | $adrax['region'] = $ancien->Etat_region($i); |
88 | $adrax['country'] = $ancien->Pays($i); |
89 | $adrax['tel'] = $ancien->Tel($i); |
90 | $adrax['fax'] = $ancien->Fax($i); |
91 | $userax['adr'][] = $adrax; |
92 | } |
93 | if ($raw) { |
94 | $userax['raw'] = $ancien; |
95 | } |
96 | |
97 | return $userax; |
98 | } |
99 | |
100 | function import_from_ax($userax, $nom_usage=false, $mobile=false, $del_address=null, $add_address=null, $del_pro=null, $add_pro=null, $nationalite=false) |
101 | { |
102 | global $globals; |
103 | |
104 | if ($nom_usage) { |
105 | $globals->xdb->execute("UPDATE auth_user_md5 SET nom_usage = {?} WHERE user_id = {?}", strtoupper($userax['nom_usage']), $userax['uid']); |
106 | } |
107 | |
108 | if ($mobile) { |
109 | $globals->xdb->execute("UPDATE auth_user_quick SET profile_mobile = {?} WHERE user_id = {?}", $userax['mobile'], $userax['uid']); |
110 | } |
111 | |
112 | if ($nationalite) { |
113 | if ($userax['nationalite'] == 'Français') { |
114 | $userax['nationalite'] = 'FR'; |
115 | } |
116 | $globals->xdb->execute("UPDATE auth_user_md5 SET nationalite = {?} WHERE user_id = {?}", $userax['nationalite'], $userax['uid']); |
117 | } |
118 | if (is_array($del_address)) foreach($del_address as $adrid) { |
119 | $globals->xdb->execute("DELETE FROM adresses WHERE uid = {?} AND adrid = {?}", $userax['uid'], $adrid); |
120 | } |
121 | |
122 | if (is_array($del_pro)) foreach($del_pro as $entrid) { |
123 | $globals->xdb->execute("DELETE FROM entreprises WHERE uid = {?} AND entrid = {?}", $userax['uid'], $entrid); |
124 | } |
125 | |
126 | if (is_array($add_address)) { |
127 | |
128 | $res = $globals->xdb->query( |
129 | "SELECT adrid |
130 | FROM adresses |
131 | WHERE uid = {?} AND adrid >= 1 |
132 | ORDER BY adrid", |
133 | $userax['uid']); |
134 | $adrids = $res->fetchColumn(); |
135 | $i_adrid = 0; |
136 | $new_adrid = 1; |
137 | |
138 | foreach($add_address as $adrid) { |
139 | |
140 | $adr = $userax['adr'][$adrid]; |
141 | |
142 | // find the next adrid not used |
143 | while ($adrids[$i_adrid] == $new_adrid) { |
144 | $i_adrid++; |
145 | $new_adrid++; |
146 | } |
147 | |
148 | if ($adr['city']) { |
149 | |
150 | $res = $globals->xdb->query( |
151 | "SELECT a2 FROM geoloc_pays |
152 | WHERE pays LIKE {?} OR country LIKE {?}", |
153 | $adr['country'], $adr['country']); |
154 | |
155 | $a2 = $res->fetchOneCell(); |
156 | } |
157 | if (!$a2) { $a2 = '00'; } |
158 | |
159 | $globals->xdb->execute( |
160 | "INSERT INTO adresses |
161 | SET uid = {?}, adrid = {?}, |
162 | adr1 = {?}, adr2 = {?}, adr3 = {?}, |
163 | postcode = {?}, city = {?}, |
164 | country = {?}, |
165 | tel = {?}, fax = {?}, |
166 | datemaj = NOW(), |
167 | pub = 'ax', |
168 | tel_pub = 'ax'", |
169 | $userax['uid'], $new_adrid, |
170 | $adr['adr1'], $adr['adr2'], $adr['adr3'], |
171 | $adr['postcode'], $adr['city'], |
172 | $a2, |
173 | $adr['tel'], $adr['fax']); |
174 | } |
175 | } |
176 | |
177 | if (is_array($add_pro)) { |
178 | |
179 | $res = $globals->xdb->query( |
180 | "SELECT entrid FROM entreprises |
181 | WHERE uid = {?} AND entrid >= 1 ORDER BY entrid", |
182 | $userax['uid']); |
183 | $entrids = $res->fetchColumn(); |
184 | $i_entrid = 0; |
185 | $new_entrid = 1; |
186 | |
187 | $nb_entr = count($entrids); |
188 | |
189 | foreach($add_pro as $entrid) if ($nb_entr < 2) { |
190 | |
191 | $nb_entr++; |
192 | |
193 | $pro = $userax['adr_pro'][$entrid]; |
194 | |
195 | // find the next adrid not used |
196 | while ($entrids[$i_entrid] == $new_entrid) { |
197 | $i_entrid++; |
198 | $new_entrid++; |
199 | } |
200 | |
201 | if ($pro['country']) { |
202 | $res = $globals->xdb->query( |
203 | "SELECT a2 FROM geoloc_pays |
204 | WHERE pays LIKE {?} OR country LIKE {?}", |
205 | $pro['country'], $pro['country']); |
206 | $a2 = $res->fetchOneCell(); |
207 | } |
208 | if (!$a2) { $a2 = '00'; } |
209 | |
210 | $globals->xdb->execute( |
211 | "INSERT INTO entreprises |
212 | SET uid = {?}, entrid = {?}, |
213 | entreprise = {?}, poste = {?}, |
214 | adr1 = {?}, adr2 = {?}, adr3 = {?}, |
215 | postcode = {?}, city = {?}, |
216 | country = {?}, |
217 | tel = {?}, fax = {?}, |
218 | pub = 'ax', adr_pub = 'ax', tel_pub = 'ax'", |
219 | $userax['uid'], $new_entrid, |
220 | $pro['entreprise'], $pro['fonction'], |
221 | $pro['adr1'], $pro['adr2'], $pro['adr3'], |
222 | $pro['postcode'], $pro['city'], |
223 | $a2, |
224 | $pro['tel'], $pro['fax']); |
225 | } |
226 | } |
227 | } |
228 | |
229 | function copy_from_ax($uid) |
230 | { |
231 | $uax = get_user_ax($uid); |
232 | import_from_ax($uax, false, true, null, array_keys($uax['adr']), null, array_keys($uax['adr_pro']), true); |
233 | } |
234 | |
235 | // vim:set et sw=4 sts=4 sws=4: |
236 | ?> |