Improvements
[infodrom.org/oldenburg.linux.de] / src / Termine / years.inc
1 <:
2   use Time::Local;
3
4   @month = ('dummy','Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember');
5   @day = ('Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag');
6
7   # Monat - Jahr
8   $layout_month = '<div style="padding-top: 10px;"></div>\
9 <table class="dates" width="100%%" border="0" cellpadding="0" cellspacing="0">\
10 <tr><th align="left" colspan="2" bgcolor="#80CCF8"><strong>&nbsp;%s %d</strong></th>\
11 <td align="left" bgcolor="#80CCF8">Ort</td>\
12 <td align="center" bgcolor="#80CCF8">Zeit</td>\
13 </tr>';
14   # bgcol Tag (Tag) - Text - Ort - Zeit
15   $layout_row = '\
16 <tr bgcolor=#%s>\
17   <td align=left width=20%%>&nbsp;%d. (%s)</td>\
18   <td align=left width=60%%>%s</td>\
19   <td align=left width=15%%>%s</td>\
20   <td align=right width=5%%>%s&nbsp;</td>\
21 </tr>';
22   $layout_foot = '\
23 </table>';
24   @layout_color = ('ffffff','eff0f1');
25 :>
26
27 <define-tag more_years>
28 <:
29
30   my @y;
31   my $max = (localtime(time))[5]+1900;
32   foreach my $year (2000..$max) {
33     next unless -f $year . '.wml';
34     push (@y, sprintf ("<a href=\"%s.%s\">%s</a>",
35     $year, $year >= 2008?"php":"html", $year))
36       if ($year ne "<get-var WML_SRC_BASENAME>");
37   }     
38   printf "<p>Vergangene Termine in %s</p>\n", join (", ", @y);
39 :>
40 </define-tag>
41
42 <define-tag build_tables>
43 <:
44   $mon = 0;
45   $year = (split (/-/, (split (/\|/, (sort (@termine))[0]))[0]))[0];
46   $descr = "";
47   $day = 0;
48   $color = $layout_color[1];
49   foreach $termin (sort (@termine)) {
50     @termin = split (/\|/, $termin);
51     @date = split (/-/, $termin[0]);
52
53     if ($mon ne "$date[0]-$date[1]") {
54       if ($mon != 0) {
55         print $layout_foot;
56         $descr = "";
57         $day = 0;
58         $color = $layout_color[1];
59         print "<p><hr>" if ($year != $date[0]);
60         $year = $date[0];
61       }
62       printf $layout_month, $month[$date[1]], $date[0];
63       $mon = "$date[0]-$date[1]";
64     }
65     if ($termin[2] ne $descr || $date[2] != $day+1) {
66       $color = $color eq $layout_color[0]?$layout_color[1]:$layout_color[0];
67       $descr = $termin[2];
68     }
69     $day = $date[2];
70     if ($termin[4]) {
71       $text = sprintf ("<a href=\"%s\">%s</a>", $termin[4], $termin[2]);
72     } else {
73       $text = $termin[2];
74     }
75     $wday = (localtime(timelocal(0,0,0,$date[2],$date[1]-1, $date[0])))[6];
76
77     printf $layout_row, $color, $date[2], $day[$wday], $text, $termin[3], $termin[1];
78   }
79   print $layout_foot;
80
81 :>
82 </define-tag>
83
84 <define-tag php_utils>
85 <?
86 function readdb($datedb)
87 {
88   $dates = array();
89
90   if (($db = fopen($datedb,'r')) !== false) {
91     $lines = array();
92     while (!feof($db)) {
93       $line = fgets($db, 200);
94
95       if (!preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})\|/", $line))
96         continue;
97
98       $dates[] = $line;
99     }
100   }
101   return $dates;
102 }
103
104 function display_dates($past=false)
105 {
106   global $dates;
107
108 <protect>
109   $layout_head = '<div style="padding-top: 10px;"></div>'
110                 .'<table class="dates" width="100%%" border="0" cellpadding="0" cellspacing="0">'
111                 .'<tr class="head"><th align="left" colspan="2"><strong>&nbsp;%s</strong></th>'
112                 .'<td align="left">Ort</td>'
113                 .'<td align="center">Zeit</td>'
114                 .'</tr>';
115   $layout_row = '<tr class="%s">'
116                .'<td align=left width=20%%>&nbsp;%d. (%s)</td>'
117                .'<td align=left width=60%%>%s</td>'
118                .'<td align=left width=15%%>%s</td>'
119                .'<td align=right width=5%%>%s&nbsp;</td>'
120                .'</tr>';
121 </protect>
122   $layout_foot = '</table>';
123
124   $nowstring = date("Y-m-d");
125   $today = mktime(0,0,0, date('m'), date('d'), date('Y'));
126
127   sort($dates);
128   $cmon = false;
129   foreach ($dates as $line) {
130     if (($past == false && $line < $nowstring) ||
131         ($past == true && $line > $nowstring))
132       continue;
133
134     if (preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})\|([^\|]*)\|[^\|]*\|([^\|]*)\|([^\|]*)\|(.*)/", $line, $match)) {
135
136       $when = mktime(0,0,0, $match[2], $match[3], $match[1]);
137
138       if ($match[1] !== $thisyear || $match[2] !== $thismonth) {
139         if ($cmon)
140           echo $layout_foot;
141         $thisyear = $match[1];
142         $thismonth = $match[2];
143         printf($layout_head, strftime("%B %Y", $when));
144         $cmon = true;
145       }
146       if (strlen($match[7]))
147         $title = '<a href="' . $match[7] . '">' . $match[5] . '</a>';
148       else
149         $title = $match[5];
150
151       if ($when == $today)
152         $class = 'today';
153       else
154         $class = ($class == 'row0'?'row1':'row0');
155
156       printf($layout_row, $class, $match[3], strftime("%A", $when), $title, $match[6], $match[4]);
157     }
158   }
159   if ($cmon)
160     echo $layout_foot;
161 }
162 ?>
163 </define-tag>
164
165 # Local variables:
166 # mode: indented-text
167 # mode: auto-fill
168 # end: