<?php
// feed_via_date.php
// RJM Programming
// October, 2018
// Plug dates into feed URLs that ask for that

function mailit($ht, $ou) {
  global $to, $two, $four, $xrest;
  $outwo="";
  $purl=$ou . $xrest;
  if ($four != "" && $two != "") {
  $purl=str_replace($two, "YYYY-mm-dd", $purl);
  if (substr($four,0,1) >= "0" && substr($four,0,1) <= "9") { $purl=str_replace($four, "YYYY-mm-dd", $purl); } 
  $subject="Report regarding date " . $two . " and " . $four . " at " . date("l jS \of F Y h:i:s A") . " with " . $ou;
            $filname="feed_" . str_replace(" ","_",str_replace(":","-",str_replace(":","-",$two))) . "-to-" . str_replace(" ","_",str_replace(":","-",str_replace(":","-",$four))) . "_via_date.html";
  } else if ($two != "") {
  $purl=str_replace($two, "YYYY-mm-dd", $purl);
  $subject="Report regarding date " . $two . " at " . date("l jS \of F Y h:i:s A") . " with " . $ou;
            $filname="feed_" . str_replace(" ","_",str_replace(":","-",str_replace(":","-",$two))) . "_via_date.html";
  } else {
  $subject="Report at " . date("l jS \of F Y h:i:s A") . " with " . $ou;
            $filname="feed_" . date("Y-m-d") . "_via_date.html";
  }
  $outwo=" or to do another date of your own click " . "https://www.rjmprogramming.com.au/PHP/feed_via_date.php?justfillin=y&urlfeed=" . urlencode($purl);
            $eol = PHP_EOL;
            $headers = 'From: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
            $headers .= 'Reply-To: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;

                $content = chunk_split(base64_encode( str_replace(" action='//"," action='https://",$ht) ));
                //$uid = md5(uniqid(time()));

                // a random hash will be necessary to send mixed content
                $separator = md5(time());

                $headers .= "MIME-Version: 1.0" . $eol;
                $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol . $eol;
                $headers .= "Content-Transfer-Encoding: 7bit" . $eol;
                $headers .= "This is a MIME encoded message." . $eol . $eol;

                // message
                $headers .= "--" . $separator . $eol;
                $headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol;
                $headers .= "Content-Transfer-Encoding: 8bit" . $eol . $eol;

                $headers .= "Please see attachment below, which is the same as just clicking the " . $ou . $outwo . " link:" . $eol . $eol;

            //ourpremail($tem, $mysubject, "", $headers . "--" . $separator . "--");

                // attachment
                $headers .= "--" . $separator . $eol;
                $headers .= "Content-Type: application/octet-stream; name=\"" . $filname . "\"" . $eol;
                $headers .= "Content-Transfer-Encoding: base64" . $eol;
                $headers .= "Content-Disposition: attachment;filename=\"" . $filname . "\"" . $eol;
                $headers .= $content . $eol . $eol;

                $headers .= "--" . $separator . "--";

            mail($to, $subject, "", $headers);
}

function relative_to_absolute($inth) {
    global $urlis;
    $ub="HTTP://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0];
    if ($urlis != "") {
      $ubf=explode("?", $urlis);
      $ubff=explode("/", $ubf[0]);
      if (strpos($ubff[sizeof($ubff) - 1], ".") !== false && (sizeof($ubff) - 1) > 2) {
       $ub=str_replace("/" . $ubff[sizeof($ubff) - 1], "/", $ubf[0]);
     } else {
       $ub=str_replace("@$@", "", str_replace("/@$@", "/", ($ubf[0] . "@$@")));
      }
      $urlis="";
    }
    $ubf=explode("?", $ub);
    $udirname=str_replace("/feed" . "_via_date.php", "/", $ubf[0]);
    //$low = strtolower($inth);
    $inth=str_replace(' href="javascript:"', ' hReF="javascript:"', $inth);
    $inth=str_replace(' href="mailto:"', ' hReF="mailto:"', $inth);
    $outth = $inth;
    $ideas = array(" data-ng-include=\"'", " action='", ' action="', " Action='", ' Action="', " ACTION='", ' ACTION="', " action=", " Action=", " ACTION=", " href='", ' href="', " Href='", ' Href="', " HREF='", ' HREF="', " href=", " Href=", " HREF=", " src='", ' src="', " Src='", ' Src="', " SRC='", ' SRC="', " src=", " Src=", " SRC=");
    if ($udirname != "") {
     for ($m=0; $m<sizeof($ideas); $m++) {
      $huhs = explode($ideas[$m], $inth);
      if (sizeof($huhs) > 1) {
        for ($ii=(sizeof($huhs) - 1); $ii>=1; $ii--) {
          if (strtolower(str_replace("file", "http", strtolower(substr($huhs[$ii], 0, 4)))) == "http") {
            $outth = $outth;
          } else if (substr($huhs[$ii], 0, 1) != "/" && substr($huhs[$ii], 0, 1) != "'" && substr($huhs[$ii], 0, 1) != '"') {
            $outth = str_replace($huhs[$ii], $udirname . $huhs[$ii], $outth);
          } else if (substr($huhs[$ii], 1, 1) != "/" && substr($huhs[$ii], 0, 1) != "'" && substr($huhs[$ii], 0, 1) != '"') {
            $outth = str_replace($huhs[$ii], substr($udirname, 0, (strlen($udirname) - 1)) . $huhs[$ii], $outth);
          }
        }
      }
     }
    }
    return $outth;
}

