<?php
include('../../config.inc.php');
Session::start();
include('../tabs/attrshow.php');
$oreon=$_SESSION['oreon'];
$num = 0;
$pullUser=$_POST["usr"];
$buttonID=$_POST["buttonID"];
$timemax=$_POST["time"];
$octets=$_POST["octet"];
$datef=$_POST["expiration"];
$billingplan=$_POST["billingplan"];
$hname=$oreon->phpmyprepaid['client_name'];
$dateFormat=$oreon->phpmyprepaid['display_date_format'];
$octet_type=$oreon->phpmyprepaid['octet_type'];
$query2="SELECT TimeBp,PriceBp from BillingPlan WHERE Id='".$billingplan."'";
$result2 = $_SESSION["oreon"]->database->database->query($query2);
$row = $oreon->database->database->fetch_array($result2);
$time = $row['TimeBp'];
$Price = $row['PriceBp'];
$Currency = $row['CurrencyBp'];
if ($timemax!='')
{
$ext="available ".$timemax." Min";
}
if ($octets!='')
{
$ext="For ".$octets." Mo";
}
if ($datef!='')
{
$ext=" until ".$datef;
}
echo '
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title></title>
</head>
<body>
<CENTER>
<table
style="width: 725px; height: 31px; text-align: center; margin-right: 0px; margin-left: 40px;"
border="0" cellpadding="2" cellspacing="2">
<tbody text-align: center; >
<tr>
<td><span
style="font-weight: bold; text-align: center;"><h1>'.$hname.'</span></td>
</tr>
</tbody>
</table>
<br>
<br>
<br></center>';
echo "Created the : <b>".date($dateFormat);
echo '<center><table style="text-align: left; width: 725px; height: 60px;"
border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="width: 100px;"></td>
<td style="width: 1076px; text-align: center;"><img
style="width: 235px; height: 182px;" alt=""
src="../../images/logo.png"></td>
</tbody>
</table>
<br>
<br>
<table style="text-align: left; width: 548px; height: 54px;"
border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td><span style="font-family: Courier;">Internet
Invoice for user '.$pullUser.', '.$ext.' </span></td>
</tr>
</tbody>
</table>
<br>
<br>
<table style="text-align: left; width: 927px;" border="2" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="width: 214px;">Logged in</td>
<td style="width: 101px;">Upload</td>';
if ($buttonID !="bill_user_time")
{
echo '<td style="width: 281px;">Session Time</td>';
echo '<td style="width: 188px;">Terminate Cause</td>';
echo '<td style="width: 101px;">Download</td>';
}
else
{
echo '<td style="width: 101px;">Download</td>';
echo '<td style="width: 188px;">Terminate Cause</td>';
echo '<td style="width: 281px;">Session Time</td>';
}
echo '</tr>';
$search = "SELECT * FROM $sql_accounting_table WHERE username = '$pullUser' ORDER BY acctstarttime;";
$acct_sessiontime_sum='';
$acct_upload_sum='';
$acct_download_sum='';
$result = $_SESSION["oreon"]->database->database->query($search);
if ($result){
$arrayres=$oreon->database->database->fetch_array($result);
while( $arrayres != NULL && $row = array_change_key_case($arrayres)) {
$arrayres=$oreon->database->database->fetch_array($result);
$tr_color='White';
$num++;
$acct_logedin = $row['acctstarttime'];
$acct_sessiontime = $row['acctsessiontime'];
$acct_sessiontime_sum += $acct_sessiontime;
$acct_sessiontime = time2str($acct_sessiontime);
$acct_upload = $row[$acctinputoctetsattr];
$acct_upload_sum += $acct_upload;
$acct_upload = octets2str($acct_upload);
$acct_download = $row[$acctoutputoctetsattr];
$acct_download_sum += $acct_download;
$acct_download = octets2str($acct_download);
$acct_terminate_cause = $row['acctterminatecause'];
if ($acct_terminate_cause == '')
$acct_terminate_cause = '-';
if (ereg('Login-Incorrect',$acct_terminate_cause) ||
ereg('Multiple-Logins', $acct_terminate_cause) || ereg('Invalid-User',$acct_terminate_cause))
$tr_color='#ffe8e0';
$acct_callerid = $row['callingstationid'];
if ($acct_callerid == '')
$acct_callerid = '-';
echo " <tr align=center bgcolor=\"$tr_color\">";
echo "<td style=\"width: 214px;\" class=\"bl\" >$acct_logedin</td>\n";
echo "<td style=\"width: 101px;\" class=\"bl\" >$acct_upload</td>\n";
if ($buttonID=="bill_user_time")
{ echo "<td style=\"width: 101px;\" class=\"bl\" >$acct_download</td>\n";}
else
{ echo "<td style=\"width: 281px;\" class=\"bl\" >$acct_sessiontime</td>\n";}
echo "<td style=\"width: 188px;\" class=\"bl\" >$acct_terminate_cause</td>\n";
if ($buttonID!="bill_user_time")
{ echo "<td style=\"width: 101px;\" class=\"bl\" >$acct_download</td>\n";}
else
{ echo "<td style=\"width: 281px;\" class=\"bl\" >$acct_sessiontime</td>\n";}
echo "</tr>\n";
}
$acct_sessiontime_sum_final = time2str($acct_sessiontime_sum);
}
else
echo "<b>Database query failed: </b><br>\n";
echo '
<tr>
<td colspan="3" rowspan="2" style="width: 214px;"></td>
<td style="width: 188px;">Total</td>';
if ($buttonID=="bill_user_time")
{
echo "<td style=\"width: 281px;\">$acct_sessiontime_sum_final</td>";
}
else if ($buttonID=="bill_user_octet")
{
echo "<td style=\"width: 101px;\">$tot_output</td>";
}
if ($result2 != NULL)
{
if ($buttonID=="bill_user_time" and $time != 0)
{
$Price=($timemax*$Price)/$time;
}
else if ($buttonID=="bill_user_octet" and $octets != 0 and $time != 0)
{
if ($tot_ouputg>($octets*1024*1024))
{
$calc=($tot_outputg)/($octets*1024*1024);
$Price=($calc*$Price)/($time*1024*1024);
}
}
}
echo '</tr>
<tr>
<td style="width: 188px;">Price</td>
<td style="width: 281px;">'.$Price.' '.$Currency.'</td>
</tr>
</tbody>
</table>
</CENTER>
</body></html>';
?>