具有树状结构的文本论坛(二)——主程序框架

    下面的PHP代码是该论坛主程序的框架forum.php文件:
<?
  
@session_start();
  require(
"funcdef.php");
  if(
$submit == "登录"
  {
    if(
checkuser($username$password) == true)
    {
      
session_register("username");
      
$headstr "Location:forum.php?".session_name()."=".session_id();
      
header($headstr);
    }
    else
    {
      include(
"loginerr.php");
    }
  }
  if(
$submit == "注销")
  {
    
session_unregister("username");
    
$headstr "Location:forum.php?".session_name()."=".session_id();
    
header($headstr);
  }
?>

<html>
<head>
<title>我的论坛</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<? 
  
if(!isset($action))
    
$action "themelist";   
  @
session_start();
  if(
$action == 'themelist')    //列出主题
  
{
    echo 
"<body bgcolor='#CCFFCC'>";
    echo 
"<table width='100%' border='0'><tr><td width='400'>";
    echo 
"<h1 align='center'><i><font color='#990000'>MYFORUM BETA1.0</font></i></h1>";
    echo 
"</td><td width='350' valign='baseline'>";
    echo 
"<div align='center'><font color='#6600CC'>";
  
    if(!
session_is_registered("username"))
    {  
      echo 
"<form name='login'>";
      echo 
"名字:";
      echo 
"<input type='text' name='username' maxlength='16' size='10'>&nbsp;";
      echo 
"密码:";
      echo 
"<input type='password' name='password' maxlength='16' size='10'>&nbsp;";
      echo 
"<input type='submit' name='submit' value = 登录>";  
      echo 
"</form>";
    }
    else
    {
      echo 
"欢迎光临!".htmlspecialchars($username)."!&nbsp;";
      echo 
"<a href = forum.php?submit=注销>取消登录</a>";
    }
  
    echo 
"</font></div></td></tr></table>";
    echo 
"<table width='100%' border=0><td><div align='left'>";
    echo 
"共有".get_total_theme()."个主题";
    echo 
"&nbsp;".get_total_note()."个帖子";
    echo 
"</div></td><td><div align='right'>";
    
$str "forum.php?action=addnew&".session_name()."=".session_id();
    echo 
"<a href=$str title='创建新的主题'>加新主题</a>&nbsp;";
    echo 
"<a href=$home_url title='回到主页'>返回主页</a></div></td></table>"
    
    include(
"listtheme.php");    //列出主题列表
    
    
}
    
    else if(
$action == 'read')    //读某一主题的树状内容
    
{
      if(isset(
$id)&&isset($title))
        include(
"listtree.php");
    }
    
    else if(
$action == 'addnew')//加新主题
    
{
      include(
"addnew.php");
    }
    
    else if(
$action == 'reply')    //回复主题
    
{
      include(
"reply.php");   
    }
    
    else if(
$action == 'edit')    //编辑/删除某个帖子
    
{
      include(
"edit.php");  
    }
    
    else if(
$action == 'search')//主题检索
    
{
      include(
"search.php");
    }
?>
</body>
</html>    

    这只是一个框架,各个部分的具体实现代码还没给出。下次将介绍用户登录部分。(未完待续)