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