• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Week: 3 At a Glance > Day 16—Message Reading (message.asp)

Day 16—Message Reading (message.asp)

When reading a bulletin board message, a user has the option to delete it by entering a password and clicking Delete. To properly construct the delete command, the UltraDev behaviors needed to be edited. This is the source code for the message display page:

<%@LANGUAGE="VBSCRIPT"%> <!--#include file="../Connections/connChapter16.asp" -->
<%
' *** Edit Operations: declare variables

MM_editAction = CStr(Request("URL"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%> <%
' *** Delete Record: declare variables

if (CStr(Request("MM_delete")) <> "" And CStr(Request("MM_recordId")) <> "")
Then

  MM_editConnection = MM_connChapter16_STRING
  MM_editTable = "message"
  MM_editColumn = "ID"
  MM_recordId = "" + Request.Form("MM_recordId") + ""
  MM_editRedirectUrl = "index.asp"

  ' set the redirect URL
  ' set the redirect URL
  If (MM_editRedirectUrl = "") Then
    MM_editRedirectUrl = CStr(Request("URL"))
  End If
  If (Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And
Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If

End If
%> <%
' *** Delete Record: construct a sql delete statement and execute it

If (CStr(Request("MM_delete")) <> "" And CStr(Request("MM_recordId")) <> "")
Then

  ' create the sql delete statement
  MM_editQuery = "delete from " & MM_editTable & " where " & MM_editColumn & " =
" & MM_recordId

  If (Not MM_abortEdit) Then
    ' execute the delete
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute

    If (MM_editRedirectUrl <> "") Then
      Call Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
<%
Dim rsMessage__MMColParam
rsMessage__MMColParam = "0"
if (Request.QueryString("ID") <> "") then rsMessage__MMColParam =
Request.QueryString("ID")
%> <%
Dim rsReply__MMColParam
rsReply__MMColParam = "2"
if (Request.QueryString("ID") <> "") then rsReply__MMColParam =
Request.QueryString("ID")
%> <%
set rsMessage = Server.CreateObject("ADODB.Recordset")
rsMessage.ActiveConnection = MM_connChapter16_STRING
rsMessage.Source = "SELECT * FROM message WHERE ID = " +
Replace(rsMessage__MMColParam, "'", "''") + ""
rsMessage.CursorType = 0
rsMessage.CursorLocation = 2
rsMessage.LockType = 3
rsMessage.Open()
rsMessage_numRows = 0
%>
<%
set rsReply = Server.CreateObject("ADODB.Recordset")
rsReply.ActiveConnection = MM_connChapter16_STRING
rsReply.Source = "SELECT * FROM message WHERE parentID = " +
Replace(rsReply__MMColParam, "'", "''") + ""
rsReply.CursorType = 0
rsReply.CursorLocation = 2
rsReply.LockType = 3
rsReply.Open()
rsReply_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
rsReply_numRows = rsReply_numRows + Repeat1__numRows
%> <%
' *** Go To Record and Move To Record: create strings for maintaining URL and
Form parameters

' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName <> "") Then MM_removeList = MM_removeList & "&" & MM_paramName &
"="
MM_keepURL="":MM_keepForm="":MM_keepBoth="":MM_keepNone=""

' add the URL parameters to the MM_keepURL string
For Each Item In Request.QueryString
  NextItem = "&" & Item & "="
  If (InStr(1,MM_removeList,NextItem,1) = 0) Then
    MM_keepURL = MM_keepURL & NextItem &
Server.URLencode(Request.QueryString(Item))
  End If
Next

' add the Form variables to the MM_keepForm string
For Each Item In Request.Form
  NextItem = "&" & Item & "="
  If (InStr(1,MM_removeList,NextItem,1) = 0) Then
    MM_keepForm = MM_keepForm & NextItem & Server.URLencode(Request.Form(Item))
  End If
Next

' create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
if (MM_keepBoth <> "") Then MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) -
1)
if (MM_keepURL <> "")  Then MM_keepURL  = Right(MM_keepURL, Len(MM_keepURL) - 1)
if (MM_keepForm <> "") Then MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) -
1)

' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
  If (firstItem <> "") Then
    MM_joinChar = "&"
  Else
    MM_joinChar = ""
  End If
End Function
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
  <tr bgcolor="#FFFF99">
    <td>
      <div align="center"><font face="Arial, Helvetica, sans-serif"><b>Message
        View</b></font></div>
    </td>
  </tr>
  <tr bgcolor="#CCCCFF">
    <td>
      <div align="center">
        <p><font face="Arial, Helvetica, sans-serif" size="-1">Replies:<br>
          <%
While ((Repeat1__numRows <> 0) AND (NOT rsReply.EOF))
%><A HREF="message.asp?<%= MM_keepBoth & MM_joinChar(MM_keepBoth) & "ID=" &
rsReply.Fields.Item("ID").Value %>"><%=(rsReply.Fields.Item("subject").Value)%>
          , <%=(rsReply.Fields.Item("author").Value)%></A><br>
          <%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsReply.MoveNext()
Wend
%></font></p>
        <p><font face="Arial, Helvetica, sans-serif" size="-1"><a
href="compose.asp?ID=<%=(rsMessage.Fields.Item("ID").Value)%>">ADD
          NEW REPLY</a></font></p>
      </div>
    </td>
  </tr>
  <tr align="center">
    <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="5">
        <tr>
          <td width="22%" bgcolor="#CCFFCC"><b><font face="Arial, Helvetica,
sans-serif">Author</font></b></td>
          <td width="78%"><%=(rsMessage.Fields.Item("author").Value)%></td>
        </tr>
        <tr>
          <td width="22%" bgcolor="#CCFFCC"><b><font face="Arial, Helvetica,
sans-serif">Subject</font></b></td>
          <td width="78%"><%=(rsMessage.Fields.Item("subject").Value)%></td>
        </tr>
        <tr>
          <td width="22%" bgcolor="#CCFFCC"><b><font face="Arial, Helvetica,
sans-serif">Body</font></b></td>
          <td width="78%"><%=(rsMessage.Fields.Item("body").Value)%></td>
        </tr>
      </table>
      <br>
      <a href="index.asp"><font face="Arial, Helvetica, sans-serif">Back To Main
      Listing</font></a></td>
  </tr>
  <tr bgcolor="#CC9933" >
    <td align="center">
      <form name="delete" method="post" action="<%=MM_editAction%>">
        <font face="Arial, Helvetica, sans-serif">Password:
        <input type="password" name="password">
        </font>
        <input type="submit" name="Submit" value="Delete">
        <input type="hidden" name="MM_recordId" value="<%=
rsMessage.Fields.Item("ID").Value %>">
        <input type="hidden" name="MM_delete" value="true">
      </form>
    </td>
  </tr>
</table>
</body>
</html>

<%
rsMessage.Close()
%> <%
rsReply.Close()
%>


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint