From: x2003bruneau Date: Sun, 17 Dec 2006 18:46:47 +0000 (+0000) Subject: New page to add users in the database X-Git-Tag: xorg/0.9.13~181 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=1f53925a716bf5cb97ed624a6787a8319eb2bcff;p=platal.git New page to add users in the database git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1285 839d8a87-29fc-0310-9880-83ba4fa771e5 --- diff --git a/ChangeLog b/ChangeLog index 0a0d068..b1c720f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ New: * Admin: - Show last contact date on marketing validation -Fal/FRU + - New page to add users in the database -FRU * Core: - New mailer -FRU diff --git a/classes/csvimporter.php b/classes/csvimporter.php index 606f444..816b9fa 100644 --- a/classes/csvimporter.php +++ b/classes/csvimporter.php @@ -35,6 +35,7 @@ class CSVImporter private $user_functions = array(); private $field_desc = array(); + private $field_value = array(); public function CSVImporter($table, $key = 'id', $do_sql = true) { @@ -47,7 +48,7 @@ class CSVImporter { $array = split($this->separator, $line); if (is_null($this->index)) { - $this->index = $array; + $this->index = array_map('strtolower', $array); return true; } @@ -205,7 +206,7 @@ class CSVImporter public function registerFunction($name, $desc, $callback) { - if (is_callable($callback)) { + if (is_callable($callback, false, $ref)) { $this->user_functions['func_' . $name] = array('desc' => $desc, 'callback' => $callback); return true; } @@ -217,6 +218,11 @@ class CSVImporter $this->field_desc[$name] = $desc; } + public function forceValue($name, $value) + { + $this->field_value[$name] = $value; + } + /** Handle insertion form * @param $page PlatalPage to process * @param $url URI of the page @@ -230,6 +236,9 @@ class CSVImporter if (is_null($fields)) { return false; } + foreach ($this->field_value as $key=>$value) { + unset($fields[$key]); + } $current = Env::v('csv_page'); if (empty($current)) { @@ -271,6 +280,9 @@ class CSVImporter $update[$key] = $insert[$key]; } } + foreach ($this->field_value as $key=>$value) { + $insert[$key] = $value; + } if ($current == 'valid' && Env::has('csv_valid')) { $this->run(Env::v('csv_action'), $insert, $update); $page->assign('csv_done', true); @@ -283,7 +295,7 @@ class CSVImporter } } $page->assign('csv_index', $this->index); - $page->assign('csv_funtions', $this->user_functions); + $page->assign('csv_functions', $this->user_functions); $page->assign('csv_field_desc', $this->field_desc); $page->assign('csv_page', $next); $page->assign('csv_path', $url); diff --git a/modules/admin.php b/modules/admin.php index ab1a129..0f77284 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -39,6 +39,7 @@ class AdminModule extends PLModule 'admin/skins' => $this->make_hook('skins', AUTH_MDP, 'admin'), 'admin/synchro_ax' => $this->make_hook('synchro_ax', AUTH_MDP, 'admin'), 'admin/user' => $this->make_hook('user', AUTH_MDP, 'admin'), + 'admin/promo' => $this->make_hook('promo', AUTH_MDP, 'admin'), 'admin/validate' => $this->make_hook('validate', AUTH_MDP, 'admin'), 'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_MDP, 'admin'), 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP, 'admin'), @@ -551,6 +552,55 @@ class AdminModule extends PLModule $page->assign('mr',$mr); } } + + function getMatricule($line, $key) + { + $mat = $line['matricule']; + $year = intval(substr($mat, 0, 3)); + $rang = intval(substr($mat, 3, 3)); + if ($year > 200) { $year /= 10; }; + if ($year < 96) { + return null; + } else { + return sprintf('%04u%04u', 1900+$year, $rang); + } + } + + function handler_promo(&$page, $action = null, $promo = null) + { + if (Env::has('promo')) { + if(Env::i('promo') > 1900 && Env::i('promo') < 2050) { + $action = Env::v('valid_promo') == 'Ajouter des membres' ? 'add' : 'ax'; + pl_redirect('admin/promo/' . $action . '/' . Env::i('promo')); + } else { + $page->trig('Promo non valide'); + } + } + + $page->changeTpl('admin/promo.tpl'); + if ($promo > 1900 && $promo < 2050 && ($action == 'add' || $action == 'ax')) { + $page->assign('promo', $promo); + } else { + return; + } + + $importer = new CSVImporter('auth_user_md5', 'matricule'); + $importer->registerFunction('matricule', 'matricle Ecole vers X.org', array($this, 'getMatricule')); + switch ($action) { + case 'add': + $fields = array('nom', 'nom_ini', 'prenom', + 'prenom_ini', 'promo', 'promo_sortie', 'flags', + 'matricule', 'matricule_ax', 'perms'); + $importer->forceValue('promo', $promo); + $importer->forceValue('promo_sortie', $promo + 3); + break; + case 'ax': + $fields = array('matricule', 'matricule_ax'); + break; + } + $importer->apply($page, "admin/promo/$action/$promo", $fields); + } + function handler_homonyms(&$page, $op = 'list', $target = null) { $page->changeTpl('admin/homonymes.tpl'); $page->assign('xorg_title','Polytechnique.org - Administration - Homonymes'); diff --git a/templates/admin/index.tpl b/templates/admin/index.tpl index 01caec8..80cfd52 100644 --- a/templates/admin/index.tpl +++ b/templates/admin/index.tpl @@ -55,6 +55,8 @@ Utilisateurs :   + Ajout +   |   Edit/Su/Logs   |   Homonymes diff --git a/templates/admin/promo.tpl b/templates/admin/promo.tpl new file mode 100644 index 0000000..de3cbff --- /dev/null +++ b/templates/admin/promo.tpl @@ -0,0 +1,42 @@ +{**************************************************************************} +{* *} +{* 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 *} +{* *} +{**************************************************************************} + +

Mise à jour de l'annuaire

+ +
+ + + +
+ Promotion : +
+ + +
+
+
+ +{if $promo} +{include file="include/csv-importer.tpl"} +{/if} + +{* vim:set et sw=2 sts=2 sws=2: *}