You are here

function theme_availability_calendars_month in Availability Calendars 5

Same name and namespace in other branches
  1. 6.2 availability_calendars.page.inc \theme_availability_calendars_month()
  2. 6 availability_calendars.module \theme_availability_calendars_month()
  3. 7.2 availability_calendars.page.inc \theme_availability_calendars_month()
1 theme call to theme_availability_calendars_month()
theme_availability_calendars_node in ./availability_calendars.module
Themed output to display a lits of node dates.

File

./availability_calendars.module, line 311
Availability Calendars Module

Code

function theme_availability_calendars_month($node, $year, $month, $startofweek, $booked) {
  $month_meta = availability_calendars_month_meta($year, $month, $startofweek);
  for ($j = 0; $j < $month_meta['weeksinmonth']; $j++) {
    for ($i = 0; $i < 7; $i++) {
      $counter++;
      $week[$j][$i] = $counter;

      // offset the days
      $week[$j][$i] -= $month_meta['firstday'];
      if ($week[$j][$i] < 1 || $week[$j][$i] > $month_meta['daysinmonth']) {
        $week[$j][$i] = "";
      }
    }
  }
  $output = "<table class='cal'>\n";
  $output .= "<tr class='calmonth'>\n";
  $output .= "<th colspan='8'>" . t("@date", array(
    '@date' => format_date(mktime(12, 0, 0, $month, 1, $year), 'custom', 'F Y'),
  ));
  if (user_access('edit availability calendars')) {
    $output .= ' ' . l('edit', 'availability-calendars/' . $node->nid . '/' . date('Y/m', mktime(0, 0, 0, $month, 1, $year)) . '/edit', NULL, 'destination=node/' . $node->nid);
  }
  $output .= "</th>\n";
  $output .= "</tr>\n";

  /*  $days = array(
        6 => array("M", "Mon", "Monday"),
        5 => array("T", "Tue", "Tuesday"),
        4 => array("W", "Wed", "Wednesday"),
        3 => array("T", "Thu", "Thursday"),
        2 => array("F", "Fri", "Friday"),
        1 => array("S", "Sat", "Saturday"),
        0 => array("S", "Sun", "Sunday"),
      );

   // Figure out how to generate the header - see archive.module in 4.7
    $output .= "<tr class='caldays'>\n";
    $output .= "<th></th>\n";
    $output .= "<th>S</th>\n";
    $output .= "<th>S</th>\n";
    $output .= "<th>M</th>\n";
    $output .= "<th>T</th>\n";
    $output .= "<th>W</th>\n";
    $output .= "<th>T</th>\n";
    $output .= "<th>F</th>\n";
    $output .= "</tr>\n";
   */

  // find all entries in database for this month ($availability, $notes) and pre-populate
  $notes_result = db_query('SELECT week, note FROM {availability_calendars_week} WHERE nid = %d AND year = %d AND month = %d', $node->nid, $year, $month);
  while ($note = db_fetch_array($notes_result)) {
    $notes[$note['week']] = $note['note'];
  }
  $status_result = db_query('SELECT day, status FROM {availability_calendars_day} WHERE nid = %d AND year = %d AND month = %d', $node->nid, $year, $month);
  while ($status = db_fetch_array($status_result)) {
    $day_status[$status['day']] = $status['status'];
  }
  $availability_calendars_options = availability_calendars_options();
  foreach ($week as $key => $val) {
    $weeknumber = $key + 1;
    $output .= "<tr class='calweek'>\n";
    $output .= "<td class='calnote'>" . $notes[$weeknumber] . "</td>\n";
    for ($i = 0; $i < 7; $i++) {

      // if there's a date, it's part of this month
      if ($week[$key][$i]) {
        if ($day_status[$week[$key][$i]] == 1) {

          // booked
          $output .= " <td class='calnotavailable'>" . $week[$key][$i] . "</td>\n";
        }
        elseif ($day_status[$week[$key][$i]] == 2) {

          // provisionally booked
          $output .= " <td class='calnotavailableprov'>" . $week[$key][$i] . "</td>\n";
        }
        else {

          // available
          $output .= " <td class='calavailable'>" . $week[$key][$i] . "</td>\n";
        }
      }
      else {
        $output .= " <td class='calothermonth'>" . $number . "</td>\n";
      }
    }
    $output .= "</tr>\n";
  }
  if ($weeknumber == 5) {
    $output .= "<tr>\n";
    $output .= "<td colspan='8'>&nbsp;</td>\n";
    $output .= "</tr>\n";
  }
  $output .= "</table>";
  return $output;
}