databases.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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-2020
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes
  22. require_once "root.php";
  23. require_once "resources/require.php";
  24. require_once "resources/check_auth.php";
  25. require_once "resources/paging.php";
  26. //check permissions
  27. if (permission_exists('database_view')) {
  28. //access granted
  29. }
  30. else {
  31. echo "access denied";
  32. exit;
  33. }
  34. //add multi-lingual support
  35. $language = new text;
  36. $text = $language->get();
  37. //get the http post data
  38. if (is_array($_POST['databases'])) {
  39. $action = $_POST['action'];
  40. $databases = $_POST['databases'];
  41. }
  42. //process the http post data by action
  43. if ($action != '' && is_array($databases) && @sizeof($databases) != 0) {
  44. switch ($action) {
  45. case 'copy':
  46. if (permission_exists('database_add')) {
  47. $obj = new databases;
  48. $obj->copy($databases);
  49. }
  50. break;
  51. case 'delete':
  52. if (permission_exists('database_delete')) {
  53. $obj = new databases;
  54. $obj->delete($databases);
  55. }
  56. break;
  57. }
  58. header('Location: databases.php');
  59. exit;
  60. }
  61. //get variables used to control the order
  62. $order_by = $_GET["order_by"];
  63. $order = $_GET["order"];
  64. //prepare to page the results
  65. $sql = "select count(*) from v_databases ";
  66. $database = new database;
  67. $num_rows = $database->select($sql, null, 'column');
  68. //prepare to page the results
  69. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  70. $param = "";
  71. $page = is_numeric($_GET['page']) ? $_GET['page'] : 0;
  72. list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
  73. $offset = $rows_per_page * $page;
  74. //get the list
  75. $sql = str_replace('count(*)', '*', $sql);
  76. $sql .= order_by($order_by, $order);
  77. $sql .= limit_offset($rows_per_page, $offset);
  78. $database = new database;
  79. $databases = $database->select($sql, null, 'all');
  80. unset($sql);
  81. //create token
  82. $object = new token;
  83. $token = $object->create($_SERVER['PHP_SELF']);
  84. //include the header
  85. $document['title'] = $text['title-databases'];
  86. require_once "resources/header.php";
  87. //show the content
  88. echo "<div class='action_bar' id='action_bar'>\n";
  89. echo " <div class='heading'><b>".$text['header-databases']." (".$num_rows.")</b></div>\n";
  90. echo " <div class='actions'>\n";
  91. if (permission_exists('database_add')) {
  92. echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'link'=>'database_edit.php']);
  93. }
  94. if (permission_exists('database_add') && $databases) {
  95. echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'onclick'=>"if (confirm('".$text['confirm-copy']."')) { list_action_set('copy'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
  96. }
  97. if (permission_exists('database_delete') && $databases) {
  98. echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'onclick'=>"if (confirm('".$text['confirm-delete']."')) { list_action_set('delete'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
  99. }
  100. echo " </div>\n";
  101. echo " <div style='clear: both;'></div>\n";
  102. echo "</div>\n";
  103. echo $text['description-databases']."\n";
  104. echo "<br /><br />\n";
  105. echo "<form id='form_list' method='post'>\n";
  106. echo "<input type='hidden' id='action' name='action' value=''>\n";
  107. echo "<table class='list'>\n";
  108. echo "<tr class='list-header'>\n";
  109. if (permission_exists('database_add') || permission_exists('database_delete')) {
  110. echo " <th class='checkbox'>\n";
  111. echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle();' ".($databases ?: "style='visibility: hidden;'").">\n";
  112. echo " </th>\n";
  113. }
  114. echo th_order_by('database_driver', $text['label-driver'], $order_by, $order);
  115. echo th_order_by('database_type', $text['label-type'], $order_by, $order);
  116. echo th_order_by('database_host', $text['label-host'], $order_by, $order);
  117. echo th_order_by('database_name', $text['label-name'], $order_by, $order);
  118. echo th_order_by('database_description', $text['label-description'], $order_by, $order, null, "class='hide-sm-dn'");
  119. if (permission_exists('database_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  120. echo " <td class='action-button'>&nbsp;</td>\n";
  121. }
  122. echo "</tr>\n";
  123. if (is_array($databases) && @sizeof($databases) != 0) {
  124. $x = 0;
  125. foreach ($databases as $row) {
  126. $list_row_url = "database_edit.php?id=".urlencode($row['database_uuid']);
  127. echo "<tr class='list-row' href='".$list_row_url."'>\n";
  128. if (permission_exists('database_add') || permission_exists('database_delete')) {
  129. echo " <td class='checkbox'>\n";
  130. echo " <input type='checkbox' name='databases[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
  131. echo " <input type='hidden' name='databases[$x][uuid]' value='".escape($row['database_uuid'])."' />\n";
  132. echo " </td>\n";
  133. }
  134. echo " <td>".escape($row['database_driver'])."&nbsp;</td>\n";
  135. echo " <td>".escape($row['database_type'])."&nbsp;</td>\n";
  136. echo " <td>".escape($row['database_host'])."&nbsp;</td>\n";
  137. echo " <td>";
  138. if (permission_exists('database_edit')) {
  139. echo "<a href='".$list_row_url."'>".escape($row['database_name'])."</a>";
  140. }
  141. else {
  142. echo escape($row['database_name']);
  143. }
  144. echo " </td>\n";
  145. echo " <td class='description overflow hide-sm-dn'>".escape($row['database_description'])."&nbsp;</td>\n";
  146. if (permission_exists('database_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  147. echo " <td class='action-button'>\n";
  148. echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
  149. echo " </td>\n";
  150. }
  151. echo "</tr>\n";
  152. $x++;
  153. }
  154. unset($databases);
  155. }
  156. echo "</table>\n";
  157. echo "<br />\n";
  158. echo "<div align='center'>".$paging_controls."</div>\n";
  159. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  160. echo "</form>\n";
  161. //include the footer
  162. require_once "resources/footer.php";
  163. ?>