<?php
include_once("inc/config.php");
include_once("inc/ftbbsdbclass.php");
include_once("inc/publicfun.php");
include_once("inc/ftcode.php");
include_once("conn.php");
include_once("checkuser.php");
include_once("bbsuser.php");

$userid=intval(get_cookie('clubuser_id'));
$query = "SELECT * FROM {$tablepre}ftbbsmb";
$ftbbsmb=makecache('ftbbsmb.html',$query,$expire);
$url=$ftbbsmb[10];
$upfiletype=$ftbbsmb[12];
$upfilesize=$ftbbsmb[13];
$getcodeoff=$ftbbsmb[30];
$htm_ext=$ftbbsmb[32];
$filename=time()."a".rand(100,999).$htm_ext;

include_once("memberinfo.php");
if ($_POST["act"]=="y"){
   $codestr=trim($_POST["codestr"]);
   $blogtitle = ftbbs_request(trim($_POST["blogtitle"]));
   $blogtitle = nohtml($blogtitle);
   $blogtitle = nojs($blogtitle);
   $blogqs=intval(trim($_POST["blogqs"]));
   $plqs=intval(trim($_POST["plqs"]));
   $blogtypeid=intval(trim($_POST["blogtypeid"]));
   $xinqin=trim($_POST["DiaryHeart"]);
   $writedate=trim($_POST["writedate"]);
   $remenu=trim($_POST["remenu"]);
   $blogtag=ftbbs_request(trim($_POST["blogtag"]));
   $bbstag=trim($_POST["bbstag"]);
   $blogtag=nohtml($blogtag);
   //++++++++++++++++++以下论坛要用的数据+++++++++++++++++++++
   $zhiye=1;
   $ticon="0.gif";
   $BoardID_1 = $_POST["BoardID_1"];
   $BoardID_2 = $_POST["BoardID_2"];
   //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   $userip=GetUserIP();

   if ($ftbbsmb[7]=="M"){
      $inFolder=date("Ym",time());
    }
   else{
      $inFolder=date("Ymd",time());
    }
    if(!file_exists ($inFolder)){
      mkdir($inFolder,0777);   
    }
    $htmfilename=$inFolder."/".$filename;
    if (clearnulllen($_POST["remenu"])<=0){
    ftbbs_msg("内容不能为空","blogcenter_add.php");
    exit;
    }	
    if ($bbstag==1){
      if ($BoardID_1=="" || $BoardID_2==""){
	     echo "<SCRIPT language=JavaScript>alert('请正确选择论坛类别！');window.location.href='blogcenter_add.php';</script>";
	     exit;
      }
    }

    //阻止ip
    $sql_arrest="select * from {$tablepre}bbs_arrest where Kind='IP' order by id asc";
    $qsrs=mysql_query($sql_arrest);
    $qsrow = mysql_fetch_array($qsrs);
    $numrows = mysql_num_rows($qsrs);

    if ($numrows!=0){
       do {
        $content=$qsrow["Content"];
	    if ($content==$ip){
	       ftbbs_msg("对不起，你无权发表话题!","blogcenter_add.php"); 
	       exit;
	    }
     }
     while ($qsrow = mysql_fetch_array($qsrs));
    }
    //阻止关键字
    $sql_arrest="select * from {$tablepre}bbs_arrest where Kind='Keyword' order by id asc";
    $qsrs=mysql_query($sql_arrest);
    $qsrow = mysql_fetch_array($qsrs);
    $numrows = mysql_num_rows($qsrs);
    if ($numrows!=0){
       do {
          $content=$qsrow["Content"];
	      $blogtitle = str_replace($content,'*****',$blogtitle);
	      $remenu = str_replace($content,'*****',$remenu);		
        }
       while ($qsrow = mysql_fetch_array($qsrs)); 
     }
   
   if ($blogtypeid==""){
	  echo "<SCRIPT language=JavaScript>alert('你没有选择日志类型！');history.go(-1);</script>";       
      exit;
   }
   
   If (get_cookie('payuser')==3){
      ftbbs_msg("你的用户名被管理员封锁,请联系管理员！","blogcenter_add.php");
      exit;
    }
   if ($_SESSION["LastPostTime"]==""){
      $_SESSION["LastPostTime"]=$now;
    }
   else{
      if (datediff("MINUTE",$_SESSION["LastPostTime"],$now)<=$lxft && $lxft!=0){
	  ftbbs_msg("连续发帖间隔时间不能少于".$lxft."秒!","blogcenter_add.php");
	  exit;
	  }
      else{
      $_SESSION["LastPostTime"]=$now;
      }
    }
    session_destroy();
   if ($getcodeoff==1&&$_SESSION["code"]!=$codestr){
       ftbbs_msg("验证码错误!","blogcenter_add.php");
       exit;
    }
   
   $remenu=ubb($remenu);
   $remenu=nojs($remenu);
   
   $str="insert into {$tablepre}ftblog(blogtitle,blogcontent,blogtypeid,blogqs,writedate,xinqin,userip,blogtag,userid,plqs) values('".$blogtitle."','".$remenu."','".$blogtypeid."','".$blogqs."','".$writedate."','".$xinqin."','".$userip."','".$blogtag."','".$userid."','".$plqs."')";
   mysql_query($str);
   $str="update {$tablepre}ftblog_type set totalnum=totalnum+1 where id=".$blogtypeid." and userid=".$userid;
   mysql_query($str);
   if ($bbstag==1){ //加入论坛
      $strsql="insert into {$tablepre}bbstitle (BoardID_1,BoardID_2,name,user_id,title,zhiye,menu,ip,dateh,hit,rep,redate,P_display,img_url_display,htmfilename,flag) values('$BoardID_1','$BoardID_2','$username','$username','$blogtitle','$zhiye','$remenu','$userip','$getnow',0,0,'$getnow',1,0,'$htmfilename','0')";
      mysql_query($strsql);
      $TitleID=mysql_insert_id();
      $sql="update {$tablepre}clubuser set postnum=postnum+1 where clubuser_name='".$username."'";
      mysql_query($sql);
      mysql_query("update {$tablepre}bbs_cate set BBS_Cate_Topic=BBS_Cate_Topic+1 where BBS_Cate_ID='".$BoardID_1."'");
	  include_once("delcache.php");
   }
   echo "<script language='javascript'>window.location.href='blogcenter.php';</script>";
   //header("Location:blogcenter.php");
}
?>
<html><head><meta http-equiv=content-type content="text/html; charset=utf-8>">
</head>
<body onLoad="addbbs();">
<center>
<title><?=$username?>的日志管理中心</title>
<link rel="stylesheet" type="text/css" href="<?=$cssfile?>">
<?
include_once("usernav.php");
include_once("bokerhead.php");
?>
<div class="stage">
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="layout">
<tr>
<td valign="top" class="c2t3">
<div id="mod_profile" class="mod" rel="drag">
<?
include_once("usercalog.php");
?>
</div>
</td>
<td valign="top" class="c2t1">
<div id="m_blog" class="modbox">
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr> 
                  <td height="50"><div class="opt"><strong><font color="#FF0000">&nbsp;&nbsp; 
                    </font>&lt;&lt; 返回</strong>：<a href="blogcenter.php">日记文集</a></div></td>
                </tr>
                <tr> 
                  <td height="1" colspan="5" bgcolor="#336699" class=new14><spacer height="1" type="block"></td>
                </tr>
                <tr> 
                  <td height="10" colspan="5"></td>
                </tr>
              </table>
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <form name="form1" method="POST" action="" onsubmit="return CheckBlogForm(this)">
                  <tr> 
                    <td width="16%" height="27"> 
                      <div align="center">标题：</div></td>
                    <td width="86%"> 
                      <input name="blogtitle" type="text" id="blogtitle" size="40">
                      是否公开发表？ 
                      <select name="blogqs" id="blogqs">
                        <option value="0" selected>是</option>
                        <option value="1">否</option>
                      </select></td>
                  </tr>
                  <tr> 
                    <td height="28"> 
                      <div align="center">分类：</div></td>
                    <td><div class="opt">
                      <select name="blogtypeid" id="blogtypeid">
