Close #429: tools to store informations about duplicated adresses
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Thu, 27 Jul 2006 14:13:10 +0000 (14:13 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Thu, 27 Jul 2006 14:13:10 +0000 (14:13 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@678 839d8a87-29fc-0310-9880-83ba4fa771e5

ChangeLog
bin/cron/emails.check.php
htdocs/images/icons/page_edit.gif [new file with mode: 0644]
modules/email.php
templates/admin/index.tpl
templates/admin/wiki.tpl
templates/emails/duplicated.tpl [new file with mode: 0644]
templates/table-editor.tpl

index a5f7e32..22a5acd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -76,6 +76,7 @@ Bug/Wish:
     * Admin:
         - #430: Specify date format on downtime admin page.                -Car
         - #397: Can edit death date in user admin page                     -FRU
+        - #429: Tools to administrate duplicated adresses                  -FRU
 
     * Carnet:
         - #435: Calendar contains yearly events for all the contacts.      -FRU
index fc9322c..3762c7b 100755 (executable)
@@ -46,7 +46,7 @@ while (list($alias1, $alias2, $mail) = $it->next()) {
 if (count($conflits) > 0) {
     echo "Nouvelles adresses en doublon détectées :\n" . join("\n", $conflits)
         . "\n\nVous pouvez entrer les informations collectées à ce sujet sur la page :\n"
-        . "http://www.polytechnique.org/admin/doublons";
+        . "http://www.polytechnique.org/admin/emails/duplicated";
 
     echo "\n\n";
     $sql = "INSERT IGNORE INTO emails_watch (email, state, detection, last)
diff --git a/htdocs/images/icons/page_edit.gif b/htdocs/images/icons/page_edit.gif
new file mode 100644 (file)
index 0000000..9f6eb3b
Binary files /dev/null and b/htdocs/images/icons/page_edit.gif differ
index 1113aa4..0e7a1b4 100644 (file)
@@ -30,6 +30,8 @@ class EmailModule extends PLModule
             'emails/broken'   => $this->make_hook('broken', AUTH_COOKIE),
             'emails/redirect' => $this->make_hook('redirect', AUTH_MDP),
             'emails/send'     => $this->make_hook('send', AUTH_MDP),
+
+            'admin/emails/duplicated' => $this->make_hook('duplicated', AUTH_MDP, 'admin')
         );
     }
 
@@ -375,6 +377,97 @@ L'
             }
         }
     }
