人人商城

menu.ctrl.php 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. $dos = array('display', 'post', 'display_status', 'delete', 'change_displayorder');
  8. $do = in_array($do, $dos) ? $do : 'display';
  9. $_W['page']['title'] = '系统管理 - 菜单设置';
  10. $system_top_menu = array('account', 'wxapp', 'module', 'help', 'advertisement', 'site', 'system', 'webapp', 'appmarket', 'custom_help', 'phoneapp', 'platform', 'xzapp');
  11. array_push($system_top_menu, 'store');
  12. $system_menu = cache_load(cache_system_key('system_frame', array('uniacid' => $_W['uniacid'])));
  13. if(empty($system_menu)) {
  14. cache_build_frame_menu();
  15. $system_menu = cache_load(cache_system_key('system_frame', array('uniacid' => $_W['uniacid'])));
  16. }
  17. $system_menu_permission = array();
  18. if (!empty($system_menu)) {
  19. foreach ($system_menu as $menu_name => $menu) {
  20. if (in_array($menu_name, $system_top_menu)) {
  21. $system_menu_permission[] = $menu_name;
  22. }
  23. if (!empty($menu['section'])) {
  24. foreach ($menu['section'] as $section_name => $section) {
  25. if (!empty($section['menu'])) {
  26. foreach ($section['menu'] as $permission_name => $sub_menu) {
  27. if ($sub_menu['is_system']) {
  28. $system_menu_permission[] = $sub_menu['permission_name'];
  29. }
  30. }
  31. }
  32. }
  33. }
  34. if (in_array($menu_name, array('account', 'wxapp', 'xzapp', 'phoneapp', 'webapp', 'aliapp'))) {
  35. $system_menu['platform']['section'][$menu_name] = $menu;
  36. unset($system_menu[$menu_name]);
  37. }
  38. }
  39. }
  40. if ($do == 'display') {
  41. $add_top_nav = pdo_getall('core_menu', array('group_name' => 'frame', 'is_system <>' => 1), array('title', 'url', 'permission_name', 'displayorder', 'is_display'));
  42. if (!empty($add_top_nav)) {
  43. foreach ($add_top_nav as $menu) {
  44. $system_menu[$menu['permission_name']] = array(
  45. 'title' => $menu['title'],
  46. 'is_system' => 0,
  47. 'displayorder' => $menu['displayorder'],
  48. 'permission_name' => $menu['permission_name'],
  49. 'url' => $menu['url'],
  50. 'is_display' => $menu['is_display']
  51. );
  52. }
  53. }
  54. template('system/menu');
  55. } elseif ($do == 'post') {
  56. $id = intval($_GPC['id']);
  57. if ($_GPC['group'] == 'platform_module') {
  58. iajax(-1, '应用模块下不可添加下级分类!', referer());
  59. }
  60. $menu = array(
  61. 'title' => $_GPC['title'],
  62. 'url' => $_GPC['url'],
  63. 'permission_name' => $_GPC['permissionName'],
  64. 'is_system' => $_GPC['isSystem'],
  65. 'displayorder' => $_GPC['displayorder'],
  66. 'type' => 'url',
  67. 'icon' => $_GPC['icon'],
  68. );
  69. if (empty($menu['title']) || empty($menu['url']) || empty($menu['permission_name'])) {
  70. iajax(-1, '请完善菜单信息', referer());
  71. }
  72. if (!preg_match('/^[a-zA-Z0-9_]+$/', $menu['permission_name'], $match)) {
  73. iajax(-1, '菜单标识只能是数字、字母、下划线', referer());
  74. }
  75. if (in_array($menu['permission_name'], $system_menu_permission)) {
  76. $menu['is_system'] = 1;
  77. unset($menu['url']);
  78. } else {
  79. $menu['group_name'] = $_GPC['group'];
  80. $menu['is_system'] = 0;
  81. $menu_db = pdo_get('core_menu', array('permission_name' => $menu['permission_name']));
  82. if (!empty($menu_db) && $menu_db['id'] != $id) {
  83. iajax(-1, '菜单标识不得重复请更换', referer());
  84. }
  85. }
  86. $permission_name = $menu['permission_name'];
  87. $menu_db = pdo_get('core_menu', array('permission_name' => $permission_name));
  88. if (!empty($menu_db)) {
  89. unset($menu['permission_name']);
  90. $menu['group_name'] = $menu_db['group_name'];
  91. pdo_update('core_menu', $menu, array('permission_name' => $permission_name));
  92. } else {
  93. $menu['is_display'] = 1;
  94. pdo_insert('core_menu', $menu);
  95. }
  96. cache_build_frame_menu();
  97. iajax(0, '更新成功', referer());
  98. } elseif ($do == 'display_status') {
  99. $permission_name = $_GPC['permission_name'];
  100. $status = intval($_GPC['status']);
  101. $menu_db = pdo_get('core_menu', array('permission_name' => $permission_name));
  102. if (!empty($menu_db)) {
  103. pdo_update('core_menu', array('is_display' => $status), array('permission_name' => $permission_name));
  104. } else {
  105. $menu_data = array('is_display' => $status, 'permission_name' => $permission_name);
  106. if (in_array($permission_name, $system_top_menu)) {
  107. $menu_data['is_system'] = 1;
  108. $menu_data['group_name'] = 'frame';
  109. }
  110. pdo_insert('core_menu', $menu_data);
  111. }
  112. cache_build_frame_menu();
  113. iajax(0, '更新成功', referer());
  114. } elseif ($do == 'delete') {
  115. $permission_name = $_GPC['permission_name'];
  116. $menu_db = pdo_get('core_menu', array('permission_name' => $permission_name));
  117. if (!empty($menu_db['is_system'])) {
  118. iajax(-1, '系统菜单不能删除', referer());
  119. }
  120. if (!empty($menu_db)) {
  121. pdo_delete('core_menu', array('id' => $menu_db['id']));
  122. cache_build_frame_menu();
  123. }
  124. iajax(0, '更新成功', referer());
  125. } elseif ($do == 'change_displayorder') {
  126. $menu_db = pdo_get('core_menu', array('permission_name' => $_GPC['permission'], 'group_name' => 'frame'));
  127. if (empty($menu_db)) {
  128. $menu = array(
  129. 'group_name' => 'frame',
  130. 'displayorder' => intval($_GPC['displayorder']),
  131. 'permission_name' => $_GPC['permission'],
  132. 'is_display' => 1,
  133. );
  134. if (in_array($_GPC['permission'], $system_top_menu)) {
  135. $menu['is_system'] = 1;
  136. }
  137. pdo_insert('core_menu', $menu);
  138. } else {
  139. pdo_update('core_menu', array('displayorder' => intval($_GPC['displayorder'])), array('id' => $menu_db['id']));
  140. }
  141. cache_build_frame_menu();
  142. iajax(0, '更新成功', referer());
  143. }