<?php
// one_line_find.php
// Find files webpage wise all in one inline arranged horizontal line
// RJM Programming
// February, 2026
// One line ls -clt https://www.rjmprogramming.com.au/*.txt via find $_SERVER['DOCUMENT_ROOT'] -type d -name '*' 

  $offdr='';
  $resis='';
  $offdrverbose='';
  $fifteen="15";
  $forty="65"; // 70
  $selbit='';
  $more='';
  if (isset($_GET['fsub'])) { $fifteen=str_replace('+',' ',urldecode($_GET['fsub'])); }
  if (isset($_POST['fsub'])) { $fifteen=str_replace('+',' ',urldecode($_POST['fsub'])); }

  if (isset($_GET['anyway']) || (!isset($_GET['offdr']) && !isset($_POST['offdr']))) {
    $extbit='*.txt';
    if (isset($_GET['extbit'])) { $extbit=str_replace('+',' ',urldecode($_GET['extbit'])); }
    if (isset($_POST['extbit'])) { $extbit=str_replace('+',' ',urldecode($_POST['extbit'])); }
    $extbit='*.txt';
    if (isset($_GET['offdr'])) {
     $offdr=str_replace('+',' ',urldecode($_GET['offdr']));
     $extbit='*.txt';
     if (isset($_GET['extbit'])) { $extbit=str_replace('+',' ',urldecode($_GET['extbit'])); }
     $extbit='*.txt';
     $more=" document.getElementById('offdr').value='" . $offdr . "';  document.getElementById('offdr').style.width='" . $fifteen . "px'; document.getElementById('fsub').name='fsub'; document.getElementById('fsub').click(); ";
    }
    $resis=str_replace($_SERVER['DOCUMENT_ROOT'],'',shell_exec('ls -clt ' . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $offdr . $extbit));
    if ($resis == '') {  $forty="15"; }
    if (file_exists('save_time.xxx')) {
        $offdrverbose=file_get_contents('save_time.xxx');
    } else {
        $offdrverbose=shell_exec("find " . $_SERVER['DOCUMENT_ROOT'] . " -type d -name '*'");
        file_put_contents('save_time.xxx', $offdrverbose);
    }
    $offds=explode("\n", $offdrverbose);
    $selbit="<select style=display:inline-block;background-color:#f0f0f0; onchange=document.getElementById(getfsub()).click(); id=offdr name=offdr></select>";
    for ($i=0; $i<sizeof($offds); $i++) {
      if (substr($offds[$i] . ' ',0,2) == '. ' || $i == 0) {
      if (strpos($offds[$i], $_SERVER['DOCUMENT_ROOT']) === false) {
        $offds[$i].=DIRECTORY_SEPARATOR;
      }
      $selbit=str_replace("</select>","<option value='" . str_replace($_SERVER['DOCUMENT_ROOT'],'',substr($offds[$i],0)) . "'>" . str_replace($_SERVER['DOCUMENT_ROOT'],'',substr($offds[$i],0)) . "</option></select>", $selbit);
      if ($i == 0) { sort($offds);  }
     } else if ($offds[$i] == $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR || $offds[$i] == $_SERVER['DOCUMENT_ROOT']) {
      $i=$i;
     } else if (substr($offds[$i] . ' ',0,2) == './') {
      $selbit=str_replace("</select>","<option value='" . str_replace($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR,'',substr($offds[$i],2)) . "'>" . str_replace($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR,'',substr($offds[$i],1)) . "</option></select>", $selbit);
     } else {
      $selbit=str_replace("</select>","<option value='" . str_replace($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR,'',substr($offds[$i],0)) . DIRECTORY_SEPARATOR . "'>" . str_replace($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR,'',substr($offds[$i],0)) . DIRECTORY_SEPARATOR . "</option></select>", $selbit);
     }
    }
  
  echo "<html>
<head>
<title>Folder listing relative to Document Root (brought to you by RJM Programming ... February, 2026)</title>
<style>
  #midtd { border-right: 2px dotted blue; border-top: 2px dotted blue;  border-bottom: 2px dotted blue;  }
  #lefttd { border-top: 2px dotted blue;  border-bottom: 2px dotted blue; }
</style>
<scr" . "ipt type=text/javascript>
  var fsub='fsub', wo=null;
  
  function getfsub() {
    document.getElementById('offdr').style.width='' + document.getElementById('fsub').value + 'px';
    return 'fsub';
  }
  
function resizeSelect(sel) { // thanks to https://www.google.com/search?q=make+select+element+width+in+sympathy+with+length+of+its+value&rlz=1C5OZZY_en&oq=make+select+element+width+in+sympathy+with+length+of+its+value&gs_lcrp=EgZjaHJvbWUyBggAEEUYOdIBCTI3MzEzajBqNKgCALACAQ&sourceid=chrome&ie=UTF-8
  // 1. Create a temporary span to measure text width
  var tempSpan = document.createElement('span');
  tempSpan.style.visibility = 'hidden';
  tempSpan.style.position = 'absolute';
  tempSpan.style.whiteSpace = 'pre';
  // 2. Set font styles to match the select box
  tempSpan.style.font = window.getComputedStyle(sel).font;
  // 3. Set content to selected text
  tempSpan.innerText = sel.options[sel.selectedIndex].text;
  document.body.appendChild(tempSpan);
  
  // 4. Update width (with extra space for the dropdown arrow)
  sel.style.width = (tempSpan.offsetWidth + 30) + 'px';
  document.body.removeChild(tempSpan);
}

  function getid(ofw) {
    return document.getElementById(ofw).innerHTML;
  }

  function onl() {
     if (window.opener) {
     document.getElementById('lefttd').innerHTML=window.opener.getid('lefttd');
     document.getElementById('midtd').innerHTML=window.opener.getid('midtd');
     } else {
    document.getElementById('lefttd').innerHTML=\"<span title='&lt;-- Folder listing relative to Document Root (brought to you by RJM Programming ... February, 2026) of ...' id=prefix>\" + document.URL.substring(0,8) + document.URL.substring(8).split('/')[0] + \"/</span>" . $selbit . "\";
    document.getElementById('midtd').innerHTML=\"<input style=width:80px; type=text id=extbit name=extbit value='" . $extbit . "' readonly disabled></input>\";
     }
    document.getElementById('fsub').value='' + document.getElementById('offdr').getBoundingClientRect().width;
    document.getElementById('fsub').name='fsub';
    document.getElementById('offdr').style.width='15px';
    document.getElementById('tres').title=\"" . str_replace("\n","\" + String.fromCharCode(10) + \"",str_replace($_SERVER['DOCUMENT_ROOT'],'',$resis)) . "\"; 
    resizeSelect(document.getElementById('offdr'));
    if (('' + top.document.URL).indexOf('/ITblog') != -1) {
      document.getElementById('myform').target='_top';
      document.getElementById('myform').method='GET';
    }
    " . $more . "
  }

</scr" . "ipt>
</head>
<body onload=\"onl();\" title='Folder listing (brought to you by RJM Programming ... February, 2026)'>
<form id=myform onsubmit=\"if (('' + this.method).toUpperCase() == 'GET') {  wo=window.open(this.action + '?offdr=' + encodeURIComponent(document.getElementById('offdr').value) + '&fsub=' + encodeURIComponent(document.getElementById('fsub').value) + '&extbit=' + encodeURIComponent(document.getElementById('extbit').value) + '&anyway=y', '_blank', 'top=200,left=0,width=' + screen.width + ',height=150');  document.getElementById('offdr').value='';  document.getElementById('offdr').style.width='15px'; return false;  } else { document.getElementById('myform').style.display='none'; document.getElementById('myif').style.display='block'; return true; } \" method=POST target=myif action='./one_line_find.php'>
<table style=width:100%;>
<tr id=mytr><td id=righttd style=width:" . $forty . "%;><textarea style=width:100%;background-color:yellow; placeholder='Folder listing of ...' rows=1 cols=120 id=tres>" . $resis . "</textarea></td><td id=lefttd style=text-align:right;vertical-align:top;></td><td id=midtd style=vertical-align:top;></td></tr>
</table>
<input type=submit style=display:none; id=fsub value=" . $fifteen . "></input>
</form>
<iframe scrolling=yes frameborder=0 name=myif id=myif src=/About_Us.html style=display:none;width:100%;height:80px;overflow-y:visible;></iframe>
</body>
</html>";
    exit;
  } else if (isset($_GET['offdr'])) {
    $offdr=str_replace('+',' ',urldecode($_GET['offdr']));
    $extbit='*.txt';
    if (isset($_GET['extbit'])) { $extbit=str_replace('+',' ',urldecode($_GET['extbit'])); }
    $extbit='*.txt';
    $resis=str_replace($_SERVER['DOCUMENT_ROOT'],'',shell_exec('ls -clt ' . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $offdr . $extbit));
    if ($resis == '') {  $forty="15"; }
  } else {
    $offdr=str_replace('+',' ',urldecode($_POST['offdr']));
    $extbit='*.txt';
    if (isset($_POST['extbit'])) { $extbit=str_replace('+',' ',urldecode($_POST['extbit'])); }
    $extbit='*.txt';
    $resis=str_replace($_SERVER['DOCUMENT_ROOT'],'',shell_exec('ls -clt ' . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $offdr . $extbit));
    if ($resis == '') {  $forty="15"; }
  }
  
  echo "<html>
