<?php

class logsIdebo_model extends Databases {

    function __construct() {
        parent::__construct();
    }

    function getLocales() {
        $sql = "select a.LOCAL,a.NUMERO_LOCAL,a.IP_LOCAL, (SELECT TOP 1 VERSION FROM LOCALES_VERSIONES WHERE EMP=a.NUMERO_LOCAL ORDER BY FACT DESC) AS VERSION, (SELECT TOP 1 FACT FROM LOCALES_VERSIONES WHERE EMP=a.NUMERO_LOCAL ORDER BY FACT DESC) AS FACT from consulta_info_1 a WHERE NUMERO_LOCAL > 0 GROUP BY a.LOCAL,a.NUMERO_LOCAL,a.IP_LOCAL ORDER BY NUMERO_LOCAL ASC";
        $data = parent::query($sql);
        if ($data && count($data) > 0) {
            return $data;
        } else {
            return FALSE;
        }
    }

    function getHistoricoLogs($local) {
        $sql = "select TOP 40 * from idebo_logs where emp=$local order by fecha desc";
        $data = parent::query($sql);
        if ($data && count($data) > 0) {
            return $data;
        } else {
            return FALSE;
        }
    }

    function getLogFromLocal($file) {
        $nombre = "Log/IDebo/$file";
        if (file_exists($nombre)) {
            $contenido = fopen($nombre, "r");
            while (!feof($contenido)) {
                $line[] = fgets($contenido);
            }
            fclose($contenido);
            if ($line && count($line) > 0) {
                return $line;
            } else {
                return FALSE;
            }
        } else {
            return FALSE;
        }
    }

}
