ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

calendar.php
Go to the documentation of this file.
1 <?php
2
3 /*
4 * This source code is a part of the Ultimix Project.
5 * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6 * it's own license wich could be found from the corresponding files or sources.
7 * This source code is provided "as is" without any warranties or garanties.
8 *
9 * Have a nice day!
10 *
11 * @url http://ultimix.sorceforge.net
12 *
13 * @author Alexey "gdever" Dodonov
14 */
15
26 class calendar_1_0_0
27 {
28
39 var $CachedMultyFS = false;
40 var $Security = false;
41
52 function __construct()
53 {
54 try
55 {
56 $this->CachedMultyFS = get_package_object( 'cached_multy_fs' , 'last' , __FILE__ );
57 $this->Security = get_package( 'security' , 'last' , __FILE__ );
58 }
59 catch( Exception $e )
60 {
61 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
62 }
63 }
64
83 function pre_generation( &$Options )
84 {
85 try
86 {
87 $PackagePath = _get_package_relative_path_ex( 'gui::calendar' , 'last' );
88 $PageCSS = get_package( 'page::page_css' , 'last' , __FILE__ );
89 $PageCSS->add_stylesheet( "{http_host}/$PackagePath/res/css/calendar.css" );
90 }
91 catch( Exception $e )
92 {
93 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
94 }
95 }
96
115 function get_templates()
116 {
117 try
118 {
119 //TODO: refactor it to get_templates( $TemplateNames )
120 return(
121 array(
122 $this->CachedMultyFS->get_template( __FILE__ , 'calendar_start.tpl' ) ,
123 $this->CachedMultyFS->get_template( __FILE__ , 'calendar_end.tpl' ) ,
124 $this->CachedMultyFS->get_template( __FILE__ , 'calendar_row_start.tpl' ) ,
125 $this->CachedMultyFS->get_template( __FILE__ , 'calendar_row_end.tpl' ) ,
126 $this->CachedMultyFS->get_template( __FILE__ , 'calendar_header_cell.tpl' ) ,
127 $this->CachedMultyFS->get_template( __FILE__ , 'calendar_cell.tpl' )
128 )
129 );
130 }
131 catch( Exception $e )
132 {
133 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
134 }
135 }
136
171 private function compile_header_cell( $DisplayTime , $Template , $Text , $Day )
172 {
173 try
174 {
175 $Template = str_replace( '{header_cell}' , $Text , $Template );
176
177 $FirstDay = mktime( 0 , 0 , 0 , date( 'n', $DisplayTime ) , 1 , date( 'Y' , $DisplayTime ) );
178 $w = date( 'w' , $FirstDay );
179 $w = $w == 0 ? 6 : $w - 1;
180
181 $Class = $w == $Day && date( 'd' ) < 7 - $w ? ' active_cell_bottom' : '';
182
183 $Template = str_replace( '{active_cell_bottom}' , $Class , $Template );
184
185 return( $Template );
186 }
187 catch( Exception $e )
188 {
189 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
190 }
191 }
192
223 private function compile_header_cells( $DisplayTime , $HeaderCell , $HolidayHeaderCell )
224 {
225 try
226 {
227 return(
228 $this->compile_header_cell( $DisplayTime , $HeaderCell , '{lang:mon}' , 1 ).
229 $this->compile_header_cell( $DisplayTime , $HeaderCell , '{lang:tue}' , 2 ).
230 $this->compile_header_cell( $DisplayTime , $HeaderCell , '{lang:wed}' , 3 ).
231 $this->compile_header_cell( $DisplayTime , $HeaderCell , '{lang:thr}' , 4 ).
232 $this->compile_header_cell( $DisplayTime , $HeaderCell , '{lang:fri}' , 5 ).
233 $this->compile_header_cell( $DisplayTime , $HolidayHeaderCell , '{lang:sat}' , 6 ).
234 $this->compile_header_cell( $DisplayTime , $HolidayHeaderCell , '{lang:sun}' , 0 )
235 );
236 }
237 catch( Exception $e )
238 {
239 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
240 }
241 }
242
265 function compile_header( $DisplayTime )
266 {
267 try
268 {
269 list( $CalendarStart , $CalendarEnd , $RowStart , $RowEnd , $HeaderCell , $Cell ) =
270 $this->get_templates();
271
272 $HolidayHeaderCell = str_replace( '{holiday}' , ' holiday' , $HeaderCell );
273
274 return(
275 $RowStart.$this->compile_header_cells( $DisplayTime , $HeaderCell , $HolidayHeaderCell ).$RowEnd
276 );
277 }
278 catch( Exception $e )
279 {
280 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
281 }
282 }
283
306 function get_toolbar( $DisplayTime )
307 {
308 try
309 {
310 $Code = $this->CachedMultyFS->get_template( __FILE__ , 'calendar_toolbar.tpl' );
311
312 $MonthYear = date( 'm} Y' , $DisplayTime );
313
314 $MonthPrev = strtotime( '-1 month' , $DisplayTime );
315 $Code = str_replace(
316 '{toolbar}' , "{href:page=?calendar_time[eq]$MonthPrev;text=month_prev}{toolbar}" , $Code
317 );
318
319 $Code = str_replace(
320 '{toolbar}' , " {lang:month_name_$MonthYear {toolbar}" , $Code
321 );
322
323 $MonthNext = strtotime( '+1 month' , $DisplayTime );
324 $Code = str_replace( '{toolbar}' , "{href:page=?calendar_time[eq]$MonthNext;text=month_next}" , $Code );
325
326 return( $Code );
327 }
328 catch( Exception $e )
329 {
330 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
331 }
332 }
333
356 private function compile_cell_class( $CellDay )
357 {
358 try
359 {
360 $ThisDay = date( 'Y-m-d' ) == date( 'Y-m-d' , $CellDay );
361 $ThisMonth = date( 'Y-m' ) == date( 'Y-m' , $CellDay );
362
363 $Class = $ThisDay ? ' active_cell' : '';
364
365 $NextWeekDay = date( 'j' ) == date( 'j' , $CellDay ) + 7;
366 $Class = $ThisMonth && $NextWeekDay ? ' active_cell_bottom' : $Class;
367
368 $NextDay = date( 'j' ) == date( 'j' , $CellDay ) + 1;
369 $Class = $ThisMonth && $NextDay ? ' active_cell_right' : $Class;
370
371 return( $Class );
372 }
373 catch( Exception $e )
374 {
375 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
376 }
377 }
378
405 private function compile_cell( $Day , $CellDay )
406 {
407 try
408 {
409 list( $CalendarStart , $CalendarEnd , $RowStart , $RowEnd , $HeaderCell , $Cell ) =
410 $this->get_templates();
411
412 $Code = '';
413
414 $Code .= $Day % 7 === 1 ? $RowStart : '';
415 $Code .= str_replace( '{day}' , $CellDay , $Cell );
416
417 $DayOfWeek = date( 'w' , $CellDay );
418
419 $Code = $DayOfWeek == 0 || $DayOfWeek == 6 ? str_replace( '{holiday}' , ' holiday' , $Code ) : $Code;
420 $Class = $this->compile_cell_class( $CellDay );
421 $Code = str_replace( '{active_cell}' , $Class , $Code );
422 $Code .= $Day % 7 === 0 ? $RowEnd : '';
423
424 return( $Code );
425 }
426 catch( Exception $e )
427 {
428 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
429 }
430 }
431
462 private function compile_rows( $DisplayTime , $DayOfWeek , $FirstDay , $DisplayTime )
463 {
464 try
465 {
466 list( $CalendarStart , $CalendarEnd , $RowStart , $RowEnd , $HeaderCell , $Cell ) =
467 $this->get_templates();
468
469 $Code = '';
470
471 for( $Day = 1 ; $Day <= 42 ; $Day++ )
472 {
473 $DayAdd = $Day - $DayOfWeek;
474 $CellDay = strtotime( $DayAdd < 0 ? $DayAdd.' day' : "+$DayAdd day" , $FirstDay );
475 $Code .= $this->compile_cell( $Day , $CellDay );
476
477 if( date( 'm' , $CellDay ) !== date( 'm' , $DisplayTime ) && $Day % 7 === 0 )
478 {
479 break;
480 }
481 }
482
483 return( $Code );
484 }
485 catch( Exception $e )
486 {
487 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
488 }
489 }
490
513 function compile_calendar( &$Settings )
514 {
515 try
516 {
517 $DisplayTime = $this->Settings->get_setting( 'calendar_time' , time() );
518 $DisplayTime = $this->Security->get_gp( 'calendar_time' , 'integer' , $DisplayTime );
519
520 list( $Start , $End , $RowStart , $RowEnd , $HeaderCell , $Cell ) =
521 $this->get_templates();
522
523 $FirstDay = mktime( 0 , 0 , 0 , date( 'n', $DisplayTime ) , 1 , date( 'Y' , $DisplayTime ) );
524
525 $Code = $Start.$this->get_toolbar( $DisplayTime );
526 $Code .= $this->compile_header( $DisplayTime );
527
528 $DayOfWeek = date( 'w' , $FirstDay );
529 $Code .= $this->compile_rows( $DisplayTime , $DayOfWeek , $FirstDay , $DisplayTime );
530
531 return( $Code.$End );
532 }
533 catch( Exception $e )
534 {
535 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
536 }
537 }
538
561 function view( &$Options )
562 {
563 try
564 {
565 if( $Options->get_setting( 'calendar' , false ) )
566 {
567 $CalendarTime = $this->Security->get_gp( 'calendar_time' , 'integer' , false );
568 $this->Output = $this->compile_calendar( $CalendarTime );
569 }
570
571 return( $this->Output );
572 }
573 catch( Exception $e )
574 {
575 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
576 }
577 }
578 }
579
580 ?>