country.php 16 KB

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