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