<?php
// moderate.php
// Moderation ideas
// RJM Programming
// November, 2015
$msg="";
$amsg="";
if (isset($_POST['mymidea'])) {
 $msg='?';
 $thisidea=urldecode($_POST['mymidea']);
     $msg='@' . $thisidea;
 if ($thisidea != '') {
     $msg='!';
     date_default_timezone_set('Australia/Perth');
     $amsg="<a style='display:none;' id='aemail' href='mailto:rmetcalfe@rjmprogramming.com.au?subject=" . str_replace(' ','%20',("Things That We Have in Common ... " . $thisidea . " ... " . date('l jS \of F Y h:i:s A'))) . "&body=" . str_replace(' ','%20',("Things That We Have in Common " . date('l jS \of F Y h:i:s A') . " ... " . $thisidea)) . "'>email</a>";
     $msg="Things That We Have in Common  " . date('l jS \of F Y h:i:s A') . " ... " . $thisidea . " ... has been sent for moderation (within 24 hours).";
     try {
      mail("rmetcalfe@rjmprogramming.com.au", "Things That We Have in Common ... " . $thisidea . " ... " . date('l jS \of F Y h:i:s A'), $thisidea);
      //$amsg="";
     } catch (Exception $e) { }
 }
}
if (isset($_POST['mymfileidea'])) {
 $msg='?';
 $thisidea=urldecode($_POST['mymfileidea']);
 file_put_contents(urlencode($thisidea) . ".aml", "");
     $msg='@' . $thisidea;
 if ($thisidea != '') {
     $msg='!';
     date_default_timezone_set('Australia/Perth');
     $amsg="<div align='center'><iframe src='./login.php' title='Admin login' style='height:600px;'></iframe></div>";
     $msg="Things That We Have in Common  " . date('l jS \of F Y h:i:s A') . " ... " . $thisidea . " ... file has been flagged for moderation (within 24 hours).";
 }
}
if (isset($_GET['admin'])) {
     $amsg="<div align='center'><iframe src='./login.php' title='Admin login' style='height:600px;'></iframe></div>";
}
echo "<!doctype html>
<html>
<head>
<title>Things That We Have in Common ... " . $msg . "</title>";
?>
<link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'>
<style> td { padding: 8 8 8 8; } </style>
<script type='text/javascript'>
 var cnt=0, thiscnt=0;
 var sbut=null;
 var mform=null;
 var sbutfile=null;
 var mformfile=null;
 function submitform() {
   var mmod=document.getElementById('mymod' + thiscnt);
   if (mmod != null) {
    document.getElementById('mymidea').value=decodeURIComponent(mmod.title);
   } 
   //mform=document.getElementById('fmoderation');
   sbut=document.getElementById('submit');
   //mform.submit();
   sbut.click();
   setTimeout(andthen, 1000);
 }
 function submitfileform() {
   var mmodfile=document.getElementById('myfilemod' + thiscnt);
   if (mmodfile != null) {
    document.getElementById('mymfileidea').value=decodeURIComponent(mmodfile.title);
   } 
   //mformfile=document.getElementById('filemoderation');
   sbutfile=document.getElementById('filesubmit');
   //mformfile.submit();
   sbutfile.click();
   setTimeout(andthenfile, 1000);
 }
 function andthen() {
   document.getElementById('mymidea').value='';
 }
 function andthenfile() {
   document.getElementById('mymideafile').value='';
 }
 function emailclient() {
   var aemailo=document.getElementById('aemail');
   if (aemailo != null) aemailo.click();
 }
 function fcnt(ot) {
   thiscnt=eval(ot.id.replace('mymod',''));
 }
 function filecnt(ot) {
   thiscnt=eval(ot.id.replace('myfilemod',''));
 }
</script>
</head>
<body onload=" sbut=document.getElementById('submit'); mform=document.getElementById('fmoderation'); document.getElementById('mymidea').focus(); emailclient(); " style=" background-color: lightblue; ">
<h1 align='center'>Things That We Have in Common</h1>
<h3 align='center'>It seems to me that there is so much more that should unite people, rather than divide.</h3>
<h3 align='center'>What do you think?</h3>
<?php global $msg;  echo "<h4 align='center'>" . $msg . "</h4>"; ?>
<hr>

<?php
   $cont="";
   if (file_exists("what_we_have_in_common.html")) {
    $cont=@file_get_contents("what_we_have_in_common.html");
   }
  
   if (strpos($cont, '<') !== false) {
    echo $cont;
   } else {
    echo "<table style=' background-color: yellow;  padding: 8 8 8 8; ' align='center'><tbody id='mytbody'><tr><th>Ideas (for what we have in common)</th><th id='hother'></th></tr>" . "\n";
    $lines=explode("\n", $cont);
    for ($cnt=1; $cnt<=sizeof($lines); $cnt++) {
      echo "<tr><td id='ltd" . $cnt . "'>" . $lines[-1 + $cnt] . "</td><td id='rtd" . $cnt . "'></td></tr>";
    }
    echo "</tbody></table>" . "\n";
   }
?>

<hr>
<div style=' background-color: lightgreen; padding: 8 8 8 8; ' align='center' id='dmoderation'>
<h1 align='center'>What do you think?</h1>
Private Thought (ie. no moderation, but will appear for you, in list above):<br> <input style='width:100%;' type='text' id='myidea' value='' onblur=" if (this.value != '') { document.getElementById('mytbody').innerHTML+='<tr><td>' + this.value + '</td><td></td>';  this.value=''; }   "></input><br><br>
<form action='./moderation.php' method='POST' align='center' name='fmoderation' id='fmoderation'>
Email Moderation (ie. click resultant moderation button and will be sent for moderation and, perhaps, be included in list above within 24 hours):<br> <input style='width:100%;' type='text' name='mymidea' id='mymidea' value='' onblur=" if (this.value != '') { cnt++; thiscnt=cnt; document.getElementById('mytbody').innerHTML+='<tr><td><input id=mymod' + cnt + ' style=background-color:pink; type=button onmousedown=fcnt(this); onclick=setTimeout(submitform,1000); value=Moderate title=' + encodeURIComponent(this.value) + '></input>' + ' ' + this.value + '</td><td></td>'; this.value='';  }   "></input><br><br>
<input style='display:none;' id='submit' type='submit' value='Moderate'></input>
</form>
<form action='./moderation.php' method='POST' align='center' name='filemoderation' id='filemoderation'>
File Moderation (ie. click resultant moderation button and will be sent for moderation and, perhaps, be included in list above within 24 hours):<br> <input style='width:100%;' type='text' name='mymfileidea' id='mymfileidea' value='' onblur=" if (this.value != '') { cnt++; thiscnt=cnt; document.getElementById('mytbody').innerHTML+='<tr><td><input id=myfilemod' + cnt + ' style=background-color:pink; type=button onmousedown=filecnt(this); onclick=setTimeout(submitfileform,1000); value=Moderate title=' + encodeURIComponent(this.value) + '></input>' + ' ' + this.value + '</td><td></td>'; this.value='';  }   "></input><br><br>
<input style='display:none;' id='filesubmit' type='submit' value='Moderate'></input>
</form>
</div>
<?php global $amsg; echo $amsg; ?>
</body>
</html>

  
