<?php
  // open_extravaganza.php
  // RJM Programming
  // November, 2025
  $afteropen='';
  $preret='';
  $ret='';
  $selstuff='';
  
  if (PHP_OS == 'Darwin') {
    $selstuff="<br><br><form onsubmit=\"if (document.getElementById('opsel')) { if (document.getElementById('opsel').value.length > 0) { this.action=document.getElementById('opsel').value;  }   } return true;\" id=myform method=POST action='./open_extravaganza.php'><select style=background-color:yellow; size=15 id=mysel name=afteropen onchange=\"if (this.value.length != 0) { document.getElementById('sbut').click();  } \"><option value=''>Select macOS open command type below ...</option><option value=' -a Finder'>Finder</option><option value=' -a Preview'>Preview</option><option value=' -a TextEdit'>TextEdit</option><option value=' -b com.apple.VoiceMemos'>Voice Memo</option><option value=' -b com.apple.QuickTimePlayerX https://www.rjmprogramming.com.au/Windows/windows_step_recorder.mov'>QuickTime Player</option><option value=' ~/Desktop/Screen\\ Shot\\ *.png'>Preview all screenshot files</option><option value=' -a Firefox https://www.rjmprogramming.com.au'>Firefox</option><option value=' -a Safari http://localhost:8888/macos_say_record.php'>Safari interface attempt to say</option><option value=' ~/Documents ~/Desktop ~/Downloads'>Open the D folders</option><option value='https://google.com'>Google</option><option value='https://wikipedia.org'>Wikipedia</option><option value='https://www.rjmprogramming.com.au'>RJM Programming</option><option value='ls -l . | open -f'>Pipe folder listing into TextEdit</option><option value='x-man-page://open'>Show man page in Terminal</option></select><br><br><input id=sbut type=submit value='Execute'></input></form>";
  } else if (substr(strtolower('' . PHP_OS),0,3) == 'win') {
    $selstuff="<br><br><form onsubmit=\"if (document.getElementById('opsel')) {  if (document.getElementById('opsel').value.length > 0) {  this.action=document.getElementById('opsel').value;   }  } return true;\" id=myform method=POST action='./open_extravaganza.php'><select style=background-color:yellow; size=4 id=mysel name=afteropen onchange=\"if (this.value.length != 0) { document.getElementById('sbut').click();  } \"><option value=''>Select Windows explorer.exe command type below ...</option><option value=' '>File Explorer</option><option value='https://google.com'>Google</option><option value='https://wikipedia.org'>Wikipedia</option><option value='https://www.rjmprogramming.com.au'>RJM Programming</option></select><br><br><input id=sbut type=submit value='Execute'></input></form>";
  } 
  
  if (isset($_GET['afteropen'])) {
    $afteropen=(trim(str_replace('+',' ',urldecode($_GET['afteropen']))) == '' ? '' : ' ' . trim(str_replace('+',' ',urldecode($_GET['afteropen']))));
  } else if (isset($_POST['afteropen'])) {
    $afteropen=(trim(str_replace('+',' ',urldecode($_POST['afteropen']))) == '' ? '' : ' ' . trim(str_replace('+',' ',urldecode($_POST['afteropen']))));
  } 
  
  if ($afteropen != '' || isset($_GET['afteropen']) || isset($_POST['afteropen'])) {
   if (PHP_OS == 'Darwin') {
    if (strpos($afteropen, ' open ') === false) {
    $preret='open' . $afteropen;
    } else {
    $preret='' . $afteropen;
    }
    $ret=shell_exec($preret);
    $preret.="\n";
   } else if (substr(strtolower('' . PHP_OS),0,3) == 'win') {
    if (strpos($afteropen, ' explorer.exe ') === false) {
    $preret='explorer.exe' . $afteropen;
    } else {
    $preret='' . $afteropen;
    }
    $ret=shell_exec($preret);
    $preret.="\n";
   }
  }

  if ($preret == '' && strpos($_SERVER['SERVER_NAME'], 'rjmprogramming.com.au') !== false) {
    $selstuff=str_replace('POST', 'GET', $selstuff);
    $preret=" <select title=\"Right click to go to Apache/PHP/MySql MAMP local web server webpage\" oncontextmenu=\"window.open('//www.mamp.info','_blank');\" id=opsel onchange=\"if (this.value.length > 0) { wo=window.open(this.value,'_blank','top=0,left=0,width=' + screen.width + ',height=' + screen.height);  }\"><option id=omamp value=''>MAMP</option><option id=omacos value='http://localhost:8888/open_extravaganza.php'>macOS</option><option id=owindows value='http://localhost/open_extravaganza.php'>Windows</option></select>";
  }
  
echo "<!doctype HTML>
<html>
<head>
<title>Local Operating System Menu</title>
<meta charset=\"UTF-8\">
<scri" . "pt type=text/javascript>
    var wo=null;
    
    function mostlikely() {
     if (document.getElementById('opsel')) {
      if (('' + navigator.platform).toLowerCase().indexOf('mac') != 0) {
        document.getElementById('opsel').innerHTML=document.getElementById('omamp').outerHTML + document.getElementById('owindows').outerHTML + document.getElementById('omacos').outerHTML;
      }
     }
    }
</scri" . "pt>
<style>
 p {
   background-color: orange;
 }
</style>
</head>
<body onload=mostlikely();><h1>Local Operating System " . explode(' ',$preret)[0] . " Menu </h1><h2>RJM Programming</h2><h3>November, 2025</h3><h4>Thanks to <a target=bank tite='https://scriptingosx.com/2017/02/the-macos-open-command/' href='//scriptingosx.com/2017/02/the-macos-open-command/'>https://scriptingosx.com/2017/02/the-macos-open-command/</a></h4><br><p>" . str_replace("\n","<br>",$preret) . str_replace("\n","<br>",$ret) . "</p>" . $selstuff . "</body>
</html>";
?>
