Lessons Calendar

Click on any highlighted day for a message about lessons on that day.
Use the previous (<) and next (>) arrows to change months.

", mysqli_connect_error()); exit(); } //print "Connected to server
"; mysqli_select_db($conn, $db_name); if ($result = mysqli_query($conn, "SELECT DATABASE()")) { $row = mysqli_fetch_row($result); //printf("Database is %s.
", $row[0]); mysqli_free_result($result); } else { printf("Query failed: %s
", mysqli_connect_error()); exit(); } $m = $_GET['month']; if (!$m) { $m = strftime('%m'); } $y = $_GET['year'] ; if (!$y) { $y = strftime('%Y'); } pc_calendar($conn, $m,$y); mysqli_close($conn); function pc_calendar ($dbconn, $month, $year, $opts='') { if (! is_array($opts)) { $opts = array(); } // if (! isset($opts['today_color'])) { $opts['today_color'] = '#fff'; } $opts['month_link'] = '%s'; list($this_month, $this_year, $this_day) = explode(',',strftime('%m,%Y,%d')); $day_highlight = (($this_month == $month) && ($this_year == $year)); list($prev_month, $prev_year) = explode(',',strftime('%m,%Y',mktime(0,0,0,$month-1,1,$year))); $prev_month_link = sprintf($opts['month_link'],$prev_month,$prev_year,'Previous','<'); list($next_month, $next_year) = explode(',',strftime('%m,%Y',mktime(0,0,0,$month+1,1,$year))); $next_month_link = sprintf($opts['month_link'],$next_month,$next_year,'Next','>'); print ''; print ''; $holidays = array(); $totaldays = date('t',mktime(0,0,0,$month,1,$year)); $result = mysqli_query($dbconn, "SELECT * FROM datemsg"); if ($result) { //printf("Select returned %d rows.
", mysqli_num_rows($result)); while ($row = mysqli_fetch_array($result)) { $date = $row{'date'}; $msg = $row{'msg'}; list($y,$m,$d) = explode('-',$date); $holidays[$date] = rtrim($msg); } } else { //print "No results
"; } // print out days of the week print ''; $weekdays = array('Su','Mo','Tu','We','Th','Fr','Sa'); while ( list($k,$v) = each($weekdays)) { print ""; } print "\n\n"; // align the first day of the month with the right week day $day_offset = date("w",mktime(0,0,0,$month,1,$year)); if ( $day_offset > 0 ) { for ($i=0; $i < $day_offset; $i++) { print ''; } } $yesterday = time() - 86400; $zmonth = str_pad($month, 2, '0', STR_PAD_LEFT); // print out the days for ($day=1; $day <= $totaldays; $day++) { $zday = str_pad($day, 2, '0', STR_PAD_LEFT); $day_secs = mktime(0,0,0,$month,$day,$year); $class = ''; $script = ''; $title = ''; if ($day_offset == 0) { $class = 'sunday'; $script='nosunlesson()'; $title = ' Sunday - No lesson '; } else { $zdate = "$year-$zmonth-$zday"; if ($holidays[$zdate]) { $title = $holidays[$zdate]; $script = "alert('$title')"; if ( preg_match('/no lesson/i',$title) ) { $class = 'nolesson'; } else { $class = 'special'; } } } /* if ($day_secs >= $yesterday) { if ($day_highlight && ($day == $this_day)) { $class .= ' today'; } } */ if ($script) { print sprintf('',$class,$script,$title,$day); } else { print sprintf('',$class,$day); } print "\n"; $day_offset++; // start a new row each week if ($day_offset == 7) { $day_offset = 0; if ($day < $totaldays) { print "\n\n"; } } } // fill in the last week with blanks if ($day_offset > 0) { $day_offset = 7 - $day_offset; } if ($day_offset > 0) { for ($i=0; $i < $day_offset; $i++) { print ''; } } print '
'; print $prev_month_link; print ''; print strftime('%B %Y',mktime(0,0,0,$month,1,$year)); print ''; print $next_month_link; print '
$v
 %d%d
 
'; } ?>
Contact Speedy for questions regarding the lesson schedule.