Overview
Comment: | Ajout de membre en utilisant les champs personnalisés |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
3b9b01fecb0bf2473b2adfe34e02e522 |
User & Date: | bohwaz on 2013-01-30 15:19:01 |
Other Links: | manifest | tags |
Context
2013-01-30
| ||
15:34 | Adapter la modif de membre aux champs personnalisés check-in: ef410c3196 user: bohwaz tags: trunk | |
15:19 | Ajout de membre en utilisant les champs personnalisés check-in: 3b9b01fecb user: bohwaz tags: trunk | |
14:53 | Amélioration recherche check-in: e89a17318a user: bohwaz tags: trunk | |
Changes
Modified include/class.champs_membres.php from [85e92511fe] to [ec688c4d23].
︙ | ︙ | |||
8 9 10 11 12 13 14 | protected $types = array( 'email' => 'Adresse E-Mail', 'url' => 'Adresse URL', 'checkbox' => 'Case à cocher', 'date' => 'Date', 'datetime' => 'Date et heure', | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | protected $types = array( 'email' => 'Adresse E-Mail', 'url' => 'Adresse URL', 'checkbox' => 'Case à cocher', 'date' => 'Date', 'datetime' => 'Date et heure', //'file' => 'Fichier', 'password' => 'Mot de passe', 'number' => 'Numéro', 'tel' => 'Numéro de téléphone', 'select' => 'Sélecteur à choix unique', 'multiple' => 'Sélecteur à choix multiple', 'country' => 'Sélecteur de pays', 'text' => 'Texte', |
︙ | ︙ | |||
347 348 349 350 351 352 353 | $config = Config::getInstance(); // Champs à créer $create = array( 'id INTEGER PRIMARY KEY, -- Numéro attribué automatiquement', 'id_categorie INTEGER NOT NULL, -- Numéro de catégorie', 'date_connexion TEXT NULL, -- Date de dernière connexion', | | | 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | $config = Config::getInstance(); // Champs à créer $create = array( 'id INTEGER PRIMARY KEY, -- Numéro attribué automatiquement', 'id_categorie INTEGER NOT NULL, -- Numéro de catégorie', 'date_connexion TEXT NULL, -- Date de dernière connexion', 'date_inscription TEXT NOT NULL DEFAULT CURRENT_DATE, -- Date d\'inscription', 'date_cotisation TEXT NULL, -- Date de cotisation', //'exemption_transaction INTEGER NOT NULL DEFAULT 0, -- Exempté de transaction obligatoire', ); $create_keys = array( 'FOREIGN KEY (id_categorie) REFERENCES membres_categories (id)' ); |
︙ | ︙ |
Modified include/class.membres.php from [04d094b864] to [542975c1d0].
︙ | ︙ | |||
237 238 239 240 241 242 243 | return utils::mail($dest, $sujet, $message, array('From' => $from)); } // Gestion des données /////////////////////////////////////////////////////// public function _checkFields(&$data, $check_mandatory = true) { | > | > > > | | | | < > | < > < > > > | < > | > > > > > > | > | | | > > > > | > < < < < < < < < < < | | 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 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 | return utils::mail($dest, $sujet, $message, array('From' => $from)); } // Gestion des données /////////////////////////////////////////////////////// public function _checkFields(&$data, $check_mandatory = true) { $champs = Config::getInstance()->get('champs_membres'); foreach ($champs->getAll() as $key=>$config) { if (!empty($config['mandatory']) && $check_mandatory && (!isset($data[$key]) || !trim($data[$key]))) { throw new UserException('Le champ "' . $config['title'] . '" doit obligatoirement être renseigné.'); } if ($config['type'] == 'email' && !filter_var($data[$key], FILTER_VALIDATE_EMAIL)) { throw new UserException('Adresse e-mail invalide dans le champ "' . $config['title'] . '".'); } elseif ($config['type'] == 'url' && !filter_var($data[$key], FILTER_VALIDATE_URL)) { throw new UserException('Adresse URL invalide dans le champ "' . $config['title'] . '".'); } elseif ($config['type'] == 'tel') { $data[$key] = preg_replace('![^\d\+]!', '', $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') { if (empty($data[$key])) { $data[$key] = 0; } if (!is_numeric($data[$key])) throw new UserException('Le champ "' . $config['title'] . '" doit contenir un chiffre.'); } } if (!empty($data['code_postal'])) { if (!empty($data['pays']) && $data['pays'] == 'FR' && !preg_match('!^\d{5}$!', $data['code_postal'])) { throw new UserException('Code postal invalide.'); } } if (!empty($data['passe']) && strlen($data['passe']) < 5) { throw new UserException('Le mot de passe doit faire au moins 5 caractères.'); } return true; } public function add($data = array(), $check_mandatory = true) { $this->_checkFields($data); $db = DB::getInstance(); if (!empty($data['email']) && $db->simpleQuerySingle('SELECT 1 FROM membres WHERE email = ? LIMIT 1;', false, $data['email'])) { |
︙ | ︙ | |||
343 344 345 346 347 348 349 | throw new UserException('Ce numéro est déjà attribué à un autre membre.'); } // Si on ne vérifie pas toutes les tables qui sont liées ici à un ID de membre // la requête de modification provoquera une erreur de contrainte de foreign key // ce qui est normal. Donc : il n'est pas possible de changer l'ID d'un membre qui // a participé au wiki, à la compta, etc. | | > | | 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | throw new UserException('Ce numéro est déjà attribué à un autre membre.'); } // Si on ne vérifie pas toutes les tables qui sont liées ici à un ID de membre // la requête de modification provoquera une erreur de contrainte de foreign key // ce qui est normal. Donc : il n'est pas possible de changer l'ID d'un membre qui // a participé au wiki, à la compta, etc. if ($db->simpleQuerySingle('SELECT 1 FROM wiki_revisions WHERE id_auteur = ?;', false, (int)$id) || $db->simpleQuerySingle('SELECT 1 FROM compta_journal WHERE id_auteur = ?;', false, (int)$id)) #|| $db->simpleQuerySingle('SELECT 1 FROM wiki_suivi WHERE id_membre = ?;', false, (int)$id)) { throw new UserException('Le numéro n\'est pas modifiable pour ce membre car des contenus sont liés à ce numéro de membre (wiki, compta, etc.).'); } } if (!empty($data['passe']) && trim($data['passe'])) { $data['passe'] = $this->_hashPassword($data['passe']); } |
︙ | ︙ | |||
370 371 372 373 374 375 376 | $db->simpleUpdate('membres', $data, 'id = '.(int)$id); } public function get($id) { $db = DB::getInstance(); | | > > > | 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | $db->simpleUpdate('membres', $data, 'id = '.(int)$id); } public function get($id) { $db = DB::getInstance(); return $db->simpleQuerySingle('SELECT *, strftime(\'%s\', date_cotisation) AS date_cotisation, strftime(\'%s\', date_inscription) AS date_inscription FROM membres WHERE id = ? LIMIT 1;', true, (int)$id); } public function delete($ids) { if (!is_array($ids)) { $ids = array((int)$ids); |
︙ | ︙ |
Modified www/admin/membres/ajouter.php from [6280225820] to [8f08712aa0].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?php namespace Garradin; require_once __DIR__ . '/../_inc.php'; if ($user['droits']['membres'] < Membres::DROIT_ECRITURE) { throw new UserException("Vous n'avez pas le droit d'accéder à cette page."); } $cats = new Membres_Categories; $error = false; if (!empty($_POST['save'])) { if (!utils::CSRF_check('new_member')) { | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <?php namespace Garradin; require_once __DIR__ . '/../_inc.php'; if ($user['droits']['membres'] < Membres::DROIT_ECRITURE) { throw new UserException("Vous n'avez pas le droit d'accéder à cette page."); } $cats = new Membres_Categories; $champs = $config->get('champs_membres'); $error = false; if (!empty($_POST['save'])) { if (!utils::CSRF_check('new_member')) { |
︙ | ︙ | |||
31 32 33 34 35 36 37 | $id_categorie = utils::post('id_categorie'); } else { $id_categorie = $config->get('categorie_membres'); } | < | | > > | > | < < | < < < < < < | | 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 | $id_categorie = utils::post('id_categorie'); } else { $id_categorie = $config->get('categorie_membres'); } $data = array('id_categorie' => $id_categorie); foreach ($champs->getAll() as $key=>$config) { $data[$key] = utils::post($key); } $id = $membres->add($data); utils::redirect('/admin/membres/fiche.php?id='.(int)$id); } catch (UserException $e) { $error = $e->getMessage(); } } } $tpl->assign('error', $error); $tpl->assign('passphrase', utils::suggestPassword()); $tpl->assign('champs', $champs->getAll()); $tpl->assign('membres_cats', $cats->listSimple()); $tpl->assign('current_cat', utils::post('id_categorie') ?: $config->get('categorie_membres')); $tpl->display('admin/membres/ajouter.tpl'); ?> |