forked from agmip/ace-dssat-import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckInputSFiles.php
167 lines (141 loc) · 4.71 KB
/
checkInputSFiles.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
include("parts_checkSession.php");
include("function.php");
include("dbTempUpdate.php");
$filesS = array();
$validDataFlg = true;
// Save Soil data into DB temp tables
if (isset($_POST["submitType"]) && $_POST["upload_file"] == "0") {
if (isset($_FILES["FilePath"]["tmp_name"])) {
$fileNumS = count($_FILES["FilePath"]["tmp_name"]);
} else {
$fileNumS = 0;
}
$filesS = readTempFileJson("S", false);
if ($filesS != "") {
$fileNumU = count($filesS);
} else {
$filesS = array();
$fileNumU = count($_POST["upload_file_id"]);
}
for($i = 0, $k = 0; $i < $fileNumS && $k < $fileNumU; $i++) {
$line = "";
$flg[0] = "";
$flg[1] = "";
$flg[2] = "";
$lineNo = 0;
$retS = createSoilArray();
//$filesS[$i] = $retS;
$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 = judgeContentTypeS($line, $flg); // explode,splitStrToArray
//echo "[line".$lineNo."],[".$flg[0]."],[".$flg[1]."],[".$flg[2]."]<br>"; //debug
$retS = getSpliterResultS($flg, $line, $retS);
}
fclose($file);
// Check if the user input data is contain the necessary data
$validDataFlgs[$i] = false;
for ($j = 1; $j <= count($retS["site"]); $j++) {
if ($retS["site"][$j]["pedon"] == $_POST["FileId"][$i]) {
$validDataFlgs[$i] = true;
$retS["upload"][$j] = 1;
} else {
$retS["upload"][$j] = 0;
}
}
$retS["file_name"] = $_FILES["FilePath"]["name"][$i];
while(isset($_POST["upload_file_id"][$k])) {
if ($_POST["upload_file_id"][$k] == "1") {
if (!isset($filesS[$k])) {
$filesS[$k]["db_sid"] = $_POST["sid"][$k];
$filesS[$k]["upload"] = array();
}
$k++;
} else {
break;
}
}
$filesS[$k] = $retS;
$k++;
}
}
// if there is data not fulfilled with requirement, then goback
for($i = 0; $i < $fileNumS; $i++) {
if (!$validDataFlgs[$i]) {
header("Location: checkInputXFiles.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($filesS), "S");
}
// 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") {
// Get all type of files which are already be uploaded previously
$fileTypes = checkUploadStatus();
// Check if weather data is avaliable in DB
if (!array_key_exists("W", $fileTypes) && !checkWthAvailable($ret, $checkRet)) {
if (!isset($_SESSION["dssat_steps"]) || $_SESSION["dssat_steps"] < 3) {
$_SESSION["dssat_steps"] = 4;
}
$target = "inputFiles03.php";
} else {
// 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();
checkWthAvailable($ret, $checkRet);
if (!isset($_SESSION["dssat_steps"]) || $_SESSION["dssat_steps"] < 3) {
$_SESSION["dssat_steps"] = 4;
}
$target = "inputFiles03.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 == "inputFiles03.php") {
foreach ($checkRet as $wth) {
echo "<input type='hidden' id='content_id' name='content_id[]' value='" . $wth["wid"] . "' />\r\n";
echo "<input type='hidden' id='content_status' name='content_status[]' value='" . $wth["dbStatus"] . "' />\r\n";
echo "<input type='hidden' id='content_syear' name='content_start[]' value='" . $wth["start"] . "' />\r\n";
echo "<input type='hidden' id='content_status' name='content_end[]' value='" . $wth["end"] . "' />\r\n";
}
if (array_key_exists("W", $fileTypes)) {
for ($i = 0; $i< count($fileTypes["W"]); $i++) {
echo "<input type='hidden' id='upload_file' name='upload_file[]' value='" . json_encode($fileTypes["W"][$i]) . "' />\r\n";
}
}
} else if ($target == "confirmFiles.php") {
}
?>
</form>
</body>
</html>