# The LearningOnline Network # Search for a user # # $Id: lonpickuser.pm,v 1.6 2016/09/05 01:46:08 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # # This file is part of the LearningOnline Network with CAPA (LON-CAPA). # # LON-CAPA is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # LON-CAPA is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with LON-CAPA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ # ### =head1 NAME Apache::lonpickuser.pm =head1 SYNOPSIS Allows users to search by username, lastname, or lastname,firstname in LON-CAPA, and also in an institutional directory (if enabled). This is part of the LearningOnline Network with CAPA project described at http://www.lon-capa.org. =head1 SUBROUTINES =over =item handler() =item gochoose_javascript() =back =cut package Apache::lonpickuser; use strict; use Apache::Constants qw(:common :http); use Apache::lonnet; use Apache::loncommon; use Apache::lonlocal; use Apache::lonuserutils; use Apache::loncreateuser; use LONCAPA; sub handler { my ($r) = @_; &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK if $r->header_only; # Get parameters from query string &Apache::loncommon::get_unprocessed_cgi ($ENV{'QUERY_STRING'},['srchdom','form','udomelement','unameelement','ulastelement', 'ufirstelement','uemailelement','hideudomelement','coursedom','caller']); my $js; 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; } my %toset = ( uname => 'unameelement', udom => 'udomelement', first => 'ufirstelement', lastn => 'ulastelement', email => 'uemailelement', hidedom => 'hideudomelement', ); my @search = ('srchterm','srchby','srchin','srchtype','srchdomain'); my %srch; foreach my $item (@search) { $srch{$item} = $env{'form.'.$item}; } my $forcenewuser; my $context = 'requestcrs'; my $usertype; if (($srch{'srchin'} eq 'dom') && ($srch{'srchby'} eq 'uname') && ($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, \%curr_rules,\%got_rules); } my $dom = $env{'form.coursedom'}; my $cancreate = &Apache::lonuserutils::can_create_user($dom,$context,$usertype); my ($userpicker,$cansearch) = &Apache::loncommon::user_picker($dom,\%srch,$forcenewuser, 'document.userpicker',$cancreate, $usertype,$context); my $srchbutton = &mt('Search'); my $headertext = &mt('Search for a user to add to course personnel'); my $opener_elems = ''."\n". ''."\n". &set_opener_elems(); unless ($env{'form.phase'} eq 'define_newuser') { if ($cansearch) { $r->print(<<"ENDBLOCK");

$headertext

$opener_elems $userpicker
ENDBLOCK } else { $r->print(<<"ENDBLOCK");
$opener_elems
ENDBLOCK } } if (($env{'form.phase'} eq 'get_user_info') && ($env{'form.srchterm'} ne '')) { $r->print('
'.&mt('Searching ...').'
'); $r->rflush(); my ($currstate,$response,$forcenewuser,$results) = &Apache::loncreateuser::user_search_result($context,\%srch); if (($currstate eq 'select') || ($currstate eq 'modify')) { &Apache::loncreateuser::print_user_selection_page($r,$response,\%srch,$results, \@search,$context,$opener_elems); } else { $r->print('
'.$response.'
'); if ($forcenewuser) { if ($srch{'srchby'} eq 'uname' && $srch{'srchtype'} eq 'exact' && $srch{'srchin'} eq 'dom' && $srch{'srchdomain'} eq $env{'form.coursedom'}) { if ($cancreate) { $r->print("\n".'
'); foreach my $item (keys(%srch)) { $r->print(''."\n"); } $r->print(' &"').'" />'."\n". $opener_elems.'
'); } else { my $helplink = 'javascript:helpMenu('."'display'".')'; my %usertypetext = &Apache::lonlocal::texthash( official => 'You are not authorized to create new institutional users in this domain.', unofficial => 'You are not authorized to create new non-institutional users in this domain.', ); $r->print('
'. $usertypetext{$usertype}.' '. &mt('Please contact the [_1]helpdesk[_2] for assistance.','','').'
'); } } } } } if ($env{'form.phase'} eq 'define_newuser') { $r->print('

'.&mt('Define new user').' '.$srch{'srchterm'}.':'. $srch{'srchdomain'}.'

'."\n".'
'. '
'."\n". ''."\n". $opener_elems. &Apache::lonhtmlcommon::start_pick_box()."\n". &Apache::lonhtmlcommon::row_title(&mt('First Name')). ''. &Apache::lonhtmlcommon::row_closure()."\n". &Apache::lonhtmlcommon::row_title(&mt('Last Name')). '' . &Apache::lonhtmlcommon::row_closure()."\n". &Apache::lonhtmlcommon::row_title(&mt('E-mail Address')). '' . &Apache::lonhtmlcommon::row_closure(1)."\n". &Apache::lonhtmlcommon::end_pick_box()); foreach my $item (keys(%srch)) { $r->print(''."\n"); } $r->print('
'."\n". '
'); } $r->print(&Apache::loncommon::end_page()); return OK; } sub gochoose_javascript { return <<"ENDGC"; ENDGC } sub check_user_form { return '
'."\n". &set_opener_elems().'
'."\n"; } sub set_opener_elems { my %toset = ( uname => 'unameelement', udom => 'udomelement', first => 'ufirstelement', lastn => 'ulastelement', email => 'uemailelement', hidedom => 'hideudomelement', ); my $output; foreach my $item (keys(%toset)) { if (exists($env{'form.'.$toset{$item}})) { $output .= ''."\n"; } } return $output; } 1;