sql_query_db.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. require_once "root.php";
  22. require_once "includes/require.php";
  23. require_once "resources/check_auth.php";
  24. if (if_group("admin") || if_group("superadmin")) {
  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. require_once "includes/header.php";
  37. $page["title"] = $text['title-databases'];
  38. require_once "includes/paging.php";
  39. //get variables used to control the order
  40. $order_by = $_GET["order_by"];
  41. $order = $_GET["order"];
  42. //show the content
  43. echo "<div align='center'>";
  44. echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
  45. echo "<tr class='border'>\n";
  46. echo " <td align=\"center\">\n";
  47. echo " <br>";
  48. echo "<table width='100%' border='0'>\n";
  49. echo " <tr>\n";
  50. echo " <td width='50%' align=\"left\" nowrap=\"nowrap\"><b>".$text['header-databases']."</b></td>\n";
  51. echo " <td width='50%' align=\"right\">";
  52. if (if_group("superadmin")) {
  53. echo " <input type='button' class='btn' name='' alt='".$text['button-manage']."' onclick=\"window.location='/core/databases/databases.php'\" value='".$text['button-manage']."'>\n";
  54. }
  55. echo " </td>\n";
  56. echo " </tr>\n";
  57. echo " <tr>\n";
  58. echo " <td align=\"left\" colspan='2'>\n";
  59. echo " ".$text['description-databases'].".<br /><br />\n";
  60. echo " </td>\n";
  61. echo " </tr>\n";
  62. echo "</table>\n";
  63. //prepare to page the results
  64. $sql = "select count(*) as num_rows from v_databases ";
  65. if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
  66. $prep_statement = $db->prepare($sql);
  67. if ($prep_statement) {
  68. $prep_statement->execute();
  69. $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
  70. if ($row['num_rows'] > 0) {
  71. $num_rows = $row['num_rows'];
  72. }
  73. else {
  74. $num_rows = '0';
  75. }
  76. }
  77. //prepare to page the results
  78. $rows_per_page = 100;
  79. $param = "";
  80. $page = $_GET['page'];
  81. if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
  82. list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page);
  83. $offset = $rows_per_page * $page;
  84. //get the list
  85. $sql = "select * from v_databases ";
  86. if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
  87. $sql .= "limit $rows_per_page offset $offset ";
  88. $prep_statement = $db->prepare(check_sql($sql));
  89. $prep_statement->execute();
  90. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  91. $result_count = count($result);
  92. unset ($prep_statement, $sql);
  93. $c = 0;
  94. $row_style["0"] = "row_style0";
  95. $row_style["1"] = "row_style1";
  96. echo "<div align='center'>\n";
  97. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  98. echo "<tr>\n";
  99. echo th_order_by('database_type', $text['label-type'], $order_by, $order);
  100. echo th_order_by('database_host', $text['label-host'], $order_by, $order);
  101. echo th_order_by('database_name', $text['label-name'], $order_by, $order);
  102. echo th_order_by('database_description', $text['label-description'], $order_by, $order);
  103. echo "<td align='right' width='21'>\n";
  104. echo "</td>\n";
  105. echo "<tr>\n";
  106. if ($result_count > 0) {
  107. foreach($result as $row) {
  108. echo "<tr >\n";
  109. echo " <td valign='top' class='".$row_style[$c]."'>".$row['database_type']."&nbsp;</td>\n";
  110. echo " <td valign='top' class='".$row_style[$c]."'>".$row['database_host']."&nbsp;</td>\n";
  111. echo " <td valign='top' class='".$row_style[$c]."'>".$row['database_name']."&nbsp;</td>\n";
  112. echo " <td valign='top' class='row_stylebg'>".$row['database_description']."&nbsp;</td>\n";
  113. echo " <td valign='top' align='right'>\n";
  114. echo " <a href='sql_query.php?id=".$row['database_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>\n";
  115. echo " </td>\n";
  116. echo "</tr>\n";
  117. if ($c==0) { $c=1; } else { $c=0; }
  118. } //end foreach
  119. unset($sql, $result, $row_count);
  120. } //end if results
  121. echo "</table>";
  122. echo "</div>";
  123. echo "<br><br>";
  124. echo "<br><br>";
  125. echo "</td>";
  126. echo "</tr>";
  127. echo "</table>";
  128. echo "</div>";
  129. echo "<br><br>";
  130. //include the footer
  131. require_once "includes/footer.php";
  132. ?>