<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" Debug="true" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Register TagPrefix="xedit" Namespace="Swarren.XmlEditGrid" Assembly="Swarren.XmlEditGrid" %>

<script language="VB" type="text/VB" runat="server">
' Specify the password to edit the list:

Dim password as string = "atlantis"

Sub Page_Load(Src As Object, E As EventArgs) 

Dim nosort
MakeGrid(nosort)

End Sub


Sub MakeGrid(sortExpr as String)

'Load file from Dataset

	Dim FILENAME As String
	FILENAME =Request.QueryString("file")
		If FILENAME = "" THEN 
			FILENAME = "faves.xml" 
		END IF
    Dim ds As New DataSet
    Dim FS As New FileStream(Server.MapPath(FILENAME), FileMode.Open)
    ds.ReadXml(FS)
    FS.close()


' 	Check the number of links in the XML file

Dim CatNum,i As Integer      
CatNum = ds.Tables(0).Rows.Count
lblCatNum.Text = "There are " & CatNum & " links in the file."


'	Get the topic, if there is one

Dim topic As String = Request.QueryString("topic")				
If topic = "" then
	topic = "My Creations"
end if
	lbltopic.Text = topic ' Set the topic to a text label

' Bind the data

Dim viewtopic as new DataView(ds.Tables(0))

' 	Filter out for a certain topic, if selected:

if topic <> "All" then
	viewtopic.RowFilter = "Category LIKE '%" & topic  & "%'"			
end if				

' Sort the data if Sort parameter not NULL

If sortExpr  <> ""
	viewtopic.Sort = sortExpr			
End if


' Write to DataGrid
	quotegrid.DataSource = viewtopic
    quotegrid.DataBind()

End Sub



Sub submit(sender As Object, e As EventArgs)
   Dim file As String = lblfile.Text
   Dim topic As String = lblkeyword.Text
If file <> "" then
   response.Redirect("links.aspx?file=" & file)
else
   response.Redirect("links.aspx?topic=" & topic)
end if 
End Sub

Sub SortResults(sender as Object, e as DataGridSortCommandEventArgs)
	' Sort the data
	

'	Dim Sort As String ="Name"
'	MakeGrid(Sort)
MakeGrid(e.SortExpression)

End Sub


' *************** IGNORE THIS ************
Sub trash(i, Catnum)

'	For i=0 to CatNum  -1
'		If (ds.Tables(0).Rows(i)(2)) = "One" then
'			response.Write(ds.Tables(0).Rows(i)(2))
'		end if
'	Next
end sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Websites of Interest</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="styles.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
hr {
	border-top-width: 1px;
    border-top-style: solid;
    border-color: #FF0000; 
    margin: 0px 2%;}

-->
</style>
</head>
<body>

<% if request("edit") = "yes" then %>

<script language="JavaScript1.2" type="text/JavaScript1.2">
<!--hide

var password;

var pass1="<%=password%>";

password=prompt('Please enter the password to edit this page!',' ');

if (password==pass1)
//  alert('Password Correct! Click OK to enter!');
var do_nothing;
else
   {
   alert('Wrong Password, try again!');
    window.location="<%=Request.ServerVariables("URL") %>";
    }


//-->
</script>

 <form id="Form1" method="post" runat="server">
      <xedit:xmleditgrid 
       id="XmlEditGrid1" runat="server" 
       xmlfile="faves.xml">
      </xedit:xmleditgrid>
    </form>

<%
 else
 %>

  <h1>Websites of Interest
</h1>
  <h3>Pick a topic:</h3>
  <p><a href="links.aspx?topic=All">Show All</a> | <a href="links.aspx?topic=Aggie">Aggie Related</a> | <a href="links.aspx?topic=My Creations">My Creations</a> | <a href="links.aspx?topic=Politics">Political Commentary</a> | <a href="links.aspx?topic=Tech">Tech News and Reviews</a> </p>
  <p>| <a href="links.aspx?topic=Art">Art and Music</a> | <a href="links.aspx?topic=Objectivism">Objectivist</a> | <a href="links.aspx?topic=Humor">Comedy and Satire</a> | <a href="links.aspx?topic=Art">Art</a> | <a href="links.aspx?topic=ThinkTank">Think tanks</a> | <a href="links.aspx?topic=Economics">Economics</a> | <a href="links.aspx?topic=News">News</a></p>
  <h2 align="center"> Results for 
    '<asp:label ID="lbltopic" runat="server" Text=topic></asp:label>'
  </h2>
  
<p>
</p>
<form runat="server">
  <asp:datagrid runat="server" ID="quotegrid" 
                BackColor="#eeeeee" Width="85%"
                HorizontalAlign="center"
                Font-Name="Verdana" CellPadding="4"
                Font-Size="10pt" 
				AutoGenerateColumns="False"
				AllowSorting ="True"
				OnSortCommand="SortResults">
    <headerstyle BackColor="Black" ForeColor="White" 
             Font-Bold="True" HorizontalAlign="center" />
    <alternatingitemstyle BackColor="White" />
  
    <columns>
      <asp:hyperlinkcolumn
                 headertext="Name"
                 DataNavigateUrlField="URL"
                 DataNavigateUrlFormatString="{0}"
                 DataTextField="Name"
                 DataTextFormatString="{0:c}"
                 target="_new"
				SortExpression="Name"
				
				 />
				 
      <asp:hyperlinkcolumn
                 headertext="URL"
                 DataNavigateUrlField="URL"
                 DataNavigateUrlFormatString="{0}"
                 DataTextField="URL"
                 DataTextFormatString="{0:c}"
                 target="_new"
				 SortExpression="URL"
				 />
				

    </columns>
  </asp:datagrid>
  <hr />
  <a href="faves.xml"><img src="rant/images/xml.gif" alt="Get this blog in XML" width="36" height="14" border="0" /></a>

Specify an XML file:
  <asp:textbox ID="lblfile" runat="server" Text="" TextMode="SingleLine" style="font: 10pt verdana;background-color:lightblue;border-style:dashed;border-color:darkblue;width:100;" />
  <em>or</em> specify a custom keyword:   
  <asp:textbox ID="lblkeyword" runat="server" Text="" TextMode="SingleLine" style="font: 10pt verdana;background-color:lightblue;border-style:dashed;border-color:darkblue;width:100;" />
<asp:Button OnClick="submit" Text="Submit" runat="server" style="font: 8pt verdana;background-color:lightblue;border-color:black;width:100" />
</form>
<a href="links.aspx?action=edit" onclick="alert('TODO!');return true;"><img src="images/edit.gif" alt="Edit" width="36" height="17" border="0" /></a>

<a href="#" onclick="alert('This page reads data from an XML file and prints the URLs that match a particular keyword.  Not all keywords are listed up top.  You can try keywords such as Homepages, Psychology, Philosophy, etc to find some that are not listed.  You also specify another XML to read, if you know the URL. ');return true;">How does this work?</a>
<asp:Label id="lblCatNum" runat="server" Font-Size="10" Font-Name="Verdana" ToolTip="LinksList 1.0 by David Veksler" />

<a href="<%=Request.ServerVariables("URL")%>?edit=yes">Edit.</a>
<hr />

<% End If %>

</body>
</html>
