<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
	//把其他cms 数据库内容读到webmator 数据库中来，注意读后Num处理
	session_start();
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/ls_inccode.php');
	
	require_once('inc/check.php');
	$db1="hebspw.com";
	$db2="hebspw.comold";
	
	$opendb=new mydb($db1);
	require_once('inc/char_set.php');
    include('widget/1transdbvar.php');
 	
	$selecttable=trim($_GET['selecttable']);
	$config_sql="select * from ls_config ";
	$config_query=$opendb->query($config_sql);
	$config_rows=mysql_fetch_assoc($config_query);
		
	$test=trim($_POST['test']); // 测试转移的数据
	$testsql=trim($_POST['testsql']); // 测试sql
	
	$transsqlinittest= "INSERT INTO `".$selecttable."`(id, functionName, articleTitle, articleText, articleDate) SELECT   id, functionName, articleTitle, articleText, articleDate FROM `".$db2."`.temp4 " ;	
	
	if($test!=""){
		//$testtable=trim($_POST['testtable']); 
		 
		$test_sql="create table  ".$selecttable.rand(10,1000)." SELECT * FROM  $selecttable  ";
		$test_query=$opendb->query($test_sql); // 复制
		
		$test_sql="truncate table  $selecttable  ";
		$test_query=$opendb->query($test_sql); // 清空

		if($testsql=="")$testsql=$transsqlinittest;  // 执行转移语句
		
		$test_query=$opendb->query($testsql);
		 if($test_query) $ls_msg.=$db1." 的 ".$selecttable." 表已导入， 最后 ID " .$opendb->insert_id() ;
 	}
	
	
	$transsqlinit="CREATE TABLE temp4 AS 
SELECT  `a`.id, `a`.truetime, `a`.title, `c`.classpagekey,    `b`.newstext, `c`.classname, `c`.intro	  
FROM phome_ecms_news as `a`
LEFT JOIN phome_ecms_news_data_1 as `b` ON `a`.id = `b`.id
LEFT JOIN phome_enewsclass as `c` ON `b`.classid = `c`.classid

UPDATE ls_article SET enable =1
UPDATE ls_article SET cateName = functionName
UPDATE ls_article  as `a`   LEFT JOIN ls_functioncates as `b` ON `b`.cateName = `a`.cateName SET a.functionName =b. functionName
UPDATE ls_article SET functionName = cateName WHERE functionName IS NULL
UPDATE ls_article SET articleText = replace(articleText ,'\\\\','')

SELECT * FROM `ls_article` WHERE   functionName ='专家团队'
SELECT * FROM `ls_article` WHERE   cateName='专家团队'
update `ls_article` set functionName='专家团队' WHERE   cateName='专家团队'
UPDATE ls_article  as `a`   LEFT JOIN temp4 as `b` ON `b`.id = `a`.id SET a.articleDate =FROM_UNIXTIME(b.truetime)  
UPDATE ls_article  as `a`   LEFT JOIN temp4 as `b` ON `b`.id = `a`.id SET a.articleText =CONCAT(a.articleText ,'<br/><img src=\" ',b.titlepic  ,'\" />')

ALTER TABLE  `temp4` CHANGE  `title`  `articleTitle` CHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT  ''

ALTER TABLE  `temp4` ADD  `cateName` VARCHAR( 50 ) NOT NULL AFTER  `functionName` ,
ADD  `description` VARCHAR( 150 ) NOT NULL AFTER  `keywords`

 
";
    

?>

<link href="css/admin.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="css/style2.css" />
<script language="JavaScript" src="js/jquery.js"></script>
<script language="JavaScript" src="js/ls.js"></script>
<title>mutiLang</title>
</head>
<body>
<div> 
<?= $ls_msg?>		  
<form id="adfastmanual" name="adfastmanual" method="post" enctype="multipart/form-data"  action="<?php echo $PHP_SELF;?>">
        
    <a href='http://192.168.2.20/phpMAd/sql.php?db=<?=$db1?>&table=<?=$selecttable?>' target='_blank' ></a>
    <div align="center">
     <table width="80%" border="0" cellspacing="5">
         <tr>
           <td colspan="2" align="center"   valign="top" style="padding-left:10%"><a href='http://192.168.2.20/phpMAd/sql.php?db=<?=$db1?>&amp;table=<?=$selecttable?>' target='_blank' >【
               <?=$selecttable?>
