<?php
// recipe_helper.php
// RJM Programming
// September, 2024
error_reporting(E_ERROR | E_PARSE);

$estitle='';
$hashurl=explode('#',explode('?', 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'])[0])[0] . '?rand=' . rand(6754,786754546);
$hashurld="";
$sharestr='';
$vertif='</tr><tr>';
$cookblurb=" Empty OK answer adds your Steps to recoverable personal list for you. Or hash delimited appended string can form a recoverable personal list title for this.";

function server_remote_addr() {
    $rma = $_SERVER['REMOTE_ADDR'];
    if (1 == 2) {
    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    // you can add different browsers with the same way ..
    if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua))
            $rma = '000000'.$rma;
    elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua))
            $rma = '00000'.$rma;
    elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua))
            $rma = '0000'.$rma;
    elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua))
            $rma = '000'.$rma;
    elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua))
            $rma = '00'.$rma;
    elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua))
            $rma = '0'.$rma;
    }
    return str_replace(":", "_", $rma);
}

function oururldecode($inth) {
  return str_replace(".+Z",". \nZ",str_replace(". Z",". \nZ",str_replace(".+Y",". \nY",str_replace(". Y",". \nY",str_replace(".+X",". \nX",str_replace(". X",". \nX",str_replace(".+W",". \nW",str_replace(". W",". \nW",str_replace(".+V",". \nV",str_replace(". V",". \nV",str_replace(".+U",". \nU",str_replace(". U",". \nU",str_replace(".+T",". \nT",str_replace(". T",". \nT",str_replace(".+S",". \nS",str_replace(". S",". \nS",str_replace(".+R",". \nR",str_replace(". R",". \nR",str_replace(".+Q",". \nQ",str_replace(". Q",". \nQ",str_replace(".+P",". \nP",str_replace(". P",". \nP",str_replace(".+O",". \nO",str_replace(". O",". \nO",str_replace(".+N",". \nN",str_replace(". N",". \nN",str_replace(".+M",". \nM",str_replace(". M",". \nM",str_replace(".+L",". \nL",str_replace(". L",". \nL",str_replace(".+K",". \nK",str_replace(". K",". \nK",str_replace(".+J",". \nJ",str_replace(". J",". \nJ",str_replace(".+I",". \nI",str_replace(". I",". \nI",str_replace(".+H",". \nH",str_replace(". H",". \nH",str_replace(".+G",". \nG",str_replace(". G",". \nG",str_replace(".+F",". \nF",str_replace(". F",". \nF",str_replace(".+E",". \nE",str_replace(". E",". \nE",str_replace(".+D",". \nD",str_replace(". D",". \nD",str_replace(".+C",". \nC",str_replace(". C",". \nC",str_replace(".+B",". \nB",str_replace(". B",". \nB",str_replace(".+A",". \nA",str_replace(". A",". \nA",str_replace('>','" . chr(62) . "',str_replace('<','" . chr(60) . "',   str_replace("$",'" . chr(36) . "',str_replace("\n",'" . chr(10) . "',str_replace('"','" . chr(34) . "',urldecode($inth))))   )))) ))))))))))))))))))))))))))))))))))))))))))))))))));
}

