<?php
// inhouse_blog_game.php
// July, 2023
// RJM Programming
// Using experimental_drag_and_drop.htm for Inhouse Blog matches of tutorial pictures to content
 error_reporting( E_ERROR | E_USER_ERROR ); 
 
 $ourrand='' . rand(5678,7890023);
 $scorebit='';
 $fgapp="";
 $fhapp="";
 $topapp="";
 $prescore="";
 $recallit='./inhouse_blog_game.php';

 if (isset($_GET['filterstuff'])) {
     if (strlen(trim(str_replace('+',' ',urldecode($_GET['filterstuff'])))) > 0) {
     $fgapp=$_GET['filterstuff'];
     }
 }
if (isset($_POST['filterstuff'])) {
     if (strlen(trim(str_replace('+',' ',urldecode($_POST['filterstuff'])))) > 0) {
     $fgapp=$_POST['filterstuff'];
     }
 }


 if (isset($_GET['score']) && isset($_GET['secs'])) {
   $scorebit="Score " . explode('.',$_GET['score'])[0] . '/' . $_GET['secs'];
   $recallit.='?score=' . explode('.',$_GET['score'])[0] . '/' . $_GET['secs'];
   if (isset($_GET['topic'])) {
     if (strlen(trim(str_replace('+',' ',urldecode($_GET['topic'])))) > 0) {
     $prescore='topic=' . $_GET['topic'] . '&';
     $recallit='./inhouse_blog_game.php?topic=' . $_GET['topic'] . '&score=' . explode('.',$_GET['score'])[0] . '/' . $_GET['secs'];
     $fhapp=$_GET['topic'];
     $topapp=' ' . trim(str_replace('+',' ',urldecode($_GET['topic'])));
     }
   }
 } else if (isset($_POST['score']) && isset($_POST['secs'])) {
   $scorebit="Score " . explode('.',$_POST['score'])[0] . '/' . $_POST['secs'];
   $recallit.='?score=' . explode('.',$_POST['score'])[0] . '/' . $_POST['secs'];
   if (isset($_POST['topic'])) {
     if (strlen(trim(str_replace('+',' ',urldecode($_POST['topic'])))) > 0) {
     $prescore='topic=' . $_POST['topic'] . '&';
     $recallit='./inhouse_blog_game.php?topic=' . $_POST['topic'] . '&score=' . explode('.',$_POST['score'])[0] . '/' . $_POST['secs'];
     $fhapp=$_POST['topic'];
     $topapp=' ' . trim(str_replace('+',' ',urldecode($_POST['topic'])));
     }
   }
 } else {
 if (isset($_GET['topic'])) {
   if (strlen(trim(str_replace('+',' ',urldecode($_GET['topic'])))) > 0) {
   $prescore='topic=' . $_GET['topic'] . '&';
   $recallit.='?topic=' . $_GET['topic'];
   $fhapp=$_GET['topic'];
   $topapp=' ' . trim(str_replace('+',' ',urldecode($_GET['topic'])));
   }
 } else if (isset($_POST['topic'])) {
   if (strlen(trim(str_replace('+',' ',urldecode($_POST['topic'])))) > 0) {
   $prescore='topic=' . $_POST['topic'] . '&';
   $recallit.='?topic=' . $_POST['topic'];
   $fhapp=$_POST['topic'];
   $topapp=' ' . trim(str_replace('+',' ',urldecode($_POST['topic'])));
   }
 }
 }
 
 if ($fgapp != '') {
   $prescore.='filterstuff=' . $fgapp . '&';
   if (strpos($recallit, '?') === false) {
   $recallit.='?filterstuff=' . $fgapp;
   } else {
   $recallit.='&filterstuff=' . $fgapp;
   }
   $topapp.=' ' . trim(str_replace('+',' ',urldecode($fgapp)));
 }
 
 if ($recallit == './inhouse_blog_game.php' && !isset($_GET['reload'])) {
   echo "<html><head><title>Experimental Drag and Drop - RJM Programming- July, 2023 ... thanks to https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/setData</title></head><body><iframe id=myihbqiframe frameborder=0 onload=\"if (this.src.indexOf('inhouse_blog_game.') == -1) { var aconto = (this.contentWindow || this.contentDocument); if (aconto.document) { aconto = aconto.document; }  aconto.body.style.border='2px dotted olive'; aconto.body.style.cursor='progress'; setTimeout(function() { document.getElementById('myihbqiframe').src='//www.rjmprogramming.com.au/HTMLCSS/inhouse_blog_game.php?reload=yes'; }, 7000); aconto.getElementById('score').innerHTML+=' ... awaiting Inhouse Blog Game loading ...';    }\" style=\"width:100%;height:900px;\" src=\"./experimental_drag_and_drop.htm\"></iframe></body></html>";
   exit;
 }
 
 function toyyyymmdd($indateis) {
   $dps=explode(' ', $indateis);
   $dpsp=explode('+', $indateis);
   if (sizeof($dps) == 3) {
     return '' . $dps[2] . str_replace('January','01',str_replace('February','02',str_replace('March','03',str_replace('April','04',str_replace('May','05',str_replace('June','06',str_replace('July','07',str_replace('August','08',str_replace('September','09',str_replace('October','10',str_replace('November','11',str_replace('December','12',$dps[1])))))))))))) . substr(('0' . $dps[0]), -2, 2);
   } else if (sizeof($dpsp) == 3) {
     return '' . $dpsp[2] . str_replace('January','01',str_replace('February','02',str_replace('March','03',str_replace('April','04',str_replace('May','05',str_replace('June','06',str_replace('July','07',str_replace('August','08',str_replace('September','09',str_replace('October','10',str_replace('November','11',str_replace('December','12',$dpsp[1])))))))))))) . substr(('0' . $dpsp[0]), -2, 2);
   }
   return urlencode($indateis);
 }
 
 $typedescstuff="1 ONE
