diff --git a/distfiles/functions.php b/distfiles/functions.php index ff1e2d7..830f0b7 100644 --- a/distfiles/functions.php +++ b/distfiles/functions.php @@ -1000,3 +1000,31 @@ function templateselect($techid, $operation) "; } + +function fix_date($datestring) +{ + // accepts a string as an argument + // returns a valid date string in the format YYYY-MM-DD + // if input string is not a valid date, return the current date + global $db, $today; + + if (!$datestring) $datestring = $today; + $datepatt = '/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/'; + if (!preg_match($datepatt,$datestring)) $datestring = $today; + $datestring = mysqli_real_escape_string($db, $datestring); + return $datestring; +} + +function fix_time($timestring) +{ + // accepts a string as an argument + // returns a valid time string in the format HH:MM:SS + // if input string is not a valid time, return the current time + global $db, $now; + + if (!$timestring) $timestring = $now; + $timepatt = '/^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/'; + if (!preg_match($timepatt,$timestring)) $timestring = $now; + $timestring = mysqli_real_escape_string($db, $timestring); + return $timestring; +}