<?php
	error_reporting(0);
	define('INCLUDE_CHECK',true);
	session_start();
	require ('classes/config.php');
	require_once('classes/session.php');
	
		
	
	if(isset($_POST['submit'])){
		         $author=$_POST['author'];
				$title = $_POST['title'];
				$year = $_POST['year'];
				$title2=$_POST['year2'];
				$volume=$_POST['volume'];
				$issues=$_POST['issues'];
				$pages=$_POST['pages'];
				//$downloadable = $_POST['downloadable'];
				$fileid = 'OSCO' . ($_SESSION['staffno']).'_' . ($title);
				
					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>Class notes must be uploaded 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 staff_journal (author,year,title,title2,volume,issues,pages,staff_id,date) 
										VALUES('$author','$year','$title','$title2','$volume','$issues','$pages','{$_SESSION['id']}',NOW())");
						$res = $conn->query($query);					
			}
	
      

?>
         
        <div id="page-wrapper" >
            <div id="page-inner">

                    <!-- /. ROW  -->
            <div class="row">
                <div class="col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Journal and Publications
                        </div>
                        <div class="panel-body">
                            <div class="panel-group" id="accordion">
                                <div class="panel panel-primary">
                                    <div class="panel-heading">
                                        <h4 class="panel-title">
                                            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" class="collapsed">Journals and Publications</a>
                                        </h4>
                                    </div>
                                    <div id="collapseOne" class="panel-collapse collapse" style="height: 0px;">
                                        <div class="panel-body">
                                            <form action="" method="post" enctype="multipart/form-data">
                                    		<div class="form-group">
                                              <label for="author">Author(s)</label>
                                              <input type="text" class="form-control" name="author" placeholder="Author">
                                            </div> 
                                            
                                            <div class="form-group">
                                              <label for="year">Year(s) of Publication</label>
                                              <input type="text" class="form-control" name="year" placeholder="Year(s) f Publication">
                                            </div> 
                                            
                                             <div class="form-group">
                                              <label for="title">Title of the Paper</label>
                                              <input type="text" class="form-control" name="title" placeholder="Title of the paper">
                                            </div> 
                                            
                                              <div class="form-group">
                                              <label for="title2">Journal Title</label>
                                              <input type="text" class="form-control" name="title2" placeholder="Journal title">
                                            </div>
                                            
                                             <div class="form-group">
                                              <label for="volume">Volume</label>
                                              <input type="text" class="form-control" name="volume" placeholder="Volume">
                                            </div>
                                            
                                             <div class="form-group">
                                              <label for="issues">Issues</label>
                                              <input type="text" class="form-control" name="issues" placeholder="Issues">
                                            </div>
                                            
                                            
                                             <div class="form-group">
                                              <label for="pages">Pages</label>
                                              <input type="text" class="form-control" name="pages" placeholder="Pages">
                                            </div>
                                            
                                            
                                         <!--   <div class="form-group">
                                                  	<label for="Journal / Publications"  ></label>
                                                 	<textarea name="topics" rows="4" class="form-control"  placeholder="Copy and paste the Journal, Publications and Seminars links or headings here " cols="50" required><?php //echo $address ?></textarea> </div>
                                            
                                            <div class="form-group">
                                              <label for="year">Year</label>
                                              <input type="text" class="form-control" name="year"placeholder="2016">
                                            </div> -->
                                          <!--  <div class="form-group">
                                                <label for="downloadable">Downloadable</label>
                                                <select class="form-control"  name="downloadable" data-placeholder="Downloadable: Yes/No">
                                                    <option value="" >-- Downloadable: Yes/No --</option> 
                                                    <option value="Yes">Yes</option>
                                                    <option value="No">No</option>
                                                </select>
                                            </div>                                             <div class="form-group">
                      								<label for="file" >Upload File <span style="color:#F00; font-size:11px;">only PDF</span></label>
                        							<input type="file" name="file" class="form-control" id="file" required>
                      							</div>-->
                    						
                                            
                                            
                                      
                                            
                                            
                                            
                                            <button type="submit" class="btn btn-primary" name="submit">Add</button>
                                            <button type="submit" class="btn btn-default">Reset</button>
                                    </form>
                                    <p>&nbsp;</p>
                                    
                                                               
                                    
                                    
                                    
                                    
                                    <div class="panel-body">
                                        <div class="form-group">
                                             <h4>List of Journals and Publications</h4>
                                             <table class="table table-striped table-bordered">
                                                <tr>
                                                	<th>S/N</th>
                                                    <th>Author</th>
                                                    <th>Year</th>
                                                    <th>Title of the Paper</th>
                                                     <th>Title of Journal</th>
                                                     <th>Volume</th>
                                                     <th>Issues</th>
                                                     <th>Pages</th>
                                                  <!-- <th>Download</th> -->
                                                    <th>OPTION</th>
                                                </tr>
									<?php
            
                                        $key="";
                                        if(isset($_POST['searchtxt']))
                                            $key=$_POST['searchtxt'];
                                        
                                        if($key !="")
                                            $sqlf=("SElECT * FROM staff_journal WHERE staff_id='{$_SESSION['id']}'");
                                        else
                                            $sqlf=("SElECT * FROM staff_journal WHERE staff_id='{$_SESSION['id']}'");
                                       	$res = $conn->query($sqlf);
                                            
                                           
                                        $i=0;
                                       // while($row=mysql_fetch_array($sqlf)){
                                      while($row = $res->fetch_assoc()) {
                                        $i++;
                                        $color=($i%2==0)?"lightblue":"white";
                                    ?>
                                                <tr>
                                                    <td><?php echo $i;?></td>
                                                    <td><?php echo $row['author'];?></td>
                                                    <td><?php echo $row['year'];?></td>
                                                    <td><?php echo $row['title'];?></td>
                                                    <td><?php echo $row['title'];?></td>
                                                    <td><?php echo $row['volume'];?></td>
                                                    <td><?php echo $row['issues'];?></td>
                                                    <td><?php echo $row['pages'];?></td>
                                                    <td><a href="#">Edit</a> | <a href="#">Delete</a></td>
                                                </tr>
                                          <?php }?>
                                             </table>

                                        </div>
                                 	</div>
                                    
                                    
                                    
                                    
                                           
                                        </div>
                                    </div>
                                </div>
                                
                                
                            </div>
                        </div>
                    </div>
                </div>
            </div>
                    <!-- /. ROW  -->



 

                 <hr />
               
    </div>
             <!-- /. PAGE INNER  -->
            </div>
         <!-- /. PAGE WRAPPER  -->
        </div>
     <!-- /. WRAPPER  -->
