Portions created by the Initial Developer are Copyright (C) 2008-2019 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; require_once "resources/paging.php"; //check permissions if (if_group("superadmin")) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //define available columns $available_columns[] = 'pin_number_uuid'; $available_columns[] = 'domain_uuid'; $available_columns[] = 'pin_number'; $available_columns[] = 'accountcode'; $available_columns[] = 'enabled'; $available_columns[] = 'description'; //define the functions function array2csv(array &$array) { if (count($array) == 0) { return null; } ob_start(); $df = fopen("php://output", 'w'); fputcsv($df, array_keys(reset($array))); foreach ($array as $row) { fputcsv($df, $row); } fclose($df); return ob_get_clean(); } function download_send_headers($filename) { // disable caching $now = gmdate("D, d M Y H:i:s"); header("Expires: Tue, 03 Jul 2001 06:00:00 GMT"); header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate"); header("Last-Modified: {$now} GMT"); // force download header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); // disposition / encoding on response body header("Content-Disposition: attachment;filename={$filename}"); header("Content-Transfer-Encoding: binary"); } //get the pin numbers from the database and send them as output if (is_array($_REQUEST["column_group"]) && @sizeof($_REQUEST["column_group"]) != 0) { //validate the token $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); header('Location: pin_numbers.php'); exit; } //validate submitted columns foreach($_REQUEST["column_group"] as $column_name) { if (in_array($column_name, $available_columns)) { $selected_columns[] = $column_name; } } if (is_array($selected_columns) && @sizeof($selected_columns) != 0) { $sql = "select ".implode(', ', $selected_columns)." from v_pin_numbers "; $sql .= "where domain_uuid = :domain_uuid "; $parameters['domain_uuid'] = $domain_uuid; $database = new database; $pin_numbers = $database->select($sql, $parameters, 'all'); unset($sql, $parameters, $selected_columns); download_send_headers("data_export_".date("Y-m-d") . ".csv"); echo array2csv($pin_numbers); exit; } } //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //include the header $document['title'] = $text['title-pin_numbers']; require_once "resources/header.php"; //show the content echo "
\n"; echo "
\n"; echo "
".$text['header-export']."
\n"; echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'pin_numbers.php']); echo button::create(['type'=>'submit','label'=>$text['button-export'],'icon'=>$_SESSION['theme']['button_icon_export'],'id'=>'btn_save']); echo "
\n"; echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; if (is_array($available_columns) && @sizeof($available_columns) != 0) { $x = 0; foreach ($available_columns as $column_name) { echo "\n"; echo " \n"; echo " \n"; echo "\n"; $x++; } unset($available_columns); } echo "
\n"; echo " \n"; echo " ".$text['label-column_name']."
\n"; echo " \n"; echo " ".$column_name."
\n"; echo "

\n"; echo "\n"; echo "
\n"; //include the footer require_once "resources/footer.php"; ?>