# The LearningOnline Network # Search for a user # # $Id: lonpickuser.pm,v 1.1 2009/08/04 20:08:34 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']); my $js; if ($env{'form.phase'} eq 'get_user_info') { $js = &gochoose_javascript(); } $r->print(&Apache::loncommon::start_page('Selecting course personnel',$js, {'no_nav_bar' => 1, })); 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 ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($srch{'srchdomain'},'username'); $usertype = &Apache::lonuserutils::check_usertype($srch{'srchdomain'}, $srch{'srchterm'},$rules); } my $dom = $env{'form.srchdom'}; my $cancreate = &Apache::lonuserutils::can_create_user($dom,$context,$usertype); my $userpicker = &Apache::loncommon::user_picker($dom,\%srch,$forcenewuser, 'document.userpicker',$cancreate,$usertype); 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");

$headertext

$opener_elems $userpicker
ENDBLOCK if ($env{'form.phase'} eq 'get_user_info') { $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.'
'); } } $r->print(&Apache::loncommon::end_page()); return OK; } sub gochoose_javascript { return <<"ENDGC"; ENDGC } 1;