<% '----------------------------------------------------------------------------------------------------------------- ' Libreria VB SCRIPT Mario Fenocchio ' Location D:\INETPUB-B\WWROOT 'Autore MARIO FENOCCHIO ' COPIARE nei vari siti ' COPIARE F:\INEPUB-B\wwwroot ' Tutte le funzioni devono iniziare con LS_ ' Tieni funzioni e routines in ordine albabetico '__________ APPUNTI ____________________________________________ ' Server.ScriptTimeout = sss Durata massima esecuzione di una pagina ASP é 90 secondi, 'Response.CacheControl = "private" oppure "public" , private vieta al proxy di memorizzare la pagina ' rende eventuale testo non selezionabile né copiabile. ' immagine con copiabile '_____________________________________________________________ ' Costanti globali di servizio Const GL_crt_somma = "∑" Const GL_crt_TM = "™" Const GL_crt_diverso = "≠" Const GL_crt_minUg ="≤" Const GL_crt_magug = "≥" Const GL_crt_euro = "€" Const GL_crt_copyright = "®" '_____________________________________________________________ SUB RW (byval stringa) Response.write(stringa) END SUB '---------------------------------------------------------------------------------------------------- SUB LS_RWS (byval stringa, byval fontsize) if fontsize <> "" then Response.write("") Response.write(stringa) Response.write("") else Response.write(stringa) end if END SUB '---------------------------------------------------------------------------------------------------- FUNCTION LS_ADDHTTP(byval stringa) 'Test=DA FARE dim strout If Ucase(Left(stringa,8)) = "HTTPS://" then strout = stringa end if If Ucase(Left(stringa,7)) = "HTTP://" then strout = stringa end if if strout = "" then strout = "http://" & stringa end if LS_AddHttp = strout END FUNCTION 'LS_ADDHTTP '---------------------------------------------------------------------------------------------------------------------------- FUNCTION LS_ALL_SERVER_VARIABLES() Response.write("") dim item for each item in Request.ServerVariables Response.Write("") next Response.write("
"&item & "" & Request.ServerVariables(item) & "
") Response.write("
") END FUNCTION '------------------------------------------------------------------------------------------------------------ FUNCTION LS_ALL_COOKIES() Dim x,y %> <% for each x in Request.Cookies %> <% if Request.Cookies(x).HasKeys then %> <% for each y in Request.Cookies(x) %> <% next %> <% else %> <% end if %> <% next %>
Request.Cookies
<% =x %> <% =y %> <% =Request.Cookies(x)(y) %>
<% =x %> <% =Request.Cookies(x) %>
<% END FUNCTION '---------------------------------------------------------------------------------------------------- FUNCTION LS_ALL_SESSION() DIM x %> <% for each x in Session.Contents %> <% next %>
Session.Contents
<% =Session.Contents(x) %>
<% END FUNCTION '------------------------------------------------------------------------------------------------ FUNCTION LS_ARABICTOROMAN(ByVal Value) Dim iPos, sBuffer, iReference, sLowChar, sMidChar, sHighChar sBuffer = String(Value \ 1000, "M") Value = Value Mod 1000 iReference = 100 Do Until iReference = 0 If iReference = 100 Then sHighChar = "M" sMidChar = "D" sLowChar = "C" ElseIf iReference = 10 Then sHighChar = "C" sMidChar = "L" sLowChar = "X" Else sHighChar = "X" sMidChar = "V" sLowChar = "I" End If iPos = Value \ iReference If (iPos > 0) And (iPos < 4) Then sBuffer = sBuffer & string(iPos, sLowChar) ElseIf iPos = 4 Then sBuffer = sBuffer & sLowChar & sMidChar ElseIf iPos = 5 Then sBuffer = sBuffer & sMidChar ElseIf (iPos > 5) And (iPos < 9) Then sBuffer = sBuffer & sMidChar & string(iPos - 5, sLowChar) ElseIf iPos = 9 Then sBuffer = sBuffer & sLowChar & sHighChar End If Value = Value - iReference * iPos iReference = iReference \ 10 Loop LS_ARABICTOROMAN = sBuffer END FUNCTION '------------------------------------------------------------------------------------------------ FUNCTION LS_BARRE422(byval stringa) ' Aggiunge le barre dopo 4 dopo 2 dopo 2 crt dim strout strout = mid(stringa,1,4) & "/" & mid(stringa,5,2) & "/" & mid(stringa,7,2) LS_BARRE422 = strout END FUNCTION '------------------------------------------------------------------------------------------------ FUNCTION LS_BARRE224 (byval stringa) ' Aggiunge le barre dopo 2 dopo 2 dopo 4 crt dim strout strout = mid(stringa,1,2) & "/" & mid(stringa,3,2) & "/" & mid(stringa,5,4) LS_BARRE224 = strout END FUNCTION '------------------------------------------------------------------------------------------------------------------- Private FUNCTION LS_DATE_VALID (FieldName , lngDay, lngMonth, lngYear) '' FUNCTION to Validate a Date '' This FUNCTION will return a string '' If the string is blank "" -- Valid date '' If the string is NOT blank -- date is invalid and the string will contain an error message. '' Parameters: '' FieldName -- '' The Field name of the date you are validating (It will be included in the Error Message if date is invalid) '' If passed a blank string "" It will generate generic error messages, if the date is invalid '' lngDay -- The Day value as integer '' lngMonth -- The Month value as integer '' lngYear -- The Year value as intger (four digit format) On Error Resume Next If StrComp(FieldName, "" , 1) <> 0 Then FieldName = " of " & FieldName End If If lngYear < 1 Then LS_DATE_VALID = "The Year" & FieldName & " is invalid" elseIf lngDay > 31 OR lngDay < 1 Then LS_DATE_VALID = "The Day" & FieldName & " should be between 1 and 31" elseif lngMonth > 12 OR lngMonth < 1 Then LS_DATE_VALID = "The Month" & FieldName & " should be between 1 and 12" elseif lngDay > 30 and _ ( lngMonth = 4 or lngMonth = 6 or lngMonth = 9 or lngMonth = 11) Then LS_DATE_VALID = "The Month" & FieldName & " doesn't have a 31st day" elseif lngDay > 29 and _ ( lngYear mod 4 ) = 0 and _ lngMonth = 2 then LS_DATE_VALID = "The Year" & FieldName & " only has 29 days in February" elseif lngDay > 28 and _ Not ( lngYear mod 4 ) = 0 and _ lngMonth = 2 then LS_DATE_VALID = "The Month (February)" & FieldName & " only has 28 days" Else LS_DATE_VALID = "" End If If Err.number <> 0 Then LS_DATE_VALID = "Internal Error During Validating the Date" Exit FUNCTION End If END FUNCTION 'LS_DATE_VALID '------------------------------------------------------------------------------------------------------------------ FUNCTION LS_DO_COMBO1_ALL (byval my_conn, byval fTableName, byval fDisplayField, byval fSelectValue, byval fName, byval swall) dim inum, strSql, rsdrop 'Un campo solo sia chiave che dati. ' Usata in IPMSV5 strSql = "SELECT " & fDisplayField & " FROM " & fTableName & " order by " & fDisplayField Set rsdrop = Server.CreateObject("ADODB.Recordset") rsdrop.Open strSql, my_Conn Response.Write "" & vbCrLf rsdrop.Close set rsdrop = nothing LS_Do_Combo1_ALL = inum END FUNCTION 'LS_DO_COMBO1_ALL '------------------------------------------------------------------------------------------------------------ FUNCTION LS_DO_COMBO2 (byval my_conn, byval fTableName, byval fKeyField, byval fDisplayField, byval fSelectValue, byval fName, byval fallcod, byval falldesc) dim inum, strSql, rsdrop 'Due campi, strSql = "SELECT " & fKeyField & ", " & fDisplayField & " FROM " & fTableName & " order by " & fDisplayField & " " Set rsdrop = Server.CreateObject("ADODB.Recordset") rsdrop.Open strSql, my_Conn Response.Write "" & vbCrLf rsdrop.Close set rsdrop = nothing LS_DO_COMBO2 = inum END FUNCTION 'LS_DO_COMBO2 '------------------------------------------------------------------------------------------ '''' FUNCTION LS_DO_COMBO3(byval my_conn, byval fTableName, byval fDisplayField, byval fSelectValue, byval fName,byval fAll) ''======> Usare LS_DO_COMBO1_ALL ''======> Modifica del 20/6/2007 '_______________________________________________________________ FUNCTION LS_DISPERR() 'Test= NON ESEGUITO 'Visualizza errori DA PROVARE On Error Resume Next LS_Disperr= ("Errore " & Err.Number &" - " & Err.Description) END FUNCTION '______________________________________________________________ Sub LS_Disp_Table (byval my_conn, byval fTableName, byval fKeyField, byval fKeyValue, byval fOrderby) ' Usata in IPMSV5. Funziona se campo in fKeyField é numerico dim rip, rss, strSql strSql = "SELECT * FROM " & fTableName strSql=strSql &" where " & fKeyField & " = " & fKeyValue strSql=strSql &" order by " & fOrderby Set rss = Server.CreateObject("ADODB.Recordset") rss.Open strSql, my_Conn %>

Table:<% =fTableName %>

<% if rss.EOF or rss.BOF then Response.Write "Nessun elemento trovato" & vbCrLf else %> <% do until rss.EOF %> <%for rip = 0 to rss.fields.count-1%> <% if trim(rss.fields(rip).value) = "" or trim(rss.fields(rip).value) = "0" or trim(rss.fields(rip).value & "") = "" then %> <% else %> <% end if %> <%next%>
<%=rss.fields(rip).name%>  <%=rss.fields(rip).value%> 
<% rss.movenext loop end if Response.Write vbCrLf rss.Close set rss = nothing END SUB '______________________________________________________________ SUB LS_Disp_Square_Alfnum (byval my_conn, byval fTableName, byval fKeyField, byval fKeyValue, byval fOrderby) ' Usata in HJS Funziona se campo in fKeyField é alfanumerico dim rip, rss, strSql strSql = "SELECT * FROM " & fTableName & " where " & fKeyField & " = '" & fKeyValue & "'" strSql=strSql & " order by " & fOrderby Set rss = Server.CreateObject("ADODB.Recordset") rss.Open strSql, my_Conn if rss.EOF or rss.BOF then Response.Write "Nessun elemento trovato" & vbCrLf else %> <%for rip = 0 to rss.fields.count-1%> <%next%> <% do until rss.EOF %> <%for rip = 0 to rss.fields.count-1%> <%next%> <% rss.movenext %> <% loop %> <% end if %>
<%=rss.fields(rip).name%> 
<%=rss.fields(rip).value%> 
<% Response.Write vbCrLf rss.Close set rss = nothing END SUB '________________________________________________________________________ FUNCTION LS_DoExecute(byval strFilePath) ' The LS_DoExecute function opens an ASP file and execute its contents ' (instead of using an Include or Server.Execute()). ' ' How to call: Call LS_DoExecute(Server.MapPath("aspfile.asp")) ' Dim fso, stream, strFileText Set fso = Server.CreateObject("Scripting.FileSystemObject") Set stream = fso.OpenTextFile(strFilePath) strFileText = stream.ReadAll() stream.Close Set stream = Nothing Set fso = Nothing '--- Remove open and close ASP tags strFileText = Replace(strFileText, "<" & "%", "") strFileText = Replace(strFileText, "%" & ">", "") Execute strFileText END FUNCTION '________________________________________________________________________ FUNCTION LS_DoubleNum (fNum) if fNum > 9 then LS_DoubleNum = fNum else LS_DoubleNum = "0" & fNum end if END FUNCTION '--------------------------------------------------------------------------- FUNCTION LS_DATA (byval dtinp, byval strDateType) ' DTINP deve essere una data ' stessa funzione di LS_DT ma senza ora min sec dim stringa stringa = left(LS_DT(dtinp,strDateType),10) LS_DATA = stringa END FUNCTION 'LS_DATA '-------------------------------------------------------------------------------- FUNCTION LS_DATAX (byval dtinp, byval strDateType) ' l'input deve essere una data ' esempio Response.write(LS_DATAX (Now,"ymd') Dim fDateTime fDateTime = year(dtinp) & LS_DoubleNum(Month(dtinp)) & LS_DoubleNum(Day(dtinp)) & LS_DoubleNum(Hour(dtinp)) & LS_DoubleNum(Minute(dtinp)) & LS_DoubleNum(Second(dtinp)) & "" if dtinp = "" then exit FUNCTION end if select case strDateType case "dmy" LS_DATAX = Mid(fDateTime,7,2) & Mid(fDateTime,5,2) & Mid(fDateTime,1,4) case "mdy" LS_DATAX = Mid(fDateTime,5,2) & Mid(fDateTime,7,2) & Mid(fDateTime,1,4) case "ymd" LS_DATAX = Mid(fDateTime,1,4) & Mid(fDateTime,5,2) & Mid(fDateTime,7,2) case "ydm" LS_DATAX = Mid(fDateTime,1,4) & Mid(fDateTime,7,2) & Mid(fDateTime,5,2) case "dmmy" LS_DATAX = Mid(fDateTime,7,2) & LS_MESE3_IT(Mid(fDateTime,5,2)) & Mid(fDateTime,1,4) case "mmdy" LS_DATAX = LS_MESE3_IT(Mid(fDateTime,5,2)) & Mid(fDateTime,7,2) & Mid(fDateTime,1,4) case "ymmd" LS_DATAX = Mid(fDateTime,1,4) & LS_MESE3_IT(Mid(fDateTime,5,2)) & Mid(fDateTime,7,2) case "ydmm" LS_DATAX = Mid(fDateTime,1,4) & Mid(fDateTime,7,2) & LS_MESE3_IT(Mid(fDateTime,5,2)) case "dmmmy" LS_DATAX = Mid(fDateTime,7,2) & LS_MESE_IT(Mid(fDateTime,5,2)) & Mid(fDateTime,1,4) case "mmmdy" LS_DATAX = LS_MESE(Mid(fDateTime,5,2)) & Mid(fDateTime,7,2) & Mid(fDateTime,1,4) case "ymmmd" LS_DATAX = Mid(fDateTime,1,4) & LS_MESE(Mid(fDateTime,5,2)) & Mid(fDateTime,7,2) case "ydmmm" LS_DATAX = Mid(fDateTime,1,4) & Mid(fDateTime,7,2) & LS_MESE(Mid(fDateTime,5,2)) case else LS_DATAX = LS_DoubleNum(Mid(fDateTime,5,2)) & Mid(fDateTime,7,2) & Mid(fDateTime,1,4) end select LS_DATAX = LS_DATAX & " " & _ Mid(fDateTime, 9,2) & ":" & _ Mid(fDateTime, 11,2) & ":" & _ Mid(fDateTime, 13,2) & " " END FUNCTION 'LS_DATAX '----------------------------------------------------------------------------------------------- FUNCTION LS_DT (byval dtinp, byval strDateType) ' l'input deve essere una data ' esempio Response.write(LS_DT(Now,"ymd') Dim fDateTime fDateTime = year(dtinp) & LS_DoubleNum(Month(dtinp)) & LS_DoubleNum(Day(dtinp)) & LS_DoubleNum(Hour(dtinp)) & LS_DoubleNum(Minute(dtinp)) & LS_DoubleNum(Second(dtinp)) & "" if dtinp = "" then exit FUNCTION end if select case strDateType case "dmy" LS_DT = Mid(fDateTime,7,2) & "/" & Mid(fDateTime,5,2) & "/" & Mid(fDateTime,1,4) case "mdy" LS_DT = Mid(fDateTime,5,2) & "/" & Mid(fDateTime,7,2) & "/" & Mid(fDateTime,1,4) case "ymd" LS_DT = Mid(fDateTime,1,4) & "/" & Mid(fDateTime,5,2) & "/" & Mid(fDateTime,7,2) case "ydm" LS_DT =Mid(fDateTime,1,4) & "/" & Mid(fDateTime,7,2) & "/" & Mid(fDateTime,5,2) case "dmmy" LS_DT = Mid(fDateTime,7,2) & " " & LS_MESE3_IT(Mid(fDateTime,5,2)) & " " & _ Mid(fDateTime,1,4) case "mmdy" LS_MESE3_IT(Mid(fDateTime,5,2)) & " " & Mid(fDateTime,7,2) & " " & Mid(fDateTime,1,4) case "ymmd" LS_DT = Mid(fDateTime,1,4) & " " & LS_MESE3_IT(Mid(fDateTime,5,2)) & " " & Mid(fDateTime,7,2) case "ydmm" LS_DT = Mid(fDateTime,1,4) & " " & Mid(fDateTime,7,2) & " " & LS_MESE3_IT(Mid(fDateTime,5,2)) case "dmmmy" LS_DT = Mid(fDateTime,7,2) & " " & LS_MESE_IT(Mid(fDateTime,5,2)) & " " & Mid(fDateTime,1,4) case "mmmdy" LS_DT = LS_MESE(Mid(fDateTime,5,2)) & " " & Mid(fDateTime,7,2) & " " & Mid(fDateTime,1,4) case "ymmmd" LS_DT = Mid(fDateTime,1,4) & " " & LS_MESE(Mid(fDateTime,5,2)) & Mid(fDateTime,7,2) case "ydmmm" LS_DT = Mid(fDateTime,1,4) & " " & Mid(fDateTime,7,2) & " " & LS_MESE(Mid(fDateTime,5,2)) case else LS_DT = LS_DoubleNum(Mid(fDateTime,5,2)) & "/" & Mid(fDateTime,7,2) & "/" & Mid(fDateTime,1,4) end select LS_DT = LS_DT & " " & _ Mid(fDateTime, 9,2) & ":" & _ Mid(fDateTime, 11,2) & ":" & _ Mid(fDateTime, 13,2) & " " END FUNCTION '------------------------------------------------------------------------------------------------------ FUNCTION LS_FRASE(byval frase, byval lunghMax) dim estrattoBreve ,ultimoCarattere , contatore, dimMax dimMax = LEN(frase) IF dimMax > lunghMax then estrattoBreve = "" ultimoCarattere = "a" contatore = lunghMax while ultimoCarattere <> " " estrattoBreve = LEFT(frase,contatore) ultimoCarattere = RIGHT(estrattoBreve,1) contatore = contatore - 1 if contatore = 0 then ultimoCarattere = " " end if wend if contatore <> 0 then estrattoBreve = LEFT(frase,contatore) & "..." else estrattoBreve = LEFT(frase,lunghMax) end if ELSE estrattoBreve = frase END IF LS_FRASE = estrattoBreve END FUNCTION '------------------------------------------------------------------------------------------------------ FUNCTION LS_GET_FILE(byval nomefile) Dim stringa,FS,F Set fs=Server.CreateObject("Scripting.FileSystemObject") Set f=fs.OpenTextFile(Server.MapPath(nomefile), 1) stringa=(f.ReadAll) f.Close Set f=Nothing Set fs=Nothing LS_GET_FILE = stringa END FUNCTION 'LS_GET_FILE '--------------------------------------------------------------------------------- FUNCTION LS_GETLASTDAY(byval intMonthNum, byval intYearNum) Dim dNextStart If CInt(intMonthNum) = 12 Then dNextStart = "1/1/" & intYearNum Else dNextStart = LDate("1", intMonthNum + 1, intYearNum, binternational) End If LS_GETLASTDAY = Day(DateValue(dNextStart) - 1) END FUNCTION '------------------------------------------------------------------------------------------------ FUNCTION LS_GET_LDAP1(byval userid, byval campo) Const ADS_SCOPE_SUBTREE = 2 dim objconnection, objcommand, objRecordSet, daLDAP, risultato daLDAP = " from 'LDAP://" & GL_LDAP_SERVER &"' " Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConnection objCommand.CommandText = "Select sAMAccountname," & campo & daLDAP & "where sAMAccountname='" & userid & "' " objCommand.Properties("Page Size") = 1000 objCommand.Properties("Timeout") = 30 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.Properties("Cache Results") = False Set objRecordSet = objCommand.Execute risultato = "" Do Until objRecordSet.EOF risultato = objRecordSet(campo) objRecordSet.MoveNext Loop LS_GET_LDAP1 = risultato END FUNCTION '------------------------------------------------------------------------------------------------ FUNCTION LS_GIORNO(byval datain) dim giorno Select case weekday(datain) case 1 : giorno = "Domenica" case 2 : giorno = "Lunedì" case 3 : giorno = "Martedì" case 4 : giorno = "Mercoledì" case 5 : giorno = "Giovedì" case 6 : giorno = "Venerdì" case 7 : giorno = "Sabato" case else: giorno ="???" End select LS_GIORNO = giorno END FUNCTION '---------------------------------------------------------------------------- FUNCTION LS_GIORNO3(byval datain) dim giorno giorno = left(LS_GIORNO(datain),3) LS_GIORNO3 = giorno END FUNCTION '------------------------------------------------------------------------------------------------ FUNCTION LS_GIORNI_OGGI(byval data) DIM giorni ' Restituisce il numero dei giorni da una data ad oggi giorni = Datediff("d",now(),data) LS_GIORNI_OGGI = giorni END FUNCTION '------------------------------------------------------------------------------------------------ SUB LS_GOOGLE_MAP(byval ind, byval cap, byval cit, byval pro) dim stringa const piu = "+" stringa = lcase(ind) stringa = replace(stringa,"str.","strada ") stringa = replace(stringa,"borg.","borgata ") RW("Map") END SUB '------------------------------------------------------------------------------------------------ FUNCTION LS_IsValidExtension(byval sFilename, byval sValidExtensions) ' Given a filename and comma separated list of valid extensions this ' function checks that the filename has an extension that appears ' in the valid list dim iPos, sExt, aExt, iIndex if len(trim(sValidExtensions)) = 0 then LS_IsValidExtension = true exit function end if sFilename = Trim(sFilename) for iPos = len(sFilename) to 1 step -1 If Strcomp(Mid(sFilename, iPos, 1), ".") = 0 Then sExt = mid(sFilename, iPos+1) aExt = split(sValidExtensions, ",") for iIndex = lbound(aExt) to ubound(aExt) if strcomp(trim(aExt(iIndex)), sExt, 1) = 0 then LS_IsValidExtension = true exit function end if next end if next LS_IsValidExtension = false END FUNCTION '------------------------------------------------------------------------------------------------ FUNCTION LS_REMOVEHTMLTAG (byval txt) ' Rimuove tutti i tag dal testo Set objRE = CreateObject("VBScript.RegExp") objRE.Pattern = "\<[^\>]*\>" objRE.Global = true objRE.IgnoreCase = true LS_RemoveHtmlTag = objRE.Replace(txt,"") END FUNCTION 'LS_REMOVEHTMLTAG '------------------------------------------------------------------------------------------------ FUNCTION LS_REMOVETAGS (byval stringa) 'Es: Response.Write(LS_RemoveTags("
Prova
")) restituisce 'Prova' dim tmptxt tmptxt = stringa if IsNull(tmptxt) then exit function 'esci x stringa nulla (che è diverso da stringa di lunghezza 0) end if dim i, pos1, pos2 DO 'inzia il ciclo di ricerca... pos1 = Instr(tmptxt, "<") 'cerca il prossimo inizio di tag if pos1=0 then exit do 'non trovato esci dal ciclo di ricerca (non ci sono più tag da eliminare) else 'se lo trovi, cerca il simbolo di chiusura del tag pos2 = Instr(pos1, tmptxt, ">") if pos2=0 then exit do 'se non lo trovi esci dal ciclo di ricerca else tmptxt = Left(tmptxt, pos1-1)&Mid(tmptxt, pos2+1) 'elimina tag determinato da pos1 e pos2 end if end if LOOP LS_REMOVETAGS = tmptxt 'restituisci il testo "depurato" dai tag HTML END FUNCTION 'LS_REMOVETAGS '------------------------------------------------------------------------------------------------ FUNCTION LS_RIGHTNAME(byval stringa) ' Estrae l'ultimo nome a destra delimitato da / o da \ dim crts if stringa <> "" then stringa=Replace(stringa,"/","\") end if if stringa <> "" then if InStrRev(stringa ,"\") > 0 then crts = Right(stringa, (Len(stringa) - InStrRev(stringa, "\"))) else crts = stringa end if end if LS_RIGHTNAME = crts END FUNCTION '----------------------------------------------------------------------------------------------------------- FUNCTION LS_SENZAAPICI (byval stringa) DIM ctrs if stringa = "" then ctrs = "" else ctrs = stringa ctrs=Replace(ctrs,"A'","Á") ctrs=Replace(ctrs,"E'","É") ctrs=Replace(ctrs,"I'","Í") ctrs=Replace(ctrs,"O'","Ó") ctrs=Replace(ctrs,"U'","Ú") ctrs=Replace(ctrs,"a'","à") ctrs=Replace(ctrs,"e'","é") ctrs=Replace(ctrs,"i'","ì") ctrs=Replace(ctrs,"o'","ò") ctrs=Replace(ctrs,"u'","ù") if ctrs <> "" then ctrs= Replace(ctrs, "'", "") end if if ctrs <> "" then ctrs= Replace(ctrs, """", "") end if end if LS_SENZAAPICI = ctrs END FUNCTION 'LS_SENZAAPICI '------------------------------------------------------------------------------------------------ SUB LS_SETTIMEOUT(byval millisecondi) ' Imposta durata massima di una transazione ' Durata massima di default esecuzione di una pagina ASP é 90 secondi, Server.ScriptTimeout = millisecondi END SUB '------------------------------------------------------------------------------------------------ FUNCTION LS_SortArray(values(), intSortCol, sSort_Dir) ' Ordina una tabella ' Da testare xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ! xxx ' ' values() la tabella ' IntSortCol il numero colonna su cui ordinare ' sSort_Dir a=Ascending d=Descending Dim i , j , value , value_j , min, max, temp, datatype, intComp dim intA, intCheckIndex, strDirection strDirection = lcase(Left(sSort_Dir, 1)) On Error Resume next min = lbound(values,2) max = ubound(values,2) '--- check to see what direction you want to sort. if strDirection = "d" then intComp = -1 else intComp = 1 end if if intSortCol < 0 or intSortCol > ubound(values,1) then arraysort = values exit FUNCTION end if '--- find the first item which has valid data in it to sort intCheckIndex = min while len(trim(values(intSortCol,intCheckIndex))) = 0 and intCheckIndex < ubound(values,2) intCheckIndex = intCheckIndex + 1 wend if isDate(trim(values(intSortCol,intCheckIndex))) then datatype = 1 else if isNumeric(trim(values(intSortCol,intCheckIndex))) then datatype = 2 else datatype = 0 end if end if For i = min To max - 1 value = values(intSortCol,i) value_j = i For j = i + 1 To max select case datatype case 0 '--- See if values(j) is smaller. works with strings now. If strComp(values(intSortCol,j),value,vbTextCompare) = intComp Then '--- Save the new smallest value. value = values(intSortCol,j) value_j = j End If case 1 if intComp = -1 then if DateDiff("s",values(intSortCol,j),value) > 0 then '--- Save the new smallest value. value = values(intSortCol,j) value_j = j end if else if DateDiff("s",values(intSortCol,j),value) < 0 then '--- Save the new smallest value. value = values(intSortCol,j) value_j = j end if end if case 2 if intComp = -1 then if cdbl(values(intSortCol,j)) < cdbl(value) then '--- Save the new smallest value. value = values(intSortCol,j) value_j = j end if else if cdbl(values(intSortCol,j)) > cdbl(value) then '--- Save the new smallest value. value = values(intSortCol,j) value_j = j end if end if end select Next 'j If value_j <> i Then '--- Swap items i and value_j. for intA = 0 to ubound(values,1) temp = values(intA,value_j) values(intA,value_j) = values(intA,i) values(intA,i) = temp next '--- intA End If Next 'i LS_SortArray = values END FUNCTION '------------------------------------------------------------------------------------------------------- FUNCTION LS_STR_TO_DATE (byval instr, byval intype, byval ottype) ' instr e intype sono stringhe la funz restituisce una data ' esempio "19510731" "yyyymmdd" "dmy" restituisce 31/7/1951 dim ladata, alfa , beta, ladataot ladata = now() ladataot = now() select case intype case "yyyymmdd" alfa = mid(instr,7,2) & mid(instr,5,2) & mid(instr,1,4) beta = LS_BARRE224(alfa) ladata = CDate(beta) 'vuole in inp gg/mm/aaaa ladataot = LS_DATA(ladata,ottype) case "mmddyyyy" alfa = mid(instr,3,2) & mid(instr,1,2) & mid(instr,5,4) beta = LS_BARRE224(alfa) ladata = CDate(beta) 'vuole in inp gg/mm/aaaa ladataot = LS_DATA(ladata,ottype) case "ggmmyyyy" beta = LS_BARRE224(instr) ladata = CDate(beta) 'vuole in inp gg/mm/aaaa ladataot = LS_DATA(ladata,ottype) end select LS_STR_TO_DATE = ladataot END FUNCTION 'LS_STR_TO_DATE '_____________________________________________________________________________ FUNCTION LS_EuroInLire (byval euro) 'Restituisce il valore in lire. FUNCTION sorella di LS_LireInEuro Dim ris ris = FormatNumber((Euro * 1936.27), 2,,,-1) 'FormatNumber(Expression [,NumDigitsAfterDecimal [,IncludeLeadingDigit ' [,UseParensForNegativeNumbers '[,GroupDigits]]]]) LS_EuroInLire = ris END FUNCTION 'LS_EuroInLire '______________________________________________________________ SUB LS_FILEDELETE (byval nomefile, byval sizelimit) 'Test= NON ESEGUITO 'Cancella il file se supera il limite in KB ' uso fname = Server.MapPath("myfile.gif") ' CALL LS_File_Delete(fname,15) Dim fso, f Set fso = Server.CreateObject("Scripting.FileSystemObject") Set f = fso.LS_FileSize(nomefile) fsize = CInt(f.Size/1024) If fsize > sizelimit Then fso.DeleteFile(nomefile) Response.Write("La dimensione del file ("&fsize&" Kb) supera il limite di "&sizelimit&" Kb. Il file è stato eliminato.") Else Response.Write("La dimensione del file ("&fsize&" Kb) non supera il limite massimo.") End If Set f = nothing Set fso = nothing END SUB 'LS_FILEDELETE '____________________________________________________________________________________ FUNCTION LS_FileExists (byval nomefile) 'Verifica se file esiste 'TEST=OK 'uso Dim fname ' fname = Server.MapPath("miafoto.gif") ' if LS_FileExists(fname) = true etc... Dim fso, f Set fso = Server.CreateObject("Scripting.FileSystemObject") on error resume next Set f = fso.GetFile(nomefile) if Err.Number <> 0 then LS_FileExists = false else LS_FileExists = true end if Set f = nothing Set fso = nothing ' ' 'on error goto 0 tolta xche da errori strani END FUNCTION 'LS_FileExists '_______________________________________________________________ SUB LS_FileRename (byval nomeold, byval nomenew) 'Test= NON ESEGUITO 'esempio nomeold= "c:\nomefile.asp" Dim fs Set fs = Server.CreateObject("Scripting.FileSystemObject") fs.MoveFile nomeold, nomenew Set fs = nothing END SUB 'LS_FileRename '___________________________________________________________________ FUNCTION LS_FilePath (byval stringa) ' Restituisce il nome completo del file Dim nomefile nomefile = ucase(stringa) if Left(UCase(nomefile),4) = "WWW." then nomefile="http://" & nomefile end if if len(nomefile) > 8 and left(Ucase(nomefile),8) = "HTTPS://" then nomefile = "HTTP://" & right(nomefile,len(nomefile) - 8) end if if len(nomefile) > 7 and left(Ucase(nomefile),7) = "HTTP://" then nomefile = right(nomefile,len(nomefile) - 7) nomefile = replace(nomefile, ucase(Request.ServerVariables("HTTP_HOST")) ,"") nomefile = Server.MapPath(nomefile) else nomefile = Server.MapPath(nomefile) end if LS_FilePath = nomefile END FUNCTION 'LS_FilePath '___________________________________________________________________ FUNCTION LS_FileSize (byval nomefile) 'Fornisce il size del file 'uso Dim fname, fpath ' fname = "myfile.gif" 'nome del file da controllare ' fpath = Server.MapPath(fname) ' Response.Write("La dimensione é " & LS_FileSize(fpath) & " kb" Dim fso, f Set fso = Server.CreateObject("Scripting.FileSystemObject") on error resume next Set f = fso.GetFile(nomefile) if Err.Number <> 0 then LS_FileSize= "Errore " & Err.Number &" - " & Err.Description else LS_FileSize=FormatNumber(f.Size/1024, 2) end if Set f = nothing Set fso = nothing END FUNCTION 'LS_FileSize '___________________________________________________________________ FUNCTION LS_FileWhereIs (byval nomefile) 'Dove si trova il file 'TEST=OK 'Uso Response.Write(LS_FileWhereIs("defalult.htm") nome senza path ' se il file non esiste da errore Dim Percorso, fso, f, nomelungo nomelungo = Server.MapPath(nomefile) Set fso = Server.CreateObject("Scripting.FileSystemObject") on error resume next Set f = fso.GetFile(nomelungo) if Err.Number <> 0 then LS_FileWhereIs = "Errore " & Err.Number &" - " & Err.Description else Percorso = Server.MapPath(nomefile) LS_FileWhereIs = Percorso end if Set f = nothing Set fso = nothing END FUNCTION 'LS_FileWhereIs '______________________________________________________________ FUNCTION LS_IMG_CLICK_ASP(byval fimg, byval assex, byval assey, byval allinea) ' Produce una sringa per l immagine cliccabile ' e restituisce nello stato true se tutto ok oppure false per ko. ' fimg senza Mathpath 'allinea = left / center / right ' Nel web ci vuole PICV.asp et PICVE.asp e la libreria JS_FMLIB.TXT ' e deve supportare le pagine ASP ' Richiamata da q_news_listall.asp, q_news_det.asp ' Esempio stato=LS_IMG_CLICK_ASP(immagine, larghezza, altezza) DIM stringa, quote quote = """" Stringa = "" ' ' ' stringa = stringa & "" stringa = stringa & "" ' stringa = stringa & "" RW(stringa) LS_IMG_CLICK_ASP = true END FUNCTION 'LS_IMG_CLICK_ASP '----------------------------------------------------------------------------------------------------------- FUNCTION LS_ImgSize (byval Immagine) 'Ottiene la dimensione in #pixel di una immagine .jpg .gif .bmp ' uso Immagine = "tuaimmagine.jpg" 'senza mathpath ' Dimensione = LS_ImgSize(Immagine) ' Response.Write "Larghezza: " & Dimensione(0) & " pixel" & "
" ' Response.Write "Altezza: " & Dimensione(1) & " pixel" ' e poi usarle 'non funziona se il nome inizia con HTTP:// or http://www. chiama LS_FilePath immagine = Server.MapPath(Immagine) LS_ImgSize = LS_IMGSIZE2(Immagine) END FUNCTION ' LS_ImgSize '----------------------------------------------------------------------------- FUNCTION LS_IMGSIZE2 (byval Immagine) ' Come LS_ImgSize ma vuole in input un nome di file fisico completo 'Ottiene la dimensione in #pixel di una immagine .jpg .gif .bmp ' uso Immagine = "tuaimmagine.jpg" 'nome file completo ' Dimensione = LS_ImgSize(Immagine) ' Response.Write "Larghezza: " & Dimensione(0) & " pixel" & "
" ' Response.Write "Altezza: " & Dimensione(1) & " pixel" ' e poi usarle Dim Dimensione,Formato,start,max,xs,xe,ys,ye,fso,ts,s Dimensione = Array("","") Formato = Right(UCase(Immagine),3) Select Case Formato Case "JPG" start = 167 : max = 4 : xs=3 : xe=4 : ys=1 : ye=2 Case"GIF" start=10 : max=4 : xs=2 : xe=1 : ys=4 : ye=3 Case "BMP" start = 24: max = 8 : xs = 4 : xe=3 : ys=8 : ye=7 End Select IF LS_FILEEXISTS(Immagine) THEN Set fso = CreateObject("Scripting.FileSystemObject") Set ts = fso.OpenTextFile(Immagine,1) s = Right(ts.Read(start), max) Dimensione(0) = LS_HEXTODEC(LS_HEXAT(s,xs) & LS_HEXAT(s,xe)) Dimensione(1) = LS_HEXTODEC(LS_HEXAT(s,ys) & LS_HEXAT(s,ye)) ts.Close ELSE Dimensione(0) = 0 Dimensione(1) = 0 END IF LS_ImgSize2 = Dimensione END FUNCTION ' LS_ImgSize2 '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - FUNCTION LS_HEXAT(s, n) LS_HEXAT = hex(asc(mid(s, n, 1))) If len(LS_HEXAT) = 1 then LS_HEXAT = "0" & LS_HEXAT END FUNCTION '- - - - - - - - - - - - - - -- - - - - - - - - - - - -- - - - - - - - - - - - - FUNCTION LS_HEXTODEC(cadhex) Dim n, i, ch, decimal decimal = 0 n = Len(cadhex) For i = 1 to n decimal = decimal * 16 ch = Mid(cadhex, i, 1) decimal = decimal + inStr("0123456789ABCDEFabcdef", ch) - 1 Next LS_HEXTODEC = decimal END FUNCTION 'LS_HEXTODEC '________________________________________________________________ SUB LS_LOG_APPEND(byval stringa) dim strUrl, FS, F, testo, modulo strUrl = Request.ServerVariables("URL") modulo = Right(strUrl, (Len(strUrl) - InStrRev(strUrl, "/"))) IF trim(stringa) <> "" then Set fs=Server.CreateObject("Scripting.FileSystemObject") Set f=fs.OpenTextFile(Server.MapPath("public\trxlog.log"), 8,true, -2) '8=xappend, true=crea se non esiste -2=system default format testo = now() & " " & modulo & " | " & stringa & vbCrLf f.write(testo) f.close set f=nothing set fs=nothing END IF END SUB 'LS_LOG_APPEND '-------------------------------------------------------------------------------------------------- FUNCTION LS_Last_Upd_Web() ' Fornisce la data di ultimo aggiornamento della pagina ' Da usare con LS_Stampa_NomePagina che fornisce il nome della pagina dim original_lcid original_lcid = Session.LCID Session.LCID=1040 'Imposto il formato italiano per la Sessione corrente Dim file, fs, f, LastModified file = Request.ServerVariables("PATH_TRANSLATED") Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFile(file) LastModified = f.datelastmodified Response.Write (FormatDateTime(LastModified, 0)) Set f = Nothing Set fs = Nothing Session.LCID = original_lcid END FUNCTION 'LS_Last_Upd_Web '____________________________________________________________________ FUNCTION LS_LireInEuro (ByVal lire) 'Restituisce il valore in euro. FUNCTION sorella di LS_EuroInLire Const Euro = 1936.27 Dim e e = FormatCurrency((lire/Euro), 2) LS_LireInEuro = e END FUNCTION 'LS_LireInEuro '________________________________________________________________________ FUNCTION LS_MESE_IT(byval mmm) dim strout Select case mmm case 1: strout="Gennaio" case 2: strout="Febbraio" case 3: strout="Marzo" case 4: strout="Aprile" case 5: strout="Maggio" case 6: strout="Giugno" case 7: strout="Luglio" case 8: strout="Agosto" case 9: strout="Settembre" case 10: strout="Ottobre" case 11: strout="Novembre" case 12: strout="Dicembre" end select LS_MESE_IT = strout END FUNCTION '_________________________________________________ FUNCTION LS_MESE3_IT(byval mmm) dim strout strout = left(LS_MESE_IT(mmm),3) LS_MESE3_IT = strout END FUNCTION '__________________________________________________________________________ SUB LS_NoClick() %> <% END SUB '____________________________________________________________________ FUNCTION LS_NomeFile() 'Test=ok dim strUrl, strPath strUrl = Request.ServerVariables("URL") strPath = Right(strUrl, (Len(strUrl) - InStrRev(strUrl, "/"))) LS_NomeFile = strPath END FUNCTION '__________________________________________________________________________ SUB LS_NO_CACHE_PAGE() 'Test da fare response.expires = -1500 response.AddHeader "PRAGMA", "NO-CACHE" response.CacheControl = "PRIVATE" END SUB 'LS_NO_CACHE_PAGE '____________________________________________________________________ FUNCTION LS_PRINDATA (byval ctrin) ' Gira una data AAAAMMGG ed aggiunge le barre ' esempio LS_PRINDATA("20051131") restituisce "31/11/2005" dim ctrot ctrot= right(ctrin,2) ctrot= ctrot & "/" ctrot= ctrot & mid(ctrin,5,2) ctrot= ctrot & "/" ctrot= ctrot & left(ctrin,4) LS_PRINDATA = ctrot END FUNCTION 'LS_PRINDATA '____________________________________________________________________ FUNCTION LS_PRsoloDATA (byval datain) ' DEVE ESSERE UNA DATA o null DIM ctrot if isnull(datain) then ctrot ="" else ctrot = FormatDateTime(datain,2) end if LS_PRsoloDATA = ctrot END FUNCTION 'PRsoloDATA '____________________________________________________________________ FUNCTION LS_QUARTI (byval stringa) ' Cambia .25 .50 .75 in ¼ ½ ¾ 'da finire e da testare Dim xxx, yyy xxx = "" & stringa yyy = "" 'yyy=L_REPSTRING('.25','¼',xxx); ' xxx=L_REPSTRING('.50','½',yyy); ' yyy=L_REPSTRING('.75','¾',xxx); LS_QUARTI = yyy END FUNCTION ' LS_QUARTI '____________________________________________________________________ FUNCTION LS_RANDOM(max) Randomize LS_RANDOM = Int(Rnd * max) + 1 END FUNCTION '____________________________________________________________________ FUNCTION LS_Refresh (byval nsec) 'ricaricare la pagina ogni n secondi Test= NON ESEGUITO ' aggiunge un HTTP , non più removibile ' nella pagina é 5= 5 secondi Response.AddHeader "Refresh", nsec END FUNCTION '____________________________________________________________________ SUB LS_Stampa_NomePagina() 'Test=ok Response.Write(UCase(LS_NomeFile)) END SUB '_____________________________________________________________ FUNCTION LS_STRING_CHG(byval stringa, byval oldcrt, byval newcrt) 'NOTA: oldcrt e newcrt lunghi 1 DIM strot, ind if isnull(stringa) or isEmpty(stringa) then strot = "" else For ind = 1 to len(stringa) if mid(stringa,ind,1) = oldcrt then strot = strot & newcrt else strot = strot & mid(stringa,ind,1) end if Next end if LS_STRING_CHG = strot END FUNCTION 'LS_STRING_CHG '------------------------------------------------------------------------------------------- FUNCTION LS_STRING_VP (byval stringa) ' la virgola diventa punto LS_STRING_VP = LS_STRING_CHG(stringa,",",".") END FUNCTION 'S_STRING_VP '___________________________________________________________________________ SUB LS_SW_ET_NOW() ' ' Stampa Identificazione transazione, la data di aggiornamento e adesso ' Response.Write("Trx ") Response.Write(UCase(LS_NomeFile)) Response.Write(" <|> ") Response.Write("Sw upd at ") Response.Write(LS_Last_Upd_Web) Response.Write(" <|> ") Response.Write("Now ") Response.Write(LS_DT(Now,"dmy")) END SUB 'LS_SW_ET_NOW '--------------------------------------------------------------------------------- FUNCTION LS_WEEKNBR (vDate,sWeekType) ' DatePart(intervallo, data, primogiornosettimana, primasettimanaanno) ' intervallo s=secondi n=minuti h=ore d=giorni, y=giorno dell anno w=giorno della settimana ww=settimana dell anno ' m=mese q=trimestre yyyy=anno ' data (obbligatorio) ' primogiornosettimana vbUseSystem 0 Usa impostaz API NLS ' vbSunday 1 Domenica impostaz predefinita ' vbMonday 2 Lun, vbTuesday 3 Mar, vbWednesday 4 Mercoledi, vbThursday 5 Giovedi ' vbFriday 6 ven, vbSaturday 7 Sabato ' primasettimanaanno vbUseSystem 0 Usa impostaz API NLS ' vbFirstJan1 1 ssettim del 1° gennaio (impostaz predefinita ' vbFirstFourdays 2, vbFirstFullWeek 3 Dim intWeek intWeek = DatePart("ww", DateValue(vDate), 0, sWeekType) LS_WEEKNBR = intWeek END FUNCTION '--- LS_WEEKNBR '------------------------------------------------------------------------------------------------------------------- '___________________________ FINE VBS_FMLIB.asp __________________ %>