<?php
/*
图片类型：pre_forum_imagetype
表情表：pre_common_smiley
*/

if($start <= 1) {
	$xc->db['discuz']->query("DELETE FROM {$discuz_tablepre}common_smiley WHERE typeid !='1' AND typeid !='0'");
	$xc->db['discuz']->query("DELETE FROM {$discuz_tablepre}forum_imagetype WHERE directory !='default'");
}

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

$query = $xc->db['source']->query("SELECT * FROM {$source_tablepre}smiles  WHERE id >= $start AND id < $start + $rpp") or dexit();
while($pwsmile = $xc->db['source']->fetch_array($query)) {
	if(!$pwsmile['type']) {
		if($pwsmile['path']) {
			$pwsmile['path']	=	$pwsmile['path'] == 'default' ?  'pw_default' : $pwsmile['path'];
			$typeid			=	$pwsmile['id'] + 1;
			$available		=	'1';
			$name			=	$pwsmile['path'] == 'default' ? 'pw默认表情' : addslashes($pwsmile['name']);
			$type			=	'smiley';
			$displayorder	=	$pwsmile['vieworder'];
			$directory		=	addslashes($pwsmile['path']);
			
			$field1			=	array('typeid', 'available', 'name', 'type', 'displayorder', 'directory');
			$query1			=	getinsertsql("{$discuz_tablepre}forum_imagetype", $field1);
			
			$xc->db['discuz']->query($query1);
		}
		continue;
	}

	$totalrows ++;

	$typeid			=	intval($pwsmile['type'] + 1);
	$displayorder	=	$pwsmile['vieworder'];
	$type			=	'smiley';
	$code			=	'[s:'.$pwsmile['id'].']';
	$url			=	addslashes($pwsmile['path']);
	
	$field2			=	array('id','typeid','displayorder','type','code','url');
	$query2			=	getinsertsql("{$discuz_tablepre}common_smiley", $field2);
	
	$xc->db['discuz']->query($query2);
	$convertedrows ++;
	$url = 'index.php?mod=dealdata&step='.$step.'&start='.($pwsmile['id']+1).'&stay='.$stay.'&totalrows='.$totalrows.'&convertedrows='.$convertedrows.'&sqlfilenum='.$sqlfilenum;
	file_put_contents(XCONVERT_ROOT.'./cache/lock/progress_'.$step.".txt", $url);
}
?>