Update device_download.php

Make the code more consistent.
This commit is contained in:
FusionPBX
2017-04-22 10:56:23 -06:00
committed by GitHub
parent e39849941f
commit 3adbbc7d57
+83 -81
View File
@@ -17,87 +17,93 @@
The Initial Developer of the Original Code is The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012 Portions created by the Initial Developer are Copyright (C) 2008-2016
the Initial Developer. All Rights Reserved. the Initial Developer. All Rights Reserved.
Contributor(s): Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
*/ */
include "root.php";
require_once "resources/require.php"; //includes
require_once "resources/check_auth.php"; include "root.php";
require_once "resources/paging.php"; require_once "resources/require.php";
if (if_group("superadmin")) { require_once "resources/check_auth.php";
//access granted require_once "resources/paging.php";
}
else { //check permissions
echo "access denied"; if (if_group("superadmin")) {
exit; //access granted
} }
else {
echo "access denied";
exit;
}
//add multi-lingual support //add multi-lingual support
$language = new text; $language = new text;
$text = $language->get(); $text = $language->get();
function array2csv(array &$array) //define the functions
{ function array2csv(array &$array)
if (count($array) == 0) { {
return null; if (count($array) == 0) {
} return null;
ob_start(); }
$df = fopen("php://output", 'w'); ob_start();
fputcsv($df, array_keys(reset($array))); $df = fopen("php://output", 'w');
foreach ($array as $row) { fputcsv($df, array_keys(reset($array)));
fputcsv($df, $row); foreach ($array as $row) {
} fputcsv($df, $row);
fclose($df); }
return ob_get_clean(); fclose($df);
} return ob_get_clean();
}
function download_send_headers($filename) { function download_send_headers($filename) {
// disable caching // disable caching
$now = gmdate("D, d M Y H:i:s"); $now = gmdate("D, d M Y H:i:s");
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT"); header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate"); header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header("Last-Modified: {$now} GMT"); header("Last-Modified: {$now} GMT");
// force download // force download
header("Content-Type: application/force-download"); header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream"); header("Content-Type: application/octet-stream");
header("Content-Type: application/download"); header("Content-Type: application/download");
// disposition / encoding on response body // disposition / encoding on response body
header("Content-Disposition: attachment;filename={$filename}"); header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary"); header("Content-Transfer-Encoding: binary");
} }
if (isset($_REQUEST["column_group"])) { //get the devices and send them as output
if (isset($_REQUEST["column_group"])) {
$columns = implode(",",$_REQUEST["column_group"]);
$sql = "select " . $columns . " from v_devices ";
$sql .= " where domain_uuid = '".$domain_uuid."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$devices = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
unset ($sql, $prep_statement);
//print_r($extensions);
$columns = implode(",",$_REQUEST["column_group"]); download_send_headers("data_export_" . date("Y-m-d") . ".csv");
$sql = "select " . $columns . " from v_devices "; echo array2csv($devices);
$sql .= " where domain_uuid = '".$domain_uuid."' "; die();
$prep_statement = $db->prepare(check_sql($sql)); }
$prep_statement->execute();
$devices = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
unset ($sql, $prep_statement);
// print_r($extensions);
download_send_headers("data_export_" . date("Y-m-d") . ".csv"); //define the columns in the array
echo array2csv($devices); $columns[] = 'device_uuid';
die(); $columns[] = 'domain_uuid';
$columns[] = 'device_mac_address';
$columns[] = 'device_label';
$columns[] = 'device_template';
$columns[] = 'device_description';
} //set the row style
$c = 0;
$columns[] = 'device_uuid'; $row_style["0"] = "row_style0";
$columns[] = 'domain_uuid'; $row_style["1"] = "row_style1";
$columns[] = 'device_mac_address';
$columns[] = 'device_label';
$columns[] = 'device_template';
$columns[] = 'device_description';
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//begin the page content //begin the page content
require_once "resources/header.php"; require_once "resources/header.php";
@@ -105,23 +111,18 @@ $row_style["1"] = "row_style1";
echo "<form method='post' name='frm' action='' autocomplete='off'>\n"; echo "<form method='post' name='frm' action='' autocomplete='off'>\n";
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n"; echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n"; echo "<tr>\n";
echo "<tr>\n"; echo " <th><input type=\"checkbox\" id=\"selecctall\"/></th>\n";
echo "<th><input type=\"checkbox\" id=\"selecctall\"/>"; echo " <th>Column Name</th>\n";
echo "</th>"; echo " <th>Description</th>\n";
echo "<th> Column Name"; echo "</tr>\n";
echo "</th>";
echo "<th> Description";
echo "</th>";
echo "</tr>";
echo "</tr>";
foreach ($columns as $value) { foreach ($columns as $value) {
echo "<tr>\n"; echo "<tr>\n";
echo " <td width = '20px' valign='top' class='".$row_style[$c]."'><input class=\"checkbox1\" type=\"checkbox\" name=\"column_group[]\" value=\"$value\"/>"; echo " <td width = '20px' valign='top' class='".$row_style[$c]."'>\n";
echo "</td>"; echo " <input class=\"checkbox1\" type=\"checkbox\" name=\"column_group[]\" value=\"$value\"/>";
echo " <td valign='top' class='".$row_style[$c]."'> $value"; echo " </td>\n";
echo "</td>"; echo " <td valign='top' class='".$row_style[$c]."'>$value</td>";
echo " <td valign='top' class='".$row_style[$c]."'>"; echo " <td valign='top' class='".$row_style[$c]."'></td>";
echo "</td>";
echo "</tr>"; echo "</tr>";
if ($c==0) { $c=1; } else { $c=0; } if ($c==0) { $c=1; } else { $c=0; }
} }
@@ -139,4 +140,5 @@ $row_style["1"] = "row_style1";
//include the footer //include the footer
require_once "resources/footer.php"; require_once "resources/footer.php";
?> ?>