<?php
/*
转换论坛版块
pre_forum_forum
pre_forum_forumfield
*/

truncatetable('forum_forum');
truncatetable('forum_forumfield');

$sql = "SELECT * FROM {$source_tablepre}board";
$rs = $xc->db['source']->execute($sql);

$fieldarray = array('boardid', 'boardtype', 'parentid', 'depth', 'orders', 'readme', 'boardmaster', 'postnum', 'topicnum', 'lastpost', 'rules');
while (!$rs->EOF) {
	foreach($fieldarray AS $field) {
		$forum[$field] = daddslashes($rs->fields[$field]->value);
	}
	//pre_forum_forum
	$fid	=	$forum['boardid'];
	if(isset($forum['depth']) && $forum['depth'] == 0) {
		$type = 'group';
	} elseif ($forum['depth'] == 1) {
		$type = 'forum';
	} else {
		$type = 'sub';
	}
	$fup	=	$forum['parentid'];
	
	$name	=	cutstr(htmlspecialchars(trim(@strip_tags($forum['boardtype']))), 50);
	$status	=	1;
	$displayorder	=	$forum['orders'];
	$styleid	=	0;
	$threads	=	$forum['topicnum'];
	$posts	=	$forum['postnum'];
	$todayposts		=	0;
	$lastpost		=	'';
	$allowsmilies	=	1;
	$allowhtml		=	1;
	$allowbbcode	=	1;
	$allowimgcode	=	1;
	$allowmediacode	=	1;
	$allowanonymous	=	0;

	$allowpostspecial	=	3;
	$allowspecialonly	=	0;
	$alloweditrules		=	0;
	$allowfeed			=	1;
	$allowside			=	1;
	$recyclebin			=	0;
	$modnewposts		=	0;
	$jammer				=	0;
	$disablewatermark	=	0;
	$inheritedmod		=	0;
	$autoclose			=	0;
	$forumcolumns		=	0;
	$threadcaches		=	0;
	$alloweditpost		=	1;
	$simple				=	0;
	$modworks			=	0;
	$allowglobalstick	=	1;
	$level				=	0;
	$commoncredits		=	0;
	$archive			=	0;
	$recommend			=	0;

	//pre_forum_forumfield
	//$fid				=	'';
	$description		=	$forum['readme'];
	$password			=	'';
	$icon				=	'';
	$redirect			=	'';
	$attachextensions	=	'';
	$creditspolicy		=	'';
	$formulaperm		=	'';
	$moderators			=	addmoderators(explode('|', $forum['boardmaster']), $fid);
	$rules				=	$forum['rules'];
	$threadtypes		=	'';
	$threadsorts		=	'';
	$viewperm			=	'';
	$postperm			=	'';
	$replyperm		=	'';
	$getattachperm		=	'';
	$postattachperm		=	'';
	$postimageperm		=	'';
	$keywords			=	'';
	$supe_pushsetting	=	'';
	$modrecommend		=	'';
	$threadplugin		=	'';
	$extra				=	'';
	$jointype			=	'';
	$gviewperm			=	'';
	$membernum			=	'';
	$dateline			=	'';
	$lastupdate			=	'';
	$activity			=	'';
	$founderuid			=	'';
	$foundername		=	'';
	$banner				=	'';
	$groupnum			=	'';
	$commentitem		=	'';

	$field1		=	array('fid','fup','type','name','status','displayorder','styleid','threads','posts','todayposts','lastpost','allowsmilies','allowhtml','allowbbcode','allowimgcode','allowmediacode','allowanonymous','allowpostspecial','allowspecialonly','alloweditrules','allowfeed','recyclebin','modnewposts','jammer','disablewatermark','inheritedmod','autoclose','forumcolumns','threadcaches','alloweditpost','simple','modworks','allowglobalstick','level','commoncredits','archive');
	$query1		=	getinsertsql("{$discuz_tablepre}forum_forum", $field1);

	$field2		=	array('fid','description','password','icon','redirect','attachextensions','creditspolicy','formulaperm','moderators','rules','threadtypes','threadsorts','viewperm','postperm','replyperm','getattachperm','postattachperm','postimageperm','keywords','supe_pushsetting','modrecommend','threadplugin','extra','jointype','gviewperm','membernum','dateline','lastupdate','activity','founderuid','foundername','banner','groupnum');
	$query2		=	getinsertsql("{$discuz_tablepre}forum_forumfield", $field2);

	if ($xc->db['discuz']->query($query1)) {
		if ($xc->db['discuz']->query($query2)) {
			$convertedrows ++;
		} else {
			$xc->db['discuz']->query("DELETE FROM {$discuz_tablepre}forum_forumfield WHERE fid='$fid' LIMIT 1;");
			reportlog("插入版区扩展信息数据出错 fid = $fid, name = $name");
		}
	} else {
		reportlog("插入版区基本数据出错 fid = $fid, name = $name");
	}
	$rs->Movenext();
	$totalrows ++;
}
$rs->close();
$catquery = $xc->db['discuz']->query("SELECT fid FROM {$discuz_tablepre}".($config_type == "x" ? "forum_forum" : "forums")." WHERE type = 'group'");
while($cat = $xc->db['discuz']->fetch_array($catquery)){
	$gid = $cat['fid'];
	$forumnum =$xc->db['discuz']->result(mysql_query("SELECT COUNT(*) FROM {$discuz_tablepre}".($config_type == "x" ? "forum_forum" : "forums")." WHERE fup = '$gid'"), 0);
	if(!$forumnum){
		$xc->db['discuz']->query("UPDATE {$discuz_tablepre}".($config_type == "x" ? "forum_forum" : "forums")." SET type = 'forum' WHERE fid = '$gid'");
	}
}

?>