From 0d75939a5e7640b66188ab4fc5d03a999b2c574e Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Sat, 20 Jan 2007 00:15:56 +0000 Subject: [PATCH] AXLetter administration page git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1365 839d8a87-29fc-0310-9880-83ba4fa771e5 --- ChangeLog | 3 ++ modules/axletter.php | 85 +++++++++++++++++++++++++++++++++++++- modules/axletter/axletter.inc.php | 24 +++++++++++ templates/admin/index.tpl | 8 ++++ templates/axletter/admin.tpl | 50 ++++++++++++++++++++++ templates/include/csv-importer.tpl | 4 ++ 6 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 templates/axletter/admin.tpl diff --git a/ChangeLog b/ChangeLog index b48d62b..9ff7535 100644 --- 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 diff --git a/modules/axletter.php b/modules/axletter.php index 9ad8292..d1f1c44 100644 --- a/modules/axletter.php +++ b/modules/axletter.php @@ -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; + } } ?> diff --git a/modules/axletter/axletter.inc.php b/modules/axletter/axletter.inc.php index 0f16c36..a2a136b 100644 --- a/modules/axletter/axletter.inc.php +++ b/modules/axletter/axletter.inc.php @@ -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'; diff --git a/templates/admin/index.tpl b/templates/admin/index.tpl index febf955..679e18a 100644 --- a/templates/admin/index.tpl +++ b/templates/admin/index.tpl @@ -134,6 +134,14 @@ Pages et permissions + + + AX-Letter :   + Edition +   |   + Inscriptions et Permissions + + {* 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 index 0000000..85dff99 --- /dev/null +++ b/templates/axletter/admin.tpl @@ -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 *} +{* *} +{**************************************************************************} + +

Droits d'administration des lettres de l'AX

+ +
+ + + + + + + + + {iterate item=a from=$admins} + + + + + {/iterate} +
NomAction
+ + +
{$a.prenom} {$a.nom} (X{$a.promo}){icon name=user_suit}{icon name=cross title="Retirer"}
+
+ +

Ajout d'utilisateurs

+ +{include file="include/csv-importer.tpl"} + +{* vim:set et sw=2 sts=2 sws=2: *} diff --git a/templates/include/csv-importer.tpl b/templates/include/csv-importer.tpl index 3234a80..199e1d6 100644 --- a/templates/include/csv-importer.tpl +++ b/templates/include/csv-importer.tpl @@ -20,6 +20,10 @@ {* *} {**************************************************************************} +{if $form_title} +

{$form_title}

+{/if} +