<?
include_once("../inc/config.php");
include_once("../inc/publicfun.php");
include_once("../inc/ftbbsdbclass.php");
include_once("../pageclass.php");
include_once("../conn.php");
include_once("../admin/check_master.php");

$ftblog_old=$_POST["ftblog_old"];
$ftblog=$_POST["ftblog"];
$nav=$_GET["nav"];
$blogtype=$_GET["blogtype"];
$userid=$_GET["userid"];
$userip=GetUserIP();

if ($nav=="b"){
   $blogphoto=0;
   $n="博客分类";
}
else{
   $blogphoto=1;
   $n="相册";
}
$query = "SELECT * FROM {$tablepre}ftbbsmb";
$ftbbsmb=adminmakecache('../cache/ftbbsmb.html',$query,$expire);
$pagesize=$ftbbsmb[5];

$searchcontent=trim($_POST["searchcontent"]);
$searchkind=$_POST["searchkind"];
if ($searchcontent==""){
$searchcontent=$_GET["searchcontent"];
$searchkind=$_GET["searchkind"];
}
if ($blogtype!="" || $userid!=""){
$searchcontent=$blogtype;
$searchkind="blogtype";
}
if ($userid!=""){
$searchcontent=$userid;
$searchkind="userid";
}

if ($ftblog_old!=""){
   $id=$_POST["id"];
   $sql="select * from {$tablepre}ftblog_type where id='".$id."' and blogphoto=".$blogphoto;
   $rsa=mysql_query($sql);
   $row = mysql_fetch_array($rsa);
   $userid=$row["userid"];
   $sql="update {$tablepre}ftblog_type set blogtype='".$ftblog."' where id='".$id."' and blogphoto=".$blogphoto;
   mysql_query($sql);
   $sql="update {$tablepre}ftbbs_upload set photo_name='".$ftblog."' where photo_name='".$ftblog_old."' and userid=".$userid;
   mysql_query($sql);
}

if ($_POST["act"]=="y"){
   $sign=$_POST["sign"];
   if ($ftblog==""){
   	   echo "<SCRIPT language=JavaScript>alert('分类不能为空！');history.go(-1);</script>" ;       
       exit;
   }
   $sql="select * from {$tablepre}ftblog_type where blogtype='".$ftblog."' and sign='".$sign."' and blogphoto=".$blogphoto." order by id desc";
   $rs=mysql_query($sql);
   $myrow = mysql_fetch_array($rs);
   $numrows = mysql_num_rows($rs);
   if ($numrows==0){
   $str="insert into {$tablepre}ftblog_type(blogtype,blogphoto,qs,sign,userip,indate) values('".$ftblog."','".$blogphoto."',0,'".$sign."','".$userip."','".$getnow."')";
   mysql_query($str);
   }
   else{
	echo "<SCRIPT language=JavaScript>alert('你添加的分类已存在！');history.go(-1);</script>";       
    exit;
   }
}

$p = new ft_page;
if ($searchcontent!=""){
$sql="select * from {$tablepre}ftblog_type where blogphoto=".$blogphoto." and ".$searchkind." like '%".$searchcontent."%' order by indate desc";
}
else{
$sql="select * from {$tablepre}ftblog_type where blogphoto=".$blogphoto." order by indate desc";
}
//$sql="select * from ftblog_type where blogphoto=".$blogphoto." order by indate desc";
$rs=mysql_query($sql);
$row = mysql_fetch_array($rs);
$numrows = mysql_num_rows($rs);

$p->pvar="page"; 
$p->setvar(array("searchcontent" => $searchcontent, "searchkind" => $searchkind, "nav" => $nav));
$p->set($pagesize,$numrows,$psize); 
$rsx=mysql_query($sql." limit ".$p->limit());
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>FTBLOG</title>

<link href="../css/main01.css" rel="stylesheet" type="text/css">
</head>
<script language="javascript" src="../js/publicfun.js"></script>
<body>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
  <form name="form1" method=post action="" onsubmit="return chkForm(this)">
    <tr valign="top" class="f12"> 
      <td height="50" colspan="6" class=new14 valign="middle"> <div align="left"> 
          &nbsp;请输入默认<font color=red> 
          <?=$n?>
          </font>名称: 
          <input name="ftblog" type="text" class="text" />
          <input name="Submit" type="Submit" class="button" value="创建<?=$n?>" />
          (不是特殊需要请不要创建) 
          <input name="act" type="hidden" id="act2" value="y">
          <input name="nav" type="hidden" value=<?=$nav?>>
          <input name="blogphoto" type="hidden" value=<?=$blogphoto?>>
          <input name="sign" type="hidden" value=0>
        </div></td>
    </tr>
  </form>
  <TR align="center" class="f12"> 
    <FORM METHOD=POST ACTION="" >
      <TD align="left"> 
        <?
	  $p->output(0);
	  ?>
      </TD>
      <TD width="40%" height="25"> <div align="right"> 
          <INPUT TYPE="text" NAME="searchcontent" size=20>
          <select name="searchkind" style="width:60px">
            <option value="blogtype">分类名</option>
            <option value="userid">用户ID</option>
          </select>
          <INPUT TYPE="submit" value="搜索" name="Input">
        </div></TD>
    </FORM>
  </TR>
