<?php
session_start();
if($action=='logout'){
//注销
session_unset();
session_destroy();
?>
<script language="javascript">
alert("已注销");
location.href="index.php";
</script>
<?php
}elseif($_SESSION['uid']){
//已登录
if($op=='edittype'&&$_POST[typename]&&$_POST[tid]){//修改type
require_once "conn.php";
$query="update type set typename='".$_POST[typename]."' where tid='".$_POST[tid]."'";
$info=mysql_query($query);
echo "<script language=\"javascript\">alert(\"分类名称已更改\");location.href=\"admincp.php?action=type\";</script>";
exit();
}elseif($op=='deltype'&&$tid){//删除type
require_once "conn.php";
$query="select count(*) ct from content where tid='".$tid."'";
$info=mysql_query($query);
while($result=mysql_fetch_array($info,MYSQL_ASSOC)){
if($result[ct]!=0){
echo "<script language=\"javascript\">alert(\"有主题的分类无法删除,请先删除分类下的主题!\");location.href=\"admincp.php?action=type\";</script>";
mysql_close($connection);
exit();
}
}
$query="delete from type where tid='".$tid."'";
$info=mysql_query($query);
mysql_close($connection);
echo "<script language=\"javascript\">alert('删除成功');location.href=\"admincp.php?action=type\";</script>";
exit();
}elseif($op=='newtype'&&$_POST[newtype]){//新建分类
require_once "conn.php";
$query="insert into type set typename='".$_POST[newtype]."'";
$info=mysql_query($query);
echo "<script language=\"javascript\">alert(\"新建分类成功\");location.href=\"admincp.php?action=type\";</script>";
exit();
}elseif($op=="delcontent"&&$cid){//删除发布信息
require_once "conn.php";
$query="delete from content where cid='".$cid."'";
$info=mysql_query($query);
mysql_close($connection);
echo "<script language=\"javascript\">alert('删除成功');location.href=\"admincp.php?action=content\";</script>";
exit();
}
require_once "top.php";
?>
<div id="content">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="15%" style="BORDER-RIGHT: #d2d2d2 1px solid; BORDER-TOP: #d2d2d2 1px solid"
vAlign=top width=180 height="100%">
<table cellSpacing=0 cellPadding=4 width="100%" align=center border=0>
<tr><td colspan=3 background="images/menu_top.gif"> </td></tr>
<tr><td> </td><td colSpan=2 align ="left">
<STRONG style="FONT-SIZE: 16px; COLOR: #0066cc">内容分类:</STRONG></td></tr>
<tr><td> </td><td align=right width="16%"><IMG src="images/arrow4.gif"></td><td align ="left"><a href="admincp.php?action=type">分类管理</a></td></tr>
<tr><td> </td><td align=right width="16%"><IMG src="images/arrow4.gif"></td><td align ="left"><a href="admincp.php?action=content">内容管理</a></td></tr>
<tr><td> </td><td align=right width="16%"><IMG src="images/arrow4.gif"></td><td align ="left"><a href="admincp.php?action=newcontent">发布内容</a></td></tr>
<tr><td> </td><td align=right width="16%"><IMG src="images/arrow4.gif"></td><td align ="left"><a href="admincp.php?action=logout">退出系统</a></td></tr>
</table>
</td>
<td width="80%" align="center" valign="top"><br />
<?php
if($action=='type'){
require_once "conn.php";
$query="select * from type";
$info=mysql_query($query);
$typearr=array();
while($result=mysql_fetch_array($info,MYSQL_ASSOC)){
$typearr[]=$result;
}
?>分类管理:
<table width="90%" border="2" cellspacing="1" cellpadding="0">
<tr>
<td width="20%">类别ID</td>
<td width="50%">类别名</td>
<td width="30%">操作</td>
</tr>
<?php
foreach($typearr as $type){
echo " <form action=\"admincp.php?op=edittype\" method=\"post\"><input type=\"hidden\" name=\"tid\" value=\"$type[tid]\"/><tr>
<td>$type[tid]</td>
<td><input type=\"text\" name=\"typename\" value=\"$type[typename]\"/></td>
<td><input type=\"submit\" value=\"修改\"> <input type=\"button\" value=\"删除\" onclick=if(confirm(\"确定删除?\")){location=\"admincp.php?op=deltype&tid=$type[tid]\";}></td>
</tr></form>";
}
?>
</table><br /><form action="admincp.php?op=newtype" method="post">
<table width="90%" border="2" cellspacing="1" cellpadding="0">
<tr>
<td width="20%">新建类别:</td>
<td width="50%"><input type="text" name="newtype" value=""/></td>
<td width="30%"><input type="submit" value="新建类别"/></td>
</tr>
</table>
<br>
<br>
<br>
</form><?php
}elseif($action=='content'){
require_once "conn.php";
$query="select * from content";
$info=mysql_query($query);
$contentarr=array();
while($result=mysql_fetch_array($info,MYSQL_ASSOC)){
$result[dateline]=date("Y-m-d",$result[dateline]);
$contentarr[]=$result;
}
?>内容管理:<br /><br />
<table width="90%" border="2" cellspacing="1" cellpadding="0">
<tr>
<td width="10%">类别ID</td>
<td width="50%">标题</td>
<td width="10%">作者</td>
<td width="15%">时间</td>
<td width="15%">操作</td>
</tr>
<?php
foreach($contentarr as $content){
echo "<tr>
<td>$content[tid]</td>
<td>$content[subject]</td>
<td>$content[author]</td>
<td>$content[dateline]</td>
<td><input type=\"button\" value=\"修改\" onclick=if(confirm(\"确定修改?\")){location=\"admincp.php?action=editcontent&cid=$content[cid]\";}> <input type=\"button\" value=\"删除\" onclick=if(confirm(\"确定删除?\")){location=\"admincp.php?op=delcontent&cid=$content[cid]\";}></td>
</tr>";
}
?>
</table><br />
<br>
<br>
<br><?php
}elseif($action=='newcontent'){
require_once "conn.php";
$query="select * from type";
$info=mysql_query($query);
$typearr=array();
while($result=mysql_fetch_array($info,MYSQL_ASSOC)){
$typearr[]=$result;
}
?>
<p>发布内容:<br>
<br><form action="post.php" method="post"><div align="center" width="90%">
<table width="90%" border="2" cellspacing="1" cellpadding="1">
<tr>
<td width="15%">选择类别:</td>
<td><select name="type" id="type">
<?php
foreach ($typearr as $type){
echo "
<option value=\"$type[tid]\">$type[typename]</option>";
}?>
</select></td>
</tr>
<tr>
<td width="15%">标题:</td>
<td><input name="subject" type="text" id="subject" size="80"></td>
</tr>
<tr>
<td width="15%" valign="top">内容:</td>
<td><textarea name="message" cols="80" rows="20" id="message"></textarea></td>
</tr>
</table><br /><input type="submit" value="发表"/></form>
<?php
}elseif($action=='editcontent'&&$cid){
require_once "conn.php";
$query="select * from type";
$info=mysql_query($query);
$typearr=array();
while($result=mysql_fetch_array($info,MYSQL_ASSOC)){
$typearr[]=$result;
}
$query="select * from content where cid='".$cid."'";
$info=mysql_query($query);
if($content=mysql_fetch_array($info,MYSQL_ASSOC)){?>
<p>修改内容:<br>
<br><form action="post.php?action=edit" method="post"><input type="hidden" name="cid" value="<?php echo $content[cid];?>"/><div align="center" width="90%">
<table width="90%" border="2" cellspacing="1" cellpadding="1">
<tr>
<td width="15%">选择类别:</td>
<td><select name="type" id="type">
<?php
foreach ($typearr as $type){
echo "<option value=\"$type[tid]\"";
if($type[tid]==$content[tid]){echo " selected";}
echo ">$type[typename]</option>";
}?>
</select></td>
</tr>
<tr>
<td width="15%">标题:</td>
<td><input name="subject" type="text" id="subject" size="80" value="<?php echo $content[subject]?>"></td>
</tr>
<tr>
<td width="15%" valign="top">内容:</td>
<td><textarea name="message" cols="80" rows="20" id="message"><?php echo $content[message]?></textarea></td>
</tr>
</table><br /><input type="submit" value="修改"/></form>
<?php
}else{
}
}else{