| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- error_reporting(E_ALL);
- //error_reporting(E_ALL ^ E_NOTICE);
- ini_set('display_errors', 1);
- $errorLog = 1;
- if(isset($_POST['PlantcsvForm'])) {
-
- if ($errorLog = "1") { error_log(print_r($_POST, true), 3, "/home/cropmonitor/public_html/site/plantformSubmit-errors.log"); }
-
- $sql = null;
- $con = mysqli_connect("localhost", "cropmonitor", "brvnCcaEYxlPCS3", "cropmonitor");
-
- //set todays date
- $date = date("Y-m-d H:i:s");
-
- // ****************************************************************************
- // Client Details
- $client_id = '1'; //(isset($_POST["client_id"])) ? $_POST["client_id"] : "";
- $modx_id = '1'; //(isset($_POST["m_user"])) ? $_POST["m_user"] : "";
- $email = (isset($_POST["email"])) ? $_POST["email"] : "";
- $client_name = (isset($_POST["name"])) ? $_POST["name"] : "";
- $site_address = (isset($_POST["site_address"])) ? $_POST["site_address"] : "";
- $state_postcode = (isset($_POST["state_postcode"])) ? $_POST["state_postcode"] : "";
- // Analysis Details
- $analysis_type = (isset($_POST["analysis_type"])) ? $_POST["analysis_type"] : "";
- $lab_no = (isset($_POST["lab_no"])) ? $_POST["lab_no"] : "";
- $batch_no = (isset($_POST["batch_no"])) ? $_POST["batch_no"] : "";
- $date_sampled = (isset($_POST["date_sampled"])) ? $_POST["date_sampled"] : "";
- $sample_id = (isset($_POST["sample_id"])) ? $_POST["sample_id"] : "";
- $site_id = (isset($_POST["site_id"])) ? $_POST["site_id"] : "";
- $crop_type = (isset($_POST["crop_type"])) ? $_POST["crop_type"] : "";
-
- // Sample Details
- $n = (isset($_POST["n"])) ? $_POST["n"] : "";
- $p = (isset($_POST["p"])) ? $_POST["p"] : "";
- $k = (isset($_POST["k"])) ? $_POST["k"] : "";
- $s = (isset($_POST["s"])) ? $_POST["s"] : "";
- $mg = (isset($_POST["mg"])) ? $_POST["mg"] : "";
- $ca = (isset($_POST["ca"])) ? $_POST["ca"] : "";
- $na = (isset($_POST["na"])) ? $_POST["na"] : "";
- $fe = (isset($_POST["fe"])) ? $_POST["fe"] : "";
- $mn = (isset($_POST["mn"])) ? $_POST["mn"] : "";
- $zn = (isset($_POST["zn"])) ? $_POST["zn"] : "";
- $cu = (isset($_POST["cu"])) ? $_POST["cu"] : "";
- $b = (isset($_POST["b"])) ? $_POST["b"] : "";
- $m = (isset($_POST["m"])) ? $_POST["m"] : "";
- $co = (isset($_POST["co"])) ? $_POST["co"] : "";
- $se = (isset($_POST["se"])) ? $_POST["se"] : "";
- $ch = (isset($_POST["cl"])) ? $_POST["cl"] : "";
-
- //$rand = substr(md5(microtime()),rand(0,26),5);
- $rand = mt_rand(10000, 99999);
-
- // Check connection
- if (mysqli_connect_errno()){
- echo "Failed to connect to MySQL: " . mysqli_connect_error();
- }
-
- $sql = mysqli_query($con, "INSERT into `plant_records`
- (
- client_records_id,
- modx_user_id,
- date,
- email,
- client_name,
- site_address,
- state_postcode,
- analysis_type,
- lab_no,
- batch_no,
- date_sampled,
- sample_id,
- site_id,
- crop_type,
- n,
- p,
- k,
- s,
- mg,
- ca,
- na,
- fe,
- mn,
- zn,
- cu,
- b,
- m,
- co,
- se,
- cl,
- rand
- ) VALUES (
- '{$client_id}',
- '{$modx_id}',
- '{$date}',
- '{$email}',
- '{$client_name}',
- '{$site_address}',
- '{$state_postcode}',
- '{$analysis_type}',
- '{$lab_no}',
- '{$batch_no}',
- '{$date_sampled}',
- '{$sample_id}',
- '{$site_id}',
- '{$crop_type}',
- '{$n}',
- '{$p}',
- '{$k}',
- '{$s}',
- '{$mg}',
- '{$ca}',
- '{$na}',
- '{$fe}',
- '{$mn}',
- '{$zn}',
- '{$cu}',
- '{$b}',
- '{$m}',
- '{$co}',
- '{$se}',
- '{$cl}',
- '{$rand}'
- )" );
-
- $insert_id = mysqli_insert_id($con);
-
- if ($sql === TRUE) {
- sleep(10);
- // forward to results page if successfully inserts to database [[~26]]
- echo "<script>location.href = '[[~26]]?rand=" . $rand . "&cid=" . $sample_id . "&rid=" . $insert_id . "&stid=" .$crop_type . "','_blank';</script>";
- } else {
- die(mysqli_error($con)); // TODO: better error handling
- //echo "User Profile incorrect";
- }
- }
- ?>
- <div id="loader-gif" style="z-index:10000;" >[[$plantPOPUP]]</div>
- <script>
- $(document).ready(function() {
- $("#start-loader").click(function() {
- $("#loader-gif").show();
- setTimeout(function() {
- $("#loader-gif").hide();
- }, 5000);
- });
- });
- </script>
|