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

Revision 4001, 10.1 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1615 - Componente novo para 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 = 'L';
82                                $this->wrapper = new pdfWrapper($this->offsetTop, $this->offsetRight, $this->offsetBottom, $this->offsetLeft, $this->orientation);
83                                $this->printDayWeek();
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 'month':
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                               
204                        case 'year':
205                                foreach ($scales->month as $month) {
206                                        $monthArr = Array();
207                                        $monthArr['label'] = (string) $month->attributes()->label;
208                                        foreach ($month->column as $col) {
209                                                $monthArr['columns'][] = (string) $col;
210                                        }
211                                       
212                                        foreach ($month->row as $row) {
213                                                $row = explode("|", $row);
214                                                $monthArr['rows'][] = $row;
215                                        }
216                                        $this->yearValues[] = $monthArr;
217                                }
218                                break;
219                       
220                        case 'agenda':
221                                $this->agendaHeader[0] = (string) $scales->column[0];
222                                $this->agendaHeader[1] = (string) $scales->column[1];
223                                break;
224
225                        case 'day':
226                        case 'week':
227                                foreach ($scales->x->column as $col) {
228                                        $this->columnHeader[] = (string) $col;
229                                }
230                                foreach ($scales->y->row as $row) {
231                                        $this->rowHeader[] = (string) $row;
232                                }
233                        default:
234                                return false;
235                }
236        }
237
238
239        // parses events from xml
240        private function renderEvents($xml) {
241                $this->events = Array();
242                switch ($this->mode) {
243                        case 'month':
244                                foreach ($xml->event as $ev) {
245                                        $event['week'] = (int) $ev->attributes()->week - 1;
246                                        $event['day'] = (int) $ev->attributes()->day;
247                                        $event['x'] = (int) $ev->attributes()->x;
248                                        $event['y'] = (int) $ev->attributes()->y;
249                                        $event['width'] = (int) $ev->attributes()->width;
250                                        $event['height'] = (int) $ev->attributes()->height;
251                                        $event['type'] = (string) $ev->attributes()->type;
252                                        $event['text'] = (string) $ev->body;
253                                        $event['color'] = (string) $ev->body->attributes()->color;
254                                        $this->events[] = $event;
255                                }
256                                break;
257                        case 'year':
258                                foreach ($xml->event as $ev) {
259                                        $week = (int) $ev->attributes()->week;
260                                        $day = (int) $ev->attributes()->day;
261                                        $month = (int) $ev->attributes()->month;
262                                        $this->events[] = $month.'_'.$week.'_'.$day;
263                                }
264                                break;
265                        case 'agenda':
266                                foreach ($xml->event as $ev) {
267                                        $head = (string) $ev->head;
268                                        $body = (string) $ev->body;
269                                        $this->events[] = Array('head' => $head, 'body' => $body);
270                                }
271                                break;
272                        case 'day':
273                        case 'week':
274                                foreach ($xml->event as $ev) {
275                                        $event['head'] = (string) $ev->header;
276                                        $event['body'] = (string) $ev->body;
277                                        $event['x'] = (int) $ev->attributes()->x;
278                                        $event['y'] = (int) $ev->attributes()->y;
279                                        $event['width'] = (int) $ev->attributes()->width;
280                                        $event['height'] = (int) $ev->attributes()->height;
281                                        $event['color'] = (string) $ev->body->attributes()->color;
282                                        $this->events[] = $event;
283                                }
284                }
285        }
286
287
288        private function printMonth() {
289                $this->wrapper->drawMonthHeader($this->orientation, $this->topScales, $this->monthHeaderHeight, $this->bgColor, $this->lineColor, $this->monthHeaderFontSize);
290                $this->wrapper->drawToday($this->today, $this->todayFontSize);
291                $this->wrapper->drawMonthGrid($this->dayHeader, $this->monthDayHeaderHeight, $this->dayHeaderColor, $this->dayBodyColor, $this->dayHeaderColorInactive, $this->dayBodyColorInactive, $this->monthDayHeaderFontSize);
292                $this->wrapper->drawMonthEvents($this->events, $this->eventColor, $this->eventBorderColor, $this->monthEventFontSize, $this->profile);
293        }
294
295
296        private function printYear() {
297                $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);
298                $this->wrapper->drawToday($this->today, $this->todayFontSize);
299        }
300
301
302        private function printAgenda() {
303                $this->wrapper->drawAgenda($this->agendaHeader, $this->events, $this->agendaRowHeight, $this->bgColor, $this->lineColor, $this->scaleColorOne, $this->scaleColorTwo, $this->agendaFontSize, $this->today, $this->todayFontSize);
304        }
305
306
307        private function printDayWeek() {
308                $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);
309                $this->wrapper->drawToday($this->today, $this->todayFontSize);
310                $this->wrapper->drawDayWeekEvents($this->events, $this->eventColor, $this->eventBorderColor, $this->dayEventHeaderFontSize, $this->dayEventBodyFontSize, $this->profile);
311        }
312
313}
314
315
316?>
Note: See TracBrowser for help on using the repository browser.