condition to show data in combobox

1

Galera is the following I have two forms, one of business registration and another of process register, being that in the process has a ComboBox where it is pulled all the enterprises that have been registered, remembering that the process form is as soon as the project registration is finalized.

The user of the system can open both forms depending on their needs, however, if the user opened the project form and made a registration as soon as the process form was called, he would like ComboBox to show only the last one projects registered, otherwise if the user only wants to see the enterprises registered in the process form all projects were displayed in ComboBox .

Personal Talk follows only the most important parts of the code:

Business registration form

<?php
session_start();
require './config/conexao.php';

if (isset($_SESSION['email']) && empty($_SESSION['email']) == FALSE) {
    if (isset($_SESSION['senha']) && empty($_SESSION['senha']) == FALSE) {        
    }
} else {
    header("Location:login.php");
    exit();
}
?>

<form  action="recebe_cad_empreendimento.php"  method="POST" name="frmempreendimento" id="frmempreendimento">
    <div class="panel panel-success">
        <div class="panel-heading"> 
            <div class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapse1"><strong>DADOS DO EMPREENDIMENTO / ATIVIDADE</strong></a>
            </div>
        </div>
        <div id="collapse1" class="panel-collapse collapse in">
            <div class="panel-body">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label for="empreendimento"><strong>NOME DO EMPREENDIMENTO*</strong></label>                                  
                            <input type="text" name="empreendimento" id="empreendimento" class="form-control">   
                        </div>                                  
                    </div>
                </div>                           
            </div>
        </div>                                             
    </div>                                                          
    <div class="panel panel-default">
        <div class="panel-title" style="text-align: center;"><br/>
            <input type="submit" value="REALIZAR CADASTRO" class="btn btn-success" style="font-size: 17px; font-weight: bold;"/>
            <button  class="btn btn-danger"><a href="home.php"  style="font-size: 17px; font-weight: bold; color: #fff;text-decoration: none;">CANCELAR CADASTRO</a></button><br/><br/>
        </div>   
    </div> 
</form>

Page that receives data from the development form ( Recebe_cad_empreendiemeto.php )

<?php
session_start();
require './config/conexao.php';

if (isset($_SESSION['email']) && empty($_SESSION['email']) == FALSE) {
    if (isset($_SESSION['senha']) && empty($_SESSION['senha']) == FALSE) {

    }
} else {
    header("Location:login.php");
    exit();
}
if (isset($_POST['nome_empreendimento']) && empty($_POST['nome_empreendimento']) == FALSE) {

    $nome_empreendimento = strtoupper(addslashes($_POST['nome_empreendimento']));

    $sql = "INSERT INTO tb_empreendimento(nome_empreendimento)"
            . "VALUES(UPPER('$nome_empreendimento')";
    mysqli_query($con, $sql);
    ?>               
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="myModalLabel">EMPREENDIMENTO CADASTRADO COM SUCESSO!</h4>
                </div>
                <div class="modal-footer">
                    <a href="cad_licenca.php"><button type="button" class="btn btn-danger">CONTINUAR CADASTRO</button></a>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(document).ready(function () {
            $('#myModal').modal('show');
        });
    </script>
    <?php
}

Process registration form

<?php
session_start();
require './config/conexao.php';

if (isset($_SESSION['email']) && empty($_SESSION['email']) == FALSE) {
    if (isset($_SESSION['senha']) && empty($_SESSION['senha']) == FALSE) {

    }
} else {
    header("Location:login.php");
    exit();
}
?>
<form  action="recebe_cad_processo.php"  method="POST" name="frmprocesso" id="frmprocesso">
    <div class="panel panel-success">
        <div class="panel-heading"> 
            <div class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapse1"><strong>DADOS DO PROCESSO</strong></a>
            </div>
        </div>
        <div id="collapse1" class="panel-collapse collapse in">
            <div class="panel-body">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">                                                
                            <label for="empreendimento"><strong>SELECIONE O EMPREENDIMENTO*</strong></label><a href="cad_empreendimento.php" style="float: right;font-size: 16px"><strong>caso não encontre,faça o cadastro - aqui</strong></a><br/>
                            <select name="empreendimento" id="empreendimento" class="form-control" autofocus="">
                                <option value="">--- SELECIONE ---</option>
                                <?php
                                $parametro_empreendimento = filter_input(INPUT_GET, "parametro_empreendimento");
                                $empreendimento = "SELECT *FROM tb_empreendimento WHERE nome_empreendimento LIKE '%$parametro_empreendimento' ORDER BY nome_empreendimento";
                                $recebe_empreendimento = mysqli_query($con, $empreendimento);
                                while ($linha = mysqli_fetch_array($recebe_empreendimento)) {
                                    echo '<option value="' . $linha['codigo_empreendimento'] . '">' . $linha['nome_empreendimento'] . '</option>';
                                }
                                ?>                                                                       
                            </select>
                        </div>
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label for="numero_processo"><strong>NÚMERO DO PROCESSO *</strong></label><br/>
                                <input type="number" name="numero_processo" id="numero_processo" class="form-control" autofocus=""/>
                            </div>
                        </div>
                    </div>
                </div>                                     
            </div>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-title" style="text-align: center;"><br/>
            <input type="submit" value="REALIZAR CADASTRO" class="btn btn-success" style="font-size: 17px; font-weight: bold;"/>
            <button  class="btn btn-danger"><a href="home.php"  style="font-size: 17px; font-weight: bold; color: #fff;text-decoration: none;">CANCELAR CADASTRO</a></button><br/><br/>
        </div>   
    </div>
