Vis: a.2.1.9.php

Tilbage

<?php
/**
 * =====================================================================
 * PHP - FILBEHANDLER - ENDRINGSHISTORIKK (CHANGELOG)
 * =====================================================================
 * ver. 1.0.0 (2024-10-24): Første stabile utgave med grunnleggende filbehandling.
 * ver. 1.1.0 (2026-10-25): Lagt til rekursiv søkefunksjon i gjeldende mappe.
 * ver. 1.2.0 (2026-10-25): Lagt til "Kopier" og "Sett tillatelser" (Chmod).
 * ver. 1.3.0 (2026-10-25): Utvidet innlogging med brukernavn ("TT" default) og passord.
 * ver. 1.4.0 (2026-10-25): Konfigurerbar linjehøyde, farger og flerspråklig støtte.
 * ver. 1.4.3 (2026-10-26): Oppdatert standardbruker, passord og linjehøyde til 8px.
 * ver. 1.5.0 (2026-10-26): Lagt til handlingsknappen "Kjør som webside" for 
 *                          php, htm, html og pl i egen fane.
 * ver. 1.5.3.1 (2026-11-01): Stabil utgave med fast venstresidepanel og visning på filnavn.
 * ver. 1.5.6 (2026-11-01): Flyttet handlingsmenyen direkte bak mappe- og filikonene.
 * ver. 1.5.7 (2026-11-01): Satt bakgrunnsfarge for kolonneoverskrifter (th) til gul.
 * ver. 1.5.8 (2026-11-01): Sterkere og tydeligere gulfarge (#ffe066) på overskrifter.
 * ver. 1.5.9 (2026-11-01): Lys blå bakgrunnsfarge på annenhver linje for lesbarhet.
 * ver. 1.5.12 (2026-11-01): Gått over til transparente SVG-ikoner for full fargekontroll.
 * ver. 1.5.13 (2026-11-01): Endret farge på filikonet til rød (#e74c3c) for god kontrast.
 * ver. 1.5.14 (2026-11-01): Lagt til ramme rundt stilinjen (.path-bar).
 * ver. 1.5.15 (2026-11-01): Gjort rammen rundt stilinjen like markant som søkefeltet.
 * ver. 1.5.16 (2026-11-01): Erstattet direkte kopiering med "Kopier og Lim inn" (Copy & Paste).
 * ver. 1.5.17 (2026-11-01): Flyttet "Lim inn" direkte inn som handlingsvalg i menyene.
 * ver. 1.5.18 (2026-11-01): Fjernet unødvendige dialogvinduer og sikret ren intern kopiering.
 * ver. 1.5.19 (2026-11-01): Rettet PHP-syntaksfeil (500-feil) i filredigeringsblokken.
 * ver. 1.5.20 (2026-11-01): Fjernet handlingen "Flytt" helt fra systemet.
 * ver. 1.5.21 (2026-11-01): Fullstendig synkronisering og oppdatering av alle språktabeller.
 * ver. 1.5.22 (2026-11-01): Robust stiberegning og støtte for system_root = true.
 * ver. 1.5.26 (2026-11-01): Lagt til video/mp4 MIME-type og direkteside for avspilling av MP4.
 * ver. 1.5.27 (2026-11-01): Komplett og robust bilde- og filvisning i undermapper.
 * ver. 1.5.28 (2026-11-01): Rettet PHP-syntaksfeil og lagt rename tilbake i handlingsmenyen.
 * ver. 1.5.29 (2026-11-02): Korrigert stiberegning for "Kjør som webside" i undermapper.
 * ver. 1.5.30 (2026-11-05): Implementert rektangulær SVG-flaggknapp og nedtrekksmeny 
 *                          for språkvalg identisk med v. 1.7.3.
 * ver. 1.5.33 (2026-11-05): Lagt til en dedikert "Lim inn"-knapp med filnavn i verktøylinjen.
 * ver. 1.5.34 (2026-11-05): Gjeninnført "Lim inn" i både verktøylinje og radmenyer.
 * ver. 1.5.35 (2026-11-05): Krympet størrelsen på handlingsmenyen og satt fet skrift.
 * ver. 1.5.36 (2026-11-05): Dynamisk lagringsmelding (grønn/gul veksling) fra v. 1.7.3 
 *                          med nullstilling av teller ved trykk på Tilbake-knappen.
 * ver. 1.5.37 (2026-11-05): Stabil originalutgave med velfungerende redigering 
 *                          og knapperekkefølge.
 * ver. 1.9.5  (2026-11-07): Lagt til ekte feilsjekk og synlige feilmeldinger ved 
 *                          sletting av filer og mapper.
 * ver. 1.9.6  (2026-11-07): Tilpasset versjonsvisning.
 * ver. 1.9.7  (2026-11-07): Tilbakestilt versjonsvisning til rolig og diskré format.
 * ver. 1.9.8  (2026-11-07): Gjenopprettet den fulle og komplette endringsloggen i toppen.
 * ver. 1.9.9  (2026-11-07): Gjeninnført flaggknapp og nedtrekksmeny for språkvalg.
 * ver. 1.10.0 (2026-11-07): Gjenopprettet samtlige opprinnelige språk i språktabellen.
 * ver. 1.10.1 (2026-11-07): Gjort "Logg ut"-knappen vesentlig tydeligere for bedre synlighet.
 * ver. 1.10.2 (2026-11-07): Gjenopprettet det eksakte toppområdet fra v. 1.5.37 identisk.
 * ver. 1.10.3 (2026-11-07): Gjenopprettet all endringshistorikk etter v. 1.5.37 fullt ut.
 * ver. 1.10.4 (2026-11-07): Gjenopprettet alle de seks opprinnelige språkene i nedtrekksmenyen.
 * ver. 1.10.5 (2026-11-07): Gjenopprettet søkefelt og søkeknapp i verktøylinjen.
 * ver. 1.10.6 (2026-11-07): Gjeninnført 'language' i $config for fastsetting av default språk.
 * ver. 1.10.7 (2026-11-07): Gjenopprettet opplastingsknapper for både filer og mapper i verktøylinjen.
 * ver. 1.10.8 (2026-11-07): Lagt til lagringsteller med nullstilling ved trykk på Tilbake-knappen.
 * ver. 1.10.9 (2026-11-07): Gjort det mulig å åpne filer som PDF, JPG, PNG og andre 
 *                          direkte i ny fane ved klikk på filnavnet.
 * ver. 2.1.0  (2026-11-07): Innebygd HTML5-lydavspiller for MP3 og samlede flagg.
 * ver. 2.1.1  (2026-11-08): Rettet dynamiske SVG-ikoner og handlingsmenyer på søkeresultater.
 * ver. 2.1.2  (2026-11-08): Lagt til finsk språkstøtte (fi) med eget SVG-flagg og oversettelser.
 * ver. 2.1.3  (2026-11-08): Lagt til konfigurasjon for om PHP-filer skal kjøres som webside ved klikk.
 * ver. 2.1.4  (2026-11-08): Rettet opp slik at konfigurasjonen (run_php_as_web) kun gjelder PHP-filer.
 * ver. 2.1.5  (2026-11-08): Rettet syntaksfeil i søkeresultat-løkken som hindret redigering.
 * ver. 2.1.6  (2026-11-08): Gjeninnført «Kjør som webside» / «Vis» i handlingsmenyen for alle visbare filer.
 * ver.a 2.1.7 (2026-11-11): Etablert ver.a som prefiks for nye endringer fra og med dette prosjektet.
 * ver.a 2.1.8 (2026-11-11): Endret overskriften i systemet fra Kontrollpanel til PHP - Filbehandler.
 * ver.a 2.1.9 (2026-11-11): Lagt til alternative konfiguratorer cfg1 (standard) og cfg2 (direkteredigering).
 * =====================================================================
 */

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$ver = "ver.a 2.1.9 2026-11-11 HBj ";

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// Nullstill lagringsteller hvis brukeren trykker på Tilbake eller åpner redigering på nytt
if (isset($_GET['reset_counter']) || (isset($_GET['edit']) && !isset($_POST['action']))) {
    unset($_SESSION['save_counter']);
}

// ==========================================
// KONSEPTUELLE INNSTILLINGER (KONFIGURASJON)
// Velg mellom cfg1 (standard: kjør PHP som webside ved klikk) 
// og cfg2 (alternativ: åpne alltid PHP for redigering ved klikk)
// ==========================================
$cfg1 = [
    'language'        => 'no',
    'run_php_as_web'  => true,
    'line_height'     => '8px',
    'folder_color'    => '#f39c12',
    'file_color'      => '#e74c3c',
    'use_login'       => true,
    'username'        => 'TT',
    'password'        => 'tt70131858',
    'system_root'     => false,
    'mkfile'          => true,
    'mkdir'           => true,
    'upload'          => true,
    'download_file'   => true,
    'download_folder' => true,
    'view'            => true,
    'edit'            => true,
    'run_web'         => true,
    'rename'          => true,
    'copy'            => true,
    'chmod'           => true,
    'delete'          => true
];