<?
$sql="select * from {$tablepre}ftblog_type where userid=".$userid." and blogphoto=0 order by id desc";
$rs=mysql_query($sql);
$myrow = mysql_fetch_array($rs);
do {
?>
                        <option value="<?=$myrow["id"]?>" selected><?=$myrow["blogtype"]?></option>
<?
}
while ($myrow = mysql_fetch_array($rs));
?>
                      </select>
                      <a href="blog_group.php?nav=b">创建日志分类</a> 心情： 
                      <select name="select" id="postheart" Onchange="setHeart();">
                        <option value="">无</option>
                        <option value="一般">一般</option>
                        <option value="开心">开心</option>
                        <option value="伤心">伤心</option>
                        <option value="郁闷">郁闷</option>
                        <option value="茫然">茫然</option>
                        <option value="说不清">说不清</option>
                        <option value="selfHeart">自填心情</option>
                      </select> &nbsp; <input name="DiaryHeart" id="myheart" style="display:none;" size="14" maxlength="10">
					  </div>
<script language="JavaScript">
function setHeart()
{
if(document.getElementById("postheart").value == "selfHeart")
{
document.getElementById("myheart").style.display = "";
document.getElementById("myheart").style.color = "#c0c0c0";
document.getElementById("myheart").value = "请输入自填心情";
}
else
{
document.getElementById("myheart").style.display = "none";
document.getElementById("myheart").value = document.getElementById("postheart").value;
}
}
function isNum(theNum)
{
if (theNum =="")
return false;
for(var i=0;i<theNum.length;i++){
oneNum=theNum.substring(i,i+1);
if (oneNum<"0" || oneNum>"9")
return false;
}
return true;
}
</script>
         </td>
       </tr>
                  <tr> 
                    <td height="28"> 
                      <div align="center">时间：</div></td>
                    <td> 
                      <input name="writedate" type="text" id="writedate" value="<?=$getnow?>" size="26" readonly></td>
                  </tr>
                  <tr> 
                    <td height=300></td>
                    <td> 
