migrate from PHP4 to PHP5
short tags ON
the same extensions enabled
it works in PHP4... it doesn't in PHP5....
what's wrong???
THANKS!
<?php
define('FPDF_FONTPATH','../../fpdf/font/');
require_once('../../fpdf/fpdf.php');
ini_set('zlib.output_compression', 'Off');
session_cache_limiter('private');
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header('Pragma: no-cache');
class PDFGrid extends FPDF
{
var $blank = false;
var $__isgrouping = false;
var $title;
var $stdfont;
var $hasgroup;
var $hasgroupfoot;
var $hasfoot;
var $anchos;
var $align;
var $semifoot;
var $foot;
var $currgroup;
var $colheadfont;
var $noheader;
var $notdecimalfoot;
var $hiddencols;
var $prehead;
var $preanchos;
var $subfont;
var $subhead;
var $subanchos;
var $subalign;
var $subquery = array();
var $subfoot = array();
var $hassubtotalfoot = false;
var $subtotalfoot;
function PDFGrid($orientation='P',$unit='mm', $format=array(210, 279))
{
// 210 x 279 es Carta y A4 al mismo tiempo
$this->hasgroup = false;
$this->hasgroupfoot = false;
$this->hasfoot = false;
$this->currgroup = "";
$this->colheadfont = 10;
$this->stdfont = 8;
$this->hiddencols = 1;
$this->noheader = false;
$this->notdecimalfoot = false;
parent::FPDF($orientation,$unit,$format);
$this->SetMargins(10,10);
}
function Header()
{
set_time_limit(30); // Mantenerme vivo
$this->SetFont('Arial','B',16);
$this->Cell(10,10,$this->title);
$this->SetFont('Arial','B',10);
$this->SetX($this->w - $this->lMargin - $this->rMargin - 20);
$this->MultiCell(40,3, 'Date: ' . date("d-M-Y") . "\nPage: " .$this->PageNo() . ' of {nb}');
//Line break
$this->Ln(2);
$this->SetLineWidth(1);
$this->Line($this->lMargin, $this->y, $this->w - $this->rMargin, $this->y);
$this->SetLineWidth(0);
if(!$this->noheader)
{
$this->Ln(1);
$this->SetFont('Arial','B',$this->colheadfont);
if(!empty($this->prehead))
{
for($i=0;$i<count($this->prehead);$i++)
$this->Cell($this->preanchos[$i]+1, 5, $this->prehead[$i],0, 'L');
$this->Ln(ceil($this->colheadfont / $this->k) + 1);
}
for($i=0;$i<count($this->titulos);$i++)
{
$a = $this->align[$i];
if($a=='R')
$a = 'C';
$this->Cell($this->anchos[$i]+1, 5, $this->titulos[$i],0,0, $a);
}
$this->Ln(ceil($this->colheadfont / $this->k) + 1);
$this->Line($this->lMargin, $this->y, $this->w - $this->rMargin, $this->y);
$this->Ln(0.3);
$this->SetFont('Arial','',$this->stdfont);
$this->blank = true;
$this->Group();
} else {
$this->SetFont('Arial','',$this->stdfont);
}
}
function Group()
{
if(!empty($this->currgroup) && !$this->__isgrouping)
{
$this->__isgrouping = true;
if(!$this->blank)
{
$this->Line($this->lMargin, $this->y, $this->w - $this->rMargin, $this->y);
$this->Ln(0.3);
}
$this->SetFont('Arial','B',$this->colheadfont);
$this->Cell(10, 5, $this->currgroup);
$this->Ln(ceil($this->colheadfont / $this->k) + 0.3);
$this->Line($this->lMargin, $this->y, $this->w - $this->rMargin, $this->y);
$this->Ln(0.3);
$this->SetFont('Arial','',$this->stdfont);
$this->__isgrouping = false;
}
}
function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='')
{
$this->blank = false;
parent::Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
}
function DoGrid($sql, $autoexit = false)
{
if(empty($sql)) // Si esta vacio el sql, me voy sin hacer nada
return;
set_time_limit(120); // Para SQL laaaaaaaaaaargos
$result = mysql_query($sql) or trigger_error("MySQL Error:" . mysql_error() . "<br>\nSQL:" . $sql, E_USER_ERROR);
$row = mysql_fetch_array($result);
if(!$row && $autoexit)
return;
for($i=0;$i<mysql_num_fields($result)-$this->hiddencols;$i++)
$this->titulos[] = mysql_field_name($result, $i);
$this->currgroup = "";
$this->AddPage();
$this->AliasNbPages();
while($row)
{
if($this->hasgroup)
{
if($this->currgroup != $row[mysql_num_fields($result)-1])
{
if($this->hasgroupfoot & (!$this->blank))
$this->semifoot = $this->putfoot($this->semifoot, true);
$this->currgroup = $row[mysql_num_fields($result)-1];
$this->Group(true);
};
}
for($i=0;$i<count($this->titulos);$i++)
{
$this->SetFillColor(0xFF, 0xFF, 0xFF);
$this->SetTextColor(0,0,0);
$this->SetFont('Arial','',$this->stdfont);
if(!(strpos($row[$i], '<red>') === false))
$this->SetTextColor(0xFF,0,0);
if(!(strpos($row[$i], '<green>') === false))
$this->SetTextColor(0,0xFF,0);
if(!(strpos($row[$i], '<blue>') === false))
$this->SetTextColor(0,0,0xFF);
if(!(strpos($row[$i], '<b>') === false))
$this->SetFont('','B');
$texto = str_replace('<red>','', $row[$i]);
$texto = str_replace('<green>','', $texto);
$texto = str_replace('<blue>','', $texto);
$texto = str_replace('<b>','', $texto);
if(!(strpos($row[$i], '<exec>') === false))
$texto = eval(str_replace('<exec>','', $row[$i]));
$this->Cell($this->anchos[$i], 4, $texto,0,0, $this->align[$i], 1);
$this->Cell(1,4,'',0,0,'',1);
if(is_numeric($this->foot[$i]))
$this->foot[$i] += $texto;
if(is_numeric($this->semifoot[$i]))
$this->semifoot[$i] += $texto;
}
$this->Ln(ceil($this->stdfont / $this->k) + 0.5);
for($sub=0;$sub<count($this->subquery);$sub++)
{
$datos = false;
$this->SetFont('Arial','',$this->subfont);
$this->SetTextColor(0,0,0);
$tq = str_replace('/recid/', $row[0], $this->subquery[$sub]);
$result2 = mysql_query($tq) or trigger_error("MySQL Error:" . mysql_error() . "<br>\nSQL:" . $tq, E_USER_ERROR);
if(mysql_num_rows($result2) > 0)
{
if($sub == 0) // Mostrar la linea solo la primera vez
{
$this->Line($this->lMargin, $this->y, $this->w - $this->rMargin, $this->y);
if(!empty($this->subhead))
{
for($i=0;$i<count($this->subhead);$i++)
$this->Cell($this->subanchos[$i]+1, 5, $this->subhead[$i],0, 'L');
$this->Ln(ceil($this->subfont / $this->k) + 1);
}
}
$datos = true;
}
while($row2 = mysql_fetch_row($result2))
{
for($i=0;$i<count($this->subhead);$i++)
{
$texto = $row2[$i];
$this->Cell($this->subanchos[$i], 4, $texto,0,0, $this->subalign[$i], 1);
$this->Cell(1,4,'',0,0,'',1);
if(is_numeric($this->subfoot[$sub][$i]))
$this->subfoot[$sub][$i] += $texto;
if(is_numeric($this->subtotalfoot[$i]))
$this->subtotalfoot[$i] += $texto;
}
$this->Ln(ceil($this->subfont / $this->k) + 0.5);
}
if($datos)
{
$this->putfoot($this->subfoot[$sub], true, true);
}
}
if($this->hassubtotalfoot)
{
$this->putfoot($this->subtotalfoot, true, true);
}
if(count($this->subquery) > 0)
$this->SetFont('Arial','',$this->stdfont);
$row = mysql_fetch_array($result);
}
if($this->hasgroupfoot)
$this->putfoot($this->semifoot, false);
if($this->hasfoot)
$this->putfoot($this->foot, false);
}
function putfoot(&$foot, $reset, $sub = false)
{
$this->SetTextColor(0,0,0);
if(!$sub)
{
$tope = count($this->titulos);
$anch = $this->anchos;
$alg = $this->align;
} else {
$tope = count($this->subhead);
$anch = $this->subanchos;
$alg = $this->subalign;
}
for($i=0;$i<$tope;$i++)
{
$toprint = $foot[$i];
if(is_numeric($foot[$i]))
{
$this->Line($this->GetX(), $this->GetY(), $this->GetX() + $anch[$i], $this->GetY());
if($reset)
$foot[$i] = 0;
if(!$this->notdecimalfoot)
$toprint = sprintf("%.2f", $toprint);
}
$this->Cell($anch[$i], 4, $toprint,0,0, $alg[$i]);
$this->Cell(1,4);
}
$this->Ln(ceil($this->stdfont / $this->k) + 0.5);
return $foot;
}
}
?>