adaptation geoloc pour utiliser une regle RewriteRule simple dans apache + verificati...
[platal.git] / include / synchro_ax.inc.php
CommitLineData
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
23require_once("xorg.inc.php");
24
25require_once('user.func.inc.php');
26
27function 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
100function 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);
79a5acea 120 $globals->xdb->execute("DELETE FROM tels WHERE uid = {?} AND adrid = {?}", $userax['uid'], $adrid);
0337d704 121 }
122
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);
125 }
126
127 if (is_array($add_address)) {
128
129 $res = $globals->xdb->query(
130 "SELECT adrid
131 FROM adresses
132 WHERE uid = {?} AND adrid >= 1
133 ORDER BY adrid",
134 $userax['uid']);
135 $adrids = $res->fetchColumn();
136 $i_adrid = 0;
137 $new_adrid = 1;
138
139 foreach($add_address as $adrid) {
140
141 $adr = $userax['adr'][$adrid];
142
143 // find the next adrid not used
144 while ($adrids[$i_adrid] == $new_adrid) {
145 $i_adrid++;
146 $new_adrid++;
147 }
148
149 if ($adr['city']) {
150
151 $res = $globals->xdb->query(
152 "SELECT a2 FROM geoloc_pays
153 WHERE pays LIKE {?} OR country LIKE {?}",
154 $adr['country'], $adr['country']);
155
156 $a2 = $res->fetchOneCell();
157 }
158 if (!$a2) { $a2 = '00'; }
159
160 $globals->xdb->execute(
161 "INSERT INTO adresses
162 SET uid = {?}, adrid = {?},
163 adr1 = {?}, adr2 = {?}, adr3 = {?},
164 postcode = {?}, city = {?},
165 country = {?},
0337d704 166 datemaj = NOW(),
79a5acea 167 pub = 'ax'",
0337d704 168 $userax['uid'], $new_adrid,
169 $adr['adr1'], $adr['adr2'], $adr['adr3'],
170 $adr['postcode'], $adr['city'],
79a5acea 171 $a2);
172 // import tels
173 if ($adr['tel'])
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']);
179 if ($adr['fax'])
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']);
0337d704 185 }
186 }
187
188 if (is_array($add_pro)) {
189
190 $res = $globals->xdb->query(
191 "SELECT entrid FROM entreprises
192 WHERE uid = {?} AND entrid >= 1 ORDER BY entrid",
193 $userax['uid']);
194 $entrids = $res->fetchColumn();
195 $i_entrid = 0;
196 $new_entrid = 1;
197
198 $nb_entr = count($entrids);
199
200 foreach($add_pro as $entrid) if ($nb_entr < 2) {
201
202 $nb_entr++;
203
204 $pro = $userax['adr_pro'][$entrid];
205
206 // find the next adrid not used
207 while ($entrids[$i_entrid] == $new_entrid) {
208 $i_entrid++;
209 $new_entrid++;
210 }
211
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();
218 }
219 if (!$a2) { $a2 = '00'; }
220
221 $globals->xdb->execute(
222 "INSERT INTO entreprises
223 SET uid = {?}, entrid = {?},
224 entreprise = {?}, poste = {?},
225 adr1 = {?}, adr2 = {?}, adr3 = {?},
226 postcode = {?}, city = {?},
227 country = {?},
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'],
234 $a2,
235 $pro['tel'], $pro['fax']);
236 }
237 }
238}
239
240function copy_from_ax($uid)
241{
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);
244}
245
246// vim:set et sw=4 sts=4 sws=4:
247?>