diff --git a/application/ConstructionConsentProject/ConstructionConsentProject.php b/application/ConstructionConsentProject/ConstructionConsentProject.php index 1f88eba6c..bda2833e3 100644 --- a/application/ConstructionConsentProject/ConstructionConsentProject.php +++ b/application/ConstructionConsentProject/ConstructionConsentProject.php @@ -238,18 +238,6 @@ class ConstructionConsentProject extends mfBaseModel { return $where; } - /** - * Checks if there are faulty owner entries in the Construction Consent system - * for a specific project - * - * A faulty entry is defined as one where: - * - Title is empty AND (first name is empty OR last name is empty OR city is empty OR zip code is invalid) - * - For Austrian addresses, zip code must be exactly 4 digits - * - For other countries, zip code must not be empty - * - * @param int $projectId The ID of the construction consent project to check - * @return bool Returns true if faulty entries exist, false otherwise - */ public static function hasFaultyOwnerEntries(int $projectId): bool { if (empty($projectId)) return false; @@ -272,23 +260,41 @@ AND ( ) AND ( + /* Country must not contain any digits */ + (cco.country REGEXP '[0-9]') + OR + /* For Austria or empty country: ZIP must be exactly 4 digits */ ( - (LOWER(cco.country) = 'österreich' OR LOWER(cco.country) = 'austria') AND - (cco.zip IS NULL OR cco.zip NOT REGEXP '^[0-9]{4}') + ( + cco.country IS NULL OR + TRIM(cco.country) = '' OR + LOWER(cco.country) = 'österreich' OR + LOWER(cco.country) = 'austria' + ) AND + (cco.zip IS NULL OR cco.zip NOT REGEXP '^[0-9]{4}$') + ) + OR + /* For Germany: ZIP must be exactly 5 digits */ + ( + (LOWER(cco.country) = 'deutschland' OR LOWER(cco.country) = 'germany') AND + (cco.zip IS NULL OR cco.zip NOT REGEXP '^[0-9]{5}$') ) OR /* For other countries: ZIP must not be empty */ ( - (LOWER(cco.country) != 'österreich' AND LOWER(cco.country) != 'austria') AND + ( + LOWER(cco.country) NOT IN ('österreich', 'austria', 'deutschland', 'germany') AND + cco.country IS NOT NULL AND + TRIM(cco.country) <> '' + ) AND (cco.zip IS NULL OR TRIM(cco.zip) = '') ) ) ) LIMIT 1"; - $res = $db->query($sql); - - return ($res->num_rows > 0); + $result = $db->query($sql); + return $result->rowCount() > 0; } public static function getFaultyOwnerEntries($projectId = null) { @@ -306,6 +312,7 @@ SELECT cco.id as owner_id, cco.firstname, cco.lastname, + cco.company, cco.title, cco.street, cco.zip, @@ -338,21 +345,40 @@ AND ( ) ) OR (cco.city IS NULL OR TRIM(cco.city) = '') -) -- Fixed parenthesis balance here +) AND ( + /* Country must not contain any digits */ + (cco.country REGEXP '[0-9]') + OR + /* For Austria or empty country: ZIP must be exactly 4 digits */ ( - (LOWER(cco.country) = 'österreich' OR LOWER(cco.country) = 'austria') AND - (cco.zip IS NULL OR cco.zip NOT REGEXP '^[0-9]{4}') + ( + cco.country IS NULL OR + TRIM(cco.country) = '' OR + LOWER(cco.country) = 'österreich' OR + LOWER(cco.country) = 'austria' + ) AND + (cco.zip IS NULL OR cco.zip NOT REGEXP '^[0-9]{4}$') ) OR + /* For Germany: ZIP must be exactly 5 digits */ ( - (LOWER(cco.country) != 'österreich' AND LOWER(cco.country) != 'austria') AND + (LOWER(cco.country) = 'deutschland' OR LOWER(cco.country) = 'germany') AND + (cco.zip IS NULL OR cco.zip NOT REGEXP '^[0-9]{5}$') + ) + OR + /* For other countries: ZIP must not be empty */ + ( + ( + LOWER(cco.country) NOT IN ('österreich', 'austria', 'deutschland', 'germany') AND + cco.country IS NOT NULL AND + TRIM(cco.country) <> '' + ) AND (cco.zip IS NULL OR TRIM(cco.zip) = '') ) ) ORDER BY ccp.name, cc.name, cco.lastname, cco.firstname - "; $res = $db->query($sql); @@ -370,17 +396,33 @@ ORDER BY } } - // Existing city check (assuming it's still relevant for faulty entries) + // Existing city check if (empty(trim($data['city']))) { $errors[] = 'city'; } - // Check ZIP based on country - $isAustria = (strtolower($data['country']) === 'österreich' || strtolower($data['country']) === 'austria'); + // Check country for numeric characters + if (isset($data['country']) && preg_match('/[0-9]/', $data['country'])) { + $errors[] = 'country'; + } - if ($isAustria && (!isset($data['zip']) || !preg_match('/^[0-9]{4}$/', $data['zip']))) { - $errors[] = 'zip'; - } elseif (!$isAustria && empty(trim($data['zip']))) { + // Check ZIP based on country + $country = strtolower($data['country'] ?? ''); + + // Austria or empty country check - must have exactly 4 digits + if ($country === '' || $country === 'österreich' || $country === 'austria') { + if (!isset($data['zip']) || !preg_match('/^[0-9]{4}$/', $data['zip'])) { + $errors[] = 'zip'; + } + } + // Germany check - must have exactly 5 digits + else if ($country === 'deutschland' || $country === 'germany') { + if (!isset($data['zip']) || !preg_match('/^[0-9]{5}$/', $data['zip'])) { + $errors[] = 'zip'; + } + } + // Other countries - ZIP must not be empty + else if (empty(trim($data['zip']))) { $errors[] = 'zip'; } @@ -394,6 +436,7 @@ ORDER BY 'title' => $data['title'], 'firstname' => $data['firstname'], 'lastname' => $data['lastname'], + 'company' => $data['company'], 'street' => $data['street'], 'zip' => $data['zip'], 'city' => $data['city'], diff --git a/public/js/pages/ConstructionConsentFaultyEntries/ConstructionConsentFaultyEntries.js b/public/js/pages/ConstructionConsentFaultyEntries/ConstructionConsentFaultyEntries.js index b25a9f982..6dff2b780 100644 --- a/public/js/pages/ConstructionConsentFaultyEntries/ConstructionConsentFaultyEntries.js +++ b/public/js/pages/ConstructionConsentFaultyEntries/ConstructionConsentFaultyEntries.js @@ -3,12 +3,12 @@ Vue.component('construction-consent-faulty-entries', { template: `
- + - + - + - + - + - + - +