<?php
require 'app/bootstrap.php';
$conectDB = connectDB();
$conectDB->exec("set names utf8mb4");
include '__valida_login.php';
?>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <title><?=$configSistema['sistema'];?> - Mensagens Recebidas</title>
	<?php
		include 'estrutura/__css.php';
	?>
	<style type="text/css">
		.frmVerMensagem{display: none}
		a .fa{line-height: 40px !important}
	</style>
</head>
<body>
    <div class="app ">
        <div class="layout  ">
			<?php
				include 'estrutura/topo.php';
				include '_menu.php'; 
			?>
            <div class="page-container">
                <div class="main-content">
                     
                   <div class="card  ">
                        <div class="card-body"> 
							 
							<div class="row">
								<div class="col-xs-12 col-lg-12">
									<h1> Leads</h1>
 								</div> 
							</div>
								 
                            <div class="">
								<div class=" ">
									  

									<?php
										$searchItem  = query($conectDB, '', "
											select
												*,
												lead.codigo as mensagemCodigo,
												lead.id as mensagemID
											from
												lead,
												imovel
											WHERE
												usuario_imovel_id = '{$_SESSION['userID']}' and
												imovel_id = imovel.id
										");

										//print_r($searchItem);
										if( count($searchItem) <= 0 ){
											echo '
												<div class="col-md-12 text-center">
													<h4>nenhuma lead encontrado</h4>
													<lottie-player src="https://assets6.lottiefiles.com/packages/lf20_dmw3t0vg.json"  background="transparent"  speed="1"  style="width: 100%; height: 300px;"  loop  autoplay></lottie-player>
												</div>
											';
										}
										else
										{
											echo 
											'
											<table class="table  table-bordered table-hover " id="sample_lead" style="width: 100%">
												<thead>
													<tr>
														<th class="all"> Imóvel</th>
		   												<th class="all"> Nome</th>
														<th class="all"> Contatos</th>
														<th class="all"> Mensagem</th>
														<th class="all"> Cadastrado </th>
														<th class="all">  </th>
													</tr>
												</thead>
												<tbody>
											';
												foreach($searchItem as $value)
												{
													echo 
													'
														<tr >
																<td style="width: 200px"><a href="imoveis/detalhes/'.$value->codigo.'">'.$value->titulo.'</a></td>
																<td >'.$value->cliente_nome.'</td>
																<td >'.$value->cliente_telefone.'<br>'.$value->cliente_email.'</td>
 																<td >
																		<span class="mensagemVisualiza" mensagem="'.$value->mensagemID.'">'.texto($value->cliente_mensagem, 30).'</span>
																	    <form method="post" id="frmVerMensagem_'.$value->mensagemID.'" class="frmVerMensagem" action="app/imovel/mensagens/visualiza">
																	    	<input type="hidden" name="mensagemVisualiza">
																	    	<input type="hidden" name="mensagem" value="'.$value->mensagemCodigo.'">
																	    	<button type="button" class="submit">ver</button>
																	    </form>
																</td>
 																<td >'.date("d/m/Y H:i", strtotime($value->cadastro)).'</td>
																<td class="text-center">
																	<a href="leads/detalhes/'.$value->mensagemCodigo.'" class=" btn btn-icon btn-primary btn-xs btn-rounded btn-tone">
																	    <i class="fa fa-eye"></i>
																	 </a>

																	
																	<button class="btn btn-icon btn-danger btn-xs btn-rounded btn-tone">
																	    <i class="fa fa-times"></i>
																	</button>
																</td>
														</tr>
													';
												}
											echo 
											'
												</tbody>
											</table>
											';
										}
									?>

								</div>
							</div>
						</div>
					</div>
                </div>
				
				<?php include 'estrutura/copy.php';?>	
            </div>
         </div>
    </div>
	<?php include 'estrutura/rodape.php';?>
	<?php include 'estrutura/_modal_admin.php';?>
	



	 <!-- Modal Nova Classe -->
	<div class="modal fade" id="modalRemoveEmpresa">
		<div class="modal-dialog modal-dialog-centered">
			<div class="modal-content">
				<div class="modal-header  text-center">
					<h5 class="modal-title" id="">Remoção de registro</h5>
					<button type="button" class="close" data-dismiss="modal">
						<i class="anticon anticon-close"></i>
					</button>
				</div>
				<div class="modal-body">
					<form method="post" id="modalClasseFormPost" action="php/sistema.php">
						<h2>Deseja remover este registro</h2>
						O registro da professor e todas as suas informações serão desativadas no sistema
						<div class="form-group row">
							<div class="col-sm-6">
								 
								<a href="#" id="modalRemoveEmpresaLink" class="btn  btn-primary m-r-5 ">
									<i class="anticon anticon-loading m-r-5"></i>
									<i class="anticon anticon-check m-r-5"></i>
									<span>Remover</span>
								</a>
							</div>
 
						</div>
					</form>
				</div> 
			</div>
		</div>
	</div>



	 <!-- ver mensagem -->
	<div class="modal fade" id="modalMensagem">
		<div class="modal-dialog modal-dialog-centered modal-xl">
			<div class="modal-content">
				<div class="modal-header  text-center">
					<h5 class="modal-title" id="">Mensagem</h5>
					<button type="button" class="close" data-dismiss="modal">
						<i class="anticon anticon-close"></i>
					</button>
				</div>
				<div class="modal-body">
  					<div id="modalMensagemVisualizaMnesagem"></div>
  				</div> 
 
			      <div class="modal-footer">
			        <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
			      </div>
			</div>
		</div>
	</div>

	<script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js" type="text/javascript"></script>
	<script src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js" type="text/javascript"></script>
	
	<script src="https://cdn.datatables.net/fixedheader/3.1.9/js/dataTables.fixedHeader.min.js" type="text/javascript"></script>
	<script src="https://cdn.datatables.net/responsive/2.2.9/js/dataTables.responsive.min.js" type="text/javascript"></script>
	<script src="https://cdn.datatables.net/responsive/2.2.9/js/responsive.bootstrap.min.js" type="text/javascript"></script>
	
	<script src="https://cdn.datatables.net/responsive/2.2.9/css/responsive.bootstrap.min.css" type="text/javascript"></script>
	<link href="https://cdn.datatables.net/fixedheader/3.1.9/css/fixedHeader.bootstrap.min.css" rel="stylesheet" type="text/css" />
	<link href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css" />

 

 	<script>
	$(document).ready(function() {
		var table = $('#sample_lead').DataTable( {
            dom: 'Bfrtip',
            //buttons: { buttons: [ { extend: 'copy', className: 'btn btn-primary btn-tone'}, { extend: 'csv', className: 'btn btn-primary btn-tone' } ]},
            "language": {
                "aria": {
                    "sortAscending": ": activate to sort column ascending",
                    "sortDescending": ": activate to sort column descending"
                },
                "emptyTable": "Nenhum registro encontrado",
                "info": "Mostrando _START_ de _END_ de _TOTAL_ registros",
                "infoEmpty": "Sem registros",
                "infoFiltered": "(filtered1 from _MAX_ total registros)",
                "lengthMenu": "_MENU_ registros",
                "search": "Buscar:",
                "zeroRecords": "Nenhum registro"
            },
            "language": {
               url: '//cdn.datatables.net/plug-ins/3cfcc339e89/i18n/Portuguese.json'
            },
            responsive: true,

            "order": [
                [4, 'desc']
            ],
            
            "lengthMenu": [
                [5, 30, 50, 100, -1],
                [5, 30, 50, 100, "Todos"] // change per page values here
            ],
            // set the initial value
            "pageLength": 50,
 

 
		});
	  
	} );
 
	</script>
	
	<script>
		$(".removeItemEmpresa").on("click", function()
		{
			$("#modalRemoveEmpresa").modal("show");
			$("#modalRemoveEmpresaLink").attr("href", $(this).attr("link") );
		});
		$(".mensagemVisualiza").on("click", function()
		{
			var mensagem = $(this).attr("mensagem");
			$("#frmVerMensagem_"+mensagem+" .submit").trigger("click");

			$("#modalMensagemVisualizaMnesagem").html('<i class="fas fa-circle-notch fa-spin"></i> por favor, aguarde...');
			$("#modalMensagem").modal("show");
			
		});

	</script>
</body>

</html>

