domain_counts.php 9.8 KB

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