Changeset 156 for trunk/preferences.cgi
- Timestamp:
- 05/14/03 22:29:51 (6 years ago)
- Files:
-
- 1 modified
-
trunk/preferences.cgi (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/preferences.cgi
r52 r156 3 3 use strict; 4 4 use CGI; 5 use CGI::Cookie;6 5 use Config::Tiny; 7 use Template; 6 use OpenGuides::CGI; 7 use OpenGuides::Utils; 8 use OpenGuides::Template; 8 9 10 my $config = Config::Tiny->read("wiki.conf"); 11 my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); 9 12 my $cgi = CGI->new(); 10 13 my $action = $cgi->param('action') || ''; … … 19 22 20 23 sub 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', 24 my $username = $cgi->param("username") || ""; 25 my $gc_link = $cgi->param('include_geocache_link') || 0; 26 my $pre_above = $cgi->param('preview_above_edit_box') || 0; 27 my $cookie = OpenGuides::CGI->make_prefs_cookie( 28 config => $config, 29 username => $username, 30 include_geocache_link => $gc_link, 31 preview_above_edit_box => $pre_above 27 32 ); 28 29 push @cookies, CGI::Cookie->new( -name => 'include_geocache_link', 30 -value => $gc_link, 31 -expires => '+12M', 33 print OpenGuides::Template->output( 34 wiki => $wiki, 35 config => $config, 36 template => "preferences.tt", 37 cookies => $cookie, 38 vars => { not_editable => 1, 39 username => $username, 40 include_geocache_link => $gc_link, 41 preview_above_edit_box => $pre_above 42 } 32 43 ); 33 print $cgi->header( -cookie => \@cookies );34 35 process_prefs_template( username => $username,36 include_geocache_link => $gc_link );37 44 } 38 39 45 40 46 sub show_form { 41 47 # 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; 48 my %prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config ); 45 49 46 print $cgi->header; 47 process_prefs_template( show_form => 1, 48 username => $username, 49 include_geocache_link => $gc_link ); 50 print OpenGuides::Template->output( 51 wiki => $wiki, 52 config => $config, 53 template => "preferences.tt", 54 vars => { %prefs, 55 not_editable => 1, 56 show_form => 1 57 } 58 ); 50 59 } 51 52 53 sub 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_name60 ) ) {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
