<!-- #include file="include/con_forum.asp" -->
<%
call time_lock()
if not isnumeric(forumid) then
  call format_redirect("forum.asp")
end if
%>
<!-- #include file="include/jk_convert.asp" -->
<!-- #include file="include/con_forum_fir.asp" -->
<!-- #include file="include/con_forum_write.asp" -->

<script language=javascript>
<!--
function forum_slect_color()
{
  var c=window.showModalDialog("htmledit/selcolor.html","s","dialogWidth=300px;dialogHeight=270px;status=0");
  var d=c;
  if (c && c!="")
  {
    window.document.all.item("bordercolor").bgColor=c;
    if (d.length==7) { d=d.substr(1,d.length); }
    window.document.all.tcolor.value=d;
  }
}

-->
</script>

<%
dim etc,etb,etcb,vote_n,isvote
etc=dim_num(11)
etb=dim_num(12)
vote_n=10
isvote=trim(request.querystring("isvote"))
ftit="发表主题"
if isvote="yes" then
  ftit="发表投票"
end if

call forum_first()
call web_head(2,1,h_var3,0,0)
call forum_readonly()
call convert_load(login_mode)
etc=format_convert(etc,"-")
etb=format_convert(etb,"-")
call forum_load(0,0,0,1)
'----------------------------中间 开始----------------------------
call forum_grade()
call forum_top(tit)
response.write vbcrlf&"<table cellspacing=1 cellpadding=4 class=table>"
response.write vbcrlf&"<tr><td colspan=2 class=td0>&nbsp;"&img_skin(web_img_m)&"&nbsp;"&tit&"</td></tr>"

if forumw=false then
  response.write vbcrlf&"<tr><td colspan=2 class=bg_td align=center height=200><font class=red><b>本论坛已设置为不可发贴模式！</b></font></td></tr>"
else
  if joekoe_cms.chk() then
    response.write vbcrlf&"<tr><td colspan=2 class=bg_td align=center height=200>"
    call forum_write_chk()
    response.write vbcrlf&"</td></tr>"
  else
    call forum_write_main()
  end if
end if

response.write vbcrlf&"</table>"
response.write vbcrlf&ukong
'----------------------------中间 结束----------------------------
call forum_end()
call web_end(0,0)


