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