2012-06-04 16:58:40 +02:00
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
FusionPBX
|
|
|
|
|
Version: MPL 1.1
|
|
|
|
|
|
|
|
|
|
The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
http://www.mozilla.org/MPL/
|
|
|
|
|
|
|
|
|
|
Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
for the specific language governing rights and limitations under the
|
|
|
|
|
License.
|
|
|
|
|
|
|
|
|
|
The Original Code is FusionPBX
|
|
|
|
|
|
|
|
|
|
The Initial Developer of the Original Code is
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
2013-09-28 22:57:57 +02:00
|
|
|
Portions created by the Initial Developer are Copyright (C) 2008-2013
|
2012-06-04 16:58:40 +02:00
|
|
|
the Initial Developer. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
*/
|
|
|
|
|
include "root.php";
|
2013-07-06 08:03:27 +02:00
|
|
|
require_once "resources/require.php";
|
2013-07-06 07:50:55 +02:00
|
|
|
require_once "resources/check_auth.php";
|
2012-06-04 16:58:40 +02:00
|
|
|
if (permission_exists('sql_query_execute')) {
|
|
|
|
|
//access granted
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo "access denied";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 02:11:52 +02:00
|
|
|
//add multi-lingual support
|
|
|
|
|
require_once "app_languages.php";
|
|
|
|
|
foreach($text as $key => $value) {
|
|
|
|
|
$text[$key] = $value[$_SESSION['domain']['language']['code']];
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
//show the header
|
2013-07-06 08:29:50 +02:00
|
|
|
require_once "resources/header.php";
|
2013-06-07 02:11:52 +02:00
|
|
|
$page["title"] = $text['title-sql_query'];
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
//pdo voicemail database connection
|
2012-11-24 03:20:53 +01:00
|
|
|
require_once "sql_query_pdo.php";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
//show the content
|
|
|
|
|
//edit area
|
2013-06-09 06:42:20 +02:00
|
|
|
echo " <script language=\"javascript\" type=\"text/javascript\" src=\"".PROJECT_PATH."/resources/edit_area/edit_area_full.js\"></script>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo " <script language=\"Javascript\" type=\"text/javascript\">\n";
|
|
|
|
|
echo "\n";
|
|
|
|
|
echo " editAreaLoader.init({\n";
|
|
|
|
|
echo " id: \"sql_cmd\" // id of the textarea to transform //, |, help\n";
|
|
|
|
|
echo " ,start_highlight: true\n";
|
|
|
|
|
//echo " ,display: \"later\"\n";
|
|
|
|
|
echo " ,font_size: \"8\"\n";
|
|
|
|
|
echo " ,allow_toggle: false\n";
|
|
|
|
|
echo " ,language: \"en\"\n";
|
|
|
|
|
echo " ,syntax: \"sql\"\n";
|
|
|
|
|
echo " ,toolbar: \"search, go_to_line,|, fullscreen, |, undo, redo, |, select_font, |, syntax_selection, |, change_smooth_selection, highlight, reset_highlight, |, help\" //new_document,\n";
|
|
|
|
|
echo " ,plugins: \"charmap\"\n";
|
|
|
|
|
echo " ,charmap_default: \"arrows\"\n";
|
|
|
|
|
echo "\n";
|
|
|
|
|
echo " });\n";
|
|
|
|
|
echo " </script>";
|
|
|
|
|
|
|
|
|
|
echo "<div align='center'>";
|
|
|
|
|
|
2012-11-24 03:20:53 +01:00
|
|
|
echo "<form method='post' target='frame' action='sql_query_result.php' >";
|
2014-02-26 07:49:42 +01:00
|
|
|
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
echo "<tr>\n";
|
2013-06-07 02:11:52 +02:00
|
|
|
echo "<td align='left' width='30%' nowrap><b>".$text['header-sql_query']."</b></td>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo "<td width='70%' align='right'>\n";
|
2014-04-27 01:56:12 +02:00
|
|
|
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onClick=\"history.back()\" value='".$text['button-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";
|
2012-06-04 16:58:40 +02:00
|
|
|
if (strlen($_REQUEST['id']) > 0) {
|
2013-06-07 02:11:52 +02:00
|
|
|
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";
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2013-06-07 02:11:52 +02:00
|
|
|
echo " <input type='button' class='btn' name='' alt='".$text['button-backup']."' onclick=\"window.location='sql_backup.php'\" value='".$text['button-backup']."'>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
|
|
echo "<tr>\n";
|
2014-02-26 07:49:42 +01:00
|
|
|
echo "<td colspan='2' style='padding: none;' align='left'><br>\n";
|
2014-03-04 17:32:51 +01:00
|
|
|
echo " <textarea name='sql_cmd' id='sql_cmd' rows='10' class='formfld' style='width: 100%;' wrap='off'>$sql_cmd</textarea\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo " <br />\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
|
|
echo " <tr>\n";
|
2014-02-26 07:49:42 +01:00
|
|
|
echo " <td colspan='2' align='right' style='padding-top: 10px;'>\n";
|
2013-06-07 02:11:52 +02:00
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
/*
|
|
|
|
|
echo " DB: <select name='sql_db'>\n";
|
|
|
|
|
echo " <option value=''></option>\n";
|
|
|
|
|
$sql = "";
|
|
|
|
|
$sql .= "select * from v_databases ";
|
|
|
|
|
$sql .= "where domain_uuid = '$domain_uuid' ";
|
|
|
|
|
$prep_statement = $db->prepare(check_sql($sql));
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
foreach ($result as &$row) {
|
|
|
|
|
//$database_type = $row["database_type"];
|
|
|
|
|
//$database_host = $row["database_host"];
|
|
|
|
|
//$database_port = $row["database_port"];
|
|
|
|
|
//$database_name = $row["database_name"];
|
|
|
|
|
//$database_username = $row["database_username"];
|
|
|
|
|
//$database_password = $row["database_password"];
|
|
|
|
|
//$database_path = $row["database_path"];
|
|
|
|
|
//$database_description = $row["database_description"];
|
|
|
|
|
echo " <option value='".$row["database_uuid"]."'>".$row["database_host"]." - ".$row["database_name"]."</option>\n";
|
|
|
|
|
}
|
|
|
|
|
unset ($prep_statement);
|
|
|
|
|
echo " </select>\n";
|
|
|
|
|
*/
|
|
|
|
|
|
2013-06-07 02:11:52 +02:00
|
|
|
|
|
|
|
|
echo " ".$text['label-table'].": \n";
|
2014-02-26 07:49:42 +01:00
|
|
|
echo " <select name='table_name' class='formfld' style='width: auto;'>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo " <option value=''></option>\n";
|
|
|
|
|
if ($db_type == "sqlite") {
|
|
|
|
|
$sql = "SELECT name FROM sqlite_master ";
|
|
|
|
|
$sql .= "WHERE type='table' ";
|
|
|
|
|
$sql .= "order by name;";
|
|
|
|
|
}
|
|
|
|
|
if ($db_type == "pgsql") {
|
|
|
|
|
$sql = "select table_name as name ";
|
|
|
|
|
$sql .= "from information_schema.tables ";
|
|
|
|
|
$sql .= "where table_schema='public' ";
|
|
|
|
|
$sql .= "and table_type='BASE TABLE' ";
|
|
|
|
|
$sql .= "order by table_name ";
|
|
|
|
|
}
|
|
|
|
|
if ($db_type == "mysql") {
|
|
|
|
|
$sql = "show tables";
|
|
|
|
|
}
|
|
|
|
|
$prep_statement = $db->prepare(check_sql($sql));
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
foreach ($result as &$row) {
|
2013-06-15 05:35:15 +02:00
|
|
|
$row = array_values($row);
|
|
|
|
|
echo " <option value='".$row[0]."'>".$row[0]."</option>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
echo " </select>\n";
|
2013-06-07 02:11:52 +02:00
|
|
|
echo " \n";
|
|
|
|
|
echo " \n";
|
2014-02-26 07:49:42 +01:00
|
|
|
echo " ".$text['label-result_type'].": <select name='sql_type' class='formfld' style='width: auto;'>\n";
|
2013-06-07 02:11:52 +02:00
|
|
|
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";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo " <input type='hidden' name='id' value='".$_REQUEST['id']."'>\n";
|
2013-06-07 02:11:52 +02:00
|
|
|
echo " <input type='submit' name='submit' class='btn' value='".$text['button-execute']."'>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo " </td>\n";
|
|
|
|
|
echo " </tr>";
|
2014-02-26 07:49:42 +01:00
|
|
|
echo "</table><br>";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo "</form>";
|
|
|
|
|
|
|
|
|
|
echo "</div>";
|
|
|
|
|
|
2014-02-26 07:49:42 +01:00
|
|
|
echo "<iframe id='frame' height='400' FRAMEBORDER='0' name='frame' style='width: 100%; background-color : #FFFFFF; border: 1px solid #c0c0c0;'></iframe>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
//show the footer
|
2013-07-06 08:29:50 +02:00
|
|
|
require_once "resources/footer.php";
|
2012-06-04 16:58:40 +02:00
|
|
|
?>
|