Annotation of loncom/interface/lonpickuser.pm, revision 1.2
1.1 raeburn 1: # The LearningOnline Network
2: # Search for a user
3: #
1.2 ! raeburn 4: # $Id: lonpickuser.pm,v 1.1 2009/08/04 20:08:34 raeburn Exp $
1.1 raeburn 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',
1.2 ! raeburn 74: 'ufirstelement','uemailelement','hideudomelement','coursedom']);
1.1 raeburn 75: my $js;
76:
1.2 ! raeburn 77: if (($env{'form.phase'} eq 'get_user_info') ||
! 78: ($env{'form.phase'} eq 'store_newuser')) {
1.1 raeburn 79: $js = &gochoose_javascript();
1.2 ! raeburn 80: } elsif ($env{'form.phase'} eq 'define_newuser') {
! 81: $js = <<"ENDSP";
! 82: <script type="text/javascript">
! 83: // <![CDATA[
! 84: function setphase(caller) {
! 85: document.newuserinfo.phase.value = caller;
! 86: document.newuserinfo.submit();
! 87: return;
! 88: }
! 89: // ]]>
! 90: </script>
! 91: ENDSP
! 92: }
! 93: my $startargs = {'no_nav_bar' => 1, };
! 94: if ($env{'form.phase'} eq 'store_newuser') {
! 95: my $uname = $env{'form.srchterm'};
! 96: my $udom = $env{'form.srchdomain'};
! 97: my $newfirst = $env{'form.newfirst'};
! 98: my $newlast = $env{'form.newlast'};
! 99: my $newemail = $env{'form.newemail'};
! 100: $startargs->{'add_entries'} = { onload => 'javascript:gochoose('."'$uname','$udom','$newfirst','$newlast','$newemail'".');' };
1.1 raeburn 101: }
1.2 ! raeburn 102: $r->print(&Apache::loncommon::start_page('Selecting course personnel',
! 103: $js,$startargs));
1.1 raeburn 104: my %toset = (
105: uname => 'unameelement',
106: udom => 'udomelement',
107: first => 'ufirstelement',
108: lastn => 'ulastelement',
109: email => 'uemailelement',
110: hidedom => 'hideudomelement',
111: );
112:
113: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
114: my %srch;
115: foreach my $item (@search) {
116: $srch{$item} = $env{'form.'.$item};
117: }
118: my $forcenewuser;
119: my $context = 'requestcrs';
120: my $usertype;
121: if (($srch{'srchin'} eq 'dom') &&
122: ($srch{'srchby'} eq 'uname') &&
123: ($srch{'srchtype'} eq 'exact') &&
124: ($srch{'srchdomain'} ne '') &&
125: ($srch{'srchterm'} ne '')) {
126: my ($rules,$ruleorder) =
127: &Apache::lonnet::inst_userrules($srch{'srchdomain'},'username');
128: $usertype = &Apache::lonuserutils::check_usertype($srch{'srchdomain'},
129: $srch{'srchterm'},$rules);
130: }
131:
1.2 ! raeburn 132: my $dom = $env{'form.coursedom'};
1.1 raeburn 133:
134: my $cancreate =
135: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
136: my $userpicker =
137: &Apache::loncommon::user_picker($dom,\%srch,$forcenewuser,
138: 'document.userpicker',$cancreate,$usertype);
139: my $srchbutton = &mt('Search');
140:
141: my $headertext = &mt('Search for a user to add to course personnel');
1.2 ! raeburn 142: my $opener_elems = '<input type="hidden" name="form" value="'.
! 143: $env{'form.form'}.'" />'."\n".
! 144: '<input type="hidden" name="coursedom" value="'.
! 145: $env{'form.coursedom'}.'" />'."\n";
1.1 raeburn 146: foreach my $item (keys(%toset)) {
147: if (exists($env{'form.'.$toset{$item}})) {
148: $opener_elems .= '<input type="hidden" name="'.$toset{$item}.'" value="'.$env{'form.'.$toset{$item}}.'" />'."\n";
149: }
1.2 ! raeburn 150: }
! 151: unless ($env{'form.phase'} eq 'define_newuser') {
! 152: $r->print(<<"ENDBLOCK");
1.1 raeburn 153: <h3>$headertext</h3>
154: <form action="/adm/pickuser" method="post" name="userpicker">
155: $opener_elems
156: <input type="hidden" name="phase" value="get_user_info" />
157: $userpicker
158: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.userpicker)" />
159: </form>
160: ENDBLOCK
1.2 ! raeburn 161: }
1.1 raeburn 162: if ($env{'form.phase'} eq 'get_user_info') {
163: $r->print('<hr /><div>'.&mt('Searching ...').'</div>');
164: $r->rflush();
165: my ($currstate,$response,$forcenewuser,$results) =
166: &Apache::loncreateuser::user_search_result($context,\%srch);
167: if (($currstate eq 'select') || ($currstate eq 'modify')) {
168: &Apache::loncreateuser::print_user_selection_page($r,$response,\%srch,$results,
169: \@search,$context,$opener_elems);
170: } else {
171: $r->print('<div>'.$response.'</div>');
1.2 ! raeburn 172: if ($forcenewuser) {
! 173: if ($srch{'srchby'} eq 'uname' &&
! 174: $srch{'srchtype'} eq 'exact' &&
! 175: $srch{'srchin'} eq 'dom' &&
! 176: $srch{'srchdomain'} eq $env{'form.coursedom'}) {
! 177: if ($cancreate) {
! 178: $r->print("\n".'<div><form name="newuser" '.
! 179: 'method="post" action="/adm/pickuser">');
! 180: foreach my $item (keys(%srch)) {
! 181: $r->print('<input type="hidden" name="'.$item.'"'.
! 182: ' value="'.$srch{$item}.'" />'."\n");
! 183: }
! 184: $r->print('
! 185: <input type="hidden" name="phase" value="define_newuser">
! 186: <input type="submit" name="forcenew" value="'.
! 187: &HTML::Entities::encode(&mt('Make new user "[_1]"',$srch{'srchterm'}),'<>&"').'" />'."\n".
! 188: $opener_elems.'
! 189: </form></div>');
! 190: } else {
! 191: my $helplink = 'javascript:helpMenu('."'display'".')';
! 192: my %usertypetext = (
! 193: official => 'institutional',
! 194: unofficial => 'non-institutional',
! 195: );
! 196: $r->print('<div class="LC_warning">'.
! 197: &mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.
! 198: &mt('Please contact the [_1]helpdesk[_2] for assistance.','<a href="'.$helplink.'">','</a>').'</div>');
! 199:
! 200: }
! 201: }
! 202: }
! 203: }
! 204: }
! 205: if ($env{'form.phase'} eq 'define_newuser') {
! 206: $r->print('<h3>'.&mt('Define new user').' '.$srch{'srchterm'}.':'.
! 207: $srch{'srchdomain'}.'</h3>'."\n".'<div>'.
! 208: '<form name="newuserinfo" method="post" action="/adm/pickuser">'."\n".
! 209: '<input type="hidden" name="phase" value="" />'."\n".
! 210: $opener_elems.
! 211: &Apache::lonhtmlcommon::start_pick_box()."\n".
! 212: &Apache::lonhtmlcommon::row_title(&mt('First Name')).
! 213: '<input type="text" name="newfirst" value="" size="15" />'.
! 214: &Apache::lonhtmlcommon::row_closure()."\n".
! 215: &Apache::lonhtmlcommon::row_title(&mt('Last Name')).
! 216: '<input type="text" name="newlast" value="" size="25" />'
! 217: .
! 218: &Apache::lonhtmlcommon::row_closure()."\n".
! 219: &Apache::lonhtmlcommon::row_title(&mt('E-mail Address')).
! 220: '<input type="text" name="newemail" value="" size="25" />'
! 221: .
! 222: &Apache::lonhtmlcommon::row_closure(1)."\n".
! 223: &Apache::lonhtmlcommon::end_pick_box());
! 224: foreach my $item (keys(%srch)) {
! 225: $r->print('<input type="hidden" name="'.$item.'"'.
! 226: ' value="'.$srch{$item}.'" />'."\n");
1.1 raeburn 227: }
1.2 ! raeburn 228: $r->print('<br /><input type="button" name="cancelnew" value="'.
! 229: &mt('Cancel').'" onclick="javascript:setphase('.
! 230: "'get_user_info'".');" />'."\n".
! 231: '<input type="button" name="definenew" value="'.
! 232: &mt('Save').'" onclick="javascript:setphase('.
! 233: "'store_newuser'".');" /></form></div>');
1.1 raeburn 234: }
235: $r->print(&Apache::loncommon::end_page());
236: return OK;
237: }
238:
239: sub gochoose_javascript {
240: return <<"ENDGC";
241: <script type="text/javascript">
1.2 ! raeburn 242: // <![CDATA[
1.1 raeburn 243: function gochoose(uname,udom,ufirst,ulast,uemail) {
244: opener.document.$env{'form.form'}.$env{'form.unameelement'}.value=uname;
245: opener.document.$env{'form.form'}.$env{'form.ufirstelement'}.value=ufirst;
246: opener.document.$env{'form.form'}.$env{'form.ulastelement'}.value=ulast;
247: opener.document.$env{'form.form'}.$env{'form.uemailelement'}.value=uemail;
248:
249: var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
250: if (slct.options == undefined) {
251: opener.document.$env{'form.form'}.$env{'form.udomelement'}.value=udom;
252: }
253: else {
254: var i;
255: for (i=0;i<slct.length;i++) {
256: if (slct.options[i].value==udom) { slct.selectedIndex=i; }
257: }
258: }
259: opener.document.$env{'form.form'}.$env{'form.hideudomelement'}.value=udom;
260: self.close();
261: }
1.2 ! raeburn 262: // ]]>
1.1 raeburn 263: </script>
264:
265: ENDGC
266: }
267:
268: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>