--- /dev/null
+<?php
+
+// Init owncloud
+require_once('../../lib/base.php');
+
+// We send json data
+header( "Content-Type: application/jsonrequest" );
+
+// Check if we are a user
+if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
+ echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
+ exit();
+}
+
+$groups = array();
+if( isset( $_POST["groups"] )){
+ $groups = $_POST["groups"];
+}
+$username = $_POST["username"];
+$password = $_POST["password"];
+
+foreach( $groups as $i ){
+ OC_GROUP::addToGroup( $username, $i );
+}
+
+// Return Success story
+if( OC_USER::createUser( $username, $password )){
+ 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 add user" )));
+}
+
+?>
--- /dev/null
+<?php
+
+// Init owncloud
+require_once('../../lib/base.php');
+
+// We send json data
+header( "Content-Type: application/jsonrequest" );
+
+// Check if we are a user
+if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
+ echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
+ exit();
+}
+
+$groups = array();
+if( isset( $_POST["groups"] )){
+ $groups = $_POST["groups"];
+}
+$username = $_POST["username"];
+$password = $_POST["password"];
+
+foreach( $groups as $i ){
+ OC_GROUP::addToGroup( $username, $i );
+}
+
+// Return Success story
+if( OC_USER::createUser( $username, $password )){
+ 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 add user" )));
+}
+
+?>
$(document).ready(function(){
+ // Vars we need
+ var uid = "";
+ var gid = "";
// Dialog for adding users
$( "#adduser-form" ).dialog({
autoOpen: false,
modal: true,
buttons: {
"Create an account": function() {
+ var post = $( "#createuserdata" ).serialize();
+ $.post( 'ajax/createuser.php', post, function(data){
+ var newrow = '<tr><td>' + data.data.username + '</td>';
+ newrow = newrow + '<td>' + data.data.groups + '</td>';
+ newrow = newrow + '<td><a href="" class="edituser-button">edit</a> | <a class="removeuser-button" href="">remove</a></td></tr>';
+ $("#userstable").append( newrow );
+ });
$( this ).dialog( "close" );
},
Cancel: function() {
}
},
close: function() {
- allFields.val( "" ).removeClass( "ui-state-error" );
+ true;
}
});
}
},
close: function() {
- allFields.val( "" ).removeClass( "ui-state-error" );
+ true;
}
});
$( ".edituser-button" )
- .click(function() {
- $( "#edituser-form" ).dialog( "open" );
+ .click(function(){
+ uid = $( this ).parent().attr( 'x-uid' );
+ $("#edituserusername").html(uid);
+ $("#edituser-form").dialog("open");
return false;
});
$( ".removeuser-button" )
.click(function() {
+ uid = $( this ).parent().attr( 'x-uid' );
+ $("#deleteuserusername").html(uid);
$( "#removeuser-form" ).dialog( "open" );
return false;
});
width: 350,
modal: true,
buttons: {
- "Remove group": function() {
+ "Remove group": function(){
+ var post = $( "#deletegroupdata" ).serialize();
+ $.post( 'ajax/deletegroup.php', post, function(data){
+ $( "a[x-gid='"+gid+"']" ).parent().remove();
+ });
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
- close: function() {
+ close: function(){
allFields.val( "" ).removeClass( "ui-state-error" );
}
});
$( ".removegroup-button" )
- .click(function() {
- $( "#removegroup-form" ).dialog( "open" );
+ .click(function(){
+ gid = $( this ).parent().attr( 'x-gid' );
+ $("#deletegroupgroupname").html(gid);
+ $("#deletegroupnamefield").val(gid);
+ $("#removegroup-form").dialog( "open" );
return false;
});
} );
exit();
}
-$adminpages = array();
-
-foreach( OC_APP::getAdminPages() as $i ){
- // Do some more work here soon
- $adminpages[] = $i;
-}
-
-$tmpl = new OC_TEMPLATE( "admin", "index", "admin" );
-$tmpl->assign( "adminpages", $adminpages );
+$tmpl = new OC_TEMPLATE( "admin", "system", "admin" );
$tmpl->printPage();
?>
<h1>Administration</h1>
<h2>Users</h2>
-<table>
+<table id="userstable">
<thead>
<tr>
<th>Name</th>
<th>Groups</th>
<th></th>
</tr>
- <thead>
+ </thead>
<tbody>
<?php foreach($_["users"] as $user): ?>
<tr>
<td><?php echo $user["name"]; ?></td>
<td><?php echo $user["groups"]; ?></td>
- <td><a href="" class="edituser-button">edit</a> | <a class="removeuser-button" href="">remove</a></td>
+ <td x-uid="<?php echo $user["name"] ?>"><a href="" class="edituser-button">edit</a> | <a class="removeuser-button" href="">remove</a></td>
</tr>
<?php endforeach; ?>
</tbody>
<h2>Groups</h2>
<form>
- <table>
+ <table id="groupstable">
<thead>
<tr>
<th>Name</th>
<th></th>
</tr>
- <thead>
+ </thead>
<tbody>
<?php foreach($_["groups"] as $group): ?>
<tr>
<td><?php echo $group["name"] ?></td>
- <td><a class="removegroup-button" href="">remove</a></td>
+ <td x-gid="<?php echo $group["name"]; ?>"><a class="removegroup-button" href="">remove</a></td>
</tr>
<?php endforeach; ?>
<tr>
<div id="adduser-form" title="Add user">
- <form>
+ <form id="createuserdata">
+ <fieldset>
User name<br>
- <input type="text" name="name" /><br>
+ <input type="text" name="username" /><br>
Password<br>
<input type="password" name="password" />
+ </fieldset>
+ <fieldset id="usergroups">
+ groups<br>
+ <?php foreach($_["groups"] as $i): ?>
+ <input type="checkbox" name="groups[]" value="<? echo $i["name"]; ?>" /><? echo $i["name"]; ?><br>
+ <?php endforeach; ?>
+ </fieldset>
</form>
</div>
<div id="edituser-form" title="Force new password">
- <form>
- New password for $user<br>
+ <form id="edituserdata">
+ New password for <span id="edituserusername">$user</span><br>
<input type="password" name="password" />
+ <input type="hidden" name="username" value="">
</form>
</div>
<div id="removeuser-form" title="Remove user">
- Do you really want to delete user $user?
+ <form id="removeuserdata">
+ Do you really want to delete user <span id="deleteuserusername">$user</span>?
+ <input type="hidden" name="username" value="">
+ </form>
</div>
<div id="removegroup-form" title="Remove Group">
- Do you really want to delete group $group?
+ <form id="removeuserdata">
+ Do you really want to delete group <span id="deletegroupgroupname">$group</span>?
+ <input id="deletegroupnamefield" type="hidden" name="username" value="">
+ </form>
</div>