| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- //$modx_user = $modx->user->get('id');
- $modx_user = 1;
- $con = mysqli_connect("localhost", "cropmonitor", "brvnCcaEYxlPCS3", "cropmonitor");
- // Check connection
- if (mysqli_connect_errno()) {
- echo "Failed to connect to MySQL: " . mysqli_connect_error();
- }
- $result = mysqli_query($con, "SELECT * FROM `client_records` Where `modx_user_id` = $modx_user ");
- // mysqli_query returns false if something went wrong with the query
- if ($result === FALSE) {
- die(mysqli_error($con)); // TODO: better error handling
- } else {
- ?>
- <div class='col-md-12 form-group'>
- <label for='client_id'>Current Client</label><?php
- //$modx_user = $modx->user->get('id');
- $modx_user = 1;
- $result = mysqli_query($con, "SELECT * FROM `client_records` Where `modx_user_id` = $modx_user ");
- // mysqli_query returns false if something went wrong with the query
- if ($result === FALSE) {
- die(mysqli_error($con)); // TODO: better error handling
- } else {
- ?>
- <div class='col-md-12 form-group'>
- <label for='client_id'>Current Client</label>
- <div><select name='client_id' id='client_id' class='form-control1' onChange='Choice();'>
- <option>Select current client or add new client below...</option>
- <?php
- while ($row=mysqli_fetch_array($result)){
- ?>
- <option value="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>"><?php echo $row['id'] . " - " . $row['client'] . " - " . $row['company']; ?></option>
- <?php
- }
- ?>
- </select></div>
- </div>
- <?php
- }
- ?>
- <script type="text/javascript">
- <?php
- $index = 0;
- while ($row = mysqli_fetch_array($result))
- {
- ?>
- var email[<?php echo $index; ?>] = <?php echo $row['email']; ?>;
- var name[<?php echo $index; ?>] = <?php echo $row['name']; ?>;
- var company[<?php echo $index; ?>] = <?php echo $row['company']; ?>;
- var site_address[<?php echo $index; ?>] = <?php echo $row['site_address']; ?>;
- var state_postcode[<?php echo $index; ?>] = <?php echo $row['state_postcode']; ?>;
- <?php
- $index++;
- }
- ?>
- </script>
- <?php
- mysqli_close($con);
- ?>
- <script type="text/javascript">
- function Choice() {
- y = document.getElementById("client_id");
- document.getElementById("email").value = email[y.selectedIndex];
- document.getElementById("name").value = name[y.selectedIndex];
- document.getElementById("company").value = company[y.selectedIndex];
- document.getElementById("site_address").value = site_address[y.selectedIndex];
- document.getElementById("state_postcode").value = state_postcode[y.selectedIndex];
- }
- </script>
- <div class="col-md-6 form-group">
- <label for="email">Email address<span class="error">*</span></label>
- <input type="email" class="form-control" name="email" id="email" value="" required autocomplete="on">
- </div>
- <div class="col-md-6 form-group">
- <label for="client_name">Client Name<span class="error">*</span></label>
- <input type="text" class="form-control" name="name" id="name" value="" required autocomplete="on">
- </div>
- <div class="col-md-6 form-group">
- <label for="company_name">Company Name</label>
- <input type="text" class="form-control" name="company" id="company" value="" autocomplete="on">
- </div>
- <div class="col-md-6 form-group">
- <label for="site_address">Site Address</label>
- <input type="text" class="form-control" name="site_address" id="site_address" value="" autocomplete="on">
- </div>
- <div class="col-md-6 form-group">
- <label for="state_postcode">State & Postcode</label>
- <input type="text" class="form-control" name="state_postcode" id="state_postcode" value="" autocomplete="on">
- </div>
- <div><select name='client_id' id='client_id' class='form-control1' onChange='Choice();'>
- <option>Select current client or add new client below...</option>
- <?php
- while ($row=mysqli_fetch_array($result)){
- ?>
- <option value="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>"><?php echo $row['id'] . " - " . $row['client'] . " - " . $row['company']; ?></option>
- <?php
- }
- ?>
- </select></div>
- </div>
- <?php
- }
- ?>
- <script type="text/javascript">
- <?php
- $index = 0;
- while ($row = mysqli_fetch_array($result))
- {
- ?>
- var email[<?php echo $index; ?>] = <?php echo $row['email']; ?>;
- var name[<?php echo $index; ?>] = <?php echo $row['name']; ?>;
- var company[<?php echo $index; ?>] = <?php echo $row['company']; ?>;
- var site_address[<?php echo $index; ?>] = <?php echo $row['site_address']; ?>;
- var state_postcode[<?php echo $index; ?>] = <?php echo $row['state_postcode']; ?>;
- <?php
- $index++;
- }
- ?>
- </script>
- <?php
- mysqli_close($con);
- ?>
- <script type="text/javascript">
- function Choice() {
- y = document.getElementById("client_id");
- document.getElementById("email").value = email[y.selectedIndex];
- document.getElementById("name").value = name[y.selectedIndex];
- document.getElementById("company").value = company[y.selectedIndex];
- document.getElementById("site_address").value = site_address[y.selectedIndex];
- document.getElementById("state_postcode").value = state_postcode[y.selectedIndex];
- }
- </script>
- <div class="col-md-6 form-group">
- <label for="email">Email address<span class="error">*</span></label>
- <input type="email" class="form-control" name="email" id="email" value="" required autocomplete="on">
- </div>
- <div class="col-md-6 form-group">
- <label for="client_name">Client Name<span class="error">*</span></label>
- <input type="text" class="form-control" name="name" id="name" value="" required autocomplete="on">
- </div>
- <div class="col-md-6 form-group">
- <label for="company_name">Company Name</label>
- <input type="text" class="form-control" name="company" id="company" value="" autocomplete="on">
- </div>
- <div class="col-md-6 form-group">
- <label for="site_address">Site Address</label>
- <input type="text" class="form-control" name="site_address" id="site_address" value="" autocomplete="on">
- </div>
- <div class="col-md-6 form-group">
- <label for="state_postcode">State & Postcode</label>
- <input type="text" class="form-control" name="state_postcode" id="state_postcode" value="" autocomplete="on">
- </div>
|