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


$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);

$user_agent = $_SERVER['HTTP_USER_AGENT']; 

if (isset($_POST['pdfimageplustext'])) {
   $w=0;
   $h=0;
   $outputpdf = new FPDF('P','pt');
   $outputpdf->SetTopMargin(0.0);
   //$outputpdf->AddPage('L');
   if (isset($_POST['pdfimage'])) {
    if (strpos(urldecode($_POST['pdfimage']), "data:image/") !== false && strpos(urldecode($_POST['pdfimage']), ";base64,") !== false) {
    $fname='./filename.' . strtolower(explode(";", explode("data:image/", urldecode($_POST['pdfimage']))[1])[0]);
    file_put_contents($fname, base64_encode(explode(";base64,", urldecode($_POST['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($_POST['pdfimage']), "rjmprogramming.com.au/") !== false) {
    $fname="./" . explode("rjmprogramming.com.au/", urldecode($_POST['pdfimage']))[1];
    //$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 {
    $fname=urldecode($_POST['pdfimage']);
    //$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 (isset($_POST['pdffamily'])) {
     $ffy=str_replace('+',' ',urldecode($_POST['pdffamily']));
   }
   if (isset($_POST['pdffontstyle'])) {
     $ffy=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;
   while (isset($_POST['pdftext' . $texti]) && isset($_POST['pdfx' . $texti]) && isset($_POST['pdfy' . $texti])) {
     $exc="~";
     if (strpos(urldecode($_POST['pdfx' . $texti]), '.') !== false && strpos(urldecode($_POST['pdfy' . $texti]), '.') === false) {
       $fsz=explode('.', urldecode($_POST['pdfx' . $texti]))[1];
       $exc=".";
     }
     if (strlen(trim(urldecode($_POST['pdftext' . $texti]))) > 0) {
     //echo "yesooo";
     //exit;
       $outputpdf->SetFont($ffy,$fst,$fsz);
       $ourx=floatval($scale * floatval(explode($exc, urldecode($_POST['pdfx' . $texti]))[0]));
       $oury=floatval($scale * floatval(urldecode($_POST['pdfy' . $texti])));
       $stris=str_replace('^%&',' + ',str_replace('+',' ',str_replace('+++','^%&',urldecode($_POST['pdftext' . $texti]))));
       $outputpdf->Text($ourx,$oury,$stris);     
     }
     $texti++;
     $fsz=$ofsz;
   }
   }
   if (file_exists('./filename.pdf')) {    unlink('./filename.pdf');   }
   $outputpdf->Output("./filename.pdf", "F");
   if (strpos( $user_agent, 'Safari') !== false) {
   header('Content-Type: application/pdf');
   echo file_get_contents('./filename.pdf');
   } 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('./filename.pdf')) . '">' . "\n" . '<embed style="width:100%;height:900px;" type="application/pdf" src="' .'data:application/pdf;base64,' . base64_encode(file_get_contents('./filename.pdf')) . '"></embed></object></div></body></html>'; 
   }
   exit;
} else if (isset($_GET['pdfimageplustext'])) {
   $w=0;
   $h=0;
   $outputpdf = new FPDF('P','pt');
   $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='./filename.' . strtolower(explode(";", explode("data:image/", urldecode($_GET['pdfimage']))[1])[0]);
    file_put_contents($fname, base64_encode(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("rjmprogramming.com.au/", urldecode($_GET['pdfimage']))[1];
    //$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 {
    $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'])) {
     $ffy=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;
   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];
       $exc=".";
     }
     if (strlen(trim(urldecode($_GET['pdftext' . $texti]))) > 0) {
     //echo "yesooo";
     //exit;
       $outputpdf->SetFont($ffy,$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]))));
       $outputpdf->Text($ourx,$oury,$stris);     
     }
     $texti++;
     $fsz=$ofsz;
   }
   }
   if (file_exists('./filename.pdf')) {    unlink('./filename.pdf');   }
   $outputpdf->Output("./filename.pdf", "F");
   if (strpos( $user_agent, 'Safari') !== false) {
   header('Content-Type: application/pdf');
   echo file_get_contents('./filename.pdf');
   } 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('./filename.pdf')) . '">' . "\n" . '<embed style="width:100%;height:900px;" type="application/pdf" src="' .'data:application/pdf;base64,' . base64_encode(file_get_contents('./filename.pdf')) . '"></embed></object></div></body></html>'; 
   }
   exit;
}

exit;  // stops rest

 
if (isset($_GET['emailto'])) {
  $emailto=urldecode($_GET['emailto']);
} else if (isset($_POST['emailto'])) {
  $emailto=urldecode($_POST['emailto']); 
}

// .replace(/\+\=/g,'#@!#').replace(/\+\+/g,'#@!#').replace(/ \+ /g,'#@#')

if (strpos($emailto, "@") !== false) {
if (isset($_GET['htmltp'])) {
  if (substr((urldecode($_GET['htmltp']) . " "), 0,1) == '<') {
file_put_contents("qaz.zaq"," pre inpdfinstructions");
  $pdfis=str_replace('#@#',' + ',str_replace('#@!#','++',str_replace('#@~#','+=',urldecode($_GET['htmltp']))));
  } else {
file_put_contents("qaz.zaq"," aft inpdfinstructions");
  $pdfis=retofcmds(urldecode($_GET['htmltp']));
  }
} else if (isset($_POST['htmltp'])) {
  if (substr((urldecode($_POST['htmltp']) . " "), 0,1) == '<') {
file_put_contents("qaz.zaq"," Pre inpdfinstructions");
  $pdfis=str_replace('#@#',' + ',str_replace('#@!#','++',str_replace('#@~#','+=',urldecode($_POST['htmltp'])))); 
  } else {
file_put_contents("qaz.zaq"," Aft inpdfinstructions");
  $pdfis=retofcmds(urldecode($_POST['htmltp']));
  }
}  
} else if ($emailto == " ") {
if (isset($_GET['htmltp'])) {
  $pdfis=retofcmds(urldecode($_GET['htmltp']));
} else if (isset($_POST['htmltp'])) {
  $pdfis=retofcmds(urldecode($_POST['htmltp']));
}
  $emailto="";
} else if ($emailto == "") {
if (isset($_GET['htmltp'])) {
  $pdfis=retofcmds(urldecode($_GET['htmltp']));
} else if (isset($_POST['htmltp'])) {
  $pdfis=retofcmds(urldecode($_POST['htmltp']));
}
}

