File:
[LON-CAPA] /
loncom /
interface /
lonpickuser.pm
Revision
1.6:
download - view:
text,
annotated -
select for diffs
Mon Sep 5 01:46:08 2016 UTC (7 years, 11 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_12_X,
version_2_11_X,
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3,
version_2_11_2_uiuc,
version_2_11_2_msu,
version_2_11_2_educog,
version_2_11_2,
HEAD
- Domain Configuration for LON-CAPA Directory searches for user information
for users in a domain.
- Can disable for all, or can disable only for other domains.
- Default: enabled for all domains.
1: # The LearningOnline Network
2: # Search for a user
3: #
4: # $Id: lonpickuser.pm,v 1.6 2016/09/05 01:46:08 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','coursedom','caller']);
75: my $js;
76:
77: if (($env{'form.phase'} eq 'get_user_info') ||
78: ($env{'form.phase'} eq 'store_newuser')) {
79: $js = &gochoose_javascript();
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: } 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
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'".');' };
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();' };
176: }
177: $r->print(&Apache::loncommon::start_page('Selecting course personnel',
178: $js,$startargs));
179: if ($env{'form.caller'} eq 'checkusername') {
180: $r->print(&check_user_form().
181: &Apache::loncommon::end_page());
182: return OK;
183: }
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 (%curr_rules,%got_rules);
207: my ($rules,$ruleorder) =
208: &Apache::lonnet::inst_userrules($srch{'srchdomain'},'username');
209: $usertype = &Apache::lonuserutils::check_usertype($srch{'srchdomain'},
210: $srch{'srchterm'},$rules,
211: \%curr_rules,\%got_rules);
212: }
213:
214: my $dom = $env{'form.coursedom'};
215:
216: my $cancreate =
217: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
218: my ($userpicker,$cansearch) =
219: &Apache::loncommon::user_picker($dom,\%srch,$forcenewuser,
220: 'document.userpicker',$cancreate,
221: $usertype,$context);
222: my $srchbutton = &mt('Search');
223:
224: my $headertext = &mt('Search for a user to add to course personnel');
225: my $opener_elems = '<input type="hidden" name="form" value="'.
226: $env{'form.form'}.'" />'."\n".
227: '<input type="hidden" name="coursedom" value="'.
228: $env{'form.coursedom'}.'" />'."\n".
229: &set_opener_elems();
230: unless ($env{'form.phase'} eq 'define_newuser') {
231: if ($cansearch) {
232:
233: $r->print(<<"ENDBLOCK");
234: <h3>$headertext</h3>
235: <form action="/adm/pickuser" method="post" name="userpicker">
236: $opener_elems
237: <input type="hidden" name="phase" value="get_user_info" />
238: $userpicker
239: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.userpicker)" />
240: </form>
241: ENDBLOCK
242: } else {
243: $r->print(<<"ENDBLOCK");
244: <form action="/adm/pickuser" method="post" name="userpicker">
245: $opener_elems
246: <input type="hidden" name="phase" value="get_user_info" />
247: </form>
248: ENDBLOCK
249: }
250: }
251: if (($env{'form.phase'} eq 'get_user_info') && ($env{'form.srchterm'} ne '')) {
252: $r->print('<hr /><div>'.&mt('Searching ...').'</div>');
253: $r->rflush();
254: my ($currstate,$response,$forcenewuser,$results) =
255: &Apache::loncreateuser::user_search_result($context,\%srch);
256: if (($currstate eq 'select') || ($currstate eq 'modify')) {
257: &Apache::loncreateuser::print_user_selection_page($r,$response,\%srch,$results,
258: \@search,$context,$opener_elems);
259: } else {
260: $r->print('<div>'.$response.'</div>');
261: if ($forcenewuser) {
262: if ($srch{'srchby'} eq 'uname' &&
263: $srch{'srchtype'} eq 'exact' &&
264: $srch{'srchin'} eq 'dom' &&
265: $srch{'srchdomain'} eq $env{'form.coursedom'}) {
266: if ($cancreate) {
267: $r->print("\n".'<div><form name="newuser" '.
268: 'method="post" action="/adm/pickuser">');
269: foreach my $item (keys(%srch)) {
270: $r->print('<input type="hidden" name="'.$item.'"'.
271: ' value="'.$srch{$item}.'" />'."\n");
272: }
273: $r->print('
274: <input type="hidden" name="phase" value="define_newuser">
275: <input type="submit" name="forcenew" value="'.
276: &HTML::Entities::encode(&mt('Make new user "[_1]"',$srch{'srchterm'}),'<>&"').'" />'."\n".
277: $opener_elems.'
278: </form></div>');
279: } else {
280: my $helplink = 'javascript:helpMenu('."'display'".')';
281: my %usertypetext =
282: &Apache::lonlocal::texthash(
283: official => 'You are not authorized to create new institutional users in this domain.',
284: unofficial => 'You are not authorized to create new non-institutional users in this domain.',
285: );
286: $r->print('<div class="LC_warning">'.
287: $usertypetext{$usertype}.' '.
288: &mt('Please contact the [_1]helpdesk[_2] for assistance.','<a href="'.$helplink.'">','</a>').'</div>');
289:
290: }
291: }
292: }
293: }
294: }
295: if ($env{'form.phase'} eq 'define_newuser') {
296: $r->print('<h3>'.&mt('Define new user').' '.$srch{'srchterm'}.':'.
297: $srch{'srchdomain'}.'</h3>'."\n".'<div>'.
298: '<form name="newuserinfo" method="post" action="/adm/pickuser">'."\n".
299: '<input type="hidden" name="phase" value="" />'."\n".
300: $opener_elems.
301: &Apache::lonhtmlcommon::start_pick_box()."\n".
302: &Apache::lonhtmlcommon::row_title(&mt('First Name')).
303: '<input type="text" name="newfirst" value="" size="15" />'.
304: &Apache::lonhtmlcommon::row_closure()."\n".
305: &Apache::lonhtmlcommon::row_title(&mt('Last Name')).
306: '<input type="text" name="newlast" value="" size="25" />'
307: .
308: &Apache::lonhtmlcommon::row_closure()."\n".
309: &Apache::lonhtmlcommon::row_title(&mt('E-mail Address')).
310: '<input type="text" name="newemail" value="" size="25" />'
311: .
312: &Apache::lonhtmlcommon::row_closure(1)."\n".
313: &Apache::lonhtmlcommon::end_pick_box());
314: foreach my $item (keys(%srch)) {
315: $r->print('<input type="hidden" name="'.$item.'"'.
316: ' value="'.$srch{$item}.'" />'."\n");
317: }
318: $r->print('<br /><input type="button" name="cancelnew" value="'.
319: &mt('Cancel').'" onclick="javascript:setphase('.
320: "'get_user_info'".');" />'."\n".
321: '<input type="button" name="definenew" value="'.
322: &mt('Save').'" onclick="javascript:setphase('.
323: "'store_newuser'".');" /></form></div>');
324: }
325: $r->print(&Apache::loncommon::end_page());
326: return OK;
327: }
328:
329: sub gochoose_javascript {
330: return <<"ENDGC";
331: <script type="text/javascript">
332: // <![CDATA[
333: function gochoose(uname,udom,ufirst,ulast,uemail) {
334: opener.document.$env{'form.form'}.$env{'form.unameelement'}.value=uname;
335: opener.document.$env{'form.form'}.$env{'form.ufirstelement'}.value=ufirst;
336: opener.document.$env{'form.form'}.$env{'form.ulastelement'}.value=ulast;
337: opener.document.$env{'form.form'}.$env{'form.uemailelement'}.value=uemail;
338:
339: var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
340: if (slct.options == undefined) {
341: opener.document.$env{'form.form'}.$env{'form.udomelement'}.value=udom;
342: }
343: else {
344: var i;
345: for (i=0;i<slct.length;i++) {
346: if (slct.options[i].value==udom) { slct.selectedIndex=i; }
347: }
348: }
349: opener.document.$env{'form.form'}.$env{'form.hideudomelement'}.value=udom;
350: self.close();
351: }
352: // ]]>
353: </script>
354:
355: ENDGC
356: }
357:
358: sub check_user_form {
359: return '
360: <form action="/adm/pickuser" method="post" name="userpicker">
361: <input type="hidden" name="form" value="'.$env{'form.form'}.'" />
362: <input type="hidden" name="coursedom" value="'.$env{'form.coursedom'}.'" />'."\n".
363: &set_opener_elems().'
364: <input type="hidden" name="srchby" value="uname" />
365: <input type="hidden" name="srchin" value="dom" />
366: <input type="hidden" name="srchterm" value="" />
367: <input type="hidden" name="srchdomain" value="" />
368: <input type="hidden" name="srchtype" value="exact" />
369: <input type="hidden" name="phase" value="get_user_info" />
370: </form>'."\n";
371: }
372:
373: sub set_opener_elems {
374: my %toset = (
375: uname => 'unameelement',
376: udom => 'udomelement',
377: first => 'ufirstelement',
378: lastn => 'ulastelement',
379: email => 'uemailelement',
380: hidedom => 'hideudomelement',
381: );
382: my $output;
383: foreach my $item (keys(%toset)) {
384: if (exists($env{'form.'.$toset{$item}})) {
385: $output .= '<input type="hidden" name="'.$toset{$item}.'" value="'.$env{'form.'.$toset{$item}}.'" />'."\n";
386: }
387: }
388: return $output;
389: }
390:
391: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>