File:  [LON-CAPA] / loncom / interface / lonpickuser.pm
Revision 1.1: download - view: text, annotated - select for diffs
Tue Aug 4 20:08:34 2009 UTC (14 years, 10 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- 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.

    1: # The LearningOnline Network
    2: # Search for a user
    3: #
    4: # $Id: lonpickuser.pm,v 1.1 2009/08/04 20:08:34 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###
   29: 
   30: =head1 NAME
   31: 
   32: Apache::lonpickuser.pm
   33: 
   34: =head1 SYNOPSIS
   35: 
   36: Allows users to search by username, lastname, or lastname,firstname in LON-CAPA,
   37: and also in an institutional directory (if enabled).
   38: 
   39: This is part of the LearningOnline Network with CAPA project
   40: described at http://www.lon-capa.org.
   41: 
   42: =head1 SUBROUTINES
   43: 
   44: =over
   45: 
   46: =item handler()
   47: 
   48: =item gochoose_javascript()
   49:  
   50: =back
   51: 
   52: =cut
   53: 
   54: package Apache::lonpickuser;
   55: 
   56: use strict;
   57: use Apache::Constants qw(:common :http);
   58: use Apache::lonnet;
   59: use Apache::loncommon;
   60: use Apache::lonlocal;
   61: use Apache::lonuserutils;
   62: use Apache::loncreateuser;
   63: use LONCAPA;
   64: 
   65: sub handler {
   66:     my ($r) = @_;
   67:     &Apache::loncommon::content_type($r,'text/html');
   68:     $r->send_http_header;
   69:     return OK if $r->header_only;
   70: 
   71:     # Get parameters from query string
   72:     &Apache::loncommon::get_unprocessed_cgi
   73:         ($ENV{'QUERY_STRING'},['srchdom','form','udomelement','unameelement','ulastelement',
   74:                                'ufirstelement','uemailelement','hideudomelement']);
   75:     my $js;
   76: 
   77:     if ($env{'form.phase'} eq 'get_user_info') {
   78:         $js = &gochoose_javascript();
   79:     }
   80: 
   81:     $r->print(&Apache::loncommon::start_page('Selecting course personnel',$js,
   82:                                              {'no_nav_bar'  => 1, }));
   83:     my %toset = (
   84:                   uname   => 'unameelement',
   85:                   udom    => 'udomelement',
   86:                   first   => 'ufirstelement',
   87:                   lastn   => 'ulastelement',
   88:                   email   => 'uemailelement',
   89:                   hidedom => 'hideudomelement',
   90:                 );
   91: 
   92:     my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
   93:     my %srch;
   94:     foreach my $item (@search) {
   95:         $srch{$item} = $env{'form.'.$item};
   96:     }
   97:     my $forcenewuser;
   98:     my $context = 'requestcrs';
   99:     my $usertype;
  100:     if (($srch{'srchin'} eq 'dom') &&
  101:         ($srch{'srchby'} eq 'uname') &&
  102:         ($srch{'srchtype'} eq 'exact') &&
  103:         ($srch{'srchdomain'} ne '') &&
  104:         ($srch{'srchterm'} ne '')) {
  105:         my ($rules,$ruleorder) =
  106:             &Apache::lonnet::inst_userrules($srch{'srchdomain'},'username');
  107:         $usertype = &Apache::lonuserutils::check_usertype($srch{'srchdomain'},
  108:                                                           $srch{'srchterm'},$rules);
  109:     }
  110: 
  111:     my $dom = $env{'form.srchdom'};
  112: 
  113:     my $cancreate =
  114:         &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
  115:     my $userpicker =
  116:        &Apache::loncommon::user_picker($dom,\%srch,$forcenewuser,
  117:                                        'document.userpicker',$cancreate,$usertype);
  118:     my $srchbutton = &mt('Search');
  119: 
  120:     my $headertext = &mt('Search for a user to add to course personnel');  
  121:     my $opener_elems;
  122:     foreach my $item (keys(%toset)) {
  123:         if (exists($env{'form.'.$toset{$item}})) {
  124:             $opener_elems .= '<input type="hidden" name="'.$toset{$item}.'" value="'.$env{'form.'.$toset{$item}}.'" />'."\n";
  125:         }
  126:     } 
  127:     $r->print(<<"ENDBLOCK");
  128: <h3>$headertext</h3>
  129: <form action="/adm/pickuser" method="post" name="userpicker">
  130: $opener_elems
  131: <input type="hidden" name="phase" value="get_user_info" />
  132: <input type="hidden" name="form" value="$env{'form.form'}" />
  133: $userpicker
  134: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.userpicker)" />
  135: </form>
  136: ENDBLOCK
  137:     if ($env{'form.phase'} eq 'get_user_info') {
  138:         $r->print('<hr /><div>'.&mt('Searching ...').'</div>');
  139:         $r->rflush();
  140:         my ($currstate,$response,$forcenewuser,$results) = 
  141:             &Apache::loncreateuser::user_search_result($context,\%srch);
  142:         if (($currstate eq 'select') || ($currstate eq 'modify')) {
  143:             &Apache::loncreateuser::print_user_selection_page($r,$response,\%srch,$results,
  144:                                                               \@search,$context,$opener_elems);
  145:         } else {
  146:             $r->print('<div>'.$response.'</div>');
  147:         }
  148:     }
  149:     $r->print(&Apache::loncommon::end_page());
  150:     return OK;
  151: }
  152: 
  153: sub gochoose_javascript {
  154:     return <<"ENDGC"; 
  155: <script type="text/javascript">
  156: function gochoose(uname,udom,ufirst,ulast,uemail) {
  157:     opener.document.$env{'form.form'}.$env{'form.unameelement'}.value=uname;
  158:     opener.document.$env{'form.form'}.$env{'form.ufirstelement'}.value=ufirst;
  159:     opener.document.$env{'form.form'}.$env{'form.ulastelement'}.value=ulast;
  160:     opener.document.$env{'form.form'}.$env{'form.uemailelement'}.value=uemail;
  161: 
  162:     var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
  163:     if (slct.options == undefined) {
  164:         opener.document.$env{'form.form'}.$env{'form.udomelement'}.value=udom;
  165:     }
  166:     else {
  167:         var i;
  168:         for (i=0;i<slct.length;i++) {
  169:             if (slct.options[i].value==udom) { slct.selectedIndex=i; }
  170:         }
  171:     }
  172:     opener.document.$env{'form.form'}.$env{'form.hideudomelement'}.value=udom;
  173:     self.close();
  174: }
  175: </script>
  176: 
  177: ENDGC
  178: }
  179: 
  180: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>