$jscr="     var before=0;  
           var emailclicked=false;
           var emailtois='" . $emailto . "'; 
           var today=new Date(); 
           var yyyy = today.getFullYear();
           function ol() {
           var dprefix='0', mprefix='0', i, months=['','January','February','March','April','May','June','July','August','September','October','November','December'];
           for (i=1; i<=12; i++) {
             document.getElementById('smonthb').innerHTML+='<option value=' + mprefix + i + '>' + months[i] + '</option>';
             document.getElementById('smonths').innerHTML+='<option value=' + mprefix + i + '>' + months[i] + '</option>';
             if (i == 9) mprefix='';
           }
           for (i=1; i<=31; i++) {
             document.getElementById('sdayb').innerHTML+='<option value=' + dprefix + i + '>' + dprefix + i + '</option>';
             document.getElementById('sdays').innerHTML+='<option value=' + dprefix + i + '>' + dprefix + i + '</option>';
             if (i == 9) dprefix='';
           }
           for (i=eval('' + yyyy) + 1; i>(eval('' + yyyy) - 100); i--) {
             document.getElementById('syearb').innerHTML+='<option value=' + i + '>' + i + '</option>';
             document.getElementById('syears').innerHTML+='<option value=' + i + '>' + i + '</option>';
           } 
        }
        function dc(sois) {
           if (sois.value != '') {
           var paro=null, lastc=sois.id.slice(-1);
           if (sois.id.indexOf('year') != -1) {
             paro=document.getElementById(sois.id.replace('s','dm').replace('year','date'));
             if (paro.value == '') {
               if (document.getElementById(sois.id.replace('year' + lastc,'month' + lastc)).value == '') {
                 document.getElementById(sois.id.replace('year' + lastc,'month' + lastc)).value='01';
               }
               if (document.getElementById(sois.id.replace('year' + lastc,'day' + lastc)).value == '') {
                 document.getElementById(sois.id.replace('year' + lastc,'day' + lastc)).value='01';
               }
             }
             paro.value=sois.value + '-' + document.getElementById(sois.id.replace('year' + lastc,'month' + lastc)).value + '-' + document.getElementById(sois.id.replace('year' + lastc,'day' + lastc)).value;
           } else if (sois.id.indexOf('month') != -1) {
             paro=document.getElementById(sois.id.replace('s','dm').replace('month','date'));
             if (paro.value == '') {
               if (document.getElementById(sois.id.replace('month' + lastc,'day' + lastc)).value == '') {
                 document.getElementById(sois.id.replace('month' + lastc,'day' + lastc)).value='01';
               }
               if (document.getElementById(sois.id.replace('month' + lastc,'year' + lastc)).value == '') {
                 document.getElementById(sois.id.replace('month' + lastc,'year' + lastc)).value='' + yyyy;
               }
             }
             paro.value=document.getElementById(sois.id.replace('month' + lastc,'year' + lastc)).value + '-' + sois.value + '-' + document.getElementById(sois.id.replace('month' + lastc,'day' + lastc)).value;
           } else if (sois.id.indexOf('day') != -1) {
             paro=document.getElementById(sois.id.replace('s','dm').replace('day','date'));
             if (paro.value == '') {
               if (document.getElementById(sois.id.replace('day' + lastc,'month' + lastc)).value == '') {
                 document.getElementById(sois.id.replace('day' + lastc,'month' + lastc)).value='01';
               }
               if (document.getElementById(sois.id.replace('day' + lastc,'year' + lastc)).value == '') {
                 document.getElementById(sois.id.replace('day' + lastc,'year' + lastc)).value='' + yyyy;
               }
             }
             paro.value=document.getElementById(sois.id.replace('day' + lastc,'year' + lastc)).value + '-' + document.getElementById(sois.id.replace('day' + lastc,'month' + lastc)).value + '-' + sois.value;
           }
           }
        }
        function checkthings() {
           if (document.getElementById('dpath').value.toLowerCase().indexOf('rjmprogramming.com.au') != -1 && (document.getElementById('dfilespec').value + '~').indexOf('GETME~') == -1) {
             alert('Sorry, no can do.');
             return false;
           }
           if (emailclicked) {
               if (emailtois == '' || document.getElementById('emailto').value.indexOf('@') != -1) {
               emailtois=document.getElementById('emailto').value;
               }
               var pem=prompt('Please enter email address to email report to (and consider adding a comma separated mention of your own email address for Reply To All purposes)', emailtois);
               if (pem == null) return false;
               if (pem.indexOf('@') != -1) {
                 document.getElementById('emailto').value=pem;
               } else {
                 return false;
               }
           }
           return true;
        }
        function beff() {
          before=0;
          setTimeout(beff,1000);
        }
        setTimeout(beff,1000);
        window.onload=ol;
        ";

function ucurldecode($qtd) {
  return str_replace("HTTP:","http:",str_replace("HTTPS:","https:",urldecode($qtd)));
}
   
function fontsel($sug) {
  global $fpdfs;
  if (strpos($fpdfs, "," . $sug . ",") !== false) return $sug;
  return 'Arial';
}     

function Scale($s_x, $s_y, $x='', $y='') {  // thanks to http://www.fpdf.org/en/script/script79.php
        global $outputto;
        if($x === '')
            $x=$outputto->x;
        if($y === '')
            $y=$outputto->y;
        if($s_x == 0 || $s_y == 0)
            $outputto->Error('Please use values unequal to zero for Scaling');
        $y=($outputto->h-$y)*$outputto->k;
        $x*=$outputto->k;
        //calculate elements of transformation matrix
        $s_x/=100;
        $s_y/=100;
        $tm[0]=$s_x;
        $tm[1]=0;
        $tm[2]=0;
        $tm[3]=$s_y;
        $tm[4]=$x*(1-$s_x);
        $tm[5]=$y*(1-$s_y);
        //scale the coordinate system
        $outputto->Transform($tm);
}
        
