<?php
  // open_extravaganza.php
  // RJM Programming
  // November, 2025
  
  $afteropen='';
  $preret='';
  $ret='';
  $selstuff='';
  $afteropens=[];
  $delim='';
  $thisone=1;
  $wds="\\";
  $plusin='+';
  $plusout=' ';
  $fromsc='~/Desktop/test_gvp.scpt';
  $tosc='~/Desktop/test_gvp.scpt';
  $vcb='';
  $vvcb='';
  if (isset($_GET['commentary'])) {
    $vcb=str_replace('+',' ',urldecode($_GET['commentary']));
    $vvcb=$vcb;
  } else if (isset($_POST['commentary'])) {
    $vcb=str_replace('+',' ',urldecode($_POST['commentary']));
    $vvcb=$vcb;
  }
  if (isset($_GET['voice'])) {
    $vcb=$_GET['voice'];
  } else if (isset($_POST['voice'])) {
    $vcb=$_POST['voice'];
  }
  $dobgd=false;
  if (PHP_OS == 'Darwin') {
  if (isset($_GET['bgd'])) {
   if ($_GET['bgd'] == 'on') {
    $dobgd=true;
   }
  }
  if (isset($_POST['bgd'])) {
   if ($_POST['bgd'] == 'on') {
    $dobgd=true;
   }
  }
  }

  $sayvoices="\n
