Fixes list display.
authorStéphane Jacob <sj@m4x.org>
Sun, 21 Nov 2010 14:31:01 +0000 (15:31 +0100)
committerStéphane Jacob <sj@m4x.org>
Wed, 24 Nov 2010 11:24:54 +0000 (12:24 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
modules/lists/lists.inc.php
templates/lists/admin.tpl
templates/lists/display_list.tpl [new file with mode: 0644]
templates/lists/members.tpl

index 0a8e0d2..5f8c2f4 100644 (file)
 
 // {{{ function list_sort_owners
 
-function list_sort_owners(&$members, $tri_promo = true)
+function list_sort_owners($members, $tri_promo = true)
 {
     global $globals;
 
-    $membres = Array();
+    // $membres' structure is the following: $sortKey => $key => $listMember
+    $membres = array();
 
-    foreach($members as $mem) {
-        $user = User::getSilent($mem);
+    foreach($members as $member) {
+        $user = User::getSilent($member);
         if (!$user) {
-            $membres[0][] = array('l' => $mem, 'p' => (!$tri_promo ? 'inconnus' : null), 'n' => null, 'x' => null, 'b' => null);
+            $membres[0][$member] = array('name' => null, 'email' => $member, 'category' => null, 'uid' => null, 'lost' => null, 'hasProfile' => null);
         } else {
+            $hasProfile = $user->hasProfile();
             $uid = $user->id();
-            $nom = $user->directoryName();
-            $promo = $user->category();
-            if (!$promo) {
-                $promo = 'extérieurs';
-            }
-            $key = $tri_promo ? ($promo != 'extérieurs' ? $promo : 0) : strtoupper(@$nom{0});
-            if ($tri_promo) {
-                $promo = null;
+            $name = $user->directoryName();
+            $category = $user->category();
+            $key = $tri_promo ? ($category ? $category : 'AAAAA') : strtoupper($name{0});
+            if (!$category) {
+                $category = 'extérieurs';
             }
-            $membres[$key][$nom.$mem] = array('n' => $nom, 'l' => $mem, 'p' => $promo, 'x' => $uid, 'b' => $user->lost);
+            $membres[$key][$name . $member] = array('name' => $name, 'email' => $member, 'category' => $category,
+                                                    'uid' => $uid, 'lost' => $user->lost, 'hasProfile' => $hasProfile);
         }
     }
 
     ksort($membres);
-    foreach($membres as $key=>$val) ksort($membres[$key]);
+    foreach($membres as $membre)  {
+        ksort($membre);
+    }
     return $membres;
 }
 
index f5974c6..24d8783 100644 (file)
@@ -108,33 +108,10 @@ emails de marketing. Une fois inscrits à Polytechnique.org, l'inscription à la
 <form method='post' action='{$smarty.server.REQUEST_URI}'>
   {xsrf_token_field}
   <table class='tinybicol' cellpadding='0' cellspacing='0'>
-    {foreach from=$owners item=users key=alpha}
-    {foreach from=$users item=user name=all}
-    <tr>
-      <td class='titre' style="width: 20%">
-        {if $smarty.foreach.all.first}
-        {if $alpha}{$alpha}{/if}
-        {/if}
-      </td>
-      <td>
-        {if t($user.x)}
-        {if t($user.b)}{assign var=lostUsers value=true}{/if}
-        {profile user=$user.x promo=false}
-        {elseif t($user.x)}
-        <a href="{$platal->ns}member/{$user.x}">{if $user.n|trim}{$x.n}{else}{$user.l}{/if}</a>
-        {elseif t($user.n)}
-        {$user.n}
-        {else}
-        {$user.l}
-        {/if}
-        <a href='{$platal->pl_self(1)}?del_owner={$user.l}&amp;token={xsrf_token}'>{icon name=cross title='retirer modérateur'}</a>
-      </td>
-    </tr>
-    {/foreach}
-    {/foreach}
+    {include file='lists/display_list.tpl' list=$owners delete='del_owner' no_sort_key='' promo=true}
     <tr class="pair">
       <td class='titre'>Ajouter</td>
-      <td>
+      <td colspan="2">
         <input type='text' size='30' name='add_owner' />
         <input type='submit' value='ajouter' />
       </td>
@@ -150,47 +127,24 @@ emails de marketing. Une fois inscrits à Polytechnique.org, l'inscription à la
 <form method='post' action='{$smarty.server.REQUEST_URI}' enctype="multipart/form-data">
   {xsrf_token_field}
   <table class='bicol' cellpadding='0' cellspacing='0'>
-    {foreach from=$members item=users key=alpha}
-    {foreach from=$users item=user name=all}
+    {include file='lists/display_list.tpl' list=$members delete='del_member' no_sort_key='' promo=true}
     <tr>
-      <td class='titre' style="width: 20%">
-        {if $smarty.foreach.all.first}
-        {if $alpha}{$alpha}{/if}
-        {/if}
-      </td>
-      <td>
-        {if t($user.x)}
-        {if t($user.b)}{assign var=lostUsers value=true}{/if}
-        {profile user=$user.x promo=false}
-        {elseif t($user.x)}
-        <a href="{$platal->ns}member/{$user.x}">{if $user.n|trim}{$x.n}{else}{$user.l}{/if}</a>
-        {elseif t($user.n)}
-        {$user.n}
-        {else}
-        {$user.l}
-        {/if}
-        <a href='{$platal->pl_self(1)}?del_member={$user.l}&amp;token={xsrf_token}'>{icon name=cross title='retirer membre'}</a>
-      </td>
-    </tr>
-    {/foreach}
-    {/foreach}
-    <tr>
-      <th colspan="2">Ajouter</th>
+      <th colspan="3">Ajouter</th>
     </tr>
     <tr class="pair">
       <td class="titre">Liste</td>
-      <td>
+      <td colspan="2">
         <input type='text' size='40' name='add_member' />
       </td>
     </tr>
     <tr class="pair">
       <td class="titre">ou fichier(*)</td>
-      <td>
+      <td colspan="2">
         <input type="file" name="add_member_file" />*
       </td>
     </tr>
     <tr class="pair">
-      <td colspan="2" class="center">
+      <td colspan="3" class="center">
         <input type='submit' value='ajouter' />
       </td>
     </tr>
diff --git a/templates/lists/display_list.tpl b/templates/lists/display_list.tpl
new file mode 100644 (file)
index 0000000..5b04544
--- /dev/null
@@ -0,0 +1,58 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2010 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+{assign var=lostUsers value=false}
+{foreach from=$list item=users key=sort_key}
+{foreach from=$users item=user name=all}
+<tr>
+  <td class='titre' style="width: 20%">
+    {if $smarty.foreach.all.first}
+    {if $sort_key neq 'AAAAA'}{$sort_key}{else}{$no_sort_key}{/if}
+    {/if}
+  </td>
+  <td>
+    {if t($user.hasProfile)}
+    {if t($user.lost)}{assign var=lostUsers value=true}{/if}
+    {profile user=$user.uid promo=$promo}
+    {elseif t($user.uid)}
+    {if t($user.name)}{$user.name}{else}{$user.email}{/if}{if t($promo)} (extérieur){/if}
+    {elseif t($user.name)}
+    {$user.name}
+    {else}
+    {$user.email}
+    {/if}
+  </td>
+  {if t($delete)}
+  <td class="center">
+    {if t($user.uid)}
+    <a href="{$platal->ns}member/{$user.uid}">{icon name=user_edit title='Éditer'}</a>&nbsp;
+    {else}
+    {icon name=null}&nbsp;
+    {/if}
+    <a href='{$platal->pl_self(1)}?{$delete}={$user.email}&amp;token={xsrf_token}'>{icon name=cross title='Retirer'}</a>
+  </td>
+  {/if}
+</tr>
+{/foreach}
+{/foreach}
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index df7d909..f266b49 100644 (file)
 
 {if $owners|@count}
 <table class='tinybicol' cellpadding='0' cellspacing='0'>
-  {foreach from=$owners item=xs key=promo}
-  {foreach from=$xs item=user name=all}
-  <tr>
-    <td class='titre'>
-      {if $smarty.foreach.all.first}
-      {if $promo}{$promo}{else}non-X{/if}
-      {/if}
-    </td>
-    <td>
-      {if $promo && $user.x}
-      {if $user.b}{assign var=lostUsers value=true}{/if}
-      {profile user=$user.x promo=false}
-      {elseif $user.x}
-      <a href="{$platal->ns}member/{$user.x}">{if $user.n|trim}{$x.n}{else}{$user.l}{/if}</a>
-      {elseif $user.n}
-      {$user.n}
-      {else}
-      {$user.l}
-      {/if}
-    </td>
-    {if $user.p}
-    <td class="right">
-      {$user.p}
-    </td>
-    {/if}
-  </tr>
-  {/foreach}
-  {/foreach}
+  {include file='lists/display_list.tpl' list=$owners delete=false no_sort_key='non-X' promo=$smarty.get.alpha}
 </table>
 {/if}
 
 {if $members|@count}
 <table class='bicol' cellpadding='0' cellspacing='0'>
   {if $details.own || hasPerms('admin,groupadmin')}
-  <tr><td colspan="3">
+  <tr><td colspan="2">
   <a href="{$platal->ns}lists/csv/{$platal->argv[1]}/{$platal->argv[1]}.csv">
     {icon name="page_excel" title="Télécharger la liste des membres"}
     Télécharger la liste des membres au format Excel
   </a>
   </td></tr>
   {/if}
-  {assign var=lostUsers value=false}
-  {foreach from=$members item=users key=promo}
-  {foreach from=$users item=user name=all}
-  <tr>
-    <td class='titre' style="width: 20%">
-      {if $smarty.foreach.all.first}
-      {if $promo}{$promo}{else}non-X{/if}
-      {/if}
-    </td>
-    <td>
-      {if $promo && $user.x}
-      {if $user.b}{assign var=lostUsers value=true}{/if}
-      {profile user=$user.x promo=false}
-      {elseif $user.x}
-      <a href="{$platal->ns}member/{$user.x}">{if $user.n|trim}{$x.n}{else}{$user.l}{/if}</a>
-      {elseif $user.n}
-      {$user.n}
-      {else}
-      {$user.l}
-      {/if}
-    </td>
-    {if $user.p}
-    <td class="right">
-      {$user.p}
-    </td>
-    {/if}
-  </tr>
-  {/foreach}
-  {/foreach}
+  {include file='lists/display_list.tpl' list=$members delete=false no_sort_key='non-X' promo=$smarty.get.alpha}
 </table>
 
-{if $lostUsers}
+{if t($lostUsers)}
 <p class="smaller">
   {icon name=error}&nbsp;Un camarade signalé par ce symbole n'a plus d'adresse de redirection et ne peut donc
   plus être contacté via son adresse polytechnique.org. Si tu connais sa nouvelle adresse, tu peux nous la communiquer en