sql_query.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2012
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. include "root.php";
  22. require_once "includes/require.php";
  23. require_once "resources/check_auth.php";
  24. if (permission_exists('sql_query_execute')) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. //add multi-lingual support
  32. require_once "app_languages.php";
  33. foreach($text as $key => $value) {
  34. $text[$key] = $value[$_SESSION['domain']['language']['code']];
  35. }
  36. //show the header
  37. require_once "includes/header.php";
  38. $page["title"] = $text['title-sql_query'];
  39. //pdo voicemail database connection
  40. require_once "sql_query_pdo.php";
  41. //show the content
  42. //edit area
  43. echo " <script language=\"javascript\" type=\"text/javascript\" src=\"".PROJECT_PATH."/resources/edit_area/edit_area_full.js\"></script>\n";
  44. echo " <script language=\"Javascript\" type=\"text/javascript\">\n";
  45. echo "\n";
  46. echo " editAreaLoader.init({\n";
  47. echo " id: \"sql_cmd\" // id of the textarea to transform //, |, help\n";
  48. echo " ,start_highlight: true\n";
  49. //echo " ,display: \"later\"\n";
  50. echo " ,font_size: \"8\"\n";
  51. echo " ,allow_toggle: false\n";
  52. echo " ,language: \"en\"\n";
  53. echo " ,syntax: \"sql\"\n";
  54. echo " ,toolbar: \"search, go_to_line,|, fullscreen, |, undo, redo, |, select_font, |, syntax_selection, |, change_smooth_selection, highlight, reset_highlight, |, help\" //new_document,\n";
  55. echo " ,plugins: \"charmap\"\n";
  56. echo " ,charmap_default: \"arrows\"\n";
  57. echo "\n";
  58. echo " });\n";
  59. echo " </script>";
  60. echo "<div align='center'>";
  61. echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
  62. echo "<tr class='border'>\n";
  63. echo " <td align=\"left\">\n";
  64. echo " <br>";
  65. echo "<form method='post' target='frame' action='sql_query_result.php' >";
  66. echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
  67. echo "<tr>\n";
  68. echo "<td align='left' width='30%' nowrap><b>".$text['header-sql_query']."</b></td>\n";
  69. echo "<td width='70%' align='right'>\n";
  70. if (strlen($_REQUEST['id']) > 0) {
  71. 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";
  72. }
  73. else {
  74. echo " <input type='button' class='btn' name='' alt='".$text['button-backup']."' onclick=\"window.location='sql_backup.php'\" value='".$text['button-backup']."'>\n";
  75. }
  76. 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";
  77. echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onClick=\"history.back()\" value='".$text['button-back']."'>\n";
  78. echo "</td>\n";
  79. echo "</tr>\n";
  80. echo "<tr>\n";
  81. echo "<td colspan='2' class='vtable' align='left'>\n";
  82. echo " <textarea name='sql_cmd' id='sql_cmd' rows='7' class='txt' wrap='off'>$sql_cmd</textarea\n";
  83. echo " <br />\n";
  84. echo "</td>\n";
  85. echo "</tr>\n";
  86. echo " <tr>\n";
  87. echo " <td colspan='2' align='right'>\n";
  88. /*
  89. echo " DB: <select name='sql_db'>\n";
  90. echo " <option value=''></option>\n";
  91. $sql = "";
  92. $sql .= "select * from v_databases ";
  93. $sql .= "where domain_uuid = '$domain_uuid' ";
  94. $prep_statement = $db->prepare(check_sql($sql));
  95. $prep_statement->execute();
  96. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  97. foreach ($result as &$row) {
  98. //$database_type = $row["database_type"];
  99. //$database_host = $row["database_host"];
  100. //$database_port = $row["database_port"];
  101. //$database_name = $row["database_name"];
  102. //$database_username = $row["database_username"];
  103. //$database_password = $row["database_password"];
  104. //$database_path = $row["database_path"];
  105. //$database_description = $row["database_description"];
  106. echo " <option value='".$row["database_uuid"]."'>".$row["database_host"]." - ".$row["database_name"]."</option>\n";
  107. }
  108. unset ($prep_statement);
  109. echo " </select>\n";
  110. */
  111. echo " ".$text['label-table'].": \n";
  112. echo " <select name='table_name'>\n";
  113. echo " <option value=''></option>\n";
  114. if ($db_type == "sqlite") {
  115. $sql = "SELECT name FROM sqlite_master ";
  116. $sql .= "WHERE type='table' ";
  117. $sql .= "order by name;";
  118. }
  119. if ($db_type == "pgsql") {
  120. $sql = "select table_name as name ";
  121. $sql .= "from information_schema.tables ";
  122. $sql .= "where table_schema='public' ";
  123. $sql .= "and table_type='BASE TABLE' ";
  124. $sql .= "order by table_name ";
  125. }
  126. if ($db_type == "mysql") {
  127. $sql = "show tables";
  128. }
  129. $prep_statement = $db->prepare(check_sql($sql));
  130. $prep_statement->execute();
  131. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  132. foreach ($result as &$row) {
  133. $row = array_values($row);
  134. echo " <option value='".$row[0]."'>".$row[0]."</option>\n";
  135. }
  136. echo " </select>\n";
  137. echo " &nbsp;\n";
  138. echo " &nbsp;\n";
  139. echo " ".$text['label-result_type'].": <select name='sql_type'>\n";
  140. echo " <option value='default'>".$text['option-result_type_view']."</option>\n";
  141. echo " <option value='csv'>".$text['option-result_type_csv']."</option>\n";
  142. echo " <option value='sql insert into'>".$text['option-result_type_insert']."</option>\n";
  143. echo " </select>\n";
  144. echo " <input type='hidden' name='id' value='".$_REQUEST['id']."'>\n";
  145. echo " <input type='submit' name='submit' class='btn' value='".$text['button-execute']."'>\n";
  146. echo " </td>\n";
  147. echo " </tr>";
  148. echo "</table>";
  149. echo "</form>";
  150. echo " </td>";
  151. echo " </tr>";
  152. echo "</table>";
  153. echo "</div>";
  154. echo "<iframe id='frame' width='100%' height='400' FRAMEBORDER='0' name='frame' style='background-color : #FFFFFF;'></iframe>\n";
  155. //show the footer
  156. include "includes/require.php";
  157. require_once "includes/footer.php";
  158. ?>