[LON-CAPA-cvs] cvs: loncom /interface lonpickuser.pm
raeburn
raeburn@source.lon-capa.org
Tue, 04 Aug 2009 20:08:34 -0000
raeburn Tue Aug 4 20:08:34 2009 EDT
Added files:
/loncom/interface lonpickuser.pm
Log:
- Directory search (within LON-CAPA domain or within institutional directory for the domain - if available). Information for selected user is copied to appropriate for elements in window's opener.
- Similar behavior to lonpickcourse.pm
- Used by lonrequestcourse.pm for requesting additional course personnel.
Index: loncom/interface/lonpickuser.pm
+++ loncom/interface/lonpickuser.pm
# 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 .= '<input type="hidden" name="'.$toset{$item}.'" value="'.$env{'form.'.$toset{$item}}.'" />'."\n";
}
}
$r->print(<<"ENDBLOCK");
<h3>$headertext</h3>
<form action="/adm/pickuser" method="post" name="userpicker">
$opener_elems
<input type="hidden" name="phase" value="get_user_info" />
<input type="hidden" name="form" value="$env{'form.form'}" />
$userpicker
<input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.userpicker)" />
</form>
ENDBLOCK
if ($env{'form.phase'} eq 'get_user_info') {
$r->print('<hr /><div>'.&mt('Searching ...').'</div>');
$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('<div>'.$response.'</div>');
}
}
$r->print(&Apache::loncommon::end_page());
return OK;
}
sub gochoose_javascript {
return <<"ENDGC";
<script type="text/javascript">
function gochoose(uname,udom,ufirst,ulast,uemail) {
opener.document.$env{'form.form'}.$env{'form.unameelement'}.value=uname;
opener.document.$env{'form.form'}.$env{'form.ufirstelement'}.value=ufirst;
opener.document.$env{'form.form'}.$env{'form.ulastelement'}.value=ulast;
opener.document.$env{'form.form'}.$env{'form.uemailelement'}.value=uemail;
var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
if (slct.options == undefined) {
opener.document.$env{'form.form'}.$env{'form.udomelement'}.value=udom;
}
else {
var i;
for (i=0;i<slct.length;i++) {
if (slct.options[i].value==udom) { slct.selectedIndex=i; }
}
}
opener.document.$env{'form.form'}.$env{'form.hideudomelement'}.value=udom;
self.close();
}
</script>
ENDGC
}
1;