<?php
// Image Plus Text PDF  ... RJM Programming ... August 2022
define('FPDF_FONTPATH','MarkItUp/fpdf17/font/');
require('MarkItUp/fpdf17/fpdf.php');
//if (1 == 1) {
//echo "<html><body><p>gfdg nhffd</p></body></html>";
//exit;=


class RPDF extends FPDF { // thanks to http://www.fpdf.org/en/script/script31.php

function TextWithDirection($x, $y, $txt, $direction='R')
{
    if ($direction=='R')
        $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET',1,0,0,1,$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
    elseif ($direction=='L')
        $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET',-1,0,0,-1,$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
    elseif ($direction=='U')
        $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET',0,1,-1,0,$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
    elseif ($direction=='D')
        $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET',0,-1,1,0,$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
    else
        $s=sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
    if ($this->ColorFlag)
        $s='q '.$this->TextColor.' '.$s.' Q';
    $this->_out($s);
}

function TextWithRotation($x, $y, $txt, $txt_angle, $font_angle=0)
{
    $font_angle+=90+$txt_angle;
    $txt_angle*=M_PI/180;
    $font_angle*=M_PI/180;

    $txt_dx=cos($txt_angle);
    $txt_dy=sin($txt_angle);
    $font_dx=cos($font_angle);
    $font_dy=sin($font_angle);

    $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET',$txt_dx,$txt_dy,$font_dx,$font_dy,$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
    if ($this->ColorFlag)
        $s='q '.$this->TextColor.' '.$s.' Q';
    $this->_out($s);
}

}

if (isset($_GET['nothing'])) {
  exit;
}

$ns="";
$bip="";
if (isset($_POST['pdfimage']) && isset($_POST['pdfnotready']) && !isset($_POST['pdfimageplustext'])) {
  //echo "here";
  //exit;
  $bip='background:url(' . str_replace(' ','+',urldecode($_POST['pdfimage'])) . ') no-repeat;';
  $ns=" datauri='" . str_replace(' ','+',urldecode($_POST['pdfimage'])) . "';  datauris[0]='" . str_replace(' ','+',urldecode($_POST['pdfimage'])) . "'; noshow();  ";
} //else if (isset($_POST['pdfimage']) && isset($_POST['pdfnotready'])) {
  //echo "there";
  //exit;
//}
if (isset($_GET['wildcard'])) {
  if (strlen($_GET['wildcard']) > 0) {
    $htmlis='';
    foreach (glob(str_replace('+',' ',urldecode($_GET['wildcard']))) as $filename) {
     if ($htmlis == '') {
         $udirnameprebimg=$filename;  
         $pjbit='data:image/' . str_replace('jpg','jpeg',strtolower(explode('.',$udirnameprebimg)[-1 + sizeof(explode('.',$udirnameprebimg))])) . ';base64,' . base64_encode(file_get_contents($udirnameprebimg));  
         $htmlis='<html><body onload=" var j=0;   parent.predurip(' . "'" . $pjbit . "'" . '); if (1 == 1) {   j++; } parent.document.getElementById(' . "'" . 'iurl' . "'" . ').value=parent.document.getElementById(' . "'" . 'iurl' . "'" . ').value.replace(' . "'" . str_replace('+',' ',urldecode($_GET['wildcard'])) . "'" . ',' . "'" . $pjbit . "'" . '); parent.setjust(parent.document.getElementById(' . "'" . 'iurl' . "'" . ')); "></body></html>';
     } else {
         $udirnameprebimg=$filename;  
         $pjbit='data:image/' . str_replace('jpg','jpeg',strtolower(explode('.',$udirnameprebimg)[-1 + sizeof(explode('.',$udirnameprebimg))])) . ';base64,' . base64_encode(file_get_contents($udirnameprebimg));  
         $htmlis=str_replace(" j++;", " parent.durip('" . $pjbit . "'); j++;", $htmlis);
     }
    }
    echo $htmlis;
  }
  exit;
}
$justdatelen=0;
$getit="";
$factor=1;
$lastrepeat="";
$repeats=0;
$mewd=null;
$newd=null;
$newdts="";
$sfm="0";
$newdtssuffix="";
if (isset($_POST['mytzn'])) {
    if (('' . urldecode($_POST['mytzn'])) != '') {
     date_default_timezone_set(urldecode($_POST['mytzn']));
    }
    $newd=new DateTime(); //date_create('');
    $newdts=$newd->format(DateTime::COOKIE);
    $mewd=$newd;
    $newdtssuffix="_" . urldecode($_POST['mytzn']);
//echo "Newdts=" . $newdts;
//exit;
} else if (isset($_GET['mytzn'])) {
    if (('' . urldecode($_GET['mytzn'])) != '') {
     date_default_timezone_set(urldecode($_GET['mytzn']));
    }
    $newd=new DateTime(); //date_create('');
    $newdts=$newd->format(DateTime::COOKIE);
    $mewd=$newd;
    $newdtssuffix="_" . urldecode($_GET['mytzn']);
//echo "newdts=" . $newdts;
//exit;
} else if (isset($_GET['myls1'])) {
    if (strpos(urldecode($_GET['myls1']), '/') > strpos(urldecode($_GET['myls1']), '_') && strpos(urldecode($_GET['myls1']), '/') !== false && strpos(urldecode($_GET['myls1']), '_') !== false) {
    $lstz=str_replace(explode('_', urldecode($_GET['myls1']))[0] . '_', '', urldecode($_GET['myls1']));   
    if (('' . $lstz) != '') {
     date_default_timezone_set($lstz);
    }
    $newdtssuffix="_" . $lstz;
    $newd=new DateTime(); //date_create('');
    $newdts=$newd->format(DateTime::COOKIE);
    $mewd=$newd;
    $sfm="1";
    }
} else if (isset($_GET['myls2'])) {
    if (strpos(urldecode($_GET['myls2']), '/') > strpos(urldecode($_GET['myls2']), '_') && strpos(urldecode($_GET['myls2']), '/') !== false && strpos(urldecode($_GET['myls2']), '_') !== false) {
    $lstz=str_replace(explode('_', urldecode($_GET['myls2']))[0] . '_', '', urldecode($_GET['myls2']));   
    if (('' . $lstz) != '') {
     date_default_timezone_set($lstz);
    }
    $newdtssuffix="_" . $lstz;
    $newd=new DateTime(); //date_create('');
    $newdts=$newd->format(DateTime::COOKIE);
    $mewd=$newd;
    $sfm="2";
    }
} else if (isset($_GET['myls3'])) {
    if (strpos(urldecode($_GET['myls3']), '/') > strpos(urldecode($_GET['myls1']), '_') && strpos(urldecode($_GET['myls3']), '/') !== false && strpos(urldecode($_GET['myls3']), '_') !== false) {
    $lstz=str_replace(explode('_', urldecode($_GET['myls3']))[0] . '_', '', urldecode($_GET['myls1']));   
    if (('' . $lstz) != '') {
     date_default_timezone_set($lstz);
    }
    $newdtssuffix="_" . $lstz;
    $newd=new DateTime(); //date_create('');
    $newdts=$newd->format(DateTime::COOKIE);
    $mewd=$newd;
    $sfm="3";
    }
} else if (isset($_GET['myls'])) {
    if (strpos(urldecode($_GET['myls']), '/') > strpos(urldecode($_GET['myls']), '_') && strpos(urldecode($_GET['myls']), '/') !== false && strpos(urldecode($_GET['myls']), '_') !== false) {
    $lstz=str_replace(explode('_', urldecode($_GET['myls']))[0] . '_', '', urldecode($_GET['myls']));   
    if (('' . $lstz) != '') {
     date_default_timezone_set($lstz);
    }
    $newdtssuffix="_" . $lstz;
    $newd=new DateTime(); //date_create('');
    $newdts=$newd->format(DateTime::COOKIE);
    $mewd=$newd;
    }
} else if (isset($_POST['myls'])) {
    if (strpos(urldecode($_POST['myls']), '/') > strpos(urldecode($_POST['myls']), '_') && strpos(urldecode($_POST['myls']), '/') !== false && strpos(urldecode($_POST['myls']), '_') !== false) {
    $lstz=str_replace(explode('_', urldecode($_POST['myls']))[0] . '_', '', urldecode($_POST['myls']));   
    if (('' . $lstz) != '') {
     date_default_timezone_set($lstz);
    }
    $newd=new DateTime(); //date_create('');
    $newdts=$newd->format(DateTime::COOKIE);
    $mewd=$newd;
    }
} else if (!isset($_POST['pdffile'])) {
    $getit="  document.getElementById('mytzn').value='' + Intl.DateTimeFormat().resolvedOptions().timeZone;  if (documentURL.indexOf('?') == -1 && ('' + location.hash) == '') {  location.href=documentURL + '?mytzn=' + encodeURIComponent(document.getElementById('mytzn').value);  } ";
}
$ofsz="";
$ofst="";
$orot="";
$odir="";
$user_agent = $_SERVER['HTTP_USER_AGENT']; 
$ffnos="Text <input style=display:inline-block;width:40px; type=number value=1 id=tnum min=1></input> from now on Colour Size Direction Rotation Style Family ideas ... <br><input onblur=fromnowon(this); style=display:inline-block; type=color id=tcol value=#000000></input>&nbsp<input onblur=fromnowon(this); style=display:inline-block;width:40px; type=number step=1 min=0 id=tsiz value=16></input>px&nbsp;<select onchange=fromnowon(this); id=tdir><option value=R>Right</option><option value=L>Left</option><option value=D>Down</option><option value=U>Up</option></select>&nbsp<input onblur=fromnowon(this); style=display:inline-block; type=number step=1 min=0 max=359 id=trot value=0></input>&deg;&nbsp;<select onchange=fromnowon(this); id=tsty><option value=>Bold</option><option value=N>Normal</option><option value=I>Italic</option><option value=U>Underline</option></select>&nbsp;<select onchange=fromnowon(this); id=tfam><option value=Arial>Arial</option><option value=Courier>Coiurier</option><option value=Helvetica>Helvetica</option><option value=Times>Times</option><option value=Symbol>Symbol</option><option value=ZapfDingbats>ZapfDingbats</option></select>&nbsp&nbsp;<input style=background-color:yellow; type=button onclick='showingc=showing; event.stopPropagation(); fromnowon(this);' id=tbut value='Apply From Now On ...'></input>&nbsp&nbsp;<input style=background-color:silver; type=button onclick='showingc=showing; event.stopPropagation(); alert(document.body.title);' id=tblb value='Long Explanation ...'></input><br><div id=saveas><button onclick=lsnamesaveas(); style=background-color:orange;>Save As ...</button></div><br><details><summary style=background-color:lightblue;>For next click establish default text ...</summary><textarea id=mytextarea cols=40 rows=10 value=></textarea></details><div id=nextetc></div>";

function ffs($insuf) {
   global $ffy, $fst, $fsz, $ofsz, $ofst;
   if (isset($_POST['pdffamily' . $insuf])) {
     $ffy=str_replace('+',' ',urldecode($_POST['pdffamily' . $insuf]));
   }
   if (isset($_POST['pdffontstyle' . $insuf])) {
     $fst=str_replace('N',' ',substr(strtoupper(str_replace('+',' ',urldecode($_POST['pdffontstyle' . $insuf]))) . ' ',0,1));
     if ($insuf != '') { $ofst=$fst; }
   }
   if (isset($_POST['pdffontsize' . $insuf])) {
     if (strlen(trim(str_replace('+',' ',urldecode($_POST['pdffontsize' . $insuf])))) > 0) {
       $fsz=str_replace('+',' ',urldecode($_POST['pdffontsize' . $insuf]));
       if ($insuf != '') { $ofsz=$fsz; }
     }
   }
   if ($ofsz == "") { $ofsz=$fsz; }
   if ($ofst == "") { $ofst=$fst; }
}

function gffs($insuf) {
   global $ffy, $fst, $fsz, $ofsz, $ofst;
   if (isset($_GET['pdffamily' . $insuf])) {
     $ffy=str_replace('+',' ',urldecode($_GET['pdffamily' . $insuf]));
   }
   if (isset($_GET['pdffontstyle' . $insuf])) {
     $fst=str_replace('N',' ',substr(strtoupper(str_replace('+',' ',urldecode($_GET['pdffontstyle' . $insuf]))) . ' ',0,1));
     if ($insuf != '') { $ofst=$fst; }
   }
   if (isset($_GET['pdffontsize' . $insuf])) {
     if (strlen(trim(str_replace('+',' ',urldecode($_GET['pdffontsize' . $insuf])))) > 0) {
       $fsz=str_replace('+',' ',urldecode($_GET['pdffontsize' . $insuf]));
       if ($insuf != '') { $ofsz=$fsz; }
     }
   }
   if ($ofsz == "") { $ofsz=$fsz; }
   if ($ofst == "") { $ofst=$fst; }
}

function yoururldecode($inmd) {
  return urldecode($inmd);
}

function itdependsone($strin, $isfromsuitable) {
  $jsfromsuitable=$isfromsuitable;
  
  
  return $jsfromsuitable;
}

function itdependstwo($strin, $istosuitable) {
  if (strpos($strin, "2022") === false) {
   echo '0:' . substr($strin, 0, $istosuitable);
   exit;
  }
  $jstosuitable=$istosuitable;
  if ((substr($strin, 0, $istosuitable) . ' ') != substr($strin, 0, (1 + $istosuitable)) && (substr($strin, 0, $istosuitable) . 'T') != substr($strin, 0, (1 + $istosuitable))) {
   echo substr($strin, 0, $istosuitable);
   exit;
   $ok=false;
   for ($io=1; $io<=3; $io++) {
    if (!$ok && (substr($strin, 0, ($io + $istosuitable)) . ' ') == substr($strin, 0, (1 + $io + $istosuitable))) {
      $ok=true;
      $jstosuitable=($io + $istosuitable);
    }
    if (!$ok && (substr($strin, 0, ($io + $istosuitable)) . 'T') == substr($strin, 0, (1 + $io + $istosuitable))) {
      $ok=true;
      $jstosuitable=($io + $istosuitable);
    }
   }
   if (!$ok) {
   for ($io=1; $io<=3; $io++) {
    if (!$ok && (substr($strin, 0, (-$io + $istosuitable)) . ' ') == substr($strin, 0, (-$io + 1 + $istosuitable))) {
      $ok=true;
      $jstosuitable=(-$io + $istosuitable);
    }
    if (!$ok && (substr($strin, 0, (-$io + $istosuitable)) . 'T') == substr($strin, 0, (-$io + 1 + $istosuitable))) {
      $ok=true;
      $jstosuitable=(-$io + $istosuitable);
    }
   }
   }
  }
  return $jstosuitable;
}

