<?php
// journal.php
// Maintain a journal
// RJM Programming
// January, 2025

$aname="";
$adob="";
$asecret="";
$vsb="visible";
  
function server_remote_addr($howlong) {
    $rma = $_SERVER['REMOTE_ADDR'];
    if ($howlong > 0) {
      $endthing='';
      $fromstart=true;
      $charnum=1;
      $idea=str_replace('.','_',$rma);
      while (strlen($endthing) < $howlong) {
        $thisc=0;
        $lastn="0";
        if ($fromstart) {
          for ($i=0; $i<strlen($idea); $i++) {
           if (substr(substr($idea,$i),0,1) >= '0' && substr(substr($idea,$i),0,1) <= '9') {
             $thisc++;
             if ($thisc == $charnum) {  $lastn=substr(substr($idea,$i),0,1); }
           }
          }
          $fromstart=false;
        } else {
          for ($i=(-1 + strlen($idea)); $i>=0; $i--) {
           if (substr(substr($idea,$i),0,1) >= '0' && substr(substr($idea,$i),0,1) <= '9') {
             $thisc++;
             if ($thisc == $charnum) {  $lastn=substr(substr($idea,$i),0,1); }
           }
          }
          $fromstart=true;
          $charnum++;
        }
        $endthing.=$lastn;
      }
      return $endthing;
    }
    return str_replace('.','_',$rma);
}

