/secure/admin/displayDonationReasons.asp

https://github.com/barrynovak5/SWOGC · ASP · 214 lines · 175 code · 37 blank · 2 comment · 4 complexity · cbc579e5c041566b74a6d520be0bb8a8 MD5 · raw file

  1. <html>
  2. <head title="Donation Reasons">
  3. <script type="text/javascript">
  4. function GetEditForm()
  5. {
  6. var existingReasonsForm = document.getElementById("existingReasonsForm");
  7. return existingReasonsForm;
  8. }
  9. function SetBasicFormParameters(action, id, theForm)
  10. {
  11. theForm.DonationReasonId.value = id;
  12. theForm.DonationReasonAction.value = action;
  13. }
  14. function UpdateDonation(donationId)
  15. {
  16. var theForm = GetEditForm();
  17. SetBasicFormParameters("U", donationId, theForm);
  18. var donationReasonText = document.getElementById("Reason" + donationId);
  19. theForm.DonationReasonValue.value = donationReasonText.value;
  20. theForm.submit();
  21. }
  22. function DeleteDonation(donationId)
  23. {
  24. var theForm = GetEditForm();
  25. SetBasicFormParameters("D", donationId, theForm);
  26. theForm.submit();
  27. }
  28. function ValidateAddReason(theForm)
  29. {
  30. if (!theForm.DonationReasonValue.value.length)
  31. {
  32. alert("Please enter a donation reason to add");
  33. return (false);
  34. }
  35. return true;
  36. }
  37. </script>
  38. </head>
  39. <body>
  40. <!--#INCLUDE FILE="adminheader.asp"-->
  41. <%
  42. successMessage = ""
  43. DonationReasonAction = Request.Form("DonationReasonAction")
  44. DonationReasonID = Request.Form("DonationReasonId")
  45. DonationReasonValue = Request.Form("DonationReasonValue")
  46. set conn=Server.CreateObject("ADODB.Connection")
  47. Sub AddDonationReason
  48. conn.Open "FourC"
  49. sql="INSERT INTO DONATIONREASONS (LISTVALUE)"
  50. sql=sql & " VALUES "
  51. sql=sql & "('" & DonationReasonValue & "')"
  52. conn.Execute sql,recaffected
  53. if err<>0 then
  54. Response.Write(sql)
  55. Response.Write("Error " & err.Description)
  56. end if
  57. conn.close
  58. successMessage = "Donation added successfully"
  59. End Sub
  60. Sub UpdateDonationReason
  61. conn.Open "FourC"
  62. sql="UPDATE DONATIONREASONS SET LISTVALUE = '" & DonationReasonValue
  63. sql = sql & "' WHERE ID =" & DonationReasonID
  64. on error resume next
  65. conn.Execute sql,recaffected
  66. if err<>0 then
  67. Response.Write(sql)
  68. Response.Write("Error " & err.Description)
  69. end if
  70. conn.close
  71. successMessage = "Donation Updated Successfully"
  72. End Sub
  73. Sub DeleteDonationReason
  74. conn.Open "FourC"
  75. sql="UPDATE DONATIONREASONS SET ACTIVE = 0"
  76. sql = sql & " WHERE ID =" & DonationReasonID
  77. on error resume next
  78. conn.Execute sql,recaffected
  79. if err<>0 then
  80. Response.Write(sql)
  81. Response.Write("Error " & err.Description)
  82. end if
  83. conn.close
  84. successMessage = "Donation Deleted Successfully"
  85. End Sub
  86. 'Process the donation reasons depending on the action specified.
  87. 'D=Delete U=Update A=Add
  88. Select Case DonationReasonAction
  89. Case "A"
  90. Call AddDonationReason
  91. Case "U"
  92. Call UpdateDonationReason
  93. Case "D"
  94. Call DeleteDonationReason
  95. End Select
  96. conn.Open "FourC"
  97. set rs=Server.CreateObject("ADODB.recordset")
  98. sql="SELECT ID, LISTVALUE FROM DONATIONREASONS WHERE ACTIVE = 1 ORDER BY LISTVALUE ASC"
  99. rs.Open sql, conn
  100. %>
  101. <table>
  102. <tr>
  103. <td>
  104. <h4><%=successMessage%></h4>
  105. </td>
  106. </tr>
  107. <tr>
  108. <td>
  109. <h3>
  110. Donation Reasons</h3>
  111. </td>
  112. </tr>
  113. <tr>
  114. <td>
  115. <form name="AddDonationReasonForm" method="post" language="javascript" onsubmit="return ValidateAddReason(this)" action="displayDonationReasons.asp">
  116. <input value="A" name="DonationReasonAction" type="hidden" />
  117. <table>
  118. <tr>
  119. <td>
  120. Add new donation reason&nbsp;&nbsp;
  121. </td>
  122. <td>
  123. <input id="newDonationReasonValue" name="DonationReasonValue" type="text" style="width: 408px" />
  124. </td>
  125. <td>
  126. &nbsp;&nbsp;
  127. <input type="submit" value="Add" />
  128. </td>
  129. </tr>
  130. </table>
  131. </form>
  132. </td>
  133. </tr>
  134. <tr>
  135. <td>
  136. <form id="existingReasonsForm" method="post" language="javascript" name="ExistingReasonsForm" action ="displayDonationReasons.asp">
  137. <input value="U" name="DonationReasonAction" type="hidden" />
  138. <input name="DonationReasonValue" type="hidden" />
  139. <input name="DonationReasonId" type="hidden" />
  140. </form>
  141. <table border="1" width="700px">
  142. <tr>
  143. <td>
  144. Id
  145. </td>
  146. <td>
  147. Donation Reason Name
  148. </td>
  149. <td></td>
  150. <td></td>
  151. </tr>
  152. <%do until rs.EOF%>
  153. <tr>
  154. <td>
  155. <%= rs.Fields.Item("ID") %>
  156. </td>
  157. <td>
  158. <input id="<%="Reason" & rs.Fields.Item("ID")%>" value="<%= rs.Fields.Item("LISTVALUE") %>" type="text"
  159. style="width: 515px" />
  160. </td>
  161. <td>
  162. <input value="Update" type="button" onclick="UpdateDonation(<%= rs.Fields.Item("ID") %>)"/>
  163. </td>
  164. <td>
  165. <input value="Delete" type="button" onclick="DeleteDonation(<%= rs.Fields.Item("ID") %>)"/>
  166. </td>
  167. </tr>
  168. <%rs.MoveNext%>
  169. <%loop
  170. rs.close
  171. conn.close%>
  172. </table>
  173. </td>
  174. </tr>
  175. </table>
  176. </body>
  177. </html>