Add Amazon revenue accounting
This commit is contained in:
@@ -76,6 +76,33 @@ function postText(string $key, int $maxLength): string
|
||||
return $value;
|
||||
}
|
||||
|
||||
function validateIsbnField(string $value, string $label): ?string
|
||||
{
|
||||
$value = trim($value);
|
||||
if ($value === '') {
|
||||
return null;
|
||||
}
|
||||
if (!preg_match('/^97[89](?:-[0-9]+)+$/', $value)) {
|
||||
throw new InvalidArgumentException($label . ' muss als ISBN-13 mit Bindestrichen eingegeben werden, zum Beispiel 978-3-16-148410-0.');
|
||||
}
|
||||
|
||||
$digits = str_replace('-', '', $value);
|
||||
if (strlen($digits) !== 13) {
|
||||
throw new InvalidArgumentException($label . ' muss genau 13 Ziffern enthalten.');
|
||||
}
|
||||
|
||||
$sum = 0;
|
||||
for ($index = 0; $index < 12; $index++) {
|
||||
$sum += (int) $digits[$index] * ($index % 2 === 0 ? 1 : 3);
|
||||
}
|
||||
$checkDigit = (10 - ($sum % 10)) % 10;
|
||||
if ((int) $digits[12] !== $checkDigit) {
|
||||
throw new InvalidArgumentException($label . ' enthält eine ungültige Prüfziffer.');
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
function redirectAdmin(): never
|
||||
{
|
||||
header('Location: admin.php');
|
||||
|
||||
Reference in New Issue
Block a user