<?php include 'header.php'; ?>

<?php include 'sidebar.php'; ?>

<div id="page-wrapper">

    <div class="container-fluid">

		<br/>

         <div class="row">

             <div class="col-lg-12">
				<div class="panel panel-default dash">
					<div class="panel panel-primary">
						<div class="panel-heading">
							<h2 class="sub-header">
								<i class="fa fa-picture-o" aria-hidden="true"></i> Publication
							</h2>
						</div>
						<!-- /.panel-heading -->
						<div class="panel-body">
							<div class="table-responsive">
							
								<div class="col-md-12">

									<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" class="form-horizontal" name="newPublication">
										<fieldset>
											<?php $csrf->echoInputField(); ?> 

                                            <!-- Text input -->
											<div class="form-group">
												<label class="col-md-2 control-label" for="category">Select faculty name  </label>
												<div class='col-md-6'> 
													<select class="form-control input-md" name="authors[]" multiple> 
													<?php 
												    $conection=mysqli_connect($host,$username,$password,$dbname);   
													  $qry=mysqli_query($conection, "select * from team");
													  while ($res=mysqli_fetch_array($qry)) {  $title=$res['name']; 							
													?>
													  <option value="<?php  echo $title; ?>">  <?php  echo $title; ?> </option> 
													<?php } ?>  
													</select> 
												</div>
											</div>
											 
											<div class="form-group">
												<label class="col-md-2 control-label" for="category"> Year of Publication</label>
												<div class='col-md-6'> 
													<select class="form-control input-md" name="yearpub" id="year"> 
												    <option value="">Select Year</option>
												<?php
												    $year_start  = 2020;
												    $year_end = (int)date('Y'); // current Year
												    $selected_year = 2020; // user date of birth year

												    for ($i_year = $year_end; $i_year >= $year_start; $i_year--) {
												      // Check if the current year should be selected
												        $selected = $selected_year == $i_year ? ' selected' : '';
												        echo '<option value="'.$i_year.'"'.$selected.'>'.$i_year.'</option>'."\n";
												    }
												?>
												</select>
												</div>
											</div>
											
											<!-- Text input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="name"> Select </label>
												<div class="col-md-6">
												<input type="radio" id="bookchapter" name="article" value="bookchapter"> Book Chapter
												<input type="radio" id="reviewarticle" name="article" value="reviewarticle"> Review Article
												<input type="radio" id="originalarticle" name="article" value="originalarticle"> Original Article
												</div>
											</div>
											
																	
											<!-- Text input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="name"> Select </label>
												<div class="col-md-6">
												<input type="radio" id="pubmed" name="pub" value="PubMed"> [Pub Med]
												<input type="radio" id="doi" name="pub" value="DOI"> [DOI] 
												<input id="name" name="publink" type="text" class="form-control input-md">
												</div>
											</div>					
											
								        	<!-- Text input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="name"> Book Title </label>
												<div class="col-md-6">  
												<textarea rows ='5' cols='10'  id="editor"  name='booktitle' type='text' class='form-control input-md'></textarea>
												</div>
											</div>	 

											<!-- Button -->
											<div class="form-group">
												<label class="col-md-10 control-label" for="singlebutton"></label>
												<div class="col-md-2">
													<input type="submit" name="newPublication" class="btn btn-primary" value="Save" />
												</div>
											</div>

										</fieldset>
									</form>
									<?php

										// Se o usuário clicou no botão cadastrar efetua as ações
										if (!empty($_POST['newPublication'])) 
										 {
											global $conection; 
											$authors = $_POST['authors']; 
											$yearpub = $_POST['yearpub']; 
											$article = $_POST['article']; 
											$pub = $_POST['pub']; 											
											$publink = $_POST['publink'];								
											$booktitle = $_POST['booktitle'];
											$checkbox1=$_POST['authors'];  
$chk="";  
foreach($checkbox1 as $chk1)  
   {  
      $chk .= $chk1.",";  
   }   
     

											  
											$sql = mysqli_query($conection,"INSERT INTO publication VALUES ('', '".$booktitle."', '".$chk."', 
												'".$yearpub."', '".$article."', '".$pub."', '".$publink."')");

													// Se os dados forem inseridos com sucesso			
													if (!$sql) {
													echo ("Can't insert into database: " . mysqli_error());
													return false;
													} else {
													echo "<script type='text/javascript'>swal('".lang('NICE')."', '".lang('ADDED')."', 'success');</script>";
													echo '<meta http-equiv="refresh" content="1; publication.php">'; 
													die();
													}		
													return true;

												// Se houver mensagens de erro, exibe-as
												if (count($error) != 0) {
													foreach ($error as $erro) {
														echo $erro . "<br />";
													}
												}
											} 
											
										?>

								</div>    
							</div>
						</div>
					</div>
				</div>
			</div>
        </div>
        <!-- /.row -->


    </div>
    <!-- /.container-fluid -->

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

</div>
<!-- /#wrapper -->

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