<?php 

include "conexao.php";

$idusuario = $_GET['idusuario'];
$idigpm  = $_GET["idigpm"];
$idindice_correcao  = $_GET["idindice_correcao"];

// echo "<pre>";
// print_r($_GET);
// echo "<pre>"; die();


$deleta_album = mysqli_query($db,"DELETE FROM igpm WHERE idigpm='$idigpm'");




//#########################################  Funcoes Grava Log   #############################################
function nome_indice($id){
    include "conexao.php";
     $query_igpm = "SELECT descricao_indice FROM indice_correcao where idindice_correcao = $id";

                $executa_igpm = mysqli_query ($db, $query_igpm);
                
                
            while ($buscar_amigoc = mysqli_fetch_assoc($executa_igpm)) {//--verifica se são amigos
           
             $descricao_indice             = $buscar_amigoc['descricao_indice'];
}
return $descricao_indice;

} 

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;
        }

          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
                    $descricao_indice = nome_indice($idindice_correcao);
                    $descricao_log = "Usuário ".$nome_usuario ." excluiu o indice : ".$descricao_indice;
                    grava_log($data_log,$idusuario,$descricao_log);
                    //echo "cheguei aqui...;".$descricao_log; die();



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



?>
<script>
window.location ="cadastro_igpm.php?idindice_correcao=<?php echo $idindice_correcao ?>&idusuario=<?php echo $idusuario ?>";
</script>