AXLetter administration page
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 20 Jan 2007 00:15:56 +0000 (00:15 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 20 Jan 2007 00:15:56 +0000 (00:15 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1365 839d8a87-29fc-0310-9880-83ba4fa771e5

ChangeLog
modules/axletter.php
modules/axletter/axletter.inc.php
templates/admin/index.tpl
templates/axletter/admin.tpl [new file with mode: 0644]
templates/include/csv-importer.tpl

index b48d62b..9ff7535 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,9 @@ New:
         - Show last contact date on marketing validation                -Fal/FRU
         - New page to add users in the database                            -FRU
 
+    * AXLetter:
+        - New module AXLetter (legal mailer for AX)                        -FRU
+
     * Core:
         - New mailer                                                       -FRU
         - Signal bug send to OTRS and not trackers.                        -Car
index 9ad8292..d1f1c44 100644 (file)
@@ -30,7 +30,7 @@ class AXLetterModule extends PLModule
             'ax/edit'        => $this->make_hook('submit', AUTH_MDP),
             'ax/edit/cancel' => $this->make_hook('cancel', AUTH_MDP),
             'ax/edit/valid'  => $this->make_hook('valid',  AUTH_MDP),
-            'admin/axletter/rights'        => $this->make_hook('admin_rights', AUTH_MDP, 'admin'),
+            'admin/axletter' => $this->make_hook('admin', AUTH_MDP, 'admin'),
         );
     }
 
@@ -276,6 +276,89 @@ class AXLetterModule extends PLModule
                         S::v('mail_fmt') != 'texte');
         }
     }
