예제 #1
0
function generateListPDF($searchData = null)
{
    $pdf = new BuildingListPDF();
    $pdf->SetMargins(15, 20, 15);
    // mm
    $pdf->bottom_margin = 20;
    // mm
    $pdf->page_height = 297;
    // mm
    $pdf->SetAutoPageBreak(true, $pdf->bottom_margin);
    //set pagebreak auto=false
    $pdf->pagebreak = false;
    //used for manual pagebreak
    $pdf->AliasNbPages();
    $pdf->SetFont('Helvetica', '', 12);
    $pdf->left_page_title = "Suchergebnisse";
    setlocale(LC_TIME, "de_DE");
    $pdf->right_page_title = ltrim(strftime("%d. %B %G"), '0');
    $pdf->AddPage();
    $pdf->Ln(5);
    if (is_null($searchData)) {
        $buildings_count = Idp_Main::getBuildings(true, 0, 1844674407371, 'published');
        $buildings = Idp_Main::getBuildings(false, 0, 1844674407371, 'published');
    } else {
        $buildings_count = Idp_Main::searchBuildings($searchData, false, true);
        $buildings = Idp_Main::searchBuildings($searchData, false, false);
        $pdf->printSearchData($searchData);
    }
    $counter = 1;
    foreach ($buildings as $building) {
        $building->address = Idp_Main::getBuildingAddress($building->id);
    }
    usort($buildings, create_function('$a, $b', 'return strnatcasecmp($a->address, $b->address);'));
    $pdf->offset_images = $pdf->GetX();
    $pdf->offset_text = $pdf->GetX() + 40;
    $pdf->YafterImage = 0;
    $pdf->YafterDescription = 0;
    $space = 0;
    foreach ($buildings as $building) {
        $main_image_thumb = wp_get_attachment_image_src($building->main_image, 'thumbnail');
        if ($main_image_thumb === false) {
            $main_image_thumb[0] = get_template_directory_uri() . "/images/spacer.png";
        }
        $pdf->Y = $pdf->GetY();
        $space_left = $pdf->page_height - ($pdf->Y + $pdf->bottom_margin);
        if (40 > $space_left) {
            $pdf->AddPage();
            $pdf->Ln(5);
            $pdf->Y = $pdf->GetY();
            $pdf->SetX($pdf->offset_images);
        }
        $pdf->Image($main_image_thumb[0], $pdf->offset_images, $pdf->Y, 36);
        $pdf->YafterImage = $pdf->GetY() + 45;
        $pdf->SetXY($pdf->offset_text, $pdf->Y);
        $pdf->SetFont('Helvetica', 'B', 12);
        $pdf->Write(5, utf8_decode($building->address));
        $pdf->Ln(5);
        $pdf->SetFont('Helvetica', '', 12);
        if (strlen($building->description) > 0) {
            $pdf->SetX($pdf->offset_text);
            $pdf->MultiAlignCell(0, 5, utf8_decode($building->description), 0, 2, 'L');
            $pdf->YafterDescription = $pdf->GetY();
        } else {
            $pdf->YafterDescription = $pdf->YafterImage;
        }
        if ($pdf->YafterImage >= $pdf->YafterDescription) {
            $pdf->Y = $pdf->YafterImage;
            $space = 0;
        } else {
            $pdf->Y = $pdf->YafterDescription;
            $space = 5;
        }
        if ($pdf->pagebreak) {
            $pdf->SetY($pdf->YafterDescription + 5);
            $pdf->pagebreak = false;
        } else {
            $pdf->SetY($pdf->Y + $space);
        }
        if ($counter == 150) {
            break;
        }
        $counter++;
    }
    //all content printed to page -> finished
    $pdf->Output($pdf->left_page_title . ".pdf", "I", true);
    exit;
}
        $list_start = ($this_page - 1) * $per_page;
        if ($list_start >= $pagination_count) {
            //Start of the list should be less than pagination count
            $list_start = $pagination_count - $per_page;
        }
        if ($list_start < 0) {
            //list start cannot be negative
            $list_start = 0;
        }
        $list_end = $this_page * $per_page - 1;
        //Get the data from the database
        if ($_SERVER["REQUEST_METHOD"] == "POST") {
            $buildings = Idp_Main::searchBuildings($searchParameters, $image_mode, false, $list_start, $per_page);
        } else {
            if (isset($_SESSION['searchData'])) {
                $buildings = Idp_Main::searchBuildings($_SESSION['searchData'], $image_mode, false, $list_start, $per_page);
            } else {
                $buildings = Idp_Main::getBuildings(false, $list_start, $per_page, 'published');
            }
        }
    }
    ?>
	
		</div>                    
    </div>
			
 <!-- CONTENT START -->
	<?php 
    showSearchForm($searchParameters);
    if ($_POST || isset($_SESSION['searchData'])) {
        if ($pagination_count == 0) {