<?php
//////////////////////////////////////////////////////////
// phpMyPrepaid was based on a project known //
// as dhalbe-Admin - a webbased application for //
// simplifying working with a Free-Radius server //
// and an MySQL as Backend-Database. //
// //
// None of the original code or concepts remain //
// in this file. //
//////////////////////////////////////////////////////////
/* Copyright (C) 2004 dhalbe-Admin Project
Copyright (C) 2004 Michael Conrad (hide@address.com),
Copyright (C) 2004 Christian Roedel (hide@address.com)
Copyright (C) 2004 Carl Peterson (hide@address.com)
Copyright (C) 2005 Carl Peterson (hide@address.com)
Copyright (C) 2005 Port Networks LLC.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//////////////////////////////////////////////////////////
// First we set some variables depending //
// on what button was pressed. We also need to //
// check and make sure we have all the data we //
// need to procede with the creation //
//////////////////////////////////////////////////////////
if (!isset($oreon))
exit();
if(isset($msg)){
unset($msg);
}
$location = $_SESSION['locID'];
$locationName=getLocDomain($location); // pulls the domain from the DB
if($buttonID == "timed"){
$type="Hourly";
}
if($buttonID == "octets"){
$type="Octets";
}
if($buttonID == "expiration"){
$type="Expiration";
}
if($buttonID == "subscription_time")
{
$type="Subscription Time";
}
if ($buttonID == "subscription_octets" )
{
$type="Subscription Octets";
}
if ($buttonID == "subscription_mac" )
{
$type="Subscription Mac";
}
if ($buttonID == "subscription_expiration" )
{
$type="Subscription Expiration";
}
if(!isset($type)){
$msg= "$msg <p class=\"error\">Card type not set, this should not happen.</p>";
}
if(!isset($msg)){
//////////////////////////////////////////////////////////
// FORM LAYOUT //
//////////////////////////////////////////////////////////
unset($error);
$phpmyprepaid=$oreon->phpmyprepaid;
$timetofinish=$phpmyprepaid['default_timetofinish'];
$simultanous=$phpmyprepaid['default_simultanous_use'];
$minmoctets=$phpmyprepaid['minimun_moctet_sold'];
$maxmoctets=$phpmyprepaid['maximun_moctet_sold'];
$mintime=$phpmyprepaid['minimun_time_sold'];
$maxtime=$phpmyprepaid['maximun_time_sold'];
$maxmonth=$phpmyprepaid['max_month_old'];
if($type=="Subscription Octets" or $type=="Subscription Time" or $type=="Subscription Expiration" or $type=="Subscription Mac"){
$tp="Account";
$details=1;
}else{
$tp="Card";
$details=0;
}
if ($type=="Hourly")
$q1 = "select Id,NameBp,TimeBp From BillingPlan where TypeBp='Time' and LocationID='".$_SESSION['locID']."' and PublishBp='1'";
else if ($type=="Octets")
$q1 = "select Id,NameBp,TimeBp From BillingPlan where TypeBp='Octets' and LocationID='".$_SESSION['locID']."' and PublishBp='1'";
else if ($type=="Expiration")
$q1 = "select Id,NameBp,TimeBp From BillingPlan where TypeBp='Expiration' and LocationID='".$_SESSION['locID']."' and PublishBp='1'";
if ($details==0) {
$resultbp = $oreon->database->database->query($q1);
if ($debug) echo " ".$q1;
if (!$resultbp) {
echo '<p class="error">Invalid request : ' . "Query database error !".'</p>';
// echo "<script Language=\"JavaScript\"> window.location.href='".$_SERVER['HTTP_REFERER']."';</script>";
return;
}
unset($error);
$numrows=$oreon->database->database->result_num_rows($resultbp);
if ($numrows == 0 and $details==0)
{
$error="<p class=\"error\"> You got to create billing plan first !</p>";
echo $error;
return;
}
}
printf('<form name="center" id="center" action="phpmyprepaid.php" method="post">');
echo('<table STYLE="width: 650px">');
if (!isset($error) and $details!=0) {
echo '<tr><td colspan=2><big><big style="font-family: Aircut"><span
style="font-weight: bold; text-decoration: italic;">';
echo "$type $tp Creation</big></big></td></tr>";
}
echo('<tr><td class="fieldcell" STYLE="text-align: right">');
if($details==0 and !isset($error)){
echo('<p>How many tickets would you like to create?</p>');
}
if($details==1){
echo('First Name:');
}
echo("</td>");
echo('<td class="fieldcell" STYLE="text-align: left">');
if($details==0){
echo('<input type=text size=5 class="text" name=\'AnzahlSeiten\' id="name" tabindex="1" STYLE="width: 50px">');
}
if($details==1){
echo('<input type=text size=30 class=text name=\'FirstName\'>');
}
echo "</td></tr><tr>";
if($type == "Hourly" or $type== "Octets" or $type=="Expiration")
{
if($type == "Hourly" or $type== "Octets" or $type="Expiration") {
echo('<td >');
echo("Select your Billing plan?");
echo("</td>");
echo('<td class="fieldcell" STYLE="text-align: left">');
while ($row = $oreon->database->database->fetch_object($resultbp)) {
printf('<input type="radio" name="zeit" value="%s" %s/> %s<br />',
$row->Id,
(isset($_REQUEST['zeit']) and $_REQUEST['zeit'] == $row->Id) ? 'checked="checked" ' : '',
$row->NameBp);
}
}
echo "</td>";
echo '
<tr>
<td class="fieldcell" style="text-align: right"> Radius profile </td>
<td class="bpcell" style="text-align: left">
<select name="RadiusProfile">';
$result2=$oreon->database->database->query("SELECT ID,RadiusProfileName FROM radiusprofile WHERE location_id='".$location."' GROUP BY RadiusProfileName");
echo ("<option value='-1'>None");
while ($row2 = $oreon->database->database->fetch_object($result2)) {
if ($row2->ID == $RadiusProfileName)
echo ("<option selected=\"selected\" value=\"".$row2->ID."\">".$row2->RadiusProfileName);
else
echo ("<option value=\"".$row2->ID."\">".$row2->RadiusProfileName);
echo ("</option>'");
}
echo '</select>
</td></tr>';
echo '
<tr>
<td class="fieldcell" style="text-align: right"> Group </td>
<td class="bpcell" style="text-align: left">
<select name="GroupBp">';
$result2=$oreon->database->database->query("SELECT ID,gp_name FROM group_template WHERE location_id='".$location."'");
echo ("<option value='-1'>None");
while ($row2 = $oreon->database->database->fetch_object($result2)) {
if ($row2->ID == $GroupBp)
echo ("<option selected=\"selected\" value=\"".$row2->ID."\">".$row2->gp_name);
else
echo ("<option value=\"".$row2->ID."\">".$row2->gp_name);
echo ("</option>'");
}
echo '</select>
</td>';
}
else if($details==1)
{
echo('<td class="fieldcell" style="text-align: right">'),
('Last Name:'),
('</td>'),
('<td class="fieldcell" style="text-align: left">'),
('<input type=text size=30 class=text name=\'LastName\'>'),
('</td>'),
('</tr><tr>'),
('<td class="fieldcell" style="text-align: right">'),
('Customer ID:'),
('</td>'),
('<td class="fieldcell" style="text-align: left">'),
('<input type=text size=30 class=text name=\'CustID\'>'),
('</td>'),
('</tr><tr>');
if ($buttonID!='subscription_mac') {
echo ('<td class="fieldcell" style="text-align: right">'),
('User Name:'),
('</td>'),
('<td class="fieldcell" style="text-align: left">'),
('<input type=text size=30 class=text name=\'UserName\'>'),
('</td></tr><tr>'),
('<td class="fieldcell" style="text-align: right">'),
('User password'),
('</td>'),
('<td class="fieldcell" style="text-align: left">'),
('<input type=text size=30 class=text name=\'UserPasswd\'>'),
('</td>'),
('<td class="fieldcell" style="text-align: center">'),
('<input type=button size=30 class=smallButton name=\'UserPasswdButton\' value="Generate" OnClick="generatepassword(this.form.UserPasswd,8);">'),
('</td></tr>');
}
echo('<tr><td class="fieldcell" style="text-align: right">'),
('Select Billing Plan :'),
('</td>');
echo('<td class="fieldcell" STYLE="text-align: left">');
if ($buttonID=="subscription_time")
$q1 = "select Id,NameBp,TimeBp From BillingPlan where TypeBp='Time' and LocationID='".$_SESSION['locID']."' and PublishBp='1'";
else if ($buttonID=="subscription_octets")
$q1 = "select Id,NameBp,TimeBp From BillingPlan where TypeBp='Octets' and LocationID='".$_SESSION['locID']."' and PublishBp='1'";
else if ($buttonID=="subscription_expiration")
$q1 = "select Id,NameBp,TimeBp From BillingPlan where TypeBp='Expiration' and LocationID='".$_SESSION['locID']."' and PublishBp='1'";
else if ($buttonID=="subscription_mac")
$q1 = "select Id,NameBp,TimeBp From BillingPlan where TypeBp='Mac' and LocationID='".$_SESSION['locID']."' and PublishBp='1'";
$urltoload=$_SERVER['HTTP_REFERER']."?buttonID=$buttonID";
$result1 = $oreon->database->database->query($q1);
if (!$result1) {
$_SESSION['error']='Invalid request : ' . "Query database error !";
return;
}
echo('<select name="BillingPlan">');
echo("<option value=\"-1\" selected=\"selected\">None</option>");
while ($row = $oreon->database->database->fetch_object($result1)) {
if ($row->Id==$bp)
{
echo("<option value=\"$row->Id\" selected=\"selected\">".$row->NameBp."</option>");
}
else
echo("<option value=\"$row->Id\">$row->NameBp");
}
echo "</td></tr>";
if ($buttonID=="subscription_time")
{
echo('</tr>');
/*echo('<tr>'),
('<td class="fieldcell" style="text-align: right">'),
('Use Time to finish :'),
('</td>'),
('<td class="fieldcell" style="text-align: left">'),
('<select name="TimeToFinish">');
if ($timetofinish=="1")
echo ("<option selected=\"selected\" value=\"true\">true");
else
echo ("<option value=\"true\">true");
if ($timetofinish=="")
echo ("<option selected=\"selected\" value=\"false\">false");
else
echo ("<option value=\"false\">false");
echo ('</td></tr>');*/
if ($val =="") $val=$mintime;
echo ('<tr>'),
('<td class="fieldcell" style="text-align: right">'),
('Max Session Time:'),
('</td>'),
('<td class="fieldcell" style="text-align: left">'),
("<table><tr><td><input type=text id='valuesub' size=10 class=text name=\"SessionTime\" value=\"$val\"></td><td>");
echo '<select name="TimeCount">';
$tabv=split(";",$timeCount);
for ($i=0;$i<sizeof($tabv);$i++) {
if ($defaultTimeCount == $tabv[$i])
echo ("<option selected=\"selected\" value=\"".$tabv[$i]."\">".$tabv[$i]);
else
echo ("<option value=\"".$tabv[$i]."\">".$tabv[$i]);
echo ("</option>'");
}
echo '</select>
</td>';
echo '
</tr></table>';
echo ('</td>');
}
else if ($buttonID=="subscription_octets")
{
if ($val =="") $val=$minmoctets;
echo ('</tr><tr>'),
('<td class="fieldcell" style="text-align: right">'),
('Max '.$octet_type.' octets:'),
('</td>'),
('<td class="fieldcell" style="text-align: left">'),
("<table><tr><td><input type=text id='valuesub' size=10 class=text name=\"MaxDownload\" value=\"$val\"></td><td>");
echo '<select name="OctetCount">';
$tabv=split(";",$octetCount);
for ($i=0;$i<sizeof($tabv);$i++) {
if ($defaultOctetCount == $tabv[$i])
echo ("<option selected=\"selected\" value=\"".$tabv[$i]."\">".$tabv[$i]);
else
echo ("<option value=\"".$tabv[$i]."\">".$tabv[$i]);
echo ("</option>'");
}
echo '</select>
</td>';
echo ('</tr></table></td>');
}
else if ($buttonID=="subscription_expiration")
{
if ($val =="") $val="10";
echo ('</tr><tr>');
echo ('<td class="fieldcell" style="text-align: right">'),
('Account Expiration Date:'),
('</td><td>');
echo "<table><tr>";
echo ('<td class="fieldcell" style="text-align: left">');
$dateExp = get_date_x_day_after($dateFormat,$val);
echo '<input type="text" name="ExpirationDate" id=\'valuesub\' value="'.$dateExp.'"/><button type="reset" id="f_trigger_b">...</button>
<script type="text/javascript">
Calendar.setup({
inputField : "valuesub", // id of the input field
ifFormat : "'.cdateformat_calendar($dateFormat).'", // format of the input field
showsTime : true, // will display a time selector
button : "f_trigger_b", // trigger for the calendar (button ID)
singleClick : true, // double-click mode
step : 1 // show all years in drop-down boxes (instead of every other year as default)
});
</script>';
echo ('</td></tr></table></td>');
}
else if ($buttonID=="subscription_mac")
{
echo ('</tr><tr>'),
('<td class="fieldcell" style="text-align: right">'),
('Mac address :'),
('</td>'),
('<td class="fieldcell" style="text-align: left">'),
("<input type=text size=30 class=text name=\"MacAddress\" value=\"$macAddr\">"),
('</td>');
}
echo '
<tr>
<td class="fieldcell" style="text-align: right"> Radius profile </td>
<td class="bpcell" style="text-align: left">
<select name="RadiusProfile">';
$result2=$oreon->database->database->query("SELECT ID,RadiusProfileName FROM radiusprofile WHERE location_id='".$location."' GROUP BY RadiusProfileName");
echo ("<option value='-1'>None");
while ($row2 = $oreon->database->database->fetch_object($result2)) {
if ($row2->ID == $RadiusProfileName)
echo ("<option selected=\"selected\" value=\"".$row2->ID."\">".$row2->RadiusProfileName);
else
echo ("<option value=\"".$row2->ID."\">".$row2->RadiusProfileName);
echo ("</option>'");
}
echo '</select>
</td>';
echo '
<tr>
<td class="fieldcell" style="text-align: right"> Group </td>
<td class="bpcell" style="text-align: left">
<select name="GroupBp">';
$result2=$oreon->database->database->query("SELECT ID,gp_name FROM group_template WHERE location_id='".$location."'");
echo ("<option value='-1'>None");
while ($row2 = $oreon->database->database->fetch_object($result2)) {
if ($row2->ID == $GroupBp)
echo ("<option selected=\"selected\" value=\"".$row2->ID."\">".$row2->gp_name);
else
echo ("<option value=\"".$row2->ID."\">".$row2->gp_name);
echo ("</option>'");
}
echo '</select>
</td>';
echo('</tr><tr>'),
('<td class="fieldcell" style="text-align: right">'),
('email:'),
('</td>'),
('<td class="fieldcell" style="text-align: left">'),
('<input type=text size=30 class=text name=\'Email\'>'),
('</td>'),
('</tr><tr>'),
('<td class="fieldcell" style="text-align: right">'),
('Bandwidth Upload Limit:'),
('</td>'),
('<td class="fieldcell" style="text-align: left">'),
('<select name="UploadLimit">'),
("<option value=\"\"></option>");
$tab=split(',',$updownload);
foreach($tab as $val)
echo ("<option value=\"$val\">$val</option>");
echo ('</select>'),
('</td>'),
('</tr><tr>'),
('<td class="fieldcell" style="text-align: right">'),
('Bandwidth Download Limit:'),
('</td>'),
('<td class="fieldcell" style="text-align: left">'),
('<select name="DownloadLimit">'),
("<option value=\"\"></option>");
$tab=split(',',$updownload);
foreach($tab as $val)
echo ("<option value=\"$val\">$val</option>");
echo('</select>'),
('</td>');
}else{
echo '<td>Select your Billing plan ? </td>';
echo('<td class="fieldcell" STYLE="text-align: left">');
$q1 = "select NameBp,TimeBp From BillingPlan where TypeBp='Time'";
$result1 = $oreon->database->database->query($q1);
while ($row = $oreon->database->database->fetch_object($result1)) {
printf('<input type="radio" name="zeit" value="%s" %s/> %s<br />',
$row->TimeBp,
(isset($_REQUEST['zeit']) and $_REQUEST['zeit'] == $row->TimeBp) ? 'checked="checked" ' : '',
$row->NameBp);
}
echo "</td>";
}
echo "</tr>";
echo('<tr><td></td>');
echo('<td class="fieldcell">');
if($type == "Hourly") {
echo('<input type="hidden" name="buttonID" value="CR_Timed">');
}
if($type == "Octets") {
echo('<input type="hidden" name="buttonID" value="CR_Octets">');
}
if($type == "Expiration") {
echo('<input type="hidden" name="buttonID" value="CR_Expiration">');
}
if($type == "Subscription Octets"){
echo('<input type="hidden" name="buttonID" value="CR_subscription_octets">');
}
if($type == "Subscription Time"){
echo('<input type="hidden" name="buttonID" value="CR_subscription_time">');
}
if($type == "Subscription Expiration"){
echo('<input type="hidden" name="buttonID" value="CR_subscription_expiration">');
}
if($type == "Subscription Mac"){
echo('<input type="hidden" name="buttonID" value="CR_subscription_mac">');
}
if($details ==1)
{
$value="ACCOUNT";
}
else
{
$value="CARDS";
}
echo('<center>'),
("<input type=\"submit\" name=\"submit\" class=\"smallButton\" value=\"CREATE $value\"/>"),
('</center></td></tr>');
echo "</table>";
echo '</form>';
//////////////////////////////////////////////////////////
// END OF FORM LAYOUT //
//////////////////////////////////////////////////////////
}
else
{
echo($msg);
if(isset($include)){
include($include);
}
}
?>