group_edit.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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) 2018-2023
  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_add') || permission_exists('group_edit')) {
  26. //access granted
  27. }
  28. else {
  29. echo "access denied";
  30. exit;
  31. }
  32. //connect to database
  33. $database = database::new();
  34. //add multi-lingual support
  35. $language = new text;
  36. $text = $language->get();
  37. //action add or update
  38. if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
  39. $action = "update";
  40. $group_uuid = $_REQUEST["id"];
  41. }
  42. else {
  43. $action = "add";
  44. $group_uuid = '';
  45. }
  46. //set default values
  47. $group_name = '';
  48. $group_level = '10';
  49. $group_description = '';
  50. //get http post variables and set them to php variables
  51. if (!empty($_POST)) {
  52. $group_uuid = $_POST["group_uuid"] ?? '';
  53. $group_name = $_POST["group_name"] ?? '';
  54. $group_name_previous = $_POST["group_name_previous"];
  55. $domain_uuid = $_POST["domain_uuid"];
  56. $group_level = $_POST["group_level"] ?? '10';
  57. $group_protected = $_POST["group_protected"] ?? '';
  58. $group_description = $_POST["group_description"] ?? '';
  59. }
  60. //process the user data and save it to the database
  61. if (!empty($_POST) && empty($_POST["persistformvar"])) {
  62. //process the http post data by submitted action
  63. if (!empty($_POST['action']) && is_uuid($group_uuid)) {
  64. $array[0]['checked'] = 'true';
  65. $array[0]['uuid'] = $group_uuid;
  66. switch ($_POST['action']) {
  67. case 'copy':
  68. if (permission_exists('group_add')) {
  69. $obj = new groups;
  70. $obj->copy($array);
  71. }
  72. break;
  73. case 'delete':
  74. if (permission_exists('group_delete')) {
  75. $obj = new groups;
  76. $obj->delete($array);
  77. }
  78. break;
  79. }
  80. header('Location: groups.php');
  81. exit;
  82. }
  83. //validate the token
  84. $token = new token;
  85. if (!$token->validate($_SERVER['PHP_SELF'])) {
  86. message::add($text['message-invalid_token'],'negative');
  87. header('Location: groups.php');
  88. exit;
  89. }
  90. //check for all required data
  91. $msg = '';
  92. if (empty($group_name)) { $msg .= $text['message-required']." ".$text['label-group_name']."<br>\n"; }
  93. //if (empty($domain_uuid)) { $msg .= $text['message-required']." ".$text['label-domain_uuid']."<br>\n"; }
  94. if (empty($group_level)) { $msg .= $text['message-required']." ".$text['label-group_level']."<br>\n"; }
  95. //if (empty($group_protected)) { $msg .= $text['message-required']." ".$text['label-group_protected']."<br>\n"; }
  96. //if (empty($group_description)) { $msg .= $text['message-required']." ".$text['label-group_description']."<br>\n"; }
  97. if (!empty($msg) && empty($_POST["persistformvar"])) {
  98. require_once "resources/header.php";
  99. require_once "resources/persist_form_var.php";
  100. echo "<div align='center'>\n";
  101. echo "<table><tr><td>\n";
  102. echo $msg."<br />";
  103. echo "</td></tr></table>\n";
  104. persistformvar($_POST);
  105. echo "</div>\n";
  106. require_once "resources/footer.php";
  107. return;
  108. }
  109. //add the group_uuid
  110. if (empty($_POST["group_uuid"])) {
  111. $group_uuid = uuid();
  112. }
  113. //prepare the array
  114. $array['groups'][0]['group_uuid'] = $group_uuid;
  115. $array['groups'][0]['group_name'] = $group_name;
  116. $array['groups'][0]['domain_uuid'] = $domain_uuid;
  117. $array['groups'][0]['group_level'] = $group_level;
  118. $array['groups'][0]['group_protected'] = $group_protected;
  119. $array['groups'][0]['group_description'] = $group_description;
  120. //save the data
  121. $database->app_name = 'Group Manager';
  122. $database->app_uuid = '2caf27b0-540a-43d5-bb9b-c9871a1e4f84';
  123. $database->save($array);
  124. //update group name in group permissions if group name changed
  125. if ($group_name != $group_name_previous) {
  126. $sql = "update v_group_permissions ";
  127. $sql .= "set group_name = :group_name ";
  128. $sql .= "where group_name = :group_name_previous ";
  129. $sql .= "and group_uuid = :group_uuid ";
  130. $parameters['group_name'] = $group_name;
  131. $parameters['group_name_previous'] = $group_name_previous;
  132. $parameters['group_uuid'] = $group_uuid;
  133. $database->app_name = 'Group Manager';
  134. $database->app_uuid = '2caf27b0-540a-43d5-bb9b-c9871a1e4f84';
  135. $database->execute($sql, $parameters);
  136. unset($sql, $parameters);
  137. }
  138. //redirect the user
  139. if (isset($action)) {
  140. if ($action == "add") {
  141. $_SESSION["message"] = $text['message-add'];
  142. }
  143. if ($action == "update") {
  144. $_SESSION["message"] = $text['message-update'];
  145. }
  146. header('Location: group_edit.php?id='.urlencode($group_uuid));
  147. return;
  148. }
  149. }
  150. //pre-populate the form
  151. if (!empty($group_uuid) && empty($_POST["persistformvar"])) {
  152. $sql = "select * from v_groups ";
  153. $sql .= "where group_uuid = :group_uuid ";
  154. //$sql .= "and domain_uuid = :domain_uuid ";
  155. //$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  156. $parameters['group_uuid'] = $group_uuid;
  157. $row = $database->select($sql, $parameters, 'row');
  158. if (!empty($row)) {
  159. $group_name = $row["group_name"];
  160. $domain_uuid = $row["domain_uuid"];
  161. $group_permissions = $row["group_permissions"] ?? '';
  162. $group_members = $row["group_members"] ?? '';
  163. $group_level = $row["group_level"];
  164. $group_protected = $row["group_protected"];
  165. $group_description = $row["group_description"];
  166. }
  167. unset ($sql, $parameters, $row);
  168. }
  169. //create token
  170. $object = new token;
  171. $token = $object->create($_SERVER['PHP_SELF']);
  172. //show the header
  173. $document['title'] = $text['title-group'];
  174. require_once "resources/header.php";
  175. //show the content
  176. echo "<form name='frm' id='frm' method='post'>\n";
  177. echo "<div class='action_bar' id='action_bar'>\n";
  178. echo " <div class='heading'><b>".$text['title-group']."</b></div>\n";
  179. echo " <div class='actions'>\n";
  180. echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','link'=>'groups.php']);
  181. if ($action == 'update' && permission_exists('group_permission_view')) {
  182. $button_margin = 'margin-left: 15px;';
  183. echo button::create(['type'=>'button','label'=>$text['button-permissions'],'icon'=>'key','style'=>$button_margin,'link'=>'group_permissions.php?group_uuid='.urlencode($group_uuid)]);
  184. }
  185. if ($action == 'update' && permission_exists('group_member_view')) {
  186. $button_margin = 'margin-left: 0px;';
  187. echo button::create(['type'=>'button','label'=>$text['button-members'],'icon'=>'users','style'=>$button_margin,'link'=>'group_members.php?group_uuid='.urlencode($group_uuid)]);
  188. }
  189. if ($action == 'update' && permission_exists('group_add')) {
  190. $button_margin = 'margin-left: 15px;';
  191. echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'name'=>'btn_copy','style'=>$button_margin,'onclick'=>"modal_open('modal-copy','btn_copy');"]);
  192. }
  193. if ($action == 'update' && permission_exists('group_delete')) {
  194. $button_margin = 'margin-left: 0px;';
  195. echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','style'=>$button_margin,'onclick'=>"modal_open('modal-delete','btn_delete');"]);
  196. }
  197. echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','style'=>'margin-left: 15px;']);
  198. echo " </div>\n";
  199. echo " <div style='clear: both;'></div>\n";
  200. echo "</div>\n";
  201. if ($action == 'update' && permission_exists('group_add')) {
  202. echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'copy','onclick'=>"modal_close();"])]);
  203. }
  204. if ($action == 'update' && permission_exists('group_delete')) {
  205. echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'delete','onclick'=>"modal_close();"])]);
  206. }
  207. echo $text['description-groups']."\n";
  208. echo "<br /><br />\n";
  209. echo "<div class='card'>\n";
  210. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  211. echo "<tr>\n";
  212. echo "<td width='30%' class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  213. echo " ".$text['label-group_name']."\n";
  214. echo "</td>\n";
  215. echo "<td width='70%' class='vtable' style='position: relative;' align='left'>\n";
  216. echo " <input class='formfld' type='text' name='group_name' maxlength='255' value='".escape($group_name)."'>\n";
  217. echo " <input type='hidden' name='group_name_previous' value='".escape($group_name)."'>\n";
  218. echo "<br />\n";
  219. //echo $text['description-group_name']."\n";
  220. echo "</td>\n";
  221. echo "</tr>\n";
  222. echo "<tr>\n";
  223. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  224. echo " ".$text['label-domain_uuid']."\n";
  225. echo "</td>\n";
  226. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  227. echo " <select class='formfld' name='domain_uuid'>\n";
  228. if (empty($domain_uuid)) {
  229. echo " <option value='' selected='selected'>".$text['label-global']."</option>\n";
  230. }
  231. else {
  232. echo " <option value=''>".$text['label-global']."</option>\n";
  233. }
  234. foreach ($_SESSION['domains'] as $row) {
  235. if ($row['domain_uuid'] == $domain_uuid) {
  236. echo " <option value='".$row['domain_uuid']."' selected='selected'>".escape($row['domain_name'])."</option>\n";
  237. }
  238. else {
  239. echo " <option value='".$row['domain_uuid']."'>".$row['domain_name']."</option>\n";
  240. }
  241. }
  242. echo " </select>\n";
  243. echo "<br />\n";
  244. //echo $text['description-domain_uuid']."\n";
  245. echo "</td>\n";
  246. echo "</tr>\n";
  247. echo "<tr>\n";
  248. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  249. echo " ".$text['label-group_level']."\n";
  250. echo "</td>\n";
  251. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  252. echo " <select class='formfld' name='group_level'>\n";
  253. echo " <option value=''></option>\n";
  254. for ($l = 10; $l <=90; $l += 10) {
  255. $selected = $group_level == $l ? "selected='selected'" : null;
  256. echo " <option value='".$l."' ".$selected.">".$l."</option>\n";
  257. }
  258. echo " </select>\n";
  259. echo "<br />\n";
  260. //echo $text['description-group_level']."\n";
  261. echo "</td>\n";
  262. echo "</tr>\n";
  263. echo "<tr>\n";
  264. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  265. echo " ".$text['label-group_protected']."\n";
  266. echo "</td>\n";
  267. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  268. echo " <select class='formfld' name='group_protected'>\n";
  269. echo " <option value='false'>".$text['label-false']."</option>\n";
  270. echo " <option value='true' ".(!empty($group_protected) && $group_protected == "true" ? "selected='selected'" : null).">".$text['label-true']."</option>\n";
  271. echo " </select>\n";
  272. echo "<br />\n";
  273. //echo $text['description-group_protected']."\n";
  274. echo "</td>\n";
  275. echo "</tr>\n";
  276. echo "<tr>\n";
  277. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  278. echo " ".$text['label-group_description']."\n";
  279. echo "</td>\n";
  280. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  281. echo " <input class='formfld' type='text' name='group_description' maxlength='255' value='".escape($group_description)."'>\n";
  282. echo "<br />\n";
  283. //echo $text['description-group_description']."\n";
  284. echo "</td>\n";
  285. echo "</tr>\n";
  286. echo "</table>";
  287. echo "</div>";
  288. echo "<br /><br />";
  289. echo "<input type='hidden' name='group_uuid' value='".escape($group_uuid)."'>\n";
  290. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  291. echo "</form>";
  292. //include the footer
  293. require_once "resources/footer.php";
  294. ?>