Merge branch 'master' of ssh://git.freeside.biz/home/git/freeside
[freeside.git] / httemplate / edit / access_user.html
index 73488ef..f40575c 100644 (file)
@@ -2,32 +2,41 @@
                  'name'   => 'Employee',
                  'table'  => 'access_user',
                  'fields' => [
-                               'username',
-                               { field=>'_password', type=>'password' },
-                               { field=>'_password2', type=>'password' },
-                               'last',
-                               'first',
-                               { field=>'disabled', type=>'checkbox', value=>'Y' },
-                             ],
+                   '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',
-                               'disabled'  => 'Disable employee',
-                             },
-                 'edit_callback' => sub { my( $c, $o ) = @_; 
-                                          $o->set('_password', '');
-                                        },
+                   '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>Employee Groups<BR>'.
-                     ntable("#cccccc",2).
+                     '<BR>'.
+                     '<FONT CLASS="fsinnerbox-title">Employee Groups</FONT>'.
+                     '<BR>'.
+                     '<TABLE CLASS="fsinnerbox">'.
                      '<TR><TD>'.
                      include( '/elements/checkboxes-table.html',
                                 'source_obj'   => $access_user,
@@ -40,6 +49,9 @@
                      '</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>