PDA

View Full Version : [PHP] pagina di risposta in un'altra finestra


vici_1
21-08-2005, 14:01
Una pagina web tramite un form invia la richiesta al server che in risposta produce un grafico disegnato in PHP.
Vorrei avere la pagina in risposta su di un'altra pagina del browser e non sulla stessa, che quindi viene ricoperta, da cui e' partita la richiesta.

Pagina di richiesta :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> Your Title Here </title>
<meta name="Generator" content="Alleycode HTML Editor">
<meta name="Description" content="Your description here...">
<meta name="Keywords" content="Your keywords here...">
</head>

<body>
<?php

echo gmdate("d M Y");
print(' - ');
echo date("H:i");
?>

<form method="post" action="grafici.php" src="pippo">

<fieldset>
<br>
<h3>Periodo
<input type="text" name="data1" size="10" maxlength="8">
<input type="text" name="data2" size="10" maxlength="8">(ssaammgg)
</h3>
<h3>Titolo

<?php

//ciclo per estrarre i nomi dei files dei titoli

print('<select name="titolo">');

// host: localhost windows
$fd = fopen ("C:\Programmi\Apache Group\Apache2\htdocs\borsa\quotazioni_m\listati.txt", "r");
// host: altervista linux
// $fd = fopen ("quotazioni_m/listati.txt", "r");

while (!feof ($fd)) {
$buffer = fgets($fd, 4096);

if ($buffer == $b) {
print('<option value=' . "$buffer" . 'SELECTED>' . " $buffer" . '</option>');
}
else {
print('<option value=' . "$buffer" . '>' . " $buffer" . '</option>');
}
}
fclose ($fd);
print ('</select>');

?>

<input type="submit" value="Disegna">
</h3>

</fieldset>
</form>
<br>

</body>
</html>


pagina di risposta tutta in PHP :

<?
function tratta_record (&$rec,
&$desb,
&$qdat,
&$qape,
&$qmax,
&$qmin,
&$qchi,
&$qvol,
&$q8,
&$q9,
&$q10,
&$desl)
{
$x = 0;

$z = 0 + 14;
for ($i = 0 ; $i <= $z ; $i++)
{
$x++;
$desb = $desb . $rec{$i};
}
//$x++;
$z = $z + 8;
for ($i = $x ; $i <= $z ; $i++)
{
$x++;
$qdat = $qdat . $rec{$i};
}
//$x++;
$z = $z + 7;
for ($i = $x ; $i <= $z ; $i++)
{
$x++;
$qape = $qape . $rec{$i};
}
//$x++;
$z = $z + 7;
for ($i = $x ; $i <= $z ; $i++)
{
$x++;
$qmax = $qmax . $rec{$i};
}
//$x++;
$z = $z + 7;
for ($i = $x ; $i <= $z ; $i++)
{
$x++;
$qmin = $qmin . $rec{$i};
}
//$x++;
$z = $z + 7;
for ($i = $x ; $i <= $z ; $i++)
{
$x++;
$qchi = $qchi . $rec{$i};
}
//$x++;
$z = $z +10;
for ($i = $x ; $i <= $z ; $i++)
{
$x++;
$qvol = $qvol . $rec{$i};
}
//$x++;
$z = $z + 7;
for ($i = $x ; $i <= $z ; $i++)
{
$x++;
$q8 = $q8 . $rec{$i};
}
//$x++;
$z = $z + 7;
for ($i = $x ; $i <= $z ; $i++)
{
$x++;
$q9 = $q9 . $rec{$i};
}
//$x++;
$z = $z + 7;
for ($i = $x ; $i <= $z ; $i++)
{
$x++;
$q10 = $q10 . $rec{$i};
}
//$x++;
$z = $z + 30;
for ($i = $x ; $i <= $z ; $i++)
{
$x++;
$desl = $desl . $rec{$i};
}
/*print ("$desb<br>");

print ("$qdat<br>");
print("$qape<br>");
print("$qmax<br>");
print("$qmin<br>");
print("$qchi<br>");
print("$qvol<br>");
print("$q8<br>");
print("$q9<br>");
print("$q10<br>");
print("$desl<br>"); */

}
//end function tratta_record

$a = $_REQUEST[titolo];
$d1 = $_REQUEST[data1];
$d2 = $_REQUEST[data2];

