post.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. //$modx_user = $modx->user->get('id');
  3. $modx_user = 1;
  4. $con = mysqli_connect("localhost", "cropmonitor", "brvnCcaEYxlPCS3", "cropmonitor");
  5. // Check connection
  6. if (mysqli_connect_errno()) {
  7. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  8. }
  9. $result = mysqli_query($con, "SELECT * FROM `client_records` Where `modx_user_id` = $modx_user ");
  10. // mysqli_query returns false if something went wrong with the query
  11. if ($result === FALSE) {
  12. die(mysqli_error($con)); // TODO: better error handling
  13. } else {
  14. ?>
  15. <div class='col-md-12 form-group'>
  16. <label for='client_id'>Current Client</label><?php
  17. //$modx_user = $modx->user->get('id');
  18. $modx_user = 1;
  19. $result = mysqli_query($con, "SELECT * FROM `client_records` Where `modx_user_id` = $modx_user ");
  20. // mysqli_query returns false if something went wrong with the query
  21. if ($result === FALSE) {
  22. die(mysqli_error($con)); // TODO: better error handling
  23. } else {
  24. ?>
  25. <div class='col-md-12 form-group'>
  26. <label for='client_id'>Current Client</label>
  27. <div><select name='client_id' id='client_id' class='form-control1' onChange='Choice();'>
  28. <option>Select current client or add new client below...</option>
  29. <?php
  30. while ($row=mysqli_fetch_array($result)){
  31. ?>
  32. <option value="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>"><?php echo $row['id'] . " - " . $row['client'] . " - " . $row['company']; ?></option>
  33. <?php
  34. }
  35. ?>
  36. </select></div>
  37. </div>
  38. <?php
  39. }
  40. ?>
  41. <script type="text/javascript">
  42. <?php
  43. $index = 0;
  44. while ($row = mysqli_fetch_array($result))
  45. {
  46. ?>
  47. var email[<?php echo $index; ?>] = <?php echo $row['email']; ?>;
  48. var name[<?php echo $index; ?>] = <?php echo $row['name']; ?>;
  49. var company[<?php echo $index; ?>] = <?php echo $row['company']; ?>;
  50. var site_address[<?php echo $index; ?>] = <?php echo $row['site_address']; ?>;
  51. var state_postcode[<?php echo $index; ?>] = <?php echo $row['state_postcode']; ?>;
  52. <?php
  53. $index++;
  54. }
  55. ?>
  56. </script>
  57. <?php
  58. mysqli_close($con);
  59. ?>
  60. <script type="text/javascript">
  61. function Choice() {
  62. y = document.getElementById("client_id");
  63. document.getElementById("email").value = email[y.selectedIndex];
  64. document.getElementById("name").value = name[y.selectedIndex];
  65. document.getElementById("company").value = company[y.selectedIndex];
  66. document.getElementById("site_address").value = site_address[y.selectedIndex];
  67. document.getElementById("state_postcode").value = state_postcode[y.selectedIndex];
  68. }
  69. </script>
  70. <div class="col-md-6 form-group">
  71. <label for="email">Email address<span class="error">*</span></label>
  72. <input type="email" class="form-control" name="email" id="email" value="" required autocomplete="on">
  73. </div>
  74. <div class="col-md-6 form-group">
  75. <label for="client_name">Client Name<span class="error">*</span></label>
  76. <input type="text" class="form-control" name="name" id="name" value="" required autocomplete="on">
  77. </div>
  78. <div class="col-md-6 form-group">
  79. <label for="company_name">Company Name</label>
  80. <input type="text" class="form-control" name="company" id="company" value="" autocomplete="on">
  81. </div>
  82. <div class="col-md-6 form-group">
  83. <label for="site_address">Site Address</label>
  84. <input type="text" class="form-control" name="site_address" id="site_address" value="" autocomplete="on">
  85. </div>
  86. <div class="col-md-6 form-group">
  87. <label for="state_postcode">State & Postcode</label>
  88. <input type="text" class="form-control" name="state_postcode" id="state_postcode" value="" autocomplete="on">
  89. </div>
  90. <div><select name='client_id' id='client_id' class='form-control1' onChange='Choice();'>
  91. <option>Select current client or add new client below...</option>
  92. <?php
  93. while ($row=mysqli_fetch_array($result)){
  94. ?>
  95. <option value="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>"><?php echo $row['id'] . " - " . $row['client'] . " - " . $row['company']; ?></option>
  96. <?php
  97. }
  98. ?>
  99. </select></div>
  100. </div>
  101. <?php
  102. }
  103. ?>
  104. <script type="text/javascript">
  105. <?php
  106. $index = 0;
  107. while ($row = mysqli_fetch_array($result))
  108. {
  109. ?>
  110. var email[<?php echo $index; ?>] = <?php echo $row['email']; ?>;
  111. var name[<?php echo $index; ?>] = <?php echo $row['name']; ?>;
  112. var company[<?php echo $index; ?>] = <?php echo $row['company']; ?>;
  113. var site_address[<?php echo $index; ?>] = <?php echo $row['site_address']; ?>;
  114. var state_postcode[<?php echo $index; ?>] = <?php echo $row['state_postcode']; ?>;
  115. <?php
  116. $index++;
  117. }
  118. ?>
  119. </script>
  120. <?php
  121. mysqli_close($con);
  122. ?>
  123. <script type="text/javascript">
  124. function Choice() {
  125. y = document.getElementById("client_id");
  126. document.getElementById("email").value = email[y.selectedIndex];
  127. document.getElementById("name").value = name[y.selectedIndex];
  128. document.getElementById("company").value = company[y.selectedIndex];
  129. document.getElementById("site_address").value = site_address[y.selectedIndex];
  130. document.getElementById("state_postcode").value = state_postcode[y.selectedIndex];
  131. }
  132. </script>
  133. <div class="col-md-6 form-group">
  134. <label for="email">Email address<span class="error">*</span></label>
  135. <input type="email" class="form-control" name="email" id="email" value="" required autocomplete="on">
  136. </div>
  137. <div class="col-md-6 form-group">
  138. <label for="client_name">Client Name<span class="error">*</span></label>
  139. <input type="text" class="form-control" name="name" id="name" value="" required autocomplete="on">
  140. </div>
  141. <div class="col-md-6 form-group">
  142. <label for="company_name">Company Name</label>
  143. <input type="text" class="form-control" name="company" id="company" value="" autocomplete="on">
  144. </div>
  145. <div class="col-md-6 form-group">
  146. <label for="site_address">Site Address</label>
  147. <input type="text" class="form-control" name="site_address" id="site_address" value="" autocomplete="on">
  148. </div>
  149. <div class="col-md-6 form-group">
  150. <label for="state_postcode">State & Postcode</label>
  151. <input type="text" class="form-control" name="state_postcode" id="state_postcode" value="" autocomplete="on">
  152. </div>