人人商城

cover.ctrl.php 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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('reply');
  8. load()->model('module');
  9. $dos = array('module', 'post');
  10. $do = in_array($do, $dos) ? $do : 'module';
  11. $system_modules = module_system();
  12. if (!in_array($_GPC['m'], $system_modules) && $do == 'post') {
  13. permission_check_account_user('', true, 'cover');
  14. }
  15. define('IN_MODULE', true);
  16. if ($do == 'module') {
  17. $modulename = $_GPC['m'];
  18. $entry_id = intval($_GPC['eid']);
  19. $cover_keywords = array();
  20. if (empty($modulename)) {
  21. $entry = module_entry($entry_id);
  22. $modulename = $entry['module'];
  23. }
  24. $module = $_W['current_module'] = module_fetch($modulename);
  25. if (empty($module)) {
  26. itoast('模块不存在或是未安装', '', 'error');
  27. }
  28. if (!empty($module['isrulefields'])) {
  29. $url = url('platform/reply', array('m' => $module['name'], 'eid' => $entry_id));
  30. }
  31. if (empty($url)) {
  32. $url = url('platform/cover', array('m' => $module['name'], 'eid' => $entry_id));
  33. }
  34. define('ACTIVE_FRAME_URL', $url);
  35. $entries = module_entries($modulename);
  36. $sql = "SELECT b.`do`, a.`type`, a.`content` FROM ".tablename('rule_keyword')." as a LEFT JOIN ".tablename('cover_reply')." as b ON a.rid = b.rid WHERE b.uniacid = :uniacid AND b.module = :module";
  37. $params = array(':uniacid' => $_W['uniacid'], ':module' => $module['name']);
  38. $replies = pdo_fetchall($sql, $params);
  39. foreach ($replies as $replay){
  40. $cover_keywords[$replay['do']][] = $replay;
  41. }
  42. $module_permission = permission_account_user_menu($_W['uid'], $_W['uniacid'], $modulename);
  43. foreach ($entries['cover'] as $key => &$cover){
  44. $permission_name = $modulename . '_cover_' . trim($cover['do']);
  45. if ($module_permission[0] != 'all' && !in_array($permission_name, $module_permission)) {
  46. unset($entries['cover'][$key]);
  47. }
  48. if (!empty($cover_keywords[$cover['do']])){
  49. $cover['cover']['rule']['keywords'] = $cover_keywords[$cover['do']];
  50. }
  51. }
  52. unset($cover);
  53. } elseif ($do == 'post') {
  54. $entry_id = intval($_GPC['eid']);
  55. if(empty($entry_id)) {
  56. itoast('访问错误', '', '');
  57. }
  58. $entry = module_entry($entry_id);
  59. if (is_error($entry)) {
  60. itoast('模块菜单不存在或是模块已经被删除', '', '');
  61. }
  62. $module = $_W['current_module'] = module_fetch($entry['module']);
  63. $reply = pdo_get('cover_reply', array('module' => $entry['module'], 'do' => $entry['do'], 'uniacid' => $_W['uniacid']));
  64. if (checksubmit('submit')) {
  65. $keywords = @json_decode(htmlspecialchars_decode($_GPC['keywords']), true);
  66. $rule = array(
  67. 'uniacid' => $_W['uniacid'],
  68. 'name' => $entry['title'],
  69. 'module' => 'cover',
  70. 'containtype' => '',
  71. 'status' => $_GPC['status'] == 'true' ? 1 : 0,
  72. 'displayorder' => intval($_GPC['displayorder_rule']),
  73. );
  74. if ($_GPC['istop'] == 1) {
  75. $rule['displayorder'] = 255;
  76. } else {
  77. $rule['displayorder'] = range_limit($rule['displayorder'], 0, 254);
  78. }
  79. if (!empty($reply)) {
  80. $rid = $reply['rid'];
  81. $result = pdo_update('rule', $rule, array('id' => $rid));
  82. } else {
  83. $result = pdo_insert('rule', $rule);
  84. $rid = pdo_insertid();
  85. }
  86. if (!empty($rid)) {
  87. pdo_delete('rule_keyword', array('rid' => $rid, 'uniacid' => $_W['uniacid']));
  88. if (!empty($keywords)) {
  89. $keyword_row = array(
  90. 'rid' => $rid,
  91. 'uniacid' => $_W['uniacid'],
  92. 'module' => 'cover',
  93. 'status' => $rule['status'],
  94. 'displayorder' => $rule['displayorder'],
  95. );
  96. foreach ($keywords as $keyword) {
  97. $keyword_insert = $keyword_row;
  98. $keyword_insert['type'] = range_limit($keyword['type'], 1, 4);
  99. $keyword_insert['content'] = $keyword['content'];
  100. pdo_insert('rule_keyword', $keyword_insert);
  101. }
  102. }
  103. $entry = array(
  104. 'uniacid' => $_W['uniacid'],
  105. 'multiid' => 0,
  106. 'rid' => $rid,
  107. 'title' => $_GPC['rulename'],
  108. 'description' => $_GPC['description'],
  109. 'thumb' => $_GPC['thumb'],
  110. 'url' => $entry['url'],
  111. 'do' => $entry['do'],
  112. 'module' => $entry['module'],
  113. );
  114. if (empty($reply['id'])) {
  115. pdo_insert('cover_reply', $entry);
  116. } else {
  117. pdo_update('cover_reply', $entry, array('id' => $reply['id']));
  118. }
  119. itoast('封面保存成功!', url('platform/cover', array('m' => $entry['module'])), 'success');
  120. } else {
  121. itoast('封面保存失败, 请联系网站管理员!', '', 'error');
  122. }
  123. }
  124. if (!empty($module['isrulefields'])) {
  125. $url = url('platform/reply', array('m' => $module['name']));
  126. }
  127. if (empty($url)) {
  128. $url = url('platform/cover', array('m' => $module['name']));
  129. }
  130. define('ACTIVE_FRAME_URL', $url);
  131. if (!empty($reply)) {
  132. if (!empty($reply['thumb'])) {
  133. $reply['src'] = tomedia($reply['thumb']);
  134. }
  135. $reply['rule'] = reply_single($reply['rid']);
  136. $reply['url_show'] = $entry['url_show'];
  137. } else {
  138. $reply = array(
  139. 'title' => $entry['title'],
  140. 'url_show' => $entry['url_show'],
  141. 'rule' => array(
  142. 'displayorder' => '0',
  143. 'status' => '1'
  144. )
  145. );
  146. }
  147. }
  148. template('platform/cover');