<?php
/*
投票
pre_forum_poll
*/

if($start <= 1) {
	truncatetable('forum_poll');
}

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

$maxid = $xc->db['source']->result(
	$xc->db['source']->query("SELECT MAX(pollid) AS MAXID FROM {$source_tablepre}polls"),
	0,
	'MAXID'
);


if($start < $maxid) {
	$converted = 1;
}

while($p = $xc->db['source']->fetch_array($query)) {
	$p		=	daddslashes($p);

	$tid		=	$p['tid'];
	$overt		=	$p['allowview'];
	$visible	=	$p['visible'];
	$maxchoices	=	$p['maxchoices'];
	$expiration	=	timetounix($p['expiration']);
	$pollpreview	=	'';
	$voters		=	$xc->db['source']->result(
					$xc->db['source']->query("SELECT COUNT(*) AS CCC FROM {$source_tablepre}polloptions WHERE tid='{$tid}' AND votes>0"),
					0, 'CCC'
				);
	
	$field1		=	array('tid', 'overt', 'visible', 'maxchoices', 'expiration', 'pollpreview', 'voters');
	$query1		=	getinsertsql("{$discuz_tablepre}forum_poll", $field1);

	if ($xc->db['discuz']->query($query1)) {
		$convertedrows ++;
	} else {
		reportlog("无法转换投票，SQL 语句如下 ：<br><textarea rows=\"3\" style=\"width: 100%;\">".$query1."</textarea>");
	}
	$converted = 1;
	$totalrows ++;
	$url = 'index.php?mod=dealdata&step='.$step.'&start='.($p['pollid']+1).'&stay='.$stay.'&totalrows='.$totalrows.'&convertedrows='.$convertedrows.'&sqlfilenum='.$sqlfilenum;
	file_put_contents(XCONVERT_ROOT.'./cache/lock/progress_'.$step.".txt", $url);
}
?>