Overview
SHA1:3ef9a80ec7303cbbb22ea89e4af6dbdf6a553524
Date: 2018-09-04 00:05:28
User: bohwaz
Comment:Recherche avancée fonctionnelle
Timelines: family | ancestors | descendants | both | dev
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2018-09-04
00:25
[4dbda990af] Ajout option de tri et de limite dans la recherche avancée (user: bohwaz, tags: dev)
00:05
[3ef9a80ec7] Recherche avancée fonctionnelle (user: bohwaz, tags: dev)
2018-09-03
19:57
[4404a06eaf] Correction fonctionnement filtre supprimer_skriv (user: bohwaz, tags: dev)
Changes

Modified src/include/data/schema.sql from [6e2d923853] to [efe750515a].

390
391
392
393
394
395
396
397
398
399
400
CREATE TABLE IF NOT EXISTS recherches
-- Recherches enregistrées
(
    id INTEGER NOT NULL PRIMARY KEY,
    id_membre INTEGER NULL REFERENCES membres (id) ON DELETE CASCADE, -- Si non NULL, alors la recherche ne sera visible que par le membre associé
    intitule TEXT NOT NULL,
    creation TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(creation) IS NOT NULL AND datetime(creation) = creation),
    table TEXT NOT NULL, -- "membres" ou "compta_journal"
    type TEXT NOT NULL, -- "json" ou "sql"
    contenu TEXT NOT NULL
);







|



390
391
392
393
394
395
396
397
398
399
400
CREATE TABLE IF NOT EXISTS recherches
-- Recherches enregistrées
(
    id INTEGER NOT NULL PRIMARY KEY,
    id_membre INTEGER NULL REFERENCES membres (id) ON DELETE CASCADE, -- Si non NULL, alors la recherche ne sera visible que par le membre associé
    intitule TEXT NOT NULL,
    creation TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(creation) IS NOT NULL AND datetime(creation) = creation),
    cible TEXT NOT NULL, -- "membres" ou "compta_journal"
    type TEXT NOT NULL, -- "json" ou "sql"
    contenu TEXT NOT NULL
);

Modified src/include/lib/Garradin/Membres.php from [369800e998] to [d83688a88c].

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
326

327
328
329

330
331






332
333
334
335
336
337
338

339
340

341

342
343
344


345
346
347

348
349


350
351

352

353
354


355
356


357

358
359
360
361
362
363
364
365
366

367






368
369
370











