
<link rel="stylesheet" href="../css/bootstrap.min.css" />
<?php include '../news/news_menu.php' /** calling of header(to make it uniform in all template file) **/?>
<?php
if( isset( $_POST['create'] ) ): /** A trigger that execute after clicking the submit 	button **/
				
			include '../connection.php'; /** calling of connection.php that has the connection code **/
			
				
						/*** Putting all the data from text into variables **/
				
				$title = $_POST['title']; 
				$details = $_POST['details'];
				$image = $_FILES['image']['name'];
				$temp = explode(".",$_FILES["image"]["name"]);
				$t=time();
				$newfilename = $t . '.' .end($temp);
				echo '<br>';
				
				$target_path = '../news/news_img/';
				$target_path = $target_path . $newfilename; 

				if(move_uploaded_file($_FILES['image']['tmp_name'], $target_path )) {
				mysql_query("INSERT INTO news(news_title,news_detail,news_image) 
							VALUES('$title','$details','$newfilename')") 
							or die(mysql_error()); /*** execute the insert sql code **/
							
				echo "<div class='alert alert-info'> Successfully Saved. </div>"; /** success message **/
				} else{
					echo "There was an error uploading the file, please try again!";
				}
				
		
			endif;
?>			
<div class="container home">
		<h3> Create New News </h3>		
		<form enctype="multipart/form-data"  action="" method="POST" >
			<label> Title: </label>
				<input type="text" placeholder="Title" class="input-medium" name="title"  style="width:525px;" />
			<label> Details: </label>
				<textarea class="span7" name="details"></textarea>
			<label>Image: </label> <input type="file" name="image" />
			<br><br>
			<input type="submit" name="create" value="Create New News" class="btn btn-info" />				
		</form>		
	</div>	
</div>
</body>
</html>
