| Server IP : 202.61.199.114 / Your IP : 216.73.217.139 Web Server : nginx/1.22.1 System : Linux de.arni-solutions.de 6.1.0-49-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.174-1 (2026-05-26) x86_64 User : web20 ( 1018) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/seaside.pacim.de/web/ |
Upload File : |
<?php
/**
* booking-history.php – Änderungs- & Zugriffsprotokoll einer Buchung für den
* Historie-Tab der Buchungsansicht. Session-/Admin-geschützt.
*
* GET action=list&invoice_id= -> { ok, entries:[ {…, changes:[…]} ] }
* POST action=revert&log_id= -> { ok, reverted_count }
*
* Datengrundlage: pacim_api_log (siehe apilog-Klasse). Schreibzugriffe enthalten
* ein Changeset (Feld, Vorher, Nachher) und sind feldgenau rückgängig zu machen.
*/
require_once( __DIR__ . '/includes/config.inc.php' );
@ini_set( 'display_errors', '0' );
error_reporting( 0 );
ob_start();
function bh_json( $a ) { while ( ob_get_level() > 0 ) ob_end_clean(); header( 'Content-Type: application/json; charset=utf-8' ); echo json_encode( $a ); exit(); }
if ( ! function_exists( 'is_admin' ) || ! is_admin() ) { http_response_code( 403 ); bh_json( array( 'ok' => false, 'error' => 'forbidden' ) ); }
$db = new MysqliDb( MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB );
$action = $_GET['action'] ?? ( $_POST['action'] ?? '' );
apilog::ensureTable();
/* ----------------------------------------------------------- Liste */
if ( $action === 'list' ) {
$iid = (int) ( $_GET['invoice_id'] ?? 0 );
$bid = (int) ( $_GET['booking_id'] ?? 0 );
if ( $iid <= 0 && $bid <= 0 ) bh_json( array( 'ok' => false, 'error' => 'invalid_id' ) );
// Wenn nur booking_id gegeben: Rechnung dazu ermitteln (und umgekehrt alle Fahrzeuge).
if ( $iid <= 0 && $bid > 0 ) { $r = $db->rawQueryOne( "SELECT booking_invoice FROM pacim_booking WHERE booking_id = ?", array( $bid ) ); if ( $r ) $iid = (int) $r['booking_invoice']; }
$bookingIds = array();
if ( $iid > 0 ) foreach ( (array) $db->rawQuery( "SELECT booking_id FROM pacim_booking WHERE booking_invoice = ?", array( $iid ) ) as $b ) $bookingIds[] = (int) $b['booking_id'];
if ( $bid > 0 ) $bookingIds[] = $bid;
$bookingIds = array_values( array_unique( array_filter( $bookingIds ) ) );
$where = array(); $params = array();
if ( $iid > 0 ) { $where[] = 'log_invoice = ?'; $params[] = $iid; }
if ( count( $bookingIds ) ) { $where[] = 'log_booking IN (' . implode( ',', array_fill( 0, count( $bookingIds ), '?' ) ) . ')'; foreach ( $bookingIds as $x ) $params[] = $x; }
if ( ! count( $where ) ) bh_json( array( 'ok' => true, 'entries' => array() ) );
$rows = $db->rawQuery( "SELECT * FROM pacim_api_log WHERE " . implode( ' OR ', $where ) . " ORDER BY log_datetime DESC, log_id DESC LIMIT 500", $params );
$entries = array();
foreach ( (array) $rows as $r ) {
$changes = array();
$raw = json_decode( (string) $r['log_changes'], true );
if ( is_array( $raw ) ) {
foreach ( $raw as $c ) {
$fmt = $c['fmt'] ?? '';
$kind = $c['kind'] ?? 'field';
if ( $kind === 'field' ) {
$changes[] = array( 'label' => $c['label'] ?? $c['col'] ?? '', 'old' => apilog::displayValue( $fmt, $c['old'] ?? null ), 'new' => apilog::displayValue( $fmt, $c['new'] ?? null ) );
} else {
$changes[] = array( 'label' => $c['label'] ?? 'Position', 'old' => (string) ( $c['old'] ?? '' ), 'new' => (string) ( $c['new'] ?? '' ) );
}
}
}
$isWrite = ( $r['log_kind'] === 'write' );
$entries[] = array(
'id' => (int) $r['log_id'],
'datetime' => (string) $r['log_datetime'],
'source' => trim( (string) $r['log_key_name'] ) !== '' ? (string) $r['log_key_name'] : ( (int) $r['log_broker'] > 0 ? 'Partner #' . (int) $r['log_broker'] : 'System' ),
'is_partner' => ( (int) $r['log_broker'] > 0 ),
'method' => (string) $r['log_method'],
'resource' => (string) $r['log_resource'],
'action' => (string) $r['log_action'],
'kind' => (string) $r['log_kind'],
'target' => (string) $r['log_target'],
'ip' => (string) $r['log_ip'],
'status' => (int) $r['log_status'],
'error' => (string) $r['log_error'],
'changes' => $changes,
'change_count'=> count( $changes ),
'reverted' => (int) $r['log_reverted'],
'reverted_at' => (string) $r['log_reverted_at'],
'reverted_by' => (string) $r['log_reverted_by'],
'revertible' => ( $isWrite && count( $changes ) > 0 && (int) $r['log_reverted'] === 0 && (int) $r['log_status'] < 400 ),
);
}
bh_json( array( 'ok' => true, 'entries' => $entries ) );
}
/* ----------------------------------------------------------- Rückgängig */
if ( $action === 'revert' ) {
if ( $_SERVER['REQUEST_METHOD'] !== 'POST' ) bh_json( array( 'ok' => false, 'error' => 'method' ) );
$lid = (int) ( $_POST['log_id'] ?? 0 );
if ( $lid <= 0 ) bh_json( array( 'ok' => false, 'error' => 'invalid_id' ) );
$by = trim( (string) ( $_SESSION['user_name'] ?? 'Administrator' ) );
$res = apilog::revert( $lid, $by );
if ( empty( $res['ok'] ) ) { http_response_code( 409 ); bh_json( $res ); }
bh_json( $res );
}
http_response_code( 400 );
bh_json( array( 'ok' => false, 'error' => 'unknown_action' ) );