diff --git a/html/billing-graph.php b/html/billing-graph.php
index e607b2e7f..cff1bc184 100644
--- a/html/billing-graph.php
+++ b/html/billing-graph.php
@@ -11,14 +11,16 @@ if($_GET['debug']) {
include("../includes/defaults.inc.php");
include("../config.php");
include("../includes/functions.php");
+include("includes/functions.inc.php");
include("includes/authenticate.inc.php");
if(!$_SESSION['authenticated']) { echo("unauthenticated"); exit; }
require("includes/jpgraph/src/jpgraph.php");
include("includes/jpgraph/src/jpgraph_line.php");
include("includes/jpgraph/src/jpgraph_utils.inc.php");
-if($_GET['bill_id']){
- if(testPassword($_GET['bill_id'],$_GET['bill_code']) == "1") {
+if(is_numeric($_GET['bill_id'])){
+ if(bill_permitted($_GET['bill_id']))
+ {
$bill_id = $_GET['bill_id'];
} else {
echo("Unauthorised Access Prohibited.");
@@ -76,7 +78,6 @@ $i = '0';
#$start = mysql_result(mysql_query("SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bill_data WHERE bill_id = $bill_id AND timestamp >=$datefrom AND timestamp <= $dateto ORDER BY timestamp ASC LIMIT 0,1"),0);
#$end = mysql_result(mysql_query("SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bill_data WHERE bill_id = $bill_id AND timestamp >=$datefrom AND timestamp <= $dateto ORDER BY timestamp DESC LIMIT 0,1"),0);
-
$dur = $end - $start;
$sql = "SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bill_data WHERE bill_id = $bill_id AND timestamp >= $datefrom AND timestamp <= $dateto ORDER BY timestamp ASC";
@@ -96,7 +97,7 @@ while($row = mysql_fetch_array($data))
#@$data[] = $in_value + $out_value;
#@$in_data[] = $in_value;
#@$out_data[] = $out_value;
- #@$ticks[] = $timestamp;
+# @$ticks[] = $timestamp;
#@$per_data[] = $rate_95th / 1000;
#@$ave_data[] = $rate_average / 1000;
@@ -111,7 +112,7 @@ while($row = mysql_fetch_array($data))
$out_data[$i] = round($iter_out * 8 / $iter_period / $div, 2);
$in_data[$i] = round($iter_in * 8 / $iter_period / $div, 2);
$tot_data[$i] = $out_data[$i] + $in_data[$i];
-# $ticks[$i] = date('M j g:ia', $timestamp);
+ $ticks[$i] = date('M j g:ia', $timestamp);
$ticks[$i] = $timestamp;
if($dur < 172800) {
@@ -170,10 +171,10 @@ $graph->title->Set("$graph_name");
$graph->title->SetFont(FF_FONT2,FS_BOLD,10);
$graph->xaxis->SetFont(FF_FONT1,FS_BOLD);
-$graph->xaxis->SetTickLabels($ticks);
+#$graph->xaxis->SetTickLabels($ticks);
if(count($tickPositions) > 24) {
- $graph->xaxis->SetTextLabelInterval(3);
+ $graph->xaxis->SetTextLabelInterval(6);
}elseif(count($tickPositions) > 12) {
$graph->xaxis->SetTextLabelInterval(2);
}
diff --git a/html/includes/authenticate.inc.php b/html/includes/authenticate.inc.php
index 6b0b127ec..14f08acdf 100644
--- a/html/includes/authenticate.inc.php
+++ b/html/includes/authenticate.inc.php
@@ -74,6 +74,8 @@ if (isset($_SESSION['username']))
setcookie("username", $_SESSION['username'], time()+60*60*24*100, "/");
setcookie("password", $_SESSION['password'], time()+60*60*24*100, "/");
}
+ $permissions = permissions_cache($_SESSION['user_id']);
+
}
elseif (isset($_SESSION['username']))
{
diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php
index a8b2af26e..c0c26f5be 100644
--- a/html/includes/functions.inc.php
+++ b/html/includes/functions.inc.php
@@ -125,7 +125,8 @@ function print_graph_popup($graph_array)
-function permissions_cache($user_id) {
+function permissions_cache($user_id)
+{
$permissions = array();
$query = mysql_query("SELECT * FROM devices_perms WHERE user_id = '".$user_id."'");
while($device = mysql_fetch_assoc($query)) {
@@ -135,9 +136,26 @@ function permissions_cache($user_id) {
while($port = mysql_fetch_assoc($query)) {
$permissions['port'][$port['interface_id']] = 1;
}
+ $query = mysql_query("SELECT * FROM bill_perms WHERE user_id = '".$user_id."'");
+ while($bill = mysql_fetch_assoc($query)) {
+ $permissions['bill'][$bill['bill_id']] = 1;
+ }
return $permissions;
}
+function bill_permitted($bill_id)
+{
+ global $_SESSION; global $permissions;
+ if ($_SESSION['userlevel'] >= "5") {
+ $allowed = TRUE;
+ } elseif ( $permissions['bill'][$bill_id]) {
+ $allowed = TRUE;
+ } else {
+ $allowed = FALSE;
+ }
+ return $allowed;
+
+}
function interfacepermitted($interface_id, $device_id = NULL)
{
global $_SESSION; global $permissions;
diff --git a/html/includes/graphs/bill/auth.inc.php b/html/includes/graphs/bill/auth.inc.php
new file mode 100644
index 000000000..eeda40913
--- /dev/null
+++ b/html/includes/graphs/bill/auth.inc.php
@@ -0,0 +1,17 @@
+
diff --git a/html/includes/graphs/bill/bits.inc.php b/html/includes/graphs/bill/bits.inc.php
new file mode 100644
index 000000000..180e9229f
--- /dev/null
+++ b/html/includes/graphs/bill/bits.inc.php
@@ -0,0 +1,28 @@
+
diff --git a/html/index.php b/html/index.php
index 1db387b6e..ec635ed54 100755
--- a/html/index.php
+++ b/html/index.php
@@ -17,10 +17,6 @@ if(strpos($_SERVER['REQUEST_URI'], "debug")) {
include("../includes/functions.php");
include("includes/functions.inc.php");
include("includes/authenticate.inc.php");
- if($_SESSION['authenticated']) {
- # Load permissions used my devicepermitted() and interfacepermitted()
- $permissions = permissions_cache($_SESSION['user_id']);
- }
$start = utime();
$now = time();
diff --git a/html/pages/bill.inc.php b/html/pages/bill.inc.php
index 23d214a39..ab2db92d5 100644
--- a/html/pages/bill.inc.php
+++ b/html/pages/bill.inc.php
@@ -1,202 +1,245 @@
= 1000000) { $paidrate_text = $paid_mb . "Mbps is the CDR."; }
+
+ $day_data = getDates($dayofmonth);
+ $datefrom = $day_data['0'];
+ $dateto = $day_data['1'];
+ $rate_data = getRates($bill_id,$datefrom,$dateto);
+ $rate_95th = $rate_data['rate_95th'];
+ $dir_95th = $rate_data['dir_95th'];
+ $total_data = $rate_data['total_data'];
+ $rate_average = $rate_data['rate_average'];
+
+ if ($rate_95th > $paid_kb) {
+ $over = $rate_95th - $paid_kb;
+ $bill_text = $over . "Kbit excess.";
+ $bill_color = "#cc0000";
+ } else {
+ $under = $paid_kb - $rate_95th;
+ $bill_text = $under . "Kbit headroom.";
+ $bill_color = "#0000cc";
+ }
+
+ $fromtext = mysql_result(mysql_query("SELECT DATE_FORMAT($datefrom, '%M %D %Y')"), 0);
+ $totext = mysql_result(mysql_query("SELECT DATE_FORMAT($dateto, '%M %D %Y')"), 0);
+ $unixfrom = mysql_result(mysql_query("SELECT UNIX_TIMESTAMP('$datefrom')"), 0);
+ $unixto = mysql_result(mysql_query("SELECT UNIX_TIMESTAMP('$dateto')"), 0);
+
+ echo(" ".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $left_background, $percent . "%", "ffffff", $right_background)." ".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $left_background, $percent . "%", "ffffff", $right_background)." Billing Period : " . $fromtext . " to " . $totext . "
+ " . $bill_name . "
");
+
+ print_optionbar_start();
+
+ if(!$_GET['optb']) { $_GET['optb'] = "details"; }
+
+ if($_GET['optb'] == "details") { echo(""); }
+ echo("Details");
+ if($_GET['optb'] == "details") { echo(""); }
+
+ echo(" | ");
+ if($_GET['optb'] == "edit") { echo(""); }
+ echo("Edit");
+ if($_GET['optb'] == "edit") { echo(""); }
+
+ print_optionbar_end();
+
+ echo("
+ # ");
+
+
+ if($_GET['optb'] == "edit") {
+
+ include("pages/bill/edit.php");
+
+ }elseif($_GET['optb'] == "details") {
+
+
+ echo(" Billed Ports
");
+
+ $ports = mysql_query("SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D
+ WHERE B.bill_id = '".$bill_id."' AND P.interface_id = B.port_id
+ AND D.device_id = P.device_id");
+
+ while ($port = mysql_fetch_array($ports)) {
+
+ echo(generateiflink($port) . " on " . generatedevicelink($port) . "
");
+
+ }
+
+ echo("Bill Summary
");
+
+ if($bill_data['bill_type'] == "quota") {
+
+ // The Customer is billed based on a pre-paid quota
+
+ echo("Quota Bill
");
+
+ $percent = round(($total_data / 1024) / $bill_data['bill_gb'] * 100, 2);
+ $unit = "MB";
+ $total_data = round($total_data, 2);
+ echo("Billing Period from " . $fromtext . " to " . $totext . "
+
Transferred ".formatStorage($total_data * 1024 * 1024)." of ".formatStorage($bill_data['bill_gb'] * 1024 * 1024 * 1024)." (".$percent."%)
+
Average rate " . formatRates($rate_average * 1000));
+
+ if ($percent > 100) { $perc = "100"; } else { $perc = $percent; }
+ if($perc > '90') { $left_background='c4323f'; $right_background='C96A73';
+ } elseif($perc > '75') { $left_background='bf5d5b'; $right_background='d39392';
+ } elseif($perc > '50') { $left_background='bf875b'; $right_background='d3ae92';
+ } elseif($perc > '25') { $left_background='5b93bf'; $right_background='92b7d3';
+ } else { $left_background='9abf5b'; $right_background='bbd392'; }
+
+ echo("CDR / 95th Bill
");
+
+ $unit = "kbps";
+ $cdr = $bill_data['bill_cdr'];
+ if($rate_95th > "1000") { $rate_95th = $rate_95th / 1000; $cdr = $cdr / 1000; $unit = "Mbps"; }
+ if($rate_95th > "1000") { $rate_95th = $rate_95th / 1000; $cdr = $cdr / 1000; $unit = "Gps"; }
+ $rate_95th = round($rate_95th, 2);
+
+ $percent = round(($rate_95th) / $cdr * 100, 2);
+
+ $type="&95th=yes";
+
+ echo("" . $fromtext . " to " . $totext . "
+
Measured ".$rate_95th."$unit of ".$cdr."$unit (".$percent."%)");
+
+ if ($percent > 100) { $perc = "100"; } else { $perc = $percent; }
+ if($perc > '90') { $left_background='c4323f'; $right_background='C96A73';
+ } elseif($perc > '75') { $left_background='bf5d5b'; $right_background='d39392';
+ } elseif($perc > '50') { $left_background='bf875b'; $right_background='d3ae92';
+ } elseif($perc > '25') { $left_background='5b93bf'; $right_background='92b7d3';
+ } else { $left_background='9abf5b'; $right_background='bbd392'; }
+
+ echo("
+ # " . $paidrate_text . "
+ # " . $total_data . "MB transfered in the current billing cycle.
+ # " . $rate_average . "Kbps Average during the current billing cycle. 
");
+
+ }
+
+ echo("

");
-
-
-if($_GET['optb'] == "edit") {
-
- include("pages/bill/edit.php");
-
-}elseif($_GET['optb'] == "details") {
-
-
-echo("Billed Ports"); - -$ports = mysql_query("SELECT * FROM interfaces AS I, devices AS D, bill_ports as B WHERE B.bill_id = '$bill_id' AND B.port_id = I.interface_id AND I.device_id = D.device_id"); - -while ($port = mysql_fetch_array($ports)) { - - echo(generateiflink($port) . " on " . generatedevicelink($port) . ""); + include("includes/error-no-perm.inc.php"); } - -echo(" Bill Summary"); - -if($bill_data['bill_type'] == "quota") { - - // The Customer is billed based on a pre-paid quota - - $percent = round(($total_data / 1024) / $bill_data['bill_gb'] * 100, 2); - $unit = "MB"; - $total_data = round($total_data, 2); - echo("Billing Period from " . $fromtext . " to " . $totext . " -Transferred ".formatStorage($total_data * 1024 * 1024)." of ".formatStorage($bill_data['bill_gb'] * 1024 * 1024 * 1024)." (".$percent."%) - Average rate " . formatRates($rate_average * 1000)); - if ($percent > 100) { $percent = "100"; } - echo(" Measured ".$rate_95th."$unit of ".$cdr."$unit (".$percent."%)"); - if ($percent > 100) { $percent = "100"; } - echo(" Billing Period : " . $fromtext . " to " . $totext . " | ![]() |

| $type | $allowed | $used | -- | Edit |
+ ".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $left_background, $percent . "%", "ffffff", $right_background)." | + Edit |