/checkInputXFiles.php

https://github.com/MengZhang/dssat-xfile-upload · PHP · 137 lines · 103 code · 25 blank · 9 comment · 35 complexity · 4acba8378ad1cd02d223efb0b948521e MD5 · raw file

  1. <?php
  2. include("parts_checkSession.php");
  3. include("function.php");
  4. include("dbTempUpdate.php");
  5. $files = array();
  6. // Get file content from user upload file or DB temp tables
  7. if (!isset($_POST["submitType"]) || $_POST["upload_file"] != "0") {
  8. // Read XFile From DB temp table
  9. $files = readTempFileJson("X", true);
  10. } else {
  11. $fileNum = 1; //TODO For furthur multiple input file
  12. for($i = 0; $i < $fileNum; $i++) {
  13. $line = "";
  14. $flg[0] = "";
  15. $flg[1] = "";
  16. $flg[2] = "";
  17. $lineNo = 0;
  18. $ret = createExpArray();
  19. $file = fopen($_FILES["FilePath"]["tmp_name"],"r") or exit("Unable to open file!");
  20. while(!feof($file)) {
  21. $lineNo++;
  22. $line = fgets($file);
  23. $flg = judgeContentType($line, $flg); // explode,splitStrToArray
  24. //echo "[line".$lineNo."],[".$flg[0]."],[".$flg[1]."],[".$flg[2]."]<br>"; //debug
  25. $ret = getSpliterResult($flg, $line, $ret);
  26. }
  27. fclose($file);
  28. $ret = checkExpId($ret, $_FILES["FilePath"]["name"]);
  29. $ret = checkCoordinate($ret);
  30. $ret["file_name"] = $_FILES["FilePath"]["name"];
  31. $files[$i] = $ret;
  32. }
  33. // Save temple Xfile data into temp table
  34. updateTempFile(json_encode($files), "X");
  35. updateTempFileExpName($files[0]["exp.details:"]["exname"]);
  36. $_SESSION["dssat_steps"] = 2;
  37. }
  38. $ret = $files[0]; // TODO will be changed when multiple file uploaded allowed
  39. // Set forward page
  40. if (isset($_POST["submitType"]) && $_POST["submitType"] == "finish") {
  41. // Get all type of files which are already be uploaded previously
  42. $fileTypes = checkUploadStatus();
  43. // Check if soil data is avaliable in DB
  44. if (!array_key_exists("S", $fileTypes) && !checkSoilAvailable($ret, $checkRet)) {
  45. if (!isset($_SESSION["dssat_steps"]) || $_SESSION["dssat_steps"] < 2) {
  46. $_SESSION["dssat_steps"] = 2;
  47. }
  48. $target = "inputFiles02.php";
  49. // Check if weather data is avaliable in DB
  50. } else if (!array_key_exists("W", $fileTypes) && !checkWthAvailable($ret, $checkRet)) {
  51. if (!isset($_SESSION["dssat_steps"]) || $_SESSION["dssat_steps"] < 3) {
  52. $_SESSION["dssat_steps"] = 3;
  53. }
  54. $target = "inputFiles03.php";
  55. } else {
  56. // All check ok, forward to confirm page
  57. if (!isset($_SESSION["dssat_steps"]) || $_SESSION["dssat_steps"] < 5) {
  58. $_SESSION["dssat_steps"] = 5;
  59. }
  60. $target = "confirmFiles.php";
  61. }
  62. } else {
  63. $fileTypes = checkUploadStatus();
  64. checkSoilAvailable($ret, $checkRet);
  65. if (!isset($_SESSION["dssat_steps"]) || $_SESSION["dssat_steps"] < 2) {
  66. $_SESSION["dssat_steps"] = 2;
  67. }
  68. $target = "inputFiles02.php";
  69. }
  70. ?>
  71. <html>
  72. <header>
  73. <script language="javascript">
  74. function autoSubmit() {
  75. var form1 = document.getElementById("form1");
  76. form1.submit();
  77. }
  78. </script>
  79. </header>
  80. <body onload="autoSubmit();">
  81. <form id="form1" method="post" action="<?php echo $target; ?>" enctype="multipart/form-data">
  82. <?php
  83. if ($target == "inputFiles02.php") {
  84. for ($i = 1; $i <= count($checkRet); $i++) {
  85. echo "<input type='hidden' id='content_status' name='content_status[]' value='" . $checkRet[$i - 1] . "' />\r\n";
  86. echo "<input type='hidden' id='content_id' name='content_id[]' value='" . $ret["fields"][$i]["slno"] . "' />\r\n";
  87. echo "<input type='hidden' id='content_id' name='content_xcrd[]' value='" . $ret["fields"][$i]["xcrd"] . "' />\r\n";
  88. echo "<input type='hidden' id='content_id' name='content_ycrd[]' value='" . $ret["fields"][$i]["ycrd"] . "' />\r\n";
  89. }
  90. if (array_key_exists("S", $fileTypes)) {
  91. for ($i = 0; $i< count($fileTypes["S"]); $i++) {
  92. echo "<input type='hidden' id='upload_file' name='upload_file[]' value='" . $fileTypes["S"][$i] . "' />\r\n";
  93. }
  94. }
  95. } else if ($target == "inputFiles03.php") {
  96. foreach ($checkRet as $wth) {
  97. echo "<input type='hidden' id='content_id' name='content_id[]' value='" . $wth["wid"] . "' />\r\n";
  98. echo "<input type='hidden' id='content_status' name='content_status[]' value='" . $wth["dbStatus"] . "' />\r\n";
  99. echo "<input type='hidden' id='content_syear' name='content_start[]' value='" . $wth["start"] . "' />\r\n";
  100. echo "<input type='hidden' id='content_status' name='content_end[]' value='" . $wth["end"] . "' />\r\n";
  101. }
  102. if (array_key_exists("W", $fileTypes)) {
  103. for ($i = 0; $i< count($fileTypes["W"]); $i++) {
  104. echo "<input type='hidden' id='upload_file' name='upload_file[]' value='" . $fileTypes["W"][$i] . "' />\r\n";
  105. }
  106. }
  107. } if ($target == "confirmFiles.php") {
  108. }
  109. ?>
  110. </form>
  111. </body>
  112. </html>