+
+    function handler_admin(&$page, $action = null, $uid = null)
+    {
+        require_once dirname(__FILE__) . '/axletter/axletter.inc.php';
+        if (Post::has('action')) {
+            $action = Post::v('action');
+            $uid    = Post::v('uid');
+        }
+        if ($uid) {
+            $uids   = preg_split('/ *[,;\: ] */', $uid);
+            foreach ($uids as $uid) {
+                switch ($action) {
+                  case 'add':
+                    $res = AXLetter::grantPerms($uid);
+                    break;
+                  case 'del';
+                    $res = AXLetter::revokePerms($uid);
+                    break;
+                }
+                if (!$res) {
+                    $page->trig("Personne ne oorrespond à l'identifiant '$uid'");
+                }
+            }
+        }
+
+        $page->changeTpl('axletter/admin.tpl');
+        $res = XDB::iterator("SELECT IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom,
+                                     u.prenom, u.promo, a.alias AS forlife
+                                FROM axletter_rights AS ar
+                          INNER JOIN auth_user_md5   AS u USING(user_id)
+                          INNER JOIN aliases         AS a ON (u.user_id = a.id AND a.type = 'a_vie')");
+        $page->assign('admins', $res);
+        
+        $importer = new CSVImporter('axletter_ins');
+        $importer->registerFunction('user_id', 'email vers Id X.org', array($this, 'idFromMail'));
+        $importer->forceValue('hash', array($this, 'createHash'));
+        $importer->apply($page, "admin/axletter", array('user_id', 'email', 'prenom', 'nom', 'promo', 'hash'));
+    }
+
+    function idFromMail($line, $key)
+    {
+        static $field;
+        if (!isset($field)) {
+            $field = array('email', 'mail', 'login', 'bestalias', 'forlife', 'flag');
+            foreach ($field as $fld) {
+                if (isset($line[$fld])) {
+                    $field = $fld;
+                    break;
+                }
+            }
+        }
+        $email = $line[$field];
+        if (strpos($email, '@') === false) {
+            $user  = $email;
+        } else {
+            global $globals;
+            list($user, $domain) = explode('@', $email);    
+            if ($domain != $globals->mail->domain && $domain != $globals->mail->domain2
+                && $domain != $globals->mail->alias_dom && $domain != $globals->mail->alias_dom2) {
+                return '0';
+            }
+            if ($domain == $globals->mail->alias_dom || $domain == $globals->mail->alias_dom2) {
+                $res = XDB::query("SELECT a.id
+                                     FROM virtual          AS v
+                               INNER JOIN virtual_redirect AS r USING(vid)
+                               INNER JOIN aliases          AS a ON (a.type = 'a_vie'
+                                                                AND r.redirect = CONCAT(a.alias, '@{$globals->mail->domain2}')
+                                    WHERE v.alias = CONCAT({?}, '@{$globals->mail->alias_dom}')", $user);
+                $id = $res->fetchOneCell();
+                return $id ? $id : '0';
+            }
+        }
+        $res = XDB::query("SELECT id FROM aliases WHERE alias = {?}", $user);
+        $id = $res->fetchOneCell();
+        return $id ? $id : '0';
+    }
+
+    function createHash($line, $key)
+    {
+        $hash = implode(time(), $line);
+        $hash = md5($hash);
+        return $hash;
+    }
 }
 
 ?>
index 0f16c36..a2a136b 100644 (file)
@@ -157,6 +157,30 @@ class AXLetter extends MassMailer
         return $res->fetchOneCell();
     }
 
+    static public function grantPerms($uid)
+    {
+        if (!is_numeric($uid)) {
+            $res = XDB::query("SELECT id FROM aliases WHERE alias = {?}", $uid);
+            $uid = $res->fetchOneCell();
+        }
+        if (!$uid) {
+            return false;
+        }
+        return XDB::execute("INSERT IGNORE INTO axletter_rights SET user_id = {?}", $uid);
+    }
+
+    static public function revokePerms($uid)
+    {
+        if (!is_numeric($uid)) {
+            $res = XDB::query("SELECT id FROM aliases WHERE alias = {?}", $uid);
+            $uid = $res->fetchOneCell();
+        }   
+        if (!$uid) {
+            return false;
+        }
+        return XDB::execute("DELETE FROM axletter_rights WHERE user_id = {?}", $uid);
+    }
+
     protected function subscriptionTable()
     {
         return 'axletter_ins';
index febf955..679e18a 100644 (file)
       <a href="admin/wiki">Pages et permissions</a>
     </td>
   </tr>
+  <tr class="pair">
+    <td>
+      <strong>AX-Letter :</strong>&nbsp;&nbsp;
+      <a href="ax/edit">Edition</a>
+      &nbsp;&nbsp;|&nbsp;&nbsp;
+      <a href="admin/axletter">Inscriptions et Permissions</a>
+    </td>
+  </tr>
 </table>
 
 {* vim:set et sw=2 sts=2 sws=2: *}
diff --git a/templates/axletter/admin.tpl b/templates/axletter/admin.tpl
new file mode 100644 (file)
index 0000000..85dff99
--- /dev/null
@@ -0,0 +1,50 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  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>Droits d'administration des lettres de l'AX</h1>
+
+<form action="admin/axletter" method="post">
+  <table class="tinybicol">
+    <tr>
+      <th>Nom</th>
+      <th>Action</th>
+    </tr>
+    <tr class="pair">
+      <td colspan="2" class="center">
+        <input type="text" name="uid" value="" />
+        <input type="submit" name="action" value="add" />
+      </td>
+    </tr>
+    {iterate item=a from=$admins}
+    <tr class="{cycle values="impair, pair"}">
+      <td><a href="profile/{$a.forlife}" class="popup2">{$a.prenom} {$a.nom} (X{$a.promo}){icon name=user_suit}</a></td>
+      <td class="right"><a href="admin/axletter/del/{$a.forlife}">{icon name=cross title="Retirer"}</a></td>
+    </tr>
+    {/iterate}
+  </table>
+</form>
+
+<h1>Ajout d'utilisateurs</h1>
+
+{include file="include/csv-importer.tpl"}
+
+{* vim:set et sw=2 sts=2 sws=2: *}
index 3234a80..199e1d6 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
+{if $form_title}
+<h1>{$form_title}</h1>
+{/if}
+
 <script type="text/javascript">//<![CDATA[
 {literal}
   function showValue(key, box)