Looking throught the complex calendars out there, i decided to write my own. But, i came across a problem, for which i cannot see the cause.
function display_calendar() {
global $member_ID, $main_contents, $table_border_color, $g_id;
global $year, $month, $day;
//Check if the form was submitted
if($year == '' && $month == '') {
//nope, so generate the date today
$today = date("Y-m-d");
list($year, $month, $day) = split("-", $today);
}
//how many days in this month?
$days_in_month = cal_days_in_month("", $month, $year); //Array of month data, bases on first day, 2nd is last day $stamp_begin = mktime("0", "0", "0", $month, "1", $year); $stamp_end = mktime("0", "0", "0", $month, $days_in_month, $year);
//make the arrays $date_begin = getdate($stamp_begin); $date_end = getdate($stamp_end); //print_r(get_defined_vars());
$main_contents .= '<table border="1" bordercolor="' . $table_border_color . '" cellspacing="0">'; $main_contents .= '<tr class="1">'; $main_contents .= '<td align="center" colspan="7">'; $main_contents .= 'My Calendar'; $main_contents .= '</td>'; $main_contents .= '</tr>'; $main_contents .= '<tr class="t_white">'; $main_contents .= '<td align="center">'; $main_contents .= '<b>Monday</b>'; $main_contents .= '</td>';
$main_contents .= '<td align="center">'; $main_contents .= '<b>Tuesday</b>'; $main_contents .= '</td>';
$main_contents .= '<td align="center">'; $main_contents .= '<b>Wednesday</b>'; $main_contents .= '</td>';
$main_contents .= '<td align="center">'; $main_contents .= '<b>Thursday</b>'; $main_contents .= '</td>';
$main_contents .= '<td align="center">'; $main_contents .= '<b>Friday</b>'; $main_contents .= '</td>';
$main_contents .= '<td align="center">'; $main_contents .= '<b>Saturday</b>'; $main_contents .= '</td>';
$main_contents .= '<td align="center">'; $main_contents .= '<b>Sunday</b>'; $main_contents .= '</td>';
$main_contents .= '</tr>';
//initilise the count
$count = '0';
for($i1=0;$i1<5;$i1++) {
$main_contents .= '<tr class="t_1">';
for($i2=0;$i2<7;$i2++) {
if((($i1 == '0') && ($date_begin['wday']-1 > $i2)) || ($count > $days_in_month)) { $main_contents .= '<td>'; $main_contents .= ' '; $main_contents .= '</td>'; $count++; } else {
//Build this date $d = sprintf("%02.0f", $i2 + ($i1 7)); $m = $month; $y = $year; $when = $y . '-' . $m . '-' . $d; $meetings = ''; $res = mysql_query("SELECT FROM calendar_dates WHERE ((owner='$member_ID') OR (involved='$member_ID')) AND date_on='$when' AND type='confirmed'"); if(mysql_num_rows($res) != '0') { while($row = mysql_fetch_assoc($res)) { $meetings .= '<br>' . $row['time_at']; } } $main_contents .= '<td>'; if($i1 != '0') { $main_contents .= $i2 + ($i1 * 7); } else { $main_contents .= $i2; } $main_contents .= $meetings; $main_contents .= '</td>'; $count++; } } $main_contents .= '</tr>'; } $main_contents .= '<form name="change_date" action="?action=calendar" method="post">'; $main_contents .= '<tr class="t_1">'; $main_contents .= '<td colspan="7">'; $main_contents .= 'Re-calculate for: '; $main_contents .= '<select name="month">'; $months[1] = 'January'; $months[2] = 'February'; $months[3] = 'March'; $months[4] = 'April'; $months[5] = 'May'; $months[6] = 'June'; $months[7] = 'July'; $months[8] = 'August'; $months[9] = 'September'; $months[10] = 'October'; $months[11] = 'November'; $months[12] = 'December'; foreach($months as $key => $val) { if($key == $month) { $main_contents .= '<option value="' . $key . '" selected>' . $val . '</option>'; } else { $main_contents .= '<option value="' . $key . '">' . $val . '</option>'; } } $main_contents .= '</select>'; $main_contents .= '<select name="year">';
When this runs, for year 2003.
January starts on the 2nd
February on the 5th
March on the 5th
April on the 1st
May on 3rd
June on 0
July on 1st
August on 4th
September on 0
October on 2nd
November on 5th
December on 0
But i cant see why it produces the wrong names. Can anyone offer any advice on this
TIA