2 /***************************************************************************
3 * Copyright (C) 2003-2004 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
23 require_once("xorg.inc.php");
25 require_once('user.func.inc.php');
27 function get_user_ax($uid, $raw=false
)
29 require_once('webservices/ax/client.inc');
33 $res = $globals->xdb
->query(
35 FROM auth_user_md5 AS u
36 WHERE u.user_id = {?}", $uid);
37 $matricule_ax = $res->fetchOneCell();
39 $ancien = recupere_infos_ancien($matricule_ax);
42 $userax['matricule_ax'] = $matricule_ax;
43 $userax['uid'] = $uid;
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";
58 $userax['applis_join'] = "Corps ".$ancien->Corps()." - ".$ancien->Grade();
60 $userax['adr_pro'] = array();
62 for ($i = 0; $i < $ancien->Num_Activite(); $i++
) {
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;
79 $userax['adr'] = array();
80 foreach ($array['dump']['adresse'] as $adr) {
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;
94 $userax['raw'] = $ancien;
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
)
105 $globals->xdb
->execute("UPDATE auth_user_md5 SET nom_usage = {?} WHERE user_id = {?}", strtoupper($userax['nom_usage']), $userax['uid']);
109 $globals->xdb
->execute("UPDATE auth_user_quick SET profile_mobile = {?} WHERE user_id = {?}", $userax['mobile'], $userax['uid']);
113 if ($userax['nationalite'] == 'Français') {
114 $userax['nationalite'] = 'FR';
116 $globals->xdb
->execute("UPDATE auth_user_md5 SET nationalite = {?} WHERE user_id = {?}", $userax['nationalite'], $userax['uid']);
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 $globals->xdb
->execute("DELETE FROM tels WHERE uid = {?} AND adrid = {?}", $userax['uid'], $adrid);
123 if (is_array($del_pro)) foreach($del_pro as $entrid) {
124 $globals->xdb
->execute("DELETE FROM entreprises WHERE uid = {?} AND entrid = {?}", $userax['uid'], $entrid);
127 if (is_array($add_address)) {
129 $res = $globals->xdb
->query(
132 WHERE uid = {?} AND adrid >= 1
135 $adrids = $res->fetchColumn();
139 foreach($add_address as $adrid) {
141 $adr = $userax['adr'][$adrid];
143 // find the next adrid not used
144 while ($adrids[$i_adrid] == $new_adrid) {
151 $res = $globals->xdb
->query(
152 "SELECT a2 FROM geoloc_pays
153 WHERE pays LIKE {?} OR country LIKE {?}",
154 $adr['country'], $adr['country']);
156 $a2 = $res->fetchOneCell();
158 if (!$a2) { $a2 = '00'; }
160 $globals->xdb
->execute(
161 "INSERT INTO adresses
162 SET uid = {?}, adrid = {?},
163 adr1 = {?}, adr2 = {?}, adr3 = {?},
164 postcode = {?}, city = {?},
168 $userax['uid'], $new_adrid,
169 $adr['adr1'], $adr['adr2'], $adr['adr3'],
170 $adr['postcode'], $adr['city'],
174 $globals->xdb
->execute(
175 "INSERT INTO adresses
176 SET uid = {?}, adrid = {?}, tel = {?},
177 telid = 0, tel_type = 'Tel.', tel_pub = 'ax'",
178 $userax["uid"], $new_adrid, $adr['tel']);
180 $globals->xdb
->execute(
181 "INSERT INTO adresses
182 SET uid = {?}, adrid = {?}, tel = {?},
183 telid = 1, tel_type = 'Fax', tel_pub = 'ax'",
184 $userax["uid"], $new_adrid, $adr['fax']);
188 if (is_array($add_pro)) {
190 $res = $globals->xdb
->query(
191 "SELECT entrid FROM entreprises
192 WHERE uid = {?} AND entrid >= 1 ORDER BY entrid",
194 $entrids = $res->fetchColumn();
198 $nb_entr = count($entrids);
200 foreach($add_pro as $entrid) if ($nb_entr < 2) {
204 $pro = $userax['adr_pro'][$entrid];
206 // find the next adrid not used
207 while ($entrids[$i_entrid] == $new_entrid) {
212 if ($pro['country']) {
213 $res = $globals->xdb
->query(
214 "SELECT a2 FROM geoloc_pays
215 WHERE pays LIKE {?} OR country LIKE {?}",
216 $pro['country'], $pro['country']);
217 $a2 = $res->fetchOneCell();
219 if (!$a2) { $a2 = '00'; }
221 $globals->xdb
->execute(
222 "INSERT INTO entreprises
223 SET uid = {?}, entrid = {?},
224 entreprise = {?}, poste = {?},
225 adr1 = {?}, adr2 = {?}, adr3 = {?},
226 postcode = {?}, city = {?},
228 tel = {?}, fax = {?},
229 pub = 'ax', adr_pub = 'ax', tel_pub = 'ax'",
230 $userax['uid'], $new_entrid,
231 $pro['entreprise'], $pro['fonction'],
232 $pro['adr1'], $pro['adr2'], $pro['adr3'],
233 $pro['postcode'], $pro['city'],
235 $pro['tel'], $pro['fax']);
240 function copy_from_ax($uid)
242 $uax = get_user_ax($uid);
243 import_from_ax($uax, false
, true
, null
, array_keys($uax['adr']), null
, array_keys($uax['adr_pro']), true
);
246 // vim:set et sw=4 sts=4 sws=4: