index.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. if (0 < $_FILES['excel']['error']) {
  3. echo 'Error: ' . $_FILES['excel']['error'] . '<br>';
  4. } else {
  5. $filepath = 'uploads/' . $_FILES['excel']['name'];
  6. move_uploaded_file($_FILES['excel']['tmp_name'], $filepath);
  7. //$project_id = pathinfo($_FILES['excel']['name'])['filename'];
  8. $project_id = $_POST['projectId'];
  9. $category_id = $_POST['category'];
  10. $file = $_FILES['excel']['name'];
  11. //header("Location: ./index.php?excel={$_FILES['excel']['name']}");
  12. } ?>
  13. <!DOCTYPE html>
  14. <html>
  15. <head>
  16. <title>設計群匯入工具</title>
  17. <meta charset="utf-8">
  18. <link rel="shortcut icon" href="/Database/assets/images/favicon.ico" />
  19. <meta name="viewport" content="width=device-width, initial-scale=1">
  20. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  21. <script src="/DataBase/assets/vendor/jquery/jquery.js"></script>
  22. <script src="/DataBase/script/js/bootstrap.js"></script>
  23. <link rel="stylesheet" href="/DataBase/assets/vendor/font-awesome/css/font-awesome.css" />
  24. <style>
  25. .excel {
  26. font-family: Arial, Helvetica, sans-serif;
  27. border-collapse: collapse;
  28. width: 100%;
  29. }
  30. .nav-tabs>li.active>a,
  31. .nav-tabs>li.active>a:focus,
  32. .nav-tabs>li.active>a:hover {
  33. border: 1px solid #000;
  34. }
  35. .excel td,
  36. .excel th {
  37. border: 1px solid #aaa;
  38. padding: 8px;
  39. }
  40. .excel tr:nth-child(even) {
  41. background-color: #f2f2f2;
  42. }
  43. .excel tr:hover {
  44. background-color: #ddd;
  45. }
  46. .excel th {
  47. padding-top: 12px;
  48. padding-bottom: 12px;
  49. text-align: left;
  50. background-color: #004B7C;
  51. color: white;
  52. }
  53. .submit {
  54. display: inline-block;
  55. margin-left: auto;
  56. margin-right: auto;
  57. width: 20%;
  58. background-color: #004B7C;
  59. border: none;
  60. color: white;
  61. padding: 15px 32px;
  62. text-align: center;
  63. text-decoration: none;
  64. font-size: 16px;
  65. margin: 10px;
  66. }
  67. .delete {
  68. background-color: red;
  69. border: none;
  70. color: white;
  71. padding: 5px 32px;
  72. text-align: center;
  73. text-decoration: none;
  74. display: inline-block;
  75. font-size: 16px;
  76. }
  77. .center {
  78. text-align: center;
  79. }
  80. </style>
  81. </head>
  82. <body>
  83. <ul id="tabs" class="nav nav-tabs">
  84. </ul>
  85. <div id="tab-content" class="tab-content">
  86. </div>
  87. <script type="text/javascript">
  88. $(document).ready(function() {
  89. const queryString = window.location.search;
  90. const urlParams = new URLSearchParams(queryString);
  91. var file = '<?= $file ?>';
  92. var categoryId = '<?= $category_id ?>';
  93. var projectId = '<?= $project_id ?>';
  94. getExcel(file, projectId,categoryId);
  95. });
  96. function getExcel(file, projectId,categoryId) {
  97. $.ajax({
  98. url: "./getExcel.php",
  99. data: {
  100. file: file,
  101. projectId: projectId,
  102. categoryId: categoryId,
  103. },
  104. async: false,
  105. contentType: "application/json",
  106. dataType: "json",
  107. type: "GET",
  108. })
  109. .success(function(response) {
  110. var table = response.table;
  111. var info = response.info;
  112. let i = 0;
  113. for (var tab in table) {
  114. if (i == 0) {
  115. active = 'class="active"';
  116. } else {
  117. active = '';
  118. }
  119. $('#tabs').append(`<li ${active}><a data-toggle="tab" href="#page${i}">${tab}</a></li>`);
  120. $("#tab-content").append(`<div id="page${i}" class="tab-pane fade"></div>`);
  121. appendTable(table[tab], `#page${i}`);
  122. i++;
  123. }
  124. $(`#page${0}`).append("<form id='form' method='post' action='./insertExcel.php'></form>");
  125. appendTable(info, "#form");
  126. $("#form").append("<div class='center'><input class='submit' type='submit' value='開始匯入'><button type='button' class='submit' onClick=\"location.href='./upload.html'\" >重新選擇檔案</button></div>");
  127. })
  128. .error(function(error) {
  129. console.log(error);
  130. })
  131. .complete(function() {
  132. $('#page0').addClass('in active')
  133. });
  134. }
  135. function appendTable(data, id) {
  136. let i = 0;
  137. table = "<table class='excel'>";
  138. for (var tab in data) {
  139. table += "<tr>";
  140. for (j = 0; j < data[tab].length; j++) {
  141. if (i == 0)
  142. table += `<th style="width:33%;">${data[tab][j]}</th>`
  143. else
  144. table += `<td>${data[tab][j]}</td>`
  145. }
  146. i++;
  147. table += "</tr>";
  148. }
  149. table += "</table>";
  150. $(id).append(table);
  151. }
  152. </script>
  153. </body>
  154. </html>