<?php 
	if(!isset($_SESSION))
		session_start();
	if (!isset($_SESSION['usuarioLogin']) || $_SESSION['usuarioLogin'] == ""){
		session_unset();
		session_destroy();
		header("Location: login.php");
		exit();
	}
?>
<?php
	require_once('../../Connections/catalogo.php');
	
	$palabras = $mysqli->query("SELECT * FROM idiomas WHERE idioma = 'es' ORDER BY palabra");
	
	$idiomas = $mysqli->query("SELECT DISTINCT idioma FROM idiomas");
	
	if(!$idiomas)
		echo "Error: " . $mysqli->error;	
?> 
<div class="heading">
    <div class="col">Editar</div>
    <div class="col">Palabra</div>
    <?php
    while ($rowIdiomas = $idiomas->fetch_object()){ ?> 
		<div class="col"><?php echo $rowIdiomas->idioma ?></div>
    <?php
	}
	?>
    <div class="col">Eliminar</div>
</div>
<?php 
if ($palabras->num_rows > 0){
	while ($row = $palabras->fetch_object()){ 
	?>
		<div class="table-row">
			<div class="col">
            	<a href='javascript:MostrarAltaEditar("idiomas", <?php echo $row->id ?>)'>
            		<img src="imagenes/editar.png" width="48" height="48" />
               	</a>
           	</div> 
			<div class="col"><?php echo $row->palabra ?></div> 
			<?php
			$idiomas = $mysqli->query("SELECT DISTINCT idioma FROM idiomas");
			while ($rowIdiomas = $idiomas->fetch_object()){ ?> 
				<div class="col">
					<?php
						$traduccion = $mysqli->query("SELECT traduccion FROM idiomas WHERE idioma = '" . $rowIdiomas->idioma . "' AND palabra = '" . $row->palabra . "'");
						$palabraTrad = $traduccion->fetch_object();
						echo $palabraTrad->traduccion; 
					?>
                </div>
			<?php
            }
            ?> 
			<div class="col">
            	<a href='javascript:confirmarEliminar("idiomas", "<?php echo $row->palabra ?>")'>	
                	<img src="imagenes/power-on-off.png" width="48" height="48" />
                </a>
            </div>
		</div>           
	<?php
	}
}   
else{
	echo "No existen palabras de idioma.";
}
?>
                