function retofcmds($inpdfinstructions) {
  global $outputto, $outputsofar, $outputpdf_hgt, $outputpdf, $top, $cpn, $emailto, $title, $istitle, $wastitle, $pdfis, $lh;
file_put_contents("qaz.zaq", $inpdfinstructions);
  if (substr(($inpdfinstructions . "     "),0,5) == "New``" && strpos($emailto, "@") === false) {
    $outputto="pdfdownload";
    $title="Textarea Pointing Webpage as PDF Download";
    $istitle=$title;
    $wastitle="tareap";
file_put_contents("qaz.zaq", $outputto . " ... " . $inpdfinstructions);
  } else if (substr(($inpdfinstructions . "     "),0,5) == "New``" && strpos($emailto, "@") !== false) {
    $title="Textarea Pointing Webpage as PDF Attachment in Email";
    $istitle=$title;
    $wastitle="tareap";
    $outputto="pdfdownloademail";
file_put_contents("qaz.zaq", $outputto . " ... " . $inpdfinstructions);
  } else if (substr(($inpdfinstructions . "     "),0,5) == "new``") {
    $title="Textarea Pointing Webpage as PDF Viewed in Default PDF Reader";
    $istitle=$title;
    $wastitle="tareap";
    $outputto="pdf";
file_put_contents("qaz.zaq", $outputto . " ... " . $inpdfinstructions);
  }
  if ($outputto != "") {
file_put_contents("qaz.zaq", $outputto . " .=. " . $inpdfinstructions);
    $lh=6; //20;
    $outputpdf = new FPDF();
    $outputpdf->SetTopMargin(0.0);
    $outputpdf->AddPage('L');
    $image1 = "./xcodefibonacci.jpg";
    $outputpdf->Image($image1, 0, 0); //, 33.78);
if (1 == 2) {
    $outputpdf->SetY(-1);
    $outputpdf_hgt=$outputpdf->GetY();
    $outputpdf_hgt++;
    $outputpdf->SetY(0);
    //$outputpdf_hgt=300; //$outputpdf->h;
    $outputpdf->AliasNbPages();
    $outputpdf->SetAutoPageBreak(true, 1.0); 
    $outputpdf->SetTitle($title);
    $cmdlist=explode("``", $inpdfinstructions);
    for ($ilist=1; $ilist<sizeof($cmdlist); $ilist++) {
        if (strpos($cmdlist[$ilist], "~`") !== false) {
          $lh=intval(intval(str_replace("px","",explode("~`", $cmdlist[$ilist])[2])) / 2);
file_put_contents("qaz.zaq", $outputto . "x .-. " . intval(str_replace("px","",explode("~`", $cmdlist[$ilist])[2])));
          $outputpdf->SetFont(fontsel(('' . explode("~`", $cmdlist[$ilist])[0])), ('' . explode("~`", $cmdlist[$ilist])[1]), intval(str_replace("px","",explode("~`", $cmdlist[$ilist])[2])));
file_put_contents("qaz.zaq", $outputto . "x -.- " . explode("~`", $cmdlist[$ilist])[0]);
        } else if (strpos($cmdlist[$ilist], "`~") !== false) {
          $linerecs=explode("\n",explode("`~", $cmdlist[$ilist])[2]);
          $ourx=explode("`~", $cmdlist[$ilist])[0];
          $oury=explode("`~", $cmdlist[$ilist])[1];
          $oury+=$lh;
          for ($j=0; $j<sizeof($linerecs); $j++) {
if (trim($linerecs[$j]) != "") file_put_contents("qaz.zaq", $outputto . " .*" . $j . ". " . floatval($ourx) . ',' . $oury . ',' . $linerecs[$j]);
           if (trim($linerecs[$j]) != "") {
             //$outputpdf->SetXY(floatval($ourx),floatval($oury)); 
             //$outputpdf->SetY(floatval($oury)); 
             $outputpdf->Text(floatval($ourx),nqt(floatval($oury)),$linerecs[$j]); 
           }
if (trim($linerecs[$j]) != "") file_put_contents("qaz.zaq", $outputto . " *." . $j . "* " . floatval($ourx) . ',' . $oury . ',' . $linerecs[$j]);
           //if ($j < (-1 + sizeof($linerecs))) $outputpdf->Ln(1);
           $oury+=$lh;
          }
        } else if (strpos($cmdlist[$ilist], "~~") !== false) {
file_put_contents("qaz.zaq", $outputto . " .^. " . explode("~~", $cmdlist[$ilist])[0]);
          $outputpdf->SetTextColor(intval(explode("~~", $cmdlist[$ilist])[0]), intval(explode("~~", $cmdlist[$ilist])[1]), intval(explode("~~", $cmdlist[$ilist])[2]));
file_put_contents("qaz.zaq", $outputto . " ^.^ " . explode("~~", $cmdlist[$ilist])[0]);
        }
    }
  }
  }
  if ($outputto == "pdf") {
    $outputpdf->Output();
    return "";
  }
file_put_contents("qaz.zaq", "here at PDF " . file_get_contents("qaz.zaq"));
  $pdfis=$outputpdf->Output("filename.pdf", "S");
  return $pdfis;
}

function nqt($ptop) {
  global $outputto, $outputsofar, $outputpdf, $top, $cpn, $outputpdf_hgt, $lh, $loffset;
  $cp=$cpn;
  if ((floatval($cpn) * $outputpdf_hgt) < floatval($ptop)) {
   while ((floatval($cpn) * $outputpdf_hgt) < floatval($ptop)) {
     $outputpdf->AddPage('L');
     $cpn=$outputpdf->PageNo();
   }
file_put_contents("qaz.zaq", ' was page number ' . $cp . ' for ' . $ptop . ' vs ' . $outputpdf_hgt . ' becomes ' . $lh . ' on page number ' . $cpn);
   $loffset=floatval($ptop) - floatval($lh);
   $top=$lh;
   $ptop=$lh;
  } else if ($loffset != 0) {
file_put_contents("qaz.zaq", '' . floatval($ptop) - floatval($loffset));
   return floatval($ptop) - floatval($loffset);
  }
  return floatval($ptop);
}
        
function qt($ptop) {
  global $outputto, $outputsofar, $outputpdf, $top, $cpn;
  if ($outputpdf->PageNo() != $cpn) {
    $top=1;
    $cpn=$outputpdf->PageNo();
  }
  return $top;
}
        
