Välj vy: Lista | Dag | Vecka | Månad | År     Visa dagens aktiviteter    Lägg till aktivitet  


<% include_once "locale.php"; include_once "calendarhelper.php"; include_once "urlhelper.php"; include_once "formatters/calendarviewitem.php"; /** * @package formatter */ class CalendarView extends CLObject { var $days = array(); var $month; var $prevURL; var $nextURL; var $baseURL = "index.htm"; var $calendars = array(); var $showNextPrevButtons = true; var $stylePrefix; function CalendarView($d=0) { if (!$d) $d = time(); $this->setDate($d); } function getStylePrefix() { return $this->stylePrefix; } function getNextURL() { return $this->nextURL; } function getPreviousURL() { return $this->prevURL; } function setShowNextPrevButtons($bool) { $this->showNextPrevButtons = $bool; } function setDate($d) { $this->date = $d; $arr = getdate($d); $this->year = $arr["year"]; $this->month = $arr["mon"]; $this->day = $arr["mday"]; } function setBaseURL($url) { $this->baseURL = $url; } function setCalendars($arr) { if (!is_array($arr)) $arr = array(); $this->calendars = $arr; } function makeURL($arr, $url=null) { if (!$url) $url = $this->baseURL; $url = URLHelper::addParameterArray($url, $arr); include_once "arrayhelper.php"; $cals = implode(" ", $this->calendars); if (is_string($cals)) $cals=array($cals); else $cals=ArrayHelper::trim($cals); $cats = $_REQUEST["cats"]; if (is_string($cats)) $cats=array($cats); else $cats=ArrayHelper::trim($cats); if (sizeof($cals) && $cals[0]) $url = URLHelper::addParameterArray($url, array("cals" => implode(" ", $cals))); if (sizeof($cats) && $cats[0]) $url = URLHelper::addParameterArray($url, array("cats" => implode(" ", $cats))); return $url; } function addDayItem(&$day) { $this->days[ $day->getKey() ] = &$day; $this->setDate($day->getDate()); } function &getDayItem($year, $month="", $day="") { if ($month && $day) $date = CalendarHelper::makeDate($year,$month,$day); else $date = CalendarHelper::makeDate($this->year, $this->month, $year); $key = date("Ymd", $date); $day = &$this->days[$key]; if (!$day) { $day = new CalendarViewDay($date); $this->days[$key] = &$day; } return $day; } function &getDayItems() { return $this->days; } function &getItemsAsSet() { $set = ObjectFactory::create("BasicSet"); $set->addArray($this->getItems()); return $set; } function &getItems() { $allItems = array(); reset($this->days); while ($day = current($this->days)) { $allItems = array_merge($allItems, $day->getItems()); next($this->days); } return $allItems; } function addItem(&$item) { $day = &$this->days[$item->getKey()]; if (!$day) { $day = new CalendarViewDay($item->getDate()); $this->addDayItem($day); } $day->addItem($item); } function getMonthName() { $t = CalendarHelper::makeDate(date("Y"),$this->month,1); return strftime("%B", $t); } } /** * @package formatter */ class YearView extends CalendarView { var $className = "YearView"; function calcURLs() { $prevYear = $this->year - 1; $nextYear = $this->year + 1; $this->prevURL = $this->makeURL(array("date" => CalendarHelper::formatDate($prevYear, 1, 1))); $this->nextURL = $this->makeURL(array("date" => CalendarHelper::formatDate($nextYear, 1, 1))); } function headerAsHTML() { $this->calcURLs(); $prevURL = $this->prevURL; $nextURL = $this->nextURL; $stylePrefix = $this->stylePrefix; echo ""; echo " "; echo ""; } function footerAsHTML() { echo "
"; if ($this->showNextPrevButtons) { echo ""; echo ""; echo ""; } echo " "; echo $this->year; echo " "; if ($this->showNextPrevButtons) { echo ""; echo ""; echo ""; } echo "
"; } function asHTML() { $arr = getdate($this->date); $year = $arr["year"]; $this->headerAsHTML(); $view = new TinyMonthView; $view->setBaseURL($this->baseURL); $view->setCalendars($this->calendars); $view->setShowNextPrevButtons(false); $view->days = &$this->days; $col = 1; for ($month = 1; $month <= 12; $month++) { $view->setDate(CalendarHelper::makeDate($year,$month,1)); echo ""; $view->asHTML(); echo ""; $col++; if ($col == 5) { $col = 1; if ($month != 12) echo " "; } else echo "   "; } $this->footerAsHTML(); } } /** * @package formatter */ class MonthView extends CalendarView { var $className = "MonthView"; var $stylePrefix = "cal"; function calcURLs() { $thisYear = $this->year; $thisMonth = $this->month; $prevYear = $nextYear = $this->year; $prevMonth = $nextMonth = $this->month; if ($this->month == 1) { $nextMonth++; $prevMonth = 12; $prevYear--; } else if ($this->month == 12) { $nextMonth = 1; $prevMonth--; $nextYear++; } else { $nextMonth++; $prevMonth--; } $this->prevURL = $this->makeURL(array("date" => CalendarHelper::formatDate($prevYear, $prevMonth, 1))); $this->nextURL = $this->makeURL(array("date" => CalendarHelper::formatDate($nextYear, $nextMonth, 1))); $this->thisURL = $this->makeURL(array("view" => "m", "date" => CalendarHelper::formatDate($thisYear, $thisMonth, 1))); } function getThisURL() { return $this->thisURL; } function getWeekdayLabels() { $l = TEXT("/calendar/weekdayNames"); $l = array_values($l); return $l; } function headerAsHTML() { $prevURL = $this->prevURL; $nextURL = $this->nextURL; $thisURL = $this->thisURL; $stylePrefix = $this->stylePrefix; echo "
"; echo ""; echo " "; echo ""; $l = $this->getWeekdayLabels(); echo "\n"; if ($this->showWeek) echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo "\n"; } function footerAsHTML() { echo "
"; if ($this->showNextPrevButtons) { echo ""; echo ""; echo ""; } echo " "; echo ""; echo ucfirst($this->getMonthName($this->month)); echo " ", $this->year; echo ""; echo " "; if ($this->showNextPrevButtons) { echo ""; echo ""; echo ""; } echo "
 ". $l[0]. "". $l[1]. "". $l[2]. "". $l[3]. "". $l[4]. "". $l[5]. "". $l[6]. "
"; echo "
\n"; } function asHTML() { if (!isset($this->showWeek)) $this->showWeek = $this->getProperty("showWeekNumber", true); $this->calcURLs(); $this->headerAsHTML(); $firstdate = CalendarHelper::getFirstDateInMonth($this->date); $lastdate = CalendarHelper::getLastDateInMonth($this->date); $wd=date("w", $firstdate); if ($wd==0) $wd=7; $cur = (-$wd) + 1; $lastday=date("d", $lastdate); for ($k=0; $k < 6; $k++) { echo "\n"; $curDate = CalendarHelper::getFirstDateInWeek($firstdate + ($k * WEEKSECONDS)); if ($this->showWeek) { $weekViewURL = $this->makeURL(array("view" => "w", "date" => CalendarHelper::formatDate($curDate))); $weekNumber = CalendarHelper::getWeekNumber($curDate); $class = $this->stylePrefix . "Week"; echo ""; echo "$weekNumber"; } for ($i=0; $i < 7; $i++) { $cur++; if (($cur <= 0 ) || ($cur > $lastday) ) $this->oneDayAsHTML(false); else $this->oneDayAsHTML($cur); } echo "\n"; if ($cur >= $lastday) { break; } } $this->footerAsHTML(); } function oneDayAsHTML($mday) { if ($mday !== false) $day = $this->getDayItem($mday); global $config; if ($config["components"] && $config["components"]["calendar"] && $config["components"]["calendar"]["hideRecurring"]) $hideRecurring = true; else $hideRecurring = false; if ($day) { if ($day->isSunday) $class=$this->stylePrefix . "Sunday"; else $class=$this->stylePrefix . "Day"; if ($day->hasItems()) $class .= "Active"; if ($day->isToday()) $class .= "Current"; $items = $day->getItems(); reset($items); $dayURL = $this->makeURL(array("view" => "d", "date" => CalendarHelper::formatDate($day->getDate()))); $s = ""; $s .= "$mday"; $s .= ""; $title = ""; $recurCount = $nonRecurCount = 0; while ($item = current($items)) { $url = $item->getURL(); $label = $item->getLabel(); if (!$label) $label = "??"; $shortLabel = $label; if (strlen($label) > 12) $shortLabel = substr($label,0,12) . ".."; if (!$hideRecurring || !$item->isRecurring()) { if ($s) $s .= "
"; $s .= $shortLabel; $nonRecurCount++; } else $recurCount++; if ($title) $title .= " "; $title .= $label; next($items); } if ($recurCount) { $s .= "
"; if ($nonRecurCount) $s .= "+ "; $fmt = TEXT("/calendar/view/recurringItemCount"); $s .= sprintf($fmt, $recurCount); } } else { $class = $this->stylePrefix . "EmptyDay"; $s = " "; } echo ""; echo "
$s
"; echo ""; } } /** * @package formatter */ class TinyMonthView extends MonthView { var $className = "TinyMonthView"; var $stylePrefix = "tCal"; function mkinitial(&$item1, $key) { $item1 = $item1[0]; } function getWeekdayLabels() { $l = TEXT("/calendar/weekdayNames"); if (!$l || !is_array($l)) $l = array("?", "?", "?", "?", "?", "?", "?"); else $l = array_values($l); if (is_array($l)) array_walk ($l, array($this,'mkinitial')); return $l; } function oneDayAsHTML($mday) { if ($mday !== false) $day = $this->getDayItem($mday); if ($day) { if ($day->isSunday) $class=$this->stylePrefix . "Sunday"; else $class=$this->stylePrefix . "Day"; if ($day->hasItems()) $class .= "Active"; if ($day->isToday()) $class .= "Current"; $d = CalendarHelper::makeDate($this->year, $this->month, $mday); $href = $this->makeURL(array("view" => "d", "date" => CalendarHelper::formatDate($d))); $s = "$mday"; // $s = sprintf("%d", // $href,$this->year,$this->month,$mday,$mday); } else { $class = $this->stylePrefix . "EmptyDay"; $s = " "; } echo ""; echo "
$s
"; echo ""; } } /** * @package formatter */ class WeekView extends CalendarView { var $className = "WeekView"; var $viewItemURL = "view.htm"; var $stylePrefix = "week"; function calcURLs() { $prevDate = $this->date - (7 * 24 * 60 * 60); $nextDate = $this->date + (7 * 24 * 60 * 60); $this->prevURL = $this->makeURL(array("date" => CalendarHelper::formatDate($prevDate))); $this->nextURL = $this->makeURL(array("date" => CalendarHelper::formatDate($nextDate))); } function asHTML() { $this->calcURLs(); $darr = getdate($this->date); $wday = $darr["wday"]; if ($wday == 0) $wday = 7; $style = $this->stylePrefix; $fromdate = CalendarHelper::getFirstDateInWeek($this->date); %>
<% if ($this->showNextPrevButtons) { echo ""; echo ""; echo ""; } $fmt = TEXT("/calendar/format/weekNumberLong"); %> <%printf($fmt, CalendarHelper::getWeekNumber($this->date)) %> <% if ($this->showNextPrevButtons) { echo ""; echo ""; echo ""; } %>
<% for ($wday = 0; $wday < 7; $wday++) { $date = ($fromdate + ($wday * DAYSECONDS)); $this->dayAsHTML($date); } %>
<% } function dayAsHTML($date) { $arr = getdate($date); $dayViewURL = $this->makeURL(array("view" => "d", "date" => CalendarHelper::formatDate($date))); $dayItem = $this->getDayItem($arr["year"], $arr["mon"], $arr["mday"]); $items = $dayItem->getItems(); $rowspan = 1; if ($items && sizeof($items) > 1) $rowspan = sizeof($items); $isFirst = true; reset($items); for ($row = 1; $row <= $rowspan; $row++): %> <% if ($isFirst): $fmt = TEXT("/calendar/format/dayLong"); %> <%=strftime($fmt, $date)%>  <% $isFirst = false; endif; $item = current($items); next($items); if ($item) { $s = ""; $ID = $item->getID(); $label = $item->getLabel(); if (!$label) $label = "??"; if ($item->isAllDay()) $itemTime = "* "; else { $h = $item->getHour(); $m = $item->getMinute(); $itemTime = sprintf("%02d:%02d ", $h, $m); } } %> <%= $itemTime %>  <% if ($item) { $url = $this->makeURL(array("ID" => $ID), $this->viewItemURL); echo "$label"; } %>
  <% endfor; } } /** * @package formatter */ class DayView extends CalendarView { var $className = "DayView"; var $viewItemURL = "view.htm"; var $stylePrefix = "day"; function calcURLs() { $prevDate = $this->date - (24 * 60 * 60); $nextDate = $this->date + (24 * 60 * 60); $this->prevURL = $this->makeURL(array("date" => CalendarHelper::formatDate($prevDate))); $this->nextURL = $this->makeURL(array("date" => CalendarHelper::formatDate($nextDate))); } function itemsAsHTML(&$items) { reset($items); while ($item = current($items)) { $s = ""; $ID = $item->getID(); $url = $this->makeURL(array("ID" => $ID), $this->viewItemURL); $label = $item->getLabel(); if (!$label) $label = "??"; if ($url) $s .= "$label"; else $s .= $label; echo $s, "
"; next($items); } } function asHTML() { $this->calcURLs(); $di = $this->getDayItem($this->day); $items = $di->getItems(); $style = $this->stylePrefix; %>
<% if ($this->showNextPrevButtons) { echo ""; echo ""; echo ""; } %> <%= CalendarHelper::formatDate($this->date) %> <% if ($this->showNextPrevButtons) { echo ""; echo ""; echo ""; } %>
<% $from = CalendarHelper::setTime($this->date, 0, 0, 0); $to = $from + DAYSECONDS; $items = $di->getAllDayItems(); if (sizeof($items) > 0) { echo ""; echo ""; echo ""; echo ""; } while ($from < $to) { echo ""; echo ""; echo ""; echo ""; $from += HOURSECONDS; } %>
*"; $this->itemsAsHTML($items); echo "
"; echo date("H:i", $from); echo "   "; $items = $di->getItemsInRange($from, $from + HOURSECONDS - 1); $this->itemsAsHTML($items); echo "
<% } } /** * @package formatter */ class ListView extends CalendarView { var $className = "ListView"; var $viewItemURL = "view.htm"; var $stylePrefix = "list"; function calcURLs() { $prevDate = $this->date - (7 * 24 * 60 * 60); $nextDate = $this->date + (7 * 24 * 60 * 60); $this->prevURL = $this->makeURL(array("date" => CalendarHelper::formatDate($prevDate))); $this->nextURL = $this->makeURL(array("date" => CalendarHelper::formatDate($nextDate))); } function asHTML() { $this->calcURLs(); $darr = getdate($this->date); $wday = $darr["wday"]; if ($wday == 0) $wday = 7; $style = $this->stylePrefix; $fromdate = CalendarHelper::getFirstDateInWeek($this->date); %>
<% if ($this->showNextPrevButtons) { echo ""; echo ""; echo ""; } $fmt = TEXT("/calendar/format/weekNumberLong"); %> <%printf($fmt, CalendarHelper::getWeekNumber($this->date)) %> <% if ($this->showNextPrevButtons) { echo ""; echo ""; echo ""; } %>
<% for ($wday = 0; $wday < 7; $wday++) { $date = ($fromdate + ($wday * DAYSECONDS)); $this->dayAsHTML($date); } %>
<% } function dayAsHTML($date) { $arr = getdate($date); $dayViewURL = $this->makeURL(array("view" => "d", "date" => CalendarHelper::formatDate($date))); $dayItem = $this->getDayItem($arr["year"], $arr["mon"], $arr["mday"]); $items = $dayItem->getItems(); $rowspan = 1; if ($items && sizeof($items) > 1) $rowspan = sizeof($items); $isFirst = true; reset($items); for ($row = 1; $row <= $rowspan; $row++): %> <% if ($isFirst): $fmt = TEXT("/calendar/format/dayLong"); %> <%=strftime($fmt, $date)%>  <% $isFirst = false; endif; $item = current($items); next($items); if ($item) { $s = ""; $ID = $item->getID(); $label = $item->getLabel(); if (!$label) $label = "??"; if ($item->isAllDay()) $itemTime = "* "; else { $h = $item->getHour(); $m = $item->getMinute(); $itemTime = sprintf("%02d:%02d ", $h, $m); } } %> <%= $itemTime %>  <% if ($item) { $url = $this->makeURL(array("ID" => $ID), $this->viewItemURL); echo "$label"; } %>
  <% endfor; } } /** * @package formatter */ class ItemView extends CalendarView { var $className = "ItemView"; function asHTML() { $items = $this->getItems(); reset($items); while ($item = current($items)) { $v = $item->getValues(); echo "
";
		  print_r($v);
		  echo "
"; next($items); } } } /** * @package formatter */ class FormatterView extends CalendarView { var $className = "FormatterView"; function setupTemplate($q1, $q2=null, $q3=null) { $this->formatter = FormatterFactory::create("CalendarViewItem", $q1, $q2, $q3); } function asHTML() { $items = $this->getItemsAsSet(); $this->formatter->setEntitySet($items); $this->formatter->asHTML(); } } %>