vorheriges KapitelInhaltsverzeichnisStichwortverzeichnisFeedbacknächstes Kapitel


Anhang D.

Anhang Benutzerdefinierte Codelistings

Für mehrere Projekte der letzten Woche mussten Änderungen an den Seiten vorgenommen werden, damit sie korrekt zu funktionierten. Der Einfachheit halber stelle ich hier den vollständigen Code für diese Seiten zur Verfügung. Das HTML entspricht genau meinem Entwurf, aber der eingebettete Code kann als Referenz genutzt werden, wenn alles andere fehlschlägt.

D.1 Tag 15 - Das Gästebuch (guestbook.asp)

Für eines der ersten Projekte, das Gästebuch, musste der Code zur korrekten Definition der Abfrage abgeändert werden. Hier sehen Sie den Quellcode für das Gästebuch:

<%@LANGUAGE="VBSCRIPT"%> 
<!--#include file="../Connections/connChapter15a.asp" --> <%
' *** Datensatz einfügen: SQL-Einfügeanweisung konstruieren und ausführen
MM_editAction = CStr(Request("URL"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If
If (CStr(Request("MM_insert")) <> "") Then

MM_tableName = "tblcomment"
MM_fields =
"name,name,',none,'',email,email,',none,'',message,message,',none,''"
MM_redirectPage = "guestbook.asp"

' SQL-Anweisung für das Einfügen erstellen
MM_tableValues = ""
MM_dbValues = ""
MM_fieldsArray = Split(MM_fields, ",")
For i = LBound(MM_fieldsArray) To UBound(MM_fieldsArray) Step 5
FormVal = CStr(Request.Form(MM_fieldsArray(i)))
Delim = MM_fieldsArray(i+2)
If (Delim = "none") Then Delim = ""
AltVal = MM_fieldsArray(i+3)
If (AltVal = "none") Then AltVal = ""
EmptyVal = MM_fieldsArray(i+4)
If (EmptyVal = "none") Then EmptyVal = ""
If (FormVal = "") Then
FormVal = EmptyVal
Else
If (AltVal <> "") Then
FormVal = AltVal
ElseIf (Delim = "'") Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''") & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fieldsArray)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End if
MM_tableValues = MM_tableValues & MM_fieldsArray(i+1)
MM_dbValues = MM_dbValues & FormVal
Next
MM_insertStr = "insert into " & MM_tableName & " (" & MM_tableValues & ")
values (" & MM_dbValues & ")"

' SQL fertigstellen und ausführen
Set MM_insertCmd = Server.CreateObject("ADODB.Command")
MM_insertCmd.ActiveConnection = "dsn=ud9;"
MM_insertCmd.CommandText = MM_insertStr
MM_insertCmd.Execute

' Umleitung mit URL-Parametern
If (MM_redirectPage = "") Then
MM_redirectPage = CStr(Request("URL"))
End If
If (InStr(1, MM_redirectPage, "?", vbTextCompare) = 0 And (Request.QueryString
<> "")) Then
MM_redirectPage = MM_redirectPage & "?" & Request.QueryString
End If
Call Response.Redirect(MM_redirectPage)
End If
%>
<%
set rsComment = Server.CreateObject("ADODB.Recordset")
rsComment.ActiveConnection = MM_connChapter15a_STRING
pc="%"
rsComment.Source = "SELECT * FROM tblcomment WHERE message NOT LIKE '%SUCK%' AND
message NOT LIKE '%<"+pc+">%' ORDER BY messageID DESC"
rsComment.CursorType = 0
rsComment.CursorLocation = 2
rsComment.LockType = 3
rsComment.Open()
rsComment_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = 10
Dim Repeat1__index
Repeat1__index = 0
rsComment_numRows = rsComment_numRows + Repeat1__numRows
%>
<html>
<head>
<title>Gästebuch</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFCC">
<p align="center"><font face="Arial, Helvetica, sans-serif"
size="+1"><b><i>Tragen Sie sich
bitte in unser Gästebuch ein!</i></b></font></p>
<form name="frmComment" method="post" action="<%=MM_editAction%>">
<table width="83%" border="1" cellspacing="0" cellpadding="2" bgcolor="#CCCCFF"
align="center">
<tr>
<td width="13%" bgcolor="#FFFFCC"><font face="Arial, Helvetica,
sans-serif">Ihr
Name:</font></td>
<td width="87%">
<input type="text" name="name">
<font face="Arial, Helvetica, sans-serif">&nbsp;&nbsp;&nbsp;E-Mail-
Adresse:</font>
<input type="text" name="email">
</td>
</tr>
<tr>
<td width="13%" bgcolor="#FFFFCC"><font face="Arial, Helvetica,
sans-serif">Kommentar:</font></td>
<td width="87%">
<textarea name="message" rows="2" wrap="VIRTUAL" cols="50"></textarea>
</td>
</tr>
<tr>
<td width="13%" bgcolor="#FFFFCC">&nbsp;</td>
<td width="87%">
<div align="center">
<input type="submit" name="Submit" value="Save Comments">
</div>
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="true">
</form>
<p>&nbsp;</p>
<p align="center"><b><i><font size="+1">The last 10 people to sign the book
said...</font></i></b></p>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsComment.EOF))
%>
<table width="75%" border="0" cellspacing="0" cellpadding="2" align="center">
<tr>
<td>
<div align="center"><font face="Arial, Helvetica,
sans-serif"><%=(rsComment.Fields.Item("message").Value)%></font></div>
</td>
</tr>
<tr>
<td>
<div align="center"><i><font face="Arial, Helvetica,
sans-serif"><%=(rsComment.Fields.Item("name").Value)%></font></i></div>
</td>
</tr>
</table>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsComment.MoveNext()
Wend
%>
<p align="center">&nbsp;</p>
</body>
</html>

D.2 Tag 16 - Nachrichtenliste (index.asp)

Die Liste für das Nachrichtenboard musste Werte an sich selbst zurückgeben, die in der SORT BY-Klausel der Abfrage verwendet wurden. Beim Anlegen der Seite haben Sie diese Werte manuell eingefügt. Hier sehen Sie die Hauptseite für die Nachrichtenliste:

<%@LANGUAGE="VBSCRIPT"%> <!--#include file="../Connections/connChapter16.asp" -->
<%
Dim rsMessageList__MMColParam
rsMessageList__MMColParam = "0"
if (Request("MM_EmptyValue") <> "") then rsMessageList__MMColParam =
Request("MM_EmptyValue")
%> <%
Dim rsMessageList__varSortby
rsMessageList__varSortby = "ID"
if (Request("sortby") <> "") then rsMessageList__varSortby = Request("sortby")
%> <%
Dim rsMessageList__varSearchterm
rsMessageList__varSearchterm = "%"
if (Request("searchterm") <> "") then rsMessageList__varSearchterm =
Request("searchterm")
%> <%
set rsMessageList = Server.CreateObject("ADODB.Recordset")
rsMessageList.ActiveConnection = MM_connChapter16_STRING
rsMessageList.Source = "SELECT ID, subject, iconURL, author FROM message WHERE
hidden = " + Replace(rsMessageList__MMColParam, "'", "''") + " AND (subject LIKE
'%" + Replace(rsMessageList__varSearchterm, "'", "''") + "%' OR author LIKE '%" +
Replace(rsMessageList__varSearchterm, "'", "''") + "%' OR body LIKE '%" +
Replace(rsMessageList__varSearchterm, "'", "''") + "%') ORDER BY '" +
Replace(rsMessageList__varSortby, "'", "''") + "'"
rsMessageList.CursorType = 0
rsMessageList.CursorLocation = 2
rsMessageList.LockType = 3
rsMessageList.Open()
rsMessageList_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = 8
Dim Repeat1__index
Repeat1__index = 0
rsMessageList_numRows = rsMessageList_numRows + Repeat1__numRows
%> <%
' *** Recordset Stats, Zu Datensatz verschieben und Go To Record: stats-Variablen deklarieren

' Datensatzzähler setzen
rsMessageList_total = rsMessageList.RecordCount

' Setzt die Anzahl der Zeilen, die auf dieser Seite angezeigt werden
If (rsMessageList_numRows < 0) Then
rsMessageList_numRows = rsMessageList_total
Elseif (rsMessageList_numRows = 0) Then
rsMessageList_numRows = 1
End If

' Legt den ersten und den letzten angezeigten Datensatz fest
rsMessageList_first = 1
rsMessageList_last = rsMessageList_first + rsMessageList_numRows - 1

' Falls wir den korrekten Datensatzzähler haben, andere stats überprüfen
If (rsMessageList_total <> -1) Then
If (rsMessageList_first > rsMessageList_total) Then rsMessageList_first =
rsMessageList_total
If (rsMessageList_last > rsMessageList_total) Then rsMessageList_last =
rsMessageList_total
If (rsMessageList_numRows > rsMessageList_total) Then rsMessageList_numRows =
rsMessageList_total
End If
%> <%
' *** Recordset Stats: Falls wir den Datensatzzähler nicht kennen, manuell zählen

If (rsMessageList_total = -1) Then

' alle Datensätze zählen, indem wir das Recordset durchlaufen
rsMessageList_total=0
While (Not rsMessageList.EOF)
rsMessageList_total = rsMessageList_total + 1
rsMessageList.MoveNext
Wend

' Cursor auf den Anfang zurücksetzen
If (rsMessageList.CursorType > 0) Then
rsMessageList.MoveFirst
Else
rsMessageList.Requery
End If

' Anzahl der auf dieser Seite angezeigten Zeilen festlegen
If (rsMessageList_numRows < 0 Or rsMessageList_numRows > rsMessageList_total)
Then
rsMessageList_numRows = rsMessageList_total
End If

' Ersten und letzten angezeigten Datensatz festlegen
rsMessageList_first = 1
rsMessageList_last = rsMessageList_first + rsMessageList_numRows - 1
If (rsMessageList_first > rsMessageList_total) Then rsMessageList_first =
rsMessageList_total
If (rsMessageList_last > rsMessageList_total) Then rsMessageList_last =
rsMessageList_total

End If
%> <%
' *** Zu Datensatz verschieben: Variablen deklarieren

Set MM_rs = rsMessageList
MM_rsCount = rsMessageList_total
MM_size = rsMessageList_numRows
MM_uniqueCol = ""
MM_paramName = ""
MM_offset = 0
MM_atTotal = false
MM_paramIsDefined = false
If (MM_paramName <> "") Then
MM_paramIsDefined = (Request.QueryString(MM_paramName) <> "")
End If
%> <%
' *** Zu Datensatz verschieben: 'index' oder 'offset' Parameter verarbeiten

if (Not MM_paramIsDefined And MM_rsCount <> 0) then

' index-Parameter verwenden, falls definiert, andernfalls offset-Parameter
r = Request.QueryString("index")
If r = "" Then r = Request.QueryString("offset")
If r <> "" Then MM_offset = Int(r)

' Falls wir einen Datensatzzähler haben, prüfen, ob wir hinter dem Ende des Recordsets sind
If (MM_rsCount <> -1) Then
If (MM_offset >= MM_rsCount Or MM_offset = -1) Then ' Ende erreicht
If ((MM_rsCount Mod MM_size) > 0) Then ' letzte Seite kein vollständiger wiederholter Bereich
MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
Else
MM_offset = MM_rsCount - MM_size
End If
End If
End If

' Cursor auf den ausgewählten Datensatz setzen
i = 0
While ((Not MM_rs.EOF) And (i < MM_offset Or MM_offset = -1))
MM_rs.MoveNext
i = i + 1
Wend
If (MM_rs.EOF) Then MM_offset = i 'MM_offset auf letzten möglichen Datensatz setzen

