All checks were successful
Deploy mahnung / deploy (push) Successful in 14s
Umlaute in allen lang-Dateien korrigiert. Alle hardcodierten deutschen Strings
in 22 PHP-Dateien durch $langs->trans('Key') ersetzt. Neue Schlüssel für
Cron-Meldungen, Dokument-Aktionen, Bonität, Vorschlag-Status, Template-Vars u.a.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
320 lines
13 KiB
PHP
320 lines
13 KiB
PHP
<?php
|
|
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*/
|
|
|
|
/**
|
|
* \file mahnung/admin/tracking_patterns.php
|
|
* \ingroup mahnung
|
|
* \brief Konfigurations-Seite für Tracking-Pattern (Regex + URL-Template).
|
|
* Live-Vorschau via /custom/mahnung/ajax/regex_preview.php.
|
|
*/
|
|
|
|
$res = 0;
|
|
if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
|
|
$res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
|
|
}
|
|
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
|
|
$tmp2 = realpath(__FILE__);
|
|
$i = strlen($tmp) - 1;
|
|
$j = strlen($tmp2) - 1;
|
|
while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
|
|
$i--;
|
|
$j--;
|
|
}
|
|
if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
|
|
$res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
|
|
}
|
|
if (!$res && file_exists("../../main.inc.php")) {
|
|
$res = @include "../../main.inc.php";
|
|
}
|
|
if (!$res && file_exists("../../../main.inc.php")) {
|
|
$res = @include "../../../main.inc.php";
|
|
}
|
|
if (!$res) {
|
|
die("Include of main fails");
|
|
}
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/custom/mahnung/class/mahnungtrackingpattern.class.php';
|
|
|
|
global $langs, $user, $db;
|
|
$langs->loadLangs(array('admin', 'mahnung@mahnung'));
|
|
|
|
if (!$user->admin && !$user->hasRight('mahnung', 'setup')) {
|
|
accessforbidden();
|
|
}
|
|
|
|
$action = GETPOST('action', 'aZ09');
|
|
$rowid = GETPOSTINT('rowid');
|
|
|
|
// POST: Speichern (Neu oder Update)
|
|
if (($action === 'save_new' || $action === 'save_edit') && $user->hasRight('mahnung', 'setup')) {
|
|
$p = new MahnungTrackingPattern($db);
|
|
if ($action === 'save_edit' && $rowid > 0) {
|
|
if ($p->fetch($rowid) <= 0) {
|
|
setEventMessages($langs->trans('MahnungPatternNichtGefunden'), null, 'errors');
|
|
header('Location: '.$_SERVER['PHP_SELF']);
|
|
exit;
|
|
}
|
|
}
|
|
$p->provider = trim(GETPOST('provider', 'aZ09'));
|
|
$p->label = trim(GETPOST('label', 'alphanohtml'));
|
|
$p->regex = (string) GETPOST('regex', 'nohtml'); // Regex kann Sonderzeichen enthalten
|
|
$p->url_template = trim(GETPOST('url_template', 'alphanohtml'));
|
|
$p->priority = GETPOSTINT('priority');
|
|
if ($p->priority <= 0) {
|
|
$p->priority = 100;
|
|
}
|
|
$p->active = GETPOST('active', 'int') ? 1 : 0;
|
|
|
|
// Basis-Validierung
|
|
$errors = array();
|
|
if ($p->provider === '') {
|
|
$errors[] = $langs->trans('MahnungTrackingPatternProviderRequired');
|
|
}
|
|
if ($p->label === '') {
|
|
$errors[] = $langs->trans('MahnungTrackingPatternLabelRequired');
|
|
}
|
|
if (!MahnungTrackingPattern::isValidRegex($p->regex)) {
|
|
$errors[] = $langs->trans('MahnungTrackingPatternRegexInvalid');
|
|
}
|
|
if (strpos($p->url_template, 'https://') !== 0) {
|
|
$errors[] = $langs->trans('MahnungTrackingPatternUrlMustHttps');
|
|
}
|
|
if (strpos($p->url_template, '{nr}') === false) {
|
|
$errors[] = $langs->trans('MahnungTrackingPatternUrlMissingPlaceholder');
|
|
}
|
|
if (!empty($errors)) {
|
|
setEventMessages('', $errors, 'errors');
|
|
} else {
|
|
$ret = ($action === 'save_new') ? $p->create() : $p->update();
|
|
if ($ret > 0) {
|
|
setEventMessages($langs->trans('MahnungTrackingPatternSaved'), null, 'mesgs');
|
|
header('Location: '.$_SERVER['PHP_SELF']);
|
|
exit;
|
|
} else {
|
|
setEventMessages($p->error ?: $langs->trans('MahnungSpeichernFehlgeschlagen'), null, 'errors');
|
|
}
|
|
}
|
|
}
|
|
|
|
// POST/GET: Löschen
|
|
if ($action === 'delete' && $rowid > 0 && $user->hasRight('mahnung', 'setup')) {
|
|
$p = new MahnungTrackingPattern($db);
|
|
if ($p->fetch($rowid) > 0 && $p->delete() > 0) {
|
|
setEventMessages($langs->trans('MahnungTrackingPatternDeleted'), null, 'mesgs');
|
|
}
|
|
header('Location: '.$_SERVER['PHP_SELF']);
|
|
exit;
|
|
}
|
|
|
|
// Toggle active
|
|
if ($action === 'toggle_active' && $rowid > 0 && $user->hasRight('mahnung', 'setup')) {
|
|
$p = new MahnungTrackingPattern($db);
|
|
if ($p->fetch($rowid) > 0) {
|
|
$p->active = $p->active ? 0 : 1;
|
|
$p->update();
|
|
}
|
|
header('Location: '.$_SERVER['PHP_SELF']);
|
|
exit;
|
|
}
|
|
|
|
llxHeader('', $langs->trans('MahnungTrackingPatternsSetup'));
|
|
|
|
print load_fiche_titre($langs->trans('MahnungTrackingPatternsSetup'), '<a class="butAction" href="'.DOL_URL_ROOT.'/custom/mahnung/admin/setup.php">'.dol_escape_htmltag($langs->trans('Back')).'</a>', 'fa-route');
|
|
|
|
print '<div class="opacitymedium" style="margin-bottom:12px;">'.$langs->trans('MahnungTrackingPatternsIntro').'</div>';
|
|
|
|
$service = new MahnungTrackingPattern($db);
|
|
$all = $service->fetchAll(false);
|
|
|
|
// Edit-Modus laden
|
|
$editP = null;
|
|
if ($action === 'edit' && $rowid > 0) {
|
|
$tmp = new MahnungTrackingPattern($db);
|
|
if ($tmp->fetch($rowid) > 0) {
|
|
$editP = $tmp;
|
|
}
|
|
}
|
|
|
|
// Liste der bestehenden Patterns
|
|
print '<table class="noborder centpercent">';
|
|
print '<tr class="liste_titre">';
|
|
print '<th>'.$langs->trans('MahnungTrackingPatternLabel').'</th>';
|
|
print '<th>'.$langs->trans('MahnungTrackingPatternProvider').'</th>';
|
|
print '<th>'.$langs->trans('MahnungTrackingPatternRegex').'</th>';
|
|
print '<th>'.$langs->trans('MahnungTrackingPatternUrlTemplate').'</th>';
|
|
print '<th class="center">'.$langs->trans('MahnungTrackingPatternPriority').'</th>';
|
|
print '<th class="center">'.$langs->trans('Status').'</th>';
|
|
print '<th></th>';
|
|
print '</tr>';
|
|
if (empty($all)) {
|
|
print '<tr><td colspan="7" class="opacitymedium center">'.$langs->trans('MahnungTrackingPatternsEmpty').'</td></tr>';
|
|
}
|
|
foreach ($all as $p) {
|
|
print '<tr class="oddeven">';
|
|
print '<td>'.dol_escape_htmltag($p['label']).'</td>';
|
|
print '<td>'.dol_escape_htmltag($p['provider']).'</td>';
|
|
print '<td><code>'.dol_escape_htmltag($p['regex']).'</code></td>';
|
|
print '<td><span class="opacitymedium small">'.dol_escape_htmltag($p['url_template']).'</span></td>';
|
|
print '<td class="center">'.((int) $p['priority']).'</td>';
|
|
print '<td class="center">';
|
|
$toggleLabel = $p['active'] ? $langs->trans('Active') : $langs->trans('Disabled');
|
|
$toggleColor = $p['active'] ? 'badge-status4' : 'badge-status8';
|
|
print '<a class="badge '.$toggleColor.'" href="'.$_SERVER['PHP_SELF'].'?action=toggle_active&rowid='.((int) $p['rowid']).'&token='.newToken().'">'.dol_escape_htmltag($toggleLabel).'</a>';
|
|
print '</td>';
|
|
print '<td class="right nowrap">';
|
|
print '<a href="'.$_SERVER['PHP_SELF'].'?action=edit&rowid='.((int) $p['rowid']).'#editform">'.img_picto($langs->trans('Edit'), 'edit').'</a> ';
|
|
print '<a href="'.$_SERVER['PHP_SELF'].'?action=delete&rowid='.((int) $p['rowid']).'&token='.newToken().'" onclick="return confirm(\''.dol_escape_js($langs->trans('ConfirmDelete')).'\');">'.img_picto($langs->trans('Delete'), 'delete').'</a>';
|
|
print '</td>';
|
|
print '</tr>';
|
|
}
|
|
print '</table>';
|
|
|
|
// Formular: Neu / Edit
|
|
$isEdit = ($editP !== null);
|
|
$formAction = $isEdit ? 'save_edit' : 'save_new';
|
|
$valProv = $editP ? $editP->provider : '';
|
|
$valLabel = $editP ? $editP->label : '';
|
|
$valRegex = $editP ? $editP->regex : '/\\b(\\d{14})\\b/';
|
|
$valUrl = $editP ? $editP->url_template : 'https://example.com/track?nr={nr}';
|
|
$valPrio = $editP ? (int) $editP->priority : 100;
|
|
$valActive = $editP ? (int) $editP->active : 1;
|
|
|
|
print '<br><h3 id="editform">'.dol_escape_htmltag($isEdit ? $langs->trans('MahnungTrackingPatternEditTitle') : $langs->trans('MahnungTrackingPatternNewTitle')).'</h3>';
|
|
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" id="patternForm">';
|
|
print '<input type="hidden" name="token" value="'.newToken().'">';
|
|
print '<input type="hidden" name="action" value="'.dol_escape_htmltag($formAction).'">';
|
|
if ($isEdit) {
|
|
print '<input type="hidden" name="rowid" value="'.((int) $editP->id).'">';
|
|
}
|
|
|
|
print '<table class="border centpercent">';
|
|
print '<tr><td class="titlefield">'.$langs->trans('MahnungTrackingPatternLabel').'</td><td>';
|
|
print '<input type="text" name="label" id="pat_label" value="'.dol_escape_htmltag($valLabel).'" size="50" required>';
|
|
print '</td></tr>';
|
|
|
|
print '<tr><td>'.$langs->trans('MahnungTrackingPatternProvider').'</td><td>';
|
|
print '<input type="text" name="provider" id="pat_provider" value="'.dol_escape_htmltag($valProv).'" size="20" required ';
|
|
print 'placeholder="dhl|dpag|dpd|hermes|ups|custom">';
|
|
print '</td></tr>';
|
|
|
|
print '<tr><td>'.$langs->trans('MahnungTrackingPatternRegex').'</td><td>';
|
|
print '<input type="text" name="regex" id="pat_regex" value="'.dol_escape_htmltag($valRegex).'" size="60" required ';
|
|
print 'style="font-family:monospace;">';
|
|
print '<div id="regex_status" class="opacitymedium small" style="margin-top:4px;"> </div>';
|
|
print '</td></tr>';
|
|
|
|
print '<tr><td>'.$langs->trans('MahnungTrackingPatternUrlTemplate').'</td><td>';
|
|
print '<input type="text" name="url_template" id="pat_url" value="'.dol_escape_htmltag($valUrl).'" size="60" required ';
|
|
print 'placeholder="https://...?nr={nr}">';
|
|
print '<div class="opacitymedium small">'.$langs->trans('MahnungTrackingPatternUrlHint').'</div>';
|
|
print '</td></tr>';
|
|
|
|
print '<tr><td>'.$langs->trans('MahnungTrackingPatternPriority').'</td><td>';
|
|
print '<input type="number" name="priority" value="'.((int) $valPrio).'" size="4"> ';
|
|
print '<span class="opacitymedium small">'.$langs->trans('MahnungTrackingPatternPriorityHint').'</span>';
|
|
print '</td></tr>';
|
|
|
|
print '<tr><td>'.$langs->trans('Status').'</td><td>';
|
|
print '<input type="checkbox" name="active" value="1"'.($valActive ? ' checked' : '').'> '.$langs->trans('Active');
|
|
print '</td></tr>';
|
|
|
|
print '<tr><td>'.$langs->trans('MahnungTrackingPatternSample').'</td><td>';
|
|
print '<textarea id="pat_sample" rows="3" style="width:100%; font-family:monospace;" placeholder="'.dol_escape_htmltag($langs->trans('MahnungTrackingPatternSamplePlaceholder')).'"></textarea>';
|
|
print '<div id="pat_preview" class="info" style="margin-top:6px; padding:6px; min-height:20px;"> </div>';
|
|
print '</td></tr>';
|
|
print '</table>';
|
|
|
|
print '<div style="margin-top:8px;">';
|
|
print '<button type="submit" class="button">'.dol_escape_htmltag($langs->trans('Save')).'</button> ';
|
|
if ($isEdit) {
|
|
print '<a class="butActionRefused" href="'.$_SERVER['PHP_SELF'].'">'.dol_escape_htmltag($langs->trans('Cancel')).'</a>';
|
|
}
|
|
print '</div>';
|
|
print '</form>';
|
|
|
|
// Live-Vorschau-JS
|
|
$ajaxUrl = DOL_URL_ROOT.'/custom/mahnung/ajax/regex_preview.php';
|
|
$labelInvalid = dol_escape_js($langs->trans('MahnungTrackingPatternRegexInvalid'));
|
|
$labelValid = dol_escape_js($langs->trans('MahnungTrackingPatternRegexValid'));
|
|
$labelMatch = dol_escape_js($langs->trans('MahnungTrackingPatternMatch'));
|
|
$labelNoMatch = dol_escape_js($langs->trans('MahnungTrackingPatternNoMatch'));
|
|
|
|
print <<<EOT
|
|
<script>
|
|
(function() {
|
|
var regexEl = document.getElementById('pat_regex');
|
|
var urlEl = document.getElementById('pat_url');
|
|
var sampleEl = document.getElementById('pat_sample');
|
|
var statusEl = document.getElementById('regex_status');
|
|
var previewEl = document.getElementById('pat_preview');
|
|
var debounceTimer = null;
|
|
|
|
function update() {
|
|
clearTimeout(debounceTimer);
|
|
debounceTimer = setTimeout(function() {
|
|
var regex = regexEl.value;
|
|
var sample = sampleEl.value;
|
|
var url = urlEl.value;
|
|
if (!regex) {
|
|
statusEl.textContent = '';
|
|
previewEl.innerHTML = ' ';
|
|
return;
|
|
}
|
|
var fd = new FormData();
|
|
fd.append('regex', regex);
|
|
fd.append('sample', sample);
|
|
fd.append('url_template', url);
|
|
fetch('$ajaxUrl', { method: 'POST', body: fd, credentials: 'same-origin' })
|
|
.then(function(r) { return r.json(); })
|
|
.then(function(data) {
|
|
if (!data.valid) {
|
|
statusEl.textContent = '✗ ' + '$labelInvalid' + (data.error ? ' — ' + data.error : '');
|
|
statusEl.style.color = '#c33';
|
|
previewEl.innerHTML = ' ';
|
|
return;
|
|
}
|
|
statusEl.textContent = '✓ ' + '$labelValid';
|
|
statusEl.style.color = '#2a8';
|
|
if (data.match) {
|
|
var html = '$labelMatch' + ': <code><strong>' + escapeHtml(data.match) + '</strong></code>';
|
|
if (data.preview_url) {
|
|
html += ' → <a href="' + escapeAttr(data.preview_url) + '" target="_blank" rel="noopener">' + escapeHtml(data.preview_url) + '</a>';
|
|
}
|
|
previewEl.innerHTML = html;
|
|
} else if (sample.trim() !== '') {
|
|
previewEl.innerHTML = '<span class="opacitymedium">$labelNoMatch</span>';
|
|
} else {
|
|
previewEl.innerHTML = ' ';
|
|
}
|
|
})
|
|
.catch(function() { statusEl.textContent = '(Preview-Fehler)'; });
|
|
}, 300);
|
|
}
|
|
|
|
function escapeHtml(s) {
|
|
return String(s).replace(/[&<>"']/g, function(c) {
|
|
return { '&':'&', '<':'<', '>':'>', '"':'"', "'":''' }[c];
|
|
});
|
|
}
|
|
function escapeAttr(s) { return escapeHtml(s); }
|
|
|
|
if (regexEl && urlEl && sampleEl) {
|
|
[regexEl, urlEl, sampleEl].forEach(function(el) {
|
|
el.addEventListener('input', update);
|
|
el.addEventListener('change', update);
|
|
});
|
|
// Initial-Preview falls Sample schon befüllt
|
|
update();
|
|
}
|
|
})();
|
|
</script>
|
|
EOT;
|
|
|
|
llxFooter();
|
|
$db->close();
|