collection_edit.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: collection_edit.php 33065 2013-04-16 10:06:07Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $titlelimit = 30;
  12. $desclimit = 250;
  13. $reasonlimit = 250;
  14. $oplist = array('add', 'edit', 'remove', 'addthread', 'delthread', 'acceptinvite', 'removeworker', 'invite');
  15. if(!in_array($op, $oplist)) {
  16. $op = '';
  17. }
  18. if(empty($_G['uid'])) {
  19. showmessage('login_before_enter_home', null, array(), array('showmsg' => true, 'login' => 1));
  20. }
  21. if(empty($op) || $op == 'add') {
  22. if(!helper_access::check_module('collection')) {
  23. showmessage('quickclear_noperm');
  24. }
  25. $_GET['handlekey'] = 'createcollection';
  26. $navtitle = lang('core', 'title_collection_create');
  27. $createdcollectionnum = C::t('forum_collection')->count_by_uid($_G['uid']);
  28. $reamincreatenum = $_G['group']['allowcreatecollection']-$createdcollectionnum;
  29. if(!$_G['group']['allowcreatecollection'] || $reamincreatenum <= 0) {
  30. showmessage('collection_create_exceed_limit');
  31. }
  32. if(!$_GET['submitcollection']) {
  33. include template('forum/collection_add');
  34. } else {
  35. if(!submitcheck('collectionsubmit')) {
  36. showmessage('undefined_action', NULL);
  37. }
  38. if(!$_GET['title']) {
  39. showmessage('collection_edit_checkentire');
  40. }
  41. $newCollectionTitle = censor(dhtmlspecialchars($_GET['title']));
  42. $newCollectionTitle = cutstr($newCollectionTitle, $titlelimit, '');
  43. $newcollection = array(
  44. 'name' => $newCollectionTitle,
  45. 'uid' => $_G['uid'],
  46. 'username' => $_G['username'],
  47. 'desc' => dhtmlspecialchars(cutstr(censor($_GET['desc']), $desclimit, '')),
  48. 'dateline' => $_G['timestamp'],
  49. 'lastupdate' => $_G['timestamp'],
  50. 'lastvisit' => $_G['timestamp'],
  51. 'keyword' => parse_keyword($_GET['keyword'], true)
  52. );
  53. $newctid = C::t('forum_collection')->insert($newcollection, true);
  54. if($newctid) {
  55. showmessage('collection_create_succ', 'forum.php?mod=collection&action=view&ctid='.$newctid, array('ctid'=>$newctid, 'title'=>$newCollectionTitle), array('closetime' => '2', 'showmsg' => ($_GET['inajax'] ? '0' : '1')));
  56. }
  57. }
  58. } elseif($op == 'edit') {
  59. $navtitle = lang('core', 'title_collection_edit');
  60. if(!$ctid) {
  61. showmessage('undefined_action', NULL);
  62. }
  63. if(!$_G['collection']['ctid'] || !checkcollectionperm($_G['collection'], $_G['uid'])) {
  64. showmessage('collection_permission_deny');
  65. }
  66. if(!submitcheck('collectionsubmit')) {
  67. include template('forum/collection_add');
  68. } else {
  69. if(!$_GET['title']) {
  70. showmessage('collection_edit_checkentire');
  71. }
  72. if($_GET['formhash'] != FORMHASH) {
  73. showmessage('undefined_action', NULL);
  74. }
  75. $newCollectionTitle = censor(dhtmlspecialchars($_GET['title']));
  76. $newCollectionTitle = cutstr($newCollectionTitle, 30, '');
  77. $newcollection = array(
  78. 'name' => $newCollectionTitle,
  79. 'desc' => dhtmlspecialchars(cutstr(censor($_GET['desc']), $desclimit, '')),
  80. 'keyword' => parse_keyword($_GET['keyword'], true)
  81. );
  82. C::t('forum_collection')->update($ctid, $newcollection);
  83. if($_GET['title'] != $_G['collection']['name']) {
  84. C::t('forum_collectionteamworker')->update_by_ctid($ctid, $_GET['title']);
  85. }
  86. showmessage('collection_edit_succ', 'forum.php?mod=collection&action=view&ctid='.$ctid);
  87. }
  88. } elseif($op == 'remove') {
  89. if($_GET['formhash'] != FORMHASH) {
  90. showmessage('undefined_action', NULL);
  91. }
  92. if($_G['collection'] && checkcollectionperm($_G['collection'], $_G['uid'])) {
  93. require_once libfile('function/delete');
  94. deletecollection($_G['collection']['ctid']);
  95. showmessage('collection_delete_succ', 'forum.php?mod=collection&op=my');
  96. } else {
  97. showmessage('collection_permission_deny');
  98. }
  99. } elseif($op == 'addthread') {
  100. if((!$_G['forum_thread'] || !$_G['forum']) && !is_array($_GET['tids'])) {
  101. showmessage('thread_nonexistence');
  102. }
  103. if(!is_array($_GET['tids']) && $_G['forum']['disablecollect']) {
  104. showmessage('collection_forum_deny', '', array(), array('showdialog' => 1));
  105. }
  106. if(!submitcheck('addthread')) {
  107. $createdcollectionnum = C::t('forum_collection')->count_by_uid($_G['uid']);
  108. $reamincreatenum = $_G['group']['allowcreatecollection']-$createdcollectionnum;
  109. $collections = getmycollection($_G['uid']);
  110. if(count($collections) > 0) {
  111. $tidrelated = C::t('forum_collectionrelated')->fetch($tid, true);
  112. $tidcollections = explode("\t", $tidrelated['collection']);
  113. }
  114. $allowcollections = array_diff(array_keys($collections), $tidcollections);
  115. if($reamincreatenum <= 0 && count($allowcollections) <= 0) {
  116. showmessage('collection_none_avail_collection', '', array(), array('showdialog' => 1));
  117. }
  118. include template('forum/collection_select');
  119. } else {
  120. if(!$ctid) {
  121. showmessage('collection_no_selected', '', array(), array('showdialog' => 1));
  122. }
  123. if(!is_array($_GET['tids'])) {
  124. $tid = $_G['tid'];
  125. $thread[$tid] = &$_G['thread'];
  126. }
  127. $collectiondata = C::t('forum_collection')->fetch_all($ctid);
  128. if(count($collectiondata) < 0) {
  129. showmessage('undefined_action', NULL);
  130. } else {
  131. foreach ($collectiondata as $curcollectiondata) {
  132. if(!$curcollectiondata['ctid']) {
  133. showmessage('collection_permission_deny', '', array(), array('showdialog' => 1));
  134. }
  135. if(!checkcollectionperm($curcollectiondata, $_G['uid'], true)) {
  136. showmessage('collection_non_creator', '', array(), array('showdialog' => 1));
  137. }
  138. if(!is_array($_GET['tids'])) {
  139. $checkexistctid[$tid] = C::t('forum_collectionthread')->fetch_by_ctid_tid($curcollectiondata['ctid'], $thread[$tid]['tid']);
  140. if($checkexistctid[$tid]['ctid']) {
  141. showmessage('collection_thread_exists', '', array(), array('showdialog' => 1));
  142. }
  143. $tids[0] = $tid;
  144. $checkexist[$tid] = C::t('forum_collectionrelated')->fetch($tid, true);
  145. } else {
  146. $thread = C::t('forum_thread')->fetch_all($_GET['tids']);
  147. foreach ($thread as $perthread) {
  148. $fids[$perthread['fid']] = $perthread['fid'];
  149. }
  150. $fids = array_keys($fids);
  151. $foruminfo = C::t('forum_forumfield')->fetch_all($fids);
  152. $tids = array_keys($thread);
  153. $checkexistctid = C::t('forum_collectionthread')->fetch_all_by_ctid_tid($curcollectiondata['ctid'], $tids);
  154. $checkexist = C::t('forum_collectionrelated')->fetch_all($tids, true);
  155. }
  156. $addsum = 0;
  157. foreach ($tids as $curtid) {
  158. $thread_fid = $thread[$curtid]['fid'];
  159. if(!$checkexistctid[$curtid]['ctid'] && !$foruminfo[$thread_fid]['disablecollect']) {
  160. $newthread = array(
  161. 'ctid' => $curcollectiondata['ctid'],
  162. 'tid' => $thread[$curtid]['tid'],
  163. 'dateline' => $thread[$curtid]['dateline'],
  164. 'reason' => cutstr(censor(dhtmlspecialchars($_GET['reason'])), $reasonlimit, '')
  165. );
  166. C::t('forum_collectionthread')->insert($newthread);
  167. } else {
  168. continue;
  169. }
  170. if(!$checkexist[$curtid]) {
  171. C::t('forum_collectionrelated')->insert(array('tid'=>$curtid, 'collection'=>$curcollectiondata['ctid']."\t"));
  172. $checkexist[$curtid] = 1;
  173. } else {
  174. C::t('forum_collectionrelated')->update_collection_by_ctid_tid($curcollectiondata['ctid'], $curtid);
  175. }
  176. if(!getstatus($thread[$curtid]['status'], 9)) {
  177. C::t('forum_thread')->update_status_by_tid($curtid, '256');
  178. }
  179. if($_G['uid'] != $thread[$curtid]['authorid']) {
  180. notification_add($thread[$curtid]['authorid'], "system", 'collection_becollected', array('from_id'=>$_G['collection']['ctid'], 'from_idtype'=>'collectionthread', 'ctid'=>$_G['collection']['ctid'], 'collectionname'=>$_G['collection']['name'], 'tid'=>$curtid, 'threadname'=>$thread[$curtid]['subject']), 1);
  181. }
  182. $addsum++;
  183. }
  184. if($addsum > 0) {
  185. $lastpost = array(
  186. 'lastpost' => $thread[$tids[0]]['tid'],
  187. 'lastsubject' => $thread[$tids[0]]['subject'],
  188. 'lastposttime' => $thread[$tids[0]]['dateline'],
  189. 'lastposter' => $thread[$tids[0]]['author']
  190. );
  191. C::t('forum_collection')->update_by_ctid($curcollectiondata['ctid'], $addsum, 0, 0, $_G['timestamp'], 0, 0, $lastpost);
  192. }
  193. }
  194. }
  195. showmessage('collection_collect_succ', dreferer(), array(), array('alert'=> 'right', 'closetime' => true, 'locationtime' => true, 'showdialog' => 1));
  196. }
  197. } elseif($op == 'delthread') {
  198. if($_GET['formhash'] != FORMHASH) {
  199. showmessage('undefined_action', NULL);
  200. }
  201. if(!$ctid || count($_GET['delthread']) == 0) {
  202. showmessage('collection_no_thread');
  203. }
  204. if(!$_G['collection']['ctid'] || !checkcollectionperm($_G['collection'], $_G['uid'])) {
  205. showmessage('collection_permission_deny');
  206. }
  207. require_once libfile('function/delete');
  208. deleterelatedtid($_GET['delthread'], $_G['collection']['ctid']);
  209. $decthread = C::t('forum_collectionthread')->delete_by_ctid_tid($ctid, $_GET['delthread']);
  210. $lastpost = null;
  211. if(in_array($_G['collection']['lastpost'], $_GET['delthread']) && ($_G['collection']['threadnum'] - $decthread) > 0) {
  212. $collection_thread = C::t('forum_collectionthread')->fetch_by_ctid_dateline($ctid);
  213. if($collection_thread) {
  214. $thread = C::t('forum_thread')->fetch($collection_thread['tid']);
  215. $lastpost = array(
  216. 'lastpost' => $thread['tid'],
  217. 'lastsubject' => $thread['subject'],
  218. 'lastposttime' => $thread['dateline'],
  219. 'lastposter' => $thread['authorid']
  220. );
  221. }
  222. }
  223. C::t('forum_collection')->update_by_ctid($ctid, -$decthread, 0, 0, 0, 0, 0, $lastpost);
  224. showmessage('collection_remove_thread', 'forum.php?mod=collection&action=view&ctid='.$ctid);
  225. } elseif($op == 'invite') {
  226. if(!$ctid) {
  227. showmessage('undefined_action', NULL);
  228. }
  229. if(!$_G['collection']['ctid'] || !checkcollectionperm($_G['collection'], $_G['uid'])) {
  230. showmessage('collection_permission_deny');
  231. }
  232. $collectionteamworker = C::t('forum_collectionteamworker')->fetch_all_by_ctid($ctid);
  233. $submitworkers = count($_GET['users']);
  234. if((count($collectionteamworker) + $submitworkers) >= $maxteamworkers) {
  235. showmessage('collection_teamworkers_exceed');
  236. }
  237. require_once libfile('function/friend');
  238. if($_GET['username'] && !$_GET['users']) {
  239. $_GET['users'][] = $_GET['username'];
  240. }
  241. if(!$_GET['users']) {
  242. if($_POST['formhash']) {
  243. showmessage('collection_teamworkers_noselect', NULL);
  244. }
  245. $friends = array();
  246. if($space['friendnum']) {
  247. $query = C::t('home_friend')->fetch_all_by_uid($_G['uid'], 0, 100, true);
  248. foreach($query as $value) {
  249. $value['uid'] = $value['fuid'];
  250. $value['username'] = daddslashes($value['fusername']);
  251. $friends[] = $value;
  252. }
  253. }
  254. $friendgrouplist = friend_group_list();
  255. include template('forum/collection_invite');
  256. } else {
  257. $invitememberuids = array();
  258. if(is_array($_GET['users'])) {
  259. $invitememberuids = C::t('common_member')->fetch_all_uid_by_username($_GET['users']);
  260. }
  261. if(!$invitememberuids) {
  262. showmessage('collection_no_teamworkers');
  263. }
  264. if(!friend_check($invitememberuids) || in_array($_G['uid'], $invitememberuids)) {
  265. showmessage('collection_non_friend');
  266. }
  267. $collectionteamworker = array_keys($collectionteamworker);
  268. if(in_array($invitememberuids, $collectionteamworker)) {
  269. showmessage('collection_teamworkers_exists');
  270. }
  271. foreach($invitememberuids as $invitememberuid) {
  272. $data = array('ctid'=>$ctid,'uid'=>$invitememberuid,'dateline'=>$_G['timestamp']);
  273. C::t('forum_collectioninvite')->insert($data, false, true);
  274. notification_add($invitememberuid, "system", 'invite_collection', array('ctid'=>$_G['collection']['ctid'], 'collectionname'=>$_G['collection']['name'], 'dateline'=>$_G['timestamp']), 1);
  275. }
  276. showmessage('collection_invite_succ', 'forum.php?mod=collection&action=view&ctid='.$ctid, array(), array('alert'=> 'right', 'closetime' => true, 'showdialog' => 1));
  277. }
  278. } elseif($op == 'acceptinvite') {
  279. if(!submitcheck('ctid', 1)) {
  280. showmessage('undefined_action', NULL);
  281. } else {
  282. $collectioninvite = C::t('forum_collectioninvite')->fetch_by_ctid_uid($ctid, $_G['uid']);
  283. if(!$collectioninvite['ctid'] || $_GET['dateline'] != $collectioninvite['dateline']) {
  284. showmessage('undefined_action', NULL);
  285. }
  286. $teamworkernum = C::t('forum_collectionteamworker')->count_by_ctid($ctid);
  287. if($teamworkernum >= $maxteamworkers) {
  288. showmessage('collection_teamworkers_exceed');
  289. }
  290. C::t('forum_collectioninvite')->delete_by_ctid_uid($ctid, $_G['uid']);
  291. $newworker = array(
  292. 'ctid'=>$ctid,
  293. 'uid'=>$_G['uid'],
  294. 'name'=>$_G['collection']['name'],
  295. 'username'=>$_G['username'],
  296. 'lastvisit' => $_G['timestamp']
  297. );
  298. C::t('forum_collectionteamworker')->insert($newworker, false, true);
  299. showmessage('collection_invite_accept', 'forum.php?mod=collection&action=view&ctid='.$ctid);
  300. }
  301. } elseif($op == 'removeworker') {
  302. if(!submitcheck('ctid', 1)) {
  303. showmessage('undefined_action', NULL);
  304. } else {
  305. if($_GET['formhash'] != FORMHASH) {
  306. showmessage('undefined_action', NULL);
  307. }
  308. if(!$_G['collection']['ctid']) {
  309. showmessage('collection_permission_deny');
  310. }
  311. if($_GET['uid'] != $_G['uid']) {
  312. if($_G['collection']['uid'] != $_G['uid']) {
  313. showmessage('collection_remove_deny');
  314. }
  315. $removeuid = $_GET['uid'];
  316. } else {
  317. $removeuid = $_G['uid'];
  318. }
  319. $collectionteamworker = array_keys(C::t('forum_collectionteamworker')->fetch_all_by_ctid($ctid));
  320. if(!in_array($removeuid, $collectionteamworker)) {
  321. showmessage('collection_teamworkers_nonexists');
  322. }
  323. C::t('forum_collectionteamworker')->delete_by_ctid_uid($ctid, $removeuid);
  324. notification_add($removeuid, "system", 'exit_collection', array('ctid'=>$_G['collection']['ctid'], 'collectionname'=>$_G['collection']['name']), 1);
  325. if($_GET['inajax']) {
  326. showmessage('', dreferer(), array(), array('msgtype' => 3, 'showmsg' => 1));
  327. } else {
  328. showmessage('collection_teamworkers_exit_succ', 'forum.php?mod=collection&action=view&ctid='.$ctid);
  329. }
  330. }
  331. }
  332. ?>