1#//www.rjmprogramming.com.au/ITblog/600" . $fhapp . "/400" . $fgapp . "/?random=" . $ourrand . "1437195

2 TWO
2#//www.rjmprogramming.com.au/ITblog/600" . $fhapp . "/400" . $fgapp . "/?random=" . $ourrand . "2437195

3 THREE
3#//www.rjmprogramming.com.au/ITblog/600" . $fhapp . "/400" . $fgapp . "/?random=" . $ourrand . "3437195

4 FOUR
4#//www.rjmprogramming.com.au/ITblog/600" . $fhapp . "/400" . $fgapp . "/?random=" . $ourrand . "4437195

5 FIVE
5#//www.rjmprogramming.com.au/ITblog/600" . $fhapp . "/400" . $fgapp . "/?random=" . $ourrand . "5437195

6 SIX
6#//www.rjmprogramming.com.au/ITblog/600" . $fhapp . "/400" . $fgapp . "/?random=" . $ourrand . "6437195
 
7 SEVEN
7#//www.rjmprogramming.com.au/ITblog/600" . $fhapp . "/400" . $fgapp . "/?random=" . $ourrand . "7437195

8 EIGHT
8#//www.rjmprogramming.com.au/ITblog/600" . $fhapp . "/400" . $fgapp . "/?random=" . $ourrand . "8437195

