diff --git a/admin/ajax/changepassword.php b/admin/ajax/changepassword.php new file mode 100644 index 0000000000..12a27fff58 --- /dev/null +++ b/admin/ajax/changepassword.php @@ -0,0 +1,25 @@ + "error", "data" => array( "message" => "Authentication error" ))); + exit(); +} + +$name = $_POST["username"]; + +// Return Success story +if( OC_USER::deleteUser( $name )){ + echo json_encode( array( "status" => "success", "data" => array( "username" => $name ))); +} +else{ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to delete user" ))); +} + +?> diff --git a/admin/ajax/removeuser.php b/admin/ajax/removeuser.php index 12a27fff58..9cf52c128b 100644 --- a/admin/ajax/removeuser.php +++ b/admin/ajax/removeuser.php @@ -12,14 +12,30 @@ if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' exit(); } -$name = $_POST["username"]; +$groups = array(); +$username = $_POST["username"]; +$password = $_POST["password"]; +$groups = $_POST["groups"]; + +$success = true; +if( $password ){ + $success = $success && OC_USER::setPassword( $username, $password ); +} + +// update groups (delete old ones, add new ones) +foreach( OC_GROUP::getUserGroups( $username ) as $i ){ + OC_GROUP::removeFromGroup( $username, $i ); +} +foreach( $groups as $i ){ + OC_GROUP::addToGroup( $username, $i ); +} // Return Success story -if( OC_USER::deleteUser( $name )){ - echo json_encode( array( "status" => "success", "data" => array( "username" => $name ))); +if( $success ){ + echo json_encode( array( "status" => "success", "data" => array( "username" => $username, "groups" => implode( ", ", $groups )))); } else{ - echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to delete user" ))); + echo json_encode( array( "status" => "error", "data" => array( "message" => "Edit user" ))); } ?> diff --git a/admin/ajax/togglegroups.php b/admin/ajax/togglegroups.php new file mode 100644 index 0000000000..12a27fff58 --- /dev/null +++ b/admin/ajax/togglegroups.php @@ -0,0 +1,25 @@ + "error", "data" => array( "message" => "Authentication error" ))); + exit(); +} + +$name = $_POST["username"]; + +// Return Success story +if( OC_USER::deleteUser( $name )){ + echo json_encode( array( "status" => "success", "data" => array( "username" => $name ))); +} +else{ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to delete user" ))); +} + +?> diff --git a/admin/js/users.js b/admin/js/users.js index 7cd1ed6f62..e543e52f1b 100644 --- a/admin/js/users.js +++ b/admin/js/users.js @@ -2,72 +2,168 @@ $(document).ready(function(){ // Vars we need var uid = ""; var gid = ""; - // Dialog for adding users - $( "#adduser-form" ).dialog({ - autoOpen: false, - height: 300, - width: 350, - modal: true, - buttons: { - "Create an account": function() { - var post = $( "#createuserdata" ).serialize(); - $.post( 'ajax/createuser.php', post, function(data){ - if( data.status == "success" ){ - var newrow = '' + data.data.username + ''; - newrow = newrow + '' + data.data.groups + ''; - newrow = newrow + 'edit | remove'; - $("#userstable").append( newrow ); - } - else{ - alert( "Bug By Jakob (c)" ); - } - }); - $( this ).dialog( "close" ); - }, - Cancel: function() { - $( this ).dialog( "close" ); - } - }, - close: function() { - true; - } - }); - $( "#adduser-button" ) - .click(function() { - $( "#adduser-form" ).dialog( "open" ); + //######################################################################### + // Functions for editing the dom after user manipulation + //######################################################################### + + // Manipulating the page after crteating a user + function userCreated( username, groups ){ + // Add user to table + var newrow = ''+username+''; + newrow = newrow+''+groups+''; + newrow = newrow+'edit | remove'; + $("#usertable").append( newrow ); + + // Clear forms + $("input[x-use='createuserfield']").val( "" ); + $("input[x-use='createusercheckbox']").attr( "checked", false ); + } + + // Manipulating the page after crteating a user + function userEdited( username, groups ){ + // Edit table + var newrow = ''+username+''; + newrow = newrow+''+groups+''; + newrow = newrow+'edit | remove'; + $("td[x-uid='"+username+"']").replace( newrow ); + } + + function userRemoved( username ){ + $( "td[x-uid='"+username+"']" ).parent().remove(); + } + + function groupCreated( groupname ){ + var newrow = '' + groupname + ''; + newrow = newrow + 'remove'; + $("#grouptable").append( newrow ); + + // Delete form content + $("input[x-use='creategroupfield']").val( "" ); + + // Add group option to Create User and Edit User + createuser = ''+groupname+'
'; + $("#createusergroups").append( createuser ); + $("#editusergroups").append( createuser ); + } + + function groupRemoved( groupname ){ + // Delete the options + $( "td[x-gid='"+groupname+"']" ).parent().remove(); + $( "span[x-gid='"+groupname+"']" ).remove(); + $( "input[x-gid='"+groupname+"']" ).remove(); + + // remove it from user list + $( "td[x-use='usergroups']" ).each(function(index){ + var content = $(this).text(); + var list = content.split( ", " ); + var newlist = []; + for( var i = 0; i < list.length; i++ ){ + var temp = list[i]; + if( temp != groupname ){ + newlist.push( temp ); + } + } + var newstring = newlist.join( ", " ); + $(this).html( newstring ) + }); + + } + + //######################################################################### + // Clicking on buttons + //######################################################################### + + // Show the create user form + $( "#createuseroptionbutton" ) + .click(function(){ + $( "#createuserform" ).toggle(); return false; }); - // Dialog for adding users - $( "#edituser-form" ).dialog({ - autoOpen: false, - height: 300, - width: 350, - modal: true, - buttons: { - "Edit password": function() { - $( this ).dialog( "close" ); - }, - Cancel: function() { - $( this ).dialog( "close" ); - } - }, - close: function() { - true; - } - }); - - $( ".edituser-button" ) + // Create a new user + $( "#createuserbutton" ) .click(function(){ + // Create the post data + var post = $( "#createuserdata" ).serialize(); + + // Ajax call + $.post( 'ajax/createuser.php', post, function(data){ + // If it says "success" then we are happy + if( data.status == "success" ){ + userCreated( data.data.username, data.data.groups ); + } + else{ + alert( "Bug By Jakob (c)" ); + } + }); + return false; + }); + + $( ".edituserbutton" ).live( 'click', function(){ uid = $( this ).parent().attr( 'x-uid' ); $("#edituserusername").html(uid); - $("#edituser-form").dialog("open"); + $("#edituserform").dialog("open"); return false; }); + $( ".removeuserbutton" ).live( 'click', function() { + uid = $( this ).parent().attr( 'x-uid' ); + $("#deleteuserusername").html(uid); + $("#deleteusernamefield").val(uid); + $("#removeuserform").dialog( "open" ); + return false; + }); + + $( "#creategroupbutton" ) + .click(function(){ + // Serialize the data + var post = $( "#creategroupdata" ).serialize(); + // Ajax foo + $.post( 'ajax/creategroup.php', post, function(data){ + if( data.status == "success" ){ + groupCreated( data.data.groupname ); + } + else{ + alert( "something went wrong! sorry!" ); + } + }); + return false; + }); + + $( ".removegroupbutton" ).live( 'click', function(){ + gid = $( this ).parent().attr( 'x-gid' ); + $("#removegroupgroupname").html(gid); + $("#removegroupnamefield").val(gid); + $("#removegroupform").dialog( "open" ); + return false; + }); + + //######################################################################### + // Dialogs + //######################################################################### + + // Edit user dialog + $( "#edituserform" ).dialog({ + autoOpen: false, + height: 500, + width: 500, + modal: true, + buttons: { + "Edit user": function() { + $( this ).dialog( "close" ); + }, + Cancel: function() { + $( this ).dialog( "close" ); + } + }, + close: function() { + true; + } + }); + // Removing users - $( "#removeuser-form" ).dialog({ + $( "#removeuserform" ).dialog({ autoOpen: false, height: 300, width: 350, @@ -77,7 +173,7 @@ $(document).ready(function(){ var post = $( "#removeuserdata" ).serialize(); $.post( 'ajax/removeuser.php', post, function(data){ if( data.status == "success" ){ - $( "a[x-uid='"+uid+"']" ).parent().remove(); + userRemoved( uid ); } else{ alert( "Bug By Jakob (c)" ); @@ -94,34 +190,9 @@ $(document).ready(function(){ } }); - $( ".removeuser-button" ) - .click(function() { - uid = $( this ).parent().attr( 'x-uid' ); - $("#deleteuserusername").html(uid); - $("#deleteusernamefield").val(uid); - $( "#removeuser-form" ).dialog( "open" ); - return false; - }); - - // Add a group - $( "#creategroupbutton" ) - .click(function(){ - var post = $( "#creategroupdata" ).serialize(); - $.post( 'ajax/creategroup.php', post, function(data){ - if( data.status == "success" ){ - var newrow = '' + data.data.groupname + ''; - newrow = newrow + 'remove'; - $("#groupstable").append( newrow ); - } - else{ - alert( "something went wrong! sorry!" ); - } - }); - return false; - }); // Dialog for adding users - $( "#removegroup-form" ).dialog({ + $( "#removegroupform" ).dialog({ autoOpen: false, height: 300, width: 350, @@ -131,7 +202,7 @@ $(document).ready(function(){ var post = $( "#removegroupdata" ).serialize(); $.post( 'ajax/removegroup.php', post, function(data){ if( data.status == "success" ){ - $( "a[x-gid='"+gid+"']" ).parent().remove(); + groupRemoved( gid ); } else{ alert( "Bug By Jakob (c)" ); @@ -148,12 +219,5 @@ $(document).ready(function(){ } }); - $( ".removegroup-button" ) - .click(function(){ - gid = $( this ).parent().attr( 'x-gid' ); - $("#deletegroupgroupname").html(gid); - $("#deletegroupnamefield").val(gid); - $("#removegroup-form").dialog( "open" ); - return false; - }); } ); + diff --git a/admin/templates/users.php b/admin/templates/users.php index b2172b0539..081ba189e9 100644 --- a/admin/templates/users.php +++ b/admin/templates/users.php @@ -1,12 +1,6 @@ - -