371
372
373
374
375
376
377
...
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
    }

    public function getIDWithNumero($numero)
    {
        return DB::getInstance()->firstColumn('SELECT id FROM membres WHERE numero = ?;', (int) $numero);
    }

    public function search($field, $query)
    {
        $db = DB::getInstance();
        $config = Config::getInstance();

        $champs = $config->get('champs_membres');

























        if (!$champs->get($field))
        {
            throw new \UnexpectedValueException($field . ' is not a valid field');




        }


        $champ = $champs->get($field);

        if ($champ->type == 'multiple')

        {
            $where = 'WHERE '.$field.' & (1 << '.(int)$query.')';
            $order = false;

        }









        elseif ($champ->type == 'tel')
        {
            $query = Utils::normalizePhoneNumber($query);
            $query = preg_replace('!^0+!', '', $query);






            if ($query == '')
            {


























































                return false;
            }

            $where = sprintf('WHERE %s LIKE %s', $field, $db->quote('%' . $query . '%'));

            $order = $field;
        }
        elseif (!$champs->isText($field))

        {
            $where = sprintf('WHERE %s = %s', $field, $db->quote($query));






            $order = $field;
        }
        else
        {
            // Si le champ est de type 'select' (sélecteur à choix unique), ne pas utiliser de LIKE mais valeur exacte
            // @link https://fossil.kd2.org/garradin/info/587f730b661a7ce16bad215d4bd02195e754ec57
            if ($champ->type != 'select')

            {
                $query = '%' . $query . '%';

            }


            $where = sprintf('WHERE transliterate_to_ascii(%s) LIKE %s', $field, $db->quote(Utils::transliterateToAscii($query)));
            $order = sprintf('transliterate_to_ascii(%s) COLLATE NOCASE', $field);


        }

        $fields = array_keys((array)$champs->getListedFields());


        if (!in_array($field, $fields))


        {
            $fields[] = $field;

        }


        if (!in_array('email', $fields))


        {
            $fields[] = 'email';


        }


        $query = sprintf('SELECT id, id_categorie, %s, %s AS identite,
            strftime(\'%%s\', date_inscription) AS date_inscription
            FROM membres %s %s LIMIT 1000;',
            implode(', ', $fields),
            $config->get('champ_identite'),
            $where,
            $order ? 'ORDER BY ' . $order : ''
        );








        return $db->get($query);
    }












    public function listByCategory($cat, $fields, $page = 1, $order = null, $desc = false)
    {
        $begin = ($page - 1) * self::ITEMS_PER_PAGE;

        $db = DB::getInstance();
        $config = Config::getInstance();

................................................................................
        Plugin::fireSignal('membre.suppression', $membres);

        $db = DB::getInstance();

        // Suppression du membre
        return $db->delete('membres', $db->where('id', $membres));
    }

    public function searchSQL($query)
    {
        $db = DB::getInstance();

        if (!preg_match('/LIMIT\s+/i', $query))
        {
            $query = preg_replace('/;?\s*$/', '', $query);
            $query .= ' LIMIT 100';
        }

        if (preg_match('/;\s*(.+?)$/', $query))
        {
            throw new UserException('Une seule requête peut être envoyée en même temps.');
        }

        $st = $db->prepare($query);

        if (!$st->readOnly())
        {
            throw new UserException('Seules les requêtes en lecture sont autorisées.');
        }

        $res = $st->execute();
        $out = [];

        while ($row = $res->fetchArray(SQLITE3_ASSOC))
        {
            if (array_key_exists('passe', $row))
            {
                unset($row['passe']);
            }
            
            $out[] = $row;
        }

        return $out;
    }

    public function schemaSQL()
    {
        $db = DB::getInstance();

        $tables = [
            'membres'   =>  $db->firstColumn('SELECT sql FROM sqlite_master WHERE type = \'table\' AND name = \'membres\';'),
            'categories'=>  $db->firstColumn('SELECT sql FROM sqlite_master WHERE type = \'table\' AND name = \'membres_categories\';'),
        ];

        return $tables;
    }
}







|





>

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

>
|

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

<
>
|
|
<
>

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


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


>
>
>
>
>
>
>
>
>
>
>







 







|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
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
326
327
328
329

330
331
332
333
334
335
336
337
338

339
340


341
342
343
344
345
346
347
348
349
350
351
352
353