</form>

Page that receives data from the process form ( Recebe_cad_processo.php )

<?php
session_start();
require './config/conexao.php';

if (isset($_SESSION['email']) && empty($_SESSION['email']) == FALSE) {
    if (isset($_SESSION['senha']) && empty($_SESSION['senha']) == FALSE) {

    }
} else {
    header("Location:login.php");
    exit();
}

if (isset($_POST['empreendimento']) && empty($_POST['empreendimento']) == FALSE) {
    if (isset($_POST['numero_processo']) && empty($_POST['numero_processo']) == FALSE) {

        $empreendimento = strtoupper(addslashes($_POST['empreendimento']));
        $numero_processo = strtoupper(addslashes($_POST['numero_processo']));

        if ($numero_processo < 0) {
            ?>
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title" id="myModalLabel">ERRO! O NÚMERO DO PROCESSO INFORMADO É INVÁLIDO</h4>                           
                        </div>
                        <div class="modal-footer">
                            <a href="cad_licenca.php"><button type="button" class="btn btn-info">POR FAVOR! INFORME OUTRO NÚMERO</button></a>
                            <a href="home.php"><button type="button" class="btn btn-danger">CANCELAR</button></a>
                        </div>
                    </div>
                </div>
            </div>
            <script>
                $(document).ready(function () {
                    $('#myModal').modal('show');
                });
            </script>
            <?php
        }

//verrificando se ja existe no banco de dados o numero do processo informado
        $consulta_processo = "SELECT *FROM tb_processo WHERE numero_processo ='" . $_POST['numero_processo'] . "' ";
        $recebe_consulta = mysqli_query($con, $consulta_processo);

        if (mysqli_num_rows($recebe_consulta) > 0) {
            ?>
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title" id="myModalLabel">ERRO! JÁ EXISTE UM PROCESSO COM O NÚMERO INFORMADO</h4>                           
                        </div>
                        <div class="modal-footer">
                            <a href="cad_licenca.php"><button type="button" class="btn btn-info">POR FAVOR! INFORME OUTRO NÚMERO</button></a>
                            <a href="home.php"><button type="button" class="btn btn-danger">CANCELAR</button></a>
                        </div>
                    </div>
                </div>
            </div>
            <script>
                $(document).ready(function () {
                    $('#myModal').modal('show');
                });
            </script>

            <?php
        } else {

            $sql = "INSERT INTO tb_processo(fk4_codigo_empreendimento,numero_processo)"
                    . "VALUES('$empreendimento','$numero_processo')";
            mysqli_query($con, $sql);
            ?>
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title" id="myModalLabel">PROCESSO CADASTRADO COM SUCESSO!</h4>
                        </div>
                        <div class="modal-footer">
                            <a href="cad_licenca.php"><button type="button" class="btn btn-danger">CONTINUAR CADASTRO</button></a>
                        </div>
                    </div>
                </div>
            </div>
            <script>
                $(document).ready(function () {
                    $('#myModal').modal('show');
                });
            </script>
            <?php
        }
    }
}
?>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">ERRO! POR FAVOR PREENCHA O FORMULÁRIO</h4>
            </div>
            <div class="modal-footer">
                <a href="cad_processo.php"><button type="button" class="btn btn-info"><strong>VOLTAR PARA O FORMULÁRIO DE CADASTRO</strong></button></a>
                <a href="home.php"><button type="button" class="btn btn-danger"><strong>CANCELAR</strong></button></a>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        $('#myModal').modal('show');
    });
</script>
    
asked by anonymous 06.09.2018 / 22:25

0 answers