From 37a84136c879425a15efdafd87c1256a0c74e685 Mon Sep 17 00:00:00 2001 From: Robert Anderson <randerson@lbsd.net> Date: Tue, 12 May 2009 13:56:51 +0000 Subject: [PATCH] Fixed up WiSPUsers to use UserID --- webgui/include/ajax/functions/WiSPUsers.php | 145 ++++++++++++++ webgui/js/app/windows/WiSPUsers.js | 198 +++----------------- 2 files changed, 171 insertions(+), 172 deletions(-) create mode 100644 webgui/include/ajax/functions/WiSPUsers.php diff --git a/webgui/include/ajax/functions/WiSPUsers.php b/webgui/include/ajax/functions/WiSPUsers.php new file mode 100644 index 00000000..d7c98fab --- /dev/null +++ b/webgui/include/ajax/functions/WiSPUsers.php @@ -0,0 +1,145 @@ +<?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; +} + +?> diff --git a/webgui/js/app/windows/WiSPUsers.js b/webgui/js/app/windows/WiSPUsers.js index c8394ac1..6256fc92 100644 --- a/webgui/js/app/windows/WiSPUsers.js +++ b/webgui/js/app/windows/WiSPUsers.js @@ -142,42 +142,42 @@ function showWiSPUserWindow() { colModel: new Ext.grid.ColumnModel([ { id: 'ID', - header: "ID", + header: "UserID", sortable: true, dataIndex: 'ID' }, { - header: "AgentName", + header: "Username", sortable: true, - dataIndex: 'AgentName' + dataIndex: 'Username' }, { - header: "Username", + header: "Disabled", sortable: true, - dataIndex: 'Username' + dataIndex: 'Disabled' }, { - header: "Service", + header: "First Name", sortable: true, - dataIndex: 'Service' + dataIndex: 'Firstname' }, { - header: "Usage Cap", + header: "Last Name", sortable: true, - dataIndex: 'UsageCap' + dataIndex: 'Lastname' }, { - header: "Agent Ref", + header: "Email", sortable: true, - dataIndex: 'AgentRef' + dataIndex: 'Email' }, { - header: "Disabled", - sortable: false, - dataIndex: 'Disabled' + header: "Phone", + sortable: true, + dataIndex: 'Phone' } ]), - autoExpandColumn: 'Service' + autoExpandColumn: 'Username' }, // Store config { @@ -194,11 +194,12 @@ function showWiSPUserWindow() { { filters: [ {type: 'numeric', dataIndex: 'ID'}, - {type: 'string', dataIndex: 'AgentName'}, {type: 'string', dataIndex: 'Username'}, - {type: 'string', dataIndex: 'Service'}, - {type: 'numeric', dataIndex: 'UsageCap'}, - {type: 'string', dataIndex: 'AgentRef'} + {type: 'boolean', dataIndex: 'Disabled'}, + {type: 'string', dataIndex: 'Firstname'}, + {type: 'string', dataIndex: 'Lastname'}, + {type: 'string', dataIndex: 'Email'}, + {type: 'string', dataIndex: 'Phone'} ] } ); @@ -221,40 +222,17 @@ function showWiSPUserEditWindow(id) { SOAPFunction: 'updateWiSPUser', SOAPParams: '0:ID,'+ - '0:UsageCap,'+ - '0:AgentRef,'+ - '0:AgentDisabled:boolean' + '0:Username' }; - editMode = true; // We doing an Add } else { submitAjaxConfig = { SOAPFunction: 'createWiSPUser', SOAPParams: - '0:AgentID,'+ - '0:UserName,'+ - '0:UsageCap,'+ - '0:AgentRef,'+ - '0:AgentDisabled:boolean' + '0:Username' }; - 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 var wispUserFormWindow = new Ext.ux.GenericFormWindow( @@ -284,148 +262,24 @@ function showWiSPUserEditWindow(id) { vtype: 'usernamePart', maskRe: usernamePartRe, 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 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(); if (id) { wispUserFormWindow.getComponent('formpanel').load({ params: { - id: id, + ID: id, SOAPUsername: globalConfig.soap.username, SOAPPassword: globalConfig.soap.password, SOAPAuthType: globalConfig.soap.authtype, SOAPModule: 'WiSPUsers', SOAPFunction: 'getWiSPUser', - SOAPParams: 'id' + SOAPParams: 'ID' } }); } @@ -453,13 +307,13 @@ function showWiSPUserRemoveWindow(parent,id) { // Do ajax request uxAjaxRequest(parent,{ params: { - id: id, + ID: id, SOAPUsername: globalConfig.soap.username, SOAPPassword: globalConfig.soap.password, SOAPAuthType: globalConfig.soap.authtype, SOAPModule: 'WiSPUsers', SOAPFunction: 'removeWiSPUser', - SOAPParams: 'id' + SOAPParams: 'ID' } }); -- GitLab