menu_item_move_down.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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-2012
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. include "root.php";
  22. require_once "includes/require.php";
  23. require_once "includes/checkauth.php";
  24. if (permission_exists('menu_edit')) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. return;
  30. }
  31. //move down more than one level at a time
  32. //update v_menu_items set menu_item_order = (menu_item_order+1) where menu_item_order > 2 or menu_item_order = 2
  33. if (count($_GET)>0) {
  34. $menu_item_id = check_str($_GET["menu_item_id"]);
  35. $menu_item_order = check_str($_GET["menu_item_order"]);
  36. $menu_parent_guid = check_str($_GET["menu_parent_guid"]);
  37. $sql = "SELECT menu_item_order FROM v_menu_items ";
  38. $sql .= "where domain_uuid = '".$domain_uuid."' ";
  39. $sql .= "order by menu_item_order desc ";
  40. $sql .= "limit 1 ";
  41. $prep_statement = $db->prepare(check_sql($sql));
  42. $prep_statement->execute();
  43. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  44. foreach ($result as &$row) {
  45. $highestmenu_item_order = $row[menu_item_order];
  46. }
  47. unset($prep_statement);
  48. if ($menu_item_order != $highestmenu_item_order) {
  49. //clear the menu session so it will rebuild with the update
  50. $_SESSION["menu"] = "";
  51. //move the current item's order number up
  52. $sql = "update v_menu_items set ";
  53. $sql .= "menu_item_order = (menu_item_order-1) "; //move down
  54. $sql .= "where domain_uuid = '".$domain_uuid."' ";
  55. $sql .= "and menu_item_order = ".($menu_item_order+1)." ";
  56. $db->exec(check_sql($sql));
  57. unset($sql);
  58. //move the selected item's order number down
  59. $sql = "update v_menu_items set ";
  60. $sql .= "menu_item_order = (menu_item_order+1) "; //move up
  61. $sql .= "where domain_uuid = '".$domain_uuid."' ";
  62. $sql .= "and menu_item_id = '$menu_item_id' ";
  63. $db->exec(check_sql($sql));
  64. unset($sql);
  65. }
  66. //redirect the user
  67. require_once "includes/header.php";
  68. echo "<meta http-equiv=\"refresh\" content=\"1;url=menu_list.php?menu_item_id=$menu_item_id\">\n";
  69. echo "<div align='center'>";
  70. echo "Item Moved Down";
  71. echo "</div>";
  72. require_once "includes/footer.php";
  73. return;
  74. }
  75. ?>