www.gusucode.com > ShopEx481 & PHPWind 整合版码程序 > bbs/mawhole.php

    <?php
if (isset($_GET['ajax'])) {
	define('AJAX','1');
}
require_once('global.php');
require_once(R_P.'require/forum.php');
require_once(R_P.'require/updateforum.php');
require_once(R_P.'require/msg.php');
require_once(R_P.'require/writelog.php');
include_once(D_P.'data/bbscache/forum_cache.php');

!$windid && Showmsg('not_login');
InitGP(array('action','tidarray','seltid'));
if (!$tidarray && is_numeric($seltid)) {
	$tidarray = array($seltid);
}
if (!in_array($action,array('type','check','del','move','copy','headtopic','digest','lock','pushtopic', 'downtopic','edit','unite')) || empty($fid) || empty($tidarray)) {
	Showmsg('undefined_action');
}
$foruminfo = $db->get_one("SELECT * FROM pw_forums f LEFT JOIN pw_forumsextra fe USING(fid) WHERE f.fid='$fid' AND f.type<>'category'");
!$foruminfo && Showmsg('data_error');
wind_forumcheck($foruminfo);

list($db_moneyname,$db_moneyunit,$db_rvrcname,$db_rvrcunit,$db_creditname,$db_creditunit)=explode("\t",$db_credits);

if (CkInArray($windid,$manager) || admincheck($foruminfo['forumadmin'],$foruminfo['fupadmin'],$windid)) {
	$admincheck = 1;
} else {
	$admincheck = 0;
}
if (!$admincheck && $groupid != 5) {
	if ($SYSTEM['rightwhere'] && strpos(",".$SYSTEM['rightwhere'].",",",".$fid.",")===false) {
		Showmsg('rightwhere');
	}
	if ($action == "type" && $SYSTEM['tpctype']) {
		$admincheck = 1;
	} elseif ($action == "check" && $SYSTEM['check']) {
		$admincheck = 1;
	} elseif ($action == "del" && $SYSTEM['delatc']) {
		$admincheck = 1;
	} elseif ($action == "move" && $SYSTEM['moveatc']) {
		$admincheck = 1;
	} elseif ($action == "copy" && $SYSTEM['copyatc']) {
		$admincheck = 1;
	} elseif ($action == "headtopic" && $SYSTEM['topped']) {
		$admincheck = 1;
	} elseif (($action=="digest" || $action=="lock" || $action=="pushtopic" || $action=="edit" || $action=='downtopic') && $SYSTEM['typeadmin']) {
		$admincheck = 1;
	} elseif ($SYSTEM[$action]) {
		$admincheck = 1;
	}
}
!$admincheck && Showmsg('mawhole_right');

$mgdate		= get_date($timestamp,'Y-m-d');
$tids		= '';
$threaddb	= array();
$template	= 'ajax_mawhole';

if (empty($_POST['step'])) {
	$reason_sel = '';
	$reason_a   = explode("\n",$db_adminreason);
	foreach ($reason_a as $k=>$v) {
		if ($v=trim($v)) {
			$reason_sel .= "<option value=\"$v\">$v</option>";
		} else {
			$reason_sel .= "<option value=\"\">-------</option>";
		}
	}
	foreach ($tidarray as $k=>$v) {
		if (is_numeric($v)) {
			$tids .= $tids ? ','.$v :$v;
		}
	}
	if ($tids) {
		$query = $db->query("SELECT * FROM pw_threads WHERE tid IN($tids)");
		while ($rt = $db->fetch_array($query)) {
			if ($rt['fid'] != $fid && $groupid == 5) {
				Showmsg('admin_forum_right');
			}
			if ($groupid != 3 && $groupid != 4) {
				$authordb = $db->get_one("SELECT groupid FROM pw_members WHERE uid='$rt[authorid]'");
				if ($authordb['groupid'] == 3 || $authordb['groupid'] == 4) {
					Showmsg('modify_admin');
				}
			}
			$rt['date'] = get_date($rt['postdate']);
			$threaddb[] = $rt;
		}
	}
	empty($threaddb) && Showmsg('data_error');

	if (!defined('AJAX')) {
		require_once(R_P.'require/header.php');
		$template = 'mawhole';
	}
}
if ($_POST['step']=='2') {
	InitGP(array('atc_content'),'P',1);

	if ($db_enterreason && !$atc_content) {
		Showmsg('enterreason');
	} elseif (defined('AJAX') && $db_charset!='utf-8') {
		$atc_content = ajax_convert($atc_content,$db_charset);
	}
}