if ((isset($_GET['isname']) && isset($_GET['isdob']) && isset($_GET['issecret'])) || (isset($_POST['name']) && isset($_POST['dob']) && isset($_POST['snum']))) {
  $fcnt=0;
  $gcnt=-1;
  $fillins="";
  $fsuff="";
  $afnd='';
  $isdone=false;
  if (!$isdone && strlen($_POST['name']) > 0) {
    if (strlen($_POST['dob']) > 0 && strlen($_POST['snum']) > 0) {
      if (isset($_POST['posting']) && isset($_POST['timestamp'])) {
       if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_POST['name']))) . '-' . $_POST['dob'] . '-' . $_POST['snum'] . '.html')) {
        $sofar=file_get_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_POST['name']))) . '-' . $_POST['dob'] . '-' . $_POST['snum'] . '.html');
        file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_POST['name']))) . '-' . $_POST['dob'] . '-' . $_POST['snum'] . '.html', $sofar . "\n\n" . str_replace('+',' ',urldecode($_POST['timestamp'])) . "\n" . str_replace('+',' ',urldecode($_POST['posting'])));
        $fsuff=" if (1 == 1) { parent.document.getElementById('fjnamemore').value='" . explode('.',basename($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_POST['name']))) . '-' . $_POST['dob'] . '-' . $_POST['snum'] . '.html'))[0] . "'; parent.document.getElementById('subfjnamemore').click();  } else { parent.location.href='./journal.php?fjname=" . urlencode(explode('.',basename($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_POST['name']))) . '-' . $_POST['dob'] . '-' . $_POST['snum'] . '.html'))[0]) . "'; } "; 
        $fillins.=" var allbef=window.windowbtoax(('' + window.localStorage.getItem(window.windowbtoa('list_journal'))).replace(/^null/g,'').replace(/^undefined/g,'')), bef=window.windowbtoax(('' + window.localStorage.getItem(window.windowbtoa('unique_journal'))).replace(/^null/g,'').replace(/^undefined/g,'')), vsbef=window.windowbtoa('" . explode('.',basename($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_POST['name']))) . '-' . $_POST['dob'] . '-' . $_POST['snum'] . '.html'))[0] . "'); parent.document.getElementById('ysecret').value='" . $_POST['snum'] . "';  parent.document.getElementById('ysecret').disabled=true;  parent.document.getElementById('yname').disabled=true;   parent.document.getElementById('ydob').disabled=true; if (bef == '') {  window.localStorage.setItem(window.windowbtoa('unique_journal'), window.windowbtoa('" . explode('.',basename($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_POST['name']))) . '-' . $_POST['dob'] . '-' . $_POST['snum'] . '.html'))[0] . "'));  } else if (bef != vsbef) { if (allbef == '') {  window.localStorage.setItem(window.windowbtoa('list_journal'), (bef == '' ? '' : window.windowbtoa(window.windowatob(bef) + window.windowbtoax(',') + window.windowbtoax('" . explode('.',basename($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_POST['name']))) . '-' . $_POST['dob'] . '-' . $_POST['snum'] . '.html'))[0] . "'))));  } else {     window.localStorage.setItem(window.windowbtoa('list_journal'), (allbef == '' ? '' : window.windowbtoa(window.windowatob(allbef) + window.windowbtoax(',') + window.windowbtoax('" . explode('.',basename($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_POST['name']))) . '-' . $_POST['dob'] . '-' . $_POST['snum'] . '.html'))[0] . "'))));   }  } " . $fsuff . " ";
       }
   $jcont=file_get_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_POST['name']))) . '-' . $_POST['dob'] . '-' . $_POST['snum'] . '.html');
   $jtitle=explode('.',basename($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_POST['name']))) . '-' . $_POST['dob'] . '-' . $_POST['snum'] . '.html'))[0];
   $none="block";
   $open=" open";
   $doneanddusted=true;
      }
      $isdone=true;
    } 
  } else if (!$isdone && strlen($_GET['isname']) > 0) {
    if (strlen($_GET['isdob']) > 0 && strlen($_GET['issecret']) > 0) {
      $isdone=true;
    } else if (strlen($_GET['isdob']) > 0 && strlen($_GET['issecret']) == 0) {
        //file_put_contents('xx.xxx', $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_GET['isname']))) . '-' . $_GET['isdob'] . '-*.*');
      foreach (glob($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_GET['isname']))) . '-' . $_GET['isdob'] . '-*.*') as $fln) {
        $afnd=$fln;
        $fcnt++;
      }
      if ($fcnt == 1) {
        if (isset($_GET['fillif'])) { $fsuff=" if (1 == 1) { parent.document.getElementById('fjnamemore').value='" . explode('.',basename($afnd))[0] . "'; parent.document.getElementById('subfjnamemore').click();  } else {  parent.location.href='./journal.php?fjname=" . urlencode(explode('.',basename($afnd))[0]) . "'; } ";  }
        //file_put_contents('xx.x', $fsuff);
        $fillins.=" parent.document.getElementById('ysecret').value='" . explode('.', explode($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_GET['isname']))) . '-' . $_GET['isdob'] . '-', $fln)[1])[0] . "'; " . $fsuff . " ";
        //file_put_contents('xx.xx', $fillins);
      } else if ($fcnt == 0 && !isset($_GET['fillif'])) {
        $sug=server_remote_addr(6);
        if (!file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_GET['isname']))) . '-' . $_GET['isdob'] . '-' . $sug . '.html')) {
        $rand=$sug;
        } else {
        while ($gcnt != 0) {
          $gcnt=0;
          $rand=rand(100000, 999999);
          foreach (glob($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_GET['isname']))) . '-*-' . $rand . '.*') as $fln) {
           $gcnt++;
          }
        }
        }
        file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_GET['isname']))) . '-' . $_GET['isdob'] . '-' . $rand . '.html', '');
        $fillins.=" var allbef=window.windowbtoax(('' + window.localStorage.getItem(window.windowbtoa('list_journal'))).replace(/^null/g,'').replace(/^undefined/g,'')), bef=window.windowbtoax(('' + window.localStorage.getItem(window.windowbtoa('unique_journal'))).replace(/^null/g,'').replace(/^undefined/g,'')), vsbef=window.windowbtoa('" . explode('.',basename($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_GET['isname']))) . '-' . $_GET['isdob'] . '-' . $rand . '.html'))[0] . "'); parent.document.getElementById('ysecret').value='" . $rand . "';  parent.document.getElementById('ysecret').disabled=true;  parent.document.getElementById('yname').disabled=true;   parent.document.getElementById('ydob').disabled=true; if (bef == '') {    window.localStorage.setItem(window.windowbtoa('unique_journal'), window.windowbtoa('" . explode('.',basename($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_GET['isname']))) . '-' . $_GET['isdob'] . '-' . $rand . '.html'))[0] . "'));  } else if (bef != vsbef) { if (allbef == '') {   window.localStorage.setItem(window.windowbtoa('list_journal'), (bef == '' ? '' : window.windowbtoa((window.windowatob(bef) + window.windowbtoax(',') + window.windowbtoax('" . explode('.',basename($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_GET['isname']))) . '-' . $_GET['isdob'] . '-' . $rand . '.html'))[0] . "'))));  } else {    window.localStorage.setItem(window.windowbtoa('list_journal'), (allbef == '' ? '' : window.windowbtoa(window.windowatob(allbef) + window.windowbtoax(',') + window.windowbtoax('" . explode('.',basename($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_GET['isname']))) . '-' . $_GET['isdob'] . '-' . $rand . '.html'))[0] . "'))));   }  }  ";
      }
    } else if (strlen($_GET['isdob']) == 0 && strlen($_GET['issecret']) > 0) {
       foreach (glob($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_GET['isname']))) . '-*-' . $_GET['issecret'] . '.*') as $fln) {
        $fcnt++;
        $afnd=$fln;
      }
      if ($fcnt == 1) {
        if (isset($_GET['fillif'])) { $fsuff=" if (1 == 1) { parent.document.getElementById('fjnamemore').value='" . explode('.',basename($afnd))[0] . "'; parent.document.getElementById('subfjnamemore').click();  } else {  parent.location.href='./journal.php?fjname=" . urlencode(explode('.',basename($afnd))[0]) . "'; } ";  }
        $fillins.=" parent.document.getElementById('ydob').value='" . explode('-', explode($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_GET['isname']))) . '-', $fln)[1])[0] . "'; " . $fsuff . " ";
      }
   } else if (strlen($_GET['isdob']) == 0 && strlen($_GET['issecret']) == 0) {
      foreach (glob($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_GET['isname']))) . '-*.*') as $fln) {
        $fcnt++;
        $afnd=$fln;
      }
      if ($fcnt == 1) {
        $fillins.=" parent.document.getElementById('ydob').value='" .    explode('-', explode($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_GET['isname']))) . '-', $fln)[1])[0] . "'; ";
        $fillins.=" parent.document.getElementById('ysecret').value='" . explode('.', explode($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_GET['isname']))) . '-' .explode('-', explode($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace(' ','_',str_replace('+',' ', urldecode($_GET['isname']))) . '-', $fln)[1])[0] . '-', $fln)[1])[0] . "'; ";
      }
    }
  }
  if (!$isdone && strlen($_GET['isdob']) > 0) {
    if (strlen($_GET['isname']) > 0 && strlen($_GET['issecret']) > 0) {
      $isdone=true;
    }
  }
  if (!$isdone && strlen($_GET['issecret']) > 0) {
    if (strlen($_GET['isname']) > 0 && strlen($_GET['isdob']) > 0) {
      $isdone=true;
    }
  }
  echo "<html><body onload=\"" . $fillins . "\"></body></html>";
  exit;
}

