1) {
$bz="";
$prebz="";
$outrpt=$outrpts[0] . $prebz . $bz . ".csv";
while (file_exists($outrpts[0] . ".csv" . $bz)) {
if (("" . $bz) == "") {
$prebz="_";
$bz=1;
} else {
$bz++;
}
$outrpt=$outrpts[0] . $prebz . $bz . ".csv";
}
}
// Start of business logic piecing together CSV report ...
$cont=file_get_contents($inxml);
$detailrec='';
$detailrec='"col1value","col2value"'; // you do more in depth work to get to this point via $cont
if (trim($detailrec) != "") {
$headerrec='"col1label","col2label"'; // you do more in depth work to get a header record as required via $cont
if ($outrpt != "" && 1 == 1) {
if ($headerrec != "") { $headerrec.="\n"; }
file_put_contents($outrpt, $headerrec . $detailrec);
exit;
} else {
if ($headerrec != "") { $headerrec.=" "; }
echo "
" . $headerrec . $detailrec . "
";
return null;
}
}
// End of business logic piecing together CSV report
return null;
}
}
$genextra="";
if (isset($_GET['generic']) || isset($_POST['generic'])) {
$genextra=" ";
}
$xmlstr="";
$outidea="outfile.csv";
$keep=true;
if (!isset($_GET['keep']) && !isset($_POST['keep'])) {
$keep=false;
}
if (isset($_GET['xml'])) {
// add in file(spec) considerations here
if (strpos(str_replace("+"," ",urldecode($_GET['xml'])), "*") !== false || strpos(str_replace("+"," ",urldecode($_GET['xml'])), "%") !== false || strpos(str_replace("+"," ",urldecode($_GET['xml'])), "?") !== false) {
$htmlis="XML to CSV " . $jobbits . " Report Run ...
";
foreach (glob(str_replace("+"," ",urldecode($_GET['xml']))) as $xmlfil) {
$bz="";
$prebz="";
$outrpts=explode(".xm", str_replace(".XML",".xml",str_replace(".Xml",".xml",$xmlfil)));
$outrpt=$outrpts[0] . $prebz . $bz . ".csv";
while (file_exists($outrpts[0] . ".csv" . $bz)) {
if (("" . $bz) == "") {
$prebz="_";
$bz=1;
} else {
$bz++;
}
$outrpt=$outrpts[0] . $prebz . $bz . ".csv";
}
exec("curl " . "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0] . '?xml=' . urlencode($xmlfil));
if (file_exists($outrpt)) {
$htmlis=str_replace("","Read " . $xmlfil . " as basis for" . " " . $jobbits . " report " . $outrpt . " for your perusal. ",$htmlis);
} else {
$htmlis=str_replace("","Could not read " . $xmlfil . " as basis for" . " " . $jobbits . " report " . $outrpt . " successfully, alas. ",$htmlis);
}
}
echo $htmlis;
exit;
}
// end of file(spec) considerations above
if (strpos(strtolower("~" . urldecode($_GET['xml'])), "~http") !== false) {
$xmlstr=file_get_contents(urldecode($_GET['xml']));
$outidea=explode("." . explode(".",urldecode($_GET['xml']))[-1 + sizeof(explode(".",urldecode($_GET['xml'])))], urldecode($_GET['xml']))[0];
$outidea=explode("/", $outidea)[-1 + sizeof(explode("/", $outidea))];
$outidea=explode(substr("\\",0,1), $outidea)[-1 + sizeof(explode(substr("\\",0,1), $outidea))];
$outidea.=".csv";
} else if (strpos(strtolower("~" . urldecode($_GET['xml'])), "~<") !== false) {
$xmlstr=str_replace("+"," ",urldecode($_GET['xml']));
}
if ($xmlstr != "") {
$xml = oursimplexml_load_string($xmlstr);
} else if (file_exists(urldecode($_GET['xml']))) {
$xmlstr=" ";
$outidea=explode("." . explode(".",urldecode($_GET['xml']))[-1 + sizeof(explode(".",urldecode($_GET['xml'])))], urldecode($_GET['xml']))[0];
$outidea=explode("/", $outidea)[-1 + sizeof(explode("/", $outidea))];
$outidea=explode(substr("\\",0,1), $outidea)[-1 + sizeof(explode(substr("\\",0,1), $outidea))];
$outidea.=".csv";
$xml = oursimplexml_load_file(urldecode($_GET['xml']));
}
} else if (isset($_POST['xml'])) {
// add in file(spec) considerations here
if (strpos(str_replace("+"," ",urldecode($_POST['xml'])), "*") !== false || strpos(str_replace("+"," ",urldecode($_POST['xml'])), "%") !== false || strpos(str_replace("+"," ",urldecode($_POST['xml'])), "?") !== false) {
$htmlis="XML to CSV " . $jobbits . " Report Run ...
";
foreach (glob(str_replace("+"," ",urldecode($_POST['xml']))) as $xmlfil) {
$bz="";
$prebz="";
$outrpts=explode(".xm", str_replace(".XML",".xml",str_replace(".Xml",".xml",$xmlfil)));
$outrpt=$outrpts[0] . $prebz . $bz . ".csv";
while (file_exists($outrpts[0] . ".csv" . $bz)) {
if (("" . $bz) == "") {
$prebz="_";
$bz=1;
} else {
$bz++;
}
$outrpt=$outrpts[0] . $prebz . $bz . ".csv";
}
exec("curl " . "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0] . '?xml=' . urlencode($xmlfil));
if (file_exists($outrpt)) {
$htmlis=str_replace("","Read " . $xmlfil . " as basis for" . " " . $jobbits . " report " . $outrpt . " for your perusal. ",$htmlis);
} else {
$htmlis=str_replace("","Could not read " . $xmlfil . " as basis for" . " " . $jobbits . " report " . $outrpt . " successfully, alas. ",$htmlis);
}
}
echo $htmlis;
exit;
}
// end of file(spec) considerations above
if (strpos(strtolower("~" . urldecode($_POST['xml'])), "~http") !== false) {
$xmlstr=file_get_contents(urldecode($_POST['xml']));
$outidea=explode("." . explode(".",urldecode($_POST['xml']))[-1 + sizeof(explode(".",urldecode($_POST['xml'])))], urldecode($_POST['xml']))[0];
$outidea=explode("/", $outidea)[-1 + sizeof(explode("/", $outidea))];
$outidea=explode(substr("\\",0,1), $outidea)[-1 + sizeof(explode(substr("\\",0,1), $outidea))];
$outidea.=".csv";
} else if (strpos(strtolower("~" . urldecode($_POST['xml'])), "~<") !== false) {
$xmlstr=str_replace("+"," ",urldecode($_POST['xml']));
}
if ($xmlstr != "") {
$xml = oursimplexml_load_string($xmlstr);
} else if (file_exists(urldecode($_POST['xml']))) {
$xmlstr=" ";
$outidea=explode("." . explode(".",urldecode($_POST['xml']))[-1 + sizeof(explode(".",urldecode($_POST['xml'])))], urldecode($_POST['xml']))[0];
$outidea=explode("/", $outidea)[-1 + sizeof(explode("/", $outidea))];
$outidea=explode(substr("\\",0,1), $outidea)[-1 + sizeof(explode(substr("\\",0,1), $outidea))];
$outidea.=".csv";
$xml = oursimplexml_load_file(urldecode($_POST['xml']));
}
}
if ($xmlstr != "") {
if ($xml) {
while (file_exists($outidea)) {
$outidea=str_replace(".csv","1.csv",$outidea);
}
$outstream = fopen($outidea,'w');
$header=false;
foreach($xml as $k=>$details) {
if (!$header) {
$harr=array_keys(get_object_vars($details));
if (sizeof($harr) != 0) {
fputcsv($outstream,$harr);
$header=true;
}
}
$harr=get_object_vars($details);
if (sizeof($harr) != 0) fputcsv($outstream,$harr);
}
fclose($outstream);
//$csvstr=preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "",file_get_contents($outidea));
//$csvstr=preg_replace("/(^[\n]*|[\n]+)[\s\t]*[\n]+/", "",$csvstr);
$csvstr=file_get_contents($outidea);
if (isset($_GET['download']) || isset($_POST['download'])) {
echo "XML to CSV " . $jobbits . " Report - RJM Programming - September, 2018
RJM Programming - August, 2018
";
}
} else {
if (!$keep) {
unlink($outidea);
header('Content-type: text/csv');
echo $csvstr;
exit;
} else {
if (isset($_GET['keep'])) {
if (urldecode($_GET['keep']) == 'keep') {
unlink($outidea);
echo "XML to CSV " . $jobbits . " Report - RJM Programming - September, 2018
";
} else {
header('Content-type: text/csv');
echo $csvstr;
exit;
}
} else if (isset($_POST['keep'])) {
if (urldecode($_POST['keep']) == 'keep') {
unlink($outidea);
echo "XML to CSV " . $jobbits . " Report - RJM Programming - September, 2018
";
} else {
header('Content-type: text/csv');
echo $csvstr;
exit;
}
}
}
}
} else {
echo "XML to CSV " . $jobbits . " Report - RJM Programming - September, 2018
XML to CSV " . $jobbits . " Report
RJM Programming - September, 2018
";
}
?>