1*a25f0a04SGreg Roach<?php 2*a25f0a04SGreg Roachnamespace Webtrees; 3*a25f0a04SGreg Roach 4*a25f0a04SGreg Roach/** 5*a25f0a04SGreg Roach * webtrees: online genealogy 6*a25f0a04SGreg Roach * Copyright (C) 2015 webtrees development team 7*a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify 8*a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by 9*a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or 10*a25f0a04SGreg Roach * (at your option) any later version. 11*a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful, 12*a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 13*a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*a25f0a04SGreg Roach * GNU General Public License for more details. 15*a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License 16*a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 17*a25f0a04SGreg Roach */ 18*a25f0a04SGreg Roach 19*a25f0a04SGreg Roach/** 20*a25f0a04SGreg Roach * Class ReportHtmlCell 21*a25f0a04SGreg Roach */ 22*a25f0a04SGreg Roachclass ReportHtmlCell extends ReportBaseCell { 23*a25f0a04SGreg Roach /** 24*a25f0a04SGreg Roach * HTML Cell renderer 25*a25f0a04SGreg Roach * 26*a25f0a04SGreg Roach * @param ReportHtml $renderer 27*a25f0a04SGreg Roach * 28*a25f0a04SGreg Roach * @return void 29*a25f0a04SGreg Roach */ 30*a25f0a04SGreg Roach function render($renderer) { 31*a25f0a04SGreg Roach if (strpos($this->text, "{{:ptp:}}") !== false) { 32*a25f0a04SGreg Roach return; 33*a25f0a04SGreg Roach } 34*a25f0a04SGreg Roach $temptext = str_replace("#PAGENUM#", $renderer->pageNo(), $this->text); 35*a25f0a04SGreg Roach // underline «title» part of Source item 36*a25f0a04SGreg Roach $temptext = str_replace(array('«', '»'), array('<u>', '</u>'), $temptext); 37*a25f0a04SGreg Roach 38*a25f0a04SGreg Roach // Setup the style name 39*a25f0a04SGreg Roach if ($renderer->getCurrentStyle() != $this->styleName) { 40*a25f0a04SGreg Roach $renderer->setCurrentStyle($this->styleName); 41*a25f0a04SGreg Roach } 42*a25f0a04SGreg Roach 43*a25f0a04SGreg Roach // If (Future-feature-enable/disable cell padding) 44*a25f0a04SGreg Roach $cP = $renderer->cPadding; 45*a25f0a04SGreg Roach 46*a25f0a04SGreg Roach // Adjust the positions 47*a25f0a04SGreg Roach if ($this->left == ".") { 48*a25f0a04SGreg Roach $this->left = $renderer->getX(); 49*a25f0a04SGreg Roach } else { 50*a25f0a04SGreg Roach $renderer->setX($this->left); 51*a25f0a04SGreg Roach } 52*a25f0a04SGreg Roach 53*a25f0a04SGreg Roach if ($this->top == ".") { 54*a25f0a04SGreg Roach $this->top = $renderer->getY(); 55*a25f0a04SGreg Roach } else { 56*a25f0a04SGreg Roach $renderer->setY($this->top); 57*a25f0a04SGreg Roach } 58*a25f0a04SGreg Roach 59*a25f0a04SGreg Roach // Start collecting the HTML code 60*a25f0a04SGreg Roach echo "<div class=\"", $this->styleName, "\" style=\"position:absolute;top:", $this->top, "pt;"; 61*a25f0a04SGreg Roach // Use Cell around padding to support RTL also 62*a25f0a04SGreg Roach echo "padding:", $cP, "pt;"; 63*a25f0a04SGreg Roach // LTR (left) or RTL (right) 64*a25f0a04SGreg Roach echo $renderer->alignRTL, ":", $this->left, "pt;"; 65*a25f0a04SGreg Roach // Background color 66*a25f0a04SGreg Roach if (!empty($this->bgcolor)) { 67*a25f0a04SGreg Roach echo "background-color:", $this->bgcolor, ";"; 68*a25f0a04SGreg Roach } 69*a25f0a04SGreg Roach // Border setup 70*a25f0a04SGreg Roach $bpixX = 0; 71*a25f0a04SGreg Roach $bpixY = 0; 72*a25f0a04SGreg Roach if (!empty($this->border)) { 73*a25f0a04SGreg Roach // Border all around 74*a25f0a04SGreg Roach if ($this->border == 1) { 75*a25f0a04SGreg Roach echo " border:solid "; 76*a25f0a04SGreg Roach if (!empty($this->bocolor)) { 77*a25f0a04SGreg Roach echo $this->bocolor; 78*a25f0a04SGreg Roach } else { 79*a25f0a04SGreg Roach echo "black"; 80*a25f0a04SGreg Roach } 81*a25f0a04SGreg Roach echo " 1pt;"; 82*a25f0a04SGreg Roach $bpixX = 1; 83*a25f0a04SGreg Roach $bpixY = 1; 84*a25f0a04SGreg Roach } else { 85*a25f0a04SGreg Roach if (stripos($this->border, "T") !== false) { 86*a25f0a04SGreg Roach echo " border-top:solid "; 87*a25f0a04SGreg Roach if (!empty($this->bocolor)) { 88*a25f0a04SGreg Roach echo $this->bocolor; 89*a25f0a04SGreg Roach } else { 90*a25f0a04SGreg Roach echo "black"; 91*a25f0a04SGreg Roach } 92*a25f0a04SGreg Roach echo " 1pt;"; 93*a25f0a04SGreg Roach $bpixY = 1; 94*a25f0a04SGreg Roach } 95*a25f0a04SGreg Roach if (stripos($this->border, "B") !== false) { 96*a25f0a04SGreg Roach echo " border-bottom:solid "; 97*a25f0a04SGreg Roach if (!empty($this->bocolor)) { 98*a25f0a04SGreg Roach echo $this->bocolor; 99*a25f0a04SGreg Roach } else { 100*a25f0a04SGreg Roach echo "black"; 101*a25f0a04SGreg Roach } 102*a25f0a04SGreg Roach echo " 1pt;"; 103*a25f0a04SGreg Roach $bpixY = 1; 104*a25f0a04SGreg Roach } 105*a25f0a04SGreg Roach if (stripos($this->border, "R") !== false) { 106*a25f0a04SGreg Roach echo " border-right:solid "; 107*a25f0a04SGreg Roach if (!empty($this->bocolor)) { 108*a25f0a04SGreg Roach echo $this->bocolor; 109*a25f0a04SGreg Roach } else { 110*a25f0a04SGreg Roach echo "black"; 111*a25f0a04SGreg Roach } 112*a25f0a04SGreg Roach echo " 1pt;"; 113*a25f0a04SGreg Roach $bpixX = 1; 114*a25f0a04SGreg Roach } 115*a25f0a04SGreg Roach if (stripos($this->border, "L") !== false) { 116*a25f0a04SGreg Roach echo " border-left:solid "; 117*a25f0a04SGreg Roach if (!empty($this->bocolor)) { 118*a25f0a04SGreg Roach echo $this->bocolor; 119*a25f0a04SGreg Roach } else { 120*a25f0a04SGreg Roach echo "black"; 121*a25f0a04SGreg Roach } 122*a25f0a04SGreg Roach echo " 1pt;"; 123*a25f0a04SGreg Roach $bpixX = 1; 124*a25f0a04SGreg Roach } 125*a25f0a04SGreg Roach } 126*a25f0a04SGreg Roach } 127*a25f0a04SGreg Roach // Check the width if set to page wide OR set by xml to larger then page wide 128*a25f0a04SGreg Roach if ($this->width == 0 || $this->width > $renderer->getRemainingWidth()) { 129*a25f0a04SGreg Roach $this->width = $renderer->getRemainingWidth(); 130*a25f0a04SGreg Roach } 131*a25f0a04SGreg Roach // We have to calculate a different width for the padding, counting on both side 132*a25f0a04SGreg Roach $cW = $this->width - ($cP * 2); 133*a25f0a04SGreg Roach 134*a25f0a04SGreg Roach // If there is any text 135*a25f0a04SGreg Roach if (!empty($temptext)) { 136*a25f0a04SGreg Roach // Wrap the text 137*a25f0a04SGreg Roach $temptext = $renderer->textWrap($temptext, $cW); 138*a25f0a04SGreg Roach $tmph = $renderer->getTextCellHeight($temptext); 139*a25f0a04SGreg Roach // Add some cell padding 140*a25f0a04SGreg Roach $this->height += $cP; 141*a25f0a04SGreg Roach if ($tmph > $this->height) { 142*a25f0a04SGreg Roach $this->height = $tmph; 143*a25f0a04SGreg Roach } 144*a25f0a04SGreg Roach } 145*a25f0a04SGreg Roach // Check the last cell height and ajust with the current cell height 146*a25f0a04SGreg Roach if ($renderer->lastCellHeight > $this->height) { 147*a25f0a04SGreg Roach $this->height = $renderer->lastCellHeight; 148*a25f0a04SGreg Roach } 149*a25f0a04SGreg Roach echo " width:", $cW - $bpixX, "pt;height:", $this->height - $bpixY, "pt;"; 150*a25f0a04SGreg Roach 151*a25f0a04SGreg Roach // Text alignment 152*a25f0a04SGreg Roach switch ($this->align) { 153*a25f0a04SGreg Roach case "C": 154*a25f0a04SGreg Roach echo " text-align:center;"; 155*a25f0a04SGreg Roach break; 156*a25f0a04SGreg Roach case "L": 157*a25f0a04SGreg Roach echo " text-align:left;"; 158*a25f0a04SGreg Roach break; 159*a25f0a04SGreg Roach case "R": 160*a25f0a04SGreg Roach echo " text-align:right;"; 161*a25f0a04SGreg Roach break; 162*a25f0a04SGreg Roach } 163*a25f0a04SGreg Roach 164*a25f0a04SGreg Roach // Print the collected HTML code 165*a25f0a04SGreg Roach echo "\">"; 166*a25f0a04SGreg Roach 167*a25f0a04SGreg Roach // Print URL 168*a25f0a04SGreg Roach if (!empty($this->url)) { 169*a25f0a04SGreg Roach echo "<a href=\"", $this->url, "\">"; 170*a25f0a04SGreg Roach } 171*a25f0a04SGreg Roach // Print any text if exists 172*a25f0a04SGreg Roach if (!empty($temptext)) { 173*a25f0a04SGreg Roach $renderer->write($temptext, $this->tcolor, false); 174*a25f0a04SGreg Roach } 175*a25f0a04SGreg Roach if (!empty($this->url)) { 176*a25f0a04SGreg Roach echo "</a>"; 177*a25f0a04SGreg Roach } 178*a25f0a04SGreg Roach // Finish the cell printing and start to clean up 179*a25f0a04SGreg Roach echo "</div>\n"; 180*a25f0a04SGreg Roach // Where to place the next position 181*a25f0a04SGreg Roach // -> Next to this cell in the same line 182*a25f0a04SGreg Roach if ($this->newline == 0) { 183*a25f0a04SGreg Roach $renderer->setXy($this->left + $this->width, $this->top); 184*a25f0a04SGreg Roach $renderer->lastCellHeight = $this->height; 185*a25f0a04SGreg Roach } // -> On a new line at the margin - Default 186*a25f0a04SGreg Roach elseif ($this->newline == 1) { 187*a25f0a04SGreg Roach $renderer->setXy(0, $renderer->getY() + $this->height + ($cP * 2)); 188*a25f0a04SGreg Roach // Reset the last cell height for the next line 189*a25f0a04SGreg Roach $renderer->lastCellHeight = 0; 190*a25f0a04SGreg Roach } // -> On a new line at the end of this cell 191*a25f0a04SGreg Roach elseif ($this->newline == 2) { 192*a25f0a04SGreg Roach $renderer->setXy($renderer->getX() + $this->width, $renderer->getY() + $this->height + ($cP * 2)); 193*a25f0a04SGreg Roach // Reset the last cell height for the next line 194*a25f0a04SGreg Roach $renderer->lastCellHeight = 0; 195*a25f0a04SGreg Roach } 196*a25f0a04SGreg Roach } 197*a25f0a04SGreg Roach} 198