generating-plant-analysis.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. error_reporting(E_ALL);
  3. //error_reporting(E_ALL ^ E_NOTICE);
  4. ini_set('display_errors', 1);
  5. $errorLog = 1;
  6. if(isset($_POST['PlantcsvForm'])) {
  7. if ($errorLog = "1") { error_log(print_r($_POST, true), 3, "/home/cropmonitor/public_html/site/plantformSubmit-errors.log"); }
  8. $sql = null;
  9. $con = mysqli_connect("localhost", "cropmonitor", "brvnCcaEYxlPCS3", "cropmonitor");
  10. //set todays date
  11. $date = date("Y-m-d H:i:s");
  12. // ****************************************************************************
  13. // Client Details
  14. $client_id = '1'; //(isset($_POST["client_id"])) ? $_POST["client_id"] : "";
  15. $modx_id = '1'; //(isset($_POST["m_user"])) ? $_POST["m_user"] : "";
  16. $email = (isset($_POST["email"])) ? $_POST["email"] : "";
  17. $client_name = (isset($_POST["name"])) ? $_POST["name"] : "";
  18. $site_address = (isset($_POST["site_address"])) ? $_POST["site_address"] : "";
  19. $state_postcode = (isset($_POST["state_postcode"])) ? $_POST["state_postcode"] : "";
  20. // Analysis Details
  21. $analysis_type = (isset($_POST["analysis_type"])) ? $_POST["analysis_type"] : "";
  22. $lab_no = (isset($_POST["lab_no"])) ? $_POST["lab_no"] : "";
  23. $batch_no = (isset($_POST["batch_no"])) ? $_POST["batch_no"] : "";
  24. $date_sampled = (isset($_POST["date_sampled"])) ? $_POST["date_sampled"] : "";
  25. $sample_id = (isset($_POST["sample_id"])) ? $_POST["sample_id"] : "";
  26. $site_id = (isset($_POST["site_id"])) ? $_POST["site_id"] : "";
  27. $crop_type = (isset($_POST["crop_type"])) ? $_POST["crop_type"] : "";
  28. // Sample Details
  29. $n = (isset($_POST["n"])) ? $_POST["n"] : "";
  30. $p = (isset($_POST["p"])) ? $_POST["p"] : "";
  31. $k = (isset($_POST["k"])) ? $_POST["k"] : "";
  32. $s = (isset($_POST["s"])) ? $_POST["s"] : "";
  33. $mg = (isset($_POST["mg"])) ? $_POST["mg"] : "";
  34. $ca = (isset($_POST["ca"])) ? $_POST["ca"] : "";
  35. $na = (isset($_POST["na"])) ? $_POST["na"] : "";
  36. $fe = (isset($_POST["fe"])) ? $_POST["fe"] : "";
  37. $mn = (isset($_POST["mn"])) ? $_POST["mn"] : "";
  38. $zn = (isset($_POST["zn"])) ? $_POST["zn"] : "";
  39. $cu = (isset($_POST["cu"])) ? $_POST["cu"] : "";
  40. $b = (isset($_POST["b"])) ? $_POST["b"] : "";
  41. $m = (isset($_POST["m"])) ? $_POST["m"] : "";
  42. $co = (isset($_POST["co"])) ? $_POST["co"] : "";
  43. $se = (isset($_POST["se"])) ? $_POST["se"] : "";
  44. $ch = (isset($_POST["cl"])) ? $_POST["cl"] : "";
  45. //$rand = substr(md5(microtime()),rand(0,26),5);
  46. $rand = mt_rand(10000, 99999);
  47. // Check connection
  48. if (mysqli_connect_errno()){
  49. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  50. }
  51. $sql = mysqli_query($con, "INSERT into `plant_records`
  52. (
  53. client_records_id,
  54. modx_user_id,
  55. date,
  56. email,
  57. client_name,
  58. site_address,
  59. state_postcode,
  60. analysis_type,
  61. lab_no,
  62. batch_no,
  63. date_sampled,
  64. sample_id,
  65. site_id,
  66. crop_type,
  67. n,
  68. p,
  69. k,
  70. s,
  71. mg,
  72. ca,
  73. na,
  74. fe,
  75. mn,
  76. zn,
  77. cu,
  78. b,
  79. m,
  80. co,
  81. se,
  82. cl,
  83. rand
  84. ) VALUES (
  85. '{$client_id}',
  86. '{$modx_id}',
  87. '{$date}',
  88. '{$email}',
  89. '{$client_name}',
  90. '{$site_address}',
  91. '{$state_postcode}',
  92. '{$analysis_type}',
  93. '{$lab_no}',
  94. '{$batch_no}',
  95. '{$date_sampled}',
  96. '{$sample_id}',
  97. '{$site_id}',
  98. '{$crop_type}',
  99. '{$n}',
  100. '{$p}',
  101. '{$k}',
  102. '{$s}',
  103. '{$mg}',
  104. '{$ca}',
  105. '{$na}',
  106. '{$fe}',
  107. '{$mn}',
  108. '{$zn}',
  109. '{$cu}',
  110. '{$b}',
  111. '{$m}',
  112. '{$co}',
  113. '{$se}',
  114. '{$cl}',
  115. '{$rand}'
  116. )" );
  117. $insert_id = mysqli_insert_id($con);
  118. if ($sql === TRUE) {
  119. sleep(10);
  120. // forward to results page if successfully inserts to database [[~26]]
  121. echo "<script>location.href = '[[~26]]?rand=" . $rand . "&cid=" . $sample_id . "&rid=" . $insert_id . "&stid=" .$crop_type . "','_blank';</script>";
  122. } else {
  123. die(mysqli_error($con)); // TODO: better error handling
  124. //echo "User Profile incorrect";
  125. }
  126. }
  127. ?>
  128. <div id="loader-gif" style="z-index:10000;" >[[$plantPOPUP]]</div>
  129. <script>
  130. $(document).ready(function() {
  131. $("#start-loader").click(function() {
  132. $("#loader-gif").show();
  133. setTimeout(function() {
  134. $("#loader-gif").hide();
  135. }, 5000);
  136. });
  137. });
  138. </script>