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

if($start <= 1){//此步不可打开
	//truncatetable('forum_forum');
	//truncatetable('forum_forumfield');
	//truncatetable('forum_grouplevel');
}

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

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

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

	$field1		=	array('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) && $xc->db['discuz']->query("UPDATE {$discuz_tablepre}forum_forumfield SET groupnum=groupnum+1 WHERE fid='$fup'")) {
			$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 ++;
}
?>
