domain_counts.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. $order_by = check_str($_GET["order_by"]);
  41. $order = check_str($_GET["order"]);
  42. //handle search term
  43. $search = check_str($_GET["search"]);
  44. if (strlen($search) > 0) {
  45. $sql_mod = "WHERE d.domain_name like '%".$search."%' ";
  46. }
  47. if (strlen($order_by) < 1) {
  48. $order_by = "domain_name";
  49. $order = "ASC";
  50. }
  51. //get all the counts from the database
  52. $sql = "SELECT \n";
  53. $sql .= "d.domain_uuid, \n";
  54. $sql .= "d.domain_name, \n";
  55. $sql .= "d.domain_description, \n";
  56. //extension
  57. $sql .= "(\n";
  58. $sql .= "select count(*) from v_extensions \n";
  59. $sql .= "where domain_uuid = d.domain_uuid\n";
  60. $sql .= ") as extension_count, \n";
  61. //users
  62. $sql .= "(\n";
  63. $sql .= "select count(*) from v_users \n";
  64. $sql .= "where domain_uuid = d.domain_uuid\n";
  65. $sql .= ") as user_count, \n";
  66. //devices
  67. $sql .= "(\n";
  68. $sql .= "select count(*) from v_devices \n";
  69. $sql .= "where domain_uuid = d.domain_uuid\n";
  70. $sql .= ") as device_count, \n";
  71. //destinations
  72. $sql .= "(\n";
  73. $sql .= "select count(*) from v_destinations \n";
  74. $sql .= "where domain_uuid = d.domain_uuid\n";
  75. $sql .= ") as destination_count, \n";
  76. //faxes
  77. $sql .= "(\n";
  78. $sql .= "select count(*) from v_fax \n";
  79. $sql .= "where domain_uuid = d.domain_uuid\n";
  80. $sql .= ") as fax_count, \n";
  81. //ivr
  82. $sql .= "(\n";
  83. $sql .= "select count(*) from v_ivr_menus \n";
  84. $sql .= "where domain_uuid = d.domain_uuid\n";
  85. $sql .= ") as ivr_count, \n";
  86. //voicemail
  87. $sql .= "(\n";
  88. $sql .= "select count(*) from v_voicemails \n";
  89. $sql .= "where domain_uuid = d.domain_uuid\n";
  90. $sql .= ") as voicemail_count, \n";
  91. //ring_group
  92. $sql .= "(\n";
  93. $sql .= "select count(*) from v_ring_groups \n";
  94. $sql .= "where domain_uuid = d.domain_uuid\n";
  95. $sql .= ") as ring_group_count, \n";
  96. //call_center_queues
  97. $sql .= "(\n";
  98. $sql .= "select count(*) from v_call_center_queues \n";
  99. $sql .= "where domain_uuid = d.domain_uuid\n";
  100. $sql .= ") as cc_queue_count, \n";
  101. //contacts
  102. $sql .= "(\n";
  103. $sql .= "select count(*) from v_contacts \n";
  104. $sql .= "where domain_uuid = d.domain_uuid\n";
  105. $sql .= ") as contact_count, \n";
  106. //accountcodes
  107. $sql .= "(\n";
  108. $sql .= "select count(DISTINCT accountcode) from v_extensions \n";
  109. $sql .= "where domain_uuid = d.domain_uuid\n";
  110. $sql .= ") as accountcode_count \n";
  111. $sql .= "FROM v_domains as d \n";
  112. $sql .= $sql_mod; //add search mod from above
  113. $sql .= "ORDER BY ".$order_by." ".$order." \n";
  114. $database = new database;
  115. $domain_counts = $database->select($sql, null);
  116. //lookup the domain count
  117. $database = new database;
  118. $database->table = "v_domains";
  119. $where[1]["name"] = "domain_uuid";
  120. $where[1]["operator"] = "=";
  121. $where[1]["value"] = "*";
  122. $numeric_domain_counts = $database->count();
  123. unset($database,$result);
  124. //set the http header
  125. if ($_REQUEST['type'] == "csv") {
  126. //set the headers
  127. header('Content-type: application/octet-binary');
  128. header("Content-Disposition: attachment; filename=domain-counts_" . date("Y-m-d") . ".csv");
  129. //show the column names on the first line
  130. $z = 0;
  131. foreach($domain_counts[1] as $key => $val) {
  132. if ($z == 0) {
  133. echo '"'.$key.'"';
  134. }
  135. else {
  136. echo ',"'.$key.'"';
  137. }
  138. $z++;
  139. }
  140. echo "\n";
  141. //add the values to the csv
  142. $x = 0;
  143. foreach($domain_counts as $domains) {
  144. $z = 0;
  145. foreach($domains as $key => $val) {
  146. if ($z == 0) {
  147. echo '"'.$domain_counts[$x][$key].'"';
  148. }
  149. else {
  150. echo ',"'.$domain_counts[$x][$key].'"';
  151. }
  152. $z++;
  153. }
  154. echo "\n";
  155. $x++;
  156. }
  157. exit;
  158. }
  159. //additional includes
  160. require_once "resources/header.php";
  161. $document['title'] = $text['title-domain_counts'];
  162. //set the alternating styles
  163. $c = 0;
  164. $row_style["0"] = "row_style0";
  165. $row_style["1"] = "row_style1";
  166. //show the content
  167. echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
  168. echo " <tr>\n";
  169. echo " <td align='left' width='100%'>\n";
  170. if (permission_exists('domain_counts_view_all')) {
  171. echo " <b>".$text['header-domain_counts']." (".$numeric_domain_counts.")</b><br>\n";
  172. }
  173. if (permission_exists('domain_counts_view_domain')) {
  174. echo " <b>".$text['header-domain_counts']."</b><br>\n";
  175. }
  176. echo " </td>\n";
  177. echo " <td align='right' width='100%' style='vertical-align: top;'>";
  178. echo " <form method='get' action=''>\n";
  179. echo " <td style='vertical-align: top; text-align: right; white-space: nowrap;'>\n";
  180. if (permission_exists('domain_counts_view_all')) {
  181. echo " <input type='text' class='txt' style='width: 150px' name='search' id='search' value='".$search."'>";
  182. echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>";
  183. }
  184. echo " <input type='button' class='btn' value='".$text['button-export']."' ";
  185. echo "onclick=\"window.location='domain_counts.php?";
  186. if (strlen($_SERVER["QUERY_STRING"]) > 0) {
  187. echo $_SERVER["QUERY_STRING"]."&type=csv';\">\n";
  188. } else {
  189. echo "type=csv';\">\n";
  190. }
  191. # if ($paging_controls_mini != '') {
  192. # echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  193. # }
  194. echo " </td>\n";
  195. echo " </form>\n";
  196. echo " </tr>\n";
  197. echo " <tr>\n";
  198. echo " <td colspan='2'>\n";
  199. echo " ".$text['description-domain_counts']."\n";
  200. echo " </td>\n";
  201. echo " </tr>\n";
  202. echo "</table>\n";
  203. echo "<br />";
  204. echo "<form name='frm' method='post' action='domain_counts_delete.php'>\n";
  205. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  206. echo "<tr>\n";
  207. echo th_order_by('domain_name', $text['label-domain_name'], $order_by, $order);
  208. echo th_order_by('extension_count', $text['label-extensions'], $order_by,$order);
  209. echo th_order_by('user_count', $text['label-users'], $order_by, $order);
  210. echo th_order_by('device_count', $text['label-devices'], $order_by, $order);
  211. echo th_order_by('destination_count', $text['label-destinations'], $order_by, $order);
  212. echo th_order_by('fax_count', $text['label-faxes'], $order_by, $order);
  213. echo th_order_by('ivr_count', $text['label-ivrs'], $order_by, $order);
  214. echo th_order_by('voicemail_count', $text['label-voicemails'], $order_by, $order);
  215. echo th_order_by('ring_group_count', $text['label-ring_groups'], $order_by, $order);
  216. echo th_order_by('cc_queue_count', $text['label-cc_queues'], $order_by, $order);
  217. echo th_order_by('contact_count', $text['label-contacts'], $order_by, $order);
  218. echo th_order_by('accountcode_count', $text['label-accountcodes'], $order_by, $order);
  219. echo "</tr>\n";
  220. if (isset($domain_counts)) foreach ($domain_counts as $key => $row) {
  221. if (permission_exists('domain_counts_view_all') || (permission_exists('domain_counts_view_domain') && $_SESSION['domain_name'] == $row['domain_name']) ) {
  222. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['domain_name'])."</td>\n";
  223. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['extension_count'])."&nbsp;</td>\n";
  224. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['user_count'])."&nbsp;</td>\n";
  225. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['device_count'])."&nbsp;</td>\n";
  226. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['destination_count'])."&nbsp;</td>\n";
  227. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['fax_count'])."&nbsp;</td>\n";
  228. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['ivr_count'])."&nbsp;</td>\n";
  229. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['voicemail_count'])."&nbsp;</td>\n";
  230. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['ring_group_count'])."&nbsp;</td>\n";
  231. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['cc_queue_count'])."&nbsp;</td>\n";
  232. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['contact_count'])."&nbsp;</td>\n";
  233. echo " <td valign='top' class='".$row_style[$c]."'><a href='domain_counts_accountcodes.php?id=".escape($row['domain_uuid'])."'>".escape($row['accountcode_count'])."&nbsp;</td>\n";
  234. echo "</tr>\n";
  235. $c = ($c==0) ? 1 : 0;
  236. }
  237. }
  238. echo "</table>";
  239. echo "</form>";
  240. //show the footer
  241. require_once "resources/footer.php";
  242. ?>