function userRefillSessionTraffic($username, $divContainer) { include 'pages_common.php'; include '../../library/checklogin.php'; include '../../library/opendb.php'; if (!is_array($username)) { $username = array($username); } $allUsers = ""; foreach ($username as $variable => $value) { $user = $dbSocket->escapeSimple($value); // clean username argument from harmful code $allUsers .= $user . ", "; $sql = "UPDATE " . $configValues['CONFIG_DB_TBL_RADACCT'] . " SET AcctInputOctets=0, AcctOutputOctets=0 " . " WHERE Username='******'"; $res = $dbSocket->query($sql); } // take care of recording the billing action in billing_history table foreach ($username as $variable => $value) { $user = $dbSocket->escapeSimple($value); // clean username argument from harmful code $sql = "SELECT " . $configValues['CONFIG_DB_TBL_DALOUSERBILLINFO'] . ".id, " . $configValues['CONFIG_DB_TBL_DALOUSERBILLINFO'] . ".username, " . $configValues['CONFIG_DB_TBL_DALOUSERBILLINFO'] . ".planName, " . $configValues['CONFIG_DB_TBL_DALOBILLINGPLANS'] . ".id as PlanID, " . $configValues['CONFIG_DB_TBL_DALOBILLINGPLANS'] . ".planTax, " . $configValues['CONFIG_DB_TBL_DALOBILLINGPLANS'] . ".planTrafficRefillCost, " . $configValues['CONFIG_DB_TBL_DALOUSERBILLINFO'] . ".paymentmethod, " . $configValues['CONFIG_DB_TBL_DALOUSERBILLINFO'] . ".cash, " . $configValues['CONFIG_DB_TBL_DALOUSERBILLINFO'] . ".creditcardname, " . $configValues['CONFIG_DB_TBL_DALOUSERBILLINFO'] . ".creditcardnumber, " . $configValues['CONFIG_DB_TBL_DALOUSERBILLINFO'] . ".creditcardverification, " . $configValues['CONFIG_DB_TBL_DALOUSERBILLINFO'] . ".creditcardtype, " . $configValues['CONFIG_DB_TBL_DALOUSERBILLINFO'] . ".creditcardexp " . " FROM " . $configValues['CONFIG_DB_TBL_DALOUSERBILLINFO'] . ", " . $configValues['CONFIG_DB_TBL_DALOBILLINGPLANS'] . " " . " WHERE " . "(" . $configValues['CONFIG_DB_TBL_DALOUSERBILLINFO'] . ".planname=" . $configValues['CONFIG_DB_TBL_DALOBILLINGPLANS'] . ".planname)" . " AND " . "(" . $configValues['CONFIG_DB_TBL_DALOUSERBILLINFO'] . ".username='******')"; $res = $dbSocket->query($sql); $row = $res->fetchRow(DB_FETCHMODE_ASSOC); $refillCost = $row['planTrafficRefillCost']; $currDate = date('Y-m-d H:i:s'); $currBy = $_SESSION['operator_user']; $sql = "INSERT INTO " . $configValues['CONFIG_DB_TBL_DALOBILLINGHISTORY'] . " (id,username,planName,billAmount,billAction,billPerformer,billReason," . " paymentmethod,cash,creditcardname,creditcardnumber,creditcardverification,creditcardtype,creditcardexp," . " creationdate,creationby" . ")" . " VALUES " . " (0,'{$user}','" . $row['planName'] . "','" . $row['planTrafficRefillCost'] . "','Refill Session Traffic','daloRADIUS Web Interface','Refill Session Traffic','" . $row['paymentmethod'] . "','" . $row['cash'] . "','" . $row['creditcardname'] . "','" . $row['creditcardnumber'] . "','" . $row['creditcardverification'] . "','" . $row['creditcardtype'] . "','" . $row['creditcardexp'] . "'," . "'{$currDate}', '{$currBy}'" . ")"; $res = $dbSocket->query($sql); // if the refill cost is anything beyond the amount 0, we create an invoice for it. if ($refillCost > 0) { // if the user id indeed set in the userbillinfo table if ($row['id']) { include_once "userBilling.php"; $invoiceInfo['notes'] = 'refill user account'; // calculate tax (planTax is the numerical percentage amount) $calcTax = (double) ($row['planTrafficRefillCost'] * (double) ($row['planTax'] / 100)); $invoiceItems[0]['plan_id'] = $row['PlanID']; $invoiceItems[0]['amount'] = $row['planTrafficRefillCost']; $invoiceItems[0]['tax'] = $calcTax; $invoiceItems[0]['notes'] = 'refill user session traffic'; userInvoiceAdd($row['id'], $invoiceInfo, $invoiceItems); } } } $users = substr($allUsers, 0, -2); printqn("\n\t\tvar divContainer = document.getElementById('{$divContainer}');\n\t divContainer.innerHTML += '<div class=\"success\">User(s) <b>{$users}</b> session traffic has been successfully refilled and billed.</div>';\n\t"); include '../../library/closedb.php'; }
$res = $dbSocket->query($sql); $row = $res->fetchRow(DB_FETCHMODE_ASSOC); // calculate tax (planTax is the numerical percentage amount) $calcTax = (double) ($row['planCost'] * (double) ($row['planTax'] / 100)); $invoiceItems[0]['plan_id'] = $row['id']; $invoiceItems[0]['amount'] = $row['planCost']; $invoiceItems[0]['tax'] = $calcTax; $invoiceItems[0]['notes'] = 'charge for plan service'; if (isset($row['planSetupCost']) && $row['planSetupCost'] != '') { $calcTax = (double) ($row['planSetupCost'] * (double) ($row['planTax'] / 100)); $invoiceItems[1]['plan_id'] = $row['id']; $invoiceItems[1]['amount'] = $row['planSetupCost']; $invoiceItems[1]['tax'] = $calcTax; $invoiceItems[1]['notes'] = 'charge for plan setup fee (one time)'; } userInvoiceAdd($userbillinfo_id, array(), $invoiceItems); } if ($notificationWelcome == 1) { include "include/common/notificationsWelcome.php"; } $successMsg = "Added to database new user: <b> {$username} </b>"; $logAction .= "Successfully added new user [{$username}] on page: "; } else { $failureMsg = "username or password are empty"; $logAction .= "Failed adding (possible empty user/pass) new user [{$username}] on page: "; } } else { $failureMsg = "user already exist in database: <b> {$username} </b>"; $logAction .= "Failed adding new user already existing in database [{$username}] on page: "; } include 'library/closedb.php';