--- loncom/interface/lonpickuser.pm 2009/08/04 20:08:34 1.1 +++ loncom/interface/lonpickuser.pm 2016/09/05 01:46:08 1.6 @@ -1,7 +1,7 @@ # The LearningOnline Network # Search for a user # -# $Id: lonpickuser.pm,v 1.1 2009/08/04 20:08:34 raeburn Exp $ +# $Id: lonpickuser.pm,v 1.6 2016/09/05 01:46:08 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -71,15 +71,116 @@ sub handler { # Get parameters from query string &Apache::loncommon::get_unprocessed_cgi ($ENV{'QUERY_STRING'},['srchdom','form','udomelement','unameelement','ulastelement', - 'ufirstelement','uemailelement','hideudomelement']); + 'ufirstelement','uemailelement','hideudomelement','coursedom','caller']); my $js; - if ($env{'form.phase'} eq 'get_user_info') { + if (($env{'form.phase'} eq 'get_user_info') || + ($env{'form.phase'} eq 'store_newuser')) { $js = &gochoose_javascript(); + } elsif ($env{'form.phase'} eq 'define_newuser') { + $js = <<"ENDSP"; + +ENDSP + } elsif ($env{'form.caller'} eq 'checkusername') { + $js = <<"ENDCHK"; + +ENDCHK + } elsif ($env{'form.phase'} eq '') { + $js = <<"ENDSET"; + +ENDSET + } + my $startargs = {'no_nav_bar' => 1, }; + if ($env{'form.phase'} eq 'store_newuser') { + my $uname = $env{'form.srchterm'}; + my $udom = $env{'form.srchdomain'}; + my $newfirst = $env{'form.newfirst'}; + my $newlast = $env{'form.newlast'}; + my $newemail = $env{'form.newemail'}; + $startargs->{'add_entries'} = { onload => 'javascript:gochoose('."'$uname','$udom','$newfirst','$newlast','$newemail'".');' }; + } elsif ($env{'form.caller'} eq 'checkusername') { + $startargs->{'add_entries'} = { onload => 'javascript:checkUser();' }; + } elsif ($env{'form.phase'} eq '') { + $startargs->{'add_entries'} = { onload => 'javascript:setUserSearch();' }; + } + $r->print(&Apache::loncommon::start_page('Selecting course personnel', + $js,$startargs)); + if ($env{'form.caller'} eq 'checkusername') { + $r->print(&check_user_form(). + &Apache::loncommon::end_page()); + return OK; } - - $r->print(&Apache::loncommon::start_page('Selecting course personnel',$js, - {'no_nav_bar' => 1, })); my %toset = ( uname => 'unameelement', udom => 'udomelement', @@ -102,39 +203,52 @@ sub handler { ($srch{'srchtype'} eq 'exact') && ($srch{'srchdomain'} ne '') && ($srch{'srchterm'} ne '')) { + my (%curr_rules,%got_rules); my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($srch{'srchdomain'},'username'); $usertype = &Apache::lonuserutils::check_usertype($srch{'srchdomain'}, - $srch{'srchterm'},$rules); + $srch{'srchterm'},$rules, + \%curr_rules,\%got_rules); } - my $dom = $env{'form.srchdom'}; + my $dom = $env{'form.coursedom'}; my $cancreate = &Apache::lonuserutils::can_create_user($dom,$context,$usertype); - my $userpicker = + my ($userpicker,$cansearch) = &Apache::loncommon::user_picker($dom,\%srch,$forcenewuser, - 'document.userpicker',$cancreate,$usertype); + 'document.userpicker',$cancreate, + $usertype,$context); my $srchbutton = &mt('Search'); my $headertext = &mt('Search for a user to add to course personnel'); - my $opener_elems; - foreach my $item (keys(%toset)) { - if (exists($env{'form.'.$toset{$item}})) { - $opener_elems .= ''."\n"; - } - } - $r->print(<<"ENDBLOCK"); + my $opener_elems = ''."\n". + ''."\n". + &set_opener_elems(); + unless ($env{'form.phase'} eq 'define_newuser') { + if ($cansearch) { + + $r->print(<<"ENDBLOCK");