forked from agmip/ace-dssat-import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkInputXFiles.php
146 lines (119 loc) · 4.82 KB
/
checkInputXFiles.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
<?php
include("parts_checkSession.php");
include("function.php");
include("dbTempUpdate.php");
$files = array();
// Get file content from user upload file or DB temp tables
if (!isset($_POST["submitType"]) || $_POST["upload_file"] != "0") {
// Read XFile From DB temp table
$files = readTempFileJson("X", true);
} else {
$fileNum = 1; //TODO For furthur multiple input file
for($i = 0; $i < $fileNum; $i++) {
$line = "";
$flg[0] = "";
$flg[1] = "";
$flg[2] = "";
$lineNo = 0;
$ret = createExpArray();
$file = fopen($_FILES["FilePath"]["tmp_name"],"r") or exit("Unable to open file!");
while(!feof($file)) {
$lineNo++;
$line = fgets($file);
$flg = judgeContentType($line, $flg); // explode,splitStrToArray
//echo "[line".$lineNo."],[".$flg[0]."],[".$flg[1]."],[".$flg[2]."]<br>"; //debug
$ret = getSpliterResult($flg, $line, $ret);
}
fclose($file);
$ret = checkExpId($ret, $_FILES["FilePath"]["name"]);
$ret = checkCoordinate($ret);
$ret["file_name"] = $_FILES["FilePath"]["name"];
$files[$i] = $ret;
}
// Save temple Xfile data into temp table
updateTempFile(json_encode($files), "X");
updateTempFileExpName($files[0]["exp.details:"]["exname"]);
$_SESSION["dssat_steps"] = 2;
}
$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 soil data is avaliable in DB
if (!array_key_exists("S", $fileTypes) && !checkSoilAvailable($ret, $checkRet)) {
if (!isset($_SESSION["dssat_steps"]) || $_SESSION["dssat_steps"] < 2) {
$_SESSION["dssat_steps"] = 3;
}
$target = "inputFiles02.php";
// Check if weather data is avaliable in DB
} else 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();
if (!isset($_SESSION["dssat_steps"]) || $_SESSION["dssat_steps"] < 2) {
$_SESSION["dssat_steps"] = 2;
}
$target = "inputFiles04.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 == "inputFiles02.php") {
for ($i = 1; $i <= count($checkRet); $i++) {
echo "<input type='hidden' id='content_status' name='content_status[]' value='" . $checkRet[$i - 1] . "' />\r\n";
echo "<input type='hidden' id='content_id' name='content_id[]' value='" . $ret["fields"][$i]["slno"] . "' />\r\n";
echo "<input type='hidden' id='content_id' name='content_xcrd[]' value='" . $ret["fields"][$i]["xcrd"] . "' />\r\n";
echo "<input type='hidden' id='content_id' name='content_ycrd[]' value='" . $ret["fields"][$i]["ycrd"] . "' />\r\n";
}
if (array_key_exists("S", $fileTypes)) {
for ($i = 0; $i< count($fileTypes["S"]); $i++) {
echo "<input type='hidden' id='upload_file' name='upload_file[]' value='" . $fileTypes["S"][$i] . "' />\r\n";
}
}
} else 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";
}
}
} 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") {
} else {
}
?>
</form>
</body>
</html>