<?php
// rhopalic_letter_sentence.php
// Rhopalic Letter Sentence
// RJM Programming
// February, 2015
$words = array("A", "go", "for", "them", "would", "really", "improve", "fairness", "standards", "constantly", "threatening", "cohesiveness", "", "", "", "", "", "", "", "");
$wordd = array("inline", "inline", "inline", "inline", "inline", "inline", "inline", "inline", "inline", "inline", "inline", "inline", "inline", "none", "none", "none", "none", "none", "none", "none", "inline");
$ending = ".";

$score = 0;
$goes = 0;

$targeteq = "";

$kk = -1;

$isvalid = "y";

if (isset($_GET['w21'])) $ending = $_GET['w21'];

if (isset($_GET['score'])) $score = $_GET['score'];
if (isset($_GET['goes'])) $goes = $_GET['goes'];

$rest = $_GET['w1'] . "~" . $_GET['w2'] . "~" . $_GET['w3'] . "~" . $_GET['w4'] . "~" . $_GET['w5'] . "~" . $_GET['w6'] . "~" . $_GET['w7'] . "~" . $_GET['w8'] . "~" . $_GET['w9'] . "~" . $_GET['w10'] . "~" . $_GET['w11'] . "~" . $_GET['w12'] . "~" . $_GET['w13'] . "~" . $_GET['w14'] . "~" . $_GET['w15'] . "~" . $_GET['w16'] . "~" . $_GET['w17'] . "~" . $_GET['w18'] . "~" . $_GET['w19'] . "~" . $_GET['w20'];
$westart = 0;
$tstart = -1;

