group_member_add.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2020
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes files
  22. require_once dirname(__DIR__, 2) . "/resources/require.php";
  23. require_once "resources/check_auth.php";
  24. //check permissions
  25. if (permission_exists('group_member_add') || if_group("superadmin")) {
  26. //access allowed
  27. }
  28. else {
  29. echo "access denied";
  30. return;
  31. }
  32. //requires a superadmin to add a user to the superadmin group
  33. if (!if_group("superadmin") && $_GET["group_name"] == "superadmin") {
  34. echo "access denied";
  35. return;
  36. }
  37. //connect to the database
  38. $database = new database;
  39. //get the http values and set them as variables
  40. $domain_uuid = $_POST["domain_uuid"];
  41. $group_uuid = $_POST["group_uuid"];
  42. $group_name = $_POST["group_name"];
  43. $user_uuid = $_POST["user_uuid"];
  44. //validate the token
  45. $token = new token;
  46. if (!$token->validate('/core/groups/group_members.php')) {
  47. message::add($text['message-invalid_token'],'negative');
  48. header('Location: groups.php');
  49. exit;
  50. }
  51. //add the user to the group
  52. if (is_uuid($user_uuid) && is_uuid($group_uuid) && !empty($group_name)) {
  53. $array['user_groups'][0]['user_group_uuid'] = uuid();
  54. $array['user_groups'][0]['domain_uuid'] = $domain_uuid;
  55. $array['user_groups'][0]['group_uuid'] = $group_uuid;
  56. $array['user_groups'][0]['group_name'] = $group_name;
  57. $array['user_groups'][0]['user_uuid'] = $user_uuid;
  58. $p = permissions::new();
  59. $p->add('user_group_add', 'temp');
  60. $database->app_name = 'groups';
  61. $database->app_uuid = '2caf27b0-540a-43d5-bb9b-c9871a1e4f84';
  62. $database->save($array);
  63. unset($array);
  64. $p->delete('user_group_add', 'temp');
  65. message::add($text['message-update']);
  66. }
  67. //redirect the user
  68. header("Location: group_members.php?group_uuid=".urlencode($group_uuid)."&group_name=".urlencode($group_name));
  69. ?>