uploadExcel.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <?php
  2. session_start();
  3. //Can't come in without logged in
  4. if (!isset($_SESSION['loggedin'])) {
  5. header('Location: pages-signin.html');
  6. exit;
  7. }
  8. if (!isset($_FILES['excel']['error'])) {
  9. //header("Location: /DataBase/upload.html");
  10. }
  11. if (0 < $_FILES['excel']['error']) {
  12. echo 'Error: ' . $_FILES['excel']['error'] . '<br>';
  13. } else {
  14. $filepath = 'uploads/' . $_FILES['excel']['name'];
  15. move_uploaded_file($_FILES['excel']['tmp_name'], $filepath);
  16. $project_id = $_POST['projectId'];
  17. $project_name = $_POST['projectName'];
  18. $category_id = $_POST['category'];
  19. $file = $_FILES['excel']['name'];
  20. }
  21. ?>
  22. <!doctype html>
  23. <html class="fixed">
  24. <head>
  25. <!-- Basic -->
  26. <meta charset="UTF-8">
  27. <title>設計資料庫匯入工具</title>
  28. <meta name="keywords" content="HTML5 Admin Template" />
  29. <meta name="description" content="JSOFT Admin - Responsive HTML5 Template">
  30. <meta name="author" content="JSOFT.net">
  31. <script src="/DataBase/assets/vendor/jquery/jquery.js"></script>
  32. <!-- Mobile Metas -->
  33. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  34. <!-- Web Fonts -->
  35. <link href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800|Shadows+Into+Light" rel="stylesheet" type="text/css">
  36. <!-- jstree CSS -->
  37. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.4/themes/default/style.min.css">
  38. <!-- Vendor CSS -->
  39. <link rel="stylesheet" href="/DataBase/assets/vendor/bootstrap/css/bootstrap.css" />
  40. <link rel="stylesheet" href="/DataBase/assets/vendor/font-awesome/css/font-awesome.css" />
  41. <link rel="stylesheet" href="/DataBase/assets/vendor/magnific-popup/magnific-popup.css" />
  42. <link rel="stylesheet" href="/DataBase/assets/vendor/bootstrap-datepicker/css/datepicker3.css" />
  43. <link rel="stylesheet" href="/DataBase/assets/vendor/pnotify/pnotify.custom.css" />
  44. <!-- Specific Page Vendor CSS -->
  45. <link rel="stylesheet" href="/DataBase/assets/vendor/jquery-ui/css/ui-lightness/jquery-ui-1.10.4.custom.css" />
  46. <link rel="stylesheet" href="/DataBase/assets/vendor/bootstrap-multiselect/bootstrap-multiselect.css" />
  47. <link rel="stylesheet" href="/DataBase/assets/vendor/morris/morris.css" />
  48. <link rel="stylesheet" href="/DataBase/assets/vendor/bootstrap-fileupload/bootstrap-fileupload.min.css" />
  49. <!-- Theme CSS -->
  50. <link rel="stylesheet" href="/DataBase/assets/stylesheets/theme.css" />
  51. <!-- Skin CSS -->
  52. <link rel="stylesheet" href="/DataBase/assets/stylesheets/skins/default.css" />
  53. <!-- Theme Custom CSS -->
  54. <link rel="stylesheet" href="/DataBase/assets/stylesheets/theme-custom.css">
  55. <!-- Head Libs -->
  56. <script src="/DataBase/assets/vendor/modernizr/modernizr.js"></script>
  57. <!-- chart.js -->
  58. <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
  59. <!-- DataTable -->
  60. <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.25/css/jquery.dataTables.css">
  61. <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.js"></script>
  62. <!-- Icon -->
  63. <link rel="shortcut icon" href="/DataBase/assets/images/favicon.ico" />
  64. <link href="https://js.arcgis.com/4.21/esri/themes/light/main.css" rel="stylesheet">
  65. <link href="/DataBase/CustomCSS/main.css" rel="stylesheet">
  66. <script src="/DataBase/script/js/bootstrap.js"></script>
  67. <script src="/DataBase/script/js/pdfobject.min.js"></script>
  68. <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.4/jstree.min.js"></script>
  69. <script src="https://js.arcgis.com/4.21/"></script>
  70. <style>
  71. body {
  72. color: #000;
  73. }
  74. .row {
  75. margin-top: -15px;
  76. }
  77. .page-header>ul {
  78. list-style: none;
  79. padding: 0;
  80. margin: 0;
  81. }
  82. .page-header>ul>li {
  83. display: inline-block;
  84. font-size: 25px;
  85. color: #FFFFFF;
  86. }
  87. .page-header>ul>li.right {
  88. float: right;
  89. padding-right: 10px;
  90. }
  91. .input-search {
  92. margin-top: 8px;
  93. }
  94. .page-header li>label {
  95. margin-top: 13px;
  96. border-bottom: 4px solid #0088cc;
  97. height: 41px;
  98. }
  99. .sidebar-left {
  100. box-shadow: 0 0 0;
  101. }
  102. .jstree-default .jstree-icon {
  103. color: #ffe693;
  104. }
  105. .jqsfield {
  106. color: white;
  107. font: 10px arial, san serif;
  108. text-align: left;
  109. }
  110. .jstree-anchor {
  111. width: 250px;
  112. text-overflow: ellipsis;
  113. overflow: hidden;
  114. white-space: nowrap;
  115. }
  116. .jstree-anchor,
  117. .jstree-anchor:link,
  118. .jstree-anchor:visited,
  119. .jstree-anchor:hover,
  120. .jstree-anchor:active {
  121. color: #abb4be;
  122. }
  123. td,
  124. th {
  125. text-align: center;
  126. }
  127. th {
  128. width: 30%;
  129. }
  130. .nav-main {
  131. padding: 15px;
  132. }
  133. .node-hidden {
  134. display: none;
  135. }
  136. html.fixed .page-header {
  137. left: 0px;
  138. }
  139. html.fixed .content-body {
  140. margin-left: 0px;
  141. }
  142. .sidebar-left {
  143. width: 0px;
  144. }
  145. #datatable-ajax tr:hover {
  146. background-color: #e8e8e8;
  147. }
  148. #viewDiv {
  149. height: 100%;
  150. width: 100%;
  151. }
  152. #zoom {
  153. margin-bottom: 5px;
  154. }
  155. #actions {
  156. padding: 5px;
  157. }
  158. .container {
  159. height: 50%;
  160. width: 100%;
  161. }
  162. #createSlideDiv {
  163. background-color: white;
  164. opacity: 0.9;
  165. color: black;
  166. padding: 6px;
  167. }
  168. #slidesDiv {
  169. background-color: white;
  170. opacity: 0.9;
  171. color: black;
  172. padding: 10px;
  173. visibility: hidden;
  174. bottom: 20px;
  175. overflow-y: auto;
  176. text-align: center;
  177. height: 260px;
  178. }
  179. #slidesDiv .slide {
  180. /* Show cursor as pointer when on a slide */
  181. cursor: pointer;
  182. margin-bottom: 6px;
  183. }
  184. #slidesDiv .slide .title {
  185. /* Center the title text */
  186. text-align: center;
  187. }
  188. /* Draw active slide with a nice border around the thumbnail */
  189. #slidesDiv .slide.active img {
  190. box-shadow: 0px 0px 12px black;
  191. border-style: solid;
  192. border-width: thin;
  193. border-color: black;
  194. }
  195. .pdfobject-container {
  196. height: 730px;
  197. }
  198. #topbar {
  199. background: #fff;
  200. padding: 10px;
  201. }
  202. /* uploadExcel */
  203. td>label {
  204. width: 8em;
  205. text-align: left;
  206. padding-right: 0.5em;
  207. /* display: inline-block; */
  208. }
  209. .excel {
  210. font-family: Arial, Helvetica, sans-serif;
  211. border-collapse: collapse;
  212. width: 100%;
  213. }
  214. .nav-tabs>li.active>a,
  215. .nav-tabs>li.active>a:focus,
  216. .nav-tabs>li.active>a:hover {
  217. border: 1px solid #000;
  218. }
  219. .excel td,
  220. .excel th {
  221. border: 1px solid #aaa;
  222. padding: 8px;
  223. }
  224. .excel tr:nth-child(even) {
  225. background-color: #f2f2f2;
  226. }
  227. .excel tr:hover {
  228. background-color: #ddd;
  229. }
  230. .excel th {
  231. padding-top: 12px;
  232. padding-bottom: 12px;
  233. text-align: center;
  234. background-color: #004B7C;
  235. color: white;
  236. }
  237. .submit {
  238. display: inline-block;
  239. margin-left: auto;
  240. margin-right: auto;
  241. width: 20%;
  242. background-color: #004B7C;
  243. border: none;
  244. color: white;
  245. padding: 15px 32px;
  246. text-align: center;
  247. text-decoration: none;
  248. font-size: 16px;
  249. margin: 10px;
  250. }
  251. .delete {
  252. background-color: red;
  253. border: none;
  254. color: white;
  255. padding: 5px 32px;
  256. text-align: center;
  257. text-decoration: none;
  258. display: inline-block;
  259. font-size: 16px;
  260. }
  261. .center {
  262. text-align: center;
  263. }
  264. .nav-tabs.nav-justified li.active a.error.text-center,
  265. a.error.text-center:hover {
  266. border-bottom-color: transparent;
  267. border-top: 3px solid #d2322d;
  268. box-shadow: none;
  269. color: #d2322d;
  270. }
  271. a.error.text-center,i.error {
  272. color: #d2322d;
  273. }
  274. .nav-tabs.nav-justified li.active a.warning.text-center,
  275. a.warning.text-center:hover {
  276. border-bottom-color: transparent;
  277. border-top: 3px solid #ed9c28;
  278. box-shadow: none;
  279. color: #ed9c28;
  280. }
  281. a.warning.text-center,i.warning {
  282. color: #ed9c28;
  283. }
  284. .nav-tabs.nav-justified li.active a.info.text-center,
  285. a.info.text-center:hover {
  286. border-bottom-color: transparent;
  287. border-top: 3px solid #0088cc;
  288. box-shadow: none;
  289. color: #0088cc;
  290. }
  291. a.info.text-center,i.info {
  292. color: #0088cc;
  293. }
  294. .nav-tabs.nav-justified li.active a.success.text-center,
  295. a.success.text-center:hover {
  296. border-bottom-color: transparent;
  297. border-top: 3px solid #4a934a;
  298. box-shadow: none;
  299. color: #4a934a;
  300. }
  301. a.success.text-center,i.success {
  302. color: #4a934a;
  303. }
  304. </style>
  305. </head>
  306. <body>
  307. <section class="body">
  308. <!-- start: header -->
  309. <header class="header">
  310. <div class="logo-container">
  311. <div class="banner-txt">設計資料庫匯入工具</div>
  312. <div class="visible-xs toggle-sidebar-left" data-toggle-class="sidebar-left-opened" data-target="html" data-fire-event="sidebar-left-opened">
  313. <i class="fa fa-bars" aria-label="Toggle sidebar"></i>
  314. </div>
  315. </div>
  316. <!-- start: search & user box -->
  317. <div class="header-right">
  318. <span class="separator"></span>
  319. <ul class="notifications">
  320. <li>
  321. <a href="/DataBase/upload.html" class="notification-icon" data-toggle="tooltip" title="匯入工具" data-placement="bottom">
  322. <i class="fa fa-upload"></i>
  323. </a>
  324. <a href="/Front-Page/home.php" class="notification-icon" data-toggle="tooltip" title="綜合登入入口" data-placement="bottom">
  325. <i class="fa fa-home"></i>
  326. </a>
  327. </li>
  328. </ul>
  329. <span class="separator"></span>
  330. <div id="userbox" class="userbox">
  331. <a href="#" data-toggle="dropdown">
  332. <figure class="profile-picture"> <img src="/DataBase/assets/images/!logged-user.jpg" alt="Joseph Doe" class="img-circle" data-lock-picture="/DataBase/assets/images/!logged-user.jpg" /> </figure>
  333. <div class="profile-info" data-lock-name="John Doe" data-lock-email="johndoe@JSOFT.com"> <span class="name"><?php echo $_SESSION['name'] ?></span> <span class="role">tester</span> </div> <i class="fa custom-caret"></i>
  334. </a>
  335. <div class="dropdown-menu">
  336. <ul class="list-unstyled">
  337. <li class="divider"></li>
  338. <li> <a role="menuitem" tabindex="-1" href="/DataBase/script/php/Logout.php"><i class="fa fa-power-off"></i> Logout</a> </li>
  339. </ul>
  340. </div>
  341. </div>
  342. </div>
  343. <!-- end: search & user box -->
  344. </header>
  345. <!-- end: header -->
  346. <div class="inner-wrapper">
  347. <!-- start: sidebar -->
  348. <section role="main" class="content-body">
  349. <header class="page-header">
  350. <ul>
  351. <li>
  352. <label id="header"></label>
  353. </li>
  354. </ul>
  355. </header>
  356. <div class="row">
  357. <div class="col-md-4 col-md-offset-8">
  358. 圖示顏色含意: <i class="fa fa-info-circle info">匯入確認頁面</i> <i class="fa fa-check-circle success">此頁面資料正確</i> <i class="fa fa-exclamation-circle warning">此頁面資料有空</i> <i class="fa fa-times-circle error">此頁面檔案路徑有誤</i>
  359. </div>
  360. <div class="col-md-12">
  361. <div class="tabs">
  362. <ul class="nav nav-tabs nav-justified" id="tabs">
  363. </ul>
  364. <div class="tab-content" id="tab-content">
  365. </div>
  366. </div>
  367. </div>
  368. </div>
  369. </div>
  370. </section>
  371. </div>
  372. </section>
  373. <script type="text/javascript">
  374. const icons = {
  375. 'info':'fa fa-info-circle',
  376. 'success':'fa fa-check-circle',
  377. 'error':'fa fa-times-circle',
  378. 'warning':'fa fa-exclamation-circle',
  379. };
  380. // TODO: 1.頁籤依據選擇變色 2.偵測null欄位資料
  381. $(document).ready(function() {
  382. const queryString = window.location.search;
  383. const urlParams = new URLSearchParams(queryString);
  384. var file = '<?= $file ?>';
  385. var categoryId = '<?= $category_id ?>';
  386. var projectId = '<?= $project_id ?>';
  387. var projectName = '<?= $project_name ?>';
  388. getExcel(file, projectId, projectName, categoryId);
  389. });
  390. function getExcel(file, projectId, projectName, categoryId) {
  391. $.ajax({
  392. url: "./getExcel.php",
  393. data: {
  394. file: file,
  395. projectId: projectId,
  396. categoryId: categoryId,
  397. },
  398. async: false,
  399. contentType: "application/json",
  400. dataType: "json",
  401. type: "GET",
  402. })
  403. .success(function(response) {
  404. var table = response.table;
  405. var info = response.info;
  406. var statuses = response.statuses;
  407. console.log(response.test);
  408. let i = 0;
  409. for (var tab in table) {
  410. let status = statuses[i];
  411. let active = '';
  412. if (i == 0) {
  413. active = 'class="active"';
  414. }
  415. let icon = icons[status];
  416. $('#tabs').append(`<li ${active}><a href="#page${i}" data-toggle="tab" class="text-center ${status}"><i class="${icon}"></i> ${tab}</a></li>`);
  417. $("#tab-content").append(`<div id="page${i}" class="tab-pane fade"></div>`);
  418. appendTable(table[tab], `#page${i}`);
  419. i++;
  420. }
  421. $(`#page${0}`).append("<form id='form' method='post' action='./insertExcel.php'></form>");
  422. appendTable(info, "#form");
  423. // TODO: add confirm message
  424. $("#form").append(`<div class='center'><input class='submit' type='submit' value='開始匯入'><button type='button' class='submit' onClick=\"location.href='/DataBase/upload.html'\" >重新選擇檔案</button></div>`);
  425. $("#form").append(`<input id='projectId' name='projectId' type='hidden' value='${projectId}'><input id='projectName' name='projectName' type='hidden' value='${projectName}'><input id='file' name='file' type='hidden' value='${file}'><input id='categoryId' name='categoryId' style='display:none;' value='${categoryId}'>`);
  426. })
  427. .error(function(error) {
  428. console.log(error);
  429. })
  430. .complete(function() {
  431. $('#page0').addClass('in active')
  432. });
  433. }
  434. function appendTable(data, id) {
  435. let i = 0;
  436. table = "<table class='excel'>";
  437. for (var tab in data) {
  438. table += "<tr>";
  439. for (j = 0; j < data[tab].length; j++) {
  440. if (i == 0)
  441. table += `<th style="width:33%;">${data[tab][j]}</th>`
  442. else
  443. table += `<td>${data[tab][j]}</td>`
  444. }
  445. i++;
  446. table += "</tr>";
  447. }
  448. table += "</table>";
  449. $(id).append(table);
  450. }
  451. </script>
  452. </body>
  453. </html>