<?php
/*
秀影5.0.2升级到6.0类文件
*/

class upgrade{
	/*
	数据库连接
	*/
	private $DB;
	private $DB2;
	public function __construct(){
		$database = $GLOBALS['database'];
		Easy_Db::Connect($database);
		$this->DB = Easy_Db::getInstance();
	}
	public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbcharset='GBK'){
		$connect['dbhost'] = $dbhost;
		$connect['dbuser'] = $dbuser;
		$connect['dbpass'] = $dbpass;
		$connect['dbname'] = $dbname;
		$connect['dbchar'] = $dbcharset;
		$connect['driver'] = 'MYSQL';
		$this->tblpre = $dbname.'.'.$_POST['tblpre'];
		Easy_Db::Connect($connect);
		$this->DB2 = Easy_Db::getInstance();
	}
	public function start(){
		$this->connect($_POST['dbhost'], $_POST['dbuser'], $_POST['dbpass'], $_POST['dbname'], $_POST['charset']);
		$all = get_class_methods(new self());
		$i =0 ;
		foreach ($all as $method){
			$i++;
			if ($i >3){
				$this->$method();
			}
		}
	}
	public function upadmin(){
		$sql = 'SELECT * FROM '.$this->tblpre.'admin';
		$data = null;
		echo '正在导入管理员数据<br />';
		$this->DB->query('truncate table '.VODCMS_ADMIN);
		foreach ($this->DB2->fetall($sql) as $row){
			$data['username'] = $row['username'];
			$data['password'] = $row['password'];
			$data['realname'] = $row['realname'];
			$data['group'] = '超级管理员';
			$data['logintime'] = $row['logintime'];
			$data['lastime'] = $row['lastime'];
			$data['lastip'] = $row['ip'];
			$data['failed'] = 0;
			$data['locked'] = 0;
			$this->DB->insert(VODCMS_ADMIN, $data);
		}
		echo '导入管理员数据完成<br />';
	}
	/*电影卡升级*/
	public function upCar(){
		$data = null;
		$sql = 'SELECT * FROM '.$this->tblpre.'car';
		echo '正在导入影卡数据...<br >';
		$this->DB->query('truncate table '.VODCMS_CAR);
		foreach ($this->DB2->fetall($sql) as $row){
			$data['carid'] = $row['carid'];
			$data['carpwd'] = $row['carpwd'];
			$data['usergroup'] = $row['groupid'];
			$data['usertype'] = $row['usertype'];
 			$data['money'] = $row['momey'];
			$data['usercount'] = $row['usercount'];
			$data['lifetime'] = $row['lifetime'];
			$data['username'] = $row['username'];
			$data['admin'] = $row['admin'];
			$data['addtime'] = $row['addtime'];
			$data['locked'] = $row['status'];
			$this->DB->insert(VODCMS_CAR, $data);
			unset($data);
		}
		echo '导入影卡数据完成<br >';
	}
	/*
	分类升级
	*/
	public function upCategory(){
		$data = null;
		$sql = 'SELECT * FROM '.$this->tblpre.'class';
		echo '正在导入分类数据...<br >';
		$this->DB->query('truncate table '.VODCMS_CATEGORY);
		foreach ($this->DB2->fetall($sql) as $row){
			$data['id'] = $row['classid'];
			$data['category'] = $row['class'];
			$data['link'] = $row['links'];
			$data['parentid'] = $row['parentid'];
			$data['sort'] = $row['sort'];
			$data['moviecount'] = $row['total'];
			$data['locked'] = $row['locked'];
			$data['list_tpl'] = $row['list_template'];
			$data['movie_tpl'] = $row['display_template'];
			$this->DB->insert(VODCMS_CATEGORY, $data);
		}
		echo '导入分类数据完成<br >';
	}
	public function uplink(){
		$data = null;
		$sql = 'SELECT * FROM '.$this->tblpre.'links';
		echo '正在导入友情连接数据...<br >';
		$this->DB->query('truncate table '.VODCMS_FLINK);
		foreach ($this->DB2->fetall($sql) as $row){
			$data['sitename'] = $row['website'];
			$data['url'] = $row['url'];
			$data['logo'] = $row['logo'];
			$data['description'] = $row['alt'];
			$data['state'] = $row['locked'];
			$this->DB->insert(VODCMS_FLINK, $data);
		}
		echo '导入友情连接数据完成<br >';
	}
	public function upmovieclass(){
		$data = null;
		$sql = 'SELECT * FROM '.$this->tblpre.'mclassid';
		echo '正在导入影片分类数据...<br >';
		$this->DB->query('truncate table '.VODCMS_MCLASSID);
		foreach ($this->DB2->fetall($sql) as $row){
			$data['movid'] = $row['movid'];
			$data['category'] = $row['classid'];
			//$this->DB->delete(VODCMS_MCLASSID, $data);
			$this->DB->insert(VODCMS_MCLASSID, $data);
		}
		echo '导入影片分类数据完成<br >';
	}
	public function upmovie(){
		$data = null;
		$sql = 'SELECT * FROM '.$this->tblpre.'movie';
		echo '正在导入影片数据...<br >';
		$this->DB->query('truncate table '.VODCMS_MOVIE);
		foreach ($this->DB2->fetall($sql) as $row){
			$data['movid'] = $row['movid'];
			$data['title'] = $row['title'];
			$data['actor'] = $row['actor'];
			$data['director'] = $row['director'];
			$data['pic'] = $row['pic'];
			$data['otherpic'] = $row['otherpic'];
			$data['sid'] = $row['server'];
			$data['player'] = $row['player'];
			$data['letter'] = $row['letter'];
			$data['content']= $row['content'];
			$data['area'] = $row['area'];
			$data['lookpoint'] = $row['lookpoint'];
			$data['downpoint'] = $row['downpoint'];
			$data['lookgid'] = $row['lookgid'];
			$data['downgid'] = $row['downgid'];
			$data['look'] = $row['look'];
			$data['down'] = $row['down'];
			$data['review'] = $row['review'];
			$data['addtime'] = $row['addtime'];
			$data['modifytime'] = $row['modifytime'];
			$data['publish'] = $row['publish'];
			$data['click'] = $row['click'];
			$data['language'] = $row['langauge'];
			$data['serialise'] = $row['serialise'];
			$data['mkey'] = $row['md5str'];
			$data['urlcount'] = $row['total'];
			$data['author'] = $row['author'];
			$data['category'] = $row['classid'];
			$this->DB->insert(VODCMS_MOVIE, $data);
			
		}
		unset($data, $row);
		echo '导入影片数据完成<br >';
	}
	/*升级用户资料*/
	public function upmember(){
		$data = null;
		$this->DB->query('truncate table '.VODCMS_MEMBERS);
		$sql = 'SELECT * FROM '.$this->tblpre.'members';
		echo '正在导入会员数据...<br >';
		foreach ($this->DB2->fetAll($sql) as $row){
			$this->DB->insert(VODCMS_MEMBERS, $row);
		}
		echo '导入会员数据完成<br >';
		unset($row);
	}
	/*升级影片服务器*/
	public function upServer(){
		$data = null;
		$sql = 'SELECT * FROM '.$this->tblpre.'server';
		echo '正在导入服务器数据...<br >';
		$this->DB->query('truncate table '.VODCMS_SERVER);
		foreach ($this->DB2->fetAll($sql) as $row){
			$data['sid'] = $row['sid'];
			$data['name'] = $row['title'];
			$data['helixserver'] = $row['helixserver'];
			$data['ftpserver'] = $row['ftpserver'];
			$data['parentid'] = $row['parentid'];
			$data['maxnum'] = $row['maxonline'];
			$data['locked'] = $row['locked'];
			$this->DB->insert(VODCMS_SERVER, $data);
			
		}
		echo '导入服务器数据完成<br >';
		unset($row);unset($data);
	}
	public function upUrl(){
		$data = null;
		$sql = 'SELECT * FROM '.$this->tblpre.'url';
		echo '正在导入影片地址数据...<br >';
		$this->DB->query('truncate table '.VODCMS_URL);
		foreach ($this->DB2->fetAll($sql) as $row){
			$this->DB->insert(VODCMS_URL, $row);
			
		}
		echo '导入影片地址数据完成<br >';
		unset($row);
	}
	public function upUserGroup(){
		$data = null;
		$sql = 'SELECT * FROM '.$this->tblpre.'usergroup';
		echo '正在导入用户组数据...<br >';
		$this->DB->query('truncate table '.VODCMS_USERGROUP);
		foreach ($this->DB2->fetAll($sql) as $row){
			$this->DB->insert(VODCMS_USERGROUP, $row);
			
		}
		echo '导入用户组数据完成<br >';
		unset($row);
	}
	public function upNetBar(){
		$data = null;
		$sql = 'SELECT * FROM '.$this->tblpre.'netbar';
		echo '正在导入用户组数据...<br >';
		$this->DB->query('truncate table '.VODCMS_NETBAR);
		foreach ($this->DB2->fetAll($sql) as $row){
			$data['id'] = $row['id'];
			$data['name'] = $row['netbar'];
			$data['sip'] = sprintf('%u', ip2long($row['sip']));
			$data['eip'] = sprintf('%u', ip2long($row['eip']));
			$data['usergroup'] = 0;
			$data['maxnum'] = $row['maxonline'];
			$data['phone'] = $row['phone'];
			$data['pass'] = $row['password'];
			$data['username'] = $row['username'];
			$data['address'] = $row['address'];
			$data['lifetime'] = $row['lifetime'];
			$data['addtime'] = $row['addtime'];
			$data['admin'] = 'admin';
			$data['locked'] = $row['locked'];
			$this->DB->insert(VODCMS_NETBAR, $data);
			
		}unset($data, $row);
		echo '导入用户组数据完成<br >';
	}
	public function upnote(){
		$data = null;
		$this->DB->query('truncate table '.VODCMS_AFFICHE);
		$sql = 'SELECT * FROM '.$this->tblpre.'note';
		echo '正在导入用户组数据...<br >';
		foreach ($this->DB2->fetAll($sql) as $row){
			$data['title'] = $row['subject'];
			$data['type'] = 1;
			$data['content'] = $row['content'];
			$data['addtime'] = $row['addtime'];
			$data['click'] = $row['click'];
			$data['locked'] = 0;
			$this->DB->insert(VODCMS_AFFICHE, $data);
			unset($data);
		}
		echo '导入用户组数据完成...<br >';
	}
}?>