9b5ef111 |
1 | <?php |
2 | |
26ba053e |
3 | function ax_load_object($obj, $from) |
34d0d755 |
4 | { |
5 | foreach ($from as $k=>$v) { |
6 | if (property_exists($obj, $k)) { |
7 | $obj->$k = $v; |
8 | } |
9 | } |
10 | } |
11 | |
9b5ef111 |
12 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
aab2ffdd |
13 | class Ancien |
34d0d755 |
14 | { |
15 | public $NOM_PATR; |
16 | public $PART_NOM; |
17 | public $PRENOM; |
18 | public $NOM_USUEL; |
19 | public $PART_NOMUS; |
20 | public $NOM_COMPLET; |
21 | public $CIVILITE; |
22 | public $GRADE; |
23 | public $CORPS; |
24 | public $PROMO; |
25 | public $NATIONALITE; |
26 | public $CORPS_LIBELLE; |
27 | public $EMAIL; |
28 | public $TYPE_ANC; |
29 | public $ADRESSE = array(); |
30 | public $NUM_ADRESSE = 0; |
31 | public $ACTIVITE = array(); |
32 | public $NUM_ACTIVITE = 0; |
33 | public $FORMATION = array(); |
34 | public $NUM_FORMATION = 0; |
35 | public $Erreur; |
36 | |
aab2ffdd |
37 | public function __construct($aa) |
34d0d755 |
38 | { |
39 | if ($aa<>'') { |
40 | ax_load_object($this, $aa); |
41 | } |
9b5ef111 |
42 | } |
43 | function Ajout_adresse ($adresse,$i) { |
34d0d755 |
44 | $this->ADRESSE[$i] = $adresse; |
45 | $this->NUM_ADRESSE++; |
9b5ef111 |
46 | } |
47 | function Ajout_activite ($activite,$i) { |
34d0d755 |
48 | $this->ACTIVITE[$i] = $activite; |
49 | $this->NUM_ACTIVITE++; |
9b5ef111 |
50 | } |
51 | function Ajout_formation ($formation,$i) { |
34d0d755 |
52 | $this->FORMATION[$i] = $formation; |
53 | $this->NUM_FORMATION++; |
9b5ef111 |
54 | } |
34d0d755 |
55 | function Ajout_erreur ($erreur) { |
56 | $this->Erreur = $erreur; |
9b5ef111 |
57 | } |
58 | function Erreur() { |
59 | return $this->Erreur; |
60 | } |
61 | function Nom_patr() { |
62 | return $this->NOM_PATR; |
63 | } |
64 | function Part_nom() { |
65 | return $this->PART_NOM; |
66 | } |
67 | function Prenom() { |
68 | return $this->PRENOM; |
69 | } |
70 | function Nom_usuel() { |
71 | return $this->NOM_USUEL; |
72 | } |
73 | function Part_nomus() { |
74 | return $this->PART_NOMUS; |
75 | } |
76 | function Nom_complet() { |
77 | return $this->NOM_COMPLET; |
78 | } |
79 | function Civilite() { |
80 | return $this->CIVILITE; |
81 | } |
82 | function Grade() { |
83 | return $this->GRADE; |
84 | } |
85 | function Corps() { |
86 | return $this->CORPS; |
87 | } |
88 | function Corps_Libelle() { |
89 | return $this->CORPS_LIBELLE; |
90 | } |
91 | function Promo() { |
92 | return $this->PROMO; |
93 | } |
94 | function Nationalite() { |
95 | return $this->NATIONALITE; |
96 | } |
97 | function Email() { |
98 | return $this->EMAIL; |
99 | } |
100 | function Type_anc() { |
101 | return $this->TYPE_ANC; |
102 | } |
103 | function Adresse_type($i) { |
104 | return $this->ADRESSE[$i]->TYPE; |
105 | } |
106 | function Adresse1($i) { |
107 | return $this->ADRESSE[$i]->ADRESS1; |
108 | } |
109 | function Adresse2($i) { |
110 | return $this->ADRESSE[$i]->ADRESS2; |
111 | } |
112 | function Adresse3($i) { |
113 | return $this->ADRESSE[$i]->ADRESS3; |
114 | } |
115 | function Code_pst($i) { |
116 | return $this->ADRESSE[$i]->CODE_PST; |
117 | } |
118 | function Ville($i) { |
119 | return $this->ADRESSE[$i]->VILLE; |
120 | } |
121 | function Zip_cedex($i) { |
122 | return $this->ADRESSE[$i]->ZIPCEDEX; |
123 | } |
124 | function Etat_region($i) { |
125 | return $this->ADRESSE[$i]->ETATREGION; |
126 | } |
127 | function Pays($i) { |
128 | return $this->ADRESSE[$i]->PAYS; |
129 | } |
130 | function Mobile($i) { |
131 | return $this->ADRESSE[$i]->MOBILE; |
132 | } |
133 | function Tel($i) { |
134 | return $this->ADRESSE[$i]->TEL; |
135 | } |
136 | function Fax($i) { |
137 | return $this->ADRESSE[$i]->FAX; |
138 | } |
139 | function Num_adresse() { |
140 | return $this->NUM_ADRESSE; |
141 | } |
142 | function Entreprise($i) { |
143 | return $this->ACTIVITE[$i]->ENTREPRISE;; |
144 | } |
145 | function Raison_sociale($i) { |
146 | return $this->ACTIVITE[$i]->RAISON_SOCIALE; |
147 | } |
148 | function Fonction($i) { |
149 | return $this->ACTIVITE[$i]->FONCTION; |
150 | } |
151 | function Adresse_act_type($i) { |
152 | return $this->ACTIVITE[$i]->TYPE; |
153 | } |
154 | function Adresse_act_adresse1($i) { |
155 | return $this->ACTIVITE[$i]->ADRESS1; |
156 | } |
157 | function Adresse_act_adresse2($i) { |
158 | return $this->ACTIVITE[$i]->ADRESS2; |
159 | } |
160 | function Adresse_act_adresse3($i) { |
161 | return $this->ACTIVITE[$i]->ADRESS3; |
162 | } |
163 | function Adresse_act_code_pst($i) { |
164 | return $this->ACTIVITE[$i]->CODE_PST; |
165 | } |
166 | function Adresse_act_ville($i) { |
167 | return $this->ACTIVITE[$i]->VILLE; |
168 | } |
169 | function Adresse_act_zip_cedex($i) { |
170 | return $this->ACTIVITE[$i]->ZIPCEDEX; |
171 | } |
172 | function Adresse_act_etat_region($i) { |
173 | return $this->ACTIVITE[$i]->ETATREGION; |
174 | } |
175 | function Adresse_act_pays($i) { |
176 | return $this->ACTIVITE[$i]->PAYS; |
177 | } |
178 | function Adresse_act_mobile($i) { |
179 | return $this->ACTIVITE[$i]->MOBILE; |
180 | } |
181 | function Adresse_act_tel($i) { |
182 | return $this->ACTIVITE[$i]->TEL; |
183 | } |
184 | function Adresse_act_fax($i) { |
185 | return $this->ACTIVITE[$i]->FAX; |
186 | } |
187 | function Num_activite() { |
188 | return $this->NUM_ACTIVITE; |
189 | } |
190 | function Formation($i) { |
191 | return $this->FORMATION[$i]->LIBELLE; |
192 | } |
193 | function Num_formation() { |
194 | return $this->NUM_FORMATION; |
195 | } |
34d0d755 |
196 | } |
197 | |
198 | class Adresse |
199 | { |
200 | public $TYPE; |
201 | public $ADRESS1; |
202 | public $ADRESS2; |
203 | public $ADRESS3; |
204 | public $CODE_PST; |
205 | public $VILLE; |
206 | public $ZIPCEDEX; |
207 | public $ETATREGION; |
208 | public $PAYS; |
209 | public $MOBILE; |
210 | public $TEL; |
211 | public $FAX; |
212 | |
aab2ffdd |
213 | public function __construct($aa) |
34d0d755 |
214 | { |
215 | ax_load_object($this, $aa); |
216 | } |
217 | } |
218 | |
219 | class Activite |
220 | { |
221 | public $ENTREPRISE; |
222 | public $RAISON_SOCIALE; |
223 | public $FONCTION; |
224 | public $TYPE; |
225 | public $ADRESS1; |
226 | public $ADRESS2; |
227 | public $ADRESS3; |
228 | public $CODE_PST; |
229 | public $VILLE; |
230 | public $ZIPCEDEX; |
231 | public $ETATREGION; |
232 | public $PAYS; |
233 | public $MOBILE; |
234 | public $TEL; |
235 | public $FAX; |
236 | |
237 | public function __construct($aa) |
238 | { |
239 | ax_load_object($this, $aa); |
9b5ef111 |
240 | } |
34d0d755 |
241 | } |
242 | |
aab2ffdd |
243 | class Formation |
34d0d755 |
244 | { |
245 | public $LIBELLE; |
9b5ef111 |
246 | |
aab2ffdd |
247 | public function __construct($aa) |
9b5ef111 |
248 | { |
34d0d755 |
249 | ax_load_object($this, $aa); |
250 | } |
251 | } |
252 | |
aab2ffdd |
253 | function xml_get_children($vals, &$i) |
34d0d755 |
254 | { |
255 | $children = array(); |
256 | if (isset($vals[$i]['value'])) $children[] = $vals[$i]['value']; |
257 | |
258 | while (++$i < count($vals)) { |
259 | switch ($vals[$i]['type']) { |
260 | case 'cdata': |
261 | $children[] = $vals[$i]['value']; |
262 | break; |
263 | |
264 | case 'complete': |
265 | $children[] = array( |
266 | 'tag' => $vals[$i]['tag'], |
267 | 'attributes' => isset($vals[$i]['attributes'])? |
268 | $vals[$i]['attributes'] : null, |
269 | 'value' => $vals[$i]['value'], |
270 | ); |
271 | break; |
272 | |
273 | case 'open': |
274 | $children[] = array( |
275 | 'tag' => $vals[$i]['tag'], |
276 | 'attributes' => isset($vals[$i]['attributes'])? |
277 | $vals[$i]['attributes'] : null, |
278 | 'children' => xml_get_children($vals, $i), |
279 | ); |
280 | break; |
281 | |
282 | case 'close': |
283 | return $children; |
284 | } |
285 | } |
286 | } |
287 | |
288 | //fonction principale de récupération des données de l'ancien |
289 | //à indiquer: matricule de l'ancien |
290 | function recupere_infos_ancien($AX_MATRICULE) |
291 | { |
292 | include('config.inc'); |
9b5ef111 |
293 | |
34d0d755 |
294 | $id =14;//14 params persos ancien |
295 | $id_ad = 11; //12 params adresse |
296 | $id_ac = 14; //15 params adresse |
297 | $id_fo = 1; //1 params fonction |
9b5ef111 |
298 | |
34d0d755 |
299 | $erreur = ""; |
9b5ef111 |
300 | |
34d0d755 |
301 | // Génération d'un identifiant de "session" inter-serveurs |
302 | $id_session = md5 (uniqid (rand())); |
9b5ef111 |
303 | |
34d0d755 |
304 | // Connexion au serveur pour lui fournir l'identifiant et lui demander un challenge |
305 | $challenge = file_get_contents ($nom_script_renvoi_challenge."?id_session=".urlencode($id_session)); |
306 | if ($challenge == 'ERROR') |
307 | { |
308 | $erreur = "Erreur lors de la demande du challenge"; |
309 | } |
310 | else |
311 | { |
312 | // On va relire la clé privée (codée) |
313 | $privkeypass = $phrase; |
314 | $pkey_txt = file_get_contents ($chemin_cle_privee); |
315 | if (($pkey_res = openssl_pkey_get_private($pkey_txt, $privkeypass)) == false) |
9b5ef111 |
316 | { |
34d0d755 |
317 | $erreur = "Erreur lors de l'ouverture de la clé privée"; |
9b5ef111 |
318 | } |
319 | else |
320 | { |
34d0d755 |
321 | // Signature du challenge (cryptage avec clé privée) |
9b5ef111 |
322 | if ( openssl_private_encrypt($challenge, $response, $pkey_res) == false ) |
323 | { |
34d0d755 |
324 | $erreur = "Erreur lors du cryptage du challenge avec la clé privée"; |
9b5ef111 |
325 | } |
326 | else |
327 | { |
34d0d755 |
328 | // Signature du login (cryptage avec clé privée) |
329 | if ( openssl_private_encrypt($AX_MATRICULE, $AX_MATRICULE_CRYPTE, $pkey_res) == false ) |
330 | { |
331 | $erreur = "Erreur lors du cryptage du matricule avec la clé privée"; |
332 | } |
333 | else |
334 | { |
335 | // Envoi de la réponse au serveur avec l'identifiant de l'ancien dont on veut récupérer les infos |
9b5ef111 |
336 | $reponse_serveur .= file_get_contents ($nom_script_renvoi_infos."?id_session=".urlencode($id_session)."&AX_MATRICULE_CRYPTE=".urlencode($AX_MATRICULE_CRYPTE)."&response=".urlencode($response)); |
337 | |
338 | $parser = xml_parser_create(); |
339 | xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); |
340 | xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); |
341 | xml_parse_into_struct($parser, $reponse_serveur, $vals, $index); |
342 | xml_parser_free($parser); |
343 | |
344 | $tree = array(); |
345 | $tree[] = array( |
34d0d755 |
346 | 'tag' => $vals[0]['tag'], |
347 | 'attributes' => isset($vals[0]['attributes'])? |
348 | $vals[0]['attributes'] : null, |
349 | 'children' => xml_get_children($vals, $i = 0), |
350 | ); |
9b5ef111 |
351 | |
352 | for ($i=0; $i < $id; $i++) |
353 | { |
354 | $val_ancien[$tree[0]['children'][0]['children'][$i]['tag']] = $tree[0]['children'][0]['children'][$i]['value']; |
355 | } |
356 | |
34d0d755 |
357 | $Ancien_renvoye = new Ancien($val_ancien); |
9b5ef111 |
358 | |
359 | //adresse while pour nbre d'adresses |
360 | $num_ad = 0; |
361 | while ($tree[0]['children'][0]['children'][$id]['tag'] == 'ADRESSE') |
362 | { |
363 | for ($i=0; $i <= $id_ad; $i++) |
364 | { |
365 | $val_adresse[$tree[0]['children'][0]['children'][$id]['children'][$i]['tag']] = $tree[0]['children'][0]['children'][$id]['children'][$i]['value']; |
366 | } |
367 | |
34d0d755 |
368 | $Adresse_renvoyee = new Adresse($val_adresse); |
369 | $Ancien_renvoye->Ajout_adresse($Adresse_renvoyee,$num_ad); |
9b5ef111 |
370 | |
371 | //prochaine adresse |
372 | $num_ad = $num_ad + 1; |
373 | $id = $id+1; |
374 | } |
375 | |
34d0d755 |
376 | //idem pour activité |
9b5ef111 |
377 | $num_ac = 0; |
378 | while ($tree[0]['children'][0]['children'][$id]['tag'] == 'ACTIVITE') |
379 | { |
380 | for ($i=0; $i <= $id_ac; $i++) |
381 | { |
382 | $val_activite[$tree[0]['children'][0]['children'][$id]['children'][$i]['tag']] = $tree[0]['children'][0]['children'][$id]['children'][$i]['value']; |
383 | |
384 | for ($j=0; $j <= $id_ad; $j++) |
385 | { |
386 | $val_activite[$tree[0]['children'][0]['children'][$id]['children'][$i]['children'][$j]['tag']] = $tree[0]['children'][0]['children'][$id]['children'][$i]['children'][$j]['value']; |
387 | } |
388 | } |
389 | |
34d0d755 |
390 | $Activite_renvoyee = new Activite($val_activite); |
391 | $Ancien_renvoye->Ajout_activite($Activite_renvoyee,$num_ac); |
9b5ef111 |
392 | |
34d0d755 |
393 | //prochaine activité |
9b5ef111 |
394 | $num_ac = $num_ac + 1; |
395 | $id = $id+1; |
396 | } |
397 | //idem pour formation |
398 | $num_fo = 0; |
399 | while ($tree[0]['children'][0]['children'][$id]['tag'] == 'FORMATION') |
400 | { |
401 | for ($i=0; $i <= $id_fo; $i++) |
402 | { |
403 | $val_formation[$tree[0]['children'][0]['children'][$id]['children'][$i]['tag']] = $tree[0]['children'][0]['children'][$id]['children'][$i]['value']; |
404 | } |
405 | |
34d0d755 |
406 | $Formation_renvoyee = new Formation($val_formation); |
407 | $Ancien_renvoye->Ajout_formation($Formation_renvoyee,$num_fo); |
9b5ef111 |
408 | |
409 | //prochaine formation |
410 | $num_fo = $num_fo + 1; |
411 | $id = $id+1; |
412 | } |
34d0d755 |
413 | } |
9b5ef111 |
414 | } |
9b5ef111 |
415 | } |
34d0d755 |
416 | } |
9b5ef111 |
417 | |
34d0d755 |
418 | //erreur indiquée |
419 | if ($erreur) //erreur ici |
420 | { |
421 | $Ancien_renvoye = new Ancien(''); |
422 | $Ancien_renvoye->Ajout_erreur($erreur); |
9b5ef111 |
423 | } |
34d0d755 |
424 | else |
425 | { //renvoyée par le fichier serveur_renvoie_infos |
426 | $Ancien_renvoye->Ajout_erreur($tree[0]['children'][1]['value']); |
427 | } |
428 | |
429 | return $Ancien_renvoye; |
430 | } |
9b5ef111 |
431 | |
34d0d755 |
432 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
9b5ef111 |
433 | ?> |