installers, RT#16584
[freeside.git] / httemplate / edit / process / access_user.html
1 %  if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
2 %    $cgi->param('error', "The passwords do not match");
3 %    print $cgi->redirect(popurl(2) . "access_user.html?" . $cgi->query_string);
4 %  } else {
5 <%   include( 'elements/process.html',
6                  'table'       => 'access_user',
7                  'viewall_dir' => 'browse',
8                  'copy_on_empty' => [ '_password' ],
9                  'clear_on_error' => [ '_password', '_password2' ],
10                  'process_m2m' => { 'link_table'   => 'access_usergroup',
11                                     'target_table' => 'access_group',
12                                   },
13                  'precheck_callback'=> \&precheck_callback,
14                  'noerror_callback' => \&noerror_callback,
15              )
16 %>
17 %   }
18 <%init>
19
20 die "access denied"
21   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
22
23 if ( FS::Conf->new->exists('disable_acl_changes') ) {
24   errorpage('ACL changes disabled in public demo.');
25   die "shouldn't be reached";
26 }
27
28 sub precheck_callback {
29   my $cgi = shift;
30   my $o = FS::access_user->new({username => $cgi->param('username')});
31   if( $o->is_system_user and !$cgi->param('usernum') ) {
32     $cgi->param('username','');
33     return "username '".$o->username."' reserved for system account."
34   }
35   return '';
36 }
37
38 sub noerror_callback {
39   my( $cgi, $access_user ) = @_;
40
41   #handle installer checkbox
42   my @sched_item = $access_user->sched_item;
43   my $sched_item = $sched_item[0];
44   if ( $cgi->param('sched_item_enabled') ) {
45
46     if ( ! $sched_item ) {
47       my $sched_item = new FS::sched_item {
48         'usernum' => $access_user->usernum,
49       };
50       my $error = $sched_item->insert;
51       die $error if $error; #wtf?  shouldn't happen
52     } elsif ( $sched_item->disabled ) {
53       $sched_item->disabled('');
54       my $error = $sched_item->replace;
55       die $error if $error; #wtf?  shouldn't happen
56     }
57
58   } elsif ( ! $cgi->param('sched_item_enabled')
59               && $sched_item
60               && ! $sched_item->disabled
61           )
62   {
63     $sched_item->disabled('Y');
64     my $error = $sched_item->replace;
65     die $error if $error; #wtf?  shouldn't happen
66   }
67
68 }
69
70 </%init>