sub forum_write_chk()
  dim topic,icon,word,tc,tcolor,tbb,is_vote,v_type,v_day,v_name,v_num,v_dim,v_dim_num,integral_del,cb_var,found_err,nistop,nisgood,nislock
  nistop=0
  nisgood=0
  nislock=0
  if int(login_modep)=1 then
    if trim(request.form("istop"))="yes" then nistop=1
    if trim(request.form("istops"))="yes" then nistop=2
    if trim(request.form("isgood"))="yes" then nisgood=1
    if trim(request.form("islock"))="yes" then nislock=1
  end if
  integral_del=0
  cb_var=""
  topic=joekoe_cms.code_form(request.form("topic"))
  icon=form_icon()
  word=request.form("jk_word")
  tc=trim(request.form("tc"))
  tcolor=trim(request.form("tcolor"))
  tbb=0
  is_vote=0
  found_err=""
  
  if not post_tim() then
    found_err=found_err&"+对不起，发帖的间隔时间为 <font class=red>"&int(dim_num(28))&"</font> 秒！<br>"
  end if
  if login_mode="" then
    found_err=found_err&"+<font class=red>您还没有注册或登陆本站！因此不能发表主题。</font><br>"
  end if
  if val_chk("f_write_"&forumid)=false then
    found_err=found_err&"+您输入的 <font class=red>验 证 码</font> 为空或有错误，请勿非法提交！<br>"
  end if
  if topic="" or len(topic)>50 then
    found_err=found_err&"+贴子的 <font class=red>主题</font> 是必须要的，且长度不能超过50个字符！<br>"
  end if
  if tc="yes" then
    if len(tcolor)<>6 then
      found_err=found_err&"+请输入正确的 <font class=red>颜色代码</font> ！（请正确填写<font class=red2>6</font>位颜色代码）<br>"
    end if
    cb_var="加色"
    integral_del=etc
  else
    tcolor=""
  end if
  if trim(request.form("tbb"))="yes" then
    tbb=1
    integral_del=integral_del+etb
    cb_var=cb_var&"加粗"
  end if
  if int(login_integral)<int(integral_del) then
    found_err=found_err&"+发布"&cb_var&"主题要扣<font class=red>"&integral_del&"</font>分，您的积分不足（只有<font class=red>"&login_integral&"</font>分）！<br>"
  end if
  if isvote="yes" then
    is_vote=1
    v_type=0
    if trim(request.form("v_type"))="more" then
      v_type=1
    end if
    v_day=trim(request.form("v_day"))
    if not isnumeric(v_day) then
      v_day=0
    end if
    if int(v_day)>365 then
      v_day=0
    end if
    v_name=trim(request.form("v_name"))
    v_name=replace(v_name,"'","")
    v_name=replace(v_name,"|","")
    if v_name="" then
      found_err=found_err&"+请输入投票的项目，不能为空或超过<font class=red>"&vote_n&"</font>项！<br>"
    else
      v_dim=split(v_name,vbcrlf)
      v_name=""
      v_num=""
      v_dim_num=0
      for i=0 to ubound(v_dim)
        if int(v_dim_num)>(vote_n-1) then exit for
        if v_dim(i)<>"" then
          if v_name="" then
            v_name=v_dim(i)
            v_num="0"
          else
            v_name=v_name&"|"&v_dim(i)
            v_num=v_num&"|0"
          end if
          v_dim_num=v_dim_num+1
        end if
      next
      if int(v_dim_num)<2 then
        found_err=found_err&"+请输入投票的项目至少不能低于两项！<br>"
      end if
    end if
  end if
  if var_null(word)="" or len(word)>word_size*1024 then
    found_err=found_err&"+贴子的 <font class=red>内容</font> 是必须要的，且大小不能超过"&word_size&"KB！<br>"
  end if
  if found_err<>"" then
    response.write found_error(found_err,320)
    exit sub
  end if
  
  sql="insert into bbs_topic (forum_id,username,userid,topic,tcolor,tbb,icon,counter,tim,re_username,re_counter,re_tim,istop,islock,isgood,isvote,vote_num) " & _
      "values ("&forumid&",'"&login_username&"',"&login_id&",'"&topic&"','"&tcolor&"',"&tbb&",'"&icon&"',0,'"&joekoe_cms.now_time&"','"&login_username&"',0,'"&joekoe_cms.now_time&"',"&nistop&","&nislock&","&nisgood&","&is_vote&",0)"
  call joekoe_cms.exec(sql,0)
  viewid=first_id("bbs_topic","id")
  if isvote="yes" then
    sql="insert into bbs_vote (reply_id,v_name,v_num,v_type,v_tim,v_day,v_username) " & _
	"values ("&viewid&",'"&v_name&"','"&v_num&"',"&v_type&",'"&joekoe_cms.now_time&"',"&v_day&",'')"
    conn.execute(sql)
  end if
  sql="select * from bbs_data where id is null"
  call joekoe_cms.exec("",-1)
  rs.open sql,conn,1,3
  rs.addnew
  rs("forum_id")=forumid
  rs("reply_id")=viewid
  rs("username")=login_username
  rs("userid")=login_id
  rs("topic")=topic
  rs("icon")=icon
  rs("word")=word
  rs("tim")=joekoe_cms.now_time
  rs("ip")=user_ip
  rs("sys")=user_sys
  rs.update
  rs.close
  'sql="insert into bbs_data (forum_id,reply_id,username,userid,topic,icon,tim,ip,sys) " & _
  '    "values ("&forumid&","&viewid&",'"&login_username&"',"&login_id&",'"&topic&"','"&icon&"','"&joekoe_cms.now_time&"','"&user_ip&"','"&user_sys&"')"
  'conn.execute(sql)
  sql="update user_data set bbs_counter=bbs_counter+1,integral=integral+"&dim_num(9)&"-"&integral_del&" where id="&login_id
  call joekoe_cms.exec(sql,0)
  sql="update configs set num_topic=num_topic+1,num_data=num_data+1,num_new=num_new+1 where id=1"
  call joekoe_cms.exec(sql,0)
  sql="update bbs_forum set forum_new_num=forum_new_num+1,forum_topic_num=forum_topic_num+1,forum_data_num=forum_data_num+1 where forum_id in ("&forumparent&")"
  call joekoe_cms.exec(sql,0)
  sql="update bbs_forum set forum_new_info='"&login_username&"|"&joekoe_cms.now_time&"|"&viewid&"|"&topic&"' where forum_id="&forumid
  call joekoe_cms.exec(sql,0)
  
  call upload_note(index_url,viewid)
  
  application.lock
  application(joekoe_cms.web_cookies&"_configs_num_topic")=application(joekoe_cms.web_cookies&"_configs_num_topic")+1
  application(joekoe_cms.web_cookies&"_configs_num_data")=application(joekoe_cms.web_cookies&"_configs_num_data")+1
  application(joekoe_cms.web_cookies&"_configs_new_num")=application(joekoe_cms.web_cookies&"_configs_new_num")+1
  select case cstr(nistop)
  case "1"
    application(joekoe_cms.web_cookies&"_forum_istop_state_"&forumid)=empty
  case "2"
    application(joekoe_cms.web_cookies&"_forum_istops_state")=empty
  end select
  application.unlock
  
  response.write vbcrlf&"<table border=0 width=300>" & _
        	 vbcrlf&"<tr><td align=center height=30><font class=red>"&tit&"成功！谢谢您的发贴。</font></td></tr>" & _
        	 vbcrlf&"<tr><td height=30>您现在可以选择以下操作：</td></tr>" & _
        	 vbcrlf&"<tr><td>　　1、<a href='forum_view.asp?forum_id=" & forumid & "&view_id=" & viewid & "'>您所发表的主题</a>" & _
        	 vbcrlf&"<tr><td>　　2、<a href='forum_list.asp?forum_id=" & forumid & "'>返回 <b>" & forumname & "</b></a></td></tr>" & _
        	 vbcrlf&"<tr><td>　　3、<a href='forum.asp'>返回论坛首页</a></td></tr>" & _
        	 vbcrlf&"<tr><td height=30>系统将在 "&dim_num(21)&" 秒钟后自动返回 <b>" & forumname & "</b> ……</td></tr>" & _
		 vbcrlf&"</table><meta http-equiv='refresh' content='"&dim_num(21)&"; url=forum_list.asp?forum_id=" & forumid & "'>"
  call val_chk_end("f_write_"&forumid)
