<?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")
 {
 $rs=mysql_fetch_object(mysql_query("select * from tm_pic_class where id='$id'"));
 if(!$rs)
 {
 echo "<script>location.href='pic_class.php';</script>";
 exit();
 }
 mysql_query("delete from tm_pic_class where id='$id'");
 mysql_query("delete from tm_pic where cid='$id'");
 echo "<script>location.href='pic_class.php';</script>";
 exit();
 }
elseif($action=="px")
{
$tempid=array();
$newpx=array();
$i=0;
$rsql=mysql_query("select * from tm_pic_class");
while($rs=mysql_fetch_object($rsql))
{
$tempid[$i++]=$rs->id;
}
for($i=0;$i<count($tempid);$i++)
    {
	mysql_query("update tm_pic_class set px="._post('px'.$tempid[$i])." where id=".$tempid[$i]);
	}
echo "<script>location.href='pic_class.php';</script>";
exit();
}
elseif($action=="add")
{
$title=_post('title');
$password=_post('password');
$des=_post('des');
if(mysql_fetch_object(mysql_query("select * from tm_pic_class where title='$title'")))
  {
  echo "<script>alert('存在相同名称!');history.go(-1);</script>";
  exit();
  }
mysql_query("insert into tm_pic_class(title,password,des,date) values('$title','$password','$des','$date')");
echo "<script>location.href='pic_class.php';</script>";
 exit();
}
elseif($action=="edit")
{
$title=_post('title');
$password=_post('password');
$des=_post('des');
if(mysql_fetch_object(mysql_query("select * from tm_pic_class where title='$title' and id<>'$id'")))
  {
  echo "<script>alert('存在相同名称');history.go(-1);</script>";
  exit();
  }
 mysql_query("update tm_pic_class set title='$title',password='$password',des='$des' where id='$id'");
echo "<script>location.href='pic_class.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="pic_class_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 height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">密码访问：
                                  <input name="password" type="text" id="password" size="50" />
          <br />
          &nbsp;&nbsp;<span class="post_date">(提示:留空则无需密码访问！)</span>
</span></TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
              <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">相薄说明：
                                  <textarea name="des" cols="50" rows="5" id="des"></textarea>
              </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_pic_class where id='$id'";
$rsql=mysql_query($sql);
$rs=mysql_fetch_object($rsql);
 ?>
 <form id="form1" name="form1" method="post" action="pic_class_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->title;?>" size="50" />
			                  </span>			                  
							  							  </TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">密码访问：
                                  <input name="password" type="text" id="password" value="<?php echo $rs->password;?>" size="50" />
          </span>
		  <br />&nbsp;&nbsp;<span class="post_date">(提示:留空则无需密码访问！)</span></TD>
    </TR>
	<TR BORDER="0" WIDTH="100%">
              <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">相薄说明：
                                  <textarea name="des" cols="50" rows="5" id="des"><?php echo $rs->des;?></textarea>
          </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>