Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can someone tell me what is wrong with this?

Status
Not open for further replies.

Jerkycold

IS-IT--Management
Jun 17, 2003
26
0
0
US
<%
Option Explicit
Response.Buffer = True

' This VBScript file creates a local copy of Moreover's news feed in XML
' format and updates it every so many hours. The local cached copy prevents
' unnecessary bandwidth useage to Moreover.

' Author: Craig H. Rettig
' Website:
' Special thanks to Peter A. Bromberg, and his article at Egghead Cafe,
' &quot;Building a Customizable Server-Side Cached Scrolling XML Newsfeed Display&quot;
' URL:
' CONFIG:
Dim sXMLDataDir, nHoursToRefresh, sDefaultCategory

' 1) Where you want the downloaded XML file to be stored (keep trailing slash).
' Please make sure the IIS Anonymous User has write access to this directory.
sXMLDataDir = Server.MapPath(&quot;.&quot;) & &quot;/news/&quot;

' 2) How many hours the page should be cached for
nHoursToRefresh = 1

' 3) If page is called with no arguments, show news from this category
sDefaultCategory = &quot;Top%20US%20stories&quot;

' 4) If you keep moreover.xsl in a different directory than moreover.asp, edit line 86.

' 5) Change stylesheet on line 158 and/or make any other look & feel configurations.

' 6) That should be it!

' This function retrieves the Moreover news feed from Moreover's site
' and saves it to a local file.
Function GetMoreoverXML(ByVal sCategory, ByVal sXMLDataFile)
Dim sChoice, sSource, objHTTP, sArticleList, sOut, oTS, oFSO, i

' Address of Moreover XML feed
sSource= &quot; & sCategory & &quot;&o=xml&quot;

Set objHTTP = Server.CreateObject(&quot;Microsoft.XMLHTTP&quot;)
Set oFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
objHTTP.Open &quot;GET&quot;, sSource, False
objHTTP.Send

sArticleList = objHTTP.ResponseBody
Set objHTTP = Nothing
sOut = &quot;&quot;

' Decode downloaded result (which is an array of unsigned bytes)
' in order to be able to write the results as plain text
For i = 0 To UBound(sArticleList)
sOut = sOut & ChrW(AscW(Chr(AscB(MidB(sArticleList, i + 1, 1)))))
Next

' Fix some Moreover formatting issues the MSXML parser doesn't like
sOut = Replace (sOut, &quot;encoding=&quot;&quot;iso-8859-1&quot;&quot;&quot;, &quot;&quot;)
sOut = Replace(sOut, &quot;<!DOCTYPE moreovernews SYSTEM &quot;&quot; &quot;&quot;)

Set oTS = oFSO.CreateTextFile(sXMLDataFile, True)
oTS.Write sOut
oTS.Close
Set oTS = Nothing
Set oFSO = Nothing
GetMoreoverXML = True
End Function


' This function applies the moreover.xsl stylesheet to
' the moreover.xml file and returns formatted HTML.
Function sShowNews(ByVal sXMLDataFile)
Dim objXML, objXSL

' Create an instance of the DOM object
Set objXML = Server.CreateObject(&quot;Microsoft.XMLDOM&quot;)
Set objXSL = Server.CreateObject(&quot;Microsoft.XMLDOM&quot;)
objXSL.Async = False

' Load the XML newsfeed into the objXML object
objXML.Load(sXMLDataFile)

' Load the XSL stylesheet into the objXSL object
objXSL.Load(Server.MapPath(&quot;.&quot;) & &quot;/moreover.xsl&quot;)

' Check for errors in the XSL
If (objXSL.ParseError.ErrorCode = 0) Then
' Parse the XML data with the XSL file
sShowNews = objXML.TransformNode(objXSL)
Else
' If an error occurs, report it
sShowNews = &quot;Error: &quot; & objXSL.ParseError.Reason & &quot;<br /> URL:&quot; & objXSL.URL
End If

Set objXSL = Nothing
Set objXML = Nothing
End Function


' Main display function
Dim sCategory, objFSO, fNewsFile, dLastSync, bGotFile, sXMLFile

' Which category to show?
If Request.QueryString(&quot;cat&quot;) = &quot;&quot; Then
sCategory = sDefaultCategory
sCategory = Replace(sCategory, &quot;%20&quot;, &quot; &quot;)
Else
sCategory = Request.QueryString(&quot;cat&quot;)
End If

bGotFile = False

Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