if (strlen($_SERVER['QUERY_STRING']) > 0) {
$w = explode("~", $rest);
for ($j=0; $j<20; $j++) {
$words[$j] = "";
if (isset($w[$j])) $words[$j] = $w[$j];
if (strlen($words[$j]) >= 1) {
$startword = file_get_contents("http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . "/PHP/surprise.php?huh=" . strtolower($words[$j]) . "");
if ($startword == "true") {
$startword = $startword;
} else {
$startword = file_get_contents("http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . "/PHP/surprise.php?huh=" . str_replace("*","",str_replace("s*","",(strtolower($words[$j]) . "*"))) . "");
if ($startword == "true") {
$startword = $startword;
} else {
if ($startword == "false") $words[$j]='';
}
}
}
if (strlen($words[$j]) != 0) {
if ($tstart < 0) {
$tstart=$j;
if ($j > 0 && $westart == 0) {
for ($jj=0; $jj<$j; $jj++) { $wordd[$jj] = "inline"; }
}
}
if ($westart == 0) $westart++;
if ($westart > 1) {
$westart=-1;
for ($jj=$tstart; $jj<$j; $jj++) { $wordd[$jj] = "inline"; }
}
if (strlen($rest) > 19) {
$wordd[$j] = "inline";
$wordd[$j + 1] = "inline";
if (isset($_GET['email'])) $kk=($j + 1);
}
} else {
if ($westart > 0) $westart++;
for ($jj=$j; $jj<20; $jj++) { if (strlen($words[$jj - 1]) == 0) { if (strlen($rest) > 19) { $wordd[$jj] = "none"; } } }
}
}
}

if ($kk >= 0) $words[$kk] = $ending;
$emailee = "";
$onload = "";

if (isset($_GET['submit']) || isset($_GET['submitemail'])) {
$goes = $goes + 1;
}

if ((isset($_GET['submit']) || isset($_GET['submitemail'])) && $westart >= 0) {
$score = $score + (strlen($rest) - 19);
$emailee = $_GET['submitemail'];
if (isset($_GET['submitemail'])) $onload = ' onload=" emailto(' . "'" . $emailee . "'" . '); "';
}

?>
<html>
<head>
<title>My Rhopalic Letter Sentence Game - RJM Programming - January, 2015</title>
<link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'>
<script type='text/javascript'>

var thattd;
var thattdi;
var potentialscore=<?php echo strlen($rest) - 19; ?>;
var score=<?php echo $score; ?>;
var goes=<?php echo $goes; ?>;
var emailee='';

function emailto(toemail) {
emailee = toemail;
if (emailee.indexOf('@') != -1) {
document.getElementById('mya').href = 'mail' + 'to:' + emailee + '?subject=My%20Rhopalic%20Letter%20Sentence&body=' + encodeURIComponent(document.URL.replace("submitemail","email=y&submit"));
} else {
document.getElementById('mya').href = 'mail' + 'to:' + '' + '?subject=My%20Rhopalic%20Letter%20Sentence&body=' + encodeURIComponent(document.URL.replace("submitemail","email=y&submit"));
}
document.getElementById('mya').click();
}


function check(thisi,thisid,thisvalue) {
thattd = document.getElementById(thisid.replace('i',''));
var ii=1;
var mm=0;
mm = eval(thisid.replace('i',''));
ii=eval(ii + eval(thisid.replace('i','')));
thattdi = document.getElementById(ii);
if (thisvalue == '') {
//thattd.innerHTML = '';
thisi.value = '';
} else if (thisvalue.length == mm) {
//thattd.innerHTML = thisi.value;
thisi.value = thisvalue;
thattdi.style.display = 'inline';
} else {
thisi.value = '';
}
}

</script>
<body style='background-color:teal;'<?php echo $onload; ?>>
<?php
if (isset($_GET['email'])) {
echo "
<h1 align='center'>Your Rhopalic Letter English Sentence Game</h1>
<h2 align='center' id='yourh2'>Score: " . $score . " / Goes: " . $goes . "</h2>
<div align='center' style='background-color:yellow;'>
<table id='yourtable'>
<tbody id='yourtbody'>
";
for ($j=0; $j<20; $j++) {
echo "\n<td id='x" . ($j + 1) . "' style='display:" . $wordd[$j] . ";'><input size=" . ($j + 1) . " id='xi" . ($j + 1) . "' value='" . $words[$j] . "'></input></td>";
}
echo "
</tbody>
</table>
</div>
<br><hr><br>
";
$words = array("A", "go", "for", "them", "would", "really", "improve", "fairness", "standards", "constantly", "threatening", "cohesiveness", "", "", "", "", "", "", "", "");
$wordd = array("inline", "inline", "inline", "inline", "inline", "inline", "inline", "inline", "inline", "inline", "inline", "inline", "inline", "none", "none", "none", "none", "none", "none", "none", "inline");
$ending = ".";

$score = 0;
$goes = 0;

$isvalid = "y";
$targeteq = " target='myi' ";

echo "<iframe id='myi' name='myi' style='width:100%;height:400px;' src='./rhopalic_letter_sentence.php'></iframe><br><div align='center' style='display:none;'>";
} else {
echo "<div align='center'>";
}
?>
<h1 align='center'>My <a target=_blank style='text-decoration:none;' title='rhopalic' href='http://en.wiktionary.org/wiki/rhopalic'>Rhopalic</a> Letter English Sentence Game</h1>
<h2 align='center' id='myh2'>Score: <?php echo $score; ?> / Goes: <?php echo $goes; ?></h2>
<div align='center'>
<form id='myform' method='GET' action='./rhopalic_letter_sentence.php'<?php echo $targeteq; ?>>
<table id='mytable'>
<tbody id='mytbody'>
<tr>
<?php
for ($j=0; $j<20; $j++) {
echo "\n<td id='" . ($j + 1) . "' style='display:" . $wordd[$j] . ";'><input size=" . ($j + 1) . " name='w" . ($j + 1) . "' id='i" . ($j + 1) . "' onblur='check(this,this.id,this.value);' value='" . $words[$j] . "'></input></td>";
}
?>
<td id='21'><select name='w21' id='i21'><option value='.'>.</option><option value='?'>?</option><option value='!'>!</option></select></td>
</tr>
</tbody>
</table>
<input type='hidden' value='<?php echo $score; ?>' id='score' name='score'></input><input type='hidden' value='<?php echo $goes; ?>' id='goes' name='goes'></input>
<br><input type='submit' name='submit' id='submit' value='Validate'></input>&nbsp;&nbsp;<input type='submit' name='submitemail' id='submitemail' value='Validate and Email'></input>&nbsp;&nbsp;<input type='button' id='reset' value='Reset' onclick='location.href="./rhopalic_letter_sentence.php?w1=&w2=&w3=&w4=&w5=&w6=&w7=&w8=&w9=&w10=&w11=&w12=&w13=&w14=&w15=&w16=&w17=&w18=&w19=&w20=&w21=.<?php echo '&score=' . $score . '&goes=' . $goes; ?>";'></input>
</form>
</div>
<a id='mya' title='Email' href='#' style='display:none;'>Email</a>
</div>
</body>
</html>