<%@ page contentType="text/html;charset=GBK" %>


<%@ page import="com.jivesoftware.util.RandomStrg,com.jdon.picture.*,com.jivesoftware.forum.JiveGlobals" %>



<html>
<head>
    <title>upload Image</title>
    <meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <link rel="stylesheet" href="jivejdon.css" type="text/css">
</head>
<SCRIPT language = "Javascript">
<!--
function selectpic(image){
	if ((image.toLowerCase().indexOf("c:") > -1) ||
	    (image.toLowerCase().indexOf("d:") > -1) ||
		(image.toLowerCase().indexOf("e:") > -1) ||
		(image.toLowerCase().indexOf("f:") > -1))
	{
	   
        alert("你硬盘上的图片必须上传！");

         return false;
	
	}

 if (window.opener.document.icon!=null){
             window.opener.document.icon.src=image;
             window.opener.document.form1.icon.value=image;
			 
             window.close();
}else if(window.opener.document.postForm.body!=null){
             imgtext="[img]"+image+"[/img]";
             window.opener.document.postForm.body.value += imgtext;
             window.close();

    }
}
//-->
</script>
<body>

<%
String status="";
if (request.getParameter("status")!=null)
   status=request.getParameter("status");


if (status.equals("save")){
    String icon=request.getParameter(request.getParameter("picname"));
    String uploadurl=JiveGlobals.getJiveProperty("upload.relurl");

%>
<center><img src='<%=uploadurl+icon%>' border=0 name="icon">
<br>
如果你能正常显示上面的图片，<br>
表示上传成功。
<script language="javascript">

function MM_openBrWindow(theURL,features) { //v2.0
   window.open(theURL,"adwin",features);

}

</script>
 <form>
<input type="button" value="确定" onclick="selectpic('<%=uploadurl+icon%>')" >
&nbsp;
</form>
 </center>
</center>

<%
return;
}


  if (request.getParameter("pic")==null)
    return;




  RandomStrg rstr=new RandomStrg();
  rstr.setCharset("a-zA-Z0-9");
  rstr.setLength(5);
  rstr.generateRandomObject();
  String picname=request.getParameter("pic")+rstr.getRandom();
%>

<script>
<!--
function cal()
{
var maxwidth=300;
var maxheight=300;
var x;
var y;
try
{
  if(document.all.<%=picname%>.value!="")
  {
    document.all.preview.src=document.all.<%=picname%>.value;
  }
  if ((document.all.<%=MultipartFormHandle.MAXWIDTHPARAMNAME%>.value!="")
      && (document.all.<%=MultipartFormHandle.MAXHEIGHTPARAMNAME%>.value!=""))
  {
      maxwidth=document.all.<%=MultipartFormHandle.MAXWIDTHPARAMNAME%>.value;
      maxheight=document.all.<%=MultipartFormHandle.MAXHEIGHTPARAMNAME%>.value;
      if(document.all.oldwidth.value<5)
      {
         document.all.oldwidth.value=document.preview.width;
      }else{
        document.preview.width= document.all.oldwidth.value;
      }
      if(document.all.oldheight.value<5)
      {
        document.all.oldheight.value=document.preview.height;
      }else{
        document.preview.height= document.all.oldheight.value;
      }
	  
  }


  if(document.preview.width >maxwidth)
    {

        x=document.preview.width;
        y=document.preview.height;

        nx=maxwidth;
        ny=maxwidth*y/x;
        document.preview.width=nx;
        document.preview.height=ny;
    }
     if(document.preview.height >maxheight)
    {
        x=document.preview.width;
        y=document.preview.height;
        ny=maxheight;
        nx=maxheight*x/y;
        document.preview.width=nx;
        document.preview.height=ny;
    }
    }
    catch(e)
    {
    }

}

function validate(){
    var field=document.form1.<%=picname%>;
	if (field.value.toLowerCase().indexOf("http://") > -1){
        alert("你必须提供你硬盘上图片上传");

         return false;
	
	}
    if ((field.value.toLowerCase().indexOf(".gif") <= -1) &&
        (field.value.toLowerCase().indexOf(".jpg") <= -1) &&
        (field.value.toLowerCase().indexOf(".png") <= -1))
    {
        alert("对不起，只能上传 .gif or .jpg png 等图片文件");

         return false;
    }
    return true;
}

-->
</script>
<body onmouseover=cal() >

<form name="form1" action="<%=request.getContextPath()%>/multipartformserv" method="post" enctype="multipart/form-data" onSubmit="return validate()">
<input type="hidden" name="<%=MultipartFormHandle.FORWARDNAME%>" value="upload.jsp">





<table align="center">
<tr ><td colspan=2>注意：</td></tr>
<tr ><td colspan=2>1.如图片有网址,直接输入带网址的图片后,按"确定"按钮</td></tr>
<tr ><td colspan=2>2.如图片在自己硬盘上,请用"浏览"选中图片后,按"上传"按钮</td></tr>
<tr><td>图片: </td><td><input type=file name='<%=picname%>' size=30  class=form ><br></td></tr>
<tr ><td colspan=2>上传图片大小 < <%=MultipartFormHandle.SIZE%>K </td></tr>
 <tr><td></td><td>
<input type="hidden" name="picname" value="<%=picname%>">



<%
//如果图片有大小限制，就不能使用远程网址的图片
if ((request.getParameter("maxwidth")!=null) && (request.getParameter("maxheight")!=null))
{
    %>
   <input type="hidden" name="<%=MultipartFormHandle.MAXWIDTHPARAMNAME%>" size="10" value="<%=request.getParameter("maxwidth")%>" >
   <input type="hidden" name="<%=MultipartFormHandle.MAXHEIGHTPARAMNAME%>" size="10" value="<%=request.getParameter("maxheight")%>" >
   <%

}else{
   %>
   <input type="hidden" name="<%=MultipartFormHandle.MAXWIDTHPARAMNAME%>" size="10" value="" >
   <input type="hidden" name="<%=MultipartFormHandle.MAXHEIGHTPARAMNAME%>" size="10" value="" >   
   <input type=button value="确定" class=Button onClick="selectpic(document.form1.<%=picname%>.value)">
<%}%>
<input type=submit value="上传" class=Button ><br>
<input type="hidden" name="status" value="save">
 </td></tr>

<tr><td  align=center colspan=2>
<img  name="preview" src="images/white_pix.gif">
<input type="hidden" name="oldwidth" >
<input type="hidden" name="oldheight" >

</td></tr>
</table>
</form>