+
+    function handler_duplicated(&$page, $action = 'list', $email = null)
+    {
+        $page->changeTpl('emails/duplicated.tpl');
+
+        $states = array('pending'   => 'En attente...',
+                        'safe'      => 'Pas d\'inquiétude',
+                        'unsafe'    => 'Recherches en cours',
+                        'dangerous' => 'Usurpations par cette adresse');
+        $page->assign('states', $states);
+
+        switch (Post::v('action')) {
+        case 'create':
+            if (trim(Post::v('emailN')) != '') {
+                Xdb::execute('INSERT IGNORE INTO emails_watch (email, state, detection, last, uid, description)
+                                          VALUES ({?}, {?}, CURDATE(), NOW(), {?}, {?})',
+                             trim(Post::v('emailN')), Post::v('stateN'), S::i('uid'), Post::v('descriptionN'));
+            };
+            break;
+
+        case 'edit':
+            Xdb::execute('UPDATE emails_watch
+                             SET state = {?}, last = NOW(), uid = {?}, description = {?}
+                           WHERE email = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), Post::v('emailN'));
+            break;
+
+        default:
+            if ($action == 'delete' && !is_null($email)) {
+                Xdb::execute('DELETE FROM emails_watch WHERE email = {?}', $email);
+            }
+        }
+        if ($action != 'create' && $action != 'edit') {
+            $action = 'list';
+        }
+        $page->assign('action', $action);
+
+        if ($action == 'list') {
+            $sql = "SELECT  w.email, w.detection, w.state, a.alias AS forlife
+                      FROM  emails_watch  AS w
+                INNER JOIN  emails        AS e USING(email)
+                INNER JOIN  aliases       AS a ON (a.id = e.uid AND a.type = 'a_vie')
+                  ORDER BY  w.state, w.email, a.alias";
+            $it = Xdb::iterRow($sql);
+
+            $table = array();
+            $props = array();
+            while (list($email, $date, $state, $forlife) = $it->next()) {
+                if (count($props) == 0 || $props['mail'] != $email) {
+                    if (count($props) > 0) {
+                        $table[] = $props;
+                    }
+                    $props = array('mail' => $email,
+                                   'detection' => $date,
+                                   'state' => $state,
+                                   'users' => array($forlife));
+                } else {
+                    $props['users'][] = $forlife;
+                }
+            }
+            if (count($props) > 0) {
+                $table[] = $props;
+            }
+            $page->assign('table', $table);
+        } elseif ($action == 'edit') {
+            $sql = "SELECT  w.detection, w.state, w.last, w.description,
+                            a1.alias AS edit, a2.alias AS forlife
+                      FROM  emails_watch AS w
+                INNER JOIN  emails       AS e  USING(email)
+                 LEFT JOIN  aliases      AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie')
+                INNER JOIN  aliases      AS a2 ON (a2.id = e.uid AND a2.type = 'a_vie')
+                     WHERE  w.email = {?}
+                  ORDER BY  a2.alias";
+            $it = Xdb::iterRow($sql, $email);
+
+            $props = array();
+            while (list($detection, $state, $last, $description, $edit, $forlife) = $it->next()) {
+                if (count($props) == 0) {
+                    $props = array('mail'        => $email,
+                                   'detection'   => $detection,
+                                   'state'       => $state,
+                                   'last'        => $last,
+                                   'description' => $description,
+                                   'edit'        => $edit,
+                                   'users'       => array($forlife));
+                } else {
+                    $props['users'][] = $forlife;
+                }
+            }
+            $page->assign('doublon', $props);
+        }
+    }
 }
 
 ?>
index 6515294..5abbc8a 100644 (file)
@@ -42,6 +42,8 @@
       <a href="admin/logger">Logs des sessions</a>
       &nbsp;&nbsp;|&nbsp;&nbsp;
       <a href="admin/logger/actions">Actions</a>
+      &nbsp;&nbsp;|&nbsp;&nbsp;
+      <a href="admin/emails/duplicated">Doublons</a>
     </td>
   </tr>
 </table>
index 5548d4d..84204d0 100644 (file)
@@ -57,7 +57,7 @@
 {foreach from=$wiki_pages item=perm key=page}
   <tr class="{cycle values="impair,pair"}">
     <td>
-      <a href="{$page|replace:'.':'/'}">{$page}</a> <a href="{$page|replace:'.':'/'}?action=edit" class="indice">{icon name=date_edit title='éditer'}</a>
+      <a href="{$page|replace:'.':'/'}">{$page}</a> <a href="{$page|replace:'.':'/'}?action=edit" class="indice">{icon name=page_edit title='éditer'}</a>
     </td>
     <td class="center">
       {$perm.read}
