<?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 "seguranca.php";
    protegePagina();
    include "log_.php";
    $mensagem = "Entrou no sistema!";
    salvaLog($mensagem);
    include "sgt.php";
    $url = 'http://sgt.eti.br/sgt/sgt.html'; 
    $versao_sgt = file_get_contents($url);
    if ($versao_local < $versao_sgt) {
        $query=$pdo_sgt->prepare("UPDATE tb_conf SET var1=:var1 WHERE conf=:conf");
        $query->bindValue(":var1","1");
        $query->bindValue(":conf","versao");
        $query->execute();
        if ($_SESSION['usuarioNivel'] < 3) {
            echo"<script language='javascript' type='text/javascript'>
                alert('Seu sistema está desatualizado!');
                window.location.href='home.php';
            </script>";
        } else {
            header("Location: home.php");
        }
    } else {
        $query=$pdo_sgt->prepare("UPDATE tb_conf SET var1=:var1 WHERE conf=:conf");
        $query->bindValue(":var1","0");
        $query->bindValue(":conf","versao");
        $query->execute();
        header("Location: home.php");
    }
?>