-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkInputWFiles.php
148 lines (124 loc) · 4.04 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
<?php
include("parts_checkSession.php");
include("function.php");
include("dbTempUpdate.php");
$filesW = array();
$validDataFlg = true;
// Save Weather data into DB temp tables
if (isset($_POST["submitType"]) && $_POST["upload_file"] == "0") {
$filesW = readTempFileJson("W", false);
if ($filesW != "") {
$fileNumU = count($filesW);
} else {
$filesW = array();
$fileNumU = count($_POST["upload_file_id"]);
}
for($j = 0, $k = 0; $j < count($_POST["wid"]) && $k < $fileNumU; $j++) {
$wid = $_POST["wid"][$j];
if (isset($_FILES["FilePath_" . $wid]["tmp_name"])) {
$fileNumW = count($_FILES["FilePath_" . $wid]["tmp_name"]);
} else {
$fileNumW = 0;
}
$firstFileFlg = true;
$validDataFlgs[$j] = true;
while(isset($_POST["upload_file_id"][$k])) {
if ($_POST["upload_file_id"][$k] == "1") {
if (!isset($filesW[$wid][$k])) {
$filesW[$k]["db_wid"] = $_POST["wid"][$k];
$filesW[$k]["upload"] = array();
}
$k++;
} else {
break;
}
}
for($i = 0; $i < $fileNumW; $i++) {
$line = "";
$flg[0] = "";
$flg[1] = "";
$flg[2] = "";
$lineNo = 0;
$retW = createWthArray();
//$filesW[$i] = $retW;
if ($_FILES["FilePath_" . $wid]["tmp_name"][$i] != "") {
$file = fopen($_FILES["FilePath_" . $wid]["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);
// if ($flg === false) {
//
// } else {
//
// } //TODO later revise to improve performance
}
fclose($file);
// Check if the user input data is contain the necessary data
if (($retW["inste"] . $retW["sitee"]) != $_POST["wid"][$j]) {
$validDataFlgs[$j] = false;
} else {
// TODO check if there is enough days in the upload file
}
//$retW["file_name"] = $_FILES["FilePath_" . $wid]["name"][$i]; // TODO
if (!isset($filesW[$k]) || ($_POST["upload_file_id"][$k] == "0" && $firstFileFlg)) {
$filesW[$k] = array();
$filesW[$k]["wid"] = $_POST["wid"][$j];
$filesW[$k]["file_name"] = array();
$filesW[$k]["start"] = $retW["daily"][1]["yrdoyw"];
$filesW[$k]["end"] = $retW["daily"][count($retW["daily"])]["yrdoyw"];
$firstFileFlg = false;
}
$num = count($filesW[$k]) - 4;
$filesW[$k][$num] = $retW;
$filesW[$k]["file_name"][$num] = $_FILES["FilePath_" . $wid]["name"][$i];
if (compareDate($filesW[$k]["start"], $retW["daily"][1]["yrdoyw"]))
$filesW[$k]["start"] = $retW["daily"][1]["yrdoyw"];
if (compareDate($retW["daily"][count($retW["daily"])]["yrdoyw"], $filesW[$k]["end"]))
$filesW[$k]["end"] = $retW["daily"][count($retW["daily"])]["yrdoyw"];
}
}
}
// if there is data not fulfilled with requirement, then goback
for($i = 0; $i < count($_POST["wid"]); $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) {
// Set forward page
if (!isset($_SESSION["dssat_steps"]) || $_SESSION["dssat_steps"] < 5) {
$_SESSION["dssat_steps"] = 5;
}
$target = "confirmFiles.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 == "confirmFiles.php") {
}
?>
</form>
</body>
</html>