function calendar_render_mini_calendar

6.x calendar.module calendar_render_mini_calendar($month, $year, $faculty_user_id, $event_type_cid = 0, $available_slots = array())
1 call to calendar_render_mini_calendar()
calendar_display_schedule_appointment_page in modules/calendar/calendar.module
This is the page which lets students schedule an appointment with the faculty member supplied in the user_id.

File

modules/calendar/calendar.module, line 2505

Code

function calendar_render_mini_calendar($month, $year, $faculty_user_id, $event_type_cid = 0, $available_slots = array()) {

  $today_num = intval(date('j', convert_time(time())));
  $today_month = intval(date('n', convert_time(time())));
  $today_year = intval(date('Y', convert_time(time())));

  $day_name_length = 3;
  $first_day = 0;


  $month_ts = convert_time(strtotime("$year-$month-01 07:01:01")); // get us into the correct month.

  $month_title = date('M', $month_ts) . " $year";

  $month_year = $month . "_$year";


  $first_of_month = mktime(0, 0, 0, $month, 1, $year);
  // remember that mktime will automatically correct if invalid dates are entered
  // for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
  // this provides a built in "rounding" feature

  $day_names = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');


  list($month, $year, $month_name, $weekday) = explode(',', strftime('%m, %Y, %B, %w', $first_of_month));
  $weekday = ($weekday + 7 - $first_day) % 7; //adjust for $first_day

  // Make sure they are integers.
  $month = intval($month);
  $year = intval($year);



  $prev_month = $month - 1;
  $prev_year = $year;
  if ($prev_month < 1) {
    $prev_month = 12;
    $prev_year--;
  }

  $prev_url = fp_url("schedule-appointment/$faculty_user_id", "stage=2&event_type_cid=$event_type_cid&month_year=$prev_month" . "_" . "$prev_year");
  $prev = '<span class="calendar-prev"><a href="' . $prev_url . '">&laquo; ' . t('Prev') . '</a></span>';

  // If we are already on TODAY's month and year, then there should be no Prev link at all.
  if ($month == date('m') && $year == date('Y')) {
    $prev = "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;";
  }


  $next_month = $month + 1;
  $next_year = $year;
  if ($next_month > 12) {
    $next_month = 1;
    $next_year++;
  }

  $next_url = fp_url("schedule-appointment/$faculty_user_id", "stage=2&event_type_cid=$event_type_cid&month_year=$next_month" . "_" . "$next_year");

  $next = '<span class="calendar-next"><a href="' . $next_url . '">' . t("Next") . ' &raquo;</a></span>';

  // TODO:  limit future months/dates based on settings?  Ex: don't let the user go past 3 months.


  $top_text = '<caption class="calendar-month">' . $prev . "<span class='month-title'>$month_title</span>" . $next . "</caption>";




  $calendar = "<div class='calendar-mini-calendar'>
                                
                <table class='mini-calendar'>
                  $top_text
                  <tr class='day-names'>";

  if ($day_name_length) 
   { //if the day names should be shown ($day_name_length > 0)
    //if day_name_length is >3, the full name of the day will be printed
    foreach ($day_names as $d) {
      $calendar .= '<th class="mini-day-of-week" abbr="' . htmlentities($d) . '">' . htmlentities($day_name_length < 4 ? substr($d, 0, $day_name_length) : $d) . '</th>';
    }
    $calendar .= "</tr>
                      <tr class='week'>";
  }

  if ($weekday > 0) {
    for ($i = 0; $i < $weekday; $i++) {
      $calendar .= "<td class='empty-day'>&nbsp;</td>"; //initial 'empty' days
    }
  }

  /////////////////////////////////////////////////////
  // Begin to output the actual days in the month.
  $days_in_month = date('t', $first_of_month);
  for ($day = 1; $day <= $days_in_month; $day++, $weekday++) {

    $disp_day = $day;

    if ($weekday == 7) {
      $weekday = 0; //start a new week
      $calendar .= "</tr>
                         <tr class='week'>";
    }

    $extra = "";
    if ($day === intval($today_num) && $month == $today_month && $year == $today_year) {
      $extra .= " mini-day-today";
    }


    // has the date already passed? 
    if ($day < $today_num && $month == $today_month && $year == $today_year) {
      $extra .= " mini-past-date";
    }
    else {
      // We are on track to being able to make this a link!

      $disp_day = $day;

      // is the faculty member available?  If so, make it a link
      if (isset($available_slots [$year][$month][$day]) && is_array($available_slots [$year][$month][$day]) && count($available_slots [$year][$month][$day]) > 0) {
        $disp_day = l($day, "schedule-appointment/$faculty_user_id", "month_year=$month_year&stage=3&day=$day&event_type_cid=$event_type_cid");
      }



    } // else






    $calendar .= "<td class='mini-day $extra'>$disp_day</td>";



  }
  //////////////////////////////////////////////////////


  // We are finished, but if we didn't end on the last day of the month,
  // we need to fill in the remaining table cells with an empty td.  
  if ($weekday != 7) {
    $calendar .= '<td class="empty-day empty-day-multi" id="emptydays" colspan="' . (7 -$weekday) . '">&nbsp;</td>'; //remaining "empty" days
  }

  // Time to close up!
  $calendar .= "</tr>
                </table>
                </div>";

  return $calendar;
}