Location: PHPKode > projects > Modular Railroad Asset/Meeting Mgmt > fredl-2-1-9-Release/loco/lococard.php
<?php
    session_cache_limiter('private');
    require_once('../php/fredlSession.php');
    /****************************************************************
     * FREMO Asset Management
     * Module: lococard.php
     * Description: Create a PDF for loco cards
     *
     * $Log: lococard.php,v $
     * Revision 1.5  2005/08/07 07:50:49  klk32002
     * Added one Translation.
     *
     * Revision 1.4  2005/06/08 12:26:28  dirkj
     * Made multilingual.
     *
     * Revision 1.3  2004/11/01 12:35:47  dirkj
     * Modified session handling.
     *
     * Revision 1.2  2004/09/19 21:07:30  dirkj
     * Added Company.
     * Added dcc adress on backside.
     *
     * Revision 1.1  2004/09/18 17:05:10  dirkj
     * Initial Revision.
     *
     ****************************************************************/
    require_once '../php/sessionhelpers.inc.php';
    require_once '../php/uihelpers.inc.php';
    require_once('../php/fpdf.php');
    require_once('../lib/loco.php');
    require_once('../lib/lang.php');
    $usrObj=getUserObject();
    $l = new Lang($usrObj->langid, 'loco-card', 'loco,general');

class LocoCard extends FPDF
{

	function fitToField($fontSize, $width, $text)
	{
		do
		{
			$this->SetFontSize($fontSize);
			$fontSize -= 1;
		} while ($this->GetStringWidth($text) > $width);
		return $fontSize;
	}

	function printCard($numX, $numY, &$loco)
	{
		global $l;	// language selector

		$lMargin=15;
		$tMargin=30;
		$cardWidth=21;
		$cardHeight=90;
		$vCardSpace=15;
		$hCardSpace=4;

		$this->SetFillColor(255,255,255);
		$this->SetTextColor(0);
		$this->SetDrawColor(0,0,0);

		$this->SetFont('Arial','',8);
		$startx=$lMargin+$numX*(2*$cardWidth+$hCardSpace);
		$starty=$tMargin+$numY*($cardHeight+$vCardSpace);

		$usrObj=getUserObject($loco->get('ownerid'));


		$x=$startx;
		$y=$starty;

		/* -- Rahmen für Vorder-/Rückseite -- */
		$this->SetLineWidth(0.1);
		$this->SetXY($x,$y);
		$this->Rect($x,$y,21,90,'D');
		$this->Rect($x+21,$y,21,90,'D');

		/* -- Vorderseite -- */
		$this->SetLineWidth(0.4);
		$this->SetXY($x,$y);
		$this->SetFont('Arial','',34);
		$baureihe=$loco->get('baureihe');
		$this->fitToField(30, 20, $baureihe);
		$this->Cell(21,10,''.$baureihe,'B',0,'C',0);
		$y += 11;

		$this->SetXY($x,$y);
		$this->SetFont('Arial','',20);
		$company=$loco->get('company');
		$this->fitToField(20, 20, $company);
		$this->Cell(21,5,''.$company,'B',0,'C',0);
		$y += 6;

		$this->SetXY($x,$y);
		$this->SetFont('Arial','',9);
		$this->Cell(21,6,$l->get('loco-dcc-adress','Adresse:'),'',0,'C',0);
		$y += 6;

		$this->SetXY($x,$y);
		$this->SetFont('Arial','',12);
		$this->Cell(21,6,$loco->get('dccadr'),'B',0,'C',0);
		$y += 6;

		$this->SetXY($x,$y);
		$this->SetFont('Arial','',8);
		$owner=$usrObj->name."\n\n".$l->get('colorcode-colon','Farbcode:')."\n".$usrObj->colorcode."";
		$this->MultiCell(21,6,''.$owner,0,'L',0);
		$y += 30;

		/* -- Rückseite -- */
		$x=$startx+$cardWidth;
		$y=$starty;
		$this->SetLineWidth(0.4);
		$this->SetXY($x,$y);
		$this->SetFont('Arial','',34);
		$baureihe=$loco->get('baureihe');
		$this->fitToField(30, 20, $baureihe);
		$this->Cell(21,10,''.$baureihe,'B',0,'C',0);
		$y += 11;

		$this->SetXY($x,$y);
		$this->SetFont('Arial','',20);
		$company=$loco->get('company');
		$this->fitToField(20, 20, $company);
		$this->Cell(21,5,''.$company,'B',0,'C',0);
		$y += 6;

		$this->SetXY($x,$y);
		$this->SetFont('Arial','',6);
		$txt='';
		$txt.=$l->get('loco-dcc-adress','Adresse:')." ";
		$dccadr=$loco->get('dccadr');
		if (strlen(''.$dccadr)>0)
		   $txt.=$dccadr;
		else $txt.= "--";
		$txt .= "\n";
		$decoder=$loco->get('decodertype');
		if (strlen(''.$decoder)>0)
		   $txt.=$l->get('loco-decoder-type',"Decoder:")."\n".$decoder."\n";
		$dcc=$loco->get('dccdescription');
		if (strlen(''.$dcc) > 0)
			$txt.=$dcc."\n";
			// $txt.=$l->get('loco-dcc-description',"Digital:")."\n".$dcc."\n";
		$txt.="\n";
		$txt.=$l->get('general-loco',"Fahrzeug:")."\n";
		$desc=$loco->get('description');
		$txt.=$desc."\n\n";

		$txt.=$l->get('loco-usedfor',"Einsatz:")."\n";
		// $txt.="  ".$l->get('loco-passenger-train','P-Züge:')." ";
		if ($loco->get('passenger')) $txt.="X  ";  else $txt.="     ";
		$txt.=$l->get('loco-passenger-train','P-Züge')."\n";
		// if ($loco->get('passenger')) $txt.=$l->get('general-yes',"Ja"); else $txt.=" -- ";
		// $txt.="\n  ".$l->get('loco-cargo-train','G-Züge:')." ";
		// if ($loco->get('cargo')) $txt.=$l->get('general-yes',"Ja"); else $txt.=" -- ";
		if ($loco->get('cargo')) $txt.="X  "; else $txt.="     ";
		$txt.=$l->get('loco-cargo-train','G-Züge')."\n";
		// $txt.="\n  ".$l->get('loco-shunter','Rangieren:')." ";
		// if ($loco->get('shunter')) $txt.=$l->get('general-yes',"Ja"); else $txt.=" -- ";
		if ($loco->get('shunter')) $txt.="X  "; else $txt.="     ";
		$txt.=$l->get('loco-shunter','Rangieren')." ";
		$txt.="\n\n";
		$txt.=$l->get('general-vmax-colon',"Vmax:")." ".$loco->get('vmax')."\n\n";
		$txt.=$l->get('general-since-colon',"Im Einsatz:")."\n   ";
		$timeFrom=$loco->get('einsatzvon');
		$timeUntil=$loco->get('einsatzbis');
		if (strlen(''.$timeFrom)>0)
		   $txt.=$timeFrom." ";
		else $txt .= ' -- ';
		$txt.=$l->get('general-timeframe-until'," - ")." ";
		if (strlen(''.$timeUntil)>0)
		   $txt.=$timeUntil;
		else $txt .= ' -- ';
		$txt.="\n\n";
		$wheel=$loco->getLookedUp('rad');
		if (strlen(''.$wheel)>0)
		   $txt.=$l->get('general-wheel-colon',"Modellrad:")." ".$wheel."\n\n";
		$this->MultiCell(21,3.0,''.$txt,0,'L',0);
	}