$none="none";
$jtitle="";
$jcont="";
$suffnum="";
if (isset($_GET['snum'])) {
  $suffnum=$_GET['snum'];
} else if (isset($_POST['snum'])) {
  $suffnum=$_POST['snum'];
} 
$dob="";
$yname="";
$open="";
$doneanddusted=false;

if (isset($_GET['fjname'])) {
  if (strlen($_GET['fjname']) > 0) {
  if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . basename(str_replace('+',' ',urldecode($_GET['fjname']))))) {
   $jcont=file_get_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . basename(str_replace('+',' ',urldecode($_GET['fjname']))));
   $jtitle=explode('.',basename(str_replace('+',' ',urldecode($_GET['fjname']))))[0];
   $none="block";
   $open=" open";
   $doneanddusted=true;
   if (sizeof(explode('-',$jtitle)) == 3) {
   $aname=str_replace('_',' ',explode('-', $jtitle)[0]);
   $adob=str_replace('_',' ',explode('-', $jtitle)[1]);
   $asecret=explode('.',str_replace('_',' ',explode('-', $jtitle)[2]))[0];
   }
  } else if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . basename(str_replace('+',' ',urldecode($_GET['fjname'])) . ".html"))) {
   $jcont=file_get_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . basename(str_replace('+',' ',urldecode($_GET['fjname'])) . ".html"));
   $jtitle=basename(str_replace('+',' ',urldecode($_GET['fjname'])));
   $none="block";
   $open=" open";
   $doneanddusted=true;
   if (sizeof(explode('-',$jtitle)) == 3) {
   $aname=str_replace('_',' ',explode('-', $jtitle)[0]);
   $adob=str_replace('_',' ',explode('-', $jtitle)[1]);
   $asecret=explode('.',str_replace('_',' ',explode('-', $jtitle)[2]))[0];
   }
  }
  }
}


if (isset($_POST['fjname'])) {
  if (strlen($_POST['fjname']) > 0) {
  if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . basename(str_replace('+',' ',urldecode($_POST['fjname']))))) {
   $jcont=file_get_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . basename(str_replace('+',' ',urldecode($_POST['fjname']))));
   $jtitle=explode('.',basename(str_replace('+',' ',urldecode($_POST['fjname']))))[0];
   $none="block";
   $open=" open";
   $vsb="hidden";   
   $doneanddusted=true;
   if (sizeof(explode('-',$jtitle)) == 3) {
   $aname=str_replace('_',' ',explode('-', $jtitle)[0]);
   $adob=str_replace('_',' ',explode('-', $jtitle)[1]);
   $asecret=explode('.',str_replace('_',' ',explode('-', $jtitle)[2]))[0];
   }
  } else if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . basename(str_replace('+',' ',urldecode($_POST['fjname'])) . ".html"))) {
   $jcont=file_get_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . basename(str_replace('+',' ',urldecode($_POST['fjname'])) . ".html"));
   $jtitle=basename(str_replace('+',' ',urldecode($_POST['fjname'])));
   $none="block";
   $open=" open";
   $vsb="hidden";   
   $doneanddusted=true;
   if (sizeof(explode('-',$jtitle)) == 3) {
   $aname=str_replace('_',' ',explode('-', $jtitle)[0]);
   $adob=str_replace('_',' ',explode('-', $jtitle)[1]);
   $asecret=explode('.',str_replace('_',' ',explode('-', $jtitle)[2]))[0];
   }
  }
  }
}

