<?php
//12、转换勋章及授勋记录

truncatetable('forum_medal');

$query_1 = $xc->db['source']->query("SELECT * FROM {$source_tablepre}medals WHERE available = 1") or die("检索数据表 '{$source_tablepre}medals' 错误！请将表 '{$source_tablepre}medals' 字段类型为 nText 的改为 Text 类型。");

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

	$medalid		= $m['medalid'];
	$name			= $m['name'];
	$available		= $m['available'];
	$image			= $m['image'];
	$type			= 0;
	$displayorder	= 0;
	$description	= '';
	$expiration		= 0;
	$permission		= '';

	$fields1 = array('medalid', 'name', 'available', 'image', 'type', 'displayorder', 'description', 'expiration', 'permission');
	$query1 = getinsertsql("{$discuz_tablepre}forum_medal", $fields1);
	if (!$xc->db['discuz']->query($query1)) {
		reportlog("插入 DZ 勋章数据出错 groupid = $groupid grouptitle = $grouptitle");
	}
}

truncatetable('forum_medallog');

$query_2 = $xc->db['source']->query("SELECT * FROM {$source_tablepre}medalslog") or die("检索数据表 '{$source_tablepre}medalslog' 错误！请将表 '{$source_tablepre}medalslog' 字段类型为 nText 的改为 Text 类型。");

while ($m = $xc->db['source']->fetch_array($query_2)) {
	
	$m = daddslashes(array_change_key_case($m));

	$id			= $m['id'];
	$uid		= $m['uid'];
	$medalid	= $m['medals'];
	$type		= 0;
	$dateline	= timetounix($m['postdatetime']);
	$expiration = 0;
	$status		= 0;

	$fields1 = array('id', 'uid', 'medalid', 'type', 'dateline', 'expiration', 'status');
	$query1 = getinsertsql("{$discuz_tablepre}forum_medallog", $fields1);
	if ($xc->db['discuz']->query($query1)) {
		$convertedrows ++;
	} else {
		reportlog("插入 DZ 授勋记录出错 uid = $uid medalid = $medalid");
	}
	$totalrows ++;
}

?>