<?php 
session_start();
include('head.php'); 
if(isset($_SESSION['login_user'])==""){
header("Location:admin.php");
}

if (isset($_POST['Submit']))
{
	$ititle = $_POST['ititle'];
	$iyear = $_POST['iyear'];
	$ivolume = $_POST['ivolume'];

	if (isset($_FILES["file"]["name"])){
							$name = $_FILES["file"]["name"];
							$filename = $_FILES["file"]["name"];
							$file_ext = substr($filename, strripos($filename, '.'));
							$u_ext=strtoupper($file_ext);
							if ($u_ext== ".JPG"){
							$DestinationDir="./covers/";
							$destination=$DestinationDir.$iyear.$file_ext;
							$image[]=$destination;
							$IMG = 300;
							resize($_FILES["file"]['tmp_name'],$IMG, $destination);
							$pat = $destination;
							$pattrim = explode(" ", $pat);
							}
	}
	$query = ("INSERT INTO issues (title,year,volume,path,createdby,date_created) 
										VALUES('$ititle','$iyear','$ivolume','$pattrim','{$_SESSION['id']}',NOW())");
		 $res = $conn->query($query); 
	
	
}
//$conn->close();
?>	
				<div id="content">
                	<h2 class="title">Add Issues</h2>
                    <br>
                    <table >
                    	<tr><td>
                        <div class="entry">
                        <form action="" method="post" role="form" class="contactForm" enctype="multipart/form-data">
                        <div class="form-group">
                        <label>Issue Title:</label>
                            <input type="text" name="ititle" class="form-control" placeholder="Issue Title" data-rule="minlen:4" data-msg="Please enter at least 4 chars" autocomplete="off" required/>
                            <div class="validation"></div>
                        </div><br>
                        <div class="form-group">
                        <label>Issue Year:</label>
                            <input type="text" name="iyear" class="form-control" placeholder="September 2017" data-rule="minlen:4" data-msg="Please enter at least 4 chars" autocomplete="off" required />
                            <div class="validation"></div>
                        </div><br>
                        <div class="form-group">
                        <label>Issue Volume No:</label>
                            <input type="text" name="ivolume" class="form-control" placeholder="Vol. 3 No. 1" data-rule="minlen:4" data-msg="Please enter at least 4 chars" autocomplete="off" required />
                            <div class="validation"></div>
                        </div><br>
                        <div class="form-group">
                        <label>Issue Back Cover Image:</label>
                            <input type="file" name="file" class="form-control" data-rule="minlen:4" data-msg="Please enter at least 4 chars" autocomplete="off" required />
                            <div class="validation"></div>
                        </div><br>                 
                        <div class="text-center"><button type="submit" name="Submit" class="btn">Login</button></div>
                       
                    </form>
                    </div>
                </td></tr></table> 
					<div style="clear: both;">&nbsp;</div>
				</div>
				<!-- end #content -->
            	
				<?php include('r_side_bar.php'); ?>	

		</div>
	</div>
	<!-- end #page -->   
</div>

<?php include('footer.php'); ?>	