<TEXTAREA type="hidden" rows=1 cols=1 name="remenu" style="position:absolute;left:0;visibility:hidden;"></textarea>
<script type="text/javascript" src="fteditor/blogeditor.js"></script> 
<script type="text/javascript">
var editor = new FtEditor("editor");
editor.hiddenName = "remenu";
//editor.editorType = "simple";
editor.editorWidth = "100%";
editor.editorHeight = "250px";
editor.show();
</script>
                    </td>
                  </tr>
                  <tr> 
                    <td height="30"> 
                      <div align="center">标签：</div></td>
                    <td> 
                      <input name="blogtag" type="text" id="blogtag" value="" size="28">
                      多个标签用&quot;|&quot;线分开.</td>
                  </tr>
                  <tr> 
                    <td height="30"> 
                      <div align="center">评论：</div></td>
                    <td> 
                      <input name="plqs" type="radio" value="0" checked>
                      允许 
                      <input type="radio" name="plqs" value="1">
                      禁止</td>
                  </tr>
                  <tr> 
                    <td height="28" colspan="2"> 
                      <div align="left"><font color="#FF0000"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;  日志内容是否同时加入论坛？</font> 
                        <select name="bbstag" id="bbstag" Onchange="addbbs();">
                          <option value="1">是</option>
                          <option value="0" selected>否</option>
                        </select>
                        主论坛： 
<script LANGUAGE="javascript">
<!--
var onecount;
onecount=0;
var j;
  
subcat = new Array();
<?
$strsql="select BBS_Cate_ID,BBS_Cate_PID,BBS_Cate_Name,Initial from {$tablepre}bbs_cate where BBS_Cate_PID<>'0' and deleted=0  order by totop asc";
$rs=mysql_query($strsql);
$row = mysql_fetch_array($rs);
$rsnum= mysql_num_rows($rs);
$j=0;
do {
?>
subcat[<?=$j?>] = new Array("<?=$row[2]?>","<?=$row[1]?>","<?=$row[0]?>");
<?
$j++;
}
while ($row = mysql_fetch_array($rs))
?>

onecount=<?=$j?>;

function changelocation(locationid)
    {
    document.form1.BoardID_2.length = 0; 

    var locationid=locationid;
    var i;
    document.form1.BoardID_2.options[0] = new Option('==请选择==','');
    for (i=0;i < onecount; i++)
        {
            if (subcat[i][1] == locationid)
            { 
            document.form1.BoardID_2.options[document.form1.BoardID_2.length] = new Option(subcat[i][0], subcat[i][2]);
            }        
        }
        
    }  
function addbbs()
{
if(document.getElementById("bbstag").value == 0)
{
parent.document.form1.BoardID_1.disabled=true;
parent.document.form1.BoardID_2.disabled=true;
}
else
{
parent.document.form1.BoardID_1.disabled=false;
parent.document.form1.BoardID_2.disabled=false;
}
}
//-->
</script>
                        <select name="BoardID_1" onChange="changelocation(document.form1.BoardID_1.options[document.form1.BoardID_1.selectedIndex].value)">
                          <option value="">==请选择==</option>
<?
$str="select BBS_Cate_ID,BBS_Cate_Name from {$tablepre}bbs_cate Where BBS_Cate_PID='0' and deleted=0 order by BBS_ID asc";
$rs1=mysql_query($str);
$row1 = mysql_fetch_array($rs1);
$rsnum1= mysql_num_rows($rs1);
do {
?>
<option value="<?=$row1["BBS_Cate_ID"]?>"><?=$row1["BBS_Cate_Name"]?></option>
<?
}
while ($row1 = mysql_fetch_array($rs1));
?>
                        </select>
                        分论坛： 
                        <select name="BoardID_2">
                          <option value="">==请选择==</option>
                        </select>
                      </div></td>
                  </tr>
                  <?if ($getcodeoff==1){?>
                  <TR class="maintbtr1"> 
                    <TD width="16%" height="28"> 
                      <div align="center"> &nbsp;&nbsp;&nbsp; 验证码：</div></TD>
                    <TD width="84%"> 
                      <input name=codestr id=codestr type=text size=10 maxlength=4> 
                      <img src="getyzm.php" alt="看不清楚请点击刷新验证码" class="simg" style="cursor : pointer;" onclick="this.src='getyzm.php';" align="absmiddle">
                    </TD>
                  </TR>
                  <?}?>
                  <tr> 
                    <td height="40"> 
                      <div align="right"></div></td>
                    <td>
                      <input name="act" type="hidden" id="act" value="y"> <INPUT type="hidden" name="filename" value="<?=$filename?>">
					  <input type="submit" value="提交" class="button" name="submit1"> 
                    </td>
                  </tr>
                </form>
              </table>
            </div>
</td>
</tr></table>
</div>
</div>
<br><center>
<?
include_once("tail.php");
?>
  </center>
</center>
</body>
</html>