End If
%> <%
' *** Zu Datensatz verschieben: falls wir den Datensatzzähler nicht kennen, Anzeigebereich
überprüfen

If (MM_rsCount = -1) Then

' zum Ende des Anzeigebereichs für diese Seite gehen
i = MM_offset
While (Not MM_rs.EOF And (MM_size < 0 Or i < MM_offset + MM_size))
MM_rs.MoveNext
i = i + 1
Wend

' falls hinter dem Recorsetende, MM_rsCount und MM_size setzen
If (MM_rs.EOF) Then
MM_rsCount = i
If (MM_size < 0 Or MM_size > MM_rsCount) Then MM_size = MM_rsCount
End If

' falls wir das Ende erreicht haben, Offset abhängig von der Seitengröße setzen
If (MM_rs.EOF And Not MM_paramIsDefined) Then
If (MM_offset > MM_rsCount - MM_size Or MM_offset = -1) Then
If ((MM_rsCount Mod MM_size) > 0) Then
MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
Else
MM_offset = MM_rsCount - MM_size
End If
End If
End If

' Cursor an den Anfang zurücksetzen
If (MM_rs.CursorType > 0) Then
MM_rs.MoveFirst
Else
MM_rs.Requery
End If

' Cursor auf den ausgewählten Datensatz setzen
i = 0
While (Not MM_rs.EOF And i < MM_offset)
MM_rs.MoveNext
i = i + 1
Wend
End If
%> <%
' *** Zu Datensatz verschieben: Datensatzgruppeninfo aktualisieren

' ersten und letzten angezeigten Datensatz festlegen
rsMessageList_first = MM_offset + 1
rsMessageList_last = MM_offset + MM_size
If (MM_rsCount <> -1) Then
If (rsMessageList_first > MM_rsCount) Then rsMessageList_first = MM_rsCount
If (rsMessageList_last > MM_rsCount) Then rsMessageList_last = MM_rsCount
End If

' Booleschen Wert setzen, mit dem der verborgene Bereich prüft, ob wir auf dem letzten Datensatz sind
MM_atTotal = (MM_rsCount <> -1 And MM_offset + MM_size >= MM_rsCount)
%> <%
' *** Zu Datensatz verschieben: Strings für die Verwaltung von URL-
Formularparameter anlegen

' Liste der Parameter erstellen, die nicht verwaltet werden sollen
MM_removeList = "&index="
If (MM_paramName <> "") Then MM_removeList = MM_removeList & "&" & MM_paramName &
"="
MM_keepURL="":MM_keepForm="":MM_keepBoth="":MM_keepNone=""

' dem String MM_keepURL die URL-Parameter hinzufügen
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

' dem String MM_keepForm die Formularparameter hinzufügen
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

' Formular- und URL-String erstellen und das führende '&' von den Strings entfernen
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)

' eine Utility-Funktion zum Hinzufügen zusätzlicher Parameter zu diesen Strings
Function MM_joinChar(firstItem)
If (firstItem <> "") Then
MM_joinChar = "&"
Else
MM_joinChar = ""
End If
End Function
%> <%
' *** Zu Datensatz verschieben: Strings für die Links erster, letzter, nächster und vorheriger setzen

MM_keepMove = MM_keepBoth
MM_moveParam = "index"

' falls die Seite einen wiederholten Bereich hat, 'offset' aus den verwalteten Parametern entfernen
parameters
If (MM_size > 0) Then
MM_moveParam = "offset"
If (MM_keepMove <> "") Then
params = Split(MM_keepMove, "&")
MM_keepMove = ""
For i = 0 To UBound(params)
nextItem = Left(params(i), InStr(params(i),"=") - 1)
If (StrComp(nextItem,MM_moveParam,1) <> 0) Then
MM_keepMove = MM_keepMove & "&" & params(i)
End If
Next
If (MM_keepMove <> "") Then
MM_keepMove = Right(MM_keepMove, Len(MM_keepMove) - 1)
End If
End If
End If

' Strings für das Verschieben zu Links setzen
If (MM_keepMove <> "") Then MM_keepMove = MM_keepMove & "&"
urlStr = Request.ServerVariables("URL") & "?" & MM_keepMove & MM_moveParam & "="
MM_moveFirst = urlStr & "0"
MM_moveLast = urlStr & "-1"
MM_moveNext = urlStr & Cstr(MM_offset + MM_size)
prev = MM_offset - MM_size
If (prev < 0) Then prev = 0
MM_movePrev = urlStr & Cstr(prev)
%>
<html>
<head>
<title>Unbenanntes Dokument </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="10" height="271">
<tr bgcolor="#9999FF">
<td>
<div align="center"><font face="Arial, Helvetica, sans-serif"
size="+3">Nachrichtenanzeige <br>
<font size="-1">(<%=(rsMessageList_total)%>
messages, showing <%=(rsMessageList_first)%>
thru <%=(rsMessageList_last)%>)
</font> </font></div>
</td>
</tr>
<tr bgcolor="#FFFF66">
<td height="124">
<table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr bgcolor="#FFFF66">
<td width="6%" bgcolor="#FFFF99">&nbsp;</td>
<td width="13%" bgcolor="#FFFF99"><font face="Arial, Helvetica,
sans-serif"><b>ID</b></font></td>
<td width="19%" bgcolor="#FFFF99"><font face="Arial, Helvetica,
sans-serif"><b><a href="index.asp?sortby=author">Autor</a></b></font></td>
<td width="62%" bgcolor="#FFFF99"><font face="Arial, Helvetica,
sans-serif"><b><A HREF="index.asp?sortby=author&<%= MM_keepBoth
%>">Subject</A></b></font></td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsMessageList.EOF))
%>
<tr>
<td width="6%"><img
src="<%=(rsMessageList.Fields.Item("iconURL").Value)%>"></td>
<td width="13%"><%=(rsMessageList.Fields.Item("ID").Value)%></td>
<td width="19%"><%=(rsMessageList.Fields.Item("author").Value)%></td>
<td width="62%"><A HREF="message.asp?<%= MM_keepBoth &
MM_joinChar(MM_keepBoth) & "ID=" & rsMessageList.Fields.Item("ID").Value
%>"><%=(rsMessageList.Fields.Item("subject").Value)%></A></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsMessageList.MoveNext()
Wend
%>
</table>
</td>
</tr>
<tr bgcolor="#CCCCFF">
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="49%"><% If MM_offset <> 0 Then %><font face="Arial,
Helvetica, sans-serif"><A HREF="<%=MM_movePrev%>">Previous
Messages</A></font><% End If ' end MM_offset <> 0 %></td>
<td align="right" width="51%"><% If Not MM_atTotal Then %><font
face="Arial, Helvetica, sans-serif"><A HREF="<%=MM_moveNext%>">Next
Messages</A></font><% End If ' end Not MM_atTotal %></td>
</tr>
</table>
<div align="center"><br>
<b><font face="Arial, Helvetica, sans-serif"><a href="compose.asp">Neue Nachricht

erstellen</a></font></b></div>
</td>
</tr>
<tr bgcolor="#CCFFCC">
<td height="61">
<form name="searchForm" action="index.asp">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="49%"><font face="Arial, Helvetica, sans-serif">Suchen nach:

<input type="text" name="searchterm">
</font></td>
<td align="right" width="51%"><font face="Arial, Helvetica,
sans-serif">
<input type="submit" name="Submit" value="Senden">
</font></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>

D.3 Tag 16 - Nachrichten lesen (message.asp)

Beim Lesen einer Nachricht auf dem Nachrichtenboard hat der Benutzer die Möglichkeit, diese zu löschen, indem er ein Kennwort eingibt und auf die Schaltfläche Löschen klickt. Um den Befehl für das Löschen korrekt aufzubauen, müssen die UltraDev-Verhalten angepasst werden. Hier der Quellcode für die Nachrichtenanzeigeseite:

<%@LANGUAGE="VBSCRIPT"%> <!--#include file="../Connections/connChapter16.asp" -->
<%
' *** Bearbeitungen: Variablen deklarieren

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

' Boolescher Wert zum Abbrechen der Datensatzbearbeitung
MM_abortEdit = false

' Auszuführender Abfragestring
MM_editQuery = ""
%> <%
' *** Datensatz löschen: Variablen deklarieren

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"

' URL für das Umleiten setzen
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
%> <%
' *** Datensatz löschen: eine SQL-Löschanweisung konstruieren und ausführen

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

' SQL-Löschanweisung erstellen
MM_editQuery = "delete from " & MM_editTable & " where " & MM_editColumn & " =
" & MM_recordId

If (Not MM_abortEdit) Then
' Löschen ausführen
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
%> <%
' *** Zu Datensatz verschieben: Strings zur Verwaltung von URL- und Formularparametern anlegen

' Liste der Parameter anlegen, die nicht verwaltet werden sollen
MM_removeList = "&index="
If (MM_paramName <> "") Then MM_removeList = MM_removeList & "&" & MM_paramName &
"="
MM_keepURL="":MM_keepForm="":MM_keepBoth="":MM_keepNone=""

' dem String MM_keepURL die URL-Parameter hinzufügen
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

' dem String MM_keepForm die Formularvariablen hinzufügen
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

' Formular- und URL-String erstellen und führendes '&' entfernen
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)

' eine Utility-Funktion zum Hinzufügen zusätzlicher Parameter zu diesen Strings
Function MM_joinChar(firstItem)
If (firstItem <> "") Then
MM_joinChar = "&"
Else
MM_joinChar = ""
End If
End Function
%>
<html>
<head>
<title>Unbenanntes Dokument</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>Nachrichtenanzeige</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)%>">NEUE ANTWORT
HINZUFÜGEN</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">Autor</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">Zurück zur
Hauptliste</font></a></td>
</tr>
<tr bgcolor="#CC9933" >
<td align="center">
<form name="delete" method="post" action="<%=MM_editAction%>">
<font face="Arial, Helvetica, sans-serif">Kennwort:
<input type="password" name="password">
</font>
<input type="submit" name="Submit" value="Löschen">
<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()
%>

D.4 Tag 17 - Anmeldeseite (login2.asp)

In Kapitel 17 wurden Anmeldeseiten verwendet, um Sitzungsvariablen die Benutzer-ID zuzuweisen. Diese Variable wurde dann genutzt, um den Benutzer zu beobachten, während er sich innerhalb der Site bewegte. Für den grundlegenden Bildschirm zur Anmeldeverarbeitung war eine benutzerdefinierte Programmierung erforderlich, um die Sitzungsvariable zu setzen:

Den Quellcode für login2.asp sehen Sie hier:

