Created
August 13, 2018 01:27
-
-
Save anselmobattisti/0b1dee2ee044f6b7aa28784f92a8d012 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// ------------------- | |
// Lendo arquivo local | |
// ------------------- | |
$filename = "acervo.csv"; | |
$handle = fopen ($filename, "r"); | |
$conteudo = fread ($handle, filesize ($filename)); | |
/* | |
// ----------------------------------- | |
// Lendo arquivo diretamente da fonte | |
// ----------------------------------- | |
$conteudo = file_get_contents("https://drive.ifsp.edu.br/s/DXZtc5bODQ79jfZ/download"); | |
*/ | |
$linhas = explode("\n",$conteudo); | |
unset($linhas[0]); | |
$dados = ""; | |
$filtro_ano = $_GET['ano']; | |
$filtro_biblioteca = $_GET['biblioteca']; | |
$filtro_tipo = $_GET['tipo']; | |
$total_obras = 0; | |
$total_linhas = 0; | |
foreach($linhas as $linha){ | |
$colunas = explode(";",$linha); | |
$coluna_biblioteca = trim($colunas[0]); | |
$coluna_tipo = trim($colunas[2]); | |
$coluna_total = trim($colunas[3]); | |
$coluna_ano = trim($colunas[7]); | |
if ($filtro_ano >= 2015 && $filtro_ano != $coluna_ano) { | |
continue; | |
} | |
if ($filtro_tipo != "" && $filtro_tipo != $coluna_tipo) { | |
continue; | |
} | |
if ($filtro_biblioteca != "" && $filtro_biblioteca != $coluna_biblioteca) { | |
continue; | |
} | |
$dados .= " | |
<tr> | |
<td>".$coluna_biblioteca."</td> | |
<td>".$coluna_tipo."</td> | |
<td>".$coluna_ano."</td> | |
<td>".$coluna_total."</td> | |
</tr> | |
"; | |
$total_obras += $coluna_total; | |
$total_linhas++; | |
} | |
//var_dump($linhas); | |
fclose ($handle); | |
?> | |
<html> | |
<head> | |
<title>Interface Web para consulta de dados abertos</title> | |
</head> | |
<body> | |
<h1>Consulta de dados abertos da biblioteca </h1> | |
<form method="get"> | |
<label> | |
Biblioteca | |
<input type="text" name="biblioteca" value="<? echo $_GET['biblioteca'] ?>"> | |
</label><br/> | |
<label> | |
Tipo | |
<select name="tipo"> | |
<option value="">Escolha</option> | |
<option value="Livros">Livros</option> | |
<option value="TFC (Trab.Final Curso Tecnico)">TFC (Trab.Final Curso Tecnico)</option> | |
<option value="Referência">Referência</option> | |
<option value="Relatórios">Relatórios</option> | |
<option value="Artigos">Artigos</option> | |
<option value="Dissertações">Dissertações</option> | |
<option value="TCC - Graduação">TCC - Graduação </option> | |
<option value="Livro eletrônico">Livro eletrônico</option> | |
<option value="Teses">Teses</option> | |
</select> | |
</label><br/> | |
<label> | |
Ano | |
<input type="text" name="ano" value="<? echo $_GET['ano'] ?>"> | |
</label><br/> | |
<input type="submit" value="Consultar"> | |
<a href="http://battisti.com.br/gci/">Limpar</a> | |
</form> | |
<hr/> | |
<table border=1> | |
<thead> | |
<th>Biblioteca</th> | |
<th>Tipo</th> | |
<th>Ano</th> | |
<th>Total Obras</th> | |
</thead> | |
<tbody> | |
<? echo $dados ?> | |
</tbody> | |
<tfoot> | |
<tr> | |
<td colspan=3> | |
<strong>Total Obras</strong> | |
</td> | |
<td> | |
<? echo $total_obras ?> | |
</td> | |
</tr> | |
<tr> | |
<td colspan=3> | |
<strong>Número Registros</strong> | |
</td> | |
<td> | |
<? echo $total_linhas ?> | |
</td> | |
</tr> | |
</tfoot> | |
</table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment