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