9 NINE
9#//www.rjmprogramming.com.au/ITblog/600" . $fhapp . "/400" . $fgapp . "/?random=" . $ourrand . "9437195";

  $thisis=file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'inhouse_blog_game.php');
  $lastotherde='';
  $categorizations=[];
  $wikistuffs=explode("\n", $typedescstuff);
  $wikidesignations=[];
  $wikidescriptions=[];
  $crandlist='';
  $randlist=[];
  $thisde='';
  $otherde='';
  for ($i=0; $i<sizeof($wikistuffs); $i++) {
    if (trim($wikistuffs[$i]) == '') {
    if ($thisde != '') {
    array_push($categorizations, $thisde);
    //array_push($wikidesignations, $thisde);
    //array_push($wikidescriptions, '');
    }
    $thisde='';
    } else if (trim($wikistuffs[$i]) != '') {
    if (trim($wikistuffs[$i]) != '' && trim($wikistuffs[$i]) == strtoupper(trim($wikistuffs[$i]))) {
    $thisde=substr($wikistuffs[$i],2);
    } else if ($thisde != '') {
    $otherde=$thisde; // . ' ... ' . $wikistuffs[$i];
    array_push($categorizations, $otherde);
    $thisde='';
    //} else {    
    if (trim($otherde) != '') {
    $cwikistuffs=explode(',', trim($wikistuffs[$i]));
    for ($ii=0; $ii<sizeof($cwikistuffs); $ii++) {
    if (1 == 7) {
    if (strpos(($cwikistuffs[$ii] . '@'), '#@') !== false) {
       $bio=file_get_contents('http://en.wikipedia.org/wiki/' . str_replace(' ','_',explode('#',$cwikistuffs[$ii])[0]) . '_(moon)');
       $biois=explode('<img src="', $bio);
       if (sizeof($biois) > 1) {
       //file_put_contents('x.x', file_get_contents('x.x') . "\n" . 'http://en.wikipedia.org/wiki/' . str_replace(' ','_',explode('#',$cwikistuffs[$ii])[0]) . '_(moon)');
         $thisis=str_replace(($cwikistuffs[$ii] . ''), $cwikistuffs[$ii] . '' . explode('"', $biois[1])[0], $thisis);
         file_put_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'inhouse_blog_game.php', $thisis); 
         $cwikistuffs[$ii].='' . explode('"', $biois[1])[0];
       }
    } else if (strpos($cwikistuffs[$ii], '#') === false) {
       $bio=file_get_contents('http://en.wikipedia.org/wiki/' . str_replace(' ','_',$cwikistuffs[$ii]) . '_(moon)');
       $biois=explode('<img src="', $bio);
       if (sizeof($biois) > 1) {
         $thisis=str_replace($cwikistuffs[$ii], $cwikistuffs[$ii] . '#' . explode('"', $biois[1])[0], $thisis);
         file_put_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'inhouse_blog_game.php', $thisis); 
         $cwikistuffs[$ii].='#' . explode('"', $biois[1])[0];
       }
    }
    }
    array_push($wikidesignations, $cwikistuffs[$ii]);
    array_push($wikidescriptions, $otherde);
    }
    $otherde='';
    }
    }
    }
  }
  
  //echo "1 " . sizeof($wikidesignations) . ' ' . sizeof($categorizations) . ' ' . sizeof($wikidescriptions);
  //exit;
  
  $randmode=rand(0,1);
  //$randmode=0;
  $goodlist='';
  $badlist='';
  
  while (strlen($goodlist) == strlen($badlist)) {
  $goodlist='';
  $badlist='';
  
  $correctans=rand(0,8);
  $sofar=';';
  for ($i=0; $i<9; $i++) {
    $j=rand(0, (-1 + sizeof($wikidesignations)));
    if ($crandlist == '') {
      $crandlist='' . $j;
      $sofar.=$wikidescriptions[$j] . ';';
      if (strpos($goodlist, $wikidescriptions[$j]) === false) {   $goodlist.=$wikidescriptions[$j] . ',';     }
    } else if (strpos((',' . $crandlist . ','), (',' . $j . ',')) !== false) { // || strpos($sofar, ';' . $wikidescriptions[$j] . ';') !== false) {
      while (strpos((',' . $crandlist . ','), (',' . $j . ',')) !== false) { // || strpos($sofar, ';' . $wikidescriptions[$j] . ';') !== false) {
        $j=rand(0, (-1 + sizeof($wikidesignations)));
      }
      $crandlist.=',' . $j;
      $sofar.=$wikidescriptions[$j] . ';';
      if (strpos($goodlist, $wikidescriptions[$j]) === false) {   $goodlist.=$wikidescriptions[$j] . ',';     }
    } else {
      if (strpos($sofar, ';' . $wikidescriptions[$j] . ';') !== false) { $badlist.=$wikidescriptions[$j] . ','; }
      $crandlist.=',' . $j;
      $sofar.=$wikidescriptions[$j] . ';';
      if (strpos($goodlist, $wikidescriptions[$j]) === false) {   $goodlist.=$wikidescriptions[$j] . ',';     }
    }
  }
  }  
  
  $sofar=';';
  $ccrandlist='';
  for ($i=1; $i<=9; $i++) {
    $j=rand(1, 9);
    if ($ccrandlist == '') {
      $ccrandlist='' . $j;
      $sofar.='' . $j . ';';
    } else if (strpos((',' . $ccrandlist . ','), (',' . $j . ',')) !== false) {
      while (strpos((',' . $ccrandlist . ','), (',' . $j . ',')) !== false) {
        $j=rand(1, 9);
      }
      $ccrandlist.=',' . $j;
      $sofar.='' . $j . ';';
    } else {
      $ccrandlist.=',' . $j;
      $sofar.='' . $j . ';';
    }
  }
  
  
  $grandlist=explode(',', "0,1,2,3,4,5,6,7,8"); //$crandlist);
  $randlist=explode(',', "1,2,3,4,5,6,7,8,9"); //$crandlist);
  $randlist=explode(',', $crandlist);
  $rrandlist=explode(',', $ccrandlist);
  
  $callbackurl='./inhouse_blog_game.php';
  $templategame=file_get_contents('./experimental_drag_and_drop.htm');

  if (1 == 6) {
  for ($i=1; $i<=9; $i++) {
    $templategame=str_replace('>' . $i . '<', '>##' . $rrandlist[-1 + $i] . '<', $templategame);
  }
  }
  
  $templategame=str_replace('>##', '>', $templategame);
  $templategame=str_replace('<table ', '<table cellspacing=8 cellpadding=8 ', $templategame);

  $templategame=str_replace('</h4>', '<input type=hidden id="callback" value="' . $callbackurl . '"></input></h4>', $templategame);
  $templategame=str_replace('>Game<', '>Inhouse Bl' . 'og' . $topapp . ' Game <font size=1>... drag to matching correct answer to score</font><', $templategame);
  $templategame=str_replace('></h3>', '>' . $scorebit . '</h3>', $templategame);
  $thepsource=explode('f0;">', explode("</p>", $templategame)[0])[-1 + sizeof(explode('f0;">', explode("</p>", $templategame)[0]))];

  $templategame=str_replace(' July, 2023<', ' September, 2023<', $templategame);
  $templategame=str_replace('>Reset example<', ' style="display:none;">Reset example<', $templategame);
  
  $templategame=str_replace('RJM Programming - ', 'RJM Programming <a style=text-decoration:none;cursor:pointer; onclick="var filterlist=' . "' emboss edge negedge sharpen boxblur grayscale gaussianianblur selectiveblur negate colourizered colourizegreen colourize colourizeblue pixellate smooth contrast brightness sketchy flipvertical fliphorizontal flip scale crop merge transparent rotation '" . '; var fbit=filterlist.substring(0,1).trim();  var fbits=filterlist.trim().split(String.fromCharCode(32));  var topic=prompt(' . "'Optionally refine Blog Postings to ones regarding your entered Topic word(s) then/or all lowercase Image Filter verbs from emboss edge negedge sharpen boxblur grayscale gaussianianblur selectiveblur negate colourizered colourizegreen colourize colourizeblue pixellate smooth contrast brightness sketchy flipvertical fliphorizontal flip scale crop merge transparent rotation.',''" . '); if (topic) { var wastopic=String.fromCharCode(32) + topic;   for (var ii=0; ii<fbits.length; ii++) { if (wastopic.indexOf(String.fromCharCode(32) + fbits[ii]) != -1) { wastopic=wastopic.split(String.fromCharCode(32) + fbits[ii])[0];   if (fbit.length == 0) { fbit=' . "'&filterstuff=' + fbits[ii]" . ';  } else { fbit+=' . "'%20' + fbits[ii]" . '; } } }   if (topic.trim().length != 0) { var documentURL=document.URL,dlm=String.fromCharCode(38); if (document.URL.indexOf(String.fromCharCode(63)) == -1) { dlm=String.fromCharCode(63);   } else {  documentURL=document.URL.replace(String.fromCharCode(102) + String.fromCharCode(61), String.fromCharCode(61)).replace(String.fromCharCode(99) + String.fromCharCode(61), String.fromCharCode(61)); }  document.body.style.cursor=' . "'progress'; " . '   location.href=' . "documentURL + dlm + 'topic=' + encodeURIComponent(wastopic.trim()) + fbit;" . '  }  }" title=Topics>+</a> ', $templategame);
  $templategame=str_replace('RJM Programming <span id="spmore">-</span> ', 'RJM Programming <span id="spmore"><a style=text-decoration:none;cursor:pointer; onclick="var filterlist=' . "' emboss edge negedge sharpen boxblur grayscale gaussianianblur selectiveblur negate colourizered colourizegreen colourize colourizeblue pixellate smooth contrast brightness sketchy flipvertical fliphorizontal flip scale crop merge transparent rotation '" . ';  var fbit=filterlist.substring(0,1).trim();  var fbits=filterlist.trim().split(String.fromCharCode(32));   var topic=prompt(' . "'Optionally refine Blog Postings to ones regarding your entered Topic word(s) then/or all lowercase Image Filter verbs from emboss edge negedge sharpen boxblur grayscale gaussianianblur selectiveblur negate colourizered colourizegreen colourize colourizeblue pixellate smooth contrast brightness sketchy flipvertical fliphorizontal flip scale crop merge transparent rotation.',''" . '); if (topic) { var wastopic=String.fromCharCode(32) + topic; for (var ii=0; ii<fbits.length; ii++) { if (wastopic.indexOf(String.fromCharCode(32) + fbits[ii]) != -1) { wastopic=wastopic.split(String.fromCharCode(32) + fbits[ii])[0];   if (fbit.length == 0) { fbit=' . "'&filterstuff=' + fbits[ii]" . ';  } else { fbit+=' . "'%20' + fbits[ii]" . '; } } } if (topic.trim().length != 0) { var documentURL=document.URL,dlm=String.fromCharCode(38); if (document.URL.indexOf(String.fromCharCode(63)) == -1) { dlm=String.fromCharCode(63);   } else {  documentURL=document.URL.replace(String.fromCharCode(102) + String.fromCharCode(61), String.fromCharCode(61)).replace(String.fromCharCode(99) + String.fromCharCode(61), String.fromCharCode(61)); }  document.body.style.cursor=' . "'progress'; " . '    location.href=' . "documentURL + dlm + 'topic=' + encodeURIComponent(wastopic.trim()) + fbit;" . '  }  }" title=Topics>+</a></span> ', $templategame);
  $templategame=str_replace('RJM Programming <span id=spmore>-</span> ', 'RJM Programming <span id=spmore><a style=text-decoration:none;cursor:pointer; onclick="var filterlist=' . "' emboss edge negedge sharpen boxblur grayscale gaussianianblur selectiveblur negate colourizered colourizegreen colourize colourizeblue pixellate smooth contrast brightness sketchy flipvertical fliphorizontal flip scale crop merge transparent rotation '" . ';  var fbit=filterlist.substring(0,1).trim();  var fbits=filterlist.trim().split(String.fromCharCode(32));   var topic=prompt(' . "'Optionally refine Blog Postings to ones regarding your entered Topic word(s) then/or all lowercase Image Filter verbs from emboss edge negedge sharpen boxblur grayscale gaussianianblur selectiveblur negate colourizered colourizegreen colourize colourizeblue pixellate smooth contrast brightness sketchy flipvertical fliphorizontal flip scale crop merge transparent rotation.',''" . '); if (topic) { var wastopic=String.fromCharCode(32) + topic; for (var ii=0; ii<fbits.length; ii++) { if (wastopic.indexOf(String.fromCharCode(32) + fbits[ii]) != -1) { wastopic=wastopic.split(String.fromCharCode(32) + fbits[ii])[0];  if (fbit.length == 0) { fbit=' . "'&filterstuff=' + fbits[ii]" . ';  } else { fbit+=' . "'%20' + fbits[ii]" . '; } } } if (topic.trim().length != 0) { var documentURL=document.URL,dlm=String.fromCharCode(38); if (document.URL.indexOf(String.fromCharCode(63)) == -1) { dlm=String.fromCharCode(63);   } else {  documentURL=document.URL.replace(String.fromCharCode(102) + String.fromCharCode(61), String.fromCharCode(61)).replace(String.fromCharCode(99) + String.fromCharCode(61), String.fromCharCode(61)); }  document.body.style.cursor=' . "'progress'; " . '  location.href=' . "documentURL + dlm + 'topic=' + encodeURIComponent(wastopic.trim()) + fbit;" . '  }  }" title=Topics>+</a></span> ', $templategame);

  
  //echo $crandlist . "\n" . $thepsource . "\n" . $correctans . "\n";
  //exit;
  //echo $crandlist . "\n";
  //echo "" . $randlist[$correctans] . "\n" . $wikidescriptions[$randlist[$correctans]] . "\n" . $wikidesignations[$randlist[$correctans]];
  //exit;
  
  //file_put_contents('x.x', '' . $randmode . "\n" . $crandlist . "\n" . $thepsource . "\n" . $correctans . "\n" . $crandlist . "\n" . $randlist[$correctans] . "\n" . $wikidescriptions[$randlist[$correctans]] . "\n" . $wikidesignations[$randlist[$correctans]]);
  $precall='';
  $subwhat="";
  if ($randmode == 0) {  // designation up top and descriptions in drop zone
    $ordns=['ZERO','ONE','TWO','THREE','FOUR','FIVE','SIX','SEVEN','EIGHT','NINE'];
    $jkh=0;
    while (strpos($badlist, ',' . explode(' ... ', $wikidescriptions[$grandlist[$correctans]])[0] . ',') !== false) {
      $jkh++;
      $correctans=rand(0,8);
      if ($jkh > 20) { header('Location: ' . $recallit); exit;   }
    }
    $subwhat=$categorizations[$correctans];
    $precall=file_get_contents('http:' . str_replace('http:','',explode('#', $wikidesignations[$correctans])[1]));
    $templategame=str_replace('>' . (1 + $correctans) . '<', ' data-answer="' . explode(' ... ', $categorizations[$grandlist[$correctans]])[0] . '">' . explode('#',$wikidesignations[$correctans])[0] . '<', $templategame);
    //$templategame=str_replace('>' . (1 + $correctans) . '<', ' data-answer="' . explode(' ... ', $wikidescriptions[$randlist[$correctans]])[0] . '">' . $categorizations[$correctans] . '<', $templategame);
    if (strpos($wikidesignations[$grandlist[$correctans]], '#') !== false) {
    $templategame=str_replace(' style="background-color:#f0f0f0;"', ' ', $templategame);
    //$templategame=str_replace('>' . $thepsource . '<', ' data-answer="' . explode(' ... ', $wikidescriptions[$grandlist[$correctans]])[0] . '" style="background-color:#f0f0f0;background:URL(' . str_replace('http:','',explode('#', $wikidesignations[$grandlist[$correctans]])[1]) . '); background-repeat: no-repeat; background-size: contain;background-position: center right;border:5px dashed pink;" alt="f0;">&nbsp;<br>' . explode('#', $wikidesignations[$grandlist[$correctans]])[0] . '<br>&nbsp;<', $templategame);
    $templategame=str_replace('>' . $thepsource . '<', ' data-answer="' . explode(' ... ', $wikidescriptions[$grandlist[$correctans]])[0] . '" style="background-color:#f0f0f0;background:URL(' . str_replace('http:','',explode('#', $wikidesignations[$grandlist[$correctans]])[1]) . '); background-repeat: no-repeat; background-size: contain;background-position: center right;border:5px dashed pink;" alt="f0;">&nbsp;<br>' . '<br>&nbsp;<', $templategame);
    } else {
    $templategame=str_replace('>' . $thepsource . '<', ' data-answer="' . explode(' ... ', $wikidescriptions[$grandlist[$correctans]])[0] . '">' . explode('#', $wikidesignations[$grandlist[$correctans]])[0] . '<', $templategame);
    }
    for ($i=1; $i<=9; $i++) {
       if ((-1 + $i) != $correctans) {
    //$templategame=str_replace('>' . $i . '</td', ' data-answer="' . explode(' ... ', $categorizations[-1 + $i])[0] . '">' . $categorizations[-1 + $i] . '</td', $templategame);
    $precall=file_get_contents('http:' . str_replace('http:','',explode('#', $wikidesignations[-1 + $i])[1]));
    $templategame=str_replace('>' . $i . '</td', ' data-answer="' . explode(' ... ', $categorizations[-1 + $i])[0] . '">' . explode('#',$wikidesignations[-1 + $i])[0] . '</td', $templategame);
       }
    }

    sleep(1);
    $cont=file_get_contents('http://www.rjmprogramming.com.au/ptitledddata.html?random=' . rand(0,987675643));
    //echo $precall . ' ... ' . $cont;
    //exit;
// echo "\n\n" . $cont . "\n\n";
    while (strpos($cont, '?random=' . $ourrand) === false) {
      sleep(5);
      $cont=file_get_contents('http://www.rjmprogramming.com.au/ptitledddata.html?random=' . rand(0,987675643));
    }

    $partn=explode('?random=' . $ourrand, $cont);
// echo "\n\n" . $partn . ' ... ' . $cont . "\n\n";
    while ($partn < 10) {
      sleep(5);
      $cont=file_get_contents('http://www.rjmprogramming.com.au/ptitledddata.html?random=' . rand(0,987675643));
      $partn=explode('?random=' . $ourrand, $cont);
// echo "\n\n" . $partn . ' ... ' . $cont . "\n\n";
    }
    sleep(1);
    $cont=file_get_contents('http://www.rjmprogramming.com.au/ptitledddata.html?random=' . rand(0,987675643));

    // from here down
    $lookforis='?random=' . $ourrand . str_replace('NINE','9',str_replace('EIGHT','8',str_replace('SEVEN','7',str_replace('SIX','6',str_replace('FIVE','5',str_replace('FOUR','4',str_replace('THREE','3',str_replace('TWO','2',str_replace('ONE','1',    $subwhat)))))))));
    $tois='><';
    if (strpos($cont, $lookforis) !== false) {
      if ($randmode == 0) {
      $templategame=str_replace("location.href=document.getElementById('callback').value + '?score=' + score + '&secs=' + secs;", "setTimeout(function(){ document.body.style.cursor='progress'; location.href = document.getElementById('callback').value + '?" . $prescore . "score=' + score + '&secs=' + secs; }, 8000);", str_replace("location.href=document.getElementById('callback').value + '?" . $prescore . "score=' + score + '&secs=' + secs;", "setTimeout(function(){ document.body.style.cursor='progress';  location.href = document.getElementById('callback').value + '?" . $prescore . "score=' + score + '&secs=' + secs; }, 8000);", $templategame));
      $tois='>' . explode("\n", explode($lookforis, $cont)[0])[-1 + sizeof(explode("\n", explode($lookforis, $cont)[0]))] . '</p>';
      $templategame=str_replace('></p>', $tois, $templategame);
      if (1 == 1) {
      for ($iw=1; $iw<=9; $iw++) {
         $lookforis='?random=' . $ourrand . $iw;
         $parts=explode('>' . $iw . '</td>', $templategame);
         if (sizeof($parts) >= 2) {
            $dtois='';
            $xtois=explode("\n", explode($lookforis, $cont)[0])[-1 + sizeof(explode("\n", explode($lookforis, $cont)[0]))];
            $tois=explode(' (', explode("\n", explode($lookforis, $cont)[0])[-1 + sizeof(explode("\n", explode($lookforis, $cont)[0]))])[0];
            if (strpos(explode("\n", explode($lookforis, $cont)[0])[-1 + sizeof(explode("\n", explode($lookforis, $cont)[0]))], ' (') !== false) {
              $dtois=explode(')', explode(' (', explode("\n", explode($lookforis, $cont)[0])[-1 + sizeof(explode("\n", explode($lookforis, $cont)[0]))])[1])[0];
              $templategame=str_replace('?random=' . $ourrand . $iw . '437195', '?mustbedated=' . toyyyymmdd($dtois), $templategame);
              $parts=explode('>' . $iw . '</td>', $templategame);
            }
            $templategame=str_replace($parts[0], $parts[0] . ' data-blogtitle="' . $tois . '"' . ' data-blogdate="' . $dtois . '" title="Double click for hint" ondblclick="window.open(' . "'//www.rjmprogramming.com.au/slideshow.html?title=' + encodeURIComponent(this.getAttribute('data-blogtitle')),'_blank','top=50,left=50,width=800,height=800'" .  ');" oncontextmenu="window.open(' . "'//www.rjmprogramming.com.au/ITblog/' + thefauxencodeURIComponent(this.getAttribute('data-blogtitle')),'_blank','top=60,left=60,width=800,height=800'" .  ');"', $templategame);
            $templategame=str_replace('>' . $iw . '</td>', '>' . $xtois . '</td>', $templategame);
            $templategame=str_replace(' data-answer="' . $ordns[$iw] . '"', ' data-answer="' . $xtois . '"', $templategame);
         }
      }
      }
      }
    //} else {
    //  file_put_contents('x.x', $lookforis . ' ... ' . $cont);
    //  exit;
    }

    $templategame=str_replace(' contenteditable=', ' data-contenteditable=', $templategame);
    echo $templategame;
  } else { // description up top and designations in drop zone
    while (strpos($badlist, ',' . explode(' ... ', $wikidescriptions[$randlist[$correctans]])[0] . ',') !== false) {
      $jkh++;
      $correctans=rand(0,8);
      if ($jkh > 20) { header('Location: ' . $recallit); exit;   }
    }
    if (strpos($wikidesignations[$grandlist[$correctans]], '#') !== false) {
    $templategame=str_replace(' style="background-color:#f0f0f0;"', ' ', $templategame);
    //$precall=file_get_contents('http' . str_replace('http:','',explode('#', $wikidesignations[$grandlist[$correctans]])[1]));
    $templategame=str_replace('>' . (1 + $correctans) . '<', ' data-answer="' . explode('#', $wikidesignations[$grandlist[$correctans]])[0] . '" style="background-color:#f0f0f0;background:URL(' . str_replace('http:','',explode('#', $wikidesignations[$grandlist[$correctans]])[1]) . '); background-repeat: no-repeat; background-size: contain;background-position: center right;" alt="f0;">' . explode('#', $wikidesignations[$grandlist[$correctans]])[0] . '<', $templategame);
    } else {
    //$precall=file_get_contents('http' . str_replace('http:','',explode('#', $wikidesignations[$grandlist[$correctans]])[1]));
    $templategame=str_replace('>' . (1 + $correctans) . '<', ' data-answer="' . explode('#', $wikidesignations[$grandlist[$correctans]])[0] . '">' . explode('#', $wikidesignations[$grandlist[$correctans]])[0] . '<', $templategame);
    }
    if (strpos($wikidesignations[$grandlist[$correctans]], '#') !== false && 1 == 7) {
    $precall=file_get_contents('http:' . str_replace('http:','',explode('#', $wikidesignations[$grandlist[$correctans]])[1]));
    $templategame=str_replace('>' . $thepsource . '<', ' data-answer="' . explode('#',$wikidesignations[$grandlist[$correctans]])[0] . '" style="background:URL(' . str_replace('http:','',explode('#', $wikidesignations[$grandlist[$correctans]])[1]) . '); background-repeat: no-repeat; background-size: contain;background-position: center right;border:5px dashed pink;" alt="f0;">&nbsp;<br>' . $wikidescriptions[$grandlist[$correctans]] . '<br>&nbsp;<', $templategame);
    } else {
    $templategame=str_replace(' style="border:5px dashed pink;background-color:#f0f0f0;"', ' ', $templategame);
    $subwhat=$wikidescriptions[$grandlist[$correctans]];
    $precall=file_get_contents('http:' . str_replace('http:','',explode('#', $wikidesignations[$grandlist[$correctans]])[1]));
    $templategame=str_replace('>' . $thepsource . '<', ' style="border:5px dashed pink;background-color:#f0f0f0;" data-answer="' . explode('#', $wikidesignations[$grandlist[$correctans]])[0] . '"><', $templategame);
    //$templategame=str_replace('>' . $thepsource . '<', ' style="border:5px dashed pink;background-color:#f0f0f0;" data-answer="' . explode('#', $wikidesignations[$randlist[$correctans]])[0] . '">' . $wikidescriptions[$randlist[$correctans]] . '<', $templategame);
    }
    for ($i=1; $i<=9; $i++) {
       if ((-1 + $i) != $correctans) {
    if (strpos($wikidesignations[$grandlist[-1 + $i]], '#') !== false) {
    $precall=file_get_contents('http:' . str_replace('http:','',explode('#', $wikidesignations[$grandlist[-1 + $i]])[1]));
    $templategame=str_replace('>' . $i . '</td', ' data-answer="" style="background:URL(' . str_replace('http:','',explode('#', $wikidesignations[$grandlist[-1 + $i]])[1]) . '); background-repeat: no-repeat; background-size: contain;background-position: center right;" alt="f0;">' . explode('#', $wikidesignations[$grandlist[-1 + $i]])[0] . '</td', $templategame);
    } else {
    $precall=file_get_contents('http:' . str_replace('http:','',explode('#', $wikidesignations[$grandlist[-1 + $i]])[1]));
    $templategame=str_replace('>' . $i . '</td', ' data-answer="">' . explode('#', $wikidesignations[$grandlist[-1 + $i]])[0] . '</td', $templategame);
    }
       }
       //sleep(1);
    }
    if (9 == 99) {
    sleep(30);
    } else {
    sleep(1);
    $cont=file_get_contents('http://www.rjmprogramming.com.au/ptitledddata.html?random=' . rand(0,987675643));
    //echo $precall . ' ... ' . $cont;
    //exit;
    while (strpos($cont, '?random=' . $ourrand) === false) {
      sleep(5);
      $cont=file_get_contents('http://www.rjmprogramming.com.au/ptitledddata.html?random=' . rand(0,987675643));
    }
    $partn=explode('?random=' . $ourrand, $cont);
    while ($partn < 10) {
      sleep(5);
      $cont=file_get_contents('http://www.rjmprogramming.com.au/ptitledddata.html?random=' . rand(0,987675643));
      $partn=explode('?random=' . $ourrand, $cont);
    }
    sleep(1);
    $cont=file_get_contents('http://www.rjmprogramming.com.au/ptitledddata.html?random=' . rand(0,987675643));
    }
    //file_put_contents('x.x', '' . $subwhat . "\n" . $cont);
    $lookforis='?random=' . $ourrand . str_replace('NINE','9',str_replace('EIGHT','8',str_replace('SEVEN','7',str_replace('SIX','6',str_replace('FIVE','5',str_replace('FOUR','4',str_replace('THREE','3',str_replace('TWO','2',str_replace('ONE','1',    $subwhat)))))))));
    $tois='><';
    if (strpos($cont, $lookforis) !== false) {
      if ($randmode == 1) {
      //$templategame=str_replace("location.href=document.getElementById('callback').value + '?score=' + score + '&secs=' + secs;", "setTimeout(function(){ location.href=document.getElementById('callback').value + '?score=' + score + '&secs=' + secs; }, 8000);", $templategame);
      $templategame=str_replace("location.href=document.getElementById('callback').value + '?score=' + score + '&secs=' + secs;", "setTimeout(function(){ document.body.style.cursor='progress';  location.href = document.getElementById('callback').value + '?" . $prescore . "score=' + score + '&secs=' + secs; }, 8000);", str_replace("location.href=document.getElementById('callback').value + '?" . $prescore . "score=' + score + '&secs=' + secs;", "setTimeout(function(){ document.body.style.cursor='progress';  location.href = document.getElementById('callback').value + '?" . $prescore . "score=' + score + '&secs=' + secs; }, 8000);", $templategame));
      $tois='>' . explode("\n", explode($lookforis, $cont)[0])[-1 + sizeof(explode("\n", explode($lookforis, $cont)[0]))] . '</p>';
      $templategame=str_replace('></p>', $tois, $templategame);
      if (1 == 1) {
      for ($iw=1; $iw<=9; $iw++) {
         $lookforis='?random=' . $ourrand . $iw;
         $parts=explode('>' . $iw . '</td>', $templategame);
         if (sizeof($parts) >= 2) {
            $dtois='';
            $tois=explode(' (', explode("\n", explode($lookforis, $cont)[0])[-1 + sizeof(explode("\n", explode($lookforis, $cont)[0]))])[0];
            if (strpos(explode("\n", explode($lookforis, $cont)[0])[-1 + sizeof(explode("\n", explode($lookforis, $cont)[0]))], ' (') !== false) {
              $dtois=explode(')', explode(' (', explode("\n", explode($lookforis, $cont)[0])[-1 + sizeof(explode("\n", explode($lookforis, $cont)[0]))])[1])[0];
              $templategame=str_replace('?random=' . $ourrand . $iw . '437195', '?mustbedated=' . toyyyymmdd($dtois), $templategame);
              $parts=explode('>' . $iw . '</td>', $templategame);
            }
            $templategame=str_replace($parts[0], $parts[0] . ' data-blogtitle="' . $tois . '"' . ' data-blogdate="' . $dtois . '" title="Double click for hint" ondblclick="window.open(' . "'//www.rjmprogramming.com.au/slideshow.html?title=' + encodeURIComponent(this.getAttribute('data-blogtitle')),'_blank','top=50,left=50,width=800,height=800'" .  ');" oncontextmenu="window.open(' . "'//www.rjmprogramming.com.au/ITblog/' + thefauxencodeURIComponent(this.getAttribute('data-blogtitle')),'_blank','top=60,left=60,width=800,height=800'" .  ');"', $templategame);
         }
      }
      }
      }
    //} else {
    //  file_put_contents('x.x', $lookforis . ' ... ' . $cont);
    //  exit;
    }
    $templategame=str_replace(' contenteditable=', ' data-contenteditable=', $templategame);
    echo $templategame;
  }
  

?>
