-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkInputWFiles.php
149 lines (122 loc) · 3.85 KB
/
checkInputWFiles.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
include("parts_checkSession.php");
include("function.php");
include("dbTempUpdate.php");
$filesW = array();
$validDataFlg = true;
// Save Soil data into DB temp tables
if (isset($_POST["submitType"]) && $_POST["upload_file"] == "0") {
if (isset($_FILES["FilePath"]["tmp_name"])) {
$fileNumW = count($_FILES["FilePath"]["tmp_name"]);
} else {
$fileNumW = 0;
}
$filesW = readTempFileJson("W", false);
if ($filesW != "") {
$fileNumU = count($filesW);
} else {
$filesW = array();
$fileNumU = count($_POST["upload_file_id"]);
}
for($i = 0, $k = 0; $i < $fileNumW && $k < $fileNumU; $i++) {
$line = "";
$flg[0] = "";
$flg[1] = "";
$flg[2] = "";
$lineNo = 0;
$retW = createWthArray();
//$filesW[$i] = $retW;
$validDataFlgs[$i] = true;
if ($_FILES["FilePath"]["tmp_name"][$i] != "") {
$file = fopen($_FILES["FilePath"]["tmp_name"][$i],"r") or exit("Unable to open file!");
while(!feof($file)) {
$lineNo++;
$line = fgets($file);
$flg = judgeContentTypeW($line, $flg); // explode,splitStrToArray
//echo "[line".$lineNo."],[".$flg[0]."],[".$flg[1]."],[".$flg[2]."]<br>"; //debug
$retW = getSpliterResultW($flg, $line, $retW);
}
fclose($file);
// Check if the user input data is contain the necessary data
// TODO check if there is enough days in the upload file
if (($retW["inste"] . $retW["sitee"]) == $_POST["FileId"][$i]) {
$validDataFlgs[$i] = true;
} else {
$validDataFlgs[$i] = false;
}
$retW["file_name"] = $_FILES["FilePath"]["name"][$i]; // TODO
while(isset($_POST["upload_file_id"][$k])) {
if ($_POST["upload_file_id"][$k] == "1") {
if (!isset($filesW[$k])) {
$filesW[$k]["db_wid"] = $_POST["wid"][$k];
$filesW[$k]["upload"] = array();
}
$k++;
} else {
break;
}
}
$filesW[$k] = $retW;
$k++;
}
}
// if there is data not fulfilled with requirement, then goback
for($i = 0; $i < $fileNumW; $i++) {
if (!$validDataFlgs[$i]) {
header("Location: checkInputSFiles.php?inputId=" . $_SESSION["input_id"] . "&" . SID );
$_SESSION["errFlg"] = "004";
$validDataFlg = false;
exit();
}
}
// Save temple Xfile data into temp table when data is OK
if($validDataFlg) updateTempFile(json_encode($filesW), "W");
}
// Read Xfile and decide forward page
if ($validDataFlg) {
// Read XFile From DB temp table
$files = readTempFileJson("X", true);
$ret = $files[0]; // TODO will be changed when multiple file uploaded allowed
// Set forward page
if (isset($_POST["submitType"]) && $_POST["submitType"] == "finish") {
// All check ok, forward to confirm page
if (!isset($_SESSION["dssat_steps"]) || $_SESSION["dssat_steps"] < 5) {
$_SESSION["dssat_steps"] = 5;
}
$target = "confirmFiles.php";
} else {
$fileTypes = checkUploadStatus();
if (!isset($_SESSION["dssat_steps"]) || $_SESSION["dssat_steps"] < 4) {
$_SESSION["dssat_steps"] = 4;
}
$target = "inputFiles04.php";
}
} else {
$target = "inputFiles00.php";
}
?>
<html>
<header>
<script language="javascript">
function autoSubmit() {
var form1 = document.getElementById("form1");
form1.submit();
}
</script>
</header>
<body onload="autoSubmit();">
<form id="form1" method="post" action="<?php echo $target; ?>" enctype="multipart/form-data">
<?php
if ($target == "inputFiles04.php") {
echo "<input type='hidden' name='content_id' value='" . $ret["exp.details:"]["exname"] . "' />\r\n";
if (array_key_exists("O", $fileTypes)) {
for ($i = 0; $i< count($fileTypes["O"]); $i++) {
echo "<input type='hidden' id='upload_file' name='upload_file[]' value='" . $fileTypes["O"][$i] . "' />\r\n";
}
}
} else if ($target == "confirmFiles.php") {
}
?>
</form>
</body>
</html>