|
|
@@ -1014,14 +1014,6 @@ function getDefaultSystemSettings()
|
|
|
"order_recipient_email" => defined("ORDER_RECIPIENT_EMAIL")
|
|
|
? ORDER_RECIPIENT_EMAIL
|
|
|
: getDefaultAdminEmail(),
|
|
|
- "order_confirmation_required" => defined("ORDER_CONFIRMATION_REQUIRED")
|
|
|
- ? (bool) ORDER_CONFIRMATION_REQUIRED
|
|
|
- : false,
|
|
|
- "order_confirmation_expiry_days" => defined(
|
|
|
- "ORDER_CONFIRMATION_EXPIRY_DAYS",
|
|
|
- )
|
|
|
- ? (int) ORDER_CONFIRMATION_EXPIRY_DAYS
|
|
|
- : 7,
|
|
|
"attach_order_pdf_to_admin_email" => defined(
|
|
|
"ATTACH_ORDER_PDF_TO_ADMIN_EMAIL",
|
|
|
)
|
|
|
@@ -1046,23 +1038,12 @@ function normalizeSystemSettings($settings)
|
|
|
$recipientEmail = $defaults["order_recipient_email"];
|
|
|
}
|
|
|
|
|
|
- $expiryDays = isset($settings["order_confirmation_expiry_days"])
|
|
|
- ? (int) $settings["order_confirmation_expiry_days"]
|
|
|
- : $defaults["order_confirmation_expiry_days"];
|
|
|
- if ($expiryDays < 1) {
|
|
|
- $expiryDays = 7;
|
|
|
- }
|
|
|
-
|
|
|
$startpageIntroText = trim(
|
|
|
(string) ($settings["startpage_intro_text"] ?? $defaults["startpage_intro_text"]),
|
|
|
);
|
|
|
|
|
|
return [
|
|
|
"order_recipient_email" => $recipientEmail,
|
|
|
- "order_confirmation_required" => !empty(
|
|
|
- $settings["order_confirmation_required"]
|
|
|
- ),
|
|
|
- "order_confirmation_expiry_days" => $expiryDays,
|
|
|
"attach_order_pdf_to_admin_email" => !empty(
|
|
|
$settings["attach_order_pdf_to_admin_email"]
|
|
|
),
|
|
|
@@ -1089,18 +1070,6 @@ function getOrderRecipientEmail()
|
|
|
return $settings["order_recipient_email"];
|
|
|
}
|
|
|
|
|
|
-function isOrderConfirmationRequired()
|
|
|
-{
|
|
|
- $settings = getSystemSettings();
|
|
|
- return !empty($settings["order_confirmation_required"]);
|
|
|
-}
|
|
|
-
|
|
|
-function getOrderConfirmationExpiryDays()
|
|
|
-{
|
|
|
- $settings = getSystemSettings();
|
|
|
- return max(1, (int) $settings["order_confirmation_expiry_days"]);
|
|
|
-}
|
|
|
-
|
|
|
function shouldAttachOrderPdfToAdminEmail()
|
|
|
{
|
|
|
$settings = getSystemSettings();
|
|
|
@@ -1293,19 +1262,6 @@ function normalizeOrderRecord($order)
|
|
|
$createdAt = date("Y-m-d H:i:s");
|
|
|
}
|
|
|
|
|
|
- $confirmationStatus = trim(
|
|
|
- (string) ($order["confirmation_status"] ?? "confirmed"),
|
|
|
- );
|
|
|
- $allowedConfirmationStatuses = [
|
|
|
- "not_required",
|
|
|
- "pending",
|
|
|
- "confirmed",
|
|
|
- "expired",
|
|
|
- ];
|
|
|
- if (!in_array($confirmationStatus, $allowedConfirmationStatuses, true)) {
|
|
|
- $confirmationStatus = "confirmed";
|
|
|
- }
|
|
|
-
|
|
|
$status = trim((string) ($order["status"] ?? "open"));
|
|
|
$allowedStatuses = ["open", "partial", "processed", "cancelled"];
|
|
|
if (!in_array($status, $allowedStatuses, true)) {
|
|
|
@@ -1321,14 +1277,6 @@ function normalizeOrderRecord($order)
|
|
|
"comment" => trim((string) ($order["comment"] ?? "")),
|
|
|
"items" => $items,
|
|
|
"status" => $status,
|
|
|
- "confirmation_status" => $confirmationStatus,
|
|
|
- "confirmation_token" => trim(
|
|
|
- (string) ($order["confirmation_token"] ?? ""),
|
|
|
- ),
|
|
|
- "confirmation_expires_at" => trim(
|
|
|
- (string) ($order["confirmation_expires_at"] ?? ""),
|
|
|
- ),
|
|
|
- "confirmed_at" => trim((string) ($order["confirmed_at"] ?? "")),
|
|
|
"created_at" => $createdAt,
|
|
|
"updated_at" => trim((string) ($order["updated_at"] ?? $createdAt)),
|
|
|
"cancelled_at" => trim((string) ($order["cancelled_at"] ?? "")),
|
|
|
@@ -1354,16 +1302,6 @@ function refreshOrderState($order)
|
|
|
return $order;
|
|
|
}
|
|
|
|
|
|
- if (
|
|
|
- ($order["confirmation_status"] ?? "") === "pending" &&
|
|
|
- !empty($order["confirmation_expires_at"])
|
|
|
- ) {
|
|
|
- $expiresAt = strtotime((string) $order["confirmation_expires_at"]);
|
|
|
- if ($expiresAt !== false && time() > $expiresAt) {
|
|
|
- $order["confirmation_status"] = "expired";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
$processedCount = 0;
|
|
|
foreach ($order["items"] as $item) {
|
|
|
if (!empty($item["is_processed"])) {
|
|
|
@@ -1382,25 +1320,6 @@ function refreshOrderState($order)
|
|
|
return $order;
|
|
|
}
|
|
|
|
|
|
-function expirePendingOrders()
|
|
|
-{
|
|
|
- $orders = getOrders();
|
|
|
- $changed = false;
|
|
|
-
|
|
|
- foreach ($orders as &$order) {
|
|
|
- $updated = refreshOrderState($order);
|
|
|
- if ($updated !== $order) {
|
|
|
- $order = $updated;
|
|
|
- $changed = true;
|
|
|
- }
|
|
|
- }
|
|
|
- unset($order);
|
|
|
-
|
|
|
- if ($changed) {
|
|
|
- saveOrders($orders);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
function getOrderById($orderId)
|
|
|
{
|
|
|
$orderId = trim((string) $orderId);
|
|
|
@@ -1417,74 +1336,6 @@ function getOrderById($orderId)
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
-function findOrderByConfirmationToken($token)
|
|
|
-{
|
|
|
- $token = trim((string) $token);
|
|
|
- if ($token === "") {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- foreach (getOrders() as $order) {
|
|
|
- if (($order["confirmation_token"] ?? "") === $token) {
|
|
|
- return $order;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
-}
|
|
|
-
|
|
|
-function buildOrderConfirmationUrl($token)
|
|
|
-{
|
|
|
- $path = "/order-confirm.php?token=" . urlencode($token);
|
|
|
- return buildAbsoluteUrl($path);
|
|
|
-}
|
|
|
-
|
|
|
-function buildAbsoluteUrl($path)
|
|
|
-{
|
|
|
- $path = "/" . ltrim((string) $path, "/");
|
|
|
- $siteUrl = defined("SITE_URL") ? trim((string) SITE_URL) : "";
|
|
|
-
|
|
|
- if (strpos($siteUrl, "://") !== false) {
|
|
|
- return rtrim($siteUrl, "/") . $path;
|
|
|
- }
|
|
|
-
|
|
|
- $basePath = trim($siteUrl);
|
|
|
- if ($basePath !== "" && $basePath !== "/") {
|
|
|
- $path = "/" . trim($basePath, "/") . $path;
|
|
|
- }
|
|
|
-
|
|
|
- $scheme = isHttpsRequest() ? "https" : "http";
|
|
|
- $host = $_SERVER["HTTP_HOST"] ?? "";
|
|
|
- if ($host === "") {
|
|
|
- return $path;
|
|
|
- }
|
|
|
-
|
|
|
- return $scheme . "://" . $host . $path;
|
|
|
-}
|
|
|
-
|
|
|
-function isHttpsRequest(): bool
|
|
|
-{
|
|
|
- if (
|
|
|
- !empty($_SERVER["HTTPS"]) &&
|
|
|
- strtolower((string) $_SERVER["HTTPS"]) !== "off"
|
|
|
- ) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- if (
|
|
|
- !empty($_SERVER["HTTP_X_FORWARDED_PROTO"]) &&
|
|
|
- strtolower((string) $_SERVER["HTTP_X_FORWARDED_PROTO"]) === "https"
|
|
|
- ) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- if (
|
|
|
- !empty($_SERVER["SERVER_PORT"]) &&
|
|
|
- (int) $_SERVER["SERVER_PORT"] === 443
|
|
|
- ) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
-}
|
|
|
-
|
|
|
function createOrder(
|
|
|
$customerName,
|
|
|
$customerEmail,
|
|
|
@@ -1527,16 +1378,6 @@ function createOrder(
|
|
|
}
|
|
|
|
|
|
$now = date("Y-m-d H:i:s");
|
|
|
- $requiresConfirmation = isOrderConfirmationRequired();
|
|
|
- $confirmationToken = $requiresConfirmation ? bin2hex(random_bytes(24)) : "";
|
|
|
- $confirmationExpiresAt = "";
|
|
|
- if ($requiresConfirmation) {
|
|
|
- $expires = new DateTimeImmutable();
|
|
|
- $expires = $expires->modify(
|
|
|
- "+" . getOrderConfirmationExpiryDays() . " days",
|
|
|
- );
|
|
|
- $confirmationExpiresAt = $expires->format("Y-m-d H:i:s");
|
|
|
- }
|
|
|
|
|
|
$order = [
|
|
|
"id" => generateOrderId(),
|
|
|
@@ -1547,12 +1388,6 @@ function createOrder(
|
|
|
"comment" => $comment,
|
|
|
"items" => $items,
|
|
|
"status" => "open",
|
|
|
- "confirmation_status" => $requiresConfirmation
|
|
|
- ? "pending"
|
|
|
- : "not_required",
|
|
|
- "confirmation_token" => $confirmationToken,
|
|
|
- "confirmation_expires_at" => $confirmationExpiresAt,
|
|
|
- "confirmed_at" => $requiresConfirmation ? "" : $now,
|
|
|
"created_at" => $now,
|
|
|
"updated_at" => $now,
|
|
|
"cancelled_at" => "",
|
|
|
@@ -1571,16 +1406,12 @@ function createOrder(
|
|
|
"organization" => $organization["label"],
|
|
|
]);
|
|
|
|
|
|
- if ($requiresConfirmation) {
|
|
|
- sendOrderConfirmationRequestEmail($order);
|
|
|
- } else {
|
|
|
- $result = sendConfirmedOrderAdminNotification($order);
|
|
|
- if ($result) {
|
|
|
- markOrderAdminNotified($order["id"]);
|
|
|
- $order = getOrderById($order["id"]);
|
|
|
- }
|
|
|
- sendOrderCreatedCustomerEmail($order);
|
|
|
+ $result = sendConfirmedOrderAdminNotification($order);
|
|
|
+ if ($result) {
|
|
|
+ markOrderAdminNotified($order["id"]);
|
|
|
+ $order = getOrderById($order["id"]);
|
|
|
}
|
|
|
+ sendOrderCreatedCustomerEmail($order);
|
|
|
|
|
|
return ["success" => true, "order" => $order];
|
|
|
}
|
|
|
@@ -1602,74 +1433,6 @@ function markOrderAdminNotified($orderId)
|
|
|
saveOrders($orders);
|
|
|
}
|
|
|
|
|
|
-function confirmOrderByToken($token)
|
|
|
-{
|
|
|
- $orders = getOrders();
|
|
|
- $now = date("Y-m-d H:i:s");
|
|
|
-
|
|
|
- foreach ($orders as &$order) {
|
|
|
- if (($order["confirmation_token"] ?? "") !== $token) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- $order = refreshOrderState($order);
|
|
|
-
|
|
|
- if ($order["status"] === "cancelled") {
|
|
|
- return [
|
|
|
- "success" => false,
|
|
|
- "message" =>
|
|
|
- "Diese Bestellung wurde storniert und kann nicht mehr bestätigt werden.",
|
|
|
- ];
|
|
|
- }
|
|
|
- if ($order["confirmation_status"] === "confirmed") {
|
|
|
- return [
|
|
|
- "success" => false,
|
|
|
- "message" => "Diese Bestellung wurde bereits bestätigt.",
|
|
|
- ];
|
|
|
- }
|
|
|
- if ($order["confirmation_status"] === "expired") {
|
|
|
- return [
|
|
|
- "success" => false,
|
|
|
- "message" => "Der Bestätigungslink ist abgelaufen.",
|
|
|
- ];
|
|
|
- }
|
|
|
- if ($order["confirmation_status"] !== "pending") {
|
|
|
- return [
|
|
|
- "success" => false,
|
|
|
- "message" =>
|
|
|
- "Für diese Bestellung ist keine Bestätigung erforderlich.",
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- $expiresAt = strtotime((string) $order["confirmation_expires_at"]);
|
|
|
- if ($expiresAt !== false && time() > $expiresAt) {
|
|
|
- $order["confirmation_status"] = "expired";
|
|
|
- $order["updated_at"] = $now;
|
|
|
- saveOrders($orders);
|
|
|
- return [
|
|
|
- "success" => false,
|
|
|
- "message" => "Der Bestätigungslink ist abgelaufen.",
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- $order["confirmation_status"] = "confirmed";
|
|
|
- $order["confirmed_at"] = $now;
|
|
|
- $order["updated_at"] = $now;
|
|
|
- saveOrders($orders);
|
|
|
-
|
|
|
- $sent = sendConfirmedOrderAdminNotification($order);
|
|
|
- if ($sent) {
|
|
|
- markOrderAdminNotified($order["id"]);
|
|
|
- }
|
|
|
- sendOrderConfirmedCustomerEmail(getOrderById($order["id"]));
|
|
|
-
|
|
|
- return ["success" => true, "order" => getOrderById($order["id"])];
|
|
|
- }
|
|
|
- unset($order);
|
|
|
-
|
|
|
- return ["success" => false, "message" => "Bestellung nicht gefunden."];
|
|
|
-}
|
|
|
-
|
|
|
function toggleOrderItemProcessed($orderId, $itemIndex)
|
|
|
{
|
|
|
$orders = getOrders();
|
|
|
@@ -1687,20 +1450,6 @@ function toggleOrderItemProcessed($orderId, $itemIndex)
|
|
|
"Stornierte Bestellungen können nicht mehr bearbeitet werden.",
|
|
|
];
|
|
|
}
|
|
|
- if (($order["confirmation_status"] ?? "") === "pending") {
|
|
|
- return [
|
|
|
- "success" => false,
|
|
|
- "message" =>
|
|
|
- "Unbestätigte Bestellungen können noch nicht bearbeitet werden.",
|
|
|
- ];
|
|
|
- }
|
|
|
- if (($order["confirmation_status"] ?? "") === "expired") {
|
|
|
- return [
|
|
|
- "success" => false,
|
|
|
- "message" =>
|
|
|
- "Abgelaufene unbestätigte Bestellungen können nicht bearbeitet werden.",
|
|
|
- ];
|
|
|
- }
|
|
|
if (!isset($order["items"][$itemIndex])) {
|
|
|
return [
|
|
|
"success" => false,
|
|
|
@@ -1796,20 +1545,6 @@ function orderItemCanBeManaged($order)
|
|
|
"Stornierte Bestellungen können nicht mehr bearbeitet werden.",
|
|
|
];
|
|
|
}
|
|
|
- if (($order["confirmation_status"] ?? "") === "pending") {
|
|
|
- return [
|
|
|
- "success" => false,
|
|
|
- "message" =>
|
|
|
- "Unbestätigte Bestellungen können noch nicht bearbeitet werden.",
|
|
|
- ];
|
|
|
- }
|
|
|
- if (($order["confirmation_status"] ?? "") === "expired") {
|
|
|
- return [
|
|
|
- "success" => false,
|
|
|
- "message" =>
|
|
|
- "Abgelaufene unbestätigte Bestellungen können nicht bearbeitet werden.",
|
|
|
- ];
|
|
|
- }
|
|
|
|
|
|
return ["success" => true];
|
|
|
}
|
|
|
@@ -2037,9 +1772,6 @@ function collectBackorderItemRefs()
|
|
|
if (($order["status"] ?? "") === "cancelled") {
|
|
|
continue;
|
|
|
}
|
|
|
- if (in_array($order["confirmation_status"] ?? "", ["pending", "expired"], true)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
|
|
|
foreach ($order["items"] as $itemIndex => $item) {
|
|
|
$status = (string) ($item["backorder_status"] ?? "");
|
|
|
@@ -2317,12 +2049,6 @@ function getOrderStatusLabel($order)
|
|
|
if (($order["status"] ?? "") === "cancelled") {
|
|
|
return "Storniert";
|
|
|
}
|
|
|
- if (($order["confirmation_status"] ?? "") === "pending") {
|
|
|
- return "Unbestätigt";
|
|
|
- }
|
|
|
- if (($order["confirmation_status"] ?? "") === "expired") {
|
|
|
- return "Bestätigung abgelaufen";
|
|
|
- }
|
|
|
if (($order["status"] ?? "") === "processed") {
|
|
|
return "Bearbeitet";
|
|
|
}
|
|
|
@@ -2337,12 +2063,6 @@ function getOrderStatusClass($order)
|
|
|
if (($order["status"] ?? "") === "cancelled") {
|
|
|
return "status-cancelled";
|
|
|
}
|
|
|
- if (($order["confirmation_status"] ?? "") === "pending") {
|
|
|
- return "status-unconfirmed";
|
|
|
- }
|
|
|
- if (($order["confirmation_status"] ?? "") === "expired") {
|
|
|
- return "status-expired";
|
|
|
- }
|
|
|
if (($order["status"] ?? "") === "processed") {
|
|
|
return "status-processed";
|
|
|
}
|
|
|
@@ -2620,38 +2340,6 @@ function buildOrderSummaryHtml($order, $title, $introHtml, $extraHtml = "")
|
|
|
</html>';
|
|
|
}
|
|
|
|
|
|
-function sendOrderConfirmationRequestEmail($order)
|
|
|
-{
|
|
|
- $subject = SITE_SERVICE_NAME . ": Bestellung bestätigen - " . $order["id"];
|
|
|
- $link = buildOrderConfirmationUrl($order["confirmation_token"]);
|
|
|
- $expiryText = formatDate($order["confirmation_expires_at"]);
|
|
|
- $intro =
|
|
|
- "<p>Guten Tag " .
|
|
|
- escape($order["customer_name"]) .
|
|
|
- ",</p><p>bitte bestätigen Sie Ihre Bestellung im " .
|
|
|
- escape(SITE_SERVICE_NAME) .
|
|
|
- " der Stadt Freising über den folgenden Link.</p>";
|
|
|
- $extra =
|
|
|
- '
|
|
|
- <p><a href="' .
|
|
|
- escape($link) .
|
|
|
- '" style="display: inline-block; padding: 0.75rem 1.5rem; background: #ffd71c; color: #111111; text-decoration: none; border: 2px solid #ffd71c; border-radius: 14px; font-weight: 700;">Bestellung bestätigen</a></p>
|
|
|
- <p>Der Link ist gültig bis: <strong>' .
|
|
|
- escape($expiryText) .
|
|
|
- '</strong></p>
|
|
|
- <p>Falls der Button nicht funktioniert, verwenden Sie bitte diesen Link:<br>' .
|
|
|
- escape($link) .
|
|
|
- "</p>";
|
|
|
- $message = buildOrderSummaryHtml(
|
|
|
- $order,
|
|
|
- "Bestellung bestätigen",
|
|
|
- $intro,
|
|
|
- $extra,
|
|
|
- );
|
|
|
-
|
|
|
- return sendEmail($order["customer_email"], $subject, $message);
|
|
|
-}
|
|
|
-
|
|
|
function sendOrderCreatedCustomerEmail($order)
|
|
|
{
|
|
|
$subject = SITE_SERVICE_NAME . ": Ihre Bestellung - " . $order["id"];
|
|
|
@@ -2666,20 +2354,6 @@ function sendOrderCreatedCustomerEmail($order)
|
|
|
return sendEmail($order["customer_email"], $subject, $message);
|
|
|
}
|
|
|
|
|
|
-function sendOrderConfirmedCustomerEmail($order)
|
|
|
-{
|
|
|
- $subject = SITE_SERVICE_NAME . ": Bestellung bestätigt - " . $order["id"];
|
|
|
- $intro =
|
|
|
- "<p>Guten Tag " .
|
|
|
- escape($order["customer_name"]) .
|
|
|
- ",</p><p>Ihre Bestellung wurde bestätigt und an " .
|
|
|
- escape(SITE_DEPARTMENT_NAME) .
|
|
|
- " weitergeleitet.</p>";
|
|
|
- $message = buildOrderSummaryHtml($order, "Bestellung bestätigt", $intro);
|
|
|
-
|
|
|
- return sendEmail($order["customer_email"], $subject, $message);
|
|
|
-}
|
|
|
-
|
|
|
function sendConfirmedOrderAdminNotification($order)
|
|
|
{
|
|
|
$recipient = getOrderRecipientEmail();
|
|
|
@@ -2689,7 +2363,7 @@ function sendConfirmedOrderAdminNotification($order)
|
|
|
|
|
|
$subject = SITE_SERVICE_NAME . ": Neue Bestellung - " . $order["id"];
|
|
|
$intro =
|
|
|
- "<p>Eine neue PSA-Bestellung wurde freigegeben und muss bearbeitet werden.</p>";
|
|
|
+ "<p>Eine neue PSA-Bestellung ist eingegangen und muss bearbeitet werden.</p>";
|
|
|
$message = buildOrderSummaryHtml($order, "Neue PSA-Bestellung", $intro);
|
|
|
|
|
|
$attachments = [];
|