[6779] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Copyright DHTMLX LTD. http://www.dhtmlx.com |
---|
| 4 | */ |
---|
| 5 | |
---|
| 6 | class 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 | if(isset($GLOBALS['e'])) |
---|
| 192 | { |
---|
| 193 | $this->today = (string) $scales->attributes()->today . " - " |
---|
| 194 | . (string) $GLOBALS['e']; |
---|
| 195 | } |
---|
| 196 | else |
---|
| 197 | { |
---|
| 198 | $this->today = (string) $scales->attributes()->today; |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | switch ($this->mode) { |
---|
| 202 | case 'week': |
---|
| 203 | foreach ($scales->x->column as $text) { |
---|
| 204 | $this->topScales[] = (string) $text; |
---|
| 205 | } |
---|
| 206 | foreach ($scales->row as $text) { |
---|
| 207 | $week = explode("|", $text); |
---|
| 208 | $this->dayHeader[] = $week; |
---|
| 209 | } |
---|
| 210 | break; |
---|
| 211 | case 'month': |
---|
| 212 | foreach ($scales->x->column as $text) { |
---|
| 213 | $this->topScales[] = (string) $text; |
---|
| 214 | } |
---|
| 215 | foreach ($scales->row as $text) { |
---|
| 216 | $week = explode("|", $text); |
---|
| 217 | $this->dayHeader[] = $week; |
---|
| 218 | } |
---|
| 219 | break; |
---|
| 220 | |
---|
| 221 | case 'year': |
---|
| 222 | foreach ($scales->month as $month) { |
---|
| 223 | $monthArr = Array(); |
---|
| 224 | $monthArr['label'] = (string) $month->attributes()->label; |
---|
| 225 | foreach ($month->column as $col) { |
---|
| 226 | $monthArr['columns'][] = (string) $col; |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | foreach ($month->row as $row) { |
---|
| 230 | $row = explode("|", $row); |
---|
| 231 | $monthArr['rows'][] = $row; |
---|
| 232 | } |
---|
| 233 | $this->yearValues[] = $monthArr; |
---|
| 234 | } |
---|
| 235 | break; |
---|
| 236 | |
---|
| 237 | case 'agenda': |
---|
| 238 | $this->agendaHeader[0] = (string) $scales->column[0]; |
---|
| 239 | $this->agendaHeader[1] = (string) $scales->column[1]; |
---|
| 240 | break; |
---|
| 241 | |
---|
| 242 | case 'day': |
---|
| 243 | foreach ($scales->x->column as $col) { |
---|
| 244 | $this->columnHeader[] = (string) $col; |
---|
| 245 | } |
---|
| 246 | foreach ($scales->y->row as $row) { |
---|
| 247 | $this->rowHeader[] = (string) $row; |
---|
| 248 | } |
---|
| 249 | default: |
---|
| 250 | return false; |
---|
| 251 | } |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | |
---|
| 255 | // parses events from xml |
---|
| 256 | private function renderEvents($xml) { |
---|
| 257 | $this->events = Array(); |
---|
| 258 | switch ($this->mode) { |
---|
| 259 | case 'month': |
---|
| 260 | foreach ($xml->event as $ev) { |
---|
| 261 | $event['week'] = (int) $ev->attributes()->week - 1; |
---|
| 262 | $event['day'] = (int) $ev->attributes()->day; |
---|
| 263 | $event['x'] = (int) $ev->attributes()->x; |
---|
| 264 | $event['y'] = (int) $ev->attributes()->y; |
---|
| 265 | $event['width'] = (int) $ev->attributes()->width; |
---|
| 266 | $event['height'] = (int) $ev->attributes()->height; |
---|
| 267 | $event['type'] = (string) $ev->attributes()->type; |
---|
| 268 | $event['text'] = (string) $ev->body; |
---|
| 269 | $event['color'] = (string) $ev->body->attributes()->color; |
---|
| 270 | $this->events[] = $event; |
---|
| 271 | } |
---|
| 272 | break; |
---|
| 273 | case 'week': |
---|
| 274 | foreach ($xml->event as $ev) { |
---|
| 275 | $event['week'] = (int) $ev->attributes()->week; |
---|
| 276 | $event['day'] = (int) $ev->attributes()->day; |
---|
| 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['type'] = (string) $ev->attributes()->type; |
---|
| 282 | $event['text'] = (string) $ev->body; |
---|
| 283 | $event['color'] = (string) $ev->body->attributes()->color; |
---|
| 284 | $this->events[] = $event; |
---|
| 285 | } |
---|
| 286 | break; |
---|
| 287 | case 'year': |
---|
| 288 | foreach ($xml->event as $ev) { |
---|
| 289 | $week = (int) $ev->attributes()->week; |
---|
| 290 | $day = (int) $ev->attributes()->day; |
---|
| 291 | $month = (int) $ev->attributes()->month; |
---|
| 292 | $this->events[] = $month.'_'.$week.'_'.$day; |
---|
| 293 | } |
---|
| 294 | break; |
---|
| 295 | case 'agenda': |
---|
| 296 | foreach ($xml->event as $ev) { |
---|
| 297 | $head = (string) $ev->head; |
---|
| 298 | $body = (string) $ev->body; |
---|
| 299 | $this->events[] = Array('head' => $head, 'body' => $body); |
---|
| 300 | } |
---|
| 301 | break; |
---|
| 302 | case 'day': |
---|
| 303 | foreach ($xml->event as $ev) { |
---|
| 304 | $event['head'] = (string) $ev->header; |
---|
| 305 | $event['body'] = (string) $ev->body; |
---|
| 306 | $event['x'] = (int) $ev->attributes()->x; |
---|
| 307 | $event['y'] = (int) $ev->attributes()->y; |
---|
| 308 | $event['width'] = (int) $ev->attributes()->width; |
---|
| 309 | $event['height'] = (int) $ev->attributes()->height; |
---|
| 310 | $event['color'] = (string) $ev->body->attributes()->color; |
---|
| 311 | $this->events[] = $event; |
---|
| 312 | } |
---|
| 313 | } |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | |
---|
| 317 | private function printMonth() { |
---|
| 318 | $this->wrapper->drawMonthHeader($this->orientation, $this->topScales, $this->monthHeaderHeight, $this->bgColor, $this->lineColor, $this->monthHeaderFontSize); |
---|
| 319 | $this->wrapper->drawToday($this->today, $this->todayFontSize); |
---|
| 320 | $this->wrapper->drawMonthGrid($this->dayHeader, $this->monthDayHeaderHeight, $this->dayHeaderColor, $this->dayBodyColor, $this->dayHeaderColorInactive, $this->dayBodyColorInactive, $this->monthDayHeaderFontSize); |
---|
| 321 | $this->wrapper->drawMonthEvents($this->events, $this->eventColor, $this->eventBorderColor, $this->monthEventFontSize, $this->profile); |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | |
---|
| 325 | private function printYear() { |
---|
| 326 | $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); |
---|
| 327 | $this->wrapper->drawToday($this->today, $this->todayFontSize); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | |
---|
| 331 | private function printAgenda() { |
---|
| 332 | $this->wrapper->drawAgenda($this->agendaHeader, $this->events, $this->agendaRowHeight, $this->bgColor, $this->lineColor, $this->scaleColorOne, $this->scaleColorTwo, $this->agendaFontSize, $this->today, $this->todayFontSize); |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | |
---|
| 336 | private function printDayWeek() { |
---|
| 337 | $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); |
---|
| 338 | $this->wrapper->drawToday($this->today, $this->todayFontSize); |
---|
| 339 | $this->wrapper->drawDayWeekEvents($this->events, $this->eventColor, $this->eventBorderColor, $this->dayEventHeaderFontSize, $this->dayEventBodyFontSize, $this->profile); |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | private function printWeek() { |
---|
| 343 | $this->wrapper->drawWeekHeader($this->orientation, $this->topScales, $this->monthHeaderHeight, $this->bgColor, $this->lineColor, $this->monthHeaderFontSize); |
---|
| 344 | $this->wrapper->drawToday($this->today, $this->todayFontSize); |
---|
| 345 | $this->wrapper->drawWeekGrid($this->dayHeader, $this->monthDayHeaderHeight, $this->dayHeaderColor, $this->dayBodyColor, $this->dayHeaderColorInactive, $this->dayBodyColorInactive, $this->monthDayHeaderFontSize); |
---|
| 346 | $this->wrapper->drawWeekEvents($this->events, $this->eventColor, $this->eventBorderColor, $this->monthEventFontSize, $this->profile); |
---|
| 347 | } |
---|
| 348 | |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | |
---|
| 352 | ?> |
---|