X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fsynchro_ax.inc.php;h=12bd4ad0f492317dc2c1bb3291d9529eadd8ae53;hb=9e1816c7666767755abbc24f6a0df290efff81b6;hp=3f78e2bdf57668e18193f387073ef90676aba81b;hpb=79a5acea67d00315fe79f2daad4568cd4d423235;p=platal.git diff --git a/include/synchro_ax.inc.php b/include/synchro_ax.inc.php index 3f78e2b..12bd4ad 100644 --- a/include/synchro_ax.inc.php +++ b/include/synchro_ax.inc.php @@ -1,6 +1,6 @@ webservice->private_key_ax) || !is_file($globals->webservice->private_key_ax); +} - $res = $globals->xdb->query( - "SELECT matricule_ax - FROM auth_user_md5 AS u - WHERE u.user_id = {?}", $uid); - $matricule_ax = $res->fetchOneCell(); +function get_user_ax($matricule_ax, $raw=false) +{ + require_once('webservices/ax/client.inc'); $ancien = recupere_infos_ancien($matricule_ax); $userax = Array(); $userax['matricule_ax'] = $matricule_ax; - $userax['uid'] = $uid; - - $userax['nom'] = $ancien->Nom_patr(); - $userax['nom_usage'] = $ancien->Nom_usuel(); + + $userax['nom'] = mb_strtoupper($ancien->Nom_patr()); + $userax['nom_usage'] = mb_strtoupper($ancien->Nom_usuel()); if ($userax['nom_usage'] == $userax['nom']) $userax['nom_usage'] = ''; $userax['prenom'] = $ancien->Prenom(); $userax['sexe'] = ($ancien->Civilite() != 'M')?1:0; $userax['promo'] = $ancien->Promo(); - $userax['nationalite'] = $ancien->Nationalite(); - if ($userax['nationalite'] == 'F') $userax['nationalite'] = 'Français'; +/* $userax['nationalite'] = $ancien->Nationalite(); + if ($userax['nationalite'] == 'F') $userax['nationalite'] = 'Français'; */ //$userax['date'] = substr($ancien[12], 0, 10); - $userax['mobile'] = $ancien->Mobile(0); - if ($ancien->Corps() == 'D' || $ancien->Corps() == 'Z') { - $userax['applis_join'] = "pas un corps"; + $userax['mobile'] = trim($ancien->Mobile(0)); +/* if ($ancien->Corps() == 'D' || $ancien->Corps() == 'Z') { + $userax['corps'] = false; } else { - $userax['applis_join'] = "Corps ".$ancien->Corps()." - ".$ancien->Grade(); - } + $userax['corps'] = $ancien->Corps(); + $userax['corps_grade'] = $ancien->Grade(); + } */ $userax['adr_pro'] = array(); - + for ($i = 0; $i < $ancien->Num_Activite(); $i++) { $jobax = array(); $jobax['entreprise'] = $ancien->Entreprise($i); - $jobax['fonction'] = $ancien->Fonction($i); + if (!$jobax['entreprise']) + $jobax['entreprise'] = $ancien->Adresse_act_adresse1($i); + $jobax['poste'] = $ancien->Fonction($i); $jobax['adr1'] = $ancien->Adresse_act_adresse1($i); $jobax['adr2'] = $ancien->Adresse_act_adresse2($i); $jobax['adr3'] = $ancien->Adresse_act_adresse3($i); $jobax['postcode'] = $ancien->Adresse_act_code_pst($i); $jobax['city'] = $ancien->Adresse_act_ville($i); $jobax['region'] = $ancien->Adresse_act_etat_region($i); - $jobax['country'] = $ancien->Adresse_act_pays($i); + $jobax['countrytxt'] = ucwords(mb_strtolower($ancien->Adresse_act_pays($i))); $jobax['tel'] = $ancien->Adresse_act_tel($i); $jobax['fax'] = $ancien->Adresse_act_fax($i); $jobax['mobile'] = $ancien->Adresse_act_mobile($i); + $jobax['pub'] = 'ax'; + $jobax['tel_pub'] = 'ax'; + $jobax['adr_pub'] = 'ax'; + $jobax['email_pub'] = 'ax'; $userax['adr_pro'][] = $jobax; } $userax['adr'] = array(); - foreach ($array['dump']['adresse'] as $adr) { + for($i=$ancien->Num_adresse() - 1; $i >= 0; $i--) { $adrax = array(); $adrax['adr1'] = $ancien->Adresse1($i); $adrax['adr2'] = $ancien->Adresse2($i); @@ -85,163 +85,34 @@ function get_user_ax($uid, $raw=false) $adrax['postcode'] = $ancien->Code_pst($i); $adrax['city'] = $ancien->Ville($i); $adrax['region'] = $ancien->Etat_region($i); - $adrax['country'] = $ancien->Pays($i); - $adrax['tel'] = $ancien->Tel($i); - $adrax['fax'] = $ancien->Fax($i); - $userax['adr'][] = $adrax; - } - if ($raw) { - $userax['raw'] = $ancien; - } - - return $userax; -} - -function import_from_ax($userax, $nom_usage=false, $mobile=false, $del_address=null, $add_address=null, $del_pro=null, $add_pro=null, $nationalite=false) -{ - global $globals; - - if ($nom_usage) { - $globals->xdb->execute("UPDATE auth_user_md5 SET nom_usage = {?} WHERE user_id = {?}", strtoupper($userax['nom_usage']), $userax['uid']); - } - - if ($mobile) { - $globals->xdb->execute("UPDATE auth_user_quick SET profile_mobile = {?} WHERE user_id = {?}", $userax['mobile'], $userax['uid']); - } - - if ($nationalite) { - if ($userax['nationalite'] == 'Français') { - $userax['nationalite'] = 'FR'; + $adrax['countrytxt'] = ucwords(mb_strtolower($ancien->Pays($i))); + $adrax['pub'] = 'ax'; + if ($ancien->Tel($i) || $ancien->Fax($i)) { + $adrax['tels'] = array(); + if ($tel = $ancien->Tel($i)) + $adrax['tels'][] = array('tel' => $tel, 'tel_type' => 'Tél.', 'tel_pub' => 'ax'); + if ($tel = $ancien->Fax($i)) + $adrax['tels'][] = array('tel' => $tel, 'tel_type' => 'Fax', 'tel_pub' => 'ax'); } - $globals->xdb->execute("UPDATE auth_user_md5 SET nationalite = {?} WHERE user_id = {?}", $userax['nationalite'], $userax['uid']); - } - if (is_array($del_address)) foreach($del_address as $adrid) { - $globals->xdb->execute("DELETE FROM adresses WHERE uid = {?} AND adrid = {?}", $userax['uid'], $adrid); - $globals->xdb->execute("DELETE FROM tels WHERE uid = {?} AND adrid = {?}", $userax['uid'], $adrid); - } - - if (is_array($del_pro)) foreach($del_pro as $entrid) { - $globals->xdb->execute("DELETE FROM entreprises WHERE uid = {?} AND entrid = {?}", $userax['uid'], $entrid); + if ($ancien->Mobile($i)) $userax['mobile'] = $ancien->Mobile($i); + $userax['adr'][$i] = $adrax; } - if (is_array($add_address)) { - - $res = $globals->xdb->query( - "SELECT adrid - FROM adresses - WHERE uid = {?} AND adrid >= 1 - ORDER BY adrid", - $userax['uid']); - $adrids = $res->fetchColumn(); - $i_adrid = 0; - $new_adrid = 1; - - foreach($add_address as $adrid) { - - $adr = $userax['adr'][$adrid]; +/* $userax['formation'] = array(); + for($i=$ancien->Num_formation() - 1; $i >= 0; $i--) + $userax['formation'][$i] = $ancien->Formation($i);*/ - // find the next adrid not used - while ($adrids[$i_adrid] == $new_adrid) { - $i_adrid++; - $new_adrid++; - } - - if ($adr['city']) { - - $res = $globals->xdb->query( - "SELECT a2 FROM geoloc_pays - WHERE pays LIKE {?} OR country LIKE {?}", - $adr['country'], $adr['country']); - - $a2 = $res->fetchOneCell(); - } - if (!$a2) { $a2 = '00'; } - - $globals->xdb->execute( - "INSERT INTO adresses - SET uid = {?}, adrid = {?}, - adr1 = {?}, adr2 = {?}, adr3 = {?}, - postcode = {?}, city = {?}, - country = {?}, - datemaj = NOW(), - pub = 'ax'", - $userax['uid'], $new_adrid, - $adr['adr1'], $adr['adr2'], $adr['adr3'], - $adr['postcode'], $adr['city'], - $a2); - // import tels - if ($adr['tel']) - $globals->xdb->execute( - "INSERT INTO adresses - SET uid = {?}, adrid = {?}, tel = {?}, - telid = 0, tel_type = 'Tel.', tel_pub = 'ax'", - $userax["uid"], $new_adrid, $adr['tel']); - if ($adr['fax']) - $globals->xdb->execute( - "INSERT INTO adresses - SET uid = {?}, adrid = {?}, tel = {?}, - telid = 1, tel_type = 'Fax', tel_pub = 'ax'", - $userax["uid"], $new_adrid, $adr['fax']); - } - } - - if (is_array($add_pro)) { - - $res = $globals->xdb->query( - "SELECT entrid FROM entreprises - WHERE uid = {?} AND entrid >= 1 ORDER BY entrid", - $userax['uid']); - $entrids = $res->fetchColumn(); - $i_entrid = 0; - $new_entrid = 1; - - $nb_entr = count($entrids); - - foreach($add_pro as $entrid) if ($nb_entr < 2) { - - $nb_entr++; - - $pro = $userax['adr_pro'][$entrid]; - - // find the next adrid not used - while ($entrids[$i_entrid] == $new_entrid) { - $i_entrid++; - $new_entrid++; - } - - if ($pro['country']) { - $res = $globals->xdb->query( - "SELECT a2 FROM geoloc_pays - WHERE pays LIKE {?} OR country LIKE {?}", - $pro['country'], $pro['country']); - $a2 = $res->fetchOneCell(); - } - if (!$a2) { $a2 = '00'; } - - $globals->xdb->execute( - "INSERT INTO entreprises - SET uid = {?}, entrid = {?}, - entreprise = {?}, poste = {?}, - adr1 = {?}, adr2 = {?}, adr3 = {?}, - postcode = {?}, city = {?}, - country = {?}, - tel = {?}, fax = {?}, - pub = 'ax', adr_pub = 'ax', tel_pub = 'ax'", - $userax['uid'], $new_entrid, - $pro['entreprise'], $pro['fonction'], - $pro['adr1'], $pro['adr2'], $pro['adr3'], - $pro['postcode'], $pro['city'], - $a2, - $pro['tel'], $pro['fax']); - } - } + return $userax; } -function copy_from_ax($uid) -{ - $uax = get_user_ax($uid); - import_from_ax($uax, false, true, null, array_keys($uax['adr']), null, array_keys($uax['adr_pro']), true); +function ax_synchronize($login, $uid) { + require_once('user.func.inc.php'); + require_once 'profil.func.inc.php'; + // get details from user, but looking only info that can be seen by ax + $user = get_user_details($login, $uid, 'ax'); + $userax= get_user_ax($user['matricule_ax']); + $diff = diff_user_details($userax, $user, 'ax'); + set_user_details($user['user_id'], $diff); } - -// vim:set et sw=4 sts=4 sws=4: +// vim:set et sw=4 sts=4 sws=4 enc=utf-8: ?>