diff --git a/webgui/ajax.php b/webgui/ajax.php index 0aed8d94d3b77318a746bb74ada1aa5b82946db7..564c6acd7cc97b17b372ef174bcee2566f708d83 100644 --- a/webgui/ajax.php +++ b/webgui/ajax.php @@ -7,6 +7,7 @@ include_once("include/ajax/functions/AdminUserAttributes.php"); include_once("include/ajax/functions/AdminUserGroups.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/AdminGroupAttributes.php"); @@ -164,6 +165,69 @@ 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 case "getWiSPUserTopups": diff --git a/webgui/include/ajax/functions/AdminUserTopups.php b/webgui/include/ajax/functions/AdminUserTopups.php new file mode 100644 index 0000000000000000000000000000000000000000..a5288191398caf9e1318ae851fd020b3deaa8d40 --- /dev/null +++ b/webgui/include/ajax/functions/AdminUserTopups.php @@ -0,0 +1,145 @@ +<?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 diff --git a/webgui/index.html b/webgui/index.html index 02b05fe7f7632bb3722eae21b52a54d7409aabe6..439fdcfc6584c0a464206cd209a69655a8c88ea2 100644 --- a/webgui/index.html +++ b/webgui/index.html @@ -74,22 +74,20 @@ <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/WiSPLocationMembers.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/AdminUserLogs.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/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/AdminGroupAttributes.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" src="js/app/main-layout.js"></script> diff --git a/webgui/js/app/windows/AdminUserTopups.js b/webgui/js/app/windows/AdminUserTopups.js new file mode 100644 index 0000000000000000000000000000000000000000..81eb2f7c8563dd83c0b6e0df84ca3a18ac2bce35 --- /dev/null +++ b/webgui/js/app/windows/AdminUserTopups.js @@ -0,0 +1,297 @@ + + +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 diff --git a/webgui/js/app/windows/AdminUsers.js b/webgui/js/app/windows/AdminUsers.js index ab07e5e2486c8abcb49af984d4175d625b5ef952..97270a8924f1ab5602b4a0355d8ab228ebe03fba 100644 --- a/webgui/js/app/windows/AdminUsers.js +++ b/webgui/js/app/windows/AdminUsers.js @@ -151,6 +151,34 @@ function showAdminUserWindow() { } else { 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 Ext.Msg.show({ title: "Nothing selected",