<%@LANGUAGE="VBSCRIPT"%> <!--#include file="../Connections/connChapter17.asp" -->
<%
Dim rsUserInfo__varUsername
rsUserInfo__varUsername = "growlf"
if (Request("username") <> "") then rsUserInfo__varUsername =
Request("username")
%> <%
Dim rsUserInfo__varPassword
rsUserInfo__varPassword = "growlf"
if (Request("password") <> "") then rsUserInfo__varPassword =
Request("password")
%> <%
set rsUserInfo = Server.CreateObject("ADODB.Recordset")
rsUserInfo.ActiveConnection = MM_connChapter17_STRING
rsUserInfo.Source = "SELECT * FROM tblUserInfo WHERE username='" +
Replace(rsUserInfo__varUsername, "'", "''") + "' AND password='" +
Replace(rsUserInfo__varPassword, "'", "''") + "'"
rsUserInfo.CursorType = 0
rsUserInfo.CursorLocation = 2
rsUserInfo.LockType = 3
rsUserInfo.Open()
rsUserInfo_numRows = 0
%>
<html>
<head>
<title>Catalog</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFCC" leftmargin="0" topmargin="0" marginwidth="0"
marginheight="0">
<table width="650" border="0" cellpadding="5" cellspacing="0">
<tr bgcolor="#000066">
<td width="85%" align="center"><font color="#FFFFFF" face="Arial, Helvetica,
sans-serif" size="+2">
Das Neueste - Die definitive Site für Falschinformationen</font></td>
</tr>
<tr>
<td width="85%" valign="top" bgcolor="#FFCC99">
<table width="100%" border="0" cellspacing="0" cellpadding="50">
<tr valign="top" align="left">
<td height="304">
<% If Not rsUserInfo.EOF Or Not rsUserInfo.BOF Then %>
<% Session("tempUserID")=(rsUserInfo.Fields.Item("userID").Value) %>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td><font face="Arial, Helvetica, sans-serif">Glückwunsch,
Sie haben sich erfolgreich angemeldet! <br>
Sie gelangen in das System, indem Sie <a
href="content.asp">hier</a>klicken.</font></td>
</tr>
</table>
<% End If ' end Not rsUserInfo.EOF Or NOT rsUserInfo.BOF %><br>
<% If rsUserInfo.EOF And rsUserInfo.BOF Then %>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td><font face="Arial, Helvetica, sans-serif">Ihre Anmeldung oder das Kennwort
sind fehlerhaft. Bitte <a
href="javascript:history.back();">versuchen Sie es
noch einmal!</a></font></td>
</tr>
</table>
<% End If ' end rsUserInfo.EOF And rsUserInfo %><br>
<br>
<font face="Arial, Helvetica, sans-serif">Falls Sie kein Konto bei diesem System haben,
müssen Sie eines einrichten, damit Sie den Inhalt anzeigen können
.<a href="register.asp"> Klicken Sie hier, um sich zu registrieren.</a></font> </td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<%
rsUserInfo.Close()
%>

D.5 Tag 17 - Inhaltsseite (content.asp)

Die Inhaltsseite der benutzerdefinierbaren Site enthält eine der umfangreichsten Änderungen des Quellcodes, die wir im gesamten Buch vorgenommen haben. Wenn sich der Benutzer erfolgreich angemeldet hat, wird ein Cookie mit seiner ID gesetzt, sodass er jederzeit auf die Site zurück kommen kann und seine Änderungen dort wiederfindet.

<%@LANGUAGE="VBSCRIPT"%> <!--#include file="../Connections/connChapter17.asp" -->
<% If (not (Session("tempUserID")="")) Then
Response.Cookies("UserID")=Session("tempUserID")
Response.Cookies("UserID").Expires=#12/31/2030#
  strUserID=Session("tempUserID")
End If
If (Request.Cookies("UserID")="") Then
Response.Redirect("login.asp")
Else
  strUserID=Request.Cookies("UserID")
