<?php
// connective_sentences.php
// Construct English sentences 
// December, 2020
// Later ... propernames
   
 exec("sort -n /usr/share/dict/connectives > " . dirname(__FILE__) . "/ourconnectives.txt");
 $connlist=explode("\n", file_get_contents(dirname(__FILE__) . "/ourconnectives.txt"));
 unlink(dirname(__FILE__) . "/ourconnectives.txt");

 $selbit="<select><option value=''>Optionally select a connective below</option></select>";
 $uoneselbit="<select><option value=''>Optionally select a Connective below</option></select>";

 for ($i=0; $i<sizeof($connlist); $i++) {
   if ($connlist[$i] == "i") {
   $selbit=str_replace("</select>", "<option value=' " . "I" . " '>" . "I" . "</option></select>", $selbit);
   } else {
   $selbit=str_replace("</select>", "<option value=' " . $connlist[$i] . " '>" . $connlist[$i] . "</option></select>", $selbit);
   }
   $uoneselbit=str_replace("</select>", "<option value='" . strtoupper(substr($connlist[$i],0,1)) . substr($connlist[$i],1) . " '>" . strtoupper(substr($connlist[$i],0,1)) . substr($connlist[$i],1) . "</option></select>", $uoneselbit);
 }

 echo "<html><head><title>Connective English Sentences - RJM Programming - December, 2020</title><script type='text/javascript'> 
 function asksms() {
   var smsto=prompt('SMS to?','');
   if (smsto == null) { smsto=''; }
   if (smsto.trim() != '') {
     document.getElementById('asms').href='sms:' + smsto + '&body=' + document.getElementById('asms').href.split('body=')[1];
     document.getElementById('asms').click();
   }
 }
 
 function alinkit(senten) {
   if (senten.trim() == '') { return senten; }
   var emih=senten.substring(0, eval(-1 + senten.length));
   var smih=senten.slice(-1); 
   return '<a title=Email href=\"mailto:?subject=' + encodeURIComponent('My Connective English Sentence(s)') + '&body=' + encodeURIComponent(senten + String.fromCharCode(10) + String.fromCharCode(10) + document.URL.split('#')[0].split('?')[0] + '?insentence=' + encodeURIComponent(senten + ' ')) + '\">' + emih + '</a><a title=SMS style=\"cursor:pointer;text-decoration:underline;\" onclick=\"asksms();\">' + smih + '</a><a id=asms style=\"display:none;\" title=SMS href=\"sms:&body=' + encodeURIComponent('My Connective English Sentence(s)' + String.fromCharCode(10) + String.fromCharCode(10)) + encodeURIComponent(senten + String.fromCharCode(10) + String.fromCharCode(10) + document.URL.split('#')[0].split('?')[0] + '?insentence=' + encodeURIComponent(senten + ' ')) + '\">' + smih + '</a>';
 }
 
 function construct() {
   var aspace='';
   if ((document.getElementById('val1').value + document.getElementById('val2').value) != '' && (document.getElementById('val3a').value + document.getElementById('val3b').value) == '' && document.getElementById('val4').value != '') { aspace=' '; }
   document.getElementById('sentence').innerHTML=alinkit(document.getElementById('val1').value + document.getElementById('val2').value + aspace + document.getElementById('val3a').value + document.getElementById('val3b').value + document.getElementById('val4').value); 
   setTimeout(construct, 5000);
 }  
 </script></head><body onload='construct();'><h1>Create your English Sentence(s)</h1><h3>RJM Programming - December, 2020</h3><h4>" . $_GET['insentence'] . "</h4><br><br>
 <table cellpadding=3 style='background-color:yellow;text-align:center;border:1px solid blue;'><tr><th>Optional Connective 1</th><th>Non connective 2</th><th>Optional connective 3</th><th>Non connective 4</th></tr>
 <tr><td>" . str_replace("<select", "<select id=val1", $uoneselbit) . "</td><td><textarea rows=2 id=val2 value=''></textarea></td><td>" . str_replace("<select", "<select id=val3a", $selbit) . "<br>" . str_replace("<select", "<select id=val3b", $uoneselbit) . "</td><td><textarea rows=2 id=val4 value=''></textarea></td></tr>
 <tr><td colspan=4 id=sentence style='text-align:center;'><br></td></tr>
 </table><input type=text style='position:absolute;left:-2000px;top:-2000px;' value=''></input></body></html>";
?>