354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
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
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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
...
587
588
589
590
591
592
593
594


















































    }

    public function getIDWithNumero($numero)
    {
        return DB::getInstance()->firstColumn('SELECT id FROM membres WHERE numero = ?;', (int) $numero);
    }

    public function buildSQLSearchQuery(array $groups, $order, $desc = false, $limit = 100)
    {
        $db = DB::getInstance();
        $config = Config::getInstance();

        $champs = $config->get('champs_membres');
        $colonnes = [];

        $query_groups = [];

        foreach ($groups as $group)
        {
            if (!isset($group['conditions'], $group['operator'])
                || !is_array($group['conditions'])
                || ($group['operator'] != 'AND' && $group['operator'] != 'OR'))
            {
                // Ignorer les groupes de conditions invalides
                continue;
            }

            $query_group_conditions = [];

            foreach ($group['conditions'] as $condition)
            {
                if (!isset($condition['column'], $condition['operator'])
                    || (isset($condition['values']) && !is_array($condition['values'])))
                {
                    // Ignorer les conditions invalides
                    continue;
                }

                if (!$champs->get($condition['column']))
                {

                    // Ignorer une condition qui se rapporte à une colonne
                    // qui n'existe pas, cas possible si on reprend une recherche
                    // après avoir modifié les fiches de membres
                    continue;
                }

                $colonnes[] = $condition['column'];
                $champ = $champs->get($condition['column']);


                if ($champs->isText($condition['column']))
                {


                    $query = sprintf('transliterate_to_ascii(%s) %s', $db->quoteIdentifier($condition['column']), $condition['operator']);
                }
                else
                {
                    $query = sprintf('%s %s', $db->quoteIdentifier($condition['column']), $condition['operator']);
                }

                $values = isset($condition['values']) ? $condition['values'] : [];

                array_walk($values, ['Garradin\Utils', 'transliterateToAscii']);
                
                if ($champ->type == 'tel')
                {


                    // Normaliser le numéro de téléphone
                    array_walk($values, ['Garradin\Utils', 'normalizePhoneNumber']);
                }

                if ($condition['operator'] == '&')
                {
                    $new_query = [];

                    foreach ($values as $value)
                    {
                        $new_query[] = sprintf('%s (1 << %d)', $query, (int) $value);
                    }

                    $query = '(' . implode(' AND ', $new_query) . ')';
                }
                elseif (strpos($query, '??') !== false)
                {
                    $values = array_map([$db, 'quote'], $values);
                    $query = str_replace('??', implode(', ', $values), $query);
                }
                elseif (preg_match('/%\?%|%\?|\?%/', $query, $match))
                {
                    $value = str_replace(['%_'], ['\\%', '\\_'], reset($values));
                    $value = str_replace('?', $value, $match[0]);
                    $query = str_replace($match[0], sprintf('%s ESCAPE \'\\\'', $db->quote($value)), $query);
                }
                elseif (strpos($query, '?') !== false)
                {
                    $expected = substr_count($query, '?');
                    $found = count($values);

                    if ($expected != $found)
                    {
                        throw new \RuntimeException(sprintf('Operator %s expects at least %d parameters, only %d supplied', $condition['operator'], $expected, $found));
                    }

                    for ($i = 0; $i < $expected; $i++)
                    {
                        $pos = strpos($query, '?');
                        $query = substr_replace($query, $db->quote(array_shift($values)), $pos, 1);
                    }
                }

                $query_group_conditions[] = $query;
            }

            $query_groups[] = implode(' ' . $group['operator'] . ' ', $query_group_conditions);
        }

        $colonnes = array_unique($colonnes);
        array_walk($colonnes, [$db, 'quoteIdentifier']);

        $sql_query = sprintf('SELECT id, %s FROM membres WHERE %s ORDER BY %s %s LIMIT 0,%d;',
            implode(', ', $colonnes),
            '(' . implode(') AND (', $query_groups) . ')',
            $db->quoteIdentifier($order),
            $desc ? 'DESC' : 'ASC',
            (int) $limit);

        return $sql_query;
    }

    public function getSearchHeaderFields(array $result)
    {
        if (!count($result))
        {
            return false;
        }


        $champs = Config::getInstance()->get('champs_membres');
        $fields = [];


        foreach (reset($result) as $field=>$value)
        {

            if ($config = $champs->get($field))
            {
                $fields[$field] = $config;
            }
        }

        return $fields;
    }





    public function searchSQL($query)
    {

        $db = DB::getInstance();

        if (!preg_match('/LIMIT\s+/i', $query))
        {


            $query = preg_replace('/;?\s*$/', '', $query);
            $query .= ' LIMIT 100';
        }


        if (preg_match('/;\s*(.+?)$/', $query))
        {

            throw new UserException('Une seule requête peut être envoyée en même temps.');
        }


        $st = $db->prepare($query);

        if (!$st->readOnly())
        {

            throw new UserException('Seules les requêtes en lecture sont autorisées.');
        }


        $res = $st->execute();
        $out = [];

        while ($row = $res->fetchArray(SQLITE3_ASSOC))
        {








            if (array_key_exists('passe', $row))
            {
                unset($row['passe']);
            }
            
            $out[] = (object) $row;
        }

        return $out;
    }

    public function schemaSQL()
    {
        $db = DB::getInstance();

        $tables = [
            'membres'   =>  $db->firstColumn('SELECT sql FROM sqlite_master WHERE type = \'table\' AND name = \'membres\';'),
            'categories'=>  $db->firstColumn('SELECT sql FROM sqlite_master WHERE type = \'table\' AND name = \'membres_categories\';'),
        ];

        return $tables;
    }
    public function listByCategory($cat, $fields, $page = 1, $order = null, $desc = false)
    {
        $begin = ($page - 1) * self::ITEMS_PER_PAGE;

        $db = DB::getInstance();
        $config = Config::getInstance();

................................................................................
        Plugin::fireSignal('membre.suppression', $membres);

        $db = DB::getInstance();

        // Suppression du membre
        return $db->delete('membres', $db->where('id', $membres));
    }
}


















































Modified src/templates/admin/membres/index.tpl from [12e18bee98] to [bdf20a85ce].

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
    </fieldset>
