<?php 
error_reporting(0);
ini_set(“display_errors”, 0 );
include "protege_professor.php";

	$idempreendimento = $_GET["idempreendimento"];
	$idusuario = $_SESSION['id_usuario'];



if(isset($_POST["percentual"])){
;
	$percentual 	    = $_POST["percentual"];
	$empreendedor_id 	= $_POST["empreendedor_id"];

 
	include "conexao.php";

	$inserir = mysqli_query($db, "INSERT INTO proprietarios (empreendimento_id, proprietario_id, percentual) values ('$idempreendimento','$empreendedor_id','$percentual')");

 $antecipar_t          = $_POST["idparcelas"];
      // echo " antecipar...".$antecipar_t; die();
      // echo "<pre>";
      // print_r($_GET);
      // echo "</pre>"; die();
                 

                    $numero_parcela   = implode(',', $_POST['antecipar']);

          date_default_timezone_set('America/Sao_Paulo');              
                $data_log = date('d-m-Y H:i:s');         // data e hr no momento
                $nome_usuario = nome_user1($idusuario); //nome usuario sessao
                $cli_nome     = nome_user1($empreendedor_id);
                $descricao_log = "Usuário ".$nome_usuario ." cadastrou o proprietário : ".$cli_nome." com participação de : ".$percentual." %.";
                grava_log($data_log,$idusuario,$descricao_log);
                //echo "cheguei aqui...;".$descricao_log; die();

}


//#########################################  Funcoes Grava Log   #############################################

function nome_user1($id){
            include "conexao.php";
                 $query_igpm = "SELECT nome_cli FROM cliente where idcliente = $id";

                 $executa_igpm = mysqli_query ($db, $query_igpm);


                   while ($buscar_amigoc = mysqli_fetch_assoc($executa_igpm)) {//--verifica se são amigos

                          $nome_cli        = $buscar_amigoc['nome_cli'];
                   }
                   return $nome_cli;

         } 


        function grava_log($data_log,$usuario_id,$descricao_log){
           include "conexao.php";
          
                $query_log = "insert into log (data_log,usuario_id,descricao_log) values('$data_log','$usuario_id','$descricao_log')";
                $executa_log = mysqli_query($db, $query_log);
                return 1;
        }


   



//######################################### " FIM " Funcoes Grava Log   ######################################




?>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if !IE]><!-->
<html>
<!--<![endif]-->


<head>
	<meta charset="utf-8" />
	<title>Immobile | Business</title>
	<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport" />
	<meta content="" name="description" />
	<meta content="" name="author" />
	
	<!-- ================== BEGIN BASE CSS STYLE ================== -->
	<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet">
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/jquery-ui/themes/base/minified/jquery-ui.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/css/animate.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/css/style.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/css/style-responsive.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/css/theme/default.css" rel="stylesheet" id="theme" />
	<!-- ================== END BASE CSS STYLE ================== -->
	
	<!-- ================== BEGIN BASE JS ================== -->
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/media/css/dataTables.bootstrap.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/css/buttons.bootstrap.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Responsive/css/responsive.bootstrap.min.css" rel="stylesheet" />
	<!-- ================== END PAGE LEVEL STYLE ================== -->
	
	<!-- ================== BEGIN BASE JS ================== -->
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/pace/pace.min.js"></script>
	<!-- ================== END BASE JS ================== -->
</head>
<body>
	<!-- begin #page-loader -->
	<div id="page-loader" class="fade in"><span class="spinner"></span></div>
	<!-- end #page-loader -->
	
	<!-- begin #page-container -->
	<div id="page-container" class="fade page-header-fixed page-sidebar-fixed">
	
	<?php  include "topo.php"; ?>

	<?php

	function busca_locador($idcliente, $idimovel){

		include "conexao.php";
		$busca = "SELECT locador_idlocador FROM imovel WHERE locador_idlocador = $idcliente AND idimovel = $idimovel";
		$executa = mysqli_query($db, $busca);

		 while ($row_comissao = mysqli_fetch_assoc($executa)) {
        
        $locador_idlocador = $row_comissao['locador_idlocador'];

    	} 

    	return $locador_idlocador;

	}

	?>
		<div class="sidebar-bg"></div>
		<!-- end #sidebar -->
		
		<!-- begin #content -->
		<div id="content" class="content">
			<!-- begin breadcrumb -->
		
				
			<!-- end breadcrumb -->
			<!-- begin page-header -->
		
			<!-- end page-header -->
			
			<!-- begin row -->
			<div class="row">



			    <!-- begin col-6 -->
			    <div class="col-md-12">
				
					<!-- <div class="tab-content"> -->
						<!-- <div class="tab-pane fade active in" id="default-tab-1"> -->
