1: # The LearningOnline Network with CAPA
2: # Create a user
3: #
4: # $Id: loncreateuser.pm,v 1.406.2.10 2017/01/22 16:00:17 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30: package Apache::loncreateuser;
31:
32: =pod
33:
34: =head1 NAME
35:
36: Apache::loncreateuser.pm
37:
38: =head1 SYNOPSIS
39:
40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
59:
60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
62:
63: =cut
64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
68: use Apache::loncommon;
69: use Apache::lonlocal;
70: use Apache::longroup;
71: use Apache::lonuserutils;
72: use Apache::loncoursequeueadmin;
73: use LONCAPA qw(:DEFAULT :match);
74:
75: my $loginscript; # piece of javascript used in two separate instances
76: my $authformnop;
77: my $authformkrb;
78: my $authformint;
79: my $authformfsys;
80: my $authformloc;
81:
82: sub initialize_authen_forms {
83: my ($dom,$formname,$curr_authtype,$mode) = @_;
84: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
85: my %param = ( formname => $formname,
86: kerb_def_dom => $krbdefdom,
87: kerb_def_auth => $krbdef,
88: domain => $dom,
89: );
90: my %abv_auth = &auth_abbrev();
91: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
92: my $long_auth = $1;
93: my $curr_autharg = $2;
94: my %abv_auth = &auth_abbrev();
95: $param{'curr_authtype'} = $abv_auth{$long_auth};
96: if ($long_auth =~ /^krb(4|5)$/) {
97: $param{'curr_kerb_ver'} = $1;
98: $param{'curr_autharg'} = $curr_autharg;
99: }
100: if ($mode eq 'modifyuser') {
101: $param{'mode'} = $mode;
102: }
103: }
104: $loginscript = &Apache::loncommon::authform_header(%param);
105: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
106: $authformnop = &Apache::loncommon::authform_nochange(%param);
107: $authformint = &Apache::loncommon::authform_internal(%param);
108: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
109: $authformloc = &Apache::loncommon::authform_local(%param);
110: }
111:
112: sub auth_abbrev {
113: my %abv_auth = (
114: krb5 => 'krb',
115: krb4 => 'krb',
116: internal => 'int',
117: localauth => 'loc',
118: unix => 'fsys',
119: );
120: return %abv_auth;
121: }
122:
123: # ====================================================
124:
125: sub user_quotas {
126: my ($ccuname,$ccdomain) = @_;
127: my %lt = &Apache::lonlocal::texthash(
128: 'usrt' => "User Tools",
129: 'cust' => "Custom quota",
130: 'chqu' => "Change quota",
131: );
132:
133: my $quota_javascript = <<"END_SCRIPT";
134: <script type="text/javascript">
135: // <![CDATA[
136: function quota_changes(caller,context) {
137: var customoff = document.getElementById('custom_'+context+'quota_off');
138: var customon = document.getElementById('custom_'+context+'quota_on');
139: var number = document.getElementById(context+'quota');
140: if (caller == "custom") {
141: if (customoff) {
142: if (customoff.checked) {
143: number.value = "";
144: }
145: }
146: }
147: if (caller == "quota") {
148: if (customon) {
149: customon.checked = true;
150: }
151: }
152: return;
153: }
154: // ]]>
155: </script>
156: END_SCRIPT
157: my $longinsttype;
158: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
159: my $output = $quota_javascript."\n".
160: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
161: &Apache::loncommon::start_data_table();
162:
163: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
164: (&Apache::lonnet::allowed('udp',$ccdomain))) {
165: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
166: }
167:
168: my %titles = &Apache::lonlocal::texthash (
169: portfolio => "Disk space allocated to user's portfolio files",
170: author => "Disk space allocated to user's Authoring Space (if role assigned)",
171: );
172: foreach my $name ('portfolio','author') {
173: my ($currquota,$quotatype,$inststatus,$defquota) =
174: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
175: if ($longinsttype eq '') {
176: if ($inststatus ne '') {
177: if ($usertypes->{$inststatus} ne '') {
178: $longinsttype = $usertypes->{$inststatus};
179: }
180: }
181: }
182: my ($showquota,$custom_on,$custom_off,$defaultinfo);
183: $custom_on = ' ';
184: $custom_off = ' checked="checked" ';
185: if ($quotatype eq 'custom') {
186: $custom_on = $custom_off;
187: $custom_off = ' ';
188: $showquota = $currquota;
189: if ($longinsttype eq '') {
190: $defaultinfo = &mt('For this user, the default quota would be [_1]'
191: .' MB.',$defquota);
192: } else {
193: $defaultinfo = &mt("For this user, the default quota would be [_1]".
194: " MB, as determined by the user's institutional".
195: " affiliation ([_2]).",$defquota,$longinsttype);
196: }
197: } else {
198: if ($longinsttype eq '') {
199: $defaultinfo = &mt('For this user, the default quota is [_1]'
200: .' MB.',$defquota);
201: } else {
202: $defaultinfo = &mt("For this user, the default quota of [_1]".
203: " MB, is determined by the user's institutional".
204: " affiliation ([_2]).",$defquota,$longinsttype);
205: }
206: }
207:
208: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
209: $output .= '<tr class="LC_info_row">'."\n".
210: ' <td>'.$titles{$name}.'</td>'."\n".
211: ' </tr>'."\n".
212: &Apache::loncommon::start_data_table_row()."\n".
213: ' <td><span class="LC_nobreak">'.
214: &mt('Current quota: [_1] MB',$currquota).'</span> '.
215: $defaultinfo.'</td>'."\n".
216: &Apache::loncommon::end_data_table_row()."\n".
217: &Apache::loncommon::start_data_table_row()."\n".
218: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
219: ': <label>'.
220: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
221: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
222: ' /><span class="LC_nobreak">'.
223: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
224: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
225: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
226: ' />'.$lt{'cust'}.':</label> '.
227: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
228: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
229: ' /> '.&mt('MB').'</span></td>'."\n".
230: &Apache::loncommon::end_data_table_row()."\n";
231: }
232: }
233: $output .= &Apache::loncommon::end_data_table();
234: return $output;
235: }
236:
237: sub build_tools_display {
238: my ($ccuname,$ccdomain,$context) = @_;
239: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
240: $colspan,$isadv,%domconfig);
241: my %lt = &Apache::lonlocal::texthash (
242: 'blog' => "Personal User Blog",
243: 'aboutme' => "Personal Information Page",
244: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
245: 'portfolio' => "Personal User Portfolio",
246: 'avai' => "Available",
247: 'cusa' => "availability",
248: 'chse' => "Change setting",
249: 'usde' => "Use default",
250: 'uscu' => "Use custom",
251: 'official' => 'Can request creation of official courses',
252: 'unofficial' => 'Can request creation of unofficial courses',
253: 'community' => 'Can request creation of communities',
254: 'textbook' => 'Can request creation of textbook courses',
255: 'requestauthor' => 'Can request author space',
256: );
257: if ($context eq 'requestcourses') {
258: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
259: 'requestcourses.official','requestcourses.unofficial',
260: 'requestcourses.community','requestcourses.textbook');
261: @usertools = ('official','unofficial','community','textbook');
262: @options =('norequest','approval','autolimit','validate');
263: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
264: %reqtitles = &courserequest_titles();
265: %reqdisplay = &courserequest_display();
266: $colspan = ' colspan="2"';
267: %domconfig =
268: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
269: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
270: } elsif ($context eq 'requestauthor') {
271: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
272: 'requestauthor');
273: @usertools = ('requestauthor');
274: @options =('norequest','approval','automatic');
275: %reqtitles = &requestauthor_titles();
276: %reqdisplay = &requestauthor_display();
277: $colspan = ' colspan="2"';
278: %domconfig =
279: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
280: } else {
281: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
282: 'tools.aboutme','tools.portfolio','tools.blog',
283: 'tools.webdav');
284: @usertools = ('aboutme','blog','webdav','portfolio');
285: }
286: foreach my $item (@usertools) {
287: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
288: $currdisp,$custdisp,$custradio);
289: $cust_off = 'checked="checked" ';
290: $tool_on = 'checked="checked" ';
291: $curr_access =
292: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
293: $context);
294: if ($context eq 'requestauthor') {
295: if ($userenv{$context} ne '') {
296: $cust_on = ' checked="checked" ';
297: $cust_off = '';
298: }
299: } elsif ($userenv{$context.'.'.$item} ne '') {
300: $cust_on = ' checked="checked" ';
301: $cust_off = '';
302: }
303: if ($context eq 'requestcourses') {
304: if ($userenv{$context.'.'.$item} eq '') {
305: $custom_access = &mt('Currently from default setting.');
306: } else {
307: $custom_access = &mt('Currently from custom setting.');
308: }
309: } elsif ($context eq 'requestauthor') {
310: if ($userenv{$context} eq '') {
311: $custom_access = &mt('Currently from default setting.');
312: } else {
313: $custom_access = &mt('Currently from custom setting.');
314: }
315: } else {
316: if ($userenv{$context.'.'.$item} eq '') {
317: $custom_access =
318: &mt('Availability determined currently from default setting.');
319: if (!$curr_access) {
320: $tool_off = 'checked="checked" ';
321: $tool_on = '';
322: }
323: } else {
324: $custom_access =
325: &mt('Availability determined currently from custom setting.');
326: if ($userenv{$context.'.'.$item} == 0) {
327: $tool_off = 'checked="checked" ';
328: $tool_on = '';
329: }
330: }
331: }
332: $output .= ' <tr class="LC_info_row">'."\n".
333: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
334: ' </tr>'."\n".
335: &Apache::loncommon::start_data_table_row()."\n";
336: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
337: my ($curroption,$currlimit);
338: my $envkey = $context.'.'.$item;
339: if ($context eq 'requestauthor') {
340: $envkey = $context;
341: }
342: if ($userenv{$envkey} ne '') {
343: $curroption = $userenv{$envkey};
344: } else {
345: my (@inststatuses);
346: if ($context eq 'requestcourses') {
347: $curroption =
348: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
349: $isadv,$ccdomain,$item,
350: \@inststatuses,\%domconfig);
351: } else {
352: $curroption =
353: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
354: $isadv,$ccdomain,undef,
355: \@inststatuses,\%domconfig);
356: }
357: }
358: if (!$curroption) {
359: $curroption = 'norequest';
360: }
361: if ($curroption =~ /^autolimit=(\d*)$/) {
362: $currlimit = $1;
363: if ($currlimit eq '') {
364: $currdisp = &mt('Yes, automatic creation');
365: } else {
366: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
367: }
368: } else {
369: $currdisp = $reqdisplay{$curroption};
370: }
371: $custdisp = '<table>';
372: foreach my $option (@options) {
373: my $val = $option;
374: if ($option eq 'norequest') {
375: $val = 0;
376: }
377: if ($option eq 'validate') {
378: my $canvalidate = 0;
379: if (ref($validations{$item}) eq 'HASH') {
380: if ($validations{$item}{'_custom_'}) {
381: $canvalidate = 1;
382: }
383: }
384: next if (!$canvalidate);
385: }
386: my $checked = '';
387: if ($option eq $curroption) {
388: $checked = ' checked="checked"';
389: } elsif ($option eq 'autolimit') {
390: if ($curroption =~ /^autolimit/) {
391: $checked = ' checked="checked"';
392: }
393: }
394: my $name = 'crsreq_'.$item;
395: if ($context eq 'requestauthor') {
396: $name = $item;
397: }
398: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
399: '<input type="radio" name="'.$name.'" '.
400: 'value="'.$val.'"'.$checked.' />'.
401: $reqtitles{$option}.'</label> ';
402: if ($option eq 'autolimit') {
403: $custdisp .= '<input type="text" name="'.$name.
404: '_limit" size="1" '.
405: 'value="'.$currlimit.'" /></span><br />'.
406: $reqtitles{'unlimited'};
407: } else {
408: $custdisp .= '</span>';
409: }
410: $custdisp .= '</td></tr>';
411: }
412: $custdisp .= '</table>';
413: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
414: } else {
415: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
416: my $name = $context.'_'.$item;
417: if ($context eq 'requestauthor') {
418: $name = $context;
419: }
420: $custdisp = '<span class="LC_nobreak"><label>'.
421: '<input type="radio" name="'.$name.'"'.
422: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
423: '<input type="radio" name="'.$name.'" value="0" '.
424: $tool_off.'/>'.&mt('Off').'</label></span>';
425: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
426: '</span>';
427: }
428: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
429: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
430: &Apache::loncommon::end_data_table_row()."\n";
431: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
432: $output .=
433: &Apache::loncommon::start_data_table_row()."\n".
434: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
435: $lt{'chse'}.': <label>'.
436: '<input type="radio" name="custom'.$item.'" value="0" '.
437: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
438: '<label><input type="radio" name="custom'.$item.'" value="1" '.
439: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
440: &Apache::loncommon::end_data_table_row()."\n";
441: }
442: }
443: return $output;
444: }
445:
446: sub coursereq_externaluser {
447: my ($ccuname,$ccdomain,$cdom) = @_;
448: my (@usertools,@options,%validations,%userenv,$output);
449: my %lt = &Apache::lonlocal::texthash (
450: 'official' => 'Can request creation of official courses',
451: 'unofficial' => 'Can request creation of unofficial courses',
452: 'community' => 'Can request creation of communities',
453: 'textbook' => 'Can request creation of textbook courses',
454: );
455:
456: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
457: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
458: 'reqcrsotherdom.community','reqcrsotherdom.textbook');
459: @usertools = ('official','unofficial','community','textbook');
460: @options = ('approval','validate','autolimit');
461: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
462: my $optregex = join('|',@options);
463: my %reqtitles = &courserequest_titles();
464: foreach my $item (@usertools) {
465: my ($curroption,$currlimit,$tooloff);
466: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
467: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
468: foreach my $req (@curr) {
469: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
470: $curroption = $1;
471: $currlimit = $2;
472: last;
473: }
474: }
475: if (!$curroption) {
476: $curroption = 'norequest';
477: $tooloff = ' checked="checked"';
478: }
479: } else {
480: $curroption = 'norequest';
481: $tooloff = ' checked="checked"';
482: }
483: $output.= &Apache::loncommon::start_data_table_row()."\n".
484: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
485: '<table><tr><td valign="top">'."\n".
486: '<label><input type="radio" name="reqcrsotherdom_'.$item.
487: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
488: '</label></td>';
489: foreach my $option (@options) {
490: if ($option eq 'validate') {
491: my $canvalidate = 0;
492: if (ref($validations{$item}) eq 'HASH') {
493: if ($validations{$item}{'_external_'}) {
494: $canvalidate = 1;
495: }
496: }
497: next if (!$canvalidate);
498: }
499: my $checked = '';
500: if ($option eq $curroption) {
501: $checked = ' checked="checked"';
502: }
503: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
504: '<input type="radio" name="reqcrsotherdom_'.$item.
505: '" value="'.$option.'"'.$checked.' />'.
506: $reqtitles{$option}.'</label>';
507: if ($option eq 'autolimit') {
508: $output .= ' <input type="text" name="reqcrsotherdom_'.
509: $item.'_limit" size="1" '.
510: 'value="'.$currlimit.'" /></span>'.
511: '<br />'.$reqtitles{'unlimited'};
512: } else {
513: $output .= '</span>';
514: }
515: $output .= '</td>';
516: }
517: $output .= '</td></tr></table></td>'."\n".
518: &Apache::loncommon::end_data_table_row()."\n";
519: }
520: return $output;
521: }
522:
523: sub domainrole_req {
524: my ($ccuname,$ccdomain) = @_;
525: return '<br /><h3>'.
526: &mt('User Can Request Assignment of Domain Roles?').
527: '</h3>'."\n".
528: &Apache::loncommon::start_data_table().
529: &build_tools_display($ccuname,$ccdomain,
530: 'requestauthor').
531: &Apache::loncommon::end_data_table();
532: }
533:
534: sub courserequest_titles {
535: my %titles = &Apache::lonlocal::texthash (
536: official => 'Official',
537: unofficial => 'Unofficial',
538: community => 'Communities',
539: textbook => 'Textbook',
540: norequest => 'Not allowed',
541: approval => 'Approval by Dom. Coord.',
542: validate => 'With validation',
543: autolimit => 'Numerical limit',
544: unlimited => '(blank for unlimited)',
545: );
546: return %titles;
547: }
548:
549: sub courserequest_display {
550: my %titles = &Apache::lonlocal::texthash (
551: approval => 'Yes, need approval',
552: validate => 'Yes, with validation',
553: norequest => 'No',
554: );
555: return %titles;
556: }
557:
558: sub requestauthor_titles {
559: my %titles = &Apache::lonlocal::texthash (
560: norequest => 'Not allowed',
561: approval => 'Approval by Dom. Coord.',
562: automatic => 'Automatic approval',
563: );
564: return %titles;
565:
566: }
567:
568: sub requestauthor_display {
569: my %titles = &Apache::lonlocal::texthash (
570: approval => 'Yes, need approval',
571: automatic => 'Yes, automatic approval',
572: norequest => 'No',
573: );
574: return %titles;
575: }
576:
577: sub requestchange_display {
578: my %titles = &Apache::lonlocal::texthash (
579: approval => "availability set to 'on' (approval required)",
580: automatic => "availability set to 'on' (automatic approval)",
581: norequest => "availability set to 'off'",
582: );
583: return %titles;
584: }
585:
586: sub curr_requestauthor {
587: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
588: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
589: if ($uname eq '' || $udom eq '') {
590: $uname = $env{'user.name'};
591: $udom = $env{'user.domain'};
592: $isadv = $env{'user.adv'};
593: }
594: my (%userenv,%settings,$val);
595: my @options = ('automatic','approval');
596: %userenv =
597: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
598: if ($userenv{'requestauthor'}) {
599: $val = $userenv{'requestauthor'};
600: @{$inststatuses} = ('_custom_');
601: } else {
602: my %alltasks;
603: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
604: %settings = %{$domconfig->{'requestauthor'}};
605: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
606: $val = $settings{'_LC_adv'};
607: @{$inststatuses} = ('_LC_adv_');
608: } else {
609: if ($userenv{'inststatus'} ne '') {
610: @{$inststatuses} = split(',',$userenv{'inststatus'});
611: } else {
612: @{$inststatuses} = ('default');
613: }
614: foreach my $status (@{$inststatuses}) {
615: if (exists($settings{$status})) {
616: my $value = $settings{$status};
617: next unless ($value);
618: unless (exists($alltasks{$value})) {
619: if (ref($alltasks{$value}) eq 'ARRAY') {
620: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
621: push(@{$alltasks{$value}},$status);
622: }
623: } else {
624: @{$alltasks{$value}} = ($status);
625: }
626: }
627: }
628: }
629: foreach my $option (@options) {
630: if ($alltasks{$option}) {
631: $val = $option;
632: last;
633: }
634: }
635: }
636: }
637: }
638: return $val;
639: }
640:
641: # =================================================================== Phase one
642:
643: sub print_username_entry_form {
644: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum) = @_;
645: my $defdom=$env{'request.role.domain'};
646: my $formtoset = 'crtuser';
647: if (exists($env{'form.startrolename'})) {
648: $formtoset = 'docustom';
649: $env{'form.rolename'} = $env{'form.startrolename'};
650: } elsif ($env{'form.origform'} eq 'crtusername') {
651: $formtoset = $env{'form.origform'};
652: }
653:
654: my ($jsback,$elements) = &crumb_utilities();
655:
656: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
657: '<script type="text/javascript">'."\n".
658: '// <![CDATA['."\n".
659: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
660: '// ]]>'."\n".
661: '</script>'."\n";
662:
663: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
664: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
665: && (&Apache::lonnet::allowed('mcr','/'))) {
666: $jscript .= &customrole_javascript();
667: }
668: my $helpitem = 'Course_Change_Privileges';
669: if ($env{'form.action'} eq 'custom') {
670: $helpitem = 'Course_Editing_Custom_Roles';
671: } elsif ($env{'form.action'} eq 'singlestudent') {
672: $helpitem = 'Course_Add_Student';
673: } elsif ($env{'form.action'} eq 'accesslogs') {
674: $helpitem = 'Domain_User_Access_Logs';
675: }
676: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
677: if ($env{'form.action'} eq 'custom') {
678: push(@{$brcrum},
679: {href=>"javascript:backPage(document.crtuser)",
680: text=>"Pick custom role",
681: help => $helpitem,}
682: );
683: } else {
684: push (@{$brcrum},
685: {href => "javascript:backPage(document.crtuser)",
686: text => $breadcrumb_text{'search'},
687: help => $helpitem,
688: faq => 282,
689: bug => 'Instructor Interface',}
690: );
691: }
692: my %loaditems = (
693: 'onload' => "javascript:setFormElements(document.$formtoset)",
694: );
695: my $args = {bread_crumbs => $brcrum,
696: bread_crumbs_component => 'User Management',
697: add_entries => \%loaditems,};
698: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
699:
700: my %lt=&Apache::lonlocal::texthash(
701: 'srst' => 'Search for a user and enroll as a student',
702: 'srme' => 'Search for a user and enroll as a member',
703: 'srad' => 'Search for a user and modify/add user information or roles',
704: 'srvu' => 'Search for a user and view user information and roles',
705: 'srva' => 'Search for a user and view access log information',
706: 'usr' => "Username",
707: 'dom' => "Domain",
708: 'ecrp' => "Define or Edit Custom Role",
709: 'nr' => "role name",
710: 'cre' => "Next",
711: );
712:
713: if ($env{'form.action'} eq 'custom') {
714: if (&Apache::lonnet::allowed('mcr','/')) {
715: my $newroletext = &mt('Define new custom role:');
716: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
717: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
718: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
719: '<h3>'.$lt{'ecrp'}.'</h3>'.
720: &Apache::loncommon::start_data_table().
721: &Apache::loncommon::start_data_table_row().
722: '<td>');
723: if (keys(%existingroles) > 0) {
724: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
725: } else {
726: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
727: }
728: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
729: &Apache::loncommon::end_data_table_row());
730: if (keys(%existingroles) > 0) {
731: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
732: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
733: &mt('View/Modify existing role:').'</b></label></td>'.
734: '<td align="center"><br />'.
735: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
736: '<option value="" selected="selected">'.
737: &mt('Select'));
738: foreach my $role (sort(keys(%existingroles))) {
739: $r->print('<option value="'.$role.'">'.$role.'</option>');
740: }
741: $r->print('</select>'.
742: '</td>'.
743: &Apache::loncommon::end_data_table_row());
744: }
745: $r->print(&Apache::loncommon::end_data_table().'<p>'.
746: '<input name="customeditor" type="submit" value="'.
747: $lt{'cre'}.'" /></p>'.
748: '</form>');
749: }
750: } else {
751: my $actiontext = $lt{'srad'};
752: if ($env{'form.action'} eq 'singlestudent') {
753: if ($crstype eq 'Community') {
754: $actiontext = $lt{'srme'};
755: } else {
756: $actiontext = $lt{'srst'};
757: }
758: } elsif ($env{'form.action'} eq 'accesslogs') {
759: $actiontext = $lt{'srva'};
760: } elsif (($env{'form.action'} eq 'singleuser') &&
761: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
762: $actiontext = $lt{'srvu'};
763: }
764: $r->print("<h3>$actiontext</h3>");
765: if ($env{'form.origform'} ne 'crtusername') {
766: if ($response) {
767: $r->print("\n<div>$response</div>".
768: '<br clear="all" />');
769: }
770: }
771: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,1));
772: }
773: }
774:
775: sub customrole_javascript {
776: my $js = <<"END";
777: <script type="text/javascript">
778: // <![CDATA[
779:
780: function setCustomFields() {
781: if (document.docustom.customroleaction.length > 0) {
782: for (var i=0; i<document.docustom.customroleaction.length; i++) {
783: if (document.docustom.customroleaction[i].checked) {
784: if (document.docustom.customroleaction[i].value == 'new') {
785: document.docustom.rolename.selectedIndex = 0;
786: } else {
787: document.docustom.newrolename.value = '';
788: }
789: }
790: }
791: }
792: return;
793: }
794:
795: function setCustomAction(caller) {
796: if (document.docustom.customroleaction.length > 0) {
797: for (var i=0; i<document.docustom.customroleaction.length; i++) {
798: if (document.docustom.customroleaction[i].value == caller) {
799: document.docustom.customroleaction[i].checked = true;
800: }
801: }
802: }
803: setCustomFields();
804: return;
805: }
806:
807: // ]]>
808: </script>
809: END
810: return $js;
811: }
812:
813: sub entry_form {
814: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
815: my ($usertype,$inexact);
816: if (ref($srch) eq 'HASH') {
817: if (($srch->{'srchin'} eq 'dom') &&
818: ($srch->{'srchby'} eq 'uname') &&
819: ($srch->{'srchtype'} eq 'exact') &&
820: ($srch->{'srchdomain'} ne '') &&
821: ($srch->{'srchterm'} ne '')) {
822: my (%curr_rules,%got_rules);
823: my ($rules,$ruleorder) =
824: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
825: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
826: } else {
827: $inexact = 1;
828: }
829: }
830: my $cancreate =
831: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
832: my ($userpicker,$cansearch) =
833: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
834: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom);
835: my $srchbutton = &mt('Search');
836: if ($env{'form.action'} eq 'singlestudent') {
837: $srchbutton = &mt('Search and Enroll');
838: } elsif ($env{'form.action'} eq 'accesslogs') {
839: $srchbutton = &mt('Search');
840: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
841: $srchbutton = &mt('Search or Add New User');
842: }
843: my $output;
844: if ($cansearch) {
845: $output = <<"ENDBLOCK";
846: <form action="/adm/createuser" method="post" name="crtuser">
847: <input type="hidden" name="action" value="$env{'form.action'}" />
848: <input type="hidden" name="phase" value="get_user_info" />
849: $userpicker
850: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
851: </form>
852: ENDBLOCK
853: } else {
854: $output = '<p>'.$userpicker.'</p>';
855: }
856: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
857: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
858: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
859: my $defdom=$env{'request.role.domain'};
860: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
861: my %lt=&Apache::lonlocal::texthash(
862: 'enro' => 'Enroll one student',
863: 'enrm' => 'Enroll one member',
864: 'admo' => 'Add/modify a single user',
865: 'crea' => 'create new user if required',
866: 'uskn' => "username is known",
867: 'crnu' => 'Create a new user',
868: 'usr' => 'Username',
869: 'dom' => 'in domain',
870: 'enrl' => 'Enroll',
871: 'cram' => 'Create/Modify user',
872: );
873: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
874: my ($title,$buttontext,$showresponse);
875: if ($env{'form.action'} eq 'singlestudent') {
876: if ($crstype eq 'Community') {
877: $title = $lt{'enrm'};
878: } else {
879: $title = $lt{'enro'};
880: }
881: $buttontext = $lt{'enrl'};
882: } else {
883: $title = $lt{'admo'};
884: $buttontext = $lt{'cram'};
885: }
886: if ($cancreate) {
887: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
888: } else {
889: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
890: }
891: if ($env{'form.origform'} eq 'crtusername') {
892: $showresponse = $responsemsg;
893: }
894: $output .= <<"ENDDOCUMENT";
895: <br />
896: <form action="/adm/createuser" method="post" name="crtusername">
897: <input type="hidden" name="action" value="$env{'form.action'}" />
898: <input type="hidden" name="phase" value="createnewuser" />
899: <input type="hidden" name="srchtype" value="exact" />
900: <input type="hidden" name="srchby" value="uname" />
901: <input type="hidden" name="srchin" value="dom" />
902: <input type="hidden" name="forcenewuser" value="1" />
903: <input type="hidden" name="origform" value="crtusername" />
904: <h3>$title</h3>
905: $showresponse
906: <table>
907: <tr>
908: <td>$lt{'usr'}:</td>
909: <td><input type="text" size="15" name="srchterm" /></td>
910: <td> $lt{'dom'}:</td><td>$domform</td>
911: <td> $sellink </td>
912: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
913: </tr>
914: </table>
915: </form>
916: ENDDOCUMENT
917: }
918: return $output;
919: }
920:
921: sub user_modification_js {
922: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
923:
924: return <<END;
925: <script type="text/javascript" language="Javascript">
926: // <![CDATA[
927:
928: $pjump_def
929: $dc_setcourse_code
930:
931: function dateset() {
932: eval("document.cu."+document.cu.pres_marker.value+
933: ".value=document.cu.pres_value.value");
934: modalWindow.close();
935: }
936:
937: $nondc_setsection_code
938: // ]]>
939: </script>
940: END
941: }
942:
943: # =================================================================== Phase two
944: sub print_user_selection_page {
945: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
946: my @fields = ('username','domain','lastname','firstname','permanentemail');
947: my $sortby = $env{'form.sortby'};
948:
949: if (!grep(/^\Q$sortby\E$/,@fields)) {
950: $sortby = 'lastname';
951: }
952:
953: my ($jsback,$elements) = &crumb_utilities();
954:
955: my $jscript = (<<ENDSCRIPT);
956: <script type="text/javascript">
957: // <![CDATA[
958: function pickuser(uname,udom) {
959: document.usersrchform.seluname.value=uname;
960: document.usersrchform.seludom.value=udom;
961: document.usersrchform.phase.value="userpicked";
962: document.usersrchform.submit();
963: }
964:
965: $jsback
966: // ]]>
967: </script>
968: ENDSCRIPT
969:
970: my %lt=&Apache::lonlocal::texthash(
971: 'usrch' => "User Search to add/modify roles",
972: 'stusrch' => "User Search to enroll student",
973: 'memsrch' => "User Search to enroll member",
974: 'srcva' => "Search for a user and view access log information",
975: 'usrvu' => "User Search to view user roles",
976: 'usel' => "Select a user to add/modify roles",
977: 'suvr' => "Select a user to view roles",
978: 'stusel' => "Select a user to enroll as a student",
979: 'memsel' => "Select a user to enroll as a member",
980: 'vacsel' => "Select a user to view access log",
981: 'username' => "username",
982: 'domain' => "domain",
983: 'lastname' => "last name",
984: 'firstname' => "first name",
985: 'permanentemail' => "permanent e-mail",
986: );
987: if ($context eq 'requestcrs') {
988: $r->print('<div>');
989: } else {
990: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
991: my $helpitem;
992: if ($env{'form.action'} eq 'singleuser') {
993: $helpitem = 'Course_Change_Privileges';
994: } elsif ($env{'form.action'} eq 'singlestudent') {
995: $helpitem = 'Course_Add_Student';
996: }
997: push (@{$brcrum},
998: {href => "javascript:backPage(document.usersrchform,'','')",
999: text => $breadcrumb_text{'search'},
1000: faq => 282,
1001: bug => 'Instructor Interface',},
1002: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1003: text => $breadcrumb_text{'userpicked'},
1004: faq => 282,
1005: bug => 'Instructor Interface',
1006: help => $helpitem}
1007: );
1008: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1009: if ($env{'form.action'} eq 'singleuser') {
1010: my $readonly;
1011: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1012: $readonly = 1;
1013: $r->print("<b>$lt{'usrvu'}</b><br />");
1014: } else {
1015: $r->print("<b>$lt{'usrch'}</b><br />");
1016: }
1017: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1018: if ($readonly) {
1019: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1020: } else {
1021: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1022: }
1023: } elsif ($env{'form.action'} eq 'singlestudent') {
1024: $r->print($jscript."<b>");
1025: if ($crstype eq 'Community') {
1026: $r->print($lt{'memsrch'});
1027: } else {
1028: $r->print($lt{'stusrch'});
1029: }
1030: $r->print("</b><br />");
1031: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1032: $r->print('</form><h3>');
1033: if ($crstype eq 'Community') {
1034: $r->print($lt{'memsel'});
1035: } else {
1036: $r->print($lt{'stusel'});
1037: }
1038: $r->print('</h3>');
1039: } elsif ($env{'form.action'} eq 'accesslogs') {
1040: $r->print("<b>$lt{'srcva'}</b><br />");
1041: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,'accesslogs',undef,undef,1));
1042: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1043: }
1044: }
1045: $r->print('<form name="usersrchform" method="post" action="">'.
1046: &Apache::loncommon::start_data_table()."\n".
1047: &Apache::loncommon::start_data_table_header_row()."\n".
1048: ' <th> </th>'."\n");
1049: foreach my $field (@fields) {
1050: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1051: "'".$field."'".';document.usersrchform.submit();">'.
1052: $lt{$field}.'</a></th>'."\n");
1053: }
1054: $r->print(&Apache::loncommon::end_data_table_header_row());
1055:
1056: my @sorted_users = sort {
1057: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1058: ||
1059: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1060: ||
1061: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1062: ||
1063: lc($a) cmp lc($b)
1064: } (keys(%$srch_results));
1065:
1066: foreach my $user (@sorted_users) {
1067: my ($uname,$udom) = split(/:/,$user);
1068: my $onclick;
1069: if ($context eq 'requestcrs') {
1070: $onclick =
1071: 'onclick="javascript:gochoose('."'$uname','$udom',".
1072: "'$srch_results->{$user}->{firstname}',".
1073: "'$srch_results->{$user}->{lastname}',".
1074: "'$srch_results->{$user}->{permanentemail}'".');"';
1075: } else {
1076: $onclick =
1077: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1078: }
1079: $r->print(&Apache::loncommon::start_data_table_row().
1080: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1081: $onclick.' /></td>'.
1082: '<td><tt>'.$uname.'</tt></td>'.
1083: '<td><tt>'.$udom.'</tt></td>');
1084: foreach my $field ('lastname','firstname','permanentemail') {
1085: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1086: }
1087: $r->print(&Apache::loncommon::end_data_table_row());
1088: }
1089: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1090: if (ref($srcharray) eq 'ARRAY') {
1091: foreach my $item (@{$srcharray}) {
1092: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1093: }
1094: }
1095: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1096: ' <input type="hidden" name="seluname" value="" />'."\n".
1097: ' <input type="hidden" name="seludom" value="" />'."\n".
1098: ' <input type="hidden" name="currstate" value="select" />'."\n".
1099: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1100: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1101: if ($context eq 'requestcrs') {
1102: $r->print($opener_elements.'</form></div>');
1103: } else {
1104: $r->print($response.'</form>');
1105: }
1106: }
1107:
1108: sub print_user_query_page {
1109: my ($r,$caller,$brcrum) = @_;
1110: # FIXME - this is for a network-wide name search (similar to catalog search)
1111: # To use frames with similar behavior to catalog/portfolio search.
1112: # To be implemented.
1113: return;
1114: }
1115:
1116: sub print_user_modification_page {
1117: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1118: $brcrum,$showcredits) = @_;
1119: if (($ccuname eq '') || ($ccdomain eq '')) {
1120: my $usermsg = &mt('No username and/or domain provided.');
1121: $env{'form.phase'} = '';
1122: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum);
1123: return;
1124: }
1125: my ($form,$formname);
1126: if ($env{'form.action'} eq 'singlestudent') {
1127: $form = 'document.enrollstudent';
1128: $formname = 'enrollstudent';
1129: } else {
1130: $form = 'document.cu';
1131: $formname = 'cu';
1132: }
1133: my %abv_auth = &auth_abbrev();
1134: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1135: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1136: if ($uhome eq 'no_host') {
1137: my $usertype;
1138: my ($rules,$ruleorder) =
1139: &Apache::lonnet::inst_userrules($ccdomain,'username');
1140: $usertype =
1141: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1142: \%curr_rules,\%got_rules);
1143: my $cancreate =
1144: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1145: $usertype);
1146: if (!$cancreate) {
1147: my $helplink = 'javascript:helpMenu('."'display'".')';
1148: my %usertypetext = (
1149: official => 'institutional',
1150: unofficial => 'non-institutional',
1151: );
1152: my $response;
1153: if ($env{'form.origform'} eq 'crtusername') {
1154: $response = '<span class="LC_warning">'.
1155: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1156: '<b>'.$ccuname.'</b>',$ccdomain).
1157: '</span><br />';
1158: }
1159: $response .= '<p class="LC_warning">'
1160: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1161: .' ';
1162: if ($context eq 'domain') {
1163: $response .= &mt('Please contact a [_1] for assistance.',
1164: &Apache::lonnet::plaintext('dc'));
1165: } else {
1166: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1167: ,'<a href="'.$helplink.'">','</a>');
1168: }
1169: $response .= '</p><br />';
1170: $env{'form.phase'} = '';
1171: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum);
1172: return;
1173: }
1174: $newuser = 1;
1175: my $checkhash;
1176: my $checks = { 'username' => 1 };
1177: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1178: &Apache::loncommon::user_rule_check($checkhash,$checks,
1179: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1180: if (ref($alerts{'username'}) eq 'HASH') {
1181: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1182: my $domdesc =
1183: &Apache::lonnet::domain($ccdomain,'description');
1184: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1185: my $userchkmsg;
1186: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1187: $userchkmsg =
1188: &Apache::loncommon::instrule_disallow_msg('username',
1189: $domdesc,1).
1190: &Apache::loncommon::user_rule_formats($ccdomain,
1191: $domdesc,$curr_rules{$ccdomain}{'username'},
1192: 'username');
1193: }
1194: $env{'form.phase'} = '';
1195: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum);
1196: return;
1197: }
1198: }
1199: }
1200: } else {
1201: $newuser = 0;
1202: }
1203: if ($response) {
1204: $response = '<br />'.$response;
1205: }
1206:
1207: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1208: my $dc_setcourse_code = '';
1209: my $nondc_setsection_code = '';
1210: my %loaditem;
1211:
1212: my $groupslist = &Apache::lonuserutils::get_groupslist();
1213:
1214: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1215: $groupslist,$newuser,$formname,\%loaditem);
1216: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1217: my $helpitem = 'Course_Change_Privileges';
1218: if ($env{'form.action'} eq 'singlestudent') {
1219: $helpitem = 'Course_Add_Student';
1220: }
1221: push (@{$brcrum},
1222: {href => "javascript:backPage($form)",
1223: text => $breadcrumb_text{'search'},
1224: faq => 282,
1225: bug => 'Instructor Interface',});
1226: if ($env{'form.phase'} eq 'userpicked') {
1227: push(@{$brcrum},
1228: {href => "javascript:backPage($form,'get_user_info','select')",
1229: text => $breadcrumb_text{'userpicked'},
1230: faq => 282,
1231: bug => 'Instructor Interface',});
1232: }
1233: push(@{$brcrum},
1234: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1235: text => $breadcrumb_text{'modify'},
1236: faq => 282,
1237: bug => 'Instructor Interface',
1238: help => $helpitem});
1239: my $args = {'add_entries' => \%loaditem,
1240: 'bread_crumbs' => $brcrum,
1241: 'bread_crumbs_component' => 'User Management'};
1242: if ($env{'form.popup'}) {
1243: $args->{'no_nav_bar'} = 1;
1244: }
1245: my $start_page =
1246: &Apache::loncommon::start_page('User Management',$js,$args);
1247:
1248: my $forminfo =<<"ENDFORMINFO";
1249: <form action="/adm/createuser" method="post" name="$formname">
1250: <input type="hidden" name="phase" value="update_user_data" />
1251: <input type="hidden" name="ccuname" value="$ccuname" />
1252: <input type="hidden" name="ccdomain" value="$ccdomain" />
1253: <input type="hidden" name="pres_value" value="" />
1254: <input type="hidden" name="pres_type" value="" />
1255: <input type="hidden" name="pres_marker" value="" />
1256: ENDFORMINFO
1257: my (%inccourses,$roledom,$defaultcredits);
1258: if ($context eq 'course') {
1259: $inccourses{$env{'request.course.id'}}=1;
1260: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1261: if ($showcredits) {
1262: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1263: }
1264: } elsif ($context eq 'author') {
1265: $roledom = $env{'request.role.domain'};
1266: } elsif ($context eq 'domain') {
1267: foreach my $key (keys(%env)) {
1268: $roledom = $env{'request.role.domain'};
1269: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1270: $inccourses{$1.'_'.$2}=1;
1271: }
1272: }
1273: } else {
1274: foreach my $key (keys(%env)) {
1275: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1276: $inccourses{$1.'_'.$2}=1;
1277: }
1278: }
1279: }
1280: my $title = '';
1281: if ($newuser) {
1282: my ($portfolioform,$domroleform);
1283: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1284: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1285: # Current user has quota or user tools modification privileges
1286: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1287: }
1288: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1289: ($ccdomain eq $env{'request.role.domain'})) {
1290: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1291: }
1292: &initialize_authen_forms($ccdomain,$formname);
1293: my %lt=&Apache::lonlocal::texthash(
1294: 'lg' => 'Login Data',
1295: 'hs' => "Home Server",
1296: );
1297: $r->print(<<ENDTITLE);
1298: $start_page
1299: $response
1300: $forminfo
1301: <script type="text/javascript" language="Javascript">
1302: // <![CDATA[
1303: $loginscript
1304: // ]]>
1305: </script>
1306: <input type='hidden' name='makeuser' value='1' />
1307: ENDTITLE
1308: if ($env{'form.action'} eq 'singlestudent') {
1309: if ($crstype eq 'Community') {
1310: $title = &mt('Create New User [_1] in domain [_2] as a member',
1311: '"'.$ccuname.'"','"'.$ccdomain.'"');
1312: } else {
1313: $title = &mt('Create New User [_1] in domain [_2] as a student',
1314: '"'.$ccuname.'"','"'.$ccdomain.'"');
1315: }
1316: } else {
1317: $title = &mt('Create New User [_1] in domain [_2]',
1318: '"'.$ccuname.'"','"'.$ccdomain.'"');
1319: }
1320: $r->print('<h2>'.$title.'</h2>'."\n");
1321: $r->print('<div class="LC_left_float">');
1322: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1323: $inst_results{$ccuname.':'.$ccdomain}));
1324: # Option to disable student/employee ID conflict checking not offerred for new users.
1325: my ($home_server_pick,$numlib) =
1326: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1327: 'default','hide');
1328: if ($numlib > 1) {
1329: $r->print("
1330: <br />
1331: $lt{'hs'}: $home_server_pick
1332: <br />");
1333: } else {
1334: $r->print($home_server_pick);
1335: }
1336: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1337: $r->print('<br /><h3>'.
1338: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1339: &Apache::loncommon::start_data_table().
1340: &build_tools_display($ccuname,$ccdomain,
1341: 'requestcourses').
1342: &Apache::loncommon::end_data_table());
1343: }
1344: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1345: $lt{'lg'}.'</h3>');
1346: my ($fixedauth,$varauth,$authmsg);
1347: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1348: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1349: my ($rules,$ruleorder) =
1350: &Apache::lonnet::inst_userrules($ccdomain,'username');
1351: if (ref($rules) eq 'HASH') {
1352: if (ref($rules->{$matchedrule}) eq 'HASH') {
1353: my $authtype = $rules->{$matchedrule}{'authtype'};
1354: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1355: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1356: } else {
1357: my $authparm = $rules->{$matchedrule}{'authparm'};
1358: $authmsg = $rules->{$matchedrule}{'authmsg'};
1359: if ($authtype =~ /^krb(4|5)$/) {
1360: my $ver = $1;
1361: if ($authparm ne '') {
1362: $fixedauth = <<"KERB";
1363: <input type="hidden" name="login" value="krb" />
1364: <input type="hidden" name="krbver" value="$ver" />
1365: <input type="hidden" name="krbarg" value="$authparm" />
1366: KERB
1367: }
1368: } else {
1369: $fixedauth =
1370: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1371: if ($rules->{$matchedrule}{'authparmfixed'}) {
1372: $fixedauth .=
1373: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1374: } else {
1375: if ($authtype eq 'int') {
1376: $varauth = '<br />'.
1377: &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>';
1378: } elsif ($authtype eq 'loc') {
1379: $varauth = '<br />'.
1380: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1381: } else {
1382: $varauth =
1383: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1384: }
1385: }
1386: }
1387: }
1388: } else {
1389: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1390: }
1391: }
1392: if ($authmsg) {
1393: $r->print(<<ENDAUTH);
1394: $fixedauth
1395: $authmsg
1396: $varauth
1397: ENDAUTH
1398: }
1399: } else {
1400: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1401: }
1402: $r->print($portfolioform.$domroleform);
1403: if ($env{'form.action'} eq 'singlestudent') {
1404: $r->print(&date_sections_select($context,$newuser,$formname,
1405: $permission,$crstype,$ccuname,
1406: $ccdomain,$showcredits));
1407: }
1408: $r->print('</div><div class="LC_clear_float_footer"></div>');
1409: } else { # user already exists
1410: $r->print($start_page.$forminfo);
1411: if ($env{'form.action'} eq 'singlestudent') {
1412: if ($crstype eq 'Community') {
1413: $title = &mt('Enroll one member: [_1] in domain [_2]',
1414: '"'.$ccuname.'"','"'.$ccdomain.'"');
1415: } else {
1416: $title = &mt('Enroll one student: [_1] in domain [_2]',
1417: '"'.$ccuname.'"','"'.$ccdomain.'"');
1418: }
1419: } else {
1420: if ($permission->{'cusr'}) {
1421: $title = &mt('Modify existing user: [_1] in domain [_2]',
1422: '"'.$ccuname.'"','"'.$ccdomain.'"');
1423: } else {
1424: $title = &mt('Existing user: [_1] in domain [_2]',
1425: '"'.$ccuname.'"','"'.$ccdomain.'"');
1426: }
1427: }
1428: $r->print('<h2>'.$title.'</h2>'."\n");
1429: $r->print('<div class="LC_left_float">');
1430: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1431: $inst_results{$ccuname.':'.$ccdomain}));
1432: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1433: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1434: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1435: &Apache::loncommon::start_data_table());
1436: if ($env{'request.role.domain'} eq $ccdomain) {
1437: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1438: } else {
1439: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1440: $env{'request.role.domain'}));
1441: }
1442: $r->print(&Apache::loncommon::end_data_table());
1443: }
1444: $r->print('</div>');
1445: my @order = ('auth','quota','tools','requestauthor');
1446: my %user_text;
1447: my ($isadv,$isauthor) =
1448: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1449: if ((!$isauthor) &&
1450: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1451: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1452: ($env{'request.role.domain'} eq $ccdomain)) {
1453: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1454: }
1455: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1456: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1457: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1458: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1459: # Current user has quota modification privileges
1460: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1461: }
1462: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1463: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1464: my %lt=&Apache::lonlocal::texthash(
1465: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1466: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1467: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1468: );
1469: $user_text{'quota'} = <<ENDNOPORTPRIV;
1470: <h3>$lt{'dska'}</h3>
1471: $lt{'youd'} $lt{'ichr'}: $ccdomain
1472: ENDNOPORTPRIV
1473: }
1474: }
1475: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1476: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1477: my %lt=&Apache::lonlocal::texthash(
1478: 'utav' => "User Tools Availability",
1479: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1480: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1481: );
1482: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1483: <h3>$lt{'utav'}</h3>
1484: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1485: ENDNOTOOLSPRIV
1486: }
1487: }
1488: my $gotdiv = 0;
1489: foreach my $item (@order) {
1490: if ($user_text{$item} ne '') {
1491: unless ($gotdiv) {
1492: $r->print('<div class="LC_left_float">');
1493: $gotdiv = 1;
1494: }
1495: $r->print('<br />'.$user_text{$item});
1496: }
1497: }
1498: if ($env{'form.action'} eq 'singlestudent') {
1499: unless ($gotdiv) {
1500: $r->print('<div class="LC_left_float">');
1501: }
1502: my $credits;
1503: if ($showcredits) {
1504: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1505: if ($credits eq '') {
1506: $credits = $defaultcredits;
1507: }
1508: }
1509: $r->print(&date_sections_select($context,$newuser,$formname,
1510: $permission,$crstype,$ccuname,
1511: $ccdomain,$showcredits));
1512: }
1513: if ($gotdiv) {
1514: $r->print('</div><div class="LC_clear_float_footer"></div>');
1515: }
1516: my $statuses;
1517: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1518: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1519: $statuses = ['active'];
1520: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1521: ($env{'request.course.sec'} &&
1522: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1523: $statuses = ['active'];
1524: }
1525: if ($env{'form.action'} ne 'singlestudent') {
1526: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1527: $roledom,$crstype,$showcredits,$statuses);
1528: }
1529: } ## End of new user/old user logic
1530: if ($env{'form.action'} eq 'singlestudent') {
1531: my $btntxt;
1532: if ($crstype eq 'Community') {
1533: $btntxt = &mt('Enroll Member');
1534: } else {
1535: $btntxt = &mt('Enroll Student');
1536: }
1537: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1538: } elsif ($permission->{'cusr'}) {
1539: $r->print('<div class="LC_left_float">'.
1540: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1541: my $addrolesdisplay = 0;
1542: if ($context eq 'domain' || $context eq 'author') {
1543: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1544: }
1545: if ($context eq 'domain') {
1546: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1547: if (!$addrolesdisplay) {
1548: $addrolesdisplay = $add_domainroles;
1549: }
1550: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1551: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1552: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1553: } elsif ($context eq 'author') {
1554: if ($addrolesdisplay) {
1555: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1556: '<br /><input type="button" value="'.&mt('Save').'"');
1557: if ($newuser) {
1558: $r->print(' onclick="auth_check()" \>'."\n");
1559: } else {
1560: $r->print('onclick="this.form.submit()" \>'."\n");
1561: }
1562: } else {
1563: $r->print('</fieldset></div>'.
1564: '<div class="LC_clear_float_footer"></div>'.
1565: '<br /><a href="javascript:backPage(document.cu)">'.
1566: &mt('Back to previous page').'</a>');
1567: }
1568: } else {
1569: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1570: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1571: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1572: }
1573: }
1574: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1575: $r->print('<input type="hidden" name="currstate" value="" />');
1576: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1577: return;
1578: }
1579:
1580: sub singleuser_breadcrumb {
1581: my ($crstype,$context,$domain) = @_;
1582: my %breadcrumb_text;
1583: if ($env{'form.action'} eq 'singlestudent') {
1584: if ($crstype eq 'Community') {
1585: $breadcrumb_text{'search'} = 'Enroll a member';
1586: } else {
1587: $breadcrumb_text{'search'} = 'Enroll a student';
1588: }
1589: $breadcrumb_text{'userpicked'} = 'Select a user';
1590: $breadcrumb_text{'modify'} = 'Set section/dates';
1591: } elsif ($env{'form.action'} eq 'accesslogs') {
1592: $breadcrumb_text{'search'} = 'View access logs for a user';
1593: $breadcrumb_text{'userpicked'} = 'Select a user';
1594: $breadcrumb_text{'activity'} = 'Activity';
1595: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1596: (!&Apache::lonnet::allowed('mau',$domain))) {
1597: $breadcrumb_text{'search'} = "View user's roles";
1598: $breadcrumb_text{'userpicked'} = 'Select a user';
1599: $breadcrumb_text{'modify'} = 'User roles';
1600: } else {
1601: $breadcrumb_text{'search'} = 'Create/modify a user';
1602: $breadcrumb_text{'userpicked'} = 'Select a user';
1603: $breadcrumb_text{'modify'} = 'Set user role';
1604: }
1605: return %breadcrumb_text;
1606: }
1607:
1608: sub date_sections_select {
1609: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1610: $showcredits) = @_;
1611: my $credits;
1612: if ($showcredits) {
1613: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1614: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1615: if ($credits eq '') {
1616: $credits = $defaultcredits;
1617: }
1618: }
1619: my $cid = $env{'request.course.id'};
1620: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1621: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1622: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1623: undef,$formname,$permission);
1624: my $rowtitle = 'Section';
1625: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1626: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1627: $permission,$context,'',$crstype,
1628: $showcredits,$credits);
1629: my $output = $date_table.$secbox;
1630: return $output;
1631: }
1632:
1633: sub validation_javascript {
1634: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1635: $loaditem) = @_;
1636: my $dc_setcourse_code = '';
1637: my $nondc_setsection_code = '';
1638: if ($context eq 'domain') {
1639: my $dcdom = $env{'request.role.domain'};
1640: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1641: $dc_setcourse_code =
1642: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1643: } else {
1644: my $checkauth;
1645: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1646: $checkauth = 1;
1647: }
1648: if ($context eq 'course') {
1649: $nondc_setsection_code =
1650: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1651: undef,$checkauth,
1652: $crstype);
1653: }
1654: if ($checkauth) {
1655: $nondc_setsection_code .=
1656: &Apache::lonuserutils::verify_authen($formname,$context);
1657: }
1658: }
1659: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1660: $nondc_setsection_code,$groupslist);
1661: my ($jsback,$elements) = &crumb_utilities();
1662: $js .= "\n".
1663: '<script type="text/javascript">'."\n".
1664: '// <![CDATA['."\n".
1665: $jsback."\n".
1666: '// ]]>'."\n".
1667: '</script>'."\n";
1668: return $js;
1669: }
1670:
1671: sub display_existing_roles {
1672: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1673: $showcredits,$statuses) = @_;
1674: my $now=time;
1675: my $showall = 1;
1676: my ($showexpired,$showactive);
1677: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1678: $showall = 0;
1679: if (grep(/^expired$/,@{$statuses})) {
1680: $showexpired = 1;
1681: }
1682: if (grep(/^active$/,@{$statuses})) {
1683: $showactive = 1;
1684: }
1685: if ($showexpired && $showactive) {
1686: $showall = 1;
1687: }
1688: }
1689: my %lt=&Apache::lonlocal::texthash(
1690: 'rer' => "Existing Roles",
1691: 'rev' => "Revoke",
1692: 'del' => "Delete",
1693: 'ren' => "Re-Enable",
1694: 'rol' => "Role",
1695: 'ext' => "Extent",
1696: 'crd' => "Credits",
1697: 'sta' => "Start",
1698: 'end' => "End",
1699: );
1700: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1701: if ($context eq 'course' || $context eq 'author') {
1702: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1703: my %roleshash =
1704: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1705: ['active','previous','future'],\@roles,$roledom,1);
1706: foreach my $key (keys(%roleshash)) {
1707: my ($start,$end) = split(':',$roleshash{$key});
1708: next if ($start eq '-1' || $end eq '-1');
1709: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1710: if ($context eq 'course') {
1711: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1712: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1713: } elsif ($context eq 'author') {
1714: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1715: }
1716: my ($newkey,$newvalue,$newrole);
1717: $newkey = '/'.$rdom.'/'.$rnum;
1718: if ($sec ne '') {
1719: $newkey .= '/'.$sec;
1720: }
1721: $newvalue = $role;
1722: if ($role =~ /^cr/) {
1723: $newrole = 'cr';
1724: } else {
1725: $newrole = $role;
1726: }
1727: $newkey .= '_'.$newrole;
1728: if ($start ne '' && $end ne '') {
1729: $newvalue .= '_'.$end.'_'.$start;
1730: } elsif ($end ne '') {
1731: $newvalue .= '_'.$end;
1732: }
1733: $rolesdump{$newkey} = $newvalue;
1734: }
1735: } else {
1736: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1737: }
1738: # Build up table of user roles to allow revocation and re-enabling of roles.
1739: my ($tmp) = keys(%rolesdump);
1740: return if ($tmp =~ /^(con_lost|error)/i);
1741: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1742: my $b1=join('_',(split('_',$b))[1,0]);
1743: return $a1 cmp $b1;
1744: } keys(%rolesdump)) {
1745: next if ($area =~ /^rolesdef/);
1746: my $envkey=$area;
1747: my $role = $rolesdump{$area};
1748: my $thisrole=$area;
1749: $area =~ s/\_\w\w$//;
1750: my ($role_code,$role_end_time,$role_start_time) =
1751: split(/_/,$role);
1752: my $active=1;
1753: $active=0 if (($role_end_time) && ($now>$role_end_time));
1754: if ($active) {
1755: next unless($showall || $showactive);
1756: } else {
1757: next unless($showall || $showexpired);
1758: }
1759: # Is this a custom role? Get role owner and title.
1760: my ($croleudom,$croleuname,$croletitle)=
1761: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1762: my $allowed=0;
1763: my $delallowed=0;
1764: my $sortkey=$role_code;
1765: my $class='Unknown';
1766: my $credits='';
1767: my $csec;
1768: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1769: $class='Course';
1770: my ($coursedom,$coursedir) = ($1,$2);
1771: my $cid = $1.'_'.$2;
1772: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1773: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1774: my %coursedata=
1775: &Apache::lonnet::coursedescription($cid);
1776: if ($coursedir =~ /^$match_community$/) {
1777: $class='Community';
1778: }
1779: $sortkey.="\0$coursedom";
1780: my $carea;
1781: if (defined($coursedata{'description'})) {
1782: $carea=$coursedata{'description'}.
1783: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1784: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1785: $sortkey.="\0".$coursedata{'description'};
1786: } else {
1787: if ($class eq 'Community') {
1788: $carea=&mt('Unavailable community').': '.$area;
1789: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1790: } else {
1791: $carea=&mt('Unavailable course').': '.$area;
1792: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1793: }
1794: }
1795: $sortkey.="\0$coursedir";
1796: $inccourses->{$cid}=1;
1797: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1798: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1799: $credits =
1800: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1801: $coursedom,$coursedir);
1802: if ($credits eq '') {
1803: $credits = $defaultcredits;
1804: }
1805: }
1806: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1807: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1808: $allowed=1;
1809: }
1810: unless ($allowed) {
1811: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1812: if ($isowner) {
1813: if (($role_code eq 'co') && ($class eq 'Community')) {
1814: $allowed = 1;
1815: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1816: $allowed = 1;
1817: }
1818: }
1819: }
1820: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1821: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1822: $delallowed=1;
1823: }
1824: # - custom role. Needs more info, too
1825: if ($croletitle) {
1826: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1827: $allowed=1;
1828: $thisrole.='.'.$role_code;
1829: }
1830: }
1831: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1832: $csec = $2;
1833: $carea.='<br />'.&mt('Section: [_1]',$csec);
1834: $sortkey.="\0$csec";
1835: if (!$allowed) {
1836: if ($env{'request.course.sec'} eq $csec) {
1837: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1838: $allowed = 1;
1839: }
1840: }
1841: }
1842: }
1843: $area=$carea;
1844: } else {
1845: $sortkey.="\0".$area;
1846: # Determine if current user is able to revoke privileges
1847: if ($area=~m{^/($match_domain)/}) {
1848: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1849: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1850: $allowed=1;
1851: }
1852: if (((&Apache::lonnet::allowed('dro',$1)) ||
1853: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1854: ($role_code ne 'dc')) {
1855: $delallowed=1;
1856: }
1857: } else {
1858: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1859: $allowed=1;
1860: }
1861: }
1862: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1863: $class='Authoring Space';
1864: } elsif ($role_code eq 'su') {
1865: $class='System';
1866: } else {
1867: $class='Domain';
1868: }
1869: }
1870: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1871: $area=~m{/($match_domain)/($match_username)};
1872: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1873: $allowed=1;
1874: } else {
1875: $allowed=0;
1876: }
1877: }
1878: my $row = '';
1879: if ($showall) {
1880: $row.= '<td>';
1881: if (($active) && ($allowed)) {
1882: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1883: } else {
1884: if ($active) {
1885: $row.=' ';
1886: } else {
1887: $row.=&mt('expired or revoked');
1888: }
1889: }
1890: $row.='</td><td>';
1891: if ($allowed && !$active) {
1892: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1893: } else {
1894: $row.=' ';
1895: }
1896: $row.='</td><td>';
1897: if ($delallowed) {
1898: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1899: } else {
1900: $row.=' ';
1901: }
1902: $row.= '</td>';
1903: }
1904: my $plaintext='';
1905: if (!$croletitle) {
1906: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1907: if (($showcredits) && ($credits ne '')) {
1908: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1909: '<span class="LC_fontsize_small">'.
1910: &mt('Credits: [_1]',$credits).
1911: '</span></span>';
1912: }
1913: } else {
1914: $plaintext=
1915: &mt('Custom role [_1][_2]defined by [_3]',
1916: '"'.$croletitle.'"',
1917: '<br />',
1918: $croleuname.':'.$croleudom);
1919: }
1920: $row.= '<td>'.$plaintext.'</td>'.
1921: '<td>'.$area.'</td>'.
1922: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1923: : ' ' ).'</td>'.
1924: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1925: : ' ' ).'</td>';
1926: $sortrole{$sortkey}=$envkey;
1927: $roletext{$envkey}=$row;
1928: $roleclass{$envkey}=$class;
1929: if ($allowed) {
1930: $rolepriv{$envkey}='edit';
1931: } else {
1932: if ($context eq 'domain') {
1933: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1934: ($envkey=~m{^/$ccdomain/})) {
1935: $rolepriv{$envkey}='view';
1936: }
1937: } elsif ($context eq 'course') {
1938: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1939: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
1940: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
1941: $rolepriv{$envkey}='view';
1942: }
1943: }
1944: }
1945: } # end of foreach (table building loop)
1946:
1947: my $rolesdisplay = 0;
1948: my %output = ();
1949: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1950: $output{$type} = '';
1951: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1952: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1953: $output{$type}.=
1954: &Apache::loncommon::start_data_table_row().
1955: $roletext{$sortrole{$which}}.
1956: &Apache::loncommon::end_data_table_row();
1957: }
1958: }
1959: unless($output{$type} eq '') {
1960: $output{$type} = '<tr class="LC_info_row">'.
1961: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1962: $output{$type};
1963: $rolesdisplay = 1;
1964: }
1965: }
1966: if ($rolesdisplay == 1) {
1967: my $contextrole='';
1968: if ($env{'request.course.id'}) {
1969: if (&Apache::loncommon::course_type() eq 'Community') {
1970: $contextrole = &mt('Existing Roles in this Community');
1971: } else {
1972: $contextrole = &mt('Existing Roles in this Course');
1973: }
1974: } elsif ($env{'request.role'} =~ /^au\./) {
1975: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1976: } else {
1977: if ($showall) {
1978: $contextrole = &mt('Existing Roles in this Domain');
1979: } elsif ($showactive) {
1980: $contextrole = &mt('Unexpired Roles in this Domain');
1981: } elsif ($showexpired) {
1982: $contextrole = &mt('Expired or Revoked Roles in this Domain');
1983: }
1984: }
1985: $r->print('<div class="LC_left_float">'.
1986: '<fieldset><legend>'.$contextrole.'</legend>'.
1987: &Apache::loncommon::start_data_table("LC_createuser").
1988: &Apache::loncommon::start_data_table_header_row());
1989: if ($showall) {
1990: $r->print(
1991: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1992: );
1993: } elsif ($showexpired) {
1994: $r->print('<th>'.$lt{'rev'}.'</th>');
1995: }
1996: $r->print(
1997: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
1998: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1999: &Apache::loncommon::end_data_table_header_row());
2000: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
2001: if ($output{$type}) {
2002: $r->print($output{$type}."\n");
2003: }
2004: }
2005: $r->print(&Apache::loncommon::end_data_table().
2006: '</fieldset></div>');
2007: }
2008: return;
2009: }
2010:
2011: sub new_coauthor_roles {
2012: my ($r,$ccuname,$ccdomain) = @_;
2013: my $addrolesdisplay = 0;
2014: #
2015: # Co-Author
2016: #
2017: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2018: $env{'request.role.domain'}) &&
2019: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2020: # No sense in assigning co-author role to yourself
2021: $addrolesdisplay = 1;
2022: my $cuname=$env{'user.name'};
2023: my $cudom=$env{'request.role.domain'};
2024: my %lt=&Apache::lonlocal::texthash(
2025: 'cs' => "Authoring Space",
2026: 'act' => "Activate",
2027: 'rol' => "Role",
2028: 'ext' => "Extent",
2029: 'sta' => "Start",
2030: 'end' => "End",
2031: 'cau' => "Co-Author",
2032: 'caa' => "Assistant Co-Author",
2033: 'ssd' => "Set Start Date",
2034: 'sed' => "Set End Date"
2035: );
2036: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2037: &Apache::loncommon::start_data_table()."\n".
2038: &Apache::loncommon::start_data_table_header_row()."\n".
2039: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2040: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2041: '<th>'.$lt{'end'}.'</th>'."\n".
2042: &Apache::loncommon::end_data_table_header_row()."\n".
2043: &Apache::loncommon::start_data_table_row().'
2044: <td>
2045: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
2046: </td>
2047: <td>'.$lt{'cau'}.'</td>
2048: <td>'.$cudom.'_'.$cuname.'</td>
2049: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2050: <a href=
2051: "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>
2052: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2053: <a href=
2054: "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".
2055: &Apache::loncommon::end_data_table_row()."\n".
2056: &Apache::loncommon::start_data_table_row()."\n".
2057: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
2058: <td>'.$lt{'caa'}.'</td>
2059: <td>'.$cudom.'_'.$cuname.'</td>
2060: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2061: <a href=
2062: "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>
2063: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2064: <a href=
2065: "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".
2066: &Apache::loncommon::end_data_table_row()."\n".
2067: &Apache::loncommon::end_data_table());
2068: } elsif ($env{'request.role'} =~ /^au\./) {
2069: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2070: $env{'request.role.domain'}))) {
2071: $r->print('<span class="LC_error">'.
2072: &mt('You do not have privileges to assign co-author roles.').
2073: '</span>');
2074: } elsif (($env{'user.name'} eq $ccuname) &&
2075: ($env{'user.domain'} eq $ccdomain)) {
2076: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Authoring Space is not permitted'));
2077: }
2078: }
2079: return $addrolesdisplay;;
2080: }
2081:
2082: sub new_domain_roles {
2083: my ($r,$ccdomain) = @_;
2084: my $addrolesdisplay = 0;
2085: #
2086: # Domain level
2087: #
2088: my $num_domain_level = 0;
2089: my $domaintext =
2090: '<h4>'.&mt('Domain Level').'</h4>'.
2091: &Apache::loncommon::start_data_table().
2092: &Apache::loncommon::start_data_table_header_row().
2093: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2094: &mt('Extent').'</th>'.
2095: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2096: &Apache::loncommon::end_data_table_header_row();
2097: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
2098: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
2099: foreach my $role (@allroles) {
2100: next if ($role eq 'ad');
2101: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
2102: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2103: my $plrole=&Apache::lonnet::plaintext($role);
2104: my %lt=&Apache::lonlocal::texthash(
2105: 'ssd' => "Set Start Date",
2106: 'sed' => "Set End Date"
2107: );
2108: $num_domain_level ++;
2109: $domaintext .=
2110: &Apache::loncommon::start_data_table_row().
2111: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
2112: <td>'.$plrole.'</td>
2113: <td>'.$thisdomain.'</td>
2114: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2115: <a href=
2116: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2117: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2118: <a href=
2119: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2120: &Apache::loncommon::end_data_table_row();
2121: }
2122: }
2123: }
2124: $domaintext.= &Apache::loncommon::end_data_table();
2125: if ($num_domain_level > 0) {
2126: $r->print($domaintext);
2127: $addrolesdisplay = 1;
2128: }
2129: return $addrolesdisplay;
2130: }
2131:
2132: sub user_authentication {
2133: my ($ccuname,$ccdomain,$formname) = @_;
2134: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
2135: my $outcome;
2136: my %lt=&Apache::lonlocal::texthash(
2137: 'err' => "ERROR",
2138: 'uuas' => "This user has an unrecognized authentication scheme",
2139: 'adcs' => "Please alert a domain coordinator of this situation",
2140: 'sldb' => "Please specify login data below",
2141: 'ld' => "Login Data"
2142: );
2143: # Check for a bad authentication type
2144: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2145: # bad authentication scheme
2146: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2147: &initialize_authen_forms($ccdomain,$formname);
2148:
2149: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
2150: $outcome = <<ENDBADAUTH;
2151: <script type="text/javascript" language="Javascript">
2152: // <![CDATA[
2153: $loginscript
2154: // ]]>
2155: </script>
2156: <span class="LC_error">$lt{'err'}:
2157: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2158: <h3>$lt{'ld'}</h3>
2159: $choices
2160: ENDBADAUTH
2161: } else {
2162: # This user is not allowed to modify the user's
2163: # authentication scheme, so just notify them of the problem
2164: $outcome = <<ENDBADAUTH;
2165: <span class="LC_error"> $lt{'err'}:
2166: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2167: </span>
2168: ENDBADAUTH
2169: }
2170: } else { # Authentication type is valid
2171: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
2172: my ($authformcurrent,$can_modify,@authform_others) =
2173: &modify_login_block($ccdomain,$currentauth);
2174: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2175: # Current user has login modification privileges
2176: $outcome =
2177: '<script type="text/javascript" language="Javascript">'."\n".
2178: '// <![CDATA['."\n".
2179: $loginscript."\n".
2180: '// ]]>'."\n".
2181: '</script>'."\n".
2182: '<h3>'.$lt{'ld'}.'</h3>'.
2183: &Apache::loncommon::start_data_table().
2184: &Apache::loncommon::start_data_table_row().
2185: '<td>'.$authformnop;
2186: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
2187: $outcome .= '</td>'."\n".
2188: &Apache::loncommon::end_data_table_row().
2189: &Apache::loncommon::start_data_table_row().
2190: '<td>'.$authformcurrent.'</td>'.
2191: &Apache::loncommon::end_data_table_row()."\n";
2192: } else {
2193: $outcome .= ' ('.$authformcurrent.')</td>'.
2194: &Apache::loncommon::end_data_table_row()."\n";
2195: }
2196: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2197: foreach my $item (@authform_others) {
2198: $outcome .= &Apache::loncommon::start_data_table_row().
2199: '<td>'.$item.'</td>'.
2200: &Apache::loncommon::end_data_table_row()."\n";
2201: }
2202: }
2203: $outcome .= &Apache::loncommon::end_data_table();
2204: } else {
2205: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2206: # Current user has rights to view domain preferences for user's domain
2207: my $result;
2208: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2209: my ($krbver,$krbrealm) = ($1,$2);
2210: if ($krbrealm eq '') {
2211: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2212: } else {
2213: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2214: $krbrealm,$krbver);
2215: }
2216: } elsif ($currentauth =~ /^internal:/) {
2217: $result = &mt('Currently internally authenticated.');
2218: } elsif ($currentauth =~ /^localauth:/) {
2219: $result = &mt('Currently using local (institutional) authentication.');
2220: } elsif ($currentauth =~ /^unix:/) {
2221: $result = &mt('Currently Filesystem Authenticated.');
2222: }
2223: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2224: &Apache::loncommon::start_data_table().
2225: &Apache::loncommon::start_data_table_row().
2226: '<td>'.$result.'</td>'.
2227: &Apache::loncommon::end_data_table_row()."\n".
2228: &Apache::loncommon::end_data_table();
2229: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
2230: my %lt=&Apache::lonlocal::texthash(
2231: 'ccld' => "Change Current Login Data",
2232: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2233: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2234: );
2235: $outcome .= <<ENDNOPRIV;
2236: <h3>$lt{'ccld'}</h3>
2237: $lt{'yodo'} $lt{'ifch'}: $ccdomain
2238: <input type="hidden" name="login" value="nochange" />
2239: ENDNOPRIV
2240: }
2241: }
2242: } ## End of "check for bad authentication type" logic
2243: return $outcome;
2244: }
2245:
2246: sub modify_login_block {
2247: my ($dom,$currentauth) = @_;
2248: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2249: my ($authnum,%can_assign) =
2250: &Apache::loncommon::get_assignable_auth($dom);
2251: my ($authformcurrent,@authform_others,$show_override_msg);
2252: if ($currentauth=~/^krb(4|5):/) {
2253: $authformcurrent=$authformkrb;
2254: if ($can_assign{'int'}) {
2255: push(@authform_others,$authformint);
2256: }
2257: if ($can_assign{'loc'}) {
2258: push(@authform_others,$authformloc);
2259: }
2260: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2261: $show_override_msg = 1;
2262: }
2263: } elsif ($currentauth=~/^internal:/) {
2264: $authformcurrent=$authformint;
2265: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2266: push(@authform_others,$authformkrb);
2267: }
2268: if ($can_assign{'loc'}) {
2269: push(@authform_others,$authformloc);
2270: }
2271: if ($can_assign{'int'}) {
2272: $show_override_msg = 1;
2273: }
2274: } elsif ($currentauth=~/^unix:/) {
2275: $authformcurrent=$authformfsys;
2276: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2277: push(@authform_others,$authformkrb);
2278: }
2279: if ($can_assign{'int'}) {
2280: push(@authform_others,$authformint);
2281: }
2282: if ($can_assign{'loc'}) {
2283: push(@authform_others,$authformloc);
2284: }
2285: if ($can_assign{'fsys'}) {
2286: $show_override_msg = 1;
2287: }
2288: } elsif ($currentauth=~/^localauth:/) {
2289: $authformcurrent=$authformloc;
2290: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2291: push(@authform_others,$authformkrb);
2292: }
2293: if ($can_assign{'int'}) {
2294: push(@authform_others,$authformint);
2295: }
2296: if ($can_assign{'loc'}) {
2297: $show_override_msg = 1;
2298: }
2299: }
2300: if ($show_override_msg) {
2301: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2302: '</td></tr>'."\n".
2303: '<tr><td> </td>'.
2304: '<td><b>'.&mt('Currently in use').'</b></td>'.
2305: '<td align="right"><span class="LC_cusr_emph">'.
2306: &mt('will override current values').
2307: '</span></td></tr></table>';
2308: }
2309: return ($authformcurrent,$show_override_msg,@authform_others);
2310: }
2311:
2312: sub personal_data_display {
2313: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
2314: $now,$captchaform,$emailusername,$usertype) = @_;
2315: my ($output,%userenv,%canmodify,%canmodify_status);
2316: my @userinfo = ('firstname','middlename','lastname','generation',
2317: 'permanentemail','id');
2318: my $rowcount = 0;
2319: my $editable = 0;
2320: my %textboxsize = (
2321: firstname => '15',
2322: middlename => '15',
2323: lastname => '15',
2324: generation => '5',
2325: permanentemail => '25',
2326: id => '15',
2327: );
2328:
2329: my %lt=&Apache::lonlocal::texthash(
2330: 'pd' => "Personal Data",
2331: 'firstname' => "First Name",
2332: 'middlename' => "Middle Name",
2333: 'lastname' => "Last Name",
2334: 'generation' => "Generation",
2335: 'permanentemail' => "Permanent e-mail address",
2336: 'id' => "Student/Employee ID",
2337: 'lg' => "Login Data",
2338: 'inststatus' => "Affiliation",
2339: 'email' => 'E-mail address',
2340: 'valid' => 'Validation',
2341: );
2342:
2343: %canmodify_status =
2344: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2345: ['inststatus'],$rolesarray);
2346: if (!$newuser) {
2347: # Get the users information
2348: %userenv = &Apache::lonnet::get('environment',
2349: ['firstname','middlename','lastname','generation',
2350: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
2351: %canmodify =
2352: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2353: \@userinfo,$rolesarray);
2354: } elsif ($context eq 'selfcreate') {
2355: if ($newuser eq 'email') {
2356: if (ref($emailusername) eq 'HASH') {
2357: if (ref($emailusername->{$usertype}) eq 'HASH') {
2358: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
2359: @userinfo = ();
2360: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2361: foreach my $field (@{$infofields}) {
2362: if ($emailusername->{$usertype}->{$field}) {
2363: push(@userinfo,$field);
2364: $canmodify{$field} = 1;
2365: unless ($textboxsize{$field}) {
2366: $textboxsize{$field} = 25;
2367: }
2368: unless ($lt{$field}) {
2369: $lt{$field} = $infotitles->{$field};
2370: }
2371: if ($emailusername->{$usertype}->{$field} eq 'required') {
2372: $lt{$field} .= '<b>*</b>';
2373: }
2374: }
2375: }
2376: }
2377: }
2378: }
2379: } else {
2380: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2381: $inst_results,$rolesarray);
2382: }
2383: }
2384:
2385: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2386: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2387: &Apache::lonhtmlcommon::start_pick_box();
2388: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2389: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
2390: 'LC_oddrow_value')."\n".
2391: '<input type="text" name="uname" size="25" value="" autocomplete="off" />';
2392: $rowcount ++;
2393: $output .= &Apache::lonhtmlcommon::row_closure(1);
2394: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2395: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
2396: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
2397: 'LC_pick_box_title',
2398: 'LC_oddrow_value')."\n".
2399: $upassone."\n".
2400: &Apache::lonhtmlcommon::row_closure(1)."\n".
2401: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
2402: 'LC_pick_box_title',
2403: 'LC_oddrow_value')."\n".
2404: $upasstwo.
2405: &Apache::lonhtmlcommon::row_closure()."\n";
2406: }
2407: foreach my $item (@userinfo) {
2408: my $rowtitle = $lt{$item};
2409: my $hiderow = 0;
2410: if ($item eq 'generation') {
2411: $rowtitle = $genhelp.$rowtitle;
2412: }
2413: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
2414: if ($newuser) {
2415: if (ref($inst_results) eq 'HASH') {
2416: if ($inst_results->{$item} ne '') {
2417: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
2418: } else {
2419: if ($context eq 'selfcreate') {
2420: if ($canmodify{$item}) {
2421: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
2422: $editable ++;
2423: } else {
2424: $hiderow = 1;
2425: }
2426: } else {
2427: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2428: }
2429: }
2430: } else {
2431: if ($context eq 'selfcreate') {
2432: if ($canmodify{$item}) {
2433: if ($newuser eq 'email') {
2434: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
2435: } else {
2436: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
2437: }
2438: $editable ++;
2439: } else {
2440: $hiderow = 1;
2441: }
2442: } else {
2443: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2444: }
2445: }
2446: } else {
2447: if ($canmodify{$item}) {
2448: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
2449: if (($item eq 'id') && (!$newuser)) {
2450: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2451: }
2452: } else {
2453: $row .= $userenv{$item};
2454: }
2455: }
2456: $row .= &Apache::lonhtmlcommon::row_closure(1);
2457: if (!$hiderow) {
2458: $output .= $row;
2459: $rowcount ++;
2460: }
2461: }
2462: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2463: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2464: if (ref($types) eq 'ARRAY') {
2465: if (@{$types} > 0) {
2466: my ($hiderow,$shown);
2467: if ($canmodify_status{'inststatus'}) {
2468: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2469: } else {
2470: if ($userenv{'inststatus'} eq '') {
2471: $hiderow = 1;
2472: } else {
2473: my @showitems;
2474: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2475: if (exists($usertypes->{$item})) {
2476: push(@showitems,$usertypes->{$item});
2477: } else {
2478: push(@showitems,$item);
2479: }
2480: }
2481: if (@showitems) {
2482: $shown = join(', ',@showitems);
2483: } else {
2484: $hiderow = 1;
2485: }
2486: }
2487: }
2488: if (!$hiderow) {
2489: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
2490: $shown.&Apache::lonhtmlcommon::row_closure(1);
2491: if ($context eq 'selfcreate') {
2492: $rowcount ++;
2493: }
2494: $output .= $row;
2495: }
2496: }
2497: }
2498: }
2499: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2500: if ($captchaform) {
2501: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2502: 'LC_pick_box_title')."\n".
2503: $captchaform."\n".'<br /><br />'.
2504: &Apache::lonhtmlcommon::row_closure(1);
2505: $rowcount ++;
2506: }
2507: my $submit_text = &mt('Create account');
2508: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2509: '<br /><input type="submit" name="createaccount" value="'.
2510: $submit_text.'" />'.
2511: '<input type="hidden" name="type" value="'.$usertype.'" />'.
2512: &Apache::lonhtmlcommon::row_closure(1);
2513: }
2514: $output .= &Apache::lonhtmlcommon::end_pick_box();
2515: if (wantarray) {
2516: if ($context eq 'selfcreate') {
2517: return($output,$rowcount,$editable);
2518: } else {
2519: return $output;
2520: }
2521: } else {
2522: return $output;
2523: }
2524: }
2525:
2526: sub pick_inst_statuses {
2527: my ($curr,$usertypes,$types) = @_;
2528: my ($output,$rem,@currtypes);
2529: if ($curr ne '') {
2530: @currtypes = map { &unescape($_); } split(/:/,$curr);
2531: }
2532: my $numinrow = 2;
2533: if (ref($types) eq 'ARRAY') {
2534: $output = '<table>';
2535: my $lastcolspan;
2536: for (my $i=0; $i<@{$types}; $i++) {
2537: if (defined($usertypes->{$types->[$i]})) {
2538: my $rem = $i%($numinrow);
2539: if ($rem == 0) {
2540: if ($i<@{$types}-1) {
2541: if ($i > 0) {
2542: $output .= '</tr>';
2543: }
2544: $output .= '<tr>';
2545: }
2546: } elsif ($i==@{$types}-1) {
2547: my $colsleft = $numinrow - $rem;
2548: if ($colsleft > 1) {
2549: $lastcolspan = ' colspan="'.$colsleft.'"';
2550: }
2551: }
2552: my $check = ' ';
2553: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2554: $check = ' checked="checked" ';
2555: }
2556: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2557: '<span class="LC_nobreak"><label>'.
2558: '<input type="checkbox" name="inststatus" '.
2559: 'value="'.$types->[$i].'"'.$check.'/>'.
2560: $usertypes->{$types->[$i]}.'</label></span></td>';
2561: }
2562: }
2563: $output .= '</tr></table>';
2564: }
2565: return $output;
2566: }
2567:
2568: sub selfcreate_canmodify {
2569: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2570: if (ref($inst_results) eq 'HASH') {
2571: my @inststatuses = &get_inststatuses($inst_results);
2572: if (@inststatuses == 0) {
2573: @inststatuses = ('default');
2574: }
2575: $rolesarray = \@inststatuses;
2576: }
2577: my %canmodify =
2578: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2579: $rolesarray);
2580: return %canmodify;
2581: }
2582:
2583: sub get_inststatuses {
2584: my ($insthashref) = @_;
2585: my @inststatuses = ();
2586: if (ref($insthashref) eq 'HASH') {
2587: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2588: @inststatuses = @{$insthashref->{'inststatus'}};
2589: }
2590: }
2591: return @inststatuses;
2592: }
2593:
2594: # ================================================================= Phase Three
2595: sub update_user_data {
2596: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
2597: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2598: $env{'form.ccdomain'});
2599: # Error messages
2600: my $error = '<span class="LC_error">'.&mt('Error').': ';
2601: my $end = '</span><br /><br />';
2602: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
2603: "'$env{'form.prevphase'}','modify')".'" />'.
2604: &mt('Return to previous page').'</a>'.
2605: &Apache::loncommon::end_page();
2606: my $now = time;
2607: my $title;
2608: if (exists($env{'form.makeuser'})) {
2609: $title='Set Privileges for New User';
2610: } else {
2611: $title='Modify User Privileges';
2612: }
2613: my $newuser = 0;
2614: my ($jsback,$elements) = &crumb_utilities();
2615: my $jscript = '<script type="text/javascript">'."\n".
2616: '// <![CDATA['."\n".
2617: $jsback."\n".
2618: '// ]]>'."\n".
2619: '</script>'."\n";
2620: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
2621: push (@{$brcrum},
2622: {href => "javascript:backPage(document.userupdate)",
2623: text => $breadcrumb_text{'search'},
2624: faq => 282,
2625: bug => 'Instructor Interface',}
2626: );
2627: if ($env{'form.prevphase'} eq 'userpicked') {
2628: push(@{$brcrum},
2629: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2630: text => $breadcrumb_text{'userpicked'},
2631: faq => 282,
2632: bug => 'Instructor Interface',});
2633: }
2634: my $helpitem = 'Course_Change_Privileges';
2635: if ($env{'form.action'} eq 'singlestudent') {
2636: $helpitem = 'Course_Add_Student';
2637: }
2638: push(@{$brcrum},
2639: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2640: text => $breadcrumb_text{'modify'},
2641: faq => 282,
2642: bug => 'Instructor Interface',},
2643: {href => "/adm/createuser",
2644: text => "Result",
2645: faq => 282,
2646: bug => 'Instructor Interface',
2647: help => $helpitem});
2648: my $args = {bread_crumbs => $brcrum,
2649: bread_crumbs_component => 'User Management'};
2650: if ($env{'form.popup'}) {
2651: $args->{'no_nav_bar'} = 1;
2652: }
2653: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
2654: $r->print(&update_result_form($uhome));
2655: # Check Inputs
2656: if (! $env{'form.ccuname'} ) {
2657: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
2658: return;
2659: }
2660: if ( $env{'form.ccuname'} ne
2661: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
2662: $r->print($error.&mt('Invalid login name.').' '.
2663: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
2664: $end.$rtnlink);
2665: return;
2666: }
2667: if (! $env{'form.ccdomain'} ) {
2668: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
2669: return;
2670: }
2671: if ( $env{'form.ccdomain'} ne
2672: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
2673: $r->print($error.&mt('Invalid domain name.').' '.
2674: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
2675: $end.$rtnlink);
2676: return;
2677: }
2678: if ($uhome eq 'no_host') {
2679: $newuser = 1;
2680: }
2681: if (! exists($env{'form.makeuser'})) {
2682: # Modifying an existing user, so check the validity of the name
2683: if ($uhome eq 'no_host') {
2684: $r->print(
2685: $error
2686: .'<p class="LC_error">'
2687: .&mt('Unable to determine home server for [_1] in domain [_2].',
2688: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2689: .'</p>');
2690: return;
2691: }
2692: }
2693: # Determine authentication method and password for the user being modified
2694: my $amode='';
2695: my $genpwd='';
2696: if ($env{'form.login'} eq 'krb') {
2697: $amode='krb';
2698: $amode.=$env{'form.krbver'};
2699: $genpwd=$env{'form.krbarg'};
2700: } elsif ($env{'form.login'} eq 'int') {
2701: $amode='internal';
2702: $genpwd=$env{'form.intarg'};
2703: } elsif ($env{'form.login'} eq 'fsys') {
2704: $amode='unix';
2705: $genpwd=$env{'form.fsysarg'};
2706: } elsif ($env{'form.login'} eq 'loc') {
2707: $amode='localauth';
2708: $genpwd=$env{'form.locarg'};
2709: $genpwd=" " if (!$genpwd);
2710: } elsif (($env{'form.login'} eq 'nochange') ||
2711: ($env{'form.login'} eq '' )) {
2712: # There is no need to tell the user we did not change what they
2713: # did not ask us to change.
2714: # If they are creating a new user but have not specified login
2715: # information this will be caught below.
2716: } else {
2717: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2718: return;
2719: }
2720:
2721: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
2722: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2723: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2724: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
2725:
2726: my (%alerts,%rulematch,%inst_results,%curr_rules);
2727: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
2728: my @usertools = ('aboutme','blog','webdav','portfolio');
2729: my @requestcourses = ('official','unofficial','community','textbook');
2730: my @requestauthor = ('requestauthor');
2731: my ($othertitle,$usertypes,$types) =
2732: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
2733: my %canmodify_status =
2734: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2735: ['inststatus']);
2736: if ($env{'form.makeuser'}) {
2737: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
2738: # Check for the authentication mode and password
2739: if (! $amode || ! $genpwd) {
2740: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2741: return;
2742: }
2743: # Determine desired host
2744: my $desiredhost = $env{'form.hserver'};
2745: if (lc($desiredhost) eq 'default') {
2746: $desiredhost = undef;
2747: } else {
2748: my %home_servers =
2749: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
2750: if (! exists($home_servers{$desiredhost})) {
2751: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2752: return;
2753: }
2754: }
2755: # Check ID format
2756: my %checkhash;
2757: my %checks = ('id' => 1);
2758: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
2759: 'newuser' => $newuser,
2760: 'id' => $env{'form.cid'},
2761: );
2762: if ($env{'form.cid'} ne '') {
2763: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2764: \%rulematch,\%inst_results,\%curr_rules);
2765: if (ref($alerts{'id'}) eq 'HASH') {
2766: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2767: my $domdesc =
2768: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2769: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2770: my $userchkmsg;
2771: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2772: $userchkmsg =
2773: &Apache::loncommon::instrule_disallow_msg('id',
2774: $domdesc,1).
2775: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2776: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2777: }
2778: $r->print($error.&mt('Invalid ID format').$end.
2779: $userchkmsg.$rtnlink);
2780: return;
2781: }
2782: }
2783: }
2784: }
2785: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
2786: # Call modifyuser
2787: my $result = &Apache::lonnet::modifyuser
2788: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
2789: $amode,$genpwd,$env{'form.cfirstname'},
2790: $env{'form.cmiddlename'},$env{'form.clastname'},
2791: $env{'form.cgeneration'},undef,$desiredhost,
2792: $env{'form.cpermanentemail'});
2793: $r->print(&mt('Generating user').': '.$result);
2794: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
2795: $env{'form.ccdomain'});
2796: my (%changeHash,%newcustom,%changed,%changedinfo);
2797: if ($uhome ne 'no_host') {
2798: if ($context eq 'domain') {
2799: foreach my $name ('portfolio','author') {
2800: if ($env{'form.custom_'.$name.'quota'} == 1) {
2801: if ($env{'form.'.$name.'quota'} eq '') {
2802: $newcustom{$name.'quota'} = 0;
2803: } else {
2804: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2805: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2806: }
2807: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2808: $changed{$name.'quota'} = 1;
2809: }
2810: }
2811: }
2812: foreach my $item (@usertools) {
2813: if ($env{'form.custom'.$item} == 1) {
2814: $newcustom{$item} = $env{'form.tools_'.$item};
2815: $changed{$item} = &tool_admin($item,$newcustom{$item},
2816: \%changeHash,'tools');
2817: }
2818: }
2819: foreach my $item (@requestcourses) {
2820: if ($env{'form.custom'.$item} == 1) {
2821: $newcustom{$item} = $env{'form.crsreq_'.$item};
2822: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2823: $newcustom{$item} .= '=';
2824: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2825: if ($env{'form.crsreq_'.$item.'_limit'}) {
2826: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2827: }
2828: }
2829: $changed{$item} = &tool_admin($item,$newcustom{$item},
2830: \%changeHash,'requestcourses');
2831: }
2832: }
2833: if ($env{'form.customrequestauthor'} == 1) {
2834: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2835: $changed{'requestauthor'} = &tool_admin('requestauthor',
2836: $newcustom{'requestauthor'},
2837: \%changeHash,'requestauthor');
2838: }
2839: }
2840: if ($canmodify_status{'inststatus'}) {
2841: if (exists($env{'form.inststatus'})) {
2842: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2843: if (@inststatuses > 0) {
2844: $changeHash{'inststatus'} = join(',',@inststatuses);
2845: $changed{'inststatus'} = $changeHash{'inststatus'};
2846: }
2847: }
2848: }
2849: if (keys(%changed)) {
2850: foreach my $item (@userinfo) {
2851: $changeHash{$item} = $env{'form.c'.$item};
2852: }
2853: my $chgresult =
2854: &Apache::lonnet::put('environment',\%changeHash,
2855: $env{'form.ccdomain'},$env{'form.ccuname'});
2856: }
2857: }
2858: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2859: &Apache::lonnet::hostname($uhome));
2860: } elsif (($env{'form.login'} ne 'nochange') &&
2861: ($env{'form.login'} ne '' )) {
2862: # Modify user privileges
2863: if (! $amode || ! $genpwd) {
2864: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
2865: return;
2866: }
2867: # Only allow authentication modification if the person has authority
2868: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
2869: $r->print('Modifying authentication: '.
2870: &Apache::lonnet::modifyuserauth(
2871: $env{'form.ccdomain'},$env{'form.ccuname'},
2872: $amode,$genpwd));
2873: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
2874: ($env{'form.ccuname'},$env{'form.ccdomain'}));
2875: } else {
2876: # Okay, this is a non-fatal error.
2877: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
2878: }
2879: }
2880: $r->rflush(); # Finish display of header before time consuming actions start
2881: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
2882: ##
2883: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
2884: if ($context eq 'course') {
2885: ($cnum,$cdom) =
2886: &Apache::lonuserutils::get_course_identity();
2887: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
2888: if ($showcredits) {
2889: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2890: }
2891: }
2892: if (! $env{'form.makeuser'} ) {
2893: # Check for need to change
2894: my %userenv = &Apache::lonnet::get
2895: ('environment',['firstname','middlename','lastname','generation',
2896: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2897: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
2898: 'requestcourses.official','requestcourses.unofficial',
2899: 'requestcourses.community','requestcourses.textbook',
2900: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2901: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
2902: 'requestauthor'],
2903: $env{'form.ccdomain'},$env{'form.ccuname'});
2904: my ($tmp) = keys(%userenv);
2905: if ($tmp =~ /^(con_lost|error)/i) {
2906: %userenv = ();
2907: }
2908: my $no_forceid_alert;
2909: # Check to see if user information can be changed
2910: my %domconfig =
2911: &Apache::lonnet::get_dom('configuration',['usermodification'],
2912: $env{'form.ccdomain'});
2913: my @statuses = ('active','future');
2914: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2915: my ($auname,$audom);
2916: if ($context eq 'author') {
2917: $auname = $env{'user.name'};
2918: $audom = $env{'user.domain'};
2919: }
2920: foreach my $item (keys(%roles)) {
2921: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
2922: if ($context eq 'course') {
2923: if ($cnum ne '' && $cdom ne '') {
2924: if ($rolenum eq $cnum && $roledom eq $cdom) {
2925: if (!grep(/^\Q$role\E$/,@userroles)) {
2926: push(@userroles,$role);
2927: }
2928: }
2929: }
2930: } elsif ($context eq 'author') {
2931: if ($rolenum eq $auname && $roledom eq $audom) {
2932: if (!grep(/^\Q$role\E$/,@userroles)) {
2933: push(@userroles,$role);
2934: }
2935: }
2936: }
2937: }
2938: if ($env{'form.action'} eq 'singlestudent') {
2939: if (!grep(/^st$/,@userroles)) {
2940: push(@userroles,'st');
2941: }
2942: } else {
2943: # Check for course or co-author roles being activated or re-enabled
2944: if ($context eq 'author' || $context eq 'course') {
2945: foreach my $key (keys(%env)) {
2946: if ($context eq 'author') {
2947: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2948: if (!grep(/^\Q$1\E$/,@userroles)) {
2949: push(@userroles,$1);
2950: }
2951: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2952: if (!grep(/^\Q$1\E$/,@userroles)) {
2953: push(@userroles,$1);
2954: }
2955: }
2956: } elsif ($context eq 'course') {
2957: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2958: if (!grep(/^\Q$1\E$/,@userroles)) {
2959: push(@userroles,$1);
2960: }
2961: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
2962: if (!grep(/^\Q$1\E$/,@userroles)) {
2963: push(@userroles,$1);
2964: }
2965: }
2966: }
2967: }
2968: }
2969: }
2970: #Check to see if we can change personal data for the user
2971: my (@mod_disallowed,@longroles);
2972: foreach my $role (@userroles) {
2973: if ($role eq 'cr') {
2974: push(@longroles,'Custom');
2975: } else {
2976: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
2977: }
2978: }
2979: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
2980: foreach my $item (@userinfo) {
2981: # Strip leading and trailing whitespace
2982: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
2983: if (!$canmodify{$item}) {
2984: if (defined($env{'form.c'.$item})) {
2985: if ($env{'form.c'.$item} ne $userenv{$item}) {
2986: push(@mod_disallowed,$item);
2987: }
2988: }
2989: $env{'form.c'.$item} = $userenv{$item};
2990: }
2991: }
2992: # Check to see if we can change the Student/Employee ID
2993: my $forceid = $env{'form.forceid'};
2994: my $recurseid = $env{'form.recurseid'};
2995: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
2996: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
2997: $env{'form.ccuname'});
2998: if (($uidhash{$env{'form.ccuname'}}) &&
2999: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3000: (!$forceid)) {
3001: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3002: $env{'form.cid'} = $userenv{'id'};
3003: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
3004: .'<br />'
3005: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3006: .'<br />'."\n";
3007: }
3008: }
3009: if ($env{'form.cid'} ne $userenv{'id'}) {
3010: my $checkhash;
3011: my $checks = { 'id' => 1 };
3012: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3013: { 'newuser' => $newuser,
3014: 'id' => $env{'form.cid'},
3015: };
3016: &Apache::loncommon::user_rule_check($checkhash,$checks,
3017: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3018: if (ref($alerts{'id'}) eq 'HASH') {
3019: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
3020: $env{'form.cid'} = $userenv{'id'};
3021: }
3022: }
3023: }
3024: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3025: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
3026: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
3027: %oldsettingstatus,%newsettingstatus);
3028: @disporder = ('inststatus');
3029: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
3030: push(@disporder,'requestcourses','requestauthor');
3031: } else {
3032: push(@disporder,'reqcrsotherdom');
3033: }
3034: push(@disporder,('quota','tools'));
3035: $oldinststatus = $userenv{'inststatus'};
3036: foreach my $name ('portfolio','author') {
3037: ($olddefquota{$name},$oldsettingstatus{$name}) =
3038: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3039: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3040: }
3041: my %canshow;
3042: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
3043: $canshow{'quota'} = 1;
3044: }
3045: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
3046: $canshow{'tools'} = 1;
3047: }
3048: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
3049: $canshow{'requestcourses'} = 1;
3050: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
3051: $canshow{'reqcrsotherdom'} = 1;
3052: }
3053: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
3054: $canshow{'inststatus'} = 1;
3055: }
3056: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3057: $canshow{'requestauthor'} = 1;
3058: }
3059: my (%changeHash,%changed);
3060: if ($oldinststatus eq '') {
3061: $oldsettings{'inststatus'} = $othertitle;
3062: } else {
3063: if (ref($usertypes) eq 'HASH') {
3064: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
3065: } else {
3066: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
3067: }
3068: }
3069: $changeHash{'inststatus'} = $userenv{'inststatus'};
3070: if ($canmodify_status{'inststatus'}) {
3071: $canshow{'inststatus'} = 1;
3072: if (exists($env{'form.inststatus'})) {
3073: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3074: if (@inststatuses > 0) {
3075: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3076: $changeHash{'inststatus'} = $newinststatus;
3077: if ($newinststatus ne $oldinststatus) {
3078: $changed{'inststatus'} = $newinststatus;
3079: foreach my $name ('portfolio','author') {
3080: ($newdefquota{$name},$newsettingstatus{$name}) =
3081: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3082: }
3083: }
3084: if (ref($usertypes) eq 'HASH') {
3085: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
3086: } else {
3087: $newsettings{'inststatus'} = join(', ',@inststatuses);
3088: }
3089: }
3090: } else {
3091: $newinststatus = '';
3092: $changeHash{'inststatus'} = $newinststatus;
3093: $newsettings{'inststatus'} = $othertitle;
3094: if ($newinststatus ne $oldinststatus) {
3095: $changed{'inststatus'} = $changeHash{'inststatus'};
3096: foreach my $name ('portfolio','author') {
3097: ($newdefquota{$name},$newsettingstatus{$name}) =
3098: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3099: }
3100: }
3101: }
3102: } elsif ($context ne 'selfcreate') {
3103: $canshow{'inststatus'} = 1;
3104: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
3105: }
3106: foreach my $name ('portfolio','author') {
3107: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3108: }
3109: if ($context eq 'domain') {
3110: foreach my $name ('portfolio','author') {
3111: if ($userenv{$name.'quota'} ne '') {
3112: $oldquota{$name} = $userenv{$name.'quota'};
3113: if ($env{'form.custom_'.$name.'quota'} == 1) {
3114: if ($env{'form.'.$name.'quota'} eq '') {
3115: $newquota{$name} = 0;
3116: } else {
3117: $newquota{$name} = $env{'form.'.$name.'quota'};
3118: $newquota{$name} =~ s/[^\d\.]//g;
3119: }
3120: if ($newquota{$name} != $oldquota{$name}) {
3121: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3122: $changed{$name.'quota'} = 1;
3123: }
3124: }
3125: } else {
3126: if ("a_admin('',\%changeHash,$name)) {
3127: $changed{$name.'quota'} = 1;
3128: $newquota{$name} = $newdefquota{$name};
3129: $newisdefault{$name} = 1;
3130: }
3131: }
3132: } else {
3133: $oldisdefault{$name} = 1;
3134: $oldquota{$name} = $olddefquota{$name};
3135: if ($env{'form.custom_'.$name.'quota'} == 1) {
3136: if ($env{'form.'.$name.'quota'} eq '') {
3137: $newquota{$name} = 0;
3138: } else {
3139: $newquota{$name} = $env{'form.'.$name.'quota'};
3140: $newquota{$name} =~ s/[^\d\.]//g;
3141: }
3142: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3143: $changed{$name.'quota'} = 1;
3144: }
3145: } else {
3146: $newquota{$name} = $newdefquota{$name};
3147: $newisdefault{$name} = 1;
3148: }
3149: }
3150: if ($oldisdefault{$name}) {
3151: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
3152: } else {
3153: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
3154: }
3155: if ($newisdefault{$name}) {
3156: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
3157: } else {
3158: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
3159: }
3160: }
3161: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3162: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3163: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3164: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3165: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3166: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3167: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3168: } else {
3169: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3170: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3171: }
3172: }
3173: foreach my $item (@userinfo) {
3174: if ($env{'form.c'.$item} ne $userenv{$item}) {
3175: $namechanged{$item} = 1;
3176: }
3177: }
3178: foreach my $name ('portfolio','author') {
3179: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3180: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
3181: }
3182: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
3183: my ($chgresult,$namechgresult);
3184: if (keys(%changed) > 0) {
3185: $chgresult =
3186: &Apache::lonnet::put('environment',\%changeHash,
3187: $env{'form.ccdomain'},$env{'form.ccuname'});
3188: if ($chgresult eq 'ok') {
3189: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3190: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
3191: my %newenvhash;
3192: foreach my $key (keys(%changed)) {
3193: if (($key eq 'official') || ($key eq 'unofficial')
3194: || ($key eq 'community') || ($key eq 'textbook')) {
3195: $newenvhash{'environment.requestcourses.'.$key} =
3196: $changeHash{'requestcourses.'.$key};
3197: if ($changeHash{'requestcourses.'.$key}) {
3198: $newenvhash{'environment.canrequest.'.$key} = 1;
3199: } else {
3200: $newenvhash{'environment.canrequest.'.$key} =
3201: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3202: $key,'reload','requestcourses');
3203: }
3204: } elsif ($key eq 'requestauthor') {
3205: $newenvhash{'environment.'.$key} = $changeHash{$key};
3206: if ($changeHash{$key}) {
3207: $newenvhash{'environment.canrequest.author'} = 1;
3208: } else {
3209: $newenvhash{'environment.canrequest.author'} =
3210: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3211: $key,'reload','requestauthor');
3212: }
3213: } elsif ($key ne 'quota') {
3214: $newenvhash{'environment.tools.'.$key} =
3215: $changeHash{'tools.'.$key};
3216: if ($changeHash{'tools.'.$key} ne '') {
3217: $newenvhash{'environment.availabletools.'.$key} =
3218: $changeHash{'tools.'.$key};
3219: } else {
3220: $newenvhash{'environment.availabletools.'.$key} =
3221: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3222: $key,'reload','tools');
3223: }
3224: }
3225: }
3226: if (keys(%newenvhash)) {
3227: &Apache::lonnet::appenv(\%newenvhash);
3228: }
3229: }
3230: }
3231: }
3232: if (keys(%namechanged) > 0) {
3233: foreach my $field (@userinfo) {
3234: $changeHash{$field} = $env{'form.c'.$field};
3235: }
3236: # Make the change
3237: $namechgresult =
3238: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3239: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3240: $changeHash{'firstname'},$changeHash{'middlename'},
3241: $changeHash{'lastname'},$changeHash{'generation'},
3242: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
3243: %userupdate = (
3244: lastname => $env{'form.clastname'},
3245: middlename => $env{'form.cmiddlename'},
3246: firstname => $env{'form.cfirstname'},
3247: generation => $env{'form.cgeneration'},
3248: id => $env{'form.cid'},
3249: );
3250: }
3251: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
3252: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
3253: # Tell the user we changed the name
3254: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
3255: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
3256: \%oldsettings, \%oldsettingstext,\%newsettings,
3257: \%newsettingstext);
3258: if ($env{'form.cid'} ne $userenv{'id'}) {
3259: &Apache::lonnet::idput($env{'form.ccdomain'},
3260: {$env{'form.ccuname'} => $env{'form.cid'}});
3261: if (($recurseid) &&
3262: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3263: my $idresult =
3264: &Apache::lonuserutils::propagate_id_change(
3265: $env{'form.ccuname'},$env{'form.ccdomain'},
3266: \%userupdate);
3267: $r->print('<br />'.$idresult.'<br />');
3268: }
3269: }
3270: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3271: ($env{'form.ccuname'} eq $env{'user.name'})) {
3272: my %newenvhash;
3273: foreach my $key (keys(%changeHash)) {
3274: $newenvhash{'environment.'.$key} = $changeHash{$key};
3275: }
3276: &Apache::lonnet::appenv(\%newenvhash);
3277: }
3278: } else { # error occurred
3279: $r->print(
3280: '<p class="LC_error">'
3281: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3282: '"'.$env{'form.ccuname'}.'"',
3283: '"'.$env{'form.ccdomain'}.'"')
3284: .'</p>');
3285: }
3286: } else { # End of if ($env ... ) logic
3287: # They did not want to change the users name, quota, tool availability,
3288: # or ability to request creation of courses,
3289: # but we can still tell them what the name and quota and availabilities are
3290: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
3291: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
3292: \%oldsettingstext,\%newsettings,\%newsettingstext);
3293: }
3294: if (@mod_disallowed) {
3295: my ($rolestr,$contextname);
3296: if (@longroles > 0) {
3297: $rolestr = join(', ',@longroles);
3298: } else {
3299: $rolestr = &mt('No roles');
3300: }
3301: if ($context eq 'course') {
3302: $contextname = 'course';
3303: } elsif ($context eq 'author') {
3304: $contextname = 'co-author';
3305: }
3306: $r->print(&mt('The following fields were not updated: ').'<ul>');
3307: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3308: foreach my $field (@mod_disallowed) {
3309: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3310: }
3311: $r->print('</ul>');
3312: if (@mod_disallowed == 1) {
3313: $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future $contextname roles:"));
3314: } else {
3315: $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future $contextname roles:"));
3316: }
3317: my $helplink = 'javascript:helpMenu('."'display'".')';
3318: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3319: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3320: ,'<a href="'.$helplink.'">','</a>')
3321: .'<br />');
3322: }
3323: $r->print('<span class="LC_warning">'
3324: .$no_forceid_alert
3325: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3326: .'</span>');
3327: }
3328: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
3329: if ($env{'form.action'} eq 'singlestudent') {
3330: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3331: $crstype,$showcredits,$defaultcredits);
3332: my $linktext = ($crstype eq 'Community' ?
3333: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3334: $r->print(
3335: &Apache::lonhtmlcommon::actionbox([
3336: '<a href="javascript:backPage(document.userupdate)">'
3337: .($crstype eq 'Community' ?
3338: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3339: .'</a>']));
3340: } else {
3341: my @rolechanges = &update_roles($r,$context,$showcredits);
3342: if (keys(%namechanged) > 0) {
3343: if ($context eq 'course') {
3344: if (@userroles > 0) {
3345: if ((@rolechanges == 0) ||
3346: (!(grep(/^st$/,@rolechanges)))) {
3347: if (grep(/^st$/,@userroles)) {
3348: my $classlistupdated =
3349: &Apache::lonuserutils::update_classlist($cdom,
3350: $cnum,$env{'form.ccdomain'},
3351: $env{'form.ccuname'},\%userupdate);
3352: }
3353: }
3354: }
3355: }
3356: }
3357: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
3358: $env{'form.ccdomain'});
3359: if ($env{'form.popup'}) {
3360: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3361: } else {
3362: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3363: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3364: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
3365: }
3366: }
3367: }
3368:
3369: sub display_userinfo {
3370: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3371: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
3372: $newsetting,$newsettingtext) = @_;
3373: return unless (ref($order) eq 'ARRAY' &&
3374: ref($canshow) eq 'HASH' &&
3375: ref($requestcourses) eq 'ARRAY' &&
3376: ref($requestauthor) eq 'ARRAY' &&
3377: ref($usertools) eq 'ARRAY' &&
3378: ref($userenv) eq 'HASH' &&
3379: ref($changedhash) eq 'HASH' &&
3380: ref($oldsetting) eq 'HASH' &&
3381: ref($oldsettingtext) eq 'HASH' &&
3382: ref($newsetting) eq 'HASH' &&
3383: ref($newsettingtext) eq 'HASH');
3384: my %lt=&Apache::lonlocal::texthash(
3385: 'ui' => 'User Information',
3386: 'uic' => 'User Information Changed',
3387: 'firstname' => 'First Name',
3388: 'middlename' => 'Middle Name',
3389: 'lastname' => 'Last Name',
3390: 'generation' => 'Generation',
3391: 'id' => 'Student/Employee ID',
3392: 'permanentemail' => 'Permanent e-mail address',
3393: 'portfolioquota' => 'Disk space allocated to portfolio files',
3394: 'authorquota' => 'Disk space allocated to Authoring Space',
3395: 'blog' => 'Blog Availability',
3396: 'webdav' => 'WebDAV Availability',
3397: 'aboutme' => 'Personal Information Page Availability',
3398: 'portfolio' => 'Portfolio Availability',
3399: 'official' => 'Can Request Official Courses',
3400: 'unofficial' => 'Can Request Unofficial Courses',
3401: 'community' => 'Can Request Communities',
3402: 'textbook' => 'Can Request Textbook Courses',
3403: 'requestauthor' => 'Can Request Author Role',
3404: 'inststatus' => "Affiliation",
3405: 'prvs' => 'Previous Value:',
3406: 'chto' => 'Changed To:'
3407: );
3408: if ($changed) {
3409: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
3410: &Apache::loncommon::start_data_table().
3411: &Apache::loncommon::start_data_table_header_row());
3412: $r->print("<th> </th>\n");
3413: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3414: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3415: $r->print(&Apache::loncommon::end_data_table_header_row());
3416: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3417:
3418: foreach my $item (@userinfo) {
3419: my $value = $env{'form.c'.$item};
3420: #show changes only:
3421: unless ($value eq $userenv->{$item}){
3422: $r->print(&Apache::loncommon::start_data_table_row());
3423: $r->print("<td>$lt{$item}</td>\n");
3424: $r->print("<td>".$userenv->{$item}."</td>\n");
3425: $r->print("<td>$value </td>\n");
3426: $r->print(&Apache::loncommon::end_data_table_row());
3427: }
3428: }
3429: foreach my $entry (@{$order}) {
3430: if ($canshow->{$entry}) {
3431: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3432: my @items;
3433: if ($entry eq 'requestauthor') {
3434: @items = ($entry);
3435: } else {
3436: @items = @{$requestcourses};
3437: }
3438: foreach my $item (@items) {
3439: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3440: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3441: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3442: $r->print("<td>$lt{$item}</td>\n");
3443: $r->print("<td>".$oldsetting->{$item});
3444: if ($oldsettingtext->{$item}) {
3445: if ($oldsetting->{$item}) {
3446: $r->print(' -- ');
3447: }
3448: $r->print($oldsettingtext->{$item});
3449: }
3450: $r->print("</td>\n");
3451: $r->print("<td>".$newsetting->{$item});
3452: if ($newsettingtext->{$item}) {
3453: if ($newsetting->{$item}) {
3454: $r->print(' -- ');
3455: }
3456: $r->print($newsettingtext->{$item});
3457: }
3458: $r->print("</td>\n");
3459: $r->print(&Apache::loncommon::end_data_table_row()."\n");
3460: }
3461: }
3462: } elsif ($entry eq 'tools') {
3463: foreach my $item (@{$usertools}) {
3464: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3465: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3466: $r->print("<td>$lt{$item}</td>\n");
3467: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3468: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3469: $r->print(&Apache::loncommon::end_data_table_row()."\n");
3470: }
3471: }
3472: } elsif ($entry eq 'quota') {
3473: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3474: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3475: foreach my $name ('portfolio','author') {
3476: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3477: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3478: $r->print("<td>$lt{$name.$entry}</td>\n");
3479: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3480: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3481: $r->print(&Apache::loncommon::end_data_table_row()."\n");
3482: }
3483: }
3484: }
3485: } else {
3486: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3487: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3488: $r->print("<td>$lt{$entry}</td>\n");
3489: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3490: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3491: $r->print(&Apache::loncommon::end_data_table_row()."\n");
3492: }
3493: }
3494: }
3495: }
3496: $r->print(&Apache::loncommon::end_data_table().'<br />');
3497: } else {
3498: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3499: '<p>'.&mt('No changes made to user information').'</p>');
3500: }
3501: return;
3502: }
3503:
3504: sub tool_changes {
3505: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3506: $changed,$newaccess,$newaccesstext) = @_;
3507: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3508: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3509: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3510: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3511: return;
3512: }
3513: my %reqdisplay = &requestchange_display();
3514: if ($context eq 'reqcrsotherdom') {
3515: my @options = ('approval','validate','autolimit');
3516: my $optregex = join('|',@options);
3517: my $cdom = $env{'request.role.domain'};
3518: foreach my $tool (@{$usertools}) {
3519: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3520: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3521: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
3522: my ($newop,$limit);
3523: if ($env{'form.'.$context.'_'.$tool}) {
3524: $newop = $env{'form.'.$context.'_'.$tool};
3525: if ($newop eq 'autolimit') {
3526: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3527: $limit =~ s/\D+//g;
3528: $newop .= '='.$limit;
3529: }
3530: }
3531: if ($userenv->{$context.'.'.$tool} eq '') {
3532: if ($newop) {
3533: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
3534: $changeHash,$context);
3535: if ($changed->{$tool}) {
3536: if ($newop =~ /^autolimit/) {
3537: if ($limit) {
3538: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3539: } else {
3540: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3541: }
3542: } else {
3543: $newaccesstext->{$tool} = $reqdisplay{$newop};
3544: }
3545: } else {
3546: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3547: }
3548: }
3549: } else {
3550: my @curr = split(',',$userenv->{$context.'.'.$tool});
3551: my @new;
3552: my $changedoms;
3553: foreach my $req (@curr) {
3554: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3555: my $oldop = $1;
3556: if ($oldop =~ /^autolimit=(\d*)/) {
3557: my $limit = $1;
3558: if ($limit) {
3559: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3560: } else {
3561: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3562: }
3563: } else {
3564: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3565: }
3566: if ($oldop ne $newop) {
3567: $changedoms = 1;
3568: foreach my $item (@curr) {
3569: my ($reqdom,$option) = split(':',$item);
3570: unless ($reqdom eq $cdom) {
3571: push(@new,$item);
3572: }
3573: }
3574: if ($newop) {
3575: push(@new,$cdom.':'.$newop);
3576: }
3577: @new = sort(@new);
3578: }
3579: last;
3580: }
3581: }
3582: if ((!$changedoms) && ($newop)) {
3583: $changedoms = 1;
3584: @new = sort(@curr,$cdom.':'.$newop);
3585: }
3586: if ($changedoms) {
3587: my $newdomstr;
3588: if (@new) {
3589: $newdomstr = join(',',@new);
3590: }
3591: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3592: $context);
3593: if ($changed->{$tool}) {
3594: if ($env{'form.'.$context.'_'.$tool}) {
3595: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
3596: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3597: $limit =~ s/\D+//g;
3598: if ($limit) {
3599: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3600: } else {
3601: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3602: }
3603: } else {
3604: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3605: }
3606: } else {
3607: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3608: }
3609: }
3610: }
3611: }
3612: }
3613: return;
3614: }
3615: foreach my $tool (@{$usertools}) {
3616: my ($newval,$limit,$envkey);
3617: $envkey = $context.'.'.$tool;
3618: if ($context eq 'requestcourses') {
3619: $newval = $env{'form.crsreq_'.$tool};
3620: if ($newval eq 'autolimit') {
3621: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3622: $limit =~ s/\D+//g;
3623: $newval .= '='.$limit;
3624: }
3625: } elsif ($context eq 'requestauthor') {
3626: $newval = $env{'form.'.$context};
3627: $envkey = $context;
3628: } else {
3629: $newval = $env{'form.'.$context.'_'.$tool};
3630: }
3631: if ($userenv->{$envkey} ne '') {
3632: $oldaccess->{$tool} = &mt('custom');
3633: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3634: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3635: my $currlimit = $1;
3636: if ($currlimit eq '') {
3637: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3638: } else {
3639: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3640: }
3641: } elsif ($userenv->{$envkey}) {
3642: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3643: } else {
3644: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3645: }
3646: } else {
3647: if ($userenv->{$envkey}) {
3648: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3649: } else {
3650: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3651: }
3652: }
3653: $changeHash->{$envkey} = $userenv->{$envkey};
3654: if ($env{'form.custom'.$tool} == 1) {
3655: if ($newval ne $userenv->{$envkey}) {
3656: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3657: $context);
3658: if ($changed->{$tool}) {
3659: $newaccess->{$tool} = &mt('custom');
3660: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3661: if ($newval =~ /^autolimit/) {
3662: if ($limit) {
3663: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3664: } else {
3665: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3666: }
3667: } elsif ($newval) {
3668: $newaccesstext->{$tool} = $reqdisplay{$newval};
3669: } else {
3670: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3671: }
3672: } else {
3673: if ($newval) {
3674: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3675: } else {
3676: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3677: }
3678: }
3679: } else {
3680: $newaccess->{$tool} = $oldaccess->{$tool};
3681: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3682: if ($newval =~ /^autolimit/) {
3683: if ($limit) {
3684: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3685: } else {
3686: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3687: }
3688: } elsif ($newval) {
3689: $newaccesstext->{$tool} = $reqdisplay{$newval};
3690: } else {
3691: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3692: }
3693: } else {
3694: if ($userenv->{$context.'.'.$tool}) {
3695: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3696: } else {
3697: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3698: }
3699: }
3700: }
3701: } else {
3702: $newaccess->{$tool} = $oldaccess->{$tool};
3703: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3704: }
3705: } else {
3706: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3707: if ($changed->{$tool}) {
3708: $newaccess->{$tool} = &mt('default');
3709: } else {
3710: $newaccess->{$tool} = $oldaccess->{$tool};
3711: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3712: if ($newval =~ /^autolimit/) {
3713: if ($limit) {
3714: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3715: } else {
3716: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3717: }
3718: } elsif ($newval) {
3719: $newaccesstext->{$tool} = $reqdisplay{$newval};
3720: } else {
3721: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3722: }
3723: } else {
3724: if ($userenv->{$context.'.'.$tool}) {
3725: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3726: } else {
3727: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3728: }
3729: }
3730: }
3731: }
3732: } else {
3733: $oldaccess->{$tool} = &mt('default');
3734: if ($env{'form.custom'.$tool} == 1) {
3735: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3736: $context);
3737: if ($changed->{$tool}) {
3738: $newaccess->{$tool} = &mt('custom');
3739: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3740: if ($newval =~ /^autolimit/) {
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: } elsif ($newval) {
3747: $newaccesstext->{$tool} = $reqdisplay{$newval};
3748: } else {
3749: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3750: }
3751: } else {
3752: if ($newval) {
3753: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3754: } else {
3755: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3756: }
3757: }
3758: } else {
3759: $newaccess->{$tool} = $oldaccess->{$tool};
3760: }
3761: } else {
3762: $newaccess->{$tool} = $oldaccess->{$tool};
3763: }
3764: }
3765: }
3766: return;
3767: }
3768:
3769: sub update_roles {
3770: my ($r,$context,$showcredits) = @_;
3771: my $now=time;
3772: my @rolechanges;
3773: my %disallowed;
3774: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
3775: foreach my $key (keys(%env)) {
3776: next if (! $env{$key});
3777: next if ($key eq 'form.action');
3778: # Revoke roles
3779: if ($key=~/^form\.rev/) {
3780: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
3781: # Revoke standard role
3782: my ($scope,$role) = ($1,$2);
3783: my $result =
3784: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3785: $env{'form.ccuname'},
3786: $scope,$role,'','',$context);
3787: $r->print(&Apache::lonhtmlcommon::confirm_success(
3788: &mt('Revoking [_1] in [_2]',
3789: &Apache::lonnet::plaintext($role),
3790: &Apache::loncommon::show_role_extent($scope,$context,$role)),
3791: $result ne "ok").'<br />');
3792: if ($result ne "ok") {
3793: $r->print(&mt('Error: [_1]',$result).'<br />');
3794: }
3795: if ($role eq 'st') {
3796: my $result =
3797: &Apache::lonuserutils::classlist_drop($scope,
3798: $env{'form.ccuname'},$env{'form.ccdomain'},
3799: $now);
3800: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
3801: }
3802: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3803: push(@rolechanges,$role);
3804: }
3805: }
3806: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
3807: # Revoke custom role
3808: my $result = &Apache::lonnet::revokecustomrole(
3809: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
3810: $r->print(&Apache::lonhtmlcommon::confirm_success(
3811: &mt('Revoking custom role [_1] by [_2] in [_3]',
3812: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
3813: $result ne 'ok').'<br />');
3814: if ($result ne "ok") {
3815: $r->print(&mt('Error: [_1]',$result).'<br />');
3816: }
3817: if (!grep(/^cr$/,@rolechanges)) {
3818: push(@rolechanges,'cr');
3819: }
3820: }
3821: } elsif ($key=~/^form\.del/) {
3822: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
3823: # Delete standard role
3824: my ($scope,$role) = ($1,$2);
3825: my $result =
3826: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3827: $env{'form.ccuname'},
3828: $scope,$role,$now,0,1,'',
3829: $context);
3830: $r->print(&Apache::lonhtmlcommon::confirm_success(
3831: &mt('Deleting [_1] in [_2]',
3832: &Apache::lonnet::plaintext($role),
3833: &Apache::loncommon::show_role_extent($scope,$context,$role)),
3834: $result ne 'ok').'<br />');
3835: if ($result ne "ok") {
3836: $r->print(&mt('Error: [_1]',$result).'<br />');
3837: }
3838:
3839: if ($role eq 'st') {
3840: my $result =
3841: &Apache::lonuserutils::classlist_drop($scope,
3842: $env{'form.ccuname'},$env{'form.ccdomain'},
3843: $now);
3844: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
3845: }
3846: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3847: push(@rolechanges,$role);
3848: }
3849: }
3850: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
3851: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3852: # Delete custom role
3853: my $result =
3854: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3855: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3856: 0,1,$context);
3857: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
3858: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
3859: $result ne "ok").'<br />');
3860: if ($result ne "ok") {
3861: $r->print(&mt('Error: [_1]',$result).'<br />');
3862: }
3863:
3864: if (!grep(/^cr$/,@rolechanges)) {
3865: push(@rolechanges,'cr');
3866: }
3867: }
3868: } elsif ($key=~/^form\.ren/) {
3869: my $udom = $env{'form.ccdomain'};
3870: my $uname = $env{'form.ccuname'};
3871: # Re-enable standard role
3872: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
3873: my $url = $1;
3874: my $role = $2;
3875: my $logmsg;
3876: my $output;
3877: if ($role eq 'st') {
3878: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
3879: my ($cdom,$cnum,$csec) = ($1,$2,$3);
3880: my $credits;
3881: if ($showcredits) {
3882: my $defaultcredits =
3883: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3884: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3885: }
3886: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
3887: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
3888: if ($result eq 'refused' && $logmsg) {
3889: $output = $logmsg;
3890: } else {
3891: $output = &mt('Error: [_1]',$result)."\n";
3892: }
3893: } else {
3894: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3895: &Apache::lonnet::plaintext($role),
3896: &Apache::loncommon::show_role_extent($url,$context,'st'),
3897: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
3898: }
3899: }
3900: } else {
3901: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
3902: $env{'form.ccuname'},$url,$role,0,$now,'','',
3903: $context);
3904: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
3905: &Apache::lonnet::plaintext($role),
3906: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
3907: if ($result ne "ok") {
3908: $output .= &mt('Error: [_1]',$result).'<br />';
3909: }
3910: }
3911: $r->print($output);
3912: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3913: push(@rolechanges,$role);
3914: }
3915: }
3916: # Re-enable custom role
3917: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
3918: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3919: my $result = &Apache::lonnet::assigncustomrole(
3920: $env{'form.ccdomain'}, $env{'form.ccuname'},
3921: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
3922: $r->print(&Apache::lonhtmlcommon::confirm_success(
3923: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
3924: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
3925: $result ne "ok").'<br />');
3926: if ($result ne "ok") {
3927: $r->print(&mt('Error: [_1]',$result).'<br />');
3928: }
3929: if (!grep(/^cr$/,@rolechanges)) {
3930: push(@rolechanges,'cr');
3931: }
3932: }
3933: } elsif ($key=~/^form\.act/) {
3934: my $udom = $env{'form.ccdomain'};
3935: my $uname = $env{'form.ccuname'};
3936: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
3937: # Activate a custom role
3938: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3939: my $url='/'.$one.'/'.$two;
3940: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
3941:
3942: my $start = ( $env{'form.start_'.$full} ?
3943: $env{'form.start_'.$full} :
3944: $now );
3945: my $end = ( $env{'form.end_'.$full} ?
3946: $env{'form.end_'.$full} :
3947: 0 );
3948:
3949: # split multiple sections
3950: my %sections = ();
3951: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
3952: if ($num_sections == 0) {
3953: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
3954: } else {
3955: my %curr_groups =
3956: &Apache::longroup::coursegroups($one,$two);
3957: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
3958: if (($sec eq 'none') || ($sec eq 'all') ||
3959: exists($curr_groups{$sec})) {
3960: $disallowed{$sec} = $url;
3961: next;
3962: }
3963: my $securl = $url.'/'.$sec;
3964: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
3965: }
3966: }
3967: if (!grep(/^cr$/,@rolechanges)) {
3968: push(@rolechanges,'cr');
3969: }
3970: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
3971: # Activate roles for sections with 3 id numbers
3972: # set start, end times, and the url for the class
3973: my ($one,$two,$three)=($1,$2,$3);
3974: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
3975: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
3976: $now );
3977: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
3978: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
3979: 0 );
3980: my $url='/'.$one.'/'.$two;
3981: my $type = 'three';
3982: # split multiple sections
3983: my %sections = ();
3984: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
3985: my $credits;
3986: if ($three eq 'st') {
3987: if ($showcredits) {
3988: my $defaultcredits =
3989: &Apache::lonuserutils::get_defaultcredits($one,$two);
3990: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
3991: $credits =~ s/[^\d\.]//g;
3992: if ($credits eq $defaultcredits) {
3993: undef($credits);
3994: }
3995: }
3996: }
3997: if ($num_sections == 0) {
3998: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
3999: } else {
4000: my %curr_groups =
4001: &Apache::longroup::coursegroups($one,$two);
4002: my $emptysec = 0;
4003: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
4004: $sec =~ s/\W//g;
4005: if ($sec ne '') {
4006: if (($sec eq 'none') || ($sec eq 'all') ||
4007: exists($curr_groups{$sec})) {
4008: $disallowed{$sec} = $url;
4009: next;
4010: }
4011: my $securl = $url.'/'.$sec;
4012: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
4013: } else {
4014: $emptysec = 1;
4015: }
4016: }
4017: if ($emptysec) {
4018: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
4019: }
4020: }
4021: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4022: push(@rolechanges,$three);
4023: }
4024: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
4025: # Activate roles for sections with two id numbers
4026: # set start, end times, and the url for the class
4027: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4028: $env{'form.start_'.$1.'_'.$2} :
4029: $now );
4030: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4031: $env{'form.end_'.$1.'_'.$2} :
4032: 0 );
4033: my $one = $1;
4034: my $two = $2;
4035: my $url='/'.$one.'/';
4036: # split multiple sections
4037: my %sections = ();
4038: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
4039: if ($num_sections == 0) {
4040: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
4041: } else {
4042: my $emptysec = 0;
4043: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
4044: if ($sec ne '') {
4045: my $securl = $url.'/'.$sec;
4046: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
4047: } else {
4048: $emptysec = 1;
4049: }
4050: }
4051: if ($emptysec) {
4052: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
4053: }
4054: }
4055: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4056: push(@rolechanges,$two);
4057: }
4058: } else {
4059: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
4060: }
4061: foreach my $key (sort(keys(%disallowed))) {
4062: $r->print('<p class="LC_warning">');
4063: if (($key eq 'none') || ($key eq 'all')) {
4064: $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.','<tt>'.$key.'</tt>'));
4065: } else {
4066: $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>'));
4067: }
4068: $r->print('</p><p>'
4069: .&mt('Please [_1]go back[_2] and choose a different section name.'
4070: ,'<a href="javascript:history.go(-1)'
4071: ,'</a>')
4072: .'</p><br />'
4073: );
4074: }
4075: }
4076: } # End of foreach (keys(%env))
4077: # Flush the course logs so reverse user roles immediately updated
4078: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
4079: if (@rolechanges == 0) {
4080: $r->print('<p>'.&mt('No roles to modify').'</p>');
4081: }
4082: return @rolechanges;
4083: }
4084:
4085: sub get_user_credits {
4086: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4087: if ($cdom eq '' || $cnum eq '') {
4088: return unless ($env{'request.course.id'});
4089: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4090: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4091: }
4092: my $credits;
4093: my %currhash =
4094: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4095: if (keys(%currhash) > 0) {
4096: my @items = split(/:/,$currhash{$uname.':'.$udom});
4097: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4098: $credits = $items[$crdidx];
4099: $credits =~ s/[^\d\.]//g;
4100: }
4101: if ($credits eq $defaultcredits) {
4102: undef($credits);
4103: }
4104: return $credits;
4105: }
4106:
4107: sub enroll_single_student {
4108: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4109: $showcredits,$defaultcredits) = @_;
4110: $r->print('<h3>');
4111: if ($crstype eq 'Community') {
4112: $r->print(&mt('Enrolling Member'));
4113: } else {
4114: $r->print(&mt('Enrolling Student'));
4115: }
4116: $r->print('</h3>');
4117:
4118: # Remove non alphanumeric values from section
4119: $env{'form.sections'}=~s/\W//g;
4120:
4121: my $credits;
4122: if (($showcredits) && ($env{'form.credits'} ne '')) {
4123: $credits = $env{'form.credits'};
4124: $credits =~ s/[^\d\.]//g;
4125: if ($credits ne '') {
4126: if ($credits eq $defaultcredits) {
4127: undef($credits);
4128: }
4129: }
4130: }
4131:
4132: # Clean out any old student roles the user has in this class.
4133: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4134: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4135: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4136: my $enroll_result =
4137: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4138: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4139: $env{'form.cmiddlename'},$env{'form.clastname'},
4140: $env{'form.generation'},$env{'form.sections'},$enddate,
4141: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4142: $credits);
4143: if ($enroll_result =~ /^ok/) {
4144: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
4145: if ($env{'form.sections'} ne '') {
4146: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4147: }
4148: my ($showstart,$showend);
4149: if ($startdate <= $now) {
4150: $showstart = &mt('Access starts immediately');
4151: } else {
4152: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4153: }
4154: if ($enddate == 0) {
4155: $showend = &mt('ends: no ending date');
4156: } else {
4157: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4158: }
4159: $r->print('.<br />'.$showstart.'; '.$showend);
4160: if ($startdate <= $now && !$newuser) {
4161: $r->print('<p class="LC_info">');
4162: if ($crstype eq 'Community') {
4163: $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.'));
4164: } else {
4165: $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.'));
4166: }
4167: $r->print('</p>');
4168: }
4169: } else {
4170: $r->print(&mt('unable to enroll').": ".$enroll_result);
4171: }
4172: return;
4173: }
4174:
4175: sub get_defaultquota_text {
4176: my ($settingstatus) = @_;
4177: my $defquotatext;
4178: if ($settingstatus eq '') {
4179: $defquotatext = &mt('default');
4180: } else {
4181: my ($usertypes,$order) =
4182: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4183: if ($usertypes->{$settingstatus} eq '') {
4184: $defquotatext = &mt('default');
4185: } else {
4186: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
4187: }
4188: }
4189: return $defquotatext;
4190: }
4191:
4192: sub update_result_form {
4193: my ($uhome) = @_;
4194: my $outcome =
4195: '<form name="userupdate" method="post" action="">'."\n";
4196: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
4197: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
4198: }
4199: if ($env{'form.origname'} ne '') {
4200: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4201: }
4202: foreach my $item ('sortby','seluname','seludom') {
4203: if (exists($env{'form.'.$item})) {
4204: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
4205: }
4206: }
4207: if ($uhome eq 'no_host') {
4208: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4209: }
4210: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
4211: '<input type="hidden" name="currstate" value="" />'."\n".
4212: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
4213: '</form>';
4214: return $outcome;
4215: }
4216:
4217: sub quota_admin {
4218: my ($setquota,$changeHash,$name) = @_;
4219: my $quotachanged;
4220: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4221: # Current user has quota modification privileges
4222: if (ref($changeHash) eq 'HASH') {
4223: $quotachanged = 1;
4224: $changeHash->{$name.'quota'} = $setquota;
4225: }
4226: }
4227: return $quotachanged;
4228: }
4229:
4230: sub tool_admin {
4231: my ($tool,$settool,$changeHash,$context) = @_;
4232: my $canchange = 0;
4233: if ($context eq 'requestcourses') {
4234: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4235: $canchange = 1;
4236: }
4237: } elsif ($context eq 'reqcrsotherdom') {
4238: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4239: $canchange = 1;
4240: }
4241: } elsif ($context eq 'requestauthor') {
4242: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4243: $canchange = 1;
4244: }
4245: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4246: # Current user has quota modification privileges
4247: $canchange = 1;
4248: }
4249: my $toolchanged;
4250: if ($canchange) {
4251: if (ref($changeHash) eq 'HASH') {
4252: $toolchanged = 1;
4253: if ($tool eq 'requestauthor') {
4254: $changeHash->{$context} = $settool;
4255: } else {
4256: $changeHash->{$context.'.'.$tool} = $settool;
4257: }
4258: }
4259: }
4260: return $toolchanged;
4261: }
4262:
4263: sub build_roles {
4264: my ($sectionstr,$sections,$role) = @_;
4265: my $num_sections = 0;
4266: if ($sectionstr=~ /,/) {
4267: my @secnums = split/,/,$sectionstr;
4268: if ($role eq 'st') {
4269: $secnums[0] =~ s/\W//g;
4270: $$sections{$secnums[0]} = 1;
4271: $num_sections = 1;
4272: } else {
4273: foreach my $sec (@secnums) {
4274: $sec =~ ~s/\W//g;
4275: if (!($sec eq "")) {
4276: if (exists($$sections{$sec})) {
4277: $$sections{$sec} ++;
4278: } else {
4279: $$sections{$sec} = 1;
4280: $num_sections ++;
4281: }
4282: }
4283: }
4284: }
4285: } else {
4286: $sectionstr=~s/\W//g;
4287: unless ($sectionstr eq '') {
4288: $$sections{$sectionstr} = 1;
4289: $num_sections ++;
4290: }
4291: }
4292:
4293: return $num_sections;
4294: }
4295:
4296: # ========================================================== Custom Role Editor
4297:
4298: sub custom_role_editor {
4299: my ($r,$brcrum,$prefix) = @_;
4300: my $action = $env{'form.customroleaction'};
4301: my $rolename;
4302: if ($action eq 'new') {
4303: $rolename=$env{'form.newrolename'};
4304: } else {
4305: $rolename=$env{'form.rolename'};
4306: }
4307:
4308: my ($crstype,$context);
4309: if ($env{'request.course.id'}) {
4310: $crstype = &Apache::loncommon::course_type();
4311: $context = 'course';
4312: } else {
4313: $context = 'domain';
4314: $crstype = 'course';
4315: }
4316:
4317: $rolename=~s/[^A-Za-z0-9]//gs;
4318: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
4319: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
4320: return;
4321: }
4322:
4323: my $formname = 'form1';
4324: my %privs=();
4325: my $body_top = '<h2>';
4326: # ------------------------------------------------------- Does this role exist?
4327: my ($rdummy,$roledef)=
4328: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4329: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
4330: $body_top .= &mt('Existing Role').' "';
4331: # ------------------------------------------------- Get current role privileges
4332: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4333: if ($privs{'system'} =~ /bre\&S/) {
4334: if ($context eq 'domain') {
4335: $crstype = 'Course';
4336: } elsif ($crstype eq 'Community') {
4337: $privs{'system'} =~ s/bre\&S//;
4338: }
4339: } elsif ($context eq 'domain') {
4340: $crstype = 'Course';
4341: }
4342: } else {
4343: $body_top .= &mt('New Role').' "';
4344: $roledef='';
4345: }
4346: $body_top .= $rolename.'"</h2>';
4347:
4348: # ------------------------------------------------------- What can be assigned?
4349: my %full=();
4350: my %levels=(
4351: course => {},
4352: domain => {},
4353: system => {},
4354: );
4355: my %levelscurrent=(
4356: course => {},
4357: domain => {},
4358: system => {},
4359: );
4360: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4361: my ($jsback,$elements) = &crumb_utilities();
4362: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4363: my $head_script =
4364: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4365: \%full,\@templateroles,$jsback);
4366: push (@{$brcrum},
4367: {href => "javascript:backPage(document.$formname,'pickrole','')",
4368: text => "Pick custom role",
4369: faq => 282,bug=>'Instructor Interface',},
4370: {href => "javascript:backPage(document.$formname,'','')",
4371: text => "Edit custom role",
4372: faq => 282,
4373: bug => 'Instructor Interface',
4374: help => 'Course_Editing_Custom_Roles'}
4375: );
4376: my $args = { bread_crumbs => $brcrum,
4377: bread_crumbs_component => 'User Management'};
4378:
4379: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4380: $head_script,$args).
4381: $body_top);
4382: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4383: &Apache::lonuserutils::custom_role_header($context,$crstype,
4384: \@templateroles,$prefix));
4385:
4386: $r->print(<<ENDCCF);
4387: <input type="hidden" name="phase" value="set_custom_roles" />
4388: <input type="hidden" name="rolename" value="$rolename" />
4389: ENDCCF
4390: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4391: \%levelscurrent,$prefix));
4392: $r->print(&Apache::loncommon::end_data_table().
4393: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
4394: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
4395: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
4396: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
4397: '<input type="submit" value="'.&mt('Save').'" /></form>');
4398: }
4399:
4400: # ---------------------------------------------------------- Call to definerole
4401: sub set_custom_role {
4402: my ($r,$context,$brcrum,$prefix) = @_;
4403: my $rolename=$env{'form.rolename'};
4404: $rolename=~s/[^A-Za-z0-9]//gs;
4405: if (!$rolename) {
4406: &custom_role_editor($r,$brcrum,$prefix);
4407: return;
4408: }
4409: my ($jsback,$elements) = &crumb_utilities();
4410: my $jscript = '<script type="text/javascript">'
4411: .'// <![CDATA['."\n"
4412: .$jsback."\n"
4413: .'// ]]>'."\n"
4414: .'</script>'."\n";
4415: push(@{$brcrum},
4416: {href => "javascript:backPage(document.customresult,'pickrole','')",
4417: text => "Pick custom role",
4418: faq => 282,
4419: bug => 'Instructor Interface',},
4420: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4421: text => "Edit custom role",
4422: faq => 282,
4423: bug => 'Instructor Interface',},
4424: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4425: text => "Result",
4426: faq => 282,
4427: bug => 'Instructor Interface',
4428: help => 'Course_Editing_Custom_Roles'},
4429: );
4430: my $args = { bread_crumbs => $brcrum,
4431: bread_crumbs_component => 'User Management'};
4432: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
4433:
4434: my $newrole;
4435: my ($rdummy,$roledef)=
4436: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4437:
4438: # ------------------------------------------------------- Does this role exist?
4439: $r->print('<h3>');
4440: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
4441: $r->print(&mt('Existing Role').' "');
4442: } else {
4443: $r->print(&mt('New Role').' "');
4444: $roledef='';
4445: $newrole = 1;
4446: }
4447: $r->print($rolename.'"</h3>');
4448: # ------------------------------------------------- Assign role and show result
4449:
4450: my $errmsg;
4451: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4452: # Assign role and return result
4453: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4454: $newprivs{'c'});
4455: if ($result ne 'ok') {
4456: $errmsg = ': '.$result;
4457: }
4458: my $message =
4459: &Apache::lonhtmlcommon::confirm_success(
4460: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
4461: if ($env{'request.course.id'}) {
4462: my $url='/'.$env{'request.course.id'};
4463: $url=~s/\_/\//g;
4464: $result =
4465: &Apache::lonnet::assigncustomrole(
4466: $env{'user.domain'},$env{'user.name'},
4467: $url,
4468: $env{'user.domain'},$env{'user.name'},
4469: $rolename,undef,undef,undef,$context);
4470: if ($result ne 'ok') {
4471: $errmsg = ': '.$result;
4472: }
4473: $message .=
4474: '<br />'
4475: .&Apache::lonhtmlcommon::confirm_success(
4476: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
4477: }
4478: $r->print(
4479: &Apache::loncommon::confirmwrapper($message)
4480: .'<br />'
4481: .&Apache::lonhtmlcommon::actionbox([
4482: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4483: .&mt('Create or edit another custom role')
4484: .'</a>'])
4485: .'<form name="customresult" method="post" action="">'
4486: .&Apache::lonhtmlcommon::echo_form_input([])
4487: .'</form>'
4488: );
4489: }
4490:
4491: # ================================================================ Main Handler
4492: sub handler {
4493: my $r = shift;
4494: if ($r->header_only) {
4495: &Apache::loncommon::content_type($r,'text/html');
4496: $r->send_http_header;
4497: return OK;
4498: }
4499: my ($context,$crstype);
4500: if ($env{'request.course.id'}) {
4501: $context = 'course';
4502: $crstype = &Apache::loncommon::course_type();
4503: } elsif ($env{'request.role'} =~ /^au\./) {
4504: $context = 'author';
4505: } else {
4506: $context = 'domain';
4507: }
4508:
4509: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
4510: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
4511: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
4512: &Apache::lonhtmlcommon::clear_breadcrumbs();
4513: my $args;
4514: my $brcrum = [];
4515: my $bread_crumbs_component = 'User Management';
4516: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
4517: $brcrum = [{href=>"/adm/createuser",
4518: text=>"User Management",
4519: help=>'Course_Create_Class_List,Course_Change_Privileges,Course_View_Class_List,Course_Editing_Custom_Roles,Course_Add_Student,Course_Drop_Student,Course_Automated_Enrollment,Course_Self_Enrollment,Course_Manage_Group'}
4520: ];
4521: }
4522: #SD Following files not added to help, because the corresponding .tex-files seem to
4523: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
4524: my ($permission,$allowed) =
4525: &Apache::lonuserutils::get_permission($context,$crstype);
4526: if (!$allowed) {
4527: if ($context eq 'course') {
4528: $r->internal_redirect('/adm/viewclasslist');
4529: return OK;
4530: }
4531: $env{'user.error.msg'}=
4532: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4533: "or view user status.";
4534: return HTTP_NOT_ACCEPTABLE;
4535: }
4536:
4537: &Apache::loncommon::content_type($r,'text/html');
4538: $r->send_http_header;
4539:
4540: my $showcredits;
4541: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4542: ($context eq 'domain')) {
4543: my %domdefaults =
4544: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4545: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4546: $showcredits = 1;
4547: }
4548: }
4549:
4550: # Main switch on form.action and form.state, as appropriate
4551: if (! exists($env{'form.action'})) {
4552: $args = {bread_crumbs => $brcrum,
4553: bread_crumbs_component => $bread_crumbs_component};
4554: $r->print(&header(undef,$args));
4555: $r->print(&print_main_menu($permission,$context,$crstype));
4556: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
4557: push(@{$brcrum},
4558: { href => '/adm/createuser?action=upload&state=',
4559: text => 'Upload Users List',
4560: help => 'Course_Create_Class_List',
4561: });
4562: $bread_crumbs_component = 'Upload Users List';
4563: $args = {bread_crumbs => $brcrum,
4564: bread_crumbs_component => $bread_crumbs_component};
4565: $r->print(&header(undef,$args));
4566: $r->print('<form name="studentform" method="post" '.
4567: 'enctype="multipart/form-data" '.
4568: ' action="/adm/createuser">'."\n");
4569: if (! exists($env{'form.state'})) {
4570: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4571: } elsif ($env{'form.state'} eq 'got_file') {
4572: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4573: $crstype,$showcredits);
4574: } elsif ($env{'form.state'} eq 'enrolling') {
4575: if ($env{'form.datatoken'}) {
4576: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4577: $showcredits);
4578: }
4579: } else {
4580: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4581: }
4582: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4583: eq 'singlestudent')) && ($permission->{'cusr'})) ||
4584: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
4585: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
4586: my $phase = $env{'form.phase'};
4587: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
4588: &Apache::loncreateuser::restore_prev_selections();
4589: my $srch;
4590: foreach my $item (@search) {
4591: $srch->{$item} = $env{'form.'.$item};
4592: }
4593: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
4594: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
4595: if ($env{'form.phase'} eq 'createnewuser') {
4596: my $response;
4597: if ($env{'form.srchterm'} !~ /^$match_username$/) {
4598: my $response =
4599: '<span class="LC_warning">'
4600: .&mt('You must specify a valid username. Only the following are allowed:'
4601: .' letters numbers - . @')
4602: .'</span>';
4603: $env{'form.phase'} = '';
4604: &print_username_entry_form($r,$context,$response,$srch,undef,
4605: $crstype,$brcrum,$showcredits);
4606: } else {
4607: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4608: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4609: &print_user_modification_page($r,$ccuname,$ccdomain,
4610: $srch,$response,$context,
4611: $permission,$crstype,$brcrum,
4612: $showcredits);
4613: }
4614: } elsif ($env{'form.phase'} eq 'get_user_info') {
4615: my ($currstate,$response,$forcenewuser,$results) =
4616: &user_search_result($context,$srch);
4617: if ($env{'form.currstate'} eq 'modify') {
4618: $currstate = $env{'form.currstate'};
4619: }
4620: if ($currstate eq 'select') {
4621: &print_user_selection_page($r,$response,$srch,$results,
4622: \@search,$context,undef,$crstype,
4623: $brcrum);
4624: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4625: my ($ccuname,$ccdomain,$uhome);
4626: if (($srch->{'srchby'} eq 'uname') &&
4627: ($srch->{'srchtype'} eq 'exact')) {
4628: $ccuname = $srch->{'srchterm'};
4629: $ccdomain= $srch->{'srchdomain'};
4630: } else {
4631: my @matchedunames = keys(%{$results});
4632: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4633: }
4634: $ccuname =&LONCAPA::clean_username($ccuname);
4635: $ccdomain=&LONCAPA::clean_domain($ccdomain);
4636: if ($env{'form.action'} eq 'accesslogs') {
4637: my $uhome;
4638: if (($ccuname ne '') && ($ccdomain ne '')) {
4639: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4640: }
4641: if (($uhome eq '') || ($uhome eq 'no_host')) {
4642: $env{'form.phase'} = '';
4643: undef($forcenewuser);
4644: #if ($response) {
4645: # unless ($response =~ m{\Q<br /><br />\E$}) {
4646: # $response .= '<br /><br />';
4647: # }
4648: #}
4649: &print_username_entry_form($r,$context,$response,$srch,
4650: $forcenewuser,$crstype,$brcrum);
4651: } else {
4652: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4653: }
4654: } else {
4655: if ($env{'form.forcenewuser'}) {
4656: $response = '';
4657: }
4658: &print_user_modification_page($r,$ccuname,$ccdomain,
4659: $srch,$response,$context,
4660: $permission,$crstype,$brcrum);
4661: }
4662: } elsif ($currstate eq 'query') {
4663: &print_user_query_page($r,'createuser',$brcrum);
4664: } else {
4665: $env{'form.phase'} = '';
4666: &print_username_entry_form($r,$context,$response,$srch,
4667: $forcenewuser,$crstype,$brcrum);
4668: }
4669: } elsif ($env{'form.phase'} eq 'userpicked') {
4670: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4671: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
4672: if ($env{'form.action'} eq 'accesslogs') {
4673: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4674: } else {
4675: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4676: $context,$permission,$crstype,
4677: $brcrum);
4678: }
4679: } elsif ($env{'form.action'} eq 'accesslogs') {
4680: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4681: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4682: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4683: }
4684: } elsif ($env{'form.phase'} eq 'update_user_data') {
4685: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
4686: } else {
4687: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4688: $brcrum);
4689: }
4690: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
4691: my $prefix;
4692: if ($env{'form.phase'} eq 'set_custom_roles') {
4693: &set_custom_role($r,$context,$brcrum,$prefix);
4694: } else {
4695: &custom_role_editor($r,$brcrum,$prefix);
4696: }
4697: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4698: ($permission->{'cusr'}) &&
4699: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4700: push(@{$brcrum},
4701: {href => '/adm/createuser?action=processauthorreq',
4702: text => 'Authoring Space requests',
4703: help => 'Domain_Role_Approvals'});
4704: $bread_crumbs_component = 'Authoring requests';
4705: if ($env{'form.state'} eq 'done') {
4706: push(@{$brcrum},
4707: {href => '/adm/createuser?action=authorreqqueue',
4708: text => 'Result',
4709: help => 'Domain_Role_Approvals'});
4710: $bread_crumbs_component = 'Authoring request result';
4711: }
4712: $args = { bread_crumbs => $brcrum,
4713: bread_crumbs_component => $bread_crumbs_component};
4714: my $js = &usernamerequest_javascript();
4715: $r->print(&header(&add_script($js),$args));
4716: if (!exists($env{'form.state'})) {
4717: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4718: $env{'request.role.domain'}));
4719: } elsif ($env{'form.state'} eq 'done') {
4720: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4721: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4722: $env{'request.role.domain'}));
4723: }
4724: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4725: ($permission->{'cusr'}) &&
4726: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4727: push(@{$brcrum},
4728: {href => '/adm/createuser?action=processusernamereq',
4729: text => 'LON-CAPA account requests',
4730: help => 'Domain_Username_Approvals'});
4731: $bread_crumbs_component = 'Account requests';
4732: if ($env{'form.state'} eq 'done') {
4733: push(@{$brcrum},
4734: {href => '/adm/createuser?action=usernamereqqueue',
4735: text => 'Result',
4736: help => 'Domain_Username_Approvals'});
4737: $bread_crumbs_component = 'LON-CAPA account request result';
4738: }
4739: $args = { bread_crumbs => $brcrum,
4740: bread_crumbs_component => $bread_crumbs_component};
4741: my $js = &usernamerequest_javascript();
4742: $r->print(&header(&add_script($js),$args));
4743: if (!exists($env{'form.state'})) {
4744: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4745: $env{'request.role.domain'}));
4746: } elsif ($env{'form.state'} eq 'done') {
4747: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4748: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4749: $env{'request.role.domain'}));
4750: }
4751: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4752: ($permission->{'cusr'})) {
4753: my $dom = $env{'form.domain'};
4754: my $uname = $env{'form.username'};
4755: my $warning;
4756: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4757: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4758: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4759: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4760: if ($uhome eq 'no_host') {
4761: my $queue = $env{'form.queue'};
4762: my $reqkey = &escape($uname).'_'.$queue;
4763: my $namespace = 'usernamequeue';
4764: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4765: my %queued =
4766: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4767: unless ($queued{$reqkey}) {
4768: $warning = &mt('No information was found for this LON-CAPA account request.');
4769: }
4770: } else {
4771: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4772: }
4773: } else {
4774: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4775: }
4776: } else {
4777: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4778: }
4779: } else {
4780: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4781: }
4782: my $args = { only_body => 1 };
4783: $r->print(&header(undef,$args).
4784: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4785: if ($warning ne '') {
4786: $r->print('<div class="LC_warning">'.$warning.'</div>');
4787: } else {
4788: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4789: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4790: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4791: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4792: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4793: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4794: my %info =
4795: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4796: if (ref($info{$uname}) eq 'HASH') {
4797: my $usertype = $info{$uname}{'inststatus'};
4798: unless ($usertype) {
4799: $usertype = 'default';
4800: }
4801: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4802: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
4803: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
4804: my ($num,$count,$showstatus);
4805: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
4806: unless ($usertype eq 'default') {
4807: my ($othertitle,$usertypes,$types) =
4808: &Apache::loncommon::sorted_inst_types($dom);
4809: if (ref($usertypes) eq 'HASH') {
4810: if ($usertypes->{$usertype}) {
4811: $showstatus = $usertypes->{$usertype};
4812: $count ++;
4813: }
4814: }
4815: }
4816: foreach my $field (@{$infofields}) {
4817: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
4818: next unless ($infotitles->{$field});
4819: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
4820: $info{$uname}{$field});
4821: $num ++;
4822: if ($count == $num) {
4823: $r->print(&Apache::lonhtmlcommon::row_closure(1));
4824: } else {
4825: $r->print(&Apache::lonhtmlcommon::row_closure());
4826: }
4827: }
4828: if ($showstatus) {
4829: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')).
4830: $showstatus.
4831: &Apache::lonhtmlcommon::row_closure(1));
4832: }
4833: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
4834: }
4835: }
4836: }
4837: }
4838: }
4839: }
4840: $r->print(&close_popup_form());
4841: }
4842: } elsif (($env{'form.action'} eq 'listusers') &&
4843: ($permission->{'view'} || $permission->{'cusr'})) {
4844: if ($env{'form.phase'} eq 'bulkchange') {
4845: push(@{$brcrum},
4846: {href => '/adm/createuser?action=listusers',
4847: text => "List Users"},
4848: {href => "/adm/createuser",
4849: text => "Result",
4850: help => 'Course_View_Class_List'});
4851: $bread_crumbs_component = 'Update Users';
4852: $args = {bread_crumbs => $brcrum,
4853: bread_crumbs_component => $bread_crumbs_component};
4854: $r->print(&header(undef,$args));
4855: my $setting = $env{'form.roletype'};
4856: my $choice = $env{'form.bulkaction'};
4857: if ($permission->{'cusr'}) {
4858: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
4859: } else {
4860: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
4861: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
4862: }
4863: } else {
4864: push(@{$brcrum},
4865: {href => '/adm/createuser?action=listusers',
4866: text => "List Users",
4867: help => 'Course_View_Class_List'});
4868: $bread_crumbs_component = 'List Users';
4869: $args = {bread_crumbs => $brcrum,
4870: bread_crumbs_component => $bread_crumbs_component};
4871: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4872: my $formname = 'studentform';
4873: my $hidecall = "hide_searching();";
4874: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
4875: ($env{'form.roletype'} eq 'community'))) {
4876: if ($env{'form.roletype'} eq 'course') {
4877: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
4878: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
4879: $formname);
4880: } elsif ($env{'form.roletype'} eq 'community') {
4881: $cb_jscript =
4882: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
4883: my %elements = (
4884: coursepick => 'radio',
4885: coursetotal => 'text',
4886: courselist => 'text',
4887: );
4888: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
4889: }
4890: $jscript .= &verify_user_display($context)."\n".
4891: &Apache::loncommon::check_uncheck_jscript();
4892: my $js = &add_script($jscript).$cb_jscript;
4893: my $loadcode =
4894: &Apache::lonuserutils::course_selector_loadcode($formname);
4895: if ($loadcode ne '') {
4896: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
4897: } else {
4898: $args->{add_entries} = {onload => $hidecall};
4899: }
4900: $r->print(&header($js,$args));
4901: } else {
4902: $args->{add_entries} = {onload => $hidecall};
4903: $jscript = &verify_user_display($context).
4904: &Apache::loncommon::check_uncheck_jscript();
4905: $r->print(&header(&add_script($jscript),$args));
4906: }
4907: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
4908: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
4909: $showcredits);
4910: }
4911: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
4912: my $brtext;
4913: if ($crstype eq 'Community') {
4914: $brtext = 'Drop Members';
4915: } else {
4916: $brtext = 'Drop Students';
4917: }
4918: push(@{$brcrum},
4919: {href => '/adm/createuser?action=drop',
4920: text => $brtext,
4921: help => 'Course_Drop_Student'});
4922: if ($env{'form.state'} eq 'done') {
4923: push(@{$brcrum},
4924: {href=>'/adm/createuser?action=drop',
4925: text=>"Result"});
4926: }
4927: $bread_crumbs_component = $brtext;
4928: $args = {bread_crumbs => $brcrum,
4929: bread_crumbs_component => $bread_crumbs_component};
4930: $r->print(&header(undef,$args));
4931: if (!exists($env{'form.state'})) {
4932: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
4933: } elsif ($env{'form.state'} eq 'done') {
4934: &Apache::lonuserutils::update_user_list($r,$context,undef,
4935: $env{'form.action'});
4936: }
4937: } elsif ($env{'form.action'} eq 'dateselect') {
4938: if ($permission->{'cusr'}) {
4939: $r->print(&header(undef,{'no_nav_bar' => 1}).
4940: &Apache::lonuserutils::date_section_selector($context,$permission,
4941: $crstype,$showcredits));
4942: } else {
4943: $r->print(&header(undef,{'no_nav_bar' => 1}).
4944: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
4945: }
4946: } elsif ($env{'form.action'} eq 'selfenroll') {
4947: if ($permission->{selfenrolladmin}) {
4948: my $cid = $env{'request.course.id'};
4949: my $cdom = $env{'course.'.$cid.'.domain'};
4950: my $cnum = $env{'course.'.$cid.'.num'};
4951: my %currsettings = (
4952: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
4953: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
4954: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
4955: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
4956: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
4957: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
4958: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
4959: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
4960: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
4961: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
4962: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
4963: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
4964: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
4965: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
4966: );
4967: push(@{$brcrum},
4968: {href => '/adm/createuser?action=selfenroll',
4969: text => "Configure Self-enrollment",
4970: help => 'Course_Self_Enrollment'});
4971: if (!exists($env{'form.state'})) {
4972: $args = { bread_crumbs => $brcrum,
4973: bread_crumbs_component => 'Configure Self-enrollment'};
4974: $r->print(&header(undef,$args));
4975: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
4976: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
4977: } elsif ($env{'form.state'} eq 'done') {
4978: push (@{$brcrum},
4979: {href=>'/adm/createuser?action=selfenroll',
4980: text=>"Result"});
4981: $args = { bread_crumbs => $brcrum,
4982: bread_crumbs_component => 'Self-enrollment result'};
4983: $r->print(&header(undef,$args));
4984: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
4985: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
4986: }
4987: } else {
4988: $r->print(&header(undef,{'no_nav_bar' => 1}).
4989: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
4990: }
4991: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
4992: if ($permission->{selfenrolladmin}) {
4993: push(@{$brcrum},
4994: {href => '/adm/createuser?action=selfenrollqueue',
4995: text => 'Enrollment requests',
4996: help => 'Course_Self_Enrollment'});
4997: $bread_crumbs_component = 'Enrollment requests';
4998: if ($env{'form.state'} eq 'done') {
4999: push(@{$brcrum},
5000: {href => '/adm/createuser?action=selfenrollqueue',
5001: text => 'Result',
5002: help => 'Course_Self_Enrollment'});
5003: $bread_crumbs_component = 'Enrollment result';
5004: }
5005: $args = { bread_crumbs => $brcrum,
5006: bread_crumbs_component => $bread_crumbs_component};
5007: $r->print(&header(undef,$args));
5008: my $cid = $env{'request.course.id'};
5009: my $cdom = $env{'course.'.$cid.'.domain'};
5010: my $cnum = $env{'course.'.$cid.'.num'};
5011: my $coursedesc = $env{'course.'.$cid.'.description'};
5012: if (!exists($env{'form.state'})) {
5013: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5014: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5015: $cdom,$cnum));
5016: } elsif ($env{'form.state'} eq 'done') {
5017: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5018: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5019: $cdom,$cnum,$coursedesc));
5020: }
5021: } else {
5022: $r->print(&header(undef,{'no_nav_bar' => 1}).
5023: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
5024: }
5025:
5026: } elsif ($env{'form.action'} eq 'changelogs') {
5027: if ($permission->{cusr} || $permission->{view}) {
5028: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5029: } else {
5030: $r->print(&header(undef,{'no_nav_bar' => 1}).
5031: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
5032: }
5033: } elsif ($env{'form.action'} eq 'helpdesk') {
5034: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5035: if ($env{'form.state'} eq 'process') {
5036: if ($permission->{'owner'}) {
5037: &update_helpdeskaccess($r,$permission,$brcrum);
5038: } else {
5039: &print_helpdeskaccess_display($r,$permission,$brcrum);
5040: }
5041: } else {
5042: &print_helpdeskaccess_display($r,$permission,$brcrum);
5043: }
5044: } else {
5045: $r->print(&header(undef,{'no_nav_bar' => 1}).
5046: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5047: }
5048: } else {
5049: $bread_crumbs_component = 'User Management';
5050: $args = { bread_crumbs => $brcrum,
5051: bread_crumbs_component => $bread_crumbs_component};
5052: $r->print(&header(undef,$args));
5053: $r->print(&print_main_menu($permission,$context,$crstype));
5054: }
5055: $r->print(&Apache::loncommon::end_page());
5056: return OK;
5057: }
5058:
5059: sub header {
5060: my ($jscript,$args) = @_;
5061: my $start_page;
5062: if (ref($args) eq 'HASH') {
5063: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
5064: } else {
5065: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
5066: }
5067: return $start_page;
5068: }
5069:
5070: sub add_script {
5071: my ($js) = @_;
5072: return '<script type="text/javascript">'."\n"
5073: .'// <![CDATA['."\n"
5074: .$js."\n"
5075: .'// ]]>'."\n"
5076: .'</script>'."\n";
5077: }
5078:
5079: sub usernamerequest_javascript {
5080: my $js = <<ENDJS;
5081:
5082: function openusernamereqdisplay(dom,uname,queue) {
5083: var url = '/adm/createuser?action=displayuserreq';
5084: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5085: var title = 'Account_Request_Browser';
5086: var options = 'scrollbars=1,resizable=1,menubar=0';
5087: options += ',width=700,height=600';
5088: var stdeditbrowser = open(url,title,options,'1');
5089: stdeditbrowser.focus();
5090: return;
5091: }
5092:
5093: ENDJS
5094: }
5095:
5096: sub close_popup_form {
5097: my $close= &mt('Close Window');
5098: return << "END";
5099: <p><form name="displayreq" action="" method="post">
5100: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5101: </form></p>
5102: END
5103: }
5104:
5105: sub verify_user_display {
5106: my ($context) = @_;
5107: my %lt = &Apache::lonlocal::texthash (
5108: course => 'course(s): description, section(s), status',
5109: community => 'community(s): description, section(s), status',
5110: author => 'author',
5111: );
5112: my $photos;
5113: if (($context eq 'course') && $env{'request.course.id'}) {
5114: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5115: }
5116: my $output = <<"END";
5117:
5118: function hide_searching() {
5119: if (document.getElementById('searching')) {
5120: document.getElementById('searching').style.display = 'none';
5121: }
5122: return;
5123: }
5124:
5125: function display_update() {
5126: document.studentform.action.value = 'listusers';
5127: document.studentform.phase.value = 'display';
5128: document.studentform.submit();
5129: }
5130:
5131: function updateCols(caller) {
5132: var context = '$context';
5133: var photos = '$photos';
5134: if (caller == 'Status') {
5135: if ((context == 'domain') &&
5136: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5137: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
5138: document.getElementById('showcolstatus').checked = false;
5139: document.getElementById('showcolstatus').disabled = 'disabled';
5140: document.getElementById('showcolstart').checked = false;
5141: document.getElementById('showcolend').checked = false;
5142: } else {
5143: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5144: document.getElementById('showcolstatus').checked = true;
5145: document.getElementById('showcolstatus').disabled = '';
5146: document.getElementById('showcolstart').checked = true;
5147: document.getElementById('showcolend').checked = true;
5148: } else {
5149: document.getElementById('showcolstatus').checked = false;
5150: document.getElementById('showcolstatus').disabled = 'disabled';
5151: document.getElementById('showcolstart').checked = false;
5152: document.getElementById('showcolend').checked = false;
5153: }
5154: }
5155: }
5156: if (caller == 'output') {
5157: if (photos == 1) {
5158: if (document.getElementById('showcolphoto')) {
5159: var photoitem = document.getElementById('showcolphoto');
5160: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5161: photoitem.checked = true;
5162: photoitem.disabled = '';
5163: } else {
5164: photoitem.checked = false;
5165: photoitem.disabled = 'disabled';
5166: }
5167: }
5168: }
5169: }
5170: if (caller == 'showrole') {
5171: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5172: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
5173: document.getElementById('showcolrole').checked = true;
5174: document.getElementById('showcolrole').disabled = '';
5175: } else {
5176: document.getElementById('showcolrole').checked = false;
5177: document.getElementById('showcolrole').disabled = 'disabled';
5178: }
5179: if (context == 'domain') {
5180: var quotausageshow = 0;
5181: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5182: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5183: document.getElementById('showcolstatus').checked = false;
5184: document.getElementById('showcolstatus').disabled = 'disabled';
5185: document.getElementById('showcolstart').checked = false;
5186: document.getElementById('showcolend').checked = false;
5187: } else {
5188: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5189: document.getElementById('showcolstatus').checked = true;
5190: document.getElementById('showcolstatus').disabled = '';
5191: document.getElementById('showcolstart').checked = true;
5192: document.getElementById('showcolend').checked = true;
5193: }
5194: }
5195: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5196: document.getElementById('showcolextent').disabled = 'disabled';
5197: document.getElementById('showcolextent').checked = 'false';
5198: document.getElementById('showextent').style.display='none';
5199: document.getElementById('showcoltextextent').innerHTML = '';
5200: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5201: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5202: if (document.getElementById('showcolauthorusage')) {
5203: document.getElementById('showcolauthorusage').disabled = '';
5204: }
5205: if (document.getElementById('showcolauthorquota')) {
5206: document.getElementById('showcolauthorquota').disabled = '';
5207: }
5208: quotausageshow = 1;
5209: }
5210: } else {
5211: document.getElementById('showextent').style.display='block';
5212: document.getElementById('showextent').style.textAlign='left';
5213: document.getElementById('showextent').style.textFace='normal';
5214: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5215: document.getElementById('showcolextent').disabled = '';
5216: document.getElementById('showcolextent').checked = 'true';
5217: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5218: } else {
5219: document.getElementById('showcolextent').disabled = '';
5220: document.getElementById('showcolextent').checked = 'true';
5221: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5222: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5223: } else {
5224: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5225: }
5226: }
5227: }
5228: if (quotausageshow == 0) {
5229: if (document.getElementById('showcolauthorusage')) {
5230: document.getElementById('showcolauthorusage').checked = false;
5231: document.getElementById('showcolauthorusage').disabled = 'disabled';
5232: }
5233: if (document.getElementById('showcolauthorquota')) {
5234: document.getElementById('showcolauthorquota').checked = false;
5235: document.getElementById('showcolauthorquota').disabled = 'disabled';
5236: }
5237: }
5238: }
5239: }
5240: return;
5241: }
5242:
5243: END
5244: return $output;
5245:
5246: }
5247:
5248: ###############################################################
5249: ###############################################################
5250: # Menu Phase One
5251: sub print_main_menu {
5252: my ($permission,$context,$crstype) = @_;
5253: my $linkcontext = $context;
5254: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5255: if (($context eq 'course') && ($crstype eq 'Community')) {
5256: $linkcontext = lc($crstype);
5257: $stuterm = 'Members';
5258: }
5259: my %links = (
5260: domain => {
5261: upload => 'Upload a File of Users',
5262: singleuser => 'Add/Modify a User',
5263: listusers => 'Manage Users',
5264: },
5265: author => {
5266: upload => 'Upload a File of Co-authors',
5267: singleuser => 'Add/Modify a Co-author',
5268: listusers => 'Manage Co-authors',
5269: },
5270: course => {
5271: upload => 'Upload a File of Course Users',
5272: singleuser => 'Add/Modify a Course User',
5273: listusers => 'List and Modify Multiple Course Users',
5274: },
5275: community => {
5276: upload => 'Upload a File of Community Users',
5277: singleuser => 'Add/Modify a Community User',
5278: listusers => 'List and Modify Multiple Community Users',
5279: },
5280: );
5281: my %linktitles = (
5282: domain => {
5283: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5284: listusers => 'Show and manage users in this domain.',
5285: },
5286: author => {
5287: singleuser => 'Add a user with a co- or assistant author role.',
5288: listusers => 'Show and manage co- or assistant authors.',
5289: },
5290: course => {
5291: singleuser => 'Add a user with a certain role to this course.',
5292: listusers => 'Show and manage users in this course.',
5293: },
5294: community => {
5295: singleuser => 'Add a user with a certain role to this community.',
5296: listusers => 'Show and manage users in this community.',
5297: },
5298: );
5299: if ($linkcontext eq 'domain') {
5300: unless ($permission->{'cusr'}) {
5301: $links{'domain'}{'singleuser'} = 'View a User';
5302: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5303:
5304: }
5305: } elsif ($linkcontext eq 'course') {
5306: unless ($permission->{'cusr'}) {
5307: $links{'course'}{'singleuser'} = 'View a Course User';
5308: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5309: $links{'course'}{'listusers'} = 'List Course Users';
5310: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5311: }
5312: } elsif ($linkcontext eq 'community') {
5313: unless ($permission->{'cusr'}) {
5314: $links{'community'}{'singleuser'} = 'View a Community User';
5315: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5316: $links{'community'}{'listusers'} = 'List Community Users';
5317: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5318: }
5319: }
5320: my @menu = ( {categorytitle => 'Single Users',
5321: items =>
5322: [
5323: {
5324: linktext => $links{$linkcontext}{'singleuser'},
5325: icon => 'edit-redo.png',
5326: #help => 'Course_Change_Privileges',
5327: url => '/adm/createuser?action=singleuser',
5328: permission => ($permission->{'view'} || $permission->{'cusr'}),
5329: linktitle => $linktitles{$linkcontext}{'singleuser'},
5330: },
5331: ]},
5332:
5333: {categorytitle => 'Multiple Users',
5334: items =>
5335: [
5336: {
5337: linktext => $links{$linkcontext}{'upload'},
5338: icon => 'uplusr.png',
5339: #help => 'Course_Create_Class_List',
5340: url => '/adm/createuser?action=upload',
5341: permission => $permission->{'cusr'},
5342: linktitle => 'Upload a CSV or a text file containing users.',
5343: },
5344: {
5345: linktext => $links{$linkcontext}{'listusers'},
5346: icon => 'mngcu.png',
5347: #help => 'Course_View_Class_List',
5348: url => '/adm/createuser?action=listusers',
5349: permission => ($permission->{'view'} || $permission->{'cusr'}),
5350: linktitle => $linktitles{$linkcontext}{'listusers'},
5351: },
5352:
5353: ]},
5354:
5355: {categorytitle => 'Administration',
5356: items => [ ]},
5357: );
5358:
5359: if ($context eq 'domain'){
5360: push(@{ $menu[0]->{items} }, # Single Users
5361: {
5362: linktext => 'User Access Log',
5363: icon => 'document-properties.png',
5364: #help => 'Domain_User_Access_Logs',
5365: url => '/adm/createuser?action=accesslogs',
5366: permission => $permission->{'activity'},
5367: linktitle => 'View user access log.',
5368: }
5369: );
5370:
5371: push(@{ $menu[2]->{items} }, #Category: Administration
5372: {
5373: linktext => 'Helpdesk Access',
5374: icon => 'helpdesk-access.png',
5375: #help => 'Course_Helpdesk_Access',
5376: url => '/adm/createuser?action=helpdesk',
5377: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5378: linktitle => 'Helpdesk access options',
5379: },
5380: {
5381: linktext => 'Custom Roles',
5382: icon => 'emblem-photos.png',
5383: #help => 'Course_Editing_Custom_Roles',
5384: url => '/adm/createuser?action=custom',
5385: permission => $permission->{'custom'},
5386: linktitle => 'Configure a custom role.',
5387: },
5388: {
5389: linktext => 'Authoring Space Requests',
5390: icon => 'selfenrl-queue.png',
5391: #help => 'Domain_Role_Approvals',
5392: url => '/adm/createuser?action=processauthorreq',
5393: permission => $permission->{'cusr'},
5394: linktitle => 'Approve or reject author role requests',
5395: },
5396: {
5397: linktext => 'LON-CAPA Account Requests',
5398: icon => 'list-add.png',
5399: #help => 'Domain_Username_Approvals',
5400: url => '/adm/createuser?action=processusernamereq',
5401: permission => $permission->{'cusr'},
5402: linktitle => 'Approve or reject LON-CAPA account requests',
5403: },
5404: {
5405: linktext => 'Change Log',
5406: icon => 'document-properties.png',
5407: #help => 'Course_User_Logs',
5408: url => '/adm/createuser?action=changelogs',
5409: permission => ($permission->{'cusr'} || $permission->{'view'}),
5410: linktitle => 'View change log.',
5411: },
5412: );
5413:
5414: }elsif ($context eq 'course'){
5415: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
5416:
5417: my %linktext = (
5418: 'Course' => {
5419: single => 'Add/Modify a Student',
5420: drop => 'Drop Students',
5421: groups => 'Course Groups',
5422: },
5423: 'Community' => {
5424: single => 'Add/Modify a Member',
5425: drop => 'Drop Members',
5426: groups => 'Community Groups',
5427: },
5428: );
5429:
5430: my %linktitle = (
5431: 'Course' => {
5432: single => 'Add a user with the role of student to this course',
5433: drop => 'Remove a student from this course.',
5434: groups => 'Manage course groups',
5435: },
5436: 'Community' => {
5437: single => 'Add a user with the role of member to this community',
5438: drop => 'Remove a member from this community.',
5439: groups => 'Manage community groups',
5440: },
5441: );
5442:
5443: push(@{ $menu[0]->{items} }, #Category: Single Users
5444: {
5445: linktext => $linktext{$crstype}{'single'},
5446: #help => 'Course_Add_Student',
5447: icon => 'list-add.png',
5448: url => '/adm/createuser?action=singlestudent',
5449: permission => $permission->{'cusr'},
5450: linktitle => $linktitle{$crstype}{'single'},
5451: },
5452: );
5453:
5454: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5455: {
5456: linktext => $linktext{$crstype}{'drop'},
5457: icon => 'edit-undo.png',
5458: #help => 'Course_Drop_Student',
5459: url => '/adm/createuser?action=drop',
5460: permission => $permission->{'cusr'},
5461: linktitle => $linktitle{$crstype}{'drop'},
5462: },
5463: );
5464: push(@{ $menu[2]->{items} }, #Category: Administration
5465: {
5466: linktext => 'Custom Roles',
5467: icon => 'emblem-photos.png',
5468: #help => 'Course_Editing_Custom_Roles',
5469: url => '/adm/createuser?action=custom',
5470: permission => $permission->{'custom'},
5471: linktitle => 'Configure a custom role.',
5472: },
5473: {
5474: linktext => $linktext{$crstype}{'groups'},
5475: icon => 'grps.png',
5476: #help => 'Course_Manage_Group',
5477: url => '/adm/coursegroups?refpage=cusr',
5478: permission => $permission->{'grp_manage'},
5479: linktitle => $linktitle{$crstype}{'groups'},
5480: },
5481: {
5482: linktext => 'Change Log',
5483: icon => 'document-properties.png',
5484: #help => 'Course_User_Logs',
5485: url => '/adm/createuser?action=changelogs',
5486: permission => ($permission->{'view'} || $permission->{'cusr'}),
5487: linktitle => 'View change log.',
5488: },
5489: );
5490: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
5491: push(@{ $menu[2]->{items} },
5492: {
5493: linktext => 'Enrollment Requests',
5494: icon => 'selfenrl-queue.png',
5495: #help => 'Course_Approve_Selfenroll',
5496: url => '/adm/createuser?action=selfenrollqueue',
5497: permission => $permission->{'selfenrolladmin'},
5498: linktitle =>'Approve or reject enrollment requests.',
5499: },
5500: );
5501: }
5502:
5503: if (!exists($permission->{'cusr_section'})){
5504: if ($crstype ne 'Community') {
5505: push(@{ $menu[2]->{items} },
5506: {
5507: linktext => 'Automated Enrollment',
5508: icon => 'roles.png',
5509: #help => 'Course_Automated_Enrollment',
5510: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
5511: && (($permission->{'cusr'}) ||
5512: ($permission->{'view'}))),
5513: url => '/adm/populate',
5514: linktitle => 'Automated enrollment manager.',
5515: }
5516: );
5517: }
5518: push(@{ $menu[2]->{items} },
5519: {
5520: linktext => 'User Self-Enrollment',
5521: icon => 'self_enroll.png',
5522: #help => 'Course_Self_Enrollment',
5523: url => '/adm/createuser?action=selfenroll',
5524: permission => $permission->{'selfenrolladmin'},
5525: linktitle => 'Configure user self-enrollment.',
5526: },
5527: );
5528: }
5529: } elsif ($context eq 'author') {
5530: push(@{ $menu[2]->{items} }, #Category: Administration
5531: {
5532: linktext => 'Change Log',
5533: icon => 'document-properties.png',
5534: #help => 'Course_User_Logs',
5535: url => '/adm/createuser?action=changelogs',
5536: permission => $permission->{'cusr'},
5537: linktitle => 'View change log.',
5538: },
5539: );
5540: }
5541: return Apache::lonhtmlcommon::generate_menu(@menu);
5542: # { text => 'View Log-in History',
5543: # help => 'Course_User_Logins',
5544: # action => 'logins',
5545: # permission => $permission->{'cusr'},
5546: # });
5547: }
5548:
5549: sub restore_prev_selections {
5550: my %saveable_parameters = ('srchby' => 'scalar',
5551: 'srchin' => 'scalar',
5552: 'srchtype' => 'scalar',
5553: );
5554: &Apache::loncommon::store_settings('user','user_picker',
5555: \%saveable_parameters);
5556: &Apache::loncommon::restore_settings('user','user_picker',
5557: \%saveable_parameters);
5558: }
5559:
5560: sub print_selfenroll_menu {
5561: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
5562: my $crstype = &Apache::loncommon::course_type();
5563: my $formname = 'selfenroll';
5564: my $nolink = 1;
5565: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
5566: my $groupslist = &Apache::lonuserutils::get_groupslist();
5567: my $setsec_js =
5568: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
5569: my %alerts = &Apache::lonlocal::texthash(
5570: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5571: butn => 'but no user types have been checked.',
5572: wilf => "Please uncheck 'activate' or check at least one type.",
5573: );
5574: my $disabled;
5575: if ($readonly) {
5576: $disabled = ' disabled="disabled"';
5577: }
5578: &js_escape(\%alerts);
5579: my $selfenroll_js = <<"ENDSCRIPT";
5580: function update_types(caller,num) {
5581: var delidx = getIndexByName('selfenroll_delete');
5582: var actidx = getIndexByName('selfenroll_activate');
5583: if (caller == 'selfenroll_all') {
5584: var selall;
5585: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5586: if (document.$formname.selfenroll_all[i].checked) {
5587: selall = document.$formname.selfenroll_all[i].value;
5588: }
5589: }
5590: if (selall == 1) {
5591: if (delidx != -1) {
5592: if (document.$formname.selfenroll_delete.length) {
5593: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5594: document.$formname.selfenroll_delete[j].checked = true;
5595: }
5596: } else {
5597: document.$formname.elements[delidx].checked = true;
5598: }
5599: }
5600: if (actidx != -1) {
5601: if (document.$formname.selfenroll_activate.length) {
5602: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5603: document.$formname.selfenroll_activate[j].checked = false;
5604: }
5605: } else {
5606: document.$formname.elements[actidx].checked = false;
5607: }
5608: }
5609: document.$formname.selfenroll_newdom.selectedIndex = 0;
5610: }
5611: }
5612: if (caller == 'selfenroll_activate') {
5613: if (document.$formname.selfenroll_activate.length) {
5614: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5615: if (document.$formname.selfenroll_activate[j].value == num) {
5616: if (document.$formname.selfenroll_activate[j].checked) {
5617: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5618: if (document.$formname.selfenroll_all[i].value == '1') {
5619: document.$formname.selfenroll_all[i].checked = false;
5620: }
5621: if (document.$formname.selfenroll_all[i].value == '0') {
5622: document.$formname.selfenroll_all[i].checked = true;
5623: }
5624: }
5625: }
5626: }
5627: }
5628: } else {
5629: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5630: if (document.$formname.selfenroll_all[i].value == '1') {
5631: document.$formname.selfenroll_all[i].checked = false;
5632: }
5633: if (document.$formname.selfenroll_all[i].value == '0') {
5634: document.$formname.selfenroll_all[i].checked = true;
5635: }
5636: }
5637: }
5638: }
5639: if (caller == 'selfenroll_delete') {
5640: if (document.$formname.selfenroll_delete.length) {
5641: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5642: if (document.$formname.selfenroll_delete[j].value == num) {
5643: if (document.$formname.selfenroll_delete[j].checked) {
5644: var delindex = getIndexByName('selfenroll_types_'+num);
5645: if (delindex != -1) {
5646: if (document.$formname.elements[delindex].length) {
5647: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5648: document.$formname.elements[delindex][k].checked = false;
5649: }
5650: } else {
5651: document.$formname.elements[delindex].checked = false;
5652: }
5653: }
5654: }
5655: }
5656: }
5657: } else {
5658: if (document.$formname.selfenroll_delete.checked) {
5659: var delindex = getIndexByName('selfenroll_types_'+num);
5660: if (delindex != -1) {
5661: if (document.$formname.elements[delindex].length) {
5662: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5663: document.$formname.elements[delindex][k].checked = false;
5664: }
5665: } else {
5666: document.$formname.elements[delindex].checked = false;
5667: }
5668: }
5669: }
5670: }
5671: }
5672: return;
5673: }
5674:
5675: function validate_types(form) {
5676: var needaction = new Array();
5677: var countfail = 0;
5678: var actidx = getIndexByName('selfenroll_activate');
5679: if (actidx != -1) {
5680: if (document.$formname.selfenroll_activate.length) {
5681: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5682: var num = document.$formname.selfenroll_activate[j].value;
5683: if (document.$formname.selfenroll_activate[j].checked) {
5684: countfail = check_types(num,countfail,needaction)
5685: }
5686: }
5687: } else {
5688: if (document.$formname.selfenroll_activate.checked) {
5689: var num = document.$formname.selfenroll_activate.value;
5690: countfail = check_types(num,countfail,needaction)
5691: }
5692: }
5693: }
5694: if (countfail > 0) {
5695: var msg = "$alerts{'acto'}\\n";
5696: var loopend = needaction.length -1;
5697: if (loopend > 0) {
5698: for (var m=0; m<loopend; m++) {
5699: msg += needaction[m]+", ";
5700: }
5701: }
5702: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5703: alert(msg);
5704: return;
5705: }
5706: setSections(form);
5707: }
5708:
5709: function check_types(num,countfail,needaction) {
5710: var typeidx = getIndexByName('selfenroll_types_'+num);
5711: var count = 0;
5712: if (typeidx != -1) {
5713: if (document.$formname.elements[typeidx].length) {
5714: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5715: if (document.$formname.elements[typeidx][k].checked) {
5716: count ++;
5717: }
5718: }
5719: } else {
5720: if (document.$formname.elements[typeidx].checked) {
5721: count ++;
5722: }
5723: }
5724: if (count == 0) {
5725: var domidx = getIndexByName('selfenroll_dom_'+num);
5726: if (domidx != -1) {
5727: var domname = document.$formname.elements[domidx].value;
5728: needaction[countfail] = domname;
5729: countfail ++;
5730: }
5731: }
5732: }
5733: return countfail;
5734: }
5735:
5736: function toggleNotify() {
5737: var selfenrollApproval = 0;
5738: if (document.$formname.selfenroll_approval.length) {
5739: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5740: if (document.$formname.selfenroll_approval[i].checked) {
5741: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5742: break;
5743: }
5744: }
5745: }
5746: if (document.getElementById('notified')) {
5747: if (selfenrollApproval == 0) {
5748: document.getElementById('notified').style.display='none';
5749: } else {
5750: document.getElementById('notified').style.display='block';
5751: }
5752: }
5753: return;
5754: }
5755:
5756: function getIndexByName(item) {
5757: for (var i=0;i<document.$formname.elements.length;i++) {
5758: if (document.$formname.elements[i].name == item) {
5759: return i;
5760: }
5761: }
5762: return -1;
5763: }
5764: ENDSCRIPT
5765:
5766: my $output = '<script type="text/javascript">'."\n".
5767: '// <![CDATA['."\n".
5768: $setsec_js."\n".$selfenroll_js."\n".
5769: '// ]]>'."\n".
5770: '</script>'."\n".
5771: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
5772:
5773: my $visactions = &cat_visibility();
5774: my ($cathash,%cattype);
5775: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5776: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5777: $cathash = $domconfig{'coursecategories'}{'cats'};
5778: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5779: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
5780: if ($cattype{'auth'} eq '') {
5781: $cattype{'auth'} = 'std';
5782: }
5783: if ($cattype{'unauth'} eq '') {
5784: $cattype{'unauth'} = 'std';
5785: }
5786: } else {
5787: $cathash = {};
5788: $cattype{'auth'} = 'std';
5789: $cattype{'unauth'} = 'std';
5790: }
5791: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
5792: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5793: '<br />'.
5794: '<br />'.$visactions->{'take'}.'<ul>'.
5795: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
5796: '</ul>');
5797: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
5798: if ($currsettings->{'uniquecode'}) {
5799: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
5800: } else {
5801: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5802: '<br />'.
5803: '<br />'.$visactions->{'take'}.'<ul>'.
5804: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
5805: '</ul><br />');
5806: }
5807: } else {
5808: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
5809: if (ref($visactions) eq 'HASH') {
5810: if ($visible) {
5811: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
5812: } else {
5813: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5814: .$visactions->{'yous'}.
5815: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5816: if (ref($vismsgs) eq 'ARRAY') {
5817: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5818: foreach my $item (@{$vismsgs}) {
5819: $output .= '<li>'.$visactions->{$item}.'</li>';
5820: }
5821: $output .= '</ul>';
5822: }
5823: $output .= '</p>';
5824: }
5825: }
5826: }
5827: my $actionhref = '/adm/createuser';
5828: if ($context eq 'domain') {
5829: $actionhref = '/adm/modifycourse';
5830: }
5831:
5832: my %noedit;
5833: unless ($context eq 'domain') {
5834: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
5835: }
5836: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
5837: &Apache::lonhtmlcommon::start_pick_box();
5838: if (ref($row) eq 'ARRAY') {
5839: foreach my $item (@{$row}) {
5840: my $title = $item;
5841: if (ref($lt) eq 'HASH') {
5842: $title = $lt->{$item};
5843: }
5844: $output .= &Apache::lonhtmlcommon::row_title($title);
5845: if ($item eq 'types') {
5846: my $curr_types;
5847: if (ref($currsettings) eq 'HASH') {
5848: $curr_types = $currsettings->{'selfenroll_types'};
5849: }
5850: if ($noedit{$item}) {
5851: if ($curr_types eq '*') {
5852: $output .= &mt('Any user in any domain');
5853: } else {
5854: my @entries = split(/;/,$curr_types);
5855: if (@entries > 0) {
5856: $output .= '<ul>';
5857: foreach my $entry (@entries) {
5858: my ($currdom,$typestr) = split(/:/,$entry);
5859: next if ($typestr eq '');
5860: my $domdesc = &Apache::lonnet::domain($currdom);
5861: my @currinsttypes = split(',',$typestr);
5862: my ($othertitle,$usertypes,$types) =
5863: &Apache::loncommon::sorted_inst_types($currdom);
5864: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5865: $usertypes->{'any'} = &mt('any user');
5866: if (keys(%{$usertypes}) > 0) {
5867: $usertypes->{'other'} = &mt('other users');
5868: }
5869: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
5870: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
5871: }
5872: }
5873: $output .= '</ul>';
5874: } else {
5875: $output .= &mt('None');
5876: }
5877: }
5878: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5879: next;
5880: }
5881: my $showdomdesc = 1;
5882: my $includeempty = 1;
5883: my $num = 0;
5884: $output .= &Apache::loncommon::start_data_table().
5885: &Apache::loncommon::start_data_table_row()
5886: .'<td colspan="2"><span class="LC_nobreak"><label>'
5887: .&mt('Any user in any domain:')
5888: .' <input type="radio" name="selfenroll_all" value="1" ';
5889: if ($curr_types eq '*') {
5890: $output .= ' checked="checked" ';
5891: }
5892: $output .= 'onchange="javascript:update_types('.
5893: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
5894: ' <input type="radio" name="selfenroll_all" value="0" ';
5895: if ($curr_types ne '*') {
5896: $output .= ' checked="checked" ';
5897: }
5898: $output .= ' onchange="javascript:update_types('.
5899: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
5900: &Apache::loncommon::end_data_table_row().
5901: &Apache::loncommon::end_data_table().
5902: &mt('Or').'<br />'.
5903: &Apache::loncommon::start_data_table();
5904: my %currdoms;
5905: if ($curr_types eq '') {
5906: $output .= &new_selfenroll_dom_row($cdom,'0');
5907: } elsif ($curr_types ne '*') {
5908: my @entries = split(/;/,$curr_types);
5909: if (@entries > 0) {
5910: foreach my $entry (@entries) {
5911: my ($currdom,$typestr) = split(/:/,$entry);
5912: $currdoms{$currdom} = 1;
5913: my $domdesc = &Apache::lonnet::domain($currdom);
5914: my @currinsttypes = split(',',$typestr);
5915: $output .= &Apache::loncommon::start_data_table_row()
5916: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
5917: .' '.$domdesc.' ('.$currdom.')'
5918: .'</b><input type="hidden" name="selfenroll_dom_'.$num
5919: .'" value="'.$currdom.'" /></span><br />'
5920: .'<span class="LC_nobreak"><label><input type="checkbox" '
5921: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
5922: .&mt('Delete').'</label></span></td>';
5923: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
5924: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
5925: .&Apache::loncommon::end_data_table_row();
5926: $num ++;
5927: }
5928: }
5929: }
5930: my $add_domtitle = &mt('Users in additional domain:');
5931: if ($curr_types eq '*') {
5932: $add_domtitle = &mt('Users in specific domain:');
5933: } elsif ($curr_types eq '') {
5934: $add_domtitle = &mt('Users in other domain:');
5935: }
5936: $output .= &Apache::loncommon::start_data_table_row()
5937: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
5938: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
5939: $includeempty,$showdomdesc,'','','',$readonly)
5940: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
5941: .'</td>'.&Apache::loncommon::end_data_table_row()
5942: .&Apache::loncommon::end_data_table();
5943: } elsif ($item eq 'registered') {
5944: my ($regon,$regoff);
5945: my $registered;
5946: if (ref($currsettings) eq 'HASH') {
5947: $registered = $currsettings->{'selfenroll_registered'};
5948: }
5949: if ($noedit{$item}) {
5950: if ($registered) {
5951: $output .= &mt('Must be registered in course');
5952: } else {
5953: $output .= &mt('No requirement');
5954: }
5955: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5956: next;
5957: }
5958: if ($registered) {
5959: $regon = ' checked="checked" ';
5960: $regoff = '';
5961: } else {
5962: $regon = '';
5963: $regoff = ' checked="checked" ';
5964: }
5965: $output .= '<label>'.
5966: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
5967: &mt('Yes').'</label> <label>'.
5968: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
5969: &mt('No').'</label>';
5970: } elsif ($item eq 'enroll_dates') {
5971: my ($starttime,$endtime);
5972: if (ref($currsettings) eq 'HASH') {
5973: $starttime = $currsettings->{'selfenroll_start_date'};
5974: $endtime = $currsettings->{'selfenroll_end_date'};
5975: if ($starttime eq '') {
5976: $starttime = $currsettings->{'default_enrollment_start_date'};
5977: }
5978: if ($endtime eq '') {
5979: $endtime = $currsettings->{'default_enrollment_end_date'};
5980: }
5981: }
5982: if ($noedit{$item}) {
5983: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
5984: &Apache::lonlocal::locallocaltime($endtime));
5985: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5986: next;
5987: }
5988: my $startform =
5989: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
5990: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
5991: my $endform =
5992: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
5993: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
5994: $output .= &selfenroll_date_forms($startform,$endform);
5995: } elsif ($item eq 'access_dates') {
5996: my ($starttime,$endtime);
5997: if (ref($currsettings) eq 'HASH') {
5998: $starttime = $currsettings->{'selfenroll_start_access'};
5999: $endtime = $currsettings->{'selfenroll_end_access'};
6000: if ($starttime eq '') {
6001: $starttime = $currsettings->{'default_enrollment_start_date'};
6002: }
6003: if ($endtime eq '') {
6004: $endtime = $currsettings->{'default_enrollment_end_date'};
6005: }
6006: }
6007: if ($noedit{$item}) {
6008: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6009: &Apache::lonlocal::locallocaltime($endtime));
6010: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6011: next;
6012: }
6013: my $startform =
6014: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
6015: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
6016: my $endform =
6017: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
6018: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
6019: $output .= &selfenroll_date_forms($startform,$endform);
6020: } elsif ($item eq 'section') {
6021: my $currsec;
6022: if (ref($currsettings) eq 'HASH') {
6023: $currsec = $currsettings->{'selfenroll_section'};
6024: }
6025: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6026: my $newsecval;
6027: if ($currsec ne 'none' && $currsec ne '') {
6028: if (!defined($sections_count{$currsec})) {
6029: $newsecval = $currsec;
6030: }
6031: }
6032: if ($noedit{$item}) {
6033: if ($currsec ne '') {
6034: $output .= $currsec;
6035: } else {
6036: $output .= &mt('No specific section');
6037: }
6038: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6039: next;
6040: }
6041: my $sections_select =
6042: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
6043: $output .= '<table class="LC_createuser">'."\n".
6044: '<tr class="LC_section_row">'."\n".
6045: '<td align="center">'.&mt('Existing sections')."\n".
6046: '<br />'.$sections_select.'</td><td align="center">'.
6047: &mt('New section').'<br />'."\n".
6048: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
6049: '<input type="hidden" name="sections" value="" />'."\n".
6050: '</td></tr></table>'."\n";
6051: } elsif ($item eq 'approval') {
6052: my ($currnotified,$currapproval,%appchecked);
6053: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
6054: if (ref($currsettings) eq 'HASH') {
6055: $currnotified = $currsettings->{'selfenroll_notifylist'};
6056: $currapproval = $currsettings->{'selfenroll_approval'};
6057: }
6058: if ($currapproval !~ /^[012]$/) {
6059: $currapproval = 0;
6060: }
6061: if ($noedit{$item}) {
6062: $output .= $selfdescs{'approval'}{$currapproval}.
6063: '<br />'.&mt('(Set by Domain Coordinator)');
6064: next;
6065: }
6066: $appchecked{$currapproval} = ' checked="checked"';
6067: for my $i (0..2) {
6068: $output .= '<label>'.
6069: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
6070: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6071: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
6072: }
6073: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6074: my (@ccs,%notified);
6075: my $ccrole = 'cc';
6076: if ($crstype eq 'Community') {
6077: $ccrole = 'co';
6078: }
6079: if ($advhash{$ccrole}) {
6080: @ccs = split(/,/,$advhash{$ccrole});
6081: }
6082: if ($currnotified) {
6083: foreach my $current (split(/,/,$currnotified)) {
6084: $notified{$current} = 1;
6085: if (!grep(/^\Q$current\E$/,@ccs)) {
6086: push(@ccs,$current);
6087: }
6088: }
6089: }
6090: if (@ccs) {
6091: my $style;
6092: unless ($currapproval) {
6093: $style = ' style="display: none;"';
6094: }
6095: $output .= '<br /><div id="notified"'.$style.'>'.
6096: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6097: &Apache::loncommon::start_data_table().
6098: &Apache::loncommon::start_data_table_row();
6099: my $count = 0;
6100: my $numcols = 4;
6101: foreach my $cc (sort(@ccs)) {
6102: my $notifyon;
6103: my ($ccuname,$ccudom) = split(/:/,$cc);
6104: if ($notified{$cc}) {
6105: $notifyon = ' checked="checked" ';
6106: }
6107: if ($count && !$count%$numcols) {
6108: $output .= &Apache::loncommon::end_data_table_row().
6109: &Apache::loncommon::start_data_table_row()
6110: }
6111: $output .= '<td><span class="LC_nobreak"><label>'.
6112: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
6113: &Apache::loncommon::plainname($ccuname,$ccudom).
6114: '</label></span></td>';
6115: $count ++;
6116: }
6117: my $rem = $count%$numcols;
6118: if ($rem) {
6119: my $emptycols = $numcols - $rem;
6120: for (my $i=0; $i<$emptycols; $i++) {
6121: $output .= '<td> </td>';
6122: }
6123: }
6124: $output .= &Apache::loncommon::end_data_table_row().
6125: &Apache::loncommon::end_data_table().
6126: '</div>';
6127: }
6128: } elsif ($item eq 'limit') {
6129: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6130: if (ref($currsettings) eq 'HASH') {
6131: $currlim = $currsettings->{'selfenroll_limit'};
6132: $currcap = $currsettings->{'selfenroll_cap'};
6133: }
6134: if ($noedit{$item}) {
6135: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6136: if ($currlim eq 'allstudents') {
6137: $output .= &mt('Limit by total students');
6138: } elsif ($currlim eq 'selfenrolled') {
6139: $output .= &mt('Limit by total self-enrolled students');
6140: }
6141: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6142: '<br />'.&mt('(Set by Domain Coordinator)');
6143: } else {
6144: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6145: }
6146: next;
6147: }
6148: if ($currlim eq 'allstudents') {
6149: $crslimit = ' checked="checked" ';
6150: $selflimit = ' ';
6151: $nolimit = ' ';
6152: } elsif ($currlim eq 'selfenrolled') {
6153: $crslimit = ' ';
6154: $selflimit = ' checked="checked" ';
6155: $nolimit = ' ';
6156: } else {
6157: $crslimit = ' ';
6158: $selflimit = ' ';
6159: $nolimit = ' checked="checked" ';
6160: }
6161: $output .= '<table><tr><td><label>'.
6162: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
6163: &mt('No limit').'</label></td><td><label>'.
6164: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
6165: &mt('Limit by total students').'</label></td><td><label>'.
6166: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
6167: &mt('Limit by total self-enrolled students').
6168: '</td></tr><tr>'.
6169: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6170: (' 'x3).&mt('Maximum number allowed: ').
6171: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
6172: }
6173: $output .= &Apache::lonhtmlcommon::row_closure(1);
6174: }
6175: }
6176: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6177: unless ($readonly) {
6178: $output .= '<input type="button" name="selfenrollconf" value="'
6179: .&mt('Save').'" onclick="validate_types(this.form);" />';
6180: }
6181: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6182: .'<input type="hidden" name="state" value="done" />'."\n"
6183: .$additional.'</form>';
6184: $r->print($output);
6185: return;
6186: }
6187:
6188: sub get_noedit_fields {
6189: my ($cdom,$cnum,$crstype,$row) = @_;
6190: my %noedit;
6191: if (ref($row) eq 'ARRAY') {
6192: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6193: 'internal.selfenrollmgrdc',
6194: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6195: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6196: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6197: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6198: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6199: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6200: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6201:
6202: foreach my $item (@{$row}) {
6203: next if ($specific_managebycc{$item});
6204: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6205: $noedit{$item} = 1;
6206: }
6207: }
6208: }
6209: return %noedit;
6210: }
6211:
6212: sub visible_in_stdcat {
6213: my ($cdom,$cnum,$domconf) = @_;
6214: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6215: unless (ref($domconf) eq 'HASH') {
6216: return ($visible,$cansetvis,\@vismsgs);
6217: }
6218: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6219: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
6220: $settable{'togglecats'} = 1;
6221: }
6222: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
6223: $settable{'categorize'} = 1;
6224: }
6225: $cathash = $domconf->{'coursecategories'}{'cats'};
6226: }
6227: if ($settable{'togglecats'} && $settable{'categorize'}) {
6228: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6229: } elsif ($settable{'togglecats'}) {
6230: $cansetvis = &mt('You are able to choose to exclude this course from the catalog, but only a Domain Coordinator may assign a course category.');
6231: } elsif ($settable{'categorize'}) {
6232: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6233: } else {
6234: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6235: }
6236:
6237: my %currsettings =
6238: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6239: $cdom,$cnum);
6240: $visible = 0;
6241: if ($currsettings{'internal.coursecode'} ne '') {
6242: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6243: $cathash = $domconf->{'coursecategories'}{'cats'};
6244: if (ref($cathash) eq 'HASH') {
6245: if ($cathash->{'instcode::0'} eq '') {
6246: push(@vismsgs,'dc_addinst');
6247: } else {
6248: $visible = 1;
6249: }
6250: } else {
6251: $visible = 1;
6252: }
6253: } else {
6254: $visible = 1;
6255: }
6256: } else {
6257: if (ref($cathash) eq 'HASH') {
6258: if ($cathash->{'instcode::0'} ne '') {
6259: push(@vismsgs,'dc_instcode');
6260: }
6261: } else {
6262: push(@vismsgs,'dc_instcode');
6263: }
6264: }
6265: if ($currsettings{'categories'} ne '') {
6266: my $cathash;
6267: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6268: $cathash = $domconf->{'coursecategories'}{'cats'};
6269: if (ref($cathash) eq 'HASH') {
6270: if (keys(%{$cathash}) == 0) {
6271: push(@vismsgs,'dc_catalog');
6272: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6273: push(@vismsgs,'dc_categories');
6274: } else {
6275: my @currcategories = split('&',$currsettings{'categories'});
6276: my $matched = 0;
6277: foreach my $cat (@currcategories) {
6278: if ($cathash->{$cat} ne '') {
6279: $visible = 1;
6280: $matched = 1;
6281: last;
6282: }
6283: }
6284: if (!$matched) {
6285: if ($settable{'categorize'}) {
6286: push(@vismsgs,'chgcat');
6287: } else {
6288: push(@vismsgs,'dc_chgcat');
6289: }
6290: }
6291: }
6292: }
6293: }
6294: } else {
6295: if (ref($cathash) eq 'HASH') {
6296: if ((keys(%{$cathash}) > 1) ||
6297: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
6298: if ($settable{'categorize'}) {
6299: push(@vismsgs,'addcat');
6300: } else {
6301: push(@vismsgs,'dc_addcat');
6302: }
6303: }
6304: }
6305: }
6306: if ($currsettings{'hidefromcat'} eq 'yes') {
6307: $visible = 0;
6308: if ($settable{'togglecats'}) {
6309: unshift(@vismsgs,'unhide');
6310: } else {
6311: unshift(@vismsgs,'dc_unhide')
6312: }
6313: }
6314: return ($visible,$cansetvis,\@vismsgs);
6315: }
6316:
6317: sub cat_visibility {
6318: my %visactions = &Apache::lonlocal::texthash(
6319: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6320: 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.',
6321: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6322: none => 'Display of a course catalog is disabled for this domain.',
6323: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6324: 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.',
6325: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6326: take => 'Take the following action to ensure the course appears in the Catalog:',
6327: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6328: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6329: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6330: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6331: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6332: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6333: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6334: 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',
6335: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6336: );
6337: $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>"');
6338: $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>"');
6339: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6340: return \%visactions;
6341: }
6342:
6343: sub new_selfenroll_dom_row {
6344: my ($newdom,$num) = @_;
6345: my $domdesc = &Apache::lonnet::domain($newdom);
6346: my $output;
6347: if ($domdesc ne '') {
6348: $output .= &Apache::loncommon::start_data_table_row()
6349: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6350: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
6351: .'" value="'.$newdom.'" /></span><br />'
6352: .'<span class="LC_nobreak"><label><input type="checkbox" '
6353: .'name="selfenroll_activate" value="'.$num.'" '
6354: .'onchange="javascript:update_types('
6355: ."'selfenroll_activate','$num'".');" />'
6356: .&mt('Activate').'</label></span></td>';
6357: my @currinsttypes;
6358: $output .= '<td>'.&mt('User types:').'<br />'
6359: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6360: .&Apache::loncommon::end_data_table_row();
6361: }
6362: return $output;
6363: }
6364:
6365: sub selfenroll_inst_types {
6366: my ($num,$currdom,$currinsttypes,$readonly) = @_;
6367: my $output;
6368: my $numinrow = 4;
6369: my $count = 0;
6370: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
6371: my $othervalue = 'any';
6372: my $disabled;
6373: if ($readonly) {
6374: $disabled = ' disabled="disabled"';
6375: }
6376: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6377: if (keys(%{$usertypes}) > 0) {
6378: $othervalue = 'other';
6379: }
6380: $output .= '<table><tr>';
6381: foreach my $type (@{$types}) {
6382: if (($count > 0) && ($count%$numinrow == 0)) {
6383: $output .= '</tr><tr>';
6384: }
6385: if (defined($usertypes->{$type})) {
6386: my $esc_type = &escape($type);
6387: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
6388: $esc_type.'" ';
6389: if (ref($currinsttypes) eq 'ARRAY') {
6390: if (@{$currinsttypes} > 0) {
6391: if (grep(/^any$/,@{$currinsttypes})) {
6392: $output .= 'checked="checked"';
6393: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
6394: $output .= 'checked="checked"';
6395: }
6396: } else {
6397: $output .= 'checked="checked"';
6398: }
6399: }
6400: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
6401: }
6402: $count ++;
6403: }
6404: if (($count > 0) && ($count%$numinrow == 0)) {
6405: $output .= '</tr><tr>';
6406: }
6407: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
6408: if (ref($currinsttypes) eq 'ARRAY') {
6409: if (@{$currinsttypes} > 0) {
6410: if (grep(/^any$/,@{$currinsttypes})) {
6411: $output .= ' checked="checked"';
6412: } elsif ($othervalue eq 'other') {
6413: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6414: $output .= ' checked="checked"';
6415: }
6416: }
6417: } else {
6418: $output .= ' checked="checked"';
6419: }
6420: } else {
6421: $output .= ' checked="checked"';
6422: }
6423: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
6424: }
6425: return $output;
6426: }
6427:
6428: sub selfenroll_date_forms {
6429: my ($startform,$endform) = @_;
6430: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
6431: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
6432: 'LC_oddrow_value')."\n".
6433: $startform."\n".
6434: &Apache::lonhtmlcommon::row_closure(1).
6435: &Apache::lonhtmlcommon::row_title(&mt('End date'),
6436: 'LC_oddrow_value')."\n".
6437: $endform."\n".
6438: &Apache::lonhtmlcommon::row_closure(1).
6439: &Apache::lonhtmlcommon::end_pick_box();
6440: return $output;
6441: }
6442:
6443: sub print_userchangelogs_display {
6444: my ($r,$context,$permission,$brcrum) = @_;
6445: my $formname = 'rolelog';
6446: my ($username,$domain,$crstype,$viewablesec,%roleslog);
6447: if ($context eq 'domain') {
6448: $domain = $env{'request.role.domain'};
6449: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6450: } else {
6451: if ($context eq 'course') {
6452: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6453: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6454: $crstype = &Apache::loncommon::course_type();
6455: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
6456: my %saveable_parameters = ('show' => 'scalar',);
6457: &Apache::loncommon::store_course_settings('roles_log',
6458: \%saveable_parameters);
6459: &Apache::loncommon::restore_course_settings('roles_log',
6460: \%saveable_parameters);
6461: } elsif ($context eq 'author') {
6462: $domain = $env{'user.domain'};
6463: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6464: $username = $env{'user.name'};
6465: } else {
6466: undef($domain);
6467: }
6468: }
6469: if ($domain ne '' && $username ne '') {
6470: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6471: }
6472: }
6473: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6474:
6475: my $helpitem;
6476: if ($context eq 'course') {
6477: $helpitem = 'Course_User_Logs';
6478: }
6479: push (@{$brcrum},
6480: {href => '/adm/createuser?action=changelogs',
6481: text => 'User Management Logs',
6482: help => $helpitem});
6483: my $bread_crumbs_component = 'User Changes';
6484: my $args = { bread_crumbs => $brcrum,
6485: bread_crumbs_component => $bread_crumbs_component};
6486:
6487: # Create navigation javascript
6488: my $jsnav = &userlogdisplay_js($formname);
6489:
6490: my $jscript = (<<ENDSCRIPT);
6491: <script type="text/javascript">
6492: // <![CDATA[
6493: $jsnav
6494: // ]]>
6495: </script>
6496: ENDSCRIPT
6497:
6498: # print page header
6499: $r->print(&header($jscript,$args));
6500:
6501: # set defaults
6502: my $now = time();
6503: my $defstart = $now - (7*24*3600); #7 days ago
6504: my %defaults = (
6505: page => '1',
6506: show => '10',
6507: role => 'any',
6508: chgcontext => 'any',
6509: rolelog_start_date => $defstart,
6510: rolelog_end_date => $now,
6511: );
6512: my $more_records = 0;
6513:
6514: # set current
6515: my %curr;
6516: foreach my $item ('show','page','role','chgcontext') {
6517: $curr{$item} = $env{'form.'.$item};
6518: }
6519: my ($startdate,$enddate) =
6520: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6521: $curr{'rolelog_start_date'} = $startdate;
6522: $curr{'rolelog_end_date'} = $enddate;
6523: foreach my $key (keys(%defaults)) {
6524: if ($curr{$key} eq '') {
6525: $curr{$key} = $defaults{$key};
6526: }
6527: }
6528: my (%whodunit,%changed,$version);
6529: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
6530: my ($minshown,$maxshown);
6531: $minshown = 1;
6532: my $count = 0;
6533: if ($curr{'show'} =~ /\D/) {
6534: $curr{'page'} = 1;
6535: } else {
6536: $maxshown = $curr{'page'} * $curr{'show'};
6537: if ($curr{'page'} > 1) {
6538: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6539: }
6540: }
6541:
6542: # Form Header
6543: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
6544: &role_display_filter($context,$formname,$domain,$username,\%curr,
6545: $version,$crstype));
6546:
6547: my $showntableheader = 0;
6548:
6549: # Table Header
6550: my $tableheader =
6551: &Apache::loncommon::start_data_table_header_row()
6552: .'<th> </th>'
6553: .'<th>'.&mt('When').'</th>'
6554: .'<th>'.&mt('Who made the change').'</th>'
6555: .'<th>'.&mt('Changed User').'</th>'
6556: .'<th>'.&mt('Role').'</th>';
6557:
6558: if ($context eq 'course') {
6559: $tableheader .= '<th>'.&mt('Section').'</th>';
6560: }
6561: $tableheader .=
6562: '<th>'.&mt('Context').'</th>'
6563: .'<th>'.&mt('Start').'</th>'
6564: .'<th>'.&mt('End').'</th>'
6565: .&Apache::loncommon::end_data_table_header_row();
6566:
6567: # Display user change log data
6568: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6569: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6570: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
6571: if ($curr{'show'} !~ /\D/) {
6572: if ($count >= $curr{'page'} * $curr{'show'}) {
6573: $more_records = 1;
6574: last;
6575: }
6576: }
6577: if ($curr{'role'} ne 'any') {
6578: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6579: }
6580: if ($curr{'chgcontext'} ne 'any') {
6581: if ($curr{'chgcontext'} eq 'selfenroll') {
6582: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6583: } else {
6584: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6585: }
6586: }
6587: if (($context eq 'course') && ($viewablesec ne '')) {
6588: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
6589: }
6590: $count ++;
6591: next if ($count < $minshown);
6592: unless ($showntableheader) {
6593: $r->print(&Apache::loncommon::start_data_table()
6594: .$tableheader);
6595: $r->rflush();
6596: $showntableheader = 1;
6597: }
6598: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6599: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6600: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6601: }
6602: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6603: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6604: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6605: }
6606: my $sec = $roleslog{$id}{'logentry'}{'section'};
6607: if ($sec eq '') {
6608: $sec = &mt('None');
6609: }
6610: my ($rolestart,$roleend);
6611: if ($roleslog{$id}{'delflag'}) {
6612: $rolestart = &mt('deleted');
6613: $roleend = &mt('deleted');
6614: } else {
6615: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6616: $roleend = $roleslog{$id}{'logentry'}{'end'};
6617: if ($rolestart eq '' || $rolestart == 0) {
6618: $rolestart = &mt('No start date');
6619: } else {
6620: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6621: }
6622: if ($roleend eq '' || $roleend == 0) {
6623: $roleend = &mt('No end date');
6624: } else {
6625: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6626: }
6627: }
6628: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6629: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6630: $chgcontext = 'selfenroll';
6631: }
6632: my %lt = &rolechg_contexts($context,$crstype);
6633: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6634: $chgcontext = $lt{$chgcontext};
6635: }
6636: $r->print(
6637: &Apache::loncommon::start_data_table_row()
6638: .'<td>'.$count.'</td>'
6639: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6640: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6641: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
6642: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6643: if ($context eq 'course') {
6644: $r->print('<td>'.$sec.'</td>');
6645: }
6646: $r->print(
6647: '<td>'.$chgcontext.'</td>'
6648: .'<td>'.$rolestart.'</td>'
6649: .'<td>'.$roleend.'</td>'
6650: .&Apache::loncommon::end_data_table_row()."\n");
6651: }
6652:
6653: if ($showntableheader) { # Table footer, if content displayed above
6654: $r->print(&Apache::loncommon::end_data_table().
6655: &userlogdisplay_navlinks(\%curr,$more_records));
6656: } else { # No content displayed above
6657: $r->print('<p class="LC_info">'
6658: .&mt('There are no records to display.')
6659: .'</p>'
6660: );
6661: }
6662:
6663: # Form Footer
6664: $r->print(
6665: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6666: .'<input type="hidden" name="action" value="changelogs" />'
6667: .'</form>');
6668: return;
6669: }
6670:
6671: sub print_useraccesslogs_display {
6672: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6673: my $formname = 'accesslog';
6674: my $form = 'document.accesslog';
6675:
6676: # set breadcrumbs
6677: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
6678: push (@{$brcrum},
6679: {href => "javascript:backPage($form)",
6680: text => $breadcrumb_text{'search'}});
6681: my (@prevphases,$prevphasestr);
6682: if ($env{'form.prevphases'}) {
6683: @prevphases = split(/,/,$env{'form.prevphases'});
6684: $prevphasestr = $env{'form.prevphases'};
6685: }
6686: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6687: push(@{$brcrum},
6688: {href => "javascript:backPage($form,'get_user_info','select')",
6689: text => $breadcrumb_text{'userpicked'}});
6690: if ($env{'form.phase'} eq 'userpicked') {
6691: $prevphasestr = 'userpicked';
6692: }
6693: }
6694: push(@{$brcrum},
6695: {href => '/adm/createuser?action=accesslogs',
6696: text => 'User access logs',
6697: help => 'Domain_User_Access_Logs'});
6698: my $bread_crumbs_component = 'User Access Logs';
6699: my $args = { bread_crumbs => $brcrum,
6700: bread_crumbs_component => 'User Management'};
6701: if ($env{'form.popup'}) {
6702: $args->{'no_nav_bar'} = 1;
6703: }
6704:
6705: # set javascript
6706: my ($jsback,$elements) = &crumb_utilities();
6707: my $jsnav = &userlogdisplay_js($formname);
6708:
6709: my $jscript = (<<ENDSCRIPT);
6710: <script type="text/javascript">
6711: // <![CDATA[
6712:
6713: $jsback
6714: $jsnav
6715:
6716: // ]]>
6717: </script>
6718:
6719: ENDSCRIPT
6720:
6721: # print page header
6722: $r->print(&header($jscript,$args));
6723:
6724: # early out unless log data can be displayed.
6725: unless ($permission->{'activity'}) {
6726: $r->print('<p class="LC_warning">'
6727: .&mt('You do not have rights to display user access logs.')
6728: .'</p>'
6729: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6730: return;
6731: }
6732:
6733: unless ($udom eq $env{'request.role.domain'}) {
6734: $r->print('<p class="LC_warning">'
6735: .&mt("User's domain must match role's domain")
6736: .'</p>'
6737: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6738: return;
6739: }
6740:
6741: if (($uname eq '') || ($udom eq '')) {
6742: $r->print('<p class="LC_warning">'
6743: .&mt('Invalid username or domain')
6744: .'</p>'
6745: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6746: return;
6747: }
6748:
6749: # set defaults
6750: my $now = time();
6751: my $defstart = $now - (7*24*3600);
6752: my %defaults = (
6753: page => '1',
6754: show => '10',
6755: activity => 'any',
6756: accesslog_start_date => $defstart,
6757: accesslog_end_date => $now,
6758: );
6759: my $more_records = 0;
6760:
6761: # set current
6762: my %curr;
6763: foreach my $item ('show','page','activity') {
6764: $curr{$item} = $env{'form.'.$item};
6765: }
6766: my ($startdate,$enddate) =
6767: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
6768: $curr{'accesslog_start_date'} = $startdate;
6769: $curr{'accesslog_end_date'} = $enddate;
6770: foreach my $key (keys(%defaults)) {
6771: if ($curr{$key} eq '') {
6772: $curr{$key} = $defaults{$key};
6773: }
6774: }
6775: my ($minshown,$maxshown);
6776: $minshown = 1;
6777: my $count = 0;
6778: if ($curr{'show'} =~ /\D/) {
6779: $curr{'page'} = 1;
6780: } else {
6781: $maxshown = $curr{'page'} * $curr{'show'};
6782: if ($curr{'page'} > 1) {
6783: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6784: }
6785: }
6786:
6787: # form header
6788: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
6789: &activity_display_filter($formname,\%curr));
6790:
6791: my $showntableheader = 0;
6792: my ($nav_script,$nav_links);
6793:
6794: # table header
6795: my $tableheader =
6796: &Apache::loncommon::start_data_table_header_row()
6797: .'<th> </th>'
6798: .'<th>'.&mt('When').'</th>'
6799: .'<th>'.&mt('HostID').'</th>'
6800: .'<th>'.&mt('Event').'</th>'
6801: .'<th>'.&mt('Other data').'</th>'
6802: .&Apache::loncommon::end_data_table_header_row();
6803:
6804: my %filters=(
6805: start => $curr{'accesslog_start_date'},
6806: end => $curr{'accesslog_end_date'},
6807: action => $curr{'activity'},
6808: );
6809:
6810: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
6811: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
6812: my (%courses,%missing);
6813: my @results = split(/\&/,$reply);
6814: foreach my $item (reverse(@results)) {
6815: my ($timestamp,$host,$event) = split(/:/,$item);
6816: next unless ($event =~ /^(Log|Role)/);
6817: if ($curr{'show'} !~ /\D/) {
6818: if ($count >= $curr{'page'} * $curr{'show'}) {
6819: $more_records = 1;
6820: last;
6821: }
6822: }
6823: $count ++;
6824: next if ($count < $minshown);
6825: unless ($showntableheader) {
6826: $r->print($nav_script
6827: .&Apache::loncommon::start_data_table()
6828: .$tableheader);
6829: $r->rflush();
6830: $showntableheader = 1;
6831: }
6832: my ($shown,$extra);
6833: my ($event,$data) = split(/\s+/,&unescape($event));
6834: if ($event eq 'Role') {
6835: my ($rolecode,$extent) = split(/\./,$data,2);
6836: next if ($extent eq '');
6837: my ($crstype,$desc,$info);
6838: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
6839: my ($cdom,$cnum,$sec) = ($1,$2,$3);
6840: my $cid = $cdom.'_'.$cnum;
6841: if (exists($courses{$cid})) {
6842: $crstype = $courses{$cid}{'type'};
6843: $desc = $courses{$cid}{'description'};
6844: } elsif ($missing{$cid}) {
6845: $crstype = 'Course';
6846: $desc = 'Course/Community';
6847: } else {
6848: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
6849: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
6850: $courses{$cid} = $crsinfo{$cid};
6851: $crstype = $crsinfo{$cid}{'type'};
6852: $desc = $crsinfo{$cid}{'description'};
6853: } else {
6854: $missing{$cid} = 1;
6855: }
6856: }
6857: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
6858: if ($sec ne '') {
6859: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
6860: }
6861: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
6862: my ($dom,$name) = ($1,$2);
6863: if ($rolecode eq 'au') {
6864: $extra = '';
6865: } elsif ($rolecode =~ /^(ca|aa)$/) {
6866: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
6867: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
6868: $extra = &mt('Domain: [_1]',$dom);
6869: }
6870: }
6871: my $rolename;
6872: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
6873: my $role = $3;
6874: my $owner = "($2:$1)";
6875: if ($2 eq $1.'-domainconfig') {
6876: $owner = '(ad hoc)';
6877: }
6878: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
6879: } else {
6880: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
6881: }
6882: $shown = &mt('Role selection: [_1]',$rolename);
6883: } else {
6884: $shown = &mt($event);
6885: if ($data ne '') {
6886: $extra = &mt('Client IP address: [_1]',$data);
6887: }
6888: }
6889: $r->print(
6890: &Apache::loncommon::start_data_table_row()
6891: .'<td>'.$count.'</td>'
6892: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
6893: .'<td>'.$host.'</td>'
6894: .'<td>'.$shown.'</td>'
6895: .'<td>'.$extra.'</td>'
6896: .&Apache::loncommon::end_data_table_row()."\n");
6897: }
6898: }
6899:
6900: if ($showntableheader) { # Table footer, if content displayed above
6901: $r->print(&Apache::loncommon::end_data_table().
6902: &userlogdisplay_navlinks(\%curr,$more_records));
6903: } else { # No content displayed above
6904: $r->print('<p class="LC_info">'
6905: .&mt('There are no records to display.')
6906: .'</p>');
6907: }
6908:
6909: if ($env{'form.popup'} == 1) {
6910: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
6911: }
6912:
6913: # Form Footer
6914: $r->print(
6915: '<input type="hidden" name="currstate" value="" />'
6916: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
6917: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
6918: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6919: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
6920: .'<input type="hidden" name="phase" value="activity" />'
6921: .'<input type="hidden" name="action" value="accesslogs" />'
6922: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
6923: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
6924: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
6925: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
6926: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
6927: .'</form>');
6928: return;
6929: }
6930:
6931: sub earlyout_accesslog_form {
6932: my ($formname,$prevphasestr,$udom) = @_;
6933: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
6934: return <<"END";
6935: <form action="/adm/createuser" method="post" name="$formname">
6936: <input type="hidden" name="currstate" value="" />
6937: <input type="hidden" name="prevphases" value="$prevphasestr" />
6938: <input type="hidden" name="phase" value="activity" />
6939: <input type="hidden" name="action" value="accesslogs" />
6940: <input type="hidden" name="srchdomain" value="$udom" />
6941: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
6942: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
6943: <input type="hidden" name="srchterm" value="$srchterm" />
6944: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
6945: </form>
6946: END
6947: }
6948:
6949: sub activity_display_filter {
6950: my ($formname,$curr) = @_;
6951: my $nolink = 1;
6952: my $output = '<table><tr><td valign="top">'.
6953: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
6954: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
6955: (&mt('all'),5,10,20,50,100,1000,10000)).
6956: '</td><td> </td>';
6957: my $startform =
6958: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
6959: $curr->{'accesslog_start_date'},undef,
6960: undef,undef,undef,undef,undef,undef,$nolink);
6961: my $endform =
6962: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
6963: $curr->{'accesslog_end_date'},undef,
6964: undef,undef,undef,undef,undef,undef,$nolink);
6965: my %lt = &Apache::lonlocal::texthash (
6966: activity => 'Activity',
6967: Role => 'Role selection',
6968: log => 'Log-in or Logout',
6969: );
6970: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
6971: '<table><tr><td>'.&mt('After:').
6972: '</td><td>'.$startform.'</td></tr>'.
6973: '<tr><td>'.&mt('Before:').'</td>'.
6974: '<td>'.$endform.'</td></tr></table>'.
6975: '</td>'.
6976: '<td> </td>'.
6977: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
6978: '<select name="activity"><option value="any"';
6979: if ($curr->{'activity'} eq 'any') {
6980: $output .= ' selected="selected"';
6981: }
6982: $output .= '>'.&mt('Any').'</option>'."\n";
6983: foreach my $activity ('Role','log') {
6984: my $selstr = '';
6985: if ($activity eq $curr->{'activity'}) {
6986: $selstr = ' selected="selected"';
6987: }
6988: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
6989: }
6990: $output .= '</select></td>'.
6991: '</tr></table>';
6992: # Update Display button
6993: $output .= '<p>'
6994: .'<input type="submit" value="'.&mt('Update Display').'" />'
6995: .'</p>';
6996: return $output;
6997: }
6998:
6999: sub userlogdisplay_js {
7000: my ($formname) = @_;
7001: return <<"ENDSCRIPT";
7002:
7003: function chgPage(caller) {
7004: if (caller == 'previous') {
7005: document.$formname.page.value --;
7006: }
7007: if (caller == 'next') {
7008: document.$formname.page.value ++;
7009: }
7010: document.$formname.submit();
7011: return;
7012: }
7013: ENDSCRIPT
7014: }
7015:
7016: sub userlogdisplay_navlinks {
7017: my ($curr,$more_records) = @_;
7018: return unless(ref($curr) eq 'HASH');
7019: # Navigation Buttons
7020: my $nav_links = '<p>';
7021: if (($curr->{'page'} > 1) || ($more_records)) {
7022: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7023: $nav_links .= '<input type="button"'
7024: .' onclick="javascript:chgPage('."'previous'".');"'
7025: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7026: .'" /> ';
7027: }
7028: if ($more_records) {
7029: $nav_links .= '<input type="button"'
7030: .' onclick="javascript:chgPage('."'next'".');"'
7031: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7032: .'" />';
7033: }
7034: }
7035: $nav_links .= '</p>';
7036: return $nav_links;
7037: }
7038:
7039: sub role_display_filter {
7040: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7041: my $lctype;
7042: if ($context eq 'course') {
7043: $lctype = lc($crstype);
7044: }
7045: my $nolink = 1;
7046: my $output = '<table><tr><td valign="top">'.
7047: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
7048: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7049: (&mt('all'),5,10,20,50,100,1000,10000)).
7050: '</td><td> </td>';
7051: my $startform =
7052: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7053: $curr->{'rolelog_start_date'},undef,
7054: undef,undef,undef,undef,undef,undef,$nolink);
7055: my $endform =
7056: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7057: $curr->{'rolelog_end_date'},undef,
7058: undef,undef,undef,undef,undef,undef,$nolink);
7059: my %lt = &rolechg_contexts($context,$crstype);
7060: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7061: '<table><tr><td>'.&mt('After:').
7062: '</td><td>'.$startform.'</td></tr>'.
7063: '<tr><td>'.&mt('Before:').'</td>'.
7064: '<td>'.$endform.'</td></tr></table>'.
7065: '</td>'.
7066: '<td> </td>'.
7067: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7068: '<select name="role"><option value="any"';
7069: if ($curr->{'role'} eq 'any') {
7070: $output .= ' selected="selected"';
7071: }
7072: $output .= '>'.&mt('Any').'</option>'."\n";
7073: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
7074: foreach my $role (@roles) {
7075: my $plrole;
7076: if ($role eq 'cr') {
7077: $plrole = &mt('Custom Role');
7078: } else {
7079: $plrole=&Apache::lonnet::plaintext($role,$crstype);
7080: }
7081: my $selstr = '';
7082: if ($role eq $curr->{'role'}) {
7083: $selstr = ' selected="selected"';
7084: }
7085: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7086: }
7087: $output .= '</select></td>'.
7088: '<td> </td>'.
7089: '<td valign="top"><b>'.
7090: &mt('Context:').'</b><br /><select name="chgcontext">';
7091: my @posscontexts;
7092: if ($context eq 'course') {
7093: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
7094: } elsif ($context eq 'domain') {
7095: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7096: } else {
7097: @posscontexts = ('any','author','domain');
7098: }
7099: foreach my $chgtype (@posscontexts) {
7100: my $selstr = '';
7101: if ($curr->{'chgcontext'} eq $chgtype) {
7102: $selstr = ' selected="selected"';
7103: }
7104: if ($context eq 'course') {
7105: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
7106: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7107: }
7108: }
7109: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
7110: }
7111: $output .= '</select></td>'
7112: .'</tr></table>';
7113:
7114: # Update Display button
7115: $output .= '<p>'
7116: .'<input type="submit" value="'.&mt('Update Display').'" />'
7117: .'</p>';
7118:
7119: # Server version info
7120: my $needsrev = '2.11.0';
7121: if ($context eq 'course') {
7122: $needsrev = '2.7.0';
7123: }
7124:
7125: $output .= '<p class="LC_info">'
7126: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
7127: ,$needsrev);
7128: if ($version) {
7129: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7130: }
7131: $output .= '</p><hr />';
7132: return $output;
7133: }
7134:
7135: sub rolechg_contexts {
7136: my ($context,$crstype) = @_;
7137: my %lt;
7138: if ($context eq 'course') {
7139: %lt = &Apache::lonlocal::texthash (
7140: any => 'Any',
7141: automated => 'Automated Enrollment',
7142: updatenow => 'Roster Update',
7143: createcourse => 'Course Creation',
7144: course => 'User Management in course',
7145: domain => 'User Management in domain',
7146: selfenroll => 'Self-enrolled',
7147: requestcourses => 'Course Request',
7148: );
7149: if ($crstype eq 'Community') {
7150: $lt{'createcourse'} = &mt('Community Creation');
7151: $lt{'course'} = &mt('User Management in community');
7152: $lt{'requestcourses'} = &mt('Community Request');
7153: }
7154: } elsif ($context eq 'domain') {
7155: %lt = &Apache::lonlocal::texthash (
7156: any => 'Any',
7157: domain => 'User Management in domain',
7158: requestauthor => 'Authoring Request',
7159: server => 'Command line script (DC role)',
7160: domconfig => 'Self-enrolled',
7161: );
7162: } else {
7163: %lt = &Apache::lonlocal::texthash (
7164: any => 'Any',
7165: domain => 'User Management in domain',
7166: author => 'User Management by author',
7167: );
7168: }
7169: return %lt;
7170: }
7171:
7172: sub print_helpdeskaccess_display {
7173: my ($r,$permission,$brcrum) = @_;
7174: my $formname = 'helpdeskaccess';
7175: my $helpitem = 'Course_Helpdesk_Access';
7176: push (@{$brcrum},
7177: {href => '/adm/createuser?action=helpdesk',
7178: text => 'Helpdesk Access',
7179: help => $helpitem});
7180: my $bread_crumbs_component = 'Helpdesk Staff Access';
7181: my $args = { bread_crumbs => $brcrum,
7182: bread_crumbs_component => $bread_crumbs_component};
7183:
7184: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7185: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7186: my $confname = $cdom.'-domainconfig';
7187: my $crstype = &Apache::loncommon::course_type();
7188:
7189: my @accesstypes = ('all','none');
7190: my ($numstatustypes,@jsarray);
7191: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7192: if (ref($types) eq 'ARRAY') {
7193: if (@{$types} > 0) {
7194: $numstatustypes = scalar(@{$types});
7195: push(@accesstypes,'status');
7196: @jsarray = ('bystatus');
7197: }
7198: }
7199: my %customroles = &get_domain_customroles($cdom,$confname);
7200: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh']);
7201: if (keys(%domhelpdesk)) {
7202: push(@accesstypes,('inc','exc'));
7203: push(@jsarray,('notinc','notexc'));
7204: }
7205: push(@jsarray,'privs');
7206: my $hiddenstr = join("','",@jsarray);
7207: my $rolestr = join("','",sort(keys(%customroles)));
7208:
7209: my $jscript;
7210: my (%settings,%overridden);
7211: if (keys(%customroles)) {
7212: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7213: $types,\%customroles,\%settings,\%overridden);
7214: my %jsfull=();
7215: my %jslevels= (
7216: course => {},
7217: domain => {},
7218: system => {},
7219: );
7220: my %jslevelscurrent=(
7221: course => {},
7222: domain => {},
7223: system => {},
7224: );
7225: my (%privs,%jsprivs);
7226: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7227: foreach my $priv (keys(%jsfull)) {
7228: if ($jslevels{'course'}{$priv}) {
7229: $jsprivs{$priv} = 1;
7230: }
7231: }
7232: my (%elements,%stored);
7233: foreach my $role (keys(%customroles)) {
7234: $elements{$role.'_access'} = 'radio';
7235: $elements{$role.'_incrs'} = 'radio';
7236: if ($numstatustypes) {
7237: $elements{$role.'_status'} = 'checkbox';
7238: }
7239: if (keys(%domhelpdesk) > 0) {
7240: $elements{$role.'_staff_inc'} = 'checkbox';
7241: $elements{$role.'_staff_exc'} = 'checkbox';
7242: }
7243: $elements{$role.'_override'} = 'checkbox';
7244: if (ref($settings{$role}) eq 'HASH') {
7245: if ($settings{$role}{'access'} ne '') {
7246: my $curraccess = $settings{$role}{'access'};
7247: $stored{$role.'_access'} = $curraccess;
7248: $stored{$role.'_incrs'} = 1;
7249: if ($curraccess eq 'status') {
7250: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7251: $stored{$role.'_status'} = $settings{$role}{'status'};
7252: }
7253: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7254: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7255: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7256: }
7257: }
7258: } else {
7259: $stored{$role.'_incrs'} = 0;
7260: }
7261: $stored{$role.'_override'} = [];
7262: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7263: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7264: foreach my $priv (@{$settings{$role}{'off'}}) {
7265: push(@{$stored{$role.'_override'}},$priv);
7266: }
7267: }
7268: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7269: foreach my $priv (@{$settings{$role}{'on'}}) {
7270: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7271: push(@{$stored{$role.'_override'}},$priv);
7272: }
7273: }
7274: }
7275: }
7276: } else {
7277: $stored{$role.'_incrs'} = 0;
7278: }
7279: }
7280: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7281: }
7282:
7283: my $js = <<"ENDJS";
7284: <script type="text/javascript">
7285: // <![CDATA[
7286: $jscript;
7287:
7288: function switchRoleTab(caller,role) {
7289: if (document.getElementById(role+'_maindiv')) {
7290: if (caller.id != 'LC_current_minitab') {
7291: if (document.getElementById('LC_current_minitab')) {
7292: document.getElementById('LC_current_minitab').id=null;
7293: }
7294: var roledivs = Array('$rolestr');
7295: if (roledivs.length > 0) {
7296: for (var i=0; i<roledivs.length; i++) {
7297: if (document.getElementById(roledivs[i]+'_maindiv')) {
7298: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7299: }
7300: }
7301: }
7302: caller.id = 'LC_current_minitab';
7303: document.getElementById(role+'_maindiv').style.display='block';
7304: }
7305: }
7306: return false;
7307: }
7308:
7309: function helpdeskAccess(role) {
7310: var curraccess = null;
7311: if (document.$formname.elements[role+'_access'].length) {
7312: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7313: if (document.$formname.elements[role+'_access'][i].checked) {
7314: curraccess = document.$formname.elements[role+'_access'][i].value;
7315: }
7316: }
7317: }
7318: var shown = Array();
7319: var hidden = Array();
7320: if (curraccess == 'none') {
7321: hidden = Array ('$hiddenstr');
7322: } else {
7323: if (curraccess == 'status') {
7324: shown = Array ('bystatus','privs');
7325: hidden = Array ('notinc','notexc');
7326: } else {
7327: if (curraccess == 'exc') {
7328: shown = Array ('notexc','privs');
7329: hidden = Array ('notinc','bystatus');
7330: }
7331: if (curraccess == 'inc') {
7332: shown = Array ('notinc','privs');
7333: hidden = Array ('notexc','bystatus');
7334: }
7335: if (curraccess == 'all') {
7336: shown = Array ('privs');
7337: hidden = Array ('notinc','notexc','bystatus');
7338: }
7339: }
7340: }
7341: if (hidden.length > 0) {
7342: for (var i=0; i<hidden.length; i++) {
7343: if (document.getElementById(role+'_'+hidden[i])) {
7344: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
7345: }
7346: }
7347: }
7348: if (shown.length > 0) {
7349: for (var i=0; i<shown.length; i++) {
7350: if (document.getElementById(role+'_'+shown[i])) {
7351: if (shown[i] == 'privs') {
7352: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7353: } else {
7354: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7355: }
7356: }
7357: }
7358: }
7359: return;
7360: }
7361:
7362: function toggleAccess(role) {
7363: if ((document.getElementById(role+'_setincrs')) &&
7364: (document.getElementById(role+'_setindom'))) {
7365: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7366: if (document.$formname.elements[role+'_incrs'][i].checked) {
7367: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7368: document.getElementById(role+'_setindom').style.display = 'none';
7369: document.getElementById(role+'_setincrs').style.display = 'block';
7370: } else {
7371: document.getElementById(role+'_setincrs').style.display = 'none';
7372: document.getElementById(role+'_setindom').style.display = 'block';
7373: }
7374: break;
7375: }
7376: }
7377: }
7378: return;
7379: }
7380:
7381: // ]]>
7382: </script>
7383: ENDJS
7384:
7385: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7386:
7387: # print page header
7388: $r->print(&header($js,$args));
7389: # print form header
7390: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7391:
7392: if (keys(%customroles)) {
7393: my %lt = &Apache::lonlocal::texthash(
7394: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7395: 'rou' => 'Role usage',
7396: 'whi' => 'Which helpdesk personnel may use this role?',
7397: 'udd' => 'Use domain default',
7398: 'all' => 'All',
7399: 'none' => 'None',
7400: 'status' => 'Determined based on institutional status',
7401: 'inc' => 'Include all, but exclude specific personnel',
7402: 'exc' => 'Exclude all, but include specific personnel',
7403: 'hel' => 'Helpdesk',
7404: 'rpr' => 'Role privileges',
7405: );
7406: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7407: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7408: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7409: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7410: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7411: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7412: }
7413: }
7414: my $count = 0;
7415: foreach my $role (sort(keys(%customroles))) {
7416: my ($order,$desc,$access_in_dom);
7417: if (ref($domcurrent{$role}) eq 'HASH') {
7418: $order = $domcurrent{$role}{'order'};
7419: $desc = $domcurrent{$role}{'desc'};
7420: $access_in_dom = $domcurrent{$role}{'access'};
7421: }
7422: if ($order eq '') {
7423: $order = $count;
7424: }
7425: $ordered{$order} = $role;
7426: if ($desc ne '') {
7427: $description{$role} = $desc;
7428: } else {
7429: $description{$role}= $role;
7430: }
7431: $count++;
7432: }
7433: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7434: my @roles_by_num = ();
7435: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7436: push(@roles_by_num,$ordered{$item});
7437: }
7438: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
7439: if ($permission->{'owner'}) {
7440: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7441: $r->print('<input type="hidden" name="state" value="process" />'.
7442: '<input type="submit" value="'.&mt('Save changes').'" />');
7443: } else {
7444: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7445: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7446: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7447: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7448: }
7449: $disabled = ' disabled="disabled"';
7450: }
7451: $r->print('</p>');
7452:
7453: $r->print('<div id="LC_minitab_header"><ul>');
7454: my $count = 0;
7455: my %visibility;
7456: foreach my $role (@roles_by_num) {
7457: my $id;
7458: if ($count == 0) {
7459: $id=' id="LC_current_minitab"';
7460: $visibility{$role} = ' style="display:block"';
7461: } else {
7462: $visibility{$role} = ' style="display:none"';
7463: }
7464: $count ++;
7465: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7466: }
7467: $r->print('</ul></div>');
7468:
7469: foreach my $role (@roles_by_num) {
7470: my %usecheck = (
7471: all => ' checked="checked"',
7472: );
7473: my %displaydiv = (
7474: status => 'none',
7475: inc => 'none',
7476: exc => 'none',
7477: priv => 'block',
7478: );
7479: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
7480: if (ref($settings{$role}) eq 'HASH') {
7481: if ($settings{$role}{'access'} ne '') {
7482: $indomvis = ' style="display:none"';
7483: $incrsvis = ' style="display:block"';
7484: $incrscheck = ' checked="checked"';
7485: if ($settings{$role}{'access'} ne 'all') {
7486: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7487: delete($usecheck{'all'});
7488: if ($settings{$role}{'access'} eq 'status') {
7489: my $access = 'status';
7490: $displaydiv{$access} = 'inline';
7491: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7492: $selected{$access} = $settings{$role}{$access};
7493: }
7494: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7495: my $access = $1;
7496: $displaydiv{$access} = 'inline';
7497: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7498: $selected{$access} = $settings{$role}{$access};
7499: }
7500: } elsif ($settings{$role}{'access'} eq 'none') {
7501: $displaydiv{'priv'} = 'none';
7502: }
7503: }
7504: } else {
7505: $indomcheck = ' checked="checked"';
7506: $indomvis = ' style="display:block"';
7507: $incrsvis = ' style="display:none"';
7508: }
7509: } else {
7510: $indomcheck = ' checked="checked"';
7511: $indomvis = ' style="display:block"';
7512: $incrsvis = ' style="display:none"';
7513: }
7514: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7515: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7516: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7517: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7518: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7519: '<span>'.(' 'x2).
7520: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7521: $lt{'udd'}.'</label><span></p>'.
7522: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7523: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7524: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7525: foreach my $access (@accesstypes) {
7526: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7527: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7528: if ($access eq 'status') {
7529: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7530: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7531: $othertitle,$usertypes,$types,$disabled).
7532: '</div>');
7533: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7534: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7535: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7536: \%domhelpdesk,$disabled).
7537: '</div>');
7538: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7539: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7540: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7541: \%domhelpdesk,$disabled).
7542: '</div>');
7543: }
7544: $r->print('</p>');
7545: }
7546: $r->print('</div></fieldset>');
7547: my %full=();
7548: my %levels= (
7549: course => {},
7550: domain => {},
7551: system => {},
7552: );
7553: my %levelscurrent=(
7554: course => {},
7555: domain => {},
7556: system => {},
7557: );
7558: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7559: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7560: '<legend>'.$lt{'rpr'}.'</legend>'.
7561: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7562: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7563: }
7564: if ($permission->{'owner'}) {
7565: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7566: }
7567: } else {
7568: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7569: }
7570: # Form Footer
7571: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7572: .'</form>');
7573: return;
7574: }
7575:
7576: sub domain_adhoc_access {
7577: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7578: my %domusage;
7579: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7580: foreach my $role (keys(%{$roles})) {
7581: if (ref($domcurrent->{$role}) eq 'HASH') {
7582: my $access = $domcurrent->{$role}{'access'};
7583: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7584: $access = 'all';
7585: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
7586: } elsif ($access eq 'status') {
7587: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7588: my @shown;
7589: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7590: unless ($type eq 'default') {
7591: if ($usertypes->{$type}) {
7592: push(@shown,$usertypes->{$type});
7593: }
7594: }
7595: }
7596: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7597: push(@shown,$othertitle);
7598: }
7599: if (@shown) {
7600: my $shownstatus = join(' '.&mt('or').' ',@shown);
7601: $domusage{$role} = &mt('Any user in domain with active [_1] role, and institutional status: [_2]',
7602: &Apache::lonnet::plaintext('dh'),$shownstatus);
7603: } else {
7604: $domusage{$role} = &mt('No one in the domain');
7605: }
7606: }
7607: } elsif ($access eq 'inc') {
7608: my @dominc = ();
7609: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7610: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7611: my ($uname,$udom) = split(/:/,$user);
7612: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7613: }
7614: my $showninc = join(', ',@dominc);
7615: if ($showninc ne '') {
7616: $domusage{$role} = &mt('Include any user in domain with active [_1] role, except: [_2]',
7617: &Apache::lonnet::plaintext('dh'),$showninc);
7618: } else {
7619: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
7620: }
7621: }
7622: } elsif ($access eq 'exc') {
7623: my @domexc = ();
7624: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7625: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7626: my ($uname,$udom) = split(/:/,$user);
7627: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7628: }
7629: }
7630: my $shownexc = join(', ',@domexc);
7631: if ($shownexc ne '') {
7632: $domusage{$role} = &mt('Only the following in the domain with active [_1] role: [_2]',
7633: &Apache::lonnet::plaintext('dh'),$shownexc);
7634: } else {
7635: $domusage{$role} = &mt('No one in the domain');
7636: }
7637: } elsif ($access eq 'none') {
7638: $domusage{$role} = &mt('No one in the domain');
7639: } elsif ($access eq 'all') {
7640: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
7641: }
7642: } else {
7643: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
7644: }
7645: }
7646: return %domusage;
7647: }
7648:
7649: sub get_domain_customroles {
7650: my ($cdom,$confname) = @_;
7651: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7652: my %customroles;
7653: foreach my $key (keys(%existing)) {
7654: if ($key=~/^rolesdef\_(\w+)$/) {
7655: my $rolename = $1;
7656: my %privs;
7657: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7658: $customroles{$rolename} = \%privs;
7659: }
7660: }
7661: return %customroles;
7662: }
7663:
7664: sub role_priv_table {
7665: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7666: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7667: (ref($levelscurrent) eq 'HASH'));
7668: my %lt=&Apache::lonlocal::texthash (
7669: 'crl' => 'Course Level Privilege',
7670: 'def' => 'Domain Defaults',
7671: 'ove' => 'Override in Course',
7672: 'ine' => 'In effect',
7673: 'dis' => 'Disabled',
7674: 'ena' => 'Enabled',
7675: );
7676: if ($crstype eq 'Community') {
7677: $lt{'ove'} = 'Override in Community',
7678: }
7679: my @status = ('Disabled','Enabled');
7680: my (%on,%off);
7681: if (ref($overridden) eq 'HASH') {
7682: if (ref($overridden->{'on'}) eq 'ARRAY') {
7683: map { $on{$_} = 1; } (@{$overridden->{'on'}});
7684: }
7685: if (ref($overridden->{'off'}) eq 'ARRAY') {
7686: map { $off{$_} = 1; } (@{$overridden->{'off'}});
7687: }
7688: }
7689: my $output=&Apache::loncommon::start_data_table().
7690: &Apache::loncommon::start_data_table_header_row().
7691: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
7692: '</th><th>'.$lt{'ine'}.'</th>'.
7693: &Apache::loncommon::end_data_table_header_row();
7694: foreach my $priv (sort(keys(%{$full}))) {
7695: next unless ($levels->{'course'}{$priv});
7696: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7697: my ($default,$ineffect);
7698: if ($levelscurrent->{'course'}{$priv}) {
7699: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7700: $ineffect = $default;
7701: }
7702: my ($customstatus,$checked);
7703: $output .= &Apache::loncommon::start_data_table_row().
7704: '<td>'.$privtext.'</td>'.
7705: '<td>'.$default.'</td><td>';
7706: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
7707: if ($permission->{'owner'}) {
7708: $checked = ' checked="checked"';
7709: }
7710: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
7711: $ineffect = $customstatus;
7712: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
7713: if ($permission->{'owner'}) {
7714: $checked = ' checked="checked"';
7715: }
7716: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7717: $ineffect = $customstatus;
7718: }
7719: if ($permission->{'owner'}) {
7720: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
7721: } else {
7722: $output .= $customstatus;
7723: }
7724: $output .= '</td><td>'.$ineffect.'</td>'.
7725: &Apache::loncommon::end_data_table_row();
7726: }
7727: $output .= &Apache::loncommon::end_data_table();
7728: return $output;
7729: }
7730:
7731: sub get_adhocrole_settings {
7732: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
7733: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
7734: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
7735: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
7736: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
7737: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
7738: $settings->{$role}{'access'} = $curraccess;
7739: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
7740: my @status = split(/,/,$rest);
7741: my @currstatus;
7742: foreach my $type (@status) {
7743: if ($type eq 'default') {
7744: push(@currstatus,$type);
7745: } elsif (grep(/^\Q$type\E$/,@{$types})) {
7746: push(@currstatus,$type);
7747: }
7748: }
7749: if (@currstatus) {
7750: $settings->{$role}{$curraccess} = \@currstatus;
7751: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7752: my @personnel = split(/,/,$rest);
7753: $settings->{$role}{$curraccess} = \@personnel;
7754: }
7755: }
7756: }
7757: }
7758: foreach my $role (keys(%{$customroles})) {
7759: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
7760: my %currentprivs;
7761: if (ref($customroles->{$role}) eq 'HASH') {
7762: if (exists($customroles->{$role}{'course'})) {
7763: my %full=();
7764: my %levels= (
7765: course => {},
7766: domain => {},
7767: system => {},
7768: );
7769: my %levelscurrent=(
7770: course => {},
7771: domain => {},
7772: system => {},
7773: );
7774: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
7775: %currentprivs = %{$levelscurrent{'course'}};
7776: }
7777: }
7778: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
7779: next if ($item eq '');
7780: my ($rule,$rest) = split(/=/,$item);
7781: next unless (($rule eq 'off') || ($rule eq 'on'));
7782: foreach my $priv (split(/:/,$rest)) {
7783: if ($priv ne '') {
7784: if ($rule eq 'off') {
7785: push(@{$overridden->{$role}{'off'}},$priv);
7786: if ($currentprivs{$priv}) {
7787: push(@{$settings->{$role}{'off'}},$priv);
7788: }
7789: } else {
7790: push(@{$overridden->{$role}{'on'}},$priv);
7791: unless ($currentprivs{$priv}) {
7792: push(@{$settings->{$role}{'on'}},$priv);
7793: }
7794: }
7795: }
7796: }
7797: }
7798: }
7799: }
7800: return;
7801: }
7802:
7803: sub update_helpdeskaccess {
7804: my ($r,$permission,$brcrum) = @_;
7805: my $helpitem = 'Course_Helpdesk_Access';
7806: push (@{$brcrum},
7807: {href => '/adm/createuser?action=helpdesk',
7808: text => 'Helpdesk Access',
7809: help => $helpitem},
7810: {href => '/adm/createuser?action=helpdesk',
7811: text => 'Result',
7812: help => $helpitem}
7813: );
7814: my $bread_crumbs_component = 'Helpdesk Staff Access';
7815: my $args = { bread_crumbs => $brcrum,
7816: bread_crumbs_component => $bread_crumbs_component};
7817:
7818: # print page header
7819: $r->print(&header('',$args));
7820: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
7821: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
7822: return;
7823: }
7824: my @accesstypes = ('all','none','status','inc','exc');
7825: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7826: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7827: my $confname = $cdom.'-domainconfig';
7828: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7829: my $crstype = &Apache::loncommon::course_type();
7830: my %customroles = &get_domain_customroles($cdom,$confname);
7831: my (%settings,%overridden);
7832: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7833: $types,\%customroles,\%settings,\%overridden);
7834: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh']);
7835: my (%changed,%storehash,@todelete);
7836:
7837: if (keys(%customroles)) {
7838: my (%newsettings,@incrs);
7839: foreach my $role (keys(%customroles)) {
7840: $newsettings{$role} = {
7841: access => '',
7842: status => '',
7843: exc => '',
7844: inc => '',
7845: on => '',
7846: off => '',
7847: };
7848: my %current;
7849: if (ref($settings{$role}) eq 'HASH') {
7850: %current = %{$settings{$role}};
7851: }
7852: if (ref($overridden{$role}) eq 'HASH') {
7853: $current{'overridden'} = $overridden{$role};
7854: }
7855: if ($env{'form.'.$role.'_incrs'}) {
7856: my $access = $env{'form.'.$role.'_access'};
7857: if (grep(/^\Q$access\E$/,@accesstypes)) {
7858: push(@incrs,$role);
7859: unless ($current{'access'} eq $access) {
7860: $changed{$role}{'access'} = 1;
7861: $storehash{'internal.adhoc.'.$role} = $access;
7862: }
7863: if ($access eq 'status') {
7864: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
7865: my @stored;
7866: my @shownstatus;
7867: if (ref($types) eq 'ARRAY') {
7868: foreach my $type (sort(@statuses)) {
7869: if ($type eq 'default') {
7870: push(@stored,$type);
7871: } elsif (grep(/^\Q$type\E$/,@{$types})) {
7872: push(@stored,$type);
7873: push(@shownstatus,$usertypes->{$type});
7874: }
7875: }
7876: if (grep(/^default$/,@statuses)) {
7877: push(@shownstatus,$othertitle);
7878: }
7879: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
7880: }
7881: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
7882: if (ref($current{'status'}) eq 'ARRAY') {
7883: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
7884: if (@diffs) {
7885: $changed{$role}{'status'} = 1;
7886: }
7887: } elsif (@stored) {
7888: $changed{$role}{'status'} = 1;
7889: }
7890: } elsif (($access eq 'inc') || ($access eq 'exc')) {
7891: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
7892: my @newspecstaff;
7893: my @stored;
7894: my @currstaff;
7895: foreach my $person (sort(@personnel)) {
7896: if ($domhelpdesk{$person}) {
7897: push(@stored,$person);
7898: }
7899: }
7900: if (ref($current{$access}) eq 'ARRAY') {
7901: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
7902: if (@diffs) {
7903: $changed{$role}{$access} = 1;
7904: }
7905: } elsif (@stored) {
7906: $changed{$role}{$access} = 1;
7907: }
7908: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
7909: foreach my $person (@stored) {
7910: my ($uname,$udom) = split(/:/,$person);
7911: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
7912: }
7913: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
7914: }
7915: $newsettings{$role}{'access'} = $access;
7916: }
7917: } else {
7918: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
7919: $changed{$role}{'access'} = 1;
7920: $newsettings{$role} = {};
7921: push(@todelete,'internal.adhoc.'.$role);
7922: }
7923: }
7924: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
7925: if (ref($current{'overridden'}) eq 'HASH') {
7926: push(@todelete,'internal.adhocpriv.'.$role);
7927: }
7928: } else {
7929: my %full=();
7930: my %levels= (
7931: course => {},
7932: domain => {},
7933: system => {},
7934: );
7935: my %levelscurrent=(
7936: course => {},
7937: domain => {},
7938: system => {},
7939: );
7940: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7941: my (@updatedon,@updatedoff,@override);
7942: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
7943: if (@override) {
7944: foreach my $priv (sort(keys(%full))) {
7945: next unless ($levels{'course'}{$priv});
7946: if (grep(/^\Q$priv\E$/,@override)) {
7947: if ($levelscurrent{'course'}{$priv}) {
7948: push(@updatedoff,$priv);
7949: } else {
7950: push(@updatedon,$priv);
7951: }
7952: }
7953: }
7954: }
7955: if (@updatedon) {
7956: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
7957: }
7958: if (@updatedoff) {
7959: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
7960: }
7961: if (ref($current{'overridden'}) eq 'HASH') {
7962: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
7963: if (@updatedon) {
7964: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
7965: if (@diffs) {
7966: $changed{$role}{'on'} = 1;
7967: }
7968: } else {
7969: $changed{$role}{'on'} = 1;
7970: }
7971: } elsif (@updatedon) {
7972: $changed{$role}{'on'} = 1;
7973: }
7974: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
7975: if (@updatedoff) {
7976: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
7977: if (@diffs) {
7978: $changed{$role}{'off'} = 1;
7979: }
7980: } else {
7981: $changed{$role}{'off'} = 1;
7982: }
7983: } elsif (@updatedoff) {
7984: $changed{$role}{'off'} = 1;
7985: }
7986: } else {
7987: if (@updatedon) {
7988: $changed{$role}{'on'} = 1;
7989: }
7990: if (@updatedoff) {
7991: $changed{$role}{'off'} = 1;
7992: }
7993: }
7994: if (ref($changed{$role}) eq 'HASH') {
7995: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
7996: my $newpriv;
7997: if (@updatedon) {
7998: $newpriv = 'on='.join(':',@updatedon);
7999: }
8000: if (@updatedoff) {
8001: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8002: }
8003: if ($newpriv eq '') {
8004: push(@todelete,'internal.adhocpriv.'.$role);
8005: } else {
8006: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8007: }
8008: }
8009: }
8010: }
8011: }
8012: if (@incrs) {
8013: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8014: } elsif (@todelete) {
8015: push(@todelete,'internal.adhocaccess');
8016: }
8017: if (keys(%changed)) {
8018: my ($putres,$delres);
8019: if (keys(%storehash)) {
8020: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8021: my %newenvhash;
8022: foreach my $key (keys(%storehash)) {
8023: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8024: }
8025: &Apache::lonnet::appenv(\%newenvhash);
8026: }
8027: if (@todelete) {
8028: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8029: foreach my $key (@todelete) {
8030: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8031: }
8032: }
8033: if (($putres eq 'ok') || ($delres eq 'ok')) {
8034: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8035: my (%domcurrent,%ordered,%description,%domusage);
8036: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8037: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8038: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8039: }
8040: }
8041: my $count = 0;
8042: foreach my $role (sort(keys(%customroles))) {
8043: my ($order,$desc);
8044: if (ref($domcurrent{$role}) eq 'HASH') {
8045: $order = $domcurrent{$role}{'order'};
8046: $desc = $domcurrent{$role}{'desc'};
8047: }
8048: if ($order eq '') {
8049: $order = $count;
8050: }
8051: $ordered{$order} = $role;
8052: if ($desc ne '') {
8053: $description{$role} = $desc;
8054: } else {
8055: $description{$role}= $role;
8056: }
8057: $count++;
8058: }
8059: my @roles_by_num = ();
8060: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8061: push(@roles_by_num,$ordered{$item});
8062: }
8063: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8064: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
8065: $r->print('<ul>');
8066: foreach my $role (@roles_by_num) {
8067: next unless (ref($changed{$role}) eq 'HASH');
8068: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8069: '<ul>');
8070: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
8071: $r->print('<li>');
8072: if ($env{'form.'.$role.'_incrs'}) {
8073: if ($newsettings{$role}{'access'} eq 'all') {
8074: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
8075: } elsif ($newsettings{$role}{'access'} eq 'none') {
8076: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8077: } elsif ($newsettings{$role}{'access'} eq 'status') {
8078: if ($newsettings{$role}{'status'}) {
8079: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
8080: if (split(/,/,$rest) > 1) {
8081: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8082: $newsettings{$role}{'status'}));
8083: } else {
8084: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8085: $newsettings{$role}{'status'}));
8086: }
8087: } else {
8088: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8089: }
8090: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8091: if ($newsettings{$role}{'exc'}) {
8092: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8093: } else {
8094: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8095: }
8096: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8097: if ($newsettings{$role}{'inc'}) {
8098: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8099: } else {
8100: $r->print(&mt('All helpdesk staff may use this role.'));
8101: }
8102: }
8103: } else {
8104: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8105: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8106: }
8107: $r->print('</li>');
8108: }
8109: unless ($newsettings{$role}{'access'} eq 'none') {
8110: if ($changed{$role}{'off'}) {
8111: if ($newsettings{$role}{'off'}) {
8112: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8113: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8114: } else {
8115: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
8116: }
8117: }
8118: if ($changed{$role}{'on'}) {
8119: if ($newsettings{$role}{'on'}) {
8120: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8121: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8122: } else {
8123: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
8124: }
8125: }
8126: }
8127: $r->print('</ul></li>');
8128: }
8129: $r->print('</ul>');
8130: }
8131: } else {
8132: $r->print(&mt('No changes made to helpdesk access settings.'));
8133: }
8134: }
8135: return;
8136: }
8137:
8138: #-------------------------------------------------- functions for &phase_two
8139: sub user_search_result {
8140: my ($context,$srch) = @_;
8141: my %allhomes;
8142: my %inst_matches;
8143: my %srch_results;
8144: my ($response,$currstate,$forcenewuser,$dirsrchres);
8145: $srch->{'srchterm'} =~ s/\s+/ /g;
8146: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
8147: $response = &mt('Invalid search.');
8148: }
8149: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8150: $response = &mt('Invalid search.');
8151: }
8152: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
8153: $response = &mt('Invalid search.');
8154: }
8155: if ($srch->{'srchterm'} eq '') {
8156: $response = &mt('You must enter a search term.');
8157: }
8158: if ($srch->{'srchterm'} =~ /^\s+$/) {
8159: $response = &mt('Your search term must contain more than just spaces.');
8160: }
8161: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8162: if (($srch->{'srchdomain'} eq '') ||
8163: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
8164: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8165: }
8166: }
8167: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8168: ($srch->{'srchin'} eq 'alc')) {
8169: if ($srch->{'srchby'} eq 'uname') {
8170: my $unamecheck = $srch->{'srchterm'};
8171: if ($srch->{'srchtype'} eq 'contains') {
8172: if ($unamecheck !~ /^\w/) {
8173: $unamecheck = 'a'.$unamecheck;
8174: }
8175: }
8176: if ($unamecheck !~ /^$match_username$/) {
8177: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8178: }
8179: }
8180: }
8181: if ($response ne '') {
8182: $response = '<span class="LC_warning">'.$response.'</span><br />';
8183: }
8184: if ($srch->{'srchin'} eq 'instd') {
8185: my $instd_chk = &instdirectorysrch_check($srch);
8186: if ($instd_chk ne 'ok') {
8187: my $domd_chk = &domdirectorysrch_check($srch);
8188: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
8189: if ($domd_chk eq 'ok') {
8190: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
8191: }
8192: $response .= '<br />';
8193: }
8194: } else {
8195: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
8196: my $domd_chk = &domdirectorysrch_check($srch);
8197: if ($domd_chk ne 'ok') {
8198: my $instd_chk = &instdirectorysrch_check($srch);
8199: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
8200: if ($instd_chk eq 'ok') {
8201: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
8202: }
8203: $response .= '<br />';
8204: }
8205: }
8206: }
8207: if ($response ne '') {
8208: return ($currstate,$response);
8209: }
8210: if ($srch->{'srchby'} eq 'uname') {
8211: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8212: if ($env{'form.forcenew'}) {
8213: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8214: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8215: if ($uhome eq 'no_host') {
8216: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
8217: my $showdom = &display_domain_info($env{'request.role.domain'});
8218: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
8219: } else {
8220: $currstate = 'modify';
8221: }
8222: } else {
8223: $currstate = 'modify';
8224: }
8225: } else {
8226: if ($srch->{'srchin'} eq 'dom') {
8227: if ($srch->{'srchtype'} eq 'exact') {
8228: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8229: if ($uhome eq 'no_host') {
8230: ($currstate,$response,$forcenewuser) =
8231: &build_search_response($context,$srch,%srch_results);
8232: } else {
8233: $currstate = 'modify';
8234: if ($env{'form.action'} eq 'accesslogs') {
8235: $currstate = 'activity';
8236: }
8237: my $uname = $srch->{'srchterm'};
8238: my $udom = $srch->{'srchdomain'};
8239: $srch_results{$uname.':'.$udom} =
8240: { &Apache::lonnet::get('environment',
8241: ['firstname',
8242: 'lastname',
8243: 'permanentemail'],
8244: $udom,$uname)
8245: };
8246: }
8247: } else {
8248: %srch_results = &Apache::lonnet::usersearch($srch);
8249: ($currstate,$response,$forcenewuser) =
8250: &build_search_response($context,$srch,%srch_results);
8251: }
8252: } else {
8253: my $courseusers = &get_courseusers();
8254: if ($srch->{'srchtype'} eq 'exact') {
8255: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
8256: $currstate = 'modify';
8257: } else {
8258: ($currstate,$response,$forcenewuser) =
8259: &build_search_response($context,$srch,%srch_results);
8260: }
8261: } else {
8262: foreach my $user (keys(%$courseusers)) {
8263: my ($cuname,$cudomain) = split(/:/,$user);
8264: if ($cudomain eq $srch->{'srchdomain'}) {
8265: my $matched = 0;
8266: if ($srch->{'srchtype'} eq 'begins') {
8267: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8268: $matched = 1;
8269: }
8270: } else {
8271: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8272: $matched = 1;
8273: }
8274: }
8275: if ($matched) {
8276: $srch_results{$user} =
8277: {&Apache::lonnet::get('environment',
8278: ['firstname',
8279: 'lastname',
8280: 'permanentemail'],
8281: $cudomain,$cuname)};
8282: }
8283: }
8284: }
8285: ($currstate,$response,$forcenewuser) =
8286: &build_search_response($context,$srch,%srch_results);
8287: }
8288: }
8289: }
8290: } elsif ($srch->{'srchin'} eq 'alc') {
8291: $currstate = 'query';
8292: } elsif ($srch->{'srchin'} eq 'instd') {
8293: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8294: if ($dirsrchres eq 'ok') {
8295: ($currstate,$response,$forcenewuser) =
8296: &build_search_response($context,$srch,%srch_results);
8297: } else {
8298: my $showdom = &display_domain_info($srch->{'srchdomain'});
8299: $response = '<span class="LC_warning">'.
8300: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8301: '</span><br />'.
8302: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
8303: '<br />';
8304: }
8305: }
8306: } else {
8307: if ($srch->{'srchin'} eq 'dom') {
8308: %srch_results = &Apache::lonnet::usersearch($srch);
8309: ($currstate,$response,$forcenewuser) =
8310: &build_search_response($context,$srch,%srch_results);
8311: } elsif ($srch->{'srchin'} eq 'crs') {
8312: my $courseusers = &get_courseusers();
8313: foreach my $user (keys(%$courseusers)) {
8314: my ($uname,$udom) = split(/:/,$user);
8315: my %names = &Apache::loncommon::getnames($uname,$udom);
8316: my %emails = &Apache::loncommon::getemails($uname,$udom);
8317: if ($srch->{'srchby'} eq 'lastname') {
8318: if ((($srch->{'srchtype'} eq 'exact') &&
8319: ($names{'lastname'} eq $srch->{'srchterm'})) ||
8320: (($srch->{'srchtype'} eq 'begins') &&
8321: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
8322: (($srch->{'srchtype'} eq 'contains') &&
8323: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8324: $srch_results{$user} = {firstname => $names{'firstname'},
8325: lastname => $names{'lastname'},
8326: permanentemail => $emails{'permanentemail'},
8327: };
8328: }
8329: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8330: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
8331: $srchlast =~ s/\s+$//;
8332: $srchfirst =~ s/^\s+//;
8333: if ($srch->{'srchtype'} eq 'exact') {
8334: if (($names{'lastname'} eq $srchlast) &&
8335: ($names{'firstname'} eq $srchfirst)) {
8336: $srch_results{$user} = {firstname => $names{'firstname'},
8337: lastname => $names{'lastname'},
8338: permanentemail => $emails{'permanentemail'},
8339:
8340: };
8341: }
8342: } elsif ($srch->{'srchtype'} eq 'begins') {
8343: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8344: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8345: $srch_results{$user} = {firstname => $names{'firstname'},
8346: lastname => $names{'lastname'},
8347: permanentemail => $emails{'permanentemail'},
8348: };
8349: }
8350: } else {
8351: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8352: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8353: $srch_results{$user} = {firstname => $names{'firstname'},
8354: lastname => $names{'lastname'},
8355: permanentemail => $emails{'permanentemail'},
8356: };
8357: }
8358: }
8359: }
8360: }
8361: ($currstate,$response,$forcenewuser) =
8362: &build_search_response($context,$srch,%srch_results);
8363: } elsif ($srch->{'srchin'} eq 'alc') {
8364: $currstate = 'query';
8365: } elsif ($srch->{'srchin'} eq 'instd') {
8366: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8367: if ($dirsrchres eq 'ok') {
8368: ($currstate,$response,$forcenewuser) =
8369: &build_search_response($context,$srch,%srch_results);
8370: } else {
8371: my $showdom = &display_domain_info($srch->{'srchdomain'});
8372: $response = '<span class="LC_warning">'.
8373: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8374: '</span><br />'.
8375: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
8376: '<br />';
8377: }
8378: }
8379: }
8380: return ($currstate,$response,$forcenewuser,\%srch_results);
8381: }
8382:
8383: sub domdirectorysrch_check {
8384: my ($srch) = @_;
8385: my $response;
8386: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8387: ['directorysrch'],$srch->{'srchdomain'});
8388: my $showdom = &display_domain_info($srch->{'srchdomain'});
8389: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8390: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8391: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8392: }
8393: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8394: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8395: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8396: }
8397: }
8398: }
8399: return 'ok';
8400: }
8401:
8402: sub instdirectorysrch_check {
8403: my ($srch) = @_;
8404: my $can_search = 0;
8405: my $response;
8406: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8407: ['directorysrch'],$srch->{'srchdomain'});
8408: my $showdom = &display_domain_info($srch->{'srchdomain'});
8409: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8410: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
8411: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
8412: }
8413: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8414: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8415: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8416: }
8417: my @usertypes = split(/:/,$env{'environment.inststatus'});
8418: if (!@usertypes) {
8419: push(@usertypes,'default');
8420: }
8421: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8422: foreach my $type (@usertypes) {
8423: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8424: $can_search = 1;
8425: last;
8426: }
8427: }
8428: }
8429: if (!$can_search) {
8430: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8431: my @longtypes;
8432: foreach my $item (@usertypes) {
8433: if (defined($insttypes->{$item})) {
8434: push (@longtypes,$insttypes->{$item});
8435: } elsif ($item eq 'default') {
8436: push (@longtypes,&mt('other'));
8437: }
8438: }
8439: my $insttype_str = join(', ',@longtypes);
8440: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
8441: }
8442: } else {
8443: $can_search = 1;
8444: }
8445: } else {
8446: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
8447: }
8448: my %longtext = &Apache::lonlocal::texthash (
8449: uname => 'username',
8450: lastfirst => 'last name, first name',
8451: lastname => 'last name',
8452: contains => 'contains',
8453: exact => 'as exact match to',
8454: begins => 'begins with',
8455: );
8456: if ($can_search) {
8457: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8458: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
8459: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
8460: }
8461: } else {
8462: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
8463: }
8464: }
8465: if ($can_search) {
8466: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8467: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8468: return 'ok';
8469: } else {
8470: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
8471: }
8472: } else {
8473: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8474: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8475: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8476: return 'ok';
8477: } else {
8478: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
8479: }
8480: }
8481: }
8482: }
8483:
8484: sub get_courseusers {
8485: my %advhash;
8486: my $classlist = &Apache::loncoursedata::get_classlist();
8487: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8488: foreach my $role (sort(keys(%coursepersonnel))) {
8489: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
8490: if (!exists($classlist->{$user})) {
8491: $classlist->{$user} = [];
8492: }
8493: }
8494: }
8495: return $classlist;
8496: }
8497:
8498: sub build_search_response {
8499: my ($context,$srch,%srch_results) = @_;
8500: my ($currstate,$response,$forcenewuser);
8501: my %names = (
8502: 'uname' => 'username',
8503: 'lastname' => 'last name',
8504: 'lastfirst' => 'last name, first name',
8505: 'crs' => 'this course',
8506: 'dom' => 'LON-CAPA domain',
8507: 'instd' => 'the institutional directory for domain',
8508: );
8509:
8510: my %single = (
8511: begins => 'A match',
8512: contains => 'A match',
8513: exact => 'An exact match',
8514: );
8515: my %nomatch = (
8516: begins => 'No match',
8517: contains => 'No match',
8518: exact => 'No exact match',
8519: );
8520: if (keys(%srch_results) > 1) {
8521: $currstate = 'select';
8522: } else {
8523: if (keys(%srch_results) == 1) {
8524: if ($env{'form.action'} eq 'accesslogs') {
8525: $currstate = 'activity';
8526: } else {
8527: $currstate = 'modify';
8528: }
8529: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8530: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
8531: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
8532: }
8533: } else { # Search has nothing found. Prepare message to user.
8534: $response = '<span class="LC_warning">';
8535: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
8536: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8537: '<b>'.$srch->{'srchterm'}.'</b>',
8538: &display_domain_info($srch->{'srchdomain'}));
8539: } else {
8540: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8541: '<b>'.$srch->{'srchterm'}.'</b>');
8542: }
8543: $response .= '</span>';
8544:
8545: if ($srch->{'srchin'} ne 'alc') {
8546: $forcenewuser = 1;
8547: my $cansrchinst = 0;
8548: if ($srch->{'srchdomain'}) {
8549: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8550: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8551: if ($domconfig{'directorysrch'}{'available'}) {
8552: $cansrchinst = 1;
8553: }
8554: }
8555: }
8556: if ((($srch->{'srchby'} eq 'lastfirst') ||
8557: ($srch->{'srchby'} eq 'lastname')) &&
8558: ($srch->{'srchin'} eq 'dom')) {
8559: if ($cansrchinst) {
8560: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
8561: }
8562: }
8563: if ($srch->{'srchin'} eq 'crs') {
8564: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8565: }
8566: }
8567: my $createdom = $env{'request.role.domain'};
8568: if ($context eq 'requestcrs') {
8569: if ($env{'form.coursedom'} ne '') {
8570: $createdom = $env{'form.coursedom'};
8571: }
8572: }
8573: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8574: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
8575: my $cancreate =
8576: &Apache::lonuserutils::can_create_user($createdom,$context);
8577: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
8578: if ($cancreate) {
8579: my $showdom = &display_domain_info($createdom);
8580: $response .= '<br /><br />'
8581: .'<b>'.&mt('To add a new user:').'</b>'
8582: .'<br />';
8583: if ($context eq 'requestcrs') {
8584: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8585: } else {
8586: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8587: }
8588: $response .='<ul><li>'
8589: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8590: .'</li><li>'
8591: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8592: .'</li><li>'
8593: .&mt('Provide the proposed username')
8594: .'</li><li>'
8595: .&mt("Click 'Search'")
8596: .'</li></ul><br />';
8597: } else {
8598: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8599: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8600: $response .= '<br /><br />';
8601: if ($context eq 'requestcrs') {
8602: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8603: } else {
8604: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8605: }
8606: $response .= '<br />'
8607: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8608: ,' <a'.$helplink.'>'
8609: ,'</a>')
8610: .'<br />';
8611: }
8612: }
8613: }
8614: }
8615: }
8616: return ($currstate,$response,$forcenewuser);
8617: }
8618:
8619: sub display_domain_info {
8620: my ($dom) = @_;
8621: my $output = $dom;
8622: if ($dom ne '') {
8623: my $domdesc = &Apache::lonnet::domain($dom,'description');
8624: if ($domdesc ne '') {
8625: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8626: }
8627: }
8628: return $output;
8629: }
8630:
8631: sub crumb_utilities {
8632: my %elements = (
8633: crtuser => {
8634: srchterm => 'text',
8635: srchin => 'selectbox',
8636: srchby => 'selectbox',
8637: srchtype => 'selectbox',
8638: srchdomain => 'selectbox',
8639: },
8640: crtusername => {
8641: srchterm => 'text',
8642: srchdomain => 'selectbox',
8643: },
8644: docustom => {
8645: rolename => 'selectbox',
8646: newrolename => 'textbox',
8647: },
8648: studentform => {
8649: srchterm => 'text',
8650: srchin => 'selectbox',
8651: srchby => 'selectbox',
8652: srchtype => 'selectbox',
8653: srchdomain => 'selectbox',
8654: },
8655: );
8656:
8657: my $jsback .= qq|
8658: function backPage(formname,prevphase,prevstate) {
8659: if (typeof prevphase == 'undefined') {
8660: formname.phase.value = '';
8661: }
8662: else {
8663: formname.phase.value = prevphase;
8664: }
8665: if (typeof prevstate == 'undefined') {
8666: formname.currstate.value = '';
8667: }
8668: else {
8669: formname.currstate.value = prevstate;
8670: }
8671: formname.submit();
8672: }
8673: |;
8674: return ($jsback,\%elements);
8675: }
8676:
8677: sub course_level_table {
8678: my ($inccourses,$showcredits,$defaultcredits) = @_;
8679: return unless (ref($inccourses) eq 'HASH');
8680: my $table = '';
8681: # Custom Roles?
8682:
8683: my %customroles=&Apache::lonuserutils::my_custom_roles();
8684: my %lt=&Apache::lonlocal::texthash(
8685: 'exs' => "Existing sections",
8686: 'new' => "Define new section",
8687: 'ssd' => "Set Start Date",
8688: 'sed' => "Set End Date",
8689: 'crl' => "Course Level",
8690: 'act' => "Activate",
8691: 'rol' => "Role",
8692: 'ext' => "Extent",
8693: 'grs' => "Section",
8694: 'crd' => "Credits",
8695: 'sta' => "Start",
8696: 'end' => "End"
8697: );
8698:
8699: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
8700: my $thiscourse=$protectedcourse;
8701: $thiscourse=~s:_:/:g;
8702: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
8703: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
8704: my $area=$coursedata{'description'};
8705: my $crstype=$coursedata{'type'};
8706: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
8707: my ($domain,$cnum)=split(/\//,$thiscourse);
8708: my %sections_count;
8709: if (defined($env{'request.course.id'})) {
8710: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
8711: %sections_count =
8712: &Apache::loncommon::get_sections($domain,$cnum);
8713: }
8714: }
8715: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
8716: foreach my $role (@roles) {
8717: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
8718: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
8719: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
8720: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
8721: $plrole,\%sections_count,\%lt,
8722: $showcredits,$defaultcredits,$crstype);
8723: } elsif ($env{'request.course.sec'} ne '') {
8724: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
8725: $env{'request.course.sec'})) {
8726: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
8727: $plrole,\%sections_count,\%lt,
8728: $showcredits,$defaultcredits,$crstype);
8729: }
8730: }
8731: }
8732: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
8733: foreach my $cust (sort(keys(%customroles))) {
8734: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
8735: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
8736: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
8737: $cust,\%sections_count,\%lt,
8738: $showcredits,$defaultcredits,$crstype);
8739: }
8740: }
8741: }
8742: return '' if ($table eq ''); # return nothing if there is nothing
8743: # in the table
8744: my $result;
8745: if (!$env{'request.course.id'}) {
8746: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
8747: }
8748: $result .=
8749: &Apache::loncommon::start_data_table().
8750: &Apache::loncommon::start_data_table_header_row().
8751: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
8752: '<th>'.$lt{'ext'}.'</th><th>'."\n";
8753: if ($showcredits) {
8754: $result .= $lt{'crd'}.'</th>';
8755: }
8756: $result .=
8757: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
8758: '<th>'.$lt{'end'}.'</th>'.
8759: &Apache::loncommon::end_data_table_header_row().
8760: $table.
8761: &Apache::loncommon::end_data_table();
8762: return $result;
8763: }
8764:
8765: sub course_level_row {
8766: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
8767: $lt,$showcredits,$defaultcredits,$crstype) = @_;
8768: my $creditem;
8769: my $row = &Apache::loncommon::start_data_table_row().
8770: ' <td><input type="checkbox" name="act_'.
8771: $protectedcourse.'_'.$role.'" /></td>'."\n".
8772: ' <td>'.$plrole.'</td>'."\n".
8773: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
8774: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
8775: $row .=
8776: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
8777: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
8778: } else {
8779: $row .= '<td> </td>';
8780: }
8781: if (($role eq 'cc') || ($role eq 'co')) {
8782: $row .= '<td> </td>';
8783: } elsif ($env{'request.course.sec'} ne '') {
8784: $row .= ' <td><input type="hidden" value="'.
8785: $env{'request.course.sec'}.'" '.
8786: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
8787: $env{'request.course.sec'}.'</td>';
8788: } else {
8789: if (ref($sections_count) eq 'HASH') {
8790: my $currsec =
8791: &Apache::lonuserutils::course_sections($sections_count,
8792: $protectedcourse.'_'.$role);
8793: $row .= '<td><table class="LC_createuser">'."\n".
8794: '<tr class="LC_section_row">'."\n".
8795: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
8796: $currsec.'</td>'."\n".
8797: ' <td> </td>'."\n".
8798: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
8799: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
8800: '" value="" />'.
8801: '<input type="hidden" '.
8802: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
8803: '</tr></table></td>'."\n";
8804: } else {
8805: $row .= '<td><input type="text" size="10" '.
8806: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
8807: }
8808: }
8809: $row .= <<ENDTIMEENTRY;
8810: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
8811: <a href=
8812: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$role.value,'start_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'ssd'}</a></td>
8813: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
8814: <a href=
8815: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
8816: ENDTIMEENTRY
8817: $row .= &Apache::loncommon::end_data_table_row();
8818: return $row;
8819: }
8820:
8821: sub course_level_dc {
8822: my ($dcdom,$showcredits) = @_;
8823: my %customroles=&Apache::lonuserutils::my_custom_roles();
8824: my @roles = &Apache::lonuserutils::roles_by_context('course');
8825: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
8826: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
8827: '<input type="hidden" name="dccourse" value="" />';
8828: my $courseform=&Apache::loncommon::selectcourse_link
8829: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
8830: my $credit_elem;
8831: if ($showcredits) {
8832: $credit_elem = 'credits';
8833: }
8834: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
8835: my %lt=&Apache::lonlocal::texthash(
8836: 'rol' => "Role",
8837: 'grs' => "Section",
8838: 'exs' => "Existing sections",
8839: 'new' => "Define new section",
8840: 'sta' => "Start",
8841: 'end' => "End",
8842: 'ssd' => "Set Start Date",
8843: 'sed' => "Set End Date",
8844: 'scc' => "Course/Community",
8845: 'crd' => "Credits",
8846: );
8847: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
8848: &Apache::loncommon::start_data_table().
8849: &Apache::loncommon::start_data_table_header_row().
8850: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
8851: '<th>'.$lt{'grs'}.'</th>'."\n";
8852: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
8853: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
8854: &Apache::loncommon::end_data_table_header_row();
8855: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
8856: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
8857: $courseform.(' ' x4).'</span></td>'."\n".
8858: '<td valign="top"><br /><select name="role">'."\n";
8859: foreach my $role (@roles) {
8860: my $plrole=&Apache::lonnet::plaintext($role);
8861: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
8862: }
8863: if ( keys(%customroles) > 0) {
8864: foreach my $cust (sort(keys(%customroles))) {
8865: my $custrole='cr_cr_'.$env{'user.domain'}.
8866: '_'.$env{'user.name'}.'_'.$cust;
8867: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
8868: }
8869: }
8870: $otheritems .= '</select></td><td>'.
8871: '<table border="0" cellspacing="0" cellpadding="0">'.
8872: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
8873: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
8874: '<td> </td>'.
8875: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
8876: '<input type="text" name="newsec" value="" />'.
8877: '<input type="hidden" name="section" value="" />'.
8878: '<input type="hidden" name="groups" value="" />'.
8879: '<input type="hidden" name="crstype" value="" /></td>'.
8880: '</tr></table></td>'."\n";
8881: if ($showcredits) {
8882: $otheritems .= '<td><br />'."\n".
8883: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
8884: }
8885: $otheritems .= <<ENDTIMEENTRY;
8886: <td><br /><input type="hidden" name="start" value='' />
8887: <a href=
8888: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
8889: <td><br /><input type="hidden" name="end" value='' />
8890: <a href=
8891: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
8892: ENDTIMEENTRY
8893: $otheritems .= &Apache::loncommon::end_data_table_row().
8894: &Apache::loncommon::end_data_table()."\n";
8895: return $cb_jscript.$header.$hiddenitems.$otheritems;
8896: }
8897:
8898: sub update_selfenroll_config {
8899: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
8900: return unless (ref($currsettings) eq 'HASH');
8901: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
8902: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8903: my (%changes,%warning);
8904: my $curr_types;
8905: my %noedit;
8906: unless ($context eq 'domain') {
8907: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
8908: }
8909: if (ref($row) eq 'ARRAY') {
8910: foreach my $item (@{$row}) {
8911: next if ($noedit{$item});
8912: if ($item eq 'enroll_dates') {
8913: my (%currenrolldate,%newenrolldate);
8914: foreach my $type ('start','end') {
8915: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
8916: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
8917: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
8918: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
8919: }
8920: }
8921: } elsif ($item eq 'access_dates') {
8922: my (%currdate,%newdate);
8923: foreach my $type ('start','end') {
8924: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
8925: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
8926: if ($newdate{$type} ne $currdate{$type}) {
8927: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
8928: }
8929: }
8930: } elsif ($item eq 'types') {
8931: $curr_types = $currsettings->{'selfenroll_'.$item};
8932: if ($env{'form.selfenroll_all'}) {
8933: if ($curr_types ne '*') {
8934: $changes{'internal.selfenroll_types'} = '*';
8935: } else {
8936: next;
8937: }
8938: } else {
8939: my %currdoms;
8940: my @entries = split(/;/,$curr_types);
8941: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
8942: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
8943: my $newnum = 0;
8944: my @latesttypes;
8945: foreach my $num (@activations) {
8946: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
8947: if (@types > 0) {
8948: @types = sort(@types);
8949: my $typestr = join(',',@types);
8950: my $typedom = $env{'form.selfenroll_dom_'.$num};
8951: $latesttypes[$newnum] = $typedom.':'.$typestr;
8952: $currdoms{$typedom} = 1;
8953: $newnum ++;
8954: }
8955: }
8956: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
8957: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
8958: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
8959: if (@types > 0) {
8960: @types = sort(@types);
8961: my $typestr = join(',',@types);
8962: my $typedom = $env{'form.selfenroll_dom_'.$j};
8963: $latesttypes[$newnum] = $typedom.':'.$typestr;
8964: $currdoms{$typedom} = 1;
8965: $newnum ++;
8966: }
8967: }
8968: }
8969: if ($env{'form.selfenroll_newdom'} ne '') {
8970: my $typedom = $env{'form.selfenroll_newdom'};
8971: if ((!defined($currdoms{$typedom})) &&
8972: (&Apache::lonnet::domain($typedom) ne '')) {
8973: my $typestr;
8974: my ($othertitle,$usertypes,$types) =
8975: &Apache::loncommon::sorted_inst_types($typedom);
8976: my $othervalue = 'any';
8977: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8978: if (@{$types} > 0) {
8979: my @esc_types = map { &escape($_); } @{$types};
8980: $othervalue = 'other';
8981: $typestr = join(',',(@esc_types,$othervalue));
8982: }
8983: $typestr = $othervalue;
8984: } else {
8985: $typestr = $othervalue;
8986: }
8987: $latesttypes[$newnum] = $typedom.':'.$typestr;
8988: $newnum ++ ;
8989: }
8990: }
8991: my $selfenroll_types = join(';',@latesttypes);
8992: if ($selfenroll_types ne $curr_types) {
8993: $changes{'internal.selfenroll_types'} = $selfenroll_types;
8994: }
8995: }
8996: } elsif ($item eq 'limit') {
8997: my $newlimit = $env{'form.selfenroll_limit'};
8998: my $newcap = $env{'form.selfenroll_cap'};
8999: $newcap =~s/\s+//g;
9000: my $currlimit = $currsettings->{'selfenroll_limit'};
9001: $currlimit = 'none' if ($currlimit eq '');
9002: my $currcap = $currsettings->{'selfenroll_cap'};
9003: if ($newlimit ne $currlimit) {
9004: if ($newlimit ne 'none') {
9005: if ($newcap =~ /^\d+$/) {
9006: if ($newcap ne $currcap) {
9007: $changes{'internal.selfenroll_cap'} = $newcap;
9008: }
9009: $changes{'internal.selfenroll_limit'} = $newlimit;
9010: } else {
9011: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9012: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
9013: }
9014: } elsif ($currcap ne '') {
9015: $changes{'internal.selfenroll_cap'} = '';
9016: $changes{'internal.selfenroll_limit'} = $newlimit;
9017: }
9018: } elsif ($currlimit ne 'none') {
9019: if ($newcap =~ /^\d+$/) {
9020: if ($newcap ne $currcap) {
9021: $changes{'internal.selfenroll_cap'} = $newcap;
9022: }
9023: } else {
9024: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9025: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
9026: }
9027: }
9028: } elsif ($item eq 'approval') {
9029: my (@currnotified,@newnotified);
9030: my $currapproval = $currsettings->{'selfenroll_approval'};
9031: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
9032: if ($currnotifylist ne '') {
9033: @currnotified = split(/,/,$currnotifylist);
9034: @currnotified = sort(@currnotified);
9035: }
9036: my $newapproval = $env{'form.selfenroll_approval'};
9037: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9038: @newnotified = sort(@newnotified);
9039: if ($newapproval ne $currapproval) {
9040: $changes{'internal.selfenroll_approval'} = $newapproval;
9041: if (!$newapproval) {
9042: if ($currnotifylist ne '') {
9043: $changes{'internal.selfenroll_notifylist'} = '';
9044: }
9045: } else {
9046: my @differences =
9047: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
9048: if (@differences > 0) {
9049: if (@newnotified > 0) {
9050: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9051: } else {
9052: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9053: }
9054: }
9055: }
9056: } else {
9057: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
9058: if (@differences > 0) {
9059: if (@newnotified > 0) {
9060: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9061: } else {
9062: $changes{'internal.selfenroll_notifylist'} = '';
9063: }
9064: }
9065: }
9066: } else {
9067: my $curr_val = $currsettings->{'selfenroll_'.$item};
9068: my $newval = $env{'form.selfenroll_'.$item};
9069: if ($item eq 'section') {
9070: $newval = $env{'form.sections'};
9071: if (defined($curr_groups{$newval})) {
9072: $newval = $curr_val;
9073: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9074: &mt('Group names and section names must be distinct');
9075: } elsif ($newval eq 'all') {
9076: $newval = $curr_val;
9077: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
9078: }
9079: if ($newval eq '') {
9080: $newval = 'none';
9081: }
9082: }
9083: if ($newval ne $curr_val) {
9084: $changes{'internal.selfenroll_'.$item} = $newval;
9085: }
9086: }
9087: }
9088: if (keys(%warning) > 0) {
9089: foreach my $item (@{$row}) {
9090: if (exists($warning{$item})) {
9091: $r->print($warning{$item}.'<br />');
9092: }
9093: }
9094: }
9095: if (keys(%changes) > 0) {
9096: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9097: if ($putresult eq 'ok') {
9098: if ((exists($changes{'internal.selfenroll_types'})) ||
9099: (exists($changes{'internal.selfenroll_start_date'})) ||
9100: (exists($changes{'internal.selfenroll_end_date'}))) {
9101: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9102: $cnum,undef,undef,'Course');
9103: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
9104: if (ref($crsinfo{$cid}) eq 'HASH') {
9105: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9106: if (exists($changes{'internal.'.$item})) {
9107: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
9108: }
9109: }
9110: my $crsputresult =
9111: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9112: $chome,'notime');
9113: }
9114: }
9115: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9116: foreach my $item (@{$row}) {
9117: my $title = $item;
9118: if (ref($lt) eq 'HASH') {
9119: $title = $lt->{$item};
9120: }
9121: if ($item eq 'enroll_dates') {
9122: foreach my $type ('start','end') {
9123: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9124: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
9125: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
9126: $title,$type,$newdate).'</li>');
9127: }
9128: }
9129: } elsif ($item eq 'access_dates') {
9130: foreach my $type ('start','end') {
9131: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9132: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
9133: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
9134: $title,$type,$newdate).'</li>');
9135: }
9136: }
9137: } elsif ($item eq 'limit') {
9138: if ((exists($changes{'internal.selfenroll_limit'})) ||
9139: (exists($changes{'internal.selfenroll_cap'}))) {
9140: my ($newval,$newcap);
9141: if ($changes{'internal.selfenroll_cap'} ne '') {
9142: $newcap = $changes{'internal.selfenroll_cap'}
9143: } else {
9144: $newcap = $currsettings->{'selfenroll_cap'};
9145: }
9146: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9147: $newval = &mt('No limit');
9148: } elsif ($changes{'internal.selfenroll_limit'} eq
9149: 'allstudents') {
9150: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9151: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9152: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9153: } else {
9154: my $currlimit = $currsettings->{'selfenroll_limit'};
9155: if ($currlimit eq 'allstudents') {
9156: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9157: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9158: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9159: }
9160: }
9161: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9162: }
9163: } elsif ($item eq 'approval') {
9164: if ((exists($changes{'internal.selfenroll_approval'})) ||
9165: (exists($changes{'internal.selfenroll_notifylist'}))) {
9166: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
9167: my ($newval,$newnotify);
9168: if (exists($changes{'internal.selfenroll_notifylist'})) {
9169: $newnotify = $changes{'internal.selfenroll_notifylist'};
9170: } else {
9171: $newnotify = $currsettings->{'selfenroll_notifylist'};
9172: }
9173: if (exists($changes{'internal.selfenroll_approval'})) {
9174: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9175: $changes{'internal.selfenroll_approval'} = '0';
9176: }
9177: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
9178: } else {
9179: my $currapproval = $currsettings->{'selfenroll_approval'};
9180: if ($currapproval !~ /^[012]$/) {
9181: $currapproval = 0;
9182: }
9183: $newval = $selfdescs{'approval'}{$currapproval};
9184: }
9185: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9186: if ($newnotify) {
9187: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
9188: } else {
9189: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
9190: }
9191: $r->print('</li>'."\n");
9192: }
9193: } else {
9194: if (exists($changes{'internal.selfenroll_'.$item})) {
9195: my $newval = $changes{'internal.selfenroll_'.$item};
9196: if ($item eq 'types') {
9197: if ($newval eq '') {
9198: $newval = &mt('None');
9199: } elsif ($newval eq '*') {
9200: $newval = &mt('Any user in any domain');
9201: }
9202: } elsif ($item eq 'registered') {
9203: if ($newval eq '1') {
9204: $newval = &mt('Yes');
9205: } elsif ($newval eq '0') {
9206: $newval = &mt('No');
9207: }
9208: }
9209: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9210: }
9211: }
9212: }
9213: $r->print('</ul>');
9214: if ($env{'course.'.$cid.'.description'} ne '') {
9215: my %newenvhash;
9216: foreach my $key (keys(%changes)) {
9217: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9218: }
9219: &Apache::lonnet::appenv(\%newenvhash);
9220: }
9221: } else {
9222: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9223: &mt('The error was: [_1].',$putresult));
9224: }
9225: } else {
9226: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
9227: }
9228: } else {
9229: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
9230: }
9231: my $visactions = &cat_visibility();
9232: my ($cathash,%cattype);
9233: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9234: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9235: $cathash = $domconfig{'coursecategories'}{'cats'};
9236: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9237: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9238: } else {
9239: $cathash = {};
9240: $cattype{'auth'} = 'std';
9241: $cattype{'unauth'} = 'std';
9242: }
9243: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9244: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9245: '<br />'.
9246: '<br />'.$visactions->{'take'}.'<ul>'.
9247: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9248: '</ul>');
9249: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9250: if ($currsettings->{'uniquecode'}) {
9251: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9252: } else {
9253: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9254: '<br />'.
9255: '<br />'.$visactions->{'take'}.'<ul>'.
9256: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9257: '</ul><br />');
9258: }
9259: } else {
9260: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9261: if (ref($visactions) eq 'HASH') {
9262: if (!$visible) {
9263: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9264: '<br />');
9265: if (ref($vismsgs) eq 'ARRAY') {
9266: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9267: foreach my $item (@{$vismsgs}) {
9268: $r->print('<li>'.$visactions->{$item}.'</li>');
9269: }
9270: $r->print('</ul>');
9271: }
9272: $r->print($cansetvis);
9273: }
9274: }
9275: }
9276: return;
9277: }
9278:
9279: #---------------------------------------------- end functions for &phase_two
9280:
9281: #--------------------------------- functions for &phase_two and &phase_three
9282:
9283: #--------------------------end of functions for &phase_two and &phase_three
9284:
9285: 1;
9286: __END__
9287:
9288:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>