	function Footer()
	{
	    //aktuelle Position 1,5 cm von unten
	    $this->SetY(-15);
	    //Schrift Arial, kursiv, Größe 8
	    $this->SetFont('Arial','',10);
	    //zentriert die Seitenzahl ausgeben
	    $now=getdate();
	    $this->Cell(0,10,
	     		sprintf("%d.%d.%d  %d:%02d",
	                	$now['mday'],
				$now['mon'],
				$now['year'],
				$now['hours'],
				$now['minutes']).'             '.
	                'FRED-Karten aus FREDL ('.getVersion().')             '.
			'Seite '.$this->PageNo(),
			0,0,'C');
	}

}


$pdf=new LocoCard('P','mm','A4');
$check=POST2Var('check');

// The card positions are row=0,1 and col=0,1,2,3
// Start position is last card of a page; will be incremented before
// first card will be printed.
$row=1;
$col=3;

// Allocate an object that will be reused for each card to be printed
$loco = new Loco();

if (isset($check) && is_array($check))
{
	foreach ($check as $locoid)
	{
		// calc output of next card
		$col++;
		if ($col > 3) { $col=0; $row++; }
		if ($row > 1) { $row=0; $pdf->AddPage(); }
		$loco->clear();
		$loco->dbRead($locoid);
		$pdf->printCard($col, $row, $loco);

	}

	$l->addTranslationHelperToPdf($pdf);
	$pdf->Output();
} else {
	print "<html>";
	print "<head>";
	print '<link rel="stylesheet" type="text/css" href="../'.$myStyleSheet.'">';
	print '</head>';
	print '<body class=right>';
	print $l->get('loco-card-nosel-msg','<p>Es wurden keine Tfz markiert, deshalb erfolgt auch keine Ausgabe von FRED-Karten.</p>');
	print "</body>";
	print "</html>";
}

?>
Return current item: Modular Railroad Asset/Meeting Mgmt