uploadExcel.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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. padding-left: 40px;
  99. }
  100. .sidebar-left {
  101. box-shadow: 0 0 0;
  102. }
  103. .jstree-default .jstree-icon {
  104. color: #ffe693;
  105. }
  106. .jqsfield {
  107. color: white;
  108. font: 10px arial, san serif;
  109. text-align: left;
  110. }
  111. .jstree-anchor {
  112. width: 250px;
  113. text-overflow: ellipsis;
  114. overflow: hidden;
  115. white-space: nowrap;
  116. }
  117. .jstree-anchor,
  118. .jstree-anchor:link,
  119. .jstree-anchor:visited,
  120. .jstree-anchor:hover,
  121. .jstree-anchor:active {
  122. color: #abb4be;
  123. }
  124. td,
  125. th {
  126. text-align: center;
  127. }
  128. #tablepage匯入資訊>thead>tr>th {
  129. width: 25%;
  130. }
  131. #tableform>thead>tr>th {
  132. width: 50%;
  133. }
  134. .nav-main {
  135. padding: 15px;
  136. }
  137. .node-hidden {
  138. display: none;
  139. }
  140. html.fixed .page-header {
  141. left: 0px;
  142. }
  143. html.fixed .content-body {
  144. margin-left: 0px;
  145. }
  146. .sidebar-left {
  147. width: 0px;
  148. }
  149. #viewDiv {
  150. height: 100%;
  151. width: 100%;
  152. }
  153. #zoom {
  154. margin-bottom: 5px;
  155. }
  156. #actions {
  157. padding: 5px;
  158. }
  159. .container {
  160. height: 50%;
  161. width: 100%;
  162. }
  163. #createSlideDiv {
  164. background-color: white;
  165. opacity: 0.9;
  166. color: black;
  167. padding: 6px;
  168. }
  169. #slidesDiv {
  170. background-color: white;
  171. opacity: 0.9;
  172. color: black;
  173. padding: 10px;
  174. visibility: hidden;
  175. bottom: 20px;
  176. overflow-y: auto;
  177. text-align: center;
  178. height: 260px;
  179. }
  180. #slidesDiv .slide {
  181. /* Show cursor as pointer when on a slide */
  182. cursor: pointer;
  183. margin-bottom: 6px;
  184. }
  185. #slidesDiv .slide .title {
  186. /* Center the title text */
  187. text-align: center;
  188. }
  189. /* Draw active slide with a nice border around the thumbnail */
  190. #slidesDiv .slide.active img {
  191. box-shadow: 0px 0px 12px black;
  192. border-style: solid;
  193. border-width: thin;
  194. border-color: black;
  195. }
  196. .pdfobject-container {
  197. height: 730px;
  198. }
  199. #topbar {
  200. background: #fff;
  201. padding: 10px;
  202. }
  203. /* uploadExcel */
  204. td>label {
  205. width: 8em;
  206. text-align: left;
  207. padding-right: 0.5em;
  208. /* display: inline-block; */
  209. }
  210. .excel {
  211. font-family: Arial, Helvetica, sans-serif;
  212. border-collapse: collapse;
  213. width: 100%;
  214. }
  215. .nav-tabs>li.active>a,
  216. .nav-tabs>li.active>a:focus,
  217. .nav-tabs>li.active>a:hover {
  218. border: 1px solid #000;
  219. }
  220. .excel td,
  221. .excel th {
  222. border: 1px solid #aaa;
  223. padding: 8px;
  224. }
  225. .excel tr:nth-child(even) {
  226. background-color: #f2f2f2;
  227. }
  228. .excel tr:hover {
  229. background-color: #ddd;
  230. }
  231. .excel th {
  232. padding-top: 12px;
  233. padding-bottom: 12px;
  234. text-align: center;
  235. background-color: #004B7C;
  236. color: white;
  237. }
  238. table.dataTable tbody tr td.NullClass {
  239. background-color: #ed9c28;
  240. }
  241. table.dataTable tbody tr td.ErrorClass {
  242. background-color: #d2322d;
  243. }
  244. .submit {
  245. display: inline-block;
  246. margin-left: auto;
  247. margin-right: auto;
  248. width: 20%;
  249. background-color: #004B7C;
  250. border: none;
  251. color: white;
  252. padding: 15px 32px;
  253. text-align: center;
  254. text-decoration: none;
  255. font-size: 16px;
  256. margin: 10px;
  257. }
  258. .delete {
  259. background-color: red;
  260. border: none;
  261. color: white;
  262. padding: 5px 32px;
  263. text-align: center;
  264. text-decoration: none;
  265. display: inline-block;
  266. font-size: 16px;
  267. }
  268. .center {
  269. text-align: center;
  270. }
  271. .nav-tabs.nav-justified li.active a.error.text-center,
  272. a.error.text-center:hover {
  273. border-bottom-color: transparent;
  274. border-top: 3px solid #d2322d;
  275. box-shadow: none;
  276. color: #d2322d;
  277. }
  278. a.error.text-center,
  279. i.error,
  280. td.error {
  281. color: #d2322d;
  282. }
  283. .nav-tabs.nav-justified li.active a.warning.text-center,
  284. a.warning.text-center:hover {
  285. border-bottom-color: transparent;
  286. border-top: 3px solid #ed9c28;
  287. box-shadow: none;
  288. color: #ed9c28;
  289. }
  290. a.warning.text-center,
  291. i.warning,
  292. td.warning {
  293. color: #ed9c28;
  294. }
  295. .nav-tabs.nav-justified li.active a.info.text-center,
  296. a.info.text-center:hover {
  297. border-bottom-color: transparent;
  298. border-top: 3px solid #0088cc;
  299. box-shadow: none;
  300. color: #0088cc;
  301. }
  302. a.info.text-center,
  303. i.info {
  304. color: #0088cc;
  305. }
  306. .nav-tabs.nav-justified li.active a.success.text-center,
  307. a.success.text-center:hover {
  308. border-bottom-color: transparent;
  309. border-top: 3px solid #4a934a;
  310. box-shadow: none;
  311. color: #4a934a;
  312. }
  313. a.success.text-center,
  314. i.success {
  315. color: #4a934a;
  316. }
  317. .dataTables_wrapper .dataTables_filter label {
  318. width: initial;
  319. }
  320. .dataTables_wrapper .dataTables_filter input {
  321. width: initial;
  322. }
  323. </style>
  324. </head>
  325. <body>
  326. <section class="body">
  327. <!-- start: header -->
  328. <header class="header">
  329. <div class="logo-container">
  330. <div class="banner-txt">設計資料庫匯入工具</div>
  331. <div class="visible-xs toggle-sidebar-left" data-toggle-class="sidebar-left-opened" data-target="html" data-fire-event="sidebar-left-opened">
  332. <i class="fa fa-bars" aria-label="Toggle sidebar"></i>
  333. </div>
  334. </div>
  335. <!-- start: search & user box -->
  336. <div class="header-right">
  337. <span class="separator"></span>
  338. <ul class="notifications">
  339. <li>
  340. <a href="/DataBase/upload.html" class="notification-icon" data-toggle="tooltip" title="匯入工具" data-placement="bottom">
  341. <i class="fa fa-upload"></i>
  342. </a>
  343. <a href="/Front-Page/home.php" class="notification-icon" data-toggle="tooltip" title="綜合登入入口" data-placement="bottom">
  344. <i class="fa fa-home"></i>
  345. </a>
  346. </li>
  347. </ul>
  348. <span class="separator"></span>
  349. <div id="userbox" class="userbox">
  350. <a href="#" data-toggle="dropdown">
  351. <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>
  352. <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>
  353. </a>
  354. <div class="dropdown-menu">
  355. <ul class="list-unstyled">
  356. <li class="divider"></li>
  357. <li> <a role="menuitem" tabindex="-1" href="/DataBase/script/php/Logout.php"><i class="fa fa-power-off"></i> Logout</a> </li>
  358. </ul>
  359. </div>
  360. </div>
  361. </div>
  362. <!-- end: search & user box -->
  363. </header>
  364. <!-- end: header -->
  365. <div class="inner-wrapper">
  366. <!-- start: sidebar -->
  367. <section role="main" class="content-body">
  368. <header class="page-header">
  369. <ul>
  370. <li>
  371. <label id="header"></label>
  372. </li>
  373. </ul>
  374. </header>
  375. <div class="row">
  376. <div class="col-md-4 col-md-offset-8">
  377. 圖示顏色含意: <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>
  378. </div>
  379. <div class="col-md-12">
  380. <div class="tabs">
  381. <ul class="nav nav-tabs nav-justified" id="tabs">
  382. </ul>
  383. <div class="tab-content" id="tab-content">
  384. </div>
  385. </div>
  386. </div>
  387. </div>
  388. </div>
  389. </section>
  390. </div>
  391. </section>
  392. <script type="text/javascript">
  393. var error;
  394. var tables;
  395. var test;
  396. var confirmMsg = "確定要匯入嗎?";
  397. var statusList = {
  398. "error": false,
  399. "warning": false
  400. };
  401. const statusDetail = {
  402. "error": "錯誤:檔案路徑有誤,請再次檢查檔案路徑是否正確。",
  403. "warning": "警告:有資料尚未填寫。"
  404. }
  405. const icons = {
  406. 'info': 'fa fa-info-circle',
  407. 'success': 'fa fa-check-circle',
  408. 'error': 'fa fa-times-circle',
  409. 'warning': 'fa fa-exclamation-circle',
  410. };
  411. $(document).ready(function() {
  412. const queryString = window.location.search;
  413. const urlParams = new URLSearchParams(queryString);
  414. var file = '<?= $file ?>';
  415. var categoryId = '<?= $category_id ?>';
  416. var projectId = '<?= $project_id ?>';
  417. var projectName = '<?= $project_name ?>';
  418. getExcel(file, projectId, projectName, categoryId);
  419. $('#form').submit(function() {
  420. var c = confirm(confirmMsg);
  421. return c;
  422. });
  423. });
  424. function getExcel(file, projectId, projectName, categoryId) {
  425. $.ajax({
  426. url: "./getExcel.php",
  427. data: {
  428. file: file,
  429. projectId: projectId,
  430. categoryId: categoryId,
  431. },
  432. async: false,
  433. contentType: "application/json",
  434. dataType: "json",
  435. type: "GET",
  436. })
  437. .success(function(response) {
  438. tables = response.table;
  439. var info = response.info;
  440. var statuses = response.statuses;
  441. errors = response.errorLists;
  442. var projectInfo = tables["匯入資訊"];
  443. $("#header").append(projectInfo[1][0] + "-" + projectInfo[1][1]); // 16019-促進民間參與高雄市鳳山溪污水處理廠放流水回收再利用案之興建、移轉、營運
  444. for (var tab in tables) {
  445. let status = statuses[tab];
  446. let active = '';
  447. if (tab == "匯入資訊") {
  448. active = 'class="active"';
  449. }
  450. //(statusList[status] != undefined) && (statusList[status] = true);
  451. if (statusList[status] != undefined & !statusList[status]) {
  452. statusList[status] = true;
  453. confirmMsg += "\n"+statusDetail[status];
  454. }
  455. console.log(status);
  456. let icon = icons[status];
  457. $('#tabs').append(`<li ${active}><a href="#page${tab}" data-toggle="tab" class="text-center ${status}"><i class="${icon}"></i> ${tab}</a></li>`);
  458. $("#tab-content").append(`<div id="page${tab}" class="tab-pane fade"></div>`);
  459. appendTable(tables[tab], `page${tab}`);
  460. }
  461. $(`#page匯入資訊`).append("<form id='form' method='post' action='./insertExcel.php'></form>");
  462. appendTable(info, "form");
  463. // TODO: add confirm message
  464. $("#form").append(`<div class='center'><input class='submit' type='submit' value='開始匯入'><button type='button' class='submit' onClick=\"location.href='/DataBase/upload.html'\" >重新選擇檔案</button></div>`);
  465. $("#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}'>`);
  466. })
  467. .error(function(error) {
  468. console.log(error);
  469. })
  470. .complete(function() {
  471. $('#page匯入資訊').addClass('in active')
  472. let i = 1;
  473. for (var tab in tables) {
  474. if (tab != "匯入資訊" && tab != "注意事項") {
  475. var errorList = [];
  476. if (errors[tab] != "" & errors[tab] != undefined) {
  477. errorList = errors[tab].split(',');
  478. errorList.shift();
  479. }
  480. /*$('#tablepage'+i).dataTable({
  481. "createdRow": function(row, data, dataIndex) {
  482. for (j = 0; j < data.length; j++) {
  483. if (data[j] == `null`) {
  484. $(row).addClass('NullClass');
  485. }
  486. }
  487. }
  488. });*/
  489. $('#tablepage' + tab).dataTable({
  490. "language": {
  491. "processing": "處理中...",
  492. "loadingRecords": "載入中...",
  493. "lengthMenu": "顯示 _MENU_ 項資料",
  494. "zeroRecords": "沒有符合的結果或是沒有資料",
  495. "info": "顯示第 _START_ 至 _END_ 項資料,共 _TOTAL_ 項",
  496. "infoEmpty": "顯示第 0 至 0 項資料,共 0 項",
  497. "infoFiltered": "(從 _MAX_ 項資料中過濾)",
  498. "infoPostFix": "",
  499. "search": "搜尋:",
  500. "paginate": {
  501. "first": '<i class="fa fa-step-backward"></i>',
  502. "previous": '<i class="fa fa-backward"></i>',
  503. "next": '<i class="fa fa-forward"></i>',
  504. "last": '<i class="fa fa-step-forward"></i>'
  505. },
  506. "aria": {
  507. "sortAscending": ": 升冪排列",
  508. "sortDescending": ": 降冪排列"
  509. }
  510. },
  511. "columnDefs": [{
  512. "targets": -1,
  513. "createdCell": function(td, cellData, rowData, row, col) {
  514. if (errorList.length > 0) {
  515. for (i = 0; i < errorList.length; i++) {
  516. if (errorList[i] == row) {
  517. $(td).addClass('ErrorClass');
  518. }
  519. }
  520. }
  521. }
  522. }, {
  523. "targets": '_all',
  524. "createdCell": function(td, cellData, rowData, row, col) {
  525. if (cellData == "null") {
  526. $(td).addClass('NullClass');
  527. }
  528. }
  529. }],
  530. });
  531. i++;
  532. }
  533. }
  534. });
  535. }
  536. function appendTable(data, id) {
  537. let i = 0;
  538. table = `<table id='table${id}' class='excel'><thead>`;
  539. for (var tab in data) {
  540. table += "<tr>";
  541. for (j = 0; j < data[tab].length; j++) {
  542. if (i == 0)
  543. table += `<th>${data[tab][j]}</th>` //style="width:33%;"
  544. else
  545. table += `<td>${data[tab][j]}</td>`
  546. }
  547. table += "</tr>";
  548. if (i == 0) {
  549. table += "</thead><tbody>";
  550. }
  551. i++;
  552. }
  553. table += "</tbody></table>";
  554. $('#' + id).append(table);
  555. }
  556. </script>
  557. </body>
  558. </html>