Merge remote-tracking branch 'upstream/master'
[freeside.git] / httemplate / edit / access_user.html
1 <% include( 'elements/edit.html',
2                  'name'   => 'Employee',
3                  'table'  => 'access_user',
4                  'fields' => [
5                                'username',
6                                @pw_fields,
7                                'last',
8                                'first',
9                                { field=>'user_custnum', type=>'search-cust_main', },
10                                { field=>'report_salesnum', type=>'select-sales', empty_label=>'all', },
11                                { field=>'disabled', type=>'checkbox', value=>'Y' },
12                              ],
13                  'labels' => { 
14                                'usernum'         => 'User number',
15                                'username'        => 'Username',
16                                '_password'       => 'Password',
17                                '_password2'      => 'Re-enter Password',
18                                'last'            => 'Last name',
19                                'first'           => 'First name',
20                                'user_custnum'    => 'Customer (optional)',
21                                'report_salesnum' => 'Limit commission report to sales person',
22                                'disabled'        => 'Disable employee',
23                              },
24                  'edit_callback' => \&edit_callback,
25                  'field_callback'=> \&field_callback,
26                  'viewall_dir' => 'browse',
27                  'html_bottom' =>
28                    sub {
29                      my $access_user = shift;
30
31                      '<BR>Employee Groups<BR>'.
32                      ntable("#cccccc",2).
33                      '<TR><TD>'.
34                      include( '/elements/checkboxes-table.html',
35                                 'source_obj'   => $access_user,
36                                 'link_table'   => 'access_usergroup',
37                                 'target_table' => 'access_group',
38                                 'name_col'     => 'groupname',
39                                 'target_link'  => $p.'edit/access_group.html?',
40                                 #'disable-able' => 1,
41                             ).
42                      '</TR></TD></TABLE>'
43                      ;
44                    },
45                  'onsubmit'  => 'check_user_custnum_search',
46                  'html_foot' => $check_user_custnum_search,
47            )
48 %>
49 <%init>
50
51 die "access denied"
52   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
53
54 my @pw_fields =
55   FS::Auth->auth_class->can('change_password')
56     ? ( { field=>'_password',  type=>'password' },
57         { field=>'_password2', type=>'password' },
58       )
59     : ();
60
61 my $check_user_custnum_search = <<END;
62   <SCRIPT TYPE="text/javascript">
63     function check_user_custnum_search(what) {
64       while ( user_custnum_search_active ) {
65         // javascript needs ambien
66       }
67       return true;
68     }
69   </SCRIPT>
70 END
71
72 sub edit_callback {
73   my ($cgi, $access_user, $fields_listref, $opt_hashref) = @_;
74   $access_user->_password('');
75 }
76
77 sub field_callback {
78   my ($c, $o, $f) = @_;
79   if($f->{'type'} eq 'password' and $o->is_system_user) {
80     $f->{'type'} = 'hidden';
81     $f->{'disabled'} = 1;
82   }
83 }
84
85 </%init>