summaryrefslogtreecommitdiffstats
path: root/settings/ajax/creategroup.php
blob: 83733ac4d2d58c130f447504b07bf5c02c6cb85d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php

// Init owncloud
require_once '../../lib/base.php';
OCP\JSON::callCheck();

// Check if we are a user
if( !OC_User::isLoggedIn() || !OC_Group::inGroup( OC_User::getUser(), 'admin' )) {
	OC_JSON::error(array("data" => array( "message" => $l->t("Authentication error") )));
	exit();
}

OCP\JSON::callCheck();

$groupname = $_POST["groupname"];

// Does the group exist?
if( in_array( $groupname, OC_Group::getGroups())) {
	OC_JSON::error(array("data" => array( "message" => $l->t("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" => $l->t("Unable to add group") )));
}