<!-- 	cliquei aqui -->


				   <div class="col-md-12">
			        <!-- begin panel -->
                    <div class="panel panel-inverse" data-sortable-id="form-plugins-11">
                        <div class="panel-heading">
                            <div class="panel-heading-btn">
                                <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-default" data-click="panel-expand"><i class="fa fa-expand"></i></a>
                                <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-success" data-click="panel-reload"><i class="fa fa-repeat"></i></a>
                                <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-warning" data-click="panel-collapse"><i class="fa fa-minus"></i></a>
                                <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-danger" data-click="panel-remove"><i class="fa fa-times"></i></a>
                            </div>
                            <h4 class="panel-title">Cadastro de Proprietários</h4>
                        </div>
                        <div class="panel-body panel-form">
                            <form class="form-horizontal form-bordered" action="proprietario_empreendedor.php?idempreendimento=<?php echo $idempreendimento ?>" method="POST">
                               
                                                        		  

                                  <div class="form-group">
                            
                                    <div class="col-md-9">
                                         <select class="form-control" name="empreendedor_id" required>
                                            <option value="">Selecione</option>
                                        
                                       
                                        <?php 

                include "conexao.php";
                $query_slide = mysqli_query($db,"SELECT * FROM cliente
                                                 INNER JOIN cliente_tipo ON cliente.idcliente = cliente_tipo.idcliente 
                                                 INNER JOIN tipo_cliente ON cliente_tipo.idtipo = tipo_cliente.idtipo 
                                                 where cliente_tipo.idtipo = 1 group by cliente.idcliente
") or die ("Erro ao listar Locador, tente mais tarde"); 


            while ($buscar_slide = mysqli_fetch_assoc($query_slide)) {
           
             $idcliente  = $buscar_slide["idcliente"];
             $nome_cli   = $buscar_slide["nome_cli"];

                    ?> 
                                            <option value="<?php echo $idcliente ?>"><?php echo $nome_cli ?></option>
                                           <?php } ?>
                                           

                                        </select>
                                    </div>
                                </div>


                                  <div class="form-group">
                            
                                    <div class="col-md-9">
                                       <input type="text" class="form-control" name="percentual" id="percentual"  placeholder="Percentual de participação" required="" />
                                    </div>
                                </div>

                            
                                  <div class="form-group">
                            
                                    <div class="col-md-9">
                                       <input type="submit" class="btn btn-success m-r-5 m-b-5" name="atualiza" value="Cadastrar" />
                                    </div>
                                </div>

                             




                              





                              






                         
                        </div>
                    </div>
                    <!-- end panel -->
                </div>




							 <div class="col-md-12">
			        <!-- begin panel -->
                    <div class="panel panel-inverse">
                        <div class="panel-heading">
                            <div class="panel-heading-btn">
                                <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-default" data-click="panel-expand"><i class="fa fa-expand"></i></a>
                                <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-success" data-click="panel-reload"><i class="fa fa-repeat"></i></a>
                                <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-warning" data-click="panel-collapse"><i class="fa fa-minus"></i></a>
                                <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-danger" data-click="panel-remove"><i class="fa fa-times"></i></a>
                            </div>
                            <h4 class="panel-title">Proprietários do Imóvel</h4>
                        </div>
                        
                        <div class="panel-body">
                            <table id="" class="table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th>Nome </th>
                                          <th>% de Participação </th> 
                                           <th> </th>
                                         
                                         
                                        
                                    </tr>
                                </thead>

                                      <tbody>
                              	<?php 

								

				include "conexao.php";
				$query = mysqli_query($db,"SELECT * FROM proprietarios
									  WHERE empreendimento_id = $idempreendimento") or die ("ERRO ao listar Imóveis"); 


		    while ($buscar = mysqli_fetch_assoc($query)) {//--While categoria
		   
		     $idproprietarios 		= $buscar["idproprietarios"];
		     $proprietario_id 		= $buscar["proprietario_id"];
		     $percentual 			= $buscar["percentual"];
		      
		

		     $verifica_titular = busca_locador($proprietario_id, $idimovel);


													?>

                          
                                    <tr class="odd gradeX">
                                        <td><?php echo nome_user($proprietario_id) ?></td>
                                        <td><?php echo $percentual ?>%</td>
                                         <td>

                                         	<?php if($verifica_titular == ''){ ?>

                                         	<a href="excluir_proprietario_empreendimento.php?idproprietarios=<?php echo $idproprietarios ?>&idempreendimento=<?php echo $idempreendimento ?>&proprietario=<?php echo $proprietario_id ?>"><span class="btn btn-danger">Remover</span></a>



                                         	<a href="editar_proprietario_empreendedor.php?idproprietarios=<?php echo $idproprietarios ?>&idempreendimento=<?php echo $idempreendimento ?>&proprietario=<?php echo $proprietario_id ?>"><span class="btn btn-warning">Editar</span></a></td>
                                      		
                                      		<?php }else{ ?>

                                      		<span class="btn btn-primary">Proprietário Titular</span>

                                      		<?php } ?>

                                    </tr>
                                   <?php } ?>


                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!-- end panel -->
                </div>
						</div>




<!-- inicio da aba de parcelas -->


						<div class="tab-pane fade" id="default-tab-2">
							


						</div>
						<div class="tab-pane fade" id="default-tab-3">
							
						</div>
					</div>
					
				</div>
			    <!-- end col-6 -->
			 
			</div>
			<!-- end row -->
		</div>
		<!-- end #content -->
		
        <!-- begin theme-panel -->
     
        <!-- end theme-panel -->
		
		<!-- begin scroll to top btn -->
		<a href="javascript:;" class="btn btn-icon btn-circle btn-success btn-scroll-to-top fade" data-click="scroll-top"><i class="fa fa-angle-up"></i></a>
		<!-- end scroll to top btn -->
	</div>
	<!-- end page container -->
	
	<!-- ================== BEGIN BASE JS ================== -->
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery/jquery-1.9.1.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/js/jquery.maskMoney.js" type="text/javascript"></script>

 <script type="text/javascript">

$(function(){
$("#preco").maskMoney({symbol:'R$ ', 
showSymbol:true, thousands:'.', decimal:',', symbolStay: true});
 })



$("#percentual").maskMoney({symbol:'', 
showSymbol:true, thousands:'.', decimal:'.', symbolStay: true});


</script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery/jquery-migrate-1.1.0.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery-ui/ui/minified/jquery-ui.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap/js/bootstrap.min.js"></script>
	
<script src="https://immobilebusiness.com.br/admin/assets/plugins/slimscroll/jquery.slimscroll.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery-cookie/jquery.cookie.js"></script>
	<!-- ================== BEGIN PAGE LEVEL JS ================== -->
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/media/js/jquery.dataTables.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/media/js/dataTables.bootstrap.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/js/dataTables.buttons.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/js/buttons.bootstrap.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/js/buttons.flash.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/js/jszip.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/js/pdfmake.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/js/vfs_fonts.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/js/buttons.html5.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/js/buttons.print.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Responsive/js/dataTables.responsive.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/js/table-manage-buttons.demo.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/js/apps.min.js"></script>
	<!-- ================== END PAGE LEVEL JS ================== -->
	
	<script>
		$(document).ready(function() {
			App.init();
			TableManageButtons.init();
		});
	</script>

</body>


</html>
