Module: nagvis
Branch: master
Commit: f7ca3420a0794c0b4ff8819a656c910afa58e1a9
URL:    
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=f7ca3420a0794c0b4ff8819a656c910afa58e1a9

Author: LaMi <[email protected]>
Date:   Sun Nov 15 14:58:43 2009 +0100

Added user deletion dialog and mechanism

---

 .../core/classes/CoreAuthorisationHandler.php      |    6 +++
 .../core/classes/CoreAuthorisationModSQLite.php    |   20 ++++++++++
 share/server/core/classes/CoreModUserMgmt.php      |   41 +++++++++++++++++++-
 share/server/core/classes/NagVisViewUserMgmt.php   |    3 +-
 .../templates/pages/default.userMgmt.html          |   20 ++++++++++
 5 files changed, 88 insertions(+), 2 deletions(-)

diff --git a/share/server/core/classes/CoreAuthorisationHandler.php 
b/share/server/core/classes/CoreAuthorisationHandler.php
index b4383b6..5298cf1 100644
--- a/share/server/core/classes/CoreAuthorisationHandler.php
+++ b/share/server/core/classes/CoreAuthorisationHandler.php
@@ -88,6 +88,12 @@ class CoreAuthorisationHandler {
                return $this->sModuleName;
        }
        
+       public function deleteUser($userId) {
+               // FIXME: First check if this is supported
+               
+               return $this->MOD->deleteUser($userId);
+       }
+       
        public function updateUserRoles($userId, $roles) {
                // FIXME: First check if this is supported
                
diff --git a/share/server/core/classes/CoreAuthorisationModSQLite.php 
b/share/server/core/classes/CoreAuthorisationModSQLite.php
index 529afdd..591be6f 100644
--- a/share/server/core/classes/CoreAuthorisationModSQLite.php
+++ b/share/server/core/classes/CoreAuthorisationModSQLite.php
@@ -42,6 +42,21 @@ class CoreAuthorisationModSQLite extends 
CoreAuthorisationModule {
                }
        }
        
