<?php
  // speech_supervisor.php
  // RJM Programming
  // May, 2018
  // Supervise some https://www.google.com/intl/en/chrome/demos/speech.html Google Speech to Text API interfacings

  if (!isset($_GET['i0']) && isset($_GET['fconcept'])) {   // Form findings
  $htmlis="<!doctype html>
<html>
<head>
<title>" . str_replace("Survey Survey","Survey",str_replace('+',' ',urldecode($_GET['fconcept'])) . " Survey") . " Form Questions</title>
<scr" . "ipt type='text/javascript'>
 function ask(inc) {
   var ans='';
   var emaillist='';
   var dl='';
   var ians=1;
   if (inc == '') {
     ans=prompt('What is your Survey Form Concept? (optionally suffix by a space then email list to have potential for those emailees to redistribute this survey further afield)', 'Survey');
     if (ans != null) {
       if (ans.split(' ').length > 1) {
         if (ans.split(' ')[eval(-1 + ans.split(' ').length)].indexOf('@') != -1) {
           emaillist=ans.split(' ')[eval(-1 + ans.split(' ').length)];
           document.getElementById('theto').value=emaillist;
           ans=ans.replace(' ' + emaillist,'');
           document.getElementById('thesubject').value=(ans + ' Survey').replace('Survey Survey','Survey') + ' Survey (ideally using Google Chrome web browser for audio input via microphone)';
         }
       }
       document.getElementById('myconcept').value=ans;
     }
   }
   while (ans != null) {
     ans=prompt('Separate a survey question ' + ians + ' from an optional prompt via ? ... Cancel finishes questions to ask ... eg. What is your favourite colour?Favourite colour', ''); 
     if (ans != null) {
       if (ans != '') {
       document.getElementById('myquestions').value+=dl + '\"' + ans + '\"';
       dl=',';
       ians++;
       }
     }
   }
   document.getElementById('mysf').click();
 }
</scr" . "ipt>
</head>
<body style=background-color:orange; onload=ask('" . str_replace('+',' ',urldecode($_GET['fconcept'])) . "');>
<h1>" . str_replace("Survey Survey","Survey",urldecode($_GET['fconcept']) . " Survey") . " Form Questions</h1> ... <a style=\"text-decoration:underline;cursor:pointer;\" onclick=\"window.open(document.URL,'_blank');\">another?</a><br><br>
<form id=myff method=POST action=https://www.rjmprogramming.com.au/PHP/speech_supervisor.php>
<!--form id=myff method=POST action=./speech_supervisor.php-->
<input id=mysf type=submit value=Submit style=display:none;></input>
<input type=hidden name=concept id=myconcept value=\"" . urldecode($_GET['fconcept']) . "\"></input>
<input type=hidden name=questions id=myquestions value=''></input>
<input type=hidden name=thesubject id=thesubject value=''></input>
<input type=hidden name=theto id=theto value=''></input>
</form>
</body>
</html>
";
  echo $htmlis;
  exit;

  } else if (isset($_POST['i0']) && isset($_POST['fconcept'])) {   // Form findings
  $htmlis="<!doctype html>
<html>
<head>
<title>" . str_replace("Survey Survey","Survey",str_replace('+',' ',urldecode($_POST['fconcept'])) . " Survey") . " Report</title>
<scr" . "ipt type='text/javascript'>
 var dul=document.URL.split('#')[0].split('?')[0];
 var argis='';
 function initemail() {
   document.getElementById('aemail').href=document.getElementById('aemail').href.replace(/\ /g,'%20').replace(/\+/g,'%20') + encodeURIComponent(dul + '?fconcept=') + encodeURIComponent('" . str_replace("'","' + String.fromCharCode(39) + '",str_replace("Survey Survey","Survey",($_POST['fconcept']) . " Survey")) . " Report&" . "').replace(/\%20/g,'+');  
   fixemail(); 
 }
 function fixemail() {
 
   var prerest=document.getElementById('aemail').href.split('?subject=')[1].split('&body=')[0];
   var rest=document.getElementById('aemail').href.split('&body=')[1].split('php')[1];
   document.getElementById('aemail').href=document.getElementById('aemail').href.split('?subject=')[0] + '?subject=' + (prerest) + '&body=' + encodeURIComponent('https://www.rjmprogramming.com.au/PHP/speech_supervisor.php') + (rest).replace(/\%20/g,'+');
 }
</scr" . "ipt>
</head>
<body style=background-color:orange; onload='initemail();'>
<h1>" . str_replace("Survey Survey","Survey",str_replace('+',' ',urldecode($_POST['fconcept'])) . " Survey") . " Report</h1> ... <a style=\"text-decoration:underline;cursor:pointer;\" onclick=\"window.open(document.URL.split('#')[0].split('?')[0] + '?fconcept=','_blank');\">another?</a>&nbsp;<a id=aemail href=\"mailto:?subject=" . str_replace("+","%20",urlencode(str_replace("Survey Survey","Survey",urldecode($_GET['fconcept']) . " Survey"))) . "%20Report%20(best%20used%20in%20Google%20Chrome%20web%20browser)&body=\">email?</a><br><br>
</body>
</html>
";
  $ival=0;
  if (isset($_POST['s' . $ival])) {
    $htmlis=str_replace("</body>", "<table cellspacing=2 cellpadding=10 border=40><tbody><tr><th>Label</th><th>Value</th></tr></tbody></table></body>", $htmlis);
  } else {
    $htmlis=str_replace("</body>", "<table cellspacing=2 cellpadding=10 border=40><tbody><tr><th>Value</th></tr></tbody></table></body>", $htmlis);
  }
  while (isset($_POST['i' . $ival])) {
    if (isset($_POST['s' . $ival])) {
      $htmlis=str_replace("</tbody>", "<tr><td>" . urldecode($_POST['s' . $ival]) . "</td><td>" . urldecode($_POST['i' . $ival]) . "</td></tr></tbody>", $htmlis);
      $htmlis=str_replace("function fixemail() {", "function fixemail() { document.getElementById('aemail').href+=encodeURIComponent('s" . $ival . "=" . str_replace("'","' + String.fromCharCode(39) + '",($_POST['s' . $ival])) . "&'); ", $htmlis);
      $htmlis=str_replace("function fixemail() {", "function fixemail() { document.getElementById('aemail').href+=encodeURIComponent('i" . $ival . "=" . str_replace("'","' + String.fromCharCode(39) + '",($_POST['i' . $ival])) . "&'); ", $htmlis);
    } else {
      $htmlis=str_replace("</tbody>", "<tr><td>" . urldecode($_POST['i' . $ival]) . "</td></tr></tbody>", $htmlis);
      $htmlis=str_replace("function fixemail() {", "function fixemail() { document.getElementById('aemail').href+=encodeURIComponent('i" . $ival . "=" . str_replace("'","' + String.fromCharCode(39) + '",($_POST['i' . $ival])) . "&'); ", $htmlis);
    }
    $ival++;
  }
  echo $htmlis;
  exit;


  } else if (isset($_GET['i0']) && isset($_GET['fconcept'])) {   // Form findings
  $htmlis="<!doctype html>
<html>
<head>
<title>" . str_replace("Survey Survey","Survey",str_replace('+',' ',urldecode($_GET['fconcept'])) . " Survey") . " Report</title>
<scr" . "ipt type='text/javascript'>
 var dul=document.URL.split('#')[0].split('?')[0];
 var argis='';
 function initemail() {
   document.getElementById('aemail').href=document.getElementById('aemail').href.replace(/\ /g,'%20').replace(/\+/g,'%20'8/*-) + encodeURIComponent(dul + '?fconcept=') + encodeURIComponent('" . str_replace("'","' + String.fromCharCode(39) + '",str_replace("Survey Survey","Survey",($_GET['fconcept']) . " Survey")) . " Report&" . "').replace(/\%20/g,'+');  
   fixemail(); 
 }
 function fixemail() {
 
   var prerest=document.getElementById('aemail').href.split('?subject=')[1].split('&body=')[0];
   var rest=document.getElementById('aemail').href.split('&body=')[1].split('php')[1];
   document.getElementById('aemail').href=document.getElementById('aemail').href.split('?subject=')[0] + '?subject=' + (prerest) + '&body=' + encodeURIComponent('https://www.rjmprogramming.com.au/PHP/speech_supervisor.php') + (rest).replace(/\%20/g,'+');
 }
</scr" . "ipt>
</head>
<body style=background-color:orange; onload='initemail();'>
<h1>" . str_replace("Survey Survey","Survey",str_replace('+',' ',urldecode($_GET['fconcept'])) . " Survey") . " Report</h1> ... <a style=\"text-decoration:underline;cursor:pointer;\" onclick=\"window.open(document.URL.split('#')[0].split('?')[0] + '?fconcept=','_blank');\">another?</a>&nbsp;<a id=aemail href=\"mailto:?subject=" . str_replace("+","%20",urlencode(str_replace("Survey Survey","Survey",urldecode($_GET['fconcept']) . " Survey"))) . "%20Report%20(best%20used%20in%20Google%20Chrome%20web%20browser)&body=\">email?</a><br><br>
</body>
</html>
";
  $ival=0;
  if (isset($_GET['s' . $ival])) {
    $htmlis=str_replace("</body>", "<table cellspacing=2 cellpadding=10 border=40><tbody><tr><th>Label</th><th>Value</th></tr></tbody></table></body>", $htmlis);
  } else {
    $htmlis=str_replace("</body>", "<table cellspacing=2 cellpadding=10 border=40><tbody><tr><th>Value</th></tr></tbody></table></body>", $htmlis);
  }
  while (isset($_GET['i' . $ival])) {
    if (isset($_GET['s' . $ival])) {
      $htmlis=str_replace("</tbody>", "<tr><td>" . urldecode($_GET['s' . $ival]) . "</td><td>" . urldecode($_GET['i' . $ival]) . "</td></tr></tbody>", $htmlis);
      $htmlis=str_replace("function fixemail() {", "function fixemail() { document.getElementById('aemail').href+=encodeURIComponent('s" . $ival . "=" . str_replace("'","' + String.fromCharCode(39) + '",($_GET['s' . $ival])) . "&'); ", $htmlis);
      $htmlis=str_replace("function fixemail() {", "function fixemail() { document.getElementById('aemail').href+=encodeURIComponent('i" . $ival . "=" . str_replace("'","' + String.fromCharCode(39) + '",($_GET['i' . $ival])) . "&'); ", $htmlis);
    } else {
      $htmlis=str_replace("</tbody>", "<tr><td>" . urldecode($_GET['i' . $ival]) . "</td></tr></tbody>", $htmlis);
      $htmlis=str_replace("function fixemail() {", "function fixemail() { document.getElementById('aemail').href+=encodeURIComponent('i" . $ival . "=" . str_replace("'","' + String.fromCharCode(39) + '",($_GET['i' . $ival])) . "&'); ", $htmlis);
    }
    $ival++;
  }
  echo $htmlis;
  exit;


  } else {
  if (isset($_POST['theto'])) {
                if (strpos(urldecode($_POST['theto']), "@") !== false) { // && strpos($htmlis, "</html>") !== false) {


  $htmlis="<!doctype html>
<html>
<head>
<title>" . str_replace("Survey Survey","Survey",str_replace('+',' ',urldecode($_POST['concept'])) . " Survey") . " Form Questions</title>
</head>
<body onload=\" document.getElementById('mysf').click(); \">
<h1>" . str_replace("Survey Survey","Survey",str_replace("+"," ",urldecode($_POST['concept'])) . " Survey") . " Form Questions</h1> ... <a style=\"text-decoration:underline;cursor:pointer;\" onclick=\"window.open(document.URL,'_blank');\">another?</a><br><br>
<form id=myff method=POST action=https://www.rjmprogramming.com.au/PHP/speech_supervisor.php>
<input id=mysf type=submit value=Submit style=display:none;></input>
<input type=hidden name=concept id=myconcept value=\"" . str_replace("+"," ",urldecode($_POST['concept'])) . "\"></input>
<input type=hidden name=questions id=myquestions value='" . str_replace("'","' + String.fromCharCode(39) + '",str_replace("+"," ",urldecode($_POST['questions']))) . "'></input>
<input type=hidden name=thesubject id=thesubject value=''></input>
<input type=hidden name=theto id=theto value=''></input>
</form>
</body>
</html>
";

                $eol = PHP_EOL;
                $header = 'From: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
                $header .= 'Reply-To: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
                if (isset($_POST['thecc'])) {
                $header .= 'CC: ' . urldecode($_POST['thecc']) . $eol;
                }
                if (isset($_POST['thebcc'])) {
                $header .= 'BCC: ' . urldecode($_POST['thebcc']) . $eol;
                }

                // attachment
                $filename=str_replace("@", "_", str_replace(".", "_", urldecode($_POST['thesubject']) . urldecode($_POST['theto']))) . ".html";
                $content = chunk_split(base64_encode(str_replace("%2b","+",$htmlis)));
                
                $message="Please download attached webpage. ";
                if (sizeof(explode("\n",urldecode($_POST['thesubject']))) > 1) {
                  $message.=str_replace("\r","  ",str_replace("\n","  ",str_replace(explode("\r",explode("\n",urldecode($_POST['thesubject']))[0])[0], "", urldecode($_POST['subject']))));
                }

                // a random hash will be necessary to send mixed content
                $uid = md5(time());
                
                $header .= "MIME-Version: 1.0\r\n";
                $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
                $header .= "This is a multi-part message in MIME format.\r\n";
                $header .= "--".$uid."\r\n";
                $header .= "Content-type:text/html; charset=iso-8859-1\r\n";
                $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
                $header .= $message."\r\n\r\n";

                $header .= "--".$uid."\r\n";
                $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
                $header .= "Content-Transfer-Encoding: base64\r\n";
                $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
                $header .= $content."\r\n\r\n";
                $header .= "--".$uid."--";
                
                try {
                mail(urldecode($_POST['theto']), explode("\r",explode("\n",urldecode($_POST['thesubject']))[0])[0], "", $header);
                //$htmlis=str_replace("inite" . "mail();"," alert('Email sent okay.'); inite" . "mail();", $htmlis);
                } catch (Exception $ee) {
                //$htmlis=str_replace("inite" . "mail();"," alert('Email not sent.');  inite" . "mail();", $htmlis);
                }
                }
  }
  $ifmaybe="<iframe onload='checki(this,2);' style='width:100%;height:95vh;' src='speech_idea.php?ifno=2'></iframe>";
  if (isset($_GET['mode'])) {
    if ($_GET['mode'] == "3") {
        $ifmaybe="<iframe onload='cb(this);' src='//www.rjmprogramming.com.au/HTMLCSS/ConfirmWindow/animal_categorization.html' style='width:100%;height:95vh;'></iframe>";
    }
  }
  $qone="Quiz";
  $qlabels='"' . $qone . '","Tongue Twisters","Haiku","Animal Categorization","Survey"';
  $qarrays='"questions","tongue_twisters","haiku","animal_categorization","survey"';
  $qdelims='"?","~","`","`","?"';
  $qcols='"yellow","lightgreen","lightblue","pink","orange"';
  $qforce="";
  $qis='"What is the name that we give to the meat we get from pigs?pork",
                       "What is the name of the metal alloy we get from zinc and copper?bronze",
                       "What is the capital of Australia?Canberra",
                       "Who wrote The Tale of Two Cities?Dickens",
                       "How many legs does the Legs of Man have?three",
                       "How many tails does a Manx cat have?none",
                       "How many teeth does an aardvark have?none",
                       "Which sea creature has three hearts?octopus",
                       "Which instrument has forty-seven strings and seven pedals?harp",
                       "In the traditional rhyme, how many mice were blind?three",
                       "How many pedals do most modern pianos have?three"';
  $qlast=0;
  if (isset($_GET['questions'])) {
    $qis=urldecode($_GET['questions']);
  } else if (isset($_POST['questions'])) { 
    $qis=urldecode($_POST['questions']);
  }
  if (isset($_GET['concept'])) {
    $qone=urldecode($_GET['concept']);
    $qlabels='"' . $qone . '"';
    $qarrays='"questions"';
    $qdelims='"?"';
    $qcols='"pink"';
    $qforce="0; /" . "/ ";
    $qins="<input type=hidden name=fconcept value=\"" . $qone . "\"></input>";
    if (strpos(explode('",', $qis)[0], "?") === false) {
    $qins.="<input type=hidden name=s0 value=\"" . substr(explode('",', ($qis . ","))[0],1) . "\"></input><span title='none' id=s0 style=display:none;>" . substr(explode('",', ($qis . ","))[0],1) . "</span> ";
    } else if (strlen(explode("?", explode('",', ($qis . ","))[0])[0] . "?") == strlen(explode('",', $qis)[0])) {
    $qins.="<input type=hidden name=s0 value=\"" . substr(explode("?", explode('",', ($qis . ","))[0])[0],1) . "\"></input><span title='none' id=s0 style=display:none;>" . str_replace('?','',substr(explode('",', ($qis . ","))[0],1)) . "</span> ";
    } else {
    $qins.="<input type=hidden name=s0 value=\"" . substr(explode("?", explode('",', ($qis . ","))[0])[1],0) . "\"></input><span title='inline' id=s0>" .  substr(explode("?", explode('",', ($qis . ","))[0])[1],0) . "</span> ";
    }
    $qins.="<input type=text name=i0 id=i0 value=''></input><br>";
    for ($ii=1; $ii<sizeof(explode('",', $qis)); $ii++) {
      if (strpos(explode('",', $qis)[$ii], "?") === false) {
      $qins.="<input type=hidden name=s" . $ii . " value=\"" . substr(explode('",', ($qis . ","))[$ii],1) . "\"></input><span title='none' id=s" . $ii . " style=display:none;>" . substr(explode('",', ($qis . ","))[$ii],1) . "</span> ";
      } else if (strlen(explode("?", explode('",', ($qis . ","))[$ii])[0] . "?") == strlen(explode('",', $qis)[$ii])) {
      $qins.="<input type=hidden name=s" . $ii . " value=\"" . substr(explode("?", explode('",', ($qis . ","))[$ii])[0],1) . "\"></input><span title='none' id=s" . $ii . " style=display:none;>" . str_replace('?','',substr(explode('",', ($qis . ","))[$ii],1)) . "</span> ";
      } else {
      $qins.="<input type=hidden name=s" . $ii . " value=\"" . substr(explode("?", explode('",', ($qis . ","))[$ii])[1],0) . "\"></input><span title='inline' id=s" . $ii . " style=display:none;>" .  substr(explode("?", explode('",', ($qis . ","))[$ii])[1],0) . "</span> ";
      }
      $qins.="<input style=display:none; type=text name=i" . $ii . " id=i" . $ii . " value=''></input><br>";
      $qlast=$ii;
    }
    $ifmaybe="<h1>" . $qone . " Form</h1><form id=myf method=POST action=https://www.rjmprogramming.com.au/PHP/speech_supervisor.php>" . $qins . "<br><input id=sdata type=submit value='Submit Report' style=display:none;background-color:orange;></input></form>";
    //$ifmaybe="<h1>" . $qone . " Form</h1><form id=myf method=POST action=./speech_supervisor.php>" . $qins . "<br><input id=sdata type=submit value='Submit Report' style=display:none;background-color:orange;></input></form>";
  } else if (isset($_POST['concept'])) { 
    $qone=urldecode($_POST['concept']);
    $qlabels='"' . $qone . '"';
    $qarrays='"questions"';
    $qdelims='"?"';
    $qcols='"pink"';
    $qforce="0; /" . "/ ";
    $qins="<input type=hidden name=fconcept value=\"" . $qone . "\"></input>";
    if (strpos(explode('",', $qis)[0], "?") === false) {
    $qins.="<input type=hidden name=s0 value=\"" . substr(explode('",', ($qis . ","))[0],1) . "\"></input><span title='none' id=s0 style=display:none;>" . substr(explode('",', ($qis . ","))[0],1) . "</span> ";
    } else if (strlen(explode("?", explode('",', ($qis . ","))[0])[0] . "?") == strlen(explode('",', $qis)[0])) {
    $qins.="<input type=hidden name=s0 value=\"" . substr(explode("?", explode('",', ($qis . ","))[0])[0],1) . "\"></input><span title='none' id=s0 style=display:none;>" . str_replace('?','',substr(explode('",', ($qis . ","))[0],1)) . "</span> ";
    } else {
    $qins.="<input type=hidden name=s0 value=\"" . substr(explode("?", explode('",', ($qis . ","))[0])[1],0) . "\"></input><span title='inline' id=s0>" .  substr(explode("?", explode('",', ($qis . ","))[0])[1],0) . "</span> ";
    }
    $qins.="<input type=text name=i0 id=i0 value=''></input><br>";
    for ($ii=1; $ii<sizeof(explode('",', $qis)); $ii++) {
      if (strpos(explode('",', $qis)[$ii], "?") === false) {
      $qins.="<input type=hidden name=s" . $ii . " value=\"" . substr(explode('",', ($qis . ","))[$ii],1) . "\"></input><span title='none' id=s" . $ii . " style=display:none;>" . substr(explode('",', ($qis . ","))[$ii],1) . "</span> ";
      } else if (strlen(explode("?", explode('",', ($qis . ","))[$ii])[0] . "?") == strlen(explode('",', $qis)[$ii])) {
      $qins.="<input type=hidden name=s" . $ii . " value=\"" . substr(explode("?", explode('",', ($qis . ","))[$ii])[0],1) . "\"></input><span title='none' id=s" . $ii . " style=display:none;>" . str_replace('?','',substr(explode('",', ($qis . ","))[$ii],1)) . "</span> ";
      } else {
      $qins.="<input type=hidden name=s" . $ii . " value=\"" . substr(explode("?", explode('",', ($qis . ","))[$ii])[1],0) . "\"></input><span title='inline' id=s" . $ii . " style=display:none;>" .  substr(explode("?", explode('",', ($qis . ","))[$ii])[1],0) . "</span> ";
      }
      $qins.="<input style=display:none; type=text name=i" . $ii . " id=i" . $ii . " value=''></input><br>";
      $qlast=$ii;
    }
    $ifmaybe="<h1>" . $qone . " Form</h1><form id=myf method=POST action=https://www.rjmprogramming.com.au/PHP/speech_supervisor.php>" . $qins . "<br><input id=sdata type=submit value='Submit Report' style=display:none;background-color:orange;></input></form>";
    //$ifmaybe="<h1>" . $qone . " Form</h1><form id=myf method=POST action=./speech_supervisor.php>" . $qins . "<br><input id=sdata type=submit value='Submit Report' style=display:none;background-color:orange;></input></form>";
  }
  }
?>
<!DOCTYPE html>
<html>
<head>
<title>Speaking Quiz (at least on Google Chrome) - RJM Programming - May, 2018 ... thanks to https://www.google.com/intl/en/chrome/demos/speech.html for Speech to Text</title>
<script type='text/javascript'>
        var mode=<?php echo $qforce; ?>location.search.split('mode=')[1] ? eval(decodeURIComponent(location.search.split('mode=')[1].split('&')[0])) : 0;
        var modes=[<?php echo $qlabels; ?>];
        var arraynames=[<?php echo $qarrays; ?>];
        var delims=[<?php echo $qdelims; ?>];
        var bcols=[<?php echo $qcols; ?>];
        var isq=0;
        var answer="";
        var sofar=["",""];
        var scores=[0,0];
        var sofarb=[null,null];
        var resultso=[null,null];
        var questions=[<?php echo $qis; ?>];
        
        var fsp=null, isp=null;
        
        var lasts='';
        
        var survey=[];
        
        var animal_categorization=["Hear you have an unknown animal.  Does your animal have a backbone?"];
                      
        // Thanks to http://www.uebersetzung.at/twister/en.htm below
        var tongue_twisters=["Peter Piper picked a peck of pickled peppers. A peck of pickled peppers Peter Piper picked. If Peter Piper picked a peck of pickled peppers, Where's the peck of pickled peppers Peter Piper picked?",
                       "I saw Susie sitting in a shoe shine shop.  Where she sits she shines, and where she shines she sits.",
                       "How many boards Could the Mongols hoard If the Mongol hordes got bored?",
                       "How can a clam cram in a clean cream can?",
                       "Send toast to ten tense stout saints' ten tall tents.",
                       "Denise sees the fleece, Denise sees the fleas. At least Denise could sneeze and feed and freeze the fleas.",
                       "Coy knows pseudonoise codes.",
                       "Sheena leads, Sheila needs.",
                       "The thirty-three thieves thought that they thrilled the throne throughout Thursday.",
                       "Something in a thirty-acre thermal thicket of thorns and thistles thumped and thundered threatening the three-D thoughts of Matthew the thug - although, theatrically, it was only the thirteen-thousand thistles and thorns through the underneath of his thigh that the thirty year old thug thought of that morning.",
                       "Can you can a can as a canner can can a can?",
                       "Seth at Sainsbury's sells thick socks.",
                       "You cuss, I cuss, we all cuss, for asparagus!",
                       "Roberta ran rings around the Roman ruins.",
                       "Clean clams crammed in clean cans.",
                       "Six sick hicks nick six slick bricks with picks and sticks.",
                       "I wish to wish the wish you wish to wish, but if you wish the wish the witch wishes, I won't wish the wish you wish to wish.",
                       "Stupid superstition!",
                       "There was a fisherman named Fisher who fished for some fish in a fissure. Till a fish with a grin, pulled the fisherman in. Now they're fishing the fissure for Fisher.",
                       "World Wide Web",
                       "Picky people pick Peter Pan Peanut-Butter, 'tis the peanut-butter picky people pick.",
                       "If Stu chews shoes, should Stu choose the shoes he chews?",
                       "Luke Luck likes lakes. Luke's duck likes lakes. Luke Luck licks lakes. Luck's duck licks lakes. Duck takes licks in lakes Luke Luck likes. Luke Luck takes licks in lakes duck likes."
                      ];
            
        // Thanks to https://en.wikipedia.org/wiki/Haiku_in_English below              
        var haiku=["Snow in my shoe <br>Abandoned <br>Sparrow's nest",
                   "Whitecaps on the bay: <br>A broken signboard banging <br>In the April wind.",
                   "lily: <br>out of the water <br>out of itself",
                   "bass <br>picking bugs <br>off the moon",
                   "an aging willow-- <br>it's image unsteady <br>in the flowing stream",
                   "Just friends: <br>he watches my gauze dress <br>blowing on the line.",
                   "Little spider, <br>will you outlive <br>me?",
                   "she watches <br>satisfied after love <br>he lies <br>looking up at nothing",
                   "beneath <br>leaf mold <br>stone <br>cool <br>stone",
                   "meteor shower... <br>a gentle wave <br>wets our sandals"
                   ];
                      
        function complexscore(inst) {
          var versusw=answer.toLowerCase().replace(/\<br\>/g,' ').replace(/\.\.\./g,' ').replace(/-/g,'').replace(/\"/g,'').replace(/\'/g,'').replace(/\./g,' ').replace(/\:/g,' ').replace(/\;/g,' ').replace(/\,/g,' ').replace(/\!/g,' ').replace(/\?/g,' ').replace(/\ \ /g,' ').replace(/\ \ /g,' ').replace(/\ \ /g,' ').split(' ');
          var ourw=inst.toLowerCase().replace(/\<br\>/g,' ').replace(/\.\.\./g,' ').replace(/-/g,'').replace(/\"/g,'').replace(/\'/g,'').replace(/\./g,' ').replace(/\:/g,' ').replace(/\;/g,' ').replace(/\,/g,' ').replace(/\!/g,' ').replace(/\?/g,' ').replace(/\ \ /g,' ').replace(/\ \ /g,' ').replace(/\ \ /g,' ').split(' ');
          var pscore=0, lastf=-1, ilastf, jlastf=-1;
          for (var iwords=0; iwords<versusw.length; iwords++) {
            jlastf=lastf;
            for (ilastf=eval(1 + lastf); ilastf<ourw.length; ilastf++) {
              if (jlastf == lastf && versusw[iwords] == ourw[ilastf]) {
                lastf=ilastf;
                pscore+=versusw[iwords].length;
                //alert(versusw.length + "vs" + ourw.length + " ... " + iwords + ": found " + versusw[iwords]);
              }
            }
            if (jlastf == lastf) {
              pscore-=versusw[iwords].length;
              //alert(versusw.length + "vs" + ourw.length + " ... " + iwords + ": did not find " + versusw[iwords]);
            }
          }
          return pscore;
        }
                      
        function dds(qwhat) {
          var selbit="<select id=selbit onchange=' location.href=document.URL.split(\"#\")[0].split(\"?\")[0] + \"?mode=\" + this.value; '><option value=0>" + modes[0] + "</option></select>";
          var ia=1;
          if (mode != 0) {
            eval("ia=" + arraynames[mode] + ".length");
            if (ia == 0) {
            location.href=document.URL.split('#')[0].split('?')[0] + '?fconcept=';
            return '';
            } else {
            eval(arraynames[0] + "=" + arraynames[mode]);
            document.getElementById('tdm').style.backgroundColor=bcols[mode];
            }
          }
          for (var iselbit=1; iselbit<modes.length; iselbit++) {
           if (mode == iselbit) {
            selbit=selbit.replace("</select>", "<option value=" + iselbit + " selected>" + modes[iselbit] + "</option></select>");
           } else {
            selbit=selbit.replace("</select>", "<option value=" + iselbit + ">" + modes[iselbit] + "</option></select>");
           }
          }
          return qwhat.replace('<?php echo str_replace("'","' + String.fromCharCode(39) + '",$qone); ?>',selbit);
        }
                      
        function pdidclick(iframen,cwhat,cwhatid,cwhattitle,cwhatvalue) {
          if (sofarb[eval(-1 + iframen)] == null) {
            sofarb[eval(-1 + iframen)]=cwhat;
          }
        }

        function athentwo() {
          if (document.getElementById('divac').innerHTML != ' ') {
            sofarb[0].click();
          }
        }
        
        function athen() {
          if (sofarb[0]) { 
           if (lasts != '') {
            if (document.getElementById('divac').innerHTML != ' ') {
            sofarb[0].click();
            if (fsp) fsp.innerHTML='';
            if (isp) isp.innerHTML='';
            }
            //alert(lasts);
            setTimeout(athentwo,2000);
            lasts='';
           }
          }
        }
        
        function pdidchange(iframen,sfinal) {
         var ioff=0;
         if (mode == 3) {
          document.getElementById('divac').innerHTML=sfinal.toLowerCase().split(' ')[eval(-1 + sfinal.toLowerCase().split(' ').length)];
          lasts=sfinal;
          setTimeout(athen,2000);
         } else {
         if (iframen <= 0) {
          if (sfinal != '1' && sfinal != '2' && sfinal != '') {
          if (mode > 0) {
          ioff=complexscore(sfinal.replace('1','').replace('2','').replace('3','three'));
          } else {
<?php
  if (isset($_GET['concept']) || isset($_POST['concept'])) {
       echo "\n document.getElementById('i' + eval(-1 + Math.abs(isq))).value=sfinal.split('<span')[0]; \n";
       echo "\n sofar[0]=''; \n";
       echo "\n sofar[1]=''; \n";
       echo "\n pickq(); \n";
       echo "\n return; \n";
  }
?>
          if (sfinal.toLowerCase().indexOf(answer.replace('1','').replace('2','').replace('3','three').toLowerCase()) != -1) {
            ioff=1;
          } else {
            ioff=-1;
          }
          }
          if (sfinal.indexOf('1') != -1) {
            scores[0]+=ioff;
            if (sofarb[0]) sofarb[0].click();
          } else if (sfinal.indexOf('2') != -1) {
            scores[1]+=ioff;
            if (sofarb[1]) sofarb[1].click();
          } else {
            var ansis=confirm('Are you player 2 on the right?');
            if (ansis == true) {
            scores[1]+=ioff;
            if (sofarb[1]) sofarb[1].click();
            } else {
            scores[0]+=ioff;
            if (sofarb[0]) sofarb[0].click();
            }
          }
          document.getElementById('score').innerHTML='Score: ' + scores[0] + '/' + scores[1];
          sofar[0]='';
          sofar[1]='';
          pickq();
          }
        } else {
         if (sofar[eval(-1 + iframen)] == '') {
          //alert('' + iframen + ' said ' + sfinal);
          if (mode > 0) {
          scores[eval(-1 + iframen)]+=complexscore(sfinal.replace('1','').replace('2','').replace('3','three'));
          } else {
<?php
  if (isset($_GET['concept']) || isset($_POST['concept'])) {
       echo "\n document.getElementById('i' + eval(-1 + Math.abs(isq))).value=sfinal.split('<span')[0]; \n";
       echo "\n sofarb[eval(-1 + iframen)].click(); \n";
       echo "\n sofar[eval(-1 + iframen)]=''; \n";
       echo "\n pickq(); \n";
       echo "\n return; \n";
  }
?>
          if (sfinal.toLowerCase().indexOf(answer.replace('1','').replace('2','').replace('3','three').toLowerCase()) != -1) {
            scores[eval(-1 + iframen)]++;
          } else {
            scores[eval(-1 + iframen)]--;
          }
          }
          document.getElementById('score').innerHTML='Score: ' + scores[0] + '/' + scores[1];
          sofarb[eval(-1 + iframen)].click();
          sofar[eval(-1 + iframen)]='';
          pickq();
         } else {
          //alert('' + iframen + ' just said ' + sfinal.replace(sofar[eval(-1 + iframen)],''));
          if (sfinal.toLowerCase().indexOf(answer.replace('1','').replace('2','').replace('3','three').toLowerCase()) != -1) {
            scores[eval(-1 + iframen)]++;
          } else {
            scores[eval(-1 + iframen)]--;
          }
          document.getElementById('score').innerHTML='Score: ' + scores[0] + '/' + scores[1];
          sofarb[eval(-1 + iframen)].click();
          sofar[eval(-1 + iframen)]='';
          pickq();
         }
         }
         }
        }
        
        function okp(e) {
			var characterCode; //literal character code will be stored in this variable

			if (e && e.which){ //if which property of event object is supported (NN4)
				e = e;
				characterCode = e.which; //character code is contained in NN4's which property
			} else {
				e = event;
				characterCode = e.keyCode; //character code is contained in IE's keyCode property
			}
 			if (characterCode == 49) {  // 1
 			  if (document.getElementById('kb').value.length <= 1) document.getElementById('kb').value='';
			  sofarb[0].click();
			} else if (characterCode == 50) {  // 2
 			  if (document.getElementById('kb').value.length <= 1) document.getElementById('kb').value='';
			  sofarb[1].click();
			}
        }

 function checki(iois, iw) {
  if (iois != null) {
    var aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto != null) {
     if (aconto.document) { aconto = aconto.document; }
     if (aconto.body != null) {
       if (aconto.getElementById('start_button')) {
         sofarb[eval(-1 + iw)]=aconto.getElementById('start_button');
         if (mode == 3 && iw == 1) {
           sofarb[eval(-1 + iw)].click();
           fsp=aconto.getElementById('final_span');
           isp=aconto.getElementById('interim_span');
         }
       }
       if (aconto.getElementById('copy')) {
         aconto.getElementById('copy').style.display='none';
       }
       if (aconto.getElementById('email_info')) {
         aconto.getElementById('email_info').style.display='none';
       }
       if (aconto.getElementById('results')) {
<?php
  if (isset($_GET['concept']) || isset($_POST['concept'])) {
           echo "\n aconto.getElementById('results').setAttribute('contenteditable', 'true'); \n";
  }
?>
       }
       if (aconto.getElementById('info_upgrade')) {
         if (aconto.getElementById('info_upgrade').innerHTML.indexOf('not supported') != -1) {
          if (('' + aconto.getElementById('info_upgrade').style.display).toLowerCase() != 'none') {
           if (document.getElementById('klr').innerHTML.indexOf('ou can type answer into left or right boxes.') == -1) {
             document.getElementById('klr').innerHTML+='<br>You can type answer into left or right boxes.<br>';
           }
           aconto.getElementById('results').setAttribute('contenteditable', 'true');
           resultso[eval(-1 + iw)]=aconto.getElementById('results');
          } else {
           document.getElementById('preq').innerHTML=dds('Speaking <?php echo str_replace("'","' + String.fromCharCode(39) + '",$qone); ?>');
          }
         } else {
          document.getElementById('preq').innerHTML=dds('Speaking <?php echo str_replace("'","' + String.fromCharCode(39) + '",$qone); ?>');
         }
       }
     }
    }
  }
 }
 
 function atcb() {
            if (document.getElementById('start_button')) {
             document.getElementById('start_button').click();
           }
}
 
 function cb(ot) {
   setTimeout(atcb,6000);
 }
 
 function andthen() {
   sofarb[0].click();
 }
 
 function modethree(inx) {
   if (mode == 3 && inx != '?') {
     return '<a onclick=" if (fsp) { fsp.innerHTML = ' + "'" + 'yes' + "'" + '; pdidchange(0,' + "'" + 'yes' + "'" + '); } " style=text-decoration:none;cursor:pointer; title=yes>' + inx + '</a>';
   } else if (mode == 3) {
     return '<a onclick=" if (fsp) { fsp.innerHTML = ' + "'" + 'no' + "'" + '; pdidchange(0,' + "'" + 'no' + "'" + ');  } " style=text-decoration:none;cursor:pointer; title=no>' + inx + '</a>';
   } else {
     return inx;
   }
 }
 
 function pickq() {
<?php
  if (isset($_GET['concept']) || isset($_POST['concept'])) {
   echo "\n  document.getElementById('p12').style.display='none'; \n   document.getElementById('klr').style.display='none'; \n   document.getElementById('score').style.display='none'; \n  document.getElementById('kb').style.display='none'; \n if (isq < 0) { isq=Math.abs(isq);  if (isq < " . $qlast . ") {  document.getElementById('s' + eval(-1 + isq)).style.display='none'; document.getElementById('i' + eval(-1 + isq)).style.display='none';  document.getElementById('s' + eval(0 + isq)).style.display=document.getElementById('s' + eval(0 + isq)).title; document.getElementById('i' + eval(0 + isq)).style.display='inline';   } else if (isq == " . $qlast . ") { for (var iqw=0; iqw<=" . $qlast . "; iqw++) {  document.getElementById('s' + iqw).style.display='inline';   document.getElementById('i' + iqw).style.display='inline';  } document.getElementById('sdata').style.display='block';   } } \n";
  } else {
   echo "\n  if (mode == 3) {  document.getElementById('p12').style.display='none'; \n   document.getElementById('klr').style.display='none'; \n   document.getElementById('score').style.display='none'; \n  document.getElementById('kb').style.display='none'; \n   } \n if (isq < 0) { isq=Math.floor(Math.random() * questions.length); } \n";
  }
?>
   if (resultso[0] != null) {
     resultso[0].innerHTML='';
   }
   if (resultso[1] != null) {
     resultso[1].innerHTML='';
   }
   if (questions.length > isq) {
   if (questions[isq].indexOf(delims[mode]) != -1) {
     document.getElementById('sq').innerHTML='<b>' + modethree(questions[isq].split('?')[0]) + modethree('?') + '</b><br><br>';
     answer=questions[isq].split('?')[1];
   } else {
     answer=questions[isq].split(delims[mode])[0];
     document.getElementById('sq').innerHTML='<b>' + answer +'</b><br><br>';
   }
   document.getElementById('kb').value='';
   isq=-Math.abs(isq);
   isq--;
   document.getElementById('kb').focus();
 <?php
  if (isset($_GET['concept']) || isset($_POST['concept'])) {
    echo "\n setTimeout(andthen,2000); \n";
  }
?>
  }
}
 
<?php
  if (1 == 2 && strlen($_SERVER['QUERY_STRING']) <= 1) {
    echo "\n location.href='./speech_supervisor.php?concept=Mushrooms&questions=" . urlencode('"What is the name that we give to the meat we get from pigs?pork","What is the name of the metal alloy we get from zinc and copper?bronze","Why is a duck?huh"') . "'; \n";
  }
?>
</script>
</head>
<body onload="document.getElementById('preq').innerHTML=dds('<?php echo str_replace("'","' + String.fromCharCode(39) + '",$qone); ?>'); document.getElementById('kb').focus(); pickq();">
<table cellspacing=10 cellpadding=10 style='width:100%;height:100vh;' border=20>
<tbody>
<tr><td style='width:40%;'><iframe onload='checki(this,1);' style='width:100%;height:95vh;' src='speech_idea.php?ifno=1'></iframe></td><td id=tdm style='text-align:center;width:10%;vertical-align:top;background-color:yellow;'><span id=preq><?php echo $qone; ?></span> (thanks to <a target=_blank title='Google Speech to Text' href='https://www.google.com/intl/en/chrome/demos/speech.html'>Google Speech to Text</a>)<br><br><span id=p12>&lt;- 1 Player 2 -&gt;</span><br><br><span id=sq></span><span id=klr>One quizzer can<br>key in 1 (left)<br>or 2 (right)<br></span><br><input onblur=pdidchange(0,this.value); id=kb type=text onkeypress=okp(event); value=''></input><br><br><span id=score>Score: 0/0</span></td><td style='width:40%;vertical-align:top;'><?php echo $ifmaybe; ?></td></tr>
</tbody>
</table>
<div id=divac style=display:none;></div>
</body>
</html>