if (!$doneanddusted) {
if (isset($_GET['name']) && isset($_GET['dob'])) {
  if ($suffnum == '') {
  } else {
  }

} else if (isset($_GET['name'])) {

} else if (isset($_GET['dob'])) {
} else if (isset($_GET['fjname'])) {
  if (strlen($_GET['fjname']) > 0) {
  if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . basename(str_replace('+',' ',urldecode($_GET['fjname']))))) {
   $jcont=file_get_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . basename(str_replace('+',' ',urldecode($_GET['fjname']))));
   $jtitle=explode('.',basename(str_replace('+',' ',urldecode($_GET['fjname']))))[0];
   $none="block";
   $open=" open";
  } else if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . basename(str_replace('+',' ',urldecode($_GET['fjname'])) . ".html"))) {
   $jcont=file_get_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . basename(str_replace('+',' ',urldecode($_GET['fjname'])) . ".html"));
   $jtitle=basename(str_replace('+',' ',urldecode($_GET['fjname'])));
   $none="block";
   $open=" open";
  }
  }
}
}

echo "<html>
<head>
<title>Personal Journal - RJM Programming - January, 2026</title>
<meta charset=UTF-8/>
<style>
  button { color: blue; }
  input[type=\"submit\"] { color: blue; }
</style>
<scr" . "ipt type=text/javascript>

  var thissuff='';
  var nextsuff='2';
  var xfill='';
  var acontod=null, divelem=null, gtao=null;
  var startid='s0', endid='s';
  
  function windowatob(astr) { // decodes
    if (astr.indexOf('_') != -1 || astr.indexOf('-') != -1) {
      //alert(astr + ' decodes as ' + window.atob(astr));
      return astr;
    }
    //alert(astr + ' ' + window.atob(window.atob(astr)));
    var atb='';
    try {
      atb=window.atob(astr);
    } catch(fhyg) {
      if (1 == 4) { alert('Bad ' + astr); }
    }
    if (atb.indexOf('_') == -1 && atb.indexOf('-') == -1) { 
      try {
        var xcv=window.atob(atb);
      } catch(hyg) {
        if (1 == 4) { alert('bad ' + atb); }
        atb=astr;
      }
      return window.atob(atb); 
    }
    return window.atob(astr);
  }
  
  function windowbtoax(astr) { 
      return astr;
  }
  
  function windowbtoa(astr) { // encodes
    if ((astr.indexOf('_') != -1 || astr.indexOf('-') != -1) && astr != 'list_journal' && astr != 'unique_journal' && 2 == 5) {
      //alert(astr + ' encodes as ' + window.btoa(astr));
      return astr;
    }
    return window.btoa(astr);
  }

  function checkls() {
    document.getElementById('ytimestamp').value=('' + new Date());
    document.getElementById('posting').placeholder='Journal Entry for ' + document.getElementById('ytimestamp').value + ' goes here ...';
    var allbef=(('' + window.localStorage.getItem(window.windowbtoa('list_journal'))).replace(/^null/g,'').replace(/^undefined/g,''));
    var bef=(('' + window.localStorage.getItem(window.windowbtoa('unique_journal'))).replace(/^null/g,'').replace(/^undefined/g,''));
    if (allbef != '') {
      document.getElementById('divlist').style.display='block';
      document.getElementById('divlist').innerHTML=\"<select style=background-color:yellow; id=mysel onchange=gto(this);><option value=''>Optionally select a Journal of interest</option></select>\";
//alert('0:' + window.windowatob(allbef));
      var ljs=window.windowatob(allbef).split(',');
      for (var jls=0; jls<ljs.length; jls++) {
        document.getElementById('mysel').innerHTML+='<option value=' + ljs[jls] + '>' + ljs[jls].split('-')[0].replace(/\_/g,' ') + '</option>';
      }
    } else if (bef != '') {
      document.getElementById('divlist').style.display='block';
      document.getElementById('uniquej').style.display='block';
      document.getElementById('uniquej').innerHTML='Display Default Journal for ' + window.windowatob(bef).split('-')[0].replace(/\_/g,' ');
      document.getElementById('uniquej').title=window.windowatob(bef).split('-')[0].replace(/\_/g,' ');
    }
  }
  
  function getu() {
    document.getElementById('yname').value=document.getElementById('uniquej').title;
    setTimeout(function(){
    var eight=8;
    var allbef=(('' + window.localStorage.getItem(window.windowbtoa('list_journal'))).replace(/^null/g,'').replace(/^undefined/g,''));
    var bef=(('' + window.localStorage.getItem(window.windowbtoa('unique_journal'))).replace(/^null/g,'').replace(/^undefined/g,''));
    var huh=prompt('Please enter relevant 8 digit date of birth ( eg, 20041231 ) or 6 digit secret number', '');
    if (huh == null) { huh=''; }
    if (eval('' + huh.length) == 8 && (window.windowatob(bef) + window.windowatob(allbef)).indexOf(document.getElementById('yname').value.replace(/\ /g,'_') + '-' + huh + '-' + document.getElementById('sc').value) == -1 && (window.windowatob(bef) + window.windowatob(allbef)).indexOf(document.getElementById('yname').value.replace(/\ /g,'_') + '-' + huh + '-') != -1) {
      eight=-1;
      huh=prompt('Please enter 6 digit secret number', '');
      if (huh == null) { huh=''; }
    }
    if (eval('' + huh.length) == eight) {
      xfill='&fillif=ok';
      document.getElementById('ydob').value=huh;
      validatename(document.getElementById('yname'));
      xfill='';
    } else if (eval('' + huh.length) == 6) {
      xfill='&fillif=ok';
      document.getElementById('ysecret').value=huh;
      validatename(document.getElementById('yname'));
      xfill='';
    }
    }, 1000);
  }
  
  function gto(osel) {
    if (osel.value.trim() != '') {
    document.getElementById('yname').value=osel.value.split('-')[0].replace(/\_/g,' ')
    setTimeout(function(){
    var eight=8;
    var allbef=(('' + window.localStorage.getItem(window.windowbtoa('list_journal'))).replace(/^null/g,'').replace(/^undefined/g,''));
    var bef=(('' + window.localStorage.getItem(window.windowbtoa('unique_journal'))).replace(/^null/g,'').replace(/^undefined/g,''));
    var huh=prompt('Please enter relevant 8 digit date of birth ( eg, 20041231 ) or 6 digit secret number', '');
    if (huh == null) { huh=''; }
    if (eval('' + huh.length) == 8 && (window.windowatob(bef) + window.windowatob(allbef)).indexOf(document.getElementById('yname').value.replace(/\ /g,'_') + '-' + huh + '-' + document.getElementById('sc').value) == -1 && (window.windowatob(bef) + window.windowatob(allbef)).indexOf(document.getElementById('yname').value.replace(/\ /g,'_') + '-' + huh + '-') != -1) {
      eight=-1;
      huh=prompt('Please enter 6 digit secret number', '');
      if (huh == null) { huh=''; }
    }
    if (eval('' + huh.length) == eight) {
      xfill='&fillif=ok';
      document.getElementById('ydob').value=huh;
      validatename(document.getElementById('yname'));
      xfill='';
    } else if (eval('' + huh.length) == 6) {
      xfill='&fillif=ok';
      document.getElementById('ysecret').value=huh;
      validatename(document.getElementById('yname'));
      xfill='';
    }
    }, 1000);
    }
  }
  
  function preform() {
    document.getElementById('yname').value=document.getElementById('yname').value.replace(/\-/g,' ').replace(/\./g,' ').replace(/\,/g,' ').replace(/\'/g,'`').replace(/^\"/g,'').replace(/\"$/g,'').replace(/\"/g,'`');
    if (document.getElementById('yname').placeholder != '' && '" . $aname . "' != '' && document.getElementById('yname').value == '') {
      document.getElementById('yname').value=document.getElementById('yname').placeholder;
    }
    if (document.getElementById('ydob').placeholder != '' && '" . $adob . "' != '' && document.getElementById('ydob').value == '') {
      document.getElementById('ydob').value=document.getElementById('ydob').placeholder;
    }
    if (document.getElementById('ysecret').placeholder != '' && '" . $asecret . "' != '' && document.getElementById('ysecret').value == '') {
      document.getElementById('ysecret').value=document.getElementById('ysecret').placeholder;
    }
  }
  
  function afterscrutiny() {
    document.getElementById('yname').value=document.getElementById('yname').value.replace(/\-/g,' ').replace(/\./g,' ').replace(/\,/g,' ').replace(/\'/g,'`').replace(/^\"/g,'').replace(/\"$/g,'').replace(/\"/g,'`');
    if (document.getElementById('yname').placeholder != '' && '" . $aname . "' != '' && document.getElementById('yname').value == '') {
      document.getElementById('yname').value=document.getElementById('yname').placeholder;
    }
    if (document.getElementById('ydob').placeholder != '' && '" . $adob . "' != '' && document.getElementById('ydob').value == '') {
      document.getElementById('ydob').value=document.getElementById('ydob').placeholder;
    }
    if (document.getElementById('ysecret').placeholder != '' && '" . $asecret . "' != '' && document.getElementById('ysecret').value == '') {
      document.getElementById('ysecret').value=document.getElementById('ysecret').placeholder;
    }
    
    if (eval('' + document.getElementById('posting').value).length > 5000) {
      alert('Sorry, please make journal entry smaller ... up to 5000 characters');
      return false;
    }
  
    return true;
  }
  
  function domore() {
  }
  
  function validatename(otb) {
    document.getElementById('yname').value=document.getElementById('yname').value.replace(/\-/g,' ').replace(/\./g,' ').replace(/\,/g,' ').replace(/\'/g,'`').replace(/^\"/g,'').replace(/\"$/g,'').replace(/\"/g,'`');
    document.getElementById('helpout').src='./journal.php?isname=' + encodeURIComponent(otb.value.replace(/\ /g,'_')) + '&isdob=' + encodeURIComponent(document.getElementById('ydob').value) + '&issecret=' + encodeURIComponent(document.getElementById('ysecret').value) + xfill;
  }
  
  function validatedob(otb) {
    document.getElementById('helpout').src='./journal.php?isdob=' + encodeURIComponent(otb.value.replace(/\ /g,'_')) + '&isname=' + encodeURIComponent(document.getElementById('yname').value.replace(/\ /g,'_')) + '&issecret=' + encodeURIComponent(document.getElementById('ysecret').value) + xfill;
  }
  
  function validatesecret(otb) {
    document.getElementById('helpout').src='./journal.php?issecret=' + encodeURIComponent(otb.value.replace(/\ /g,'_')) + '&isdob=' + encodeURIComponent(document.getElementById('ydob').value) + '&isname=' + encodeURIComponent(document.getElementById('yname').value.replace(/\ /g,'_')) + xfill;
  }
  
  function wbt(taow,tao) {
    //alert(tao.value);
    if (acontod && tao) {
     if (!divelem) {
     document.getElementById('helpout').style.backgroundColor='yellow';
     document.getElementById('dcont').style.backgroundColor='yellow';
     divelem = acontod.getElementById('djc');
     gtao=tao;
     var recto = tao.getBoundingClientRect();
     if (divelem) { // thanks to ideas off http://stackoverflow.com/questions/12266320/copy-div-content-to-textarea-or-text-with-the-same-font-family-style
      divelem.style.display='flex';
    //divelem.style.alignItems='flex-end';
      divelem.style.overflowY='scroll';
      //divelem.style.flexFlow='column nowrap';
      divelem.style.flexDirection='column-reverse';
      divelem.style.fontFamily = window.getComputedStyle(tao,null).fontFamily || tao.style.fontFamily || tao.currentStyle.getCurrentProperty('font-family');
      divelem.style.fontSize = window.getComputedStyle(tao,null).fontSize || tao.style.fontSize || tao.currentStyle.getCurrentProperty('font-size');
      divelem.style.border = window.getComputedStyle(tao,null).border || tao.style.border || tao.currentStyle.getCurrentProperty('border');
      divelem.style.padding = window.getComputedStyle(tao,null).padding || tao.style.padding || tao.currentStyle.getCurrentProperty('padding');
      divelem.style.margin = window.getComputedStyle(tao,null).margin || tao.style.margin || tao.currentStyle.getCurrentProperty('margin');
      divelem.style.overflow = window.getComputedStyle(tao,null).overflow || tao.style.overflow || tao.currentStyle.getCurrentProperty('overflow');
      divelem.style.position='absolute';
      divelem.style.left='' + recto.left + 'px';
      divelem.style.width='' + eval(0 + recto.width) + 'px';
      divelem.style.height='' + recto.height + 'px';
      divelem.style.top='' + eval(-12 + recto.top) + 'px';
      //alert('' + recto.top + ' ' + recto.height + ' ' + ' ... ' + 'eval(-12 + recto.top + recto.height)=' + eval(-12 + recto.top + recto.height));
      //divelem.style.bottom='' + eval(-12 + recto.top + recto.height) + 'px';
      divelem.style.zIndex='999';
      divelem.scrollTop=divelem.scrollHeight;
      tao.style.color='transparent';
     }
     }
     var taovalue=tao.value.replace(/\</g,'&lt;').replace(/\>/g,'&gt;');
     while (taovalue.indexOf(String.fromCharCode(10)) != -1) {
      taovalue=taovalue.replace(String.fromCharCode(10),'<br>');
     }
     acontod.getElementById('djc').innerHTML='<div id=indiv title=\"Journal\" style=\"text-shadow:-0.5px 0.5px 0.5px #ff0000;background: linear-gradient(to right, #e0eafc, #ffffff);margin-top: auto !important;\">' + massage(taovalue) + '</div>';
    }
    return '';
  }
  
  function massage(tv) {
    var tscnt=0, itv=0;
    var tlls=tv.split('<br>');
    var tslist=[], selis='<select style=background-color:#fadadd; id=thesel onchange=\"if (this.value.length > 0) {  document.getElementById(this.value).scrollIntoView(); this.value=' + \"''\" + '; }\"><option value=></option></select>';
    for (itv=0; itv<tlls.length; itv++) {
      if (tlls[itv].indexOf(' GMT') != -1 && eval('' + tlls[itv].split(':').length) >= 3) {
        tslist.push(tlls[itv]);
        selis=selis.replace('</select>', '<option value=s' + tscnt + '>' + tlls[itv].replace(/\ /g,'  ') + '</option></select>');
        parent.endid='s' + tscnt;
        tscnt++;
      }
    }
    tscnt=0;
    var bprev='<button onclick=\"document.getElementById(' + \"'s'\" + ').scrollIntoView();\">&#x2196;&#xFE0F;</button>&nbsp;';
    var baftr='<button onclick=\"document.getElementById(' + \"'s'\" + ').scrollIntoView();\">&#x2198;&#xFE0F;</button>';
    for (itv=0; itv<tlls.length; itv++) {
      if (tlls[itv].indexOf(' GMT') != -1 && eval('' + tlls[itv].split(':').length) >= 3) {
        tv=tv.replace(tlls[itv], '<button onclick=\"document.getElementById(parent.startid).scrollIntoView();\">&#x2196;&#xFE0F; &#x2196;&#xFE0F;</button>&nbsp;' + bprev.replace('s',('s' + eval(-1 + tscnt)).replace('s-1','s0')) + selis.replace('thesel', 's' + tscnt).replace('>' +  tlls[itv].replace(/\ /g,'  ') + '<', ' selected>' +  tlls[itv].replace(/\ /g,'  ') + '<').replace('></', \"''>\" + tlls[itv].replace(/\ /g,'  ') + '</') + '&nbsp;' + baftr.replace('s',('s' + eval(1 + tscnt))) + '&nbsp;<button onclick=\"document.getElementById(parent.endid).scrollIntoView();\">&#x2198;&#xFE0F; &#x2198;&#xFE0F;</button>');
        tscnt++;
      }
    }
    return tv;
  }
  
  function rez(ota) {
     if (divelem && ota == gtao) { // thanks to ideas off http://stackoverflow.com/questions/12266320/copy-div-content-to-textarea-or-text-with-the-same-font-family-style
//alert(1);
      var recto = gtao.getBoundingClientRect();
      var jrecto = document.getElementById('jcont').getBoundingClientRect();
      var drecto = document.getElementById('dcont').getBoundingClientRect();
//alert(12);
//alert(31);
      if (eval('' + recto.width) > eval('' + drecto.width)) {
//alert(31);
        document.getElementById('dcont').style.width='' + eval(30 + eval('' + recto.width)) + 'px';
      }
       if (eval('' + recto.height) > eval('' + drecto.height)) {
//alert(31);
        document.getElementById('dcont').style.height='' + eval(30 + eval('' + recto.height)) + 'px';
      }
      if (eval('' + recto.width) > eval('' + jrecto.width)) {
//alert(41);
        document.getElementById('jcont').style.width='' + eval(20 + eval('' + recto.width)) + 'px';
      }
      if (eval('' + recto.height) > eval('' + jrecto.height)) {
//alert(41);
        document.getElementById('jcont').style.height='' + eval(20 + eval('' + recto.height)) + 'px';
      }
      divelem.style.left='' + recto.left + 'px';
//alert(41);
      divelem.style.width='' + eval(0 + recto.width) + 'px';
//alert(51);
      divelem.style.height='' + recto.height + 'px';
//alert(61);
      //divelem.style.top='' + eval(-12 + recto.top) + 'px';
      divelem.style.bottom='' + eval(-12 + recto.top + recto.height) + 'px';
      divelem.style.zIndex='999';
//alert(71);
      gtao.style.color='transparent';
//alert(81);
     }
  }
  
  function analtwo(vorh) {
    if (document.getElementById('vspan')) {
      document.getElementById('vspan').style.visibility=vorh;
    }
    return vorh;
  }
  
  function anal(vorh) {
    var lstf='';
    if (vorh.toLowerCase() == 'hidden' && document.getElementById('scont')) {
      if (document.getElementById('scont').innerHTML.indexOf('-') != -1) {
        lstf=document.getElementById('scont').innerHTML.split('-')[eval(-1 + document.getElementById('scont').innerHTML.split('-').length)];
        document.getElementById('scont').innerHTML=(document.getElementById('scont').innerHTML + '~').split('-' + lstf + '~')[0] + '-<span style=visibility:hidden; id=vspan>' + lstf + '</span>';
      }
    }
    return vorh;
  }

</scr" . "ipt>
</head>
<body onload=checkls();>
<table style=width:100%;><tr><td>
<details id=dcont style=width:98%;display:" . $none . ";" . $open . "><summary id=scont>" . $jtitle . "</summary> 
<iframe onload=\"acontod = (this.contentWindow || this.contentDocument);  if (acontod != null) {  if (acontod.document) { acontod = acontod.document; } } setTimeout(function(){ window.wbt(acontod,acontod.getElementById('jc'));  acontod.getElementById('jc').scrollTop=acontod.getElementById('jc').scrollHeight; }, 2000);\" frameborder=1 style='display:" . $none . ";width:98%;height:350px;' id=jcont name=jcont srcdoc=\"" . ($jcont == '' ? $jcont : '<html><head><meta charset=UTF-8 /><style> button { background-color:lightgreen; } </style></head><body><textarea onmousemove=parent.rez(this); id=jc style=width:98%;height:320px;background-color:#f0f0f0;>' . str_replace('"','&#34;',str_replace('>','&gt;',str_replace('<','&lt;',$jcont))) . '</textarea><div id=djc onmousemove=parent.rez(this);></div></body></html>') . "\"></iframe>
</details></td><td style='vertical-align:top;width:20%;background-color:#f5f5f5;'>
<h1>Journal</h1>
<h3>RJM Programming - February, 2026</h3>
<div id=divlist style=display:none;><button style=display:none;background-color:yellow; id=uniquej onclick=getu();></button></div>
</td></tr></table>
<br>
<hr>
<br>
<form style=background-color:#f9f9f9; onsubmit='return afterscrutiny();' action='./journal.php' method=POST target=jcont><input type=hidden name=fjname id=fjname value=''></input>
<input onfocus=\"document.getElementById('ysecret').style.visibility=analtwo('visible');\" style=background-color:lightgreen;width:30%; pattern='[^\.\,\-]+' onblur='validatename(this);' type=text id=yname name=name title='Journal Owner Name' placeholder='" . ($aname != '' ? $aname : 'Journal Owner Name') . "' value='' style=width:40%></input><br>
<input onfocus=\"document.getElementById('ysecret').style.visibility=analtwo('visible');\" style=background-color:lightgreen;width:30%; onblur='validatedob(this);' type=text pattern='[0-9]{8}' min=19700101 step=1 id=ydob name=dob title='Journal Owner Date of Birth eg. 20210112' placeholder='" . ($adob != '' ? $adob : 'Journal Owner Date of Birth eg. 20210112') . "' value='' style=width:40% required></input>&nbsp;&nbsp;<input type=submit value='Post to Journal' style=background-color:yellow; required></input><br>
<input style=background-color:lightgreen;width:30%;visibility:visible; onblur='validatesecret(this);' type=text pattern='[0-9]{6}' id=ysecret name=snum title='Journal Owner Secret 6 digit Number' placeholder='" . ($asecret != '' ? $asecret : 'Journal Owner Secret 6 digit Number') . "' value='' style=width:40% required></input><br>
<hr>
<input type=text id=ytimestamp name=timestamp placeholder='Journal Entry Timestamp' value='' style=width:40%;background-color:lightblue;></input><br><br>
<textarea oninput=\"if (eval('' + this.value.length) > eval('' + this.maxlength)) { alert('Content will be truncated to ' + this.maxlength + ' characters.');  }\" maxlength=5000 onblur='preform();' name=posting placeholder='' id=posting value='' style=width:80%;background-color:lightblue; rows=5></textarea>&nbsp;&nbsp;<button id=plus onclick=domore(); style=background-color:lightgreen;display:none;>+</button>
<div id=andmore></div>
</form>
<input type=hidden id=sc value='" . server_remote_addr(6) . "'></input>
<iframe onload=\"setTimeout(function(){ document.getElementById('ysecret').style.visibility=anal('" . $vsb . "'); }, 20000);\" src='./journal.php' id=helpout style='display:none;'></iframe>
<form style=display:none; action='./journal.php' method=POST target=_top><input type=hidden name=fjname id=fjnamemore value=''></input><input type=submit id=subfjnamemore value='Submit' style='display:none;'></input></form>
</body></html>
";
?>