1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:
609:
610:
611:
612:
613:
614:
615:
616:
617:
618:
619:
|
<?php
require ("./global.php");
require ("./lib/mod_functions.php");
@set_time_limit(0);
$lang->load("ACP_THREADS");
if(isset($_REQUEST['action'])) $action=$_REQUEST['action'];
else $action="spinning";
/** threads: mass prune/move/unsubscribe **/
if($action=="threads_mass_edit") {
checkAdminPermissions("a_can_threads_mass_edit",1);
if(isset($_POST['send'])) {
$where = "";
// first post older than x days
if(isset($_POST['starttime']) && $_POST['starttime']!="") add2where("starttime < '".(time() - intval($_POST['starttime']) * 86400)."'");
// last post older than x days
if(isset($_POST['lastposttime']) && $_POST['lastposttime']!="") add2where("lastposttime < '".(time() - intval($_POST['lastposttime']) * 86400)."'");
// replies more than x
if(isset($_POST['replies_morethan']) && $_POST['replies_morethan']!="") add2where("replycount > '".intval($_POST['replies_morethan'])."'");
// replies less than x
if(isset($_POST['replies_lessthan']) && $_POST['replies_lessthan']!="") add2where("replycount < '".intval($_POST['replies_morethan'])."'");
// starter is
if(isset($_POST['starter']) && $_POST['starter']!="") add2where("starter = '".addslashes(wbb_trim($_POST['starter']))."'");
// poster is
if(isset($_POST['username']) && $_POST['username']!="") {
$threadids = "";
$result = $db->unbuffered_query("SELECT DISTINCT threadid FROM bb".$n."_posts WHERE username='".addslashes(wbb_trim($_POST['username']))."'");
while($row=$db->fetch_array($result)) $threadids .= ",".$row['threadid'];
if($threadids!="") add2where("threadid IN (0".$threadids.")");
}
// is closed?
if(isset($_POST['closed']) && $_POST['closed']!="") add2where("closed = '".intval($_POST['closed'])."'");
// in boards
if(isset($_POST['boardids']) && count($_POST['boardids'])) add2where("boardid IN (".implode(",", intval_array($_POST['boardids'])).")");
if(isset($_POST['threadaction'])) $threadaction=$_POST['threadaction'];
else $threadaction="";
$done = 0;
if($where!="") {
$result = $db->unbuffered_query("SELECT threadid FROM bb".$n."_threads WHERE ".$where." AND closed<>3");
while($row=$db->fetch_array($result)) $threadids .= ",".$row['threadid'];
if($threadids!="") {
// unsubscribe users from threads
if($threadaction=="unsubscribe") {
$db->unbuffered_query("DELETE FROM bb".$n."_subscribethreads WHERE threadid IN (0".$threadids.")",1);
$done = 1;
}
// open threads
if($threadaction=="open") {
$db->unbuffered_query("UPDATE bb".$n."_threads SET closed=0 WHERE threadid IN (0".$threadids.") AND closed<>3",1);
$done = 1;
}
// close threads
if($threadaction=="close") {
$db->unbuffered_query("UPDATE bb".$n."_threads SET closed=1 WHERE threadid IN (0".$threadids.") AND closed<>3",1);
$done = 1;
}
// delete threads
if($threadaction=="delete") {
// update global stats
list($threadcount) = $db->query_first("SELECT COUNT(*) FROM bb".$n."_threads WHERE threadid IN (0".$threadids.")");
list($postcount) = $db->query_first("SELECT COUNT(*) FROM bb".$n."_posts WHERE threadid IN (0".$threadids.")");
$db->unbuffered_query("UPDATE bb".$n."_stats SET threadcount=threadcount-".intval($threadcount).", postcount=postcount-".intval($postcount),1);
// delete polls
$pollids="";
$result = $db->unbuffered_query("SELECT pollid FROM bb".$n."_threads WHERE threadid IN (0".$threadids.") AND pollid<>0 AND closed<>3");
while($row=$db->fetch_array($result)) $pollids = ",".$row['pollid'];
if($pollids!="") {
$db->unbuffered_query("DELETE FROM bb".$n."_polls WHERE pollid IN (0".$pollids.")",1);
$db->unbuffered_query("DELETE FROM bb".$n."_votes WHERE id IN (0".$pollids.") AND votemode=1",1);
$db->unbuffered_query("DELETE FROM bb".$n."_polloptions WHERE pollid IN (0".$pollids.")",1);
}
// delete attachments
$attachmentids="";
$result = $db->unbuffered_query("SELECT attachmentid FROM bb".$n."_posts WHERE threadid IN (0".$threadids.") AND attachmentid>0");
while($row=$db->fetch_array($result)) $attachmentids.=",".$row['attachmentid'];
if($attachmentids!="") {
$result = $db->query("SELECT attachmentid, attachmentextension FROM bb".$n."_attachments WHERE attachmentid IN (0".$attachmentids.")");
while($row=$db->fetch_array($result)) @unlink("./../attachments/attachment-".$row['attachmentid'].".".$row['attachmentextension']);
$db->unbuffered_query("DELETE FROM bb".$n."_attachments WHERE attachmentid IN (0".$attachmentids.")",1);
}
// delete threads
$db->unbuffered_query("DELETE FROM bb".$n."_threads WHERE threadid IN (0".$threadids.")",1);
$db->unbuffered_query("DELETE FROM bb".$n."_threads WHERE pollid IN (0".$threadids.") AND closed=3",1);
$db->unbuffered_query("DELETE FROM bb".$n."_subscribethreads WHERE threadid IN (0".$threadids.")",1);
$db->unbuffered_query("DELETE FROM bb".$n."_announcements WHERE threadid IN (0".$threadids.")",1);
$db->unbuffered_query("DELETE FROM bb".$n."_votes WHERE id IN (0".$threadids.") AND votemode=2",1);
// delete posts
$db->unbuffered_query("DELETE FROM bb".$n."_posts WHERE threadid IN (0".$threadids.")",1);
$done = 1;
}
// move thread
if($threadaction=="move") {
if(isset($_POST['movethread'])) $movethread = $_POST['movethread'];
else $movethread = "";
if(isset($_POST['newboardid'])) $newboardid=intval($_POST['newboardid']);
else $newboardid=0;
if($movethread=="onlymove" || $movethread=="movewithredirect") {
// update announcements
$result = $db->query("SELECT COUNT(a.threadid) AS acount, t.threadid, t.boardid FROM bb".$n."_threads t LEFT JOIN bb".$n."_announcements a USING(threadid) WHERE t.threadid IN (0".$threadids.") AND t.important=2 GROUP BY t.threadid");
while($row=$db->fetch_array($result)) {
if($row['acount']>1) $db->unbuffered_query("INSERT IGNORE INTO bb".$n."_announcements (boardid,threadid) VALUES ('".$newboardid."','".$row['threadid']."')",1);
else $db->unbuffered_query("UPDATE bb".$n."_announcements SET boardid='".$newboardid."' WHERE threadid='".$row['threadid']."' AND boardid='".$row['boardid']."'",1);
}
// add redirect
if($movethread=="movewithredirect") {
$result = $db->query("SELECT * FROM bb".$n."_threads WHERE threadid IN (0".$threadids.")");
while($row=$db->fetch_array($result)) {
$db->unbuffered_query("INSERT INTO bb".$n."_threads (boardid,prefix,topic,iconid,starttime,starterid,starter,lastposttime,lastposterid,lastposter,replycount,views,closed,voted,votepoints,pollid,visible) VALUES "
. "('".$row['boardid']."','".addslashes($row['prefix'])."','".addslashes($row['topic'])."','".$thread['iconid']."','".$thread['starttime']."','".$thread['starterid']."','".addslashes($thread['starter'])."','".$thread['lastposttime']."','".$thread['lastposterid']."','".addslashes($thread['lastposter'])."','".$thread['replycount']."','".$thread['views']."','3','".$thread['voted']."','".$thread['votepoints']."','".$row['threadid']."','".$thread['visible']."')",1);
}
}
// update thread
$db->unbuffered_query("UPDATE bb".$n."_threads SET boardid='".$newboardid."' WHERE threadid IN (0".$threadids.")",1);
}
$done = 1;
}
}
}
if($done == 0) acp_error($lang->get("LANG_ACP_THREADS_MASS_EDIT_ERROR"));
else acp_message($lang->get("LANG_ACP_THREADS_MASS_EDIT_DONE"));
}
$boardcache=array();
$result = $db->unbuffered_query("SELECT boardid, parentid, boardorder, title FROM bb".$n."_boards ORDER by parentid ASC, boardorder ASC");
while ($row = $db->fetch_array($result)) {
$row['title'] = getlangvar($row['title'], $lang);
$boardcache[$row['parentid']][$row['boardorder']][$row['boardid']] = $row;
}
$boardid_options = makeboardoptions(0);
eval ("\$lang->items['LANG_ACP_THREADS_MASS_EDIT_DESC'] = \"".$lang->get4eval("LANG_ACP_THREADS_MASS_EDIT_DESC")."\";");
eval("\$tpl->output(\"".$tpl->get("threads_mass_edit",1)."\",1);");
}
/** thread spinning **/
if($action=="spinning") {
checkAdminPermissions("a_can_threads_edit",1);
if(isset($_POST['send'])) {
$boardid=intval($_POST['boardid']);
// read in modpermissions
$board = $db->query_first("SELECT *,userid as moderatorid FROM bb".$n."_moderators WHERE userid='".$wbbuserdata['userid']."' AND boardid='".$boardid."'");
if(!checkmodpermissions("m_can_thread_close") && !checkmodpermissions("m_can_thread_move") && !checkmodpermissions("m_can_thread_del")) acp_error($lang->get("LANG_ACP_THREADS_EDIT_ACCESS_ERROR"));
$limit=intval($_POST['limit']);
if(!$limit) $limit=20;
$offset=intval($_POST['offset']);
if($offset<1) $offset=1;
$offset-=1;
$sortby=$_REQUEST['sortby'];
$sortorder=$_REQUEST['sortorder'];
switch($sortorder) {
case "ASC": break;
case "DESC": break;
default: $sortorder="DESC";
}
switch($sortby) {
case "topic": break;
case "starttime": break;
case "starter": break;
case "lastposttime": break;
case "lastposter": break;
case "replycount": break;
case "views": break;
default: $sortby="lastposttime";
}
$threadbit="";
$count=0;
$result=$db->query("SELECT threadid, topic, starter, starterid FROM bb".$n."_threads WHERE boardid='$boardid' ORDER BY $sortby $sortorder",$limit,$offset);
if(!$db->num_rows($result)) acp_error($lang->get("LANG_ACP_GLOBAL_ERROR_NORESULT"));
while($row=$db->fetch_array($result)) {
$rowclass=getone($count++,"firstrow","secondrow");
$row['starter']=htmlconverter($row['starter']);
$row['topic']=htmlconverter($row['topic']);
if($row['starterid']!=0) $row['starter']=makehreftag("../profile.php?userid=$row[starterid]",$row['starter'],"_blank");
eval ("\$threadbit .= \"".$tpl->get("threads_spinbit",1)."\";");
}
eval("\$tpl->output(\"".$tpl->get("threads_spin",1)."\",1);");
exit();
}
$lang->load("BOARD,ACP_BOARD");
// read permissions
$permissioncache=getPermissions();
// read boardoptions
$boardcache=array();
$result = $db->unbuffered_query("SELECT boardid, parentid, boardorder, title FROM bb".$n."_boards ORDER by parentid ASC, boardorder ASC");
while ($row = $db->fetch_array($result)) {
if(!isset($permissioncache[$row['boardid']]['can_view_board'])) $permissioncache[$row['boardid']]['can_view_board']=-1;
if($permissioncache[$row['boardid']]['can_view_board']==0 || ($permissioncache[$row['boardid']]['can_view_board']==-1 && !$wbbuserdata['can_view_board'])) continue;
$row['title'] = getlangvar($row['title'], $lang);
$boardcache[$row['parentid']][$row['boardorder']][$row['boardid']] = $row;
}
$boardid_options = makeboardoptions(0);
eval("\$tpl->output(\"".$tpl->get("threads",1)."\",1);");
}
/** thread spinning (verify) **/
if($action=="verify") {
checkAdminPermissions("a_can_threads_edit",1);
$boardid=intval($_REQUEST['boardid']);
if(isset($_POST['send'])) {
$closethread=$_POST['closethread'];
// close threads
$close_threadids="";
if(is_array($closethread)) {
reset($closethread);
while(list($key,$val)=each($closethread)) if($val==1) $close_threadids.=",$key";
}
if($close_threadids) $db->unbuffered_query("UPDATE bb".$n."_threads SET closed=1-closed WHERE threadid IN (0".$close_threadids.")",1);
// delete threads
$delthread=$_POST['delthread'];
$del_threadids="";
if(is_array($delthread)) {
reset($delthread);
while(list($key,$val)=each($delthread)) if($val==1) $del_threadids.=",$key";
}
if($del_threadids) {
$board=$db->query_first("SELECT * FROM bb".$n."_boards WHERE boardid='$boardid'");
// delete threads
$result=$db->query("SELECT pollid, replycount FROM bb".$n."_threads WHERE threadid IN (0".$del_threadids.")");
$threadcount=$db->num_rows($result); // thread count for board counter
$pollids="";
$postcount=0;
while($row=$db->fetch_array($result)) {
$postcount+=1+$row['replycount']; // post count for board counter
if($row['pollid']) $pollids.=",$row[pollid]";
}
$db->query("DELETE FROM bb".$n."_threads WHERE threadid IN (0".$del_threadids.")"); // delete thread
$db->unbuffered_query("DELETE FROM bb".$n."_threads WHERE pollid IN (0".$del_threadids.") AND closed=3",1); // delete redirect thread
$db->unbuffered_query("DELETE FROM bb".$n."_announcements WHERE threadid IN (0".$del_threadids.")",1); // delete announcements
$db->unbuffered_query("DELETE FROM bb".$n."_subscribethreads WHERE threadid IN (0".$del_threadids.")",1); // delete subscriptions
// update global stats
$db->unbuffered_query("UPDATE bb".$n."_stats SET threadcount=threadcount-".intval($threadcount).", postcount=postcount-".intval($postcount),1);
// delete polls
if($pollids) {
$db->query("DELETE FROM bb".$n."_polls WHERE pollid IN (0$pollids)");
$pollvotes=" OR (id IN (0$pollids) AND votemode=1)";
$db->query("DELETE FROM bb".$n."_polloptions WHERE pollid IN (0$pollids)");
}
else $pollvotes="";
$db->query("DELETE FROM bb".$n."_votes WHERE (id IN (0$del_threadids) AND votemode=2)$pollvotes"); // delete ratings
/* delete attachments */
$result = $db->unbuffered_query("SELECT attachmentid FROM bb".$n."_posts WHERE threadid IN (0$del_threadids) AND attachmentid>0");
while($row=$db->fetch_array($result)) $attachmentids.=",".$row['attachmentid'];
$result = $db->unbuffered_query("SELECT attachmentid, attachmentextension FROM bb".$n."_attachments WHERE attachmentid IN (0$attachmentids)");
while($row=$db->fetch_array($result)) @unlink("./../attachments/attachment-".$row['attachmentid'].".".$row['attachmentextension']);
$db->unbuffered_query("DELETE FROM bb".$n."_attachments WHERE attachmentid IN (0$attachmentids)",1);
// update userposts
// if($board['countuserposts']==1) {
$result = $db->query("SELECT COUNT(postid) AS posts, userid FROM bb".$n."_posts WHERE threadid IN (0$del_threadids) AND visible=1 AND userid>0 GROUP BY userid");
// while($row=$db->fetch_array($result)) $db->query("UPDATE bb".$n."_users SET userposts=userposts-'$row[posts]' WHERE userid='$row[userid]'");
}
// delete posts
$db->query("DELETE FROM bb".$n."_posts WHERE threadid IN (0$del_threadids)");
/* update boardcount */
$db->query("UPDATE bb".$n."_boards SET threadcount=threadcount-'$threadcount', postcount=postcount-'$postcount' WHERE boardid IN ($boardid,$board[parentlist])");
updateBoardInfo("$boardid,$board[parentlist]");
}
// move threads
$movethread=$_POST['movethread'];
$newboardid=$_POST['newboardid'];
$move_threadids="";
if(is_array($movethread)) {
reset($movethread);
while(list($key,$val)=each($movethread)) if($val) $move_threadids.=",$key";
}
if($move_threadids) {
$board=$db->query_first("SELECT * FROM bb".$n."_boards WHERE boardid='$boardid'");
$result=$db->query("SELECT * FROM bb".$n."_threads WHERE threadid IN (0$move_threadids)");
while($thread=$db->fetch_array($result)) movethread($thread['threadid'],$movethread[$thread['threadid']],$newboardid[$thread['threadid']]);
}
header("Location: threads.php?action=spinning&sid=$session[hash]");
exit();
}
$threadaction=$_POST['threadaction'];
reset($threadaction);
$threadids="";
while(list($key,$val)=each($threadaction)) if($val) $threadids.=",$key";
if(!$threadids) acp_error($lang->get("LANG_ACP_GLOBAL_ERROR_NORESULT"));
// read permissions
$permissioncache=getPermissions();
// read boardoptions
$boardcache=array();
$result = $db->unbuffered_query("SELECT boardid, parentid, boardorder, title FROM bb".$n."_boards ORDER by parentid ASC, boardorder ASC");
while ($row = $db->fetch_array($result)) {
if(!isset($permissioncache[$row['boardid']]['can_view_board'])) $permissioncache[$row['boardid']]['can_view_board']=-1;
if($permissioncache[$row['boardid']]['can_view_board']==0 || ($permissioncache[$row['boardid']]['can_view_board']==-1 && !$wbbuserdata['can_view_board'])) continue;
$row['title'] = getlangvar($row['title'], $lang);
$boardcache[$row['parentid']][$row['boardorder']][$row['boardid']] = $row;
}
$boardid_options = makeboardoptions(0);
// read in modpermissions
$board = $db->query_first("SELECT *,userid as moderatorid FROM bb".$n."_moderators WHERE userid='".$wbbuserdata['userid']."' AND boardid='".$boardid."'");
$result=$db->query("SELECT threadid, topic FROM bb".$n."_threads WHERE threadid IN (0$threadids)");
if(!$db->num_rows($result)) acp_error($lang->get("LANG_ACP_GLOBAL_ERROR_NORESULT"));
$threadbit1="";
$threadbit2="";
$threadbit3="";
$count1=0;
$count2=0;
$count3=0;
while($row=$db->fetch_array($result)) {
$row['topic']=htmlconverter($row['topic']);
if($threadaction[$row['threadid']]=="del") {
if(!checkmodpermissions("m_can_thread_del")) continue;
$rowclass=getone($count1++,"firstrow","secondrow");
eval ("\$threadbit1 .= \"".$tpl->get("threads_spindelbit",1)."\";");
}
if($threadaction[$row['threadid']]=="move") {
if(!checkmodpermissions("m_can_thread_move")) continue;
$rowclass=getone($count2++,"firstrow","secondrow");
eval ("\$threadbit2 .= \"".$tpl->get("threads_spinmovebit",1)."\";");
}
if($threadaction[$row['threadid']]=="close") {
if(!checkmodpermissions("m_can_thread_close")) continue;
$rowclass=getone($count3++,"firstrow","secondrow");
eval ("\$threadbit3 .= \"".$tpl->get("threads_spinclosebit",1)."\";");
}
}
eval("\$tpl->output(\"".$tpl->get("threads_spinverify",1)."\",1);");
}
/** moderate threads **/
if($action=="moderate") {
checkAdminPermissions("a_can_threads_moderate",1);
if(isset($_POST['send'])) {
if(isset($_POST['setvisible']) && is_array($_POST['setvisible']) && count($_POST['setvisible'])) {
$lang->load("MAIL");
unset($defaultlangpackid);
$langpacks = array();
$langpacks[$lang->languagepackid]=$lang;
$threadids=implode(",",$_POST['setvisible']);
// is super mod?
$boardids="";
if($wbbuserdata['m_is_supermod']==0) {
$result=$db->query("SELECT boardid FROM bb".$n."_moderators WHERE userid='".$wbbuserdata['userid']."'");
while($row=$db->fetch_array($result)) $boardids .= ",".$row['boardid'];
}
// get threads
$threads=$db->query("SELECT t.topic, t.boardid, t.starttime, t.threadid, t.starter, " .
"b.parentlist, b.countuserposts, b.lastposttime, b.title, " .
"u.rankgroupid, u.userposts, u.gender, u.rankid, u.userid " .
"FROM bb".$n."_threads t " .
"LEFT JOIN bb".$n."_boards b ON (t.boardid=b.boardid) " .
"LEFT JOIN bb".$n."_users u ON (u.userid=t.starterid) " .
"WHERE t.threadid IN (".$threadids.")" . (($wbbuserdata['m_is_supermod']==0) ? (" AND t.boardid IN (0".$boardids.")") : ("")) );
while($thread=$db->fetch_array($threads)) {
// update board counter
$db->unbuffered_query("UPDATE bb".$n."_boards SET threadcount=threadcount+1, postcount=postcount+1 WHERE boardid IN ($thread[parentlist],$thread[boardid])",1);
// update global stats
$db->unbuffered_query("UPDATE bb".$n."_stats SET threadcount=threadcount+1, postcount=postcount+1",1);
// update userposts
if($thread['countuserposts']==1 && $thread['userid']) {
$thread['userposts']+=1;
list($rankid)=$db->query_first("SELECT rankid FROM bb".$n."_ranks WHERE groupid IN ('0','$thread[rankgroupid]') AND needposts<='$thread[userposts]' AND gender IN ('0','$thread[gender]') ORDER BY needposts DESC, gender DESC",1);
$db->unbuffered_query("UPDATE bb".$n."_users SET userposts=userposts+1".(($rankid!=$thread['rankid']) ? (", rankid='$rankid'") : (""))." WHERE userid = '$thread[userid]'",1);
checkPosts4AI();
}
// set thread & post visible
$db->unbuffered_query("UPDATE bb".$n."_threads SET visible=1 WHERE threadid IN ($threadids)");
$db->unbuffered_query("UPDATE bb".$n."_posts SET visible=1 WHERE threadid IN ($threadids)");
// update board lastpostinfo
if($thread['lastposttime']<$thread['starttime']) {
$result = $db->query("SELECT boardid, childlist FROM bb".$n."_boards WHERE boardid IN ($thread[boardid],$thread[parentlist]) AND lastposttime<'$thread[starttime]'");
while($row=$db->fetch_array($result)) {
$lastpost=$db->query_first("SELECT p.threadid, p.userid, p.username, p.posttime FROM bb".$n."_posts p, bb".$n."_threads t WHERE p.threadid=t.threadid AND p.visible = 1 AND t.boardid IN ($row[boardid],$row[childlist]) ORDER BY p.posttime DESC",1);
$db->unbuffered_query("UPDATE bb".$n."_boards SET lastthreadid='$lastpost[threadid]', lastposttime='$lastpost[posttime]', lastposterid='$lastpost[userid]', lastposter='".addslashes($lastpost['username'])."' WHERE boardid='$row[boardid]'",1);
}
}
// subscriptions
$topic=$thread['topic'];
$threadid=$thread['threadid'];
$wbbuserdata['username']=$thread['starter'];
$result=$db->query("SELECT u.email, u.username, s.countemails, l.languagepackid FROM bb".$n."_subscribeboards s LEFT JOIN bb".$n."_users u USING(userid) LEFT JOIN bb".$n."_languagepacks l ON(l.languagepackid=u.langid) WHERE s.boardid='$thread[boardid]' AND s.userid<>'$thread[userid]' AND s.emailnotify=1 AND s.countemails<'$maxnotifymails' AND u.email is not null");
while($row=$db->fetch_array($result)) {
if(!isset($langpacks[$row['languagepackid']])) {
$langpacks[$row['languagepackid']]=new language(intval($row['languagepackid']));
$langpacks[$row['languagepackid']]->load("OWN,MAIL");
}
$master_board_name = getlangvar($o_master_board_name, $langpacks[$row['languagepackid']], 0);
$board['title']=getlangvar($thread['title'], $langpacks[$row['languagepackid']], 0);
eval ("\$mail_subject = \"".$langpacks[$row['languagepackid']]->get4eval("LANG_MAIL_NEWTHREAD_SUBJECT")."\";");
eval ("\$mail_text = \"".$langpacks[$row['languagepackid']]->get4eval("LANG_MAIL_NEWTHREAD_TEXT")."\";");
mailer($row['email'],$mail_subject,$mail_text);
}
$db->unbuffered_query("UPDATE bb".$n."_subscribeboards SET countemails=countemails+1 WHERE boardid='$thread[boardid]' AND userid<>'$thread[userid]' AND emailnotify=1 AND countemails<'$maxnotifymails'",1);
}
}
}
// is super mod?
if($wbbuserdata['m_is_supermod']==0) {
$boardids="";
$result=$db->query("SELECT boardid FROM bb".$n."_moderators WHERE userid='".$wbbuserdata['userid']."'");
while($row=$db->fetch_array($result)) $boardids .= ",".$row['boardid'];
$result=$db->query("SELECT threadid, topic, starter, starterid FROM bb".$n."_threads WHERE visible=0 AND boardid IN (0".$boardids.") ORDER BY starttime DESC");
}
else $result=$db->query("SELECT threadid, topic, starter, starterid FROM bb".$n."_threads WHERE visible=0 ORDER BY starttime DESC");
$threadbit="";
$count=0;
while($row=$db->fetch_array($result)) {
$rowclass=getone($count++,"firstrow","secondrow");
$row['starter']=htmlconverter($row['starter']);
$row['topic']=htmlconverter($row['topic']);
if($row['starterid']!=0) $row['starter']=makehreftag("../profile.php?userid=$row[starterid]",$row['starter'],"_blank");
eval ("\$threadbit .= \"".$tpl->get("threads_moderatebit",1)."\";");
}
eval("\$tpl->output(\"".$tpl->get("threads_moderate",1)."\",1);");
}
/** moderate posts **/
if($action=="moderateposts") {
checkAdminPermissions("a_can_threads_moderate_posts",1);
if(isset($_POST['send'])) {
if(isset($_POST['setvisible']) && is_array($_POST['setvisible']) && count($_POST['setvisible'])) {
$lang->load("MAIL");
unset($defaultlangpackid);
$langpacks = array();
$langpacks[$lang->languagepackid]=$lang;
$postids=implode(",",$_POST['setvisible']);
// is super mod?
$boardids="";
if($wbbuserdata['m_is_supermod']==0) {
$result=$db->query("SELECT boardid FROM bb".$n."_moderators WHERE userid='".$wbbuserdata['userid']."'");
while($row=$db->fetch_array($result)) $boardids .= ",".$row['boardid'];
}
$posts=$db->query("SELECT p.postid, p.posttime, p.userid, p.username, p.threadid, " .
"t.topic, t.boardid, t.lastposttime, " .
"b.parentlist, b.countuserposts, b.lastposttime as blastposttime, b.title, " .
"u.rankgroupid, u.userposts, u.gender, u.rankid, u.userid " .
"FROM bb".$n."_posts p " .
"LEFT JOIN bb".$n."_users u USING (userid) " .
"LEFT JOIN bb".$n."_threads t ON (t.threadid=p.threadid) " .
"LEFT JOIN bb".$n."_boards b ON (t.boardid=b.boardid) " .
"WHERE p.postid IN ($postids)" . (($wbbuserdata['m_is_supermod']==0) ? (" AND t.boardid IN (0".$boardids.")") : ("")) );
while($post=$db->fetch_array($posts)) {
// update thread
if($post['posttime']>$post['lastposttime']) $db->unbuffered_query("UPDATE bb".$n."_threads SET lastposttime = '$post[posttime]', lastposterid = '$post[userid]', lastposter = '".addslashes($post['username'])."', replycount = replycount+1 WHERE threadid = '$post[threadid]'",1);
else $db->unbuffered_query("UPDATE bb".$n."_threads SET replycount = replycount+1 WHERE threadid = '$post[threadid]'",1);
// update board counter
$db->unbuffered_query("UPDATE bb".$n."_boards SET postcount=postcount+1 WHERE boardid IN ($post[parentlist],$post[boardid])",1);
// update global stats
$db->unbuffered_query("UPDATE bb".$n."_stats SET postcount=postcount+1",1);
// update userposts
if($post['countuserposts']==1 && $post['userid']) {
$post['userposts']+=1;
list($rankid)=$db->query_first("SELECT rankid FROM bb".$n."_ranks WHERE groupid IN ('0','$post[rankgroupid]') AND needposts<='$post[userposts]' AND gender IN ('0','$post[gender]') ORDER BY needposts DESC, gender DESC",1);
$db->unbuffered_query("UPDATE bb".$n."_users SET userposts=userposts+1".(($rankid!=$post['rankid']) ? (", rankid='$rankid'") : (""))." WHERE userid = '$post[userid]'",1);
checkPosts4AI();
}
// set post visible
$db->unbuffered_query("UPDATE bb".$n."_posts SET visible=1 WHERE postid IN ($postids)");
// update board lastpostinfo
if($post['blastposttime']<$post['posttime']) {
$result = $db->query("SELECT boardid, childlist FROM bb".$n."_boards WHERE boardid IN ($post[boardid],$post[parentlist]) AND lastposttime<'$post[posttime]'");
while($row=$db->fetch_array($result)) {
$lastpost=$db->query_first("SELECT p.threadid, p.userid, p.username, p.posttime FROM bb".$n."_posts p, bb".$n."_threads t WHERE p.threadid=t.threadid AND p.visible = 1 AND t.boardid IN ($row[boardid],$row[childlist]) ORDER BY p.posttime DESC",1);
$db->unbuffered_query("UPDATE bb".$n."_boards SET lastthreadid='$lastpost[threadid]', lastposttime='$lastpost[posttime]', lastposterid='$lastpost[userid]', lastposter='".addslashes($lastpost[username])."' WHERE boardid='$row[boardid]'",1);
}
}
// subscriptions
$thread['topic']=$post['topic'];
$postid=$post['postid'];
$wbbuserdata['username']=$post['username'];
$result=$db->query("SELECT u.email, u.username, s.countemails, l.languagepackid FROM bb".$n."_subscribethreads s LEFT JOIN bb".$n."_users u USING(userid) LEFT JOIN bb".$n."_languagepacks l ON(l.languagepackid=u.langid) WHERE s.threadid='$post[threadid]' AND s.userid<>'$post[userid]' AND s.emailnotify=1 AND s.countemails<'$maxnotifymails' AND u.email is not null");
while($row=$db->fetch_array($result)) {
if(!isset($langpacks[$row['languagepackid']])) {
$langpacks[$row['languagepackid']]=new language(intval($row['languagepackid']));
$langpacks[$row['languagepackid']]->load("OWN,MAIL");
}
$master_board_name = getlangvar($o_master_board_name, $langpacks[$row['languagepackid']], 0);
eval ("\$mail_subject = \"".$langpacks[$row['languagepackid']]->get4eval("LANG_MAIL_NEWPOST_SUBJECT")."\";");
eval ("\$mail_text = \"".$langpacks[$row['languagepackid']]->get4eval("LANG_MAIL_NEWPOST_TEXT")."\";");
mailer($row['email'],$mail_subject,$mail_text);
}
$db->unbuffered_query("UPDATE bb".$n."_subscribethreads SET countemails=countemails+1 WHERE threadid='$post[threadid]' AND userid<>'$post[userid]' AND emailnotify=1 AND countemails<'$maxnotifymails'",1);
}
}
}
// is super mod?
if($wbbuserdata['m_is_supermod']==0) {
$boardids="";
$result=$db->query("SELECT boardid FROM bb".$n."_moderators WHERE userid='".$wbbuserdata['userid']."'");
while($row=$db->fetch_array($result)) $boardids .= ",".$row['boardid'];
$result=$db->query("SELECT t.topic, p.username, p.userid, p.postid FROM bb".$n."_posts p, bb".$n."_threads t WHERE t.threadid=p.threadid AND t.visible=1 AND p.visible=0 AND t.boardid IN (0".$boardids.") ORDER BY posttime DESC");
}
else $result=$db->query("SELECT t.topic, p.username, p.userid, p.postid FROM bb".$n."_posts p, bb".$n."_threads t WHERE t.threadid=p.threadid AND t.visible=1 AND p.visible=0 ORDER BY posttime DESC");
$postbit="";
$count=0;
while($row=$db->fetch_array($result)) {
$rowclass=getone($count++,"firstrow","secondrow");
$row['username']=htmlconverter($row['username']);
$row['topic']=htmlconverter($row['topic']);
if($row['userid']!=0) $row['username']=makehreftag("../profile.php?userid=$row[userid]",$row['username'],"_blank");
eval ("\$postbit .= \"".$tpl->get("threads_moderatepostsbit",1)."\";");
}
eval("\$tpl->output(\"".$tpl->get("threads_moderateposts",1)."\",1);");
}
?> |