End If
%> <%
Dim rsPageColor__varUserID
rsPageColor__varUserID = "0"
if (strUserID <> "") then rsPageColor__varUserID = strUserID
%> <%
Dim rsContentColor__varUserID
rsContentColor__varUserID = "0"
if (strUserID <> "") then rsContentColor__varUserID = strUserID
%> <%
Dim rsRegion1Content__varUserID
rsRegion1Content__varUserID = "0"
if (strUserID <> "") then rsRegion1Content__varUserID = strUserID
%> <%
Dim rsRegion2Content__varUserID
rsRegion2Content__varUserID = "0"
if (strUserID <> "") then rsRegion2Content__varUserID = strUserID
%> <%
Dim rsRegion3Content__varUserID
rsRegion3Content__varUserID = "0"
if (strUserID <> "") then rsRegion3Content__varUserID = strUserID
%> <%
Dim rsRegion4Content__varUserID
rsRegion4Content__varUserID = "0"
if (strUserID <> "") then rsRegion4Content__varUserID = strUserID
%> <%
Dim rsRegion1Location__varUserID
rsRegion1Location__varUserID = "0"
if (strUserID <> "") then rsRegion1Location__varUserID = strUserID
%> <%
Dim rsRegion2Location__varUserID
rsRegion2Location__varUserID = "0"
if (strUserID <> "") then rsRegion2Location__varUserID = strUserID
%> <%
Dim rsRegion3Location__varUserID
rsRegion3Location__varUserID = "0"
if (strUserID <> "") then rsRegion3Location__varUserID = strUserID
%> <%
Dim rsRegion4Location__varUserID
rsRegion4Location__varUserID = "0"
if (strUserID <> "") then rsRegion4Location__varUserID = strUserID
%> <%
set rsPageColor = Server.CreateObject("ADODB.Recordset")
rsPageColor.ActiveConnection = MM_connChapter17_STRING
rsPageColor.Source = "SELECT tblOption.optionValue FROM tblPreference,tblOption
WHERE tblPreference.featureID='1' AND tblPreference.optionID=tblOption.optionID
AND (tblPreference.userID='" + Replace(rsPageColor__varUserID, "'", "''") + "' OR
tblPreference.userID=0) ORDER BY tblPreference.userID DESC"
rsPageColor.CursorType = 0
rsPageColor.CursorLocation = 2
rsPageColor.LockType = 3
rsPageColor.Open()
rsPageColor_numRows = 0
%>
<%
set rsContentColor = Server.CreateObject("ADODB.Recordset")
rsContentColor.ActiveConnection = MM_connChapter17_STRING
rsContentColor.Source = "SELECT tblOption.optionValue FROM
tblPreference,tblOption WHERE tblPreference.featureID='2' AND
tblPreference.optionID=tblOption.optionID AND (tblPreference.userID='" +
Replace(rsContentColor__varUserID, "'", "''") + "' OR tblPreference.userID=0)
ORDER BY tblPreference.userID DESC"
rsContentColor.CursorType = 0
rsContentColor.CursorLocation = 2
rsContentColor.LockType = 3
rsContentColor.Open()
rsContentColor_numRows = 0
%>
<%
set rsRegion1Content = Server.CreateObject("ADODB.Recordset")
rsRegion1Content.ActiveConnection = MM_connChapter17_STRING
rsRegion1Content.Source = "SELECT tblOption.optionValue FROM
tblPreference,tblOption WHERE tblPreference.featureID='3' AND
tblPreference.optionID=tblOption.optionID AND (tblPreference.userID='" +
Replace(rsRegion1Content__varUserID, "'", "''") + "' OR tblPreference.userID=0)
ORDER BY tblPreference.userID DESC"
rsRegion1Content.CursorType = 0
rsRegion1Content.CursorLocation = 2
rsRegion1Content.LockType = 3
rsRegion1Content.Open()
rsRegion1Content_numRows = 0
%>
<%
set rsRegion2Content = Server.CreateObject("ADODB.Recordset")
rsRegion2Content.ActiveConnection = MM_connChapter17_STRING
rsRegion2Content.Source = "SELECT tblOption.optionValue FROM
tblPreference,tblOption WHERE tblPreference.featureID='4' AND
tblPreference.optionID=tblOption.optionID AND (tblPreference.userID='" +
Replace(rsRegion2Content__varUserID, "'", "''") + "' OR tblPreference.userID=0)
ORDER BY tblPreference.userID DESC"
rsRegion2Content.CursorType = 0
rsRegion2Content.CursorLocation = 2
rsRegion2Content.LockType = 3
rsRegion2Content.Open()
rsRegion2Content_numRows = 0
%>
<%
set rsRegion3Content = Server.CreateObject("ADODB.Recordset")
rsRegion3Content.ActiveConnection = MM_connChapter17_STRING
rsRegion3Content.Source = "SELECT tblOption.optionValue FROM
tblPreference,tblOption WHERE tblPreference.featureID='5' AND
tblPreference.optionID=tblOption.optionID AND (tblPreference.userID='" +
Replace(rsRegion3Content__varUserID, "'", "''") + "' OR tblPreference.userID=0)
ORDER BY tblPreference.userID DESC"
rsRegion3Content.CursorType = 0
rsRegion3Content.CursorLocation = 2
rsRegion3Content.LockType = 3
rsRegion3Content.Open()
rsRegion3Content_numRows = 0
%>
<%
set rsRegion4Content = Server.CreateObject("ADODB.Recordset")
rsRegion4Content.ActiveConnection = MM_connChapter17_STRING
rsRegion4Content.Source = "SELECT tblOption.optionValue FROM
tblPreference,tblOption WHERE tblPreference.featureID='6' AND
tblPreference.optionID=tblOption.optionID AND (tblPreference.userID='" +
Replace(rsRegion4Content__varUserID, "'", "''") + "' OR tblPreference.userID=0)
ORDER BY tblPreference.userID DESC"
rsRegion4Content.CursorType = 0
rsRegion4Content.CursorLocation = 2
rsRegion4Content.LockType = 3
rsRegion4Content.Open()
rsRegion4Content_numRows = 0
%>
<%
set rsRegion1Location = Server.CreateObject("ADODB.Recordset")
rsRegion1Location.ActiveConnection = MM_connChapter17_STRING
rsRegion1Location.Source = "SELECT tblOption.optionValue FROM
tblPreference,tblOption WHERE tblPreference.featureID='7' AND
tblPreference.optionID=tblOption.optionID AND (tblPreference.userID='" +
Replace(rsRegion1Location__varUserID, "'", "''") + "' OR tblPreference.userID=0)
ORDER BY tblPreference.userID DESC"
rsRegion1Location.CursorType = 0
rsRegion1Location.CursorLocation = 2
rsRegion1Location.LockType = 3
rsRegion1Location.Open()
rsRegion1Location_numRows = 0
%>
<%
set rsRegion2Location = Server.CreateObject("ADODB.Recordset")
rsRegion2Location.ActiveConnection = MM_connChapter17_STRING
rsRegion2Location.Source = "SELECT tblOption.optionValue FROM
tblPreference,tblOption WHERE tblPreference.featureID='8' AND
tblPreference.optionID=tblOption.optionID AND (tblPreference.userID='" +
Replace(rsRegion2Location__varUserID, "'", "''") + "' OR tblPreference.userID=0)
ORDER BY tblPreference.userID DESC"
rsRegion2Location.CursorType = 0
rsRegion2Location.CursorLocation = 2
rsRegion2Location.LockType = 3
rsRegion2Location.Open()
rsRegion2Location_numRows = 0
%>
<%
set rsRegion3Location = Server.CreateObject("ADODB.Recordset")
rsRegion3Location.ActiveConnection = MM_connChapter17_STRING
rsRegion3Location.Source = "SELECT tblOption.optionValue FROM
tblPreference,tblOption WHERE tblPreference.featureID='9' AND
tblPreference.optionID=tblOption.optionID AND (tblPreference.userID='" +
Replace(rsRegion3Location__varUserID, "'", "''") + "' OR tblPreference.userID=0)
ORDER BY tblPreference.userID DESC"
rsRegion3Location.CursorType = 0
rsRegion3Location.CursorLocation = 2
rsRegion3Location.LockType = 3
rsRegion3Location.Open()
rsRegion3Location_numRows = 0
%>
<%
set rsRegion4Location = Server.CreateObject("ADODB.Recordset")
rsRegion4Location.ActiveConnection = MM_connChapter17_STRING
rsRegion4Location.Source = "SELECT tblOption.optionValue FROM
tblPreference,tblOption WHERE tblPreference.featureID='10' AND
tblPreference.optionID=tblOption.optionID AND (tblPreference.userID='" +
Replace(rsRegion4Location__varUserID, "'", "''") + "' OR tblPreference.userID=0)
ORDER BY tblPreference.userID DESC"
rsRegion4Location.CursorType = 0
rsRegion4Location.CursorLocation = 2
rsRegion4Location.LockType = 3
rsRegion4Location.Open()
rsRegion4Location_numRows = 0
%>
<html>
<head>
<title>Misinformation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="<%=(rsPageColor.Fields.Item("optionValue").Value)%>">
<div id="Layer1" style="position:absolute; width:270px; height:268px; z-index:1;
<%=(rsRegion1Location.Fields.Item("optionValue").Value)%>; background-color:
<%=(rsContentColor.Fields.Item("optionValue").Value)%>; layer-background-color:
<%=(rsContentColor.Fields.Item("optionValue").Value)%>; border: 1px none
#000000"><%=(rsRegion1Content.Fields.Item("optionValue").Value)%></div>
<div id="Layer2" style="position:absolute; width:270px; height:268px; z-index:1;
<%=(rsRegion2Location.Fields.Item("optionValue").Value)%>; background-color:
<%=(rsContentColor.Fields.Item("optionValue").Value)%>; layer-background-color:
<%=(rsContentColor.Fields.Item("optionValue").Value)%>; border: 1px none
#000000"><%=(rsRegion2Content.Fields.Item("optionValue").Value)%></div>
<div id="Layer3" style="position:absolute; width:270px; height:268px; z-index:1;
<%=(rsRegion3Location.Fields.Item("optionValue").Value)%>; background-color:
<%=(rsContentColor.Fields.Item("optionValue").Value)%>; layer-background-color:
<%=(rsContentColor.Fields.Item("optionValue").Value)%>; border: 1px none
#000000"><%=(rsRegion3Content.Fields.Item("optionValue").Value)%></div>
<div id="Layer4" style="position:absolute; width:270px; height:268px; z-index:1;
<%=(rsRegion4Location.Fields.Item("optionValue").Value)%>; background-color:
<%=(rsContentColor.Fields.Item("optionValue").Value)%>; layer-background-color:
<%=(rsContentColor.Fields.Item("optionValue").Value)%>; border: 1px none
#000000"><%=(rsRegion4Content.Fields.Item("optionValue").Value)%></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p align="center"><font face="Arial, Helvetica, sans-serif"><a
href="preferences.asp">Einstellungen</a></font></p>
</body>
</html>
<%
rsPageColor.Close()
%> <%
rsContentColor.Close()
%> <%
rsRegion1Content.Close()
%> <%
rsRegion2Content.Close()
%> <%
rsRegion3Content.Close()
%> <%
rsRegion4Content.Close()
%> <%
rsRegion1Location.Close()
%> <%
rsRegion2Location.Close()
%> <%
rsRegion3Location.Close()
%> <%
rsRegion4Location.Close()
%>

D.6 Tag 19 - Bildschirm für die Quizfragen (quiz.asp)

Beim Prüfen des Benutzers muss das Programm wissen, welche Frage gerade angezeigt wird, um die möglichen Antworten für diese Frage anzuzeigen. Das haben wir ermöglicht, indem wir eine der Datensatzgruppen auf einer vorhergehenden Abfrage basieren ließen, die die Frage-ID zurückgab. Die Datensatzgruppen-Definitionen mussten umgeordnet werden, damit sie in der richtigen Reihenfolge ausgeführt wurden. Darüber hinaus wurde ein benutzerdefinierter Code für die Bereichsanzeige eingeführt, um anzuzeigen, dass das Quiz abgeschlossen ist. Den endgültigen Code für den Bildschirm, auf dem die Frage gestellt wird, sehen Sie hier:

<%@LANGUAGE="VBSCRIPT"%> <!--#include file="../Connections/connChapter19.asp"
--><%
' *** Zugriff auf die Seite beschränken: Zugriff auf die Seite erlauben oder verweigern
MM_authorizedUsers="student,teacher"
MM_authFailedURL="index.asp"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
If (false Or CStr(Session("MM_UserAuthorization"))="") Or _
(InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
MM_grantAccess = true
End If
End If
If Not MM_grantAccess Then
MM_qsChar = "?"
If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
MM_referrer = Request.ServerVariables("URL")
if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" &
Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" &
Server.URLEncode(MM_referrer)
Response.Redirect(MM_authFailedURL)
End If
%> <%
' *** Bearbeitungen: Variablen deklarieren

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

' Boolescher Wert für das Abbrechen der Bearbeitung
MM_abortEdit = false

' auszuführender Abfragestring
MM_editQuery = ""
%> <%
' *** Datensatz einfügen: Variablen setzen

If (CStr(Request("MM_insert")) <> "") Then

MM_editConnection = MM_connChapter19_STRING
MM_editTable = "response"
MM_editRedirectUrl = ""
MM_fieldsStr = "answerID|value|questionID|value|username|value"
MM_columnsStr =
"answerID|none,none,NULL|questionID|none,none,NULL|username|',none,''"

' Arrays MM_fields und MM_columns anlegen
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' Formularwerte setzen
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next

' URL für die Weiterleitung setzen
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
%> <%
' *** Datensatz einfügen: eine SQL-Einfügeanweisung erstellen und ausführen

If (CStr(Request("MM_insert")) <> "") Then

' die SQL-Einfügeanweisung erstellen
MM_tableValues = ""
MM_dbValues = ""
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),",")
Delim = MM_typeArray(0)
If (Delim = "none") Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none") Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none") Then EmptyVal = ""
If (FormVal = "") Then
FormVal = EmptyVal
Else
If (AltVal <> "") Then
FormVal = AltVal
ElseIf (Delim = "'") Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''") & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End if
MM_tableValues = MM_tableValues & MM_columns(i)
MM_dbValues = MM_dbValues & FormVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ")
values (" & MM_dbValues & ")"

If (Not MM_abortEdit) Then
' das Einfügen ausführen
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
%>
<%
set rsQuestion = Server.CreateObject("ADODB.Recordset")
rsQuestion.ActiveConnection = MM_connChapter19_STRING
rsQuestion.Source = "SELECT * FROM question"
rsQuestion.CursorType = 0
rsQuestion.CursorLocation = 2
rsQuestion.LockType = 3
rsQuestion.Open()
rsQuestion_numRows = 0
%>
<%
set rsResponse = Server.CreateObject("ADODB.Recordset")
rsResponse.ActiveConnection = MM_connChapter19_STRING
rsResponse.Source = "SELECT * FROM response"
rsResponse.CursorType = 0
rsResponse.CursorLocation = 2
rsResponse.LockType = 3
rsResponse.Open()
rsResponse_numRows = 0
%> <%
Dim rsCorrect__varUsername
rsCorrect__varUsername = "jray"
if (Session("MM_Username") <> "") then rsCorrect__varUsername =
Session("MM_Username")
%>
<%
set rsCorrect = Server.CreateObject("ADODB.Recordset")
rsCorrect.ActiveConnection = MM_connChapter19_STRING
rsCorrect.Source = "SELECT * FROM response,question WHERE response.username='"
+ Replace(rsCorrect__varUsername, "'", "''") + "' AND
response.answerID=question.answerID AND response.questionID=question.questionID"
rsCorrect.CursorType = 0
rsCorrect.CursorLocation = 2
rsCorrect.LockType = 3
rsCorrect.Open()
rsCorrect_numRows = 0
%>
<%
Dim rsResponseAll__MMColParam
rsResponseAll__MMColParam = "0"
if (Session("MM_Username") <> "") then rsResponseAll__MMColParam =
Session("MM_Username")
%> <%
set rsResponseAll = Server.CreateObject("ADODB.Recordset")
rsResponseAll.ActiveConnection = MM_connChapter19_STRING
rsResponseAll.Source = "SELECT * FROM response WHERE username = '" +
Replace(rsResponseAll__MMColParam, "'", "''") + "'"
rsResponseAll.CursorType = 0
rsResponseAll.CursorLocation = 2
rsResponseAll.LockType = 3
rsResponseAll.Open()
rsResponseAll_numRows = 0
%>
<%
' *** Datensatzgruppe Stats, Zu Datensatz verschieben: stats-Variablen deklarieren

' Datensatzzähler setzen
rsQuestion_total = rsQuestion.RecordCount

' Anzahl der auf dieser Seite angezeigten Zeilen festlegen
If (rsQuestion_numRows < 0) Then
rsQuestion_numRows = rsQuestion_total
Elseif (rsQuestion_numRows = 0) Then
rsQuestion_numRows = 1
End If

' ersten und letzten angezeigten Datensatz festlegen
rsQuestion_first = 1
rsQuestion_last = rsQuestion_first + rsQuestion_numRows - 1

' falls wir den richtigen Datensatzzähler haben, andere stats überprüfen
If (rsQuestion_total <> -1) Then
If (rsQuestion_first > rsQuestion_total) Then rsQuestion_first =
rsQuestion_total
If (rsQuestion_last > rsQuestion_total) Then rsQuestion_last = rsQuestion_total
If (rsQuestion_numRows > rsQuestion_total) Then rsQuestion_numRows =
rsQuestion_total
End If
%> <%
' *** Datensatzgruppen-Stats, Zu Datensatz verschieben: stats-Variablen deklarieren

' Datensatzzähler setzen
rsCorrect_total = rsCorrect.RecordCount

' Anzahl der auf dieser Seite angezeigten Zeilen festlegen
If (rsCorrect_numRows < 0) Then
rsCorrect_numRows = rsCorrect_total
Elseif (rsCorrect_numRows = 0) Then
rsCorrect_numRows = 1
End If

' ersten und letzten angezeigten Datensatz festlegen
rsCorrect_first = 1
rsCorrect_last = rsCorrect_first + rsCorrect_numRows - 1

' falls wir den richtigen Datensatzzähler haben, andere stats überprüfen
If (rsCorrect_total <> -1) Then
If (rsCorrect_first > rsCorrect_total) Then rsCorrect_first = rsCorrect_total
If (rsCorrect_last > rsCorrect_total) Then rsCorrect_last = rsCorrect_total
If (rsCorrect_numRows > rsCorrect_total) Then rsCorrect_numRows =
rsCorrect_total
End If
%> <%
' *** Datensatzgruppen-Stats, Zu Datensatz verschieben: stats-Variablen deklarieren

' Datensatzzähler setzen
rsResponseAll_total = rsResponseAll.RecordCount

' Anzahl der auf dieser Seite angezeigten Zeilen festlegen
If (rsResponseAll_numRows < 0) Then
rsResponseAll_numRows = rsResponseAll_total
Elseif (rsResponseAll_numRows = 0) Then
rsResponseAll_numRows = 1
End If

' ersten und letzten angezeigten Datensatz festlegen
rsResponseAll_first = 1
rsResponseAll_last = rsResponseAll_first + rsResponseAll_numRows - 1

' falls wir den richtigen Datensatzzähler haben, andere stats überprüfen
If (rsResponseAll_total <> -1) Then
If (rsResponseAll_first > rsResponseAll_total) Then rsResponseAll_first =
rsResponseAll_total
If (rsResponseAll_last > rsResponseAll_total) Then rsResponseAll_last =
rsResponseAll_total
If (rsResponseAll_numRows > rsResponseAll_total) Then rsResponseAll_numRows =
rsResponseAll_total
End If
%> <%
' *** Datensatzgruppen-Stats: wenn wir den Datensatzzähler nicht kennen, zählen wir sie manuell

If (rsQuestion_total = -1) Then

' Datensatzgruppe durchlaufen, um die Datensätze zu zählen
rsQuestion_total=0
While (Not rsQuestion.EOF)
rsQuestion_total = rsQuestion_total + 1
rsQuestion.MoveNext
Wend

' Cursor auf den Anfang zurücksetzen
If (rsQuestion.CursorType > 0) Then
rsQuestion.MoveFirst
Else
rsQuestion.Requery
End If

' Anzahl der auf dieser Seite angezeigten Zeilen festlegen
If (rsQuestion_numRows < 0 Or rsQuestion_numRows > rsQuestion_total) Then
rsQuestion_numRows = rsQuestion_total
End If

' ersten und letzten angezeigten Datensatz festlegen
rsQuestion_first = 1
rsQuestion_last = rsQuestion_first + rsQuestion_numRows - 1
If (rsQuestion_first > rsQuestion_total) Then rsQuestion_first =
rsQuestion_total
If (rsQuestion_last > rsQuestion_total) Then rsQuestion_last = rsQuestion_total

End If
%> <%
' *** Datensatzgruppen-Stats: wenn wir den Datensatzzähler nicht kennen, zählen wir sie manuell

If (rsCorrect_total = -1) Then

' Datensatzgruppe durchlaufen, um die Datensätze zu zählen
rsCorrect_total=0
While (Not rsCorrect.EOF)
rsCorrect_total = rsCorrect_total + 1
rsCorrect.MoveNext
Wend

' Cursor auf den Anfang zurücksetzen
If (rsCorrect.CursorType > 0) Then
rsCorrect.MoveFirst
Else
rsCorrect.Requery
End If

' Anzahl der auf dieser Seite angezeigten Zeilen festlegen
If (rsCorrect_numRows < 0 Or rsCorrect_numRows > rsCorrect_total) Then
rsCorrect_numRows = rsCorrect_total
End If

' ersten und letzten angezeigten Datensatz festlegen
rsCorrect_first = 1
rsCorrect_last = rsCorrect_first + rsCorrect_numRows - 1
If (rsCorrect_first > rsCorrect_total) Then rsCorrect_first = rsCorrect_total
If (rsCorrect_last > rsCorrect_total) Then rsCorrect_last = rsCorrect_total

End If
%> <%
' *** Datensatzgruppen-Stats: wenn wir den Datensatzzähler nicht kennen, zählen wir sie manuell

If (rsResponseAll_total = -1) Then

' Datensatzgruppe durchlaufen, um die Datensätze zu zählen
rsResponseAll_total=0
While (Not rsResponseAll.EOF)
rsResponseAll_total = rsResponseAll_total + 1
rsResponseAll.MoveNext
Wend

' Cursor auf den Anfang zurücksetzen
If (rsResponseAll.CursorType > 0) Then
rsResponseAll.MoveFirst
Else
rsResponseAll.Requery
End If

' Anzahl der auf dieser Seite angezeigten Zeilen festlegen
If (rsResponseAll_numRows < 0 Or rsResponseAll_numRows > rsResponseAll_total)
Then
rsResponseAll_numRows = rsResponseAll_total
End If

' ersten und letzten angezeigten Datensatz festlegen
rsResponseAll_first = 1
rsResponseAll_last = rsResponseAll_first + rsResponseAll_numRows - 1
If (rsResponseAll_first > rsResponseAll_total) Then rsResponseAll_first =
rsResponseAll_total
If (rsResponseAll_last > rsResponseAll_total) Then rsResponseAll_last =
rsResponseAll_total

End If
%> <%
' *** Zu Datensatz verschieben: Variablen deklarieren

Set MM_rs = rsQuestion
MM_rsCount = rsQuestion_total
MM_size = rsQuestion_numRows
MM_uniqueCol = ""
MM_paramName = ""
MM_offset = 0
MM_atTotal = false
MM_paramIsDefined = false
If (MM_paramName <> "") Then
MM_paramIsDefined = (Request.QueryString(MM_paramName) <> "")
End If
%> <%
' *** Zu Datensatz verschieben: index- und offset-Parameter verarbeiten

if (Not MM_paramIsDefined And MM_rsCount <> 0) then

' ggf. definierten index-Parameter verwenden, andernfalls den offset-Parameter
r = Request.QueryString("index")
If r = "" Then r = Request.QueryString("offset")
If r <> "" Then MM_offset = Int(r)

' falls wir einen Datensatzzähler haben, prüfen, ob wir das Ende der Datensatzgruppe erreicht haben
If (MM_rsCount <> -1) Then
If (MM_offset >= MM_rsCount Or MM_offset = -1) Then ' past end or move last
If ((MM_rsCount Mod MM_size) > 0) Then ' letzte Seite ist kein vollständiger
wiederholter Bereich
MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
Else
MM_offset = MM_rsCount - MM_size
End If
End If
End If

' Cursor auf den ausgewählten Datensatz setzen
i = 0
While ((Not MM_rs.EOF) And (i < MM_offset Or MM_offset = -1))
MM_rs.MoveNext
i = i + 1
Wend
If (MM_rs.EOF) Then MM_offset = i ' set MM_offset to the last possible record

End If
%> <%
' *** Zu Datensatz verschieben: falls wir den Datensatzzähler nicht kennen, Anzeigebereich überprüfen

If (MM_rsCount = -1) Then

' ans Ende des Anzeigebereichs für diese Seite gehen
i = MM_offset
While (Not MM_rs.EOF And (MM_size < 0 Or i < MM_offset + MM_size))
MM_rs.MoveNext
i = i + 1
Wend

' falls wir das Ende der Datensatzgruppe erreicht haben, MM_rsCount und MM_size setzen
If (MM_rs.EOF) Then
MM_rsCount = i
If (MM_size < 0 Or MM_size > MM_rsCount) Then MM_size = MM_rsCount
End If

' falls wir das Ende der Datensatzgruppe erreicht haben, Offset abhängig von der Seitengröße setzen
If (MM_rs.EOF And Not MM_paramIsDefined) Then
If (MM_offset > MM_rsCount - MM_size Or MM_offset = -1) Then
If ((MM_rsCount Mod MM_size) > 0) Then
MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
Else
MM_offset = MM_rsCount - MM_size
End If
End If
End If

' Cursor auf den Anfang zurücksetzen
If (MM_rs.CursorType > 0) Then
MM_rs.MoveFirst
Else
MM_rs.Requery
End If

' Cursor auf den ausgewählten Datensatz setzen
i = 0
While (Not MM_rs.EOF And i < MM_offset)
MM_rs.MoveNext
i = i + 1
Wend
End If
%> <%
set rsAnswer = Server.CreateObject("ADODB.Recordset")
rsAnswer.ActiveConnection = MM_connChapter19_STRING
rsAnswer.Source = "SELECT * FROM answer WHERE questionID='" &
rsQuestion.Fields.Item("questionID").Value & "'"
rsAnswer.CursorType = 0
rsAnswer.CursorLocation = 2
rsAnswer.LockType = 3
rsAnswer.Open()
rsAnswer_numRows = 0
%>
<%
' *** Zu Datensatz verschieben: update recordset stats

' ersten und letzten angezeigten Datensatz festlegen
rsQuestion_first = MM_offset + 1
rsQuestion_last = MM_offset + MM_size
If (MM_rsCount <> -1) Then
If (rsQuestion_first > MM_rsCount) Then rsQuestion_first = MM_rsCount
If (rsQuestion_last > MM_rsCount) Then rsQuestion_last = MM_rsCount
End If

' den booleschen Wert setzen, der vom zu verbergenden Bereich verwendet wird, um zu prüfen,
ob wir uns auf dem letzten Datensatz befinden
MM_atTotal = (MM_rsCount <> -1 And MM_offset + MM_size >= MM_rsCount)
%> <%
' *** Zu Datensatz verschieben: Strings zum Verwalten von URL- und
Formularparametern erstellen

' Liste der Parameter erstellen, die nicht verwaltet werden sollen
MM_removeList = "&index="
If (MM_paramName <> "") Then MM_removeList = MM_removeList & "&" & MM_paramName &
"="
MM_keepURL="":MM_keepForm="":MM_keepBoth="":MM_keepNone=""

' dem String MM_keepURL die URL-Parameter hinzufügen
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

' dem String MM_keepForm die Formular-Parameter hinzufügen
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

' Formular- und URL-String erstellen und das führende '&' entfernen
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)

' eine Utility-Funktion zum Hinzufügen zusätzlicher Parameter zu diesen Strings
Function MM_joinChar(firstItem)
If (firstItem <> "") Then
MM_joinChar = "&"
Else
MM_joinChar = ""
End If
End Function
%> <%
' *** Zu Datensatz verschieben: Strings für erster, letzter, nächster und vorheriger setzen
links

MM_keepMove = MM_keepBoth
MM_moveParam = "index"

' falls die Seite einen wiederholten Bereich enthält, 'offset' von den verwalteten Parametern entfernen
If (MM_size > 0) Then
MM_moveParam = "offset"
If (MM_keepMove <> "") Then
params = Split(MM_keepMove, "&")
MM_keepMove = ""
For i = 0 To UBound(params)
nextItem = Left(params(i), InStr(params(i),"=") - 1)
If (StrComp(nextItem,MM_moveParam,1) <> 0) Then
MM_keepMove = MM_keepMove & "&" & params(i)
End If
Next
If (MM_keepMove <> "") Then
MM_keepMove = Right(MM_keepMove, Len(MM_keepMove) - 1)
End If
End If
End If

' Strings für das Verschieben zu Links setzen
If (MM_keepMove <> "") Then MM_keepMove = MM_keepMove & "&"
urlStr = Request.ServerVariables("URL") & "?" & MM_keepMove & MM_moveParam & "="
MM_moveFirst = urlStr & "0"
MM_moveLast = urlStr & "-1"
MM_moveNext = urlStr & Cstr(MM_offset + MM_size)
prev = MM_offset - MM_size
If (prev < 0) Then prev = 0
MM_movePrev = urlStr & Cstr(prev)
%>
<html>
<head>
<title>Quiz Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<form name="saveResponse" method="post" action="<%=MM_moveNext%>">
<% If rsResponseAll_total <> rsQuestion_total Then %>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr align="center" bgcolor="#CCCCFF">
<td><a href="admin1.asp"><font face="Arial, Helvetica,
sans-serif">Admin</font></a></td>
<td>
<p><font face="Arial, Helvetica, sans-serif" size="+1">Quizfrage
</font></p>
<p><font face="Arial, Helvetica, sans-serif" size="+1">(Ihre Antwort
<%=(rsResponseAll_total)%>/<%=(rsQuestion_total)%>)<br>
Thema:
<b><%=(rsQuestion.Fields.Item("questionTitle").Value)%></b></font></p>
</td>
</tr>
<tr bgcolor="#FFCC99">
<td width="17%"><font face="Arial, Helvetica, sans-serif">Die Frage:</font></td>
<td width="83%"><font face="Arial, Helvetica,
sans-serif"><%=(rsQuestion.Fields.Item("questionText").Value)%></font></td>
</tr>
<tr bgcolor="#FFCC99">
<td width="17%"><font face="Arial, Helvetica, sans-serif">Ihre Antwort:</font></td>
<td width="83%">
<select name="answerID">
<%
While (NOT rsAnswer.EOF)
%>
<option
value="<%=(rsAnswer.Fields.Item("answerID").Value)%>"><%=
(rsAnswer.Fields.Item("answerText").Value)%></option>
<%
rsAnswer.MoveNext()
Wend
%>
</select>
</td>
</tr>
<tr align="center" bgcolor="#CCCCFF">
<td><A HREF="<%=MM_moveNext%>">SKIP
QUESTION</A></td>
<td>
<input type="submit" name="Submit" value="Antwort senden">
<input type="hidden" name="questionID"
value="<%=rsQuestion.Fields.Item("questionID").Value%>">
<input type="hidden" name="username" value="<%=Session("MM_Username")%>">
<input type="hidden" name="MM_insert" value="true">
</td>
</tr>
</table>
<% End If %>
<% If rsResponseAll_total = rsQuestion_total Then %>
Herzlichen Glückwunsch! Sie sind fertig! <% End If %>
</form>
<%=(rsCorrect_total)%>
</body>
</html>
<%
rsQuestion.Close()
%> <%
rsResponse.Close()
%> <%
rsAnswer.Close()
%> <%
rsCorrect.Close()
%> <%
rsResponseAll.Close()
%>

D.7 Tag 20 - In den Einkaufswagen legen (details.asp)

In Kapitel 20 gab es ein kleineres Problem damit, Artikel in den Einkaufswagen zu legen. Weil die Benutzer-ID in einer Sitzungsvariablen abgelegt wurde, konnte das Standardverhalten für das Einfügen nicht genutzt werden. Schnell und einfach kann man diese Situation auflösen, indem man Code in das HTML einfügt, der direkt auf die Sitzungsvariable zugreift. Der Benutzer, der den Artikel anzeigt, muss angemeldet sein, um ihn in den Einkaufswagen legen zu können. Das bedeutet eine weitere Abänderung des Verhaltens Bereich verbergen. Hier der Quellcode für die Seite details.asp des E- Commerce-Katalogsystems:

<%@LANGUAGE="VBSCRIPT"%> <!--#include file="../Connections/connCatalog.asp" -->
<%
' *** Bearbeitungen: Variablen deklarieren

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

' Boolescher Wert für das Abbrechen der Bearbeitung
MM_abortEdit = false

' auszuführender Abfragestring
MM_editQuery = ""
%> <%
' *** Datensatz einfügen: Variablen setzen

If (CStr(Request("MM_insert")) <> "") Then

MM_editConnection = MM_connCatalog_STRING
MM_editTable = "tblCart"
MM_editRedirectUrl = "checkout.asp"
MM_fieldsStr = "prodID|value"
MM_columnsStr = "prodID|',none,''"

' Arrays MM_fields und MM_columns anlegen
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' Formularwerte setzen
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next

' URL für die Weiterleitung setzen
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
%> <%
' *** Datensatz einfügen: eine SQL-Einfügeanweisung erstellen und ausführen

If (CStr(Request("MM_insert")) <> "") Then

' die SQL-Einfügeanweisung erstellen
MM_tableValues = ""
MM_dbValues = ""
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),",")
Delim = MM_typeArray(0)
If (Delim = "none") Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none") Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none") Then EmptyVal = ""
If (FormVal = "") Then
FormVal = EmptyVal
Else
If (AltVal <> "") Then
FormVal = AltVal
ElseIf (Delim = "'") Then ' Escape für Anführungszeichen
FormVal = "'" & Replace(FormVal,"'","''") & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End if
MM_tableValues = MM_tableValues & MM_columns(i)
MM_dbValues = MM_dbValues & FormVal
Next
strUsername = Session("MM_Username")
MM_editQuery = "insert into " & MM_editTable & " values (''," & MM_dbValues &
",'" & strUsername & "','')"

If (Not MM_abortEdit) Then
' das Einfügen ausführen
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 searchresults__formCat
searchresults__formCat = "%"
if (Request("category") <> "") then searchresults__formCat = Request("category")

%> <%
Dim searchresults__formPrice
searchresults__formPrice = "9999"
if (Request("pricelimit") <> "") then searchresults__formPrice =
Request("pricelimit")
%> <%
Dim searchresults__formKey
searchresults__formKey = "%"
if (Request("keyword") <> "") then searchresults__formKey = Request("keyword")
%> <%
Dim RelatedItems__relatedID
RelatedItems__relatedID = "M004"
if (Request("id") <> "") then RelatedItems__relatedID = Request("id")
%> <%
set searchresults = Server.CreateObject("ADODB.Recordset")
searchresults.ActiveConnection = MM_connCatalog_STRING
searchresults.Source = "SELECT * FROM tblProduct WHERE catID LIKE '" +
Replace(searchresults__formCat, "'", "''") + "' AND prodPrice<'" +
Replace(searchresults__formPrice, "'", "''") + "' AND prodDesc LIKE '%" +
Replace(searchresults__formKey, "'", "''") + "%' ORDER BY catID"
searchresults.CursorType = 0
searchresults.CursorLocation = 2
searchresults.LockType = 3
searchresults.Open()
searchresults_numRows = 0
%>
<%
set RelatedItems = Server.CreateObject("ADODB.Recordset")
RelatedItems.ActiveConnection = MM_connCatalog_STRING
RelatedItems.Source = "SELECT tblProduct.* FROM tblProduct,tblRelated WHERE
tblProduct.prodID=tblRelated.prodID2 and tblRelated.prodID1='" +
Replace(RelatedItems__relatedID, "'", "''") + "';"
RelatedItems.CursorType = 0
RelatedItems.CursorLocation = 2
RelatedItems.LockType = 3
RelatedItems.Open()
RelatedItems_numRows = 0
%>
<%
set rsCart = Server.CreateObject("ADODB.Recordset")
rsCart.ActiveConnection = MM_connCatalog_STRING
rsCart.Source = "SELECT * FROM tblCart"
rsCart.CursorType = 0
rsCart.CursorLocation = 2
rsCart.LockType = 3
rsCart.Open()
rsCart_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
RelatedItems_numRows = RelatedItems_numRows + Repeat1__numRows
%> <%
' *** Datensatzgruppen-Stats, Zu Datensatz verschieben: stats-Variablen deklarieren

' Datensatzzähler setzen
searchresults_total = searchresults.RecordCount

' Anzahl der auf dieser Seite angezeigten Zeilen festlegen
If (searchresults_numRows < 0) Then
searchresults_numRows = searchresults_total
Elseif (searchresults_numRows = 0) Then
searchresults_numRows = 1
End If

' ersten und letzten angezeigten Datensatz festlegen
searchresults_first = 1
searchresults_last = searchresults_first + searchresults_numRows - 1

' falls wir den richtigen Datensatzzähler haben, andere stats überprüfen
If (searchresults_total <> -1) Then
If (searchresults_first > searchresults_total) Then searchresults_first =
searchresults_total
If (searchresults_last > searchresults_total) Then searchresults_last =
searchresults_total
If (searchresults_numRows > searchresults_total) Then searchresults_numRows =
searchresults_total
End If
%> <%
' *** Zu Datensatz verschieben: Variablen deklarieren

Set MM_rs = searchresults
MM_rsCount = searchresults_total
MM_size = searchresults_numRows
MM_uniqueCol = "prodID"
MM_paramName = "id"
MM_offset = 0
MM_atTotal = false
MM_paramIsDefined = false
If (MM_paramName <> "") Then
MM_paramIsDefined = (Request.QueryString(MM_paramName) <> "")
End If
%> <%
' *** Zu Datensatz verschieben: index- und offset-Parameter verarbeiten

if (Not MM_paramIsDefined And MM_rsCount <> 0) then

' ggf. definierten index-Parameter verwenden, andernfalls den offset-Parameter
r = Request.QueryString("index")
If r = "" Then r = Request.QueryString("offset")
If r <> "" Then MM_offset = Int(r)

' falls wir einen Datensatzzähler haben, prüfen, ob wir das Ende der Datensatzgruppe erreicht haben
If (MM_rsCount <> -1) Then
If (MM_offset >= MM_rsCount Or MM_offset = -1) Then ' past end or move last
If ((MM_rsCount Mod MM_size) > 0) Then ' last page not a full
repeat region
MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
Else
MM_offset = MM_rsCount - MM_size
End If
End If
End If

' Cursor auf den ausgewählten Datensatz setzen
i = 0
While ((Not MM_rs.EOF) And (i < MM_offset Or MM_offset = -1))
MM_rs.MoveNext
i = i + 1
Wend
If (MM_rs.EOF) Then MM_offset = i ' set MM_offset to the last possible record

End If
%> <%
' *** Zu bestimmtem Datensatz verschieben: Detailparameter verarbeiten

If (MM_paramIsDefined And MM_rsCount <> 0) Then

' Wert des Parameters ermitteln
param = Request.QueryString(MM_paramName)

' Datensatz mit dem eindeutigen Spaltenwert gleich dem Parameterwert finden
MM_offset = 0
Do While (Not MM_rs.EOF)
If (Cstr(MM_rs.Fields.Item(MM_uniqueCol).Value) = param) Then
Exit Do
End If
MM_offset = MM_offset + 1
MM_rs.MoveNext
Loop

' falls nicht gefunden, Anzahl der Datensätze setzen und den Cursor zurücksetzen
If (MM_rs.EOF) Then
If (MM_rsCount < 0) Then MM_rsCount = MM_offset
If (MM_size < 0 Or MM_size > MM_offset) Then MM_size = MM_offset
MM_offset = 0

' Cursor auf den Anfang zurücksetzen
If (MM_rs.CursorType > 0) Then
MM_rs.MoveFirst
Else
MM_rs.Close
MM_rs.Open
End If
End If

End If
%> <%
' *** Zu Datensatz verschieben: falls wir den Datensatzzähler nicht kennen, Anzeigebereich überprüfen

If (MM_rsCount = -1) Then

' ans Ende des Anzeigebereichs für diese Seite gehen
i = MM_offset
While (Not MM_rs.EOF And (MM_size < 0 Or i < MM_offset + MM_size))
MM_rs.MoveNext
i = i + 1
Wend

' falls wir das Ende der Datensatzgruppe erreicht haben, MM_rsCount und MM_size setzen
If (MM_rs.EOF) Then
MM_rsCount = i
If (MM_size < 0 Or MM_size > MM_rsCount) Then MM_size = MM_rsCount
End If

' falls wir das Ende der Datensatzgruppe erreicht haben, Offset abhängig von der Seitengröße setzen
If (MM_rs.EOF And Not MM_paramIsDefined) Then
If (MM_offset > MM_rsCount - MM_size Or MM_offset = -1) Then
If ((MM_rsCount Mod MM_size) > 0) Then
MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
Else
MM_offset = MM_rsCount - MM_size
End If
End If
End If

' Cursor auf den Anfang zurücksetzen
If (MM_rs.CursorType > 0) Then
MM_rs.MoveFirst
Else
MM_rs.Requery
End If

' Cursor auf den ausgewählten Datensatz setzen
i = 0
While (Not MM_rs.EOF And i < MM_offset)
MM_rs.MoveNext
i = i + 1
Wend
End If
%> <%
' *** Zu Datensatz verschieben: Datensatzgruppen-stats aktualisieren

' ersten und letzten angezeigten Datensatz festlegen
searchresults_first = MM_offset + 1
searchresults_last = MM_offset + MM_size
If (MM_rsCount <> -1) Then
If (searchresults_first > MM_rsCount) Then searchresults_first = MM_rsCount
If (searchresults_last > MM_rsCount) Then searchresults_last = MM_rsCount
End If

' den booleschen Wert setzen, der vom zu verbergenden Bereich verwendet wird, um zu prüfen, ob wir uns auf dem letzten Datensatz befinden
MM_atTotal = (MM_rsCount <> -1 And MM_offset + MM_size >= MM_rsCount)
%> <%
' *** Zu Datensatz verschieben: Strings für die Verwaltung von URL- und Formularparameter erstellen

' Liste der Parameter erstellen, die nicht verwaltet werden sollen
MM_removeList = "&index="
If (MM_paramName <> "") Then MM_removeList = MM_removeList & "&" & MM_paramName &
"="
MM_keepURL="":MM_keepForm="":MM_keepBoth="":MM_keepNone=""

' dem String MM_keepURL die URL-Parameter hinzufügen
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

' dem String MM_keepForm die Formular-Parameter hinzufügen
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

' Formular- und URL-String erstellen und das führende '&' entfernen
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)

' eine Utility-Funktion zum Hinzufügen zusätzlicher Parameter zu diesen Strings
Function MM_joinChar(firstItem)
If (firstItem <> "") Then
MM_joinChar = "&"
Else
MM_joinChar = ""
End If
End Function
%> <%
' *** Zu Datensatz verschieben: Strings für erster, letzter, nächster und vorheriger setzen
links

MM_keepMove = MM_keepBoth
MM_moveParam = "index"

' falls die Seite einen wiederholten Bereich enthält, 'offset' von den verwalteten Parametern entfernen
If (MM_size > 0) Then
MM_moveParam = "offset"
If (MM_keepMove <> "") Then
params = Split(MM_keepMove, "&")
MM_keepMove = ""
For i = 0 To UBound(params)
nextItem = Left(params(i), InStr(params(i),"=") - 1)
If (StrComp(nextItem,MM_moveParam,1) <> 0) Then
MM_keepMove = MM_keepMove & "&" & params(i)
End If
Next
If (MM_keepMove <> "") Then
MM_keepMove = Right(MM_keepMove, Len(MM_keepMove) - 1)
End If
End If
End If

' Strings für das Verschieben zu Links setzen
If (MM_keepMove <> "") Then MM_keepMove = MM_keepMove & "&"
urlStr = Request.ServerVariables("URL") & "?" & MM_keepMove & MM_moveParam & "="
MM_moveFirst = urlStr & "0"
MM_moveLast = urlStr & "-1"
MM_moveNext = urlStr & Cstr(MM_offset + MM_size)
prev = MM_offset - MM_size
If (prev < 0) Then prev = 0
MM_movePrev = urlStr & Cstr(prev)
%>
<html>
<head>
<title>Catalog</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFCC" leftmargin="0" topmargin="0" marginwidth="0"
marginheight="0">
<table width="650" border="0" cellpadding="5" cellspacing="0">
<tr bgcolor="#000066">
<td width="15%" bgcolor="#CCCCFF">&nbsp;</td>
<td width="85%" align="center"><font face="Arial, Helvetica, sans-serif"
size="6" color="#FFFFFF">Produktkatalog</font></td>
</tr>
<tr>
<td width="15%" bgcolor="#CCCCFF" valign="top">
<p><b><font face="Arial, Helvetica, sans-serif"><a
href="javascript:history.back()">Go
Back</a></font></b></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</td>
<td width="85%" valign="top" bgcolor="#FFCC99">
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr valign="top" align="center">
<td height="304">
<table border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="46%" valign="middle" bgcolor="#FFFFFF"
align="center"><font face="Arial, Helvetica, sans-serif"><img
src="<%=(searchresults.Fields.Item("prodLgPic").Value)%>" width="250"
height="250"></font></td>
<td width="54%" bgcolor="#FFFF66"><font face="Arial, Helvetica,
sans-serif"><b><%=(searchresults.Fields.Item("prodName").Value)%></b><br>
<font size="-1">Artikel
#:<%=(searchresults.Fields.Item("prodID").Value)%></font><br>
Preis :<%=
FormatCurrency((searchresults.Fields.Item("prodPrice").Value), 2, -2, -2, -2)
%><br>
<br>
<br>
<br>
<% If Session("MM_Username")<>"" Then %>
<form name="frmAddtoCart" method="post"
action="<%=MM_editAction%>">
<input type="hidden" name="prodID"
value="<%=(searchresults.Fields.Item("prodID").Value)%>">
<input type="submit" name="Purchase" value="Add to Cart">
<input type="hidden" name="MM_insert" value="true">
</form>
<% End If %>
<% If Session("MM_Username")="" Then %>
<A HREF="login.asp">Log into the system</A> <% End If %>
</font></td>
</tr>
<tr>
<td colspan="2" valign="middle"
bgcolor="#FFFFFF"><%=(searchresults.Fields.Item("prodDesc").Value)%></td>
</tr>
</table>
<br>
<font face="Arial, Helvetica, sans-serif">Related Items:<br>
<%
While ((Repeat1__numRows <> 0) AND (NOT RelatedItems.EOF))
%><%=(RelatedItems.Fields.Item("prodName").Value)%><br>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
RelatedItems.MoveNext()
Wend
%> </font></td>
</tr>
</table>
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><font face="Arial, Helvetica, sans-serif"><A
HREF="<%=MM_movePrev%>">Vorheriger</A>
</font></td>
<td>
<div align="right"><font face="Arial, Helvetica, sans-serif"><A
HREF="<%=MM_moveNext%>">Nächster</A></font></div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

<%
RelatedItems.Close()
%> <%
rsCart.Close()
%> <%
searchresults.Close()
%>

D.8 Tag 20 - Artikel aus dem Einkaufswagen löschen (checkout.asp)

Das Löschen von Artikeln aus dem Einkaufswagen war eine weitere Herausforderung, weil das von UltraDev automatisch erstellte Verhalten nicht so funktioniert, wie wir uns das vorgestellt haben. Die Änderungen an dieser Seite (checkout.asp) beinhalten das Entfernen von UltraDev erzeugten Codes und der Notwendigkeit einer Serverumleitung.

<%@LANGUAGE="VBSCRIPT"%> <!--#include file="../Connections/connCatalog.asp" -->
<%
' *** Bearbeitungen: Variablen deklarieren

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

' Boolescher Wert für das Abbrechen der Bearbeitung
MM_abortEdit = false

' auszuführender Abfragestring
MM_editQuery = ""
%> <%
' *** Datensatz löschen: Variablen löschen

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

MM_editConnection = MM_connCatalog_STRING
MM_editTable = "tblCart"
MM_editColumn = "cartID"
MM_recordId = "" + Request.Form("MM_recordId") + ""
MM_editRedirectUrl = ""

' URL für die Weiterleitung setzen
' URL für die Weiterleitung setzen
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
%> <%
' *** Datensatz löschen: SQL-Löschanweisung erstellen und ausführen

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

' SQL-Löschanweisung erstellen
MM_editQuery = "delete from tblCart where cartID='" & Request("DeleteID") & "'"

If (Not MM_abortEdit) Then
' Löschen ausführen
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 rsCart__varUsername
rsCart__varUsername = "testuser"
if (Session("MM_Username") <> "") then rsCart__varUsername =
Session("MM_Username")
%> <%
Dim rsCartTotal__varUsername
rsCartTotal__varUsername = "testuser"
if (Session("MM_Username") <> "") then rsCartTotal__varUsername =
Session("MM_Username")
%> <%
set rsCart = Server.CreateObject("ADODB.Recordset")
rsCart.ActiveConnection = MM_connCatalog_STRING
rsCart.Source = "SELECT
tblCart.cartID,tblCart.prodID,tblProduct.prodName,tblProduct.ProdPrice FROM
tblCart,tblProduct WHERE tblCart.username='" + Replace(rsCart__varUsername, "'",
"''") + "' AND tblCart.prodID=tblProduct.prodID AND tblCart.orderID=''"
rsCart.CursorType = 0
rsCart.CursorLocation = 2
rsCart.LockType = 3
rsCart.Open()
rsCart_numRows = 0
%>
<%
set rsCartTotal = Server.CreateObject("ADODB.Recordset")
rsCartTotal.ActiveConnection = MM_connCatalog_STRING
rsCartTotal.Source = "SELECT sum(tblProduct.ProdPrice) FROM tblCart,tblProduct
WHERE tblCart.username='" + Replace(rsCartTotal__varUsername, "'", "''") + "' AND
tblCart.prodID=tblProduct.prodID AND tblCart.orderID=''"
rsCartTotal.CursorType = 0
rsCartTotal.CursorLocation = 2
rsCartTotal.LockType = 3
rsCartTotal.Open()
rsCartTotal_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
rsCart_numRows = rsCart_numRows + Repeat1__numRows
%>
<html>
<head>
<title>Catalog</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFCC" leftmargin="0" topmargin="0" marginwidth="0"
marginheight="0">
<table width="650" border="0" cellpadding="5" cellspacing="0">
<tr bgcolor="#000066">
<td width="15%" bgcolor="#CCCCFF">&nbsp;</td>
<td width="85%" align="center"><font face="Arial, Helvetica, sans-serif"
size="6" color="#FFFFFF">Shopping
Cart </font></td>
</tr>
<tr>
<td width="15%" bgcolor="#CCCCFF" valign="top">
<p><b><font face="Arial, Helvetica, sans-serif">Product
Categories:</font></b></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</td>
<td width="85%" valign="top" bgcolor="#FFCC99">
<table width="100%" border="0" cellspacing="0" cellpadding="50">
<tr valign="top" align="left">
<td height="304">
<form name="frmDeleteFromCart" method="post"
action="<%=MM_editAction%>">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td><font face="Arial, Helvetica, sans-serif"><b>Product
ID</b></font></td>
<td><font face="Arial, Helvetica,
sans-serif"><b>Name</b></font></td>
<td><font face="Arial, Helvetica,
sans-serif"><b>Price</b></font></td>
<td><font face="Arial, Helvetica,
sans-serif"><b>Selected</b></font></td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsCart.EOF))
%>
<tr>
<td><%=(rsCart.Fields.Item("prodID").Value)%></td>
<td><%=(rsCart.Fields.Item("prodName").Value)%></td>
<td><%= FormatCurrency((rsCart.Fields.Item("ProdPrice").Value),
-1, -2, -2, -2) %></td>
<td>
<input type="radio" name="DeleteID"
value="<%=(rsCart.Fields.Item("cartID").Value)%>">
</td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsCart.MoveNext()
Wend
%>
<tr>
<td>&nbsp;</td>
<td><b><font face="Arial, Helvetica,
sans-serif">Total:</font></b></td>
<td><%=
FormatCurrency((rsCartTotal.Fields.Item("sum(tblProduct.ProdPrice)").Value), -1,
-2, -2, -2) %></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp; </td>
<td>
<input type="submit" name="Submit" value="Delete Selected
Item">
</td>
</tr>
</table>
<input type="hidden" name="MM_delete" value="true">
</form>
<div align="center"><br>
<a href="javascript:history.back()"><font face="Arial, Helvetica,
sans-serif">Continue
Shopping</font></a><br>
<br>
<a href="checkout2.asp"><font face="Arial, Helvetica,
sans-serif">Go
To Check Out</font></a></div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<%
rsCart.Close()
%> <%
rsCartTotal.Close()
%>

D.9 Tag 20 - Auftragserteilung (checkout2.asp)

Die endgültige Auftragserteilung auf der E-Commerce-Site bedingt die Umformulierung des temporären Einkaufswagens, sodass er als fertig betrachtet wird. Dies ist ein einzigartiges Verhalten dieser Applikation und basiert nicht direkt auf einer bereits existierenden UltraDev-Verhaltensweise.

<%@LANGUAGE="VBSCRIPT"%> <!--#include file="../Connections/connCatalog.asp" -->
<%
' *** Bearbeitungen: Variablen deklarieren

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

' Boolescher Wert für das Abbrechen der Bearbeitung
MM_abortEdit = false

' auszuführender Abfragestring
MM_editQuery = ""
%> <%
' *** Datensatz einfügen: Variablen setzen

If (CStr(Request("MM_insert")) <> "") Then

MM_editConnection = MM_connCatalog_STRING
MM_editTable = "tblOrderInfo"
MM_editRedirectUrl = "finished.asp"
MM_fieldsStr =
"shipaddress1|value|shipaddress2|value|shipcity|value|shipstate|value|shipzip|
=>;value|billaddress1|value|billaddress2|value|billcity|value|billstate|
=>;value|billzip|value|paymethod|value|payaccount|value|payexpire|value"
MM_columnsStr =
"shipaddress1|',none,''|shipaddress2|',none,''|shipcity|',none,''|shipstate|
=>;',none,''|shipzip|',none,''|billaddress1|',none,''|billaddress2|
=>;',none,''|billcity|',none,''|billstate|',none,''|billzip|',none,''|
=>;paymethod|',none,''|payaccount|',none,''|payexpire|',none,''"

' Arrays MM_fields und MM_columns anlegen
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' Formularwerte setzen
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next

' URL für die Weiterleitung setzen
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
%> <%
' *** Datensatz einfügen: eine SQL-Einfügeanweisung erstellen und ausführen

If (CStr(Request("MM_insert")) <> "") Then

' die SQL-Einfügeanweisung erstellen
MM_tableValues = ""
MM_dbValues = ""
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),",")
Delim = MM_typeArray(0)
If (Delim = "none") Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none") Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none") Then EmptyVal = ""
If (FormVal = "") Then
FormVal = EmptyVal
Else
If (AltVal <> "") Then
FormVal = AltVal
ElseIf (Delim = "'") Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''") & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End if
MM_tableValues = MM_tableValues & MM_columns(i)
MM_dbValues = MM_dbValues & FormVal
Next
orderStr=Date()&"-"&Session("MM_Username")&"-"&Time()
MM_editQuery = "insert into " & MM_editTable & " (orderID," & MM_tableValues &
") values ('" & orderStr & "'," & MM_dbValues & ")"

