Adds XSRF protection to the Carnet module.
[platal.git] / include / synchro_ax.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2008 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 is_ax_key_missing() {
28 global $globals;
29 return !isset($globals->webservice->private_key_ax) || !is_file($globals->webservice->private_key_ax);
30 }
31
32 function get_user_ax($matricule_ax, $raw=false)
33 {
34 require_once('webservices/ax/client.inc');
35
36 $ancien = recupere_infos_ancien($matricule_ax);
37
38 $userax = Array();
39 $userax['matricule_ax'] = $matricule_ax;
40
41 $userax['nom'] = strtoupper($ancien->Nom_patr());
42 $userax['nom_usage'] = strtoupper($ancien->Nom_usuel());
43 if ($userax['nom_usage'] == $userax['nom']) $userax['nom_usage'] = '';
44 $userax['prenom'] = $ancien->Prenom();
45 $userax['sexe'] = ($ancien->Civilite() != 'M')?1:0;
46 $userax['promo'] = $ancien->Promo();
47 /* $userax['nationalite'] = $ancien->Nationalite();
48 if ($userax['nationalite'] == 'F') $userax['nationalite'] = 'Français'; */
49 //$userax['date'] = substr($ancien[12], 0, 10);
50 $userax['mobile'] = trim($ancien->Mobile(0));
51 /* if ($ancien->Corps() == 'D' || $ancien->Corps() == 'Z') {
52 $userax['corps'] = false;
53 } else {
54 $userax['corps'] = $ancien->Corps();
55 $userax['corps_grade'] = $ancien->Grade();
56 } */
57 $userax['adr_pro'] = array();
58
59 for ($i = 0; $i < $ancien->Num_Activite(); $i++) {
60 $jobax = array();
61 $jobax['entreprise'] = $ancien->Entreprise($i);
62 if (!$jobax['entreprise'])
63 $jobax['entreprise'] = $ancien->Adresse_act_adresse1($i);
64 $jobax['poste'] = $ancien->Fonction($i);
65 $jobax['adr1'] = $ancien->Adresse_act_adresse1($i);
66 $jobax['adr2'] = $ancien->Adresse_act_adresse2($i);
67 $jobax['adr3'] = $ancien->Adresse_act_adresse3($i);
68 $jobax['postcode'] = $ancien->Adresse_act_code_pst($i);
69 $jobax['city'] = $ancien->Adresse_act_ville($i);
70 $jobax['region'] = $ancien->Adresse_act_etat_region($i);
71 $jobax['countrytxt'] = ucwords(strtolower($ancien->Adresse_act_pays($i)));
72 $jobax['tel'] = $ancien->Adresse_act_tel($i);
73 $jobax['fax'] = $ancien->Adresse_act_fax($i);
74 $jobax['mobile'] = $ancien->Adresse_act_mobile($i);
75 $jobax['pub'] = 'ax';
76 $jobax['tel_pub'] = 'ax';
77 $jobax['adr_pub'] = 'ax';
78 $jobax['email_pub'] = 'ax';
79 $userax['adr_pro'][] = $jobax;
80 }
81
82 $userax['adr'] = array();
83 for($i=$ancien->Num_adresse() - 1; $i >= 0; $i--) {
84 $adrax = array();
85 $adrax['adr1'] = $ancien->Adresse1($i);
86 $adrax['adr2'] = $ancien->Adresse2($i);
87 $adrax['adr3'] = $ancien->Adresse3($i);
88 $adrax['postcode'] = $ancien->Code_pst($i);
89 $adrax['city'] = $ancien->Ville($i);
90 $adrax['region'] = $ancien->Etat_region($i);
91 $adrax['countrytxt'] = ucwords(strtolower($ancien->Pays($i)));
92 $adrax['pub'] = 'ax';
93 if ($ancien->Tel($i) || $ancien->Fax($i)) {
94 $adrax['tels'] = array();
95 if ($tel = $ancien->Tel($i))
96 $adrax['tels'][] = array('tel' => $tel, 'tel_type' => 'Tél.', 'tel_pub' => 'ax');
97 if ($tel = $ancien->Fax($i))
98 $adrax['tels'][] = array('tel' => $tel, 'tel_type' => 'Fax', 'tel_pub' => 'ax');
99 }
100 if ($ancien->Mobile($i)) $userax['mobile'] = $ancien->Mobile($i);
101 $userax['adr'][$i] = $adrax;
102 }
103
104 /* $userax['formation'] = array();
105 for($i=$ancien->Num_formation() - 1; $i >= 0; $i--)
106 $userax['formation'][$i] = $ancien->Formation($i);*/
107
108 return $userax;
109 }
110
111 function ax_synchronize($login, $uid) {
112 require_once('user.func.inc.php');
113 require_once 'profil.func.inc.php';
114 // get details from user, but looking only info that can be seen by ax
115 $user = get_user_details($login, $uid, 'ax');
116 $userax= get_user_ax($user['matricule_ax']);
117 $diff = diff_user_details($userax, $user, 'ax');
118 set_user_details($user['user_id'], $diff);
119 }
120 // vim:set et sw=4 sts=4 sws=4 enc=utf-8:
121 ?>