<?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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>The Aggie Review Online: Add Article</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="stylesheet.css" type="text/css" />
</head>
<body topmargin="0">

<!--#include file="functions.asp" -->
<%
' SUBMIT ARTICLE??
EDIT= Request("EDIT")
IF EDIT = "ADDNOW" OR EDIT = "EDIT" THEN

UserName = Request.Cookies("user")("UserName")
Title =Request("Title")
Body =Request("Body")
Intro =Request("Intro")
Genre =Request("Genre")
Rank =Request("Rank")
theDate= Date()
theTime= Time()

' CHECK FOR WEIRD CHARACTERS
Title = Trim(Replace(Request.Form("Title"), "'", "''"))
' Title = Replace(Title,"""","""""")
Body = Trim(Replace(Request.Form("Body"), "'", "''"))
'Body = Replace(Body,"""","""""")
Intro = Trim(Replace(Request.Form("Intro"), "'", "''"))
' Intro = Replace(Intro,"""","""""")
' do more later...

' BEGIN INSERT RS
set insertRS=Server.CreateObject("ADODB.recordset")

' INSERT OR EDIT ?
IF EDIT = "ADDNOW" THEN
sql= "INSERT INTO articles (UserName, Title, Body, Intro, Genre, [Date], [Time]) VALUES ('" & UserName & "', '" & Title & " ', '" & Body & "', '" & Intro & "' , '" & Genre & "' , '" & theDate & "' , '" & theTime & "')"
insertRS.Open sql, conn
' END user1 RECORDSET FOR ARTICLE BODY DISPLAY
%>
<script>
<!-- Hide Script
	alert("You have added an article named <%=Title%>!")
	
	 top.location = 'default.asp';
//End Hide Script-->
</script>
<%
END IF 
' END FOR INSERT

' EDIT ARTICLE ?
EDIT= Request("EDIT")
IF EDIT="EDIT" THEN


UserName = Request("UserName")
theID= Request("ID")


sqlPUT= "UPDATE articles SET UserName = '" & UserName & "', Title = '" & Title & "', Body= '" & Body & "' , Intro= '" & Intro & "' , Genre = '" & Genre & "' , Rank = '" & Rank & "' WHERE ID = " & theID & " "
insertRS.Open sqlPUT, conn

%>
<script>
<!-- Hide Script
	alert("You have changed article number <%=theID%>!")
	 
	 top.location = 'config.asp';
//End Hide Script-->
</script>
<%

END IF ' END EDIT
END IF ' END FINISH
%>
<%
' SHOW EDITED ARTICLE?
IF Request("EDIT")="YES" THEN

theID = Request("ID")
sqlGET="SELECT * FROM articles WHERE ID = " & theID & " "

set rs = Server.CreateObject("ADODB.recordset")
rs.Open sqlGET, conn

UserName = rs("UserName").Value
Title = rs("Title").Value
Body= rs("Body").Value
Intro= rs("Intro").Value
Genre= rs("Genre").Value
ID= rs("ID").Value
Rank= rs("Rank").Value

END IF
%>

<table width="80%" border="1" height="581">
  <tr bgcolor="#8CAAE7"> 
    <td colspan="3"> 
      <!--server side include numero uno -->
      <!--#include file="titleINC.asp" -->
    </td>
  </tr>
  <tr bgcolor="#0066CC"> 
    <td colspan="3" height="38" class="quicklink"> 
      <!--server side include numero dos -->
      <!--#include file="topINC.asp" -->
    </td>
  </tr>
  <tr> 
    <td width="10%" height="413" class="left" valign="top" bgcolor="#EFF3FF"> 
      <!--server side include numero tres -->
      <!--#include file="contentsINC.asp" -->
    </td>
    <td width="70%" height="413" valign="top" bgcolor="white"> 
      <!--                     BODY                -->
      <h2>Add an Article: </h2>
      <p>
        <%
'IF COOKIE SET 
author = Request.Cookies("user")("author")
if author ="YES" THEN
%>
      </p>
      <form action="addarticle.asp" method="post">
	   	<h3>Title: (NO HTML!)</h3>
        <h3> 
          <input type="text" name="title" size="70" value="<%=title%>" />
        </h3>
        <h3>Article Intro:
        <h3> 
            <textarea name="Intro" cols="70" rows="12"><%=Intro%></textarea>
		  </h3>
        </h3>
        <h3>Body: (HTML Allowed) </h3>
        <h3>
          <textarea name="body" rows="15" cols="70"><%=Body%></textarea>
        </h3>
        
          
        <h3>Article Category: 
          <select name="Genre">
            <option value=" <%=Genre%> "><%=Genre%></option>
<%
SQLtopics= "SELECT * FROM TOPICS"
set rs3 = Server.CreateObject("ADODB.recordset")
rs3.Open SQLtopics, conn
%>
<%
rs3.MoveFirst
Do until rs3.EOF
%>
    <option value="<%=rs3("Topic").Value%>"><%=rs3("Description").Value%></option>
<%
rs3.MoveNext
Loop
rs3.close
%>
          </select>
          (Use General for Most Users)</h3>
        <p> 
          <% IF Request("EDIT")= "YES" THEN %>
         </p>
        <h3>User:
          <input type="text" name="UserName" value="<%=rs("UserName").Value%>" />
        </h3>
		
		 Rank:
          <select name="Rank">
   			<option value="<%=rs("Rank").Value%>"><%=rs("Rank").Value%></option>
			 <option value="0">Exclude</option>
			<option value="1">Highest</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
           
          </select>
		  
        <input type="hidden" name="EDIT" value="EDIT" />
		  <%
					 ELSE
					%>
          
        <input type="hidden" name="EDIT" value="ADDNOW" />
          <% END IF %>
          
        <input type="hidden" name="ID" value="<%=ID%>" />
          
        <input type="submit" name="Submit3" value="Submit!" />
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
          
        <input type="reset" name="Submit2" value="Reset!" />
      </form>
        <%
ELSE
'ELSE KICK OUT
Response.write("<h1>You are not registered as an author!</h1>")
END IF
%>
     
    
               <!--                END     BODY                -->
    </td>
    <td width="10%" height="413" class="right" valign="top" bgcolor="#D7DEF8"> 
      <!--server side include five? -->
      <!--#include file="rightside.asp" -->
    </td>
  </tr>
  <tr bgcolor="#8CAAE7"> 
    <td colspan="3" height="71" class="quicklink"> 
      <!--server side include numero quatro -->
      <!--#include file="bottomINC.asp" -->
    </td>
  </tr>
</table>

<%
'close connections
conn.close
%>
</body>
</html>
