--- /dev/null
+<?
+ # PDF generation
+
+ 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, 0, 'R');
+
+ $this->SetFont('Arial','B',14);
+ $this->SetY(20);
+ $this->Cell(0,0,'Free Software Events Calendar ' . $this->year, 0, 2, 'C');
+ }
+
+ function Footer()
+ {
+ //Position at 1.5 cm from bottom
+ $this->SetY(-15);
+ //Arial italic 8
+ $this->SetFont('Arial','',8);
+ //Page number
+ $this->Cell(0,10,$this->PageNo().'/{nb}',0,'T','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;
+
+ error_log('SetFillColor('.$rgb.')');
+ $val = $this->RGBtoInt($rgb);
+ $this->SetFillColor($val[0], $val[1], $val[2]);
+ }
+
+ function SetTextCol($rgb)
+ {
+ if ($this->colors === false)
+ return;
+
+ error_log('SetTextColor('.$rgb.')');
+ $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)
+ {
+ require('fpdf/fpdf.php');
+
+ $pdf = new CalPDF($year, true);
+ $pdf->AliasNbPages();
+ $pdf->SetTitle('Free Software Events Calendar');
+ $pdf->SetAuthor('Joey Schulze <joey@infodrom.org>');
+ $pdf->SetCreator('Infodrom Oldenburg <http://www.infodrom.org/>');
+ $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);
+ }
+
+ $pdf->Ending();
+ $pdf->Output();
+ }
+?>