<?php
// The Derivations Game - RJM Programming - 2014
// latin_greek.php

class Derivation {
 function newDerivation($latinVSgreek, $lgis, $meaning, $relbit, $example) {
  $this->latinVSgreek = $latinVSgreek;
  $this->lgis = $lgis;
  $this->meaning = $meaning;
  $this->relbit = $relbit;
  $this->example = $example;
 }
 function newDerivationCSV($latinVSgreek) {
  $one = explode(",", $latinVSgreek);
  $this->latinVSgreek = $one[0];
  $this->lgis = $one[1];
  $this->meaning = $one[2];
  $this->relbit = $one[3];
  $this->example = $one[4];
 }
}

$suggestion = "";
$dataarray = array(
    0    => "Latin,annus,a year,annu,annual",
    1    => "Latin,audio,I hear,audi,audible",
    2    => "Latin,avis,a bird,avi,aviation",
    3    => "Latin,brevis,short,brev,abbreviate",
    4    => "Latin,cavus,hollow,cav,cavity",
    5    => "Latin,corpus,the body,corp,corpse",
    6    => "Latin,centum,one hundred,cent,century",
    7    => "Latin,credo,I believe,ced,incredible",
    8    => "Latin,dico,I say,dic,dictation",
    9    => "Latin,dominus,lord/master,dom,dominate",
    10   => "Latin,finis,end,fin,finite",
    11   => "Latin,forma,shape,form,formulate",
    12   => "Latin,genus,a kind/type,gen,generation",
    13   => "Latin,aravis,heavy,ravi,gravity",
    14   => "Latin,labor,work,labo,labour",
    15   => "Latin,liber,free,libe,liberty",
    16   => "Latin,locus,a place,loc,location",
    17   => "Latin,magnus,great,magn,magnify",
    18   => "Latin,navis,a ship,nav,navy",
    19   => "Latin,scribo,I write,scri,inscribe",
    20   => "Latin,sento,I feel,sent,sentimental",
    21   => "Latin,similis,like,simi,similar",
    22   => "Latin,sol,the sun,sol,solar",
    23   => "Latin,spiro,I breath,spir,respiration",
    24   => "Latin,terra,the earth,terr,terrestrial",
    25   => "Latin,verbum,a word,verb,verbal",
    26   => "Greek,aer,the air,aer,aeroplane",
    27   => "Greek,archo,I rule,arch,monarch",
    28   => "Greek,atmos,vapour,atmos,atmosphere",
    29   => "Greek,autos,self,auto,automatic",
    30   => "Greek,bios,life,bio,biography",
    31   => "Greek,chroma,colour,chroma,chromatic",
    32   => "Greek,chronos,time,chron,chronology",
    33   => "Greek,demos,the people,demo,democratic",
    34   => "Greek,grapto,I write,grap,autograph",
    35   => "Greek,isos,equal,isos,isosceles",
    36   => "Greek,mechane,machine,mech,mechanical",
    37   => "Greek,mikros,small,micro,microscope",
    38   => "Greek,monos,alone/one,mono,monologue",
    39   => "Greek,naus,ship,nau,nautical",
    40   => "Greek,optomai,I see,opt,optical",
    41   => "Greek,orthos,right,orth,orthodox",
    42   => "Greek,pathos,feeling,path,pathetic",
    43   => "Greek,phone,voice/sound,phon,telephone",
    44   => "Greek,photos,light,phot,photograph",
    45   => "Greek,polis,city,poli,metropolitan",
    46   => "Greek,skopeo,I see,scop,telescope",
    47   => "Greek,therme,heat,therm,thermal",
);


  if (isset($_GET['suggestion']) && isset($_GET['lgis']) && isset($_GET['reason']) && isset($_GET['echoback'])) {
    $suggestion=" var yh=prompt('Error(s) reported regarding your `" . $_GET['echoback'] . "` answer(s) is/are `" . str_replace("_"," ",$_GET['reason']) . "`.  One word derived from " . $_GET['lgis'] . " is " . $_GET['suggestion'] . ".  Hit OK to see it explained by http://www.thefreedictionary.com/ ... thanks.','" . $_GET['suggestion'] . "'); if (yh != null && yh == '" . $_GET['suggestion'] . "') { window.open('http://www.thefreedictionary.com/" . $_GET['suggestion'] . "','" . $_GET['suggestion'] . "',' height=600,width=900,top=30,left=400 '); } ";
  }

  $myderivation = new Derivation();
  $myderivation->newDerivationCSV($dataarray[rand(0, (sizeof($dataarray)-1))]); 

  $tablehtml = "<table cellpadding='5'>";
  $numtoguess = 0;
  $score = "0";
  $outof = "0";
  $theword = "";
  if (isset($_GET['score'])) {
    $score=$_GET['score'];
  }
  if (isset($_GET['outof'])) {
    $outof=$_GET['outof'];
  }
  if (isset($_POST['score'])) {
    $score=$_POST['score'];
  }
  if (isset($_POST['outof'])) {
    $outof=$_POST['outof'];
  }

