source: trunk/preferences.cgi @ 52

Last change on this file since 52 was 52, checked in by kake, 19 years ago

username.cgi is now preferences.cgi and sets preference for including geocaches link in navbar, as well as username

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1#!/usr/bin/perl -w
2
3use strict;
4use CGI;
5use CGI::Cookie;
6use Config::Tiny;
7use Template;
8
9my $cgi = CGI->new();
10my $action = $cgi->param('action') || '';
11
12if ( $action eq "set_preferences" ) {
13    set_preferences();
14} else {
15    show_form();
16}
17
18exit 0;
19
20sub set_preferences {
21    my $username = $cgi->param("username") || "";
22    my $gc_link  = $cgi->param('include_geocache_link') || 0,
23    my @cookies;
24    push @cookies, CGI::Cookie->new( -name    => 'username',
25                                     -value   => $username,
26                                     -expires => '+12M',
27    );
28
29    push @cookies, CGI::Cookie->new( -name    => 'include_geocache_link',
30                                     -value   => $gc_link,
31                                     -expires => '+12M',
32    );
33    print $cgi->header( -cookie => \@cookies );
34
35    process_prefs_template( username              => $username,
36                            include_geocache_link => $gc_link );
37}
38
39
40sub show_form {
41    # Get defaults for form fields from cookies.
42    my %cookies = CGI::Cookie->fetch;
43    my $username = $cookies{"username"} ? $cookies{"username"}->value : "";
44    my $gc_link  = $cookies{"include_geocache_link"} ? $cookies{"include_geocache_link"}->value : 0;
45
46    print $cgi->header;
47    process_prefs_template( show_form             => 1,
48                            username              => $username,
49                            include_geocache_link => $gc_link );
50}
51
52
53sub process_prefs_template {
54    # Some TT params are passed in to the sub.
55    my %tt_vars = @_;
56
57    # Others are global and we get them from the config file.
58    my $config = Config::Tiny->read("wiki.conf");
59    foreach my $param ( qw( site_name stylesheet_url script_name home_name
60                            ) ) {
61        $tt_vars{$param} = $config->{_}->{$param};
62    }
63
64    # This isn't a page you can edit.
65    $tt_vars{not_editable} = 1;
66
67    my %tt_conf = ( INCLUDE_PATH => $config->{_}->{template_path},
68    );
69
70    my $tt = Template->new( \%tt_conf );
71    $tt->process( "preferences.tt", \%tt_vars ) or warn $tt->error;
72}
73 
Note: See TracBrowser for help on using the repository browser.