4 Commits
1.1 ... main

Author SHA1 Message Date
315c477cad wp-multi-ticket.php aktualisiert 2026-01-07 12:55:36 +00:00
cc126b792f wp-multi-ticket.php aktualisiert 2026-01-07 12:53:06 +00:00
520426dda2 wp-multi-ticket.php aktualisiert 2026-01-06 14:53:14 +00:00
4486306d7f README.md aktualisiert 2026-01-02 21:31:38 +00:00
2 changed files with 589 additions and 26 deletions

112
README.md
View File

@@ -1,2 +1,112 @@
# wp-multi-ticket
# WP Multi Ticket Pro 🚀
Ein leistungsstarkes und einfaches Ticket- und Support-System für WordPress.
Es ermöglicht Gästen (ohne Login), Tickets zu erstellen, und bietet Administratoren ein umfassendes Dashboard zur Verwaltung, Analyse und Kommunikation.
---
## ✨ Features
- **Gast-Tickets:** Besucher können Tickets erstellen, ohne sich registrieren zu müssen.
- **Frontend Integration:** Einfache Einbindung über Shortcodes auf beliebigen Seiten.
- **Intelligente Benachrichtigungen:**
- E-Mail-Benachrichtigungen an Admins und Kunden
- Discord & Telegram Integration für Echtzeit-Alerts
- **Analytics Dashboard:** Visuelle Auswertung (Charts) von Ticket-Statistiken, Arbeitslast und Statusverteilung direkt im Admin-Bereich
- **Ticket-Management:**
- Status- und Prioritätsverwaltung
- Zuweisung an spezifische Abteilungen oder Mitarbeiter
- Interne Notizen (für Mitarbeiter) vs. öffentliche Antworten
- **CSV-Export:** Exportieren Sie alle Tickets zur externen Analyse
- **Textbausteine:** Erstellen Sie Vorlagen für schnelle Antworten
- **Datei-Uploads:** Kunden und Admins können Dateien an Tickets anhängen
- **Auto-Updates:** Das Plugin prüft automatisch auf Updates (über Gitea)
---
## 📦 Installation
1. Laden Sie das Plugin-Verzeichnis (`wp-multi-ticket`) in den `/wp-content/plugins/` Ordner Ihrer WordPress-Installation hoch, oder installieren Sie es direkt über das WordPress Plugin-Menü ("ZIP hochladen").
2. Aktivieren Sie das Plugin im WordPress "Plugins" Menü.
3. Gehen Sie zu **Einstellungen > Permalinks** und klicken Sie einmal auf "Änderungen speichern", um sicherzustellen, dass die Links funktionieren.
---
## 🚀 Nutzung (Shortcodes)
### Ticket erstellen
Fügen Sie diesen Shortcode auf einer Seite ein (z.B. "Support"), wo Kunden neue Tickets eröffnen sollen:
```text
[wmt_form]
```
### Ticket-Status suchen
Fügen Sie diesen Shortcode ein, damit Kunden ihre offenen Tickets über ihre E-Mail-Adresse finden können:
```text
[wmt_lookup]
```
### Ticket-Ansicht
Dieser Shortcode ist meist nicht nötig manuell einzufügen, da Kunden automatisch per E-Mail-Link zu ihrer Ticket-Ansicht weitergeleitet werden:
```text
[wmt_view]
```
---
## ⚙️ Konfiguration
Nach der Installation finden Sie im WordPress-Menü den Punkt **"Tickets Pro"**.
### 1. Einstellungen
Hier passen Sie das System an Ihre Bedürfnisse an:
- **Kategorien & Abteilungen:** Definieren Sie Themenbereiche und weisen Sie sie Abteilungen zu.
- **Status & Prioritäten:** Legen Sie fest, welche Stati (z.B. *Offen*, *In Bearbeitung*) und Prioritäten verfügbar sind.
- **Textbausteine:** Erstellen Sie Vorlagen für häufige Antworten (öffentlich oder intern).
- **Datei-Uploads:** Legen Sie fest, welche Dateitypen (z.B. pdf, jpg) erlaubt sind.
### 2. Benachrichtigungen
Verbinden Sie Ihre Favoriten-Apps, um nie ein Ticket zu verpassen:
- **Discord Webhook URL:** Fügen Sie Ihre Discord-Webhook-URL für Push-Nachrichten in einen Channel ein.
- **Telegram Bot:** Token und Chat ID eingeben für Telegram-Benachrichtigungen.
- **Zusätzliche User:** Wählen Sie spezifische WordPress-Benutzer aus, die bei jedem neuen Ticket per E-Mail benachrichtigt werden sollen.
### 3. Analytics
Unter dem Menüpunkt **Analytics** sehen Sie Diagramme zu:
- Gesamtanzahl der Tickets
- Offene vs. geschlossene Tickets
- Tickets der letzten 30 Tage
- Workload pro Mitarbeiter (Agent Performance)
---
## 📄 Admin-Funktionen
Im Dashboard finden Sie eine Übersicht offener Tickets.
- **Antworten:** Nutzen Sie den WordPress Editor für formatierte Antworten.
- **Interne Notizen:** Schreiben Notizen, die nur für andere Admins sichtbar sind.
- **Drucken:** Erstellen Sie ein sauberes PDF/Print-Layout eines Tickets für Akten.
- **Export:** Nutzen Sie den *CSV Export* Button oben in der Liste, um Daten zu sichern.
---
## 🔄 Updates
Das Plugin enthält einen eingebauten **Update-Checker**.
Sollte eine neue Version auf **Gitea** veröffentlicht werden, sehen Sie oben im Admin-Bereich eine Hinweismeldung mit einem Download-Link.
---
## 🆘 Support
Bei Fragen oder Problemen kontaktieren Sie bitte:
- **Telegram Support:** [t.me/M_Viper04](https://t.me/M_Viper04)
- **Web:** [m-viper.de](https://m-viper.de)

View File

@@ -3,7 +3,7 @@
* Plugin Name: WP Multi Ticket Pro
* Plugin URI: https://git.viper.ipv64.net/M_Viper/wp-multi-ticket
* Description: Leistungsstarkes Ticket- und Support-System für WordPress mit Gast-Tickets, Admin-Antworten, CSV-Export, Dashboard-Widgets und integriertem Update-Management über Gitea.
* Version: 1.1
* Version: 1.3
* Author: M_Viper
* Author URI: https://m-viper.de
* Requires at least: 6.7.2
@@ -17,8 +17,6 @@
* Support: https://t.me/M_Viper04
*/
if ( ! defined( 'ABSPATH' ) ) exit;
class WP_Multi_Ticket_Pro {
@@ -47,6 +45,11 @@ class WP_Multi_Ticket_Pro {
// Hook für Update-Benachrichtigung
add_action( 'admin_notices', array( $this, 'check_plugin_updates' ) );
// E-Mail-Konfiguration
add_action( 'phpmailer_init', array( $this, 'configure_phpmailer' ) );
add_filter( 'wp_mail_from', array( $this, 'custom_wp_mail_from' ) );
add_filter( 'wp_mail_from_name', array( $this, 'custom_wp_mail_from_name' ) );
add_shortcode( 'wmt_form', array( $this, 'render_creation_form' ) );
add_shortcode( 'wmt_view', array( $this, 'render_ticket_view' ) );
add_shortcode( 'wmt_lookup', array( $this, 'render_lookup_form' ) );
@@ -60,7 +63,179 @@ class WP_Multi_Ticket_Pro {
add_action( 'admin_init', array( $this, 'handle_csv_export' ) );
}
/**
/**
* Hilfsfunktion: Letzte Fehlermeldung aus dem Log holen
*/
private function get_last_error_log_entry() {
$log_file = WP_CONTENT_DIR . '/debug.log';
if ( ! file_exists( $log_file ) || ! is_readable( $log_file ) ) return null;
// Letzte 5KB der Datei lesen
$lines = array_reverse( file( $log_file ) );
foreach ( $lines as $line ) {
// Nach SMTP Debug Zeilen suchen
if ( strpos( $line, 'SMTP Debug' ) !== false ) {
return esc_html( trim( $line ) );
}
// Nach PHP Fatal Warnings suchen
if ( strpos( $line, 'Fatal error' ) !== false ) {
return esc_html( trim( $line ) );
}
}
return null;
}
/**
* FIX: Verbesserte Konfiguration für PHPMailer
*/
public function configure_phpmailer( $phpmailer ) {
$smtp_enabled = get_option( 'wmt_smtp_enabled' );
if ( $smtp_enabled == '1' || $smtp_enabled === true ) {
$encryption = get_option( 'wmt_smtp_encryption', '' );
// Prüfen, ob OpenSSL geladen ist
if ( ( $encryption === 'tls' || $encryption === 'ssl' ) && ! extension_loaded('openssl') ) {
error_log('WMT SMTP Error: OpenSSL extension missing.');
// Setzen einer Error-Info, die manuell abgerufen werden kann
global $wmt_last_smtp_error;
$wmt_last_smtp_error = "FATAL: PHP OpenSSL Extension fehlt. Bitte kontaktieren Sie Ihren Webhoster.";
return;
}
$phpmailer->isSMTP();
$phpmailer->Host = get_option( 'wmt_smtp_host', 'localhost' );
$phpmailer->Port = get_option( 'wmt_smtp_port', 25 );
// SSL/TLS korrekt setzen
if ( $encryption === 'tls' ) {
$phpmailer->SMTPSecure = 'tls';
} elseif ( $encryption === 'ssl' ) {
$phpmailer->SMTPSecure = 'ssl';
} else {
$phpmailer->SMTPSecure = '';
}
$smtp_auth = get_option( 'wmt_smtp_auth' );
$phpmailer->SMTPAuth = ( $smtp_auth == '1' || $smtp_auth === true );
if ( $phpmailer->SMTPAuth ) {
$phpmailer->Username = get_option( 'wmt_smtp_username', '' );
$phpmailer->Password = get_option( 'wmt_smtp_password', '' );
// WICHTIG: Envelope Sender setzen
$phpmailer->Sender = $phpmailer->Username;
}
if ( get_option( 'wmt_smtp_debug', false ) ) {
$phpmailer->SMTPDebug = 3; // Client + Server
$phpmailer->Debugoutput = function($str, $level) {
error_log("WMT SMTP: $str");
};
}
}
$phpmailer->CharSet = 'UTF-8';
}
/**
* Setzt die Absender-E-Mail
*/
public function custom_wp_mail_from( $original_email_address ) {
$custom_email = get_option( 'wmt_from_email', '' );
return $custom_email ? $custom_email : $original_email_address;
}
/**
* Setzt den Absender-Namen
*/
public function custom_wp_mail_from_name( $original_email_from ) {
$custom_name = get_option( 'wmt_from_name', '' );
return $custom_name ? $custom_name : $original_email_from;
}
/**
* Verbesserte E-Mail-Versand-Funktion mit Logging
*/
private function send_mail( $to, $subject, $message, $attachments = array() ) {
$html_message = '
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; background-color: #f4f4f4; margin: 0; padding: 20px; }
.container { max-width: 600px; margin: 0 auto; background: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.header { background: #0073aa; color: white; padding: 20px; text-align: center; border-radius: 8px 8px 0 0; margin: -20px -20px 20px -20px; }
.header h2 { margin: 0; color: white; }
.content { padding: 0 10px; }
.footer { text-align: center; padding: 20px; font-size: 12px; color: #666; border-top: 1px solid #eee; margin-top: 20px; }
.button { background: #0073aa; color: white; padding: 12px 24px; text-decoration: none; border-radius: 4px; display: inline-block; margin: 10px 0; font-weight: bold; }
.button:hover { background: #005177; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h2>' . get_bloginfo('name') . ' Support</h2>
</div>
<div class="content">
' . wpautop( $message ) . '
</div>
<div class="footer">
<p>Diese E-Mail wurde automatisch vom Support-System generiert.</p>
<p><a href="' . home_url() . '">' . get_bloginfo('name') . '</a></p>
</div>
</div>
</body>
</html>';
$headers = array(
'Content-Type: text/html; charset=UTF-8',
);
if ( get_option( 'wmt_bcc_admin', false ) ) {
$admin_email = get_option( 'wmt_admin_email', get_option('admin_email') );
$headers[] = 'Bcc: ' . $admin_email;
}
$result = wp_mail( $to, $subject, $html_message, $headers, $attachments );
// Logging für Debugging
if ( get_option( 'wmt_mail_logging', true ) ) {
$error_msg = 'Mail delivery failed';
// Wenn es fehlschlägt, versuchen wir den letzten Fehler aus dem Log zu holen für mehr Details
if ( ! $result ) {
$log_entry = $this->get_last_error_log_entry();
if ( $log_entry ) {
$error_msg .= " (Server Log: " . $log_entry . ")";
}
}
$logs = get_option( 'wmt_mail_logs', array() );
array_unshift( $logs, array(
'timestamp' => current_time( 'mysql' ),
'to' => $to,
'subject' => $subject,
'success' => $result ? 'YES' : 'NO',
'error' => $result ? '' : $error_msg
));
// Nur letzte 50 behalten
$logs = array_slice( $logs, 0, 50 );
update_option( 'wmt_mail_logs', $logs );
}
if ( ! $result ) {
error_log( 'WMT Mail Error: Failed to send email to ' . $to . ' - Subject: ' . $subject );
}
return $result;
}
/**
* Prüft auf Updates von der Git-URL und zeigt eine Admin-Notice an
*/
public function check_plugin_updates() {
@@ -149,9 +324,7 @@ class WP_Multi_Ticket_Pro {
}
// *** HIER: korrigierter Hook-Name für die Analytics-Unterseite ***
public function load_analytics_scripts( $hook ) {
// Für Submenu: parent slug wmt_tickets -> Hook: wmt-tickets_page_wmt_analytics
if ( 'wmt-tickets_page_wmt_analytics' !== $hook ) return;
$local_js = plugin_dir_path( __FILE__ ) . 'chart.js';
@@ -163,9 +336,16 @@ class WP_Multi_Ticket_Pro {
}
public function enqueue_styles() {
$custom_font_color = get_option( 'wmt_font_color', '#6b7280' );
?>
<style>
.wmt-box { max-width: 800px; margin: 20px auto; background: #fff; padding: 25px; border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.08); font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif; }
.wmt-box { max-width: 800px; margin: 20px auto; background: #fff; padding: 25px; border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.08); font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif; color: <?php echo esc_attr($custom_font_color); ?>; }
.wmt-box h1, .wmt-box h2, .wmt-box h3 {
color: <?php echo esc_attr($custom_font_color); ?>;
}
.wmt-btn { background: #0073aa; color: #fff; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; font-size: 14px; text-decoration: none; display: inline-block; line-height: 1.4; }
.wmt-btn:hover { background: #005177; }
.wmt-btn.danger { background: #dc3545; }
@@ -182,8 +362,9 @@ class WP_Multi_Ticket_Pro {
.wmt-system-msg { text-align: center; margin: 20px 0; font-size: 12px; color: #666; background: #e9ecef; padding: 5px 10px; border-radius: 20px; display: inline-block; width: 100%; box-sizing: border-box; border: 1px solid #ced4da; }
.wmt-internal-note { background: #eee; border-left: 4px solid #6c757d; padding: 10px; margin-bottom: 10px; font-size: 12px; color: #333; font-style: italic; display: block; }
.wmt-internal-note strong { display: block; font-style: normal; color: #495057; margin-bottom: 3px; }
.wmt-alert { padding: 15px; background: #fff3cd; color: #856404; border: 1px solid #ffeeba; margin-bottom: 20px; border-radius: 4px; }
.wmt-alert { padding: 15px; background: #d4edda; color: #155724; border: 1px solid #c3e6cb; margin-bottom: 20px; border-radius: 4px; }
.wmt-error { padding: 15px; background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; margin-bottom: 20px; border-radius: 4px; }
.wmt-warning { padding: 15px; background: #fff3cd; color: #856404; border: 1px solid #ffeeba; margin-bottom: 20px; border-radius: 4px; }
.wmt-avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: bold; font-size: 14px; margin-right: 10px; flex-shrink: 0; text-transform: uppercase; }
.wmt-msg-row { display: flex; align-items: flex-start; margin-bottom: 15px; }
@@ -230,6 +411,13 @@ class WP_Multi_Ticket_Pro {
.wmt-css-bar-bg { flex-grow: 1; background: #f3f4f6; height: 24px; border-radius: 4px; overflow: hidden; position: relative; }
.wmt-css-bar-fill { height: 100%; background: #3b82f6; display: flex; align-items: center; padding-left: 10px; color: #fff; font-size: 11px; white-space: nowrap; transition: width 0.5s ease; }
.wmt-css-bar-val { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 11px; color: #6c757d; font-weight: bold; }
/* Mail Log Styles */
.wmt-mail-log-table { width: 100%; border-collapse: collapse; margin-top: 20px; }
.wmt-mail-log-table th, .wmt-mail-log-table td { padding: 10px; text-align: left; border-bottom: 1px solid #ddd; }
.wmt-mail-log-table th { background: #f5f5f5; font-weight: bold; }
.wmt-mail-success { color: #155724; font-weight: bold; }
.wmt-mail-failed { color: #721c24; font-weight: bold; }
</style>
<?php
}
@@ -293,6 +481,7 @@ class WP_Multi_Ticket_Pro {
add_submenu_page( 'wmt_tickets', 'Analytics', 'Analytics', 'manage_options', 'wmt_analytics', array( $this, 'render_analytics_page' ) );
add_submenu_page( 'wmt_tickets', 'Einstellungen', 'Einstellungen', 'manage_options', 'wmt_settings', array( $this, 'render_settings_page' ) );
add_submenu_page( 'wmt_tickets', 'Benachrichtigungen', 'Benachrichtigungen', 'manage_options', 'wmt_notifications', array( $this, 'render_notifications_page' ) );
add_submenu_page( 'wmt_tickets', 'E-Mail Einstellungen', 'E-Mail Setup', 'manage_options', 'wmt_mail_settings', array( $this, 'render_mail_settings_page' ) );
}
public function register_settings() {
@@ -303,11 +492,258 @@ class WP_Multi_Ticket_Pro {
register_setting( 'wmt_settings_group', 'wmt_admin_email' );
register_setting( 'wmt_settings_group', 'wmt_templates' );
register_setting( 'wmt_settings_group', 'wmt_allowed_filetypes' );
register_setting( 'wmt_settings_group', 'wmt_font_color' );
register_setting( 'wmt_notifications_group', 'wmt_discord_webhook' );
register_setting( 'wmt_notifications_group', 'wmt_telegram_token' );
register_setting( 'wmt_notifications_group', 'wmt_telegram_chat_id' );
register_setting( 'wmt_notifications_group', 'wmt_new_ticket_notify_users' );
// SMTP Settings
register_setting( 'wmt_mail_settings_group', 'wmt_smtp_enabled' );
register_setting( 'wmt_mail_settings_group', 'wmt_smtp_host' );
register_setting( 'wmt_mail_settings_group', 'wmt_smtp_port' );
register_setting( 'wmt_mail_settings_group', 'wmt_smtp_auth' );
register_setting( 'wmt_mail_settings_group', 'wmt_smtp_username' );
register_setting( 'wmt_mail_settings_group', 'wmt_smtp_password' );
register_setting( 'wmt_mail_settings_group', 'wmt_smtp_encryption' );
register_setting( 'wmt_mail_settings_group', 'wmt_from_email' );
register_setting( 'wmt_mail_settings_group', 'wmt_from_name' );
register_setting( 'wmt_mail_settings_group', 'wmt_bcc_admin' );
register_setting( 'wmt_mail_settings_group', 'wmt_mail_logging' );
register_setting( 'wmt_mail_settings_group', 'wmt_smtp_debug' );
}
public function render_mail_settings_page() {
// Test-Mail senden
if ( isset( $_POST['wmt_send_test_mail'] ) ) {
// Prüfen des Nonce
$nonce_value = isset( $_POST['wmt_test_nonce'] ) ? $_POST['wmt_test_nonce'] : '';
if ( ! wp_verify_nonce( $nonce_value, 'wmt_test_mail' ) ) {
echo '<div class="wmt-error">Sicherheitsfehler beim Senden der Test-E-Mail.</div>';
} else {
$test_email = sanitize_email( $_POST['test_email'] );
// Debug-Modus temporär für Test aktivieren
$orig_debug = get_option('wmt_smtp_debug', false);
if(!$orig_debug) update_option('wmt_smtp_debug', '1');
$result = $this->send_mail(
$test_email,
'Test E-Mail von WP Multi Ticket Pro',
'Wenn Sie diese E-Mail erhalten, funktioniert der E-Mail-Versand korrekt!'
);
// Debug-Modus zurücksetzen
update_option('wmt_smtp_debug', $orig_debug);
if ( $result ) {
echo '<div class="wmt-alert">✓ Test-E-Mail erfolgreich an ' . esc_html($test_email) . ' gesendet!</div>';
} else {
echo '<div class="wmt-error">✗ Test-E-Mail konnte nicht gesendet werden. Prüfen Sie die Tabelle unten für Details.</div>';
}
}
}
// Logs löschen
if ( isset( $_POST['wmt_clear_logs'] ) ) {
// Manuelle Nonce-Prüfung da settings_fields hier nicht verwendet wird
if ( check_admin_referer( 'wmt_clear_logs' ) ) {
delete_option( 'wmt_mail_logs' );
echo '<div class="wmt-alert">Mail-Logs gelöscht.</div>';
}
}
$logs = get_option( 'wmt_mail_logs', array() );
?>
<div class="wrap">
<h1>E-Mail Einstellungen</h1>
<div class="wmt-warning">
<strong>⚠️ Wichtig:</strong> Wenn SMTP nicht funktioniert, prüfen Sie unten die Logs für den genauen Fehler.
</div>
<form method="post" action="options.php">
<?php settings_fields( 'wmt_mail_settings_group' ); ?>
<h2>Grundeinstellungen</h2>
<table class="form-table">
<tr>
<th>Absender E-Mail</th>
<td>
<input type="email" name="wmt_from_email" value="<?php echo esc_attr( get_option('wmt_from_email', get_option('admin_email')) ); ?>" class="regular-text">
<p class="description">Die E-Mail-Adresse, von der Tickets versendet werden.</p>
</td>
</tr>
<tr>
<th>Absender Name</th>
<td>
<input type="text" name="wmt_from_name" value="<?php echo esc_attr( get_option('wmt_from_name', get_bloginfo('name') . ' Support') ); ?>" class="regular-text">
<p class="description">Der Name, der als Absender angezeigt wird.</p>
</td>
</tr>
<tr>
<th>BCC an Admin</th>
<td>
<label>
<input type="checkbox" name="wmt_bcc_admin" value="1" <?php checked( get_option('wmt_bcc_admin'), 1 ); ?>>
Admin erhält BCC-Kopie aller E-Mails
</label>
</td>
</tr>
<tr>
<th>E-Mail Logging</th>
<td>
<label>
<input type="checkbox" name="wmt_mail_logging" value="1" <?php checked( get_option('wmt_mail_logging', 1), 1 ); ?>>
E-Mail-Versand protokollieren (empfohlen für Debugging)
</label>
</td>
</tr>
</table>
<h2>SMTP Einstellungen (empfohlen)</h2>
<table class="form-table">
<tr>
<th>SMTP aktivieren</th>
<td>
<label>
<input type="checkbox" name="wmt_smtp_enabled" value="1" <?php checked( get_option('wmt_smtp_enabled'), 1 ); ?>>
SMTP für E-Mail-Versand verwenden
</label>
<p class="description">Empfohlen für zuverlässigen E-Mail-Versand.</p>
</td>
</tr>
<tr>
<th>SMTP Host</th>
<td>
<input type="text" name="wmt_smtp_host" value="<?php echo esc_attr( get_option('wmt_smtp_host', 'localhost') ); ?>" class="regular-text">
<p class="description">z.B. smtp.gmail.com, smtp.ionos.de, mail.ihr-provider.de</p>
</td>
</tr>
<tr>
<th>SMTP Port</th>
<td>
<input type="number" name="wmt_smtp_port" value="<?php echo esc_attr( get_option('wmt_smtp_port', 587) ); ?>" class="small-text">
<p class="description">Standard: 587 (TLS), 465 (SSL), 25 (keine Verschlüsselung)</p>
</td>
</tr>
<tr>
<th>Verschlüsselung</th>
<td>
<select name="wmt_smtp_encryption">
<option value="">Keine</option>
<option value="tls" <?php selected( get_option('wmt_smtp_encryption'), 'tls' ); ?>>TLS (empfohlen)</option>
<option value="ssl" <?php selected( get_option('wmt_smtp_encryption'), 'ssl' ); ?>>SSL</option>
</select>
</td>
</tr>
<tr>
<th>SMTP Authentifizierung</th>
<td>
<label>
<input type="checkbox" name="wmt_smtp_auth" value="1" <?php checked( get_option('wmt_smtp_auth', 1), 1 ); ?>>
SMTP Authentifizierung verwenden
</label>
</td>
</tr>
<tr>
<th>SMTP Benutzername</th>
<td>
<input type="text" name="wmt_smtp_username" value="<?php echo esc_attr( get_option('wmt_smtp_username') ); ?>" class="regular-text" autocomplete="off">
<p class="description">Meist Ihre E-Mail-Adresse</p>
</td>
</tr>
<tr>
<th>SMTP Passwort</th>
<td>
<input type="password" name="wmt_smtp_password" value="<?php echo esc_attr( get_option('wmt_smtp_password') ); ?>" class="regular-text" autocomplete="new-password">
<p class="description">⚠️ Wird unverschlüsselt in der Datenbank gespeichert!</p>
</td>
</tr>
<tr>
<th>Debug-Modus</th>
<td>
<label>
<input type="checkbox" name="wmt_smtp_debug" value="1" <?php checked( get_option('wmt_smtp_debug'), 1 ); ?>>
SMTP Debug aktivieren (schreibt Logs für jeden Versand)
</label>
<p class="description">Wichtig für den Test! Wird nach dem Test automatisch wieder ausgeschaltet.</p>
</td>
</tr>
</table>
<?php submit_button( 'Einstellungen speichern' ); ?>
</form>
<hr>
<h2>Test-E-Mail senden</h2>
<form method="post">
<input type="hidden" id="wmt_test_nonce" name="wmt_test_nonce" value="<?php echo wp_create_nonce('wmt_test_mail'); ?>" />
<table class="form-table">
<tr>
<th>Test-E-Mail an</th>
<td>
<input type="email" name="test_email" value="<?php echo esc_attr( get_option('wmt_admin_email', get_option('admin_email')) ); ?>" class="regular-text" required>
<button type="submit" name="wmt_send_test_mail" class="button button-primary">Test-Mail senden</button>
</td>
</tr>
</table>
</form>
<?php if ( ! empty( $logs ) ): ?>
<hr>
<h2>E-Mail Logs (letzte 50)</h2>
<form method="post">
<input type="hidden" name="wmt_clear_logs" value="1" />
<?php wp_nonce_field( 'wmt_clear_logs' ); ?>
<button type="submit" name="submit" class="button">Logs löschen</button>
</form>
<table class="wmt-mail-log-table">
<thead>
<tr>
<th>Zeit</th>
<th>Empfänger</th>
<th>Betreff</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php foreach ( $logs as $log ): ?>
<tr>
<td><?php echo esc_html( $log['timestamp'] ); ?></td>
<td><?php echo esc_html( $log['to'] ); ?></td>
<td><?php echo esc_html( $log['subject'] ); ?></td>
<td class="<?php echo $log['success'] === 'YES' ? 'wmt-mail-success' : 'wmt-mail-failed'; ?>">
<?php echo $log['success'] === 'YES' ? '✓ Gesendet' : '✗ Fehler'; ?>
<?php if ( ! empty( $log['error'] ) ): ?>
<div style="font-size: 11px; margin-top: 5px; color: #d63638; word-break: break-all; background: #f9f9f9; padding: 5px; border: 1px solid #eee; max-width: 500px;">
<strong>Server-Fehler:</strong><br>
<?php echo esc_html( $log['error'] ); ?>
</div>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<hr>
<h2>Häufige Probleme & Lösungen</h2>
<div style="background: #f9f9f9; padding: 20px; border-left: 4px solid #0073aa; margin-top: 20px;">
<h3>E-Mails kommen nicht an?</h3>
<ol>
<li><strong>Prüfen Sie das Log:</strong> Wenn die Test-Mail fehlschlägt, steht der genaue Fehler oben in der Tabelle unter "Server-Fehler".</li>
<li><strong>Gmail Nutzer:</strong> Verwenden Sie ein <strong>App-Passwort</strong>, nicht Ihr normales Passwort. Port 587 + TLS.</li>
<li><strong>OpenSSL Fehler:</strong> Wenn im Log steht "OpenSSL extension missing", kontaktieren Sie Ihren Hoster.</li>
<li><strong>Firewall:</strong> Manche Hoster blockieren Port 25 und 587.</li>
</ol>
</div>
</div>
<?php
}
public function render_analytics_page() {
@@ -404,12 +840,10 @@ class WP_Multi_Ticket_Pro {
</div>
</div>
<!-- Chart.js Fallback CDN (für 100% Funktionalität) -->
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
<script type="text/javascript">
// Warten, bis Dokument und Skripte geladen sind
document.addEventListener('DOMContentLoaded', function() {
const statusLabels = <?php echo json_encode(array_column($status_data, 'status'), JSON_UNESCAPED_UNICODE); ?>;
@@ -421,7 +855,6 @@ class WP_Multi_Ticket_Pro {
const timeLabels = <?php echo json_encode(array_column($timeline_data, 'date'), JSON_UNESCAPED_UNICODE); ?>;
const timeCounts = <?php echo json_encode(array_column($timeline_data, 'count'), JSON_UNESCAPED_UNICODE); ?>;
// DEBUG: Ausgabe des Pfades in der Browser-Konsole (F12)
const localUrl = "<?php echo plugins_url( 'chart.js', __FILE__ ); ?>";
console.log("WMT DEBUG: Suche nach Chart.js auf: " + localUrl);
@@ -575,7 +1008,7 @@ class WP_Multi_Ticket_Pro {
}
public function render_settings_page() {
$templates = get_option( 'wmt_templates', array() ); // FIX: Corrected array()
$templates = get_option( 'wmt_templates', array() );
if ( is_string($templates) ) $templates = array();
?>
<div class="wrap">
@@ -589,6 +1022,14 @@ class WP_Multi_Ticket_Pro {
<tr><th>Status</th><td><input type="text" name="wmt_statuses" value="<?php echo esc_attr( get_option('wmt_statuses', 'Offen, In Bearbeitung, Wartet auf Antwort, Geschlossen') ); ?>" class="regular-text"></td></tr>
<tr><th>Admin E-Mail</th><td><input type="email" name="wmt_admin_email" value="<?php echo esc_attr( get_option('wmt_admin_email', get_option('admin_email') ) ); ?>" class="regular-text"></td></tr>
<tr><th>Erlaubte Dateiendungen</th><td><input type="text" name="wmt_allowed_filetypes" value="<?php echo esc_attr( get_option('wmt_allowed_filetypes', 'pdf, doc, docx, jpg, jpeg, png, txt') ); ?>" class="regular-text"><p class="description">Kommagetrennt (z.B. pdf, doc, png).</p></td></tr>
<!-- Schriftfarbe Einstellung -->
<tr>
<th>Schriftfarbe</th>
<td>
<input type="color" name="wmt_font_color" value="<?php echo esc_attr( get_option('wmt_font_color', '#6b7280') ); ?>" class="regular-text">
<p class="description">Wählen Sie die Standard-Schriftfarbe für das Ticket-System (inkl. Überschriften).</p>
</td>
</tr>
<tr>
<th>Textbausteine</th>
<td>
@@ -641,7 +1082,7 @@ class WP_Multi_Ticket_Pro {
public function render_notifications_page() {
$all_users = get_users( array( 'orderby' => 'display_name' ) );
$selected_users = get_option( 'wmt_new_ticket_notify_users', array() ); // FIX: Corrected array()
$selected_users = get_option( 'wmt_new_ticket_notify_users', array() );
if ( ! is_array( $selected_users ) ) $selected_users = array();
?>
<div class="wrap">
@@ -1117,7 +1558,6 @@ class WP_Multi_Ticket_Pro {
$tid = intval( $_POST['ticket_id'] );
// STATUS LOGIK:
// Wenn nicht "Geschlossen" gewählt wurde, setzen wir es auf "In Bearbeitung"
$status = sanitize_text_field( $_POST['status'] );
if ( strtolower( $status ) !== 'geschlossen' ) {
$status = 'In Bearbeitung';
@@ -1129,9 +1569,7 @@ class WP_Multi_Ticket_Pro {
$assigned = !empty($_POST['assigned_to']) ? intval( $_POST['assigned_to'] ) : null;
// Auto-Detection Logik
// Wenn im Dropdown "Niemand" ausgewählt ist (NULL), ABER der User gerade antwortet...
if ( empty($assigned) && (!empty($msg_content) || !empty($_FILES['ticket_file']['name'])) ) {
// ...dann weisen wir es dem aktuellen User zu.
$assigned = get_current_user_id();
}
@@ -1153,13 +1591,15 @@ class WP_Multi_Ticket_Pro {
));
}
// Handover Benachrichtigung: Wenn sich der zugewiesene User ändert
// Handover Benachrichtigung
if ( $old_ticket->assigned_to != $assigned && $assigned ) {
$user = get_userdata( $assigned );
if ( $user ) {
$subject = "Ticket #{$tid} wurde Ihnen zugewiesen";
$body = "Hallo {$user->display_name},\n\nDas Ticket #{$tid} „{$old_ticket->title}“ wurde Ihnen zur Bearbeitung zugewiesen.\n\nLink: " . admin_url( "admin.php?page=wmt_tickets&action=edit&id={$tid}" );
wp_mail( $user->user_email, $subject, $body );
// HIER: Sendet HTML E-Mail mit Template
$this->send_mail( $user->user_email, $subject, $body );
}
}
@@ -1174,7 +1614,9 @@ class WP_Multi_Ticket_Pro {
$subject = "Neue Antwort zu Ihrem Ticket #{$tid}";
$body = "Hallo {$old_ticket->guest_name},\n\nEs gibt eine neue Antwort:\n{$msg_content}\n\nLink zum Ticket:\n{$view_link}";
if($file_url) $body .= "\n\nAnhang: {$file_url}";
wp_mail( $old_ticket->guest_email, $subject, $body );
// HIER: Sendet HTML E-Mail mit Template
$this->send_mail( $old_ticket->guest_email, $subject, $body );
} elseif ( ! empty( $internal_note ) ) {
$current_user = wp_get_current_user();
@@ -1366,24 +1808,31 @@ class WP_Multi_Ticket_Pro {
$guest_link = add_query_arg( array( 'wmt_view' => $tid, 'hash' => $hash ), home_url() );
$admin_email = get_option( 'wmt_admin_email', get_option('admin_email') );
wp_mail( $admin_email, "Neues Ticket #{$tid}: {$title}", "Von: {$name} ({$email})\nLink: {$admin_link}" );
// Admin Benachrichtigung (HTML)
$admin_body = "Ein neues Ticket wurde erstellt.\n\nBetreff: {$title}\nVon: {$name} ({$email})\nPriorität: {$prio}\n\nLink: {$admin_link}";
$this->send_mail( $admin_email, "Neues Ticket #{$tid}: {$title}", $admin_body );
$this->send_discord_notification( "Neues Ticket #{$tid}", "{$title}\nVon: {$name} ({$email})\nPriorität: {$prio}", $admin_link );
$this->send_telegram_notification( "<b>Neues Ticket #{$tid}</b>\n<b>Betreff:</b> {$title}\n<b>Von:</b> {$name} ({$email})\n<b>Priorität:</b> {$prio}\nLink: {$admin_link}" );
$notify_user_ids = get_option( 'wmt_new_ticket_notify_users', array() ); // FIX: Corrected array()
$notify_user_ids = get_option( 'wmt_new_ticket_notify_users', array() );
if ( is_array( $notify_user_ids ) && ! empty( $notify_user_ids ) ) {
foreach ( $notify_user_ids as $user_id ) {
$user = get_userdata( $user_id );
if ( $user ) {
$subject = "Neues Ticket #{$tid}: {$title}";
$body = "Hallo {$user->display_name},\n\nein neues Ticket wurde erstellt.\n\nBetreff: {$title}\nVon: {$name} ({$email})\nPriorität: {$prio}\n\nLink zum Ticket: {$admin_link}";
wp_mail( $user->user_email, $subject, $body );
// HTML Benachrichtigung an zusätzliche User
$this->send_mail( $user->user_email, $subject, $body );
}
}
}
wp_mail( $email, "Ihr Ticket #{$tid} wurde erstellt", "Hallo {$name},\n\nVielen Dank für Ihr Ticket.\nLink: {$guest_link}" );
// Gast Bestätigung (HTML)
$guest_body = "Hallo {$name},\n\nVielen Dank für Ihr Ticket #{$tid}.\nWir werden uns so schnell wie möglich bei Ihnen melden.\n\nLink zum Ticket:\n{$guest_link}";
$this->send_mail( $email, "Ihr Ticket #{$tid} wurde erstellt", $guest_body );
wp_redirect( add_query_arg( 'wmt_success', '1', wp_get_referer() ) );
exit;
@@ -1407,7 +1856,10 @@ class WP_Multi_Ticket_Pro {
$admin_link = admin_url( "admin.php?page=wmt_tickets&action=edit&id={$tid}" );
$admin_email = get_option( 'wmt_admin_email', get_option('admin_email') );
wp_mail( $admin_email, "Neue Antwort zu Ticket #{$tid}", "Kunde hat geantwortet.\nLink: {$admin_link}" );
// Admin Benachrichtigung über Gast Antwort (HTML)
$admin_body = "Der Kunde {$ticket->guest_name} hat auf Ticket #{$tid} geantwortet.\n\nLink: {$admin_link}";
$this->send_mail( $admin_email, "Neue Antwort zu Ticket #{$tid}", $admin_body );
$this->send_discord_notification( "Neue Antwort in Ticket #{$tid}", "Kunde {$ticket->guest_name} hat geantwortet.", $admin_link );
$this->send_telegram_notification( "<b>Neue Antwort in Ticket #{$tid}</b>\nKunde: {$ticket->guest_name}\nLink: {$admin_link}" );
@@ -1428,7 +1880,8 @@ class WP_Multi_Ticket_Pro {
$link = add_query_arg( array( 'wmt_view' => $t->id, 'hash' => $t->ticket_hash ), home_url() );
$body .= "#{$t->id}: {$t->title}\n{$link}\n\n";
}
wp_mail( $email, "Ihre Tickets", $body );
// HTML E-Mail senden
$this->send_mail( $email, "Ihre Tickets", $body );
}
wp_redirect( add_query_arg( 'wmt_lookup_sent', '1', wp_get_referer() ) );
exit;