Overview
Comment:Modernisation code catégories
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 2989f0c0e4e8f48bd6f606d20b57a7dffe058f9e
User & Date: bohwaz on 2017-08-03 01:40:49
Other Links: branch diff | manifest | tags
Context
2017-08-03
02:07
Modernisation du code: suppression des _POST et passage au système d'erreurs des formulaires check-in: 143ddfa442 user: bohwaz tags: dev
01:40
Modernisation code catégories check-in: 2989f0c0e4 user: bohwaz tags: dev
01:09
Création de page publique depuis la configuration, pour aider les gens perdus check-in: 676fa5202d user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Membres/Categories.php from [7cda995183] to [af4fccf952].

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

        if (!isset($data['nom']) || !trim($data['nom']))
        {
            throw new UserException('Le nom de catégorie ne peut rester vide.');
        }

        if (!empty($data['id_cotisation_obligatoire']) 
            && !$db->firstColumn('SELECT 1 FROM cotisations WHERE id = ?;', 
                (int)$data['id_cotisation_obligatoire']))
        {
            throw new UserException('Numéro de cotisation inconnu.');
        }

        if (isset($data['id_cotisation_obligatoire']) && empty($data['id_cotisation_obligatoire']))
        {
            $data['id_cotisation_obligatoire'] = null;







<
|







30
31
32
33
34
35
36

37
38
39
40
41
42
43
44

        if (!isset($data['nom']) || !trim($data['nom']))
        {
            throw new UserException('Le nom de catégorie ne peut rester vide.');
        }

        if (!empty($data['id_cotisation_obligatoire']) 

            && !$db->test('cotisations', 'id = ?', (int)$data['id_cotisation_obligatoire']))
        {
            throw new UserException('Numéro de cotisation inconnu.');
        }

        if (isset($data['id_cotisation_obligatoire']) && empty($data['id_cotisation_obligatoire']))
        {
            $data['id_cotisation_obligatoire'] = null;
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
        $config = Config::getInstance();

        if ($id == $config->get('categorie_membres'))
        {
            throw new UserException('Il est interdit de supprimer la catégorie définie par défaut dans la configuration.');
        }

        if ($db->firstColumn('SELECT 1 FROM membres WHERE id_categorie = ?;', (int)$id))
        {
            throw new UserException('La catégorie contient encore des membres, il n\'est pas possible de la supprimer.');
        }

        $db->update(
            'wiki_pages',
            [







|







99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
        $config = Config::getInstance();

        if ($id == $config->get('categorie_membres'))
        {
            throw new UserException('Il est interdit de supprimer la catégorie définie par défaut dans la configuration.');
        }

        if ($db->test('membres', 'id_categorie = ?', (int)$id))
        {
            throw new UserException('La catégorie contient encore des membres, il n\'est pas possible de la supprimer.');
        }

        $db->update(
            'wiki_pages',
            [

Modified src/templates/admin/_head.tpl from [878c526e08] to [5e497dab30].

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
        {if $user.droits.membres >= Garradin\Membres::DROIT_ACCES}
            <li class="member list{if $current == 'membres'} current{/if}"><a href="{$admin_url}membres/"><b class="icn">👪</b> Membres</a>
            {if $user.droits.membres >= Garradin\Membres::DROIT_ECRITURE}
            <ul>
                <li class="member new{if $current == 'membres/ajouter'} current{/if}"><a href="{$admin_url}membres/ajouter.php">Ajouter</a></li>
                <li class="member cotisations{if $current == 'membres/cotisations'} current{/if}"><a href="{$admin_url}membres/cotisations/">Cotisations</a></li>
                {if $user.droits.membres >= Garradin\Membres::DROIT_ADMIN}
                <li class="member admin config{if $current == 'membres/categories'} current{/if}"><a href="{$admin_url}membres/categories.php">Catégories</a></li>
                <li class="members admin mail{if $current == 'membres/message_collectif'} current{/if}"><a href="{$admin_url}membres/message_collectif.php">Message collectif</a></li>
                {/if}
            </ul>
            {/if}
            </li>
        {/if}
        {if $user.droits.compta >= Garradin\Membres::DROIT_ACCES}







|







61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
        {if $user.droits.membres >= Garradin\Membres::DROIT_ACCES}
            <li class="member list{if $current == 'membres'} current{/if}"><a href="{$admin_url}membres/"><b class="icn">👪</b> Membres</a>
            {if $user.droits.membres >= Garradin\Membres::DROIT_ECRITURE}
            <ul>
                <li class="member new{if $current == 'membres/ajouter'} current{/if}"><a href="{$admin_url}membres/ajouter.php">Ajouter</a></li>
                <li class="member cotisations{if $current == 'membres/cotisations'} current{/if}"><a href="{$admin_url}membres/cotisations/">Cotisations</a></li>
                {if $user.droits.membres >= Garradin\Membres::DROIT_ADMIN}
                <li class="member admin config{if $current == 'membres/categories'} current{/if}"><a href="{$admin_url}membres/categories/">Catégories</a></li>
                <li class="members admin mail{if $current == 'membres/message_collectif'} current{/if}"><a href="{$admin_url}membres/message_collectif.php">Message collectif</a></li>
                {/if}
            </ul>
            {/if}
            </li>
        {/if}
        {if $user.droits.compta >= Garradin\Membres::DROIT_ACCES}

Modified src/templates/admin/membres/categories/index.tpl from [f5797e2254] to [9c762d5e02].

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
            <tr>
                <th>{$cat.nom}</th>
                <td class="num">{$cat.nombre}</td>
                <td class="droits">
                    {format_droits droits=$cat}
                </td>
                <td class="actions">
                    <a class="icn" href="cat_modifier.php?id={$cat.id}" title="Modifier">✎</a>
                    {if $cat.id != $user.id_categorie}
                    <a class="icn" href="cat_supprimer.php?id={$cat.id}" title="Supprimer">✘</a>
                    {/if}
                </td>
            </tr>
        {/foreach}
    </tbody>
</table>

{if $error}
    <p class="error">
        {$error}
    </p>
{/if}

<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Ajouter une catégorie</legend>
        <dl>
            <dt><label for="f_nom">Nom</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
            <dd><input type="text" name="nom" id="f_nom" value="{form_field name=nom}" required="required" /></dd>







|

|







<
<
<
<
<
<







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28






29
30
31
32
33
34
35
            <tr>
                <th>{$cat.nom}</th>
                <td class="num">{$cat.nombre}</td>
                <td class="droits">
                    {format_droits droits=$cat}
                </td>
                <td class="actions">
                    <a class="icn" href="{$admin_url}membres/categories/modifier.php?id={$cat.id}" title="Modifier">✎</a>
                    {if $cat.id != $user.id_categorie}
                    <a class="icn" href="{$admin_url}membres/categories/supprimer.php?id={$cat.id}" title="Supprimer">✘</a>
                    {/if}
                </td>
            </tr>
        {/foreach}
    </tbody>
</table>







<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Ajouter une catégorie</legend>
        <dl>
            <dt><label for="f_nom">Nom</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
            <dd><input type="text" name="nom" id="f_nom" value="{form_field name=nom}" required="required" /></dd>

Modified src/templates/admin/membres/categories/modifier.tpl from [178c923010] to [206fa39a37].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{include file="admin/_head.tpl" title="Modifier une catégorie" current="membres/categories"}

{if $error}
    <p class="error">
        {$error}
    </p>
{/if}

<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Informations générales</legend>
        <dl>
            <dt><label for="f_nom">Nom</label> <b title="(Champ obligatoire)">obligatoire</b></dt>


<
<
|
<
<







1
2


3


4
5
6
7
8
9
10
{include file="admin/_head.tpl" title="Modifier une catégorie" current="membres/categories"}



{form_errors}



<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Informations générales</legend>
        <dl>
            <dt><label for="f_nom">Nom</label> <b title="(Champ obligatoire)">obligatoire</b></dt>

Modified src/templates/admin/membres/categories/supprimer.tpl from [99229c44b3] to [145753eeb5].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{include file="admin/_head.tpl" title="Supprimer une catégorie" current="membres/categories"}

{if $error}
    <p class="error">
        {$error}
    </p>
{/if}

<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Supprimer la catégorie de membres ?</legend>
        <h3 class="warning">
            Êtes-vous sûr de vouloir supprimer la catégorie «&nbsp;{$cat.nom}&nbsp;» ?


<
<
|
<
<







1
2


3


4
5
6
7
8
9
10
{include file="admin/_head.tpl" title="Supprimer une catégorie" current="membres/categories"}



{form_errors}



<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Supprimer la catégorie de membres ?</legend>
        <h3 class="warning">
            Êtes-vous sûr de vouloir supprimer la catégorie «&nbsp;{$cat.nom}&nbsp;» ?

Modified src/www/admin/membres/categories/index.php from [40bd489c9b] to [7aa637066f].

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
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

$session->requireAccess('membres', Membres::DROIT_ADMIN);

$cats = new Membres\Categories;

$error = false;

if (!empty($_POST['save']))
{
    if (!Utils::CSRF_check('new_cat'))


    {
        $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
    }
    else
    {
        try {
            $cats->add([
                'nom'           =>  Utils::post('nom'),
            ]);

            Utils::redirect('/admin/membres/categories.php');
        }
        catch (UserException $e)
        {
            $error = $e->getMessage();
        }
    }
}

$tpl->assign('error', $error);

$tpl->assign('liste', $cats->listCompleteWithStats());

$tpl->display('admin/membres/categories.tpl');



|





<
|
<

|
>
>
|
|
<
<

<
|
|
|

|
|
<
<
<
|
|
<
<
<
<


|
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
<?php
namespace Garradin;

require_once __DIR__ . '/../_inc.php';

$session->requireAccess('membres', Membres::DROIT_ADMIN);

$cats = new Membres\Categories;


if (f('save'))

{
    $form->check('new_cat', [
        'nom' => 'required',
    ]);

    if (!$form->hasErrors())


    {

        $cats->add([
            'nom' => f('nom'),
        ]);

        Utils::redirect('/admin/membres/categories/');
    }



}





$tpl->assign('liste', $cats->listCompleteWithStats());

$tpl->display('admin/membres/categories/index.tpl');

Modified src/www/admin/membres/categories/modifier.php from [e550802be2] to [6a0668b24c].

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
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

$session->requireAccess('membres', Membres::DROIT_ADMIN);

$cats = new Membres\Categories;

qv(['id' => 'required|numeric']);

$id = (int) qg('id');

$cat = $cats->get($id);

if (!$cat)
{
    throw new UserException("Cette catégorie n'existe pas.");
}

$error = false;






if (!empty($_POST['save']))
{
    if (!Utils::CSRF_check('edit_cat_'.$id))










    {
        $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
    }
    else

    {
        $data = [
                'nom'           =>  Utils::post('nom'),
                'description'   =>  Utils::post('description'),
                'droit_wiki'    =>  (int) Utils::post('droit_wiki'),
                'droit_compta'  =>  (int) Utils::post('droit_compta'),
                'droit_config'  =>  (int) Utils::post('droit_config'),
                'droit_membres' =>  (int) Utils::post('droit_membres'),
                'droit_connexion' => (int) Utils::post('droit_connexion'),
                'droit_inscription' => (int) Utils::post('droit_inscription'),
                'cacher'        =>  (int) Utils::post('cacher'),
                'id_cotisation_obligatoire' => (int) Utils::post('id_cotisation_obligatoire'),
        ];

        // Ne pas permettre de modifier la connexion, l'accès à la config et à la gestion des membres
        // pour la catégorie du membre qui édite les catégories, sinon il pourrait s'empêcher
        // de se connecter ou n'avoir aucune catégorie avec le droit de modifier les catégories !
        if ($cat->id == $user->id_categorie)
        {
            $data['droit_connexion'] = Membres::DROIT_ACCES;
            $data['droit_config'] = Membres::DROIT_ADMIN;
            $data['droit_membres'] = Membres::DROIT_ADMIN;
        }

        try {
            $cats->edit($id, $data);

            if ($id == $user->id_categorie)
            {

                $membres->updateSessionData();
            }

            Utils::redirect('/admin/membres/categories.php');
        }
        catch (UserException $e)
        {
            $error = $e->getMessage();
        }
    }
}

$tpl->assign('cat', $cat);
$tpl->assign('error', $error);

$tpl->assign('readonly', $cat->id == $user->id_categorie ? 'disabled="disabled"' : '');

$cotisations = new Cotisations;
$tpl->assign('cotisations', $cotisations->listCurrent());

$tpl->assign('membres', $membres);

$tpl->display('admin/membres/cat_modifier.tpl');



|
















|
|
>
>
>
>
>
|
|
|
>
>
>
>
>
>
>
>
>
>
|
<
<
<
>


|
|
|
|
|
|
|
|
|
|

















>
|


|



|





<








|
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
<?php
namespace Garradin;

require_once __DIR__ . '/../_inc.php';

$session->requireAccess('membres', Membres::DROIT_ADMIN);

$cats = new Membres\Categories;

qv(['id' => 'required|numeric']);

$id = (int) qg('id');

$cat = $cats->get($id);

if (!$cat)
{
    throw new UserException("Cette catégorie n'existe pas.");
}

if (f('save'))
{
    $droits = implode(',', [
        Membres::DROIT_AUCUN,
        Membres::DROIT_ACCES,
        Membres::DROIT_ECRITURE,
        Membres::DROIT_ADMIN,
    ]);

    $form->check('edit_cat_' . $id, [
        'nom'                       => 'required',
        'droit_wiki'                => 'in:' . $droits,
        'droit_compta'              => 'in:' . $droits,
        'droit_membres'             => 'in:' . $droits,
        'droit_config'              => sprintf('in:%s,%s', Membres::DROIT_ADMIN, Membres::DROIT_AUCUN),
        'droit_connexion'           => sprintf('in:%s,%s', Membres::DROIT_ACCES, Membres::DROIT_AUCUN),
        'droit_inscription'         => sprintf('in:%s,%s', Membres::DROIT_ACCES, Membres::DROIT_AUCUN),
        'cacher'                    => 'boolean',
        'id_cotisation_obligatoire' => 'numeric',
    ]);




    if (!$form->hasErrors())
    {
        $data = [
            'nom'           =>  f('nom'),
            'description'   =>  f('description'),
            'droit_wiki'    =>  (int) f('droit_wiki'),
            'droit_compta'  =>  (int) f('droit_compta'),
            'droit_config'  =>  (int) f('droit_config'),
            'droit_membres' =>  (int) f('droit_membres'),
            'droit_connexion' => (int) f('droit_connexion'),
            'droit_inscription' => (int) f('droit_inscription'),
            'cacher'        =>  (int) f('cacher'),
            'id_cotisation_obligatoire' => (int) f('id_cotisation_obligatoire'),
        ];

        // Ne pas permettre de modifier la connexion, l'accès à la config et à la gestion des membres
        // pour la catégorie du membre qui édite les catégories, sinon il pourrait s'empêcher
        // de se connecter ou n'avoir aucune catégorie avec le droit de modifier les catégories !
        if ($cat->id == $user->id_categorie)
        {
            $data['droit_connexion'] = Membres::DROIT_ACCES;
            $data['droit_config'] = Membres::DROIT_ADMIN;
            $data['droit_membres'] = Membres::DROIT_ADMIN;
        }

        try {
            $cats->edit($id, $data);

            if ($id == $user->id_categorie)
            {
                // Mise à jour de la session courante
                $session->updateSessionData();
            }

            Utils::redirect('/admin/membres/categories/');
        }
        catch (UserException $e)
        {
            $form->addError($e->getMessage());
        }
    }
}

$tpl->assign('cat', $cat);


$tpl->assign('readonly', $cat->id == $user->id_categorie ? 'disabled="disabled"' : '');

$cotisations = new Cotisations;
$tpl->assign('cotisations', $cotisations->listCurrent());

$tpl->assign('membres', $membres);

$tpl->display('admin/membres/categories/modifier.tpl');

Modified src/www/admin/membres/categories/supprimer.php from [43e89df1f9] to [e114fcd96a].

1
2
3
4
5
6
7
8
9
10
11
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

$session->requireAccess('membres', Membres::DROIT_ADMIN);

$cats = new Membres\Categories;

qv(['id' => 'required|numeric']);




|







1
2
3
4
5
6
7
8
9
10
11
<?php
namespace Garradin;

require_once __DIR__ . '/../_inc.php';

$session->requireAccess('membres', Membres::DROIT_ADMIN);

$cats = new Membres\Categories;

qv(['id' => 'required|numeric']);

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
}

if ($cat->id == $user->id_categorie)
{
    throw new UserException("Vous ne pouvez pas supprimer votre catégorie.");
}

$error = false;

if (!empty($_POST['delete']))
{
    if (!Utils::CSRF_check('delete_cat_'.$id))
    {
        $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
    }
    else

    {
        try {
            $cats->remove($id);
            Utils::redirect('/admin/membres/categories.php');
        }
        catch (UserException $e)
        {
            $error = $e->getMessage();
        }
    }
}

$tpl->assign('cat', $cat);
$tpl->assign('error', $error);

$tpl->display('admin/membres/cat_supprimer.tpl');







<
<
|

|
|
<
<
<
>



|



|





<

|
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
}

if ($cat->id == $user->id_categorie)
{
    throw new UserException("Vous ne pouvez pas supprimer votre catégorie.");
}



if (f('delete'))
{
    $form->check('delete_cat_' . $id);




    if (!$form->hasErrors())
    {
        try {
            $cats->remove($id);
            Utils::redirect('/admin/membres/categories/');
        }
        catch (UserException $e)
        {
            $form->addError($e->getMessage());
        }
    }
}

$tpl->assign('cat', $cat);


$tpl->display('admin/membres/categories/supprimer.tpl');