<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
	pagename	= "news.asp"
	pageheader	= "Manage News"
	pagetable	= "news"
	pageobject  = "News Article"
	candelete 	= True
	canadd		= True
	useeditor	= False
%>
<!--#include file="include/functions.asp"-->
<%
	GetOrder()
%>
<!--#include file="include/header.asp"-->
<% 	
	Select case action
		Case ""
			If OrderBy = "" Then 
				OrderBy = "fldDate"
			End If
			numrows = GetNumRecs(pagetable)
			OpenRS("SELECT id,fldName,fldDate FROM "&pagetable&" ORDER BY "&OrderBy&" "&SortBy)
%>
			<table width="550" border="0" cellpadding="0" cellspacing="0">
			 <tr> 
			  <td class="gridbox">
			   <table width="550" border="0" cellpadding="0" cellspacing="0" class="gridhead">
				<tr class="row1"> 
				 <td width="100" onClick="Redirect('<%=pagename%>?o=fldDate&s=<%=nsort%>');" onMouseOver="this.style.cursor='hand';">Date<%If torder="fldDate" Then Response.Write("<img src=""images/"&nsort&".gif"">")%></td>				
				 <td width="450" onClick="Redirect('<%=pagename%>?o=fldName&s=<%=nsort%>');" onMouseOver="this.style.cursor='hand';">Name<%If torder="fldName" Then Response.Write("<img src=""images/"&nsort&".gif"">")%></td>
				</tr>
			   </table>
<%
			If Not rs.EOF Then
				x = 1
				Response.Write("<div class=""grid""><table width=""550"" border=""0"" cellpadding=""0"" cellspacing=""0"" class=""gridbody"">"&vbCrLf)
				Do While Not rs.EOF					
					Response.Write("<tr id=""row"&x&""" class=""row1"" onMouseOver=""RowOver(this);"" onMouseOut=""RowOut(this);"" onClick=""ChangeRow(this,"&numrows&","&rs("id")&");"">"&vbCrLf) 
					Response.Write("<td width=""100"">"&rs("fldDate")&"</td>"&vbCrLf)
					Response.Write("<td width=""450"">"&rs("fldName")&"</td>"&vbCrLf)
					Response.Write("</tr>"&vbCrLf)
					x = x + 1
					rs.MoveNext
				Loop
				Response.Write("</table></div>"&vbCrLf)
			End If		
%>
		      </td>
		     </tr>
		     <tr>
		      <td height="60" align="right" valign="top"> 
			   <table width="550" cellpadding="0" cellspacing="0">
			    <tr>
				 <td height="5" colspan="2"><img src="images/pixel.gif" height="5"></td>
				</tr>
			    <tr>
				 <td valign="top" align="left" width="202">
				 </td>
				 <td width="348" valign="top">
				  <form name="actionform" method="post" action="<%=pagename%>">
		           <input type="hidden" id="action" name="action" value="">
		           <input type="hidden" id="id" name="id" value="">
		           <input type="hidden" id="step" name="step"  value="1">
		           <%If canadd = True Then Response.Write("<input name=""button"" type=""button"" id=""button"" value=""Add"" onClick=""return DoAction('add');"">")%>
		           <input name="button" type="button" id="button" value="Edit" onClick="return DoAction('edit');">
		           <%If candelete = True Then Response.Write("<input name=""button"" type=""button"" id=""button"" value=""Delete"" onClick=""return DoAction('delete');"">")%>
		          </form>
				 </td>
				</tr>
			   </table>
		      </td>
		     </tr>
	        </table>
<%
			CloseRS()
	Case "add", "edit"
		If step = 1 Then
			If action = "edit" Then
				OpenRS("SELECT * FROM "&pagetable&" WHERE ID = "&id)
					If Not rs.EOF Then
						id = rs("ID")
						rName = rs("fldName")
						rDate = rs("fldDate")
						rText = rs("fldText")
					End If
				CloseRS()
			End If
%>
		   <form name="form" action="<%=pagename%>" method="post">
		    <input type="hidden" name="action" value="<%=action%>">
		    <input type="hidden" name="step" value="2">
		    <input type="hidden" name="id" value="<%=id%>">
			<input type="hidden" name="time" value="">
			<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
			 <tr>
			  <td height="26" width="75">Date</td>
			  <td width="425"><table width="124" cellpadding="0" cellspacing="0"><tr><td width="101"><input name="date" type="text" id="date" style="width:100px;" value="<%=rDate%>"></td><td width="23"><img src="images/cal.gif" width="23" height="23" alt="Date Selector" onMouseOver="this.style.cursor='hand';" onClick="popup('include/calendar.asp','PopCal','210','175','no');"></td></tr></table></td>
			 </tr>
			 <tr>
			  <td height="26">Name:</td>
			  <td><input name="name" type="text" id="name" style="width:425px;" value="<%=rName%>" maxlength="100"></td>
			 </tr>
			 <tr>
			  <td height="26">Text:</td>
			  <td><textarea name="text" rows="5" id="text" style="width:425px;"><%=RemoveBreaks(rText)%></textarea></td>
			 </tr>
			 <tr>
			  <td></td>
			  <td height="40"><input type="button" name="Button" value="Submit" onClick="return ValidateForm('<%=pagename%>');"> <input type="reset" name="Submit2" value="Reset"></td>
			 </tr>
			</table>
		   </form>
<%
			Else
				If action = "edit" Then
					sql = "UPDATE news SET fldDate='"&MySQLDate(Request("date"))&"', fldName='"&Clean(Request("name"))&"', fldText='"&Clean(InsertBreaks(Request("text")))&"' WHERE ID = " & id
					msg = pageobject & " has been edited."
				Else
					sql = "INSERT INTO news (ID,fldDate,fldName,fldText) VALUES ('','"&MySQLDate(Request("date"))&"','"&Clean(Request("name"))&"','"&Clean(InsertBreaks(Request("text")))&"')"
					msg = pageobject & " has been added."
				End If
				ExecRS(sql)
				Response.Redirect(pagename&"?msg="&Server.UrlEncode(msg))	
			End If
		Case "delete"
			If candelete = True Then
				DeleteRecord pagename,pagetable,pageobject,id
			End If
	End Select
%>		
<!--#include file="include/footer.asp"-->        