123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <?php
- /*
- FusionPBX
- Version: MPL 1.1
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
- The Original Code is FusionPBX
- The Initial Developer of the Original Code is
- Mark J Crane <[email protected]>
- Portions created by the Initial Developer are Copyright (C) 2008-2023
- the Initial Developer. All Rights Reserved.
- Contributor(s):
- KonradSC <[email protected]>
- */
- //includes files
- require_once dirname(__DIR__, 2) . "/resources/require.php";
- require_once "resources/check_auth.php";
- require_once "resources/paging.php";
- //include the class
- require_once "resources/check_auth.php";
- //check permissions
- require_once "resources/check_auth.php";
- if (permission_exists('domain_counts_view')) {
- //access granted
- }
- else {
- echo "access denied";
- exit;
- }
-
- //add multi-lingual support
- $language = new text;
- $text = $language->get();
- //get the http values and set them as variables
- $order_by = check_str($_GET["order_by"]);
- $order = check_str($_GET["order"]);
- //handle search term
- $search = check_str($_GET["search"]);
- if (strlen($search) > 0) {
- $sql_mod = "WHERE d.domain_name like '%".$search."%' ";
- }
- if (strlen($order_by) < 1) {
- $order_by = "domain_name";
- $order = "ASC";
- }
- //get all the counts from the database
- $sql = "SELECT \n";
- $sql .= "d.domain_uuid, \n";
- $sql .= "d.domain_name, \n";
- $sql .= "d.domain_description, \n";
- //extension
- $sql .= "(\n";
- $sql .= "select count(*) from v_extensions \n";
- $sql .= "where domain_uuid = d.domain_uuid\n";
- $sql .= ") as extension_count, \n";
-
- //users
- $sql .= "(\n";
- $sql .= "select count(*) from v_users \n";
- $sql .= "where domain_uuid = d.domain_uuid\n";
- $sql .= ") as user_count, \n";
- //devices
- $sql .= "(\n";
- $sql .= "select count(*) from v_devices \n";
- $sql .= "where domain_uuid = d.domain_uuid\n";
- $sql .= ") as device_count, \n";
- //inbound-destinations
- $sql .= "(\n";
- $sql .= "select count(*) from v_destinations \n";
- $sql .= "where domain_uuid = d.domain_uuid \n";
- $sql .= "and destination_type = 'inbound'\n";
- $sql .= ") as inbound_destination_count, \n";
- //outbound-destinations
- $sql .= "(\n";
- $sql .= "select count(*) from v_destinations \n";
- $sql .= "where domain_uuid = d.domain_uuid \n";
- $sql .= "and destination_type = 'outbound'\n";
- $sql .= ") as outbound_destination_count, \n";
-
- //faxes
- $sql .= "(\n";
- $sql .= "select count(*) from v_fax \n";
- $sql .= "where domain_uuid = d.domain_uuid\n";
- $sql .= ") as fax_count, \n";
- //ivr
- $sql .= "(\n";
- $sql .= "select count(*) from v_ivr_menus \n";
- $sql .= "where domain_uuid = d.domain_uuid\n";
- $sql .= ") as ivr_count, \n";
- //voicemail
- $sql .= "(\n";
- $sql .= "select count(*) from v_voicemails \n";
- $sql .= "where domain_uuid = d.domain_uuid\n";
- $sql .= ") as voicemail_count, \n";
- //ring_group
- $sql .= "(\n";
- $sql .= "select count(*) from v_ring_groups \n";
- $sql .= "where domain_uuid = d.domain_uuid\n";
- $sql .= ") as ring_group_count, \n";
- //call_center_queues
- $sql .= "(\n";
- $sql .= "select count(*) from v_call_center_queues \n";
- $sql .= "where domain_uuid = d.domain_uuid\n";
- $sql .= ") as cc_queue_count, \n";
- //contacts
- $sql .= "(\n";
- $sql .= "select count(*) from v_contacts \n";
- $sql .= "where domain_uuid = d.domain_uuid\n";
- $sql .= ") as contact_count, \n";
-
- //accountcodes
- $sql .= "(\n";
- $sql .= "select count(DISTINCT accountcode) from v_extensions \n";
- $sql .= "where domain_uuid = d.domain_uuid\n";
- $sql .= ") as accountcode_count \n";
-
- $sql .= "FROM v_domains as d \n";
- $sql .= $sql_mod; //add search mod from above
- $sql .= "ORDER BY ".$order_by." ".$order." \n";
- $database = new database;
- $domain_counts = $database->select($sql, null);
- //lookup the domain count
- $database = new database;
- $database->table = "v_domains";
- $where[1]["name"] = "domain_uuid";
- $where[1]["operator"] = "=";
- $where[1]["value"] = "*";
- $numeric_domain_counts = $database->count();
- unset($database,$result);
- //set the http header
- if ($_REQUEST['type'] == "csv") {
-
- //set the headers
- header('Content-type: application/octet-binary');
- header("Content-Disposition: attachment; filename=domain-counts_" . date("Y-m-d") . ".csv");
- //show the column names on the first line
- $z = 0;
- foreach($domain_counts[1] as $key => $val) {
- if ($z == 0) {
- echo '"'.$key.'"';
- }
- else {
- echo ',"'.$key.'"';
- }
- $z++;
- }
- echo "\n";
-
- //add the values to the csv
- $x = 0;
- foreach($domain_counts as $domains) {
- $z = 0;
- foreach($domains as $key => $val) {
- if ($z == 0) {
- echo '"'.$domain_counts[$x][$key].'"';
- }
- else {
- echo ',"'.$domain_counts[$x][$key].'"';
- }
- $z++;
- }
- echo "\n";
- $x++;
- }
- exit;
- }
-
- //additional includes
- require_once "resources/header.php";
- $document['title'] = $text['title-domain_counts'];
- //set the alternating styles
- $c = 0;
- $row_style["0"] = "row_style0";
- $row_style["1"] = "row_style1";
-
- //show the content
- echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
- echo " <tr>\n";
- echo " <td align='left' width='100%'>\n";
- if (permission_exists('domain_counts_view_all')) {
- echo " <b>".$text['header-domain_counts']." (".$numeric_domain_counts.")</b><br>\n";
- }
- if (permission_exists('domain_counts_view_domain')) {
- echo " <b>".$text['header-domain_counts']."</b><br>\n";
- }
- echo " </td>\n";
- echo " <td align='right' width='100%' style='vertical-align: top;'>";
- echo " <form method='get' action=''>\n";
- echo " <td style='vertical-align: top; text-align: right; white-space: nowrap;'>\n";
- if (permission_exists('domain_counts_view_all')) {
- echo " <input type='text' class='txt' style='width: 150px' name='search' id='search' value='".$search."'>";
- echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>";
- }
- echo " <input type='button' class='btn' value='".$text['button-export']."' ";
- echo "onclick=\"window.location='domain_counts.php?";
- if (strlen($_SERVER["QUERY_STRING"]) > 0) {
- echo $_SERVER["QUERY_STRING"]."&type=csv';\">\n";
- } else {
- echo "type=csv';\">\n";
- }
- # if ($paging_controls_mini != '') {
- # echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
- # }
- echo " </td>\n";
- echo " </form>\n";
- echo " </tr>\n";
-
-
- echo " <tr>\n";
- echo " <td colspan='2'>\n";
- echo " ".$text['description-domain_counts']."\n";
- echo " </td>\n";
- echo " </tr>\n";
- echo "</table>\n";
- echo "<br />";
- echo "<form name='frm' method='post' action='domain_counts_delete.php'>\n";
- echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
- echo "<tr>\n";
- echo th_order_by('domain_name', $text['label-domain_name'], $order_by, $order);
- echo th_order_by('extension_count', $text['label-extensions'], $order_by,$order);
- echo th_order_by('user_count', $text['label-users'], $order_by, $order);
- echo th_order_by('device_count', $text['label-devices'], $order_by, $order);
- echo th_order_by('inbound_destination_count', $text['label-inbound-destinations'], $order_by, $order);
- echo th_order_by('outbound_destination_count', $text['label-outbound-destinations'], $order_by, $order);
- echo th_order_by('fax_count', $text['label-faxes'], $order_by, $order);
- echo th_order_by('ivr_count', $text['label-ivrs'], $order_by, $order);
- echo th_order_by('voicemail_count', $text['label-voicemails'], $order_by, $order);
- echo th_order_by('ring_group_count', $text['label-ring_groups'], $order_by, $order);
- echo th_order_by('cc_queue_count', $text['label-cc_queues'], $order_by, $order);
- echo th_order_by('contact_count', $text['label-contacts'], $order_by, $order);
- echo th_order_by('accountcode_count', $text['label-accountcodes'], $order_by, $order);
- echo "</tr>\n";
- if (isset($domain_counts)) foreach ($domain_counts as $key => $row) {
-
- if (permission_exists('domain_counts_view_all') || (permission_exists('domain_counts_view_domain') && $_SESSION['domain_name'] == $row['domain_name']) ) {
- echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['domain_name'])."</td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['extension_count'])." </td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['user_count'])." </td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['device_count'])." </td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['inbound_destination_count'])." </td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['outbound_destination_count'])." </td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['fax_count'])." </td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['ivr_count'])." </td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['voicemail_count'])." </td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['ring_group_count'])." </td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['cc_queue_count'])." </td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['contact_count'])." </td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'><a href='domain_counts_accountcodes.php?id=".escape($row['domain_uuid'])."'>".escape($row['accountcode_count'])." </td>\n";
- echo "</tr>\n";
- $c = ($c==0) ? 1 : 0;
- }
- }
- echo "</table>";
- echo "</form>";
- //show the footer
- require_once "resources/footer.php";
- ?>
|