浏览代码

Domain counts accountcodes (#48)

* Create domain_counts_accountcodes.php

Add ability to view the number of extensions for each unique accountcode.

* Update app_languages.php

* Update domain_counts.php
konradSC 8 年之前
父节点
当前提交
7d9aa3500a
共有 3 个文件被更改,包括 237 次插入1 次删除
  1. 13 0
      domain_counts/app_languages.php
  2. 10 1
      domain_counts/domain_counts.php
  3. 214 0
      domain_counts/domain_counts_accountcodes.php

+ 13 - 0
domain_counts/app_languages.php

@@ -3,8 +3,12 @@ $text['title-domain_counts']['en-us'] = "Domain Counts";
 
 
 $text['header-domain_counts']['en-us'] = "Domain Counts";
 $text['header-domain_counts']['en-us'] = "Domain Counts";
 
 
+$text['header-domain_counts_accountcodes']['en-us'] = "Accountcodes";
+
 $text['description-domain_counts']['en-us'] = "Displays the number of items from all domains";
 $text['description-domain_counts']['en-us'] = "Displays the number of items from all domains";
 
 
+$text['description-domain_counts_accountcodes']['en-us'] = "Displays the number of extensions assigned to each domain accountcode.";
+
 $text['label-domain_name']['en-us'] = "Domain Name";
 $text['label-domain_name']['en-us'] = "Domain Name";
 
 
 $text['label-extensions']['en-us'] = "Extensions";
 $text['label-extensions']['en-us'] = "Extensions";
@@ -27,5 +31,14 @@ $text['label-cc_queues']['en-us'] = "CC Queues";
 
 
 $text['label-contacts']['en-us'] = "Contacts";
 $text['label-contacts']['en-us'] = "Contacts";
 
 
+$text['label-accountcodes']['en-us'] = "Accountcodes";
+
+$text['label-accountcode']['en-us'] = "Accountcode";
+
+$text['label-count']['en-us'] = "Extension Count";
+
 $text['button-export']['en-us'] = "Export";
 $text['button-export']['en-us'] = "Export";
+
+$text['title-domain_counts_accountcodes']['en-us'] = "Accountcodes";
+
 ?>
 ?>

+ 10 - 1
domain_counts/domain_counts.php

@@ -28,6 +28,7 @@
 	include "root.php";
 	include "root.php";
 	require_once "resources/require.php";
 	require_once "resources/require.php";
 	require_once "resources/check_auth.php";
 	require_once "resources/check_auth.php";
+	require_once "resources/paging.php";	
 
 
 //include the class
 //include the class
 	require_once "resources/check_auth.php";
 	require_once "resources/check_auth.php";
@@ -123,7 +124,13 @@
 	$sql .= "(\n";
 	$sql .= "(\n";
 	$sql .= "select count(*) from v_contacts \n";
 	$sql .= "select count(*) from v_contacts \n";
 	$sql .= "where domain_uuid = d.domain_uuid\n";
 	$sql .= "where domain_uuid = d.domain_uuid\n";
-	$sql .= ") as contact_count \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 .= "FROM v_domains as d \n";
 	$sql .= $sql_mod; //add search mod from above
 	$sql .= $sql_mod; //add search mod from above
@@ -240,6 +247,7 @@
 	echo th_order_by('ring_group_count', $text['label-ring_groups'], $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('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('contact_count', $text['label-contacts'], $order_by, $order);
+	echo th_order_by('accountcode_count', $text['label-accountcodes'], $order_by, $order);	
 	echo "</tr>\n";
 	echo "</tr>\n";
 
 
 	if (isset($domain_counts)) foreach ($domain_counts as $key => $row) {
 	if (isset($domain_counts)) foreach ($domain_counts as $key => $row) {
@@ -254,6 +262,7 @@
 		echo "	<td valign='top' class='".$row_style[$c]."'>".$row['ring_group_count']."&nbsp;</td>\n";
 		echo "	<td valign='top' class='".$row_style[$c]."'>".$row['ring_group_count']."&nbsp;</td>\n";
 		echo "	<td valign='top' class='".$row_style[$c]."'>".$row['cc_queue_count']."&nbsp;</td>\n";
 		echo "	<td valign='top' class='".$row_style[$c]."'>".$row['cc_queue_count']."&nbsp;</td>\n";
 		echo "	<td valign='top' class='".$row_style[$c]."'>".$row['contact_count']."&nbsp;</td>\n";
 		echo "	<td valign='top' class='".$row_style[$c]."'>".$row['contact_count']."&nbsp;</td>\n";
+		echo "	<td valign='top' class='".$row_style[$c]."'><a href='domain_counts_accountcodes.php?id=".$row['domain_uuid']."'>".$row['accountcode_count']."&nbsp;</td>\n";		
 		
 		
 		
 		
 		echo "</tr>\n";
 		echo "</tr>\n";

+ 214 - 0
domain_counts/domain_counts_accountcodes.php

@@ -0,0 +1,214 @@
+<?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-2016
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	KonradSC <[email protected]>
+*/
+
+//includes
+	include "root.php";
+	require_once "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
+	$domain_uuid = check_str($_GET["id"]);
+	$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 = "and accountcode ILIKE '%".$search."%' "; 
+	}
+	if (strlen($order_by) < 1) {
+		$order_by = "accountcode";
+		$order = "ASC";
+	}
+	
+//get total accountcode count from the database
+	$sql = "select count(DISTINCT accountcode) as num_rows from v_extensions where domain_uuid = '".$domain_uuid."' ".$sql_mod." ";
+	$prep_statement = $db->prepare($sql);
+	if ($prep_statement) {
+		$prep_statement->execute();
+		$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
+		$total_accountcodes = $row['num_rows'];
+		if (($db_type == "pgsql") or ($db_type == "mysql")) {
+			$numeric_accountcodes = $row['num_rows'];
+		}
+	}
+	unset($prep_statement, $row);
+
+//prepare to page the results
+	$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
+	$param = "&search=".$search."&id=".$domain_uuid."&order_by=".$order_by."&order=".$order;
+	if (!isset($_GET['page'])) { $_GET['page'] = 0; }
+	$_GET['page'] = check_str($_GET['page']);
+	list($paging_controls_mini, $rows_per_page, $var_3) = paging($total_accountcodes, $param, $rows_per_page, true); //top
+	list($paging_controls, $rows_per_page, $var_3) = paging($total_accountcodes, $param, $rows_per_page); //bottom
+	$offset = $rows_per_page * $_GET['page'];
+	
+//get the domain name from the database
+	$sql = "SELECT domain_name  \n";
+	$sql .= "FROM v_domains \n";
+	$sql .= "WHERE domain_uuid = '$domain_uuid' \n";
+	$database = new database;
+	$database->select($sql);
+	$domain_result = $database->result;
+	unset($database,$result);
+	
+//get all the accountcodes from the database
+	$sql = "SELECT accountcode, count(*) AS count  \n";
+	$sql .= "FROM v_extensions \n";
+	$sql .= "WHERE domain_uuid = '$domain_uuid' and accountcode is not null \n";
+	$sql .= $sql_mod; //add search mod from above
+	$sql .= "GROUP BY accountcode ";
+	$sql .= "ORDER BY ".$order_by." ".$order." \n";
+	$sql .= "limit $rows_per_page offset $offset ";
+	$database = new database;
+	$database->select($sql);
+	$directory = $database->result;
+	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_result[0][domain_name]."_accountcodes" . date("Y-m-d") . ".csv'");
+
+		//show the column names on the first line
+			$z = 0;
+			foreach($directory[1] as $key => $val) {
+				if ($z == 0) {
+					echo '"'.$key.'"';
+				}
+				else {
+					echo ',"'.$key.'"';
+				}
+				$z++;
+			}
+			echo "\n";
+		
+		//add the values to the csv
+			$x = 0;
+			foreach($directory as $codes) {
+				$z = 0;
+				foreach($codes as $key => $val) {
+					if ($z == 0) {
+						echo '"'.$directory[$x][$key].'"';
+					}
+					else {
+						echo ',"'.$directory[$x][$key].'"';
+					}
+					$z++;
+				}
+				echo "\n";
+				$x++;
+			}
+			exit;
+	}
+	
+//additional includes
+	require_once "resources/header.php";
+	$document['title'] = $text['title-domain_counts_accountcodes'];
+
+//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";
+	echo "		<b>".$text['header-domain_counts_accountcodes'].": ".$domain_result[0][domain_name]." (".$numeric_accountcodes.")</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";
+	echo "				<input type='button' class='btn' alt='".$text['button-back']."' onclick=\"window.location='domain_counts.php'\" value='".$text['button-back']."'>\n";	
+	echo "				<input type='text' class='txt' style='width: 150px' name='search' id='search' value='".$search."'>";
+	echo "				<input type='hidden' name='id' value='".$domain_uuid."' />";	
+	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_accountcodes.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_accountcodes']."\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('acountcode', $text['label-accountcode'], $order_by, $order);
+	echo th_order_by('count', $text['label-count'], $order_by,$order);
+	echo "</tr>\n";
+
+	if (isset($directory)) foreach ($directory as $key => $row) {
+		echo "	<td valign='top' class='".$row_style[$c]."'>".$row['accountcode']."</td>\n";
+		echo "	<td valign='top' class='row_stylebg' width='75%'>".$row['count']."&nbsp;</td>\n";
+		echo "	</tr>\n";
+		$c = ($c==0) ? 1 : 0;
+	}
+
+	echo "</table>";
+	echo "</form>";
+
+//show the footer
+	require_once "resources/footer.php";	
+?>