Portions created by the Initial Developer are Copyright (C) 2008-2021 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes files require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once "resources/check_auth.php"; require_once "resources/paging.php"; //check permissions if (!permission_exists('destination_export')) { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //define available columns $available_columns[] = 'domain_uuid'; $available_columns[] = 'destination_uuid '; $available_columns[] = 'dialplan_uuid'; $available_columns[] = 'fax_uuid'; $available_columns[] = 'destination_type'; $available_columns[] = 'destination_number'; $available_columns[] = 'destination_trunk_prefix'; $available_columns[] = 'destination_area_code'; $available_columns[] = 'destination_prefix'; $available_columns[] = 'destination_condition_field'; $available_columns[] = 'destination_number_regex'; $available_columns[] = 'destination_caller_id_name'; $available_columns[] = 'destination_caller_id_number'; $available_columns[] = 'destination_cid_name_prefix'; $available_columns[] = 'destination_context'; $available_columns[] = 'destination_record'; $available_columns[] = 'destination_hold_music'; $available_columns[] = 'destination_accountcode'; $available_columns[] = 'destination_type_voice'; $available_columns[] = 'destination_type_fax'; $available_columns[] = 'destination_type_text'; $available_columns[] = 'destination_conditions'; $available_columns[] = 'destination_actions'; $available_columns[] = 'destination_app'; $available_columns[] = 'destination_data'; $available_columns[] = 'destination_alternate_app'; $available_columns[] = 'destination_alternate_data'; $available_columns[] = 'destination_enabled'; $available_columns[] = 'destination_description'; $available_columns[] = 'destination_type_emergency'; $available_columns[] = 'destination_order'; //define the functions /** * Converts an associative or numerical array into a CSV string. * * This function takes an array and returns its contents as a properly formatted * CSV string. If the input array is empty, it will return null. * * @param array $array The array to be converted into a CSV string. * It can be either an associative or numerical array. * * @return string A CSV string representation of the input array, or null if the array is empty. */ 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(); } /** * Sends HTTP headers for a file download. * * This function sends the necessary HTTP headers to force the browser to download * a file instead of displaying it in the browser. The filename specified should be * a path to the file on the server, not a URL. * * @param string $filename The name and path to the file that will be downloaded by the client. * * @return void This function does not return anything. */ 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 extensions from the database and send them as output if (!empty($_REQUEST["column_group"]) && 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: destination_download.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_destinations "; $sql .= "where domain_uuid = :domain_uuid "; $parameters['domain_uuid'] = $domain_uuid; $destinations = $database->select($sql, $parameters, 'all'); unset($sql, $parameters, $selected_columns); download_send_headers("destination_export_".date("Y-m-d").".csv"); echo array2csv($destinations); exit; } } //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //include the header $document['title'] = $text['title-destination_export']; require_once "resources/header.php"; //show the content echo "
\n"; echo "
\n"; echo "
".$text['header-destination_export']."
\n"; echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','link'=>'destinations.php']); echo button::create(['type'=>'submit','label'=>$text['button-export'],'icon'=>$settings->get('theme', 'button_icon_export'),'id'=>'btn_save','style'=>'margin-left: 15px;']); echo "
\n"; echo "
\n"; echo "
\n"; echo $text['description-destination_export']; 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) { $list_row_onclick = "if (!this.checked) { document.getElementById('checkbox_all').checked = false; }"; echo "\n"; echo " \n"; echo " "; echo ""; $x++; } } echo "
\n"; echo " \n"; echo " ".$text['label-column_name']."
\n"; echo " \n"; echo " ".$column_name."
\n"; echo "
\n"; echo "
\n"; echo "\n"; echo "
\n"; //include the footer require_once "resources/footer.php"; ?>