<?php
@session_start();
include('checkstate.php');
include('../inc/function.php');
require_once 'Excel/reader.php';
?>
<!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" />
<title>ETW国际案例演示</title>
<link rel="stylesheet" href="media/css.css" type="text/css" media="screen" />
<script type="text/javascript" src="js/modifykeyinfo.js"></script>
</head>

<body>
<div id="main">
     <div id="top"><a href="loginout.php" title="退出">退出</a></div>
     <div id="menu"><ul>
         <li><a href="index.php">管理首页</a></li><li><a href="allcompany.php">案例企业</a></li><li><a href="keymanage.php">关键字</a></li><li><a href="accountmangage.php">帐户管理</a></li>
     </ul></div>
     
     <div id="center">
        <div id="left">
        <div class="title"><strong>行业分类案例</strong></div>
            <div class="grade"><ul>
              <li><a href="allcompany.php?id=1"><img src="img/grade_img1.jpg" />上市公司</a></li>
              <li><a href="allcompany.php?id=2"><img src="img/grade_img2.jpg" />龙头企业</a></li>
              <li><a href="allcompany.php?id=3"><img src="img/grade_img3.jpg" />中小型企业</a></li>
            </ul></div>
        </div>
        
        <div id="right">
          <div class="location"><strong>当前位置 : 管理首页 >> 批量更新</strong></div>
          <div id="content">
          	<form action="importkey.php?do=up" method="post"  enctype="multipart/form-data" >
            	<input type="file" name="upfile"  /><input type="submit" name="submit" value="上传附件" />
            </form>
<?php
if(@$_GET['do']=='up'){
	$savePath="upfile/";
	
	if($_FILES['upfile']['name']!='')
	{
		$tmp_file=$_FILES['upfile']['tmp_name'];
		$file_types=explode(".",$_FILES['upfile']['name']);
		$file_type=$file_types[count($file_types)-1];
		if(strtolower($file_type)=="xls"){				 
			$file_name="keyword_".date("Ymd").".xls";			
			if(!copy($tmp_file,$savePath.$file_name)){
				echo "<span style=\"color:red;line-height: 25px;\">上传错误请重试！！<a href=# onclick=history.go(-1);>[返回]</a></span>";
			}else{
//开始更新数据库
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('UTF-8');
$data->read($savePath.$file_name);
error_reporting(E_ALL ^ E_NOTICE);
$x=0;
for($a=0;$a<3;$a++){
	for ($i = 1; $i <= $data->sheets[$a]['numRows']; $i++) {   //取得excel的数据到一个数组realdata
		for ($j = 1; $j <= $data->sheets[$a]['numCols']; $j++) {
			$item=getitem($data->sheets[$a]['cells'],$i,$j);
			echo $item."<br>";
			$realdata[$x][$j-1]=$item;
		}
		$x++;
	}
}
$del="delete from keyrank_temp";
mysql_query($sql);
print_r($realdata);
for($i=0;$i<count($realdata);$i++){
	$weburl=trim(str_replace("www.","",$realdata[$i][0]));
	$sql="select webId,comId from website where weburl like '".$weburl."' limit 0,1";
	$result=mysql_query($sql);
	if(mysql_num_rows($result)){
		$webid=mysql_result($result,0,'webId');
		$comid=mysql_result($result,0,'comId');
		$searchid=trim(str_replace("www.","",$realdata[$i][1]));
		$insert="insert into keyrank_temp(webid,keyword,transmean,searchid,rank,edittime) value($webid,'".$realdata[$i][2]."','".$realdata[$i][3]."','".$searchid."','".$realdata[$i][4]."','".date('Y-m-d')."' )";
		//echo $insert."<br>";
		//if(mysql_query($insert)){	}
	}else{
		echo  $weburl."域名在表中没有找到，请添加后重新导入<br>";
	}
}			
//更新数据库结束
				echo "<span style=\"color:red;line-height: 25px;\">上传成功!</span>";	
			}
		}
	}else{
		echo "<span style=\"color:red;line-height: 25px;\">请选择需要上传的文件!!<a href=# onclick=history.go(-1);>[返回]</a></span>";
	}
}
if(1==0){

}
?> 
          </div>
        </div>
     </div>
     
     <div id="foot"><P>copy right &copy; 2008-2009  <font color="#990000">ETW International</font></P></div>
</div>
</body>
</html>
