Overview
Comment:Restreindre les dates acceptées dans les champs persos
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0c2ea2638ca16e477ea5f26e07fd2b5de0eadfa2
User & Date: bohwaz on 2014-04-12 00:41:30
Other Links: manifest | tags
Context
2014-04-12
01:03
Amélioration ergonomique des champs date pour les navigateurs qui ne gèrent pas le type date : on peut entrer la date au format dd/mm/YYYY check-in: e879dc5feb user: bohwaz tags: trunk
00:41
Restreindre les dates acceptées dans les champs persos check-in: 0c2ea2638c user: bohwaz tags: trunk
00:40
Plugin système vide par défaut check-in: e1f6095884 user: bohwaz tags: trunk
Changes

Modified src/include/class.membres.php from [db8b6f595c] to [7f657564b8].

299
300
301
302
303
304
305













306
307
308
309
310
311
312
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







+
+
+
+
+
+
+
+
+
+
+
+
+







                {
                    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'] == 'date' && trim($data[$key]) !== '' && !utils::checkDate($data[$key]))
                {
                    throw new UserException('Date invalide "' . $config['title'] . '", format attendu : AAAA-MM-JJ.');
                }
                elseif ($config['type'] == 'datetime' && trim($data[$key]) !== '')
                {
                    if (!utils::checkDateTime($data[$key]) || !($dt = new DateTime($data[$key])))
                    {
                        throw new UserException('Date invalide "' . $config['title'] . '", format attendu : AAAA-MM-JJ HH:mm.');
                    }

                    $data[$key] = $dt->format('Y-m-d H:i');
                }
                elseif ($config['type'] == 'tel')
                {
                    $data[$key] = utils::normalizePhoneNumber($data[$key]);
                }
                elseif ($config['type'] == 'country')
                {
                    $data[$key] = strtoupper(substr($data[$key], 0, 2));
433
434
435
436
437
438
439
440

441
442
443
444
445
446
447
446
447
448
449
450
451
452

453
454
455
456
457
458
459
460







-
+








            // 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))
            # FIXME || $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']))
        {

Modified src/include/lib.template.php from [29cd731071] to [5bb0e07573].

390
391
392
393
394
395
396




397
398
399
400
401
402
403
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407







+
+
+
+







    }
    elseif ($type == 'country')
    {
        $type = 'select';
        $config['options'] = utils::getCountryList();
        $params['default'] = Config::getInstance()->get('pays');
    }
    elseif ($type == 'date')
    {
        $params['pattern'] = '\d{4}-\d{2}-\d{2}';
    }
    elseif ($type == 'multiple')
    {
        if (empty($config['options']))
            throw new \BadFunctionCallException('Paramètre options obligatoire pour champ de type multiple.');
    }

    $field = '';

Modified src/include/lib.utils.php from [6668e725cc] to [6a6471aec6].

41
42
43
44
45
46
47

48




49

50



51





52




53
54
55
56
57
58
59
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







+
-
+
+
+
+

+
-
+
+
+

+
+
+
+
+
-
+
+
+
+







        $date = strtolower($date);
        return $date;
    }

    static public function sqliteDateToFrench($d, $short = false)
    {
        if (strlen($d) == 10 || $short)
        {
            return \DateTime::createFromFormat('Y-m-d', substr($d, 0, 10))->format('d/m/Y');
            $d = substr($d, 0, 10);
            $f = 'Y-m-d';
            $f2 = 'd/m/Y';
        }
        elseif (strlen($d) == 16)
        {
            return \DateTime::createFromFormat('Y-m-d H:i', $d)->format('d/m/Y H:i');
            $f = 'Y-m-d H:i';
            $f2 = 'd/m/Y H:i';
        }
        else
        {
            $f = 'Y-m-d H:i:s';
            $f2 = 'd/m/Y H:i';
        }
        
            return \DateTime::createFromFormat('Y-m-d H:i:s', $d)->format('d/m/Y H:i');
        if ($dt = \DateTime::createFromFormat($f, $d))
            return $dt->format($f2);
        else
            return $d;
    }

    static public function makeTimestampFromForm($d)
    {
        return mktime($d['h'], $d['min'], 0, $d['m'], $d['d'], $d['y']);
    }

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







-
+







            return false;

        return true;
    }

    static public function checkDateTime($str)
    {
        if (!preg_match('!^(\d{4}-\d{2}-\d{2}) (\d{2}):(\d{2})(?::(\d{2}))?$!', $str, $match))
        if (!preg_match('!^(\d{4}-\d{2}-\d{2})[T ](\d{2}):(\d{2})!', $str, $match))
            return false;

        if (!self::checkDate($match[1]))
            return false;

        if ((int) $match[2] < 0 || (int) $match[2] > 23)
            return false;