<?php
// renameidea.php
// File rename idea
// RJM Programming
// December, 2018
// Filename: act-1989-76-2017-07-01.xml
// replace ‘act-‘ with ‘ACT~AUS~NSW~Y.’ and delete the date at the end ‘-2017-07-01’ – this will vary with each file



$path="";
if (isset($_GET['path'])) {
   $path=str_replace("+"," ",urldecode($_GET['path']));
   $htmlis="<html><body><h1>XML Rename Report ...</h1><br><h3>Filename: act-1989-76-2017-07-01.xml ... replace act- with ACT~AUS~NSW~Y. and delete the date at the end -2017-07-01 ... this will vary with each file</h3><br><div></div></body></html>";
   foreach (glob($path . "act-*-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].xml") as $xmlfil) {
     $predotxml=explode(".xml", $xmlfil);
     $postdotxml=explode("act-", substr($predotxml[0],0,(strlen($predotxml[0]) - 11)));
     $renfile=$postdotxml[0] . "ACT~AUS~NSW~Y." . $postdotxml[1] . ".xml";
     $htmlis=str_replace("</div>", "<br>File candidate called " . $xmlfil . " found that we renamed to " . $renfile . "</div>", $htmlis);
     rename($xmlfil, $renfile);
   }
   echo $htmlis;
   exit;
} else if (isset($_POST['path'])) {
   $path=str_replace("+"," ",urldecode($_POST['path']));
   $htmlis="<html><body><h1>XML Rename Report ...</h1><br><h3>Filename: act-1989-76-2017-07-01.xml ... replace act- with ACT~AUS~NSW~Y. and delete the date at the end -2017-07-01 ... this will vary with each file</h3><br><div></div></body></html>";
   foreach (glob($path . "act-*-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].xml") as $xmlfil) {
     $predotxml=explode(".xml", $xmlfil);
     $postdotxml=explode("act-", substr($predotxml[0],0,(strlen($predotxml[0]) - 11)));
     $renfile=$postdotxml[0] . "ACT~AUS~NSW~Y." . $postdotxml[1] . ".xml";
     $htmlis=str_replace("</div>", "<br>File candidate called " . $xmlfil . " found that we renamed to " . $renfile . "</div>", $htmlis);
     rename($xmlfil, $renfile);
   }
   echo $htmlis;
   exit;
} else {
   if (!isset($_GET['nothing'])) {
   $htmlis="<html><body><h1>XML Rename Run ...</h1><br><h3>Filename: act-1989-76-2017-07-01.xml ... replace act- with ACT~AUS~NSW~Y. and delete the date at the end -2017-07-01 ... this will vary with each file</h3><br><form target=ibelow action=./renameidea.php method=GET><br>XML File Folder on which to perform renames: <input style='width:30%;' name=path type='text' value='" . dirname(__FILE__) . "/' placeholder='XML File Folder'></input>&nbsp;<input type=submit value='Rename'></input><form><br><br><iframe src='./renameidea.php?nothing=y' name=ibelow id=ibelow style='width:100%;height:600px;'></iframe></body></html>";
   echo $htmlis;
   exit;
   } else {
   exit;
   }
}
?>
