diff --git a/api.php b/api.php index d00dfe7..0bf5a56 100644 --- a/api.php +++ b/api.php @@ -1198,6 +1198,7 @@ switch ($action) { 'elaskuvalittaja' => trim($input['elaskuvalittaja'] ?? ''), 'ytunnus' => trim($input['ytunnus'] ?? ''), 'lisatiedot' => trim($input['lisatiedot'] ?? ''), + 'priority_emails' => trim($input['priority_emails'] ?? ''), 'liittymat' => parseLiittymat($input), 'luotu' => date('Y-m-d H:i:s'), ]; @@ -1223,7 +1224,7 @@ switch ($action) { foreach ($customers as $c) { if ($c['id'] === $id) { $changes = []; - $fields = ['yritys','yhteyshenkilö','puhelin','sahkoposti','laskutusosoite','laskutuspostinumero','laskutuskaupunki','laskutussahkoposti','elaskuosoite','elaskuvalittaja','ytunnus','lisatiedot']; + $fields = ['yritys','yhteyshenkilö','puhelin','sahkoposti','laskutusosoite','laskutuspostinumero','laskutuskaupunki','laskutussahkoposti','elaskuosoite','elaskuvalittaja','ytunnus','lisatiedot','priority_emails']; foreach ($fields as $f) { if (isset($input[$f])) { $old = $c[$f] ?? ''; diff --git a/db.php b/db.php index c6b6f8d..359e7f9 100644 --- a/db.php +++ b/db.php @@ -194,6 +194,7 @@ function initDatabase(): void { elaskuvalittaja VARCHAR(100), ytunnus VARCHAR(20), lisatiedot TEXT, + priority_emails TEXT DEFAULT '', luotu DATETIME, muokattu DATETIME NULL, muokkaaja VARCHAR(100) DEFAULT '', @@ -373,6 +374,7 @@ function initDatabase(): void { $alters = [ "ALTER TABLE tickets ADD COLUMN cc TEXT DEFAULT '' AFTER mailbox_id", "ALTER TABLE tickets ADD COLUMN priority VARCHAR(20) DEFAULT 'normaali' AFTER cc", + "ALTER TABLE customers ADD COLUMN priority_emails TEXT DEFAULT '' AFTER lisatiedot", ]; foreach ($alters as $sql) { try { $db->query($sql); } catch (\Throwable $e) { /* sarake on jo olemassa */ } @@ -661,10 +663,10 @@ function dbSaveCustomer(string $companyId, array $customer): void { _dbExecute(" INSERT INTO customers (id, company_id, yritys, yhteyshenkilö, puhelin, sahkoposti, laskutusosoite, laskutuspostinumero, laskutuskaupunki, laskutussahkoposti, - elaskuosoite, elaskuvalittaja, ytunnus, lisatiedot, luotu, muokattu, muokkaaja) + elaskuosoite, elaskuvalittaja, ytunnus, lisatiedot, priority_emails, luotu, muokattu, muokkaaja) VALUES (:id, :company_id, :yritys, :yhteyshenkilö, :puhelin, :sahkoposti, :laskutusosoite, :laskutuspostinumero, :laskutuskaupunki, :laskutussahkoposti, - :elaskuosoite, :elaskuvalittaja, :ytunnus, :lisatiedot, :luotu, :muokattu, :muokkaaja) + :elaskuosoite, :elaskuvalittaja, :ytunnus, :lisatiedot, :priority_emails, :luotu, :muokattu, :muokkaaja) ON DUPLICATE KEY UPDATE yritys = VALUES(yritys), yhteyshenkilö = VALUES(yhteyshenkilö), puhelin = VALUES(puhelin), sahkoposti = VALUES(sahkoposti), @@ -672,6 +674,7 @@ function dbSaveCustomer(string $companyId, array $customer): void { laskutuskaupunki = VALUES(laskutuskaupunki), laskutussahkoposti = VALUES(laskutussahkoposti), elaskuosoite = VALUES(elaskuosoite), elaskuvalittaja = VALUES(elaskuvalittaja), ytunnus = VALUES(ytunnus), lisatiedot = VALUES(lisatiedot), + priority_emails = VALUES(priority_emails), muokattu = VALUES(muokattu), muokkaaja = VALUES(muokkaaja) ", [ 'id' => $customer['id'], @@ -688,6 +691,7 @@ function dbSaveCustomer(string $companyId, array $customer): void { 'elaskuvalittaja' => $customer['elaskuvalittaja'] ?? '', 'ytunnus' => $customer['ytunnus'] ?? '', 'lisatiedot' => $customer['lisatiedot'] ?? '', + 'priority_emails' => $customer['priority_emails'] ?? '', 'luotu' => $customer['luotu'] ?? date('Y-m-d H:i:s'), 'muokattu' => $customer['muokattu'] ?? null, 'muokkaaja' => $customer['muokkaaja'] ?? '', @@ -1081,15 +1085,14 @@ function dbDeleteTemplate(string $templateId): void { // ==================== PRIORITY EMAILS (ASIAKKUUDET) ==================== -function dbLoadPriorityEmails(string $companyId): array { - return _dbFetchColumn("SELECT email FROM customer_priority_emails WHERE company_id = ?", [$companyId]); -} - function dbIsPriorityEmail(string $companyId, string $email): bool { $email = strtolower(trim($email)); if (!$email) return false; - return (bool)_dbFetchScalar( - "SELECT COUNT(*) FROM customer_priority_emails WHERE company_id = ? AND LOWER(email) = ?", - [$companyId, $email] - ); + // Hae kaikki asiakkaiden priority_emails kentät ja tarkista onko sähköposti listalla + $rows = _dbFetchAll("SELECT priority_emails FROM customers WHERE company_id = ? AND priority_emails != ''", [$companyId]); + foreach ($rows as $row) { + $emails = array_map('strtolower', array_map('trim', explode("\n", $row['priority_emails']))); + if (in_array($email, $emails)) return true; + } + return false; } diff --git a/index.html b/index.html index 69ff8c2..f39e20b 100644 --- a/index.html +++ b/index.html @@ -423,6 +423,7 @@ + @@ -525,16 +526,6 @@ - -
Näiltä osoitteilta saapuvat tiketit saavat automaattisesti "Tärkeä"-prioriteetin.
- -Näiltä osoitteilta saapuvat tiketit saavat automaattisesti ⚠️ Tärkeä -prioriteetin. Yksi per rivi.
+ +