summaryrefslogtreecommitdiff
path: root/httemplate/edit/access_user.html
blob: f40575c0bfc7f1961b30fcaa07fca6ea35544e02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<% include( 'elements/edit.html',
                 'name'   => 'Employee',
                 'table'  => 'access_user',
                 'fields' => [
                   'username',
                   @pw_fields,
                   'last',
                   'first',
                   { field=>'sched_item_enabled', type=>'checkbox', value=>'Y' },
                   { field=>'user_custnum', type=>'search-cust_main', },
                   { field       => 'report_salesnum',
                     type        => 'select-sales',
                     empty_label => 'all',
                   },
                   { field=>'disabled', type=>'checkbox', value=>'Y' },
                 ],
                 'labels' => { 
                   'usernum'            => 'User number',
                   'username'           => 'Username',
                   '_password'          => 'Password',
                   '_password2'         => 'Re-enter Password',
                   'last'               => 'Last name',
                   'first'              => 'First name',
                   'sched_item_enabled' => 'Installer',
                   'user_custnum'       => 'Customer (optional)',
                   'report_salesnum'    => 'Limit commission report to sales person',
                   'disabled'           => 'Disable employee',
                 },
                 'edit_callback' => \&edit_callback,
                 'field_callback'=> \&field_callback,
                 'viewall_dir' => 'browse',
                 'html_bottom' =>
                   sub {
                     my $access_user = shift;

                     '<BR>'.
                     '<FONT CLASS="fsinnerbox-title">Employee Groups</FONT>'.
                     '<BR>'.
                     '<TABLE CLASS="fsinnerbox">'.
                     '<TR><TD>'.
                     include( '/elements/checkboxes-table.html',
                                'source_obj'   => $access_user,
                                'link_table'   => 'access_usergroup',
                                'target_table' => 'access_group',
                                'name_col'     => 'groupname',
                                'target_link'  => $p.'edit/access_group.html?',
                                #'disable-able' => 1,
                            ).
                     '</TR></TD></TABLE>'
                     ;
                   },
                 'onsubmit'  => 'check_user_custnum_search',
                 'html_foot' => $check_user_custnum_search,
                 'html_table_class' => 'fsinnerbox',
           )
%>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');

my @pw_fields =
  FS::Auth->auth_class->can('change_password')
    ? ( { field=>'_password',  type=>'password' },
        { field=>'_password2', type=>'password' },
      )
    : ();

my $check_user_custnum_search = <<END;
  <SCRIPT TYPE="text/javascript">
    function check_user_custnum_search(what) {
      while ( user_custnum_search_active ) {
        // javascript needs ambien
      }
      return true;
    }
  </SCRIPT>
END

sub edit_callback {
  my ($cgi, $access_user, $fields_listref, $opt_hashref) = @_;
  $access_user->_password('');

  my @sched_item = $access_user->sched_item;
  $access_user->sched_item_enabled('Y')
    if $sched_item[0] && ! $sched_item[0]->disabled;
}

sub field_callback {
  my ($c, $o, $f) = @_;
  if($f->{'type'} eq 'password' and $o->is_system_user) {
    $f->{'type'} = 'hidden';
    $f->{'disabled'} = 1;
  }
}

</%init>