Actually implement filtering.
[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                                         $newsettings{'model'} = $e->{'model'};
257                                         $newsettings{'lens'} = defined($e->{'lens'}) ? $e->{'lens'} : '';
258                                         my $url = "/$event/" . Sesse::pr0n::Common::get_query_string(\%newsettings, \%defsettings);
259
260                                         # This isn't correct for all languages. Fix if we ever need to care. :-)
261                                         if ($e->{'num'} == 1) {
262                                                 Sesse::pr0n::Templates::print_template($r, "equipment-item-singular", { eqspec => $eqspec, filterurl => $url });
263                                         } else {
264                                                 Sesse::pr0n::Templates::print_template($r, "equipment-item", { eqspec => $eqspec, num => $e->{'num'}, filterurl => $url });
265                                         }
266                                 }
267                                 Sesse::pr0n::Templates::print_template($r, "equipment-end");
268                         }
269                 }
270
271                 my $toclose = 0;
272                 my $lastupl = "";
273                 my $img_num = (defined($start) && defined($num)) ? $start : 1;
274                 
275                 # Print out all thumbnails
276                 if ($rot == 1) {
277                         $r->print("    <form method=\"post\" action=\"/rotate\">\n");
278                         $r->print("      <input type=\"hidden\" name=\"event\" value=\"$event\" />\n");
279         
280                         while (my $ref = $q->fetchrow_hashref()) {
281                                 my $imgsz = "";
282                                 my $takenby = $ref->{'takenby'};
283                                 if (defined($ref->{'day'})) {
284                                          $takenby .= ", " . $ref->{'day'};
285                                 }
286
287                                 if ($takenby ne $lastupl) {
288                                         $lastupl = $takenby;
289                                         $r->print("    <h2>");
290                                         Sesse::pr0n::Templates::print_template($r, "submittedby", { author => $lastupl });
291                                         print_fullscreen_fromhere($r, $event, \%settings, \%defsettings, $img_num);
292                                         $r->print("</h2>\n");
293                                 }
294                                 if ($ref->{'width'} != -1 && $ref->{'height'} != -1) {
295                                         my $width = $ref->{'width'};
296                                         my $height = $ref->{'height'};
297                                                 
298                                         ($width, $height) = Sesse::pr0n::Common::scale_aspect($width, $height, $thumbxres, $thumbyres);
299                                         $imgsz = " width=\"$width\" height=\"$height\"";
300                                 }
301
302                                 my $filename = $ref->{'filename'};
303                                 my $uri = $infobox . $filename;
304                                 if (defined($xres) && defined($yres) && $xres != -1) {
305                                         $uri = "${xres}x$yres/$infobox$filename";
306                                 } elsif (defined($xres) && $xres == -1) {
307                                         $uri = "original/$infobox$filename";
308                                 }
309
310                                 my $prefix = "";
311                                 if ($abspath) {
312                                         $prefix = "/" . $ref->{'event'} . "/";
313                                 }
314
315                                 $r->print("    <p><a href=\"$prefix$uri\"><img src=\"$prefix${thumbxres}x${thumbyres}/$filename\" alt=\"\"$imgsz /></a>\n");
316                                 $r->print("      90 <input type=\"checkbox\" name=\"rot-" .
317                                         $ref->{'id'} . "-90\" />\n");
318                                 $r->print("      180 <input type=\"checkbox\" name=\"rot-" .
319                                         $ref->{'id'} . "-180\" />\n");
320                                 $r->print("      270 <input type=\"checkbox\" name=\"rot-" .
321                                         $ref->{'id'} . "-270\" />\n");
322                                 $r->print("      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .
323                                         "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Del <input type=\"checkbox\" name=\"del-" . $ref->{'id'} . "\" /></p>\n");
324                         
325                                 ++$img_num;
326                         }
327                         $r->print("      <input type=\"submit\" value=\"Rotate\" />\n");
328                         $r->print("    </form>\n");
329                 } else {
330                         while (my $ref = $q->fetchrow_hashref()) {
331                                 my $imgsz = "";
332                                 my $takenby = $ref->{'takenby'};
333                                 if (defined($ref->{'day'})) {
334                                          $takenby .= ", " . $ref->{'day'};
335                                 }
336
337                                 if ($takenby ne $lastupl) {
338                                         $r->print("    </p>\n\n") if ($lastupl ne "");
339                                         $lastupl = $takenby;
340                                         $r->print("    <h2>");
341                                         Sesse::pr0n::Templates::print_template($r, "submittedby", { author => $lastupl });
342                                         print_fullscreen_fromhere($r, $event, \%settings, \%defsettings, $img_num);
343                                         $r->print("</h2>\n");
344                                         $r->print("    <p class=\"photos\">\n");
345                                 }
346                                 if ($ref->{'width'} != -1 && $ref->{'height'} != -1) {
347                                         my $width = $ref->{'width'};
348                                         my $height = $ref->{'height'};
349                                                 
350                                         ($width, $height) = Sesse::pr0n::Common::scale_aspect($width, $height, $thumbxres, $thumbyres);
351                                         $imgsz = " width=\"$width\" height=\"$height\"";
352                                 }
353
354                                 my $filename = $ref->{'filename'};
355                                 my $uri = $infobox . $filename;
356                                 if (defined($xres) && defined($yres) && $xres != -1) {
357                                         $uri = "${xres}x$yres/$infobox$filename";
358                                 } elsif (defined($xres) && $xres == -1) {
359                                         $uri = "original/$infobox$filename";
360                                 }
361                                 
362                                 my $prefix = "";
363                                 if ($abspath) {
364                                         $prefix = "/" . $ref->{'event'} . "/";
365                                 }
366                                 
367                                 $r->print("      <a href=\"$prefix$uri\"><img src=\"$prefix${thumbxres}x${thumbyres}/$filename\" alt=\"\"$imgsz /></a>\n");
368                                 
369                                 ++$img_num;
370                         }
371                         $r->print("    </p>\n");
372                 }
373
374                 print_nextprev($r, $event, $where, \%settings, \%defsettings);
375                 Sesse::pr0n::Common::footer($r);
376         }
377
378         return Apache2::Const::OK;
379 }
380
381 sub eq_with_undef {
382         my ($a, $b) = @_;
383         
384         return 1 if (!defined($a) && !defined($b));
385         return 0 unless (defined($a) && defined($b));
386         return ($a eq $b);
387 }
388
389 sub print_changes {
390         my ($r, $event, $template, $settings, $defsettings, $var1, $var2, $alternatives) = @_;
391
392         my $title = Sesse::pr0n::Templates::fetch_template($r, $template);
393         chomp $title;
394         $r->print("    <p>$title:\n");
395
396         for my $a (@$alternatives) {
397                 my $text;
398                 my %newsettings = %$settings;
399
400                 if (ref $a) {
401                         my ($v1, $v2);
402                         ($text, $v1, $v2) = @$a;
403                         
404                         $newsettings{$var1} = $v1;
405                         $newsettings{$var2} = $v2;
406                 } else {
407                         $text = $a;
408
409                         # Parse the current alternative
410                         my ($v1, $v2) = split /x/, $a;
411
412                         $newsettings{$var1} = $v1;
413                         $newsettings{$var2} = $v2;
414                 }
415
416                 $r->print("      ");
417
418                 # Check if these settings are current (print only label)
419                 if (eq_with_undef($settings->{$var1}, $newsettings{$var1}) &&
420                     eq_with_undef($settings->{$var2}, $newsettings{$var2})) {
421                         $r->print($text);
422                 } else {
423                         Sesse::pr0n::Common::print_link($r, $text, "/$event/", \%newsettings, $defsettings);
424                 }
425                 $r->print("\n");
426         }
427         $r->print("    </p>\n");
428 }
429
430 sub print_thumbsize {
431         my ($r, $event, $settings, $defsettings) = @_;
432         my @alternatives = qw(80x64 120x96 160x128 240x192 320x256);
433
434         print_changes($r, $event, 'thumbsize', $settings, $defsettings,
435                       'thumbxres', 'thumbyres', \@alternatives);
436 }
437 sub print_viewres {
438         my ($r, $event, $settings, $defsettings) = @_;
439         my @alternatives = qw(320x256 512x384 640x480 800x600 1024x768 1280x960);
440         chomp (my $unlimited = Sesse::pr0n::Templates::fetch_template($r, 'viewres-unlimited'));
441         chomp (my $original = Sesse::pr0n::Templates::fetch_template($r, 'viewres-original'));
442         push @alternatives, [ $unlimited, undef, undef ];
443         push @alternatives, [ $original, -1, -1 ];
444
445         print_changes($r, $event, 'viewres', $settings, $defsettings,
446                       'xres', 'yres', \@alternatives);
447 }
448
449 sub print_pagelimit {
450         my ($r, $event, $settings, $defsettings) = @_;
451         
452         my $title = Sesse::pr0n::Templates::fetch_template($r, 'imgsperpage');
453         chomp $title;
454         $r->print("    <p>$title:\n");
455         
456         # Get choices
457         chomp (my $unlimited = Sesse::pr0n::Templates::fetch_template($r, 'imgsperpage-unlimited'));
458         my @alternatives = qw(10 50 100 500);
459         push @alternatives, $unlimited;
460         
461         for my $num (@alternatives) {
462                 my %newsettings = %$settings;
463
464                 if ($num !~ /^\d+$/) { # unlimited
465                         $newsettings{'num'} = -1;
466                 } else {
467                         $newsettings{'num'} = $num;
468                 }
469
470                 $r->print("      ");
471                 if (eq_with_undef($settings->{'num'}, $newsettings{'num'})) {
472                         $r->print($num);
473                 } else {
474                         Sesse::pr0n::Common::print_link($r, $num, "/$event/", \%newsettings, $defsettings);
475                 }
476                 $r->print("\n");
477         }
478         $r->print("    </p>\n");
479 }
480
481 sub print_infobox {
482         my ($r, $event, $settings, $defsettings) = @_;
483
484         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'infobox'));
485         chomp (my $on = Sesse::pr0n::Templates::fetch_template($r, 'infobox-on'));
486         chomp (my $off = Sesse::pr0n::Templates::fetch_template($r, 'infobox-off'));
487
488         $r->print("    <p>$title:\n");
489
490         my %newsettings = %$settings;
491
492         if ($settings->{'infobox'} == 1) {
493                 $r->print($on);
494         } else {
495                 $newsettings{'infobox'} = 1;
496                 Sesse::pr0n::Common::print_link($r, $on, "/$event/", \%newsettings, $defsettings);
497         }
498
499         $r->print(' ');
500
501         if ($settings->{'infobox'} == 0) {
502                 $r->print($off);
503         } else {
504                 $newsettings{'infobox'} = 0;
505                 Sesse::pr0n::Common::print_link($r, $off, "/$event/", \%newsettings, $defsettings);
506         }
507         
508         $r->print('</p>');
509 }
510
511 sub print_nextprev {
512         my ($r, $event, $where, $settings, $defsettings) = @_;
513         my $start = $settings->{'start'};
514         my $num = $settings->{'num'};
515         my $dbh = Sesse::pr0n::Common::get_dbh();
516
517         $num = undef if (defined($num) && $num == -1);
518         return unless (defined($start) && defined($num));
519
520         # determine total number
521         my $ref = $dbh->selectrow_hashref("SELECT count(*) AS num_images FROM images WHERE vhost=? $where",
522                 undef, $r->get_server_name)
523                 or dberror($r, "image enumeration");
524         my $num_images = $ref->{'num_images'};
525
526         return if ($start == 1 && $start + $num >= $num_images);
527
528         my $end = $start + $num - 1;
529         if ($end > $num_images) {
530                 $end = $num_images;
531         }
532
533         $r->print("    <p class=\"nextprev\">\n");
534
535         # Previous
536         if ($start > 1) {
537                 my $newstart = $start - $num;
538                 if ($newstart < 1) {
539                         $newstart = 1;
540                 }
541                 my $newend = $newstart + $num - 1;
542                 if ($newend > $num_images) {
543                         $newend = $num_images;
544                 }
545
546                 my %newsettings = %$settings;
547                 $newsettings{'start'} = $newstart;
548                 chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'prevpage'));
549                 chomp (my $accesskey = Sesse::pr0n::Templates::fetch_template($r, 'prevaccesskey'));
550                 Sesse::pr0n::Common::print_link($r, "$title ($newstart-$newend)\n", "/$event/", \%newsettings, $defsettings, $accesskey);
551         }
552
553         # This
554         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'thispage'));
555         $r->print("    $title ($start-$end)\n");
556
557         # Next
558         if ($end < $num_images) {
559                 my $newstart = $start + $num;
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, 'nextpage'));
568                 chomp (my $accesskey = Sesse::pr0n::Templates::fetch_template($r, 'nextaccesskey'));
569                 Sesse::pr0n::Common::print_link($r, "$title ($newstart-$newend)", "/$event/", \%newsettings, $defsettings, $accesskey);
570         }
571
572         $r->print("    </p>\n");
573 }
574
575 sub print_selected {
576         my ($r, $event, $settings, $defsettings) = @_;
577
578         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'show'));
579         chomp (my $all = Sesse::pr0n::Templates::fetch_template($r, 'show-all'));
580         chomp (my $sel = Sesse::pr0n::Templates::fetch_template($r, 'show-selected'));
581
582         $r->print("    <p>$title:\n");
583
584         my %newsettings = %$settings;
585
586         if ($settings->{'all'} == 0) {
587                 $r->print($sel);
588         } else {
589                 $newsettings{'all'} = 0;
590                 Sesse::pr0n::Common::print_link($r, $sel, "/$event/", \%newsettings, $defsettings);
591         }
592
593         $r->print(' ');
594
595         if ($settings->{'all'} == 1) {
596                 $r->print($all);
597         } else {
598                 $newsettings{'all'} = 1;
599                 Sesse::pr0n::Common::print_link($r, $all, "/$event/", \%newsettings, $defsettings);
600         }
601         
602         $r->print('</p>');
603 }
604
605 sub print_fullscreen {
606         my ($r, $event, $settings, $defsettings) = @_;
607
608         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'fullscreen'));
609
610         my %newsettings = %$settings;
611         $newsettings{'fullscreen'} = 1;
612
613         $r->print("    <p>");
614         Sesse::pr0n::Common::print_link($r, $title, "/$event/", \%newsettings, $defsettings);
615         $r->print("</p>\n");
616 }
617
618 sub print_fullscreen_fromhere {
619         my ($r, $event, $settings, $defsettings, $start) = @_;
620
621         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'fullscreen-fromhere'));
622
623         my %newsettings = %$settings;
624         $newsettings{'fullscreen'} = 1;
625         $newsettings{'start'} = $start;
626
627         $r->print("    <p class=\"fsfromhere\">");
628         Sesse::pr0n::Common::print_link($r, $title, "/$event/", \%newsettings, $defsettings);
629         $r->print("</p>\n");
630 }
631         
632 1;
633
634