$cfg2 = [
    'language'        => 'no',
    'run_php_as_web'  => false, // Alternativ: Klikk på PHP åpner redigering
    'line_height'     => '8px',
    'folder_color'    => '#f39c12',
    'file_color'      => '#e74c3c',
    'use_login'       => true,
    'username'        => 'TT',
    'password'        => 'tt70131858',
    'system_root'     => false,
    'mkfile'          => true,
    'mkdir'           => true,
    'upload'          => true,
    'download_file'   => true,
    'download_folder' => true,
    'view'            => true,
    'edit'            => true,
    'run_web'         => true,
    'rename'          => true,
    'copy'            => true,
    'chmod'           => true,
    'delete'          => true
];

// Velg aktiv konfigurator her (bytt til $cfg2 hvis ønskelig)
$config = $cfg1;

// Språkvalgshåndtering via sesjon, med fallback til $config['language']
if (isset($_GET['lang']) && in_array($_GET['lang'], ['no', 'en', 'sv', 'da', 'de', 'fr', 'fi'])) {
    $_SESSION['lang'] = $_GET['lang'];
    header("Location: " . strtok($_SERVER["REQUEST_URI"], '?') . (isset($_GET['path']) ? '?path=' . urlencode($_GET['path']) : ''));
    exit;
}

$current_lang = isset($_SESSION['lang']) ? $_SESSION['lang'] : (isset($config['language']) ? $config['language'] : 'no');

