domain_counts_accountcodes.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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-2023
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. KonradSC <[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. //include the class
  26. require_once "resources/check_auth.php";
  27. //check permissions
  28. require_once "resources/check_auth.php";
  29. if (permission_exists('domain_counts_view')) {
  30. //access granted
  31. }
  32. else {
  33. echo "access denied";
  34. exit;
  35. }
  36. //add multi-lingual support
  37. $language = new text;
  38. $text = $language->get();
  39. //get the http values and set them as variables
  40. $domain_uuid = check_str($_GET["id"]);
  41. $order_by = check_str($_GET["order_by"]);
  42. $order = check_str($_GET["order"]);
  43. //handle search term
  44. $search = check_str($_GET["search"]);
  45. if (strlen($search) > 0) {
  46. $sql_mod = "and accountcode ILIKE '%".$search."%' ";
  47. }
  48. if (strlen($order_by) < 1) {
  49. $order_by = "accountcode";
  50. $order = "ASC";
  51. }
  52. //get total accountcode count from the database
  53. $sql = "select count(DISTINCT accountcode) as num_rows from v_extensions where domain_uuid = '".$domain_uuid."' ".$sql_mod." ";
  54. $database = new database;
  55. $numeric_accountcodes = $database->select($sql, null, 'column');
  56. $total_accountcodes = $numeric_accountcodes;
  57. unset($sql);
  58. //prepare to page the results
  59. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  60. $param = "&search=".$search."&id=".$domain_uuid."&order_by=".$order_by."&order=".$order;
  61. if (!isset($_GET['page'])) { $_GET['page'] = 0; }
  62. $_GET['page'] = check_str($_GET['page']);
  63. list($paging_controls_mini, $rows_per_page, $var_3) = paging($total_accountcodes, $param, $rows_per_page, true); //top
  64. list($paging_controls, $rows_per_page, $var_3) = paging($total_accountcodes, $param, $rows_per_page); //bottom
  65. $offset = $rows_per_page * $_GET['page'];
  66. //get the domain name from the database
  67. $sql = "SELECT domain_name \n";
  68. $sql .= "FROM v_domains \n";
  69. $sql .= "WHERE domain_uuid = '$domain_uuid' \n";
  70. $database = new database;
  71. $result = $database->select($sql, null);
  72. $domain_result = $database->result;
  73. unset($database,$result);
  74. //get all the accountcodes from the database
  75. $sql = "SELECT accountcode, count(*) AS count \n";
  76. $sql .= "FROM v_extensions \n";
  77. $sql .= "WHERE domain_uuid = '$domain_uuid' and accountcode is not null \n";
  78. $sql .= $sql_mod; //add search mod from above
  79. $sql .= "GROUP BY accountcode ";
  80. $sql .= "ORDER BY ".$order_by." ".$order." \n";
  81. $sql .= "limit $rows_per_page offset $offset ";
  82. $database = new database;
  83. $directory = $database->select($sql, null);
  84. unset($database);
  85. //set the http header
  86. if ($_REQUEST['type'] == "csv") {
  87. //set the headers
  88. header('Content-type: application/octet-binary');
  89. header("Content-Disposition: attachment; filename='".$domain_result[0][domain_name]."_accountcodes" . date("Y-m-d") . ".csv'");
  90. //show the column names on the first line
  91. $z = 0;
  92. foreach($directory[1] as $key => $val) {
  93. if ($z == 0) {
  94. echo '"'.$key.'"';
  95. }
  96. else {
  97. echo ',"'.$key.'"';
  98. }
  99. $z++;
  100. }
  101. echo "\n";
  102. //add the values to the csv
  103. $x = 0;
  104. foreach($directory as $codes) {
  105. $z = 0;
  106. foreach($codes as $key => $val) {
  107. if ($z == 0) {
  108. echo '"'.$directory[$x][$key].'"';
  109. }
  110. else {
  111. echo ',"'.$directory[$x][$key].'"';
  112. }
  113. $z++;
  114. }
  115. echo "\n";
  116. $x++;
  117. }
  118. exit;
  119. }
  120. //additional includes
  121. require_once "resources/header.php";
  122. $document['title'] = $text['title-domain_counts_accountcodes'];
  123. //set the alternating styles
  124. $c = 0;
  125. $row_style["0"] = "row_style0";
  126. $row_style["1"] = "row_style1";
  127. //show the content
  128. echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
  129. echo " <tr>\n";
  130. echo " <td align='left' width='100%'>\n";
  131. echo " <b>".$text['header-domain_counts_accountcodes'].": ".$domain_result[0][domain_name]." (".$numeric_accountcodes.")</b><br>\n";
  132. echo " </td>\n";
  133. echo " <td align='right' width='100%' style='vertical-align: top;'>";
  134. echo " <form method='get' action=''>\n";
  135. echo " <td style='vertical-align: top; text-align: right; white-space: nowrap;'>\n";
  136. echo " <input type='button' class='btn' alt='".$text['button-back']."' onclick=\"window.location='domain_counts.php'\" value='".$text['button-back']."'>\n";
  137. echo " <input type='text' class='txt' style='width: 150px' name='search' id='search' value='".escape($search)."'>";
  138. echo " <input type='hidden' name='id' value='".escape($domain_uuid)."' />";
  139. echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>";
  140. echo " <input type='button' class='btn' value='".$text['button-export']."' ";
  141. echo "onclick=\"window.location='domain_counts_accountcodes.php?";
  142. if (strlen($_SERVER["QUERY_STRING"]) > 0) {
  143. echo $_SERVER["QUERY_STRING"]."&type=csv';\">\n";
  144. } else {
  145. echo "type=csv';\">\n";
  146. }
  147. # if ($paging_controls_mini != '') {
  148. # echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  149. # }
  150. echo " </td>\n";
  151. echo " </form>\n";
  152. echo " </tr>\n";
  153. echo " <tr>\n";
  154. echo " <td colspan='2'>\n";
  155. echo " ".$text['description-domain_counts_accountcodes']."\n";
  156. echo " </td>\n";
  157. echo " </tr>\n";
  158. echo "</table>\n";
  159. echo "<br />";
  160. echo "<form name='frm' method='post' action='domain_counts_delete.php'>\n";
  161. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  162. echo "<tr>\n";
  163. echo th_order_by('acountcode', $text['label-accountcode'], $order_by, $order);
  164. echo th_order_by('count', $text['label-count'], $order_by,$order);
  165. echo "</tr>\n";
  166. if (isset($directory)) foreach ($directory as $key => $row) {
  167. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['accountcode'])."</td>\n";
  168. echo " <td valign='top' class='row_stylebg' width='75%'>".escape($row['count'])."&nbsp;</td>\n";
  169. echo " </tr>\n";
  170. $c = ($c==0) ? 1 : 0;
  171. }
  172. echo "</table>";
  173. echo "</form>";
  174. //show the footer
  175. require_once "resources/footer.php";
  176. ?>