permissions_copy.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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-2013
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Sérgio Reis <[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_permission_add')) {
  26. //access granted
  27. }
  28. else {
  29. echo "access denied";
  30. exit;
  31. }
  32. //connect to the database
  33. $database = new database;
  34. //add multi-lingual support
  35. $language = new text;
  36. $text = $language->get();
  37. //include paging
  38. require_once "resources/paging.php";
  39. //set the http get/post variable(s) to a php variable
  40. if (is_uuid($_REQUEST["id"]) && isset($_REQUEST["new_group_name"])) {
  41. //get HTTP values and set as variables
  42. $group_uuid = $_REQUEST["id"];
  43. $new_group_name = $_REQUEST["new_group_name"];
  44. $new_group_desc = $_REQUEST["new_group_desc"];
  45. //get the source groups data
  46. $sql = "select * from v_groups ";
  47. $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
  48. $sql .= "and group_uuid = :group_uuid ";
  49. $parameters['domain_uuid'] = $domain_uuid;
  50. $parameters['group_uuid'] = $group_uuid;
  51. $row = $database->select($sql, $parameters, 'row');
  52. if (is_array($row) && sizeof($row) != 0) {
  53. $domain_uuid = $row["domain_uuid"];
  54. $group_name = $row["group_name"];
  55. }
  56. unset($sql, $parameters, $row);
  57. //create new target group
  58. $new_group_uuid = uuid();
  59. $array['groups'][0]['group_uuid'] = $new_group_uuid;
  60. if (is_uuid($domain_uuid)) {
  61. $array['groups'][0]['domain_uuid'] = $domain_uuid;
  62. }
  63. $array['groups'][0]['group_name'] = $new_group_name;
  64. $array['groups'][0]['group_description'] = $new_group_desc;
  65. $database->app_name = 'groups';
  66. $database->app_uuid = '2caf27b0-540a-43d5-bb9b-c9871a1e4f84';
  67. $database->save($array);
  68. unset($array);
  69. //get the source group permissions data
  70. $sql = "select * from v_group_permissions ";
  71. $sql .= "where group_name = :group_name ";
  72. if (is_uuid($domain_uuid)) {
  73. $sql .= "and domain_uuid = :domain_uuid ";
  74. $parameters['domain_uuid'] = $domain_uuid;
  75. }
  76. else {
  77. $sql .= "and domain_uuid is null ";
  78. }
  79. $parameters['group_name'] = $group_name;
  80. $result = $database->select($sql, $parameters, 'all');
  81. unset($sql, $parameters);
  82. if (is_array($result) && sizeof($result) != 0) {
  83. foreach ($result as $x => $row) {
  84. //define group permissions values
  85. $domain_uuid = $row["domain_uuid"];
  86. $permission_name = $row["permission_name"];
  87. $group_name = $row["group_name"];
  88. //build insert array
  89. $array['group_permissions'][$x]['group_permission_uuid'] = uuid();
  90. if (is_uuid($domain_uuid)) {
  91. $array['group_permissions'][$x]['domain_uuid'] = $domain_uuid;
  92. }
  93. $array['group_permissions'][$x]['permission_name'] = $permission_name;
  94. $array['group_permissions'][$x]['group_name'] = $new_group_name;
  95. $array['group_permissions'][$x]['group_uuid'] = $new_group_uuid;
  96. }
  97. if (is_array($array) && sizeof($array) != 0) {
  98. //grant temporary permissions
  99. $p = permissions::new();
  100. $p->add('group_permission_add', 'temp');
  101. //execute insert
  102. $database->app_name = 'groups';
  103. $database->app_uuid = '2caf27b0-540a-43d5-bb9b-c9871a1e4f84';
  104. $database->save($array);
  105. unset($array);
  106. //revoke temporary permissions
  107. $p->delete('group_permission_add', 'temp');
  108. //set message
  109. message::add($text['message-copy']);
  110. }
  111. }
  112. unset($result, $row);
  113. }
  114. //redirect
  115. header("Location: groups.php");
  116. ?>