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

Revision 4049, 11.4 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
6class schedulerPDF {
7
8        public $offsetTop = 15;
9        public $offsetBottom = 10;
10        public $offsetLeft = 10;
11        public $offsetRight = 10;
12
13        // header height of day container in month mode
14        public $monthDayHeaderHeight = 6;
15        // header height in month mode
16        public $monthHeaderHeight = 8;
17        // height of month name container in year mode
18        public $yearMonthHeaderHeight = 8;
19        // height of row in agenda mode
20        public $agendaRowHeight = 6;
21        // height of header in day and week mode
22        public $dayTopHeight = 6;
23        // width of left scale in day and week mode
24        public $dayLeftWidth = 16;
25
26        // font size settings
27        public $monthHeaderFontSize = 9;
28        public $monthDayHeaderFontSize = 8;
29        public $monthEventFontSize = 7;
30        public $yearHeaderFontSize = 8;
31        public $yearFontSize = 8;
32        public $agendaFontSize = 8;
33        public $dayHeaderFontSize = 7;
34        public $dayScaleFontSize = 8;
35        public $dayEventHeaderFontSize = 7;
36        public $dayEventBodyFontSize = 7;
37        public $todayFontSize = 11;
38
39        private $profile = 'color';
40        private $orientation = 'P';
41        private $mode;
42        private $today;
43
44        public $lineColor;
45        public $bgColor;
46        public $dayHeaderColor;
47        public $dayBodyColor;
48        public $dayHeaderColorInactive;
49        public $dayBodyColorInactive;
50        public $headerTextColor;
51        public $textColor;
52        public $eventTextColor;
53        public $eventBorderColor;
54        public $eventColor;
55        public $todayTextColor;
56        public $scaleColorOne;
57        public $scaleColorTwo;
58
59        public function printScheduler(&$xml) {
60                $this->renderData($xml);
61                $this->renderScales($xml);
62                $this->renderEvents($xml);
63
64                $this->wrapper = new pdfWrapper($this->offsetTop, $this->offsetRight, $this->offsetBottom, $this->offsetLeft, $this->orientation);
65                $date = '';
66                switch ($this->mode) {
67                        case 'month':
68                                $date = date("MY");
69                                $this->orientation = 'L';
70                                $this->wrapper = new pdfWrapper($this->offsetTop, $this->offsetRight, $this->offsetBottom, $this->offsetLeft, $this->orientation);
71                                $this->printMonth();
72                                break;
73                        case 'day':
74                                $date = date("Ymd") . "_" . date("H:i");
75                                $this->orientation = 'P';
76                                $this->wrapper = new pdfWrapper($this->offsetTop, $this->offsetRight, $this->offsetBottom, $this->offsetLeft, $this->orientation);
77                                $this->printDayWeek();
78                                break;
79                        case 'week':
80                                $date = date("Ymd") . "_" . date("H:i");
81                                $this->orientation = 'P';
82                                $this->wrapper = new pdfWrapper($this->offsetTop, $this->offsetRight, $this->offsetBottom, $this->offsetLeft, $this->orientation);
83                                $this->printWeek();
84                                break;
85                        case 'year':
86                                $date = date("Y");
87                                $this->orientation = 'L';
88                                $this->wrapper = new pdfWrapper($this->offsetTop, $this->offsetRight, $this->offsetBottom, $this->offsetLeft, $this->orientation);
89                                $this->printYear();
90                                break;
91                        case 'agenda':
92                                $this->orientation = 'P';
93                            $this->wrapper = new pdfWrapper($this->offsetTop, $this->offsetRight, $this->offsetBottom, $this->offsetLeft, $this->orientation);
94                                $this->printAgenda();
95                                break;
96                        default:
97                                return false;
98                }
99
100//              $this->wrapper = '';
101//              echo "<pre>";
102//              print_r($this);
103//              echo "</pre>";
104
105                $this->wrapper->pdfOut($date);
106        }
107
108        // parses options profile, orientation, header and footer from xml
109        private function renderData($data) {
110                if (isset($data->attributes()->profile)) {
111                        $this->profile = (string) $data->attributes()->profile;
112                }
113                if (isset($data->attributes()->orientation)) {
114                        $this->orientation = (string) $data->attributes()->orientation;
115                }
116                if (isset($data->attributes()->header)) {
117                        $this->header = (string) $data->attributes()->header;
118                }
119                if (isset($data->attributes()->footer)) {
120                        $this->footer = (string) $data->attributes()->footer;
121                }
122                $this->setProfile();
123        }
124
125
126        // sets color profile
127        private function setProfile() {
128                switch ($this->profile) {
129                        case 'color':
130                                $this->lineColor = '586A7E';
131                                $this->bgColor = 'C2D5FC';
132                                $this->dayHeaderColor = 'EBEFF4';
133                                $this->dayBodyColor = 'FFFFFF';
134                                $this->dayHeaderColorInactive = 'E2E3E6';
135                                $this->dayBodyColorInactive = 'ECECEC';
136                                $this->headerTextColor = '2F3A48';
137                                $this->textColor = '2F3A48';
138                                $this->eventTextColor = '887A2E';
139                                $this->eventBorderColor = 'B7A543';
140                                $this->eventColor = 'FFE763';
141                                $this->todayTextColor = '000000';
142                                $this->scaleColorOne = 'FCFEFC';
143                                $this->scaleColorTwo = 'DCE6F4';
144                                $this->yearDayColor = 'EBEFF4';
145                                $this->yearDayColorInactive = 'd6d6d6';
146                                break;
147                        case 'gray':
148                                $this->lineColor = '666666';
149                                $this->bgColor = 'D3D3D3';
150                                $this->dayHeaderColor = 'EEEEEE';
151                                $this->dayBodyColor = 'FFFFFF';
152                                $this->dayHeaderColorInactive = 'E3E3E3';
153                                $this->dayBodyColorInactive = 'ECECEC';
154                                $this->headerTextColor = '383838';
155                                $this->textColor = '000000';
156                                $this->eventTextColor = '000000';
157                                $this->eventBorderColor = '9F9F9F';
158                                $this->eventColor = 'DFDFDF';
159                                $this->todayTextColor = '000000';
160                                $this->scaleColorOne = 'E4E4E4';
161                                $this->scaleColorTwo = 'FDFDFD';
162                                $this->yearDayColor = 'EBEFF4';
163                                $this->yearDayColorInactive = 'E2E3E6';
164                                break;
165                        case 'bw':
166                                $this->lineColor = '000000';
167                                $this->bgColor = 'FFFFFF';
168                                $this->dayHeaderColor = 'FFFFFF';
169                                $this->dayBodyColor = 'FFFFFF';
170                                $this->dayHeaderColorInactive = 'FFFFFF';
171                                $this->dayBodyColorInactive = 'FFFFFF';
172                                $this->headerTextColor = '000000';
173                                $this->textColor = '000000';
174                                $this->eventTextColor = '000000';
175                                $this->eventBorderColor = '000000';
176                                $this->eventColor = 'FFFFFF';
177                                $this->todayTextColor = '000000';
178                                $this->scaleColorOne = 'FFFFFF';
179                                $this->scaleColorTwo = 'FFFFFF';
180                                $this->yearDayColor = 'FFFFFF';
181                                $this->yearDayColorInactive = 'FFFFFF';
182                                break;
183                }
184        }
185
186
187        // render scales
188        private function renderScales($xml) {
189                $scales = $xml->scale;
190                $this->mode = (string) $scales->attributes()->mode;
191                $this->today = (string) $scales->attributes()->today;
192
193                switch ($this->mode) {
194                        case 'week':
195                            foreach ($scales->x->column as $text) {
196                                        $this->topScales[] = (string) $text;
197                                }
198                                foreach ($scales->row as $text) {
199                                        $week = explode("|", $text);
200                                        $this->dayHeader[] = $week;
201                                }
202                                break;
203                        case 'month':
204                                foreach ($scales->x->column as $text) {
205                                        $this->topScales[] = (string) $text;
206                                }
207                                foreach ($scales->row as $text) {
208                                        $week = explode("|", $text);
209                                        $this->dayHeader[] = $week;
210                                }
211                                break;
212
213                        case 'year':
214                                foreach ($scales->month as $month) {
215                                        $monthArr = Array();
216                                        $monthArr['label'] = (string) $month->attributes()->label;
217                                        foreach ($month->column as $col) {
218                                                $monthArr['columns'][] = (string) $col;
219                                        }
220
221                                        foreach ($month->row as $row) {
222                                                $row = explode("|", $row);
223                                                $monthArr['rows'][] = $row;
224                                        }
225                                        $this->yearValues[] = $monthArr;
226                                }
227                                break;
228
229                        case 'agenda':
230                                $this->agendaHeader[0] = (string) $scales->column[0];
231                                $this->agendaHeader[1] = (string) $scales->column[1];
232                                break;
233
234                        case 'day':
235                                foreach ($scales->x->column as $col) {
236                                        $this->columnHeader[] = (string) $col;
237                                }
238                                foreach ($scales->y->row as $row) {
239                                        $this->rowHeader[] = (string) $row;
240                                }
241                        default:
242                                return false;
243                }
244        }
245
246
247        // parses events from xml
248        private function renderEvents($xml) {
249                $this->events = Array();
250                switch ($this->mode) {
251                        case 'month':
252                                foreach ($xml->event as $ev) {
253                                        $event['week'] = (int) $ev->attributes()->week - 1;
254                                        $event['day'] = (int) $ev->attributes()->day;
255                                        $event['x'] = (int) $ev->attributes()->x;
256                                        $event['y'] = (int) $ev->attributes()->y;
257                                        $event['width'] = (int) $ev->attributes()->width;
258                                        $event['height'] = (int) $ev->attributes()->height;
259                                        $event['type'] = (string) $ev->attributes()->type;
260                                        $event['text'] = (string) $ev->body;
261                                        $event['color'] = (string) $ev->body->attributes()->color;
262                                        $this->events[] = $event;
263                                }
264                                break;
265                        case 'week':
266                                foreach ($xml->event as $ev) {
267                                        $event['week'] = (int) $ev->attributes()->week;
268                                        $event['day'] = (int) $ev->attributes()->day;
269                                        $event['x'] = (int) $ev->attributes()->x;
270                                        $event['y'] = (int) $ev->attributes()->y;
271                                        $event['width'] = (int) $ev->attributes()->width;
272                                        $event['height'] = (int) $ev->attributes()->height;
273                                        $event['type'] = (string) $ev->attributes()->type;
274                                        $event['text'] = (string) $ev->body;
275                                        $event['color'] = (string) $ev->body->attributes()->color;
276                                        $this->events[] = $event;
277                                }
278                                break;
279                        case 'year':
280                                foreach ($xml->event as $ev) {
281                                        $week = (int) $ev->attributes()->week;
282                                        $day = (int) $ev->attributes()->day;
283                                        $month = (int) $ev->attributes()->month;
284                                        $this->events[] = $month.'_'.$week.'_'.$day;
285                                }
286                                break;
287                        case 'agenda':
288                                foreach ($xml->event as $ev) {
289                                        $head = (string) $ev->head;
290                                        $body = (string) $ev->body;
291                                        $this->events[] = Array('head' => $head, 'body' => $body);
292                                }
293                                break;
294                        case 'day':
295                                foreach ($xml->event as $ev) {
296                                        $event['head'] = (string) $ev->header;
297                                        $event['body'] = (string) $ev->body;
298                                        $event['x'] = (int) $ev->attributes()->x;
299                                        $event['y'] = (int) $ev->attributes()->y;
300                                        $event['width'] = (int) $ev->attributes()->width;
301                                        $event['height'] = (int) $ev->attributes()->height;
302                                        $event['color'] = (string) $ev->body->attributes()->color;
303                                        $this->events[] = $event;
304                                }
305                }
306        }
307
308
309        private function printMonth() {
310                $this->wrapper->drawMonthHeader($this->orientation, $this->topScales, $this->monthHeaderHeight, $this->bgColor, $this->lineColor, $this->monthHeaderFontSize);
311                $this->wrapper->drawToday($this->today, $this->todayFontSize);
312                $this->wrapper->drawMonthGrid($this->dayHeader, $this->monthDayHeaderHeight, $this->dayHeaderColor, $this->dayBodyColor, $this->dayHeaderColorInactive, $this->dayBodyColorInactive, $this->monthDayHeaderFontSize);
313                $this->wrapper->drawMonthEvents($this->events, $this->eventColor, $this->eventBorderColor, $this->monthEventFontSize, $this->profile);
314        }
315
316
317        private function printYear() {
318                $this->wrapper->drawYear($this->orientation, $this->yearValues, $this->events, $this->yearMonthHeaderHeight, $this->bgColor, $this->lineColor, $this->yearDayColor, $this->yearDayColorInactive, $this->eventColor, $this->yearHeaderFontSize, $this->yearFontSize);
319                $this->wrapper->drawToday($this->today, $this->todayFontSize);
320        }
321
322
323        private function printAgenda() {
324                $this->wrapper->drawAgenda($this->agendaHeader, $this->events, $this->agendaRowHeight, $this->bgColor, $this->lineColor, $this->scaleColorOne, $this->scaleColorTwo, $this->agendaFontSize, $this->today, $this->todayFontSize);
325        }
326
327
328        private function printDayWeek() {
329                $this->wrapper->drawDayWeekHeader($this->columnHeader, $this->rowHeader, $this->dayTopHeight, $this->dayLeftWidth, $this->bgColor, $this->lineColor, $this->scaleColorOne, $this->scaleColorTwo, $this->dayHeaderFontSize, $this->dayScaleFontSize, $this->profile);
330                $this->wrapper->drawToday($this->today, $this->todayFontSize);
331                $this->wrapper->drawDayWeekEvents($this->events, $this->eventColor, $this->eventBorderColor, $this->dayEventHeaderFontSize, $this->dayEventBodyFontSize, $this->profile);
332        }
333
334        private function printWeek() {
335                $this->wrapper->drawWeekHeader($this->orientation, $this->topScales, $this->monthHeaderHeight, $this->bgColor, $this->lineColor, $this->monthHeaderFontSize);
336                $this->wrapper->drawToday($this->today, $this->todayFontSize);
337                $this->wrapper->drawWeekGrid($this->dayHeader, $this->monthDayHeaderHeight, $this->dayHeaderColor, $this->dayBodyColor, $this->dayHeaderColorInactive, $this->dayBodyColorInactive, $this->monthDayHeaderFontSize);
338                $this->wrapper->drawWeekEvents($this->events, $this->eventColor, $this->eventBorderColor, $this->monthEventFontSize, $this->profile);
339        }
340
341}
342
343
344?>
Note: See TracBrowser for help on using the repository browser.