<!--Copyright �2015 Anouk Stein, MD--> <?php //Save to csv include "SaveElection.php"; if ($_POST['output'] == "csv") { $filename = "electionResults.csv"; header('Content-type: application/csv'); header('Content-Disposition: attachment; filename=' . $filename); download(); } if ($_POST['output'] == "json") { $filename = "electionResults.json"; header('Content-type: application/json'); header('Content-Disposition: attachment; filename=' . $filename); getResultsOutputJsn(); } ?>
function download($type) { global $variables; $year = 2015; //TODO getElectionYear $path = $variables['pathForCSVandJson']; $output = ""; if ($type == 'csv') { $output .= getResultsOutputCsv(); } elseif ($type == 'json') { $output .= getResultsOutputJsn(); } $file = fopen($path . "/ptonElections_" . $year . "." . $type, "w"); if ($file) { fwrite($file, $output); fclose($file); } return $output; }
function download($type, $date) { global $variables; $year = $date; $path = $variables['pathForCSVandJson']; $output = ""; if ($type == 'csv') { //$output .= getResultsOutputCsv(); $output .= getResultsOutputWithDelimiter("\t"); } elseif ($type == 'tsv') { $output .= getResultsOutputTsv(); } elseif ($type == 'json') { $output .= getResultsOutputJsn(); } elseif ($type == 'xls') { $output .= getResultsOutputXls(); } $file = @fopen($path . "electionResults" . "." . $type, "w"); if ($file) { fwrite($file, $output); fclose($file); } return $output; }