<?php
include 'conexao.php';

function nl2p($string, $line_breaks = true, $xml = true) {
    $string = str_replace(array('<p>', '</p>', '<br>', '<br />'), '', $string);

// It is conceivable that people might still want single line-breaks
// without breaking into a new paragraph.
    if ($line_breaks == true)
        return '<p>'.preg_replace(array("/([\n]{2,})/i", "/([^>])\n([^<])/i"), array("</p>\n<p>", '$1<br'.($xml == true ? ' /' : '').'>$2'), trim($string)).'</p>';
    else
        return '<p>'.preg_replace(
                array("/([\n]{2,})/i", "/([\r\n]{3,})/i","/([^>])\n([^<])/i"),
                array("</p>\n<p style='margin-top: 10px;'>", "</p>\n<p style='margin-top: 10px;'>", '$1<br'.($xml == true ? ' /' : '').'>$2'),
                trim($string)).'</p>';
}

$sql_consult = $sqli->query("SELECT * FROM empresas WHERE id='".$_GET['id']."'");
$row_consult = $sql_consult->fetch_assoc();

$sql_atividade = $sqli->query("SELECT * FROM atividades WHERE id='".$row_consult['id_atividade']."'");
$row_atividade = $sql_atividade->fetch_assoc();

$sql_grupos = $sqli->query("SELECT * FROM grupos WHERE id='".$row_consult['id_grupo']."'");
$row_grupos = $sql_grupos->fetch_assoc();

$sql_setores = $sqli->query("SELECT * FROM setores WHERE id='".$row_consult['id_setor']."'");
$row_setores = $sql_setores->fetch_assoc();
?>



