| 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 : /proc/3951577/root/tmp/ |
Upload File : |
function im_parking_import() {
if ( empty( $_FILES['file'] ) || !isset( $_FILES['file']['error'] ) || $_FILES['file']['error'] !== UPLOAD_ERR_OK ) return array( 'ok' => false, 'message' => 'Keine Datei empfangen.' );
$tmp = $_FILES['file']['tmp_name']; $name = basename( (string) $_FILES['file']['name'] ); $size = (int) $_FILES['file']['size'];
if ( !is_uploaded_file( $tmp ) ) return array( 'ok' => false, 'message' => 'Ungültiger Upload.' );
$p = im_parking_parse( $tmp );
if ( empty( $p['ok'] ) ) return $p;
$rows = $p['rows'];
if ( !count( $rows ) ) return array( 'ok' => false, 'message' => 'Keine Datensätze gefunden.' );
$db = new MysqliDb( MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB );
$now = date( 'Y-m-d H:i:s' ); $today = date( 'Y-m-d' );
// Datei ablegen + in pacim_files registrieren (für Übersicht/Undo)
$dir = PATH_DATAS . '/parkinglist';
if ( !is_dir( $dir ) ) @mkdir( $dir, 0775, true );
$stored = $dir . '/' . date( 'Ymd_His' ) . '_' . preg_replace( '/[^A-Za-z0-9._-]/', '_', $name );
@copy( $tmp, $stored );
$md5 = is_file( $stored ) ? md5_file( $stored ) : md5( uniqid( '', true ) );
$fileId = $db->insert( 'pacim_files', array(
'file_name' => basename( $stored ), 'file_size' => $size, 'file_md5' => $md5, 'file_category' => 'parkinglist',
'file_path' => $dir . '/', 'file_type' => 'file', 'file_datetime' => $now, 'file_updated' => $now,
) );
$map = im_parking_existing_map( $db, $p['minA'], $p['maxA'] );
im_parking_classify( $rows, $map );
$runId = 'pl_' . uniqid();
$created = 0; $updated = 0; $skipped = 0; $errors = array();
foreach ( $rows as $i => $row ) {
try {
if ( $row['status'] === 'duplicate' ) { $skipped++; continue; }
$net = round( $row['price'] / 1.19, 15 );
$pid = ( $row['typ'] === 'Halle' ) ? 1 : 2;
$posTitle = ( $row['typ'] === 'Halle' ) ? 'Hallenstellplatz' : 'Außenstellplatz';
$ev = im_event_match( $db, $row['aDateRaw'], $row['rDateRaw'], $row['ship'] );
$eventId = $ev ? $ev['id'] : null;
$eventTitle = $ev ? $ev['title'] : $row['ship']; // DB-Titel übernehmen, wenn Event gefunden
$country = $row['country'] !== '' ? $row['country'] : 'Deutschland';
if ( $row['status'] === 'update' && !empty( $row['match'] ) ) {
$m = $row['match'];
$db->where( 'customer_id', (int) $m['booking_customer'] );
$db->update( 'pacim_customer', array(
'customer_name' => trim( $row['name'] ), 'customer_firstname' => $row['firstname'], 'customer_lastname' => $row['lastname'],
'customer_street' => $row['street'], 'customer_zipcode' => $row['zip'], 'customer_city' => $row['city'],
'customer_country' => $country, 'customer_phone' => $row['phone'], 'customer_email' => $row['mail'],
'customer_source' => 'ParkingList',
) );
$db->where( 'booking_id', (int) $m['booking_id'] );
$bUpd = array(
'booking_event' => $eventTitle, 'booking_event_id' => $eventId, 'booking_type' => $pid,
'booking_end' => ( $row['rDateRaw'] ? $row['rDateRaw'] : $m['booking_end'] ), 'booking_serial' => strtoupper( $row['plate'] ),
'booking_guests' => $row['pers'], 'booking_phone' => $row['phone'],
);
if ( !empty( $row['cruise_checkin'] ) ) $bUpd['booking_cruise_checkin'] = $row['cruise_checkin'];
$db->update( 'pacim_booking', $bUpd );
$db->where( 'invoice_id', (int) $m['booking_invoice'] );
$db->update( 'pacim_invoice_pos', array( 'product_id' => $pid, 'invoice_pos_price' => $net, 'invoice_pos_title' => $posTitle ) );
$updated++;
continue;
}
// NEU anlegen
$cid = $db->insert( 'pacim_customer', array(
'customer_gender' => 0, 'customer_name' => trim( $row['name'] ), 'customer_firstname' => $row['firstname'], 'customer_lastname' => $row['lastname'],
'customer_street' => $row['street'], 'customer_zipcode' => $row['zip'], 'customer_city' => $row['city'],
'customer_country' => $country, 'customer_phone' => $row['phone'], 'customer_email' => $row['mail'],
'customer_source' => 'ParkingList',
) );
if ( !$cid ) throw new Exception( 'Kunde konnte nicht angelegt werden' );
$iid = $db->insert( 'pacim_invoice', array(
'invoice_customer' => $cid, 'invoice_no' => '', 'invoice_price' => 0.00, 'invoice_status' => 0, 'invoice_payment' => 0,
'invoice_coupon' => 0, 'invoice_date' => $today, 'invoice_datetime' => $now,
) );
if ( !$iid ) throw new Exception( 'Rechnung konnte nicht angelegt werden' );
$bid = $db->insert( 'pacim_booking', array(
'booking_invoice' => $iid, 'booking_customer' => $cid, 'booking_no' => im_next_booking_no( $db ),
'booking_event' => $eventTitle, 'booking_event_id' => $eventId, 'booking_type' => $pid,
'booking_begin' => $row['aDateRaw'], 'booking_end' => ( $row['rDateRaw'] ? $row['rDateRaw'] : $row['aDateRaw'] ),
'booking_cruise_checkin' => $row['cruise_checkin'],
'booking_serial' => strtoupper( $row['plate'] ), 'booking_guests' => $row['pers'], 'booking_phone' => $row['phone'],
'booking_datetime' => $now,
) );
if ( !$bid ) throw new Exception( 'Buchung konnte nicht angelegt werden' );
$db->insert( 'pacim_invoice_pos', array(
'invoice_id' => $iid, 'product_id' => $pid, 'booking_id' => $bid, 'invoice_pos_price' => $net, 'invoice_pos_quantity' => 1, 'invoice_pos_title' => $posTitle,
) );
$db->insert( 'pacim_import', array(
'import_file_id' => $fileId, 'import_booking' => $bid, 'import_customer' => $cid, 'import_invoice' => $iid,
'import_datetime' => $now, 'import_run_id' => $runId,
) );
$created++;
} catch ( Exception $e ) {
if ( count( $errors ) < 10 ) $errors[] = 'Zeile ' . ( $i + 1 ) . ': ' . $e->getMessage();
}
}
// Dauerhaftes Import-Protokoll (unabhängig von pacim_files/Datei – bleibt sichtbar)
$logRaw = settings::get( 'parking_import_log', '' );
$log = $logRaw ? json_decode( $logRaw, true ) : array();
if ( ! is_array( $log ) ) $log = array();
array_unshift( $log, array(
'file_id' => (int) $fileId, 'name' => $name, 'dt' => $now,
'created' => $created, 'updated' => $updated, 'skipped' => $skipped, 'total' => count( $rows ),
) );
$log = array_slice( $log, 0, 50 );
settings::set( 'parking_import_log', json_encode( $log, JSON_UNESCAPED_UNICODE ) );
return array( 'ok' => true, 'type' => 'parking', 'fileId' => (int) $fileId, 'created' => $created, 'updated' => $updated,
'skipped' => $skipped, 'errorCount' => count( $errors ), 'errors' => $errors, 'total' => count( $rows ) );
}