<?php 
    require "../../Run.php";
    require "../../include/class/upload.class.php";
    require "../../include/getmkurl.fun.php";
    require "../../include/class/simage.class.php";
	echo head('文章上传');
	if($login == 1){              /*如果用户已经登录*/
	if($admin == 1||$admin == 2){ 
    if($_POST['add'] == 'y'){
	if($_POST['title'] == NULL || $_POST['content'] == NULL){
	   die("标题内容均不能为空！");
	   }
	/*文件上传*/
	$wapid = WAPID;
	
	$username = $name;
	
	$path = 'uploads/'.WAPID.'/'.date('Ymd',time());
	
	$allowtype = array("jpeg","png","swf","3gp","mp4","avi","gif","jpg");
	
	$nums = $_GET['nums'];
	
	if($nums <1){$nums = 1;}
	
	$fileid = 'pic_file';
	
	$upload = new file($wapid,$username,'../'.$path,$allowtype,$nums,$fileid);
	
	$upload_back = $upload->uploadfile();
	$i = 1;
	$upload_text = NULL; 
	foreach($upload_back as $value){
		if($value != '0' && $value !='-1' ){
			$upload_text .=  '[文件'.$i.']上传成功!<br>';
			if(!is_dir("../uploads/100_100/")){mkdir("../uploads/100_100/");}
			if(!is_dir("../uploads/240_200/")){mkdir("../uploads/240_200/");}
			if(!is_dir("../uploads/300_240/")){mkdir("../uploads/300_240/");}
			$upload_url[] = $path.'/'.$value;
			simage('../'.$path.'/'.$value,'100','100','../uploads/100_100/'.$value,$type);
			simage('../'.$path.'/'.$value,'240','200','../uploads/240_200/'.$value,$type);
			simage('../'.$path.'/'.$value,'300','240','../uploads/300_240/'.$value,$type);
			$simg[] = 'uploads/300_240/'.$value;
		}else{
			$upload_text .=NULL;
		}
		$i++;
	}
	 $file_url_str = implode("|",$upload_url);
	 $file_simg_str = implode("|",$simg);
	/*文件处理结束,文章信息处理开始*/
	$time = time();
	$article="INSERT INTO article(title,userid,name,gro,content,time,pic,top,spic,siteid)VALUES
	('{$_POST["title"]}','{$id}','{$_POST["name"]}','{$_POST['gro']}','{$_POST['content']}','{$time}','{$file_url_str}','NULL','{$file_simg_str}','{$wapid}')";
	$article=mysql_query($article);
    if($article && mysql_affected_rows()>0){
	echo "<div class=\"tip\">";
	echo $upload_text;
    echo "文章已经成功上传了！<br>";
	echo "请阅读检查";
	echo "</div>";
	}else{
	echo "上传失败!请重试或者联系网站管理员！";
	     }
	}
    echo "
	<div class=\"title\">文章上传</div>
	<div class=\"content\">
	<form method=\"get\" enctype=\"multipart/form-data\" action=\"add.php?\">    
	<input type=\"hidden\" value=\"".$_GET['cid']."\" name=\"cid\"><br>
	<input type=\"text\" value=\"5\" name=\"nums\"><br>
	<input type=\"submit\" value=\"多图模式\">
	</form>
    <form method=\"post\" enctype=\"multipart/form-data\" action=\"add.php?cid=".$_GET['cid']."&nums=".$_GET['nums']."\">      
    <br><input type=\"text\" name=\"title\"  value=\"文章标题\">
    <input type=\"hidden\" name=\"add\" value=\"y\">
    <br>
    <input type=\"text\" name=\"name\" value=\"来源/作者\">
    <br>
    栏目分类
    <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>
    文章内容
    <br>
    <textarea name=\"content\" ></textarea><br>";
	
	$nums=$_GET['nums'];
	
	if($_GET['nums'] == NULL || $_GET['nums'] == ""){$nums = 1;};
	for($i=1;$i<=$nums;$i++){
   echo "<input type=\"file\" name=\"pic_file".$i."\" id=\"fileField\" value=\"图片上传\"/><br>";
   }
    echo " <br> <input type=\"submit\" value=\"上传文章\"></form></div>";
	echo "<div class=\"mylink\"><a href=\"list.php?cid=".$_GET['cid']."\">返回上级</a><a href=\"../../index.php?\">网站首页</a></div>";
    }else{
     echo"您无权进入此页面，请联系管理员！";
    }
	}else{
    echo "您好，您尚未登录！";
	}
	echo footer(1);
?>	         