country.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <?php
  2. require_once 'conn.php';
  3. checklogin("信息管理");
  4. ?>
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <title>管理区域</title>
  10. <link rel="stylesheet" href="css/common.css" type="text/css" />
  11. <link rel="stylesheet" href="css/jquery.galpop.css" type="text/css" />
  12. <script language="javascript" src="js/jquery-1.7.2.min.js"></script>
  13. <script type="text/javascript" src="js/js.js"></script>
  14. <script type="text/javascript" src="xheditor-1.1.9/xheditor-1.1.9-zh-cn.min.js"></script>
  15. <script type="text/javascript" src="js/Searchproduct.js"></script>
  16. </head>
  17. <body>
  18. <div id="man_zone">
  19. <?php
  20. $act = $_GET['act'] ?? '';
  21. if ($act == "save") {
  22. $isedit = false;
  23. $id = $_POST['id'] ?? '';
  24. if ($id != "" && is_numeric($id)) {
  25. $isedit = true;
  26. }
  27. $productId = $_POST['productId'] ?? '';
  28. $num = $_POST['num'] ?? '';
  29. $price = $_POST['price'] ?? '';
  30. if ($isedit) {
  31. $sql = "UPDATE country SET addtime=NOW() WHERE id=$id";
  32. $conn->query($sql);
  33. $productIds = explode(',', $productId);
  34. $nums = explode(',', $num);
  35. $prices = explode(',', $price);
  36. $conn->query("DELETE FROM price WHERE AreaId=$id");
  37. for ($i = 0; $i < count($productIds); $i++) {
  38. $numVal = empty($nums[$i]) ? 0 : $nums[$i];
  39. $priceVal = empty($prices[$i]) ? 0 : $prices[$i];
  40. $sql = "INSERT INTO price (productId, AreaId, num, price) VALUES ($productIds[$i], $id, $numVal, '$priceVal')";
  41. $conn->query($sql);
  42. }
  43. $page = $_GET['Page'] ?? '';
  44. $keys = urlencode($_GET['Keys'] ?? '');
  45. $ord = urlencode($_GET['Ord'] ?? '');
  46. header("Location: ?keys=$keys&Ord=$ord&Page=$page");
  47. exit;
  48. } else {
  49. $sql = "INSERT INTO country (addtime) VALUES (NOW())";
  50. $conn->query($sql);
  51. $id = $conn->insert_id;
  52. $productIds = explode(',', $productId);
  53. $nums = explode(',', $num);
  54. $prices = explode(',', $price);
  55. for ($i = 0; $i < count($productIds); $i++) {
  56. $numVal = empty($nums[$i]) ? 0 : $nums[$i];
  57. $priceVal = empty($prices[$i]) ? 0 : $prices[$i];
  58. $sql = "INSERT INTO price (productId, AreaId, num, price) VALUES ($productIds[$i], $id, $numVal, '$priceVal')";
  59. $conn->query($sql);
  60. }
  61. header("Location: ?");
  62. exit;
  63. }
  64. }
  65. if ($act == "add" || $act == "edit") {
  66. $id = $_GET['id'] ?? '';
  67. $isedit = false;
  68. $countryCode = '';
  69. $countryName = '';
  70. $addtime = '';
  71. if ($id != "" && is_numeric($id)) {
  72. $isedit = true;
  73. $sql = "SELECT * FROM country WHERE id = $id";
  74. $result = $conn->query($sql);
  75. $row = $result->fetch_assoc();
  76. if ($row) {
  77. $countryCode = $row['countryCode'];
  78. $countryName = $row['countryName'];
  79. $addtime = $row['addtime'];
  80. } else {
  81. $isedit = false;
  82. }
  83. }
  84. $page = $_GET['Page'] ?? '';
  85. $keys = urlencode($_GET['Keys'] ?? '');
  86. $ord = urlencode($_GET['Ord'] ?? '');
  87. $hrefstr = "?keys=$keys&Ord=$ord&Page=$page";
  88. ?>
  89. <form name="form1" method="post" action="<?= $hrefstr ?>&act=save">
  90. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  91. <tbody>
  92. <tr>
  93. <th width="8%">国家</th>
  94. <td><input type="text" id="countryName" name="countryName" readonly value="<?= htmlspecialcharsFix($countryName) ?>" class="txt1" /><input type="hidden" name="id" value="<?= $id ?>" /></td>
  95. </tr>
  96. <tr>
  97. <th width="8%">区号</th>
  98. <td><input type="text" id="countryCode" name="countryCode" readonly value="<?= htmlspecialcharsFix($countryCode) ?>" class="txt1" /></td>
  99. </tr>
  100. <tr>
  101. <th width="8%">更新日期</th>
  102. <td><?= $addtime ?></td>
  103. </tr>
  104. <tr>
  105. <th width="8%">售价管理</th>
  106. <td>
  107. <div class="prowapper">
  108. <?php
  109. $sql = "SELECT id, ProductName, ProductImg, unit FROM Products WHERE id IN (SELECT productId FROM price WHERE AreaId = $id)";
  110. $result = $conn->query($sql);
  111. while ($row = $result->fetch_assoc()) {
  112. ?>
  113. <div class="proitem">
  114. <div class="prodelet"></div>
  115. <div class="proname"><?= htmlspecialcharsFix($row['ProductName']) ?></div>
  116. <div class="propic"><img src="<?= htmlspecialcharsFix($row['ProductImg']) ?>"></div>
  117. <div class="proprice">
  118. <?php
  119. $sql2 = "SELECT num, price FROM Price WHERE productId = {$row['id']} AND AreaId = $id ORDER BY num ASC";
  120. $result2 = $conn->query($sql2);
  121. while ($row2 = $result2->fetch_assoc()) {
  122. ?>
  123. <div class="priceitem">
  124. <input type="hidden" name="productId" value="<?= $row['id'] ?>">
  125. <label>≥</label>
  126. <input type="number" autocomplete="off" class="txt3 num" name="num" value="<?= $row2['num'] ?>">
  127. <label class='unit'><?= htmlspecialcharsFix($row['unit']) ?></label>
  128. <label>售价</label>
  129. <input type="text" class="txt3 price" autocomplete="off" name="price" value="<?= $row2['price'] ?>">
  130. <label>RMB</label>
  131. <span class="additem"></span>
  132. <span class="delitem"></span>
  133. <span class="note"></span>
  134. </div>
  135. <?php
  136. }
  137. ?>
  138. </div>
  139. </div>
  140. <?php
  141. }
  142. ?>
  143. </div>
  144. </td>
  145. </tr>
  146. <tr>
  147. <th width="8%">产品添加</th>
  148. <td class="productinput">
  149. <input type="text" id="productSearch" class="fastsearch">
  150. <div id="productlist" class="productlist"><ul></ul></div>
  151. </td>
  152. </tr>
  153. <tr>
  154. <th></th>
  155. <td>
  156. <input type="submit" name="save" id="save" value="确定" class="btn1" />
  157. <input type="reset" name="save" id="save" value="重置" class="btn1" />
  158. <input type="button" value="返回" class="btn1" onClick="location.href='<?= $hrefstr ?>'" />
  159. </td>
  160. </tr>
  161. </tbody>
  162. </table>
  163. </form>
  164. </div>
  165. </body>
  166. </html>
  167. <?php
  168. exit;
  169. }
  170. if ($act == "postchk") {
  171. $keys = urlencode($_GET['Keys'] ?? '');
  172. $ord = urlencode($_GET['Ord'] ?? '');
  173. $page = $_GET['Page'] ?? '';
  174. $chkact = $_POST['chkact'] ?? '';
  175. if (isset($_POST['chkbox']) && is_array($_POST['chkbox'])) {
  176. $ids = implode(',', array_map('intval', $_POST['chkbox']));
  177. $sql = "DELETE FROM country WHERE id IN ($ids)";
  178. $conn->query($sql);
  179. }
  180. header("Location: ?Keys=$keys&Ord=$ord&Page=$page");
  181. exit;
  182. }
  183. // Main list view
  184. $keys = $_GET['Keys'] ?? '';
  185. $keyscode = $keys;
  186. $ord = $_GET['Ord'] ?? '';
  187. $page = $_GET['Page'] ?? '';
  188. $sql = "SELECT * FROM country WHERE countryName LIKE '%$keyscode%' OR countryCode LIKE '%$keyscode%' ORDER BY id DESC";
  189. $result = $conn->query($sql);
  190. $results = [];
  191. while($row = $result->fetch_assoc()) {
  192. $results[] = $row;
  193. }
  194. $totalRecords = count($results);
  195. $pageSize = 20;
  196. $totalPages = ceil($totalRecords / $pageSize);
  197. if ($page == "") $page = 1;
  198. if ($page == "end") $page = $totalPages;
  199. if (!is_numeric($page) || $page < 1) $page = 1;
  200. $page = (int)$page;
  201. if ($page > $totalPages) $page = $totalPages;
  202. $start = ($page - 1) * $pageSize;
  203. $currentPageRecords = array_slice($results, $start, $pageSize);
  204. $keys = urlencode($keys);
  205. $ord = urlencode($ord);
  206. $hrefstr = "?keys=$keys";
  207. ?>
  208. <form id="form1" method="post" action="?act=postchk&Keys=<?= $keys ?>&Ord=<?= $ord ?>&Page=<?= $page ?>" onSubmit="return false">
  209. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  210. <thead>
  211. <tr>
  212. <th width="4%"><input type="checkbox" name="chkall" id="chkall" onClick="chkboxall(this,'chkbox')" /></th>
  213. <th width="6%">序号</th>
  214. <th width="30%">国家</th>
  215. <th width="30%">区号</th>
  216. <th width="30%">操作</th>
  217. </tr>
  218. </thead>
  219. <tbody>
  220. <?php
  221. if (!empty($currentPageRecords)) {
  222. $tempNum = $start;
  223. foreach ($currentPageRecords as $row) {
  224. $tempNum++;
  225. ?>
  226. <tr onMouseOver="this.style.background='#F7FCFF'" onMouseOut="this.style.background='#FFFFFF'">
  227. <td align="center"><input type="checkbox" name="chkbox[]" value="<?= $row['id'] ?>" /></td>
  228. <td align="center"><?= $tempNum ?></td>
  229. <td align="center"><?= htmlspecialcharsFix($row['countryName']) ?></td>
  230. <td align="center"><?= htmlspecialcharsFix($row['countryCode']) ?></td>
  231. <td align="center">
  232. <a href="?Keys=<?= $keys ?>&Ord=<?= $ord ?>&Page=<?= $page ?>&act=edit&id=<?= $row['id'] ?>" class="ico_edit ico">修改</a>
  233. </td>
  234. </tr>
  235. <?php
  236. }
  237. } else {
  238. if ($keys == "") {
  239. ?>
  240. <tr>
  241. <td align="center" colspan="5">Sorry,当前暂无信息</td>
  242. </tr>
  243. <?php
  244. } else {
  245. ?>
  246. <tr>
  247. <td align="center" colspan="5"><a href="?">Sorry,没有找到"<?= htmlspecialcharsFix($keyscode) ?>"相关的信息,点击返回</a></td>
  248. </tr>
  249. <?php
  250. }
  251. }
  252. ?>
  253. </tbody>
  254. <tfoot>
  255. <tr>
  256. <td colspan="5">
  257. <div class="showpagebox">
  258. <?php
  259. if ($totalPages > 1) {
  260. $pageName = "?Keys=$keys&Ord=$ord&";
  261. $pagelen = 3;
  262. if ($page > 1) {
  263. echo "<a href=\"{$pageName}Page=1\">首页</a>";
  264. echo "<a href=\"{$pageName}Page=" . ($page-1) . "\">上一页</a>";
  265. }
  266. if ($pagelen * 2 + 1 >= $totalPages) {
  267. $startPage = 1;
  268. $endPage = $totalPages;
  269. } else {
  270. if ($page <= $pagelen + 1) {
  271. $startPage = 1;
  272. $endPage = $pagelen * 2 + 1;
  273. } else {
  274. $startPage = $page - $pagelen;
  275. $endPage = $page + $pagelen;
  276. }
  277. if ($page + $pagelen > $totalPages) {
  278. $startPage = $totalPages - $pagelen * 2;
  279. $endPage = $totalPages;
  280. }
  281. }
  282. for ($i = $startPage; $i <= $endPage; $i++) {
  283. if ($i == $page) {
  284. echo "<a class=\"current\">$i</a>";
  285. } else {
  286. echo "<a href=\"{$pageName}Page=$i\">$i</a>";
  287. }
  288. }
  289. if ($page < $totalPages) {
  290. if ($totalPages - $page > $pagelen) {
  291. echo "<a href=\"{$pageName}Page=$totalPages\">...$totalPages</a>";
  292. }
  293. echo "<a href=\"{$pageName}Page=" . ($page+1) . "\">下一页</a>";
  294. echo "<a href=\"{$pageName}Page=$totalPages\">尾页</a>";
  295. }
  296. echo "<input type=\"text\" id=\"Pagego\" value=\"$page\" onFocus=\"if(this.value == '$page'){this.value='';}\""
  297. . " onBlur=\"if(this.value == ''){this.value='$page';}\""
  298. . " onKeyUp=\"this.value=this.value.replace(/\\D/g,'')\""
  299. . " onKeyDown=\"if(event.keyCode==13){location.href='{$pageName}Page='+document.getElementById('Pagego').value}\" />";
  300. }
  301. ?>
  302. </div>
  303. <div class="searchbox">
  304. <input type="text" id="keys" value="<?= $keyscode == "" ? "请输入搜索关键词" : htmlspecialcharsFix($keyscode) ?>"
  305. onFocus="if(this.value == '<?= $keyscode == "" ? "请输入搜索关键词" : htmlspecialcharsFix($keyscode) ?>'){this.value='';}"
  306. onBlur="if(this.value == ''){this.value='<?= $keyscode == "" ? "请输入搜索关键词" : htmlspecialcharsFix($keyscode) ?>';}"
  307. onKeyDown="if(event.keyCode==13){location.href='?Keys='+encodeURIComponent(document.getElementById('keys').value)}" />
  308. <input type="button" id="searchgo" value="go" onClick="location.href='?Keys='+encodeURIComponent(document.getElementById('keys').value)" />
  309. </div>
  310. <div class="postchkbox">
  311. <select id="chkact" name="chkact">
  312. <option value="1">请选择</option>
  313. <option value="-1">删除</option>
  314. </select>
  315. <input type="button" value="执行" onClick="postchk(1)" class="btn1" />
  316. <input type="button" value="新增" onClick="location.href='?act=add'" class="btn1" />
  317. </div>
  318. </td>
  319. </tr>
  320. </tfoot>
  321. </table>
  322. </form>
  323. </div>
  324. <script>
  325. $('.click-open-iframe').galpop({
  326. contentType: 'iframe',
  327. });
  328. </script>
  329. </body>
  330. </html>