<?php
// interactive_becomes_web.php
// RJM Programming
// December, 2015

$prefix="Regarding our Profile Creation web application ... ";
$fullname="";
$sn=$_SERVER['SERVER_NAME'];
$sc=$_SERVER['HTTP_COOKIE'];
if (str_replace("www.rjmprogramming.com.au","",str_replace("localhost","",$sn)) == "")  $sn="www.rjmprogramming.com.au/PHP"; // $sn="localhost:8888"; // // . str_replace("interactive_becomes_web.php","",str_replace("/interactive_becomes_web.php","",$_SERVER['REQUEST_URI']));
$astr="";
$ithing=0;
$things_to_ask=["First Name", "Last Name", "Gender", "Age", "Interest", "Other1of5", "Other2of5", "Other3of5", "Other4of5", "Other5of5andlast"];  
$idea="<head>
       <title>Rudimentary Profile Webpage - RJM Programming - December, 2015</title>
       <style>
       a { background-color: lightgreen; text-decoration: none; border: solid 3px black; padding: 3 3 3 3; }
       </style>
       <script type='text/javascript'>
       var oaemailhref='', oh='';
       var inx=50, iny=50;
       var elem, elemTwo;
       var elemLeft, elemLeftTwo;
       var elemTop, elemTopTwo;
       var context, contextTwo;
       var cfb = '24px Courier New';
       var cf = '18px Courier New';
       var cfs = '16px Courier New';
       var ttd='';
       var imgis=null;
       var moveid=-1;
       var mousePos;
       var canvasbasis='canvaselement';
       var firstgo=true;

 
function allowDrop(ev) {
    ev.preventDefault();
    mousePos = getMousePos(elemTwo, ev);
    //mousePos.x=ev.clientX;
    //mousePos.y=ev.clientY;
}

function drag(ev) {
   moveid = ev.target.id;
   if (document.getElementById(ev.target.id).innerHTML.indexOf('<') == -1) {
    if (ev.target.id.substring(0,1) == 'i' || ev.target.id == 'ourimage') {
    //alert(ev.target.id);
    ttd='';
    imgis=document.getElementById(ev.target.id);
    ev.dataTransfer.setData('image/png', ev.target.id);
    } else {
    ttd=document.getElementById(ev.target.id).innerHTML;
    imgis=null;
    if (ev.dataTransfer) {
     ev.dataTransfer.setData('text/plain', ev.target.id);
    }
    }
   } else {
    ttd='';
    imgis=document.getElementById(ev.target.id);
    if (ev.dataTransfer) {
    ev.dataTransfer.setData('image/png', ev.target.id);
    }
   }
}

