Fork of FusionPBX but with LDAP kinda working
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
8.3 KiB

2 years ago
  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 <markjcrane@fusionpbx.com>
  16. Portions created by the Initial Developer are Copyright (C) 2016 - 2021
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <markjcrane@fusionpbx.com>
  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_transaction_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 variables used to control the order
  38. $order_by = $_GET["order_by"];
  39. $order = $_GET["order"];
  40. //add the user filter and search term
  41. $user_uuid = $_GET['user_uuid'];
  42. $search = strtolower($_GET["search"]);
  43. if ($search != '') {
  44. $sql_search = "and (";
  45. $sql_search .= " lower(t.app_name) like :search ";
  46. $sql_search .= " or lower(t.transaction_code) like :search ";
  47. $sql_search .= " or lower(t.transaction_address) like :search ";
  48. $sql_search .= " or lower(t.transaction_type) like :search ";
  49. $sql_search .= " or cast(t.transaction_date as text) like :search ";
  50. $sql_search .= " or lower(t.transaction_old) like :search ";
  51. $sql_search .= " or lower(t.transaction_new) like :search ";
  52. $sql_search .= " or lower(u.username) like :search ";
  53. $sql_search .= ") ";
  54. $parameters['search'] = '%'.$search.'%';
  55. }
  56. //prepare to page the results
  57. $sql = "select count(t.database_transaction_uuid) from v_database_transactions as t ";
  58. $sql .= "left outer join v_domains as d using (domain_uuid) ";
  59. $sql .= "left outer join v_users as u using (user_uuid) ";
  60. $sql .= "where t.domain_uuid = :domain_uuid ";
  61. if (is_uuid($user_uuid)) {
  62. $sql .= "and t.user_uuid = :user_uuid ";
  63. $parameters['user_uuid'] = $user_uuid;
  64. }
  65. $sql .= $sql_search;
  66. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  67. $database = new database;
  68. $num_rows = $database->select($sql, $parameters, 'column');
  69. //prepare to page the results
  70. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  71. $param = "search=".$search;
  72. $page = $_GET['page'];
  73. if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
  74. list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
  75. list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
  76. $offset = $rows_per_page * $page;
  77. //get the list
  78. $sql = str_replace('count(t.database_transaction_uuid)','t.database_transaction_uuid, d.domain_name, u.username, t.user_uuid, t.app_name, t.app_uuid, t.transaction_code, t.transaction_address, t.transaction_type, t.transaction_date', $sql);
  79. $sql .= order_by($order_by, $order, 't.transaction_date', 'desc');
  80. $sql .= limit_offset($rows_per_page, $offset);
  81. $database = new database;
  82. $result = $database->select($sql, $parameters, 'all');
  83. unset($sql, $parameters);
  84. //get users
  85. $sql = "select user_uuid, username from v_users ";
  86. $sql .= "where domain_uuid = :domain_uuid ";
  87. $sql .= "order by username ";
  88. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  89. $database = new database;
  90. $rows = $database->select($sql, $parameters, 'all');
  91. if (is_array($rows) && @sizeof($rows) != 0) {
  92. foreach ($rows as $row) {
  93. $users[$row['user_uuid']] = $row['username'];
  94. }
  95. }
  96. unset($sql, $parameters, $rows, $row);
  97. //additional includes
  98. $document['title'] = $text['title-database_transactions'];
  99. require_once "resources/header.php";
  100. //show the content
  101. echo "<div class='action_bar' id='action_bar'>\n";
  102. echo " <div class='heading'><b>".$text['title-database_transactions']." (".$num_rows.")</b></div>\n";
  103. echo " <div class='actions'>\n";
  104. echo "<form id='form_search' class='inline' method='get'>\n";
  105. if (is_array($users) && @sizeof($users) != 0) {
  106. echo "<select class='formfld' name='user_uuid' onchange=\"document.getElementById('form_search').submit();\">\n";
  107. echo " <option value=''>".$text['label-user']."...</option>\n";
  108. echo " <option value=''>".$text['label-all']."</option>\n";
  109. foreach ($users as $uuid => $username) {
  110. $selected = $user_uuid == $uuid ? "selected='selected'" : null;
  111. echo " <option value='".escape($uuid)."' ".$selected.">".escape($username)."</option>\n";
  112. }
  113. echo " </select>";
  114. }
  115. echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
  116. echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search']);
  117. //echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','onclick'=>"document.getElementById('search').value = ''; document.getElementById('form_search').submit();",'style'=>(!$search ? 'display: none;' : null)]);
  118. if ($paging_controls_mini != '') {
  119. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>";
  120. }
  121. echo " </form>\n";
  122. echo " </div>\n";
  123. echo " <div style='clear: both;'></div>\n";
  124. echo "</div>\n";
  125. echo $text['description-database_transactions']."\n";
  126. echo "<br /><br />\n";
  127. echo "<table class='list'>\n";
  128. echo "<tr class='list-header'>\n";
  129. echo th_order_by('domain_name', $text['label-domain'], $order_by, $order);
  130. echo th_order_by('username', $text['label-user_uuid'], $order_by, $order);
  131. echo th_order_by('app_name', $text['label-app_name'], $order_by, $order);
  132. echo th_order_by('transaction_code', $text['label-transaction_code'], $order_by, $order);
  133. echo th_order_by('transaction_address', $text['label-transaction_address'], $order_by, $order);
  134. echo th_order_by('transaction_type', $text['label-transaction_type'], $order_by, $order);
  135. echo th_order_by('transaction_date', $text['label-transaction_date'], $order_by, $order);
  136. //echo th_order_by('transaction_old', $text['label-transaction_old'], $order_by, $order);
  137. //echo th_order_by('transaction_new', $text['label-transaction_new'], $order_by, $order);
  138. //echo th_order_by('transaction_result', $text['label-transaction_result'], $order_by, $order);
  139. if (permission_exists('database_transaction_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  140. echo " <td class='action-button'>&nbsp;</td>\n";
  141. }
  142. echo "</tr>\n";
  143. if (is_array($result)) {
  144. $x = 0;
  145. foreach($result as $row) {
  146. if (permission_exists('database_transaction_edit')) {
  147. $list_row_url = "database_transaction_edit.php?id=".urlencode($row['database_transaction_uuid']).($page != '' ? "&page=".urlencode($page) : null).($search != '' ? "&search=".urlencode($search) : null);
  148. }
  149. echo "<tr class='list-row' href='".$list_row_url."'>\n";
  150. echo " <td>".escape($row['domain_name'])."&nbsp;</td>\n";
  151. echo " <td>".escape($row['username'])."&nbsp;</td>\n";
  152. echo " <td><a href='".$list_row_url."'>".escape($row['app_name'])."</a>&nbsp;</td>\n";
  153. echo " <td>".escape($row['transaction_code'])."&nbsp;</td>\n";
  154. echo " <td>".escape($row['transaction_address'])."&nbsp;</td>\n";
  155. echo " <td>".escape($row['transaction_type'])."&nbsp;</td>\n";
  156. echo " <td>".escape($row['transaction_date'])."&nbsp;</td>\n";
  157. //echo " <td>".escape($row['transaction_old']."&nbsp;</td>\n";
  158. //echo " <td>".escape($row['transaction_new']."&nbsp;</td>\n";
  159. //echo " <td>".escape($row['transaction_result']."&nbsp;</td>\n";
  160. if (permission_exists('database_transaction_edit')) {
  161. echo " <td class='action-button'>";
  162. echo button::create(['type'=>'button','title'=>$text['button-view'],'icon'=>$_SESSION['theme']['button_icon_view'],'link'=>$list_row_url]);
  163. echo " </td>\n";
  164. }
  165. echo "</tr>\n";
  166. $x++;
  167. }
  168. unset($result);
  169. }
  170. echo "</table>\n";
  171. echo "<br />\n";
  172. echo "<div align='center'>".$paging_controls."</div>\n";
  173. //include the footer
  174. require_once "resources/footer.php";
  175. ?>