Inhaltsverzeichnis drucken
This commit is contained in:
286
dashboard/print_toc.php
Normal file
286
dashboard/print_toc.php
Normal file
@ -0,0 +1,286 @@
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
require_once("../config.inc.php");
|
||||
require('../fpdf186/fpdf.php');
|
||||
require_once('../fpdf186/FPDI-master/src/autoload.php');
|
||||
use setasign\Fpdi\Fpdi;
|
||||
|
||||
// https://www.vonderborn.com/erweiterte-tabellen-mit-fpdf.php
|
||||
/*
|
||||
Dokumentation
|
||||
Der Quellcode ist eigentlich selbst erkl<6B>rend. Mehreren Zellen werdern in einem Array zu einer Zeile zusammengefasst, welche dann das Array f<>r die Visualisierung darstellt und an die Funktion WriteTable <20>bergeben wird.
|
||||
Das Array muss f<>r jede Celle jeweils komplett gef<65>llt werden. Farben werden als RGB im CSV <20>bergegeben.
|
||||
Linearea gibt an, ob linke, rechte, obere oder untere Rahmen angezeigt werden sollen. Alles andere sollte logisch sein. Ansonsten in den Beispielen etwas rumprobieren.
|
||||
*/
|
||||
class MYPDF extends FPDI
|
||||
{
|
||||
// Margins
|
||||
var $left = 20;
|
||||
var $right = 10;
|
||||
var $top = 10;
|
||||
var $bottom = 10;
|
||||
|
||||
// Create Table
|
||||
function WriteTable($tcolums)
|
||||
{
|
||||
// go through all colums
|
||||
for ($i = 0; $i < sizeof($tcolums); $i++)
|
||||
{
|
||||
$current_col = $tcolums[$i];
|
||||
$height = 0;
|
||||
|
||||
// get max height of current col
|
||||
$nb=0;
|
||||
for($b = 0; $b < sizeof($current_col); $b++)
|
||||
{
|
||||
// set style
|
||||
$this->SetFont($current_col[$b]['font_name'], $current_col[$b]['font_style'], $current_col[$b]['font_size']);
|
||||
$color = explode(",", $current_col[$b]['fillcolor']);
|
||||
$this->SetFillColor($color[0], $color[1], $color[2]);
|
||||
$color = explode(",", $current_col[$b]['textcolor']);
|
||||
$this->SetTextColor($color[0], $color[1], $color[2]);
|
||||
$color = explode(",", $current_col[$b]['drawcolor']);
|
||||
$this->SetDrawColor($color[0], $color[1], $color[2]);
|
||||
$this->SetLineWidth($current_col[$b]['linewidth']);
|
||||
|
||||
$nb = max($nb, $this->NbLines($current_col[$b]['width'], $current_col[$b]['text']));
|
||||
$height = $current_col[$b]['height'];
|
||||
}
|
||||
$h=$height*$nb;
|
||||
|
||||
|
||||
// Issue a page break first if needed
|
||||
$this->CheckPageBreak($h);
|
||||
|
||||
// Draw the cells of the row
|
||||
for($b = 0; $b < sizeof($current_col); $b++)
|
||||
{
|
||||
$w = $current_col[$b]['width'];
|
||||
$a = $current_col[$b]['align'];
|
||||
|
||||
// Save the current position
|
||||
$x=$this->GetX();
|
||||
$y=$this->GetY();
|
||||
|
||||
// set style
|
||||
$this->SetFont($current_col[$b]['font_name'], $current_col[$b]['font_style'], $current_col[$b]['font_size']);
|
||||
$color = explode(",", $current_col[$b]['fillcolor']);
|
||||
$this->SetFillColor($color[0], $color[1], $color[2]);
|
||||
$color = explode(",", $current_col[$b]['textcolor']);
|
||||
$this->SetTextColor($color[0], $color[1], $color[2]);
|
||||
$color = explode(",", $current_col[$b]['drawcolor']);
|
||||
$this->SetDrawColor($color[0], $color[1], $color[2]);
|
||||
$this->SetLineWidth($current_col[$b]['linewidth']);
|
||||
|
||||
$color = explode(",", $current_col[$b]['fillcolor']);
|
||||
$this->SetDrawColor($color[0], $color[1], $color[2]);
|
||||
|
||||
|
||||
// Draw Cell Background
|
||||
$this->Rect($x, $y, $w, $h, 'FD');
|
||||
|
||||
$color = explode(",", $current_col[$b]['drawcolor']);
|
||||
$this->SetDrawColor($color[0], $color[1], $color[2]);
|
||||
|
||||
// Draw Cell Border
|
||||
if (substr_count($current_col[$b]['linearea'], "T") > 0)
|
||||
{
|
||||
$this->Line($x, $y, $x+$w, $y);
|
||||
}
|
||||
|
||||
if (substr_count($current_col[$b]['linearea'], "B") > 0)
|
||||
{
|
||||
$this->Line($x, $y+$h, $x+$w, $y+$h);
|
||||
}
|
||||
|
||||
if (substr_count($current_col[$b]['linearea'], "L") > 0)
|
||||
{
|
||||
$this->Line($x, $y, $x, $y+$h);
|
||||
}
|
||||
|
||||
if (substr_count($current_col[$b]['linearea'], "R") > 0)
|
||||
{
|
||||
$this->Line($x+$w, $y, $x+$w, $y+$h);
|
||||
}
|
||||
|
||||
|
||||
// Print the text
|
||||
$this->MultiCell($w, $current_col[$b]['height'], $current_col[$b]['text'], 0, $a, 0);
|
||||
|
||||
// Put the position to the right of the cell
|
||||
$this->SetXY($x+$w, $y);
|
||||
}
|
||||
|
||||
// Go to the next line
|
||||
$this->Ln($h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If the height h would cause an overflow, add a new page immediately
|
||||
function CheckPageBreak($h)
|
||||
{
|
||||
if($this->GetY()+$h>$this->PageBreakTrigger)
|
||||
$this->AddPage($this->CurOrientation);
|
||||
}
|
||||
|
||||
|
||||
// Computes the number of lines a MultiCell of width w will take
|
||||
function NbLines($w, $txt)
|
||||
{
|
||||
$cw=&$this->CurrentFont['cw'];
|
||||
if($w==0)
|
||||
$w=$this->w-$this->rMargin-$this->x;
|
||||
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
|
||||
$s=str_replace("\r", '', $txt);
|
||||
$nb=strlen($s);
|
||||
if($nb>0 and $s[$nb-1]=="\n")
|
||||
$nb--;
|
||||
$sep=-1;
|
||||
$i=0;
|
||||
$j=0;
|
||||
$l=0;
|
||||
$nl=1;
|
||||
while($i<$nb)
|
||||
{
|
||||
$c=$s[$i];
|
||||
if($c=="\n")
|
||||
{
|
||||
$i++;
|
||||
$sep=-1;
|
||||
$j=$i;
|
||||
$l=0;
|
||||
$nl++;
|
||||
continue;
|
||||
}
|
||||
if($c==' ')
|
||||
$sep=$i;
|
||||
$l+=$cw[$c];
|
||||
if($l>$wmax)
|
||||
{
|
||||
if($sep==-1)
|
||||
{
|
||||
if($i==$j)
|
||||
$i++;
|
||||
}
|
||||
else
|
||||
$i=$sep+1;
|
||||
$sep=-1;
|
||||
$j=$i;
|
||||
$l=0;
|
||||
$nl++;
|
||||
}
|
||||
else
|
||||
$i++;
|
||||
}
|
||||
return $nl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$pdf=new MYPDF('P','mm','A4');
|
||||
$pdf->SetAutoPageBreak(false);
|
||||
$pdf->AliasNbPages();
|
||||
$pdf->SetMargins($pdf->left, $pdf->top, $pdf->right);
|
||||
$pdf->AddPage();
|
||||
|
||||
// create table
|
||||
$columns = array();
|
||||
|
||||
// header col
|
||||
#$col = array();
|
||||
#$col[] = array('text' => 'Datum', 'width' => '20', 'height' => '5', 'align' => 'C', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => 'B', 'fillcolor' => '135,206,250', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
#$col[] = array('text' => 'Text', 'width' => '125', 'height' => '5', 'align' => 'C', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => 'B', 'fillcolor' => '135,206,250', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
#$col[] = array('text' => 'Soll', 'width' => '15', 'height' => '5', 'align' => 'C', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => 'B', 'fillcolor' => '135,206,250', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
#$col[] = array('text' => 'Haben', 'width' => '15', 'height' => '5', 'align' => 'C', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => 'B', 'fillcolor' => '135,206,250', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
#$col[] = array('text' => 'Saldo', 'width' => '15', 'height' => '5', 'align' => 'C', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => 'B', 'fillcolor' => '135,206,250', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
#$columns[] = $col;
|
||||
/*
|
||||
// data col
|
||||
$col = array();
|
||||
$col[] = array('text' => '01.12.2010', 'width' => '20', 'height' => '5', 'align' => 'L', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => '', 'fillcolor' => '255,255,255', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
$col[] = array('text' => 'Rechnungs Nr 123456789', 'width' => '125', 'height' => '5', 'align' => 'L', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => '', 'fillcolor' => '255,255,255', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
$col[] = array('text' => '120.50', 'width' => '15', 'height' => '5', 'align' => 'R', 'font_name' => 'Arial', 'font_size' => '12', 'font_style' => '', 'fillcolor' => '255,255,255', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
$col[] = array('text' => '', 'width' => '15', 'height' => '5', 'align' => 'R', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => 'B', 'fillcolor' => '255,255,255', 'textcolor' => '0,0,255', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
$col[] = array('text' => '120.50S', 'width' => '15', 'height' => '5', 'align' => 'R', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => '', 'fillcolor' => '255,255,255', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
$columns[] = $col;
|
||||
|
||||
// data col
|
||||
$col = array();
|
||||
$col[] = array('text' => '15.12.2010', 'width' => '20', 'height' => '5', 'align' => 'L', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => '', 'fillcolor' => '255,255,255', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
$col[] = array('text' => 'Zahlung: 123456789', 'width' => '125', 'height' => '5', 'align' => 'L', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => '', 'fillcolor' => '255,255,255', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
$col[] = array('text' => '', 'width' => '15', 'height' => '5', 'align' => 'R', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => '', 'fillcolor' => '255,255,255', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
$col[] = array('text' => '120.50', 'width' => '15', 'height' => '5', 'align' => 'R', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => '', 'fillcolor' => '255,255,255', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
$col[] = array('text' => '0.00H', 'width' => '15', 'height' => '5', 'align' => 'R', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => '', 'fillcolor' => '255,255,255', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
$columns[] = $col;
|
||||
|
||||
$col = array();
|
||||
$col[] = array('text' => 'Ist der Text zu lang, ist das kein Problem', 'width' => '50', 'height' => '5', 'align' => 'R', 'font_name' => 'Arial', 'font_size' => '12', 'font_style' => '', 'fillcolor' => '0,0,255', 'textcolor' => '0,255,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
$col[] = array('text' => 'Auch mit mehreren Farben ist es kein Problem', 'width' => '50', 'height' => '5', 'align' => 'L', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => 'B', 'fillcolor' => '255,255,0', 'textcolor' => '0,255,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
$col[] = array('text' => 'So ist das Bauen einer Tabelle einfach nur einfach. MuliCell macht es einfach. Okay das ist nun lang genug', 'width' => '50', 'height' => '5', 'align' => 'C', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => '', 'fillcolor' => '255,255,255', 'textcolor' => '0,255,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
$col[] = array('text' => 'Erstellen von Rechnungen sind kein Problem mehr', 'width' => '40', 'height' => '5', 'align' => 'L', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => '', 'fillcolor' => '255,0,255', 'textcolor' => '0,255,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
$columns[] = $col;
|
||||
|
||||
$col = array();
|
||||
$col[] = array('text' => 'Einfach nur mal eine Zeile ohne Rahmen', 'width' => '190', 'height' => '5', 'align' => 'L', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => '', 'fillcolor' => '255,255,255', 'textcolor' => '0,255,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'TB');
|
||||
$columns[] = $col;
|
||||
|
||||
$col = array();
|
||||
$col[] = array('text' => 'Einfach nur mal eine Zeile in der Tabelle', 'width' => '80', 'height' => '5', 'align' => 'L', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => '', 'fillcolor' => '255,0,0', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
$col[] = array('text' => 'Gerne auch mit einer Spalte mehr', 'width' => '110', 'height' => '5', 'align' => 'L', 'font_name' => 'Arial', 'font_size' => '8', 'font_style' => '', 'fillcolor' => '255,255,255', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.4', 'linearea' => 'LTBR');
|
||||
$columns[] = $col;
|
||||
|
||||
*/
|
||||
|
||||
|
||||
$zsid = $_GET['zsid'];
|
||||
$query = "SELECT liednr, titel
|
||||
FROM jumi_noten_daten a, jumi_noten_zusammenstellung_zuord b
|
||||
WHERE a.jndid=b.jndid
|
||||
AND b.zsid=$zsid
|
||||
ORDER BY titel";
|
||||
#ORDER BY CAST(liednr AS UNSIGNED), liednr
|
||||
$result = $db->query ($query)
|
||||
or die ("Cannot execute query");
|
||||
$query_titel = $db->query ("SELECT bezeichnung
|
||||
FROM jumi_noten_zusammenstellung
|
||||
WHERE zsid =$zsid");
|
||||
$row_titel = $query_titel->fetch_array();
|
||||
|
||||
$pdf->Image('../media/qr_liedordner.png', 18, 7, 20,20);
|
||||
$pdf->SetFont('Arial', 'B', 20);
|
||||
$pdf->SetTextColor(13,115,119);
|
||||
$pdf->Cell(0, 3, "Inhaltsverzeichnis", 0, 0, 'C');
|
||||
$pdf->SetFont('Arial', '', 10);
|
||||
$pos = $pdf->GetY()+5;
|
||||
$pdf->SetY($pos);
|
||||
$pdf->Cell(0, 3, "(Aktuelles Inhaltsverzeichnis findest Du beim Aufruf des QR-Codes)", 0, 0, 'C');
|
||||
$pos = $pdf->GetY()+15;
|
||||
$pdf->SetY($pos);
|
||||
while ($row = $result->fetch_array()){
|
||||
$col = array();
|
||||
$col[] = array('text' => utf8_decode($row['titel']), 'width' => '160', 'height' => '7', 'align' => 'L', 'font_name' => 'Arial', 'font_size' => '12', 'font_style' => '', 'fillcolor' => '255,255,255', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.2', 'linearea' => 'LTB');
|
||||
$col[] = array('text' => $row['liednr'], 'width' => '20', 'height' => '7', 'align' => 'R', 'font_name' => 'Arial', 'font_size' => '12', 'font_style' => '', 'fillcolor' => '255,255,255', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.2', 'linearea' => 'TBR');
|
||||
$columns[] = $col;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Draw Table
|
||||
$pdf->WriteTable($columns);
|
||||
|
||||
$pos=$pdf->GetY();
|
||||
for($i=$pos;$i<270;$i++){
|
||||
$fil = array();
|
||||
$fil[] = array('text' => "", 'width' => '180', 'height' => '7', 'align' => 'L', 'font_name' => 'Arial', 'font_size' => '12', 'font_style' => '', 'fillcolor' => '255,255,255', 'textcolor' => '0,0,0', 'drawcolor' => '0,0,0', 'linewidth' => '0.2', 'linearea' => 'LTBR');
|
||||
$i=$i+6;
|
||||
$filler[] = $fil;
|
||||
}
|
||||
$pdf->WriteTable($filler);
|
||||
|
||||
// Show PDF
|
||||
#$pdf->Output();
|
||||
|
||||
$pdf->Output('I',utf8_decode($row_titel['bezeichnung']).'_toc');
|
||||
|
||||
?>
|
Reference in New Issue
Block a user