ergonomie synchro_x + coding rules
authorPascal Corpet <pascal.corpet@m4x.org>
Tue, 18 Jan 2005 23:49:24 +0000 (23:49 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:27:50 +0000 (23:27 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-387

htdocs/admin/synchro_ax.php
include/synchro_ax.inc.php
templates/admin/synchro_ax.tpl

index 3820c12..9bc3332 100644 (file)
@@ -77,7 +77,7 @@ if ($login) {
             }
         }
 
-        import_from_ax($userax, Env::has('epouse'), Env::has('mobile'), $adr_dels, $adr_adds, $pro_dels, $pro_adds);
+        import_from_ax($userax, Env::has('epouse'), Env::has('mobile'), $adr_dels, $adr_adds, $pro_dels, $pro_adds, Env::has('nationalite'));
 
     }
 
@@ -86,8 +86,13 @@ if ($login) {
     if ($userax) {
         $user['matricule_ax'] = $userax['matricule_ax'];
         unset($userax['matricule_ax']);
+        $user['nom'] = ucwords(strtolower($user['nom']));
+        $user['epouse'] = ucwords(strtolower($user['epouse']));
     }
 
+    $page->assign('watch_champs',array('nom', 'epouse', 'prenom', 'nationalite', 'mobile'));
+    $page->assign('modifiables', array(0,1,0,1,1));
+
     $page->assign('x', $user);
     $page->assign('ax', $userax); 
 }
index da96161..f2e626f 100644 (file)
@@ -38,14 +38,12 @@ function get_user_ax($uid, $raw=false)
     $matricule_ax = $res->fetchOneCell();
 
     $array = get_annuaire_infos(2, $matricule_ax, 0);
-    
-    $ancien = $array['dump']['ancien'];
 
     $userax = Array();
-
     $userax['matricule_ax'] = $matricule_ax;
     $userax['uid'] = $uid;
     
+    $ancien = $array['dump']['ancien'];
     $userax['nom'] = $ancien[0];
     // ancien1 = ?
     $userax['epouse'] = ($ancien[2] != $ancien[0])?$ancien[2]:"";
@@ -56,6 +54,7 @@ function get_user_ax($uid, $raw=false)
     // ancien7 = Type de membre à l'AX
     // ancien8 = dernière année de cotisation
     $userax['nationalite'] = $ancien[9];
+    if ($userax['nationalite'] == 'F') $userax['nationalite'] = 'Français';
     // ancien10 = ?
     // ancine11 = ?
     $userax['date'] = substr($ancien[12], 0, 10);
@@ -130,7 +129,7 @@ function get_user_ax($uid, $raw=false)
     return $userax;
 }
 
-function import_from_ax($userax, $epouse=false, $mobile=false, $del_address=null, $add_address=null, $del_pro=null, $add_pro=null)
+function import_from_ax($userax, $epouse=false, $mobile=false, $del_address=null, $add_address=null, $del_pro=null, $add_pro=null, $nationalite=false)
 { 
     global $globals;
 
@@ -142,6 +141,12 @@ function import_from_ax($userax, $epouse=false, $mobile=false, $del_address=null
         $globals->xdb->execute("UPDATE auth_user_md5 SET mobile = {?} WHERE user_id = {?}", $userax['mobile'], $userax['uid']);
     }
 
+    if ($nationalite) {
+        if ($userax['nationalite'] == 'Français') {
+            $userax['nationalite'] = 'FR';
+        }
+        $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);
     }
