<?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) { top.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] . "'; top.document.getElementById('subfjnamemore').click();  } else { top.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=top.windowbtoax(('' + window.localStorage.getItem(top.windowbtoa('list_journal'))).replace(/^null/g,'').replace(/^undefined/g,'')), bef=top.windowbtoax(('' + window.localStorage.getItem(top.windowbtoa('unique_journal'))).replace(/^null/g,'').replace(/^undefined/g,'')), vsbef=top.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(top.windowbtoa('unique_journal'), top.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(top.windowbtoa('list_journal'), (bef == '' ? '' : top.windowbtoa(top.windowatob(bef) + top.windowbtoax(',') + top.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(top.windowbtoa('list_journal'), (allbef == '' ? '' : top.windowbtoa(top.windowatob(allbef) + top.windowbtoax(',') + top.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) { top.document.getElementById('fjnamemore').value='" . explode('.',basename($afnd))[0] . "'; top.document.getElementById('subfjnamemore').click();  } else {  top.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=top.windowbtoax(('' + window.localStorage.getItem(top.windowbtoa('list_journal'))).replace(/^null/g,'').replace(/^undefined/g,'')), bef=top.windowbtoax(('' + window.localStorage.getItem(top.windowbtoa('unique_journal'))).replace(/^null/g,'').replace(/^undefined/g,'')), vsbef=top.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(top.windowbtoa('unique_journal'), top.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(top.windowbtoa('list_journal'), (bef == '' ? '' : top.windowbtoa((top.windowatob(bef) + top.windowbtoax(',') + top.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(top.windowbtoa('list_journal'), (allbef == '' ? '' : top.windowbtoa(top.windowatob(allbef) + top.windowbtoax(',') + top.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) { top.document.getElementById('fjnamemore').value='" . explode('.',basename($afnd))[0] . "'; top.document.getElementById('subfjnamemore').click();  } else {  top.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;
  
  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(top.windowbtoa('list_journal'))).replace(/^null/g,'').replace(/^undefined/g,''));
    var bef=(('' + window.localStorage.getItem(top.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:' + top.windowatob(allbef));
      var ljs=top.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 ' + top.windowatob(bef).split('-')[0].replace(/\_/g,' ');
      document.getElementById('uniquej').title=top.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(top.windowbtoa('list_journal'))).replace(/^null/g,'').replace(/^undefined/g,''));
    var bef=(('' + window.localStorage.getItem(top.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 && (top.windowatob(bef) + top.windowatob(allbef)).indexOf(document.getElementById('yname').value.replace(/\ /g,'_') + '-' + huh + '-' + document.getElementById('sc').value) == -1 && (top.windowatob(bef) + top.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(top.windowbtoa('list_journal'))).replace(/^null/g,'').replace(/^undefined/g,''));
    var bef=(('' + window.localStorage.getItem(top.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 && (top.windowatob(bef) + top.windowatob(allbef)).indexOf(document.getElementById('yname').value.replace(/\ /g,'_') + '-' + huh + '-' + document.getElementById('sc').value) == -1 && (top.windowatob(bef) + top.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);
    return '';
  }
  
  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(){ top.wbt(acontod,acontod.getElementById('jc'));  acontod.getElementById('jc').scrollTop=acontod.getElementById('jc').scrollHeight; }, 2000);\" frameborder=1 style='display:" . $none . ";width:97%;height:350px;' id=jcont name=jcont srcdoc=\"" . ($jcont == '' ? $jcont : '<html><head><meta charset=UTF-8 /></head><body><textarea id=jc style=width:98%;height:300px;background-color:#f0f0f0;>' . str_replace('"','&#34;',str_replace('>','&gt;',str_replace('<','&lt;',$jcont))) . '</textarea></body></html>') . "\"></iframe>
</details></td><td style='vertical-align:top;width:25%;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>
";
?>