home *** CD-ROM | disk | FTP | other *** search
/ 207.233.110.77 / 207.233.110.77.tar / 207.233.110.77 / vbasic / ProcessAdminEdits.asp < prev    next >
Text File  |  2003-09-18  |  9KB  |  201 lines

  1. <%@ LANGUAGE="VBSCRIPT" %>
  2. <% Option Explicit %>
  3. <!-- METADATA 
  4.    TYPE="TypeLib" 
  5.    FILE="C:\Program Files\Common Files\System\ADO\msado21.tlb" 
  6. -->
  7. <!--#include file="DatabaseConnect.asp"-->
  8. <%    If Session("ValidatedAdministrator") <> True Then
  9.         Response.Redirect "error.asp?error=denied"
  10.     End If %>
  11. <html>
  12. <head>
  13. <title>Admin Edit Record Processing</title>
  14. </head>
  15. <body>
  16. <%
  17.     Dim objRS
  18.     Dim objRSstudents
  19.     Dim objRSTeacher
  20.     Dim objStudent
  21.     Dim sSQL
  22.     Dim strTmp
  23.     Dim strEmail
  24.     Dim strName
  25.     Dim bNewPassword
  26.     Dim Mailer
  27.     Dim i
  28.     
  29.     bNewPassword = False
  30.      Select Case LCase(Trim(Request.Form("action")))
  31.       Case "save edits"
  32.       If Trim(Request.Form("Last")) = "" Or Trim(Request.Form("First")) = "" Then
  33.         Response.Write ("<B>You must specify a First and Last name! Changes NOT saved.</B><BR>")
  34.         bNewPassword = 99        'Use this flag to skip the default message at the end
  35.       Else
  36.         strTmp = Request.QueryString("email") 
  37.         sSQL = "SELECT * FROM Students WHERE email = '" & strTmp & "';"
  38.         Set objRS = Server.CreateObject("ADODB.Recordset")
  39.         objRS.Open sSQL, objConn, adOpenDynamic, adLockOptimistic, adCmdText
  40.         'Don't try processing if record doesn't exist
  41.         If Not (objRS.EOF And objRS.BOF) Then 
  42.           'Special processing for a Teacher's account
  43.           If objRS("security") = vbTeacher Then
  44.             'If a Teacher changes their email address, all the 'TeacherEmail'
  45.             '        fields from their Student's accounts must be updated.
  46.             If objRS("email") <> Trim(Request.Form("email")) Then
  47.               objRS("email") = Trim(Request.Form("email"))
  48.               sSQL = "SELECT * FROM Students WHERE Teacher = '" & objRS("name") & "';"
  49.               Set objRSstudents = Server.CreateObject("ADODB.Recordset")
  50.               objRSstudents.Open sSQL, objConn, adOpenDynamic, adLockOptimistic, adCmdText
  51.               objRSstudents.MoveFirst
  52.               'If this Teacher has no students, don't do anything
  53.               If Not (objRSstudents.EOF And objRSstudents.BOF) Then 
  54.                 'Update the TeacherEmail field of all the Teacher's students
  55.                 Do While Not objRSstudents.EOF
  56.                   objRSstudents("teacheremail") = Trim(Request.Form("email"))
  57.                   objRSstudents.MoveNext
  58.                 Loop
  59.                 objRSstudents.MoveFirst
  60.                 objRSstudents.Update
  61.                 objRSstudents.Close
  62.               End If
  63.             Set objRSstudents = Nothing
  64.             End If
  65.             strName = objRS("name")
  66.             'Process these fields for Student accounts only 
  67.             '   Don't let Teacher accounts change their names
  68.           Else    
  69.             objRS("name") = Request.Form("Last") & ", " & Request.Form("First")
  70.             strName = Request.Form("First") & " " & Request.Form("Last")
  71.           End If
  72.           objRS("email") = Trim(Request.Form("email"))
  73.           'If the password changes, email the student with the new password info
  74.           If objRS("password") <> Request.Form("password") Then
  75.             objRS("password") = Request.Form("password")
  76.             strEmail = objRS("email")
  77.             bNewPassword = True
  78.             Set Mailer = Server.CreateObject("SoftArtisans.SMTPMail")
  79.             Mailer.FromName = "Guy Campbell"
  80.             Mailer.FromAddress = "campbell_guy@hotmail.com"
  81.             Mailer.organization = "Visual Basic - Moorpark College"
  82.             Mailer.Subject = "Moorpark College -- Visual Basic Account Modification"
  83.             Mailer.smtplog = "C:\mysmtplog.txt"
  84.             Mailer.live = True
  85.             Mailer.RemoteHost = "sunny.moorpark.cc.ca.us"
  86.             Mailer.Priority = 3        
  87.             Mailer.addrecipient strName, objRS("email")
  88.             Mailer.bodytext = "Your Visual Basic Account Password has been changed. " & vbCRLF _
  89.             & vbCRLF _
  90.             & "Name: " & objRS("name") & vbCRLF _
  91.             & "eMail: " & objRS("email") & vbCRLF _
  92.             & "New Password: " & objRS("password") & vbCRLF & vbCRLF _
  93.             & "Important:  All information is case sensitive." & vbCRLF & vbCRLF _
  94.             & "http://cislab.moorpark.cc.ca.us/vbasic" & vbCRLF & vbCRLF _                
  95.             & "Thank You, " & vbCRLF & vbCRLF & "Guy Campbell" & vbCRLF & "gcampbell@moorparkcollege.edu"
  96.             Mailer.SendMail                        
  97.             Mailer.ClearRecipients
  98.           Else
  99.             bNewPassword = False
  100.           End If
  101.           'These fields for Students only
  102.           If objRS("security") = vbStudent Then
  103.             objRS("classtype") = Request.Form("cis40or41")
  104.             objRS("meetday") = Request.Form("meetday")
  105.             objRS("modified") = CStr(Date)
  106.             'If the Teacher changes be sure to update the TeacherEmail field
  107.             If Request.Form("teacher") <> objRS("teacher") Then
  108.               sSQL = "SELECT * FROM Students WHERE Name = '" & Request.Form("teacher") & "';"
  109.               Set objRSTeacher = Server.CreateObject("ADODB.Recordset")
  110.               objRSTeacher.Open sSQL, objConn, adOpenDynamic, adLockOptimistic, adCmdText
  111.               objRSTeacher.MoveFirst
  112.               'If this Teacher doesn't exist, don't do anything
  113.               If Not (objRSTeacher.EOF And objRSTeacher.BOF) Then 
  114.                 'Update the TeacherEmail field of the Teacher
  115.                 objRS("teacheremail") = objRSTeacher("email")
  116.                 objRS("teacher") = Request.Form("teacher")
  117.                 objRSTeacher.Close
  118.                 Set objRSTeacher = Nothing
  119.               End If
  120.             End If
  121.             If IsNumeric(Trim(Request.Form("score1"))) Then
  122.               objRS("score1") = CInt(Trim(Request.Form("score1")))
  123.             Else
  124.               objRS("score1") = "0"
  125.             End If
  126.             If IsNumeric(Trim(Request.Form("score2"))) Then
  127.               objRS("score2") = CInt(Trim(Request.Form("score2")))
  128.             Else
  129.               objRS("score2") = "0"
  130.             End If
  131.             If IsNumeric(Trim(Request.Form("score3"))) Then
  132.               objRS("score3") = CInt(Trim(Request.Form("score3")))
  133.             Else
  134.               objRS("score3") = "0"
  135.             End If
  136.             If IsNumeric(Trim(Request.Form("score4"))) Then
  137.               objRS("score4") = CInt(Trim(Request.Form("score4")))
  138.             Else
  139.               objRS("score4") = "0"
  140.             End If
  141.             If IsNumeric(Trim(Request.Form("score5"))) Then
  142.               objRS("score5") = CInt(Trim(Request.Form("score5")))
  143.             Else
  144.               objRS("score5") = "0"
  145.             End If
  146.             If IsNumeric(Trim(Request.Form("score6"))) Then
  147.               objRS("score6") = CInt(Trim(Request.Form("score6")))
  148.             Else
  149.               objRS("score6") = "0"
  150.             End If
  151.             If IsNumeric(Trim(Request.Form("score7"))) Then
  152.               objRS("score7") = CInt(Trim(Request.Form("score7")))
  153.             Else
  154.               objRS("score7") = "0"
  155.             End If
  156.             If IsNumeric(Trim(Request.Form("score8"))) Then
  157.               objRS("score8") = CInt(Trim(Request.Form("score8")))
  158.             Else
  159.               objRS("score8") = "0"
  160.             End If
  161.             If IsNumeric(Trim(Request.Form("score9"))) Then
  162.               objRS("score9") = CInt(Trim(Request.Form("score9")))
  163.             Else
  164.               objRS("score9") = "0"
  165.             End If
  166.             If IsNumeric(Trim(Request.Form("score10"))) Then
  167.               objRS("score10") = CInt(Trim(Request.Form("score10")))
  168.             Else
  169.               objRS("score10") = "0"
  170.             End If
  171.             If IsNumeric(Trim(Request.Form("score11"))) Then
  172.               objRS("score11") = CInt(Trim(Request.Form("score11")))
  173.             Else
  174.               objRS("score11") = "0"
  175.             End If
  176.             If IsNumeric(Trim(Request.Form("score12"))) Then
  177.               objRS("score12") = CInt(Trim(Request.Form("score12")))
  178.             Else
  179.               objRS("score12") = "0"
  180.             End If
  181.           End If
  182.           objRS.Update
  183.           objRS.Close
  184.           Set objRS = Nothing
  185.         End If
  186.       End If
  187.       Case Else   'Cancel the edit
  188.           Response.Redirect "admin.asp"
  189.     End Select
  190.     If bNewPassword = True Then
  191.         Response.Write ("<B>An email has been sent to " & strName & " at " & strEmail & "<BR>informing them that their password has been changed.</B><BR>")
  192.     ElseIf bNewPassword = False Then
  193.         Response.Write ("<B>Edits to account " & strName & " saved.</B><BR>")
  194.     End If
  195.     %>
  196.     <BR><INPUT TYPE="Button" ALIGN="left" VALUE="Continue" onClick="document.location='admin.asp';"> 
  197.     <%
  198. %>
  199. </body>
  200. </html>
  201.