Skip to content

Commit

Permalink
Update mkCal.php
Browse files Browse the repository at this point in the history
  • Loading branch information
goerdy authored Sep 17, 2023
1 parent b102511 commit af938fa
Showing 1 changed file with 128 additions and 86 deletions.
214 changes: 128 additions & 86 deletions mkCal.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,100 +5,142 @@ class PDF extends FPDF
{

// makeCalendar
function mkCal($title, $Year, $locale, $daysText, $daysColor, $daysHollidays, $highlightHollidays, $highlightSunday, $ighlightSaturday, $footer, $format)
{
/*
$title = String that contains the Header-text of the Calendar
$locale = locale setting for Month and Day names (e.g. de_DE)
$daysText = 2-dimensional string array [month][day] for text in cell
$daysColor = 2-dimensional string array [month][day] for bgcolor of cell (HEX)
$daysHollidays = 2-dimensional bool array [month][day] true=day is holliday
$highlightHollidays = Hex key of highlightcolor of Hollidays
$highlightSunday = Hex key of highlightcolor of Sundays
$highlightSaturday = Hex key of highlightcolor of Saturdays
$footer = String with footer text
$format = currently only "A4Landscape"
*/

//setlocale for correct display of month and days
setlocale(LC_TIME, $locale);

//initialize PDF
$this->SetMargins(12,5,5);
$this->SetAutoPageBreak(true,5);
$this->SetFont('Arial','',12);
$this->AddPage();



//title
$this->Cell(200,10,iconv('UTF-8', 'windows-1252', $title),0);
$this->Ln();

// Colors, line width and bold font
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
// Header
$w = 22; //Cell Width
$this->Cell(8,7,' ',1,0,'C',true);
for($i=1;$i<=12;$i++)
$this->Cell($w,7,$date = strftime('%B',strtotime($i."/01/1970")) ,1,0,'C',true);
$this->Ln();
// Color and font restoration
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = false;

for($i=1;$i<=31;$i++)
function mkCal($title, $Year, $locale, $daysText, $daysColor, $daysHollidays, $highlightHollidays, $highlightSunday, $highlightSaturday, $footer, $format, $colorSceme)
{
for($j=0;$j<13;$j++)
{
if($j==0)
{
$this->Cell(8,5.2,$i,'LRB',0,'L',$fill);
}
else
{
if($data[$j][$i]==3)
{
$fill=true;
}

//check if sunday and draw border
$wday= date('w', strtotime('2024'.$j.$l));
if($wday==0)
/*
$title = String that contains the Header-text of the Calendar
$locale = locale setting for Month and Day names (e.g. de_DE)
$daysText = 2-dimensional string array [month][day] for text in cell
$daysColor = 2-dimensional string array [month][day] for bgcolor of cell (HEX)
$daysHollidays = 2-dimensional bool array [month][day] true=day is holliday
$highlightHollidays = Hex key of highlightcolor of Hollidays
$highlightSunday = Hex key of highlightcolor of Sundays
$highlightSaturday = Hex key of highlightcolor of Saturdays
$footer = String with footer text
$format = currently only "A4Landscape"
$ColorSceme = Color for Title and Month Background
*/

//setlocale for correct display of month and days
setlocale(LC_TIME, $locale);

//initialize PDF
// $this = new PDF('L','mm','A4');
$this->SetMargins(12,5,5);
$this->SetAutoPageBreak(true,5);
$this->SetFont('Arial','',10);
$this->AddPage();



//title
$this->SetFont('','B');
$this->SetFont('Arial','',22);
list($r, $g, $b) = sscanf($colorSceme, "#%02x%02x%02x");
$this->SetTextColor($r,$g,$b);
$this->Cell(250,10,iconv('UTF-8', 'windows-1252', $title),0);
$this->Cell(30,10,$Year,0);
$this->Ln();

// Colors, line width and bold font
list($r, $g, $b) = sscanf($colorSceme, "#%02x%02x%02x");
$this->SetFillColor($r,$g,$b);
$this->SetTextColor(255);
$this->SetDrawColor(0,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
$this->SetFont('Arial','',12);
// Header
$w = 16; //Cell Width
$wWeekDay = 6; //Cell Width
$this->Cell(8,7,' ',1,0,'C',true);
for($i=1;$i<=12;$i++)
$this->Cell($w+$wWeekDay,7,$date = strftime('%B',strtotime($i."/01/1970")) ,1,0,'C',true);
$this->Ln();
// Color and font restoration
//$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('Arial','',14);
// Data
$fill = false;

for($i=1;$i<=31;$i++)
{
$this->SetDrawColor(138,0,138);
$fill = true;
for($j=0;$j<13;$j++)
{
if($j==0)
{
$this->SetFont('Arial','',14);
$this->SetDrawColor(0,0,0);
$this->Cell(8,5.2,$i,'LRB',0,'L',false);
}
else
{
// Weekday
$this->SetFont('Arial','',6);
//check if sunday/saturday/ and set fill color
$wday= date('w', strtotime($i.'-'.$j.'-'.$Year));
if($wday==0)
{
list($r, $g, $b) = sscanf($highlightSunday, "#%02x%02x%02x");
$this->SetFillColor($r,$g,$b);
$fill = true;
}
else if($wday==6)
{
list($r, $g, $b) = sscanf($highlightSaturday, "#%02x%02x%02x");
$this->SetFillColor($r,$g,$b);
$fill = true;
}
else
{
$this->SetFillColor(0,0,0);
$fill = false;
}
if(checkdate($j,$i,$Year))
{
$this->Cell($wWeekDay,5.2,strftime('%a', strtotime($i.'-'.$j.'-'.$Year)),1,0,'L',$fill);
}
else
{
$this->Cell($wWeekDay,5.2,' ',1,0,'L',false);
}
$this->SetFont('Arial','',12);

// Cell Background depending on DayColorArray
list($r, $g, $b) = sscanf($daysColor[$j][$i], "#%02x%02x%02x");
$this->SetFillColor($r,$g,$b);
if($r!=0||$g!=0||$b!=0)
{
$fill=true;
}
else
{
$fill=false;
}
// End of Background Color

$this->Cell($w,5.2,$daysText[$j][$i],1,0,'L',$fill);
//$this->SetFillColor(0,0,0);
//$this->SetDrawColor(0,0,0);
}
}


$this->Ln();
}

$this->Cell($w,5.2,$daysText[$j][$i],'LRB',0,'L',$fill);
$fill=false;
$this->SetDrawColor(0,0,0);
}
}


$this->Ln();
}
$this->SetFont('Arial','',14);
$this->Cell(400,10,$footer,0);
$this->Ln();
$this->Cell(400,10,"This Calendar was made using PrintablePDFYearCalendar by @goerdy - github.com/goerdy/PrintablePDFYearCalendar",0);


$this->SetFont('Arial','',10);
$this->Cell(400,10,iconv('UTF-8', 'windows-1252',"This Calendar was made using PrintablePDFYearCalendar by Philipp Gürth - github.com/goerdy/PrintablePDFYearCalendar"),0);
$fill = !$fill;

//finalize pdf and output
$this->Output();
}




//finalize pdf and output
$this->Output();
}
}

?>

0 comments on commit af938fa

Please sign in to comment.