// ==========================================
// SPRÅKTABELLER
// ==========================================
$lang = [
    'no' => [
        'title' => 'PHP - Filbehandler',
        'subtitle' => 'Utviklet av H. Bjerkan ved hjelp av Gemini',
        'login_header' => 'PHP - Filbehandler',
        'username' => 'Brukernavn',
        'password' => 'Passord',
        'login_btn' => 'Logg inn',
        'login_error' => 'Feil brukernavn eller passord!',
        'logout' => 'Logg ut',
        'logged_in_as' => 'Innlogget som:',
        'guest' => 'Gjest',
        'home_root' => 'Hjem / Rotmappe',
        'sidebar_title' => 'Mappestruktur',
        'path_label' => 'Sti:',
        'new_file_placeholder' => 'Nytt filnavn...',
        'new_file_btn' => '+ Ny fil',
        'new_folder_placeholder' => 'Nytt mappenavn...',
        'new_folder_btn' => '+ Ny mappe',
        'upload_files_btn' => 'Last opp fil(er)',
        'upload_folder_btn' => 'Last opp mappe',
        'search_placeholder' => 'Søk i mappe...',
        'search_btn' => 'Søk',
        'reset_btn' => 'Nullstill',
        'search_results' => 'Søkeresultater for',
        'found_count' => 'funnet',
        'no_results' => 'Ingen filer eller mapper funnet.',
        'th_name' => 'Navn',
        'th_folder' => 'Mappe',
        'th_type' => 'Type',
        'th_size' => 'Størrelse',
        'th_perms' => 'Tillatelser',
        'th_actions' => 'Handling',
        'parent_dir' => '.. (Opp et nivå)',
        'type_dir' => 'Mappe',
        'type_file' => 'Fil',
        'action_view' => 'Vis',
        'action_edit' => 'Rediger',
        'action_run_web' => 'Kjør som webside',
        'action_download' => 'Last ned',
        'action_download_zip' => 'Last ned (ZIP)',
        'action_rename' => 'Gi nytt navn',
        'action_copy' => 'Kopier',
        'action_paste' => 'Lim inn',
        'action_chmod' => 'Tillatelser',
        'action_delete' => 'Slett',
        'prompt_rename' => "Skriv inn nytt navn:",
        'prompt_chmod' => "Sett tillatelser (f.eks. 0644 for filer eller 0755 for mapper):",
        'confirm_delete' => "Vil du slette",
        'back_to_files' => 'Tilbake',
        'save_changes' => 'Lagre endringer',
        'save_success' => 'Endringene ble lagret vellykket!',
        'save_error' => 'Feil: Kunne ikke lagre til filen (sjekk tillatelser eller skrivebeskyttelse)!',
        'delete_error' => 'Feil: Kunne ikke slette elementet (sjekk tillatelser eller om mappen er tom)!'
    ],
    'en' => [
        'title' => 'PHP - File Manager',
        'subtitle' => 'Developed by H. Bjerkan using Gemini',
        'login_header' => 'PHP - File Manager',
        'username' => 'Username',
        'password' => 'Password',
        'login_btn' => 'Log in',
        'login_error' => 'Invalid username or password!',
        'logout' => 'Log out',
        'logged_in_as' => 'Logged in as:',
        'guest' => 'Guest',
        'home_root' => 'Home / Root folder',
        'sidebar_title' => 'Folder Structure',
        'path_label' => 'Path:',
        'new_file_placeholder' => 'New file name...',
        'new_file_btn' => '+ New file',
        'new_folder_placeholder' => 'New folder name...',
        'new_folder_btn' => '+ New folder',
        'upload_files_btn' => 'Upload file(s)',
        'upload_folder_btn' => 'Upload folder',
        'search_placeholder' => 'Search in folder...',
        'search_btn' => 'Search',
        'reset_btn' => 'Reset',
        'search_results' => 'Search results for',
        'found_count' => 'found',
        'no_results' => 'No files or folders found.',
        'th_name' => 'Name',
        'th_folder' => 'Folder',
        'th_type' => 'Type',
        'th_size' => 'Size',
        'th_perms' => 'Permissions',
        'th_actions' => 'Action',
        'parent_dir' => '.. (Up one level)',
        'type_dir' => 'Folder',
        'type_file' => 'File',
        'action_view' => 'View',
        'action_edit' => 'Edit',
        'action_run_web' => 'Run as webpage',
        'action_download' => 'Download',
        'action_download_zip' => 'Download (ZIP)',
        'action_rename' => 'Rename',
        'action_copy' => 'Copy',
        'action_paste' => 'Paste',
        'action_chmod' => 'Permissions',
        'action_delete' => 'Delete',
        'prompt_rename' => "Enter new name:",
        'prompt_chmod' => "Set permissions (e.g. 0644 for files or 0755 for folders):",
        'confirm_delete' => "Do you want to delete",
        'back_to_files' => 'Back',
        'save_changes' => 'Save changes',
        'save_success' => 'Changes saved successfully!',
        'save_error' => 'Error: Could not save to file (check permissions or write protection)!',
        'delete_error' => 'Error: Could not delete item (check permissions or if folder is empty)!'
    ],
    'sv' => [
        'title' => 'PHP - Filhanterare',
        'subtitle' => 'Utvecklad av H. Bjerkan med hjälp av Gemini',
        'login_header' => 'PHP - Filhanterare',
        'username' => 'Användarnamn',
        'password' => 'Lösenord',
        'login_btn' => 'Logga in',
        'login_error' => 'Felaktigt användarnamn eller lösenord!',
        'logout' => 'Logga ut',
        'logged_in_as' => 'Inloggad som:',
        'guest' => 'Gäst',
        'home_root' => 'Hem / Rotmapp',
        'sidebar_title' => 'Mappstruktur',
        'path_label' => 'Sökväg:',
        'new_file_placeholder' => 'Nytt filnamn...',
        'new_file_btn' => '+ Ny fil',
        'new_folder_placeholder' => 'Nytt mappnamn...',
        'new_folder_btn' => '+ Ny mapp',
        'upload_files_btn' => 'Ladda upp fil(er)',
        'upload_folder_btn' => 'Ladda upp mapp',
        'search_placeholder' => 'Sök i mapp...',
        'search_btn' => 'Sök',
        'reset_btn' => 'Återställ',
        'search_results' => 'Sökresultat för',
        'found_count' => 'hittade',
        'no_results' => 'Inga filer eller mappar hittades.',
        'th_name' => 'Namn',
        'th_folder' => 'Mapp',
        'th_type' => 'Typ',
        'th_size' => 'Storlek',
        'th_perms' => 'Behörigheter',
        'th_actions' => 'Åtgärd',
        'parent_dir' => '.. (Upp en nivå)',
        'type_dir' => 'Mapp',
        'type_file' => 'Fil',
        'action_view' => 'Visa',
        'action_edit' => 'Redigera',
        'action_run_web' => 'Kör som webbsida',
        'action_download' => 'Ladda ner',
        'action_download_zip' => 'Ladda ner (ZIP)',
        'action_rename' => 'Byt namn',
        'action_copy' => 'Kopiera',
        'action_paste' => 'Klistra in',
        'action_chmod' => 'Behörigheter',
        'action_delete' => 'Radera',
        'prompt_rename' => "Ange nytt namn:",
        'prompt_chmod' => "Ange behörigheter (t.ex. 0644 för filer eller 0755 för mappar):",
        'confirm_delete' => "Vill du radera",
        'back_to_files' => 'Tillbaka',
        'save_changes' => 'Spara ändringar',
        'save_success' => 'Ändringarna sparades utan problem!',
        'save_error' => 'Fel: Kunde inte spara till filen (kontrollera behörigheter eller skrivskydd)!',
        'delete_error' => 'Fel: Kunde inte radera objektet (kontrollera behörigheter eller om mappen är tom)!'
    ],
    'da' => [
        'title' => 'PHP - Filhåndtering',
        'subtitle' => 'Udviklet af H. Bjerkan ved hjælp af Gemini',
        'login_header' => 'PHP - Filhåndtering',
        'username' => 'Brugernavn',
        'password' => 'Adgangskode',
        'login_btn' => 'Log ind',
        'login_error' => 'Forkert brugernavn eller adgangskode!',
        'logout' => 'Log ud',
        'logged_in_as' => 'Logget ind som:',
        'guest' => 'Gæst',
        'home_root' => 'Hjem / Rodmappe',
        'sidebar_title' => 'Mappestruktur',
        'path_label' => 'Sti:',
        'new_file_placeholder' => 'Nyt filnavn...',
        'new_file_btn' => '+ Ny fil',
        'new_folder_placeholder' => 'Nyt mappenavn...',
        'new_folder_btn' => '+ Ny mappe',
        'upload_files_btn' => 'Upload fil(er)',
        'upload_folder_btn' => 'Upload mappe',
        'search_placeholder' => 'Søg i mappe...',
        'search_btn' => 'Søg',
        'reset_btn' => 'Nulstil',
        'search_results' => 'Søgeresultater for',
        'found_count' => 'fundet',
        'no_results' => 'Ingen filer eller mapper fundet.',
        'th_name' => 'Navn',
        'th_folder' => 'Mappe',
        'th_type' => 'Type',
        'th_size' => 'Størrelse',
        'th_perms' => 'Tilladelser',
        'th_actions' => 'Handling',
        'parent_dir' => '.. (Op et niveau)',
        'type_dir' => 'Mappe',
        'type_file' => 'Fil',
        'action_view' => 'Vis',
        'action_edit' => 'Rediger',
        'action_run_web' => 'Kør som webside',
        'action_download' => 'Download',
        'action_download_zip' => 'Download (ZIP)',
        'action_rename' => 'Omdøb',
        'action_copy' => 'Kopier',
        'action_paste' => 'Indsæt',
        'action_chmod' => 'Tilladelser',
        'action_delete' => 'Slet',
        'prompt_rename' => "Indtast nyt navn:",
        'prompt_chmod' => "Angiv tilladelser (f.eks. 0644 for filer eller 0755 for mapper):",
        'confirm_delete' => "Vil du slette",
        'back_to_files' => 'Tilbage',
        'save_changes' => 'Gem ændringer',
        'save_success' => 'Ændringerne blev gemt uden problemer!',
        'save_error' => 'Fejl: Kunne ikke gemme til filen (tjek tilladelser eller skrivebeskyttelse)!',
        'delete_error' => 'Fejl: Kunne ikke slette elementet (tjek tilladelser eller om mappen er tom)!'
    ],
    'de' => [
        'title' => 'PHP - Dateimanager',
        'subtitle' => 'Entwickelt von H. Bjerkan mit Hilfe von Gemini',
        'login_header' => 'PHP - Dateimanager',
        'username' => 'Benutzername',
        'password' => 'Passwort',
        'login_btn' => 'Anmelden',
        'login_error' => 'Falscher Benutzername oder falsches Passwort!',
        'logout' => 'Abmelden',
        'logged_in_as' => 'Angemeldet als:',
        'guest' => 'Gast',
        'home_root' => 'Start / Stammverzeichnis',
        'sidebar_title' => 'Ordnerstruktur',
        'path_label' => 'Pfad:',
        'new_file_placeholder' => 'Neuer Dateiname...',
        'new_file_btn' => '+ Neue Datei',
        'new_folder_placeholder' => 'Neuer Ordnername...',
        'new_folder_btn' => '+ Neuer Ordner',
        'upload_files_btn' => 'Datei(en) hochladen',
        'upload_folder_btn' => 'Ordner hochladen',
        'search_placeholder' => 'In Ordner suchen...',
        'search_btn' => 'Suchen',
        'reset_btn' => 'Zurücksetzen',
        'search_results' => 'Suchergebnisse für',
        'found_count' => 'gefunden',
        'no_results' => 'Keine Dateien oder Ordner gefunden.',
        'th_name' => 'Name',
        'th_folder' => 'Ordner',
        'th_type' => 'Typ',
        'th_size' => 'Größe',
        'th_perms' => 'Berechtigungen',
        'th_actions' => 'Aktion',
        'parent_dir' => '.. (Eine Ebene höher)',
        'type_dir' => 'Ordner',
        'type_file' => 'Datei',
        'action_view' => 'Anzeigen',
        'action_edit' => 'Bearbeiten',
        'action_run_web' => 'Als Webseite ausführen',
        'action_download' => 'Herunterladen',
        'action_download_zip' => 'Herunterladen (ZIP)',
        'action_rename' => 'Umbenennen',
        'action_copy' => 'Kopieren',
        'action_paste' => 'Einfügen',
        'action_chmod' => 'Berechtigungen',
        'action_delete' => 'Löschen',
        'prompt_rename' => "Neuen Namen eingeben:",
        'prompt_chmod' => "Berechtigungen festlegen (z.B. 0644 für Dateien oder 0755 für Ordner):",
        'confirm_delete' => "Möchten Sie löschen",
        'back_to_files' => 'Zurück',
        'save_changes' => 'Änderungen speichern',
        'save_success' => 'Änderungen erfolgreich gespeichert!',
        'save_error' => 'Fehler: Konnte nicht in die Datei speichern (Berechtigungen oder Schreibschutz prüfen)!',
        'delete_error' => 'Fehler: Konnte Element nicht löschen (Berechtigungen oder ob Ordner leer ist prüfen)!'
    ],
    'fr' => [
        'title' => 'PHP - Gestionnaire de fichiers',
        'subtitle' => 'Développé par H. Bjerkan avec l\'aide de Gemini',
        'login_header' => 'PHP - Gestionnaire de fichiers',
        'username' => 'Nom d\'utilisateur',
        'password' => 'Mot de passe',
        'login_btn' => 'Se connecter',
        'login_error' => 'Nom d\'utilisateur ou mot de passe invalide !',
        'logout' => 'Se déconnecter',
        'logged_in_as' => 'Connecté en tant que :',
        'guest' => 'Invité',
        'home_root' => 'Accueil / Racine',
        'sidebar_title' => 'Structure des dossiers',
        'path_label' => 'Chemin :',
        'new_file_placeholder' => 'Nouveau nom de fichier...',
        'new_file_btn' => '+ Nouveau fichier',
        'new_folder_placeholder' => 'Nouveau nom de dossier...',
        'new_folder_btn' => '+ Nouveau dossier',
        'upload_files_btn' => 'Téléverser fichier(s)',
        'upload_folder_btn' => 'Téléverser dossier',
        'search_placeholder' => 'Rechercher dans le dossier...',
        'search_btn' => 'Rechercher',
        'reset_btn' => 'Réinitialiser',
        'search_results' => 'Résultats de recherche pour',
        'found_count' => 'trouvé(s)',
        'no_results' => 'Aucun fichier ni dossier trouvé.',
        'th_name' => 'Nom',
        'th_folder' => 'Dossier',
        'th_type' => 'Type',
        'th_size' => 'Taille',
        'th_perms' => 'Permissions',
        'th_actions' => 'Action',
        'parent_dir' => '.. (Niveau supérieur)',
        'type_dir' => 'Dossier',
        'type_file' => 'Fichier',
        'action_view' => 'Voir',
        'action_edit' => 'Modifier',
        'action_run_web' => 'Exécuter en page Web',
        'action_download' => 'Télécharger',
        'action_download_zip' => 'Télécharger (ZIP)',
        'action_rename' => 'Renommer',
        'action_copy' => 'Copier',
        'action_paste' => 'Coller',
        'action_chmod' => 'Permissions',
        'action_delete' => 'Supprimer',
        'prompt_rename' => "Entrez le nouveau nom :",
        'prompt_chmod' => "Définir les permissions (ex. 0644 pour les fichiers ou 0755 pour les dossiers) :",
        'confirm_delete' => "Voulez-vous supprimer",
        'back_to_files' => 'Retour',
        'save_changes' => 'Enregistrer les modifications',
        'save_success' => 'Modifications enregistrées avec succès !',
        'save_error' => 'Erreur : Impossible d\'enregistrer dans le fichier (vérifiez les permissions ou la protection en écriture) !',
        'delete_error' => 'Erreur : Impossible de supprimer l\'élément (vérifiez les permissions ou si le dossier est vide) !'
    ],
    'fi' => [
        'title' => 'PHP - Tiedostonhallinta',
        'subtitle' => 'Kehittänyt H. Bjerkan Geminin avulla',
        'login_header' => 'PHP - Tiedostonhallinta',
        'username' => 'Käyttäjätunnus',
        'password' => 'Salasana',
        'login_btn' => 'Kirjaudu sisään',
        'login_error' => 'Virheellinen käyttäjätunnus tai salasana!',
        'logout' => 'Kirjaudu ulos',
        'logged_in_as' => 'Kirjautuneena:',
        'guest' => 'Vieras',
        'home_root' => 'Koti / Juurikansio',
        'sidebar_title' => 'Kansiorakenne',
        'path_label' => 'Polku:',
        'new_file_placeholder' => 'Uusi tiedostonimi...',
        'new_file_btn' => '+ Uusi tiedosto',
        'new_folder_placeholder' => 'Uusi kansionimi...',
        'new_folder_btn' => '+ Uusi kansio',
        'upload_files_btn' => 'Lataa tiedosto(ja)',
        'upload_folder_btn' => 'Lataa kansio',
        'search_placeholder' => 'Etsi kansiosta...',
        'search_btn' => 'Etsi',
        'reset_btn' => 'Nollaa',
        'search_results' => 'Hakutulokset hakusanalle',
        'found_count' => 'löytyi',
        'no_results' => 'Tiedostoja tai kansioita ei löytynyt.',
        'th_name' => 'Nimi',
        'th_folder' => 'Kansio',
        'th_type' => 'Tyyppi',
        'th_size' => 'Koko',
        'th_perms' => 'Oikeudet',
        'th_actions' => 'Toiminto',
        'parent_dir' => '.. (Yksi taso ylöspäin)',
        'type_dir' => 'Kansio',
        'type_file' => 'Tiedosto',
        'action_view' => 'Näytä',
        'action_edit' => 'Muokkaa',
        'action_run_web' => 'Suorita verkkosivuna',
        'action_download' => 'Lataa',
        'action_download_zip' => 'Lataa (ZIP)',
        'action_rename' => 'Nimeä uudelleen',
        'action_copy' => 'Kopioi',
        'action_paste' => 'Liitä',
        'action_chmod' => 'Oikeudet',
        'action_delete' => 'Poista',
        'prompt_rename' => "Syötä uusi nimi:",
        'prompt_chmod' => "Aseta oikeudet (esim. 0644 tiedostoille tai 0755 kansioille):",
        'confirm_delete' => "Haluatko poistaa",
        'back_to_files' => 'Takaisin',
        'save_changes' => 'Tallenna muutokset',
        'save_success' => 'Muutokset tallennettu onnistuneesti!',
        'save_error' => 'Virhe: Tiedostoon ei voitu tallentaa (tarkista oikeudet)!',
        'delete_error' => 'Virhe: Kohdetta ei voitu poistaa (tarkista oikeudet tai onko kansio tyhjä)!'
    ]
];

