Annotation of loncom/interface/lonpickuser.pm, revision 1.4
1.1 raeburn 1: # The LearningOnline Network
2: # Search for a user
3: #
1.4 ! raeburn 4: # $Id: lonpickuser.pm,v 1.3 2009/08/19 19:57:53 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.4 ! raeburn 74: 'ufirstelement','uemailelement','hideudomelement','coursedom','caller']);
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
1.4 ! raeburn 92: } elsif ($env{'form.caller'} eq 'checkusername') {
! 93: $js = <<"ENDCHK";
! 94: <script type="text/javascript">
! 95: // <![CDATA[
! 96: function checkUser() {
! 97: var uname = opener.document.$env{'form.form'}.$env{'form.unameelement'}.value;
! 98: var udom;
! 99: var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
! 100: if (slct.options == undefined) {
! 101: udom = opener.document.$env{'form.form'}.$env{'form.udomelement'}.value;
! 102: } else {
! 103: udom = slct.options[slct.selectedIndex].value;
! 104: }
! 105: if (uname != '') {
! 106: document.userpicker.srchterm.value = uname;
! 107: document.userpicker.srchdomain.value = udom;
! 108: }
! 109: document.userpicker.submit();
! 110: }
! 111: // ]]>
! 112: </script>
! 113: ENDCHK
! 114: } elsif ($env{'form.phase'} eq '') {
! 115: $js = <<"ENDSET";
! 116: <script type="text/javascript">
! 117: // <![CDATA[
! 118: function setUserSearch() {
! 119: var uname = opener.document.$env{'form.form'}.$env{'form.unameelement'}.value;
! 120: var udom;
! 121: var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
! 122: if (slct.options == undefined) {
! 123: udom = opener.document.$env{'form.form'}.$env{'form.udomelement'}.value;
! 124: } else {
! 125: udom = slct.options[slct.selectedIndex].value;
! 126: }
! 127: if (uname != '') {
! 128: document.userpicker.srchterm.value = uname;
! 129: var seldom = document.userpicker.srchdomain;
! 130: if (seldom.options != undefined) {
! 131: var i;
! 132: for (i=0;i<seldom.length;i++) {
! 133: if (seldom.options[i].value==udom) { seldom.selectedIndex=i; }
! 134: }
! 135: }
! 136: var selby = document.userpicker.srchby;
! 137: if (selby.options != undefined) {
! 138: var i;
! 139: for (i=0;i<selby.length;i++) {
! 140: if (selby.options[i].value=="uname") { selby.selectedIndex=i; }
! 141: }
! 142: }
! 143: var seltype = document.userpicker.srchtype;
! 144: if (seltype.options != undefined) {
! 145: var i;
! 146: for (i=0;i<seltype.length;i++) {
! 147: if (seltype.options[i].value=="exact") { seltype.selectedIndex=i; }
! 148: }
! 149: }
! 150: var selin = document.userpicker.srchin;
! 151: if (selin.options != undefined) {
! 152: var i;
! 153: for (i=0;i<selin.length;i++) {
! 154: if (selin.options[i].value=="dom") { selin.selectedIndex=i; }
! 155: }
! 156: }
! 157: }
! 158: return;
! 159: }
! 160: // ]]>
! 161: </script>
! 162: ENDSET
1.2 raeburn 163: }
164: my $startargs = {'no_nav_bar' => 1, };
165: if ($env{'form.phase'} eq 'store_newuser') {
166: my $uname = $env{'form.srchterm'};
167: my $udom = $env{'form.srchdomain'};
168: my $newfirst = $env{'form.newfirst'};
169: my $newlast = $env{'form.newlast'};
170: my $newemail = $env{'form.newemail'};
171: $startargs->{'add_entries'} = { onload => 'javascript:gochoose('."'$uname','$udom','$newfirst','$newlast','$newemail'".');' };
1.4 ! raeburn 172: } elsif ($env{'form.caller'} eq 'checkusername') {
! 173: $startargs->{'add_entries'} = { onload => 'javascript:checkUser();' };
! 174: } elsif ($env{'form.phase'} eq '') {
! 175: $startargs->{'add_entries'} = { onload => 'javascript:setUserSearch();' };
1.1 raeburn 176: }
1.2 raeburn 177: $r->print(&Apache::loncommon::start_page('Selecting course personnel',
178: $js,$startargs));
1.4 ! raeburn 179: if ($env{'form.caller'} eq 'checkusername') {
! 180: $r->print(&check_user_form().
! 181: &Apache::loncommon::end_page());
! 182: return OK;
! 183: }
1.1 raeburn 184: my %toset = (
185: uname => 'unameelement',
186: udom => 'udomelement',
187: first => 'ufirstelement',
188: lastn => 'ulastelement',
189: email => 'uemailelement',
190: hidedom => 'hideudomelement',
191: );
192:
193: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
194: my %srch;
195: foreach my $item (@search) {
196: $srch{$item} = $env{'form.'.$item};
197: }
198: my $forcenewuser;
199: my $context = 'requestcrs';
200: my $usertype;
201: if (($srch{'srchin'} eq 'dom') &&
202: ($srch{'srchby'} eq 'uname') &&
203: ($srch{'srchtype'} eq 'exact') &&
204: ($srch{'srchdomain'} ne '') &&
205: ($srch{'srchterm'} ne '')) {
206: my ($rules,$ruleorder) =
207: &Apache::lonnet::inst_userrules($srch{'srchdomain'},'username');
208: $usertype = &Apache::lonuserutils::check_usertype($srch{'srchdomain'},
209: $srch{'srchterm'},$rules);
210: }
211:
1.2 raeburn 212: my $dom = $env{'form.coursedom'};
1.1 raeburn 213:
214: my $cancreate =
215: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
216: my $userpicker =
217: &Apache::loncommon::user_picker($dom,\%srch,$forcenewuser,
218: 'document.userpicker',$cancreate,$usertype);
219: my $srchbutton = &mt('Search');
220:
221: my $headertext = &mt('Search for a user to add to course personnel');
1.2 raeburn 222: my $opener_elems = '<input type="hidden" name="form" value="'.
223: $env{'form.form'}.'" />'."\n".
224: '<input type="hidden" name="coursedom" value="'.
1.4 ! raeburn 225: $env{'form.coursedom'}.'" />'."\n".
! 226: &set_opener_elems();
1.2 raeburn 227: unless ($env{'form.phase'} eq 'define_newuser') {
228: $r->print(<<"ENDBLOCK");
1.1 raeburn 229: <h3>$headertext</h3>
230: <form action="/adm/pickuser" method="post" name="userpicker">
231: $opener_elems
232: <input type="hidden" name="phase" value="get_user_info" />
233: $userpicker
234: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.userpicker)" />
235: </form>
236: ENDBLOCK
1.2 raeburn 237: }
1.4 ! raeburn 238: if (($env{'form.phase'} eq 'get_user_info') && ($env{'form.srchterm'} ne '')) {
1.1 raeburn 239: $r->print('<hr /><div>'.&mt('Searching ...').'</div>');
240: $r->rflush();
241: my ($currstate,$response,$forcenewuser,$results) =
242: &Apache::loncreateuser::user_search_result($context,\%srch);
243: if (($currstate eq 'select') || ($currstate eq 'modify')) {
244: &Apache::loncreateuser::print_user_selection_page($r,$response,\%srch,$results,
245: \@search,$context,$opener_elems);
246: } else {
247: $r->print('<div>'.$response.'</div>');
1.2 raeburn 248: if ($forcenewuser) {
249: if ($srch{'srchby'} eq 'uname' &&
250: $srch{'srchtype'} eq 'exact' &&
251: $srch{'srchin'} eq 'dom' &&
252: $srch{'srchdomain'} eq $env{'form.coursedom'}) {
253: if ($cancreate) {
254: $r->print("\n".'<div><form name="newuser" '.
255: 'method="post" action="/adm/pickuser">');
256: foreach my $item (keys(%srch)) {
257: $r->print('<input type="hidden" name="'.$item.'"'.
258: ' value="'.$srch{$item}.'" />'."\n");
259: }
260: $r->print('
261: <input type="hidden" name="phase" value="define_newuser">
262: <input type="submit" name="forcenew" value="'.
263: &HTML::Entities::encode(&mt('Make new user "[_1]"',$srch{'srchterm'}),'<>&"').'" />'."\n".
264: $opener_elems.'
265: </form></div>');
266: } else {
267: my $helplink = 'javascript:helpMenu('."'display'".')';
1.3 raeburn 268: my %usertypetext =
269: &Apache::lonlocal::texthash(
270: official => 'You are not authorized to create new institutional users in this domain.',
271: unofficial => 'You are not authorized to create new non-institutional users in this domain.',
1.2 raeburn 272: );
273: $r->print('<div class="LC_warning">'.
1.3 raeburn 274: $usertypetext{$usertype}.' '.
1.2 raeburn 275: &mt('Please contact the [_1]helpdesk[_2] for assistance.','<a href="'.$helplink.'">','</a>').'</div>');
276:
277: }
278: }
279: }
280: }
281: }
282: if ($env{'form.phase'} eq 'define_newuser') {
283: $r->print('<h3>'.&mt('Define new user').' '.$srch{'srchterm'}.':'.
284: $srch{'srchdomain'}.'</h3>'."\n".'<div>'.
285: '<form name="newuserinfo" method="post" action="/adm/pickuser">'."\n".
286: '<input type="hidden" name="phase" value="" />'."\n".
287: $opener_elems.
288: &Apache::lonhtmlcommon::start_pick_box()."\n".
289: &Apache::lonhtmlcommon::row_title(&mt('First Name')).
290: '<input type="text" name="newfirst" value="" size="15" />'.
291: &Apache::lonhtmlcommon::row_closure()."\n".
292: &Apache::lonhtmlcommon::row_title(&mt('Last Name')).
293: '<input type="text" name="newlast" value="" size="25" />'
294: .
295: &Apache::lonhtmlcommon::row_closure()."\n".
296: &Apache::lonhtmlcommon::row_title(&mt('E-mail Address')).
297: '<input type="text" name="newemail" value="" size="25" />'
298: .
299: &Apache::lonhtmlcommon::row_closure(1)."\n".
300: &Apache::lonhtmlcommon::end_pick_box());
301: foreach my $item (keys(%srch)) {
302: $r->print('<input type="hidden" name="'.$item.'"'.
303: ' value="'.$srch{$item}.'" />'."\n");
1.1 raeburn 304: }
1.2 raeburn 305: $r->print('<br /><input type="button" name="cancelnew" value="'.
306: &mt('Cancel').'" onclick="javascript:setphase('.
307: "'get_user_info'".');" />'."\n".
308: '<input type="button" name="definenew" value="'.
309: &mt('Save').'" onclick="javascript:setphase('.
310: "'store_newuser'".');" /></form></div>');
1.1 raeburn 311: }
312: $r->print(&Apache::loncommon::end_page());
313: return OK;
314: }
315:
316: sub gochoose_javascript {
317: return <<"ENDGC";
318: <script type="text/javascript">
1.2 raeburn 319: // <![CDATA[
1.1 raeburn 320: function gochoose(uname,udom,ufirst,ulast,uemail) {
321: opener.document.$env{'form.form'}.$env{'form.unameelement'}.value=uname;
322: opener.document.$env{'form.form'}.$env{'form.ufirstelement'}.value=ufirst;
323: opener.document.$env{'form.form'}.$env{'form.ulastelement'}.value=ulast;
324: opener.document.$env{'form.form'}.$env{'form.uemailelement'}.value=uemail;
325:
326: var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
327: if (slct.options == undefined) {
328: opener.document.$env{'form.form'}.$env{'form.udomelement'}.value=udom;
329: }
330: else {
331: var i;
332: for (i=0;i<slct.length;i++) {
333: if (slct.options[i].value==udom) { slct.selectedIndex=i; }
334: }
335: }
336: opener.document.$env{'form.form'}.$env{'form.hideudomelement'}.value=udom;
337: self.close();
338: }
1.2 raeburn 339: // ]]>
1.1 raeburn 340: </script>
341:
342: ENDGC
343: }
344:
1.4 ! raeburn 345: sub check_user_form {
! 346: return '
! 347: <form action="/adm/pickuser" method="post" name="userpicker">
! 348: <input type="hidden" name="form" value="'.$env{'form.form'}.'" />
! 349: <input type="hidden" name="coursedom" value="'.$env{'form.coursedom'}.'" />'."\n".
! 350: &set_opener_elems().'
! 351: <input type="hidden" name="srchby" value="uname" />
! 352: <input type="hidden" name="srchin" value="dom" />
! 353: <input type="hidden" name="srchterm" value="" />
! 354: <input type="hidden" name="srchdomain" value="" />
! 355: <input type="hidden" name="srchtype" value="exact" />
! 356: <input type="hidden" name="phase" value="get_user_info" />
! 357: </form>'."\n";
! 358: }
! 359:
! 360: sub set_opener_elems {
! 361: my %toset = (
! 362: uname => 'unameelement',
! 363: udom => 'udomelement',
! 364: first => 'ufirstelement',
! 365: lastn => 'ulastelement',
! 366: email => 'uemailelement',
! 367: hidedom => 'hideudomelement',
! 368: );
! 369: my $output;
! 370: foreach my $item (keys(%toset)) {
! 371: if (exists($env{'form.'.$toset{$item}})) {
! 372: $output .= '<input type="hidden" name="'.$toset{$item}.'" value="'.$env{'form.'.$toset{$item}}.'" />'."\n";
! 373: }
! 374: }
! 375: return $output;
! 376: }
! 377:
1.1 raeburn 378: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>