@@ -152,31 +157,42 @@ function import_from_ax($userax, $epouse=false, $mobile=false, $del_address=null
 
     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;
+        $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];
+        foreach($add_address as $adrid) {
 
-        // find the next adrid not used
-        while ($adrids[$i_adrid] == $new_adrid) { $i_adrid++; $new_adrid++; }
-        
-        if ($adr['pays']) {
-            $res = $globals->xdb->query("SELECT a2 FROM geoloc_pays WHERE pays LIKE {?} OR country LIKE {?}", $adr['pays'], $adr['pays']);
-            $a2 = $res->fetchOneCell();
-        }
-        if (!$a2) {
-            $a2 = '00';
-        }
-        
-        $globals->xdb->execute(
-            "INSERT INTO adresses
-                     SET uid = {?}, adrid = {?},
-                         adr1 = {?}, adr2 = {?}, adr3 = {?},
-                         cp = {?}, ville = {?},
+            $adr = $userax['adr'][$adrid];
+
+            // find the next adrid not used
+            while ($adrids[$i_adrid] == $new_adrid) {
+                $i_adrid++;
+                $new_adrid++;
+            }
+            
+            if ($adr['pays']) {
+            
+                $res = $globals->xdb->query(
+                "SELECT a2 FROM geoloc_pays
+                 WHERE pays LIKE {?} OR country LIKE {?}",
+                 $adr['pays'], $adr['pays']);
+                 
+                $a2 = $res->fetchOneCell();
+            }
+            if (!$a2) { $a2 = '00'; }
+            
+            $globals->xdb->execute(
+                "INSERT INTO adresses
+                         SET uid = {?}, adrid = {?},
+                             adr1 = {?}, adr2 = {?}, adr3 = {?},
+                             cp = {?}, ville = {?},
                          pays = {?},
                          tel = {?}, fax = {?},
                          datemaj = NOW(),
@@ -186,37 +202,45 @@ function import_from_ax($userax, $epouse=false, $mobile=false, $del_address=null
                 $adr['cp'], $adr['ville'],
                 $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) {
+        $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);
 
-        $nb_entr++;
-    
-        $pro = $userax['adr_pro'][$entrid];
+        foreach($add_pro as $entrid) if ($nb_entr < 2) {
 
-        // find the next adrid not used
-        while ($entrids[$i_entrid] == $new_entrid) { $i_entrid++; $new_entrid++; }
+            $nb_entr++;
         
-        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 = {?},
+            $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 = {?},
                          entreprise = {?}, poste = {?},
                          adr1 = {?}, adr2 = {?}, adr3 = {?},
                          cp = {?}, ville = {?},
@@ -229,7 +253,8 @@ function import_from_ax($userax, $epouse=false, $mobile=false, $del_address=null
                 $pro['cp'], $pro['ville'],
                 $a2,
                 $pro['tel'], $pro['fax']);
-    }}
+        }
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4:
index 7ef50cb..fad0f38 100644 (file)
   <tr>
     <th>champ</th>
     <th style='width:50%'>x.org</th>
-    <th>supprimer</th>
-    <th style='width:50%'>AX</th>
     <th>importer</th>
+    <th style='width:50%'>AX</th>
   </tr>
-  <tr class="pair">
-    <td>fiches</td>
-    <td colspan='2'>
+  <tr class="impair">
+    <td>fiche</td>
+    <td>
       <a href='{rel}/fiche.php?user={$x.user_id}' class='popup2'>polytechnique.org</a>
     </td>
-    <td colspan='2'>
+    <td>
+    </td>
+    <td>
       <a href='http://www.polytechniciens.com/index.php?page=AX_FICHE_ANCIEN&amp;anc_id={$x.matricule_ax}'>polytechniciens.com</a>
     </td>
   </tr>
-{foreach from=$ax item='val' key='i'}
-  {if ($i neq 'adr') and ($i neq 'adr_pro')}
-    {if $x[$i] neq $val}
-    <tr class="{cycle values='impair,pair'}">
+{foreach from=$watch_champs item='i'}
+  {if $x[$i] or $ax[$i]}
+    <tr class="{if ($x[$i] eq $ax[$i]) or !$ax[$i]}im{/if}pair">
       <td>
         {$i}
       </td>
-      <td colspan='2'>
+      <td>
         {$x[$i]}
       </td>
-      <td colspan='2'>
-        {if (($i eq 'epouse') or ($i eq 'mobile')) and $val}
-        <div style='float:right'>
-          <input style='flat:right' type='checkbox' name='{$i}' />
-        </div>
+      <td class='center'>
+        {if $x[$i] eq $ax[$i]}
+          ==
+        {else}
+          {if $ax[$i]}
+            <input style='flat:right' type='checkbox' name='{$i}' />
+          {/if}
         {/if}
-        {$val}
+      </td>
+      <td>
+        {$ax[$i]}
       </td>
     </tr>
-    {/if}
   {/if}
 {/foreach}
-  <tr class='impair'>
-    <td>
-      adresses
-    </td>
-    <td colspan='2'>
+</table>
+
+<table>
+<tr>
+<td>
+{if $ax.adr[0]}
+{if $x.adr}
+<div>
+  Supprimer les adresses suivantes :
+</div>
+<table>
     {foreach from=$x.adr item='adr'}
-      <div style="padding:5px">
-        {if $ax.adr[0]}
-        <div style='float:right'>
+      <tr style="padding:5px">
+        <td>
           <input type='checkbox' name='del_address{$adr.adrid}' />
-        </div>
-        {/if}
-        {include file='geoloc/address.tpl' address=$adr no_div=1}
-      </div>
+        </td>
+        <td>
+          {include file='geoloc/address.tpl' address=$adr no_div=1}
+        </td>
+      </tr>
     {/foreach}
-    </td>
-    <td colspan='2'>
+</table>
+<div>
+  et les remplacer par les adresses suivantes de l'AX :
+</div>
+{else}
+<div>
+  Importer les adresses AX suivantes :
+</div>
+{/if}
+<table>
     {foreach from=$ax.adr item='adr' key='adrid'}
-      <div style='padding:5px'>
-        <div style='float:right'>
+      <tr style='padding:5px'>
+        <td>
           <input type='checkbox' name='add_address{$adrid}' />
-        </div>
-        {include file='geoloc/address.tpl' address=$adr no_div=1}
-      </div>
+        </td>
+        <td>
+          {include file='geoloc/address.tpl' address=$adr no_div=1}
+        </td>
+      </tr>
     {/foreach}
-    </td>
-  </tr>
-  <tr class='pair'>
-    <td>
-      adr_pro
-    </td>
-    <td colspan='2'>
+</table>
+{/if}
+</td>
+
+<td>
+{if $ax.adr_pro[0].entreprise}
+{if $x.adr_pro}
+<div>
+  Supprimer les emplois suivants :
+</div>
+<table>
     {foreach from=$x.adr_pro item='pro'}
     {if ($pro.poste) or ($pro.fonction) or ($pro.entreprise)}
-      <div style='padding:5px'>
-        {if $ax.adr_pro[0]}
-        <div style='float:right'>
+      <tr style='padding:5px'>
+        <td>
           <input type='checkbox' name='del_pro{$pro.entrid}' />
-        </div>
-        {/if}
+        </td>
+        <td>
         {if $pro.entreprise}
         <div>
           <em>Entreprise/Organisme : </em> <strong>{$pro.entreprise}</strong>
         </div>
         {/if}
         {include file='geoloc/address.tpl' address=$pro no_div=1}
-      </div>
+        </td>
+      </tr>
     {/if}
     {/foreach}
-    </td>
-    <td colspan='2'>
+</table>
+
+<div>
+  et les remplacer par les emplois suivants de l'AX :
+</div>
+{else}
+<div>
+  Importer les emplois suivants depuis l'AX :
+</div>
+{/if}
+<table>
     {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'>
+      <tr style='padding:5px'>
+        <td>
           <input type='checkbox' name='add_pro{$proid}' />
-        </div>
+        </td>
+        <td>
         {if $pro.entreprise}
         <div>
           <em>Entreprise/Organisme : </em> <strong>{$pro.entreprise}</strong>
         </div>
         {/if}
         {include file='geoloc/address.tpl' address=$pro no_div=1}
-      </div>
+        </td>
+      </tr>
     {/if}
     {/foreach}
-    </td>
-  </tr>
+</table>
+{/if}
+</td>
+</tr>
 </table>
 <div class='center'>
   <input type='hidden' name='user' value='{$ax.uid}' />