function nuance($zrepeats,$inoth,$inrs,$negplus,$inpal,$outpal,$oone,$otwo,$fc) {
  global $justdatelen, $newd, $repeats, $lastrepeat, $factor, $newdts;
  $comlen=0;
  $outcomlen=0;
  $difflen=0;
  if (strpos($outpal, ",") !== false) {
    $comlen=explode(",", $outpal)[0];
  }
  $altnegplus='';
  $altcookielook='';
  $rests='';
  if ($oone != $otwo && strpos($otwo, $oone) !== false) { // && $zrepeats < 0) {
    $rests=explode($oone, $otwo)[1];
    if ($zrepeats < 0) { 
      $altnegplus=explode(';', str_replace('+','',str_replace('=','', $rests)))[0]; 
      $pmnd=true;
      for ($jk=0; $jk<strlen($altnegplus); $jk++) {
        if ($pmnd && (substr($altnegplus, $jk, 1) != '+' && substr($altnegplus, $jk, 1) != '-' && substr($altnegplus, $jk, 1) != '.' && substr($altnegplus, $jk, 1) != '0' && substr($altnegplus, $jk, 1) != '1' && substr($altnegplus, $jk, 1) != '2' && substr($altnegplus, $jk, 1) != '3' && substr($altnegplus, $jk, 1) != '4' && substr($altnegplus, $jk, 1) != '5' && substr($altnegplus, $jk, 1) != '6' && substr($altnegplus, $jk, 1) != '7' && substr($altnegplus, $jk, 1) != '8' && substr($altnegplus, $jk, 1) != '9')) {
          $pmnd=false;
          $altcookielook=substr($altnegplus, $jk);
        }
        if ($altcookielook != '') { $altnegplus=substr($altnegplus, 0 , (strlen($altnegplus) - strlen($altcookielook)));    }
      }
    }
  }
    //echo "zrepeats=". $zrepeats . "and repeats=" . $repeats;
    //exit;
  if ($rests != '') {
    $xi=explode($rests, $inpal)[0];
    $inpal=$xi . substr($inpal, strlen($xi) + strlen($rests)); 
  }
  if ($repeats < 0) {
    //echo "inpal=" . $inpal;
    //exit;
    $lastrepeat=$inpal;
    //$repeats=-$repeats;
  } else if ($repeats > 0) {
    $inpal=$lastrepeat;
    $repeats--;
  }
  $intd='D';
  $outrs="";
  //$factor=$negplus;
  $five=5;
  $negplus=explode(';', $negplus)[0];
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
  if ($inoth == strtoupper($inoth) && trim($inrs) == '') { return $outpal; }
  if ($inoth == 'DATE' . strtolower(substr($inoth,0,4)) && trim($inrs) == '') { return substr($outpal,0,itdependstwo($outpal,$justdatelen)); }
  if ($inoth == 'date' . strtoupper(substr($inoth,0,4)) && trim($inrs) == '') { return substr($outpal,itdependsone($outpal,($justdatelen + 1))); }
  if (trim($inrs) != '' || strpos(strtoupper($inoth), 'DATE') !== false) {
  //echo "inrs=" . $inrs . " inoth=" . $inoth;
  //exit;
    $outrs=explode(" ", $inrs)[0];
    if (trim($outrs) != '' || strpos(strtoupper($inoth), 'DATE') !== false) {
      if (str_replace('-','',str_replace('.','',str_replace('=','',str_replace('+','',str_replace('0','',str_replace('1','',str_replace('2','',str_replace('3','',str_replace('4','',str_replace('5','',str_replace('6','',str_replace('7','',str_replace('8','',str_replace('9','',trim($outrs))))))))))))))) == '') {
        if (trim($outrs) != '') { $factor*=str_replace('-','',str_replace('+','',$outrs)); }
        if (strpos($inoth, 'DATE') !== false) {
          if (substr($inoth, $five) == strtolower(substr($inoth, $five, 1)) . strtoupper(substr($inoth, (1 + $five)))) {
            $intd='Y';
          } else if (substr($inoth, $five) == strtoupper(substr($inoth, $five, 1)) . strtolower(substr($inoth, (1 + $five), 1)) . strtoupper(substr($inoth, (2 + $five)))) {
            $intd='M';
          } else if (substr($inoth, $five) == strtoupper(substr($inoth, $five, 2)) . strtolower(substr($inoth, (2 + $five), 1)) . strtoupper(substr($inoth, (3 + $five)))) {
            $intd='D';
          }
          if ($zrepeats >= 0) {
          if (strpos(('' . $negplus), '-') !== false) {
          $newd->sub(new DateInterval('P' . str_replace('-','','' . $negplus) . $intd));
          } else {
          $newd->add(new DateInterval('P' . $negplus . $intd));
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          } else if ($zrepeats < 0) {
    //$lastrepeat=$inpal;
          if (strpos(('' . $altnegplus), '-') !== false) {
          $newd->sub(new DateInterval('P' . str_replace('-','','' . $altnegplus) . $intd));
          if ($altcookielook != '') {
            while (strpos(strtolower('' . $newd->format(DateTime::COOKIE)), strtolower($altcookielook)) === false) {
              $newd->sub(new DateInterval('P1' . $intd));
            }
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          } else if ($altnegplus != '') {
          $newd->add(new DateInterval('P' . $altnegplus . $intd));
          if ($altcookielook != '') {
            while (strpos(strtolower('' . $newd->format(DateTime::COOKIE)), strtolower($altcookielook)) === false) {
              $newd->add(new DateInterval('P1' . $intd));
            }
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          }
    $repeats=-$zrepeats;
          }
          return substr($outpal,0,itdependstwo($outpal,$justdatelen)); 
        } else if (strpos($inoth, 'date') !== false) {
          $intd='H';
          if (substr($inoth, $five) == strtolower(substr($inoth, $five, 1)) . strtoupper(substr($inoth, (1 + $five)))) {
            $intd='H';
          } else if (substr($inoth, $five) == strtoupper(substr($inoth, $five, 1)) . strtolower(substr($inoth, (1 + $five), 1)) . strtoupper(substr($inoth, (2 + $five)))) {
            $intd='M';
          } else if (substr($inoth, $five) == strtoupper(substr($inoth, $five, 2)) . strtolower(substr($inoth, (2 + $five), 1)) . strtoupper(substr($inoth, (3 + $five)))) {
            $intd='S';
          }
          if ($zrepeats >= 0) {
          if (strpos(('' . $negplus), '-') !== false) {
          $newd->sub(new DateInterval('PT' . str_replace('-','','' . $negplus) . $intd));
          } else {
          $newd->add(new DateInterval('PT' . $negplus . $intd));
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          } else if ($zrepeats < 0) {
    //$lastrepeat=$inpal;
          if (strpos(('' . $altnegplus), '-') !== false) {
          $newd->sub(new DateInterval('PT' . str_replace('-','','' . $altnegplus) . $intd));
          if ($altcookielook != '') {
            while (strpos(strtolower('' . $newd->format(DateTime::COOKIE)), strtolower($altcookielook)) === false) {
              $newd->sub(new DateInterval('PT1' . $intd));
            }
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          } else if ($altnegplus != '') {
          $newd->add(new DateInterval('PT' . $altnegplus . $intd));
          if ($altcookielook != '') {
            while (strpos(strtolower('' . $newd->format(DateTime::COOKIE)), strtolower($altcookielook)) === false) {
              $newd->add(new DateInterval('PT1' . $intd));
            }
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          }
    $repeats=-$zrepeats;
          }
          return substr($outpal,itdependsone($outpal,($justdatelen + 1))); 
        } else {
          $five=0;
          $intd='D';
  //echo "InoTH=" . $inoth . " and factor=" . $factor;
  //exit;
          if (substr($inoth, $five) == strtolower(substr($inoth, $five, 1)) . strtoupper(substr($inoth, (1 + $five)))) {
            $intd='Y';
            //echo 'P' . $factor . $intd;
            //exit;
          if ($zrepeats >= 0) {
          if (strpos(('' . $negplus), '-') !== false) {
          $newd->sub(new DateInterval('P' . str_replace('-','','' . $negplus) . $intd));
          } else {
          $newd->add(new DateInterval('P' . $negplus . $intd));
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
           } else if ($zrepeats < 0) {
    //$lastrepeat=$inpal;
          if (strpos(('' . $altnegplus), '-') !== false) {
          $newd->sub(new DateInterval('P' . str_replace('-','','' . $altnegplus) . $intd));
          if ($altcookielook != '') {
            while (strpos(strtolower('' . $newd->format(DateTime::COOKIE)), strtolower($altcookielook)) === false) {
              $newd->sub(new DateInterval('P1' . $intd));
            }
          }
          } else if ($altnegplus != '') {
          $newd->add(new DateInterval('P' . $altnegplus . $intd));
          if ($altcookielook != '') {
            while (strpos(strtolower('' . $newd->format(DateTime::COOKIE)), strtolower($altcookielook)) === false) {
              $newd->add(new DateInterval('P1' . $intd));
            }
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          }
    $repeats=-$zrepeats;
          }
           return $outpal; 
          } else if (substr($inoth, $five) == strtoupper(substr($inoth, $five, 1)) . strtolower(substr($inoth, (1 + $five), 1)) . strtoupper(substr($inoth, (2 + $five)))) {
            $intd='M';
            //echo 'P' . $factor . $intd;
            //exit;
          if ($zrepeats >= 0) {
          if (strpos(('' . $negplus), '-') !== false) {
          $newd->sub(new DateInterval('P' . str_replace('-','','' . $negplus) . $intd));
          } else {
          $newd->add(new DateInterval('P' . $negplus . $intd));
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          } else if ($zrepeats < 0) {
    //$lastrepeat=$inpal;
          if (strpos(('' . $altnegplus), '-') !== false) {
          $newd->sub(new DateInterval('P' . str_replace('-','','' . $altnegplus) . $intd));
          if ($altcookielook != '') {
            while (strpos(strtolower('' . $newd->format(DateTime::COOKIE)), strtolower($altcookielook)) === false) {
              $newd->sub(new DateInterval('P1' . $intd));
            }
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          } else if ($altnegplus != '') {
          $newd->add(new DateInterval('P' . $altnegplus . $intd));
          if ($altcookielook != '') {
            while (strpos(strtolower('' . $newd->format(DateTime::COOKIE)), strtolower($altcookielook)) === false) {
              $newd->add(new DateInterval('P1' . $intd));
            }
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          }
    $repeats=-$zrepeats;
          }
            return $outpal; 
          } else if (substr($inoth, $five) == strtoupper(substr($inoth, $five, 2)) . strtolower(substr($inoth, (2 + $five), 1)) . strtoupper(substr($inoth, (3 + $five)))) {
            $intd='D';
            //echo 'P' . $negplus . $intd;
            //exit;
          if ($zrepeats >= 0) {
          if (strpos(('' . $negplus), '-') !== false) {
          $newd->sub(new DateInterval('P' . str_replace('-','','' . $negplus) . $intd));
          } else {
          $newd->add(new DateInterval('P' . $negplus . $intd));
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          } else if ($zrepeats < 0) {
    //$lastrepeat=$inpal;
          if (strpos(('' . $altnegplus), '-') !== false) {
          $newd->sub(new DateInterval('P' . str_replace('-','','' . $altnegplus) . $intd));
          if ($altcookielook != '') {
            while (strpos(strtolower('' . $newd->format(DateTime::COOKIE)), strtolower($altcookielook)) === false) {
              $newd->sub(new DateInterval('P1' . $intd));
            }
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
         } else if ($altnegplus != '') {
          $newd->add(new DateInterval('P' . $altnegplus . $intd));
          if ($altcookielook != '') {
            while (strpos(strtolower('' . $newd->format(DateTime::COOKIE)), strtolower($altcookielook)) === false) {
              $newd->add(new DateInterval('P1' . $intd));
            }
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          }
    $repeats=-$zrepeats;
          }
            return $outpal; 
          }
          $five=5;
          if (substr($inoth, $five) == strtolower(substr($inoth, $five, 1)) . strtoupper(substr($inoth, (1 + $five)))) {
            $intd='H';
          if ($zrepeats >= 0) {
          if (strpos(('' . $negplus), '-') !== false) {
          $newd->sub(new DateInterval('PT' . str_replace('-','','' . $negplus) . $intd));
          } else {
          $newd->add(new DateInterval('PT' . $negplus . $intd));
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          } else if ($zrepeats < 0) {
    //$lastrepeat=$inpal;
          if (strpos(('' . $altnegplus), '-') !== false) {
          $newd->sub(new DateInterval('PT' . str_replace('-','','' . $altnegplus) . $intd));
          if ($altcookielook != '') {
            while (strpos(strtolower('' . $newd->format(DateTime::COOKIE)), strtolower($altcookielook)) === false) {
              $newd->sub(new DateInterval('P1' . $intd));
            }
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          } else if ($altnegplus != '') {
          $newd->add(new DateInterval('PT' . $altnegplus . $intd));
          if ($altcookielook != '') {
            while (strpos(strtolower('' . $newd->format(DateTime::COOKIE)), strtolower($altcookielook)) === false) {
              $newd->add(new DateInterval('P1' . $intd));
            }
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          }
    $repeats=-$zrepeats;
          }
            return $outpal; 
          } else if (substr($inoth, $five) == strtoupper(substr($inoth, $five, 1)) . strtolower(substr($inoth, (1 + $five), 1)) . strtoupper(substr($inoth, (2 + $five)))) {
            $intd='M';
          if ($zrepeats >= 0) {
          if (strpos(('' . $negplus), '-') !== false) {
          $newd->sub(new DateInterval('PT' . str_replace('-','','' . $negplus) . $intd));
          } else {
          $newd->add(new DateInterval('PT' . $negplus . $intd));
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          } else if ($zrepeats < 0) {
    //$lastrepeat=$inpal;
          if (strpos(('' . $altnegplus), '-') !== false) {
          $newd->sub(new DateInterval('PT' . str_replace('-','','' . $altnegplus) . $intd));
          if ($altcookielook != '') {
            while (strpos(strtolower('' . $newd->format(DateTime::COOKIE)), strtolower($altcookielook)) === false) {
              $newd->sub(new DateInterval('P1' . $intd));
            }
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          } else if ($altnegplus != '') {
          $newd->add(new DateInterval('PT' . $altnegplus . $intd));
          if ($altcookielook != '') {
            while (strpos(strtolower('' . $newd->format(DateTime::COOKIE)), strtolower($altcookielook)) === false) {
              $newd->add(new DateInterval('P1' . $intd));
            }
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          }
    $repeats=-$zrepeats;
          }
            return $outpal; 
          } else if (substr($inoth, $five) == strtoupper(substr($inoth, $five, 2)) . strtolower(substr($inoth, (2 + $five), 1)) . strtoupper(substr($inoth, (3 + $five)))) {
            $intd='S';
          if ($zrepeats >= 0) {
          if (strpos(('' . $negplus), '-') !== false) {
          $newd->sub(new DateInterval('PT' . str_replace('-','','' . $negplus) . $intd));
          } else {
          $newd->add(new DateInterval('PT' . $negplus . $intd));
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          } else if ($zrepeats < 0) {
    //$lastrepeat=$inpal;
          if (strpos(('' . $altnegplus), '-') !== false) {
          $newd->sub(new DateInterval('PT' . str_replace('-','','' . $altnegplus) . $intd));
          if ($altcookielook != '') {
            while (strpos(strtolower('' . $newd->format(DateTime::COOKIE)), strtolower($altcookielook)) === false) {
              $newd->sub(new DateInterval('P1' . $intd));
            }
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          } else if ($altnegplus != '') {
          $newd->add(new DateInterval('PT' . $altnegplus . $intd));
          if ($altcookielook != '') {
            while (strpos(strtolower('' . $newd->format(DateTime::COOKIE)), strtolower($altcookielook)) === false) {
              $newd->sub(new DateInterval('P1' . $intd));
            }
          }
  $outpal='' . $newd->format($fc);
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
          }
    $repeats=-$zrepeats;
          }
            return $outpal; 
          }
          return $outpal; 
        }
      }      
    }
  }
  return $outpal;
}

function oururldecode($inmd) {
  global $newd, $repeats, $lastrepeat, $factor, $newdts;
  $inmd=str_replace(urlencode("~~"), urlencode("\n"), str_replace("~~", "\n", $inmd));
  if (!$newd || strpos(strtoupper('~' . urldecode($inmd)), '~DATE') === false) { 
    if (strpos(str_replace('+',' ',urldecode($inmd)), ' x ') !== false) {
      $inmd=urlencode(explode(' x ', str_replace('+',' ',urldecode($inmd)))[0]);
    } else if (strpos(str_replace('+',' ',urldecode($inmd)), ' * ') !== false) {
      $inmd=urlencode(explode(' * ', str_replace('+',' ',urldecode($inmd)))[0]);
    }
    //return mb_html_entity_decode('&#25105;&#22909;');
    //return mb_html_entity_decode(str_replace('+',' ',urldecode($inmd))); 
    //echo "<html><head><meta charset='utf-8'/></head><body><p>" . html_entity_decode(str_replace('+',' ',urldecode($inmd))) . "</p></body></html>"; 
    //exit;
    return urldecode($inmd); 
  }
  $dateadd=0;
  $xrepeats=0;
  $factor=1;
  $halfchar="_";
  $retstr="";
        //echo "inmd=" . str_replace('+',' ',urldecode($inmd)); // . " xRePeats=" . explode(' x ', str_replace('+',' ',urldecode($inmd)))[1] . ' ';
        //exit;
  if ($repeats == 0 || strpos(str_replace('+',' ',urldecode($inmd)), ' x ') !== false || strpos(str_replace('+',' ',urldecode($inmd)), ' * ') !== false) {
    if (strpos(str_replace('+',' ',urldecode($inmd)), ' x ') !== false) {
      $xrepeats-=floatval(explode(' x ', str_replace('+',' ',urldecode($inmd)))[1]);
      $xrepeats--;
      $inmd=urlencode(explode(' x ', str_replace('+',' ',urldecode($inmd)))[0]);
    } else if (strpos(str_replace('+',' ',urldecode($inmd)), ' * ') !== false) {
      $xrepeats-=floatval(explode(' * ', str_replace('+',' ',urldecode($inmd)))[1]);
      $xrepeats--;
      $inmd=urlencode(explode(' * ', str_replace('+',' ',urldecode($inmd)))[0]);
    }
  } 
  if ($repeats > 0) {
      $inmd=$lastrepeat;
      $xrepeats=$repeats;
  }
  if (strpos(strtoupper('~' . urldecode($inmd)), '~DATE-') !== false) {
    $halfchar="-";
    $factor=-1;
  }
  if (strpos(strtoupper('~' . urldecode($inmd)), '~DATE+') !== false) {
    $halfchar="+";
  }
  if (strpos(strtoupper('~' . urldecode($inmd)), '~DATE ') !== false) {
    $halfchar=" ";
  }
  if (strpos(str_replace('+',' ',urldecode($inmd)), '--') !== false) {
    $factor=-1;
  }
  if (strpos(str_replace('+',' ',urldecode($inmd)), '  ') !== false) {
    $factor=1;
  }
  if (strpos(str_replace('+',' ',urldecode($inmd)), '-=') !== false) {
    $factor=-1;
    //echo explode(' ',explode(';',explode('-=', str_replace('+',' ',urldecode($inmd)))[1])[0])[0];
    //exit;
    $factor*=floatval(explode(' ',explode(';',explode('-=', str_replace('+',' ',urldecode($inmd)))[1])[0])[0]);
  }
  if (strpos(str_replace('+',' ',urldecode($inmd)), ' =') !== false) {
    $factor*=floatval(explode(' ',explode(';',explode(' =', str_replace('+',' ',urldecode($inmd)))[1])[0])[0]);
  }
  if (strpos(strtoupper('~' . urldecode($inmd)), '~DATE' . $halfchar) !== false) {
    //echo "factor=" . $factor;
    //exit;
    if ($xrepeats < 0) {
      $repeats=$xrepeats;
      //$lastrepeat=$inmd;
    } else if ($repeats > 0) {
      $inmd=$lastrepeat;
    }
    $otheroth=explode(' ',explode('DATE' . $halfchar, strtoupper(urldecode($inmd)))[1])[0];
    $oth=explode(' ',explode('-',explode('+',explode('DATE' . $halfchar, strtoupper(urldecode($inmd)))[1])[0])[0])[0];
    $ucoth=substr(str_replace($halfchar,'_',str_replace('+',' ',urldecode($inmd))), 0, (5 + strlen($oth)));
    $rsoth=trim(substr(str_replace('+',' ',urldecode($inmd)), strlen($ucoth) + strlen($otheroth) - strlen($oth)));
    
    //echo $oth . ' ' . $ucoth . ' ' . $rsoth;
    switch ($oth) {
      case 'ATOM':
        //echo "xRepeats=" . $xrepeats . ' ';
        //exit;
        //echo $newd->format(DateTime::ATOM);
        //exit;
        //($ucoth,$rsoth,$factor,$newd);
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::ATOM),$oth,$otheroth, DateTime::ATOM); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('-',explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0])[0];
        $xx=str_replace('DATE' . $halfchar . 'ATOM',substr($newd->format(DateTime::ATOM),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        //echo "zero=" . $zero . " retstr=" . $retstr . " xx=" . $xx . " and inmd=" . strtoupper(urldecode($inmd)) . " vs " . 'DATE' . $halfchar . 'ATOM' . " and =" . $newd->format(DateTime::ATOM);
        //exit;
        return str_replace('DATE' . $halfchar . 'ATOM',substr($newd->format(DateTime::ATOM),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'COOKIE':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::COOKIE),$oth,$otheroth, DateTime::COOKIE); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('-',explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0])[0];
        return str_replace('DATE' . $halfchar . 'COOKIE',substr($newd->format(DateTime::COOKIE),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'ISO8601':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::ISO8601),$oth,$otheroth, DateTime::ISO8601); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('-',explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0])[0];
        return str_replace('DATE' . $halfchar . 'ISO8601',substr($newd->format(DateTime::ISO8601),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'RFC822':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::RFC822),$oth,$otheroth, DateTime::RFC822); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('-',explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0])[0];
        return str_replace('DATE' . $halfchar . 'RFC822',substr($newd->format(DateTime::RFC822),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'RFC850':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::RFC850),$oth,$otheroth, DateTime::RFC850); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('-',explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0])[0];
        return str_replace('DATE' . $halfchar . 'RFC850',substr($newd->format(DateTime::RFC850),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'RFC1036':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::RFC1036),$oth,$otheroth, DateTime::RFC1036); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('-',explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0])[0];
        return str_replace('DATE' . $halfchar . 'RFC1036',substr($newd->format(DateTime::RFC1036),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'RFC1123':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::RFC1123),$oth,$otheroth,DateTime::RFC1123); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('-',explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0])[0];
        return str_replace('DATE' . $halfchar . 'RFC1123',substr($newd->format(DateTime::RFC1123),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'RFC2822':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::RFC2822),$oth,$otheroth,DateTime::RFC2822); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('-',explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0])[0];
        return str_replace('DATE' . $halfchar . 'RFC2822',substr($newd->format(DateTime::RFC2822),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'RFC3339':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::RFC3339),$oth,$otheroth,DateTime::RFC2822); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('-',explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0])[0];
        return str_replace('DATE' . $halfchar . 'RFC3339',substr($newd->format(DateTime::RFC3339),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'RSS':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::RSS),$oth,$otheroth,DateTime::RSS); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('-',explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0])[0];
        return str_replace('DATE' . $halfchar . 'RSS',substr($newd->format(DateTime::RSS),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'W3C':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::W3C),$oth,$otheroth,DateTime::W3C); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('-',explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0])[0];
        return str_replace('DATE_W3C',substr($newd->format(DateTime::W3C),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      default:
        break;
    }
  }
  return urldecode($inmd);
}

function server_remote_addr() {
    $rma = $_SERVER['REMOTE_ADDR'];
    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    // you can add different browsers with the same way ..
    if (1 == 2) {
    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;
    }
    if (isset($_GET['ipsuff'])) {
    return "_" . str_replace(".", "_", str_replace(":", "_", $rma)) . str_replace(' ','+',urldecode($_GET['ipsuff']));
    } else if (isset($_POST['ipsuff'])) {
    return "_" . str_replace(".", "_", str_replace(":", "_", $rma)) . str_replace(' ','+',urldecode($_POST['ipsuff']));
    }
    return "_" . str_replace(".", "_", str_replace(":", "_", $rma));
}

if (isset($_GET['pdffile'])) {
   $val=str_replace('+',' ',urldecode($_GET['pdffile']));
   if (strpos($val, ".") !== false) {
    if (strtolower(explode(".", basename($val))[-1 + sizeof(explode(".", basename($val)))]) == 'pdf') {
     $ourfname=str_replace('.pdf','',str_replace('.PDF','',basename($val)));
     if (1 == 1) {
   if (strpos( $user_agent, 'Safari') !== false && strpos( $user_agent, 'Chrome') === false && strpos( $user_agent, 'OPR') === false && strpos( $user_agent, 'Firefox') === false && strpos( $user_agent, 'Opera') === false) {
       $wobit="window.open('/" . $ourfname . ".pdf','_blank');";
       echo '<html><body onclick="' . $wobit . '" title="Click for PDF and/or scroll down to Sharing section" style="background:URL(' . 'data:image/jpeg;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.jpg')) . ');background-repeat:no-repeat;background-size:contain;"><img title="Click for PDF and/or scroll down to Sharing section" style=visibility:hidden; onclick="' . $wobit . '" src="' . 'data:image/jpeg;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.jpg')) . '"></img><canvas </body></html>';
   } else {
       echo '<html><body><div style="overflow:auto;-webkit-overflow-scrolling:touch;height:100%;"><object style="width:100%;height:900px;" type="application/pdf" data="' . 'data:application/pdf;base64,' . base64_encode(file_get_contents('./' . basename($val))) . '">' . "\n" . '<embed style="width:100%;height:900px;" type="application/pdf" src="' .'data:application/pdf;base64,' . base64_encode(file_get_contents('./' . basename($val))) . '"></embed></object></div></body></html>'; 
   }
     } else {
       header('Content-Type: application/pdf');
       echo file_get_contents('./' . basename($val));
     }
    } else {
     header('Content-Type: image/' . strtolower(explode(".", basename($val))[1]));
     echo file_get_contents('./' . basename($val));
    }
   }
   exit;   
} else if (1 == 7 && isset($_GET['justiurl'])) {
   echo "<html><head><title>Image and Text Nodes PDF Creator - RJM Programming - August, 2022</title><meta charset='utf-8'/></head>
<body style='background:" . urldecode($_GET['justiurl']) . ";background-repeat:no-repeat;'>
</body>
</html>";
   exit;
} else if (1 == 7 && isset($_POST['justiurl'])) {
   echo "<html><head><title>Image and Text Nodes PDF Creator - RJM Programming - August, 2022</title><meta charset='utf-8'/></head>
<body style='background:URL(" . urldecode($_POST['justiurl']) . ");background-repeat:no-repeat;'>
</body>
</html>";
   exit;
} else if (strlen('' . $_SERVER['QUERY_STRING']) <= 1 || strpos('' . $_SERVER['QUERY_STRING'], '&') === false) { //strpos($_SERVER['REQUEST_URI'], '?'))
   if (!isset($_POST['pdfimageplustext'])) {
   echo "<html>
<head><title>Image and Text Nodes PDF Creator - RJM Programming - August, 2022</title>
<meta charset='utf-8'/>
<style>

 .custom-alert {
  display: inline-block;
  /* visibility: visible; */
  background-color: rgba(102,102,102,0.8);
  color: #fff;
  text-align: center;
  margin: 5% auto;
  padding: 12px 28px;
  opacity: 0.9;
  z-index: 200;
  -webkit-animation: glow 1s linear infinite alternate;
  -moz-animation: glow 1s linear infinite alternate;
  animation: glow 1s linear infinite alternate;
 }

 .custom-prompt {
  display: inline-block;
  /* visibility: visible; */
  background-color: rgba(202,202,202,0.8);
  color: #fff;
  text-align: center;
  margin: 5% auto;
  padding: 12px 28px;
  opacity: 0.9;
  z-index: 200;
  -webkit-animation: wglow 1s linear infinite alternate;
  -moz-animation: wglow 1s linear infinite alternate;
  animation: wglow 1s linear infinite alternate;
 }

 /* Thanks to https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_glowing_text */

 @-webkit-keyframes glow {
  from {
    box-shadow: 0 0 3px #fff, 0 0 5px #fff, 0 0 37px #e60073, 0 0 9px #e60073, 0 0 11px #e60073, 0 0 13px #e60073, 0 0 15px #e60073;
  }

  to {
    box-shadow: 0 0 24px #fff, 0 0 6px #ff4da6, 0 0 8px #ff4da6, 0 0 10px #ff4da6, 0 0 12px #ff4da6, 0 0 14px #ff4da6, 0 0 16px #ff4da6;
  }
 }


 @-webkit-keyframes wglow {
  from {
    box-shadow: 0 0 3px #fff, 0 0 5px #fff, 0 0 37px #7300e6, 0 0 9px #7300e6, 0 0 11px #7300e6, 0 0 13px #7300e6, 0 0 15px #7300e6;
  }

  to {
    box-shadow: 0 0 24px #fff, 0 0 6px #ff4da6, 0 0 8px #a64dff, 0 0 10px #a64dff, 0 0 12px #a64dff, 0 0 14px #a64dff, 0 0 16px #a64dff;
  }
 }

</style>
<script type='text/javascript'>

var documentURL=document.URL;
if (documentURL.indexOf('about') == 0) { documentURL='/pdfimageplustext.php';  }
var sofarso='" . $newdts . $newdtssuffix . "';  
var sofarsoatend=''; 
var sofarsonext=1;
var sofarmode=" . $sfm . ";  // 1=step through and 2=stop at sequences and dates and 3=fully automate and 4=review a full automation run

var arect=null;
var curone=2;
var isokay=true;
var xans='';
var onlval='';
var datauris=[''];
var lsnames=[];
var curls=-1;
var origtz='';
var lsname='';
var newtz='';
var woos=[];
var datauri='';
var coordn=1;
var x=-1, y=-1;
var startrecording=false;
var ontox='';
var repeats=0, lastans='';
var nofiddling=false;
var showing=false;
var showingc=false;
var ffnos=\"" . $ffnos . "\";
var cpone=\"" . $ffnos . "\";
var cmds=[];
var tempcmd=\" document.getElementById('coords').innerHTML+='<input type=hidden name=xxx value=zzz></input>'; \"; 
var rawStr='';
var mycanvas; // = document.getElementById('mycanvas');
var ctx; // = mycanvas.getContext('2d');
var myimg; // = new Image;

var encodedStr = rawStr.replace(/[\\u00A0-\\u9999<>\\&]/g, function(i) { // Thanks to https://stackoverflow.com/questions/18749591/encode-html-entities-in-javascript
   return '&#'+i.charCodeAt(0)+';';
});

/**
 * Convert a string to HTML entities ... Thanks to https://zditect.com/code/javascript/easy-solution-to-encode-html-entities-in-javascript.html
 */
String.prototype.toHtmlEntities = function() {
    return this.replace(/./gm, function(s) {
        return (s.match(/[a-z0-9" . "\\" . "s]+/i)) ? s : '&#' + s.charCodeAt(0) + ';';
    });
};

/**
 * Create string from HTML entities
 */
String.fromHtmlEntities = function(string) {
    return (string+'').replace(/&#" . "\\" . "d+;/gm,function(s) {
        return String.fromCharCode(s.match(/" . "\\" . "d+/gm)[0]);
    })
};

if (!String.fromCodePoint) {   // thanks to http://xahlee.info/js/js_unicode_code_point.html
// ES6 Unicode Shims 0.1 , © 2012 Steven Levithan , MIT License
    String.fromCodePoint = function fromCodePoint () {
        var chars = [], point, offset, units, i;
        for (i = 0; i < arguments.length; ++i) {
            point = arguments[i];
            offset = point - 0x10000;
            units = point > 0xFFFF ? [0xD800 + (offset >> 10), 0xDC00 + (offset & 0x3FF)] : [point];
            chars.push(String.fromCharCode.apply(null, units));
        }
        return chars.join('');
    }
}

function getr(incis) {
  return '' + hexdec(incis.replace('#','').substring(0,2));
}

function getg(incis) {
  return '' + hexdec(incis.replace('#','').substring(2).substring(0,2));
}

function getb(incis) {
  return '' + hexdec(incis.replace('#','').substring(4).substring(0,2));
}

 function hexdec(hexString) {  // thanks to https://locutus.io/php/math/hexdec/
  //  discuss at: https://locutus.io/php/hexdec/
  // original by: Philippe Baumann
  //   example 1: hexdec('that')
  //   returns 1: 10
  //   example 2: hexdec('a0')
  //   returns 2: 160

  hexString = (hexString + '').replace(/[^a-f0-9]/gi, '');
  return parseInt(hexString, 16);
 }
 
 function predurip(indu) {
   datauris[0]=indu;
 }
  
 function durip(indu) {
   console.log('durip=' + indu);
   datauris.push(indu);
   //if (datauris.length > 1) { alert('wow ' + datauris.length); }
 }

 function hex2dec(couleur, inopac) {
    var dolR = couleur.toLowerCase().replace('#','').substring(0,2);
    var dolrouge = hexdec(dolR);
    var dolV = couleur.toLowerCase().replace('#','').replace(dolR,'').substring(0,2);
    var dolvert = hexdec(dolV);
    var dolB = couleur.toLowerCase().replace('#','').replace(dolR,'').replace(dolV,'').substring(0,2);
    var dolbleu = hexdec(dolB);
    if (('' + inopac).replace('1.0','') != '') {
      return 'rgba(' + dolrouge + ',' + dolvert + ',' + dolbleu + ',' + inopac + ')';
    } else if (1 == 2) {
      return couleur.toLowerCase();
    } else {
      return 'rgb(' + dolrouge + ',' + dolvert + ',' + dolbleu + ')';
    }
 }

function fromnowon(ovis) {
   var jdi=0;
   var idi='' + document.getElementById('tnum').value;
   var newcmd='', newsuff='', newpref='';
   if (ovis.id == 'tnum') {
    jdi=jdi;
   } else if (ovis.id == 'tbut') {
    for (jdi=0; jdi<cmds.length; jdi++) {
      newcmd=cmds[jdi];
      if (newcmd.indexOf('' + idi + ' value=') == -1) {
        newsuff=' value=' + newcmd.split(' value=')[1];
        newpref=cmds[jdi].split('0')[0].split('1')[0].split('2')[0].split('3')[0].split('4')[0].split('5')[0].split('6')[0].split('7')[0].split('8')[0].split('9')[0];
        cmds[jdi]=newpref + idi + newsuff;
        newcmd=cmds[jdi];
      }
      //alert(newcmd);
      sofarsoatend+='@!@' + newcmd.split(' name=')[1].split(' ')[0] + ':' + newcmd.split(' value=')[1].split(' ')[0];
      eval(newcmd);
  showing=false;
  showingc=false;
  document.getElementById('custom-prompt-1').style.display='none';
    }
    cmds=[];
   } else if (ovis.id == 'tcol') {
    cmds.push(tempcmd.replace('xxx', 'pdfrtext' + idi).replace('zzz', getr(ovis.value.trim())));
    cmds.push(tempcmd.replace('xxx', 'pdfgtext' + idi).replace('zzz', getg(ovis.value.trim())));
    cmds.push(tempcmd.replace('xxx', 'pdfbtext' + idi).replace('zzz', getb(ovis.value.trim())));
    ctx.fillStyle='' + ovis.value.trim();
   } else if (ovis.id == 'tsiz') {
    cmds.push(tempcmd.replace('xxx', 'pdffontsize' + idi).replace('zzz', ovis.value.trim()));
    ctx.font = '' + ovis.value.trim() + 'px ' + document.getElementById('tfam').value.trim();
   } else if (ovis.id == 'tsty') {
    cmds.push(tempcmd.replace('xxx', 'pdffontstyle' + idi).replace('zzz', ovis.value.trim()));
   } else if (ovis.id == 'trot') {
    cmds.push(tempcmd.replace('xxx', 'pdfrotatetextdeg' + idi).replace('zzz', ovis.value.trim()));
   } else if (ovis.id == 'tdir') {
    cmds.push(tempcmd.replace('xxx', 'pdfdirectiontext' + idi).replace('zzz', ovis.value.trim()));
   } else if (ovis.id == 'tfam') {
    cmds.push(tempcmd.replace('xxx', 'pdffamily' + idi).replace('zzz', ovis.value.trim()));
    ctx.font = '' + document.getElementById('tsiz').value + 'px ' + ovis.value.trim();
   }
}

function maybemore() {
}

function iifopen(iois) {
  if (iois != null) {
    var aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto.document) { aconto = aconto.document; }
    if (aconto != null) {
    //alert(1);
      if (aconto.getElementById('distyle')) {
        aconto.getElementById('distyle').innerHTML+='<style> input[type=file]::file-selector-button { background-color: pink; } </style>';
        aconto.getElementById('files').accept='image/*';
        aconto.getElementById('files').style.border='5px solid yellow';
        arect=aconto.getElementById('files').getBoundingClientRect();
        //alert(2);
        //aconto.getElementById('files').click();
      }
    }
  }
}

function addtoform(withwhat) {
  if (withwhat.trim() != '') {
    if (x >= 0 && y >= 0) {
      document.getElementById('coords').innerHTML+='<input type=hidden name=pdfx' + coordn + ' value=\"' + ('' + x).split('.')[0] + ontox + '\"></input>';
      document.getElementById('coords').innerHTML+='<input type=hidden name=pdfy' + coordn + ' value=\"' + ('' + y).split('.')[0] + '\"></input>';
      //document.getElementById('coords').innerHTML+='<input type=hidden name=pdftext' + coordn + ' value=\"' + withwhat + '\"></input>';
      if (withwhat.toHtmlEntities().replace(/\\&\\#[0-9][0-9][0-9]\\;/g,'').replace(/\\&\\#[0-9][0-9]\\;/g,'').replace(/\\&\\#[0-9]\\;/g,'').indexOf('&#') >= 0) {
      //alert(withwhat.toHtmlEntities() + ' versus ' + withwhat);
      document.getElementById('coords').innerHTML+='<input type=hidden id=pdftext' + coordn + ' name=pdftext' + coordn + ' value=\"\"></input>';
      if (document.getElementById('bpdftext' + coordn)) {
        document.getElementById('bpdftext' + coordn).title='Sorry, cannot Click Delete ... ' + withwhat;
      }
      canvasize(('' + x).split('.')[0], ('' + y).split('.')[0], withwhat);
      } else {
      document.getElementById('coords').innerHTML+='<input type=hidden id=pdftext' + coordn + ' name=pdftext' + coordn + ' value=\"' + withwhat.toHtmlEntities() + '\"></input>';
       if (document.getElementById('bpdftext' + coordn)) {
        document.getElementById('bpdftext' + coordn).title='Click Delete ... ' + withwhat;
      }
     }
      //rawStr=withwhat;
      //alert('x=' + x + ' andy=' + y + ' and text=' + withwhat + ' and Text=' + withwhat.toHtmlEntities() );
      coordn++;
      document.getElementById('tnum').value='' + coordn;
      ontox='';
      startrecording=false; 
    } //else {
       //alert('oops');
    //}
  }
}

function canvasize(inx, iny, inemojis) {
  var lineHeight=eval('' + document.getElementById('tsiz').value);
  if (document.getElementById('tdir').value.toUpperCase().substring(0,1) == 'U') {
  ctx.save();
  ctx.translate(inx, iny);
  ctx.rotate(-Math.PI / 2);
  ctx.textAlign = 'left';
  ctx.fillText(inemojis, 0, lineHeight / 2);
  ctx.restore();
  } else if (document.getElementById('tdir').value.toUpperCase().substring(0,1) == 'D') {
  ctx.save();
  ctx.translate(inx, iny);
  ctx.rotate(Math.PI / 2);
  ctx.textAlign = 'left';
  ctx.fillText(inemojis, 0, lineHeight / 2);
  ctx.restore();
  } else if (document.getElementById('tdir').value.toUpperCase().substring(0,1) == 'L') {
  ctx.save();
  ctx.translate(inx, iny);
  ctx.rotate(Math.PI / 1);
  ctx.textAlign = 'left';
  ctx.fillText(inemojis, 0, lineHeight / 2);
  ctx.restore();
  } else if (document.getElementById('trot').value.toUpperCase().substring(0,1) != '0') {
  ctx.save();
  ctx.translate(inx, iny);
  ctx.rotate(eval(eval('' + document.getElementById('trot').value) * Math.PI / 180.0));
  ctx.textAlign = 'left';
  ctx.fillText(inemojis, 0, lineHeight / 2);
  ctx.restore();
  } else if (document.getElementById('tdir').value.toUpperCase().substring(0,1) == 'R') {
  ctx.fillText(inemojis, inx, iny);
  } else {
  ctx.fillText(inemojis, inx, iny);
  }
  document.getElementById('slideshow').value=mycanvas.toDataURL('image/jpeg');
  if (datauris.length != 1) {
   //if (datauris.length > 1) { alert('Wow ' + datauris.length); }
  var multi='url(' + document.getElementById('slideshow').value + ')';
  var br='no-repeat';
  var bs='contain';
  for (var ioop=1; ioop<datauris.length; ioop++) {
    multi+=',url(' + datauris[ioop] + ')';
    br+=',no-repeat';
    bs+=',contain';
  }
  if (1 == 1) {
  document.body.style.backgroundImage='url(' + document.getElementById('slideshow').value + ')';
  } else {
  //alert(multi);
  document.body.style.backgroundImage=multi;
  document.body.style.backgroundRepeat=br;
  document.body.style.backgroundSize=bs;
  document.body.style.backgroundPosition='right bottom, left top';
  }
  document.getElementById('myform').target='_top'; // 'iblank'
  } else {
  document.body.style.backgroundImage='url(' + document.getElementById('slideshow').value + ')';
  }
}

function encodeHTML(str) {
    return str.replace(/([" . "\\" . "u00A0-" . "\\" . "u9999<>&])(.|$)/g, function(full, char, next) {
      if(char !== '&' || next !== '#'){
        if(/[" . "\\" . "u00A0-" . "\\" . "u9999<>&]/.test(next))
          next = '&#' + next.charCodeAt(0) + ';';

        return '&#' + char.charCodeAt(0) + ';' + next;
      }

      return full;
    });
}

function decodeHTML(str) {
    return str.replace(/&#([0-9]+);/g, function(full, int) {
        return String.fromCharCode(parseInt(int));
    });
}

function analyze(inans) {
  var zeroes='';
  var ffst=',Courier,Helvetica,Arial,Times,Symbol,ZapfDingbats,';
  var fss=',regular,normal, ,B,bold,I,italic,itallic,U,underline,';
  var outans=inans.replace(/\\~\\~/g, String.fromCharCode(10));
  var arris=outans.split(';');
  if (arris.length > 1) {
    for (var iarris=0; iarris<eval(-1 + eval('' + arris.length)); iarris++) {
      if ((arris[iarris] + ' ').substring(0,1) >= '0' && (arris[iarris] + ' ').substring(0,1) <= '9') {
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontsize').value='' + arris[iarris];
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontsize name=pdffontsize value=\"' + arris[iarris] + '\"></input>';
          }
        }
        ontox='.' + zeroes + arris[iarris];
        outans=outans.replace(arris[iarris] + ';', '');
      } else if (ffst.toLowerCase().indexOf(',' + arris[iarris].toLowerCase() + ',') != -1) {
        outans=outans.replace(arris[iarris] + ';', '');
        if (document.getElementById('pdffamily')) {
          document.getElementById('pdffamily').value=arris[iarris].substring(0,1).toUpperCase() + arris[iarris].substring(1).toLowerCase().replace('apfdingbats','apfDingbats');
        } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffamily name=pdffamily value=' + arris[iarris].substring(0,1).toUpperCase() + arris[iarris].substring(1).toLowerCase().replace('apfdingbats','apfDingbats') + '></input>';
        }
      } else if (fss.toLowerCase().indexOf(',' + arris[iarris].toLowerCase() + ',') != -1) {
        switch (fss.toLowerCase()) {
          case 'regular':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value=' ';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"N\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='0';
        }
            break;
          case 'normal':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='N';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"N\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='0';
        }
            break;
          case 'n':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='N';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"N\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='0';
        }
            break;
          case 'b':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='B';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"B\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='0000';
        }
            break;
          case 'bold':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='B';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"B\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='0000';
        }
            break;
          case 'i':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='I';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"I\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='00';
        }
            break;
          case 'italic':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='I';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"I\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='00';
        }
            break;
          case 'itallic':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='I';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"I\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='00';
        }
            break;
          case 'u':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='U';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"U\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='000';
        }
            break;
          case 'underline':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='U';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"U\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='000';
        }
            break;
          default:
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value=' ';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\" \"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='0';
        }
            break;
        }
      }
    }
  }
  if (ontox == '' && zeroes != '') { ontox='.' + zeroes; }
  if (repeats > 0) { repeats--; if (repeats == 0) { lastans=''; }  }
  return outans;
}

