File:
[LON-CAPA] /
loncom /
interface /
loncreateuser.pm
Revision
1.449:
download - view:
text,
annotated -
select for diffs
Fri Mar 23 01:01:21 2018 UTC (6 years, 6 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Bug 6754 LON-CAPA as LTI Provider
- Creation of new LON-CAPA user account available from an LTI Consumer.
- Creation of new LON-CAPA course available from an LTI Consumer.
- Self-enrollment in a LON-CAPA course available from an LTI Consumer.
1: # The LearningOnline Network with CAPA
2: # Create a user
3: #
4: # $Id: loncreateuser.pm,v 1.449 2018/03/23 01:01:21 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: my $authformlti;
82:
83: sub initialize_authen_forms {
84: my ($dom,$formname,$curr_authtype,$mode) = @_;
85: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
86: my %param = ( formname => $formname,
87: kerb_def_dom => $krbdefdom,
88: kerb_def_auth => $krbdef,
89: domain => $dom,
90: );
91: my %abv_auth = &auth_abbrev();
92: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix|lti):(.*)$/) {
93: my $long_auth = $1;
94: my $curr_autharg = $2;
95: my %abv_auth = &auth_abbrev();
96: $param{'curr_authtype'} = $abv_auth{$long_auth};
97: if ($long_auth =~ /^krb(4|5)$/) {
98: $param{'curr_kerb_ver'} = $1;
99: $param{'curr_autharg'} = $curr_autharg;
100: }
101: if ($mode eq 'modifyuser') {
102: $param{'mode'} = $mode;
103: }
104: }
105: $loginscript = &Apache::loncommon::authform_header(%param);
106: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
107: $authformnop = &Apache::loncommon::authform_nochange(%param);
108: $authformint = &Apache::loncommon::authform_internal(%param);
109: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
110: $authformloc = &Apache::loncommon::authform_local(%param);
111: $authformlti = &Apache::loncommon::authform_lti(%param);
112: }
113:
114: sub auth_abbrev {
115: my %abv_auth = (
116: krb5 => 'krb',
117: krb4 => 'krb',
118: internal => 'int',
119: localauth => 'loc',
120: unix => 'fsys',
121: lti => 'lti',
122: );
123: return %abv_auth;
124: }
125:
126: # ====================================================
127:
128: sub user_quotas {
129: my ($ccuname,$ccdomain) = @_;
130: my %lt = &Apache::lonlocal::texthash(
131: 'usrt' => "User Tools",
132: 'cust' => "Custom quota",
133: 'chqu' => "Change quota",
134: );
135:
136: my $quota_javascript = <<"END_SCRIPT";
137: <script type="text/javascript">
138: // <![CDATA[
139: function quota_changes(caller,context) {
140: var customoff = document.getElementById('custom_'+context+'quota_off');
141: var customon = document.getElementById('custom_'+context+'quota_on');
142: var number = document.getElementById(context+'quota');
143: if (caller == "custom") {
144: if (customoff) {
145: if (customoff.checked) {
146: number.value = "";
147: }
148: }
149: }
150: if (caller == "quota") {
151: if (customon) {
152: customon.checked = true;
153: }
154: }
155: return;
156: }
157: // ]]>
158: </script>
159: END_SCRIPT
160: my $longinsttype;
161: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
162: my $output = $quota_javascript."\n".
163: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
164: &Apache::loncommon::start_data_table();
165:
166: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
167: (&Apache::lonnet::allowed('udp',$ccdomain))) {
168: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
169: }
170:
171: my %titles = &Apache::lonlocal::texthash (
172: portfolio => "Disk space allocated to user's portfolio files",
173: author => "Disk space allocated to user's Authoring Space (if role assigned)",
174: );
175: foreach my $name ('portfolio','author') {
176: my ($currquota,$quotatype,$inststatus,$defquota) =
177: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
178: if ($longinsttype eq '') {
179: if ($inststatus ne '') {
180: if ($usertypes->{$inststatus} ne '') {
181: $longinsttype = $usertypes->{$inststatus};
182: }
183: }
184: }
185: my ($showquota,$custom_on,$custom_off,$defaultinfo);
186: $custom_on = ' ';
187: $custom_off = ' checked="checked" ';
188: if ($quotatype eq 'custom') {
189: $custom_on = $custom_off;
190: $custom_off = ' ';
191: $showquota = $currquota;
192: if ($longinsttype eq '') {
193: $defaultinfo = &mt('For this user, the default quota would be [_1]'
194: .' MB.',$defquota);
195: } else {
196: $defaultinfo = &mt("For this user, the default quota would be [_1]".
197: " MB, as determined by the user's institutional".
198: " affiliation ([_2]).",$defquota,$longinsttype);
199: }
200: } else {
201: if ($longinsttype eq '') {
202: $defaultinfo = &mt('For this user, the default quota is [_1]'
203: .' MB.',$defquota);
204: } else {
205: $defaultinfo = &mt("For this user, the default quota of [_1]".
206: " MB, is determined by the user's institutional".
207: " affiliation ([_2]).",$defquota,$longinsttype);
208: }
209: }
210:
211: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
212: $output .= '<tr class="LC_info_row">'."\n".
213: ' <td>'.$titles{$name}.'</td>'."\n".
214: ' </tr>'."\n".
215: &Apache::loncommon::start_data_table_row()."\n".
216: ' <td><span class="LC_nobreak">'.
217: &mt('Current quota: [_1] MB',$currquota).'</span> '.
218: $defaultinfo.'</td>'."\n".
219: &Apache::loncommon::end_data_table_row()."\n".
220: &Apache::loncommon::start_data_table_row()."\n".
221: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
222: ': <label>'.
223: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
224: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
225: ' /><span class="LC_nobreak">'.
226: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
227: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
228: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
229: ' />'.$lt{'cust'}.':</label> '.
230: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
231: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
232: ' /> '.&mt('MB').'</span></td>'."\n".
233: &Apache::loncommon::end_data_table_row()."\n";
234: }
235: }
236: $output .= &Apache::loncommon::end_data_table();
237: return $output;
238: }
239:
240: sub build_tools_display {
241: my ($ccuname,$ccdomain,$context) = @_;
242: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
243: $colspan,$isadv,%domconfig);
244: my %lt = &Apache::lonlocal::texthash (
245: 'blog' => "Personal User Blog",
246: 'aboutme' => "Personal Information Page",
247: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
248: 'portfolio' => "Personal User Portfolio",
249: 'avai' => "Available",
250: 'cusa' => "availability",
251: 'chse' => "Change setting",
252: 'usde' => "Use default",
253: 'uscu' => "Use custom",
254: 'official' => 'Can request creation of official courses',
255: 'unofficial' => 'Can request creation of unofficial courses',
256: 'community' => 'Can request creation of communities',
257: 'textbook' => 'Can request creation of textbook courses',
258: 'placement' => 'Can request creation of placement tests',
259: 'lti' => 'Can request creation of LTI courses',
260: 'requestauthor' => 'Can request author space',
261: );
262: if ($context eq 'requestcourses') {
263: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
264: 'requestcourses.official','requestcourses.unofficial',
265: 'requestcourses.community','requestcourses.textbook',
266: 'requestcourses.placement','requestcourses.lti');
267: @usertools = ('official','unofficial','community','textbook','placement','lti');
268: @options =('norequest','approval','autolimit','validate');
269: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
270: %reqtitles = &courserequest_titles();
271: %reqdisplay = &courserequest_display();
272: $colspan = ' colspan="2"';
273: %domconfig =
274: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
275: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
276: } elsif ($context eq 'requestauthor') {
277: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
278: 'requestauthor');
279: @usertools = ('requestauthor');
280: @options =('norequest','approval','automatic');
281: %reqtitles = &requestauthor_titles();
282: %reqdisplay = &requestauthor_display();
283: $colspan = ' colspan="2"';
284: %domconfig =
285: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
286: } else {
287: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
288: 'tools.aboutme','tools.portfolio','tools.blog',
289: 'tools.webdav');
290: @usertools = ('aboutme','blog','webdav','portfolio');
291: }
292: foreach my $item (@usertools) {
293: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
294: $currdisp,$custdisp,$custradio);
295: $cust_off = 'checked="checked" ';
296: $tool_on = 'checked="checked" ';
297: $curr_access =
298: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
299: $context);
300: if ($context eq 'requestauthor') {
301: if ($userenv{$context} ne '') {
302: $cust_on = ' checked="checked" ';
303: $cust_off = '';
304: }
305: } elsif ($userenv{$context.'.'.$item} ne '') {
306: $cust_on = ' checked="checked" ';
307: $cust_off = '';
308: }
309: if ($context eq 'requestcourses') {
310: if ($userenv{$context.'.'.$item} eq '') {
311: $custom_access = &mt('Currently from default setting.');
312: } else {
313: $custom_access = &mt('Currently from custom setting.');
314: }
315: } elsif ($context eq 'requestauthor') {
316: if ($userenv{$context} eq '') {
317: $custom_access = &mt('Currently from default setting.');
318: } else {
319: $custom_access = &mt('Currently from custom setting.');
320: }
321: } else {
322: if ($userenv{$context.'.'.$item} eq '') {
323: $custom_access =
324: &mt('Availability determined currently from default setting.');
325: if (!$curr_access) {
326: $tool_off = 'checked="checked" ';
327: $tool_on = '';
328: }
329: } else {
330: $custom_access =
331: &mt('Availability determined currently from custom setting.');
332: if ($userenv{$context.'.'.$item} == 0) {
333: $tool_off = 'checked="checked" ';
334: $tool_on = '';
335: }
336: }
337: }
338: $output .= ' <tr class="LC_info_row">'."\n".
339: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
340: ' </tr>'."\n".
341: &Apache::loncommon::start_data_table_row()."\n";
342:
343: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
344: my ($curroption,$currlimit);
345: my $envkey = $context.'.'.$item;
346: if ($context eq 'requestauthor') {
347: $envkey = $context;
348: }
349: if ($userenv{$envkey} ne '') {
350: $curroption = $userenv{$envkey};
351: } else {
352: my (@inststatuses);
353: if ($context eq 'requestcourses') {
354: $curroption =
355: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
356: $isadv,$ccdomain,$item,
357: \@inststatuses,\%domconfig);
358: } else {
359: $curroption =
360: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
361: $isadv,$ccdomain,undef,
362: \@inststatuses,\%domconfig);
363: }
364: }
365: if (!$curroption) {
366: $curroption = 'norequest';
367: }
368: if ($curroption =~ /^autolimit=(\d*)$/) {
369: $currlimit = $1;
370: if ($currlimit eq '') {
371: $currdisp = &mt('Yes, automatic creation');
372: } else {
373: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
374: }
375: } else {
376: $currdisp = $reqdisplay{$curroption};
377: }
378: $custdisp = '<table>';
379: foreach my $option (@options) {
380: my $val = $option;
381: if ($option eq 'norequest') {
382: $val = 0;
383: }
384: if ($option eq 'validate') {
385: my $canvalidate = 0;
386: if (ref($validations{$item}) eq 'HASH') {
387: if ($validations{$item}{'_custom_'}) {
388: $canvalidate = 1;
389: }
390: }
391: next if (!$canvalidate);
392: }
393: my $checked = '';
394: if ($option eq $curroption) {
395: $checked = ' checked="checked"';
396: } elsif ($option eq 'autolimit') {
397: if ($curroption =~ /^autolimit/) {
398: $checked = ' checked="checked"';
399: }
400: }
401: my $name = 'crsreq_'.$item;
402: if ($context eq 'requestauthor') {
403: $name = $item;
404: }
405: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
406: '<input type="radio" name="'.$name.'" '.
407: 'value="'.$val.'"'.$checked.' />'.
408: $reqtitles{$option}.'</label> ';
409: if ($option eq 'autolimit') {
410: $custdisp .= '<input type="text" name="'.$name.
411: '_limit" size="1" '.
412: 'value="'.$currlimit.'" /></span><br />'.
413: $reqtitles{'unlimited'};
414: } else {
415: $custdisp .= '</span>';
416: }
417: $custdisp .= '</td></tr>';
418: }
419: $custdisp .= '</table>';
420: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
421: } else {
422: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
423: my $name = $context.'_'.$item;
424: if ($context eq 'requestauthor') {
425: $name = $context;
426: }
427: $custdisp = '<span class="LC_nobreak"><label>'.
428: '<input type="radio" name="'.$name.'"'.
429: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
430: '<input type="radio" name="'.$name.'" value="0" '.
431: $tool_off.'/>'.&mt('Off').'</label></span>';
432: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
433: '</span>';
434: }
435: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
436: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
437: &Apache::loncommon::end_data_table_row()."\n";
438: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
439: $output .=
440: &Apache::loncommon::start_data_table_row()."\n".
441: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
442: $lt{'chse'}.': <label>'.
443: '<input type="radio" name="custom'.$item.'" value="0" '.
444: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
445: '<label><input type="radio" name="custom'.$item.'" value="1" '.
446: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
447: &Apache::loncommon::end_data_table_row()."\n";
448: }
449: }
450: return $output;
451: }
452:
453: sub coursereq_externaluser {
454: my ($ccuname,$ccdomain,$cdom) = @_;
455: my (@usertools,@options,%validations,%userenv,$output);
456: my %lt = &Apache::lonlocal::texthash (
457: 'official' => 'Can request creation of official courses',
458: 'unofficial' => 'Can request creation of unofficial courses',
459: 'community' => 'Can request creation of communities',
460: 'textbook' => 'Can request creation of textbook courses',
461: 'placement' => 'Can request creation of placement tests',
462: );
463:
464: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
465: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
466: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
467: 'reqcrsotherdom.placement');
468: @usertools = ('official','unofficial','community','textbook','placement');
469: @options = ('approval','validate','autolimit');
470: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
471: my $optregex = join('|',@options);
472: my %reqtitles = &courserequest_titles();
473: foreach my $item (@usertools) {
474: my ($curroption,$currlimit,$tooloff);
475: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
476: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
477: foreach my $req (@curr) {
478: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
479: $curroption = $1;
480: $currlimit = $2;
481: last;
482: }
483: }
484: if (!$curroption) {
485: $curroption = 'norequest';
486: $tooloff = ' checked="checked"';
487: }
488: } else {
489: $curroption = 'norequest';
490: $tooloff = ' checked="checked"';
491: }
492: $output.= &Apache::loncommon::start_data_table_row()."\n".
493: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
494: '<table><tr><td valign="top">'."\n".
495: '<label><input type="radio" name="reqcrsotherdom_'.$item.
496: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
497: '</label></td>';
498: foreach my $option (@options) {
499: if ($option eq 'validate') {
500: my $canvalidate = 0;
501: if (ref($validations{$item}) eq 'HASH') {
502: if ($validations{$item}{'_external_'}) {
503: $canvalidate = 1;
504: }
505: }
506: next if (!$canvalidate);
507: }
508: my $checked = '';
509: if ($option eq $curroption) {
510: $checked = ' checked="checked"';
511: }
512: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
513: '<input type="radio" name="reqcrsotherdom_'.$item.
514: '" value="'.$option.'"'.$checked.' />'.
515: $reqtitles{$option}.'</label>';
516: if ($option eq 'autolimit') {
517: $output .= ' <input type="text" name="reqcrsotherdom_'.
518: $item.'_limit" size="1" '.
519: 'value="'.$currlimit.'" /></span>'.
520: '<br />'.$reqtitles{'unlimited'};
521: } else {
522: $output .= '</span>';
523: }
524: $output .= '</td>';
525: }
526: $output .= '</td></tr></table></td>'."\n".
527: &Apache::loncommon::end_data_table_row()."\n";
528: }
529: return $output;
530: }
531:
532: sub domainrole_req {
533: my ($ccuname,$ccdomain) = @_;
534: return '<br /><h3>'.
535: &mt('User Can Request Assignment of Domain Roles?').
536: '</h3>'."\n".
537: &Apache::loncommon::start_data_table().
538: &build_tools_display($ccuname,$ccdomain,
539: 'requestauthor').
540: &Apache::loncommon::end_data_table();
541: }
542:
543: sub courserequest_titles {
544: my %titles = &Apache::lonlocal::texthash (
545: official => 'Official',
546: unofficial => 'Unofficial',
547: community => 'Communities',
548: textbook => 'Textbook',
549: placement => 'Placement Tests',
550: lti => 'LTI Provider',
551: norequest => 'Not allowed',
552: approval => 'Approval by Dom. Coord.',
553: validate => 'With validation',
554: autolimit => 'Numerical limit',
555: unlimited => '(blank for unlimited)',
556: );
557: return %titles;
558: }
559:
560: sub courserequest_display {
561: my %titles = &Apache::lonlocal::texthash (
562: approval => 'Yes, need approval',
563: validate => 'Yes, with validation',
564: norequest => 'No',
565: );
566: return %titles;
567: }
568:
569: sub requestauthor_titles {
570: my %titles = &Apache::lonlocal::texthash (
571: norequest => 'Not allowed',
572: approval => 'Approval by Dom. Coord.',
573: automatic => 'Automatic approval',
574: );
575: return %titles;
576:
577: }
578:
579: sub requestauthor_display {
580: my %titles = &Apache::lonlocal::texthash (
581: approval => 'Yes, need approval',
582: automatic => 'Yes, automatic approval',
583: norequest => 'No',
584: );
585: return %titles;
586: }
587:
588: sub requestchange_display {
589: my %titles = &Apache::lonlocal::texthash (
590: approval => "availability set to 'on' (approval required)",
591: automatic => "availability set to 'on' (automatic approval)",
592: norequest => "availability set to 'off'",
593: );
594: return %titles;
595: }
596:
597: sub curr_requestauthor {
598: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
599: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
600: if ($uname eq '' || $udom eq '') {
601: $uname = $env{'user.name'};
602: $udom = $env{'user.domain'};
603: $isadv = $env{'user.adv'};
604: }
605: my (%userenv,%settings,$val);
606: my @options = ('automatic','approval');
607: %userenv =
608: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
609: if ($userenv{'requestauthor'}) {
610: $val = $userenv{'requestauthor'};
611: @{$inststatuses} = ('_custom_');
612: } else {
613: my %alltasks;
614: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
615: %settings = %{$domconfig->{'requestauthor'}};
616: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
617: $val = $settings{'_LC_adv'};
618: @{$inststatuses} = ('_LC_adv_');
619: } else {
620: if ($userenv{'inststatus'} ne '') {
621: @{$inststatuses} = split(',',$userenv{'inststatus'});
622: } else {
623: @{$inststatuses} = ('default');
624: }
625: foreach my $status (@{$inststatuses}) {
626: if (exists($settings{$status})) {
627: my $value = $settings{$status};
628: next unless ($value);
629: unless (exists($alltasks{$value})) {
630: if (ref($alltasks{$value}) eq 'ARRAY') {
631: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
632: push(@{$alltasks{$value}},$status);
633: }
634: } else {
635: @{$alltasks{$value}} = ($status);
636: }
637: }
638: }
639: }
640: foreach my $option (@options) {
641: if ($alltasks{$option}) {
642: $val = $option;
643: last;
644: }
645: }
646: }
647: }
648: }
649: return $val;
650: }
651:
652: # =================================================================== Phase one
653:
654: sub print_username_entry_form {
655: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
656: $permission) = @_;
657: my $defdom=$env{'request.role.domain'};
658: my $formtoset = 'crtuser';
659: if (exists($env{'form.startrolename'})) {
660: $formtoset = 'docustom';
661: $env{'form.rolename'} = $env{'form.startrolename'};
662: } elsif ($env{'form.origform'} eq 'crtusername') {
663: $formtoset = $env{'form.origform'};
664: }
665:
666: my ($jsback,$elements) = &crumb_utilities();
667:
668: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
669: '<script type="text/javascript">'."\n".
670: '// <![CDATA['."\n".
671: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
672: '// ]]>'."\n".
673: '</script>'."\n";
674:
675: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
676: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
677: && (&Apache::lonnet::allowed('mcr','/'))) {
678: $jscript .= &customrole_javascript();
679: }
680: my $helpitem = 'Course_Change_Privileges';
681: if ($env{'form.action'} eq 'custom') {
682: if ($context eq 'course') {
683: $helpitem = 'Course_Editing_Custom_Roles';
684: } elsif ($context eq 'domain') {
685: $helpitem = 'Domain_Editing_Custom_Roles';
686: }
687: } elsif ($env{'form.action'} eq 'singlestudent') {
688: $helpitem = 'Course_Add_Student';
689: } elsif ($env{'form.action'} eq 'accesslogs') {
690: $helpitem = 'Domain_User_Access_Logs';
691: } elsif ($context eq 'author') {
692: $helpitem = 'Author_Change_Privileges';
693: } elsif ($context eq 'domain') {
694: if ($permission->{'cusr'}) {
695: $helpitem = 'Domain_Change_Privileges';
696: } elsif ($permission->{'view'}) {
697: $helpitem = 'Domain_View_Privileges';
698: } else {
699: undef($helpitem);
700: }
701: }
702: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
703: if ($env{'form.action'} eq 'custom') {
704: push(@{$brcrum},
705: {href=>"javascript:backPage(document.crtuser)",
706: text=>"Pick custom role",
707: help => $helpitem,}
708: );
709: } else {
710: push (@{$brcrum},
711: {href => "javascript:backPage(document.crtuser)",
712: text => $breadcrumb_text{'search'},
713: help => $helpitem,
714: faq => 282,
715: bug => 'Instructor Interface',}
716: );
717: }
718: my %loaditems = (
719: 'onload' => "javascript:setFormElements(document.$formtoset)",
720: );
721: my $args = {bread_crumbs => $brcrum,
722: bread_crumbs_component => 'User Management',
723: add_entries => \%loaditems,};
724: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
725:
726: my %lt=&Apache::lonlocal::texthash(
727: 'srst' => 'Search for a user and enroll as a student',
728: 'srme' => 'Search for a user and enroll as a member',
729: 'srad' => 'Search for a user and modify/add user information or roles',
730: 'srvu' => 'Search for a user and view user information and roles',
731: 'srva' => 'Search for a user and view access log information',
732: 'usr' => "Username",
733: 'dom' => "Domain",
734: 'ecrp' => "Define or Edit Custom Role",
735: 'nr' => "role name",
736: 'cre' => "Next",
737: );
738:
739: if ($env{'form.action'} eq 'custom') {
740: if (&Apache::lonnet::allowed('mcr','/')) {
741: my $newroletext = &mt('Define new custom role:');
742: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
743: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
744: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
745: '<h3>'.$lt{'ecrp'}.'</h3>'.
746: &Apache::loncommon::start_data_table().
747: &Apache::loncommon::start_data_table_row().
748: '<td>');
749: if (keys(%existingroles) > 0) {
750: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
751: } else {
752: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
753: }
754: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
755: &Apache::loncommon::end_data_table_row());
756: if (keys(%existingroles) > 0) {
757: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
758: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
759: &mt('View/Modify existing role:').'</b></label></td>'.
760: '<td align="center"><br />'.
761: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
762: '<option value="" selected="selected">'.
763: &mt('Select'));
764: foreach my $role (sort(keys(%existingroles))) {
765: $r->print('<option value="'.$role.'">'.$role.'</option>');
766: }
767: $r->print('</select>'.
768: '</td>'.
769: &Apache::loncommon::end_data_table_row());
770: }
771: $r->print(&Apache::loncommon::end_data_table().'<p>'.
772: '<input name="customeditor" type="submit" value="'.
773: $lt{'cre'}.'" /></p>'.
774: '</form>');
775: }
776: } else {
777: my $actiontext = $lt{'srad'};
778: my $fixeddom;
779: if ($env{'form.action'} eq 'singlestudent') {
780: if ($crstype eq 'Community') {
781: $actiontext = $lt{'srme'};
782: } else {
783: $actiontext = $lt{'srst'};
784: }
785: } elsif ($env{'form.action'} eq 'accesslogs') {
786: $actiontext = $lt{'srva'};
787: $fixeddom = 1;
788: } elsif (($env{'form.action'} eq 'singleuser') &&
789: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
790: $actiontext = $lt{'srvu'};
791: $fixeddom = 1;
792: }
793: $r->print("<h3>$actiontext</h3>");
794: if ($env{'form.origform'} ne 'crtusername') {
795: if ($response) {
796: $r->print("\n<div>$response</div>".
797: '<br clear="all" />');
798: }
799: }
800: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
801: }
802: }
803:
804: sub customrole_javascript {
805: my $js = <<"END";
806: <script type="text/javascript">
807: // <![CDATA[
808:
809: function setCustomFields() {
810: if (document.docustom.customroleaction.length > 0) {
811: for (var i=0; i<document.docustom.customroleaction.length; i++) {
812: if (document.docustom.customroleaction[i].checked) {
813: if (document.docustom.customroleaction[i].value == 'new') {
814: document.docustom.rolename.selectedIndex = 0;
815: } else {
816: document.docustom.newrolename.value = '';
817: }
818: }
819: }
820: }
821: return;
822: }
823:
824: function setCustomAction(caller) {
825: if (document.docustom.customroleaction.length > 0) {
826: for (var i=0; i<document.docustom.customroleaction.length; i++) {
827: if (document.docustom.customroleaction[i].value == caller) {
828: document.docustom.customroleaction[i].checked = true;
829: }
830: }
831: }
832: setCustomFields();
833: return;
834: }
835:
836: // ]]>
837: </script>
838: END
839: return $js;
840: }
841:
842: sub entry_form {
843: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
844: my ($usertype,$inexact);
845: if (ref($srch) eq 'HASH') {
846: if (($srch->{'srchin'} eq 'dom') &&
847: ($srch->{'srchby'} eq 'uname') &&
848: ($srch->{'srchtype'} eq 'exact') &&
849: ($srch->{'srchdomain'} ne '') &&
850: ($srch->{'srchterm'} ne '')) {
851: my (%curr_rules,%got_rules);
852: my ($rules,$ruleorder) =
853: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
854: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
855: } else {
856: $inexact = 1;
857: }
858: }
859: my ($cancreate,$noinstd);
860: if ($env{'form.action'} eq 'accesslogs') {
861: $noinstd = 1;
862: } else {
863: $cancreate =
864: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
865: }
866: my ($userpicker,$cansearch) =
867: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
868: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
869: my $srchbutton = &mt('Search');
870: if ($env{'form.action'} eq 'singlestudent') {
871: $srchbutton = &mt('Search and Enroll');
872: } elsif ($env{'form.action'} eq 'accesslogs') {
873: $srchbutton = &mt('Search');
874: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
875: $srchbutton = &mt('Search or Add New User');
876: }
877: my $output;
878: if ($cansearch) {
879: $output = <<"ENDBLOCK";
880: <form action="/adm/createuser" method="post" name="crtuser">
881: <input type="hidden" name="action" value="$env{'form.action'}" />
882: <input type="hidden" name="phase" value="get_user_info" />
883: $userpicker
884: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
885: </form>
886: ENDBLOCK
887: } else {
888: $output = '<p>'.$userpicker.'</p>';
889: }
890: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
891: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
892: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
893: my $defdom=$env{'request.role.domain'};
894: my ($trusted,$untrusted);
895: if ($context eq 'course') {
896: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
897: } elsif ($context eq 'author') {
898: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
899: } elsif ($context eq 'domain') {
900: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
901: }
902: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain',undef,undef,undef,$trusted,$untrusted);
903: my %lt=&Apache::lonlocal::texthash(
904: 'enro' => 'Enroll one student',
905: 'enrm' => 'Enroll one member',
906: 'admo' => 'Add/modify a single user',
907: 'crea' => 'create new user if required',
908: 'uskn' => "username is known",
909: 'crnu' => 'Create a new user',
910: 'usr' => 'Username',
911: 'dom' => 'in domain',
912: 'enrl' => 'Enroll',
913: 'cram' => 'Create/Modify user',
914: );
915: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
916: my ($title,$buttontext,$showresponse);
917: if ($env{'form.action'} eq 'singlestudent') {
918: if ($crstype eq 'Community') {
919: $title = $lt{'enrm'};
920: } else {
921: $title = $lt{'enro'};
922: }
923: $buttontext = $lt{'enrl'};
924: } else {
925: $title = $lt{'admo'};
926: $buttontext = $lt{'cram'};
927: }
928: if ($cancreate) {
929: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
930: } else {
931: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
932: }
933: if ($env{'form.origform'} eq 'crtusername') {
934: $showresponse = $responsemsg;
935: }
936: $output .= <<"ENDDOCUMENT";
937: <br />
938: <form action="/adm/createuser" method="post" name="crtusername">
939: <input type="hidden" name="action" value="$env{'form.action'}" />
940: <input type="hidden" name="phase" value="createnewuser" />
941: <input type="hidden" name="srchtype" value="exact" />
942: <input type="hidden" name="srchby" value="uname" />
943: <input type="hidden" name="srchin" value="dom" />
944: <input type="hidden" name="forcenewuser" value="1" />
945: <input type="hidden" name="origform" value="crtusername" />
946: <h3>$title</h3>
947: $showresponse
948: <table>
949: <tr>
950: <td>$lt{'usr'}:</td>
951: <td><input type="text" size="15" name="srchterm" /></td>
952: <td> $lt{'dom'}:</td><td>$domform</td>
953: <td> $sellink </td>
954: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
955: </tr>
956: </table>
957: </form>
958: ENDDOCUMENT
959: }
960: return $output;
961: }
962:
963: sub user_modification_js {
964: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
965:
966: return <<END;
967: <script type="text/javascript" language="Javascript">
968: // <![CDATA[
969:
970: $pjump_def
971: $dc_setcourse_code
972:
973: function dateset() {
974: eval("document.cu."+document.cu.pres_marker.value+
975: ".value=document.cu.pres_value.value");
976: modalWindow.close();
977: }
978:
979: $nondc_setsection_code
980: // ]]>
981: </script>
982: END
983: }
984:
985: # =================================================================== Phase two
986: sub print_user_selection_page {
987: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
988: my @fields = ('username','domain','lastname','firstname','permanentemail');
989: my $sortby = $env{'form.sortby'};
990:
991: if (!grep(/^\Q$sortby\E$/,@fields)) {
992: $sortby = 'lastname';
993: }
994:
995: my ($jsback,$elements) = &crumb_utilities();
996:
997: my $jscript = (<<ENDSCRIPT);
998: <script type="text/javascript">
999: // <![CDATA[
1000: function pickuser(uname,udom) {
1001: document.usersrchform.seluname.value=uname;
1002: document.usersrchform.seludom.value=udom;
1003: document.usersrchform.phase.value="userpicked";
1004: document.usersrchform.submit();
1005: }
1006:
1007: $jsback
1008: // ]]>
1009: </script>
1010: ENDSCRIPT
1011:
1012: my %lt=&Apache::lonlocal::texthash(
1013: 'usrch' => "User Search to add/modify roles",
1014: 'stusrch' => "User Search to enroll student",
1015: 'memsrch' => "User Search to enroll member",
1016: 'srcva' => "Search for a user and view access log information",
1017: 'usrvu' => "User Search to view user roles",
1018: 'usel' => "Select a user to add/modify roles",
1019: 'suvr' => "Select a user to view roles",
1020: 'stusel' => "Select a user to enroll as a student",
1021: 'memsel' => "Select a user to enroll as a member",
1022: 'vacsel' => "Select a user to view access log",
1023: 'username' => "username",
1024: 'domain' => "domain",
1025: 'lastname' => "last name",
1026: 'firstname' => "first name",
1027: 'permanentemail' => "permanent e-mail",
1028: );
1029: if ($context eq 'requestcrs') {
1030: $r->print('<div>');
1031: } else {
1032: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1033: my $helpitem;
1034: if ($env{'form.action'} eq 'singleuser') {
1035: $helpitem = 'Course_Change_Privileges';
1036: } elsif ($env{'form.action'} eq 'singlestudent') {
1037: $helpitem = 'Course_Add_Student';
1038: } elsif ($context eq 'author') {
1039: $helpitem = 'Author_Change_Privileges';
1040: } elsif ($context eq 'domain') {
1041: $helpitem = 'Domain_Change_Privileges';
1042: }
1043: push (@{$brcrum},
1044: {href => "javascript:backPage(document.usersrchform,'','')",
1045: text => $breadcrumb_text{'search'},
1046: faq => 282,
1047: bug => 'Instructor Interface',},
1048: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1049: text => $breadcrumb_text{'userpicked'},
1050: faq => 282,
1051: bug => 'Instructor Interface',
1052: help => $helpitem}
1053: );
1054: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1055: if ($env{'form.action'} eq 'singleuser') {
1056: my $readonly;
1057: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1058: $readonly = 1;
1059: $r->print("<b>$lt{'usrvu'}</b><br />");
1060: } else {
1061: $r->print("<b>$lt{'usrch'}</b><br />");
1062: }
1063: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1064: if ($readonly) {
1065: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1066: } else {
1067: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1068: }
1069: } elsif ($env{'form.action'} eq 'singlestudent') {
1070: $r->print($jscript."<b>");
1071: if ($crstype eq 'Community') {
1072: $r->print($lt{'memsrch'});
1073: } else {
1074: $r->print($lt{'stusrch'});
1075: }
1076: $r->print("</b><br />");
1077: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1078: $r->print('</form><h3>');
1079: if ($crstype eq 'Community') {
1080: $r->print($lt{'memsel'});
1081: } else {
1082: $r->print($lt{'stusel'});
1083: }
1084: $r->print('</h3>');
1085: } elsif ($env{'form.action'} eq 'accesslogs') {
1086: $r->print("<b>$lt{'srcva'}</b><br />");
1087: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1088: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1089: }
1090: }
1091: $r->print('<form name="usersrchform" method="post" action="">'.
1092: &Apache::loncommon::start_data_table()."\n".
1093: &Apache::loncommon::start_data_table_header_row()."\n".
1094: ' <th> </th>'."\n");
1095: foreach my $field (@fields) {
1096: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1097: "'".$field."'".';document.usersrchform.submit();">'.
1098: $lt{$field}.'</a></th>'."\n");
1099: }
1100: $r->print(&Apache::loncommon::end_data_table_header_row());
1101:
1102: my @sorted_users = sort {
1103: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1104: ||
1105: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1106: ||
1107: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1108: ||
1109: lc($a) cmp lc($b)
1110: } (keys(%$srch_results));
1111:
1112: foreach my $user (@sorted_users) {
1113: my ($uname,$udom) = split(/:/,$user);
1114: my $onclick;
1115: if ($context eq 'requestcrs') {
1116: $onclick =
1117: 'onclick="javascript:gochoose('."'$uname','$udom',".
1118: "'$srch_results->{$user}->{firstname}',".
1119: "'$srch_results->{$user}->{lastname}',".
1120: "'$srch_results->{$user}->{permanentemail}'".');"';
1121: } else {
1122: $onclick =
1123: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1124: }
1125: $r->print(&Apache::loncommon::start_data_table_row().
1126: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1127: $onclick.' /></td>'.
1128: '<td><tt>'.$uname.'</tt></td>'.
1129: '<td><tt>'.$udom.'</tt></td>');
1130: foreach my $field ('lastname','firstname','permanentemail') {
1131: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1132: }
1133: $r->print(&Apache::loncommon::end_data_table_row());
1134: }
1135: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1136: if (ref($srcharray) eq 'ARRAY') {
1137: foreach my $item (@{$srcharray}) {
1138: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1139: }
1140: }
1141: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1142: ' <input type="hidden" name="seluname" value="" />'."\n".
1143: ' <input type="hidden" name="seludom" value="" />'."\n".
1144: ' <input type="hidden" name="currstate" value="select" />'."\n".
1145: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1146: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1147: if ($context eq 'requestcrs') {
1148: $r->print($opener_elements.'</form></div>');
1149: } else {
1150: $r->print($response.'</form>');
1151: }
1152: }
1153:
1154: sub print_user_query_page {
1155: my ($r,$caller,$brcrum) = @_;
1156: # FIXME - this is for a network-wide name search (similar to catalog search)
1157: # To use frames with similar behavior to catalog/portfolio search.
1158: # To be implemented.
1159: return;
1160: }
1161:
1162: sub print_user_modification_page {
1163: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1164: $brcrum,$showcredits) = @_;
1165: if (($ccuname eq '') || ($ccdomain eq '')) {
1166: my $usermsg = &mt('No username and/or domain provided.');
1167: $env{'form.phase'} = '';
1168: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1169: $permission);
1170: return;
1171: }
1172: my ($form,$formname);
1173: if ($env{'form.action'} eq 'singlestudent') {
1174: $form = 'document.enrollstudent';
1175: $formname = 'enrollstudent';
1176: } else {
1177: $form = 'document.cu';
1178: $formname = 'cu';
1179: }
1180: my %abv_auth = &auth_abbrev();
1181: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1182: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1183: if ($uhome eq 'no_host') {
1184: my $usertype;
1185: my ($rules,$ruleorder) =
1186: &Apache::lonnet::inst_userrules($ccdomain,'username');
1187: $usertype =
1188: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1189: \%curr_rules,\%got_rules);
1190: my $cancreate =
1191: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1192: $usertype);
1193: if (!$cancreate) {
1194: my $helplink = 'javascript:helpMenu('."'display'".')';
1195: my %usertypetext = (
1196: official => 'institutional',
1197: unofficial => 'non-institutional',
1198: );
1199: my $response;
1200: if ($env{'form.origform'} eq 'crtusername') {
1201: $response = '<span class="LC_warning">'.
1202: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1203: '<b>'.$ccuname.'</b>',$ccdomain).
1204: '</span><br />';
1205: }
1206: $response .= '<p class="LC_warning">'
1207: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1208: .' ';
1209: if ($context eq 'domain') {
1210: $response .= &mt('Please contact a [_1] for assistance.',
1211: &Apache::lonnet::plaintext('dc'));
1212: } else {
1213: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1214: ,'<a href="'.$helplink.'">','</a>');
1215: }
1216: $response .= '</p><br />';
1217: $env{'form.phase'} = '';
1218: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1219: $permission);
1220: return;
1221: }
1222: $newuser = 1;
1223: my $checkhash;
1224: my $checks = { 'username' => 1 };
1225: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1226: &Apache::loncommon::user_rule_check($checkhash,$checks,
1227: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1228: if (ref($alerts{'username'}) eq 'HASH') {
1229: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1230: my $domdesc =
1231: &Apache::lonnet::domain($ccdomain,'description');
1232: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1233: my $userchkmsg;
1234: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1235: $userchkmsg =
1236: &Apache::loncommon::instrule_disallow_msg('username',
1237: $domdesc,1).
1238: &Apache::loncommon::user_rule_formats($ccdomain,
1239: $domdesc,$curr_rules{$ccdomain}{'username'},
1240: 'username');
1241: }
1242: $env{'form.phase'} = '';
1243: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1244: $permission);
1245: return;
1246: }
1247: }
1248: }
1249: } else {
1250: $newuser = 0;
1251: }
1252: if ($response) {
1253: $response = '<br />'.$response;
1254: }
1255:
1256: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1257: my $dc_setcourse_code = '';
1258: my $nondc_setsection_code = '';
1259: my %loaditem;
1260:
1261: my $groupslist = &Apache::lonuserutils::get_groupslist();
1262:
1263: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1264: $groupslist,$newuser,$formname,\%loaditem);
1265: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1266: my $helpitem = 'Course_Change_Privileges';
1267: if ($env{'form.action'} eq 'singlestudent') {
1268: $helpitem = 'Course_Add_Student';
1269: } elsif ($context eq 'author') {
1270: $helpitem = 'Author_Change_Privileges';
1271: } elsif ($context eq 'domain') {
1272: $helpitem = 'Domain_Change_Privileges';
1273: }
1274: push (@{$brcrum},
1275: {href => "javascript:backPage($form)",
1276: text => $breadcrumb_text{'search'},
1277: faq => 282,
1278: bug => 'Instructor Interface',});
1279: if ($env{'form.phase'} eq 'userpicked') {
1280: push(@{$brcrum},
1281: {href => "javascript:backPage($form,'get_user_info','select')",
1282: text => $breadcrumb_text{'userpicked'},
1283: faq => 282,
1284: bug => 'Instructor Interface',});
1285: }
1286: push(@{$brcrum},
1287: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1288: text => $breadcrumb_text{'modify'},
1289: faq => 282,
1290: bug => 'Instructor Interface',
1291: help => $helpitem});
1292: my $args = {'add_entries' => \%loaditem,
1293: 'bread_crumbs' => $brcrum,
1294: 'bread_crumbs_component' => 'User Management'};
1295: if ($env{'form.popup'}) {
1296: $args->{'no_nav_bar'} = 1;
1297: }
1298: my $start_page =
1299: &Apache::loncommon::start_page('User Management',$js,$args);
1300:
1301: my $forminfo =<<"ENDFORMINFO";
1302: <form action="/adm/createuser" method="post" name="$formname">
1303: <input type="hidden" name="phase" value="update_user_data" />
1304: <input type="hidden" name="ccuname" value="$ccuname" />
1305: <input type="hidden" name="ccdomain" value="$ccdomain" />
1306: <input type="hidden" name="pres_value" value="" />
1307: <input type="hidden" name="pres_type" value="" />
1308: <input type="hidden" name="pres_marker" value="" />
1309: ENDFORMINFO
1310: my (%inccourses,$roledom,$defaultcredits);
1311: if ($context eq 'course') {
1312: $inccourses{$env{'request.course.id'}}=1;
1313: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1314: if ($showcredits) {
1315: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1316: }
1317: } elsif ($context eq 'author') {
1318: $roledom = $env{'request.role.domain'};
1319: } elsif ($context eq 'domain') {
1320: foreach my $key (keys(%env)) {
1321: $roledom = $env{'request.role.domain'};
1322: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1323: $inccourses{$1.'_'.$2}=1;
1324: }
1325: }
1326: } else {
1327: foreach my $key (keys(%env)) {
1328: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1329: $inccourses{$1.'_'.$2}=1;
1330: }
1331: }
1332: }
1333: my $title = '';
1334: if ($newuser) {
1335: my ($portfolioform,$domroleform);
1336: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1337: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1338: # Current user has quota or user tools modification privileges
1339: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1340: }
1341: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1342: ($ccdomain eq $env{'request.role.domain'})) {
1343: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1344: }
1345: &initialize_authen_forms($ccdomain,$formname);
1346: my %lt=&Apache::lonlocal::texthash(
1347: 'lg' => 'Login Data',
1348: 'hs' => "Home Server",
1349: );
1350: $r->print(<<ENDTITLE);
1351: $start_page
1352: $response
1353: $forminfo
1354: <script type="text/javascript" language="Javascript">
1355: // <![CDATA[
1356: $loginscript
1357: // ]]>
1358: </script>
1359: <input type='hidden' name='makeuser' value='1' />
1360: ENDTITLE
1361: if ($env{'form.action'} eq 'singlestudent') {
1362: if ($crstype eq 'Community') {
1363: $title = &mt('Create New User [_1] in domain [_2] as a member',
1364: '"'.$ccuname.'"','"'.$ccdomain.'"');
1365: } else {
1366: $title = &mt('Create New User [_1] in domain [_2] as a student',
1367: '"'.$ccuname.'"','"'.$ccdomain.'"');
1368: }
1369: } else {
1370: $title = &mt('Create New User [_1] in domain [_2]',
1371: '"'.$ccuname.'"','"'.$ccdomain.'"');
1372: }
1373: $r->print('<h2>'.$title.'</h2>'."\n");
1374: $r->print('<div class="LC_left_float">');
1375: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1376: $inst_results{$ccuname.':'.$ccdomain}));
1377: # Option to disable student/employee ID conflict checking not offerred for new users.
1378: my ($home_server_pick,$numlib) =
1379: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1380: 'default','hide');
1381: if ($numlib > 1) {
1382: $r->print("
1383: <br />
1384: $lt{'hs'}: $home_server_pick
1385: <br />");
1386: } else {
1387: $r->print($home_server_pick);
1388: }
1389: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1390: $r->print('<br /><h3>'.
1391: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1392: &Apache::loncommon::start_data_table().
1393: &build_tools_display($ccuname,$ccdomain,
1394: 'requestcourses').
1395: &Apache::loncommon::end_data_table());
1396: }
1397: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1398: $lt{'lg'}.'</h3>');
1399: my ($fixedauth,$varauth,$authmsg);
1400: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1401: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1402: my ($rules,$ruleorder) =
1403: &Apache::lonnet::inst_userrules($ccdomain,'username');
1404: if (ref($rules) eq 'HASH') {
1405: if (ref($rules->{$matchedrule}) eq 'HASH') {
1406: my $authtype = $rules->{$matchedrule}{'authtype'};
1407: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1408: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1409: } else {
1410: my $authparm = $rules->{$matchedrule}{'authparm'};
1411: $authmsg = $rules->{$matchedrule}{'authmsg'};
1412: if ($authtype =~ /^krb(4|5)$/) {
1413: my $ver = $1;
1414: if ($authparm ne '') {
1415: $fixedauth = <<"KERB";
1416: <input type="hidden" name="login" value="krb" />
1417: <input type="hidden" name="krbver" value="$ver" />
1418: <input type="hidden" name="krbarg" value="$authparm" />
1419: KERB
1420: }
1421: } else {
1422: $fixedauth =
1423: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1424: if ($rules->{$matchedrule}{'authparmfixed'}) {
1425: $fixedauth .=
1426: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1427: } else {
1428: if ($authtype eq 'int') {
1429: $varauth = '<br />'.
1430: &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>';
1431: } elsif ($authtype eq 'loc') {
1432: $varauth = '<br />'.
1433: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1434: } else {
1435: $varauth =
1436: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1437: }
1438: }
1439: }
1440: }
1441: } else {
1442: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1443: }
1444: }
1445: if ($authmsg) {
1446: $r->print(<<ENDAUTH);
1447: $fixedauth
1448: $authmsg
1449: $varauth
1450: ENDAUTH
1451: }
1452: } else {
1453: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1454: }
1455: $r->print($portfolioform.$domroleform);
1456: if ($env{'form.action'} eq 'singlestudent') {
1457: $r->print(&date_sections_select($context,$newuser,$formname,
1458: $permission,$crstype,$ccuname,
1459: $ccdomain,$showcredits));
1460: }
1461: $r->print('</div><div class="LC_clear_float_footer"></div>');
1462: } else { # user already exists
1463: $r->print($start_page.$forminfo);
1464: if ($env{'form.action'} eq 'singlestudent') {
1465: if ($crstype eq 'Community') {
1466: $title = &mt('Enroll one member: [_1] in domain [_2]',
1467: '"'.$ccuname.'"','"'.$ccdomain.'"');
1468: } else {
1469: $title = &mt('Enroll one student: [_1] in domain [_2]',
1470: '"'.$ccuname.'"','"'.$ccdomain.'"');
1471: }
1472: } else {
1473: if ($permission->{'cusr'}) {
1474: $title = &mt('Modify existing user: [_1] in domain [_2]',
1475: '"'.$ccuname.'"','"'.$ccdomain.'"');
1476: } else {
1477: $title = &mt('Existing user: [_1] in domain [_2]',
1478: '"'.$ccuname.'"','"'.$ccdomain.'"');
1479: }
1480: }
1481: $r->print('<h2>'.$title.'</h2>'."\n");
1482: $r->print('<div class="LC_left_float">');
1483: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1484: $inst_results{$ccuname.':'.$ccdomain}));
1485: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1486: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1487: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1488: &Apache::loncommon::start_data_table());
1489: if ($env{'request.role.domain'} eq $ccdomain) {
1490: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1491: } else {
1492: if (&Apache::lonnet::will_trust('reqcrs',$ccdomain,$env{'request.role.domain'})) {
1493: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1494: $env{'request.role.domain'}));
1495: }
1496: }
1497: $r->print(&Apache::loncommon::end_data_table());
1498: }
1499: $r->print('</div>');
1500: my @order = ('auth','quota','tools','requestauthor');
1501: my %user_text;
1502: my ($isadv,$isauthor) =
1503: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1504: if ((!$isauthor) &&
1505: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1506: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1507: ($env{'request.role.domain'} eq $ccdomain)) {
1508: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1509: }
1510: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1511: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1512: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1513: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1514: # Current user has quota modification privileges
1515: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1516: }
1517: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1518: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1519: my %lt=&Apache::lonlocal::texthash(
1520: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1521: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1522: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1523: );
1524: $user_text{'quota'} = <<ENDNOPORTPRIV;
1525: <h3>$lt{'dska'}</h3>
1526: $lt{'youd'} $lt{'ichr'}: $ccdomain
1527: ENDNOPORTPRIV
1528: }
1529: }
1530: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1531: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1532: my %lt=&Apache::lonlocal::texthash(
1533: 'utav' => "User Tools Availability",
1534: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1535: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1536: );
1537: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1538: <h3>$lt{'utav'}</h3>
1539: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1540: ENDNOTOOLSPRIV
1541: }
1542: }
1543: my $gotdiv = 0;
1544: foreach my $item (@order) {
1545: if ($user_text{$item} ne '') {
1546: unless ($gotdiv) {
1547: $r->print('<div class="LC_left_float">');
1548: $gotdiv = 1;
1549: }
1550: $r->print('<br />'.$user_text{$item});
1551: }
1552: }
1553: if ($env{'form.action'} eq 'singlestudent') {
1554: unless ($gotdiv) {
1555: $r->print('<div class="LC_left_float">');
1556: }
1557: my $credits;
1558: if ($showcredits) {
1559: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1560: if ($credits eq '') {
1561: $credits = $defaultcredits;
1562: }
1563: }
1564: $r->print(&date_sections_select($context,$newuser,$formname,
1565: $permission,$crstype,$ccuname,
1566: $ccdomain,$showcredits));
1567: }
1568: if ($gotdiv) {
1569: $r->print('</div><div class="LC_clear_float_footer"></div>');
1570: }
1571: my $statuses;
1572: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1573: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1574: $statuses = ['active'];
1575: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1576: ($env{'request.course.sec'} &&
1577: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1578: $statuses = ['active'];
1579: }
1580: if ($env{'form.action'} ne 'singlestudent') {
1581: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1582: $roledom,$crstype,$showcredits,$statuses);
1583: }
1584: } ## End of new user/old user logic
1585: if ($env{'form.action'} eq 'singlestudent') {
1586: my $btntxt;
1587: if ($crstype eq 'Community') {
1588: $btntxt = &mt('Enroll Member');
1589: } else {
1590: $btntxt = &mt('Enroll Student');
1591: }
1592: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1593: } elsif ($permission->{'cusr'}) {
1594: $r->print('<div class="LC_left_float">'.
1595: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1596: my $addrolesdisplay = 0;
1597: if ($context eq 'domain' || $context eq 'author') {
1598: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1599: }
1600: if ($context eq 'domain') {
1601: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1602: if (!$addrolesdisplay) {
1603: $addrolesdisplay = $add_domainroles;
1604: }
1605: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1606: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1607: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1608: } elsif ($context eq 'author') {
1609: if ($addrolesdisplay) {
1610: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1611: '<br /><input type="button" value="'.&mt('Save').'"');
1612: if ($newuser) {
1613: $r->print(' onclick="auth_check()" \>'."\n");
1614: } else {
1615: $r->print('onclick="this.form.submit()" \>'."\n");
1616: }
1617: } else {
1618: $r->print('</fieldset></div>'.
1619: '<div class="LC_clear_float_footer"></div>'.
1620: '<br /><a href="javascript:backPage(document.cu)">'.
1621: &mt('Back to previous page').'</a>');
1622: }
1623: } else {
1624: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1625: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1626: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1627: }
1628: }
1629: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1630: $r->print('<input type="hidden" name="currstate" value="" />');
1631: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1632: return;
1633: }
1634:
1635: sub singleuser_breadcrumb {
1636: my ($crstype,$context,$domain) = @_;
1637: my %breadcrumb_text;
1638: if ($env{'form.action'} eq 'singlestudent') {
1639: if ($crstype eq 'Community') {
1640: $breadcrumb_text{'search'} = 'Enroll a member';
1641: } else {
1642: $breadcrumb_text{'search'} = 'Enroll a student';
1643: }
1644: $breadcrumb_text{'userpicked'} = 'Select a user';
1645: $breadcrumb_text{'modify'} = 'Set section/dates';
1646: } elsif ($env{'form.action'} eq 'accesslogs') {
1647: $breadcrumb_text{'search'} = 'View access logs for a user';
1648: $breadcrumb_text{'userpicked'} = 'Select a user';
1649: $breadcrumb_text{'activity'} = 'Activity';
1650: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1651: (!&Apache::lonnet::allowed('mau',$domain))) {
1652: $breadcrumb_text{'search'} = "View user's roles";
1653: $breadcrumb_text{'userpicked'} = 'Select a user';
1654: $breadcrumb_text{'modify'} = 'User roles';
1655: } else {
1656: $breadcrumb_text{'search'} = 'Create/modify a user';
1657: $breadcrumb_text{'userpicked'} = 'Select a user';
1658: $breadcrumb_text{'modify'} = 'Set user role';
1659: }
1660: return %breadcrumb_text;
1661: }
1662:
1663: sub date_sections_select {
1664: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1665: $showcredits) = @_;
1666: my $credits;
1667: if ($showcredits) {
1668: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1669: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1670: if ($credits eq '') {
1671: $credits = $defaultcredits;
1672: }
1673: }
1674: my $cid = $env{'request.course.id'};
1675: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1676: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1677: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1678: undef,$formname,$permission);
1679: my $rowtitle = 'Section';
1680: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1681: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1682: $permission,$context,'',$crstype,
1683: $showcredits,$credits);
1684: my $output = $date_table.$secbox;
1685: return $output;
1686: }
1687:
1688: sub validation_javascript {
1689: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1690: $loaditem) = @_;
1691: my $dc_setcourse_code = '';
1692: my $nondc_setsection_code = '';
1693: if ($context eq 'domain') {
1694: my $dcdom = $env{'request.role.domain'};
1695: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1696: $dc_setcourse_code =
1697: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1698: } else {
1699: my $checkauth;
1700: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1701: $checkauth = 1;
1702: }
1703: if ($context eq 'course') {
1704: $nondc_setsection_code =
1705: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1706: undef,$checkauth,
1707: $crstype);
1708: }
1709: if ($checkauth) {
1710: $nondc_setsection_code .=
1711: &Apache::lonuserutils::verify_authen($formname,$context);
1712: }
1713: }
1714: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1715: $nondc_setsection_code,$groupslist);
1716: my ($jsback,$elements) = &crumb_utilities();
1717: $js .= "\n".
1718: '<script type="text/javascript">'."\n".
1719: '// <![CDATA['."\n".
1720: $jsback."\n".
1721: '// ]]>'."\n".
1722: '</script>'."\n";
1723: return $js;
1724: }
1725:
1726: sub display_existing_roles {
1727: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1728: $showcredits,$statuses) = @_;
1729: my $now=time;
1730: my $showall = 1;
1731: my ($showexpired,$showactive);
1732: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1733: $showall = 0;
1734: if (grep(/^expired$/,@{$statuses})) {
1735: $showexpired = 1;
1736: }
1737: if (grep(/^active$/,@{$statuses})) {
1738: $showactive = 1;
1739: }
1740: if ($showexpired && $showactive) {
1741: $showall = 1;
1742: }
1743: }
1744: my %lt=&Apache::lonlocal::texthash(
1745: 'rer' => "Existing Roles",
1746: 'rev' => "Revoke",
1747: 'del' => "Delete",
1748: 'ren' => "Re-Enable",
1749: 'rol' => "Role",
1750: 'ext' => "Extent",
1751: 'crd' => "Credits",
1752: 'sta' => "Start",
1753: 'end' => "End",
1754: );
1755: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1756: if ($context eq 'course' || $context eq 'author') {
1757: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1758: my %roleshash =
1759: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1760: ['active','previous','future'],\@roles,$roledom,1);
1761: foreach my $key (keys(%roleshash)) {
1762: my ($start,$end) = split(':',$roleshash{$key});
1763: next if ($start eq '-1' || $end eq '-1');
1764: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1765: if ($context eq 'course') {
1766: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1767: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1768: } elsif ($context eq 'author') {
1769: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1770: }
1771: my ($newkey,$newvalue,$newrole);
1772: $newkey = '/'.$rdom.'/'.$rnum;
1773: if ($sec ne '') {
1774: $newkey .= '/'.$sec;
1775: }
1776: $newvalue = $role;
1777: if ($role =~ /^cr/) {
1778: $newrole = 'cr';
1779: } else {
1780: $newrole = $role;
1781: }
1782: $newkey .= '_'.$newrole;
1783: if ($start ne '' && $end ne '') {
1784: $newvalue .= '_'.$end.'_'.$start;
1785: } elsif ($end ne '') {
1786: $newvalue .= '_'.$end;
1787: }
1788: $rolesdump{$newkey} = $newvalue;
1789: }
1790: } else {
1791: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1792: }
1793: # Build up table of user roles to allow revocation and re-enabling of roles.
1794: my ($tmp) = keys(%rolesdump);
1795: return if ($tmp =~ /^(con_lost|error)/i);
1796: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1797: my $b1=join('_',(split('_',$b))[1,0]);
1798: return $a1 cmp $b1;
1799: } keys(%rolesdump)) {
1800: next if ($area =~ /^rolesdef/);
1801: my $envkey=$area;
1802: my $role = $rolesdump{$area};
1803: my $thisrole=$area;
1804: $area =~ s/\_\w\w$//;
1805: my ($role_code,$role_end_time,$role_start_time) =
1806: split(/_/,$role);
1807: my $active=1;
1808: $active=0 if (($role_end_time) && ($now>$role_end_time));
1809: if ($active) {
1810: next unless($showall || $showactive);
1811: } else {
1812: next unless($showall || $showexpired);
1813: }
1814: # Is this a custom role? Get role owner and title.
1815: my ($croleudom,$croleuname,$croletitle)=
1816: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1817: my $allowed=0;
1818: my $delallowed=0;
1819: my $sortkey=$role_code;
1820: my $class='Unknown';
1821: my $credits='';
1822: my $csec;
1823: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1824: $class='Course';
1825: my ($coursedom,$coursedir) = ($1,$2);
1826: my $cid = $1.'_'.$2;
1827: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1828: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1829: my %coursedata=
1830: &Apache::lonnet::coursedescription($cid);
1831: if ($coursedir =~ /^$match_community$/) {
1832: $class='Community';
1833: }
1834: $sortkey.="\0$coursedom";
1835: my $carea;
1836: if (defined($coursedata{'description'})) {
1837: $carea=$coursedata{'description'}.
1838: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1839: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1840: $sortkey.="\0".$coursedata{'description'};
1841: } else {
1842: if ($class eq 'Community') {
1843: $carea=&mt('Unavailable community').': '.$area;
1844: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1845: } else {
1846: $carea=&mt('Unavailable course').': '.$area;
1847: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1848: }
1849: }
1850: $sortkey.="\0$coursedir";
1851: $inccourses->{$cid}=1;
1852: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1853: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1854: $credits =
1855: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1856: $coursedom,$coursedir);
1857: if ($credits eq '') {
1858: $credits = $defaultcredits;
1859: }
1860: }
1861: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1862: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1863: $allowed=1;
1864: }
1865: unless ($allowed) {
1866: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1867: if ($isowner) {
1868: if (($role_code eq 'co') && ($class eq 'Community')) {
1869: $allowed = 1;
1870: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1871: $allowed = 1;
1872: }
1873: }
1874: }
1875: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1876: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1877: $delallowed=1;
1878: }
1879: # - custom role. Needs more info, too
1880: if ($croletitle) {
1881: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1882: $allowed=1;
1883: $thisrole.='.'.$role_code;
1884: }
1885: }
1886: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1887: $csec = $2;
1888: $carea.='<br />'.&mt('Section: [_1]',$csec);
1889: $sortkey.="\0$csec";
1890: if (!$allowed) {
1891: if ($env{'request.course.sec'} eq $csec) {
1892: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1893: $allowed = 1;
1894: }
1895: }
1896: }
1897: }
1898: $area=$carea;
1899: } else {
1900: $sortkey.="\0".$area;
1901: # Determine if current user is able to revoke privileges
1902: if ($area=~m{^/($match_domain)/}) {
1903: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1904: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1905: $allowed=1;
1906: }
1907: if (((&Apache::lonnet::allowed('dro',$1)) ||
1908: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1909: ($role_code ne 'dc')) {
1910: $delallowed=1;
1911: }
1912: } else {
1913: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1914: $allowed=1;
1915: }
1916: }
1917: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1918: $class='Authoring Space';
1919: } elsif ($role_code eq 'su') {
1920: $class='System';
1921: } else {
1922: $class='Domain';
1923: }
1924: }
1925: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1926: $area=~m{/($match_domain)/($match_username)};
1927: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1928: $allowed=1;
1929: } else {
1930: $allowed=0;
1931: }
1932: }
1933: my $row = '';
1934: if ($showall) {
1935: $row.= '<td>';
1936: if (($active) && ($allowed)) {
1937: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1938: } else {
1939: if ($active) {
1940: $row.=' ';
1941: } else {
1942: $row.=&mt('expired or revoked');
1943: }
1944: }
1945: $row.='</td><td>';
1946: if ($allowed && !$active) {
1947: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1948: } else {
1949: $row.=' ';
1950: }
1951: $row.='</td><td>';
1952: if ($delallowed) {
1953: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1954: } else {
1955: $row.=' ';
1956: }
1957: $row.= '</td>';
1958: }
1959: my $plaintext='';
1960: if (!$croletitle) {
1961: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1962: if (($showcredits) && ($credits ne '')) {
1963: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1964: '<span class="LC_fontsize_small">'.
1965: &mt('Credits: [_1]',$credits).
1966: '</span></span>';
1967: }
1968: } else {
1969: $plaintext=
1970: &mt('Custom role [_1][_2]defined by [_3]',
1971: '"'.$croletitle.'"',
1972: '<br />',
1973: $croleuname.':'.$croleudom);
1974: }
1975: $row.= '<td>'.$plaintext.'</td>'.
1976: '<td>'.$area.'</td>'.
1977: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1978: : ' ' ).'</td>'.
1979: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1980: : ' ' ).'</td>';
1981: $sortrole{$sortkey}=$envkey;
1982: $roletext{$envkey}=$row;
1983: $roleclass{$envkey}=$class;
1984: if ($allowed) {
1985: $rolepriv{$envkey}='edit';
1986: } else {
1987: if ($context eq 'domain') {
1988: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1989: ($envkey=~m{^/$ccdomain/})) {
1990: $rolepriv{$envkey}='view';
1991: }
1992: } elsif ($context eq 'course') {
1993: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1994: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
1995: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
1996: $rolepriv{$envkey}='view';
1997: }
1998: }
1999: }
2000: } # end of foreach (table building loop)
2001:
2002: my $rolesdisplay = 0;
2003: my %output = ();
2004: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
2005: $output{$type} = '';
2006: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2007: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2008: $output{$type}.=
2009: &Apache::loncommon::start_data_table_row().
2010: $roletext{$sortrole{$which}}.
2011: &Apache::loncommon::end_data_table_row();
2012: }
2013: }
2014: unless($output{$type} eq '') {
2015: $output{$type} = '<tr class="LC_info_row">'.
2016: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2017: $output{$type};
2018: $rolesdisplay = 1;
2019: }
2020: }
2021: if ($rolesdisplay == 1) {
2022: my $contextrole='';
2023: if ($env{'request.course.id'}) {
2024: if (&Apache::loncommon::course_type() eq 'Community') {
2025: $contextrole = &mt('Existing Roles in this Community');
2026: } else {
2027: $contextrole = &mt('Existing Roles in this Course');
2028: }
2029: } elsif ($env{'request.role'} =~ /^au\./) {
2030: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
2031: } else {
2032: if ($showall) {
2033: $contextrole = &mt('Existing Roles in this Domain');
2034: } elsif ($showactive) {
2035: $contextrole = &mt('Unexpired Roles in this Domain');
2036: } elsif ($showexpired) {
2037: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2038: }
2039: }
2040: $r->print('<div class="LC_left_float">'.
2041: '<fieldset><legend>'.$contextrole.'</legend>'.
2042: &Apache::loncommon::start_data_table("LC_createuser").
2043: &Apache::loncommon::start_data_table_header_row());
2044: if ($showall) {
2045: $r->print(
2046: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
2047: );
2048: } elsif ($showexpired) {
2049: $r->print('<th>'.$lt{'rev'}.'</th>');
2050: }
2051: $r->print(
2052: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2053: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
2054: &Apache::loncommon::end_data_table_header_row());
2055: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
2056: if ($output{$type}) {
2057: $r->print($output{$type}."\n");
2058: }
2059: }
2060: $r->print(&Apache::loncommon::end_data_table().
2061: '</fieldset></div>');
2062: }
2063: return;
2064: }
2065:
2066: sub new_coauthor_roles {
2067: my ($r,$ccuname,$ccdomain) = @_;
2068: my $addrolesdisplay = 0;
2069: #
2070: # Co-Author
2071: #
2072: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2073: $env{'request.role.domain'}) &&
2074: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2075: # No sense in assigning co-author role to yourself
2076: $addrolesdisplay = 1;
2077: my $cuname=$env{'user.name'};
2078: my $cudom=$env{'request.role.domain'};
2079: my %lt=&Apache::lonlocal::texthash(
2080: 'cs' => "Authoring Space",
2081: 'act' => "Activate",
2082: 'rol' => "Role",
2083: 'ext' => "Extent",
2084: 'sta' => "Start",
2085: 'end' => "End",
2086: 'cau' => "Co-Author",
2087: 'caa' => "Assistant Co-Author",
2088: 'ssd' => "Set Start Date",
2089: 'sed' => "Set End Date"
2090: );
2091: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2092: &Apache::loncommon::start_data_table()."\n".
2093: &Apache::loncommon::start_data_table_header_row()."\n".
2094: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2095: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2096: '<th>'.$lt{'end'}.'</th>'."\n".
2097: &Apache::loncommon::end_data_table_header_row()."\n".
2098: &Apache::loncommon::start_data_table_row().'
2099: <td>
2100: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
2101: </td>
2102: <td>'.$lt{'cau'}.'</td>
2103: <td>'.$cudom.'_'.$cuname.'</td>
2104: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2105: <a href=
2106: "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>
2107: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2108: <a href=
2109: "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".
2110: &Apache::loncommon::end_data_table_row()."\n".
2111: &Apache::loncommon::start_data_table_row()."\n".
2112: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
2113: <td>'.$lt{'caa'}.'</td>
2114: <td>'.$cudom.'_'.$cuname.'</td>
2115: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2116: <a href=
2117: "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>
2118: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2119: <a href=
2120: "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".
2121: &Apache::loncommon::end_data_table_row()."\n".
2122: &Apache::loncommon::end_data_table());
2123: } elsif ($env{'request.role'} =~ /^au\./) {
2124: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2125: $env{'request.role.domain'}))) {
2126: $r->print('<span class="LC_error">'.
2127: &mt('You do not have privileges to assign co-author roles.').
2128: '</span>');
2129: } elsif (($env{'user.name'} eq $ccuname) &&
2130: ($env{'user.domain'} eq $ccdomain)) {
2131: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Authoring Space is not permitted'));
2132: }
2133: }
2134: return $addrolesdisplay;;
2135: }
2136:
2137: sub new_domain_roles {
2138: my ($r,$ccdomain) = @_;
2139: my $addrolesdisplay = 0;
2140: #
2141: # Domain level
2142: #
2143: my $num_domain_level = 0;
2144: my $domaintext =
2145: '<h4>'.&mt('Domain Level').'</h4>'.
2146: &Apache::loncommon::start_data_table().
2147: &Apache::loncommon::start_data_table_header_row().
2148: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2149: &mt('Extent').'</th>'.
2150: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2151: &Apache::loncommon::end_data_table_header_row();
2152: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
2153: my $uprimary = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2154: my $uintdom = &Apache::lonnet::internet_dom($uprimary);
2155: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
2156: foreach my $role (@allroles) {
2157: next if ($role eq 'ad');
2158: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
2159: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2160: if ($role eq 'dc') {
2161: unless ($thisdomain eq $env{'request.role.domain'}) {
2162: my $domprim = &Apache::lonnet::domain($thisdomain,'primary');
2163: my $intdom = &Apache::lonnet::internet_dom($domprim);
2164: next unless ($uintdom eq $intdom);
2165: }
2166: }
2167: my $plrole=&Apache::lonnet::plaintext($role);
2168: my %lt=&Apache::lonlocal::texthash(
2169: 'ssd' => "Set Start Date",
2170: 'sed' => "Set End Date"
2171: );
2172: $num_domain_level ++;
2173: $domaintext .=
2174: &Apache::loncommon::start_data_table_row().
2175: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
2176: <td>'.$plrole.'</td>
2177: <td>'.$thisdomain.'</td>
2178: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2179: <a href=
2180: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2181: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2182: <a href=
2183: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2184: &Apache::loncommon::end_data_table_row();
2185: }
2186: }
2187: }
2188: $domaintext.= &Apache::loncommon::end_data_table();
2189: if ($num_domain_level > 0) {
2190: $r->print($domaintext);
2191: $addrolesdisplay = 1;
2192: }
2193: return $addrolesdisplay;
2194: }
2195:
2196: sub user_authentication {
2197: my ($ccuname,$ccdomain,$formname) = @_;
2198: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
2199: my $outcome;
2200: my %lt=&Apache::lonlocal::texthash(
2201: 'err' => "ERROR",
2202: 'uuas' => "This user has an unrecognized authentication scheme",
2203: 'adcs' => "Please alert a domain coordinator of this situation",
2204: 'sldb' => "Please specify login data below",
2205: 'ld' => "Login Data"
2206: );
2207: # Check for a bad authentication type
2208: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth|lti):/) {
2209: # bad authentication scheme
2210: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2211: &initialize_authen_forms($ccdomain,$formname);
2212:
2213: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
2214: $outcome = <<ENDBADAUTH;
2215: <script type="text/javascript" language="Javascript">
2216: // <![CDATA[
2217: $loginscript
2218: // ]]>
2219: </script>
2220: <span class="LC_error">$lt{'err'}:
2221: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2222: <h3>$lt{'ld'}</h3>
2223: $choices
2224: ENDBADAUTH
2225: } else {
2226: # This user is not allowed to modify the user's
2227: # authentication scheme, so just notify them of the problem
2228: $outcome = <<ENDBADAUTH;
2229: <span class="LC_error"> $lt{'err'}:
2230: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2231: </span>
2232: ENDBADAUTH
2233: }
2234: } else { # Authentication type is valid
2235:
2236: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
2237: my ($authformcurrent,$can_modify,@authform_others) =
2238: &modify_login_block($ccdomain,$currentauth);
2239: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2240: # Current user has login modification privileges
2241: $outcome =
2242: '<script type="text/javascript" language="Javascript">'."\n".
2243: '// <![CDATA['."\n".
2244: $loginscript."\n".
2245: '// ]]>'."\n".
2246: '</script>'."\n".
2247: '<h3>'.$lt{'ld'}.'</h3>'.
2248: &Apache::loncommon::start_data_table().
2249: &Apache::loncommon::start_data_table_row().
2250: '<td>'.$authformnop;
2251: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
2252: $outcome .= '</td>'."\n".
2253: &Apache::loncommon::end_data_table_row().
2254: &Apache::loncommon::start_data_table_row().
2255: '<td>'.$authformcurrent.'</td>'.
2256: &Apache::loncommon::end_data_table_row()."\n";
2257: } else {
2258: $outcome .= ' ('.$authformcurrent.')</td>'.
2259: &Apache::loncommon::end_data_table_row()."\n";
2260: }
2261: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2262: foreach my $item (@authform_others) {
2263: $outcome .= &Apache::loncommon::start_data_table_row().
2264: '<td>'.$item.'</td>'.
2265: &Apache::loncommon::end_data_table_row()."\n";
2266: }
2267: }
2268: $outcome .= &Apache::loncommon::end_data_table();
2269: } else {
2270: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2271: # Current user has rights to view domain preferences for user's domain
2272: my $result;
2273: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2274: my ($krbver,$krbrealm) = ($1,$2);
2275: if ($krbrealm eq '') {
2276: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2277: } else {
2278: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2279: $krbrealm,$krbver);
2280: }
2281: } elsif ($currentauth =~ /^internal:/) {
2282: $result = &mt('Currently internally authenticated.');
2283: } elsif ($currentauth =~ /^localauth:/) {
2284: $result = &mt('Currently using local (institutional) authentication.');
2285: } elsif ($currentauth =~ /^unix:/) {
2286: $result = &mt('Currently Filesystem Authenticated.');
2287: } elsif ($currentauth =~ /^lti:/) {
2288: $result = &mt('Currently LTi authenticated.');
2289: }
2290: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2291: &Apache::loncommon::start_data_table().
2292: &Apache::loncommon::start_data_table_row().
2293: '<td>'.$result.'</td>'.
2294: &Apache::loncommon::end_data_table_row()."\n".
2295: &Apache::loncommon::end_data_table();
2296: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
2297: my %lt=&Apache::lonlocal::texthash(
2298: 'ccld' => "Change Current Login Data",
2299: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2300: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2301: );
2302: $outcome .= <<ENDNOPRIV;
2303: <h3>$lt{'ccld'}</h3>
2304: $lt{'yodo'} $lt{'ifch'}: $ccdomain
2305: <input type="hidden" name="login" value="nochange" />
2306: ENDNOPRIV
2307: }
2308: }
2309: } ## End of "check for bad authentication type" logic
2310: return $outcome;
2311: }
2312:
2313: sub modify_login_block {
2314: my ($dom,$currentauth) = @_;
2315: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2316: my ($authnum,%can_assign) =
2317: &Apache::loncommon::get_assignable_auth($dom);
2318: my ($authformcurrent,@authform_others,$show_override_msg);
2319: if ($currentauth=~/^krb(4|5):/) {
2320: $authformcurrent=$authformkrb;
2321: if ($can_assign{'int'}) {
2322: push(@authform_others,$authformint);
2323: }
2324: if ($can_assign{'loc'}) {
2325: push(@authform_others,$authformloc);
2326: }
2327: if ($can_assign{'lti'}) {
2328: push(@authform_others,$authformlti);
2329: }
2330: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2331: $show_override_msg = 1;
2332: }
2333: } elsif ($currentauth=~/^internal:/) {
2334: $authformcurrent=$authformint;
2335: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2336: push(@authform_others,$authformkrb);
2337: }
2338: if ($can_assign{'loc'}) {
2339: push(@authform_others,$authformloc);
2340: }
2341: if ($can_assign{'lti'}) {
2342: push(@authform_others,$authformlti);
2343: }
2344: if ($can_assign{'int'}) {
2345: $show_override_msg = 1;
2346: }
2347: } elsif ($currentauth=~/^unix:/) {
2348: $authformcurrent=$authformfsys;
2349: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2350: push(@authform_others,$authformkrb);
2351: }
2352: if ($can_assign{'int'}) {
2353: push(@authform_others,$authformint);
2354: }
2355: if ($can_assign{'loc'}) {
2356: push(@authform_others,$authformloc);
2357: }
2358: if ($can_assign{'lti'}) {
2359: push(@authform_others,$authformlti);
2360: }
2361: if ($can_assign{'fsys'}) {
2362: $show_override_msg = 1;
2363: }
2364: } elsif ($currentauth=~/^localauth:/) {
2365: $authformcurrent=$authformloc;
2366: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2367: push(@authform_others,$authformkrb);
2368: }
2369: if ($can_assign{'int'}) {
2370: push(@authform_others,$authformint);
2371: }
2372: if ($can_assign{'lti'}) {
2373: push(@authform_others,$authformlti);
2374: }
2375: if ($can_assign{'loc'}) {
2376: $show_override_msg = 1;
2377: }
2378: } elsif ($currentauth=~/^lti:/) {
2379: $authformcurrent=$authformlti;
2380: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2381: push(@authform_others,$authformkrb);
2382: }
2383: if ($can_assign{'int'}) {
2384: push(@authform_others,$authformint);
2385: }
2386: if ($can_assign{'loc'}) {
2387: push(@authform_others,$authformloc);
2388: }
2389: }
2390: if ($show_override_msg) {
2391: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2392: '</td></tr>'."\n".
2393: '<tr><td> </td>'.
2394: '<td><b>'.&mt('Currently in use').'</b></td>'.
2395: '<td align="right"><span class="LC_cusr_emph">'.
2396: &mt('will override current values').
2397: '</span></td></tr></table>';
2398: }
2399: return ($authformcurrent,$show_override_msg,@authform_others);
2400: }
2401:
2402: sub personal_data_display {
2403: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
2404: $now,$captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded) = @_;
2405: my ($output,%userenv,%canmodify,%canmodify_status);
2406: my @userinfo = ('firstname','middlename','lastname','generation',
2407: 'permanentemail','id');
2408: my $rowcount = 0;
2409: my $editable = 0;
2410: my %textboxsize = (
2411: firstname => '15',
2412: middlename => '15',
2413: lastname => '15',
2414: generation => '5',
2415: permanentemail => '25',
2416: id => '15',
2417: );
2418:
2419: my %lt=&Apache::lonlocal::texthash(
2420: 'pd' => "Personal Data",
2421: 'firstname' => "First Name",
2422: 'middlename' => "Middle Name",
2423: 'lastname' => "Last Name",
2424: 'generation' => "Generation",
2425: 'permanentemail' => "Permanent e-mail address",
2426: 'id' => "Student/Employee ID",
2427: 'lg' => "Login Data",
2428: 'inststatus' => "Affiliation",
2429: 'email' => 'E-mail address',
2430: 'valid' => 'Validation',
2431: 'username' => 'Username',
2432: );
2433:
2434: %canmodify_status =
2435: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2436: ['inststatus'],$rolesarray);
2437: if (!$newuser) {
2438: # Get the users information
2439: %userenv = &Apache::lonnet::get('environment',
2440: ['firstname','middlename','lastname','generation',
2441: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
2442: %canmodify =
2443: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2444: \@userinfo,$rolesarray);
2445: } elsif ($context eq 'selfcreate') {
2446: if ($newuser eq 'email') {
2447: if (ref($emailusername) eq 'HASH') {
2448: if (ref($emailusername->{$usertype}) eq 'HASH') {
2449: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
2450: @userinfo = ();
2451: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2452: foreach my $field (@{$infofields}) {
2453: if ($emailusername->{$usertype}->{$field}) {
2454: push(@userinfo,$field);
2455: $canmodify{$field} = 1;
2456: unless ($textboxsize{$field}) {
2457: $textboxsize{$field} = 25;
2458: }
2459: unless ($lt{$field}) {
2460: $lt{$field} = $infotitles->{$field};
2461: }
2462: if ($emailusername->{$usertype}->{$field} eq 'required') {
2463: $lt{$field} .= '<b>*</b>';
2464: }
2465: }
2466: }
2467: }
2468: }
2469: }
2470: } else {
2471: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2472: $inst_results,$rolesarray);
2473: }
2474: }
2475:
2476: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2477: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2478: &Apache::lonhtmlcommon::start_pick_box();
2479: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2480: my $size = 25;
2481: if ($condition) {
2482: if ($condition =~ /^\@[^\@]+$/) {
2483: $size = 10;
2484: } else {
2485: undef($condition);
2486: }
2487: }
2488: if ($excluded) {
2489: unless ($excluded =~ /^\@[^\@]+$/) {
2490: undef($condition);
2491: }
2492: }
2493: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
2494: 'LC_oddrow_value')."\n".
2495: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2496: if ($condition) {
2497: $output .= $condition;
2498: } elsif ($excluded) {
2499: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2500: $excluded).'</span>';
2501: }
2502: if ($usernameset eq 'first') {
2503: $output .= '<br /><span style="font-size: smaller">';
2504: if ($condition) {
2505: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2506: $condition);
2507: } else {
2508: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2509: }
2510: $output .= '</span>';
2511: }
2512: $rowcount ++;
2513: $output .= &Apache::lonhtmlcommon::row_closure(1);
2514: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2515: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
2516: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
2517: 'LC_pick_box_title',
2518: 'LC_oddrow_value')."\n".
2519: $upassone."\n".
2520: &Apache::lonhtmlcommon::row_closure(1)."\n".
2521: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
2522: 'LC_pick_box_title',
2523: 'LC_oddrow_value')."\n".
2524: $upasstwo.
2525: &Apache::lonhtmlcommon::row_closure()."\n";
2526: if ($usernameset eq 'free') {
2527: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
2528: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
2529: &mt('Use e-mail address: ').
2530: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.&mt('Yes').'</label>'."\n".
2531: (' 'x2).
2532: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.&mt('No').'</label>'."\n".
2533: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2534: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2535: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2536: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2537: $rowcount ++;
2538: }
2539: }
2540: foreach my $item (@userinfo) {
2541: my $rowtitle = $lt{$item};
2542: my $hiderow = 0;
2543: if ($item eq 'generation') {
2544: $rowtitle = $genhelp.$rowtitle;
2545: }
2546: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
2547: if ($newuser) {
2548: if (ref($inst_results) eq 'HASH') {
2549: if ($inst_results->{$item} ne '') {
2550: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
2551: } else {
2552: if ($context eq 'selfcreate') {
2553: if ($canmodify{$item}) {
2554: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
2555: $editable ++;
2556: } else {
2557: $hiderow = 1;
2558: }
2559: } else {
2560: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2561: }
2562: }
2563: } else {
2564: if ($context eq 'selfcreate') {
2565: if ($canmodify{$item}) {
2566: if ($newuser eq 'email') {
2567: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
2568: } else {
2569: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
2570: }
2571: $editable ++;
2572: } else {
2573: $hiderow = 1;
2574: }
2575: } else {
2576: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2577: }
2578: }
2579: } else {
2580: if ($canmodify{$item}) {
2581: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
2582: if (($item eq 'id') && (!$newuser)) {
2583: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2584: }
2585: } else {
2586: $row .= $userenv{$item};
2587: }
2588: }
2589: $row .= &Apache::lonhtmlcommon::row_closure(1);
2590: if (!$hiderow) {
2591: $output .= $row;
2592: $rowcount ++;
2593: }
2594: }
2595: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2596: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2597: if (ref($types) eq 'ARRAY') {
2598: if (@{$types} > 0) {
2599: my ($hiderow,$shown);
2600: if ($canmodify_status{'inststatus'}) {
2601: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2602: } else {
2603: if ($userenv{'inststatus'} eq '') {
2604: $hiderow = 1;
2605: } else {
2606: my @showitems;
2607: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2608: if (exists($usertypes->{$item})) {
2609: push(@showitems,$usertypes->{$item});
2610: } else {
2611: push(@showitems,$item);
2612: }
2613: }
2614: if (@showitems) {
2615: $shown = join(', ',@showitems);
2616: } else {
2617: $hiderow = 1;
2618: }
2619: }
2620: }
2621: if (!$hiderow) {
2622: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
2623: $shown.&Apache::lonhtmlcommon::row_closure(1);
2624: if ($context eq 'selfcreate') {
2625: $rowcount ++;
2626: }
2627: $output .= $row;
2628: }
2629: }
2630: }
2631: }
2632: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2633: if ($captchaform) {
2634: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2635: 'LC_pick_box_title')."\n".
2636: $captchaform."\n".'<br /><br />'.
2637: &Apache::lonhtmlcommon::row_closure(1);
2638: $rowcount ++;
2639: }
2640: my $submit_text = &mt('Create account');
2641: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2642: '<br /><input type="submit" name="createaccount" value="'.
2643: $submit_text.'" />'.
2644: '<input type="hidden" name="type" value="'.$usertype.'" />'.
2645: &Apache::lonhtmlcommon::row_closure(1);
2646: }
2647: $output .= &Apache::lonhtmlcommon::end_pick_box();
2648: if (wantarray) {
2649: if ($context eq 'selfcreate') {
2650: return($output,$rowcount,$editable);
2651: } else {
2652: return $output;
2653: }
2654: } else {
2655: return $output;
2656: }
2657: }
2658:
2659: sub pick_inst_statuses {
2660: my ($curr,$usertypes,$types) = @_;
2661: my ($output,$rem,@currtypes);
2662: if ($curr ne '') {
2663: @currtypes = map { &unescape($_); } split(/:/,$curr);
2664: }
2665: my $numinrow = 2;
2666: if (ref($types) eq 'ARRAY') {
2667: $output = '<table>';
2668: my $lastcolspan;
2669: for (my $i=0; $i<@{$types}; $i++) {
2670: if (defined($usertypes->{$types->[$i]})) {
2671: my $rem = $i%($numinrow);
2672: if ($rem == 0) {
2673: if ($i<@{$types}-1) {
2674: if ($i > 0) {
2675: $output .= '</tr>';
2676: }
2677: $output .= '<tr>';
2678: }
2679: } elsif ($i==@{$types}-1) {
2680: my $colsleft = $numinrow - $rem;
2681: if ($colsleft > 1) {
2682: $lastcolspan = ' colspan="'.$colsleft.'"';
2683: }
2684: }
2685: my $check = ' ';
2686: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2687: $check = ' checked="checked" ';
2688: }
2689: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2690: '<span class="LC_nobreak"><label>'.
2691: '<input type="checkbox" name="inststatus" '.
2692: 'value="'.$types->[$i].'"'.$check.'/>'.
2693: $usertypes->{$types->[$i]}.'</label></span></td>';
2694: }
2695: }
2696: $output .= '</tr></table>';
2697: }
2698: return $output;
2699: }
2700:
2701: sub selfcreate_canmodify {
2702: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2703: if (ref($inst_results) eq 'HASH') {
2704: my @inststatuses = &get_inststatuses($inst_results);
2705: if (@inststatuses == 0) {
2706: @inststatuses = ('default');
2707: }
2708: $rolesarray = \@inststatuses;
2709: }
2710: my %canmodify =
2711: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2712: $rolesarray);
2713: return %canmodify;
2714: }
2715:
2716: sub get_inststatuses {
2717: my ($insthashref) = @_;
2718: my @inststatuses = ();
2719: if (ref($insthashref) eq 'HASH') {
2720: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2721: @inststatuses = @{$insthashref->{'inststatus'}};
2722: }
2723: }
2724: return @inststatuses;
2725: }
2726:
2727: # ================================================================= Phase Three
2728: sub update_user_data {
2729: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
2730: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2731: $env{'form.ccdomain'});
2732: # Error messages
2733: my $error = '<span class="LC_error">'.&mt('Error').': ';
2734: my $end = '</span><br /><br />';
2735: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
2736: "'$env{'form.prevphase'}','modify')".'" />'.
2737: &mt('Return to previous page').'</a>'.
2738: &Apache::loncommon::end_page();
2739: my $now = time;
2740: my $title;
2741: if (exists($env{'form.makeuser'})) {
2742: $title='Set Privileges for New User';
2743: } else {
2744: $title='Modify User Privileges';
2745: }
2746: my $newuser = 0;
2747: my ($jsback,$elements) = &crumb_utilities();
2748: my $jscript = '<script type="text/javascript">'."\n".
2749: '// <![CDATA['."\n".
2750: $jsback."\n".
2751: '// ]]>'."\n".
2752: '</script>'."\n";
2753: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
2754: push (@{$brcrum},
2755: {href => "javascript:backPage(document.userupdate)",
2756: text => $breadcrumb_text{'search'},
2757: faq => 282,
2758: bug => 'Instructor Interface',}
2759: );
2760: if ($env{'form.prevphase'} eq 'userpicked') {
2761: push(@{$brcrum},
2762: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2763: text => $breadcrumb_text{'userpicked'},
2764: faq => 282,
2765: bug => 'Instructor Interface',});
2766: }
2767: my $helpitem = 'Course_Change_Privileges';
2768: if ($env{'form.action'} eq 'singlestudent') {
2769: $helpitem = 'Course_Add_Student';
2770: } elsif ($context eq 'author') {
2771: $helpitem = 'Author_Change_Privileges';
2772: } elsif ($context eq 'domain') {
2773: $helpitem = 'Domain_Change_Privileges';
2774: }
2775: push(@{$brcrum},
2776: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2777: text => $breadcrumb_text{'modify'},
2778: faq => 282,
2779: bug => 'Instructor Interface',},
2780: {href => "/adm/createuser",
2781: text => "Result",
2782: faq => 282,
2783: bug => 'Instructor Interface',
2784: help => $helpitem});
2785: my $args = {bread_crumbs => $brcrum,
2786: bread_crumbs_component => 'User Management'};
2787: if ($env{'form.popup'}) {
2788: $args->{'no_nav_bar'} = 1;
2789: }
2790: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
2791: $r->print(&update_result_form($uhome));
2792: # Check Inputs
2793: if (! $env{'form.ccuname'} ) {
2794: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
2795: return;
2796: }
2797: if ( $env{'form.ccuname'} ne
2798: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
2799: $r->print($error.&mt('Invalid login name.').' '.
2800: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
2801: $end.$rtnlink);
2802: return;
2803: }
2804: if (! $env{'form.ccdomain'} ) {
2805: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
2806: return;
2807: }
2808: if ( $env{'form.ccdomain'} ne
2809: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
2810: $r->print($error.&mt('Invalid domain name.').' '.
2811: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
2812: $end.$rtnlink);
2813: return;
2814: }
2815: if ($uhome eq 'no_host') {
2816: $newuser = 1;
2817: }
2818: if (! exists($env{'form.makeuser'})) {
2819: # Modifying an existing user, so check the validity of the name
2820: if ($uhome eq 'no_host') {
2821: $r->print(
2822: $error
2823: .'<p class="LC_error">'
2824: .&mt('Unable to determine home server for [_1] in domain [_2].',
2825: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2826: .'</p>');
2827: return;
2828: }
2829: }
2830: # Determine authentication method and password for the user being modified
2831: my $amode='';
2832: my $genpwd='';
2833: if ($env{'form.login'} eq 'krb') {
2834: $amode='krb';
2835: $amode.=$env{'form.krbver'};
2836: $genpwd=$env{'form.krbarg'};
2837: } elsif ($env{'form.login'} eq 'int') {
2838: $amode='internal';
2839: $genpwd=$env{'form.intarg'};
2840: } elsif ($env{'form.login'} eq 'fsys') {
2841: $amode='unix';
2842: $genpwd=$env{'form.fsysarg'};
2843: } elsif ($env{'form.login'} eq 'loc') {
2844: $amode='localauth';
2845: $genpwd=$env{'form.locarg'};
2846: $genpwd=" " if (!$genpwd);
2847: } elsif ($env{'form.login'} eq 'lti') {
2848: $amode='lti';
2849: $genpwd=" ";
2850: } elsif (($env{'form.login'} eq 'nochange') ||
2851: ($env{'form.login'} eq '' )) {
2852: # There is no need to tell the user we did not change what they
2853: # did not ask us to change.
2854: # If they are creating a new user but have not specified login
2855: # information this will be caught below.
2856: } else {
2857: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2858: return;
2859: }
2860:
2861: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
2862: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2863: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2864: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
2865:
2866: my (%alerts,%rulematch,%inst_results,%curr_rules);
2867: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
2868: my @usertools = ('aboutme','blog','webdav','portfolio');
2869: my @requestcourses = ('official','unofficial','community','textbook','placement','lti');
2870: my @requestauthor = ('requestauthor');
2871: my ($othertitle,$usertypes,$types) =
2872: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
2873: my %canmodify_status =
2874: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2875: ['inststatus']);
2876: if ($env{'form.makeuser'}) {
2877: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
2878: # Check for the authentication mode and password
2879: if (! $amode || ! $genpwd) {
2880: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2881: return;
2882: }
2883: # Determine desired host
2884: my $desiredhost = $env{'form.hserver'};
2885: if (lc($desiredhost) eq 'default') {
2886: $desiredhost = undef;
2887: } else {
2888: my %home_servers =
2889: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
2890: if (! exists($home_servers{$desiredhost})) {
2891: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2892: return;
2893: }
2894: }
2895: # Check ID format
2896: my %checkhash;
2897: my %checks = ('id' => 1);
2898: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
2899: 'newuser' => $newuser,
2900: 'id' => $env{'form.cid'},
2901: );
2902: if ($env{'form.cid'} ne '') {
2903: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2904: \%rulematch,\%inst_results,\%curr_rules);
2905: if (ref($alerts{'id'}) eq 'HASH') {
2906: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2907: my $domdesc =
2908: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2909: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2910: my $userchkmsg;
2911: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2912: $userchkmsg =
2913: &Apache::loncommon::instrule_disallow_msg('id',
2914: $domdesc,1).
2915: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2916: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2917: }
2918: $r->print($error.&mt('Invalid ID format').$end.
2919: $userchkmsg.$rtnlink);
2920: return;
2921: }
2922: }
2923: }
2924: }
2925: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
2926: # Call modifyuser
2927: my $result = &Apache::lonnet::modifyuser
2928: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
2929: $amode,$genpwd,$env{'form.cfirstname'},
2930: $env{'form.cmiddlename'},$env{'form.clastname'},
2931: $env{'form.cgeneration'},undef,$desiredhost,
2932: $env{'form.cpermanentemail'});
2933: $r->print(&mt('Generating user').': '.$result);
2934: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
2935: $env{'form.ccdomain'});
2936: my (%changeHash,%newcustom,%changed,%changedinfo);
2937: if ($uhome ne 'no_host') {
2938: if ($context eq 'domain') {
2939: foreach my $name ('portfolio','author') {
2940: if ($env{'form.custom_'.$name.'quota'} == 1) {
2941: if ($env{'form.'.$name.'quota'} eq '') {
2942: $newcustom{$name.'quota'} = 0;
2943: } else {
2944: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2945: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2946: }
2947: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2948: $changed{$name.'quota'} = 1;
2949: }
2950: }
2951: }
2952: foreach my $item (@usertools) {
2953: if ($env{'form.custom'.$item} == 1) {
2954: $newcustom{$item} = $env{'form.tools_'.$item};
2955: $changed{$item} = &tool_admin($item,$newcustom{$item},
2956: \%changeHash,'tools');
2957: }
2958: }
2959: foreach my $item (@requestcourses) {
2960: if ($env{'form.custom'.$item} == 1) {
2961: $newcustom{$item} = $env{'form.crsreq_'.$item};
2962: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2963: $newcustom{$item} .= '=';
2964: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2965: if ($env{'form.crsreq_'.$item.'_limit'}) {
2966: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2967: }
2968: }
2969: $changed{$item} = &tool_admin($item,$newcustom{$item},
2970: \%changeHash,'requestcourses');
2971: }
2972: }
2973: if ($env{'form.customrequestauthor'} == 1) {
2974: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2975: $changed{'requestauthor'} = &tool_admin('requestauthor',
2976: $newcustom{'requestauthor'},
2977: \%changeHash,'requestauthor');
2978: }
2979: }
2980: if ($canmodify_status{'inststatus'}) {
2981: if (exists($env{'form.inststatus'})) {
2982: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2983: if (@inststatuses > 0) {
2984: $changeHash{'inststatus'} = join(',',@inststatuses);
2985: $changed{'inststatus'} = $changeHash{'inststatus'};
2986: }
2987: }
2988: }
2989: if (keys(%changed)) {
2990: foreach my $item (@userinfo) {
2991: $changeHash{$item} = $env{'form.c'.$item};
2992: }
2993: my $chgresult =
2994: &Apache::lonnet::put('environment',\%changeHash,
2995: $env{'form.ccdomain'},$env{'form.ccuname'});
2996: }
2997: }
2998: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2999: &Apache::lonnet::hostname($uhome));
3000: } elsif (($env{'form.login'} ne 'nochange') &&
3001: ($env{'form.login'} ne '' )) {
3002: # Modify user privileges
3003: if (! $amode || ! $genpwd) {
3004: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
3005: return;
3006: }
3007: # Only allow authentication modification if the person has authority
3008: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
3009: $r->print('Modifying authentication: '.
3010: &Apache::lonnet::modifyuserauth(
3011: $env{'form.ccdomain'},$env{'form.ccuname'},
3012: $amode,$genpwd));
3013: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
3014: ($env{'form.ccuname'},$env{'form.ccdomain'}));
3015: } else {
3016: # Okay, this is a non-fatal error.
3017: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
3018: }
3019: }
3020: $r->rflush(); # Finish display of header before time consuming actions start
3021: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
3022: ##
3023: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
3024: if ($context eq 'course') {
3025: ($cnum,$cdom) =
3026: &Apache::lonuserutils::get_course_identity();
3027: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
3028: if ($showcredits) {
3029: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3030: }
3031: }
3032: if (! $env{'form.makeuser'} ) {
3033: # Check for need to change
3034: my %userenv = &Apache::lonnet::get
3035: ('environment',['firstname','middlename','lastname','generation',
3036: 'id','permanentemail','portfolioquota','authorquota','inststatus',
3037: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
3038: 'requestcourses.official','requestcourses.unofficial',
3039: 'requestcourses.community','requestcourses.textbook',
3040: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3041: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
3042: 'reqcrsotherdom.placement','requestauthor'],
3043: $env{'form.ccdomain'},$env{'form.ccuname'});
3044: my ($tmp) = keys(%userenv);
3045: if ($tmp =~ /^(con_lost|error)/i) {
3046: %userenv = ();
3047: }
3048: my $no_forceid_alert;
3049: # Check to see if user information can be changed
3050: my %domconfig =
3051: &Apache::lonnet::get_dom('configuration',['usermodification'],
3052: $env{'form.ccdomain'});
3053: my @statuses = ('active','future');
3054: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3055: my ($auname,$audom);
3056: if ($context eq 'author') {
3057: $auname = $env{'user.name'};
3058: $audom = $env{'user.domain'};
3059: }
3060: foreach my $item (keys(%roles)) {
3061: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
3062: if ($context eq 'course') {
3063: if ($cnum ne '' && $cdom ne '') {
3064: if ($rolenum eq $cnum && $roledom eq $cdom) {
3065: if (!grep(/^\Q$role\E$/,@userroles)) {
3066: push(@userroles,$role);
3067: }
3068: }
3069: }
3070: } elsif ($context eq 'author') {
3071: if ($rolenum eq $auname && $roledom eq $audom) {
3072: if (!grep(/^\Q$role\E$/,@userroles)) {
3073: push(@userroles,$role);
3074: }
3075: }
3076: }
3077: }
3078: if ($env{'form.action'} eq 'singlestudent') {
3079: if (!grep(/^st$/,@userroles)) {
3080: push(@userroles,'st');
3081: }
3082: } else {
3083: # Check for course or co-author roles being activated or re-enabled
3084: if ($context eq 'author' || $context eq 'course') {
3085: foreach my $key (keys(%env)) {
3086: if ($context eq 'author') {
3087: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3088: if (!grep(/^\Q$1\E$/,@userroles)) {
3089: push(@userroles,$1);
3090: }
3091: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3092: if (!grep(/^\Q$1\E$/,@userroles)) {
3093: push(@userroles,$1);
3094: }
3095: }
3096: } elsif ($context eq 'course') {
3097: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3098: if (!grep(/^\Q$1\E$/,@userroles)) {
3099: push(@userroles,$1);
3100: }
3101: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3102: if (!grep(/^\Q$1\E$/,@userroles)) {
3103: push(@userroles,$1);
3104: }
3105: }
3106: }
3107: }
3108: }
3109: }
3110: #Check to see if we can change personal data for the user
3111: my (@mod_disallowed,@longroles);
3112: foreach my $role (@userroles) {
3113: if ($role eq 'cr') {
3114: push(@longroles,'Custom');
3115: } else {
3116: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
3117: }
3118: }
3119: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3120: foreach my $item (@userinfo) {
3121: # Strip leading and trailing whitespace
3122: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
3123: if (!$canmodify{$item}) {
3124: if (defined($env{'form.c'.$item})) {
3125: if ($env{'form.c'.$item} ne $userenv{$item}) {
3126: push(@mod_disallowed,$item);
3127: }
3128: }
3129: $env{'form.c'.$item} = $userenv{$item};
3130: }
3131: }
3132: # Check to see if we can change the Student/Employee ID
3133: my $forceid = $env{'form.forceid'};
3134: my $recurseid = $env{'form.recurseid'};
3135: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
3136: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3137: $env{'form.ccuname'});
3138: if (($uidhash{$env{'form.ccuname'}}) &&
3139: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3140: (!$forceid)) {
3141: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3142: $env{'form.cid'} = $userenv{'id'};
3143: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
3144: .'<br />'
3145: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3146: .'<br />'."\n";
3147: }
3148: }
3149: if ($env{'form.cid'} ne $userenv{'id'}) {
3150: my $checkhash;
3151: my $checks = { 'id' => 1 };
3152: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3153: { 'newuser' => $newuser,
3154: 'id' => $env{'form.cid'},
3155: };
3156: &Apache::loncommon::user_rule_check($checkhash,$checks,
3157: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3158: if (ref($alerts{'id'}) eq 'HASH') {
3159: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
3160: $env{'form.cid'} = $userenv{'id'};
3161: }
3162: }
3163: }
3164: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3165: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
3166: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
3167: %oldsettingstatus,%newsettingstatus);
3168: @disporder = ('inststatus');
3169: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
3170: push(@disporder,'requestcourses','requestauthor');
3171: } else {
3172: push(@disporder,'reqcrsotherdom');
3173: }
3174: push(@disporder,('quota','tools'));
3175: $oldinststatus = $userenv{'inststatus'};
3176: foreach my $name ('portfolio','author') {
3177: ($olddefquota{$name},$oldsettingstatus{$name}) =
3178: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3179: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3180: }
3181: my %canshow;
3182: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
3183: $canshow{'quota'} = 1;
3184: }
3185: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
3186: $canshow{'tools'} = 1;
3187: }
3188: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
3189: $canshow{'requestcourses'} = 1;
3190: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
3191: $canshow{'reqcrsotherdom'} = 1;
3192: }
3193: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
3194: $canshow{'inststatus'} = 1;
3195: }
3196: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3197: $canshow{'requestauthor'} = 1;
3198: }
3199: my (%changeHash,%changed);
3200: if ($oldinststatus eq '') {
3201: $oldsettings{'inststatus'} = $othertitle;
3202: } else {
3203: if (ref($usertypes) eq 'HASH') {
3204: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
3205: } else {
3206: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
3207: }
3208: }
3209: $changeHash{'inststatus'} = $userenv{'inststatus'};
3210: if ($canmodify_status{'inststatus'}) {
3211: $canshow{'inststatus'} = 1;
3212: if (exists($env{'form.inststatus'})) {
3213: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3214: if (@inststatuses > 0) {
3215: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3216: $changeHash{'inststatus'} = $newinststatus;
3217: if ($newinststatus ne $oldinststatus) {
3218: $changed{'inststatus'} = $newinststatus;
3219: foreach my $name ('portfolio','author') {
3220: ($newdefquota{$name},$newsettingstatus{$name}) =
3221: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3222: }
3223: }
3224: if (ref($usertypes) eq 'HASH') {
3225: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
3226: } else {
3227: $newsettings{'inststatus'} = join(', ',@inststatuses);
3228: }
3229: }
3230: } else {
3231: $newinststatus = '';
3232: $changeHash{'inststatus'} = $newinststatus;
3233: $newsettings{'inststatus'} = $othertitle;
3234: if ($newinststatus ne $oldinststatus) {
3235: $changed{'inststatus'} = $changeHash{'inststatus'};
3236: foreach my $name ('portfolio','author') {
3237: ($newdefquota{$name},$newsettingstatus{$name}) =
3238: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3239: }
3240: }
3241: }
3242: } elsif ($context ne 'selfcreate') {
3243: $canshow{'inststatus'} = 1;
3244: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
3245: }
3246: foreach my $name ('portfolio','author') {
3247: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3248: }
3249: if ($context eq 'domain') {
3250: foreach my $name ('portfolio','author') {
3251: if ($userenv{$name.'quota'} ne '') {
3252: $oldquota{$name} = $userenv{$name.'quota'};
3253: if ($env{'form.custom_'.$name.'quota'} == 1) {
3254: if ($env{'form.'.$name.'quota'} eq '') {
3255: $newquota{$name} = 0;
3256: } else {
3257: $newquota{$name} = $env{'form.'.$name.'quota'};
3258: $newquota{$name} =~ s/[^\d\.]//g;
3259: }
3260: if ($newquota{$name} != $oldquota{$name}) {
3261: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3262: $changed{$name.'quota'} = 1;
3263: }
3264: }
3265: } else {
3266: if ("a_admin('',\%changeHash,$name)) {
3267: $changed{$name.'quota'} = 1;
3268: $newquota{$name} = $newdefquota{$name};
3269: $newisdefault{$name} = 1;
3270: }
3271: }
3272: } else {
3273: $oldisdefault{$name} = 1;
3274: $oldquota{$name} = $olddefquota{$name};
3275: if ($env{'form.custom_'.$name.'quota'} == 1) {
3276: if ($env{'form.'.$name.'quota'} eq '') {
3277: $newquota{$name} = 0;
3278: } else {
3279: $newquota{$name} = $env{'form.'.$name.'quota'};
3280: $newquota{$name} =~ s/[^\d\.]//g;
3281: }
3282: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3283: $changed{$name.'quota'} = 1;
3284: }
3285: } else {
3286: $newquota{$name} = $newdefquota{$name};
3287: $newisdefault{$name} = 1;
3288: }
3289: }
3290: if ($oldisdefault{$name}) {
3291: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
3292: } else {
3293: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
3294: }
3295: if ($newisdefault{$name}) {
3296: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
3297: } else {
3298: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
3299: }
3300: }
3301: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3302: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3303: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3304: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3305: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3306: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3307: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3308: } else {
3309: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3310: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3311: }
3312: }
3313: foreach my $item (@userinfo) {
3314: if ($env{'form.c'.$item} ne $userenv{$item}) {
3315: $namechanged{$item} = 1;
3316: }
3317: }
3318: foreach my $name ('portfolio','author') {
3319: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3320: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
3321: }
3322: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
3323: my ($chgresult,$namechgresult);
3324: if (keys(%changed) > 0) {
3325: $chgresult =
3326: &Apache::lonnet::put('environment',\%changeHash,
3327: $env{'form.ccdomain'},$env{'form.ccuname'});
3328: if ($chgresult eq 'ok') {
3329: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3330: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
3331: my %newenvhash;
3332: foreach my $key (keys(%changed)) {
3333: if (($key eq 'official') || ($key eq 'unofficial') ||
3334: ($key eq 'community') || ($key eq 'textbook') ||
3335: ($key eq 'placement') || ($key eq 'lti')) {
3336: $newenvhash{'environment.requestcourses.'.$key} =
3337: $changeHash{'requestcourses.'.$key};
3338: if ($changeHash{'requestcourses.'.$key}) {
3339: $newenvhash{'environment.canrequest.'.$key} = 1;
3340: } else {
3341: $newenvhash{'environment.canrequest.'.$key} =
3342: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3343: $key,'reload','requestcourses');
3344: }
3345: } elsif ($key eq 'requestauthor') {
3346: $newenvhash{'environment.'.$key} = $changeHash{$key};
3347: if ($changeHash{$key}) {
3348: $newenvhash{'environment.canrequest.author'} = 1;
3349: } else {
3350: $newenvhash{'environment.canrequest.author'} =
3351: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3352: $key,'reload','requestauthor');
3353: }
3354: } elsif ($key ne 'quota') {
3355: $newenvhash{'environment.tools.'.$key} =
3356: $changeHash{'tools.'.$key};
3357: if ($changeHash{'tools.'.$key} ne '') {
3358: $newenvhash{'environment.availabletools.'.$key} =
3359: $changeHash{'tools.'.$key};
3360: } else {
3361: $newenvhash{'environment.availabletools.'.$key} =
3362: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3363: $key,'reload','tools');
3364: }
3365: }
3366: }
3367: if (keys(%newenvhash)) {
3368: &Apache::lonnet::appenv(\%newenvhash);
3369: }
3370: }
3371: }
3372: }
3373: if (keys(%namechanged) > 0) {
3374: foreach my $field (@userinfo) {
3375: $changeHash{$field} = $env{'form.c'.$field};
3376: }
3377: # Make the change
3378: $namechgresult =
3379: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3380: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3381: $changeHash{'firstname'},$changeHash{'middlename'},
3382: $changeHash{'lastname'},$changeHash{'generation'},
3383: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
3384: %userupdate = (
3385: lastname => $env{'form.clastname'},
3386: middlename => $env{'form.cmiddlename'},
3387: firstname => $env{'form.cfirstname'},
3388: generation => $env{'form.cgeneration'},
3389: id => $env{'form.cid'},
3390: );
3391: }
3392: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
3393: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
3394: # Tell the user we changed the name
3395: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
3396: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
3397: \%oldsettings, \%oldsettingstext,\%newsettings,
3398: \%newsettingstext);
3399: if ($env{'form.cid'} ne $userenv{'id'}) {
3400: &Apache::lonnet::idput($env{'form.ccdomain'},
3401: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
3402: if (($recurseid) &&
3403: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3404: my $idresult =
3405: &Apache::lonuserutils::propagate_id_change(
3406: $env{'form.ccuname'},$env{'form.ccdomain'},
3407: \%userupdate);
3408: $r->print('<br />'.$idresult.'<br />');
3409: }
3410: }
3411: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3412: ($env{'form.ccuname'} eq $env{'user.name'})) {
3413: my %newenvhash;
3414: foreach my $key (keys(%changeHash)) {
3415: $newenvhash{'environment.'.$key} = $changeHash{$key};
3416: }
3417: &Apache::lonnet::appenv(\%newenvhash);
3418: }
3419: } else { # error occurred
3420: $r->print(
3421: '<p class="LC_error">'
3422: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3423: '"'.$env{'form.ccuname'}.'"',
3424: '"'.$env{'form.ccdomain'}.'"')
3425: .'</p>');
3426: }
3427: } else { # End of if ($env ... ) logic
3428: # They did not want to change the users name, quota, tool availability,
3429: # or ability to request creation of courses,
3430: # but we can still tell them what the name and quota and availabilities are
3431: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
3432: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
3433: \%oldsettingstext,\%newsettings,\%newsettingstext);
3434: }
3435: if (@mod_disallowed) {
3436: my ($rolestr,$contextname);
3437: if (@longroles > 0) {
3438: $rolestr = join(', ',@longroles);
3439: } else {
3440: $rolestr = &mt('No roles');
3441: }
3442: if ($context eq 'course') {
3443: $contextname = 'course';
3444: } elsif ($context eq 'author') {
3445: $contextname = 'co-author';
3446: }
3447: $r->print(&mt('The following fields were not updated: ').'<ul>');
3448: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3449: foreach my $field (@mod_disallowed) {
3450: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3451: }
3452: $r->print('</ul>');
3453: if (@mod_disallowed == 1) {
3454: $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future $contextname roles:"));
3455: } else {
3456: $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future $contextname roles:"));
3457: }
3458: my $helplink = 'javascript:helpMenu('."'display'".')';
3459: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3460: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3461: ,'<a href="'.$helplink.'">','</a>')
3462: .'<br />');
3463: }
3464: $r->print('<span class="LC_warning">'
3465: .$no_forceid_alert
3466: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3467: .'</span>');
3468: }
3469: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
3470: if ($env{'form.action'} eq 'singlestudent') {
3471: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3472: $crstype,$showcredits,$defaultcredits);
3473: my $linktext = ($crstype eq 'Community' ?
3474: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3475: $r->print(
3476: &Apache::lonhtmlcommon::actionbox([
3477: '<a href="javascript:backPage(document.userupdate)">'
3478: .($crstype eq 'Community' ?
3479: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3480: .'</a>']));
3481: } else {
3482: my @rolechanges = &update_roles($r,$context,$showcredits);
3483: if (keys(%namechanged) > 0) {
3484: if ($context eq 'course') {
3485: if (@userroles > 0) {
3486: if ((@rolechanges == 0) ||
3487: (!(grep(/^st$/,@rolechanges)))) {
3488: if (grep(/^st$/,@userroles)) {
3489: my $classlistupdated =
3490: &Apache::lonuserutils::update_classlist($cdom,
3491: $cnum,$env{'form.ccdomain'},
3492: $env{'form.ccuname'},\%userupdate);
3493: }
3494: }
3495: }
3496: }
3497: }
3498: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
3499: $env{'form.ccdomain'});
3500: if ($env{'form.popup'}) {
3501: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3502: } else {
3503: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3504: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3505: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
3506: }
3507: }
3508: }
3509:
3510: sub display_userinfo {
3511: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3512: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
3513: $newsetting,$newsettingtext) = @_;
3514: return unless (ref($order) eq 'ARRAY' &&
3515: ref($canshow) eq 'HASH' &&
3516: ref($requestcourses) eq 'ARRAY' &&
3517: ref($requestauthor) eq 'ARRAY' &&
3518: ref($usertools) eq 'ARRAY' &&
3519: ref($userenv) eq 'HASH' &&
3520: ref($changedhash) eq 'HASH' &&
3521: ref($oldsetting) eq 'HASH' &&
3522: ref($oldsettingtext) eq 'HASH' &&
3523: ref($newsetting) eq 'HASH' &&
3524: ref($newsettingtext) eq 'HASH');
3525: my %lt=&Apache::lonlocal::texthash(
3526: 'ui' => 'User Information',
3527: 'uic' => 'User Information Changed',
3528: 'firstname' => 'First Name',
3529: 'middlename' => 'Middle Name',
3530: 'lastname' => 'Last Name',
3531: 'generation' => 'Generation',
3532: 'id' => 'Student/Employee ID',
3533: 'permanentemail' => 'Permanent e-mail address',
3534: 'portfolioquota' => 'Disk space allocated to portfolio files',
3535: 'authorquota' => 'Disk space allocated to Authoring Space',
3536: 'blog' => 'Blog Availability',
3537: 'webdav' => 'WebDAV Availability',
3538: 'aboutme' => 'Personal Information Page Availability',
3539: 'portfolio' => 'Portfolio Availability',
3540: 'official' => 'Can Request Official Courses',
3541: 'unofficial' => 'Can Request Unofficial Courses',
3542: 'community' => 'Can Request Communities',
3543: 'textbook' => 'Can Request Textbook Courses',
3544: 'placement' => 'Can Request Placement Tests',
3545: 'lti' => 'Can Request LTI Courses',
3546: 'requestauthor' => 'Can Request Author Role',
3547: 'inststatus' => "Affiliation",
3548: 'prvs' => 'Previous Value:',
3549: 'chto' => 'Changed To:'
3550: );
3551: if ($changed) {
3552: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
3553: &Apache::loncommon::start_data_table().
3554: &Apache::loncommon::start_data_table_header_row());
3555: $r->print("<th> </th>\n");
3556: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3557: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3558: $r->print(&Apache::loncommon::end_data_table_header_row());
3559: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3560:
3561: foreach my $item (@userinfo) {
3562: my $value = $env{'form.c'.$item};
3563: #show changes only:
3564: unless ($value eq $userenv->{$item}){
3565: $r->print(&Apache::loncommon::start_data_table_row());
3566: $r->print("<td>$lt{$item}</td>\n");
3567: $r->print("<td>".$userenv->{$item}."</td>\n");
3568: $r->print("<td>$value </td>\n");
3569: $r->print(&Apache::loncommon::end_data_table_row());
3570: }
3571: }
3572: foreach my $entry (@{$order}) {
3573: if ($canshow->{$entry}) {
3574: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3575: my @items;
3576: if ($entry eq 'requestauthor') {
3577: @items = ($entry);
3578: } else {
3579: @items = @{$requestcourses};
3580: }
3581: foreach my $item (@items) {
3582: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3583: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3584: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3585: $r->print("<td>$lt{$item}</td>\n");
3586: $r->print("<td>".$oldsetting->{$item});
3587: if ($oldsettingtext->{$item}) {
3588: if ($oldsetting->{$item}) {
3589: $r->print(' -- ');
3590: }
3591: $r->print($oldsettingtext->{$item});
3592: }
3593: $r->print("</td>\n");
3594: $r->print("<td>".$newsetting->{$item});
3595: if ($newsettingtext->{$item}) {
3596: if ($newsetting->{$item}) {
3597: $r->print(' -- ');
3598: }
3599: $r->print($newsettingtext->{$item});
3600: }
3601: $r->print("</td>\n");
3602: $r->print(&Apache::loncommon::end_data_table_row()."\n");
3603: }
3604: }
3605: } elsif ($entry eq 'tools') {
3606: foreach my $item (@{$usertools}) {
3607: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3608: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3609: $r->print("<td>$lt{$item}</td>\n");
3610: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3611: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3612: $r->print(&Apache::loncommon::end_data_table_row()."\n");
3613: }
3614: }
3615: } elsif ($entry eq 'quota') {
3616: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3617: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3618: foreach my $name ('portfolio','author') {
3619: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3620: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3621: $r->print("<td>$lt{$name.$entry}</td>\n");
3622: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3623: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3624: $r->print(&Apache::loncommon::end_data_table_row()."\n");
3625: }
3626: }
3627: }
3628: } else {
3629: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3630: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3631: $r->print("<td>$lt{$entry}</td>\n");
3632: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3633: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3634: $r->print(&Apache::loncommon::end_data_table_row()."\n");
3635: }
3636: }
3637: }
3638: }
3639: $r->print(&Apache::loncommon::end_data_table().'<br />');
3640: } else {
3641: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3642: '<p>'.&mt('No changes made to user information').'</p>');
3643: }
3644: return;
3645: }
3646:
3647: sub tool_changes {
3648: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3649: $changed,$newaccess,$newaccesstext) = @_;
3650: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3651: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3652: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3653: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3654: return;
3655: }
3656: my %reqdisplay = &requestchange_display();
3657: if ($context eq 'reqcrsotherdom') {
3658: my @options = ('approval','validate','autolimit');
3659: my $optregex = join('|',@options);
3660: my $cdom = $env{'request.role.domain'};
3661: foreach my $tool (@{$usertools}) {
3662: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3663: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3664: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
3665: my ($newop,$limit);
3666: if ($env{'form.'.$context.'_'.$tool}) {
3667: $newop = $env{'form.'.$context.'_'.$tool};
3668: if ($newop eq 'autolimit') {
3669: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3670: $limit =~ s/\D+//g;
3671: $newop .= '='.$limit;
3672: }
3673: }
3674: if ($userenv->{$context.'.'.$tool} eq '') {
3675: if ($newop) {
3676: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
3677: $changeHash,$context);
3678: if ($changed->{$tool}) {
3679: if ($newop =~ /^autolimit/) {
3680: if ($limit) {
3681: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3682: } else {
3683: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3684: }
3685: } else {
3686: $newaccesstext->{$tool} = $reqdisplay{$newop};
3687: }
3688: } else {
3689: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3690: }
3691: }
3692: } else {
3693: my @curr = split(',',$userenv->{$context.'.'.$tool});
3694: my @new;
3695: my $changedoms;
3696: foreach my $req (@curr) {
3697: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3698: my $oldop = $1;
3699: if ($oldop =~ /^autolimit=(\d*)/) {
3700: my $limit = $1;
3701: if ($limit) {
3702: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3703: } else {
3704: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3705: }
3706: } else {
3707: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3708: }
3709: if ($oldop ne $newop) {
3710: $changedoms = 1;
3711: foreach my $item (@curr) {
3712: my ($reqdom,$option) = split(':',$item);
3713: unless ($reqdom eq $cdom) {
3714: push(@new,$item);
3715: }
3716: }
3717: if ($newop) {
3718: push(@new,$cdom.':'.$newop);
3719: }
3720: @new = sort(@new);
3721: }
3722: last;
3723: }
3724: }
3725: if ((!$changedoms) && ($newop)) {
3726: $changedoms = 1;
3727: @new = sort(@curr,$cdom.':'.$newop);
3728: }
3729: if ($changedoms) {
3730: my $newdomstr;
3731: if (@new) {
3732: $newdomstr = join(',',@new);
3733: }
3734: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3735: $context);
3736: if ($changed->{$tool}) {
3737: if ($env{'form.'.$context.'_'.$tool}) {
3738: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
3739: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3740: $limit =~ s/\D+//g;
3741: if ($limit) {
3742: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3743: } else {
3744: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3745: }
3746: } else {
3747: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3748: }
3749: } else {
3750: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3751: }
3752: }
3753: }
3754: }
3755: }
3756: return;
3757: }
3758: foreach my $tool (@{$usertools}) {
3759: my ($newval,$limit,$envkey);
3760: $envkey = $context.'.'.$tool;
3761: if ($context eq 'requestcourses') {
3762: $newval = $env{'form.crsreq_'.$tool};
3763: if ($newval eq 'autolimit') {
3764: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3765: $limit =~ s/\D+//g;
3766: $newval .= '='.$limit;
3767: }
3768: } elsif ($context eq 'requestauthor') {
3769: $newval = $env{'form.'.$context};
3770: $envkey = $context;
3771: } else {
3772: $newval = $env{'form.'.$context.'_'.$tool};
3773: }
3774: if ($userenv->{$envkey} ne '') {
3775: $oldaccess->{$tool} = &mt('custom');
3776: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3777: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3778: my $currlimit = $1;
3779: if ($currlimit eq '') {
3780: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3781: } else {
3782: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3783: }
3784: } elsif ($userenv->{$envkey}) {
3785: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3786: } else {
3787: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3788: }
3789: } else {
3790: if ($userenv->{$envkey}) {
3791: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3792: } else {
3793: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3794: }
3795: }
3796: $changeHash->{$envkey} = $userenv->{$envkey};
3797: if ($env{'form.custom'.$tool} == 1) {
3798: if ($newval ne $userenv->{$envkey}) {
3799: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3800: $context);
3801: if ($changed->{$tool}) {
3802: $newaccess->{$tool} = &mt('custom');
3803: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3804: if ($newval =~ /^autolimit/) {
3805: if ($limit) {
3806: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3807: } else {
3808: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3809: }
3810: } elsif ($newval) {
3811: $newaccesstext->{$tool} = $reqdisplay{$newval};
3812: } else {
3813: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3814: }
3815: } else {
3816: if ($newval) {
3817: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3818: } else {
3819: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3820: }
3821: }
3822: } else {
3823: $newaccess->{$tool} = $oldaccess->{$tool};
3824: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3825: if ($newval =~ /^autolimit/) {
3826: if ($limit) {
3827: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3828: } else {
3829: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3830: }
3831: } elsif ($newval) {
3832: $newaccesstext->{$tool} = $reqdisplay{$newval};
3833: } else {
3834: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3835: }
3836: } else {
3837: if ($userenv->{$context.'.'.$tool}) {
3838: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3839: } else {
3840: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3841: }
3842: }
3843: }
3844: } else {
3845: $newaccess->{$tool} = $oldaccess->{$tool};
3846: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3847: }
3848: } else {
3849: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3850: if ($changed->{$tool}) {
3851: $newaccess->{$tool} = &mt('default');
3852: } else {
3853: $newaccess->{$tool} = $oldaccess->{$tool};
3854: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3855: if ($newval =~ /^autolimit/) {
3856: if ($limit) {
3857: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3858: } else {
3859: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3860: }
3861: } elsif ($newval) {
3862: $newaccesstext->{$tool} = $reqdisplay{$newval};
3863: } else {
3864: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3865: }
3866: } else {
3867: if ($userenv->{$context.'.'.$tool}) {
3868: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3869: } else {
3870: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3871: }
3872: }
3873: }
3874: }
3875: } else {
3876: $oldaccess->{$tool} = &mt('default');
3877: if ($env{'form.custom'.$tool} == 1) {
3878: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3879: $context);
3880: if ($changed->{$tool}) {
3881: $newaccess->{$tool} = &mt('custom');
3882: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3883: if ($newval =~ /^autolimit/) {
3884: if ($limit) {
3885: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3886: } else {
3887: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3888: }
3889: } elsif ($newval) {
3890: $newaccesstext->{$tool} = $reqdisplay{$newval};
3891: } else {
3892: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3893: }
3894: } else {
3895: if ($newval) {
3896: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3897: } else {
3898: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3899: }
3900: }
3901: } else {
3902: $newaccess->{$tool} = $oldaccess->{$tool};
3903: }
3904: } else {
3905: $newaccess->{$tool} = $oldaccess->{$tool};
3906: }
3907: }
3908: }
3909: return;
3910: }
3911:
3912: sub update_roles {
3913: my ($r,$context,$showcredits) = @_;
3914: my $now=time;
3915: my @rolechanges;
3916: my %disallowed;
3917: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
3918: foreach my $key (keys(%env)) {
3919: next if (! $env{$key});
3920: next if ($key eq 'form.action');
3921: # Revoke roles
3922: if ($key=~/^form\.rev/) {
3923: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
3924: # Revoke standard role
3925: my ($scope,$role) = ($1,$2);
3926: my $result =
3927: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3928: $env{'form.ccuname'},
3929: $scope,$role,'','',$context);
3930: $r->print(&Apache::lonhtmlcommon::confirm_success(
3931: &mt('Revoking [_1] in [_2]',
3932: &Apache::lonnet::plaintext($role),
3933: &Apache::loncommon::show_role_extent($scope,$context,$role)),
3934: $result ne "ok").'<br />');
3935: if ($result ne "ok") {
3936: $r->print(&mt('Error: [_1]',$result).'<br />');
3937: }
3938: if ($role eq 'st') {
3939: my $result =
3940: &Apache::lonuserutils::classlist_drop($scope,
3941: $env{'form.ccuname'},$env{'form.ccdomain'},
3942: $now);
3943: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
3944: }
3945: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3946: push(@rolechanges,$role);
3947: }
3948: }
3949: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
3950: # Revoke custom role
3951: my $result = &Apache::lonnet::revokecustomrole(
3952: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
3953: $r->print(&Apache::lonhtmlcommon::confirm_success(
3954: &mt('Revoking custom role [_1] by [_2] in [_3]',
3955: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
3956: $result ne 'ok').'<br />');
3957: if ($result ne "ok") {
3958: $r->print(&mt('Error: [_1]',$result).'<br />');
3959: }
3960: if (!grep(/^cr$/,@rolechanges)) {
3961: push(@rolechanges,'cr');
3962: }
3963: }
3964: } elsif ($key=~/^form\.del/) {
3965: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
3966: # Delete standard role
3967: my ($scope,$role) = ($1,$2);
3968: my $result =
3969: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3970: $env{'form.ccuname'},
3971: $scope,$role,$now,0,1,'',
3972: $context);
3973: $r->print(&Apache::lonhtmlcommon::confirm_success(
3974: &mt('Deleting [_1] in [_2]',
3975: &Apache::lonnet::plaintext($role),
3976: &Apache::loncommon::show_role_extent($scope,$context,$role)),
3977: $result ne 'ok').'<br />');
3978: if ($result ne "ok") {
3979: $r->print(&mt('Error: [_1]',$result).'<br />');
3980: }
3981:
3982: if ($role eq 'st') {
3983: my $result =
3984: &Apache::lonuserutils::classlist_drop($scope,
3985: $env{'form.ccuname'},$env{'form.ccdomain'},
3986: $now);
3987: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
3988: }
3989: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3990: push(@rolechanges,$role);
3991: }
3992: }
3993: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
3994: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3995: # Delete custom role
3996: my $result =
3997: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3998: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3999: 0,1,$context);
4000: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
4001: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
4002: $result ne "ok").'<br />');
4003: if ($result ne "ok") {
4004: $r->print(&mt('Error: [_1]',$result).'<br />');
4005: }
4006:
4007: if (!grep(/^cr$/,@rolechanges)) {
4008: push(@rolechanges,'cr');
4009: }
4010: }
4011: } elsif ($key=~/^form\.ren/) {
4012: my $udom = $env{'form.ccdomain'};
4013: my $uname = $env{'form.ccuname'};
4014: # Re-enable standard role
4015: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
4016: my $url = $1;
4017: my $role = $2;
4018: my $logmsg;
4019: my $output;
4020: if ($role eq 'st') {
4021: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
4022: my ($cdom,$cnum,$csec) = ($1,$2,$3);
4023: my $credits;
4024: if ($showcredits) {
4025: my $defaultcredits =
4026: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4027: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4028: }
4029: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
4030: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
4031: if ($result eq 'refused' && $logmsg) {
4032: $output = $logmsg;
4033: } else {
4034: $output = &mt('Error: [_1]',$result)."\n";
4035: }
4036: } else {
4037: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4038: &Apache::lonnet::plaintext($role),
4039: &Apache::loncommon::show_role_extent($url,$context,'st'),
4040: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
4041: }
4042: }
4043: } else {
4044: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
4045: $env{'form.ccuname'},$url,$role,0,$now,'','',
4046: $context);
4047: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
4048: &Apache::lonnet::plaintext($role),
4049: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
4050: if ($result ne "ok") {
4051: $output .= &mt('Error: [_1]',$result).'<br />';
4052: }
4053: }
4054: $r->print($output);
4055: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4056: push(@rolechanges,$role);
4057: }
4058: }
4059: # Re-enable custom role
4060: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
4061: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4062: my $result = &Apache::lonnet::assigncustomrole(
4063: $env{'form.ccdomain'}, $env{'form.ccuname'},
4064: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
4065: $r->print(&Apache::lonhtmlcommon::confirm_success(
4066: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
4067: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
4068: $result ne "ok").'<br />');
4069: if ($result ne "ok") {
4070: $r->print(&mt('Error: [_1]',$result).'<br />');
4071: }
4072: if (!grep(/^cr$/,@rolechanges)) {
4073: push(@rolechanges,'cr');
4074: }
4075: }
4076: } elsif ($key=~/^form\.act/) {
4077: my $udom = $env{'form.ccdomain'};
4078: my $uname = $env{'form.ccuname'};
4079: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
4080: # Activate a custom role
4081: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4082: my $url='/'.$one.'/'.$two;
4083: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
4084:
4085: my $start = ( $env{'form.start_'.$full} ?
4086: $env{'form.start_'.$full} :
4087: $now );
4088: my $end = ( $env{'form.end_'.$full} ?
4089: $env{'form.end_'.$full} :
4090: 0 );
4091:
4092: # split multiple sections
4093: my %sections = ();
4094: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
4095: if ($num_sections == 0) {
4096: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
4097: } else {
4098: my %curr_groups =
4099: &Apache::longroup::coursegroups($one,$two);
4100: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
4101: if (($sec eq 'none') || ($sec eq 'all') ||
4102: exists($curr_groups{$sec})) {
4103: $disallowed{$sec} = $url;
4104: next;
4105: }
4106: my $securl = $url.'/'.$sec;
4107: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
4108: }
4109: }
4110: if (!grep(/^cr$/,@rolechanges)) {
4111: push(@rolechanges,'cr');
4112: }
4113: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
4114: # Activate roles for sections with 3 id numbers
4115: # set start, end times, and the url for the class
4116: my ($one,$two,$three)=($1,$2,$3);
4117: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4118: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
4119: $now );
4120: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4121: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
4122: 0 );
4123: my $url='/'.$one.'/'.$two;
4124: my $type = 'three';
4125: # split multiple sections
4126: my %sections = ();
4127: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
4128: my $credits;
4129: if ($three eq 'st') {
4130: if ($showcredits) {
4131: my $defaultcredits =
4132: &Apache::lonuserutils::get_defaultcredits($one,$two);
4133: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4134: $credits =~ s/[^\d\.]//g;
4135: if ($credits eq $defaultcredits) {
4136: undef($credits);
4137: }
4138: }
4139: }
4140: if ($num_sections == 0) {
4141: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
4142: } else {
4143: my %curr_groups =
4144: &Apache::longroup::coursegroups($one,$two);
4145: my $emptysec = 0;
4146: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
4147: $sec =~ s/\W//g;
4148: if ($sec ne '') {
4149: if (($sec eq 'none') || ($sec eq 'all') ||
4150: exists($curr_groups{$sec})) {
4151: $disallowed{$sec} = $url;
4152: next;
4153: }
4154: my $securl = $url.'/'.$sec;
4155: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
4156: } else {
4157: $emptysec = 1;
4158: }
4159: }
4160: if ($emptysec) {
4161: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
4162: }
4163: }
4164: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4165: push(@rolechanges,$three);
4166: }
4167: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
4168: # Activate roles for sections with two id numbers
4169: # set start, end times, and the url for the class
4170: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4171: $env{'form.start_'.$1.'_'.$2} :
4172: $now );
4173: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4174: $env{'form.end_'.$1.'_'.$2} :
4175: 0 );
4176: my $one = $1;
4177: my $two = $2;
4178: my $url='/'.$one.'/';
4179: # split multiple sections
4180: my %sections = ();
4181: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
4182: if ($num_sections == 0) {
4183: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
4184: } else {
4185: my $emptysec = 0;
4186: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
4187: if ($sec ne '') {
4188: my $securl = $url.'/'.$sec;
4189: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
4190: } else {
4191: $emptysec = 1;
4192: }
4193: }
4194: if ($emptysec) {
4195: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
4196: }
4197: }
4198: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4199: push(@rolechanges,$two);
4200: }
4201: } else {
4202: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
4203: }
4204: foreach my $key (sort(keys(%disallowed))) {
4205: $r->print('<p class="LC_warning">');
4206: if (($key eq 'none') || ($key eq 'all')) {
4207: $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.','<tt>'.$key.'</tt>'));
4208: } else {
4209: $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>'));
4210: }
4211: $r->print('</p><p>'
4212: .&mt('Please [_1]go back[_2] and choose a different section name.'
4213: ,'<a href="javascript:history.go(-1)'
4214: ,'</a>')
4215: .'</p><br />'
4216: );
4217: }
4218: }
4219: } # End of foreach (keys(%env))
4220: # Flush the course logs so reverse user roles immediately updated
4221: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
4222: if (@rolechanges == 0) {
4223: $r->print('<p>'.&mt('No roles to modify').'</p>');
4224: }
4225: return @rolechanges;
4226: }
4227:
4228: sub get_user_credits {
4229: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4230: if ($cdom eq '' || $cnum eq '') {
4231: return unless ($env{'request.course.id'});
4232: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4233: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4234: }
4235: my $credits;
4236: my %currhash =
4237: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4238: if (keys(%currhash) > 0) {
4239: my @items = split(/:/,$currhash{$uname.':'.$udom});
4240: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4241: $credits = $items[$crdidx];
4242: $credits =~ s/[^\d\.]//g;
4243: }
4244: if ($credits eq $defaultcredits) {
4245: undef($credits);
4246: }
4247: return $credits;
4248: }
4249:
4250: sub enroll_single_student {
4251: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4252: $showcredits,$defaultcredits) = @_;
4253: $r->print('<h3>');
4254: if ($crstype eq 'Community') {
4255: $r->print(&mt('Enrolling Member'));
4256: } else {
4257: $r->print(&mt('Enrolling Student'));
4258: }
4259: $r->print('</h3>');
4260:
4261: # Remove non alphanumeric values from section
4262: $env{'form.sections'}=~s/\W//g;
4263:
4264: my $credits;
4265: if (($showcredits) && ($env{'form.credits'} ne '')) {
4266: $credits = $env{'form.credits'};
4267: $credits =~ s/[^\d\.]//g;
4268: if ($credits ne '') {
4269: if ($credits eq $defaultcredits) {
4270: undef($credits);
4271: }
4272: }
4273: }
4274:
4275: # Clean out any old student roles the user has in this class.
4276: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4277: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4278: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4279: my $enroll_result =
4280: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4281: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4282: $env{'form.cmiddlename'},$env{'form.clastname'},
4283: $env{'form.generation'},$env{'form.sections'},$enddate,
4284: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4285: $credits);
4286: if ($enroll_result =~ /^ok/) {
4287: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
4288: if ($env{'form.sections'} ne '') {
4289: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4290: }
4291: my ($showstart,$showend);
4292: if ($startdate <= $now) {
4293: $showstart = &mt('Access starts immediately');
4294: } else {
4295: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4296: }
4297: if ($enddate == 0) {
4298: $showend = &mt('ends: no ending date');
4299: } else {
4300: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4301: }
4302: $r->print('.<br />'.$showstart.'; '.$showend);
4303: if ($startdate <= $now && !$newuser) {
4304: $r->print('<p class="LC_info">');
4305: if ($crstype eq 'Community') {
4306: $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.'));
4307: } else {
4308: $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.'));
4309: }
4310: $r->print('</p>');
4311: }
4312: } else {
4313: $r->print(&mt('unable to enroll').": ".$enroll_result);
4314: }
4315: return;
4316: }
4317:
4318: sub get_defaultquota_text {
4319: my ($settingstatus) = @_;
4320: my $defquotatext;
4321: if ($settingstatus eq '') {
4322: $defquotatext = &mt('default');
4323: } else {
4324: my ($usertypes,$order) =
4325: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4326: if ($usertypes->{$settingstatus} eq '') {
4327: $defquotatext = &mt('default');
4328: } else {
4329: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
4330: }
4331: }
4332: return $defquotatext;
4333: }
4334:
4335: sub update_result_form {
4336: my ($uhome) = @_;
4337: my $outcome =
4338: '<form name="userupdate" method="post" action="">'."\n";
4339: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
4340: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
4341: }
4342: if ($env{'form.origname'} ne '') {
4343: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4344: }
4345: foreach my $item ('sortby','seluname','seludom') {
4346: if (exists($env{'form.'.$item})) {
4347: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
4348: }
4349: }
4350: if ($uhome eq 'no_host') {
4351: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4352: }
4353: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
4354: '<input type="hidden" name="currstate" value="" />'."\n".
4355: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
4356: '</form>';
4357: return $outcome;
4358: }
4359:
4360: sub quota_admin {
4361: my ($setquota,$changeHash,$name) = @_;
4362: my $quotachanged;
4363: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4364: # Current user has quota modification privileges
4365: if (ref($changeHash) eq 'HASH') {
4366: $quotachanged = 1;
4367: $changeHash->{$name.'quota'} = $setquota;
4368: }
4369: }
4370: return $quotachanged;
4371: }
4372:
4373: sub tool_admin {
4374: my ($tool,$settool,$changeHash,$context) = @_;
4375: my $canchange = 0;
4376: if ($context eq 'requestcourses') {
4377: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4378: $canchange = 1;
4379: }
4380: } elsif ($context eq 'reqcrsotherdom') {
4381: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4382: $canchange = 1;
4383: }
4384: } elsif ($context eq 'requestauthor') {
4385: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4386: $canchange = 1;
4387: }
4388: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4389: # Current user has quota modification privileges
4390: $canchange = 1;
4391: }
4392: my $toolchanged;
4393: if ($canchange) {
4394: if (ref($changeHash) eq 'HASH') {
4395: $toolchanged = 1;
4396: if ($tool eq 'requestauthor') {
4397: $changeHash->{$context} = $settool;
4398: } else {
4399: $changeHash->{$context.'.'.$tool} = $settool;
4400: }
4401: }
4402: }
4403: return $toolchanged;
4404: }
4405:
4406: sub build_roles {
4407: my ($sectionstr,$sections,$role) = @_;
4408: my $num_sections = 0;
4409: if ($sectionstr=~ /,/) {
4410: my @secnums = split/,/,$sectionstr;
4411: if ($role eq 'st') {
4412: $secnums[0] =~ s/\W//g;
4413: $$sections{$secnums[0]} = 1;
4414: $num_sections = 1;
4415: } else {
4416: foreach my $sec (@secnums) {
4417: $sec =~ ~s/\W//g;
4418: if (!($sec eq "")) {
4419: if (exists($$sections{$sec})) {
4420: $$sections{$sec} ++;
4421: } else {
4422: $$sections{$sec} = 1;
4423: $num_sections ++;
4424: }
4425: }
4426: }
4427: }
4428: } else {
4429: $sectionstr=~s/\W//g;
4430: unless ($sectionstr eq '') {
4431: $$sections{$sectionstr} = 1;
4432: $num_sections ++;
4433: }
4434: }
4435:
4436: return $num_sections;
4437: }
4438:
4439: # ========================================================== Custom Role Editor
4440:
4441: sub custom_role_editor {
4442: my ($r,$context,$brcrum,$prefix,$permission) = @_;
4443: my $action = $env{'form.customroleaction'};
4444: my ($rolename,$helpitem);
4445: if ($action eq 'new') {
4446: $rolename=$env{'form.newrolename'};
4447: } else {
4448: $rolename=$env{'form.rolename'};
4449: }
4450:
4451: my ($crstype,$context);
4452: if ($env{'request.course.id'}) {
4453: $crstype = &Apache::loncommon::course_type();
4454: $context = 'course';
4455: $helpitem = 'Course_Editing_Custom_Roles';
4456: } else {
4457: $context = 'domain';
4458: $crstype = 'course';
4459: $helpitem = 'Domain_Editing_Custom_Roles';
4460: }
4461:
4462: $rolename=~s/[^A-Za-z0-9]//gs;
4463: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
4464: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4465: $permission);
4466: return;
4467: }
4468:
4469: my $formname = 'form1';
4470: my %privs=();
4471: my $body_top = '<h2>';
4472: # ------------------------------------------------------- Does this role exist?
4473: my ($rdummy,$roledef)=
4474: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4475: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
4476: $body_top .= &mt('Existing Role').' "';
4477: # ------------------------------------------------- Get current role privileges
4478: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4479: if ($privs{'system'} =~ /bre\&S/) {
4480: if ($context eq 'domain') {
4481: $crstype = 'Course';
4482: } elsif ($crstype eq 'Community') {
4483: $privs{'system'} =~ s/bre\&S//;
4484: }
4485: } elsif ($context eq 'domain') {
4486: $crstype = 'Course';
4487: }
4488: } else {
4489: $body_top .= &mt('New Role').' "';
4490: $roledef='';
4491: }
4492: $body_top .= $rolename.'"</h2>';
4493:
4494: # ------------------------------------------------------- What can be assigned?
4495: my %full=();
4496: my %levels=(
4497: course => {},
4498: domain => {},
4499: system => {},
4500: );
4501: my %levelscurrent=(
4502: course => {},
4503: domain => {},
4504: system => {},
4505: );
4506: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4507: my ($jsback,$elements) = &crumb_utilities();
4508: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4509: my $head_script =
4510: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4511: \%full,\@templateroles,$jsback);
4512: push (@{$brcrum},
4513: {href => "javascript:backPage(document.$formname,'pickrole','')",
4514: text => "Pick custom role",
4515: faq => 282,bug=>'Instructor Interface',},
4516: {href => "javascript:backPage(document.$formname,'','')",
4517: text => "Edit custom role",
4518: faq => 282,
4519: bug => 'Instructor Interface',
4520: help => $helpitem}
4521: );
4522: my $args = { bread_crumbs => $brcrum,
4523: bread_crumbs_component => 'User Management'};
4524: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4525: $head_script,$args).
4526: $body_top);
4527: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4528: &Apache::lonuserutils::custom_role_header($context,$crstype,
4529: \@templateroles,$prefix));
4530:
4531: $r->print(<<ENDCCF);
4532: <input type="hidden" name="phase" value="set_custom_roles" />
4533: <input type="hidden" name="rolename" value="$rolename" />
4534: ENDCCF
4535: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4536: \%levelscurrent,$prefix));
4537: $r->print(&Apache::loncommon::end_data_table().
4538: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
4539: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
4540: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
4541: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
4542: '<input type="submit" value="'.&mt('Save').'" /></form>');
4543: }
4544:
4545: # ---------------------------------------------------------- Call to definerole
4546: sub set_custom_role {
4547: my ($r,$context,$brcrum,$prefix,$permission) = @_;
4548: my $rolename=$env{'form.rolename'};
4549: $rolename=~s/[^A-Za-z0-9]//gs;
4550: if (!$rolename) {
4551: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
4552: return;
4553: }
4554: my ($jsback,$elements) = &crumb_utilities();
4555: my $jscript = '<script type="text/javascript">'
4556: .'// <![CDATA['."\n"
4557: .$jsback."\n"
4558: .'// ]]>'."\n"
4559: .'</script>'."\n";
4560: my $helpitem = 'Course_Editing_Custom_Roles';
4561: if ($context eq 'domain') {
4562: $helpitem = 'Domain_Editing_Custom_Roles';
4563: }
4564: push(@{$brcrum},
4565: {href => "javascript:backPage(document.customresult,'pickrole','')",
4566: text => "Pick custom role",
4567: faq => 282,
4568: bug => 'Instructor Interface',},
4569: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4570: text => "Edit custom role",
4571: faq => 282,
4572: bug => 'Instructor Interface',},
4573: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4574: text => "Result",
4575: faq => 282,
4576: bug => 'Instructor Interface',
4577: help => $helpitem,}
4578: );
4579: my $args = { bread_crumbs => $brcrum,
4580: bread_crumbs_component => 'User Management'};
4581: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
4582:
4583: my $newrole;
4584: my ($rdummy,$roledef)=
4585: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4586:
4587: # ------------------------------------------------------- Does this role exist?
4588: $r->print('<h3>');
4589: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
4590: $r->print(&mt('Existing Role').' "');
4591: } else {
4592: $r->print(&mt('New Role').' "');
4593: $roledef='';
4594: $newrole = 1;
4595: }
4596: $r->print($rolename.'"</h3>');
4597: # ------------------------------------------------- Assign role and show result
4598:
4599: my $errmsg;
4600: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4601: # Assign role and return result
4602: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4603: $newprivs{'c'});
4604: if ($result ne 'ok') {
4605: $errmsg = ': '.$result;
4606: }
4607: my $message =
4608: &Apache::lonhtmlcommon::confirm_success(
4609: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
4610: if ($env{'request.course.id'}) {
4611: my $url='/'.$env{'request.course.id'};
4612: $url=~s/\_/\//g;
4613: $result =
4614: &Apache::lonnet::assigncustomrole(
4615: $env{'user.domain'},$env{'user.name'},
4616: $url,
4617: $env{'user.domain'},$env{'user.name'},
4618: $rolename,undef,undef,undef,$context);
4619: if ($result ne 'ok') {
4620: $errmsg = ': '.$result;
4621: }
4622: $message .=
4623: '<br />'
4624: .&Apache::lonhtmlcommon::confirm_success(
4625: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
4626: }
4627: $r->print(
4628: &Apache::loncommon::confirmwrapper($message)
4629: .'<br />'
4630: .&Apache::lonhtmlcommon::actionbox([
4631: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4632: .&mt('Create or edit another custom role')
4633: .'</a>'])
4634: .'<form name="customresult" method="post" action="">'
4635: .&Apache::lonhtmlcommon::echo_form_input([])
4636: .'</form>'
4637: );
4638: }
4639:
4640: # ================================================================ Main Handler
4641: sub handler {
4642: my $r = shift;
4643: if ($r->header_only) {
4644: &Apache::loncommon::content_type($r,'text/html');
4645: $r->send_http_header;
4646: return OK;
4647: }
4648: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4649:
4650: if ($env{'request.course.id'}) {
4651: $context = 'course';
4652: $crstype = &Apache::loncommon::course_type();
4653: } elsif ($env{'request.role'} =~ /^au\./) {
4654: $context = 'author';
4655: } else {
4656: $context = 'domain';
4657: }
4658:
4659: my ($permission,$allowed) =
4660: &Apache::lonuserutils::get_permission($context,$crstype);
4661:
4662: if ($allowed) {
4663: my @allhelp;
4664: if ($context eq 'course') {
4665: $cid = $env{'request.course.id'};
4666: $cdom = $env{'course.'.$cid.'.domain'};
4667: $cnum = $env{'course.'.$cid.'.num'};
4668:
4669: if ($permission->{'cusr'}) {
4670: push(@allhelp,'Course_Create_Class_List');
4671: }
4672: if ($permission->{'view'} || $permission->{'cusr'}) {
4673: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4674: }
4675: if ($permission->{'custom'}) {
4676: push(@allhelp,'Course_Editing_Custom_Roles');
4677: }
4678: if ($permission->{'cusr'}) {
4679: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4680: }
4681: unless ($permission->{'cusr_section'}) {
4682: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4683: push(@allhelp,'Course_Automated_Enrollment');
4684: }
4685: if ($permission->{'selfenrolladmin'}) {
4686: push(@allhelp,'Course_Approve_Selfenroll');
4687: }
4688: }
4689: if ($permission->{'grp_manage'}) {
4690: push(@allhelp,'Course_Manage_Group');
4691: }
4692: if ($permission->{'view'} || $permission->{'cusr'}) {
4693: push(@allhelp,'Course_User_Logs');
4694: }
4695: } elsif ($context eq 'author') {
4696: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4697: 'Author_View_Coauthor_List','Author_User_Logs'));
4698: } else {
4699: if ($permission->{'cusr'}) {
4700: push(@allhelp,'Domain_Change_Privileges');
4701: if ($permission->{'activity'}) {
4702: push(@allhelp,'Domain_User_Access_Logs');
4703: }
4704: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4705: if ($permission->{'custom'}) {
4706: push(@allhelp,'Domain_Editing_Custom_Roles');
4707: }
4708: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4709: } elsif ($permission->{'view'}) {
4710: push(@allhelp,'Domain_View_Privileges');
4711: if ($permission->{'activity'}) {
4712: push(@allhelp,'Domain_User_Access_Logs');
4713: }
4714: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4715: }
4716: }
4717: if (@allhelp) {
4718: $allhelpitems = join(',',@allhelp);
4719: }
4720: }
4721:
4722: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
4723: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
4724: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
4725: &Apache::lonhtmlcommon::clear_breadcrumbs();
4726: my $args;
4727: my $brcrum = [];
4728: my $bread_crumbs_component = 'User Management';
4729: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
4730: $brcrum = [{href=>"/adm/createuser",
4731: text=>"User Management",
4732: help=>$allhelpitems}
4733: ];
4734: }
4735: if (!$allowed) {
4736: if ($context eq 'course') {
4737: $r->internal_redirect('/adm/viewclasslist');
4738: return OK;
4739: }
4740: $env{'user.error.msg'}=
4741: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4742: "or view user status.";
4743: return HTTP_NOT_ACCEPTABLE;
4744: }
4745:
4746: &Apache::loncommon::content_type($r,'text/html');
4747: $r->send_http_header;
4748:
4749: my $showcredits;
4750: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4751: ($context eq 'domain')) {
4752: my %domdefaults =
4753: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4754: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4755: $showcredits = 1;
4756: }
4757: }
4758:
4759: # Main switch on form.action and form.state, as appropriate
4760: if (! exists($env{'form.action'})) {
4761: $args = {bread_crumbs => $brcrum,
4762: bread_crumbs_component => $bread_crumbs_component};
4763: $r->print(&header(undef,$args));
4764: $r->print(&print_main_menu($permission,$context,$crstype));
4765: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
4766: my $helpitem = 'Course_Create_Class_List';
4767: if ($context eq 'author') {
4768: $helpitem = 'Author_Create_Coauthor_List';
4769: } elsif ($context eq 'domain') {
4770: $helpitem = 'Domain_Create_Users';
4771: }
4772: push(@{$brcrum},
4773: { href => '/adm/createuser?action=upload&state=',
4774: text => 'Upload Users List',
4775: help => $helpitem,
4776: });
4777: $bread_crumbs_component = 'Upload Users List';
4778: $args = {bread_crumbs => $brcrum,
4779: bread_crumbs_component => $bread_crumbs_component};
4780: $r->print(&header(undef,$args));
4781: $r->print('<form name="studentform" method="post" '.
4782: 'enctype="multipart/form-data" '.
4783: ' action="/adm/createuser">'."\n");
4784: if (! exists($env{'form.state'})) {
4785: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4786: } elsif ($env{'form.state'} eq 'got_file') {
4787: my $result =
4788: &Apache::lonuserutils::print_upload_manager_form($r,$context,
4789: $permission,
4790: $crstype,$showcredits);
4791: if ($result eq 'missingdata') {
4792: delete($env{'form.state'});
4793: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4794: }
4795: } elsif ($env{'form.state'} eq 'enrolling') {
4796: if ($env{'form.datatoken'}) {
4797: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
4798: $permission,
4799: $showcredits);
4800: if ($result eq 'missingdata') {
4801: delete($env{'form.state'});
4802: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4803: } elsif ($result eq 'invalidhome') {
4804: $env{'form.state'} = 'got_file';
4805: delete($env{'form.lcserver'});
4806: my $result =
4807: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4808: $crstype,$showcredits);
4809: if ($result eq 'missingdata') {
4810: delete($env{'form.state'});
4811: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4812: }
4813: }
4814: } else {
4815: delete($env{'form.state'});
4816: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4817: }
4818: } else {
4819: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4820: }
4821: $r->print('</form>');
4822: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4823: eq 'singlestudent')) && ($permission->{'cusr'})) ||
4824: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
4825: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
4826: my $phase = $env{'form.phase'};
4827: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
4828: &Apache::loncreateuser::restore_prev_selections();
4829: my $srch;
4830: foreach my $item (@search) {
4831: $srch->{$item} = $env{'form.'.$item};
4832: }
4833: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
4834: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
4835: if ($env{'form.phase'} eq 'createnewuser') {
4836: my $response;
4837: if ($env{'form.srchterm'} !~ /^$match_username$/) {
4838: my $response =
4839: '<span class="LC_warning">'
4840: .&mt('You must specify a valid username. Only the following are allowed:'
4841: .' letters numbers - . @')
4842: .'</span>';
4843: $env{'form.phase'} = '';
4844: &print_username_entry_form($r,$context,$response,$srch,undef,
4845: $crstype,$brcrum,$permission);
4846: } else {
4847: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4848: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4849: &print_user_modification_page($r,$ccuname,$ccdomain,
4850: $srch,$response,$context,
4851: $permission,$crstype,$brcrum,
4852: $showcredits);
4853: }
4854: } elsif ($env{'form.phase'} eq 'get_user_info') {
4855: my ($currstate,$response,$forcenewuser,$results) =
4856: &user_search_result($context,$srch);
4857: if ($env{'form.currstate'} eq 'modify') {
4858: $currstate = $env{'form.currstate'};
4859: }
4860: if ($currstate eq 'select') {
4861: &print_user_selection_page($r,$response,$srch,$results,
4862: \@search,$context,undef,$crstype,
4863: $brcrum);
4864: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4865: my ($ccuname,$ccdomain,$uhome);
4866: if (($srch->{'srchby'} eq 'uname') &&
4867: ($srch->{'srchtype'} eq 'exact')) {
4868: $ccuname = $srch->{'srchterm'};
4869: $ccdomain= $srch->{'srchdomain'};
4870: } else {
4871: my @matchedunames = keys(%{$results});
4872: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4873: }
4874: $ccuname =&LONCAPA::clean_username($ccuname);
4875: $ccdomain=&LONCAPA::clean_domain($ccdomain);
4876: if ($env{'form.action'} eq 'accesslogs') {
4877: my $uhome;
4878: if (($ccuname ne '') && ($ccdomain ne '')) {
4879: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4880: }
4881: if (($uhome eq '') || ($uhome eq 'no_host')) {
4882: $env{'form.phase'} = '';
4883: undef($forcenewuser);
4884: #if ($response) {
4885: # unless ($response =~ m{\Q<br /><br />\E$}) {
4886: # $response .= '<br /><br />';
4887: # }
4888: #}
4889: &print_username_entry_form($r,$context,$response,$srch,
4890: $forcenewuser,$crstype,$brcrum,
4891: $permission);
4892: } else {
4893: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4894: }
4895: } else {
4896: if ($env{'form.forcenewuser'}) {
4897: $response = '';
4898: }
4899: &print_user_modification_page($r,$ccuname,$ccdomain,
4900: $srch,$response,$context,
4901: $permission,$crstype,$brcrum);
4902: }
4903: } elsif ($currstate eq 'query') {
4904: &print_user_query_page($r,'createuser',$brcrum);
4905: } else {
4906: $env{'form.phase'} = '';
4907: &print_username_entry_form($r,$context,$response,$srch,
4908: $forcenewuser,$crstype,$brcrum,
4909: $permission);
4910: }
4911: } elsif ($env{'form.phase'} eq 'userpicked') {
4912: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4913: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
4914: if ($env{'form.action'} eq 'accesslogs') {
4915: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4916: } else {
4917: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4918: $context,$permission,$crstype,
4919: $brcrum);
4920: }
4921: } elsif ($env{'form.action'} eq 'accesslogs') {
4922: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4923: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4924: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4925: }
4926: } elsif ($env{'form.phase'} eq 'update_user_data') {
4927: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
4928: } else {
4929: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4930: $brcrum,$permission);
4931: }
4932: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
4933: my $prefix;
4934: if ($env{'form.phase'} eq 'set_custom_roles') {
4935: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
4936: } else {
4937: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
4938: }
4939: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4940: ($permission->{'cusr'}) &&
4941: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4942: push(@{$brcrum},
4943: {href => '/adm/createuser?action=processauthorreq',
4944: text => 'Authoring Space requests',
4945: help => 'Domain_Role_Approvals'});
4946: $bread_crumbs_component = 'Authoring requests';
4947: if ($env{'form.state'} eq 'done') {
4948: push(@{$brcrum},
4949: {href => '/adm/createuser?action=authorreqqueue',
4950: text => 'Result',
4951: help => 'Domain_Role_Approvals'});
4952: $bread_crumbs_component = 'Authoring request result';
4953: }
4954: $args = { bread_crumbs => $brcrum,
4955: bread_crumbs_component => $bread_crumbs_component};
4956: my $js = &usernamerequest_javascript();
4957: $r->print(&header(&add_script($js),$args));
4958: if (!exists($env{'form.state'})) {
4959: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4960: $env{'request.role.domain'}));
4961: } elsif ($env{'form.state'} eq 'done') {
4962: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4963: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4964: $env{'request.role.domain'}));
4965: }
4966: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4967: ($permission->{'cusr'}) &&
4968: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4969: push(@{$brcrum},
4970: {href => '/adm/createuser?action=processusernamereq',
4971: text => 'LON-CAPA account requests',
4972: help => 'Domain_Username_Approvals'});
4973: $bread_crumbs_component = 'Account requests';
4974: if ($env{'form.state'} eq 'done') {
4975: push(@{$brcrum},
4976: {href => '/adm/createuser?action=usernamereqqueue',
4977: text => 'Result',
4978: help => 'Domain_Username_Approvals'});
4979: $bread_crumbs_component = 'LON-CAPA account request result';
4980: }
4981: $args = { bread_crumbs => $brcrum,
4982: bread_crumbs_component => $bread_crumbs_component};
4983: my $js = &usernamerequest_javascript();
4984: $r->print(&header(&add_script($js),$args));
4985: if (!exists($env{'form.state'})) {
4986: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4987: $env{'request.role.domain'}));
4988: } elsif ($env{'form.state'} eq 'done') {
4989: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4990: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4991: $env{'request.role.domain'}));
4992: }
4993: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4994: ($permission->{'cusr'})) {
4995: my $dom = $env{'form.domain'};
4996: my $uname = $env{'form.username'};
4997: my $warning;
4998: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4999: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
5000: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
5001: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
5002: if ($uhome eq 'no_host') {
5003: my $queue = $env{'form.queue'};
5004: my $reqkey = &escape($uname).'_'.$queue;
5005: my $namespace = 'usernamequeue';
5006: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
5007: my %queued =
5008: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
5009: unless ($queued{$reqkey}) {
5010: $warning = &mt('No information was found for this LON-CAPA account request.');
5011: }
5012: } else {
5013: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
5014: }
5015: } else {
5016: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
5017: }
5018: } else {
5019: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
5020: }
5021: } else {
5022: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
5023: }
5024: my $args = { only_body => 1 };
5025: $r->print(&header(undef,$args).
5026: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
5027: if ($warning ne '') {
5028: $r->print('<div class="LC_warning">'.$warning.'</div>');
5029: } else {
5030: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5031: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
5032: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5033: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5034: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
5035: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
5036: my %info =
5037: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
5038: if (ref($info{$uname}) eq 'HASH') {
5039: my $usertype = $info{$uname}{'inststatus'};
5040: unless ($usertype) {
5041: $usertype = 'default';
5042: }
5043: my ($showstatus,$showemail,$pickstart);
5044: my $numextras = 0;
5045: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5046: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
5047: if (ref($usertypes) eq 'HASH') {
5048: if ($usertypes->{$usertype}) {
5049: $showstatus = $usertypes->{$usertype};
5050: } else {
5051: $showstatus = $othertitle;
5052: }
5053: if ($showstatus) {
5054: $numextras ++;
5055: }
5056: }
5057: }
5058: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5059: $showemail = $info{$uname}{'email'};
5060: $numextras ++;
5061: }
5062: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5063: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
5064: $pickstart = 1;
5065: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5066: my ($num,$count);
5067: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
5068: $count += $numextras;
5069: foreach my $field (@{$infofields}) {
5070: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5071: next unless ($infotitles->{$field});
5072: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5073: $info{$uname}{$field});
5074: $num ++;
5075: unless ($count == $num) {
5076: $r->print(&Apache::lonhtmlcommon::row_closure());
5077: }
5078: }
5079: }
5080: }
5081: if ($numextras) {
5082: unless ($pickstart) {
5083: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5084: $pickstart = 1;
5085: }
5086: if ($showemail) {
5087: my $closure = '';
5088: unless ($showstatus) {
5089: $closure = 1;
5090: }
5091: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5092: $showemail.
5093: &Apache::lonhtmlcommon::row_closure($closure));
5094: }
5095: if ($showstatus) {
5096: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5097: $showstatus.
5098: &Apache::lonhtmlcommon::row_closure(1));
5099: }
5100: }
5101: if ($pickstart) {
5102: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5103: } else {
5104: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
5105: }
5106: } else {
5107: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
5108: }
5109: }
5110: }
5111: }
5112: }
5113: $r->print(&close_popup_form());
5114: } elsif (($env{'form.action'} eq 'listusers') &&
5115: ($permission->{'view'} || $permission->{'cusr'})) {
5116: my $helpitem = 'Course_View_Class_List';
5117: if ($context eq 'author') {
5118: $helpitem = 'Author_View_Coauthor_List';
5119: } elsif ($context eq 'domain') {
5120: $helpitem = 'Domain_View_Users_List';
5121: }
5122: if ($env{'form.phase'} eq 'bulkchange') {
5123: push(@{$brcrum},
5124: {href => '/adm/createuser?action=listusers',
5125: text => "List Users"},
5126: {href => "/adm/createuser",
5127: text => "Result",
5128: help => $helpitem});
5129: $bread_crumbs_component = 'Update Users';
5130: $args = {bread_crumbs => $brcrum,
5131: bread_crumbs_component => $bread_crumbs_component};
5132: $r->print(&header(undef,$args));
5133: my $setting = $env{'form.roletype'};
5134: my $choice = $env{'form.bulkaction'};
5135: if ($permission->{'cusr'}) {
5136: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
5137: } else {
5138: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
5139: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
5140: }
5141: } else {
5142: push(@{$brcrum},
5143: {href => '/adm/createuser?action=listusers',
5144: text => "List Users",
5145: help => $helpitem});
5146: $bread_crumbs_component = 'List Users';
5147: $args = {bread_crumbs => $brcrum,
5148: bread_crumbs_component => $bread_crumbs_component};
5149: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5150: my $formname = 'studentform';
5151: my $hidecall = "hide_searching();";
5152: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5153: ($env{'form.roletype'} eq 'community'))) {
5154: if ($env{'form.roletype'} eq 'course') {
5155: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5156: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5157: $formname);
5158: } elsif ($env{'form.roletype'} eq 'community') {
5159: $cb_jscript =
5160: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5161: my %elements = (
5162: coursepick => 'radio',
5163: coursetotal => 'text',
5164: courselist => 'text',
5165: );
5166: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5167: }
5168: $jscript .= &verify_user_display($context)."\n".
5169: &Apache::loncommon::check_uncheck_jscript();
5170: my $js = &add_script($jscript).$cb_jscript;
5171: my $loadcode =
5172: &Apache::lonuserutils::course_selector_loadcode($formname);
5173: if ($loadcode ne '') {
5174: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5175: } else {
5176: $args->{add_entries} = {onload => $hidecall};
5177: }
5178: $r->print(&header($js,$args));
5179: } else {
5180: $args->{add_entries} = {onload => $hidecall};
5181: $jscript = &verify_user_display($context).
5182: &Apache::loncommon::check_uncheck_jscript();
5183: $r->print(&header(&add_script($jscript),$args));
5184: }
5185: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
5186: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5187: $showcredits);
5188: }
5189: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
5190: my $brtext;
5191: if ($crstype eq 'Community') {
5192: $brtext = 'Drop Members';
5193: } else {
5194: $brtext = 'Drop Students';
5195: }
5196: push(@{$brcrum},
5197: {href => '/adm/createuser?action=drop',
5198: text => $brtext,
5199: help => 'Course_Drop_Student'});
5200: if ($env{'form.state'} eq 'done') {
5201: push(@{$brcrum},
5202: {href=>'/adm/createuser?action=drop',
5203: text=>"Result"});
5204: }
5205: $bread_crumbs_component = $brtext;
5206: $args = {bread_crumbs => $brcrum,
5207: bread_crumbs_component => $bread_crumbs_component};
5208: $r->print(&header(undef,$args));
5209: if (!exists($env{'form.state'})) {
5210: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
5211: } elsif ($env{'form.state'} eq 'done') {
5212: &Apache::lonuserutils::update_user_list($r,$context,undef,
5213: $env{'form.action'});
5214: }
5215: } elsif ($env{'form.action'} eq 'dateselect') {
5216: if ($permission->{'cusr'}) {
5217: $r->print(&header(undef,{'no_nav_bar' => 1}).
5218: &Apache::lonuserutils::date_section_selector($context,$permission,
5219: $crstype,$showcredits));
5220: } else {
5221: $r->print(&header(undef,{'no_nav_bar' => 1}).
5222: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
5223: }
5224: } elsif ($env{'form.action'} eq 'selfenroll') {
5225: if ($permission->{selfenrolladmin}) {
5226: my %currsettings = (
5227: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5228: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5229: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5230: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5231: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5232: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5233: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5234: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5235: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5236: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5237: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5238: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5239: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
5240: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
5241: );
5242: push(@{$brcrum},
5243: {href => '/adm/createuser?action=selfenroll',
5244: text => "Configure Self-enrollment",
5245: help => 'Course_Self_Enrollment'});
5246: if (!exists($env{'form.state'})) {
5247: $args = { bread_crumbs => $brcrum,
5248: bread_crumbs_component => 'Configure Self-enrollment'};
5249: $r->print(&header(undef,$args));
5250: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5251: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5252: } elsif ($env{'form.state'} eq 'done') {
5253: push (@{$brcrum},
5254: {href=>'/adm/createuser?action=selfenroll',
5255: text=>"Result"});
5256: $args = { bread_crumbs => $brcrum,
5257: bread_crumbs_component => 'Self-enrollment result'};
5258: $r->print(&header(undef,$args));
5259: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5260: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
5261: }
5262: } else {
5263: $r->print(&header(undef,{'no_nav_bar' => 1}).
5264: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
5265: }
5266: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
5267: if ($permission->{selfenrolladmin}) {
5268: push(@{$brcrum},
5269: {href => '/adm/createuser?action=selfenrollqueue',
5270: text => 'Enrollment requests',
5271: help => 'Course_Approve_Selfenroll'});
5272: $bread_crumbs_component = 'Enrollment requests';
5273: if ($env{'form.state'} eq 'done') {
5274: push(@{$brcrum},
5275: {href => '/adm/createuser?action=selfenrollqueue',
5276: text => 'Result',
5277: help => 'Course_Approve_Selfenroll'});
5278: $bread_crumbs_component = 'Enrollment result';
5279: }
5280: $args = { bread_crumbs => $brcrum,
5281: bread_crumbs_component => $bread_crumbs_component};
5282: $r->print(&header(undef,$args));
5283: my $coursedesc = $env{'course.'.$cid.'.description'};
5284: if (!exists($env{'form.state'})) {
5285: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5286: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5287: $cdom,$cnum));
5288: } elsif ($env{'form.state'} eq 'done') {
5289: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5290: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5291: $cdom,$cnum,$coursedesc));
5292: }
5293: } else {
5294: $r->print(&header(undef,{'no_nav_bar' => 1}).
5295: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
5296: }
5297: } elsif ($env{'form.action'} eq 'changelogs') {
5298: if ($permission->{cusr} || $permission->{view}) {
5299: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5300: } else {
5301: $r->print(&header(undef,{'no_nav_bar' => 1}).
5302: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
5303: }
5304: } elsif ($env{'form.action'} eq 'helpdesk') {
5305: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5306: if ($env{'form.state'} eq 'process') {
5307: if ($permission->{'owner'}) {
5308: &update_helpdeskaccess($r,$permission,$brcrum);
5309: } else {
5310: &print_helpdeskaccess_display($r,$permission,$brcrum);
5311: }
5312: } else {
5313: &print_helpdeskaccess_display($r,$permission,$brcrum);
5314: }
5315: } else {
5316: $r->print(&header(undef,{'no_nav_bar' => 1}).
5317: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5318: }
5319: } else {
5320: $bread_crumbs_component = 'User Management';
5321: $args = { bread_crumbs => $brcrum,
5322: bread_crumbs_component => $bread_crumbs_component};
5323: $r->print(&header(undef,$args));
5324: $r->print(&print_main_menu($permission,$context,$crstype));
5325: }
5326: $r->print(&Apache::loncommon::end_page());
5327: return OK;
5328: }
5329:
5330: sub header {
5331: my ($jscript,$args) = @_;
5332: my $start_page;
5333: if (ref($args) eq 'HASH') {
5334: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
5335: } else {
5336: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
5337: }
5338: return $start_page;
5339: }
5340:
5341: sub add_script {
5342: my ($js) = @_;
5343: return '<script type="text/javascript">'."\n"
5344: .'// <![CDATA['."\n"
5345: .$js."\n"
5346: .'// ]]>'."\n"
5347: .'</script>'."\n";
5348: }
5349:
5350: sub usernamerequest_javascript {
5351: my $js = <<ENDJS;
5352:
5353: function openusernamereqdisplay(dom,uname,queue) {
5354: var url = '/adm/createuser?action=displayuserreq';
5355: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5356: var title = 'Account_Request_Browser';
5357: var options = 'scrollbars=1,resizable=1,menubar=0';
5358: options += ',width=700,height=600';
5359: var stdeditbrowser = open(url,title,options,'1');
5360: stdeditbrowser.focus();
5361: return;
5362: }
5363:
5364: ENDJS
5365: }
5366:
5367: sub close_popup_form {
5368: my $close= &mt('Close Window');
5369: return << "END";
5370: <p><form name="displayreq" action="" method="post">
5371: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5372: </form></p>
5373: END
5374: }
5375:
5376: sub verify_user_display {
5377: my ($context) = @_;
5378: my %lt = &Apache::lonlocal::texthash (
5379: course => 'course(s): description, section(s), status',
5380: community => 'community(s): description, section(s), status',
5381: author => 'author',
5382: );
5383: my $photos;
5384: if (($context eq 'course') && $env{'request.course.id'}) {
5385: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5386: }
5387: my $output = <<"END";
5388:
5389: function hide_searching() {
5390: if (document.getElementById('searching')) {
5391: document.getElementById('searching').style.display = 'none';
5392: }
5393: return;
5394: }
5395:
5396: function display_update() {
5397: document.studentform.action.value = 'listusers';
5398: document.studentform.phase.value = 'display';
5399: document.studentform.submit();
5400: }
5401:
5402: function updateCols(caller) {
5403: var context = '$context';
5404: var photos = '$photos';
5405: if (caller == 'Status') {
5406: if ((context == 'domain') &&
5407: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5408: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
5409: document.getElementById('showcolstatus').checked = false;
5410: document.getElementById('showcolstatus').disabled = 'disabled';
5411: document.getElementById('showcolstart').checked = false;
5412: document.getElementById('showcolend').checked = false;
5413: } else {
5414: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5415: document.getElementById('showcolstatus').checked = true;
5416: document.getElementById('showcolstatus').disabled = '';
5417: document.getElementById('showcolstart').checked = true;
5418: document.getElementById('showcolend').checked = true;
5419: } else {
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: }
5425: }
5426: }
5427: if (caller == 'output') {
5428: if (photos == 1) {
5429: if (document.getElementById('showcolphoto')) {
5430: var photoitem = document.getElementById('showcolphoto');
5431: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5432: photoitem.checked = true;
5433: photoitem.disabled = '';
5434: } else {
5435: photoitem.checked = false;
5436: photoitem.disabled = 'disabled';
5437: }
5438: }
5439: }
5440: }
5441: if (caller == 'showrole') {
5442: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5443: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
5444: document.getElementById('showcolrole').checked = true;
5445: document.getElementById('showcolrole').disabled = '';
5446: } else {
5447: document.getElementById('showcolrole').checked = false;
5448: document.getElementById('showcolrole').disabled = 'disabled';
5449: }
5450: if (context == 'domain') {
5451: var quotausageshow = 0;
5452: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5453: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5454: document.getElementById('showcolstatus').checked = false;
5455: document.getElementById('showcolstatus').disabled = 'disabled';
5456: document.getElementById('showcolstart').checked = false;
5457: document.getElementById('showcolend').checked = false;
5458: } else {
5459: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5460: document.getElementById('showcolstatus').checked = true;
5461: document.getElementById('showcolstatus').disabled = '';
5462: document.getElementById('showcolstart').checked = true;
5463: document.getElementById('showcolend').checked = true;
5464: }
5465: }
5466: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5467: document.getElementById('showcolextent').disabled = 'disabled';
5468: document.getElementById('showcolextent').checked = 'false';
5469: document.getElementById('showextent').style.display='none';
5470: document.getElementById('showcoltextextent').innerHTML = '';
5471: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5472: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5473: if (document.getElementById('showcolauthorusage')) {
5474: document.getElementById('showcolauthorusage').disabled = '';
5475: }
5476: if (document.getElementById('showcolauthorquota')) {
5477: document.getElementById('showcolauthorquota').disabled = '';
5478: }
5479: quotausageshow = 1;
5480: }
5481: } else {
5482: document.getElementById('showextent').style.display='block';
5483: document.getElementById('showextent').style.textAlign='left';
5484: document.getElementById('showextent').style.textFace='normal';
5485: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5486: document.getElementById('showcolextent').disabled = '';
5487: document.getElementById('showcolextent').checked = 'true';
5488: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5489: } else {
5490: document.getElementById('showcolextent').disabled = '';
5491: document.getElementById('showcolextent').checked = 'true';
5492: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5493: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5494: } else {
5495: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5496: }
5497: }
5498: }
5499: if (quotausageshow == 0) {
5500: if (document.getElementById('showcolauthorusage')) {
5501: document.getElementById('showcolauthorusage').checked = false;
5502: document.getElementById('showcolauthorusage').disabled = 'disabled';
5503: }
5504: if (document.getElementById('showcolauthorquota')) {
5505: document.getElementById('showcolauthorquota').checked = false;
5506: document.getElementById('showcolauthorquota').disabled = 'disabled';
5507: }
5508: }
5509: }
5510: }
5511: return;
5512: }
5513:
5514: END
5515: return $output;
5516:
5517: }
5518:
5519: ###############################################################
5520: ###############################################################
5521: # Menu Phase One
5522: sub print_main_menu {
5523: my ($permission,$context,$crstype) = @_;
5524: my $linkcontext = $context;
5525: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5526: if (($context eq 'course') && ($crstype eq 'Community')) {
5527: $linkcontext = lc($crstype);
5528: $stuterm = 'Members';
5529: }
5530: my %links = (
5531: domain => {
5532: upload => 'Upload a File of Users',
5533: singleuser => 'Add/Modify a User',
5534: listusers => 'Manage Users',
5535: },
5536: author => {
5537: upload => 'Upload a File of Co-authors',
5538: singleuser => 'Add/Modify a Co-author',
5539: listusers => 'Manage Co-authors',
5540: },
5541: course => {
5542: upload => 'Upload a File of Course Users',
5543: singleuser => 'Add/Modify a Course User',
5544: listusers => 'List and Modify Multiple Course Users',
5545: },
5546: community => {
5547: upload => 'Upload a File of Community Users',
5548: singleuser => 'Add/Modify a Community User',
5549: listusers => 'List and Modify Multiple Community Users',
5550: },
5551: );
5552: my %linktitles = (
5553: domain => {
5554: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5555: listusers => 'Show and manage users in this domain.',
5556: },
5557: author => {
5558: singleuser => 'Add a user with a co- or assistant author role.',
5559: listusers => 'Show and manage co- or assistant authors.',
5560: },
5561: course => {
5562: singleuser => 'Add a user with a certain role to this course.',
5563: listusers => 'Show and manage users in this course.',
5564: },
5565: community => {
5566: singleuser => 'Add a user with a certain role to this community.',
5567: listusers => 'Show and manage users in this community.',
5568: },
5569: );
5570: if ($linkcontext eq 'domain') {
5571: unless ($permission->{'cusr'}) {
5572: $links{'domain'}{'singleuser'} = 'View a User';
5573: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5574: }
5575: } elsif ($linkcontext eq 'course') {
5576: unless ($permission->{'cusr'}) {
5577: $links{'course'}{'singleuser'} = 'View a Course User';
5578: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5579: $links{'course'}{'listusers'} = 'List Course Users';
5580: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5581: }
5582: } elsif ($linkcontext eq 'community') {
5583: unless ($permission->{'cusr'}) {
5584: $links{'community'}{'singleuser'} = 'View a Community User';
5585: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5586: $links{'community'}{'listusers'} = 'List Community Users';
5587: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5588: }
5589: }
5590: my @menu = ( {categorytitle => 'Single Users',
5591: items =>
5592: [
5593: {
5594: linktext => $links{$linkcontext}{'singleuser'},
5595: icon => 'edit-redo.png',
5596: #help => 'Course_Change_Privileges',
5597: url => '/adm/createuser?action=singleuser',
5598: permission => ($permission->{'view'} || $permission->{'cusr'}),
5599: linktitle => $linktitles{$linkcontext}{'singleuser'},
5600: },
5601: ]},
5602:
5603: {categorytitle => 'Multiple Users',
5604: items =>
5605: [
5606: {
5607: linktext => $links{$linkcontext}{'upload'},
5608: icon => 'uplusr.png',
5609: #help => 'Course_Create_Class_List',
5610: url => '/adm/createuser?action=upload',
5611: permission => $permission->{'cusr'},
5612: linktitle => 'Upload a CSV or a text file containing users.',
5613: },
5614: {
5615: linktext => $links{$linkcontext}{'listusers'},
5616: icon => 'mngcu.png',
5617: #help => 'Course_View_Class_List',
5618: url => '/adm/createuser?action=listusers',
5619: permission => ($permission->{'view'} || $permission->{'cusr'}),
5620: linktitle => $linktitles{$linkcontext}{'listusers'},
5621: },
5622:
5623: ]},
5624:
5625: {categorytitle => 'Administration',
5626: items => [ ]},
5627: );
5628:
5629: if ($context eq 'domain'){
5630: push(@{ $menu[0]->{items} }, # Single Users
5631: {
5632: linktext => 'User Access Log',
5633: icon => 'document-properties.png',
5634: #help => 'Domain_User_Access_Logs',
5635: url => '/adm/createuser?action=accesslogs',
5636: permission => $permission->{'activity'},
5637: linktitle => 'View user access log.',
5638: }
5639: );
5640:
5641: push(@{ $menu[2]->{items} }, #Category: Administration
5642: {
5643: linktext => 'Custom Roles',
5644: icon => 'emblem-photos.png',
5645: #help => 'Course_Editing_Custom_Roles',
5646: url => '/adm/createuser?action=custom',
5647: permission => $permission->{'custom'},
5648: linktitle => 'Configure a custom role.',
5649: },
5650: {
5651: linktext => 'Authoring Space Requests',
5652: icon => 'selfenrl-queue.png',
5653: #help => 'Domain_Role_Approvals',
5654: url => '/adm/createuser?action=processauthorreq',
5655: permission => $permission->{'cusr'},
5656: linktitle => 'Approve or reject author role requests',
5657: },
5658: {
5659: linktext => 'LON-CAPA Account Requests',
5660: icon => 'list-add.png',
5661: #help => 'Domain_Username_Approvals',
5662: url => '/adm/createuser?action=processusernamereq',
5663: permission => $permission->{'cusr'},
5664: linktitle => 'Approve or reject LON-CAPA account requests',
5665: },
5666: {
5667: linktext => 'Change Log',
5668: icon => 'document-properties.png',
5669: #help => 'Course_User_Logs',
5670: url => '/adm/createuser?action=changelogs',
5671: permission => ($permission->{'cusr'} || $permission->{'view'}),
5672: linktitle => 'View change log.',
5673: },
5674: );
5675:
5676: }elsif ($context eq 'course'){
5677: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
5678:
5679: my %linktext = (
5680: 'Course' => {
5681: single => 'Add/Modify a Student',
5682: drop => 'Drop Students',
5683: groups => 'Course Groups',
5684: },
5685: 'Community' => {
5686: single => 'Add/Modify a Member',
5687: drop => 'Drop Members',
5688: groups => 'Community Groups',
5689: },
5690: );
5691: $linktext{'Placement'} = $linktext{'Course'};
5692:
5693: my %linktitle = (
5694: 'Course' => {
5695: single => 'Add a user with the role of student to this course',
5696: drop => 'Remove a student from this course.',
5697: groups => 'Manage course groups',
5698: },
5699: 'Community' => {
5700: single => 'Add a user with the role of member to this community',
5701: drop => 'Remove a member from this community.',
5702: groups => 'Manage community groups',
5703: },
5704: );
5705:
5706: $linktitle{'Placement'} = $linktitle{'Course'};
5707:
5708: push(@{ $menu[0]->{items} }, #Category: Single Users
5709: {
5710: linktext => $linktext{$crstype}{'single'},
5711: #help => 'Course_Add_Student',
5712: icon => 'list-add.png',
5713: url => '/adm/createuser?action=singlestudent',
5714: permission => $permission->{'cusr'},
5715: linktitle => $linktitle{$crstype}{'single'},
5716: },
5717: );
5718:
5719: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5720: {
5721: linktext => $linktext{$crstype}{'drop'},
5722: icon => 'edit-undo.png',
5723: #help => 'Course_Drop_Student',
5724: url => '/adm/createuser?action=drop',
5725: permission => $permission->{'cusr'},
5726: linktitle => $linktitle{$crstype}{'drop'},
5727: },
5728: );
5729: push(@{ $menu[2]->{items} }, #Category: Administration
5730: {
5731: linktext => 'Helpdesk Access',
5732: icon => 'helpdesk-access.png',
5733: #help => 'Course_Helpdesk_Access',
5734: url => '/adm/createuser?action=helpdesk',
5735: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5736: linktitle => 'Helpdesk access options',
5737: },
5738: {
5739: linktext => 'Custom Roles',
5740: icon => 'emblem-photos.png',
5741: #help => 'Course_Editing_Custom_Roles',
5742: url => '/adm/createuser?action=custom',
5743: permission => $permission->{'custom'},
5744: linktitle => 'Configure a custom role.',
5745: },
5746: {
5747: linktext => $linktext{$crstype}{'groups'},
5748: icon => 'grps.png',
5749: #help => 'Course_Manage_Group',
5750: url => '/adm/coursegroups?refpage=cusr',
5751: permission => $permission->{'grp_manage'},
5752: linktitle => $linktitle{$crstype}{'groups'},
5753: },
5754: {
5755: linktext => 'Change Log',
5756: icon => 'document-properties.png',
5757: #help => 'Course_User_Logs',
5758: url => '/adm/createuser?action=changelogs',
5759: permission => ($permission->{'view'} || $permission->{'cusr'}),
5760: linktitle => 'View change log.',
5761: },
5762: );
5763: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
5764: push(@{ $menu[2]->{items} },
5765: {
5766: linktext => 'Enrollment Requests',
5767: icon => 'selfenrl-queue.png',
5768: #help => 'Course_Approve_Selfenroll',
5769: url => '/adm/createuser?action=selfenrollqueue',
5770: permission => $permission->{'selfenrolladmin'},
5771: linktitle =>'Approve or reject enrollment requests.',
5772: },
5773: );
5774: }
5775:
5776: if (!exists($permission->{'cusr_section'})){
5777: if ($crstype ne 'Community') {
5778: push(@{ $menu[2]->{items} },
5779: {
5780: linktext => 'Automated Enrollment',
5781: icon => 'roles.png',
5782: #help => 'Course_Automated_Enrollment',
5783: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
5784: && (($permission->{'cusr'}) ||
5785: ($permission->{'view'}))),
5786: url => '/adm/populate',
5787: linktitle => 'Automated enrollment manager.',
5788: }
5789: );
5790: }
5791: push(@{ $menu[2]->{items} },
5792: {
5793: linktext => 'User Self-Enrollment',
5794: icon => 'self_enroll.png',
5795: #help => 'Course_Self_Enrollment',
5796: url => '/adm/createuser?action=selfenroll',
5797: permission => $permission->{'selfenrolladmin'},
5798: linktitle => 'Configure user self-enrollment.',
5799: },
5800: );
5801: }
5802: } elsif ($context eq 'author') {
5803: push(@{ $menu[2]->{items} }, #Category: Administration
5804: {
5805: linktext => 'Change Log',
5806: icon => 'document-properties.png',
5807: #help => 'Course_User_Logs',
5808: url => '/adm/createuser?action=changelogs',
5809: permission => $permission->{'cusr'},
5810: linktitle => 'View change log.',
5811: },
5812: );
5813: }
5814: return Apache::lonhtmlcommon::generate_menu(@menu);
5815: # { text => 'View Log-in History',
5816: # help => 'Course_User_Logins',
5817: # action => 'logins',
5818: # permission => $permission->{'cusr'},
5819: # });
5820: }
5821:
5822: sub restore_prev_selections {
5823: my %saveable_parameters = ('srchby' => 'scalar',
5824: 'srchin' => 'scalar',
5825: 'srchtype' => 'scalar',
5826: );
5827: &Apache::loncommon::store_settings('user','user_picker',
5828: \%saveable_parameters);
5829: &Apache::loncommon::restore_settings('user','user_picker',
5830: \%saveable_parameters);
5831: }
5832:
5833: sub print_selfenroll_menu {
5834: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
5835: my $crstype = &Apache::loncommon::course_type();
5836: my $formname = 'selfenroll';
5837: my $nolink = 1;
5838: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
5839: my $groupslist = &Apache::lonuserutils::get_groupslist();
5840: my $setsec_js =
5841: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
5842: my %alerts = &Apache::lonlocal::texthash(
5843: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5844: butn => 'but no user types have been checked.',
5845: wilf => "Please uncheck 'activate' or check at least one type.",
5846: );
5847: my $disabled;
5848: if ($readonly) {
5849: $disabled = ' disabled="disabled"';
5850: }
5851: &js_escape(\%alerts);
5852: my $selfenroll_js = <<"ENDSCRIPT";
5853: function update_types(caller,num) {
5854: var delidx = getIndexByName('selfenroll_delete');
5855: var actidx = getIndexByName('selfenroll_activate');
5856: if (caller == 'selfenroll_all') {
5857: var selall;
5858: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5859: if (document.$formname.selfenroll_all[i].checked) {
5860: selall = document.$formname.selfenroll_all[i].value;
5861: }
5862: }
5863: if (selall == 1) {
5864: if (delidx != -1) {
5865: if (document.$formname.selfenroll_delete.length) {
5866: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5867: document.$formname.selfenroll_delete[j].checked = true;
5868: }
5869: } else {
5870: document.$formname.elements[delidx].checked = true;
5871: }
5872: }
5873: if (actidx != -1) {
5874: if (document.$formname.selfenroll_activate.length) {
5875: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5876: document.$formname.selfenroll_activate[j].checked = false;
5877: }
5878: } else {
5879: document.$formname.elements[actidx].checked = false;
5880: }
5881: }
5882: document.$formname.selfenroll_newdom.selectedIndex = 0;
5883: }
5884: }
5885: if (caller == 'selfenroll_activate') {
5886: if (document.$formname.selfenroll_activate.length) {
5887: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5888: if (document.$formname.selfenroll_activate[j].value == num) {
5889: if (document.$formname.selfenroll_activate[j].checked) {
5890: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5891: if (document.$formname.selfenroll_all[i].value == '1') {
5892: document.$formname.selfenroll_all[i].checked = false;
5893: }
5894: if (document.$formname.selfenroll_all[i].value == '0') {
5895: document.$formname.selfenroll_all[i].checked = true;
5896: }
5897: }
5898: }
5899: }
5900: }
5901: } else {
5902: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5903: if (document.$formname.selfenroll_all[i].value == '1') {
5904: document.$formname.selfenroll_all[i].checked = false;
5905: }
5906: if (document.$formname.selfenroll_all[i].value == '0') {
5907: document.$formname.selfenroll_all[i].checked = true;
5908: }
5909: }
5910: }
5911: }
5912: if (caller == 'selfenroll_delete') {
5913: if (document.$formname.selfenroll_delete.length) {
5914: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5915: if (document.$formname.selfenroll_delete[j].value == num) {
5916: if (document.$formname.selfenroll_delete[j].checked) {
5917: var delindex = getIndexByName('selfenroll_types_'+num);
5918: if (delindex != -1) {
5919: if (document.$formname.elements[delindex].length) {
5920: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5921: document.$formname.elements[delindex][k].checked = false;
5922: }
5923: } else {
5924: document.$formname.elements[delindex].checked = false;
5925: }
5926: }
5927: }
5928: }
5929: }
5930: } else {
5931: if (document.$formname.selfenroll_delete.checked) {
5932: var delindex = getIndexByName('selfenroll_types_'+num);
5933: if (delindex != -1) {
5934: if (document.$formname.elements[delindex].length) {
5935: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5936: document.$formname.elements[delindex][k].checked = false;
5937: }
5938: } else {
5939: document.$formname.elements[delindex].checked = false;
5940: }
5941: }
5942: }
5943: }
5944: }
5945: return;
5946: }
5947:
5948: function validate_types(form) {
5949: var needaction = new Array();
5950: var countfail = 0;
5951: var actidx = getIndexByName('selfenroll_activate');
5952: if (actidx != -1) {
5953: if (document.$formname.selfenroll_activate.length) {
5954: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5955: var num = document.$formname.selfenroll_activate[j].value;
5956: if (document.$formname.selfenroll_activate[j].checked) {
5957: countfail = check_types(num,countfail,needaction)
5958: }
5959: }
5960: } else {
5961: if (document.$formname.selfenroll_activate.checked) {
5962: var num = document.$formname.selfenroll_activate.value;
5963: countfail = check_types(num,countfail,needaction)
5964: }
5965: }
5966: }
5967: if (countfail > 0) {
5968: var msg = "$alerts{'acto'}\\n";
5969: var loopend = needaction.length -1;
5970: if (loopend > 0) {
5971: for (var m=0; m<loopend; m++) {
5972: msg += needaction[m]+", ";
5973: }
5974: }
5975: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5976: alert(msg);
5977: return;
5978: }
5979: setSections(form);
5980: }
5981:
5982: function check_types(num,countfail,needaction) {
5983: var boxname = 'selfenroll_types_'+num;
5984: var typeidx = getIndexByName(boxname);
5985: var count = 0;
5986: if (typeidx != -1) {
5987: if (document.$formname.elements[boxname].length) {
5988: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
5989: if (document.$formname.elements[boxname][k].checked) {
5990: count ++;
5991: }
5992: }
5993: } else {
5994: if (document.$formname.elements[typeidx].checked) {
5995: count ++;
5996: }
5997: }
5998: if (count == 0) {
5999: var domidx = getIndexByName('selfenroll_dom_'+num);
6000: if (domidx != -1) {
6001: var domname = document.$formname.elements[domidx].value;
6002: needaction[countfail] = domname;
6003: countfail ++;
6004: }
6005: }
6006: }
6007: return countfail;
6008: }
6009:
6010: function toggleNotify() {
6011: var selfenrollApproval = 0;
6012: if (document.$formname.selfenroll_approval.length) {
6013: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
6014: if (document.$formname.selfenroll_approval[i].checked) {
6015: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
6016: break;
6017: }
6018: }
6019: }
6020: if (document.getElementById('notified')) {
6021: if (selfenrollApproval == 0) {
6022: document.getElementById('notified').style.display='none';
6023: } else {
6024: document.getElementById('notified').style.display='block';
6025: }
6026: }
6027: return;
6028: }
6029:
6030: function getIndexByName(item) {
6031: for (var i=0;i<document.$formname.elements.length;i++) {
6032: if (document.$formname.elements[i].name == item) {
6033: return i;
6034: }
6035: }
6036: return -1;
6037: }
6038: ENDSCRIPT
6039:
6040: my $output = '<script type="text/javascript">'."\n".
6041: '// <![CDATA['."\n".
6042: $setsec_js."\n".$selfenroll_js."\n".
6043: '// ]]>'."\n".
6044: '</script>'."\n".
6045: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
6046:
6047: my $visactions = &cat_visibility();
6048: my ($cathash,%cattype);
6049: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
6050: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6051: $cathash = $domconfig{'coursecategories'}{'cats'};
6052: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
6053: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
6054: if ($cattype{'auth'} eq '') {
6055: $cattype{'auth'} = 'std';
6056: }
6057: if ($cattype{'unauth'} eq '') {
6058: $cattype{'unauth'} = 'std';
6059: }
6060: } else {
6061: $cathash = {};
6062: $cattype{'auth'} = 'std';
6063: $cattype{'unauth'} = 'std';
6064: }
6065: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
6066: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6067: '<br />'.
6068: '<br />'.$visactions->{'take'}.'<ul>'.
6069: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
6070: '</ul>');
6071: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
6072: if ($currsettings->{'uniquecode'}) {
6073: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
6074: } else {
6075: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6076: '<br />'.
6077: '<br />'.$visactions->{'take'}.'<ul>'.
6078: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6079: '</ul><br />');
6080: }
6081: } else {
6082: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6083: if (ref($visactions) eq 'HASH') {
6084: if ($visible) {
6085: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6086: } else {
6087: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6088: .$visactions->{'yous'}.
6089: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6090: if (ref($vismsgs) eq 'ARRAY') {
6091: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6092: foreach my $item (@{$vismsgs}) {
6093: $output .= '<li>'.$visactions->{$item}.'</li>';
6094: }
6095: $output .= '</ul>';
6096: }
6097: $output .= '</p>';
6098: }
6099: }
6100: }
6101: my $actionhref = '/adm/createuser';
6102: if ($context eq 'domain') {
6103: $actionhref = '/adm/modifycourse';
6104: }
6105:
6106: my %noedit;
6107: unless ($context eq 'domain') {
6108: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6109: }
6110: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
6111: &Apache::lonhtmlcommon::start_pick_box();
6112: if (ref($row) eq 'ARRAY') {
6113: foreach my $item (@{$row}) {
6114: my $title = $item;
6115: if (ref($lt) eq 'HASH') {
6116: $title = $lt->{$item};
6117: }
6118: $output .= &Apache::lonhtmlcommon::row_title($title);
6119: if ($item eq 'types') {
6120: my $curr_types;
6121: if (ref($currsettings) eq 'HASH') {
6122: $curr_types = $currsettings->{'selfenroll_types'};
6123: }
6124: if ($noedit{$item}) {
6125: if ($curr_types eq '*') {
6126: $output .= &mt('Any user in any domain');
6127: } else {
6128: my @entries = split(/;/,$curr_types);
6129: if (@entries > 0) {
6130: $output .= '<ul>';
6131: foreach my $entry (@entries) {
6132: my ($currdom,$typestr) = split(/:/,$entry);
6133: next if ($typestr eq '');
6134: my $domdesc = &Apache::lonnet::domain($currdom);
6135: my @currinsttypes = split(',',$typestr);
6136: my ($othertitle,$usertypes,$types) =
6137: &Apache::loncommon::sorted_inst_types($currdom);
6138: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6139: $usertypes->{'any'} = &mt('any user');
6140: if (keys(%{$usertypes}) > 0) {
6141: $usertypes->{'other'} = &mt('other users');
6142: }
6143: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6144: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6145: }
6146: }
6147: $output .= '</ul>';
6148: } else {
6149: $output .= &mt('None');
6150: }
6151: }
6152: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6153: next;
6154: }
6155: my $showdomdesc = 1;
6156: my $includeempty = 1;
6157: my $num = 0;
6158: $output .= &Apache::loncommon::start_data_table().
6159: &Apache::loncommon::start_data_table_row()
6160: .'<td colspan="2"><span class="LC_nobreak"><label>'
6161: .&mt('Any user in any domain:')
6162: .' <input type="radio" name="selfenroll_all" value="1" ';
6163: if ($curr_types eq '*') {
6164: $output .= ' checked="checked" ';
6165: }
6166: $output .= 'onchange="javascript:update_types('.
6167: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
6168: ' <input type="radio" name="selfenroll_all" value="0" ';
6169: if ($curr_types ne '*') {
6170: $output .= ' checked="checked" ';
6171: }
6172: $output .= ' onchange="javascript:update_types('.
6173: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
6174: &Apache::loncommon::end_data_table_row().
6175: &Apache::loncommon::end_data_table().
6176: &mt('Or').'<br />'.
6177: &Apache::loncommon::start_data_table();
6178: my %currdoms;
6179: if ($curr_types eq '') {
6180: $output .= &new_selfenroll_dom_row($cdom,'0');
6181: } elsif ($curr_types ne '*') {
6182: my @entries = split(/;/,$curr_types);
6183: if (@entries > 0) {
6184: foreach my $entry (@entries) {
6185: my ($currdom,$typestr) = split(/:/,$entry);
6186: $currdoms{$currdom} = 1;
6187: my $domdesc = &Apache::lonnet::domain($currdom);
6188: my @currinsttypes = split(',',$typestr);
6189: $output .= &Apache::loncommon::start_data_table_row()
6190: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6191: .' '.$domdesc.' ('.$currdom.')'
6192: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6193: .'" value="'.$currdom.'" /></span><br />'
6194: .'<span class="LC_nobreak"><label><input type="checkbox" '
6195: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
6196: .&mt('Delete').'</label></span></td>';
6197: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
6198: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
6199: .&Apache::loncommon::end_data_table_row();
6200: $num ++;
6201: }
6202: }
6203: }
6204: my $add_domtitle = &mt('Users in additional domain:');
6205: if ($curr_types eq '*') {
6206: $add_domtitle = &mt('Users in specific domain:');
6207: } elsif ($curr_types eq '') {
6208: $add_domtitle = &mt('Users in other domain:');
6209: }
6210: my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$cdom);
6211: $output .= &Apache::loncommon::start_data_table_row()
6212: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6213: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
6214: $includeempty,$showdomdesc,'',$trusted,$untrusted,$readonly)
6215: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6216: .'</td>'.&Apache::loncommon::end_data_table_row()
6217: .&Apache::loncommon::end_data_table();
6218: } elsif ($item eq 'registered') {
6219: my ($regon,$regoff);
6220: my $registered;
6221: if (ref($currsettings) eq 'HASH') {
6222: $registered = $currsettings->{'selfenroll_registered'};
6223: }
6224: if ($noedit{$item}) {
6225: if ($registered) {
6226: $output .= &mt('Must be registered in course');
6227: } else {
6228: $output .= &mt('No requirement');
6229: }
6230: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6231: next;
6232: }
6233: if ($registered) {
6234: $regon = ' checked="checked" ';
6235: $regoff = '';
6236: } else {
6237: $regon = '';
6238: $regoff = ' checked="checked" ';
6239: }
6240: $output .= '<label>'.
6241: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
6242: &mt('Yes').'</label> <label>'.
6243: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
6244: &mt('No').'</label>';
6245: } elsif ($item eq 'enroll_dates') {
6246: my ($starttime,$endtime);
6247: if (ref($currsettings) eq 'HASH') {
6248: $starttime = $currsettings->{'selfenroll_start_date'};
6249: $endtime = $currsettings->{'selfenroll_end_date'};
6250: if ($starttime eq '') {
6251: $starttime = $currsettings->{'default_enrollment_start_date'};
6252: }
6253: if ($endtime eq '') {
6254: $endtime = $currsettings->{'default_enrollment_end_date'};
6255: }
6256: }
6257: if ($noedit{$item}) {
6258: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6259: &Apache::lonlocal::locallocaltime($endtime));
6260: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6261: next;
6262: }
6263: my $startform =
6264: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
6265: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
6266: my $endform =
6267: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
6268: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
6269: $output .= &selfenroll_date_forms($startform,$endform);
6270: } elsif ($item eq 'access_dates') {
6271: my ($starttime,$endtime);
6272: if (ref($currsettings) eq 'HASH') {
6273: $starttime = $currsettings->{'selfenroll_start_access'};
6274: $endtime = $currsettings->{'selfenroll_end_access'};
6275: if ($starttime eq '') {
6276: $starttime = $currsettings->{'default_enrollment_start_date'};
6277: }
6278: if ($endtime eq '') {
6279: $endtime = $currsettings->{'default_enrollment_end_date'};
6280: }
6281: }
6282: if ($noedit{$item}) {
6283: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6284: &Apache::lonlocal::locallocaltime($endtime));
6285: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6286: next;
6287: }
6288: my $startform =
6289: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
6290: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
6291: my $endform =
6292: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
6293: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
6294: $output .= &selfenroll_date_forms($startform,$endform);
6295: } elsif ($item eq 'section') {
6296: my $currsec;
6297: if (ref($currsettings) eq 'HASH') {
6298: $currsec = $currsettings->{'selfenroll_section'};
6299: }
6300: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6301: my $newsecval;
6302: if ($currsec ne 'none' && $currsec ne '') {
6303: if (!defined($sections_count{$currsec})) {
6304: $newsecval = $currsec;
6305: }
6306: }
6307: if ($noedit{$item}) {
6308: if ($currsec ne '') {
6309: $output .= $currsec;
6310: } else {
6311: $output .= &mt('No specific section');
6312: }
6313: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6314: next;
6315: }
6316: my $sections_select =
6317: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
6318: $output .= '<table class="LC_createuser">'."\n".
6319: '<tr class="LC_section_row">'."\n".
6320: '<td align="center">'.&mt('Existing sections')."\n".
6321: '<br />'.$sections_select.'</td><td align="center">'.
6322: &mt('New section').'<br />'."\n".
6323: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
6324: '<input type="hidden" name="sections" value="" />'."\n".
6325: '</td></tr></table>'."\n";
6326: } elsif ($item eq 'approval') {
6327: my ($currnotified,$currapproval,%appchecked);
6328: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
6329: if (ref($currsettings) eq 'HASH') {
6330: $currnotified = $currsettings->{'selfenroll_notifylist'};
6331: $currapproval = $currsettings->{'selfenroll_approval'};
6332: }
6333: if ($currapproval !~ /^[012]$/) {
6334: $currapproval = 0;
6335: }
6336: if ($noedit{$item}) {
6337: $output .= $selfdescs{'approval'}{$currapproval}.
6338: '<br />'.&mt('(Set by Domain Coordinator)');
6339: next;
6340: }
6341: $appchecked{$currapproval} = ' checked="checked"';
6342: for my $i (0..2) {
6343: $output .= '<label>'.
6344: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
6345: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6346: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
6347: }
6348: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6349: my (@ccs,%notified);
6350: my $ccrole = 'cc';
6351: if ($crstype eq 'Community') {
6352: $ccrole = 'co';
6353: }
6354: if ($advhash{$ccrole}) {
6355: @ccs = split(/,/,$advhash{$ccrole});
6356: }
6357: if ($currnotified) {
6358: foreach my $current (split(/,/,$currnotified)) {
6359: $notified{$current} = 1;
6360: if (!grep(/^\Q$current\E$/,@ccs)) {
6361: push(@ccs,$current);
6362: }
6363: }
6364: }
6365: if (@ccs) {
6366: my $style;
6367: unless ($currapproval) {
6368: $style = ' style="display: none;"';
6369: }
6370: $output .= '<br /><div id="notified"'.$style.'>'.
6371: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6372: &Apache::loncommon::start_data_table().
6373: &Apache::loncommon::start_data_table_row();
6374: my $count = 0;
6375: my $numcols = 4;
6376: foreach my $cc (sort(@ccs)) {
6377: my $notifyon;
6378: my ($ccuname,$ccudom) = split(/:/,$cc);
6379: if ($notified{$cc}) {
6380: $notifyon = ' checked="checked" ';
6381: }
6382: if ($count && !$count%$numcols) {
6383: $output .= &Apache::loncommon::end_data_table_row().
6384: &Apache::loncommon::start_data_table_row()
6385: }
6386: $output .= '<td><span class="LC_nobreak"><label>'.
6387: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
6388: &Apache::loncommon::plainname($ccuname,$ccudom).
6389: '</label></span></td>';
6390: $count ++;
6391: }
6392: my $rem = $count%$numcols;
6393: if ($rem) {
6394: my $emptycols = $numcols - $rem;
6395: for (my $i=0; $i<$emptycols; $i++) {
6396: $output .= '<td> </td>';
6397: }
6398: }
6399: $output .= &Apache::loncommon::end_data_table_row().
6400: &Apache::loncommon::end_data_table().
6401: '</div>';
6402: }
6403: } elsif ($item eq 'limit') {
6404: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6405: if (ref($currsettings) eq 'HASH') {
6406: $currlim = $currsettings->{'selfenroll_limit'};
6407: $currcap = $currsettings->{'selfenroll_cap'};
6408: }
6409: if ($noedit{$item}) {
6410: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6411: if ($currlim eq 'allstudents') {
6412: $output .= &mt('Limit by total students');
6413: } elsif ($currlim eq 'selfenrolled') {
6414: $output .= &mt('Limit by total self-enrolled students');
6415: }
6416: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6417: '<br />'.&mt('(Set by Domain Coordinator)');
6418: } else {
6419: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6420: }
6421: next;
6422: }
6423: if ($currlim eq 'allstudents') {
6424: $crslimit = ' checked="checked" ';
6425: $selflimit = ' ';
6426: $nolimit = ' ';
6427: } elsif ($currlim eq 'selfenrolled') {
6428: $crslimit = ' ';
6429: $selflimit = ' checked="checked" ';
6430: $nolimit = ' ';
6431: } else {
6432: $crslimit = ' ';
6433: $selflimit = ' ';
6434: $nolimit = ' checked="checked" ';
6435: }
6436: $output .= '<table><tr><td><label>'.
6437: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
6438: &mt('No limit').'</label></td><td><label>'.
6439: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
6440: &mt('Limit by total students').'</label></td><td><label>'.
6441: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
6442: &mt('Limit by total self-enrolled students').
6443: '</td></tr><tr>'.
6444: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6445: (' 'x3).&mt('Maximum number allowed: ').
6446: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
6447: }
6448: $output .= &Apache::lonhtmlcommon::row_closure(1);
6449: }
6450: }
6451: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6452: unless ($readonly) {
6453: $output .= '<input type="button" name="selfenrollconf" value="'
6454: .&mt('Save').'" onclick="validate_types(this.form);" />';
6455: }
6456: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6457: .'<input type="hidden" name="state" value="done" />'."\n"
6458: .$additional.'</form>';
6459: $r->print($output);
6460: return;
6461: }
6462:
6463: sub get_noedit_fields {
6464: my ($cdom,$cnum,$crstype,$row) = @_;
6465: my %noedit;
6466: if (ref($row) eq 'ARRAY') {
6467: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6468: 'internal.selfenrollmgrdc',
6469: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6470: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6471: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6472: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6473: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6474: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6475: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6476:
6477: foreach my $item (@{$row}) {
6478: next if ($specific_managebycc{$item});
6479: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6480: $noedit{$item} = 1;
6481: }
6482: }
6483: }
6484: return %noedit;
6485: }
6486:
6487: sub visible_in_stdcat {
6488: my ($cdom,$cnum,$domconf) = @_;
6489: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6490: unless (ref($domconf) eq 'HASH') {
6491: return ($visible,$cansetvis,\@vismsgs);
6492: }
6493: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6494: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
6495: $settable{'togglecats'} = 1;
6496: }
6497: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
6498: $settable{'categorize'} = 1;
6499: }
6500: $cathash = $domconf->{'coursecategories'}{'cats'};
6501: }
6502: if ($settable{'togglecats'} && $settable{'categorize'}) {
6503: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6504: } elsif ($settable{'togglecats'}) {
6505: $cansetvis = &mt('You are able to choose to exclude this course from the catalog, but only a Domain Coordinator may assign a course category.');
6506: } elsif ($settable{'categorize'}) {
6507: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6508: } else {
6509: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6510: }
6511:
6512: my %currsettings =
6513: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6514: $cdom,$cnum);
6515: $visible = 0;
6516: if ($currsettings{'internal.coursecode'} ne '') {
6517: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6518: $cathash = $domconf->{'coursecategories'}{'cats'};
6519: if (ref($cathash) eq 'HASH') {
6520: if ($cathash->{'instcode::0'} eq '') {
6521: push(@vismsgs,'dc_addinst');
6522: } else {
6523: $visible = 1;
6524: }
6525: } else {
6526: $visible = 1;
6527: }
6528: } else {
6529: $visible = 1;
6530: }
6531: } else {
6532: if (ref($cathash) eq 'HASH') {
6533: if ($cathash->{'instcode::0'} ne '') {
6534: push(@vismsgs,'dc_instcode');
6535: }
6536: } else {
6537: push(@vismsgs,'dc_instcode');
6538: }
6539: }
6540: if ($currsettings{'categories'} ne '') {
6541: my $cathash;
6542: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6543: $cathash = $domconf->{'coursecategories'}{'cats'};
6544: if (ref($cathash) eq 'HASH') {
6545: if (keys(%{$cathash}) == 0) {
6546: push(@vismsgs,'dc_catalog');
6547: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6548: push(@vismsgs,'dc_categories');
6549: } else {
6550: my @currcategories = split('&',$currsettings{'categories'});
6551: my $matched = 0;
6552: foreach my $cat (@currcategories) {
6553: if ($cathash->{$cat} ne '') {
6554: $visible = 1;
6555: $matched = 1;
6556: last;
6557: }
6558: }
6559: if (!$matched) {
6560: if ($settable{'categorize'}) {
6561: push(@vismsgs,'chgcat');
6562: } else {
6563: push(@vismsgs,'dc_chgcat');
6564: }
6565: }
6566: }
6567: }
6568: }
6569: } else {
6570: if (ref($cathash) eq 'HASH') {
6571: if ((keys(%{$cathash}) > 1) ||
6572: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
6573: if ($settable{'categorize'}) {
6574: push(@vismsgs,'addcat');
6575: } else {
6576: push(@vismsgs,'dc_addcat');
6577: }
6578: }
6579: }
6580: }
6581: if ($currsettings{'hidefromcat'} eq 'yes') {
6582: $visible = 0;
6583: if ($settable{'togglecats'}) {
6584: unshift(@vismsgs,'unhide');
6585: } else {
6586: unshift(@vismsgs,'dc_unhide')
6587: }
6588: }
6589: return ($visible,$cansetvis,\@vismsgs);
6590: }
6591:
6592: sub cat_visibility {
6593: my %visactions = &Apache::lonlocal::texthash(
6594: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6595: 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.',
6596: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6597: none => 'Display of a course catalog is disabled for this domain.',
6598: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6599: 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.',
6600: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6601: take => 'Take the following action to ensure the course appears in the Catalog:',
6602: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6603: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6604: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6605: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6606: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6607: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6608: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6609: 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',
6610: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6611: );
6612: $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>"');
6613: $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>"');
6614: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6615: return \%visactions;
6616: }
6617:
6618: sub new_selfenroll_dom_row {
6619: my ($newdom,$num) = @_;
6620: my $domdesc = &Apache::lonnet::domain($newdom);
6621: my $output;
6622: if ($domdesc ne '') {
6623: $output .= &Apache::loncommon::start_data_table_row()
6624: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6625: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
6626: .'" value="'.$newdom.'" /></span><br />'
6627: .'<span class="LC_nobreak"><label><input type="checkbox" '
6628: .'name="selfenroll_activate" value="'.$num.'" '
6629: .'onchange="javascript:update_types('
6630: ."'selfenroll_activate','$num'".');" />'
6631: .&mt('Activate').'</label></span></td>';
6632: my @currinsttypes;
6633: $output .= '<td>'.&mt('User types:').'<br />'
6634: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6635: .&Apache::loncommon::end_data_table_row();
6636: }
6637: return $output;
6638: }
6639:
6640: sub selfenroll_inst_types {
6641: my ($num,$currdom,$currinsttypes,$readonly) = @_;
6642: my $output;
6643: my $numinrow = 4;
6644: my $count = 0;
6645: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
6646: my $othervalue = 'any';
6647: my $disabled;
6648: if ($readonly) {
6649: $disabled = ' disabled="disabled"';
6650: }
6651: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6652: if (keys(%{$usertypes}) > 0) {
6653: $othervalue = 'other';
6654: }
6655: $output .= '<table><tr>';
6656: foreach my $type (@{$types}) {
6657: if (($count > 0) && ($count%$numinrow == 0)) {
6658: $output .= '</tr><tr>';
6659: }
6660: if (defined($usertypes->{$type})) {
6661: my $esc_type = &escape($type);
6662: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
6663: $esc_type.'" ';
6664: if (ref($currinsttypes) eq 'ARRAY') {
6665: if (@{$currinsttypes} > 0) {
6666: if (grep(/^any$/,@{$currinsttypes})) {
6667: $output .= 'checked="checked"';
6668: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
6669: $output .= 'checked="checked"';
6670: }
6671: } else {
6672: $output .= 'checked="checked"';
6673: }
6674: }
6675: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
6676: }
6677: $count ++;
6678: }
6679: if (($count > 0) && ($count%$numinrow == 0)) {
6680: $output .= '</tr><tr>';
6681: }
6682: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
6683: if (ref($currinsttypes) eq 'ARRAY') {
6684: if (@{$currinsttypes} > 0) {
6685: if (grep(/^any$/,@{$currinsttypes})) {
6686: $output .= ' checked="checked"';
6687: } elsif ($othervalue eq 'other') {
6688: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6689: $output .= ' checked="checked"';
6690: }
6691: }
6692: } else {
6693: $output .= ' checked="checked"';
6694: }
6695: } else {
6696: $output .= ' checked="checked"';
6697: }
6698: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
6699: }
6700: return $output;
6701: }
6702:
6703: sub selfenroll_date_forms {
6704: my ($startform,$endform) = @_;
6705: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
6706: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
6707: 'LC_oddrow_value')."\n".
6708: $startform."\n".
6709: &Apache::lonhtmlcommon::row_closure(1).
6710: &Apache::lonhtmlcommon::row_title(&mt('End date'),
6711: 'LC_oddrow_value')."\n".
6712: $endform."\n".
6713: &Apache::lonhtmlcommon::row_closure(1).
6714: &Apache::lonhtmlcommon::end_pick_box();
6715: return $output;
6716: }
6717:
6718: sub print_userchangelogs_display {
6719: my ($r,$context,$permission,$brcrum) = @_;
6720: my $formname = 'rolelog';
6721: my ($username,$domain,$crstype,$viewablesec,%roleslog);
6722: if ($context eq 'domain') {
6723: $domain = $env{'request.role.domain'};
6724: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6725: } else {
6726: if ($context eq 'course') {
6727: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6728: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6729: $crstype = &Apache::loncommon::course_type();
6730: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
6731: my %saveable_parameters = ('show' => 'scalar',);
6732: &Apache::loncommon::store_course_settings('roles_log',
6733: \%saveable_parameters);
6734: &Apache::loncommon::restore_course_settings('roles_log',
6735: \%saveable_parameters);
6736: } elsif ($context eq 'author') {
6737: $domain = $env{'user.domain'};
6738: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6739: $username = $env{'user.name'};
6740: } else {
6741: undef($domain);
6742: }
6743: }
6744: if ($domain ne '' && $username ne '') {
6745: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6746: }
6747: }
6748: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6749:
6750: my $helpitem;
6751: if ($context eq 'course') {
6752: $helpitem = 'Course_User_Logs';
6753: } elsif ($context eq 'domain') {
6754: $helpitem = 'Domain_Role_Logs';
6755: } elsif ($context eq 'author') {
6756: $helpitem = 'Author_User_Logs';
6757: }
6758: push (@{$brcrum},
6759: {href => '/adm/createuser?action=changelogs',
6760: text => 'User Management Logs',
6761: help => $helpitem});
6762: my $bread_crumbs_component = 'User Changes';
6763: my $args = { bread_crumbs => $brcrum,
6764: bread_crumbs_component => $bread_crumbs_component};
6765:
6766: # Create navigation javascript
6767: my $jsnav = &userlogdisplay_js($formname);
6768:
6769: my $jscript = (<<ENDSCRIPT);
6770: <script type="text/javascript">
6771: // <![CDATA[
6772: $jsnav
6773: // ]]>
6774: </script>
6775: ENDSCRIPT
6776:
6777: # print page header
6778: $r->print(&header($jscript,$args));
6779:
6780: # set defaults
6781: my $now = time();
6782: my $defstart = $now - (7*24*3600); #7 days ago
6783: my %defaults = (
6784: page => '1',
6785: show => '10',
6786: role => 'any',
6787: chgcontext => 'any',
6788: rolelog_start_date => $defstart,
6789: rolelog_end_date => $now,
6790: );
6791: my $more_records = 0;
6792:
6793: # set current
6794: my %curr;
6795: foreach my $item ('show','page','role','chgcontext') {
6796: $curr{$item} = $env{'form.'.$item};
6797: }
6798: my ($startdate,$enddate) =
6799: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6800: $curr{'rolelog_start_date'} = $startdate;
6801: $curr{'rolelog_end_date'} = $enddate;
6802: foreach my $key (keys(%defaults)) {
6803: if ($curr{$key} eq '') {
6804: $curr{$key} = $defaults{$key};
6805: }
6806: }
6807: my (%whodunit,%changed,$version);
6808: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
6809: my ($minshown,$maxshown);
6810: $minshown = 1;
6811: my $count = 0;
6812: if ($curr{'show'} =~ /\D/) {
6813: $curr{'page'} = 1;
6814: } else {
6815: $maxshown = $curr{'page'} * $curr{'show'};
6816: if ($curr{'page'} > 1) {
6817: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6818: }
6819: }
6820:
6821: # Form Header
6822: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
6823: &role_display_filter($context,$formname,$domain,$username,\%curr,
6824: $version,$crstype));
6825:
6826: my $showntableheader = 0;
6827:
6828: # Table Header
6829: my $tableheader =
6830: &Apache::loncommon::start_data_table_header_row()
6831: .'<th> </th>'
6832: .'<th>'.&mt('When').'</th>'
6833: .'<th>'.&mt('Who made the change').'</th>'
6834: .'<th>'.&mt('Changed User').'</th>'
6835: .'<th>'.&mt('Role').'</th>';
6836:
6837: if ($context eq 'course') {
6838: $tableheader .= '<th>'.&mt('Section').'</th>';
6839: }
6840: $tableheader .=
6841: '<th>'.&mt('Context').'</th>'
6842: .'<th>'.&mt('Start').'</th>'
6843: .'<th>'.&mt('End').'</th>'
6844: .&Apache::loncommon::end_data_table_header_row();
6845:
6846: # Display user change log data
6847: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6848: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6849: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
6850: if ($curr{'show'} !~ /\D/) {
6851: if ($count >= $curr{'page'} * $curr{'show'}) {
6852: $more_records = 1;
6853: last;
6854: }
6855: }
6856: if ($curr{'role'} ne 'any') {
6857: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6858: }
6859: if ($curr{'chgcontext'} ne 'any') {
6860: if ($curr{'chgcontext'} eq 'selfenroll') {
6861: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6862: } else {
6863: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6864: }
6865: }
6866: if (($context eq 'course') && ($viewablesec ne '')) {
6867: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
6868: }
6869: $count ++;
6870: next if ($count < $minshown);
6871: unless ($showntableheader) {
6872: $r->print(&Apache::loncommon::start_data_table()
6873: .$tableheader);
6874: $r->rflush();
6875: $showntableheader = 1;
6876: }
6877: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6878: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6879: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6880: }
6881: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6882: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6883: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6884: }
6885: my $sec = $roleslog{$id}{'logentry'}{'section'};
6886: if ($sec eq '') {
6887: $sec = &mt('None');
6888: }
6889: my ($rolestart,$roleend);
6890: if ($roleslog{$id}{'delflag'}) {
6891: $rolestart = &mt('deleted');
6892: $roleend = &mt('deleted');
6893: } else {
6894: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6895: $roleend = $roleslog{$id}{'logentry'}{'end'};
6896: if ($rolestart eq '' || $rolestart == 0) {
6897: $rolestart = &mt('No start date');
6898: } else {
6899: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6900: }
6901: if ($roleend eq '' || $roleend == 0) {
6902: $roleend = &mt('No end date');
6903: } else {
6904: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6905: }
6906: }
6907: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6908: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6909: $chgcontext = 'selfenroll';
6910: }
6911: my %lt = &rolechg_contexts($context,$crstype);
6912: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6913: $chgcontext = $lt{$chgcontext};
6914: }
6915: $r->print(
6916: &Apache::loncommon::start_data_table_row()
6917: .'<td>'.$count.'</td>'
6918: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6919: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6920: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
6921: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6922: if ($context eq 'course') {
6923: $r->print('<td>'.$sec.'</td>');
6924: }
6925: $r->print(
6926: '<td>'.$chgcontext.'</td>'
6927: .'<td>'.$rolestart.'</td>'
6928: .'<td>'.$roleend.'</td>'
6929: .&Apache::loncommon::end_data_table_row()."\n");
6930: }
6931:
6932: if ($showntableheader) { # Table footer, if content displayed above
6933: $r->print(&Apache::loncommon::end_data_table().
6934: &userlogdisplay_navlinks(\%curr,$more_records));
6935: } else { # No content displayed above
6936: $r->print('<p class="LC_info">'
6937: .&mt('There are no records to display.')
6938: .'</p>'
6939: );
6940: }
6941:
6942: # Form Footer
6943: $r->print(
6944: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6945: .'<input type="hidden" name="action" value="changelogs" />'
6946: .'</form>');
6947: return;
6948: }
6949:
6950: sub print_useraccesslogs_display {
6951: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6952: my $formname = 'accesslog';
6953: my $form = 'document.accesslog';
6954:
6955: # set breadcrumbs
6956: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
6957: my $prevphasestr;
6958: if ($env{'form.popup'}) {
6959: $brcrum = [];
6960: } else {
6961: push (@{$brcrum},
6962: {href => "javascript:backPage($form)",
6963: text => $breadcrumb_text{'search'}});
6964: my @prevphases;
6965: if ($env{'form.prevphases'}) {
6966: @prevphases = split(/,/,$env{'form.prevphases'});
6967: $prevphasestr = $env{'form.prevphases'};
6968: }
6969: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6970: push(@{$brcrum},
6971: {href => "javascript:backPage($form,'get_user_info','select')",
6972: text => $breadcrumb_text{'userpicked'}});
6973: if ($env{'form.phase'} eq 'userpicked') {
6974: $prevphasestr = 'userpicked';
6975: }
6976: }
6977: }
6978: push(@{$brcrum},
6979: {href => '/adm/createuser?action=accesslogs',
6980: text => 'User access logs',
6981: help => 'Domain_User_Access_Logs'});
6982: my $bread_crumbs_component = 'User Access Logs';
6983: my $args = { bread_crumbs => $brcrum,
6984: bread_crumbs_component => 'User Management'};
6985: if ($env{'form.popup'}) {
6986: $args->{'no_nav_bar'} = 1;
6987: $args->{'bread_crumbs_nomenu'} = 1;
6988: }
6989:
6990: # set javascript
6991: my ($jsback,$elements) = &crumb_utilities();
6992: my $jsnav = &userlogdisplay_js($formname);
6993:
6994: my $jscript = (<<ENDSCRIPT);
6995: <script type="text/javascript">
6996: // <![CDATA[
6997:
6998: $jsback
6999: $jsnav
7000:
7001: // ]]>
7002: </script>
7003:
7004: ENDSCRIPT
7005:
7006: # print page header
7007: $r->print(&header($jscript,$args));
7008:
7009: # early out unless log data can be displayed.
7010: unless ($permission->{'activity'}) {
7011: $r->print('<p class="LC_warning">'
7012: .&mt('You do not have rights to display user access logs.')
7013: .'</p>');
7014: if ($env{'form.popup'}) {
7015: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7016: } else {
7017: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7018: }
7019: return;
7020: }
7021:
7022: unless ($udom eq $env{'request.role.domain'}) {
7023: $r->print('<p class="LC_warning">'
7024: .&mt("User's domain must match role's domain")
7025: .'</p>'
7026: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7027: return;
7028: }
7029:
7030: if (($uname eq '') || ($udom eq '')) {
7031: $r->print('<p class="LC_warning">'
7032: .&mt('Invalid username or domain')
7033: .'</p>'
7034: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7035: return;
7036: }
7037:
7038: if (&Apache::lonnet::privileged($uname,$udom,
7039: [$env{'request.role.domain'}],['dc','su'])) {
7040: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
7041: [$env{'request.role.domain'}],['dc','su'])) {
7042: $r->print('<p class="LC_warning">'
7043: .&mt('You need to be a privileged user to display user access logs for [_1]',
7044: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
7045: $uname,$udom))
7046: .'</p>');
7047: if ($env{'form.popup'}) {
7048: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7049: } else {
7050: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7051: }
7052: return;
7053: }
7054: }
7055:
7056: # set defaults
7057: my $now = time();
7058: my $defstart = $now - (7*24*3600);
7059: my %defaults = (
7060: page => '1',
7061: show => '10',
7062: activity => 'any',
7063: accesslog_start_date => $defstart,
7064: accesslog_end_date => $now,
7065: );
7066: my $more_records = 0;
7067:
7068: # set current
7069: my %curr;
7070: foreach my $item ('show','page','activity') {
7071: $curr{$item} = $env{'form.'.$item};
7072: }
7073: my ($startdate,$enddate) =
7074: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
7075: $curr{'accesslog_start_date'} = $startdate;
7076: $curr{'accesslog_end_date'} = $enddate;
7077: foreach my $key (keys(%defaults)) {
7078: if ($curr{$key} eq '') {
7079: $curr{$key} = $defaults{$key};
7080: }
7081: }
7082: my ($minshown,$maxshown);
7083: $minshown = 1;
7084: my $count = 0;
7085: if ($curr{'show'} =~ /\D/) {
7086: $curr{'page'} = 1;
7087: } else {
7088: $maxshown = $curr{'page'} * $curr{'show'};
7089: if ($curr{'page'} > 1) {
7090: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7091: }
7092: }
7093:
7094: # form header
7095: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7096: &activity_display_filter($formname,\%curr));
7097:
7098: my $showntableheader = 0;
7099: my ($nav_script,$nav_links);
7100:
7101: # table header
7102: my $tableheader = '<h3>'.
7103: &mt('User access logs for: [_1]',
7104: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>'
7105: .&Apache::loncommon::start_data_table_header_row()
7106: .'<th> </th>'
7107: .'<th>'.&mt('When').'</th>'
7108: .'<th>'.&mt('HostID').'</th>'
7109: .'<th>'.&mt('Event').'</th>'
7110: .'<th>'.&mt('Other data').'</th>'
7111: .&Apache::loncommon::end_data_table_header_row();
7112:
7113: my %filters=(
7114: start => $curr{'accesslog_start_date'},
7115: end => $curr{'accesslog_end_date'},
7116: action => $curr{'activity'},
7117: );
7118:
7119: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7120: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7121: my (%courses,%missing);
7122: my @results = split(/\&/,$reply);
7123: foreach my $item (reverse(@results)) {
7124: my ($timestamp,$host,$event) = split(/:/,$item);
7125: next unless ($event =~ /^(Log|Role)/);
7126: if ($curr{'show'} !~ /\D/) {
7127: if ($count >= $curr{'page'} * $curr{'show'}) {
7128: $more_records = 1;
7129: last;
7130: }
7131: }
7132: $count ++;
7133: next if ($count < $minshown);
7134: unless ($showntableheader) {
7135: $r->print($nav_script
7136: .&Apache::loncommon::start_data_table()
7137: .$tableheader);
7138: $r->rflush();
7139: $showntableheader = 1;
7140: }
7141: my ($shown,$extra);
7142: my ($event,$data) = split(/\s+/,&unescape($event),2);
7143: if ($event eq 'Role') {
7144: my ($rolecode,$extent) = split(/\./,$data,2);
7145: next if ($extent eq '');
7146: my ($crstype,$desc,$info);
7147: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7148: my ($cdom,$cnum,$sec) = ($1,$2,$3);
7149: my $cid = $cdom.'_'.$cnum;
7150: if (exists($courses{$cid})) {
7151: $crstype = $courses{$cid}{'type'};
7152: $desc = $courses{$cid}{'description'};
7153: } elsif ($missing{$cid}) {
7154: $crstype = 'Course';
7155: $desc = 'Course/Community';
7156: } else {
7157: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7158: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7159: $courses{$cid} = $crsinfo{$cid};
7160: $crstype = $crsinfo{$cid}{'type'};
7161: $desc = $crsinfo{$cid}{'description'};
7162: } else {
7163: $missing{$cid} = 1;
7164: }
7165: }
7166: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
7167: if ($sec ne '') {
7168: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7169: }
7170: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7171: my ($dom,$name) = ($1,$2);
7172: if ($rolecode eq 'au') {
7173: $extra = '';
7174: } elsif ($rolecode =~ /^(ca|aa)$/) {
7175: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
7176: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7177: $extra = &mt('Domain: [_1]',$dom);
7178: }
7179: }
7180: my $rolename;
7181: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7182: my $role = $3;
7183: my $owner = "($2:$1)";
7184: if ($2 eq $1.'-domainconfig') {
7185: $owner = '(ad hoc)';
7186: }
7187: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7188: } else {
7189: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7190: }
7191: $shown = &mt('Role selection: [_1]',$rolename);
7192: } else {
7193: $shown = &mt($event);
7194: if ($data =~ /^webdav/) {
7195: my ($path,$clientip) = split(/\s+/,$data,2);
7196: $path =~ s/^webdav//;
7197: if ($clientip ne '') {
7198: $extra = &mt('Client IP address: [_1]',$clientip);
7199: }
7200: if ($path ne '') {
7201: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7202: }
7203: } elsif ($data ne '') {
7204: $extra = &mt('Client IP address: [_1]',$data);
7205: }
7206: }
7207: $r->print(
7208: &Apache::loncommon::start_data_table_row()
7209: .'<td>'.$count.'</td>'
7210: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7211: .'<td>'.$host.'</td>'
7212: .'<td>'.$shown.'</td>'
7213: .'<td>'.$extra.'</td>'
7214: .&Apache::loncommon::end_data_table_row()."\n");
7215: }
7216: }
7217:
7218: if ($showntableheader) { # Table footer, if content displayed above
7219: $r->print(&Apache::loncommon::end_data_table().
7220: &userlogdisplay_navlinks(\%curr,$more_records));
7221: } else { # No content displayed above
7222: $r->print('<p class="LC_info">'
7223: .&mt('There are no records to display.')
7224: .'</p>');
7225: }
7226:
7227: if ($env{'form.popup'} == 1) {
7228: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7229: }
7230:
7231: # Form Footer
7232: $r->print(
7233: '<input type="hidden" name="currstate" value="" />'
7234: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7235: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7236: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7237: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7238: .'<input type="hidden" name="phase" value="activity" />'
7239: .'<input type="hidden" name="action" value="accesslogs" />'
7240: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7241: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7242: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7243: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7244: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7245: .'</form>');
7246: return;
7247: }
7248:
7249: sub earlyout_accesslog_form {
7250: my ($formname,$prevphasestr,$udom) = @_;
7251: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7252: return <<"END";
7253: <form action="/adm/createuser" method="post" name="$formname">
7254: <input type="hidden" name="currstate" value="" />
7255: <input type="hidden" name="prevphases" value="$prevphasestr" />
7256: <input type="hidden" name="phase" value="activity" />
7257: <input type="hidden" name="action" value="accesslogs" />
7258: <input type="hidden" name="srchdomain" value="$udom" />
7259: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7260: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7261: <input type="hidden" name="srchterm" value="$srchterm" />
7262: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7263: </form>
7264: END
7265: }
7266:
7267: sub activity_display_filter {
7268: my ($formname,$curr) = @_;
7269: my $nolink = 1;
7270: my $output = '<table><tr><td valign="top">'.
7271: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7272: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7273: (&mt('all'),5,10,20,50,100,1000,10000)).
7274: '</td><td> </td>';
7275: my $startform =
7276: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7277: $curr->{'accesslog_start_date'},undef,
7278: undef,undef,undef,undef,undef,undef,$nolink);
7279: my $endform =
7280: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7281: $curr->{'accesslog_end_date'},undef,
7282: undef,undef,undef,undef,undef,undef,$nolink);
7283: my %lt = &Apache::lonlocal::texthash (
7284: activity => 'Activity',
7285: Role => 'Role selection',
7286: log => 'Log-in or Logout',
7287: );
7288: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7289: '<table><tr><td>'.&mt('After:').
7290: '</td><td>'.$startform.'</td></tr>'.
7291: '<tr><td>'.&mt('Before:').'</td>'.
7292: '<td>'.$endform.'</td></tr></table>'.
7293: '</td>'.
7294: '<td> </td>'.
7295: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7296: '<select name="activity"><option value="any"';
7297: if ($curr->{'activity'} eq 'any') {
7298: $output .= ' selected="selected"';
7299: }
7300: $output .= '>'.&mt('Any').'</option>'."\n";
7301: foreach my $activity ('Role','log') {
7302: my $selstr = '';
7303: if ($activity eq $curr->{'activity'}) {
7304: $selstr = ' selected="selected"';
7305: }
7306: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7307: }
7308: $output .= '</select></td>'.
7309: '</tr></table>';
7310: # Update Display button
7311: $output .= '<p>'
7312: .'<input type="submit" value="'.&mt('Update Display').'" />'
7313: .'</p><hr />';
7314: return $output;
7315: }
7316:
7317: sub userlogdisplay_js {
7318: my ($formname) = @_;
7319: return <<"ENDSCRIPT";
7320:
7321: function chgPage(caller) {
7322: if (caller == 'previous') {
7323: document.$formname.page.value --;
7324: }
7325: if (caller == 'next') {
7326: document.$formname.page.value ++;
7327: }
7328: document.$formname.submit();
7329: return;
7330: }
7331: ENDSCRIPT
7332: }
7333:
7334: sub userlogdisplay_navlinks {
7335: my ($curr,$more_records) = @_;
7336: return unless(ref($curr) eq 'HASH');
7337: # Navigation Buttons
7338: my $nav_links = '<p>';
7339: if (($curr->{'page'} > 1) || ($more_records)) {
7340: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7341: $nav_links .= '<input type="button"'
7342: .' onclick="javascript:chgPage('."'previous'".');"'
7343: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7344: .'" /> ';
7345: }
7346: if ($more_records) {
7347: $nav_links .= '<input type="button"'
7348: .' onclick="javascript:chgPage('."'next'".');"'
7349: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7350: .'" />';
7351: }
7352: }
7353: $nav_links .= '</p>';
7354: return $nav_links;
7355: }
7356:
7357: sub role_display_filter {
7358: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7359: my $lctype;
7360: if ($context eq 'course') {
7361: $lctype = lc($crstype);
7362: }
7363: my $nolink = 1;
7364: my $output = '<table><tr><td valign="top">'.
7365: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
7366: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7367: (&mt('all'),5,10,20,50,100,1000,10000)).
7368: '</td><td> </td>';
7369: my $startform =
7370: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7371: $curr->{'rolelog_start_date'},undef,
7372: undef,undef,undef,undef,undef,undef,$nolink);
7373: my $endform =
7374: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7375: $curr->{'rolelog_end_date'},undef,
7376: undef,undef,undef,undef,undef,undef,$nolink);
7377: my %lt = &rolechg_contexts($context,$crstype);
7378: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7379: '<table><tr><td>'.&mt('After:').
7380: '</td><td>'.$startform.'</td></tr>'.
7381: '<tr><td>'.&mt('Before:').'</td>'.
7382: '<td>'.$endform.'</td></tr></table>'.
7383: '</td>'.
7384: '<td> </td>'.
7385: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7386: '<select name="role"><option value="any"';
7387: if ($curr->{'role'} eq 'any') {
7388: $output .= ' selected="selected"';
7389: }
7390: $output .= '>'.&mt('Any').'</option>'."\n";
7391: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
7392: foreach my $role (@roles) {
7393: my $plrole;
7394: if ($role eq 'cr') {
7395: $plrole = &mt('Custom Role');
7396: } else {
7397: $plrole=&Apache::lonnet::plaintext($role,$crstype);
7398: }
7399: my $selstr = '';
7400: if ($role eq $curr->{'role'}) {
7401: $selstr = ' selected="selected"';
7402: }
7403: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7404: }
7405: $output .= '</select></td>'.
7406: '<td> </td>'.
7407: '<td valign="top"><b>'.
7408: &mt('Context:').'</b><br /><select name="chgcontext">';
7409: my @posscontexts;
7410: if ($context eq 'course') {
7411: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
7412: } elsif ($context eq 'domain') {
7413: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7414: } else {
7415: @posscontexts = ('any','author','domain');
7416: }
7417: foreach my $chgtype (@posscontexts) {
7418: my $selstr = '';
7419: if ($curr->{'chgcontext'} eq $chgtype) {
7420: $selstr = ' selected="selected"';
7421: }
7422: if ($context eq 'course') {
7423: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
7424: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7425: }
7426: }
7427: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
7428: }
7429: $output .= '</select></td>'
7430: .'</tr></table>';
7431:
7432: # Update Display button
7433: $output .= '<p>'
7434: .'<input type="submit" value="'.&mt('Update Display').'" />'
7435: .'</p>';
7436:
7437: # Server version info
7438: my $needsrev = '2.11.0';
7439: if ($context eq 'course') {
7440: $needsrev = '2.7.0';
7441: }
7442:
7443: $output .= '<p class="LC_info">'
7444: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
7445: ,$needsrev);
7446: if ($version) {
7447: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7448: }
7449: $output .= '</p><hr />';
7450: return $output;
7451: }
7452:
7453: sub rolechg_contexts {
7454: my ($context,$crstype) = @_;
7455: my %lt;
7456: if ($context eq 'course') {
7457: %lt = &Apache::lonlocal::texthash (
7458: any => 'Any',
7459: automated => 'Automated Enrollment',
7460: updatenow => 'Roster Update',
7461: createcourse => 'Course Creation',
7462: course => 'User Management in course',
7463: domain => 'User Management in domain',
7464: selfenroll => 'Self-enrolled',
7465: requestcourses => 'Course Request',
7466: );
7467: if ($crstype eq 'Community') {
7468: $lt{'createcourse'} = &mt('Community Creation');
7469: $lt{'course'} = &mt('User Management in community');
7470: $lt{'requestcourses'} = &mt('Community Request');
7471: }
7472: } elsif ($context eq 'domain') {
7473: %lt = &Apache::lonlocal::texthash (
7474: any => 'Any',
7475: domain => 'User Management in domain',
7476: requestauthor => 'Authoring Request',
7477: server => 'Command line script (DC role)',
7478: domconfig => 'Self-enrolled',
7479: );
7480: } else {
7481: %lt = &Apache::lonlocal::texthash (
7482: any => 'Any',
7483: domain => 'User Management in domain',
7484: author => 'User Management by author',
7485: );
7486: }
7487: return %lt;
7488: }
7489:
7490: sub print_helpdeskaccess_display {
7491: my ($r,$permission,$brcrum) = @_;
7492: my $formname = 'helpdeskaccess';
7493: my $helpitem = 'Course_Helpdesk_Access';
7494: push (@{$brcrum},
7495: {href => '/adm/createuser?action=helpdesk',
7496: text => 'Helpdesk Access',
7497: help => $helpitem});
7498: my $bread_crumbs_component = 'Helpdesk Staff Access';
7499: my $args = { bread_crumbs => $brcrum,
7500: bread_crumbs_component => $bread_crumbs_component};
7501:
7502: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7503: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7504: my $confname = $cdom.'-domainconfig';
7505: my $crstype = &Apache::loncommon::course_type();
7506:
7507: my @accesstypes = ('all','dh','da','none');
7508: my ($numstatustypes,@jsarray);
7509: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7510: if (ref($types) eq 'ARRAY') {
7511: if (@{$types} > 0) {
7512: $numstatustypes = scalar(@{$types});
7513: push(@accesstypes,'status');
7514: @jsarray = ('bystatus');
7515: }
7516: }
7517: my %customroles = &get_domain_customroles($cdom,$confname);
7518: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
7519: if (keys(%domhelpdesk)) {
7520: push(@accesstypes,('inc','exc'));
7521: push(@jsarray,('notinc','notexc'));
7522: }
7523: push(@jsarray,'privs');
7524: my $hiddenstr = join("','",@jsarray);
7525: my $rolestr = join("','",sort(keys(%customroles)));
7526:
7527: my $jscript;
7528: my (%settings,%overridden);
7529: if (keys(%customroles)) {
7530: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7531: $types,\%customroles,\%settings,\%overridden);
7532: my %jsfull=();
7533: my %jslevels= (
7534: course => {},
7535: domain => {},
7536: system => {},
7537: );
7538: my %jslevelscurrent=(
7539: course => {},
7540: domain => {},
7541: system => {},
7542: );
7543: my (%privs,%jsprivs);
7544: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7545: foreach my $priv (keys(%jsfull)) {
7546: if ($jslevels{'course'}{$priv}) {
7547: $jsprivs{$priv} = 1;
7548: }
7549: }
7550: my (%elements,%stored);
7551: foreach my $role (keys(%customroles)) {
7552: $elements{$role.'_access'} = 'radio';
7553: $elements{$role.'_incrs'} = 'radio';
7554: if ($numstatustypes) {
7555: $elements{$role.'_status'} = 'checkbox';
7556: }
7557: if (keys(%domhelpdesk) > 0) {
7558: $elements{$role.'_staff_inc'} = 'checkbox';
7559: $elements{$role.'_staff_exc'} = 'checkbox';
7560: }
7561: $elements{$role.'_override'} = 'checkbox';
7562: if (ref($settings{$role}) eq 'HASH') {
7563: if ($settings{$role}{'access'} ne '') {
7564: my $curraccess = $settings{$role}{'access'};
7565: $stored{$role.'_access'} = $curraccess;
7566: $stored{$role.'_incrs'} = 1;
7567: if ($curraccess eq 'status') {
7568: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7569: $stored{$role.'_status'} = $settings{$role}{'status'};
7570: }
7571: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7572: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7573: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7574: }
7575: }
7576: } else {
7577: $stored{$role.'_incrs'} = 0;
7578: }
7579: $stored{$role.'_override'} = [];
7580: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7581: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7582: foreach my $priv (@{$settings{$role}{'off'}}) {
7583: push(@{$stored{$role.'_override'}},$priv);
7584: }
7585: }
7586: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7587: foreach my $priv (@{$settings{$role}{'on'}}) {
7588: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7589: push(@{$stored{$role.'_override'}},$priv);
7590: }
7591: }
7592: }
7593: }
7594: } else {
7595: $stored{$role.'_incrs'} = 0;
7596: }
7597: }
7598: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7599: }
7600:
7601: my $js = <<"ENDJS";
7602: <script type="text/javascript">
7603: // <![CDATA[
7604: $jscript;
7605:
7606: function switchRoleTab(caller,role) {
7607: if (document.getElementById(role+'_maindiv')) {
7608: if (caller.id != 'LC_current_minitab') {
7609: if (document.getElementById('LC_current_minitab')) {
7610: document.getElementById('LC_current_minitab').id=null;
7611: }
7612: var roledivs = Array('$rolestr');
7613: if (roledivs.length > 0) {
7614: for (var i=0; i<roledivs.length; i++) {
7615: if (document.getElementById(roledivs[i]+'_maindiv')) {
7616: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7617: }
7618: }
7619: }
7620: caller.id = 'LC_current_minitab';
7621: document.getElementById(role+'_maindiv').style.display='block';
7622: }
7623: }
7624: return false;
7625: }
7626:
7627: function helpdeskAccess(role) {
7628: var curraccess = null;
7629: if (document.$formname.elements[role+'_access'].length) {
7630: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7631: if (document.$formname.elements[role+'_access'][i].checked) {
7632: curraccess = document.$formname.elements[role+'_access'][i].value;
7633: }
7634: }
7635: }
7636: var shown = Array();
7637: var hidden = Array();
7638: if (curraccess == 'none') {
7639: hidden = Array ('$hiddenstr');
7640: } else {
7641: if (curraccess == 'status') {
7642: shown = Array ('bystatus','privs');
7643: hidden = Array ('notinc','notexc');
7644: } else {
7645: if (curraccess == 'exc') {
7646: shown = Array ('notexc','privs');
7647: hidden = Array ('notinc','bystatus');
7648: }
7649: if (curraccess == 'inc') {
7650: shown = Array ('notinc','privs');
7651: hidden = Array ('notexc','bystatus');
7652: }
7653: if (curraccess == 'all') {
7654: shown = Array ('privs');
7655: hidden = Array ('notinc','notexc','bystatus');
7656: }
7657: }
7658: }
7659: if (hidden.length > 0) {
7660: for (var i=0; i<hidden.length; i++) {
7661: if (document.getElementById(role+'_'+hidden[i])) {
7662: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
7663: }
7664: }
7665: }
7666: if (shown.length > 0) {
7667: for (var i=0; i<shown.length; i++) {
7668: if (document.getElementById(role+'_'+shown[i])) {
7669: if (shown[i] == 'privs') {
7670: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7671: } else {
7672: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7673: }
7674: }
7675: }
7676: }
7677: return;
7678: }
7679:
7680: function toggleAccess(role) {
7681: if ((document.getElementById(role+'_setincrs')) &&
7682: (document.getElementById(role+'_setindom'))) {
7683: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7684: if (document.$formname.elements[role+'_incrs'][i].checked) {
7685: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7686: document.getElementById(role+'_setindom').style.display = 'none';
7687: document.getElementById(role+'_setincrs').style.display = 'block';
7688: } else {
7689: document.getElementById(role+'_setincrs').style.display = 'none';
7690: document.getElementById(role+'_setindom').style.display = 'block';
7691: }
7692: break;
7693: }
7694: }
7695: }
7696: return;
7697: }
7698:
7699: // ]]>
7700: </script>
7701: ENDJS
7702:
7703: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7704:
7705: # print page header
7706: $r->print(&header($js,$args));
7707: # print form header
7708: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7709:
7710: if (keys(%customroles)) {
7711: my %lt = &Apache::lonlocal::texthash(
7712: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7713: 'rou' => 'Role usage',
7714: 'whi' => 'Which helpdesk personnel may use this role?',
7715: 'udd' => 'Use domain default',
7716: 'all' => 'All with domain helpdesk or helpdesk assistant role',
7717: 'dh' => 'All with domain helpdesk role',
7718: 'da' => 'All with domain helpdesk assistant role',
7719: 'none' => 'None',
7720: 'status' => 'Determined based on institutional status',
7721: 'inc' => 'Include all, but exclude specific personnel',
7722: 'exc' => 'Exclude all, but include specific personnel',
7723: 'hel' => 'Helpdesk',
7724: 'rpr' => 'Role privileges',
7725: );
7726: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7727: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7728: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7729: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7730: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7731: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7732: }
7733: }
7734: my $count = 0;
7735: foreach my $role (sort(keys(%customroles))) {
7736: my ($order,$desc,$access_in_dom);
7737: if (ref($domcurrent{$role}) eq 'HASH') {
7738: $order = $domcurrent{$role}{'order'};
7739: $desc = $domcurrent{$role}{'desc'};
7740: $access_in_dom = $domcurrent{$role}{'access'};
7741: }
7742: if ($order eq '') {
7743: $order = $count;
7744: }
7745: $ordered{$order} = $role;
7746: if ($desc ne '') {
7747: $description{$role} = $desc;
7748: } else {
7749: $description{$role}= $role;
7750: }
7751: $count++;
7752: }
7753: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7754: my @roles_by_num = ();
7755: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7756: push(@roles_by_num,$ordered{$item});
7757: }
7758: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
7759: if ($permission->{'owner'}) {
7760: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7761: $r->print('<input type="hidden" name="state" value="process" />'.
7762: '<input type="submit" value="'.&mt('Save changes').'" />');
7763: } else {
7764: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7765: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7766: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7767: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7768: }
7769: $disabled = ' disabled="disabled"';
7770: }
7771: $r->print('</p>');
7772:
7773: $r->print('<div id="LC_minitab_header"><ul>');
7774: my $count = 0;
7775: my %visibility;
7776: foreach my $role (@roles_by_num) {
7777: my $id;
7778: if ($count == 0) {
7779: $id=' id="LC_current_minitab"';
7780: $visibility{$role} = ' style="display:block"';
7781: } else {
7782: $visibility{$role} = ' style="display:none"';
7783: }
7784: $count ++;
7785: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7786: }
7787: $r->print('</ul></div>');
7788:
7789: foreach my $role (@roles_by_num) {
7790: my %usecheck = (
7791: all => ' checked="checked"',
7792: );
7793: my %displaydiv = (
7794: status => 'none',
7795: inc => 'none',
7796: exc => 'none',
7797: priv => 'block',
7798: );
7799: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
7800: if (ref($settings{$role}) eq 'HASH') {
7801: if ($settings{$role}{'access'} ne '') {
7802: $indomvis = ' style="display:none"';
7803: $incrsvis = ' style="display:block"';
7804: $incrscheck = ' checked="checked"';
7805: if ($settings{$role}{'access'} ne 'all') {
7806: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7807: delete($usecheck{'all'});
7808: if ($settings{$role}{'access'} eq 'status') {
7809: my $access = 'status';
7810: $displaydiv{$access} = 'inline';
7811: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7812: $selected{$access} = $settings{$role}{$access};
7813: }
7814: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7815: my $access = $1;
7816: $displaydiv{$access} = 'inline';
7817: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7818: $selected{$access} = $settings{$role}{$access};
7819: }
7820: } elsif ($settings{$role}{'access'} eq 'none') {
7821: $displaydiv{'priv'} = 'none';
7822: }
7823: }
7824: } else {
7825: $indomcheck = ' checked="checked"';
7826: $indomvis = ' style="display:block"';
7827: $incrsvis = ' style="display:none"';
7828: }
7829: } else {
7830: $indomcheck = ' checked="checked"';
7831: $indomvis = ' style="display:block"';
7832: $incrsvis = ' style="display:none"';
7833: }
7834: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7835: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7836: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7837: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7838: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7839: '<span>'.(' 'x2).
7840: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7841: $lt{'udd'}.'</label><span></p>'.
7842: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7843: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7844: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7845: foreach my $access (@accesstypes) {
7846: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7847: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7848: if ($access eq 'status') {
7849: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7850: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7851: $othertitle,$usertypes,$types,$disabled).
7852: '</div>');
7853: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7854: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7855: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7856: \%domhelpdesk,$disabled).
7857: '</div>');
7858: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7859: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7860: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7861: \%domhelpdesk,$disabled).
7862: '</div>');
7863: }
7864: $r->print('</p>');
7865: }
7866: $r->print('</div></fieldset>');
7867: my %full=();
7868: my %levels= (
7869: course => {},
7870: domain => {},
7871: system => {},
7872: );
7873: my %levelscurrent=(
7874: course => {},
7875: domain => {},
7876: system => {},
7877: );
7878: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7879: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7880: '<legend>'.$lt{'rpr'}.'</legend>'.
7881: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7882: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7883: }
7884: if ($permission->{'owner'}) {
7885: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7886: }
7887: } else {
7888: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7889: }
7890: # Form Footer
7891: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7892: .'</form>');
7893: return;
7894: }
7895:
7896: sub domain_adhoc_access {
7897: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7898: my %domusage;
7899: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7900: foreach my $role (keys(%{$roles})) {
7901: if (ref($domcurrent->{$role}) eq 'HASH') {
7902: my $access = $domcurrent->{$role}{'access'};
7903: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7904: $access = 'all';
7905: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7906: &Apache::lonnet::plaintext('da'));
7907: } elsif ($access eq 'status') {
7908: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7909: my @shown;
7910: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7911: unless ($type eq 'default') {
7912: if ($usertypes->{$type}) {
7913: push(@shown,$usertypes->{$type});
7914: }
7915: }
7916: }
7917: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7918: push(@shown,$othertitle);
7919: }
7920: if (@shown) {
7921: my $shownstatus = join(' '.&mt('or').' ',@shown);
7922: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7923: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
7924: } else {
7925: $domusage{$role} = &mt('No one in the domain');
7926: }
7927: }
7928: } elsif ($access eq 'inc') {
7929: my @dominc = ();
7930: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7931: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7932: my ($uname,$udom) = split(/:/,$user);
7933: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7934: }
7935: my $showninc = join(', ',@dominc);
7936: if ($showninc ne '') {
7937: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7938: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
7939: } else {
7940: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7941: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
7942: }
7943: }
7944: } elsif ($access eq 'exc') {
7945: my @domexc = ();
7946: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7947: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7948: my ($uname,$udom) = split(/:/,$user);
7949: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7950: }
7951: }
7952: my $shownexc = join(', ',@domexc);
7953: if ($shownexc ne '') {
7954: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7955: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
7956: } else {
7957: $domusage{$role} = &mt('No one in the domain');
7958: }
7959: } elsif ($access eq 'none') {
7960: $domusage{$role} = &mt('No one in the domain');
7961: } elsif ($access eq 'dh') {
7962: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
7963: } elsif ($access eq 'da') {
7964: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
7965: } elsif ($access eq 'all') {
7966: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7967: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
7968: }
7969: } else {
7970: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7971: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
7972: }
7973: }
7974: return %domusage;
7975: }
7976:
7977: sub get_domain_customroles {
7978: my ($cdom,$confname) = @_;
7979: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7980: my %customroles;
7981: foreach my $key (keys(%existing)) {
7982: if ($key=~/^rolesdef\_(\w+)$/) {
7983: my $rolename = $1;
7984: my %privs;
7985: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7986: $customroles{$rolename} = \%privs;
7987: }
7988: }
7989: return %customroles;
7990: }
7991:
7992: sub role_priv_table {
7993: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7994: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7995: (ref($levelscurrent) eq 'HASH'));
7996: my %lt=&Apache::lonlocal::texthash (
7997: 'crl' => 'Course Level Privilege',
7998: 'def' => 'Domain Defaults',
7999: 'ove' => 'Override in Course',
8000: 'ine' => 'In effect',
8001: 'dis' => 'Disabled',
8002: 'ena' => 'Enabled',
8003: );
8004: if ($crstype eq 'Community') {
8005: $lt{'ove'} = 'Override in Community',
8006: }
8007: my @status = ('Disabled','Enabled');
8008: my (%on,%off);
8009: if (ref($overridden) eq 'HASH') {
8010: if (ref($overridden->{'on'}) eq 'ARRAY') {
8011: map { $on{$_} = 1; } (@{$overridden->{'on'}});
8012: }
8013: if (ref($overridden->{'off'}) eq 'ARRAY') {
8014: map { $off{$_} = 1; } (@{$overridden->{'off'}});
8015: }
8016: }
8017: my $output=&Apache::loncommon::start_data_table().
8018: &Apache::loncommon::start_data_table_header_row().
8019: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
8020: '</th><th>'.$lt{'ine'}.'</th>'.
8021: &Apache::loncommon::end_data_table_header_row();
8022: foreach my $priv (sort(keys(%{$full}))) {
8023: next unless ($levels->{'course'}{$priv});
8024: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
8025: my ($default,$ineffect);
8026: if ($levelscurrent->{'course'}{$priv}) {
8027: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8028: $ineffect = $default;
8029: }
8030: my ($customstatus,$checked);
8031: $output .= &Apache::loncommon::start_data_table_row().
8032: '<td>'.$privtext.'</td>'.
8033: '<td>'.$default.'</td><td>';
8034: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
8035: if ($permission->{'owner'}) {
8036: $checked = ' checked="checked"';
8037: }
8038: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
8039: $ineffect = $customstatus;
8040: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
8041: if ($permission->{'owner'}) {
8042: $checked = ' checked="checked"';
8043: }
8044: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8045: $ineffect = $customstatus;
8046: }
8047: if ($permission->{'owner'}) {
8048: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
8049: } else {
8050: $output .= $customstatus;
8051: }
8052: $output .= '</td><td>'.$ineffect.'</td>'.
8053: &Apache::loncommon::end_data_table_row();
8054: }
8055: $output .= &Apache::loncommon::end_data_table();
8056: return $output;
8057: }
8058:
8059: sub get_adhocrole_settings {
8060: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
8061: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
8062: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
8063: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
8064: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
8065: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
8066: $settings->{$role}{'access'} = $curraccess;
8067: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
8068: my @status = split(/,/,$rest);
8069: my @currstatus;
8070: foreach my $type (@status) {
8071: if ($type eq 'default') {
8072: push(@currstatus,$type);
8073: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8074: push(@currstatus,$type);
8075: }
8076: }
8077: if (@currstatus) {
8078: $settings->{$role}{$curraccess} = \@currstatus;
8079: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8080: my @personnel = split(/,/,$rest);
8081: $settings->{$role}{$curraccess} = \@personnel;
8082: }
8083: }
8084: }
8085: }
8086: foreach my $role (keys(%{$customroles})) {
8087: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8088: my %currentprivs;
8089: if (ref($customroles->{$role}) eq 'HASH') {
8090: if (exists($customroles->{$role}{'course'})) {
8091: my %full=();
8092: my %levels= (
8093: course => {},
8094: domain => {},
8095: system => {},
8096: );
8097: my %levelscurrent=(
8098: course => {},
8099: domain => {},
8100: system => {},
8101: );
8102: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8103: %currentprivs = %{$levelscurrent{'course'}};
8104: }
8105: }
8106: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8107: next if ($item eq '');
8108: my ($rule,$rest) = split(/=/,$item);
8109: next unless (($rule eq 'off') || ($rule eq 'on'));
8110: foreach my $priv (split(/:/,$rest)) {
8111: if ($priv ne '') {
8112: if ($rule eq 'off') {
8113: push(@{$overridden->{$role}{'off'}},$priv);
8114: if ($currentprivs{$priv}) {
8115: push(@{$settings->{$role}{'off'}},$priv);
8116: }
8117: } else {
8118: push(@{$overridden->{$role}{'on'}},$priv);
8119: unless ($currentprivs{$priv}) {
8120: push(@{$settings->{$role}{'on'}},$priv);
8121: }
8122: }
8123: }
8124: }
8125: }
8126: }
8127: }
8128: return;
8129: }
8130:
8131: sub update_helpdeskaccess {
8132: my ($r,$permission,$brcrum) = @_;
8133: my $helpitem = 'Course_Helpdesk_Access';
8134: push (@{$brcrum},
8135: {href => '/adm/createuser?action=helpdesk',
8136: text => 'Helpdesk Access',
8137: help => $helpitem},
8138: {href => '/adm/createuser?action=helpdesk',
8139: text => 'Result',
8140: help => $helpitem}
8141: );
8142: my $bread_crumbs_component = 'Helpdesk Staff Access';
8143: my $args = { bread_crumbs => $brcrum,
8144: bread_crumbs_component => $bread_crumbs_component};
8145:
8146: # print page header
8147: $r->print(&header('',$args));
8148: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8149: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8150: return;
8151: }
8152: my @accesstypes = ('all','dh','da','none','status','inc','exc');
8153: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8154: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8155: my $confname = $cdom.'-domainconfig';
8156: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8157: my $crstype = &Apache::loncommon::course_type();
8158: my %customroles = &get_domain_customroles($cdom,$confname);
8159: my (%settings,%overridden);
8160: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8161: $types,\%customroles,\%settings,\%overridden);
8162: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
8163: my (%changed,%storehash,@todelete);
8164:
8165: if (keys(%customroles)) {
8166: my (%newsettings,@incrs);
8167: foreach my $role (keys(%customroles)) {
8168: $newsettings{$role} = {
8169: access => '',
8170: status => '',
8171: exc => '',
8172: inc => '',
8173: on => '',
8174: off => '',
8175: };
8176: my %current;
8177: if (ref($settings{$role}) eq 'HASH') {
8178: %current = %{$settings{$role}};
8179: }
8180: if (ref($overridden{$role}) eq 'HASH') {
8181: $current{'overridden'} = $overridden{$role};
8182: }
8183: if ($env{'form.'.$role.'_incrs'}) {
8184: my $access = $env{'form.'.$role.'_access'};
8185: if (grep(/^\Q$access\E$/,@accesstypes)) {
8186: push(@incrs,$role);
8187: unless ($current{'access'} eq $access) {
8188: $changed{$role}{'access'} = 1;
8189: $storehash{'internal.adhoc.'.$role} = $access;
8190: }
8191: if ($access eq 'status') {
8192: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8193: my @stored;
8194: my @shownstatus;
8195: if (ref($types) eq 'ARRAY') {
8196: foreach my $type (sort(@statuses)) {
8197: if ($type eq 'default') {
8198: push(@stored,$type);
8199: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8200: push(@stored,$type);
8201: push(@shownstatus,$usertypes->{$type});
8202: }
8203: }
8204: if (grep(/^default$/,@statuses)) {
8205: push(@shownstatus,$othertitle);
8206: }
8207: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8208: }
8209: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8210: if (ref($current{'status'}) eq 'ARRAY') {
8211: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8212: if (@diffs) {
8213: $changed{$role}{'status'} = 1;
8214: }
8215: } elsif (@stored) {
8216: $changed{$role}{'status'} = 1;
8217: }
8218: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8219: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8220: my @newspecstaff;
8221: my @stored;
8222: my @currstaff;
8223: foreach my $person (sort(@personnel)) {
8224: if ($domhelpdesk{$person}) {
8225: push(@stored,$person);
8226: }
8227: }
8228: if (ref($current{$access}) eq 'ARRAY') {
8229: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8230: if (@diffs) {
8231: $changed{$role}{$access} = 1;
8232: }
8233: } elsif (@stored) {
8234: $changed{$role}{$access} = 1;
8235: }
8236: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8237: foreach my $person (@stored) {
8238: my ($uname,$udom) = split(/:/,$person);
8239: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8240: }
8241: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8242: }
8243: $newsettings{$role}{'access'} = $access;
8244: }
8245: } else {
8246: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8247: $changed{$role}{'access'} = 1;
8248: $newsettings{$role} = {};
8249: push(@todelete,'internal.adhoc.'.$role);
8250: }
8251: }
8252: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8253: if (ref($current{'overridden'}) eq 'HASH') {
8254: push(@todelete,'internal.adhocpriv.'.$role);
8255: }
8256: } else {
8257: my %full=();
8258: my %levels= (
8259: course => {},
8260: domain => {},
8261: system => {},
8262: );
8263: my %levelscurrent=(
8264: course => {},
8265: domain => {},
8266: system => {},
8267: );
8268: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8269: my (@updatedon,@updatedoff,@override);
8270: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
8271: if (@override) {
8272: foreach my $priv (sort(keys(%full))) {
8273: next unless ($levels{'course'}{$priv});
8274: if (grep(/^\Q$priv\E$/,@override)) {
8275: if ($levelscurrent{'course'}{$priv}) {
8276: push(@updatedoff,$priv);
8277: } else {
8278: push(@updatedon,$priv);
8279: }
8280: }
8281: }
8282: }
8283: if (@updatedon) {
8284: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
8285: }
8286: if (@updatedoff) {
8287: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8288: }
8289: if (ref($current{'overridden'}) eq 'HASH') {
8290: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8291: if (@updatedon) {
8292: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8293: if (@diffs) {
8294: $changed{$role}{'on'} = 1;
8295: }
8296: } else {
8297: $changed{$role}{'on'} = 1;
8298: }
8299: } elsif (@updatedon) {
8300: $changed{$role}{'on'} = 1;
8301: }
8302: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8303: if (@updatedoff) {
8304: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8305: if (@diffs) {
8306: $changed{$role}{'off'} = 1;
8307: }
8308: } else {
8309: $changed{$role}{'off'} = 1;
8310: }
8311: } elsif (@updatedoff) {
8312: $changed{$role}{'off'} = 1;
8313: }
8314: } else {
8315: if (@updatedon) {
8316: $changed{$role}{'on'} = 1;
8317: }
8318: if (@updatedoff) {
8319: $changed{$role}{'off'} = 1;
8320: }
8321: }
8322: if (ref($changed{$role}) eq 'HASH') {
8323: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8324: my $newpriv;
8325: if (@updatedon) {
8326: $newpriv = 'on='.join(':',@updatedon);
8327: }
8328: if (@updatedoff) {
8329: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8330: }
8331: if ($newpriv eq '') {
8332: push(@todelete,'internal.adhocpriv.'.$role);
8333: } else {
8334: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8335: }
8336: }
8337: }
8338: }
8339: }
8340: if (@incrs) {
8341: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8342: } elsif (@todelete) {
8343: push(@todelete,'internal.adhocaccess');
8344: }
8345: if (keys(%changed)) {
8346: my ($putres,$delres);
8347: if (keys(%storehash)) {
8348: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8349: my %newenvhash;
8350: foreach my $key (keys(%storehash)) {
8351: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8352: }
8353: &Apache::lonnet::appenv(\%newenvhash);
8354: }
8355: if (@todelete) {
8356: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8357: foreach my $key (@todelete) {
8358: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8359: }
8360: }
8361: if (($putres eq 'ok') || ($delres eq 'ok')) {
8362: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8363: my (%domcurrent,%ordered,%description,%domusage);
8364: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8365: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8366: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8367: }
8368: }
8369: my $count = 0;
8370: foreach my $role (sort(keys(%customroles))) {
8371: my ($order,$desc);
8372: if (ref($domcurrent{$role}) eq 'HASH') {
8373: $order = $domcurrent{$role}{'order'};
8374: $desc = $domcurrent{$role}{'desc'};
8375: }
8376: if ($order eq '') {
8377: $order = $count;
8378: }
8379: $ordered{$order} = $role;
8380: if ($desc ne '') {
8381: $description{$role} = $desc;
8382: } else {
8383: $description{$role}= $role;
8384: }
8385: $count++;
8386: }
8387: my @roles_by_num = ();
8388: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8389: push(@roles_by_num,$ordered{$item});
8390: }
8391: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8392: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
8393: $r->print('<ul>');
8394: foreach my $role (@roles_by_num) {
8395: next unless (ref($changed{$role}) eq 'HASH');
8396: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8397: '<ul>');
8398: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
8399: $r->print('<li>');
8400: if ($env{'form.'.$role.'_incrs'}) {
8401: if ($newsettings{$role}{'access'} eq 'all') {
8402: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
8403: } elsif ($newsettings{$role}{'access'} eq 'dh') {
8404: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8405: &Apache::lonnet::plaintext('dh')));
8406: } elsif ($newsettings{$role}{'access'} eq 'da') {
8407: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8408: &Apache::lonnet::plaintext('da')));
8409: } elsif ($newsettings{$role}{'access'} eq 'none') {
8410: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8411: } elsif ($newsettings{$role}{'access'} eq 'status') {
8412: if ($newsettings{$role}{'status'}) {
8413: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
8414: if (split(/,/,$rest) > 1) {
8415: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8416: $newsettings{$role}{'status'}));
8417: } else {
8418: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8419: $newsettings{$role}{'status'}));
8420: }
8421: } else {
8422: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8423: }
8424: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8425: if ($newsettings{$role}{'exc'}) {
8426: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8427: } else {
8428: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8429: }
8430: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8431: if ($newsettings{$role}{'inc'}) {
8432: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8433: } else {
8434: $r->print(&mt('All helpdesk staff may use this role.'));
8435: }
8436: }
8437: } else {
8438: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8439: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8440: }
8441: $r->print('</li>');
8442: }
8443: unless ($newsettings{$role}{'access'} eq 'none') {
8444: if ($changed{$role}{'off'}) {
8445: if ($newsettings{$role}{'off'}) {
8446: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8447: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8448: } else {
8449: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
8450: }
8451: }
8452: if ($changed{$role}{'on'}) {
8453: if ($newsettings{$role}{'on'}) {
8454: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8455: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8456: } else {
8457: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
8458: }
8459: }
8460: }
8461: $r->print('</ul></li>');
8462: }
8463: $r->print('</ul>');
8464: }
8465: } else {
8466: $r->print(&mt('No changes made to helpdesk access settings.'));
8467: }
8468: }
8469: return;
8470: }
8471:
8472: #-------------------------------------------------- functions for &phase_two
8473: sub user_search_result {
8474: my ($context,$srch) = @_;
8475: my %allhomes;
8476: my %inst_matches;
8477: my %srch_results;
8478: my ($response,$currstate,$forcenewuser,$dirsrchres);
8479: $srch->{'srchterm'} =~ s/\s+/ /g;
8480: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
8481: $response = &mt('Invalid search.');
8482: }
8483: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8484: $response = &mt('Invalid search.');
8485: }
8486: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
8487: $response = &mt('Invalid search.');
8488: }
8489: if ($srch->{'srchterm'} eq '') {
8490: $response = &mt('You must enter a search term.');
8491: }
8492: if ($srch->{'srchterm'} =~ /^\s+$/) {
8493: $response = &mt('Your search term must contain more than just spaces.');
8494: }
8495: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8496: if (($srch->{'srchdomain'} eq '') ||
8497: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
8498: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8499: }
8500: }
8501: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8502: ($srch->{'srchin'} eq 'alc')) {
8503: if ($srch->{'srchby'} eq 'uname') {
8504: my $unamecheck = $srch->{'srchterm'};
8505: if ($srch->{'srchtype'} eq 'contains') {
8506: if ($unamecheck !~ /^\w/) {
8507: $unamecheck = 'a'.$unamecheck;
8508: }
8509: }
8510: if ($unamecheck !~ /^$match_username$/) {
8511: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8512: }
8513: }
8514: }
8515: if ($response ne '') {
8516: $response = '<span class="LC_warning">'.$response.'</span><br />';
8517: }
8518: if ($srch->{'srchin'} eq 'instd') {
8519: my $instd_chk = &instdirectorysrch_check($srch);
8520: if ($instd_chk ne 'ok') {
8521: my $domd_chk = &domdirectorysrch_check($srch);
8522: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
8523: if ($domd_chk eq 'ok') {
8524: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
8525: }
8526: $response .= '<br />';
8527: }
8528: } else {
8529: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
8530: my $domd_chk = &domdirectorysrch_check($srch);
8531: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
8532: my $instd_chk = &instdirectorysrch_check($srch);
8533: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
8534: if ($instd_chk eq 'ok') {
8535: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
8536: }
8537: $response .= '<br />';
8538: }
8539: }
8540: }
8541: if ($response ne '') {
8542: return ($currstate,$response);
8543: }
8544: if ($srch->{'srchby'} eq 'uname') {
8545: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8546: if ($env{'form.forcenew'}) {
8547: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8548: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8549: if ($uhome eq 'no_host') {
8550: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
8551: my $showdom = &display_domain_info($env{'request.role.domain'});
8552: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
8553: } else {
8554: $currstate = 'modify';
8555: }
8556: } else {
8557: $currstate = 'modify';
8558: }
8559: } else {
8560: if ($srch->{'srchin'} eq 'dom') {
8561: if ($srch->{'srchtype'} eq 'exact') {
8562: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8563: if ($uhome eq 'no_host') {
8564: ($currstate,$response,$forcenewuser) =
8565: &build_search_response($context,$srch,%srch_results);
8566: } else {
8567: $currstate = 'modify';
8568: if ($env{'form.action'} eq 'accesslogs') {
8569: $currstate = 'activity';
8570: }
8571: my $uname = $srch->{'srchterm'};
8572: my $udom = $srch->{'srchdomain'};
8573: $srch_results{$uname.':'.$udom} =
8574: { &Apache::lonnet::get('environment',
8575: ['firstname',
8576: 'lastname',
8577: 'permanentemail'],
8578: $udom,$uname)
8579: };
8580: }
8581: } else {
8582: %srch_results = &Apache::lonnet::usersearch($srch);
8583: ($currstate,$response,$forcenewuser) =
8584: &build_search_response($context,$srch,%srch_results);
8585: }
8586: } else {
8587: my $courseusers = &get_courseusers();
8588: if ($srch->{'srchtype'} eq 'exact') {
8589: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
8590: $currstate = 'modify';
8591: } else {
8592: ($currstate,$response,$forcenewuser) =
8593: &build_search_response($context,$srch,%srch_results);
8594: }
8595: } else {
8596: foreach my $user (keys(%$courseusers)) {
8597: my ($cuname,$cudomain) = split(/:/,$user);
8598: if ($cudomain eq $srch->{'srchdomain'}) {
8599: my $matched = 0;
8600: if ($srch->{'srchtype'} eq 'begins') {
8601: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8602: $matched = 1;
8603: }
8604: } else {
8605: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8606: $matched = 1;
8607: }
8608: }
8609: if ($matched) {
8610: $srch_results{$user} =
8611: {&Apache::lonnet::get('environment',
8612: ['firstname',
8613: 'lastname',
8614: 'permanentemail'],
8615: $cudomain,$cuname)};
8616: }
8617: }
8618: }
8619: ($currstate,$response,$forcenewuser) =
8620: &build_search_response($context,$srch,%srch_results);
8621: }
8622: }
8623: }
8624: } elsif ($srch->{'srchin'} eq 'alc') {
8625: $currstate = 'query';
8626: } elsif ($srch->{'srchin'} eq 'instd') {
8627: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8628: if ($dirsrchres eq 'ok') {
8629: ($currstate,$response,$forcenewuser) =
8630: &build_search_response($context,$srch,%srch_results);
8631: } else {
8632: my $showdom = &display_domain_info($srch->{'srchdomain'});
8633: $response = '<span class="LC_warning">'.
8634: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8635: '</span><br />'.
8636: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
8637: '<br />';
8638: }
8639: }
8640: } else {
8641: if ($srch->{'srchin'} eq 'dom') {
8642: %srch_results = &Apache::lonnet::usersearch($srch);
8643: ($currstate,$response,$forcenewuser) =
8644: &build_search_response($context,$srch,%srch_results);
8645: } elsif ($srch->{'srchin'} eq 'crs') {
8646: my $courseusers = &get_courseusers();
8647: foreach my $user (keys(%$courseusers)) {
8648: my ($uname,$udom) = split(/:/,$user);
8649: my %names = &Apache::loncommon::getnames($uname,$udom);
8650: my %emails = &Apache::loncommon::getemails($uname,$udom);
8651: if ($srch->{'srchby'} eq 'lastname') {
8652: if ((($srch->{'srchtype'} eq 'exact') &&
8653: ($names{'lastname'} eq $srch->{'srchterm'})) ||
8654: (($srch->{'srchtype'} eq 'begins') &&
8655: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
8656: (($srch->{'srchtype'} eq 'contains') &&
8657: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8658: $srch_results{$user} = {firstname => $names{'firstname'},
8659: lastname => $names{'lastname'},
8660: permanentemail => $emails{'permanentemail'},
8661: };
8662: }
8663: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8664: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
8665: $srchlast =~ s/\s+$//;
8666: $srchfirst =~ s/^\s+//;
8667: if ($srch->{'srchtype'} eq 'exact') {
8668: if (($names{'lastname'} eq $srchlast) &&
8669: ($names{'firstname'} eq $srchfirst)) {
8670: $srch_results{$user} = {firstname => $names{'firstname'},
8671: lastname => $names{'lastname'},
8672: permanentemail => $emails{'permanentemail'},
8673:
8674: };
8675: }
8676: } elsif ($srch->{'srchtype'} eq 'begins') {
8677: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8678: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8679: $srch_results{$user} = {firstname => $names{'firstname'},
8680: lastname => $names{'lastname'},
8681: permanentemail => $emails{'permanentemail'},
8682: };
8683: }
8684: } else {
8685: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8686: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8687: $srch_results{$user} = {firstname => $names{'firstname'},
8688: lastname => $names{'lastname'},
8689: permanentemail => $emails{'permanentemail'},
8690: };
8691: }
8692: }
8693: }
8694: }
8695: ($currstate,$response,$forcenewuser) =
8696: &build_search_response($context,$srch,%srch_results);
8697: } elsif ($srch->{'srchin'} eq 'alc') {
8698: $currstate = 'query';
8699: } elsif ($srch->{'srchin'} eq 'instd') {
8700: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8701: if ($dirsrchres eq 'ok') {
8702: ($currstate,$response,$forcenewuser) =
8703: &build_search_response($context,$srch,%srch_results);
8704: } else {
8705: my $showdom = &display_domain_info($srch->{'srchdomain'});
8706: $response = '<span class="LC_warning">'.
8707: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8708: '</span><br />'.
8709: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
8710: '<br />';
8711: }
8712: }
8713: }
8714: return ($currstate,$response,$forcenewuser,\%srch_results);
8715: }
8716:
8717: sub domdirectorysrch_check {
8718: my ($srch) = @_;
8719: my $response;
8720: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8721: ['directorysrch'],$srch->{'srchdomain'});
8722: my $showdom = &display_domain_info($srch->{'srchdomain'});
8723: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8724: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8725: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8726: }
8727: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8728: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8729: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8730: }
8731: }
8732: }
8733: return 'ok';
8734: }
8735:
8736: sub instdirectorysrch_check {
8737: my ($srch) = @_;
8738: my $can_search = 0;
8739: my $response;
8740: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8741: ['directorysrch'],$srch->{'srchdomain'});
8742: my $showdom = &display_domain_info($srch->{'srchdomain'});
8743: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8744: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
8745: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
8746: }
8747: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8748: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8749: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8750: }
8751: my @usertypes = split(/:/,$env{'environment.inststatus'});
8752: if (!@usertypes) {
8753: push(@usertypes,'default');
8754: }
8755: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8756: foreach my $type (@usertypes) {
8757: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8758: $can_search = 1;
8759: last;
8760: }
8761: }
8762: }
8763: if (!$can_search) {
8764: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8765: my @longtypes;
8766: foreach my $item (@usertypes) {
8767: if (defined($insttypes->{$item})) {
8768: push (@longtypes,$insttypes->{$item});
8769: } elsif ($item eq 'default') {
8770: push (@longtypes,&mt('other'));
8771: }
8772: }
8773: my $insttype_str = join(', ',@longtypes);
8774: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
8775: }
8776: } else {
8777: $can_search = 1;
8778: }
8779: } else {
8780: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
8781: }
8782: my %longtext = &Apache::lonlocal::texthash (
8783: uname => 'username',
8784: lastfirst => 'last name, first name',
8785: lastname => 'last name',
8786: contains => 'contains',
8787: exact => 'as exact match to',
8788: begins => 'begins with',
8789: );
8790: if ($can_search) {
8791: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8792: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
8793: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
8794: }
8795: } else {
8796: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
8797: }
8798: }
8799: if ($can_search) {
8800: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8801: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8802: return 'ok';
8803: } else {
8804: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
8805: }
8806: } else {
8807: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8808: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8809: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8810: return 'ok';
8811: } else {
8812: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
8813: }
8814: }
8815: }
8816: }
8817:
8818: sub get_courseusers {
8819: my %advhash;
8820: my $classlist = &Apache::loncoursedata::get_classlist();
8821: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8822: foreach my $role (sort(keys(%coursepersonnel))) {
8823: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
8824: if (!exists($classlist->{$user})) {
8825: $classlist->{$user} = [];
8826: }
8827: }
8828: }
8829: return $classlist;
8830: }
8831:
8832: sub build_search_response {
8833: my ($context,$srch,%srch_results) = @_;
8834: my ($currstate,$response,$forcenewuser);
8835: my %names = (
8836: 'uname' => 'username',
8837: 'lastname' => 'last name',
8838: 'lastfirst' => 'last name, first name',
8839: 'crs' => 'this course',
8840: 'dom' => 'LON-CAPA domain',
8841: 'instd' => 'the institutional directory for domain',
8842: );
8843:
8844: my %single = (
8845: begins => 'A match',
8846: contains => 'A match',
8847: exact => 'An exact match',
8848: );
8849: my %nomatch = (
8850: begins => 'No match',
8851: contains => 'No match',
8852: exact => 'No exact match',
8853: );
8854: if (keys(%srch_results) > 1) {
8855: $currstate = 'select';
8856: } else {
8857: if (keys(%srch_results) == 1) {
8858: if ($env{'form.action'} eq 'accesslogs') {
8859: $currstate = 'activity';
8860: } else {
8861: $currstate = 'modify';
8862: }
8863: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8864: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
8865: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
8866: }
8867: } else { # Search has nothing found. Prepare message to user.
8868: $response = '<span class="LC_warning">';
8869: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
8870: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8871: '<b>'.$srch->{'srchterm'}.'</b>',
8872: &display_domain_info($srch->{'srchdomain'}));
8873: } else {
8874: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8875: '<b>'.$srch->{'srchterm'}.'</b>');
8876: }
8877: $response .= '</span>';
8878:
8879: if ($srch->{'srchin'} ne 'alc') {
8880: $forcenewuser = 1;
8881: my $cansrchinst = 0;
8882: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
8883: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8884: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8885: if ($domconfig{'directorysrch'}{'available'}) {
8886: $cansrchinst = 1;
8887: }
8888: }
8889: }
8890: if ((($srch->{'srchby'} eq 'lastfirst') ||
8891: ($srch->{'srchby'} eq 'lastname')) &&
8892: ($srch->{'srchin'} eq 'dom')) {
8893: if ($cansrchinst) {
8894: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
8895: }
8896: }
8897: if ($srch->{'srchin'} eq 'crs') {
8898: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8899: }
8900: }
8901: my $createdom = $env{'request.role.domain'};
8902: if ($context eq 'requestcrs') {
8903: if ($env{'form.coursedom'} ne '') {
8904: $createdom = $env{'form.coursedom'};
8905: }
8906: }
8907: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8908: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
8909: my $cancreate =
8910: &Apache::lonuserutils::can_create_user($createdom,$context);
8911: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
8912: if ($cancreate) {
8913: my $showdom = &display_domain_info($createdom);
8914: $response .= '<br /><br />'
8915: .'<b>'.&mt('To add a new user:').'</b>'
8916: .'<br />';
8917: if ($context eq 'requestcrs') {
8918: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8919: } else {
8920: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8921: }
8922: $response .='<ul><li>'
8923: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8924: .'</li><li>'
8925: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8926: .'</li><li>'
8927: .&mt('Provide the proposed username')
8928: .'</li><li>'
8929: .&mt("Click 'Search'")
8930: .'</li></ul><br />';
8931: } else {
8932: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8933: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8934: $response .= '<br /><br />';
8935: if ($context eq 'requestcrs') {
8936: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8937: } else {
8938: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8939: }
8940: $response .= '<br />'
8941: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8942: ,' <a'.$helplink.'>'
8943: ,'</a>')
8944: .'<br />';
8945: }
8946: }
8947: }
8948: }
8949: }
8950: return ($currstate,$response,$forcenewuser);
8951: }
8952:
8953: sub display_domain_info {
8954: my ($dom) = @_;
8955: my $output = $dom;
8956: if ($dom ne '') {
8957: my $domdesc = &Apache::lonnet::domain($dom,'description');
8958: if ($domdesc ne '') {
8959: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8960: }
8961: }
8962: return $output;
8963: }
8964:
8965: sub crumb_utilities {
8966: my %elements = (
8967: crtuser => {
8968: srchterm => 'text',
8969: srchin => 'selectbox',
8970: srchby => 'selectbox',
8971: srchtype => 'selectbox',
8972: srchdomain => 'selectbox',
8973: },
8974: crtusername => {
8975: srchterm => 'text',
8976: srchdomain => 'selectbox',
8977: },
8978: docustom => {
8979: rolename => 'selectbox',
8980: newrolename => 'textbox',
8981: },
8982: studentform => {
8983: srchterm => 'text',
8984: srchin => 'selectbox',
8985: srchby => 'selectbox',
8986: srchtype => 'selectbox',
8987: srchdomain => 'selectbox',
8988: },
8989: );
8990:
8991: my $jsback .= qq|
8992: function backPage(formname,prevphase,prevstate) {
8993: if (typeof prevphase == 'undefined') {
8994: formname.phase.value = '';
8995: }
8996: else {
8997: formname.phase.value = prevphase;
8998: }
8999: if (typeof prevstate == 'undefined') {
9000: formname.currstate.value = '';
9001: }
9002: else {
9003: formname.currstate.value = prevstate;
9004: }
9005: formname.submit();
9006: }
9007: |;
9008: return ($jsback,\%elements);
9009: }
9010:
9011: sub course_level_table {
9012: my ($inccourses,$showcredits,$defaultcredits) = @_;
9013: return unless (ref($inccourses) eq 'HASH');
9014: my $table = '';
9015: # Custom Roles?
9016:
9017: my %customroles=&Apache::lonuserutils::my_custom_roles();
9018: my %lt=&Apache::lonlocal::texthash(
9019: 'exs' => "Existing sections",
9020: 'new' => "Define new section",
9021: 'ssd' => "Set Start Date",
9022: 'sed' => "Set End Date",
9023: 'crl' => "Course Level",
9024: 'act' => "Activate",
9025: 'rol' => "Role",
9026: 'ext' => "Extent",
9027: 'grs' => "Section",
9028: 'crd' => "Credits",
9029: 'sta' => "Start",
9030: 'end' => "End"
9031: );
9032:
9033: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
9034: my $thiscourse=$protectedcourse;
9035: $thiscourse=~s:_:/:g;
9036: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
9037: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
9038: my $area=$coursedata{'description'};
9039: my $crstype=$coursedata{'type'};
9040: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
9041: my ($domain,$cnum)=split(/\//,$thiscourse);
9042: my %sections_count;
9043: if (defined($env{'request.course.id'})) {
9044: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
9045: %sections_count =
9046: &Apache::loncommon::get_sections($domain,$cnum);
9047: }
9048: }
9049: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
9050: foreach my $role (@roles) {
9051: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
9052: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
9053: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
9054: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
9055: $plrole,\%sections_count,\%lt,
9056: $showcredits,$defaultcredits,$crstype);
9057: } elsif ($env{'request.course.sec'} ne '') {
9058: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
9059: $env{'request.course.sec'})) {
9060: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
9061: $plrole,\%sections_count,\%lt,
9062: $showcredits,$defaultcredits,$crstype);
9063: }
9064: }
9065: }
9066: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
9067: foreach my $cust (sort(keys(%customroles))) {
9068: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
9069: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
9070: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
9071: $cust,\%sections_count,\%lt,
9072: $showcredits,$defaultcredits,$crstype);
9073: }
9074: }
9075: }
9076: return '' if ($table eq ''); # return nothing if there is nothing
9077: # in the table
9078: my $result;
9079: if (!$env{'request.course.id'}) {
9080: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9081: }
9082: $result .=
9083: &Apache::loncommon::start_data_table().
9084: &Apache::loncommon::start_data_table_header_row().
9085: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
9086: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9087: if ($showcredits) {
9088: $result .= $lt{'crd'}.'</th>';
9089: }
9090: $result .=
9091: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9092: '<th>'.$lt{'end'}.'</th>'.
9093: &Apache::loncommon::end_data_table_header_row().
9094: $table.
9095: &Apache::loncommon::end_data_table();
9096: return $result;
9097: }
9098:
9099: sub course_level_row {
9100: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
9101: $lt,$showcredits,$defaultcredits,$crstype) = @_;
9102: my $creditem;
9103: my $row = &Apache::loncommon::start_data_table_row().
9104: ' <td><input type="checkbox" name="act_'.
9105: $protectedcourse.'_'.$role.'" /></td>'."\n".
9106: ' <td>'.$plrole.'</td>'."\n".
9107: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
9108: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
9109: $row .=
9110: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9111: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9112: } else {
9113: $row .= '<td> </td>';
9114: }
9115: if (($role eq 'cc') || ($role eq 'co')) {
9116: $row .= '<td> </td>';
9117: } elsif ($env{'request.course.sec'} ne '') {
9118: $row .= ' <td><input type="hidden" value="'.
9119: $env{'request.course.sec'}.'" '.
9120: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9121: $env{'request.course.sec'}.'</td>';
9122: } else {
9123: if (ref($sections_count) eq 'HASH') {
9124: my $currsec =
9125: &Apache::lonuserutils::course_sections($sections_count,
9126: $protectedcourse.'_'.$role);
9127: $row .= '<td><table class="LC_createuser">'."\n".
9128: '<tr class="LC_section_row">'."\n".
9129: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9130: $currsec.'</td>'."\n".
9131: ' <td> </td>'."\n".
9132: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
9133: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9134: '" value="" />'.
9135: '<input type="hidden" '.
9136: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
9137: '</tr></table></td>'."\n";
9138: } else {
9139: $row .= '<td><input type="text" size="10" '.
9140: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
9141: }
9142: }
9143: $row .= <<ENDTIMEENTRY;
9144: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
9145: <a href=
9146: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$role.value,'start_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'ssd'}</a></td>
9147: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
9148: <a href=
9149: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9150: ENDTIMEENTRY
9151: $row .= &Apache::loncommon::end_data_table_row();
9152: return $row;
9153: }
9154:
9155: sub course_level_dc {
9156: my ($dcdom,$showcredits) = @_;
9157: my %customroles=&Apache::lonuserutils::my_custom_roles();
9158: my @roles = &Apache::lonuserutils::roles_by_context('course');
9159: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9160: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
9161: '<input type="hidden" name="dccourse" value="" />';
9162: my $courseform=&Apache::loncommon::selectcourse_link
9163: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
9164: my $credit_elem;
9165: if ($showcredits) {
9166: $credit_elem = 'credits';
9167: }
9168: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
9169: my %lt=&Apache::lonlocal::texthash(
9170: 'rol' => "Role",
9171: 'grs' => "Section",
9172: 'exs' => "Existing sections",
9173: 'new' => "Define new section",
9174: 'sta' => "Start",
9175: 'end' => "End",
9176: 'ssd' => "Set Start Date",
9177: 'sed' => "Set End Date",
9178: 'scc' => "Course/Community",
9179: 'crd' => "Credits",
9180: );
9181: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
9182: &Apache::loncommon::start_data_table().
9183: &Apache::loncommon::start_data_table_header_row().
9184: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
9185: '<th>'.$lt{'grs'}.'</th>'."\n";
9186: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9187: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
9188: &Apache::loncommon::end_data_table_header_row();
9189: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
9190: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9191: $courseform.(' ' x4).'</span></td>'."\n".
9192: '<td valign="top"><br /><select name="role">'."\n";
9193: foreach my $role (@roles) {
9194: my $plrole=&Apache::lonnet::plaintext($role);
9195: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
9196: }
9197: if ( keys(%customroles) > 0) {
9198: foreach my $cust (sort(keys(%customroles))) {
9199: my $custrole='cr_cr_'.$env{'user.domain'}.
9200: '_'.$env{'user.name'}.'_'.$cust;
9201: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
9202: }
9203: }
9204: $otheritems .= '</select></td><td>'.
9205: '<table border="0" cellspacing="0" cellpadding="0">'.
9206: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
9207: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
9208: '<td> </td>'.
9209: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
9210: '<input type="text" name="newsec" value="" />'.
9211: '<input type="hidden" name="section" value="" />'.
9212: '<input type="hidden" name="groups" value="" />'.
9213: '<input type="hidden" name="crstype" value="" /></td>'.
9214: '</tr></table></td>'."\n";
9215: if ($showcredits) {
9216: $otheritems .= '<td><br />'."\n".
9217: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
9218: }
9219: $otheritems .= <<ENDTIMEENTRY;
9220: <td><br /><input type="hidden" name="start" value='' />
9221: <a href=
9222: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
9223: <td><br /><input type="hidden" name="end" value='' />
9224: <a href=
9225: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9226: ENDTIMEENTRY
9227: $otheritems .= &Apache::loncommon::end_data_table_row().
9228: &Apache::loncommon::end_data_table()."\n";
9229: return $cb_jscript.$header.$hiddenitems.$otheritems;
9230: }
9231:
9232: sub update_selfenroll_config {
9233: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
9234: return unless (ref($currsettings) eq 'HASH');
9235: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9236: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9237: my (%changes,%warning);
9238: my $curr_types;
9239: my %noedit;
9240: unless ($context eq 'domain') {
9241: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9242: }
9243: if (ref($row) eq 'ARRAY') {
9244: foreach my $item (@{$row}) {
9245: next if ($noedit{$item});
9246: if ($item eq 'enroll_dates') {
9247: my (%currenrolldate,%newenrolldate);
9248: foreach my $type ('start','end') {
9249: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
9250: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9251: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9252: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9253: }
9254: }
9255: } elsif ($item eq 'access_dates') {
9256: my (%currdate,%newdate);
9257: foreach my $type ('start','end') {
9258: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
9259: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9260: if ($newdate{$type} ne $currdate{$type}) {
9261: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9262: }
9263: }
9264: } elsif ($item eq 'types') {
9265: $curr_types = $currsettings->{'selfenroll_'.$item};
9266: if ($env{'form.selfenroll_all'}) {
9267: if ($curr_types ne '*') {
9268: $changes{'internal.selfenroll_types'} = '*';
9269: } else {
9270: next;
9271: }
9272: } else {
9273: my %currdoms;
9274: my @entries = split(/;/,$curr_types);
9275: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
9276: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
9277: my $newnum = 0;
9278: my @latesttypes;
9279: foreach my $num (@activations) {
9280: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9281: if (@types > 0) {
9282: @types = sort(@types);
9283: my $typestr = join(',',@types);
9284: my $typedom = $env{'form.selfenroll_dom_'.$num};
9285: $latesttypes[$newnum] = $typedom.':'.$typestr;
9286: $currdoms{$typedom} = 1;
9287: $newnum ++;
9288: }
9289: }
9290: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9291: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
9292: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9293: if (@types > 0) {
9294: @types = sort(@types);
9295: my $typestr = join(',',@types);
9296: my $typedom = $env{'form.selfenroll_dom_'.$j};
9297: $latesttypes[$newnum] = $typedom.':'.$typestr;
9298: $currdoms{$typedom} = 1;
9299: $newnum ++;
9300: }
9301: }
9302: }
9303: if ($env{'form.selfenroll_newdom'} ne '') {
9304: my $typedom = $env{'form.selfenroll_newdom'};
9305: if ((!defined($currdoms{$typedom})) &&
9306: (&Apache::lonnet::domain($typedom) ne '')) {
9307: my $typestr;
9308: my ($othertitle,$usertypes,$types) =
9309: &Apache::loncommon::sorted_inst_types($typedom);
9310: my $othervalue = 'any';
9311: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9312: if (@{$types} > 0) {
9313: my @esc_types = map { &escape($_); } @{$types};
9314: $othervalue = 'other';
9315: $typestr = join(',',(@esc_types,$othervalue));
9316: }
9317: $typestr = $othervalue;
9318: } else {
9319: $typestr = $othervalue;
9320: }
9321: $latesttypes[$newnum] = $typedom.':'.$typestr;
9322: $newnum ++ ;
9323: }
9324: }
9325: my $selfenroll_types = join(';',@latesttypes);
9326: if ($selfenroll_types ne $curr_types) {
9327: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9328: }
9329: }
9330: } elsif ($item eq 'limit') {
9331: my $newlimit = $env{'form.selfenroll_limit'};
9332: my $newcap = $env{'form.selfenroll_cap'};
9333: $newcap =~s/\s+//g;
9334: my $currlimit = $currsettings->{'selfenroll_limit'};
9335: $currlimit = 'none' if ($currlimit eq '');
9336: my $currcap = $currsettings->{'selfenroll_cap'};
9337: if ($newlimit ne $currlimit) {
9338: if ($newlimit ne 'none') {
9339: if ($newcap =~ /^\d+$/) {
9340: if ($newcap ne $currcap) {
9341: $changes{'internal.selfenroll_cap'} = $newcap;
9342: }
9343: $changes{'internal.selfenroll_limit'} = $newlimit;
9344: } else {
9345: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9346: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
9347: }
9348: } elsif ($currcap ne '') {
9349: $changes{'internal.selfenroll_cap'} = '';
9350: $changes{'internal.selfenroll_limit'} = $newlimit;
9351: }
9352: } elsif ($currlimit ne 'none') {
9353: if ($newcap =~ /^\d+$/) {
9354: if ($newcap ne $currcap) {
9355: $changes{'internal.selfenroll_cap'} = $newcap;
9356: }
9357: } else {
9358: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9359: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
9360: }
9361: }
9362: } elsif ($item eq 'approval') {
9363: my (@currnotified,@newnotified);
9364: my $currapproval = $currsettings->{'selfenroll_approval'};
9365: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
9366: if ($currnotifylist ne '') {
9367: @currnotified = split(/,/,$currnotifylist);
9368: @currnotified = sort(@currnotified);
9369: }
9370: my $newapproval = $env{'form.selfenroll_approval'};
9371: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9372: @newnotified = sort(@newnotified);
9373: if ($newapproval ne $currapproval) {
9374: $changes{'internal.selfenroll_approval'} = $newapproval;
9375: if (!$newapproval) {
9376: if ($currnotifylist ne '') {
9377: $changes{'internal.selfenroll_notifylist'} = '';
9378: }
9379: } else {
9380: my @differences =
9381: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
9382: if (@differences > 0) {
9383: if (@newnotified > 0) {
9384: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9385: } else {
9386: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9387: }
9388: }
9389: }
9390: } else {
9391: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
9392: if (@differences > 0) {
9393: if (@newnotified > 0) {
9394: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9395: } else {
9396: $changes{'internal.selfenroll_notifylist'} = '';
9397: }
9398: }
9399: }
9400: } else {
9401: my $curr_val = $currsettings->{'selfenroll_'.$item};
9402: my $newval = $env{'form.selfenroll_'.$item};
9403: if ($item eq 'section') {
9404: $newval = $env{'form.sections'};
9405: if (defined($curr_groups{$newval})) {
9406: $newval = $curr_val;
9407: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9408: &mt('Group names and section names must be distinct');
9409: } elsif ($newval eq 'all') {
9410: $newval = $curr_val;
9411: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
9412: }
9413: if ($newval eq '') {
9414: $newval = 'none';
9415: }
9416: }
9417: if ($newval ne $curr_val) {
9418: $changes{'internal.selfenroll_'.$item} = $newval;
9419: }
9420: }
9421: }
9422: if (keys(%warning) > 0) {
9423: foreach my $item (@{$row}) {
9424: if (exists($warning{$item})) {
9425: $r->print($warning{$item}.'<br />');
9426: }
9427: }
9428: }
9429: if (keys(%changes) > 0) {
9430: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9431: if ($putresult eq 'ok') {
9432: if ((exists($changes{'internal.selfenroll_types'})) ||
9433: (exists($changes{'internal.selfenroll_start_date'})) ||
9434: (exists($changes{'internal.selfenroll_end_date'}))) {
9435: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9436: $cnum,undef,undef,'Course');
9437: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
9438: if (ref($crsinfo{$cid}) eq 'HASH') {
9439: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9440: if (exists($changes{'internal.'.$item})) {
9441: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
9442: }
9443: }
9444: my $crsputresult =
9445: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9446: $chome,'notime');
9447: }
9448: }
9449: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9450: foreach my $item (@{$row}) {
9451: my $title = $item;
9452: if (ref($lt) eq 'HASH') {
9453: $title = $lt->{$item};
9454: }
9455: if ($item eq 'enroll_dates') {
9456: foreach my $type ('start','end') {
9457: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9458: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
9459: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
9460: $title,$type,$newdate).'</li>');
9461: }
9462: }
9463: } elsif ($item eq 'access_dates') {
9464: foreach my $type ('start','end') {
9465: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9466: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
9467: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
9468: $title,$type,$newdate).'</li>');
9469: }
9470: }
9471: } elsif ($item eq 'limit') {
9472: if ((exists($changes{'internal.selfenroll_limit'})) ||
9473: (exists($changes{'internal.selfenroll_cap'}))) {
9474: my ($newval,$newcap);
9475: if ($changes{'internal.selfenroll_cap'} ne '') {
9476: $newcap = $changes{'internal.selfenroll_cap'}
9477: } else {
9478: $newcap = $currsettings->{'selfenroll_cap'};
9479: }
9480: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9481: $newval = &mt('No limit');
9482: } elsif ($changes{'internal.selfenroll_limit'} eq
9483: 'allstudents') {
9484: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9485: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9486: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9487: } else {
9488: my $currlimit = $currsettings->{'selfenroll_limit'};
9489: if ($currlimit eq 'allstudents') {
9490: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9491: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9492: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9493: }
9494: }
9495: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9496: }
9497: } elsif ($item eq 'approval') {
9498: if ((exists($changes{'internal.selfenroll_approval'})) ||
9499: (exists($changes{'internal.selfenroll_notifylist'}))) {
9500: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
9501: my ($newval,$newnotify);
9502: if (exists($changes{'internal.selfenroll_notifylist'})) {
9503: $newnotify = $changes{'internal.selfenroll_notifylist'};
9504: } else {
9505: $newnotify = $currsettings->{'selfenroll_notifylist'};
9506: }
9507: if (exists($changes{'internal.selfenroll_approval'})) {
9508: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9509: $changes{'internal.selfenroll_approval'} = '0';
9510: }
9511: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
9512: } else {
9513: my $currapproval = $currsettings->{'selfenroll_approval'};
9514: if ($currapproval !~ /^[012]$/) {
9515: $currapproval = 0;
9516: }
9517: $newval = $selfdescs{'approval'}{$currapproval};
9518: }
9519: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9520: if ($newnotify) {
9521: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
9522: } else {
9523: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
9524: }
9525: $r->print('</li>'."\n");
9526: }
9527: } else {
9528: if (exists($changes{'internal.selfenroll_'.$item})) {
9529: my $newval = $changes{'internal.selfenroll_'.$item};
9530: if ($item eq 'types') {
9531: if ($newval eq '') {
9532: $newval = &mt('None');
9533: } elsif ($newval eq '*') {
9534: $newval = &mt('Any user in any domain');
9535: }
9536: } elsif ($item eq 'registered') {
9537: if ($newval eq '1') {
9538: $newval = &mt('Yes');
9539: } elsif ($newval eq '0') {
9540: $newval = &mt('No');
9541: }
9542: }
9543: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9544: }
9545: }
9546: }
9547: $r->print('</ul>');
9548: if ($env{'course.'.$cid.'.description'} ne '') {
9549: my %newenvhash;
9550: foreach my $key (keys(%changes)) {
9551: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9552: }
9553: &Apache::lonnet::appenv(\%newenvhash);
9554: }
9555: } else {
9556: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9557: &mt('The error was: [_1].',$putresult));
9558: }
9559: } else {
9560: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
9561: }
9562: } else {
9563: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
9564: }
9565: my $visactions = &cat_visibility();
9566: my ($cathash,%cattype);
9567: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9568: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9569: $cathash = $domconfig{'coursecategories'}{'cats'};
9570: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9571: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9572: } else {
9573: $cathash = {};
9574: $cattype{'auth'} = 'std';
9575: $cattype{'unauth'} = 'std';
9576: }
9577: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9578: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9579: '<br />'.
9580: '<br />'.$visactions->{'take'}.'<ul>'.
9581: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9582: '</ul>');
9583: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9584: if ($currsettings->{'uniquecode'}) {
9585: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9586: } else {
9587: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9588: '<br />'.
9589: '<br />'.$visactions->{'take'}.'<ul>'.
9590: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9591: '</ul><br />');
9592: }
9593: } else {
9594: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9595: if (ref($visactions) eq 'HASH') {
9596: if (!$visible) {
9597: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9598: '<br />');
9599: if (ref($vismsgs) eq 'ARRAY') {
9600: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9601: foreach my $item (@{$vismsgs}) {
9602: $r->print('<li>'.$visactions->{$item}.'</li>');
9603: }
9604: $r->print('</ul>');
9605: }
9606: $r->print($cansetvis);
9607: }
9608: }
9609: }
9610: return;
9611: }
9612:
9613: #---------------------------------------------- end functions for &phase_two
9614:
9615: #--------------------------------- functions for &phase_two and &phase_three
9616:
9617: #--------------------------end of functions for &phase_two and &phase_three
9618:
9619: 1;
9620: __END__
9621:
9622:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>