Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 KB | None | 0 0
  1. <div>
  2. <div id="vendor">
  3. <strong>Vendor:</strong>
  4. </div>
  5.  
  6. <div class="align">
  7. <select name="vendor_dropdown" id="ven" onChange="updateinput();">
  8. <option value="">Choose a Vendor</option>
  9. <?php foreach($users->fetchAll() as $user): ?>
  10. <option
  11. data-name="<?php echo $user['MR_POC_N'];?>"
  12. data-email="<?php echo $user['MR_POC_E'];?>"
  13. data-phone="<?php echo $user['MR_POC_P'];?>"
  14. >
  15. <?php echo $user['MR_Name'];?>
  16. </option>
  17. <?php endforeach; ?>
  18. </select>
  19. </div>
  20.  
  21. </div>
  22.  
  23. <div>
  24. <div id="contact_info">
  25. <strong>Contact Information:</strong><br>
  26. </div>
  27.  
  28. <div class="align1">
  29. <table align="left" id="contact">
  30. <tr align="left">
  31. <th>Name</th>
  32. <th>Email</th>
  33. <th>Phone Number</th>
  34. </tr>
  35. <tr>
  36. <td><input type="text" id="name" class="name" name="name"></td>
  37. <td><input type="email" id="email" class="email" name="email"></td>
  38. <td><input type="tel" id="tel" class="tel" name="number"></td>
  39. <td><input type="button" class="edit" name="edit" value="Save"></td>
  40. </tr>
  41. </table>
  42. </div>
  43.  
  44. </div>
  45.  
  46. // ----- Edit Contact Info -----
  47.  
  48. $(document).on("click", "#contact .edit", function () {
  49. var $this = $(this);
  50. var tds = $this.closest('tr').find('td').filter(function () {
  51. return $(this).find('.edit').length === 0;
  52. });
  53. if ($this.val() === 'Edit') {
  54. /*if($this.id !== '.mr_id') {
  55. tds.not('.mr_id').not('.mr_name').prop('contenteditable', true);
  56. }*/
  57. } else {
  58. var isValid = true;
  59. var errors = '';
  60. $('#myDialogBox').empty();
  61. var elements = tds;
  62. if (tds.find('input').length > 0) {
  63. elements = tds.find('input');
  64. }
  65. var dict = {};
  66. elements.each(function (index, element) {
  67. var type = $(this).attr('class');
  68. var value = (element.tagName == 'INPUT') ? $(this).val() : $(this).text();
  69. console.log(type);
  70. // ----- Switch statement that provides validation for each table cell -----
  71. switch (type) {
  72. case "ven":
  73. dict["MR_Name"] = value;
  74. break;
  75. case "name":
  76. if (value == value.match(/^[a-zA-Zs]+$/)) {
  77. dict["MR_POC_N"] = value;
  78. break;
  79. }
  80. else {
  81. isValid = false;
  82. errors += "Please enter a valid Namen";
  83. }
  84. break;
  85. case "email":
  86. if (value == value.match(/^[w-.+]+@[a-zA-Z0-9.-]+.[a-zA-z0-9]{2,4}$/)) {
  87. dict["MR_POC_E"] = value;
  88. break;
  89. }
  90. else {
  91. isValid = false;
  92. errors += "Please enter a valid Emailn";
  93. }
  94. break;
  95. case "tel":
  96. if (value == value.match('^[0-9 ()+/-]{10,}$')) {
  97. dict["MR_POC_P"] = value;
  98. break;
  99. }
  100. else {
  101. isValid = false;
  102. errors += "Please enter a valid Phone Numbern";
  103. }
  104. break;
  105. }
  106. })
  107.  
  108. if (isValid) {
  109. console.log(dict);
  110. //$this.val('Save');
  111. //tds.prop('contenteditable', false);
  112. var request = $.ajax({
  113. type: "POST",
  114. url: "update.php",
  115. data: dict
  116. });
  117.  
  118. request.done(function (response, textStatus, jqXHR){
  119. if(JSON.parse(response) == true){
  120. console.log("Data saved");
  121. } else {
  122. console.log("Data failed to save");
  123. console.log(response);
  124. console.log(textStatus);
  125. console.log(jqXHR);
  126. }
  127. });
  128.  
  129. // Callback handler that will be called on failure
  130. request.fail(function (jqXHR, textStatus, errorThrown){
  131. // Log the error to the console
  132. console.log(textStatus);
  133. console.log(jqXHR);
  134. console.error(
  135. "The following error occurred: "+
  136. textStatus, errorThrown
  137. );
  138. });
  139.  
  140. // Callback handler that will be called regardless
  141. // if the request failed or succeeded
  142. request.always(function () {
  143.  
  144. });
  145. } else {
  146. alert(errors);
  147. }
  148. }
  149. });
  150.  
  151. <?php
  152.  
  153. $MR_Name = $_POST['MR_Name'];
  154. $MR_POC_N = $_POST['MR_POC_N'];
  155. $MR_POC_E = $_POST['MR_POC_E'];
  156. $MR_POC_P = $_POST['MR_POC_P'];
  157.  
  158. $host="xxxxxxx";
  159. $dbName="xxxxxxxxx";
  160. $dbUser="xxxx";
  161. $dbPass="xxxxxxxx";
  162.  
  163. $pdo = new PDO("sqlsrv:server=".$host.";Database=".$dbName, $dbUser, $dbPass);
  164.  
  165. $sql = "UPDATE Stage_Rebate_Master SET MR_POC_N = :MR_POC_N, MR_POC_E = :MR_POC_E, MR_POC_P = :MR_POC_P WHERE MR_Name = :MR_Name";
  166.  
  167. $stmt = $pdo->prepare($sql);
  168. $stmt->bindValue(':MR_Name', $MR_Name);
  169. $stmt->bindValue(':MR_POC_N', $MR_POC_N);
  170. $stmt->bindValue(':MR_POC_E', $MR_POC_E);
  171. $stmt->bindValue(':MR_POC_P', $MR_POC_P);
  172. $result = $stmt->execute();
  173. echo json_encode($result);
  174.  
  175. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement