root/ip/trunk/modcp.php

154157
27
include_once(IP_ROOT_PATH . 'includes/functions_admin.' . PHP_EXT);
27
include_once(IP_ROOT_PATH . 'includes/functions_admin.' . PHP_EXT);
28
include_once(IP_ROOT_PATH . 'includes/functions_post.' . PHP_EXT);
28
include_once(IP_ROOT_PATH . 'includes/functions_post.' . PHP_EXT);
29
29
30
include(IP_ROOT_PATH . 'includes/class_mcp.' . PHP_EXT);
31
$mcp_topic = new class_mcp_topic();
32
30
@include_once(IP_ROOT_PATH . 'includes/class_topics.' . PHP_EXT);
33
@include_once(IP_ROOT_PATH . 'includes/class_topics.' . PHP_EXT);
31
$class_topics = new class_topics();
34
$class_topics = new class_topics();
32
35
...
...
241
	redirect(append_sid($redirect, true));
244
	redirect(append_sid($redirect, true));
242
}
245
}
243
246
244
if(!function_exists('find_names'))
245
{
246
	function find_names($id)
247
	{
248
		global $db;
249
250
		$sql = "SELECT forum_name FROM " . FORUMS_TABLE . " WHERE forum_id = $id";
251
		$result = $db->sql_query($sql);
252
		$row = $db->sql_fetchrow($result);
253
		return $row['forum_name'];
254
	}
255
}
256
257
if (!($mode == 'quick_title_edit'))
247
if (!($mode == 'quick_title_edit'))
258
{
248
{
259
	$is_auth = auth(AUTH_ALL, $forum_id, $userdata);
249
	$is_auth = auth(AUTH_ALL, $forum_id, $userdata);
...
...
301
291
302
		if($confirm)
292
		if($confirm)
303
		{
293
		{
304
			include(IP_ROOT_PATH . 'includes/functions_search.' . PHP_EXT);
305
306
			$topics = (isset($_POST['topic_id_list'])) ? $_POST['topic_id_list'] : array($topic_id);
294
			$topics = (isset($_POST['topic_id_list'])) ? $_POST['topic_id_list'] : array($topic_id);
307
			$topic_id_sql = '';
295
			$mcp_topic->topic_delete($topics, $forum_id);
308
			for($i = 0; $i < sizeof($topics); $i++)
309
			{
310
				$topic_id_sql .= (($topic_id_sql != '') ? ', ' : '') . intval($topics[$i]);
311
			}
312
296
313
			$sql = "SELECT topic_id FROM " . TOPICS_TABLE . " WHERE topic_id IN ($topic_id_sql) AND forum_id = $forum_id";
314
			$result = $db->sql_query($sql);
315
316
			$topic_id_sql = '';
317
			while($row = $db->sql_fetchrow($result))
318
			{
319
				$topic_id_sql .= (($topic_id_sql != '') ? ', ' : '') . intval($row['topic_id']);
320
			}
321
			if ($topic_id_sql == '')
322
			{
323
				message_die(GENERAL_MESSAGE, $lang['None_selected']);
324
			}
325
			$db->sql_freeresult($result);
326
327
			$sql = "SELECT poster_id, COUNT(post_id) AS posts FROM " . POSTS_TABLE . "
328
				WHERE topic_id IN ($topic_id_sql) GROUP BY poster_id";
329
			$result = $db->sql_query($sql);
330
331
			$count_sql = array();
332
			while($row = $db->sql_fetchrow($result))
333
			{
334
				$count_sql[] = "UPDATE " . USERS_TABLE . " SET user_posts = user_posts - " . $row['posts'] . " WHERE user_id = " . $row['poster_id'];
335
			}
336
			$db->sql_freeresult($result);
337
338
			if(sizeof($count_sql))
339
			{
340
				for($i = 0; $i < sizeof($count_sql); $i++)
341
				{
342
					$db->sql_query($count_sql[$i]);
343
				}
344
			}
345
346
			$sql = "SELECT post_id FROM " . POSTS_TABLE . " WHERE topic_id IN ($topic_id_sql)";
347
			$result = $db->sql_query($sql);
348
349
			$post_id_sql = '';
350
			while($row = $db->sql_fetchrow($result))
351
			{
352
				$post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($row['post_id']);
353
			}
354
			$db->sql_freeresult($result);
355
356
			$sql = "SELECT vote_id FROM " . VOTE_DESC_TABLE . " WHERE topic_id IN ($topic_id_sql)";
357
			$result = $db->sql_query($sql);
358
359
			$vote_id_sql = '';
360
			while($row = $db->sql_fetchrow($result))
361
			{
362
				$vote_id_sql .= (($vote_id_sql != '') ? ', ' : '') . $row['vote_id'];
363
			}
364
			$db->sql_freeresult($result);
365
366
			$sql = "DELETE FROM " . TOPICS_TABLE . " WHERE topic_id IN ($topic_id_sql) OR topic_moved_id IN ($topic_id_sql)";
367
			$db->sql_transaction('begin');
368
			$db->sql_query($sql);
369
370
			$sql = "DELETE FROM " . THANKS_TABLE . "
371
					WHERE topic_id IN ($topic_id_sql)";
372
			$db->sql_query($sql);
373
374
			$sql = "DELETE FROM " . BOOKMARK_TABLE . "
375
				WHERE topic_id IN ($topic_id_sql)";
376
			$db->sql_query($sql);
377
378
			// Event Registration - BEGIN
379
			$sql = "DELETE FROM " . REGISTRATION_TABLE . " WHERE topic_id IN ($topic_id_sql)";
380
			$db->sql_query($sql);
381
382
			$sql = "DELETE FROM " . REGISTRATION_DESC_TABLE . " WHERE topic_id IN ($topic_id_sql)";
383
			$db->sql_query($sql);
384
			// Event Registration - END
385
386
			if($post_id_sql != '')
387
			{
388
				$sql = "DELETE FROM " . POSTS_TABLE . " WHERE post_id IN ($post_id_sql)";
389
				$db->sql_query($sql);
390
391
				remove_search_post($post_id_sql);
392
			}
393
394
			if($vote_id_sql != '')
395
			{
396
				$sql = "DELETE FROM " . VOTE_DESC_TABLE . " WHERE vote_id IN ($vote_id_sql)";
397
				$db->sql_query($sql);
398
399
				$sql = "DELETE FROM " . VOTE_RESULTS_TABLE . " WHERE vote_id IN ($vote_id_sql)";
400
				$db->sql_query($sql);
401
402
				$sql = "DELETE FROM " . VOTE_USERS_TABLE . " WHERE vote_id IN ($vote_id_sql)";
403
				$db->sql_query($sql);
404
			}
405
406
			$sql = "DELETE FROM " . TOPICS_WATCH_TABLE . " WHERE topic_id IN ($topic_id_sql)";
407
			$db->sql_query($sql);
408
			$db->sql_transaction('commit');
409
410
			if(!empty($topic_id))
297
			if(!empty($topic_id))
411
			{
298
			{
412
				$redirect_page = CMS_PAGE_VIEWFORUM . '?' . POST_FORUM_URL . '=' . $forum_id . '&amp;sid=' . $userdata['session_id'];
299
				$redirect_page = CMS_PAGE_VIEWFORUM . '?' . POST_FORUM_URL . '=' . $forum_id . '&amp;sid=' . $userdata['session_id'];
...
...
421
			$redirect_url = $redirect_page;
308
			$redirect_url = $redirect_page;
422
			meta_refresh(3, $redirect_url);
309
			meta_refresh(3, $redirect_url);
423
310
424
			empty_cache_folders(POSTS_CACHE_FOLDER);
425
			empty_cache_folders(FORUMS_CACHE_FOLDER);
426
			sync('forum', $forum_id);
427
428
			message_die(GENERAL_MESSAGE, ((sizeof($topics) == '1') ? $lang['Mod_CP_topic_removed'] : $lang['Topics_Removed']) . '<br /><br />' .
$l_redirect);
311
			message_die(GENERAL_MESSAGE, ((sizeof($topics) == '1') ? $lang['Mod_CP_topic_removed'] : $lang['Topics_Removed']) . '<br /><br />' .
$l_redirect);
429
		}
312
		}
430
		else
313
		else
...
...
472
		if($confirm)
355
		if($confirm)
473
		{
356
		{
474
			$topics = (isset($_POST['topic_id_list'])) ? $_POST['topic_id_list'] : array($topic_id);
357
			$topics = (isset($_POST['topic_id_list'])) ? $_POST['topic_id_list'] : array($topic_id);
475
			$topic_id_sql = '';
358
			$mcp_topic->topic_poll_delete($topics);
476
			for($i = 0; $i < sizeof($topics); $i++)
477
			{
478
				$topic_id_sql .= (($topic_id_sql != '') ? ', ' : '') . intval($topics[$i]);
479
			}
480
359
481
			$sql = "UPDATE " . TOPICS_TABLE . " SET topic_vote = '0' WHERE topic_id IN ($topic_id_sql)";
482
			$result = $db->sql_query($sql);
483
484
			$sql = "SELECT vote_id FROM " . VOTE_DESC_TABLE . " WHERE topic_id IN ($topic_id_sql)";
485
			$result = $db->sql_query($sql);
486
487
			$vote_id_sql = '';
488
			while($row = $db->sql_fetchrow($result))
489
			{
490
				$vote_id_sql .= (($vote_id_sql != '') ? ', ' : '') . $row['vote_id'];
491
			}
492
			$db->sql_freeresult($result);
493
494
			if($vote_id_sql != '')
495
			{
496
				$sql = "DELETE FROM " . VOTE_DESC_TABLE . " WHERE vote_id IN ($vote_id_sql)";
497
				$db->sql_query($sql);
498
499
				$sql = "DELETE FROM " . VOTE_RESULTS_TABLE . " WHERE vote_id IN ($vote_id_sql)";
500
				$db->sql_query($sql);
501
502
				$sql = "DELETE FROM " . VOTE_USERS_TABLE . " WHERE vote_id IN ($vote_id_sql)";
503
				$db->sql_query($sql);
504
			}
505
506
			$redirect_page = 'modcp.' . PHP_EXT . '?' . POST_FORUM_URL . '=' . $forum_id . '&amp;sid=' . $userdata['session_id'];
360
			$redirect_page = 'modcp.' . PHP_EXT . '?' . POST_FORUM_URL . '=' . $forum_id . '&amp;sid=' . $userdata['session_id'];
507
			$l_redirect = sprintf($lang['Click_return_modcp'], '<a href="'. $redirect_page .'">', '</a>') .'<br /><br />'.
sprintf($lang['Click_return_forum'], '<a href="'. CMS_PAGE_VIEWFORUM . '?' . POST_FORUM_URL . '=' . $forum_id . '&amp;sid=' .
$userdata['session_id'] .'">', '</a>');
361
			$l_redirect = sprintf($lang['Click_return_modcp'], '<a href="'. $redirect_page .'">', '</a>') .'<br /><br />'.
sprintf($lang['Click_return_forum'], '<a href="'. CMS_PAGE_VIEWFORUM . '?' . POST_FORUM_URL . '=' . $forum_id . '&amp;sid=' .
$userdata['session_id'] .'">', '</a>');
508
362
509
			$redirect_url = $redirect_page;
363
			$redirect_url = $redirect_page;
510
			meta_refresh(3, $redirect_url);
364
			meta_refresh(3, $redirect_url);
511
365
512
			empty_cache_folders(POSTS_CACHE_FOLDER);
513
514
			message_die(GENERAL_MESSAGE, ((sizeof($topics) == '1') ? $lang['Mod_CP_poll_removed'] : $lang['Mod_CP_polls_removed']) .'<br /><br />'.
$l_redirect);
366
			message_die(GENERAL_MESSAGE, ((sizeof($topics) == '1') ? $lang['Mod_CP_poll_removed'] : $lang['Mod_CP_polls_removed']) .'<br /><br />'.
$l_redirect);
515
		}
367
		}
516
		else
368
		else
...
...
552
404
553
		if($confirm)
405
		if($confirm)
554
		{
406
		{
555
			$new_forum_id = intval($_POST['new_forum']);
407
			$topics = (isset($_POST['topic_id_list'])) ?  $_POST['topic_id_list'] : array($topic_id);
556
			$fid = $_POST['new_forum'];
408
			$new_forum_id = $_POST['new_forum'];
557
			if ($fid == 'Root')
409
			if ($mcp_topic->topic_move($topics, $forum_id, $new_forum_id, isset($_POST['move_leave_shadow'])))
558
			{
410
			{
559
				$type = POST_CAT_URL;
411
				$message = ((sizeof($topics) == '1') ? sprintf($lang['Mod_CP_topic_moved'], $mcp_topic->find_names($forum_id), $mcp_topic->find_names($new_forum_id)) : sprintf($lang['Mod_CP_topics_moved'], $mcp_topic->find_names($forum_id), $mcp_topic->find_names($new_forum_id))) .'<br /><br />';
560
				$new_forum_id = 0;
561
			}
412
			}
562
			else
413
			else
563
			{
414
			{
564
				$type = substr($fid, 0, 1);
565
				$new_forum_id = ($type == POST_FORUM_URL) ? intval(substr($fid, 1)) : 0;
566
			}
567
			if ($new_forum_id <= 0)
568
			{
569
				message_die(GENERAL_MESSAGE, $lang['Forum_not_exist']);
570
			}
571
			$old_forum_id = $forum_id;
572
			if($new_forum_id != $old_forum_id)
573
			{
574
				$topics = (isset($_POST['topic_id_list'])) ?  $_POST['topic_id_list'] : array($topic_id);
575
				$topic_list = '';
576
				for($i = 0; $i < sizeof($topics); $i++)
577
				{
578
					$topic_list .= (($topic_list != '') ? ', ' : '') . intval($topics[$i]);
579
				}
580
581
				$sql = "SELECT * FROM " . TOPICS_TABLE . "
582
					WHERE topic_id IN ($topic_list) AND forum_id = $old_forum_id AND topic_status <> " . TOPIC_MOVED;
583
				$result = $db->sql_query($sql);
584
				$row = $db->sql_fetchrowset($result);
585
				$db->sql_freeresult($result);
586
587
				$db->sql_transaction('begin');
588
589
				for($i = 0; $i < sizeof($row); $i++)
590
				{
591
					$topic_id = $row[$i]['topic_id'];
592
					if(isset($_POST['move_leave_shadow']))
593
					{
594
						$sql = "INSERT INTO " . TOPICS_TABLE . " (forum_id, topic_title, topic_poster, topic_time, topic_status, topic_type, topic_vote, topic_views, topic_replies, topic_first_post_id, topic_last_post_id, topic_moved_id)
595
							VALUES ($old_forum_id, '" . addslashes(str_replace("\'", "''", $row[$i]['topic_title'])) . "', '" . str_replace("\'", "''", $row[$i]['topic_poster']) . "', " . $row[$i]['topic_time'] . ", " . TOPIC_MOVED . ", " . POST_NORMAL . ", " . $row[$i]['topic_vote'] . ", " . $row[$i]['topic_views'] . ", " . $row[$i]['topic_replies'] . ", " . $row[$i]['topic_first_post_id'] . ", " . $row[$i]['topic_last_post_id'] . ", $topic_id)";
596
						$db->sql_query($sql);
597
					}
598
599
					$sql = "UPDATE " . TOPICS_TABLE . " SET forum_id = $new_forum_id WHERE topic_id = $topic_id";
600
					$db->sql_query($sql);
601
602
					$sql = "UPDATE " . POSTS_TABLE . " SET forum_id = $new_forum_id WHERE topic_id = $topic_id";
603
					$db->sql_query($sql);
604
				}
605
606
				$db->sql_transaction('commit');
607
608
				empty_cache_folders(POSTS_CACHE_FOLDER);
609
				empty_cache_folders(FORUMS_CACHE_FOLDER);
610
				sync_topic_details(0, 0, true, false);
611
				sync('forum', $new_forum_id);
612
				sync('forum', $old_forum_id);
613
				$message = ((sizeof($topics) == '1') ? sprintf($lang['Mod_CP_topic_moved'], find_names($old_forum_id), find_names($new_forum_id)) : sprintf($lang['Mod_CP_topics_moved'], find_names($old_forum_id), find_names($new_forum_id))) .'<br /><br />';
614
			}
615
			else
616
			{
617
				$message = $lang['No_Topics_Moved'] .'<br /><br />';
415
				$message = $lang['No_Topics_Moved'] .'<br /><br />';
618
			}
416
			}
619
417
...
...
683
		}
481
		}
684
482
685
		$topics = (isset($_POST['topic_id_list'])) ?  $_POST['topic_id_list'] : array($topic_id);
483
		$topics = (isset($_POST['topic_id_list'])) ?  $_POST['topic_id_list'] : array($topic_id);
686
		$topic_id_sql = '';
484
		$mcp_topic->topic_lock_unlock($topics, $mode, $forum_id);
687
		for($i = 0; $i < sizeof($topics); $i++)
688
		{
689
			$topic_id_sql .= (($topic_id_sql != '') ? ', ' : '') . intval($topics[$i]);
690
		}
691
485
692
		$sql = "UPDATE " . TOPICS_TABLE . " SET topic_status = " . (($mode == 'lock') ? TOPIC_LOCKED : TOPIC_UNLOCKED) . "
693
			WHERE topic_id IN ($topic_id_sql) AND forum_id = $forum_id AND topic_moved_id = 0";
694
		$result = $db->sql_query($sql);
695
696
		if(!empty($topic_id))
486
		if(!empty($topic_id))
697
		{
487
		{
698
			$redirect_page = CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $topic_id . '&amp;sid=' . $userdata['session_id'];
488
			$redirect_page = CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $topic_id . '&amp;sid=' . $userdata['session_id'];
...
...
707
		$redirect_url = $redirect_page;
497
		$redirect_url = $redirect_page;
708
		meta_refresh(3, $redirect_url);
498
		meta_refresh(3, $redirect_url);
709
499
710
		empty_cache_folders(POSTS_CACHE_FOLDER);
711
712
		if($mode == 'lock')
500
		if($mode == 'lock')
713
		{
501
		{
714
			message_die(GENERAL_MESSAGE, ((sizeof($topics) == '1') ? $lang['Mod_CP_topic_locked'] : $lang['Topics_Locked']) .'<br /><br />'. $message .
'<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . CMS_PAGE_VIEWFORUM . '?' . POST_FORUM_URL . '=' . $forum_id .
'&amp;sid=' . $userdata['session_id'] . '">', '</a>'));
502
			message_die(GENERAL_MESSAGE, ((sizeof($topics) == '1') ? $lang['Mod_CP_topic_locked'] : $lang['Topics_Locked']) .'<br /><br />'. $message .
'<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . CMS_PAGE_VIEWFORUM . '?' . POST_FORUM_URL . '=' . $forum_id .
'&amp;sid=' . $userdata['session_id'] . '">', '</a>'));
...
...
723
	case 'announce':
511
	case 'announce':
724
	case 'super_announce':
512
	case 'super_announce':
725
	case 'normalize':
513
	case 'normalize':
726
		if($mode == 'sticky' && !$is_auth['auth_sticky'])
727
		{
728
			$message = sprintf($lang['Sorry_auth_sticky'], $is_auth['auth_sticky_type']);
729
			message_die(GENERAL_MESSAGE, $message);
730
		}
731
		if($mode == 'announce' && !$is_auth['auth_announce'])
732
		{
733
			$message = sprintf($lang['Sorry_auth_announce'], $is_auth['auth_announce_type']);
734
			message_die(GENERAL_MESSAGE, $message);
735
		}
736
		if($mode == 'super_announce' && !$is_auth['auth_globalannounce'])
737
		{
738
			$message = sprintf($lang['Sorry_auth_announce'], $is_auth['auth_announce_type']);
739
			message_die(GENERAL_MESSAGE, $message);
740
		}
741
		if(empty($_POST['topic_id_list']) && empty($topic_id))
514
		if(empty($_POST['topic_id_list']) && empty($topic_id))
742
		{
515
		{
743
			message_die(GENERAL_MESSAGE, $lang['None_selected']);
516
			message_die(GENERAL_MESSAGE, $lang['None_selected']);
744
		}
517
		}
745
518
746
		$topics = (isset($_POST['topic_id_list'])) ?  $_POST['topic_id_list'] : array($topic_id);
519
		$topics = (isset($_POST['topic_id_list'])) ?  $_POST['topic_id_list'] : array($topic_id);
747
		$topic_id_sql = '';
520
		$mcp_topic->topic_switch_status($topics, $mode);
748
		for($i = 0; $i < sizeof($topics); $i++)
749
		{
750
			$topic_id_sql .= (($topic_id_sql != "") ? ', ' : '') . $topics[$i];
751
		}
752
521
753
		if($mode == 'sticky')
754
		{
755
			$topic_type = POST_STICKY;
756
		}
757
		elseif($mode == 'announce')
758
		{
759
			$topic_type = POST_ANNOUNCE;
760
		}
761
		elseif($mode == 'super_announce')
762
		{
763
			$topic_type = POST_GLOBAL_ANNOUNCE;
764
		}
765
		elseif($mode == 'normalize')
766
		{
767
			$topic_type = POST_NORMAL;
768
		}
769
		$sql = "UPDATE " . TOPICS_TABLE . " SET topic_type = " . $topic_type . " WHERE topic_id IN ($topic_id_sql) AND topic_moved_id = 0";
770
		$result = $db->sql_query($sql);
771
772
		if(!empty($topic_id))
522
		if(!empty($topic_id))
773
		{
523
		{
774
			$redirect_page = append_sid(CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $topic_id);
524
			$redirect_page = append_sid(CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $topic_id);
...
...
797
				$message = ((sizeof($topics) == '1') ? $lang['Mod_CP_topic_normalized'] : $lang['Mod_CP_topics_normalized']) .'<br /><br />'. $message; break;
547
				$message = ((sizeof($topics) == '1') ? $lang['Mod_CP_topic_normalized'] : $lang['Mod_CP_topics_normalized']) .'<br /><br />'. $message; break;
798
		}
548
		}
799
549
800
		empty_cache_folders(POSTS_CACHE_FOLDER);
801
802
		message_die(GENERAL_MESSAGE, $message);
550
		message_die(GENERAL_MESSAGE, $message);
803
		break;
551
		break;
552
804
	case 'merge':
553
	case 'merge':
805
		$meta_content['page_title'] = $lang['Mod_CP'] . ' (' . $lang['Merge_topic'] . ')';
554
		$meta_content['page_title'] = $lang['Mod_CP'] . ' (' . $lang['Merge_topic'] . ')';
806
555
...
...
817
			}
566
			}
818
567
819
			$new_topic_id = $_POST['new_topic'];
568
			$new_topic_id = $_POST['new_topic'];
820
			$topic_id_list = (isset($_POST['topic_id_list'])) ? $_POST['topic_id_list'] : array($topic_id);
569
			$topics = (isset($_POST['topic_id_list']) ? $_POST['topic_id_list'] : array($topic_id));
821
570
822
			$db->sql_transaction('begin');
571
			if(sizeof($topics) > 0)
823
824
			for ($i = 0; $i < sizeof($topic_id_list); $i++)
825
			{
572
			{
826
				$old_topic_id = $topic_id_list[$i];
573
				$mcp_topic->topic_merge($topics, $new_topic_id, $forum_id);
574
				$message = $lang['Topics_Merged'] . '<br /><br />';
575
			}
576
			else
577
			{
578
				$message = $lang['No_Topics_Merged'] . '<br /><br />';
579
			}
827
580
828
				if ($new_topic_id != $old_topic_id)
829
				{
830
					$sql = "UPDATE " . POSTS_TABLE . "
831
						SET topic_id = '" . $new_topic_id . "'
832
						WHERE topic_id = '" . $topic_id_list[$i] . "'";
833
					$result = $db->sql_query($sql);
834
835
//<!-- BEGIN Unread Post Information to Database Mod -->
836
					if($userdata['upi2db_access'])
837
					{
838
						/*
839
						$sql = "DELETE FROM " . UPI2DB_UNREAD_POSTS_TABLE . "
840
							WHERE topic_id IN ($topic_id_sql)";
841
						*/
842
						$sql = "DELETE FROM " . UPI2DB_UNREAD_POSTS_TABLE . "
843
							WHERE topic_id IN ($topic_id_list[$i])";
844
						$db->sql_query($sql);
845
846
						/*
847
						$sql = "DELETE FROM " . UPI2DB_LAST_POSTS_TABLE . "
848
							WHERE topic_id IN ($topic_id_sql)";
849
						*/
850
						$sql = "DELETE FROM " . UPI2DB_LAST_POSTS_TABLE . " WHERE topic_id IN ($topic_id_list[$i])";
851
						$db->sql_query($sql);
852
					}
853
//<!-- END Unread Post Information to Database Mod -->
854
855
					$sql = "DELETE FROM " . TOPICS_TABLE . " WHERE topic_id = $topic_id_list[$i]";
856
					$result = $db->sql_query($sql);
857
858
					$sql = "DELETE FROM  " . TOPICS_WATCH_TABLE . " WHERE topic_id = $topic_id_list[$i]";
859
					$result = $db->sql_query($sql);
860
861
					// Sync the forum indexes
862
					empty_cache_folders(POSTS_CACHE_FOLDER);
863
					empty_cache_folders(FORUMS_CACHE_FOLDER);
864
					sync('forum', $forum_id);
865
					sync('topic', $new_topic_id);
866
867
					$message = $lang['Topics_Merged'] . '<br /><br />';
868
				}
869
				else
870
				{
871
					$message = $lang['No_Topics_Merged'] . '<br /><br />';
872
				}
873
874
			} // end for
875
876
			$db->sql_transaction('commit');
877
878
			if (!empty($topic_id))
581
			if (!empty($topic_id))
879
			{
582
			{
880
				$redirect_page = CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $new_topic_id . '&amp;sid=' . $userdata['session_id'];
583
				$redirect_page = CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $new_topic_id . '&amp;sid=' . $userdata['session_id'];
...
...
941
			page_footer(true, '', true);
644
			page_footer(true, '', true);
942
		}
645
		}
943
		break;
646
		break;
647
944
	case 'split':
648
	case 'split':
945
		$meta_content['page_title'] = $lang['Mod_CP'] . ' (' . $lang['Split'] . ')';
649
		$meta_content['page_title'] = $lang['Mod_CP'] . ' (' . $lang['Split'] . ')';
946
650
947
		$post_id_sql = '';
651
		if((isset($_POST['split_type_all']) || isset($_POST['split_type_beyond'])) && isset($_POST['post_id_list']))
948
		if(isset($_POST['split_type_all']) || isset($_POST['split_type_beyond']))
949
		{
652
		{
950
			$posts = $_POST['post_id_list'];
653
			$posts = $_POST['post_id_list'];
951
			for($i = 0; $i < sizeof($posts); $i++)
654
			$fid = $_POST['new_forum_id'];
655
			$topic_id = $_POST[POST_TOPIC_URL];
656
			$split_beyond = (isset($_POST['split_type_beyond'])) ? true : false;
657
			$topic_subject = trim(htmlspecialchars($_POST['subject']));
658
			if(empty($topic_subject))
952
			{
659
			{
953
				$post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($posts[$i]);
660
			message_die(GENERAL_MESSAGE, $lang['Empty_subject']);
954
			}
661
			}
955
		}
956
662
957
		if($post_id_sql != '')
663
			$new_topic_id = $mcp_topic->topic_split($posts, $forum_id, $fid, $topic_id, $split_beyond, $topic_subject);
958
		{
664
			$redirect_url = CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $topic_id . '&amp;sid=' . $userdata['session_id'];
959
			$sql = "SELECT post_id FROM " . POSTS_TABLE . " WHERE post_id IN ($post_id_sql) AND forum_id = $forum_id";
665
			meta_refresh(3, $redirect_url);
960
			$result = $db->sql_query($sql);
961
666
962
			$post_id_sql = '';
667
			$message = $lang['Topic_split'] . '<br /><br />' . sprintf($lang['Mod_CP_click_return_topic'], '<a href="' . $redirect_url . '">', '</a>', '<a href="' . CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $new_topic_id . '&amp;sid=' . $userdata['session_id'] . '">', '</a>').'<br /><br />'. sprintf($lang['Click_return_modcp'], '<a href="modcp.' . PHP_EXT . '?' . POST_FORUM_URL . '=' . $forum_id . '&sid=' . $userdata['session_id'] .'">', '</a>').'<br /><br />'. sprintf($lang['Click_return_forum'], '<a href="'. CMS_PAGE_VIEWFORUM . '?' . POST_FORUM_URL . '=' . $forum_id . '&amp;sid=' . $userdata['session_id'] .'">', '</a>');
963
			while($row = $db->sql_fetchrow($result))
964
			{
965
				$post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($row['post_id']);
966
			}
967
			if ($post_id_sql == '')
968
			{
969
				message_die(GENERAL_MESSAGE, $lang['None_selected']);
970
			}
971
			$db->sql_freeresult($result);
972
668
973
			$sql = "SELECT post_id, poster_id, topic_id, post_time FROM " . POSTS_TABLE . "
669
			message_die(GENERAL_MESSAGE, $message);
974
				WHERE post_id IN ($post_id_sql) ORDER BY post_time ASC";
975
			$result = $db->sql_query($sql);
976
977
			if($row = $db->sql_fetchrow($result))
978
			{
979
				$first_poster = $row['poster_id'];
980
				$topic_id = $row['topic_id'];
981
				$post_time = $row['post_time'];
982
983
				$user_id_sql = '';
984
				$post_id_sql = '';
985
				do
986
				{
987
					$user_id_sql .= (($user_id_sql != '') ? ', ' : '') . intval($row['poster_id']);
988
					$post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($row['post_id']);;
989
				}
990
				while ($row = $db->sql_fetchrow($result));
991
992
				$post_subject = trim(htmlspecialchars($_POST['subject']));
993
				if(empty($post_subject))
994
				{
995
					message_die(GENERAL_MESSAGE, $lang['Empty_subject']);
996
				}
997
998
				$fid = $_POST['new_forum_id'];
999
				if ($fid == 'Root')
1000
				{
1001
					$type = POST_CAT_URL;
1002
					$new_forum_id = 0;
1003
				}
1004
				else
1005
				{
1006
					$type = substr($fid, 0, 1);
1007
					$new_forum_id = ($type == POST_FORUM_URL) ? intval(substr($fid, 1)) : 0;
1008
				}
1009
1010
				if ($new_forum_id <= 0)
1011
				{
1012
					message_die(GENERAL_MESSAGE, $lang['Forum_not_exist']);
1013
				}
1014
1015
				$topic_time = time();
1016
1017
				$sql  = "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type)
1018
					VALUES ('" . str_replace("\'", "''", $post_subject) . "', $first_poster, " . $topic_time . ", $new_forum_id, " . TOPIC_UNLOCKED . ", " . POST_NORMAL . ")";
1019
				$db->sql_transaction('begin');
1020
				$db->sql_query($sql);
1021
				$new_topic_id = $db->sql_nextid();
1022
1023
				$sql = "UPDATE " . TOPICS_WATCH_TABLE . " SET topic_id = $new_topic_id
1024
					WHERE topic_id = $topic_id AND user_id IN ($user_id_sql)";
1025
				$db->sql_query($sql);
1026
1027
				$sql_where = (!empty($_POST['split_type_beyond'])) ? " post_time >= $post_time AND topic_id = $topic_id" : "post_id IN ($post_id_sql)";
1028
				$sql = "UPDATE " . POSTS_TABLE . " SET topic_id = $new_topic_id, forum_id = $new_forum_id WHERE $sql_where";
1029
				$db->sql_query($sql);
1030
				$db->sql_transaction('commit');
1031
1032
//<!-- BEGIN Unread Post Information to Database Mod -->
1033
				$sql_where_upi = (!empty($_POST['split_type_beyond'])) ? " topic_id = $topic_id" : "post_id IN ($post_id_sql)";
1034
1035
				$sql = "UPDATE " . UPI2DB_LAST_POSTS_TABLE . "
1036
					SET topic_id = $new_topic_id, forum_id = $new_forum_id
1037
					WHERE $sql_where_upi";
1038
				$db->sql_query($sql);
1039
1040
				$sql = "UPDATE " . UPI2DB_UNREAD_POSTS_TABLE . "
1041
					SET topic_id = $new_topic_id, forum_id = $new_forum_id
1042
					WHERE $sql_where_upi";
1043
				$db->sql_query($sql);
1044
//<!-- END Unread Post Information to Database Mod -->
1045
1046
				empty_cache_folders(POSTS_CACHE_FOLDER);
1047
				empty_cache_folders(FORUMS_CACHE_FOLDER);
1048
				sync('topic', $new_topic_id);
1049
				sync('topic', $topic_id);
1050
				sync('forum', $new_forum_id);
1051
				sync('forum', $forum_id);
1052
1053
				$redirect_url = CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $topic_id . '&amp;sid=' . $userdata['session_id'];
1054
				meta_refresh(3, $redirect_url);
1055
1056
				$message = $lang['Topic_split'] . '<br /><br />' . sprintf($lang['Mod_CP_click_return_topic'], '<a href="' . $redirect_url . '">', '</a>', '<a href="' . CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $new_topic_id . '&amp;sid=' . $userdata['session_id'] . '">', '</a>').'<br /><br />'. sprintf($lang['Click_return_modcp'], '<a href="modcp.' . PHP_EXT . '?' . POST_FORUM_URL . '=' . $forum_id . '&sid=' . $userdata['session_id'] .'">', '</a>').'<br /><br />'. sprintf($lang['Click_return_forum'], '<a href="'. CMS_PAGE_VIEWFORUM . '?' . POST_FORUM_URL . '=' . $forum_id . '&amp;sid=' . $userdata['session_id'] .'">', '</a>');
1057
1058
				message_die(GENERAL_MESSAGE, $message);
1059
			}
1060
		}
670
		}
1061
		else
671
		else
1062
		{
672
		{
...
...
1231
		}
841
		}
1232
		$template->pparse('viewip');
842
		$template->pparse('viewip');
1233
		break;
843
		break;
844
1234
	case 'recycle':
845
	case 'recycle':
1235
		$meta_content['page_title'] = $lang['Mod_CP'];
846
		$meta_content['page_title'] = $lang['Mod_CP'];
1236
847
...
...
1249
			}
860
			}
1250
			elseif (isset($_POST['topic_id_list']))
861
			elseif (isset($_POST['topic_id_list']))
1251
			{
862
			{
1252
				// Define bin forum
863
				$topics = (isset($_POST['topic_id_list'])) ? $_POST['topic_id_list'] : array($topic_id);
1253
				$new_forum_id = intval($config['bin_forum']);
1254
				$old_forum_id = $forum_id;
1255
864
1256
				if ($new_forum_id != $old_forum_id)
865
				if($mcp_topic->topic_recycle($topics, $forum_id))
1257
				{
866
				{
1258
					$topics = (isset($_POST['topic_id_list'])) ?  $_POST['topic_id_list'] : array($topic_id);
1259
1260
					$topic_list = '';
1261
					for($i = 0; $i < sizeof($topics); $i++)
1262
					{
1263
						$topic_list .= (($topic_list != '') ? ', ' : '') . intval($topics[$i]);
1264
					}
1265
1266
					$sql = "SELECT *
1267
						FROM " . TOPICS_TABLE . "
1268
						WHERE topic_id IN (" . $topic_list . ")
1269
							AND forum_id = $old_forum_id
1270
							AND topic_status <> " . TOPIC_MOVED;
1271
					$result = $db->sql_query($sql);
1272
					$row = $db->sql_fetchrowset($result);
1273
					$db->sql_freeresult($result);
1274
1275
					$db->sql_transaction('begin');
1276
1277
					for($i = 0; $i < sizeof($row); $i++)
1278
					{
1279
						$topic_id = $row[$i]['topic_id'];
1280
1281
						if (isset($_POST['move_leave_shadow']))
1282
						{
1283
							// Insert topic in the old forum that indicates that the forum has moved.
1284
							$sql = "INSERT INTO " . TOPICS_TABLE . " (forum_id, topic_title, topic_poster, topic_time, topic_status, topic_type, topic_vote, topic_views, topic_replies, topic_first_post_id, topic_last_post_id, topic_moved_id)
1285
								VALUES ($old_forum_id, '" . addslashes(str_replace("\'", "''", $row[$i]['topic_title'])) . "', '" . str_replace("\'", "''", $row[$i]['topic_poster']) . "', " . $row[$i]['topic_time'] . ", " . TOPIC_MOVED . ", " . POST_NORMAL . ", " . $row[$i]['topic_vote'] . ", " . $row[$i]['topic_views'] . ", " . $row[$i]['topic_replies'] . ", " . $row[$i]['topic_first_post_id'] . ", " . $row[$i]['topic_last_post_id'] . ", $topic_id)";
1286
							$db->sql_query($sql);
1287
						}
1288
1289
						$sql = "UPDATE " . TOPICS_TABLE . "
1290
							SET forum_id = " . $new_forum_id . "
1291
							WHERE topic_id = " . $topic_id;
1292
						$db->sql_query($sql);
1293
1294
						$sql = "DELETE FROM " . TOPICS_WATCH_TABLE . " WHERE topic_id = " . $topic_id;
1295
						$db->sql_query($sql);
1296
1297
//<!-- BEGIN Unread Post Information to Database Mod -->
1298
						$sql = "UPDATE " . UPI2DB_LAST_POSTS_TABLE . "
1299
							SET forum_id = " . $new_forum_id . "
1300
							WHERE topic_id = " . $topic_id;
1301
						$db->sql_query($sql);
1302
1303
						$sql = "UPDATE " . UPI2DB_UNREAD_POSTS_TABLE . "
1304
							SET forum_id = " . $new_forum_id . "
1305
							WHERE topic_id = " . $topic_id;
1306
						$db->sql_query($sql);
1307
//<!-- END Unread Post Information to Database Mod -->
1308
1309
						$sql = "UPDATE " . POSTS_TABLE . "
1310
							SET forum_id = " . $new_forum_id . "
1311
							WHERE topic_id = " . $topic_id;
1312
						$db->sql_query($sql);
1313
					}
1314
1315
					$db->sql_transaction('commit');
1316
1317
					// Sync the forum indexes
1318
					empty_cache_folders(POSTS_CACHE_FOLDER);
1319
					empty_cache_folders(FORUMS_CACHE_FOLDER);
1320
					sync('forum', $new_forum_id);
1321
					sync('forum', $old_forum_id);
1322
1323
					$message = $lang['Topics_Moved_bin'];
867
					$message = $lang['Topics_Moved_bin'];
1324
				}
868
				}
1325
				else
869
				else
...
...
1347
			message_die(GENERAL_MESSAGE, $lang['None_selected']);
891
			message_die(GENERAL_MESSAGE, $lang['None_selected']);
1348
		}
892
		}
1349
893
1350
		$addon = str_replace('%mod%', addslashes($userdata['username']), $qt_row['title_info'] . ' ');
1351
		$dateqt = ($qt_row['date_format'] == '') ? create_date($config['default_dateformat'], time(), $config['board_timezone']) : create_date($qt_row['date_format'], time(), $config['board_timezone']);
1352
		$addon = str_replace('%date%', $dateqt, $addon);
1353
1354
		$topics = (isset($_POST['topic_id_list'])) ?  $_POST['topic_id_list'] : array($topic_id);
894
		$topics = (isset($_POST['topic_id_list'])) ?  $_POST['topic_id_list'] : array($topic_id);
895
		$mcp_topic->topic_quick_title_edit($topics, $qt_row);
1355
896
1356
		$topic_id_sql = '';
1357
		for($i = 0; $i < sizeof($topics); $i++)
1358
		{
1359
			$topic_id_sql .= (($topic_id_sql != "") ? ', ' : '') . $topics[$i];
1360
		}
1361
1362
		$sql = "UPDATE " . TOPICS_TABLE . "
1363
			SET title_compl_infos = '" . addslashes($addon) . "'
1364
			WHERE topic_id IN ($topic_id_sql)
1365
				AND topic_moved_id = 0";
1366
		$result = $db->sql_query($sql);
1367
1368
		if (!empty($topic_id))
897
		if (!empty($topic_id))
1369
		{
898
		{
1370
			$redirect_page = CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $topic_id . '&amp;sid=' . $userdata['session_id'];
899
			$redirect_page = CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $topic_id . '&amp;sid=' . $userdata['session_id'];
...
...
1381
		$redirect_url = $redirect_page;
910
		$redirect_url = $redirect_page;
1382
		meta_refresh(3, $redirect_url);
911
		meta_refresh(3, $redirect_url);
1383
912
1384
		empty_cache_folders(POSTS_CACHE_FOLDER);
1385
1386
		message_die(GENERAL_MESSAGE, $lang['Topics_Title_Edited'] . '<br /><br />' . $message);
913
		message_die(GENERAL_MESSAGE, $lang['Topics_Title_Edited'] . '<br /><br />' . $message);
1387
		break;
914
		break;
1388
915
...
...
1398
		}
925
		}
1399
926
1400
		$topics = (isset($_POST['topic_id_list'])) ?  $_POST['topic_id_list'] : array($topic_id);
927
		$topics = (isset($_POST['topic_id_list'])) ?  $_POST['topic_id_list'] : array($topic_id);
928
		$mcp_topic->topic_news_category_edit($topics, $news_category);
1401
929
1402
		$topic_id_sql = '';
1403
		for($i = 0; $i < sizeof($topics); $i++)
1404
		{
1405
			$topic_id_sql .= (($topic_id_sql != "") ? ', ' : '') . $topics[$i];
1406
		}
1407
1408
		$sql = "UPDATE " . TOPICS_TABLE . "
1409
			SET news_id = '" . $news_category . "'
1410
			WHERE topic_id IN ($topic_id_sql)
1411
				AND topic_moved_id = 0";
1412
		$result = $db->sql_query($sql);
1413
1414
		if (!empty($topic_id))
930
		if (!empty($topic_id))
1415
		{
931
		{
1416
			$redirect_page = CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $topic_id . '&amp;sid=' . $userdata['session_id'];
932
			$redirect_page = CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $topic_id . '&amp;sid=' . $userdata['session_id'];
...
...
1427
		$redirect_url = $redirect_page;
943
		$redirect_url = $redirect_page;
1428
		meta_refresh(3, $redirect_url);
944
		meta_refresh(3, $redirect_url);
1429
945
1430
		empty_cache_folders(POSTS_CACHE_FOLDER);
1431
1432
		message_die(GENERAL_MESSAGE, $lang['Category_Updated'] . '<br /><br />' . $message);
946
		message_die(GENERAL_MESSAGE, $lang['Category_Updated'] . '<br /><br />' . $message);
1433
		break;
947
		break;
1434
948
...
...
1477
		$template->assign_vars(array(
991
		$template->assign_vars(array(
1478
			'TOPIC_TYPES' => $topic_types,
992
			'TOPIC_TYPES' => $topic_types,
1479
			'TOPIC_COUNT' => ($forum_topics == '1') ? sprintf($lang['Mod_CP_topic_count'], $forum_topics) : sprintf($lang['Mod_CP_topics_count'], $forum_topics),
993
			'TOPIC_COUNT' => ($forum_topics == '1') ? sprintf($lang['Mod_CP_topic_count'], $forum_topics) : sprintf($lang['Mod_CP_topics_count'], $forum_topics),
1480
			'FORUM_NAME' => find_names($forum_id),
994
			'FORUM_NAME' => $mcp_topic->find_names($forum_id),
1481
			'SELECT_TITLE' => $select_title,
995
			'SELECT_TITLE' => $select_title,
1482
			'SELECT_NEWS_CATS' => $select_news_cats,
996
			'SELECT_NEWS_CATS' => $select_news_cats,
1483
997
...
...
1555
1069
1556
		$sql = "SELECT t.*, u.username, u.user_id, u.user_active, u.user_color, p.post_time, p.post_id, p.post_username, p.enable_smilies, u2.username AS
topic_starter, u2.user_id AS topic_starter_id, u2.user_active AS topic_starter_active, u2.user_color AS topic_starter_color, p2.post_id, p2.post_username AS
topic_starter_guest
1070
		$sql = "SELECT t.*, u.username, u.user_id, u.user_active, u.user_color, p.post_time, p.post_id, p.post_username, p.enable_smilies, u2.username AS
topic_starter, u2.user_id AS topic_starter_id, u2.user_active AS topic_starter_active, u2.user_color AS topic_starter_color, p2.post_id, p2.post_username AS
topic_starter_guest
1557
			FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . USERS_TABLE . " u2, " .
POSTS_TABLE . " p2
1071
			FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . USERS_TABLE . " u2, " .
POSTS_TABLE . " p2
1558
			WHERE t.forum_id = $forum_id
1072
			WHERE t.forum_id = " . $forum_id . "
1559
				AND p.poster_id = u.user_id
1073
				AND p.poster_id = u.user_id
1560
				AND t.topic_poster = u2.user_id
1074
				AND t.topic_poster = u2.user_id
1561
				AND p.post_id = t.topic_last_post_id
1075
				AND p.post_id = t.topic_last_post_id
1562
				AND p2.post_id = t.topic_first_post_id $where_type
1076
				AND p2.post_id = t.topic_first_post_id " . $where_type . "
1563
			ORDER BY t.topic_type DESC, p.post_time DESC LIMIT $start, " . $config['topics_per_page'];
1077
			ORDER BY t.topic_type DESC, p.post_time DESC LIMIT " . $start . ", " . $config['topics_per_page'];
1564
		$result = $db->sql_query($sql);
1078
		$result = $db->sql_query($sql);
1565
1079
1566
		$total_topics = 0;
1080
		$total_topics = 0;
...
...
1607
1121
1608
			$topic_link = $class_topics->build_topic_icon_link($forum_id, $topic_rowset[$i]['topic_id'], $topic_rowset[$i]['topic_type'],
$topic_rowset[$i]['topic_reg'], $topic_rowset[$i]['topic_replies'], $topic_rowset[$i]['news_id'], $topic_rowset[$i]['topic_vote'],
$topic_rowset[$i]['topic_status'], $topic_rowset[$i]['topic_moved_id'], $topic_rowset[$i]['post_time'], $user_replied, $replies, $is_unread);
1122
			$topic_link = $class_topics->build_topic_icon_link($forum_id, $topic_rowset[$i]['topic_id'], $topic_rowset[$i]['topic_type'],
$topic_rowset[$i]['topic_reg'], $topic_rowset[$i]['topic_replies'], $topic_rowset[$i]['news_id'], $topic_rowset[$i]['topic_vote'],
$topic_rowset[$i]['topic_status'], $topic_rowset[$i]['topic_moved_id'], $topic_rowset[$i]['post_time'], $user_replied, $replies, $is_unread);
1609
1123
1610
			$topic_id = $topic_link['topic_id'];
1124
			if (!$topic_rowset[$i]['topic_status'] == TOPIC_MOVED)
1125
			{
1126
				$topic_id = $topic_link['topic_id'];
1127
			}
1611
			$topic_id_append = $topic_link['topic_id_append'];
1128
			$topic_id_append = $topic_link['topic_id_append'];
1612
1129
1613
			if(($replies + 1) > $config['posts_per_page'])
1130
			if(($replies + 1) > $config['posts_per_page'])