edit_product.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. require_once('conn.php');
  3. require_once('functions.php');
  4. // Check login status
  5. checkLogin("信息管理");
  6. // Initialize variables
  7. $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
  8. $keys = isset($_GET['Keys']) ? urlencode($_GET['Keys']) : '';
  9. $page = isset($_GET['Page']) ? $_GET['Page'] : 1;
  10. $category_id = isset($_GET['category_id']) ? intval($_GET['category_id']) : 0;
  11. // Get the return URL
  12. $href_str = "products.php?keys=" . $keys . "&Page=" . $page;
  13. if ($category_id) {
  14. $href_str .= "&category_id=" . $category_id;
  15. }
  16. // Check if the product exists
  17. if ($id <= 0) {
  18. header("Location: " . $href_str);
  19. exit();
  20. }
  21. // Fetch product data
  22. $sql = "SELECT * FROM products WHERE id = " . (int)$id;
  23. $result = mysqli_query($conn, $sql);
  24. if (mysqli_num_rows($result) <= 0) {
  25. // Product not found, redirect
  26. header("Location: " . $href_str);
  27. exit();
  28. }
  29. $row = mysqli_fetch_assoc($result);
  30. $product_name = htmlspecialcharsFix($row['ProductName']);
  31. $product_img = htmlspecialcharsFix($row['ProductImg']);
  32. $unit = htmlspecialcharsFix($row['unit']);
  33. $moq = htmlspecialcharsFix($row['moq']);
  34. $nosale = $row['nosale'];
  35. $note = htmlspecialcharsFix($row['note']);
  36. $tips = htmlspecialcharsFix($row['tips']);
  37. $category_id = $row['category_id'] ? intval($row['category_id']) : 0;
  38. ?>
  39. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  40. <html xmlns="http://www.w3.org/1999/xhtml">
  41. <head>
  42. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  43. <title>编辑产品</title>
  44. <link rel="stylesheet" href="css/common.css" type="text/css" />
  45. <script language="javascript" src="js/jquery-1.7.2.min.js"></script>
  46. <script type="text/javascript" src="js/js.js"></script>
  47. <script type="text/javascript" src="js/SearchArea.js"></script>
  48. <script type="text/javascript" src="xheditor-1.1.9/xheditor-1.1.9-zh-cn.min.js"></script>
  49. </head>
  50. <body>
  51. <div id="man_zone">
  52. <form name="form1" method="post" action="save_product.php">
  53. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  54. <tbody>
  55. <tr>
  56. <th width="8%">产品名称</th>
  57. <td><input type="text" id="ProductName" name="ProductName" value="<?php echo $product_name; ?>" class="txt1" />
  58. <input type="hidden" name="id" value="<?php echo $id; ?>" />
  59. <input type="hidden" name="keys" value="<?php echo $keys; ?>" />
  60. <input type="hidden" name="page" value="<?php echo $page; ?>" />
  61. <input type="hidden" name="category_id" value="<?php echo $category_id; ?>" />
  62. </td>
  63. </tr>
  64. <tr>
  65. <th width="8%">产品分类</th>
  66. <td>
  67. <select name="category_id" id="category_id" class="select1">
  68. <option value="0">-- 请选择分类 --</option>
  69. <?php
  70. // Build category tree
  71. $category_data = buildCategoryTree($conn);
  72. $cat_tree = $category_data['tree'];
  73. // Output options
  74. outputCategoryOptions($cat_tree, $category_id);
  75. ?>
  76. </select>
  77. </td>
  78. </tr>
  79. <tr>
  80. <th width="8%">产品图片</th>
  81. <td><input type="text" id="ProductImg" name="ProductImg" placeholder="186x*186px" value="<?php echo $product_img; ?>" class="txt1" style="width:390px;float:left;" />
  82. <iframe src="uploadfile.php" frameborder="0" scrolling="no" style="width:400px;height:22px;float:left;margin-left:10px;"></iframe></td>
  83. </tr>
  84. <tr>
  85. <th width="8%">计价单位</th>
  86. <td><input type="text" id="unit" name="unit" value="<?php echo $unit; ?>" class="txt1"/></td>
  87. </tr>
  88. <tr>
  89. <th width="8%">起订数量</th>
  90. <td><input type="text" id="moq" name="moq" value="<?php echo $moq; ?>" class="txt1"/></td>
  91. </tr>
  92. <tr>
  93. <th width="8%">默认售价</th>
  94. <td>
  95. <div class="Price">
  96. <?php
  97. $price_sql = "SELECT num, price FROM price WHERE AreaId = 0 AND productId = " . $id . " ORDER BY num ASC";
  98. $price_result = mysqli_query($conn, $price_sql);
  99. if (mysqli_num_rows($price_result) > 0) {
  100. while ($price_row = mysqli_fetch_assoc($price_result)) {
  101. ?>
  102. <div class="priceitem">
  103. <label>≥</label>
  104. <input type="number" class="txt3 num" name="num[]" value="<?php echo $price_row['num']; ?>">
  105. <label class="unit"><?php echo $unit; ?></label>
  106. <label>售价</label>
  107. <input type="text" class="txt3 price" name="price[]" value="<?php echo $price_row['price']; ?>">
  108. <label>RMB</label>
  109. <span class="additem"></span>
  110. <span class="delitem"></span>
  111. <span class="note"></span>
  112. </div>
  113. <?php
  114. }
  115. } else {
  116. ?>
  117. <div class="priceitem">
  118. <label>≥</label>
  119. <input type="number" class="txt3 num" name="num[]">
  120. <label class="unit"><?php echo $unit; ?></label>
  121. <label>售价</label>
  122. <input type="text" class="txt3 price" name="price[]">
  123. <label>RMB</label>
  124. <span class="additem"></span>
  125. <span class="delitem"></span>
  126. <span class="note"></span>
  127. </div>
  128. <?php
  129. }
  130. ?>
  131. </div>
  132. </td>
  133. </tr>
  134. <tr>
  135. <th width="8%">不报价地区</th>
  136. <td>
  137. <ul class="areadd">
  138. <?php
  139. if (!empty($nosale)) {
  140. // 确保nosale是逗号分隔的字符串格式
  141. $nosale_str = is_array($nosale) ? implode(',', $nosale) : $nosale;
  142. $area_sql = "SELECT id, countryName FROM country WHERE id IN(" . $nosale_str . ")";
  143. $area_result = mysqli_query($conn, $area_sql);
  144. while ($area_row = mysqli_fetch_assoc($area_result)) {
  145. ?>
  146. <li><input type="hidden" name="nosale[]" value="<?php echo $area_row['id']; ?>"><span class="cname"><?php echo htmlspecialcharsFix($area_row['countryName']); ?></span><span class="close"></span></li>
  147. <?php
  148. }
  149. }
  150. ?>
  151. </ul>
  152. <input type="text" id="AreaSearch" class="fastsearch">
  153. <div id="arealist" class="productlist"><ul></ul></div>
  154. </td>
  155. </tr>
  156. <tr>
  157. <th width="8%">不报价处理方式</th>
  158. <td><input type="text" id="note" name="note" value="<?php echo $note; ?>" class="txt1"/></td>
  159. </tr>
  160. <tr>
  161. <th width="8%">备注</th>
  162. <td><input type="text" id="tips" name="tips" value="<?php echo $tips; ?>" class="txt1"/></td>
  163. </tr>
  164. <tr>
  165. <th></th>
  166. <td colspan="2">
  167. <input type="submit" name="save" value="确定" class="btn1" />
  168. <input type="reset" name="reset" value="重置" class="btn1" />
  169. <input type="button" value="返回" class="btn1" onClick="location.href='<?php echo $href_str; ?>'" />
  170. </td>
  171. </tr>
  172. </tbody>
  173. </table>
  174. </form>
  175. </div>
  176. </body>
  177. </html>
  178. <?php mysqli_close($conn); ?>