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