$t = $lang[$current_lang];

$conf_user = $config['username'];
$conf_pass = $config['password'];

// Innloggingshåndtering
if ($config['use_login']) {
    if (isset($_POST['action']) && $_POST['action'] === 'login') {
        $input_user = isset($_POST['username']) ? trim($_POST['username']) : '';
        $input_pass = isset($_POST['password']) ? $_POST['password'] : '';

        if ($input_user === $conf_user && $input_pass === $conf_pass) {
            $_SESSION['loggedin'] = true;
            $_SESSION['username'] = $input_user;
            header("Location: " . $_SERVER['PHP_SELF']);
            exit;
        } else {
            $login_error = $t['login_error'];
        }
    }

    if (isset($_GET['action']) && $_GET['action'] === 'logout') {
        session_destroy();
        header("Location: " . strtok($_SERVER["REQUEST_URI"], '?'));
        exit;
    }

    if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
        ?>
        <!DOCTYPE html>
        <html lang="<?php echo $current_lang; ?>">
        <head>
            <meta charset="UTF-8">
            <title><?php echo htmlspecialchars($t['login_header']); ?></title>
            <style>
                body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background: #f8f9fa; margin: 0; }
                .login-box { background: white; padding: 30px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); width: 320px; text-align: left; position: relative; }
                .login-version { font-size: 11px; color: #7f8c8d; font-weight: normal; margin-bottom: 6px; }
                .login-box h2 { margin-top: 0; margin-bottom: 5px; text-align: center; }
                .login-subtitle { font-size: 12px; color: #666; margin-bottom: 20px; text-align: center; }
                input[type="text"], input[type="password"] { width: 100%; padding: 10px; margin: 8px 0; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; }
                button { width: 100%; background: #3498db; color: white; border: none; padding: 10px; border-radius: 4px; cursor: pointer; font-size: 14px; margin-top: 10px; }
                button:hover { opacity: 0.9; }
                .error { color: #e74c3c; font-size: 13px; margin-bottom: 10px; text-align: center; }
            </style>
        </head>
        <body>
            <div class="login-box">
                <div class="login-version"><?php echo htmlspecialchars($ver); ?></div>
                <h2><?php echo htmlspecialchars($t['login_header']); ?></h2>
                <div class="login-subtitle"><?php echo htmlspecialchars($t['subtitle']); ?></div>
                <?php if (isset($login_error)): ?>
                    <div class="error"><?php echo $login_error; ?></div>
                <?php endif; ?>
                <form method="POST">
                    <input type="hidden" name="action" value="login">
                    <label style="font-size: 12px; color: #555; font-weight: bold;"><?php echo htmlspecialchars($t['username']); ?></label>
                    <input type="text" name="username" value="<?php echo htmlspecialchars($conf_user); ?>" required autofocus>
                    <label style="font-size: 12px; color: #555; font-weight: bold;"><?php echo htmlspecialchars($t['password']); ?></label>
                    <input type="password" name="password" placeholder="<?php echo htmlspecialchars($t['password']); ?>" required>
                    <button type="submit"><?php echo htmlspecialchars($t['login_btn']); ?></button>
                </form>
            </div>
        </body>
        </html>
        <?php
        exit;
    }
}

// STIBEREGNING
$base_dir = realpath(__DIR__);
$current_path = isset($_GET['path']) ? $_GET['path'] : '';
$target_dir = realpath($base_dir . ($base_dir === '/' || substr($base_dir, -1) === '\\' ? '' : '/') . $current_path);

if ($target_dir === false || strpos($target_dir, $base_dir) !== 0) {
    $target_dir = $base_dir;
    $current_path = '';
}

// --- HANDLINGER ---

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'mkdir') {
    $new_folder = trim($_POST['folder_name']);
    if (!empty($new_folder)) {
        @mkdir($target_dir . '/' . $new_folder, 0777, true);
    }
    header("Location: ?path=" . urlencode($current_path));
    exit;
}

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'mkfile') {
    $new_file = trim($_POST['file_name']);
    if (!empty($new_file)) {
        $path_to_create = $target_dir . '/' . $new_file;
        if (!file_exists($path_to_create) && $path_to_create !== __FILE__) {
            @file_put_contents($path_to_create, '');
        }
    }
    header("Location: ?path=" . urlencode($current_path));
    exit;
}

// Opplasting av filer
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upload_files') {
    if (isset($_FILES['files'])) {
        $file_count = count($_FILES['files']['name']);
        for ($i = 0; $i < $file_count; $i++) {
            if ($_FILES['files']['error'][$i] === UPLOAD_ERR_OK) {
                $tmp_name = $_FILES['files']['tmp_name'][$i];
                $name = basename($_FILES['files']['name'][$i]);
                @move_uploaded_file($tmp_name, $target_dir . '/' . $name);
            }
        }
    }
    header("Location: ?path=" . urlencode($current_path));
    exit;
}

// Opplasting av mappe
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upload_folder') {
    if (isset($_FILES['folder_files'])) {
        $file_count = count($_FILES['folder_files']['name']);
        for ($i = 0; $i < $file_count; $i++) {
            if ($_FILES['folder_files']['error'][$i] === UPLOAD_ERR_OK) {
                $tmp_name = $_FILES['folder_files']['tmp_name'][$i];
                $rel_path = $_FILES['folder_files']['full_path'][$i] ?? $_FILES['folder_files']['name'][$i];
                
                $dest_path = $target_dir . '/' . $rel_path;
                $dest_dir = dirname($dest_path);
                
                if (!is_dir($dest_dir)) {
                    @mkdir($dest_dir, 0777, true);
                }
                @move_uploaded_file($tmp_name, $dest_path);
            }
        }
    }
    header("Location: ?path=" . urlencode($current_path));
    exit;
}

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'rename') {
    $old_name = basename($_POST['item_name']);
    $new_name = basename($_POST['new_name']);
    $action_dir = realpath($base_dir . '/' . $_POST['action_path']);
    if ($action_dir && strpos($action_dir, $base_dir) === 0 && !empty($new_name)) {
        @rename($action_dir . '/' . $old_name, $action_dir . '/' . $new_name);
    }
    header("Location: ?path=" . urlencode($current_path));
    exit;
}

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'chmod') {
    $item_name = basename($_POST['item_name']);
    $action_dir = realpath($base_dir . '/' . trim($_POST['action_path'], '/'));
    $new_perms = trim($_POST['permissions']);
    if ($action_dir && strpos($action_dir, $base_dir) === 0 && preg_match('/^[0-7]{3,4}$/', $new_perms)) {
        @chmod($action_dir . '/' . $item_name, octdec($new_perms));
    }
    header("Location: ?path=" . urlencode($current_path));
    exit;
}

// Slette med direkte feilmelding via URL ved feil
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'delete') {
    $item_name = basename($_POST['item_name']);
    $action_dir = realpath($base_dir . '/' . $_POST['action_path']);
    $error_msg = '';
    
    if ($action_dir && strpos($action_dir, $base_dir) === 0) {
        $target_p = $action_dir . '/' . $item_name;
        if (file_exists($target_p) && $target_p !== __FILE__) {
            $success = is_dir($target_p) ? rmdir($target_p) : unlink($target_p);
            if (!$success) {
                $error_msg = '&error=' . urlencode($t['delete_error']);
            }
        }
    }
    header("Location: ?path=" . urlencode($_POST['action_path']) . $error_msg);
    exit;
}

