<?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 
$date=time();
 if($action=="del")
 {
 mysql_query("delete from tm_bq_list where id='$id'");
 mysql_query("delete from tm_bq_list where cid='$id'");
 echo "<script>location.href='bq_list.php';</script>";
 exit();
 }
elseif($action=="px")
{
$tempid=array();
$newpx=array();
$i=0;
$rsql=mysql_query("select * from tm_bq_list");
while($rs=mysql_fetch_object($rsql))
{
$tempid[$i++]=$rs->id;
}
for($i=0;$i<count($tempid);$i++)
    {
	mysql_query("update tm_bq_list set px="._post('px'.$tempid[$i])." where id=".$tempid[$i]);
	}
echo "<script>location.href='bq_list.php';</script>";
exit();
}
elseif($action=="add")
{
$name=_post('name');
$url=_post('url');
$num=_post('num');
if(mysql_fetch_object(mysql_query("select * from tm_bq_list where name='$name'")))
  {
  echo "<script>alert('此博客地址已存在!');history.go(-1);</script>";
  exit();
  }
mysql_query("insert into tm_bq_list(name,url,num) values('$name','$url','$num')");
exit();
echo "<script>location.href='bq_list.php';</script>";
 exit();
}
elseif($action=="edit")
{
$name=_post('name');
$url=_post('url');
$num=_post('num');
if(mysql_fetch_object(mysql_query("select * from tm_bq_list where name='$name' and id<>'$id'")))
  {
  echo "<script>alert('此博客地址已存在');history.go(-1);</script>";
  exit();
  }
 mysql_query("update tm_bq_list set name='$name',url='$url',num='$num' where id='$id'");
echo "<script>location.href='bq_list.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="bq_list_w.php">
			<TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">博主名称：
                                  <input name="name" type="text" id="name" size="50" />
                <span class="post_date">(任意，自己作区分用) </span></span></TD>
    </TR>
	<TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">博主网址：
                                  <input name="url" type="text" id="url" value="http://" size="50" />
	                            <span class="post_date">(对方的博客的网址,例：http://php.tmacn.cn) </span></span></TD>
    </TR>
	<TR BORDER="0" WIDTH="100%">
              <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">文章条数：
                <select name="num" id="num">
				<?php 
				for($i=1;$i<=10;$i++)
				   {
				?>
                  <option value="<?php echo $i;?>"><?php echo $i;?>篇文章</option>
                <?php 
				}
				?>
				</select>
              <span class="post_date">(调用对方最新文章篇数) </span></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.name.value=="")
  {
  alert("请输入博主名称！");
  theform.name.focus();
  return false;
  }
if(theform.url.value=="")
  {
  alert("请输入博主网址！");
  theform.url.focus();
  return false;
  }
return true;
}
</script>
 <?php 
 }
if($action=="" and $id<>"")
{
$sql="select * from tm_bq_list where id='$id'";
$rsql=mysql_query($sql);
$rs=mysql_fetch_object($rsql);
 ?>
 <form id="form1" name="form1" method="post" action="bq_list_w.php">
			<TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">博主名称：
                                  <input name="name" type="text" id="name" value="<?php echo $rs->name;?>" size="50" />
                <span class="post_date">(任意，自己作区分用) </span></span></TD>
    </TR>
	<TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">博主网址：
                                  <input name="url" type="text" id="url" value="<?php echo $rs->url;?>" size="50" />
	                            <span class="post_date">(对方的博客的网址,例：http://php.tmacn.cn) </span></span></TD>
    </TR>
	<TR BORDER="0" WIDTH="100%">
              <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">文章条数：
                <select name="num" id="num">
				<?php 
				for($i=1;$i<=10;$i++)
				   {
				?>
                  <option value="<?php echo $i;?>" <?php if($rs->num==$i) echo 'selected="selected"';?>><?php echo $i;?>篇文章</option>
                <?php 
				}
				?>
				</select>
              <span class="post_date">(调用对方最新文章篇数) </span></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.name.value=="")
  {
  alert("请输入博主名称！");
  theform.name.focus();
  return false;
  }
if(theform.url.value=="")
  {
  alert("请输入博主网址！");
  theform.url.focus();
  return false;
  }
return true;
}
</script>
 <?PHP }
 ?>
      </TABLE>
</td>
</tr></table></div>

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