sql_query_db.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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-2025
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes files
  22. require_once dirname(__DIR__, 2) . "/resources/require.php";
  23. require_once "resources/check_auth.php";
  24. //check permissions
  25. if (!permission_exists('sql_query')) {
  26. echo "access denied";
  27. exit;
  28. }
  29. //add multi-lingual support
  30. $language = new text;
  31. $text = $language->get();
  32. //add the header and title
  33. require_once "resources/header.php";
  34. $document['title'] = $text['title-databases'];
  35. //include paging
  36. require_once "resources/paging.php";
  37. //get variables used to control the order
  38. $order_by = $_GET["order_by"] ?? '';
  39. $order = $_GET["order"] ?? '';
  40. //show the content
  41. echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
  42. echo " <tr>\n";
  43. echo " <td width='50%' align='left' nowrap='nowrap'><b>".$text['header-databases']."</b></td>\n";
  44. echo " <td width='50%' align='right'>";
  45. echo " <input type='button' class='btn' alt='".$text['button-back']."' onclick=\"document.location.href='exec.php';\" value='".$text['button-back']."'>\n";
  46. if (if_group("superadmin")) {
  47. echo " <input type='button' class='btn' alt='".$text['button-manage']."' onclick=\"document.location.href='/core/databases/databases.php';\" value='".$text['button-manage']."'>\n";
  48. }
  49. echo " </td>\n";
  50. echo " </tr>\n";
  51. echo " <tr>\n";
  52. echo " <td align='left' colspan='2'>\n";
  53. echo " ".$text['description-databases'].".<br /><br />\n";
  54. echo " </td>\n";
  55. echo " </tr>\n";
  56. echo "</table>\n";
  57. //prepare to page the results
  58. $sql = "select count(*) from v_databases ";
  59. $database = new database;
  60. $num_rows = $database->select($sql, null, 'column');
  61. //prepare to page the results
  62. $rows_per_page = $settings->get('domain','paging',50);
  63. $param = "";
  64. $page = $_GET['page'];
  65. if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
  66. list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page);
  67. $offset = $rows_per_page * $page;
  68. //get the list
  69. $sql = str_replace('count(*)', '*', $sql);
  70. $sql .= order_by($order_by, $order);
  71. $sql .= limit_offset($rows_per_page, $offset);
  72. $database = new database;
  73. $result = $database->select($sql, null, 'all');
  74. unset($sql);
  75. $c = 0;
  76. $row_style["0"] = "row_style0";
  77. $row_style["1"] = "row_style1";
  78. echo "<div class='card'>\n";
  79. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  80. echo "<tr>\n";
  81. echo th_order_by('database_type', $text['label-type'], $order_by, $order);
  82. echo th_order_by('database_host', $text['label-host'], $order_by, $order);
  83. echo th_order_by('database_name', $text['label-name'], $order_by, $order);
  84. echo th_order_by('database_description', $text['label-description'], $order_by, $order);
  85. echo "<td class='list_control_icons' style='width: 25px;'>&nbsp;</td>\n";
  86. echo "<tr>\n";
  87. if (is_array($result) && @sizeof($result) != 0) {
  88. foreach($result as $row) {
  89. $tr_link = "href='exec.php?id=".escape($row['database_uuid'])."'";
  90. echo "<tr ".$tr_link.">\n";
  91. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['database_type'])."&nbsp;</td>\n";
  92. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['database_host'])."&nbsp;</td>\n";
  93. echo " <td valign='top' class='".$row_style[$c]."'><a href='exec.php?id=".escape($row['database_uuid'])."'>".escape($row['database_name'])."</a>&nbsp;</td>\n";
  94. echo " <td valign='top' class='row_stylebg'>".escape($row['database_description'])."&nbsp;</td>\n";
  95. echo " <td class='list_control_icons' style='width: 25px;'>";
  96. echo " <a href='exec.php?id=".escape($row['database_uuid'])."' alt='".$text['button-edit']."'>".$v_link_label_edit."</a>\n";
  97. echo " </td>\n";
  98. echo "</tr>\n";
  99. $c = ($c == 0) ? 1 : 0;
  100. }
  101. }
  102. unset($result, $row);
  103. echo "</table>";
  104. echo "</div>\n";
  105. echo "<br><br>";
  106. //include the footer
  107. require_once "resources/footer.php";