Guest

SteffenR

By: a guest on Apr 28th, 2010  |  syntax: PHP  |  size: 3.96 KB  |  hits: 328  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. /*
  2.  * Themed output to display monthperline
  3.  */
  4. function theme_availability_calendars_node_line($node, $year = 2008, $month = 1, $monthstodisplay = 24) {
  5.  
  6.   drupal_add_css(drupal_get_path('module', 'availability_calendars') .'/availability_calendars.css');
  7.   $rows = array();
  8.   // Fill availability array
  9.   /* foreach ($node->availability_dates as $k => $v) {
  10.     foreach ($v as $i) {
  11.       $booked[date("Y", $i['date'])][date("m", $i['date'])][date("d", $i['date'])] = 1;
  12.     }
  13.   } */
  14.   // Calendar code based on example at http://evolt.org/node/60673 :
  15.   $day = 1;
  16.  //$startofweek = variable_get('availability_calendars_'. $node->nid .'_startofweek', 1);
  17.   // Montag als Start der Woche
  18.   $startofweek = 6;
  19.  
  20.   $monthsremaining = $monthstodisplay;
  21.   while ($monthsremaining > 0) {
  22.         /*
  23.          * Ausgabe der Tage für Kalender in Line-Ausgabe
  24.          */
  25.         if($monthsremaining==$monthstodisplay && $year==date("Y")) {
  26.                 $output .= "<p style=\"clear:left\"></p>
  27.                 <table class=\"cal_neu\">";
  28.                 $output .= "<tr>";
  29.                 for($yy=0;$yy<=31;$yy++) {
  30.                         if($yy==0) {
  31.                                 $output .= "<td class=\"year_strong\">".$year."</td>";
  32.                         }
  33.                         else {
  34.                                 $output .= "<td class=\"days\">".$yy."</td>";
  35.                         }
  36.                 }
  37.                 $output .= "</tr>";
  38.                 /*
  39.                 $output .= "<tr>";
  40.                 $output .= "<td colspan=32 class=\"year\">".$year."</td>";
  41.                 $output .= "</tr>";
  42.                 */
  43.                 $output .= "</table>";
  44.         }
  45.  
  46.         //$output .= theme('availability_calendars_line', $node, $year, $month, $startofweek, $booked);
  47.     $output .= theme_availability_calendars_line( $node, $year, $month, $startofweek, $booked);
  48.     $monthsremaining--;
  49.     $month++;
  50.     if ($month > 12) {
  51.       $month = 1;
  52.       $year++;
  53.  
  54.       $output .= "<table class=\"cal_neu\">";
  55.       $output .= "<tr>";
  56.           $output .= "<td class=\"year_strong\" >".$year."</td>";
  57.       for($yy=1;$yy<=31;$yy++) {
  58.                 $output .= "<td class=\"days\">".$yy."</td>";
  59.           }
  60.           $output .= "</tr>";
  61.           $output .= "</table>";
  62.  
  63.  
  64.     }
  65.   }
  66.   return $output;
  67. }
  68.  
  69. /*
  70.  * theme for month/line
  71.  */
  72. function theme_availability_calendars_line($node, $year, $month, $startofweek, $booked,$extra) {
  73.   $month_meta = availability_calendars_month_meta($year, $month, $startofweek);
  74.  
  75.   // read Day Status
  76.   $status_result = db_query('SELECT day, status FROM {availability_calendars_day}
  77.                                                         WHERE nid = %d AND year = %d AND month = %d', $node, $year, $month);
  78.   while ($status = db_fetch_array($status_result)) {
  79.         $day_status[$status['day']] = $status['status'];
  80.   }
  81.   // get current day
  82.   if($month == date("m") && $year == date("Y")) {
  83.         $day_status[date("j")] = 4;
  84.   }
  85.   //$availability_calendars_options = availability_calendars_options();
  86.   $output  = "<table class='cal_neu'><tr>\n";
  87.  // $output  .= "<td class=\"month_name\">". t("@date", array('@date' => format_date(mktime(12, 0, 0, $month, 1, $year), 'custom', 'F Y')))."</td>\n";
  88.   if($extra!='nomonth') {
  89.         $output  .= "<td class=\"monthname\">". t("@date", array('@date' => format_date(mktime(12, 0, 0, $month, 1, $year), 'custom', 'F')))."</td>\n";
  90.   }
  91.   for($xx=1;$xx<=$month_meta['daysinmonth'];$xx++) {
  92.         if($extra!='nomonth' || $node==0 )
  93.                 $xx_day = format_date(mktime(12, 0, 0, $month, $xx, $year), 'custom', 'D');
  94.         else {
  95.                 $xx_day = format_date(mktime(12, 0, 0, $month, $xx, $year), 'custom', 'j');
  96.         }
  97.  
  98.         if ($day_status[$xx] == 0) {
  99.                 $output .= " <td class='calavailable day'>". $xx_day ."</td>\n";
  100.         }
  101.         elseif ($day_status[$xx] == 1) {
  102.                 $output .= " <td class='calnotavailable day'>". $xx_day ."</td>\n";
  103.         }
  104.     elseif ($day_status[$xx] == 2) {
  105.                 $output .= " <td class='calnotavailableprov day'>". $xx_day ."</td>\n";
  106.         }
  107.     elseif ($day_status[$xx] == 3) {
  108.                 $output .= " <td class='calarrivaldeparture day'>". $xx_day ."</td>\n";
  109.         }
  110.     elseif ($day_status[$xx] == 4) {
  111.                 $output .= " <td class='caltoday day'>". $xx_day ."</td>\n";
  112.         }
  113.    else {
  114.                 $output .= " <td class='calotherday day'>". $xx_day ."</td>\n";
  115.         }
  116.   }
  117.   $output  .="</tr></table>";
  118.   return $output;
  119. }