If (Not MM_abortEdit) Then
' das Einfügen ausführen
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute

' Auftragselemente ändern, sodass sie dieselbe ID haben
Set FixOrder = Server.CreateObject("ADODB.Command")
FixOrder.ActiveConnection = MM_editConnection
FixOrder.CommandText = "UPDATE tblCart SET orderID='" & orderStr & "' WHERE
username='" & Session("MM_Username") & "' AND orderID=''"
FixOrder.Execute

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

End If
%>
<%
Dim rsCart__varUsername
rsCart__varUsername = "testuser"
if (Session("MM_Username") <> "") then rsCart__varUsername =
Session("MM_Username")
%> <%
Dim rsCartTotal__varUsername
rsCartTotal__varUsername = "testuser"
if (Session("MM_Username") <> "") then rsCartTotal__varUsername =
Session("MM_Username")
%> <%
Dim rsUserInfo__varUsername
rsUserInfo__varUsername = "testuser"
if (Session("MM_Username") <> "") then rsUserInfo__varUsername =
Session("MM_Username")
%> <%
set rsCart = Server.CreateObject("ADODB.Recordset")
rsCart.ActiveConnection = MM_connCatalog_STRING
rsCart.Source = "SELECT tblCart.prodID,tblProduct.prodName,tblProduct.ProdPrice
FROM tblCart,tblProduct WHERE tblCart.username='" + Replace(rsCart__varUsername,
"'", "''") + "' AND tblCart.prodID=tblProduct.prodID AND tblCart.orderID=''"
rsCart.CursorType = 0
rsCart.CursorLocation = 2
rsCart.LockType = 3
rsCart.Open()
rsCart_numRows = 0
%>
<%
set rsCartTotal = Server.CreateObject("ADODB.Recordset")
rsCartTotal.ActiveConnection = MM_connCatalog_STRING
rsCartTotal.Source = "SELECT sum(tblProduct.ProdPrice) FROM tblCart,tblProduct
WHERE tblCart.username='" + Replace(rsCartTotal__varUsername, "'", "''") + "' AND
tblCart.prodID=tblProduct.prodID AND tblCart.orderID=''"
rsCartTotal.CursorType = 0
rsCartTotal.CursorLocation = 2
rsCartTotal.LockType = 3
rsCartTotal.Open()
rsCartTotal_numRows = 0
%>
<%
set rsUserInfo = Server.CreateObject("ADODB.Recordset")
rsUserInfo.ActiveConnection = MM_connCatalog_STRING
rsUserInfo.Source = "SELECT * FROM tblUserInfo WHERE username='" +
Replace(rsUserInfo__varUsername, "'", "''") + "'"
rsUserInfo.CursorType = 0
rsUserInfo.CursorLocation = 2
rsUserInfo.LockType = 3
rsUserInfo.Open()
rsUserInfo_numRows = 0
%>
<%
set rsOrderInfo = Server.CreateObject("ADODB.Recordset")
rsOrderInfo.ActiveConnection = MM_connCatalog_STRING
rsOrderInfo.Source = "SELECT * FROM tblOrderInfo"
rsOrderInfo.CursorType = 0
rsOrderInfo.CursorLocation = 2
rsOrderInfo.LockType = 3
rsOrderInfo.Open()
rsOrderInfo_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
rsCart_numRows = rsCart_numRows + Repeat1__numRows
%>
<html>
<head>
<title>Catalog</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFCC" leftmargin="0" topmargin="0" marginwidth="0"
marginheight="0">
<table width="650" border="0" cellpadding="5" cellspacing="0">
<tr bgcolor="#000066">
<td width="15%" bgcolor="#CCCCFF">&nbsp;</td>
<td width="85%" align="center"><font face="Arial, Helvetica, sans-serif"
size="6" color="#FFFFFF">Einkaufswagen</font></td>
</tr>
<tr>
<td width="15%" bgcolor="#CCCCFF" valign="top">
<p><b><font face="Arial, Helvetica, sans-serif">Produktkategorien:</font></b></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</td>
<td width="85%" valign="top" bgcolor="#FFCC99">
<table width="100%" border="0" cellspacing="0" cellpadding="50">
<tr valign="top" align="left">
<td height="304">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td><font face="Arial, Helvetica, sans-serif"><b>Produkt-
ID</b></font></td>
<td><font face="Arial, Helvetica,
sans-serif"><b>Name</b></font></td>
<td><font face="Arial, Helvetica,
sans-serif"><b>Price</b></font></td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsCart.EOF))
%>
<tr>
<td><%=(rsCart.Fields.Item("prodID").Value)%></td>
<td><%=(rsCart.Fields.Item("prodName").Value)%></td>
<td><%= FormatCurrency((rsCart.Fields.Item("ProdPrice").Value),
2, -2, -2, -2) %></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsCart.MoveNext()
Wend
%>
<tr>
<td>&nbsp;</td>
<td><b><font face="Arial, Helvetica,
sans-serif">Total:</font></b></td>
<td><%=
FormatCurrency((rsCartTotal.Fields.Item("sum(tblProduct.ProdPrice)").Value), -1,
-2, -2, -2) %></td>
</tr>
</table>
<div align="center"><br>
<form ACTION="<%=MM_editAction%>" name="frmFinalOrder"
method="POST">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr align="center" bgcolor="#FFFFCC">
<td colspan="2"><b><font face="Arial, Helvetica,
sans-serif">Versandinformation
</font></b></td>
</tr>
<tr>
<td width="25%"><font face="Arial, Helvetica, sans-serif">
Adresse 1:</font></td>
<td width="75%">
<input type="text" name="shipaddress1" size="50"
value="<%=(rsUserInfo.Fields.Item("address1").Value)%>">
</td>
</tr>
<tr>
<td width="25%"><font face="Arial, Helvetica, sans-serif">
Adresse 2:</font></td>
<td width="75%">
<input type="text" name="shipaddress2" size="50"
value="<%=(rsUserInfo.Fields.Item("address2").Value)%>">
</td>
</tr>
<tr>
<td width="25%"><font face="Arial, Helvetica,
sans-serif">Stadt:</font></td>
<td width="75%">
<input type="text" name="shipcity"
value="<%=(rsUserInfo.Fields.Item("city").Value)%>">
</td>
</tr>
<tr>
<td width="25%"><font face="Arial, Helvetica,
sans-serif">Staat:</font></td>
<td width="75%">
<input type="text" name="shipstate"
value="<%=(rsUserInfo.Fields.Item("state").Value)%>">
</td>
</tr>
<tr>
<td width="25%">
<p><font face="Arial, Helvetica,
sans-serif">PLZ:</font></p>
</td>
<td width="75%">
<input type="text" name="shipzip"
value="<%=(rsUserInfo.Fields.Item("zip").Value)%>">
</td>
</tr>
<tr bgcolor="#FFFFCC">
<td colspan="2">
<div align="center"><b><font face="Arial, Helvetica,
sans-serif">Rechnungs-
Information </font></b></div>
</td>
</tr>
<tr>
<td width="25%"><font face="Arial, Helvetica,
sans-serif">Adresse
1:</font></td>
<td width="75%">
<input type="text" name="billaddress1" size="50"
value="<%=(rsUserInfo.Fields.Item("address1").Value)%>">
</td>
</tr>
<tr>
<td width="25%"><font face="Arial, Helvetica,
sans-serif">Adresse
2:</font></td>
<td width="75%">
<input type="text" name="billaddress2" size="50"
value="<%=(rsUserInfo.Fields.Item("address2").Value)%>">
</td>
</tr>
<tr>
<td width="25%"><font face="Arial, Helvetica,
sans-serif">Stadt:</font></td>
<td width="75%">
<input type="text" name="billcity"
value="<%=(rsUserInfo.Fields.Item("city").Value)%>">
</td>
</tr>
<tr>
<td width="25%"><font face="Arial, Helvetica,
sans-serif">Staat:</font></td>
<td width="75%">
<input type="text" name="billstate"
value="<%=(rsUserInfo.Fields.Item("state").Value)%>">
</td>
</tr>
<tr>
<td width="25%"><font face="Arial, Helvetica,
sans-serif">PKZ:</font></td>
<td width="75%">
<input type="text" name="billzip"
value="<%=(rsUserInfo.Fields.Item("zip").Value)%>">
</td>
</tr>
<tr>
<td width="25%">&nbsp;</td>
<td width="75%">&nbsp;</td>
</tr>
<tr>
<td width="25%"><font face="Arial, Helvetica,
sans-serif">Zahlungsmethode:</font></td>
<td width="75%">
<select name="paymethod">
<option selected>Mastercard</option>
<option>Visa</option>
</select>
</td>
</tr>
<tr>
<td width="25%"><font face="Arial, Helvetica,
sans-serif">Kontonummer:</font></td>
<td width="75%">
<input type="text" name="payaccount">
</td>
</tr>
<tr>
<td width="25%"><font face="Arial, Helvetica,
sans-serif">Ablaufdatum:</font></td>
<td width="75%">
<input type="text" name="payexpire">
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="submit" name="Submit" value="Auftrag senden">
</div>
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="true">
</form>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<%
rsCart.Close()
%> <%
rsCartTotal.Close()
%> <%
rsUserInfo.Close()
%> <%
rsOrderInfo.Close()
%>



vorheriges KapitelInhaltsverzeichnisStichwortverzeichnisFeedbackKapitelanfangnächstes Kapitel


© Markt+Technik Verlag, ein Imprint der Pearson Education Deutschland GmbH