</form>
{/if}

<form method="get" action="{$admin_url}membres/recherche.php" class="shortFormLeft">
    <fieldset>
        <legend>Rechercher un membre</legend>
        <input type="text" name="r" value="" />
        <input type="submit" value="Chercher &rarr;" />
    </fieldset>
</form>

<form method="post" action="action.php" class="memberList">

{if !empty($liste)}







|







30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
    </fieldset>
</form>
{/if}

<form method="get" action="{$admin_url}membres/recherche.php" class="shortFormLeft">
    <fieldset>
        <legend>Rechercher un membre</legend>
        <input type="text" name="qt" value="" />
        <input type="submit" value="Chercher &rarr;" />
    </fieldset>
</form>

<form method="post" action="action.php" class="memberList">

{if !empty($liste)}

Modified src/templates/admin/membres/recherche.tpl from [8cd775429b] to [df74ceb0fe].

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
{include file="admin/_head.tpl" title="Recherche de membre" current="membres" js=1}

{if $session->canAccess('membres', Garradin\Membres::DROIT_ADMIN)}
<ul class="actions">
    <li><a href="{$admin_url}membres/">Liste des membres</a></li>
    <li class="current"><a href="{$admin_url}membres/recherche.php">Recherche avancée</a></li>
    <li><a href="{$admin_url}membres/recherche_sql.php">Recherche par requête SQL</a></li>
</ul>
{/if}

<form method="get" action="{$admin_url}membres/recherche.php" class="shortFormLeft">
    <fieldset>
        <legend>Rechercher un membre</legend>
        <dl>
            <dt><label for="f_champ">Champ</label></dt>
            <dd>
                <select name="c" id="f_champ">
                    {foreach from=$champs_liste key="k" item="v"}
                    <option value="{$k}"{form_field name="c" default=$champ selected=$k}>{$v.title}</option>
                    {/foreach}
                </select>
            </dd>
            <dt><label for="f_texte">Recherche</label></dt>
            <dd id="f_free"><input id="f_texte" type="text" name="r" value="{$recherche}" required="required" /></dd>
            {foreach from=$champs_liste key="k" item="v"}
                {if $v.type == 'select'}
                    <dd class="special" id="f_{$k}">
                        <select name="r" disabled="disabled">
                            {foreach from=$v.options item="opt"}
                            <option value="{$opt}"{form_field name="r" default=$recherche selected=$opt}>{$opt}</option>
                            {/foreach}
                        </select>
                    </dd>
                {elseif $v.type == 'multiple'}
                    <dd class="special" id="f_{$k}">
                        <select name="r" disabled="disabled">
                            {foreach from=$v.options key="opt_k" item="opt"}
                            <option value="{$opt_k}"{form_field name="r" default=$recherche selected=$opt_k}>{$opt}</option>
                            {/foreach}
                        </select>
                    </dd>
                {elseif $v.type == 'checkbox'}
                    <dd class="special" id="f_{$k}">
                        <select name="r" disabled="disabled">
                            <option value="1"{form_field name="r" default=$recherche selected=1}>Oui</option>
                            <option value="0"{form_field name="r" default=$recherche selected=0}>Non</option>
                        </select>
                    </dd>
                {/if}
            {/foreach}
        </dl>
        <p class="submit">
            <input type="submit" value="Chercher &rarr;" />

        </p>
    </fieldset>
</form>








































































{if $session->canAccess('membres', Garradin\Membres::DROIT_ECRITURE)}
    <form method="post" action="{$admin_url}membres/action.php" class="memberList">
{/if}

