<?php
// ziptest.php
// RJM Programming
// September, 2017
// Testing PHP zip file functionalities in PHP
// Thanks to https://www.w3schools.com/PHP/func_zip_entry_open.asp

$types = ["audio/wav","audio/x-wav","audio/x-pn-realaudio","audio/x-mpegurl","audio/x-aiff","audio/mpeg","audio/mid",
      "audio/basic","audio/ogg","video/x-sgi-movie","video/x-msvideo","video/quicktime","audio/mp3","video/mp4","video/mpeg",
      "video/x-la-asf","video/ogg","video/webm","audio/mp4", "image/jpeg", "image/jpeg", "image/png", "image/gif", "image/bmp", "image/tif",
      "text/html", "text/html", "text/html", "text/javascript", "text/css", "text/plain", "text/xml", "text/csv",
      "application/vnd.ms-word", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/x-php", "application/pdf",
      "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.ms-powerpoint",
      "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"];
$exts = [".wav",".wav",".ram",".m3u",".aiff",".mp3",".rmi",
      ".snd",".ogg",".movie",".avi",".mov",".mp3",".m4v",".mpeg",
      ".lsx",".ogv",".webm",".m4a", ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tif",
      ".htm", ".html", ".htmls", ".js", ".css", ".txt", ".xml", ".csv", 
      ".doc", ".docx", ".php", ".pdf",
      ".pptx", ".ppt",
      ".xls", ".xlsx"];

$onc=" window.location=document.URL.split('#')[0].replace('&myh1=y','') + '&myh1=y#myh1'; ";  
$ic="^";  
$itable="#itable";
if (strpos(("" . $_SERVER['QUERY_STRING']), "myh1=") !== false) {
 $ic="v";  
 $itable="&myh1=y#myh1";
 $onc=" window.location=document.URL.split('#')[0].replace('&myh1=y','') + '#itable'; ";  
}
      
$jsc="<style> td { text-align: center; } </style>
      <scri" . "pt type='text/javascript'> 
    var jsup=1, jsub=1, rawy='', htok=true;
    function animqnextone() {
      //alert(document.getElementById('jsup').innerHTML.replace('&nbsp;','').replace('g',''));
      jsup=eval(document.getElementById('jsup').innerHTML.replace('&nbsp;','').replace('g',''));
      jsub=eval(document.getElementById('jsub').innerHTML.replace('&nbsp;','').replace('g',''));
      //alert(jsup + ' ... ' + jsub);
      if (jsup < jsub) {
        jsup++;
        document.getElementById('jsup').innerHTML=jsup;
        window.location='#g' + jsup;
        //alert('#g' + jsup);
        if (htok) setTimeout(animqnextone,2000);
      } else {
        if (htok) setTimeout(animqprevone,2000);
      }
    }
    function animqprevone() {
      jsup=eval(document.getElementById('jsup').innerHTML.replace('&nbsp;','').replace('g',''));
      jsub=eval(document.getElementById('jsub').innerHTML.replace('&nbsp;','').replace('g',''));
      if (jsup > 1) {
        jsup--;
        document.getElementById('jsup').innerHTML=jsup;
        window.location='#g' + jsup;
        //alert('#g' + jsup);
        if (htok) setTimeout(animqprevone,2000);
      } else {
        if (htok) setTimeout(animqnextone,2000);
      }
    }
    function animnextone() {
      var wls, wlstwo='';
      if (document.getElementById('ishownext')) {
        if (document.getElementById('ishownext').outerHTML.indexOf(' onclick=') != -1) {
          wls=document.getElementById('ishownext').outerHTML.replace(/&amp;/g,'&').split('window.location=');
          if (wls.length > 1) {
            wlstwo=wls[1].substring(1).split(wls[1].substring(0,1))[0].split('#')[0].replace('&animf=y','').replace('&animb=y','') + '&animf=y" . $itable . "';
    //alert(wlstwo);
            //document.getElementById('ishow').src=wlstwo;
            window.location=wlstwo;
          }
        } else {
          setTimeout(animprevone,8000);
        }
      }
    }
    function animprevone() {
      var wls, wlstwo='';
      if (document.getElementById('ishowprev')) {
        if (document.getElementById('ishowprev').outerHTML.indexOf(' onclick=') != -1) {
          wls=document.getElementById('ishowprev').outerHTML.replace(/&amp;/g,'&').split('window.location=');
          if (wls.length > 1) {
            wlstwo=wls[1].substring(1).split(wls[1].substring(0,1))[0].split('#')[0].replace('&animf=y','').replace('&animb=y','') + '&animb=y" . $itable . "';
    //alert(wlstwo);
            //document.getElementById('ishow').src=wlstwo;
            window.location=wlstwo;
          }
        } else {
          setTimeout(animnextone,8000);
        }
      }
    }
    
    function nounderline() {
      if (document.getElementById('ianim')) document.getElementById('ianim').style.textDecoration='none';
      if (document.getElementById('janim')) document.getElementById('janim').style.textDecoration='none';
    }
    
    function checkrawy() {
      if (document.getElementById('rawy').value != '') rawy='rawy=y&';
    }
    
    if (document.URL.indexOf('&animf=') != -1) {
      setTimeout(nounderline, 300);
      setTimeout(animnextone, 8000);
    } else if (document.URL.indexOf('&animb=') != -1) {
      setTimeout(nounderline, 300);
      setTimeout(animprevone, 8000);
    }
    
    setTimeout(checkrawy, 2800);
    </scr" . "ipt>
    ";
  

