country.php 15 KB

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