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

  	$where = "WHERE ativo = '1'";

	$result_cursos = "SELECT * FROM companies $where";
  	$resultado = $mysqli->query($result_cursos);

?>
<!DOCTYPE html>
<html lang="pt-br">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>Modal</title>
		<link href="css/bootstrap.min.css" rel="stylesheet">
		
	</head>
	<body>
		<div class="container theme-showcase" role="main">
			<div class="page-header">
				<h1>Listar Cursos</h1>
			</div>
			<div class="row">
				<div class="col-md-12">
					<table class="table">
						<thead>
							<tr>
								<th>#</th>
								<th>Nome do Curso</th>
								<th>Ação</th>
							</tr>
						</thead>
						<tbody>
							<?php while($rows_cursos = mysqli_fetch_assoc($resultado)){ ?>
								<tr>
									<td><?php echo $rows_cursos['id']; ?></td>
									<td><?php echo $rows_cursos['company']; ?></td>
									<td>
										<button type="button" class="btn btn-xs btn-primary" data-toggle="modal" data-target="#myModal<?php echo $rows_cursos['id']; ?>">Visualizar</button>
										
                                        <button type="button" class="btn btn-xs btn-warning" data-toggle="modal" data-target="#exampleModal" data-whatever="<?php echo $rows_cursos['id']; ?>" data-whatevernome="<?php echo $rows_cursos['company']; ?>"data-whateverdetalhes="<?php echo $rows_cursos['address']; ?>">Editar</button>
										
                                        <button type="button" class="btn btn-xs btn-danger">Apagar</button>
									</td>
								</tr>
								<!-- Inicio Modal -->
								<div class="modal fade" id="myModal<?php echo $rows_cursos['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
									<div class="modal-dialog" role="document">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
												<h4 class="modal-title text-center" id="myModalLabel"><?php echo $rows_cursos['popular_name']; ?></h4>
											</div>
											<div class="modal-body
                                            ">
												<p><?php echo $rows_cursos['id']; ?></p>
												<p><?php echo $rows_cursos['company']; ?></p>
												<p><?php echo $rows_cursos['address']; ?></p>
											</div>
										</div>
									</div>
								</div>
								<!-- Fim Modal -->
							<?php } ?>
						</tbody>
					 </table>
				</div>
			</div>		
		</div>
		
		<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
		  <div class="modal-dialog modal-lg" role="document">
			<div class="modal-content">
			  <div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="exampleModalLabel">Curso</h4>
			  </div>
			  <div class="modal-body">
              
				<form method="POST" action="processa.php" enctype="multipart/form-data">
                   
                   <div class="row">

                        <input name="id" type="hidden" class="form-control" id="id-curso" value="">

                         <div class="col-xs-2 col-md-offset-1">
                            <label for="tita">Titulo Grade</label>
                            <input type="text" class="form-control" id="recipient-name" name="grade" >
                        </div>

                         <div class="col-xs-2">
                            <label for="tita">Setor</label>
                            <input type="text" class="form-control" id="detalhes" name="setor" >
                        </div>
                         <div class="col-xs-5">
                            <label for="obsa">Obs</label>
                            <input type="text" class="form-control" id="obsa" name="obsa" >
                        </div>
                        <div class="form-group col-md-1">
                            <label for="ajua">%</label>
                            <input type="number" class="form-control" id="ajua" name="ajua">
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group col-md-2">
                            <label for="tda">32</label>
                            <input type="number" class="form-control" id="tda" name="tda" onBlur="soma();">
                        </div>
                        <div class="form-group col-md-2">
                            <label for="tqa">34</label>
                            <input type="number" class="form-control" id="tqa" name="tqa" onBlur="soma();">
                        </div>
                        <div class="form-group col-md-2">
                            <label for="tsa">36</label>
                            <input type="number" class="form-control" id="tsa" name="tsa" onBlur="soma();">
                        </div>
                        <div class="form-group col-md-2">
                            <label for="toa">38</label>
                            <input type="number" class="form-control" id="toa" name="toa" onBlur="soma();">
                        </div>
                    </div>
                    <div class="row">                    
                        <button type="button" class="btn btn-success" data-dismiss="modal">Cancelar</button>
                        <button type="submit" class="btn btn-danger">Alterar</button>
                    </div>
            </form>
			  
			</div>
		  </div>
		</div>


    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></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('ID ' + recipient)
		  modal.find('#id-curso').val(recipient)
		  modal.find('#recipient-name').val(recipientnome)
		  modal.find('#detalhes').val(recipientdetalhes)
		  
		})
	</script>
  </body>
</html>