* * 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'), ''.dol_escape_htmltag($langs->trans('Back')).'', 'fa-route'); print '
| '.$langs->trans('MahnungTrackingPatternLabel').' | '; print ''.$langs->trans('MahnungTrackingPatternProvider').' | '; print ''.$langs->trans('MahnungTrackingPatternRegex').' | '; print ''.$langs->trans('MahnungTrackingPatternUrlTemplate').' | '; print ''.$langs->trans('MahnungTrackingPatternPriority').' | '; print ''.$langs->trans('Status').' | '; print ''; print ' |
|---|---|---|---|---|---|---|
| '.$langs->trans('MahnungTrackingPatternsEmpty').' | ||||||
| '.dol_escape_htmltag($p['label']).' | '; print ''.dol_escape_htmltag($p['provider']).' | '; print ''.dol_escape_htmltag($p['regex']).' | ';
print ''.dol_escape_htmltag($p['url_template']).' | '; print ''.((int) $p['priority']).' | '; print ''; $toggleLabel = $p['active'] ? $langs->trans('Active') : $langs->trans('Disabled'); $toggleColor = $p['active'] ? 'badge-status4' : 'badge-status8'; print ''.dol_escape_htmltag($toggleLabel).''; print ' | '; print ''; print ''.img_picto($langs->trans('Edit'), 'edit').' '; print ''.img_picto($langs->trans('Delete'), 'delete').''; print ' | '; print '
' + escapeHtml(data.match) + '';
if (data.preview_url) {
html += ' → ' + escapeHtml(data.preview_url) + '';
}
previewEl.innerHTML = html;
} else if (sample.trim() !== '') {
previewEl.innerHTML = '$labelNoMatch';
} 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();
}
})();
EOT;
llxFooter();
$db->close();