人人商城

menu.ctrl.php 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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', 'del', 'ajax', 'module', 'view', 'switch', 'del_bind');
  8. $do = in_array($do, $dos) ? $do : 'display';
  9. load()->model('frame');
  10. if($do == 'display') {
  11. $menus = frame_lists();
  12. if(checksubmit('submit')) {
  13. foreach($_GPC['id'] as $k => $menuid) {
  14. $update = array();
  15. $menuid = intval($menuid);
  16. $title = trim($_GPC['title'][$k]);
  17. $is_system = intval($_GPC['is_system'][$k]);
  18. if($menuid && $title) {
  19. $update = array(
  20. 'title' => $title,
  21. 'displayorder' => intval($_GPC['displayorder'][$k]),
  22. );
  23. if(!$is_system) {
  24. $update['url'] = trim($_GPC['url'][$k]);
  25. $update['append_title'] = trim($_GPC['append_title'][$k]);
  26. $update['append_url'] = trim($_GPC['append_url'][$k]);
  27. }
  28. pdo_update('core_menu', $update, array('id' => $menuid));
  29. }
  30. }
  31. if(!empty($_GPC['add_parent_name'])) {
  32. $exist_names = array();
  33. foreach($_GPC['add_parent_name'] as $k1 => $v1) {
  34. $insert = array();
  35. $add_parent_title = trim($_GPC['add_parent_title'][$k1]);
  36. $add_parent_name = trim($_GPC['add_parent_name'][$k1]);
  37. $name_exist = pdo_get('core_menu', array('name' => $add_parent_name, 'pid' => 0));
  38. if (!empty($name_exist)) {
  39. $exist_names[] = $add_parent_name;
  40. continue;
  41. }
  42. if($add_parent_title && $add_parent_name) {
  43. $insert = array(
  44. 'pid' => 0,
  45. 'title' => $add_parent_title,
  46. 'name' => $add_parent_name,
  47. 'append_title' => trim($_GPC['add_parent_append_title'][$k1]),
  48. 'displayorder' => intval($_GPC['add_parent_displayorder'][$k1]),
  49. 'is_system' => 0
  50. );
  51. pdo_insert('core_menu', $insert);
  52. }
  53. }
  54. }
  55. if(!empty($_GPC['add_pid'])) {
  56. foreach($_GPC['add_pid'] as $k1 => $v1) {
  57. $insert = array();
  58. $v1 = intval($v1);
  59. $add_title = trim($_GPC['add_title'][$k1]);
  60. $add_name = trim($_GPC['add_name'][$k1]);
  61. if($v1 && $add_title && $add_name) {
  62. $insert = array(
  63. 'pid' => $v1,
  64. 'title' => $add_title,
  65. 'name' => $add_name,
  66. 'displayorder' => intval($_GPC['add_displayorder'][$k1]),
  67. 'is_system' => 0
  68. );
  69. pdo_insert('core_menu', $insert);
  70. }
  71. }
  72. }
  73. if(!empty($_GPC['add_child_pid'])) {
  74. foreach($_GPC['add_child_pid'] as $k2 => $v2) {
  75. $insert = array();
  76. $v2 = intval($v2);
  77. $add_child_title = trim($_GPC['add_child_title'][$k2]);
  78. $add_child_name = trim($_GPC['add_child_name'][$k2]);
  79. $add_child_url = trim($_GPC['add_child_url'][$k2]);
  80. if($v2 && $add_child_title && $add_child_name && $add_child_url) {
  81. $insert = array(
  82. 'pid' => $v2,
  83. 'title' => $add_child_title,
  84. 'name' => $add_child_name,
  85. 'url' => $add_child_url,
  86. 'type' => 'url',
  87. 'displayorder' => intval($_GPC['add_child_displayorder'][$k2]),
  88. 'is_system' => 0,
  89. 'permission_name' => trim($_GPC['add_child_permission'][$k2]),
  90. );
  91. $add_child_append_title = trim($_GPC['add_child_append_title'][$k2]);
  92. $add_child_append_url = trim($_GPC['add_child_append_url'][$k2]);
  93. if($add_child_append_title && $add_child_append_url) {
  94. $insert['append_title'] = $add_child_append_title;
  95. $insert['append_url'] = $add_child_append_url;
  96. }
  97. pdo_insert('core_menu', $insert);
  98. }
  99. }
  100. }
  101. if(!empty($_GPC['add_permission_pid'])) {
  102. foreach($_GPC['add_permission_pid'] as $k1 => $v1) {
  103. $insert = array();
  104. $v1 = intval($v1);
  105. $add_permission_title = trim($_GPC['add_permission_title'][$k1]);
  106. $add_permission_name = trim($_GPC['add_permission_name'][$k1]);
  107. $add_permission_flag = trim($_GPC['add_permission_flag'][$k1]);
  108. $isexist = pdo_fetchcolumn('SELECT id FROM ' . tablename('core_menu') . ' WHERE permission_name = :permission_name', array(':permission_name' => $add_permission_name));
  109. if(!empty($isexist)) {
  110. continue;
  111. }
  112. if($v1 && $add_permission_title && $add_permission_name && $add_permission_flag) {
  113. $insert = array(
  114. 'pid' => $v1,
  115. 'title' => $add_permission_title,
  116. 'name' => $add_permission_flag,
  117. 'permission_name' => $add_permission_name,
  118. 'type' => 'permission',
  119. 'displayorder' => intval($_GPC['add_permission_displayorder'][$k1]),
  120. 'is_system' => 0,
  121. 'is_display' => 0,
  122. );
  123. pdo_insert('core_menu', $insert);
  124. }
  125. }
  126. }
  127. cache_build_frame_menu();
  128. if (!empty($exist_names)) {
  129. $exist_names = implode(',', $exist_names);
  130. message($exist_names."标识已存在", referer(), 'info');
  131. }
  132. message('更新菜单成功', referer(), 'success');
  133. }
  134. template('extension/menu');
  135. }
  136. if($do == 'del') {
  137. $id = intval($_GPC['id']);
  138. $menu= pdo_fetch('SELECT * FROM ' . tablename('core_menu') . ' WHERE id = :id', array(':id' => $id));
  139. if($menu['is_system']) {
  140. message('系统分类不能删除', referer(), 'error');
  141. }
  142. $ids = pdo_fetchall('SELECT id FROM ' . tablename('core_menu') . ' WHERE pid = :id', array(':id' => $id), 'id');
  143. if(!empty($ids)) {
  144. $ids_str = implode(',', array_keys($ids));
  145. pdo_query('DELETE FROM ' . tablename('core_menu') . " WHERE pid IN ({$ids_str})");
  146. pdo_query('DELETE FROM ' . tablename('core_menu') . " WHERE id IN ({$ids_str})");
  147. }
  148. pdo_query('DELETE FROM ' . tablename('core_menu') . " WHERE id = {$id}");
  149. cache_build_frame_menu();
  150. message('删除分类成功', referer(), 'success');
  151. }
  152. if($do == 'ajax') {
  153. $id = intval($_GPC['id']);
  154. $value = intval($_GPC['value']) ? 0 : 1;
  155. pdo_update('core_menu', array('is_display' => $value), array('id' => $id));
  156. cache_build_frame_menu();
  157. exit();
  158. }
  159. if($do == 'module') {
  160. load()->model('module');
  161. if(checksubmit('submit')) {
  162. if(!empty($_GPC['eid'])) {
  163. foreach($_GPC['eid'] as $k => $v) {
  164. $update = array();
  165. $entry = trim($_GPC['entry'][$k]);
  166. if($entry == 'mine') {
  167. $update['url'] = trim($_GPC['url'][$k]);
  168. }
  169. $update['icon'] = empty($_GPC['icon'][$k]) ? 'fa fa-puzzle-piece' : $_GPC['icon'][$k];
  170. $update['displayorder'] = intval($_GPC['displayorder'][$k]);
  171. pdo_update('modules_bindings', $update, array('eid' => intval($v)));
  172. }
  173. }
  174. if(!empty($_GPC['add_title'])) {
  175. foreach($_GPC['add_title'] as $k => $v) {
  176. $title = trim($v);
  177. $url = trim($_GPC['add_url'][$k]);
  178. $m = trim($_GPC['add_module'][$k]);
  179. if(strexists($url, 'http://') || strexists($url, 'https://')) {
  180. if(strexists($url, $_W['siteroot'])) {
  181. $url = './index.php?' . str_replace($_W['siteroot'].'web/index.php?', '', $url);
  182. }
  183. }
  184. $icon = empty($_GPC['add_icon'][$k]) ? 'fa fa-puzzle-piece' : trim($_GPC['add_icon'][$k]);
  185. if($title && $url && $m) {
  186. $data = array();
  187. $data['do'] = '';
  188. $data['module'] = $m;
  189. $data['entry'] = 'mine';
  190. $data['title'] = $title;
  191. $data['url'] = $url;
  192. $data['icon'] = $icon;
  193. $data['displayorder'] = intval($_GPC['add_displayorder'][$k]);
  194. pdo_insert('modules_bindings', $data);
  195. } else {
  196. continue;
  197. }
  198. }
  199. }
  200. message('更新模块菜单成功', 'refresh', 'success');
  201. }
  202. $modules = pdo_fetchall('SELECT mid, name, title FROM ' . tablename('modules') . ' WHERE issystem = 0');
  203. foreach($modules as &$li) {
  204. $li['entry'] = module_entries($li['name'], array('mine', 'menu'));
  205. }
  206. template('extension/module-permission');
  207. }
  208. if($do == 'del_bind') {
  209. $eid = intval($_GPC['eid']);
  210. $permission = intval($_GPC['permission']);
  211. pdo_delete('modules_bindings', array('eid' => $eid, 'entry' => 'mine'));
  212. exit();
  213. }