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

Fixed up WiSPUsers to use UserID

parent 9b4f4f8e
No related branches found
No related tags found
No related merge requests found
<?php
include_once("include/db.php");
# Return list of wisp users
function getWiSPUsers($params) {
global $db;
# Filters and sorts are the same here
$filtersorts = array(
'Username' => 'users.Username',
'Disabled' => 'users.Disabled',
'ID' => 'wisp_userdata.UserID',
'Firstname' => 'wisp_userdata.Firstname',
'Lastname' => 'wisp_userdata.Lastname',
'Email' => 'wisp_userdata.Email',
'Phone' => 'wisp_userdata.Phone'
);
$res = DBSelectSearch("
SELECT
users.Username,
users.Disabled,
wisp_userdata.UserID,
wisp_userdata.FirstName,
wisp_userdata.LastName,
wisp_userdata.Email,
wisp_userdata.Phone
FROM
users, wisp_userdata
WHERE
wisp_userdata.UserID = users.ID
",$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->userid;
$item['Username'] = $row->username;
$item['Disabled'] = $row->disabled;
$item['Firstname'] = $row->firstname;
$item['Lastname'] = $row->lastname;
$item['Email'] = $row->email;
$item['Phone'] = $row->phone;
# push this row onto array
array_push($resultArray,$item);
}
return array($resultArray,$numResults);
}
# Return specific wisp user row
function getWiSPUser($params) {
global $db;
$res = DBSelect("SELECT ID, Username FROM users WHERE ID = ?",array($params[0]));
if (!is_object($res)) {
return $res;
}
$resultArray = array();
$row = $res->fetchObject();
$resultArray['ID'] = $row->id;
$resultArray['Username'] = $row->username;
return $resultArray;
}
# Remove wisp user
function removeWiSPUser($params) {
global $db;
DBBegin();
$res = DBDo("DELETE FROM wisp_userdata WHERE UserID = ?",array($params[0]));
if ($res !== FALSE) {
$res = DBDo("DELETE FROM users WHERE ID = ?",array($params[0]));
} else {
DBRollback();
return $res;
}
if ($res !== FALSE) {
DBCommit();
return $res;
} else {
DBRollback();
}
return NULL;
}
# Add wisp user
function createWiSPUser($params) {
global $db;
DBBegin();
$res = DBDo("INSERT INTO users (Username) VALUES (?)",array($params[0]['Username']));
if ($res !== FALSE) {
$userID = DBLastInsertID();
$res = DBDo("INSERT INTO wisp_userdata (UserID) VALUES (?)",array($userID));
}
if ($res !== FALSE) {
DBCommit();
return $res;
} else {
DBRollback();
}
# if (!is_numeric($res)) {
# return $res;
# }
return NULL;
}
# Edit admin group
function updateWiSPUser($params) {
global $db;
$res = DBDo("UPDATE users SET Username = ? WHERE ID = ?",array($params[0]['Username'],$params[0]['ID']));
if (!is_numeric($res)) {
return $res;
}
return NULL;
}
?>
...@@ -142,42 +142,42 @@ function showWiSPUserWindow() { ...@@ -142,42 +142,42 @@ function showWiSPUserWindow() {
colModel: new Ext.grid.ColumnModel([ colModel: new Ext.grid.ColumnModel([
{ {
id: 'ID', id: 'ID',
header: "ID", header: "UserID",
sortable: true, sortable: true,
dataIndex: 'ID' dataIndex: 'ID'
}, },
{ {
header: "AgentName", header: "Username",
sortable: true, sortable: true,
dataIndex: 'AgentName' dataIndex: 'Username'
}, },
{ {
header: "Username", header: "Disabled",
sortable: true, sortable: true,
dataIndex: 'Username' dataIndex: 'Disabled'
}, },
{ {
header: "Service", header: "First Name",
sortable: true, sortable: true,
dataIndex: 'Service' dataIndex: 'Firstname'
}, },
{ {
header: "Usage Cap", header: "Last Name",
sortable: true, sortable: true,
dataIndex: 'UsageCap' dataIndex: 'Lastname'
}, },
{ {
header: "Agent Ref", header: "Email",
sortable: true, sortable: true,
dataIndex: 'AgentRef' dataIndex: 'Email'
}, },
{ {
header: "Disabled", header: "Phone",
sortable: false, sortable: true,
dataIndex: 'Disabled' dataIndex: 'Phone'
} }
]), ]),
autoExpandColumn: 'Service' autoExpandColumn: 'Username'
}, },
// Store config // Store config
{ {
...@@ -194,11 +194,12 @@ function showWiSPUserWindow() { ...@@ -194,11 +194,12 @@ function showWiSPUserWindow() {
{ {
filters: [ filters: [
{type: 'numeric', dataIndex: 'ID'}, {type: 'numeric', dataIndex: 'ID'},
{type: 'string', dataIndex: 'AgentName'},
{type: 'string', dataIndex: 'Username'}, {type: 'string', dataIndex: 'Username'},
{type: 'string', dataIndex: 'Service'}, {type: 'boolean', dataIndex: 'Disabled'},
{type: 'numeric', dataIndex: 'UsageCap'}, {type: 'string', dataIndex: 'Firstname'},
{type: 'string', dataIndex: 'AgentRef'} {type: 'string', dataIndex: 'Lastname'},
{type: 'string', dataIndex: 'Email'},
{type: 'string', dataIndex: 'Phone'}
] ]
} }
); );
...@@ -221,40 +222,17 @@ function showWiSPUserEditWindow(id) { ...@@ -221,40 +222,17 @@ function showWiSPUserEditWindow(id) {
SOAPFunction: 'updateWiSPUser', SOAPFunction: 'updateWiSPUser',
SOAPParams: SOAPParams:
'0:ID,'+ '0:ID,'+
'0:UsageCap,'+ '0:Username'
'0:AgentRef,'+
'0:AgentDisabled:boolean'
}; };
editMode = true;
// We doing an Add // We doing an Add
} else { } else {
submitAjaxConfig = { submitAjaxConfig = {
SOAPFunction: 'createWiSPUser', SOAPFunction: 'createWiSPUser',
SOAPParams: SOAPParams:
'0:AgentID,'+ '0:Username'
'0:UserName,'+
'0:UsageCap,'+
'0:AgentRef,'+
'0:AgentDisabled:boolean'
}; };
editMode = false;
} }
// Service store
var serviceStore = new Ext.ux.JsonStore({
ID: id,
sortInfo: { field: "Name", direction: "ASC" },
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'WiSPUsers',
SOAPFunction: 'getClasses',
AgentID: 1,
SOAPParams: '0:AgentID,__search'
}
});
// Create window // Create window
var wispUserFormWindow = new Ext.ux.GenericFormWindow( var wispUserFormWindow = new Ext.ux.GenericFormWindow(
...@@ -284,148 +262,24 @@ function showWiSPUserEditWindow(id) { ...@@ -284,148 +262,24 @@ function showWiSPUserEditWindow(id) {
vtype: 'usernamePart', vtype: 'usernamePart',
maskRe: usernamePartRe, maskRe: usernamePartRe,
allowBlank: false, allowBlank: false,
disabled: editMode
},
{
xtype: 'combo',
// We use an ID so we can get the box later
id: 'agent_combobox',
fieldLabel: 'Agent',
name: 'Agent',
allowBlank: false,
width: 225,
store: new Ext.ux.JsonStore({
ID: id,
sortInfo: { field: "Name", direction: "ASC" },
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'Agents',
SOAPFunction: 'getAgents',
SOAPParams: '__search'
}
}),
displayField: 'Name',
valueField: 'ID',
hiddenName: 'AgentID',
forceSelection: false,
triggerAction: 'all',
editable: false,
disabled: editMode
},
{
xtype: 'combo',
// We use an ID so we can get the box later
id: 'service_combobox',
fieldLabel: 'Service',
name: 'Service',
allowBlank: false,
width: 340,
store: serviceStore,
displayField: 'Service',
valueField: 'ID',
hiddenName: 'ClassID',
forceSelection: false,
triggerAction: 'all',
editable: false,
disabled: true
},
{
fieldLabel: 'Usage Cap',
name: 'UsageCap',
},
{
fieldLabel: 'Agent Ref',
name: 'AgentRef'
}, },
{
xtype: 'checkbox',
fieldLabel: 'Disabled',
name: 'AgentDisabled'
}/*,
{
xtype: 'tabpanel',
plain: 'true',
deferredRender: false, // Load all panels!
activeTab: 0,
height: 100,
defaults: {
layout: 'form',
bodyStyle: 'padding: 10px;'
},
items: [
{
title: 'Policy Settings',
layout: 'form',
defaultType: 'textfield',
items: [
{
fieldLabel: 'Transport Policy',
name: 'Policy',
vtype: 'number',
value: '1'
}
]
}
]
}*/
], ],
}, },
// Submit button config // Submit button config
submitAjaxConfig submitAjaxConfig
); );
// Events
if (!id) {
wispUserFormWindow.findById('agent_combobox').on({
select: {
fn: function() {
var tb = this.ownerCt.findById('service_combobox');
if (this.getValue()) {
tb.reset();
serviceStore.baseParams.AgentID = this.getValue();
serviceStore.reload();
tb.enable();
} else {
tb.reset();
tb.disable();
}
}
},
});
}
wispUserFormWindow.show(); wispUserFormWindow.show();
if (id) { if (id) {
wispUserFormWindow.getComponent('formpanel').load({ wispUserFormWindow.getComponent('formpanel').load({
params: { params: {
id: id, ID: id,
SOAPUsername: globalConfig.soap.username, SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password, SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype, SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'WiSPUsers', SOAPModule: 'WiSPUsers',
SOAPFunction: 'getWiSPUser', SOAPFunction: 'getWiSPUser',
SOAPParams: 'id' SOAPParams: 'ID'
} }
}); });
} }
...@@ -453,13 +307,13 @@ function showWiSPUserRemoveWindow(parent,id) { ...@@ -453,13 +307,13 @@ function showWiSPUserRemoveWindow(parent,id) {
// Do ajax request // Do ajax request
uxAjaxRequest(parent,{ uxAjaxRequest(parent,{
params: { params: {
id: id, ID: id,
SOAPUsername: globalConfig.soap.username, SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password, SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype, SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'WiSPUsers', SOAPModule: 'WiSPUsers',
SOAPFunction: 'removeWiSPUser', SOAPFunction: 'removeWiSPUser',
SOAPParams: 'id' SOAPParams: 'ID'
} }
}); });
......
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