|
|
@@ -4,10 +4,11 @@ include("../sql.php");
|
|
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
+
|
|
|
$type = array();
|
|
|
$i = 0;
|
|
|
-while(isset($_POST["type{$i}"])){
|
|
|
- $type[$i] = $_POST["type{$i}"];
|
|
|
+while (isset($_POST["type{$i}"])) {
|
|
|
+ $type[$i] = $_POST["type{$i}"];
|
|
|
$i++;
|
|
|
}
|
|
|
|
|
|
@@ -20,11 +21,16 @@ if ($conn === false) {
|
|
|
}
|
|
|
|
|
|
$Category_List = [];
|
|
|
-if (isset($_GET['file'])) {
|
|
|
- $file = $_GET['file'];
|
|
|
+if (isset($_POST['file'])) {
|
|
|
+ $file = $_POST['file'];
|
|
|
+ $project_id = $_POST['projectId'];
|
|
|
+ $project_name = $_POST['projectName'];
|
|
|
+ $category_id = $_POST['categoryId'];
|
|
|
+} else {
|
|
|
+ header("Location: ./upload.html#error");
|
|
|
}
|
|
|
+
|
|
|
$filename = "uploads/{$file}";
|
|
|
-$project_id = pathinfo($filename)['filename'];
|
|
|
$importinfo = array();
|
|
|
|
|
|
|
|
|
@@ -36,15 +42,27 @@ $spreadsheet = $reader->load($filename);
|
|
|
$sheetCount = $spreadsheet->getSheetCount();
|
|
|
$all = $spreadsheet->getSheetNames();
|
|
|
|
|
|
+$sql = "DELETE FROM [Blueprint] WHERE [project_id] = ?";
|
|
|
+$stmt = sqlsrv_query($conn, $sql, array($project_id));
|
|
|
+$sql = "DELETE FROM [File_table] WHERE [project_id] = ?";
|
|
|
+$stmt = sqlsrv_query($conn, $sql, array($project_id));
|
|
|
|
|
|
-
|
|
|
+$sql = "IF NOT EXISTS (SELECT [project_id] FROM [Project_Table] WHERE [project_id] = '{$project_id}')
|
|
|
+ BEGIN
|
|
|
+ INSERT INTO [dbo].[Project_Table] ([project_id],[project_name],[category_id])
|
|
|
+ VALUES
|
|
|
+ (?,?,?)
|
|
|
+ END";
|
|
|
+$stmt = sqlsrv_query($conn, $sql, array($project_id,$project_name,$category_id));
|
|
|
for ($s = 0; $s < $sheetCount; $s++) {
|
|
|
- if($type[$s] !='cancel'){
|
|
|
-
|
|
|
+ if ($type[$s] != 'cancel') {
|
|
|
+
|
|
|
if (str_contains($all[$s], "_")) {
|
|
|
$Category = explode("_", $all[$s])[1];
|
|
|
} else if (str_contains($all[$s], ".")) {
|
|
|
$Category = explode(".", $all[$s])[1];
|
|
|
+ } else if (str_contains($all[$s], "-")) {
|
|
|
+ $Category = explode("-", $all[$s])[1];
|
|
|
} else {
|
|
|
$Category = $all[$s];
|
|
|
}
|
|
|
@@ -55,19 +73,60 @@ for ($s = 0; $s < $sheetCount; $s++) {
|
|
|
INSERT INTO [File_Category] ([type_name],[filetype_id]) VALUES ('{$Category}',@filetype_id);
|
|
|
END";
|
|
|
$fetchResult = sqlsrv_query($conn, $sql);
|
|
|
-
|
|
|
+
|
|
|
$sql = "SELECT [type_id] FROM [File_Category] WHERE [type_name] = '{$Category}';";
|
|
|
-
|
|
|
+
|
|
|
$fetchResult = sqlsrv_query($conn, $sql);
|
|
|
- $id = 0;
|
|
|
+ $type_id = 0;
|
|
|
while ($row = sqlsrv_fetch_array($fetchResult)) {
|
|
|
- $id = $row[0];
|
|
|
+ $type_id = $row[0];
|
|
|
}
|
|
|
- array_push($Category_List, $id);
|
|
|
- }
|
|
|
+ array_push($Category_List, $type_id);
|
|
|
+
|
|
|
+ $sheet = $spreadsheet->getSheet($s);
|
|
|
+ $cellCollection = $sheet->getCellCollection();
|
|
|
+ $column = $cellCollection->getHighestRowAndColumn();
|
|
|
+ $data = array();
|
|
|
|
|
|
-
|
|
|
+ for ($i = 2; $i <= $column['row']; $i++) { //行
|
|
|
+ $row = array($project_id, $type_id);
|
|
|
+ for ($j = 'A'; $j <= $column['column']; $j++) { //列
|
|
|
+ $key = $j . $i;
|
|
|
+ $value = $sheet->getCell($key)->getValue();
|
|
|
+ array_push($row, $value);
|
|
|
+ }
|
|
|
+ if ($type[$s] == '[Blueprint]') {
|
|
|
+ $sql = "INSERT INTO [Blueprint]
|
|
|
+ ([project_id]
|
|
|
+ ,[type_id]
|
|
|
+ ,[SN]
|
|
|
+ ,[blueprint_id]
|
|
|
+ ,[original_name]
|
|
|
+ ,[keyword]
|
|
|
+ ,[notes]
|
|
|
+ ,[filename])
|
|
|
+ VALUES
|
|
|
+ (?,?,?,?,?,?,?,?)";
|
|
|
+ } else if ($type[$s] == '[File_Table]') {
|
|
|
+ $sql = "INSERT INTO [File_Table]
|
|
|
+ ([project_id]
|
|
|
+ ,[type_id]
|
|
|
+ ,[SN]
|
|
|
+ ,[original_name]
|
|
|
+ ,[filename]
|
|
|
+ ,[keyword])
|
|
|
+ VALUES
|
|
|
+ (?,?,?,?,?,?)";
|
|
|
+ array_push($row, 'NULL');
|
|
|
+ }
|
|
|
+ $stmt = sqlsrv_query($conn, $sql, $row);
|
|
|
+ echo "<br>";
|
|
|
+ }
|
|
|
+ echo "<br>";
|
|
|
+ echo "<br>";
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
$Category_List_s = implode(",", $Category_List);
|
|
|
$sql = "IF NOT EXISTS (SELECT [list_id] FROM [Category_List] WHERE [category_list] = '{$Category_List_s}')
|
|
|
BEGIN
|
|
|
@@ -75,27 +134,5 @@ $sql = "IF NOT EXISTS (SELECT [list_id] FROM [Category_List] WHERE [category_lis
|
|
|
VALUES ('{$Category_List_s}')
|
|
|
END";
|
|
|
$fetchResult = sqlsrv_query($conn, $sql);
|
|
|
-
|
|
|
-
|
|
|
-for ($s = 0; $s < $sheetCount; $s++) {
|
|
|
-
|
|
|
-
|
|
|
- $sheet = $spreadsheet->getSheet($s);
|
|
|
- $sheetName = $spreadsheet->getSheetNames()[$s];
|
|
|
- $cellCollection = $sheet->getCellCollection();
|
|
|
- $column = $cellCollection->getHighestRowAndColumn();
|
|
|
- $data = array();
|
|
|
-
|
|
|
- for ($i = 1; $i <= $column['row']; $i++) { //行
|
|
|
- $row = array();
|
|
|
- for ($j = 'A'; $j <= $column['column']; $j++) { //列
|
|
|
- $key = $j . $i;
|
|
|
- $value = $sheet->getCell($key)->getValue();
|
|
|
- array_push($row, $value);
|
|
|
- }
|
|
|
- array_push($data, $row);
|
|
|
- }
|
|
|
- $ajax[$sheetName] = $data;
|
|
|
- array_push($importinfo, array($sheetName, ""));
|
|
|
-}
|
|
|
-
|
|
|
+sqlsrv_close($conn);
|
|
|
+header("Location: ./upload.html");
|