<?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');
?>
<!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_zt_class where zt_id=".$tempid;
mysql_query($exec);
}
}
echo "<script>alert('删除成功!');location.href='zt.php';</script>";
exit();
 }
elseif($action=="add")
{
$title=_post('title');
if(mysql_fetch_object(mysql_query("select * from tm_zt_class where zt_name='$title'")))
  {
  echo "<script>alert('存在相同来源');history.go(-1);</script>";
  exit();
  }
mysql_query("insert into tm_zt_class(zt_name) values('$title')");
echo "<script>location.href='zt.php';</script>";
 exit();
}
elseif($action=="edit")
{
$title=_post('title');
$uid=1;
if(mysql_fetch_object(mysql_query("select * from tm_zt_class where zt_name='$title' and zt_id<>'$id'")))
  {
  echo "<script>alert('存在相同来源');history.go(-1);</script>";
  exit();
  }
 mysql_query("update tm_zt_class set zt_name='$title' where zt_id='$id'");
 echo "<script>location.href='zt.php';</script>";
 exit();
}
?>
<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="100%" border=0 CALLPADDING="0">
<?php 			  
if($action=="" and $id=="")
{
?>
<form id="form1" name="form1" method="post" action="zt_w.php">
			<TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><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 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_zt_class where zt_id='$id'";
$rsql=mysql_query($sql);
$rs=mysql_fetch_object($rsql);
 ?>
 <form id="form1" name="form1" method="post" action="zt_w.php">
			<TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">名　称：
                                  <input name="title" type="text" id="title" value="<?php echo $rs->zt_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><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>