Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fix/1722 #13

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 41 additions & 18 deletions lib/GaletteAuto/Auto.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* PHP version 5
*
* Copyright © 2009-2022 The Galette Team
* Copyright © 2009-2023 The Galette Team
*
* This file is part of Galette (http://galette.tuxfamily.org).
*
Expand Down Expand Up @@ -57,7 +57,7 @@
* @name Auto
* @package GaletteAuto
* @author Johan Cwiklinski <johan@x-tnd.be>
* @copyright 2009-2021 The Galette Team
* @copyright 2009-2023 The Galette Team
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
* @link http://galette.tuxfamily.org
* @since Available since 0.7dev - 2009-03-16
Expand Down Expand Up @@ -703,33 +703,56 @@ public function check($post)
}

switch ($prop) {
//string values with special check
case 'registration':
if (mb_strlen($value) <= 10) {
$this->$prop = $value;
} else {
$this->errors[] = str_replace(
array(
'%maxsize',
'%field',
'%cursize'
),
array(
10,
$this->getPropName($prop),
mb_strlen($value)
),
_T("- Maximum size for %field is %maxsize (current %cursize)!")
);
}
break;
//string values, no check
case 'name':
case 'comment':
//string values with special check?
case 'chassis_number':
case 'registration':
$this->$prop = $value;
break;
//dates
case 'first_registration_date':
case 'first_circulation_date':
if (preg_match("@^([0-9]{2})/([0-9]{2})/([0-9]{4})$@", $value, $array_jours)) {
if (checkdate($array_jours[2], $array_jours[1], $array_jours[3])) {
$value = $array_jours[3] . '-' . $array_jours[2] . '-' . $array_jours[1];
$this->$prop = $value;
} else {
$this->errors[] = str_replace(
'%s',
$this->getPropName($prop),
_T("- Non valid date for %s!")
);
try {
$d = \DateTime::createFromFormat(__("Y-m-d"), $value);
if ($d === false) {
//try with non localized date
$d = \DateTime::createFromFormat("Y-m-d", $value);
if ($d === false) {
throw new \Exception('Incorrect format');
}
}
} else {
$this->$prop = $d->format('Y-m-d');
} catch (\Throwable $e) {
$this->errors[] = str_replace(
'%s',
$this->getPropName($prop),
_T("- Wrong date format for %s (dd/mm/yyyy)!")
array(
'%date_format',
'%field'
),
array(
__("Y-m-d"),
$this->getPropName($prop)
),
_T("- Wrong date format (%date_format) for %field!")
);
}
break;
Expand Down