app_defaults.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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-2019
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. if ($domains_processed == 1) {
  22. //if the default groups do not exist add them
  23. $group = new groups;
  24. $group->defaults();
  25. //find rows that have a null group_uuid and set the correct group_uuid
  26. $sql = "select * from v_user_groups ";
  27. $sql .= "where group_uuid is null; ";
  28. $result = $database->select($sql, null, 'all');
  29. if (is_array($result)) {
  30. foreach($result as $row) {
  31. if (!empty($row['group_name'])) {
  32. //get the group_uuid
  33. $sql = "select group_uuid from v_groups ";
  34. $sql .= "where group_name = :group_name ";
  35. $parameters['group_name'] = $row['group_name'];
  36. $group_uuid = $database->select($sql, $parameters, 'column');
  37. unset($sql, $parameters);
  38. //set the group_uuid
  39. $sql = "update v_user_groups set ";
  40. $sql .= "group_uuid = :group_uuid ";
  41. $sql .= "where user_group_uuid = :user_group_uuid; ";
  42. $parameters['group_uuid'] = $group_uuid;
  43. $parameters['user_group_uuid'] = $row['user_group_uuid'];
  44. $database->execute($sql, $parameters);
  45. unset($sql, $parameters);
  46. }
  47. }
  48. unset ($result);
  49. }
  50. //set the default group levels
  51. $sql = "select * from v_groups ";
  52. $sql .= "where group_level is null; ";
  53. $result = $database->select($sql, null, 'all');
  54. if (is_array($result) && count($result) > 0) {
  55. $x = 0;
  56. foreach($result as $row) {
  57. $array['groups'][$x]['group_uuid'] = $row['group_uuid'];
  58. switch ($row['group_name']) {
  59. case 'superadmin':
  60. $array['groups'][$x]['group_level'] = 80;
  61. break;
  62. case 'admin':
  63. $array['groups'][$x]['group_level'] = 50;
  64. break;
  65. case 'user':
  66. $array['groups'][$x]['group_level'] = 30;
  67. break;
  68. case 'agent':
  69. $array['groups'][$x]['group_level'] = 20;
  70. break;
  71. case 'public':
  72. $array['groups'][$x]['group_level'] = 10;
  73. break;
  74. default:
  75. $array['groups'][$x]['group_level'] = 10;
  76. }
  77. $x++;
  78. }
  79. $database->app_name = 'groups';
  80. $database->app_uuid = '2caf27b0-540a-43d5-bb9b-c9871a1e4f84';
  81. $database->save($array, false);
  82. unset($array);
  83. }
  84. //update the group_uuid
  85. $sql = "UPDATE v_group_permissions as p ";
  86. $sql .= "SET group_uuid = ( ";
  87. $sql .= " SELECT group_uuid FROM v_groups as g ";
  88. $sql .= " WHERE g.group_name = p.group_name ";
  89. $sql .= ") ";
  90. $sql .= "WHERE group_uuid is null; ";
  91. $parameters = null;
  92. $database->execute($sql, $parameters);
  93. unset($sql, $parameters);
  94. //drop the view_groups
  95. $database->execute("DROP VIEW view_groups;", null);
  96. //add or update the view
  97. $sql = "CREATE VIEW view_groups AS (";
  98. $sql .= " select domain_uuid, group_uuid, group_name, ";
  99. $sql .= " (select domain_name from v_domains where domain_uuid = g.domain_uuid) as domain_name, ";
  100. $sql .= " (select count(*) from v_group_permissions where group_uuid = g.group_uuid) as group_permissions, ";
  101. $sql .= " (select count(*) from v_user_groups where group_uuid = g.group_uuid) as group_members, ";
  102. $sql .= " group_level, group_protected, group_description ";
  103. $sql .= " from v_groups as g ";
  104. $sql .= ");";
  105. $database->execute($sql, null);
  106. unset($sql);
  107. //group permissions
  108. $database->execute("update v_group_permissions set permission_protected = 'false' where permission_protected is null;", null);
  109. $database->execute("update v_group_permissions set permission_assigned = 'true' where permission_assigned is null;", null);
  110. }
  111. ?>