<!--#include file="Access.asp"  -->
<!-- #include file="inc/functions.asp" -->
<!-- #include file="x_to_html/index_to_html.asp" -->
<!-- #include file="x_to_html/img_content_to_html.asp" -->

<% '添加数据到数据表
act=Request("act")
If act="save" Then 
l_name=trim(request.form("name"))
l_url=trim(request.form("url"))
l_position=trim(request.form("position"))
l_image=trim(request.form("web_image"))
l_order=trim(request.form("order"))
l_memo=trim(request.form("memo"))
l_view_yes=trim(request.form("view_yes"))
a_index_push=trim(request.form("a_index_push"))
l_time=now()
picmore=trim(request.form("picmore"))

set rs=server.createobject("adodb.recordset")
sql="select CategoryID from web_img_position where id="&l_position
rs.open(sql),cn,1,1
if not rs.eof then
l_CategoryID=rs("CategoryID")
end if
rs.close
set rs=nothing



if picmore<>"" then


'批量添加图片
picmore1=split(picmore,",")
c=ubound(picmore1)
for i=0 to c
set rs=server.createobject("adodb.recordset")
sql="select * from web_img"
rs.open(sql),cn,1,3
rs.addnew
rs("name")=l_name
rs("url")=l_url
rs("position")=l_position
rs("image")=picmore1(i)
if l_order<>"" then
rs("order")=cint(l_order)
end if
rs("memo")=l_memo
rs("view_yes")=cint(l_view_yes)
rs("index_push")=a_index_push
rs("CategoryID")=l_CategoryID
rs("time")=now()

rs.update
rs.close
set rs=nothing

'图片生成
set rs_create=server.createobject("adodb.recordset")
sql="select [id],[position] from [web_img] where [image]='"&picmore1(i)&"'"
rs_create.open(sql),cn,1,1
if not rs_create.eof then
a_id=rs_create("id")
a_pid=rs_create("position")
call img_content_to_html(a_id,a_pid)
end if
rs_create.close
set rs_create=nothing

next

else
'单个添加图片
if l_image="" then
response.redirect "img_list.asp"
else
set rs=server.createobject("adodb.recordset")
sql="select * from web_img"
rs.open(sql),cn,1,3
rs.addnew
rs("name")=l_name
rs("url")=l_url
rs("position")=l_position
rs("image")=l_image
if l_order<>"" then
rs("order")=cint(l_order)
end if
rs("memo")=l_memo
rs("view_yes")=cint(l_view_yes)
rs("index_push")=a_index_push
rs("CategoryID")=l_CategoryID
rs("time")=l_time

rs.update
rs.close
set rs=nothing
'图片生成
set rs_create=server.createobject("adodb.recordset")
sql="select [id],[position] from [web_img] where [image]='"&l_image&"'"
rs_create.open(sql),cn,1,1
if not rs_create.eof then
a_id=rs_create("id")
a_pid=rs_create("position")
call img_content_to_html(a_id,a_pid)
end if
rs_create.close
set rs_create=nothing
end if

end if

response.Write "<script language='javascript'>alert('添加成功！');location.href='img_list.asp';</script>"
end if 
 %>
 

	<%
Call header()

%>

  <form id="form1" name="form1" method="post" action="?act=save">
         <script language='javascript'>
function checksignup1() {
if ( document.form1.name.value == '' ) {
window.alert('请输入图片标题^_^');
document.form1.name.focus();
return false;}


if ( document.form1.position.value == '' ) {
window.alert('请选择图片分类^_^');
document.form1.position.focus();
return false;}

if(document.form1.order.value.search(/^([0-9]*)([.]?)([0-9]*)$/)   ==   -1)   
      {   
  window.alert("排序只能是数字^_^");   
document.form1.order.focus();
return false;}

return true;}
</script>
	<table cellpadding='3' cellspacing='1' border='0' class='tableBorder' align=center>
	<tr>
	  <th class='tableHeaderText' colspan=2 height=25>添加新的图片</th>
	<tr>
	<td width="15%" height=23 class='forumRowHighLight'>图片标题 (必填)</td>
	<td class='forumRowHighLight'><input name='name' type='text' id='name' size='70'>
	  &nbsp;</td>
	</tr>
	  <tr>
	    <td class='forumRow' height=23>图片链接 </td>
	    <td class='forumRow'><input name='url' type='text' id='url' value="" size='70'>
        &nbsp;以http://开头</td>
      </tr>
	  <tr>
	    <td class='forumRowHighLight' height=23>图片分类<span class="forumRowHighLight"> (必选)</span></td>
	    <td class='forumRowHighLight'><label>
	      <select name="position" id="position">
	       <% set rsp=server.createobject("adodb.recordset")
		   sql="select id,name from web_img_position "
		   rsp.open(sql),cn,1,1
		   if not rsp.eof and not rsp.bof then
		   do while not rsp.eof 
		   %> <option value="<%=rsp("id")%>"><%=rsp("name")%></option>
            <%
			rsp.movenext
			loop
			end if
			rsp.close
			set rsp=nothing%></select>
	    </label></td>
      </tr>
	  <tr>
	    <td class='forumRow' height=23>上传图片</td>
	    <td width="85%" class='forumRow'><table width="100%" border="0" cellspacing="0" cellpadding="0">
         <tr>
           <td width="22%" ><input name="web_image" type="text" id="web_image"  size="30"></td>
           <td width="78%"  ><iframe width="500" name="ad" frameborder=0 height=30 scrolling=no src=upload_photo.asp></iframe></td>
         </tr>
       </table></td>
      </tr>
<tr>
	    <td class='forumRow' height=23>批量添加图片</td>
	    <td class='forumRow'><span class="forumRow">
	      <input name='picmore' type='text' id='picmore' value="" size='130' >
	    <br>
	    请先将图片上传致服务器photos文件夹，在此列入上传的图片名字，以,隔开。非批量上传图片请务必保持为空，否则将产生错误。</span></td>
      </tr>	  <tr>
	    <td class='forumRowHighLight' height=23>排序</td>
	    <td class='forumRowHighLight'><span class="forumRow">
	      <input name='order' type='text' id='order' value="100" size='20'>
	    &nbsp;只能是数字，数字越小排名越靠前</span></td>
      </tr>
	  <tr>
	  <td class='forumRowHighLight' height=11>备注</td>
	  <td class='forumRowHighLight'><textarea name='memo'  cols="100" rows="6" id="memo" ></textarea></td>
	</tr>
	  
	  <tr>
	  <td class='forumRow' height=23>是否显示</td>
	  <td class='forumRow'><label><input name="view_yes" type="radio" value="1" checked></label></td>
	</tr>
	<tr>
	  <td class='forumRowHighLight' height=23>推荐到幻灯</td>
	  <td class='forumRowHighLight'><input name="a_index_push" type="radio" value="0" checked readonly></td>
	  </tr>	
	<tr><td height="50" colspan=2  class='forumRow'><div align="center">
	  <INPUT type=submit value='提交' onClick='javascript:return checksignup1()' name=Submit>
	  </div></td></tr>
	</table>
</form>
<%
Call DbconnEnd()
 %>