<?php require_once('../../include/class.inc.php'); ?>

<!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=gb2312" />
<link rel="stylesheet" href="../inc/css.css" type="text/css" />
<title>无标题文档</title>
<style type="text/css">
<!--
.STYLE5 {color: #FFFFFF; font-weight: bold; }
.STYLE7 {color: #999999}
-->
</style>
<script language="javascript" src="ajax.js"></script>
<script language="javascript">
function query(){
var yiid = document.getElementById("bigClassName").value;
if(yiid!=""){
   createRequest('query.php?yiid='+yiid);
}
}
</script>
<script language="javascript" src="ajaxa.js"></script>
<script language="javascript">
function query2(){
var erid = document.getElementById("smallClassName").value;
if(erid!=""){
   createRequest2('query2.php?erid='+erid);
}
}
</script>

</head>

<body>
<?php

		function msg($msg,$url)
{
	echo "<script type=\"text/javascript\">alert('$msg');window.location.href='$url';</script>";
}

function dafenglei_arr($m,$id)
{
	global $class_arr;
	global $classid;
	global $mysql;
	if($id=="") $id=0;
	$n = str_pad('',$m,'-',STR_PAD_RIGHT);
	$n = str_replace("-","&nbsp;&nbsp;",$n);
	for($i=0;$i<count($class_arr);$i++){
		if($class_arr[$i][2]==$id){
			//自定义的
			if ($class_arr[$i][3] ==0) {
				$show="是";
			}else {
				$show="<font color='red'>否</font>";
			}
		
		echo "<tr>\n";
		echo "	  <td>".$n."|--<a href=\"?action=edit&amp;id=".$class_arr[$i][0]."\">".$class_arr[$i][1]."</a></td>\n";
		echo "	  <td><div align=\"center\">".$show."</div></td>\n";
		echo "	  <td><div align=\"center\"><a href=\"?action=edit&amp;id=".$class_arr[$i][0]."\">修改</a>";
		echo " <a href=\"?action=del&amp;id=".$class_arr[$i][0]."\">删除</a>";
		echo "</div></td>\n";
		echo "	</tr>\n";		
			dafenglei_arr($m+1,$class_arr[$i][0]);
		}
		
	}
	
}

function dafenglei_select($m,$id,$index)
{	
	global $class_arr;
	$n = str_pad('',$m,'-',STR_PAD_RIGHT);
	$n = str_replace("-","&nbsp;&nbsp;",$n);
	for($i=0;$i<count($class_arr);$i++){
	
		if($class_arr[$i][2]==$id){
			if($class_arr[$i][0]==$index){
				echo "        <option value=\"".$class_arr[$i][0]."\" selected=\"selected\">".$n."|--".$class_arr[$i][1]."</option>\n";
			}else{
				echo "        <option value=\"".$class_arr[$i][0]."\">".$n."|--".$class_arr[$i][1]."</option>\n";
			}
			dafenglei_select($m+1,$class_arr[$i][0],$index);
			
		}
		
	}
	
}
/**
 *-------------------------数据库操作类-----------------------------*
*/
class mySql_Class
{
	function __construct($host, $user, $pass)
	{
 		@mysql_connect($host,$user,$pass) or die("数据库连接失败!");
		mysql_query("SET NAMES 'gbk'");
 	}
	
	function select_db($db)//连接表
	{
		return @mysql_select_db($db);
	}
	
	function query($sql)//执行SQL语句
	{
		return @mysql_query($sql);
	}
	
	function fetch_array($fetch_array)
	{
		return @mysql_fetch_array($fetch_array, MYSQL_ASSOC);
	}
	
	
	function close() //关闭数据库
	{ 
		return @mysql_close();
	}
	
	function insert($table,$arr) //添加记录
	{
		$sql = $this -> query("INSERT INTO `$table` (`".implode('`,`', array_keys($arr))."`) VALUES('".implode("','", $arr)."')");
		return $sql;
	}
}

		include("../../include/config.php");
		mysql_query("set names 'gbk'");
		$result=mysql_query("select * from db");
		while ($info=mysql_fetch_array($result)) {
		$hostname=$info[hostname];
		$username=$info[username];
		$userpwd=$info[userpwd];
		$dbname=$info[dbname];
		}
		$mysql = new mysql_Class($hostname,$username,$userpwd);
		
		$mysql -> select_db($dbname);
		$class_arr=array();
		$sql = "select * from `bigclass_nav` order by id Desc";
		$query = $mysql -> query($sql);
		while($row = $mysql -> fetch_array($query)){
			$class_arr[] = array($row['id'],$row['cname'],$row['fid']);
		}

?>

<form method="post" action="padd_save.php" enctype="multipart/form-data">
  <table width="1052" border="0" align="center" cellpadding="2" cellspacing="1" bordercolor="#799AE1" class="tableBorder">
    <tbody>
      <tr bgcolor="#CCCCCC">
        <td height="20" colspan="3" bgcolor="#4455aa"><div align="center" class="STYLE5">
            <div align="left">添加产品</div>
        </div></td>
      </tr>
      <tr bgcolor="#DEE5FA">
        <td colspan="2" align="center" class="txlrow"><div align="center"><strong>产品分类</strong></div></td>
        <td align="center" class="txlrow"><div align="left">
            <select name="fid" id="fid">
            <option value="0">-----顶级分类-----</option>
            <?php
            	dafenglei_select(0,0,0);
			?>
          </select><font color="#FF0000">*</font>
        </div></td>
      </tr>
      <tr bgcolor="#DEE5FA">
        <td colspan="2" align="center" class="txlrow"><div align="center"><strong>产品名称</strong></div></td>
        <td align="center" class="txlrow"><div align="left">
            <input name="title" type="text" id="title" size="50" />&nbsp;&nbsp;&nbsp;<font color="#FF0000">*</font>
        </div></td>
      </tr>
      <tr bgcolor="#DEE5FA">
        <td colspan="2" align="center" class="txlrow"><div align="center"><strong>产品编号</strong></div></td>
        <td align="center" class="txlrow"><div align="left">
          <input name="Product_id" type="text" id="Product_id" size="20" />
        </div></td>
      </tr>
      <tr bgcolor="#DEE5FA">
        <td colspan="2" align="center" class="txlrow"><div align="center"><strong>产品规格</strong></div></td>
        <td align="center" class="txlrow"><div align="left">
          <input name="spec" type="text" id="spec" size="20" />
        </div></td>
      </tr>
      <tr bgcolor="#DEE5FA">
        <td colspan="2" align="center" class="txlrow"><div align="center"><strong>产品价格</strong></div></td>
        <td align="center" class="txlrow"><div align="left">
          <input name="price" type="text" id="price" size="20" />
        </div></td>
      </tr>
      <tr bgcolor="#DEE5FA">
        <td colspan="2" align="center" class="txlrow"><div align="center"><strong>产品内容</strong></div></td>
        <td align="center" class="txlrow"><div align="left">
          <textarea name="content" cols="40" rows="5" id="content" style="display:none;width:600px;height:300px;"></textarea>
            <script type="text/javascript" charset="utf-8" src="../editor/kindeditor.js"></script>
            <script type="text/javascript">    KE.show({        id : 'content' //TEXTAREA输入框的ID   
		    });</script>
        </div></td>
      </tr>
      <tr bgcolor="#DEE5FA">
        <td colspan="2" align="center" class="txlrow"><div align="center"><strong>产品图片</strong></div></td>
        <td align="center" class="txlrow"><div align="left">
            <input type="hidden" name="submitted" value="yes" />
   图片上传 (只能上传.jpg和.gif文件, 文件大小不能超过500KB):<br />
<input type="file" name="image" />&nbsp;&nbsp;&nbsp;<font color="#FF0000">*</font>
        </div></td>
      </tr>
      <tr bgcolor="#DEE5FA">
        <td colspan="2" align="center" class="txlrow"><div align="center"><strong>首页推荐</strong></div></td>
        <td align="center" class="txlrow"><div align="left">
            <input type="radio" name="Home_t" id="radio3" value="首页推荐" />
            是
            <input name="Home_t" type="radio" id="radio" value="HomeNo" checked="checked" />
            否
            <span class="STYLE7">（选择后在首页产品展示中显示）</span></div></td>
      </tr>
	   <tr bgcolor="#DEE5FA">
        <td colspan="2" align="center" class="txlrow"><div align="center"><strong>首页幻灯片</strong></div></td>
        <td align="center" class="txlrow"><div align="left">
            <input type="radio" name="ppt" id="ppt" value="1" />
            是
            <input name="ppt" type="radio" id="ppt" value="0" checked="checked" />
            否
            <span class="STYLE7">（选择后在首页幻灯片中显示）</span></div></td>
      </tr>
      <tr bgcolor="#DEE5FA">
        <td colspan="2" align="center" class="txlrow"><div align="center"><strong>默认点击数</strong></div></td>
        <td align="center" class="txlrow"><div align="left">
            <input name="hits" type="text" id="hits" value="10" size="10" />
        </div></td>
      </tr>
      <tr bgcolor="#DEE5FA">
        <td colspan="2" align="center" class="txlrow"><div align="center"><strong>发布人</strong></div></td>
        <td align="center" class="txlrow"><div align="left">
            <label>
            <input type="text" name="user" id="user" />
            </label>
        </div></td>
      </tr>
      <tr bgcolor="#DEE5FA">
        <td colspan="2" align="center" class="txlrow">&nbsp;</td>
        <td align="center" class="txlrow"><div align="left">
            <input type="submit" name="button3" id="button3" value="提交" />
            <input type="reset" name="button3" id="button4" value="重置" />
        </div></td>
      </tr>
    </tbody>
  </table>
</form>
</body>
</html>
