Fix tons of JSLint issues.
[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 !~ /\/$/) {
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 key='Model' AND TRIM(value)<>'' )";
119                 } else {
120                         $where .= " AND id IN ( SELECT image FROM exif_info WHERE key='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 (key='Lens' OR key='LensSpec') AND TRIM(value)<>'' )";
127                 } else {
128                         $where .= " AND id IN ( SELECT image FROM exif_info WHERE (key='Lens' OR key='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
177                 my @files = ();
178                 while (my $ref = $q->fetchrow_hashref()) {
179                         push @files, [ $ref->{'event'}, $ref->{'filename'} ];
180                 }
181                 
182                 for my $i (0..$#files) {
183                         $r->print("        [ \"" . $files[$i]->[0] . "\", \"" . $files[$i]->[1] . "\" ]");
184                         $r->print(",") unless ($i == $#files);
185                         $r->print("\n");
186                 }
187
188                 my %settings_no_fullscreen = %settings;
189                 $settings_no_fullscreen{'fullscreen'} = 0;
190
191                 my $returnurl = "http://" . $r->get_server_name . "/" . $event . "/" .
192                         Sesse::pr0n::Common::get_query_string(\%settings_no_fullscreen, \%defsettings);
193
194                 # *whistle*
195                 $returnurl =~ s/&amp;/&/g;
196
197                 Sesse::pr0n::Templates::print_template($r, "fullscreen-footer", {
198                         vhost => $r->get_server_name,
199                         start => $settings{'start'} - 1,
200                         returnurl => $returnurl,
201                         sel => $settings{'sel'},
202                         infobox => $infobox
203                 });
204         } else {
205                 Sesse::pr0n::Common::header($r, "$name [$event]");
206                 if (defined($date)) {
207                         Sesse::pr0n::Templates::print_template($r, "date", { date => $date });
208                 }
209
210                 if (Sesse::pr0n::Overload::is_in_overload($r)) {
211                         Sesse::pr0n::Templates::print_template($r, "overloadmode");
212                 }
213
214                 print_thumbsize($r, $event, \%settings, \%defsettings);
215                 print_viewres($r, $event, \%settings, \%defsettings);
216                 print_pagelimit($r, $event, \%settings, \%defsettings);
217                 print_infobox($r, $event, \%settings, \%defsettings);
218                 print_selected($r, $event, \%settings, \%defsettings) if ($num_selected > 0);
219                 print_fullscreen($r, $event, \%settings, \%defsettings);
220                 print_nextprev($r, $event, $where, \%settings, \%defsettings);
221         
222                 if (1 || $event ne '+all') {
223                         # Find the equipment used
224                         my $eq = $dbh->prepare("
225                                 SELECT 
226                                         TRIM(model.value) AS model,
227                                         coalesce(TRIM(lens_spec.value), TRIM(lens.value)) AS lens,
228                                         COUNT(*) AS num
229                                 FROM ( SELECT * FROM images WHERE vhost=? $where ) i
230                                         LEFT JOIN exif_info model ON i.id=model.image
231                                         LEFT JOIN ( SELECT * FROM exif_info WHERE key='Lens' ) lens ON i.id=lens.image
232                                         LEFT JOIN ( SELECT * FROM exif_info WHERE key='LensSpec') lens_spec ON i.id=lens_spec.image
233                                 WHERE model.key='Model'
234                                 GROUP BY 1,2
235                                 ORDER BY 1,2")
236                                 or die "Couldn't prepare to find equipment: $!";
237                         $eq->execute($r->get_server_name)
238                                 or die "Couldn't find equipment: $!";
239
240                         my @equipment = ();
241                         my %cameras_seen = ();
242                         while (my $ref = $eq->fetchrow_hashref) {
243                                 if (!defined($ref->{'lens'}) && exists($cameras_seen{$ref->{'model'}})) {
244                                         #
245                                         # Some compact cameras seem to add lens info sometimes and not at other
246                                         # times; if we have seen a camera with at least one specific lens earlier,
247                                         # just combine entries without a lens with the previous one.
248                                         #
249                                         $equipment[$#equipment]->{'num'} += $ref->{'num'};
250                                         next;
251                                 }
252                                 push @equipment, $ref;
253                                 $cameras_seen{$ref->{'model'}} = 1;
254                         }
255                         $eq->finish;
256
257                         if (scalar @equipment > 0) {
258                                 Sesse::pr0n::Templates::print_template($r, "equipment-start");
259                                 for my $e (@equipment) {
260                                         my $eqspec = $e->{'model'};
261                                         $eqspec .= ', ' . $e->{'lens'} if (defined($e->{'lens'}));
262                                         $eqspec = HTML::Entities::encode_entities($eqspec);
263
264                                         my %newsettings = %settings;
265
266                                         my $action;
267                                         if (defined($model) && defined($lens)) {
268                                                 chomp ($action = Sesse::pr0n::Templates::fetch_template($r, "unfilter"));
269                                                 $newsettings{'model'} = undef;
270                                                 $newsettings{'lens'} = undef;
271                                         } else {
272                                                 chomp ($action = Sesse::pr0n::Templates::fetch_template($r, "filter"));
273                                                 $newsettings{'model'} = $e->{'model'};
274                                                 $newsettings{'lens'} = defined($e->{'lens'}) ? $e->{'lens'} : '';
275                                         }
276                                         
277                                         my $url = "/$event/" . Sesse::pr0n::Common::get_query_string(\%newsettings, \%defsettings);
278
279                                         # This isn't correct for all languages. Fix if we ever need to care. :-)
280                                         if ($e->{'num'} == 1) {
281                                                 Sesse::pr0n::Templates::print_template($r, "equipment-item-singular", { eqspec => $eqspec, filterurl => $url, action => $action });
282                                         } else {
283                                                 Sesse::pr0n::Templates::print_template($r, "equipment-item", { eqspec => $eqspec, num => $e->{'num'}, filterurl => $url, action => $action });
284                                         }
285                                 }
286                                 Sesse::pr0n::Templates::print_template($r, "equipment-end");
287                         }
288                 }
289
290                 my $toclose = 0;
291                 my $lastupl = "";
292                 my $img_num = (defined($start) && defined($num)) ? $start : 1;
293                 
294                 # Print out all thumbnails
295                 if ($rot == 1) {
296                         $r->print("    <form method=\"post\" action=\"/rotate\">\n");
297                         $r->print("      <input type=\"hidden\" name=\"event\" value=\"$event\" />\n");
298         
299                         while (my $ref = $q->fetchrow_hashref()) {
300                                 my $imgsz = "";
301                                 my $takenby = $ref->{'takenby'};
302                                 if (defined($ref->{'day'})) {
303                                          $takenby .= ", " . $ref->{'day'};
304                                 }
305
306                                 if ($takenby ne $lastupl) {
307                                         $lastupl = $takenby;
308                                         $r->print("    <h2>");
309                                         Sesse::pr0n::Templates::print_template($r, "submittedby", { author => $lastupl });
310                                         print_fullscreen_fromhere($r, $event, \%settings, \%defsettings, $img_num);
311                                         $r->print("</h2>\n");
312                                 }
313                                 if ($ref->{'width'} != -1 && $ref->{'height'} != -1) {
314                                         my $width = $ref->{'width'};
315                                         my $height = $ref->{'height'};
316                                                 
317                                         ($width, $height) = Sesse::pr0n::Common::scale_aspect($width, $height, $thumbxres, $thumbyres);
318                                         $imgsz = " width=\"$width\" height=\"$height\"";
319                                 }
320
321                                 my $filename = $ref->{'filename'};
322                                 my $uri = $infobox . $filename;
323                                 if (defined($xres) && defined($yres) && $xres != -1) {
324                                         $uri = "${xres}x$yres/$infobox$filename";
325                                 } elsif (defined($xres) && $xres == -1) {
326                                         $uri = "original/$infobox$filename";
327                                 }
328
329                                 my $prefix = "";
330                                 if ($abspath) {
331                                         $prefix = "/" . $ref->{'event'} . "/";
332                                 }
333
334                                 $r->print("    <p><a href=\"$prefix$uri\"><img src=\"$prefix${thumbxres}x${thumbyres}/$filename\" alt=\"\"$imgsz /></a>\n");
335                                 $r->print("      90 <input type=\"checkbox\" name=\"rot-" .
336                                         $ref->{'id'} . "-90\" />\n");
337                                 $r->print("      180 <input type=\"checkbox\" name=\"rot-" .
338                                         $ref->{'id'} . "-180\" />\n");
339                                 $r->print("      270 <input type=\"checkbox\" name=\"rot-" .
340                                         $ref->{'id'} . "-270\" />\n");
341                                 $r->print("      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .
342                                         "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Del <input type=\"checkbox\" name=\"del-" . $ref->{'id'} . "\" /></p>\n");
343                         
344                                 ++$img_num;
345                         }
346                         $r->print("      <input type=\"submit\" value=\"Rotate\" />\n");
347                         $r->print("    </form>\n");
348                 } else {
349                         while (my $ref = $q->fetchrow_hashref()) {
350                                 my $imgsz = "";
351                                 my $takenby = $ref->{'takenby'};
352                                 if (defined($ref->{'day'})) {
353                                          $takenby .= ", " . $ref->{'day'};
354                                 }
355
356                                 if ($takenby ne $lastupl) {
357                                         $r->print("    </p>\n\n") if ($lastupl ne "");
358                                         $lastupl = $takenby;
359                                         $r->print("    <h2>");
360                                         Sesse::pr0n::Templates::print_template($r, "submittedby", { author => $lastupl });
361                                         print_fullscreen_fromhere($r, $event, \%settings, \%defsettings, $img_num);
362                                         $r->print("</h2>\n");
363                                         $r->print("    <p class=\"photos\">\n");
364                                 }
365                                 if ($ref->{'width'} != -1 && $ref->{'height'} != -1) {
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                                 $r->print("      <a href=\"$prefix$uri\"><img src=\"$prefix${thumbxres}x${thumbyres}/$filename\" alt=\"\"$imgsz /></a>\n");
387                                 
388                                 ++$img_num;
389                         }
390                         $r->print("    </p>\n");
391                 }
392
393                 print_nextprev($r, $event, $where, \%settings, \%defsettings);
394                 Sesse::pr0n::Common::footer($r);
395         }
396
397         return Apache2::Const::OK;
398 }
399
400 sub eq_with_undef {
401         my ($a, $b) = @_;
402         
403         return 1 if (!defined($a) && !defined($b));
404         return 0 unless (defined($a) && defined($b));
405         return ($a eq $b);
406 }
407
408 sub print_changes {
409         my ($r, $event, $template, $settings, $defsettings, $var1, $var2, $alternatives) = @_;
410
411         my $title = Sesse::pr0n::Templates::fetch_template($r, $template);
412         chomp $title;
413         $r->print("    <p>$title:\n");
414
415         for my $a (@$alternatives) {
416                 my $text;
417                 my %newsettings = %$settings;
418
419                 if (ref $a) {
420                         my ($v1, $v2);
421                         ($text, $v1, $v2) = @$a;
422                         
423                         $newsettings{$var1} = $v1;
424                         $newsettings{$var2} = $v2;
425                 } else {
426                         $text = $a;
427
428                         # Parse the current alternative
429                         my ($v1, $v2) = split /x/, $a;
430
431                         $newsettings{$var1} = $v1;
432                         $newsettings{$var2} = $v2;
433                 }
434
435                 $r->print("      ");
436
437                 # Check if these settings are current (print only label)
438                 if (eq_with_undef($settings->{$var1}, $newsettings{$var1}) &&
439                     eq_with_undef($settings->{$var2}, $newsettings{$var2})) {
440                         $r->print($text);
441                 } else {
442                         Sesse::pr0n::Common::print_link($r, $text, "/$event/", \%newsettings, $defsettings);
443                 }
444                 $r->print("\n");
445         }
446         $r->print("    </p>\n");
447 }
448
449 sub print_thumbsize {
450         my ($r, $event, $settings, $defsettings) = @_;
451         my @alternatives = qw(80x64 120x96 160x128 240x192 320x256);
452
453         print_changes($r, $event, 'thumbsize', $settings, $defsettings,
454                       'thumbxres', 'thumbyres', \@alternatives);
455 }
456 sub print_viewres {
457         my ($r, $event, $settings, $defsettings) = @_;
458         my @alternatives = qw(320x256 512x384 640x480 800x600 1024x768 1280x960);
459         chomp (my $unlimited = Sesse::pr0n::Templates::fetch_template($r, 'viewres-unlimited'));
460         chomp (my $original = Sesse::pr0n::Templates::fetch_template($r, 'viewres-original'));
461         push @alternatives, [ $unlimited, undef, undef ];
462         push @alternatives, [ $original, -1, -1 ];
463
464         print_changes($r, $event, 'viewres', $settings, $defsettings,
465                       'xres', 'yres', \@alternatives);
466 }
467
468 sub print_pagelimit {
469         my ($r, $event, $settings, $defsettings) = @_;
470         
471         my $title = Sesse::pr0n::Templates::fetch_template($r, 'imgsperpage');
472         chomp $title;
473         $r->print("    <p>$title:\n");
474         
475         # Get choices
476         chomp (my $unlimited = Sesse::pr0n::Templates::fetch_template($r, 'imgsperpage-unlimited'));
477         my @alternatives = qw(10 50 100 500);
478         push @alternatives, $unlimited;
479         
480         for my $num (@alternatives) {
481                 my %newsettings = %$settings;
482
483                 if ($num !~ /^\d+$/) { # unlimited
484                         $newsettings{'num'} = -1;
485                 } else {
486                         $newsettings{'num'} = $num;
487                 }
488
489                 $r->print("      ");
490                 if (eq_with_undef($settings->{'num'}, $newsettings{'num'})) {
491                         $r->print($num);
492                 } else {
493                         Sesse::pr0n::Common::print_link($r, $num, "/$event/", \%newsettings, $defsettings);
494                 }
495                 $r->print("\n");
496         }
497         $r->print("    </p>\n");
498 }
499
500 sub print_infobox {
501         my ($r, $event, $settings, $defsettings) = @_;
502
503         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'infobox'));
504         chomp (my $on = Sesse::pr0n::Templates::fetch_template($r, 'infobox-on'));
505         chomp (my $off = Sesse::pr0n::Templates::fetch_template($r, 'infobox-off'));
506
507         $r->print("    <p>$title:\n");
508
509         my %newsettings = %$settings;
510
511         if ($settings->{'infobox'} == 1) {
512                 $r->print($on);
513         } else {
514                 $newsettings{'infobox'} = 1;
515                 Sesse::pr0n::Common::print_link($r, $on, "/$event/", \%newsettings, $defsettings);
516         }
517
518         $r->print(' ');
519
520         if ($settings->{'infobox'} == 0) {
521                 $r->print($off);
522         } else {
523                 $newsettings{'infobox'} = 0;
524                 Sesse::pr0n::Common::print_link($r, $off, "/$event/", \%newsettings, $defsettings);
525         }
526         
527         $r->print('</p>');
528 }
529
530 sub print_nextprev {
531         my ($r, $event, $where, $settings, $defsettings) = @_;
532         my $start = $settings->{'start'};
533         my $num = $settings->{'num'};
534         my $dbh = Sesse::pr0n::Common::get_dbh();
535
536         $num = undef if (defined($num) && $num == -1);
537         return unless (defined($start) && defined($num));
538
539         # determine total number
540         my $ref = $dbh->selectrow_hashref("SELECT count(*) AS num_images FROM images WHERE vhost=? $where",
541                 undef, $r->get_server_name)
542                 or dberror($r, "image enumeration");
543         my $num_images = $ref->{'num_images'};
544
545         return if ($start == 1 && $start + $num >= $num_images);
546
547         my $end = $start + $num - 1;
548         if ($end > $num_images) {
549                 $end = $num_images;
550         }
551
552         $r->print("    <p class=\"nextprev\">\n");
553
554         # Previous
555         if ($start > 1) {
556                 my $newstart = $start - $num;
557                 if ($newstart < 1) {
558                         $newstart = 1;
559                 }
560                 my $newend = $newstart + $num - 1;
561                 if ($newend > $num_images) {
562                         $newend = $num_images;
563                 }
564
565                 my %newsettings = %$settings;
566                 $newsettings{'start'} = $newstart;
567                 chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'prevpage'));
568                 chomp (my $accesskey = Sesse::pr0n::Templates::fetch_template($r, 'prevaccesskey'));
569                 Sesse::pr0n::Common::print_link($r, "$title ($newstart-$newend)\n", "/$event/", \%newsettings, $defsettings, $accesskey);
570         }
571
572         # This
573         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'thispage'));
574         $r->print("    $title ($start-$end)\n");
575
576         # Next
577         if ($end < $num_images) {
578                 my $newstart = $start + $num;
579                 my $newend = $newstart + $num - 1;
580                 if ($newend > $num_images) {
581                         $newend = $num_images;
582                 }
583                 
584                 my %newsettings = %$settings;
585                 $newsettings{'start'} = $newstart;
586                 chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'nextpage'));
587                 chomp (my $accesskey = Sesse::pr0n::Templates::fetch_template($r, 'nextaccesskey'));
588                 Sesse::pr0n::Common::print_link($r, "$title ($newstart-$newend)", "/$event/", \%newsettings, $defsettings, $accesskey);
589         }
590
591         $r->print("    </p>\n");
592 }
593
594 sub print_selected {
595         my ($r, $event, $settings, $defsettings) = @_;
596
597         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'show'));
598         chomp (my $all = Sesse::pr0n::Templates::fetch_template($r, 'show-all'));
599         chomp (my $sel = Sesse::pr0n::Templates::fetch_template($r, 'show-selected'));
600
601         $r->print("    <p>$title:\n");
602
603         my %newsettings = %$settings;
604
605         if ($settings->{'all'} == 0) {
606                 $r->print($sel);
607         } else {
608                 $newsettings{'all'} = 0;
609                 Sesse::pr0n::Common::print_link($r, $sel, "/$event/", \%newsettings, $defsettings);
610         }
611
612         $r->print(' ');
613
614         if ($settings->{'all'} == 1) {
615                 $r->print($all);
616         } else {
617                 $newsettings{'all'} = 1;
618                 Sesse::pr0n::Common::print_link($r, $all, "/$event/", \%newsettings, $defsettings);
619         }
620         
621         $r->print('</p>');
622 }
623
624 sub print_fullscreen {
625         my ($r, $event, $settings, $defsettings) = @_;
626
627         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'fullscreen'));
628
629         my %newsettings = %$settings;
630         $newsettings{'fullscreen'} = 1;
631
632         $r->print("    <p>");
633         Sesse::pr0n::Common::print_link($r, $title, "/$event/", \%newsettings, $defsettings);
634         $r->print("</p>\n");
635 }
636
637 sub print_fullscreen_fromhere {
638         my ($r, $event, $settings, $defsettings, $start) = @_;
639
640         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'fullscreen-fromhere'));
641
642         my %newsettings = %$settings;
643         $newsettings{'fullscreen'} = 1;
644         $newsettings{'start'} = $start;
645
646         $r->print("    <p class=\"fsfromhere\">");
647         Sesse::pr0n::Common::print_link($r, $title, "/$event/", \%newsettings, $defsettings);
648         $r->print("</p>\n");
649 }
650         
651 1;
652
653