】</a></td>
         </tr>
       <tr>
           <td colspan="2" align="center"   valign="top" style="padding-left:10%"><select name="selectdelfast1" id="selectusername1"  onchange="window.open('?selecttable='+this.value,'right','');">
             <option value=" "> --------   请选择需要转移的表  ------- </option>
             <?
	$mantplstr=""; //手工翻译拼合串
	$headlang="";
 
	
	$skipinclude=array(); // 包含这些关键字的字段跳过 

	$skiptable=array(); // 
	
	$includetable=array("ls_functioncates","ls_article","ls_products" ); // 必须包含的表
	$skiptitle=array("ID","Num","enable" ,"clickNum", "grade", "suffStr" ); // 与这些关键字相同的字段跳过 
	
		$j=0;
		$alltables="";
		$sqltable="show table status  ";
			$querytable=$opendb->query($sqltable);
			while($rowstable=mysql_fetch_assoc($querytable))
		  	{				
				$tablename=trim($rowstable['Name']);
				if($tablename==""||!strin($tablename,$includetable)) continue;
				if(!strin($tablename,$skiptable))
				{ 
					$alltables.=$tablename." , ";
					echo "<option value=".$tablename." title='".$tablename."'> ".$tablename."</option>";
				}
				 
			}
		 ?>
           </select></td>
           </tr>
         <tr>
                   <td width="50%"   valign="top" style="padding-left:10%"><?
			   if($selecttable!=""){
		 
				 $sqlcolumns   ="show columns in  ".$selecttable." "; 
					  $querycolumns   = $opendb->query($sqlcolumns); 
					 // echo $tablename."  ";
					 $transsqlinit2="【".$selecttable."】 ";

					  while($rowscolumns=mysql_fetch_assoc($querycolumns))
					  {		
						  $j++;
						  $fieldname=$rowscolumns['Field'];
						  if($fieldname=="")continue;
                           $transsqlinit2.=" ".$fieldname.", ";
							  if(!strin($fieldname,$skiptitle))
							  {
								   echo "<br/>".$fieldname.":  "; ?>
                     <select name="selectdelfast<?=$j?>" id="selectusername<?=$j?>"  onchange='$("#transsql2").val( $("#transsql2").val()+ String.fromCharCode(10)+ String.fromCharCode(10)+this.value);'>
                       <option value=" "> --------   请选择需要转移的表  ------- </option>
                       <?	include('widget/1transdbtgdb.php');  ?>
                     </select>
                     <? }
					  }  ?>
                   <?
                }
			

		?>
                   <br />
                   <br />
                    <br />
                   <?=$alltables?><br />
                   <?=$db1?><br />
                   <?=$db2?>
<br /></td>
                   <td width="50%" align="" style="padding-left:10%"><? echo $flagtablename; $thiscms=substr($flagtablename,0,5); echo $$thiscms; // CMS 数据字典提示,1transdbtgdb.php  ?></td>
             </tr>
           </table>
               
               
               <p>转移表数据从库：
                 <?=$db1." 到： ".$db2."； 标志表 flagtablename 是 ".$flagtablename?>
               </p>
               <p><input type="hidden" name="transtype" id="hiddenField2" value="<?=$transtype?>" />
                 测试语句：
	               <textarea name="transsql" cols="160" rows="8" id="transsql" ><?=$transsqlinit?> 
	             </textarea>
               </p>
               <p>
                 <button name="test" type="submit" value="测试" onClick=" "/>                  
                 导入</button>

                 <button name="submitaddlang" type="submit" value="确定" onClick=" "/>                  
                 确定</button>
                  
                  <button type="button" name="button" id="button" value="打开<?=$db2?>"  onclick='window.open("http://192.168.2.20/phpMAd/index.php?db=<?=$db2?>","_blank");'/>                       
                打开<?=$db2?></button>
             </p>
               <p>导入语句
                 ：
                   <textarea name="testsql" cols="160" rows="2" id="testsql" ><?=$transsqlinittest?> 
	             </textarea>
                 <br />
                 数据资源：
                 <textarea name="transsql2" cols="160" rows="20" id="transsql2" ><?=$transsqlinit2?> 
                  </textarea>
                 <br />
               </p>
</div>
       
        </form>   

      </p></td>
       
  </tr>
</table>
</div>
</body>
</html>