menu_edit.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. //connect to the database
  33. $database = new database;
  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. $menu_uuid = $_REQUEST["id"];
  41. }
  42. else {
  43. $action = "add";
  44. }
  45. //get http post variables and set them to php variables
  46. if (!empty($_POST) && count($_POST) > 0) {
  47. $menu_uuid = $_POST["menu_uuid"] ?? null;
  48. $menu_name = $_POST["menu_name"];
  49. $menu_language = $_POST["menu_language"];
  50. $menu_description = $_POST["menu_description"];
  51. }
  52. //process the http post
  53. if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
  54. //validate the token
  55. $token = new token;
  56. if (!$token->validate($_SERVER['PHP_SELF'])) {
  57. message::add($text['message-invalid_token'],'negative');
  58. header('Location: menu.php');
  59. exit;
  60. }
  61. //check for all required data
  62. $msg = '';
  63. if (empty($menu_name)) { $msg .= $text['message-required'].$text['label-name']."<br>\n"; }
  64. if (empty($menu_language)) { $msg .= $text['message-required'].$text['label-language']."<br>\n"; }
  65. //if (empty($menu_description)) { $msg .= $text['message-required'].$text['label-description']."<br>\n"; }
  66. if (!empty($msg) && empty($_POST["persistformvar"])) {
  67. require_once "resources/header.php";
  68. require_once "resources/persist_form_var.php";
  69. echo "<div align='center'>\n";
  70. echo "<table><tr><td>\n";
  71. echo $msg."<br />";
  72. echo "</td></tr></table>\n";
  73. persistformvar($_POST);
  74. echo "</div>\n";
  75. require_once "resources/footer.php";
  76. return;
  77. }
  78. //add or update the database
  79. if (empty($_POST["persistformvar"])) {
  80. if ($action == "add") {
  81. //create a new unique id
  82. $menu_uuid = uuid();
  83. //start a new menu
  84. $array['menus'][0]['menu_uuid'] = $menu_uuid;
  85. $array['menus'][0]['menu_name'] = $menu_name;
  86. $array['menus'][0]['menu_language'] = $menu_language;
  87. $array['menus'][0]['menu_description'] = $menu_description;
  88. $database->app_name = 'menu';
  89. $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
  90. $database->save($array);
  91. unset($array);
  92. //redirect the user back to the main menu
  93. message::add($text['message-add']);
  94. header("Location: menu.php");
  95. return;
  96. } //if ($action == "add")
  97. if ($action == "update") {
  98. //update the menu
  99. $array['menus'][0]['menu_uuid'] = $menu_uuid;
  100. $array['menus'][0]['menu_name'] = $menu_name;
  101. $array['menus'][0]['menu_language'] = $menu_language;
  102. $array['menus'][0]['menu_description'] = $menu_description;
  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. $row = $database->select($sql, $parameters, 'row');
  121. if (!empty($row)) {
  122. $menu_uuid = $row["menu_uuid"];
  123. $menu_name = $row["menu_name"];
  124. $menu_language = $row["menu_language"];
  125. $menu_description = $row["menu_description"];
  126. }
  127. unset($sql, $parameters, $row);
  128. }
  129. //create token
  130. $object = new token;
  131. $token = $object->create($_SERVER['PHP_SELF']);
  132. //show the header
  133. $document['title'] = $text['title-menu'];
  134. require_once "resources/header.php";
  135. //show the content
  136. echo "<form method='post' name='frm' id='frm'>\n";
  137. echo "<div class='action_bar' id='action_bar'>\n";
  138. echo " <div class='heading'><b>".$text['header-menu']."</b></div>\n";
  139. echo " <div class='actions'>\n";
  140. echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','collapse'=>'hide-xs','link'=>'menu.php']);
  141. 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 ?? '')]);
  142. if (permission_exists('menu_restore') && $action == "update") {
  143. echo button::create(['type'=>'button','label'=>$text['button-restore_default'],'icon'=>'undo-alt','collapse'=>'hide-xs','onclick'=>"modal_open('modal-restore','btn_restore');"]);
  144. }
  145. echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','collapse'=>'hide-xs']);
  146. echo " </div>\n";
  147. echo " <div style='clear: both;'></div>\n";
  148. echo "</div>\n";
  149. if (permission_exists('menu_restore') && $action == "update") {
  150. 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();'])]);
  151. }
  152. echo $text['description-menu']."\n";
  153. echo "<br /><br />\n";
  154. echo "<div class='card'>\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 "</div>";
  188. echo "<br>";
  189. if ($action == "update") {
  190. echo "<input type='hidden' name='menu_uuid' value='".escape($menu_uuid)."'>\n";
  191. }
  192. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  193. echo "</form>";
  194. //show the menu items
  195. if ($action == "update") {
  196. require_once "core/menu/menu_item_list.php";
  197. }
  198. //include the footer
  199. require_once "resources/footer.php";
  200. ?>