$ufrom="YYYY-mm-dd";
$uto="YYYY-mm-dd";
$clk="document.getElementById('straight').click();";
if (isset($_GET['justfillin']) || isset($_POST['justfillin'])) {
  $clk="";
  $uto=date('Y-m-d');
}
$urlis="";
$to="";
$scriptis="<scr" . "ipt type='text/javascript'>
  var tis='_self', mif='myiframe';
  function osm() {
      document.getElementById('myform').target=tis;
      return true;
  }
  function pieceurl() {
      var pit='';
      document.getElementById('feedurl').value='';
      if (document.getElementById('prefixfeedurl').value.toUpperCase().indexOf('HTTP') == 0) {
        pit=document.getElementById('prefixfeedurl').value;
        pit+=encodeURIComponent(document.getElementById('firstdate').value);
        pit+=document.getElementById('middlefeedurl').value;
        pit+=encodeURIComponent(document.getElementById('seconddate').value);
        if (document.getElementById('everyn').value.replace('0','').replace('.0','') != '') {
         if (document.getElementById('everyunit').value == '') {
          pit+='#' + document.getElementById('everyn').value + 'minute';
         } else {
          pit+='#' + document.getElementById('everyn').value + document.getElementById('everyunit').value;
         }
        }
        if (document.getElementById('optionalemail').value.replace('emailee@goes.here','').indexOf('@') != -1) {
         if (pit.replace('/#/','').indexOf('#') != -1) {
          pit+='%20' + encodeURIComponent(document.getElementById('optionalemail').value);
         } else {
          pit+='#' + encodeURIComponent(document.getElementById('optionalemail').value);
         }
         if (document.getElementById('je').innerHTML.length == 0) {
          document.getElementById('je').innerHTML=\"&nbsp;<input onmouseover='tis=mif;' onclick='tis=mif;' style='background-color:yellow;' type=submit name=justemail id=justemail value='Just Email ...'></input>\";
          document.getElementById('myform').target='myiframe';
         }
        }
        document.getElementById('feedurl').value=pit;
      }
  }
</scr" . "ipt>";

$wholeu="";
$one="";
$two="";
$three="";
$four="";
$five="emailee@goes.here";
$six="0.0";
$minutesel="";
$hoursel="";
$daysel="";
$xrest="@!@!@@@!^$";

