server/settings/ajax/creategroup.php
Bart Visscher 17e631bc5e Use OC_JSON for json responses
Create OC_JSON class, for single point of creating json responses.
No real logic change, this just cleans up the code a bit.
2011-09-25 22:19:28 +02:00

28 lines
695 B
PHP

<?php
// Init owncloud
require_once('../../lib/base.php');
// Check if we are a user
if( !OC_User::isLoggedIn() || !OC_Group::inGroup( OC_User::getUser(), 'admin' )){
OC_JSON::error(array("data" => array( "message" => "Authentication error" )));
exit();
}
$groupname = $_POST["groupname"];
// Does the group exist?
if( in_array( $groupname, OC_Group::getGroups())){
OC_JSON::error(array("data" => array( "message" => "Group already exists" )));
exit();
}
// Return Success story
if( OC_Group::createGroup( $groupname )){
OC_JSON::success(array("data" => array( "groupname" => $groupname )));
}
else{
OC_JSON::error(array("data" => array( "message" => "Unable to add group" )));
}
?>