I have been tasked with sifting through the worst classic asp spaghetti i've ever come across.
The script runs a series of recordsets in sequence, getting 1 record at a time. As the record is built it takes the id and passes it to the next loop, which gets data, and passes on the id to the next loop. It then continues in this manner and builds an unordered list, kicking out the required html as it goes.
Here are my efforts so far:
have a class delivering data via sqldatareaders and output these to nested repeaters (this failed due to not being able to loop and get the id)
Have a datatable populated with all the required data, then datatable.select to filter it out.
have 4 datareaders looping and building the ul arraylists (I
couldnt get the id's to match up)
Please can you suggest the best method (with a bit of sample code if possible) to go about doing this conversion?
Here is the code (sorry its long / horrible / spaghetti!!!)
<%
set RSMenuLevel0 = conn.execute("select id, DepartmentID, GroupingID, Heading, OrderID, Publish, moduleid, url, urltarget " &_
"from Grouping where (DepartmentID = 0 and GroupingID = 0 and Publish <> 0) order by OrderID")
%>
<%
if session("JavaScriptEnabled") = "False" Then
%>
<%
while not RSMenuLevel0.EOF
if RSMenuLevel0("Publish") <> 0 then
Menu0heading = RSMenuLevel0("Heading")
Menu0id = RSMenuLevel0("id")
%>
<%if RSMenuLevel0("url") > "" and RSMenuLevel0("moduleid") = 0 then%>
<a href="http://<%=RSMenuLevel0("url")%>" target="<%=RSMenuLevel0("urltarget")%>"><%=Menu0heading%></a>
<%else%>
<a href="/default.asp?id=<%=Menu0id%>"><%=Menu0heading%></a>
<%end if%>
<%
end if
RSMenuLevel0.MoveNext
wend
%>
<%
else
%>
<ul id="Menu1" class="MM">
<%if home <> 1 then%>
<!-- <li><a href="/default.asp"><span class="item">Home</span></a> -->
<%end if%>
<%
numone=0
while not RSMenuLevel0.EOF
' numone = numone + 1
Menu0heading = RSMenuLevel0("Heading")
'itemID = lcase(replace(Menu0heading," ",""))
Menu0id = RSMenuLevel0("id")
if RSMenuLevel0("url") > "" and RSMenuLevel0("moduleid") = 0 then
url = RSMenuLevel0("url")
if instr(url,"file:///") > 0 then
%>
<li><a href="<%=RSMenuLevel0("url")%>" target="<%=RSMenuLevel0("urltarget")%>" <%if numone=1 then%>class="CURRENT"<%end if%>><span class="item"><%=Menu0heading%></span></a>
<%else%>
<li><a href="http://<%=RSMenuLevel0("url")%>" target="<%=RSMenuLevel0("urltarget")%>" <%if numone=1 then%>class="CURRENT"<%end if%>><span class="item"><%=Menu0heading%></span></a>
<%end if%>
<%else%>
<li><a href="/default.asp?id=<%=RSMenuLevel0("id")%>" <%if numone=1 then%>class="CURRENT"<%end if%>><span class="item"><%=Menu0heading%></span></a>
<%end if%>
<%
set RSMenuLevel1 = conn.execute("select id, DepartmentID, GroupingID, Heading, OrderID, Publish, moduleid, url, urltarget " &_
"from Grouping where (DepartmentID = 0 and GroupingID = " & Menu0id & " and Publish <> 0) order by OrderID")
if not RSMenuLevel1.EOF then
%>
<ul>
<%
while not RSMenuLevel1.EOF
Menu1heading = RSMenuLevel1("Heading")
Menu1id = RSMenuLevel1("id")
if RSMenuLevel1("url") > "" and RSMenuLevel1("moduleid") = 0 then
url = RSMenuLevel1("url")
if instr(url,"file:///") > 0 then
%>
<li><a href="<%=RSMenuLevel1("url")%>" target="<%=RSMenuLevel1("urltarget")%>"><%=Menu1heading%></a>
<%else%>
<li><a href="http://<%=RSMenuLevel1("url")%>" target="<%=RSMenuLevel1("urltarget")%>"><%=Menu1heading%></a>
<%end if%>
<%else%>
<li><a href="/default.asp?id=<%=RSMenuLevel1("id")%>"><%=Menu1heading%></a>
<%end if%>
<%
set RSMenuLevel2 = conn.execute("select id, DepartmentID, GroupingID, Heading, OrderID, Publish, moduleid, url, urltarget " &_
"from Grouping where (DepartmentID = 0 and GroupingID = " & Menu1id & " and Publish <> 0) order by OrderID")
if not RSMenuLevel2.EOF then
%>
<ul>
<%
while not RSMenuLevel2.EOF
Menu2heading = RSMenuLevel2("Heading")
Menu2id = RSMenuLevel2("id")
if RSMenuLevel2("url") > "" and RSMenuLevel2("moduleid") = 0 then
%>
<li><a href="http://<%=RSMenuLevel2("url")%>" target="<%=RSMenuLevel2("urltarget")%>"><%=Menu2heading%></a>
<%else%>
<li><a href="/default.asp?id=<%=RSMenuLevel2("id")%>"><%=Menu2heading%></a>
<%end if%>
<%
set RSMenuLevel3 = conn.execute("select id, DepartmentID, GroupingID, Heading, OrderID, Publish, moduleid, url, urltarget " &_
"from Grouping where (DepartmentID = 0 and GroupingID = " & Menu2id & " and Publish <> 0) order by OrderID")
if not RSMenuLevel3.EOF then
%>
<ul>
<%
while not RSMenuLevel3.EOF
Menu3heading = RSMenuLevel3("Heading")
Menu3id = RSMenuLevel3("id")
if RSMenuLevel3("url") > "" and RSMenuLevel3("moduleid") = 0 then
%>
<li><a href="http://<%=RSMenuLevel3("url")%>" target="<%=RSMenuLevel3("urltarget")%>"><%=Menu3heading%></a></li>
<%else%>
<li><a href="/default.asp?id=<%=RSMenuLevel3("id")%>"><%=Menu3heading%></a></li>
<%end if%>
<%
RSMenuLevel3.MoveNext
wend
%>
</ul>
<%
end if
RSMenuLevel2.MoveNext
%>
</li>
<%
wend
%>
</ul>
<%
end if
RSMenuLevel1.MoveNext
%>
</li>
<%
wend
%>
</ul>
<% end if
RSMenuLevel0.MoveNext
%>
</li>
<%
wend
%>
</ul>
<%
end if
%>