diff --git a/templates/emails/duplicated.tpl b/templates/emails/duplicated.tpl
new file mode 100644 (file)
index 0000000..4091cf9
--- /dev/null
@@ -0,0 +1,127 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2006 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               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<h1>Gestion des adresses en doublon</h1>
+
+{if $action eq "list"}
+<table class="bicol">
+  <tr>
+    <th>Adresse</th>
+    <th>Etat</th>
+    <th>Utilisateurs</th>
+    <th></th>
+  </tr>
+  <tr>
+  <tr class="impair">
+    <td colspan="2">
+      <strong>Ajouter une entrée manuellement</strong>
+    </td>
+    <td colspan="2" class="right">
+      <strong><a href="admin/emails/duplicated/create">créer{icon name=add}</a></strong>
+    </td>
+  </tr>
+  {foreach from=$table item=doublon}
+  <tr class="{cycle values="pair,impair"}">
+    <td>
+      <strong>{$doublon.mail}</strong><br />
+      Détecté le {$doublon.detection|date_format}
+    </td>
+    <td>
+      {$doublon.state}
+    </td>
+    <td class="right">
+      {foreach from=$doublon.users item=user name=all}
+      <a href="profile/{$user}">{$user}{icon name=user_suit title="Fiche"}</a>
+      <a href="admin/user/{$user}">{icon name=wrench title="Administrer}</a>{if !$smarty.foreach.all.last}<br />{/if}
+      {/foreach}
+    </td>
+    <td class="right">
+      <a href="admin/emails/duplicated/edit/{$doublon.mail}">{icon name=page_edit title="Editer"}</a>
+      <a href="admin/emails/duplicated/delete/{$doublon.mail}">{icon name=delete title="Supprimer"}</a>
+    </td>
+  </tr>
+  {/foreach}
+</table>
+{elseif $action eq "create" || $action eq "edit"}
+[<a href="admin/emails/duplicated">Retour à la liste des doublons</a>]<br /><br />
+<form method="post" action="admin/emails/duplicated">
+<table class="tinybicol">
+  <tr>
+    <th colspan="2"><strong>Commenter le doublon</strong></th>
+  </tr>
+  <tr class="impair">
+    <td class="title"><strong>Adresse mail</strong></td>
+  {if $action eq "create"}
+    <td><input type="text" name="emailN" /></td>
+  {else}
+    <td>
+      <a href="mailto:{$doublon.mail}">{icon name=email title="Envoyer un mail"}</a>
+      &nbsp;{$doublon.mail}
+      <input type="hidden" name="emailN" value="{$doublon.mail}" />
+    </td>
+  {foreach from=$doublon.users key=i name=all item=user}
+  {if $i is even}<tr class="impair">{/if}
+    <td>
+      <a href="profile/{$user}">{$user}{icon name=user_suit title="Fiche"}</a>
+      <a href="admin/user/{$user}">{icon name=wrench title="Administrer}</a>{if !$smarty.foreach.all.last}<br />{/if}
+    </td>
+    {if $i is even && $smarty.foreach.all.last}<td></td>{/if}
+  {if $id is odd || $smarty.foreach.all.last}</tr>{/if}
+  {/foreach}
+  </tr>
+  <tr class="pair">
+    <td class="title"><strong>Date de détection</strong></td>
+    <td>{$doublon.detection|date_format}</td>
+  {/if}
+  </tr>
+  <tr class="pair">
+    <td class="title"><strong>Danger</strong></td>
+    <td>
+      <select name="stateN">
+        {foreach from=$states key=state item=text}
+        <option value="{$state}"{if $doublon.state eq $state} selected="selected"{/if}>{$text}</option>
+        {/foreach}
+      </select>
+    </td>
+  </tr>
+  <tr class="impair">
+    <td colspan="2" class="title">
+      <strong>Description</strong><br/>
+      {if $doublon.edit}<small>Dernière édition par {$doublon.edit} le {$doublon.last|date_format}</small>{/if}
+    </td>
+  </tr>
+  <tr class="impair">
+    <td colspan="2" class="center">
+      <textarea cols="50" rows="10" name="descriptionN">{$doublon.description}</textarea>
+    </td>
+  </tr>
+  <tr>
+    <th colspan="2">
+      <input type="hidden" name="action" value="{$action}" />
+      <input type="submit" name="valid"  value="Valider" />
+    </th>
+  </tr>
+</table>
+</form>
+{/if}
+
+{* vim:set et sw=2 sts=2 sws=2: *}
index 6601c7d..392c55a 100644 (file)
@@ -61,7 +61,7 @@
   {if !$hideactions}
   <td class="action">
     {if !$readonly}
-    <a href="{$t->pl}/edit/{$idval}">{icon name=date_edit title='éditer'}</a>
+    <a href="{$t->pl}/edit/{$idval}">{icon name=page_edit title='éditer'}</a>
     <a href="{$t->pl}/delete/{$idval}">{icon name=delete title='supprimer'}</a>
     {/if}
   </td>