<?php 
require "../../Run.php";
require "../../include/getmkurl.fun.php";
if($admin !=1 && $admin !=2 && $admin !=3){
	echo head('出错提示');
	echo '<div class="tip">权限不足</div>';
	echo footer(1);
	exit;
}
	echo head('批量导入');
	if($_GET['add'] == 'yes'){
	
	$base_dir = 'text/'; 
		$fso  = opendir($base_dir);  
		$num = 0;
		while($flist = readdir($fso)){  
			if($flist !='.' && $flist != '..' && $flist != 'title.txt')
			{
			$nums ++; 
			$file_url_str = NULL;
			$file_simg_str = NULL;
			$content = file_get_contents('text/'.$flist);
			$title   = $flist;
			$time = time();
			$wapid = WAPID;
			$article="INSERT INTO article(title,userid,name,gro,content,time,pic,top,spic,siteid)VALUES('{$title}','{$id}','网站转载','{$_POST['gro']}','{$content}','{$time}','{$file_url_str}','NULL','{$file_simg_str}','{$wapid}')";
			$article=mysql_query($article);
				if($article && mysql_affected_rows()>0){
				$ok[] = 'ok';
					}	
			}
		}  
	echo '<div class="tip">成功导入'.count($ok).'个文件</div>';
	}else{
	$base_dir = 'text/'; 
		$fso  = opendir($base_dir);  
		$num = 0;
		while($flist = readdir($fso)){  
			if($flist !='.' && $flist != '..' && $flist != 'title.txt')
			{
			$nums ++; 
			
				}
			}  
		
		echo '<div class="title">本地TEXT批量导入</div>';
	echo '<div clas="tip">批量导入将把article/admin/text/文件下的所有.txt格式的文件一次性导入，形态检测到目前此目录下有'.$nums.'个文件</div>';
	echo "<form method=\"post\" enctype=\"multipart/form-data\" action=\"add.php?add=yes\">";
	echo '<div class="content">请选择要导入的栏目<br>';
    echo "<select name=\"gro\">";
	echo "<option value=\"".$_GET['cid']."\">".$_GET['cid']."_".class_name($_GET['cid'],'cn',$wapid)."</option>";
    $sql = "SELECT cid,xuhao,cn,gro,q,url FROM class WHERE url='".get_mkid("article/list.php")."' ORDER BY xuhao";
	/*执行数据查询语句*/  
	$result = mysql_query($sql);
	/*处理结果集*/
	if($result && mysql_num_rows($result)>0){
	$i=0;
    while(list($cid,$number,$cn,$class,$lmq,$urld)=mysql_fetch_row($result)){
	echo "<option value=\"".$cid."\">".$cid."_".$cn."</option>";
	    }
	}
	
    echo "</select><br>";
	echo '<input value="确定导入" type="submit">';
	echo '</div>';
	}
	echo footer(1);