$nomeb="";
$max = 0;
$min = 999;

if ($a != "") {
for ($i = 0 ; $a{$i} != "," ; $i++)
{
$nomeb = $nomeb . $a{$i};
}
}
// host: localhost windows
$filename ="C:\\Programmi\\Apache Group\\Apache2\\htdocs\\borsa\\quotazioni_m\\titoli\\" . "$nomeb" . ".bin";
// host: altervista linux
// $filename ="quotazioni_m/" . "$nomeb" . ".bin";

if ($a != "") {
$ft = fopen ($filename, "rb");
while (!feof ($ft)) {
$rec = fread ($ft, 112);

$desb="";
$qdat="";
$qape="";
$qmax="";
$qmin="";
$qchi="";
$qvol="";
$q8="";
$q9="";
$q10="";
$desl="";

tratta_record( $rec,
$desb,
$qdat,
$qape,
$qmax,
$qmin,
$qchi,
$qvol,
$q8,
$q9,
$q10,
$desl);

if ($qdat >= $d1 && $qdat <= $d2) {
$descrizione = $desl;
if ($max < $qmax) {
$max = $qmax;
}
if ($min > $qmin) {
$min = $qmin;
}
}
}

fclose ($ft);
}

// istanzio una nuova immagine di dimensioni x=200 e y=300
$immagine = imageCreate(850, 680);
// assegno il primo colore, questo colore sarà anche lo sfondo dell'immagine
$bianco = imageColorAllocate($immagine, 255, 255, 255);
// assegno un secondo colore, da utilizzare per colorare il testo
$nero = imageColorAllocate($immagine, 0, 0, 0);
// visualizzo il testo
imageString($immagine, 2, 52, 50, $nomeb, $nero);
// visualizzo il rettangolo per il disegno
imageRectangle($immagine, 50, 50, 800, 670, $nero);

$ystart = 600;
$x1 = 60;

if ($a != "") {
$ft = fopen ($filename, "rb");
while (!feof ($ft)) {
$rec = fread ($ft, 112);

$desb="";
$qdat="";
$qape="";
$qmax="";
$qmin="";
$qchi="";
$qvol="";
$q8="";
$q9="";
$q10="";
$desl="";

tratta_record( $rec,
$desb,
$qdat,
$qape,
$qmax,
$qmin,
$qchi,
$qvol,
$q8,
$q9,
$q10,
$desl);

if ($qdat >= $d1 && $qdat <= $d2) {
// barra verticale
$y1 = ((($max - $qmax) * $ystart) / ($max - $min)) + 50;
$y2 = ((($max - $qmin) * $ystart) / ($max - $min)) + 50;
//echo("$y1<br>");
//echo("$y2<br>");
imageLine($immagine, $x1, $y1, $x1, $y2, $nero);

//barre orrizzontali
$y1 = ((($max - $qape) * $ystart) / ($max - $min)) + 50;
imageLine($immagine, $x1, $y1, ($x1 + 4), $y1, $nero);

$y1 = ((($max - $qchi) * $ystart) / ($max - $min)) + 50;
imageLine($immagine, $x1, $y1, ($x1 - 4), $y1, $nero);

$x1 = $x1 + 07;
}
}

fclose ($ft);
// imposto correttamente gli header
header("Content-type: image/png");
// invio l'output come immagine PNG
imagePng($immagine);
// libero la memoria
imageDestroy($immagine);
}

?>

<html>
<head>
<title> Your Title Here </title>
<meta name="Generator" content="Alleycode HTML Editor">
<meta name="Description" content="Your description here...">
<meta name="Keywords" content="Your keywords here...">
</head>

<body>

</div>
</body>
</html>

BlueDragon
21-08-2005, 15:47
Una pagina web tramite un form invia la richiesta al server che in risposta produce un grafico disegnato in PHP.
Vorrei avere la pagina in risposta su di un'altra pagina del browser e non sulla stessa, che quindi viene ricoperta, da cui e' partita la richiesta.

Se vuoi semplicemente che inviando la form si apra una finestra a parte, ti basta dichiarare nel form il parametro target='_blank'
ES:
<form action="test.php" method="get" name="MiaForm" target="_blank">

vici_1
21-08-2005, 16:00
Ottimo.
Ha funzionato. :)
Grazie.