 <?php
	include("inside/config.php");
	session_start();
	$user=$_SESSION['username'];
	if(empty($user))
	{
		echo "<script>window.location='login.php'</script>";
	}
$currentpage = "newarticle";
if($_REQUEST['action']=="add"){	
//This is the directory where images will be saved
   	$name=time();
    $target = "pictures/";
    $target = $target .$name. basename( $_FILES['fpic']['name']);
//This gets all the other information from the form
    	$id=$_REQUEST['id'];
		$heading=mysql_real_escape_string($_REQUEST['ftitle']);
		$pagename=$_REQUEST['fpage'];
		$content=mysql_real_escape_string($_REQUEST['fcontent']);
		$pic=($_FILES['fpic']['name']);
		$imageFileType = pathinfo($target,PATHINFO_EXTENSION);
//Writes the photo to the server

    if(move_uploaded_file($_FILES['fpic']['tmp_name'], $target))
    {
		//Writes the information to the database
   		mysql_query("insert into `articles`(`article_heading`, `article_picture`, `article_content`, `page_name`)
		values('$heading','$target','$content','$pagename')");
		echo "<script>window.location='index.php'</script>";
    }
    else {
 //Gives an error if its not
    $type = "error";
	$msg =  "Sorry, there was a problem uploading your file!";
    }
}
?>
<!DOCTYPE html>
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
	<title>Admin Panel : Frontier Public High School</title>
	<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
<?php include('inside/jsfunctions.php'); ?>
</head>
<body>
<?php include('inside/header.php'); ?>
<!-- Container -->
<div id="container">
	<div class="shell">
		
		<!-- Small Nav -->
		<div class="small-nav">
			<a href="#">Dashboard</a>
			<span>&gt;</span>
			New Article</div>
		<!-- End Small Nav -->
			<!-- Message OK -->		
		<?php if($type=="ok"){ ?>
        <div class="msg msg-ok" id="msgok">
			<p><strong><?php echo $msg; ?></strong></p>
			<a href="#" class="close" onclick="removeOk();">close</a>
		</div>
		<!-- End Message OK -->		
		<?php } ?>
		<!-- Message Error -->
		<?php if($type=="error"){ ?>
		<div class="msg msg-error" id="error">
			<p><strong><?php echo $msg; ?></strong></p>
			<a href="#" class="close" onclick="removeError();">close</a>
		</div>
        <?php } ?>
		<!-- End Message Error -->
	
	
		<br />
		<!-- Main -->
		<div id="main">
			<div class="cl">&nbsp;</div>
			
			<!-- Content -->
			<div id="content">
				
				<!-- Box --><!-- End Box -->
				
				<!-- Box -->
				<div class="box">
					<!-- Box Head -->
					<div class="box-head">
						<h2>Add New Article</h2>
					</div>
					<!-- End Box Head -->
					
					<form action="new-article.php?action=add" method="post" enctype="multipart/form-data">
						
						<!-- Form -->
						<div class="form">
								<p>
								  <label>Article Title <span>(Required Field)</span></label>
									<input name="ftitle" type="text" required class="field size1" id="ftitle" />
								</p>	
						  <p class="inline-field">
									<span class="req"></span>
                              <label>Article Page <span>(Required Field)</span></label>
							<select name="fpage" class="field size3a" id="fpage">
							  <option value="Home" selected="selected">Home</option>
							  <option value="Fee Structure">Fee Structure</option>
							  <option value="Contact">Contact</option>
							  <option value="Mission &amp; Vission">Mission &amp; Vission</option>
							  <option value="News">News</option>
                            </select>
						  </p>
						  <p>
								  <label>Picture <span>(Required Field)</span></label>
							<input name="fpic" type="file" id="fpic" required />
						  </p>		
								<p>
								  <label>Content <span>(Required Field)</span></label>
									<textarea name="fcontent" cols="30" rows="10" class="field size1" id="fcontent" required></textarea>
						  </p>	
							
						</div>
						<!-- End Form -->
						
						<!-- Form Buttons -->
						<div class="buttons">
							<input type="reset" class="button" value="reset" />
							<input type="submit" class="button" value="submit" />
						</div>
						<!-- End Form Buttons -->
					</form>
				</div>
				<!-- End Box -->

			</div>
			<!-- End Content -->
			
			<!-- Sidebar -->
			<div id="sidebar">
				
				<!-- Box -->
			  <div class="box">
					
					<!-- Box Head -->
					<div class="box-head">
						<h2>Management</h2>
					</div>
					<!-- End Box Head-->
					
					<div class="box-content">
				</div>
				</div>
				<!-- End Box -->
			</div>
			<!-- End Sidebar -->
			
			<div class="cl">&nbsp;</div>			
		</div>
		<!-- Main -->
	</div>
</div>
<!-- End Container -->
<?php include("inside/footer.php"); ?>
</body>
</html>