function askaway() {
  var retval=true;
  var ans=' ';
  if (startrecording && !showingc) {
  if (repeats > 0) {
  ans=lastans;
  if (ans == null) { ans=''; }
  if (ans.trim() != '' && x >= 0 && y >= 0) {
      sofarsoatend+='@!@' + ans + '!!!' + x + '@@@' + y;
  } else if (ans.trim() == '' && ans != '' && x >= 0 && y >= 0) {
      sofarsoatend+='@!@!!!' + x + '@@@' + y;
      lsnamesaveas();
      ans='';
  }
  if (analyze(ans).trim() == '') { startrecording=false; if (1 == 11) {  alert(document.getElementById('coords').innerHTML);  } if (9 == 99) { document.getElementById('isub').click(); } else { huhf(); document.getElementById('myform').submit(); }  } else { addtoform(ans); setTimeout(askaway, 5000);   }
  } else {
  repeats=0;
  lastans='';
  var indef='';
  if (document.getElementById('mytextarea')) {
    if (document.getElementById('mytextarea').value != '') {
      indef=document.getElementById('mytextarea').value;
      while (indef.indexOf(String.fromCharCode(10)) != -1) {
        indef=indef.replace(String.fromCharCode(10), '~~')
      }
      if (sofarmode == 0) { document.getElementById('mytextarea').value=''; }
    }
  }
  if (xans != '') {
  var nondebatable=false;
  if (sofarmode == 2 && xans.toUpperCase().indexOf('DATE') != 0 && xans.toUpperCase().replace(' * ',' x ').indexOf(' x ') == -1) { nondebatable=true; }
  if (sofarmode == 3 || nondebatable) {
  ans=xans.trim();
  xans='';
  } else if (sofarmode == 1 || (sofarmode == 2 && !nondebatable)) {
  if (isokay) {
  indef=xans.trim();
  }
  //xans='';
  //retval=false;
  ans=prompt('Append more spaces to default suggestion in order to indicate you want to click again in a new place for this entry, and note that you can change wording, as well over at the textarea if you wish.  Enter with nothing to proceed or space to Save As along the way to creating PDF.  Else enter text number ' + coordn + ' to place where last click was made.  Can use a suffix such as x 5 to repeat value on the 4 clicks to follow.  Optionally prefix by text Font Family (for all text if Arial no good versus Courier or Helvetica or Arial or Times or Symbol or ZapfDingbats);Font Style (double semicolon delimit for all text default if Bold no good else single semicolon delimit for this text only versus Normal or Italic or Bold or Underline);Font Size in px (for this text if 16px no good) delimited by semicolon.  Line feed via ~~ anywhere.',indef);
  if (ans.trim() == xans.trim() && xans != ans) { retval=false; return retval; } else { retval=true; xans=''; }
  }
  } else {
  ans=prompt('Enter with nothing to proceed or space to Save As along the way to creating PDF.  Else enter text number ' + coordn + ' to place where last click was made.  Can use a suffix such as x 5 to repeat value on the 4 clicks to follow.  Optionally prefix by text Font Family (for all text if Arial no good versus Courier or Helvetica or Arial or Times or Symbol or ZapfDingbats);Font Style (double semicolon delimit for all text default if Bold no good else single semicolon delimit for this text only versus Normal or Italic or Bold or Underline);Font Size in px (for this text if 16px no good) delimited by semicolon.  Line feed via ~~ anywhere.',indef);
  }
  if (ans == null) { ans=''; }
  if (ans.trim() != '' && x >= 0 && y >= 0) {
      sofarsoatend+='@!@' + ans + '!!!' + x + '@@@' + y;
  } else if (ans.trim() == '' && ans != '' && x >= 0 && y >= 0) {
      sofarsoatend+='@!@!!!' + x + '@@@' + y;
      lsnamesaveas();
      ans='';
  }
  var rarris=ans.replace(' * ',' x ').split(' x 1');
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 2');  } 
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 3');  }
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 4');  }
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 5');  }
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 6');  }
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 7');  }
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 8');  }
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 9');  }
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 0');  }
  if (rarris.length > 1) { repeats=eval(0 + eval('' + ans.replace(' * ',' x ').split(' x ')[1])); lastans=ans.replace(' * ',' x ').split(' x ')[0];   } else if (1 == 3) { lastans=''; }
  if (analyze(ans).trim() == '') { startrecording=false; if (1 == 11) {  alert(document.getElementById('coords').innerHTML);  }  huhf();  document.getElementById('myform').submit();  } else { addtoform(ans); setTimeout(askaway, 5000);   }
  }
  }
  if (retval) { xans=''; }
  return retval;
}

