*
* 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 idsconnect/log_detail.php
* \ingroup idsconnect
* \brief Detailansicht eines Log-Eintrags
*/
// Dolibarr laden
$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 && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
$res = @include dirname(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");
}
dol_include_once('/idsconnect/class/idslog.class.php');
dol_include_once('/idsconnect/class/idssupplier.class.php');
dol_include_once('/idsconnect/lib/idsconnect.lib.php');
/**
* @var DoliDB $db
* @var Translate $langs
* @var User $user
*/
$langs->loadLangs(array("idsconnect@idsconnect"));
if (!$user->hasRight('idsconnect', 'read')) {
accessforbidden();
}
$id = GETPOSTINT('id');
if (empty($id)) {
setEventMessages('Keine Log-ID angegeben', null, 'errors');
header('Location: '.DOL_URL_ROOT.'/custom/idsconnect/log_list.php');
exit;
}
// Log laden
$log = new IdsLog($db);
$result = $log->fetch($id);
if ($result <= 0) {
setEventMessages('Log-Eintrag #'.$id.' nicht gefunden', null, 'errors');
header('Location: '.DOL_URL_ROOT.'/custom/idsconnect/log_list.php');
exit;
}
// Großhändler laden
$supplier = new IdsSupplier($db);
$supplier->fetch($log->fk_supplier);
// Benutzer laden
$userObj = new User($db);
$userObj->fetch($log->fk_user);
/*
* View
*/
llxHeader('', $langs->trans("IdsconnectLogDetail").' #'.$id, '', '', 0, 0, '', '', '', 'mod-idsconnect page-log_detail');
print load_fiche_titre($langs->trans("IdsconnectLogDetail").' #'.$id, ''.$langs->trans("IdsconnectLogList").'', 'fa-search');
// ============================================================
// Basis-Informationen
// ============================================================
print '
';
print '';
print '| '.$langs->trans("ID").' | ';
print ''.$log->id.' |
';
print '| '.$langs->trans("IdsconnectLogDate").' | ';
print ''.dol_print_date($log->date_creation, 'dayhour').' |
';
print '| '.$langs->trans("IdsconnectLogSupplier").' | ';
print '';
if ($supplier->id > 0) {
print ''.htmlspecialchars($supplier->label).'';
print ' ('.htmlspecialchars($supplier->ref).')';
} else {
print 'Großhändler #'.$log->fk_supplier.' (gelöscht?)';
}
print ' |
';
print '| '.$langs->trans("IdsconnectLogUser").' | ';
print ''.($userObj->id > 0 ? $userObj->getNomUrl(1) : 'User #'.$log->fk_user).' |
';
print '| '.$langs->trans("IdsconnectLogAction").' | ';
print ''.$log->getActionLabel().' ('.$log->action_type.') |
';
print '| '.$langs->trans("IdsconnectLogDirection").' | ';
print ''.$log->direction.' |
';
print '| '.$langs->trans("IdsconnectLogStatus").' | ';
print ''.$log->getStatusLabel().' |
';
print '| IP-Adresse | ';
print ''.htmlspecialchars($log->ip_address ?: '-').' |
';
if ($log->fk_commande > 0) {
print '| Lieferantenbestellung | ';
print '#'.$log->fk_commande.' |
';
}
if (!empty($log->error_message)) {
print '| Fehlermeldung | ';
print ''.htmlspecialchars($log->error_message).' |
';
}
print '
';
// ============================================================
// Request-Daten (was wurde gesendet)
// ============================================================
if (!empty($log->request_data)) {
print '
';
print load_fiche_titre('Request-Daten (gesendet)', '', 'fa-arrow-up');
$request = json_decode($log->request_data, true);
if (is_array($request)) {
print '';
foreach ($request as $key => $value) {
print '';
print ''.$key.' | ';
print '';
if (is_array($value)) {
print ''.htmlspecialchars(json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)).' ';
} elseif ($key === 'hookurl' || $key === 'target_url' || $key === 'shop_url') {
print ''.htmlspecialchars($value).'';
} elseif ($key === 'testmode') {
print $value ? 'Testmodus' : 'LIVE';
} else {
print htmlspecialchars($value);
}
print ' |
';
}
print '
';
} else {
print ''.htmlspecialchars($log->request_data).'
';
}
}
// ============================================================
// Response-Daten (was kam zurück)
// ============================================================
if (!empty($log->response_data)) {
print '
';
print load_fiche_titre('Response-Daten (empfangen)', '', 'fa-arrow-down');
$response = json_decode($log->response_data, true);
if (is_array($response)) {
// Callback-Meta-Informationen separat anzeigen
if (!empty($response['callback_meta'])) {
print '';
print '| Callback-Informationen |
';
foreach ($response['callback_meta'] as $key => $value) {
print '';
print ''.$key.' | ';
print '';
if (is_array($value)) {
print htmlspecialchars(implode(', ', $value));
} else {
print htmlspecialchars($value);
}
print ' |
';
}
print '
';
print '
';
}
// Empfangene Artikel anzeigen
if (!empty($response['items']) && is_array($response['items'])) {
print '';
print '';
print '| '.$langs->trans("IdsconnectCartArticleNr").' | ';
print ''.$langs->trans("IdsconnectCartDescription").' | ';
print ''.$langs->trans("IdsconnectCartQty").' | ';
print ''.$langs->trans("IdsconnectCartUnit").' | ';
print ''.$langs->trans("IdsconnectCartUnitPrice").' | ';
print ''.$langs->trans("IdsconnectCartTotalPrice").' | ';
print ''.$langs->trans("IdsconnectCartManufacturer").' | ';
print '
';
$total = 0;
foreach ($response['items'] as $item) {
$line_total = (float) ($item['gesamtpreis'] ?? ((float) ($item['menge'] ?? 0) * (float) ($item['einzelpreis'] ?? 0)));
$total += $line_total;
print '';
print ''.htmlspecialchars($item['artikelnr'] ?? '-').' | ';
print ''.htmlspecialchars($item['bezeichnung'] ?? '-').' | ';
print ''.((float) ($item['menge'] ?? 0)).' | ';
print ''.htmlspecialchars($item['einheit'] ?? 'STK').' | ';
print ''.price($item['einzelpreis'] ?? 0).' | ';
print ''.price($line_total).' | ';
print ''.htmlspecialchars($item['hersteller'] ?? '-').' | ';
print '
';
}
print '';
print '| '.$langs->trans("Total").' | ';
print ''.price($total).' | ';
print ' |
';
print '
';
}
// Restliche Response-Felder
$skip_keys = array('callback_meta', 'items');
$remaining = array_diff_key($response, array_flip($skip_keys));
if (!empty($remaining)) {
print '
';
print '| Weitere Response-Daten |
';
foreach ($remaining as $key => $value) {
print '';
print ''.$key.' | ';
print '';
if (is_array($value)) {
print ''.htmlspecialchars(json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)).' ';
} else {
print htmlspecialchars($value);
}
print ' |
';
}
print '
';
}
} else {
print ''.htmlspecialchars($log->response_data).'
';
}
}
// ============================================================
// Warenkorb-XML (Rohdaten)
// ============================================================
if (!empty($log->cart_xml)) {
print '
';
print load_fiche_titre('Warenkorb-XML ('.strlen($log->cart_xml).' Bytes)', '', 'fa-code');
// XML formatiert ausgeben
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$formatted_xml = $log->cart_xml;
if (@$dom->loadXML($log->cart_xml)) {
$formatted_xml = $dom->saveXML();
}
print '';
print htmlspecialchars($formatted_xml);
print '
';
}
// ============================================================
// Callback-Token (für Debugging)
// ============================================================
if (!empty($log->callback_token)) {
print '
';
print load_fiche_titre('Callback-Token', '', 'fa-key');
print '';
print '| Token | ';
print ''.htmlspecialchars($log->callback_token).' |
';
print '| Token-Status | ';
print '';
if ($log->status === 'pending') {
$token_age = dol_now() - $log->date_creation;
if ($token_age < 7200) {
$remaining = 7200 - $token_age;
print 'Gültig (noch '.round($remaining / 60).' Min.)';
} else {
print 'Abgelaufen';
}
} else {
print 'Eingelöst ('.$log->status.')';
}
print ' |
';
print '
';
}
// Aktionsbuttons
print '';
llxFooter();
$db->close();