Viewing File: /home/cienp/public_html/portal/sql_agnd_pagm.php

<?
    $dt_atua = date("Y-m-d");
    echo ".";

    switch ($_POST[opc]){
        case "ins":

            require "$this->include_dir/conecta.php";

            $s_id_tipo_pagm = protecao($_POST[id_tipo_pagm],'inteiro');
            $s_de_titl = protecao($_POST[de_titl]);
            $s_de_agnd = protecao($_POST[de_agnd]);
            $s_dt_agnd = protecao($_POST[dt_agnd],'data');
            $s_vl_agnd = protecao($_POST[vl_agnd]);
            $s_de_obsr = protecao($_POST[de_obsr]);

            $s_vl_agnd = str_replace('.','',$s_vl_agnd);
            $s_vl_agnd = str_replace(',','.',$s_vl_agnd);

            if ($s_dt_agnd != '') {
                $d1 = explode('/', $s_dt_agnd);
                $dt_agnd = $d1[2]."-".$d1[1]."-".$d1[0];
            }

            $sql  = "INSERT INTO ".$pref_tabl."agnd_pagm ";
            $sql .= "(id_tipo_pagm, de_titl, de_agnd, dt_agnd, vl_agnd, de_obsr, dt_cads, id_cads) ";
            $sql .= "VALUES ('$s_id_tipo_pagm', '$s_de_titl', '$s_de_agnd', '$dt_agnd', '$s_vl_agnd', '$s_de_obsr', '$dt_atua', $linhau[id_user])";
            #echo $sql;
            $res  = mysqli_query($conn, $sql);
            
            if ($res) {
                $onde = "index1.php?pg=ins_agnd_pagm&certo=S";
            } else
                $onde = "index1.php?pg=ins_agnd_pagm&certo=N";

        break;

        case "alt":

            $erros = 0;

            require "$this->include_dir/conecta.php";

            if ($erros == 0) {

                $s_id_tipo_pagm = protecao($_POST[id_tipo_pagm],'inteiro');
                $s_de_titl = protecao($_POST[de_titl]);
                $s_de_agnd = protecao($_POST[de_agnd]);
                $s_dt_agnd = protecao($_POST[dt_agnd],'data');
                $s_dt_pagm = protecao($_POST[dt_pagm],'data');
                $s_vl_agnd = protecao($_POST[vl_agnd]);
                $s_de_obsr = protecao($_POST[de_obsr]);
                $s_id_agnd_pagm = protecao($_POST[id_agnd_pagm],'inteiro');

                $s_vl_agnd = str_replace('.','',$s_vl_agnd);
                $s_vl_agnd = str_replace(',','.',$s_vl_agnd);

                if ($s_dt_agnd != '') {
                    $d1 = explode('/', $s_dt_agnd);
                    $dt_agnd = $d1[2]."-".$d1[1]."-".$d1[0];
                }

                if ($s_dt_pagm != '') {
                    $d1 = explode('/', $s_dt_pagm);
                    $dt_pagm = $d1[2]."-".$d1[1]."-".$d1[0];
                }

                $sql  = "UPDATE ".$pref_tabl."agnd_pagm ";
                $sql .= "SET id_tipo_pagm = '$s_id_tipo_pagm', ";
                $sql .= "de_titl = '$s_de_titl', ";
                $sql .= "de_agnd = '$s_de_agnd', ";
                $sql .= "dt_agnd = '$dt_agnd', ";
                $sql .= "dt_pagm = '$dt_pagm', ";
                $sql .= "vl_agnd = '$s_vl_agnd', ";
                $sql .= "de_obsr = '$s_de_obsr', ";
                $sql .= "id_altr = '$linhau[id_user]', ";
                $sql .= "dt_altr = '$dt_atua' ";
                $sql .= "WHERE id_agnd_pagm = $s_id_agnd_pagm ";
                $sql .= "LIMIT 1";
                $res  = mysqli_query($conn, $sql);

                if ($res) {
                    $onde = "index1.php?pg=alt_solc&certo=SAPP";
                } else
                    $onde = "index1.php?pg=alt_solc&certo=NAPP";
            }

        break;

        case "exc":

            require "$this->include_dir/conecta.php";

            $s_id_agnd_pagm = protecao($_POST[id_agnd_pagm],'inteiro');
            if ($s_id_agnd_pagm > 0) {

                $sql  = "DELETE FROM ".$pref_tabl."agnd_pagm ";
                $sql .= "WHERE id_agnd_pagm = '$s_id_agnd_pagm' ";
                $sql .= "LIMIT 1";
                $res  = mysqli_query($conn, $sql);
                if ($res) {
                    $onde = "index1.php?pg=res_agnd_pagm&certo=X";

                    // apaga os anexos
                    $sqlar  = "SELECT id_anex, de_arqv ";
                    $sqlar .= "FROM ".$pref_tabl."agnd_anex ";
                    $sqlar .= "WHERE id_agnd_pagm = $s_id_agnd_pagm ";
                    $sqlar .= "ORDER BY id_anex ";
                    #echo $sqlit.'<br>';
                    $resar  = mysqli_query($conn, $sqlar);
                    if (mysqli_num_rows($resar) > 0) {
                        while ($linhaar = mysqli_fetch_array($resar)) {
                            $sqlv  = "DELETE FROM ".$pref_tabl."agnd_anex ";
                            $sqlv .= "WHERE id_agnd_pagm = '$s_id_agnd_pagm' ";
                            $sqlv .= "AND id_anex = '$linhaar[id_anex]' ";
                            $sqlv .= "LIMIT 1 ";
                            $resv  = mysqli_query($conn, $sqlv);
                            if ($resv) {
                                @unlink("arqv/$linhaar[de_arqv]");
                            } 
                        }
                    }

                } else {
                    $onde = "index1.php?pg=res_agnd_pagm&certo=N";
                } 
            } else {
                $onde = "index1.php?pg=res_agnd_pagm&certo=N";
            }
            break;

        case "ins_anex":

            $erros = 0;

            require "$this->include_dir/conecta.php";

            $s_id_agnd_pagm = protecao($_POST[id_agnd_pagm],'inteiro');
            $s_de_arqv = protecao($_POST[de_arqv]);

                if (!empty($_FILES['nm_arqv']['name'])) {

                if (($_FILES['nm_arqv']['size'] >= 10000000) || ($_FILES['nm_arqv']['size'] == 0)) {
                    $erros++;
                    $onde = "index1.php?pg=alt_agnd_pagm&certo=M";
                }

                if (strtoupper(substr($_FILES['nm_arqv']['type'],-3)) != "PDF") { 
                    $erros++;
                    $onde = "index1.php?pg=alt_agnd_pagm&certo=F";
                }

                if (!is_file($_FILES['nm_arqv']['tmp_name'])){
                    $erros++;
                    $onde = "index1.php?pg=alt_agnd_pagm&certo=Y";	
                }

                if (is_dir($_FILES['nm_arqv']['name'])){
                    $erros++;
                    $onde = "index1.php?pg=alt_agnd_pagm&certo=D";				
                }

                if ($erros == 0) {
                    
                    $sql  = "INSERT INTO ".$pref_tabl."agnd_anex ";
                    $sql .= "(id_agnd_pagm, de_arqv, dt_cads, id_cads) ";
                    $sql .= "VALUES ('$s_id_agnd_pagm', '$s_de_arqv', '$dt_atua', $linhau[id_user])";
                    #echo $sql;
                    $res  = mysqli_query($conn, $sql);
                    
                    if ($res) {
                        $onde = "index1.php?pg=alt_agnd_pagm&certo=SA";
                        
                        $sqln  = "SELECT MAX(id_anex) as id_anex ";
                        $sqln .= "FROM ".$pref_tabl."agnd_anex ";
                        $resn  = mysqli_query($conn, $sqln);
                        if (mysqli_num_rows($resn) > 0) {
                            $linhan = mysqli_fetch_array($resn);
                            
                            $s_de_arqv = 'Anexo_do_Pagamento_'.$linhan[id_anex].'.pdf';
                            
                            if (move_uploaded_file($_FILES['nm_arqv']['tmp_name'], "arqv_agnd/$s_de_arqv")) {

                                $sqlv  = "UPDATE ".$pref_tabl."agnd_anex ";
                                $sqlv .= "SET nm_arqv = '$s_de_arqv' ";
                                $sqlv .= "WHERE id_anex = $linhan[id_anex] ";
                                $sqlv .= "LIMIT 1";
                                $resv  = mysqli_query($conn, $sqlv);
                                if ($resv) {
                                    $onde = "index1.php?pg=alt_agnd_pagm&certo=SA";
                                } else {
                                    $onde = "index1.php?pg=alt_agnd_pagm&certo=N";
                                }
                            } else {
                                $onde = "index1.php?pg=alt_agnd_pagm&certo=N";
                            }
                        } else {
                            $onde = "index1.php?pg=alt_agnd_pagm&certo=N";
                        }
                    } else {
                        $onde = "index1.php?pg=alt_agnd_pagm&certo=N";
                    }
                }
            } else {
                $onde = "index1.php?pg=alt_agnd_pagm&certo=V";
            }
            break;
            
        case "exc_anex":

            $erros = 0;

            require "$this->include_dir/conecta.php";

            $s_id_agnd_pagm = protecao($_POST[id_agnd_pagm],'inteiro');
            $s_id_anex = protecao($_POST[id_anex],'inteiro');

            $sqlv  = "DELETE FROM ".$pref_tabl."agnd_anex ";
            $sqlv .= "WHERE id_anex = '$s_id_anex' ";
            $sqlv .= "AND id_agnd_pagm = '$s_id_agnd_pagm' ";
            $sqlv .= "LIMIT 1";
            $resv  = mysqli_query($conn, $sqlv);
            if ($resv) {
                $onde = "index1.php?pg=alt_agnd_pagm&certo=X";
                
                $s_de_arqv = 'Anexo_do_Pagamento_'.$s_id_anex.'.pdf';
                @unlink("arqv_agnd/$s_de_arqv");
            } else {
                $onde = "index1.php?pg=alt_agnd_pagm&certo=N";
            }
            break;
        
    }
