Merge branch 'master' into issue-2193

This commit is contained in:
Aaron Daniels
2016-03-29 20:16:07 +10:00
46 changed files with 4134 additions and 325 deletions

View File

@@ -1,3 +1,4 @@
<h4>Bill Information</h4>
<div class="form-group">
<label for="bill_name" class="col-sm-4 control-label">Description</label>
<div class="col-sm-8">

View File

@@ -150,16 +150,7 @@
<?php
$devices = dbFetchRows('SELECT * FROM `devices` ORDER BY hostname');
foreach ($devices as $device) {
unset($done);
foreach ($access_list as $ac) {
if ($ac == $device['device_id']) {
$done = 1;
}
}
if (!$done) {
echo " <option value='".$device['device_id']."'>".$device['hostname']."</option>\n";
}
echo "<option value='${device['device_id']}'>${device['hostname']}</option>\n";
}
?>

View File

@@ -75,8 +75,8 @@ if ($_POST['addbill'] == 'yes') {
$bill_id = dbInsert($insert, 'bills');
if (is_numeric($bill_id) && is_numeric($_POST['port'])) {
dbInsert(array('bill_id' => $bill_id, 'port_id' => $_POST['port']), 'bill_ports');
if (is_numeric($bill_id) && is_numeric($_POST['port_id'])) {
dbInsert(array('bill_id' => $bill_id, 'port_id' => $_POST['port_id']), 'bill_ports');
}
header('Location: /' . generate_url(array('page' => 'bill', 'bill_id' => $bill_id, 'view' => 'edit')));
@@ -87,116 +87,90 @@ $pagetitle[] = 'Billing';
echo "<meta http-equiv='refresh' content='10000'>";
if ($vars['view'] == 'history') {
include 'pages/bills/search.inc.php';
include 'pages/bills/pmonth.inc.php';
}
else {
include 'pages/bills/search.inc.php';
include 'includes/modal/new_bill.inc.php';
include 'includes/modal/new_bill.inc.php';
?>
<table class="table table-striped">
<thead>
<th>Billing name</th>
<th></th>
<th>Type</th>
<th>Allowed</th>
<th>Used</th>
<th>Overusage</th>
<th></th>
<th></th>
</thead>
<tbody>
<?php
$wheres = array();
$params = array();
if (!empty($_GET['search'])) {
$wheres[] = 'bills.bill_name LIKE ?';
$params[] = '%'.$_GET['search'].'%';
}
if (!empty($_GET['bill_type'])) {
$wheres[] = 'bill_type = ?';
$params[] = $_GET['bill_type'];
}
if ($_GET['state'] === 'under') {
$wheres[] = "((bill_type = 'cdr' AND rate_95th <= bill_cdr) OR (bill_type = 'quota' AND total_data <= bill_quota))";
} else if ($_GET['state'] === 'over') {
$wheres[] = "((bill_type = 'cdr' AND rate_95th > bill_cdr) OR (bill_type = 'quota' AND total_data > bill_quota))";
}
<div class="panel panel-default panel-condensed">
<div class="table-responsive">
<table class="table table-hover" id="bills-list">
<thead>
<th data-column-id="bill_name">Billing name</th>
<th data-column-id="notes" data-sortable="false"></th>
<th data-column-id="bill_type">Type</th>
<th data-column-id="bill_allowed" data-align="right">Allowed</th>
<th data-column-id="total_data_in" data-align="right">Inbound</th>
<th data-column-id="total_data_out" data-align="right">Outbound</th>
<th data-column-id="total_data" data-align="right">Total</th>
<th data-column-id="rate_95th" data-align="right">95th Percentile</th>
<th data-column-id="overusage" data-sortable="false" data-align="center">Overusage</th>
<th data-column-id="graph" data-sortable="false"></th>
<th data-column-id="actions" data-sortable="false"></th>
</thead>
</table>
</div>
</div>
<script type="text/html" id="table-header">
<div id="{{ctx.id}}" class="{{css.header}}">
<div class="row">
<div class="col-sm-4">
<?php if ($_SESSION['userlevel'] >= 10) { ?>
<button type="button" class="btn btn-default btn-sm" data-toggle="modal" data-target="#create-bill"><i class="fa fa-plus"></i> Create Bill</button>
<?php } ?>
</div>
<div class="col-sm-8 actionBar">
<span class="form-inline" id="table-filters">
<fieldset class="form-group">
<select name='period' id='period' class="form-control input-sm">
<option value=''>Current Billing Period</option>
<option value='prev'>Previous Billing Period</option>
</select>
<select name='bill_type' id='bill_type' class="form-control input-sm">
<option value=''>All Types</option>
<option value='cdr' <?php if ($_GET['bill_type'] === 'cdr') { echo 'selected'; } ?>>CDR</option>
<option value='quota' <?php if ($_GET['bill_type'] === 'quota') { echo 'selected'; } ?>>Quota</option>
</select>
<select name='state' id='state' class="form-control input-sm">
<option value=''>All States</option>
<option value='under' <?php if ($_GET['state'] === 'under') { echo 'selected'; } ?>>Under Quota</option>
<option value='over' <?php if ($_GET['state'] === 'over') { echo 'selected'; } ?>>Over Quota</option>
</select>
</fieldset>
</span>
<p class="{{css.search}}"></p>
<p class="{{css.actions}}"></p>
</div>
</div>
</div>
</script>
<script type="text/javascript">
var grid = $('#bills-list').bootgrid({
ajax: true,
templates: {
header: $('#table-header').html()
},
columnSelection: false,
rowCount: [10,20,50,100,-1],
post: function() {
return {
id: 'bills',
bill_type: $('select#bill_type').val(),
state: $('select#state').val(),
period: $('select#period').val()
};
},
url: "/ajax_table.php"
}).on("loaded.rs.jquery.bootgrid", function() {
});
$('#table-filters select').on('change', function() { grid.bootgrid('reload'); });
$query = 'SELECT *
FROM `bills`
';
if (sizeof($wheres) > 0) {
$query .= 'WHERE ' . implode(' AND ', $wheres) . "\n";
}
$query .= 'ORDER BY bills.bill_name';
foreach (dbFetchRows($query, $params) as $bill) {
if (bill_permitted($bill['bill_id'])) {
unset($class);
$day_data = getDates($bill['bill_day']);
$datefrom = $day_data['0'];
$dateto = $day_data['1'];
$rate_data = $bill;
$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 ($bill['bill_type'] == 'cdr') {
$type = 'CDR';
$allowed = format_si($bill['bill_cdr']).'bps';
$used = format_si($rate_data['rate_95th']).'bps';
$percent = round((($rate_data['rate_95th'] / $bill['bill_cdr']) * 100), 2);
$background = get_percentage_colours($percent);
$overuse = ($rate_data['rate_95th'] - $bill['bill_cdr']);
$overuse = (($overuse <= 0) ? '-' : '<span style="color: #'.$background['left'].'; font-weight: bold;">'.format_si($overuse).'bps</span>');
}
else if ($bill['bill_type'] == 'quota') {
$type = 'Quota';
$allowed = format_bytes_billing($bill['bill_quota']);
$used = format_bytes_billing($rate_data['total_data']);
$percent = round((($rate_data['total_data'] / ($bill['bill_quota'])) * 100), 2);
$background = get_percentage_colours($percent);
$overuse = ($rate_data['total_data'] - $bill['bill_quota']);
$overuse = (($overuse <= 0) ? '-' : '<span style="color: #'.$background['left'].'; font-weight: bold;">'.format_bytes_billing($overuse).'</span>');
}
$right_background = $background['right'];
$left_background = $background['left'];
?>
<tr>
<td>
<a href='<?php echo generate_url(array('page' => 'bill', 'bill_id' => $bill['bill_id'])) ?>'><span style='font-weight: bold;' class=interface><?php echo $bill['bill_name'] ?></span></a>
<br />
<?php echo strftime('%F', strtotime($datefrom)) ?> to <?php echo strftime('%F', strtotime($dateto)) ?>
</td>
<td><?php echo $notes ?></td>
<td><?php echo $type ?></td>
<td><?php echo $allowed ?></td>
<td><?php echo $used ?></td>
<td style="text-align: center;"><?php echo $overuse ?></td>
<td><?php echo print_percentage_bar(250, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right'])?></td>
<td>
<?php if ($_SESSION['userlevel'] >= 10) { ?>
<a href='<?php echo generate_url(array('page' => 'bill', 'bill_id' => $bill['bill_id'], 'view' => 'edit')) ?>'><img src='images/16/wrench.png' align=absmiddle alt='Edit'> Edit</a>
<?php } ?>
</td>
</tr>
<?php }
}?>
</tbody>
</table>
<?php
if ($vars['view'] == 'add') {
?>
<script type="text/javascript">
$(function() {
$('#create-bill').modal('show');
});
</script>
<?php
}
}
}
?>
</script>

View File

@@ -1,98 +0,0 @@
<?php
$no_refresh = true;
$pagetitle[] = 'Previous Billing Period';
echo '<table class="table table-condensed table-striped">
<thead>
<tr>
<th>Billing name</th>
<th>Type</th>
<th>Allowed</th>
<th>Inbound</th>
<th>Outbound</th>
<th>Total</th>
<th>95 percentile</th>
<th>Overusage</th>
<th></th>
</tr>
</thead>
<tbody>';
$wheres = array();
$params = array();
if (!empty($_GET['search'])) {
$wheres[] = 'bills.bill_name LIKE ?';
$params[] = '%'.$_GET['search'].'%';
}
if (!empty($_GET['bill_type'])) {
$wheres[] = 'bill_history.bill_type = ?';
$params[] = $_GET['bill_type'];
}
if ($_GET['state'] === 'under') {
$wheres[] = 'bill_history.bill_overuse = 0';
} else if ($_GET['state'] === 'over') {
$wheres[] = 'bill_history.bill_overuse > 0';
}
$query = 'SELECT bills.bill_name, bill_history.*
FROM `bills`
INNER JOIN (SELECT bill_id, MAX(bill_hist_id) AS bill_hist_id FROM bill_history WHERE bill_dateto < NOW() AND bill_dateto > subdate(NOW(), 40) GROUP BY bill_id) qLastBills ON bills.bill_id = qLastBills.bill_id
INNER JOIN bill_history ON qLastBills.bill_hist_id = bill_history.bill_hist_id
';
if (sizeof($wheres) > 0) {
$query .= 'WHERE ' . implode(' AND ', $wheres) . "\n";
}
$query .= 'ORDER BY bills.bill_name';
foreach (dbFetchRows($query, $params) as $bill) {
if (bill_permitted($bill['bill_id'])) {
$datefrom = $bill['bill_datefrom'];
$dateto = $bill['bill_dateto'];
unset($class);
$type = $bill['bill_type'];
$percent = $bill['bill_percent'];
$dir_95th = $bill['dir_95th'];
$rate_95th = format_si($bill['rate_95th']).'bps';
$total_data = format_bytes_billing($bill['traf_total']);
$background = get_percentage_colours($percent);
if ($type == 'CDR') {
$allowed = format_si($bill['bill_allowed']).'bps';
$used = format_si($bill['rate_95th']).'bps';
$in = format_si($bill['rate_95th_in']).'bps';
$out = format_si($bill['rate_95th_out']).'bps';
$overuse = (($bill['bill_overuse'] <= 0) ? '-' : '<span style="color: #'.$background['left'].'; font-weight: bold;">'.format_si($bill['bill_overuse']).'bps</span>');
}
else if ($type == 'Quota') {
$allowed = format_bytes_billing($bill['bill_allowed']);
$used = format_bytes_billing($bill['total_data']);
$in = format_bytes_billing($bill['traf_in']);
$out = format_bytes_billing($bill['traf_out']);
$overuse = (($bill['bill_overuse'] <= 0) ? '-' : '<span style="color: #'.$background['left'].'; font-weight: bold;">'.format_bytes_billing($bill['bill_overuse']).'</span>');
}
$total_data = (($type == 'Quota') ? '<b>'.$total_data.'</b>' : $total_data);
$rate_95th = (($type == 'CDR') ? '<b>'.$rate_95th.'</b>' : $rate_95th);
echo "
<tr>
<td><a href=\"".generate_url(array('page' => 'bill', 'bill_id' => $bill['bill_id'], 'view' => 'history', detail => $bill['bill_hist_id'])).'"><span style="font-weight: bold;" class="interface">'.$bill['bill_name'].'</a></span><br />from '.strftime('%x', strtotime($datefrom)).' to '.strftime('%x', strtotime($dateto))."</td>
<td>$type</td>
<td>$allowed</td>
<td>$in</td>
<td>$out</td>
<td>$total_data</td>
<td>$rate_95th</td>
<td style=\"text-align: center;\">$overuse</td>
<td>".print_percentage_bar(250, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']).'</td>
</tr>';
}//end if
}//end foreach
echo '</tbody>
</table>';

View File

@@ -1,40 +0,0 @@
<?php
print_optionbar_start('40');
?>
<form method='get' action='' class="form-inline" role="form">
<fieldset class="form-group">
Bills
<input type="text" name="search" id="search" class="form-control input-sm" value="<?php echo $_GET['search']; ?>" />
<select name='bill_type' id='bill_type' class="form-control input-sm">
<option value=''>All Types</option>
<option value='cdr' <?php if ($_GET['bill_type'] === 'cdr') { echo 'selected'; } ?>>CDR</option>
<option value='quota' <?php if ($_GET['bill_type'] === 'quota') { echo 'selected'; } ?>>Quota</option>
</select>
<select name='state' id='state' class="form-control input-sm">
<option value=''>All States</option>
<option value='under' <?php if ($_GET['state'] === 'under') { echo 'selected'; } ?>>Under Quota</option>
<option value='over' <?php if ($_GET['state'] === 'over') { echo 'selected'; } ?>>Over Quota</option>
</select>
<button type="submit" class="btn btn-default input-sm">Search</button>
</fieldset>
<div class="form-group pull-right">
<?php
if ($vars['view'] == 'history') {
echo '<a class="btn btn-default btn-sm" href="bills/"><i class="fa fa-clock-o"></i> Current Billing Period</a>';
}
else {
echo '<a class="btn btn-default btn-sm" href="bills/view=history/"><i class="fa fa-history"></i> Previous Billing Period</a>';
}
?>
<?php if ($_SESSION['userlevel'] >= 10) { ?>
<button type="button" class="btn btn-default btn-sm" data-toggle="modal" data-target="#create-bill"><i class="fa fa-plus"></i> Create Bill</button>
<?php } ?>
</div>
</form>
<?php
print_optionbar_end();

View File

@@ -248,6 +248,10 @@ $mail_conf = array(
'descr' => 'From email address',
'type' => 'text',
),
array('name' => 'email_html',
'descr' => 'Use HTML emails',
'type' => 'checkbox',
),
array('name' => 'email_sendmail_path',
'descr' => 'Sendmail path',
'type' => 'text',
@@ -854,7 +858,7 @@ echo '
var transport = $this.data("transport");
$.ajax({
type: 'POST',
url: '/ajax_form.php',
url: 'ajax_form.php',
data: { type: "test-transport", transport: transport },
dataType: "json",
success: function(data){