<?php 
$action=_get('action');
if($action=="")
$action=_post('action');
$id=_get('id');
if($id=="")
$id=_post('id');

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);
}
$qs=explode(",",$_SESSION["tm_qs"]);
if($qs[0]==0)
   {
   echo "<script>location.href='main.php';</script>";
   exit();
   }
 if($action=="del")
 {
if(isset($_POST['chkkindid']) && is_array($_POST['chkkindid'])){
foreach($_POST['chkkindid'] as $tempid){
$exec="delete from tm_link where link_id=".$tempid;
mysql_query($exec);
}
} 
 
echo "<script>location.href='link.php';</script>";
exit();
   }
elseif($action=="add")
{
$zt_name=_post('zt_name');
$zt_url=_post('zt_url');
$zt_show=_post('zt_show');
$sql="insert into tm_link(link_name,link_show,link_url) values('$zt_name','$zt_show','$zt_url')";
mysql_query($sql);
echo "<script>location.href='link.php';</script>";
 exit();
}
elseif($action=="edit")
{
$zt_name=_post('zt_name');
$zt_url=_post('zt_url');
$zt_show=_post('zt_show');
$sql="update tm_link set link_name='$zt_name',link_show='$zt_show',link_url='$zt_url' where link_id='$id'";
  mysql_query($sql);
 echo "<script>location.href='link.php';</script>";
 exit();
}
?>
<!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" />
<script type="text/javascript" src="js/jquery.js"></script>
</HEAD><BODY>
<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"><div align="center"><h1><span class="action-span"><a href="link_w.php">添加</a></span></h1></div></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="link_w.php">
			<TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">名称：
                                  <input name="zt_name" type="text" id="zt_name" size="50" />
			                  </span>			                  </TD>
                    </TR>
<TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">网址：
                                  <input name="zt_url" type="text" id="zt_url" value="http://" 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>显示状态：
                  <input name="zt_show" type="radio" value="1" checked="checked" />
                  显示
                  <input type="radio" name="zt_show" value="0" />
                  隐藏</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_link where link_id='$id'";
$rsql=mysql_query($sql);
$rs=mysql_fetch_object($rsql);
    if(!$rs)
     {
	 echo "<script>alert('无相关链接!');location.href='link.php'</script>";
     exit();
	 }
 ?>
 <form id="form1" name="form1" method="post" action="link_w.php">
			<TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">名称：
                                  <input name="zt_name" type="text" id="zt_name" value="<?php echo $rs->link_name;?>" size="50" />
			                  </span>			                  </TD>
                    </TR>
			<TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">网址：
                                  <input name="zt_url" type="text" id="zt_url" value="<?php echo $rs->link_url;?>" 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>显示状态：
                  <input name="zt_show" type="radio" value="1" <?php if($rs->link_show==1) echo "checked";?> />
                  显示
                  <input type="radio" name="zt_show" value="0" <?php if($rs->link_show==0) echo "checked";?> />
                  隐藏
                  </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>