Anyway, here is my code...
<?php
class Ajax_Calendar
{
/*
* Define custom callback functions (optional)
*/
# using a callback function like this is optional
public function day_details($y, $m, $d)
{
# blank cells before day 1 or after day 30/31
if ($day == '') {
echo ' '; # for IE table cells
}
echo "$d";
if ($m == 1 and $d == 1) {
echo "<br/><em>New Year's Day!</em>";
}
}
function link_to_events($year, $month, $day, $date_data)
{
# blank cells before day 1 or after day 30/31
if ($day == '')
echo ' '; # for IE table cells
# Your date_array should tell us how many events are on the given day...
if ('0' < $date_data) {
echo '<a href="/calendar/list_events/' . "$year/$month/$day" . '" class="day_link">' . $day . '</a>';
} else
echo '<div class="day_simple">' . $day . '</div>';
}
public function getPhpAjaxCalendarCore($month, $year, $date_array = NULL, $day_function = null)
{
$current_time = time();
$month_start = mktime(0, 0, 0, $month, 1, $year);
$month_name = date('F', $month_start);
$first_day = date('D', $month_start);
switch ($first_day) {
case "Sun":
$offset = 0;
break;
case "Mon":
$offset = 1;
break;
case "Tue":
$offset = 2;
break;
case "Wed":
$offset = 3;
break;
case "Thu":
$offset = 4;
break;
case "Fri":
$offset = 5;
break;
case "Sat":
$offset = 6;
break;
}
if ($month == 1)
$num_days_last = cal_days_in_month(CAL_GREGORIAN, 12, ($year - 1));
else
$num_days_last = cal_days_in_month(CAL_GREGORIAN, ($month - 1), $year);
$num_days_current = cal_days_in_month(CAL_GREGORIAN, $month, $year);
for ($i = 0; $i < $num_days_current; $i++) {
$num_days_array[] = $i + 1;
}
for ($i = 0; $i < $num_days_last; $i++) {
$num_days_last_array[] = '';
}
if ($offset > 0) {
$offset_correction = array_slice($num_days_last_array, -$offset, $offset);
$new_count = array_merge($offset_correction, $num_days_array);
$offset_count = count($offset_correction);
} else {
$new_count = $num_days_array;
}
$current_num = count($new_count);
if ($current_num > 35) {
$num_weeks = 6;
$outset = (42 - $current_num);
} else if ($current_num < 35) {
$num_weeks = 5;
$outset = (35 - $current_num);
}
if ($current_num == 35) {
$num_weeks = 5;
$outset = 0;
}
// Outset Correction
for ($i = 1; $i <= $outset; $i++) {
$new_count[] = '';
}
$weeks = array_chunk($new_count, 7);
// Start the output buffer so we can output our calendar nicely
ob_start();
$prev_month = $month - 1;
$prev_year = $year;
if ($month == 1) {
$prev_month = 12;
$prev_year = $year - 1;
}
$next_month = $month + 1;
$next_year = $year;
if ($month == 12) {
$next_month = 1;
$next_year = $year + 1;
}
// Build the heading portion of the calendar table
echo <<<EOS
<table class="calendar fluid large-margin-bottom">
<caption>
<a href="?month=$prev_month&year=$prev_year" class="next" id="arrow_left">◄</a>
<a href="?month=$next_month&year=$next_year" class="next" id="arrow_right">►</a>
$month_name $year
</caption>
<thead>
<tr>
<th scope="col">Sun</th>
<th scope="col">Mon</th>
<th scope="col">Tue</th>
<th scope="col">Wed</th>
<th scope="col">Thu</th>
<th scope="col">Fri</th>
<th scope="col">Sat</th>
</tr>
</thead><tbody>
EOS;
foreach ($weeks AS $week) {
echo '<tr class="week">';
foreach ($week as $day) {
if ($day == date('d', $current_time) && $month == date('m', $current_time) && $year == date('Y', $current_time))
echo '<td class="today"><span class="cal-day">';
else
echo '<td><span class="cal-day">';
if (null == $day_function OR empty($date_array[$day])) {
echo $day;
} else {
/* Calls user function from this class,
* Sends appropriate date data from date_array
*/
call_user_func(array(
$this,
$day_function
), $year, $month, $day, $date_array[$day]);
}
echo '</td>';
}
echo '</tr>';
}
echo '</tbody></table>';
return ob_get_clean();
}
}
?>
Every thing works great except the weekend thing, and the fact that I also need to figure out how to set the calendar for my time zone. I'm at UTC/GMT -4 hours.
Anyway, thanks for everyone's help.
This post has been edited by Java Neil: 01 October 2012 - 04:48 PM

New Topic/Question
Reply




MultiQuote





|