$dtt='';
$lhdtt='';
$dttmid='';
$downloaddefname='';
$results='';
$interimtitle='My Steps';
$dtitle="Overall instructions, perhaps incorporating a title='[Iframe Save As downloading default name basis]' and first URL can be a node with a link, can be typed here after you double click on border to clear the contents.";
$origdt=$dtitle;
if (isset($_POST['dtitle']) || isset($_GET['dtitle'])) {
  $dtitle=(isset($_POST['dtitle']) ? str_replace('+',' ',urldecode($_POST['dtitle'])) : '') . (isset($_GET['dtitle']) ? str_replace('+',' ',urldecode($_GET['dtitle'])) : '');
  if (isset($_POST['dtitle'])) {
   $hashurld.='#dtitle=' . $_POST['dtitle'];
   if (strrpos($dtitle, "itle='") !== false) {
    $estitle=explode("'", explode("itle='", $dtitle)[1])[0];
   } else if (strrpos($dtitle, 'itle="') !== false) {
    $estitle=explode('"', explode('itle="', $dtitle)[1])[0];
   } else if (strrpos($dtitle, 'itle=') !== false) {
    $estitle=explode("\n", explode('<', explode(' ', explode('itle=', $dtitle)[1])[0])[0])[0];
   }
  } else if (isset($_GET['dtitle'])) {
   $hashurld.='#dtitle=' . $_GET['dtitle'];
   if (strrpos($dtitle, "itle='") !== false) {
    $estitle=explode("'", explode("itle='", $dtitle)[1])[0];
   } else if (strrpos($dtitle, 'itle="') !== false) {
    $estitle=explode('"', explode('itle="', $dtitle)[1])[0];
   } else if (strrpos($dtitle, 'itle=') !== false) {
    $estitle=explode("\n", explode('<', explode(' ', explode('itle=', $dtitle)[1])[0])[0])[0];
   }
  }
  $dtt="\n/* " . str_replace("\n","~~",str_replace('*/','  ',str_replace('/*','  ',$dtitle))) . " */\n";
  $lhdtt="dtitle=" . str_replace("\n","~~",str_replace('*/','  ',str_replace('/*','  ',$dtitle)));
  if (strpos($dtt, 'itle="') !== false) {
  $interimtitle=explode('"',explode('itle="', $dtt)[1])[0];
  if (strpos($dtitle, 'http') !== false) {
  $dttmid="\n\$attr = array(
     'URL' => 'http" . str_replace("\r","",str_replace("\n","",explode("~~",explode("\\n",explode("\n",explode('"',explode("'",explode('>',explode(' ',explode('http', $dtitle)[1])[0])[0])[0])[0])[0])[0])[0])) . "',
     'shape' => 'box'
);\n\n\$gv->addNode('" . str_replace("'","`",$interimtitle) . "' , \$attr); \n\n";
  } else if (strpos($dtitle, 'HTTP') !== false) {
  $dttmid="\n\$attr = array(
     'URL' => 'HTTP" . str_replace("\r","",str_replace("\n","",explode("~~",explode("\\n",explode("\n",explode('"',explode("'",explode('>',explode(' ',explode('HTTP', $dtitle)[1])[0])[0])[0])[0])[0])[0])[0])) . "',
     'shape' => 'box'
);\n\n\$gv->addNode('" . str_replace("'","`",$interimtitle) . "' , \$attr); \n\n";
  }
  $downloaddefname=$_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "recipe_helper_" . str_replace(' ','_',explode('"',explode('itle="', $dtt)[1])[0]) . '.php';
  if (file_exists($downloaddefname)) {
    $downloaddefname='';
  }
  
  } else if (strpos($dtt, "itle='") !== false) {
  $interimtitle=explode("'",explode("itle='", $dtt)[1])[0];
  if (strpos($dtitle, 'http') !== false) {
  $dttmid="\n\$attr = array(
     'URL' => 'http" . str_replace("\r","",str_replace("\n","",explode("~~",explode("\\n",explode("\n",explode('"',explode("'",explode('>',explode(' ',explode('http', $dtitle)[1])[0])[0])[0])[0])[0])[0])[0])) . "',
     'shape' => 'box'
);\n\n\$gv->addNode('" . str_replace("'","`",$interimtitle) . "' , \$attr); \n\n";
  } else if (strpos($dtitle, 'HTTP') !== false) {
  $dttmid="\n\$attr = array(
     'URL' => 'HTTP" . str_replace("\r","",str_replace("\n","",explode("~~",explode("\\n",explode("\n",explode('"',explode("'",explode('>',explode(' ',explode('HTTP', $dtitle)[1])[0])[0])[0])[0])[0])[0])[0])) . "',
     'shape' => 'box'
);\n\n\$gv->addNode('" . str_replace("'","`",$interimtitle) . "' , \$attr); \n\n";
  }
  $downloaddefname=$_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "recipe_helper_" . str_replace(' ','_',explode("'",explode("itle='", $dtt)[1])[0]) . '.php';
  if (file_exists($downloaddefname)) {
    $downloaddefname='';
  }
  } else if (strpos($dtt, "itle=") !== false) {
  $interimtitle=explode(">",explode(" ",explode("itle=", $dtt)[1])[0])[0];
  if (strpos($dtitle, 'http') !== false) {
  $dttmid="\n\$attr = array(
     'URL' => 'http" . str_replace("\r","",str_replace("\n","",explode("~~",explode("\\n",explode("\n",explode('"',explode("'",explode('>',explode(' ',explode('http', $dtitle)[1])[0])[0])[0])[0])[0])[0])[0])) . "',
     'shape' => 'box'
);\n\n\$gv->addNode('" . str_replace("'","`",$interimtitle) . "' , \$attr); \n\n";
  } else if (strpos($dtitle, 'HTTP') !== false) {
  $dttmid="\n\$attr = array(
     'URL' => 'HTTP" . str_replace("\r","",str_replace("\n","",explode("~~",explode("\\n",explode("\n",explode('"',explode("'",explode('>',explode(' ',explode('HTTP', $dtitle)[1])[0])[0])[0])[0])[0])[0])[0])) . "',
     'shape' => 'box'
);\n\n\$gv->addNode('" . str_replace("'","`",$interimtitle) . "' , \$attr); \n\n";
  }
  $downloaddefname=$_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "recipe_helper_" . str_replace(' ','_',explode(">",explode(" ",explode("itle=", $dtt)[1])[0])[0]) . '.php';
  if (file_exists($downloaddefname)) {
    $downloaddefname='';
  }
  }


}

$base_recipe="";
$morerecs="";
$newedge="\$gv->addEdge(array(\"\" => \"\")); \n";
$tmpphpname='/tmp/recipe_' . server_remote_addr() . ".php";

