creategroup.php 715 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. // Init owncloud
  3. require_once('../../lib/base.php');
  4. // Check if we are a user
  5. if( !OC_User::isLoggedIn() || !OC_Group::inGroup( OC_User::getUser(), 'admin' )){
  6. OC_JSON::error(array("data" => array( "message" => "Authentication error" )));
  7. exit();
  8. }
  9. OCP\JSON::callCheck();
  10. $groupname = $_POST["groupname"];
  11. // Does the group exist?
  12. if( in_array( $groupname, OC_Group::getGroups())){
  13. OC_JSON::error(array("data" => array( "message" => "Group already exists" )));
  14. exit();
  15. }
  16. // Return Success story
  17. if( OC_Group::createGroup( $groupname )){
  18. OC_JSON::success(array("data" => array( "groupname" => $groupname )));
  19. }
  20. else{
  21. OC_JSON::error(array("data" => array( "message" => "Unable to add group" )));
  22. }