<?php
#   SGT - The SGT for Internet - http://sgt.eti.br
#   Copyright (c) 2016-2018, Jean Azevedo. All rights reserved.

#   This file is part of SGT.

#   SGT is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   any later version.

#   SGT is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.

#   You should have received a copy of the GNU General Public License
#   along with Foobar.  If not, see <http://www.gnu.org/licenses/>.

    include "../conectar.php";
    include"../seguranca_aux_unid.php";
    include "../log_.php";
    date_default_timezone_set('America/Sao_Paulo');
    $hora = date('Y-m-d H:i:s', time());
    $user = $_SESSION['usuarioLogin'];
    $cod_c = $_POST['cod_c'];
    $tipo = $_POST['tipo'];
    $des = $_POST['desc_tex_area'];
    if($cod_c == "Cod."){
        echo"<script language='javascript' type='text/javascript'>
            alert('O campo Cód. deve ser escolhido!');
            window.history.go(-1)>Volta;
        </script>";
    }
    else{
        if($tipo == "Tipo"){
            echo"<script language='javascript' type='text/javascript'>
                alert('O campo Tipo deve ser escolhido!');
                window.history.go(-1)>Volta;
            </script>";
        }
        else{
            if($des == "" || $des== null){
                echo"<script language='javascript' type='text/javascript'>
                    alert('O campo Descrição deve ser preenchido!');
                    window.history.go(-1)>Volta;
                </script>";
                die();
            }
            else{
                $query=$pdo_sgt->prepare("INSERT INTO tb_oc_comp (dt,user_nome,cod_c,tipo,des ) VALUES (:dt,:user_nome,:cod_c,:tipo,:des)");
                $query->bindValue(":dt",$hora);
                $query->bindValue(":user_nome",$user);
                $query->bindValue(":cod_c",$cod_c);
                $query->bindValue(":tipo",$tipo);
                $query->bindValue(":des",$des);
                $query->execute();
                $mensagem = "Dados inseridos na tabela: tb_oc_comp - Para os campos: dt, user_nome, cod_c, tipo, des - Com os seguintes valores: $hora, $user, $cod_c, $tipo, $des.";
                salvaLog($mensagem);
                echo"<script language='javascript' type='text/javascript'>
                    window.location.href='cad_oc_comp.php';
                </script>";
            }
        }
    }	
?>