<?php 
    
    require "../../Run.php";
 
    echo head('文章上传').'<body>';
	if($login == 1){              /*如果用户已经登录*/
	if($admin == 1||$admin == 2){ 
    if($_POST['add'] == 'y'){
	if($_POST['title'] == NULL || $_POST['content'] == NULL){
	   die("标题内容均不能为空！");
	   }
	/*文件处理机制问题暂时停止此功能*/
	date_default_timezone_set('PRC');
	$D = date(YmdHis);
	$filetype = substr(strrchr($_FILES['userfile']['name'],"."),1);
	$newname = $D.".".$filetype;
	$uploaddir = $_SERVER['DOCUMENT_ROOT'].'/article/uploads/';
    $UploadFile = $uploaddir.$newname;//$_FILES['userfile']['name'];
    $UploadPath = Addslashes(dirname($PATH_TRANSLATED))."/uploads";
    $FileName = $uploadPath.$UploadFile_name;	
	/*上传文件检测*/
	$error=$_FILES['userfile']['error'];
	if($error == 1){ 
	   echo '上传失败：你上传的文件超过了php的系统约定值！';
	}elseif($error == 2){
	   echo '上传失败：上传的文件超过了表单设置的最大值！';
	}elseif($error == 3){
	   echo '上传失败：文件只有部分被上传';
    }elseif($error == 5){
	   echo '上传失败：发生未知错误！';
	}elseif($error == 4){
	     $pic = NULL;
	}else{
	    $allowtype = array("jpeg","png","jpg","gif");
		if(!in_array($filetype,$allowtype)){
		   echo '上传失败：您上传的文件类型不是图片！';
		   }else{
            if(move_uploaded_file($_FILES['userfile']['tmp_name'],$UploadFile)){
	        echo "文件上传成功";
	        $picpath="../uploads/".$newname;
	        $pic=$newname;
	        $newpicpath="../uploads/simage/s".$newname;
	        $newpic='s'.$newname;
	        simage($picpath,150,150,$newpicpath,$filetype);
	        }else{
	        echo "文件上传失败";
	        $pic==NULL;
	              }
               }
		  }       
	/*文件处理结束,文章信息处理开始*/
	$time=date("Y-m-d");
    echo "$time";
	
	$content = htmlspecialchars($_POST['content'], ENT_QUOTES); 
	$article="INSERT INTO article(title,userid,name,gro,content,time,pic,top,spic,siteid)VALUES
	('{$_POST["title"]}','{$id}','{$_POST["name"]}','{$_POST['gro']}','{$content}','{$time}','{$pic}','NULL','{$newpic}','{$wapid}')";
	$article=mysql_query($article);
    if($article && mysql_affected_rows()>0){
	echo "<div class=\"tip\">";
    echo "文章已经成功上传了！<br>";
	echo "请阅读检查";
	echo "</div>";
	}else{
	echo "上传失败!请重试或者联系网站管理员！";
	     }
	}
    echo "
	<div class=\"title\">文章上传</div>
	<div class=\"content\">
    <form method=\"post\" enctype=\"multipart/form-data\" action=\"add.php?cid=".$_GET['cid']."\">      
    <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='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\" style=\"width:80%;height:300px;\" ></textarea><br>
    <input type=\"file\" name=\"userfile\" id=\"fileField\" value=\"图片上传\"/>
    <br> <input type=\"submit\" value=\"上传文章\"><br></form></div>";
	echo "<div class=\"mylink\"><a href=\"list.php?cid=".$_GET['cid']."&sid=".$sid_info."\">返回上级</a><a href=\"../../index.php?sid=".$sid_info."\">网站首页</a></div>";
    }else{
     echo"您无权进入此页面，请联系管理员！";
    }
	}else{
    echo"您好，您尚未登录！";}
	  ?>	         
</body></html>