end sub

sub forum_write_main()
  call forum_write_frm_check()
%>
<form name=write_frm action='?forum_id=<%response.write forumid%>&isvote=<%response.write isvote%>' method=post onsubmit="javascript:frm_submitonce(this);">
<input type=hidden name=chk value='yes'>
<input type=hidden name=upid value=''>
<%response.write val_code_num("f_write_"&forumid,1)%>
<tr class=bg_td>
<td width='20%'>用户信息：</td>
<td width='80%'>用户名：<input type=username name=username value='<%response.write login_username%>' size=18 maxlength=20>&nbsp;&nbsp;
密码：<input type=password name=password value='<%response.write login_password%>' size=18 maxlength=20>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font class=gray>[ <a href='user_main.asp'>用户中心</a> ]&nbsp;&nbsp;&nbsp;&nbsp;[ <a href='login.asp?action=logout'>退出登陆</a> ]</font></td>
</tr>
<tr class=bg_tds>
<td>贴子主题：</td>
<td>
  <table border=0 cellspacing=0 cellpadding=0>
  <tr>
  <td><%call frm_topic("write_frm","topic")%></td>
  <td>&nbsp;<input type=text name=topic size=60 maxlength=50><%response.write redx%>长度不能超过50</td>
  </tr>
  </table>
</td>
</tr>
<tr class=bg_td>
<td>当前心情：</td>
<td><%response.write jk_icon(0)%></td>
</tr>
<!--------------------------------开始----------------------------------->