</TABLE>
<table width="98%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
    <td height="1" colspan="6" background="../blogimages/dotbg.gif"><spacer height="1" type="block"></td>
  </tr>
  <tr id="t1"  style="display:none" class="f12"> 
    <td height="25" colspan="6" class="f12" bgcolor="#ffffff"> <fieldset>
      <legend>修改“<span id="oldgroupname" style="color:red"></span>” 
      <?=$n?>
      名称:</legend>
      <table width="100%"  border="0" align="center" cellpadding="3" cellspacing="1">
        <tr> 
          <td colspan="2" bgcolor="#FFFFFF" class="f12"> <form name="form2" method=post action="">
              <div align="center"> 
                <input name="ftblog" type="text" class="text" id="ftblog" />
                <input name="Submit" type="submit" class="button" value="修 改" <? if (false===strrpos($_SESSION["admin_qs"],"2")){?>disabled<? }?>/>
                <input name="cannel" type="reset" id="cannel" value="取 消" class="button" onclick="closechk()">
                <input type="hidden" name="ftblog_old">
                <input name="nav" type="hidden" value=<?=$nav?>>
                <input name="id" type="hidden">
                (注意:只能是中文,英文或数字) </div>
            </form></td>
        </tr>
      </table>
      </fieldset></td>
  </tr>
  <tr class="f12" bgcolor="#F8F8F8"> 
    <td width="20%" height="25"> <div align="left"><strong>&nbsp; 
        <?=$n?>
        名称</strong></div></td>
    <td width="61%">用户ID</td>
    <td width="5%"> <div align="center">改名</div></td>
    <td width="14%"> <div align="center">权限</div></td>
  </tr>
  <tr> 
    <td height="1" colspan="6" background="../blogimages/dotbg.gif"><spacer height="1" type="block"></td>
  </tr>
  <form name="selectform" method=post action="delblogtype.php">
    <input type="hidden" name="op" value="选择转正">
    <script language="JavaScript">
  function select_pl_submit(optype){
	var f=document.forms["selectform"]
	f.op.value=optype
	f.submit()
  }
 </script>
    <?
if ($numrows!=0){
while ($row = mysql_fetch_array($rsx)){
   $sign=$row["sign"];		  
?>
    <tr class="f12"> 
      <td height="25"><div class="opt"> 
          <input name="checkbox1[]" type="checkbox" value="<?=$row["id"]?>">
          <a href="manage_blogtype.php?id=<?=$row["id"]?>&blogtype=<?=$row["blogtype"]?>"> 
          <?=$row["blogtype"]?>
          </a></div></td>
      <td height="25"><a href="manage_blogtype.php?id=<?=$row["id"]?>&userid=<?=$row["userid"]?>">
        <?=$row["userid"]?>
        </a></td>
      <td height="25" align="center"><div class="opt"><a href="#" onclick="chkid('<?=$row["blogtype"]?>','<?=$row["id"]?>')">改名</a></div></td>
      <td height="25" align="center"> <div class="opt"> 
          <? if ($nav=="b"){?>
          <? if ($sign==1){?>
          <font color=red>隐藏</font> 
          <? }else{?>
          显示 
          <? }?>
          <? }else{?>
          <? if ($sign==0){?>
          公开 
          <? }else{?>
          <font color=red>不公开</font> 
          <? }?>
          <? if ($sign==1){?>
          <font color=red>隐藏</font> 
          <? }else{?>
          显示 
          <? }?>
          <? if ($sign==2){?>
          <font color=red>已加密</font> 
          <? }else{?>
          未加密 
          <? }?>
          <? }?>
        </div></td>
    </tr>
    <tr> 
      <td height="1" colspan="6" background="../blogimages/dotbg.gif"><spacer height="1" type="block"></td>
    </tr>
    <?
}
?>
    <tr bgcolor="#F8F8F8"> 
      <td colspan="6" height="35"> <input type="checkbox" name="chkall" onclick="checkall(this.form)"> 
        <input name="button" type="button" onclick="select_pl_submit('选择删除')" value="将所选删除" <? if (false===strrpos($_SESSION["admin_qs"],"3")){?>disabled<? }?>> 
        <input name="button" type="button" onclick="select_pl_submit('选择显示')" value="将所选显示" <? if (false===strrpos($_SESSION["admin_qs"],"3")){?>disabled<? }?>> 
        <input name="button" type="button" onclick="select_pl_submit('取消显示')" value="将所选隐藏" <? if (false===strrpos($_SESSION["admin_qs"],"3")){?>disabled<? }?>> 
      </td>
    </tr>
  </form>
  <tr> 
    <td height="1" colspan="6" background="../blogimages/dotbg.gif"><spacer height="1" type="block"></td>
  </tr>
  <tr> 
    <td height="30" colspan="6" align="left"> 
      <?
     $p->output(0);
     mysql_free_result($rs);
     mysql_free_result($rsx);
     $db->close(); 
    ?>
    </td>
  </tr>
  <? }else{?>
  <tr> 
    <td height="25" colspan=6 align="center" class="f12"> 记录为空!</td>
  </tr>
  <? }?>
</table>
</body>
</html>