|
<%
'Variabili globali
Dim form
Dim nome, cognome, telefono, emailaddress
Dim ntessera, autore, titolo, biblio
Dim collocazione, avviso, note
Call Main()
' ===================================
' ===== SUBROUTINES E FUNCTIONS =====
' ===================================
Sub Main
'------------------------------------------------
'Contiene la logica del sistema di prenotazione
'------------------------------------------------
Dim action
action = Request.Querystring("action")
If action="send" Then
Call AcquisisciInput(form)
Call InviaRichiesta()
Call Grazie()
ElseIf action="check" Then
Call AcquisisciInput(form)
If Len(nome)=0 Then
ErrMsg("E' necessario inserire il proprio nome!")
ElseIf Len(cognome)=0 Then
ErrMsg("E' necessario inserire il proprio cognome!")
ElseIf avviso="Telefonicamente" AND Len(telefono)=0 Then
ErrMsg("E' necessario inserire il numero di telefono!")
ElseIf avviso="Via E-Mail" AND chkEmail(emailaddress)<>0 Then
ErrMsg("L'indirizzo e-mail non è corretto!")
ElseIf Not chkNTessera(ntessera) Then
ErrMsg("Il numero di tessera non è corretto!")
ElseIf Len(titolo)=0 Then
ErrMsg("E' necessario inserire il titolo del libro da prenotare!")
ElseIf Len(autore)=0 Then
ErrMsg("E' necessario inserire l'autore del libro da prenotare!")
ElseIf Len(collocazione)=0 Then
ErrMsg("E' necessario inserire la collocazione del libro da prenotare!")
Else
Call Conferma()
End If
Else
Call VisualizzaForm()
End If
End Sub 'Main
%>
<%
Function ErrMsg(msg)
'------------------------------------------------
' Visualizza il messaggio di errore 'msg' e crea
' un pulsante per tornare alla pagina precedente
' per corregere i dati.
'------------------------------------------------
%>
<%
End Function
%>
<%
Sub VisualizzaForm()
%>
<%
End Sub
Sub AcquisisciInput(form)
'------------------------------------------------
'Acquisisce i dati dalla form
'------------------------------------------------
nome = Trim(Request.Form("nome"))
cognome = Trim(Request.Form("cognome"))
telefono = Trim(Request.Form("telefono"))
emailaddress = Trim(Request.Form("emailaddress"))
ntessera = Trim(Request.Form("ntessera"))
titolo = Trim(Request.Form("titolo"))
autore = Trim(Request.Form("autore"))
biblio = Request.Form("biblio")
collocazione = Trim(Request.Form("collocazione"))
avviso = Request.Form("avviso")
note = Request.Form("note")
End Sub
Sub Conferma()
'------------------------------------------------
' Visualizza il riepilogo dei dati inseriti
' nella form e chiede la conferma per l'invio
'------------------------------------------------
%>
<%
End Sub
Sub InviaRichiesta()
'------------------------------------------------
'Invia la mail di richiesta
'------------------------------------------------
Dim text
Dim objMail
text=text & ""
text=text & ""
text=text & ""
text=text & "Prenotazione Prestisto Interbibliotecario"
text=text & ""
text=text & ""
text=text & " " & _
"Prenotazione Prestito " & _
"" & _
"| Nome: | " & _
" " & nome & " | " & _
"| Cognome: | " & _
" " & cognome & " | " & _
"| Telefono: | " & _
" " & telefono & " | " & _
"| E-Mail: | " & _
" " & emailaddress & " | " & _
"| Tessera N°: | " & _
" " & ntessera & " | " & _
"| Titolo: | " & _
" " & titolo & " | " & _
"| Autore: | " & _
" " & autore & " | " & _
"| Biblioteca: | " & _
" " & biblio & " | " & _
"| Collocazione: | " & _
" " & collocazione & " | " & _
"| Avviso: | " & _
" " & avviso & " | " & _
"| Commenti: | " & _
" " & _
Replace(note,vbCrLf," ") & " | " & _
"| Data e Ora: | " & _
" " & _
fncFmtDate(Now(),"%d/%m/%Y - %H.%N.%S") & " | "
text=text & " "
text=text & ""
text=text & ""
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.From = "prenotazioni@bibliotecabussero.it"
objMail.To = "prenotazioni@bibliotecabussero.it"
objMail.Subject = "RICHIESTA PRESTITO INTERBIBLIOTECARIO"
objMail.BodyFormat = 0
objMail.MailFormat = 0
objMail.Body = text
objMail.Importance = 1
objMail.Send
Set objMail = Nothing
End Sub 'InviaRichiesta
%>
<%
Sub Grazie()
'------------------------------------------------
'Visualizza il messaggio di rigraziamento
'------------------------------------------------
%>
La richiesta è
stata inviata correttamente.
Sarai contattato dal bibliotecario non appena il libro sarà
disponibile.
Grazie per aver utilizzato questo servizio. |
Continua
<%
End Sub
%>
<%
Function chkNTessera(numero)
'------------------------------------------------
' Verifica la correttezza del numero di tessera
' - restituisce False se ERRATO
' - restituisce True se VALIDO
'------------------------------------------------
Dim i
chkNTessera = true
if Len(numero)=0 Then
chkNTessera = false
Else
For i=1 to Len(numero)
if Mid(numero,i,1)<"0" or Mid(numero,i,1)>"9" Then
chkNTessera = false
End If
next
End If
End Function
function chkEmail(theAddress)
' checks for a vaild email
' returns 1 for invalid addresses
' returns 0 for valid addresses
dim atCnt, i
chkEmail = 0
' chk length
if len(theAddress) < 5 then
' a@b.c should be the shortest an
' address could be
chkEmail = 1
' chk format
' has at least one "@"
elseif instr(theAddress,"@") = 0 then
chkEmail = 1
' has at least one "."
elseif instr(theAddress,".") = 0 then
chkEmail = 1
' has no more than 3 chars after last "."
elseif len(theAddress) - instrrev(theAddress,".") > 3 then
chkEmail = 1
' has no "_" after the "@"
elseif instr(theAddress,"_") <> 0 and _
instrrev(theAddress,"_") > instrrev(theAddress,"@") then
chkEmail = 1
else
' has only one "@"
atCnt = 0
for i = 1 to len(theAddress)
if mid(theAddress,i,1) = "@" then
atCnt = atCnt + 1
end if
next
if atCnt > 1 then
chkEmail = 1
end if
' chk each char for validity
for i = 1 to len(theAddress)
if not isnumeric(mid(theAddress,i,1)) and _
(lcase(mid(theAddress,i,1)) < "a" or _
lcase(mid(theAddress,i,1)) > "z") and _
mid(theAddress,i,1) <> "_" and _
mid(theAddress,i,1) <> "." and _
mid(theAddress,i,1) <> "@" and _
mid(theAddress,i,1) <> "-" then
chkEmail = 1
end if
next
end if
end function
Function fncGetDayOrdinal( _
byVal intDay _
)
' Accepts a day of the month as an integer and returns the
' appropriate suffix
Dim strOrd
Select Case intDay
Case 1, 21, 31
strOrd = "st"
Case 2, 22
strOrd = "nd"
Case 3, 23
strOrd = "rd"
Case Else
strOrd = "th"
End Select
fncGetDayOrdinal = strOrd
End Function ' fncGetDayOrdinal
Function fncFmtDate( _
byVal strDate, _
byRef strFormat _
)
' Accepts strDate as a valid date/time,
' strFormat as the output template.
' The function finds each item in the
' template and replaces it with the
' relevant information extracted from strDate
' Template items (example)
' %m Month as a decimal (02)
' %B Full month name (February)
' %b Abbreviated month name (Feb )
' %d Day of the month (23)
' %O Ordinal of day of month (eg st or rd or nd)
' %j Day of the year (54)
' %Y Year with century (1998)
' %y Year without century (98)
' %w Weekday as integer (0 is Sunday)
' %a Abbreviated day name (Fri)
' %A Weekday Name (Friday)
' %H Hour in 24 hour format (24)
' %h Hour in 12 hour format (12)
' %N Minute as an integer (01)
' %n Minute as optional if minute <> 0
' %S Second as an integer (55)
' %P AM/PM Indicator (PM)
On Error Resume Next
Dim intPosItem
Dim int12HourPart
Dim str24HourPart
Dim strMinutePart
Dim strSecondPart
Dim strAMPM
' Insert Month Numbers
strFormat = Replace(strFormat, "%m", _
DatePart("m", strDate), 1, -1, vbBinaryCompare)
' Insert non-Abbreviated Month Names
strFormat = Replace(strFormat, "%B", _
MonthName(DatePart("m", strDate), _
False), 1, -1, vbBinaryCompare)
' Insert Abbreviated Month Names
strFormat = Replace(strFormat, "%b", _
MonthName(DatePart("m", strDate), _
True), 1, -1, vbBinaryCompare)
' Insert Day Of Month
strFormat = Replace(strFormat, "%d", _
DatePart("d",strDate), 1, _
-1, vbBinaryCompare)
' Insert Day of Month Ordinal (eg st, th, or rd)
strFormat = Replace(strFormat, "%O", _
fncGetDayOrdinal(Day(strDate)), _
1, -1, vbBinaryCompare)
' Insert Day of Year
strFormat = Replace(strFormat, "%j", _
DatePart("y",strDate), 1, _
-1, vbBinaryCompare)
' Insert Long Year (4 digit)
strFormat = Replace(strFormat, "%Y", _
DatePart("yyyy",strDate), 1, _
-1, vbBinaryCompare)
' Insert Short Year (2 digit)
strFormat = Replace(strFormat, "%y", _
Right(DatePart("yyyy",strDate),2), _
1, -1, vbBinaryCompare)
' Insert Weekday as Integer (eg 0 = Sunday)
strFormat = Replace(strFormat, "%w", _
DatePart("w",strDate,1), 1, _
-1, vbBinaryCompare)
' Insert Abbreviated Weekday Name (eg Sun)
strFormat = Replace(strFormat, "%a", _
WeekDayName(DatePart("w",strDate,1),True), 1, _
-1, vbBinaryCompare)
' Insert non-Abbreviated Weekday Name
strFormat = Replace(strFormat, "%A", _
WeekDayName(DatePart("w",strDate,1),False), 1, _
-1, vbBinaryCompare)
' Insert Hour in 24hr format
str24HourPart = DatePart("h",strDate)
If Len(str24HourPart) < 2 then str24HourPart = "0" & _
str24HourPart
strFormat = Replace(strFormat, "%H", str24HourPart, 1, _
-1, vbBinaryCompare)
' Insert Hour in 12hr format
int12HourPart = DatePart("h",strDate) Mod 12
If int12HourPart = 0 then int12HourPart = 12
strFormat = Replace(strFormat, "%h", int12HourPart, 1, _
-1, vbBinaryCompare)
' Insert Minutes
strMinutePart = DatePart("n",strDate)
If Len(strMinutePart) < 2 then _
strMinutePart = "0" & strMinutePart
strFormat = Replace(strFormat, "%N", strMinutePart, _
1, -1, vbBinaryCompare)
' Insert Optional Minutes
If CInt(strMinutePart) = 0 then
strFormat = Replace(strFormat, "%n", "", 1, _
-1, vbBinaryCompare)
Else
If CInt(strMinutePart) < 10 then _
strMinutePart = "0" & strMinutePart
strMinutePart = ":" & strMinutePart
strFormat = Replace(strFormat, "%n", strMinutePart, _
1, -1, vbBinaryCompare)
End if
' Insert Seconds
strSecondPart = DatePart("s",strDate)
If Len(strSecondPart) < 2 then _
strSecondPart = "0" & strSecondPart
strFormat = Replace(strFormat, "%S", strSecondPart, 1, _
-1, vbBinaryCompare)
' Insert AM/PM indicator
If DatePart("h",strDate) >= 12 then
strAMPM = "PM"
Else
strAMPM = "AM"
End If
strFormat = Replace(strFormat, "%P", strAMPM, 1, _
-1, vbBinaryCompare)
fncFmtDate = strFormat
'If there is an error output its value
If err.Number <> 0 then
Response.Clear
Response.Write "ERROR " & err.Number & _
": fmcFmtDate - " & err.Description
Response.Flush
Response.End
End if
End Function ' fncFmtDate
%>
|