<head>
<title>Folder listing relative to Document Root (brought to you by RJM Programming ... February, 2026)</title>
<style>
  #midtd { border-right: 2px dotted blue; border-top: 2px dotted blue;  border-bottom: 2px dotted blue;  }
  #lefttd { border-top: 2px dotted blue;  border-bottom: 2px dotted blue; }
</style>
<scr" . "ipt type=text/javascript>
  var fsub='fsub';
  
  function getfsub() {
    document.getElementById('offdr').style.width='300px';
    return 'fsub';
  }

  function getid(ofw) {
    return document.getElementById(ofw).innerHTML;
  }
  
function resizeSelect(sel) { // thanks to https://www.google.com/search?q=make+select+element+width+in+sympathy+with+length+of+its+value&rlz=1C5OZZY_en&oq=make+select+element+width+in+sympathy+with+length+of+its+value&gs_lcrp=EgZjaHJvbWUyBggAEEUYOdIBCTI3MzEzajBqNKgCALACAQ&sourceid=chrome&ie=UTF-8
  // 1. Create a temporary span to measure text width
  var tempSpan = document.createElement('span');
  tempSpan.style.visibility = 'hidden';
  tempSpan.style.position = 'absolute';
  tempSpan.style.whiteSpace = 'pre';
  // 2. Set font styles to match the select box
  tempSpan.style.font = window.getComputedStyle(sel).font;
  // 3. Set content to selected text
  tempSpan.innerText = sel.options[sel.selectedIndex].text;
  document.body.appendChild(tempSpan);
  
  // 4. Update width (with extra space for the dropdown arrow)
  sel.style.width = (tempSpan.offsetWidth + 30) + 'px';
  document.body.removeChild(tempSpan);
}

  function leftize() {
  //alert(8);
     if (window.opener) {
  //alert(84);
     document.getElementById('lefttd').innerHTML=window.opener.getid('lefttd');
  //alert(document.getElementById('lefttd').innerHTML);
     document.getElementById('midtd').innerHTML=window.opener.getid('midtd');
  //alert(document.getElementById('midtd').innerHTML);
     } else {
  //alert(80);
     document.getElementById('lefttd').innerHTML=parent.document.getElementById('lefttd').innerHTML;
     document.getElementById('midtd').innerHTML=parent.document.getElementById('midtd').innerHTML;
     }
     document.getElementById('offdr').value='" . $offdr . "'; 
     document.getElementById('offdr').style.width='" . $fifteen . "px';
     document.getElementById('fsub').name='fsub';
     document.getElementById('tres').title=\"" . str_replace("\n","\" + String.fromCharCode(10) + \"",str_replace($_SERVER['DOCUMENT_ROOT'],'',$resis)) . "\"; 
     resizeSelect(document.getElementById('offdr'));
     " . $more . "
  }

</scr" . "ipt>
</head>
<body onload=\"leftize();\" title='Folder listing relative to Document Root (brought to you by RJM Programming ... February, 2026)'>
<form id=myform onsubmit=\"document.getElementById('myform').style.display='none'; document.getElementById('myif').style.display='block'; return true; \" method=POST target=myif action='./one_line_find.php'>
<table style=width:100%;>
<tr id=mytr><td id=righttd style=width:" . $forty . "%;><textarea style=width:100%;background-color:yellow; placeholder='Folder listing of ...' rows=1 cols=120 id=tres>" . $resis . "</textarea></td><td id=lefttd style=vertical-align:top;text-align:right;></td><td id=midtd style=vertical-align:top;></td></tr>
</table>
<input type=submit style=display:none; id=fsub value=" . $fifteen . "></input>
</form>
<iframe scrolling=yes frameborder=0 name=myif id=myif src=/About_Us.html style=display:none;width:100%;height:80px;overflow-y:visible;></iframe>
</body>
</html>";
?>