function blobover(ini) {
  event.target.style.backgroundColor='orange';
}

function blobout(ini) {
  event.target.style.backgroundColor='red';
}

function blobdel(inid) {
 inid='' + event.target.id;
 event.stopPropagation();
 if (document.getElementById(inid).title.indexOf('Sorry') != 0) {
  //if (!document.getElementById(inid.substring(1))) {
  //alert('Why not found? ' + inid);
  //} else {
  document.getElementById(inid.substring(1)).value='';
  document.getElementById(inid).style.backgroundColor='cyan';
  document.getElementById(inid).title=document.getElementById(inid).title.replace('Delete ', 'Deleted ');
  //}
 } 
}

function noshow() {
  document.getElementById('doverlay').innerHTML=''; 
  document.getElementById('cbi').style.display='none'; 
  document.getElementById('myp').style.display='none'; 
  document.getElementById('iurl').style.display='none'; 
  document.getElementById('relfind').style.display='none'; 
  document.getElementById('myptwo').style.display='none'; 
  document.getElementById('myh1').style.display='none'; 
  document.getElementById('myh3').style.display='none'; 
  document.getElementById('thetable').style.display='none'; 
}

function redraw() {
  document.getElementById('doverlay').innerHTML=''; 
  document.getElementById('cbi').style.display='none'; 
  document.getElementById('myp').style.display='none'; 
  document.getElementById('iurl').style.display='none'; 
  document.getElementById('relfind').style.display='none'; 
  document.getElementById('myptwo').style.display='none'; 
  document.getElementById('myh1').style.display='none'; 
  document.getElementById('myh3').style.display='none'; 
  document.getElementById('thetable').style.display='none'; 
  if (datauris.length != 1) {
  //if (datauris.length > 1) { alert('Wow ' + datauris.length); }
  var multi='url(' + document.getElementById('slideshow').value + ')';
  var br='no-repeat';
  var bs='contain';
  for (var ioop=1; ioop<datauris.length; ioop++) {
    multi+=',url(' + datauris[ioop] + ')';
    br+=',no-repeat';
    bs+=',contain';
  }
  //alert(multi);
  if (1 == 1) {
    document.getElementById('mybody').style.background='url(' + datauri + ')';
  } else {
  document.getElementById('mybody').style.backgroundImage=multi;
  document.getElementById('mybody').style.backgroundRepeat=br;
  document.getElementById('mybody').style.backgroundSize=bs;
  document.getElementById('mybody').style.backgroundPosition='right bottom, left top';
  }
  document.getElementById('myform').target='_top';  // 'iblank'
  } else {
  document.getElementById('mybody').style.background='url(' + datauri + ')';
  }
mycanvas = document.getElementById('mycanvas');
ctx = mycanvas.getContext('2d');
myimg = new Image;
myimg.onload = function() {
  mycanvas.width=myimg.width;
  mycanvas.height=myimg.height;
  mycanvas.style.width='' + myimg.width + 'px';
  mycanvas.style.height='' + myimg.height + 'px';
  ctx.font = '' + document.getElementById('tsiz').value.trim() + 'px ' + document.getElementById('tfam').value.trim();
  ctx.fillStyle='' + document.getElementById('tcol').value.trim();
  ctx.drawImage(myimg,0,0); // Or at whatever offset you like
};
myimg.src = datauri;
  document.getElementById('mybody').style.backgroundRepeat='no-repeat';
  document.getElementById('slideshow').name='pdfimage';
  if (document.body.outerHTML.indexOf('url(') != -1) {
    datauri=document.body.outerHTML.split('url(')[1].split(')')[0].replace(/\&quot\;/g,''); //.replace(/\'/g,'').replace(/\\\"/g,'');
    datauris[0]=datauri;
  }
  document.getElementById('slideshow').value=datauri;
  sofarso+='@!@' + document.getElementById('slideshow').value;
  //alert(datauri.substring(0,100) + ' ... ' + document.body.outerHTML.substring(0,350));
  document.getElementById('coords').innerHTML+='<input type=hidden name=pdfimageplustext value=y></input>';
  startrecording=true;
  document.getElementById('mybody').onclick=function(e){
    e = e || window.event;
    e.preventDefault();
       if (!showingc) {
       startrecording=true;
       if (e.touches) {
       if (e.touches[0].pageX) {
       x = e.touches[0].pageX;
       y = e.touches[0].pageY;
       document.getElementById('blob').innerHTML+='<div onmouseover=\" blobover(this); \" onmouseout=\" blobout(this);\" onclick=\" blobdel(this.id); \" title=\"\" id=\"bpdftext' + coordn + '\" style=\"position:absolute;left:' + x + 'px;top:' + y + 'px;background-color:red;z-index:200;\">x</div>';
       setTimeout(askaway,500);
       } else {
       x = e.touches[0].clientX;
       y = e.touches[0].clientY;
       document.getElementById('blob').innerHTML+='<div onmouseover=\" blobover(this); \" onmouseout=\" blobout(this);\" onclick=\" blobdel(this.id); \" title=\"\" id=\"bpdftext' + coordn + '\" style=\"position:absolute;left:' + x + 'px;top:' + y + 'px;background-color:red;z-index:200;\">x</div>';
       setTimeout(askaway,500);
       }
       //console.log('pos3=' + pos3 + ',pos4=' + pos4);
       } else if (e.clientX || e.clientY) {
        x = e.clientX;
        y = e.clientY;
       document.getElementById('blob').innerHTML+='<div onmouseover=\" blobover(this); \" onmouseout=\" blobout(this);\" onclick=\" blobdel(this.id); \" title=\"\" id=\"bpdftext' + coordn + '\" style=\"position:absolute;left:' + x + 'px;top:' + y + 'px;background-color:red;z-index:200;\">x</div>';
       setTimeout(askaway,500);
       } else {
        x = e.pageX;
        y = e.pageY;
       document.getElementById('blob').innerHTML+='<div onmouseover=\" blobover(this); \" onmouseout=\" blobout(this);\" onclick=\" blobdel(this.id); \" title=\"\" id=\"bpdftext' + coordn + '\" style=\"position:absolute;left:' + x + 'px;top:' + y + 'px;background-color:red;z-index:200;\">x</div>';
       setTimeout(askaway,500);
       }
       }
  };
  document.getElementById('mybody').title='Click where text to be placed in resultant PDF. Can use suffix such as x 5 to repeat value on 4 clicks to follow. As far as dates go consult https://www.w3schools.com/php/func_date_date_format.asp DATE_ATOM type entries where DATE_ followed by ymd lowercase character correspondence in 2nd part means change just date via its ymd means whereas date_ followed by hms lowercase character correspondence in 2nd part means change time via its hms means whereas uppercase 2nd part preceeded by ymd lowercase character in first part means change datetime via its ymd means whereas datE_ followed by hms lowercase character correspondence in 2nd part means change datetime via its hms means. Incrementing scale can be done via ++ or -- or +=2 or -=4 types of strings before x 5 repeat definitions. An offset to DATE_ATOM type entry meaning of today and now can be achieved via no spaces between it and offset ++ or -4 type of string and optional more until string such as Tuesday. Basis date is " . $newdts . "'; //setTimeout(askaway, 5000); //alert('am here');
  document.body.innerHTML+=\"<div id=custom-alert-1 class=custom-alert style='position:fixed; left: 50%; transform: translate(-50%, -50%); top:50%; display: block;'>Click where text node(s) are to be placed in your resultant PDF.  You will get prompted for optional styling options.  There are also other glowing <i>from now on</i> ways to change the text look.</div>\";
  document.body.innerHTML+=\"<div onclick='showingc=showing; event.stopPropagation();' id=custom-prompt-1 class=custom-prompt style='position:fixed; left: 70%; transform: translate(-70%, -10%); top:10%; display: none;'>\" + cpone +  \"</div>\";
  setTimeout(hideIt, 10000);
  setTimeout(showPromptIt, 5000);
  if (curls >= 0 && eval('' + lsnames.length) > curone) {
    curls=curone;
    startrecording=true;
    showingc=false;
    if (sofarmode == 3) {
    setTimeout(processcmd, 3000);
    } else {
    x=eval(lsnames[curls].split('!!!')[1].split('@@@')[0]);
    y=eval(lsnames[curls].split('@@@')[1]);
    xans=lsnames[curls].split('!!!')[0] + ' ';
    document.getElementById('mytextarea').value=xans.replace(/" . "\\" . "~" . "\\" . "~/g, String.fromCharCode(10));    
    setTimeout(processcmd, 15000);
    }
  }
 }
 
 function nextoneisone(one) {
   if (eval(one + curls) < eval('' + lsnames.length)) {
   document.getElementById('mytextarea').value='';
   if (lsnames[eval(one + curls)].indexOf('!!!') != -1) {
    x=eval(lsnames[eval(one + curls)].split('!!!')[1].split('@@@')[0]);
    y=eval(lsnames[eval(one + curls)].split('@@@')[1]);
    xans=lsnames[eval(one + curls)].split('!!!')[0] + ' ';
    document.getElementById('mytextarea').value=xans.replace(/" . "\\" . "~" . "\\" . "~/g, String.fromCharCode(10));    
   }
   }
   return one;
 }
 
 function processcmd() {
   if (isokay && eval('' + curls) < eval(0 + eval('' + lsnames.length))) {
   xans='';
   //document.getElementById('mytextarea').value='';
   if (lsnames[curls].indexOf('!!!') != -1) {
   //alert('curls=' + curls + ' ' + lsnames[curls]);
     x=eval(lsnames[curls].split('!!!')[1].split('@@@')[0]);
     y=eval(lsnames[curls].split('@@@')[1]);
     xans=lsnames[curls].split('!!!')[0] + ' ';
  //alert('Xans=' + xans);
    document.getElementById('mytextarea').value=xans.replace(/" . "\\" . "~" . "\\" . "~/g, String.fromCharCode(10));
     //alert('Will start with command ' + lsnames[curls]);
     startrecording=true;
     showingc=false;
     document.getElementById('blob').innerHTML+='<div style=\"position:absolute;left:' + x + 'px;top:' + y + 'px;background-color:red;z-index:200;\">x</div>';
 //alert('xans=' + xans);
     isokay=askaway();
     if (eval('' + curls) < eval(-1 + eval('' + lsnames.length))) {
     if (isokay) { curls+=nextoneisone(1); }
     setTimeout(processcmd, 2000);
     }
   } else if ((lsnames[curls] + ' ').indexOf('#') == 0) {
   curls++;
   setTimeout(processcmd, 100);
   } else if ((lsnames[curls] + ' ').indexOf(':') != -1 && (lsnames[curls] + ' ').indexOf('data:') != 0) {
   alert(lsnames[curls].split(':')[0]);
   document.getElementById(lsnames[curls].split(':')[0]).value=lsnames[curls].replace(lsnames[curls].split(':')[0] + ':', '');
   curls+=nextoneisone(1);
   setTimeout(processcmd, 100);
   } else {
   curls+=nextoneisone(1);
   setTimeout(processcmd, 100);
   }
   } else if (eval('' + curls) < eval(-1 + eval('' + lsnames.length))) {
     setTimeout(processcmd, 2000);
   }
 }

 function hideIt() {
  document.getElementById('custom-alert-1').style.display='none';
 }

 function showPromptIt() {
  showing=true;
  showingc=false;
  document.getElementById('custom-prompt-1').style.display='block';
  if (cpone == '') {
  cpone=document.getElementById('custom-prompt-1').innerHTML;
  }
  setTimeout(hidePromptIt, 20000);
 }

 function hidePromptIt() {
  showing=false;
  showingc=false;
  document.getElementById('custom-prompt-1').style.display='none';
  setTimeout(showPromptIt, 10000);
 }

