<?php
// colouring_in_was_numbers_guessing_game.php
// April, 2024
// RJM Programming
// Using experimental_drag_and_drop.htm for Colouring In web application
// Note use of input type=color id=ddcolour 
error_reporting( E_ERROR | E_USER_ERROR ); 
 
$tstyle='';
if (isset($_GET['imageurl'])) {
 $fgc=file_get_contents(str_replace('https:','http:',str_replace('+',' ',urldecode($_GET['imageurl']))));
 if (trim($fgc) != '') {
 if (isset($_GET['opacity'])) {
   $tstyle='background-image:linear-gradient(rgba(255,255,255,' . (1.0 - str_replace('+','',urldecode($_GET['opacity']))) . '),rgba(255,255,255,' . (1.0 - str_replace('+','',urldecode($_GET['opacity']))) . ')),URL(' . 'data:image/' . str_replace('jpg','jpeg',strtolower(explode('.',str_replace('+',' ',urldecode($_GET['imageurl'])))[-1 + sizeof(explode('.',str_replace('+',' ',urldecode($_GET['imageurl']))))])) . ';base64,' . str_replace(' ','+',base64_encode($fgc)) . '); background-repeat:no-repeat; background-size:contain; ';
 } else {
   $tstyle='background-image:linear-gradient(rgba(255,255,255,0.0),rgba(255,255,255,0.0)),URL(' . 'data:image/' . str_replace('jpg','jpeg',strtolower(explode('.',str_replace('+',' ',urldecode($_GET['imageurl'])))[-1 + sizeof(explode('.',str_replace('+',' ',urldecode($_GET['imageurl']))))])) . ';base64,' . str_replace(' ','+',base64_encode($fgc)) . '); background-repeat:no-repeat; background-size:contain; ';
 }
 } else {
 $fgc=str_replace('http:','',str_replace('https:','',str_replace('+',' ',urldecode($_GET['imageurl']))));
 if (isset($_GET['opacity'])) {
   $tstyle='background-image:linear-gradient(rgba(255,255,255,' . (1.0 - str_replace('+','',urldecode($_GET['opacity']))) . '),rgba(255,255,255,' . (1.0 - str_replace('+','',urldecode($_GET['opacity']))) . ')),URL("' . $fgc . '"); background-repeat:no-repeat; background-size:contain; ';
 } else {
   $tstyle='background-image:linear-gradient(rgba(255,255,255,0.0),rgba(255,255,255,0.0)),URL("' . $fgc . '"); background-repeat:no-repeat; background-size:contain; ';
 }
 }
 if (!isset($_GET['across'])) {
   $_GET['across']='200';
 }
}
$across=99;
if (isset($_GET['across'])) {  $across=str_replace('+',' ',urldecode($_GET['across']));  }
$fontweight=1;
if (isset($_GET['fontweight'])) {  $fontweight=str_replace('+',' ',urldecode($_GET['fontweight']));  }
$theans=rand(1,99);
$theclue="switch ($nclue) {
    case 0:
 $clue = 'Is the additive identity.';
        break;
    case 1:
 $clue = 'Is the multiplicative identity.';
        break;
    case 2:
 $clue = 'Is the only even prime.';
        break;
    case 3:
 $clue = 'Is the number of spatial dimensions we live in.';
        break;
    case 4:
 $clue = 'Is the smallest number of colors sufficient to color all planar maps.';
        break;
    case 5:
 $clue = 'Is the number of Platonic solids.';
        break;
    case 6:
 $clue = 'Is the smallest perfect number.';
        break;
    case 7:
 $clue = 'Is the smallest number of sides of a regular polygon that is not constructible by straightedge and compass.';
        break;
    case 8:
 $clue = 'Is the largest cube in the Fibonacci sequence.';
        break;
    case 9:
 $clue = 'Is the maximum number of cubes that are needed to sum to any positive integer.';
        break;
    case 10:
 $clue = 'Is the base of our number system.';
        break;
    case 11:
 $clue = 'Is the largest known multiplicative persistence.';
        break;
    case 12:
 $clue = 'Is the smallest abundant number.';
        break;
    case 13:
 $clue = 'Is the number of Archimedian solids.';
        break;
    case 14:
 $clue = 'Is the smallest even number n with no solutions to phi(m) = n.';
        break;
    case 15:
 $clue = 'Is the smallest composite number n with the property that there is only one group of order n.';
        break;
    case 16:
 $clue = 'Is the only number of the form xy = yx with x and y being different integers.';
        break;
    case 17:
 $clue = 'Is the number of wallpaper groups.';
        break;
    case 18:
 $clue = 'Is the only positive number that is twice the sum of its digits.';
        break;
    case 19:
 $clue = 'Is the maximum number of 4th powers needed to sum to any number.';
        break;
    case 20:
 $clue = 'Is the number of rooted trees with 6 vertices.';
        break;
    case 21:
 $clue = 'Is the smallest number of distinct squares needed to tile a square.';
        break;
    case 22:
 $clue = 'Is the number of partitions of 8.';
        break;
    case 23:
 $clue = 'Is the smallest number of integer-sided boxes that tile a box so that no two boxes share a common length.';
        break;
    case 24:
 $clue = 'Is the largest number divisible by all numbers less than its square root.';
        break;
    case 25:
 $clue = 'Is the smallest square that can be written as a sum of 2 squares.';
        break;
    case 26:
 $clue = 'Is the only positive number to be directly between a square and a cube.';
        break;
    case 27:
 $clue = 'Is the largest number that is the sum of the digits of its cube.';
        break;
    case 28:
 $clue = 'Is the 2nd perfect number.';
        break;
    case 29:
 $clue = 'Is the 7th Lucas number.';
        break;
    case 30:
 $clue = 'Is the largest number with the property that all smaller numbers relatively prime to it are prime.';
        break;
    case 31:
 $clue = 'Is a Mersenne prime.';
        break;
    case 32:
 $clue = 'Is the smallest non-trivial 5th power.';
        break;
    case 33:
 $clue = 'Is the largest number that is not a sum of distinct triangular numbers.';
        break;
    case 34:
 $clue = 'Is the smallest number with the property that it and its neighbors have the same number of divisors.';
        break;
    case 35:
 $clue = 'Is the number of hexominoes.';
        break;
    case 36:
 $clue = 'Is the smallest non-trivial number which is both square and triangular.';
        break;
    case 37:
 $clue = 'Is the maximum number of 5th powers needed to sum to any number.';
        break;
    case 38:
 $clue = 'Is the last Roman numeral when written lexicographically.';
        break;
    case 39:
 $clue = 'Is the smallest number which has 3 different partitions into 3 parts with the same product.';
        break;
    case 40:
 $clue = 'Is the only number whose letters are in alphabetical order.';
        break;
    case 41:
 $clue = 'Is a value of n so that x squared + x + n takes on prime values for x = 0, 1, 2, ... n-2.';
        break;
    case 42:
 $clue = 'Is the 5th Catalan number.';
        break;
    case 43:
 $clue = 'Is the number of sided 7-iamonds.';
        break;
    case 44:
 $clue = 'Is the number of derangements of 5 items.';
        break;
    case 45:
 $clue = 'Is a Kaprekar number.';
        break;
    case 46:
 $clue = 'Is the number of different arrangements (up to rotation and reflection) of 9 non-attacking queens on a 9×9 chessboard.';
        break;
    case 47:
 $clue = 'Is the largest number of cubes that cannot tile a cube.';
        break;
    case 48:
 $clue = 'Is the smallest number with 10 divisors.';
        break;
    case 49:
 $clue = 'Is the smallest number with the property that it and its neighbors are squareful.';
        break;
    case 50:
 $clue = 'Is the smallest number that can be written as the sum of 2 squares in 2 ways.';
        break;
    case 51:
 $clue = 'Is the 6th Motzkin number.';
        break;
    case 52:
 $clue = 'Is the 5th Bell number.';
        break;
    case 53:
 $clue = 'Is the only two digit number that is reversed in hexadecimal.';
        break;
    case 54:
 $clue = 'Is the smallest number that can be written as the sum of 3 squares in 3 ways.';
        break;
    case 55:
 $clue = 'Is the largest triangular number in the Fibonacci sequence.';
        break;
    case 56:
 $clue = 'Is the number of reduced 5 × 5 Latin squares.';
        break;
    case 57:
 $clue = 'Is 111 in base 7.';
        break;
    case 58:
 $clue = 'Is the number of commutative semigroups of order 4.';
        break;
    case 59:
 $clue = 'Is the number of stellations of an icosahedron.';
        break;
    case 60:
 $clue = 'Is the smallest number divisible by 1 through 6.';
        break;
    case 61:
 $clue = 'Is the 3rd secant number.';
        break;
    case 62:
 $clue = 'Is the smallest number that can be written as the sum of 3 distinct squares in 2 ways.';
        break;
    case 63:
 $clue = 'Is the number of partially ordered sets of 5 elements.';
        break;
    case 64:
 $clue = 'Is the smallest number with 7 divisors.';
        break;
    case 65:
 $clue = 'Is the smallest number that becomes square if its reverse is either added to or subtracted from it.';
        break;
    case 66:
 $clue = 'Is the number of 8-iamonds.';
        break;
    case 67:
 $clue = 'Is the smallest number which is palindromic in bases 5 and 6.';
        break;
    case 68:
 $clue = 'Is the 2-digit string that appears latest in the decimal expansion of π.';
        break;
    case 69:
 $clue = 'Is a value of n where n squared and n cubed together contain each digit once.';
        break;
    case 70:
 $clue = 'Is the smallest weird number.';
        break;
    case 71:
 $clue = 'Is the number that divides the sum of the primes less than it.';
        break;
    case 72:
 $clue = 'Is the maximum number of spheres that can touch another sphere in a lattice packing in 6 dimensions.';
        break;
    case 73:
 $clue = 'Is the smallest multi-digit number which is one less than twice its reverse.';
        break;
    case 74:
 $clue = 'Is the number of different non-Hamiltonian polyhedra with a minimum number of vertices.';
        break;
    case 75:
 $clue = 'Is the number of orderings of 4 objects with ties allowed.';
        break;
    case 76:
 $clue = 'Is an automorphic number.';
        break;
    case 77:
 $clue = 'Is the largest number that cannot be written as a sum of distinct numbers whose reciprocals sum to 1.';
        break;
    case 78:
 $clue = 'Is the smallest number that can be written as the sum of 4 distinct squares in 3 ways.';
        break;
    case 79:
 $clue = 'Is a permutable prime.';
        break;
    case 80:
 $clue = 'Is the smallest number n where n and n+1 are both products of 4 or more primes.';
        break;
    case 81:
 $clue = 'Is the square of the sum of its digits.';
        break;
    case 82:
 $clue = 'Is the number of 6-hexes.';
        break;
    case 83:
 $clue = 'Is the number of strongly connected digraphs with 4 vertices.';
        break;
    case 84:
 $clue = 'Is the largest order of a permutation of 14 elements.';
        break;
    case 85:
 $clue = 'Is the largest n for which 12+22+32+ ... +n2 = 1+2+3+ ... +m has a solution.';
        break;
    case 86:
 $clue = 'Is 222 in base 6.';
        break;
    case 87:
 $clue = 'Is the sum of the squares of the first 4 primes.';
        break;
    case 88:
 $clue = 'Is one of only 2 numbers known whose square has no isolated digits.';
        break;
    case 89:
 $clue = 'Is 8 to power of one + 9 to the power of 2.';
        break;
    case 90:
 $clue = 'Is the number of degrees in a right angle.';
        break;
    case 91:
 $clue = 'Is the smallest pseudoprime in base 3.';
        break;
    case 92:
 $clue = 'Is the number of different arrangements of 8 non-attacking queens on an 8×8 chessboard.';
        break;
    case 93:
 $clue = 'Is 333 in base 5.';
        break;
    case 94:
 $clue = 'Is a Smith number.';
        break;
    case 95:
 $clue = 'Is the number of planar partitions of 10.';
        break;
    case 96:
 $clue = 'Is the smallest number that can be written as the difference of 2 squares in 4 ways.';
        break;
    case 97:
 $clue = 'Is the smallest number with the property that its first 3 multiples contain the digit 9.';
        break;
    case 98:
 $clue = 'Is the smallest number with the property that its first 5 multiples contain the digit 9.';
        break;
    case 99:
 $clue = 'Is a Kaprekar number.';
        break;
    }
