'Date', 'width' => 19, 'justify' => 'L'), array('name' => 'Event', 'width' => 110, 'justify' => 'L'), array('name' => 'City', 'width' => 20, 'justify' => 'C'), array('name' => 'Country', 'width' => 25, 'justify' => 'C'), array('name' => 'Conf', 'width' => 10, 'justify' => 'C'), array('name' => 'Exh.', 'width' => 10, 'justify' => 'C')); require('fpdf/fpdf.php'); class CalPDF extends FPDF { var $year; var $colors; function CalPDF($year,$colors=true,$orientation='P',$unit='mm',$format='A4') { //Call parent constructor $this->FPDF($orientation,$unit,$format); //Initialization $this->year = $year; $this->colors = $colors; } function Header() { $this->Image(LOGO, 8.5, 4, 17, 0, LOGO_TYPE, LOGO_LINK); $this->SetFont('Arial','',10); $this->SetY(5.5); $this->Cell(0, 6, 'Infodrom Oldenburg', 0, 2, 'R'); $this->Cell(0, 6, '', 0, 2, 'R'); $this->Cell(0, 6, 'Seite '.$this->PageNo(), 0, 0, 'R'); $this->SetFont('Arial','B',14); $this->SetY(20); $this->Cell(0,0,'Free Software Events Calendar ' . $this->year, 0, 2, 'C'); } function RGBtoInt($rgb) { if (substr($rgb, 0, 1) == '#') $rgb = substr($rgb, 1, 6); return array(hexdec(substr($rgb, 0, 2)), hexdec(substr($rgb, 2, 2)), hexdec(substr($rgb, 4, 2))); } function SetFillCol($rgb) { if ($this->colors === false) return; $val = $this->RGBtoInt($rgb); $this->SetFillColor($val[0], $val[1], $val[2]); } function SetTextCol($rgb) { if ($this->colors === false) return; $val = $this->RGBtoInt($rgb); $this->SetTextColor($val[0], $val[1], $val[2]); } function Ending() { $this->Ln(); $this->SetFont('Arial','',10); $this->SetTextCol('000000'); $this->Write(4.5, 'Infodrom Oldenburg'); $this->Ln(); $this->SetTextCol('0000ff'); $this->Write(4.5, 'http://www.infodrom.org/', 'http://www.infodrom.org/'); $this->Ln(); $this->SetTextCol('000000'); $this->Write(4.5, 'Free Software Calendar'); $this->Ln(); $this->SetTextCol('0000ff'); $this->Write(4.5, 'http://www.infodrom.org/Linux/calendar.html', 'http://www.infodrom.org/Linux/calendar.html'); } } function gather_events($year) { global $dbh; $result = array(); $dbh = pg_pconnect ("", "", "web") or die("Unable to connect to SQL server"); pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!"); $event_cols = "name,start,start+delta AS end,city,country,conference,exhibition,url"; $query = sprintf("SELECT %s FROM events WHERE cancelled=0 " . "AND start >= '%04d-01-01' and start < '%04d-01-01' " . "ORDER BY start,name", $event_cols, $year, $year+1); $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!"); for ($i=0; $i < pg_NumRows ($sth); $i++) { $row = pg_fetch_array ($sth, $i); $date = explode (" ", $row['start']); $date = explode ("-", $date[0]); $end = explode (" ", $row[2]); $end = explode ("-", $end[0]); $date = str_replace(' ', ' ', format_date ($date, $end)); $event = array($date, $row['name'], $row['city'], $row['country'], $row['conference']==1?"x":"", $row['exhibition']==1?"x":""); $result[] = $event; } return $result; } function caltable_head($pdf, $columns) { $pdf->SetY(30); $pdf->SetX(10); $pdf->SetFont('Arial','B',10); $pdf->SetFillCol('1AA2FE'); $pdf->SetTextCol('ffffff'); foreach ($columns as $col) { $pdf->Cell($col['width'], 6, $col['name'], 1, 0, 'C', true); } $pdf->Ln(); } function caltable_data($pdf, $columns, $rows, $chunk) { $pdf->SetFont('Arial','',8); $pdf->SetFillCol('d7d7d7'); $pdf->SetTextCol('000000'); $fill = false; $nr = 0; $offset = $chunk * EVENTS_PER_PAGE; $maxnr = min(count($rows), $offset + EVENTS_PER_PAGE); for ($nr=$offset; $nr < $maxnr; $nr++) { $row = $rows[$nr]; for ($i=0; $i < count($columns); $i++) { $frame = 'LR'; if ($nr == $maxnr-1) $frame .= 'B'; $pdf->Cell($columns[$i]['width'], 4.5, $row[$i], $frame, 0, $columns[$i]['justify'], $fill); } $pdf->Ln(); $fill=!$fill; } } function calendar_pdf($year) { global $columns; $pdf = new CalPDF($year, true); $pdf->AliasNbPages(); $pdf->SetTitle('Free Software Events Calendar'); $pdf->SetAuthor('Joey Schulze '); $pdf->SetCreator('Infodrom Oldenburg '); $pdf->SetAutoPageBreak(false); $pdf->SetFillColor(255,255,255); # $pdf->SetAutoPageBreak(true, 10); $rows = gather_events($year); for ($chunk=0; $chunk < ceil(count($rows)/EVENTS_PER_PAGE); $chunk++) { $pdf->AddPage(); caltable_head($pdf, $columns); caltable_data($pdf, $columns, $rows, $chunk); } if ($chunk > 0) $chunk--; $offset = $chunk * EVENTS_PER_PAGE; $maxnr = min(count($rows), $offset + EVENTS_PER_PAGE); if (EVENTS_PER_PAGE - ($maxnr-$offset) >= 5) $pdf->Ending(); $pdf->Output('events-' . $year . '.pdf', 'I'); } ?>