function ourhtmltopdf($hwhat) {
  global $outputto, $outputsofar, $outputpdf, $top, $istitle, $wastitle, $emailto, $pdfis;
  $textareapointing=false;
  if ($pdfis != "") $textareapointing=true;
  if (strpos($hwhat, ">") !== false) {
    if (strpos($hwhat, "<body") !== false) {
      $hwhat=str_replace("><h1", "<h1", explode("<body", $hwhat)[1]);
    }
    //$outputpdf->AddPage();
    //$outputpdf->SetFont('Arial','B',16);
    
$outputpdf = new FPDF(); // rubbish line

    
    
    $candidates=explode(">",$hwhat);
    for ($ii=1; $ii<sizeof($candidates); $ii++) {
    if (explode("<",$candidates[$ii])[0] != "") {
if (2 == 6) {
    if (1 == 11) {
    $outputpdf->Text(40,qt($top),explode("<",$candidates[$ii])[0]);
    } else {
    $outputpdf->Cell(40,qt($top),explode("<",$candidates[$ii])[0]);
    }
    $top+=(1 * sizeof(explode("\n", explode("<",$candidates[$ii])[0]))); 
    $outputsofar.=explode("<",$candidates[$ii])[0];
}
    } else if (strpos($candidates[-1 + $ii], "<iframe ") !== false && strpos($candidates[-1 + $ii], " src='") !== false) {
    if ("huxh.huxh" != str_replace(".htm","",explode("?",explode("'",explode(" src='", $candidates[-1 + $ii])[-1 + sizeof(explode(" src='", $candidates[-1 + $ii]))])[0])[0])) {

    $outputpdf->SetTopMargin(0.0);
    $outputpdf->AddPage('L');
    $image1 = "./xcodefibonacci.jpg";
    $outputpdf->Image($image1, 0, 0); //, 33.78);
    $outputpdf->SetFont('Arial','B',6);
    $outputpdf->SetFillColor(200,200,200);
    $outputpdf->SetTextColor(128);
    $outputpdf->Cell(40,"one",""); //,0,1,"L",true);
if (1 == 7) {

    $outputpdf->SetFont('Arial','B',6);
    $outputpdf->SetFillColor(200,200,200);
    $outputpdf->SetTextColor(128);
    $outputpdf->Cell(40,qt($top),""); //,0,1,"L",true);
    $outputpdf->Ln(3);
    $top+=1;
    $cont=file_get_contents(str_replace(".htm","",explode("?",explode("'",explode(" src='", $candidates[-1 + $ii])[-1 + sizeof(explode(" src='", $candidates[-1 + $ii]))])[0])[0]));
    if (strpos(("*" . $cont), "*<pre") !== false) {
      $cont=str_replace("<br>","\n",str_replace("&gt;",">",str_replace("&lt;","<",str_replace("</pre>","",str_replace("<pre>","",$cont)))));
  //echo $cont;
    } else {
      $cont=str_replace("<br>","\n", $cont);
    }
    if (sizeof(explode("\n", $cont)) > 1) {
    for ($jj=0; $jj<sizeof(explode("\n", $cont)); $jj++) {
    if (explode("\n", $cont)[$jj] != "") {
    if (1 == 11) {
    $outputpdf->Text(40,qt($top),explode("\n", $cont)[$jj]); //,0,1,"L",true);
    } else {
    $outputpdf->Cell(40,qt($top),explode("\n", $cont)[$jj]); //,0,1,"L",true);
    }
    $outputpdf->Ln(3);
    $top+=1;
    }
    }
    } else {
    if (1 == 11) {
    $outputpdf->Text(40,qt($top),$cont);
    } else {
    $outputpdf->Cell(40,qt($top),$cont);
    }
    $outputpdf->Ln(3);
    $top+=(1 * sizeof(explode("\n", $cont))); 
    }    
    $outputsofar.=str_replace("<br>","\n",$cont);
    $outputpdf->SetFont('Arial','B',8);
    $outputpdf->SetFillColor(255,255,255);
    $outputpdf->SetTextColor(0);
    }
}
    } else if (strpos($candidates[-1 + $ii], "<iframe ") !== false && strpos($candidates[-1 + $ii], ' src="') !== false) {
    if ("huxh.huxh" != str_replace(".htm","",explode("?",explode('"',explode(' src="', $candidates[-1 + $ii])[-1 + sizeof(explode(' src="', $candidates[-1 + $ii]))])[0])[0])) {

    $outputpdf->SetTopMargin(0.0);
    $outputpdf->AddPage('L');
    $image1 = "./xcodefibonacci.jpg";
    $outputpdf->Image($image1, 0, 0); //, 33.78);
if (1 == 7) {

    $outputpdf->SetFont('Arial','B',6);
    $outputpdf->SetFillColor(200,200,200);
    $outputpdf->SetTextColor(128);
    $outputpdf->Cell(40,qt($top),""); //,0,1,"L",true);
    $outputpdf->Ln(3);
    $top+=1;
    $cont=file_get_contents(str_replace(".htm","",explode("?",explode('"',explode(' src="', $candidates[-1 + $ii])[-1 + sizeof(explode(' src="', $candidates[-1 + $ii]))])[0])[0]));
    if (strpos(("*" . $cont), "*<pre") !== false) {
      $cont=str_replace("<br>","\n",str_replace("&gt;",">",str_replace("&lt;","<",str_replace("</pre>","",str_replace("<pre>","",$cont)))));
  //echo $cont;
    } else {
      $cont=str_replace("<br>","\n", $cont);
    }
    if (sizeof(explode("\n", $cont)) > 1) {
    for ($jj=0; $jj<sizeof(explode("\n", $cont)); $jj++) {
    if (explode("\n", $cont)[$jj] != "") {
    if (1 == 11) {
    $outputpdf->Text(40,qt($top),explode("\n", $cont)[$jj]); //,0,1,"L",true);
    } else {
    $outputpdf->Cell(40,qt($top),explode("\n", $cont)[$jj]); //,0,1,"L",true);
    }
    $outputpdf->Ln(3);
    $top+=1;
    }
}
    } else {
if (6 == 9) {
    if (1 == 11) {
    $outputpdf->Text(40,qt($top),$cont);
    } else {
    $outputpdf->Cell(40,qt($top),$cont);
    }
    $outputpdf->Ln(3);
    $top+=(1 * sizeof(explode("\n", $cont))); 
    }
    $outputsofar.=str_replace("<br>","\n",$cont);
}
    $outputpdf->SetFont('Arial','B',8);
    $outputpdf->SetFillColor(255,255,255);
    $outputpdf->SetTextColor(0);
    }
    }
}
    }
    if (strpos($hwhat, "</html>") !== false) {
      if (strpos($outputto, "ownload") !== false && 1 == 2) {
        header('Content-type: application/pdf'); 
        header('Content-Disposition: attachment; filename="filename.pdf"');
      }
      if (strpos($outputto, "ownload") !== false) {
        //ob_start();
        //$outputpdf->Close();
        if ($pdfis == "") {
        $pdfis=$outputpdf->Output("filename.pdf", "S"); //, "FILENAME.PDF");
        } //else {
        //file_put_contents("zaq.qaz",$emailto);
        //}
        //echo strlen($pdfis);
        //exit;
        //ob_end_flush();
        
        if (strpos($outputto, "email") !== false) { // thanks to https://stackoverflow.com/questions/4353271/email-pdf-attachment-with-php-using-fpdf/8900290
        
        
// email stuff (change data below)
$to = $emailto; 
$from = "rmetcalfe@rjmprogramming.com.au"; 
$subject = $istitle; 
$message = "Please see the attachment.";

//echo $emailto . " ";

// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;

// attachment name
if (substr($pdfis,0,1) == "<") {
//$message=$pdfis;
$filename = str_replace(" ","",$wastitle) . ".html";
        //file_put_contents("zaq.qaz",$emailto . ' ' . str_replace(" ","",$wastitle));
$filename = "tareap.html";
$message = "Please download the attachment to open the webpage using Textarea Pointing techniques.";
} else {
$filename = $wastitle . ".pdf";
$message = "Please download the PDF attachment to open the webpage using Textarea Pointing techniques.";
}

//echo $filename . " ";


// encode data (puts attachment in proper format)
//$pdfdoc = $pdfis; //file_get_contents("S");
$attachment = chunk_split(base64_encode($pdfis));
$pdfis="";


// main header
$headers  = "From: ".$from.$eol;
//$headers .= 'Reply-To: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";

// no more headers after this, we start the body! //

$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;

// message
$body .= "--".$separator.$eol;
if (substr($message,0,1) == '<') {
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
} else {
$body .= "Content-Type: text/plain; charset=\"iso-8859-1\"".$eol;
}
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol.$eol;

// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment;filename=\"" . $filename . "\"" . $eol;
$body .= $attachment.$eol.$eol;
$body .= "--".$separator."--";


//echo $subject . " ";

// send message
$mret=mail($to, $subject, $body, $headers);
        //file_put_contents("zaq.qaz",$emailto . ' ' . str_replace(" ","",$wastitle) . ' ... ' . $mret);

if ($textareapointing) {
 exit;
} 
exit;
//header("Location: ./prediff.php");
  } else {
        
        
        header('Content-type: application/pdf'); 
        header('Content-Disposition: attachment; filename="' . $wastitle . '.pdf"');
        echo $pdfis; //file_get_contents("S");
        exit;
}
        //echo $pdfis;
        //exit;
      } else {
        $outputpdf->Output();
      }
    }
  }
}
        
