<?php 
    require "../../Run.php";
	echo head('文章内容修改').'<body>';
    if($login==1){              /*如果用户已经登录*/
	if($admin==1||$admin==2){
	if($_GET['article_mod'] == 'yes'){
	$sql = "SELECT articleid,pic FROM article WHERE articleid='{$_GET['id']}' AND siteid={$wapid}";
	$view = mysql_query($sql);
	list($articleid,$pic) = mysql_fetch_row($view);
	 if($pic != NULL){
	 $file = '../uploads/'.$pic;
	 unlink($file);
	 $file = '../uploads/simage/s'.$pic;
		unlink($file);
	 }
    //文件上传
	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){
		echo NULL;
	     $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,NULL);
	        }else{
	        echo "文件上传失败";
				$pic == NULL;
					}
				}
			}       
	$sql = "UPDATE article SET title='{$_POST["title"]}',name='{$_POST["name"]}',content='{$_POST["content"]}',pic='{$pic}',spic='{$newpic}' WHERE articleid='{$_POST["articleid"]}' AND siteid={$wapid}";
    $result = mysql_query($sql);
	echo "<div class=\"tip\">";
	if($result && mysql_affected_rows()>0){
	echo "修改成功";
    }else{
    echo "修改失败";
    };
	echo "<a href=\"mod.php?cid=".$_GET['cid']."&page=".$_GET['page']."&id=".$articleid."&sid=".$sid_info."\">点击返回文章修改</a></div>";
	}else{
    $sql="SELECT articleid,gro,userid,title,content,pic,name,time FROM article WHERE articleid=
	'{$_GET['id']}'";
	$view = mysql_query($sql);
	  /*数据验证*/
	if($view && mysql_num_rows($view)>0){
	list($articleid,$gro,$userid,$title,$content,$pic,$nc,$time) = mysql_fetch_row($view);
	echo '<div class="title">文章修改</div><div class="content">';
	echo "<form method=\"post\" enctype=\"multipart/form-data\" action=\"mod.php?article_mod=yes&id=".$articleid."&page=".$_GET['page']."&sid=".$sid_info."\">
    <br> <input type=\"text\" name=\"title\" value=\"".$title."\">
    <input type=\"hidden\" name=\"articleid\" value=\"".$_GET['id']."\">
	<input type=\"hidden\" name=\"cid\" value=\"".$_GET['cid']."\">
    <br><input type=\"text\" name=\"name\"  value=\"".$name."\">
    <br>文章内容<br><textarea name=\"content\" style=\"width:80%;height:300px;\">".$content."</textarea><br>";
	if($pic != NULL && $pic != ''){
	echo "图片地址[/article/uploads/".$pic."]<br>
	小图地址[/article/uploads/simage/s".$pic."]";
	}
	echo"<input type=\"file\"  name=\"userfile\" id=\"fileField\" value=\"图片上传\"/>
    <br><input type=\"submit\" value=\"修改文章\">
	</form></div><div class=\"mylink\"><a href=\"list.php?cid=".$gro."&sid=".$sid_info."\">返回上级</a><a href=\"../../index.php?sid=".$sid_info."\">网站首页</a></div>";
		}else{
	    echo "抱歉 内容获取失败";
				}
			}
        }else{
	    echo "您无权进入此页面，请联系管理员！";
		   }
	    }else{
		echo "登录信息错误";
		  }
    
		 ?>         
</body></html>