function drop(ev) {
    var evpageX = ev.pageX, evpageX2;
    var evpageY = ev.pageY, evpageY2;
    ev.preventDefault();
    if (typeof mousePos.x !== 'undefined') {
     //alert(evpageX + ' vs mousePos.x=' + mousePos.x + ' ' + evpageY + ' vs mousePos.y=' + mousePos.y);
     if (ttd != '') {
       if (moveid.indexOf('myh1') != -1) { 
        contextTwo.strokeStyle = 'black';
        contextTwo.font = cfb;
       } else if (moveid.indexOf('th') != -1) { 
        contextTwo.strokeStyle = 'black';
        contextTwo.font = cf;
       } else {
        contextTwo.strokeStyle = 'blue';
        contextTwo.font = cfs;
       }
       contextTwo.strokeText(ttd, mousePos.x, mousePos.y);
     } else if (imgis != null) {
       contextTwo.drawImage(imgis, mousePos.x, mousePos.y);
     }
   }
}

       function doaemail(intd, ourj) {
         var it, things_to_ask=['First+Name', 'Last+Name', 'Gender', 'Age', 'Interest', 'Other1of5', 'Other2of5', 'Other3of5', 'Other4of5', 'Other5of5andlast'];  
         var outtd=intd;
         //var tbits=intd.replace('</td>','').replace('</td>','').split('<td' + ' id=t' + ourj + '>');
         var tbits=intd.replace('</td>','').replace('</td>','').split('' + ' id=t' + ourj + '>');
         var oaemail=document.getElementById('aemail');
         if (oaemail == null) {
          if (1 == 2) {
          document.getElementById('ldiv').innerHTML=\"<br><br><a id=aemail href='mailto:?subject=Profile&body=http://" . $sn . "/interactive_becomes_web.php'>Email</a>\";
          } else if (ourj == 0) {
          oaemailhref=\"<br><br><a id='aemail' href='mailto:?subject=Profile&body=http://" . $sn . "/interactive_becomes_web.php'>Email</a>\";
          oh=\"mailto:?subject=Profile&body=http://" . $sn . "/interactive_becomes_web.php\";
          }
          /" . "/ oaemail=document.getElementById('aemail');
         }
         if (tbits.length > 1) {
          if (tbits[1].indexOf('<img' + ' ') != -1 && tbits[1].indexOf('drag') == -1) {
           var extras='';
           if (tbits[1].indexOf(' id=') == -1) extras=' id=i' + ourj + ' ';
           tbits[1]=tbits[1].replace('<img' + ' ', '<img' + ' onclick=drag(event) ondragstart=drag(event) draggable=true ' + extras);
           outtd=outtd.replace('<img' + ' ', '<img' + ' onclick=drag(event) ondragstart=drag(event) draggable=true ' + extras);
           //alert(tbits[1]);
          }
         }
         if (ourj == 0) {
          it='?' + things_to_ask[ourj] + '=' + tbits[1]; /" . "/eval(-1 + tbits.length)];
          if (it.indexOf('=<') != -1) {
            it='?' + things_to_ask[ourj] + '=' + encodeURIComponent(tbits[1]);
          }
          oaemailhref=oaemailhref.replace(\"'>Email<\", encodeURIComponent(it.replace(' ','+').replace(' ','+').replace(' ','+').replace(' ','+').replace(' ','+').replace(' ','+').replace(' ','+')) + \"'>Email<\");
          oh+=encodeURIComponent(it.replace(' ','+').replace(' ','+').replace(' ','+').replace(' ','+').replace(' ','+').replace(' ','+').replace(' ','+'));
         } else {
          it='&' + things_to_ask[ourj] + '=' + tbits[1]; /" . "/eval(-1 + tbits.length)];
          if (it.indexOf('=<') != -1) it='&' + things_to_ask[ourj] + '=' + encodeURIComponent(tbits[1]);
          oaemailhref=oaemailhref.replace(\"'>Email<\", encodeURIComponent(it.replace(' ','+').replace(' ','+').replace(' ','+').replace(' ','+').replace(' ','+').replace(' ','+').replace(' ','+')) + \"'>Email<\");
          oh+=encodeURIComponent(it.replace(' ','+').replace(' ','+').replace(' ','+').replace(' ','+').replace(' ','+').replace(' ','+').replace(' ','+'));
          if (ourj == 2) {
            oaemailhref=oaemailhref.replace('=Profile&', '=' + encodeURIComponent('A ' + document.getElementById('myh1').innerHTML) + '&');
          }
         }
         return outtd;
       }
       function ol() {
            var oaemail=document.getElementById('aemail');
            if (oaemail != null) oaemail.href=oaemail.href.replace('=Profile&', '=' + encodeURIComponent('A ' + document.getElementById('myh1').innerHTML) + '&');
            elem = document.getElementById('canvaselement');
            if (elem) {
            elemLeft = elem.offsetLeft;
            elemTop = elem.offsetTop;
            context = elem.getContext('2d');
            }
                 elemTwo = document.getElementById('yourcanvas');
                // var rect = elemTwo.getBoundingClientRect();
                // elemLeftTwo = rect.left;
                // elemTopTwo = rect.top;
                 contextTwo = elemTwo.getContext('2d');
       }
      function getMousePos(canvas, evt) { // thanks to http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
        var rect = canvas.getBoundingClientRect();
        //document.title='' + eval(evt.clientX - rect.left) + ',' + eval(evt.clientY - rect.top);
        return {
          x: eval(evt.clientX - rect.left),
          y: eval(evt.clientY - rect.top)
        };
      }
       function andmore() {
                 var ii;
                 //alert(92);
                 var ois=document.getElementsByTagName('th');
                 elem = document.getElementById('canvaselement');
                 elemTwo = document.getElementById('yourcanvas');
                 //elemLeftTwo = elemTwo.offsetLeft;
                 //elemTopTwo = elemTwo.offsetTop;
                 contextTwo = elemTwo.getContext('2d');
                 //if (elem != null) alert(989);
                 elemLeft = elem.offsetLeft;
                 elemTop = elem.offsetTop;
                 //if (elem != null) alert(98);
                 context = elem.getContext('2d');
                 context.strokeStyle = 'black';
                 context.font = cf;
                 //alert(84);
                 ois=document.getElementsByTagName('img');
                 //alert(85 + ' ' + ois.length);
                 if (ois) {
                 for (ii=0; ii<ois.length; ii++) {
                   //alert(56);
                   if (ois[ii].id != 'ourimage') {
                    context.drawImage(ois[ii], inx, iny);
                    iny+=eval(20 + ois[ii].height);
                   }
                   //alert(57);
                 }
                 }
                 //alert(86);
                 context.strokeText(document.getElementById('myh1').innerHTML,inx,iny);
                 iny+=30;
                 ois=document.getElementsByTagName('th');
                 for (ii=0; ii<ois.length; ii++) {
                   if (ois[ii].innerHTML.indexOf('<') == -1) {
                     //alert(ois[ii].innerHTML);
                     context.strokeText(ois[ii].innerHTML,eval(inx + eval((ii % 2) * 200)),iny);
                   }
                   if (eval((ii % 2)) == 1) iny+=20;
                 }
                 iny+=5;
                 context.strokeStyle = 'blue';
                 context.font = cfs;
                 ois=document.getElementsByTagName('td');
                 for (ii=1; ii<ois.length; ii++) {
                   if (ois[ii].innerHTML.indexOf('<') == -1) {
                    //alert(ois[ii].innerHTML);
                    context.strokeText(ois[ii].innerHTML,eval(inx + eval((1 - (ii % 2)) * 200)),iny);
                   }
                   if (eval((ii % 2)) == 0) iny+=20;
                 }
                 var ourcanvas = document.getElementById(canvasbasis);
                 //if (ourcanvas != null) alert(91);
                 document.getElementById('ourimage').src = ourcanvas.toDataURL();
                 //if (ourcanvas != null) alert(document.getElementById('ourimage').src);
                 document.getElementById('ourimage').style.display = 'none';
                 //if (ourcanvas != null) alert(93);
      elemTwo.addEventListener('mouseenter', function(evt) {  // thanks to http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
        mousePos = getMousePos(elemTwo, evt);
      }, false);
       }
       function andthen() {
                 document.getElementById('ldiv').innerHTML=oaemailhref.replace(\"'>Email\",'\">Email').replace(\"href='\",'href=\"') + \"<canvas id='canvaselement' style='border: 5px solid green; background-color: yellow; opacity: 0.0;border: 1px solid green;display:block;' title='Profile' width='1150' height='500' />\";
                 var oaemail=document.getElementById('aemail');
                 if (oaemail != null) oh=oh.replace('=Profile&', '=' + encodeURIComponent('A ' + document.getElementById('myh1').innerHTML) + '&');
                 oaemail.href=oh;
                 setTimeout(andmore,2000);
       }
       function andshow() {
         firstgo=false;
         document.getElementById('ourimage').style.display='block';
         //document.getElementById('ourimage').style.border='green 2px solid';
       }
       function preshow() {
                 var ourcanvas = document.getElementById(canvasbasis);
                 document.getElementById('ourimage').src = ourcanvas.toDataURL();
       }
       function preshowtwo() {
                 var ourcanvas = document.getElementById('yourcanvas');
                 document.getElementById('ourimage').src = ourcanvas.toDataURL();
       }
       function clearit() {
         var canvas = document.getElementById('yourcanvas');
         ctx = canvas.getContext('2d');
         ctx.clearRect(0, 0, canvas.width, canvas.height);
       }
       </script>
       </head>"; 
       
function adddragdrop($inh) {
  $outh=$inh;
  $outh=str_replace("</table>", "</table></td><td><br>-&gt;<br>-&gt;<br>-&gt;<br>-&gt;<br>-&gt;<br><br>Drag<br>and<br>Drop<br><br>Calling<br>Card<br>creator<br><br><a title='Clear' href='#' onclick='clearit();'>Clear</a><br><br>-&gt;<br>-&gt;<br>-&gt;<br>-&gt;<br>-&gt;<br></td><td><canvas onclick='allowDrop(event); drop(event);' ondrop='drop(event);' ondragover='allowDrop(event);' id=yourcanvas width=800 height=500 style='display:block;background-color:yellow;' /></td></tr></table></div>", $outh);
  $outh=str_replace("<table", "<div align='center'><table><tr><td><table", $outh);
  $outh=str_replace("<img ", "<img  draggable='true' onclick='drag(event)' ondragstart='drag(event);'  ", $outh);
  $outh=str_replace("<td ", "<td draggable='true' onclick='drag(event)' ondragstart='drag(event);'  ", $outh);
  $outh=str_replace("<th ", "<th draggable='true' onclick='drag(event)' ondragstart='drag(event);'  ", $outh);
  $outh=str_replace("<h1 ", "<h1 draggable='true' onclick='drag(event)' ondragstart='drag(event);'  ", $outh);
  return $outh;
}

function get_line($inidea, $j) {
  global $things_to_ask, $prefix;
  $suffix="";
  if ($j == 1) $suffix="<script> document.getElementById('myh1').innerHTML='Profile for ' + document.getElementById('t0').innerHTML + ' ' + document.getElementById('t1').innerHTML; var oaemail=document.getElementById('aemail');  if (oaemail) { oaemail.href=oaemail.href.replace('=Profile&', '=' + encodeURIComponent('A ' + document.getElementById('myh1').innerHTML) + '&'); } </script>";
  if ($j == (-1 + sizeof($things_to_ask))) $suffix="<script> setTimeout(andthen,1000); </script>";
  $retval="\n" . '<script> document.write(doaemail(("<td id=l' . $j . '>' . $inidea . '</td><td id=t' . $j . '>" + prompt("' . $prefix . 'What is your ' . $inidea . '?  You can Cancel or OK nothing.","") + "</td>").replace("<td id=j' . $j . '>' . $inidea . '</td><td id=t' . $j . '></td>","<td id=l' . $j . '></td><td id=t' . $j . '></td>").replace("<td id=l' . $j . '>' . $inidea . '</td><td id=t' . $j . '>null</td>","<td id=l' . $j . '></td><td id=t' . $j . '></td>"),' . $j . ')); </script>' . $suffix . "\n";
  $prefix="";
  return $retval;
}

function webdisplay($h) { 
 global $fullname, $sn;
 if ($h != '') {
  if (file_exists(dirname(__FILE__) . "/interactive_becomes_web.htm")) unlink(dirname(__FILE__) . "/interactive_becomes_web.htm");
  file_put_contents(dirname(__FILE__) . "/interactive_becomes_web.htm", $h);
  if (file_exists(dirname(__FILE__) . "/interactive_becomes_web.html")) unlink(dirname(__FILE__) . "/interactive_becomes_web.html");
  //sleep(1);
  exec("ksh -c \"perl -p -e 's/&nbsp;/Profile for " . $fullname . "/g' " . dirname(__FILE__) . "/interactive_becomes_web.htm\" > " . dirname(__FILE__) . "/interactive_becomes_web.html");
  //sleep(1);
  exec("python -mwebbrowser http://" . $sn . "/interactive_becomes_web.html");
  //exec("python -mwebbrowser http://" . $sn . "/interactive_becomes_web.htm");
 }
}

if (strlen($_SERVER['QUERY_STRING']) > 0 || !isset($argv[0])) {
 if (strpos($_SERVER['QUERY_STRING'], "reask=") !== false || strlen($_SERVER['QUERY_STRING']) == 0) {
  for ($i=0; $i<sizeof($things_to_ask); $i++) {
   if ($html == "") {
    $astr="<br><br><div align='center'><a title='Calling Card' href='#ourimage' onclick='if (!firstgo) { preshow(); } andshow();'>Calling Card</a>&nbsp;&nbsp;<a title='Your Calling Card' href='#ourimage' onclick='preshowtwo(); andshow();'>Your Calling Card</a><img id='ourimage' title='Calling Card with right button download possibilities' status='display:none;'></img><br><br><a title='Reask' href='http://" . $sn . "/interactive_becomes_web.php?reask=y'>Reask</a></div>";
    $html="<!doctype html><html>" . $idea . "<body style='background-color:pink'><h1 align='center' style='background-color:yellow' id='myh1'>&nbsp;</h1><br><div align='center'><table style='background-color:orange' border=1 cellpadding=8 cellspacing=8><tbody><tr><th id=thp>Parameter</th><th id=thv>Value</th></tr><tr>" . get_line($things_to_ask[$i], $i) . "</tr></tbody></table></div>" . $astr . "<div id=ldiv align=center></div></body></html>";
   } else {
    $html=str_replace("</tbody>", "<tr>" . get_line($things_to_ask[$i], $i) . "</tr></tbody>", $html);
   }
  }
  if ($html != "") {
   $html=adddragdrop($html);
   if (!$sc) {
    webdisplay($html);
   } else if ($sc == "") {
    webdisplay($html);
   } else {
    echo $html;
   }
  }
 } else {
  $bits=explode("&", $_SERVER['QUERY_STRING']);
  for ($i=0; $i<sizeof($bits); $i++) {
   $subbits=explode("=", $bits[$i]);
   $things_to_askithing=str_replace("+"," ",str_replace("_"," ",$subbits[0]));
   $line=urldecode($subbits[1]);
   if ($html == "") {
    $fullname.=str_replace("\n","",$line);
    if (strpos($subbits[1], "%20") === false) {
    $astr="<br><br><div align='center'><a title='Calling Card' href='#ourimage' onclick='if (!firstgo) { preshow(); }  andshow();'>Calling Card</a>&nbsp;&nbsp;<a title='Your Calling Card' href='#ourimage' onclick='preshowtwo(); andshow();'>Your Calling Card</a><img id='ourimage' title='Calling Card with right button download possibilities' status='display:none;'></img><br><br><a title='Reask' href='http://" . $sn . "/interactive_becomes_web.php?reask=y'>Reask</a><br><br><a id='arefresh' title='Refresh' href='http://" . $sn . "/interactive_becomes_web.php?" . str_replace(" ","_",$things_to_askithing) . "=" . urlencode(str_replace("\n","",$line)) . "'>Refresh</a><br><br><a id='aemail' title='Refresh' href='mailto:?subject=Profile&body=http://" . $sn . "/interactive_becomes_web.php" . urlencode("?" . str_replace(" ","_",$things_to_askithing) . "=") . urlencode(str_replace("\n","",$line)) . "'>Email</a></div>";
    $html="<!doctype html><html>" . $idea . "<body onload='ol();' style='background-color:pink'><h1 align='center' style='background-color:yellow' id='myh1'>&nbsp;</h1><br><div align='center'><table style='background-color:orange' border=1 cellpadding=8 cellspacing=8><tbody><tr><th id=thp>Parameter</th><th id=thv>Value</th></tr><tr><td id=l" . $i . ">" . $things_to_askithing . "</td><td id=t" . $i . ">" . str_replace("\n","",$line) . "</td></tr></tbody></table></div>" . $astr . "<div id=ldiv align=center></div></body></html>";
    } else {
    $astr="<br><br><div align='center'><a title='Calling Card' href='#ourimage' onclick='if (!firstgo) { preshow(); }  andshow();'>Calling Card</a>&nbsp;&nbsp;<a title='Your Calling Card' href='#ourimage' onclick='preshowtwo(); andshow();'>Your Calling Card</a><img id='ourimage' title='Calling Card with right button download possibilities' status='display:none;'></img><br><br><a title='Reask' href='http://" . $sn . "/interactive_becomes_web.php?reask=y'>Reask</a><br><br><a id='arefresh' title='Refresh' href='http://" . $sn . "/interactive_becomes_web.php?" . str_replace(" ","_",$things_to_askithing) . "=" . $subbits[1] . "'>Refresh</a><br><br><a id='aemail' title='Refresh' href='mailto:?subject=Profile&body=http://" . $sn . "/interactive_becomes_web.php" . urlencode("?" . str_replace(" ","_",$things_to_askithing) . "=") . $subbits[1] . "'>Email</a></div>";
    $html="<!doctype html><html>" . $idea . "<body onload='ol();' style='background-color:pink'><h1 align='center' style='background-color:yellow' id='myh1'>&nbsp;</h1><br><div align='center'><table style='background-color:orange' border=1 cellpadding=8 cellspacing=8><tbody><tr><th id=thp>Parameter</th><th id=thv>Value</th></tr><tr><td id=l" . $i . ">" . $things_to_askithing . "</td><td id=t" . $i . ">" . str_replace("\n","",$line) . "</td></tr></tbody></table></div>" . $astr . "<div id=ldiv align=center></div></body></html>";
    }
   } else {
    if ($fullname == $lastline) $fullname.=(" " . str_replace("\n","",$line));
    if (strpos($subbits[1], "%20") === false) {
    $html=str_replace("'>Refresh</a>", "&" . str_replace(" ","_",$things_to_askithing) . "=" . urlencode(str_replace("\n","",$line)) . "'>Refresh</a>", str_replace("'>Email</a>", urlencode("&" . str_replace(" ","_",$things_to_askithing) . "=") . urlencode(str_replace("\n","",$line)) . "'>Email</a>", str_replace("</tbody>", "<tr><td>" . $things_to_askithing . "</td><td>" . str_replace("\n","",$line) . "</td></tr></tbody>", $html)));
    } else {
    $html=str_replace("'>Refresh</a>", "&" . str_replace(" ","_",$things_to_askithing) . "=" . $subbits[1] . "'>Refresh</a>", str_replace("'>Email</a>", urlencode("&" . str_replace(" ","_",$things_to_askithing) . "=") . $subbits[1] . "'>Email</a>", str_replace("</tbody>", "<tr><td>" . $things_to_askithing . "</td><td>" . str_replace("\n","",$line) . "</td></tr></tbody>", $html)));
    }
   }
   $lastline=str_replace("\n","",$line);
  }
  if ($html != "") {
   $html=adddragdrop($html);
   if ($_SERVER['SERVER_NAME'] == "www.rjmprogramming.com.au" || $_SERVER['SERVER_NAME'] != '') {
    echo str_replace("&nbsp;","Profile for " . $fullname, $html);
   } else {
    webdisplay($html);
   }
  }
 }
} else if (isset($argv[0])) {
 $lastline="";
 $html="";
 echo "PHP Interactive Input becomes Web Output\n\n";
 while ($ithing < sizeof($things_to_ask)) {
  echo "What is your " . $things_to_ask[$ithing] . "?  Type nothing to stop, else we present this information to you on a web page: ";
  $handle = fopen ("php://stdin","r");
  $line = fgets($handle);
  if (trim($line) == '') {
    echo "Bye now\n";
    if ($html != "") {
     $html=adddragdrop($html);
     webdisplay($html);
    }
    exit;
  } else if ($html == "") {
    $fullname.=str_replace("\n","",$line);
    $astr="<br><br><div align='center'><a title='Calling Card' href='#ourimage' onclick='if (!firstgo) { preshow(); }  andshow();'>Calling Card</a>&nbsp;&nbsp;<a title='Your Calling Card' href='#ourimage' onclick='preshowtwo(); andshow();'>Your Calling Card</a><img id='ourimage' title='Calling Card with right button download possibilities' status='display:none;'></img><br><br><a title='Reask' href='http://" . $sn . "/interactive_becomes_web.php?reask=y'>Reask</a><br><br><a id='arefresh' title='Refresh' href='http://" . $sn . "/interactive_becomes_web.php?" . str_replace(" ","_",$things_to_ask[$ithing]) . "=" . urlencode(str_replace("\n","",$line)) . "'>Refresh</a><br><br><a id='aemail' title='Email' href='mailto:?subject=Profile&body=http://" . $sn . "/interactive_becomes_web.php" . urlencode("?" . str_replace(" ","_",$things_to_ask[$ithing]) . "=") . urlencode(str_replace("\n","",$line)) . "'>Email</a></div>";
    $html="<!doctype html><html>" . $idea . "<body onload='ol();' style='background-color:pink'><h1 align='center' style='background-color:yellow' id='myh1'>&nbsp;</h1><br><div align='center'><table style='background-color:orange' border=1 cellpadding=8 cellspacing=8><tbody><tr><th id=thp>Parameter</th><th id=thv>Value</th></tr><tr><td id=l" . $ithing . ">" . $things_to_ask[$ithing] . "</td><td id=t" . $ithing . ">" . $line . "</td></tr></tbody></table></div>" . $astr . "<div id=ldiv align=center></div></body></html>";
  } else {
    if ($fullname == $lastline) $fullname.=(" " . str_replace("\n","",$line));
    $html=str_replace("'>Refresh</a>", "&" . str_replace(" ","_",$things_to_ask[$ithing]) . "=" . urlencode(str_replace("\n","",$line)) . "'>Refresh</a>", str_replace("'>Email</a>", urlencode("&" . str_replace(" ","_",$things_to_ask[$ithing]) . "=") . urlencode(str_replace("\n","",$line)) . "'>Email</a>", str_replace("</tbody>", "<tr><td id=l" . $ithing . ">" . $things_to_ask[$ithing] . "</td><td id=t" . $ithing . ">" . str_replace("\n","",$line) . "</td></tr></tbody>", $html)));
  }
  $lastline=str_replace("\n","",$line);
  echo "\n"; 
  echo "Thank you, continuing...\n";
  $ithing++;
 }
 if ($html != "") {
  $html=adddragdrop($html);
  webdisplay($html);
 }
}

?>
