Multilinguified SQL Query. Added Manage button on Select Database page to link to Databases app. Fixed bug in CSV download file extension.
This commit is contained in:
parent
720b53eb1e
commit
0d9ea1c194
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
//SQL Query
|
||||
|
||||
$text['title-sql_query']['en-us'] = 'SQL Query';
|
||||
$text['title-databases']['en-us'] = 'Databases';
|
||||
|
||||
$text['header-sql_query']['en-us'] = 'SQL Query';
|
||||
$text['header-databases']['en-us'] = 'Databases';
|
||||
|
||||
$text['description-databases']['en-us'] = 'Select the database to use with SQL Query.';
|
||||
|
||||
$text['label-sql_query']['en-us'] = 'SQL Query';
|
||||
$text['label-table']['en-us'] = 'Table';
|
||||
$text['label-result_type']['en-us'] = 'Result';
|
||||
$text['label-results']['en-us'] = 'Results';
|
||||
$text['label-error']['en-us'] = 'Error';
|
||||
$text['label-type']['en-us'] = 'Type';
|
||||
$text['label-host']['en-us'] = 'Host';
|
||||
$text['label-name']['en-us'] = 'Name';
|
||||
$text['label-description']['en-us'] = 'Description';
|
||||
|
||||
$text['option-result_type_view']['en-us'] = 'View';
|
||||
$text['option-result_type_csv']['en-us'] = 'CSV Download';
|
||||
$text['option-result_type_insert']['en-us'] = 'SQL Inserts';
|
||||
|
||||
$text['button-edit']['en-us'] = 'Edit';
|
||||
$text['button-backup']['en-us'] = 'Backup';
|
||||
$text['button-select_database']['en-us'] = 'Select Database';
|
||||
$text['button-back']['en-us'] = 'Back';
|
||||
$text['button-execute']['en-us'] = 'Execute';
|
||||
$text['button-manage']['en-us'] = 'Manage';
|
||||
?>
|
||||
|
|
@ -34,6 +34,12 @@ else {
|
|||
exit;
|
||||
}
|
||||
|
||||
//add multi-lingual support
|
||||
require_once "app_languages.php";
|
||||
foreach($text as $key => $value) {
|
||||
$text[$key] = $value[$_SESSION['domain']['language']['code']];
|
||||
}
|
||||
|
||||
//pdo database connection
|
||||
if (strlen($_REQUEST['id']) > 0) {
|
||||
require_once "sql_query_pdo.php";
|
||||
|
|
@ -69,12 +75,12 @@ else {
|
|||
$sql = "select * from $table_name";
|
||||
if (strlen($sql) > 0) {
|
||||
$prep_statement_2 = $db->prepare(check_sql($sql));
|
||||
if ($prep_statement_2) {
|
||||
if ($prep_statement_2) {
|
||||
$prep_statement_2->execute();
|
||||
$result2 = $prep_statement_2->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
else {
|
||||
echo "<b>Error:</b>\n";
|
||||
echo "<b>".$text['label-error'].":</b>\n";
|
||||
echo "<pre>\n";
|
||||
print_r($db->errorInfo());
|
||||
echo "</pre>\n";
|
||||
|
|
|
|||
|
|
@ -34,6 +34,13 @@ if (if_group("superadmin")) {
|
|||
else {
|
||||
echo "access denied";
|
||||
exit;
|
||||
}
|
||||
|
||||
//add multi-lingual support
|
||||
require_once "app_languages.php";
|
||||
foreach($text as $key => $value) {
|
||||
$text[$key] = $value[$_SESSION['domain']['language']['code']];
|
||||
}
|
||||
|
||||
//show errors
|
||||
ini_set('display_errors', '1');
|
||||
|
|
@ -45,7 +52,7 @@ else {
|
|||
$result = false;
|
||||
foreach ($tmp_array as &$row) {
|
||||
if ($row[0] == $column) {
|
||||
$result = true;
|
||||
$result = true;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
|
@ -95,7 +102,7 @@ else {
|
|||
$db_dest->beginTransaction();
|
||||
}
|
||||
catch (PDOException $error) {
|
||||
print "error: " . $error->getMessage() . "<br/>";
|
||||
print $text['label-error'].": " . $error->getMessage() . "<br/>";
|
||||
die();
|
||||
}
|
||||
|
||||
|
|
@ -116,7 +123,7 @@ else {
|
|||
}
|
||||
}
|
||||
catch (PDOException $error) {
|
||||
echo "error: " . $error->getMessage() . " sql: $sql<br/>";
|
||||
echo $text['label-error'].": " . $error->getMessage() . " sql: $sql<br/>";
|
||||
}
|
||||
$x++;
|
||||
}
|
||||
|
|
@ -140,7 +147,7 @@ else {
|
|||
$db_dest = new PDO("pgsql:host=localhost port={$db_port} user={$db_create_username} password={$db_create_password} dbname=template1");
|
||||
}
|
||||
} catch (PDOException $error) {
|
||||
print "error: " . $error->getMessage() . "<br/>";
|
||||
print $text['label-error'].": " . $error->getMessage() . "<br/>";
|
||||
die();
|
||||
}
|
||||
//create the database, user, grant perms
|
||||
|
|
@ -161,7 +168,7 @@ else {
|
|||
}
|
||||
}
|
||||
catch (PDOException $error) {
|
||||
print "error: " . $error->getMessage() . "<br/>";
|
||||
print $text['label-error'].": " . $error->getMessage() . "<br/>";
|
||||
die();
|
||||
}
|
||||
|
||||
|
|
@ -183,7 +190,7 @@ else {
|
|||
}
|
||||
}
|
||||
catch (PDOException $error) {
|
||||
echo "error: " . $error->getMessage() . " sql: $sql<br/>";
|
||||
echo $text['label-error'].": " . $error->getMessage() . " sql: $sql<br/>";
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
|
@ -232,7 +239,7 @@ else {
|
|||
}
|
||||
catch (PDOException $error) {
|
||||
if ($v_debug) {
|
||||
print "error: " . $error->getMessage() . "<br/>";
|
||||
print $text['label-error'].": " . $error->getMessage() . "<br/>";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -244,7 +251,7 @@ else {
|
|||
}
|
||||
catch (PDOException $error) {
|
||||
if ($v_debug) {
|
||||
print "error: " . $error->getMessage() . "<br/>";
|
||||
print $text['label-error'].": " . $error->getMessage() . "<br/>";
|
||||
}
|
||||
}
|
||||
//create user and set the permissions
|
||||
|
|
@ -254,7 +261,7 @@ else {
|
|||
}
|
||||
catch (PDOException $error) {
|
||||
if ($v_debug) {
|
||||
print "error: " . $error->getMessage() . "<br/>";
|
||||
print $text['label-error'].": " . $error->getMessage() . "<br/>";
|
||||
}
|
||||
}
|
||||
//set account to unlimitted use
|
||||
|
|
@ -266,7 +273,7 @@ else {
|
|||
}
|
||||
catch (PDOException $error) {
|
||||
if ($v_debug) {
|
||||
print "error: " . $error->getMessage() . "<br/>";
|
||||
print $text['label-error'].": " . $error->getMessage() . "<br/>";
|
||||
}
|
||||
}
|
||||
//create the database and set the create user with permissions
|
||||
|
|
@ -276,7 +283,7 @@ else {
|
|||
}
|
||||
catch (PDOException $error) {
|
||||
if ($v_debug) {
|
||||
print "error: " . $error->getMessage() . "<br/>";
|
||||
print $text['label-error'].": " . $error->getMessage() . "<br/>";
|
||||
}
|
||||
}
|
||||
//set user permissions
|
||||
|
|
@ -285,7 +292,7 @@ else {
|
|||
}
|
||||
catch (PDOException $error) {
|
||||
if ($v_debug) {
|
||||
print "error: " . $error->getMessage() . "<br/>";
|
||||
print $text['label-error'].": " . $error->getMessage() . "<br/>";
|
||||
}
|
||||
}
|
||||
//make the changes active
|
||||
|
|
@ -295,7 +302,7 @@ else {
|
|||
}
|
||||
catch (PDOException $error) {
|
||||
if ($v_debug) {
|
||||
print "error: " . $error->getMessage() . "<br/>";
|
||||
print $text['label-error'].": " . $error->getMessage() . "<br/>";
|
||||
}
|
||||
}
|
||||
} //if (strlen($db_create_username) > 0)
|
||||
|
|
@ -305,7 +312,7 @@ else {
|
|||
}
|
||||
catch (PDOException $error) {
|
||||
if ($v_debug) {
|
||||
print "error: " . $error->getMessage() . "<br/>";
|
||||
print $text['label-error'].": " . $error->getMessage() . "<br/>";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -379,7 +386,7 @@ else {
|
|||
$tmp_sql = "PRAGMA table_info($table_name);";
|
||||
}
|
||||
if ($db_dest_type == "pgsql") {
|
||||
|
||||
|
||||
}
|
||||
if ($db_dest_type == "mysql") {
|
||||
$tmp_sql = "show columns from $table_name;";
|
||||
|
|
@ -392,7 +399,7 @@ else {
|
|||
$result2 = $prep_statement_2->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
else {
|
||||
echo "<b>Error:</b>\n";
|
||||
echo "<b>".$text['label-error'].":</b>\n";
|
||||
echo "<pre>\n";
|
||||
print_r($db_dest->errorInfo());
|
||||
echo "</pre>\n";
|
||||
|
|
@ -406,7 +413,7 @@ else {
|
|||
$destination_column_array[$x] = $row2['Field'];
|
||||
}
|
||||
if ($db_dest_type == "pgsql") {
|
||||
|
||||
|
||||
}
|
||||
$x++;
|
||||
}
|
||||
|
|
@ -435,7 +442,7 @@ else {
|
|||
$result2 = $prep_statement_2->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
else {
|
||||
echo "<b>Error:</b>\n";
|
||||
echo "<b>".$text['label-error'].":</b>\n";
|
||||
echo "<pre>\n";
|
||||
print_r($db->errorInfo());
|
||||
echo "</pre>\n";
|
||||
|
|
|
|||
|
|
@ -34,8 +34,15 @@ else {
|
|||
exit;
|
||||
}
|
||||
|
||||
//add multi-lingual support
|
||||
require_once "app_languages.php";
|
||||
foreach($text as $key => $value) {
|
||||
$text[$key] = $value[$_SESSION['domain']['language']['code']];
|
||||
}
|
||||
|
||||
//show the header
|
||||
require_once "includes/header.php";
|
||||
$page["title"] = $text['title-sql_query'];
|
||||
|
||||
//pdo voicemail database connection
|
||||
require_once "sql_query_pdo.php";
|
||||
|
|
@ -70,16 +77,16 @@ else {
|
|||
echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
|
||||
|
||||
echo "<tr>\n";
|
||||
echo "<td align='left' width='30%' nowrap><b>SQL Query</b></td>\n";
|
||||
echo "<td align='left' width='30%' nowrap><b>".$text['header-sql_query']."</b></td>\n";
|
||||
echo "<td width='70%' align='right'>\n";
|
||||
if (strlen($_REQUEST['id']) > 0) {
|
||||
echo " <input type='button' class='btn' name='' alt='backup' onclick=\"window.location='sql_backup.php?id=".$_REQUEST['id']."'\" value='Backup'>\n";
|
||||
echo " <input type='button' class='btn' name='' alt='".$text['button-backup']."' onclick=\"window.location='sql_backup.php?id=".$_REQUEST['id']."'\" value='".$text['button-backup']."'>\n";
|
||||
}
|
||||
else {
|
||||
echo " <input type='button' class='btn' name='' alt='backup' onclick=\"window.location='sql_backup.php'\" value='Backup'>\n";
|
||||
echo " <input type='button' class='btn' name='' alt='".$text['button-backup']."' onclick=\"window.location='sql_backup.php'\" value='".$text['button-backup']."'>\n";
|
||||
}
|
||||
echo " <input type='button' class='btn' name='' alt='backup' onclick=\"window.location='sql_query_db.php'\" value='Database'>\n";
|
||||
echo " <input type='button' class='btn' name='' alt='back' onClick=\"history.back()\" value='Back'>\n";
|
||||
echo " <input type='button' class='btn' name='' alt='".$text['button-select_database']."' onclick=\"window.location='sql_query_db.php'\" value='".$text['button-select_database']."'>\n";
|
||||
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onClick=\"history.back()\" value='".$text['button-back']."'>\n";
|
||||
echo "</td>\n";
|
||||
echo "</tr>\n";
|
||||
|
||||
|
|
@ -92,7 +99,7 @@ else {
|
|||
|
||||
echo " <tr>\n";
|
||||
echo " <td colspan='2' align='right'>\n";
|
||||
|
||||
|
||||
/*
|
||||
echo " DB: <select name='sql_db'>\n";
|
||||
echo " <option value=''></option>\n";
|
||||
|
|
@ -117,14 +124,8 @@ else {
|
|||
echo " </select>\n";
|
||||
*/
|
||||
|
||||
echo " Type: <select name='sql_type'>\n";
|
||||
echo " <option value='default'>default</option>\n";
|
||||
echo " <option value='csv'>csv</option>\n";
|
||||
echo " <option value='sql insert into'>sql insert into</option>\n";
|
||||
echo " </select>\n";
|
||||
echo " \n";
|
||||
echo " \n";
|
||||
echo " Table: \n";
|
||||
|
||||
echo " ".$text['label-table'].": \n";
|
||||
echo " <select name='table_name'>\n";
|
||||
echo " <option value=''></option>\n";
|
||||
if ($db_type == "sqlite") {
|
||||
|
|
@ -149,8 +150,15 @@ else {
|
|||
echo " <option value='".$row['name']."'>".$row['name']."</option>\n";
|
||||
}
|
||||
echo " </select>\n";
|
||||
echo " \n";
|
||||
echo " \n";
|
||||
echo " ".$text['label-result_type'].": <select name='sql_type'>\n";
|
||||
echo " <option value='default'>".$text['option-result_type_view']."</option>\n";
|
||||
echo " <option value='csv'>".$text['option-result_type_csv']."</option>\n";
|
||||
echo " <option value='sql insert into'>".$text['option-result_type_insert']."</option>\n";
|
||||
echo " </select>\n";
|
||||
echo " <input type='hidden' name='id' value='".$_REQUEST['id']."'>\n";
|
||||
echo " <input type='submit' name='submit' class='btn' value='Execute'>\n";
|
||||
echo " <input type='submit' name='submit' class='btn' value='".$text['button-execute']."'>\n";
|
||||
echo " </td>\n";
|
||||
echo " </tr>";
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,16 @@ else {
|
|||
echo "access denied";
|
||||
exit;
|
||||
}
|
||||
|
||||
//add multi-lingual support
|
||||
require_once "app_languages.php";
|
||||
foreach($text as $key => $value) {
|
||||
$text[$key] = $value[$_SESSION['domain']['language']['code']];
|
||||
}
|
||||
|
||||
require_once "includes/header.php";
|
||||
$page["title"] = $text['title-databases'];
|
||||
|
||||
require_once "includes/paging.php";
|
||||
|
||||
//get variables used to control the order
|
||||
|
|
@ -49,12 +58,16 @@ require_once "includes/paging.php";
|
|||
|
||||
echo "<table width='100%' border='0'>\n";
|
||||
echo " <tr>\n";
|
||||
echo " <td width='50%' align=\"left\" nowrap=\"nowrap\"><b>Databases</b></td>\n";
|
||||
echo " <td width='50%' align=\"right\"> </td>\n";
|
||||
echo " <td width='50%' align=\"left\" nowrap=\"nowrap\"><b>".$text['header-databases']."</b></td>\n";
|
||||
echo " <td width='50%' align=\"right\">";
|
||||
if (if_group("superadmin")) {
|
||||
echo " <input type='button' class='btn' name='' alt='".$text['button-manage']."' onclick=\"window.location='/core/databases/databases.php'\" value='".$text['button-manage']."'>\n";
|
||||
}
|
||||
echo " </td>\n";
|
||||
echo " </tr>\n";
|
||||
echo " <tr>\n";
|
||||
echo " <td align=\"left\" colspan='2'>\n";
|
||||
echo " Select the database to use.<br /><br />\n";
|
||||
echo " ".$text['description-databases'].".<br /><br />\n";
|
||||
echo " </td>\n";
|
||||
echo " </tr>\n";
|
||||
echo "</table>\n";
|
||||
|
|
@ -78,9 +91,9 @@ require_once "includes/paging.php";
|
|||
$rows_per_page = 100;
|
||||
$param = "";
|
||||
$page = $_GET['page'];
|
||||
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
|
||||
list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page);
|
||||
$offset = $rows_per_page * $page;
|
||||
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
|
||||
list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page);
|
||||
$offset = $rows_per_page * $page;
|
||||
|
||||
//get the list
|
||||
$sql = "select * from v_databases ";
|
||||
|
|
@ -100,15 +113,11 @@ require_once "includes/paging.php";
|
|||
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
|
||||
|
||||
echo "<tr>\n";
|
||||
echo th_order_by('database_type', 'Type', $order_by, $order);
|
||||
echo th_order_by('database_host', 'Host', $order_by, $order);
|
||||
//echo th_order_by('database_port', 'Port', $order_by, $order);
|
||||
echo th_order_by('database_name', 'Name', $order_by, $order);
|
||||
//echo th_order_by('database_username', 'Username', $order_by, $order);
|
||||
//echo th_order_by('database_path', 'Path', $order_by, $order);
|
||||
echo th_order_by('database_description', 'Description', $order_by, $order);
|
||||
echo th_order_by('database_type', $text['label-type'], $order_by, $order);
|
||||
echo th_order_by('database_host', $text['label-host'], $order_by, $order);
|
||||
echo th_order_by('database_name', $text['label-name'], $order_by, $order);
|
||||
echo th_order_by('database_description', $text['label-description'], $order_by, $order);
|
||||
echo "<td align='right' width='21'>\n";
|
||||
//echo " <a href='database_edit.php' alt='add'>$v_link_label_add</a>\n";
|
||||
echo "</td>\n";
|
||||
echo "<tr>\n";
|
||||
|
||||
|
|
@ -117,13 +126,10 @@ require_once "includes/paging.php";
|
|||
echo "<tr >\n";
|
||||
echo " <td valign='top' class='".$row_style[$c]."'>".$row['database_type']." </td>\n";
|
||||
echo " <td valign='top' class='".$row_style[$c]."'>".$row['database_host']." </td>\n";
|
||||
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['database_port']." </td>\n";
|
||||
echo " <td valign='top' class='".$row_style[$c]."'>".$row['database_name']." </td>\n";
|
||||
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['database_username']." </td>\n";
|
||||
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['database_path']." </td>\n";
|
||||
echo " <td valign='top' class='row_stylebg'>".$row['database_description']." </td>\n";
|
||||
echo " <td valign='top' align='right'>\n";
|
||||
echo " <a href='sql_query.php?id=".$row['database_uuid']."' alt='edit'>$v_link_label_edit</a>\n";
|
||||
echo " <a href='sql_query.php?id=".$row['database_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>\n";
|
||||
echo " </td>\n";
|
||||
echo "</tr>\n";
|
||||
if ($c==0) { $c=1; } else { $c=0; }
|
||||
|
|
|
|||
|
|
@ -34,6 +34,12 @@ else {
|
|||
exit;
|
||||
}
|
||||
|
||||
//add multi-lingual support
|
||||
require_once "app_languages.php";
|
||||
foreach($text as $key => $value) {
|
||||
$text[$key] = $value[$_SESSION['domain']['language']['code']];
|
||||
}
|
||||
|
||||
//pdo database connection
|
||||
if (strlen($_REQUEST['id']) > 0) {
|
||||
require_once "sql_query_pdo.php";
|
||||
|
|
@ -118,7 +124,7 @@ if (count($_POST)>0) {
|
|||
reset($sql_array);
|
||||
foreach($sql_array as $sql) {
|
||||
$sql = trim($sql);
|
||||
echo "<b>SQL Query:</b><br>\n";
|
||||
echo "<b>".$text['label-sql_query'].":</b><br>\n";
|
||||
echo "".$sql."<br /><br />";
|
||||
|
||||
if (strlen($sql) > 0) {
|
||||
|
|
@ -127,10 +133,10 @@ if (count($_POST)>0) {
|
|||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
echo "<b>Results: ".count($result)."</b><br />";
|
||||
echo "<b>".$text['label-results'].": ".count($result)."</b><br />";
|
||||
}
|
||||
catch(PDOException $e) {
|
||||
echo "<b>Error:</b><br />\n";
|
||||
echo "<b>".$text['label-error'].":</b><br />\n";
|
||||
echo "<table>\n";
|
||||
echo "<tr>\n";
|
||||
echo "<td>\n";
|
||||
|
|
@ -170,19 +176,19 @@ if (count($_POST)>0) {
|
|||
echo $tmp_header;
|
||||
|
||||
$sql = trim($sql);
|
||||
echo "<b>SQL Query:</b><br>\n";
|
||||
echo "<b>".$text['label-sql_query'].":</b><br>\n";
|
||||
echo "".$sql."<br /><br />";
|
||||
|
||||
//get the table data
|
||||
$sql = "select * from $table_name";
|
||||
if (strlen($sql) > 0) {
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
if ($prep_statement) {
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
else {
|
||||
echo "<b>Error:</b>\n";
|
||||
echo "<b>".$text['label-error'].":</b>\n";
|
||||
echo "<pre>\n";
|
||||
print_r($db->errorInfo());
|
||||
echo "</pre>\n";
|
||||
|
|
@ -240,19 +246,19 @@ if (count($_POST)>0) {
|
|||
|
||||
//set the headers
|
||||
header('Content-type: application/octet-binary');
|
||||
header('Content-Disposition: attachment; filename='.$table_name.'.sql');
|
||||
header('Content-Disposition: attachment; filename='.$table_name.'.csv');
|
||||
|
||||
//get the table data
|
||||
$sql = trim($sql);
|
||||
$sql = "select * from $table_name";
|
||||
if (strlen($sql) > 0) {
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
if ($prep_statement) {
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
else {
|
||||
echo "<b>Error:</b>\n";
|
||||
echo "<b>".$text['label-error'].":</b>\n";
|
||||
echo "<pre>\n";
|
||||
print_r($db->errorInfo());
|
||||
echo "</pre>\n";
|
||||
|
|
|
|||
Loading…
Reference in New Issue