<?php
    session_start();
	ob_start();

	$id_users = isset($_SESSION['id_users']) ? $_SESSION['id_users']: "";	
	$nome_user = isset($_SESSION['nome']) ? $_SESSION['nome']: "";	
	$email_users = isset($_SESSION['email']) ? $_SESSION['email']: "";	
	$pass_users = isset($_SESSION['pass']) ? $_SESSION['pass']: "";	
	$logado = isset($_SESSION['logado']) ? $_SESSION['logado']: "N";	

	if ($logado == "N" && $id_users == ""){	    
		echo  "<script type='text/javascript'>
					location.href='login.php'
				</script>";	
		exit();
	}

	require 'conexion.php';
	require_once('functions.php');

    $sql = "SELECT * FROM tecidos WHERE ativo = '1' ORDER BY tecido";
    
    include(HEADER_TEMPLATE);
	//<h3 style="text-align:center">ORDEM DE CORTE e PRODUÇÃO</h3>    
?>

			<div class="container-fluid">
            
				<table class="table table-hover" id="tabelaTecidos" >
					<thead>
						<tr>
							<th>ID</th>
							<th>Fornecedor</th>
							<th>Tecido</th>
                            <th>Composição</th>
							<th>Cor</th>
							<th>UM</th>
							<th>Largura</th>
							<th></th>
							<th></th>
						</tr>
					</thead>
					
					<tbody>
                            <?php 
                            $resultado = $mysqli->query($sql);
                            while($row = $resultado->fetch_array(MYSQLI_ASSOC)) { ?>
                                <tr>
                                    <td><?php echo $row['id_tecido']; ?></td>
                                    <td><?php echo $row['fornecedor']; ?></td>
                                    <td><?php echo $row['tecido']; ?></td>
                                    <td><?php echo $row['composicao']; ?></td>
                                    <td><?php echo $row['cor']; ?></td>
                                    <td><?php echo $row['unidade']; ?></td>
                                    <td><?php echo $row['largura']; ?></td>
                                    <td><a href="tecido_view.php?id=<?php echo $row['id_tecido']; ?>"><span class="glyphicon glyphicon-eye-open"></span></a></td>
                                    <td><a href="#" data-href="eliminar.php?id=<?php echo $row['id_tecido']; ?>&x=2" data-toggle="modal" data-target="#confirm-delete"><span class="glyphicon glyphicon-trash"></span></a></td>
                                </tr>
                            <?php } ?>

                    </tbody>
				</table>
				<a href="tecido_novo.php?" class="btn btn-primary">Cadastrar Tecido</a>
            </div>
                    <!-- Modal -->
                    <div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                    <h4 class="modal-title" id="myModalLabel">Eliminar Registro</h4>
                                </div>
                                
                                <div class="modal-body">
                                    Deseja eliminar este registro?
                                </div>
                                
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancela</button>
                                    <a class="btn btn-danger btn-ok">Elimina</a>
                                </div>
                            </div>
                        </div>
                    </div>                
            
            
    <?php include(FOOTER_TEMPLATE); ?>  
    
<script>
    $('#confirm-delete').on('show.bs.modal', function(e) {
        $(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));
        
        $('.debug-url').html('Delete URL: <strong>' + $(this).find('.btn-ok').attr('href') + '</strong>');
    });
</script>	
    <script type="text/javascript">
        $('#exampleModal').on('show.bs.modal', function (event) {
          var button = $(event.relatedTarget) // Button that triggered the modal
          var recipient = button.data('whatever') // Extract info from data-* attributes
          var recipientnome = button.data('whatevernome')
          var recipientdetalhes = button.data('whateverdetalhes')
          // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
          // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
          var modal = $(this)
          modal.find('.modal-title').text('Pedido Nr.: ' + recipient)
          modal.find('#pedidoID').val(recipient)
          modal.find('#recipient-name').val(recipientnome)
          modal.find('#detalhes').val(recipientdetalhes)
        })
    </script>
<?php include(FOOTER_TEMPLATE); ?>      
	<script type="text/javascript">		
		$(document).ready(function() {
			$('#tabelaTecidos').DataTable( {
				"order": [[1, "desc"]],
						"language":{
							"lengthMenu": "Mostrar _MENU_ registros por página",
							"info": "Mostrando pagina _PAGE_ de _PAGES_",
							"infoEmpty": "Sem registros para serem mostrados",
							"infoFiltered": "(filtrada de _MAX_ registros)",
							"loadingRecords": "Lendo...",
							"processing":     "Procesando...",
							"search": "Buscar:",
							"zeroRecords":    "Não se encontra registros com esta caracterísica",
							"paginate": {
								"next":       ">>",
								"previous":   "<<"
						}},                  
			"columnDefs": [
				{
					"targets": [ 0 ],
					"visible": true,
					"searchable": true
				}
				]
			} );
		} );
		</script>   
