<?php
include("qs.php");
require( '../data/config.php');
$conn=mysql_connect($db_host,$db_user,$db_pass);
mysql_query("set names 'utf8'");
mysql_select_db($db_name);
if (PHP_VERSION >= '5.1' && !empty($timezone))
{
    date_default_timezone_set($timezone);
}
$action=_get('action');
if($action=="")
$action=_post('action');
$id=_get('id');
if($id=="")
$id=_post('id');
$qs=explode(",",$_SESSION["tm_qs"]);
if($qs[1]==0)
   {
   echo "<script>location.href='main.php';</script>";
   exit();
   }
$uid=$_SESSION["tm_id"];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<META http-equiv="Pragma" content="no-cache" />
<LINK href="css/general.css" rel="stylesheet" type="text/css" />
<LINK href="css/main.css" rel="stylesheet" type="text/css" />
</HEAD><BODY>
<?php 
if($action=="del")
{
if(isset($_POST['chkkindid']) && is_array($_POST['chkkindid'])){
foreach($_POST['chkkindid'] as $tempid){
$exec="delete from tm_about where id=".$tempid;
mysql_query($exec);
}
}
 echo "<script>location.href='about.php';</script>";
 exit();
 }
elseif($action=="tj")
 {
if(isset($_POST['chkkindid']) && is_array($_POST['chkkindid'])){
foreach($_POST['chkkindid'] as $tempid){
$exec="update tm_about set tj=1 where id=".$tempid;
mysql_query($exec);
}
}
 echo "<script>location.href='about.php';</script>";
 exit();
 }
elseif($action=="utj")
 {
if(isset($_POST['chkkindid']) && is_array($_POST['chkkindid'])){
foreach($_POST['chkkindid'] as $tempid){
$exec="update tm_about set tj=0 where id=".$tempid;
mysql_query($exec);
}
}
 echo "<script>location.href='about.php';</script>";
 exit();
 }
elseif($action=="add")
{
$title=_post('title');
$cont=_post('cont');
$name=_post('name');
$date=date('Y-m-d');
$sql="insert into tm_about(title,name,cont,date) values('$title','$name','$cont','$date')";
mysql_query($sql);
echo "<script>location.href='about.php';</script>";
 exit();
}
elseif($action=="edit")
{
$title=_post('title');
$cont=_post('cont');
$name=_post('name');
$sql="update tm_about set title='$title',name='$name',cont='$cont' where id='$id'";
mysql_query($sql);
 echo "<script>location.href='about.php';</script>";
}
?>
<div class="h2">系统管理 >> 公告管理 >> <?php if($id=="") echo "添加";else echo "编辑";?></div>
<div class="list-div">

<table cellspacing='1' cellpadding='3'>
<tr>
  <th align='left'><table width="100" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><div align="left">&nbsp;&nbsp;公告管理</div></td>
        <td width="150">&nbsp;</td>
      </tr>
    </table></th>
</tr>
<tr><td align="left" valign="top" style="background:#F5F5F5;padding-bottom:8px;">
<TABLE cellSpacing=0 cellPadding=0 width="97.5%" border=0 CALLPADDING="0">
<?php 			  
if($action=="" and $id=="")
{
?>
<form id="form1" name="form1" method="post" action="about_w.php">
			<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">标　题：
                                  <input name="title" type="text" id="title" size="50" />
              </span>			                  </TD>
    </TR>
	<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">作　者：
                                  <input name="name" type="text" id="name" value="<?php echo $_SESSION["tm_name"];?>" size="50" />
              </span>			                  </TD>
    </TR>
		<TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left height=30><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="50">内　容：</td>
                    <td><?php
	include_once('../fckeditor/fckeditor.php'); 
	$editor = new FCKeditor("cont");
    $editor->BasePath   = '../fckeditor/';
    $editor->ToolbarSet = 'Default';
    $editor->Width      = '100%';
    $editor->Height     = '370';
    $editor->Value      = '';
    $FCKeditor = $editor->Create(); 
?></td>
                  </tr>
                </table></TD>
			<TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left bgColor=#ffffff height=30><span class="help">
                  <input type="image" 
                        src="images/submit.gif" align="absmiddle" border="0" 
                        name="submit" onclick="return checkform(this.form)" />
                  <input name="action" type="hidden" id="action" value="add" />
                </span></TD>
              </TR>
 </form>
 <script language="javascript">
function checkform(theform)
{
if(theform.title.value=="")
  {
  alert("文章标题不能为空！");
  theform.title.focus();
  return false;
  }
return true;
}
</script>
 <?php 
 }
if($action=="" and $id<>"")
{
$sql="select * from tm_about where id='$id'";
$rsql=mysql_query($sql);
$rs=mysql_fetch_object($rsql);
if(!$rs)
   {
   echo "<script>alert('无相关文章!');location.href='about.php'</script>";
   exit();
   }
 ?>
 <form id="form1" name="form1" method="post" action="about_w.php">
			<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">标题：
                                  <input name="title" type="text" id="title" value="<?php echo $rs->title;?>" size="50" />
              </span>			                  </TD>
    </TR>
	<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">作者：
                                  <input name="name" type="text" id="name" value="<?php echo $rs->name;?>" size="50" />
              </span>			                  </TD>
    </TR>
		<TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left bgColor=#ffffff height=30><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="43">内容：</td>
                    <td><?php
	include_once('../fckeditor/fckeditor.php'); 
	$editor = new FCKeditor("cont");
    $editor->BasePath   = '../fckeditor/';
    $editor->ToolbarSet = 'Default';
    $editor->Width      = '100%';
    $editor->Height     = '370';
    $editor->Value      = $rs->cont;
    $FCKeditor = $editor->Create(); 
?></td>
                  </tr>
                </table></TD>
    </TR>
			<TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left bgColor=#ffffff height=30><span class="help">
                  <input type="image" 
                        src="images/submit.gif" align="absmiddle" border="0" 
                        name="submit" onclick="return checkform(this.form)" />
                  <input name="action" type="hidden" id="action" value="edit" />
                  <input name="id" type="hidden" id="id" value="<?php echo $id;?>" />
                </span></TD>
              </TR>
 </form>
<script language="javascript">
function checkform(theform)
{
if(theform.title.value=="")
  {
  alert("文章标题不能为空！");
  theform.title.focus();
  return false;
  }
return true;
}
</script>
 <?PHP }
 ?>
      </TABLE>
</td>
</tr></table></div>

<?php include "boot.php";?>
</body></html>