<?php
// get_tz.php
// RJM Programming
// Optionally helps out x1.cc 
if (!isset($argc)) { 
  $scr="<script type='text/javascript'>
  function myifer() {
    parent.document.getElementById('myif').src=document.URL.split('#')[0].split('?')[0] + '?rand=' + Math.floor(Math.random() * 1987564) + '&tz=' + (location.search.split('tz=')[1] ? location.search.split('tz=')[1].split('&')[0] : '');
  }
  function onl() {
    if (window.parent && document.URL.indexOf('&') != -1) {
      if (parent.document.getElementById('ds')) {
       var huh=parent.document.getElementById('ds').innerHTML;
       parent.document.getElementById('ds').innerHTML='<iframe id=myif style=height:30px; src=\"' + document.URL.split('#')[0].split('?')[0] + '?rand=' + Math.floor(Math.random() * 1987564) + '&tz=' + (location.search.split('tz=')[1] ? location.search.split('tz=')[1].split('&')[0] : '') + '\"></iframe><br>'; // + huh;
       setTimeout(myifer, 2000);
      }
    } else if (!document.getElementById('myif')) {
      document.body.innerHTML+='<iframe id=myif style=display:none; src=></iframe>';
    } else if (1 == 2) {
      document.getElementById('myif').src=document.URL.split('#')[0].split('?')[0] + '?rand=' + Math.floor(Math.random() * 1987564) + '&tz=' + (location.search.split('tz=')[1] ? location.search.split('tz=')[1].split('&')[0] : '');
      setTimeout(onl, 2000);
    }
  }
  </script>";
if (isset($_GET['tz'])) {
//while (1) {
  //sleep(1);
  echo "<doctype html><html><head>" . $scr . "</head><body onload=setTimeout(onl,1500);><p id=xds>" . passthru("TZ=" . urldecode($_GET['tz']) . " date") . "</p></body></html>";
//}
//exit;
} else {
echo "<!doctype html><html><head>" . $scr . "</head><body onload=onl();><div id=ds></div><input style='width:50%;' onblur=\"if (this.value.indexOf('/') != -1) { document.getElementById('myif').src=document.URL.split('#')[0].split('?')[0] + '?rand=1&tz=' + encodeURIComponent(this.value);  } \" type=text placeholder='Optionally specify timezone that is not your local one eg. Europe/Berlin' name=tz id=tz value=''></input><input type=text style='position:absolute;left:-200px;top:-200px;' value=''></input><iframe id=myif style=display:none; src=></iframe>"; 
}
} else {
if (file_exists("stop_x1.x1")) { unlink("stop_x1.x1"); }
$line = readline("Optionally specify timezone that is not your local one eg. Europe/Berlin (else return): ");
if (strpos(trim($line), "/") !== false) {
  file_put_contents("stop_x1.x1", "");
  sleep(2);
  exec("TZ=" . $line . " ./x1 " . $line);
  exit(1);
} else {
  exit(0);
} 
}
?>
