123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- <?php
- require_once('conn.php');
- checkLogin("信息管理");
- $act = isset($_GET['act']) ? $_GET['act'] : '';
- $product_name = isset($_POST['ProductName']) ? htmlspecialchars($_POST['ProductName']) : '';
- $product_img = isset($_POST['ProductImg']) ? htmlspecialchars($_POST['ProductImg']) : '';
- $unit = isset($_POST['unit']) ? htmlspecialchars($_POST['unit']) : '';
- $moq = isset($_POST['moq']) ? htmlspecialchars($_POST['moq']) : '';
- $nosale = isset($_POST['nosale']) ? $_POST['nosale'] : array();
- $num = isset($_POST['num']) ? $_POST['num'] : array();
- $price = isset($_POST['price']) ? $_POST['price'] : array();
- $note = isset($_POST['note']) ? htmlspecialchars($_POST['note']) : '';
- $tips = isset($_POST['tips']) ? htmlspecialchars($_POST['tips']) : '';
- $page = isset($_GET['Page']) ? $_GET['Page'] : 1;
- $keys = isset($_GET['Keys']) ? urlencode($_GET['Keys']) : '';
- $keyscode = isset($_GET['Keys']) ? htmlspecialchars($_GET['Keys']) : '';
- if ($act == 'save') {
- $id = isset($_POST['id']) ? $_POST['id'] : '';
- $is_edit = (!empty($id) && is_numeric($id));
-
-
- $nosale_str = '';
- if (is_array($nosale) && !empty($nosale)) {
- $nosale_clean = array_map('intval', $nosale);
- $nosale_str = implode(',', $nosale_clean);
- }
-
- if ($is_edit) {
-
- $sql = "UPDATE products SET
- ProductName = '" . mysqli_real_escape_string($conn, $product_name) . "',
- ProductImg = '" . mysqli_real_escape_string($conn, $product_img) . "',
- Addtime = NOW(),
- moq = '" . mysqli_real_escape_string($conn, $moq) . "',
- unit = '" . mysqli_real_escape_string($conn, $unit) . "',
- nosale = '" . $nosale_str . "',
- note = '" . mysqli_real_escape_string($conn, $note) . "',
- tips = '" . mysqli_real_escape_string($conn, $tips) . "'
- WHERE id = " . (int)$id;
- mysqli_query($conn, $sql);
-
-
- mysqli_query($conn, "DELETE FROM price WHERE productId = " . (int)$id . " AND AreaId = 0");
-
- if (is_array($num) && is_array($price)) {
- foreach ($num as $key => $num_value) {
- if (isset($price[$key])) {
- $num_value = empty($num_value) ? 0 : (float)$num_value;
- $price_value = empty($price[$key]) ? 0 : (float)$price[$key];
- $sql = "INSERT INTO price (productId, AreaId, num, price) VALUES
- (" . (int)$id . ", 0, " . $num_value . ", '" . $price_value . "')";
- mysqli_query($conn, $sql);
- }
- }
- }
- } else {
-
- $sql = "INSERT INTO products (ProductName, ProductImg, Addtime, unit, moq, nosale, note, tips)
- VALUES (
- '" . mysqli_real_escape_string($conn, $product_name) . "',
- '" . mysqli_real_escape_string($conn, $product_img) . "',
- NOW(),
- '" . mysqli_real_escape_string($conn, $unit) . "',
- '" . mysqli_real_escape_string($conn, $moq) . "',
- '" . $nosale_str . "',
- '" . mysqli_real_escape_string($conn, $note) . "',
- '" . mysqli_real_escape_string($conn, $tips) . "'
- )";
- mysqli_query($conn, $sql);
- $id = mysqli_insert_id($conn);
-
-
- if (is_array($num) && is_array($price)) {
- foreach ($num as $key => $num_value) {
- if (isset($price[$key])) {
- $num_value = empty($num_value) ? 0 : (float)$num_value;
- $price_value = empty($price[$key]) ? 0 : (float)$price[$key];
- $sql = "INSERT INTO price (productId, AreaId, num, price) VALUES
- (" . (int)$id . ", 0, " . $num_value . ", '" . $price_value . "')";
- mysqli_query($conn, $sql);
- }
- }
- }
- }
-
-
- header("Location: ?keys=" . $keys . "&Page=" . $page);
- exit();
- }
- if ($act == 'postchk') {
- if (isset($_POST['chkbox']) && isset($_POST['chkact'])) {
- $chk_ids = array_map('intval', $_POST['chkbox']);
- $chk_act = (int)$_POST['chkact'];
-
- if (!empty($chk_ids)) {
- $ids_str = implode(',', $chk_ids);
-
- switch ($chk_act) {
- case 0:
- case 1:
- $sql = "UPDATE customer SET cs_state = " . $chk_act . " WHERE id IN (" . $ids_str . ")";
- break;
- case -1:
- $sql = "DELETE FROM products WHERE id IN (" . $ids_str . ")";
- break;
- }
-
- if (isset($sql)) {
- mysqli_query($conn, $sql);
- }
- }
-
- header("Location: ?Keys=" . $keys . "&Page=" . $page);
- exit();
- }
- }
- ?>
- <!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">
- <?php
- if ($act == 'add' || $act == 'edit') {
- $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
- $is_edit = ($id > 0);
-
- if ($is_edit) {
- $sql = "SELECT ProductName, ProductImg, unit, moq, nosale, note, tips
- FROM products WHERE id = " . $id;
- $result = mysqli_query($conn, $sql);
- if ($row = mysqli_fetch_assoc($result)) {
- $product_name = htmlspecialchars($row['ProductName']);
- $product_img = htmlspecialchars($row['ProductImg']);
- $unit = htmlspecialchars($row['unit']);
- $moq = htmlspecialchars($row['moq']);
- $nosale = $row['nosale'];
- $note = htmlspecialchars($row['note']);
- $tips = htmlspecialchars($row['tips']);
- }
- }
-
- $href_str = "?keys=" . $keys . "&Page=" . $page;
- ?>
- <form name="form1" method="post" action="<?php echo $href_str; ?>&act=save">
- <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="<?php echo $id; ?>" /></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">
- <?php
- if ($is_edit) {
- $price_sql = "SELECT num, price FROM price WHERE AreaId = 0 AND productId = " . $id . " ORDER BY num ASC";
- $price_result = mysqli_query($conn, $price_sql);
- if (mysqli_num_rows($price_result) > 0) {
- while ($price_row = mysqli_fetch_assoc($price_result)) {
- ?>
- <div class="priceitem">
- <label>≥</label>
- <input type="number" class="txt3 num" name="num[]" value="<?php echo $price_row['num']; ?>">
- <label class="unit"><?php echo $unit; ?></label>
- <label>售价</label>
- <input type="text" class="txt3 price" name="price[]" value="<?php echo $price_row['price']; ?>">
- <label>RMB</label>
- <span class="additem"></span>
- <span class="delitem"></span>
- <span class="note"></span>
- </div>
- <?php
- }
- }
- }
- if (!$is_edit || mysqli_num_rows($price_result) == 0) {
- ?>
- <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>
- <?php
- }
- ?>
- </div>
- </td>
- </tr>
- <tr>
- <th width="8%">不报价地区</th>
- <td>
- <ul class="areadd">
- <?php
- if (!empty($nosale)) {
- $area_sql = "SELECT id, countryName FROM country WHERE id IN(" . $nosale . ")";
- $area_result = mysqli_query($conn, $area_sql);
- while ($area_row = mysqli_fetch_assoc($area_result)) {
- ?>
- <li>
- <input type="hidden" name="nosale[]" value="<?php echo $area_row['id']; ?>">
- <span class="cname"><?php echo htmlspecialchars($area_row['countryName']); ?></span>
- <span class="close"></span>
- </li>
- <?php
- }
- }
- ?>
- </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>
- <?php
- } else {
-
- $sql = "SELECT id, ProductName, ProductImg FROM products ORDER BY id DESC";
- $result = mysqli_query($conn, $sql);
- $total_records = mysqli_num_rows($result);
- $records_per_page = 18;
- $total_pages = ceil($total_records / $records_per_page);
-
-
- if ($page == 'end') $page = $total_pages;
- if (!is_numeric($page) || $page < 1) $page = 1;
- if ($page > $total_pages) $page = $total_pages;
-
- $offset = ($page - 1) * $records_per_page;
- $sql .= " LIMIT $offset, $records_per_page";
- $result = mysqli_query($conn, $sql);
- ?>
- <form id="form1" method="post" action="?act=postchk&Keys=<?php echo $keys; ?>&Page=<?php echo $page; ?>" onSubmit="return false">
- <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
- <thead>
- <tr>
- <th width="4%"><input type="checkbox" name="chkall" id="chkall" onClick="chkboxall(this,'chkbox')" /></th>
- <th width="6%">序号</th>
- <th width="30%">产品名称</th>
- <th width="40%">图片</th>
- <th width="20%">操作</th>
- </tr>
- </thead>
- <tbody>
- <?php
- if (mysqli_num_rows($result) > 0) {
- $temp_num = $offset;
- while ($row = mysqli_fetch_assoc($result)) {
- $temp_num++;
- ?>
- <tr onMouseOver="this.style.background='#F7FCFF'" onMouseOut="this.style.background='#FFFFFF'">
- <td align="center"><input type="checkbox" name="chkbox[]" value="<?php echo $row['id']; ?>" /></td>
- <td align="center"><?php echo $temp_num; ?></td>
- <td align="center"><?php echo htmlspecialchars($row['ProductName']); ?></td>
- <td align="center"><img src="<?php echo htmlspecialchars($row['ProductImg']); ?>" width="80px"></td>
- <td align="center">
- <a href="?Keys=<?php echo $keys; ?>&Page=<?php echo $page; ?>&act=edit&id=<?php echo $row['id']; ?>" class="ico_edit ico">修改</a>
- </td>
- </tr>
- <?php
- }
- } else {
- ?>
- <tr>
- <td colspan="9" align="center">
- <?php echo empty($keys) ? 'Sorry,当前暂无信息' : '<a href="?">Sorry,没有找到"' . htmlspecialchars($keyscode) . '"相关的信息,点击返回</a>'; ?>
- </td>
- </tr>
- <?php
- }
- ?>
- </tbody>
- <tfoot>
- <tr>
- <td colspan="9">
- <div class="showpagebox">
- <?php
- if ($total_pages > 1) {
- $page_name = "?Keys=" . $keys . "&";
- $page_len = 3;
-
-
- if ($page > 1) {
- echo "<a href=\"{$page_name}Page=1\">首页</a>";
- echo "<a href=\"{$page_name}Page=" . ($page - 1) . "\">上一页</a>";
- }
-
-
- if ($page_len * 2 + 1 >= $total_pages) {
- $start_page = 1;
- $end_page = $total_pages;
- } else {
- if ($page <= $page_len + 1) {
- $start_page = 1;
- $end_page = $page_len * 2 + 1;
- } else {
- $start_page = $page - $page_len;
- $end_page = $page + $page_len;
- }
- if ($page + $page_len > $total_pages) {
- $start_page = $total_pages - $page_len * 2;
- $end_page = $total_pages;
- }
- }
-
-
- for ($i = $start_page; $i <= $end_page; $i++) {
- if ($i == $page) {
- echo "<a class=\"current\">{$i}</a>";
- } else {
- echo "<a href=\"{$page_name}Page={$i}\">{$i}</a>";
- }
- }
-
-
- if ($page < $total_pages) {
- if ($total_pages - $page > $page_len) {
- echo "<a href=\"{$page_name}Page={$total_pages}\">...{$total_pages}</a>";
- }
- echo "<a href=\"{$page_name}Page=" . ($page + 1) . "\">下一页</a>";
- echo "<a href=\"{$page_name}Page={$total_pages}\">尾页</a>";
- }
- ?>
- <input type="text" id="Pagego" value="<?php echo $page; ?>"
- onFocus="if(this.value == '<?php echo $page; ?>'){this.value='';}"
- onBlur="if(this.value == ''){this.value='<?php echo $page; ?>';}"
- onKeyUp="this.value=this.value.replace(/\D/g,'')"
- onKeyDown="if(event.keyCode==13){location.href='<?php echo $page_name; ?>Page='+document.getElementById('Pagego').value}" />
- <?php
- }
- ?>
- </div>
- <div class="postchkbox">
- <select id="chkact" name="chkact">
- <option value="1">显示</option>
- <option value="0">隐藏</option>
- <option value="-1">删除</option>
- </select>
- <input type="button" value="执行" onClick="postchk(1)" class="btn1" />
- <input type="button" value="新增" onClick="location.href='?act=add'" class="btn1" />
- </div>
- </td>
- </tr>
- </tfoot>
- </table>
- </form>
- <?php
- }
- mysqli_close($conn);
- ?>
- </div>
- </body>
- </html>
|