Update sql_query_result.php

Prevent warnings.
This commit is contained in:
FusionPBX
2017-01-19 11:50:30 -07:00
committed by GitHub
parent 4eb8d5c53f
commit 87e481d285

View File

@@ -17,22 +17,26 @@
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";
if (permission_exists('exec_sql')) { require_once "resources/require.php";
//access granted require_once "resources/check_auth.php";
}
else { //check permissions
echo "access denied"; if (permission_exists('exec_sql')) {
exit; //access granted
} }
else {
echo "access denied";
exit;
}
//add multi-lingual support //add multi-lingual support
$language = new text; $language = new text;
@@ -121,7 +125,7 @@ if (count($_POST)>0) {
$show_query = (sizeof($sql_array) > 1) ? true : false; $show_query = (sizeof($sql_array) > 1) ? true : false;
reset($sql_array); reset($sql_array);
foreach($sql_array as $sql_index => $sql) { if (is_array($sql_array)) foreach($sql_array as $sql_index => $sql) {
$sql = trim($sql); $sql = trim($sql);
if (sizeof($sql_array) > 1 || $show_query) { if (sizeof($sql_array) > 1 || $show_query) {
@@ -147,20 +151,25 @@ if (count($_POST)>0) {
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n"; echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
$x = 0; $x = 0;
foreach ($result[0] as $key => $value) { if (is_array($result[0])) {
echo "<th>".$key."</th>"; foreach ($result[0] as $key => $value) {
$column_array[$x++] = $key; echo "<th>".$key."</th>";
} $column_array[$x++] = $key;
}
$x = 1; }
foreach ($result as &$row) { $x = 1;
if ($x++ > 1000) { break; } if (is_array($result)) {
echo "<tr>\n"; foreach ($result as &$row) {
foreach ($column_array as $column_index => $column) { if ($x++ > 1000) { break; }
echo "<td class='".$row_style[$c]."' ".(($column_index == 0) ? "style='border-left: none;'" : null).">".$row[$column]."&nbsp;</td>"; echo "<tr>\n";
if (is_array($column_array)) {
foreach ($column_array as $column_index => $column) {
echo "<td class='".$row_style[$c]."' ".(($column_index == 0) ? "style='border-left: none;'" : null).">".$row[$column]."&nbsp;</td>";
}
}
echo "</tr>\n";
$c = ($c == 0) ? 1 : 0;
} }
echo "</tr>\n";
$c = ($c == 0) ? 1 : 0;
} }
echo "</table>\n"; echo "</table>\n";
echo "<br>\n"; echo "<br>\n";
@@ -193,31 +202,36 @@ if (count($_POST)>0) {
} }
$x = 0; $x = 0;
foreach ($result[0] as $key => $value) { if (is_array($result[0])) {
$column_array[$x++] = $key; foreach ($result[0] as $key => $value) {
$column_array[$x++] = $key;
}
} }
$column_array_count = count($column_array); $column_array_count = count($column_array);
if (is_array($result)) foreach ($result as &$row) {
foreach ($result as &$row) {
echo "insert into ".$table_name." ("; echo "insert into ".$table_name." (";
$x = 1; $x = 1;
foreach ($column_array as $column) { if (is_array($column_array)) {
if ($column != "menuid" && $column != "menuparentid") { foreach ($column_array as $column) {
$columns[] = $column; if ($column != "menuid" && $column != "menuparentid") {
$columns[] = $column;
}
$x++;
} }
$x++;
} }
if (is_array($columns) && sizeof($columns) > 0) { if (is_array($columns) && sizeof($columns) > 0) {
echo implode(', ', $columns); echo implode(', ', $columns);
} }
echo ") values ("; echo ") values (";
$x = 1; $x = 1;
foreach ($column_array as $column) { if (is_array($column_array)) {
if ($column != "menuid" && $column != "menuparentid") { foreach ($column_array as $column) {
$values[] = ($row[$column] != '') ? "'".check_str($row[$column])."'" : 'null'; if ($column != "menuid" && $column != "menuparentid") {
$values[] = ($row[$column] != '') ? "'".check_str($row[$column])."'" : 'null';
}
$x++;
} }
$x++;
} }
if (is_array($values) && sizeof($values) > 0) { if (is_array($values) && sizeof($values) > 0) {
echo implode(', ', $values); echo implode(', ', $values);
@@ -253,18 +267,22 @@ if (count($_POST)>0) {
} }
$x = 0; $x = 0;
foreach ($result[0] as $key => $value) { if (is_array($result[0])) {
$column_array[$x++] = $key; foreach ($result[0] as $key => $value) {
$column_array[$x++] = $key;
}
} }
//column names //column names
echo '"'.implode('","', $column_array).'"'."\r\n"; echo '"'.implode('","', $column_array).'"'."\r\n";
//column values //column values
foreach ($result as &$row) { if (is_array($result)) {
$x = 1; foreach ($result as &$row) {
foreach ($column_array as $column) { $x = 1;
echo '"'.check_str($row[$column]).'"'.(($x++ < count($column_array)) ? ',' : null); foreach ($column_array as $column) {
echo '"'.check_str($row[$column]).'"'.(($x++ < count($column_array)) ? ',' : null);
}
echo "\n";
} }
echo "\n";
} }
} }
} }