function ourpassthru($hwhat) {
  global $outputto, $outputsofar, $outputpdf, $top, $title;
  if ($outputto == "") {
    passthru($hwhat);
  } else if (strpos(strtolower($outputto), "pdf") !== false && sizeof(explode("cho '",$hwhat)) > 1) {
    if (strpos($hwhat, "curl ") !== false) {
    $top=1;
    $outputpdf->AddPage();
    $outputpdf->SetFont('Arial','B',8);
    if ($title != "") {
      $top+=2;
    if (1 == 11) {
      $outputpdf->Text(40,qt($top),$title); //,0,1,"L",true);
    } else {
      $outputpdf->Cell(40,qt($top),$title); //,0,1,"L",true);
    }
      $outputpdf->Ln(5);
      $top+=2;
      $title="";
    }
    }
    $outputsofar.=explode("'",explode("cho '",$hwhat)[1])[0];
    $outputpdf->AddLink();
    if (1 == 11) {
    $outputpdf->Text(40,qt($top),explode("'",explode("cho '",$hwhat)[1])[0]); //,0,0,"L",true);
    } else {
    $outputpdf->Cell(40,qt($top),explode("'",explode("cho '",$hwhat)[1])[0]); //,0,0,"L",true);
    }
    $outputpdf->Ln(3);
    $top+=1;
  } else if (strpos(strtolower($outputto), "pdf") !== false) {
    $stuff = shell_exec($hwhat);
    $outputsofar.=$stuff;
    if (strpos($stuff, "<") !== false) {
    ourhtmltopdf($stuff);
    } else {
    ourhtmltopdf("<pre>" . $stuff . "</pre>");
    }
  }
}
        
function ourecho($what) {
  global $outputto, $outputsofar, $outputpdf, $top, $title;
  if ($outputto == "") {
    echo $what;
  } else if (strpos(strtolower($outputto), "pdf") !== false) {
    if (!$outputpdf) {
  //echo str_replace("<","&lt;",str_replace(">","&gt;",$what));
  //exit;
      if (strpos($outputto, "ownload") !== false && 1 == 4) {
        header('Content-type: application/pdf'); 
        header('Content-Disposition: attachment; filename="filename.pdf"');
      }
      $outputpdf = new FPDF();
      $outputpdf->AliasNbPages();
      $outputpdf->SetAutoPageBreak(true, 1.0); 
      $outputpdf->SetTopMargin(1.0);
      $outputpdf->SetTitle($title);
      
      //echo $title;
      //exit;
      
    }
    ourhtmltopdf($what);
  }
}
 
