<?php
/*
define('RELATIVE_PATH','include/html2fpdf/');
define('FPDF_FONTPATH','include/html2fpdf/font/');
require_once("include/html2fpdf/html2fpdf.php");

$pdf = new HTML2FPDF("P");
$pdf->SetMargins(12,12,12);
$pdf->SetAutoPageBreak(true,0);
$pdf->AddPage();
$pdf->SetFont('arialpl', '', 10);

$cids=explode(",",$_REQUEST['uid']);
$count=count($cids);
$y=0;
for($i=0;$i<$count;$i++){
	if($i%3==0)$x=5;
	if($i%3==1)$x=75;
	if($i%3==2)$x=145;
	
	$nm=array();
	$r=mysql_fetch_array(mysql_query("select * from pcontacts where id='".$cids[$i]."'"));
	if($r['salutation'])$nm[]=$r['saultation'];
	if($r['first_name'])$nm[]=$r['first_name'];
	if($r['last_name'])$nm[]=$r['last_name'];
	
	$rr=mysql_fetch_array(mysql_query("select account_id from accounts_pcontacts where contact_id='".$r['id']."' and deleted='0'"));
	$rr=mysql_fetch_array(mysql_query("select * from accounts where id='".$rr['account_id']."'"));
	$r['primary_address_street']=$rr['billing_address_street'];
	$r['primary_address_postalcode']=$rr['billing_address_postalcode'];
	$r['primary_address_city']=$rr['billing_address_city'];
	$r['primary_address_country']=$rr['billing_address_country'];
	
	$name=iconv("UTF-8","ISO-8859-2",implode(" ",$nm));
	$pdf->SetXY($x,$y);
	$pdf->SetFont('arialpl', 'B', 10);
	$yy=$y;
	$pdf->Cell(60,6,$name,0,0,"C");
	$yy+=5;
	$pdf->SetXY($x,$yy);
	$pdf->SetFont('arialpl', '', 8);
	if($r['primary_address_street']){
		$pdf->Cell(60,6,iconv("UTF-8","ISO-8859-2",$rr['name']),0,0,"C");
		$yy+=5;
	}
	$pdf->SetXY($x,$yy);
	$pdf->SetFont('arialpl', '', 10);
	if($r['primary_address_street']){
		$pdf->Cell(60,6,iconv("UTF-8","ISO-8859-2",$r['primary_address_street']),0,0,"C");
		$yy+=5;
	}
	$pdf->SetXY($x,$yy);
	if($r['primary_address_postalcode'] || $r['primary_address_city']){
		$pdf->Cell(60,6,iconv("UTF-8","ISO-8859-2",$r['primary_address_postalcode'].' '.$r['primary_address_city']),0,0,"C");
		$yy+=5;
	}
	$pdf->SetXY($x,$yy);
	if($r['primary_address_country']){
		$pdf->Cell(60,6,iconv("UTF-8","ISO-8859-2",$r['primary_address_country']),0,0,"C");
		$yy+=5;
	}
	$ph=array();
	if($r['phone_work'])$ph[]="Tel.: ".$r['phone_work'];
	if($r['phone_mobile'])$ph[]="Kom.: ".$r['phone_mobile'];
	$phone=implode(" ",$ph);
	$pdf->SetXY($x,$yy);
	$pdf->SetFont('arialpl', '', 8);
	if($phone){
		$pdf->Cell(60,6,iconv("UTF-8","ISO-8859-2",$phone),0,0,"C");
		$yy+=5;
	}
	if($i%3==2)$y+=38;
	if($i==23){
		$pdf->AddPage();
		$y=0;
		$x=5;
	}
}

$pdf->Output("MailingTags.pdf", "D");*/

define('RELATIVE_PATH','include/html2fpdf/');
define('FPDF_FONTPATH','include/html2fpdf/font/');
require_once("include/html2fpdf/html2fpdf.php");

$pdf = new HTML2FPDF("L");
$pdf->SetMargins(12,12,12);
$pdf->SetAutoPageBreak(true,0);
$pdf->AddPage();
$pdf->SetFont('arialpl', '', 20);

$cids=explode(",",$_REQUEST['uid']);
$count=count($cids);
$y=37;
for($i=0;$i<$count;$i++){
	if($i%2==0)$x=0;
	if($i%2==1)$x=135;
	
	$nm=array();
	$r=mysql_fetch_array(mysql_query("select * from pcontacts where id='".$cids[$i]."'"));
	if($r['salutation'])$nm[]=$r['saultation'];
	if($r['first_name'])$nm[]=$r['first_name'];
	if($r['last_name'])$nm[]=$r['last_name'];
	
	$rr=mysql_fetch_array(mysql_query("select account_id from accounts_pcontacts where contact_id='".$r['id']."' and deleted='0'"));
	$rr=mysql_fetch_array(mysql_query("select * from accounts where id='".$rr['account_id']."'"));
	$r['primary_address_street']=$rr['billing_address_street'];
	$r['primary_address_postalcode']=$rr['billing_address_postalcode'];
	$r['primary_address_city']=$rr['billing_address_city'];
	$r['primary_address_country']=$rr['billing_address_country'];
	
	$name=iconv("UTF-8","ISO-8859-2",implode(" ",$nm));
	$pdf->SetXY($x,$y);
	$pdf->SetFont('arialpl', 'B', 20);
	$yy=$y;
	$pdf->Cell(160,6,$name,0,0,"C");
	$yy+=9;
	$pdf->SetXY($x,$yy);
	$pdf->SetFont('arialpl', '', 16);
	if($r['primary_address_street']){
		$pdf->Cell(160,6,iconv("UTF-8","ISO-8859-2",$rr['name']),0,0,"C");
		$yy+=9;
	}
	$pdf->SetXY($x,$yy);
	$pdf->SetFont('arialpl', '', 20);
	if($r['primary_address_street']){
		$pdf->Cell(160,6,iconv("UTF-8","ISO-8859-2",$r['primary_address_street']),0,0,"C");
		$yy+=9;
	}
	$pdf->SetXY($x,$yy);
	if($r['primary_address_postalcode'] || $r['primary_address_city']){
		$pdf->Cell(160,6,iconv("UTF-8","ISO-8859-2",$r['primary_address_postalcode'].' '.$r['primary_address_city']),0,0,"C");
		$yy+=9;
	}
	$pdf->SetXY($x,$yy);
	if($r['primary_address_country']){
		$pdf->Cell(160,6,iconv("UTF-8","ISO-8859-2",$r['primary_address_country']),0,0,"C");
		$yy+=9;
	}
	$ph=array();
	if($r['phone_work'])$ph[]="Tel.: ".$r['phone_work'];
	if($r['phone_mobile'])$ph[]="Kom.: ".$r['phone_mobile'];
	$phone=implode(" ",$ph);
	$pdf->SetXY($x,$yy);
	$pdf->SetFont('arialpl', '', 16);
	if($phone){
		$pdf->Cell(160,6,iconv("UTF-8","ISO-8859-2",""),0,0,"C");
		$yy+=9;
	}
	if($i%2==1)$y+=85;
	if($i%4==3 && $i!=$count-1){
		$pdf->AddPage();
		$y=37;
		$x=5;
	}
}

$pdf->Output("MailingTags.pdf", "D");


?>