function lookfordatauri() {
  if (datauri == '' && document.getElementById('slideshow').value.trim() != '') {
    //datauri=' ';
    //setTimeout(lookfordatauri, 19000);
  //} else if (datauri .trim()== '' && document.getElementById('slideshow').value.trim() != '') {
    if (nofiddling || datauris[0] != '') {
    datauri=document.getElementById('slideshow').value;
    datauris[0]=datauri;
    if (('   ' + sofarso).slice(-3) == '@!@') { sofarso+=datauri; }
    } else {
    datauri=document.getElementById('slideshow').value.replace(/^\.\.\//g, '').replace(/^\.\//g, 'PHP/');
    datauris[0]=datauri;
    document.getElementById('slideshow').value=datauri;
    if (('   ' + sofarso).slice(-3) == '@!@') { sofarso+=datauri; }
    }
    //document.getElementById('slideshow').value='';
    redraw(); //document.getElementById('isub').click();
  } else {
    setTimeout(lookfordatauri, 1000);
  }
}

function setjust(ino) {
  var szc='';
  var trc='';
  var lastcis=-1;
  var hases=ino.value.split('#');
  if (hases[0].replace('?','*').indexOf('*') != -1) {
  nofiddling=true;
  document.getElementById('iblank').src='./pdfimageplustext.php?wildcard=' + encodeURIComponent(hases[0]);
  } else {
  if (ino.value.trim() != '') {
    if (hases.length > 1) {
      if (hases[1].trim() != '') {
        var coms=hases[1].split(',');
        sofarsoatend+='@!@#' + hases[1];
        if (hases[1].toLowerCase().indexOf('rgb') == 0) {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfrtext name=pdfrtext value=' + hases[1].split('(')[1].split(',')[0] + '></input>';
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfgtext name=pdfgtext value=' + hases[1].split('(')[1].split(',')[1] + '></input>';
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfbtext name=pdfbtext value=' + hases[1].replace(')',',').split('(')[1].split(',')[2] + '></input>';
          cpone=cpone.replace(' value=#000000', ' value=#' + hases[1].split('(')[1].split(',')[0].toString(16) + hases[1].split('(')[1].split(',')[1].toString(16) + hases[1].replace(')',',').split('(')[1].split(',')[2].toString(16));
          hases[1]=hases[1].replace(hases[1].split(')')[0] + ')', '').trim();
        }
        if (ino.value.replace(hases[0] + '#','').indexOf('px') != -1) {
          while ((' ' + ino.value.replace(hases[0] + '#','').split('px')[0]).slice(lastcis).substring(0,1) >= '0' && (' ' + ino.value.replace(hases[0] + '#','').split('px')[0]).slice(lastcis).substring(0,1) <= '9') {
            szc=(' ' + ino.value.replace(hases[0] + '#','').split('px')[0]).slice(lastcis);
            lastcis--;
          }
          hases[1]=hases[1].replace(szc + 'px', '').trim();
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontsize name=pdffontsize value=' + szc + '></input>'; 
          cpone=cpone.replace(' value=16', ' value=' + szc);
        }
        lastcis=1;
        if ((hases[1] + ' ').substring(0,1) >= '0' && (hases[1] + ' ').substring(0,1) <= '9') {
          while ((hases[1] + ' ').substring(0,lastcis).slice(-1) >= '0' && (hases[1] + ' ').substring(0,lastcis).slice(-1) <= '9') {
            trc+=(hases[1] + ' ').substring(0,lastcis).slice(-1);
            lastcis++;
          }
          hases[1]=hases[1].replace(trc + '', '').trim();
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfrotatetextdeg name=pdfrotatetextdeg value=' + trc + '></input>'; 
          cpone=cpone.replace(' value=0', ' value=' + trc);
        }
        if (hases[1].indexOf('Normal') != -1) {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdfdfontstyle value=\" \"></input>'; 
          hases[1]=hases[1].replace('Normal', '').trim();
          cpone=cpone.replace(' id=tsty>', ' id=tsty><option value=>Normal</option>');
        }
        if (hases[1].indexOf('Bold') != -1) {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdfdfontstyle value=\"B\"></input>'; 
          hases[1]=hases[1].replace('Bold', '').trim();
        }
        if (hases[1].indexOf('Ital') != -1) {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdfdfontstyle value=\"I\"></input>'; 
          hases[1]=hases[1].replace('Italic', '').replace('Itallic', '').trim();
          cpone=cpone.replace(' id=tsty>', ' id=tsty><option value=I>Italic</option>');
        }
        if (hases[1].indexOf('Underline') != -1) {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdfdfontstyle value=\"U\"></input>'; 
          hases[1]=hases[1].replace('Underline', '').trim();
          cpone=cpone.replace(' id=tsty>', ' id=tsty><option value=U>Underline</option>');
        }
        if (hases[1].indexOf('R') != -1) { 
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfdirectiontext name=pdfdirectiontext value=R></input>'; 
          cpone=cpone.replace(' id=tdir>', ' id=tdir><option value=Right>Right</option>');
        } else if (hases[1].indexOf('L') != -1) { 
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfdirectiontext name=pdfdirectiontext value=L></input>'; 
        } else if (hases[1].indexOf('U') != -1) { 
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfdirectiontext name=pdfdirectiontext value=U></input>'; 
          cpone=cpone.replace(' id=tdir>', ' id=tdir><option value=U>Up</option>');
        } else if (hases[1].indexOf('D') != -1) { 
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfdirectiontext name=pdfdirectiontext value=D></input>'; 
          cpone=cpone.replace(' id=tdir>', ' id=tdir><option value=D>Down</option>');
        }
      }
      document.getElementById('iurl').value=hases[0].trim() ; //ino.value.split('#')[0];
    }
    if (hases[0].trim() != '') {
    nofiddling=true;
    document.getElementById('slideshow').value=ino.value.split('#')[0];
    lookfordatauri(); //document.getElementById('isub').click();
    nofiddling=false;
    }
  }
  }
}

function maybels(putorig) {
  //alert(putorig);
  if (origtz == '') { origtz=putorig; }
  if (lsname != '') {
    if (lsname.indexOf('_') != -1 && lsname.indexOf('/') != -1 && lsname.indexOf('/') > lsname.indexOf('_')) {
      newtz=lsname.replace(lsname.split('_')[0] + '_', '');
      //document.getElementById('mytzn').value=newtz;
      return newtz;
    }
  }
  return putorig;
}

function lslook() {
  var lsstuff='', jj=1;
  if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
    document.getElementById('pressi').click();
  }
  if (('' + window.localStorage.getItem('pdftimesheet' + jj)).replace(/^undefined/g,'').replace(/^null/g,'') != '') {
    if (decodeURIComponent('' + window.localStorage.getItem('pdftimesheet' + jj)).indexOf('@!@') != -1) {
      lsstuff='<option value=\"' + 'pdftimesheet' + jj + '\">' + decodeURIComponent('' + window.localStorage.getItem('pdftimesheet' + jj)).split('@!@')[0].replace('_',' ') + '</option>';
    }
    jj++;
    while (('' + window.localStorage.getItem('pdftimesheet' + jj)).replace(/^undefined/g,'').replace(/^null/g,'') != '') {
      if (decodeURIComponent('' + window.localStorage.getItem('pdftimesheet' + jj)).indexOf('@!@') != -1) {
        lsstuff+='<option value=\"' + 'pdftimesheet' + jj + '\">' + decodeURIComponent('' + window.localStorage.getItem('pdftimesheet' + jj)).split('@!@')[0].replace('_',' ') + '</option>';
      }
      jj++;
    }
    sofarsonext=jj;
    document.getElementById('lstd').innerHTML='<span id=tablespan> ... or ... <select style=background-color:pink; onchange=lsnameget(this.value);><option value=>Optionally select a Standing Order PDF Creation below to step through ...</option>' + lsstuff + '</select>&nbsp;<select style=background-color:magenta; onchange=lsnamefullauto(this.value);><option value=>Standing Order PDF Creation to fully automate ...</option>' + lsstuff + '</select>&nbsp;<select style=background-color:olive; onchange=lsnamereviewfullauto(this.value);><option value=>Standing Order PDF Creation to review a full automation run ...</option>' + lsstuff + '</select>&nbsp;<select style=background-color:cyan; onchange=lsnamesemiauto(this.value);><option value=>Standing Order PDF Creation to stop at sequence clicks and date clicks ...</option>' + lsstuff + '</select>&nbsp;<select style=background-color:lightblue; onchange=lsnamedelete(this.value);><option value=>Standing Order PDF Creation to delete ...</option>' + lsstuff + '</select>';
  }
  onlval=location.search.split('myls3=')[1] ? decodeURIComponent(location.search.split('myls3=')[1].split('&')[0]) : '';
  if (onlval != '') {
    sofarmode=3;
  } else {
    onlval=location.search.split('myls2=')[1] ? decodeURIComponent(location.search.split('myls2=')[1].split('&')[0]) : '';
    if (onlval != '') {
      sofarmode=2;
      setTimeout(setupgn, 2000); //document.getElementById('nextetc').innerHTML+='<br><button onclick=gonext();>Next</button>';
    } else {
      onlval=location.search.split('myls1=')[1] ? decodeURIComponent(location.search.split('myls1=')[1].split('&')[0]) : '';
      if (onlval != '') {
        sofarmode=1;
        setTimeout(setupgn, 2000); //document.getElementById('nextetc').innerHTML+='<br><button onclick=gonext();>Next</button>';
      } else {
       onlval=location.search.split('myls4=')[1] ? decodeURIComponent(location.search.split('myls4=')[1].split('&')[0]) : '';
       if (onlval != '') {
        sofarmode=4;
        setTimeout(setupgn, 2000); //document.getElementById('nextetc').innerHTML+='<br><button onclick=gonext();>Next</button>';
       } else {
        onlval=location.search.split('myls=')[1] ? decodeURIComponent(location.search.split('myls=')[1].split('&')[0]) : '';
       }
      }
    }
  }
  
  if (onlval != '') {
    //alert(onlval);
    if (onlval.indexOf('_') != -1 && onlval.indexOf('/') != -1) { // && onlval.indexOf('/') > onlval.indexOf('_')) {
     if (onlval.indexOf('/') > onlval.indexOf('_')) {
      newtz=onlval.replace(onlval.split('_')[0] + '_', '');
      onlval=onlval.split('_')[0];
     }
    }
    //alert('Onlval=' + onlval + ' ... ' + ('' + window.localStorage.getItem(onlval)));
    if (decodeURIComponent('' + window.localStorage.getItem(onlval)).indexOf('@!@') != -1) {
     lsval=decodeURIComponent(window.localStorage.getItem(onlval)).replace('@!@@!@','@!@');
     //alert('Lsval=' + lsval);
     if (lsval.indexOf('@!@') != -1) {
      lsnames=lsval.split('@!@');
      if (sofarmode == 4) {
        if (eval('' + lsnames.length) > 2) {
          if (lsnames[eval(-1 + lsnames.length)].indexOf('!!!') == 0) {
            lsval=lsval.replace('@!@' + lsnames[eval(-1 + lsnames.length)], '');
            lsnames=lsval.split('@!@');
          }
        }
        sofarmode=3;
      }
      curls=0;
      lsname=lsval.split('@!@')[0];
      lsvaliname=lsval.split('@!@')[1];
      if (lsvaliname.indexOf('data:') == 0) {  lsvaliname=lsvaliname.replace(/" . "\\" . " /g,'+');  }
      if (eval('' + lsval.length) > 2) {
        if (lsval[2].replace('#','').trim() != '' && ('' + lsval[1] + ' ').indexOf('#') == 0) {
           document.getElementById('iurl').value='#' + lsval[2];
           setjust(document.getElementById('iurl'));
           curone++;
        }
      }
      //alert('onlval=' + onlval);
      document.getElementById('mytzn').value=maybels('' + Intl.DateTimeFormat().resolvedOptions().timeZone); //maybels(document.getElementById('mytzn').value);
      sofarso=lsname + '@!@' + lsvaliname;
      document.getElementById('slideshow').value=lsvaliname;  // standing order image established
      //alert('here');
      datauri='';
      //if (lsval.indexOf('DATE_') != -1) {
   //alert(lsval.substring(eval(-30 + lsval.indexOf('DATE_'))));
      //} else {
   //alert(sofarso);
      //}
     lookfordatauri();
     }
    }
  } else {
     document.getElementById('mytzn').value=maybels('' + Intl.DateTimeFormat().resolvedOptions().timeZone);
     if (sofarso.indexOf(document.getElementById('mytzn').value) == -1) {
     sofarso+='_' + document.getElementById('mytzn').value + '@!@';
     } else {
     sofarso+='@!@';
     }
  }
  if (document.getElementById('doverlay1')) {
    setTimeout(arectdivs, 2000);
  }
}

  function arectdivs() {
  if (document.getElementById('doverlay1')) {
    document.getElementById('doverlay1').style.position='absolute';
    document.getElementById('doverlay1').style.zIndex='999';
    document.getElementById('doverlay1').style.backgroundColor='#fefefe';
    document.getElementById('doverlay1').style.top='0px';
    document.getElementById('doverlay1').style.left='0px';
    document.getElementById('doverlay1').style.width='173px'; //'' + eval(228 - eval('' + arect.width) + 'px';
    document.getElementById('doverlay1').style.height='' + eval(218 - eval('' + arect.top)) + 'px';
    //alert(arect.top);
    document.getElementById('doverlay2').style.position='absolute';
    document.getElementById('doverlay2').style.zIndex='999';
    document.getElementById('doverlay2').style.backgroundColor='#fefefe';
    document.getElementById('doverlay2').style.top='' + eval(222 - eval('' + arect.top) + eval('' + arect.height)) + 'px';
    document.getElementById('doverlay2').style.left='0px';
    document.getElementById('doverlay2').style.width='173px'; //'' + eval(228 - eval('' + arect.width)) + 'px';
    document.getElementById('doverlay2').style.height='14px'; //'' + eval(228 - eval('' + arect.top) + eval('' + arect.height)) + 'px';

    document.getElementById('doverlay3').style.position='absolute';
    //document.getElementById('doverlay3').style.border='1px dotted red';
    document.getElementById('doverlay3').style.zIndex='999';
    document.getElementById('doverlay3').style.backgroundColor='#fefefe';
    document.getElementById('doverlay3').style.top='10px'
    document.getElementById('doverlay3').style.left='100px';
    document.getElementById('doverlay3').style.width='50px';
    document.getElementById('doverlay3').style.height='50px';
  }
  }

  function setupgn() {
    document.getElementById('nextetc').innerHTML+='<br><button onclick=gonext();>Next</button>';
  }


function lsnamereviewfullauto(tv) {
  if (tv.trim() != '') {
   sofarmode=4;
   lsnameget(tv.split('_')[0]);
  }
}

function lsnamefullauto(tv) {
  if (tv.trim() != '') {
   sofarmode=3;
   lsnameget(tv.split('_')[0]);
  }
}

function lsnamesemiauto(tv) {
  if (tv.trim() != '') {
   sofarmode=2;
   lsnameget(tv.split('_')[0]);
  }
}

function lsnameget(tv) {
  //alert(98);
  if (tv.trim() != '') {
  //alert(tv.split('_')[0]);
   if (('' + window.localStorage.getItem(tv.split('_')[0])).replace(/^undefined/g,'').replace(/^null/g,'') != '') {
  //alert('2:' + tv.split('_')[0]);
    lsval=decodeURIComponent(window.localStorage.getItem(tv.split('_')[0]));
  //alert('3:' + lsval);
    if (lsval.indexOf('@!@') == -1) {
     sofarmode=0;
    } else if (lsval.indexOf('@!@') != -1) {
     lsname=lsval.split('@!@')[0];
     lsvaliname=lsval.split('@!@')[1];
  //alert('lsname:' + lsname);
     if (lsvaliname.indexOf('data:') == 0) {  lsvaliname=lsvaliname.replace(/" . "\\" . " /g,'+');  }
  //alert('lsvaliname:' + lsvaliname);
     if (lsvaliname.trim() != '') { 
        if (sofarmode == 0) { sofarmode=1; } 
        if (lsname.indexOf('_') != -1 && lsname.indexOf('/') != -1) {
        //alert('onlval=' + lsname);
        if (documentURL.indexOf('?myls') != -1) {
  sofarmode=sofarmode; //alert('lsvaliname:' + lsvaliname);
        } else {
        if (lsname.indexOf('/') > lsname.indexOf('_')) {
          location.href=documentURL.split('?')[0].split('#')[0] + '?myls' + sofarmode + '=' + encodeURIComponent(tv + '_' + lsname.replace(lsname.split('_')[0] + '_', '') + sofarsoatend); 
        } else {
          location.href=documentURL.split('?')[0].split('#')[0] + '?myls' + sofarmode + '=' + encodeURIComponent(tv); 
        }
        }
        }
     }   
     
    }
   }
  }
}

function gonext() {
  document.getElementById('mytextarea').value='';
  isokay=true;
  curls++;
}

function lsnamedelete(tv) {
  window.localStorage.setItem(tv.split('_')[0], '');
}

function lsnamesaveas() {
  if (sofarso.trim() != '') {
    if (sofarso == '' && document.body.title.indexOf('asis date is ') != -1) {   sofarso=document.body.title.split('asis date is ')[1] + '_' + document.getElementById('mytzn').value + '@!@'; } 
    if (sofarsoatend != '' && ('   ' + sofarso).slice(-3) != '@!@') { sofarso+='@!@';   }
    //alert('pdftimesheet' + sofarsonext + ' will get value ' + sofarso + sofarsoatend);
    window.localStorage.setItem('pdftimesheet' + sofarsonext, encodeURIComponent(sofarso + sofarsoatend));
    sofarsonext++;
  }
}

function huhf() {
 //if (document.body.outerHTML.indexOf(datauris[0]) == -1) {
 //alert('Huh');
 //} else {
 //alert('' + document.body.outerHTML.split(datauris[0]).length + ' ... ' + datauris[0]);
 // }
 
 if (('' + document.getElementById('myform').target) == '_top') { 
   if (1 == 6) {  
     document.getElementById('relfind').style.display='block';  
     location.href='#relfind'; 
   }  
   var woo=null;
   var itop=50;
   var ileft=50;
   if (datauris.length != 1) {
   if (!window.opener) {
   for (var ijk=1; ijk<datauris.length; ijk++) {
   //alert(datauris[0] + ' ... ' + datauris[ijk] + ' . ' + document.body.outerHTML.split(datauris[0]).length);
   woos.push(window.open('./pdfimageplustext.php?ipsuff=' + encodeURIComponent('-' + ijk),'_blank','top=' + itop + ',left=' + ileft + ',width=500,height=500'));
   woos[eval(-1 + woos.length)].document.write('<html>' + document.head.outerHTML + document.body.outerHTML.replace(' data-title=\"\" value=\"', ' data-title=\"\" value=\"-' + ijk).replace(datauris[0], datauris[ijk]).replace(datauris[0], datauris[ijk]).replace(datauris[0], datauris[ijk]) + '</html>');
   itop+=10;
   ileft+=10;
   }
   }
   }
 } //else { 
   //alert(document.getElementById('myform').target); 
 //} 
 return true;
}

setTimeout(lookfordatauri, 1000);

</script>
</head>
<body style='background-image:linear-gradient(#fefefe,#fefefe,silver,#fefefe,#fefefe);" . $bip . "' id=mybody onload=\" " . $ns . " lslook();  " . $getit . "  \">
<table id=thetable><tr><td><iframe onload='iifopen(this);' id='cbi' frameborder='0' style='width:173px;height:228px;margin-top:-194px;' src='/HTMLCSS/client_browsing.htm?d=320562686'></iframe></td><td id=lstd></td></tr></table>
<p id=myp> ... or ...<hr></p>
<h1 id=myh1>Image and Text Nodes PDF Creation</h1>
<h3 id=myh3>RJM Programming - August, 2022</h3>
<input style='width:100%;' id=iurl type=url placeholder='Image Relative URLspec (hash value can define a text colour for the PDF eg. #rgb(0,0,255) and/or text rotation in degrees and/or px font size [16] and/or R or L or U or D text direction and/or Normal or Bold or Italic or Underline text style [Bold])' value='' onblur='setjust(this);'></input>
<p id=myptwo> ... or ...<hr></p>
<iframe id=relfind name=relfind src='/PHP/find_images_via_size.php?fillps=y' style='width:100%;height:900px;'></iframe>
<form onsubmit='return huhf();' id=myform method=POST action=./pdfimageplustext.php style=display:none;>
<input type=hidden id=slideshow name=justiurl value=''></input> 
<input type=hidden id=mytzn name=mytzn value='UTC'></input>
<div id=coords style=display:none;></div>
<input type=hidden name=ipsuff data-title=\"\" value=\"\"></input>
<input type=submit id=isub style=display:none; value='Ask for Text'></input>
</form>
<canvas id=mycanvas style=display:none;></canvas>
<div id=blob></div>
<div id=doverlay>
<div id=doverlay1></div>
<div id=doverlay2></div>
<div id=doverlay3></div>
<div id=doverlay4></div>
</div>
<div id=formobile style=display:none;><form target=relfind style=display:none; method=GET action='/PHP/find_images_via_size.php'><input name=fillps value=y type=hidden></input><input id=pressi style=display:none; value=Submit type=submit></input></form></div>
<iframe id=iblank name=iblank src='/' style=display:none;></iframe>
</body>
</html>";
     exit;
   }
}

