menu_edit.php 7.4 KB

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