<?php
/*
板块
pre_forum_forum
pre_forum_forumfield
pre_forum_threadclass
*/

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

$query = $xc->db['source']->query("SELECT f.*, ff.* FROM {$source_tablepre}forums f, {$source_tablepre}forumfields ff where f.fid=ff.fid") 
	or die("检索数据表 '{$source_tablepre}forums' 和 '{$source_tablepre}forumfields' 错误！请将表 '{$source_tablepre}forums' 和 '{$source_tablepre}forumfields' 字段类型为 nText 的改为 Text 类型。");

while ($f = $xc->db['source']->fetch_assoc($query)) {
	$f = daddslashes(array_change_key_case($f));

	//pre_forum_forum
	$fid			= $f['fid'];
	$fup			= $f['parentid'];
	$type			= $f['parentid'] == 0 ? 'group' : 'forum';
	$name			= $f['name'];
	$status			= $f['status'];
	$displayorder		= $f['displayorder'];
	$styleid		= 0;
	$threads		= $f['topics'];
	$posts			= $f['posts'];
	$todayposts		= $f['todayposts'];
	$lastpost		= $f['lasttid']."\t".$f['lasttitle']."\t".timetounix($f['lastpost'])."\t".$f['lastposter'];
	$allowsmilies		= $f['allowsmilies'];
	$allowhtml		= $f['allowhtml'];
	$allowbbcode		= $f['allowbbcode'];
	$allowimgcode		= $f['allowimgcode'];
	$allowmediacode		= 1;
	$allowanonymous		= 0;
	$allowshare		= 1;
	$allowpostspecial	= 63;
	$allowspecialonly	= 0;
	$alloweditrules		= $f['alloweditrules'];
	$recyclebin		= $f['recyclebin'];
	$modnewposts		= $f['modnewposts'];
	$jammer			= $f['jammer'];
	$disablewatermark	= $f['disablewatermark'];
	$inheritedmod		= $f['inheritedmod'];
	$autoclose		= $f['autoclose'];
	$forumcolumns		= 0;
	$threadcaches		= 0;
	$alloweditpost		= 1;
	$simple			= 0;
	$modworks		= 0;
	$allowtag		= 1;
	$updateline		= 0;
	$allowpost		= 0;

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

	if(!$xc->db['discuz']->query($query1)) {
		reportlog("插入版区基本数据出错 fid = $fid name = $name");
	}

	//forum_forumfield
	$description		= $f['description'];
	$password		= $f['password'];
	$icon			= $f['icon'];
	$redirect		= $f['redirect'];
	$attachextensions	= $f['attachextensions'];
	$creditspolicy		='';
	$formulaperm		= '';
	$moderators		= addmoderators(explode(',', $f['moderators']),$fid);
	$rules			= $f['rules'];

	$temp			= explode('|', $f['topictypes']);
	$temp			= array_filter($temp);
	$types			= array();
	$icons			= array();
	$tmoderators		= array();
	foreach ($temp as $v) {
		$temp1 = explode(',', $v);

		$xc->db['discuz']->query(
			"INSERT INTO {$discuz_tablepre}forum_threadclass (typeid,fid,name,displayorder,icon,moderators)
			VALUES (NULL,'$fid','{$temp1[1]}','0','','')"
		);
		$typeid = $xc->db['discuz']->insert_id();
		$types[$typeid] = $temp1[1];
		$icons[$typeid] = '';
		$tmoderators[$typeid] = '';
	}
	
	$threadtypes = $temp ? daddslashes(serialize(array
					(
					'required' => 0,
					'listable' => 0,
					'prefix' => 1,
					'types' => $types,
					'icons' => $icons,
					'moderators' => $tmoderators,
					))) : '';

	$threadsorts	= '';
	$viewperm		= $f['viewperm'];
	$postperm		= $f['postperm'];
	$replyperm		= $f['replyperm'];
	$getattachperm	= $f['getattachperm'];
	$postattachperm = $f['postattachperm'];
	$postimageperm	= '';
	$spviewperm		= '';
	$seotitle		= '';
	$keywords		= '';
	$seodescription	= '';
	$supe_pushsetting = '';
	$modrecommend	= '';
	$threadplugin   = '';
	$extra			= '';
	$jointype		= 0;
	$gviewperm		= 0;
	$membernum		= 0;
	$dateline		= 0;
	$lastupdate		= 0;
	$activity		= 0;
	$founderuid		= 0;
	$foundername	= '';
	$banner			= '';
	$groupnum		= 0;
	$commentitem	= '';
	$relatedgroup 	= '';
	$picstyl		= 0;
	$widthauto		= 0;

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

	if($xc->db['discuz']->query($query2)) {
		$convertedrows ++;
	} else {

		$xc->db['discuz']->query("DELETE FROM {$discuz_tablepre}forum_forum WHERE fid='$fid' LIMIT 1;");
		reportlog("插入版区扩展信息数据出错 fid = $fid name = $name");
	}
	$totalrows ++;
}
?>