$htmlis="<!doctype><html><head>" . $scriptis . "</head><body><div id=msg></div><iframe name=myiframe id=myiframe style='display:none;' src=''></iframe></body></html>";
if (isset($_GET['feedurl']) || isset($_GET['urlfeed'])) {
  if (isset($_GET['feedurl'])) {
  $wholeu=str_replace($ufrom,$uto,str_replace("+"," ",$_GET['feedurl']));
  } else {
  $wholeu=str_replace($ufrom,$uto,str_replace("+"," ",$_GET['urlfeed']));
  }
  if ($wholeu != "") {
  $urlis=explode("#",$wholeu)[0];
  if (strpos($wholeu, "#") !== false) {
    $rest=str_replace("%20"," ",str_replace("%40","@",explode("#", $wholeu)[-1 + sizeof(explode("#", $wholeu))]));
    if (strpos($rest, "@") !== false) {
      $to=explode(" ",$rest)[-1 + sizeof(explode(" ",$rest))];
      $five=$to;
      $rest=str_replace($to,"",$rest);
      $xrest="#" . explode("#", $wholeu)[-1 + sizeof(explode("#", $wholeu))];
    }
    if (strpos($rest, "minute") !== false) {
      $six=explode("minute",$rest)[0];
      $minutesel=" selected";
      $xrest="#" . explode("#", $wholeu)[-1 + sizeof(explode("#", $wholeu))];
    } else if (strpos($rest, "hour") !== false) {
      $six=explode("hour",$rest)[0];
      $hoursel=" selected";
      $xrest="#" . explode("#", $wholeu)[-1 + sizeof(explode("#", $wholeu))];
    } else if (strpos($rest, "day") !== false) {
      $six=explode("day",$rest)[0];
      $daysel=" selected";
      $xrest="#" . explode("#", $wholeu)[-1 + sizeof(explode("#", $wholeu))];
    } else if (trim($rest) != "") {
      if (substr($rest,0,1) >= "0" && substr($rest,0,1) <= "9") {
      $six=trim($rest);
      $xrest="#" . explode("#", $wholeu)[-1 + sizeof(explode("#", $wholeu))];
      }
    } 
  }
  if (strpos($wholeu, "=") !== false) {
    $one=explode("=", $wholeu)[0] . "=";
    $two=explode("#",explode("&",explode($one, $wholeu)[1])[0])[0];
    if (strpos(explode(($one . $two), $wholeu)[1], "=") !== false) {
     $three=explode("=",explode(($one . $two), $wholeu)[1])[0] . "=";
     $four=explode("#",explode("&",explode(($one . $two . $three), $wholeu)[1])[0])[0];
    }
  } else {
    $one=explode("#", $wholeu)[0];
  }
  if (strpos(($wholeu . "?"), "/feed_via_date.php?") !== false || strpos(($wholeu . "?"), "/feed_via_date.php#") !== false) {
    $repcont="Welcome to feed_via_date.php on " . date("l jS \of F Y h:i:s A");
    if (isset($_GET['justemail'])) {
       mailit("<html><body><p>" . $repcont . "</p></body></html>", str_replace($xrest,"", $wholeu)); 
       exit; 
    }
  } else if (isset($_GET['feedurl'])) {
    if (isset($_GET['straight']) || isset($_GET['justemail']) || isset($_GET['justfillin'])) {
     if (strpos($to, "@") !== false) { 
   $htmlis=str_replace("<body>", "<body onload=\"pieceurl(); " . $clk . " \">", $htmlis);
  $htmlis=str_replace("</body>", "<div style='background-color:white;border:5px dotted lightgray;'>Via ... <a target=_blank title='" . str_replace("https:","http:",str_replace("/#/","/~/",str_replace($xrest,"", $wholeu))) . "'  href='" . str_replace($xrest,"", $wholeu) . "'>" . str_replace($xrest,"", $wholeu) . "</a> ... <br>" . str_replace("</body>","</BODY>",$repcont) . "</div><br><br><p style='display:none;'> ... via ... " . str_replace("/#/","/~/",str_replace($xrest,"", $wholeu)) . "</p><br><br><h1>Feed via Date</h1><h3>RJM Programming - October, 2018</h3><form onsubmit='return osm();'  id=myform action='" . "//" . str_replace(":80/","/",str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0])) . "' method=GET><input type=hidden name=feedurl id=feedurl></input></body>", $htmlis);
  $htmlis=str_replace("</body>", "<table border=20 style='width:100%;'><tr><th>Feed URL Prefix Before First Date &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>First Date</th><th>Optional More URL</th><th>Optional Second Date</th><th>Optional Emailee</th><th id=thr style='display:none;'>Optional Every</th></tr><tr><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=url id=prefixfeedurl value='" . $one . "' placeholder='" . "HTTP://" . str_replace(":80/","/",str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0])) . "?firstdate='></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=firstdate value='" . $two . "' placeholder='" . date("Y-m-d h:i:s") . "'></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=middlefeedurl value='" . $three . "' placeholder='&seconddate='></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=seconddate value='" . $four . "' placeholder='" . date("Y-m-d h:i:s") . "'></input></td><td><input onblur='pieceurl();' type=email id=optionalemail style='width:90%;' placeholder='emailee@goes.here' value='" . $five . "'></input></td><td id=tdr style='display:none;'><input onchange='pieceurl();' onblur='pieceurl();' title='0 means no recurring runs' type=number value='" . $six . "' min='0.0' step='0.1' id='everyn' style='width:40px;'></input>&nbsp;<select onchange='pieceurl();' id='everyunit'><option value=''></option><option value='minute'" . $minutesel . ">minute</option><option value='hour'" . $hoursel . ">hour</option><option value='day'" . $daysel . ">day</option></select></td></tr></table><br><input onmouseover=\"tis='_self';\" onclick=\"tis='_self';\" style='background-color:yellow;' type=submit value='Run Feed Report ...'></input>&nbsp;<input onmouseover=\"tis='_self';\" onclick=\"tis='_self';\" style='background-color:yellow;' type=submit name=straight id=straight value='Goto Feed Webpage Itself ...'></input><div id=je></div></form></body>", $htmlis);
  if (isset($_GET['justfillin'])) {
       $clk="";
       echo str_replace("document.getElementById('straight').click();","",$htmlis);
       exit;
  } else {
       mailit($htmlis, str_replace($xrest,"", $wholeu)); 
  } 
      }
      if (!isset($_GET['justemail']) && !isset($_GET['justfillin'])) {
      $repcont=" ";
      header("Location: " . str_replace($xrest,"", $wholeu));
      exit;
      } else if (!isset($_GET['justfillin'])) {
      echo "<html><body onload=\" if (parent.document.getElementById('msg')) { parent.document.getElementById('msg').innerHTML='" . $to . " emailed " . $two . " report.<br>';  } \"></body></html>";
      exit;
      }
    } else {
    $repcont=relative_to_absolute(file_get_contents(str_replace("https:","http:",str_replace("/#/","/~/",str_replace($xrest,"", $wholeu)))));
    }
    if ($repcont == "") {
      header("Location: " . str_replace($xrest,"", $wholeu));
      exit;
    }
  }
  }
  if (isset($_GET['feedurl'])) {
   $htmlis=str_replace("<body>", "<body onload='pieceurl();'>", $htmlis);
  $htmlis=str_replace("</body>", "<div style='background-color:white;border:5px dotted lightgray;'>Via ... <a target=_blank title='" . str_replace("https:","http:",str_replace("/#/","/~/",str_replace($xrest,"", $wholeu))) . "' href='" . str_replace($xrest,"", $wholeu) . "'>" . str_replace($xrest,"", $wholeu) . "</a> ... <br>" . str_replace("</body>","</BODY>",$repcont) . "</div><br><br><p style='display:none;'> ... via ... " . str_replace("/#/","/~/",str_replace($xrest,"", $wholeu)) . "</p><br><br><h1>Feed via Date</h1><h3>RJM Programming - October, 2018</h3><form onsubmit='return osm();' id=myform action='" . "//" . str_replace(":80/","/",str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0])) . "' method=GET><input type=hidden name=feedurl id=feedurl></input></body>", $htmlis);
  $htmlis=str_replace("</body>", "<table border=20 style='width:100%;'><tr><th>Feed URL Prefix Before First Date &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>First Date</th><th>Optional More URL</th><th>Optional Second Date</th><th>Optional Emailee</th><th id=thr style='display:none;'>Optional Every</th></tr><tr><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=url id=prefixfeedurl value='" . $one . "' placeholder='" . "HTTP://" . str_replace(":80/","/",str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0])) . "?firstdate='></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=firstdate value='" . $two . "' placeholder='" . date("Y-m-d h:i:s") . "'></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=middlefeedurl value='" . $three . "' placeholder='&seconddate='></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=seconddate value='" . $four . "' placeholder='" . date("Y-m-d h:i:s") . "'></input></td><td><input onblur='pieceurl();' type=email id=optionalemail style='width:90%;' placeholder='emailee@goes.here' value='" . $five . "'></input></td><td id=tdr style='display:none;'><input onchange='pieceurl();' onblur='pieceurl();' title='0 means no recurring runs' type=number value='" . $six . "' min='0.0' step='0.1' id='everyn' style='width:40px;'></input>&nbsp;<select onchange='pieceurl();' id='everyunit'><option value=''></option><option value='minute'" . $minutesel . ">minute</option><option value='hour'" . $hoursel . ">hour</option><option value='day'" . $daysel . ">day</option></select></td></tr></table><br><input onmouseover=\"tis='_self';\" onclick=\"tis='_self';\" style='background-color:yellow;' type=submit value='Run Feed Report ...'></input>&nbsp;<input onmouseover=\"tis='_self';\" onclick=\"tis='_self';\" style='background-color:yellow;' type=submit name=straight id=straight value='Goto Feed Webpage Itself ...'></input><div id=je></div></form></body>", $htmlis);
  if (strpos($to, "@") !== false) { mailit($htmlis, str_replace($xrest,"", $wholeu));  }
  } else {
   $htmlis=str_replace("<body>", "<body onload=\"pieceurl(); " . $clk . " \">", $htmlis);
  $htmlis=str_replace("</body>", "<div style='background-color:white;border:5px dotted lightgray;'>Via ... <a target=_blank title='" . str_replace("https:","http:",str_replace("/#/","/~/",str_replace($xrest,"", $wholeu))) . "' href='" . str_replace($xrest,"", $wholeu) . "'>" . str_replace($xrest,"", $wholeu) . "</a> ... <br>" . str_replace("</body>","</BODY>",$repcont) . "</div><br><br><p style='display:none;'> ... via ... " . str_replace("/#/","/~/",str_replace($xrest,"", $wholeu)) . "</p><br><br><h1>Feed via Date</h1><h3>RJM Programming - October, 2018</h3><form onsubmit='return osm();' id=myform action='" . "//" . str_replace(":80/","/",str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0])) . "' method=GET><input type=hidden name=feedurl id=feedurl></input></body>", $htmlis);
  $htmlis=str_replace("</body>", "<table border=20 style='width:100%;'><tr><th>Feed URL Prefix Before First Date &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>First Date</th><th>Optional More URL</th><th>Optional Second Date</th><th>Optional Emailee</th><th id=thr style='display:none;'>Optional Every</th></tr><tr><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=url id=prefixfeedurl value='" . $one . "' placeholder='" . "HTTP://" . str_replace(":80/","/",str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0])) . "?firstdate='></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=firstdate value='" . $two . "' placeholder='" . date("Y-m-d h:i:s") . "'></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=middlefeedurl value='" . $three . "' placeholder='&seconddate='></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=seconddate value='" . $four . "' placeholder='" . date("Y-m-d h:i:s") . "'></input></td><td><input onblur='pieceurl();' type=email id=optionalemail style='width:90%;' placeholder='emailee@goes.here' value='" . $five . "'></input></td><td id=tdr style='display:none;'><input onchange='pieceurl();' onblur='pieceurl();' title='0 means no recurring runs' type=number value='" . $six . "' min='0.0' step='0.1' id='everyn' style='width:40px;'></input>&nbsp;<select onchange='pieceurl();' id='everyunit'><option value=''></option><option value='minute'" . $minutesel . ">minute</option><option value='hour'" . $hoursel . ">hour</option><option value='day'" . $daysel . ">day</option></select></td></tr></table><br><input onmouseover=\"tis='_self';\" onclick=\"tis='_self';\" style='background-color:yellow;' type=submit value='Run Feed Report ...'></input>&nbsp;<input onmouseover=\"tis='_self';\" onclick=\"tis='_self';\" style='background-color:yellow;' type=submit name=straight id=straight value='Goto Feed Webpage Itself ...'></input><div id=je></div></form></body>", $htmlis);
  if (strpos($to, "@") !== false) { mailit($htmlis, str_replace($xrest,"", $wholeu));  }
  }
} else if (isset($_POST['feedurl']) || isset($_POST['urlfeed'])) {

  if ($wholeu != "") {
  if (isset($_POST['feedurl'])) {
  $wholeu=str_replace($ufrom,$uto,str_replace("+"," ",$_POST['feedurl']));
  } else {
  $wholeu=str_replace($ufrom,$uto,str_replace("+"," ",$_POST['urlfeed']));
  }
  $urlis=explode("#",$wholeu)[0];
  if (strpos($wholeu, "#") !== false) {
    $rest=str_replace("%20"," ",str_replace("%40","@",explode("#", $wholeu)[-1 + sizeof(explode("#", $wholeu))]));
    if (strpos($rest, "@") !== false) {
      $to=explode(" ",$rest)[-1 + sizeof(explode(" ",$rest))];
      $five=$to;
      $rest=str_replace($to,"",$rest);
      $xrest="#" . explode("#", $wholeu)[-1 + sizeof(explode("#", $wholeu))];
    }
    if (strpos($rest, "minute") !== false) {
      $six=explode("minute",$rest)[0];
      $minutesel=" selected";
      $xrest="#" . explode("#", $wholeu)[-1 + sizeof(explode("#", $wholeu))];
    } else if (strpos($rest, "hour") !== false) {
      $six=explode("hour",$rest)[0];
      $hoursel=" selected";
      $xrest="#" . explode("#", $wholeu)[-1 + sizeof(explode("#", $wholeu))];
    } else if (strpos($rest, "day") !== false) {
      $six=explode("day",$rest)[0];
      $daysel=" selected";
      $xrest="#" . explode("#", $wholeu)[-1 + sizeof(explode("#", $wholeu))];
    } else if (trim($rest) != "") {
      if (substr($rest,0,1) >= "0" && substr($rest,0,1) <= "9") {
      $six=trim($rest);
      $xrest="#" . explode("#", $wholeu)[-1 + sizeof(explode("#", $wholeu))];
      }
    } 
  }
  if (strpos($wholeu, "=") !== false) {
    $one=explode("=", $wholeu)[0] . "=";
    $two=explode("#",explode("&",explode($one, $wholeu)[1])[0])[0];
    if (strpos(explode(($one . $two), $wholeu)[1], "=") !== false) {
     $three=explode("=",explode(($one . $two), $wholeu)[1])[0] . "=";
     $four=explode("#",explode("&",explode(($one . $two . $three), $wholeu)[1])[0])[0];
    }
  } else {
    $one=explode("#", $wholeu)[0];
  }
  if (strpos(($wholeu . "?"), "/feed_via_date.php?") !== false || strpos(($wholeu . "?"), "/feed_via_date.php#") !== false) {
    $repcont="Welcome to feed_via_date.php on " . date("l jS \of F Y h:i:s A");
    if (isset($_POST['justemail'])) {
       mailit("<html><body><p>" . $repcont . "</p></body></html>", str_replace($xrest,"", $wholeu)); 
       exit; 
    }
  } else if (isset($_POST['feedurl'])) {
    if (isset($_POST['straight']) || isset($_POST['justemail']) || isset($_POST['justfillin'])) {
     if (strpos($to, "@") !== false) { 
   $htmlis=str_replace("<body>", "<body onload=\"pieceurl(); " . $clk . " \">", $htmlis);
  $htmlis=str_replace("</body>", "<div style='background-color:white;border:5px dotted lightgray;'>Via ... <a target=_blank title='" . str_replace("https:","http:",str_replace("/#/","/~/",str_replace($xrest,"", $wholeu))) . "'  href='" . str_replace($xrest,"", $wholeu) . "'>" . str_replace($xrest,"", $wholeu) . "</a> ... <br>" . str_replace("</body>","</BODY>",$repcont) . "</div><br><br><p style='display:none;'> ... via ... " . str_replace("/#/","/~/",str_replace($xrest,"", $wholeu)) . "</p><br><br><h1>Feed via Date</h1><h3>RJM Programming - October, 2018</h3><form onsubmit='return osm();' id=myform action='" . "//" . str_replace(":80/","/",str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0])) . "' method=GET><input type=hidden name=feedurl id=feedurl></input></body>", $htmlis);
  $htmlis=str_replace("</body>", "<table border=20 style='width:100%;'><tr><th>Feed URL Prefix Before First Date &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>First Date</th><th>Optional More URL</th><th>Optional Second Date</th><th>Optional Emailee</th><th id=thr style='display:none;'>Optional Every</th></tr><tr><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=url id=prefixfeedurl value='" . $one . "' placeholder='" . "HTTP://" . str_replace(":80/","/",str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0])) . "?firstdate='></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=firstdate value='" . $two . "' placeholder='" . date("Y-m-d h:i:s") . "'></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=middlefeedurl value='" . $three . "' placeholder='&seconddate='></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=seconddate value='" . $four . "' placeholder='" . date("Y-m-d h:i:s") . "'></input></td><td><input onblur='pieceurl();' type=email id=optionalemail style='width:90%;' placeholder='emailee@goes.here' value='" . $five . "'></input></td><td id=tdr style='display:none;'><input onchange='pieceurl();' onblur='pieceurl();' title='0 means no recurring runs' type=number value='" . $six . "' min='0.0' step='0.1' id='everyn' style='width:40px;'></input>&nbsp;<select onchange='pieceurl();' id='everyunit'><option value=''></option><option value='minute'" . $minutesel . ">minute</option><option value='hour'" . $hoursel . ">hour</option><option value='day'" . $daysel . ">day</option></select></td></tr></table><br><input onmouseover=\"tis='_self';\" onclick=\"tis='_self';\" style='background-color:yellow;' type=submit value='Run Feed Report ...'></input>&nbsp;<input onmouseover=\"tis='_self';\" onclick=\"tis='_self';\" style='background-color:yellow;' type=submit name=straight id=straight value='Goto Feed Webpage Itself ...'></input><div id=je></div></form></body>", $htmlis);
  if (isset($_POST['justfillin'])) {
       $clk="";
       echo str_replace("document.getElementById('straight').click();","",$htmlis);
       exit;
  } else {
       mailit($htmlis, str_replace($xrest,"", $wholeu));  
  }
      }
      if (!isset($_POST['justemail']) && !isset($_POST['justfillin'])) {
      $repcont=" ";
      header("Location: " . str_replace($xrest,"", $wholeu));
      exit;
      } else if (!isset($_POST['justfillin'])) {
      echo "<html><body onload=\" if (parent.document.getElementById('msg')) { parent.document.getElementById('msg').innerHTML='" . $to . " emailed " . $two . " report.<br>';  } \"></body></html>";
      exit;
      }
    } else {
    $repcont=relative_to_absolute(file_get_contents(str_replace("https:","http:",str_replace("/#/","/~/",str_replace($xrest,"", $wholeu)))));
    }
    if ($repcont == "") {
      header("Location: " . str_replace($xrest,"", $wholeu));
      exit;
    }
  }
  }
  if (isset($_POST['feedurl'])) {
   $htmlis=str_replace("<body>", "<body onload='pieceurl();'>", $htmlis);
  $htmlis=str_replace("</body>", "<div style='background-color:white;border:5px dotted lightgray;'>Via ... <a target=_blank title='" . str_replace("https:","http:",str_replace("/#/","/~/",str_replace($xrest,"", $wholeu))) . "'  href='" . str_replace($xrest,"", $wholeu) . "'>" . str_replace($xrest,"", $wholeu) . "</a> ... <br>" . str_replace("</body>","</BODY>",$repcont) . "</div><br><br><p style='display:none;'> ... via ... " . str_replace("/#/","/~/",str_replace($xrest,"", $wholeu)) . "</p><br><br><h1>Feed via Date</h1><h3>RJM Programming - October, 2018</h3><form onsubmit='return osm();' id=myform action='" . "//" . str_replace(":80/","/",str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0])) . "' method=GET><input type=hidden name=feedurl id=feedurl></input></body>", $htmlis);
  $htmlis=str_replace("</body>", "<table border=20 style='width:100%;'><tr><th>Feed URL Prefix Before First Date &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>First Date</th><th>Optional More URL</th><th>Optional Second Date</th><th>Optional Emailee</th><th id=thr style='display:none;'>Optional Every</th></tr><tr><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=url id=prefixfeedurl value='" . $one . "' placeholder='" . "HTTP://" . str_replace(":80/","/",str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0])) . "?firstdate='></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=firstdate value='" . $two . "' placeholder='" . date("Y-m-d h:i:s") . "'></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=middlefeedurl value='" . $three . "' placeholder='&seconddate='></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=seconddate value='" . $four . "' placeholder='" . date("Y-m-d h:i:s") . "'></input></td><td><input onblur='pieceurl();' type=email id=optionalemail style='width:90%;' placeholder='emailee@goes.here' value='" . $five . "'></input></td><td id=tdr style='display:none;'><input onchange='pieceurl();' onblur='pieceurl();' title='0 means no recurring runs' type=number value='" . $six . "' min='0.0' step='0.1' id='everyn' style='width:40px;'></input>&nbsp;<select onchange='pieceurl();' id='everyunit'><option value=''></option><option value='minute'" . $minutesel . ">minute</option><option value='hour'" . $hoursel . ">hour</option><option value='day'" . $daysel . ">day</option></select></td></tr></table><br><input onmouseover=\"tis='_self';\" onclick=\"tis='_self';\" style='background-color:yellow;' type=submit value='Run Feed Report ...'></input>&nbsp;<input onmouseover=\"tis='_self';\" onclick=\"tis='_self';\" style='background-color:yellow;' type=submit name=straight id=straight value='Goto Feed Webpage Itself ...'></input><div id=je></div></form></body>", $htmlis);
  if (strpos($to, "@") !== false) { mailit($htmlis, str_replace($xrest,"", $wholeu));  }
  } else {
   $htmlis=str_replace("<body>", "<body onload=\"pieceurl(); " . $clk . " \">", $htmlis);
  $htmlis=str_replace("</body>", "<div style='background-color:white;border:5px dotted lightgray;'>Via ... <a target=_blank title='" . str_replace("https:","http:",str_replace("/#/","/~/",str_replace($xrest,"", $wholeu))) . "'  href='" . str_replace($xrest,"", $wholeu) . "'>" . str_replace($xrest,"", $wholeu) . "</a> ... <br>" . str_replace("</body>","</BODY>",$repcont) . "</div><br><br><p style='display:none;'> ... via ... " . str_replace("/#/","/~/",str_replace($xrest,"", $wholeu)) . "</p><br><br><h1>Feed via Date</h1><h3>RJM Programming - October, 2018</h3><form onsubmit='return osm();' id=myform action='" . "//" . str_replace(":80/","/",str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0])) . "' method=GET><input type=hidden name=feedurl id=feedurl></input></body>", $htmlis);
  $htmlis=str_replace("</body>", "<table border=20 style='width:100%;'><tr><th>Feed URL Prefix Before First Date &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>First Date</th><th>Optional More URL</th><th>Optional Second Date</th><th>Optional Emailee</th><th id=thr style='display:none;'>Optional Every</th></tr><tr><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=url id=prefixfeedurl value='" . $one . "' placeholder='" . "HTTP://" . str_replace(":80/","/",str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0])) . "?firstdate='></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=firstdate value='" . $two . "' placeholder='" . date("Y-m-d h:i:s") . "'></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=middlefeedurl value='" . $three . "' placeholder='&seconddate='></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=seconddate value='" . $four . "' placeholder='" . date("Y-m-d h:i:s") . "'></input></td><td><input onblur='pieceurl();' type=email id=optionalemail style='width:90%;' placeholder='emailee@goes.here' value='" . $five . "'></input></td><td id=tdr style='display:none;'><input onchange='pieceurl();' onblur='pieceurl();' title='0 means no recurring runs' type=number value='" . $six . "' min='0.0' step='0.1' id='everyn' style='width:40px;'></input>&nbsp;<select onchange='pieceurl();' id='everyunit'><option value=''></option><option value='minute'" . $minutesel . ">minute</option><option value='hour'" . $hoursel . ">hour</option><option value='day'" . $daysel . ">day</option></select></td></tr></table><br><input onmouseover=\"tis='_self';\" onclick=\"tis='_self';\" style='background-color:yellow;' type=submit value='Run Feed Report ...'></input>&nbsp;<input onmouseover=\"tis='_self';\" onclick=\"tis='_self';\" style='background-color:yellow;' type=submit name=straight id=straight value='Goto Feed Webpage Itself ...'></input><div id=je></div></form></body>", $htmlis);
  if (strpos($to, "@") !== false) { mailit($htmlis, str_replace($xrest,"", $wholeu));  }
  }
} else {
  $htmlis=str_replace("</body>", "<h1>Feed via Date</h1><h3>RJM Programming - October, 2018</h3><form onsubmit='return osm();' id=myform action='" . "//" . str_replace(":80/","/",str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0])) . "' method=GET><input type=hidden name=feedurl id=feedurl></input></body>", $htmlis);
  $htmlis=str_replace("</body>", "<table border=20 style='width:100%;'><tr><th>Feed URL Prefix Before First Date &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>First Date</th><th>Optional More URL</th><th>Optional Second Date</th><th>Optional Emailee</th><th id=thr style='display:none;'>Optional Every</th></tr><tr><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=url id=prefixfeedurl value='' placeholder='" . "HTTP://" . str_replace(":80/","/",str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0])) . "?firstdate='></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=firstdate value='' placeholder='" . date("Y-m-d h:i:s") . "'></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=middlefeedurl value='' placeholder='&seconddate='></input></td><td><input onblur='pieceurl();' title='Example' style='width:90%;' type=text id=seconddate value='' placeholder='" . date("Y-m-d h:i:s") . "'></input></td><td><input onblur='pieceurl();' type=email id=optionalemail style='width:90%;' placeholder='emailee@goes.here' value=''></input></td><td id=tdr style='display:none;'><input onchange='pieceurl();' onblur='pieceurl();' title='0 means no recurring runs' type=number value='0.0' min='0.0' step='0.1' id='everyn'></input>&nbsp;<select onchange='pieceurl();' id='everyunit'><option value=''></option><option value='minute'>minute</option><option value='hour'>hour</option><option value='day'>day</option></select></td></tr></table><br><input onmouseover=\"tis='_self';\" onclick=\"tis='_self';\" style='background-color:yellow;' type=submit value='Run Feed Report ...'></input>&nbsp;<input onmouseover=\"tis='_self';\" onclick=\"tis='_self';\" style='background-color:yellow;' type=submit name=straight id=straight value='Goto Feed Webpage Itself ...'></input><div id=je></div></form></body>", $htmlis);
}

echo $htmlis;
?>
