Merge pull request #30 from GameServerPanel/copilot/update-create-servers-file
Refactor billing module to remove billing_carts table dependency
This commit is contained in:
commit
0f07344321
3 changed files with 23 additions and 37 deletions
|
|
@ -6,20 +6,19 @@ function exec_ogp_module()
|
||||||
{
|
{
|
||||||
global $db,$view,$settings;
|
global $db,$view,$settings;
|
||||||
$user_id = $_SESSION['user_id'];
|
$user_id = $_SESSION['user_id'];
|
||||||
if (isset($_POST['cart_id'])) {
|
if (isset($_POST['order_id'])) {
|
||||||
$cart_id = $_POST['cart_id'];
|
$order_id = $_POST['order_id'];
|
||||||
}
|
}
|
||||||
if(isset($_GET['cart_id'])){
|
if(isset($_GET['order_id'])){
|
||||||
$cart_id = $_GET['cart_id'];
|
$order_id = $_GET['order_id'];
|
||||||
}
|
}
|
||||||
$cart_paid = $db->resultQuery( "SELECT paid FROM OGP_DB_PREFIXbilling_carts WHERE cart_id=".$db->realEscapeSingle($cart_id) );
|
|
||||||
$isAdmin = $db->isAdmin( $_SESSION['user_id'] );
|
$isAdmin = $db->isAdmin( $_SESSION['user_id'] );
|
||||||
if ( $isAdmin ){
|
if ( $isAdmin ){
|
||||||
$orders = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXbilling_orders WHERE cart_id=".$db->realEscapeSingle($cart_id) );
|
$orders = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXbilling_orders WHERE order_id=".$db->realEscapeSingle($order_id)." AND status='paid'" );
|
||||||
} else {
|
} else {
|
||||||
$orders = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXbilling_orders WHERE cart_id=".$db->realEscapeSingle($cart_id)." AND user_id=".$db->realEscapeSingle($user_id) );
|
$orders = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXbilling_orders WHERE order_id=".$db->realEscapeSingle($order_id)." AND user_id=".$db->realEscapeSingle($user_id)." AND status='paid'" );
|
||||||
}
|
}
|
||||||
if( !empty($orders) and !empty($cart_paid) )
|
if( !empty($orders) )
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach($orders as $order)
|
foreach($orders as $order)
|
||||||
|
|
@ -287,8 +286,12 @@ function exec_ogp_module()
|
||||||
|
|
||||||
}
|
}
|
||||||
// Set expiration date in ogp database
|
// Set expiration date in ogp database
|
||||||
//status is -3 -2 -1 0 and 1
|
//status is: in-cart, paid, installed, invoiced, suspended, deleted
|
||||||
// deleted, suspended, invoiced, inactive, active
|
// 'paid' - order has been paid but server not yet created
|
||||||
|
// 'installed' - server created and active
|
||||||
|
// 'invoiced' - invoice created for renewal
|
||||||
|
// 'suspended' - server suspended for non-payment
|
||||||
|
// 'deleted' - server deleted after extended suspension
|
||||||
//finish_date the server will be suspended
|
//finish_date the server will be suspended
|
||||||
//in cron_shop the finish_date is used to delete the server
|
//in cron_shop the finish_date is used to delete the server
|
||||||
//several days after being suspended
|
//several days after being suspended
|
||||||
|
|
@ -297,12 +300,10 @@ function exec_ogp_module()
|
||||||
|
|
||||||
if($order['finish_date'] == 0){
|
if($order['finish_date'] == 0){
|
||||||
$finish_date = strtotime('+'.$order['qty'].' day');
|
$finish_date = strtotime('+'.$order['qty'].' day');
|
||||||
$status = 'paid';
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
//this is a renewel, start from end of previous order
|
//this is a renewel, start from end of previous order
|
||||||
$finish_date = strtotime('+'.$order['qty'].' day',$order['finish_date']);
|
$finish_date = strtotime('+'.$order['qty'].' day',$order['finish_date']);
|
||||||
$status = 'paid';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -311,13 +312,11 @@ function exec_ogp_module()
|
||||||
// this is a new order
|
// this is a new order
|
||||||
if($order['finish_date'] == 0){
|
if($order['finish_date'] == 0){
|
||||||
$finish_date = strtotime('+'.$order['qty'].' month');
|
$finish_date = strtotime('+'.$order['qty'].' month');
|
||||||
$status = 'paid';
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
//this is a renewel, start from end of previous order
|
//this is a renewel, start from end of previous order
|
||||||
$finish_date = strtotime('+'.$order['qty'].' month',$order['finish_date']);
|
$finish_date = strtotime('+'.$order['qty'].' month',$order['finish_date']);
|
||||||
$status = 'paid';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif ($order['invoice_duration'] == "year")
|
elseif ($order['invoice_duration'] == "year")
|
||||||
|
|
@ -325,19 +324,17 @@ function exec_ogp_module()
|
||||||
// this is a new order
|
// this is a new order
|
||||||
if($order['finish_date'] == 0){
|
if($order['finish_date'] == 0){
|
||||||
$finish_date = strtotime('+'.$order['qty'].' year');
|
$finish_date = strtotime('+'.$order['qty'].' year');
|
||||||
$status = 'paid';
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
//this is a renewel, start from end of previous order
|
//this is a renewel, start from end of previous order
|
||||||
$finish_date = strtotime('+'.$order['qty'].' year',$order['finish_date']);
|
$finish_date = strtotime('+'.$order['qty'].' year',$order['finish_date']);
|
||||||
$status = 'paid';
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// set order status
|
// set order status to 'installed' to indicate server has been provisioned
|
||||||
$db->query("UPDATE OGP_DB_PREFIXbilling_orders
|
$db->query("UPDATE OGP_DB_PREFIXbilling_orders
|
||||||
SET status='" . $db->realEscapeSingle($status) . "'
|
SET status='installed'
|
||||||
WHERE order_id=".$db->realEscapeSingle($order_id));
|
WHERE order_id=".$db->realEscapeSingle($order_id));
|
||||||
|
|
||||||
// set the order expiration
|
// set the order expiration
|
||||||
|
|
@ -351,17 +348,6 @@ function exec_ogp_module()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Update Cart Payment Status as 3(paid and installed)
|
|
||||||
$db->query("UPDATE OGP_DB_PREFIXbilling_carts
|
|
||||||
SET paid=3
|
|
||||||
WHERE cart_id=".$db->realEscapeSingle($cart_id));
|
|
||||||
|
|
||||||
// Set payment/creation date
|
|
||||||
$date = date('d M Y');
|
|
||||||
$db->query("UPDATE OGP_DB_PREFIXbilling_carts
|
|
||||||
SET date='" . $db->realEscapeSingle($date) . "'
|
|
||||||
WHERE cart_id=".$db->realEscapeSingle($cart_id));
|
|
||||||
|
|
||||||
$db->query( "UPDATE OGP_DB_PREFIXgame_mods SET max_players= ".$order['max_players']." WHERE home_id=".$db->realEscapeSingle($home_id));
|
$db->query( "UPDATE OGP_DB_PREFIXgame_mods SET max_players= ".$order['max_players']." WHERE home_id=".$db->realEscapeSingle($home_id));
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,11 +54,11 @@ $db->logger("AUTO-CLEAN: Server Cleanup running at ".$rundate);
|
||||||
|
|
||||||
|
|
||||||
//THESE SERVERS HAVE REACHED THE DATE FOR INVOICE, FINISH_DATE - 7 (OR WHAT IS IN SETTINGS)
|
//THESE SERVERS HAVE REACHED THE DATE FOR INVOICE, FINISH_DATE - 7 (OR WHAT IS IN SETTINGS)
|
||||||
//SET STATUS -1 MEANING INVOICED
|
//SET STATUS 'invoiced' MEANING INVOICE SHOULD BE CREATED
|
||||||
//LOOP THROUGH ALL SERVERS WITH STATUS = 'paid' (ACTIVE) -----------------------------------------------------------
|
//LOOP THROUGH ALL SERVERS WITH STATUS = 'paid' OR 'installed' (ACTIVE) -----------------------------------------------------------
|
||||||
$user_homes = $db->resultQuery( "SELECT *
|
$user_homes = $db->resultQuery( "SELECT *
|
||||||
FROM " . $table_prefix . "billing_orders
|
FROM " . $table_prefix . "billing_orders
|
||||||
WHERE status = 'paid' AND finish_date <" . $invoice_date);
|
WHERE status IN ('paid', 'installed') AND finish_date <" . $invoice_date);
|
||||||
|
|
||||||
if (!is_array($user_homes))
|
if (!is_array($user_homes))
|
||||||
{
|
{
|
||||||
|
|
@ -188,7 +188,7 @@ else
|
||||||
// Set order as not installed
|
// Set order as not installed
|
||||||
$db->query( "UPDATE " . $table_prefix . "billing_orders
|
$db->query( "UPDATE " . $table_prefix . "billing_orders
|
||||||
SET home_id=0
|
SET home_id=0
|
||||||
WHERE cart_id=".$db->realEscapeSingle($user_home['cart_id']));
|
WHERE order_id=".$db->realEscapeSingle($user_home['order_id']));
|
||||||
|
|
||||||
// remove userid and table from database
|
// remove userid and table from database
|
||||||
$db->query( "DROP USER 'server_" .$home_id ."'@'%'");
|
$db->query( "DROP USER 'server_" .$home_id ."'@'%'");
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ function exec_ogp_module()
|
||||||
|
|
||||||
<strong>GOOD NEWS!</strong> You have a new server! <br>
|
<strong>GOOD NEWS!</strong> You have a new server! <br>
|
||||||
<form method="post" action="home.php?m=billing&p=create_servers">
|
<form method="post" action="home.php?m=billing&p=create_servers">
|
||||||
<input type="hidden" name="cart_id" value="'. $res['cart_id'].'">
|
<input type="hidden" name="order_id" value="'. $res['order_id'].'">
|
||||||
<button type="submit" name="submit_param" value="submit_value" class="link-button">
|
<button type="submit" name="submit_param" value="submit_value" class="link-button">
|
||||||
Create Server
|
Create Server
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -80,7 +80,7 @@ function exec_ogp_module()
|
||||||
<a href="#" class="close" data-dismiss="alert" aria-label="close"></a>
|
<a href="#" class="close" data-dismiss="alert" aria-label="close"></a>
|
||||||
You have an Invoice Due <br>
|
You have an Invoice Due <br>
|
||||||
<form method="post" action="home.php?m=billing&p=create_servers">
|
<form method="post" action="home.php?m=billing&p=create_servers">
|
||||||
<input type="hidden" name="cart_id" value="'. $res['cart_id'].'">
|
<input type="hidden" name="order_id" value="'. $res['order_id'].'">
|
||||||
<button type="submit" name="submit_param" value="submit_value" class="link-button">
|
<button type="submit" name="submit_param" value="submit_value" class="link-button">
|
||||||
View Invoice
|
View Invoice
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -99,7 +99,7 @@ function exec_ogp_module()
|
||||||
<a href="#" class="close" data-dismiss="alert" aria-label="close"></a>
|
<a href="#" class="close" data-dismiss="alert" aria-label="close"></a>
|
||||||
<strong>Warning!</strong> You have an OVERDUE invoice<br>
|
<strong>Warning!</strong> You have an OVERDUE invoice<br>
|
||||||
<form method="post" action="home.php?m=billing&p=create_servers">
|
<form method="post" action="home.php?m=billing&p=create_servers">
|
||||||
<input type="hidden" name="cart_id" value="'. $res['cart_id'].'">
|
<input type="hidden" name="order_id" value="'. $res['order_id'].'">
|
||||||
<button type="submit" name="submit_param" value="submit_value" class="link-button">
|
<button type="submit" name="submit_param" value="submit_value" class="link-button">
|
||||||
View Overdue Invoice
|
View Overdue Invoice
|
||||||
</button>
|
</button>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue