source: branches/2.2.0.1/calendar/js/dhtmlx/server/pdfWrapper.php @ 4049

Revision 4049, 32.2 KB checked in by brunocosta, 13 years ago (diff)

Ticket #1745 - Nova visão semanal e mensal da agenda.

Line 
1<?php
2/*
3Copyright DHTMLX LTD. http://www.dhtmlx.com
4*/
5
6
7require_once 'tcpdf_ext.php';
8
9class pdfWrapper {
10        private $cb;
11        private $footenotes;
12        private $colWidth = 50; // column width in month mode for footenotes
13        private $colOffset = 5;  // spaces between columns in month mode for footenotes
14
15        public function pdfWrapper($offsetTop, $offsetRight, $offsetBottom, $offsetLeft, $orientation) {
16                $this->cb = new TCPDFExt($orientation, 'mm', 'A4', true, 'UTF-8', false);
17
18                $this->offsetLeft = $offsetLeft;
19                $this->offsetRight = $offsetRight;
20                $this->offsetTop = $offsetTop;
21                $this->offsetBottom = $offsetBottom;
22
23                // sets header and footer
24                $this->cb->setPrintHeader(false);
25                $this->cb->setPrintFooter(false);
26                $this->cb->SetMargins($this->offsetLeft, $this->offsetTop, $this->offsetRight);
27                $this->cb->SetAutoPageBreak(FALSE, $this->offsetBottom);
28                $this->cb->SetFooterMargin($this->offsetBottom);
29
30                // sets output PDF information
31                $this->cb->SetCreator('DHTMLX LTD');
32                $this->cb->SetAuthor('DHTMLX LTD');
33                $this->cb->SetTitle('dhtmlxScheduler');
34                $this->cb->SetSubject('DHTMLX LTD');
35                $this->cb->SetKeywords('');
36
37                // sets font family and size
38                $this->cb->SetFont('freesans', '', 8);
39        }
40
41
42        // draws scheduler header in month mode
43        public function drawMonthHeader($orientation, $topScale, $topScaleHeight, $bgColor, $lineColor, $monthHeaderFontSize) {
44                $this->cb->AddPage($orientation);
45                $this->bgColor = $this->convertColor($bgColor);
46                $this->lineColor = $this->convertColor($lineColor);
47                $this->topScaleHeight = $topScaleHeight;
48                $this->topScale = $topScale;
49
50                $this->lineStyle = Array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '2', 'color' => $this->lineColor);
51                $this->cb->SetLineStyle($this->lineStyle);
52                $this->cb->SetFillColor($this->bgColor['R'], $this->bgColor['G'], $this->bgColor['B']);
53                $this->cb->SetFontSize($monthHeaderFontSize);
54
55                // calculates day width
56                $this->dayWidth = ($this->cb->getPageWidth() - $this->offsetLeft - $this->offsetRight)/7;
57                // circle: for every column of header draw cell
58                for ($i = 0; $i < count($topScale); $i++) {
59                        $this->cb->Cell($this->dayWidth, $topScaleHeight, $topScale[$i], 1, 0, 'C', 1);
60                }
61        }
62
63
64        // draws scheduler grid on month mode
65        public function drawMonthGrid($dayHeader, $dayHeaderHeight, $dayHeaderColor, $dayBodyColor, $dayHeaderColorInactive, $dayBodyColorInactive, $monthDayHeaderFontSize) {
66                // sets starting coordinates
67                $this->cb->setX($this->offsetLeft);
68                $this->cb->setY($this->offsetTop + $this->topScaleHeight, false);
69
70                $this->dayHeaderColor = $this->convertColor($dayHeaderColor);
71                $this->dayBodyColor = $this->convertColor($dayBodyColor);
72                $this->dayHeaderColorInactive = $this->convertColor($dayHeaderColorInactive);
73                $this->dayBodyColorInactive = $this->convertColor($dayBodyColorInactive);
74
75                // calculates height of day container header, body and whole height of day container
76                $this->dayHeaderHeight = $dayHeaderHeight;
77                $this->dayHeader = $dayHeader;
78                $this->dayBodyHeight = ($this->cb->getPageHeight() - $this->offsetTop - $this->offsetBottom - $this->topScaleHeight - $this->dayHeaderHeight*count($dayHeader))/count($dayHeader);
79                $this->dayHeight = $this->dayHeaderHeight + $this->dayBodyHeight;
80
81                // sets font size
82                $this->cb->SetFontSize($monthDayHeaderFontSize);
83                // creates array of values where result['week']['day'] is true if day container in current month and false otherwise
84                $activeDays = $this->setActiveDays($dayHeader);
85
86                // circle for drawing day containers
87                for ($i = 0; $i < count($dayHeader); $i++) {
88                    // draws day headers for every cell of row
89                    for ($j = 0; $j < count($dayHeader[$i]); $j++) {
90                            $ln = ($j == 6) ? 1 : 0;
91                            $color = ($activeDays[$i][$j] == true) ? $this->dayHeaderColor : $this->dayHeaderColorInactive;
92                            $this->cb->SetFillColor($color['R'], $color['G'], $color['B']);
93                            $this->cb->Cell($this->dayWidth, $this->dayHeaderHeight, $dayHeader[$i][$j], 1, $ln, 'R', 1);
94                            $this->dayEventsHeight[$i][$j] = 0;
95                    }
96                    // draws day body for every cell of row
97                    for ($j = 0; $j < 7; $j++) {
98                            $ln = ($j == 6) ? 1 : 0;
99                            $color = ($activeDays[$i][$j] == true) ? $this->dayBodyColor : $this->dayBodyColorInactive;
100                            $this->cb->SetFillColor($color['R'], $color['G'], $color['B']);
101                            $this->cb->Cell($this->dayWidth, $this->dayBodyHeight, '', 1, $ln, 'R', 0);
102                    }
103                }
104        }
105
106
107        // draws events in month mode
108        public function drawMonthEvents($events, $eventColor, $eventBorderColor, $monthEventFontSize, $mode, $offset = 1, $offsetLine = 6) {
109                $this->eventColor = $this->convertColor($eventColor);
110                $this->eventBorderColor = $this->convertColor($eventBorderColor);
111                $this->events = $events;
112
113                $this->cb->setFontSize($monthEventFontSize);
114
115                $this->cb->SetFillColor($this->eventColor['R'], $this->eventColor['G'], $this->eventColor['B']);
116                // initial value for footnote number
117                $footNum = 0;
118                // initial values for checking if in some day footenote has already drawed
119                $day = -1;
120                $week = -1;
121
122                // circle for drawing every event
123                for ($i = 0; $i < count($this->events); $i++) {
124                        $event = $this->events[$i];
125                        if ($event['week'] >= count($this->dayHeader)) {
126                                continue;
127                        }
128                        // calculation x-, y- positions, width and height of event
129                        $x = $this->offsetLeft + $event['day']*$this->dayWidth;
130                        $y = $this->offsetTop + $this->topScaleHeight + $event['week']*$this->dayHeight + $this->dayHeaderHeight + $this->dayEventsHeight[$event['week']][$event['day']] + $offset;
131                        if ($event['type'] == 'event_line') {
132                                $width = $event['width']*$this->dayWidth/100;
133                                $x += 1.5;
134                        } else {
135                                $width = $this->dayWidth - 1;
136                        }
137                        $height = 4;
138
139                        $this->cb->setX($x);
140                        $this->cb->setY($y, false);
141
142                        // checks if event can be drawed in day container
143                        if ($y + $height > ($this->offsetTop + $this->topScaleHeight + ($event['week'] + 1)*$this->dayHeight)) {
144                                // checks if footenote hasn't already drawed for current day and week values
145                                if (!(($week == $event['week'])&&($day == $event['day']))) {
146                                        $footNum++;
147                                        $x1Line = $this->offsetLeft + $this->dayWidth*($event['day'] + 1);
148                                        $x2Line = $x1Line - $offsetLine;
149                                        $y1Line = $this->offsetTop + $this->topScaleHeight + $this->dayHeight*($event['week'] + 1) - $offsetLine;
150                                        $y2Line = $this->offsetTop + $this->topScaleHeight + $this->dayHeight*($event['week'] + 1);
151                                        $this->lineStyle = Array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '2', 'color' => $this->lineColor);
152                                        $this->cb->SetLineStyle($this->lineStyle);
153                                        $this->cb->Line($x1Line, $y1Line, $x2Line, $y2Line);
154                                        $textWidth = $this->cb->getStringWidth($footNum);
155                                        $xText = $x1Line - $textWidth - 0.5;
156                                        $yText = $y2Line - 0.6;
157
158                                        $day = $event['day'];
159                                        $week = $event['week'];
160                                        $this->cb->Text($xText, $yText, $footNum);
161                                }
162                                // sets variable which means that this event will print in footenotes
163                                $this->events[$i]['foot'] = true;
164                        } else {
165                                // draws event in current day
166                                $this->lineStyle = Array('width' => 0.3, 'cap' => 'round', 'join' => 'round', 'dash' => '0', 'color' => $this->eventBorderColor);
167                                $this->cb->SetLineStyle($this->lineStyle);
168                                $text = $this->textWrap($event['text'], $width, $monthEventFontSize);
169
170                                // sets event color
171                                $color = $this->processEventColor($event['color']);
172                                if (($color == 'transparent')||($mode !== 'color')) {
173                                        $this->cb->SetFillColor($this->eventColor['R'], $this->eventColor['G'], $this->eventColor['B']);
174                                } else {
175                                        $color = $this->convertColor($color);
176                                        $this->cb->SetFillColor($color['R'], $color['G'], $color['B']);
177                                }
178
179                                if ($event['type'] == 'event_clear') {
180                                        $this->cb->Cell($width, $height, $text, 0, 0, 'L', 0);
181                                } else {
182                                        $this->cb->Cell($width, $height, $text, 1, 0, 'L', 1);
183                                }
184                                for ($j = $event['day']; ($j < $event['day'] + ceil($width/$this->dayWidth))&&($j < 7); $j++) {
185                                        if ($event['week'] < count($this->dayHeader)) {
186                                                $this->dayEventsHeight[$event['week']][$j] += $height + $offset;
187                                        }
188                                }
189                                $this->events[$i]['foot'] = false;
190                        }
191                }
192                // draws footenotes
193                if ($footNum > 0) {
194                        $this->drawMonthFootenotes();
195                }
196        }
197
198
199        // draws pages with events which can not being showed in day container
200        private function drawMonthFootenotes() {
201                $this->cb->addPage();
202
203                // initials x-, y- coordinates
204                $x = $this->offsetLeft;
205                $y = $this->offsetTop;
206
207                // variables for checking if events have the same date
208                $week = -1;
209                $day = -1;
210                $footNum = 1;
211                // circle for all events
212                for ($i = 0; $i < count($this->events); $i++) {
213                        // checks not printed events
214                        if (($this->events[$i]['week'] < count($this->dayHeader))&&($this->events[$i]['foot'] == true)) {
215                                $event = $this->events[$i];
216                                $text = $event['text'];
217                                // checks if it's necessary to print footenote number
218                                if (!(($week == $event['week'])&&($day == $event['day']))) {
219                                        $textTop = $this->dayHeader[$event['week']][$event['day']].'['.$footNum.']';
220                                        $linesNum = $this->cb->getNumLines($text, $this->colWidth);
221                                        $heightEvent = $linesNum*$this->cb->getFontSize() + $this->cb->getFontSize()*0.5*($linesNum + 1);
222                                        $linesNum = $this->cb->getNumLines($textTop, $this->colWidth);
223                                        $heightHeader = $linesNum*$this->cb->getFontSize() + $this->cb->getFontSize()*0.5*($linesNum + 1);
224                                        // checks if the current column is over
225                                        if ($y + $heightEvent + $heightHeader > $this->cb->getPageHeight() - $this->offsetBottom) {
226                                                $x += $this->colWidth + $this->colOffset;
227                                                $y = $this->offsetTop;
228                                                // checks if it's necessary to add new page
229                                                if ($x + $this->colWidth > $this->cb->getPageWidth() - $this->offsetRight) {
230                                                        $this->cb->addPage();
231                                                        $x = $this->offsetLeft;
232                                                        $y = $this->offsetTop;
233                                                }
234                                        }
235
236                                        $this->cb->MultiCell($this->colWidth, 5, $textTop, 0, 'C', 0, 0, $x, $y);
237                                        $y += $this->cb->getLastH();
238                                        $footNum++;
239                                }
240
241                                // checks if currrent column is over
242                                if ($y + $heightEvent > $this->cb->getPageHeight() - $this->offsetBottom) {
243                                        $x += $this->colWidth + $this->colOffset;
244                                        $y = $this->offsetTop;
245                                        // checks if it's necessary to add new page
246                                        if ($x + $this->colWidth > $this->cb->getPageWidth() - $this->offsetRight) {
247                                                $this->cb->addPage();
248                                                $x = $this->offsetLeft;
249                                                $y = $this->offsetTop;
250                                        }
251                                        $textTop = $this->dayHeader[$event['week']][$event['day']].'['.($footNum - 1).']';
252                                        $this->cb->MultiCell($this->colWidth, 5, $textTop, 0, 'C', 0, 0, $x, $y);
253                                        $y += $this->cb->getLastH();
254                                }
255                                // draws event
256                                $this->cb->MultiCell($this->colWidth, 5, $text, 1, 'L', 1, 0, $x, $y);
257                                $y += $this->cb->getLastH();
258                                $week = $event['week'];
259                                $day = $event['day'];
260                        }
261                }
262        }
263
264
265        // creates array with active/inactive option for every day
266        private function setActiveDays($dayHeader) {
267                if ($dayHeader[0][0] == '1') {
268                        // month grid starts from first day of month
269                        $flag = true;
270                        $flagCount = 1;
271                } else {
272                        // month grid starts from day of previous month
273                        $flag = false;
274                        $flagCount = 0;
275                }
276                $activeDays = Array();
277                $prevDay = (int) $dayHeader[0][0];
278
279                for ($i = 0; $i < count($dayHeader); $i++) {
280                        for ($j = 0; $j < count($dayHeader[$i]); $j++) {
281                                // check if previous day value is less then current day value
282                                if (((int) $dayHeader[$i][$j] < $prevDay)&&($flagCount < 2)) {
283                                        $flag = !$flag;
284                                        $flagCount++;
285                                }
286                                $activeDays[$i][$j] = $flag;
287                                $prevDay = (int) $dayHeader[$i][$j];
288                        }
289                }
290                return $activeDays;
291        }
292
293
294        //
295        public function drawYear($orientation, $yearValues, $events, $headerHeight, $bgColor, $lineColor, $dayColor, $dayColorInactive, $eventColor, $yearHeaderFontSize, $yearFontSize) {
296                $this->cb->AddPage($orientation);
297                $this->bgColor = $this->convertColor($bgColor);
298                $this->lineColor = $this->convertColor($lineColor);
299                $this->dayColor = $this->convertColor($dayColor);
300                $this->dayColorInactive = $this->convertColor($dayColorInactive);
301                $this->eventColor = $this->convertColor($eventColor);
302                $this->yearValues = $yearValues;
303                $this->events = $events;
304                $this->headerHeight = $headerHeight;
305
306                // offset between monthes
307                $offset = 5;
308
309                // sets line style and color
310                $this->lineStyle = Array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '2', 'color' => $this->lineColor);
311                $this->cb->SetLineStyle($this->lineStyle);
312                $this->cb->SetFillColor($this->bgColor['R'], $this->bgColor['G'], $this->bgColor['B']);
313
314                // calculates month width and height
315                $monthWidth = ($this->cb->getPageWidth() - $this->offsetLeft - $this->offsetRight - $offset*3)/4;
316                $monthHeight = ($this->cb->getPageHeight() - $this->offsetTop - $this->offsetBottom - $offset*2)/3;
317
318                // circles for drawing all monthes
319                for ($i = 0; $i < 3; $i++) {
320                        for ($j = 0; $j < 4; $j++) {
321                                $this->cb->SetFillColor($this->bgColor['R'], $this->bgColor['G'], $this->bgColor['B']);
322                                $num = $i*4 + $j;
323                                // calculates x- and y-coordinates of current month
324                                $x = $this->offsetLeft + $j*$monthWidth + $offset*($j);
325                                $y = $this->offsetTop + $i*$monthHeight + $offset*($i);
326                                $this->cb->setX($x);
327                                $this->cb->setY($y, false);
328                                $this->cb->SetFontSize($yearHeaderFontSize);
329                                // draws name of month
330                                $this->cb->Cell($monthWidth, $this->headerHeight, $this->yearValues[$num]['label'], 1, 1, 'C', 1);
331                                // calculates day width and height
332                                $dayWidth = $monthWidth/7;
333                                $dayHeight = ($monthHeight - $headerHeight)/7;
334                                $y += $headerHeight;
335                                // create array of day in current month
336                                $activeDays = $this->setActiveDays($this->yearValues[$num]['rows']);
337
338                                // draws day names
339                                for ($k = 0; $k < count($this->yearValues[$num]['columns']); $k++) {
340                                        $this->cb->setX($x);
341                                        $this->cb->setY($y, false);
342                                        $this->cb->Cell($dayWidth, $dayHeight, $this->yearValues[$num]['columns'][$k], 1, 1, 'C', 1);
343                                        $x += $dayWidth;
344                                }
345                                $y += $dayHeight;
346                                $x -= $dayWidth*7;
347                                $this->cb->SetFontSize($yearFontSize);
348                                // draws days
349                                for ($k = 0; $k < count($this->yearValues[$num]['rows']); $k++) {
350                                        for ($l = 0; $l < count($this->yearValues[$num]['rows'][$k]); $l++) {
351                                                $this->cb->setX($x);
352                                                $this->cb->setY($y, false);
353                                                // checks if day of current month
354                                                if ($activeDays[$k][$l] == true) {
355                                                        // checks if the day have events
356                                                        if (in_array($num.'_'.$k.'_'.$l, $this->events)) {
357                                                                $this->cb->SetFillColor($this->eventColor['R'], $this->eventColor['G'], $this->eventColor['B']);
358                                                        } else {
359                                                                $this->cb->SetFillColor($this->dayColor['R'], $this->dayColor['G'], $this->dayColor['B']);
360                                                        }
361                                                        $text = $this->yearValues[$num]['rows'][$k][$l];
362                                                } else {
363                                                        // it's the day of previous or next month
364                                                        $this->cb->SetFillColor($this->dayColorInactive['R'], $this->dayColorInactive['G'], $this->dayColorInactive['B']);
365                                                        $text = '';
366                                                }
367                                                // draw day
368                                                $this->cb->Cell($dayWidth, $dayHeight, $text, 1, 1, 'C', 1);
369                                                $x += $dayWidth;
370                                        }
371                                        $y += $dayHeight;
372                                        $x -= $dayWidth*7;
373                                }
374                        }
375                }
376        }
377
378
379        // draws agenda mode
380        public function drawAgenda($agendaHeader, $events, $rowHeight, $bgColor, $lineColor, $scaleColorOne, $scaleColorTwo, $fontSize, $today, $todayFontSize) {
381                $this->bgColor = $this->convertColor($bgColor);
382                $this->lineColor = $this->convertColor($lineColor);
383                $this->scaleColorOne = $this->convertColor($scaleColorOne);
384                $this->scaleColorTwo = $this->convertColor($scaleColorTwo);
385                $this->cb->addPage();
386                $this->drawToday($today, $todayFontSize);
387                $this->cb->setFontSize($fontSize);
388
389                // sets column
390                $timeColWidth = 50;
391                $dscColWidth = $this->cb->getPageWidth() - $this->offsetLeft - $this->offsetRight - $timeColWidth;
392                $this->lineStyle = Array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '2', 'color' => $this->lineColor);
393                $this->cb->SetLineStyle($this->lineStyle);
394                $this->cb->SetFillColor($this->bgColor['R'], $this->bgColor['G'], $this->bgColor['B']);
395
396                $text = $this->textWrap($agendaHeader[0], $timeColWidth, $fontSize);
397                $this->cb->Cell($timeColWidth, $rowHeight, $text, 1, 0, 'C', 1);
398                $text = $this->textWrap($agendaHeader[1], $dscColWidth, $fontSize);
399                $this->cb->Cell($dscColWidth, $rowHeight, $text, 1, 1, 'C', 1);
400
401                for ($i = 0; $i < count($events); $i++) {
402                        // checks if the page is over
403                        if ($this->cb->getY() + $rowHeight > $this->cb->getPageHeight() - $this->offsetBottom) {
404                                // add new page, draws page num, header and today label
405                                $this->cb->setPrintFooter(true);
406                                $this->cb->addPage();
407                                $this->drawToday($today, $todayFontSize);
408                                $this->cb->setFontSize($fontSize);
409                                $this->cb->SetFillColor($this->bgColor['R'], $this->bgColor['G'], $this->bgColor['B']);
410                                $text = $this->textWrap($agendaHeader[0], $timeColWidth, $fontSize);
411                                $this->cb->Cell($timeColWidth, $rowHeight, $text, 1, 0, 'C', 1);
412                                $text = $this->textWrap($agendaHeader[1], $dscColWidth, $fontSize);
413                                $this->cb->Cell($dscColWidth, $rowHeight, $text, 1, 1, 'C', 1);
414                        }
415                        // selects scale color
416                        if ($i%2 == 0) {
417                                $this->cb->SetFillColor($this->scaleColorOne['R'], $this->scaleColorOne['G'], $this->scaleColorOne['B']);
418                        } else {
419                                $this->cb->SetFillColor($this->scaleColorTwo['R'], $this->scaleColorTwo['G'], $this->scaleColorTwo['B']);
420                        }
421                        // draws time cell
422                        $text = $this->textWrap($events[$i]['head'], $timeColWidth, $fontSize);
423                        $this->cb->Cell($timeColWidth, $rowHeight, $text, 1, 0, 'L', 1);
424                        // draws description cell
425                        $text = $this->textWrap($events[$i]['body'], $dscColWidth, $fontSize);
426                        $this->cb->Cell($dscColWidth, $rowHeight, $text, 1, 1, 'L', 1);
427                }
428        }
429
430
431        // draws headers and grid for day and week mode
432        public function drawDayWeekHeader($columnHeader, $rowHeader, $topHeight, $leftWidth, $bgColor, $lineColor, $scaleColorOne, $scaleColorTwo, $dayHeaderFontSize, $dayScaleFontSize, $mode) {
433                $this->cb->addPage();
434                $this->bgColor = $this->convertColor($bgColor);
435                $this->lineColor = $this->convertColor($lineColor);
436                $this->scaleColorOne = $this->convertColor($scaleColorOne);
437                $this->scaleColorTwo = $this->convertColor($scaleColorTwo);
438
439                $this->leftWidth = $leftWidth;
440                $this->topHeight = $topHeight;
441
442                $this->lineStyle = Array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '2', 'color' => $this->lineColor);
443                $this->cb->SetLineStyle($this->lineStyle);
444                $this->cb->SetFillColor($this->bgColor['R'], $this->bgColor['G'], $this->bgColor['B']);
445
446                // calculates cell width and height
447                $this->colWidth = ($this->cb->getPageWidth() - $this->offsetLeft - $this->offsetRight - $leftWidth)/count($columnHeader);
448                $this->colHeight = ($this->cb->getPageHeight() - $this->offsetTop - $this->offsetBottom - $topHeight)/count($rowHeader);
449
450                $this->cb->setX($this->offsetLeft + $leftWidth);
451                $this->cb->setY($this->offsetTop, false);
452
453                // draws scales on top
454                $this->cb->setFontSize($dayHeaderFontSize);
455                for ($i = 0; $i < count($columnHeader); $i++) {
456                        $Ln = ($i == count($columnHeader) - 1) ? 1 : 0;
457                        $this->cb->Cell($this->colWidth, $topHeight, $columnHeader[$i], 1, $Ln, 'C', 1);
458                }
459
460                $this->cb->setFontSize($dayScaleFontSize);
461                // draws scales on left
462                for ($i = 0; $i < count($rowHeader); $i++) {
463                        $this->cb->Cell($leftWidth, $this->colHeight, $rowHeader[$i], 1, 1, 'C', 1);
464                }
465
466                $this->cb->setX($this->offsetLeft + $leftWidth);
467                $this->cb->setY($this->offsetTop + $topHeight, false);
468                // circle for drawing scales
469
470                for ($i = 0; $i < count($rowHeader); $i++) {
471                        // draws white line
472                        $this->cb->SetFillColor($this->scaleColorOne['R'], $this->scaleColorOne['G'], $this->scaleColorOne['B']);
473                        $border = (($i == 0)||($mode == 'bw')) ? 'LRT' : 'LR';
474                        $this->cb->Cell($this->colWidth*count($columnHeader), $this->colHeight/2, '', $border, 1, 'C', 1);
475                        // draws blue line
476                        $this->cb->setX($this->offsetLeft + $leftWidth);
477                        $this->cb->SetFillColor($this->scaleColorTwo['R'], $this->scaleColorTwo['G'], $this->scaleColorTwo['B']);
478                        $border = (($i == count($rowHeader) - 1)||($mode == 'bw')) ? 'LRB' : 'LR';
479                        $this->cb->Cell($this->colWidth*count($columnHeader), $this->colHeight/2, '', $border, 1, 'C', 1);
480                        $this->cb->setX($this->offsetLeft + $leftWidth);
481                }
482                // draws lines delemiters between days if it's week mode
483                if (count($columnHeader > 1)) {
484                        for ($i = 0; $i < count($columnHeader) - 1; $i++) {
485                                $x = $this->offsetLeft + $leftWidth + ($i + 1)*$this->colWidth;
486                                $y1 = $this->offsetTop + $topHeight;
487                                $y2 = $this->cb->getPageHeight() - $this->offsetBottom;
488                                $this->cb->line($x, $y1, $x, $y2);
489                        }
490                }
491        }
492
493
494        // draws events in day and week modes
495        public function drawDayWeekEvents($events, $eventColor, $eventBorderColor, $dayEventHeaderFontSize, $dayEventBodyFontSize, $mode) {
496                $this->eventColor = $this->convertColor($eventColor);
497                $this->eventBorderColor = $this->convertColor($eventBorderColor);
498
499                $eventHeaderHeight = 4;
500
501                $this->lineStyle = Array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '0', 'color' => $this->eventBorderColor);
502                $this->cb->setLineStyle($this->lineStyle);
503
504
505                // circle for every event
506                for ($i = 0; $i < count($events); $i++) {
507                        $event = $events[$i];
508                        // sets event color
509                        $color = $this->processEventColor($event['color']);
510                        if (($color == 'transparent')||($mode !== 'color')) {
511                                $this->cb->SetFillColor($this->eventColor['R'], $this->eventColor['G'], $this->eventColor['B']);
512                        } else {
513                                $color = $this->convertColor($color);
514                                $this->cb->SetFillColor($color['R'], $color['G'], $color['B']);
515                        }
516
517                        // calculates x-, y-coordinates, width and height of event
518                        $x = $this->offsetLeft + $this->leftWidth + $event['x']*$this->colWidth/100;
519                        $y = $this->offsetTop + $this->topHeight + $event['y']*$this->colHeight/100;
520                        $width = $event['width']*$this->colWidth/100 - $this->colWidth/60;
521                        $height = $event['height']*$this->colHeight/100;
522
523                        // draws event container
524                        $this->cb->RoundedRect($x, $y, $width, $height, 1, '1111', 'DF', array(), $this->eventColor);
525                        $this->cb->setX($x);
526                        $this->cb->setY($y, false);
527                        // draws event header
528                        $this->cb->setFontSize($dayEventHeaderFontSize);
529                        $text = $this->textWrap($event['head'], $width, $dayEventHeaderFontSize);
530                        $this->cb->Cell($width, $eventHeaderHeight, $text, 0, 0, 'C', 0);
531                        $y += $eventHeaderHeight;
532                        $height -= $eventHeaderHeight;
533                        // draws event body
534                        $this->cb->setFontSize($dayEventBodyFontSize);
535                        $this->cb->MultiCell($width, $height, $event['body'], 0, 'L', 0, 0, $x, $y,  true, 0, false, true, $height);
536                        // draws separate line
537                        $this->cb->line($x, $y, $x + $width, $y);
538                }
539        }
540
541
542
543
544        /*************************************************************************/
545        // draws scheduler header in month mode
546        public function drawWeekHeader($orientation, $topScale, $topScaleHeight, $bgColor, $lineColor, $monthHeaderFontSize) {
547                $this->cb->AddPage($orientation);
548                $this->bgColor = $this->convertColor($bgColor);
549                $this->lineColor = $this->convertColor($lineColor);
550                $this->topScaleHeight = $topScaleHeight;
551                $this->topScale = $topScale;
552
553                $this->lineStyle = Array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '2', 'color' => $this->lineColor);
554                $this->cb->SetLineStyle($this->lineStyle);
555                $this->cb->SetFillColor($this->bgColor['R'], $this->bgColor['G'], $this->bgColor['B']);
556                $this->cb->SetFontSize($monthHeaderFontSize);
557
558                // calculates day width
559                $this->dayWidth = ($this->cb->getPageWidth() - $this->offsetLeft - $this->offsetRight)/2;
560                // circle: for every column of header draw cell
561//              for ($i = 0; $i < count($topScale); $i++) {
562//                      $this->cb->Cell($this->dayWidth, $topScaleHeight, $topScale[$i], 1, 0, 'C', 1);
563//              }
564        }
565
566
567        // draws scheduler grid on month mode
568        public function drawWeekGrid($dayHeader, $dayHeaderHeight, $dayHeaderColor, $dayBodyColor, $dayHeaderColorInactive, $dayBodyColorInactive, $monthDayHeaderFontSize) {
569
570                // sets starting coordinates
571                $this->cb->setX($this->offsetLeft);
572                $this->cb->setY($this->offsetTop + $this->topScaleHeight, false);
573
574                $this->dayHeaderColor = $this->convertColor($dayHeaderColor);
575                $this->dayBodyColor = $this->convertColor($dayBodyColor);
576                $this->dayHeaderColorInactive = $this->convertColor($dayHeaderColorInactive);
577                $this->dayBodyColorInactive = $this->convertColor($dayBodyColorInactive);
578
579                // calculates height of day container header, body and whole height of day container
580                $this->dayHeaderHeight = $dayHeaderHeight;
581                $this->dayHeader = $dayHeader;
582                $this->dayBodyHeight = ($this->cb->getPageHeight() - $this->offsetTop - $this->offsetBottom - $this->topScaleHeight - $this->dayHeaderHeight*count($dayHeader))/count($dayHeader);
583                $this->dayHeight = $this->dayHeaderHeight + $this->dayBodyHeight;
584
585                // sets font size
586                $this->cb->SetFontSize($monthDayHeaderFontSize);
587                // creates array of values where result['week']['day'] is true if day container in current month and false otherwise
588                //$activeDays = $this->setActiveDays($dayHeader);
589
590                // circle for drawing day containers
591                for ($i = 0; $i < count($dayHeader); $i++) {
592                    // draws day headers for every cell of row
593                    for ($j = 0; $j < 2; $j++) {
594                            if($i == 3 && $j == 1){
595                                $ln = ($j == 1) ? 1 : 0;
596                                $color =  $this->dayHeaderColor ;
597                                $this->cb->SetFillColor($color['R'], $color['G'], $color['B']);
598                                $this->cb->Cell($this->dayWidth, $this->dayHeaderHeight, '', 1, $ln, 'R', 1);
599                                $this->dayEventsHeight[$i][$j] = 0;
600                            }else{
601                                $ln = ($j == 1) ? 1 : 0;
602                                $color =  $this->dayHeaderColor ;
603                                $this->cb->SetFillColor($color['R'], $color['G'], $color['B']);
604                                $this->cb->Cell($this->dayWidth, $this->dayHeaderHeight, $dayHeader[$i][$j], 1, $ln, 'R', 1);
605                                $this->dayEventsHeight[$i][$j] = 0;
606
607                            }
608
609
610                    }
611                    // draws day body for every cell of row
612                    for ($j = 0; $j < 2; $j++) {
613                            $ln = ($j == 1) ? 1 : 0;
614                            $color = $this->dayBodyColor ;
615                            $this->cb->SetFillColor($color['R'], $color['G'], $color['B']);
616                            $this->cb->Cell($this->dayWidth, $this->dayBodyHeight, '', 1, $ln, 'R', 0);
617
618                    }
619
620                }
621        }
622
623
624
625        // draws events in month mode
626        public function drawWeekEvents($events, $eventColor, $eventBorderColor, $monthEventFontSize, $mode, $offset = 1, $offsetLine = 6) {
627                $this->eventColor = $this->convertColor($eventColor);
628                $this->eventBorderColor = $this->convertColor($eventBorderColor);
629                $this->events = $events;
630
631                $this->cb->setFontSize($monthEventFontSize);
632
633                $this->cb->SetFillColor($this->eventColor['R'], $this->eventColor['G'], $this->eventColor['B']);
634                // initial value for footnote number
635                $footNum = 0;
636                // initial values for checking if in some day footenote has already drawed
637                $day = -1;
638                $week = -1;
639
640                // circle for drawing every event
641                foreach ($this->events as $i => $event) {
642                        //$event = $this->events[$i];
643
644                       if($event['week'] == 3 && $event['day'] > 0)
645                               continue;
646//                        $event['week'] = $event['week'] -1;
647                        // calculation x-, y- positions, width and height of event
648                        $x = $this->offsetLeft + $event['day']*$this->dayWidth;
649                        $y = $this->offsetTop + $this->topScaleHeight + $event['week']*$this->dayHeight + $this->dayHeaderHeight + $this->dayEventsHeight[$event['week']][$event['day']];
650                        if ($event['type'] == 'event_line') {
651                                $width = $event['width']*$this->dayWidth/100;
652                                $x += 1.5;
653                        } else {
654                                $width = $this->dayWidth - 1;
655                        }
656                        $height = 4;
657
658                        $this->cb->setX($x);
659                        $this->cb->setY($y, false);
660
661                        // checks if event can be drawed in day container
662//                      if ($y + $height > ($this->offsetTop + $this->topScaleHeight + ($event['week'] + 1)*$this->dayHeight)) {
663//                              // checks if footenote hasn't already drawed for current day and week values
664//                              if (!(($week == $event['week'])&&($day == $event['day']))) {
665//                                      $footNum++;
666//                                      $x1Line = $this->offsetLeft + $this->dayWidth*($event['day'] + 1);
667//                                      $x2Line = $x1Line - $offsetLine;
668//                                      $y1Line = $this->offsetTop + $this->topScaleHeight + $this->dayHeight*($event['week'] + 1) - $offsetLine;
669//                                      $y2Line = $this->offsetTop + $this->topScaleHeight + $this->dayHeight*($event['week'] + 1);
670//                                      $this->lineStyle = Array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '2', 'color' => $this->lineColor);
671//                                      $this->cb->SetLineStyle($this->lineStyle);
672//                                      $this->cb->Line($x1Line, $y1Line, $x2Line, $y2Line);
673//                                      $textWidth = $this->cb->getStringWidth($footNum);
674//                                      $xText = $x1Line - $textWidth - 0.5;
675//                                      $yText = $y2Line - 0.6;
676//
677//                                      $day = $event['day'];
678//                                      $week = $event['week'];
679//                                      $this->cb->Text($xText, $yText, $footNum);
680//                              }
681//                              // sets variable which means that this event will print in footenotes
682//                              $this->events[$i]['foot'] = true;
683//                      } else {
684                                // draws event in current day
685                                $this->lineStyle = Array('width' => 0.3, 'cap' => 'round', 'join' => 'round', 'dash' => '0', 'color' => $this->eventBorderColor);
686                                $this->cb->SetLineStyle($this->lineStyle);
687                                $text = $this->textWrap($event['text'], $width, $monthEventFontSize);
688
689                                // sets event color
690                                $color = $this->processEventColor($event['color']);
691                                if (($color == 'transparent')||($mode !== 'color')) {
692                                        $this->cb->SetFillColor($this->eventColor['R'], $this->eventColor['G'], $this->eventColor['B']);
693                                } else {
694                                        $color = $this->convertColor($color);
695                                        $this->cb->SetFillColor($color['R'], $color['G'], $color['B']);
696                                }
697
698                                if ($event['type'] == 'event_clear') {
699                                        $this->cb->Cell($width, $height, $text, 0, 0, 'L', 0);
700                                } else {
701                                        $this->cb->Cell($width, $height, $text, 1, 0, 'L', 1);
702                                }
703                                for ($j = $event['day']; ($j < $event['day'] + ceil($width/$this->dayWidth))&&($j < 7); $j++) {
704                                        if ($event['week'] < count($this->dayHeader)) {
705                                                $this->dayEventsHeight[$event['week']][$j] += $height + $offset;
706                                        }
707                                }
708                                $this->events[$i]['foot'] = false;
709                //      }
710                //}
711                // draws footenotes
712//              if ($footNum > 0) {
713//                      $this->drawMonthFootenotes();
714                }
715        }
716
717        /*********************************************/
718
719
720
721
722
723        // draws today value
724        public function drawToday($today, $todayFontSize) {
725                $this->cb->setFontSize($todayFontSize);
726                $this->cb->Text($this->offsetLeft, $this->offsetTop - 2, $today);
727        }
728
729
730        // wraps text accordigly getted width and font size
731        private function textWrap($text, $width, $fontSize) {
732                $strWidth = $this->cb->GetStringWidth($text, '', '', $fontSize, false);
733                // if text should be wrapped
734                if ($strWidth >= $width) {
735                        $newStr = '';
736                        $newW = 0;
737                        $i = 0;
738                        // adds one symbol and checks text width
739                        while ($newW < $width - 1) {
740                                $newStr .= $text[$i];
741                                $newW = $this->cb->GetStringWidth($newStr.$text[$i + 1].'...', '', '', $fontSize, false);
742                                $i++;
743                        }
744                        return $newStr.'...';
745                } else {
746                        return $text;
747                }
748        }
749
750
751        // outputs PDF in browser
752        public function pdfOut($date) {
753                // send PDF-file in browser
754
755                $this->cb->Output('Cal_'.$date.'.pdf', 'I');
756        }
757
758
759        // converts color from "ffffff" to Array('R' => 255, 'G' => 255, 'B' => 255)
760        private function convertColor($colorHex) {
761                $final = Array();
762                $final['R'] = hexdec(substr($colorHex, 0, 2));
763                $final['G'] = hexdec(substr($colorHex, 2, 2));
764                $final['B'] = hexdec(substr($colorHex, 4, 2));
765                return $final;
766        }
767
768
769        // convert event color ot RGB-format
770        private function processEventColor($color) {
771                if ($color == 'transparent') {
772                        return $color;
773                }
774
775                if (preg_match("/#[0-9A-Fa-f]{6}/", $color)) {
776                        return substr($color, 1);
777                }
778                $result = preg_match_all("/rgb\s?\((\d{1,3})\s?,\s?(\d{1,3})\s?,\s?(\d{1,3})\)/", $color, $rgb);
779
780                if ($result) {
781                        $color = '';
782                        for ($i = 1; $i <= 3; $i++) {
783                                $comp = dechex($rgb[$i][0]);
784                                if (strlen($comp) == 1) {
785                                        $comp = '0'.$comp;
786                                        }
787                                $color .= $comp;
788                        }
789                        return $color;
790                } else {
791                        return 'transparent';
792                }
793        }
794
795
796
797
798
799
800
801
802}
803
804?>
Note: See TracBrowser for help on using the repository browser.