File:
[LON-CAPA] /
loncom /
interface /
loncreateuser.pm
Revision
1.448:
download - view:
text,
annotated -
select for diffs
Sat Nov 4 20:59:38 2017 UTC (6 years, 9 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- When a csv file of users is uploaded, error messages are displayed in the
case of (a) an invalid datatoken, or (b) invalid home server for new users,
In (a) user is prompted to re-upload the file; in (b) user is prompted to
select default domain again.
1: # The LearningOnline Network with CAPA
2: # Create a user
3: #
4: # $Id: loncreateuser.pm,v 1.448 2017/11/04 20:59:38 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: package Apache::loncreateuser;
31:
32: =pod
33:
34: =head1 NAME
35:
36: Apache::loncreateuser.pm
37:
38: =head1 SYNOPSIS
39:
40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
59:
60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
62:
63: =cut
64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
68: use Apache::loncommon;
69: use Apache::lonlocal;
70: use Apache::longroup;
71: use Apache::lonuserutils;
72: use Apache::loncoursequeueadmin;
73: use LONCAPA qw(:DEFAULT :match);
74:
75: my $loginscript; # piece of javascript used in two separate instances
76: my $authformnop;
77: my $authformkrb;
78: my $authformint;
79: my $authformfsys;
80: my $authformloc;
81:
82: sub initialize_authen_forms {
83: my ($dom,$formname,$curr_authtype,$mode) = @_;
84: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
85: my %param = ( formname => $formname,
86: kerb_def_dom => $krbdefdom,
87: kerb_def_auth => $krbdef,
88: domain => $dom,
89: );
90: my %abv_auth = &auth_abbrev();
91: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
92: my $long_auth = $1;
93: my $curr_autharg = $2;
94: my %abv_auth = &auth_abbrev();
95: $param{'curr_authtype'} = $abv_auth{$long_auth};
96: if ($long_auth =~ /^krb(4|5)$/) {
97: $param{'curr_kerb_ver'} = $1;
98: $param{'curr_autharg'} = $curr_autharg;
99: }
100: if ($mode eq 'modifyuser') {
101: $param{'mode'} = $mode;
102: }
103: }
104: $loginscript = &Apache::loncommon::authform_header(%param);
105: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
106: $authformnop = &Apache::loncommon::authform_nochange(%param);
107: $authformint = &Apache::loncommon::authform_internal(%param);
108: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
109: $authformloc = &Apache::loncommon::authform_local(%param);
110: }
111:
112: sub auth_abbrev {
113: my %abv_auth = (
114: krb5 => 'krb',
115: krb4 => 'krb',
116: internal => 'int',
117: localauth => 'loc',
118: unix => 'fsys',
119: );
120: return %abv_auth;
121: }
122:
123: # ====================================================
124:
125: sub user_quotas {
126: my ($ccuname,$ccdomain) = @_;
127: my %lt = &Apache::lonlocal::texthash(
128: 'usrt' => "User Tools",
129: 'cust' => "Custom quota",
130: 'chqu' => "Change quota",
131: );
132:
133: my $quota_javascript = <<"END_SCRIPT";
134: <script type="text/javascript">
135: // <![CDATA[
136: function quota_changes(caller,context) {
137: var customoff = document.getElementById('custom_'+context+'quota_off');
138: var customon = document.getElementById('custom_'+context+'quota_on');
139: var number = document.getElementById(context+'quota');
140: if (caller == "custom") {
141: if (customoff) {
142: if (customoff.checked) {
143: number.value = "";
144: }
145: }
146: }
147: if (caller == "quota") {
148: if (customon) {
149: customon.checked = true;
150: }
151: }
152: return;
153: }
154: // ]]>
155: </script>
156: END_SCRIPT
157: my $longinsttype;
158: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
159: my $output = $quota_javascript."\n".
160: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
161: &Apache::loncommon::start_data_table();
162:
163: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
164: (&Apache::lonnet::allowed('udp',$ccdomain))) {
165: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
166: }
167:
168: my %titles = &Apache::lonlocal::texthash (
169: portfolio => "Disk space allocated to user's portfolio files",
170: author => "Disk space allocated to user's Authoring Space (if role assigned)",
171: );
172: foreach my $name ('portfolio','author') {
173: my ($currquota,$quotatype,$inststatus,$defquota) =
174: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
175: if ($longinsttype eq '') {
176: if ($inststatus ne '') {
177: if ($usertypes->{$inststatus} ne '') {
178: $longinsttype = $usertypes->{$inststatus};
179: }
180: }
181: }
182: my ($showquota,$custom_on,$custom_off,$defaultinfo);
183: $custom_on = ' ';
184: $custom_off = ' checked="checked" ';
185: if ($quotatype eq 'custom') {
186: $custom_on = $custom_off;
187: $custom_off = ' ';
188: $showquota = $currquota;
189: if ($longinsttype eq '') {
190: $defaultinfo = &mt('For this user, the default quota would be [_1]'
191: .' MB.',$defquota);
192: } else {
193: $defaultinfo = &mt("For this user, the default quota would be [_1]".
194: " MB, as determined by the user's institutional".
195: " affiliation ([_2]).",$defquota,$longinsttype);
196: }
197: } else {
198: if ($longinsttype eq '') {
199: $defaultinfo = &mt('For this user, the default quota is [_1]'
200: .' MB.',$defquota);
201: } else {
202: $defaultinfo = &mt("For this user, the default quota of [_1]".
203: " MB, is determined by the user's institutional".
204: " affiliation ([_2]).",$defquota,$longinsttype);
205: }
206: }
207:
208: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
209: $output .= '<tr class="LC_info_row">'."\n".
210: ' <td>'.$titles{$name}.'</td>'."\n".
211: ' </tr>'."\n".
212: &Apache::loncommon::start_data_table_row()."\n".
213: ' <td><span class="LC_nobreak">'.
214: &mt('Current quota: [_1] MB',$currquota).'</span> '.
215: $defaultinfo.'</td>'."\n".
216: &Apache::loncommon::end_data_table_row()."\n".
217: &Apache::loncommon::start_data_table_row()."\n".
218: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
219: ': <label>'.
220: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
221: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
222: ' /><span class="LC_nobreak">'.
223: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
224: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
225: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
226: ' />'.$lt{'cust'}.':</label> '.
227: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
228: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
229: ' /> '.&mt('MB').'</span></td>'."\n".
230: &Apache::loncommon::end_data_table_row()."\n";
231: }
232: }
233: $output .= &Apache::loncommon::end_data_table();
234: return $output;
235: }
236:
237: sub build_tools_display {
238: my ($ccuname,$ccdomain,$context) = @_;
239: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
240: $colspan,$isadv,%domconfig);
241: my %lt = &Apache::lonlocal::texthash (
242: 'blog' => "Personal User Blog",
243: 'aboutme' => "Personal Information Page",
244: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
245: 'portfolio' => "Personal User Portfolio",
246: 'avai' => "Available",
247: 'cusa' => "availability",
248: 'chse' => "Change setting",
249: 'usde' => "Use default",
250: 'uscu' => "Use custom",
251: 'official' => 'Can request creation of official courses',
252: 'unofficial' => 'Can request creation of unofficial courses',
253: 'community' => 'Can request creation of communities',
254: 'textbook' => 'Can request creation of textbook courses',
255: 'placement' => 'Can request creation of placement tests',
256: 'requestauthor' => 'Can request author space',
257: );
258: if ($context eq 'requestcourses') {
259: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
260: 'requestcourses.official','requestcourses.unofficial',
261: 'requestcourses.community','requestcourses.textbook',
262: 'requestcourses.placement');
263: @usertools = ('official','unofficial','community','textbook','placement');
264: @options =('norequest','approval','autolimit','validate');
265: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
266: %reqtitles = &courserequest_titles();
267: %reqdisplay = &courserequest_display();
268: $colspan = ' colspan="2"';
269: %domconfig =
270: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
271: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
272: } elsif ($context eq 'requestauthor') {
273: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
274: 'requestauthor');
275: @usertools = ('requestauthor');
276: @options =('norequest','approval','automatic');
277: %reqtitles = &requestauthor_titles();
278: %reqdisplay = &requestauthor_display();
279: $colspan = ' colspan="2"';
280: %domconfig =
281: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
282: } else {
283: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
284: 'tools.aboutme','tools.portfolio','tools.blog',
285: 'tools.webdav');
286: @usertools = ('aboutme','blog','webdav','portfolio');
287: }
288: foreach my $item (@usertools) {
289: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
290: $currdisp,$custdisp,$custradio);
291: $cust_off = 'checked="checked" ';
292: $tool_on = 'checked="checked" ';
293: $curr_access =
294: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
295: $context);
296: if ($context eq 'requestauthor') {
297: if ($userenv{$context} ne '') {
298: $cust_on = ' checked="checked" ';
299: $cust_off = '';
300: }
301: } elsif ($userenv{$context.'.'.$item} ne '') {
302: $cust_on = ' checked="checked" ';
303: $cust_off = '';
304: }
305: if ($context eq 'requestcourses') {
306: if ($userenv{$context.'.'.$item} eq '') {
307: $custom_access = &mt('Currently from default setting.');
308: } else {
309: $custom_access = &mt('Currently from custom setting.');
310: }
311: } elsif ($context eq 'requestauthor') {
312: if ($userenv{$context} eq '') {
313: $custom_access = &mt('Currently from default setting.');
314: } else {
315: $custom_access = &mt('Currently from custom setting.');
316: }
317: } else {
318: if ($userenv{$context.'.'.$item} eq '') {
319: $custom_access =
320: &mt('Availability determined currently from default setting.');
321: if (!$curr_access) {
322: $tool_off = 'checked="checked" ';
323: $tool_on = '';
324: }
325: } else {
326: $custom_access =
327: &mt('Availability determined currently from custom setting.');
328: if ($userenv{$context.'.'.$item} == 0) {
329: $tool_off = 'checked="checked" ';
330: $tool_on = '';
331: }
332: }
333: }
334: $output .= ' <tr class="LC_info_row">'."\n".
335: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
336: ' </tr>'."\n".
337: &Apache::loncommon::start_data_table_row()."\n";
338:
339: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
340: my ($curroption,$currlimit);
341: my $envkey = $context.'.'.$item;
342: if ($context eq 'requestauthor') {
343: $envkey = $context;
344: }
345: if ($userenv{$envkey} ne '') {
346: $curroption = $userenv{$envkey};
347: } else {
348: my (@inststatuses);
349: if ($context eq 'requestcourses') {
350: $curroption =
351: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
352: $isadv,$ccdomain,$item,
353: \@inststatuses,\%domconfig);
354: } else {
355: $curroption =
356: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
357: $isadv,$ccdomain,undef,
358: \@inststatuses,\%domconfig);
359: }
360: }
361: if (!$curroption) {
362: $curroption = 'norequest';
363: }
364: if ($curroption =~ /^autolimit=(\d*)$/) {
365: $currlimit = $1;
366: if ($currlimit eq '') {
367: $currdisp = &mt('Yes, automatic creation');
368: } else {
369: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
370: }
371: } else {
372: $currdisp = $reqdisplay{$curroption};
373: }
374: $custdisp = '<table>';
375: foreach my $option (@options) {
376: my $val = $option;
377: if ($option eq 'norequest') {
378: $val = 0;
379: }
380: if ($option eq 'validate') {
381: my $canvalidate = 0;
382: if (ref($validations{$item}) eq 'HASH') {
383: if ($validations{$item}{'_custom_'}) {
384: $canvalidate = 1;
385: }
386: }
387: next if (!$canvalidate);
388: }
389: my $checked = '';
390: if ($option eq $curroption) {
391: $checked = ' checked="checked"';
392: } elsif ($option eq 'autolimit') {
393: if ($curroption =~ /^autolimit/) {
394: $checked = ' checked="checked"';
395: }
396: }
397: my $name = 'crsreq_'.$item;
398: if ($context eq 'requestauthor') {
399: $name = $item;
400: }
401: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
402: '<input type="radio" name="'.$name.'" '.
403: 'value="'.$val.'"'.$checked.' />'.
404: $reqtitles{$option}.'</label> ';
405: if ($option eq 'autolimit') {
406: $custdisp .= '<input type="text" name="'.$name.
407: '_limit" size="1" '.
408: 'value="'.$currlimit.'" /></span><br />'.
409: $reqtitles{'unlimited'};
410: } else {
411: $custdisp .= '</span>';
412: }
413: $custdisp .= '</td></tr>';
414: }
415: $custdisp .= '</table>';
416: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
417: } else {
418: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
419: my $name = $context.'_'.$item;
420: if ($context eq 'requestauthor') {
421: $name = $context;
422: }
423: $custdisp = '<span class="LC_nobreak"><label>'.
424: '<input type="radio" name="'.$name.'"'.
425: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
426: '<input type="radio" name="'.$name.'" value="0" '.
427: $tool_off.'/>'.&mt('Off').'</label></span>';
428: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
429: '</span>';
430: }
431: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
432: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
433: &Apache::loncommon::end_data_table_row()."\n";
434: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
435: $output .=
436: &Apache::loncommon::start_data_table_row()."\n".
437: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
438: $lt{'chse'}.': <label>'.
439: '<input type="radio" name="custom'.$item.'" value="0" '.
440: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
441: '<label><input type="radio" name="custom'.$item.'" value="1" '.
442: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
443: &Apache::loncommon::end_data_table_row()."\n";
444: }
445: }
446: return $output;
447: }
448:
449: sub coursereq_externaluser {
450: my ($ccuname,$ccdomain,$cdom) = @_;
451: my (@usertools,@options,%validations,%userenv,$output);
452: my %lt = &Apache::lonlocal::texthash (
453: 'official' => 'Can request creation of official courses',
454: 'unofficial' => 'Can request creation of unofficial courses',
455: 'community' => 'Can request creation of communities',
456: 'textbook' => 'Can request creation of textbook courses',
457: 'placement' => 'Can request creation of placement tests',
458: );
459:
460: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
461: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
462: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
463: 'reqcrsotherdom.placement');
464: @usertools = ('official','unofficial','community','textbook','placement');
465: @options = ('approval','validate','autolimit');
466: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
467: my $optregex = join('|',@options);
468: my %reqtitles = &courserequest_titles();
469: foreach my $item (@usertools) {
470: my ($curroption,$currlimit,$tooloff);
471: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
472: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
473: foreach my $req (@curr) {
474: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
475: $curroption = $1;
476: $currlimit = $2;
477: last;
478: }
479: }
480: if (!$curroption) {
481: $curroption = 'norequest';
482: $tooloff = ' checked="checked"';
483: }
484: } else {
485: $curroption = 'norequest';
486: $tooloff = ' checked="checked"';
487: }
488: $output.= &Apache::loncommon::start_data_table_row()."\n".
489: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
490: '<table><tr><td valign="top">'."\n".
491: '<label><input type="radio" name="reqcrsotherdom_'.$item.
492: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
493: '</label></td>';
494: foreach my $option (@options) {
495: if ($option eq 'validate') {
496: my $canvalidate = 0;
497: if (ref($validations{$item}) eq 'HASH') {
498: if ($validations{$item}{'_external_'}) {
499: $canvalidate = 1;
500: }
501: }
502: next if (!$canvalidate);
503: }
504: my $checked = '';
505: if ($option eq $curroption) {
506: $checked = ' checked="checked"';
507: }
508: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
509: '<input type="radio" name="reqcrsotherdom_'.$item.
510: '" value="'.$option.'"'.$checked.' />'.
511: $reqtitles{$option}.'</label>';
512: if ($option eq 'autolimit') {
513: $output .= ' <input type="text" name="reqcrsotherdom_'.
514: $item.'_limit" size="1" '.
515: 'value="'.$currlimit.'" /></span>'.
516: '<br />'.$reqtitles{'unlimited'};
517: } else {
518: $output .= '</span>';
519: }
520: $output .= '</td>';
521: }
522: $output .= '</td></tr></table></td>'."\n".
523: &Apache::loncommon::end_data_table_row()."\n";
524: }
525: return $output;
526: }
527:
528: sub domainrole_req {
529: my ($ccuname,$ccdomain) = @_;
530: return '<br /><h3>'.
531: &mt('User Can Request Assignment of Domain Roles?').
532: '</h3>'."\n".
533: &Apache::loncommon::start_data_table().
534: &build_tools_display($ccuname,$ccdomain,
535: 'requestauthor').
536: &Apache::loncommon::end_data_table();
537: }
538:
539: sub courserequest_titles {
540: my %titles = &Apache::lonlocal::texthash (
541: official => 'Official',
542: unofficial => 'Unofficial',
543: community => 'Communities',
544: textbook => 'Textbook',
545: placement => 'Placement Tests',
546: norequest => 'Not allowed',
547: approval => 'Approval by Dom. Coord.',
548: validate => 'With validation',
549: autolimit => 'Numerical limit',
550: unlimited => '(blank for unlimited)',
551: );
552: return %titles;
553: }
554:
555: sub courserequest_display {
556: my %titles = &Apache::lonlocal::texthash (
557: approval => 'Yes, need approval',
558: validate => 'Yes, with validation',
559: norequest => 'No',
560: );
561: return %titles;
562: }
563:
564: sub requestauthor_titles {
565: my %titles = &Apache::lonlocal::texthash (
566: norequest => 'Not allowed',
567: approval => 'Approval by Dom. Coord.',
568: automatic => 'Automatic approval',
569: );
570: return %titles;
571:
572: }
573:
574: sub requestauthor_display {
575: my %titles = &Apache::lonlocal::texthash (
576: approval => 'Yes, need approval',
577: automatic => 'Yes, automatic approval',
578: norequest => 'No',
579: );
580: return %titles;
581: }
582:
583: sub requestchange_display {
584: my %titles = &Apache::lonlocal::texthash (
585: approval => "availability set to 'on' (approval required)",
586: automatic => "availability set to 'on' (automatic approval)",
587: norequest => "availability set to 'off'",
588: );
589: return %titles;
590: }
591:
592: sub curr_requestauthor {
593: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
594: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
595: if ($uname eq '' || $udom eq '') {
596: $uname = $env{'user.name'};
597: $udom = $env{'user.domain'};
598: $isadv = $env{'user.adv'};
599: }
600: my (%userenv,%settings,$val);
601: my @options = ('automatic','approval');
602: %userenv =
603: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
604: if ($userenv{'requestauthor'}) {
605: $val = $userenv{'requestauthor'};
606: @{$inststatuses} = ('_custom_');
607: } else {
608: my %alltasks;
609: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
610: %settings = %{$domconfig->{'requestauthor'}};
611: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
612: $val = $settings{'_LC_adv'};
613: @{$inststatuses} = ('_LC_adv_');
614: } else {
615: if ($userenv{'inststatus'} ne '') {
616: @{$inststatuses} = split(',',$userenv{'inststatus'});
617: } else {
618: @{$inststatuses} = ('default');
619: }
620: foreach my $status (@{$inststatuses}) {
621: if (exists($settings{$status})) {
622: my $value = $settings{$status};
623: next unless ($value);
624: unless (exists($alltasks{$value})) {
625: if (ref($alltasks{$value}) eq 'ARRAY') {
626: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
627: push(@{$alltasks{$value}},$status);
628: }
629: } else {
630: @{$alltasks{$value}} = ($status);
631: }
632: }
633: }
634: }
635: foreach my $option (@options) {
636: if ($alltasks{$option}) {
637: $val = $option;
638: last;
639: }
640: }
641: }
642: }
643: }
644: return $val;
645: }
646:
647: # =================================================================== Phase one
648:
649: sub print_username_entry_form {
650: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
651: $permission) = @_;
652: my $defdom=$env{'request.role.domain'};
653: my $formtoset = 'crtuser';
654: if (exists($env{'form.startrolename'})) {
655: $formtoset = 'docustom';
656: $env{'form.rolename'} = $env{'form.startrolename'};
657: } elsif ($env{'form.origform'} eq 'crtusername') {
658: $formtoset = $env{'form.origform'};
659: }
660:
661: my ($jsback,$elements) = &crumb_utilities();
662:
663: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
664: '<script type="text/javascript">'."\n".
665: '// <![CDATA['."\n".
666: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
667: '// ]]>'."\n".
668: '</script>'."\n";
669:
670: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
671: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
672: && (&Apache::lonnet::allowed('mcr','/'))) {
673: $jscript .= &customrole_javascript();
674: }
675: my $helpitem = 'Course_Change_Privileges';
676: if ($env{'form.action'} eq 'custom') {
677: if ($context eq 'course') {
678: $helpitem = 'Course_Editing_Custom_Roles';
679: } elsif ($context eq 'domain') {
680: $helpitem = 'Domain_Editing_Custom_Roles';
681: }
682: } elsif ($env{'form.action'} eq 'singlestudent') {
683: $helpitem = 'Course_Add_Student';
684: } elsif ($env{'form.action'} eq 'accesslogs') {
685: $helpitem = 'Domain_User_Access_Logs';
686: } elsif ($context eq 'author') {
687: $helpitem = 'Author_Change_Privileges';
688: } elsif ($context eq 'domain') {
689: if ($permission->{'cusr'}) {
690: $helpitem = 'Domain_Change_Privileges';
691: } elsif ($permission->{'view'}) {
692: $helpitem = 'Domain_View_Privileges';
693: } else {
694: undef($helpitem);
695: }
696: }
697: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
698: if ($env{'form.action'} eq 'custom') {
699: push(@{$brcrum},
700: {href=>"javascript:backPage(document.crtuser)",
701: text=>"Pick custom role",
702: help => $helpitem,}
703: );
704: } else {
705: push (@{$brcrum},
706: {href => "javascript:backPage(document.crtuser)",
707: text => $breadcrumb_text{'search'},
708: help => $helpitem,
709: faq => 282,
710: bug => 'Instructor Interface',}
711: );
712: }
713: my %loaditems = (
714: 'onload' => "javascript:setFormElements(document.$formtoset)",
715: );
716: my $args = {bread_crumbs => $brcrum,
717: bread_crumbs_component => 'User Management',
718: add_entries => \%loaditems,};
719: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
720:
721: my %lt=&Apache::lonlocal::texthash(
722: 'srst' => 'Search for a user and enroll as a student',
723: 'srme' => 'Search for a user and enroll as a member',
724: 'srad' => 'Search for a user and modify/add user information or roles',
725: 'srvu' => 'Search for a user and view user information and roles',
726: 'srva' => 'Search for a user and view access log information',
727: 'usr' => "Username",
728: 'dom' => "Domain",
729: 'ecrp' => "Define or Edit Custom Role",
730: 'nr' => "role name",
731: 'cre' => "Next",
732: );
733:
734: if ($env{'form.action'} eq 'custom') {
735: if (&Apache::lonnet::allowed('mcr','/')) {
736: my $newroletext = &mt('Define new custom role:');
737: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
738: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
739: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
740: '<h3>'.$lt{'ecrp'}.'</h3>'.
741: &Apache::loncommon::start_data_table().
742: &Apache::loncommon::start_data_table_row().
743: '<td>');
744: if (keys(%existingroles) > 0) {
745: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
746: } else {
747: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
748: }
749: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
750: &Apache::loncommon::end_data_table_row());
751: if (keys(%existingroles) > 0) {
752: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
753: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
754: &mt('View/Modify existing role:').'</b></label></td>'.
755: '<td align="center"><br />'.
756: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
757: '<option value="" selected="selected">'.
758: &mt('Select'));
759: foreach my $role (sort(keys(%existingroles))) {
760: $r->print('<option value="'.$role.'">'.$role.'</option>');
761: }
762: $r->print('</select>'.
763: '</td>'.
764: &Apache::loncommon::end_data_table_row());
765: }
766: $r->print(&Apache::loncommon::end_data_table().'<p>'.
767: '<input name="customeditor" type="submit" value="'.
768: $lt{'cre'}.'" /></p>'.
769: '</form>');
770: }
771: } else {
772: my $actiontext = $lt{'srad'};
773: my $fixeddom;
774: if ($env{'form.action'} eq 'singlestudent') {
775: if ($crstype eq 'Community') {
776: $actiontext = $lt{'srme'};
777: } else {
778: $actiontext = $lt{'srst'};
779: }
780: } elsif ($env{'form.action'} eq 'accesslogs') {
781: $actiontext = $lt{'srva'};
782: $fixeddom = 1;
783: } elsif (($env{'form.action'} eq 'singleuser') &&
784: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
785: $actiontext = $lt{'srvu'};
786: $fixeddom = 1;
787: }
788: $r->print("<h3>$actiontext</h3>");
789: if ($env{'form.origform'} ne 'crtusername') {
790: if ($response) {
791: $r->print("\n<div>$response</div>".
792: '<br clear="all" />');
793: }
794: }
795: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
796: }
797: }
798:
799: sub customrole_javascript {
800: my $js = <<"END";
801: <script type="text/javascript">
802: // <![CDATA[
803:
804: function setCustomFields() {
805: if (document.docustom.customroleaction.length > 0) {
806: for (var i=0; i<document.docustom.customroleaction.length; i++) {
807: if (document.docustom.customroleaction[i].checked) {
808: if (document.docustom.customroleaction[i].value == 'new') {
809: document.docustom.rolename.selectedIndex = 0;
810: } else {
811: document.docustom.newrolename.value = '';
812: }
813: }
814: }
815: }
816: return;
817: }
818:
819: function setCustomAction(caller) {
820: if (document.docustom.customroleaction.length > 0) {
821: for (var i=0; i<document.docustom.customroleaction.length; i++) {
822: if (document.docustom.customroleaction[i].value == caller) {
823: document.docustom.customroleaction[i].checked = true;
824: }
825: }
826: }
827: setCustomFields();
828: return;
829: }
830:
831: // ]]>
832: </script>
833: END
834: return $js;
835: }
836:
837: sub entry_form {
838: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
839: my ($usertype,$inexact);
840: if (ref($srch) eq 'HASH') {
841: if (($srch->{'srchin'} eq 'dom') &&
842: ($srch->{'srchby'} eq 'uname') &&
843: ($srch->{'srchtype'} eq 'exact') &&
844: ($srch->{'srchdomain'} ne '') &&
845: ($srch->{'srchterm'} ne '')) {
846: my (%curr_rules,%got_rules);
847: my ($rules,$ruleorder) =
848: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
849: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
850: } else {
851: $inexact = 1;
852: }
853: }
854: my ($cancreate,$noinstd);
855: if ($env{'form.action'} eq 'accesslogs') {
856: $noinstd = 1;
857: } else {
858: $cancreate =
859: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
860: }
861: my ($userpicker,$cansearch) =
862: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
863: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
864: my $srchbutton = &mt('Search');
865: if ($env{'form.action'} eq 'singlestudent') {
866: $srchbutton = &mt('Search and Enroll');
867: } elsif ($env{'form.action'} eq 'accesslogs') {
868: $srchbutton = &mt('Search');
869: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
870: $srchbutton = &mt('Search or Add New User');
871: }
872: my $output;
873: if ($cansearch) {
874: $output = <<"ENDBLOCK";
875: <form action="/adm/createuser" method="post" name="crtuser">
876: <input type="hidden" name="action" value="$env{'form.action'}" />
877: <input type="hidden" name="phase" value="get_user_info" />
878: $userpicker
879: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
880: </form>
881: ENDBLOCK
882: } else {
883: $output = '<p>'.$userpicker.'</p>';
884: }
885: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
886: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
887: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
888: my $defdom=$env{'request.role.domain'};
889: my ($trusted,$untrusted);
890: if ($context eq 'course') {
891: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
892: } elsif ($context eq 'author') {
893: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
894: } elsif ($context eq 'domain') {
895: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
896: }
897: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain',undef,undef,undef,$trusted,$untrusted);
898: my %lt=&Apache::lonlocal::texthash(
899: 'enro' => 'Enroll one student',
900: 'enrm' => 'Enroll one member',
901: 'admo' => 'Add/modify a single user',
902: 'crea' => 'create new user if required',
903: 'uskn' => "username is known",
904: 'crnu' => 'Create a new user',
905: 'usr' => 'Username',
906: 'dom' => 'in domain',
907: 'enrl' => 'Enroll',
908: 'cram' => 'Create/Modify user',
909: );
910: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
911: my ($title,$buttontext,$showresponse);
912: if ($env{'form.action'} eq 'singlestudent') {
913: if ($crstype eq 'Community') {
914: $title = $lt{'enrm'};
915: } else {
916: $title = $lt{'enro'};
917: }
918: $buttontext = $lt{'enrl'};
919: } else {
920: $title = $lt{'admo'};
921: $buttontext = $lt{'cram'};
922: }
923: if ($cancreate) {
924: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
925: } else {
926: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
927: }
928: if ($env{'form.origform'} eq 'crtusername') {
929: $showresponse = $responsemsg;
930: }
931: $output .= <<"ENDDOCUMENT";
932: <br />
933: <form action="/adm/createuser" method="post" name="crtusername">
934: <input type="hidden" name="action" value="$env{'form.action'}" />
935: <input type="hidden" name="phase" value="createnewuser" />
936: <input type="hidden" name="srchtype" value="exact" />
937: <input type="hidden" name="srchby" value="uname" />
938: <input type="hidden" name="srchin" value="dom" />
939: <input type="hidden" name="forcenewuser" value="1" />
940: <input type="hidden" name="origform" value="crtusername" />
941: <h3>$title</h3>
942: $showresponse
943: <table>
944: <tr>
945: <td>$lt{'usr'}:</td>
946: <td><input type="text" size="15" name="srchterm" /></td>
947: <td> $lt{'dom'}:</td><td>$domform</td>
948: <td> $sellink </td>
949: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
950: </tr>
951: </table>
952: </form>
953: ENDDOCUMENT
954: }
955: return $output;
956: }
957:
958: sub user_modification_js {
959: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
960:
961: return <<END;
962: <script type="text/javascript" language="Javascript">
963: // <![CDATA[
964:
965: $pjump_def
966: $dc_setcourse_code
967:
968: function dateset() {
969: eval("document.cu."+document.cu.pres_marker.value+
970: ".value=document.cu.pres_value.value");
971: modalWindow.close();
972: }
973:
974: $nondc_setsection_code
975: // ]]>
976: </script>
977: END
978: }
979:
980: # =================================================================== Phase two
981: sub print_user_selection_page {
982: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
983: my @fields = ('username','domain','lastname','firstname','permanentemail');
984: my $sortby = $env{'form.sortby'};
985:
986: if (!grep(/^\Q$sortby\E$/,@fields)) {
987: $sortby = 'lastname';
988: }
989:
990: my ($jsback,$elements) = &crumb_utilities();
991:
992: my $jscript = (<<ENDSCRIPT);
993: <script type="text/javascript">
994: // <![CDATA[
995: function pickuser(uname,udom) {
996: document.usersrchform.seluname.value=uname;
997: document.usersrchform.seludom.value=udom;
998: document.usersrchform.phase.value="userpicked";
999: document.usersrchform.submit();
1000: }
1001:
1002: $jsback
1003: // ]]>
1004: </script>
1005: ENDSCRIPT
1006:
1007: my %lt=&Apache::lonlocal::texthash(
1008: 'usrch' => "User Search to add/modify roles",
1009: 'stusrch' => "User Search to enroll student",
1010: 'memsrch' => "User Search to enroll member",
1011: 'srcva' => "Search for a user and view access log information",
1012: 'usrvu' => "User Search to view user roles",
1013: 'usel' => "Select a user to add/modify roles",
1014: 'suvr' => "Select a user to view roles",
1015: 'stusel' => "Select a user to enroll as a student",
1016: 'memsel' => "Select a user to enroll as a member",
1017: 'vacsel' => "Select a user to view access log",
1018: 'username' => "username",
1019: 'domain' => "domain",
1020: 'lastname' => "last name",
1021: 'firstname' => "first name",
1022: 'permanentemail' => "permanent e-mail",
1023: );
1024: if ($context eq 'requestcrs') {
1025: $r->print('<div>');
1026: } else {
1027: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1028: my $helpitem;
1029: if ($env{'form.action'} eq 'singleuser') {
1030: $helpitem = 'Course_Change_Privileges';
1031: } elsif ($env{'form.action'} eq 'singlestudent') {
1032: $helpitem = 'Course_Add_Student';
1033: } elsif ($context eq 'author') {
1034: $helpitem = 'Author_Change_Privileges';
1035: } elsif ($context eq 'domain') {
1036: $helpitem = 'Domain_Change_Privileges';
1037: }
1038: push (@{$brcrum},
1039: {href => "javascript:backPage(document.usersrchform,'','')",
1040: text => $breadcrumb_text{'search'},
1041: faq => 282,
1042: bug => 'Instructor Interface',},
1043: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1044: text => $breadcrumb_text{'userpicked'},
1045: faq => 282,
1046: bug => 'Instructor Interface',
1047: help => $helpitem}
1048: );
1049: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1050: if ($env{'form.action'} eq 'singleuser') {
1051: my $readonly;
1052: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1053: $readonly = 1;
1054: $r->print("<b>$lt{'usrvu'}</b><br />");
1055: } else {
1056: $r->print("<b>$lt{'usrch'}</b><br />");
1057: }
1058: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1059: if ($readonly) {
1060: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1061: } else {
1062: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1063: }
1064: } elsif ($env{'form.action'} eq 'singlestudent') {
1065: $r->print($jscript."<b>");
1066: if ($crstype eq 'Community') {
1067: $r->print($lt{'memsrch'});
1068: } else {
1069: $r->print($lt{'stusrch'});
1070: }
1071: $r->print("</b><br />");
1072: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1073: $r->print('</form><h3>');
1074: if ($crstype eq 'Community') {
1075: $r->print($lt{'memsel'});
1076: } else {
1077: $r->print($lt{'stusel'});
1078: }
1079: $r->print('</h3>');
1080: } elsif ($env{'form.action'} eq 'accesslogs') {
1081: $r->print("<b>$lt{'srcva'}</b><br />");
1082: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1083: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1084: }
1085: }
1086: $r->print('<form name="usersrchform" method="post" action="">'.
1087: &Apache::loncommon::start_data_table()."\n".
1088: &Apache::loncommon::start_data_table_header_row()."\n".
1089: ' <th> </th>'."\n");
1090: foreach my $field (@fields) {
1091: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1092: "'".$field."'".';document.usersrchform.submit();">'.
1093: $lt{$field}.'</a></th>'."\n");
1094: }
1095: $r->print(&Apache::loncommon::end_data_table_header_row());
1096:
1097: my @sorted_users = sort {
1098: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1099: ||
1100: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1101: ||
1102: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1103: ||
1104: lc($a) cmp lc($b)
1105: } (keys(%$srch_results));
1106:
1107: foreach my $user (@sorted_users) {
1108: my ($uname,$udom) = split(/:/,$user);
1109: my $onclick;
1110: if ($context eq 'requestcrs') {
1111: $onclick =
1112: 'onclick="javascript:gochoose('."'$uname','$udom',".
1113: "'$srch_results->{$user}->{firstname}',".
1114: "'$srch_results->{$user}->{lastname}',".
1115: "'$srch_results->{$user}->{permanentemail}'".');"';
1116: } else {
1117: $onclick =
1118: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1119: }
1120: $r->print(&Apache::loncommon::start_data_table_row().
1121: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1122: $onclick.' /></td>'.
1123: '<td><tt>'.$uname.'</tt></td>'.
1124: '<td><tt>'.$udom.'</tt></td>');
1125: foreach my $field ('lastname','firstname','permanentemail') {
1126: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1127: }
1128: $r->print(&Apache::loncommon::end_data_table_row());
1129: }
1130: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1131: if (ref($srcharray) eq 'ARRAY') {
1132: foreach my $item (@{$srcharray}) {
1133: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1134: }
1135: }
1136: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1137: ' <input type="hidden" name="seluname" value="" />'."\n".
1138: ' <input type="hidden" name="seludom" value="" />'."\n".
1139: ' <input type="hidden" name="currstate" value="select" />'."\n".
1140: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1141: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1142: if ($context eq 'requestcrs') {
1143: $r->print($opener_elements.'</form></div>');
1144: } else {
1145: $r->print($response.'</form>');
1146: }
1147: }
1148:
1149: sub print_user_query_page {
1150: my ($r,$caller,$brcrum) = @_;
1151: # FIXME - this is for a network-wide name search (similar to catalog search)
1152: # To use frames with similar behavior to catalog/portfolio search.
1153: # To be implemented.
1154: return;
1155: }
1156:
1157: sub print_user_modification_page {
1158: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1159: $brcrum,$showcredits) = @_;
1160: if (($ccuname eq '') || ($ccdomain eq '')) {
1161: my $usermsg = &mt('No username and/or domain provided.');
1162: $env{'form.phase'} = '';
1163: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1164: $permission);
1165: return;
1166: }
1167: my ($form,$formname);
1168: if ($env{'form.action'} eq 'singlestudent') {
1169: $form = 'document.enrollstudent';
1170: $formname = 'enrollstudent';
1171: } else {
1172: $form = 'document.cu';
1173: $formname = 'cu';
1174: }
1175: my %abv_auth = &auth_abbrev();
1176: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1177: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1178: if ($uhome eq 'no_host') {
1179: my $usertype;
1180: my ($rules,$ruleorder) =
1181: &Apache::lonnet::inst_userrules($ccdomain,'username');
1182: $usertype =
1183: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1184: \%curr_rules,\%got_rules);
1185: my $cancreate =
1186: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1187: $usertype);
1188: if (!$cancreate) {
1189: my $helplink = 'javascript:helpMenu('."'display'".')';
1190: my %usertypetext = (
1191: official => 'institutional',
1192: unofficial => 'non-institutional',
1193: );
1194: my $response;
1195: if ($env{'form.origform'} eq 'crtusername') {
1196: $response = '<span class="LC_warning">'.
1197: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1198: '<b>'.$ccuname.'</b>',$ccdomain).
1199: '</span><br />';
1200: }
1201: $response .= '<p class="LC_warning">'
1202: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1203: .' ';
1204: if ($context eq 'domain') {
1205: $response .= &mt('Please contact a [_1] for assistance.',
1206: &Apache::lonnet::plaintext('dc'));
1207: } else {
1208: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1209: ,'<a href="'.$helplink.'">','</a>');
1210: }
1211: $response .= '</p><br />';
1212: $env{'form.phase'} = '';
1213: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1214: $permission);
1215: return;
1216: }
1217: $newuser = 1;
1218: my $checkhash;
1219: my $checks = { 'username' => 1 };
1220: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1221: &Apache::loncommon::user_rule_check($checkhash,$checks,
1222: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1223: if (ref($alerts{'username'}) eq 'HASH') {
1224: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1225: my $domdesc =
1226: &Apache::lonnet::domain($ccdomain,'description');
1227: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1228: my $userchkmsg;
1229: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1230: $userchkmsg =
1231: &Apache::loncommon::instrule_disallow_msg('username',
1232: $domdesc,1).
1233: &Apache::loncommon::user_rule_formats($ccdomain,
1234: $domdesc,$curr_rules{$ccdomain}{'username'},
1235: 'username');
1236: }
1237: $env{'form.phase'} = '';
1238: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1239: $permission);
1240: return;
1241: }
1242: }
1243: }
1244: } else {
1245: $newuser = 0;
1246: }
1247: if ($response) {
1248: $response = '<br />'.$response;
1249: }
1250:
1251: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1252: my $dc_setcourse_code = '';
1253: my $nondc_setsection_code = '';
1254: my %loaditem;
1255:
1256: my $groupslist = &Apache::lonuserutils::get_groupslist();
1257:
1258: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1259: $groupslist,$newuser,$formname,\%loaditem);
1260: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1261: my $helpitem = 'Course_Change_Privileges';
1262: if ($env{'form.action'} eq 'singlestudent') {
1263: $helpitem = 'Course_Add_Student';
1264: } elsif ($context eq 'author') {
1265: $helpitem = 'Author_Change_Privileges';
1266: } elsif ($context eq 'domain') {
1267: $helpitem = 'Domain_Change_Privileges';
1268: }
1269: push (@{$brcrum},
1270: {href => "javascript:backPage($form)",
1271: text => $breadcrumb_text{'search'},
1272: faq => 282,
1273: bug => 'Instructor Interface',});
1274: if ($env{'form.phase'} eq 'userpicked') {
1275: push(@{$brcrum},
1276: {href => "javascript:backPage($form,'get_user_info','select')",
1277: text => $breadcrumb_text{'userpicked'},
1278: faq => 282,
1279: bug => 'Instructor Interface',});
1280: }
1281: push(@{$brcrum},
1282: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1283: text => $breadcrumb_text{'modify'},
1284: faq => 282,
1285: bug => 'Instructor Interface',
1286: help => $helpitem});
1287: my $args = {'add_entries' => \%loaditem,
1288: 'bread_crumbs' => $brcrum,
1289: 'bread_crumbs_component' => 'User Management'};
1290: if ($env{'form.popup'}) {
1291: $args->{'no_nav_bar'} = 1;
1292: }
1293: my $start_page =
1294: &Apache::loncommon::start_page('User Management',$js,$args);
1295:
1296: my $forminfo =<<"ENDFORMINFO";
1297: <form action="/adm/createuser" method="post" name="$formname">
1298: <input type="hidden" name="phase" value="update_user_data" />
1299: <input type="hidden" name="ccuname" value="$ccuname" />
1300: <input type="hidden" name="ccdomain" value="$ccdomain" />
1301: <input type="hidden" name="pres_value" value="" />
1302: <input type="hidden" name="pres_type" value="" />
1303: <input type="hidden" name="pres_marker" value="" />
1304: ENDFORMINFO
1305: my (%inccourses,$roledom,$defaultcredits);
1306: if ($context eq 'course') {
1307: $inccourses{$env{'request.course.id'}}=1;
1308: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1309: if ($showcredits) {
1310: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1311: }
1312: } elsif ($context eq 'author') {
1313: $roledom = $env{'request.role.domain'};
1314: } elsif ($context eq 'domain') {
1315: foreach my $key (keys(%env)) {
1316: $roledom = $env{'request.role.domain'};
1317: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1318: $inccourses{$1.'_'.$2}=1;
1319: }
1320: }
1321: } else {
1322: foreach my $key (keys(%env)) {
1323: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1324: $inccourses{$1.'_'.$2}=1;
1325: }
1326: }
1327: }
1328: my $title = '';
1329: if ($newuser) {
1330: my ($portfolioform,$domroleform);
1331: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1332: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1333: # Current user has quota or user tools modification privileges
1334: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1335: }
1336: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1337: ($ccdomain eq $env{'request.role.domain'})) {
1338: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1339: }
1340: &initialize_authen_forms($ccdomain,$formname);
1341: my %lt=&Apache::lonlocal::texthash(
1342: 'lg' => 'Login Data',
1343: 'hs' => "Home Server",
1344: );
1345: $r->print(<<ENDTITLE);
1346: $start_page
1347: $response
1348: $forminfo
1349: <script type="text/javascript" language="Javascript">
1350: // <![CDATA[
1351: $loginscript
1352: // ]]>
1353: </script>
1354: <input type='hidden' name='makeuser' value='1' />
1355: ENDTITLE
1356: if ($env{'form.action'} eq 'singlestudent') {
1357: if ($crstype eq 'Community') {
1358: $title = &mt('Create New User [_1] in domain [_2] as a member',
1359: '"'.$ccuname.'"','"'.$ccdomain.'"');
1360: } else {
1361: $title = &mt('Create New User [_1] in domain [_2] as a student',
1362: '"'.$ccuname.'"','"'.$ccdomain.'"');
1363: }
1364: } else {
1365: $title = &mt('Create New User [_1] in domain [_2]',
1366: '"'.$ccuname.'"','"'.$ccdomain.'"');
1367: }
1368: $r->print('<h2>'.$title.'</h2>'."\n");
1369: $r->print('<div class="LC_left_float">');
1370: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1371: $inst_results{$ccuname.':'.$ccdomain}));
1372: # Option to disable student/employee ID conflict checking not offerred for new users.
1373: my ($home_server_pick,$numlib) =
1374: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1375: 'default','hide');
1376: if ($numlib > 1) {
1377: $r->print("
1378: <br />
1379: $lt{'hs'}: $home_server_pick
1380: <br />");
1381: } else {
1382: $r->print($home_server_pick);
1383: }
1384: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1385: $r->print('<br /><h3>'.
1386: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1387: &Apache::loncommon::start_data_table().
1388: &build_tools_display($ccuname,$ccdomain,
1389: 'requestcourses').
1390: &Apache::loncommon::end_data_table());
1391: }
1392: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1393: $lt{'lg'}.'</h3>');
1394: my ($fixedauth,$varauth,$authmsg);
1395: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1396: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1397: my ($rules,$ruleorder) =
1398: &Apache::lonnet::inst_userrules($ccdomain,'username');
1399: if (ref($rules) eq 'HASH') {
1400: if (ref($rules->{$matchedrule}) eq 'HASH') {
1401: my $authtype = $rules->{$matchedrule}{'authtype'};
1402: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1403: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1404: } else {
1405: my $authparm = $rules->{$matchedrule}{'authparm'};
1406: $authmsg = $rules->{$matchedrule}{'authmsg'};
1407: if ($authtype =~ /^krb(4|5)$/) {
1408: my $ver = $1;
1409: if ($authparm ne '') {
1410: $fixedauth = <<"KERB";
1411: <input type="hidden" name="login" value="krb" />
1412: <input type="hidden" name="krbver" value="$ver" />
1413: <input type="hidden" name="krbarg" value="$authparm" />
1414: KERB
1415: }
1416: } else {
1417: $fixedauth =
1418: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1419: if ($rules->{$matchedrule}{'authparmfixed'}) {
1420: $fixedauth .=
1421: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1422: } else {
1423: if ($authtype eq 'int') {
1424: $varauth = '<br />'.
1425: &mt('[_1] Internally authenticated (with initial password [_2])','','<input type="password" size="10" name="intarg" value="" />')."<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1426: } elsif ($authtype eq 'loc') {
1427: $varauth = '<br />'.
1428: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1429: } else {
1430: $varauth =
1431: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1432: }
1433: }
1434: }
1435: }
1436: } else {
1437: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1438: }
1439: }
1440: if ($authmsg) {
1441: $r->print(<<ENDAUTH);
1442: $fixedauth
1443: $authmsg
1444: $varauth
1445: ENDAUTH
1446: }
1447: } else {
1448: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1449: }
1450: $r->print($portfolioform.$domroleform);
1451: if ($env{'form.action'} eq 'singlestudent') {
1452: $r->print(&date_sections_select($context,$newuser,$formname,
1453: $permission,$crstype,$ccuname,
1454: $ccdomain,$showcredits));
1455: }
1456: $r->print('</div><div class="LC_clear_float_footer"></div>');
1457: } else { # user already exists
1458: $r->print($start_page.$forminfo);
1459: if ($env{'form.action'} eq 'singlestudent') {
1460: if ($crstype eq 'Community') {
1461: $title = &mt('Enroll one member: [_1] in domain [_2]',
1462: '"'.$ccuname.'"','"'.$ccdomain.'"');
1463: } else {
1464: $title = &mt('Enroll one student: [_1] in domain [_2]',
1465: '"'.$ccuname.'"','"'.$ccdomain.'"');
1466: }
1467: } else {
1468: if ($permission->{'cusr'}) {
1469: $title = &mt('Modify existing user: [_1] in domain [_2]',
1470: '"'.$ccuname.'"','"'.$ccdomain.'"');
1471: } else {
1472: $title = &mt('Existing user: [_1] in domain [_2]',
1473: '"'.$ccuname.'"','"'.$ccdomain.'"');
1474: }
1475: }
1476: $r->print('<h2>'.$title.'</h2>'."\n");
1477: $r->print('<div class="LC_left_float">');
1478: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1479: $inst_results{$ccuname.':'.$ccdomain}));
1480: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1481: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1482: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1483: &Apache::loncommon::start_data_table());
1484: if ($env{'request.role.domain'} eq $ccdomain) {
1485: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1486: } else {
1487: if (&Apache::lonnet::will_trust('reqcrs',$ccdomain,$env{'request.role.domain'})) {
1488: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1489: $env{'request.role.domain'}));
1490: }
1491: }
1492: $r->print(&Apache::loncommon::end_data_table());
1493: }
1494: $r->print('</div>');
1495: my @order = ('auth','quota','tools','requestauthor');
1496: my %user_text;
1497: my ($isadv,$isauthor) =
1498: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1499: if ((!$isauthor) &&
1500: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1501: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1502: ($env{'request.role.domain'} eq $ccdomain)) {
1503: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1504: }
1505: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1506: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1507: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1508: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1509: # Current user has quota modification privileges
1510: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1511: }
1512: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1513: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1514: my %lt=&Apache::lonlocal::texthash(
1515: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1516: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1517: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1518: );
1519: $user_text{'quota'} = <<ENDNOPORTPRIV;
1520: <h3>$lt{'dska'}</h3>
1521: $lt{'youd'} $lt{'ichr'}: $ccdomain
1522: ENDNOPORTPRIV
1523: }
1524: }
1525: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1526: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1527: my %lt=&Apache::lonlocal::texthash(
1528: 'utav' => "User Tools Availability",
1529: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1530: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1531: );
1532: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1533: <h3>$lt{'utav'}</h3>
1534: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1535: ENDNOTOOLSPRIV
1536: }
1537: }
1538: my $gotdiv = 0;
1539: foreach my $item (@order) {
1540: if ($user_text{$item} ne '') {
1541: unless ($gotdiv) {
1542: $r->print('<div class="LC_left_float">');
1543: $gotdiv = 1;
1544: }
1545: $r->print('<br />'.$user_text{$item});
1546: }
1547: }
1548: if ($env{'form.action'} eq 'singlestudent') {
1549: unless ($gotdiv) {
1550: $r->print('<div class="LC_left_float">');
1551: }
1552: my $credits;
1553: if ($showcredits) {
1554: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1555: if ($credits eq '') {
1556: $credits = $defaultcredits;
1557: }
1558: }
1559: $r->print(&date_sections_select($context,$newuser,$formname,
1560: $permission,$crstype,$ccuname,
1561: $ccdomain,$showcredits));
1562: }
1563: if ($gotdiv) {
1564: $r->print('</div><div class="LC_clear_float_footer"></div>');
1565: }
1566: my $statuses;
1567: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1568: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1569: $statuses = ['active'];
1570: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1571: ($env{'request.course.sec'} &&
1572: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1573: $statuses = ['active'];
1574: }
1575: if ($env{'form.action'} ne 'singlestudent') {
1576: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1577: $roledom,$crstype,$showcredits,$statuses);
1578: }
1579: } ## End of new user/old user logic
1580: if ($env{'form.action'} eq 'singlestudent') {
1581: my $btntxt;
1582: if ($crstype eq 'Community') {
1583: $btntxt = &mt('Enroll Member');
1584: } else {
1585: $btntxt = &mt('Enroll Student');
1586: }
1587: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1588: } elsif ($permission->{'cusr'}) {
1589: $r->print('<div class="LC_left_float">'.
1590: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1591: my $addrolesdisplay = 0;
1592: if ($context eq 'domain' || $context eq 'author') {
1593: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1594: }
1595: if ($context eq 'domain') {
1596: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1597: if (!$addrolesdisplay) {
1598: $addrolesdisplay = $add_domainroles;
1599: }
1600: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1601: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1602: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1603: } elsif ($context eq 'author') {
1604: if ($addrolesdisplay) {
1605: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1606: '<br /><input type="button" value="'.&mt('Save').'"');
1607: if ($newuser) {
1608: $r->print(' onclick="auth_check()" \>'."\n");
1609: } else {
1610: $r->print('onclick="this.form.submit()" \>'."\n");
1611: }
1612: } else {
1613: $r->print('</fieldset></div>'.
1614: '<div class="LC_clear_float_footer"></div>'.
1615: '<br /><a href="javascript:backPage(document.cu)">'.
1616: &mt('Back to previous page').'</a>');
1617: }
1618: } else {
1619: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1620: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1621: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1622: }
1623: }
1624: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1625: $r->print('<input type="hidden" name="currstate" value="" />');
1626: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1627: return;
1628: }
1629:
1630: sub singleuser_breadcrumb {
1631: my ($crstype,$context,$domain) = @_;
1632: my %breadcrumb_text;
1633: if ($env{'form.action'} eq 'singlestudent') {
1634: if ($crstype eq 'Community') {
1635: $breadcrumb_text{'search'} = 'Enroll a member';
1636: } else {
1637: $breadcrumb_text{'search'} = 'Enroll a student';
1638: }
1639: $breadcrumb_text{'userpicked'} = 'Select a user';
1640: $breadcrumb_text{'modify'} = 'Set section/dates';
1641: } elsif ($env{'form.action'} eq 'accesslogs') {
1642: $breadcrumb_text{'search'} = 'View access logs for a user';
1643: $breadcrumb_text{'userpicked'} = 'Select a user';
1644: $breadcrumb_text{'activity'} = 'Activity';
1645: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1646: (!&Apache::lonnet::allowed('mau',$domain))) {
1647: $breadcrumb_text{'search'} = "View user's roles";
1648: $breadcrumb_text{'userpicked'} = 'Select a user';
1649: $breadcrumb_text{'modify'} = 'User roles';
1650: } else {
1651: $breadcrumb_text{'search'} = 'Create/modify a user';
1652: $breadcrumb_text{'userpicked'} = 'Select a user';
1653: $breadcrumb_text{'modify'} = 'Set user role';
1654: }
1655: return %breadcrumb_text;
1656: }
1657:
1658: sub date_sections_select {
1659: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1660: $showcredits) = @_;
1661: my $credits;
1662: if ($showcredits) {
1663: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1664: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1665: if ($credits eq '') {
1666: $credits = $defaultcredits;
1667: }
1668: }
1669: my $cid = $env{'request.course.id'};
1670: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1671: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1672: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1673: undef,$formname,$permission);
1674: my $rowtitle = 'Section';
1675: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1676: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1677: $permission,$context,'',$crstype,
1678: $showcredits,$credits);
1679: my $output = $date_table.$secbox;
1680: return $output;
1681: }
1682:
1683: sub validation_javascript {
1684: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1685: $loaditem) = @_;
1686: my $dc_setcourse_code = '';
1687: my $nondc_setsection_code = '';
1688: if ($context eq 'domain') {
1689: my $dcdom = $env{'request.role.domain'};
1690: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1691: $dc_setcourse_code =
1692: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1693: } else {
1694: my $checkauth;
1695: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1696: $checkauth = 1;
1697: }
1698: if ($context eq 'course') {
1699: $nondc_setsection_code =
1700: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1701: undef,$checkauth,
1702: $crstype);
1703: }
1704: if ($checkauth) {
1705: $nondc_setsection_code .=
1706: &Apache::lonuserutils::verify_authen($formname,$context);
1707: }
1708: }
1709: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1710: $nondc_setsection_code,$groupslist);
1711: my ($jsback,$elements) = &crumb_utilities();
1712: $js .= "\n".
1713: '<script type="text/javascript">'."\n".
1714: '// <![CDATA['."\n".
1715: $jsback."\n".
1716: '// ]]>'."\n".
1717: '</script>'."\n";
1718: return $js;
1719: }
1720:
1721: sub display_existing_roles {
1722: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1723: $showcredits,$statuses) = @_;
1724: my $now=time;
1725: my $showall = 1;
1726: my ($showexpired,$showactive);
1727: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1728: $showall = 0;
1729: if (grep(/^expired$/,@{$statuses})) {
1730: $showexpired = 1;
1731: }
1732: if (grep(/^active$/,@{$statuses})) {
1733: $showactive = 1;
1734: }
1735: if ($showexpired && $showactive) {
1736: $showall = 1;
1737: }
1738: }
1739: my %lt=&Apache::lonlocal::texthash(
1740: 'rer' => "Existing Roles",
1741: 'rev' => "Revoke",
1742: 'del' => "Delete",
1743: 'ren' => "Re-Enable",
1744: 'rol' => "Role",
1745: 'ext' => "Extent",
1746: 'crd' => "Credits",
1747: 'sta' => "Start",
1748: 'end' => "End",
1749: );
1750: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1751: if ($context eq 'course' || $context eq 'author') {
1752: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1753: my %roleshash =
1754: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1755: ['active','previous','future'],\@roles,$roledom,1);
1756: foreach my $key (keys(%roleshash)) {
1757: my ($start,$end) = split(':',$roleshash{$key});
1758: next if ($start eq '-1' || $end eq '-1');
1759: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1760: if ($context eq 'course') {
1761: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1762: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1763: } elsif ($context eq 'author') {
1764: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1765: }
1766: my ($newkey,$newvalue,$newrole);
1767: $newkey = '/'.$rdom.'/'.$rnum;
1768: if ($sec ne '') {
1769: $newkey .= '/'.$sec;
1770: }
1771: $newvalue = $role;
1772: if ($role =~ /^cr/) {
1773: $newrole = 'cr';
1774: } else {
1775: $newrole = $role;
1776: }
1777: $newkey .= '_'.$newrole;
1778: if ($start ne '' && $end ne '') {
1779: $newvalue .= '_'.$end.'_'.$start;
1780: } elsif ($end ne '') {
1781: $newvalue .= '_'.$end;
1782: }
1783: $rolesdump{$newkey} = $newvalue;
1784: }
1785: } else {
1786: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1787: }
1788: # Build up table of user roles to allow revocation and re-enabling of roles.
1789: my ($tmp) = keys(%rolesdump);
1790: return if ($tmp =~ /^(con_lost|error)/i);
1791: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1792: my $b1=join('_',(split('_',$b))[1,0]);
1793: return $a1 cmp $b1;
1794: } keys(%rolesdump)) {
1795: next if ($area =~ /^rolesdef/);
1796: my $envkey=$area;
1797: my $role = $rolesdump{$area};
1798: my $thisrole=$area;
1799: $area =~ s/\_\w\w$//;
1800: my ($role_code,$role_end_time,$role_start_time) =
1801: split(/_/,$role);
1802: my $active=1;
1803: $active=0 if (($role_end_time) && ($now>$role_end_time));
1804: if ($active) {
1805: next unless($showall || $showactive);
1806: } else {
1807: next unless($showall || $showexpired);
1808: }
1809: # Is this a custom role? Get role owner and title.
1810: my ($croleudom,$croleuname,$croletitle)=
1811: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1812: my $allowed=0;
1813: my $delallowed=0;
1814: my $sortkey=$role_code;
1815: my $class='Unknown';
1816: my $credits='';
1817: my $csec;
1818: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1819: $class='Course';
1820: my ($coursedom,$coursedir) = ($1,$2);
1821: my $cid = $1.'_'.$2;
1822: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1823: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1824: my %coursedata=
1825: &Apache::lonnet::coursedescription($cid);
1826: if ($coursedir =~ /^$match_community$/) {
1827: $class='Community';
1828: }
1829: $sortkey.="\0$coursedom";
1830: my $carea;
1831: if (defined($coursedata{'description'})) {
1832: $carea=$coursedata{'description'}.
1833: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1834: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1835: $sortkey.="\0".$coursedata{'description'};
1836: } else {
1837: if ($class eq 'Community') {
1838: $carea=&mt('Unavailable community').': '.$area;
1839: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1840: } else {
1841: $carea=&mt('Unavailable course').': '.$area;
1842: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1843: }
1844: }
1845: $sortkey.="\0$coursedir";
1846: $inccourses->{$cid}=1;
1847: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1848: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1849: $credits =
1850: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1851: $coursedom,$coursedir);
1852: if ($credits eq '') {
1853: $credits = $defaultcredits;
1854: }
1855: }
1856: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1857: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1858: $allowed=1;
1859: }
1860: unless ($allowed) {
1861: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1862: if ($isowner) {
1863: if (($role_code eq 'co') && ($class eq 'Community')) {
1864: $allowed = 1;
1865: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1866: $allowed = 1;
1867: }
1868: }
1869: }
1870: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1871: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1872: $delallowed=1;
1873: }
1874: # - custom role. Needs more info, too
1875: if ($croletitle) {
1876: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1877: $allowed=1;
1878: $thisrole.='.'.$role_code;
1879: }
1880: }
1881: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1882: $csec = $2;
1883: $carea.='<br />'.&mt('Section: [_1]',$csec);
1884: $sortkey.="\0$csec";
1885: if (!$allowed) {
1886: if ($env{'request.course.sec'} eq $csec) {
1887: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1888: $allowed = 1;
1889: }
1890: }
1891: }
1892: }
1893: $area=$carea;
1894: } else {
1895: $sortkey.="\0".$area;
1896: # Determine if current user is able to revoke privileges
1897: if ($area=~m{^/($match_domain)/}) {
1898: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1899: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1900: $allowed=1;
1901: }
1902: if (((&Apache::lonnet::allowed('dro',$1)) ||
1903: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1904: ($role_code ne 'dc')) {
1905: $delallowed=1;
1906: }
1907: } else {
1908: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1909: $allowed=1;
1910: }
1911: }
1912: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1913: $class='Authoring Space';
1914: } elsif ($role_code eq 'su') {
1915: $class='System';
1916: } else {
1917: $class='Domain';
1918: }
1919: }
1920: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1921: $area=~m{/($match_domain)/($match_username)};
1922: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1923: $allowed=1;
1924: } else {
1925: $allowed=0;
1926: }
1927: }
1928: my $row = '';
1929: if ($showall) {
1930: $row.= '<td>';
1931: if (($active) && ($allowed)) {
1932: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1933: } else {
1934: if ($active) {
1935: $row.=' ';
1936: } else {
1937: $row.=&mt('expired or revoked');
1938: }
1939: }
1940: $row.='</td><td>';
1941: if ($allowed && !$active) {
1942: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1943: } else {
1944: $row.=' ';
1945: }
1946: $row.='</td><td>';
1947: if ($delallowed) {
1948: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1949: } else {
1950: $row.=' ';
1951: }
1952: $row.= '</td>';
1953: }
1954: my $plaintext='';
1955: if (!$croletitle) {
1956: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1957: if (($showcredits) && ($credits ne '')) {
1958: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1959: '<span class="LC_fontsize_small">'.
1960: &mt('Credits: [_1]',$credits).
1961: '</span></span>';
1962: }
1963: } else {
1964: $plaintext=
1965: &mt('Custom role [_1][_2]defined by [_3]',
1966: '"'.$croletitle.'"',
1967: '<br />',
1968: $croleuname.':'.$croleudom);
1969: }
1970: $row.= '<td>'.$plaintext.'</td>'.
1971: '<td>'.$area.'</td>'.
1972: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1973: : ' ' ).'</td>'.
1974: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1975: : ' ' ).'</td>';
1976: $sortrole{$sortkey}=$envkey;
1977: $roletext{$envkey}=$row;
1978: $roleclass{$envkey}=$class;
1979: if ($allowed) {
1980: $rolepriv{$envkey}='edit';
1981: } else {
1982: if ($context eq 'domain') {
1983: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1984: ($envkey=~m{^/$ccdomain/})) {
1985: $rolepriv{$envkey}='view';
1986: }
1987: } elsif ($context eq 'course') {
1988: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1989: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
1990: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
1991: $rolepriv{$envkey}='view';
1992: }
1993: }
1994: }
1995: } # end of foreach (table building loop)
1996:
1997: my $rolesdisplay = 0;
1998: my %output = ();
1999: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
2000: $output{$type} = '';
2001: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2002: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2003: $output{$type}.=
2004: &Apache::loncommon::start_data_table_row().
2005: $roletext{$sortrole{$which}}.
2006: &Apache::loncommon::end_data_table_row();
2007: }
2008: }
2009: unless($output{$type} eq '') {
2010: $output{$type} = '<tr class="LC_info_row">'.
2011: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2012: $output{$type};
2013: $rolesdisplay = 1;
2014: }
2015: }
2016: if ($rolesdisplay == 1) {
2017: my $contextrole='';
2018: if ($env{'request.course.id'}) {
2019: if (&Apache::loncommon::course_type() eq 'Community') {
2020: $contextrole = &mt('Existing Roles in this Community');
2021: } else {
2022: $contextrole = &mt('Existing Roles in this Course');
2023: }
2024: } elsif ($env{'request.role'} =~ /^au\./) {
2025: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
2026: } else {
2027: if ($showall) {
2028: $contextrole = &mt('Existing Roles in this Domain');
2029: } elsif ($showactive) {
2030: $contextrole = &mt('Unexpired Roles in this Domain');
2031: } elsif ($showexpired) {
2032: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2033: }
2034: }
2035: $r->print('<div class="LC_left_float">'.
2036: '<fieldset><legend>'.$contextrole.'</legend>'.
2037: &Apache::loncommon::start_data_table("LC_createuser").
2038: &Apache::loncommon::start_data_table_header_row());
2039: if ($showall) {
2040: $r->print(
2041: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
2042: );
2043: } elsif ($showexpired) {
2044: $r->print('<th>'.$lt{'rev'}.'</th>');
2045: }
2046: $r->print(
2047: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2048: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
2049: &Apache::loncommon::end_data_table_header_row());
2050: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
2051: if ($output{$type}) {
2052: $r->print($output{$type}."\n");
2053: }
2054: }
2055: $r->print(&Apache::loncommon::end_data_table().
2056: '</fieldset></div>');
2057: }
2058: return;
2059: }
2060:
2061: sub new_coauthor_roles {
2062: my ($r,$ccuname,$ccdomain) = @_;
2063: my $addrolesdisplay = 0;
2064: #
2065: # Co-Author
2066: #
2067: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2068: $env{'request.role.domain'}) &&
2069: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2070: # No sense in assigning co-author role to yourself
2071: $addrolesdisplay = 1;
2072: my $cuname=$env{'user.name'};
2073: my $cudom=$env{'request.role.domain'};
2074: my %lt=&Apache::lonlocal::texthash(
2075: 'cs' => "Authoring Space",
2076: 'act' => "Activate",
2077: 'rol' => "Role",
2078: 'ext' => "Extent",
2079: 'sta' => "Start",
2080: 'end' => "End",
2081: 'cau' => "Co-Author",
2082: 'caa' => "Assistant Co-Author",
2083: 'ssd' => "Set Start Date",
2084: 'sed' => "Set End Date"
2085: );
2086: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2087: &Apache::loncommon::start_data_table()."\n".
2088: &Apache::loncommon::start_data_table_header_row()."\n".
2089: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2090: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2091: '<th>'.$lt{'end'}.'</th>'."\n".
2092: &Apache::loncommon::end_data_table_header_row()."\n".
2093: &Apache::loncommon::start_data_table_row().'
2094: <td>
2095: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
2096: </td>
2097: <td>'.$lt{'cau'}.'</td>
2098: <td>'.$cudom.'_'.$cuname.'</td>
2099: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2100: <a href=
2101: "javascript:pjump('."'date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2102: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2103: <a href=
2104: "javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
2105: &Apache::loncommon::end_data_table_row()."\n".
2106: &Apache::loncommon::start_data_table_row()."\n".
2107: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
2108: <td>'.$lt{'caa'}.'</td>
2109: <td>'.$cudom.'_'.$cuname.'</td>
2110: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2111: <a href=
2112: "javascript:pjump('."'date_start','Start Date Assistant Co-Author',document.cu.start_$cudom\_$cuname\_aa.value,'start_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2113: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2114: <a href=
2115: "javascript:pjump('."'date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
2116: &Apache::loncommon::end_data_table_row()."\n".
2117: &Apache::loncommon::end_data_table());
2118: } elsif ($env{'request.role'} =~ /^au\./) {
2119: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2120: $env{'request.role.domain'}))) {
2121: $r->print('<span class="LC_error">'.
2122: &mt('You do not have privileges to assign co-author roles.').
2123: '</span>');
2124: } elsif (($env{'user.name'} eq $ccuname) &&
2125: ($env{'user.domain'} eq $ccdomain)) {
2126: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Authoring Space is not permitted'));
2127: }
2128: }
2129: return $addrolesdisplay;;
2130: }
2131:
2132: sub new_domain_roles {
2133: my ($r,$ccdomain) = @_;
2134: my $addrolesdisplay = 0;
2135: #
2136: # Domain level
2137: #
2138: my $num_domain_level = 0;
2139: my $domaintext =
2140: '<h4>'.&mt('Domain Level').'</h4>'.
2141: &Apache::loncommon::start_data_table().
2142: &Apache::loncommon::start_data_table_header_row().
2143: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2144: &mt('Extent').'</th>'.
2145: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2146: &Apache::loncommon::end_data_table_header_row();
2147: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
2148: my $uprimary = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2149: my $uintdom = &Apache::lonnet::internet_dom($uprimary);
2150: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
2151: foreach my $role (@allroles) {
2152: next if ($role eq 'ad');
2153: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
2154: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2155: if ($role eq 'dc') {
2156: unless ($thisdomain eq $env{'request.role.domain'}) {
2157: my $domprim = &Apache::lonnet::domain($thisdomain,'primary');
2158: my $intdom = &Apache::lonnet::internet_dom($domprim);
2159: next unless ($uintdom eq $intdom);
2160: }
2161: }
2162: my $plrole=&Apache::lonnet::plaintext($role);
2163: my %lt=&Apache::lonlocal::texthash(
2164: 'ssd' => "Set Start Date",
2165: 'sed' => "Set End Date"
2166: );
2167: $num_domain_level ++;
2168: $domaintext .=
2169: &Apache::loncommon::start_data_table_row().
2170: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
2171: <td>'.$plrole.'</td>
2172: <td>'.$thisdomain.'</td>
2173: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2174: <a href=
2175: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2176: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2177: <a href=
2178: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2179: &Apache::loncommon::end_data_table_row();
2180: }
2181: }
2182: }
2183: $domaintext.= &Apache::loncommon::end_data_table();
2184: if ($num_domain_level > 0) {
2185: $r->print($domaintext);
2186: $addrolesdisplay = 1;
2187: }
2188: return $addrolesdisplay;
2189: }
2190:
2191: sub user_authentication {
2192: my ($ccuname,$ccdomain,$formname) = @_;
2193: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
2194: my $outcome;
2195: my %lt=&Apache::lonlocal::texthash(
2196: 'err' => "ERROR",
2197: 'uuas' => "This user has an unrecognized authentication scheme",
2198: 'adcs' => "Please alert a domain coordinator of this situation",
2199: 'sldb' => "Please specify login data below",
2200: 'ld' => "Login Data"
2201: );
2202: # Check for a bad authentication type
2203: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2204: # bad authentication scheme
2205: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2206: &initialize_authen_forms($ccdomain,$formname);
2207:
2208: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
2209: $outcome = <<ENDBADAUTH;
2210: <script type="text/javascript" language="Javascript">
2211: // <![CDATA[
2212: $loginscript
2213: // ]]>
2214: </script>
2215: <span class="LC_error">$lt{'err'}:
2216: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2217: <h3>$lt{'ld'}</h3>
2218: $choices
2219: ENDBADAUTH
2220: } else {
2221: # This user is not allowed to modify the user's
2222: # authentication scheme, so just notify them of the problem
2223: $outcome = <<ENDBADAUTH;
2224: <span class="LC_error"> $lt{'err'}:
2225: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2226: </span>
2227: ENDBADAUTH
2228: }
2229: } else { # Authentication type is valid
2230:
2231: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
2232: my ($authformcurrent,$can_modify,@authform_others) =
2233: &modify_login_block($ccdomain,$currentauth);
2234: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2235: # Current user has login modification privileges
2236: $outcome =
2237: '<script type="text/javascript" language="Javascript">'."\n".
2238: '// <![CDATA['."\n".
2239: $loginscript."\n".
2240: '// ]]>'."\n".
2241: '</script>'."\n".
2242: '<h3>'.$lt{'ld'}.'</h3>'.
2243: &Apache::loncommon::start_data_table().
2244: &Apache::loncommon::start_data_table_row().
2245: '<td>'.$authformnop;
2246: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
2247: $outcome .= '</td>'."\n".
2248: &Apache::loncommon::end_data_table_row().
2249: &Apache::loncommon::start_data_table_row().
2250: '<td>'.$authformcurrent.'</td>'.
2251: &Apache::loncommon::end_data_table_row()."\n";
2252: } else {
2253: $outcome .= ' ('.$authformcurrent.')</td>'.
2254: &Apache::loncommon::end_data_table_row()."\n";
2255: }
2256: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2257: foreach my $item (@authform_others) {
2258: $outcome .= &Apache::loncommon::start_data_table_row().
2259: '<td>'.$item.'</td>'.
2260: &Apache::loncommon::end_data_table_row()."\n";
2261: }
2262: }
2263: $outcome .= &Apache::loncommon::end_data_table();
2264: } else {
2265: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2266: # Current user has rights to view domain preferences for user's domain
2267: my $result;
2268: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2269: my ($krbver,$krbrealm) = ($1,$2);
2270: if ($krbrealm eq '') {
2271: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2272: } else {
2273: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2274: $krbrealm,$krbver);
2275: }
2276: } elsif ($currentauth =~ /^internal:/) {
2277: $result = &mt('Currently internally authenticated.');
2278: } elsif ($currentauth =~ /^localauth:/) {
2279: $result = &mt('Currently using local (institutional) authentication.');
2280: } elsif ($currentauth =~ /^unix:/) {
2281: $result = &mt('Currently Filesystem Authenticated.');
2282: }
2283: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2284: &Apache::loncommon::start_data_table().
2285: &Apache::loncommon::start_data_table_row().
2286: '<td>'.$result.'</td>'.
2287: &Apache::loncommon::end_data_table_row()."\n".
2288: &Apache::loncommon::end_data_table();
2289: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
2290: my %lt=&Apache::lonlocal::texthash(
2291: 'ccld' => "Change Current Login Data",
2292: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2293: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2294: );
2295: $outcome .= <<ENDNOPRIV;
2296: <h3>$lt{'ccld'}</h3>
2297: $lt{'yodo'} $lt{'ifch'}: $ccdomain
2298: <input type="hidden" name="login" value="nochange" />
2299: ENDNOPRIV
2300: }
2301: }
2302: } ## End of "check for bad authentication type" logic
2303: return $outcome;
2304: }
2305:
2306: sub modify_login_block {
2307: my ($dom,$currentauth) = @_;
2308: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2309: my ($authnum,%can_assign) =
2310: &Apache::loncommon::get_assignable_auth($dom);
2311: my ($authformcurrent,@authform_others,$show_override_msg);
2312: if ($currentauth=~/^krb(4|5):/) {
2313: $authformcurrent=$authformkrb;
2314: if ($can_assign{'int'}) {
2315: push(@authform_others,$authformint);
2316: }
2317: if ($can_assign{'loc'}) {
2318: push(@authform_others,$authformloc);
2319: }
2320: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2321: $show_override_msg = 1;
2322: }
2323: } elsif ($currentauth=~/^internal:/) {
2324: $authformcurrent=$authformint;
2325: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2326: push(@authform_others,$authformkrb);
2327: }
2328: if ($can_assign{'loc'}) {
2329: push(@authform_others,$authformloc);
2330: }
2331: if ($can_assign{'int'}) {
2332: $show_override_msg = 1;
2333: }
2334: } elsif ($currentauth=~/^unix:/) {
2335: $authformcurrent=$authformfsys;
2336: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2337: push(@authform_others,$authformkrb);
2338: }
2339: if ($can_assign{'int'}) {
2340: push(@authform_others,$authformint);
2341: }
2342: if ($can_assign{'loc'}) {
2343: push(@authform_others,$authformloc);
2344: }
2345: if ($can_assign{'fsys'}) {
2346: $show_override_msg = 1;
2347: }
2348: } elsif ($currentauth=~/^localauth:/) {
2349: $authformcurrent=$authformloc;
2350: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2351: push(@authform_others,$authformkrb);
2352: }
2353: if ($can_assign{'int'}) {
2354: push(@authform_others,$authformint);
2355: }
2356: if ($can_assign{'loc'}) {
2357: $show_override_msg = 1;
2358: }
2359: }
2360: if ($show_override_msg) {
2361: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2362: '</td></tr>'."\n".
2363: '<tr><td> </td>'.
2364: '<td><b>'.&mt('Currently in use').'</b></td>'.
2365: '<td align="right"><span class="LC_cusr_emph">'.
2366: &mt('will override current values').
2367: '</span></td></tr></table>';
2368: }
2369: return ($authformcurrent,$show_override_msg,@authform_others);
2370: }
2371:
2372: sub personal_data_display {
2373: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
2374: $now,$captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded) = @_;
2375: my ($output,%userenv,%canmodify,%canmodify_status);
2376: my @userinfo = ('firstname','middlename','lastname','generation',
2377: 'permanentemail','id');
2378: my $rowcount = 0;
2379: my $editable = 0;
2380: my %textboxsize = (
2381: firstname => '15',
2382: middlename => '15',
2383: lastname => '15',
2384: generation => '5',
2385: permanentemail => '25',
2386: id => '15',
2387: );
2388:
2389: my %lt=&Apache::lonlocal::texthash(
2390: 'pd' => "Personal Data",
2391: 'firstname' => "First Name",
2392: 'middlename' => "Middle Name",
2393: 'lastname' => "Last Name",
2394: 'generation' => "Generation",
2395: 'permanentemail' => "Permanent e-mail address",
2396: 'id' => "Student/Employee ID",
2397: 'lg' => "Login Data",
2398: 'inststatus' => "Affiliation",
2399: 'email' => 'E-mail address',
2400: 'valid' => 'Validation',
2401: 'username' => 'Username',
2402: );
2403:
2404: %canmodify_status =
2405: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2406: ['inststatus'],$rolesarray);
2407: if (!$newuser) {
2408: # Get the users information
2409: %userenv = &Apache::lonnet::get('environment',
2410: ['firstname','middlename','lastname','generation',
2411: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
2412: %canmodify =
2413: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2414: \@userinfo,$rolesarray);
2415: } elsif ($context eq 'selfcreate') {
2416: if ($newuser eq 'email') {
2417: if (ref($emailusername) eq 'HASH') {
2418: if (ref($emailusername->{$usertype}) eq 'HASH') {
2419: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
2420: @userinfo = ();
2421: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2422: foreach my $field (@{$infofields}) {
2423: if ($emailusername->{$usertype}->{$field}) {
2424: push(@userinfo,$field);
2425: $canmodify{$field} = 1;
2426: unless ($textboxsize{$field}) {
2427: $textboxsize{$field} = 25;
2428: }
2429: unless ($lt{$field}) {
2430: $lt{$field} = $infotitles->{$field};
2431: }
2432: if ($emailusername->{$usertype}->{$field} eq 'required') {
2433: $lt{$field} .= '<b>*</b>';
2434: }
2435: }
2436: }
2437: }
2438: }
2439: }
2440: } else {
2441: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2442: $inst_results,$rolesarray);
2443: }
2444: }
2445:
2446: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2447: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2448: &Apache::lonhtmlcommon::start_pick_box();
2449: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2450: my $size = 25;
2451: if ($condition) {
2452: if ($condition =~ /^\@[^\@]+$/) {
2453: $size = 10;
2454: } else {
2455: undef($condition);
2456: }
2457: }
2458: if ($excluded) {
2459: unless ($excluded =~ /^\@[^\@]+$/) {
2460: undef($condition);
2461: }
2462: }
2463: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
2464: 'LC_oddrow_value')."\n".
2465: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2466: if ($condition) {
2467: $output .= $condition;
2468: } elsif ($excluded) {
2469: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2470: $excluded).'</span>';
2471: }
2472: if ($usernameset eq 'first') {
2473: $output .= '<br /><span style="font-size: smaller">';
2474: if ($condition) {
2475: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2476: $condition);
2477: } else {
2478: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2479: }
2480: $output .= '</span>';
2481: }
2482: $rowcount ++;
2483: $output .= &Apache::lonhtmlcommon::row_closure(1);
2484: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2485: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
2486: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
2487: 'LC_pick_box_title',
2488: 'LC_oddrow_value')."\n".
2489: $upassone."\n".
2490: &Apache::lonhtmlcommon::row_closure(1)."\n".
2491: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
2492: 'LC_pick_box_title',
2493: 'LC_oddrow_value')."\n".
2494: $upasstwo.
2495: &Apache::lonhtmlcommon::row_closure()."\n";
2496: if ($usernameset eq 'free') {
2497: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
2498: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
2499: &mt('Use e-mail address: ').
2500: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.&mt('Yes').'</label>'."\n".
2501: (' 'x2).
2502: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.&mt('No').'</label>'."\n".
2503: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2504: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2505: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2506: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2507: $rowcount ++;
2508: }
2509: }
2510: foreach my $item (@userinfo) {
2511: my $rowtitle = $lt{$item};
2512: my $hiderow = 0;
2513: if ($item eq 'generation') {
2514: $rowtitle = $genhelp.$rowtitle;
2515: }
2516: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
2517: if ($newuser) {
2518: if (ref($inst_results) eq 'HASH') {
2519: if ($inst_results->{$item} ne '') {
2520: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
2521: } else {
2522: if ($context eq 'selfcreate') {
2523: if ($canmodify{$item}) {
2524: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
2525: $editable ++;
2526: } else {
2527: $hiderow = 1;
2528: }
2529: } else {
2530: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2531: }
2532: }
2533: } else {
2534: if ($context eq 'selfcreate') {
2535: if ($canmodify{$item}) {
2536: if ($newuser eq 'email') {
2537: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
2538: } else {
2539: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
2540: }
2541: $editable ++;
2542: } else {
2543: $hiderow = 1;
2544: }
2545: } else {
2546: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2547: }
2548: }
2549: } else {
2550: if ($canmodify{$item}) {
2551: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
2552: if (($item eq 'id') && (!$newuser)) {
2553: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2554: }
2555: } else {
2556: $row .= $userenv{$item};
2557: }
2558: }
2559: $row .= &Apache::lonhtmlcommon::row_closure(1);
2560: if (!$hiderow) {
2561: $output .= $row;
2562: $rowcount ++;
2563: }
2564: }
2565: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2566: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2567: if (ref($types) eq 'ARRAY') {
2568: if (@{$types} > 0) {
2569: my ($hiderow,$shown);
2570: if ($canmodify_status{'inststatus'}) {
2571: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2572: } else {
2573: if ($userenv{'inststatus'} eq '') {
2574: $hiderow = 1;
2575: } else {
2576: my @showitems;
2577: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2578: if (exists($usertypes->{$item})) {
2579: push(@showitems,$usertypes->{$item});
2580: } else {
2581: push(@showitems,$item);
2582: }
2583: }
2584: if (@showitems) {
2585: $shown = join(', ',@showitems);
2586: } else {
2587: $hiderow = 1;
2588: }
2589: }
2590: }
2591: if (!$hiderow) {
2592: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
2593: $shown.&Apache::lonhtmlcommon::row_closure(1);
2594: if ($context eq 'selfcreate') {
2595: $rowcount ++;
2596: }
2597: $output .= $row;
2598: }
2599: }
2600: }
2601: }
2602: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2603: if ($captchaform) {
2604: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2605: 'LC_pick_box_title')."\n".
2606: $captchaform."\n".'<br /><br />'.
2607: &Apache::lonhtmlcommon::row_closure(1);
2608: $rowcount ++;
2609: }
2610: my $submit_text = &mt('Create account');
2611: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2612: '<br /><input type="submit" name="createaccount" value="'.
2613: $submit_text.'" />'.
2614: '<input type="hidden" name="type" value="'.$usertype.'" />'.
2615: &Apache::lonhtmlcommon::row_closure(1);
2616: }
2617: $output .= &Apache::lonhtmlcommon::end_pick_box();
2618: if (wantarray) {
2619: if ($context eq 'selfcreate') {
2620: return($output,$rowcount,$editable);
2621: } else {
2622: return $output;
2623: }
2624: } else {
2625: return $output;
2626: }
2627: }
2628:
2629: sub pick_inst_statuses {
2630: my ($curr,$usertypes,$types) = @_;
2631: my ($output,$rem,@currtypes);
2632: if ($curr ne '') {
2633: @currtypes = map { &unescape($_); } split(/:/,$curr);
2634: }
2635: my $numinrow = 2;
2636: if (ref($types) eq 'ARRAY') {
2637: $output = '<table>';
2638: my $lastcolspan;
2639: for (my $i=0; $i<@{$types}; $i++) {
2640: if (defined($usertypes->{$types->[$i]})) {
2641: my $rem = $i%($numinrow);
2642: if ($rem == 0) {
2643: if ($i<@{$types}-1) {
2644: if ($i > 0) {
2645: $output .= '</tr>';
2646: }
2647: $output .= '<tr>';
2648: }
2649: } elsif ($i==@{$types}-1) {
2650: my $colsleft = $numinrow - $rem;
2651: if ($colsleft > 1) {
2652: $lastcolspan = ' colspan="'.$colsleft.'"';
2653: }
2654: }
2655: my $check = ' ';
2656: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2657: $check = ' checked="checked" ';
2658: }
2659: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2660: '<span class="LC_nobreak"><label>'.
2661: '<input type="checkbox" name="inststatus" '.
2662: 'value="'.$types->[$i].'"'.$check.'/>'.
2663: $usertypes->{$types->[$i]}.'</label></span></td>';
2664: }
2665: }
2666: $output .= '</tr></table>';
2667: }
2668: return $output;
2669: }
2670:
2671: sub selfcreate_canmodify {
2672: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2673: if (ref($inst_results) eq 'HASH') {
2674: my @inststatuses = &get_inststatuses($inst_results);
2675: if (@inststatuses == 0) {
2676: @inststatuses = ('default');
2677: }
2678: $rolesarray = \@inststatuses;
2679: }
2680: my %canmodify =
2681: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2682: $rolesarray);
2683: return %canmodify;
2684: }
2685:
2686: sub get_inststatuses {
2687: my ($insthashref) = @_;
2688: my @inststatuses = ();
2689: if (ref($insthashref) eq 'HASH') {
2690: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2691: @inststatuses = @{$insthashref->{'inststatus'}};
2692: }
2693: }
2694: return @inststatuses;
2695: }
2696:
2697: # ================================================================= Phase Three
2698: sub update_user_data {
2699: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
2700: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2701: $env{'form.ccdomain'});
2702: # Error messages
2703: my $error = '<span class="LC_error">'.&mt('Error').': ';
2704: my $end = '</span><br /><br />';
2705: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
2706: "'$env{'form.prevphase'}','modify')".'" />'.
2707: &mt('Return to previous page').'</a>'.
2708: &Apache::loncommon::end_page();
2709: my $now = time;
2710: my $title;
2711: if (exists($env{'form.makeuser'})) {
2712: $title='Set Privileges for New User';
2713: } else {
2714: $title='Modify User Privileges';
2715: }
2716: my $newuser = 0;
2717: my ($jsback,$elements) = &crumb_utilities();
2718: my $jscript = '<script type="text/javascript">'."\n".
2719: '// <![CDATA['."\n".
2720: $jsback."\n".
2721: '// ]]>'."\n".
2722: '</script>'."\n";
2723: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
2724: push (@{$brcrum},
2725: {href => "javascript:backPage(document.userupdate)",
2726: text => $breadcrumb_text{'search'},
2727: faq => 282,
2728: bug => 'Instructor Interface',}
2729: );
2730: if ($env{'form.prevphase'} eq 'userpicked') {
2731: push(@{$brcrum},
2732: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2733: text => $breadcrumb_text{'userpicked'},
2734: faq => 282,
2735: bug => 'Instructor Interface',});
2736: }
2737: my $helpitem = 'Course_Change_Privileges';
2738: if ($env{'form.action'} eq 'singlestudent') {
2739: $helpitem = 'Course_Add_Student';
2740: } elsif ($context eq 'author') {
2741: $helpitem = 'Author_Change_Privileges';
2742: } elsif ($context eq 'domain') {
2743: $helpitem = 'Domain_Change_Privileges';
2744: }
2745: push(@{$brcrum},
2746: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2747: text => $breadcrumb_text{'modify'},
2748: faq => 282,
2749: bug => 'Instructor Interface',},
2750: {href => "/adm/createuser",
2751: text => "Result",
2752: faq => 282,
2753: bug => 'Instructor Interface',
2754: help => $helpitem});
2755: my $args = {bread_crumbs => $brcrum,
2756: bread_crumbs_component => 'User Management'};
2757: if ($env{'form.popup'}) {
2758: $args->{'no_nav_bar'} = 1;
2759: }
2760: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
2761: $r->print(&update_result_form($uhome));
2762: # Check Inputs
2763: if (! $env{'form.ccuname'} ) {
2764: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
2765: return;
2766: }
2767: if ( $env{'form.ccuname'} ne
2768: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
2769: $r->print($error.&mt('Invalid login name.').' '.
2770: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
2771: $end.$rtnlink);
2772: return;
2773: }
2774: if (! $env{'form.ccdomain'} ) {
2775: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
2776: return;
2777: }
2778: if ( $env{'form.ccdomain'} ne
2779: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
2780: $r->print($error.&mt('Invalid domain name.').' '.
2781: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
2782: $end.$rtnlink);
2783: return;
2784: }
2785: if ($uhome eq 'no_host') {
2786: $newuser = 1;
2787: }
2788: if (! exists($env{'form.makeuser'})) {
2789: # Modifying an existing user, so check the validity of the name
2790: if ($uhome eq 'no_host') {
2791: $r->print(
2792: $error
2793: .'<p class="LC_error">'
2794: .&mt('Unable to determine home server for [_1] in domain [_2].',
2795: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2796: .'</p>');
2797: return;
2798: }
2799: }
2800: # Determine authentication method and password for the user being modified
2801: my $amode='';
2802: my $genpwd='';
2803: if ($env{'form.login'} eq 'krb') {
2804: $amode='krb';
2805: $amode.=$env{'form.krbver'};
2806: $genpwd=$env{'form.krbarg'};
2807: } elsif ($env{'form.login'} eq 'int') {
2808: $amode='internal';
2809: $genpwd=$env{'form.intarg'};
2810: } elsif ($env{'form.login'} eq 'fsys') {
2811: $amode='unix';
2812: $genpwd=$env{'form.fsysarg'};
2813: } elsif ($env{'form.login'} eq 'loc') {
2814: $amode='localauth';
2815: $genpwd=$env{'form.locarg'};
2816: $genpwd=" " if (!$genpwd);
2817: } elsif (($env{'form.login'} eq 'nochange') ||
2818: ($env{'form.login'} eq '' )) {
2819: # There is no need to tell the user we did not change what they
2820: # did not ask us to change.
2821: # If they are creating a new user but have not specified login
2822: # information this will be caught below.
2823: } else {
2824: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2825: return;
2826: }
2827:
2828: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
2829: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2830: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2831: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
2832:
2833: my (%alerts,%rulematch,%inst_results,%curr_rules);
2834: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
2835: my @usertools = ('aboutme','blog','webdav','portfolio');
2836: my @requestcourses = ('official','unofficial','community','textbook','placement');
2837: my @requestauthor = ('requestauthor');
2838: my ($othertitle,$usertypes,$types) =
2839: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
2840: my %canmodify_status =
2841: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2842: ['inststatus']);
2843: if ($env{'form.makeuser'}) {
2844: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
2845: # Check for the authentication mode and password
2846: if (! $amode || ! $genpwd) {
2847: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2848: return;
2849: }
2850: # Determine desired host
2851: my $desiredhost = $env{'form.hserver'};
2852: if (lc($desiredhost) eq 'default') {
2853: $desiredhost = undef;
2854: } else {
2855: my %home_servers =
2856: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
2857: if (! exists($home_servers{$desiredhost})) {
2858: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2859: return;
2860: }
2861: }
2862: # Check ID format
2863: my %checkhash;
2864: my %checks = ('id' => 1);
2865: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
2866: 'newuser' => $newuser,
2867: 'id' => $env{'form.cid'},
2868: );
2869: if ($env{'form.cid'} ne '') {
2870: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2871: \%rulematch,\%inst_results,\%curr_rules);
2872: if (ref($alerts{'id'}) eq 'HASH') {
2873: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2874: my $domdesc =
2875: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2876: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2877: my $userchkmsg;
2878: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2879: $userchkmsg =
2880: &Apache::loncommon::instrule_disallow_msg('id',
2881: $domdesc,1).
2882: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2883: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2884: }
2885: $r->print($error.&mt('Invalid ID format').$end.
2886: $userchkmsg.$rtnlink);
2887: return;
2888: }
2889: }
2890: }
2891: }
2892: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
2893: # Call modifyuser
2894: my $result = &Apache::lonnet::modifyuser
2895: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
2896: $amode,$genpwd,$env{'form.cfirstname'},
2897: $env{'form.cmiddlename'},$env{'form.clastname'},
2898: $env{'form.cgeneration'},undef,$desiredhost,
2899: $env{'form.cpermanentemail'});
2900: $r->print(&mt('Generating user').': '.$result);
2901: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
2902: $env{'form.ccdomain'});
2903: my (%changeHash,%newcustom,%changed,%changedinfo);
2904: if ($uhome ne 'no_host') {
2905: if ($context eq 'domain') {
2906: foreach my $name ('portfolio','author') {
2907: if ($env{'form.custom_'.$name.'quota'} == 1) {
2908: if ($env{'form.'.$name.'quota'} eq '') {
2909: $newcustom{$name.'quota'} = 0;
2910: } else {
2911: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2912: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2913: }
2914: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2915: $changed{$name.'quota'} = 1;
2916: }
2917: }
2918: }
2919: foreach my $item (@usertools) {
2920: if ($env{'form.custom'.$item} == 1) {
2921: $newcustom{$item} = $env{'form.tools_'.$item};
2922: $changed{$item} = &tool_admin($item,$newcustom{$item},
2923: \%changeHash,'tools');
2924: }
2925: }
2926: foreach my $item (@requestcourses) {
2927: if ($env{'form.custom'.$item} == 1) {
2928: $newcustom{$item} = $env{'form.crsreq_'.$item};
2929: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2930: $newcustom{$item} .= '=';
2931: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2932: if ($env{'form.crsreq_'.$item.'_limit'}) {
2933: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2934: }
2935: }
2936: $changed{$item} = &tool_admin($item,$newcustom{$item},
2937: \%changeHash,'requestcourses');
2938: }
2939: }
2940: if ($env{'form.customrequestauthor'} == 1) {
2941: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2942: $changed{'requestauthor'} = &tool_admin('requestauthor',
2943: $newcustom{'requestauthor'},
2944: \%changeHash,'requestauthor');
2945: }
2946: }
2947: if ($canmodify_status{'inststatus'}) {
2948: if (exists($env{'form.inststatus'})) {
2949: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2950: if (@inststatuses > 0) {
2951: $changeHash{'inststatus'} = join(',',@inststatuses);
2952: $changed{'inststatus'} = $changeHash{'inststatus'};
2953: }
2954: }
2955: }
2956: if (keys(%changed)) {
2957: foreach my $item (@userinfo) {
2958: $changeHash{$item} = $env{'form.c'.$item};
2959: }
2960: my $chgresult =
2961: &Apache::lonnet::put('environment',\%changeHash,
2962: $env{'form.ccdomain'},$env{'form.ccuname'});
2963: }
2964: }
2965: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2966: &Apache::lonnet::hostname($uhome));
2967: } elsif (($env{'form.login'} ne 'nochange') &&
2968: ($env{'form.login'} ne '' )) {
2969: # Modify user privileges
2970: if (! $amode || ! $genpwd) {
2971: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
2972: return;
2973: }
2974: # Only allow authentication modification if the person has authority
2975: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
2976: $r->print('Modifying authentication: '.
2977: &Apache::lonnet::modifyuserauth(
2978: $env{'form.ccdomain'},$env{'form.ccuname'},
2979: $amode,$genpwd));
2980: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
2981: ($env{'form.ccuname'},$env{'form.ccdomain'}));
2982: } else {
2983: # Okay, this is a non-fatal error.
2984: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
2985: }
2986: }
2987: $r->rflush(); # Finish display of header before time consuming actions start
2988: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
2989: ##
2990: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
2991: if ($context eq 'course') {
2992: ($cnum,$cdom) =
2993: &Apache::lonuserutils::get_course_identity();
2994: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
2995: if ($showcredits) {
2996: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2997: }
2998: }
2999: if (! $env{'form.makeuser'} ) {
3000: # Check for need to change
3001: my %userenv = &Apache::lonnet::get
3002: ('environment',['firstname','middlename','lastname','generation',
3003: 'id','permanentemail','portfolioquota','authorquota','inststatus',
3004: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
3005: 'requestcourses.official','requestcourses.unofficial',
3006: 'requestcourses.community','requestcourses.textbook',
3007: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3008: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
3009: 'reqcrsotherdom.placement','requestauthor'],
3010: $env{'form.ccdomain'},$env{'form.ccuname'});
3011: my ($tmp) = keys(%userenv);
3012: if ($tmp =~ /^(con_lost|error)/i) {
3013: %userenv = ();
3014: }
3015: my $no_forceid_alert;
3016: # Check to see if user information can be changed
3017: my %domconfig =
3018: &Apache::lonnet::get_dom('configuration',['usermodification'],
3019: $env{'form.ccdomain'});
3020: my @statuses = ('active','future');
3021: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3022: my ($auname,$audom);
3023: if ($context eq 'author') {
3024: $auname = $env{'user.name'};
3025: $audom = $env{'user.domain'};
3026: }
3027: foreach my $item (keys(%roles)) {
3028: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
3029: if ($context eq 'course') {
3030: if ($cnum ne '' && $cdom ne '') {
3031: if ($rolenum eq $cnum && $roledom eq $cdom) {
3032: if (!grep(/^\Q$role\E$/,@userroles)) {
3033: push(@userroles,$role);
3034: }
3035: }
3036: }
3037: } elsif ($context eq 'author') {
3038: if ($rolenum eq $auname && $roledom eq $audom) {
3039: if (!grep(/^\Q$role\E$/,@userroles)) {
3040: push(@userroles,$role);
3041: }
3042: }
3043: }
3044: }
3045: if ($env{'form.action'} eq 'singlestudent') {
3046: if (!grep(/^st$/,@userroles)) {
3047: push(@userroles,'st');
3048: }
3049: } else {
3050: # Check for course or co-author roles being activated or re-enabled
3051: if ($context eq 'author' || $context eq 'course') {
3052: foreach my $key (keys(%env)) {
3053: if ($context eq 'author') {
3054: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3055: if (!grep(/^\Q$1\E$/,@userroles)) {
3056: push(@userroles,$1);
3057: }
3058: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3059: if (!grep(/^\Q$1\E$/,@userroles)) {
3060: push(@userroles,$1);
3061: }
3062: }
3063: } elsif ($context eq 'course') {
3064: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3065: if (!grep(/^\Q$1\E$/,@userroles)) {
3066: push(@userroles,$1);
3067: }
3068: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3069: if (!grep(/^\Q$1\E$/,@userroles)) {
3070: push(@userroles,$1);
3071: }
3072: }
3073: }
3074: }
3075: }
3076: }
3077: #Check to see if we can change personal data for the user
3078: my (@mod_disallowed,@longroles);
3079: foreach my $role (@userroles) {
3080: if ($role eq 'cr') {
3081: push(@longroles,'Custom');
3082: } else {
3083: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
3084: }
3085: }
3086: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3087: foreach my $item (@userinfo) {
3088: # Strip leading and trailing whitespace
3089: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
3090: if (!$canmodify{$item}) {
3091: if (defined($env{'form.c'.$item})) {
3092: if ($env{'form.c'.$item} ne $userenv{$item}) {
3093: push(@mod_disallowed,$item);
3094: }
3095: }
3096: $env{'form.c'.$item} = $userenv{$item};
3097: }
3098: }
3099: # Check to see if we can change the Student/Employee ID
3100: my $forceid = $env{'form.forceid'};
3101: my $recurseid = $env{'form.recurseid'};
3102: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
3103: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3104: $env{'form.ccuname'});
3105: if (($uidhash{$env{'form.ccuname'}}) &&
3106: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3107: (!$forceid)) {
3108: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3109: $env{'form.cid'} = $userenv{'id'};
3110: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
3111: .'<br />'
3112: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3113: .'<br />'."\n";
3114: }
3115: }
3116: if ($env{'form.cid'} ne $userenv{'id'}) {
3117: my $checkhash;
3118: my $checks = { 'id' => 1 };
3119: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3120: { 'newuser' => $newuser,
3121: 'id' => $env{'form.cid'},
3122: };
3123: &Apache::loncommon::user_rule_check($checkhash,$checks,
3124: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3125: if (ref($alerts{'id'}) eq 'HASH') {
3126: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
3127: $env{'form.cid'} = $userenv{'id'};
3128: }
3129: }
3130: }
3131: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3132: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
3133: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
3134: %oldsettingstatus,%newsettingstatus);
3135: @disporder = ('inststatus');
3136: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
3137: push(@disporder,'requestcourses','requestauthor');
3138: } else {
3139: push(@disporder,'reqcrsotherdom');
3140: }
3141: push(@disporder,('quota','tools'));
3142: $oldinststatus = $userenv{'inststatus'};
3143: foreach my $name ('portfolio','author') {
3144: ($olddefquota{$name},$oldsettingstatus{$name}) =
3145: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3146: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3147: }
3148: my %canshow;
3149: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
3150: $canshow{'quota'} = 1;
3151: }
3152: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
3153: $canshow{'tools'} = 1;
3154: }
3155: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
3156: $canshow{'requestcourses'} = 1;
3157: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
3158: $canshow{'reqcrsotherdom'} = 1;
3159: }
3160: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
3161: $canshow{'inststatus'} = 1;
3162: }
3163: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3164: $canshow{'requestauthor'} = 1;
3165: }
3166: my (%changeHash,%changed);
3167: if ($oldinststatus eq '') {
3168: $oldsettings{'inststatus'} = $othertitle;
3169: } else {
3170: if (ref($usertypes) eq 'HASH') {
3171: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
3172: } else {
3173: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
3174: }
3175: }
3176: $changeHash{'inststatus'} = $userenv{'inststatus'};
3177: if ($canmodify_status{'inststatus'}) {
3178: $canshow{'inststatus'} = 1;
3179: if (exists($env{'form.inststatus'})) {
3180: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3181: if (@inststatuses > 0) {
3182: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3183: $changeHash{'inststatus'} = $newinststatus;
3184: if ($newinststatus ne $oldinststatus) {
3185: $changed{'inststatus'} = $newinststatus;
3186: foreach my $name ('portfolio','author') {
3187: ($newdefquota{$name},$newsettingstatus{$name}) =
3188: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3189: }
3190: }
3191: if (ref($usertypes) eq 'HASH') {
3192: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
3193: } else {
3194: $newsettings{'inststatus'} = join(', ',@inststatuses);
3195: }
3196: }
3197: } else {
3198: $newinststatus = '';
3199: $changeHash{'inststatus'} = $newinststatus;
3200: $newsettings{'inststatus'} = $othertitle;
3201: if ($newinststatus ne $oldinststatus) {
3202: $changed{'inststatus'} = $changeHash{'inststatus'};
3203: foreach my $name ('portfolio','author') {
3204: ($newdefquota{$name},$newsettingstatus{$name}) =
3205: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3206: }
3207: }
3208: }
3209: } elsif ($context ne 'selfcreate') {
3210: $canshow{'inststatus'} = 1;
3211: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
3212: }
3213: foreach my $name ('portfolio','author') {
3214: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3215: }
3216: if ($context eq 'domain') {
3217: foreach my $name ('portfolio','author') {
3218: if ($userenv{$name.'quota'} ne '') {
3219: $oldquota{$name} = $userenv{$name.'quota'};
3220: if ($env{'form.custom_'.$name.'quota'} == 1) {
3221: if ($env{'form.'.$name.'quota'} eq '') {
3222: $newquota{$name} = 0;
3223: } else {
3224: $newquota{$name} = $env{'form.'.$name.'quota'};
3225: $newquota{$name} =~ s/[^\d\.]//g;
3226: }
3227: if ($newquota{$name} != $oldquota{$name}) {
3228: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3229: $changed{$name.'quota'} = 1;
3230: }
3231: }
3232: } else {
3233: if ("a_admin('',\%changeHash,$name)) {
3234: $changed{$name.'quota'} = 1;
3235: $newquota{$name} = $newdefquota{$name};
3236: $newisdefault{$name} = 1;
3237: }
3238: }
3239: } else {
3240: $oldisdefault{$name} = 1;
3241: $oldquota{$name} = $olddefquota{$name};
3242: if ($env{'form.custom_'.$name.'quota'} == 1) {
3243: if ($env{'form.'.$name.'quota'} eq '') {
3244: $newquota{$name} = 0;
3245: } else {
3246: $newquota{$name} = $env{'form.'.$name.'quota'};
3247: $newquota{$name} =~ s/[^\d\.]//g;
3248: }
3249: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3250: $changed{$name.'quota'} = 1;
3251: }
3252: } else {
3253: $newquota{$name} = $newdefquota{$name};
3254: $newisdefault{$name} = 1;
3255: }
3256: }
3257: if ($oldisdefault{$name}) {
3258: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
3259: } else {
3260: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
3261: }
3262: if ($newisdefault{$name}) {
3263: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
3264: } else {
3265: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
3266: }
3267: }
3268: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3269: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3270: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3271: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3272: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3273: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3274: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3275: } else {
3276: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3277: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3278: }
3279: }
3280: foreach my $item (@userinfo) {
3281: if ($env{'form.c'.$item} ne $userenv{$item}) {
3282: $namechanged{$item} = 1;
3283: }
3284: }
3285: foreach my $name ('portfolio','author') {
3286: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3287: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
3288: }
3289: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
3290: my ($chgresult,$namechgresult);
3291: if (keys(%changed) > 0) {
3292: $chgresult =
3293: &Apache::lonnet::put('environment',\%changeHash,
3294: $env{'form.ccdomain'},$env{'form.ccuname'});
3295: if ($chgresult eq 'ok') {
3296: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3297: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
3298: my %newenvhash;
3299: foreach my $key (keys(%changed)) {
3300: if (($key eq 'official') || ($key eq 'unofficial') ||
3301: ($key eq 'community') || ($key eq 'textbook') ||
3302: ($key eq 'placement')) {
3303: $newenvhash{'environment.requestcourses.'.$key} =
3304: $changeHash{'requestcourses.'.$key};
3305: if ($changeHash{'requestcourses.'.$key}) {
3306: $newenvhash{'environment.canrequest.'.$key} = 1;
3307: } else {
3308: $newenvhash{'environment.canrequest.'.$key} =
3309: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3310: $key,'reload','requestcourses');
3311: }
3312: } elsif ($key eq 'requestauthor') {
3313: $newenvhash{'environment.'.$key} = $changeHash{$key};
3314: if ($changeHash{$key}) {
3315: $newenvhash{'environment.canrequest.author'} = 1;
3316: } else {
3317: $newenvhash{'environment.canrequest.author'} =
3318: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3319: $key,'reload','requestauthor');
3320: }
3321: } elsif ($key ne 'quota') {
3322: $newenvhash{'environment.tools.'.$key} =
3323: $changeHash{'tools.'.$key};
3324: if ($changeHash{'tools.'.$key} ne '') {
3325: $newenvhash{'environment.availabletools.'.$key} =
3326: $changeHash{'tools.'.$key};
3327: } else {
3328: $newenvhash{'environment.availabletools.'.$key} =
3329: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3330: $key,'reload','tools');
3331: }
3332: }
3333: }
3334: if (keys(%newenvhash)) {
3335: &Apache::lonnet::appenv(\%newenvhash);
3336: }
3337: }
3338: }
3339: }
3340: if (keys(%namechanged) > 0) {
3341: foreach my $field (@userinfo) {
3342: $changeHash{$field} = $env{'form.c'.$field};
3343: }
3344: # Make the change
3345: $namechgresult =
3346: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3347: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3348: $changeHash{'firstname'},$changeHash{'middlename'},
3349: $changeHash{'lastname'},$changeHash{'generation'},
3350: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
3351: %userupdate = (
3352: lastname => $env{'form.clastname'},
3353: middlename => $env{'form.cmiddlename'},
3354: firstname => $env{'form.cfirstname'},
3355: generation => $env{'form.cgeneration'},
3356: id => $env{'form.cid'},
3357: );
3358: }
3359: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
3360: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
3361: # Tell the user we changed the name
3362: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
3363: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
3364: \%oldsettings, \%oldsettingstext,\%newsettings,
3365: \%newsettingstext);
3366: if ($env{'form.cid'} ne $userenv{'id'}) {
3367: &Apache::lonnet::idput($env{'form.ccdomain'},
3368: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
3369: if (($recurseid) &&
3370: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3371: my $idresult =
3372: &Apache::lonuserutils::propagate_id_change(
3373: $env{'form.ccuname'},$env{'form.ccdomain'},
3374: \%userupdate);
3375: $r->print('<br />'.$idresult.'<br />');
3376: }
3377: }
3378: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3379: ($env{'form.ccuname'} eq $env{'user.name'})) {
3380: my %newenvhash;
3381: foreach my $key (keys(%changeHash)) {
3382: $newenvhash{'environment.'.$key} = $changeHash{$key};
3383: }
3384: &Apache::lonnet::appenv(\%newenvhash);
3385: }
3386: } else { # error occurred
3387: $r->print(
3388: '<p class="LC_error">'
3389: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3390: '"'.$env{'form.ccuname'}.'"',
3391: '"'.$env{'form.ccdomain'}.'"')
3392: .'</p>');
3393: }
3394: } else { # End of if ($env ... ) logic
3395: # They did not want to change the users name, quota, tool availability,
3396: # or ability to request creation of courses,
3397: # but we can still tell them what the name and quota and availabilities are
3398: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
3399: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
3400: \%oldsettingstext,\%newsettings,\%newsettingstext);
3401: }
3402: if (@mod_disallowed) {
3403: my ($rolestr,$contextname);
3404: if (@longroles > 0) {
3405: $rolestr = join(', ',@longroles);
3406: } else {
3407: $rolestr = &mt('No roles');
3408: }
3409: if ($context eq 'course') {
3410: $contextname = 'course';
3411: } elsif ($context eq 'author') {
3412: $contextname = 'co-author';
3413: }
3414: $r->print(&mt('The following fields were not updated: ').'<ul>');
3415: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3416: foreach my $field (@mod_disallowed) {
3417: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3418: }
3419: $r->print('</ul>');
3420: if (@mod_disallowed == 1) {
3421: $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future $contextname roles:"));
3422: } else {
3423: $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future $contextname roles:"));
3424: }
3425: my $helplink = 'javascript:helpMenu('."'display'".')';
3426: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3427: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3428: ,'<a href="'.$helplink.'">','</a>')
3429: .'<br />');
3430: }
3431: $r->print('<span class="LC_warning">'
3432: .$no_forceid_alert
3433: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3434: .'</span>');
3435: }
3436: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
3437: if ($env{'form.action'} eq 'singlestudent') {
3438: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3439: $crstype,$showcredits,$defaultcredits);
3440: my $linktext = ($crstype eq 'Community' ?
3441: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3442: $r->print(
3443: &Apache::lonhtmlcommon::actionbox([
3444: '<a href="javascript:backPage(document.userupdate)">'
3445: .($crstype eq 'Community' ?
3446: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3447: .'</a>']));
3448: } else {
3449: my @rolechanges = &update_roles($r,$context,$showcredits);
3450: if (keys(%namechanged) > 0) {
3451: if ($context eq 'course') {
3452: if (@userroles > 0) {
3453: if ((@rolechanges == 0) ||
3454: (!(grep(/^st$/,@rolechanges)))) {
3455: if (grep(/^st$/,@userroles)) {
3456: my $classlistupdated =
3457: &Apache::lonuserutils::update_classlist($cdom,
3458: $cnum,$env{'form.ccdomain'},
3459: $env{'form.ccuname'},\%userupdate);
3460: }
3461: }
3462: }
3463: }
3464: }
3465: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
3466: $env{'form.ccdomain'});
3467: if ($env{'form.popup'}) {
3468: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3469: } else {
3470: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3471: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3472: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
3473: }
3474: }
3475: }
3476:
3477: sub display_userinfo {
3478: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3479: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
3480: $newsetting,$newsettingtext) = @_;
3481: return unless (ref($order) eq 'ARRAY' &&
3482: ref($canshow) eq 'HASH' &&
3483: ref($requestcourses) eq 'ARRAY' &&
3484: ref($requestauthor) eq 'ARRAY' &&
3485: ref($usertools) eq 'ARRAY' &&
3486: ref($userenv) eq 'HASH' &&
3487: ref($changedhash) eq 'HASH' &&
3488: ref($oldsetting) eq 'HASH' &&
3489: ref($oldsettingtext) eq 'HASH' &&
3490: ref($newsetting) eq 'HASH' &&
3491: ref($newsettingtext) eq 'HASH');
3492: my %lt=&Apache::lonlocal::texthash(
3493: 'ui' => 'User Information',
3494: 'uic' => 'User Information Changed',
3495: 'firstname' => 'First Name',
3496: 'middlename' => 'Middle Name',
3497: 'lastname' => 'Last Name',
3498: 'generation' => 'Generation',
3499: 'id' => 'Student/Employee ID',
3500: 'permanentemail' => 'Permanent e-mail address',
3501: 'portfolioquota' => 'Disk space allocated to portfolio files',
3502: 'authorquota' => 'Disk space allocated to Authoring Space',
3503: 'blog' => 'Blog Availability',
3504: 'webdav' => 'WebDAV Availability',
3505: 'aboutme' => 'Personal Information Page Availability',
3506: 'portfolio' => 'Portfolio Availability',
3507: 'official' => 'Can Request Official Courses',
3508: 'unofficial' => 'Can Request Unofficial Courses',
3509: 'community' => 'Can Request Communities',
3510: 'textbook' => 'Can Request Textbook Courses',
3511: 'placement' => 'Can Request Placement Tests',
3512: 'requestauthor' => 'Can Request Author Role',
3513: 'inststatus' => "Affiliation",
3514: 'prvs' => 'Previous Value:',
3515: 'chto' => 'Changed To:'
3516: );
3517: if ($changed) {
3518: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
3519: &Apache::loncommon::start_data_table().
3520: &Apache::loncommon::start_data_table_header_row());
3521: $r->print("<th> </th>\n");
3522: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3523: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3524: $r->print(&Apache::loncommon::end_data_table_header_row());
3525: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3526:
3527: foreach my $item (@userinfo) {
3528: my $value = $env{'form.c'.$item};
3529: #show changes only:
3530: unless ($value eq $userenv->{$item}){
3531: $r->print(&Apache::loncommon::start_data_table_row());
3532: $r->print("<td>$lt{$item}</td>\n");
3533: $r->print("<td>".$userenv->{$item}."</td>\n");
3534: $r->print("<td>$value </td>\n");
3535: $r->print(&Apache::loncommon::end_data_table_row());
3536: }
3537: }
3538: foreach my $entry (@{$order}) {
3539: if ($canshow->{$entry}) {
3540: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3541: my @items;
3542: if ($entry eq 'requestauthor') {
3543: @items = ($entry);
3544: } else {
3545: @items = @{$requestcourses};
3546: }
3547: foreach my $item (@items) {
3548: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3549: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3550: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3551: $r->print("<td>$lt{$item}</td>\n");
3552: $r->print("<td>".$oldsetting->{$item});
3553: if ($oldsettingtext->{$item}) {
3554: if ($oldsetting->{$item}) {
3555: $r->print(' -- ');
3556: }
3557: $r->print($oldsettingtext->{$item});
3558: }
3559: $r->print("</td>\n");
3560: $r->print("<td>".$newsetting->{$item});
3561: if ($newsettingtext->{$item}) {
3562: if ($newsetting->{$item}) {
3563: $r->print(' -- ');
3564: }
3565: $r->print($newsettingtext->{$item});
3566: }
3567: $r->print("</td>\n");
3568: $r->print(&Apache::loncommon::end_data_table_row()."\n");
3569: }
3570: }
3571: } elsif ($entry eq 'tools') {
3572: foreach my $item (@{$usertools}) {
3573: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3574: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3575: $r->print("<td>$lt{$item}</td>\n");
3576: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3577: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3578: $r->print(&Apache::loncommon::end_data_table_row()."\n");
3579: }
3580: }
3581: } elsif ($entry eq 'quota') {
3582: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3583: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3584: foreach my $name ('portfolio','author') {
3585: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3586: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3587: $r->print("<td>$lt{$name.$entry}</td>\n");
3588: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3589: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3590: $r->print(&Apache::loncommon::end_data_table_row()."\n");
3591: }
3592: }
3593: }
3594: } else {
3595: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3596: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3597: $r->print("<td>$lt{$entry}</td>\n");
3598: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3599: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3600: $r->print(&Apache::loncommon::end_data_table_row()."\n");
3601: }
3602: }
3603: }
3604: }
3605: $r->print(&Apache::loncommon::end_data_table().'<br />');
3606: } else {
3607: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3608: '<p>'.&mt('No changes made to user information').'</p>');
3609: }
3610: return;
3611: }
3612:
3613: sub tool_changes {
3614: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3615: $changed,$newaccess,$newaccesstext) = @_;
3616: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3617: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3618: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3619: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3620: return;
3621: }
3622: my %reqdisplay = &requestchange_display();
3623: if ($context eq 'reqcrsotherdom') {
3624: my @options = ('approval','validate','autolimit');
3625: my $optregex = join('|',@options);
3626: my $cdom = $env{'request.role.domain'};
3627: foreach my $tool (@{$usertools}) {
3628: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3629: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3630: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
3631: my ($newop,$limit);
3632: if ($env{'form.'.$context.'_'.$tool}) {
3633: $newop = $env{'form.'.$context.'_'.$tool};
3634: if ($newop eq 'autolimit') {
3635: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3636: $limit =~ s/\D+//g;
3637: $newop .= '='.$limit;
3638: }
3639: }
3640: if ($userenv->{$context.'.'.$tool} eq '') {
3641: if ($newop) {
3642: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
3643: $changeHash,$context);
3644: if ($changed->{$tool}) {
3645: if ($newop =~ /^autolimit/) {
3646: if ($limit) {
3647: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3648: } else {
3649: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3650: }
3651: } else {
3652: $newaccesstext->{$tool} = $reqdisplay{$newop};
3653: }
3654: } else {
3655: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3656: }
3657: }
3658: } else {
3659: my @curr = split(',',$userenv->{$context.'.'.$tool});
3660: my @new;
3661: my $changedoms;
3662: foreach my $req (@curr) {
3663: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3664: my $oldop = $1;
3665: if ($oldop =~ /^autolimit=(\d*)/) {
3666: my $limit = $1;
3667: if ($limit) {
3668: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3669: } else {
3670: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3671: }
3672: } else {
3673: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3674: }
3675: if ($oldop ne $newop) {
3676: $changedoms = 1;
3677: foreach my $item (@curr) {
3678: my ($reqdom,$option) = split(':',$item);
3679: unless ($reqdom eq $cdom) {
3680: push(@new,$item);
3681: }
3682: }
3683: if ($newop) {
3684: push(@new,$cdom.':'.$newop);
3685: }
3686: @new = sort(@new);
3687: }
3688: last;
3689: }
3690: }
3691: if ((!$changedoms) && ($newop)) {
3692: $changedoms = 1;
3693: @new = sort(@curr,$cdom.':'.$newop);
3694: }
3695: if ($changedoms) {
3696: my $newdomstr;
3697: if (@new) {
3698: $newdomstr = join(',',@new);
3699: }
3700: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3701: $context);
3702: if ($changed->{$tool}) {
3703: if ($env{'form.'.$context.'_'.$tool}) {
3704: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
3705: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3706: $limit =~ s/\D+//g;
3707: if ($limit) {
3708: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3709: } else {
3710: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3711: }
3712: } else {
3713: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3714: }
3715: } else {
3716: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3717: }
3718: }
3719: }
3720: }
3721: }
3722: return;
3723: }
3724: foreach my $tool (@{$usertools}) {
3725: my ($newval,$limit,$envkey);
3726: $envkey = $context.'.'.$tool;
3727: if ($context eq 'requestcourses') {
3728: $newval = $env{'form.crsreq_'.$tool};
3729: if ($newval eq 'autolimit') {
3730: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3731: $limit =~ s/\D+//g;
3732: $newval .= '='.$limit;
3733: }
3734: } elsif ($context eq 'requestauthor') {
3735: $newval = $env{'form.'.$context};
3736: $envkey = $context;
3737: } else {
3738: $newval = $env{'form.'.$context.'_'.$tool};
3739: }
3740: if ($userenv->{$envkey} ne '') {
3741: $oldaccess->{$tool} = &mt('custom');
3742: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3743: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3744: my $currlimit = $1;
3745: if ($currlimit eq '') {
3746: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3747: } else {
3748: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3749: }
3750: } elsif ($userenv->{$envkey}) {
3751: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3752: } else {
3753: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3754: }
3755: } else {
3756: if ($userenv->{$envkey}) {
3757: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3758: } else {
3759: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3760: }
3761: }
3762: $changeHash->{$envkey} = $userenv->{$envkey};
3763: if ($env{'form.custom'.$tool} == 1) {
3764: if ($newval ne $userenv->{$envkey}) {
3765: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3766: $context);
3767: if ($changed->{$tool}) {
3768: $newaccess->{$tool} = &mt('custom');
3769: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3770: if ($newval =~ /^autolimit/) {
3771: if ($limit) {
3772: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3773: } else {
3774: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3775: }
3776: } elsif ($newval) {
3777: $newaccesstext->{$tool} = $reqdisplay{$newval};
3778: } else {
3779: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3780: }
3781: } else {
3782: if ($newval) {
3783: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3784: } else {
3785: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3786: }
3787: }
3788: } else {
3789: $newaccess->{$tool} = $oldaccess->{$tool};
3790: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3791: if ($newval =~ /^autolimit/) {
3792: if ($limit) {
3793: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3794: } else {
3795: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3796: }
3797: } elsif ($newval) {
3798: $newaccesstext->{$tool} = $reqdisplay{$newval};
3799: } else {
3800: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3801: }
3802: } else {
3803: if ($userenv->{$context.'.'.$tool}) {
3804: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3805: } else {
3806: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3807: }
3808: }
3809: }
3810: } else {
3811: $newaccess->{$tool} = $oldaccess->{$tool};
3812: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3813: }
3814: } else {
3815: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3816: if ($changed->{$tool}) {
3817: $newaccess->{$tool} = &mt('default');
3818: } else {
3819: $newaccess->{$tool} = $oldaccess->{$tool};
3820: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3821: if ($newval =~ /^autolimit/) {
3822: if ($limit) {
3823: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3824: } else {
3825: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3826: }
3827: } elsif ($newval) {
3828: $newaccesstext->{$tool} = $reqdisplay{$newval};
3829: } else {
3830: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3831: }
3832: } else {
3833: if ($userenv->{$context.'.'.$tool}) {
3834: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3835: } else {
3836: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3837: }
3838: }
3839: }
3840: }
3841: } else {
3842: $oldaccess->{$tool} = &mt('default');
3843: if ($env{'form.custom'.$tool} == 1) {
3844: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3845: $context);
3846: if ($changed->{$tool}) {
3847: $newaccess->{$tool} = &mt('custom');
3848: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3849: if ($newval =~ /^autolimit/) {
3850: if ($limit) {
3851: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3852: } else {
3853: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3854: }
3855: } elsif ($newval) {
3856: $newaccesstext->{$tool} = $reqdisplay{$newval};
3857: } else {
3858: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3859: }
3860: } else {
3861: if ($newval) {
3862: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3863: } else {
3864: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3865: }
3866: }
3867: } else {
3868: $newaccess->{$tool} = $oldaccess->{$tool};
3869: }
3870: } else {
3871: $newaccess->{$tool} = $oldaccess->{$tool};
3872: }
3873: }
3874: }
3875: return;
3876: }
3877:
3878: sub update_roles {
3879: my ($r,$context,$showcredits) = @_;
3880: my $now=time;
3881: my @rolechanges;
3882: my %disallowed;
3883: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
3884: foreach my $key (keys(%env)) {
3885: next if (! $env{$key});
3886: next if ($key eq 'form.action');
3887: # Revoke roles
3888: if ($key=~/^form\.rev/) {
3889: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
3890: # Revoke standard role
3891: my ($scope,$role) = ($1,$2);
3892: my $result =
3893: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3894: $env{'form.ccuname'},
3895: $scope,$role,'','',$context);
3896: $r->print(&Apache::lonhtmlcommon::confirm_success(
3897: &mt('Revoking [_1] in [_2]',
3898: &Apache::lonnet::plaintext($role),
3899: &Apache::loncommon::show_role_extent($scope,$context,$role)),
3900: $result ne "ok").'<br />');
3901: if ($result ne "ok") {
3902: $r->print(&mt('Error: [_1]',$result).'<br />');
3903: }
3904: if ($role eq 'st') {
3905: my $result =
3906: &Apache::lonuserutils::classlist_drop($scope,
3907: $env{'form.ccuname'},$env{'form.ccdomain'},
3908: $now);
3909: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
3910: }
3911: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3912: push(@rolechanges,$role);
3913: }
3914: }
3915: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
3916: # Revoke custom role
3917: my $result = &Apache::lonnet::revokecustomrole(
3918: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
3919: $r->print(&Apache::lonhtmlcommon::confirm_success(
3920: &mt('Revoking custom role [_1] by [_2] in [_3]',
3921: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
3922: $result ne 'ok').'<br />');
3923: if ($result ne "ok") {
3924: $r->print(&mt('Error: [_1]',$result).'<br />');
3925: }
3926: if (!grep(/^cr$/,@rolechanges)) {
3927: push(@rolechanges,'cr');
3928: }
3929: }
3930: } elsif ($key=~/^form\.del/) {
3931: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
3932: # Delete standard role
3933: my ($scope,$role) = ($1,$2);
3934: my $result =
3935: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3936: $env{'form.ccuname'},
3937: $scope,$role,$now,0,1,'',
3938: $context);
3939: $r->print(&Apache::lonhtmlcommon::confirm_success(
3940: &mt('Deleting [_1] in [_2]',
3941: &Apache::lonnet::plaintext($role),
3942: &Apache::loncommon::show_role_extent($scope,$context,$role)),
3943: $result ne 'ok').'<br />');
3944: if ($result ne "ok") {
3945: $r->print(&mt('Error: [_1]',$result).'<br />');
3946: }
3947:
3948: if ($role eq 'st') {
3949: my $result =
3950: &Apache::lonuserutils::classlist_drop($scope,
3951: $env{'form.ccuname'},$env{'form.ccdomain'},
3952: $now);
3953: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
3954: }
3955: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3956: push(@rolechanges,$role);
3957: }
3958: }
3959: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
3960: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3961: # Delete custom role
3962: my $result =
3963: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3964: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3965: 0,1,$context);
3966: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
3967: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
3968: $result ne "ok").'<br />');
3969: if ($result ne "ok") {
3970: $r->print(&mt('Error: [_1]',$result).'<br />');
3971: }
3972:
3973: if (!grep(/^cr$/,@rolechanges)) {
3974: push(@rolechanges,'cr');
3975: }
3976: }
3977: } elsif ($key=~/^form\.ren/) {
3978: my $udom = $env{'form.ccdomain'};
3979: my $uname = $env{'form.ccuname'};
3980: # Re-enable standard role
3981: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
3982: my $url = $1;
3983: my $role = $2;
3984: my $logmsg;
3985: my $output;
3986: if ($role eq 'st') {
3987: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
3988: my ($cdom,$cnum,$csec) = ($1,$2,$3);
3989: my $credits;
3990: if ($showcredits) {
3991: my $defaultcredits =
3992: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3993: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3994: }
3995: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
3996: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
3997: if ($result eq 'refused' && $logmsg) {
3998: $output = $logmsg;
3999: } else {
4000: $output = &mt('Error: [_1]',$result)."\n";
4001: }
4002: } else {
4003: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4004: &Apache::lonnet::plaintext($role),
4005: &Apache::loncommon::show_role_extent($url,$context,'st'),
4006: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
4007: }
4008: }
4009: } else {
4010: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
4011: $env{'form.ccuname'},$url,$role,0,$now,'','',
4012: $context);
4013: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
4014: &Apache::lonnet::plaintext($role),
4015: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
4016: if ($result ne "ok") {
4017: $output .= &mt('Error: [_1]',$result).'<br />';
4018: }
4019: }
4020: $r->print($output);
4021: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4022: push(@rolechanges,$role);
4023: }
4024: }
4025: # Re-enable custom role
4026: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
4027: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4028: my $result = &Apache::lonnet::assigncustomrole(
4029: $env{'form.ccdomain'}, $env{'form.ccuname'},
4030: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
4031: $r->print(&Apache::lonhtmlcommon::confirm_success(
4032: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
4033: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
4034: $result ne "ok").'<br />');
4035: if ($result ne "ok") {
4036: $r->print(&mt('Error: [_1]',$result).'<br />');
4037: }
4038: if (!grep(/^cr$/,@rolechanges)) {
4039: push(@rolechanges,'cr');
4040: }
4041: }
4042: } elsif ($key=~/^form\.act/) {
4043: my $udom = $env{'form.ccdomain'};
4044: my $uname = $env{'form.ccuname'};
4045: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
4046: # Activate a custom role
4047: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4048: my $url='/'.$one.'/'.$two;
4049: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
4050:
4051: my $start = ( $env{'form.start_'.$full} ?
4052: $env{'form.start_'.$full} :
4053: $now );
4054: my $end = ( $env{'form.end_'.$full} ?
4055: $env{'form.end_'.$full} :
4056: 0 );
4057:
4058: # split multiple sections
4059: my %sections = ();
4060: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
4061: if ($num_sections == 0) {
4062: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
4063: } else {
4064: my %curr_groups =
4065: &Apache::longroup::coursegroups($one,$two);
4066: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
4067: if (($sec eq 'none') || ($sec eq 'all') ||
4068: exists($curr_groups{$sec})) {
4069: $disallowed{$sec} = $url;
4070: next;
4071: }
4072: my $securl = $url.'/'.$sec;
4073: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
4074: }
4075: }
4076: if (!grep(/^cr$/,@rolechanges)) {
4077: push(@rolechanges,'cr');
4078: }
4079: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
4080: # Activate roles for sections with 3 id numbers
4081: # set start, end times, and the url for the class
4082: my ($one,$two,$three)=($1,$2,$3);
4083: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4084: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
4085: $now );
4086: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4087: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
4088: 0 );
4089: my $url='/'.$one.'/'.$two;
4090: my $type = 'three';
4091: # split multiple sections
4092: my %sections = ();
4093: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
4094: my $credits;
4095: if ($three eq 'st') {
4096: if ($showcredits) {
4097: my $defaultcredits =
4098: &Apache::lonuserutils::get_defaultcredits($one,$two);
4099: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4100: $credits =~ s/[^\d\.]//g;
4101: if ($credits eq $defaultcredits) {
4102: undef($credits);
4103: }
4104: }
4105: }
4106: if ($num_sections == 0) {
4107: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
4108: } else {
4109: my %curr_groups =
4110: &Apache::longroup::coursegroups($one,$two);
4111: my $emptysec = 0;
4112: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
4113: $sec =~ s/\W//g;
4114: if ($sec ne '') {
4115: if (($sec eq 'none') || ($sec eq 'all') ||
4116: exists($curr_groups{$sec})) {
4117: $disallowed{$sec} = $url;
4118: next;
4119: }
4120: my $securl = $url.'/'.$sec;
4121: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
4122: } else {
4123: $emptysec = 1;
4124: }
4125: }
4126: if ($emptysec) {
4127: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
4128: }
4129: }
4130: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4131: push(@rolechanges,$three);
4132: }
4133: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
4134: # Activate roles for sections with two id numbers
4135: # set start, end times, and the url for the class
4136: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4137: $env{'form.start_'.$1.'_'.$2} :
4138: $now );
4139: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4140: $env{'form.end_'.$1.'_'.$2} :
4141: 0 );
4142: my $one = $1;
4143: my $two = $2;
4144: my $url='/'.$one.'/';
4145: # split multiple sections
4146: my %sections = ();
4147: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
4148: if ($num_sections == 0) {
4149: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
4150: } else {
4151: my $emptysec = 0;
4152: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
4153: if ($sec ne '') {
4154: my $securl = $url.'/'.$sec;
4155: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
4156: } else {
4157: $emptysec = 1;
4158: }
4159: }
4160: if ($emptysec) {
4161: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
4162: }
4163: }
4164: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4165: push(@rolechanges,$two);
4166: }
4167: } else {
4168: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
4169: }
4170: foreach my $key (sort(keys(%disallowed))) {
4171: $r->print('<p class="LC_warning">');
4172: if (($key eq 'none') || ($key eq 'all')) {
4173: $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.','<tt>'.$key.'</tt>'));
4174: } else {
4175: $r->print(&mt('[_1] may not be used as the name for a section, as it is the name of a course group.','<tt>'.$key.'</tt>'));
4176: }
4177: $r->print('</p><p>'
4178: .&mt('Please [_1]go back[_2] and choose a different section name.'
4179: ,'<a href="javascript:history.go(-1)'
4180: ,'</a>')
4181: .'</p><br />'
4182: );
4183: }
4184: }
4185: } # End of foreach (keys(%env))
4186: # Flush the course logs so reverse user roles immediately updated
4187: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
4188: if (@rolechanges == 0) {
4189: $r->print('<p>'.&mt('No roles to modify').'</p>');
4190: }
4191: return @rolechanges;
4192: }
4193:
4194: sub get_user_credits {
4195: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4196: if ($cdom eq '' || $cnum eq '') {
4197: return unless ($env{'request.course.id'});
4198: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4199: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4200: }
4201: my $credits;
4202: my %currhash =
4203: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4204: if (keys(%currhash) > 0) {
4205: my @items = split(/:/,$currhash{$uname.':'.$udom});
4206: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4207: $credits = $items[$crdidx];
4208: $credits =~ s/[^\d\.]//g;
4209: }
4210: if ($credits eq $defaultcredits) {
4211: undef($credits);
4212: }
4213: return $credits;
4214: }
4215:
4216: sub enroll_single_student {
4217: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4218: $showcredits,$defaultcredits) = @_;
4219: $r->print('<h3>');
4220: if ($crstype eq 'Community') {
4221: $r->print(&mt('Enrolling Member'));
4222: } else {
4223: $r->print(&mt('Enrolling Student'));
4224: }
4225: $r->print('</h3>');
4226:
4227: # Remove non alphanumeric values from section
4228: $env{'form.sections'}=~s/\W//g;
4229:
4230: my $credits;
4231: if (($showcredits) && ($env{'form.credits'} ne '')) {
4232: $credits = $env{'form.credits'};
4233: $credits =~ s/[^\d\.]//g;
4234: if ($credits ne '') {
4235: if ($credits eq $defaultcredits) {
4236: undef($credits);
4237: }
4238: }
4239: }
4240:
4241: # Clean out any old student roles the user has in this class.
4242: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4243: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4244: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4245: my $enroll_result =
4246: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4247: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4248: $env{'form.cmiddlename'},$env{'form.clastname'},
4249: $env{'form.generation'},$env{'form.sections'},$enddate,
4250: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4251: $credits);
4252: if ($enroll_result =~ /^ok/) {
4253: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
4254: if ($env{'form.sections'} ne '') {
4255: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4256: }
4257: my ($showstart,$showend);
4258: if ($startdate <= $now) {
4259: $showstart = &mt('Access starts immediately');
4260: } else {
4261: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4262: }
4263: if ($enddate == 0) {
4264: $showend = &mt('ends: no ending date');
4265: } else {
4266: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4267: }
4268: $r->print('.<br />'.$showstart.'; '.$showend);
4269: if ($startdate <= $now && !$newuser) {
4270: $r->print('<p class="LC_info">');
4271: if ($crstype eq 'Community') {
4272: $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
4273: } else {
4274: $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
4275: }
4276: $r->print('</p>');
4277: }
4278: } else {
4279: $r->print(&mt('unable to enroll').": ".$enroll_result);
4280: }
4281: return;
4282: }
4283:
4284: sub get_defaultquota_text {
4285: my ($settingstatus) = @_;
4286: my $defquotatext;
4287: if ($settingstatus eq '') {
4288: $defquotatext = &mt('default');
4289: } else {
4290: my ($usertypes,$order) =
4291: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4292: if ($usertypes->{$settingstatus} eq '') {
4293: $defquotatext = &mt('default');
4294: } else {
4295: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
4296: }
4297: }
4298: return $defquotatext;
4299: }
4300:
4301: sub update_result_form {
4302: my ($uhome) = @_;
4303: my $outcome =
4304: '<form name="userupdate" method="post" action="">'."\n";
4305: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
4306: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
4307: }
4308: if ($env{'form.origname'} ne '') {
4309: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4310: }
4311: foreach my $item ('sortby','seluname','seludom') {
4312: if (exists($env{'form.'.$item})) {
4313: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
4314: }
4315: }
4316: if ($uhome eq 'no_host') {
4317: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4318: }
4319: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
4320: '<input type="hidden" name="currstate" value="" />'."\n".
4321: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
4322: '</form>';
4323: return $outcome;
4324: }
4325:
4326: sub quota_admin {
4327: my ($setquota,$changeHash,$name) = @_;
4328: my $quotachanged;
4329: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4330: # Current user has quota modification privileges
4331: if (ref($changeHash) eq 'HASH') {
4332: $quotachanged = 1;
4333: $changeHash->{$name.'quota'} = $setquota;
4334: }
4335: }
4336: return $quotachanged;
4337: }
4338:
4339: sub tool_admin {
4340: my ($tool,$settool,$changeHash,$context) = @_;
4341: my $canchange = 0;
4342: if ($context eq 'requestcourses') {
4343: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4344: $canchange = 1;
4345: }
4346: } elsif ($context eq 'reqcrsotherdom') {
4347: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4348: $canchange = 1;
4349: }
4350: } elsif ($context eq 'requestauthor') {
4351: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4352: $canchange = 1;
4353: }
4354: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4355: # Current user has quota modification privileges
4356: $canchange = 1;
4357: }
4358: my $toolchanged;
4359: if ($canchange) {
4360: if (ref($changeHash) eq 'HASH') {
4361: $toolchanged = 1;
4362: if ($tool eq 'requestauthor') {
4363: $changeHash->{$context} = $settool;
4364: } else {
4365: $changeHash->{$context.'.'.$tool} = $settool;
4366: }
4367: }
4368: }
4369: return $toolchanged;
4370: }
4371:
4372: sub build_roles {
4373: my ($sectionstr,$sections,$role) = @_;
4374: my $num_sections = 0;
4375: if ($sectionstr=~ /,/) {
4376: my @secnums = split/,/,$sectionstr;
4377: if ($role eq 'st') {
4378: $secnums[0] =~ s/\W//g;
4379: $$sections{$secnums[0]} = 1;
4380: $num_sections = 1;
4381: } else {
4382: foreach my $sec (@secnums) {
4383: $sec =~ ~s/\W//g;
4384: if (!($sec eq "")) {
4385: if (exists($$sections{$sec})) {
4386: $$sections{$sec} ++;
4387: } else {
4388: $$sections{$sec} = 1;
4389: $num_sections ++;
4390: }
4391: }
4392: }
4393: }
4394: } else {
4395: $sectionstr=~s/\W//g;
4396: unless ($sectionstr eq '') {
4397: $$sections{$sectionstr} = 1;
4398: $num_sections ++;
4399: }
4400: }
4401:
4402: return $num_sections;
4403: }
4404:
4405: # ========================================================== Custom Role Editor
4406:
4407: sub custom_role_editor {
4408: my ($r,$context,$brcrum,$prefix,$permission) = @_;
4409: my $action = $env{'form.customroleaction'};
4410: my ($rolename,$helpitem);
4411: if ($action eq 'new') {
4412: $rolename=$env{'form.newrolename'};
4413: } else {
4414: $rolename=$env{'form.rolename'};
4415: }
4416:
4417: my ($crstype,$context);
4418: if ($env{'request.course.id'}) {
4419: $crstype = &Apache::loncommon::course_type();
4420: $context = 'course';
4421: $helpitem = 'Course_Editing_Custom_Roles';
4422: } else {
4423: $context = 'domain';
4424: $crstype = 'course';
4425: $helpitem = 'Domain_Editing_Custom_Roles';
4426: }
4427:
4428: $rolename=~s/[^A-Za-z0-9]//gs;
4429: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
4430: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4431: $permission);
4432: return;
4433: }
4434:
4435: my $formname = 'form1';
4436: my %privs=();
4437: my $body_top = '<h2>';
4438: # ------------------------------------------------------- Does this role exist?
4439: my ($rdummy,$roledef)=
4440: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4441: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
4442: $body_top .= &mt('Existing Role').' "';
4443: # ------------------------------------------------- Get current role privileges
4444: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4445: if ($privs{'system'} =~ /bre\&S/) {
4446: if ($context eq 'domain') {
4447: $crstype = 'Course';
4448: } elsif ($crstype eq 'Community') {
4449: $privs{'system'} =~ s/bre\&S//;
4450: }
4451: } elsif ($context eq 'domain') {
4452: $crstype = 'Course';
4453: }
4454: } else {
4455: $body_top .= &mt('New Role').' "';
4456: $roledef='';
4457: }
4458: $body_top .= $rolename.'"</h2>';
4459:
4460: # ------------------------------------------------------- What can be assigned?
4461: my %full=();
4462: my %levels=(
4463: course => {},
4464: domain => {},
4465: system => {},
4466: );
4467: my %levelscurrent=(
4468: course => {},
4469: domain => {},
4470: system => {},
4471: );
4472: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4473: my ($jsback,$elements) = &crumb_utilities();
4474: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4475: my $head_script =
4476: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4477: \%full,\@templateroles,$jsback);
4478: push (@{$brcrum},
4479: {href => "javascript:backPage(document.$formname,'pickrole','')",
4480: text => "Pick custom role",
4481: faq => 282,bug=>'Instructor Interface',},
4482: {href => "javascript:backPage(document.$formname,'','')",
4483: text => "Edit custom role",
4484: faq => 282,
4485: bug => 'Instructor Interface',
4486: help => $helpitem}
4487: );
4488: my $args = { bread_crumbs => $brcrum,
4489: bread_crumbs_component => 'User Management'};
4490: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4491: $head_script,$args).
4492: $body_top);
4493: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4494: &Apache::lonuserutils::custom_role_header($context,$crstype,
4495: \@templateroles,$prefix));
4496:
4497: $r->print(<<ENDCCF);
4498: <input type="hidden" name="phase" value="set_custom_roles" />
4499: <input type="hidden" name="rolename" value="$rolename" />
4500: ENDCCF
4501: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4502: \%levelscurrent,$prefix));
4503: $r->print(&Apache::loncommon::end_data_table().
4504: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
4505: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
4506: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
4507: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
4508: '<input type="submit" value="'.&mt('Save').'" /></form>');
4509: }
4510:
4511: # ---------------------------------------------------------- Call to definerole
4512: sub set_custom_role {
4513: my ($r,$context,$brcrum,$prefix,$permission) = @_;
4514: my $rolename=$env{'form.rolename'};
4515: $rolename=~s/[^A-Za-z0-9]//gs;
4516: if (!$rolename) {
4517: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
4518: return;
4519: }
4520: my ($jsback,$elements) = &crumb_utilities();
4521: my $jscript = '<script type="text/javascript">'
4522: .'// <![CDATA['."\n"
4523: .$jsback."\n"
4524: .'// ]]>'."\n"
4525: .'</script>'."\n";
4526: my $helpitem = 'Course_Editing_Custom_Roles';
4527: if ($context eq 'domain') {
4528: $helpitem = 'Domain_Editing_Custom_Roles';
4529: }
4530: push(@{$brcrum},
4531: {href => "javascript:backPage(document.customresult,'pickrole','')",
4532: text => "Pick custom role",
4533: faq => 282,
4534: bug => 'Instructor Interface',},
4535: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4536: text => "Edit custom role",
4537: faq => 282,
4538: bug => 'Instructor Interface',},
4539: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4540: text => "Result",
4541: faq => 282,
4542: bug => 'Instructor Interface',
4543: help => $helpitem,}
4544: );
4545: my $args = { bread_crumbs => $brcrum,
4546: bread_crumbs_component => 'User Management'};
4547: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
4548:
4549: my $newrole;
4550: my ($rdummy,$roledef)=
4551: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4552:
4553: # ------------------------------------------------------- Does this role exist?
4554: $r->print('<h3>');
4555: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
4556: $r->print(&mt('Existing Role').' "');
4557: } else {
4558: $r->print(&mt('New Role').' "');
4559: $roledef='';
4560: $newrole = 1;
4561: }
4562: $r->print($rolename.'"</h3>');
4563: # ------------------------------------------------- Assign role and show result
4564:
4565: my $errmsg;
4566: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4567: # Assign role and return result
4568: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4569: $newprivs{'c'});
4570: if ($result ne 'ok') {
4571: $errmsg = ': '.$result;
4572: }
4573: my $message =
4574: &Apache::lonhtmlcommon::confirm_success(
4575: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
4576: if ($env{'request.course.id'}) {
4577: my $url='/'.$env{'request.course.id'};
4578: $url=~s/\_/\//g;
4579: $result =
4580: &Apache::lonnet::assigncustomrole(
4581: $env{'user.domain'},$env{'user.name'},
4582: $url,
4583: $env{'user.domain'},$env{'user.name'},
4584: $rolename,undef,undef,undef,$context);
4585: if ($result ne 'ok') {
4586: $errmsg = ': '.$result;
4587: }
4588: $message .=
4589: '<br />'
4590: .&Apache::lonhtmlcommon::confirm_success(
4591: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
4592: }
4593: $r->print(
4594: &Apache::loncommon::confirmwrapper($message)
4595: .'<br />'
4596: .&Apache::lonhtmlcommon::actionbox([
4597: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4598: .&mt('Create or edit another custom role')
4599: .'</a>'])
4600: .'<form name="customresult" method="post" action="">'
4601: .&Apache::lonhtmlcommon::echo_form_input([])
4602: .'</form>'
4603: );
4604: }
4605:
4606: # ================================================================ Main Handler
4607: sub handler {
4608: my $r = shift;
4609: if ($r->header_only) {
4610: &Apache::loncommon::content_type($r,'text/html');
4611: $r->send_http_header;
4612: return OK;
4613: }
4614: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4615:
4616: if ($env{'request.course.id'}) {
4617: $context = 'course';
4618: $crstype = &Apache::loncommon::course_type();
4619: } elsif ($env{'request.role'} =~ /^au\./) {
4620: $context = 'author';
4621: } else {
4622: $context = 'domain';
4623: }
4624:
4625: my ($permission,$allowed) =
4626: &Apache::lonuserutils::get_permission($context,$crstype);
4627:
4628: if ($allowed) {
4629: my @allhelp;
4630: if ($context eq 'course') {
4631: $cid = $env{'request.course.id'};
4632: $cdom = $env{'course.'.$cid.'.domain'};
4633: $cnum = $env{'course.'.$cid.'.num'};
4634:
4635: if ($permission->{'cusr'}) {
4636: push(@allhelp,'Course_Create_Class_List');
4637: }
4638: if ($permission->{'view'} || $permission->{'cusr'}) {
4639: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4640: }
4641: if ($permission->{'custom'}) {
4642: push(@allhelp,'Course_Editing_Custom_Roles');
4643: }
4644: if ($permission->{'cusr'}) {
4645: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4646: }
4647: unless ($permission->{'cusr_section'}) {
4648: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4649: push(@allhelp,'Course_Automated_Enrollment');
4650: }
4651: if ($permission->{'selfenrolladmin'}) {
4652: push(@allhelp,'Course_Approve_Selfenroll');
4653: }
4654: }
4655: if ($permission->{'grp_manage'}) {
4656: push(@allhelp,'Course_Manage_Group');
4657: }
4658: if ($permission->{'view'} || $permission->{'cusr'}) {
4659: push(@allhelp,'Course_User_Logs');
4660: }
4661: } elsif ($context eq 'author') {
4662: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4663: 'Author_View_Coauthor_List','Author_User_Logs'));
4664: } else {
4665: if ($permission->{'cusr'}) {
4666: push(@allhelp,'Domain_Change_Privileges');
4667: if ($permission->{'activity'}) {
4668: push(@allhelp,'Domain_User_Access_Logs');
4669: }
4670: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4671: if ($permission->{'custom'}) {
4672: push(@allhelp,'Domain_Editing_Custom_Roles');
4673: }
4674: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4675: } elsif ($permission->{'view'}) {
4676: push(@allhelp,'Domain_View_Privileges');
4677: if ($permission->{'activity'}) {
4678: push(@allhelp,'Domain_User_Access_Logs');
4679: }
4680: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4681: }
4682: }
4683: if (@allhelp) {
4684: $allhelpitems = join(',',@allhelp);
4685: }
4686: }
4687:
4688: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
4689: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
4690: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
4691: &Apache::lonhtmlcommon::clear_breadcrumbs();
4692: my $args;
4693: my $brcrum = [];
4694: my $bread_crumbs_component = 'User Management';
4695: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
4696: $brcrum = [{href=>"/adm/createuser",
4697: text=>"User Management",
4698: help=>$allhelpitems}
4699: ];
4700: }
4701: if (!$allowed) {
4702: if ($context eq 'course') {
4703: $r->internal_redirect('/adm/viewclasslist');
4704: return OK;
4705: }
4706: $env{'user.error.msg'}=
4707: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4708: "or view user status.";
4709: return HTTP_NOT_ACCEPTABLE;
4710: }
4711:
4712: &Apache::loncommon::content_type($r,'text/html');
4713: $r->send_http_header;
4714:
4715: my $showcredits;
4716: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4717: ($context eq 'domain')) {
4718: my %domdefaults =
4719: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4720: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4721: $showcredits = 1;
4722: }
4723: }
4724:
4725: # Main switch on form.action and form.state, as appropriate
4726: if (! exists($env{'form.action'})) {
4727: $args = {bread_crumbs => $brcrum,
4728: bread_crumbs_component => $bread_crumbs_component};
4729: $r->print(&header(undef,$args));
4730: $r->print(&print_main_menu($permission,$context,$crstype));
4731: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
4732: my $helpitem = 'Course_Create_Class_List';
4733: if ($context eq 'author') {
4734: $helpitem = 'Author_Create_Coauthor_List';
4735: } elsif ($context eq 'domain') {
4736: $helpitem = 'Domain_Create_Users';
4737: }
4738: push(@{$brcrum},
4739: { href => '/adm/createuser?action=upload&state=',
4740: text => 'Upload Users List',
4741: help => $helpitem,
4742: });
4743: $bread_crumbs_component = 'Upload Users List';
4744: $args = {bread_crumbs => $brcrum,
4745: bread_crumbs_component => $bread_crumbs_component};
4746: $r->print(&header(undef,$args));
4747: $r->print('<form name="studentform" method="post" '.
4748: 'enctype="multipart/form-data" '.
4749: ' action="/adm/createuser">'."\n");
4750: if (! exists($env{'form.state'})) {
4751: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4752: } elsif ($env{'form.state'} eq 'got_file') {
4753: my $result =
4754: &Apache::lonuserutils::print_upload_manager_form($r,$context,
4755: $permission,
4756: $crstype,$showcredits);
4757: if ($result eq 'missingdata') {
4758: delete($env{'form.state'});
4759: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4760: }
4761: } elsif ($env{'form.state'} eq 'enrolling') {
4762: if ($env{'form.datatoken'}) {
4763: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
4764: $permission,
4765: $showcredits);
4766: if ($result eq 'missingdata') {
4767: delete($env{'form.state'});
4768: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4769: } elsif ($result eq 'invalidhome') {
4770: $env{'form.state'} = 'got_file';
4771: delete($env{'form.lcserver'});
4772: my $result =
4773: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4774: $crstype,$showcredits);
4775: if ($result eq 'missingdata') {
4776: delete($env{'form.state'});
4777: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4778: }
4779: }
4780: } else {
4781: delete($env{'form.state'});
4782: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4783: }
4784: } else {
4785: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4786: }
4787: $r->print('</form>');
4788: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4789: eq 'singlestudent')) && ($permission->{'cusr'})) ||
4790: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
4791: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
4792: my $phase = $env{'form.phase'};
4793: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
4794: &Apache::loncreateuser::restore_prev_selections();
4795: my $srch;
4796: foreach my $item (@search) {
4797: $srch->{$item} = $env{'form.'.$item};
4798: }
4799: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
4800: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
4801: if ($env{'form.phase'} eq 'createnewuser') {
4802: my $response;
4803: if ($env{'form.srchterm'} !~ /^$match_username$/) {
4804: my $response =
4805: '<span class="LC_warning">'
4806: .&mt('You must specify a valid username. Only the following are allowed:'
4807: .' letters numbers - . @')
4808: .'</span>';
4809: $env{'form.phase'} = '';
4810: &print_username_entry_form($r,$context,$response,$srch,undef,
4811: $crstype,$brcrum,$permission);
4812: } else {
4813: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4814: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4815: &print_user_modification_page($r,$ccuname,$ccdomain,
4816: $srch,$response,$context,
4817: $permission,$crstype,$brcrum,
4818: $showcredits);
4819: }
4820: } elsif ($env{'form.phase'} eq 'get_user_info') {
4821: my ($currstate,$response,$forcenewuser,$results) =
4822: &user_search_result($context,$srch);
4823: if ($env{'form.currstate'} eq 'modify') {
4824: $currstate = $env{'form.currstate'};
4825: }
4826: if ($currstate eq 'select') {
4827: &print_user_selection_page($r,$response,$srch,$results,
4828: \@search,$context,undef,$crstype,
4829: $brcrum);
4830: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4831: my ($ccuname,$ccdomain,$uhome);
4832: if (($srch->{'srchby'} eq 'uname') &&
4833: ($srch->{'srchtype'} eq 'exact')) {
4834: $ccuname = $srch->{'srchterm'};
4835: $ccdomain= $srch->{'srchdomain'};
4836: } else {
4837: my @matchedunames = keys(%{$results});
4838: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4839: }
4840: $ccuname =&LONCAPA::clean_username($ccuname);
4841: $ccdomain=&LONCAPA::clean_domain($ccdomain);
4842: if ($env{'form.action'} eq 'accesslogs') {
4843: my $uhome;
4844: if (($ccuname ne '') && ($ccdomain ne '')) {
4845: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4846: }
4847: if (($uhome eq '') || ($uhome eq 'no_host')) {
4848: $env{'form.phase'} = '';
4849: undef($forcenewuser);
4850: #if ($response) {
4851: # unless ($response =~ m{\Q<br /><br />\E$}) {
4852: # $response .= '<br /><br />';
4853: # }
4854: #}
4855: &print_username_entry_form($r,$context,$response,$srch,
4856: $forcenewuser,$crstype,$brcrum,
4857: $permission);
4858: } else {
4859: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4860: }
4861: } else {
4862: if ($env{'form.forcenewuser'}) {
4863: $response = '';
4864: }
4865: &print_user_modification_page($r,$ccuname,$ccdomain,
4866: $srch,$response,$context,
4867: $permission,$crstype,$brcrum);
4868: }
4869: } elsif ($currstate eq 'query') {
4870: &print_user_query_page($r,'createuser',$brcrum);
4871: } else {
4872: $env{'form.phase'} = '';
4873: &print_username_entry_form($r,$context,$response,$srch,
4874: $forcenewuser,$crstype,$brcrum,
4875: $permission);
4876: }
4877: } elsif ($env{'form.phase'} eq 'userpicked') {
4878: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4879: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
4880: if ($env{'form.action'} eq 'accesslogs') {
4881: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4882: } else {
4883: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4884: $context,$permission,$crstype,
4885: $brcrum);
4886: }
4887: } elsif ($env{'form.action'} eq 'accesslogs') {
4888: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4889: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4890: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4891: }
4892: } elsif ($env{'form.phase'} eq 'update_user_data') {
4893: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
4894: } else {
4895: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4896: $brcrum,$permission);
4897: }
4898: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
4899: my $prefix;
4900: if ($env{'form.phase'} eq 'set_custom_roles') {
4901: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
4902: } else {
4903: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
4904: }
4905: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4906: ($permission->{'cusr'}) &&
4907: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4908: push(@{$brcrum},
4909: {href => '/adm/createuser?action=processauthorreq',
4910: text => 'Authoring Space requests',
4911: help => 'Domain_Role_Approvals'});
4912: $bread_crumbs_component = 'Authoring requests';
4913: if ($env{'form.state'} eq 'done') {
4914: push(@{$brcrum},
4915: {href => '/adm/createuser?action=authorreqqueue',
4916: text => 'Result',
4917: help => 'Domain_Role_Approvals'});
4918: $bread_crumbs_component = 'Authoring request result';
4919: }
4920: $args = { bread_crumbs => $brcrum,
4921: bread_crumbs_component => $bread_crumbs_component};
4922: my $js = &usernamerequest_javascript();
4923: $r->print(&header(&add_script($js),$args));
4924: if (!exists($env{'form.state'})) {
4925: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4926: $env{'request.role.domain'}));
4927: } elsif ($env{'form.state'} eq 'done') {
4928: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4929: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4930: $env{'request.role.domain'}));
4931: }
4932: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4933: ($permission->{'cusr'}) &&
4934: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4935: push(@{$brcrum},
4936: {href => '/adm/createuser?action=processusernamereq',
4937: text => 'LON-CAPA account requests',
4938: help => 'Domain_Username_Approvals'});
4939: $bread_crumbs_component = 'Account requests';
4940: if ($env{'form.state'} eq 'done') {
4941: push(@{$brcrum},
4942: {href => '/adm/createuser?action=usernamereqqueue',
4943: text => 'Result',
4944: help => 'Domain_Username_Approvals'});
4945: $bread_crumbs_component = 'LON-CAPA account request result';
4946: }
4947: $args = { bread_crumbs => $brcrum,
4948: bread_crumbs_component => $bread_crumbs_component};
4949: my $js = &usernamerequest_javascript();
4950: $r->print(&header(&add_script($js),$args));
4951: if (!exists($env{'form.state'})) {
4952: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4953: $env{'request.role.domain'}));
4954: } elsif ($env{'form.state'} eq 'done') {
4955: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4956: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4957: $env{'request.role.domain'}));
4958: }
4959: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4960: ($permission->{'cusr'})) {
4961: my $dom = $env{'form.domain'};
4962: my $uname = $env{'form.username'};
4963: my $warning;
4964: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4965: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4966: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4967: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4968: if ($uhome eq 'no_host') {
4969: my $queue = $env{'form.queue'};
4970: my $reqkey = &escape($uname).'_'.$queue;
4971: my $namespace = 'usernamequeue';
4972: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4973: my %queued =
4974: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4975: unless ($queued{$reqkey}) {
4976: $warning = &mt('No information was found for this LON-CAPA account request.');
4977: }
4978: } else {
4979: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4980: }
4981: } else {
4982: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4983: }
4984: } else {
4985: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4986: }
4987: } else {
4988: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4989: }
4990: my $args = { only_body => 1 };
4991: $r->print(&header(undef,$args).
4992: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4993: if ($warning ne '') {
4994: $r->print('<div class="LC_warning">'.$warning.'</div>');
4995: } else {
4996: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4997: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4998: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4999: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5000: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
5001: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
5002: my %info =
5003: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
5004: if (ref($info{$uname}) eq 'HASH') {
5005: my $usertype = $info{$uname}{'inststatus'};
5006: unless ($usertype) {
5007: $usertype = 'default';
5008: }
5009: my ($showstatus,$showemail,$pickstart);
5010: my $numextras = 0;
5011: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5012: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
5013: if (ref($usertypes) eq 'HASH') {
5014: if ($usertypes->{$usertype}) {
5015: $showstatus = $usertypes->{$usertype};
5016: } else {
5017: $showstatus = $othertitle;
5018: }
5019: if ($showstatus) {
5020: $numextras ++;
5021: }
5022: }
5023: }
5024: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5025: $showemail = $info{$uname}{'email'};
5026: $numextras ++;
5027: }
5028: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5029: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
5030: $pickstart = 1;
5031: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5032: my ($num,$count);
5033: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
5034: $count += $numextras;
5035: foreach my $field (@{$infofields}) {
5036: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5037: next unless ($infotitles->{$field});
5038: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5039: $info{$uname}{$field});
5040: $num ++;
5041: unless ($count == $num) {
5042: $r->print(&Apache::lonhtmlcommon::row_closure());
5043: }
5044: }
5045: }
5046: }
5047: if ($numextras) {
5048: unless ($pickstart) {
5049: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5050: $pickstart = 1;
5051: }
5052: if ($showemail) {
5053: my $closure = '';
5054: unless ($showstatus) {
5055: $closure = 1;
5056: }
5057: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5058: $showemail.
5059: &Apache::lonhtmlcommon::row_closure($closure));
5060: }
5061: if ($showstatus) {
5062: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5063: $showstatus.
5064: &Apache::lonhtmlcommon::row_closure(1));
5065: }
5066: }
5067: if ($pickstart) {
5068: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5069: } else {
5070: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
5071: }
5072: } else {
5073: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
5074: }
5075: }
5076: }
5077: }
5078: }
5079: $r->print(&close_popup_form());
5080: } elsif (($env{'form.action'} eq 'listusers') &&
5081: ($permission->{'view'} || $permission->{'cusr'})) {
5082: my $helpitem = 'Course_View_Class_List';
5083: if ($context eq 'author') {
5084: $helpitem = 'Author_View_Coauthor_List';
5085: } elsif ($context eq 'domain') {
5086: $helpitem = 'Domain_View_Users_List';
5087: }
5088: if ($env{'form.phase'} eq 'bulkchange') {
5089: push(@{$brcrum},
5090: {href => '/adm/createuser?action=listusers',
5091: text => "List Users"},
5092: {href => "/adm/createuser",
5093: text => "Result",
5094: help => $helpitem});
5095: $bread_crumbs_component = 'Update Users';
5096: $args = {bread_crumbs => $brcrum,
5097: bread_crumbs_component => $bread_crumbs_component};
5098: $r->print(&header(undef,$args));
5099: my $setting = $env{'form.roletype'};
5100: my $choice = $env{'form.bulkaction'};
5101: if ($permission->{'cusr'}) {
5102: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
5103: } else {
5104: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
5105: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
5106: }
5107: } else {
5108: push(@{$brcrum},
5109: {href => '/adm/createuser?action=listusers',
5110: text => "List Users",
5111: help => $helpitem});
5112: $bread_crumbs_component = 'List Users';
5113: $args = {bread_crumbs => $brcrum,
5114: bread_crumbs_component => $bread_crumbs_component};
5115: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5116: my $formname = 'studentform';
5117: my $hidecall = "hide_searching();";
5118: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5119: ($env{'form.roletype'} eq 'community'))) {
5120: if ($env{'form.roletype'} eq 'course') {
5121: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5122: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5123: $formname);
5124: } elsif ($env{'form.roletype'} eq 'community') {
5125: $cb_jscript =
5126: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5127: my %elements = (
5128: coursepick => 'radio',
5129: coursetotal => 'text',
5130: courselist => 'text',
5131: );
5132: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5133: }
5134: $jscript .= &verify_user_display($context)."\n".
5135: &Apache::loncommon::check_uncheck_jscript();
5136: my $js = &add_script($jscript).$cb_jscript;
5137: my $loadcode =
5138: &Apache::lonuserutils::course_selector_loadcode($formname);
5139: if ($loadcode ne '') {
5140: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5141: } else {
5142: $args->{add_entries} = {onload => $hidecall};
5143: }
5144: $r->print(&header($js,$args));
5145: } else {
5146: $args->{add_entries} = {onload => $hidecall};
5147: $jscript = &verify_user_display($context).
5148: &Apache::loncommon::check_uncheck_jscript();
5149: $r->print(&header(&add_script($jscript),$args));
5150: }
5151: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
5152: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5153: $showcredits);
5154: }
5155: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
5156: my $brtext;
5157: if ($crstype eq 'Community') {
5158: $brtext = 'Drop Members';
5159: } else {
5160: $brtext = 'Drop Students';
5161: }
5162: push(@{$brcrum},
5163: {href => '/adm/createuser?action=drop',
5164: text => $brtext,
5165: help => 'Course_Drop_Student'});
5166: if ($env{'form.state'} eq 'done') {
5167: push(@{$brcrum},
5168: {href=>'/adm/createuser?action=drop',
5169: text=>"Result"});
5170: }
5171: $bread_crumbs_component = $brtext;
5172: $args = {bread_crumbs => $brcrum,
5173: bread_crumbs_component => $bread_crumbs_component};
5174: $r->print(&header(undef,$args));
5175: if (!exists($env{'form.state'})) {
5176: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
5177: } elsif ($env{'form.state'} eq 'done') {
5178: &Apache::lonuserutils::update_user_list($r,$context,undef,
5179: $env{'form.action'});
5180: }
5181: } elsif ($env{'form.action'} eq 'dateselect') {
5182: if ($permission->{'cusr'}) {
5183: $r->print(&header(undef,{'no_nav_bar' => 1}).
5184: &Apache::lonuserutils::date_section_selector($context,$permission,
5185: $crstype,$showcredits));
5186: } else {
5187: $r->print(&header(undef,{'no_nav_bar' => 1}).
5188: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
5189: }
5190: } elsif ($env{'form.action'} eq 'selfenroll') {
5191: if ($permission->{selfenrolladmin}) {
5192: my %currsettings = (
5193: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5194: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5195: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5196: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5197: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5198: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5199: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5200: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5201: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5202: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5203: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5204: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5205: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
5206: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
5207: );
5208: push(@{$brcrum},
5209: {href => '/adm/createuser?action=selfenroll',
5210: text => "Configure Self-enrollment",
5211: help => 'Course_Self_Enrollment'});
5212: if (!exists($env{'form.state'})) {
5213: $args = { bread_crumbs => $brcrum,
5214: bread_crumbs_component => 'Configure Self-enrollment'};
5215: $r->print(&header(undef,$args));
5216: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5217: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5218: } elsif ($env{'form.state'} eq 'done') {
5219: push (@{$brcrum},
5220: {href=>'/adm/createuser?action=selfenroll',
5221: text=>"Result"});
5222: $args = { bread_crumbs => $brcrum,
5223: bread_crumbs_component => 'Self-enrollment result'};
5224: $r->print(&header(undef,$args));
5225: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5226: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
5227: }
5228: } else {
5229: $r->print(&header(undef,{'no_nav_bar' => 1}).
5230: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
5231: }
5232: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
5233: if ($permission->{selfenrolladmin}) {
5234: push(@{$brcrum},
5235: {href => '/adm/createuser?action=selfenrollqueue',
5236: text => 'Enrollment requests',
5237: help => 'Course_Approve_Selfenroll'});
5238: $bread_crumbs_component = 'Enrollment requests';
5239: if ($env{'form.state'} eq 'done') {
5240: push(@{$brcrum},
5241: {href => '/adm/createuser?action=selfenrollqueue',
5242: text => 'Result',
5243: help => 'Course_Approve_Selfenroll'});
5244: $bread_crumbs_component = 'Enrollment result';
5245: }
5246: $args = { bread_crumbs => $brcrum,
5247: bread_crumbs_component => $bread_crumbs_component};
5248: $r->print(&header(undef,$args));
5249: my $coursedesc = $env{'course.'.$cid.'.description'};
5250: if (!exists($env{'form.state'})) {
5251: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5252: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5253: $cdom,$cnum));
5254: } elsif ($env{'form.state'} eq 'done') {
5255: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5256: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5257: $cdom,$cnum,$coursedesc));
5258: }
5259: } else {
5260: $r->print(&header(undef,{'no_nav_bar' => 1}).
5261: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
5262: }
5263: } elsif ($env{'form.action'} eq 'changelogs') {
5264: if ($permission->{cusr} || $permission->{view}) {
5265: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5266: } else {
5267: $r->print(&header(undef,{'no_nav_bar' => 1}).
5268: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
5269: }
5270: } elsif ($env{'form.action'} eq 'helpdesk') {
5271: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5272: if ($env{'form.state'} eq 'process') {
5273: if ($permission->{'owner'}) {
5274: &update_helpdeskaccess($r,$permission,$brcrum);
5275: } else {
5276: &print_helpdeskaccess_display($r,$permission,$brcrum);
5277: }
5278: } else {
5279: &print_helpdeskaccess_display($r,$permission,$brcrum);
5280: }
5281: } else {
5282: $r->print(&header(undef,{'no_nav_bar' => 1}).
5283: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5284: }
5285: } else {
5286: $bread_crumbs_component = 'User Management';
5287: $args = { bread_crumbs => $brcrum,
5288: bread_crumbs_component => $bread_crumbs_component};
5289: $r->print(&header(undef,$args));
5290: $r->print(&print_main_menu($permission,$context,$crstype));
5291: }
5292: $r->print(&Apache::loncommon::end_page());
5293: return OK;
5294: }
5295:
5296: sub header {
5297: my ($jscript,$args) = @_;
5298: my $start_page;
5299: if (ref($args) eq 'HASH') {
5300: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
5301: } else {
5302: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
5303: }
5304: return $start_page;
5305: }
5306:
5307: sub add_script {
5308: my ($js) = @_;
5309: return '<script type="text/javascript">'."\n"
5310: .'// <![CDATA['."\n"
5311: .$js."\n"
5312: .'// ]]>'."\n"
5313: .'</script>'."\n";
5314: }
5315:
5316: sub usernamerequest_javascript {
5317: my $js = <<ENDJS;
5318:
5319: function openusernamereqdisplay(dom,uname,queue) {
5320: var url = '/adm/createuser?action=displayuserreq';
5321: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5322: var title = 'Account_Request_Browser';
5323: var options = 'scrollbars=1,resizable=1,menubar=0';
5324: options += ',width=700,height=600';
5325: var stdeditbrowser = open(url,title,options,'1');
5326: stdeditbrowser.focus();
5327: return;
5328: }
5329:
5330: ENDJS
5331: }
5332:
5333: sub close_popup_form {
5334: my $close= &mt('Close Window');
5335: return << "END";
5336: <p><form name="displayreq" action="" method="post">
5337: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5338: </form></p>
5339: END
5340: }
5341:
5342: sub verify_user_display {
5343: my ($context) = @_;
5344: my %lt = &Apache::lonlocal::texthash (
5345: course => 'course(s): description, section(s), status',
5346: community => 'community(s): description, section(s), status',
5347: author => 'author',
5348: );
5349: my $photos;
5350: if (($context eq 'course') && $env{'request.course.id'}) {
5351: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5352: }
5353: my $output = <<"END";
5354:
5355: function hide_searching() {
5356: if (document.getElementById('searching')) {
5357: document.getElementById('searching').style.display = 'none';
5358: }
5359: return;
5360: }
5361:
5362: function display_update() {
5363: document.studentform.action.value = 'listusers';
5364: document.studentform.phase.value = 'display';
5365: document.studentform.submit();
5366: }
5367:
5368: function updateCols(caller) {
5369: var context = '$context';
5370: var photos = '$photos';
5371: if (caller == 'Status') {
5372: if ((context == 'domain') &&
5373: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5374: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
5375: document.getElementById('showcolstatus').checked = false;
5376: document.getElementById('showcolstatus').disabled = 'disabled';
5377: document.getElementById('showcolstart').checked = false;
5378: document.getElementById('showcolend').checked = false;
5379: } else {
5380: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5381: document.getElementById('showcolstatus').checked = true;
5382: document.getElementById('showcolstatus').disabled = '';
5383: document.getElementById('showcolstart').checked = true;
5384: document.getElementById('showcolend').checked = true;
5385: } else {
5386: document.getElementById('showcolstatus').checked = false;
5387: document.getElementById('showcolstatus').disabled = 'disabled';
5388: document.getElementById('showcolstart').checked = false;
5389: document.getElementById('showcolend').checked = false;
5390: }
5391: }
5392: }
5393: if (caller == 'output') {
5394: if (photos == 1) {
5395: if (document.getElementById('showcolphoto')) {
5396: var photoitem = document.getElementById('showcolphoto');
5397: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5398: photoitem.checked = true;
5399: photoitem.disabled = '';
5400: } else {
5401: photoitem.checked = false;
5402: photoitem.disabled = 'disabled';
5403: }
5404: }
5405: }
5406: }
5407: if (caller == 'showrole') {
5408: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5409: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
5410: document.getElementById('showcolrole').checked = true;
5411: document.getElementById('showcolrole').disabled = '';
5412: } else {
5413: document.getElementById('showcolrole').checked = false;
5414: document.getElementById('showcolrole').disabled = 'disabled';
5415: }
5416: if (context == 'domain') {
5417: var quotausageshow = 0;
5418: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5419: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5420: document.getElementById('showcolstatus').checked = false;
5421: document.getElementById('showcolstatus').disabled = 'disabled';
5422: document.getElementById('showcolstart').checked = false;
5423: document.getElementById('showcolend').checked = false;
5424: } else {
5425: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5426: document.getElementById('showcolstatus').checked = true;
5427: document.getElementById('showcolstatus').disabled = '';
5428: document.getElementById('showcolstart').checked = true;
5429: document.getElementById('showcolend').checked = true;
5430: }
5431: }
5432: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5433: document.getElementById('showcolextent').disabled = 'disabled';
5434: document.getElementById('showcolextent').checked = 'false';
5435: document.getElementById('showextent').style.display='none';
5436: document.getElementById('showcoltextextent').innerHTML = '';
5437: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5438: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5439: if (document.getElementById('showcolauthorusage')) {
5440: document.getElementById('showcolauthorusage').disabled = '';
5441: }
5442: if (document.getElementById('showcolauthorquota')) {
5443: document.getElementById('showcolauthorquota').disabled = '';
5444: }
5445: quotausageshow = 1;
5446: }
5447: } else {
5448: document.getElementById('showextent').style.display='block';
5449: document.getElementById('showextent').style.textAlign='left';
5450: document.getElementById('showextent').style.textFace='normal';
5451: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5452: document.getElementById('showcolextent').disabled = '';
5453: document.getElementById('showcolextent').checked = 'true';
5454: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5455: } else {
5456: document.getElementById('showcolextent').disabled = '';
5457: document.getElementById('showcolextent').checked = 'true';
5458: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5459: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5460: } else {
5461: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5462: }
5463: }
5464: }
5465: if (quotausageshow == 0) {
5466: if (document.getElementById('showcolauthorusage')) {
5467: document.getElementById('showcolauthorusage').checked = false;
5468: document.getElementById('showcolauthorusage').disabled = 'disabled';
5469: }
5470: if (document.getElementById('showcolauthorquota')) {
5471: document.getElementById('showcolauthorquota').checked = false;
5472: document.getElementById('showcolauthorquota').disabled = 'disabled';
5473: }
5474: }
5475: }
5476: }
5477: return;
5478: }
5479:
5480: END
5481: return $output;
5482:
5483: }
5484:
5485: ###############################################################
5486: ###############################################################
5487: # Menu Phase One
5488: sub print_main_menu {
5489: my ($permission,$context,$crstype) = @_;
5490: my $linkcontext = $context;
5491: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5492: if (($context eq 'course') && ($crstype eq 'Community')) {
5493: $linkcontext = lc($crstype);
5494: $stuterm = 'Members';
5495: }
5496: my %links = (
5497: domain => {
5498: upload => 'Upload a File of Users',
5499: singleuser => 'Add/Modify a User',
5500: listusers => 'Manage Users',
5501: },
5502: author => {
5503: upload => 'Upload a File of Co-authors',
5504: singleuser => 'Add/Modify a Co-author',
5505: listusers => 'Manage Co-authors',
5506: },
5507: course => {
5508: upload => 'Upload a File of Course Users',
5509: singleuser => 'Add/Modify a Course User',
5510: listusers => 'List and Modify Multiple Course Users',
5511: },
5512: community => {
5513: upload => 'Upload a File of Community Users',
5514: singleuser => 'Add/Modify a Community User',
5515: listusers => 'List and Modify Multiple Community Users',
5516: },
5517: );
5518: my %linktitles = (
5519: domain => {
5520: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5521: listusers => 'Show and manage users in this domain.',
5522: },
5523: author => {
5524: singleuser => 'Add a user with a co- or assistant author role.',
5525: listusers => 'Show and manage co- or assistant authors.',
5526: },
5527: course => {
5528: singleuser => 'Add a user with a certain role to this course.',
5529: listusers => 'Show and manage users in this course.',
5530: },
5531: community => {
5532: singleuser => 'Add a user with a certain role to this community.',
5533: listusers => 'Show and manage users in this community.',
5534: },
5535: );
5536: if ($linkcontext eq 'domain') {
5537: unless ($permission->{'cusr'}) {
5538: $links{'domain'}{'singleuser'} = 'View a User';
5539: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5540: }
5541: } elsif ($linkcontext eq 'course') {
5542: unless ($permission->{'cusr'}) {
5543: $links{'course'}{'singleuser'} = 'View a Course User';
5544: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5545: $links{'course'}{'listusers'} = 'List Course Users';
5546: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5547: }
5548: } elsif ($linkcontext eq 'community') {
5549: unless ($permission->{'cusr'}) {
5550: $links{'community'}{'singleuser'} = 'View a Community User';
5551: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5552: $links{'community'}{'listusers'} = 'List Community Users';
5553: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5554: }
5555: }
5556: my @menu = ( {categorytitle => 'Single Users',
5557: items =>
5558: [
5559: {
5560: linktext => $links{$linkcontext}{'singleuser'},
5561: icon => 'edit-redo.png',
5562: #help => 'Course_Change_Privileges',
5563: url => '/adm/createuser?action=singleuser',
5564: permission => ($permission->{'view'} || $permission->{'cusr'}),
5565: linktitle => $linktitles{$linkcontext}{'singleuser'},
5566: },
5567: ]},
5568:
5569: {categorytitle => 'Multiple Users',
5570: items =>
5571: [
5572: {
5573: linktext => $links{$linkcontext}{'upload'},
5574: icon => 'uplusr.png',
5575: #help => 'Course_Create_Class_List',
5576: url => '/adm/createuser?action=upload',
5577: permission => $permission->{'cusr'},
5578: linktitle => 'Upload a CSV or a text file containing users.',
5579: },
5580: {
5581: linktext => $links{$linkcontext}{'listusers'},
5582: icon => 'mngcu.png',
5583: #help => 'Course_View_Class_List',
5584: url => '/adm/createuser?action=listusers',
5585: permission => ($permission->{'view'} || $permission->{'cusr'}),
5586: linktitle => $linktitles{$linkcontext}{'listusers'},
5587: },
5588:
5589: ]},
5590:
5591: {categorytitle => 'Administration',
5592: items => [ ]},
5593: );
5594:
5595: if ($context eq 'domain'){
5596: push(@{ $menu[0]->{items} }, # Single Users
5597: {
5598: linktext => 'User Access Log',
5599: icon => 'document-properties.png',
5600: #help => 'Domain_User_Access_Logs',
5601: url => '/adm/createuser?action=accesslogs',
5602: permission => $permission->{'activity'},
5603: linktitle => 'View user access log.',
5604: }
5605: );
5606:
5607: push(@{ $menu[2]->{items} }, #Category: Administration
5608: {
5609: linktext => 'Custom Roles',
5610: icon => 'emblem-photos.png',
5611: #help => 'Course_Editing_Custom_Roles',
5612: url => '/adm/createuser?action=custom',
5613: permission => $permission->{'custom'},
5614: linktitle => 'Configure a custom role.',
5615: },
5616: {
5617: linktext => 'Authoring Space Requests',
5618: icon => 'selfenrl-queue.png',
5619: #help => 'Domain_Role_Approvals',
5620: url => '/adm/createuser?action=processauthorreq',
5621: permission => $permission->{'cusr'},
5622: linktitle => 'Approve or reject author role requests',
5623: },
5624: {
5625: linktext => 'LON-CAPA Account Requests',
5626: icon => 'list-add.png',
5627: #help => 'Domain_Username_Approvals',
5628: url => '/adm/createuser?action=processusernamereq',
5629: permission => $permission->{'cusr'},
5630: linktitle => 'Approve or reject LON-CAPA account requests',
5631: },
5632: {
5633: linktext => 'Change Log',
5634: icon => 'document-properties.png',
5635: #help => 'Course_User_Logs',
5636: url => '/adm/createuser?action=changelogs',
5637: permission => ($permission->{'cusr'} || $permission->{'view'}),
5638: linktitle => 'View change log.',
5639: },
5640: );
5641:
5642: }elsif ($context eq 'course'){
5643: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
5644:
5645: my %linktext = (
5646: 'Course' => {
5647: single => 'Add/Modify a Student',
5648: drop => 'Drop Students',
5649: groups => 'Course Groups',
5650: },
5651: 'Community' => {
5652: single => 'Add/Modify a Member',
5653: drop => 'Drop Members',
5654: groups => 'Community Groups',
5655: },
5656: );
5657: $linktext{'Placement'} = $linktext{'Course'};
5658:
5659: my %linktitle = (
5660: 'Course' => {
5661: single => 'Add a user with the role of student to this course',
5662: drop => 'Remove a student from this course.',
5663: groups => 'Manage course groups',
5664: },
5665: 'Community' => {
5666: single => 'Add a user with the role of member to this community',
5667: drop => 'Remove a member from this community.',
5668: groups => 'Manage community groups',
5669: },
5670: );
5671:
5672: $linktitle{'Placement'} = $linktitle{'Course'};
5673:
5674: push(@{ $menu[0]->{items} }, #Category: Single Users
5675: {
5676: linktext => $linktext{$crstype}{'single'},
5677: #help => 'Course_Add_Student',
5678: icon => 'list-add.png',
5679: url => '/adm/createuser?action=singlestudent',
5680: permission => $permission->{'cusr'},
5681: linktitle => $linktitle{$crstype}{'single'},
5682: },
5683: );
5684:
5685: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5686: {
5687: linktext => $linktext{$crstype}{'drop'},
5688: icon => 'edit-undo.png',
5689: #help => 'Course_Drop_Student',
5690: url => '/adm/createuser?action=drop',
5691: permission => $permission->{'cusr'},
5692: linktitle => $linktitle{$crstype}{'drop'},
5693: },
5694: );
5695: push(@{ $menu[2]->{items} }, #Category: Administration
5696: {
5697: linktext => 'Helpdesk Access',
5698: icon => 'helpdesk-access.png',
5699: #help => 'Course_Helpdesk_Access',
5700: url => '/adm/createuser?action=helpdesk',
5701: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5702: linktitle => 'Helpdesk access options',
5703: },
5704: {
5705: linktext => 'Custom Roles',
5706: icon => 'emblem-photos.png',
5707: #help => 'Course_Editing_Custom_Roles',
5708: url => '/adm/createuser?action=custom',
5709: permission => $permission->{'custom'},
5710: linktitle => 'Configure a custom role.',
5711: },
5712: {
5713: linktext => $linktext{$crstype}{'groups'},
5714: icon => 'grps.png',
5715: #help => 'Course_Manage_Group',
5716: url => '/adm/coursegroups?refpage=cusr',
5717: permission => $permission->{'grp_manage'},
5718: linktitle => $linktitle{$crstype}{'groups'},
5719: },
5720: {
5721: linktext => 'Change Log',
5722: icon => 'document-properties.png',
5723: #help => 'Course_User_Logs',
5724: url => '/adm/createuser?action=changelogs',
5725: permission => ($permission->{'view'} || $permission->{'cusr'}),
5726: linktitle => 'View change log.',
5727: },
5728: );
5729: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
5730: push(@{ $menu[2]->{items} },
5731: {
5732: linktext => 'Enrollment Requests',
5733: icon => 'selfenrl-queue.png',
5734: #help => 'Course_Approve_Selfenroll',
5735: url => '/adm/createuser?action=selfenrollqueue',
5736: permission => $permission->{'selfenrolladmin'},
5737: linktitle =>'Approve or reject enrollment requests.',
5738: },
5739: );
5740: }
5741:
5742: if (!exists($permission->{'cusr_section'})){
5743: if ($crstype ne 'Community') {
5744: push(@{ $menu[2]->{items} },
5745: {
5746: linktext => 'Automated Enrollment',
5747: icon => 'roles.png',
5748: #help => 'Course_Automated_Enrollment',
5749: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
5750: && (($permission->{'cusr'}) ||
5751: ($permission->{'view'}))),
5752: url => '/adm/populate',
5753: linktitle => 'Automated enrollment manager.',
5754: }
5755: );
5756: }
5757: push(@{ $menu[2]->{items} },
5758: {
5759: linktext => 'User Self-Enrollment',
5760: icon => 'self_enroll.png',
5761: #help => 'Course_Self_Enrollment',
5762: url => '/adm/createuser?action=selfenroll',
5763: permission => $permission->{'selfenrolladmin'},
5764: linktitle => 'Configure user self-enrollment.',
5765: },
5766: );
5767: }
5768: } elsif ($context eq 'author') {
5769: push(@{ $menu[2]->{items} }, #Category: Administration
5770: {
5771: linktext => 'Change Log',
5772: icon => 'document-properties.png',
5773: #help => 'Course_User_Logs',
5774: url => '/adm/createuser?action=changelogs',
5775: permission => $permission->{'cusr'},
5776: linktitle => 'View change log.',
5777: },
5778: );
5779: }
5780: return Apache::lonhtmlcommon::generate_menu(@menu);
5781: # { text => 'View Log-in History',
5782: # help => 'Course_User_Logins',
5783: # action => 'logins',
5784: # permission => $permission->{'cusr'},
5785: # });
5786: }
5787:
5788: sub restore_prev_selections {
5789: my %saveable_parameters = ('srchby' => 'scalar',
5790: 'srchin' => 'scalar',
5791: 'srchtype' => 'scalar',
5792: );
5793: &Apache::loncommon::store_settings('user','user_picker',
5794: \%saveable_parameters);
5795: &Apache::loncommon::restore_settings('user','user_picker',
5796: \%saveable_parameters);
5797: }
5798:
5799: sub print_selfenroll_menu {
5800: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
5801: my $crstype = &Apache::loncommon::course_type();
5802: my $formname = 'selfenroll';
5803: my $nolink = 1;
5804: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
5805: my $groupslist = &Apache::lonuserutils::get_groupslist();
5806: my $setsec_js =
5807: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
5808: my %alerts = &Apache::lonlocal::texthash(
5809: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5810: butn => 'but no user types have been checked.',
5811: wilf => "Please uncheck 'activate' or check at least one type.",
5812: );
5813: my $disabled;
5814: if ($readonly) {
5815: $disabled = ' disabled="disabled"';
5816: }
5817: &js_escape(\%alerts);
5818: my $selfenroll_js = <<"ENDSCRIPT";
5819: function update_types(caller,num) {
5820: var delidx = getIndexByName('selfenroll_delete');
5821: var actidx = getIndexByName('selfenroll_activate');
5822: if (caller == 'selfenroll_all') {
5823: var selall;
5824: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5825: if (document.$formname.selfenroll_all[i].checked) {
5826: selall = document.$formname.selfenroll_all[i].value;
5827: }
5828: }
5829: if (selall == 1) {
5830: if (delidx != -1) {
5831: if (document.$formname.selfenroll_delete.length) {
5832: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5833: document.$formname.selfenroll_delete[j].checked = true;
5834: }
5835: } else {
5836: document.$formname.elements[delidx].checked = true;
5837: }
5838: }
5839: if (actidx != -1) {
5840: if (document.$formname.selfenroll_activate.length) {
5841: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5842: document.$formname.selfenroll_activate[j].checked = false;
5843: }
5844: } else {
5845: document.$formname.elements[actidx].checked = false;
5846: }
5847: }
5848: document.$formname.selfenroll_newdom.selectedIndex = 0;
5849: }
5850: }
5851: if (caller == 'selfenroll_activate') {
5852: if (document.$formname.selfenroll_activate.length) {
5853: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5854: if (document.$formname.selfenroll_activate[j].value == num) {
5855: if (document.$formname.selfenroll_activate[j].checked) {
5856: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5857: if (document.$formname.selfenroll_all[i].value == '1') {
5858: document.$formname.selfenroll_all[i].checked = false;
5859: }
5860: if (document.$formname.selfenroll_all[i].value == '0') {
5861: document.$formname.selfenroll_all[i].checked = true;
5862: }
5863: }
5864: }
5865: }
5866: }
5867: } else {
5868: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5869: if (document.$formname.selfenroll_all[i].value == '1') {
5870: document.$formname.selfenroll_all[i].checked = false;
5871: }
5872: if (document.$formname.selfenroll_all[i].value == '0') {
5873: document.$formname.selfenroll_all[i].checked = true;
5874: }
5875: }
5876: }
5877: }
5878: if (caller == 'selfenroll_delete') {
5879: if (document.$formname.selfenroll_delete.length) {
5880: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5881: if (document.$formname.selfenroll_delete[j].value == num) {
5882: if (document.$formname.selfenroll_delete[j].checked) {
5883: var delindex = getIndexByName('selfenroll_types_'+num);
5884: if (delindex != -1) {
5885: if (document.$formname.elements[delindex].length) {
5886: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5887: document.$formname.elements[delindex][k].checked = false;
5888: }
5889: } else {
5890: document.$formname.elements[delindex].checked = false;
5891: }
5892: }
5893: }
5894: }
5895: }
5896: } else {
5897: if (document.$formname.selfenroll_delete.checked) {
5898: var delindex = getIndexByName('selfenroll_types_'+num);
5899: if (delindex != -1) {
5900: if (document.$formname.elements[delindex].length) {
5901: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5902: document.$formname.elements[delindex][k].checked = false;
5903: }
5904: } else {
5905: document.$formname.elements[delindex].checked = false;
5906: }
5907: }
5908: }
5909: }
5910: }
5911: return;
5912: }
5913:
5914: function validate_types(form) {
5915: var needaction = new Array();
5916: var countfail = 0;
5917: var actidx = getIndexByName('selfenroll_activate');
5918: if (actidx != -1) {
5919: if (document.$formname.selfenroll_activate.length) {
5920: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5921: var num = document.$formname.selfenroll_activate[j].value;
5922: if (document.$formname.selfenroll_activate[j].checked) {
5923: countfail = check_types(num,countfail,needaction)
5924: }
5925: }
5926: } else {
5927: if (document.$formname.selfenroll_activate.checked) {
5928: var num = document.$formname.selfenroll_activate.value;
5929: countfail = check_types(num,countfail,needaction)
5930: }
5931: }
5932: }
5933: if (countfail > 0) {
5934: var msg = "$alerts{'acto'}\\n";
5935: var loopend = needaction.length -1;
5936: if (loopend > 0) {
5937: for (var m=0; m<loopend; m++) {
5938: msg += needaction[m]+", ";
5939: }
5940: }
5941: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5942: alert(msg);
5943: return;
5944: }
5945: setSections(form);
5946: }
5947:
5948: function check_types(num,countfail,needaction) {
5949: var boxname = 'selfenroll_types_'+num;
5950: var typeidx = getIndexByName(boxname);
5951: var count = 0;
5952: if (typeidx != -1) {
5953: if (document.$formname.elements[boxname].length) {
5954: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
5955: if (document.$formname.elements[boxname][k].checked) {
5956: count ++;
5957: }
5958: }
5959: } else {
5960: if (document.$formname.elements[typeidx].checked) {
5961: count ++;
5962: }
5963: }
5964: if (count == 0) {
5965: var domidx = getIndexByName('selfenroll_dom_'+num);
5966: if (domidx != -1) {
5967: var domname = document.$formname.elements[domidx].value;
5968: needaction[countfail] = domname;
5969: countfail ++;
5970: }
5971: }
5972: }
5973: return countfail;
5974: }
5975:
5976: function toggleNotify() {
5977: var selfenrollApproval = 0;
5978: if (document.$formname.selfenroll_approval.length) {
5979: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5980: if (document.$formname.selfenroll_approval[i].checked) {
5981: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5982: break;
5983: }
5984: }
5985: }
5986: if (document.getElementById('notified')) {
5987: if (selfenrollApproval == 0) {
5988: document.getElementById('notified').style.display='none';
5989: } else {
5990: document.getElementById('notified').style.display='block';
5991: }
5992: }
5993: return;
5994: }
5995:
5996: function getIndexByName(item) {
5997: for (var i=0;i<document.$formname.elements.length;i++) {
5998: if (document.$formname.elements[i].name == item) {
5999: return i;
6000: }
6001: }
6002: return -1;
6003: }
6004: ENDSCRIPT
6005:
6006: my $output = '<script type="text/javascript">'."\n".
6007: '// <![CDATA['."\n".
6008: $setsec_js."\n".$selfenroll_js."\n".
6009: '// ]]>'."\n".
6010: '</script>'."\n".
6011: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
6012:
6013: my $visactions = &cat_visibility();
6014: my ($cathash,%cattype);
6015: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
6016: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6017: $cathash = $domconfig{'coursecategories'}{'cats'};
6018: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
6019: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
6020: if ($cattype{'auth'} eq '') {
6021: $cattype{'auth'} = 'std';
6022: }
6023: if ($cattype{'unauth'} eq '') {
6024: $cattype{'unauth'} = 'std';
6025: }
6026: } else {
6027: $cathash = {};
6028: $cattype{'auth'} = 'std';
6029: $cattype{'unauth'} = 'std';
6030: }
6031: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
6032: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6033: '<br />'.
6034: '<br />'.$visactions->{'take'}.'<ul>'.
6035: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
6036: '</ul>');
6037: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
6038: if ($currsettings->{'uniquecode'}) {
6039: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
6040: } else {
6041: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6042: '<br />'.
6043: '<br />'.$visactions->{'take'}.'<ul>'.
6044: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6045: '</ul><br />');
6046: }
6047: } else {
6048: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6049: if (ref($visactions) eq 'HASH') {
6050: if ($visible) {
6051: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6052: } else {
6053: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6054: .$visactions->{'yous'}.
6055: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6056: if (ref($vismsgs) eq 'ARRAY') {
6057: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6058: foreach my $item (@{$vismsgs}) {
6059: $output .= '<li>'.$visactions->{$item}.'</li>';
6060: }
6061: $output .= '</ul>';
6062: }
6063: $output .= '</p>';
6064: }
6065: }
6066: }
6067: my $actionhref = '/adm/createuser';
6068: if ($context eq 'domain') {
6069: $actionhref = '/adm/modifycourse';
6070: }
6071:
6072: my %noedit;
6073: unless ($context eq 'domain') {
6074: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6075: }
6076: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
6077: &Apache::lonhtmlcommon::start_pick_box();
6078: if (ref($row) eq 'ARRAY') {
6079: foreach my $item (@{$row}) {
6080: my $title = $item;
6081: if (ref($lt) eq 'HASH') {
6082: $title = $lt->{$item};
6083: }
6084: $output .= &Apache::lonhtmlcommon::row_title($title);
6085: if ($item eq 'types') {
6086: my $curr_types;
6087: if (ref($currsettings) eq 'HASH') {
6088: $curr_types = $currsettings->{'selfenroll_types'};
6089: }
6090: if ($noedit{$item}) {
6091: if ($curr_types eq '*') {
6092: $output .= &mt('Any user in any domain');
6093: } else {
6094: my @entries = split(/;/,$curr_types);
6095: if (@entries > 0) {
6096: $output .= '<ul>';
6097: foreach my $entry (@entries) {
6098: my ($currdom,$typestr) = split(/:/,$entry);
6099: next if ($typestr eq '');
6100: my $domdesc = &Apache::lonnet::domain($currdom);
6101: my @currinsttypes = split(',',$typestr);
6102: my ($othertitle,$usertypes,$types) =
6103: &Apache::loncommon::sorted_inst_types($currdom);
6104: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6105: $usertypes->{'any'} = &mt('any user');
6106: if (keys(%{$usertypes}) > 0) {
6107: $usertypes->{'other'} = &mt('other users');
6108: }
6109: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6110: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6111: }
6112: }
6113: $output .= '</ul>';
6114: } else {
6115: $output .= &mt('None');
6116: }
6117: }
6118: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6119: next;
6120: }
6121: my $showdomdesc = 1;
6122: my $includeempty = 1;
6123: my $num = 0;
6124: $output .= &Apache::loncommon::start_data_table().
6125: &Apache::loncommon::start_data_table_row()
6126: .'<td colspan="2"><span class="LC_nobreak"><label>'
6127: .&mt('Any user in any domain:')
6128: .' <input type="radio" name="selfenroll_all" value="1" ';
6129: if ($curr_types eq '*') {
6130: $output .= ' checked="checked" ';
6131: }
6132: $output .= 'onchange="javascript:update_types('.
6133: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
6134: ' <input type="radio" name="selfenroll_all" value="0" ';
6135: if ($curr_types ne '*') {
6136: $output .= ' checked="checked" ';
6137: }
6138: $output .= ' onchange="javascript:update_types('.
6139: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
6140: &Apache::loncommon::end_data_table_row().
6141: &Apache::loncommon::end_data_table().
6142: &mt('Or').'<br />'.
6143: &Apache::loncommon::start_data_table();
6144: my %currdoms;
6145: if ($curr_types eq '') {
6146: $output .= &new_selfenroll_dom_row($cdom,'0');
6147: } elsif ($curr_types ne '*') {
6148: my @entries = split(/;/,$curr_types);
6149: if (@entries > 0) {
6150: foreach my $entry (@entries) {
6151: my ($currdom,$typestr) = split(/:/,$entry);
6152: $currdoms{$currdom} = 1;
6153: my $domdesc = &Apache::lonnet::domain($currdom);
6154: my @currinsttypes = split(',',$typestr);
6155: $output .= &Apache::loncommon::start_data_table_row()
6156: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6157: .' '.$domdesc.' ('.$currdom.')'
6158: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6159: .'" value="'.$currdom.'" /></span><br />'
6160: .'<span class="LC_nobreak"><label><input type="checkbox" '
6161: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
6162: .&mt('Delete').'</label></span></td>';
6163: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
6164: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
6165: .&Apache::loncommon::end_data_table_row();
6166: $num ++;
6167: }
6168: }
6169: }
6170: my $add_domtitle = &mt('Users in additional domain:');
6171: if ($curr_types eq '*') {
6172: $add_domtitle = &mt('Users in specific domain:');
6173: } elsif ($curr_types eq '') {
6174: $add_domtitle = &mt('Users in other domain:');
6175: }
6176: my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$cdom);
6177: $output .= &Apache::loncommon::start_data_table_row()
6178: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6179: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
6180: $includeempty,$showdomdesc,'',$trusted,$untrusted,$readonly)
6181: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6182: .'</td>'.&Apache::loncommon::end_data_table_row()
6183: .&Apache::loncommon::end_data_table();
6184: } elsif ($item eq 'registered') {
6185: my ($regon,$regoff);
6186: my $registered;
6187: if (ref($currsettings) eq 'HASH') {
6188: $registered = $currsettings->{'selfenroll_registered'};
6189: }
6190: if ($noedit{$item}) {
6191: if ($registered) {
6192: $output .= &mt('Must be registered in course');
6193: } else {
6194: $output .= &mt('No requirement');
6195: }
6196: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6197: next;
6198: }
6199: if ($registered) {
6200: $regon = ' checked="checked" ';
6201: $regoff = '';
6202: } else {
6203: $regon = '';
6204: $regoff = ' checked="checked" ';
6205: }
6206: $output .= '<label>'.
6207: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
6208: &mt('Yes').'</label> <label>'.
6209: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
6210: &mt('No').'</label>';
6211: } elsif ($item eq 'enroll_dates') {
6212: my ($starttime,$endtime);
6213: if (ref($currsettings) eq 'HASH') {
6214: $starttime = $currsettings->{'selfenroll_start_date'};
6215: $endtime = $currsettings->{'selfenroll_end_date'};
6216: if ($starttime eq '') {
6217: $starttime = $currsettings->{'default_enrollment_start_date'};
6218: }
6219: if ($endtime eq '') {
6220: $endtime = $currsettings->{'default_enrollment_end_date'};
6221: }
6222: }
6223: if ($noedit{$item}) {
6224: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6225: &Apache::lonlocal::locallocaltime($endtime));
6226: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6227: next;
6228: }
6229: my $startform =
6230: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
6231: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
6232: my $endform =
6233: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
6234: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
6235: $output .= &selfenroll_date_forms($startform,$endform);
6236: } elsif ($item eq 'access_dates') {
6237: my ($starttime,$endtime);
6238: if (ref($currsettings) eq 'HASH') {
6239: $starttime = $currsettings->{'selfenroll_start_access'};
6240: $endtime = $currsettings->{'selfenroll_end_access'};
6241: if ($starttime eq '') {
6242: $starttime = $currsettings->{'default_enrollment_start_date'};
6243: }
6244: if ($endtime eq '') {
6245: $endtime = $currsettings->{'default_enrollment_end_date'};
6246: }
6247: }
6248: if ($noedit{$item}) {
6249: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6250: &Apache::lonlocal::locallocaltime($endtime));
6251: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6252: next;
6253: }
6254: my $startform =
6255: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
6256: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
6257: my $endform =
6258: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
6259: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
6260: $output .= &selfenroll_date_forms($startform,$endform);
6261: } elsif ($item eq 'section') {
6262: my $currsec;
6263: if (ref($currsettings) eq 'HASH') {
6264: $currsec = $currsettings->{'selfenroll_section'};
6265: }
6266: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6267: my $newsecval;
6268: if ($currsec ne 'none' && $currsec ne '') {
6269: if (!defined($sections_count{$currsec})) {
6270: $newsecval = $currsec;
6271: }
6272: }
6273: if ($noedit{$item}) {
6274: if ($currsec ne '') {
6275: $output .= $currsec;
6276: } else {
6277: $output .= &mt('No specific section');
6278: }
6279: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6280: next;
6281: }
6282: my $sections_select =
6283: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
6284: $output .= '<table class="LC_createuser">'."\n".
6285: '<tr class="LC_section_row">'."\n".
6286: '<td align="center">'.&mt('Existing sections')."\n".
6287: '<br />'.$sections_select.'</td><td align="center">'.
6288: &mt('New section').'<br />'."\n".
6289: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
6290: '<input type="hidden" name="sections" value="" />'."\n".
6291: '</td></tr></table>'."\n";
6292: } elsif ($item eq 'approval') {
6293: my ($currnotified,$currapproval,%appchecked);
6294: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
6295: if (ref($currsettings) eq 'HASH') {
6296: $currnotified = $currsettings->{'selfenroll_notifylist'};
6297: $currapproval = $currsettings->{'selfenroll_approval'};
6298: }
6299: if ($currapproval !~ /^[012]$/) {
6300: $currapproval = 0;
6301: }
6302: if ($noedit{$item}) {
6303: $output .= $selfdescs{'approval'}{$currapproval}.
6304: '<br />'.&mt('(Set by Domain Coordinator)');
6305: next;
6306: }
6307: $appchecked{$currapproval} = ' checked="checked"';
6308: for my $i (0..2) {
6309: $output .= '<label>'.
6310: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
6311: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6312: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
6313: }
6314: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6315: my (@ccs,%notified);
6316: my $ccrole = 'cc';
6317: if ($crstype eq 'Community') {
6318: $ccrole = 'co';
6319: }
6320: if ($advhash{$ccrole}) {
6321: @ccs = split(/,/,$advhash{$ccrole});
6322: }
6323: if ($currnotified) {
6324: foreach my $current (split(/,/,$currnotified)) {
6325: $notified{$current} = 1;
6326: if (!grep(/^\Q$current\E$/,@ccs)) {
6327: push(@ccs,$current);
6328: }
6329: }
6330: }
6331: if (@ccs) {
6332: my $style;
6333: unless ($currapproval) {
6334: $style = ' style="display: none;"';
6335: }
6336: $output .= '<br /><div id="notified"'.$style.'>'.
6337: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6338: &Apache::loncommon::start_data_table().
6339: &Apache::loncommon::start_data_table_row();
6340: my $count = 0;
6341: my $numcols = 4;
6342: foreach my $cc (sort(@ccs)) {
6343: my $notifyon;
6344: my ($ccuname,$ccudom) = split(/:/,$cc);
6345: if ($notified{$cc}) {
6346: $notifyon = ' checked="checked" ';
6347: }
6348: if ($count && !$count%$numcols) {
6349: $output .= &Apache::loncommon::end_data_table_row().
6350: &Apache::loncommon::start_data_table_row()
6351: }
6352: $output .= '<td><span class="LC_nobreak"><label>'.
6353: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
6354: &Apache::loncommon::plainname($ccuname,$ccudom).
6355: '</label></span></td>';
6356: $count ++;
6357: }
6358: my $rem = $count%$numcols;
6359: if ($rem) {
6360: my $emptycols = $numcols - $rem;
6361: for (my $i=0; $i<$emptycols; $i++) {
6362: $output .= '<td> </td>';
6363: }
6364: }
6365: $output .= &Apache::loncommon::end_data_table_row().
6366: &Apache::loncommon::end_data_table().
6367: '</div>';
6368: }
6369: } elsif ($item eq 'limit') {
6370: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6371: if (ref($currsettings) eq 'HASH') {
6372: $currlim = $currsettings->{'selfenroll_limit'};
6373: $currcap = $currsettings->{'selfenroll_cap'};
6374: }
6375: if ($noedit{$item}) {
6376: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6377: if ($currlim eq 'allstudents') {
6378: $output .= &mt('Limit by total students');
6379: } elsif ($currlim eq 'selfenrolled') {
6380: $output .= &mt('Limit by total self-enrolled students');
6381: }
6382: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6383: '<br />'.&mt('(Set by Domain Coordinator)');
6384: } else {
6385: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6386: }
6387: next;
6388: }
6389: if ($currlim eq 'allstudents') {
6390: $crslimit = ' checked="checked" ';
6391: $selflimit = ' ';
6392: $nolimit = ' ';
6393: } elsif ($currlim eq 'selfenrolled') {
6394: $crslimit = ' ';
6395: $selflimit = ' checked="checked" ';
6396: $nolimit = ' ';
6397: } else {
6398: $crslimit = ' ';
6399: $selflimit = ' ';
6400: $nolimit = ' checked="checked" ';
6401: }
6402: $output .= '<table><tr><td><label>'.
6403: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
6404: &mt('No limit').'</label></td><td><label>'.
6405: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
6406: &mt('Limit by total students').'</label></td><td><label>'.
6407: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
6408: &mt('Limit by total self-enrolled students').
6409: '</td></tr><tr>'.
6410: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6411: (' 'x3).&mt('Maximum number allowed: ').
6412: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
6413: }
6414: $output .= &Apache::lonhtmlcommon::row_closure(1);
6415: }
6416: }
6417: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6418: unless ($readonly) {
6419: $output .= '<input type="button" name="selfenrollconf" value="'
6420: .&mt('Save').'" onclick="validate_types(this.form);" />';
6421: }
6422: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6423: .'<input type="hidden" name="state" value="done" />'."\n"
6424: .$additional.'</form>';
6425: $r->print($output);
6426: return;
6427: }
6428:
6429: sub get_noedit_fields {
6430: my ($cdom,$cnum,$crstype,$row) = @_;
6431: my %noedit;
6432: if (ref($row) eq 'ARRAY') {
6433: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6434: 'internal.selfenrollmgrdc',
6435: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6436: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6437: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6438: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6439: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6440: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6441: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6442:
6443: foreach my $item (@{$row}) {
6444: next if ($specific_managebycc{$item});
6445: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6446: $noedit{$item} = 1;
6447: }
6448: }
6449: }
6450: return %noedit;
6451: }
6452:
6453: sub visible_in_stdcat {
6454: my ($cdom,$cnum,$domconf) = @_;
6455: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6456: unless (ref($domconf) eq 'HASH') {
6457: return ($visible,$cansetvis,\@vismsgs);
6458: }
6459: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6460: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
6461: $settable{'togglecats'} = 1;
6462: }
6463: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
6464: $settable{'categorize'} = 1;
6465: }
6466: $cathash = $domconf->{'coursecategories'}{'cats'};
6467: }
6468: if ($settable{'togglecats'} && $settable{'categorize'}) {
6469: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6470: } elsif ($settable{'togglecats'}) {
6471: $cansetvis = &mt('You are able to choose to exclude this course from the catalog, but only a Domain Coordinator may assign a course category.');
6472: } elsif ($settable{'categorize'}) {
6473: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6474: } else {
6475: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6476: }
6477:
6478: my %currsettings =
6479: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6480: $cdom,$cnum);
6481: $visible = 0;
6482: if ($currsettings{'internal.coursecode'} ne '') {
6483: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6484: $cathash = $domconf->{'coursecategories'}{'cats'};
6485: if (ref($cathash) eq 'HASH') {
6486: if ($cathash->{'instcode::0'} eq '') {
6487: push(@vismsgs,'dc_addinst');
6488: } else {
6489: $visible = 1;
6490: }
6491: } else {
6492: $visible = 1;
6493: }
6494: } else {
6495: $visible = 1;
6496: }
6497: } else {
6498: if (ref($cathash) eq 'HASH') {
6499: if ($cathash->{'instcode::0'} ne '') {
6500: push(@vismsgs,'dc_instcode');
6501: }
6502: } else {
6503: push(@vismsgs,'dc_instcode');
6504: }
6505: }
6506: if ($currsettings{'categories'} ne '') {
6507: my $cathash;
6508: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6509: $cathash = $domconf->{'coursecategories'}{'cats'};
6510: if (ref($cathash) eq 'HASH') {
6511: if (keys(%{$cathash}) == 0) {
6512: push(@vismsgs,'dc_catalog');
6513: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6514: push(@vismsgs,'dc_categories');
6515: } else {
6516: my @currcategories = split('&',$currsettings{'categories'});
6517: my $matched = 0;
6518: foreach my $cat (@currcategories) {
6519: if ($cathash->{$cat} ne '') {
6520: $visible = 1;
6521: $matched = 1;
6522: last;
6523: }
6524: }
6525: if (!$matched) {
6526: if ($settable{'categorize'}) {
6527: push(@vismsgs,'chgcat');
6528: } else {
6529: push(@vismsgs,'dc_chgcat');
6530: }
6531: }
6532: }
6533: }
6534: }
6535: } else {
6536: if (ref($cathash) eq 'HASH') {
6537: if ((keys(%{$cathash}) > 1) ||
6538: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
6539: if ($settable{'categorize'}) {
6540: push(@vismsgs,'addcat');
6541: } else {
6542: push(@vismsgs,'dc_addcat');
6543: }
6544: }
6545: }
6546: }
6547: if ($currsettings{'hidefromcat'} eq 'yes') {
6548: $visible = 0;
6549: if ($settable{'togglecats'}) {
6550: unshift(@vismsgs,'unhide');
6551: } else {
6552: unshift(@vismsgs,'dc_unhide')
6553: }
6554: }
6555: return ($visible,$cansetvis,\@vismsgs);
6556: }
6557:
6558: sub cat_visibility {
6559: my %visactions = &Apache::lonlocal::texthash(
6560: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6561: gen => 'Courses can be both self-cataloging, based on an institutional code (e.g., fs08phy231), or can be assigned categories from a hierarchy defined for the domain.',
6562: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6563: none => 'Display of a course catalog is disabled for this domain.',
6564: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6565: coca => 'Courses can be absent from the Catalog, because they do not have an institutional code, have no assigned category, or have been specifically excluded.',
6566: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6567: take => 'Take the following action to ensure the course appears in the Catalog:',
6568: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6569: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6570: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6571: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6572: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6573: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6574: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6575: dc_chgcat => 'Ask a domain coordinator to change the category assigned to the course, as the one currently assigned is no longer used in the domain',
6576: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6577: );
6578: $visactions{'unhide'} = &mt('Use [_1]Categorize course[_2] to change the "Exclude from course catalog" setting.','<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6579: $visactions{'chgcat'} = &mt('Use [_1]Categorize course[_2] to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6580: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6581: return \%visactions;
6582: }
6583:
6584: sub new_selfenroll_dom_row {
6585: my ($newdom,$num) = @_;
6586: my $domdesc = &Apache::lonnet::domain($newdom);
6587: my $output;
6588: if ($domdesc ne '') {
6589: $output .= &Apache::loncommon::start_data_table_row()
6590: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6591: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
6592: .'" value="'.$newdom.'" /></span><br />'
6593: .'<span class="LC_nobreak"><label><input type="checkbox" '
6594: .'name="selfenroll_activate" value="'.$num.'" '
6595: .'onchange="javascript:update_types('
6596: ."'selfenroll_activate','$num'".');" />'
6597: .&mt('Activate').'</label></span></td>';
6598: my @currinsttypes;
6599: $output .= '<td>'.&mt('User types:').'<br />'
6600: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6601: .&Apache::loncommon::end_data_table_row();
6602: }
6603: return $output;
6604: }
6605:
6606: sub selfenroll_inst_types {
6607: my ($num,$currdom,$currinsttypes,$readonly) = @_;
6608: my $output;
6609: my $numinrow = 4;
6610: my $count = 0;
6611: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
6612: my $othervalue = 'any';
6613: my $disabled;
6614: if ($readonly) {
6615: $disabled = ' disabled="disabled"';
6616: }
6617: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6618: if (keys(%{$usertypes}) > 0) {
6619: $othervalue = 'other';
6620: }
6621: $output .= '<table><tr>';
6622: foreach my $type (@{$types}) {
6623: if (($count > 0) && ($count%$numinrow == 0)) {
6624: $output .= '</tr><tr>';
6625: }
6626: if (defined($usertypes->{$type})) {
6627: my $esc_type = &escape($type);
6628: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
6629: $esc_type.'" ';
6630: if (ref($currinsttypes) eq 'ARRAY') {
6631: if (@{$currinsttypes} > 0) {
6632: if (grep(/^any$/,@{$currinsttypes})) {
6633: $output .= 'checked="checked"';
6634: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
6635: $output .= 'checked="checked"';
6636: }
6637: } else {
6638: $output .= 'checked="checked"';
6639: }
6640: }
6641: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
6642: }
6643: $count ++;
6644: }
6645: if (($count > 0) && ($count%$numinrow == 0)) {
6646: $output .= '</tr><tr>';
6647: }
6648: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
6649: if (ref($currinsttypes) eq 'ARRAY') {
6650: if (@{$currinsttypes} > 0) {
6651: if (grep(/^any$/,@{$currinsttypes})) {
6652: $output .= ' checked="checked"';
6653: } elsif ($othervalue eq 'other') {
6654: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6655: $output .= ' checked="checked"';
6656: }
6657: }
6658: } else {
6659: $output .= ' checked="checked"';
6660: }
6661: } else {
6662: $output .= ' checked="checked"';
6663: }
6664: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
6665: }
6666: return $output;
6667: }
6668:
6669: sub selfenroll_date_forms {
6670: my ($startform,$endform) = @_;
6671: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
6672: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
6673: 'LC_oddrow_value')."\n".
6674: $startform."\n".
6675: &Apache::lonhtmlcommon::row_closure(1).
6676: &Apache::lonhtmlcommon::row_title(&mt('End date'),
6677: 'LC_oddrow_value')."\n".
6678: $endform."\n".
6679: &Apache::lonhtmlcommon::row_closure(1).
6680: &Apache::lonhtmlcommon::end_pick_box();
6681: return $output;
6682: }
6683:
6684: sub print_userchangelogs_display {
6685: my ($r,$context,$permission,$brcrum) = @_;
6686: my $formname = 'rolelog';
6687: my ($username,$domain,$crstype,$viewablesec,%roleslog);
6688: if ($context eq 'domain') {
6689: $domain = $env{'request.role.domain'};
6690: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6691: } else {
6692: if ($context eq 'course') {
6693: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6694: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6695: $crstype = &Apache::loncommon::course_type();
6696: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
6697: my %saveable_parameters = ('show' => 'scalar',);
6698: &Apache::loncommon::store_course_settings('roles_log',
6699: \%saveable_parameters);
6700: &Apache::loncommon::restore_course_settings('roles_log',
6701: \%saveable_parameters);
6702: } elsif ($context eq 'author') {
6703: $domain = $env{'user.domain'};
6704: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6705: $username = $env{'user.name'};
6706: } else {
6707: undef($domain);
6708: }
6709: }
6710: if ($domain ne '' && $username ne '') {
6711: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6712: }
6713: }
6714: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6715:
6716: my $helpitem;
6717: if ($context eq 'course') {
6718: $helpitem = 'Course_User_Logs';
6719: } elsif ($context eq 'domain') {
6720: $helpitem = 'Domain_Role_Logs';
6721: } elsif ($context eq 'author') {
6722: $helpitem = 'Author_User_Logs';
6723: }
6724: push (@{$brcrum},
6725: {href => '/adm/createuser?action=changelogs',
6726: text => 'User Management Logs',
6727: help => $helpitem});
6728: my $bread_crumbs_component = 'User Changes';
6729: my $args = { bread_crumbs => $brcrum,
6730: bread_crumbs_component => $bread_crumbs_component};
6731:
6732: # Create navigation javascript
6733: my $jsnav = &userlogdisplay_js($formname);
6734:
6735: my $jscript = (<<ENDSCRIPT);
6736: <script type="text/javascript">
6737: // <![CDATA[
6738: $jsnav
6739: // ]]>
6740: </script>
6741: ENDSCRIPT
6742:
6743: # print page header
6744: $r->print(&header($jscript,$args));
6745:
6746: # set defaults
6747: my $now = time();
6748: my $defstart = $now - (7*24*3600); #7 days ago
6749: my %defaults = (
6750: page => '1',
6751: show => '10',
6752: role => 'any',
6753: chgcontext => 'any',
6754: rolelog_start_date => $defstart,
6755: rolelog_end_date => $now,
6756: );
6757: my $more_records = 0;
6758:
6759: # set current
6760: my %curr;
6761: foreach my $item ('show','page','role','chgcontext') {
6762: $curr{$item} = $env{'form.'.$item};
6763: }
6764: my ($startdate,$enddate) =
6765: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6766: $curr{'rolelog_start_date'} = $startdate;
6767: $curr{'rolelog_end_date'} = $enddate;
6768: foreach my $key (keys(%defaults)) {
6769: if ($curr{$key} eq '') {
6770: $curr{$key} = $defaults{$key};
6771: }
6772: }
6773: my (%whodunit,%changed,$version);
6774: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
6775: my ($minshown,$maxshown);
6776: $minshown = 1;
6777: my $count = 0;
6778: if ($curr{'show'} =~ /\D/) {
6779: $curr{'page'} = 1;
6780: } else {
6781: $maxshown = $curr{'page'} * $curr{'show'};
6782: if ($curr{'page'} > 1) {
6783: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6784: }
6785: }
6786:
6787: # Form Header
6788: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
6789: &role_display_filter($context,$formname,$domain,$username,\%curr,
6790: $version,$crstype));
6791:
6792: my $showntableheader = 0;
6793:
6794: # Table Header
6795: my $tableheader =
6796: &Apache::loncommon::start_data_table_header_row()
6797: .'<th> </th>'
6798: .'<th>'.&mt('When').'</th>'
6799: .'<th>'.&mt('Who made the change').'</th>'
6800: .'<th>'.&mt('Changed User').'</th>'
6801: .'<th>'.&mt('Role').'</th>';
6802:
6803: if ($context eq 'course') {
6804: $tableheader .= '<th>'.&mt('Section').'</th>';
6805: }
6806: $tableheader .=
6807: '<th>'.&mt('Context').'</th>'
6808: .'<th>'.&mt('Start').'</th>'
6809: .'<th>'.&mt('End').'</th>'
6810: .&Apache::loncommon::end_data_table_header_row();
6811:
6812: # Display user change log data
6813: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6814: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6815: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
6816: if ($curr{'show'} !~ /\D/) {
6817: if ($count >= $curr{'page'} * $curr{'show'}) {
6818: $more_records = 1;
6819: last;
6820: }
6821: }
6822: if ($curr{'role'} ne 'any') {
6823: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6824: }
6825: if ($curr{'chgcontext'} ne 'any') {
6826: if ($curr{'chgcontext'} eq 'selfenroll') {
6827: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6828: } else {
6829: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6830: }
6831: }
6832: if (($context eq 'course') && ($viewablesec ne '')) {
6833: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
6834: }
6835: $count ++;
6836: next if ($count < $minshown);
6837: unless ($showntableheader) {
6838: $r->print(&Apache::loncommon::start_data_table()
6839: .$tableheader);
6840: $r->rflush();
6841: $showntableheader = 1;
6842: }
6843: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6844: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6845: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6846: }
6847: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6848: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6849: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6850: }
6851: my $sec = $roleslog{$id}{'logentry'}{'section'};
6852: if ($sec eq '') {
6853: $sec = &mt('None');
6854: }
6855: my ($rolestart,$roleend);
6856: if ($roleslog{$id}{'delflag'}) {
6857: $rolestart = &mt('deleted');
6858: $roleend = &mt('deleted');
6859: } else {
6860: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6861: $roleend = $roleslog{$id}{'logentry'}{'end'};
6862: if ($rolestart eq '' || $rolestart == 0) {
6863: $rolestart = &mt('No start date');
6864: } else {
6865: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6866: }
6867: if ($roleend eq '' || $roleend == 0) {
6868: $roleend = &mt('No end date');
6869: } else {
6870: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6871: }
6872: }
6873: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6874: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6875: $chgcontext = 'selfenroll';
6876: }
6877: my %lt = &rolechg_contexts($context,$crstype);
6878: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6879: $chgcontext = $lt{$chgcontext};
6880: }
6881: $r->print(
6882: &Apache::loncommon::start_data_table_row()
6883: .'<td>'.$count.'</td>'
6884: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6885: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6886: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
6887: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6888: if ($context eq 'course') {
6889: $r->print('<td>'.$sec.'</td>');
6890: }
6891: $r->print(
6892: '<td>'.$chgcontext.'</td>'
6893: .'<td>'.$rolestart.'</td>'
6894: .'<td>'.$roleend.'</td>'
6895: .&Apache::loncommon::end_data_table_row()."\n");
6896: }
6897:
6898: if ($showntableheader) { # Table footer, if content displayed above
6899: $r->print(&Apache::loncommon::end_data_table().
6900: &userlogdisplay_navlinks(\%curr,$more_records));
6901: } else { # No content displayed above
6902: $r->print('<p class="LC_info">'
6903: .&mt('There are no records to display.')
6904: .'</p>'
6905: );
6906: }
6907:
6908: # Form Footer
6909: $r->print(
6910: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6911: .'<input type="hidden" name="action" value="changelogs" />'
6912: .'</form>');
6913: return;
6914: }
6915:
6916: sub print_useraccesslogs_display {
6917: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6918: my $formname = 'accesslog';
6919: my $form = 'document.accesslog';
6920:
6921: # set breadcrumbs
6922: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
6923: my $prevphasestr;
6924: if ($env{'form.popup'}) {
6925: $brcrum = [];
6926: } else {
6927: push (@{$brcrum},
6928: {href => "javascript:backPage($form)",
6929: text => $breadcrumb_text{'search'}});
6930: my @prevphases;
6931: if ($env{'form.prevphases'}) {
6932: @prevphases = split(/,/,$env{'form.prevphases'});
6933: $prevphasestr = $env{'form.prevphases'};
6934: }
6935: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6936: push(@{$brcrum},
6937: {href => "javascript:backPage($form,'get_user_info','select')",
6938: text => $breadcrumb_text{'userpicked'}});
6939: if ($env{'form.phase'} eq 'userpicked') {
6940: $prevphasestr = 'userpicked';
6941: }
6942: }
6943: }
6944: push(@{$brcrum},
6945: {href => '/adm/createuser?action=accesslogs',
6946: text => 'User access logs',
6947: help => 'Domain_User_Access_Logs'});
6948: my $bread_crumbs_component = 'User Access Logs';
6949: my $args = { bread_crumbs => $brcrum,
6950: bread_crumbs_component => 'User Management'};
6951: if ($env{'form.popup'}) {
6952: $args->{'no_nav_bar'} = 1;
6953: $args->{'bread_crumbs_nomenu'} = 1;
6954: }
6955:
6956: # set javascript
6957: my ($jsback,$elements) = &crumb_utilities();
6958: my $jsnav = &userlogdisplay_js($formname);
6959:
6960: my $jscript = (<<ENDSCRIPT);
6961: <script type="text/javascript">
6962: // <![CDATA[
6963:
6964: $jsback
6965: $jsnav
6966:
6967: // ]]>
6968: </script>
6969:
6970: ENDSCRIPT
6971:
6972: # print page header
6973: $r->print(&header($jscript,$args));
6974:
6975: # early out unless log data can be displayed.
6976: unless ($permission->{'activity'}) {
6977: $r->print('<p class="LC_warning">'
6978: .&mt('You do not have rights to display user access logs.')
6979: .'</p>');
6980: if ($env{'form.popup'}) {
6981: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6982: } else {
6983: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6984: }
6985: return;
6986: }
6987:
6988: unless ($udom eq $env{'request.role.domain'}) {
6989: $r->print('<p class="LC_warning">'
6990: .&mt("User's domain must match role's domain")
6991: .'</p>'
6992: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6993: return;
6994: }
6995:
6996: if (($uname eq '') || ($udom eq '')) {
6997: $r->print('<p class="LC_warning">'
6998: .&mt('Invalid username or domain')
6999: .'</p>'
7000: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7001: return;
7002: }
7003:
7004: if (&Apache::lonnet::privileged($uname,$udom,
7005: [$env{'request.role.domain'}],['dc','su'])) {
7006: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
7007: [$env{'request.role.domain'}],['dc','su'])) {
7008: $r->print('<p class="LC_warning">'
7009: .&mt('You need to be a privileged user to display user access logs for [_1]',
7010: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
7011: $uname,$udom))
7012: .'</p>');
7013: if ($env{'form.popup'}) {
7014: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7015: } else {
7016: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7017: }
7018: return;
7019: }
7020: }
7021:
7022: # set defaults
7023: my $now = time();
7024: my $defstart = $now - (7*24*3600);
7025: my %defaults = (
7026: page => '1',
7027: show => '10',
7028: activity => 'any',
7029: accesslog_start_date => $defstart,
7030: accesslog_end_date => $now,
7031: );
7032: my $more_records = 0;
7033:
7034: # set current
7035: my %curr;
7036: foreach my $item ('show','page','activity') {
7037: $curr{$item} = $env{'form.'.$item};
7038: }
7039: my ($startdate,$enddate) =
7040: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
7041: $curr{'accesslog_start_date'} = $startdate;
7042: $curr{'accesslog_end_date'} = $enddate;
7043: foreach my $key (keys(%defaults)) {
7044: if ($curr{$key} eq '') {
7045: $curr{$key} = $defaults{$key};
7046: }
7047: }
7048: my ($minshown,$maxshown);
7049: $minshown = 1;
7050: my $count = 0;
7051: if ($curr{'show'} =~ /\D/) {
7052: $curr{'page'} = 1;
7053: } else {
7054: $maxshown = $curr{'page'} * $curr{'show'};
7055: if ($curr{'page'} > 1) {
7056: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7057: }
7058: }
7059:
7060: # form header
7061: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7062: &activity_display_filter($formname,\%curr));
7063:
7064: my $showntableheader = 0;
7065: my ($nav_script,$nav_links);
7066:
7067: # table header
7068: my $tableheader = '<h3>'.
7069: &mt('User access logs for: [_1]',
7070: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>'
7071: .&Apache::loncommon::start_data_table_header_row()
7072: .'<th> </th>'
7073: .'<th>'.&mt('When').'</th>'
7074: .'<th>'.&mt('HostID').'</th>'
7075: .'<th>'.&mt('Event').'</th>'
7076: .'<th>'.&mt('Other data').'</th>'
7077: .&Apache::loncommon::end_data_table_header_row();
7078:
7079: my %filters=(
7080: start => $curr{'accesslog_start_date'},
7081: end => $curr{'accesslog_end_date'},
7082: action => $curr{'activity'},
7083: );
7084:
7085: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7086: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7087: my (%courses,%missing);
7088: my @results = split(/\&/,$reply);
7089: foreach my $item (reverse(@results)) {
7090: my ($timestamp,$host,$event) = split(/:/,$item);
7091: next unless ($event =~ /^(Log|Role)/);
7092: if ($curr{'show'} !~ /\D/) {
7093: if ($count >= $curr{'page'} * $curr{'show'}) {
7094: $more_records = 1;
7095: last;
7096: }
7097: }
7098: $count ++;
7099: next if ($count < $minshown);
7100: unless ($showntableheader) {
7101: $r->print($nav_script
7102: .&Apache::loncommon::start_data_table()
7103: .$tableheader);
7104: $r->rflush();
7105: $showntableheader = 1;
7106: }
7107: my ($shown,$extra);
7108: my ($event,$data) = split(/\s+/,&unescape($event),2);
7109: if ($event eq 'Role') {
7110: my ($rolecode,$extent) = split(/\./,$data,2);
7111: next if ($extent eq '');
7112: my ($crstype,$desc,$info);
7113: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7114: my ($cdom,$cnum,$sec) = ($1,$2,$3);
7115: my $cid = $cdom.'_'.$cnum;
7116: if (exists($courses{$cid})) {
7117: $crstype = $courses{$cid}{'type'};
7118: $desc = $courses{$cid}{'description'};
7119: } elsif ($missing{$cid}) {
7120: $crstype = 'Course';
7121: $desc = 'Course/Community';
7122: } else {
7123: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7124: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7125: $courses{$cid} = $crsinfo{$cid};
7126: $crstype = $crsinfo{$cid}{'type'};
7127: $desc = $crsinfo{$cid}{'description'};
7128: } else {
7129: $missing{$cid} = 1;
7130: }
7131: }
7132: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
7133: if ($sec ne '') {
7134: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7135: }
7136: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7137: my ($dom,$name) = ($1,$2);
7138: if ($rolecode eq 'au') {
7139: $extra = '';
7140: } elsif ($rolecode =~ /^(ca|aa)$/) {
7141: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
7142: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7143: $extra = &mt('Domain: [_1]',$dom);
7144: }
7145: }
7146: my $rolename;
7147: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7148: my $role = $3;
7149: my $owner = "($2:$1)";
7150: if ($2 eq $1.'-domainconfig') {
7151: $owner = '(ad hoc)';
7152: }
7153: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7154: } else {
7155: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7156: }
7157: $shown = &mt('Role selection: [_1]',$rolename);
7158: } else {
7159: $shown = &mt($event);
7160: if ($data =~ /^webdav/) {
7161: my ($path,$clientip) = split(/\s+/,$data,2);
7162: $path =~ s/^webdav//;
7163: if ($clientip ne '') {
7164: $extra = &mt('Client IP address: [_1]',$clientip);
7165: }
7166: if ($path ne '') {
7167: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7168: }
7169: } elsif ($data ne '') {
7170: $extra = &mt('Client IP address: [_1]',$data);
7171: }
7172: }
7173: $r->print(
7174: &Apache::loncommon::start_data_table_row()
7175: .'<td>'.$count.'</td>'
7176: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7177: .'<td>'.$host.'</td>'
7178: .'<td>'.$shown.'</td>'
7179: .'<td>'.$extra.'</td>'
7180: .&Apache::loncommon::end_data_table_row()."\n");
7181: }
7182: }
7183:
7184: if ($showntableheader) { # Table footer, if content displayed above
7185: $r->print(&Apache::loncommon::end_data_table().
7186: &userlogdisplay_navlinks(\%curr,$more_records));
7187: } else { # No content displayed above
7188: $r->print('<p class="LC_info">'
7189: .&mt('There are no records to display.')
7190: .'</p>');
7191: }
7192:
7193: if ($env{'form.popup'} == 1) {
7194: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7195: }
7196:
7197: # Form Footer
7198: $r->print(
7199: '<input type="hidden" name="currstate" value="" />'
7200: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7201: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7202: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7203: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7204: .'<input type="hidden" name="phase" value="activity" />'
7205: .'<input type="hidden" name="action" value="accesslogs" />'
7206: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7207: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7208: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7209: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7210: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7211: .'</form>');
7212: return;
7213: }
7214:
7215: sub earlyout_accesslog_form {
7216: my ($formname,$prevphasestr,$udom) = @_;
7217: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7218: return <<"END";
7219: <form action="/adm/createuser" method="post" name="$formname">
7220: <input type="hidden" name="currstate" value="" />
7221: <input type="hidden" name="prevphases" value="$prevphasestr" />
7222: <input type="hidden" name="phase" value="activity" />
7223: <input type="hidden" name="action" value="accesslogs" />
7224: <input type="hidden" name="srchdomain" value="$udom" />
7225: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7226: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7227: <input type="hidden" name="srchterm" value="$srchterm" />
7228: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7229: </form>
7230: END
7231: }
7232:
7233: sub activity_display_filter {
7234: my ($formname,$curr) = @_;
7235: my $nolink = 1;
7236: my $output = '<table><tr><td valign="top">'.
7237: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7238: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7239: (&mt('all'),5,10,20,50,100,1000,10000)).
7240: '</td><td> </td>';
7241: my $startform =
7242: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7243: $curr->{'accesslog_start_date'},undef,
7244: undef,undef,undef,undef,undef,undef,$nolink);
7245: my $endform =
7246: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7247: $curr->{'accesslog_end_date'},undef,
7248: undef,undef,undef,undef,undef,undef,$nolink);
7249: my %lt = &Apache::lonlocal::texthash (
7250: activity => 'Activity',
7251: Role => 'Role selection',
7252: log => 'Log-in or Logout',
7253: );
7254: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7255: '<table><tr><td>'.&mt('After:').
7256: '</td><td>'.$startform.'</td></tr>'.
7257: '<tr><td>'.&mt('Before:').'</td>'.
7258: '<td>'.$endform.'</td></tr></table>'.
7259: '</td>'.
7260: '<td> </td>'.
7261: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7262: '<select name="activity"><option value="any"';
7263: if ($curr->{'activity'} eq 'any') {
7264: $output .= ' selected="selected"';
7265: }
7266: $output .= '>'.&mt('Any').'</option>'."\n";
7267: foreach my $activity ('Role','log') {
7268: my $selstr = '';
7269: if ($activity eq $curr->{'activity'}) {
7270: $selstr = ' selected="selected"';
7271: }
7272: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7273: }
7274: $output .= '</select></td>'.
7275: '</tr></table>';
7276: # Update Display button
7277: $output .= '<p>'
7278: .'<input type="submit" value="'.&mt('Update Display').'" />'
7279: .'</p><hr />';
7280: return $output;
7281: }
7282:
7283: sub userlogdisplay_js {
7284: my ($formname) = @_;
7285: return <<"ENDSCRIPT";
7286:
7287: function chgPage(caller) {
7288: if (caller == 'previous') {
7289: document.$formname.page.value --;
7290: }
7291: if (caller == 'next') {
7292: document.$formname.page.value ++;
7293: }
7294: document.$formname.submit();
7295: return;
7296: }
7297: ENDSCRIPT
7298: }
7299:
7300: sub userlogdisplay_navlinks {
7301: my ($curr,$more_records) = @_;
7302: return unless(ref($curr) eq 'HASH');
7303: # Navigation Buttons
7304: my $nav_links = '<p>';
7305: if (($curr->{'page'} > 1) || ($more_records)) {
7306: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7307: $nav_links .= '<input type="button"'
7308: .' onclick="javascript:chgPage('."'previous'".');"'
7309: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7310: .'" /> ';
7311: }
7312: if ($more_records) {
7313: $nav_links .= '<input type="button"'
7314: .' onclick="javascript:chgPage('."'next'".');"'
7315: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7316: .'" />';
7317: }
7318: }
7319: $nav_links .= '</p>';
7320: return $nav_links;
7321: }
7322:
7323: sub role_display_filter {
7324: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7325: my $lctype;
7326: if ($context eq 'course') {
7327: $lctype = lc($crstype);
7328: }
7329: my $nolink = 1;
7330: my $output = '<table><tr><td valign="top">'.
7331: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
7332: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7333: (&mt('all'),5,10,20,50,100,1000,10000)).
7334: '</td><td> </td>';
7335: my $startform =
7336: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7337: $curr->{'rolelog_start_date'},undef,
7338: undef,undef,undef,undef,undef,undef,$nolink);
7339: my $endform =
7340: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7341: $curr->{'rolelog_end_date'},undef,
7342: undef,undef,undef,undef,undef,undef,$nolink);
7343: my %lt = &rolechg_contexts($context,$crstype);
7344: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7345: '<table><tr><td>'.&mt('After:').
7346: '</td><td>'.$startform.'</td></tr>'.
7347: '<tr><td>'.&mt('Before:').'</td>'.
7348: '<td>'.$endform.'</td></tr></table>'.
7349: '</td>'.
7350: '<td> </td>'.
7351: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7352: '<select name="role"><option value="any"';
7353: if ($curr->{'role'} eq 'any') {
7354: $output .= ' selected="selected"';
7355: }
7356: $output .= '>'.&mt('Any').'</option>'."\n";
7357: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
7358: foreach my $role (@roles) {
7359: my $plrole;
7360: if ($role eq 'cr') {
7361: $plrole = &mt('Custom Role');
7362: } else {
7363: $plrole=&Apache::lonnet::plaintext($role,$crstype);
7364: }
7365: my $selstr = '';
7366: if ($role eq $curr->{'role'}) {
7367: $selstr = ' selected="selected"';
7368: }
7369: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7370: }
7371: $output .= '</select></td>'.
7372: '<td> </td>'.
7373: '<td valign="top"><b>'.
7374: &mt('Context:').'</b><br /><select name="chgcontext">';
7375: my @posscontexts;
7376: if ($context eq 'course') {
7377: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
7378: } elsif ($context eq 'domain') {
7379: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7380: } else {
7381: @posscontexts = ('any','author','domain');
7382: }
7383: foreach my $chgtype (@posscontexts) {
7384: my $selstr = '';
7385: if ($curr->{'chgcontext'} eq $chgtype) {
7386: $selstr = ' selected="selected"';
7387: }
7388: if ($context eq 'course') {
7389: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
7390: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7391: }
7392: }
7393: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
7394: }
7395: $output .= '</select></td>'
7396: .'</tr></table>';
7397:
7398: # Update Display button
7399: $output .= '<p>'
7400: .'<input type="submit" value="'.&mt('Update Display').'" />'
7401: .'</p>';
7402:
7403: # Server version info
7404: my $needsrev = '2.11.0';
7405: if ($context eq 'course') {
7406: $needsrev = '2.7.0';
7407: }
7408:
7409: $output .= '<p class="LC_info">'
7410: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
7411: ,$needsrev);
7412: if ($version) {
7413: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7414: }
7415: $output .= '</p><hr />';
7416: return $output;
7417: }
7418:
7419: sub rolechg_contexts {
7420: my ($context,$crstype) = @_;
7421: my %lt;
7422: if ($context eq 'course') {
7423: %lt = &Apache::lonlocal::texthash (
7424: any => 'Any',
7425: automated => 'Automated Enrollment',
7426: updatenow => 'Roster Update',
7427: createcourse => 'Course Creation',
7428: course => 'User Management in course',
7429: domain => 'User Management in domain',
7430: selfenroll => 'Self-enrolled',
7431: requestcourses => 'Course Request',
7432: );
7433: if ($crstype eq 'Community') {
7434: $lt{'createcourse'} = &mt('Community Creation');
7435: $lt{'course'} = &mt('User Management in community');
7436: $lt{'requestcourses'} = &mt('Community Request');
7437: }
7438: } elsif ($context eq 'domain') {
7439: %lt = &Apache::lonlocal::texthash (
7440: any => 'Any',
7441: domain => 'User Management in domain',
7442: requestauthor => 'Authoring Request',
7443: server => 'Command line script (DC role)',
7444: domconfig => 'Self-enrolled',
7445: );
7446: } else {
7447: %lt = &Apache::lonlocal::texthash (
7448: any => 'Any',
7449: domain => 'User Management in domain',
7450: author => 'User Management by author',
7451: );
7452: }
7453: return %lt;
7454: }
7455:
7456: sub print_helpdeskaccess_display {
7457: my ($r,$permission,$brcrum) = @_;
7458: my $formname = 'helpdeskaccess';
7459: my $helpitem = 'Course_Helpdesk_Access';
7460: push (@{$brcrum},
7461: {href => '/adm/createuser?action=helpdesk',
7462: text => 'Helpdesk Access',
7463: help => $helpitem});
7464: my $bread_crumbs_component = 'Helpdesk Staff Access';
7465: my $args = { bread_crumbs => $brcrum,
7466: bread_crumbs_component => $bread_crumbs_component};
7467:
7468: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7469: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7470: my $confname = $cdom.'-domainconfig';
7471: my $crstype = &Apache::loncommon::course_type();
7472:
7473: my @accesstypes = ('all','dh','da','none');
7474: my ($numstatustypes,@jsarray);
7475: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7476: if (ref($types) eq 'ARRAY') {
7477: if (@{$types} > 0) {
7478: $numstatustypes = scalar(@{$types});
7479: push(@accesstypes,'status');
7480: @jsarray = ('bystatus');
7481: }
7482: }
7483: my %customroles = &get_domain_customroles($cdom,$confname);
7484: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
7485: if (keys(%domhelpdesk)) {
7486: push(@accesstypes,('inc','exc'));
7487: push(@jsarray,('notinc','notexc'));
7488: }
7489: push(@jsarray,'privs');
7490: my $hiddenstr = join("','",@jsarray);
7491: my $rolestr = join("','",sort(keys(%customroles)));
7492:
7493: my $jscript;
7494: my (%settings,%overridden);
7495: if (keys(%customroles)) {
7496: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7497: $types,\%customroles,\%settings,\%overridden);
7498: my %jsfull=();
7499: my %jslevels= (
7500: course => {},
7501: domain => {},
7502: system => {},
7503: );
7504: my %jslevelscurrent=(
7505: course => {},
7506: domain => {},
7507: system => {},
7508: );
7509: my (%privs,%jsprivs);
7510: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7511: foreach my $priv (keys(%jsfull)) {
7512: if ($jslevels{'course'}{$priv}) {
7513: $jsprivs{$priv} = 1;
7514: }
7515: }
7516: my (%elements,%stored);
7517: foreach my $role (keys(%customroles)) {
7518: $elements{$role.'_access'} = 'radio';
7519: $elements{$role.'_incrs'} = 'radio';
7520: if ($numstatustypes) {
7521: $elements{$role.'_status'} = 'checkbox';
7522: }
7523: if (keys(%domhelpdesk) > 0) {
7524: $elements{$role.'_staff_inc'} = 'checkbox';
7525: $elements{$role.'_staff_exc'} = 'checkbox';
7526: }
7527: $elements{$role.'_override'} = 'checkbox';
7528: if (ref($settings{$role}) eq 'HASH') {
7529: if ($settings{$role}{'access'} ne '') {
7530: my $curraccess = $settings{$role}{'access'};
7531: $stored{$role.'_access'} = $curraccess;
7532: $stored{$role.'_incrs'} = 1;
7533: if ($curraccess eq 'status') {
7534: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7535: $stored{$role.'_status'} = $settings{$role}{'status'};
7536: }
7537: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7538: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7539: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7540: }
7541: }
7542: } else {
7543: $stored{$role.'_incrs'} = 0;
7544: }
7545: $stored{$role.'_override'} = [];
7546: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7547: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7548: foreach my $priv (@{$settings{$role}{'off'}}) {
7549: push(@{$stored{$role.'_override'}},$priv);
7550: }
7551: }
7552: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7553: foreach my $priv (@{$settings{$role}{'on'}}) {
7554: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7555: push(@{$stored{$role.'_override'}},$priv);
7556: }
7557: }
7558: }
7559: }
7560: } else {
7561: $stored{$role.'_incrs'} = 0;
7562: }
7563: }
7564: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7565: }
7566:
7567: my $js = <<"ENDJS";
7568: <script type="text/javascript">
7569: // <![CDATA[
7570: $jscript;
7571:
7572: function switchRoleTab(caller,role) {
7573: if (document.getElementById(role+'_maindiv')) {
7574: if (caller.id != 'LC_current_minitab') {
7575: if (document.getElementById('LC_current_minitab')) {
7576: document.getElementById('LC_current_minitab').id=null;
7577: }
7578: var roledivs = Array('$rolestr');
7579: if (roledivs.length > 0) {
7580: for (var i=0; i<roledivs.length; i++) {
7581: if (document.getElementById(roledivs[i]+'_maindiv')) {
7582: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7583: }
7584: }
7585: }
7586: caller.id = 'LC_current_minitab';
7587: document.getElementById(role+'_maindiv').style.display='block';
7588: }
7589: }
7590: return false;
7591: }
7592:
7593: function helpdeskAccess(role) {
7594: var curraccess = null;
7595: if (document.$formname.elements[role+'_access'].length) {
7596: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7597: if (document.$formname.elements[role+'_access'][i].checked) {
7598: curraccess = document.$formname.elements[role+'_access'][i].value;
7599: }
7600: }
7601: }
7602: var shown = Array();
7603: var hidden = Array();
7604: if (curraccess == 'none') {
7605: hidden = Array ('$hiddenstr');
7606: } else {
7607: if (curraccess == 'status') {
7608: shown = Array ('bystatus','privs');
7609: hidden = Array ('notinc','notexc');
7610: } else {
7611: if (curraccess == 'exc') {
7612: shown = Array ('notexc','privs');
7613: hidden = Array ('notinc','bystatus');
7614: }
7615: if (curraccess == 'inc') {
7616: shown = Array ('notinc','privs');
7617: hidden = Array ('notexc','bystatus');
7618: }
7619: if (curraccess == 'all') {
7620: shown = Array ('privs');
7621: hidden = Array ('notinc','notexc','bystatus');
7622: }
7623: }
7624: }
7625: if (hidden.length > 0) {
7626: for (var i=0; i<hidden.length; i++) {
7627: if (document.getElementById(role+'_'+hidden[i])) {
7628: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
7629: }
7630: }
7631: }
7632: if (shown.length > 0) {
7633: for (var i=0; i<shown.length; i++) {
7634: if (document.getElementById(role+'_'+shown[i])) {
7635: if (shown[i] == 'privs') {
7636: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7637: } else {
7638: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7639: }
7640: }
7641: }
7642: }
7643: return;
7644: }
7645:
7646: function toggleAccess(role) {
7647: if ((document.getElementById(role+'_setincrs')) &&
7648: (document.getElementById(role+'_setindom'))) {
7649: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7650: if (document.$formname.elements[role+'_incrs'][i].checked) {
7651: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7652: document.getElementById(role+'_setindom').style.display = 'none';
7653: document.getElementById(role+'_setincrs').style.display = 'block';
7654: } else {
7655: document.getElementById(role+'_setincrs').style.display = 'none';
7656: document.getElementById(role+'_setindom').style.display = 'block';
7657: }
7658: break;
7659: }
7660: }
7661: }
7662: return;
7663: }
7664:
7665: // ]]>
7666: </script>
7667: ENDJS
7668:
7669: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7670:
7671: # print page header
7672: $r->print(&header($js,$args));
7673: # print form header
7674: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7675:
7676: if (keys(%customroles)) {
7677: my %lt = &Apache::lonlocal::texthash(
7678: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7679: 'rou' => 'Role usage',
7680: 'whi' => 'Which helpdesk personnel may use this role?',
7681: 'udd' => 'Use domain default',
7682: 'all' => 'All with domain helpdesk or helpdesk assistant role',
7683: 'dh' => 'All with domain helpdesk role',
7684: 'da' => 'All with domain helpdesk assistant role',
7685: 'none' => 'None',
7686: 'status' => 'Determined based on institutional status',
7687: 'inc' => 'Include all, but exclude specific personnel',
7688: 'exc' => 'Exclude all, but include specific personnel',
7689: 'hel' => 'Helpdesk',
7690: 'rpr' => 'Role privileges',
7691: );
7692: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7693: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7694: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7695: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7696: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7697: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7698: }
7699: }
7700: my $count = 0;
7701: foreach my $role (sort(keys(%customroles))) {
7702: my ($order,$desc,$access_in_dom);
7703: if (ref($domcurrent{$role}) eq 'HASH') {
7704: $order = $domcurrent{$role}{'order'};
7705: $desc = $domcurrent{$role}{'desc'};
7706: $access_in_dom = $domcurrent{$role}{'access'};
7707: }
7708: if ($order eq '') {
7709: $order = $count;
7710: }
7711: $ordered{$order} = $role;
7712: if ($desc ne '') {
7713: $description{$role} = $desc;
7714: } else {
7715: $description{$role}= $role;
7716: }
7717: $count++;
7718: }
7719: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7720: my @roles_by_num = ();
7721: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7722: push(@roles_by_num,$ordered{$item});
7723: }
7724: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
7725: if ($permission->{'owner'}) {
7726: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7727: $r->print('<input type="hidden" name="state" value="process" />'.
7728: '<input type="submit" value="'.&mt('Save changes').'" />');
7729: } else {
7730: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7731: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7732: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7733: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7734: }
7735: $disabled = ' disabled="disabled"';
7736: }
7737: $r->print('</p>');
7738:
7739: $r->print('<div id="LC_minitab_header"><ul>');
7740: my $count = 0;
7741: my %visibility;
7742: foreach my $role (@roles_by_num) {
7743: my $id;
7744: if ($count == 0) {
7745: $id=' id="LC_current_minitab"';
7746: $visibility{$role} = ' style="display:block"';
7747: } else {
7748: $visibility{$role} = ' style="display:none"';
7749: }
7750: $count ++;
7751: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7752: }
7753: $r->print('</ul></div>');
7754:
7755: foreach my $role (@roles_by_num) {
7756: my %usecheck = (
7757: all => ' checked="checked"',
7758: );
7759: my %displaydiv = (
7760: status => 'none',
7761: inc => 'none',
7762: exc => 'none',
7763: priv => 'block',
7764: );
7765: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
7766: if (ref($settings{$role}) eq 'HASH') {
7767: if ($settings{$role}{'access'} ne '') {
7768: $indomvis = ' style="display:none"';
7769: $incrsvis = ' style="display:block"';
7770: $incrscheck = ' checked="checked"';
7771: if ($settings{$role}{'access'} ne 'all') {
7772: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7773: delete($usecheck{'all'});
7774: if ($settings{$role}{'access'} eq 'status') {
7775: my $access = 'status';
7776: $displaydiv{$access} = 'inline';
7777: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7778: $selected{$access} = $settings{$role}{$access};
7779: }
7780: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7781: my $access = $1;
7782: $displaydiv{$access} = 'inline';
7783: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7784: $selected{$access} = $settings{$role}{$access};
7785: }
7786: } elsif ($settings{$role}{'access'} eq 'none') {
7787: $displaydiv{'priv'} = 'none';
7788: }
7789: }
7790: } else {
7791: $indomcheck = ' checked="checked"';
7792: $indomvis = ' style="display:block"';
7793: $incrsvis = ' style="display:none"';
7794: }
7795: } else {
7796: $indomcheck = ' checked="checked"';
7797: $indomvis = ' style="display:block"';
7798: $incrsvis = ' style="display:none"';
7799: }
7800: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7801: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7802: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7803: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7804: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7805: '<span>'.(' 'x2).
7806: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7807: $lt{'udd'}.'</label><span></p>'.
7808: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7809: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7810: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7811: foreach my $access (@accesstypes) {
7812: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7813: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7814: if ($access eq 'status') {
7815: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7816: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7817: $othertitle,$usertypes,$types,$disabled).
7818: '</div>');
7819: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7820: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7821: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7822: \%domhelpdesk,$disabled).
7823: '</div>');
7824: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7825: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7826: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7827: \%domhelpdesk,$disabled).
7828: '</div>');
7829: }
7830: $r->print('</p>');
7831: }
7832: $r->print('</div></fieldset>');
7833: my %full=();
7834: my %levels= (
7835: course => {},
7836: domain => {},
7837: system => {},
7838: );
7839: my %levelscurrent=(
7840: course => {},
7841: domain => {},
7842: system => {},
7843: );
7844: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7845: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7846: '<legend>'.$lt{'rpr'}.'</legend>'.
7847: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7848: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7849: }
7850: if ($permission->{'owner'}) {
7851: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7852: }
7853: } else {
7854: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7855: }
7856: # Form Footer
7857: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7858: .'</form>');
7859: return;
7860: }
7861:
7862: sub domain_adhoc_access {
7863: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7864: my %domusage;
7865: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7866: foreach my $role (keys(%{$roles})) {
7867: if (ref($domcurrent->{$role}) eq 'HASH') {
7868: my $access = $domcurrent->{$role}{'access'};
7869: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7870: $access = 'all';
7871: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7872: &Apache::lonnet::plaintext('da'));
7873: } elsif ($access eq 'status') {
7874: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7875: my @shown;
7876: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7877: unless ($type eq 'default') {
7878: if ($usertypes->{$type}) {
7879: push(@shown,$usertypes->{$type});
7880: }
7881: }
7882: }
7883: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7884: push(@shown,$othertitle);
7885: }
7886: if (@shown) {
7887: my $shownstatus = join(' '.&mt('or').' ',@shown);
7888: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7889: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
7890: } else {
7891: $domusage{$role} = &mt('No one in the domain');
7892: }
7893: }
7894: } elsif ($access eq 'inc') {
7895: my @dominc = ();
7896: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7897: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7898: my ($uname,$udom) = split(/:/,$user);
7899: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7900: }
7901: my $showninc = join(', ',@dominc);
7902: if ($showninc ne '') {
7903: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7904: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
7905: } else {
7906: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7907: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
7908: }
7909: }
7910: } elsif ($access eq 'exc') {
7911: my @domexc = ();
7912: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7913: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7914: my ($uname,$udom) = split(/:/,$user);
7915: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7916: }
7917: }
7918: my $shownexc = join(', ',@domexc);
7919: if ($shownexc ne '') {
7920: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7921: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
7922: } else {
7923: $domusage{$role} = &mt('No one in the domain');
7924: }
7925: } elsif ($access eq 'none') {
7926: $domusage{$role} = &mt('No one in the domain');
7927: } elsif ($access eq 'dh') {
7928: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
7929: } elsif ($access eq 'da') {
7930: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
7931: } elsif ($access eq 'all') {
7932: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7933: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
7934: }
7935: } else {
7936: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7937: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
7938: }
7939: }
7940: return %domusage;
7941: }
7942:
7943: sub get_domain_customroles {
7944: my ($cdom,$confname) = @_;
7945: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7946: my %customroles;
7947: foreach my $key (keys(%existing)) {
7948: if ($key=~/^rolesdef\_(\w+)$/) {
7949: my $rolename = $1;
7950: my %privs;
7951: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7952: $customroles{$rolename} = \%privs;
7953: }
7954: }
7955: return %customroles;
7956: }
7957:
7958: sub role_priv_table {
7959: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7960: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7961: (ref($levelscurrent) eq 'HASH'));
7962: my %lt=&Apache::lonlocal::texthash (
7963: 'crl' => 'Course Level Privilege',
7964: 'def' => 'Domain Defaults',
7965: 'ove' => 'Override in Course',
7966: 'ine' => 'In effect',
7967: 'dis' => 'Disabled',
7968: 'ena' => 'Enabled',
7969: );
7970: if ($crstype eq 'Community') {
7971: $lt{'ove'} = 'Override in Community',
7972: }
7973: my @status = ('Disabled','Enabled');
7974: my (%on,%off);
7975: if (ref($overridden) eq 'HASH') {
7976: if (ref($overridden->{'on'}) eq 'ARRAY') {
7977: map { $on{$_} = 1; } (@{$overridden->{'on'}});
7978: }
7979: if (ref($overridden->{'off'}) eq 'ARRAY') {
7980: map { $off{$_} = 1; } (@{$overridden->{'off'}});
7981: }
7982: }
7983: my $output=&Apache::loncommon::start_data_table().
7984: &Apache::loncommon::start_data_table_header_row().
7985: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
7986: '</th><th>'.$lt{'ine'}.'</th>'.
7987: &Apache::loncommon::end_data_table_header_row();
7988: foreach my $priv (sort(keys(%{$full}))) {
7989: next unless ($levels->{'course'}{$priv});
7990: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7991: my ($default,$ineffect);
7992: if ($levelscurrent->{'course'}{$priv}) {
7993: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7994: $ineffect = $default;
7995: }
7996: my ($customstatus,$checked);
7997: $output .= &Apache::loncommon::start_data_table_row().
7998: '<td>'.$privtext.'</td>'.
7999: '<td>'.$default.'</td><td>';
8000: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
8001: if ($permission->{'owner'}) {
8002: $checked = ' checked="checked"';
8003: }
8004: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
8005: $ineffect = $customstatus;
8006: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
8007: if ($permission->{'owner'}) {
8008: $checked = ' checked="checked"';
8009: }
8010: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8011: $ineffect = $customstatus;
8012: }
8013: if ($permission->{'owner'}) {
8014: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
8015: } else {
8016: $output .= $customstatus;
8017: }
8018: $output .= '</td><td>'.$ineffect.'</td>'.
8019: &Apache::loncommon::end_data_table_row();
8020: }
8021: $output .= &Apache::loncommon::end_data_table();
8022: return $output;
8023: }
8024:
8025: sub get_adhocrole_settings {
8026: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
8027: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
8028: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
8029: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
8030: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
8031: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
8032: $settings->{$role}{'access'} = $curraccess;
8033: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
8034: my @status = split(/,/,$rest);
8035: my @currstatus;
8036: foreach my $type (@status) {
8037: if ($type eq 'default') {
8038: push(@currstatus,$type);
8039: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8040: push(@currstatus,$type);
8041: }
8042: }
8043: if (@currstatus) {
8044: $settings->{$role}{$curraccess} = \@currstatus;
8045: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8046: my @personnel = split(/,/,$rest);
8047: $settings->{$role}{$curraccess} = \@personnel;
8048: }
8049: }
8050: }
8051: }
8052: foreach my $role (keys(%{$customroles})) {
8053: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8054: my %currentprivs;
8055: if (ref($customroles->{$role}) eq 'HASH') {
8056: if (exists($customroles->{$role}{'course'})) {
8057: my %full=();
8058: my %levels= (
8059: course => {},
8060: domain => {},
8061: system => {},
8062: );
8063: my %levelscurrent=(
8064: course => {},
8065: domain => {},
8066: system => {},
8067: );
8068: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8069: %currentprivs = %{$levelscurrent{'course'}};
8070: }
8071: }
8072: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8073: next if ($item eq '');
8074: my ($rule,$rest) = split(/=/,$item);
8075: next unless (($rule eq 'off') || ($rule eq 'on'));
8076: foreach my $priv (split(/:/,$rest)) {
8077: if ($priv ne '') {
8078: if ($rule eq 'off') {
8079: push(@{$overridden->{$role}{'off'}},$priv);
8080: if ($currentprivs{$priv}) {
8081: push(@{$settings->{$role}{'off'}},$priv);
8082: }
8083: } else {
8084: push(@{$overridden->{$role}{'on'}},$priv);
8085: unless ($currentprivs{$priv}) {
8086: push(@{$settings->{$role}{'on'}},$priv);
8087: }
8088: }
8089: }
8090: }
8091: }
8092: }
8093: }
8094: return;
8095: }
8096:
8097: sub update_helpdeskaccess {
8098: my ($r,$permission,$brcrum) = @_;
8099: my $helpitem = 'Course_Helpdesk_Access';
8100: push (@{$brcrum},
8101: {href => '/adm/createuser?action=helpdesk',
8102: text => 'Helpdesk Access',
8103: help => $helpitem},
8104: {href => '/adm/createuser?action=helpdesk',
8105: text => 'Result',
8106: help => $helpitem}
8107: );
8108: my $bread_crumbs_component = 'Helpdesk Staff Access';
8109: my $args = { bread_crumbs => $brcrum,
8110: bread_crumbs_component => $bread_crumbs_component};
8111:
8112: # print page header
8113: $r->print(&header('',$args));
8114: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8115: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8116: return;
8117: }
8118: my @accesstypes = ('all','dh','da','none','status','inc','exc');
8119: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8120: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8121: my $confname = $cdom.'-domainconfig';
8122: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8123: my $crstype = &Apache::loncommon::course_type();
8124: my %customroles = &get_domain_customroles($cdom,$confname);
8125: my (%settings,%overridden);
8126: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8127: $types,\%customroles,\%settings,\%overridden);
8128: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
8129: my (%changed,%storehash,@todelete);
8130:
8131: if (keys(%customroles)) {
8132: my (%newsettings,@incrs);
8133: foreach my $role (keys(%customroles)) {
8134: $newsettings{$role} = {
8135: access => '',
8136: status => '',
8137: exc => '',
8138: inc => '',
8139: on => '',
8140: off => '',
8141: };
8142: my %current;
8143: if (ref($settings{$role}) eq 'HASH') {
8144: %current = %{$settings{$role}};
8145: }
8146: if (ref($overridden{$role}) eq 'HASH') {
8147: $current{'overridden'} = $overridden{$role};
8148: }
8149: if ($env{'form.'.$role.'_incrs'}) {
8150: my $access = $env{'form.'.$role.'_access'};
8151: if (grep(/^\Q$access\E$/,@accesstypes)) {
8152: push(@incrs,$role);
8153: unless ($current{'access'} eq $access) {
8154: $changed{$role}{'access'} = 1;
8155: $storehash{'internal.adhoc.'.$role} = $access;
8156: }
8157: if ($access eq 'status') {
8158: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8159: my @stored;
8160: my @shownstatus;
8161: if (ref($types) eq 'ARRAY') {
8162: foreach my $type (sort(@statuses)) {
8163: if ($type eq 'default') {
8164: push(@stored,$type);
8165: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8166: push(@stored,$type);
8167: push(@shownstatus,$usertypes->{$type});
8168: }
8169: }
8170: if (grep(/^default$/,@statuses)) {
8171: push(@shownstatus,$othertitle);
8172: }
8173: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8174: }
8175: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8176: if (ref($current{'status'}) eq 'ARRAY') {
8177: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8178: if (@diffs) {
8179: $changed{$role}{'status'} = 1;
8180: }
8181: } elsif (@stored) {
8182: $changed{$role}{'status'} = 1;
8183: }
8184: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8185: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8186: my @newspecstaff;
8187: my @stored;
8188: my @currstaff;
8189: foreach my $person (sort(@personnel)) {
8190: if ($domhelpdesk{$person}) {
8191: push(@stored,$person);
8192: }
8193: }
8194: if (ref($current{$access}) eq 'ARRAY') {
8195: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8196: if (@diffs) {
8197: $changed{$role}{$access} = 1;
8198: }
8199: } elsif (@stored) {
8200: $changed{$role}{$access} = 1;
8201: }
8202: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8203: foreach my $person (@stored) {
8204: my ($uname,$udom) = split(/:/,$person);
8205: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8206: }
8207: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8208: }
8209: $newsettings{$role}{'access'} = $access;
8210: }
8211: } else {
8212: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8213: $changed{$role}{'access'} = 1;
8214: $newsettings{$role} = {};
8215: push(@todelete,'internal.adhoc.'.$role);
8216: }
8217: }
8218: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8219: if (ref($current{'overridden'}) eq 'HASH') {
8220: push(@todelete,'internal.adhocpriv.'.$role);
8221: }
8222: } else {
8223: my %full=();
8224: my %levels= (
8225: course => {},
8226: domain => {},
8227: system => {},
8228: );
8229: my %levelscurrent=(
8230: course => {},
8231: domain => {},
8232: system => {},
8233: );
8234: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8235: my (@updatedon,@updatedoff,@override);
8236: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
8237: if (@override) {
8238: foreach my $priv (sort(keys(%full))) {
8239: next unless ($levels{'course'}{$priv});
8240: if (grep(/^\Q$priv\E$/,@override)) {
8241: if ($levelscurrent{'course'}{$priv}) {
8242: push(@updatedoff,$priv);
8243: } else {
8244: push(@updatedon,$priv);
8245: }
8246: }
8247: }
8248: }
8249: if (@updatedon) {
8250: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
8251: }
8252: if (@updatedoff) {
8253: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8254: }
8255: if (ref($current{'overridden'}) eq 'HASH') {
8256: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8257: if (@updatedon) {
8258: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8259: if (@diffs) {
8260: $changed{$role}{'on'} = 1;
8261: }
8262: } else {
8263: $changed{$role}{'on'} = 1;
8264: }
8265: } elsif (@updatedon) {
8266: $changed{$role}{'on'} = 1;
8267: }
8268: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8269: if (@updatedoff) {
8270: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8271: if (@diffs) {
8272: $changed{$role}{'off'} = 1;
8273: }
8274: } else {
8275: $changed{$role}{'off'} = 1;
8276: }
8277: } elsif (@updatedoff) {
8278: $changed{$role}{'off'} = 1;
8279: }
8280: } else {
8281: if (@updatedon) {
8282: $changed{$role}{'on'} = 1;
8283: }
8284: if (@updatedoff) {
8285: $changed{$role}{'off'} = 1;
8286: }
8287: }
8288: if (ref($changed{$role}) eq 'HASH') {
8289: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8290: my $newpriv;
8291: if (@updatedon) {
8292: $newpriv = 'on='.join(':',@updatedon);
8293: }
8294: if (@updatedoff) {
8295: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8296: }
8297: if ($newpriv eq '') {
8298: push(@todelete,'internal.adhocpriv.'.$role);
8299: } else {
8300: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8301: }
8302: }
8303: }
8304: }
8305: }
8306: if (@incrs) {
8307: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8308: } elsif (@todelete) {
8309: push(@todelete,'internal.adhocaccess');
8310: }
8311: if (keys(%changed)) {
8312: my ($putres,$delres);
8313: if (keys(%storehash)) {
8314: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8315: my %newenvhash;
8316: foreach my $key (keys(%storehash)) {
8317: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8318: }
8319: &Apache::lonnet::appenv(\%newenvhash);
8320: }
8321: if (@todelete) {
8322: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8323: foreach my $key (@todelete) {
8324: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8325: }
8326: }
8327: if (($putres eq 'ok') || ($delres eq 'ok')) {
8328: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8329: my (%domcurrent,%ordered,%description,%domusage);
8330: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8331: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8332: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8333: }
8334: }
8335: my $count = 0;
8336: foreach my $role (sort(keys(%customroles))) {
8337: my ($order,$desc);
8338: if (ref($domcurrent{$role}) eq 'HASH') {
8339: $order = $domcurrent{$role}{'order'};
8340: $desc = $domcurrent{$role}{'desc'};
8341: }
8342: if ($order eq '') {
8343: $order = $count;
8344: }
8345: $ordered{$order} = $role;
8346: if ($desc ne '') {
8347: $description{$role} = $desc;
8348: } else {
8349: $description{$role}= $role;
8350: }
8351: $count++;
8352: }
8353: my @roles_by_num = ();
8354: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8355: push(@roles_by_num,$ordered{$item});
8356: }
8357: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8358: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
8359: $r->print('<ul>');
8360: foreach my $role (@roles_by_num) {
8361: next unless (ref($changed{$role}) eq 'HASH');
8362: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8363: '<ul>');
8364: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
8365: $r->print('<li>');
8366: if ($env{'form.'.$role.'_incrs'}) {
8367: if ($newsettings{$role}{'access'} eq 'all') {
8368: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
8369: } elsif ($newsettings{$role}{'access'} eq 'dh') {
8370: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8371: &Apache::lonnet::plaintext('dh')));
8372: } elsif ($newsettings{$role}{'access'} eq 'da') {
8373: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8374: &Apache::lonnet::plaintext('da')));
8375: } elsif ($newsettings{$role}{'access'} eq 'none') {
8376: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8377: } elsif ($newsettings{$role}{'access'} eq 'status') {
8378: if ($newsettings{$role}{'status'}) {
8379: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
8380: if (split(/,/,$rest) > 1) {
8381: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8382: $newsettings{$role}{'status'}));
8383: } else {
8384: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8385: $newsettings{$role}{'status'}));
8386: }
8387: } else {
8388: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8389: }
8390: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8391: if ($newsettings{$role}{'exc'}) {
8392: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8393: } else {
8394: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8395: }
8396: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8397: if ($newsettings{$role}{'inc'}) {
8398: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8399: } else {
8400: $r->print(&mt('All helpdesk staff may use this role.'));
8401: }
8402: }
8403: } else {
8404: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8405: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8406: }
8407: $r->print('</li>');
8408: }
8409: unless ($newsettings{$role}{'access'} eq 'none') {
8410: if ($changed{$role}{'off'}) {
8411: if ($newsettings{$role}{'off'}) {
8412: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8413: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8414: } else {
8415: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
8416: }
8417: }
8418: if ($changed{$role}{'on'}) {
8419: if ($newsettings{$role}{'on'}) {
8420: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8421: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8422: } else {
8423: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
8424: }
8425: }
8426: }
8427: $r->print('</ul></li>');
8428: }
8429: $r->print('</ul>');
8430: }
8431: } else {
8432: $r->print(&mt('No changes made to helpdesk access settings.'));
8433: }
8434: }
8435: return;
8436: }
8437:
8438: #-------------------------------------------------- functions for &phase_two
8439: sub user_search_result {
8440: my ($context,$srch) = @_;
8441: my %allhomes;
8442: my %inst_matches;
8443: my %srch_results;
8444: my ($response,$currstate,$forcenewuser,$dirsrchres);
8445: $srch->{'srchterm'} =~ s/\s+/ /g;
8446: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
8447: $response = &mt('Invalid search.');
8448: }
8449: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8450: $response = &mt('Invalid search.');
8451: }
8452: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
8453: $response = &mt('Invalid search.');
8454: }
8455: if ($srch->{'srchterm'} eq '') {
8456: $response = &mt('You must enter a search term.');
8457: }
8458: if ($srch->{'srchterm'} =~ /^\s+$/) {
8459: $response = &mt('Your search term must contain more than just spaces.');
8460: }
8461: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8462: if (($srch->{'srchdomain'} eq '') ||
8463: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
8464: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8465: }
8466: }
8467: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8468: ($srch->{'srchin'} eq 'alc')) {
8469: if ($srch->{'srchby'} eq 'uname') {
8470: my $unamecheck = $srch->{'srchterm'};
8471: if ($srch->{'srchtype'} eq 'contains') {
8472: if ($unamecheck !~ /^\w/) {
8473: $unamecheck = 'a'.$unamecheck;
8474: }
8475: }
8476: if ($unamecheck !~ /^$match_username$/) {
8477: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8478: }
8479: }
8480: }
8481: if ($response ne '') {
8482: $response = '<span class="LC_warning">'.$response.'</span><br />';
8483: }
8484: if ($srch->{'srchin'} eq 'instd') {
8485: my $instd_chk = &instdirectorysrch_check($srch);
8486: if ($instd_chk ne 'ok') {
8487: my $domd_chk = &domdirectorysrch_check($srch);
8488: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
8489: if ($domd_chk eq 'ok') {
8490: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
8491: }
8492: $response .= '<br />';
8493: }
8494: } else {
8495: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
8496: my $domd_chk = &domdirectorysrch_check($srch);
8497: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
8498: my $instd_chk = &instdirectorysrch_check($srch);
8499: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
8500: if ($instd_chk eq 'ok') {
8501: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
8502: }
8503: $response .= '<br />';
8504: }
8505: }
8506: }
8507: if ($response ne '') {
8508: return ($currstate,$response);
8509: }
8510: if ($srch->{'srchby'} eq 'uname') {
8511: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8512: if ($env{'form.forcenew'}) {
8513: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8514: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8515: if ($uhome eq 'no_host') {
8516: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
8517: my $showdom = &display_domain_info($env{'request.role.domain'});
8518: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
8519: } else {
8520: $currstate = 'modify';
8521: }
8522: } else {
8523: $currstate = 'modify';
8524: }
8525: } else {
8526: if ($srch->{'srchin'} eq 'dom') {
8527: if ($srch->{'srchtype'} eq 'exact') {
8528: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8529: if ($uhome eq 'no_host') {
8530: ($currstate,$response,$forcenewuser) =
8531: &build_search_response($context,$srch,%srch_results);
8532: } else {
8533: $currstate = 'modify';
8534: if ($env{'form.action'} eq 'accesslogs') {
8535: $currstate = 'activity';
8536: }
8537: my $uname = $srch->{'srchterm'};
8538: my $udom = $srch->{'srchdomain'};
8539: $srch_results{$uname.':'.$udom} =
8540: { &Apache::lonnet::get('environment',
8541: ['firstname',
8542: 'lastname',
8543: 'permanentemail'],
8544: $udom,$uname)
8545: };
8546: }
8547: } else {
8548: %srch_results = &Apache::lonnet::usersearch($srch);
8549: ($currstate,$response,$forcenewuser) =
8550: &build_search_response($context,$srch,%srch_results);
8551: }
8552: } else {
8553: my $courseusers = &get_courseusers();
8554: if ($srch->{'srchtype'} eq 'exact') {
8555: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
8556: $currstate = 'modify';
8557: } else {
8558: ($currstate,$response,$forcenewuser) =
8559: &build_search_response($context,$srch,%srch_results);
8560: }
8561: } else {
8562: foreach my $user (keys(%$courseusers)) {
8563: my ($cuname,$cudomain) = split(/:/,$user);
8564: if ($cudomain eq $srch->{'srchdomain'}) {
8565: my $matched = 0;
8566: if ($srch->{'srchtype'} eq 'begins') {
8567: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8568: $matched = 1;
8569: }
8570: } else {
8571: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8572: $matched = 1;
8573: }
8574: }
8575: if ($matched) {
8576: $srch_results{$user} =
8577: {&Apache::lonnet::get('environment',
8578: ['firstname',
8579: 'lastname',
8580: 'permanentemail'],
8581: $cudomain,$cuname)};
8582: }
8583: }
8584: }
8585: ($currstate,$response,$forcenewuser) =
8586: &build_search_response($context,$srch,%srch_results);
8587: }
8588: }
8589: }
8590: } elsif ($srch->{'srchin'} eq 'alc') {
8591: $currstate = 'query';
8592: } elsif ($srch->{'srchin'} eq 'instd') {
8593: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8594: if ($dirsrchres eq 'ok') {
8595: ($currstate,$response,$forcenewuser) =
8596: &build_search_response($context,$srch,%srch_results);
8597: } else {
8598: my $showdom = &display_domain_info($srch->{'srchdomain'});
8599: $response = '<span class="LC_warning">'.
8600: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8601: '</span><br />'.
8602: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
8603: '<br />';
8604: }
8605: }
8606: } else {
8607: if ($srch->{'srchin'} eq 'dom') {
8608: %srch_results = &Apache::lonnet::usersearch($srch);
8609: ($currstate,$response,$forcenewuser) =
8610: &build_search_response($context,$srch,%srch_results);
8611: } elsif ($srch->{'srchin'} eq 'crs') {
8612: my $courseusers = &get_courseusers();
8613: foreach my $user (keys(%$courseusers)) {
8614: my ($uname,$udom) = split(/:/,$user);
8615: my %names = &Apache::loncommon::getnames($uname,$udom);
8616: my %emails = &Apache::loncommon::getemails($uname,$udom);
8617: if ($srch->{'srchby'} eq 'lastname') {
8618: if ((($srch->{'srchtype'} eq 'exact') &&
8619: ($names{'lastname'} eq $srch->{'srchterm'})) ||
8620: (($srch->{'srchtype'} eq 'begins') &&
8621: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
8622: (($srch->{'srchtype'} eq 'contains') &&
8623: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8624: $srch_results{$user} = {firstname => $names{'firstname'},
8625: lastname => $names{'lastname'},
8626: permanentemail => $emails{'permanentemail'},
8627: };
8628: }
8629: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8630: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
8631: $srchlast =~ s/\s+$//;
8632: $srchfirst =~ s/^\s+//;
8633: if ($srch->{'srchtype'} eq 'exact') {
8634: if (($names{'lastname'} eq $srchlast) &&
8635: ($names{'firstname'} eq $srchfirst)) {
8636: $srch_results{$user} = {firstname => $names{'firstname'},
8637: lastname => $names{'lastname'},
8638: permanentemail => $emails{'permanentemail'},
8639:
8640: };
8641: }
8642: } elsif ($srch->{'srchtype'} eq 'begins') {
8643: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8644: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8645: $srch_results{$user} = {firstname => $names{'firstname'},
8646: lastname => $names{'lastname'},
8647: permanentemail => $emails{'permanentemail'},
8648: };
8649: }
8650: } else {
8651: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8652: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8653: $srch_results{$user} = {firstname => $names{'firstname'},
8654: lastname => $names{'lastname'},
8655: permanentemail => $emails{'permanentemail'},
8656: };
8657: }
8658: }
8659: }
8660: }
8661: ($currstate,$response,$forcenewuser) =
8662: &build_search_response($context,$srch,%srch_results);
8663: } elsif ($srch->{'srchin'} eq 'alc') {
8664: $currstate = 'query';
8665: } elsif ($srch->{'srchin'} eq 'instd') {
8666: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8667: if ($dirsrchres eq 'ok') {
8668: ($currstate,$response,$forcenewuser) =
8669: &build_search_response($context,$srch,%srch_results);
8670: } else {
8671: my $showdom = &display_domain_info($srch->{'srchdomain'});
8672: $response = '<span class="LC_warning">'.
8673: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8674: '</span><br />'.
8675: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
8676: '<br />';
8677: }
8678: }
8679: }
8680: return ($currstate,$response,$forcenewuser,\%srch_results);
8681: }
8682:
8683: sub domdirectorysrch_check {
8684: my ($srch) = @_;
8685: my $response;
8686: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8687: ['directorysrch'],$srch->{'srchdomain'});
8688: my $showdom = &display_domain_info($srch->{'srchdomain'});
8689: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8690: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8691: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8692: }
8693: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8694: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8695: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8696: }
8697: }
8698: }
8699: return 'ok';
8700: }
8701:
8702: sub instdirectorysrch_check {
8703: my ($srch) = @_;
8704: my $can_search = 0;
8705: my $response;
8706: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8707: ['directorysrch'],$srch->{'srchdomain'});
8708: my $showdom = &display_domain_info($srch->{'srchdomain'});
8709: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8710: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
8711: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
8712: }
8713: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8714: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8715: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8716: }
8717: my @usertypes = split(/:/,$env{'environment.inststatus'});
8718: if (!@usertypes) {
8719: push(@usertypes,'default');
8720: }
8721: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8722: foreach my $type (@usertypes) {
8723: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8724: $can_search = 1;
8725: last;
8726: }
8727: }
8728: }
8729: if (!$can_search) {
8730: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8731: my @longtypes;
8732: foreach my $item (@usertypes) {
8733: if (defined($insttypes->{$item})) {
8734: push (@longtypes,$insttypes->{$item});
8735: } elsif ($item eq 'default') {
8736: push (@longtypes,&mt('other'));
8737: }
8738: }
8739: my $insttype_str = join(', ',@longtypes);
8740: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
8741: }
8742: } else {
8743: $can_search = 1;
8744: }
8745: } else {
8746: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
8747: }
8748: my %longtext = &Apache::lonlocal::texthash (
8749: uname => 'username',
8750: lastfirst => 'last name, first name',
8751: lastname => 'last name',
8752: contains => 'contains',
8753: exact => 'as exact match to',
8754: begins => 'begins with',
8755: );
8756: if ($can_search) {
8757: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8758: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
8759: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
8760: }
8761: } else {
8762: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
8763: }
8764: }
8765: if ($can_search) {
8766: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8767: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8768: return 'ok';
8769: } else {
8770: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
8771: }
8772: } else {
8773: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8774: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8775: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8776: return 'ok';
8777: } else {
8778: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
8779: }
8780: }
8781: }
8782: }
8783:
8784: sub get_courseusers {
8785: my %advhash;
8786: my $classlist = &Apache::loncoursedata::get_classlist();
8787: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8788: foreach my $role (sort(keys(%coursepersonnel))) {
8789: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
8790: if (!exists($classlist->{$user})) {
8791: $classlist->{$user} = [];
8792: }
8793: }
8794: }
8795: return $classlist;
8796: }
8797:
8798: sub build_search_response {
8799: my ($context,$srch,%srch_results) = @_;
8800: my ($currstate,$response,$forcenewuser);
8801: my %names = (
8802: 'uname' => 'username',
8803: 'lastname' => 'last name',
8804: 'lastfirst' => 'last name, first name',
8805: 'crs' => 'this course',
8806: 'dom' => 'LON-CAPA domain',
8807: 'instd' => 'the institutional directory for domain',
8808: );
8809:
8810: my %single = (
8811: begins => 'A match',
8812: contains => 'A match',
8813: exact => 'An exact match',
8814: );
8815: my %nomatch = (
8816: begins => 'No match',
8817: contains => 'No match',
8818: exact => 'No exact match',
8819: );
8820: if (keys(%srch_results) > 1) {
8821: $currstate = 'select';
8822: } else {
8823: if (keys(%srch_results) == 1) {
8824: if ($env{'form.action'} eq 'accesslogs') {
8825: $currstate = 'activity';
8826: } else {
8827: $currstate = 'modify';
8828: }
8829: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8830: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
8831: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
8832: }
8833: } else { # Search has nothing found. Prepare message to user.
8834: $response = '<span class="LC_warning">';
8835: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
8836: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8837: '<b>'.$srch->{'srchterm'}.'</b>',
8838: &display_domain_info($srch->{'srchdomain'}));
8839: } else {
8840: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8841: '<b>'.$srch->{'srchterm'}.'</b>');
8842: }
8843: $response .= '</span>';
8844:
8845: if ($srch->{'srchin'} ne 'alc') {
8846: $forcenewuser = 1;
8847: my $cansrchinst = 0;
8848: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
8849: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8850: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8851: if ($domconfig{'directorysrch'}{'available'}) {
8852: $cansrchinst = 1;
8853: }
8854: }
8855: }
8856: if ((($srch->{'srchby'} eq 'lastfirst') ||
8857: ($srch->{'srchby'} eq 'lastname')) &&
8858: ($srch->{'srchin'} eq 'dom')) {
8859: if ($cansrchinst) {
8860: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
8861: }
8862: }
8863: if ($srch->{'srchin'} eq 'crs') {
8864: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8865: }
8866: }
8867: my $createdom = $env{'request.role.domain'};
8868: if ($context eq 'requestcrs') {
8869: if ($env{'form.coursedom'} ne '') {
8870: $createdom = $env{'form.coursedom'};
8871: }
8872: }
8873: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8874: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
8875: my $cancreate =
8876: &Apache::lonuserutils::can_create_user($createdom,$context);
8877: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
8878: if ($cancreate) {
8879: my $showdom = &display_domain_info($createdom);
8880: $response .= '<br /><br />'
8881: .'<b>'.&mt('To add a new user:').'</b>'
8882: .'<br />';
8883: if ($context eq 'requestcrs') {
8884: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8885: } else {
8886: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8887: }
8888: $response .='<ul><li>'
8889: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8890: .'</li><li>'
8891: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8892: .'</li><li>'
8893: .&mt('Provide the proposed username')
8894: .'</li><li>'
8895: .&mt("Click 'Search'")
8896: .'</li></ul><br />';
8897: } else {
8898: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8899: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8900: $response .= '<br /><br />';
8901: if ($context eq 'requestcrs') {
8902: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8903: } else {
8904: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8905: }
8906: $response .= '<br />'
8907: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8908: ,' <a'.$helplink.'>'
8909: ,'</a>')
8910: .'<br />';
8911: }
8912: }
8913: }
8914: }
8915: }
8916: return ($currstate,$response,$forcenewuser);
8917: }
8918:
8919: sub display_domain_info {
8920: my ($dom) = @_;
8921: my $output = $dom;
8922: if ($dom ne '') {
8923: my $domdesc = &Apache::lonnet::domain($dom,'description');
8924: if ($domdesc ne '') {
8925: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8926: }
8927: }
8928: return $output;
8929: }
8930:
8931: sub crumb_utilities {
8932: my %elements = (
8933: crtuser => {
8934: srchterm => 'text',
8935: srchin => 'selectbox',
8936: srchby => 'selectbox',
8937: srchtype => 'selectbox',
8938: srchdomain => 'selectbox',
8939: },
8940: crtusername => {
8941: srchterm => 'text',
8942: srchdomain => 'selectbox',
8943: },
8944: docustom => {
8945: rolename => 'selectbox',
8946: newrolename => 'textbox',
8947: },
8948: studentform => {
8949: srchterm => 'text',
8950: srchin => 'selectbox',
8951: srchby => 'selectbox',
8952: srchtype => 'selectbox',
8953: srchdomain => 'selectbox',
8954: },
8955: );
8956:
8957: my $jsback .= qq|
8958: function backPage(formname,prevphase,prevstate) {
8959: if (typeof prevphase == 'undefined') {
8960: formname.phase.value = '';
8961: }
8962: else {
8963: formname.phase.value = prevphase;
8964: }
8965: if (typeof prevstate == 'undefined') {
8966: formname.currstate.value = '';
8967: }
8968: else {
8969: formname.currstate.value = prevstate;
8970: }
8971: formname.submit();
8972: }
8973: |;
8974: return ($jsback,\%elements);
8975: }
8976:
8977: sub course_level_table {
8978: my ($inccourses,$showcredits,$defaultcredits) = @_;
8979: return unless (ref($inccourses) eq 'HASH');
8980: my $table = '';
8981: # Custom Roles?
8982:
8983: my %customroles=&Apache::lonuserutils::my_custom_roles();
8984: my %lt=&Apache::lonlocal::texthash(
8985: 'exs' => "Existing sections",
8986: 'new' => "Define new section",
8987: 'ssd' => "Set Start Date",
8988: 'sed' => "Set End Date",
8989: 'crl' => "Course Level",
8990: 'act' => "Activate",
8991: 'rol' => "Role",
8992: 'ext' => "Extent",
8993: 'grs' => "Section",
8994: 'crd' => "Credits",
8995: 'sta' => "Start",
8996: 'end' => "End"
8997: );
8998:
8999: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
9000: my $thiscourse=$protectedcourse;
9001: $thiscourse=~s:_:/:g;
9002: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
9003: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
9004: my $area=$coursedata{'description'};
9005: my $crstype=$coursedata{'type'};
9006: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
9007: my ($domain,$cnum)=split(/\//,$thiscourse);
9008: my %sections_count;
9009: if (defined($env{'request.course.id'})) {
9010: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
9011: %sections_count =
9012: &Apache::loncommon::get_sections($domain,$cnum);
9013: }
9014: }
9015: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
9016: foreach my $role (@roles) {
9017: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
9018: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
9019: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
9020: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
9021: $plrole,\%sections_count,\%lt,
9022: $showcredits,$defaultcredits,$crstype);
9023: } elsif ($env{'request.course.sec'} ne '') {
9024: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
9025: $env{'request.course.sec'})) {
9026: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
9027: $plrole,\%sections_count,\%lt,
9028: $showcredits,$defaultcredits,$crstype);
9029: }
9030: }
9031: }
9032: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
9033: foreach my $cust (sort(keys(%customroles))) {
9034: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
9035: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
9036: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
9037: $cust,\%sections_count,\%lt,
9038: $showcredits,$defaultcredits,$crstype);
9039: }
9040: }
9041: }
9042: return '' if ($table eq ''); # return nothing if there is nothing
9043: # in the table
9044: my $result;
9045: if (!$env{'request.course.id'}) {
9046: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9047: }
9048: $result .=
9049: &Apache::loncommon::start_data_table().
9050: &Apache::loncommon::start_data_table_header_row().
9051: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
9052: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9053: if ($showcredits) {
9054: $result .= $lt{'crd'}.'</th>';
9055: }
9056: $result .=
9057: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9058: '<th>'.$lt{'end'}.'</th>'.
9059: &Apache::loncommon::end_data_table_header_row().
9060: $table.
9061: &Apache::loncommon::end_data_table();
9062: return $result;
9063: }
9064:
9065: sub course_level_row {
9066: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
9067: $lt,$showcredits,$defaultcredits,$crstype) = @_;
9068: my $creditem;
9069: my $row = &Apache::loncommon::start_data_table_row().
9070: ' <td><input type="checkbox" name="act_'.
9071: $protectedcourse.'_'.$role.'" /></td>'."\n".
9072: ' <td>'.$plrole.'</td>'."\n".
9073: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
9074: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
9075: $row .=
9076: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9077: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9078: } else {
9079: $row .= '<td> </td>';
9080: }
9081: if (($role eq 'cc') || ($role eq 'co')) {
9082: $row .= '<td> </td>';
9083: } elsif ($env{'request.course.sec'} ne '') {
9084: $row .= ' <td><input type="hidden" value="'.
9085: $env{'request.course.sec'}.'" '.
9086: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9087: $env{'request.course.sec'}.'</td>';
9088: } else {
9089: if (ref($sections_count) eq 'HASH') {
9090: my $currsec =
9091: &Apache::lonuserutils::course_sections($sections_count,
9092: $protectedcourse.'_'.$role);
9093: $row .= '<td><table class="LC_createuser">'."\n".
9094: '<tr class="LC_section_row">'."\n".
9095: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9096: $currsec.'</td>'."\n".
9097: ' <td> </td>'."\n".
9098: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
9099: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9100: '" value="" />'.
9101: '<input type="hidden" '.
9102: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
9103: '</tr></table></td>'."\n";
9104: } else {
9105: $row .= '<td><input type="text" size="10" '.
9106: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
9107: }
9108: }
9109: $row .= <<ENDTIMEENTRY;
9110: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
9111: <a href=
9112: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$role.value,'start_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'ssd'}</a></td>
9113: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
9114: <a href=
9115: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9116: ENDTIMEENTRY
9117: $row .= &Apache::loncommon::end_data_table_row();
9118: return $row;
9119: }
9120:
9121: sub course_level_dc {
9122: my ($dcdom,$showcredits) = @_;
9123: my %customroles=&Apache::lonuserutils::my_custom_roles();
9124: my @roles = &Apache::lonuserutils::roles_by_context('course');
9125: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9126: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
9127: '<input type="hidden" name="dccourse" value="" />';
9128: my $courseform=&Apache::loncommon::selectcourse_link
9129: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
9130: my $credit_elem;
9131: if ($showcredits) {
9132: $credit_elem = 'credits';
9133: }
9134: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
9135: my %lt=&Apache::lonlocal::texthash(
9136: 'rol' => "Role",
9137: 'grs' => "Section",
9138: 'exs' => "Existing sections",
9139: 'new' => "Define new section",
9140: 'sta' => "Start",
9141: 'end' => "End",
9142: 'ssd' => "Set Start Date",
9143: 'sed' => "Set End Date",
9144: 'scc' => "Course/Community",
9145: 'crd' => "Credits",
9146: );
9147: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
9148: &Apache::loncommon::start_data_table().
9149: &Apache::loncommon::start_data_table_header_row().
9150: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
9151: '<th>'.$lt{'grs'}.'</th>'."\n";
9152: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9153: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
9154: &Apache::loncommon::end_data_table_header_row();
9155: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
9156: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9157: $courseform.(' ' x4).'</span></td>'."\n".
9158: '<td valign="top"><br /><select name="role">'."\n";
9159: foreach my $role (@roles) {
9160: my $plrole=&Apache::lonnet::plaintext($role);
9161: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
9162: }
9163: if ( keys(%customroles) > 0) {
9164: foreach my $cust (sort(keys(%customroles))) {
9165: my $custrole='cr_cr_'.$env{'user.domain'}.
9166: '_'.$env{'user.name'}.'_'.$cust;
9167: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
9168: }
9169: }
9170: $otheritems .= '</select></td><td>'.
9171: '<table border="0" cellspacing="0" cellpadding="0">'.
9172: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
9173: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
9174: '<td> </td>'.
9175: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
9176: '<input type="text" name="newsec" value="" />'.
9177: '<input type="hidden" name="section" value="" />'.
9178: '<input type="hidden" name="groups" value="" />'.
9179: '<input type="hidden" name="crstype" value="" /></td>'.
9180: '</tr></table></td>'."\n";
9181: if ($showcredits) {
9182: $otheritems .= '<td><br />'."\n".
9183: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
9184: }
9185: $otheritems .= <<ENDTIMEENTRY;
9186: <td><br /><input type="hidden" name="start" value='' />
9187: <a href=
9188: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
9189: <td><br /><input type="hidden" name="end" value='' />
9190: <a href=
9191: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9192: ENDTIMEENTRY
9193: $otheritems .= &Apache::loncommon::end_data_table_row().
9194: &Apache::loncommon::end_data_table()."\n";
9195: return $cb_jscript.$header.$hiddenitems.$otheritems;
9196: }
9197:
9198: sub update_selfenroll_config {
9199: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
9200: return unless (ref($currsettings) eq 'HASH');
9201: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9202: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9203: my (%changes,%warning);
9204: my $curr_types;
9205: my %noedit;
9206: unless ($context eq 'domain') {
9207: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9208: }
9209: if (ref($row) eq 'ARRAY') {
9210: foreach my $item (@{$row}) {
9211: next if ($noedit{$item});
9212: if ($item eq 'enroll_dates') {
9213: my (%currenrolldate,%newenrolldate);
9214: foreach my $type ('start','end') {
9215: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
9216: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9217: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9218: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9219: }
9220: }
9221: } elsif ($item eq 'access_dates') {
9222: my (%currdate,%newdate);
9223: foreach my $type ('start','end') {
9224: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
9225: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9226: if ($newdate{$type} ne $currdate{$type}) {
9227: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9228: }
9229: }
9230: } elsif ($item eq 'types') {
9231: $curr_types = $currsettings->{'selfenroll_'.$item};
9232: if ($env{'form.selfenroll_all'}) {
9233: if ($curr_types ne '*') {
9234: $changes{'internal.selfenroll_types'} = '*';
9235: } else {
9236: next;
9237: }
9238: } else {
9239: my %currdoms;
9240: my @entries = split(/;/,$curr_types);
9241: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
9242: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
9243: my $newnum = 0;
9244: my @latesttypes;
9245: foreach my $num (@activations) {
9246: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9247: if (@types > 0) {
9248: @types = sort(@types);
9249: my $typestr = join(',',@types);
9250: my $typedom = $env{'form.selfenroll_dom_'.$num};
9251: $latesttypes[$newnum] = $typedom.':'.$typestr;
9252: $currdoms{$typedom} = 1;
9253: $newnum ++;
9254: }
9255: }
9256: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9257: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
9258: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9259: if (@types > 0) {
9260: @types = sort(@types);
9261: my $typestr = join(',',@types);
9262: my $typedom = $env{'form.selfenroll_dom_'.$j};
9263: $latesttypes[$newnum] = $typedom.':'.$typestr;
9264: $currdoms{$typedom} = 1;
9265: $newnum ++;
9266: }
9267: }
9268: }
9269: if ($env{'form.selfenroll_newdom'} ne '') {
9270: my $typedom = $env{'form.selfenroll_newdom'};
9271: if ((!defined($currdoms{$typedom})) &&
9272: (&Apache::lonnet::domain($typedom) ne '')) {
9273: my $typestr;
9274: my ($othertitle,$usertypes,$types) =
9275: &Apache::loncommon::sorted_inst_types($typedom);
9276: my $othervalue = 'any';
9277: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9278: if (@{$types} > 0) {
9279: my @esc_types = map { &escape($_); } @{$types};
9280: $othervalue = 'other';
9281: $typestr = join(',',(@esc_types,$othervalue));
9282: }
9283: $typestr = $othervalue;
9284: } else {
9285: $typestr = $othervalue;
9286: }
9287: $latesttypes[$newnum] = $typedom.':'.$typestr;
9288: $newnum ++ ;
9289: }
9290: }
9291: my $selfenroll_types = join(';',@latesttypes);
9292: if ($selfenroll_types ne $curr_types) {
9293: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9294: }
9295: }
9296: } elsif ($item eq 'limit') {
9297: my $newlimit = $env{'form.selfenroll_limit'};
9298: my $newcap = $env{'form.selfenroll_cap'};
9299: $newcap =~s/\s+//g;
9300: my $currlimit = $currsettings->{'selfenroll_limit'};
9301: $currlimit = 'none' if ($currlimit eq '');
9302: my $currcap = $currsettings->{'selfenroll_cap'};
9303: if ($newlimit ne $currlimit) {
9304: if ($newlimit ne 'none') {
9305: if ($newcap =~ /^\d+$/) {
9306: if ($newcap ne $currcap) {
9307: $changes{'internal.selfenroll_cap'} = $newcap;
9308: }
9309: $changes{'internal.selfenroll_limit'} = $newlimit;
9310: } else {
9311: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9312: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
9313: }
9314: } elsif ($currcap ne '') {
9315: $changes{'internal.selfenroll_cap'} = '';
9316: $changes{'internal.selfenroll_limit'} = $newlimit;
9317: }
9318: } elsif ($currlimit ne 'none') {
9319: if ($newcap =~ /^\d+$/) {
9320: if ($newcap ne $currcap) {
9321: $changes{'internal.selfenroll_cap'} = $newcap;
9322: }
9323: } else {
9324: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9325: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
9326: }
9327: }
9328: } elsif ($item eq 'approval') {
9329: my (@currnotified,@newnotified);
9330: my $currapproval = $currsettings->{'selfenroll_approval'};
9331: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
9332: if ($currnotifylist ne '') {
9333: @currnotified = split(/,/,$currnotifylist);
9334: @currnotified = sort(@currnotified);
9335: }
9336: my $newapproval = $env{'form.selfenroll_approval'};
9337: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9338: @newnotified = sort(@newnotified);
9339: if ($newapproval ne $currapproval) {
9340: $changes{'internal.selfenroll_approval'} = $newapproval;
9341: if (!$newapproval) {
9342: if ($currnotifylist ne '') {
9343: $changes{'internal.selfenroll_notifylist'} = '';
9344: }
9345: } else {
9346: my @differences =
9347: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
9348: if (@differences > 0) {
9349: if (@newnotified > 0) {
9350: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9351: } else {
9352: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9353: }
9354: }
9355: }
9356: } else {
9357: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
9358: if (@differences > 0) {
9359: if (@newnotified > 0) {
9360: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9361: } else {
9362: $changes{'internal.selfenroll_notifylist'} = '';
9363: }
9364: }
9365: }
9366: } else {
9367: my $curr_val = $currsettings->{'selfenroll_'.$item};
9368: my $newval = $env{'form.selfenroll_'.$item};
9369: if ($item eq 'section') {
9370: $newval = $env{'form.sections'};
9371: if (defined($curr_groups{$newval})) {
9372: $newval = $curr_val;
9373: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9374: &mt('Group names and section names must be distinct');
9375: } elsif ($newval eq 'all') {
9376: $newval = $curr_val;
9377: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
9378: }
9379: if ($newval eq '') {
9380: $newval = 'none';
9381: }
9382: }
9383: if ($newval ne $curr_val) {
9384: $changes{'internal.selfenroll_'.$item} = $newval;
9385: }
9386: }
9387: }
9388: if (keys(%warning) > 0) {
9389: foreach my $item (@{$row}) {
9390: if (exists($warning{$item})) {
9391: $r->print($warning{$item}.'<br />');
9392: }
9393: }
9394: }
9395: if (keys(%changes) > 0) {
9396: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9397: if ($putresult eq 'ok') {
9398: if ((exists($changes{'internal.selfenroll_types'})) ||
9399: (exists($changes{'internal.selfenroll_start_date'})) ||
9400: (exists($changes{'internal.selfenroll_end_date'}))) {
9401: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9402: $cnum,undef,undef,'Course');
9403: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
9404: if (ref($crsinfo{$cid}) eq 'HASH') {
9405: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9406: if (exists($changes{'internal.'.$item})) {
9407: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
9408: }
9409: }
9410: my $crsputresult =
9411: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9412: $chome,'notime');
9413: }
9414: }
9415: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9416: foreach my $item (@{$row}) {
9417: my $title = $item;
9418: if (ref($lt) eq 'HASH') {
9419: $title = $lt->{$item};
9420: }
9421: if ($item eq 'enroll_dates') {
9422: foreach my $type ('start','end') {
9423: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9424: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
9425: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
9426: $title,$type,$newdate).'</li>');
9427: }
9428: }
9429: } elsif ($item eq 'access_dates') {
9430: foreach my $type ('start','end') {
9431: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9432: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
9433: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
9434: $title,$type,$newdate).'</li>');
9435: }
9436: }
9437: } elsif ($item eq 'limit') {
9438: if ((exists($changes{'internal.selfenroll_limit'})) ||
9439: (exists($changes{'internal.selfenroll_cap'}))) {
9440: my ($newval,$newcap);
9441: if ($changes{'internal.selfenroll_cap'} ne '') {
9442: $newcap = $changes{'internal.selfenroll_cap'}
9443: } else {
9444: $newcap = $currsettings->{'selfenroll_cap'};
9445: }
9446: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9447: $newval = &mt('No limit');
9448: } elsif ($changes{'internal.selfenroll_limit'} eq
9449: 'allstudents') {
9450: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9451: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9452: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9453: } else {
9454: my $currlimit = $currsettings->{'selfenroll_limit'};
9455: if ($currlimit eq 'allstudents') {
9456: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9457: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9458: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9459: }
9460: }
9461: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9462: }
9463: } elsif ($item eq 'approval') {
9464: if ((exists($changes{'internal.selfenroll_approval'})) ||
9465: (exists($changes{'internal.selfenroll_notifylist'}))) {
9466: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
9467: my ($newval,$newnotify);
9468: if (exists($changes{'internal.selfenroll_notifylist'})) {
9469: $newnotify = $changes{'internal.selfenroll_notifylist'};
9470: } else {
9471: $newnotify = $currsettings->{'selfenroll_notifylist'};
9472: }
9473: if (exists($changes{'internal.selfenroll_approval'})) {
9474: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9475: $changes{'internal.selfenroll_approval'} = '0';
9476: }
9477: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
9478: } else {
9479: my $currapproval = $currsettings->{'selfenroll_approval'};
9480: if ($currapproval !~ /^[012]$/) {
9481: $currapproval = 0;
9482: }
9483: $newval = $selfdescs{'approval'}{$currapproval};
9484: }
9485: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9486: if ($newnotify) {
9487: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
9488: } else {
9489: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
9490: }
9491: $r->print('</li>'."\n");
9492: }
9493: } else {
9494: if (exists($changes{'internal.selfenroll_'.$item})) {
9495: my $newval = $changes{'internal.selfenroll_'.$item};
9496: if ($item eq 'types') {
9497: if ($newval eq '') {
9498: $newval = &mt('None');
9499: } elsif ($newval eq '*') {
9500: $newval = &mt('Any user in any domain');
9501: }
9502: } elsif ($item eq 'registered') {
9503: if ($newval eq '1') {
9504: $newval = &mt('Yes');
9505: } elsif ($newval eq '0') {
9506: $newval = &mt('No');
9507: }
9508: }
9509: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9510: }
9511: }
9512: }
9513: $r->print('</ul>');
9514: if ($env{'course.'.$cid.'.description'} ne '') {
9515: my %newenvhash;
9516: foreach my $key (keys(%changes)) {
9517: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9518: }
9519: &Apache::lonnet::appenv(\%newenvhash);
9520: }
9521: } else {
9522: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9523: &mt('The error was: [_1].',$putresult));
9524: }
9525: } else {
9526: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
9527: }
9528: } else {
9529: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
9530: }
9531: my $visactions = &cat_visibility();
9532: my ($cathash,%cattype);
9533: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9534: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9535: $cathash = $domconfig{'coursecategories'}{'cats'};
9536: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9537: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9538: } else {
9539: $cathash = {};
9540: $cattype{'auth'} = 'std';
9541: $cattype{'unauth'} = 'std';
9542: }
9543: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9544: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9545: '<br />'.
9546: '<br />'.$visactions->{'take'}.'<ul>'.
9547: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9548: '</ul>');
9549: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9550: if ($currsettings->{'uniquecode'}) {
9551: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9552: } else {
9553: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9554: '<br />'.
9555: '<br />'.$visactions->{'take'}.'<ul>'.
9556: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9557: '</ul><br />');
9558: }
9559: } else {
9560: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9561: if (ref($visactions) eq 'HASH') {
9562: if (!$visible) {
9563: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9564: '<br />');
9565: if (ref($vismsgs) eq 'ARRAY') {
9566: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9567: foreach my $item (@{$vismsgs}) {
9568: $r->print('<li>'.$visactions->{$item}.'</li>');
9569: }
9570: $r->print('</ul>');
9571: }
9572: $r->print($cansetvis);
9573: }
9574: }
9575: }
9576: return;
9577: }
9578:
9579: #---------------------------------------------- end functions for &phase_two
9580:
9581: #--------------------------------- functions for &phase_two and &phase_three
9582:
9583: #--------------------------end of functions for &phase_two and &phase_three
9584:
9585: 1;
9586: __END__
9587:
9588:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>