member_group.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * 管理员后台会员组操作类
  4. */
  5. defined('IN_PHPCMS') or exit('No permission resources.');
  6. pc_base::load_app_class('admin', 'admin', 0);
  7. class member_group extends admin {
  8. private $db;
  9. function __construct() {
  10. parent::__construct();
  11. $this->db = pc_base::load_model('member_group_model');
  12. }
  13. /**
  14. * 会员组首页
  15. */
  16. function init() {
  17. include $this->admin_tpl('member_init');
  18. }
  19. /**
  20. * 会员组列表
  21. */
  22. function manage() {
  23. $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
  24. $member_group_list = $this->db->listinfo('', 'sort ASC', $page, 15);
  25. $this->member_db = pc_base::load_model('member_model');
  26. //TODO 此处循环中执行sql,会严重影响效率,稍后考虑在memebr_group表中加入会员数字段和统计会员总数功能解决。
  27. foreach ($member_group_list as $k=>$v) {
  28. $membernum = $this->member_db->count(array('groupid'=>$v['groupid']));
  29. $member_group_list[$k]['membernum'] = $membernum;
  30. }
  31. $pages = $this->db->pages;
  32. $big_menu = array('javascript:window.top.art.dialog({id:\'add\',iframe:\'?m=member&c=member_group&a=add\', title:\''.L('member_group_add').'\', width:\'700\', height:\'500\', lock:true}, function(){var d = window.top.art.dialog({id:\'add\'}).data.iframe;var form = d.document.getElementById(\'dosubmit\');form.click();return false;}, function(){window.top.art.dialog({id:\'add\'}).close()});void(0);', L('member_group_add'));
  33. include $this->admin_tpl('member_group_list');
  34. }
  35. /**
  36. * 添加会员组
  37. */
  38. function add() {
  39. if(isset($_POST['dosubmit'])) {
  40. $info = array();
  41. if(!$this->_checkname($_POST['info']['name'])){
  42. showmessage('会员组名称已经存在');
  43. }
  44. $info = $_POST['info'];
  45. $info['allowpost'] = $info['allowpost'] ? 1 : 0;
  46. $info['allowupgrade'] = $info['allowupgrade'] ? 1 : 0;
  47. $info['allowpostverify'] = $info['allowpostverify'] ? 1 : 0;
  48. $info['allowsendmessage'] = $info['allowsendmessage'] ? 1 : 0;
  49. $info['allowattachment'] = $info['allowattachment'] ? 1 : 0;
  50. $info['allowsearch'] = $info['allowsearch'] ? 1 : 0;
  51. $info['allowvisit'] = $info['allowvisit'] ? 1 : 0;
  52. $this->db->insert($info);
  53. if($this->db->insert_id()){
  54. $this->_updatecache();
  55. showmessage(L('operation_success'),'?m=member&c=member_group&a=manage', '', 'add');
  56. }
  57. } else {
  58. $show_header = $show_scroll = true;
  59. include $this->admin_tpl('member_group_add');
  60. }
  61. }
  62. /**
  63. * 修改会员组
  64. */
  65. function edit() {
  66. if(isset($_POST['dosubmit'])) {
  67. $info = array();
  68. $info = $_POST['info'];
  69. $info['allowpost'] = isset($info['allowpost']) ? 1 : 0;
  70. $info['allowupgrade'] = isset($info['allowupgrade']) ? 1 : 0;
  71. $info['allowpostverify'] = isset($info['allowpostverify']) ? 1 : 0;
  72. $info['allowsendmessage'] = isset($info['allowsendmessage']) ? 1 : 0;
  73. $info['allowattachment'] = isset($info['allowattachment']) ? 1 : 0;
  74. $info['allowsearch'] = isset($info['allowsearch']) ? 1 : 0;
  75. $info['allowvisit'] = isset($info['allowvisit']) ? 1 : 0;
  76. $this->db->update($info, array('groupid'=>$info['groupid']));
  77. $this->_updatecache();
  78. showmessage(L('operation_success'), '?m=member&c=member_group&a=manage', '', 'edit');
  79. } else {
  80. $show_header = $show_scroll = true;
  81. $groupid = isset($_GET['groupid']) ? $_GET['groupid'] : showmessage(L('illegal_parameters'), HTTP_REFERER);
  82. $groupinfo = $this->db->get_one(array('groupid'=>$groupid));
  83. include $this->admin_tpl('member_group_edit');
  84. }
  85. }
  86. /**
  87. * 排序会员组
  88. */
  89. function sort() {
  90. if(isset($_POST['sort'])) {
  91. foreach($_POST['sort'] as $k=>$v) {
  92. $this->db->update(array('sort'=>$v), array('groupid'=>$k));
  93. }
  94. $this->_updatecache();
  95. showmessage(L('operation_success'), HTTP_REFERER);
  96. } else {
  97. showmessage(L('operation_failure'), HTTP_REFERER);
  98. }
  99. }
  100. /**
  101. * 删除会员组
  102. */
  103. function delete() {
  104. $groupidarr = isset($_POST['groupid']) ? $_POST['groupid'] : showmessage(L('illegal_parameters'), HTTP_REFERER);
  105. $where = to_sqls($groupidarr, '', 'groupid');
  106. if ($this->db->delete($where)) {
  107. $this->_updatecache();
  108. showmessage(L('operation_success'), HTTP_REFERER);
  109. } else {
  110. showmessage(L('operation_failure'), HTTP_REFERER);
  111. }
  112. }
  113. /**
  114. * 检查用户名是否合法
  115. * @param string $name
  116. */
  117. private function _checkname($name = NULL) {
  118. if(empty($name)) return false;
  119. if ($this->db->get_one(array('name'=>$name),'groupid')){
  120. return false;
  121. }
  122. return true;
  123. }
  124. /**
  125. * 更新会员组列表缓存
  126. */
  127. private function _updatecache() {
  128. $grouplist = $this->db->listinfo('', '', 1, 1000, 'groupid');
  129. setcache('grouplist', $grouplist);
  130. }
  131. public function public_checkname_ajax() {
  132. $name = isset($_GET['name']) && trim($_GET['name']) ? trim($_GET['name']) : exit(0);
  133. $name = iconv('utf-8', CHARSET, $name);
  134. if ($this->db->get_one(array('name'=>$name),'groupid')){
  135. exit('0');
  136. } else {
  137. exit('1');
  138. }
  139. }
  140. }
  141. ?>