<?php

//--------------------- 更新附件表 ---------------------

//附件表结构开始处理
function upStartChangeFileTbStru(){
	global $empire,$dbtbpre,$ecms_config;
	$empire->query("alter table {$dbtbpre}enewsfile 
		change fileid fileid int(10) unsigned NOT NULL auto_increment,
		add `pubid` bigint(16) unsigned NOT NULL default '0',
		change filename filename char(60) NOT NULL default '',
		change filesize filesize int(10) unsigned NOT NULL default '0',
		change path path char(20) NOT NULL default '',
		change adduser adduser char(30) NOT NULL default '',
		add `oldfiletime` datetime NOT NULL default '0000-00-00 00:00:00',
		change classid classid smallint(5) unsigned NOT NULL default '0',
		change no no char(60) NOT NULL default '',
		change type type tinyint(1) unsigned NOT NULL default '0',
		change onclick onclick mediumint(8) unsigned NOT NULL default '0',
		change id id int(10) unsigned NOT NULL default '0',
		change cjid cjid int(10) unsigned NOT NULL default '0',
		add `modtype` tinyint(1) NOT NULL default '0',
		add INDEX(pubid);");

	$empire->query("update {$dbtbpre}enewsfile set oldfiletime=filetime");

	$empire->query("alter table {$dbtbpre}enewsfile 
		change filetime filetime int(10) unsigned NOT NULL default '0';");
	
	//新建会员附件表
	$empire->query(SetCreateTable("CREATE TABLE `{$dbtbpre}enewsfile_member` (
  `fileid` int(10) unsigned NOT NULL auto_increment,
  `pubid` tinyint(1) NOT NULL default '0',
  `filename` char(60) NOT NULL default '',
  `filesize` int(10) unsigned NOT NULL default '0',
  `path` char(20) NOT NULL default '',
  `adduser` char(30) NOT NULL default '',
  `filetime` int(10) unsigned NOT NULL default '0',
  `classid` tinyint(1) NOT NULL default '0',
  `no` char(60) NOT NULL default '',
  `type` tinyint(1) unsigned NOT NULL default '0',
  `onclick` mediumint(8) unsigned NOT NULL default '0',
  `id` int(10) unsigned NOT NULL default '0',
  `cjid` int(10) unsigned NOT NULL default '0',
  `fpath` tinyint(1) NOT NULL default '0',
  `modtype` tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (`fileid`),
  KEY `id` (`id`),
  KEY `type` (`type`)
) TYPE=MyISAM;",$ecms_config['db']['dbchar']));

	//新建其他附件表
	$empire->query(SetCreateTable("CREATE TABLE `{$dbtbpre}enewsfile_other` (
  `fileid` int(10) unsigned NOT NULL auto_increment,
  `pubid` tinyint(1) NOT NULL default '0',
  `filename` char(60) NOT NULL default '',
  `filesize` int(10) unsigned NOT NULL default '0',
  `path` char(20) NOT NULL default '',
  `adduser` char(30) NOT NULL default '',
  `filetime` int(10) unsigned NOT NULL default '0',
  `classid` tinyint(1) NOT NULL default '0',
  `no` char(60) NOT NULL default '',
  `type` tinyint(1) unsigned NOT NULL default '0',
  `onclick` mediumint(8) unsigned NOT NULL default '0',
  `id` int(10) unsigned NOT NULL default '0',
  `cjid` int(10) unsigned NOT NULL default '0',
  `fpath` tinyint(1) NOT NULL default '0',
  `modtype` tinyint(3) unsigned NOT NULL default '0',
  PRIMARY KEY  (`fileid`),
  KEY `id` (`id`),
  KEY `type` (`type`),
  KEY `modtype` (`modtype`)
) TYPE=MyISAM;",$ecms_config['db']['dbchar']));

	//新建公共附件表
	$empire->query(SetCreateTable("CREATE TABLE `{$dbtbpre}enewsfile_public` (
  `fileid` int(10) unsigned NOT NULL auto_increment,
  `pubid` tinyint(1) NOT NULL default '0',
  `filename` char(60) NOT NULL default '',
  `filesize` int(10) unsigned NOT NULL default '0',
  `path` char(20) NOT NULL default '',
  `adduser` char(30) NOT NULL default '',
  `filetime` int(10) unsigned NOT NULL default '0',
  `classid` tinyint(1) NOT NULL default '0',
  `no` char(60) NOT NULL default '',
  `type` tinyint(1) unsigned NOT NULL default '0',
  `onclick` mediumint(8) unsigned NOT NULL default '0',
  `id` int(10) unsigned NOT NULL default '0',
  `cjid` int(10) unsigned NOT NULL default '0',
  `fpath` tinyint(1) NOT NULL default '0',
  `modtype` tinyint(3) unsigned NOT NULL default '0',
  PRIMARY KEY  (`fileid`),
  KEY `id` (`id`),
  KEY `type` (`type`),
  KEY `modtype` (`modtype`)
) TYPE=MyISAM;",$ecms_config['db']['dbchar']));

}

//附件表结构结束处理
function upEndChangeFileTbStru(){
	global $empire,$dbtbpre,$ecms_config;
	$empire->query("alter table {$dbtbpre}enewsfile 
		drop COLUMN oldfiletime;");
	//重命名表
	$empire->query("ALTER TABLE `{$dbtbpre}enewsfile` RENAME `{$dbtbpre}enewsfile_1`");
}

//附件转换
function upChangeFileTbData($add){
	global $empire,$public_r,$class_r,$fun_r,$dbtbpre,$etable_r,$ecms_config,$dofileline,$dofileretime;
	$dofileline=(int)$dofileline;
	$dofileretime=(int)$dofileretime;
	$start=(int)$add['start'];
	//表结构开始处理
	if($start==0)
	{
		upStartChangeFileTbStru();
	}
	$b=0;
	$sql=$empire->query("select * from {$dbtbpre}enewsfile where fileid>$start order by fileid limit ".$dofileline);
	while($r=$empire->fetch($sql))
	{
		$b=1;
		$new_start=$r[fileid];
		$pubid=0;
		if($r['classid']&&$r['id'])
		{
			$pubid=ReturnInfoPubid($r['classid'],$r['id'],upChangeClassReturnTbid($r['classid']));
		}
		//更新主表
		$filetime=to_time($r['oldfiletime']);
		$empire->query("update {$dbtbpre}enewsfile set pubid='$pubid',filetime='$filetime' where fileid='$r[fileid]'");
	}
	if(empty($b))
	{
		//表结构结束处理
		upEndChangeFileTbStru();
		echo"<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><meta http-equiv=\"refresh\" content=\"".$dofileretime.";url=index.php?ecms=ChangeMemberTbData\">附件数据转换完毕!正进入会员数据转换......";
		db_close();
		$empire=null;
		exit();
	}
	echo"<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><meta http-equiv=\"refresh\" content=\"".$dofileretime.";url=index.php?ecms=ChangeFileTbData&start=$new_start\">转换一组附件数据完毕，正在进入下一组......(ID:<font color=red><b>".$new_start."</b></font>)";
	exit();
}

?>