$ourfname="filename" . server_remote_addr();
$dru="http://" . $_SERVER['SERVER_NAME'] . "" . str_replace("~","",str_replace(":443~","",str_replace(":80~","",(":" . $_SERVER['SERVER_PORT'] . "~")))) . "/";
$linkemailshare=$dru . $ourfname . ".pdf#Your Image and Text PDF#Via RJM Programming";
$sharehtmlbit="<br><br><iframe src='" . str_replace('http:','',str_replace("rjmprogramming.com.au/","rjmprogramming.com.au/HTMLCSS/",$dru)) . "web_share_api_test.html?suggestion=" . urlencode($linkemailshare) . "' style='width:100%;height:900px;'></iframe>";
$safarisharehtmlbit='open "' . str_replace("rjmprogramming.com.au/","rjmprogramming.com.au/HTMLCSS/",$dru) . 'web_share_api_test.html?suggestion=' . urlencode($linkemailshare) . '"';

$furl=((isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $_SERVER[HTTP_HOST] . str_replace("HTTP:","http:",$_SERVER[REQUEST_URI]));
$dpath=str_replace("$#$","//", explode("/",str_replace("//","$#$",$furl))[0] ) . "/";
$frest=explode(((isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $_SERVER[HTTP_HOST] . "/"),   ((isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $_SERVER[HTTP_HOST] . str_replace("HTTP:","http:",$_SERVER[REQUEST_URI]))   )[1];
if (strpos(($frest . '*'), '=*') === false && strpos($frest, "=") !== false) {
  $frest=explode("=", $frest)[0] . "=";
}
//echo $furl . " ... " . $dpath . " ... " . $frest;
//exit;
$sincebefore="";
$prefix="";
$notprefix="";
for ($i=0; $i<(-1 + sizeof(explode("/",$frest))); $i++) {
  $notprefix=explode($frest,$furl)[0];
  $prefix.="../";
}
if ($prefix == "") $notprefix="";
$first=true;
$outputto="";
$outputsofar="";
$outputpdf=null;
$top=1;
$title="";
$wastitle="";
$istitle="";
$cpn=1;
$emailto="";
$pdfis="";
$outputpdf_hgt=100.0;
$lh=6;
$loffset=0;
$fpdfs=",Arial,Courier,Helvetica,Symbol,Times,ZapfDingbats,";

$scale=floatval(1.0);
$scalep=floatval(100.0);

if (isset($_POST['pdfimageplustext'])) {
   if (isset($_POST['mytzn'])) {
    if (('' . urldecode($_POST['mytzn'])) != '') {
     date_default_timezone_set(urldecode($_POST['mytzn']));
    }
   }
   if (!$newd) { $newd=new DateTime();  $mewd=$newd;   $newdts=$newd->format(DateTime::COOKIE); } //date_create('');
   $w=0;
   $h=0;
   $outputpdf = new RPDF('P','pt');
   //$outputpdf->AddFont('DeJaVuSansMono','','DeJaVuSansMono.php');
   //$outputpdf->AddFont('DeJaVuSansCondensed','','DeJaVuSansCondensed.php');

   //if (isset($_POST['pdfrtext']) && isset($_POST['pdfgtext']) && isset($_POST['pdfbtext'])) {
   //$outputpdf->SetTextColor(urldecode($_POST['pdfrtext']), urldecode($_POST['pdfgtext']), urldecode($_POST['pdfbtext']));
   //}
   $outputpdf->SetTopMargin(0.0);
   //$outputpdf->AddPage('L');
   if (isset($_POST['pdfimage'])) {
    $inval=$_POST['pdfimage'];
    //if (strpos(urldecode($inval), "data:image/") === false && strpos(urldecode($inval), "data:") !== false && strpos(urldecode($inval), ";base64,") !== false) {
    //  $inval=urlencode('data:image/jpeg;base64,' . explode(";base64,", urldecode($inval)));
    //}
    if (strpos(urldecode($inval), "data:image/") !== false && strpos(urldecode($inval), ";base64,") !== false) {
    $fname='./' . $ourfname . '.' . strtolower(explode(";", explode("data:image/", urldecode($inval))[1])[0]);
    file_put_contents($fname, base64_decode(str_replace(' ','+',explode(";base64,", urldecode($inval))[1])));
    list($w, $h) = getimagesize($fname);
    if ($w > $h) {
    $outputpdf->AddPage('L', 'A4');
    if ($w > 830) {
    $scale=floatval(830.0 / $w);
    $scalep=floatval($scale * 100.0);
    //$outputpdf->_out('q');
    //Scale(floatval($scalep), floatval($scalep));
    $newh=($h * (830.0 / $w));
    $outputpdf->Image($fname, 0, 0, 830, floatval($newh)); //, 33.78);
    //$outputpdf->_out('Q');
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    } else {
    $outputpdf->AddPage('P', 'A4');
    if ($h > 830) {
    $scale=floatval(830.0 / $h);
    $scalep=floatval($scale * 100.0);
    //Scale(floatval($scalep), floatval($scalep));
    $neww=($w * (830.0 / $h));
    $outputpdf->Image($fname, 0, 0, floatval($neww), 830); //, 33.78);
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    }
    } else if (strpos(urldecode($_POST['pdfimage']), "rjmprogramming.com.au/") !== false) {
    $fname="./" . explode(')',explode('&quot;',explode("rjmprogramming.com.au/", urldecode($_POST['pdfimage']))[1])[0])[0];
    //$outputpdf->Image("./" . explode("rjmprogramming.com.au/", urldecode($_POST['pdfimage']))[1], 0, 0); //, 33.78);
    list($w, $h) = getimagesize($fname);
    if ($w > $h) {
    $outputpdf->AddPage('L', 'A4');
    if ($w > 830) {
    $scale=floatval(830.0 / $w);
    $scalep=floatval($scale * 100.0);
    //$outputpdf->_out('q');
    //Scale(floatval($scalep), floatval($scalep));
    $newh=($h * (830.0 / $w));
    $outputpdf->Image($fname, 0, 0, 830, floatval($newh)); //, 33.78);
    //$outputpdf->_out('Q');
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    } else {
    $outputpdf->AddPage('P', 'A4');
    if ($h > 830) {
    $scale=floatval(830.0 / $h);
    $scalep=floatval($scale * 100.0);
    //Scale(floatval($scalep), floatval($scalep));
    $neww=($w * (830.0 / $h));
    $outputpdf->Image($fname, 0, 0, floatval($neww), 830); //, 33.78);
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    }
    } else {
    if (strpos(urldecode($_POST['pdfimage']), 'url(') !== false) {
    $fname=str_replace('&quot;','',explode(')',explode('url(',urldecode($_POST['pdfimage']))[1])[0]);
    } else {
    $fname=urldecode($_POST['pdfimage']);
    }
    //file_put_contents('x.x', $fname);
    //$outputpdf->Image(urldecode($_POST['pdfimage']), 0, 0); //, 33.78);
    list($w, $h) = getimagesize($fname);
    if ($w > $h) {
    $outputpdf->AddPage('L', 'A4');
    if ($w > 830) {
    $scale=floatval(830.0 / $w);
    $scalep=floatval($scale * 100.0);
    //$outputpdf->_out('q');
    //Scale(floatval($scalep), floatval($scalep));
    $newh=($h * (830.0 / $w));
    $outputpdf->Image($fname, 0, 0, 830, floatval($newh)); //, 33.78);
    //$outputpdf->_out('Q');
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    } else {
    $outputpdf->AddPage('P', 'A4');
    if ($h > 830) {
    $scale=floatval(830.0 / $h);
    $scalep=floatval($scale * 100.0);
    //Scale(floatval($scalep), floatval($scalep));
    $neww=($w * (830.0 / $h));
    $outputpdf->Image($fname, 0, 0, floatval($neww), 830); //, 33.78);
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    }
    }
   } else {
    $outputpdf->AddPage('L','A4');
   }
   
   if (isset($_POST['pdftext1'])) {
   $texti=1;
   $ffy='Arial';
   $fst='B';
   $fsz=16;
   if (1 == 1) {
   ffs('');
   } else {
   if (isset($_POST['pdffamily'])) {
     $ffy=str_replace('+',' ',urldecode($_POST['pdffamily']));
   }
   if (isset($_POST['pdffontstyle'])) {
     $fst=str_replace('N',' ',substr(strtoupper(str_replace('+',' ',urldecode($_POST['pdffontstyle']))) . ' ',0,1));
   }
   if (isset($_POST['pdffontsize'])) {
     if (strlen(trim(str_replace('+',' ',urldecode($_POST['pdffontsize'])))) > 0) {
       $fsz=str_replace('+',' ',urldecode($_POST['pdffontsize']));
     }
   }
   $ofsz=$fsz;
   $ofst=$fst;
   }
   while (isset($_POST['pdftext' . $texti]) && isset($_POST['pdfx' . $texti]) && isset($_POST['pdfy' . $texti])) {
   ffs('' . $texti);
     $exc="~";
     if (strpos(urldecode($_POST['pdfx' . $texti]), '.') !== false && strpos(urldecode($_POST['pdfy' . $texti]), '.') === false) {
       $fsz=explode('.', urldecode($_POST['pdfx' . $texti]))[1];
       if (substr('' . $fsz . '   ',4) == '0000') {
         $fst='B';
         $fsz=substr($fsz,4);
         if ($fsz == '') { $fsz=$ofsz;  }
       } else if (substr('' . $fsz . '   ',3) == '000') {
         $fst='U';
         $fsz=substr($fsz,3);
         if ($fsz == '') { $fsz=$ofsz;  }
       } else if (substr('' . $fsz . '  ',2) == '00') {
         $fst='I';
         $fsz=substr($fsz,2);
         if ($fsz == '') { $fsz=$ofsz;  }
       } else if (substr('' . $fsz . ' ',1) == '0') {
         $fst=' ';
         $fsz=substr($fsz,1);
         if ($fsz == '') { $fsz=$ofsz;  }
       } 
       $exc=".";
     }
     if (strlen(trim(urldecode($_POST['pdftext' . $texti]))) > 0) {
     //echo "yesooo";
     //exit;
       $outputpdf->SetFont($ffy,trim($fst),$fsz);
       $ourx=floatval($scale * floatval(explode($exc, urldecode($_POST['pdfx' . $texti]))[0]));
       $oury=floatval($scale * floatval(urldecode($_POST['pdfy' . $texti])));
       if ($repeats == 1) {
       $stris=str_replace('^%&',' + ',str_replace('+',' ',str_replace('+++','^%&',   oururldecode($_POST['pdftext' . $texti]))));
       if ($mewd) { $newd=$mewd; } else { $newd=new DateTime();  $newdts=$newd->format(DateTime::COOKIE);  $mewd=$newd; }
       } else {
       $stris=str_replace('^%&',' + ',str_replace('+',' ',str_replace('+++','^%&',   oururldecode($_POST['pdftext' . $texti]))));
       }
   if (isset($_POST['pdfrtext' . $texti]) && isset($_POST['pdfgtext' . $texti]) && isset($_POST['pdfbtext' . $texti])) {
   $outputpdf->SetTextColor(urldecode($_POST['pdfrtext' . $texti]), urldecode($_POST['pdfgtext' . $texti]), urldecode($_POST['pdfbtext' . $texti]));
   if (isset($_POST['pdfrtext'])) { // because means "from here on"
     $_POST['pdfrtext']=$_POST['pdfrtext' . $texti];
     $_POST['pdfgtext']=$_POST['pdfgtext' . $texti];
     $_POST['pdfbtext']=$_POST['pdfbtext' . $texti];
   }
   } else if (isset($_POST['pdfrtext']) && isset($_POST['pdfgtext']) && isset($_POST['pdfbtext'])) {
   $outputpdf->SetTextColor(urldecode($_POST['pdfrtext']), urldecode($_POST['pdfgtext']), urldecode($_POST['pdfbtext']));
   }
   
   $str_is=explode("\n", $stris);
   $xfsz=0;
   $yfsz=floatval($fsz);
   for ($ii=0; $ii<sizeof($str_is); $ii++) {
       if (isset($_POST['pdfdirectiontext' . $texti])) {
    //file_put_contents('xxx.xxx',$_POST['pdfdirectiontext' . $texti]);
       if (('' . urldecode($_POST['pdfdirectiontext' . $texti])) == '') {
    //file_put_contents('xx.xxx',$_POST['pdfdirectiontext' . $texti]);
       if (1 == 8 && strpos($str_is[$ii], "\n") !== false) {
       $outputpdf->SetXY($ourx,$oury); //,''); 
       $outputpdf->Write(5, html_entity_decode($str_is[$ii]));
       } else {
       $outputpdf->Text($ourx,$oury,$str_is[$ii]); 
       }
       if (isset($_POST['pdfdirectiontext'])) {
         $_POST['pdfdirectiontext']="R"; // because means "from here on"
       } 
       } else {
    //file_put_contents('xx.xx',$_POST['pdfdirectiontext' . $texti]);
       $outputpdf->TextWithDirection($ourx,$oury,$str_is[$ii],$_POST['pdfdirectiontext' . $texti]);
       if (isset($_POST['pdfdirectiontext'])) {
         $_POST['pdfdirectiontext']=$_POST['pdfdirectiontext' . $texti]; // because means "from here on"
         if ($_POST['pdfdirectiontext' . $texti] == "U") {
           $xfsz=floatval($fsz);
           $yfsz=0;
         } else if ($_POST['pdfdirectiontext' . $texti] == "D") {
           $xfsz=-floatval($fsz);
           $yfsz=0;
         }
       } else {
         $odir=$_POST['pdfdirectiontext' . $texti];
         if ($odir == "U") {
           $xfsz=floatval($fsz);
           $yfsz=0;
         } else if ($odir == "D") {
           $xfsz=-floatval($fsz);
           $yfsz=0;
         }
       }
       }
       } else if (isset($_POST['pdfrotatetextdeg' . $texti])) {
       if (('' . urldecode($_POST['pdfrotatetextdeg' . $texti])) == '') {
       $outputpdf->Text($ourx,$oury,$str_is[$ii]); 
       if (isset($_POST['pdfrotatetextdeg'])) {
         $_POST['pdfrotatetextdeg']="0"; // because means "from here on"
       }
       } else {
       $outputpdf->TextWithRotation($ourx,$oury,$str_is[$ii],$_POST['pdfrotatetextdeg' . $texti],0); 
       if (isset($_POST['pdfrotatetextdeg'])) {
         $_POST['pdfrotatetextdeg']=$_POST['pdfrotatetextdeg' . $texti]; // bdecause means "from here on"
         $xfsz=sin(floatval($_POST['pdfrotatetextdeg' . $texti]) * pi() / 180.0) * floatval($fsz);
         $yfsz=cos(floatval($_POST['pdfrotatetextdeg' . $texti]) * pi() / 180.0) * floatval($fsz);
       } else {
         $orot=$_POST['pdfrotatetextdeg' . $texti];
         $xfsz=sin(floatval($orot) * pi() / 180.0) * floatval($fsz);
         $yfsz=cos(floatval($orot) * pi() / 180.0) * floatval($fsz);
       }
       }
       } else if ($odir != "") {
    //file_put_contents('xxxx.xx',$odir . ' for ' . $texti);
       $outputpdf->TextWithDirection($ourx,$oury,$str_is[$ii],$odir);
         if ($odir == "U") {
           $xfsz=floatval($fsz);
           $yfsz=0;
         } else if ($odir == "D") {
           $xfsz=-floatval($fsz);
           $yfsz=0;
         }
       } else if (isset($_POST['pdfdirectiontext'])) {
    //file_put_contents('xxxxx.xx',$_POST['pdfdirectiontext'] . ' For ' . $texti);
       $outputpdf->TextWithDirection($ourx,$oury,$str_is[$ii],$_POST['pdfdirectiontext']);
         if ($_POST['pdfdirectiontext'] == "U") {
           $xfsz=floatval($fsz);
           $yfsz=0;
         } else if ($_POST['pdfdirectiontext'] == "D") {
           $xfsz=-floatval($fsz);
           $yfsz=0;
         }
       } else if ($orot != "") {
       $outputpdf->TextWithRotation($ourx,$oury,$str_is[$ii],$orot,0); 
       } else if (isset($_POST['pdfrotatetextdeg'])) {
       $outputpdf->TextWithRotation($ourx,$oury,$str_is[$ii],$_POST['pdfrotatetextdeg'],0); 
       $xfsz=sin(floatval($_POST['pdfrotatetextdeg']) * pi() / 180.0) * floatval($fsz);
       $yfsz=cos(floatval($_POST['pdfrotatetextdeg']) * pi() / 180.0) * floatval($fsz);
       } else {
       if (1 == 8 && strpos($str_is[$ii], "\n") !== false) {
       $outputpdf->SetXY($ourx,$oury); //,''); 
       $outputpdf->Write($fsz, html_entity_decode($str_is[$ii]));
       } else {
       $outputpdf->Text($ourx,$oury,$str_is[$ii]); 
       }
       }    
     $ourx+=$xfsz;
     $oury+=$yfsz;
     }
     }
     $texti++;
     $fsz=$ofsz;
     $fst=$ofst;
   }
   }
   if (file_exists('./' . $ourfname . '.pdf')) {    unlink('./' . $ourfname . '.pdf');   }
   $outputpdf->Output("./" . $ourfname . ".pdf", "F");
   $result = 0;
   if (strpos($_SERVER['SERVER_NAME'], 'rjmprogramming.com.au') !== false) {
   exec( "/usr/local/cpanel/3rdparty/bin/convert -density 300 " . dirname(__FILE__) . DIRECTORY_SEPARATOR . $ourfname . ".pdf " . dirname(__FILE__) . DIRECTORY_SEPARATOR . $ourfname . ".jpg"); //, null, $result ); // Thanks to https://stackoverflow.com/questions/8624886/pdf-to-jpg-conversion-using-php
   } else {
   exec( "/usr/local/bin/convert -density 300 " . dirname(__FILE__) . DIRECTORY_SEPARATOR . $ourfname . ".pdf " . dirname(__FILE__) . DIRECTORY_SEPARATOR . $ourfname . ".jpg"); //, null, $result ); // Thanks to https://stackoverflow.com/questions/8624886/pdf-to-jpg-conversion-using-php
   }
   if (strpos( $user_agent, 'Safari') !== false && strpos( $user_agent, 'Chrome') === false && strpos( $user_agent, 'OPR') === false && strpos( $user_agent, 'Firefox') === false && strpos( $user_agent, 'Opera') === false) {
   if (1 == 1) {
   $wobit="window.open('/" . $ourfname . ".pdf','_blank');";
   echo '<html><body onclick="' . $wobit . '" title="Click for PDF and/or scroll down to Sharing section" style="background:URL(' . 'data:image/jpeg;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.jpg')) . ');background-repeat:no-repeat;background-size:contain;"><img title="Click for PDF and/or scroll down to Sharing section" style=visibility:hidden; src="' . 'data:image/jpeg;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.jpg')) . '"></img></body></html>';
   } else {
   header('Content-Type: application/pdf');
   echo file_get_contents('./' . $ourfname . '.pdf');
   exec($safarisharehtmlbit);
   }
   } else {
   echo '<html><body><div style="overflow:auto;-webkit-overflow-scrolling:touch;height:100%;"><object style="width:100%;height:900px;" type="application/pdf" data="' . 'data:application/pdf;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.pdf')) . '">' . "\n" . '<embed style="width:100%;height:900px;" type="application/pdf" src="' .'data:application/pdf;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.pdf')) . '"></embed></object></div>' . $sharehtmlbit . '</body></html>'; 
   }
   exit;
} else if (isset($_GET['pdfimageplustext'])) {
   $w=0;
   $h=0;
   $outputpdf = new RPDF('P','pt');
   //if (isset($_GET['pdfrtext']) && isset($_GET['pdfgtext']) && isset($_GET['pdfbtext'])) {
   //$outputpdf->SetTextColor(urldecode($_GET['pdfrtext']), urldecode($_GET['pdfgtext']), urldecode($_GET['pdfbtext']));
   //}
   $outputpdf->SetTopMargin(0.0);
   //$outputpdf->AddPage('L');
   if (isset($_GET['pdfimage'])) {
    if (strpos(urldecode($_GET['pdfimage']), "data:image/") !== false && strpos(urldecode($_GET['pdfimage']), ";base64,") !== false) {
    $fname='./' . $ourfname . '.' . strtolower(explode(";", explode("data:image/", urldecode($_GET['pdfimage']))[1])[0]);
    file_put_contents($fname, base64_decode(str_replace(' ','+',explode(";base64,", urldecode($_GET['pdfimage']))[1])));
    list($w, $h) = getimagesize($fname);
    if ($w > $h) {
    $outputpdf->AddPage('L', 'A4');
    if ($w > 830) {
    $scale=floatval(830.0 / $w);
    $scalep=floatval($scale * 100.0);
    //$outputpdf->_out('q');
    //Scale(floatval($scalep), floatval($scalep));
    $newh=($h * (830.0 / $w));
    $outputpdf->Image($fname, 0, 0, 830, floatval($newh)); //, 33.78);
    //$outputpdf->_out('Q');
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    } else {
    $outputpdf->AddPage('P', 'A4');
    if ($h > 830) {
    $scale=floatval(830.0 / $h);
    $scalep=floatval($scale * 100.0);
    //Scale(floatval($scalep), floatval($scalep));
    $neww=($w * (830.0 / $h));
    $outputpdf->Image($fname, 0, 0, floatval($neww), 830); //, 33.78);
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    }
    } else if (strpos(urldecode($_GET['pdfimage']), "rjmprogramming.com.au/") !== false) {
    $fname="./" . explode(')',explode('&quot;',explode("rjmprogramming.com.au/", urldecode($_GET['pdfimage']))[1])[0])[0];
    //$outputpdf->Image("./" . explode("rjmprogramming.com.au/", urldecode($_GET['pdfimage']))[1], 0, 0); //, 33.78);
    list($w, $h) = getimagesize($fname);
    if ($w > $h) {
    $outputpdf->AddPage('L', 'A4');
    if ($w > 830) {
    $scale=floatval(830.0 / $w);
    $scalep=floatval($scale * 100.0);
    //$outputpdf->_out('q');
    //Scale(floatval($scalep), floatval($scalep));
    $newh=($h * (830.0 / $w));
    $outputpdf->Image($fname, 0, 0, 830, floatval($newh)); //, 33.78);
    //$outputpdf->_out('Q');
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    } else {
    $outputpdf->AddPage('P', 'A4');
    if ($h > 830) {
    $scale=floatval(830.0 / $h);
    $scalep=floatval($scale * 100.0);
    //Scale(floatval($scalep), floatval($scalep));
    $neww=($w * (830.0 / $h));
    $outputpdf->Image($fname, 0, 0, floatval($neww), 830); //, 33.78);
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    }
    } else {
     if (strpos(urldecode($_GET['pdfimage']), 'url(') !== false) {
    $fname=str_replace('&quot;','',explode(')',explode('url(',urldecode($_GET['pdfimage']))[1])[0]);
    } else {
    $fname=urldecode($_GET['pdfimage']);
    }
    //$outputpdf->Image(urldecode($_GET['pdfimage']), 0, 0); //, 33.78);
    list($w, $h) = getimagesize($fname);
    if ($w > $h) {
    $outputpdf->AddPage('L', 'A4');
    if ($w > 830) {
    $scale=floatval(830.0 / $w);
    $scalep=floatval($scale * 100.0);
    //$outputpdf->_out('q');
    //Scale(floatval($scalep), floatval($scalep));
    $newh=($h * (830.0 / $w));
    $outputpdf->Image($fname, 0, 0, 830, floatval($newh)); //, 33.78);
    //$outputpdf->_out('Q');
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    } else {
    $outputpdf->AddPage('P', 'A4');
    if ($h > 830) {
    $scale=floatval(830.0 / $h);
    $scalep=floatval($scale * 100.0);
    //Scale(floatval($scalep), floatval($scalep));
    $neww=($w * (830.0 / $h));
    $outputpdf->Image($fname, 0, 0, floatval($neww), 830); //, 33.78);
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    }
    }
   } else {
    $outputpdf->AddPage('L','A4');
   }
   
   if (isset($_GET['pdftext1'])) {
   $texti=1;
   $ffy='Arial';
   $fst='B';
   $fsz=16;
   if (isset($_GET['pdffamily'])) {
     $ffy=str_replace('+',' ',urldecode($_GET['pdffamily']));
   }
   if (isset($_GET['pdffontstyle'])) {
     $fst=str_replace('N',' ',substr(strtoupper(str_replace('+',' ',urldecode($_GET['pdffontstyle']))) . ' ',0,1));
   }
   if (isset($_GET['pdffontsize'])) {
     if (strlen(trim(str_replace('+',' ',urldecode($_GET['pdffontsize'])))) > 0) {
       $fsz=str_replace('+',' ',urldecode($_GET['pdffontsize']));
     }
   }
   $ofsz=$fsz;
   $ofsz=$fst;
   while (isset($_GET['pdftext' . $texti]) && isset($_GET['pdfx' . $texti]) && isset($_GET['pdfy' . $texti])) {
     $exc="~";
     if (strpos(urldecode($_GET['pdfx' . $texti]), '.') !== false && strpos(urldecode($_GET['pdfy' . $texti]), '.') === false) {
       $fsz=explode('.', urldecode($_GET['pdfx' . $texti]))[1];
       if (substr('' . $fsz . '   ',4) == '0000') {
         $fst='B';
         $fsz=substr($fsz,4);
         if ($fsz == '') { $fsz=$ofsz;  }
       } else if (substr('' . $fsz . '   ',3) == '000') {
         $fst='U';
         $fsz=substr($fsz,3);
         if ($fsz == '') { $fsz=$ofsz;  }
       } else if (substr('' . $fsz . '  ',2) == '00') {
         $fst='I';
         $fsz=substr($fsz,2);
         if ($fsz == '') { $fsz=$ofsz;  }
       } else if (substr('' . $fsz . ' ',1) == '0') {
         $fst=' ';
         $fsz=substr($fsz,1);
         if ($fsz == '') { $fsz=$ofsz;  }
       } 
       $exc=".";
     }
     if (strlen(trim(urldecode($_GET['pdftext' . $texti]))) > 0) {
     //echo "yesooo";
     //exit;
       $outputpdf->SetFont($ffy,trim($fst),$fsz);
       $ourx=floatval($scale * floatval(explode($exc, urldecode($_GET['pdfx' . $texti]))[0]));
       $oury=floatval($scale * floatval(urldecode($_GET['pdfy' . $texti])));
       $stris=str_replace('^%&',' + ',str_replace('+',' ',str_replace('+++','^%&',urldecode($_GET['pdftext' . $texti]))));
   if (isset($_GET['pdfrtext' . $texti]) && isset($_GET['pdfgtext' . $texti]) && isset($_GET['pdfbtext' . $texti])) {
   $outputpdf->SetTextColor(urldecode($_GET['pdfrtext' . $texti]), urldecode($_GET['pdfgtext' . $texti]), urldecode($_GET['pdfbtext' . $texti]));
   if (isset($_GET['pdfrtext'])) { // because means "from here on"
     $_GET['pdfrtext']=$_GET['pdfrtext' . $texti];
     $_GET['pdfgtext']=$_GET['pdfgtext' . $texti];
     $_GET['pdfbtext']=$_GET['pdfbtext' . $texti];
   }
   } else if (isset($_GET['pdfrtext']) && isset($_GET['pdfgtext']) && isset($_GET['pdfbtext'])) {
   $outputpdf->SetTextColor(urldecode($_GET['pdfrtext']), urldecode($_GET['pdfgtext']), urldecode($_GET['pdfbtext']));
   }
       if (isset($_GET['pdfdirectiontext' . $texti])) {
       if (strlen($_GET['pdfdirectiontext' . $texti]) == 0) {
       $outputpdf->Text($ourx,$oury,$stris); 
       if (isset($_GET['pdfdirectiontext'])) {
         $_GET['pdfdirectiontext']="L"; // because means "from here on"
       } 
       } else {
       $outputpdf->TextWithDirection($ourx,$oury,$stris,$_GET['pdfdirectiontext' . $texti]);
       if (isset($_GET['pdfdirectiontext'])) {
         $_GET['pdfdirectiontext']=$_GET['pdfdirectiontext' . $texti]; // because means "from here on"
       }
       }
       } else if (isset($_GET['pdfrotatetextdeg' . $texti])) {
       if (strlen($_GET['pdfrotatetextdeg' . $texti]) == 0) {
       $outputpdf->Text($ourx,$oury,$stris); 
       if (isset($_GET['pdfrotatetextdeg'])) {
         $_GET['pdfrotatetextdeg']="0"; // because means "from here on"
       }
       } else {
       $outputpdf->TextWithRotation($ourx,$oury,$stris,$_GET['pdfrotatetextdeg' . $texti],0); 
       if (isset($_GET['pdfrotatetextdeg'])) {
         $_GET['pdfrotatetextdeg']=$_GET['pdfrotatetextdeg' . $texti]; // bdecause means "from here on"
       }
       }
       } else if (isset($_GET['pdfdirectiontext'])) {
       $outputpdf->TextWithDirection($ourx,$oury,$stris,$_GET['pdfdirectiontext']);
       } else if (isset($_GET['pdfrotatetextdeg'])) {
       $outputpdf->TextWithRotation($ourx,$oury,$stris,$_GET['pdfrotatetextdeg'],0); 
       } else {
       $outputpdf->Text($ourx,$oury,$stris); 
       }    
     }
     $texti++;

     $fsz=$ofsz;
     $fst=$ofst;
   }
   }
   if (file_exists('./' . $ourfname . '.pdf')) {    unlink('./' . $ourfname . '.pdf');   }
   $outputpdf->Output("./" . $ourfname . ".pdf", "F");
   $result = 0;
   if (strpos($_SERVER['SERVER_NAME'], 'rjmprogramming.com.au') !== false) {
   exec( "/usr/local/cpanel/3rdparty/bin/convert -density 300 " . dirname(__FILE__) . DIRECTORY_SEPARATOR . $ourfname . ".pdf " . dirname(__FILE__) . DIRECTORY_SEPARATOR . $ourfname . ".jpg"); //, null, $result ); // Thanks to https://stackoverflow.com/questions/8624886/pdf-to-jpg-conversion-using-php
   } else {
   exec( "/usr/local/bin/convert -density 300 " . dirname(__FILE__) . DIRECTORY_SEPARATOR . $ourfname . ".pdf " . dirname(__FILE__) . DIRECTORY_SEPARATOR . $ourfname . ".jpg"); //, null, $result ); // Thanks to https://stackoverflow.com/questions/8624886/pdf-to-jpg-conversion-using-php
   }
   if (strpos( $user_agent, 'Safari') !== false && strpos( $user_agent, 'Chrome') === false && strpos( $user_agent, 'OPR') === false && strpos( $user_agent, 'Firefox') === false && strpos( $user_agent, 'Opera') === false) {
   if (1 == 1) {
   $wobit="window.open('/" . $ourfname . ".pdf','_blank');";
   echo '<html><body onclick="' . $wobit . '" title="Click for PDF and/or scroll down to Sharing section" style="background:URL(' . 'data:image/jpeg;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.jpg')) . ');background-repeat:no-repeat;background-size:contain;"><img title="Click for PDF and/or scroll down to Sharing section" style=visibility:hidden; onclick="' . $wobit . '" src="' . 'data:image/jpeg;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.jpg')) . '"></img>' . $sharehtmlbit . '</body></html>';
   } else {
   header('Content-Type: application/pdf');
   echo file_get_contents('./' . $ourfname . '.pdf');
   exec($safarisharehtmlbit);
   }
   } else {
   echo '<html><body><div style="overflow:auto;-webkit-overflow-scrolling:touch;height:100%;"><object style="width:100%;height:900px;" type="application/pdf" data="' . 'data:application/pdf;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.pdf')) . '">' . "\n" . '<embed style="width:100%;height:900px;" type="application/pdf" src="' .'data:application/pdf;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.pdf')) . '"></embed></object></div>' . $sharehtmlbit . '</body></html>'; 
   }
   exit;
}

?>
