category.ctrl.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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('article');
  8. $do = !empty($do) ? $do : 'display';
  9. $do = in_array($do, array('display', 'post', 'delete', 'change_status')) ? $do : 'display';
  10. permission_check_account_user('platform_site');
  11. if ($do == 'display') {
  12. $children = array();
  13. $category = pdo_fetchall("SELECT * FROM ".tablename('site_category')." WHERE uniacid = '{$_W['uniacid']}' ORDER BY parentid, displayorder DESC, id");
  14. foreach ($category as $index => $row) {
  15. if (!empty($row['parentid'])){
  16. $children[$row['parentid']][] = $row;
  17. unset($category[$index]);
  18. }
  19. }
  20. template('site/category-display');
  21. } elseif ($do == 'post') {
  22. $parentid = intval($_GPC['parentid']);
  23. $id = intval($_GPC['id']);
  24. $setting = uni_setting($_W['uniacid'], array('default_site'));
  25. $site_styleid = pdo_fetchcolumn('SELECT styleid FROM ' . tablename('site_multi') . ' WHERE id = :id', array(':id' => $setting['default_site']));
  26. if ($site_styleid) {
  27. $site_template = pdo_fetch("SELECT a.*,b.name,b.sections FROM ".tablename('site_styles').' AS a LEFT JOIN ' . tablename('site_templates') . ' AS b ON a.templateid = b.id WHERE a.uniacid = :uniacid AND a.id = :id', array(':uniacid' => $_W['uniacid'], ':id' => $site_styleid));
  28. }
  29. $styles = pdo_fetchall("SELECT a.*, b.name AS tname, b.title FROM ".tablename('site_styles').' AS a LEFT JOIN ' . tablename('site_templates') . ' AS b ON a.templateid = b.id WHERE a.uniacid = :uniacid', array(':uniacid' => $_W['uniacid']), 'id');
  30. if (!empty($id)) {
  31. $category = pdo_fetch("SELECT * FROM ".tablename('site_category')." WHERE id = '$id' AND uniacid = {$_W['uniacid']}");
  32. if (empty($category)) {
  33. itoast('分类不存在或已删除', '', 'error');
  34. }
  35. if (!empty($category['css'])) {
  36. $category['css'] = iunserializer($category['css']);
  37. } else {
  38. $category['css'] = array();
  39. }
  40. } else {
  41. $category = array(
  42. 'displayorder' => 0,
  43. 'css' => array(),
  44. );
  45. }
  46. if (!empty($parentid)) {
  47. $parent = pdo_fetch("SELECT id, name FROM ".tablename('site_category')." WHERE id = '$parentid'");
  48. if (empty($parent)) {
  49. itoast('抱歉,上级分类不存在或是已经被删除!', url('site/category/display'), 'error');
  50. }
  51. }
  52. $category['style'] = $styles[$category['styleid']];
  53. $category['style']['tname'] = empty($category['style']['tname'])? 'default' : $category['style']['tname'];
  54. if (!empty($category['nid'])) {
  55. $category['nav'] = pdo_get('site_nav', array('id' => $category['nid']));
  56. } else {
  57. $category['nav'] = array();
  58. }
  59. $multis = pdo_getall('site_multi', array('uniacid' => $_W['uniacid']), array(), 'id');
  60. if (checksubmit('submit')) {
  61. if (empty($_GPC['cname'])) {
  62. itoast('抱歉,请输入分类名称!', '', '');
  63. }
  64. $data = array(
  65. 'uniacid' => $_W['uniacid'],
  66. 'name' => $_GPC['cname'],
  67. 'displayorder' => intval($_GPC['displayorder']),
  68. 'parentid' => intval($parentid),
  69. 'description' => $_GPC['description'],
  70. 'styleid' => intval($_GPC['styleid']),
  71. 'linkurl' => $_GPC['linkurl'],
  72. 'ishomepage' => intval($_GPC['ishomepage']),
  73. 'enabled' => intval($_GPC['enabled']),
  74. 'icontype' => intval($_GPC['icontype']),
  75. 'multiid' => intval($_GPC['multiid'])
  76. );
  77. if ($data['icontype'] == 1) {
  78. $data['icon'] = '';
  79. $data['css'] = serialize(array(
  80. 'icon' => array(
  81. 'font-size' => $_GPC['icon']['size'],
  82. 'color' => $_GPC['icon']['color'],
  83. 'width' => $_GPC['icon']['size'],
  84. 'icon' => empty($_GPC['icon']['icon']) ? 'fa fa-external-link' : $_GPC['icon']['icon'],
  85. ),
  86. ));
  87. } else {
  88. $data['css'] = '';
  89. $data['icon'] = $_GPC['iconfile'];
  90. }
  91. $isnav = intval($_GPC['isnav']);
  92. if ($isnav) {
  93. $nav = array(
  94. 'uniacid' => $_W['uniacid'],
  95. 'categoryid' => $id,
  96. 'displayorder' => $_GPC['displayorder'],
  97. 'name' => $_GPC['cname'],
  98. 'description' => $_GPC['description'],
  99. 'url' => "./index.php?c=site&a=site&cid={$category['id']}&i={$_W['uniacid']}",
  100. 'status' => 1,
  101. 'position' => 1,
  102. 'multiid' => intval($_GPC['multiid']),
  103. );
  104. if ($data['icontype'] == 1) {
  105. $nav['icon'] = '';
  106. $nav['css'] = serialize(array(
  107. 'icon' => array(
  108. 'font-size' => $_GPC['icon']['size'],
  109. 'color' => $_GPC['icon']['color'],
  110. 'width' => $_GPC['icon']['size'],
  111. 'icon' => empty($_GPC['icon']['icon']) ? 'fa fa-external-link' : $_GPC['icon']['icon'],
  112. ),
  113. 'name' => array(
  114. 'color' => $_GPC['icon']['color'],
  115. ),
  116. ));
  117. } else {
  118. $nav['css'] = '';
  119. $nav['icon'] = $_GPC['iconfile'];
  120. }
  121. if ($category['nid']) {
  122. $nav_exist = pdo_fetch('SELECT id FROM ' . tablename('site_nav') . ' WHERE id = :id AND uniacid = :uniacid', array(':id' => $category['nid'], ':uniacid' => $_W['uniacid']));
  123. } else {
  124. $nav_exist = '';
  125. }
  126. if (!empty($nav_exist)) {
  127. pdo_update('site_nav', $nav, array('id' => $category['nid'], 'uniacid' => $_W['uniacid']));
  128. } else {
  129. pdo_insert('site_nav', $nav);
  130. $nid = pdo_insertid();
  131. $data['nid'] = $nid;
  132. }
  133. } else {
  134. if ($category['nid']) {
  135. $data['nid'] = 0;
  136. pdo_delete('site_nav', array('id' => $category['nid'], 'uniacid' => $_W['uniacid']));
  137. }
  138. }
  139. if (!empty($id)) {
  140. unset($data['parentid']);
  141. pdo_update('site_category', $data, array('id' => $id, 'uniacid' => $_W['uniacid']));
  142. } else {
  143. pdo_insert('site_category', $data);
  144. $id = pdo_insertid();
  145. $nav_url['url'] = "./index.php?c=site&a=site&cid={$id}&i={$_W['uniacid']}";
  146. pdo_update('site_nav', $nav_url, array('id' => $data['nid'], 'uniacid' => $_W['uniacid']));
  147. }
  148. itoast('更新分类成功!', url('site/category'), 'success');
  149. }
  150. template('site/category-post');
  151. } elseif ($do == 'delete') {
  152. $owner_info = account_owner($_W['uniacid']);
  153. if (checksubmit('submit')) {
  154. if (user_is_founder($_W['uid']) || $_W['uid'] == $owner_info['uid']) {
  155. foreach ($_GPC['rid'] as $key => $id) {
  156. $category_delete = article_category_delete($id);
  157. if (empty($category_delete)) {
  158. itoast('抱歉,分类不存在或是已经被删除!', referer(), 'error');
  159. }
  160. }
  161. itoast('分类批量删除成功!', referer(), 'success');
  162. } else {
  163. itoast('操作失败!', referer(), 'error');
  164. }
  165. } else {
  166. $id = intval($_GPC['id']);
  167. if (user_is_founder($_W['uid']) || $_W['uid'] == $owner_info['uid']) {
  168. $category_delete = article_category_delete($id);
  169. if (empty($category_delete)) {
  170. itoast('抱歉,分类不存在或是已经被删除!', referer(), 'error');
  171. }
  172. itoast('分类删除成功!', referer(), 'success');
  173. } else {
  174. itoast('操作失败!', referer(), 'error');
  175. }
  176. }
  177. } else if ($do == 'change_status') {
  178. $id = intval($_GPC['id']);
  179. $category_exist = pdo_get('site_category', array('id' => $id, 'uniacid' => $_W['uniacid']));
  180. if (!empty($category_exist)) {
  181. $status = $category_exist['enabled'] == 1 ? 0 : 1;
  182. $result = pdo_update('site_category', array('enabled' => $status), array('id' => $id, 'uniacid' => $_W['uniacid']));
  183. if ($result) {
  184. iajax(0, '更改成功!', url('site/category'));
  185. } else {
  186. iajax(1, '更改失败!', '');
  187. }
  188. } else {
  189. iajax(-1, '分类不存在!', '');
  190. }
  191. }