if (isset($_GET['pdf'])) {
  $outputto="pdf";
} else if (isset($_POST['pdf'])) {
  $outputto="pdf"; 
} else if (isset($_POST['pdfdownload'])) {
  $outputto="pdfdownload"; 
} else if (isset($_POST['pdfdownload'])) {
  $outputto="pdfdownload"; 
} else if (isset($_POST['pdfdownloademail'])) {
  $outputto="pdfdownloademail"; 
} else if (isset($_POST['pdfdownloademail'])) {
  $outputto="pdfdownloademail"; 
} else if ($pdfis != "") {
  if ($outputto == "") $outputto="pdfdownloademail"; 
  if ($title == "") {
  $title="Textarea Pointing Webpage";
  $istitle=$title;
  $wastitle=$istitle;
  }
  ourhtmltopdf("</html>");
  exit;
}

if (isset($_GET['dpath']) && isset($_GET['dfilespec'])) {
 $filespecmdates="";
 if (isset($_GET['dmdates'])) {
   $filespecmdates=urldecode($_GET['dmdates']);
   if ($filespecmdates != "") $sincebefore.=" since " . $filespecmdates;
 }
 $filespecmdateb="";
 if (isset($_GET['dmdateb'])) {
   $filespecmdateb=urldecode($_GET['dmdateb']);
   if ($filespecmdateb != "") $sincebefore.=" before " . $filespecmdateb;
 }
 $filespec=urldecode($_GET['dfilespec']);
 if (($filespecmdates == "" && $filespecmdateb == "") || 1 == 1) {
 echo "prefix=" . $prefix . " filespec=" . $filespec;
 exit;
 foreach (glob($prefix . $filespec) as $filename) {
   $ok=true;
   $thisd=date ("Y-m-d", filemtime($filename));
   if ($filespecmdates != "" && $thisd < $filespecmdates) $ok=false;
   if ($filespecmdateb != "" && $thisd > $filespecmdateb) $ok=false;
   if ($ok) {
     if ($first) {
        //header('Content-type: application/pdf'); 
        //header('Content-Disposition: attachment; filename="filename.pdf"');
        $title="Difference Reporting for Files regarding " . ucurldecode($_GET['dpath']) . urldecode($_GET['dfilespec']) . $sincebefore;
        $istitle=$title;
        $wastitle=str_replace("?","-",str_replace("%","-",str_replace("*","-",str_replace(".","_",str_replace("/","_",str_replace(":","-",str_replace(" ","",$title)))))));
        ourecho("<!doctype html><html><head><title>Difference Reporting for Files regarding " . ucurldecode($_GET['dpath']) . urldecode($_GET['dfilespec']) . $sincebefore . " - RJM Programming - December, 2017</title><scr" . "ipt type='text/javascript'>" . $jscr . "</scr" . "ipt></head><body style='width:100%;word-wrap:break-word;'><h1 id=top>Differences Report for Files regarding " . ucurldecode($_GET['dpath']) . urldecode($_GET['dfilespec']) . $sincebefore . "<h1><h3>RJM Programming - December, 2017 ... <a href=#myform title='Another run'>Another report run</a></h3><hr><br><div style='background-color:#f0f0f0;' id=topdiv title='Click for end of report and form for next query' onclick=\" before++; if (before <= 1) {   location.href='#myform'; } before=0; \">");
        $first=false;
     }
     ourpassthru("echo '<details onclick=\" before++;\" open><summary>'");
     ourpassthru("echo 'curl " . str_replace("Https:","http:",str_replace("HTTPS:","http:",str_replace("https:","http:",str_replace("pdfimageplustext","PHP/Geographicals/diff",explode("?",$furl)[0])))) . "?one=" . str_replace($prefix, $notprefix, $filename) . " #" . $thisd . "'");
     ourpassthru("echo '</summary>'");
     if (strpos($filename . "~", "_GETME~") !== false) {
     ourpassthru("echo '<br>'");
     ourpassthru("echo 'No differences found.'");
     ourpassthru("echo '<br>'");
     ourpassthru("echo '</details>'");
     } else {
     sleep(2);
     //ourpassthru("echo '<details onclick=\" before++;\" open><summary></summary>'");
     ourpassthru("curl " . str_replace("Https:","http:",str_replace("HTTPS:","http:",str_replace("https:","http:",str_replace("pdfimageplustext","PHP/Geographicals/diff",explode("?",$furl)[0])))) . "?one=" . str_replace($prefix, $notprefix, $filename) . " | tr \"\\n\" \"\<br\>\"");
     ourpassthru("echo '</details>'");
     }
     //echo $filename . " " . date ("Y-m-d", filemtime($filename));
   }
 }
 if (!$first) {
 ourecho("</div><hr><br><a onclick=\"before=2;\" href='#top' title='Back to top of report'>Top</a><br><br><form style='padding: 5px 5px 5px 5px;border:3px solid green;' id=myform onsubmit='return checkthings();' action=./pdfimageplustext.php method=POST>
 Set Path and Variable Filespec: <input readonly style=display:inline-flex;width:220px; type=text id=dpath name=dpath value=" . $dpath . "></input><input type=text id=dfilespec name=dfilespec value='PHP/*/*.*GETME'></input><br><br>
 Modified Date Since (optional): <input type=hidden name=dmdates id=dmdates value=''></input><select style=display:inline-flex; onchange=dc(this); id=syears><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=smonths><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=sdays><option value=''>N/A vs ...</option></select><br><br>
 Modified Date Before (optional): <input type=hidden name=dmdateb id=dmdateb value=''></input><select style=display:inline-flex; onchange=dc(this); id=syearb><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=smonthb><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=sdayb><option value=''>N/A vs ...</option></select><br><br>
<input type=hidden name=emailto id=emailto value='" . $emailto . "'></input><input style='background-color:pink;border:2px solid red;' type=submit value=Show></input>&nbsp;<input style='background-color:pink;border:2px solid red;' type=submit name=pdf value='Show as PDF'></input>&nbsp;<input style='background-color:pink;border:2px solid red;' type=submit name=pdfdownload value='Show as Downloadable PDF'></input>&nbsp;<input onclick='emailclicked=true;' style='background-color:pink;border:2px solid red;' type=submit name=pdfdownloademail value='Email PDF'></input>
 </form>
 </body></html>");
 } else {
 ourecho("<!doctype html><html><head><title>Difference Reporting - RJM Programming - December, 2017</title><scr" . "ipt type='text/javascript'> " . $jscr . "</scr" . "ipt></head><body style='width:100%;word-wrap:break-word;'><p>No files found for report regarding " . ucurldecode($_GET['dpath']) . urldecode($_GET['dfilespec']) . $sincebefore . "</p><br><h1>Differences Report for Files Changed Lately<h1><h3>RJM Programming - December, 2017</h3><br>
 <form style='padding: 5px 5px 5px 5px;border:3px solid green;' id=myform onsubmit='return checkthings();' action=./pdfimageplustext.php method=POST>
 Set Path and Variable Filespec: <input readonly style=display:inline-flex;width:220px; type=text id=dpath name=dpath value=" . $dpath . "></input><input type=text id=dfilespec name=dfilespec value='PHP/*/*.*GETME'></input><br><br>
 Modified Date Since (optional): <input type=hidden name=dmdates id=dmdates value=''></input><select style=display:inline-flex; onchange=dc(this); id=syears><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=smonths><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=sdays><option value=''>N/A vs ...</option></select><br><br>
 Modified Date Before (optional): <input type=hidden name=dmdateb id=dmdateb value=''></input><select style=display:inline-flex; onchange=dc(this); id=syearb><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=smonthb><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=sdayb><option value=''>N/A vs ...</option></select><br><br>
<input type=hidden name=emailto id=emailto value='" . $emailto . "'></input><input style='background-color:pink;border:2px solid red;' type=submit value=Show></input>&nbsp;<input style='background-color:pink;border:2px solid red;' type=submit name=pdf value='Show as PDF'></input>&nbsp;<input style='background-color:pink;border:2px solid red;' type=submit name=pdfdownload value='Show as Downloadable PDF'></input>&nbsp;<input onclick='emailclicked=true;' style='background-color:pink;border:2px solid red;' type=submit name=pdfdownloademail value='Email PDF'></input>
 </form>
 </body></html>");
 }
 } else {
 ourecho("*" . $filespecmdates . "*" . $filespecmdateb);
 exit;
 }
} else if (isset($_POST['dpath']) && isset($_POST['dfilespec'])) {
 $filespecmdates="";
 if (isset($_POST['dmdates'])) {
   $filespecmdates=urldecode($_POST['dmdates']);
   if ($filespecmdates != "") $sincebefore.=" since " . $filespecmdates;
 }
 $filespecmdateb="";
 if (isset($_POST['dmdateb'])) {
   $filespecmdateb=urldecode($_POST['dmdateb']);
   if ($filespecmdateb != "") $sincebefore.=" before " . $filespecmdateb;
 }
 $filespec=urldecode($_POST['dfilespec']);
 if (($filespecmdates == "" && $filespecmdateb == "") || 1 == 1) {
 foreach (glob($prefix . $filespec) as $filename) {
   $ok=true;
   $thisd=date ("Y-m-d", filemtime($filename));
   if ($filespecmdates != "" && $thisd < $filespecmdates) $ok=false;
   if ($filespecmdateb != "" && $thisd > $filespecmdateb) $ok=false;
   if ($ok) {
     if ($first) {
        //header('Content-type: application/pdf'); 
        //header('Content-Disposition: attachment; filename="filename.pdf"');
        $title="Difference Reporting for Files regarding " . ucurldecode($_POST['dpath']) . urldecode($_POST['dfilespec']) . $sincebefore;
        $istitle=$title;
        $wastitle=str_replace("?","-",str_replace("%","-",str_replace("*","-",str_replace(".","_",str_replace("/","_",str_replace(":","-",str_replace(" ","",$title)))))));
        //echo str_replace("<","&lt;",str_replace(">","&gt;","here with " . "<!doctype html><html><head><title>Difference Reporting for Files regarding " . ucurldecode($_POST['dpath']) . urldecode($_POST['dfilespec']) . $sincebefore . " - RJM Programming - December, 2017</title><scr" . "ipt type='text/javascript'> " . $jscr . "</scr" . "ipt></head><body style='width:100%;word-wrap:break-word;'><h1 id=top>Differences Report for Files " . ucurldecode($_POST['dpath']) . urldecode($_POST['dfilespec']) . $sincebefore . "<h1><h3>RJM Programming - December, 2017 ... <a href=#myform title='Another run'>Another report run</a></h3><hr><br><div style='background-color:#f0f0f0;' id=topdiv title='Click for end of report and form for next query' onclick=\" location.href='#myform'; \">"));
        //exit;
        ourecho("<!doctype html><html><head><title>Difference Reporting for Files regarding " . ucurldecode($_POST['dpath']) . urldecode($_POST['dfilespec']) . $sincebefore . " - RJM Programming - December, 2017</title><scr" . "ipt type='text/javascript'> " . $jscr . "</scr" . "ipt></head><body style='width:100%;word-wrap:break-word;'><h1 id=top>Differences Report for Files " . ucurldecode($_POST['dpath']) . urldecode($_POST['dfilespec']) . $sincebefore . "<h1><h3>RJM Programming - December, 2017 ... <a href=#myform title='Another run'>Another report run</a></h3><hr><br><div style='background-color:#f0f0f0;' id=topdiv title='Click for end of report and form for next query' onclick=\"  before++; if (before <= 1) {  location.href='#myform'; } before=0;  \">");
        $first=false;
     }
     ourpassthru("echo '<details onclick=\" before++;\" open><summary>'");
     ourpassthru("echo 'curl " . str_replace("Https:","http:",str_replace("HTTPS:","http:",str_replace("https:","http:",str_replace("pdfimageplustext","PHP/Geographicals/diff",explode("?",$furl)[0])))) . "?one=" . str_replace($prefix, $notprefix, $filename) . " #" . $thisd . "'");
     ourpassthru("echo '</summary>'");
     if (strpos($filename . "~", "_GETME~") !== false) {
     ourpassthru("echo '<br>'");
     ourpassthru("echo 'No differences found.'");
     ourpassthru("echo '<br>'");
     ourpassthru("echo '</details>'");
     } else {
     sleep(2);
     //ourpassthru("echo '<details onclick=\" before++;\" open><summary></summary>'");
     ourpassthru("curl " . str_replace("Https:","http:",str_replace("HTTPS:","http:",str_replace("https:","http:",str_replace("pdfimageplustext","PHP/Geographicals/diff",explode("?",$furl)[0])))) . "?one=" . str_replace($prefix, $notprefix, $filename) . " | tr \"\\n\" \"\<br\>\"");
     ourpassthru("echo '</details>'");
     }
   }
 }
 if (!$first) {
 ourecho("</div><hr><br><a onclick=\"before=2;\" href='#top' title='Back to top of report'>Top</a><br><br><form style='padding: 5px 5px 5px 5px;border:3px solid green;' id=myform onsubmit='return checkthings();' action=./pdfimageplustext.php method=POST>
 Set Path and Variable Filespec: <input readonly style=display:inline-flex;width:220px; type=text id=dpath name=dpath value=" . $dpath . "></input><input type=text id=dfilespec name=dfilespec value='PHP/*/*.*GETME'></input><br><br>
 Modified Date Since (optional): <input type=hidden name=dmdates id=dmdates value=''></input><select style=display:inline-flex; onchange=dc(this); id=syears><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=smonths><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=sdays><option value=''>N/A vs ...</option></select><br><br>
 Modified Date Before (optional): <input type=hidden name=dmdateb id=dmdateb value=''></input><select style=display:inline-flex; onchange=dc(this); id=syearb><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=smonthb><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=sdayb><option value=''>N/A vs ...</option></select><br><br>
<input type=hidden name=emailto id=emailto value='" . $emailto . "'></input><input style='background-color:pink;border:2px solid red;' type=submit value=Show></input>&nbsp;<input style='background-color:pink;border:2px solid red;' type=submit name=pdf value='Show as PDF'></input>&nbsp;<input style='background-color:pink;border:2px solid red;' type=submit name=pdfdownload value='Show as Downloadable PDF'></input>&nbsp;<input onclick='emailclicked=true;' style='background-color:pink;border:2px solid red;' type=submit name=pdfdownloademail value='Email PDF'></input>
 </form>
 </body></html>");
 } else {
 ourecho("<!doctype html><html><head><title>Difference Reporting - RJM Programming - December, 2017</title><scr" . "ipt type='text/javascript'> " . $jscr . "</scr" . "ipt></head><body style='width:100%;word-wrap:break-word;'><p>No files found for report regarding " . ucurldecode($_POST['dpath']) . urldecode($_POST['dfilespec']) . $sincebefore . "</p><br><h1>Differences Report for Files Changed Lately<h1><h3>RJM Programming - December, 2017</h3><br>
 <form style='padding: 5px 5px 5px 5px;border:3px solid green;' id=myform onsubmit='return checkthings();' action=./pdfimageplustext.php method=POST>
 Set Path and Variable Filespec: <input readonly style=display:inline-flex;width:220px; type=text id=dpath name=dpath value=" . $dpath . "></input><input type=text id=dfilespec name=dfilespec value='PHP/*/*.*GETME'></input><br><br>
 Modified Date Since (optional): <input type=hidden name=dmdates id=dmdates value=''></input><select style=display:inline-flex; onchange=dc(this); id=syears><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=smonths><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=sdays><option value=''>N/A vs ...</option></select><br><br>
 Modified Date Before (optional): <input type=hidden name=dmdateb id=dmdateb value=''></input><select style=display:inline-flex; onchange=dc(this); id=syearb><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=smonthb><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=sdayb><option value=''>N/A vs ...</option></select><br><br>
<input type=hidden name=emailto id=emailto value='" . $emailto . "'></input><input style='background-color:pink;border:2px solid red;' type=submit value=Show></input>&nbsp;<input style='background-color:pink;border:2px solid red;' type=submit name=pdf value='Show as PDF'></input>&nbsp;<input style='background-color:pink;border:2px solid red;' type=submit name=pdfdownload value='Show as Downloadable PDF'></input>&nbsp;<input onclick='emailclicked=true;' style='background-color:pink;border:2px solid red;' type=submit name=pdfdownloademail value='Email PDF'></input>
 </form>
 </body></html>");
 }
 } else {
 ourecho("*" . $filespecmdates . "*" . $filespecmdateb);
 exit;
 }
} else if ($pdfis == "") {
 echo "<!doctype html><html><head><title>Difference Reporting - RJM Programming - December, 2017</title><scr" . "ipt type='text/javascript'> " . $jscr . "</scr" . "ipt></head><body style='width:100%;word-wrap:break-word;'><h1>Differences Report for Files Changed Lately<h1><h3>RJM Programming - December, 2017</h3><br>
 <form style='padding: 5px 5px 5px 5px;border:3px solid green;' id=myform onsubmit='return checkthings();' action=./pdfimageplustext.php method=POST>
 Set Path and Variable Filespec: <input readonly style=display:inline-flex;width:220px; type=text id=dpath name=dpath value=" . $dpath . "></input><input type=text id=dfilespec name=dfilespec value='PHP/*/*.*GETME'></input><br><br>
 Modified Date Since (optional): <input type=hidden name=dmdates id=dmdates value=''></input><select style=display:inline-flex; onchange=dc(this); id=syears><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=smonths><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=sdays><option value=''>N/A vs ...</option></select><br><br>
 Modified Date Before (optional): <input type=hidden name=dmdateb id=dmdateb value=''></input><select style=display:inline-flex; onchange=dc(this); id=syearb><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=smonthb><option value=''>N/A vs ...</option></select><select style=display:inline-flex; onchange=dc(this); id=sdayb><option value=''>N/A vs ...</option></select><br><br>
<input type=hidden name=emailto id=emailto value='" . $emailto . "'></input><input style='background-color:pink;border:2px solid red;' type=submit value=Show></input>&nbsp;<input style='background-color:pink;border:2px solid red;' type=submit name=pdf value='Show as PDF'></input>&nbsp;<input style='background-color:pink;border:2px solid red;' type=submit name=pdfdownload value='Show as Downloadable PDF'></input>&nbsp;<input onclick='emailclicked=true;' style='background-color:pink;border:2px solid red;' type=submit name=pdfdownloademail value='Email PDF'></input>
 </form>
 </body></html>";
}

//}
?>
