my_header_msg = $msg; $my_url = $url; return; } if( $this->my_header_msg == NULL ) return; if( $this->msg_page_nr > 0 ) { $font_fam = $this->FontFamily; $font_style = $this->FontStyle.($this->underline ? 'U' : '').($this->linethrough ? 'D' : ''); $font_size = $this->getFontSize(); $this->SetFont($this->font,'', F_SIZE-1); $this->setXY($this->lMargin, MARGIN-3); $this->Cell($this->colwidth, 3,$this->my_header_msg, 0, 0, 'R'); if( !empty($font_fam ) ) $this->SetFont($font_fam,$font_style,$font_size); if( $my_url != NULL AND $my_url != '' ) $this->myLink($this->lMargin+$this->colwidth/2,$this->lMargin-4,$this->colwidth,(F_SIZE+5)/2.9,$my_url); } $this->setXY($this->lMargin, MARGIN+3); $this->y0 = $this->getY(); } // undefine default header and footer handling // default routines do not handle columns function Footer() { } function Header() { } function Mark( $title = '', $string = '' ) { return 1+substr_count($string,'.'); } public function myFooter( $msg = NULL, $url = NULL ) { static $my_url = NULL; if( $msg != NULL ) { $this->my_footer_msg = $msg; $this->msg_page_nr = 0; $my_url = $url; return; } if( $this->my_footer_msg == NULL ) return; $this->InFooter = true; $this->msg_page_nr++; $font_fam = $this->FontFamily; $font_style = $this->FontStyle.($this->underline ? 'U' : '').($this->linethrough ? 'D' : ''); $font_size = $this->getFontSize(); $this->SetFont($this->font,'', F_SIZE-1); if( $this->msg_page_nr > 1 ) { $this->SetXY($this->lMargin, $this->GetPageHeight()/$this->scale*100.0-MARGIN/2-2); $this->Cell($this->colwidth, 3, sprintf("%s %d", $this->unhtmlentities( _("page") ), $this->msg_page_nr), 0, 0, 'C'); } if( $this->my_footer_msg != '' ) { $strg = '© '. date('Y'). ' CAcert Inc.'.', '. $this->my_footer_msg; $this->SetXY($this->lMargin+MARGIN/2, $this->GetPageHeight()/$this->scale*100-MARGIN/2-2); $this->Cell($this->colwidth, 3, $strg, 0, 0, 'R'); if( $my_url != NULL AND $my_url != '' ) $this->myLink($this->lMargin+MARGIN/2,$this->GetPageHeight()/$this->scale*100.0-MARGIN/2-2,$this->colwidth,(F_SIZE+5)/2.9,$my_url); } if( $this->Watermark != '' ) { $this->StartTransform(); $savex = $this->GetX(); $savey = $this->GetY(); $this->SetFont($this->font,'', F_SIZE*7); $l = $this->GetStringWidth($this->Watermark); $h = $this->GetPageHeight()/$this->scale*100.0/2; $w = $this->colwidth/2+MARGIN*2; $this->SetXY(0,0); $this->TranslateY($h+(F_SIZE*7)/2.9-MARGIN*3); $this->TranslateX($w+$this->lMargin); $this->Rotate(rad2deg(atan($h/$w))); $this->Text(-$l/2,0,$this->Watermark, 0.8); $this->StopTransform(); $this->SetXY($savex,$savey); } if( !empty($font_fam ) ) $this->SetFont($font_fam,$font_style,$font_size); $this->InFooter = false; } // user and print preferences // NumCopies, PrintPageRange, DisplayDocTitle, HideMenuBar, HideToolBar, ... public $ViewerPrefs = array( 'Duplex' => 'Duplex', 'NumCopies'=> '1', 'DisplayDocTitle' => 'CAcert document', 'HideToolBar' => true, 'FitWindow' => true, ); // font used here protected $font = "freesans"; //number of colums protected $ncols=1; // columns width protected $colwidth=0; // space between columns protected $column_space = 0; //Current column protected $col=0; //Ordinate of column start protected $y0; // scaling factor protected $scale = 100.0; // print header and footer protected $my_footer_msg = NULL; protected $my_header_msg = NULL; protected $msg_page_nr = 0; // print short watermark on the page public $Watermark = WATERMARK; public function SetFormat( $format = 'a5' ) { switch( strtolower($format) ) { // there is some scale problems with margins... case 'a1': case 'b1': $this->scale *= 1.4142; case 'a2': case 'b2': $this->scale *= 1.4142; case 'a3': case 'b3': $this->scale *= 1.4142; break; case 'a5': case 'b5': $this->scale /= 1.4142; break; case 'letter': $this->scale *= 0.97; break; default: $format = 'a4'; case 'a4': case 'b4': case 'folio': case 'legal': break; } $this->SetDisplayMode(intval($this->scale), 'SinglePage', 'UseOC'); return( $format ); } //Set position at a given column private function SetCol($col = -1) { static $pagecolwidth = 1.0; static $column_space = 1.0; if( $col == -1 ) $col = $this->col+1; if( $this->colwidth == 0 ) { // only once at start; set default values //set margins $this->addPage(); $col = 0; // reset to zero $this->SetMargins(MARGIN, MARGIN, MARGIN); if( $this->CurOrientation != 'L' ) { $this->scale *= 1.4142; $this->ScaleXY($this->scale,0,0); } else { $this->scale *= 1.0; $this->ScaleXY($this->scale,0,0); } $this->ncols = $this->CurOrientation == 'L'? MAX_COLS : 1; $this->colwidth = $this->w / $this->scale * 100 / $this->ncols - MARGIN*2; $pagecolwidth = $this->w/$this->ncols; // space between columns if ($this->ncols > 1) { $column_space = round((float)($this->w - ($this->ncols * $pagecolwidth)) / ($this->ncols - 1)); } else { $column_space = 0; } $this->y0 = $this->GetY(); } else { if( $col == $this->col ) { // reset on close of this column $x = MARGIN + $this->col*($pagecolwidth+$column_space); $this->SetLeftMargin($x); //$this->SetRightMargin($this->w - $x - $this->colwidth); } $this->PrintTable('', -1); // if pending table close up table $this->myFooter(); // print footer msg if defined } if( $col >= $this->ncols ) { $this->addPage(); $col = 0; $this->ScaleXY($this->scale,0,0); $this->y0 = 0; //no header/footer done... } elseif ( $col > 0 AND $col < $this->ncols) { // print column separator $x = $this->w/$this->ncols*($this->col+1); $y = $this->tMargin; $this->SetLineWidth(0.1); $this->SetDrawColor(195); $this->SetLineStyle(array('dash'=>'1,8') ); // gray dotted $this->Line( $x, $y+27, $x, $y+185); $this->SetLineWidth(0.2); $this->SetDrawColor(0); $this->SetLineStyle(array('dash'=>'0') ); } $this->col = $col; // X position of the current column $x = MARGIN + $col*($pagecolwidth+$column_space); $this->SetLeftMargin($x); $this->SetRightMargin($this->w - $x - $this->colwidth); $this->SetXY($x, $this->y0); $this->myHeader(); //print header msg if defined $this->PrintTable('', 0); // if in table reprint title table $this->InFooter = false; } //Method accepting or not automatic page break public function AcceptPageBreak() { $this->SetCol(); return false; } // redefine this routine from tcpdf.php due to scaling bug protected function checkPageBreak($h) { if (((($this->y + $h)*$this->scale/100.0) > $this->PageBreakTrigger) ) { if ( !$this->InFooter ) { if ( ($this->AcceptPageBreak())) { $rs = ''; //Automatic page break $x = $this->x; $ws = $this->ws; if ($ws > 0) { $this->ws = 0; $rs .= '0 Tw'; } $this->AddPage($this->CurOrientation); if ($ws > 0) { $this->ws = $ws; $rs .= sprintf('%.3f Tw', $ws * $k); } $this->_out($rs); $this->y = $this->tMargin; $this->x = $x; } } } } public function myLine( $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0 ) { if ( BW ) { $this->SetDrawColor(195); } else { $this->SetDrawColor(173,197,215); } $this->SetLineWidth(0.1); // small line in points collumn $this->Line($x1, $y1, $x2, $y2 ); $this->SetLineWidth(0.2); $this->SetDrawColor(0); } public function S( $value = 1.0 ) { return( $value * $this->scale / 100.0 ); } // put Link in user space public function myLink( $x, $y, $w, $h, $Lnk = NULL, $Type = array('SubType'=>'Link') ) { if( $Lnk == NULL ) return; if( $Lnk == '' ) $Lnk = WEB.'/'; $this->Annotation( $x, $y, $w, $h, $Lnk, $Type); } // set formfield coordinates // this routine is needed due to field ordinates are not scaled and in user space // to be called before form field call (or as width parameter) // and just after with true argument to restore X Y ordinates. public function SetFieldXY( $x=NULL, $y=NULL, $w=0) { static $savex; static $savey; static $restored = true; $restoreXY = $x == NULL ? true : false; if( $restored == $restoreXY ) $this->Error("internal Form Field save/restore error\n"); if( !$restoreXY ) { /* save X Y ordinates */ $savex = $this->GetX(); $savey = $this->GetY(); // scale to user ordinates $this->SetY( $this->S($y)); $this->SetX( $this->S($x)); } else { /* restore X Y ordinates */ $this->SetY( $savey); // different from SetXY() $this->SetX( $savex); // different from SetXY() } $restored = $restoreXY; return( $this->S($w) ); } // print Date on left or right side public function PrintDate( $x=10, $y=10, $dstrg='teus', $dvalue='1945-10-6', $field = NULL , $RL = 'L') { static $TextProps = array('strokeColor' => LLBLUE, 'value' => '', 'fillColor' => LBLUE , 'textSize' => '11', 'charLimit'=> 10); // next statements can cause php to go into an infinite loop if( $dstrg != NULL AND $dstrg == '') $TextProps['userName'] = $this->unhtmlentities( _("On mutual assurance provide Assurer date of birth") ) . '(' . $this->unhtmlentities( _("yyyy-mm-dd") ) . ')'; else // end of problem with infinite loop $TextProps['userName'] = $this->unhtmlentities( _("yyyy-mm-dd") ); $this->SetFont( $this->font, '', F_SIZE); $this->SetXY($RL == 'L'? $x : $x-50, $y); $this->Cell(50, 3, $dstrg, 0, 0, $RL); if($dvalue) { $this->SetXY($RL == 'L'? $x :$x-50, $y+3.5); $this->SetFont($this->font, 'B', F_SIZE); $this->Cell(50, 3, $dvalue, 0 , 0, $RL); } if( $field == NULL ) return; $TextProps['value'] = $dvalue; $this->TextField($field, $this->SetFieldXY(($RL == 'L'? $x+1 : $x-17), ($y+3.5),17), 5, $TextProps ); $this->SetFieldXY(); } // Add import HTML text eg from CCA private function PrintHTML( $url = NULL ) { if( $url == NULL OR $url == '' ) return; $error = ''; $title = ''; //if( ! file_exists($url) ) $url = WEB.'/'.$url; $data = file_get_contents($url); if( !$data ) $error = "\nInternal Error: no ".$url.' found.'; else { $regs = array(); preg_match('/<[Tt][Ii][Tt][Ll][Ee][^>]*>/', $data, $regs); if( count($regs) < 1 ) $error .= "\nInternal Error: no open tag title found on $url."; else { $start = strpos($data, $regs[0]) + strlen($regs[0]); $data = substr($data, $start); } $regs = array(); preg_match('/<\/[Tt][Ii][Tt][Ll][Ee][^>]*>/', $data, $regs); if( count($regs) < 1 ) $error .= "\nInternal Error: no close title tag found on $url."; else { $end = strpos($data, $regs[0]); $title = trim(substr($data,0,$end)); $data = substr($data, $end+strlen($regs[0])); } $regs = array(); preg_match('/<[Bb][oO][Dd][yY][^>]*>/', $data, $regs); if( count($regs) < 1 ) $error .= "\nInternal Error: no open html body tag found on $url."; else { $start = strpos($data, $regs[0]) + strlen($regs[0]); $data = substr($data, $start); } $regs = array(); preg_match('/<\/[Bb][oO][Dd][yY][^>]*>/', $data, $regs); if( count($regs) < 1 ) $error .= "\nInternal Error: no closing html body tag found on $url."; else { $end = strpos($data, $regs[0])-1; $data = substr($data, 1, $end); } } if( !$title ) $title = $url; $this->SetCol(); $this->setFont($this->font, F_SIZE); if( !$error ) { $this->PrintHeader($this->unhtmlentities( _($title) ), $this->unhtmlentities( _("policy document") ), strncmp($url,WEB,strlen(WEB))==0? $url : (WEB.'/'.$url)); if( $title ) $this->Bookmark($title,0); $this->writeHTMLCell($this->colwidth,2.5,$this->lMargin+1,$this->GetY()+2.5, $data, 0,2,0,'L'); } else $this->MultiCell($this->colwidth, 3, $error); } private function PrintCP($applicant = NULL, $assurer = NULL, $assurance = NULL, $registry = NULL){ if( $assurance != NULL ) $this->ViewerPrefs['NumCopies'] = 2; $this->SetCol(); if( $assurance != NULL ) $this->PrintHeader($this->unhtmlentities( _("CAcert Assurance Programme") ), $this->unhtmlentities( _("Identity Verification Form (CAP) form") ), defined('ASSCAP')?ASSCAP:'',defined('WEB')? WEB.substr(__FILE__, strrpos(__FILE__,'/')) : ''); if( $registry != NULL ) $this->PrintHeader($this->unhtmlentities( _("CAcert Organisation Assurance Programme"), $this->unhtmlentities( _("Organisation Information (COAP) form") ), defined('ASSCOAP')?ASSCOAP:"",defined('WEB')? WEB.substr(__FILE__, strrpos(__FILE__,'/')) : '') ); // define slighly different footer message $this->myFooter("V". substr($this->Version(), 0, strpos($this->Version(), '.')).", ". $this->unhtmlentities( _("generated")." ".date("Y-n-j") )); $this->AssuranceInfo($assurance); if( $assurance != NULL ) { $this->InfoAssuree($applicant, $assurer, $assurance); $this->StatementAssuree( $applicant['date']); } // else if( $registry != NULL ) { $this->InfoOrganisation($applicant, $registry); $this->StatementOrganisation($applicant); } $this->StatementAssurer( $assurer, $assurance ); } //Add form and/or CCA (on duplex only when more as one page is printed) public function PrintForm( $applicant = NULL, $assurer = NULL, $assurance = NULL, $registry = NULL, $page = NULL ) { // make sure we use the same font as the html form if( defined('FONT') ) $this->font = ereg_replace('-','',ereg_replace(',.*', '', FONT)); //!!! not present in tcpdf package! if( $this->font == 'SJIS' AND function_exists('AddSJISFont')) $this->AddSJISFont(); for($cnt=0 ; $cnt < $this->ncols; $cnt++ ) { if( !isset( $page['form']) OR $page['form'] ) { // the form is one page, use new room? if ( $applicant == NULL OR $assurer == NULL OR ($assurance == NULL AND $registry == NULL) ) $this->Error("Organisation or Assurer data records failure"); $this->PrintCP( $applicant, $assurer, $assurance, $registry); } // print off policy documents to be included in pdf file foreach( $page['policies'] as $i => $file ) { $this->Watermark = WATERMARK; // no watermark on these pages if( $file[0] AND $file[1] ) $this->PrintHTML( $file[0] ); } if( $this->col > 0 OR $this->getPage() > 1 ) break; } if( $this->getPage() > 1 ) { // and on duplex print back side with Community Agreement if( $this->CurOrientation == 'P' ) $this->ViewerPrefs['Duplex'] = 'DuplexFlipLongEdge'; else $this->ViewerPrefs['Duplex'] = 'DuplexFlipShortEdge'; } // close up this column, make sure footer is printed. $this->my_header_msg = NULL; $this->SetCol($this->col); } // Set form title (right align) public function PrintHeader($title1 = ' ', $title2 = ' ' , $url1 = NULL, $url2 = NULL) { // store current top margin value $tSide = $this->tMargin; if( $title1 != '' AND $title1 != ' ') $this->ViewerPrefs['DisplayDocTile'] = $title1; if( $title2 != '' AND $title2 != ' ') $this->ViewerPrefs['DisplayDocTile'] .= ' ('.$title2.')'; // CAcert logo // eps should be better, but it does not seem to work with CAcert logo $this->rMargin -= 1; $this->myFooter($title1,$url1); $this->myHeader($title2,$url2); if( LOGO_TYPE == '.eps' ) $this->ImageEPS(BW?LOGO.'mono'.LOGO_TYPE:LOGO.'colour'.LOGO_TYPE, ($this->lMargin+$this->colwidth)-51,$tSide-3,51); else // png image 1000 X 229 * 8 bits $this->Image(BW?LOGO.'mono'.LOGO_TYPE:LOGO.'colour'.LOGO_TYPE, ($this->lMargin+$this->colwidth)-51,$tSide-3,51,0,0, NULL,0,true,intval(LOGO_DPI)); $this->myLink($this->lMargin+$this->colwidth-51, $tSide-3,51,51/1000*229,WEB. '/'); // form type $this->SetFont($this->font,'B',F_SIZE+5); $this->SetY($tSide+5); $this->SetX($this->lMargin); $l = $this->GetStringWidth($title1); $this->Cell($this->colwidth+1,14,$title1,0,0,'R',0,NULL); if( $url1 != NULL AND $url1 != '' ) $this->myLink($this->lMargin+$this->colwidth-$l,$this->GetY()+5,$l,(F_SIZE+5)/2.9,$url1); $this->Ln(5); $this->SetX($this->lMargin); $l = $this->GetStringWidth($title2); $this->Cell($this->colwidth+1,14,$title2,0,0,'R',0,NULL); if( $url2 != NULL AND $url2 != '' ) $this->myLink($this->lMargin+$this->colwidth-$l,$this->GetY()+5,$l,(F_SIZE+5)/2.9,$url2); // CAcert Inc. postbox address $this->Ln(6); $this->SetX($this->lMargin); $this->SetFont($this->font,'',F_SIZE); $savex = $this->GetX(); $savey = $this->GetY(); $strg = POBOX .' - '. WEB; $this->SetXY($this->lMargin+$this->colwidth-$this->GetStringWidth($strg)-1.1,$this->GetY()+3.5); // right align if( !BW ) $this->SetTextColor(17,86,140); $ret = $this->Write(0, $strg, NULL); $l = $this->GetStringWidth($strg); $this->myLink($this->lMargin+$this->colwidth-$l,$this->GetY()+0.5,$l,F_SIZE/2.9,WEB.'/'); $this->Ln(); if( !BW ) $this->SetTextColor(0); $this->SetXY($savex,$savey); // sha1 fingerprint CAcert rootkeys class 1 and class 3 $strg = $this->unhtmlentities( _("CAcert's Root Certificate") ) . ', class 1: '. CLASS1_SHA1 . ', class 3: ' . CLASS3_SHA1; $this->Ln(3); $this->SetX($this->lMargin); $this->SetFont($this->font,'',F_SIZE * $this->colwidth / ($this->GetStringWidth($strg) +1)); $this->Cell($this->colwidth,10, $strg,0,0,'C',0,NULL); $this->myLink($this->lMargin, $this->GetY()+4,$this->colwidth,F_SIZE/2.9,ROOTKEYS); $this->SetLineWidth(0.1); if ( BW ) { $this->SetDrawColor(195); } else { $this->SetDrawColor(17,86,140); } $this->Line($this->lMargin, $tSide+25, $this->lMargin+$this->colwidth, $tSide+25); $this->SetLineWidth(0.2); $this->SetDrawColor(0); $this->rMargin += 1; $this->SetXY($this->lMargin, $tSide+26); // top } // Set general form information public function PrintInfo( $strg = '', $url = '') { // store current margin values // Print text blurb paragraph at top of page $this->SetFont($this->font,'',F_SIZE+0.5); $this->SetXY($this->lMargin, $this->GetY()-1.5); $y = $this->GetY(); $x = $this->GetX(); $cnt=$this->MultiCell($this->colwidth+1, 0, $strg,0,'L',0,2); if ( $url != '' ) // link should be in user space $this->myLink($x, $y, $this->colwidth, $this->GetY()-$y, $url); return($cnt); } // print empty table with title for statements (called twice per table) public function PrintTable( $strg = NULL, $height = -1, $ext = 0 ) { // store current margin values static $tSide = -1; static $title = ''; if( $height < 0 ) { // mark table position, leave room for title if( $strg != '' ) $title = $strg; if( $title == '' ) return ($this->GetY()); // nothing to do $tSide = $this->GetY()+1; // background if ( BW ) { $this->SetFillColor(195); $this->SetDrawColor(195); } else { $this->SetFillColor(173,197,215); $this->SetDrawColor(173,197,215); } $this->Rect($this->lMargin-1,$tSide-1,1,9, 'F'); $this->Rect($this->lMargin-1,$tSide-1,$this->colwidth,1, 'F'); $this->SetFillColor(255); if ( BW ) { $this->SetFillColor(125); } else { $this->SetFillColor(17,86,140); } $this->Rect($this->lMargin,$tSide,$this->colwidth,7, 'DF'); $this->SetFillColor(255); $this->SetDrawColor(0); $this->SetXY($this->lMargin+1, $tSide+0.6); $this->Bookmark($title,1,$this->S($tSide)); $this->SetFont($this->font, '', F_SIZE+7); $this->SetTextColor(255); $this->Write(0, $title); $this->SetTextColor(0); $this->SetXY($this->lMargin+1, $tSide + 7); $tSide += 8; // save old top if ( $height != 0 ) return($this->GetY()); } elseif( $tSide < 0 ) return( $this->GetY()); if( $height == 0 ) { // interrupted bottum of column reached $height = $this-GetY() - $tSide; $save = $title; $this->PrintTable('', $height); // finish till bottumn page $tSide = $this->originalMargin; $title = $save; return( $this->GetY()); } if( $strg != '' ) $title = $strg; // just to be defensive // background if ( BW ) { $this->SetFillColor(195); $this->SetDrawColor(195); } else { $this->SetFillColor(173,197,215); $this->SetDrawColor(173,197,215); } $this->Rect($this->lMargin-1,$tSide,1,$height-1+$ext, 'F'); if( $ext ) $this->Rect($this->lMargin-1,$tSide+$height,$this->colwidth,$ext, 'F'); $this->SetFillColor(255); // borders of the table left, bottumn, right $this->Line($this->lMargin,$tSide+$height-1, $this->lMargin, $tSide+$height); $this->Line($this->lMargin,$tSide+$height,$this->lMargin+$this->colwidth,$tSide+$height); $this->Line($this->lMargin+$this->colwidth,$tSide-1, $this->lMargin+$this->colwidth, $tSide+$height); $this->SetDrawColor(0); $this->SetY($tSide + $height + 1); // set Y ordinate to plus 7 $tSide = -1; $title = ''; return($this->GetY()); } } // END of shared functions between cap/coap pdf generator ?>