whish 151 : mise a jour depuis l'AX
authorPascal Corpet <pascal.corpet@m4x.org>
Tue, 18 Jan 2005 16:43:20 +0000 (16:43 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:27:48 +0000 (23:27 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-379

htdocs/synchro_ax.php
include/synchro_ax.inc.php
include/user.func.inc.php
templates/geoloc/address.tpl
templates/synchro_ax.tpl

index 7e9e8f4..4aba88a 100644 (file)
@@ -26,10 +26,6 @@ new_admin_page('synchro_ax.tpl');
 require_once('user.func.inc.php');
 require_once('synchro_ax.inc.php');
 
-if (!Env::has('user') && !Env::has('mat')) {
-    $page->kill("cette page n'existe pas");
-}
-
 if (Env::has('user')) {
     $login = get_user_forlife(Env::get('user'));
     if ($login === false) {
@@ -44,17 +40,41 @@ if (Env::has('mat')) {
          INNER JOIN  auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie')
               WHERE  matricule={?}", Env::getInt('mat'));
     $login = $res->fetchOneCell();
-    if (empty($login)) {
-        $page->kill("cette page n'existe pas");
-    }
 }
 
-$new   = Env::get('modif') == 'new';
+if ($login) {
+    $new   = Env::get('modif') == 'new';
+    $user  = get_user_details($login, Session::getInt('uid'));
+    $userax= get_user_ax($user['user_id']);
+
+if (Env::has('importe')) {
+
+    $adr_dels = array();
+    foreach ($user['adr'] as $adr)
+        if (Env::has('del_address'.$adr['adrid'])) $adr_dels[] = $adr['adrid'];
+        
+    $adr_adds = array();
+    foreach ($userax['adr'] as $i => $adr)
+        if (Env::has('add_address'.$i)) $adr_adds[] = $i;
+    
+    $pro_dels = array();
+    foreach ($user['adr_pro'] as $pro)
+        if (Env::has('del_pro'.$pro['entrid'])) $pro_dels[] = $pro['proid'];
+
+    $pro_adds = array();
+    foreach ($userax['adr_pro'] as $i => $pro)
+        if (Env::has('add_pro'.$i)) $pro_adds[] = $i;
+
+    import_from_ax($userax, Env::has('epouse'), Env::has('mobile'), $adr_dels, $adr_adds, $pro_dels, $pro_adds);
+
+}
+
 $user  = get_user_details($login, Session::getInt('uid'));
 
 $page->assign('x', $user);
-$page->assign('ax', get_user_ax($user['user_id'])); 
-
+$page->assign('ax', $userax); 
+}
 $page->run();
 
+// vim:set et sts=4 sws=4 sw=4:
 ?>
index 5b710e0..b9351ef 100644 (file)
@@ -94,7 +94,7 @@ function import_from_ax($userax, $epouse=false, $mobile=false, $del_address=null
     global $globals;
 
     if ($epouse) {
-        $globals->xdb->execute("UPDATE auth_user_md5 SET epouse = {?} WHERE user_id = {?}", $userax['epouse'], $userax['uid']);
+        $globals->xdb->execute("UPDATE auth_user_md5 SET epouse = {?} WHERE user_id = {?}", strtoupper($userax['epouse']), $userax['uid']);
     }
     
     if ($mobile) {
@@ -105,10 +105,14 @@ function import_from_ax($userax, $epouse=false, $mobile=false, $del_address=null
         $globals->xdb->execute("DELETE FROM adresses 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 (is_array($add_address)) {
 
-    $res = $globals->xdb->query("SELECT adrid FROM adresses WHERE uid = {?} ORDER BY adrid", $userax['uid']);
-    $adrids = $res->fetchOneColumn();
+    $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;
     
@@ -131,12 +135,55 @@ function import_from_ax($userax, $epouse=false, $mobile=false, $del_address=null
                          adr1 = {?}, adr2 = {?}, adr3 = {?},
                          cp = {?}, ville = {?},
                          pays = {?},
+                         tel = {?}, fax = {?},
                          datemaj = NOW(),
                          visibilite = 'adr_ax,tel_ax'",
                 $userax['uid'], $new_adrid,
                 $adr['adr1'], $adr['adr2'], $adr['adr3'],
                 $adr['cp'], $adr['ville'],
-                $a2);
+                $a2,
+                $adr['tel'], $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['pays']) {
+            $res = $globals->xdb->query("SELECT a2 FROM geoloc_pays WHERE pays LIKE {?} OR country LIKE {?}", $pro['pays'], $pro['pays']);
+            $a2 = $res->fetchOneCell();
+        }
+        if (!$a2) $a2 = '00';
+        
+        $globals->xdb->execute(
+            "INSERT INTO entreprises
+                     SET uid = {?}, entrid = {?},
+                         adr1 = {?}, adr2 = {?}, adr3 = {?},
+                         cp = {?}, ville = {?},
+                         pays = {?},
+                         tel = {?}, fax = {?},
+                         entreprise = {?}, fonction = {?},
+                         visibilite = 'entreprise_ax,adr_ax,tel_ax'",
+                $userax['uid'], $new_entrid,
+                $pro['adr1'], $pro['adr2'], $pro['adr3'],
+                $pro['cp'], $pro['ville'],
+                $a2,
+                $pro['tel'], $pro['fax'],
+                $pro['entreprise'], $pro['fonction']);
     }}
 }
 
index 974d3bd..8410932 100644 (file)
@@ -157,7 +157,7 @@ function &get_user_details($login, $from_uid = '')
     global $globals;
     $reqsql = "SELECT  u.user_id, u.promo, u.prenom, u.nom, u.epouse, u.date, u.cv, u.mobile, u.web, u.libre,
                        u.perms IN ('admin','user') AS inscrit,  FIND_IN_SET('femme', u.flags) AS sexe, u.deces != 0 AS dcd, u.deces,
-                       q.profile_nick AS nickname,
+                       q.profile_nick AS nickname, q.profile_from_ax,
                        IF(gp.nat='',gp.pays,gp.nat) AS nationalite, gp.a2 AS iso3166,
                        a.alias AS forlife, a2.alias AS bestalias,
                        c.uid IS NOT NULL AS is_contact,
@@ -180,7 +180,7 @@ function &get_user_details($login, $from_uid = '')
 
     $sql  = "SELECT  e.entreprise, s.label as secteur , ss.label as sous_secteur , f.fonction_fr as fonction,
                      e.poste, e.adr1, e.adr2, e.adr3, e.cp, e.ville,
-                     gp.pays, gr.name, e.tel, e.fax, e.mobile
+                     gp.pays, gr.name, e.tel, e.fax, e.mobile, e.entrid
                FROM  entreprises AS e
           LEFT JOIN  emploi_secteur AS s ON(e.secteur = s.id)
           LEFT JOIN  emploi_ss_secteur AS ss ON(e.ss_secteur = ss.id AND e.secteur = ss.secteur)
@@ -194,7 +194,7 @@ function &get_user_details($login, $from_uid = '')
 
     $sql  = "SELECT  a.adr1,a.adr2,a.adr3,a.cp,a.ville,
                      gp.pays,gr.name AS region,a.tel,a.fax,
-                     FIND_IN_SET('active', a.statut) AS active,
+                     FIND_IN_SET('active', a.statut) AS active, a.adrid,
                      FIND_IN_SET('res-secondaire', a.statut) AS secondaire
                FROM  adresses AS a
           LEFT JOIN  geoloc_pays AS gp ON (gp.a2=a.pays)
index 4b80d84..dbb548a 100644 (file)
@@ -20,7 +20,9 @@
 
 
       {if $address.adr1 || $address.pays || $geoloc_address.ville || $address.tel || $address.fax || $address.mobile}
+      {if $no_div neq 1}
       <div class="adresse">
+      {/if}
         {if $titre && ($address.adr1 || $address.ville || $address.pays)}
           {if $titre_div}
             <div class="titre">
@@ -59,7 +61,9 @@
         </div>
         {/if}
 
+      {if $no_div neq 1}
       </div>
       {/if}
+      {/if}
 
 {* vim:set et sw=2 sts=2 sws=2: *}
index 3b696ab..f06ca57 100644 (file)
   Synchronisation depuis l'AX
 </h1>
 
-<table class="bicol" cellpadding="0" cellspacing="0">
+<form action='{$smarty.request.PHP_SELF}' method='get'>
+<table class="tinybicol">
+<tr>
+  <th>Synchroniser un utilisateur</th>
+</tr>
+<tr>
+  <td style='padding:5px'>
+    <input type='text' name='user' value='{$smarty.request.user}' size='40' maxlength='255'/>
+    <input type='submit' value='Chercher' />
+  </td>
+</tr>
+</table>
+</form>
+
+<form action='{$smarty.request.PHP_SELF}' method='post'>
+{if $x.profile_from_ax}
+<div style="text-align:center;margin:5px;background:green">
+<strong>Cet utilisateur a accpeté la synchronisation</strong>
+</div>
+{else}
+<div style="text-align:center;margin:5px;background:red">
+<strong>ATTENTION !  Cet utilisateur n'a pas accepté la synchronisation</strong>
+</div>
+{/if}
+<table class="bicol" cellpadding="0" cellspacing="0" border="1">
   <tr>
     <th>champ</th>
-    <th style='width:50%'>AX</th>
     <th style='width:50%'>x.org</th>
+    <th style='width:50%'>AX</th>
   </tr>
 {foreach from=$ax item='val' key='i'}
-  <tr class="{cycle values='pair,impair'}">
+  {if ($i neq 'adr') and ($i neq 'adr_pro')}
+    <tr class="{cycle values='impair,pair'}">
+      <td>
+        {$i}
+      </td>
+      <td>
+        {$x[$i]}
+      </td>
+      <td>
+        {if ($i eq 'epouse') or ($i eq 'mobile')}
+        <div style='float:right'>
+          <input style='flat:right' type='checkbox' name='{$i}' />
+        </div>
+        {/if}
+        {$val}
+      </td>
+    </tr>
+  {/if}
+{/foreach}
+  <tr class='impair'>
     <td>
-    {$i}
+      adresses
     </td>
     <td>
-    {if ($i neq 'adr') and ($i neq 'adr_pro')}
-    {$val}
-    {else}
-    {foreach from=$val item='sval' key='j'}
-      {include file='geoloc/address.tpl' address=$sval}
-    {/foreach}{/if}
+    {foreach from=$x.adr item='adr'}
+      <div style="padding:5px">
+        <div style='float:right'>
+          <input type='checkbox' name='del_address{$adr.adrid}' />
+        </div>
+        {include file='geoloc/address.tpl' address=$adr no_div=1}
+      </div>
+    {/foreach}
     </td>
     <td>
-    {if ($i neq 'adr') and ($i neq 'adr_pro')}
-    {$x[$i]}
-    {else}
-    {foreach from=$x[$i] item='sval' key='j'}
-      {include file='geoloc/address.tpl' address=$sval}
-    {/foreach}{/if}
+    {foreach from=$ax.adr item='adr' key='adrid'}
+      <div style='padding:5px'>
+        <div style='float:right'>
+          <input type='checkbox' name='add_address{$adrid}' />
+        </div>
+        {include file='geoloc/address.tpl' address=$adr no_div=1}
+      </div>
+    {/foreach}
+    </td>
+  </tr>
+  <tr class='pair'>
+    <td>
+      adr_pro
+    </td>
+    <td>
+    {foreach from=$x.adr_pro item='pro'}
+    {if ($pro.poste) or ($pro.fonction) or ($pro.entreprise)}
+      <div style='padding:5px'>
+        <div style='float:right'>
+          <input type='checkbox' name='add_pro{$pro.entrid}' />
+        </div>
+        {if $pro.entreprise}
+        <div>
+          <em>Entreprise/Organisme : </em> <strong>{$pro.entreprise}</strong>
+        </div>
+        {/if}
+        {if $pro.secteur}
+        <div>
+          <em>Secteur : </em>
+          <strong>{$pro.secteur}{if $pro.ss_secteur} ({$pro.ss_secteur}){/if}</strong>
+        </div>
+        {/if}
+        {if $pro.fonction}
+        <div>
+          <em>Fonction : </em> <strong>{$pro.fonction}</strong>
+        </div>
+        {/if}
+        {if $pro.poste}
+        <div>
+          <em>Poste : </em> <strong>{$pro.poste}</strong>
+        </div>
+        {/if}
+        {include file='geoloc/address.tpl' address=$pro no_div=1}
+      </div>
+    {/if}
+    {/foreach}
+    </td>
+    <td>
+    {foreach from=$ax.adr_pro item='pro' key='proid'}
+    {if ($pro.poste) or ($pro.fonction) or ($pro.entreprise)}
+      <div style='padding:5px'>
+        <div style='float:right'>
+          <input type='checkbox' name='add_pro{$proid}' />
+        </div>
+        {if $pro.entreprise}
+        <div>
+          <em>Entreprise/Organisme : </em> <strong>{$pro.entreprise}</strong>
+        </div>
+        {/if}
+        {if $pro.fonction}
+        <div>
+          <em>Fonction : </em> <strong>{$pro.fonction}</strong>
+        </div>
+        {/if}
+        {include file='geoloc/address.tpl' address=$pro no_div=1}
+      </div>
+    {/if}
+    {/foreach}
     </td>
   </tr>
-{/foreach}
 </table>
-
+<div class='center'>
+  <input type='hidden' name='user' value='{$ax.uid}' />
+  <input type='submit' name='importe' value='Importer' />
+</div>
+</form>
 
 {* vim:set et sw=2 sts=2 sws=2: *}