Portions created by the Initial Developer are Copyright (C) 2008-2012 the Initial Developer. All Rights Reserved. Contributor(s): James Rose Mark J Crane */ require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; require_once "resources/header.php"; require_once "resources/schema.php"; //require_once "xml_cdr_statistics_inc.php"; if (permission_exists('xml_cdr_view')) { //access granted } else { echo "access denied"; exit; } //additional includes //require_once "xml_cdr_statistics_inc.php"; require_once "resources/header.php"; global $db; $dom = date('m'); $year = date('Y'); if (strlen($where) == 0) { $duuid = "domain_uuid = '".$_SESSION['domain_uuid']."' "; } for ($y=0; $y<4; $y++) { $fileheader = array( 'month', 'total calls' , 'total seconds' , 'total minutes' , 'total hours' , 'billing periods', 'rate', 'approx cost'); if ( $y == 0) { $tablename = "Previous 12 Months Inbound Call Summary
"; $sql1 = "select billsec as seconds from v_xml_cdr where (".$duuid."and direction='inbound') "; $sql3 = ";"; //really we should set rate in domain settings or something and pull it from the php session. $rate=0.012; $bill_period=60; } elseif ($y == 1) { $tablename = "Previous 12 Months Outbound Metered Call Summary
"; $sql1 = "select billsec as seconds from v_xml_cdr where (".$duuid."and direction='outbound') "; $sql3 = "and destination_number not like '%800_______' and destination_number not like '%888_______' and destination_number not like '%877_______' and destination_number not like '%866_______' and destination_number not like '%855_______' ;"; $rate=0.0098; $rate=$rate/10; $bill_period=6; } elseif ($y == 2) { $tablename = "Previous 12 Months Toll Free Call Summary
"; $sql1 = "select billsec as seconds from v_xml_cdr where (".$duuid."and direction='outbound') "; $sql3 = "and (destination_number like '%800_______' or destination_number like '%888_______' or destination_number like '%877_______' or destination_number like '%866_______' or destination_number like '%855_______');"; $rate=0; $bill_period=6; } elseif ($y == 3) { $tablename = "Previous 12 Months Local Free Call Summary
"; $sql1 = "select billsec as seconds from v_xml_cdr where (".$duuid."and direction='local') "; $sql3 = ";"; $rate=0; $bill_period=6; } else { echo "whoops
"; } //set the style $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; echo ""; $dom = date('m'); $year = date('Y'); $lyear=$year; $lastmonth = $year."-".$dolm."-01"; $thismonth = $year."-".$dom."-01"; echo $tablename; foreach ($fileheader as $tr){ echo ""; } for ($x=0; $x < 12; $x++) { if ($dom == 1){ $dom=12; $year=$year-1; } elseif ($x == 0){ $dom=$dom; } else { $dom=$dom-1; } if ($dom == 1) { $dolm=12; $lyear=$lyear-1; } else { $dolm=$dom-1; } //convert to int $dom=$dom*1; $dolm=$dolm*1; //back to string, prepend 0) if ( $dolm < 10 ) { $dolm = "0".$dolm; } if ( $dom < 10 ) { $dom = "0".$dom; } $lastmonth = $lyear."-".$dolm."-01"; $thismonth = $year."-".$dom."-01"; $sql2 = "and (start_stamp >= '" . $lastmonth . "' AND start_stamp < '" . $thismonth. "') "; $sql = $sql1; $sql .= $sql2; $sql .= $sql3; $sql .= $callsort; //echo "
" . $sql . "
"; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); unset ($prep_statement, $sql); $max = sizeof($result) -1; $i=0; echo ""; //echo " \n"; if ( $max > 0 ) { foreach($result as $row) { $result = $row['seconds']; $billtime_1 = intval($result/$bill_period); $billtime_2 = $result%$bill_period; if (($result%$bill_period) != 0 ) { //need to round up for billing period $billtime = $billtime + intval($result/$bill_period) + 1; //echo " mod worked "; } else { //no need to round up for billing period $billtime = $billtime + intval($result/$bill_period); } $tottime = $tottime + $result; } echo ""; echo ""; echo ""; $mintime = $tottime/$bill_period; echo ""; $hourtime = $tottime/3600; echo ""; $tot_cost = $rate * $billtime ; echo ""; echo ""; echo ""; if ($c==0) { $c=1; } else { $c=0; } } echo ""; $max=0; $tottime=0; $hourtime=0; $billtime=0; $tot_cost=0; $mintime=0; } echo "
" . $tr . "
".($i+1)."".$dolm."/".$lyear."".$max."".$tottime."".round($mintime,1)."".round($hourtime,1)."".$billtime."".$rate."$".round($tot_cost,2)."
"; echo "
"; } //show the footer require_once "resources/footer.php"; ?>