if ($action == "type") {
	if (empty($_POST['step'])) {
		$typesel  = '';
		$t_typedb = array();
		$t_db     = $foruminfo['t_type'];
		if (trim($t_db)) {
			$t_typedb = explode("\t",$t_db);
			$t_typedb = array_unique($t_typedb);
			unset($t_typedb[0]);
		} else {
			Showmsg('mawhole_notype');
		}
		require_once PrintEot('mawhole');footer();
	} else {
		InitGP(array('type','ifmsg'));
		count($tidarray) > 500 && Showmsg('mawhole_count');
		$tids = '';
		if (is_array($tidarray)) {
			foreach ($tidarray as $key => $value) {
				if (is_numeric($value)) {
					$tids .= $tids ? ','.$value : $value;
				}
			}
		}
		!$tids && Showmsg('mawhole_nodata');
		$db->update("UPDATE pw_threads SET type='$type' WHERE tid IN($tids)");
		if($ifmsg){
			$t_typedb = array();
			$t_db     = $foruminfo['t_type'];
			if (trim($t_db)) {
				$t_typedb = explode("\t",$t_db);
				$t_typedb = array_unique($t_typedb);
				unset($t_typedb[0]);
			}
			$query = $db->query("SELECT tid,fid,author,authorid,subject,postdate FROM pw_threads WHERE tid IN($tids)");
			while (@extract($db->fetch_array($query))){
				$msgdb[] = array(
					$author,
					$winduid,
					'change_type_title',
					$timestamp,
					'change_type_content',
					'N',
					$windid,
					'fid'		=> $fid,
					'tid'		=> $tid,
					'postdate'	=> get_date($postdate),
					'subject'	=> $subject,
					'forum'		=> strip_tags($forum[$fid]['name']),
					'admindate'	=> get_date($timestamp),
					'reason'	=> $atc_content,
					'type'		=> $t_typedb[$type],
				);
			}
			foreach ($msgdb as $key=>$val) {
				writenewmsg($val,1);
			}
		}
		refreshto("thread.php?fid=$fid",'operate_success');
	}
} elseif ($_POST['action'] == "check") {
	if (empty($_POST['step'])) {
		require_once PrintEot('mawhole');footer();
	} else {
		InitGP(array('ifmsg'));
		count($tidarray) > 500 && Showmsg('mawhole_count');
		$tids  = '';
		$count = 0;
		if (is_array($tidarray)) {
			foreach ($tidarray as $key => $value) {
				if (is_numeric($value)) {
					$tids .= $tids ? ','.$value : $value;
					$count++;
				}
			}
		}
		!$tids && Showmsg('mawhole_nodata');
		$db->update("UPDATE pw_threads SET ifcheck='1' WHERE tid IN($tids)");
		$rt = $db->get_one("SELECT tid,author,postdate,subject,lastpost,lastposter FROM pw_threads WHERE fid='$fid' AND ifcheck='1' AND topped='0' ORDER BY lastpost DESC LIMIT 0,1");
		if ($rt['postdate'] == $rt['lastpost']) {
			$subject = addslashes(substrs($rt['subject'],21));
			$author  = $rt['author'];
		} else {
			$subject = 'Re:'.addslashes(substrs($rt['subject'],21));
			$author  = $rt['lastposter'];
		}
		$new_url  = "read.php?tid=$rt[tid]&page=e#a";
		$lastpost = $subject."\t".addslashes($author)."\t".$rt['lastpost']."\t".$new_url;
		$db->update("UPDATE pw_forumdata SET lastpost='$lastpost',tpost=tpost+'$count',article=article+'$count',topic=topic+'$count' WHERE fid='$fid'");
		P_unlink(D_P.'data/bbscache/c_cache.php');
		if($ifmsg){
			$query = $db->query("SELECT tid,fid,author,authorid,subject,postdate FROM pw_threads WHERE tid IN($tids)");
			while (@extract($db->fetch_array($query))){
				$msgdb[] = array(
					$author,
					$winduid,
					'check_title',
					$timestamp,
					'check_content',
					'N',
					$windid,
					'fid'		=> $fid,
					'tid'		=> $tid,
					'postdate'	=> get_date($postdate),
					'subject'	=> $subject,
					'forum'		=> strip_tags($forum[$fid]['name']),
					'admindate'	=> get_date($timestamp),
					'reason'	=> $atc_content,
				);
			}
			foreach ($msgdb as $key=>$val) {
				writenewmsg($val,1);
			}
		}
		refreshto("thread.php?fid=$fid",'operate_success');
	}
} elseif ($action == "del") {
	if (empty($_POST['step'])) {
		require_once PrintEot($template);footer();
	} else {
		InitGP(array('ifdel','ifmsg'));
		count($tidarray) > 500 && Showmsg('mawhole_count');
		$pollids = $actids = $rewids = '';
		$delids  = 0;
		$readdb  = $ttable_a = $ptable_a = $attachdb = $msgdb = array();
		foreach ($tidarray as $key => $value) {
			if (is_numeric($value)) {
				$delids .= ','.$value;
				$ttable_a[GetTtable($value)] .= $value.',';
			}
		}
		!$delids && Showmsg('mawhole_nodata');

		$creditset    = get_creditset($foruminfo['creditset'],$db_creditset);
		$msg_delrvrc  = $ifdel ? floor($creditset['rvrc']['Delete']/10) : 0;
		$msg_delmoney = $ifdel ? $creditset['money']['Delete'] : 0;

		$updatetop = 0;
		foreach ($ttable_a as $pw_tmsgs=>$value) {
			$value = substr($value,0,-1);
			$query = $db->query("SELECT t.tid,t.fid as tfid,t.postdate,tm.aid,t.author,t.authorid,t.subject,t.replies,t.topped,t.special,t.ifupload,t.ptable FROM pw_threads t LEFT JOIN $pw_tmsgs tm ON tm.tid=t.tid WHERE t.tid IN($value)");
			while ($read=$db->fetch_array($query)) {
				$read['tfid'] != $fid && Showmsg('admin_forum_right');
				$readdb[] = $read;
			}
		}
		$db_guestread && require_once(R_P.'require/guestfunc.php');
		foreach ($readdb as $key=>$read) {
			@extract($read);
			$topped > 1 && $updatetop = 1;
			$ptable_a[$ptable]=1;
			if ($aid) $attachdb[] = $aid;

			switch ($special) {
				case 1: $pollids .= $tid.',';break;
				case 2: $actids  .= $tid.',';break;
				case 3: $rewids  .= $tid.',';break;
			}
			if ($ifupload) {
				$pw_posts = GetPtable($ptable);
				$query2 = $db->query("SELECT aid FROM $pw_posts WHERE tid='$tid' AND aid!=''");
				while (@extract($db->fetch_array($query2))) {
					if ($aid) $attachdb[] = $aid;
				}
			}
			if ($ifmsg) {
				$msgdb[] = array(
					$author,
					$winduid,
					'del_title',
					$timestamp,
					'del_content',
					'N',
					$windid,
					'fid'		=> $fid,
					'tid'		=> $tid,
					'subject'	=> $subject,
					'postdate'	=> get_date($postdate),
					'forum'		=> strip_tags($forum[$fid]['name']),
					'affect'    => "{$db_rvrcname}:-{$msg_delrvrc},{$db_moneyname}:-{$msg_delmoney}",
					'admindate'	=> get_date($timestamp),
					'reason'	=> $atc_content
				);
			}
			$logdb[] = array(
				'type'      => 'delete',
				'username1' => $author,
				'username2' => $windid,
				'field1'    => $fid,
				'field2'    => '',
				'field3'    => '',
				'descrip'   => 'del_descrip',
				'timestamp' => $timestamp,
				'ip'        => $onlineip,
				'affect'    => "{$db_rvrcname}:-{$msg_delrvrc},{$db_moneyname}:-{$msg_delmoney}",
				'tid'		=> $tid,
				'subject'	=> substrs($subject,28),
				'forum'		=> $forum[$fid]['name'],
				'reason'	=> $atc_content
			);
			if ($ifdel) {
				dtchange($authorid,-$creditset['rvrc']['Delete'],-1,-$creditset['money']['Delete']);
				customcredit($authorid,$creditset,'Delete');
			}
			// 删除静态模版
			$htmurl = R_P.$db_htmdir.'/'.$fid.'/'.date('ym',$postdate).'/'.$tid.'.html';
			if (file_exists($htmurl)) {
				P_unlink($htmurl);
			}
			if ($db_recycle) {
				$db->update("REPLACE INTO pw_recycle (pid,tid,fid,deltime,admin) VALUES('0','$tid','$fid','$timestamp','".addslashes($windid)."')");
			}
			$db_guestread && clearguestcache($tid,$replies);
		}
		if($attachdb){
			$ftp = null;
			if ($db_ifftp) {
				require_once(R_P.'require/ftp.php');
				$ftp = new FTP($ftp_server,$ftp_port,$ftp_user,$ftp_pass,$ftp_dir);
			}
			delete_att($attachdb,!$db_recycle);
			if ($ftp) {
				$ftp->close(); unset($ftp);
			}
		}
		foreach ($msgdb as $key=>$val) {
			writenewmsg($val,1);
		}
		foreach ($logdb as $key=>$val) {
			writelog($val);
		}
		if (!$db_recycle) {
			if ($pollids) {
				$pollids = substr($pollids,0,-1);
				$db->update("DELETE FROM pw_polls WHERE tid IN($pollids)");
			}
			if ($actids) {
				$actids = substr($actids,0,-1);
				$db->update("DELETE FROM pw_activity WHERE tid IN($actids)");
				$db->update("DELETE FROM pw_actmember WHERE actid IN($actids)");
			}
			if ($rewids) {
				$rewids = substr($rewids,0,-1);
				$db->update("DELETE FROM pw_reward WHERE tid IN($rewids)");
			}
			$db->update("DELETE FROM pw_threads	WHERE tid IN($delids)");

			foreach ($ttable_a as $pw_tmsgs=>$val) {
				$val = substr($val,0,-1);
				$db->update("DELETE FROM $pw_tmsgs WHERE tid IN($val)");
			}
			foreach ($ptable_a as $key=>$val) {
				$pw_posts = GetPtable($key);
				$db->update("DELETE FROM $pw_posts WHERE tid IN($delids)");
			}
			delete_tag($delids);
		} else {
			$db->update("UPDATE pw_threads SET fid=0,ifcheck=1,topped=0 WHERE tid IN($delids)");
			foreach ($ptable_a as $key=>$val) {
				$pw_posts = GetPtable($key);
				$db->update("UPDATE $pw_posts SET fid=0 WHERE tid IN($delids)");
			}
		}
		if($delids && $db_ifsort&30){
			require_once(R_P.'require/sort.php');
			sort_delete($delids);
		}
		updateforum($fid);
		if ($updatetop) {
			updatetop();
		}
		P_unlink(D_P.'data/bbscache/c_cache.php');
		if (!defined('AJAX')) {
			refreshto("thread.php?fid=$fid",'operate_success');
		} else {
			Showmsg('ajax_operate_success');
		}
	}
} elseif ($action == "move") {
	if (empty($_POST['step'])) {
		$forumadd='';
		$query=$db->query("SELECT fid,name,allowvisit FROM pw_forums WHERE f_type='hidden'");
		if ($query) {
			while ($rt = $db->fetch_array($query)) {
				if (strpos($rt['allowvisit'],','.$groupid.',') !== false) {
					$forumadd.="<option value='$rt[fid]'> &nbsp;|- $rt[name]</option>";
				}
			}
		}
		@include_once(D_P.'data/bbscache/forumcache.php');
		require_once PrintEot($template);footer();
	} else {
		InitGP(array('to_id','ifmsg'));
		if ($forum[$to_id]['type'] == 'category') {
			Showmsg('mawhole_error');
		}
		count($tidarray) > 500 && Showmsg('mawhole_count');
		$mids = 0;
		$ttable_a = $ptable_a = $msgdb = array();
		foreach ($tidarray as $key => $value) {
			if (is_numeric($value)) {
				$mids .= ','.$value;
				$ttable_a[GetTtable($value)] .= $value.',';
			}
		}
		!$mids && Showmsg('mawhole_nodata');

		$updatetop = 0;
		$query     = $db->query("SELECT tid,fid as tfid,author,postdate,subject,replies,topped,ptable FROM pw_threads WHERE tid IN($mids)");
		while ($rt=$db->fetch_array($query)) {
			Add_S($rt);
			@extract($rt);
			$tfid != $fid && Showmsg('admin_forum_right');
			$ptable_a[$ptable]=1;
			$topped > 1 && $updatetop = 1;
			// 静态模版更新
			if ($foruminfo['allowhtm'] == 1) {
				$date=date('ym',$postdate);
				$htmurldel=R_P.$db_htmdir.'/'.$fid.'/'.$date.'/'.$tid.'.html';
				P_unlink($htmurldel);
			}
			$toname = addslashes($forum[$to_id]['name']);
			if ($ifmsg) {
				$msgdb[] =array(
					$author,
					$winduid,
					'move_title',
					$timestamp,
					'move_content',
					'N',
					$windid,
					'fid'		=> $fid,
					'tid'		=> $tid,
					'tofid'		=> $to_id,
					'subject'	=> $subject,
					'postdate'	=> get_date($postdate),
					'forum'		=> strip_tags($forum[$fid]['name']),
					'toforum'	=> $toname,
					'admindate'	=> get_date($timestamp),
					'reason'	=> $atc_content
				);
			}
			$logdb[] = array(
				'type'      => 'move',
				'username1' => $author,
				'username2' => $windid,
				'field1'    => $fid,
				'field2'    => '',
				'field3'    => '',
				'descrip'   => 'move_descrip',
				'timestamp' => $timestamp,
				'ip'        => $onlineip,
				'tid'		=> $tid,
				'subject'	=> substrs($subject,28),
				'tofid'		=> $to_id,
				'toforum'	=> $toname,
				'forum'		=> $forum[$fid]['name'],
				'reason'	=> $atc_content
			);
		}
		foreach ($msgdb as $key=>$val) {
			writenewmsg($val,1);
		}
		foreach ($logdb as $key=>$val) {
			writelog($val);
		}
		include GetLang('other');
		$remindinfo = strip_tags($lang['mawhole_move']);
		$db->update("UPDATE pw_threads SET fid='$to_id',type='0' WHERE tid IN($mids)");

		foreach ($ttable_a as $pw_tmsgs=>$val) {
			$val = substr($val,0,-1);
			$db->update("UPDATE $pw_tmsgs SET remindinfo='$remindinfo' WHERE tid IN($val)");
		}
		foreach ($ptable_a as $key=>$val) {
			$pw_posts = GetPtable($key);
			$db->update("UPDATE $pw_posts SET fid='$to_id' WHERE tid IN($mids)");
		}
		updateforum($fid);
		updateforum($to_id);
		if ($updatetop) {
			updatetop();
		}
		P_unlink(D_P.'data/bbscache/c_cache.php');
		if (!defined('AJAX')) {
			refreshto("thread.php?fid=$fid",'operate_success');
		} else {
			Showmsg("ajax_operate_success");
		}
	}
} elseif ($action == "copy") {
	if (empty($_POST['step'])) {
		$forumadd  = '';
		$query = $db->query("SELECT fid,name,allowvisit FROM pw_forums WHERE f_type='hidden'");
		if ($query) {
			while ($rt = $db->fetch_array($query)) {
				if (strpos($rt['allowvisit'],','.$groupid.',') !== false) {
					$forumadd .= "<option value='$rt[fid]'> &nbsp;|- $rt[name]</option>";
				}
			}
		}
		@include_once(D_P.'data/bbscache/forumcache.php');
		require_once PrintEot($template);footer();
	} else {
		InitGP(array('to_id','ifmsg'));
		if ($forum[$to_id]['type'] == 'category') {
			Showmsg('mawhole_error');
		}
		count($tidarray) > 500 && Showmsg('mawhole_count');
		$selids = '';
		$readdb = $ttable_a = array();
		foreach ($tidarray as $k=>$v) {
			if (is_numeric($v)) {
				$selids .= $selids ? ','.$v : $v;
				$ttable_a[GetTtable($v)] .= $v.',';
			}
		}
		!$selids && Showmsg('mawhole_nodata');
		$updatetop = 0;
		$ufid = $fid;

		foreach ($ttable_a as $pw_tmsgs=>$val) {
			$val = substr($val,0,-1);
			$query = $db->query("SELECT * FROM pw_threads t LEFT JOIN $pw_tmsgs tm ON tm.tid=t.tid WHERE t.tid IN($val)");
			while ($rt=$db->fetch_array($query)) {
				$ufid != $rt['fid'] && Showmsg('admin_forum_right');
				$readdb[] = $rt;
			}
		}
		foreach ($readdb as $key=>$read) {
			Add_S($read);
			@extract($read);
			$topped > 1 && $updatetop = 1;
			$toname = addslashes($forum[$to_id]['name']);
			if ($ifmsg) {
				$msgdb[] =array(
					$author,
					$winduid,
					'copy_title',
					$timestamp,
					'copy_content',
					'N',
					$windid,
					'fid'		=> $fid,
					'tid'		=> $tid,
					'tofid'		=> $to_id,
					'subject'	=> $subject,
					'postdate'	=> get_date($postdate),
					'forum'		=> strip_tags($forum[$fid]['name']),
					'toforum'	=> $toname,
					'admindate'	=> get_date($timestamp),
					'reason'	=> $atc_content
				);
			}
			$logdb[] = array(
				'type'      => 'copy',
				'username1' => $author,
				'username2' => $windid,
				'field1'    => $fid,
				'field2'    => '',
				'field3'    => '',
				'descrip'   => 'copy_descrip',
				'timestamp' => $timestamp,
				'ip'        => $onlineip,
				'tid'		=> $tid,
				'subject'	=> substrs($subject,28),
				'tofid'		=> $to_id,
				'toforum'	=> $toname,
				'forum'		=> $forum[$fid]['name'],
				'reason'	=> $atc_content
			);

			$db->update("INSERT INTO pw_threads (fid,icon,titlefont,author,authorid,subject,ifcheck, postdate,lastpost,lastposter,hits,replies,topped,locked,digest,special,ifupload,ifmail,ifshield,anonymous,ptable) VALUES ('$to_id','$icon','$titlefont','$author','$authorid','$subject','$ifcheck','$postdate','$lastpost','$lastposter','$hits','$replies','$topped','$locked','$digest','$special','$ifupload','$ifmail','$ifshield','$anonymous','$db_ptable')");
			$newtid = $db->insert_id();
			$aid    = str_replace("'","\'",$aid);
			if ($special==1) {
				$rs = $db->get_one("SELECT voteopts,state,modifiable,previewable,timelimit FROM pw_polls WHERE tid='$tid'");
				Add_S($rs);
				$db->update("INSERT INTO pw_polls (tid,voteopts,state,modifiable,previewable,timelimit) VALUES ('$newtid','$rs[voteopts]','$rs[state]','$rs[modifiable]','$rs[previewable]','$rs[timelimit]')");
			}

			include GetLang('other');
			$remindinfo = strip_tags($lang['mawhole_copy']);
			$pw_tmsgs   = GetTtable($newtid);
			$db->update("INSERT INTO $pw_tmsgs(tid,aid,userip,ifsign,buy,ipfrom,remindinfo,ifconvert,content) VALUES('$newtid','$aid','$userip','$ifsign','$buy','$ipfrom','$remindinfo','$ifconvert','$content')");

			$pw_posts=GetPtable($ptable);
			$query2  =$db->query("SELECT * FROM $pw_posts WHERE tid='$tid'");
			$pw_posts=GetPtable($db_ptable);
			while ($rt=$db->fetch_array($query2)) {
				Add_S($rt);
				@extract($rt);
				if ($db_plist) {
					$db->update("INSERT INTO pw_pidtmp(pid) values('')");
					$pid=$db->insert_id();
				} else {
					$pid='';
				}
				$db->update("INSERT INTO $pw_posts (pid,fid,tid,aid,author,authorid,icon,postdate,subject,userip,ifsign,alterinfo,remindinfo,ipfrom,ifconvert,ifcheck,content,ifshield,anonymous) VALUES ('$pid','$to_id','$newtid','$aid','$author','$authorid','$icon','$postdate','$subject','$userip','$ifsign','$alterinfo','$remindinfo','$ipfrom','$ifconvert','$ifcheck','$content','$ifshield','$anonymous')");
			}
		}
		foreach ($msgdb as $key=>$val) {
			writenewmsg($val,1);
		}
		foreach ($logdb as $key=>$val) {
			writelog($val);
		}
		updateforum($to_id);
		if ($updatetop) {
			updatetop();
		}
		refreshto("thread.php?fid=$fid",'operate_success');
	}
} elseif ($action=="headtopic") {
	if (empty($_POST['step'])) {
		if (is_numeric($seltid)) {
			$rt = $db->get_one("SELECT fid,topped FROM pw_threads WHERE tid='$seltid'");
			if ($fid != $rt['fid']) {
				Showmsg('admin_forum_right');
			}
			${'topped_'.$rt['topped']} = 'checked';
		}
		require_once PrintEot($template);footer();
	} else {
		InitGP(array('topped','ifmsg','timelimit','nextto'));
		if ($topped > 1 && ($groupid == 5 || $SYSTEM['topped'] < $topped)) {
			Showmsg('masigle_top');
		}
		count($tidarray) > 500 && Showmsg('mawhole_count');
		$selids = $tids = '';
		$ttable_a = array();
		foreach ($tidarray as $k => $v) {
			if (is_numeric($v)) {
				$selids .= $selids ? ','.$v : $v;
				$ttable_a[GetTtable($v)] .= $v.',';
			}
		}
		!$selids && Showmsg('mawhole_nodata');

		$msgdb = $logdb = array();
		$updatetop = 0;
		$toolfield = $timelimit>0 && $topped ? $timelimit*86400 + $timestamp : '';

		$query = $db->query("SELECT tid,fid,postdate,author,authorid,subject,topped,toolfield FROM pw_threads WHERE tid IN($selids)");
		while ($rt=$db->fetch_array($query)) {
			if ($rt['topped'] > 1 && ($groupid == 5 || $SYSTEM['topped'] < $rt['topped'])) {
				Showmsg('masigle_top');
			}
			if ($fid != $rt['fid']) {
				Showmsg('admin_forum_right');
			}
			if ($topped > 1 || $rt['topped'] > 1) {
				$updatetop = 1;
			}
			if ($topped && $topped != $rt['topped']) {
				if ($ifmsg) {
					$msgdb[] = array(
						$rt['author'],
						$winduid,
						'top_title',
						$timestamp,
						'top_content',
						'',
						$windid,
						'fid'		=> $fid,
						'tid'		=> $rt['tid'],
						'subject'	=> $rt['subject'],
						'postdate'	=> get_date($rt['postdate']),
						'forum'		=> strip_tags($forum[$fid]['name']),
						'admindate'	=> get_date($timestamp),
						'reason'	=> $atc_content
					);
				}
				$logdb[] = array(
					'type'      => 'topped',
					'username1' => $rt['author'],
					'username2' => $windid,
					'field1'    => $fid,
					'field2'    => '',
					'field3'    => '',
					'descrip'   => 'topped_descrip',
					'timestamp' => $timestamp,
					'ip'        => $onlineip,
					'topped'	=> $topped,
					'tid'		=> $rt['tid'],
					'subject'	=> substrs($rt['subject'],28),
					'forum'		=> $forum[$fid]['name'],
					'reason'	=> $atc_content
				);
			} elseif ($rt['topped'] && !$topped) {
				if ($ifmsg) {
					$msgdb[] = array(
						$rt['author'],
						$winduid,
						'untop_title',
						$timestamp,
						'untop_content',
						'',
						$windid,
						'fid'		=> $fid,
						'tid'		=> $rt['tid'],
						'subject'	=> $rt['subject'],
						'postdate'	=> get_date($rt['postdate']),
						'forum'		=> strip_tags($forum[$fid]['name']),
						'admindate'	=> get_date($timestamp),
						'reason'	=> $atc_content
					);
				}
				$logdb[] = array(
					'type'      => 'topped',
					'username1' => $rt['author'],
					'username2' => $windid,
					'field1'    => $fid,
					'field2'    => '',
					'field3'    => '',
					'descrip'   => 'untopped_descrip',
					'timestamp' => $timestamp,
					'ip'        => $onlineip,
					'tid'		=> $rt['tid'],
					'subject'	=> substrs($rt['subject'],28),
					'forum'		=> $forum[$fid]['name'],
					'reason'	=> $atc_content
				);
			}
			if ($toolfield || $rt['toolfield']) {
				$t = explode(',',$rt['toolfield']);
				$rt['toolfield'] = $toolfield.','.$t[1];
				$db->update("UPDATE pw_threads SET topped='$topped',toolfield='$rt[toolfield]' WHERE tid='$rt[tid]'");
			} else {
				$tids .= $tids ? ','.$rt['tid'] : $rt['tid'];
			}
		}
		foreach ($msgdb as $key=>$val) {
			writenewmsg($val,1);
		}
		foreach ($logdb as $key=>$val) {
			writelog($val);
		}
		include GetLang('other');
		$remindinfo = $topped ? $lang['mawhole_top_2'] : $lang['mawhole_top_1'];

		if ($tids) {
			$db->update("UPDATE pw_threads SET topped='$topped' WHERE tid IN($tids)");
		}
		foreach ($ttable_a as $pw_tmsgs=>$val) {
			$val = substr($val,0,-1);
			$db->update("UPDATE $pw_tmsgs SET remindinfo='$remindinfo' WHERE tid IN($val)");
		}
		$updatetop && updatetop();
		delfcache($fid,$db_fcachenum);

		if ($nextto && is_numeric($selids)) {
			if (!defined('AJAX')) {
				refreshto("mawhole.php?action=$nextto&fid=$fid&seltid=$selids",'operate_success');
			} else {
				Showmsg("ajax_nextto");
			}
		} else {
			refreshto("thread.php?fid=$fid",'operate_success');
		}
	}
} elseif ($action=="digest") {
	if (empty($_POST['step'])) {
		if (is_numeric($seltid)) {
			$rt = $db->get_one("SELECT fid,digest FROM pw_threads WHERE tid='$seltid'");
			if ($fid != $rt['fid']) {
				Showmsg('admin_forum_right');
			}
			${'digest_'.$rt['digest']} = 'checked';
		}
		require_once PrintEot($template);footer();
	} else {
		InitGP(array('digest','ifmsg','nextto'));
		count($tidarray) > 500 && Showmsg('mawhole_count');
		$selids = '';
		$ttable_a = array();
		foreach ($tidarray as $k => $v) {
			if (is_numeric($v)) {
				$selids .= $selids ? ','.$v : $v;
				$ttable_a[GetTtable($v)] .= $v.',';
			}
		}
		!$selids && Showmsg('mawhole_nodata');

		$creditset = get_creditset($foruminfo['creditset'],$db_creditset);
		$add_rvrc  = floor($creditset['rvrc']['Digest']/10);
		$add_money = $creditset['money']['Digest'];
		$del_rvrc  = floor($creditset['rvrc']['Undigest']/10);
		$del_money = $creditset['money']['Undigest'];

		$msgdb = $logdb = array();
		$query = $db->query("SELECT tid,fid,postdate,author,authorid,subject,digest FROM pw_threads WHERE tid IN($selids)");
		while ($rt=$db->fetch_array($query)) {
			if ($fid != $rt['fid']) {
				Showmsg('admin_forum_right');
			}
			if (!$rt['digest'] && $digest) {
				if ($ifmsg) {
					$msgdb[] = array(
						$rt['author'],
						$winduid,
						'digest_title',
						$timestamp,
						'digest_content',
						'',
						$windid,
						'fid'		=> $fid,
						'tid'		=> $rt['tid'],
						'subject'	=> $rt['subject'],
						'postdate'	=> get_date($rt['postdate']),
						'forum'		=> strip_tags($forum[$fid]['name']),
						'affect'    => "{$db_rvrcname}:+{$add_rvrc},{$db_moneyname}:+{$add_money}",
						'admindate'	=> get_date($timestamp),
						'reason'	=> $atc_content
					);
				}
				dtchange($rt['authorid'],$creditset['rvrc']['Digest'],0,$creditset['money']['Digest']);
				$db->update("UPDATE pw_memberdata SET digests=digests+1 WHERE uid='$rt[authorid]'");
				customcredit($rt['authorid'],$creditset,'Digest');
				$logdb[] = array(
					'type'      => 'digest',
					'username1' => $rt['author'],
					'username2' => $windid,
					'field1'    => $fid,
					'field2'    => '',
					'field3'    => '',
					'descrip'   => 'digest_descrip',
					'timestamp' => $timestamp,
					'ip'        => $onlineip,
					'digest'	=> $digest,
					'affect'    => "{$db_rvrcname}:+{$add_rvrc},{$db_moneyname}:+{$add_money}",
					'tid'		=> $rt['tid'],
					'digest'	=> $digest,
					'subject'	=> substrs($rt['subject'],28),
					'forum'		=> $forum[$fid]['name'],
					'reason'	=> $atc_content
				);
			} elseif ($rt['digest'] && !$digest) {
				if ($ifmsg) {
					$msgdb[] = array(
						$rt['author'],
						$winduid,
						'undigest_title',
						$timestamp,
						'undigest_content',
						'',
						$windid,
						'fid'		=> $fid,
						'tid'		=> $rt['tid'],
						'subject'	=> $rt['subject'],
						'postdate'	=> get_date($rt['postdate']),
						'forum'		=> strip_tags($forum[$fid]['name']),
						'affect'    => "{$db_rvrcname}:-{$del_rvrc},{$db_moneyname}:-{$del_money}",
						'admindate'	=> get_date($timestamp),
						'reason'	=> $atc_content
					);
				}
				dtchange($rt['authorid'],-$creditset['rvrc']['Undigest'],0,-$creditset['money']['Undigest']);
				$db->update("UPDATE pw_memberdata SET digests=digests-1 WHERE uid='$rt[authorid]'");
				customcredit($rt['authorid'],$creditset,'Undigest');
				$logdb[] = array(
					'type'      => 'digest',
					'username1' => $rt['author'],
					'username2' => $windid,
					'field1'    => $fid,
					'field2'    => '',
					'field3'    => '',
					'descrip'   => 'undigest_descrip',
					'timestamp' => $timestamp,
					'ip'        => $onlineip,
					'affect'    => "{$db_rvrcname}:-{$del_rvrc},{$db_moneyname}:-{$del_money}",
					'tid'		=> $rt['tid'],
					'subject'	=> substrs($rt['subject'],28),
					'forum'		=> $forum[$fid]['name'],
					'reason'	=> $atc_content
				);
			}
		}
		foreach ($msgdb as $key=>$val) {
			writenewmsg($val,1);
		}
		foreach ($logdb as $key=>$val) {
			writelog($val);
		}
		include GetLang('other');
		$remindinfo = $digest ? $lang['mawhole_digest_2'] : $lang['mawhole_digest_1'];
		$db->update("UPDATE pw_threads SET digest='$digest' WHERE tid IN($selids)",0);
		foreach ($ttable_a as $pw_tmsgs=>$val) {
			$val = substr($val,0,-1);
			$db->update("UPDATE $pw_tmsgs SET remindinfo='$remindinfo' WHERE tid IN($val)");
		}

		if ($nextto && is_numeric($selids)) {
			if (!defined('AJAX')) {
				refreshto("mawhole.php?action=$nextto&fid=$fid&seltid=$selids",'operate_success');
			} else {
				Showmsg("ajax_nextto");
			}
		} else {
			refreshto("thread.php?fid=$fid",'operate_success');
		}
	}
} elseif ($action=="lock") {
	if (empty($_POST['step'])) {
		if (is_numeric($seltid)) {
			$rt = $db->get_one("SELECT fid,locked FROM pw_threads WHERE tid='$seltid'");
			if ($fid != $rt['fid']) {
				Showmsg('admin_forum_right');
			}
			$rt['locked'] %= 3;
			${'lock_'.$rt['locked']} = 'checked';
		}
		require_once PrintEot($template);footer();
	} else {
		InitGP(array('locked','ifmsg'));
		count($tidarray) > 500 && Showmsg('mawhole_count');
		$selids = '';
		$ttable_a = array();
		foreach ($tidarray as $k => $v) {
			if (is_numeric($v)) {
				$selids .= $selids ? ','.$v : $v;
				$ttable_a[GetTtable($v)] .= $v.',';
			}
		}
		!$selids && Showmsg('mawhole_nodata');
		$msgdb = $logdb = array();
		$query = $db->query("SELECT tid,fid,postdate,author,authorid,subject,locked FROM pw_threads WHERE tid IN($selids)");
		while ($rt=$db->fetch_array($query)) {
			if ($fid != $rt['fid']) {
				Showmsg('admin_forum_right');
			}
			if ($rt['locked']%3<>$locked && $locked) {
				if ($locked==2) {
					P_unlink(R_P."$db_htmdir/$fid/".date('ym',$rt['postdate'])."/$tid.html");
				}
				$s = $rt['locked']>2 ? $locked + 3 : $locked;
				$db->update("UPDATE pw_threads SET locked='$s' WHERE tid='$rt[tid]'");
				if ($ifmsg) {
					$msgdb[] = array(
						$rt['author'],
						$winduid,
						'lock_title',
						$timestamp,
						'lock_content',
						'',
						$windid,
						'fid'		=> $fid,
						'tid'		=> $rt['tid'],
						'subject'	=> $rt['subject'],
						'postdate'	=> get_date($rt['postdate']),
						'forum'		=> strip_tags($forum[$fid]['name']),
						'admindate'	=> get_date($timestamp),
						'reason'	=> $atc_content
					);
				}
				$logdb[] = array(
					'type'      => 'locked',
					'username1' => $rt['author'],
					'username2' => $windid,
					'field1'    => $fid,
					'field2'    => '',
					'field3'    => '',
					'descrip'   => 'lock_descrip',
					'timestamp' => $timestamp,
					'ip'        => $onlineip,
					'tid'		=> $rt['tid'],
					'subject'	=> substrs($rt['subject'],28),
					'forum'		=> $forum[$fid]['name'],
					'reason'	=> $atc_content
				);
			} elseif ($rt['locked']%3<>0 && !$locked) {
				$s = $rt['locked'] > 2 ? 3 : 0;
				$db->update("UPDATE pw_threads SET locked='$s' WHERE tid='$rt[tid]'");
				if ($ifmsg) {
					$msgdb[] = array(
						$rt['author'],
						$winduid,
						'unlock_title',
						$timestamp,
						'unlock_content',
						'',
						$windid,
						'fid'		=> $fid,
						'tid'		=> $rt['tid'],
						'subject'	=> $rt['subject'],
						'postdate'	=> get_date($rt['postdate']),
						'forum'		=> strip_tags($forum[$fid]['name']),
						'admindate'	=> get_date($timestamp),
						'reason'	=> $atc_content
					);
				}
				$logdb[] = array(
					'type'      => 'locked',
					'username1' => $rt['author'],
					'username2' => $windid,
					'field1'    => $fid,
					'field2'    => '',
					'field3'    => '',
					'descrip'   => 'unlock_descrip',
					'timestamp' => $timestamp,
					'ip'        => $onlineip,
					'tid'		=> $rt['tid'],
					'subject'	=> substrs($rt['subject'],28),
					'forum'		=> $forum[$fid]['name'],
					'reason'	=> $atc_content
				);
			}
		}
		foreach ($msgdb as $key=>$val) {
			writenewmsg($val,1);
		}
		foreach ($logdb as $key=>$val) {
			writelog($val);
		}
		include GetLang('other');
		$remindinfo = $lang['mawhole_locked_'.$locked];
		foreach ($ttable_a as $pw_tmsgs=>$val) {
			$val = substr($val,0,-1);
			$db->update("UPDATE $pw_tmsgs SET remindinfo='$remindinfo' WHERE tid IN($val)");
		}
		refreshto("thread.php?fid=$fid",'operate_success');
	}
} elseif ($action=="pushtopic") {
	if (empty($_POST['step'])) {
		require_once PrintEot($template);footer();
	} else {
		InitGP(array('ifmsg','nextto','pushtime'));
		count($tidarray) > 500 && Showmsg('mawhole_count');
		$selids = '';
		$ttable_a = array();
		foreach ($tidarray as $k => $v) {
			if (is_numeric($v)) {
				$selids .= $selids ? ','.$v : $v;
				$ttable_a[GetTtable($v)] .= $v.',';
			}
		}
		!$selids && Showmsg('mawhole_nodata');
		$msgdb = $logdb = array();
		$query = $db->query("SELECT tid,fid,postdate,author,authorid,subject FROM pw_threads WHERE tid IN($selids)");
		while ($rt=$db->fetch_array($query)) {
			if ($fid != $rt['fid']) {
				Showmsg('admin_forum_right');
			}
			if ($ifmsg) {
				$msgdb[] = array(
					$rt['author'],
					$winduid,
					'push_title',
					$timestamp,
					'push_content',
					'',
					$windid,
					'fid'		=> $fid,
					'tid'		=> $rt['tid'],
					'subject'	=> $rt['subject'],
					'postdate'	=> get_date($rt['postdate']),
					'forum'		=> strip_tags($forum[$fid]['name']),
					'admindate'	=> get_date($timestamp),
					'reason'	=> $atc_content
				);
			}
			$logdb[] = array(
				'type'      => 'push',
				'username1' => $rt['author'],
				'username2' => $windid,
				'field1'    => $fid,
				'field2'    => '',
				'field3'    => '',
				'descrip'   => 'push_descrip',
				'timestamp' => $timestamp,
				'ip'        => $onlineip,
				'tid'		=> $rt['tid'],
				'subject'	=> substrs($rt['subject'],28),
				'forum'		=> $forum[$fid]['name'],
				'reason'	=> $atc_content
			);
		}
		foreach ($msgdb as $key=>$val) {
			writenewmsg($val,1);
		}
		foreach ($logdb as $key=>$val) {
			writelog($val);
		}
		include GetLang('other');
		$remindinfo = $lang['mawhole_push'];
		$pushtime < 0 && $pushtime = 1;
		$uptime = $timestamp+$pushtime*3600;
		$db->update("UPDATE pw_threads SET lastpost='$uptime' WHERE tid IN($selids)");
		foreach ($ttable_a as $pw_tmsgs=>$val) {
			$val = substr($val,0,-1);
			$db->update("UPDATE $pw_tmsgs SET remindinfo='$remindinfo' WHERE tid IN($val)");
		}
		delfcache($fid,$db_fcachenum);

		if ($nextto && is_numeric($selids)) {
			if (!defined('AJAX')) {
				refreshto("mawhole.php?action=$nextto&fid=$fid&seltid=$selids",'operate_success');
			} else {
				Showmsg("ajax_nextto");
			}
		} else {
			refreshto("thread.php?fid=$fid",'operate_success');
		}
	}
} elseif ($action=='downtopic') {
	if (empty($_POST['step'])) {
		if (is_numeric($seltid)) {
			$rt = $db->get_one("SELECT locked FROM pw_threads WHERE tid='$seltid'");
			if ($rt['locked']>2) {$lock_1 = 'checked';}else {$lock_0 = 'checked';}
		} else {
			$lock_0 = 'checked';
		}
		require_once PrintEot($template);footer();
	} else {
		InitGP(array('ifmsg','nextto','timelimit','ifpush'));
		count($tidarray) > 500 && Showmsg('mawhole_count');
		$selids   = '';
		$ttable_a = array();
		foreach ($tidarray as $k => $v) {
			if (is_numeric($v)) {
				$selids .= $selids ? ','.$v : $v;
				$ttable_a[GetTtable($v)] .= $v.',';
			}
		}
		!$selids && Showmsg('mawhole_nodata');
		$timelimit < 0 && $timelimit = 24;
		$downtime = $timelimit * 3600;
		$msgdb = $logdb = array();
		$query = $db->query("SELECT tid,fid,postdate,author,authorid,subject,locked FROM pw_threads WHERE tid IN($selids)");
		while ($rt=$db->fetch_array($query)) {
			if ($fid != $rt['fid']) {
				Showmsg('admin_forum_right');
			}
			$sql = ",locked='".($ifpush ? ($rt['locked']%3 + 3) : $rt['locked']%3)."'";
			$db->update("UPDATE pw_threads SET lastpost=lastpost-'$downtime' $sql WHERE tid='$rt[tid]'");
			if ($ifmsg) {
				$msgdb[] = array(
					$rt['author'],
					$winduid,
					'down_title',
					$timestamp,
					'down_content',
					'',
					$windid,
					'fid'		=> $fid,
					'tid'		=> $rt['tid'],
					'subject'	=> $rt['subject'],
					'postdate'	=> get_date($rt['postdate']),
					'forum'		=> strip_tags($forum[$fid]['name']),
					'admindate'	=> get_date($timestamp),
					'reason'	=> $atc_content
				);
			}
			$logdb[] = array(
				'type'      => 'down',
				'username1' => $rt['author'],
				'username2' => $windid,
				'field1'    => $fid,
				'field2'    => '',
				'field3'    => '',
				'descrip'   => 'down_descrip',
				'timestamp' => $timestamp,
				'ip'        => $onlineip,
				'tid'		=> $rt['tid'],
				'subject'	=> substrs($rt['subject'],28),
				'forum'		=> $forum[$fid]['name'],
				'reason'	=> $atc_content
			);
		}
		foreach ($msgdb as $key=>$val) {
			writenewmsg($val,1);
		}
		foreach ($logdb as $key=>$val) {
			writelog($val);
		}
		include GetLang('other');
		$remindinfo = $lang['mawhole_down'];

		foreach ($ttable_a as $pw_tmsgs=>$val) {
			$val = substr($val,0,-1);
			$db->update("UPDATE $pw_tmsgs SET remindinfo='$remindinfo' WHERE tid IN($val)");
		}
		delfcache($fid,$db_fcachenum);
		refreshto("thread.php?fid=$fid",'operate_success');
	}
} elseif ($action=="edit") {
	if (empty($_POST['step'])) {
		if (is_numeric($seltid)) {
			$rt=$db->get_one("SELECT fid,titlefont,author FROM pw_threads WHERE tid='$seltid'");
			if ($fid!=$rt['fid']) {
				Showmsg('admin_forum_right');
			}
			$titledetail=explode("~",$rt['titlefont']);
			$titlecolor=$titledetail[0];
			$titlecolor ? $ifchecked[$titlecolor]='checked' : $ifchecked['none']='checked';
			if ($titledetail[1]=='1')$ifchecked[1]='checked';
			if ($titledetail[2]=='1')$ifchecked[2]='checked';
			if ($titledetail[3]=='1')$ifchecked[3]='checked';
		}
		require_once PrintEot($template);footer();
	} else {
		InitGP(array('title1','title2','title3','title4','nextto','ifmsg','timelimit'));
		count($tidarray) > 500 && Showmsg('mawhole_count');
		$selids = $tids = '';
		$ttable_a = array();
		foreach ($tidarray as $k => $v) {
			if (is_numeric($v)) {
				$selids .= $selids ? ','.$v : $v;
				$ttable_a[GetTtable($v)] .= $v.',';
			}
		}
		!$selids && Showmsg('mawhole_nodata');
		$titlefont = Char_cv("$title1~$title2~$title3~$title4~$title5~$title6~");
		$ifedit = (!$title1 && !$title2 && !$title3 && !$title4) ? 0 : 1;
		$toolfield = $timelimit>0 && $ifedit ? $timelimit*86400 + $timestamp : '';
		$msgdb = $logdb = array();
		$query = $db->query("SELECT tid,fid,postdate,author,authorid,subject,toolfield FROM pw_threads WHERE tid IN($selids)");
		while ($rt=$db->fetch_array($query)) {
			if ($fid != $rt['fid']) {
				Showmsg('admin_forum_right');
			}
			if ($ifmsg) {
				$msgdb[] = array(
					$rt['author'],
					$winduid,
					$ifedit ? 'highlight_title' : 'unhighlight_title',
					$timestamp,
					$ifedit ? 'highlight_content' : 'unhighlight_content',
					'',
					$windid,
					'fid'		=> $fid,
					'tid'		=> $rt['tid'],
					'subject'	=> $rt['subject'],
					'postdate'	=> get_date($rt['postdate']),
					'forum'		=> strip_tags($forum[$fid]['name']),
					'admindate'	=> get_date($timestamp),
					'reason'	=> $atc_content
				);
			}
			$logdb[] = array(
				'type'      => 'highlight',
				'username1' => $rt['author'],
				'username2' => $windid,
				'field1'    => $fid,
				'field2'    => '',
				'field3'    => '',
				'descrip'   => $ifedit ? 'highlight_descrip' : 'unhighlight_descrip',
				'timestamp' => $timestamp,
				'ip'        => $onlineip,
				'tid'		=> $rt['tid'],
				'subject'	=> substrs($rt['subject'],28),
				'forum'		=> $forum[$fid]['name'],
				'reason'	=> $atc_content
			);
			if ($toolfield || $rt['toolfield']) {
				$t = explode(',',$rt['toolfield']);
				$rt['toolfield'] = $t[0].','.$toolfield;
				$db->update("UPDATE pw_threads SET titlefont='$titlefont',toolfield='$rt[toolfield]' WHERE tid='$rt[tid]'");
			} else {
				$tids .= $tids ? ','.$rt['tid'] : $rt['tid'];
			}
		}
		foreach ($msgdb as $key=>$val) {
			writenewmsg($val,1);
		}
		foreach ($logdb as $key=>$val) {
			writelog($val);
		}
		include GetLang('other');
		$remindinfo = $lang['mawhole_edit_'.$ifedit];

		if ($tids) {
			$db->update("UPDATE pw_threads SET titlefont='$titlefont' WHERE tid IN($tids)");
		}
		foreach ($ttable_a as $pw_tmsgs=>$val) {
			$val = substr($val,0,-1);
			$db->update("UPDATE $pw_tmsgs SET remindinfo='$remindinfo' WHERE tid IN($val)");
		}
		if ($nextto && is_numeric($selids)) {
			if (!defined('AJAX')) {
				refreshto("mawhole.php?action=$nextto&fid=$fid&seltid=$selids",'operate_success');
			} else {
				Showmsg("ajax_nextto");
			}
		} else {
			refreshto("thread.php?fid=$fid",'operate_success');
		}
	}
} elseif ($action=="unite") {

	if (empty($_POST['step'])) {

		if (is_numeric($seltid)) {
			$unitetype = 'from';
		} else {
			foreach ($threaddb as $key => $value) {
				if ($value['topped'] || $value['special'] || $value['digest'] || $value['toolinfo']) {
					Showmsg('unite_limit');
				}
			}
			$unitetype = 'to';
		}
		require_once PrintEot($template);footer();

	} else {

		InitGP(array('unitetid','unitetype','ifmsg'));
		$totid	  = '';
		$ttable_a = $readdb = array();

		if ($unitetype == 'to') {
			$totid = (int)$unitetid;
			$tidarray[] = $totid;
		} else {
			count($tidarray) > 1 && Showmsg('mawhole_count');
			$totid = $tidarray[0];
			$tidarray = array_merge($tidarray,explode(',',$unitetid));
		}
		foreach ($tidarray as $k => $v) {
			if (is_numeric($v)) {
				$ttable_a[GetTtable($v)] .= $v.',';
			}
		}
		if (empty($totid) || count($tidarray) < 2) {
			Showmsg('unite_data_error');
		}

		foreach ($ttable_a as $pw_tmsgs => $val) {
			$val = substr($val,0,-1);
			$query = $db->query("SELECT * FROM pw_threads t LEFT JOIN $pw_tmsgs tm USING(tid) WHERE t.tid IN($val)");
			while ($rt = $db->fetch_array($query)) {
				$rt['fid'] != $fid && Showmsg('unite_fid_error');
				if($rt['tid']<>$totid && ($rt['topped'] || $rt['special'] || $rt['digest'] || $rt['toolinfo'])){
					Showmsg('unite_limit');
				}
				$readdb[$rt['tid']] = $rt;
			}
		}
		$todb = $readdb[$totid];
		unset($readdb[$totid]);

		if (!$todb || !$readdb) {
			Showmsg('data_error');
		}
		$pw_posts = GetPtable($todb['ptable']);
		include GetLang('other');
		$remindinfo = $lang['mawhole_unite'];
		$replies = 0;

		foreach ($readdb as $key => $fromdb) {
			Add_S($fromdb);

			if ($db_plist) {
				$db->update("INSERT INTO pw_pidtmp(pid) values('')");
				$pid = $db->insert_id();
			} else {
				$pid = '';
			}
			$db->update("INSERT INTO $pw_posts (pid,fid,tid,aid,author,authorid,icon,postdate,subject,userip,ifsign,alterinfo,ipfrom,ifconvert,ifcheck,content,ifmark,ifshield) VALUES ('$pid','$fid','$totid','$fromdb[aid]','$fromdb[author]','$fromdb[authorid]','$fromdb[icon]','$fromdb[postdate]','$fromdb[subject]','$fromdb[userip]','$fromdb[ifsign]','$fromdb[alterinfo]','$fromdb[ipfrom]','$fromdb[ifconvert]','$fromdb[ifcheck]','$fromdb[content]','$fromdb[ifmark]','$fromdb[ifshield]')");
			!$pid && $pid = $db->insert_id();
			$replies += $fromdb['replies']+1;

			$db->update("DELETE FROM pw_threads WHERE tid='$fromdb[tid]'");
			$pw_tmsgsf = GetTtable($fromdb['tid']);
			$db->update("DELETE FROM $pw_tmsgsf WHERE tid='$fromdb[tid]'");

			if ($db_guestread) {
				require_once(R_P.'require/guestfunc.php');
				clearguestcache($fromdb['tid'],$replies);
			}
			if ($todb['ptable'] == $fromdb['ptable']) {
				$db->update("UPDATE $pw_posts SET tid='$totid' WHERE tid='$fromdb[tid]'");
			} else {
				$pw_postsf = GetPtable($fromdb['ptable']);
				$db->update("INSERT INTO $pw_posts SELECT * FROM $pw_postsf WHERE tid='$fromdb[tid]'");
				$db->update("UPDATE $pw_posts SET tid='$totid' WHERE tid='$fromdb[tid]'");
				$db->update("DELETE FROM $pw_postsf WHERE tid='$fromdb[tid]'");
			}
			$fromdb['ifupload'] && $db->update("UPDATE pw_attachs SET pid='$pid',tid='$totid' WHERE pid='0' AND tid='$fromdb[tid]'");
			$db->update("UPDATE pw_attachs SET tid='$totid' WHERE tid='$fromdb[tid]'");

			if ($ifmsg) {
				$msgdb = array(
					$fromdb['author'],
					$winduid,
					'unite_title',
					$timestamp,
					'unite_content',
					'',
					$windid,
					'fid'		=> $fid,
					'tid'		=> $totid,
					'subject'	=> $todb['subject'],
					'postdate'	=> get_date($todb['postdate']),
					'forum'		=> strip_tags($forum[$fid]['name']),
					'admindate'	=> get_date($timestamp),
					'reason'	=> $atc_content
				);
				writenewmsg($msgdb,1);
			}
			$log = array(
				'type'      => 'unite',
				'username1' => $fromdb['author'],
				'username2' => $windid,
				'field1'    => $fid,
				'field2'    => '',
				'field3'    => '',
				'descrip'   => 'unite_descrip',
				'timestamp' => $timestamp,
				'ip'        => $onlineip,
				'tid'		=> $totid,
				'subject'	=> substrs($todb['subject'],28),
				'forum'		=> $forum[$fid]['name'],
				'reason'	=> $atc_content
			);
			writelog($log);
		}
		$db->update("UPDATE pw_threads SET replies=replies+'$replies' WHERE tid='$totid'");
		$pw_tmsgs = GetTtable($totid);
		$db->update("UPDATE $pw_tmsgs SET remindinfo='$remindinfo' WHERE tid='$totid'");

		updateforum($fid);

		if (!defined('AJAX')) {
			refreshto("read.php?tid=$totid",'operate_success');
		} else {
			Showmsg('ajax_unite_success');
		}
	}
}
?>