<tr class=bg_tds>
<td>主题加色：</td>
<td>
  <table border=0 cellspacing=0 cellpadding=0>
  <tr>
  <td><input type=checkbox name=tc value='yes' class=bg_tds></td>
  <td width=2></td>
  <td>选择加色功能后将扣取你 <font class=red><%response.write etc%></font> 分<font class=gray>（积分）</font></td>
  <td width=5></td>
  <td>颜色：#&nbsp;<input type=text name=tcolor id=tcolor value='' size=10 maxlength=7 alt='请正确填写 6 位颜色代码'></td>
  <td width=5></td>
  <td><table border=0 cellspacing=0 cellpadding=0><tr><td width=20 align=center><table id=bordercolor border=0 cellspacing=0 cellpadding=0 bgcolor=#000000><tr><td onClick="javascript:forum_slect_color();"><img border=0 src='htmledit/images/clrbox.gif' width=16 height=16></td></tr></table></td><td><font style="cursor: hand;" onClick="javascript:forum_slect_color();"><u>点击选取颜色</u></font></td></tr></table></td>
  </tr>
  </table>
</td>
</tr>
<!--------------------------------结束----------------------------------->

<tr class=bg_tds>
<td>主题加粗：</td>
<td><input type=checkbox name=tbb value='yes' class=bg_tds>&nbsp;选择加粗功能后将扣取你 <font class=red><%response.write etb%></font> 分<font class=gray>（积分）</font>
&nbsp;&nbsp;&nbsp;&nbsp;您的现有积分为：<font class=red><%response.write login_integral%></font> 分</td>
</tr>
<% if isvote="yes" then %>
<tr class=bg_td>
<td>投票选项：</td>
<td><input type=radio name=v_type value='only' class=bg_td checked>&nbsp;单选&nbsp;<input type=radio name=v_type value='more' class=bg_td>&nbsp;多选&nbsp;&nbsp;&nbsp;过期时间：<select name=v_day size=1>
<option value='0'>永不过期</option>
<option value='1'>一天</option>
<option value='7'>一周</option>
<option value='30'>一个月</option>
<option value='365'>一年</option>
</select></td>
</tr>
<tr class=bg_tds>
<td class=htd>1、每行作为一个选项；<br>2、至少不能低于两项；<br>3、最多有 <font class=red><%response.write vote_n%></font> 个选项；<br>4、超过的将自动作废；<br>5、一经发布不得修改；</td>
<td><textarea name=v_name rows=8 cols=93></textarea></td>
</td>
</tr>
<% end if %>
<tr class=bg_td>
<td><%call frm_ubb_type("class=bg_td")%></td>
<td><%call frm_ubb("write_frm","jk_word","")%></td>
</tr>
<tr class=bg_tds>
<td valign=top><table border=0><tr><td class=htd>贴子内容：<br><br><%call frm_word_size("write_frm","jk_word",word_size,"贴子内容")%><br><br><%response.write web_frm_word&"<br>长度<="&max_word&"KB"%></td></td></tr></table></td>
<td><textarea name=jk_word rows=12 cols=93 alt='按 Ctrl+Enter 可直接发送' onkeydown="javascript:frm_quicksubmit();"></textarea></td>
</tr>
<tr class=bg_td>
<td>上传文件：</td>
<td class=bg><iframe frameborder=0 name=upload_frame width='98%' height=30 scrolling=no src='upload.asp?uppath=forum&upname=&uptext=jk_word'></iframe></td>
</tr>
<tr class=bg_td>
<td>E M 贴图：</td>
<td>&nbsp;<%response.write jk_em("write_frm","jk_word")%></td>
</tr>
<% if int(login_modep)=1 then %>
<tr class=bg_td>
<td>高级选项：</td>
<td><input type=checkbox name=istop value='yes' class=bg_td>&nbsp;固顶&nbsp;<input type=checkbox name=istops value='yes' class=bg_td>&nbsp;总固顶&nbsp;<input type=checkbox name=isgood value='yes' class=bg_td>&nbsp;精华&nbsp;<input type=checkbox name=islock value='yes' class=bg_td>&nbsp;锁定</td>
</tr>
<% end if %>
<tr class=bg_tds>
<td>发表新贴：</td>
<td height=40><input type=submit value='可以发表啦' onclick="javascript:return write_frm_check(1);">　&nbsp;<%response.write preview_b("write_frm","jk_word","预览回复")%>　&nbsp;<input type=reset value='清除重写'>　&nbsp;（按 Ctrl + Enter 可快速发表）</td>
</tr>
</form>
<%
  call preview_form("write_frm","jk_word")
end sub
%>