. */ require_once("./include/include.php"); require_once("./include/IExport.php"); $exports = array(); $dir = dirname($_SERVER["SCRIPT_FILENAME"])."/include/Exports/*.php"; if( is_dir(dirname($dir)) ) { foreach( glob($dir) as $file ) { if( is_file($file) ) { $className = basename($file, ".php"); require_once($file); $exports[$className] = new $className; } } }else { debug(dirname($dir)." does not exist, failed loading exports"); } $error = NULL; if( $_SERVER['REQUEST_METHOD'] == "POST" ) { if( isset($_POST['export']) && array_key_exists($_POST['export'], $exports) && $exports[ $_POST['export'] ]->hasAccess() ) { admin_header(true, true); $exportClass = $exports[ $_POST['export'] ]; $data = ""; $columns = array(); foreach($exportClass->getHeaders() as $headerName => $headerValue) { $columns[] = $headerName; $data .= "\"" . addslashes($headerValue) . "\","; } $data = substr($data, 0, -1) . "\n"; foreach($exportClass->getData() as $row) { foreach($columns as $column) { if( !isset($row[$column]) ) { $data .= ","; }elseif( is_numeric($row[$column]) ) { $data .= $row[$column] . ","; }else { $data .= "\"" . addslashes($row[$column]) . "\","; } } $data = substr($data, 0, -1) . "\n"; } header("Last-Modified: " . gmdate("D, d M Y H:i ") . " GMT"); header('Pragma: no-cache'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header("Content-length: ".strlen($data)); header("Content-disposition: attachment; filename=\"".$_POST['export'].".csv\""); header("Content-type: application/octet-stream"); header("Content-Transfer-Encoding: binary"); header('Pragma: public'); echo $data; admin_footer(true, true); }else { $error = "Unknown export selected, or you don't have access."; } } if( $_SERVER['REQUEST_METHOD'] == "GET" || $error != NULL ) { admin_header(); if( $error != NULL ) { echoln("" . $error . "

"); } echoln("

"); foreach( $exports as $exportName => $exportClass ) { if( $exportClass->hasAccess() ) { echoln(""); echoln("
"); } } echoln("

"); echoln("

"); admin_footer(); } ?>