forked from filipi/onde
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formFieldDownload.php
83 lines (73 loc) · 3.13 KB
/
formFieldDownload.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?PHP
//////////////////////// Tratar todos os GET aqui para eviter injecao de codigo
///////////////////////////////////////////////////////////////// Tratando POST
/////////////////////////////////////////////// GET passado para links (action)
if (isset($_GET['keyIsQuoted']))
$keyIsQuoted = intval(trim($_GET['keyIsQuoted']));
else
$keyIsQuoted = false;
if (isset($_GET['keyField']))
$keyField = pg_escape_string(trim($_GET['keyField']));
else
$keyField = 'codigo';
$field = pg_escape_string(trim($_GET['field']));
if ($keyIsQuoted)
$keyValue = pg_escape_string(trim($_GET['keyValue']));
else
$keyValue = intval(trim($_GET['keyValue']));
$table = pg_escape_string(trim($_GET['table']));
///////////////////////////////////////////////////////////////////// Cabecalho
$useSessions = 1; $ehXML = 1;
//$headerTitle = "Página de gabarito";
$myPATH = ini_get('include_path') . ':./include:../include:../../include';
ini_set('include_path', $myPATH);
include "light_header.inc";
//////////////////////////////////////////////////////////////// Funcoes locais
///////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////// Monta formulario
$query = "SELECT encode(\"" . $field . "\", 'base64') AS field \n";
$query .= " FROM \"" . $table . "\"\n";
$query .= " WHERE \"" . $keyField . "\" = " . ($keyIsQuoted ? "'" : '') . $keyValue . ($keyIsQuoted ? "'" : '');
//echo $query;
$res = pg_query($conn, $query);
$raw = pg_fetch_result($res, 'field');
////////////////////////////////////////////
//pg_close($conn);
$fileArray = formsDecodeFile(base64_decode($raw));
//var_dump($fileArray);
header("Content-Type: ". $fileArray['type']);
header('Content-Disposition: attachment; filename="' . $fileArray['name'] . '"');
echo $fileArray['contents'];
/* create table file_form_download_log( */
/* codigo serial primary key, */
/* user_login char(8) not null references usuarios(login), */
/* success boolean not null, */
/* table_name varchar(100) not null, */
/* field varchar(100) not null, */
/* key_field varchar(100) not null, */
/* key_value varchar(100) not null, */
/* key_is_quoted boolean not null, */
/* log_timestamp timestamp not null default current_timestamp, */
/* ip char(15) not null */
/* ) */
$queryLog = "INSERT INTO file_form_download_log (user_login, success, table_name, field,";
$queryLog .= " key_field, key_value, key_is_quoted, ip) VALUES (";
$queryLog .= "'" . $_SESSION['matricula'] . "', ";
$queryLog .= "'" . ($res ? "t" : "f") . "', ";
$queryLog .= "'" . $table . "', ";
$queryLog .= "'" . $field . "', ";
$queryLog .= "'" . $keyField . "', ";
$queryLog .= "'" . $keyValue . "', ";
$queryLog .= "'" . ($keyIsQuoted ? "t" : "f") . "', ";
$queryLog .= "'" . $_SESSION['ip'] . "') ";
$res = pg_query($conn, $queryLog);
/**
* verificar se o campo é bytea
* Esse script só pode ser chamado por um form
* verificar se a tabela passada é a tabela do form
* verificar se usuario tem permissao no form
*/
?>
<?PHP
include "page_footer.inc";
?>