group_edit.php 10 KB

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