mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
implement standard URL scheme for billing.
git-svn-id: http://www.observium.org/svn/observer/trunk@2753 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
$bill_id = mres($_GET['opta']);
|
||||
$bill_id = mres($vars['bill_id']);
|
||||
|
||||
|
||||
if ($_SESSION['userlevel'] == "10")
|
||||
{
|
||||
@@ -9,7 +10,7 @@ if ($_SESSION['userlevel'] == "10")
|
||||
|
||||
if (bill_permitted($bill_id))
|
||||
{
|
||||
$bill_data = dbFetchRow("SELECT * FROM bills WHERE bill_id = ? LIMIT 1", array($bill_id));
|
||||
$bill_data = dbFetchRow("SELECT * FROM bills WHERE bill_id = ? LIMIT 1", $bill_id);
|
||||
$bill_name = $bill_data['bill_name'];
|
||||
|
||||
$today = str_replace("-", "", dbFetchCell("SELECT CURDATE()"));
|
||||
@@ -68,9 +69,14 @@ if (bill_permitted($bill_id))
|
||||
|
||||
$unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')");
|
||||
$unix_prev_to = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastto')");
|
||||
|
||||
# Speeds up loading for other included pages by setting it before progessing of mysql data!
|
||||
|
||||
$ports = dbFetchRows("SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D
|
||||
WHERE B.bill_id = ? AND P.interface_id = B.port_id
|
||||
AND D.device_id = P.device_id", array($bill_id));
|
||||
|
||||
|
||||
|
||||
echo("<font face=\"Verdana, Arial, Sans-Serif\"><h2>
|
||||
Bill : " . $bill_name . "</h2>");
|
||||
|
||||
@@ -80,67 +86,67 @@ if (bill_permitted($bill_id))
|
||||
echo("<span style='font-weight: bold;'>Bill</span> » ");
|
||||
|
||||
|
||||
if (!$_GET['optb']) { $_GET['optb'] = "details"; }
|
||||
if ($_GET['opta'] == "admin_history") { $_GET['optb'] = $_GET['opta']; }
|
||||
if (!$vars['view']) { $vars['view'] = "quick"; }
|
||||
if ($_GET['opta'] == "admin_history") { $vars['view'] = $_GET['opta']; }
|
||||
|
||||
|
||||
if ($_GET['optb'] == "basic") { echo("<span class='pagemenu-selected'>"); }
|
||||
echo("<a href='bill/".$bill_id."/basic/'>Quick Graphs</a>");
|
||||
if ($_GET['optb'] == "basic") { echo("</span>"); }
|
||||
if ($vars['view'] == "basic") { echo("<span class='pagemenu-selected'>"); }
|
||||
echo('<a href="'.generate_url($vars, array('view' => 'quick')).'">Quick Graphs</a>');
|
||||
if ($vars['view'] == "basic") { echo("</span>"); }
|
||||
|
||||
echo(" | ");
|
||||
|
||||
if ($_GET['optb'] == "details") { echo("<span class='pagemenu-selected'>"); }
|
||||
echo("<a href='bill/".$bill_id."/details/'>Accurate Graphs</a>");
|
||||
if ($_GET['optb'] == "details") { echo("</span>"); }
|
||||
if ($vars['view'] == "details") { echo("<span class='pagemenu-selected'>"); }
|
||||
echo('<a href="'.generate_url($vars, array('view' => 'accurate')).'">Accurate Graphs</a>');
|
||||
if ($vars['view'] == "details") { echo("</span>"); }
|
||||
|
||||
echo(" | ");
|
||||
|
||||
if ($_GET['optb'] == "bandwidth") { echo("<span class='pagemenu-selected'>"); }
|
||||
echo("<a href='bill/".$bill_id."/bandwidth/'>Bandwidth Graphs</a>");
|
||||
if ($_GET['optb'] == "bandwidth") { echo("</span>"); }
|
||||
if ($vars['view'] == "transfer") { echo("<span class='pagemenu-selected'>"); }
|
||||
echo('<A href="'.generate_url($vars, array('view' => 'transfer')).'">Transfer Graphs</a>');
|
||||
if ($vars['view'] == "transfer") { echo("</span>"); }
|
||||
|
||||
echo(" | ");
|
||||
|
||||
if ($_GET['optb'] == "history") { echo("<span class='pagemenu-selected'>"); }
|
||||
echo("<a href='bill/".$bill_id."/history/'>Historical Usage</a>");
|
||||
if ($_GET['optb'] == "history") { echo("</span>"); }
|
||||
if ($vars['view'] == "history") { echo("<span class='pagemenu-selected'>"); }
|
||||
echo('<A href="'.generate_url($vars, array('view' => 'history')).'">Historical Usage</a>');
|
||||
if ($vars['view'] == "history") { echo("</span>"); }
|
||||
|
||||
if ($_SESSION['userlevel'] == "10")
|
||||
{
|
||||
echo(" | ");
|
||||
if ($_GET['optb'] == "edit") { echo("<span class='pagemenu-selected'>"); }
|
||||
echo("<a href='bill/".$bill_id."/edit/'>Edit</a>");
|
||||
if ($_GET['optb'] == "edit") { echo("</span>"); }
|
||||
if ($vars['view'] == "edit") { echo("<span class='pagemenu-selected'>"); }
|
||||
echo('<A href="'.generate_url($vars, array('view' => 'edit')).'">Edit</a>');
|
||||
if ($vars['view'] == "edit") { echo("</span>"); }
|
||||
|
||||
echo(" | ");
|
||||
if ($_GET['optb'] == "delete") { echo("<span class='pagemenu-selected'>"); }
|
||||
echo("<a href='bill/".$bill_id."/delete/'>Delete</a>");
|
||||
if ($_GET['optb'] == "delete") { echo("</span>"); }
|
||||
if ($vars['view'] == "delete") { echo("<span class='pagemenu-selected'>"); }
|
||||
echo('<A href="'.generate_url($vars, array('view' => 'delete')).'">Delete</a>');
|
||||
if ($vars['view'] == "delete") { echo("</span>"); }
|
||||
}
|
||||
|
||||
echo('<div style="font-weight: bold; float: right;"><a href="bills/"><img align=absmiddle src="/images/16/arrow_left.png"> Back to Bills</a></div>');
|
||||
echo('<div style="font-weight: bold; float: right;"><a href="'.generate_url(array('page' => "bills")).'/"><img align=absmiddle src="/images/16/arrow_left.png"> Back to Bills</a></div>');
|
||||
|
||||
|
||||
print_optionbar_end();
|
||||
|
||||
if ($_GET['optb'] == "edit" && $_SESSION['userlevel'] == "10")
|
||||
if ($vars['view'] == "edit" && $_SESSION['userlevel'] == "10")
|
||||
{
|
||||
include("pages/bill/edit.inc.php");
|
||||
}
|
||||
elseif ($_GET['optb'] == "delete" && $_SESSION['userlevel'] == "10")
|
||||
elseif ($vars['view'] == "delete" && $_SESSION['userlevel'] == "10")
|
||||
{
|
||||
include("pages/bill/delete.inc.php");
|
||||
}
|
||||
elseif ($_GET['optb'] == "history")
|
||||
elseif ($vars['view'] == "history")
|
||||
{
|
||||
include("pages/bill/history.inc.php");
|
||||
}
|
||||
elseif ($_GET['optb'] == "bandwidth")
|
||||
elseif ($vars['view'] == "transfer")
|
||||
{
|
||||
include("pages/bill/bandwidth.inc.php");
|
||||
include("pages/bill/transfer.inc.php");
|
||||
}
|
||||
elseif ($_GET['optb'] == "details" || $_GET['optb'] == "basic") {
|
||||
elseif ($vars['view'] == "quick" || $vars['view'] == "accurate") {
|
||||
|
||||
$bill_data = dbFetchRow("SELECT * FROM bills WHERE bill_id = ?", array($bill_id));
|
||||
|
||||
@@ -202,10 +208,7 @@ if (bill_permitted($bill_id))
|
||||
|
||||
echo("<h3>Billed Ports</h3>");
|
||||
|
||||
$ports = dbFetchRows("SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D
|
||||
WHERE B.bill_id = ? AND P.interface_id = B.port_id
|
||||
AND D.device_id = P.device_id", array($bill_id));
|
||||
|
||||
### Collected Earlier
|
||||
foreach ($ports as $port)
|
||||
{
|
||||
echo(generate_port_link($port) . " on " . generate_device_link($port) . "<br />");
|
||||
@@ -219,11 +222,11 @@ if (bill_permitted($bill_id))
|
||||
|
||||
echo("<h4>Quota Bill</h4>");
|
||||
|
||||
$percent = round(($total_data / 1024) / $bill_data['bill_gb'] * 100, 2);
|
||||
$percent = round(($total_data / 1000) / $bill_data['bill_gb'] * 100, 2);
|
||||
$unit = "MB";
|
||||
$total_data = round($total_data, 2);
|
||||
echo("Billing Period from " . $fromtext . " to " . $totext . "
|
||||
<br />Transferred ".formatStorage($total_data * 1024 * 1024)." of ".formatStorage($bill_data['bill_gb'] * 1024 * 1024 * 1024)." (".$percent."%)
|
||||
<br />Transferred ".formatStorage($total_data * 1000 * 1000)." of ".formatStorage($bill_data['bill_gb'] * 1000 * 1000 * 1000)." (".$percent."%)
|
||||
<br />Average rate " . formatRates($rate_average * 1000));
|
||||
|
||||
$background = get_percentage_colours($percent);
|
||||
@@ -276,7 +279,7 @@ if (bill_permitted($bill_id))
|
||||
$yesterday = dbFetchCell("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))");
|
||||
$rightnow = date(U);
|
||||
|
||||
if ($_GET['optb'] == "details") {
|
||||
if ($vars['view'] == "accurate") {
|
||||
|
||||
$bi = "<img src='billing-graph.php?bill_id=" . $bill_id . "&bill_code=" . $_GET['bill_code'];
|
||||
$bi .= "&from=" . $unixfrom . "&to=" . $unixto;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
$pagetitle[] = "Historical Usage";
|
||||
$detail = (isset($_GET['detail']) ? $_GET['detail'] : "");
|
||||
$url = $PHP_SELF."/bill/".$bill_id."/history/";
|
||||
// $detail = (isset($vars['detail']) ? $vars['detail'] : "");
|
||||
// $url = $PHP_SELF."/bill/".$bill_id."/history/";
|
||||
$i = 0;
|
||||
|
||||
$gbconvert = $config['billing']['base'];
|
||||
@@ -14,10 +14,10 @@
|
||||
|
||||
echo($img['his']);
|
||||
|
||||
function showDetails($id, $imgtype, $from, $to, $bittype = "Quota")
|
||||
function showDetails($bill_id, $imgtype, $from, $to, $bittype = "Quota")
|
||||
{
|
||||
if ($imgtype == "bitrate") {
|
||||
$res = "<img src=\"billing-graph.php?bill_id=".$id;
|
||||
$res = "<img src=\"billing-graph.php?bill_id=".$bill_id;
|
||||
if ($bittype == "Quota")
|
||||
{
|
||||
$res .= "&ave=yes";
|
||||
@@ -27,7 +27,7 @@
|
||||
}
|
||||
} else
|
||||
{
|
||||
$res = "<img src=\"bandwidth-graph.php?bill_id=".$id;
|
||||
$res = "<img src=\"bandwidth-graph.php?bill_id=".$bill_id;
|
||||
}
|
||||
//$res .= "&type=".$type;
|
||||
$res .= "&type=".$imgtype;
|
||||
@@ -37,6 +37,9 @@
|
||||
return $res;
|
||||
}
|
||||
|
||||
// $url = generate_url($vars, array('detail' => 'yes'));
|
||||
$url = $PHP_SELF."/bill/".$bill_id."/history/detail=all/";
|
||||
|
||||
echo("<table border=0 cellspacing=0 cellpadding=5 class=devicetable width=100%>
|
||||
<tr style=\"font-weight: bold; \">
|
||||
<td width=\"7\"></td>
|
||||
@@ -48,10 +51,10 @@
|
||||
<td>Total</td>
|
||||
<td>95 percentile</td>
|
||||
<td style=\"text-align: center;\">Overusage</td>
|
||||
<td colspan=\"2\" style=\"text-align: right;\"><a href=\"".$url."?detail=all\"><img src=\"images/16/chart_curve.png\" border=\"0\" align=\"absmiddle\" alt=\"Show details\" title=\"Show details\" /> Show all details</a></td>
|
||||
<td colspan=\"2\" style=\"text-align: right;\"><a href=\"".generate_url($vars, array('detail' => "all"))."\"><img src=\"images/16/chart_curve.png\" border=\"0\" align=\"absmiddle\" alt=\"Show details\" title=\"Show details\" /> Show all details</a></td>
|
||||
</tr>");
|
||||
|
||||
foreach (dbFetchRows("SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` AND `bill_dateto` DESC LIMIT 24", array($bill_id)) as $history)
|
||||
foreach (dbFetchRows("SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` DESC LIMIT 24", array($bill_id)) as $history)
|
||||
{
|
||||
if (bill_permitted($history['bill_id']))
|
||||
{
|
||||
@@ -85,6 +88,8 @@
|
||||
$total_data = (($type == "Quota") ? "<b>".$total_data."</b>" : $total_data);
|
||||
$rate_95th = (($type == "CDR") ? "<b>".$rate_95th."</b>" : $rate_95th);
|
||||
|
||||
$url = generate_url($vars, array('detail' => $history['id']));
|
||||
|
||||
echo("
|
||||
<tr style=\"background: ".$row_colour.";\">
|
||||
<td></td>
|
||||
@@ -98,15 +103,15 @@
|
||||
<td style=\"text-align: center;\">$overuse</td>
|
||||
<td width=\"250\">".print_percentage_bar(250, 20, $perc, NULL, "ffffff", $background['left'], $percent."%", "ffffff", $background['right'])."</td>
|
||||
<td>
|
||||
<a href=\"".$url."?detail=".($i+1)."\"><img src=\"images/16/chart_curve.png\" border=\"0\" align=\"absmiddle\" alt=\"Show details\" title=\"Show details\"/></a>
|
||||
<a href=\"".$url."\"><img src=\"images/16/chart_curve.png\" border=\"0\" align=\"absmiddle\" alt=\"Show details\" title=\"Show details\"/></a>
|
||||
<a href=\"#\"><img src=\"images/16/page_white_acrobat.png\" border=\"0\" align=\"absmiddle\" alt=\"PDF Report\" title=\"PDF Report\"/></a>
|
||||
</td>
|
||||
</tr>");
|
||||
|
||||
if ($detail == ($i+1) || $detail == "all") {
|
||||
$img['bitrate'] = showDetails($history['bill_id'], "bitrate", strtotime($datefrom), strtotime($dateto), $type);
|
||||
$img['bw_day'] = showDetails($history['bill_id'], "day", strtotime($datefrom), strtotime($dateto));
|
||||
$img['bw_hour'] = showDetails($history['bill_id'], "hour", strtotime($datefrom), strtotime($dateto));
|
||||
if ($vars['detail'] == $history['id'] || $vars['detail'] == "all") {
|
||||
$img['bitrate'] = showDetails($bill_id, "bitrate", strtotime($datefrom), strtotime($dateto), $type);
|
||||
$img['bw_day'] = showDetails($bill_id, "day", strtotime($datefrom), strtotime($dateto));
|
||||
$img['bw_hour'] = showDetails($bill_id, "hour", strtotime($datefrom), strtotime($dateto));
|
||||
echo("
|
||||
<tr style=\"background: #fff; border-top: 1px solid ".$row_colour."; border-bottom: 1px solid #ccc;\">
|
||||
<td colspan=\"11\">
|
||||
|
||||
@@ -36,10 +36,6 @@
|
||||
|
||||
echo("<h3>Billed Ports</h3>");
|
||||
|
||||
$ports = dbFetchRows("SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D
|
||||
WHERE B.bill_id = ? AND P.interface_id = B.port_id
|
||||
AND D.device_id = P.device_id", array($bill_id));
|
||||
|
||||
foreach ($ports as $port)
|
||||
{
|
||||
echo(generate_port_link($port) . " on " . generate_device_link($port) . "<br />");
|
||||
@@ -117,12 +117,12 @@ elseif ($_GET['opta'] == "add")
|
||||
$overuse = (($overuse <= 0) ? "-" : "<span style=\"color: #".$background['left']."; font-weight: bold;\">".formatRates($overuse * 1000)."</span>");
|
||||
} elseif ($bill['bill_type'] == "quota") {
|
||||
$type = "Quota";
|
||||
$allowed = formatStorage($bill['bill_gb']* 1024 * 1024 * 1024);
|
||||
$used = formatStorage($rate_data['total_data'] * 1024 * 1024);
|
||||
$percent = round(($rate_data['total_data'] / ($bill['bill_gb'] * 1024)) * 100,2);
|
||||
$allowed = formatStorage($bill['bill_gb']* 1000 * 1000 * 1000);
|
||||
$used = formatStorage($rate_data['total_data'] * 1000 * 1000);
|
||||
$percent = round(($rate_data['total_data'] / ($bill['bill_gb'] * 1000)) * 100,2);
|
||||
$background = get_percentage_colours($percent);
|
||||
$overuse = $rate_data['total_data'] - ($bill['bill_gb'] * 1024);
|
||||
$overuse = (($overuse <= 0) ? "-" : "<span style=\"color: #".$background['left']."; font-weight: bold;\">".formatStorage($overuse * 1024 * 1024)."</span>");
|
||||
$overuse = $rate_data['total_data'] - ($bill['bill_gb'] * 1000);
|
||||
$overuse = (($overuse <= 0) ? "-" : "<span style=\"color: #".$background['left']."; font-weight: bold;\">".formatStorage($overuse * 1000 * 1000)."</span>");
|
||||
}
|
||||
|
||||
$right_background = $background['right'];
|
||||
@@ -132,14 +132,14 @@ elseif ($_GET['opta'] == "add")
|
||||
echo("
|
||||
<tr bgcolor='$row_colour'>
|
||||
<td></td>
|
||||
<td><a href='bill/".$bill['bill_id']."/'><span style='font-weight: bold;' class=interface>".$bill['bill_name']."</span></a><br />".strftime("%F", strtotime($datefrom))." to ".strftime("%F", strtotime($dateto))."</td>
|
||||
<td><a href='".generate_url(array('page' => "bill", 'bill_id' => $bill['bill_id']))."'><span style='font-weight: bold;' class=interface>".$bill['bill_name']."</span></a><br />".strftime("%F", strtotime($datefrom))." to ".strftime("%F", strtotime($dateto))."</td>
|
||||
<td>$notes</td>
|
||||
<td>$type</td>
|
||||
<td>$allowed</td>
|
||||
<td>$used</td>
|
||||
<td style=\"text-align: center;\">$overuse</td>
|
||||
<td>".print_percentage_bar (250, 20, $perc, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right'])."</td>
|
||||
<td><a href='bill/".$bill['bill_id']."/edit/'><img src='images/16/wrench.png' align=absmiddle alt='Edit'> Edit</a></td>
|
||||
<td><a href='".generate_url(array('page' => "bill", 'bill_id' => $bill['bill_id'], 'view' => "edit"))."'><img src='images/16/wrench.png' align=absmiddle alt='Edit'> Edit</a></td>
|
||||
</tr>
|
||||
");
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
$percent = $history['bill_percent'];
|
||||
$dir_95th = $history['dir_95th'];
|
||||
$rate_95th = formatRates($history['rate_95th'] * 1000);
|
||||
$total_data = formatStorage($history['traf_total'] * 1024 * 1024);
|
||||
$total_data = formatStorage($history['traf_total'] * 1000 * 1000);
|
||||
|
||||
$background = get_percentage_colours($percent);
|
||||
$row_colour = ((!is_integer($i/2)) ? $list_colour_a : $list_colour_b);
|
||||
@@ -45,11 +45,11 @@
|
||||
$out = formatRates($history['rate_95th_out'] * 1000);
|
||||
$overuse = (($history['bill_overuse'] <= 0) ? "-" : "<span style=\"color: #".$background['left']."; font-weight: bold;\">".formatRates($history['bill_overuse'] * 1000)."</span>");
|
||||
} elseif ($type == "Quota") {
|
||||
$allowed = formatStorage($history['bill_allowed'] * 1024 * 1024);
|
||||
$used = formatStorage($history['total_data'] * 1024 * 1024);
|
||||
$in = formatStorage($history['traf_in'] * 1024 * 1024);
|
||||
$out = formatStorage($history['traf_out'] * 1024 * 1024);
|
||||
$overuse = (($history['bill_overuse'] <= 0) ? "-" : "<span style=\"color: #".$background['left']."; font-weight: bold;\">".formatStorage($history['bill_overuse'] * 1024 * 1024)."</span>");
|
||||
$allowed = formatStorage($history['bill_allowed'] * 1000 * 1000);
|
||||
$used = formatStorage($history['total_data'] * 1000 * 1000);
|
||||
$in = formatStorage($history['traf_in'] * 1000 * 1000);
|
||||
$out = formatStorage($history['traf_out'] * 1000 * 1000);
|
||||
$overuse = (($history['bill_overuse'] <= 0) ? "-" : "<span style=\"color: #".$background['left']."; font-weight: bold;\">".formatStorage($history['bill_overuse'] * 1000 * 1000)."</span>");
|
||||
}
|
||||
|
||||
$total_data = (($type == "Quota") ? "<b>".$total_data."</b>" : $total_data);
|
||||
|
||||
Reference in New Issue
Block a user