groups.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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) 2016-2019
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. /**
  22. * groups class provides methods for add, delete groups, and add default groups
  23. *
  24. * @method string add
  25. * @method boolean delete
  26. * @method boolean defaults
  27. */
  28. if (!class_exists('groups')) {
  29. class groups {
  30. public $db;
  31. /**
  32. * Called when the object is created
  33. */
  34. public function __construct() {
  35. //connect to the database if not connected
  36. if (!$this->db) {
  37. require_once "resources/classes/database.php";
  38. $database = new database;
  39. $database->connect();
  40. $this->db = $database->db;
  41. }
  42. }
  43. /**
  44. * Called when there are no references to a particular object
  45. * unset the variables used in the class
  46. */
  47. public function __destruct() {
  48. foreach ($this as $key => $value) {
  49. unset($this->$key);
  50. }
  51. }
  52. /**
  53. * add a group
  54. */
  55. public function add() {
  56. $id = uuid();
  57. //return $id;
  58. return false;
  59. }
  60. /**
  61. * delete a group
  62. */
  63. public function delete($id) {
  64. return false;
  65. }
  66. /**
  67. * add defaults groups
  68. */
  69. public function defaults() {
  70. //if the are no groups add the default groups
  71. $sql = "select * from v_groups ";
  72. $sql .= "where domain_uuid is null ";
  73. $database = new database;
  74. $result = $database->select($sql, null, 'all');
  75. if (count($result) == 0) {
  76. $x = 0;
  77. $array['groups'][$x]['group_uuid'] = uuid();
  78. $array['groups'][$x]['domain_uuid'] = null;
  79. $array['groups'][$x]['group_name'] = 'superadmin';
  80. $array['groups'][$x]['group_level'] = '80';
  81. $array['groups'][$x]['group_description'] = 'Super Administrator Group';
  82. $array['groups'][$x]['group_protected'] = 'false';
  83. $x++;
  84. $array['groups'][$x]['group_uuid'] = uuid();
  85. $array['groups'][$x]['domain_uuid'] = null;
  86. $array['groups'][$x]['group_name'] = 'admin';
  87. $array['groups'][$x]['group_level'] = '50';
  88. $array['groups'][$x]['group_description'] = 'Administrator Group';
  89. $array['groups'][$x]['group_protected'] = 'false';
  90. $x++;
  91. $array['groups'][$x]['group_uuid'] = uuid();
  92. $array['groups'][$x]['domain_uuid'] = null;
  93. $array['groups'][$x]['group_name'] = 'user';
  94. $array['groups'][$x]['group_level'] = '30';
  95. $array['groups'][$x]['group_description'] = 'User Group';
  96. $array['groups'][$x]['group_protected'] = 'false';
  97. $x++;
  98. $array['groups'][$x]['group_uuid'] = uuid();
  99. $array['groups'][$x]['domain_uuid'] = null;
  100. $array['groups'][$x]['group_name'] = 'agent';
  101. $array['groups'][$x]['group_level'] = '20';
  102. $array['groups'][$x]['group_description'] = 'Call Center Agent Group';
  103. $array['groups'][$x]['group_protected'] = 'false';
  104. $x++;
  105. $array['groups'][$x]['group_uuid'] = uuid();
  106. $array['groups'][$x]['domain_uuid'] = null;
  107. $array['groups'][$x]['group_name'] = 'public';
  108. $array['groups'][$x]['group_level'] = '10';
  109. $array['groups'][$x]['group_description'] = 'Public Group';
  110. $array['groups'][$x]['group_protected'] = 'false';
  111. //add the temporary permissions
  112. $p = new permissions;
  113. $p->add("group_add", "temp");
  114. $p->add("group_edit", "temp");
  115. //save the data to the database
  116. $database = new database;
  117. $database->app_name = 'groups';
  118. $database->app_uuid = '2caf27b0-540a-43d5-bb9b-c9871a1e4f84';
  119. $database->save($array);
  120. unset($array);
  121. //remove the temporary permission
  122. $p->delete("group_add", "temp");
  123. $p->delete("group_edit", "temp");
  124. }
  125. unset($result);
  126. //if there are no permissions listed in v_group_permissions then set the default permissions
  127. $sql = "select count(*) from v_group_permissions ";
  128. $sql .= "where domain_uuid is null ";
  129. $database = new database;
  130. $num_rows = $database->select($sql, null, 'column');
  131. if ($num_rows == 0) {
  132. //build the apps array
  133. $config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
  134. $x = 0;
  135. foreach ($config_list as &$config_path) {
  136. include($config_path);
  137. $x++;
  138. }
  139. //no permissions found add the defaults
  140. foreach($apps as $app) {
  141. if (is_array($app['permissions'])) foreach ($app['permissions'] as $row) {
  142. if (is_array($row['groups'])) foreach ($row['groups'] as $group) {
  143. $x++;
  144. $array['group_permissions'][$x]['group_permission_uuid'] = uuid();
  145. $array['group_permissions'][$x]['domain_uuid'] = null;
  146. $array['group_permissions'][$x]['permission_name'] = $row['name'];
  147. $array['group_permissions'][$x]['group_name'] = $group;
  148. }
  149. }
  150. }
  151. //add the temporary permissions
  152. $p = new permissions;
  153. $p->add("group_permission_add", "temp");
  154. $p->add("group_permission_edit", "temp");
  155. //save the data to the database
  156. $database = new database;
  157. $database->app_name = 'groups';
  158. $database->app_uuid = '2caf27b0-540a-43d5-bb9b-c9871a1e4f84';
  159. $database->save($array);
  160. unset($array);
  161. //remove the temporary permission
  162. $p->delete("group_permission_add", "temp");
  163. $p->delete("group_permission_edit", "temp");
  164. }
  165. }
  166. } //end scripts class
  167. }
  168. /*
  169. //example use
  170. $group = new groups;
  171. $group->defaults();
  172. */
  173. ?>