echo "\n" . '<html>' . "\n";
echo "\n" . '<head>' . "\n";
echo "\n" . '<title>The Derivations Game - RJM Programming - 2014</title>' . "\n";
echo "\n" . '<script type="text/javascript">' . "\n";
echo "\n" . 'var score=0;' . "\n";
echo "\n" . 'var outof=0;' . "\n";
  if (isset($_GET['score'])) {
    echo "\n score=" . $_GET['score'] . "; \n";
  }
  if (isset($_GET['outof'])) {
    echo "\n outof=" . $_GET['outof'] . "; \n";
  }
?>

function golater() {
    location.href = "./latin_greek.php?score=" + score + "&outof=" + outof;
}

function goagain(pshow) {
    outof = outof + 1;
    if (pshow == 1) {
      document.getElementById('example').style.display = 'block';
      setInterval(golater, 5000);
    } else {
      location.href = "./latin_greek.php?score=" + score + "&outof=" + outof;
    }
}

</script>
</head>
<?php
  echo "\n <body style=\"background-color: yellow;\" onload=\"" . $suggestion . " document.getElementById('huhguess').focus(); \"> \n";
?>
<div align="center">
<h1 id="gamename">The Derivations Game</h1>
<?php
  global $score, $outof;
  if ($outof < $score) {
    $outof = $score;
  }
  echo "\n <h2 id='scoreis'>Score: " . $score . " / " . $outof . "</h2> \n";
  echo "\n" . '<form id="gform" method="POST" action="http://' . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . '/PHP/surprise.php">' . "\n";
  echo "\n" . '<input type="hidden" id="returnto" name="returnto" value="' . $_SERVER['PHP_SELF'] . '" />' . "\n";
?>
<input type="hidden" id="relbit" name="relbit" value="<?php echo $myderivation->relbit; ?>" />
<input type="hidden" id="sword" name="sword" value="<?php echo $myderivation->example; ?>" />
<input type="text" style="display:none;" id="example" name="example" value="<?php echo $myderivation->example; ?>" />
<input type="hidden" id="score" name="score" value="<?php echo $score; ?>" />
<input type="hidden" id="outof" name="outof" value="<?php echo $outof; ?>" />
<table border=1 cellpadding=8 style="font-size:20px;"><tr><th>Old Word</th><th>Old Language</th><th>Meaning</th><th>English Word</th></tr>
<tr><td><input style="font-size:20px;" type="text" onchange=" document.getElementById('relbit').value = this.value; " id="lgis" name="lgis" value="<?php echo $myderivation->lgis; ?>" />
</td><td><select style="font-size:20px;" id="oldlang" name="oldlang"><option value="Latin" <?php if ($myderivation->latinVSgreek == "Latin") echo "selected=selected"; ?>>Latin</option><option value="Greek" <?php if ($myderivation->latinVSgreek == "Greek") echo "selected=selected"; ?>>Greek</option></select>
</td><td><input style="font-size:20px;" type="text" id="meaning" name="meaning" value="<?php echo $myderivation->meaning; ?>" />
</td><td><input style="font-size:20px;background-color: pink;" type="text" id="huhguess" name="huhguess" value="" />
</tr></table>
<br><br><input type="button" onclick="goagain(1);" value="Please Show Example"></input>&nbsp;<input title="Can have comma separated list of your nominated English words derived from the Old Language (Latin or Greek) word (but not the same)" type="submit" name="submit" id="submit" value="Check My Word"></input>
<p id='lsofar' name='lsofar'></p>
</form>
<p id="information"></p>
</div>
</body>
</html>