Alex                en_US\n
Alice               it_IT\n
Alva                sv_SE\n
Amelie              fr_CA\n
Anna                de_DE\n
Carmit              he_IL\n
Damayanti           id_ID\n
Daniel              en_GB\n
Diego               es_AR\n
Ellen               nl_BE\n
Fiona               en-scotland\n
Fred                en_US\n
Ioana               ro_RO\n
Joana               pt_PT\n
Jorge               es_ES\n
Juan                es_MX\n
Kanya               th_TH\n
Karen               en_AU\n
Kyoko               ja_JP\n
Laura               sk_SK\n
Lekha               hi_IN\n
Luca                it_IT\n
Luciana             pt_BR\n
Maged               ar_SA\n
Mariska             hu_HU\n
Mei-Jia             zh_TW\n
Melina              el_GR\n
Milena              ru_RU\n
Moira               en_IE\n
Monica              es_ES\n
Nora                nb_NO\n
Paulina             es_MX\n
Samantha            en_US\n
Sara                da_DK\n
Satu                fi_FI\n
Sin-ji              zh_HK\n
Tessa               en_ZA\n
Thomas              fr_FR\n
Ting-Ting           zh_CN\n
Veena               en_IN\n
Victoria            en_US\n
Xander              nl_NL\n
Yelda               tr_TR\n
Yuna                ko_KR\n
Yuri                ru_RU\n
Zosia               pl_PL\n
Zuzana              cs_CZ\n
";

  $svinnards='';
  $svarr=explode("\n", $sayvoices);
  $icb='';
  
  function oururldecode($ofwhat) {
    global $plusin, $plusout, $fromsc, $tosc;
    $interim=str_replace($fromsc,$tosc,urldecode($ofwhat));
    if (strpos($interim, ' ') === false || substr(($interim . 'x'),0,1) == '+') {
      $plusin=' ';
      $plusout=' ';
      return str_replace($fromsc,$tosc,base64_decode($ofwhat));
    } else {
      $plusin='+';
      $plusout=' ';
    }
    return $interim;
  }
  
  if (PHP_OS == 'Darwin') {
    $svinnards='<option value="">Optionally add commentary with Voice ...</option>';
    for ($isv=0; $isv<sizeof($svarr); $isv++) {
     if (trim($svarr[$isv]) != '') {
      $svinnards.='<option value="' . explode(' ',$svarr[$isv])[0] . '">' . explode(' ',$svarr[$isv])[0] . ' ' . trim(str_replace(explode(' ',$svarr[$isv])[0],'',$svarr[$isv])) . '</option>';
     }
    }
    $selstuff="<br><br><form onsubmit=\"formclickmode=0; document.body.style.cursor='pointer'; if (lastselo) { lastselo.style.cursor='pointer'; lastselo=null; } if (document.getElementById('opsel')) { if (document.getElementById('opsel').value.length > 0) { this.action=document.getElementById('opsel').value;  }   } return perhaps(true,this);\" id=myform method=GET action='./open_extravaganza.php'><select title='Right click can modify dropdown choices' style=background-color:yellow; size=21 id=mysel multiple name=afteropen onchange=\"if (this.value.length != 0) { if (1 == 1) { formclickmode=prg(1,event.target); } else { document.getElementById('sbutmac').click(); } } \"><option oncontextmenu=ocmopt(this); value=''>Select macOS open command type(s) below ...</option><option oncontextmenu=ocmopt(this); value=' -a Finder'>Finder</option><option oncontextmenu=ocmopt(this); value=' -a Preview'>Preview</option><option oncontextmenu=ocmopt(this); value=' -a TextEdit'>TextEdit</option><option oncontextmenu=ocmopt(this); value=' -b com.apple.VoiceMemos'>Voice Memo</option><option oncontextmenu=ocmopt(this); value=' -b com.apple.QuickTimePlayerX https://www.rjmprogramming.com.au/Windows/windows_step_recorder.mov'>QuickTime Player</option><option oncontextmenu=ocmopt(this); value=' -b com.apple.VoiceOverUtility'>VoiceOver Utility</option><option oncontextmenu=ocmopt(this); value=' ~/Desktop/Screen\\ Shot\\ *.png'>Preview all screenshot files</option><option oncontextmenu=ocmopt(this); value=' -a Firefox https://www.rjmprogramming.com.au'>Firefox</option><option oncontextmenu=ocmopt(this); value=' -a Safari http://localhost:8888/macos_say_record.php?saythis=Welcome\\&voice=Karen\\&audioname=;open -a Safari http://localhost:8888/macos_say_record.php'>Safari interface attempt to say</option><option oncontextmenu=ocmopt(this); value=' -b com.apple.ScriptEditor2 ~/Desktop/test_gvp.scpt'>AppleScript example ready to Script-&gt;Run</option><option title='System sounds ... macOS ... right click for chance to try another system sound' oncontextmenu=ocmopt(this); value=' http://localhost:8888/mamp_beep.php?sound=beep'>Beep</option><option oncontextmenu=ocmopt(this); value=\"IGVjaG8gJzU2NCs5ODc2NScgfCBiYw==\">Add 564 to 98765</option><option oncontextmenu=ocmopt(this); value=' ~/Documents ~/Desktop ~/Downloads'>Open the D folders</option><option oncontextmenu=ocmopt(this); value=' \"http://localhost:8888/pbcopy_ideas.php?verb=" . urlencode("~/Documents") . urlencode("%20") . urlencode("~/Desktop") . urlencode("%20") . urlencode("~/Downloads") . "\"'>Clipboard paste and copy D folder listings</option><option oncontextmenu=ocmopt(this); value=' \"https://www.rjmprogramming.com.au/recording_ideas.php\"'>Record yourself</option><option oncontextmenu=ocmopt(this); value=' https://google.com'>Google</option><option oncontextmenu=ocmopt(this); value=' https://wikipedia.org'>Wikipedia</option><option oncontextmenu=ocmopt(this); value=' https://www.rjmprogramming.com.au'>RJM Programming</option><option oncontextmenu=ocmopt(this); value=' ls -l . | open -f'>Pipe folder listing into TextEdit</option><option oncontextmenu=ocmopt(this); value=' x-man-page://open'>Show man page in Terminal</option></select><br><br><input id=sbutmac type=submit value='Execute'></input>&nbsp;<input type=checkbox name=bgd id=myinput>Background</input><input type=hidden name=commentary id=myinputcb value='" . $icb . "'></input>&nbsp;<select onchange=commonoff(this); name=voice id=myinputvc value='" . $vcb . "'>" . $svinnards . "</select></form>";
    $asc="tell application \"Terminal\"
	activate
	do script \"cd '~/Desktop'\" in window 1
	do script \"open 'https://www.rjmprogramming.com.au/ITblog/graphviz-via-php-on-almalinux-dot-html-table-tutorial/'\" in window 1
end tell";
    if (!file_exists('~/Desktop/test_gvp.scpt')) {
      $tosc=str_replace('~/Desktop/', dirname(__FILE__) . DIRECTORY_SEPARATOR, $tosc);
      $asc=str_replace('~/Desktop', dirname(__FILE__), $asc);
      //file_put_contents('~/Desktop/test_gvp.scpt', $asc);
      if (!file_exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test_gvp.scpt')) {
      $fp = fopen(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test_gvp.scpt', 'x');
      fwrite($fp, $asc);
      fclose($fp);
      }
    }
    if (str_replace('y','',$vvcb) != '') {
      exec('say -v ' . $vcb . ' ' . $vvcb);
    }
  } else if (substr(strtolower('' . PHP_OS),0,3) == 'win') {
    $selstuff="<br><br><form onsubmit=\"formclickmode=0; document.body.style.cursor='pointer'; if (lastselo) { lastselo.style.cursor='pointer'; lastselo=null; } if (document.getElementById('opsel')) {  if (document.getElementById('opsel').value.length > 0) {  this.action=document.getElementById('opsel').value;   }  } return perhaps(true,this);\" id=myform method=GET action='./open_extravaganza.php'><div id=mydiv></div><select title='Right click can modify dropdown choices' style=background-color:yellow; size=10 id=mysel multiple name=afteropen onchange=\"if (this.value.length != 0) { if (1 == 1) { formclickmode=prg(-1,event.target); } else { document.getElementById('sbutwin').click(); } } \"><option oncontextmenu=ocmopt(this); value=''>Select Windows explorer.exe command type(s) below ...</option><option oncontextmenu=ocmopt(this); value=' '>File Explorer</option><option oncontextmenu=ocmopt(this); value=' ,'>Explore My Computer</option><option value=' ::{21ec2020-3aea-1069-a2dd-08002b30309d}\::{2227a280-3aea-1069-a2de-08002b30309d}'>Printers folder in Control Panel</option><option value=' /EXPAND,%windir%'>Windows folder</option><option oncontextmenu=ocmopt(this); value=' https://google.com'>Google</option><option oncontextmenu=ocmopt(this); value=' https://wikipedia.org'>Wikipedia</option><option oncontextmenu=ocmopt(this); value=' \"http://localhost/pbcopy_ideas.php?verb=" . "dir%20%2fc%2ft2fl%2ft%20" . "Documents" . "%20" . "Desktop" . "%20" . "Downloads" . "\"'>Clipboard paste and copy D folder listings</option><option oncontextmenu=ocmopt(this); value=' \"https://www.rjmprogramming.com.au/recording_ideas.php\"'>Record yourself</option><option oncontextmenu=ocmopt(this); value=' https://www.rjmprogramming.com.au'>RJM Programming</option></select><br><br><input id=sbutwin type=submit value='Execute'></input><input type=hidden name=bgd id=myinput value=''></input><input type=hidden name=commentary id=myinputcb value='" . $icb . "'></input><select name=voice id=myinputvc value='" . $vcb . "'>" . $svinnards . "</select></form>";
  } else {
    $svinnards='<option value="">Optionally add commentary with Voice ...</option>';
    for ($isv=0; $isv<sizeof($svarr); $isv++) {
     if (trim($svarr[$isv]) != '') {
      $svinnards.='<option value="' . explode(' ',$svarr[$isv])[0] . '">' . explode(' ',$svarr[$isv])[0] . ' ' . trim(str_replace(explode(' ',$svarr[$isv])[0],'',$svarr[$isv])) . '</option>';
     }
    }
    $selstuff="<br><form target=_blank onsubmit=\"formclickmode=0; document.body.style.cursor='pointer'; if (lastselo) { lastselo.style.cursor='pointer'; lastselo=null; } if (document.getElementById('opsel')) { if (document.getElementById('opsel').value.length > 0) { this.action=document.getElementById('opsel').value;  }   } return perhaps(true,this);\" id=myformmac method=GET style=display:none; action='http://localhost:8888/open_extravaganza.php'><div id=mydivmac></div><select title='Right click can modify dropdown choices' multiple style=background-color:yellow; size=21 id=myselmac name=afteropen onchange=\"if (this.value.length != 0) { if (1 == 1) { formclickmode=prg(1,event.target); } else { document.getElementById('sbutmac').click(); }  } \"><option oncontextmenu=ocmopt(this); value=''>Select macOS open command type(s) below ...</option><option oncontextmenu=ocmopt(this); value=' -a Finder'>Finder</option><option oncontextmenu=ocmopt(this); value=' -a Preview'>Preview</option><option oncontextmenu=ocmopt(this); value=' -a TextEdit'>TextEdit</option><option oncontextmenu=ocmopt(this); value=' -b com.apple.VoiceMemos'>Voice Memo</option><option oncontextmenu=ocmopt(this); value=' -b com.apple.QuickTimePlayerX https://www.rjmprogramming.com.au/Windows/windows_step_recorder.mov'>QuickTime Player</option><option oncontextmenu=ocmopt(this); value=' -b com.apple.VoiceOverUtility'>VoiceOver Utility</option><option oncontextmenu=ocmopt(this); value=' ~/Desktop/Screen\\ Shot\\ *.png'>Preview all screenshot files</option><option oncontextmenu=ocmopt(this); value=' -a Firefox https://www.rjmprogramming.com.au'>Firefox</option><option oncontextmenu=ocmopt(this); value=' -a Safari http://localhost:8888/macos_say_record.php?saythis=Welcome\\&voice=Karen\\&audioname=;open -a Safari http://localhost:8888/macos_say_record.php'>Safari interface attempt to say</option><option oncontextmenu=ocmopt(this); value=' -b com.apple.ScriptEditor2 ~/Desktop/test_gvp.scpt'>AppleScript example ready to Script-&gt;Run</option><option title='System sounds ... macOS ... right click for chance to try another system sound' oncontextmenu=ocmopt(this); value=' http://localhost:8888/mamp_beep.php?sound=beep'>Beep</option><option oncontextmenu=ocmopt(this); value=\"IGVjaG8gJzU2NCs5ODc2NScgfCBiYw==\">Add 564 to 98765</option><option oncontextmenu=ocmopt(this); value=' ~/Documents ~/Desktop ~/Downloads'>Open the D folders</option><option oncontextmenu=ocmopt(this); value=' \"http://localhost:8888/pbcopy_ideas.php?verb=" . urlencode("~/Documents") . urlencode("%20") . urlencode("~/Desktop") . urlencode("%20") . urlencode("~/Downloads") . "\"'>Clipboard paste and copy D folder listings</option><option oncontextmenu=ocmopt(this); value=' \"https://www.rjmprogramming.com.au/recording_ideas.php\"'>Record yourself</option><option oncontextmenu=ocmopt(this); value=' https://google.com'>Google</option><option oncontextmenu=ocmopt(this); value=' https://wikipedia.org'>Wikipedia</option><option oncontextmenu=ocmopt(this); value=' https://www.rjmprogramming.com.au'>RJM Programming</option><option oncontextmenu=ocmopt(this); value=' ls -l . | open -f'>Pipe folder listing into TextEdit</option><option oncontextmenu=ocmopt(this); value=' x-man-page://open'>Show man page in Terminal</option></select><br><br><input id=sbutmac type=submit value='Execute'></input>&nbsp;<input type=checkbox name=bgd id=myinputmac>Background</input><input type=hidden name=commentary id=myinputcbmac value='" . $icb . "'></input>&nbsp;<select onchange=commonoff(this); name=voice id=myinputvcmac value='" . $vcb . "'>" . $svinnards . "</select></form>";
    $selstuff.="<br><br><form target=_blank onsubmit=\"formclickmode=0; document.body.style.cursor='pointer'; if (lastselo) { lastselo.style.cursor='pointer'; lastselo=null; } if (document.getElementById('opsel')) {  if (document.getElementById('opsel').value.length > 0) {  this.action=document.getElementById('opsel').value;   }  } return perhaps(true,this);\" id=myformwin method=GET style=display:none; action='http://localhost/open_extravaganza.php'><div id=mydivwin></div><select title='Right click can modify dropdown choices' multiple style=background-color:yellow; size=7 id=myselwin name=afteropen onchange=\"if (this.value.length != 0) { if (1 == 1) { formclickmode=prg(-1,event.target); } else { document.getElementById('sbutwin').click(); }  } \"><option oncontextmenu=ocmopt(this); value=''>Select Windows explorer.exe command type(s) below ...</option><option oncontextmenu=ocmopt(this); value=' '>File Explorer</option><option oncontextmenu=ocmopt(this); value=' https://google.com'>Google</option><option oncontextmenu=ocmopt(this); value=' https://wikipedia.org'>Wikipedia</option><option oncontextmenu=ocmopt(this); value=' \"http://localhost/pbcopy_ideas.php?verb=" . "dir%20%2fc%2ft%2fl%2ft%20" . "Documents" . "%20" . "Desktop" . "%20" . "Downloads" . "\"'>Clipboard paste and copy D folder listings</option><option oncontextmenu=ocmopt(this); value=' https://www.rjmprogramming.com.au'>RJM Programming</option><option oncontextmenu=ocmopt(this); value=' \"https://www.rjmprogramming.com.au/recording_ideas.php\"'>Record yourself</option></select><br><br><input id=sbutwin type=submit value='Execute'></input>&nbsp;<input type=checkbox title=Background style=display:none; data-name=bgd id=myinputwin></input><input type=hidden data-name=commentary id=myinputcbwin value=''></input><input type=hidden data-name=voice id=myinputvcwin value=''></input></form>";
  }
  
  if (isset($_GET['afteropen'])) {
    if (sizeof(explode('afteropen=', '?' . $_SERVER['QUERY_STRING'])) > 2) {
    for ($thisone=1; $thisone<sizeof(explode('afteropen=', '?' . $_SERVER['QUERY_STRING'])); $thisone++) {
    if ($dobgd) {
    array_push($afteropens, ' -g ' . str_replace('open ','open -g ',str_replace('  ',' ' . $plusin,str_replace($plusin,$plusout,oururldecode(explode('#',explode('&',explode('afteropen=', $_SERVER['QUERY_STRING'])[$thisone])[0])[0])))));
    } else {
    array_push($afteropens, str_replace('  ',' ' . $plusin,str_replace($plusin,$plusout,oururldecode(explode('#',explode('&',explode('afteropen=', $_SERVER['QUERY_STRING'])[$thisone])[0])[0]))));
    }
    }
    } else {
    if ($dobgd) {
    $afteropen=(trim(str_replace('  ',' ' . $plusin,str_replace($plusin,$plusout,oururldecode($_GET['afteropen'])))) == '' ? '' : ' -g ' . trim(str_replace('  ',' ' . $plusin,str_replace($plusin,$plusout,oururldecode($_GET['afteropen'])))));
    } else {
    $afteropen=(trim(str_replace('  ',' ' . $plusin,str_replace($plusin,$plusout,oururldecode($_GET['afteropen'])))) == '' ? '' : ' ' . trim(str_replace('  ',' ' . $plusin,str_replace($plusin,$plusout,oururldecode($_GET['afteropen'])))));
    }
    $afteropens=[$afteropen];
    }
  } else if (isset($_POST['afteropen'])) {
    if (sizeof(explode('afteropen=', '?' . $_SERVER['QUERY_STRING'])) > 2) {
    for ($thisone=1; $thisone<sizeof(explode('afteropen=', '?' . $_SERVER['QUERY_STRING'])); $thisone++) {
    if ($dobgd) {
    array_push($afteropens, ' -g ' . str_replace('open ','open -g ',str_replace('  ',' ' . $plusin,str_replace($plusin,$plusout,oururldecode(explode('#',explode('&',explode('afteropen=', $_SERVER['QUERY_STRING'])[$thisone])[0])[0])))));
    } else {
    array_push($afteropens, str_replace('  ',' ' . $plusin,str_replace($plusin,$plusout,oururldecode(explode('#',explode('&',explode('afteropen=', $_SERVER['QUERY_STRING'])[$thisone])[0])[0]))));
    }
    }
    } else {
    if ($dobgd) {
    $afteropen=(trim(str_replace('  ',' ' . $plusin,str_replace($plusin,$plusout,oururldecode($_POST['afteropen'])))) == '' ? '' : ' -g ' . trim(str_replace('  ',' ' . $plusin,str_replace($plusin,$plusout,oururldecode($_POST['afteropen'])))));
    } else {
    $afteropen=(trim(str_replace('  ',' ' . $plusin,str_replace($plusin,$plusout,oururldecode($_POST['afteropen'])))) == '' ? '' : ' ' . trim(str_replace('  ',' ' . $plusin,str_replace($plusin,$plusout,oururldecode($_POST['afteropen'])))));
    }
    $afteropens=[$afteropen];
    }
  } 
  
  for ($i=0; $i<sizeof($afteropens); $i++) {
  $afteropen=$afteropens[$i];
  if ($afteropen != '' || isset($_GET['afteropen']) || isset($_POST['afteropen'])) {
   if (PHP_OS == 'Darwin') {
    if (strpos($afteropen, ' open ') === false) {
    if (strpos($afteropen, ' | bc') === false) {
    $preret.=$delim . 'open' . $afteropen;
    } else {
    $preret.=$delim . '' . str_replace('  ',' ',str_replace('-g','',$afteropen));
    }
    } else {
    $preret.=$delim . '' . $afteropen;
    }
    if (($i + 1) == sizeof($afteropens)) {
    if (strpos($preret, 'http://localhost:8888/mamp_beep.php') !== false) {
    if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'mamp_beep.php')) {
    if (isset($_GET['wop'])) { 
    $preret=str_replace('open ', 'curl "', $preret . '"'); //str_replace('open ', 'php ', str_replace('http://localhost:8888/',$_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR,str_replace('?sound=',' ',$preret)));
    //echo $preret;
    //exit;
    } else {
    $preret=str_replace('open ', 'curl "', $preret . '"');
    }
    } else if (strpos($preret, 'http://localhost:8888/mamp_beep.php?') === false) {
    $preret="osascript -e beep";
    } else if (strpos($preret, 'http://localhost:8888/mamp_beep.php?sound=beep') !== false) {
    $preret="osascript -e " . str_replace('+',' ',urldecode(explode('http://localhost:8888/mamp_beep.php?sound=',$preret)[1]));
    } else if (strpos($preret, 'http://localhost:8888/mamp_beep.php?sound=') !== false) {
    $preret=("afplay /System/Library/Sounds/" . strtoupper(substr(explode('http://localhost:8888/mamp_beep.php?sound=',$preret)[1],0,1)) . strtolower(substr(explode('http://localhost:8888/mamp_beep.php?sound=',$preret)[1],1)) . ".aiff");
    }
    } 
    $ret=shell_exec($preret);
    $preret.="\n";
    }
   } else if (substr(strtolower('' . PHP_OS),0,3) == 'win') {
    if (strpos($afteropen, 'http') !== false && strpos($afteropen, '?') !== false) {
      $twpart=explode('?', $afteropen)[1];
      $thpart=str_replace('/','%2f',str_replace(' ','%20',$twpart));
      if ($twpart != $thpart) {
        $afteropen=str_replace($twpart,$thpart,$afteropen);
      }
      header('Location: ' . 'http' . explode('http', str_replace('"','',$afteropen))[1]);
      exit;
    }
    if (strpos($afteropen, ' explorer. ') === false) {
    $preret.=$delim . 'explorer.exe ' . $afteropen . '';
    } else {
    $preret.=$delim . '' . $afteropen;
    }
    if (($i + 1) == sizeof($afteropens)) {
    if (1 == 1) {
    $fp = fopen(str_replace("/",$wds,$_SERVER['DOCUMENT_ROOT']) . $wds . 'open_extravaganza.bxt', 'x');
    fwrite($fp, str_replace(" ; ", "\n", $preret) . "\nerase " . str_replace("/",$wds,$_SERVER['DOCUMENT_ROOT']) . $wds . 'open_extravaganza.bat');
    fclose($fp);
    } else if (4 == 7) {
    $fp = fopen(str_replace("/",$wds,$_SERVER['DOCUMENT_ROOT']) . $wds . 'open_extravaganza.bat', 'x');
    fwrite($fp, str_replace(" ; ", "\n", $preret) . "\nerase " . str_replace("/",$wds,$_SERVER['DOCUMENT_ROOT']) . $wds . 'open_extravaganza.bat');
    fclose($fp);
    } else {
    file_put_contents(str_replace("/",$wds,$_SERVER['DOCUMENT_ROOT']) . $wds . 'open_extravaganza.bat', str_replace(" ; ", "\n", $preret) . "\nerase " . str_replace("/",$wds,$_SERVER['DOCUMENT_ROOT']) . $wds . 'open_extravaganza.bat');
    }
    try {
    if (file_exists(str_replace("/",$wds,$_SERVER['DOCUMENT_ROOT']) . $wds . 'open_extravaganza.bat')) {
    $ret=shell_exec(str_replace("/",$wds,$_SERVER['DOCUMENT_ROOT']) . $wds . 'open_extravaganza.bat');
    if (strpos($preret, ' | bc') !== false) { $preret.=' = ' . $ret;  }
    }
    } catch (Exception $e) {
    }  
  //passthru($preret);
//$descriptorspec = [STDIN, STDOUT, STDOUT];
//$cmd = $preret;
//$proc = proc_open($cmd, $descriptorspec, $pipes);
//$ret = fread($pipes[1], 1024);
//$ret .= fread($pipes[2], 1024);

//fclose($pipes[0]);
//fclose($pipes[1]);
//fclose($pipes[2]);

//proc_close($proc);
    //$ret=shell_exec($preret);
    //system($preret, $ret);
 //$file = popen($preret,"r");
 //some code to be executed
 //pclose($file);
   $preret.="\n";
    }
   }
  }
  $delim=' ; ';
  }
  
  $afteropens=[];
  $delim='';
  $thisone=1;

  if ($preret == '' && strpos($_SERVER['SERVER_NAME'], 'rjmprogramming.com.au') !== false) {
    $selstuff=str_replace('POST', 'GET', $selstuff);
    $preret=" <select size=3 title=\"Double or right click click (while set to MAMP) to go to Apache/PHP/MySql MAMP local web server webpage\" ondblclick=\"window.open('//www.mamp.info','_blank');\" oncontextmenu=\"event.stopPropagation(); 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='' selected>MAMP</option><option id=omacos oncontextmenu=macportchange(this); value='http://localhost:8888/open_extravaganza.php' title='Right click to peruse Apache (perhaps macOS MAMP) port assumption'>macOS</option><option id=owindows oncontextmenu=winportchange(this); value='http://localhost/open_extravaganza.php' title='Right click to peruse Apache (perhaps Windows MAMP) port assumption'>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;
    var formclickmode=0;
    var lastselo=null, aptselo=null, aptformo=null;
    var macosport=':8888', winport='';
    var gmacosport=' ', gwinport=' ';
    var bassomore=String.fromCharCode(10) + ' Rather than beep you could use other macOS system sound names Basso or Blow or Bottle or Frog or Funk or Glass or Hero or Morse or Ping or Pop or Purr or Sosumi or Submarine or Tink';
    
     function anal(videa) {
       if (videa.indexOf('+') != -1) {
          return window.btoa(videa);
       }
       return videa;
     }
     
     function commonoff(osel) {
       if (osel.value.trim() == '') {
        document.getElementById(aptformo.id.replace('form','inputcb')).value=''; 
       } else {
        document.getElementById(aptformo.id.replace('form','inputcb')).value='y'; 
       }
     }
    
     function macportchange(opto) {
     var spare='';
     var newidea=null;
     if (gmacosport != ' ') {
     newidea=gmacosport.trim();
     gmacosport=' ';
     } else {
     event.stopPropagation();
     newidea=prompt('Change the macOS Apache (perhaps MAMP) port as required?', macosport);
     }
     if (newidea == null) { return ''; }
     if (newidea == macosport) { return ''; }
     var jf=0, formos=document.getElementsByTagName('form');
     if (newidea.trim() != '' && newidea.substring(0,1) != ':') { spare=':' + newidea.trim();  } else {  spare=newidea.trim(); }
     if (macosport != spare) {
           for (jf=0; jf<formos.length; jf++) {
             if (('' + formos.action).indexOf('localhost' + macosport + '/') != -1) {
                formos.action=formos.action.replace('localhost' + macosport + '/', 'localhost' + spare + '/');
             }
           }  
     }
     if (newidea.trim() != '' && newidea.substring(0,1) != ':') { macosport=':' + newidea.trim();  } else {  macosport=newidea.trim(); }
     try {
          window.localStorage.removeItem('open_extravaganza_macport');
     } catch(weeeeeeee) {  }    
     try {
          window.localStorage.setItem('open_extravaganza_macport', encodeURIComponent(macosport));
     } catch(veeeeeeee) {  }  
     return '';  
     }
    
     function winportchange(opto) {
     var spare='';
     var newidea=null;
     if (gwinport != ' ') {
     newidea=gwinport.trim();
     gwinport=' ';
     } else {
     event.stopPropagation();
     newidea=prompt('Change the Windows Apache (perhaps MAMP) port as required?', winport);
     }
     if (newidea == null) { return ''; }
     if (newidea == winport) { return ''; }
     var jf=0, formos=document.getElementsByTagName('form');
     if (newidea.trim() != '' && newidea.substring(0,1) != ':') { spare=':' + newidea.trim();  } else {  spare=newidea.trim(); }
     if (winport != spare) {
           for (jf=0; jf<formos.length; jf++) {
             if (('' + formos.action).indexOf('localhost' + winport + '/') != -1) {
                formos.action=formos.action.replace('localhost' + winport + '/', 'localhost' + spare + '/');
             }
           }  
     }
     if (macosport != ':8888') {
           for (jf=0; jf<formos.length; jf++) {
             if (('' + formos.action).indexOf('localhost:8888/') != -1) {
                formos.action=formos.action.replace(':8888/', macosport + '/');
             }
           }  
     }
     if (newidea.trim() != '' && newidea.substring(0,1) != ':') { winport=':' + newidea.trim();  } else {  winport=newidea.trim(); }
     try {
          window.localStorage.removeItem('open_extravaganza_winport');
     } catch(ueeeeeeee) {  }    
     try {
          window.localStorage.setItem('open_extravaganza_winport', encodeURIComponent(winport));
     } catch(teeeeeeee) {  }    
     return '';
     }
    
    function ocmopt(opto) {
      var remem=false;
      var vis=prompt('Change value#wording? ' + String.fromCharCode(10) + ' Start with a + to add the entry. ' + String.fromCharCode(10) + ' Just - forgets this option. ' + String.fromCharCode(10) + ' Ends with three blanks to remember for next time. ' + String.fromCharCode(10) + ' Ends with two blanks unremembers.' + (opto.value.indexOf('/mamp_beep.php') != -1 ? bassomore : ''), (opto.value + '#' + opto.innerText));
      if (vis == null) { return '';   }
      var hp=eval(1 + eval('' + vis.indexOf('#')));
      if (vis == '') { return '';   }
      if (vis == (opto.value + '#' + opto.innerText)) { return '';   }
      if (vis.replace(/\ \ \ $/g,'') != vis) { 
        remem=true; 
        vis=vis.replace(/\ \ \ $/g,''); 
        try {
          window.localStorage.removeItem('open_extravaganza_selectih');
        } catch(eeeeeee) {  }    
      } else if (vis.replace(/\ \ $/g,'') != vis) {
        try {
          window.localStorage.removeItem('open_extravaganza_selectih');
        } catch(eeeeee) {  }    
      }
      if (vis == '  ') { location.href=document.URL.split('?')[0].split('#')[0]; vis=''; return '';   }
      while (vis.indexOf('  ') != -1) {
         vis=vis.replace('  ',' ');
      }
      if (vis == '-') {
      opto.value='';
      opto.innerHTML='';
      } else if (vis.substring(0,1) == '+') {
      if (vis.indexOf('#') != -1) { aptselo.innerHTML+='<option oncontextmenu=ocmopt(this); value=\"' + anal((' ' + vis.substring(1).split('#')[0]).replace('  ',' ')) + '\">' + vis.substring(hp) + '</option>'; aptselo.size='' + eval(1 + eval('' + aptselo.size));  } else {  aptselo.innerHTML+='<option oncontextmenu=ocmopt(this); value=\"' + ' ' + vis.substring(1).split('#')[0] + '\">...</option>';  aptselo.size='' + eval(1 + eval('' + aptselo.size));    }
      } else {
      opto.value=anal((' ' + vis.split('#')[0]).replace('  ',' '));
      if (vis.indexOf('#') != -1) { opto.innerHTML=vis.substring(hp);   }
      }
      aptformo.action=('' + aptformo.action).split('#') + '#' + encodeURIComponent(aptselo.innerHTML);
      if (remem) {
        try {
          window.localStorage.setItem('open_extravaganza_selectih', encodeURIComponent(aptselo.innerHTML));
        } catch(eeeeeeee) {  }    
      }
      return '';
    }
    
    function fcm() {
      if (formclickmode == 0) {
        formclickmode=0;
      } else if (formclickmode < 0) {
        formclickmode--;
        if (formclickmode <= -10) {
          document.body.style.cursor='pointer';
          if (lastselo) { lastselo.style.cursor='pointer'; lastselo=null; }
          formclickmode=0;
          document.getElementById('sbutwin').click();
        }
      } else {
        formclickmode++;
        if (formclickmode >= 10) {
          document.body.style.cursor='pointer';
          if (lastselo) { lastselo.style.cursor='pointer'; lastselo=null; }
          formclickmode=0;
          document.getElementById('sbutmac').click();
        }
      }
    }
    
    function mostlikely() {
     var spare='';
     try {
          spare=('' + window.localStorage.getItem('open_extravaganza_macport'));
          if (spare != 'null' && spare != 'undefined') {
          macosport=decodeURIComponent(window.localStorage.getItem('open_extravaganza_macport'));
          }
     } catch(zeeeeeeee) {  }    
     try {
          spare=('' + window.localStorage.getItem('open_extravaganza_winport'));
          if (spare != 'null' && spare != 'undefined') {
          winport=decodeURIComponent(window.localStorage.getItem('open_extravaganza_winport'));
          }
     } catch(yeeeeeeee) {  }    
     if (document.getElementById('opsel')) {
      if (('' + navigator.platform).toLowerCase().indexOf('mac') != 0) {
        if (('' + navigator.platform).toLowerCase().indexOf('win') != -1) {
        if (document.getElementById('myformwin')) {
          document.getElementById('myformwin').style.display='block';
          aptselo=document.getElementById('myselwin');
          aptformo=document.getElementById('myformwin');
        }
        }
        document.getElementById('opsel').innerHTML=document.getElementById('omamp').outerHTML + document.getElementById('owindows').outerHTML + document.getElementById('omacos').outerHTML;
      } else {
        if (document.getElementById('myformmac')) {
          document.getElementById('myformmac').style.display='block';
          aptselo=document.getElementById('myselmac');
          aptformo=document.getElementById('myformmac');
        }
      }
     }
     spare='';
     if (aptselo == null) {  aptselo=document.getElementById('mysel');  aptformo=document.getElementById('myform'); }
     if (('' + location.hash).replace(/^undefined/g,'').replace(/^null/g,'').replace(/^\#/g,'').trim() != '') {
        if (decodeURIComponent(('' + location.hash).replace(/^undefined/g,'').replace(/^null/g,'').replace(/^\#/g,'')).indexOf('<option') != -1) {
           if (decodeURIComponent(('' + location.hash).replace(/^undefined/g,'').replace(/^null/g,'').replace(/^\#/g,'')).indexOf('<option') > 0) {
             spare=decodeURIComponent(('' + location.hash).replace(/^undefined/g,'').replace(/^null/g,'').replace(/^\#/g,'')).split('<option')[0].trim();
             if (spare.indexOf('macport') != -1) {
               macosport=spare.split('macport')[1].split(' ')[0].split('winport')[0].replace(/^\=/g,'');
          //alert(245);
     try {
          window.localStorage.removeItem('open_extravaganza_macport');
     } catch(weeeeeeee) {  }    
     try {
          window.localStorage.setItem('open_extravaganza_macport', encodeURIComponent(macosport));
     } catch(veeeeeeee) {  }    
             }
             if (spare.indexOf('winport') != -1) {
               winport=spare.split('winport')[1].split(' ')[0].split('macport')[0].replace(/^\=/g,'');
     try {
          window.localStorage.removeItem('open_extravaganza_winport');
     } catch(ueeeeeeee) {  }    
     try {
          window.localStorage.setItem('open_extravaganza_winport', encodeURIComponent(winport));
     } catch(teeeeeeee) {  }    
             }
           }
           aptselo.innerHTML=decodeURIComponent(('' + location.hash).replace(/^undefined/g,'').replace(/^null/g,'').replace(/^\#/g,'')).substring(decodeURIComponent(('' + location.hash).replace(/^undefined/g,'').replace(/^null/g,'').replace(/^\#/g,'')).indexOf('<option'));
           aptselo.size='' + eval(-1 + eval('' + aptselo.innerHTML.split('</option').length));
           aptformo.action=('' + aptformo.action).split('#') + '#' + encodeURIComponent(aptselo.innerHTML);
        }
     } else {
        try {
          var selih='' + decodeURIComponent('' + window.localStorage.getItem('open_extravaganza_selectih'));
          if (selih.indexOf('<option') != -1) {
           aptselo.innerHTML=selih;
           aptselo.size='' + eval(-1 + eval('' + aptselo.innerHTML.split('</option').length));
           aptformo.action=('' + aptformo.action).split('#') + '#' + encodeURIComponent(aptselo.innerHTML);
          }
        } catch(eeeeee) {  }    
     }
     
     if (document.URL.indexOf('localhost') != -1) {
      if (('' + navigator.platform).toLowerCase().indexOf('mac') != 0) {
        if (('' + navigator.platform).toLowerCase().indexOf('win') != -1) {
        if (document.URL.indexOf('localhost' + winport + '/') == -1) {
          gwinport=document.URL.split('localhost')[1].split('/')[0];
          winportchange(null);
        }
        }
      } else {
        if (document.URL.indexOf('localhost' + macosport + '/') == -1) {
          gmacosport=document.URL.split('localhost')[1].split('/')[0];
          macportchange(null);
        }
      }
     }
     
     var jf=0, formos=document.getElementsByTagName('form');
     if (winport != '') {
           for (jf=0; jf<formos.length; jf++) {
             if (('' + formos.action).indexOf('localhost/') != -1) {
                formos.action=formos.action.replace('localhost/', 'localhost' + winport + '/');
             }
           }  
     }
     if (macosport != ':8888') {
           for (jf=0; jf<formos.length; jf++) {
             if (('' + formos.action).indexOf('localhost:8888/') != -1) {
                formos.action=formos.action.replace(':8888/', macosport + '/');
             }
           }  
     }
    }
    
    function prg(wht, selo) {
      if (selo) { lastselo=selo; lastselo.style.cursor='progress'; }
      document.body.style.cursor='progress';
      return wht;
    }



  function doemail(inemis) {
    var arrinput=[], karr=0;
    var huhhash='youllneverfindthis';
    wasdb='';
    suffis='';
    var anchor=null, xmore=''; 
    var emis='';
    if (('' + aptformo.action).indexOf('#') != -1) { xmore='  Add three spaces at the end to ignore the dropdown option changes you have made in terms of what the recipient sees.'; }
    if (('' + inemis).replace(/^undefined/g,'').replace(/^null/g,'') != '') {
      emis=inemis;
    } else {
      emis=prompt('Please enter email address to send to.' + xmore, '');
    }
    if (emis == null) { emis=''; } 
    if (emis.replace(/\ \ \ $/g,'') != emis) {  emis=emis.replace(/\ \ \ $/g,''); huhhash='#'; }
    if (emis.indexOf('@') != -1) {
                anchor = document.createElement('a');
                if (emis.trim() == emis.trim().toUpperCase()) {
                anchor.href = 'mailto:' + nosq(emis.trim()) + '?subject=My%20Local%20Desktop%20Functionality%20Menu' + (inemis == '' ? '' : encodeURIComponent(' ' + inemis.replace('#',','))) + '&body=' + encodeURIComponent(aptformo.action.split(huhhash)[0]);
                } else {
                anchor.href = 'mailto:' + nosq(emis.trim()) + '?subject=My%20Local%20Desktop%20Functionality%20Menu' + (inemis == '' ? '' : encodeURIComponent(' ' + inemis.replace('#',','))) + '&body=' + encodeURIComponent(aptformo.action.split(huhhash)[0]);
                }
                anchor.style.display='none';
                document.body.appendChild(anchor);
                anchor.innerHTML='Email';
                anchor.target='_top';
                anchor.click();
    } else if (emis.trim() != '' && emis.trim().replace(/0/g,'').replace(/1/g,'').replace(/2/g,'').replace(/3/g,'').replace(/4/g,'').replace(/5/g,'').replace(/6/g,'').replace(/7/g,'').replace(/8/g,'').replace(/9/g,'') == '') {
                anchor = document.createElement('a');
                anchor.href = 'sms:' + nosq(emis.trim()) + '&body=' + encodeURIComponent(aptformo.action.split(huhhash)[0]); 
                anchor.style.display='none';
                anchor.innerHTML='SMS';
                anchor.target='_top';
                anchor.click();
    }
  }
 
  function dosms(inemis) {
    var arrinput=[], karr=0;
    var huhhash='youllneverfindthis';
    wasdb='';
    suffis='';
    var anchor=null, xmore='';
    var emis='';
    if (('' + aptformo.action).indexOf('#') != -1) { xmore='  Add three spaces at the end to ignore the dropdown option changes you have made in terms of what the recipient sees.'; }
    if (('' + inemis).replace(/^undefined/g,'').replace(/^null/g,'') != '') {
      emis=inemis;
    } else {
      emis=prompt('Please enter SMS number to send to.' + xmore, '');
    }
    if (emis == null) { emis=''; }
    if (emis.replace(/\ \ \ $/g,'') != emis) {  emis=emis.replace(/\ \ \ $/g,''); huhhash='#'; }
    if (emis.indexOf('@') != -1) {
                anchor = document.createElement('a');
                if (emis.trim() == emis.trim().toUpperCase()) {
                anchor.href = 'mailto:' + nosq(emis.trim()) + '?subject=My%20Local%20Desktop%20Functionality%20Menu' + (inemis == '' ? '' : encodeURIComponent(' ' + inemis.replace('#',','))) + '&body=' + encodeURIComponent(aptformo.action.split(huhhash)[0]);
                } else {
                anchor.href = 'mailto:' + nosq(emis.trim()) + '?subject=My%20Local%20Desktop%20Functionality%20Menu' + (inemis == '' ? '' : encodeURIComponent(' ' + inemis.replace('#',','))) + '&body=' + encodeURIComponent(aptformo.action.split(huhhash)[0]);
                }
                anchor.style.display='none';
                document.body.appendChild(anchor);
                anchor.innerHTML='Email';
                anchor.target='_top';
                anchor.click();
    } else if (emis.trim() != '' && emis.trim().replace(/0/g,'').replace(/1/g,'').replace(/2/g,'').replace(/3/g,'').replace(/4/g,'').replace(/5/g,'').replace(/6/g,'').replace(/7/g,'').replace(/8/g,'').replace(/9/g,'') == '') {
                anchor = document.createElement('a');
                anchor.href = 'sms:' + nosq(emis.trim()) + '&body=' + encodeURIComponent(aptformo.action.split(huhhash)[0]);
                anchor.style.display='none';
                anchor.innerHTML='SMS';
                anchor.target='_top';
                anchor.click();
    }
  }

    function nosq(inq) {
      return inq;
    }
    
    function selanal(sin) {
    var rva='';
    for (var ii=0; ii<sin.options.length; ii++) {
    if (sin.options[ii].selected) {
      if (sin.options[ii].value != '') {  
        if (rva == '') {
          rva='You selected ' + sin.options[ii].text;
        } else {
          rva+=' and ' + sin.options[ii].text;
        }
      }
    }
    }
    return rva;
    }
    
    function perhaps(intrue, thisformo) {
      if (document.getElementById(thisformo.id.replace('form','inputcb'))) {
        if (document.getElementById(thisformo.id.replace('form','inputcb')).value == 'y') {
           if (document.getElementById(thisformo.id.replace('form','sel'))) {
             document.getElementById(thisformo.id.replace('form','inputcb')).value=selanal(document.getElementById(thisformo.id.replace('form','sel')));
           }
        }
      } 

      return intrue;
    }
    
    setInterval(fcm, 1000);
</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 <button onclick=\"setTimeout(function(){ doemail(''); }, 2000);\" id=butemail>Email &#128231;</button>&nbsp;&nbsp;<button onclick=\"setTimeout(function(){ dosms(''); }, 2000);\" id=butsms>SMS &#128223;</button></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> and <a target=_blank title='https://www.geoffchappell.com/studies/windows/shell/explorer/cmdline.htm' href='//www.geoffchappell.com/studies/windows/shell/explorer/cmdline.htm'>https://www.geoffchappell.com/studies/windows/shell/explorer/cmdline.htm</a></h4><br><p>" . str_replace("\n","<br>",$preret) . str_replace("\n","<br>",$ret) . "</p>" . $selstuff . "</body>
</html>";
?>
