<?php
 // Crontab Curl Update of rjmprogramming.com.au Landing Page Tutorial Dropdown - RJM Programming - October, 2014
 // RJM Programming
 // Amended on 12/2/2016 to allow for indexmobile.html be updated via crontab/curl ?mobile=mobile $_GET[] PHP parameter usage
 // Amended on 14/6/2016 to populate http://www.rjmprogramming.com.au/slideshow.html

 set_time_limit(0);
 
 $isuffix = "";
 if (isset($_GET['mobile'])) $isuffix = $_GET['mobile'];

 $prevdod = "";
 $prevint = "";
 $prevret = "";
 $prevxid = "";
 $retvalp = "";
  
 $ulist = ";";
 
 $and = "";
 $ptg = "post_title, guid,";
 $changethis = "youwillnevsfindthis";
 $changeto = "youwillnevsfindthis";
 $index = "index";
 if (isset($_GET['index'])) {
    $index = $_GET['index'];
 } else if (isset($_POST['index'])) { 
    $index = $_POST['index'];
 } 
 if ($index != "index") {
   if ($index == "slideshow") {
     //$and = " and post_content like '%/" . '"' . "><img style=" . '"' . "float%' and (instr(post_content, '" . '"' . "><img style=') - instr(post_content, 'http')) < 100 ";
     $and = " and post_content like '%" . '"' . "><img style=" . '"' . "%' and (instr(post_content, '" . '"' . "><img style=') - instr(post_content, 'http')) < 100 ";
     //$ptg = "concat(post_title, ' (Slideshow or Web Application or Game or Image)'), substring(post_content, instr(post_content, 'http'), (instr(post_content, '" . '"' . "><img style=') - instr(post_content, 'http'))),";
     $ptg = "concat(post_title, ' (Slideshow or Web Application or Game or Image)'), CASE substring(post_content, instr(post_content, 'http'), (instr(post_content, '" . '"' . "><img style=') - instr(post_content, 'http'))) WHEN '' THEN guid ELSE substring(post_content, instr(post_content, 'http'), (instr(post_content, '" . '"' . "><img style=') - instr(post_content, 'http'))) END,";
     $changethis = "Tutorials (";
     $changeto = "Slideshows and Web Applications (";
   } else {
     exit;
   }
 } 
 
 function uq($inu) {
   global $ulist;
   $suf = "a";
   if (strpos($ulist, ";" . $inu . ";") !== false) {
     if (strpos($ulist, ";" . $inu . "a;") !== false) $suf = "b";
     if (strpos($ulist, ";" . $inu . "b;") !== false) $suf = "c";
     if (strpos($ulist, ";" . $inu . "c;") !== false) $suf = "d";
     if (strpos($ulist, ";" . $inu . "d;") !== false) $suf = "e";
     if (strpos($ulist, ";" . $inu . "e;") !== false) $suf = "f";
     if (strpos($ulist, ";" . $inu . "f;") !== false) $suf = "g";
     if (strpos($ulist, ";" . $inu . "g;") !== false) $suf = "h";
     if (strpos($ulist, ";" . $inu . "h;") !== false) $suf = "i";
     if (strpos($ulist, ";" . $inu . "i;") !== false) $suf = "j";
     if (strpos($ulist, ";" . $inu . "j;") !== false) $suf = "k";
     if (strpos($ulist, ";" . $inu . "k;") !== false) $suf = "l";
     if (strpos($ulist, ";" . $inu . "l;") !== false) $suf = "m";
     if (strpos($ulist, ";" . $inu . "m;") !== false) $suf = "n";
     if (strpos($ulist, ";" . $inu . "n;") !== false) $suf = "o";
     if (strpos($ulist, ";" . $inu . "o;") !== false) $suf = "p";
     if (strpos($ulist, ";" . $inu . "p;") !== false) $suf = "q";
     if (strpos($ulist, ";" . $inu . "q;") !== false) $suf = "r";
     if (strpos($ulist, ";" . $inu . "r;") !== false) $suf = "s";
     if (strpos($ulist, ";" . $inu . "s;") !== false) $suf = "t";

     $ulist .= ($inu . $suf . ";");
     return $inu . $suf;
   } else {
     $ulist .= ($inu . ";");
   }
   return $inu;
 }

 function guidedextras($ing, $intitle, $xid, $pexcerpt) {
   global $prevdod, $prevint, $prevret, $retvalp, $prevxid, $and, $ptg, $index;
   $thisint = explode(" ", str_replace("_", " ", str_replace("  ", "++", str_replace('"', '%22', str_replace("'", "%27", $intitle)))));
   $ipfile = str_replace("tutorial_options.php", $xid . "_" . $_SERVER['REMOTE_ADDR'] . ".npg", __FILE__);
   if (!file_exists($ipfile)) $ipfile = str_replace("tutorial_options.php", $xid . "_admin.npg", __FILE__);
   if (file_exists($ipfile)) {
     $psq = str_replace("\n", "", file_get_contents($ipfile));
     if (strpos($psq, "title=") !== false) {
       if ($pexcerpt == "" && $prevret != "") {
         $prevret = "";
       }
       if ($index == "slideshow") return $ing;
       return $ing . $psq;
     }   
   } else if (strpos(("?" . $pexcerpt), "?&") !== false && strpos(("?" . $pexcerpt), "&title") === false) {
     if ($pexcerpt == "" && $prevret != "") {
         $prevret = "";
     }
     return $ing . $pexcerpt . "&title=" . str_replace("#", "%23", str_replace(" ", "_", str_replace("  ", "++", str_replace('"', '%22', str_replace("'", "%27", $intitle)))));
   } else if (strpos(("?" . $pexcerpt), "?&") !== false) {
     if ($pexcerpt == "" && $prevret != "") {
         $prevret = "";
     }
     if ($index == "slideshow") return $ing;
     return $ing . $pexcerpt;
   } else if ($pexcerpt != "") {
     if ($thisint[0] != $prevint) {
       $prevret = "";
     }
     if ($prevret == "") {
       $retvalp = str_replace("&", "&amp;", $ing . "&pp=&pn=@$@" . "&title=" . str_replace("#", "%23", str_replace(" ", "_",str_replace("  ", "++", str_replace('"', '%22', str_replace("'", "%27", $intitle))))));
       $prevret = $retvalp; 
     } else {
       $retvalp = str_replace("&", "&amp;", $ing . "&pp=" . $prevxid . "&pn=@$@" . $xid . "&title=" . str_replace("#", "%23", str_replace(" ", "_", str_replace("  ", "++", str_replace('"', '%22', str_replace("'", "%27", $intitle))))));
       $prevret = $retvalp; 
     }
     $prevint = $thisint[0];
     return "$@$";
   }
   if ($pexcerpt == "" && $prevret != "") {
         $prevret = "";
   }
   if ($index == "slideshow") return $ing;
   return $ing . "&pp=&pn=&title=" . str_replace("#", "%23", str_replace(" ", "_", str_replace("  ", "++", str_replace('"', '%22', str_replace("'", "%27", $intitle)))));
 }

 $retval = "<option selected='selected' value=' '>Tutorials (show blog, toggle sort order) ...</option>";
 $retvalalt = "<option selected='selected' value=' '>Tutorials (show blog, toggle sort order) ...</option>";
 /*** mysql hostname ***/
 $hostname = 'localhost';

 /*** mysql username ***/
 $username = 'username';

 /*** mysql ***/
 $password = 'password';

 $dbname = 'rjmprogr_wordpress';
 if (isset($_GET['dbname'])) $dbname = $_GET['dbname'];
 $tname = 'wp_posts';

 $link = mysql_connect($hostname, $username, $password);
 if (!$link) {
    die('Could not connect: ' . mysql_error());
 }
 mysql_select_db($dbname);
 // <option id='MyNew-20140327' onclick='windowopen("http://www.rjmprogramming.com.au/wordpress/?p=6976","_blank"); ' value='http://www.rjmprogramming.com.au/wordpress/?p=6976'>Linux Monitor Processes Primer Tutorial (20140327)</option>
 if ($index == "slideshow") {
 $res = mysql_query("SELECT  ID, post_date, " . $ptg . " DATE_FORMAT(post_date,'%Y%m%d') As pdate, IfNull(post_excerpt, '') As post_excerpt, 'zzz' as bpost_title FROM " . $tname . " WHERE post_status='publish' " . $and . " and post_title not like '%Show Tags of this Webpage%' and post_title not like '%Show Most Popular Words%' and (substr(IfNull(post_excerpt, ''),1,1) < '0' or substr(IfNull(post_excerpt, ''),1,1) > '9') ORDER BY bpost_title, post_date DESC");
 } else {
 $res = mysql_query("SELECT  ID, post_date, " . $ptg . " DATE_FORMAT(post_date,'%Y%m%d') As pdate, IfNull(post_excerpt, '') As post_excerpt, replace(post_title, ' ', LPAD(post_excerpt,13,'*')) as bpost_title FROM " . $tname . " WHERE post_status='publish' " . $and . " and post_title not like '%Show Tags of this Webpage%' and post_title not like '%Show Most Popular Words%' and substr(IfNull(post_excerpt, ''),1,1) >= '0' and substr(IfNull(post_excerpt, ''),1,1) <= '9' UNION SELECT  ID, post_date, " . $ptg . " DATE_FORMAT(post_date,'%Y%m%d') As pdate, IfNull(post_excerpt, '') As post_excerpt, 'zzz' as bpost_title FROM " . $tname . " WHERE post_status='publish' " . $and . " and post_title not like '%Show Tags of this Webpage%' and post_title not like '%Show Most Popular Words%' and (substr(IfNull(post_excerpt, ''),1,1) < '0' or substr(IfNull(post_excerpt, ''),1,1) > '9') ORDER BY bpost_title, post_date DESC");
 }
 if ($res == 0) {
  echo("<b>Error " . mysql_errno() . ": " . mysql_error() . "</b>");
 } else if (mysql_num_rows($res) == 0) {
  echo("<b>Query executed successfully</b>");
 } else {
  $j = 1;
  $bval = '  ';
  $lastr0 = "";
  $lastr1 = "";
  $ulist = ";";
  while (($r_array = mysql_fetch_row($res))) {
    $lastr0 = $r_array[0];
    $lastr1 = $r_array[2];
    if ($retvalp != "") {
      $thisintr = explode(" ", str_replace("_", " ", str_replace("  ", "++", $r_array[2])));
      if ($thisintr[0] == $prevint) $retvalp = str_replace("@$@", $r_array[0], $retvalp);
      $retval = str_replace("$@$", $retvalp, $retval);
    }
    $teis = explode("s Wally", $r_array[2]);
    if (sizeof($teis) == 2) {
    $preteis = explode("Where", $teis[0]);
    $retval .= str_replace("&", "&amp;", "\n<option id='MyNew-" . uq($r_array[4]) . "' onclick='windowopen(\"" . guidedextras($r_array[3],$preteis[0] . "Where%27s Wally" . $teis[1] . " (" . $r_array[4],$r_array[0],$r_array[5]) . "\",\"_blank\"); ' value='" . guidedextras($r_array[3],$preteis[0] . "Where%27s Wally" . $teis[1] . " (" . $r_array[4],$r_array[0],$r_array[5]) . "'>" . $preteis[0] . "Where%27s Wally" . $teis[1] . " (" . $r_array[4] . ")</option>");
    } else {
    $retval .= str_replace("&", "&amp;", "\n<option id='MyNew-" . uq($r_array[4]) . "' onclick='windowopen(\"" . guidedextras($r_array[3],$r_array[2],$r_array[0],$r_array[5]) . "\",\"_blank\"); ' value='" . guidedextras($r_array[3],$r_array[2],$r_array[0],$r_array[5]) . "'>" . $r_array[2] . " (" . $r_array[4] . ")</option>");
    }
    if (($j % 19) == 0) {
      $retval .= "\n<option value='" . $bval . "'>Tutorials (toggle sort order) ...</option>";
      $bval .= ' ';
    }
    $j++;
    $prevxid = $r_array[0];
  }
 }
 if ($retvalp != "") {
      $thisintr = explode(" ", str_replace("_", " ", str_replace("  ", "++", $lastr1)));
      if ($thisintr[0] == $prevint) $retvalp = str_replace("@$@", $lastr0, $retvalp);
      $retval = str_replace("$@$", $retvalp, $retval);
 }
 $retval = str_replace("$@$", "", $retval);
 $retval = str_replace("@$@", "", $retval);
 $res = mysql_query("SELECT  ID, post_date, " . $ptg . " DATE_FORMAT(post_date,'%Y%m%d') As pdate, IfNull(post_excerpt, '') As post_excerpt FROM " . $tname . " WHERE post_status='publish' " . $and . " and post_title not like '%Show Tags of this Webpage%' and post_title not like '%Show Most Popular Words%' ORDER BY post_title");
 if ($res == 0) {
  echo("<b>Error " . mysql_errno() . ": " . mysql_error() . "</b>");
 } else if (mysql_num_rows($res) == 0) {
  echo("<b>Query executed successfully</b>");
 } else {
  $j = 1;
  $bval = '  ';
  $ulist = ';';
  while (($r_array = mysql_fetch_row($res))) {
  
    $teis = explode("s Wally", $r_array[2]);
    if (sizeof($teis) == 2) {
    $preteis = explode("Where", $teis[0]);
    $retvalalt .= str_replace("&", "&amp;", "<option id='MyNew-" . uq($r_array[4]) . "' onclick='windowopen(\"" . guidedextras($r_array[3],$preteis[0] . "Where%27s Wally" . $teis[1],$r_array[0],$r_array[5]) . "\",\"_blank\"); ' value='" . guidedextras($r_array[3],$preteis[0] . "Where%27s Wally" . $teis[1],$r_array[0],$r_array[5]) . "'>" . $preteis[0] . "Where%27s Wally" . $teis[1] . " (" . $r_array[4] . ")</option>");
    } else {
    $retvalalt .= str_replace("&", "&amp;", "<option id='MyNew-" . uq($r_array[4]) . "' onclick='windowopen(\"" . guidedextras($r_array[3],$r_array[2],$r_array[0],$r_array[5]) . "\",\"_blank\"); ' value='" . guidedextras($r_array[3],$r_array[2],$r_array[0],$r_array[5]) . "'>" . $r_array[2] . " (" . $r_array[4] . ")</option>");
    }
  
  
    if (($j % 19) == 0) {
      $retvalalt .= "<option value='" . $bval . "'>Tutorials (toggle sort order) ...</option>";
      $bval .= ' ';
    }
    $j++;
  }
 }
 mysql_close($link);
 $newhtml = $retval;
 if (file_exists(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . "Welcome" . str_replace("index","",$index) . ".html")) {
   if (!file_exists(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . "Welcome" . str_replace("index","",$index) . ".html_original")) {
     copy(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . "Welcome" . str_replace("index","",$index) . ".html",str_replace("/PHP", "/", dirname(__FILE__)) . "/" . "Welcome" . str_replace("index","",$index) . ".html_original"); 
   }
   $whtml = str_replace("<select", "@!@",  str_replace("</select", "@!@", file_get_contents(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . "Welcome" . str_replace("index","",$index) . ".html")));
   $earr = explode("@!@", $whtml);
   //file_put_contents(dirname(__FILE__) . "/huh.hh", count($earr));
   if (count($earr) == 5) {
    $newearr4 = explode("@!@", str_replace("<script", "@!@",  str_replace("</script>", "@!@", $earr[4])));
    $selarr = explode(">", $earr[3]);
    $newhtml = $earr[0] . "<select" . $earr[1] . "</select" . $earr[2] . "<select" . $selarr[0] . ">" . $retval . "</select" . $newearr4[0];
 $ethis = "<script type='text/javascript'>\n function toggle() {  var dq = String.fromCharCode(34); \n";
 $ethis .= ' var xnewstr="", os=document.getElementById("tuts"); ' . "\n";
 $ethis .= ' if (wasstr == "") { var isdq=os.innerHTML.split(dq);  wasstr=isdq[0];  for (var iii=1; iii < isdq.length; iii++) { wasstr = wasstr + dq + isdq[iii]; }   } ' . "\n";
 $exp = explode('"', $retvalalt);
 $ethis .= " var newstr='" . str_replace('onclick="windowopen(', "onclick=' + \"'\" + 'windowopen(", str_replace("'", '"', $exp[0])) . "'; " . "\n";
 for ($ii=1; $ii<sizeof($exp); $ii++) { 
   $ethis .= "\n" . " newstr = newstr + dq + \"" . $exp[$ii] . "\";  " . "\n"; 
 } 
 $ethis .= " if (tval != 0) { tval = 0; os.innerHTML = newstr; } else { tval = 1; os.innerHTML = wasstr; } " . "\n";
 $ethis .= " } \n";
 $ethis .= "</script>\n";
 
 if (str_replace("if (val.value.length != 0) {", "", $newhtml) != $newhtml) {
   $newhtml = str_replace("if (val.value.length != 0) {","if ( val.value.length == 1 && bzgoes == 0 ) { bzgoes = 1; window.open(\"http://www.rjmprogramming.com.au/wordpress\",\"Robert Metcalfe Blog\",\"height=429, left=278, top=360, width=400\"); } else if (val.value.trim() == '') { toggle(); } else if ( val.value.length != 0 ) {", $newhtml);
 } 
 if (str_replace("var wasstr = '';", "", $newhtml) == $newhtml) {
   $newhtml = str_replace("function windowopen(myurl,mytarget) {", " var tval = 1;\n var wasstr = '';\n var bval='  ';\n var bzgoes=0; \n function windowopen(myurl,mytarget) {", $newhtml);
 } 
 if (str_replace("</body>", "", $newhtml) == $newhtml) {
   $newhtml .= $ethis . "</body></html>";
 } else {
   $newhtml = str_replace("</body>", $ethis . "</body>", $newhtml);
 }
    if (strpos($newhtml, "HTML/Javascript") === false) exit;
    //if ($index == "index") {
    //file_put_contents(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . "Welcome" . str_replace("index","",$index) . ".htm", $newhtml);
    //file_put_contents(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . "Welcome" . str_replace("index","",$index) . ".html", $newhtml);
    file_put_contents(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . "Welcome" . str_replace("index","",$index) . ".htm", str_replace("<92>", "'", str_replace($changethis,$changeto,$newhtml)));
    file_put_contents(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . "Welcome" . str_replace("index","",$index) . ".html", str_replace("<92>", "'", str_replace($changethis,$changeto,$newhtml)));
    chown(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . "Welcome" . str_replace("index","",$index) . ".html", "rjmprogr");
    //}
     if (file_exists(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . $index . $isuffix . ".html")) {
   if (!file_exists(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . $index . $isuffix . ".html_original")) {
     copy(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . $index . $isuffix . ".html",str_replace("/PHP", "/", dirname(__FILE__)) . "/index" . $isuffix . ".html_original"); 
   }
   $whtml = str_replace("<select", "@!@",  str_replace("</select", "@!@", file_get_contents(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . $index . $isuffix . ".html")));
   $earr = explode("@!@", $whtml);
   if (count($earr) == 5) {
    $newearr4 = explode("@!@", str_replace("<script", "@!@",  str_replace("</script>", "@!@", $earr[4])));
    $selarr = explode(">", $earr[3]);
    $newhtml = $earr[0] . "<select" . $earr[1] . "</select" . $earr[2] . "<select" . $selarr[0] . ">" . $retval . "</select" . $newearr4[0];
 $ethis = "<script type='text/javascript'>\n function toggle() {  var dq = String.fromCharCode(34); \n";
 $ethis .= ' var xnewstr="", os=document.getElementById("tuts"); ' . "\n";
 $ethis .= ' if (wasstr == "") {  var isdq=os.innerHTML.split(dq);  wasstr=isdq[0];  for (var iii=1; iii < isdq.length; iii++) { wasstr = wasstr + dq + isdq[iii]; }   } ' . "\n";
 $exp = explode('"', $retvalalt);
 $ethis .= " var newstr='" . str_replace('onclick="windowopen(', "onclick=' + \"'\" + 'windowopen(", str_replace("'", '"', $exp[0])) . "'; " . "\n";
 for ($ii=1; $ii<sizeof($exp); $ii++) { 
   $ethis .= "\n" . " newstr = newstr + dq + \"" . $exp[$ii] . "\";  " . "\n"; 
 } 
 $ethis .= " if (tval != 0) { tval = 0; os.innerHTML = newstr; } else { tval = 1; os.innerHTML = wasstr; } " . "\n";
 $ethis .= " } \n";
 $ethis .= "</script>\n";
 
 if (str_replace("if (val.value.length != 0) {", "", $newhtml) != $newhtml) {
   $newhtml = str_replace("if (val.value.length != 0) {","if ( val.value.length == 1 && bzgoes == 0 ) { bzgoes = 1; window.open(\"http://www.rjmprogramming.com.au/wordpress\",\"Robert Metcalfe Blog\",\"height=429, left=278, top=360, width=400\"); } else if (val.value.trim() == '') { toggle(); } else if ( val.value.length != 0 ) {", $newhtml);
 } 
 if (str_replace("var wasstr = '';", "", $newhtml) == $newhtml) {
   $newhtml = str_replace("function windowopen(myurl,mytarget) {", " var tval = 1;\n var wasstr = '';\n var bval='  '; \n\n var bzgoes=0; \n function windowopen(myurl,mytarget) {", $newhtml);
 } 
 if (str_replace("</body>", "", $newhtml) == $newhtml) {
   $newhtml .= $ethis . "</body></html>";
 } else {
   $newhtml = str_replace("</body>", $ethis . "</body>", $newhtml);
 }
    if (strpos($newhtml, "HTML/Javascript") === false) exit;
    //file_put_contents(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . $index . $isuffix . ".htm", str_replace($changethis,$changeto,$newhtml));
    //file_put_contents(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . $index . $isuffix . ".html", str_replace($changethis,$changeto,$newhtml));
    //file_put_contents(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . $index . $isuffix . ".htm", str_replace("<92>", "'", str_replace($changethis,$changeto,$newhtml)));
    file_put_contents(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . $index . $isuffix . ".html", str_replace("<92>", "'", str_replace($changethis,$changeto,$newhtml)));
    chown(str_replace("/PHP", "/", dirname(__FILE__)) . "/" . $index . $isuffix . ".html", "rjmprogr");
   } else {
    $newhtml = $retval;
   }
   } 
   } else {
    $newhtml = $retval;
   }
 } 
 $ethis = "<script type='text/javascript'>\n function toggle() { var dq = String.fromCharCode(34);  \n";
 $ethis .= ' var xnewstr="", os=document.getElementById("tuts"); ' . "\n";
 $ethis .= ' if (wasstr == "") {  var isdq=os.innerHTML.split(dq);  wasstr=isdq[0];  for (var iii=1; iii < isdq.length; iii++) { wasstr = wasstr + dq + isdq[iii]; }   } ' . "\n";
 $exp = explode('"', $retvalalt);
 $ethis .= " var newstr='" . str_replace('onclick="windowopen(', "onclick=' + \"'\" + 'windowopen(", str_replace("'", '"', $exp[0])) . "'; " . "\n";
 for ($ii=1; $ii<sizeof($exp); $ii++) { 
   $ethis .= "\n" . " newstr = newstr + dq + \"" . $exp[$ii] . "\"; " . "\n"; 
 } 
 $ethis .= " if (tval != 0) { tval = 0; os.innerHTML = newstr; } else { tval = 1; os.innerHTML = wasstr; } " . "\n";
 $ethis .= " }  \n";
 $ethis .= "</script>\n";
 
 if (str_replace("if (val.value.length != 0) {", "", $newhtml) != $newhtml) {
   $newhtml = str_replace("if (val.value.length != 0) {","if ( val.value.length == 1 && bzgoes == 0 ) { bzgoes = 1; window.open(\"http://www.rjmprogramming.com.au/wordpress\",\"Robert Metcalfe Blog\",\"height=429, left=278, top=360, width=400\"); } else if (val.value.trim() == '') { toggle(); } else if ( val.value.length != 0 ) {", $newhtml);
 } 
 if (str_replace("var wasstr = '';", "", $newhtml) == $newhtml) {
   $newhtml = str_replace("function windowopen(myurl,mytarget) {", " var tval = 1;\n var wasstr = '';\n var bval='  '; \n\n var bzgoes=0; \n function windowopen(myurl,mytarget) {", $newhtml);
 } 
 if (str_replace("</body>", "", $newhtml) == $newhtml) {
   $newhtml .= $ethis . "</body></html>";
 } else {
   $newhtml = str_replace("</body>", $ethis . "</body>", $newhtml);
 }
 file_put_contents(str_replace("/PHP", "/", dirname(__FILE__)) . "/tutorial_options" . str_replace("index","",$index) . ".html", str_replace("<92>", "'", str_replace($changethis,$changeto,$newhtml)));
 if (file_exists("/etc/init.d/todaylist.is")) {
   date_default_timezone_set('Australia/Perth');
   //mail("rmetcalfe@rjmprogramming.com.au", "Today's list " . date('l jS \of F Y h:i:s A'), file_get_contents("/etc/init.d/todaylist.is"));
   exec("rm -f /etc/init.d/todaylist.is");
 }
 echo $retval;
?>