' Format the filename of datafile
sXMLFile = LCase(sCategory) & &quot;.xml&quot;
sXMLFile = Replace(sXMLFile, &quot;:&quot;, &quot;&quot;) ' Strip out illegal/ugly characters
sXMLFile = Replace(sXMLFile, &quot;/&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;&&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;?&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;\&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;;&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;=&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;@&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;,&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;&quot;&quot;&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;'&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot; &quot;, &quot;_&quot;)
sXMLFile = sXMLDataDir & sXMLFile

' Check if XML file exists
If Not objFSO.FileExists(sXMLFile) Then
bGotFile = GetMoreoverXML(sCategory, sXMLFile)
dLastSync = Now()
Else
' Check if file is more than nHoursToRefresh hours old
Set fNewsFile = objFSO.GetFile(sXMLFile)
dLastSync = fNewsFile.DateLastModified
Set fNewsFile = Nothing
If DateDiff(&quot;h&quot;, dLastSync, Now()) >= nHoursToRefresh Then
bGotFile = GetMoreoverXML(sCategory, sXMLFile)
dLastSync = Now()
Else
bGotFile = True
End If
End If
Set objFSO = Nothing
%>
<%
if session(&quot;empid&quot;)=&quot;&quot; then
response.redirect &quot;/peregrine/logon.asp&quot;
end if
%>
<%
empfname = Session(&quot;empfname&quot;)
folder = Session(&quot;empid&quot;)
%>
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>


<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName==&quot;Netscape&quot;)&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a.indexOf(&quot;#&quot;)!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a)&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf(&quot;?&quot;))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<link href=&quot;../images/pef.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;>
<link href=&quot;file://///Pacific/Inetpub/ rel=&quot;stylesheet&quot; type=&quot;text/css&quot;>
</head>

<body bgcolor=&quot;#CCCCCC&quot; leftmargin=&quot;0&quot; topmargin=&quot;0&quot; onLoad=&quot;MM_preloadImages('file://///Pacific/Inetpub/<TABLE width=100% border=0 align=&quot;center&quot; cellPadding=0 cellSpacing=0>
<TBODY>
<TR>
<!-- row 01 -->
<TD bgcolor=&quot;#C9C37F&quot;><div align=&quot;center&quot;>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=&quot;file://///Pacific/Inetpub/ width=&quot;134&quot; height=&quot;62&quot;></div></TD>
</TR>
</TBODY>
</TABLE>
<table width=&quot;100%&quot; border=&quot;0&quot; bgcolor=&quot;#7C2230&quot;>
<!--DWLayoutTable-->
<tr>
<td width=&quot;7%&quot;><a href=&quot;loui.asp&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Image6','','file://///Pacific/Inetpub/ src=&quot;file://///Pacific/Inetpub/ name=&quot;Image6&quot; width=&quot;70&quot; height=&quot;13&quot; border=&quot;0&quot;></a></td>
<td width=&quot;7%&quot;><font color=&quot;#FF0000&quot;><a href=&quot;1003/prequal.asp&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Image4','','file://///Pacific/Inetpub/ src=&quot;file://///Pacific/Inetpub/ name=&quot;Image4&quot; width=&quot;70&quot; height=&quot;13&quot; border=&quot;0&quot;></a></font></td>
<td width=&quot;6%&quot;><a href=&quot;logoff.asp&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Image5','','file://///Pacific/Inetpub/ src=&quot;file://///Pacific/Inetpub/ name=&quot;Image5&quot; width=&quot;70&quot; height=&quot;13&quot; border=&quot;0&quot;></a></td>
<td width=&quot;75%&quot;>&nbsp;</td>
<td width=&quot;5%&quot;>&nbsp;</td>
</tr>
</table>
<table width=&quot;100%&quot; height=&quot;478&quot; border=&quot;0&quot; bgcolor=&quot;#FFFFFF&quot;>
<!--DWLayoutTable-->
<tr>
<td width=&quot;89%&quot; height=&quot;474&quot; valign=&quot;top&quot; bgcolor=&quot;#FFFFFF&quot;>
<div align=&quot;center&quot;>
<table width=&quot;100%&quot; border=&quot;0&quot;>
<!--DWLayoutTable-->
<tr>
<td height=&quot;23&quot; colspan=&quot;5&quot;><div align=&quot;center&quot;><a href=&quot; &middot; <a href=&quot; &middot;
<a href=&quot; &middot; <a href=&quot;file://///Pacific/Inetpub/ &middot; <a href=&quot;file://///Pacific/Inetpub/ Search</a><br>
<a href=&quot; &middot; <a href=&quot;file://///Pacific/Inetpub/ Search</a> &middot; <a href=&quot;file://///Pacific/Inetpub/ Search</a>
<cfif #currentcompanyid# is 80>
</cfif>
</div></td>
</tr>
<tr>
<td width=&quot;157&quot; height=&quot;83&quot;>&nbsp;</td>
<td width=&quot;120&quot;>&nbsp;</td>
<td width=&quot;311&quot;>&nbsp;</td>
<td width=&quot;273&quot; valign=&quot;bottom&quot;>
<%
If bGotFile = True Then
Response.Write sShowNews(sXMLFile)
Else
Response.Write &quot;<p><strong>There was an error retrieving the news feed.</strong></p>&quot;
End If
%>
</td>
<td width=&quot;144&quot;>&nbsp;</td>
</tr>
<tr>
<td height=&quot;168&quot;><font color=&quot;#FF0000&quot;>&nbsp;</font></td>
<td colspan=&quot;2&quot; valign=&quot;top&quot;><table width=&quot;100%&quot; border=&quot;0&quot;>
<tr>
<td><font size=&quot;-2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;><strong>Welcome
<%=Session(&quot;empfname&quot;)%>&nbsp;<%=Session(&quot;emplname&quot;)%> </strong></font></td>
</tr>
</table>
<table width=&quot;100%&quot; border=&quot;0&quot;>
<tr>
<td><p><font size=&quot;-2&quot;><strong>What would you like to do?</strong></font></p></td>
</tr>
</table>
<table width=&quot;84%&quot; border=&quot;0&quot;>
<!--DWLayoutTable-->
<tr>
<td width=&quot;409&quot; height=&quot;114&quot; valign=&quot;top&quot;> <blockquote>
<p><strong><font size=&quot;-1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;><font size=&quot;-7&quot;>&#8226;</font>
<a href=&quot;../Calendar/default.asp&quot; target=&quot;_self&quot;>Check
Leads </a></font></strong><strong><font size=&quot;-1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;><br>
<font size=&quot;-7&quot;>&#8226;</font> <a href=&quot;../Calendar/default.htm&quot; target=&quot;_self&quot;>Check
Pipeline</a><br>
<font size=&quot;-7&quot;>&#8226;</font> <a href=&quot;1003/prequal.asp&quot; target=&quot;_self&quot;>Prequal</a>
<br>
<font size=&quot;-7&quot;>&#8226;</font> <a href=&quot;1003/1003.asp&quot; target=&quot;_self&quot;>Loan
Application</a><br>
</font></strong></p>
</blockquote></td>
</tr>
</table></td>
<td valign=&quot;top&quot;><font size=&quot;1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;><strong>
<span class=&quot;ip&quot;><font size=&quot;-2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;><strong>IP</strong></font></span>:
<font size=&quot;-2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;><strong>
<%Response.Write(Request.ServerVariables(&quot;remote_addr&quot;))%>
<br>
<br>
<%
response.write(&quot;Todays Date: &quot;)
response.write(&quot;<br />&quot;)
response.write(FormatDateTime(date(),vblongdate))
%>
<br>
<br>
</strong></font> </strong></font> </td>
<td valign=&quot;top&quot;>&nbsp; </td>
</tr>
</table>
</div></td>
</tr>
</table>
<table width=&quot;100%&quot; border=&quot;0&quot; bgcolor=&quot;#000000&quot;>
<tr>
<td width=&quot;1%&quot; bgcolor=&quot;#000000&quot;>&nbsp;</td>
<td width=&quot;99%&quot; height=&quot;72&quot; bgcolor=&quot;#000000&quot;><p>&nbsp;</p>
<h6>&nbsp;</h6>
<font color=&quot;#FFFFFF&quot; size=&quot;-2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;>Copyright
&copy; 2003 &#8226; Pacific Eagle Financial Incorporated | Privacy Information
| Legal</font></td>
</tr>
</table>
</body>
</html>



When I take out my session code:

<%
if session(&quot;empid&quot;)=&quot;&quot; then
response.redirect &quot;/peregrine/logon.asp&quot;
end if
%>
<%
empfname = Session(&quot;empfname&quot;)
folder = Session(&quot;empid&quot;)
%>

It works!! So how can I get it to work with my session code or if I need to do my session code another way?
 
Are you getting any errors? If so please describe them. What happens when &quot;it doesn't work&quot;?

You have declared Option Explicit which requires all variables to be declared, so why didn't you Dim empfname, folder too since it also is a local variable, though I don't see where you are using it... Could that be the problem?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top