Skip to content
Snippets Groups Projects
Commit 068c1ec0 authored by Robert Anderson's avatar Robert Anderson
Browse files

Added topups to admin control panels

parent b4b3e551
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
include_once("include/ajax/functions/AdminUserAttributes.php"); include_once("include/ajax/functions/AdminUserAttributes.php");
include_once("include/ajax/functions/AdminUserGroups.php"); include_once("include/ajax/functions/AdminUserGroups.php");
include_once("include/ajax/functions/AdminUserLogs.php"); include_once("include/ajax/functions/AdminUserLogs.php");
include_once("include/ajax/functions/AdminUserTopups.php");
include_once("include/ajax/functions/AdminGroups.php"); include_once("include/ajax/functions/AdminGroups.php");
include_once("include/ajax/functions/AdminGroupAttributes.php"); include_once("include/ajax/functions/AdminGroupAttributes.php");
...@@ -164,6 +165,69 @@ ...@@ -164,6 +165,69 @@
switch ($function) { switch ($function) {
# AdminUserTopups.js functions
case "getAdminUserTopups":
$res = getAdminUserTopups($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Timestamp','date');
$res->addField('Type','int');
$res->addField('Value','int');
$res->addField('ValidFrom','string');
$res->addField('ValidTo','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "createAdminUserTopup":
$res = createAdminUserTopup($soapParams);
if (isset($res)) {
ajaxException($res);
}
break;
case "updateAdminUserTopup":
$res = updateAdminUserTopup($soapParams);
if (isset($res)) {
ajaxException($res);
}
break;
case "getAdminUserTopup":
$rawData = getAdminUserTopup($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Type','int');
$res->addField('Value','int');
$res->addField('ValidFrom','date');
$res->addField('ValidTo','date');
$res->parseHash($rawData);
echo json_encode($res->export());
break;
case "removeAdminUserTopup":
$res = removeAdminUserTopup($soapParams);
if (isset($res)) {
ajaxException($res);
}
break;
# WiSPUserTopups.js functions # WiSPUserTopups.js functions
case "getWiSPUserTopups": case "getWiSPUserTopups":
......
<?php
include_once("include/db.php");
# Add new topup
function createAdminUserTopup($params) {
global $db;
$timestamp = date('Y-m-d H:i:s');
$res = DBDo("INSERT INTO topups (UserID,Timestamp,Type,Value,ValidFrom,ValidTo) VALUES (?,?,?,?,?,?)",
array($params[0]['UserID'],$timestamp,$params[0]['Type'],$params[0]['Value'],$params[0]['ValidFrom'],
$params[0]['ValidTo'])
);
if (!is_numeric($res)) {
return $res;
}
return NULL;
}
# Edit topup
function updateAdminUserTopup($params) {
global $db;
$res = DBDo("UPDATE topups SET Value = ?, Type = ?, ValidFrom = ?, ValidTo = ? WHERE ID = ?",
array($params[0]['Value'],
$params[0]['Type'],
$params[0]['ValidFrom'],
$params[0]['ValidTo'],
$params[0]['ID'])
);
if (!is_numeric($res)) {
return $res;
}
return NULL;
}
# Delete user topup
function removeAdminUserTopup($params) {
global $db;
$res = DBDo("DELETE FROM topups WHERE ID = ?",array($params[0]));
if (!is_numeric($res)) {
return $res;
}
return NULL;
}
# Return specific topup row
function getAdminUserTopup($params) {
global $db;
$res = DBSelect("SELECT ID, Type, Value, ValidFrom, ValidTo FROM topups WHERE ID = ?",array($params[0]));
if (!is_object($res)) {
return $res;
}
$resultArray = array();
$row = $res->fetchObject();
$resultArray['ID'] = $row->id;
$resultArray['Type'] = $row->type;
$resultArray['Value'] = $row->value;
# Convert to ISO format
$date = new DateTime($row->validfrom);
$value = $date->format("Y-m-d");
$resultArray['ValidFrom'] = $value;
# Convert to ISO format
$date = new DateTime($row->validto);
$value = $date->format("Y-m-d");
$resultArray['ValidTo'] = $value;
return $resultArray;
}
# Return list of topups
function getAdminUserTopups($params) {
global $db;
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'topups.ID',
'Type' => 'topups.Type',
'Value' => 'topups.Value',
'ValidFrom' => 'topups.ValidFrom',
'ValidTo' => 'topups.ValidTo'
);
$res = DBSelectSearch("
SELECT
ID, Timestamp, Type, Value, ValidFrom, ValidTo
FROM
topups
WHERE
Depleted = 0
AND
UserID = ".DBQuote($params[0]['UserID'])."
ORDER BY
Timestamp
DESC
",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data
if (!isset($sth)) {
return $res;
}
$resultArray = array();
# loop through rows
while ($row = $sth->fetchObject()) {
$item = array();
$item['ID'] = $row->id;
$item['Timestamp'] = $row->timestamp;
$item['Type'] = $row->type;
$item['Value'] = $row->value;
# Convert to ISO format
$date = new DateTime($row->validfrom);
$value = $date->format("Y-m-d");
$item['ValidFrom'] = $value;
# Convert to ISO format
$date = new DateTime($row->validto);
$value = $date->format("Y-m-d");
$item['ValidTo'] = $value;
# push this row onto array
array_push($resultArray,$item);
}
return array($resultArray,$numResults);
}
# vim: ts=4
...@@ -74,22 +74,20 @@ ...@@ -74,22 +74,20 @@
<script type="text/javascript" src="js/app/windows/WiSPUserTopups.js"></script> <script type="text/javascript" src="js/app/windows/WiSPUserTopups.js"></script>
<script type="text/javascript" src="js/app/windows/WiSPLocations.js"></script> <script type="text/javascript" src="js/app/windows/WiSPLocations.js"></script>
<script type="text/javascript" src="js/app/windows/WiSPLocationMembers.js"></script> <script type="text/javascript" src="js/app/windows/WiSPLocationMembers.js"></script>
<script type="text/javascript" src="js/app/windows/WiSPResellers.js"></script> <script type="text/javascript" src="js/app/windows/WiSPResellers.js"></script>
<script type="text/javascript" src="js/app/windows/AdminRealms.js"></script>
<script type="text/javascript" src="js/app/windows/AdminRealmAttributes.js"></script>
<script type="text/javascript" src="js/app/windows/AdminUsers.js"></script> <script type="text/javascript" src="js/app/windows/AdminUsers.js"></script>
<script type="text/javascript" src="js/app/windows/AdminUserLogs.js"></script> <script type="text/javascript" src="js/app/windows/AdminUserLogs.js"></script>
<script type="text/javascript" src="js/app/windows/AdminUserAttributes.js"></script> <script type="text/javascript" src="js/app/windows/AdminUserAttributes.js"></script>
<script type="text/javascript" src="js/app/windows/AdminUserGroups.js"></script> <script type="text/javascript" src="js/app/windows/AdminUserGroups.js"></script>
<script type="text/javascript" src="js/app/windows/AdminUserTopups.js"></script>
<script type="text/javascript" src="js/app/windows/AdminRealms.js"></script>
<script type="text/javascript" src="js/app/windows/AdminRealmAttributes.js"></script>
<script type="text/javascript" src="js/app/windows/AdminGroups.js"></script> <script type="text/javascript" src="js/app/windows/AdminGroups.js"></script>
<script type="text/javascript" src="js/app/windows/AdminGroupAttributes.js"></script> <script type="text/javascript" src="js/app/windows/AdminGroupAttributes.js"></script>
<script type="text/javascript" src="js/app/windows/AdminGroupMembers.js"></script> <script type="text/javascript" src="js/app/windows/AdminGroupMembers.js"></script>
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Layout...';</script> <script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Layout...';</script>
<script type="text/javascript" src="js/app/main-layout.js"></script> <script type="text/javascript" src="js/app/main-layout.js"></script>
......
function showAdminUserTopupsWindow(userID) {
var adminUserTopupsWindow = new Ext.ux.GenericGridWindow(
// Window config
{
title: "User Topups",
width: 500,
height: 335,
minWidth: 500,
minHeight: 335,
},
// Grid config
{
// Inline toolbars
tbar: [
{
text:'Add',
tooltip:'Add topup',
iconCls:'add',
handler: function() {
showAdminUserTopupAddEditWindow(userID,0);
}
},
'-',
{
text:'Edit',
tooltip:'Edit topup',
iconCls:'option',
handler: function() {
var selectedItem = adminUserTopupsWindow.getComponent('gridpanel').getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showAdminUserTopupAddEditWindow(userID,selectedItem.data.ID);
} else {
adminUserTopupsWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No topup selected",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.CANCEL,
modal: false,
fn: function() {
adminUserTopupsWindow.getEl().unmask();
}
});
}
}
},
'-',
{
text:'Remove',
tooltip:'Remove topup',
iconCls:'remove',
handler: function() {
var selectedItem = adminUserTopupsWindow.getComponent('gridpanel').getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showAdminUserTopupRemoveWindow(adminUserTopupsWindow,selectedItem.data.ID);
} else {
adminUserTopupsWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No topup selected",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.CANCEL,
modal: false,
fn: function() {
adminUserTopupsWindow.getEl().unmask();
}
});
}
}
}
],
// Column model
colModel: new Ext.grid.ColumnModel([
{
id: 'ID',
header: "ID",
sortable: true,
hidden: true,
dataIndex: 'ID'
},
{
header: "Type",
sortable: true,
dataIndex: 'Type'
},
{
header: "Value",
sortable: true,
dataIndex: 'Value'
},
{
header: "Timestamp",
sortable: true,
hidden: true,
dataIndex: 'Timestamp'
},
{
header: "ValidFrom",
sortable: true,
dataIndex: 'ValidFrom'
},
{
header: "ValidTo",
sortable: true,
dataIndex: 'ValidTo'
}
]),
},
// Store config
{
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminUsers',
SOAPFunction: 'getAdminUserTopups',
SOAPParams: '0:UserID,__search',
UserID: userID
}
},
// Filter config
{
filters: [
{type: 'numeric', dataIndex: 'ID'},
{type: 'date', dataIndex: 'Timestamp'},
{type: 'numeric', dataIndex: 'Value'},
{type: 'date', dataIndex: 'ValidFrom'},
{type: 'date', dataIndex: 'ValidTo'}
]
}
);
adminUserTopupsWindow.show();
}
// Display edit/add form
function showAdminUserTopupAddEditWindow(userID,topupID) {
var today = new Date();
var firstOfMonth = today.getFirstDateOfMonth();
var firstOfNext = today.getLastDateOfMonth().add(Date.DAY, 1);
var submitAjaxConfig;
// We doing an update
if (topupID) {
submitAjaxConfig = {
ID: topupID,
SOAPFunction: 'updateAdminUserTopup',
SOAPParams:
'0:ID,0:Value,0:Type,'+
'0:ValidFrom,0:ValidTo'
};
// We doing an Add
} else {
submitAjaxConfig = {
UserID: userID,
SOAPFunction: 'createAdminUserTopup',
SOAPParams:
'0:UserID,0:Value,0:Type,'+
'0:ValidFrom,0:ValidTo'
};
}
// Create window
var adminUserTopupFormWindow = new Ext.ux.GenericFormWindow(
// Window config
{
title: "Topup Information",
width: 400,
height: 200,
minWidth: 400,
minHeight: 200
},
// Form panel config
{
labelWidth: 85,
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminUsers'
},
items: [
{
xtype: 'numberfield',
fieldLabel: 'Type',
name: 'Type',
minValue: 1,
allowBlank: false
},
{
xtype: 'numberfield',
fieldLabel: 'Value',
name: 'Value',
minValue: 1,
allowBlank: false
},
{
xtype: 'datefield',
fieldLabel: 'ValidFrom',
name: 'ValidFrom',
id: 'ValidFrom',
vtype: 'daterange',
value: firstOfMonth,
format: 'Y-m-d',
endDateField: 'ValidTo'
},
{
xtype: 'datefield',
fieldLabel: 'ValidTo',
name: 'ValidTo',
id: 'ValidTo',
vtype: 'daterange',
value: firstOfNext,
format: 'Y-m-d',
startDateField: 'ValidFrom'
}
],
},
// Submit button config
submitAjaxConfig
);
adminUserTopupFormWindow.show();
if (topupID) {
adminUserTopupFormWindow.getComponent('formpanel').load({
params: {
id: topupID,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminUsers',
SOAPFunction: 'getAdminUserTopup',
SOAPParams: 'id'
}
});
}
}
// Display edit/add form
function showAdminUserTopupRemoveWindow(parent,id) {
// Mask parent window
parent.getEl().mask();
// Display remove confirm window
Ext.Msg.show({
title: "Confirm removal",
msg: "Are you very sure you wish to remove this topup?",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.YESNO,
modal: false,
fn: function(buttonId,text) {
// Check if user clicked on 'yes' button
if (buttonId == 'yes') {
// Do ajax request
uxAjaxRequest(parent,{
params: {
id: id,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminUsers',
SOAPFunction: 'removeAdminUserTopup',
SOAPParams: 'id'
}
});
// Unmask if user answered no
} else {
parent.getEl().unmask();
}
}
});
}
// vim: ts=4
...@@ -151,6 +151,34 @@ function showAdminUserWindow() { ...@@ -151,6 +151,34 @@ function showAdminUserWindow() {
} else { } else {
AdminUserWindow.getEl().mask(); AdminUserWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No user selected",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.CANCEL,
modal: false,
fn: function() {
AdminUserWindow.getEl().unmask();
}
});
}
}
},
'-',
{
text:'Topups',
tooltip:'User topups',
iconCls:'logs',
handler: function() {
var selectedItem = AdminUserWindow.getComponent('gridpanel').getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showAdminUserTopupsWindow(selectedItem.data.ID);
} else {
AdminUserWindow.getEl().mask();
// Display error // Display error
Ext.Msg.show({ Ext.Msg.show({
title: "Nothing selected", title: "Nothing selected",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment