Overview
Comment: | Import des membres depuis Galette |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
9afa585de04b8b8cdd9a69ad6cf8da27 |
User & Date: | bohwaz on 2014-03-22 01:31:39 |
Other Links: | manifest | tags |
Context
2014-03-22
| ||
02:19 | Import au format CSV garradin check-in: dd2ab5b039 user: bohwaz tags: trunk | |
01:31 | Import des membres depuis Galette check-in: 9afa585de0 user: bohwaz tags: trunk | |
01:30 | Mettre les champs vides à NULL avant de créer l'index sinon ça risque de foirer (deux champs vides ne sont pas uniques) check-in: 0e386a3a61 user: bohwaz tags: trunk | |
Changes
Modified src/include/class.membres.php from [475706e765] to [0cd205af5e].
︙ | ︙ | |||
276 277 278 279 280 281 282 | { if (!$check_editable && (!empty($config['private']) || empty($config['editable']))) { unset($data[$key]); continue; } | | | | | | 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | { if (!$check_editable && (!empty($config['private']) || empty($config['editable']))) { unset($data[$key]); continue; } if (!isset($data[$key]) || (!is_array($data[$key]) && trim($data[$key]) === '') || (is_array($data[$key]) && empty($data[$key]))) { if (!empty($config['mandatory']) && ($check_password || $key != 'passe')) { throw new UserException('Le champ "' . $config['title'] . '" doit obligatoirement être renseigné.'); } elseif (!empty($config['mandatory'])) { continue; } } if (isset($data[$key])) { if ($config['type'] == 'email' && trim($data[$key]) !== '' && !filter_var($data[$key], FILTER_VALIDATE_EMAIL)) { throw new UserException('Adresse e-mail invalide dans le champ "' . $config['title'] . '".'); } elseif ($config['type'] == 'url' && trim($data[$key]) !== '' && !filter_var($data[$key], FILTER_VALIDATE_URL)) { throw new UserException('Adresse URL invalide dans le champ "' . $config['title'] . '".'); } elseif ($config['type'] == 'tel') { $data[$key] = utils::normalizePhoneNumber($data[$key]); } elseif ($config['type'] == 'country') { $data[$key] = strtoupper(substr($data[$key], 0, 2)); } elseif ($config['type'] == 'checkbox') { $data[$key] = empty($data[$key]) ? 0 : 1; } elseif ($config['type'] == 'number' && trim($data[$key]) !== '') { if (empty($data[$key])) { $data[$key] = 0; } if (!is_numeric($data[$key])) |
︙ | ︙ | |||
345 346 347 348 349 350 351 352 353 354 355 356 357 358 | { $binary |= 0x01 << $k; } } $data[$key] = $binary; } } } if (isset($data['code_postal']) && trim($data['code_postal']) != '') { if (!empty($data['pays']) && $data['pays'] == 'FR' && !preg_match('!^\d{5}$!', $data['code_postal'])) { | > > > > > > | 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | { $binary |= 0x01 << $k; } } $data[$key] = $binary; } // Un champ texte vide c'est un champ NULL if (is_string($data[$key]) && trim($data[$key]) === '') { $data[$key] = null; } } } if (isset($data['code_postal']) && trim($data['code_postal']) != '') { if (!empty($data['pays']) && $data['pays'] == 'FR' && !preg_match('!^\d{5}$!', $data['code_postal'])) { |
︙ | ︙ | |||
703 704 705 706 707 708 709 | $sujet = '['.$config->get('nom_asso').'] '.$sujet; while ($row = $res->fetchArray(SQLITE3_ASSOC)) { utils::mail($row['email'], $sujet, $message, $headers); } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 709 710 711 712 713 714 715 716 717 718 719 720 721 722 | $sujet = '['.$config->get('nom_asso').'] '.$sujet; while ($row = $res->fetchArray(SQLITE3_ASSOC)) { utils::mail($row['email'], $sujet, $message, $headers); } return true; } public function searchSQL($query) { $db = DB::getInstance(); |
︙ | ︙ |
Added src/include/class.membres_import.php version [555583a988].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | <?php namespace Garradin; class Membres_Import { /** * Champs du CSV de Galette * les lignes vides ('') ne seront pas proposées à l'import * @var array */ public $galette_fields = [ 'Numéro', 1, 'Nom', 'Prénom', 'Pseudo', 'Société', 2, 'Date de naissance', 3, 'Adresse, ligne 1', 'Adresse, ligne 2', 'Code postal', 'Ville', 'Pays', 'Téléphone fixe', 'Téléphone mobile', 'E-Mail', 'Site web', 'ICQ', 'MSN', 'Jabber', 'Infos (réservé administrateur)', 'Infos (public)', 'Profession', 'Identifiant', 'Mot de passe', 'Date création fiche', 'Date modification fiche', 4, // activite_adh 5, // bool_admin_adh 6, // bool_exempt_adh 7, // bool_display_info 8, // date_echeance 9, // pref_lang 'Lieu de naissance', 10, // GPG id 11 // Fingerprint ]; /** * Importer un CSV de la liste des membres depuis Galette * @param string $path Chemin vers le CSV * @param array $translation_table Tableau indiquant la correspondance à effectuer entre les champs * de Galette et ceux de Garradin. Par exemple : ['Date création fiche' => 'date_inscription'] * @return boolean TRUE en cas de succès */ public function fromGalette($path, $translation_table) { if (!file_exists($path) || !is_readable($path)) { throw new \RuntimeException('Fichier inconnu : '.$path); } $fp = fopen($path, 'r'); if (!$fp) { return false; } $db = DB::getInstance(); $db->exec('BEGIN;'); $membres = new Membres; $columns = array_flip($this->galette_fields); $col = function($column) use (&$row, &$columns) { if (!isset($columns[$column])) return null; if (!isset($row[$columns[$column]])) return null; return $row[$columns[$column]]; }; $line = 0; while (!feof($fp)) { $row = fgetcsv($fp, 4096, ';'); $line++; if (empty($row)) { continue; } if (count($row) != count($columns)) { $db->exec('ROLLBACK;'); throw new UserException('Erreur sur la ligne ' . $line . ' : le nombre de colonnes est incorrect.'); } $data = []; foreach ($translation_table as $galette=>$garradin) { // Champs qu'on ne veut pas importer if (empty($garradin)) continue; // Concaténer plusieurs champs if (isset($data[$garradin])) $data[$garradin] .= "\n" . $col($galette); else $data[$garradin] = $col($galette); } try { $membres->add($data); } catch (UserException $e) { $db->exec('ROLLBACK;'); throw new UserException('Erreur sur la ligne ' . $line . ' : ' . $e->getMessage()); } } $db->exec('END;'); fclose($fp); return true; } public function toCSV() { $db = DB::getInstance(); $res = $db->prepare('SELECT m.id, c.nom AS "categorie", m.* FROM membres AS m LEFT JOIN membres_categories AS c ON m.id_categorie = c.id ORDER BY c.id;')->execute(); $fp = fopen('php://output', 'w'); $header = false; while ($row = $res->fetchArray(SQLITE3_ASSOC)) { unset($row['passe']); if (!$header) { fputcsv($fp, array_keys($row)); $header = true; } fputcsv($fp, $row); } fclose($fp); return true; } } |
Modified src/templates/admin/config/import.tpl from [8a9bbe0a3f] to [e2b6c250be].
1 2 3 4 5 6 7 | {include file="admin/_head.tpl" title="Import & export" current="config"} {include file="admin/config/_menu.tpl" current="import"} <fieldset> <dl> <dt>Membres</dt> | > | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | {include file="admin/_head.tpl" title="Import & export" current="config"} {include file="admin/config/_menu.tpl" current="import"} <fieldset> <dl> <dt>Membres</dt> <dd><a href="{$admin_url}membres/import.php">Import de la liste des membres</a></dd> <dd><a href="{$admin_url}membres/import.php?export">Export de la liste des membres en CSV (pour tableurs)</a></dd> <dt>Comptabilité</dt> <dd><a href="{$admin_url}compta/import.php">Import des données comptables</a></dd> <dd><a href="{$admin_url}compta/import.php?export">Export des données comptables en CSV</a></dd> </dl> </fieldset> {include file="admin/_foot.tpl"} |
Added src/templates/admin/membres/import.tpl version [a7f96e6b34].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | {include file="admin/_head.tpl" title="Import & export des membres" current="membres" js=1} {if $error} <p class="error"> {$error|escape} </p> {elseif $ok} <p class="confirm"> L'import s'est bien déroulé. </p> {/if} <ul class="actions"> <li class="current"><a href="{$www_url}admin/membres/import.php">Importer</a></li> <li><a href="{$www_url}admin/membres/import.php?export">Exporter en CSV</a></li> </ul> <form method="post" action="{$self_url|escape}" enctype="multipart/form-data"> <fieldset> <legend>Importer depuis un fichier</legend> <dl> <dt><label for="f_file">Fichier à importer</label> <b title="(Champ obligatoire)">obligatoire</b></dt> <dd><input type="file" name="upload" id="f_file" /></dd> <dt><label for="f_type">Type de fichier</label> <b title="(Champ obligatoire)">obligatoire</b></dt> <dd> <input type="radio" name="type" id="f_type" value="garradin" {form_field name=type checked="garradin" default="garradin"} /> <label for="f_type">Export CSV de Garradin</label> </dd> <dd class="help"> Export de la liste des membres au format CSV provenant de Garradin. Les lignes comportant un numéro de membre mettront à jour les fiches des membres ayant ce numéro, les lignes sans numéro créeront de nouveaux membres. </dd> <dd> <input type="radio" name="type" id="f_type_galette" value="galette" {form_field name=type checked="galette"} /> <label for="f_type_galette">Export CSV de Galette</label> </dd> <dd class="help"> Export des données au format CSV provenant du logiciel libre <a href="http://galette.eu/">Galette</a>. </dd> <dt class="galette"><label>Correspondance des champs</label></dt> <dd class="help">Indiquer quels champs des fiches membre de Garradin les données de Galette doivent remplir.</dd> <dd class="galette"> <table class="list auto"> <tbody> {foreach from=$galette_champs item="galette"} {if is_int($galette)}{continue}{/if} <tr> <th>{$galette|escape}</th> <td><select name="galette_translate[{$galette|escape}]"> <option value="">-- Ne pas importer ce champ</option> {foreach from=$garradin_champs item="champ" key="name"} {if $champ.type == 'checkbox' || $champ.type == 'multiple'}{continue}{/if} <option value="{$name|escape}" {if (!empty($translate[$galette]) && $translate[$galette] == $name)}selected="selected"{/if}>{$champ.title|escape}</option> {/foreach} </select></td> </tr> {/foreach} </tbody> </table> </dd> </dl> </fieldset> <p class="submit"> {csrf_field key="membres_import"} <input type="submit" name="import" value="Importer →" /> </p> </form> <script type="text/javascript"> {literal} (function () { function toggleGalette() { toggleElementVisibility('.galette', $('#f_type_galette').checked); } $('#f_type').onchange = toggleGalette; $('#f_type_galette').onchange = toggleGalette; toggleGalette(); })(); {/literal} </script> {include file="admin/_foot.tpl"} |
Modified src/templates/admin/membres/index.tpl from [65d4600c03] to [a239eeef83].
1 2 3 4 5 6 7 | {include file="admin/_head.tpl" title="Liste des membres" current="membres"} {if $user.droits.membres >= Garradin\Membres::DROIT_ECRITURE} <ul class="actions"> <li class="current"><a href="{$admin_url}membres/">Liste des membres</a></li> <li><a href="{$admin_url}membres/recherche.php">Recherche avancée</a></li> {if $user.droits.membres >= Garradin\Membres::DROIT_ADMIN} | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | {include file="admin/_head.tpl" title="Liste des membres" current="membres"} {if $user.droits.membres >= Garradin\Membres::DROIT_ECRITURE} <ul class="actions"> <li class="current"><a href="{$admin_url}membres/">Liste des membres</a></li> <li><a href="{$admin_url}membres/recherche.php">Recherche avancée</a></li> {if $user.droits.membres >= Garradin\Membres::DROIT_ADMIN} <li><a href="{$admin_url}membres/import.php">Import & export</a></li> <li><a href="{$admin_url}membres/recherche_sql.php">Recherche par requête SQL</a></li> {/if} </ul> {/if} {if isset($tpl.get.sent)} <p class="confirm">Votre message a été envoyé.</p> |
︙ | ︙ |
Modified src/www/admin/compta/import.php from [32c999b4c9] to [b8811b992b].
︙ | ︙ | |||
19 20 21 22 23 24 25 | exit; } $error = false; if (!empty($_POST['import'])) { | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | exit; } $error = false; if (!empty($_POST['import'])) { if (!utils::CSRF_check('compta_import')) { $error = 'Une erreur est survenue, merci de renvoyer le formulaire.'; } elseif (empty($_FILES['upload']['tmp_name'])) { $error = 'Aucun fichier fourni.'; } |
︙ | ︙ |
Deleted src/www/admin/membres/export.php version [e2a1f35a78].
|
| < < < < < < < < < < < < < < < < |
Added src/www/admin/membres/import.php version [9157bcf691].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | <?php namespace Garradin; require_once __DIR__ . '/../_inc.php'; if ($user['droits']['membres'] < Membres::DROIT_ADMIN) { throw new UserException("Vous n'avez pas le droit d'accéder à cette page."); } $import = new Membres_Import; if (isset($_GET['export'])) { header('Content-type: application/csv'); header('Content-Disposition: attachment; filename="Export membres - ' . $config->get('nom_asso') . ' - ' . date('Y-m-d') . '.csv"'); $import->toCSV(); exit; } $error = false; $champs = $config->get('champs_membres')->getAll(); $champs['date_inscription'] = ['title' => 'Date inscription', 'type' => 'date']; if (utils::post('import')) { if (!utils::CSRF_check('membres_import')) { $error = 'Une erreur est survenue, merci de renvoyer le formulaire.'; } elseif (empty($_FILES['upload']['tmp_name'])) { $error = 'Aucun fichier fourni.'; } else { try { if (utils::post('type') == 'galette') { $import->fromGalette($_FILES['upload']['tmp_name'], utils::post('galette_translate')); } elseif (utils::post('type') == 'garradin') { $import->fromCSV($_FILES['upload']['tmp_name']); } else { throw new UserException('Import inconnu.'); } utils::redirect('/admin/membres/import.php?ok'); } catch (UserException $e) { $error = $e->getMessage(); } } } $tpl->assign('error', $error); $tpl->assign('ok', isset($_GET['ok']) ? true : false); $tpl->assign('garradin_champs', $champs); $tpl->assign('galette_champs', $import->galette_fields); $tpl->assign('translate', utils::post('galette_translate')); $tpl->display('admin/membres/import.tpl'); ?> |
Modified src/www/admin/static/admin.css from [0ae3d4eedb] to [d2031306cc].
︙ | ︙ | |||
320 321 322 323 324 325 326 327 328 329 330 331 332 333 | } table.list { border-collapse: collapse; margin-bottom: 1em; width: 100%; } table.list table { margin: 0; } table.list th { text-align: left; | > > > > | 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | } table.list { border-collapse: collapse; margin-bottom: 1em; width: 100%; } table.list.auto { width: auto; } table.list table { margin: 0; } table.list th { text-align: left; |
︙ | ︙ |