if (isset($_POST['step1'])) {
$base_recipe="
<?php
require_once 'Image/GraphViz.php';
error_reporting(E_ERROR | E_PARSE); " . $dtt . "

\$gv = new Image_GraphViz(); " . $dttmid . "
\$gv->addEdge(array(\"" . (isset($_POST['step1']) ? str_replace('+',' ',oururldecode($_POST['step1'])) : '') . "\" => \"" . (isset($_POST['step2']) ? str_replace('+',' ',oururldecode($_POST['step2'])) : '') . "\"));\n" . $morerecs . "\n
\$gv->image();
?>";
  $hashurl.='#step1=' . $_POST['step1'];
  if (isset($_POST['step2'])) {
   $hashurl.='#step2=' . $_POST['step2'];
  } 
} else if (isset($_GET['step1'])) {
$base_recipe="
<?php
require_once 'Image/GraphViz.php';
error_reporting(E_ERROR | E_PARSE); " . $dtt . "

\$gv = new Image_GraphViz(); " . $dttmid . "
\$gv->addEdge(array(\"" . (isset($_GET['step1']) ? str_replace('+',' ',oururldecode($_GET['step1'])) : '') . "\" => \"" . (isset($_GET['step2']) ? str_replace('+',' ',oururldecode($_GET['step2'])) : '') . "\"));\n" . $morerecs . "\n
\$gv->image();
?>";
  $hashurl.='#step1=' . $_GET['step1'];
  if (isset($_GET['step2'])) {
   $hashurl.='#step2=' . $_GET['step2'];
  }
}

$three=3;
while (isset($_POST['step' . $three])) {
 $hashurl.='#step' . $three . '=' . $_POST['step' . $three];
 if (strlen(trim( (isset($_POST['step' . (-1 + $three)]) ? str_replace('+',' ',oururldecode($_POST['step' . (0 + $three)])) : '') )) > 0) {
 $amore="\$gv->addEdge(array(\"" . (isset($_POST['step' . (-1 + $three)]) ? str_replace('+',' ',oururldecode($_POST['step' . (-1 + $three)])) : '') . "\" => \"" . (isset($_POST['step' . (0 + $three)]) ? str_replace('+',' ',oururldecode($_POST['step' . (0 + $three)])) : '') . "\"));\n";
 if (strpos($amore, '""') === false) {
 $morerecs.=$amore;
 }
 $base_recipe="
<?php
require_once 'Image/GraphViz.php';
error_reporting(E_ERROR | E_PARSE); " . $dtt . "

\$gv = new Image_GraphViz(); " . $dttmid . "
\$gv->addEdge(array(\"" . (isset($_POST['step1']) ? str_replace('+',' ',oururldecode($_POST['step1'])) : '') . "\" => \"" . (isset($_POST['step2']) ? str_replace('+',' ',oururldecode($_POST['step2'])) : '') . "\"));\n" . $morerecs . "\n
\$gv->image();
?>";
 }
 $three++;
}
$three=3;
while (isset($_GET['step' . $three])) {
 $hashurl.='#step' . $three . '=' . $_GET['step' . $three];
 if (strlen(trim( (isset($_GET['step' . (-1 + $three)]) ? str_replace('+',' ',oururldecode($_GET['step' . (0 + $three)])) : '') )) > 0) {
 $amore="\$gv->addEdge(array(\"" . (isset($_GET['step' . (-1 + $three)]) ? str_replace('+',' ',oururldecode($_GET['step' . (-1 + $three)])) : '') . "\" => \"" . (isset($_GET['step' . (0 + $three)]) ? str_replace('+',' ',oururldecode($_GET['step' . (0 + $three)])) : '') . "\"));\n";
 if (strpos($amore, '""') === false) {
 $morerecs.=$amore;
 }
 $base_recipe="
<?php
require_once 'Image/GraphViz.php';
error_reporting(E_ERROR | E_PARSE); " . $dtt . "

\$gv = new Image_GraphViz(); " . $dttmid . "
\$gv->addEdge(array(\"" . (isset($_GET['step1']) ? str_replace('+',' ',oururldecode($_GET['step1'])) : '') . "\" => \"" . (isset($_GET['step2']) ? str_replace('+',' ',oururldecode($_GET['step2'])) : '') . "\"));\n" . $morerecs . "\n
\$gv->image();
?>";
 }
 $three++;
}

if ($base_recipe != '') {

if (file_exists($tmpphpname)) {
  exec('rm -f ' . $tmpphpname);
  if (file_exists($tmpphpname)) {
  unlink($tmpphpname);
  }
}
file_put_contents($tmpphpname, $base_recipe);
exec('chmod 777 ' . $tmpphpname . ' ; chgrp rjmprogr ' . $tmpphpname . ' ; chown rjmprogr ' . $tmpphpname);
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . basename($tmpphpname))) {
  exec('ln -s ' . $tmpphpname . ' ' . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . basename($tmpphpname));
}

if (1 == 1) {
if ($downloaddefname != '') {
  exec('ln -s ' . $tmpphpname . ' ' . $downloaddefname);
  if (file_exists($downloaddefname)) {
    $results='<iframe style=width:100%;height:100%; src="/' . basename($downloaddefname) . '"></iframe>';
  } else {
    $results='<iframe style=width:100%;height:100%; src="/' . basename($tmpphpname) . '"></iframe>';
  }
} else {
  $results='<iframe style=width:100%;height:100%; src="/' . basename($tmpphpname) . '"></iframe>';
}
} else {
header('Location: /' . basename($tmpphpname));
exit;
}
}

if ($results == '') {
  if (file_exists('/tmp/' . basename($tmpphpname))) {
    $phpcont=file_get_contents('/tmp/' . basename($tmpphpname));
    if (strpos($phpcont, "\n/* ") !== false && $origdt == $dtitle) {
      $dtitle=str_replace("~~","\n",explode("\n", explode(" */", explode("\n/* ", $phpcont)[1])[0])[0]);
    } else if (strpos($phpcont, "\n// ") !== false && $origdt == $dtitle) {
      $dtitle=str_replace("~~","\n",explode("\n", explode("\n// ", $phpcont)[1])[0]);
    } 
    $results='<iframe title="' . (isset($dtitle) ? $dtitle : '') . '" style=width:100%;height:100%; src="/' . basename($tmpphpname) . '"></iframe>';
  } else {
    $results='<iframe title="' . (isset($dtitle) ? $dtitle : '') . '" style=width:100%;height:100%; src="/simple_recipe.php"></iframe>';
  }
}


echo "<html>
<head>
<title>My Recipe Steps - RJM Programming - September, 2024</title>
<style>
  th { vertical-align: top; }
  #results {  border-left:3px solid yellow; border-top:3px solid yellow;  border-bottom:3px solid yellow; overflow: scroll; text-align: left;  }
</style>
<scr" . "ipt type=text/javascript>
  var estitle=\"" . $estitle . "\"; 
  var templtd='';
  var thesteps=[];
  var anyhashes='';
  var aone=1;
  var tdc=0;
  var cookb=\"" . $cookblurb . "\"; 
  var lssel='';
  var woo=null;
  var mysubject='', myurl='';
  var lastemail='', lastsms='';
 
function deleteAVal(goodname, aparticularvalue) {
 if (window.localStorage && goodname.indexOf('steps_') == 0) {
      if (('' + localStorage.getItem(goodname)).replace(/^undefined/g,'').replace(/^null/g,'') != '') {
        if (aparticularvalue == '') {
        localStorage.removeItem(goodname);
        } else {
        if (aparticularvalue.replace('HTTP','http').toLowerCase() == ('' + localStorage.getItem(goodname)).toLowerCase()) {
        localStorage.removeItem(goodname);
        }
        }
      }
 }
}

function setAVal(cName, cVal) {
 if (cName.indexOf('steps_') == 0) {
   if (window.localStorage) {
    localStorage.setItem(cName, encodeURIComponent(cVal));
    cookieAVal('steps_', true);
    return ' ';
   }
   return '';
 }
 return '';
}

function gotothis(inu) {
  if (inu.trim() != '') {
   if (inu.indexOf('HttP') == 0) {
     mysubject='Steps';
     if (inu.indexOf('#') != -1) {
     mysubject=inu.split('#')[eval(-1 + inu.split('#').length)].replace(/^steps\_/g,'').replace(/\_/g,' ').replace(/\-/g,' ');
     if (mysubject.trim() == '') { mysubject='Steps'; }
     }
     myurl=inu.replace('HttP','http').replace(/\ /g,'%20');
     emailit('');
   } else if (inu.indexOf('HTTP') == 0) {
     //alert('2:' + inu);
     if (inu.indexOf('#steps_') != -1) {
     //alert('22:' + inu.split('#')[eval(-1 + inu.split('#').length)]);
       deleteAVal(inu.split('#')[eval(-1 + inu.split('#').length)], encodeURIComponent(inu.replace('#' + inu.split('#')[eval(-1 + inu.split('#').length)], '').replace('HTTP','http')));
     //alert('222:' + inu.split('#')[eval(-1 + inu.split('#').length)]);
       cookieAVal('steps_', true);
     //alert('2222:' + inu.split('#')[eval(-1 + inu.split('#').length)]);
     }
   } else {
     woo=window.open(inu.replace(/\ /g,'%20'), '_blank', 'top=50,left=50,width=800,height=800');
   }
  }
}

function cookieAVal(cName, selize) {
 var key=null;
 if (selize && window.localStorage) {
  lssel=' ';
  for (var i=0; i<localStorage.length; i++) { // thanks to https://stackoverflow.com/questions/41271092/how-to-loop-through-localstorage-values       
   key = localStorage.key(i);
   if (('' + key).indexOf(cName) == 0) {
     if (lssel.trim() == '') {
       lssel='<select id=sells onchange=gotothis(this.value);><option value=\"\">Recallable Steps below ...</option></select>';
     }
     lssel=lssel.replace('</select>', '<option value=\"' + decodeURIComponent(localStorage.getItem('' + key)) + '\">' + ('' + key).substring(eval('' + cName.length)).replace(/\_/g,' ').replace(/\-/g,' ') + '</option>' + '<option value=\"' + decodeURIComponent(localStorage.getItem('' + key).replace('http','HTTP')) + '#steps_' + ('' + key).substring(eval('' + cName.length)) + '\">Remove ' + ('' + key).substring(eval('' + cName.length)).replace(/\_/g,' ').replace(/\-/g,' ') + '</option>' + '<option value=\"' + decodeURIComponent(localStorage.getItem('' + key).replace('http','HttP')) + '#steps_' + ('' + key).substring(eval('' + cName.length)) + '\">Email or SMS ' + ('' + key).substring(eval('' + cName.length)).replace(/\_/g,' ').replace(/\-/g,' ') + '</option>' + '</select>');
   }
  }
  if (lssel != '') {
   document.getElementById('ssel').innerHTML=lssel.trim();
  }
 }
 if (cName.indexOf('steps_') == 0) {
   if (window.localStorage) {
    if (decodeURIComponent(('' + localStorage.getItem(cName)).replace(/^undefined/g,'').replace(/^null/g,'')) != '') {
     return decodeURIComponent(localStorage.getItem(cName));
    }
    if (decodeURIComponent(('' + sessionStorage.getItem(cName)).replace(/^undefined/g,'').replace(/^null/g,'')) != '') {
     return decodeURIComponent(sessionStorage.getItem(cName));
    }
   }
   return '';
 }
 return '';
}
  
function nuance(insg) {
  if (insg.indexOf(\"title='\") != -1) {
    estitle=insg.split(\"title='\")[1].split(\"'\")[0];
  } else if (insg.indexOf('title=\"') != -1) {
    estitle=insg.split('title=\"')[1].split('\"')[0];
  } else if (insg.indexOf('title=') != -1) { 
    estitle=insg.split('title=')[1].split('<')[0].split(' ')[0].split(String.fromCharCode(10))[0];
  }
  if (estitle != '') {
    document.getElementById('pcookie').style.display='inline-block';
    cookb=cookb.replace(cookb.split(' Or hash delimited appended string can ')[0], 'Empty OK answer adds your Steps to recoverable personal list, with the title ... ' + estitle + ' ... for you.');
  }
  return insg;
}

function emailit(insg) {
   var em='', ccok='';
   if (estitle == '') {
     if (cookb.split(' Or hash delimited appended string can ')[0] != '') {
      cookb=cookb.replace(cookb.split(' Or hash delimited appended string can ')[0], '');
     }
   }
   if (('' + insg).replace(/^null/g,'').replace(/^undefined/g,'').trim() != '') { 
   em='' + insg;
   } else if (myurl != '' && mysubject != '') {
   em=prompt('Please enter Email address or SMS number to share ' + mysubject + ' with.' + (' ' + cookb).substring(0,1) + ' Hash separate an email subject that is not as suggested.', (lastemail != '' ? lastemail : lastsms));
   if (em != null) {
   if (em.indexOf('#') != -1) {
     mysubject=em.substring(eval(1 + eval('' + em.indexOf('#'))));
     em=em.split('#')[0].trim();
   }
   }
   } else {
   em=prompt('Please enter Email address to share with. ' + cookb, lastemail);
   }
   if (em != null) {
     if (em.trim() == '' && estitle != '') {
       em='#' + estitle;
     } else if (em == estitle && estitle != '') {
       em='#' + estitle;
     }
   }
   if (em.indexOf('#') != -1) {
     cook=em.substring(eval(1 + eval('' + em.indexOf('#'))));
     em=em.split('#')[0].trim();
     if (cook.trim() != '') {
        deleteAVal('steps_' + cook.replace(/\ /g,'-'),'');
        setAVal('steps_' + cook.replace(/\ /g,'-'), \"" . str_replace('+',' ',$hashurl) . $hashurld . "\".replace(/\ /g,'%20') + anyhashes.replace(/\ /g,'%20'));
     }
   }
   if (em == null) { em=''; }
   if (em.trim() != '') {
     if (em.trim().indexOf('@') != -1) {
     if (myurl != '' && mysubject != '') {
     em+='?subject=' + encodeURIComponent(mysubject) + '&body=' + encodeURIComponent(myurl);
     myurl='';
     mysubject='';
     } else {
     //console.log(\"" . $hashurl . $hashurld . "\" + anyhashes + ' anyhashes=' + anyhashes + ' and hashurld=' + \"" . $hashurld . "\");
     em+='?subject=Steps&body=' + encodeURIComponent(\"" . $hashurl . $hashurld . "\".replace(/\ /g,'%20') + anyhashes.replace(/\ /g,'%20'));
     }
     document.getElementById('dimap').innerHTML=\"<a style=display:none; id=theaemail target=_blank href='mailto:\" + em + \"'>Email</a>\";
     lastemail=em.trim().split('?')[0].split('&')[0];
     document.getElementById('theaemail').click();
     } else if (em.trim().replace(/0/g,'').replace(/1/g,'').replace(/2/g,'').replace(/3/g,'').replace(/4/g,'').replace(/5/g,'').replace(/6/g,'').replace(/7/g,'').replace(/8/g,'').replace(/9/g,'') == '') {
     if (myurl != '' && mysubject != '') {
     em+='&body=' + encodeURIComponent(myurl);
     myurl='';
     mysubject='';
     } else {
     em+='&body=' + encodeURIComponent(\"" . $hashurl . $hashurld . "\".replace(/\ /g,'%20') + anyhashes.replace(/\ /g,'%20'));
     }
     document.getElementById('dimap').innerHTML=\"<a style=display:none; id=theasms target=_blank href='sms:\" + em + \"'>SMS</a>\";
     lastsms=em.trim().split('?')[0].split('&')[0];
     document.getElementById('theasms').click();
     }
   }
   myurl='';
   mysubject='';
   return false;

}

function smsit(insg) {
   var em='', cook='';
   if (estitle == '') {
     if (cookb.split(' Or hash delimited appended string can ')[0] != '') {
      cookb=cookb.replace(cookb.split(' Or hash delimited appended string can ')[0], '');
     }
   }
   if (('' + insg).replace(/^null/g,'').replace(/^undefined/g,'').trim() != '') { 
   em='' + insg;
   } else {
   em=prompt('Please enter SMS number to share with. ' + cookb, lastsms);
   }
   if (em != null) {
     if (em.trim() == '' && estitle != '') {
       em='#' + estitle;
     } else if (em == estitle && estitle != '') {
       em='#' + estitle;
     }
   }
   if (em.indexOf('#') != -1) {
     cook=em.substring(eval(1 + eval('' + em.indexOf('#'))));
     em=em.split('#')[0].trim();
     if (cook.trim() != '') {
        deleteAVal('steps_' + cook.replace(/\ /g,'-'),'');
        setAVal('steps_' + cook.replace(/\ /g,'-'), \"" . $hashurl . $hashurld . "\".replace(/\ /g,'%20') + anyhashes.replace(/\ /g,'%20'));
     }
   } 
   if (em == null) { em=''; }
   if (em.trim() != '') {
     if (em.trim().replace(/0/g,'').replace(/1/g,'').replace(/2/g,'').replace(/3/g,'').replace(/4/g,'').replace(/5/g,'').replace(/6/g,'').replace(/7/g,'').replace(/8/g,'').replace(/9/g,'') == '') {
     em+='&body=' + encodeURIComponent(\"" . $hashurl . $hashurld . "\".replace(/\ /g,'%20') + anyhashes.replace(/\ /g,'%20'));
     document.getElementById('dimap').innerHTML=\"<a style=display:none; id=theasms target=_blank href='sms:\" + em + \"'>SMS</a>\";
     lastsms=em.trim().split('?')[0].split('&')[0];
     document.getElementById('theasms').click();
     } else if (em.trim().indexOf('@') != -1) {
     em+='?subject=Steps&body=' + encodeURIComponent(\"" . $hashurl . $hashurld . "\".replace(/\ /g,'%20') + anyhashes.replace(/\ /g,'%20'));
     document.getElementById('dimap').innerHTML=\"<a style=display:none; id=theaemail target=_blank href='mailto:\" + em + \"'>Email</a>\";
     lastemail=em.trim().split('?')[0].split('&')[0];
     document.getElementById('theaemail').click();
     } 
   }
   return false;
}

  function danalyze(dio) {
    if (dio.innerHTML.indexOf('<iframe') != 0) {
    document.getElementById('therest').name='dtitle';
    document.getElementById('therest').value=nuance('' + dio.innerText); //(dio.innerText | dio.contentWindow | dio.contentDocument);
    anyhashes=anyhashes.replace('dtitle=', 'dtiOLDtle=') + '#dtitle=' + encodeURIComponent(dio.innerText);
    document.getElementById('pcookie').style.display='inline-block';
    }
  }

  function obl(tdio, viahash) {
    var ij=0;
    var thisi=eval(('' + tdio.id).replace('tdi',''));
    var arrtd=document.getElementsByTagName('input');
    arrtd=document.getElementsByTagName('textarea');
    var tarrtd=document.getElementsByTagName('td');
    tdc=eval('' + tarrtd.length);
    if (tdio.value.trim() == '') {  return ''; }
    if (!viahash) {
    //alert('anyhashes=' + anyhashes + ' will become ' + anyhashes.replace('step' + thisi + '=', 'steOLDp' + thisi + '=') + '#step' + thisi + '=' + encodeURIComponent(tdio.value));
    anyhashes=anyhashes.replace('step' + thisi + '=', 'steOLDp' + thisi + '=') + '#step' + thisi + '=' + encodeURIComponent(tdio.value);
    document.getElementById('pcookie').style.display='inline-block';
    }
    //alert(tdio.value.indexOf(String.fromCharCode(10)));
    thesteps=[];
    for (ij=0; ij<tarrtd.length; ij++) {
      thesteps.push('' + arrtd[ij].value);
      //console.log(thesteps);
    }
    //if (thisi != tdc && thisi > 1) { alert('thisi=' + thisi + ' and tdc=' + tdc); } 
    if (thisi == tdc || 1 == 1) {
    //if (thisi == tdc && thisi > 1) { alert('thisI=' + thisi + ' and tdC=' + tdc); } 
      //document.getElementById('myrec').innerHTML+=templtd.replace(/td1/g, 'td' + eval(1 + tdc)).replace(/tdi1/g, 'tdi' + eval(1 + tdc)).replace(/tep1/g, 'tep' + eval(1 + tdc)) + '" . $vertif . "';
      document.getElementById('mytable').innerHTML+=templtd.replace(/td1/g, 'td' + eval(1 + tdc)).replace(/tdi1/g, 'tdi' + eval(1 + tdc)).replace(/tep1/g, 'tep' + eval(1 + tdc)) + '" . $vertif . "';
      //alert('templtd=' + templtd + ' ' + document.getElementById('myrec').innerHTML);
      for (ij=1; ij<=tarrtd.length; ij++) {
        //alert('ij=' + ij + ' and thesteps[eval(-1 + ij)]=' + thesteps[eval(-1 + ij)]);
        if (eval(-1 + ij) < thesteps.length) {
          document.getElementById('tdi' + ij).value=('' + thesteps[eval(-1 + ij)]).replace(/^undefined/g, '');
        }
      }
      if (!viahash) {
      setTimeout(function() {
      if (document.getElementById('tdi' + eval(-1 + tdc))) {
      if (document.getElementById('tdi' + eval(-1 + tdc)).value == '') {
      document.getElementById('tdi' + eval(-1 + tdc)).focus();
      } else {
      document.getElementById('tdi' + eval(0 + tdc)).focus();
      }
      } else if (document.getElementById('tdi' + eval(0 + tdc))) {
      document.getElementById('tdi' + eval(0 + tdc)).focus();
      } else {
      document.getElementById('tdi' + eval(-1 + tdc)).focus();
      }
      console.log('There2');
      }, 1000);
      } else {
      if (document.getElementById('tdi' + eval(0 + tdc))) {
      document.getElementById('tdi' + eval(0 + tdc)).focus();
      } else {
      document.getElementById('tdi' + eval(-1 + tdc)).focus();
      }
      console.log('TherE2');
      }
    }
    return true;
  }
  
  function checkforlh() {
    var ifs=[], jifs=0;
    var eneqs=encodeURIComponent('=');
    var noneqs=encodeURIComponent('=').toLowerCase();
    if (noneqs == eneqs) { noneqs=eneqs.toUpperCase(); }
    aone=1;
    if (estitle != '') { document.getElementById('pcookie').style.display='inline-block';  }
    if ((('' + location.hash) + (\"" . $lhdtt . "\")).indexOf('dtitle') != -1) {
    if ((('' + location.hash) + (\"" . $lhdtt . "\")).indexOf('dtitle=') != -1) {
//alert(1);
      document.getElementById('therest').value=nuance(decodeURIComponent((('' + location.hash) + (\"" . $dtt . "\")).split('dtitle=')[1].split('#')[0].split(encodeURIComponent('#'))[0].replace(/\~\~/g, String.fromCharCode(10))));
//alert(document.getElementById('therest').value);
      document.getElementById('therest').name='dtitle';
      document.getElementById('results').title=document.getElementById('therest').value;
      document.body.title=document.getElementById('therest').value;
    } else if ((('' + location.hash) + (\"" . $lhdtt . "\")).indexOf('dtitle' + eneqs) != -1) {
//alert(11);
      document.getElementById('therest').value=nuance(decodeURIComponent((('' + location.hash) + (\"" . $lhdtt . "\")).split('dtitle' + eneqs)[1].split('#')[0].split(encodeURIComponent('#'))[0].replace(/\~\~/g, String.fromCharCode(10))));
      document.getElementById('therest').name='dtitle';
      document.getElementById('results').title=document.getElementById('therest').value;
      document.body.title=document.getElementById('therest').value;
//alert(document.getElementById('therest').value);
    } else if ((('' + location.hash) + (\"" . $lhdtt . "\")).indexOf('dtitle' + noneqs) != -1) {
//alert(111);
      document.getElementById('therest').value=nuance(decodeURIComponent((('' + location.hash) + (\"" . $lhdtt . "\")).split('dtitle' + noneqs)[1].split('#')[0].split(encodeURIComponent('#'))[0].replace(/\~\~/g, String.fromCharCode(10))));
      document.getElementById('therest').name='dtitle';
      document.getElementById('results').title=document.getElementById('therest').value;
      document.body.title=document.getElementById('therest').value;
//alert(document.getElementById('therest').value);
    }
    }
    
    var retv='';
    while (('' + location.hash.indexOf('step' + aone)) != -1) {
    if (('' + location.hash.indexOf('step' + aone + '=')) != -1) {
    if (aone <= 1) {
    document.getElementById('tdi' + aone).value=decodeURIComponent(('' + location.hash).split('step' + aone + '=')[1].split('#')[0].split(encodeURIComponent('#'))[0]);
    } else {
    document.getElementById('tdi' + aone).value=decodeURIComponent(('' + location.hash).split('step' + aone + '=')[1].split('#')[0].split(encodeURIComponent('#'))[0]);
    obl(document.getElementById('tdi' + aone), true); //document.getElementById('tdi' + aone).blur();
    if ( document.getElementById('tdi' + eval(1 + aone))) {
      document.getElementById('tdi' + eval(1 + aone)).focus();
      if (document.getElementById('tdi' + eval(0 + aone))) {
        if (document.getElementById('tdi' + eval(0 + aone)).value == '') {
          document.getElementById('tdi' + eval(0 + aone)).focus();
        }
      }
      console.log('here1');
    } 
    }
    } else if (('' + location.hash.indexOf('step' + aone + eneqs)) != -1) {
    if (aone <= 1) {
    document.getElementById('tdi' + aone).value=decodeURIComponent(('' + location.hash).split('step' + aone + eneqs)[1].split('#')[0].split(encodeURIComponent('#'))[0]);
    } else {
    document.getElementById('tdi' + aone).value=decodeURIComponent(('' + location.hash).split('step' + aone + eneqs)[1].split('#')[0].split(encodeURIComponent('#'))[0]);
    obl(document.getElementById('tdi' + aone), true); //document.getElementById('tdi' + aone).blur();
    if ( document.getElementById('tdi' + eval(1 + aone))) {
      document.getElementById('tdi' + eval(1 + aone)).focus();
      if (document.getElementById('tdi' + eval(0 + aone))) {
        if (document.getElementById('tdi' + eval(0 + aone)).value == '') {
          document.getElementById('tdi' + eval(0 + aone)).focus();
        }
      }
      console.log('Here1');
    } 
    }
    } else if (('' + location.hash.indexOf('step' + aone + noneqs)) != -1) {
    if (aone <= 1) {
    document.getElementById('tdi' + aone).value=decodeURIComponent(('' + location.hash).split('step' + aone + noneqs)[1].split('#')[0].split(encodeURIComponent('#'))[0]);
    } else {
    document.getElementById('tdi' + aone).value=decodeURIComponent(('' + location.hash).split('step' + aone + noneqs)[1].split('#')[0].split(encodeURIComponent('#'))[0]);
    obl(document.getElementById('tdi' + aone), true); //document.getElementById('tdi' + aone).blur();
    if ( document.getElementById('tdi' + eval(1 + aone))) {
    //alert('herRe1');
      document.getElementById('tdi' + eval(1 + aone)).focus();
      if (document.getElementById('tdi' + eval(0 + aone))) {
        if (document.getElementById('tdi' + eval(0 + aone)).value == '') {
          document.getElementById('tdi' + eval(0 + aone)).focus();
        }
      }
      console.log('HeRe1');
    } 
    }
    }
    aone++;
    }
    if (aone > 1 || document.getElementById('therest').value != '') { anyhashes=('' + location.hash).replace(/\%23/g,'#'); setTimeout(function(){ if (confirm('Draw now (versus add more yourself)?') == true) { document.getElementById('mysub').click(); } }, 8000); }
    
    //alert(document.body.title);
    //alert('' + document.body.title);
    if (('' + document.body.title) == 'undefined') {
      document.body.title=\"Overall instructions, perhaps incorporating a title='[Iframe Save As downloading default name basis]' and first URL can be a node with a link, can be typed here after you double click on border to clear the contents.\";
      document.getElementById('results').title=\"Overall instructions, perhaps incorporating a title='[Iframe Save As downloading default name basis]' and first URL can be a node with a link, can be typed here after you double click on border to clear the contents.\";
      ifs=document.getElementsByTagName('iframe');
      for (jifs=0; jifs<ifs.length; jifs++) {
        if (('' + ifs[jifs].title) == 'undefined') {
          ifs[jifs].title=\"Overall instructions, perhaps incorporating a title='[Iframe Save As downloading default name basis]' and first URL can be a node with a link, can be typed here after you double click on border to clear the contents.\";
        }
      }
    } else if (('' + document.body.title).trim() != '') {
      ifs=document.getElementsByTagName('iframe');
      for (jifs=0; jifs<ifs.length; jifs++) {
        if (('' + ifs[jifs].title) == 'undefined') {
          ifs[jifs].title=document.body.title;
        }
      }
    }
  }
  
  if (estitle != '') {
    cookb=cookb.replace(cookb.split(' Or hash delimited appended string can ')[0], 'Empty OK answer adds your Steps to recoverable personal list, with the title ... ' + estitle + ' ... for you.');
  }

</scr" . "ipt>
</head>
<body title=\"" . $dtitle . "\" onload=\" templtd=document.getElementById('td1').outerHTML; checkforlh();  if (window.parent == window.self) {  if (aone > 1) { document.getElementById('tdi' + eval(-1 + aone)).focus(); console.log('hErE1 ' + aone);  } else { document.getElementById('tdi' + aone).focus();  console.log('HErE1');   } } cookieAVal('steps_', true);  \">
<h1>My Recipe Steps <span id=ssel></span> <a id=pemail title='Email now or later or Recall' class=share  onclick=\"return emailit('');\" style='text-decoration:none;cursor:pointer;'>&#128231;</a>&nbsp;<a id=psms title='SMS now or later or Recall'  class=share  onclick=\"return smsit('');\" style='text-decoration:none;cursor:pointer;'>&#128223;</a>&nbsp;<a id=pcookie title='Recall this'  class=share  onclick=\"return emailit(estitle);\" style='display:none;text-decoration:none;cursor:pointer;'>&#127850;</a></h1>
<h3>RJM Programming - September, 2024</h3><br>
<table style=width:100%;height:80%;><tr><th style=width:80%;>
<div ondblclick=\"this.innerHTML='';\" onblur=danalyze(this); contenteditable=true title=\"" . $dtitle . "\" style=\"display:block;width:100%;height:100%;\" id=results>" . $results . "</div><br></th><th style='background-color:rgb(240,240,240);'><br>
<form id=myform method=POST action='./recipe_helper.php'>
<button onmousedown=\" document.getElementById('mysub').click(); \" ontouchdown=\" document.getElementById('mysub').click(); \" data-value=Draw style=background-color:pink;>Draw</button>
<table cellpadding=3 cellspacing=3 style=width:100%;height:100%; id=mytable>
<tr id=myrec><td id=td1><textarea tabindex=0 onblur=obl(this,false); data-type=text value='' id=tdi1 name=step1 placeholder='Step1'></textarea></td>" . $vertif . "<td id=td2><textarea tabindex=0 onblur=obl(this,false); data-type=text value='' id=tdi2 name=step2 placeholder='Step2'></textarea></td>" . $vertif . "</tr>
</table><input type=hidden id=therest value=''></input><input type=submit value=Draw id=mysub style=display:none;></input></form><br><br></th></tr></table><br><br>
<div id=dimap style=display:none;></div>
</body>
</html>";



?>
