Remove the tag support; nobody is using it anymore.
[pr0n] / perl / Sesse / pr0n / Index.pm
1 package Sesse::pr0n::Index;
2 use strict;
3 use warnings;
4
5 use Sesse::pr0n::Common qw(error dberror);
6 use POSIX;
7
8 sub handler {
9         my $r = shift;
10         my $dbh = Sesse::pr0n::Common::get_dbh();
11
12         my ($event, $abspath, $datesort);
13         if ($r->path_info =~ /^\/\+all\/?/) {
14                 $event = '+all';
15                 $abspath = 1;
16
17                 $datesort = 'DESC NULLS LAST';
18         } else {
19                 # Find the event
20                 $r->path_info =~ /^\/([a-zA-Z0-9-]+)\/?$/
21                         or return error($r, "Could not extract event");
22                 $event = $1;
23                 $abspath = 0;
24                 $datesort = 'ASC NULLS LAST';
25         }
26
27         # Fix common error: pr0n.sesse.net/event -> pr0n.sesse.net/event/
28         if ($r->path_info !~ /\/$/) {
29                 my $res = Plack::Response->new(301);
30                 $res->header('Location' => $r->path_info . "/");
31                 return $res;
32         }
33
34         # Internal? (Ugly?) 
35         if (Sesse::pr0n::Common::get_server_name($r) =~ /internal/ ||
36             Sesse::pr0n::Common::get_server_name($r) =~ /skoyen\.bilder\.knatten\.com/ ||
37             Sesse::pr0n::Common::get_server_name($r) =~ /lia\.heimdal\.org/) {
38                 my $user = Sesse::pr0n::Common::check_access($r);
39                 return Sesse::pr0n::Common::generate_401($r) if (!defined($user));
40         }
41
42         # Read the appropriate settings from the query string into the settings hash
43         my %defsettings = (
44                 thumbxres => 80,
45                 thumbyres => 64,
46                 xres => -1,
47                 yres => -1,
48                 start => 1,
49                 num => 250,
50                 all => 1,
51                 infobox => 1,
52                 rot => 0,
53                 sel => 0,
54                 fullscreen => 0,
55                 model => undef,
56                 lens => undef,
57                 author => undef
58         );
59         
60         my $where;
61         if ($event eq '+all') {
62                 $where = '';
63         } else {
64                 $where = ' AND event=' . $dbh->quote($event);
65         }
66         
67         # Any NEF files => default to processing
68         my $ref = $dbh->selectrow_hashref("SELECT * FROM images WHERE vhost=? $where AND ( LOWER(filename) LIKE '%.nef' OR LOWER(filename) LIKE '%.cr2' ) LIMIT 1",
69                 undef, Sesse::pr0n::Common::get_server_name($r))
70                 and $defsettings{'xres'} = $defsettings{'yres'} = undef;
71         
72         # Reduce the front page load when in overload mode.
73         if (Sesse::pr0n::Overload::is_in_overload($r)) {
74                 $defsettings{'num'} = 100;
75         }
76                 
77         my %settings = %defsettings;
78
79         for my $s (qw(thumbxres thumbyres xres yres start num all infobox rot sel fullscreen model lens author)) {
80                 my $val = $r->param($s);
81                 if (defined($val) && $val =~ /^(\d+)$/) {
82                         $settings{$s} = $val;
83                 }
84                 if ($s eq "num" && defined($val) && $val == -1) {
85                         $settings{$s} = $val;
86                 }
87                 if (($s eq "xres" || $s eq "yres") && defined($val) && ($val == -1 || $val == -2)) {
88                         $settings{$s} = $val;
89                 }
90                 if (($s eq "model" || $s eq "lens" || $s eq "author") && defined($val)) {
91                         $settings{$s} = Sesse::pr0n::Common::pretty_unescape($val);
92                 }
93         }
94
95         my $thumbxres = $settings{'thumbxres'};
96         my $thumbyres = $settings{'thumbyres'};
97         my $xres = $settings{'xres'};
98         my $yres = $settings{'yres'};
99         my $start = $settings{'start'};
100         my $num = $settings{'num'};
101         my $all = $settings{'all'};
102         my $infobox = $settings{'infobox'} ? '' : 'nobox/';
103         my $rot = $settings{'rot'};
104         my $sel = $settings{'sel'};
105         my $model = $settings{'model'};
106         my $lens = $settings{'lens'};
107         my $author = $settings{'author'};
108
109         # Construct SQL for this filter
110         if ($all == 0) {
111                 $where .= ' AND selected=\'t\'';        
112         }
113         if (defined($model) && defined($lens)) {
114                 my $mq = $dbh->quote($model);
115                 my $lq = $dbh->quote($lens);
116
117                 if ($model eq '') {
118                         # no defined model
119                         $where .= " AND model IS NULL";
120                 } else {
121                         $where .= " AND model=$mq";
122                 }
123         
124                 if ($lens eq '') {
125                         # no defined lens
126                         $where .= " AND lens IS NULL";
127                 } else {
128                         $where .= " AND lens=$lq";
129                 }
130         }
131         if (defined($author)) {
132                 my $aq = $dbh->quote($author);
133
134                 $where .= " AND takenby=$aq";
135         }
136
137         if (defined($num) && $num == -1) {
138                 $num = undef;
139         }
140
141         my ($date, $name);
142
143         if ($event eq '+all') {
144                 $ref = $dbh->selectrow_hashref("SELECT EXTRACT(EPOCH FROM MAX(last_update)) AS last_update FROM last_picture_cache WHERE vhost=?",
145                         undef, Sesse::pr0n::Common::get_server_name($r))
146                         or return error($r, "Could not list events", 404, "File not found");
147                 $date = undef;
148                 $name = Sesse::pr0n::Templates::fetch_template($r, 'all-event-title');
149                 Sesse::pr0n::Common::set_last_modified($r, $ref->{'last_update'});
150         } else {
151                 $ref = $dbh->selectrow_hashref("SELECT name,date,EXTRACT(EPOCH FROM last_update) AS last_update FROM events NATURAL JOIN last_picture_cache WHERE vhost=? AND event=?",
152                         undef, Sesse::pr0n::Common::get_server_name($r), $event)
153                         or return error($r, "Could not find event $event", 404, "File not found");
154
155                 $date = HTML::Entities::encode_entities($ref->{'date'});
156                 $name = HTML::Entities::encode_entities($ref->{'name'});
157                 Sesse::pr0n::Common::set_last_modified($r, $ref->{'last_update'});
158         }
159                                 
160         # # If the client can use cache, do so
161         # if ((my $rc = $r->meets_conditions) != Apache2::Const::OK) {
162         #       return $rc;
163         # }
164         
165         # Count the number of selected images.
166         $ref = $dbh->selectrow_hashref("SELECT COUNT(*) AS num_selected FROM images WHERE vhost=? $where AND selected=\'t\'", undef, Sesse::pr0n::Common::get_server_name($r));
167         my $num_selected = $ref->{'num_selected'};
168
169         # Find all images related to this event.
170         my $limit = (defined($start) && defined($num) && !$settings{'fullscreen'}) ? (" LIMIT $num OFFSET " . ($start-1)) : "";
171
172         my $q = $dbh->prepare("SELECT *, (date - INTERVAL '6 hours')::date AS day FROM images WHERE vhost=? $where ORDER BY (date - INTERVAL '6 hours')::date $datesort,takenby,date,filename $limit")
173                 or return dberror($r, "prepare()");
174         $q->execute(Sesse::pr0n::Common::get_server_name($r))
175                 or return dberror($r, "image enumeration");
176
177         # Print the page itself
178         my $res = Plack::Response->new(200);
179         my $io = IO::String->new;
180         if ($settings{'fullscreen'}) {
181                 $res->content_type("text/html; charset=utf-8");
182
183                 Sesse::pr0n::Templates::print_template($r, $io, "fullscreen-header", { title => "$name [$event]" });
184
185                 my @files = ();
186                 while (my $ref = $q->fetchrow_hashref()) {
187                         my $width = defined($ref->{'width'}) ? $ref->{'width'} : -1;
188                         my $height = defined($ref->{'height'}) ? $ref->{'height'} : -1;
189                         push @files, [ $ref->{'event'}, $ref->{'filename'}, $width, $height ];
190                 }
191                 
192                 for my $i (0..$#files) {
193                         my $line = sprintf "        [ \"%s\", \"%s\", %d, %d ]", @{$files[$i]};
194                         $line .= "," unless ($i == $#files);
195                         $io->print($line . "\n");
196                 }
197
198                 my %settings_no_fullscreen = %settings;
199                 $settings_no_fullscreen{'fullscreen'} = 0;
200
201                 my $returnurl = "http://" . Sesse::pr0n::Common::get_server_name($r) . "/" . $event . "/" .
202                         Sesse::pr0n::Common::get_query_string(\%settings_no_fullscreen, \%defsettings);
203                 
204                 # *whistle*
205                 $returnurl =~ s/&/&/g;
206
207                 Sesse::pr0n::Templates::print_template($r, $io, "fullscreen-footer", {
208                         returnurl => $returnurl,
209                         start => $settings{'start'} - 1,
210                         sel => $settings{'sel'},
211                         infobox => $infobox
212                 });
213         } else {
214                 Sesse::pr0n::Common::header($r, $io, "$name [$event]");
215                 if (defined($date)) {
216                         Sesse::pr0n::Templates::print_template($r, $io, "date", { date => $date });
217                 }
218
219                 if (Sesse::pr0n::Overload::is_in_overload($r)) {
220                         Sesse::pr0n::Templates::print_template($r, $io, "overloadmode");
221                 }
222
223                 print_thumbsize($r, $io, $event, \%settings, \%defsettings);
224                 print_viewres($r, $io, $event, \%settings, \%defsettings);
225                 print_pagelimit($r, $io, $event, \%settings, \%defsettings);
226                 print_infobox($r, $io, $event, \%settings, \%defsettings);
227                 print_selected($r, $io, $event, \%settings, \%defsettings) if ($num_selected > 0);
228                 print_fullscreen($r, $io, $event, \%settings, \%defsettings);
229                 print_nextprev($r, $io, $event, $where, \%settings, \%defsettings);
230         
231                 if (1 || $event ne '+all') {
232                         # Find the equipment used
233                         my $eq = $dbh->prepare("
234                                 SELECT
235                                         model,
236                                         lens,
237                                         COUNT(*) AS num
238                                 FROM images
239                                 WHERE vhost=? $where
240                                 GROUP BY 1,2
241                                 ORDER BY 1,2")
242                                 or die "Couldn't prepare to find equipment: $!";
243                         $eq->execute(Sesse::pr0n::Common::get_server_name($r))
244                                 or die "Couldn't find equipment: $!";
245
246                         my @equipment = ();
247                         my %cameras_seen = ();
248                         while (my $ref = $eq->fetchrow_hashref) {
249                                 if (!defined($ref->{'lens'}) && exists($cameras_seen{$ref->{'model'}})) {
250                                         #
251                                         # Some compact cameras seem to add lens info sometimes and not at other
252                                         # times; if we have seen a camera with at least one specific lens earlier,
253                                         # just combine entries without a lens with the previous one.
254                                         #
255                                         $equipment[$#equipment]->{'num'} += $ref->{'num'};
256                                         next;
257                                 }
258                                 push @equipment, $ref;
259                                 $cameras_seen{$ref->{'model'}} = 1;
260                         }
261                         $eq->finish;
262
263                         if (scalar @equipment > 0) {
264                                 Sesse::pr0n::Templates::print_template($r, $io, "equipment-start");
265                                 for my $e (@equipment) {
266                                         my $eqspec = $e->{'model'};
267                                         $eqspec .= ', ' . $e->{'lens'} if (defined($e->{'lens'}));
268                                         $eqspec = HTML::Entities::encode_entities($eqspec);
269
270                                         my %newsettings = %settings;
271
272                                         my $action;
273                                         if (defined($model) && defined($lens)) {
274                                                 chomp ($action = Sesse::pr0n::Templates::fetch_template($r, "unfilter"));
275                                                 $newsettings{'model'} = undef;
276                                                 $newsettings{'lens'} = undef;
277                                                 $newsettings{'start'} = 1;
278                                         } else {
279                                                 chomp ($action = Sesse::pr0n::Templates::fetch_template($r, "filter"));
280                                                 $newsettings{'model'} = $e->{'model'};
281                                                 $newsettings{'lens'} = defined($e->{'lens'}) ? $e->{'lens'} : '';
282                                                 $newsettings{'start'} = 1;
283                                         }
284                                         
285                                         my $url = "/$event/" . Sesse::pr0n::Common::get_query_string(\%newsettings, \%defsettings);
286
287                                         # This isn't correct for all languages. Fix if we ever need to care. :-)
288                                         if ($e->{'num'} == 1) {
289                                                 Sesse::pr0n::Templates::print_template($r, $io, "equipment-item-singular", { eqspec => $eqspec, filterurl => $url, action => $action });
290                                         } else {
291                                                 Sesse::pr0n::Templates::print_template($r, $io, "equipment-item", { eqspec => $eqspec, num => $e->{'num'}, filterurl => $url, action => $action });
292                                         }
293                                 }
294                                 Sesse::pr0n::Templates::print_template($r, $io, "equipment-end");
295                         }
296                 }
297
298                 my $toclose = 0;
299                 my $lastupl = "";
300                 my $img_num = (defined($start) && defined($num)) ? $start : 1;
301                 
302                 # Print out all thumbnails
303                 if ($rot == 1) {
304                         $io->print("    <form method=\"post\" action=\"/rotate\">\n");
305                         $io->print("      <input type=\"hidden\" name=\"event\" value=\"$event\" />\n");
306                 }
307
308                 while (my $ref = $q->fetchrow_hashref()) {
309                         my $imgsz = "";
310                         my $takenby = $ref->{'takenby'};
311                         my $day = '';
312                         if (defined($ref->{'day'})) {
313                                 $day = ", " . $ref->{'day'};
314                         }
315
316                         my $groupkey = $takenby . $day;
317
318                         if ($groupkey ne $lastupl) {
319                                 $io->print("    </p>\n\n") if ($lastupl ne "" && $rot != 1);
320                                 $lastupl = $groupkey;
321
322                                 my %newsettings = %settings;
323
324                                 my $action;
325                                 if (defined($author)) {
326                                         chomp ($action = Sesse::pr0n::Templates::fetch_template($r, "unfilter"));
327                                         $newsettings{'author'} = undef;
328                                         $newsettings{'start'} = 1;
329                                 } else {
330                                         chomp ($action = Sesse::pr0n::Templates::fetch_template($r, "filter"));
331                                         $newsettings{'author'} = $ref->{'takenby'};
332                                         $newsettings{'start'} = 1;
333                                 }
334
335                                 my $url = "/$event/" . Sesse::pr0n::Common::get_query_string(\%newsettings, \%defsettings);
336                                 
337                                 $io->print("    <h2>");
338                                 Sesse::pr0n::Templates::print_template($r, $io, "submittedby", { author => $takenby, action => $action, filterurl => $url, date => $day });
339                                 print_fullscreen_fromhere($r, $io, $event, \%settings, \%defsettings, $img_num);
340                                 $io->print("</h2>\n");
341
342                                 if ($rot != 1) {
343                                         $io->print("    <p class=\"photos\">\n");
344                                 }
345                         }
346
347                         if (defined($ref->{'width'}) && defined($ref->{'height'})) {
348                                 my $width = $ref->{'width'};
349                                 my $height = $ref->{'height'};
350                                         
351                                 ($width, $height) = Sesse::pr0n::Common::scale_aspect($width, $height, $thumbxres, $thumbyres);
352                                 $imgsz = " width=\"$width\" height=\"$height\"";
353                         }
354
355                         my $filename = $ref->{'filename'};
356                         my $uri = $infobox . $filename;
357                         if (defined($xres) && defined($yres) && $xres != -1 && $xres != -2) {
358                                 $uri = "${xres}x$yres/$infobox$filename";
359                         } elsif (defined($xres) && $xres == -1) {
360                                 $uri = "original/$infobox$filename";
361                         }
362                         
363                         my $prefix = "";
364                         if ($abspath) {
365                                 $prefix = "/" . $ref->{'event'} . "/";
366                         }
367                 
368                         if ($rot == 1) {        
369                                 $io->print("    <p>");
370                         } else {
371                                 $io->print("     ");
372                         }
373                         $io->print("<a href=\"$prefix$uri\"><img src=\"$prefix${thumbxres}x${thumbyres}/$filename\" alt=\"\"$imgsz /></a>\n");
374                 
375                         if ($rot == 1) {
376                                 $io->print("      90 <input type=\"checkbox\" name=\"rot-" .
377                                         $ref->{'id'} . "-90\" />\n");
378                                 $io->print("      180 <input type=\"checkbox\" name=\"rot-" .
379                                         $ref->{'id'} . "-180\" />\n");
380                                 $io->print("      270 <input type=\"checkbox\" name=\"rot-" .
381                                         $ref->{'id'} . "-270\" />\n");
382                                 $io->print("      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .
383                                         "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Del <input type=\"checkbox\" name=\"del-" . $ref->{'id'} . "\" /></p>\n");
384                         }
385                         
386                         ++$img_num;
387                 }
388
389                 if ($rot == 1) {
390                         $io->print("      <input type=\"submit\" value=\"Rotate\" />\n");
391                         $io->print("    </form>\n");
392                 } else {
393                         $io->print("    </p>\n");
394                 }
395
396                 print_nextprev($r, $io, $event, $where, \%settings, \%defsettings);
397                 Sesse::pr0n::Common::footer($r, $io);
398         }
399
400         $io->setpos(0);
401         $res->body($io);
402         return $res;
403 }
404
405 sub eq_with_undef {
406         my ($a, $b) = @_;
407         
408         return 1 if (!defined($a) && !defined($b));
409         return 0 unless (defined($a) && defined($b));
410         return ($a eq $b);
411 }
412
413 sub print_changes {
414         my ($r, $io, $event, $template, $settings, $defsettings, $var1, $var2, $alternatives) = @_;
415
416         my $title = Sesse::pr0n::Templates::fetch_template($r, $template);
417         chomp $title;
418         $io->print("    <p>$title:\n");
419
420         for my $a (@$alternatives) {
421                 my $text;
422                 my %newsettings = %$settings;
423
424                 if (ref $a) {
425                         my ($v1, $v2);
426                         ($text, $v1, $v2) = @$a;
427                         
428                         $newsettings{$var1} = $v1;
429                         $newsettings{$var2} = $v2;
430                 } else {
431                         $text = $a;
432
433                         # Parse the current alternative
434                         my ($v1, $v2) = split /x/, $a;
435
436                         $newsettings{$var1} = $v1;
437                         $newsettings{$var2} = $v2;
438                 }
439
440                 $io->print("      ");
441
442                 # Check if these settings are current (print only label)
443                 if (eq_with_undef($settings->{$var1}, $newsettings{$var1}) &&
444                     eq_with_undef($settings->{$var2}, $newsettings{$var2})) {
445                         $io->print($text);
446                 } else {
447                         Sesse::pr0n::Common::print_link($io, $text, "/$event/", \%newsettings, $defsettings);
448                 }
449                 $io->print("\n");
450         }
451         $io->print("    </p>\n");
452 }
453
454 sub print_thumbsize {
455         my ($r, $io, $event, $settings, $defsettings) = @_;
456         my @alternatives = qw(80x64 120x96 160x128 240x192 320x256);
457
458         print_changes($r, $io, $event, 'thumbsize', $settings, $defsettings,
459                       'thumbxres', 'thumbyres', \@alternatives);
460 }
461 sub print_viewres {
462         my ($r, $io, $event, $settings, $defsettings) = @_;
463         my @alternatives = qw(320x256 512x384 640x480 800x600 1024x768 1152x864 1280x960 1400x1050 1600x1200 1920x1440 2048x1536 2304x1728);
464         chomp (my $unlimited = Sesse::pr0n::Templates::fetch_template($r, 'viewres-unlimited'));
465         chomp (my $original = Sesse::pr0n::Templates::fetch_template($r, 'viewres-original'));
466         push @alternatives, [ $unlimited, -2, -2 ];
467         push @alternatives, [ $original, -1, -1 ];
468
469         print_changes($r, $io, $event, 'viewres', $settings, $defsettings,
470                       'xres', 'yres', \@alternatives);
471 }
472
473 sub print_pagelimit {
474         my ($r, $io, $event, $settings, $defsettings) = @_;
475         
476         my $title = Sesse::pr0n::Templates::fetch_template($r, 'imgsperpage');
477         chomp $title;
478         $io->print("    <p>$title:\n");
479         
480         # Get choices
481         chomp (my $unlimited = Sesse::pr0n::Templates::fetch_template($r, 'imgsperpage-unlimited'));
482         my @alternatives = qw(10 50 100 250 500);
483         push @alternatives, $unlimited;
484         
485         for my $num (@alternatives) {
486                 my %newsettings = %$settings;
487
488                 if ($num !~ /^\d+$/) { # unlimited
489                         $newsettings{'num'} = -1;
490                 } else {
491                         $newsettings{'num'} = $num;
492                 }
493
494                 $io->print("      ");
495                 if (eq_with_undef($settings->{'num'}, $newsettings{'num'})) {
496                         $io->print($num);
497                 } else {
498                         Sesse::pr0n::Common::print_link($io, $num, "/$event/", \%newsettings, $defsettings);
499                 }
500                 $io->print("\n");
501         }
502         $io->print("    </p>\n");
503 }
504
505 sub print_infobox {
506         my ($r, $io, $event, $settings, $defsettings) = @_;
507
508         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'infobox'));
509         chomp (my $on = Sesse::pr0n::Templates::fetch_template($r, 'infobox-on'));
510         chomp (my $off = Sesse::pr0n::Templates::fetch_template($r, 'infobox-off'));
511
512         $io->print("    <p>$title:\n");
513
514         my %newsettings = %$settings;
515
516         if ($settings->{'infobox'} == 1) {
517                 $io->print($on);
518         } else {
519                 $newsettings{'infobox'} = 1;
520                 Sesse::pr0n::Common::print_link($io, $on, "/$event/", \%newsettings, $defsettings);
521         }
522
523         $io->print(' ');
524
525         if ($settings->{'infobox'} == 0) {
526                 $io->print($off);
527         } else {
528                 $newsettings{'infobox'} = 0;
529                 Sesse::pr0n::Common::print_link($io, $off, "/$event/", \%newsettings, $defsettings);
530         }
531         
532         $io->print('</p>');
533 }
534
535 sub print_nextprev {
536         my ($r, $io, $event, $where, $settings, $defsettings) = @_;
537         my $start = $settings->{'start'};
538         my $num = $settings->{'num'};
539         my $dbh = Sesse::pr0n::Common::get_dbh();
540
541         $num = undef if (defined($num) && $num == -1);
542         return unless (defined($start) && defined($num));
543
544         # determine total number
545         my $ref = $dbh->selectrow_hashref("SELECT count(*) AS num_images FROM images WHERE vhost=? $where",
546                 undef, Sesse::pr0n::Common::get_server_name($r))
547                 or return dberror($r, "image enumeration");
548         my $num_images = $ref->{'num_images'};
549
550         return if ($start == 1 && $start + $num >= $num_images);
551
552         my $end = $start + $num - 1;
553         if ($end > $num_images) {
554                 $end = $num_images;
555         }
556
557         $io->print("    <p class=\"nextprev\">\n");
558
559         # Previous
560         if ($start > 1) {
561                 my $newstart = $start - $num;
562                 if ($newstart < 1) {
563                         $newstart = 1;
564                 }
565                 my $newend = $newstart + $num - 1;
566                 if ($newend > $num_images) {
567                         $newend = $num_images;
568                 }
569
570                 my %newsettings = %$settings;
571                 $newsettings{'start'} = $newstart;
572                 chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'prevpage'));
573                 chomp (my $accesskey = Sesse::pr0n::Templates::fetch_template($r, 'prevaccesskey'));
574                 Sesse::pr0n::Common::print_link($io, "$title ($newstart-$newend)\n", "/$event/", \%newsettings, $defsettings, $accesskey);
575         }
576
577         # This
578         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'thispage'));
579         $io->print("    $title ($start-$end)\n");
580
581         # Next
582         if ($end < $num_images) {
583                 my $newstart = $start + $num;
584                 my $newend = $newstart + $num - 1;
585                 if ($newend > $num_images) {
586                         $newend = $num_images;
587                 }
588                 
589                 my %newsettings = %$settings;
590                 $newsettings{'start'} = $newstart;
591                 chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'nextpage'));
592                 chomp (my $accesskey = Sesse::pr0n::Templates::fetch_template($r, 'nextaccesskey'));
593                 Sesse::pr0n::Common::print_link($io, "$title ($newstart-$newend)", "/$event/", \%newsettings, $defsettings, $accesskey);
594         }
595
596         $io->print("    </p>\n");
597 }
598
599 sub print_selected {
600         my ($r, $io, $event, $settings, $defsettings) = @_;
601
602         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'show'));
603         chomp (my $all = Sesse::pr0n::Templates::fetch_template($r, 'show-all'));
604         chomp (my $sel = Sesse::pr0n::Templates::fetch_template($r, 'show-selected'));
605
606         $io->print("    <p>$title:\n");
607
608         my %newsettings = %$settings;
609
610         if ($settings->{'all'} == 0) {
611                 $io->print($sel);
612         } else {
613                 $newsettings{'all'} = 0;
614                 Sesse::pr0n::Common::print_link($io, $sel, "/$event/", \%newsettings, $defsettings);
615         }
616
617         $io->print(' ');
618
619         if ($settings->{'all'} == 1) {
620                 $io->print($all);
621         } else {
622                 $newsettings{'all'} = 1;
623                 Sesse::pr0n::Common::print_link($io, $all, "/$event/", \%newsettings, $defsettings);
624         }
625         
626         $io->print('</p>');
627 }
628
629 sub print_fullscreen {
630         my ($r, $io, $event, $settings, $defsettings) = @_;
631
632         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'fullscreen'));
633
634         my %newsettings = %$settings;
635         $newsettings{'fullscreen'} = 1;
636
637         $io->print("    <p>");
638         Sesse::pr0n::Common::print_link($io, $title, "/$event/", \%newsettings, $defsettings);
639         $io->print("</p>\n");
640 }
641
642 sub print_fullscreen_fromhere {
643         my ($r, $io, $event, $settings, $defsettings, $start) = @_;
644
645         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'fullscreen-fromhere'));
646
647         my %newsettings = %$settings;
648         $newsettings{'fullscreen'} = 1;
649         $newsettings{'start'} = $start;
650
651         $io->print("    <span class=\"fsfromhere\">");
652         Sesse::pr0n::Common::print_link($io, $title, "/$event/", \%newsettings, $defsettings);
653         $io->print("</span>\n");
654 }
655         
656 1;
657
658