diff -r c2d325791e24 -r f1a8785434e4 fhiiqm/test/fpdf_create.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fhiiqm/test/fpdf_create.php Fri Dec 21 15:31:50 2012 +0100 @@ -0,0 +1,259 @@ +GetStringWidth($txt); + // Division by 0 avoid, 21.11.2012, bs + if ($str_width == 0) $str_width = 0.1; + + //Calculate ratio to fit cell + if($w==0) + $w = $this->w-$this->rMargin-$this->x; + $ratio = ($w-$this->cMargin*2)/$str_width; + + $fit = ($ratio < 1 || ($ratio > 1 && $force)); + if ($fit) + { + if ($scale) + { + //Calculate horizontal scaling + $horiz_scale=$ratio*100.0; + //Set horizontal scaling + $this->_out(sprintf('BT %.2F Tz ET',$horiz_scale)); + } + else + { + //Calculate character spacing in points + $char_space=($w-$this->cMargin*2-$str_width)/max($this->MBGetStringLength($txt)-1,1)*$this->k; + //Set character spacing + $this->_out(sprintf('BT %.2F Tc ET',$char_space)); + } + //Override user alignment (since text will fill up cell) + $align=''; + } + + //Pass on to Cell method + $this->Cell($w,$h,$txt,$border,$ln,$align,$fill,$link); + + //Reset character spacing/horizontal scaling + if ($fit) + $this->_out('BT '.($scale ? '100 Tz' : '0 Tc').' ET'); + } + + //Cell with horizontal scaling only if necessary + function CellFitScale($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='') + { + $this->CellFit($w,$h,$txt,$border,$ln,$align,$fill,$link,true,false); + } + + //Cell with horizontal scaling always + function CellFitScaleForce($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='') + { + $this->CellFit($w,$h,$txt,$border,$ln,$align,$fill,$link,true,true); + } + + //Cell with character spacing only if necessary + function CellFitSpace($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='') + { + $this->CellFit($w,$h,$txt,$border,$ln,$align,$fill,$link,false,false); + } + + //Cell with character spacing always + function CellFitSpaceForce($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='') + { + //Same as calling CellFit directly + $this->CellFit($w,$h,$txt,$border,$ln,$align,$fill,$link,false,true); + } + + //Patch to also work with CJK double-byte text + function MBGetStringLength($s) + { + if($this->CurrentFont['type']=='Type0') + { + $len = 0; + $nbbytes = strlen($s); + for ($i = 0; $i < $nbbytes; $i++) + { + if (ord($s[$i])<128) + $len++; + else + { + $len++; + $i++; + } + } + return $len; + } + else + return strlen($s); + } + + //Kopfzeile + function Header() + { + global $header; + //$this->Cell(20); + //Titel + //Arial fett 15 + $this->SetFont('Arial','BI',11); + $this->Cell(55,10,'Fritz-Haber-Institut',0,0,'L'); + $this->SetFont('Arial','B',11); + $this->Cell(40,10,'Telefonverzeichnis',0,0,'L'); + $this->SetTextColor(255,0,0); + $this->Cell(0,10,'(intern)',0,0,'L'); + //Logo + $this->Image($_SERVER['DOCUMENT_ROOT']."/fhiiqm/img/fhilogotransp.png",170,8,25); + //Zeilenumbruch + $this->Ln(20); + //Colors, line width and bold font + $this->SetFont('helvetica','',8); + $this->SetFillColor(104,172,191); + $this->SetTextColor(0,0,102); + $this->SetDrawColor(255,255,255); + $this->SetLineWidth(.0); + $this->SetFont('','B'); + //Tabellen-Header immer im Kopf + $w=array(55,40,30,15,40); + for($i=0;$iCell($w[$i],5,$header[$i],1,0,'L',1); + $this->Ln(); + } + + //Fusszeile + function Footer() + { + //Position 1,5 cm von unten + $this->SetY(-15); + //Arial kursiv 8 + $this->SetFont('Arial','I',8); + //Datum der Liste + $heute = new DateTime(); + $this->Cell(0,10,$heute->format('d.m.Y H:i:s'),0,0,'L'); + //Seitenzahl + $this->Cell(0,10,'Seite '.$this->PageNo().'/{nb}',0,0,'R'); + } + //Colored table + function FancyTable($header,$data) + { + + //Colors, line width and bold font + $this->SetFillColor(104,172,191); + $this->SetTextColor(0,0,102); + $this->SetDrawColor(255,255,255); + $this->SetLineWidth(.0); + $this->SetFont('','B'); + + //Header notwendig fuer Tabelle, Hoehe = 0! + $w=array(55,40,30,15,40); + for($i=0;$iCell($w[$i],0,'',1,0,'L',1); + $this->Ln(); + //Color and font restoration +// $this->SetFillColor(222,222,222); + $this->SetFillColor(238,238,238); + $this->SetTextColor(0); + $this->SetFont(''); + //Data + $fill=0; + $fill = !$fill; + foreach($data as $row) + { + if ($row->persknr != $vpnr) + { +/* if ($newline) + { + $this->Cell(array_sum($w),4,'',0,'',$fill); + $this->Ln(); + $newline = 0; + } +*/ + $fill=!$fill; + $titel = ($row->titel)? ", $row->titel" : "" ; + $vname = ($row->vorname)? ", $row->vorname" : ""; + $name = $row->name . $titel . $vname; +/* $y = $this->GetY(); + if (strlen($row->name . $titel . $vname) > 40) + { + echo "name = $name
"; + $name = $row->name . $titel . "\n" . substr($vname,2); + $this->MultiCell($w[0],4,$name,0,'L',$fill); + $this -> SetXY($w[0]+$this->lMargin,$y); + $newline = 1; +*/ +/* } + else + $this->Cell($w[0],4,$name,'LR',0,'L',$fill); +*/ + $this->CellFitScale($w[0],4.5,$name,0,0,'L',$fill); + $this->CellFitScale($w[1],4.5,$row->abt_name,'LR',0,'L',$fill); + if ($row->telefon_typ == "fax") $typ = " FAX"; else $typ = ""; + if (!$row->public) $this->SetTextColor(255,0,0); else $this->SetTextColor(0,0,136); + $this->CellFitScale($w[2],4.5,$row->telefon_nr.$typ,'LR',0,'L',$fill); + $this->SetTextColor(0); + $this->CellFitScale($w[3],4.5,$row->geb_ID . " " . $row->raum_nr,'LR',0,'L',$fill); + $this->CellFitScale($w[4],4.5,$row->email,'LR',0,'L',$fill); + $this->Ln(); + } + else + { + $newline = 0; + $this->Cell($w[0],4.5,'','LR',0,'L',$fill); + if ($vabt != $row->abt_name) $abt = $row->abt_name; + else $abt = ''; + $this->CellFitScale($w[1],4.5,$abt,'LR',0,'L',$fill); + if ($row->telefon_typ == "fax") $typ = " FAX"; else $typ = ""; + if (!$row->public) $this->SetTextColor(255,0,0); else $this->SetTextColor(0,0,136); + $this->CellFitScale($w[2],4.5,$row->telefon_nr.$typ,'LR',0,'L',$fill); + $this->SetTextColor(0); + $this->CellFitScale($w[3],4.5,$row->geb_ID . " " . $row->raum_nr,'LR',0,'L',$fill); + $this->Cell($w[4],4.5,'','LR',0,'L',$fill); + $this->Ln(); + + } + $vpnr = $row->persknr; + $vabt = $row->abt_name; + } +// $this->Cell(array_sum($w),0,'','T'); + } + } + +// $pdf = new FPDF(); + $header=array('Name','Abteilung','Tel/Fax','Raum','E-Mail'); + $pdf = new PDF(); + $pdf->SetLeftMargin(25); + $pdf->AddPage(); + $pdf->AliasNbPages(); +/* + $pdf->SetFont('Arial','B',16); + $pdf->Cell(40,10,'Hallo Du!',0,1); + $pdf->SetFont('courier','i',12); + $pdf->Cell(100,10,'Dieser Text ist mit fpdf erstellt worden.',0,1); +*/ + // Telefonliste + include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php"); +// include_once ($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/func_lib.inc.php"); + + $dbc = new dbconnection(); + $sql = "SELECT persknr, name, vorname, titel, abt_name, telefon_nr, telefon_typ, public, geb_ID, raum_nr, email FROM v_tel_list + ORDER BY 2,3,5,6"; + $result = $dbc ->queryObjectArray($sql); + $pdf->SetFont('helvetica','',9); + + $pdf->FancyTable($header,$result); + $pdf->Output(); + +?> \ No newline at end of file