menu.ctrl.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. load()->model('system');
  8. $dos = array('display', 'post', 'display_status', 'delete', 'change_displayorder');
  9. $do = in_array($do, $dos) ? $do : 'display';
  10. $system_top_menu = array_keys(system_menu());
  11. $system_menu = system_menu_permission_list();
  12. $account_all_type = uni_account_type();
  13. $account_all_type_sign = array_keys(uni_account_type_sign());
  14. $system_menu_permission = array();
  15. if (!empty($system_menu)) {
  16. foreach ($system_menu as $menu_name => $menu) {
  17. if (in_array($menu_name, $system_top_menu)) {
  18. $system_menu_permission[] = $menu_name;
  19. }
  20. if (!empty($menu['section'])) {
  21. foreach ($menu['section'] as $section_name => $section) {
  22. if (!empty($section['menu'])) {
  23. foreach ($section['menu'] as $permission_name => $sub_menu) {
  24. if ($sub_menu['is_system']) {
  25. $system_menu_permission[] = $sub_menu['permission_name'];
  26. }
  27. }
  28. }
  29. }
  30. }
  31. if (in_array($menu_name, $account_all_type_sign)) {
  32. $system_menu['platform']['section'][$menu_name] = $menu;
  33. unset($system_menu[$menu_name]);
  34. }
  35. }
  36. }
  37. if ($do == 'display') {
  38. template('system/menu');
  39. } elseif ($do == 'post') {
  40. $id = intval($_GPC['id']);
  41. if ($_GPC['group'] == 'platform_module') {
  42. iajax(-1, '应用模块下不可添加下级分类!', referer());
  43. }
  44. $menu = array(
  45. 'title' => $_GPC['title'],
  46. 'url' => $_GPC['url'],
  47. 'permission_name' => $_GPC['permissionName'],
  48. 'is_system' => $_GPC['isSystem'],
  49. 'displayorder' => $_GPC['displayorder'],
  50. 'type' => 'url',
  51. 'icon' => $_GPC['icon'],
  52. );
  53. if (empty($menu['title']) || empty($menu['url']) || empty($menu['permission_name'])) {
  54. iajax(-1, '请完善菜单信息', referer());
  55. }
  56. if (!preg_match('/^[a-zA-Z0-9_]+$/', $menu['permission_name'], $match)) {
  57. iajax(-1, '菜单标识只能是数字、字母、下划线', referer());
  58. }
  59. if (in_array($menu['permission_name'], $system_menu_permission)) {
  60. $menu['is_system'] = 1;
  61. unset($menu['url']);
  62. } else {
  63. $menu['group_name'] = $_GPC['group'];
  64. $menu['is_system'] = 0;
  65. $menu_db = pdo_get('core_menu', array('permission_name' => $menu['permission_name']));
  66. if (!empty($menu_db) && $menu_db['id'] != $id) {
  67. iajax(-1, '菜单标识不得重复请更换', referer());
  68. }
  69. }
  70. $permission_name = $menu['permission_name'];
  71. $menu_db = pdo_get('core_menu', array('permission_name' => $permission_name));
  72. if (!empty($menu_db)) {
  73. unset($menu['permission_name']);
  74. $menu['group_name'] = $menu_db['group_name'];
  75. pdo_update('core_menu', $menu, array('permission_name' => $permission_name));
  76. } else {
  77. $menu['is_display'] = 1;
  78. pdo_insert('core_menu', $menu);
  79. }
  80. cache_clean(cache_system_key('system_frame'));
  81. iajax(0, '更新成功', referer());
  82. } elseif ($do == 'display_status') {
  83. $permission_name = $_GPC['permission_name'];
  84. $status = intval($_GPC['status']);
  85. $menu_db = pdo_get('core_menu', array('permission_name' => $permission_name));
  86. if (!empty($menu_db)) {
  87. pdo_update('core_menu', array('is_display' => $status), array('permission_name' => $permission_name));
  88. } else {
  89. $menu_data = array('is_display' => $status, 'permission_name' => $permission_name);
  90. if (in_array($permission_name, $system_top_menu)) {
  91. $menu_data['is_system'] = 1;
  92. $menu_data['group_name'] = 'frame';
  93. }
  94. pdo_insert('core_menu', $menu_data);
  95. }
  96. cache_clean(cache_system_key('system_frame'));
  97. iajax(0, '更新成功', referer());
  98. } elseif ($do == 'delete') {
  99. $permission_name = $_GPC['permission_name'];
  100. $menu_db = pdo_get('core_menu', array('permission_name' => $permission_name));
  101. if (!empty($menu_db['is_system'])) {
  102. iajax(-1, '系统菜单不能删除', referer());
  103. }
  104. if (!empty($menu_db)) {
  105. pdo_delete('core_menu', array('id' => $menu_db['id']));
  106. cache_clean(cache_system_key('system_frame'));
  107. }
  108. iajax(0, '更新成功', referer());
  109. } elseif ($do == 'change_displayorder') {
  110. $menu_db = pdo_get('core_menu', array('permission_name' => $_GPC['permission'], 'group_name' => 'frame'));
  111. if (empty($menu_db)) {
  112. $menu = array(
  113. 'group_name' => 'frame',
  114. 'displayorder' => intval($_GPC['displayorder']),
  115. 'permission_name' => $_GPC['permission'],
  116. 'is_display' => 1,
  117. );
  118. if (in_array($_GPC['permission'], $system_top_menu)) {
  119. $menu['is_system'] = 1;
  120. }
  121. pdo_insert('core_menu', $menu);
  122. } else {
  123. pdo_update('core_menu', array('displayorder' => intval($_GPC['displayorder'])), array('id' => $menu_db['id']));
  124. }
  125. cache_clean(cache_system_key('system_frame'));
  126. iajax(0, '更新成功', referer());
  127. }