1<?php
2
3namespace GO\Calendar\Reports;
4
5
6/**
7 * Copyright Intermesh
8 *
9 * This file is part of Group-Office. You should have received a copy of the
10 * Group-Office license along with Group-Office. See the file /LICENSE.TXT
11 *
12 * If you have questions write an e-mail to info@intermesh.nl
13 *
14 * @copyright Copyright Intermesh
15 * @version $Id: Day.php 22115 2018-01-12 10:41:26Z mschering $
16 * @author Michael de Hart <mdhart@intermesh.nl>
17 */
18class Day extends Calendar {
19
20	/**
21	 * @var \GO\Calender\Model\Event[]
22	 */
23	protected $events = array();
24	protected $notes = array(); //unused (no notes attache to calendar in groupoffice)
25	public $tasks = array();
26
27	protected $leftCol = 135;
28	protected $rightCol = 60;
29
30	public function Header() {
31		//A4 = 21 x 29.7
32		$this->setXY($this->leftMargin+2,12);
33		$pageWidth = $this->getPageWidth()-$this->leftMargin*2;
34
35		$this->Rect($this->leftMargin, 10, $pageWidth, 30,'DF', array(), $this->greyFill);
36		$this->SetFont(null, 'B',$this->fSizeLarge);
37		$this->Cell(100, 12, date('d. ',$this->day).$this->months_long[date('n',$this->day)].date(' Y',$this->day), 0, 1);
38
39		$this->setX($this->leftMargin+2);
40		$this->SetFont(null, '', $this->fSizeMedium+3);
41		$this->Cell(100, 5, $this->days_long[date('N',$this->day)-1], 0, 1);
42
43		$this->drawCalendar($this->day, 110, 12);
44		$this->drawCalendar($this->day+(32*24*3600), 160, 12);
45
46		$this->setXY(10,41);
47	}
48
49	public function Footer() {
50		$bottom = 238;
51		$width = $this->leftCol-$this->timeCol;
52
53		$this->Rect($this->leftMargin, 41, $this->timeCol, $bottom-(3*$this->rowHeight),'D', $this->thickBorder);
54		$this->Rect($this->leftMargin+$this->timeCol, 41, $width, $bottom-(3*$this->rowHeight),'D', $this->thickBorder);
55		$this->Rect($this->leftMargin, $bottom+$this->headerHeight-(3*$this->rowHeight), $this->leftCol, 3*$this->rowHeight,'D', $this->thickBorder);
56		parent::Footer();
57	}
58
59	public function setEvents($value){
60		$this->events = $this->orderEvents($value);
61	}
62
63	/**
64	 * Renders a page in the PDF with the given day parmeter
65	 * @param integer $day unixtimestamp of day you like to render
66	 */
67	public function render($day) {
68		$this->day = \GO\Base\Util\Date::clear_time($day);
69		$this->currentDay = $this->day;
70		//$this->events = $this->orderEvents($events);
71		$this->AddPage();
72		$this->calculateOverlap();
73
74		$this->drawEventsBackground();
75		$this->drawEvents();
76
77		$this->drawTasks();
78		$this->drawNotes();
79	}
80
81	public function drawEventsBackground() {
82
83		$left = $this->timeCol; // width of cell with time
84		$minus = 2;
85
86		$this->Cell($left, ($this->rowHeight*3)-$minus, '', 1, 0, '', true);
87
88		$x=$this->GetX();
89		$this->Rect($this->GetX(), $this->GetY(),$this->leftCol-$left, $this->rowHeight-$minus, '',$this->thickBorder);
90		$this->SetLineStyle($this->lineStyle);
91
92		$this->SetFont('','B');
93		$this->Cell($this->leftCol-$left, $this->rowHeight-$minus, date('d.',$this->day), 0, 0);
94		$this->SetFont('','');
95		$this->SetX($x);
96		$this->Cell($this->leftCol-$left, $this->rowHeight-$minus, $this->days_long[date('N',$this->day)-1], 0,1,'C');
97		$this->SetX($x);
98		$this->Cell($this->leftCol-$left, $this->rowHeight*2, '', 1, 1);
99
100
101		for($i=0;$i<24;$i++){
102			if($i%2==0) {
103				$hour = ($i/2+7);
104				$this->drawTime($hour);
105
106				//$this->Cell($left, $this->rowHeight * 2, $i < 24 ? str_pad($i/2+7, 2, '0', STR_PAD_LEFT).':00':'', 1, 0);
107			} else
108				$this->setX($this->leftMargin+$this->timeCol);
109			$this->Cell($this->leftCol-$left, $this->rowHeight, '', 1, 1);
110		}
111		$this->Cell($left, $this->rowHeight, '', 1, 0, '', true);
112		$this->Cell($this->leftCol-$left, $this->rowHeight, '', 1, 1);
113		$this->Cell($left, $this->rowHeight, '', 1, 0, '', true);
114		$this->Cell($this->leftCol-$left, $this->rowHeight, '', 1, 1);
115		$this->Cell($left, $this->rowHeight, '', 1, 0, '', true);
116		$this->Cell($this->leftCol-$left, $this->rowHeight, '', 1, 1);
117	}
118
119	protected function drawEvents() {
120
121		$colWidth = $this->leftCol - $this->timeCol;
122		if(isset($this->events[$this->day]['early'])) {
123			$x=$this->headerHeight+6; $i=0;
124			foreach($this->events[$this->day]['early'] as $event) {
125				if($i>1) {
126					$this->Image('modules/calendar/themes/Default/images/pdf/arrow_down.png',$this->leftMargin+$this->leftCol-4, $x+$this->rowHeight*$i-5, 3,3, 'PNG');
127					break;
128				}
129				$this->SetXY($this->leftMargin+$this->timeCol ,$x+$this->rowHeight*$i);
130				$this->Cell($colWidth, $this->rowHeight , date('G:i ', $event->start_time).' - '.date('G:i ', $event->end_time).' '. $event->name, 1, 1, 'L', false);
131				$i++;
132			}
133		}
134		if(isset($this->events[$this->day]['part'])) {
135			$this->SetDrawColorArray($this->eventLineColor);
136			$this->SetLineWidth(0.3);
137			foreach($this->events[$this->day]['part'] as $event) {
138				$this->drawEvent(0, $colWidth, $event);
139			}
140			$this->SetLineWidth(0.1);
141			$this->SetDrawColorArray($this->lineStyle['color']);
142
143		}
144		if(isset($this->events[$this->day]['late'])) {
145
146			$x = $this->headerHeight+214;$i=0;
147			$this->SetXY($this->leftMargin+$this->leftCol-4 ,$x+$this->rowHeight-14);
148			foreach($this->events[$this->day]['late'] as $event) {
149				if($i>2) {
150					$this->Image('modules/calendar/themes/Default/images/pdf/arrow_down.png',$this->leftMargin+$this->leftCol-4, $x+$this->rowHeight*$i-5, 3,3, 'PNG');
151					break;
152				}
153				$this->SetXY($this->leftMargin+$this->timeCol ,$x+$this->rowHeight*$i);
154				$this->EventCell(date('G:i',$event->start_time) .' - '. date('G:i',$event->end_time) .' '. $event->name, $colWidth, $this->rowHeight);
155				//$this->Cell($colWidth, $this->rowHeight , date('G:i ', $event->start_time).' - '.date('G:i ', $event->end_time).' '. $event->name, 1, 1, 'L', false);
156				$i++;
157
158			}
159		}
160	}
161
162	public function drawTasks() {
163		$margin = $this->getMargins();
164		$x = $this->getPageWidth()-$this->rightCol-$this->rMargin; // $this->leftCol+$margin['left']+2;
165		$w= $this->rightCol;
166
167		$this->SetXY($x, $this->headerHeight);
168
169		$this->SetFillColor(240);
170		$this->Cell($w, $this->rowHeight-3, \GO::t("Tasklist", "tasks") .' '. \GO::t("Today"), 1,1,'C', true);
171
172		foreach($this->tasks as $task) {
173			$this->SetX($x);
174			$this->MultiCell($w, $this->rowHeight - 3, $task->name, 1,'L',false,1);
175		}
176
177		$this->Rect($x, $this->headerHeight, $w, 29*$this->rowHeight/2, '',$this->thickBorder);
178		$this->SetLineStyle($this->lineStyle);
179	}
180
181	public function drawNotes() {
182
183		$margin = $this->getMargins();
184		$x = $this->getPageWidth()-$this->rightCol-$this->rMargin;
185		$y = $this->headerHeight+14.5*$this->rowHeight+2;
186		$w= $this->rightCol; //200-$this->leftCol-$margin['left']-2;
187
188		$this->SetXY($x, $y);
189		$this->Cell($w, $this->rowHeight-3, \GO::t("All day", "calendar"), 1,1,'C', true);
190
191		$this->Rect($x, $this->headerHeight+14.5*$this->rowHeight+2, $w, 30*$this->rowHeight/2, '',$this->thickBorder);
192		if(!isset($this->events[$this->day]['fd']))
193			return;
194
195		foreach($this->events[$this->day]['fd'] as $event) {
196			$this->SetX($x);
197			$this->MultiCell($w, $this->rowHeight - 3, $event->name, 1,'L',false,1);
198		}
199
200
201	}
202}
203