app_defaults.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. $database = new database;
  29. $result = $database->select($sql, null, 'all');
  30. if (is_array($result)) {
  31. foreach($result as $row) {
  32. if (strlen($row['group_name']) > 0) {
  33. //get the group_uuid
  34. $sql = "select group_uuid from v_groups ";
  35. $sql .= "where group_name = :group_name ";
  36. $parameters['group_name'] = $row['group_name'];
  37. $database = new database;
  38. $group_uuid = $database->select($sql, $parameters, 'column');
  39. unset($sql, $parameters);
  40. //set the group_uuid
  41. $sql = "update v_user_groups set ";
  42. $sql .= "group_uuid = :group_uuid ";
  43. $sql .= "where user_group_uuid = :user_group_uuid; ";
  44. $parameters['group_uuid'] = $group_uuid;
  45. $parameters['user_group_uuid'] = $row['user_group_uuid'];
  46. $database = new database;
  47. $database->execute($sql, $parameters);
  48. unset($sql, $parameters);
  49. }
  50. }
  51. unset ($result);
  52. }
  53. //set the default group levels
  54. $sql = "select * from v_groups ";
  55. $sql .= "where group_level is null; ";
  56. $database = new database;
  57. $result = $database->select($sql, null, 'all');
  58. if (is_array($result) && count($result) > 0) {
  59. $x = 0;
  60. foreach($result as $row) {
  61. $array['groups'][$x]['group_uuid'] = $row['group_uuid'];
  62. switch ($row['group_name']) {
  63. case 'superadmin':
  64. $array['groups'][$x]['group_level'] = 80;
  65. break;
  66. case 'admin':
  67. $array['groups'][$x]['group_level'] = 50;
  68. break;
  69. case 'user':
  70. $array['groups'][$x]['group_level'] = 30;
  71. break;
  72. case 'agent':
  73. $array['groups'][$x]['group_level'] = 20;
  74. break;
  75. case 'public':
  76. $array['groups'][$x]['group_level'] = 10;
  77. break;
  78. default:
  79. $array['groups'][$x]['group_level'] = 10;
  80. }
  81. $x++;
  82. }
  83. $database = new database;
  84. $database->app_name = 'groups';
  85. $database->app_uuid = '2caf27b0-540a-43d5-bb9b-c9871a1e4f84';
  86. $database->save($array);
  87. unset($array);
  88. }
  89. //drop the view_groups
  90. $database = new database;
  91. $database->execute("DROP VIEW view_groups;", null);
  92. //add or update the view
  93. $sql = "CREATE VIEW view_groups AS (";
  94. $sql .= " select domain_uuid, group_uuid, group_name, ";
  95. $sql .= " (select count(*) from v_group_permissions where group_uuid = g.group_uuid) as group_permissions, ";
  96. $sql .= " (select count(*) from v_user_groups where group_uuid = g.group_uuid) as group_members, ";
  97. $sql .= " group_level, group_protected, group_description ";
  98. $sql .= " from v_groups as g ";
  99. $sql .= ");";
  100. $database = new database;
  101. $database->execute($sql, null);
  102. unset($sql);
  103. }
  104. ?>