call-count-reporting.php

来自「asterisk用 的voip记费软件」· PHP 代码 · 共 712 行 · 第 1/3 页

PHP
712
字号
<?phpinclude ("../lib/defines.php");include ("../lib/module.access.php");include ("../lib/smarty.php");if (! has_rights (ACX_CALL_REPORT)){ 	Header ("HTTP/1.0 401 Unauthorized");	Header ("Location: PP_error.php?c=accessdenied");	   	die();}getpost_ifset(array('inputtopvar','topsearch', 'posted', 'Period', 'frommonth', 'fromstatsmonth', 'tomonth', 'tostatsmonth', 'fromday', 'fromstatsday_sday', 'fromstatsmonth_sday', 'today', 'tostatsday_sday', 'tostatsmonth_sday', 'resulttype', 'stitle', 'atmenu', 'current_page', 'order', 'sens', 'choose_currency', 'terminatecause', 'nodisplay','grouped'));//var $field=array();switch ($topsearch){	case "topuser":		$field=array('CARD ID','username');	break;	case "topdestination":		$field=array('DESTINATION','destination');	break;		default:		$field=array('CARD ID','username');}if (!isset ($current_page) || ($current_page == "")){		$current_page=0; }if (!isset ($FG_TABLE_CLAUSE) || strlen($FG_TABLE_CLAUSE)==0){				$cc_yearmonth = sprintf("%04d-%02d-%02d",date("Y"),date("n"),date("d")); 			$FG_TABLE_CLAUSE=" $UNIX_TIMESTAMP(starttime) <= $UNIX_TIMESTAMP('$cc_yearmonth')";}// this variable specifie the debug type (0 => nothing, 1 => sql result, 2 => boucle checking, 3 other value checking)$FG_DEBUG = 0;// The variable FG_TABLE_NAME define the table name to use$FG_TABLE_NAME="cc_call";// THIS VARIABLE DEFINE THE COLOR OF THE HEAD TABLE$FG_TABLE_HEAD_COLOR = "#D1D9E7";$FG_TABLE_EXTERN_COLOR = "#7F99CC"; //#CC0033 (Rouge)$FG_TABLE_INTERN_COLOR = "#EDF3FF"; //#FFEAFF (Rose)// THIS VARIABLE DEFINE THE COLOR OF THE HEAD TABLE$FG_TABLE_ALTERNATE_ROW_COLOR[] = "#FFFFFF";$FG_TABLE_ALTERNATE_ROW_COLOR[] = "#F2F8FF";//$link = DbConnect();$DBHandle  = DbConnect();// The variable Var_col would define the col that we want show in your table// First Name of the column in the html page, second name of the field$FG_TABLE_COL = array();if ((!isset($field)) && (count($field)<=1)){	$field[0]="CARD ID";	$field[1]="username";	}$FG_TABLE_COL[]=array (gettext($field[0]), $field[1], "20%", "center","SORT");$FG_TABLE_COL[]=array (gettext("Duration"), "calltime", "20%", "center", "SORT", "30", "", "", "", "", "", "display_minute");$FG_TABLE_COL[]=array (gettext("Buy"), "buy", "25%", "center","sort","","","","","","","display_2bill");$FG_TABLE_COL[]=array (gettext("Sell"), "cost", "25%", "center","sort","","","","","","","display_2bill");if ($grouped) $FG_TABLE_COL[]=array (gettext("Calldate"), "day", "10%", "center", "SORT", "19", "", "", "", "", "", "display_dateformat");$FG_TABLE_COL[]=array (gettext("terminatecause"), "terminatecause", "10%", "center", "SORT", "30");if ((isset($inputtopvar)) && ($inputtopvar!="") && (isset($topsearch)) && ($topsearch!="")){	$FG_TABLE_COL[]=array (gettext("NbrCall"), 'nbcall', "10%", "center", "SORT");}if ($grouped){	$FG_COL_QUERY=$field[1].', sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy,substring(starttime,1,10) AS day,terminatecause, count(*) as nbcall';	$SQL_GROUP="GROUP BY ".$field[1].",day,terminatecause ";}else{	$FG_COL_QUERY=$field[1].', sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy,terminatecause, count(*) as nbcall';	$SQL_GROUP="GROUP BY ".$field[1].",terminatecause ";}$FG_TABLE_DEFAULT_ORDER = "username";$FG_TABLE_DEFAULT_SENS = "DESC";	// The variable LIMITE_DISPLAY define the limit of record to display by page$FG_LIMITE_DISPLAY=20;// Number of column in the html table$FG_NB_TABLE_COL=count($FG_TABLE_COL);// The variable $FG_EDITION define if you want process to the edition of the database record$FG_EDITION=false;//This variable will store the total number of column$FG_TOTAL_TABLE_COL = $FG_NB_TABLE_COL;if ($FG_DELETION || $FG_EDITION) $FG_TOTAL_TABLE_COL++;//This variable define the Title of the HTML table$FG_HTML_TABLE_TITLE=gettext(" - Call Report - ");//This variable define the width of the HTML table$FG_HTML_TABLE_WIDTH="96%";	if ($FG_DEBUG == 3) echo "<br>Table : $FG_TABLE_NAME  	- 	Col_query : $FG_COL_QUERY";	if ( is_null ($order) || is_null($sens) ){	$order = $FG_TABLE_DEFAULT_ORDER;	$sens  = $FG_TABLE_DEFAULT_SENS;}$date_clause='';// Period (Month-Day)if (DB_TYPE == "postgres"){			 	$UNIX_TIMESTAMP = "";}else{		$UNIX_TIMESTAMP = "UNIX_TIMESTAMP";}$lastdayofmonth = date("t", strtotime($tostatsmonth.'-01'));if ($Period=="Month"){	if ($frommonth && isset($fromstatsmonth)) $date_clause.=" AND $UNIX_TIMESTAMP(starttime) >= $UNIX_TIMESTAMP('$fromstatsmonth-01')";	if ($tomonth && isset($tostatsmonth)) $date_clause.=" AND $UNIX_TIMESTAMP(starttime) <= $UNIX_TIMESTAMP('".$tostatsmonth."-$lastdayofmonth 23:59:59')"; }else{	if ($fromday && isset($fromstatsday_sday) && isset($fromstatsmonth_sday)) $date_clause.=" AND $UNIX_TIMESTAMP(starttime) >= $UNIX_TIMESTAMP('$fromstatsmonth_sday-$fromstatsday_sday')";	if ($today && isset($tostatsday_sday) && isset($tostatsmonth_sday)) $date_clause.=" AND $UNIX_TIMESTAMP(starttime) <= $UNIX_TIMESTAMP('$tostatsmonth_sday-".sprintf("%02d",intval($tostatsday_sday)/*+1*/)." 23:59:59')";}if (strpos($date_clause, 'AND') > 0){	$FG_TABLE_CLAUSE = substr($date_clause,5); }//To select just terminatecause=ANSWERif (!isset($terminatecause)){	$terminatecause="ANSWER";}if ($terminatecause=="ANSWER") {	if (strlen($FG_TABLE_CLAUSE)>0) $FG_TABLE_CLAUSE.=" AND ";	$FG_TABLE_CLAUSE.="terminatecause='ANSWER' OR terminatecause='ANSWERED'";}if ($grouped){	$QUERY_TOTAL = "SELECT sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy, count(*) as nbcall,substring(starttime,1,10) AS day FROM $FG_TABLE_NAME  GROUP BY day";}else{	$QUERY_TOTAL = "SELECT sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy, count(*) as nbcall FROM $FG_TABLE_NAME";}if ((isset($inputtopvar)) && ($inputtopvar!="") && (isset($topsearch)) && ($topsearch!="")){	if ($grouped){		$FG_COL_QUERY1=$field[1].', sum(sessiontime) AS sessiontime, sum(sessionbill) as sessionbill, sum(buycost) as buycost,substring(starttime,1,10) AS starttime,terminatecause, count(*) as nbcall';		$SQL_GROUP1=" GROUP BY $field[1],starttime,terminatecause";	}else{		$FG_COL_QUERY1=$field[1].', sum(sessiontime) AS sessiontime, sum(sessionbill) as sessionbill, sum(buycost) as buycost,terminatecause, count(*) as nbcall,starttime';		$SQL_GROUP1=" GROUP BY $field[1],terminatecause,starttime";	}	$QUERY = "CREATE TEMPORARY TABLE temp_result AS (SELECT $FG_COL_QUERY1 FROM $FG_TABLE_NAME WHERE $FG_TABLE_CLAUSE  $SQL_GROUP1 ORDER BY nbcall DESC LIMIT $inputtopvar)";	$res = $DBHandle -> Execute($QUERY);	if ($res){		$FG_TABLE_NAME="temp_result";		if ($grouped){			$FG_COL_QUERY=$field[1].', sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy,substring(starttime,1,10) AS day,terminatecause, nbcall';			$SQL_GROUP=" GROUP BY ".$field[1].",day,terminatecause,nbcall ";			$QUERY_TOTAL = "SELECT sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy, sum(nbcall) as nbcall,substring(starttime,1,10) AS day FROM $FG_TABLE_NAME GROUP BY day";		}else{			$FG_COL_QUERY=$field[1].', sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy,terminatecause, nbcall';			$SQL_GROUP=" GROUP BY ".$field[1].",terminatecause,nbcall ";			$QUERY_TOTAL = "SELECT sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy, sum(nbcall) as nbcall FROM $FG_TABLE_NAME";		}		$order = "nbcall";	}}$instance_table = new Table($FG_TABLE_NAME, $FG_COL_QUERY);if (!$nodisplay){	$list = $instance_table -> Get_list ($DBHandle, $FG_TABLE_CLAUSE, $order, $sens, null, null, $FG_LIMITE_DISPLAY, $current_page*$FG_LIMITE_DISPLAY,$SQL_GROUP);	$res = $DBHandle -> Execute($QUERY_TOTAL);	if ($res){		$num=$res->RecordCount( );		for($i=0;$i<$num;$i++)		{							$list_total[]=$res -> fetchRow();		}	}	if ($FG_DEBUG == 3) echo "<br>Clause : $FG_TABLE_CLAUSE";	$nb_record = $instance_table -> Table_count ($DBHandle);	if ($FG_DEBUG >= 1) var_dump ($list);}//end IF nodisplayif ($nb_record<=$FG_LIMITE_DISPLAY){ 	$nb_record_max=1;}else{ 	if ($nb_record % $FG_LIMITE_DISPLAY == 0){		$nb_record_max=(intval($nb_record/$FG_LIMITE_DISPLAY));	}else{		$nb_record_max=(intval($nb_record/$FG_LIMITE_DISPLAY)+1);	}	}if ($FG_DEBUG == 3) echo "<br>Nb_record : $nb_record";if ($FG_DEBUG == 3) echo "<br>Nb_record_max : $nb_record_max";/*******************   TOTAL COSTS  *****************************************$instance_table_cost = new Table($FG_TABLE_NAME, "sum(.costs), sum(.buycosts)");		if (!$nodisplay){		$total_cost = $instance_table_cost -> Get_list ($DBHandle, $FG_TABLE_CLAUSE, null, null, null, null, null, null);}*//*************************************************************/?><?php	$smarty->display('main.tpl');

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?