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

	if(isset($_POST['submit'])){
				$ptitle = $_POST['ptitle'];
				$pauthor = $_POST['pauthor'];
				$issues_id = $_POST['issues_id'];
				$fileid2 = 'OJASS'." ".($issues_id)." ".($ptitle);
				$fileid3 = ereg_replace(':','_',$fileid2);
				$fileid = ereg_replace(' ','_',$fileid3);

				define ("filesplace","./journal/");

					 if (is_uploaded_file($_FILES['file']['tmp_name'])) {
					
					 if ($_FILES['file']['type'] == "application/pdf") {
						$name = $fileid;
						$u_ext = 'pdf';
					 	$result = move_uploaded_file($_FILES['file']['tmp_name'], filesplace."/$name.$u_ext");
					 //echo "<p>uploadable Journals must be in PDF format.</p>";
					 
					 if ($result == 1) echo "<p>Upload done .</p>";
					 else echo "<p>Sorry, Error happened while uploading . </p>";
					} #endIF
					 } #endIF		
					
				$filedoc = filesplace."$name.$u_ext";	
				$query = ("INSERT INTO pub (title,author,pdf_pat,issues_id,uploaded_date) 
										VALUES('$ptitle','$pauthor','$filedoc','$issues_id',NOW())");
					$res1 = $conn->query($query);		
			}


?>	
				<div id="content">
                	<h2 class="title">Add Journal</h2>
                    <br>
                    
                      <form action="" method="post" role="form" class="contactForm" enctype="multipart/form-data">
                         <table >
                    	<tr><td>
                            <div class="form-group">
                                <label>Select Issues:</label>
                                <select name="issues_id"  class="form-control" required>
                                    <option value="">-- Select Publication Issue -- </option>
                                        <?php 
                                            $getcissues = ("SELECT * FROM issues");
                                             $ans = $conn->query($getcissues);
                                          //  while($rowissues = mysql_fetch_array($getcissues)){
                                                
                                          while($rowissues = $ans->fetch_assoc()) {      
                                                
                                        ?>
                                            <option value="<?php echo $rowissues['id'] ?>"><?php echo $rowissues['year']?></option>
                                        <?php
                                            }
                                    ?>
                                </select>
                            </div>
                   	</td></tr></table> 
                    <br />
                    <table >
                    	<tr><td>
                        <div class="entry">
                        <div class="form-group">
                        <label>Title:</label>
                            <input type="text" name="ptitle" 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>Author:</label>
                            <input type="text" name="pauthor" class="form-control" placeholder="Authors Name" 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>Attach PDF File :</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">Add Journal</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'); ?>	