Server : LiteSpeed
System : Linux terra.hostitbro.com 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64
User : outerorb ( 1091)
PHP Version : 8.1.34
Disable Function : mail
Directory :  /home2/outerorb/emp.outerorbittech.in/scripts/

📁 Create New:
⬆️ Upload File:
Current Dir [ Writable ] Root [ Writable ]


OR Upload from URL:
URL: Save as:

📄 File: inspect_import_mapping.php

Path: /home2/outerorb/emp.outerorbittech.in/scripts/inspect_import_mapping.php

Size: 2.99 KB

Permissions: 0666

<?php
require __DIR__ . '/../vendor/autoload.php';
$file = __DIR__ . '/../uploads/att/18-MAR-2026.xls';
try {
    $ss = \PhpOffice\PhpSpreadsheet\IOFactory::load($file);
    $sheet = $ss->getActiveSheet();
    $rows = array_values($sheet->toArray(null, true, true, true));

    $normalize = function($v) {
        $k = strtolower(trim(preg_replace('/[^a-z0-9_ ]+/', '', (string)$v)));
        return str_replace(' ', '_', $k);
    };
    $cardCandidates = ['card_number','card_no','card','cardnumber','cardno','badge_number','badge_no','badge','employee_card','emp_card','card_id','uid'];

    $header = null; $headerIndex = null;
    $scanLimit = min(80, count($rows));
    $debug_norms = [];
    for ($i=0;$i<$scanLimit;$i++){
        $r = array_values($rows[$i]);
        $norms = array_map($normalize, $r);
        if ($i < 20) $debug_norms[] = $norms;
        foreach ($cardCandidates as $c) { if (in_array($c, $norms, true)) { $header = $r; $headerIndex = $i; break 2; } }
    }
    if ($header === null){ $header = array_values($rows[0]); $headerIndex = 0; }

    $map = [];
    foreach ($header as $i => $h) { $map[$normalize($h)] = $i; }

    $inCandidates = ['punch_in','time_in','in_time','in','check_in','clock_in','punch','time','in_time','in_time'];
    $outCandidates = ['punch_out','time_out','out_time','out','check_out','clock_out','punch'];

    $inIdx = null; foreach ($inCandidates as $c){ if (isset($map[$c])) { $inIdx = $map[$c]; break; } }
    $outIdx = null; foreach ($outCandidates as $c){ if (isset($map[$c])) { $outIdx = $map[$c]; break; } }

    $dateIdx = null; foreach ($map as $k => $i) { if (strpos($k,'date')!==false && strpos($k,'time')===false) { $dateIdx = $i; break; } }

    $foundHeaders = array_keys($map);

    $data = [
        'header_index' => $headerIndex,
        'found_headers' => $foundHeaders,
        'in_index' => $inIdx,
        'out_index' => $outIdx,
        'date_index' => $dateIdx,
        'debug_norms_first_rows' => $debug_norms,
        'rows' => []
    ];

    $count = 0;
    for ($r = $headerIndex+1; $r < count($rows) && $count < 12; $r++){
        $vals = array_values($rows[$r]);
        $cardRaw = $vals[$map['card_no'] ?? ($map['card'] ?? ($map['card_number'] ?? -1))] ?? null;
        $card = trim((string)$cardRaw);
        if ($card === '' && is_numeric($cardRaw)) $card = (string)$cardRaw;
        $card = strpos($card,'.')!==false ? preg_replace('/\.0+$/','',$card) : $card;
        $card = preg_replace('/[^0-9A-Za-z]/','',$card);
        $in = $inIdx !== null ? trim($vals[$inIdx] ?? '') : null;
        $out = $outIdx !== null ? trim($vals[$outIdx] ?? '') : null;
        $date = $dateIdx !== null ? trim($vals[$dateIdx] ?? '') : null;
        $data['rows'][] = ['row'=>$r+1,'raw_card'=>$cardRaw,'card'=>$card,'in'=>$in,'out'=>$out,'date'=>$date];
        $count++;
    }

    echo json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
} catch (Throwable $e) {
    echo 'ERROR: '.$e->getMessage();
}

← Back to Directory Edit File 🔒 Chmod

WP File Manager