Administration

Users

- +
@@ -14,80 +8,96 @@ + + + + + + + + + + + + + + - - + +
Name
  
">edit | remove">edit | remove
-New user -

Groups

-
- - +
+ + + + + + + + - - - - - - - + - - - - - - - - - -
Name
Name
">remove
-
- -
-
-
- User name
-
- Password
- -
-
- groups
- - " />
+ + + + + + + ">remove + + + + + + +
+
+ $user
+
+ New password: + +
+ +
+ + " type="checkbox" name="groups[]" value="" /> + ">
+
-
-
- New password for $user
- - -
-
- -
+
Do you really want to delete user $user?
-
+
- Do you really want to delete group $group? - + Do you really want to delete group $group? +
diff --git a/admin/users.php b/admin/users.php index 312bfba2c5..9529ea7497 100644 --- a/admin/users.php +++ b/admin/users.php @@ -40,7 +40,7 @@ foreach( OC_USER::getUsers() as $i ){ foreach( OC_GROUP::getUserGroups( $i ) as $userGroup ){ $ingroups[] = $userGroup; } - $users[] = array( "name" => $i, "groups" => join( ",", $ingroups )); + $users[] = array( "name" => $i, "groups" => join( ", ", $ingroups )); } foreach( OC_GROUP::getGroups() as $i ){