<?php 
require_once("sistema/conexao.php");
 ?>
<!DOCTYPE html>
<html>
<head>

	 <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">

	<link href="sistema/img/logo-icone.ico" rel="shortcut icon" type="image/x-icon">
	<link href="sistema/css/style.css" rel="stylesheet" type="text/css">

	<title><?php echo $nome_igreja_sistema ?></title>
</head>
<body>


	
	<img src="images/bannerindex.jpg" width="1600px" height="50px">
	
	

	<div class="row mx-2 mt-3" style="margin-right:10px">

		<?php 

		$query = $pdo->query("SELECT * FROM igrejas order by matriz desc, nome asc");
		$res = $query->fetchAll(PDO::FETCH_ASSOC);
		$total_reg = count($res);

		for($i=0; $i < $total_reg; $i++){
			foreach ($res[$i] as $key => $value){} 

				$nome = $res[$i]['nome'];
					//$pastor = $res[$i]['pastor'];
			$imagem = $res[$i]['imagem'];
			$matriz = $res[$i]['matriz'];
			$pastor = $res[$i]['pastor'];
			$id_ig = $res[$i]['id'];
			$url = $res[$i]['url'];

			if($matriz == 'Sim'){
				$bordacard = 'bordacardsede';
				$classe = 'text-danger';
				$texto_matriz = 'Matriz';
			}else{
				$bordacard = 'bordacard';
				$classe = 'text-primary';
				$texto_matriz = 'Filial';
			}

			$query_m = $pdo->query("SELECT * FROM membros where igreja = '$id_ig' and ativo = 'Sim'");
			$res_m = $query_m->fetchAll(PDO::FETCH_ASSOC);
			$membrosCad = @count($res_m);


			$query_con = $pdo->query("SELECT * FROM pastores where id = '$pastor'");
			$res_con = $query_con->fetchAll(PDO::FETCH_ASSOC);
			if(count($res_con) > 0){
				$nome_p = $res_con[0]['nome'];
			}else{
				$nome_p = 'Não Definido';
			}

			?>

			<div class="col-xl-3 col-md-6 col-12 mb-4 linkcard">
				<a href="igreja<?php echo $url ?>">
					<div class="card <?php echo $classe ?> shadow h-100 py-2 <?php echo $bordacard ?>">
						<div class="card-body">
							<div class="row no-gutters align-items-center">
								<div class="col mr-2">
									<div class="text-xs font-weight-bold <?php echo $classe ?> text-uppercase titulocard"><?php echo $nome ?></div>
									<div class="text-xs text-secondary subtitulocard"><b>PASTOR:</b> <?php echo mb_strtoupper($nome_p) ?> </div>
								</div>
								<div class="col-auto" align="center">
									<img src="sistema/img/igrejas/<?php echo $imagem ?>" width="50px" height="50px"><br>
									<span class="text-xs totaiscard <?php echo $classe ?>"><?php echo mb_strtoupper($texto_matriz) ?></span>
								</div>
							</div>
						</div>
					</div>
				</a>
			</div>



		<?php } ?>

	</div>

</body>
</html>