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