Service Area Calendar:

'' and date_format(sdate,'%Y-%m') = '$yrmo' order by sdate"; //echo $query; $result=give_msg($query,Sel); while($row=mysqli_fetch_array($result)) { $eday= substr($row[sdate],8,2); // get day from date $eday=abs($eday); // convert days like '01' to '1' $eventaray[$eday][day] = $eday; $eventaray[$eday][headline] = $row[headline]; $eventaray[$eday][event] = $row[event]; //echo "Day $eday
"; //echo "Headline $row[headline]
"; //echo "Event $row[event]
"; } return $eventaray; } // Get the first day of the month $month_start = mktime(0,0,0,$month, 1, $year); // Get friendly month name $month_name = date('M', $month_start); // Get month number $month_number = $year."-".date('m', $month_start); // call function for events $eventaray=getmonthevents($month_number); // Figure out which day of the week // the month starts on. $month_start_day = date('D', $month_start); //echo "Date $month_start_day"; switch($month_start_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; } // determine how many days are in the last month. if($month == 1){ // $num_days_last = cal_days_in_month(0, 12, ($year -1)); for newer php ver $num_days_last = date("t",mktime(0,0,0,$month,-1,$year)); //maybe needed for older php ver? } else { // $num_days_last = cal_days_in_month(0, ($month -1), $year); for newer php ver $num_days_last = date("t",mktime(0,0,0,$month,1,$year)); // needed for older php ver? } // determine how many days are in the current month. //$num_days_current = cal_days_in_month(0, $month, $year); // For newer php ver $num_days_current = date("t",mktime(0,0,0,$month,1,$year)); // needed for older php ver? // Build an array for the current days // in the month for($i = 1; $i <= $num_days_current; $i++){ $num_days_array[] = $i; } // Build an array for the number of days // in last month for($i = 1; $i <= $num_days_last; $i++){ $num_days_last_array[] = $i; } // If the $offset from the starting day of the // week happens to be Sunday, $offset would be 0, // so don't need an offset correction. 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); } // The else statement is to prevent building the $offset array. else { $offset_count = 0; $new_count = $num_days_array; } // count how many days we have with the two // previous arrays merged together $current_num = count($new_count); // Since we will have 5 HTML table rows (TR) // with 7 table data entries (TD) // we need to fill in 35 TDs // so, we will have to figure out // how many days to append to the end // of the final array to make it 35 days. if($current_num > 35){ $num_weeks = 6; $outset = (42 - $current_num); } elseif($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[] = $i; } // Now let's "chunk" the $all_days array // into weeks. Each week has 7 days // so we will array_chunk it into 7 days. $weeks = array_chunk($new_count, 7); // Build Previous and Next Links $previous_link = "<< Prev"; $next_link = "Next >>"; // Build the heading portion of the calendar table echo "\n". "\n". "\n". "\n". "\n". "\n"; // Now we break each key of the array // into a week and create a new table row for each // week with the days of that week in the table data $i = 0; foreach($weeks AS $week){ echo "\n"; foreach($week as $d) { if($i < $offset_count) { echo "\n"; // don't show anything for nonmonthdays } if(($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset)){ $headline=$eventaray[$d][headline]; ///echo "Headline: $headline
"; $dd=$eventaray["$d"][event]; $dd=urlencode($dd); // encode the event data $dd=str_replace('%0D','
',$dd); // replace the CR with br $dd=str_replace('%0A','',$dd); // replace the LF with blank $dd=urldecode($dd); // un-encode the event data for viewing if($date == mktime(0,0,0,$month,$d,$year)) { // if todays date ///echo "\n"; // don't show anything for nonmonthdays } } $i++; } // end foreach week as d echo "\n"; } // end foreach week as week // Close out your table and that's it! //echo ''; echo '
\n". "\n". "\n". "\n". "\n". "\n". "\n". "
$previous_link$month_name $year$next_link
\n". "
S
M
T
W
T
F
S
. $dd
\n"; echo "
$dd
\n"; ?> $dd
\n"; echo "
$dd
\n"; ?> 0)) { // nonmonthdays if(($i >= ($num_weeks * 7) - $outset)){ $day_link = "$d"; echo "
.
 
'; ?>