{if !empty($liste)}
    <table class="list search">
        <thead>

            {if $session->canAccess('membres', Garradin\Membres::DROIT_ADMIN)}<td class="check"><input type="checkbox" value="Tout cocher / décocher" onclick="g.checkUncheck();" /></td>{/if}
            {foreach from=$champs_entete key="c" item="cfg"}
                {if $champ == $c}
                    <th><strong>{$cfg.title}</strong></th>
                {else}
                    <td>{$cfg.title}</td>
                {/if}
            {/foreach}
            <td></td>

        </thead>
        <tbody>
            {foreach from=$liste item="membre"}
                <tr>
                    {if $session->canAccess('membres', Garradin\Membres::DROIT_ADMIN)}<td class="check"><input type="checkbox" name="selected[]" value="{$membre.id}" /></td>{/if}
                    {foreach from=$champs_entete key="c" item="cfg"}
                        {if $champ == $c}
                            <th><strong>{$membre->$c|raw|display_champ_membre:$cfg}</strong></th>
                        {else}


                            <td>{$membre->$c|raw|display_champ_membre:$cfg}</td>
                        {/if}
                    {/foreach}
                    <td class="actions">
                    	<a class="icn" href="{$admin_url}membres/fiche.php?id={$membre.id}" title="Fiche membre">👤</a>
                    	{if $session->canAccess('membres', Garradin\Membres::DROIT_ECRITURE)}
                        <a class="icn" href="{$admin_url}membres/modifier.php?id={$membre.id}" title="Modifier la fiche membre">✎</a>
                        {/if}
                    </td>
                </tr>
            {/foreach}
        </tbody>
    </table>

    {if $session->canAccess('membres', Garradin\Membres::DROIT_ADMIN)}
    <p class="checkUncheck">
        <input type="button" value="Tout cocher / décocher" onclick="g.checkUncheck();" />
    </p>
    <p class="actions">
        <em>Pour les membres cochés :</em>
        <input type="submit" name="move" value="Changer de catégorie" />
        <input type="submit" name="delete" value="Supprimer" />
        {csrf_field key="membres_action"}
    </p>
    {/if}

{elseif $recherche != ''}

    <p class="alert">
        Aucun membre trouvé.
    </p>


{/if}

{if $session->canAccess('membres', Garradin\Membres::DROIT_ECRITURE)}
    </form>
{/if}

<script type="text/javascript">
{literal}
(function() {
    var current = false;

    var selectField = function(elm)
    {
        if (current)
        {
            document.getElementById('f_' + current).style.display = 'none';
            document.getElementById('f_' + current).querySelector('select').disabled = true;
            current = false;
        }
        
        if (document.getElementById('f_' + elm.value))
        {
            document.getElementById('f_' + elm.value).style.display = 'block';
            document.getElementById('f_' + elm.value).querySelector('select').disabled = false;
            document.getElementById('f_free').style.display = 'none';
            document.getElementById('f_texte').disabled = true;
            current = elm.value;
        }
        else
        {
            document.getElementById('f_texte').disabled = false;
            document.getElementById('f_free').style.display = 'block';
        }

        return true;
    }

    document.getElementById('f_champ').onchange = function() { selectField(this); };
    window.onload = selectField(document.getElementById('f_champ'));
}())
{/literal}
</script>