<div class="toggle" data-plugin-toggle data-plugin-options='{ "isAccordion": false }'>


    <!-- DADOS INICIAIS -->
    <section class="toggle active">
        <label>Dados Iniciais</label>
        <div class="toggle-content">
            <div class="col-md-12" style="padding-bottom: 15px;">

                <div class="form-group" style="border-bottom: 1px solid #ccc;">
                    <label class="control-label" style="color:#666;"><b>Razão Social</b></label>
                    <p class="font-info"><?php echo $row_consult['razao_social'] ?></p>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc;">
                    <label class="control-label" style="color:#666;"><b>Ramo de Atividade</b></label>
                    <p class="font-info"><?php echo $row_atividade['atividade'] ?></p>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc;">
                    <label class="control-label" style="color:#666;"><b>Setor</b></label>
                    <p class="font-info"><?php echo $row_setores['setor'] ?></p>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc;">
                    <label class="control-label" style="color:#666;"><b>Controlador</b></label>
                    <p class="font-info"><?php echo $row_consult['controlador'] ?></p>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc;">
                    <label class="control-label" style="color:#666;"><b>Grupo</b></label>
                    <p class="font-info"><?php echo $row_grupos['grupo'] ?></p>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc;">
                    <label class="control-label" style="color:#666;"><b>Data de abertura</b></label>
                    <p class="font-info"><?php echo date('d/m/Y', strtotime($row_consult['data_abertura'])); ?></p>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc;">
                    <label class="control-label" style="color:#666;"><b>Missão/Propósito</b></label>
                    <p class="font-info"><?php echo $row_consult['missao'] ?></p>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc;">
                    <label class="control-label" style="color:#666;"><b>Estrelas</b></label>
                    <p class="font-info">
                        <?php
                        if($row_consult['transparencia'] == 0) {
                            echo 0;
                        }
                        else {
                            for ($i = 1; $i <= $row_consult['transparencia']; $i++) {
                                ?>
                                <i class="fa fa-star"></i>
                                <?php
                            }
                        }
                        ?>
                    </p>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc;">
                    <label class="control-label" style="color:#666;"><b>Transparência</b></label>
                    <p class="font-info"><?php echo nl2br($row_consult['transparencia_txt']); ?></p>
                </div>


            </div>
        </div>
    </section>

    <!-- DADOS ADICIONAIS -->
    <section class="toggle">
        <label>Dados adicionais</label>
        <div class="toggle-content">


            <div class="col-md-12" style="padding-bottom: 15px;">

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Informações sobre Empresa</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo  nl2p($row_consult['informacoes_empresa'],false); ?></div>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Tem Política de Patrocínio?</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo  nl2p($row_consult['politica_patrocinio_txt'],false); ?></div>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Investe em Esporte?</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo  nl2p($row_consult['esporte_txt'],false); ?></div>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Investe em Sociocultural?</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo $row_consult['sociocultura'] ?></div>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Critérios</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo  nl2p($row_consult['criterios'],false); ?></div>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Lei de Incentivo</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo  $row_consult['lei_incentivo']; ?></div>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Perfil de investimento</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo  nl2p($row_consult['perfil_investimento'],false); ?></div>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Recebimento de projeto</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo  nl2p($row_consult['periodo_projetos'],false); ?></div>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Para encaminhar projeto</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo  nl2p($row_consult['receber_projetos'],false); ?></div>
                </div>




            </div>

        </div>
    </section>

    <!-- DADOS SEGMENTOS -->
    <section class="toggle">
        <label>Segmentos</label>
        <div class="toggle-content">

            <div class="col-md-12">
                <p style="font-size: 18px;">
                <?php
                $sql_segs = $sqli->query("SELECT segmentos.segmento, SUM(segmentos_empresa.count) AS total FROM segmentos, segmentos_empresa WHERE segmentos_empresa.id_empresa='".$_GET['id']."' AND segmentos_empresa.id_segmento=segmentos.id GROUP BY segmentos_empresa.id_segmento ORDER BY total DESC");
                while($row_segs = $sql_segs->fetch_assoc()) {
                ?>
                        <?php echo $row_segs['segmento'] ?>: <span class="badge badge-success"><?php echo $row_segs['total'] ?></span>  
                <?php
                }
                ?>
                </p>
            </div>


            <iframe class="responsive-iframe" frameBorder="0" scrolling="false" style="height: 700px;" src="grafico_segmentos.php?id=<?php echo $_GET['id'] ?>&color=#efefef"></iframe>

        </div>
    </section>

    <!-- DADOS INVESTIMENTOS -->
    <section class="toggle">
        <label>Investimentos</label>
        <div class="toggle-content">

            <div class="col-md-12" style="margin-bottom:20px;">

                <?php
                $sql_total_investimento = $sqli->query("SELECT SUM(valor) as total FROM `investimentos_empresa` WHERE id_empresa='".$_GET['id']."'");
                $row_total_investimento = $sql_total_investimento->fetch_assoc();

                $sql_investimento_ano = $sqli->query("SELECT * FROM `investimentos_empresa` WHERE id_empresa='".$_GET['id']."' ORDER BY id DESC LIMIT 1");
                $row_investimento_ano = $sql_investimento_ano->fetch_assoc();

                ?>

                <p style="font-size: 17px;"><b>Total Investido: </b> R$ <?php echo number_format($row_total_investimento['total'], 2, ',','.'); ?></p>
                <p style="font-size: 17px;"><b>Último ano <span class="badge badge-success"><?php echo $row_investimento_ano['ano'] ?></span></b> R$ <?php echo number_format($row_investimento_ano['valor'], 2, ',','.'); ?></p>

                <iframe class="responsive-iframe" frameBorder="0" scrolling="false" style="height: 400px;" src="grafico_investimentos.php?id=<?php echo $_GET['id'] ?>&color=#efefef"></iframe>

            </div>

        </div>
    </section>

    <!-- DADOS CONTATOS -->
    <section class="toggle">
        <label>Contatos</label>
        <div class="toggle-content">


            <div class="col-md-12" style="padding-bottom: 15px;">

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Local da sede</b></label>
                    <p class="font-info"><?php echo $row_consult['cidade'] ?> / <?php echo $row_consult['estado'] ?></p>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Endereço</b></label>
                    <p class="font-info"><?php echo $row_consult['endereco'] ?></p>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Website</b></label>
                    <p class="font-info"><a href="http://<?php echo $row_consult['site'] ?>" target="_blank"><?php echo $row_consult['site'] ?></a></p>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Contatos</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo  nl2p($row_consult['dados_contato'],false); ?></div>
                </div>

            </div>

        </div>
    </section>

    <!-- DADOS SOCIAIS -->
    <section class="toggle">
        <label>Social</label>
        <div class="toggle-content">

            <div class="col-md-12" style="padding-bottom: 15px;">

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Áreas de atuação</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo  nl2p($row_consult['area_atuacao'],false); ?></div>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Beneficiários</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo  $row_consult['beneficiarios'] ?></div>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Região de Atuação</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo  nl2p($row_consult['regiao_atuacao'],false); ?></div>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Projetos que desenvolve</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo nl2p($row_consult['projetos_desenvolve'],false); ?></div>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Projetos que apoia</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px;!important;"><?php echo $row_consult['projetos_apoia'] ?></div>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Critérios para apoio</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo nl2p($row_consult['criterio_apoio'],false); ?></div>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Quem pode se candidatar</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo nl2p($row_consult['quem_pode_candidatar'],false); ?></div>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Para Enviar Projeto Social</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo nl2p($row_consult['envio_projetos'],false); ?></div>
                </div>

                <div class="form-group" style="border-bottom: 1px solid #ccc; padding-bottom: 10px;">
                    <label class="control-label" style="color:#666;"><b>Para Receber Projetos</b></label>
                    <div class="font-info" style="font-size: 22px!important; line-height: 27px!important;"><?php echo nl2p($row_consult['para_enviar_projetos'],false); ?></div>
                </div>


            </div>


        </div>
    </section>




</div>
<script src="assets/javascripts/theme.custom.js"></script>

<!-- Theme Initialization Files -->
<script src="assets/javascripts/theme.init.js"></script>

