<?php
require('header.php');
require('connect.php');
?>
<script>
	function approve(id){
		$.ajax({
			method: 'POST',
			url: 'toDB.php',
			data: {id: id, user: '<?php echo $_SESSION['susername']; ?>', approve: 1},
			success: function(r){
				if(r==""){
					alertify.success('Η Ενέργεια ολοκληρώθηκε επιτυχώς!');
				} else {
					alertify.error(r);
				}
				$('#container').load(document.URL + ' #allpar_cont',function(){
					$('.datatable').DataTable();
				});
			}
		})
	}
</script>
<?php
$qry = "SELECT * FROM production";
$res = mysqli_query($dbC, $qry);
?>
<style>
	tr.blue{
		background-color:#007cc4 !important;
		color:white;
	}
</style>
<div id="container">
	<div class="panel panel-default" id="allpar_cont">
		<div class="panel-heading"><b>Πίνακας ελέγχων παραγωγής</b></div>
		<div class="panel-body">
			<div class="container">
				<table class="table table-striped table-bordered table-condensed bootstrap-datatable datatable dataTable table-responsive">
					<thead>
						<th style="text-align:center;">ID</th>
						<th style="text-align:center;">Ημ/νία Επεξεργασίας</th>
						<th style="text-align:center;">Ημ/νία Αναχώρησης</th>
						<th style="text-align:center;">Προϊόν</th>
						<th style="text-align:center;">Ελεγκτής</th>
						<th style="text-align:center;">Ενέργειες</th>
					</thead>
					<tbody>
						<?php
							while($row=mysqli_fetch_array($res)){
						?>
								<tr class="<?php echo ($row['pros_emporio']==1 ? 'blue' : '') ?>">
									<td><?php echo $row['id']; ?></td>
									<td><?php echo $row['hm_epex'] ?></td>
									<td><?php echo $row['hm_anaxwrhshs'] ?></td>
									<td><?php echo $row['proion']; ?></td>
									<td><?php echo $row['elegkths']; ?></td>
									<td>
										<div class="btn-group">
	  										<a href="controlpar_view.php?id=<?php echo $row['id']; ?>" class="btn btn-default">View</a>
	  										<a href="controlpar_view.php?id=<?php echo $row['id']; ?>&type=edit" class="btn btn-default">Edit</a>
	  										<a onclick="approve(<?php echo $row['id']; ?>)" class="btn btn-default">Προς Εμπόριο</a>
										</div>


									</td>
								</tr>
						<?php
							}
						?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
