X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fprofile%2Fpage.inc.php;h=ec0ed6234d6797503fe1ad9471ff66ab140a52f8;hb=7bff4cb031e50e345d346d2a333b5ac7a9d434fd;hp=4f440241f9c75e3bf806bc87a7949f29cc7ddbe3;hpb=7c2e0f0db1940d4d52d282ddd06d22706ee35a54;p=platal.git diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index 4f44024..ec0ed62 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -125,6 +125,33 @@ class ProfileBool extends ProfileNoSave } } +class ProfileDate extends ProfileNoSave +{ + public function value(ProfilePage &$page, $field, $value, &$success) + { + $success = true; + if (is_null($value)) { + $value = preg_replace('/(\d{4})-(\d{2})-(\d{2})/', '\3/\2/\1', @$page->values[$field]); + } else { + $success = preg_match('@(\d{2})/(\d{2})/(\d{4})@', $value, $matches); + if (!$success) { + global $page; + $page->trig("Les dates doivent être au format jj/mm/aaaa"); + } else { + $day = (int)$matches[1]; + $month = (int)$matches[2]; + $year = (int)$matches[3]; + $success = ($day > 0 && $day <= 31) && ($month > 0 && $month <= 12) && ($year > 1900 && $year <= 2020); + if (!$success) { + global $page; + $page->trig("La date n'a pas une valeur valide"); + } + } + } + return $value; + } +} + abstract class ProfileGeoloc implements ProfileSetting { protected function geolocAddress(array &$address, &$success)