PageRenderTime 176ms CodeModel.GetById 44ms RepoModel.GetById 2ms app.codeStats 0ms

/upload/apps/groups/action/m_groups.php

https://github.com/bluelovers/phpwind
PHP | 402 lines | 307 code | 45 blank | 50 comment | 84 complexity | 33b491089c74927032e40ca51d45e934 MD5 | raw file
  1. <?php
  2. !defined('A_P') && exit('Forbidden');
  3. !$winduid && Showmsg('not_login');
  4. !$db_groups_open && Showmsg('groups_close');
  5. $isGM = S::inArray($windid,$manager);
  6. !$isGM && $groupid==3 && $isGM=1;
  7. S::gp(array('a', 'uid', 'ajax', 'page'));
  8. if ($ajax == 1) define('AJAX', '1');
  9. require_once(R_P . 'u/lib/space.class.php');
  10. $newSpace = new PwSpace($uid ? $uid : $winduid);
  11. if (!$space =& $newSpace->getInfo()) {
  12. Showmsg('您访问的空间不存在!');
  13. }
  14. if ($uid) {
  15. $isSpace = true;
  16. $USCR = 'space_groups';
  17. require_once S::escapePath($appEntryBasePath . 'action/view.php');
  18. }
  19. if ($db_question && $o_groups_qcheck) {
  20. $qkey = array_rand($db_question);
  21. }
  22. require_once(R_P.'require/showimg.php');
  23. $current_tab_id = empty($a) ? 'index' : ($a == 'create' ? 'index' : $a);
  24. $db_perpage = 18;
  25. if (empty($a)) {
  26. $colonyids = $group_own = $group_other = $apply = array();
  27. $counter = 0;
  28. $query = $db->query("SELECT cm.ifadmin,cm.addtime,c.id,c.cname,c.cnimg,c.admin,c.createtime,cm2.uid FROM pw_cmembers cm LEFT JOIN pw_colonys c ON cm.colonyid=c.id LEFT JOIN pw_members cm2 ON c.admin=cm2.username WHERE cm.uid=" . S::sqlEscape($winduid) . " ORDER BY cm.addtime DESC");
  29. while ($rt = $db->fetch_array($query)) {
  30. if ($rt['cnimg']) {
  31. list($rt['cnimg']) = geturl("cn_img/$rt[cnimg]",'lf');
  32. } else {
  33. $rt['cnimg'] = $GLOBALS['imgpath'] . '/g/groupnopic.gif';
  34. }
  35. empty($rt['addtime']) && $rt['addtime'] = $rt['createtime'];
  36. $rt['addtime'] = get_date($rt['addtime'], 'Y-m-d');
  37. if ($rt['ifadmin'] == '-1') {
  38. $apply[] = $rt;
  39. } elseif($rt['admin'] == $windid) {
  40. $counter++;
  41. $colonyids[] = $rt['id'];
  42. $group_own[] = $rt;
  43. } else {
  44. $counter++;
  45. $colonyids[] = $rt['id'];
  46. $group_other[] = $rt;
  47. }
  48. }
  49. $group_own = array_slice($group_own,0,3);
  50. $group_other = array_slice($group_other,0,3);
  51. $do = "conloy";
  52. if ($colonyids) {
  53. $perpage = 20;//$db_perpage;
  54. $weiboService = L::loadClass('weibo','sns');/* @var $weiboService PW_Weibo */
  55. $count = $weiboService->getConloysWeibosCount($colonyids);
  56. $pageCount = ceil($count / $perpage);
  57. $page = validatePage($page,$pageCount);
  58. $navPages = numofpage($count,$page,$pageCount,'apps.php?q=groups&');
  59. $weiboList = $weiboService->getConloysWeibos($colonyids,$page,$perpage);
  60. }
  61. list($isheader,$isfooter,$tplname,$isleft) = array(true,true,"m_groups",true);
  62. } elseif ($a == 'my') {
  63. S::gp(array('page'), '', 2);
  64. $page < 1 && $page = 1;
  65. $total = $db->get_one("SELECT COUNT(*) AS sum,SUM(cm.username=c.admin) AS creates FROM pw_cmembers cm LEFT JOIN pw_colonys c ON cm.colonyid=c.id WHERE cm.ifadmin<>'-1' AND cm.uid=" . S::sqlEscape($winduid));
  66. list($pages, $limit) = pwLimitPages($total['sum'], $page, "{$basename}a=my&");
  67. $group = array();
  68. $query = $db->query("SELECT c.id,c.cname,c.cnimg,c.admin,c.members FROM pw_cmembers cm LEFT JOIN pw_colonys c ON cm.colonyid=c.id WHERE cm.ifadmin<>'-1' AND cm.uid=" . S::sqlEscape($winduid) . ' ORDER BY (cm.username=c.admin) DESC ' . $limit);
  69. while ($rt = $db->fetch_array($query)) {
  70. if ($rt['cnimg']) {
  71. list($rt['cnimg']) = geturl("cn_img/$rt[cnimg]",'lf');
  72. } else {
  73. $rt['cnimg'] = $GLOBALS['imgpath'] . '/g/groupnopic.gif';
  74. }
  75. $group[$rt['id']] = $rt;
  76. }
  77. $total['adds'] = $total['sum'] - $total['creates'];
  78. list($isheader,$isfooter,$tplname,$isleft) = array(true,true,"m_groups",true);
  79. } elseif ($a == 'all') {
  80. S::gp(array('page', 'styleid', 'friends', 'members'), null, 2);
  81. S::gp(array('keyword'));
  82. require_once(R_P . 'apps/groups/lib/colony.class.php');
  83. $atc_name = getLangInfo('app','group');
  84. $cMembers = $group = array();
  85. $sqlsel = $sqltab = '';
  86. if ($styleid) {
  87. $tmpStyle = array();
  88. if ($o_styledb[$styleid]['upid'] == '0') {
  89. foreach ($o_styledb as $k => $v) {
  90. if ($v['upid'] == $styleid) {
  91. $tmpStyle[] = $k;
  92. }
  93. }
  94. }
  95. $sqlsel .= ' AND c.styleid' . ($tmpStyle ? ' IN(' . S::sqlImplode($tmpStyle) . ')' : '=' . S::sqlEscape($styleid));
  96. }
  97. if ($members) {
  98. $sqlsel .= ' AND c.members>=' . S::sqlEscape($members);
  99. }
  100. if ($keyword) {
  101. $sqlsel .= ' AND c.cname LIKE ' . S::sqlEscape("%" . $keyword . "%");
  102. }
  103. if ($friends) {
  104. $friends = getFriends($winduid);
  105. unset($friends[$winduid]);
  106. $uids = $friends ? array_keys($friends) : array(0);
  107. $sqltab .= ' LEFT JOIN pw_cmembers cm ON c.id=cm.colonyid';
  108. $sqlsel .= ' AND cm.uid IN(' . S::sqlImplode($uids) . ')';
  109. }
  110. $total = $db->get_value("SELECT COUNT(DISTINCT c.id) AS sum FROM pw_colonys c {$sqltab} WHERE 1 {$sqlsel}");
  111. if ($total) {
  112. require_once(R_P . 'require/bbscode.php');
  113. list($pages, $limit) = pwLimitPages($total, $page, "{$basename}a=all&keyword=".rawurlencode($keyword)."&".($styleid?("styleid=".$styleid):"")."&");
  114. $query = $db->query("SELECT DISTINCT c.* FROM pw_colonys c {$sqltab} WHERE 1 {$sqlsel} ORDER BY c.id DESC $limit");
  115. while ($rt = $db->fetch_array($query)) {
  116. if ($rt['cnimg']) {
  117. list($rt['cnimg']) = geturl("cn_img/$rt[cnimg]", 'lf');
  118. } else {
  119. $rt['cnimg'] = $GLOBALS['imgpath'] . '/g/groupnopic.gif';
  120. }
  121. $rt['descrip'] = stripWindCode($rt['descrip']);
  122. $rt['colonyNums'] = PwColony::calculateCredit($rt);
  123. $rt['createtime'] = get_date($rt['createtime'], 'Y-m-d');
  124. $group[$rt['id']] = $rt;
  125. }
  126. }
  127. $colonyids = S::sqlImplode(array_keys($group));
  128. if ($colonyids) {
  129. $query = $db->query("SELECT id,ifadmin,colonyid FROM pw_cmembers WHERE colonyid IN ($colonyids) AND uid=" . S::sqlEscape($winduid,false));
  130. while ($rt = $db->fetch_array($query)) {
  131. $cMembers[$rt['colonyid']] = $rt['ifadmin'];
  132. }
  133. }
  134. $u = $winduid;
  135. $username = $windid;
  136. /*
  137. $o_cate = array();
  138. include_once(D_P . 'data/bbscache/forum_cache.php');
  139. if(is_array($o_classdb)){
  140. foreach ($o_classdb as $key => $value) {
  141. $o_cate[$forum[$key]['fup']][$key] = $value;
  142. }
  143. }
  144. */
  145. // require_once(M_P.'require/header.php');
  146. // require_once PrintEot('m_groups');
  147. // footer();
  148. list($isheader,$isfooter,$tplname,$isleft) = array(true,true,"m_groups",true);
  149. } elseif ($a == 'friend') {
  150. S::gp(array('page','cid'), null, 2);
  151. $friends = getFriends($winduid);
  152. unset($friends[$winduid]);
  153. $friends = is_array($friends) ? array_keys($friends) : array();
  154. $group = array();
  155. $pages = '';
  156. $total = 0;
  157. if (count($friends)) {
  158. $total = $db->get_value("SELECT COUNT(DISTINCT c.id) AS count FROM pw_cmembers cm LEFT JOIN pw_colonys c ON cm.colonyid=c.id WHERE cm.uid IN(" . S::sqlImplode($friends) . ") AND cm.ifadmin <> '-1'");
  159. list($pages,$limit) = pwLimitPages($total,$page,"{$basename}a=friend&");
  160. $friends[] = $winduid;
  161. $query = $db->query("SELECT c.id,c.cname,c.cnimg,c.admin,SUM(cm.uid='$winduid') AS ifadd FROM pw_cmembers cm LEFT JOIN pw_colonys c ON cm.colonyid=c.id WHERE cm.uid IN(" . S::sqlImplode($friends) . ") AND cm.ifadmin<>'-1' GROUP BY cm.colonyid HAVING(SUM(cm.uid!='$winduid') > 0) ORDER BY cm.colonyid DESC $limit");
  162. while ($rt = $db->fetch_array($query)) {
  163. if ($rt['cnimg']) {
  164. list($rt['cnimg']) = geturl("cn_img/$rt[cnimg]",'lf');
  165. } else {
  166. $rt['cnimg'] = $GLOBALS['imgpath'] . '/g/groupnopic.gif';
  167. }
  168. $rt['friends'] = array();
  169. $group[$rt['id']] = $rt;
  170. }
  171. if ($group) {
  172. $query = $db->query("SELECT uid,username,colonyid FROM pw_cmembers WHERE uid IN (" . S::sqlImplode($friends) . ') AND colonyid IN(' . S::sqlImplode(array_keys($group)) . ") AND ifadmin<>'-1'");
  173. while ($rt = $db->fetch_array($query)) {
  174. $num = $group[$rt['colonyid']]['ifadd'] ? 2 : 3;
  175. if ($rt['uid'] != $winduid && count($group[$rt['colonyid']]['friends']) < $num) {
  176. $group[$rt['colonyid']]['friends'][$rt['uid']] = $rt['username'];
  177. }
  178. }
  179. }
  180. }
  181. $u = $winduid;
  182. $username = $windid;
  183. // require_once(M_P.'require/header.php');
  184. // require_once PrintEot('m_groups');
  185. // footer();
  186. list($isheader,$isfooter,$tplname,$isleft) = array(true,true,"m_groups",true);
  187. } elseif ($a == 'create') {
  188. banUser();
  189. !$o_newcolony && Showmsg('colony_reglimit');
  190. if($o_groups && strpos($o_groups,','.$groupid.',') === false){
  191. Showmsg('colony_groupright');
  192. }
  193. require_once(R_P.'require/credit.php');
  194. $o_groups_creditset['Creategroup'] = @array_diff($o_groups_creditset['Creategroup'],array(0));
  195. $costs = '';
  196. if (!empty($o_groups_creditset['Creategroup']) && is_array($o_groups_creditset['Creategroup'])) {
  197. foreach ($o_groups_creditset['Creategroup'] as $key => $value) {
  198. if ($value > 0) {
  199. $moneyname = $credit->cType[$key];
  200. if ($value > $credit->get($winduid,$key)) {
  201. $GLOBALS['o_createmoney'] = $value;
  202. Showmsg('colony_creatfailed');
  203. }
  204. $unit = $credit->cUnit[$key];
  205. $value>0 && $costs .= $value.$unit.$moneyname.",";
  206. }
  207. }
  208. }
  209. $costs = trim($costs,",");
  210. //* include_once pwCache::getPath(S::escapePath(D_P."data/groupdb/group_$groupid.php"));
  211. pwCache::getData(S::escapePath(D_P."data/groupdb/group_$groupid.php"));
  212. if ($_G['allowcreate'] && $_G['allowcreate'] <= $db->get_value("SELECT COUNT(*) AS sum FROM pw_colonys WHERE admin=" . S::sqlEscape($windid))) {
  213. Showmsg('colony_numlimit');
  214. }
  215. if (empty($_POST['step'])) {
  216. $u = $winduid;
  217. $username = $windid;
  218. $o_cate = array();
  219. //* include_once pwCache::getPath(D_P . 'data/bbscache/forum_cache.php');
  220. pwCache::getData(D_P . 'data/bbscache/forum_cache.php');
  221. if(is_array($o_classdb)){
  222. foreach ($o_classdb as $key => $value) {
  223. $o_cate[$forum[$key]['fup']][$key] = $value;
  224. }
  225. }
  226. $cnimg_1 = array();
  227. $filetype = (is_array($db_uploadfiletype) ? $db_uploadfiletype : unserialize($db_uploadfiletype));
  228. $default_type = array('gif','jpg','jpeg','bmp','png');
  229. foreach ($default_type as $value) {
  230. $cnimg_1[$value] = $o_imgsize ? $o_imgsize : $filetype[$value];
  231. }
  232. $jsStyle = pwJsonEncode($o_styledb);
  233. $jsStyleRelation = pwJsonEncode($o_style_relation);
  234. list($isheader,$isfooter,$tplname,$isleft) = array(true,true,"m_groups",true);
  235. } else {
  236. require_once(R_P.'require/postfunc.php');
  237. PostCheck(1,$o_groups_gdcheck,$o_groups_qcheck && $db_question);
  238. S::gp(array('cname','descrip'),'P');
  239. S::gp(array('cid','firstgradestyle','secondgradestyle'), 'P', 2);
  240. (!$cname || strlen($cname) > 20) && Showmsg('colony_emptyname');
  241. $descrip = str_replace('&#61;' , '=', $descrip);
  242. strlen($descrip) > 255 && Showmsg('colony_descrip');
  243. //!$cid && Showmsg('colony_class');
  244. require_once(R_P . 'require/bbscode.php');
  245. $wordsfb = L::loadClass('FilterUtil', 'filter');
  246. if (($banword = $wordsfb->comprise($cname)) !== false) {
  247. Showmsg('title_wordsfb');
  248. }
  249. if (($banword = $wordsfb->comprise($descrip)) !== false) {
  250. Showmsg('title_wordsfb');
  251. }
  252. $styleid = 0;
  253. $styles = array();
  254. if ($o_styledb) {
  255. if (!isset($o_style_relation[$firstgradestyle])) {
  256. Showmsg('请选择分类!');
  257. }
  258. if (empty($o_style_relation[$firstgradestyle])) {
  259. $styleid = $firstgradestyle;
  260. array_push($styles,$firstgradestyle);
  261. } else {
  262. !in_array($secondgradestyle, $o_style_relation[$firstgradestyle]) && Showmsg('请选择二级分类!');
  263. $styleid = $secondgradestyle;
  264. array_push($styles,$firstgradestyle,$secondgradestyle);
  265. }
  266. }
  267. /*
  268. if (empty($cid) || !isset($o_classdb[$cid])) {
  269. $cid = 0;
  270. }
  271. */
  272. $rt = $db->get_one("SELECT id FROM pw_colonys WHERE cname=".S::sqlEscape($cname));
  273. $rt['id'] > 0 && Showmsg('colony_samename');
  274. //积分变动
  275. if (!empty($o_groups_creditset['Creategroup'])) {
  276. $creditset = getCreditset($o_groups_creditset['Creategroup'],false);
  277. $credit->sets($winduid,$creditset,true);
  278. updateMemberid($winduid);
  279. }
  280. if ($creditlog = $o_groups_creditlog) {
  281. addLog($creditlog['Creategroup'],$windid,$winduid,'groups_Creategroup');
  282. }
  283. @asort($o_groups_levelneed);
  284. $commonLevel = key($o_groups_levelneed);
  285. empty($commonLevel) && Showmsg("系统未创建群组等级,无法创建群组!");
  286. S::gp(array('title1','title2','title3','title4'));
  287. $titlefont = S::escapeChar("$title1~$title2~$title3~$title4~$title5~$title6~");
  288. /**
  289. $db->update("INSERT INTO pw_colonys SET " . S::sqlSingle(array(
  290. 'cname' => $cname,
  291. //'classid' => $cid,
  292. 'styleid' => $styleid,
  293. 'commonlevel' => $commonLevel,
  294. 'admin' => $windid,
  295. 'members' => 1,
  296. 'ifcheck' => 2,
  297. 'createtime'=> $timestamp,
  298. 'descrip' => $descrip,
  299. 'titlefont' => $titlefont
  300. )));
  301. $cyid = $db->insert_id();
  302. **/
  303. $cyid = pwQuery::insert('pw_colonys', array(
  304. 'cname' => $cname,
  305. //'classid' => $cid,
  306. 'styleid' => $styleid,
  307. 'commonlevel' => $commonLevel,
  308. 'admin' => $windid,
  309. 'members' => 1,
  310. 'ifcheck' => 2,
  311. 'createtime'=> $timestamp,
  312. 'descrip' => $descrip,
  313. 'titlefont' => $titlefont
  314. ));
  315. $db->update("UPDATE pw_cnstyles SET csum=csum+1 WHERE id IN (" . S::sqlImplode($styles) . ')');
  316. require_once(A_P . 'groups/lib/imgupload.class.php');
  317. $img = new CnimgUpload($cyid);
  318. PwUpload::upload($img);
  319. pwFtpClose($ftp);
  320. if ($cnimg = $img->getImgUrl()) {
  321. $cnimg = substr(strrchr($cnimg,'/'),1);
  322. //* $db->update("UPDATE pw_colonys SET cnimg=".S::sqlEscape($cnimg)." WHERE id=".S::sqlEscape($cyid));
  323. $db->update(pwQuery::buildClause("UPDATE :pw_table SET cnimg=:cnimg WHERE id=:id", array('pw_colonys', $cnimg, $cyid)));
  324. }
  325. /**
  326. $db->update("INSERT INTO pw_cmembers SET " . S::sqlSingle(array(
  327. 'uid' => $winduid,
  328. 'username' => $windid,
  329. 'ifadmin' => 1,
  330. 'colonyid' => $cyid,
  331. 'addtime' => $timestamp
  332. )));
  333. **/
  334. pwQuery::insert('pw_cmembers', array(
  335. 'uid' => $winduid,
  336. 'username' => $windid,
  337. 'ifadmin' => 1,
  338. 'colonyid' => $cyid,
  339. 'addtime' => $timestamp
  340. ));
  341. updateUserAppNum($winduid,'group');
  342. $url = "apps.php?q=group&cyid=$cyid&a=set";
  343. $msg = defined('AJAX') ? "success\t".$url : 'colony_regsuccess';
  344. refreshto("apps.php?q=group&cyid=$cyid&a=set",$msg);
  345. }
  346. } elseif ($a == 'checkcname') {
  347. define('AJAX',1);
  348. S::gp(array('cname'));
  349. $ckcname = $db->get_value("SELECT cname FROM pw_colonys WHERE cname=".S::sqlEscape($cname));
  350. if(empty($ckcname)) {
  351. echo "ok";
  352. }
  353. ajax_footer();
  354. }
  355. require_once PrintEot('m_groups');
  356. pwOutPut();
  357. ?>