{include file="admin/_foot.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
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
{include file="admin/_head.tpl" title="Recherche de membre" current="membres" js=1 custom_js=['sql_query_builder.js']}

{if $session->canAccess('membres', Garradin\Membres::DROIT_ADMIN)}
<ul class="actions">
	<li><a href="{$admin_url}membres/">Liste des membres</a></li>
	<li class="current"><a href="{$admin_url}membres/recherche.php">Recherche avancée</a></li>
	<li><a href="{$admin_url}membres/recherche_sql.php">Recherche par requête SQL</a></li>
</ul>
{/if}

<form method="post" action="{$admin_url}membres/recherche.php" id="queryBuilderForm">
	<fieldset>
		<legend>Rechercher un membre</legend>
		<div class="queryBuilder" id="queryBuilder"></div>





































		<p class="submit">
			<input type="submit" value="Chercher &rarr;" id="send" />
			<input type="hidden" name="q" id="jsonQuery" />
		</p>
	</fieldset>
</form>

<script type="text/javascript">
var colonnes = {$colonnes|escape:'json'};

{literal}
var traductions = {
	"after": "après",
	"before": "avant",
	"is equal to": "est égal à",
	"is equal to one of": "est égal à une des ces options",
	"is not equal to one of": "n'est pas égal à une des ces options",
	"is not equal to": "n'est pas égal à",
	"is greater than": "est supérieur à",
	"is greater than or equal to": "est supérieur ou égal à",
	"is less than": "est inférieur à",
	"is less than or equal to": "est inférieur ou égal à",
	"is between": "est situé entre",
	"is not between": "n'est pas situé entre",
	"is null": "est nul",
	"is not null": "n'est pas nul",
	"begins with": "commence par",
	"doesn't begin with": "ne commence pas par",
	"ends with": "se termine par",
	"doesn't end with": "ne se termine pas par",
	"contains": "contient",
	"doesn't contain": "ne contient pas",
	"matches one of": "correspond à",
	"is true": "oui",
	"is false": "non",
	"Matches ALL of the following conditions:": "Correspond à TOUS les critères suivants :",
	"Matches ANY of the following conditions:": "Correspond à UN SEUL des critères suivants :",
	"Add a new set of conditions below this one": "-- Ajouter un groupe de critères",
	"Remove this set of conditions": "-- Supprimer ce groupe de critères"
};

var q = new SQLQueryBuilder(colonnes);
q.__ = function (str) {
	return traductions[str];
};
q.loadDefaultOperators();
q.buildInput = function (type, label, column) {
	if (label == '+')
	{
		label = '➕';
	}
	else if (label == '-')
	{
		label = '➖';
	}

	var i = document.createElement('input');
	console.log(type);
	i.type = type == 'integer' ? 'number' : type;
	i.value = label;

	if (type == 'button')
	{
		i.className = 'icn action';
	}

	return i;
};
q.init(document.getElementById('queryBuilder'));

$('#queryBuilderForm').onsubmit = function () {
	$('#jsonQuery').value = JSON.stringify(q.export());
};
{/literal}
q.import({$query|escape:'json'});
</script>


{if $session->canAccess('membres', Garradin\Membres::DROIT_ECRITURE)}
	<form method="post" action="{$admin_url}membres/action.php" class="memberList">
{/if}

{if !empty($result)}
	<table class="list search">
		<thead>
			<tr>
				{if $session->canAccess('membres', Garradin\Membres::DROIT_ADMIN)}<td class="check"><input type="checkbox" value="Tout cocher / décocher" onclick="g.checkUncheck();" /></td>{/if}
				{foreach from=$result_header key="c" item="cfg"}



					<td>{$cfg.title}</td>

				{/foreach}
				<td></td>
			</tr>
		</thead>
		<tbody>
			{foreach from=$result item="row"}
				<tr>
					{if $session->canAccess('membres', Garradin\Membres::DROIT_ADMIN)}<td class="check"><input type="checkbox" name="selected[]" value="{$row.id}" /></td>{/if}




					{foreach from=$row key="key" item="value"}
						{if isset($result_header[$key])}
							<td>{$value|raw|display_champ_membre:$result_header[$key]}</td>
						{/if}
					{/foreach}
					<td class="actions">
						<a class="icn" href="{$admin_url}membres/fiche.php?id={$row.id}" title="Fiche membre">👤</a>
						{if $session->canAccess('membres', Garradin\Membres::DROIT_ECRITURE)}
						<a class="icn" href="{$admin_url}membres/modifier.php?id={$row.id}" title="Modifier la fiche membre">✎</a>
						{/if}
					</td>
				</tr>
			{/foreach}
		</tbody>
	</table>

	{if $session->canAccess('membres', Garradin\Membres::DROIT_ADMIN)}
	<p class="checkUncheck">
		<input type="button" value="Tout cocher / décocher" onclick="g.checkUncheck();" />
	</p>
	<p class="actions">
		<em>Pour les membres cochés :</em>
		<input type="submit" name="move" value="Changer de catégorie" />
		<input type="submit" name="delete" value="Supprimer" />
		{csrf_field key="membres_action"}
	</p>
	{/if}

{elseif $result !== null}

	<p class="alert">
		Aucun membre trouvé.
	</p>

	</form>
{/if}

{if $session->canAccess('membres', Garradin\Membres::DROIT_ECRITURE)}
	</form>
{/if}






































{include file="admin/_foot.tpl"}

Modified src/www/admin/membres/recherche.php from [53c0358ecc] to [6952bd8048].

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

require_once __DIR__ . '/_inc.php';

$recherche = trim(qg('r'));
$champ = trim(qg('c'));

$champs = $config->get('champs_membres');




$auto = false;

// On détermine magiquement quel champ on recherche
if (!$champ)
{
    $auto = true;


    if (is_numeric(trim($recherche))) {
        $champ = 'numero';

    }
    elseif (strpos($recherche, '@') !== false) {

        $champ = 'email';
    }
    else {

        $champ = $config->get('champ_identite');
    }
}
else
{

    if ($champ != 'numero' && !$champs->get($champ))










    {
        throw new UserException('Le champ demandé n\'existe pas.');

    }
}


if ($recherche != '')
{

    $result = $membres->search($champ, $recherche);

    if (count($result) == 1 && $auto)
    {
        Utils::redirect(ADMIN_URL . 'membres/fiche.php?id=' . (int)$result[0]->id);
    }
}






















$champs_liste = $champs->getList();
$champs_entete = $champs->getListedFields();

if (!isset($champs_entete->$champ))





{
    $champs_entete = array_merge(
        [$champ => $champs_liste->$champ],
        (array)$champs_entete
    );



}


$tpl->assign('champs_entete', $champs_entete);
$tpl->assign('champs_liste', $champs_liste);
$tpl->assign('champ', $champ);



if ($recherche != '')

{
    $tpl->assign('liste', $result);


}












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

$tpl->display('admin/membres/recherche.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
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';




$champs = $config->get('champs_membres');
$text_query = trim(qg('qt'));
$query = null;

// Recherche simple
if ($text_query !== '')
{
    $operator = 'LIKE %?%';



    if (is_numeric(trim($text_query)))
    {

        $column = 'numero';
        $operator = '= ?';
    }
    elseif (strpos($text_query, '@') !== false)
    {
        $column = 'email';
    }
    else
    {
        $column = $config->get('champ_identite');
    }



    $query = [[
        'operator' => 'AND',
        'conditions' => [
            [
                'column'   => $column,
                'operator' => $operator,
                'values'   => [$text_query],
            ],
        ],
    ]];
}
elseif (f('q') !== null)
{

    $query = json_decode(f('q'), true);
}

if ($query)
{


    $sql_query = $membres->buildSQLSearchQuery($query, 'id', false, 100);
    $result = $membres->searchSQL($sql_query);

    if (count($result) == 1 && $text_query !== '')
    {
        Utils::redirect(ADMIN_URL . 'membres/fiche.php?id=' . (int)$result[0]->id);
    }

    $tpl->assign('result_header', $membres->getSearchHeaderFields($result));
}
else
{
    $query = [[
        'operator' => 'AND',
        'conditions' => [
            [
                'column'   => $config->get('champ_identite'),
                'operator' => '= ?',
                'values'   => ['Souad Massi'],
            ],
        ],
    ]];
    $result = null;
}

$tpl->assign('query', $query);
$tpl->assign('result', $result);

$colonnes = [];

foreach ($champs->getList() as $champ => $config)

{

    $colonne = [
        'label' => $config->title,
        'type'  => 'text',
        'null'  => true,
    ];





    if ($config->type == 'checkbox')
    {
        $colonne['type'] = 'boolean';
    }
    elseif ($config->type == 'select')
    {



        $colonne['type'] = 'enum';
        $colonne['values'] = $config->options;
    }

    elseif ($config->type == 'multiple')
    {

        $colonne['type'] = 'bitwise';
        $colonne['values'] = $config->options;
    }
    elseif ($config->type == 'date' || $config->type == 'datetime')
    {
        $colonne['type'] = $config->type;
    }
    elseif ($config->type == 'number' || $champ == 'numero')
    {
        $colonne['type'] = 'integer';
    }

    $colonnes[$champ] = $colonne;
}

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

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

Modified src/www/admin/static/admin.css from [a5c6973ae1] to [052cd9f4f6].

613
614
615
616
617
618
619




620
621
622
623
624
625
626
}

table.search th {
    background: rgb(217, 134, 40);
    background: rgba(217, 134, 40, 0.5);
    background: rgba(var(--gSecondColor), 0.5);
}





.userOrder .cur {
    background: rgb(217, 134, 40);
    background: rgba(var(--gSecondColor), 1.0);
    color: #fff;
    color: rgb(var(--gBgColor));
}







>
>
>
>







613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
}

table.search th {
    background: rgb(217, 134, 40);
    background: rgba(217, 134, 40, 0.5);
    background: rgba(var(--gSecondColor), 0.5);
}

#queryBuilder p select {
    max-width: 15em;
}

.userOrder .cur {
    background: rgb(217, 134, 40);
    background: rgba(var(--gSecondColor), 1.0);
    color: #fff;
    color: rgb(var(--gBgColor));
}