Overview
Comment:Ne pas permettre d'ajouter des champs ayant un nom système
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable
Files: files | file ages | folders
SHA1: 1f26ad54dd15a5dd45b70cd0f91f12d3947afe86
User & Date: bohwaz on 2018-06-20 21:10:56
Other Links: manifest | tags
Context
2018-06-20
21:18
Corrige champ passe qui ne devrait pas être système + possibilité d'ajouter plusieurs champs perso de suite check-in: ba2128803f user: bohwaz tags: trunk, stable
21:10
Ne pas permettre d'ajouter des champs ayant un nom système check-in: 1f26ad54dd user: bohwaz tags: trunk, stable
2018-06-11
14:27
Plugins: Ne pas lister les répertoires qui ne sont pas des plugins ou qui n'ont pas un nom valide check-in: 9e063787cb user: bohwaz tags: trunk, stable
Changes

Modified src/include/lib/Garradin/Membres/Champs.php from [2b5c5300ef] to [611652ad59].

1
2
3
4
5
6
7
8
9
10
11
12










13
14
15
16
17
18
19
<?php

namespace Garradin\Membres;

use Garradin\Config;
use Garradin\DB;
use Garradin\Utils;
use Garradin\UserException;

class Champs
{
	protected $champs = null;











	protected $types = [
		'email'		=>	'Adresse E-Mail',
		'url'		=>	'Adresse URL',
		'checkbox'	=>	'Case à cocher',
		'date'		=>	'Date',
		'datetime'	=>	'Date et heure',












>
>
>
>
>
>
>
>
>
>







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
<?php

namespace Garradin\Membres;

use Garradin\Config;
use Garradin\DB;
use Garradin\Utils;
use Garradin\UserException;

class Champs
{
	protected $champs = null;

    protected $system_fields = [
        'passe',
        'date_connexion',
        'date_inscription',
        'clef_pgp',
        'secret_otp',
        'id',
        'id_categorie',
    ];

	protected $types = [
		'email'		=>	'Adresse E-Mail',
		'url'		=>	'Adresse URL',
		'checkbox'	=>	'Case à cocher',
		'date'		=>	'Date',
		'datetime'	=>	'Date et heure',
410
411
412
413
414
415
416




















417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434





435
436
437
438
439
440
441
        $config = clone $this->champs->$champ;
        $config->$key = $value;
        $this->_checkField($champ, $config);

		$this->champs->$champ = $config;
		return true;
	}





















    /**
     * Modifie les champs en interne en vérifiant que tout va bien
     * @param array $champs Liste des champs
     * @return boolean true
     */
    public function setAll($champs, $initial_setup = false)
    {
        $presets = self::importPresets();
        $champs = (object) $champs;

        if (!isset($champs->passe))
        {
            $champs->passe = (object) ['type' => 'password'];
        }

        foreach ($champs as $key=>&$config)
        {





            if (is_array($config))
            {
                $config = (object) $config;
            }

            if (isset($presets[$key]))
            {







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


















>
>
>
>
>







420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
        $config = clone $this->champs->$champ;
        $config->$key = $value;
        $this->_checkField($champ, $config);

		$this->champs->$champ = $config;
		return true;
	}

    public function checkCustomFieldName($name)
    {
        if (in_array($name, $this->system_fields))
        {
            throw new UserException('Ce nom unique de champ existe déjà dans les champs systèmes utilisés par Garradin.');
        }

        $presets = self::importPresets();

        if (array_key_exists($name, $presets))
        {
            throw new UserException('Le champ personnalisé ne peut avoir le même nom qu\'un champ pré-défini.');
        }

        if (isset($this->champs->$name))
        {
            throw new UserException('Ce nom est déjà utilisé par un autre champ.');
        }
    }

    /**
     * Modifie les champs en interne en vérifiant que tout va bien
     * @param array $champs Liste des champs
     * @return boolean true
     */
    public function setAll($champs, $initial_setup = false)
    {
        $presets = self::importPresets();
        $champs = (object) $champs;

        if (!isset($champs->passe))
        {
            $champs->passe = (object) ['type' => 'password'];
        }

        foreach ($champs as $key=>&$config)
        {
            if (in_array($key, $this->system_fields))
            {
                throw new UserException('Ce nom unique de champ existe déjà dans les champs systèmes utilisés par Garradin.');
            }

            if (is_array($config))
            {
                $config = (object) $config;
            }

            if (isset($presets[$key]))
            {

Modified src/www/admin/config/membres.php from [7610ec7561] to [0aca5c7236].

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
                        throw new UserException('Le champ pré-défini demandé ne fait pas partie des champs disponibles.');
                    }

                    $champs->add(f('preset'), $presets[f('preset')]);
                }
                elseif (f('new'))
                {
                    $presets = Membres\Champs::importPresets();
                    $new = f('new');

                    if (array_key_exists($new, $presets))
                    {
                        throw new UserException('Le champ personnalisé ne peut avoir le même nom qu\'un champ pré-défini.');
                    }

                    $config = [
                        'type'  =>  f('new_type'),
                        'title' =>  f('new_title'),
                        'editable'  =>  true,
                        'mandatory' =>  false,
                    ];







<


|
<
<
<







54
55
56
57
58
59
60

61
62
63



64
65
66
67
68
69
70
                        throw new UserException('Le champ pré-défini demandé ne fait pas partie des champs disponibles.');
                    }

                    $champs->add(f('preset'), $presets[f('preset')]);
                }
                elseif (f('new'))
                {

                    $new = f('new');

                    $champs->checkCustomFieldName($new);




                    $config = [
                        'type'  =>  f('new_type'),
                        'title' =>  f('new_title'),
                        'editable'  =>  true,
                        'mandatory' =>  false,
                    ];