| 1 | |
|---|
| 2 | |
|---|
| 3 | use warnings; |
|---|
| 4 | use strict; |
|---|
| 5 | |
|---|
| 6 | use CGI; |
|---|
| 7 | use OpenGuides::Config; |
|---|
| 8 | use OpenGuides::CGI; |
|---|
| 9 | use OpenGuides::Utils; |
|---|
| 10 | use OpenGuides::Template; |
|---|
| 11 | |
|---|
| 12 | my $config_file = $ENV{OPENGUIDES_CONFIG_FILE} || "wiki.conf"; |
|---|
| 13 | my $config = OpenGuides::Config->new( file => $config_file ); |
|---|
| 14 | my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); |
|---|
| 15 | my $cgi = CGI->new(); |
|---|
| 16 | my $action = $cgi->param('action') || ''; |
|---|
| 17 | |
|---|
| 18 | if ( $action eq "set_preferences" ) { |
|---|
| 19 | set_preferences(); |
|---|
| 20 | } else { |
|---|
| 21 | show_form(); |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | exit 0; |
|---|
| 25 | |
|---|
| 26 | sub set_preferences { |
|---|
| 27 | my $username = $cgi->param("username") || ""; |
|---|
| 28 | my $gc_link = $cgi->param("include_geocache_link") || 0; |
|---|
| 29 | my $pre_above = $cgi->param("preview_above_edit_box") || 0; |
|---|
| 30 | my $latlong_trad = $cgi->param("latlong_traditional") || 0; |
|---|
| 31 | my $omit_hlplnks = $cgi->param("omit_help_links") || 0; |
|---|
| 32 | my $rc_minor_eds = $cgi->param("show_minor_edits_in_rc") || 0; |
|---|
| 33 | my $edit_type = $cgi->param("default_edit_type") || "normal"; |
|---|
| 34 | my $expires = $cgi->param("cookie_expires") || "month"; |
|---|
| 35 | my $track_rc = $cgi->param("track_recent_changes_views") || 0; |
|---|
| 36 | my $gmaps = $cgi->param("display_google_maps") || 0; |
|---|
| 37 | my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie( |
|---|
| 38 | config => $config, |
|---|
| 39 | username => $username, |
|---|
| 40 | include_geocache_link => $gc_link, |
|---|
| 41 | preview_above_edit_box => $pre_above, |
|---|
| 42 | latlong_traditional => $latlong_trad, |
|---|
| 43 | omit_help_links => $omit_hlplnks, |
|---|
| 44 | show_minor_edits_in_rc => $rc_minor_eds, |
|---|
| 45 | default_edit_type => $edit_type, |
|---|
| 46 | cookie_expires => $expires, |
|---|
| 47 | track_recent_changes_views => $track_rc, |
|---|
| 48 | display_google_maps => $gmaps |
|---|
| 49 | ); |
|---|
| 50 | my @cookies = ( $prefs_cookie ); |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | if ( ! $track_rc ) { |
|---|
| 54 | my $rc_cookie = OpenGuides::CGI->make_recent_changes_cookie( |
|---|
| 55 | config => $config, |
|---|
| 56 | clear_cookie => 1, |
|---|
| 57 | ); |
|---|
| 58 | push @cookies, $rc_cookie; |
|---|
| 59 | } |
|---|
| 60 | print OpenGuides::Template->output( |
|---|
| 61 | wiki => $wiki, |
|---|
| 62 | config => $config, |
|---|
| 63 | template => "preferences.tt", |
|---|
| 64 | cookies => \@cookies, |
|---|
| 65 | vars => { |
|---|
| 66 | not_editable => 1, |
|---|
| 67 | username => $username, |
|---|
| 68 | include_geocache_link => $gc_link, |
|---|
| 69 | preview_above_edit_box => $pre_above, |
|---|
| 70 | latlong_traditional => $latlong_trad, |
|---|
| 71 | omit_help_links => $omit_hlplnks, |
|---|
| 72 | show_minor_edits_in_rc => $rc_minor_eds, |
|---|
| 73 | default_edit_type => $edit_type, |
|---|
| 74 | cookie_expires => $expires, |
|---|
| 75 | track_recent_changes_views => $track_rc, |
|---|
| 76 | display_google_maps => $gmaps |
|---|
| 77 | } |
|---|
| 78 | ); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | sub show_form { |
|---|
| 82 | |
|---|
| 83 | my %prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config ); |
|---|
| 84 | |
|---|
| 85 | print OpenGuides::Template->output( |
|---|
| 86 | wiki => $wiki, |
|---|
| 87 | config => $config, |
|---|
| 88 | template => "preferences.tt", |
|---|
| 89 | vars => { %prefs, |
|---|
| 90 | not_editable => 1, |
|---|
| 91 | show_form => 1 |
|---|
| 92 | } |
|---|
| 93 | ); |
|---|
| 94 | } |
|---|