Merge branch 'patch-18' of https://github.com/gjones2/Freeside
[freeside.git] / httemplate / pref / pref-process.html
1 % if ( $error ) {
2 %   $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(1). "pref.html?". $cgi->query_string ) %>
4 % } else {
5 <% include('/elements/header.html', 'Preferences updated') %>
6 <% include('/elements/footer.html') %>
7 % }
8 <%init>
9
10 if ( FS::Conf->new->exists('disable_acl_changes') ) {
11   errorpage("Preference changes disabled in public demo");
12   die "shouldn't be reached";
13 }
14
15 my $error = '';
16 my $access_user = '';
17
18 if ( grep { $cgi->param($_) !~ /^\s*$/ }
19           qw(_password new_password new_password2)
20    ) {
21
22   $access_user = qsearchs( 'access_user', {
23     'username'  => getotaker,
24     '_password' => scalar($cgi->param('_password')),
25   } );
26
27   $error = 'Current password incorrect; password not changed'
28     unless $access_user;
29
30   $error ||= "New passwords don't match"
31     unless $cgi->param('new_password') eq $cgi->param('new_password2');
32
33   $error ||= "No new password entered"
34    unless length($cgi->param('new_password'));
35
36   $access_user->_password($cgi->param('new_password')) unless $error;
37
38 } else {
39
40   $access_user = $FS::CurrentUser::CurrentUser;
41
42 }
43
44 #well, if you got your password change wrong, you don't get anything else
45 #changed right now.  but it should be sticky on the form
46 unless ( $error ) { # if ($access_user) {
47
48   my %param = $access_user->options;
49
50   #XXX autogen
51   my @paramlist = qw( locale menu_position default_customer_view 
52                       history_order
53                       spreadsheet_format mobile_menu
54                       enable_fuzzy_on_exact
55                       disable_html_editor disable_enter_submit_onetimecharge
56                       email_address
57                       snom-ip snom-username snom-password
58                       vonage-fromnumber vonage-username vonage-password
59                       cust_pkg-display_times
60                       show_pkgnum show_confitem_counts export_getsettings
61                       show_db_profile save_db_profile save_tmp_typesetting
62                       height width availHeight availWidth colorDepth
63                     );
64
65   foreach (@paramlist) {
66     scalar($cgi->param($_)) =~ /^[,.\-\@\w]*$/ && next;
67     $error ||= "Illegal value for parameter $_";
68     last;
69   }
70
71   foreach (@paramlist) {
72     $param{$_} = scalar($cgi->param($_));
73   }
74
75   $error ||= $access_user->replace( \%param );
76
77 }
78
79 if ( !$error and ($FS::TicketSystem::system || '') eq 'RT_Internal' ) {
80   # sync RT user locale on every update
81   my $locale = $access_user->option('locale');
82   FS::TicketSystem->init;
83   my $UserObj = FS::TicketSystem->session('')->{'CurrentUser'}->UserObj;
84   # Bypass RT ModifySelf ACL
85   $UserObj->CurrentUser( RT::SystemUser );
86   if ( $UserObj->Lang ne $locale ) {
87     my ($val, $msg) = $UserObj->SetLang($locale);
88     $error = $msg if !$val;
89   }
90 }
91 </%init>