<?php
require_once('conn.php');
require_once('functions.php');

// Check login status
checkLogin("信息管理");

// Initialize variables
$product_name = '';
$product_img = '';
$unit = '';
$moq = '';
$category_id = isset($_GET['category_id']) ? intval($_GET['category_id']) : 0;
$note = '';
$tips = '';
$keys = isset($_GET['Keys']) ? urlencode($_GET['Keys']) : '';
$page = isset($_GET['Page']) ? $_GET['Page'] : 1;

// Get the return URL
$href_str = "products.php?keys=" . $keys . "&Page=" . $page;
if ($category_id) {
    $href_str .= "&category_id=" . $category_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" />
<title>添加产品</title>
<link rel="stylesheet" href="css/common.css" type="text/css" />
<script language="javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/js.js"></script>
<script type="text/javascript" src="js/SearchArea.js"></script>
<script type="text/javascript" src="xheditor-1.1.9/xheditor-1.1.9-zh-cn.min.js"></script>
</head>

<body>
<div id="man_zone">
    <form name="form1" method="post" action="save_product.php">
        <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
            <tbody>
                <tr>
                    <th width="8%">产品名称</th>
                    <td><input type="text" id="ProductName" name="ProductName" value="<?php echo $product_name; ?>" class="txt1" />
                    <input type="hidden" name="id" value="" />
                    <input type="hidden" name="keys" value="<?php echo $keys; ?>" />
                    <input type="hidden" name="page" value="<?php echo $page; ?>" />
                    <input type="hidden" name="category_id" value="<?php echo $category_id; ?>" />
                    </td>
                </tr>
                <tr>
                    <th width="8%">产品分类</th>
                    <td>
                        <select name="category_id" id="category_id" class="select1">
                            <option value="0">-- 请选择分类 --</option>
                            <?php
                            // Build category tree
                            $category_data = buildCategoryTree($conn);
                            $cat_tree = $category_data['tree'];
                            
                            // Output options
                            outputCategoryOptions($cat_tree, $category_id);
                            ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th width="8%">产品图片</th>
                    <td><input type="text" id="ProductImg" name="ProductImg" placeholder="186x*186px" value="<?php echo $product_img; ?>" class="txt1" style="width:390px;float:left;" />
                    <iframe src="uploadfile.php" frameborder="0" scrolling="no" style="width:400px;height:22px;float:left;margin-left:10px;"></iframe></td>
                </tr>
                <tr>
                    <th width="8%">计价单位</th>
                    <td><input type="text" id="unit" name="unit" value="<?php echo $unit; ?>" class="txt1"/></td>
                </tr>
                <tr>
                    <th width="8%">起订数量</th>
                    <td><input type="text" id="moq" name="moq" value="<?php echo $moq; ?>" class="txt1"/></td>
                </tr>
                <tr>
                    <th width="8%">默认售价</th>
                    <td>
                        <div class="Price">
                            <div class="priceitem">
                                <label>≥</label>
                                <input type="number" class="txt3 num" name="num[]">
                                <label class="unit"><?php echo $unit; ?></label>
                                <label>售价</label>
                                <input type="text" class="txt3 price" name="price[]">
                                <label>RMB</label>
                                <span class="additem"></span>
                                <span class="delitem"></span>
                                <span class="note"></span>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <th width="8%">不报价地区</th>
                    <td>
                        <ul class="areadd"></ul>
                        <input type="text" id="AreaSearch" class="fastsearch">
                        <div id="arealist" class="productlist"><ul></ul></div>
                    </td>
                </tr>
                <tr>
                    <th width="8%">不报价处理方式</th>
                    <td><input type="text" id="note" name="note" value="<?php echo $note; ?>" class="txt1"/></td>
                </tr>
                <tr>
                    <th width="8%">备注</th>
                    <td><input type="text" id="tips" name="tips" value="<?php echo $tips; ?>" class="txt1"/></td>
                </tr>
                <tr>
                    <th></th>
                    <td colspan="2">
                        <input type="submit" name="save" value="确定" class="btn1" />
                        <input type="reset" name="reset" value="重置" class="btn1" />
                        <input type="button" value="返回" class="btn1" onClick="location.href='<?php echo $href_str; ?>'" />
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</div>
</body>
</html>
<?php mysqli_close($conn); ?>