sql_query_db.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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-2016
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. require_once "root.php";
  22. require_once "resources/require.php";
  23. require_once "resources/check_auth.php";
  24. if (permission_exists('exec_sql')) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. //add multi-lingual support
  32. $language = new text;
  33. $text = $language->get();
  34. require_once "resources/header.php";
  35. $document['title'] = $text['title-databases'];
  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(*) as num_rows from v_databases ";
  59. if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
  60. $prep_statement = $db->prepare($sql);
  61. if ($prep_statement) {
  62. $prep_statement->execute();
  63. $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
  64. $num_rows = ($row['num_rows'] > 0) ? $row['num_rows'] : '0';
  65. }
  66. //prepare to page the results
  67. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  68. $param = "";
  69. $page = $_GET['page'];
  70. if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
  71. list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page);
  72. $offset = $rows_per_page * $page;
  73. //get the list
  74. $sql = "select * from v_databases ";
  75. if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
  76. $sql .= "limit $rows_per_page offset $offset ";
  77. $prep_statement = $db->prepare(check_sql($sql));
  78. $prep_statement->execute();
  79. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  80. $result_count = count($result);
  81. unset ($prep_statement, $sql);
  82. $c = 0;
  83. $row_style["0"] = "row_style0";
  84. $row_style["1"] = "row_style1";
  85. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  86. echo "<tr>\n";
  87. echo th_order_by('database_type', $text['label-type'], $order_by, $order);
  88. echo th_order_by('database_host', $text['label-host'], $order_by, $order);
  89. echo th_order_by('database_name', $text['label-name'], $order_by, $order);
  90. echo th_order_by('database_description', $text['label-description'], $order_by, $order);
  91. echo "<td class='list_control_icons' style='width: 25px;'>&nbsp;</td>\n";
  92. echo "<tr>\n";
  93. if ($result_count > 0) {
  94. foreach($result as $row) {
  95. $tr_link = "href='exec.php?id=".$row['database_uuid']."'";
  96. echo "<tr ".$tr_link.">\n";
  97. echo " <td valign='top' class='".$row_style[$c]."'>".$row['database_type']."&nbsp;</td>\n";
  98. echo " <td valign='top' class='".$row_style[$c]."'>".$row['database_host']."&nbsp;</td>\n";
  99. echo " <td valign='top' class='".$row_style[$c]."'><a href='exec.php?id=".$row['database_uuid']."'>".$row['database_name']."</a>&nbsp;</td>\n";
  100. echo " <td valign='top' class='row_stylebg'>".$row['database_description']."&nbsp;</td>\n";
  101. echo " <td class='list_control_icons' style='width: 25px;'>";
  102. echo " <a href='exec.php?id=".$row['database_uuid']."' alt='".$text['button-edit']."'>".$v_link_label_edit."</a>\n";
  103. echo " </td>\n";
  104. echo "</tr>\n";
  105. $c = ($c == 0) ? 1 : 0;
  106. } //end foreach
  107. unset($sql, $result, $row_count);
  108. } //end if results
  109. echo "</table>";
  110. echo "<br><br>";
  111. //include the footer
  112. require_once "resources/footer.php";
  113. ?>