query('SELECT department_id FROM email_addresses')->fetchAll(PDO::FETCH_COLUMN))); $priorities = $pdo->query('SELECT * FROM priorities ORDER BY sort_order')->fetchAll(); $topics = help_topic_options($pdo, false, false); if ($_SERVER['REQUEST_METHOD'] === 'POST') { verify_csrf(); $action = $_POST['action'] ?? ''; if ($action === 'create' || $action === 'update') { $id = $action === 'update' ? (int) ($_POST['id'] ?? 0) : 0; try { $newId = email_address_save($pdo, $id, [ 'email' => $_POST['email'] ?? '', 'label' => $_POST['label'] ?? '', 'department_id' => $_POST['department_id'] ?? 0, 'priority_id' => $_POST['priority_id'] ?? null, 'help_topic_id' => $_POST['help_topic_id'] ?? null, 'is_default' => !empty($_POST['is_default']), 'is_active' => ($_POST['status'] ?? 'active') === 'active', 'notes' => $_POST['notes'] ?? '', 'imap_enabled' => !empty($_POST['imap_enabled']), 'imap_host' => $_POST['host'] ?? '', 'imap_port' => $_POST['port'] ?? 993, 'imap_encryption' => $_POST['encryption'] ?? 'ssl', 'imap_username' => $_POST['username'] ?? '', 'imap_password' => $_POST['password'] ?? '', 'imap_folder' => $_POST['folder'] ?? '', 'imap_after_fetch' => $_POST['after_fetch'] ?? 'seen', 'imap_archive_folder' => $_POST['archive_folder'] ?? '', 'imap_spam_folder' => $_POST['spam_folder'] ?? '', 'smtp_enabled' => !empty($_POST['smtp_enabled']), 'smtp_host' => $_POST['smtp_host'] ?? '', 'smtp_port' => $_POST['smtp_port'] ?? 587, 'smtp_encryption' => $_POST['smtp_encryption'] ?? 'tls', 'smtp_username' => $_POST['smtp_username'] ?? '', 'smtp_password' => $_POST['smtp_password'] ?? '', ]); audit_log($admin['id'], ($action === 'create' ? 'E-Mail-Adresse erstellt: ' : 'E-Mail-Adresse aktualisiert: ') . strtolower(trim($_POST['email'] ?? ''))); flash('success', $action === 'create' ? 'E-Mail-Adresse erstellt.' : 'Änderungen gespeichert.'); redirect('/staff/email_addresses.php'); } catch (EmailAddressException $e) { $errors[] = $e->getMessage(); } } if ($action === 'delete') { $delEmail = email_address_delete($pdo, (int) $_POST['id']); audit_log($admin['id'], "E-Mail-Adresse gelöscht: {$delEmail}"); flash('success', 'E-Mail-Adresse gelöscht.'); redirect('/staff/email_addresses.php'); } if (in_array($action, ['send_test', 'test', 'test_smtp'], true)) { $id = (int) $_POST['id']; try { $msg = match ($action) { 'send_test' => email_address_send_test($pdo, $id, $admin['email']), 'test' => email_address_test_imap($pdo, $id), default => email_address_test_smtp($pdo, $id), }; flash('success', $msg); } catch (EmailAddressException $e) { flash('error', $e->getMessage()); } redirect('/staff/email_addresses.php?edit=' . $id . ($action === 'test' ? '&tab=imap' : ($action === 'test_smtp' ? '&tab=smtp' : ''))); } if ($action === 'bulk_add') { $raw = trim($_POST['bulk_emails'] ?? ''); $deptId = (int) ($_POST['bulk_department_id'] ?? 0); $prioId = ($_POST['bulk_priority_id'] ?? '') !== '' ? (int) $_POST['bulk_priority_id'] : null; if (!in_array($deptId, array_map('intval', array_column($departments, 'id')), true)) { $errors[] = 'Bitte eine gültige Abteilung wählen.'; } else { // Eine Adresse pro Zeile, optional mit Komma getrennter Bezeichnung: "email@x.de, Bezeichnung" $lines = array_filter(array_map('trim', preg_split('/[\r\n]+/', $raw))); $added = 0; $skipped = 0; foreach ($lines as $line) { $parts = array_map('trim', explode(',', $line, 2)); try { email_address_save($pdo, 0, ['email' => $parts[0] ?? '', 'label' => $parts[1] ?? '', 'department_id' => $deptId, 'priority_id' => $prioId]); $added++; } catch (EmailAddressException $e) { $skipped++; } } audit_log($admin['id'], "E-Mail-Adressen Massen-Import: $added hinzugefügt, $skipped übersprungen"); flash('success', "$added Adresse(n) hinzugefügt, $skipped übersprungen (ungültig oder bereits vorhanden)."); redirect('/staff/email_addresses.php'); } } } // --- Anzeige: Formular (neu/bearbeiten) oder Liste --------------------------------------- $isNew = isset($_GET['new']); $editId = (int) ($_GET['edit'] ?? 0); $showForm = $isNew || $editId || ($errors && in_array($_POST['action'] ?? '', ['create', 'update'], true)); $editAddress = null; $editImap = null; if ($editId) { $stmt = $pdo->prepare('SELECT * FROM email_addresses WHERE id = ?'); $stmt->execute([$editId]); $editAddress = $stmt->fetch() ?: null; if ($editAddress) $editImap = email_address_imap($pdo, $editId); } $f = fn(string $k, $default = '') => $_POST[$k] ?? $default; $tab = in_array($_GET['tab'] ?? '', ['imap', 'smtp'], true) ? $_GET['tab'] : 'account'; if ($errors && !empty($_POST['smtp_enabled'])) $tab = 'smtp'; elseif ($errors && !empty($_POST['imap_enabled'])) $tab = 'imap'; $addresses = $pdo->query( 'SELECT ea.*, d.name AS department_name, p.name AS priority_name, (SELECT COUNT(*) FROM imap_accounts ia WHERE ia.email_address_id = ea.id AND ia.is_active = 1) AS imap_active FROM email_addresses ea JOIN departments d ON d.id = ea.department_id LEFT JOIN priorities p ON p.id = ea.priority_id ORDER BY d.name, ea.email' )->fetchAll(); $fmt = fn(?string $dt) => $dt ? date('d.m.Y H:i', strtotime($dt)) : '–'; $pageTitle = 'E-Mail-Adressen'; $activePage = 'email_addresses'; require __DIR__ . '/_header.php'; ?>
Tests verwenden die gespeicherten Werte.
Eine Adresse = Abteilung + Priorität + Hilfethema + (optional) Postfach zum Abruf und eigener SMTP-Server. DeskHub wertet beim Abruf den „An:“- und „CC:“-Header aus und legt das Ticket in der passenden Abteilung ab. Ist keine Adresse passend, greift die Standardabteilung aus den Einstellungen.
| E-Mail-Adresse | Anzeigename | Status | Abteilung | Priorität | Abruf | Eigener SMTP | Zuletzt aktualisiert | |
|---|---|---|---|---|---|---|---|---|
| = e($a['email']) ?>= $a['is_default'] ? ' (Standard)' : '' ?> | = e($a['label'] ?: '–') ?> | = ($a['is_active'] ?? 1) ? 'Aktiv' : 'Deaktiviert' ?> | = e($a['department_name']) ?> | = e($a['priority_name'] ?? 'Systemstandard') ?> | = $a['imap_active'] ? '✓' : '–' ?> | = !empty($a['smtp_enabled']) ? '✓' : '–' ?> | = e($fmt($a['updated_at'] ?? null)) ?> | Bearbeiten · |
| Noch keine E-Mail-Adressen angelegt. | ||||||||
Eine Adresse pro Zeile, optional mit Anzeigename nach einem Komma (z. B. technik@firma.de, Technik-Support).