";
//$theclue=file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/Games/Battleshipsandcruisers/index2.php');
$ansa=explode('case ' . $theans . ':', $theclue);
$thecluewording=explode("'", explode("'", $ansa[1])[1])[0];

 $scorebit='';
 if (isset($_GET['score']) && isset($_GET['secs'])) {
   $scorebit="Score " . $_GET['score'] . '/' . $_GET['secs'];
 }

 $wikistuff=str_replace(' ','_',$thecluewording) . ' ' . $thecluewording;
 $wikistuff="1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15
16 16
17 17
18 18
19 19
20 20
21 21
22 22
23 23
24 24
25 25
26 26
27 27
28 28
29 29
30 30
31 31
32 32
33 33
34 34
35 35
36 36
37 37
38 38
39 39
40 40
41 41
42 42
43 43
44 44
45 45
46 46
47 47
48 48
49 49
50 50
51 51
52 52
53 53
54 54
55 55
56 56
57 57
58 58
59 59
60 60
61 61
62 62
63 63
64 64
65 65
66 66
67 67
68 68
69 69
70 70
71 71
72 72
73 73
74 74
75 75
76 76
77 77
78 78
79 79
80 80
81 81
82 82
83 83
84 84
85 85
86 86
87 87
88 88
89 89
90 90
91 91
92 92
93 93
94 94
95 95
96 96
97 97
98 98
99 99
";

  if ($across > 9) {
    $waswikistuff=$wikistuff;
    $wikistuffs=explode("\n", $wikistuff);
    while (sizeof($wikistuffs) < ($across * $across)) {
      $wikistuff.=$waswikistuff;
      $wikistuffs=explode("\n", $wikistuff);
    }
  }

  $lastotherde='';
  $wikistuffs=explode("\n", $wikistuff);
  $wikidesignations=[];
  $wikidescriptions=[];
  $crandlist='';
  $randlist=[];
  for ($i=0; $i<sizeof($wikistuffs); $i++) {
    $thisde=explode(' ', $wikistuffs[$i])[0];
    $otherde=substr($wikistuffs[$i], (strlen($thisde) + 1));
    if (strpos($otherde, ') ') !== false) {
      $otherde=explode(') ', $otherde)[1];
    }
    //echo $otherde;
    //exit;
    if (trim($thisde) != '') {
    array_push($wikidesignations, $thisde);
    array_push($wikidescriptions, trim($otherde));
    $lastotherde=$otherde;
    }
  }
  
  for ($i=0; $i<1; $i++) {
    $j=rand(0, (-1 + sizeof($wikidesignations)));
    if ($crandlist == '') {
      $crandlist='' . $j;
    } else if (strpos((',' . $crandlist . ','), (',' . $j . ',')) !== false) {
      while (strpos((',' . $crandlist . ','), (',' . $j . ',')) !== false) {
        $j=rand(0, (-1 + sizeof($wikidesignations)));
      }
      $crandlist.=',' . $j;
    } else {
      $crandlist.=',' . $j;
    }
  }
  
  $randlist=explode(',', $crandlist);
  $randmode=0; //rand(0,1);
  $correctans=(-1 + $theans); //rand(0,98);
  
  $callbackurl='./colouring_in_was_numbers_guessing_game.php';
  //$callbackurl='./colouringinwasnumbersguessinggame.php';
  //$dru='http://' . $_SERVER['SERVER_NAME'] . "" . str_replace("~","",str_replace(":443~","",str_replace(":80~","",(":" . $_SERVER['SERVER_PORT'] . "~")))) . "" . explode("#", explode("?", str_replace('/numbers_guessing_game.php','/experimental_drag_and_drop.htm',$_SERVER['REQUEST_URI']))[0])[0];
  $dru='http://' . $_SERVER['SERVER_NAME'] . "" . str_replace("~","",str_replace(":443~","",str_replace(":80~","",(":" . $_SERVER['SERVER_PORT'] . "~")))) . "" . explode("#", explode("?", str_replace('/numbers_guessing_game.php','/experimental_drag_and_drop.htm',$_SERVER['REQUEST_URI']))[0])[0];
  //$templategame=file_get_contents($dru . '?tdnum=99');
  $templategame=file_get_contents('./experimental_drag_and_drop.htm');
  //$templategame=file_get_contents('./experimentaldraganddrop.htm');
  //if (isset($_GET['notice'])) {
  //$templategame=str_replace('>-</span>', '><a style="text-decoration:none;cursor:pointer;" title="Stop showing where contemplated as well." onclick="location.href=' . "'#no_tice=y'" . ';">-</a><a style="text-decoration:none;cursor:pointer;" title="Show where contemplated as well." onclick="location.href=' . "'#notice=y'" . ';">+</a></span>', $templategame);
  //} else {
  //$templategame=str_replace('>-</span>', '><a style="text-decoration:none;cursor:pointer;" title="Show where contemplated as well." onclick="location.href=' . "'#notice=y'" . ';">+</a><a style="text-decoration:none;cursor:pointer;" title="Stop showing where contemplated as well." onclick="location.href=' . "'#no_tice=y'" . ';">-</a></span>', $templategame);
  //}
  $arow='';
  $rownum=$across;
  $tdnum=($across * $across);
  if (1 == 5) {
  for ($ijk=(1 + $across); $ijk<=$thnum; $ijk++) {
    if (($ijk % $across) == 1) {
      $rownum=(1 + ((-1 + $ijk) / $across));
      $arow='<tr id=tr' . $rownum . '><th id=th' . $rownum . '1>' . $ijk . '</th></tr>';
    } else if (($ijk % $across) == 0) {
      $arow=str_replace('</tr>', '<th id=th' . $rownum . $across . '>' . $ijk . '</th></tr>', $arow);
      $templategame=str_replace('</table>', $arow . '</table>', $templategame);
      $arow='';
    } else if (($ijk % $across) > 1) {
      $arow=str_replace('</tr>', '<th id=th' . $rownum . ($ijk % $across) . '>' . $ijk . '</th></tr>', $arow);
      $templategame=str_replace('</table>', $arow . '</table>', $templategame);
      $arow='';
    }
  }
  $templategame=str_replace('</table>', $arow . '</table>', $templategame);
    //file_put_contents('xx.html', $templategame);
  }
  
  if ($across != $across || 1 == 1) {
    //$across=99;
    $irws=1;
    $sofartd='';
    $two=2;
    if (strpos($templategame, '</table>') !== false) {
    if ($tstyle != '') {
    $templategame=str_replace("</body>", "\n<div id=\"ddstyle\"><style>" . " #mytable { " . $tstyle . " } </style></div></body>", $templategame);    
    $tstyle='';
    }
    if ($tstyle != '') {
    $wasih="<table" . str_replace(' style="', ' style="' . $tstyle, explode("</table>", explode("<table", $templategame)[1])[0]) . "</table>";
    } else {
    $wasih="<table" . explode("</table>", explode("<table", $templategame)[1])[0] . "</table>";
    }
    $templategame=str_replace($wasih, '', $templategame);
    }
    if (strpos($templategame, '</p>') !== false) {
    $wasih='#f0f0f0;">' . explode('#f0f0f0;">', explode("</p>", $templategame)[0])[-1 + sizeof(explode('#f0f0f0;">', explode("</p>", $templategame)[0]))] . "</p>";
    $templategame=str_replace($wasih, '#f0f0f0;width:20px;height:25px;">&#128396;</p>', $templategame);
    }
    $wasih='<div id="target"' . explode("</div>", explode('<div id="target"', $templategame)[1])[0]; // . "</div>";
    $origih=$wasih;
    
    $newih='<table border=1 cellpadding=0 cellspacing=0 style="width: 90%; height: 53%;" id="mytable"><tbody id=mytbody></tbody></table>';
    $cacross='' . $across;
    $iacross=strlen($cacross);
    $thisid='';
    $rowsofar='';
    $thistdid='td';
    $thistdidsuffix='';
    $ttcnt=1;
    
    for ($thisrow=1; $thisrow<=$across; $thisrow++) {
      $cthisrow='0000000000' . $thisrow;
      //$rowsofar='<tr id=svgtr' . $thisrow . ' onclick=textbthis(event); style="width:100%;" id=tr' . substr($cthisrow, -$iacross, $iacross) . '></tr>';
      $rowsofar='<tr id=tr' . ltrim(substr($cthisrow, -$iacross, $iacross),'0') . ' onclick=textbthis(event); style="width:100%;"></tr>';
      //$rowsofar='<tr id=svgtr' . $thisrow . ' style="width:100%;"></tr>';
      $thistdid='td' . substr($cthisrow, -$iacross, $iacross) . '_';
      for ($thiscol=1; $thiscol<=$across; $thiscol++) {
        $cthiscol='0000000000' . $thiscol;
        $thistdidsuffix='' . substr($cthiscol, -$iacross, $iacross) . '';
        $rowsofar=str_replace('></tr>', '><td class="tdone" id=' . $thistdid . $thistdidsuffix . ' style=text-align:center; data-answer=' . $ttcnt . '></td></tr>', $rowsofar);
      }
      $newih=str_replace('</tbody>', $rowsofar . '</tbody>', $newih);
    }
    
    //echo strlen($newih);
    //exit;
    
    //file_put_contents('x.html', str_replace($origih, $wasih, $templategame));
    $changeanyfrom='youllneverfindthis';
    $changeanyto='youllneverfindthis';
    if (isset($_GET['tableohprefix'])) {
      $changeanyfrom='width: 90%; height: 53%;'; // tableohprefix
      $changeanyto='position:absolute;top:0px;left:0px;width:' . trim(explode(';', explode('width:', str_replace('+',' ',urldecode($_GET['tableohprefix'])))[1])[0]) . ';height:' . trim(explode(';', explode('height:', str_replace('+',' ',urldecode($_GET['tableohprefix'])))[1])[0]) . ';';
      $changeanyto='width:' . trim(explode(';', explode('width:', str_replace('+',' ',urldecode($_GET['tableohprefix'])))[1])[0]) . ';height:' . trim(explode(';', explode('height:', str_replace('+',' ',urldecode($_GET['tableohprefix'])))[1])[0]) . ';';
      //$changeanyfrom='width:90vw;height:53vh;'; // tableohprefix
      //file_put_contents('x.x', $origih . "\n\n\n" . $newih);
      //$newih="<table" . str_replace('+',' ',urldecode($_GET['tableohprefix'])) . "><tbody></tbody></table>";
    } //else {
      //file_put_contents('x.x', $origih . "\n\n\n" . $newih);
    //}
    //if (strpos($templategame, $origih) !== false) {
    //  file_put_contents('xx.xx', $origih . "\n\n\n" . $newih);
    //}
    $templategame=str_replace($changeanyfrom,$changeanyto,str_replace($origih, explode('<table', str_replace('Drop Zone', '<span id=spancb>Canvas Below</span>&nbsp;&nbsp;<input onchange="document.getElementById(' . "'source'" . ').style.backgroundColor=this.value;" onblur="document.getElementById(' . "'source'" . ').style.backgroundColor=this.value;" type=color title="Pen colour" value="#f0f0f0" id=ddcolour></input>&nbsp;<input onchange="doverd=eval(this.value); doverc=doverd;" onblur="doverd=eval(this.value); doverc=doverd;" style=display:inline-block;width:60px; type=number title="Optional countdown in seconds before dragover takes effect from when you start dragging" id=dragoverdelay value=0 min=0></input><input style=display:none;background-color:yellow;width:60px; type=number title="Countdown in seconds before dragover takes effect from when you start dragging" id=dragovercountdown value=0 min=0></input>&nbsp;&nbsp;<input onblur=acrossf(this,' . $across . '); style=display:inline-block;width:60px;background-color:orange; type=number title="Number of squares across and down" id=numacross value=' . $across . ' min=10 max=499></input>&nbsp;&nbsp;<input onblur=fontweightf(this,' . $fontweight . '); style=display:inline-block;width:60px;background-color:lightblue; type=number title="Number of squares of brush stroke" id=numfontweight value=' . $fontweight . ' min=1 max=2></input>&nbsp;&nbsp;<button style=display:inline-block; title="Share via Email" id=semail onclick="doemail(' . "''" . ');">&#128231;</button>&nbsp;<button style=display:inline-block; title="Share via SMS" id=ssms onclick=dosms();>&#128223;</button>&nbsp;&nbsp;<button style="display:inline-block;border:4px outset green;background-color:lightgray;-webkit-appearance: none;-moz-appearance:none;appearance:none;height:35px;" id=jsundo data-type="button" data-ssn="0" data-value="Undo &#10060;" onclick=" undosnapshot(); "><u>U</u>ndo &#10060;</button>&nbsp;<button style="display:inline-block;border:4px outset green;background-color:lightgray;-webkit-appearance: none;-moz-appearance:none;appearance:none;height:35px;" id="jsredo" data-ssn="0" data-type="button" data-value="Redo &#10004;"" onclick=" redosnapshot(); "><u>R</u>edo &#10004;</button>', $origih))[0] . $newih, $templategame));
    if (isset($_GET['tableohprefix']) && 1 == 1) {
      $templategame=str_replace('v' . 'w;', '%' . ';', $templategame);
      $templategame=str_replace('v' . 'h;', '%' . ';', $templategame);
    }
    if (isset($_GET['tableohprefix']) && 4 == 41) {
      $templategame=str_replace('<bo' . 'dy ', '<bo' . 'dy style=width:' . explode(';', explode('width:', str_replace('+',' ',urldecode($_GET['tableohprefix'])))[1])[0] . '; ', $templategame);
    }
    if (isset($_GET['tableohprefix']) && 4 == 42) {
      $templategame=str_replace(':contain;', ':auto;', $templategame);
    }
    if (isset($_GET['tableohprefix']) && 4 == 4) {
      if (1 == 11) {
      $templategame=str_replace("<head>", "<head><meta id='myviewport' name='viewport' content='width=device-width, initial-scale=1, minimum-scale=0.1, maximum-scale=8, user-scalable=yes'  >", $templategame);
      }
      $templategame=str_replace('93%', '95vw', $templategame);
    }
    $templategame=str_replace('1px dotted green', '0px dotted transparent', $templategame); 
    $justforcolouringin=" var rectis=document.getElementById('mytable').getBoundingClientRect(); document.getElementById('mytable').width='' + rectis.height + 'px'; setTimeout(function(){ document.getElementsByTagName('h3')[0].style.display='none'; document.getElementsByTagName('h4')[0].style.display='none'; document.getElementsByTagName('h3')[1].style.display='none';  }, 7000); cibihcheck(); ";
    $templategame=str_replace('<body onload="', '<body onload="' . $justforcolouringin, $templategame); 
  }  
    //file_put_contents('xxx.html', $templategame);
  
  $templategame=str_replace('</h4>', '<input type=hidden id="callback" value="' . $callbackurl . '"></input></h4>', $templategame);

  $templategame=str_replace('</sc' . 'ript>', "\n" . " function getduresult(inr) {  document.getElementById('result').innerHTML=inr; onecheck();  return inr;   } " . "\n" . '</sc' . 'ript>', $templategame);

  //$templategame=str_replace('>Game</button>', '>Colouring In <font style=display:none;>Numbers Guessing Game</font> Game <font size=1>... drag pen over canvas to colour in</font></button>&nbsp;<iframe class="spag" scrolling="no" data-onload="iifopen(this);" id="cbi" frameborder="0" style="width:173px;height:218px;margin-top:-194px;" src="/HTMLCSS/client_browsing.htm?d=312160562686&amp;wording=Allimages%20images%2E%20"></iframe>&nbsp;<input onblur="if (this.value.trim().length > 0) { if (document.URL.indexOf(String.fromCharCode(63)) != -1) { location.href=document.URL.replace(' + "'.php','.php?imageurl=' + encodeURIComponent(this.value) + ''" + '); } else {  location.href=document.URL.replace(String.fromCharCode(63), ' + "'?imageurl=' + encodeURIComponent(this.value) + '&'" + ');   }" type=url placeholder="Optional linework background image URL" value=""></input><div id="doverlay"></div><div id="result" style=display:none;></div><div id="resultav" style=display:none;></div><div id="videoag" style=display:none;></div><input type=hidden id="audioname" style=display:none; value=""></input><input type=hidden id="outputname" style=display:none; value=""></input><input type=hidden id="cto" style=display:none; value=""></input><input type=hidden id="thewords" style=display:none; value=""></input><input type=hidden id="saysub" style=display:none; value=""></input>', $templategame);
  $templategame=str_replace('>Game</button>', '>Colouring In <font style=display:none;>Numbers Guessing Game</font> Game <br><font size=1>... drag <select onchange="document.getElementById(' . "'source'" . ').innerHTML=String.fromCodePoint(this.value);" id=pensel><option value=128396>pen &#128396;</option><option value=9999>pencil &#9999;</option><option value=128397>crayon &#128397;</option><option value=8598>totopleft &#8598;</option><option value=8599>totopright &#8599;</option>8624><option value=8624>topandright &#8624;</option><option value=8625>topandleft &#8625;</option><option value=8626>bottomandright &#8626;</option><option value=8627>bottomandleft &#8627;</option></select> over canvas to colour in</font></button>&nbsp;<span id=dimageb title="Image background settings or some text you want (where ~~ is line feed and {} encased CSS styling can be applied) ... click in pink to open window with some clipart colouring in ideas where Copy Image Address pasted into the Image URL textbox might be interesting for you" onclick="event.preventDefault(); woca=window.open(' . "'https://www.google.com/search?sca_esv=aa70acbcf6aac4c2&sca_upv=1&rlz=1C5CHFA_enAU973AU973&sxsrf=ACQVn0-MqfQVwZOqDS91Pot1E9D39q8Lyg:1712968623365&q=clip+art+linework+suiting+colouring+in&udm=2&source=univ&fir=gh0h5-oZtx___M%252CzQcS3q59Cyx7iM%252C_%253BpuKW1EldlM7spM%252C2l3v9-Tut9pnnM%252C_%253BHIGuP0JItVxEqM%252CRCw7hcXgARi6UM%252C_%253B_jAscIrC7E-1zM%252CIjNu9xj1ZLcxhM%252C_%253B-BKvL80Ovv4lzM%252C9kdy1MVEDMZMEM%252C_%253BAprlfAn4MgndFM%252CXilzPDMvdflqwM%252C_%253BYqCFEOovm8CXXM%252CMz1wIMhhp5At7M%252C_%253BG0zHmO34M00DYM%252C5Af1ulgnwMCIWM%252C_%253Bxzq7L7uZ1EcSyM%252CHPVvluHB2GlLyM%252C_%253BVbPdNDKgb2fUQM%252CGBsWFGjb2mW9sM%252C_&usg=AI4_-kQgjrNM4Kef_p1kQppck71FGlUm6A&biw=1417&bih=746&dpr=1','_blank','left=100,top=200,width=' + eval(-200 + screen.width) + ',height=' + eval(-400 + screen.height))" . ';" style="padding-left:3px;padding-right:3px;background-color:pink;border:1px dotted purple;display:inline;"><iframe class="spag" scrolling="no" data-onload="iifopen(this);" id="cbi" frameborder="0" style="width:173px;height:218px;margin-top:-194px;" src="/HTMLCSS/client_browsing.htm?d=312160562686&wording=Allimages%20images%2E%20"></iframe>&nbsp;<input onclick="event.stopPropagation();" id=inurl style=width:420px; onblur="if (mayberesultalready(this.value).trim().length > 0) { if (document.URL.indexOf(String.fromCharCode(63)) == -1) { location.href=document.URL.replace(' . "'.php','.php?imageurl=' + encodeURIComponent(this.value) + '&opacity=' + encodeURIComponent(document.getElementById('opmeter').value) + ''" . '); } else {  location.href=document.URL.replace(String.fromCharCode(63), ' . "'?imageurl=' + encodeURIComponent(this.value) + '&opacity=' + encodeURIComponent(document.getElementById('opmeter').value) + '&'" . ');  } }" type=url placeholder="Optional linework, postcard, other background image URL or text" value=""></input>&nbsp;<input onclick="event.stopPropagation();" type=number step=0.01 style=display:inline-block; title=Opacity id=opmeter value=1.00 min=0.00 max=1.00></input></span><div id="doverlay" style=display:none;></div><div id="result" style=display:none;></div><div id="resultav" style=display:none;></div><div id="videoag" style=display:none;></div><input type=hidden id="audioname" style=display:none; value=""></input><input type=hidden id="outputname" style=display:none; value=""></input><input type=hidden id="cto" style=display:none; value=""></input><input type=hidden id="thewords" style=display:none; value=""></input><input type=hidden id="saysub" style=display:none; value=""></input>', $templategame); //'', $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(', 2023<', ', 2023 ... thanks to <a target=_blank href=https://en.wikipedia.org/wiki/Street_suffix>https://en.wikipedia.org/wiki/Street_suffix</a><', $templategame);
  $templategame=str_replace('>Reset example<', ' style="display:none;">Reset example<', $templategame);
  
  if (1 == 2) {
  $templategame=str_replace('</b' . 'ody>', "<input type=hidden value=tab' . 'lece' . 'llb' . 'c></input></b" . "ody>", $templategame);
  }
  
  //echo $crandlist . "\n" . $thepsource . "\n" . $correctans . "\n";
  //exit;
  //echo $crandlist . "\n";
  //echo "" . $randlist[$correctans] . "\n" . $wikidescriptions[$randlist[$correctans]] . "\n" . $wikidesignations[$randlist[$correctans]];
  //exit;
  
  if ($randmode == 0) {  // designation up top and descriptions in drop zone  
    if (1 == 6) {
    $templategame=str_replace('>' . (1 + $correctans) . '<', ' style=text-align:center; data-answer="' . $theans . '">' . $theans . '<', $templategame);
    $templategame=str_replace('">' . $thepsource . '<', 'text-align:center;" data-answer="' . $theans. '">' . $thecluewording . '<', $templategame);
    for ($i=1; $i<=99; $i++) {
       if ((-1 + $i) != $correctans) {
    $templategame=str_replace('>' . $i . '</td', ' style=text-align:center; data-answer="">' . $i . '</td', $templategame);
       }
    }
    }
    $templategame=str_replace(' contenteditable=', ' data-contenteditable=', $templategame);
    echo $templategame;
  } else { // description up top and designations in drop zone
    if (1 == 6) {
    $templategame=str_replace('>' . (1 + $correctans) . '<', ' style=text-align:center; data-answer="' . $wikidesignations[$randlist[$correctans]] . '">' .$wikidesignations[$randlist[$correctans]] . '<', $templategame);
    $templategame=str_replace('">' . $thepsource . '<', 'text-align:center;" data-answer="' . $wikidesignations[$randlist[$correctans]] . '">' . $wikidescriptions[$randlist[$correctans]] . '<', $templategame);
    for ($i=1; $i<=99; $i++) {
       if ((-1 + $i) != $correctans) {
    $templategame=str_replace('>' . $i . '</td', ' style=text-align:center; data-answer="">' . mapittwo($wikidesignations[$randlist[-1 + $i]]) . '</td', $templategame);
       }
    }
    }
    $templategame=str_replace(' contenteditable=', ' data-contenteditable=', $templategame);
    echo $templategame;
  }
  

?>
