<?php
/*
转换群组分类
pre_forum_forum
pre_forum_forumfield
*/

$maxfid = $xc->db['source']->result($xc->db['source']->query("SELECT max(id) FROM {$source_tablepre}cnstyles"), 0);
if($start < $maxfid){
	$converted = 1;
}

$query = $xc->db['source']->query("SELECT * FROM {$source_tablepre}cnstyles WHERE id >= $start AND id < $start + $rpp") or dexit();
while ($pwcnclass = $xc->db['source']->fetch_array($query)) {
	$pwcnclass			=	daddslashes($pwcnclass);

	//pre_forum_forum
	$maxfid				=	$xc->db['source']->result($xc->db['source']->query("SELECT MAX(fid) FROM {$source_tablepre}forums"),0);
	$fid				=	$pwcnclass['id'] + $maxfid;
	$fup				=	($pwcnclass['upid'] ? ($pwcnclass['upid'] + $maxfid) : 0);
	$type				=	$pwcnclass['upid'] == 0 ? 'group' : 'forum';//类型(group:分类 forum:普通论坛 sub:子论坛)
	$name				=	$pwcnclass['cname'];
	$status				=	3;
	$displayorder		=	$pwcnclass['vieworder'];
	$styleid			=	0;
	$threads			=	0;
	$posts				=	0;
	$todayposts			=	0;
	$lastpost			=	'';
	$allowsmilies		=	0;
	$allowhtml			=	0;
	$allowbbcode		=	0;
	$allowimgcode		=	0;
	$allowmediacode		=	0;
	$allowanonymous		=	0;
	$allowpostspecial	=	0;
	$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
	$description		=	'';
	$password			=	'';
	$icon				=	'';
	$redirect			=	'';
	$attachextensions	=	'';
	$creditspolicy		=	'';
	$formulaperm		=	'';
	$moderators			=	'';
	$rules				=	'';
	$threadtypes		=	'';
	$threadsorts		=	'';
	$viewperm			=	'';
	$postperm			=	'';
	$replyperm			=	'';
	$getattachperm		=	'';
	$postattachperm		=	'';
	$postimageperm		=	'';
	$keywords			=	'';
	$supe_pushsetting	=	'';
	$modrecommend		=	'';
	$threadplugin		=	'';
	$extra				=	'';
	$jointype			=	0;			//加入群组方式 -1为关闭，0为公开， 2邀请
	$gviewperm			=	0;			//群组浏览权限 0:仅成员 1:所有用户
	$membernum			=	0;
	$dateline			=	0;			//群组创建时间
	$lastupdate			=	0;			//群组最后更新时间
	$activity			=	0;			//群组活跃度
	$founderuid			=	0;			//群组创始人UID
	$foundername		=	'';			//群组创始人名称
	$banner				=	'';			//群组头图片
	$groupnum			=	0;			//分类下的群组数量
	$commentitem		=	'';

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

	if($xc->db['discuz']->query($query1)) {//插入一级版块
		$fid = $xc->db['discuz']->insert_id();
		$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','commentitem');
		$query2	= getinsertsql("{$discuz_tablepre}forum_forumfield", $field2);
		if($xc->db['discuz']->query($query2)) {
			$convertedrows ++;
		} else {
			$xc->db['discuz']->query("DELETE FROM {$discuz_tablepre}forum_forum WHERE fid='$fid'");
			reportlog("无法转换群组扩展信息 fid = $fid");
		}
	} else {
		reportlog("无法转换群组分类 fid = $fid");
	}
	$converted = 1;
	$totalrows ++;
}
?>
