menu_edit.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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-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('menu_add') || permission_exists('menu_edit')) {
  26. //access granted
  27. }
  28. else {
  29. echo "access denied";
  30. exit;
  31. }
  32. //add multi-lingual support
  33. $language = new text;
  34. $text = $language->get();
  35. //action add or update
  36. if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
  37. $action = "update";
  38. $menu_uuid = $_REQUEST["id"];
  39. }
  40. else {
  41. $action = "add";
  42. }
  43. //get http post variables and set them to php variables
  44. if (!empty($_POST) && count($_POST) > 0) {
  45. $menu_uuid = $_POST["menu_uuid"] ?? null;
  46. $menu_name = $_POST["menu_name"];
  47. $menu_language = $_POST["menu_language"];
  48. $menu_description = $_POST["menu_description"];
  49. }
  50. //process the http post
  51. if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
  52. //validate the token
  53. $token = new token;
  54. if (!$token->validate($_SERVER['PHP_SELF'])) {
  55. message::add($text['message-invalid_token'],'negative');
  56. header('Location: menu.php');
  57. exit;
  58. }
  59. //check for all required data
  60. $msg = '';
  61. if (empty($menu_name)) { $msg .= $text['message-required'].$text['label-name']."<br>\n"; }
  62. if (empty($menu_language)) { $msg .= $text['message-required'].$text['label-language']."<br>\n"; }
  63. //if (empty($menu_description)) { $msg .= $text['message-required'].$text['label-description']."<br>\n"; }
  64. if (!empty($msg) && empty($_POST["persistformvar"])) {
  65. require_once "resources/header.php";
  66. require_once "resources/persist_form_var.php";
  67. echo "<div align='center'>\n";
  68. echo "<table><tr><td>\n";
  69. echo $msg."<br />";
  70. echo "</td></tr></table>\n";
  71. persistformvar($_POST);
  72. echo "</div>\n";
  73. require_once "resources/footer.php";
  74. return;
  75. }
  76. //add or update the database
  77. if (empty($_POST["persistformvar"])) {
  78. if ($action == "add") {
  79. //create a new unique id
  80. $menu_uuid = uuid();
  81. //start a new menu
  82. $array['menus'][0]['menu_uuid'] = $menu_uuid;
  83. $array['menus'][0]['menu_name'] = $menu_name;
  84. $array['menus'][0]['menu_language'] = $menu_language;
  85. $array['menus'][0]['menu_description'] = $menu_description;
  86. $database = new database;
  87. $database->app_name = 'menu';
  88. $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
  89. $database->save($array);
  90. unset($array);
  91. //redirect the user back to the main menu
  92. message::add($text['message-add']);
  93. header("Location: menu.php");
  94. return;
  95. } //if ($action == "add")
  96. if ($action == "update") {
  97. //update the menu
  98. $array['menus'][0]['menu_uuid'] = $menu_uuid;
  99. $array['menus'][0]['menu_name'] = $menu_name;
  100. $array['menus'][0]['menu_language'] = $menu_language;
  101. $array['menus'][0]['menu_description'] = $menu_description;
  102. $database = new database;
  103. $database->app_name = 'menu';
  104. $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
  105. $database->save($array);
  106. unset($array);
  107. //redirect the user back to the main menu
  108. message::add($text['message-update']);
  109. header("Location: menu.php");
  110. return;
  111. }
  112. }
  113. }
  114. //pre-populate the form
  115. if (count($_GET) > 0 && is_uuid($_GET["id"]) && empty($_POST["persistformvar"])) {
  116. $menu_uuid = $_GET["id"];
  117. $sql = "select * from v_menus ";
  118. $sql .= "where menu_uuid = :menu_uuid ";
  119. $parameters['menu_uuid'] = $menu_uuid;
  120. $database = new database;
  121. $row = $database->select($sql, $parameters, 'row');
  122. if (!empty($row)) {
  123. $menu_uuid = $row["menu_uuid"];
  124. $menu_name = $row["menu_name"];
  125. $menu_language = $row["menu_language"];
  126. $menu_description = $row["menu_description"];
  127. }
  128. unset($sql, $parameters, $row);
  129. }
  130. //create token
  131. $object = new token;
  132. $token = $object->create($_SERVER['PHP_SELF']);
  133. //show the header
  134. $document['title'] = $text['title-menu'];
  135. require_once "resources/header.php";
  136. //show the content
  137. echo "<form method='post' name='frm' id='frm'>\n";
  138. echo "<div class='action_bar' id='action_bar'>\n";
  139. echo " <div class='heading'><b>".$text['header-menu']."</b></div>\n";
  140. echo " <div class='actions'>\n";
  141. echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','collapse'=>'hide-xs','link'=>'menu.php']);
  142. echo button::create(['type'=>'button','label'=>$text['button-reload'],'icon'=>$_SESSION['theme']['button_icon_reload'],'collapse'=>'hide-xs','style'=>'margin-left: 15px;','link'=>'menu_reload.php?menu_uuid='.urlencode($menu_uuid ?? '').'&menu_language='.urlencode($menu_language ?? '')]);
  143. if (permission_exists('menu_restore') && $action == "update") {
  144. echo button::create(['type'=>'button','label'=>$text['button-restore_default'],'icon'=>'undo-alt','collapse'=>'hide-xs','onclick'=>"modal_open('modal-restore','btn_restore');"]);
  145. }
  146. echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','collapse'=>'hide-xs']);
  147. echo " </div>\n";
  148. echo " <div style='clear: both;'></div>\n";
  149. echo "</div>\n";
  150. if (permission_exists('menu_restore') && $action == "update") {
  151. echo modal::create(['id'=>'modal-restore','type'=>'confirmation','message'=>$text['confirm-restore'],'actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_restore','style'=>'float: right; margin-left: 15px;','collapse'=>'never','link'=>'menu_restore_default.php?menu_uuid='.urlencode($menu_uuid).'&menu_language='.urlencode($menu_language),'onclick'=>'modal_close();'])]);
  152. }
  153. echo $text['description-menu']."\n";
  154. echo "<br /><br />\n";
  155. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  156. echo "<tr>\n";
  157. echo "<td width='30%' class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  158. echo " ".$text['label-name']."\n";
  159. echo "</td>\n";
  160. echo "<td width='70%' class='vtable' align='left'>\n";
  161. echo " <input class='formfld' type='text' name='menu_name' maxlength='255' value=\"".escape($menu_name ?? '')."\">\n";
  162. echo "<br />\n";
  163. echo "\n";
  164. echo $text['description-name']."</td>\n";
  165. echo "</tr>\n";
  166. echo "<tr>\n";
  167. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  168. echo " ".$text['label-language']."\n";
  169. echo "</td>\n";
  170. echo "<td class='vtable' align='left'>\n";
  171. echo " <input class='formfld' type='text' name='menu_language' maxlength='255' value=\"".escape($menu_language ?? '')."\">\n";
  172. echo "<br />\n";
  173. echo $text['description-language']."\n";
  174. echo "</td>\n";
  175. echo "</tr>\n";
  176. echo "<tr>\n";
  177. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  178. echo " ".$text['label-description']."\n";
  179. echo "</td>\n";
  180. echo "<td class='vtable' align='left'>\n";
  181. echo " <input class='formfld' type='text' name='menu_description' maxlength='255' value=\"".escape($menu_description ?? '')."\">\n";
  182. echo "<br />\n";
  183. echo $text['description-description']."\n";
  184. echo "</td>\n";
  185. echo "</tr>\n";
  186. echo "</table>";
  187. echo "<br><br>";
  188. if ($action == "update") {
  189. echo "<input type='hidden' name='menu_uuid' value='".escape($menu_uuid)."'>\n";
  190. }
  191. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  192. echo "</form>";
  193. //show the menu items
  194. if ($action == "update") {
  195. require_once "core/menu/menu_item_list.php";
  196. }
  197. //include the footer
  198. require_once "resources/footer.php";
  199. ?>