<?php
//Se impostato Excel
if(isSet($_POST['XLS'])){
header ("Content-Type: application/vnd.ms-excel");
header ("Content-Disposition: attachment; filename=Questionari_Gradimento.xls");
}
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="it">
<head>
<link rel="shortcut icon" href="https://172.20.15.8/celltel_pic.jpg" />
</head>
<title>Query</title>
<body>
<?php
$_SESSION['user'] = "RRTPPT1";
$_SESSION['password'] = '$W34$7YE$2';
$AS400 = 'GESPER_DAT';
$connect = odbc_connect ($AS400, $_SESSION['user'], $_SESSION['password']);
if(isSet($_POST['query']) && $_POST['query']<>'' && substr($_POST['query'],0,6)=="SELECT"){
//if(isSet($_POST['query']) && $_POST['query']<>''){
$qry = $_POST['query'];
//print $qry."<br>";
@$rs=odbc_exec($connect,$qry);
if ($rs ==0)
echo ("<B>Error ".odbc_error().":".odbc_errormsg()."</B>");
else if (odbc_num_rows($rs)==0)
print "<BR><B>Nessun dato trovato<br></B>";
else
{
print "<table border=1>\n";
print " <tr>\n";
$fields=odbc_num_fields($rs);
for($c=1;$c<=$fields;$c++)
print "<th bgcolor=orange>".odbc_field_name($rs, $c)."</th>";
print " </tr>\n";
while ($row =odbc_fetch_row($rs)){
print " <tr>";
for($c=1;$c<=$fields;$c++)
print " <td>".trim(odbc_result( $rs, $c ))."</td>";
print " </tr>\n";
}
odbc_free_result($rs);
odbc_close($connect);
print "</table>";
}
}else{
print "<b>Query non valida</b> ".$_POST['query'];
}
?>
</body>
</html>