// Dedikert avspillingsside for MP3
if (isset($_GET['play_mp3'])) {
    $mp3_path = isset($_GET['p_path']) ? $_GET['p_path'] : $current_path;
    $mp3_target_dir = realpath($base_dir . '/' . $mp3_path);
    if ($mp3_target_dir && strpos($mp3_target_dir, $base_dir) === 0) {
        $mp3_file = realpath($mp3_target_dir . '/' . $_GET['play_mp3']);
        if ($mp3_file && strpos($mp3_file, $base_dir) === 0 && is_file($mp3_file) && strtolower(pathinfo($mp3_file, PATHINFO_EXTENSION)) === 'mp3') {
            $rel_mp3_url = ltrim(substr($mp3_file, strlen($base_dir)), '/\\');
            ?>
            <!DOCTYPE html>
            <html lang="<?php echo $current_lang; ?>">
            <head>
                <meta charset="UTF-8">
                <title>Spill av: <?php echo htmlspecialchars(basename($mp3_file)); ?></title>
                <style>
                    body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; margin: 40px; background: #f8f9fa; display: flex; justify-content: center; align-items: center; height: 80vh; }
                    .player-box { background: white; padding: 30px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); text-align: center; width: 400px; }
                    .btn { background: #3498db; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; text-decoration: none; display: inline-block; font-size: 13px; margin-top: 20px; }
                    .btn:hover { opacity: 0.9; }
                    audio { width: 100%; margin-top: 15px; }
                </style>
            </head>
            <body>
                <div class="player-box">
                    <h2>🎵 <?php echo htmlspecialchars(basename($mp3_file)); ?></h2>
                    <audio controls autoplay>
                        <source src="<?php echo htmlspecialchars($rel_mp3_url); ?>" type="audio/mpeg">
                        Nettleseren din støtter ikke lydavspilling.
                    </audio>
                    <br>
                    <a href="?path=<?php echo urlencode($mp3_path); ?>" class="btn"><?php echo $t['back_to_files']; ?></a>
                </div>
            </body>
            </html>
            <?php
            exit;
        }
    }
}