$gthisis=1;
$gtotis=0;
$thisis=0;
$totis=0;
$numis=0;
$ourfilename="";
$ofprevinterest="";
$firstone="";
$lastone="";
$secondone="";
$secondlastone="";
$prevone="";
$nextone="";
$prevtoprevone="";
$nexttoprevone="";
$nexttonextone="";
$prevtonextone="";
$zipfile="";

$gnumis=0;
$greportdata="";
$gofprevinterest="";

if (isset($_GET['zipfile'])) {
  $zipfile=urldecode($_GET['zipfile']);
}
$ofinterest="youllneverfindthis";
if (isset($_GET['ofinterest'])) {
  $ofinterest=urldecode($_GET['ofinterest']);
  if ($ofinterest == "") $ofinterest="youllneverfindthis";
}
$asgallery="";
if (isset($_GET['asgallery'])) {
  $asgallery=urldecode($_GET['asgallery']);
}
     
if (isset($_GET['ofinterest']) && isset($_GET['ofprevinterest']) && isset($_GET['ofnextinterest'])) {
$formstuff="<br><form style='padding:5px 5px 5px 5px;border:3px solid red;background-color:pink;' action='./ziptest.php' method=GET>
  Zipfile Name: <input type=text name=zipfile value='" . $zipfile . "' title='Zipfile name goes here'></input><br>
  Zipfile File of Interest (can be comma separated list): <input style='width:60%;' type=text id=ofinterest name=ofinterest value='" . str_replace("youllneverfindthis","",$ofinterest) . "' title='Zipfile file of Interest name goes here'></input><br><select id=mysel onchange=\" if (this.value != '') { if (document.getElementById('ofinterest').value != '') { document.getElementById('ofinterest').value+=','; } document.getElementById('ofinterest').value+=this.value; } \"><option value=>Optionally please add to list above selecting below ...</option></select><br>
  <br><br><input style='background-color:yellow;' type=submit name=asgallery value='Display Media Gallery from Media Files within Zipfile'></input> <input onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&asgallery=y'; \" style='background-color:yellow;' type=button value='Media Gallery of all Media in Zipfile List'></input> <input onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "'; \" style='background-color:yellow;' type=button value='This Zipfile List'></input> <input style='background-color:yellow;' type=submit value='Other Zipfile Run'></input>    
  </form><br><table id='itable' style='width:100%;'><tbody><tr><td style='vertical-align:top;width:5%;background-color:rgba(255,0,0,0.2);'><a id='ishowprev' style='cursor:pointer;text-decoration:none;display:none;'>&lt;</a></td><td style='width:90%;'><table><tbody><tr><td style='width:5%;background-color:rgba(127,127,0,0.2);'><a id='ishowfirst' style='cursor:pointer;text-decoration:none;display:none;'>&lt;&lt;</a></td><td style='width:15%;background-color:rgba(127,127,127,0.2);'><a id='ianim' style='cursor:pointer;text-decoration:underline;display:block;' title='Animate a slideshow' onclick=' nounderline(); setTimeout(animnextone,3000);  '>&#127916;<sup id=isup></sup></a><sub id=isub></sub></a></td><td style='width:15%;background-color:rgba(127,0,127,0.2);'><a id='ianim' style='cursor:pointer;text-decoration:none;display:block;' title='Hashtag positioning' onclick=\"" . $onc . "\">" . $ic . "</a></td><td style='border:5px solid purple;'><a onclick=\"window.open('" . "./ziptest.php?' + rawy + 'zipfile=" . $zipfile . "&ofinterest=" . $ofinterest . $itable . "','_blank'); \" title='New window for this' style='cursor:pointer;text-decoration:underline;'>" . $ofinterest . "</a></td><td style='width:5%;background-color:rgba(0,255,0,0.2);'><a id='ishowlast' style='cursor:pointer;text-decoration:none;display:none;'>&gt;&gt;</a></td></tr></tbody></table><br><iframe frameborder=0 width='90%' height='600px;' id='ishow' src='./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . $ofinterest . $itable . "'></iframe></td><td style='vertical-align:top;width:5%;background-color:rgba(0,0,255,0.2);'><a id='ishownext' style='cursor:pointer;text-decoration:none;display:none;'>&gt;</a></td></td></td></tbody></table>";
} else if (isset($_GET['ofinterest']) && isset($_GET['ofprevinterest'])) {
$formstuff="<br><form style='padding:5px 5px 5px 5px;border:3px solid red;background-color:pink;' action='./ziptest.php' method=GET>
  Zipfile Name: <input type=text name=zipfile value='" . $zipfile . "' title='Zipfile name goes here'></input><br>
  Zipfile File of Interest (can be comma separated list): <input style='width:60%;' type=text id=ofinterest name=ofinterest value='" . str_replace("youllneverfindthis","",$ofinterest) . "' title='Zipfile file of Interest name goes here'></input><br><select id=mysel onchange=\" if (this.value != '') { if (document.getElementById('ofinterest').value != '') { document.getElementById('ofinterest').value+=','; } document.getElementById('ofinterest').value+=this.value; } \"><option value=>Optionally please add to list above selecting below ...</option></select><br>
  <br><br><input style='background-color:yellow;' type=submit name=asgallery value='Display Media Gallery from Media Files within Zipfile'></input> <input onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&asgallery=y'; \" style='background-color:yellow;' type=button value='Media Gallery of all Media in Zipfile List'></input> <input onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "'; \" style='background-color:yellow;' type=button value='This Zipfile List'></input> <input style='background-color:yellow;' type=submit value='Other Zipfile Run'></input>
  </form><br><table id='itable' style='width:100%;'><tbody><tr><td style='vertical-align:top;width:5%;;background-color:rgba(255,0,0,0.2);'><a id='ishowprev' style='cursor:pointer;text-decoration:none;display:none;'>&lt;</a></td><td style='width:90%;'><table><tbody><tr><td style='width:5%;background-color:rgba(127,127,0,0.2);'><a id='ishowfirst' style='cursor:pointer;text-decoration:none;display:none;'>&lt;&lt;</a></td><td style='width:15%;background-color:rgba(127,127,127,0.2);'><a id='ianim' style='cursor:pointer;text-decoration:underline;display:block;' title='Animate a slideshow' onclick=' nounderline();  setTimeout(animnextone,3000);  '>&#127916;<sup id=isup></sup></a><sub id=isub></sub></a></td><td style='width:15%;background-color:rgba(127,0,127,0.2);'><a id='ianim' style='cursor:pointer;text-decoration:none;display:block;' title='Hashtag positioning' onclick=\"" . $onc . "\">" . $ic . "</a></td><td style='border:5px solid purple;'><a onclick=\"window.open('" . "./ziptest.php?' + rawy + 'zipfile=" . $zipfile . "&ofinterest=" . $ofinterest . $itable . "','_blank'); \" title='New window for this' style='cursor:pointer;text-decoration:underline;'>" . $ofinterest . "</a></td><td style='width:5%;background-color:rgba(0,255,0,0.2);'><a id='ishowlast' style='cursor:pointer;text-decoration:none;display:none;'>&gt;&gt;</a></td></tr></tbody></table><br><iframe frameborder=0 width='90%' height='600px;' id='ishow' src='./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . $ofinterest . $itable . "'></iframe></td><td style='vertical-align:top;width:5%;background-color:rgba(0,0,255,0.2);'><a id='ishownext' style='cursor:pointer;text-decoration:none;display:none;'>&gt;</a></td></td></td></tbody></table>";
} else if (isset($_GET['ofinterest']) && isset($_GET['ofnextinterest'])) {
$formstuff="<br><form style='padding:5px 5px 5px 5px;border:3px solid red;background-color:pink;' action='./ziptest.php' method=GET>
  Zipfile Name: <input type=text name=zipfile value='" . $zipfile . "' title='Zipfile name goes here'></input><br>
  Zipfile File of Interest (can be comma separated list): <input style='width:60%;' type=text id=ofinterest name=ofinterest value='" . str_replace("youllneverfindthis","",$ofinterest) . "' title='Zipfile file of Interest name goes here'></input><br><select id=mysel onchange=\" if (this.value != '') { if (document.getElementById('ofinterest').value != '') { document.getElementById('ofinterest').value+=','; } document.getElementById('ofinterest').value+=this.value; } \"><option value=>Optionally please add to list above selecting below ...</option></select><br>
  <br><br><input style='background-color:yellow;' type=submit name=asgallery value='Display Media Gallery from Media Files within Zipfile'></input> <input onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&asgallery=y'; \" style='background-color:yellow;' type=button value='Media Gallery of all Media in Zipfile List'></input> <input onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "'; \" style='background-color:yellow;' type=button value='This Zipfile List'></input> <input style='background-color:yellow;' type=submit value='Other Zipfile Run'></input>
  </form><br><table id='itable' style='width:100%;'><tbody><tr><td style='vertical-align:top;width:5%;;background-color:rgba(255,0,0,0.2);'><a id='ishowprev' style='cursor:pointer;text-decoration:none;display:none;display:none;'>&lt;</a></td><td style='width:90%;'><table><tbody><tr><td style='width:5%;background-color:rgba(127,127,0,0.2);'><a id='ishowfirst' style='cursor:pointer;text-decoration:none;display:none;'>&lt;&lt;</a></td><td style='width:15%;background-color:rgba(127,127,127,0.2);'><a id='ianim' style='cursor:pointer;text-decoration:underline;display:block;' title='Animate a slideshow' onclick=' nounderline();  setTimeout(animnextone,3000);  '>&#127916;<sup id=isup></sup></a><sub id=isub></sub></a></td><td style='width:15%;background-color:rgba(127,0,127,0.2);'><a id='ianim' style='cursor:pointer;text-decoration:none;display:block;' title='Hashtag positioning' onclick=\"" . $onc . "\">" . $ic . "</a></td><td style='border:5px solid purple;'><a onclick=\"window.open('" . "./ziptest.php?' + rawy + 'zipfile=" . $zipfile . "&ofinterest=" . $ofinterest . $itable . "','_blank'); \" title='New window for this' style='cursor:pointer;text-decoration:underline;'>" . $ofinterest . "</a></td><td style='width:5%;background-color:rgba(0,255,0,0.2);'><a id='ishowlast' style='cursor:pointer;text-decoration:none;display:none;'>&gt;&gt;</a></td></tr></tbody></table><br><iframe frameborder=0 width='90%' height='600px;' id='ishow' src='./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . $ofinterest . $itable . "'></iframe></td><td style='vertical-align:top;width:5%;background-color:rgba(0,0,255,0.2);'><a id='ishownext' style='cursor:pointer;text-decoration:none;display:none;'>&gt;</a></td></td></td></tbody></table>";
} else if (1 == 2 && isset($_GET['ofinterest'])) {
$formstuff="<br><form style='padding:5px 5px 5px 5px;border:3px solid red;background-color:pink;' action='./ziptest.php' method=GET>
  Zipfile Name: <input type=text name=zipfile value='" . $zipfile . "' title='Zipfile name goes here'></input><br>
  Zipfile File of Interest (can be comma separated list): <input style='width:60%;' type=text id=ofinterest name=ofinterest value='" . str_replace("youllneverfindthis","",$ofinterest) . "' title='Zipfile file of Interest name goes here'></input><br><select id=mysel onchange=\" if (this.value != '') { if (document.getElementById('ofinterest').value != '') { document.getElementById('ofinterest').value+=','; } document.getElementById('ofinterest').value+=this.value; } \"><option value=>Optionally please add to list above selecting below ...</option></select><br>
  <br><br><input style='background-color:yellow;' type=submit name=asgallery value='Display Media Gallery from Media Files within Zipfile'></input> <input onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&asgallery=y'; \" style='background-color:yellow;' type=button value='Media Gallery of all Media in Zipfile List'></input> <input onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "'; \" style='background-color:yellow;' type=button value='This Zipfile List'></input> <input style='background-color:yellow;' type=submit value='Other Zipfile Run'></input>
  </form><br><table style='width:100%;'><tbody><tr><td style='width:5%;'><iframe id='ishowprev' style='display:none;' src='./ziptest.php'></iframe></td><td style='width:90%;'><iframe id='ishow' style='display:none;' src='./ziptest.php'></iframe></td><td style='width:5%;'><iframe id='ishownext' style='display:none;' src='./ziptest.php'></iframe></td></td></tbody></table>";
} else if ($zipfile != "") {
$formstuff="<br><form style='padding:5px 5px 5px 5px;border:3px solid red;background-color:pink;' action='./ziptest.php' method=GET>
  Zipfile Name: <input type=text name=zipfile value='" . $zipfile . "' title='Zipfile name goes here'></input><br>
  Zipfile File of Interest (can be comma separated list): <input style='width:60%;' type=text id=ofinterest name=ofinterest value='" . str_replace("youllneverfindthis","",$ofinterest) . "' title='Zipfile file of Interest name goes here'></input><br><select id=mysel onchange=\" if (this.value != '') { if (document.getElementById('ofinterest').value != '') { document.getElementById('ofinterest').value+=','; } document.getElementById('ofinterest').value+=this.value; } \"><option value=>Optionally please add to list above selecting below ...</option></select><br>
  <br><br><input style='background-color:yellow;' type=submit name=asgallery value='Display Media Gallery from Media Files within Zipfile'></input> <input onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&asgallery=y'; \" style='background-color:yellow;' type=button value='Media Gallery of all Media in Zipfile List'></input> <input onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "'; \" style='background-color:yellow;' type=button value='This Zipfile List'></input> <input style='background-color:yellow;' type=submit value='Other Zipfile Run'></input>
  </form><br><table style='width:100%;'><tbody><tr><td style='width:5%;'><iframe id='ishowprev' style='display:none;' src='./ziptest.php'></iframe></td><td style='width:90%;'><iframe id='ishow' style='display:none;' src='./ziptest.php'></iframe></td><td style='width:5%;'><iframe id='ishownext' style='display:none;' src='./ziptest.php'></iframe></td></td></tbody></table>";
} else {
$formstuff="<br><form style='padding:5px 5px 5px 5px;border:3px solid red;background-color:pink;' action='./ziptest.php' method=GET>
  Zipfile Name: <input type=text name=zipfile value='" . $zipfile . "' title='Zipfile name goes here'></input><br>
  Zipfile File of Interest (can be comma separated list): <input style='width:60%;' type=text id=ofinterest name=ofinterest value='" . str_replace("youllneverfindthis","",$ofinterest) . "' title='Zipfile file of Interest name goes here'></input><br><select id=mysel onchange=\" if (this.value != '') { if (document.getElementById('ofinterest').value != '') { document.getElementById('ofinterest').value+=','; } document.getElementById('ofinterest').value+=this.value; } \"><option value=>Optionally please add to list above selecting below ...</option></select><br>
  <br><br><input style='background-color:yellow;' type=submit name=asgallery value='Display Media Gallery from Media Files within Zipfile'></input> <input style='background-color:yellow;' type=submit value='Other Zipfile Run'></input>
  </form><br><table style='width:100%;'><tbody><tr><td style='width:5%;'><iframe id='ishowprev' style='display:none;' src='./ziptest.php'></iframe></td><td style='width:90%;'><iframe id='ishow' style='display:none;' src='./ziptest.php'></iframe></td><td style='width:5%;'><iframe id='ishownext' style='display:none;' src='./ziptest.php'></iframe></td></td></tbody></table>";
}
$tabledata="";
$reportdata="";
if ($zipfile != "") {
$zip = zip_open($zipfile);

if ($zip)
  {
  while ($zip_entry = zip_read($zip)) {
    $ourfilename=zip_entry_name($zip_entry);
    if (strpos($ourfilename, "__MACOSX/") === false) {
    $formstuff=str_replace("</select>", "<option value='" . $ourfilename . "'>" . $ourfilename . "</option></select>", $formstuff);
    $ourext=explode(".",$ourfilename)[-1 + sizeof(explode(".",$ourfilename))];
    $ourmimetype="";
    for ($i=0; $i<sizeof($exts); $i++) {
      if (strtolower("." . $ourext) == strtolower($exts[$i])) $ourmimetype=$types[$i];
    }

    if (($asgallery == "" || 1 == 1) && (strpos($ourmimetype, "image/") !== false || strpos($ourmimetype, "video/") !== false || strpos($ourmimetype, "audio/") !== false)) {
        $totis++;
        if (urldecode($ourfilename) == urldecode($_GET['ofinterest'])) {
          $thisis=$totis;
        }
        if ($firstone == "") {
          $firstone=$ourfilename;
        } else if ($secondone == "") {
          $secondone=$ourfilename;
        }
        if ($lastone != "") $secondlastone=$lastone;
        $lastone=$ourfilename;
    }

    if ($asgallery == "" && (strpos($ourmimetype, "image/") !== false || strpos($ourmimetype, "video/") !== false || strpos($ourmimetype, "audio/") !== false)) {
      if (isset($_GET['ofprevinterest'])) {   // new if
        if (urldecode($ourfilename) == urldecode($_GET['ofprevinterest'])) {
          $prevtoprevone=" " . $prevtoprevone . " ";
          $nexttoprevone="";
        } else if (trim($prevtoprevone) == $prevtoprevone && $nexttoprevone == "") {
          $prevtoprevone=$ourfilename;
        } else if ($nexttoprevone == "") {
          $nexttoprevone=$ourfilename;
          $prevtoprevone=trim($prevtoprevone);
        }
      }
    }

    if ($asgallery == "" && (strpos($ourmimetype, "image/") !== false || strpos($ourmimetype, "video/") !== false || strpos($ourmimetype, "audio/") !== false)) {
      if (isset($_GET['ofnextinterest'])) {   // new if
        if (urldecode($ourfilename) == urldecode($_GET['ofnextinterest'])) {
          $prevtonextone=" " . $prevtonextone . " ";
          $nexttonextone="";
        } else if (trim($prevtonextone) == $prevtonextone && $nexttonextone == "") {
          $prevtonextone=$ourfilename;
        } else if ($nexttonextone == "") {
          $nexttonextone=$ourfilename;
          $prevtonextone=trim($prevtonextone);
        }
      }
    }


    if ($asgallery == "" && (strpos($ourmimetype, "image/") !== false || strpos($ourmimetype, "video/") !== false || strpos($ourmimetype, "audio/") !== false)) {
      if (isset($_GET['ofprevinterest']) || isset($_GET['ofnextinterest'])) {   // new if
        if (urldecode($ofinterest) == urldecode($ourfilename)) {
          $prevone=" " . $ourfilename . " ";
          $nextone="";
        } else if (trim($prevone) == $prevone && $nextone == "") {
          $prevone=$ourfilename;
        } else if ($nextone == "") {
          $nextone=$ourfilename;
          $prevone=trim($prevone);
        }
      }
    }
    if ($asgallery != "" && (strpos($ourmimetype, "image/") !== false || strpos($ourmimetype, "video/") !== false || strpos($ourmimetype, "audio/") !== false)) {
        if (firstone == "") {
          $firstone=$ourfilename;
        } else if ($secondone == "") {
          $secondone=$ourfilename;
        }
      $lastone=$ourfilename;
      $isok=true;
      if ($ofinterest != "youllneverfindthis" && strpos("," . $ofinterest . ",","," . $ourfilename . ",") === false) $isok=false;
      if ($isok) {
      if ($tabledata == "") {
        $tabledata="<!doctype html><html><head><title>Media Gallery extracted from " . $zipfile . "</title></head><body><table border=5><THEAD><TR><td></td></TR></THEAD><tbody><tr><td style='width:15%;background-color:rgba(127,127,127,0.2);'><a id='janim' style='cursor:pointer;text-decoration:underline;display:block;' title='Animate a slideshow' onclick=' htok=true; nounderline(); setTimeout(animqnextone,3000);  '>&#127916;<sup id=jsup></sup></a><sub id=jsub></sub></a></td></tr></tbody></table></body></html>";
      }
    if ($gnumis == 0) {
        $gtotis++;
    $gnumis++;  // &#127916;
    $greportdata="<a onclick=\" htok=false; window.open('" . "./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . $ourfilename . $itable . "','_blank');\" id='g" . $gnumis . "' style='cursor:pointer;text-decoration:underline;' title='Click to display in new window'>&#127916;</a>";
    $gofprevinterest="&ofprevinterest=" . $ourfilename;
    } else {
        $gtotis++;
    $tabledata=str_replace($itable . "','_blank');\" id='g" . $gnumis . "'","&ofnextinterest=" . $ourfilename . $itable . "','_blank');\" id='g" . $gnumis . "'",$tabledata);
    $gnumis++;
    $greportdata="<a onclick=\" htok=false; window.open('" . "./ziptest.php?zipfile=" . $zipfile . $gofprevinterest . "&ofinterest=" . $ourfilename . $itable . "','_blank');\" id='g" . $gnumis . "' style='cursor:pointer;text-decoration:underline;' title='Click to display in new window'>&#127916;</a>";
    $gofprevinterest="&ofprevinterest=" . $ourfilename;
    }
      $tabledata=str_replace("</TR>", "<th><a style=\"cursor:pointer;text-decoration:none;\" onclick=\" htok=false; document.getElementById('jsup').innerHTML='&nbsp;" . $gtotis . "'; setTimeout(animqprevone,1000); \" href=#g" . $gtotis . " title='Bit to left'>&#11013;</a>&nbsp;&nbsp;<a style=\"cursor:pointer;text-decoration:none;\" onclick=\" htok=false; document.getElementById('jsup').innerHTML='&nbsp;" . $gtotis . "'; setTimeout(animqnextone,1000); \" href=#g" . $gtotis . " title='Bit to right'>&#10145;</a>&nbsp;&nbsp;<a onclick=\" htok=false; window.open('" . "./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . $ourfilename . $itable . "','_blank');\" style='cursor:pointer;text-decoration:underline;' title='Click for this in new window'>" . $ourfilename . "</a>&nbsp;" . $greportdata . "&nbsp;&nbsp;<a style=\"cursor:pointer;text-decoration:none;\" onclick=\" htok=false;  document.getElementById('jsup').innerHTML='&nbsp;1'; \" href='#janim' title='Back to left'>&#11013;&#11013;</a>&nbsp;&nbsp;<a style=\"cursor:pointer;text-decoration:none;\" onclick=\" htok=false; document.getElementById('jsup').innerHTML='&nbsp;" . $gtotis . "'; setTimeout(animqprevone,1000); \" href=#g" . $gtotis . " title='Bit to left'>&#11013;</a>&nbsp;&nbsp;<a style=\"cursor:pointer;text-decoration:none;\" onclick=\" htok=false; document.getElementById('jsup').innerHTML='&nbsp;" . $gtotis . "'; setTimeout(animqnextone,1000); \" href=#g" . $gtotis . " title='Bit to right'>&#10145;</a>&nbsp;&nbsp;<a style=\"cursor:pointer;text-decoration:none;\" href=#g0 title='Back to right'>&#10145;&#10145;</a></th></TR>", $tabledata);
      $tabledata=str_replace("</tr>", "<td><iframe src='./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . $ourfilename . $itable . "'></iframe></td></tr>", $tabledata);
      }
    }
    if ($asgallery == "" && strpos("," . $ofinterest . ",","," . $ourfilename . ",") !== false) {
    if (!isset($_GET['ofprevinterest']) && !isset($_GET['ofnextinterest'])) {   // new if
    if (zip_entry_open($zip, $zip_entry)) {
      // some code
      $cont=zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
      zip_close($zip);
      if (!isset($_GET['raw']) && strpos($ourmimetype, "video/") !== false) {
      echo "<!doctype html><html><body><video id='myvideo' onerror=\" if (parent.document.getElementById('rawy')) {  parent.document.getElementById('rawy').value='raw=y&'; } \" controls><source type=\"" . $ourmimetype . "\" src=\"data:" . $ourmimetype . ";base64," . base64_encode($cont) . "\"></source></video></body></html>";
      exit;
      } else if (!isset($_GET['raw']) && strpos($ourmimetype, "audio/") !== false) {
      echo "<!doctype html><html><body><audio id='myaudio' onerror=\" if (parent.document.getElementById('rawy')) {  parent.document.getElementById('rawy').value='raw=y&'; } \" controls src=\"data:" . $ourmimetype . ";base64," . base64_encode($cont) . "\" /></body></html>";
      exit;
      } else {
      //echo $ourmimetype . ' ' . zip_entry_filesize($zip_entry);
      //exit;
      header('Content-type: ' . $ourmimetype);
      if (strpos(str_replace("text/csv","application/csv",$ourmimetype),"application/") !== false) header("Content-Disposition: attachment;Filename=" . explode("/",str_replace(substr("\\",0,1),"",$ourfilename))[-1 + sizeof(explode("/",str_replace(substr("\\",0,1),"",$ourfilename)))]);
      echo $cont;
      exit;
      }
    }
    }


        
    } else if ($ofinterest == "youllneverfindthis") {
    $reportdata.="<p>";
    if ($ourmimetype == "") {
    $reportdata.="Name: " . $ourfilename . "<br />";
    } else {
    if ($numis == 0) {
    $numis++;
    $reportdata.="Name: <a onclick=\"window.open('" . "./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . $ourfilename . $itable . ",'_blank');\" id='" . $numis . "' style='cursor:pointer;text-decoration:underline;' title='Click to display in new window'>" . $ourfilename . "</a><br />";
    $ofprevinterest="&ofprevinterest=" . $ourfilename;
    } else {
    $reportdata=str_replace($itable . "','_blank');\" id='" . $numis . "'","&ofnextinterest=" . $ourfilename . $itable . "','_blank');\" id='" . $numis . "'",$reportdata);
    $numis++;
    $reportdata.="Name: <a onclick=\"window.open('" . "./ziptest.php?zipfile=" . $zipfile . $ofprevinterest . "&ofinterest=" . $ourfilename . $itable . "','_blank');\" id='" . $numis . "' style='cursor:pointer;text-decoration:underline;' title='Click to display in new window'>" . $ourfilename . "</a><br />";
    $ofprevinterest="&ofprevinterest=" . $ourfilename;
    }
    }
    $reportdata.="Original size: " . zip_entry_filesize($zip_entry);
    $reportdata.="</p>";
    }
    }
  }
  zip_close($zip);
  }



    if ($asgallery == "") {
      if (isset($_GET['ofnextinterest'])) {   // new if
        if ($prevtonextone != "" && $nexttonextone != "") {
          $formstuff=str_replace("display:none;'>&gt;<","display:block;' onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . urldecode($_GET['ofnextinterest']) . "&ofprevinterest=" . trim($prevtonextone) . "&ofnextinterest=" . $nexttonextone . $itable . "'; \">&gt;<",$formstuff);
        } else if ($prevtonextone != "") {
          $formstuff=str_replace("display:none;'>&gt;<","display:block;' onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . urldecode($_GET['ofnextinterest']) . "&ofprevinterest=" . trim($prevtonextone) . $itable . "'; \">&gt;<",$formstuff);
        } else if ($nexttonextone != "") {
          $formstuff=str_replace("display:none;'>&gt;<","display:block;' onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . urldecode($_GET['ofnextinterest']) . "&ofnextinterest=" . trim($nexttonextone) . $itable . "'; \">&gt;<",$formstuff);
        } else {
          $formstuff=str_replace("display:none;'>&gt;<","display:block;' onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . urldecode($_GET['ofnextinterest']) . $itable . "'; \">&gt;<",$formstuff);
        }
      }
    }


    if ($asgallery == "") {
      if (isset($_GET['ofprevinterest'])) {   // new if
        if ($prevtoprevone != "" && $nexttoprevone != "") {
          $formstuff=str_replace("display:none;'>&lt;<","display:block;' onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . urldecode($_GET['ofprevinterest']) . "&ofprevinterest=" . trim($prevtoprevone) . "&ofnextinterest=" . $nexttoprevone . $itable . "'; \">&lt;<",$formstuff);
        } else if ($prevtoprevone != "") {
          $formstuff=str_replace("display:none;'>&lt;<","display:block;' onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . urldecode($_GET['ofprevinterest']) . "&ofprevinterest=" . trim($prevtoprevone) . $itable . "'; \">&lt;<",$formstuff);
        } else if ($nexttoprevone != "") {
          $formstuff=str_replace("display:none;'>&lt;<","display:block;' onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . urldecode($_GET['ofprevinterest']) . "&ofnextinterest=" . trim($nexttoprevone) . $itable . "'; \">&lt;<",$formstuff);
        } else {
          $formstuff=str_replace("display:none;'>&lt;<","display:block;' onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . urldecode($_GET['ofprevinterest']) . $itable . "'; \">&lt;<",$formstuff);
        }
      }
    }
    
    if ($asgallery == "") {
        if ($firstone != "" && $secondone != "") {
          $formstuff=str_replace("display:none;'>&lt;&lt;<","display:block;' onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . $firstone . "&ofnextinterest=" . $secondone . $itable . "'; \">&lt;&lt;<",$formstuff);
        } else if ($firstone != "") {
          $formstuff=str_replace("display:none;'>&lt;&lt;<","display:block;' onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . $firstone . $itable . "'; \">&lt;&lt;<",$formstuff);
        }
	}

    if ($asgallery == "") {
        if ($lastone != "" && $secondlastone != "") {
          $formstuff=str_replace("display:none;'>&gt;&gt;<","display:block;' onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . $lastone . "&ofprevinterest=" . $secondlastone . $itable . "'; \">&gt;&gt;<",$formstuff);
        } else if ($lastone != "") {
          $formstuff=str_replace("display:none;'>&gt;&gt;<","display:block;' onclick=\" window.location='./ziptest.php?zipfile=" . $zipfile . "&ofinterest=" . $lastone . $itable . "'; \">&gt;&gt;<",$formstuff);
        }
	}

    if ($asgallery == "" || 1 == 1) {
        if ($totis != 0) {
          $formstuff=str_replace("></sub>",">&nbsp;" . $totis . "</sub>",$formstuff);
        }
        if ($thisis != 0) {
          $formstuff=str_replace("></sup>",">&nbsp;" . $thisis . "</sup>",$formstuff);
        }
    }
    
    $formstuff=str_replace("&lt;","&#11013;",$formstuff);
    $formstuff=str_replace("&gt;","&#10145;",$formstuff);
    $formstuff=str_replace(">^<",">&#11014;<",$formstuff);
    $formstuff=str_replace(">v<",">&#11015;<",$formstuff);
    
    if ($asgallery == "" || 1 == 1) {
        if ($gtotis != 0) {
          $tabledata=str_replace("></sub>",">&nbsp;" . $gtotis . "</sub>",$tabledata);
          $tabledata=str_replace("#g0","#g" . $gtotis . " onclick=\" htok=false; document.getElementById('jsup').innerHTML='&nbsp;" . $gtotis . "; \" ",$tabledata);
        }
        if ($gthisis != 0) {
          $tabledata=str_replace("></sup>",">&nbsp;" . $gthisis . "</sup>",$tabledata);
        }
    }
  }  
    
  if ($tabledata != "") {
    echo str_replace("</body>", "<!doctype html><html><head><title>Zipfile Information - RJM Programming - September, 2017</title>" . $jsc . "</head><body>" . "<h1 id=myh1>Zipfile Information<h1><h3>RJM Programming - September, 2017</h3>" . $formstuff . "</table><input id='rawy' value='' type='hidden'></input></body>", $tabledata);
  } else if ($reportdata != "") {
    echo "<!doctype html><html><head><title>Files extracted from " . $zipfile . "</title>" . $jsc . "</head><body><h1>Zipfile Information<h1 id=myh1><h3>RJM Programming - September, 2017</h3><table border=20><tbody><tr><td style='vertical-align:top;'>" . $formstuff . "</td><td style='vertical-align:top;background-color:cyan;'>" . $reportdata . "</td></tr></tbody></table></table><input id='rawy' value='' type='hidden'></input></body></html>";
  } else {
    echo "<!doctype html><html><head><title>Zipfile Information - RJM Programming - September, 2017</title>" . $jsc . "</head><body>" . "<h1 id=myh1>Zipfile Information<h1><h3>RJM Programming - September, 2017</h3>" . $formstuff . "</table><input id='rawy' value='' type='hidden'></input></body></html>";
  }
?> 