+       public function deleteUser($userId) {
+               // Delete user
+               $this->DB->query('DELETE FROM users WHERE 
userId=\''.sqlite_escape_string($userId).'\'');
+               
+               // Delete user roles
+               $this->DB->query('DELETE FROM users2roles WHERE 
userId=\''.sqlite_escape_string($userId).'\'');
+               
+               // Check result
+               if($this->checkUserExistsById($userId) <= 0) {
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+       
        public function updateUserRoles($userId, $roles) {
                // First delete all role perms
                $this->DB->query('DELETE FROM users2roles WHERE 
userId=\''.sqlite_escape_string($userId).'\'');
@@ -169,6 +184,11 @@ class CoreAuthorisationModSQLite extends 
CoreAuthorisationModule {
                return $aPerms;
        }
        
+       private function checkUserExistsById($id) {
+               $RES = $this->DB->query('SELECT userId FROM users WHERE 
userId=\''.sqlite_escape_string($id).'\'');
+               return intval($RES->fetchSingle());
+       }
+       
        private function checkUserExists($sUsername) {
                $RES = $this->DB->query('SELECT userId FROM users WHERE 
name=\''.sqlite_escape_string($sUsername).'\'');
                return intval($RES->fetchSingle());
diff --git a/share/server/core/classes/CoreModUserMgmt.php 
b/share/server/core/classes/CoreModUserMgmt.php
index 00b7334..e227ef4 100644
--- a/share/server/core/classes/CoreModUserMgmt.php
+++ b/share/server/core/classes/CoreModUserMgmt.php
@@ -10,7 +10,8 @@ class CoreModUserMgmt extends CoreModule {
                                        'getUserRoles' => 
REQUIRES_AUTHORISATION,
                                        'getAllRoles' => REQUIRES_AUTHORISATION,
                                        'doAdd' => REQUIRES_AUTHORISATION,
-                                       'doEdit' => REQUIRES_AUTHORISATION);
+                                       'doEdit' => REQUIRES_AUTHORISATION,
+                                       'doDelete' => REQUIRES_AUTHORISATION);
                
                $this->FHANDLER = new CoreRequestHandler($_POST);
        }
@@ -71,12 +72,50 @@ class CoreModUserMgmt extends CoreModule {
                                                $sReturn = '';
                                        }
                                break;
+                               case 'doDelete':
+                                       $aReturn = 
$this->handleResponseDelete();
+                                       
+                                       if($aReturn !== false) {
+                                               
if($this->AUTHORISATION->deleteUser($aReturn['userId'])) {
+                                                       new 
GlobalMessage('NOTE', $this->CORE->getLang()->getText('The user has been 
deleted.'));
+                                                       $sReturn = '';
+                                               } else {
+                                                       new 
GlobalMessage('NOTE', $this->CORE->getLang()->getText('Problem while deleting 
user.'));
+                                                       $sReturn = '';
+                                               }
+                                       } else {
+                                               new GlobalMessage('ERROR', 
$this->CORE->getLang()->getText('You entered invalid information.'));
+                                               $sReturn = '';
+                                       }
+                               break;
                        }
                }
                
                return $sReturn;
        }
                
+       private function handleResponseDelete() {
+               $bValid = true;
+               // Validate the response
+               
+               // Check for needed params
+               if($bValid && !$this->FHANDLER->isSetAndNotEmpty('userId')) {
+                       $bValid = false;
+               }
+               
+               // Parse the specific options
+               // FIXME: validate
+               $userId = intval($this->FHANDLER->get('userId'));
+               
+         // Store response data
+         if($bValid === true) {
+                 // Return the data
+                 return Array('userId' => $userId);
+               } else {
+                       return false;
+               }
+       }
+       
        private function handleResponseEdit() {
                $bValid = true;
                // Validate the response
diff --git a/share/server/core/classes/NagVisViewUserMgmt.php 
b/share/server/core/classes/NagVisViewUserMgmt.php
index baa0cdc..04eb6f4 100644
--- a/share/server/core/classes/NagVisViewUserMgmt.php
+++ b/share/server/core/classes/NagVisViewUserMgmt.php
@@ -57,6 +57,7 @@ class NagVisViewUserMgmt {
                        'htmlBase' => 
$this->CORE->getMainCfg()->getValue('paths', 'htmlbase'),
                        'formTargetAdd' => 
$this->CORE->getMainCfg()->getValue('paths','htmlbase').'/server/core/ajax_handler.php?mod=UserMgmt&amp;act=doAdd',
                        'formTargetEdit' => 
$this->CORE->getMainCfg()->getValue('paths','htmlbase').'/server/core/ajax_handler.php?mod=UserMgmt&amp;act=doEdit',
+                       'formTargetDelete' => 
$this->CORE->getMainCfg()->getValue('paths','htmlbase').'/server/core/ajax_handler.php?mod=UserMgmt&amp;act=doDelete',
                        'htmlImages' => 
$this->CORE->getMainCfg()->getValue('paths', 'htmlimages'),
       'maxPasswordLength' => AUTH_MAX_PASSWORD_LENGTH,
       'maxUsernameLength' => AUTH_MAX_USERNAME_LENGTH,
@@ -65,7 +66,7 @@ class NagVisViewUserMgmt {
       'langPassword2' => $this->CORE->getLang()->getText('Password Confirm'),
       'langUserAdd' => $this->CORE->getLang()->getText('Create User'),
       'langUserModify' => $this->CORE->getLang()->getText('Modify User'),
-      'langUserModify' => $this->CORE->getLang()->getText('Modify User'),
+      'langUserDelete' => $this->CORE->getLang()->getText('Delete User'),
       'langSelectUser' => $this->CORE->getLang()->getText('Select User'),
       'users' => $this->AUTHENTICATION->getAllUsers(),
       'langManageRoles' => $this->CORE->getLang()->getText('Modify Roles'),
diff --git a/share/userfiles/templates/pages/default.userMgmt.html 
b/share/userfiles/templates/pages/default.userMgmt.html
index b1a0976..8088269 100644
--- a/share/userfiles/templates/pages/default.userMgmt.html
+++ b/share/userfiles/templates/pages/default.userMgmt.html
@@ -157,4 +157,24 @@ function getUserRoles(id) \{
                </p>
        </form>
 </fieldset>
+</div>
+
+<div id="deleteUsers">
+<fieldset class="form">
+       <legend>{$langUserDelete}</legend>
+       <form name="userDelete" id="userDeleteForm" action="#" 
onsubmit="submitFrontendForm('{$formTargetDelete}', 'userDeleteForm');return 
false" method="post">
+               <table>
+                       <tr>
+                               <td><label 
for="username">{$langUsername}:</label></td>
+                               <td>
+                                       <select type="text" name="userId" 
id="userId" class="select" tabindex="40" />
+                                               <option value="" 
selected="selected"></option>
+                                               {foreach $users user}<option 
value="{$user.userId}">{$user.name}</option>{/foreach}
+                                       </select>
+                               </td>
+                               <td><input type="submit" name="submit" 
id="submit" value="{$langUserDelete}" tabindex="100" /></td>
+                       </tr>
+               </table>
+       </form>
+</fieldset>
 </div>
\ No newline at end of file


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to