Difference between revisions of "Calendar.php"

From Organic Design wiki
(Make main cal table into "calendar" class)
(CSS class xwCalendar and xwToday, removed all hardwired styles!)
Line 5: Line 5:
 
$thisDay = date('d');
 
$thisDay = date('d');
 
$thisMonth = date('n');
 
$thisMonth = date('n');
$c = ' style="font-size:8pt"';
 
 
if ( !$d = date( 'w', $ts = mktime( 0, 0, 0, $m, 1, $y) ) ) $d = 7;
 
if ( !$d = date( 'w', $ts = mktime( 0, 0, 0, $m, 1, $y) ) ) $d = 7;
 
$month = date( 'F', $ts );
 
$month = date( 'F', $ts );
$article = "<table border=0><tr><th colspan=7$c><h3>$month</h3>\n<tr>";
+
$article = "<table><tr><th colspan=7><h3>$month</h3>\n<tr>";
$article .= "<th$c>M<th$c>T<th$c>W<th$c>T<th$c>F<th$c>S<th$c>S\n";
+
$article .= "<th>M<th>T<th>W<th>T<th>F<th>S<th>S\n";
 
if ( $d > 1 ) $article .= '<tr>'.str_repeat( '<td>', $d-1 );
 
if ( $d > 1 ) $article .= '<tr>'.str_repeat( '<td>', $d-1 );
 
for ( $i = $day = $d; $day < 32; $i++ ) {
 
for ( $i = $day = $d; $day < 32; $i++ ) {
Line 16: Line 15:
 
if ( $day < 29 or checkdate( $m, $day, $y ) ) {
 
if ( $day < 29 or checkdate( $m, $day, $y ) ) {
 
if ( $i%7 == 1 ) $article .= "\n<tr>";
 
if ( $i%7 == 1 ) $article .= "\n<tr>";
$t = ( $day == $thisDay and $m == $thisMonth ) ? ' bgcolor=white' : '';
+
$t = ( $day == $thisDay and $m == $thisMonth ) ? ' class=xwToday' : '';
$article .= "<td$t$c><b>&nbsp;[[$prefix$day $month $y|$day]]&nbsp;</b>";
+
$article .= "<td$t>&nbsp;[[$prefix$day $month $y|$day]]&nbsp;";
 
}
 
}
 
}
 
}
Line 28: Line 27:
  
 
# Append the article content with a table of all the month-tables
 
# Append the article content with a table of all the month-tables
$article .= "<table class=calendar border=0 cellpadding=5 cellspacing=5><tr><td>\n<tr>";
+
$article .= "<table class=xwCalendar><tr><td>\n<tr>";
 
$m = 1;
 
$m = 1;
 
$y = date( 'Y' );
 
$y = date( 'Y' );
 
for ( $rows = 3; $rows--; $article .= "\n<tr>" )
 
for ( $rows = 3; $rows--; $article .= "\n<tr>" )
 
for ( $cols = 0; $cols < 4; $cols++ )
 
for ( $cols = 0; $cols < 4; $cols++ )
$article .= "\n<td valign=top style='border:groove 2px #eeeeee'>".month( $m++, $y, $p );
+
$article .= "\n<td>".month( $m++, $y, $p );
 
$article .= '</table>';
 
$article .= '</table>';
  
 
?>
 
?>

Revision as of 23:09, 7 March 2006

<?

  1. Return a calendar table of the passed month and year

function month( $m, $y, $prefix = ) { $thisDay = date('d'); $thisMonth = date('n'); if ( !$d = date( 'w', $ts = mktime( 0, 0, 0, $m, 1, $y) ) ) $d = 7; $month = date( 'F', $ts );

$article = "

"; $article .= "'.str_repeat( '"; $t = ( $day == $thisDay and $m == $thisMonth ) ? ' class=xwToday' : ; $article .= "<td$t> $day "; } } $article .= "\n

$month

\n
MTWTFSS\n"; if ( $d > 1 ) $article .= '
', $d-1 );

for ( $i = $day = $d; $day < 32; $i++ ) { $day = $i - $d + 1; $day = $day < 10 ? "0$day" : $day; if ( $day < 29 or checkdate( $m, $day, $y ) ) {

if ( $i%7 == 1 ) $article .= "\n

";

return $article; }

  1. Use everything before "Calendar" in name as prefix

$p = preg_replace( '/calendar.*$/i', , $title );

  1. Append the article content with a table of all the month-tables

$article .= "

";

$m = 1; $y = date( 'Y' );

for ( $rows = 3; $rows--; $article .= "\n" ) for ( $cols = 0; $cols < 4; $cols++ ) $article .= "\n
\n
".month( $m++, $y, $p ); $article .= '

';

?>