// Rediger fil med teller og feilsjekk på lagring
if (isset($_GET['edit'])) {
    $e_path = isset($_GET['e_path']) ? $_GET['e_path'] : $current_path;
    $e_target_dir = realpath($base_dir . '/' . $e_path);
    if ($e_target_dir && strpos($e_target_dir, $base_dir) === 0) {
        $item_to_edit = realpath($e_target_dir . '/' . $_GET['edit']);
        if ($item_to_edit && strpos($item_to_edit, $base_dir) === 0 && is_file($item_to_edit)) {
            
            if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'save_file') {
                $bytes_written = @file_put_contents($item_to_edit, $_POST['file_content']);
                if ($bytes_written !== false) {
                    if (!isset($_SESSION['save_counter'])) {
                        $_SESSION['save_counter'] = 0;
                    }
                    $_SESSION['save_counter']++;
                    $save_message = $t['save_success'] . " (Lagring nr. " . $_SESSION['save_counter'] . ")";
                    $is_error = false;
                } else {
                    $save_message = $t['save_error'];
                    $is_error = true;
                }
            }
            
            $file_content = file_get_contents($item_to_edit);
            ?>
            <!DOCTYPE html>
            <html lang="<?php echo $current_lang; ?>">
            <head>
                <meta charset="UTF-8">
                <title>Rediger: <?php echo htmlspecialchars(basename($item_to_edit)); ?></title>
                <style>
                    body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; margin: 20px; background: #f8f9fa; }
                    .edit-container { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
                    textarea { width: 100%; height: 500px; font-family: monospace; font-size: 13px; padding: 10px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; margin-top: 10px; }
                    .btn { background: #3498db; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; text-decoration: none; display: inline-block; font-size: 13px; }
                    .btn-back { background: #95a5a6; margin-right: 10px; }
                    .btn:hover { opacity: 0.9; }
                    <?php 
                    $msg_bg = (isset($is_error) && $is_error) ? '#e74c3c' : '#2ecc71'; 
                    ?>
                    .msg { background: <?php echo $msg_bg; ?>; color: white; padding: 10px; border-radius: 4px; margin-bottom: 15px; font-weight: bold; }
                </style>
            </head>
            <body>
                <div class="edit-container">
                    <?php if (isset($save_message)): ?>
                        <div class="msg"><?php echo $save_message; ?></div>
                    <?php endif; ?>
                    <h2>Rediger: <?php echo htmlspecialchars(basename($item_to_edit)); ?></h2>
                    <form method="POST">
                        <input type="hidden" name="action" value="save_file">
                        <button type="submit" class="btn"><?php echo $t['save_changes']; ?></button>
                        <a href="?path=<?php echo urlencode($e_path); ?>&reset_counter=1" class="btn btn-back" style="margin-left: 10px;"><?php echo $t['back_to_files']; ?></a>
                        <br><br>
                        <textarea name="file_content"><?php echo htmlspecialchars($file_content); ?></textarea>
                    </form>
                </div>
            </body>
            </html>
            <?php
            exit;
        }
    }
}

// Les inn filer og mapper
$dirs = [];
$files = [];
$search_query = isset($_GET['search']) ? trim($_GET['search']) : '';
$is_searching = ($search_query !== '');

if ($is_searching) {
    function recursiveSearch($dir, $base_dir, $query, &$results) {
        $items = @scandir($dir);
        if ($items === false) return;
        foreach ($items as $item) {
            if ($item === '.' || $item === '..') continue;
            $full_path = $dir . '/' . $item;
            if (stripos($item, $query) !== false) {
                $rel_path = ltrim(substr($full_path, strlen($base_dir)), '/\\');
                $results[] = [
                    'name' => $item,
                    'path' => $rel_path,
                    'is_dir' => is_dir($full_path),
                    'dir_path' => dirname($rel_path)
                ];
            }
            if (is_dir($full_path) && !is_link($full_path)) {
                recursiveSearch($full_path, $base_dir, $query, $results);
            }
        }
    }
    $search_results = [];
    recursiveSearch($target_dir, $base_dir, $search_query, $search_results);
} else {
    $scan_items = @scandir($target_dir);
    if ($scan_items !== false) {
        foreach ($scan_items as $item) {
            if ($item === '.' || $item === '..') continue;
            $full_path = $target_dir . '/' . $item;
            if (is_dir($full_path)) {
                $dirs[] = ['name' => $item, 'path' => ($current_path !== '' ? $current_path . '/' : '') . $item];
            } else {
                $files[] = ['name' => $item, 'path' => ($current_path !== '' ? $current_path . '/' : '') . $item];
            }
        }
    }
}

// Funksjon for mappestruktur i sidepanel
function getFolderTree($dir, $base_dir, $current_path) {
    $result = '';
    $items = @scandir($dir);
    if ($items === false) return $result;

    $result .= '<ul>';
    $count = 0;
    foreach ($items as $item) {
        if ($item === '.' || $item === '..') continue;
        $full_path = $dir . '/' . $item;
        if (is_dir($full_path) && !is_link($full_path)) {
            $rel_path = ltrim(substr($full_path, strlen($base_dir)), '/\\');
            $is_active = ($current_path === $rel_path) ? ' style="font-weight:bold; color:#2980b9;"' : '';
            $result .= '<li>📁 <a href="?path=' . urlencode($rel_path) . '"' . $is_active . '>' . htmlspecialchars($item) . '</a>';
            $sub_items = @scandir($full_path);
            if ($sub_items !== false && count($sub_items) < 50) {
                $result .= '<ul>';
                foreach ($sub_items as $sub) {
                    if ($sub === '.' || $sub === '..') continue;
                    $sub_full = $full_path . '/' . $sub;
                    if (is_dir($sub_full) && !is_link($sub_full)) {
                        $sub_rel = ltrim(substr($sub_full, strlen($base_dir)), '/\\');
                        $sub_active = ($current_path === $sub_rel) ? ' style="font-weight:bold; color:#2980b9;"' : '';
                        $result .= '<li>📁 <a href="?path=' . urlencode($sub_rel) . '"' . $sub_active . '>' . htmlspecialchars($sub) . '</a></li>';
                    }
                }
                $result .= '</ul>';
            }
            $result .= '</li>';
            if (++$count > 30) { break; }
        }
    }
    $result .= '</ul>';
    return $result;
}
?>
<!DOCTYPE html>
<html lang="<?php echo $current_lang; ?>">
<head>
    <meta charset="UTF-8">
    <title><?php echo htmlspecialchars($t['title']); ?></title>
    <style>
        body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 13px; margin: 0; background: #f8f9fa; color: #333; display: flex; flex-direction: column; height: 100vh; }
        .header { display: flex; justify-content: space-between; align-items: flex-start; padding: 15px 20px; border-bottom: 2px solid #e9ecef; background: white; }
        .header-title h1 { margin: 0; font-size: 20px; }
        .header-version { font-size: 11px; color: #7f8c8d; font-weight: normal; margin-bottom: 4px; }
        .header-subtitle { font-size: 12px; color: #666; margin-top: 4px; }
        .user-info { font-size: 12px; display: flex; align-items: center; gap: 15px; }
        
        .logout-btn { background: #e74c3c; color: white !important; padding: 6px 12px; border-radius: 4px; text-decoration: none; font-weight: bold; display: inline-block; box-shadow: 0 1px 3px rgba(0,0,0,0.15); }
        .logout-btn:hover { background: #c0392b; opacity: 1; }
        
        .lang-dropdown { position: relative; display: inline-block; margin-left: 10px; }
        .lang-btn { background: none; border: 1px solid #ccc; padding: 2px 6px; cursor: pointer; border-radius: 4px; vertical-align: middle; display: inline-flex; align-items: center; gap: 4px; }
        .lang-menu { display: none; position: absolute; right: 0; top: 100%; background: white; border: 1px solid #ccc; box-shadow: 0 4px 12px rgba(0,0,0,0.15); border-radius: 4px; z-index: 99999; min-width: 100px; }
        .lang-menu a { display: flex; align-items: center; gap: 6px; padding: 6px 10px; text-decoration: none; color: #333; font-size: 11px; font-weight: bold; }
        .lang-menu a:hover { background: #3498db; color: white; }

        .main-layout { display: flex; flex: 1; overflow: hidden; }
        .sidebar { width: 260px; background: #fff; border-right: 1px solid #e9ecef; padding: 15px; overflow-y: auto; box-sizing: border-box; }
        .sidebar h3 { font-size: 14px; margin-top: 0; color: #2c3e50; border-bottom: 1px solid #eee; padding-bottom: 8px; }
        .sidebar ul { list-style: none; padding-left: 15px; margin: 5px 0; }
        .sidebar li { margin: 4px 0; }
        .sidebar a { text-decoration: none; color: #333; font-size: 12px; }
        .sidebar a:hover { text-decoration: underline; color: #2980b9; }

        .content-area { flex: 1; padding: 20px; overflow-y: auto; background: #f8f9fa; box-sizing: border-box; }
        .toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 15px; background: white; padding: 12px; border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
        .toolbar form { display: flex; gap: 5px; align-items: center; margin: 0; }
        input[type="text"] { padding: 6px 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 12px; }
        .btn { background: #3498db; color: white; border: none; padding: 6px 12px; border-radius: 4px; cursor: pointer; font-size: 12px; text-decoration: none; display: inline-block; }
        .btn:hover { opacity: 0.9; }
        
        .path-bar { font-size: 13px; margin-bottom: 15px; background: #ffffff; border: 1px solid #ccc; padding: 8px 10px; border-radius: 4px; }
        .path-bar a { color: #2980b9; text-decoration: none; }
        
        table { width: 100%; border-collapse: collapse; background: white; border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
        th, td { padding: 8px; text-align: left; border-bottom: 1px solid #eee; vertical-align: middle; }
        th { background: #ffe066; color: #5f4300; font-weight: 700; font-size: 12px; border-bottom: 2px solid #fcc419; }
        tr.file-row:nth-child(even) { background-color: #f0f7ff; }
        tr.file-row:hover { background: #e2e8f0; }
        
        .icon-cell { width: 40px; text-align: center; overflow: visible !important; }
        .icon-menu-btn { background: none; border: none; padding: 2px 4px; cursor: pointer; font-size: 1.1rem; border-radius: 3px; line-height: 1; vertical-align: middle; }
        .icon-menu-btn:hover { background: #cbd5e1; }
        
        .svg-icon { width: 16px; height: 16px; vertical-align: middle; fill: currentColor; }
        
        .action-dropdown-wrapper { position: relative; display: inline-block; }
        .dropdown-menu { display: none; position: absolute; top: 100%; left: 0; z-index: 99999; background: #ffffff; border: 1px solid #ccc; box-shadow: 0 4px 12px rgba(0,0,0,0.15); min-width: 130px; border-radius: 4px; text-align: left; }
        .dropdown-menu a { display: block; padding: 4px 8px; text-decoration: none; color: #333; font-size: 11px; font-weight: bold; }
        .dropdown-menu a:hover { background: #3498db; color: #fff; }
        .dropdown-menu a.text-danger:hover { background: #e74c3c; color: #fff; }
        .name-cell a { text-decoration: none; color: #2980b9; }
        .global-error { background: #e74c3c; color: white; padding: 10px; border-radius: 4px; margin-bottom: 15px; font-weight: bold; }
    </style>
    <script>
        function toggleRowMenu(event, btn) {
            event.stopPropagation();
            var currentMenu = btn.nextElementSibling;
            document.querySelectorAll('.dropdown-menu, .lang-menu').forEach(function(m) {
                if (m !== currentMenu) { m.style.display = 'none'; }
            });
            currentMenu.style.display = (currentMenu.style.display === 'block') ? 'none' : 'block';
        }

        function toggleLangMenu(event, btn) {
            event.stopPropagation();
            var currentMenu = btn.nextElementSibling;
            document.querySelectorAll('.dropdown-menu, .lang-menu').forEach(function(m) {
                if (m !== currentMenu) { m.style.display = 'none'; }
            });
            currentMenu.style.display = (currentMenu.style.display === 'block') ? 'none' : 'block';
        }

        document.addEventListener('click', function() {
            document.querySelectorAll('.dropdown-menu, .lang-menu').forEach(function(m) { m.style.display = 'none'; });
        });

        function renameItem(actionPath, itemName) {
            var newName = prompt("<?php echo $t['prompt_rename']; ?>", itemName);
            if (newName !== null && newName.trim() !== '') {
                var form = document.createElement('form');
                form.method = 'POST';
                form.innerHTML = '<input type="hidden" name="action" value="rename"><input type="hidden" name="action_path" value="' + actionPath + '"><input type="hidden" name="item_name" value="' + itemName + '"><input type="hidden" name="new_name" value="' + newName.trim() + '">';
                document.body.appendChild(form);
                form.submit();
            }
        }

        function chmodItem(actionPath, itemName) {
            var perms = prompt("<?php echo $t['prompt_chmod']; ?>", "0644");
            if (perms !== null && perms.trim() !== '') {
                var form = document.createElement('form');
                form.method = 'POST';
                form.innerHTML = '<input type="hidden" name="action" value="chmod"><input type="hidden" name="action_path" value="' + actionPath + '"><input type="hidden" name="item_name" value="' + itemName + '"><input type="hidden" name="permissions" value="' + perms + '">';
                document.body.appendChild(form);
                form.submit();
            }
        }

        function deleteItem(actionPath, itemName) {
            if (confirm("<?php echo $t['confirm_delete']; ?> " + itemName + "?")) {
                var form = document.createElement('form');
                form.method = 'POST';
                form.innerHTML = '<input type="hidden" name="action" value="delete"><input type="hidden" name="action_path" value="' + actionPath + '"><input type="hidden" name="item_name" value="' + itemName + '">';
                document.body.appendChild(form);
                form.submit();
            }
        }
    </script>
</head>
<body>

<div class="header">
    <div class="header-title">
        <div class="header-version"><?php echo htmlspecialchars($ver); ?></div>
        <h1><?php echo htmlspecialchars($t['title']); ?></h1>
        <div class="header-subtitle"><?php echo htmlspecialchars($t['subtitle']); ?></div>
    </div>
    <div class="user-info">
        <div>
            <?php echo $t['logged_in_as']; ?> <strong><?php echo htmlspecialchars($_SESSION['username'] ?? $t['guest']); ?></strong>
            <a href="?action=logout" class="logout-btn"><?php echo $t['logout']; ?></a>
        </div>
        <div class="lang-dropdown">
            <button type="button" class="lang-btn" onclick="toggleLangMenu(event, this)" title="Velg språk / Select language">
                <?php if ($current_lang === 'no'): ?>
                    <svg width="20" height="14" viewBox="0 0 22 16"><rect width="22" height="16" fill="#ba0c2f"/><rect x="6" width="4" height="16" fill="#ffffff"/><rect y="6" width="22" height="4" fill="#ffffff"/><rect x="7" width="2" height="16" fill="#00205b"/><rect y="7" width="22" height="2" fill="#00205b"/></svg> NO
                <?php elseif ($current_lang === 'en'): ?>
                    <svg width="20" height="14" viewBox="0 0 60 30"><rect width="60" height="30" fill="#012169"/><path d="M0,0 L60,30 M60,0 L0,30" stroke="#fff" stroke-width="6"/><path d="M0,0 L60,30 M60,0 L0,30" stroke="#C8102E" stroke-width="4"/><path d="M30,0 V30 M0,15 H60" stroke="#fff" stroke-width="10"/><path d="M30,0 V30 M0,15 H60" stroke="#C8102E" stroke-width="6"/></svg> EN
                <?php elseif ($current_lang === 'sv'): ?>
                    <svg width="20" height="14" viewBox="0 0 16 10"><rect width="16" height="10" fill="#006aa7"/><rect x="5" width="2" height="10" fill="#fecc00"/><rect y="4" width="16" height="2" fill="#fecc00"/></svg> SV
                <?php elseif ($current_lang === 'da'): ?>
                    <svg width="20" height="14" viewBox="0 0 37 28"><rect width="37" height="28" fill="#c8102e"/><rect x="12" width="4" height="28" fill="#ffffff"/><rect y="12" width="37" height="4" fill="#ffffff"/></svg> DA
                <?php elseif ($current_lang === 'de'): ?>
                    <svg width="20" height="14" viewBox="0 0 5 3"><rect width="5" height="1" y="0" fill="#000"/><rect width="5" height="1" y="1" fill="#d00"/><rect width="5" height="1" y="2" fill="#ffce00"/></svg> DE
                <?php elseif ($current_lang === 'fr'): ?>
                    <svg width="20" height="14" viewBox="0 0 3 2"><rect width="1" height="2" x="0" fill="#002395"/><rect width="1" height="2" x="1" fill="#fff"/><rect width="1" height="2" x="2" fill="#ed2939"/></svg> FR
                <?php elseif ($current_lang === 'fi'): ?>
                    <svg width="20" height="14" viewBox="0 0 18 11"><rect width="18" height="11" fill="#ffffff"/><rect x="5" width="3" height="11" fill="#003580"/><rect y="4" width="18" height="3" fill="#003580"/></svg> FI
                <?php endif; ?>
            </button>
            <div class="lang-menu">
                <a href="?lang=no<?php echo $current_path !== '' ? '&path=' . urlencode($current_path) : ''; ?>">Norsk</a>
                <a href="?lang=en<?php echo $current_path !== '' ? '&path=' . urlencode($current_path) : ''; ?>">English</a>
                <a href="?lang=sv<?php echo $current_path !== '' ? '&path=' . urlencode($current_path) : ''; ?>">Svenska</a>
                <a href="?lang=da<?php echo $current_path !== '' ? '&path=' . urlencode($current_path) : ''; ?>">Dansk</a>
                <a href="?lang=de<?php echo $current_path !== '' ? '&path=' . urlencode($current_path) : ''; ?>">Deutsch</a>
                <a href="?lang=fr<?php echo $current_path !== '' ? '&path=' . urlencode($current_path) : ''; ?>">Français</a>
                <a href="?lang=fi<?php echo $current_path !== '' ? '&path=' . urlencode($current_path) : ''; ?>">Suomi</a>
            </div>
        </div>
    </div>
</div>

<div class="main-layout">
    <div class="sidebar">
        <h3>📁 <?php echo htmlspecialchars($t['sidebar_title']); ?></h3>
        <div>
            <a href="?"><strong><?php echo htmlspecialchars($t['home_root']); ?></strong></a>
            <?php echo getFolderTree($base_dir, $base_dir, $current_path); ?>
        </div>
    </div>

    <div class="content-area">
        <?php if (isset($_GET['error'])): ?>
            <div class="global-error"><?php echo htmlspecialchars($_GET['error']); ?></div>
        <?php endif; ?>

        <div class="toolbar">
            <form method="POST">
                <input type="hidden" name="action" value="mkfile">
                <input type="text" name="file_name" placeholder="<?php echo $t['new_file_placeholder']; ?>" required>
                <button type="submit" class="btn"><?php echo $t['new_file_btn']; ?></button>
            </form>

            <form method="POST">
                <input type="hidden" name="action" value="mkdir">
                <input type="text" name="folder_name" placeholder="<?php echo $t['new_folder_placeholder']; ?>" required>
                <button type="submit" class="btn"><?php echo $t['new_folder_btn']; ?></button>
            </form>

            <form method="POST" enctype="multipart/form-data">
                <input type="hidden" name="action" value="upload_files">
                <input type="file" name="files[]" multiple required style="display:none;" id="file-upload-input" onchange="this.form.submit()">
                <button type="button" class="btn" onclick="document.getElementById('file-upload-input').click()"><?php echo $t['upload_files_btn']; ?></button>
            </form>

            <form method="POST" enctype="multipart/form-data">
                <input type="hidden" name="action" value="upload_folder">
                <input type="file" name="folder_files[]" webkitdirectory directory multiple required style="display:none;" id="folder-upload-input" onchange="this.form.submit()">
                <button type="button" class="btn" onclick="document.getElementById('folder-upload-input').click()"><?php echo $t['upload_folder_btn']; ?></button>
            </form>

            <form method="GET">
                <?php if ($current_path !== ''): ?>
                    <input type="hidden" name="path" value="<?php echo htmlspecialchars($current_path); ?>">
                <?php endif; ?>
                <input type="text" name="search" placeholder="<?php echo $t['search_placeholder']; ?>" value="<?php echo htmlspecialchars($search_query); ?>" required>
                <button type="submit" class="btn"><?php echo $t['search_btn']; ?></button>
                <?php if ($is_searching): ?>
                    <a href="?<?php echo $current_path !== '' ? 'path=' . urlencode($current_path) : ''; ?>" class="btn" style="background: #95a5a6;"><?php echo $t['reset_btn']; ?></a>
                <?php endif; ?>
            </form>
        </div>

        <div class="path-bar">
            <strong><?php echo $t['path_label']; ?></strong>
            <a href="?"><?php echo $t['home_root']; ?></a>
            <?php
            if ($current_path !== '') {
                $parts = explode('/', trim($current_path, '/'));
                $accum = '';
                foreach ($parts as $part) {
                    $accum .= ($accum === '' ? '' : '/') . $part;
                    echo ' / <a href="?path=' . urlencode($accum) . '">' . htmlspecialchars($part) . '</a>';
                }
            }
            ?>
        </div>

        <?php if ($is_searching): ?>
            <div style="margin-bottom: 15px; font-weight: bold; color: #2c3e50;">
                <?php echo $t['search_results']; ?> "<?php echo htmlspecialchars($search_query); ?>" (<?php echo count($search_results); ?> <?php echo $t['found_count']; ?>):
            </div>
            <table>
                <thead>
                    <tr>
                        <th style="width: 40px; text-align: center;">📁/📄</th>
                        <th><?php echo $t['th_name']; ?></th>
                        <th><?php echo $t['th_folder']; ?></th>
                        <th><?php echo $t['th_type']; ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php if (empty($search_results)): ?>
                        <tr>
                            <td colspan="4" style="text-align: center; color: #7f8c8d; padding: 20px;"><?php echo $t['no_results']; ?></td>
                        </tr>
                    <?php else: ?>
                        <?php foreach ($search_results as $res): ?>
                            <?php 
                            $res_ext = strtolower(pathinfo($res['name'], PATHINFO_EXTENSION));
                            $res_is_mp3 = ($res_ext === 'mp3');
                            $res_is_php = ($res_ext === 'php');
                            $res_viewable_exts = ['pdf', 'jpg', 'jpeg', 'png', 'gif', 'svg', 'mp4', 'txt', 'html', 'htm', 'php', 'pl'];
                            $res_is_viewable = in_array($res_ext, $res_viewable_exts) || $res_is_mp3;
                            $res_run_as_web = $res_is_php ? $config['run_php_as_web'] : $res_is_viewable;
                            ?>
                            <tr class="file-row">
                                <td class="icon-cell">
                                    <div class="action-dropdown-wrapper">
                                        <button type="button" class="icon-menu-btn" onclick="toggleRowMenu(event, this)" title="Handlinger">
                                            <?php if ($res['is_dir']): ?>
                                                <svg class="svg-icon" style="color: <?php echo $config['folder_color']; ?>;" viewBox="0 0 24 24"><path d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg>
                                            <?php else: ?>
                                                <svg class="svg-icon" style="color: <?php echo $config['file_color']; ?>;" viewBox="0 0 24 24"><path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z"/></svg>
                                            <?php endif; ?>
                                        </button>
                                        <div class="dropdown-menu">
                                            <?php if ($res['is_dir']): ?>
                                                <a href="?path=<?php echo urlencode($res['path']); ?>"><?php echo $t['action_view']; ?></a>
                                                <a href="#" onclick="renameItem('<?php echo addslashes($res['dir_path']); ?>', '<?php echo addslashes($res['name']); ?>'); return false;"><?php echo $t['action_rename']; ?></a>
                                                <a href="#" onclick="chmodItem('<?php echo addslashes($res['dir_path']); ?>', '<?php echo addslashes($res['name']); ?>'); return false;"><?php echo $t['action_chmod']; ?></a>
                                                <a href="#" onclick="deleteItem('<?php echo addslashes($res['dir_path']); ?>', '<?php echo addslashes($res['name']); ?>'); return false;" class="text-danger"><?php echo $t['action_delete']; ?></a>
                                            <?php else: ?>
                                                <?php if ($res_is_mp3): ?>
                                                    <a href="?path=<?php echo urlencode($res['dir_path']); ?>&play_mp3=<?php echo urlencode($res['name']); ?>&p_path=<?php echo urlencode($res['dir_path']); ?>">Spill av</a>
                                                <?php elseif ($res_is_viewable): ?>
                                                    <a href="<?php echo htmlspecialchars($res['path']); ?>" target="_blank"><?php echo $res_is_php ? $t['action_run_web'] : $t['action_view']; ?></a>
                                                <?php endif; ?>
                                                <a href="?path=<?php echo urlencode($res['dir_path']); ?>&edit=<?php echo urlencode($res['name']); ?>&e_path=<?php echo urlencode($res['dir_path']); ?>"><?php echo $t['action_edit']; ?></a>
                                                <a href="#" onclick="renameItem('<?php echo addslashes($res['dir_path']); ?>', '<?php echo addslashes($res['name']); ?>'); return false;"><?php echo $t['action_rename']; ?></a>
                                                <a href="#" onclick="chmodItem('<?php echo addslashes($res['dir_path']); ?>', '<?php echo addslashes($res['name']); ?>'); return false;"><?php echo $t['action_chmod']; ?></a>
                                                <a href="#" onclick="deleteItem('<?php echo addslashes($res['dir_path']); ?>', '<?php echo addslashes($res['name']); ?>'); return false;" class="text-danger"><?php echo $t['action_delete']; ?></a>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </td>
                                <td class="name-cell">
                                    <?php if ($res['is_dir']): ?>
                                        <a href="?path=<?php echo urlencode($res['path']); ?>"><strong><?php echo htmlspecialchars($res['name']); ?></strong></a>
                                    <?php else: ?>
                                        <?php if ($res_is_mp3): ?>
                                            <a href="?path=<?php echo urlencode($res['dir_path']); ?>&play_mp3=<?php echo urlencode($res['name']); ?>&p_path=<?php echo urlencode($res['dir_path']); ?>">🎵 <strong><?php echo htmlspecialchars($res['name']); ?></strong></a>
                                        <?php elseif ($res_is_viewable && $res_run_as_web): ?>
                                            <a href="<?php echo htmlspecialchars($res['path']); ?>" target="_blank"><?php echo htmlspecialchars($res['name']); ?></a>
                                        <?php else: ?>
                                            <a href="?path=<?php echo urlencode($res['dir_path']); ?>&edit=<?php echo urlencode($res['name']); ?>&e_path=<?php echo urlencode($res['dir_path']); ?>"><?php echo htmlspecialchars($res['name']); ?></a>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                </td>
                                <td><?php echo $res['dir_path'] === '' ? '/' : htmlspecialchars($res['dir_path']); ?></td>
                                <td><?php echo $res['is_dir'] ? $t['type_dir'] : $t['type_file']; ?></td>
                            </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
            </table>
        <?php else: ?>
            <table>
                <thead>
                    <tr>
                        <th style="width: 40px; text-align: center;">📁/📄</th>
                        <th><?php echo $t['th_name']; ?></th>
                        <th><?php echo $t['th_type']; ?></th>
                        <th><?php echo $t['th_size']; ?></th>
                        <th><?php echo $t['th_perms']; ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php if ($current_path !== ''): ?>
                        <?php
                        $parent_path = dirname($current_path);
                        if ($parent_path === '.' || $parent_path === '\\') $parent_path = '';
                        ?>
                        <tr class="file-row">
                            <td style="text-align: center;">⬆️</td>
                            <td class="name-cell" colspan="4">
                                <a href="?path=<?php echo urlencode($parent_path); ?>"><strong><?php echo $t['parent_dir']; ?></strong></a>
                            </td>
                        </tr>
                    <?php endif; ?>

                    <!-- MAPPER -->
                    <?php foreach ($dirs as $d): ?>
                        <?php
                        $d_full = $base_dir . '/' . $d['path'];
                        $d_perms = file_exists($d_full) ? substr(sprintf('%o', fileperms($d_full)), -4) : '-';
                        $d_act = dirname($d['path']);
                        if ($d_act === '.' || $d_act === '\\') $d_act = '';
                        ?>
                        <tr class="file-row">
                            <td class="icon-cell">
                                <div class="action-dropdown-wrapper">
                                    <button type="button" class="icon-menu-btn" onclick="toggleRowMenu(event, this)" title="Handlinger">
                                        <svg class="svg-icon" style="color: <?php echo $config['folder_color']; ?>;" viewBox="0 0 24 24"><path d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg>
                                    </button>
                                    <div class="dropdown-menu">
                                        <a href="?path=<?php echo urlencode($d['path']); ?>"><?php echo $t['action_view']; ?></a>
                                        <a href="#" onclick="renameItem('<?php echo addslashes($d_act); ?>', '<?php echo addslashes($d['name']); ?>'); return false;"><?php echo $t['action_rename']; ?></a>
                                        <a href="#" onclick="chmodItem('<?php echo addslashes($d_act); ?>', '<?php echo addslashes($d['name']); ?>'); return false;"><?php echo $t['action_chmod']; ?></a>
                                        <a href="#" onclick="deleteItem('<?php echo addslashes($d_act); ?>', '<?php echo addslashes($d['name']); ?>'); return false;" class="text-danger"><?php echo $t['action_delete']; ?></a>
                                    </div>
                                </div>
                            </td>
                            <td class="name-cell">
                                <a href="?path=<?php echo urlencode($d['path']); ?>"><strong><?php echo htmlspecialchars($d['name']); ?></strong></a>
                            </td>
                            <td><?php echo $t['type_dir']; ?></td>
                            <td>-</td>
                            <td><code><?php echo $d_perms; ?></code></td>
                        </tr>
                    <?php endforeach; ?>

                    <!-- FILER -->
                    <?php foreach ($files as $f): ?>
                        <?php
                        $f_act = dirname($f['path']);
                        if ($f_act === '.' || $f_act === '\\') $f_act = '';
                        $f_full = $base_dir . '/' . $f['path'];
                        $f_size = file_exists($f_full) ? number_format(filesize($f_full)) . ' B' : '-';
                        $f_perms = file_exists($f_full) ? substr(sprintf('%o', fileperms($f_full)), -4) : '-';
                        $ext = strtolower(pathinfo($f['name'], PATHINFO_EXTENSION));
                        
                        $is_mp3 = ($ext === 'mp3');
                        $is_php = ($ext === 'php');
                        $viewable_exts = ['pdf', 'jpg', 'jpeg', 'png', 'gif', 'svg', 'mp4', 'txt', 'html', 'htm', 'php', 'pl'];
                        $is_viewable = in_array($ext, $viewable_exts) || $is_mp3;
                        $run_as_web = $is_php ? $config['run_php_as_web'] : $is_viewable;
                        ?>
                        <tr class="file-row">
                            <td class="icon-cell">
                                <div class="action-dropdown-wrapper">
                                    <button type="button" class="icon-menu-btn" onclick="toggleRowMenu(event, this)" title="Handlinger">
                                        <svg class="svg-icon" style="color: <?php echo $config['file_color']; ?>;" viewBox="0 0 24 24"><path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z"/></svg>
                                    </button>
                                    <div class="dropdown-menu">
                                        <?php if ($is_mp3): ?>
                                            <a href="?path=<?php echo urlencode($current_path); ?>&play_mp3=<?php echo urlencode($f['name']); ?>&p_path=<?php echo urlencode($f_act); ?>">Spill av</a>
                                        <?php elseif ($is_viewable): ?>
                                            <a href="<?php echo htmlspecialchars($f['path']); ?>" target="_blank"><?php echo $is_php ? $t['action_run_web'] : $t['action_view']; ?></a>
                                        <?php endif; ?>
                                        <a href="?path=<?php echo urlencode($current_path); ?>&edit=<?php echo urlencode($f['name']); ?>&e_path=<?php echo urlencode($f_act); ?>"><?php echo $t['action_edit']; ?></a>
                                        <a href="#" onclick="renameItem('<?php echo addslashes($f_act); ?>', '<?php echo addslashes($f['name']); ?>'); return false;"><?php echo $t['action_rename']; ?></a>
                                        <a href="#" onclick="chmodItem('<?php echo addslashes($f_act); ?>', '<?php echo addslashes($f['name']); ?>'); return false;"><?php echo $t['action_chmod']; ?></a>
                                        <a href="#" onclick="deleteItem('<?php echo addslashes($f_act); ?>', '<?php echo addslashes($f['name']); ?>'); return false;" class="text-danger"><?php echo $t['action_delete']; ?></a>
                                    </div>
                                </div>
                            </td>
                            <td class="name-cell">
                                <?php if ($is_mp3): ?>
                                    <a href="?path=<?php echo urlencode($current_path); ?>&play_mp3=<?php echo urlencode($f['name']); ?>&p_path=<?php echo urlencode($f_act); ?>">🎵 <strong><?php echo htmlspecialchars($f['name']); ?></strong></a>
                                <?php elseif ($is_viewable && $run_as_web): ?>
                                    <a href="<?php echo htmlspecialchars($f['path']); ?>" target="_blank"><?php echo htmlspecialchars($f['name']); ?></a>
                                <?php else: ?>
                                    <a href="?path=<?php echo urlencode($current_path); ?>&edit=<?php echo urlencode($f['name']); ?>&e_path=<?php echo urlencode($f_act); ?>"><?php echo htmlspecialchars($f['name']); ?></a>
                                <?php endif; ?>
                            </td>
                            <td><?php echo $t['type_file']; ?></td>
                            <td><?php echo $f_size; ?></td>
                            <td><code><?php echo $f_perms; ?></code></td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        <?php endif; ?>
    </div>
</div>

</body>
</html>