databases.php 8.2 KB

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