人人商城

solution.ctrl.php 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. if ($_W['isfounder']) {
  8. $dos = array('operator', 'menu','management');
  9. } else {
  10. $dos = array('management');
  11. }
  12. $do = in_array($do, $dos) ? $do : 'management';
  13. if ($do == 'operator') {
  14. $pindex = max(1, intval($_GPC['page']));
  15. $psize = 20;
  16. $wechatmembers = pdo_fetchall('SELECT memberid FROM '.tablename('uni_account_users')." WHERE weid=:weid", array(':weid'=>$_W['weid']), 'memberid');
  17. if (empty($wechatmembers)) {
  18. message('抱歉,请您先选择能操作此功能的用户!');
  19. }
  20. $where = ' WHERE uid in ('.implode(',', array_keys($wechatmembers)).')';
  21. if (!empty($_GPC['username'])) {
  22. $where .= " AND `username` LIKE '%{$_GPC['username']}%'";
  23. }
  24. $sql = 'SELECT * FROM '.tablename('members').$where." LIMIT ".($pindex - 1) * $psize .','.$psize;
  25. $members = pdo_fetchall($sql);
  26. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM '.tablename('members').$where);
  27. $pager = pagination($total, $pindex, $psize);
  28. }
  29. if($do == 'menu') {
  30. $modulename = $_GPC['module'];
  31. if(empty($_W['modules'][$modulename])){
  32. message('抱歉,该模块已经被删除或是您没有权限使用!');
  33. }
  34. $uid = intval($_GPC['memberid']);
  35. if(!empty($uid)){
  36. $haspermission = pdo_fetch("SELECT id FROM ".tablename('uni_account_users')." WHERE memberid = :memberid", array(':memberid' => $uid));
  37. }
  38. if(empty($haspermission)){
  39. message('抱歉,该用户没有权限操作该功能或是用户已经被删除!');
  40. }
  41. if (checksubmit('submit')) {
  42. if (empty($_GPC['check'])) {
  43. message('抱歉,请您选择要赋予操作人员的菜单权限。');
  44. }
  45. pdo_delete('modules_solution_bindings', array('acid'=>$_W['weid'], 'memberid' => $uid, 'module' => $modulename));
  46. foreach ($_GPC['check'] as $i => $check) {
  47. $eid = $_GPC['eid'][$i];
  48. $state = $_GPC['state'][$i];
  49. $do = $_GPC['doname'][$i];
  50. $title = $_GPC['title'][$i];
  51. if (empty($eid) && empty($state)) {
  52. continue;
  53. }
  54. $data = array(
  55. 'acid' => $_W['weid'],
  56. 'memberid' => $uid,
  57. 'module' => $modulename,
  58. 'do' => $do,
  59. 'title' => $title,
  60. 'enable' => 1,
  61. );
  62. if (empty($check) || $check != 'true') {
  63. $data['enable'] = 0;
  64. }
  65. if (!empty($eid)) {
  66. $data['eid'] = $eid;
  67. } else {
  68. $data['state'] = $state;
  69. }
  70. pdo_insert('modules_solution_bindings', $data);
  71. }
  72. message('编辑成功.',url('site/solution/menu', array('module' => $modulename, 'memberid' => $uid)));
  73. }
  74. $sql = "SELECT id, enable, eid, state FROM ".tablename('modules_solution_bindings')." WHERE memberid = :memberid AND acid = :acid AND module=:module";
  75. $mymenus = pdo_fetchall($sql, array(':memberid' => $uid, ':acid' => $_W['weid'], ':module' => $modulename));
  76. $menus = array();
  77. foreach ($mymenus as $menu) {
  78. if (!empty($menu['eid'])) {
  79. $menus[$menu['eid']] = $menu;
  80. } else {
  81. $menus[$menu['state']] = $menu;
  82. }
  83. }
  84. $allmenus = array();
  85. $bindings = pdo_fetchall('SELECT * FROM '.tablename('modules_bindings')." WHERE module = :module AND entry IN ('menu', 'cover') ORDER BY entry ASC", array(':module' => $modulename));
  86. foreach ($bindings as $binding) {
  87. if(empty($binding['call'])){
  88. $allmenus[] = array(
  89. 'eid' => $binding['eid'],
  90. 'do' => $binding['do'],
  91. 'state' => $binding['state'],
  92. 'title' => $binding['title'],
  93. 'url' => $binding['entry'] == 'cover' ? url('rule/cover', array('eid' => $binding['eid'])) : url('site/module/'.$binding['do'], array('name'=>$binding['module'],'weid'=>$_W['weid']))
  94. );
  95. } else {
  96. $call = $binding['call'];
  97. $site = WeUtility::createModuleSite($modulename);
  98. if (method_exists($site, $call)) {
  99. $callmenus = $site->$call();
  100. if (empty($callmenus) && !is_array($callmenus)) {
  101. continue;
  102. }
  103. foreach ($callmenus as $callmenu) {
  104. if(empty($callmenu['url']) || empty($callmenu['title'])){
  105. continue;
  106. }
  107. $url_result = parse_url($callmenu['url']);
  108. if (empty($url_result) || empty($url_result['query'])) {
  109. continue;
  110. }
  111. $query = $url_result['query'];
  112. parse_str($query, $queryarr);
  113. ksort($queryarr);
  114. $menu = array();
  115. $menu['do'] = $queryarr['do'];
  116. $menu['state'] = http_build_query($queryarr);
  117. $menu['module'] = $queryarr['name'];
  118. $menu['memberid'] = $uid;
  119. $menu['acid'] = $_W['weid'];
  120. $menu['title'] = $callmenu['title'];
  121. $menu['url'] = url('site', $queryarr);
  122. $allmenus[] = $menu;
  123. }
  124. }
  125. }
  126. }
  127. }
  128. if ($do == 'management') {
  129. $eid = intval($_GPC['eid']);
  130. $eid = json_decode(base64_decode($_GPC['eid']), true);
  131. $modulename = $eid['module'];
  132. $_W['weid'] = $eid['weid'];
  133. $mod = module_fetch($modulename);
  134. if (empty($mod)) {
  135. message('抱歉,该功能未被启用或是您没有使用该功能的权限!');
  136. }
  137. load()->model('extension');
  138. if (ext_module_checkupdate($modulename)) {
  139. message('系统检测到该模块有更新,请点击“<a href="'.url('extension/module/upgrade', array('id' => $modulename)).'">更新模块</a>”后继续使用!', '', 'error');
  140. }
  141. if (!empty($_W['isfounder'])) {
  142. $menus = array();
  143. $bindings = pdo_fetchall('SELECT * FROM ' . tablename('modules_bindings')." WHERE module = :module ORDER BY eid ASC", array(':module' => $modulename));
  144. if(!empty($bindings) && is_array($bindings)) {
  145. foreach($bindings as $opt) {
  146. if(!empty($opt['call'])) {
  147. $site = WeUtility::createModuleSite($modulename);
  148. if(method_exists($site, $opt['call'])) {
  149. $ret = $site->$opt['call']();
  150. if(is_array($ret)) {
  151. foreach($ret as $et) {
  152. $menus[] = array($et['title'], $et['url']);
  153. }
  154. }
  155. }
  156. } else {
  157. $menus[] = array(
  158. $opt['title'],
  159. url("site/entry", array('eid' => $opt['eid']))
  160. );
  161. }
  162. }
  163. }
  164. } else {
  165. $sql = "SELECT * FROM ".tablename('modules_solution_bindings')." WHERE memberid = :memberid AND acid = :acid AND module=:module AND enable = 1";
  166. $mymenus = pdo_fetchall($sql, array(':memberid' => $_W['uid'], ':acid' => $_W['weid'], ':module' => $modulename));
  167. foreach ($mymenus as $menu) {
  168. if (!empty($menu['eid'])) {
  169. $eids[] = $menu['eid'];
  170. } else {
  171. $menus[] = array(
  172. $menu['title'],
  173. 'site.php?' . $menu['state']
  174. );
  175. }
  176. }
  177. if (!empty($eids)) {
  178. $bindings = pdo_fetchall('SELECT * FROM ' . tablename('modules_bindings')." WHERE eid IN (".implode(',', $eids).") ORDER BY eid ASC");
  179. if(!empty($bindings) && is_array($bindings)) {
  180. foreach($bindings as $opt) {
  181. $menus[] = array(
  182. $opt['title'],
  183. url("site/entry", array('eid' => $opt['eid']))
  184. );
  185. }
  186. }
  187. }
  188. }
  189. if (empty($menus)) {
  190. message('抱歉,您没有任何操作权限,请联系管理员!');
  191. }
  192. }
  193. template('site/solution');