?>
<form name="retorna" method="post" action="">
    <input type="hidden" name="id_agnd_pagm" id="id_agnd_pagm" value="<?=$_POST[id_agnd_pagm]?>">
    <input type="hidden" name="id_comp" id="id_comp" value="<?=$_POST[id_comp]?>">
    <input type="hidden" name="v_nu_oc" id="v_nu_oc" value="<?=$_POST[v_nu_oc]?>">
    <input type="hidden" name="v_id_tipo" id="v_id_tipo" value="<?=$_POST[v_id_tipo]?>">
    <input type="hidden" name="v_id_recs" id="v_id_recs" value="<?=$_POST[v_id_recs]?>">
    <input type="hidden" name="v_id_sitc" id="v_id_sitc" value="<?=$_POST[v_id_sitc]?>">
    <input type="hidden" name="v_id_user" id="v_id_user" value="<?=$_POST[v_id_user]?>">
    <input type="hidden" name="v_dt_inic" id="v_dt_inic" value="<?=$_POST[v_dt_inic]?>">
    <input type="hidden" name="v_dt_finl" id="v_dt_finl" value="<?=$_POST[v_dt_finl]?>">
    <input name="passa" type="hidden" id="passa" value="yes">
</form>
<?
echo "<SCRIPT LANGUAGE=javascript> \n";
echo "document.retorna.action = '$onde'; \n";
echo "document.retorna.submit(); \n";
echo "</script>";
?>
Back to Directory File Manager