<?php
 // daylight_saving_time.php
 // RJM Programming
 // September, 2015
 // Thanks to http://gomashup.com
 $retstuff="";
 $tzi="";
 $place="";
 $region="";
 if (isset($_GET['place'])) $place=$_GET['place'];
 if (isset($_POST['place'])) $place=$_POST['place'];
 if (isset($_GET['region'])) $region=$_GET['region'];
 if (isset($_POST['region'])) $region=$_POST['region'];
 if (isset($_GET['url'])) {
   //file_put_contents("xc.xc", urldecode($_GET['url']));
   $acontobodyinnerHTML=@file_get_contents(urldecode($_GET['url']));
   $tablestuff="<table cellpadding=5 cellspacing=5><thead><tr><th>Time Zone ID</th><th>Daylight Saving Time (<i>Now</i>)</th><th>Greenwich Mean Time(zone)</th></tr></thead><tbody></tbody></table>";
   $disp=true;
   $stuff=explode(" : ", $acontobodyinnerHTML);
   if (sizeof($stuff) > 1) {
         for ($i=1; $i<sizeof($stuff); $i+=3) {
           $dqstuff=explode('"', $stuff[$i]);
           $tzi=$dqstuff[1];
           $dqstuff=explode('"', $stuff[(1 + $i)]);
           $dst=$dqstuff[1];
           $dqstuff=explode('"', $stuff[(2 + $i)]);
           $gmt=$dqstuff[1];
           $disp=true;
           if ($region != "") {
             if (strpos(("~" . $tzi), "~" . $region . "-") === false) $disp=false;
           }
           if ($place != "") {
             if (strpos(strtolower(str_replace("_", " ", $tzi)), strtolower(str_replace("_", " ", $place))) === false) $disp=false;
           }
           if ($disp) {
             // Thanks to http://stackoverflow.com/questions/851574/how-do-i-get-greenwich-mean-time-in-php
             $timestamp = time();
             date_default_timezone_set(str_replace("-", "/", $tzi));

             if ($dst != $gmt) {
              $tablestuff=str_replace("</tbody>", "<tr><td><a href='#" . $tzi . "' id='" . $tzi . "' onclick='wois=window.open(\"http://www.timezoneconverter.com/cgi-bin/zoneinfo?tz=" . str_replace("-", "/", $tzi) . "\",\"_blank\",\"top=50,left=50,width=700,height=800\"); setTimeout(repos,2000); '>" . $tzi . "</a></td><td><b><font color=blue>" . $dst . "</font></b>    (<i>" . date('r', $timestamp) . "</i>)</td><td>" . $gmt . "</td></tr></tbody>", $tablestuff);
            } else {
              $tablestuff=str_replace("</tbody>", "<tr><td><a href='#" . $tzi . "' id='" . $tzi . "' onclick='wois=window.open(\"http://www.timezoneconverter.com/cgi-bin/zoneinfo?tz=" . str_replace("-", "/", $tzi) . "\",\"_blank\",\"top=50,left=50,width=700,height=800\"); setTimeout(repos,2000); '>" . $tzi . "</a></td><td>" . $dst . "    (<i>" . date('r', $timestamp) . "</i>)</td><td>" . $gmt . "</td></tr></tbody>", $tablestuff);
             }
           }
         }
         $retstuff='<html><head><style> td { text-align: center; } </style><scri' . 'pt> var rt="' . str_replace("+", " ", urlencode($tablestuff)) . '"; </scr' . 'ipt></head><body onload=" parent.document.getElementById(' . "'result'" . ').innerHTML=decodeURIComponent(rt); "></body></html>';
   }
 }
 echo $retstuff;
?>