Annotation of loncom/interface/loncreateuser.pm, revision 1.482
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.482 ! raeburn 4: # $Id: loncreateuser.pm,v 1.481 2024/08/31 21:12:45 raeburn Exp $
1.22 albertel 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: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 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:
1.324 raeburn 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>.
1.66 bowersj2 59:
1.324 raeburn 60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
1.66 bowersj2 62:
63: =cut
1.1 www 64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
1.54 bowersj2 68: use Apache::loncommon;
1.68 www 69: use Apache::lonlocal;
1.117 raeburn 70: use Apache::longroup;
1.190 raeburn 71: use Apache::lonuserutils;
1.307 raeburn 72: use Apache::loncoursequeueadmin;
1.470 raeburn 73: use Apache::lonviewcoauthors;
1.139 albertel 74: use LONCAPA qw(:DEFAULT :match);
1.456 raeburn 75: use HTML::Entities;
1.1 www 76:
1.20 harris41 77: my $loginscript; # piece of javascript used in two separate instances
78: my $authformnop;
79: my $authformkrb;
80: my $authformint;
81: my $authformfsys;
82: my $authformloc;
1.449 raeburn 83: my $authformlti;
1.20 harris41 84:
1.94 matthew 85: sub initialize_authen_forms {
1.470 raeburn 86: my ($dom,$formname,$curr_authtype,$mode,$readonly) = @_;
1.227 raeburn 87: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
88: my %param = ( formname => $formname,
1.187 raeburn 89: kerb_def_dom => $krbdefdom,
1.227 raeburn 90: kerb_def_auth => $krbdef,
1.187 raeburn 91: domain => $dom,
92: );
1.188 raeburn 93: my %abv_auth = &auth_abbrev();
1.449 raeburn 94: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix|lti):(.*)$/) {
1.188 raeburn 95: my $long_auth = $1;
1.227 raeburn 96: my $curr_autharg = $2;
1.188 raeburn 97: my %abv_auth = &auth_abbrev();
98: $param{'curr_authtype'} = $abv_auth{$long_auth};
99: if ($long_auth =~ /^krb(4|5)$/) {
100: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 101: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 102: }
1.205 raeburn 103: if ($mode eq 'modifyuser') {
104: $param{'mode'} = $mode;
105: }
1.187 raeburn 106: }
1.470 raeburn 107: if ($readonly) {
108: $param{'readonly'} = 1;
109: }
1.227 raeburn 110: $loginscript = &Apache::loncommon::authform_header(%param);
111: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 112: $authformnop = &Apache::loncommon::authform_nochange(%param);
113: $authformint = &Apache::loncommon::authform_internal(%param);
114: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
115: $authformloc = &Apache::loncommon::authform_local(%param);
1.449 raeburn 116: $authformlti = &Apache::loncommon::authform_lti(%param);
1.20 harris41 117: }
118:
1.188 raeburn 119: sub auth_abbrev {
120: my %abv_auth = (
1.368 raeburn 121: krb5 => 'krb',
122: krb4 => 'krb',
123: internal => 'int',
124: localauth => 'loc',
125: unix => 'fsys',
1.449 raeburn 126: lti => 'lti',
1.188 raeburn 127: );
128: return %abv_auth;
129: }
1.43 www 130:
1.134 raeburn 131: # ====================================================
132:
1.378 raeburn 133: sub user_quotas {
1.470 raeburn 134: my ($ccuname,$ccdomain,$name) = @_;
1.134 raeburn 135: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 136: 'cust' => "Custom quota",
137: 'chqu' => "Change quota",
1.134 raeburn 138: );
1.470 raeburn 139: my ($output,$longinsttype);
140: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
141: my %titles = &Apache::lonlocal::texthash (
142: portfolio => "Disk space allocated to user's portfolio files",
143: author => "Disk space allocated to user's Authoring Space",
144: );
145: my ($currquota,$quotatype,$inststatus,$defquota) =
146: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
147: if ($longinsttype eq '') {
148: if ($inststatus ne '') {
149: if ($usertypes->{$inststatus} ne '') {
150: $longinsttype = $usertypes->{$inststatus};
151: }
152: }
153: }
154: my ($showquota,$custom_on,$custom_off,$defaultinfo,$colspan);
155: $custom_on = ' ';
156: $custom_off = ' checked="checked" ';
157: $colspan = ' colspan="2"';
158: if ($quotatype eq 'custom') {
159: $custom_on = $custom_off;
160: $custom_off = ' ';
161: $showquota = $currquota;
162: if ($longinsttype eq '') {
163: $defaultinfo = &mt('For this user, the default quota would be [_1]'
164: .' MB.',$defquota);
165: } else {
166: $defaultinfo = &mt("For this user, the default quota would be [_1]".
167: " MB,[_2]as determined by the user's institutional".
168: " affiliation ([_3]).",$defquota,'<br />',$longinsttype);
169: }
170: } else {
171: if ($longinsttype eq '') {
172: $defaultinfo = &mt('For this user, the default quota is [_1]'
173: .' MB.',$defquota);
174: } else {
175: $defaultinfo = &mt("For this user, the default quota of [_1]".
176: " MB,[_2]is determined by the user's institutional".
177: " affiliation ([_3]).",$defquota,'<br />'.$longinsttype);
178: }
179: }
180:
181: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
182: $output .= '<tr class="LC_info_row">'."\n".
183: ' <td'.$colspan.'>'.$titles{$name}.'</td>'."\n".
184: ' </tr>'."\n".
185: &Apache::loncommon::start_data_table_row()."\n".
186: ' <td'.$colspan.'><span class="LC_nobreak">'.
187: &mt('Current quota: [_1] MB',$currquota).'</span> '.
188: $defaultinfo.'</td>'."\n".
189: &Apache::loncommon::end_data_table_row()."\n".
190: &Apache::loncommon::start_data_table_row()."\n".
191: '<td'.$colspan.'><span class="LC_nobreak">'.$lt{'chqu'}.
192: ': <label>'.
193: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
194: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
195: ' /><span class="LC_nobreak">'.
196: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
197: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
198: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
199: ' />'.$lt{'cust'}.':</label> '.
200: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
201: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
202: ' /> '.&mt('MB').'</span></td>'."\n".
203: &Apache::loncommon::end_data_table_row()."\n";
204: }
205: return $output;
206: }
207:
208: sub user_quota_js {
209: return <<"END_SCRIPT";
1.149 raeburn 210: <script type="text/javascript">
1.301 bisitz 211: // <![CDATA[
1.378 raeburn 212: function quota_changes(caller,context) {
213: var customoff = document.getElementById('custom_'+context+'quota_off');
214: var customon = document.getElementById('custom_'+context+'quota_on');
215: var number = document.getElementById(context+'quota');
1.149 raeburn 216: if (caller == "custom") {
1.378 raeburn 217: if (customoff) {
218: if (customoff.checked) {
219: number.value = "";
220: }
1.149 raeburn 221: }
222: }
223: if (caller == "quota") {
1.378 raeburn 224: if (customon) {
225: customon.checked = true;
226: }
1.149 raeburn 227: }
1.378 raeburn 228: return;
1.149 raeburn 229: }
1.301 bisitz 230: // ]]>
1.149 raeburn 231: </script>
232: END_SCRIPT
1.378 raeburn 233:
1.470 raeburn 234: }
235:
236: sub set_custom_js {
237: return <<"END_SCRIPT";
238:
239: <script type="text/javascript">
240: // <![CDATA[
241: function toggleCustom(form,item,name) {
242: if (document.getElementById(item)) {
243: var divid = document.getElementById(item);
244: var radioname = form.elements[name];
245: if (radioname) {
246: if (radioname.length > 0) {
247: var setvis;
1.478 raeburn 248: var RegExp = /^customtext_(aboutme|blog|portfolio|portaccess|timezone|webdav|archive)\$/;
1.470 raeburn 249: for (var i=0; i<radioname.length; i++) {
250: if (radioname[i].checked == true) {
251: if (radioname[i].value == 1) {
1.476 raeburn 252: if (RegExp.test(item)) {
253: divid.style.display = 'inline';
254: } else {
255: divid.style.display = 'block';
256: }
1.470 raeburn 257: setvis = 1;
258: }
259: break;
260: }
261: }
262: if (!setvis) {
263: divid.style.display = 'none';
1.378 raeburn 264: }
265: }
266: }
1.470 raeburn 267: }
268: return;
269: }
270: // ]]>
271: </script>
272:
273: END_SCRIPT
1.378 raeburn 274:
1.134 raeburn 275: }
276:
1.275 raeburn 277: sub build_tools_display {
278: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 279: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.470 raeburn 280: $colspan,$isadv,%domconfig,@defaulteditors,@customeditors,@custommanagers,
1.475 raeburn 281: @possmanagers);
1.275 raeburn 282: my %lt = &Apache::lonlocal::texthash (
283: 'blog' => "Personal User Blog",
284: 'aboutme' => "Personal Information Page",
1.470 raeburn 285: 'webdav' => "WebDAV access to Authoring Spaces (https)",
286: 'editors' => "Available Editors",
1.473 raeburn 287: 'managers' => "Co-authors who can add/revoke roles",
1.479 raeburn 288: 'archive' => "Managers can download tar.gz file of Authoring Space",
1.275 raeburn 289: 'portfolio' => "Personal User Portfolio",
1.470 raeburn 290: 'portaccess' => "Portfolio Shareable",
1.459 raeburn 291: 'timezone' => "Can set Time Zone",
1.275 raeburn 292: 'avai' => "Available",
293: 'cusa' => "availability",
294: 'chse' => "Change setting",
295: 'usde' => "Use default",
296: 'uscu' => "Use custom",
297: 'official' => 'Can request creation of official courses',
1.299 raeburn 298: 'unofficial' => 'Can request creation of unofficial courses',
299: 'community' => 'Can request creation of communities',
1.384 raeburn 300: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 301: 'placement' => 'Can request creation of placement tests',
1.449 raeburn 302: 'lti' => 'Can request creation of LTI courses',
1.362 raeburn 303: 'requestauthor' => 'Can request author space',
1.470 raeburn 304: 'edit' => 'Standard editor (Edit)',
305: 'xml' => 'Text editor (EditXML)',
306: 'daxe' => 'Daxe editor (Daxe)',
1.275 raeburn 307: );
1.462 raeburn 308: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.279 raeburn 309: if ($context eq 'requestcourses') {
1.275 raeburn 310: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 311: 'requestcourses.official','requestcourses.unofficial',
1.411 raeburn 312: 'requestcourses.community','requestcourses.textbook',
1.449 raeburn 313: 'requestcourses.placement','requestcourses.lti');
314: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.309 raeburn 315: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 316: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
317: %reqtitles = &courserequest_titles();
318: %reqdisplay = &courserequest_display();
1.332 raeburn 319: %domconfig =
320: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.362 raeburn 321: } elsif ($context eq 'requestauthor') {
1.470 raeburn 322: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,'requestauthor');
1.362 raeburn 323: @usertools = ('requestauthor');
324: @options =('norequest','approval','automatic');
325: %reqtitles = &requestauthor_titles();
326: %reqdisplay = &requestauthor_display();
327: %domconfig =
328: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.470 raeburn 329: } elsif ($context eq 'authordefaults') {
330: %domconfig =
331: &Apache::lonnet::get_dom('configuration',['quotas','authordefaults'],$ccdomain);
332: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,'tools.webdav',
1.471 raeburn 333: 'authoreditors','authormanagers',
1.477 raeburn 334: 'authorarchive','domcoord.author');
335: @usertools = ('webdav','editors','managers','archive');
1.470 raeburn 336: $colspan = ' colspan="2"';
1.275 raeburn 337: } else {
338: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 339: 'tools.aboutme','tools.portfolio','tools.blog',
1.470 raeburn 340: 'tools.timezone','tools.portaccess');
341: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
342: $colspan = ' colspan="2"';
1.275 raeburn 343: }
344: foreach my $item (@usertools) {
1.306 raeburn 345: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
1.475 raeburn 346: $currdisp,$custdisp,$custradio,$onclick,$customsty,$editorsty);
1.275 raeburn 347: $cust_off = 'checked="checked" ';
348: $tool_on = 'checked="checked" ';
1.477 raeburn 349: unless (($context eq 'authordefaults') || ($item eq 'webdav')) {
1.474 raeburn 350: $curr_access =
351: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
352: $context,\%userenv,'',
353: {'is_adv' => $isadv});
354: }
1.362 raeburn 355: if ($context eq 'requestauthor') {
356: if ($userenv{$context} ne '') {
357: $cust_on = ' checked="checked" ';
358: $cust_off = '';
1.470 raeburn 359: }
360: } elsif ($context eq 'authordefaults') {
1.477 raeburn 361: if (($item eq 'editors') || ($item eq 'archive')) {
1.470 raeburn 362: if ($userenv{'author'.$item} ne '') {
363: $cust_on = ' checked="checked" ';
364: $cust_off = '';
1.478 raeburn 365: if ($item eq 'archive') {
366: $curr_access = $userenv{'author'.$item};
367: }
368: } elsif ($item eq 'archive') {
369: $curr_access = 0;
370: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
371: $curr_access = $domconfig{'authordefaults'}{'archive'};
372: }
1.470 raeburn 373: }
374: } elsif ($item eq 'webdav') {
375: if ($userenv{'tools.'.$item} ne '') {
376: $cust_on = ' checked="checked" ';
377: $cust_off = '';
1.482 ! raeburn 378: $curr_access = $userenv{'tools.'.$item};
! 379: } else {
! 380: $curr_access =
! 381: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,'reload',
! 382: undef,\%userenv,'',
! 383: {'is_adv' => $isadv});
1.470 raeburn 384: }
385: }
1.362 raeburn 386: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 387: $cust_on = ' checked="checked" ';
388: $cust_off = '';
389: }
390: if ($context eq 'requestcourses') {
391: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 392: $custom_access = &mt('Currently from default setting.');
1.470 raeburn 393: $customsty = ' style="display:none;"';
1.306 raeburn 394: } else {
395: $custom_access = &mt('Currently from custom setting.');
1.470 raeburn 396: $customsty = ' style="display:block;"';
1.275 raeburn 397: }
1.362 raeburn 398: } elsif ($context eq 'requestauthor') {
399: if ($userenv{$context} eq '') {
400: $custom_access = &mt('Currently from default setting.');
1.470 raeburn 401: $customsty = ' style="display:none;"';
402: } else {
403: $custom_access = &mt('Currently from custom setting.');
404: $customsty = ' style="display:block;"';
405: }
406: } elsif ($item eq 'editors') {
407: if ($userenv{'author'.$item} eq '') {
408: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
409: @defaulteditors = @{$domconfig{'authordefaults'}{'editors'}};
410: } else {
411: @defaulteditors = ('edit','xml');
412: }
413: $custom_access = &mt('Can use: [_1]',
414: join(', ', map { $lt{$_} } @defaulteditors));
415: $editorsty = ' style="display:none;"';
1.362 raeburn 416: } else {
417: $custom_access = &mt('Currently from custom setting.');
1.470 raeburn 418: foreach my $editor (split(/,/,$userenv{'author'.$item})) {
419: if ($editor =~ /^(edit|daxe|xml)$/) {
420: push(@customeditors,$editor);
421: }
422: }
423: if (@customeditors) {
424: if (@customeditors > 1) {
425: $custom_access .= '<br /><span>';
426: } else {
427: $custom_access .= ' <span class="LC_nobreak">';
428: }
429: $custom_access .= &mt('Can use: [_1]',
430: join(', ', map { $lt{$_} } @customeditors)).
431: '</span>';
432: } else {
433: $custom_access .= ' '.&mt('No available editors');
434: }
435: $editorsty = ' style="display:block;"';
436: }
437: } elsif ($item eq 'managers') {
438: my %ca_roles = &Apache::lonnet::get_my_roles($ccuname,$ccdomain,undef,
439: ['active','future'],['ca']);
440: if (keys(%ca_roles)) {
441: foreach my $entry (sort(keys(%ca_roles))) {
442: if ($entry =~ /^($match_username\:$match_domain):ca$/) {
443: my $user = $1;
444: unless ($user eq "$ccuname:$ccdomain") {
445: push(@possmanagers,$user);
446: }
447: }
448: }
449: }
450: if ($userenv{'author'.$item} eq '') {
451: $custom_access = &mt('Currently author manages co-author roles');
452: } else {
453: if (keys(%ca_roles)) {
454: foreach my $user (split(/,/,$userenv{'author'.$item})) {
455: if ($user =~ /^($match_username):($match_domain)$/) {
456: if (exists($ca_roles{$user.':ca'})) {
457: unless ($user eq "$ccuname:$ccdomain") {
458: push(@custommanagers,$user);
459: }
460: }
461: }
462: }
463: }
464: if (@custommanagers) {
465: $custom_access = &mt('Co-authors who manage co-author roles: [_1]',
466: join(', ',@custommanagers));
467: } else {
468: $custom_access = &mt('Currently author manages co-author roles');
469: }
1.362 raeburn 470: }
1.275 raeburn 471: } else {
1.470 raeburn 472: my $current = $userenv{$context.'.'.$item};
473: if ($item eq 'webdav') {
474: $current = $userenv{'tools.webdav'};
1.478 raeburn 475: } elsif ($item eq 'archive') {
476: $current = $userenv{'author'.$item};
1.470 raeburn 477: }
478: if ($current eq '') {
1.314 raeburn 479: $custom_access =
1.306 raeburn 480: &mt('Availability determined currently from default setting.');
481: if (!$curr_access) {
482: $tool_off = 'checked="checked" ';
483: $tool_on = '';
484: }
1.470 raeburn 485: $customsty = ' style="display:none;"';
1.306 raeburn 486: } else {
1.314 raeburn 487: $custom_access =
1.306 raeburn 488: &mt('Availability determined currently from custom setting.');
1.470 raeburn 489: if ($current == 0) {
1.306 raeburn 490: $tool_off = 'checked="checked" ';
491: $tool_on = '';
492: }
1.476 raeburn 493: $customsty = ' style="display:inline;"';
1.275 raeburn 494: }
495: }
496: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 497: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 498: ' </tr>'."\n".
1.306 raeburn 499: &Apache::loncommon::start_data_table_row()."\n";
1.362 raeburn 500: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.475 raeburn 501: my ($curroption,$currlimit);
1.362 raeburn 502: my $envkey = $context.'.'.$item;
503: if ($context eq 'requestauthor') {
504: $envkey = $context;
505: }
506: if ($userenv{$envkey} ne '') {
507: $curroption = $userenv{$envkey};
1.332 raeburn 508: } else {
509: my (@inststatuses);
1.362 raeburn 510: if ($context eq 'requestcourses') {
511: $curroption =
512: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
513: $isadv,$ccdomain,$item,
514: \@inststatuses,\%domconfig);
515: } else {
516: $curroption =
517: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
518: $isadv,$ccdomain,undef,
519: \@inststatuses,\%domconfig);
520: }
1.332 raeburn 521: }
1.306 raeburn 522: if (!$curroption) {
523: $curroption = 'norequest';
524: }
1.470 raeburn 525: my $name = 'crsreq_'.$item;
526: if ($context eq 'requestauthor') {
527: $name = $item;
528: }
529: $onclick = ' onclick="javascript:toggleCustom(this.form,'."'customtext_$item','custom$item'".');"';
1.306 raeburn 530: if ($curroption =~ /^autolimit=(\d*)$/) {
531: $currlimit = $1;
1.314 raeburn 532: if ($currlimit eq '') {
533: $currdisp = &mt('Yes, automatic creation');
534: } else {
535: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
536: }
1.306 raeburn 537: } else {
538: $currdisp = $reqdisplay{$curroption};
539: }
1.470 raeburn 540: $custdisp = '<fieldset id="customtext_'.$item.'"'.$customsty.'>';
1.306 raeburn 541: foreach my $option (@options) {
542: my $val = $option;
543: if ($option eq 'norequest') {
544: $val = 0;
545: }
546: if ($option eq 'validate') {
547: my $canvalidate = 0;
548: if (ref($validations{$item}) eq 'HASH') {
549: if ($validations{$item}{'_custom_'}) {
550: $canvalidate = 1;
551: }
552: }
553: next if (!$canvalidate);
554: }
555: my $checked = '';
556: if ($option eq $curroption) {
557: $checked = ' checked="checked"';
558: } elsif ($option eq 'autolimit') {
559: if ($curroption =~ /^autolimit/) {
560: $checked = ' checked="checked"';
561: }
562: }
1.470 raeburn 563: if ($option eq 'autolimit') {
564: $custdisp .= '<br />';
1.362 raeburn 565: }
1.470 raeburn 566: $custdisp .= '<span class="LC_nobreak"><label>'.
1.362 raeburn 567: '<input type="radio" name="'.$name.'" '.
568: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 569: $reqtitles{$option}.'</label> ';
570: if ($option eq 'autolimit') {
1.362 raeburn 571: $custdisp .= '<input type="text" name="'.$name.
572: '_limit" size="1" '.
1.470 raeburn 573: 'value="'.$currlimit.'" /> '.
574: $reqtitles{'unlimited'}.'</span>';
1.362 raeburn 575: } else {
576: $custdisp .= '</span>';
577: }
1.470 raeburn 578: $custdisp .= ' ';
579: }
580: $custdisp .= '</fieldset>';
581: $custradio = '<br />'.$custdisp;
582: } elsif ($item eq 'editors') {
583: $output .= '<td'.$colspan.'>'.$custom_access.'</td>'."\n".
584: &Apache::loncommon::end_data_table_row()."\n";
585: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
586: $output .= &Apache::loncommon::start_data_table_row()."\n".
587: '<td'.$colspan.'><span class="LC_nobreak">'.
588: $lt{'chse'}.': <label>'.
589: '<input type="radio" name="custom'.$item.'" value="0" '.
590: $cust_off.' onclick="toggleCustom(this.form,'."'customtext_$item','custom$item'".');" />'.
591: $lt{'usde'}.'</label>'.(' ' x3).
592: '<label><input type="radio" name="custom'.$item.'" value="1" '.
593: $cust_on.' onclick="toggleCustom(this.form,'."'customtext_$item','custom$item'".');" />'.
594: $lt{'uscu'}.'</label></span><br />'.
595: '<fieldset id="customtext_'.$item.'"'.$editorsty.'>';
596: foreach my $editor ('edit','xml','daxe') {
597: my $checked;
598: if ($userenv{'author'.$item} eq '') {
599: if (grep(/^\Q$editor\E$/,@defaulteditors)) {
600: $checked = ' checked="checked"';
601: }
602: } elsif (grep(/^\Q$editor\E$/,@customeditors)) {
603: $checked = ' checked="checked"';
604: }
605: $output .= '<span style="LC_nobreak"><label>'.
606: '<input type="checkbox" name="custom_editor" '.
607: 'value="'.$editor.'"'.$checked.' />'.
608: $lt{$editor}.'</label></span> ';
609: }
610: $output .= '</fieldset></td>'.
611: &Apache::loncommon::end_data_table_row()."\n";
612: }
613: } elsif ($item eq 'managers') {
614: $output .= '<td'.$colspan.'>'.$custom_access.'</td>'."\n".
615: &Apache::loncommon::end_data_table_row()."\n";
1.471 raeburn 616: unless ((&Apache::lonnet::allowed('udp',$ccdomain)) ||
617: (($userenv{'domcoord.author'} eq 'blocked') &&
618: (($env{'user.name'} ne $ccuname) || ($env{'user.domain'} ne $ccdomain)))) {
1.470 raeburn 619: $output .=
620: &Apache::loncommon::start_data_table_row()."\n".
621: '<td'.$colspan.'>';
622: if (@possmanagers) {
623: $output .= &mt('Select manager(s)').': ';
624: foreach my $user (@possmanagers) {
625: my $checked;
626: if (grep(/^\Q$user\E$/,@custommanagers)) {
627: $checked = ' checked="checked"';
628: }
629: $output .= '<span style="LC_nobreak"><label>'.
630: '<input type="checkbox" name="custommanagers" '.
631: 'value="'.&HTML::Entities::encode($user,'\'<>"&').'"'.$checked.' />'.
632: $user.'</label></span> ';
633: }
634: } else {
635: $output .= &mt('No co-author roles assignable as manager');
636: }
637: $output .= '</td>'.
638: &Apache::loncommon::end_data_table_row()."\n";
1.306 raeburn 639: }
640: } else {
641: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 642: my $name = $context.'_'.$item;
1.470 raeburn 643: $onclick = 'onclick="javascript:toggleCustom(this.form,'."'customtext_$item','custom$item'".');" ';
1.306 raeburn 644: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 645: '<input type="radio" name="'.$name.'"'.
1.470 raeburn 646: ' value="1" '.$tool_on.$onclick.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 647: '<input type="radio" name="'.$name.'" value="0" '.
1.470 raeburn 648: $tool_off.$onclick.'/>'.&mt('Off').'</label></span>';
649: $custradio = '<span id="customtext_'.$item.'"'.$customsty.' class="LC_nobreak">'.
650: '--'.$lt{'cusa'}.': '.$custdisp.'</span>';
651: }
652: unless (($item eq 'editors') || ($item eq 'managers')) {
653: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
654: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
655: &Apache::loncommon::end_data_table_row()."\n";
656: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
657: $output .=
1.275 raeburn 658: &Apache::loncommon::start_data_table_row()."\n".
1.470 raeburn 659: '<td><span class="LC_nobreak">'.
1.306 raeburn 660: $lt{'chse'}.': <label>'.
1.275 raeburn 661: '<input type="radio" name="custom'.$item.'" value="0" '.
1.470 raeburn 662: $cust_off.$onclick.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
1.306 raeburn 663: '<label><input type="radio" name="custom'.$item.'" value="1" '.
1.470 raeburn 664: $cust_on.$onclick.'/>'.$lt{'uscu'}.'</label></span>';
665: if ($colspan) {
666: $output .= '</td><td>';
667: }
668: $output .= $custradio.'</td>'.
669: &Apache::loncommon::end_data_table_row()."\n";
670: }
1.418 raeburn 671: }
1.275 raeburn 672: }
673: return $output;
674: }
675:
1.300 raeburn 676: sub coursereq_externaluser {
677: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 678: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 679: my %lt = &Apache::lonlocal::texthash (
680: 'official' => 'Can request creation of official courses',
681: 'unofficial' => 'Can request creation of unofficial courses',
682: 'community' => 'Can request creation of communities',
1.384 raeburn 683: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 684: 'placement' => 'Can request creation of placement tests',
1.300 raeburn 685: );
686:
687: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
688: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.411 raeburn 689: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
690: 'reqcrsotherdom.placement');
691: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 692: @options = ('approval','validate','autolimit');
1.306 raeburn 693: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
694: my $optregex = join('|',@options);
695: my %reqtitles = &courserequest_titles();
1.300 raeburn 696: foreach my $item (@usertools) {
1.306 raeburn 697: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 698: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
699: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 700: foreach my $req (@curr) {
701: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
702: $curroption = $1;
703: $currlimit = $2;
704: last;
1.306 raeburn 705: }
706: }
1.314 raeburn 707: if (!$curroption) {
708: $curroption = 'norequest';
709: $tooloff = ' checked="checked"';
710: }
1.306 raeburn 711: } else {
712: $curroption = 'norequest';
713: $tooloff = ' checked="checked"';
714: }
715: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 716: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
717: '<table><tr><td valign="top">'."\n".
1.306 raeburn 718: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 719: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
720: '</label></td>';
1.306 raeburn 721: foreach my $option (@options) {
722: if ($option eq 'validate') {
723: my $canvalidate = 0;
724: if (ref($validations{$item}) eq 'HASH') {
725: if ($validations{$item}{'_external_'}) {
726: $canvalidate = 1;
727: }
728: }
729: next if (!$canvalidate);
730: }
731: my $checked = '';
732: if ($option eq $curroption) {
733: $checked = ' checked="checked"';
734: }
1.314 raeburn 735: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 736: '<input type="radio" name="reqcrsotherdom_'.$item.
737: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 738: $reqtitles{$option}.'</label>';
1.306 raeburn 739: if ($option eq 'autolimit') {
1.314 raeburn 740: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 741: $item.'_limit" size="1" '.
1.314 raeburn 742: 'value="'.$currlimit.'" /></span>'.
743: '<br />'.$reqtitles{'unlimited'};
744: } else {
745: $output .= '</span>';
1.300 raeburn 746: }
1.314 raeburn 747: $output .= '</td>';
1.300 raeburn 748: }
1.314 raeburn 749: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 750: &Apache::loncommon::end_data_table_row()."\n";
751: }
752: return $output;
753: }
754:
1.362 raeburn 755: sub domainrole_req {
756: my ($ccuname,$ccdomain) = @_;
757: return '<br /><h3>'.
1.470 raeburn 758: &mt('Can Request Assignment of Domain Roles?').
1.362 raeburn 759: '</h3>'."\n".
760: &Apache::loncommon::start_data_table().
761: &build_tools_display($ccuname,$ccdomain,
762: 'requestauthor').
763: &Apache::loncommon::end_data_table();
764: }
765:
1.470 raeburn 766: sub authoring_defaults {
767: my ($ccuname,$ccdomain) = @_;
768: return '<br /><h3>'.
769: &mt('Authoring Space defaults (if role assigned)').
770: '</h3>'."\n".
771: &Apache::loncommon::start_data_table().
772: &build_tools_display($ccuname,$ccdomain,
773: 'authordefaults').
774: &user_quotas($ccuname,$ccdomain,'author').
775: &Apache::loncommon::end_data_table();
776: }
777:
1.306 raeburn 778: sub courserequest_titles {
779: my %titles = &Apache::lonlocal::texthash (
780: official => 'Official',
781: unofficial => 'Unofficial',
782: community => 'Communities',
1.384 raeburn 783: textbook => 'Textbook',
1.411 raeburn 784: placement => 'Placement Tests',
1.449 raeburn 785: lti => 'LTI Provider',
1.306 raeburn 786: norequest => 'Not allowed',
1.309 raeburn 787: approval => 'Approval by Dom. Coord.',
1.306 raeburn 788: validate => 'With validation',
789: autolimit => 'Numerical limit',
1.314 raeburn 790: unlimited => '(blank for unlimited)',
1.306 raeburn 791: );
792: return %titles;
793: }
794:
795: sub courserequest_display {
796: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 797: approval => 'Yes, need approval',
1.306 raeburn 798: validate => 'Yes, with validation',
799: norequest => 'No',
800: );
801: return %titles;
802: }
803:
1.362 raeburn 804: sub requestauthor_titles {
805: my %titles = &Apache::lonlocal::texthash (
806: norequest => 'Not allowed',
807: approval => 'Approval by Dom. Coord.',
808: automatic => 'Automatic approval',
809: );
810: return %titles;
811:
812: }
813:
814: sub requestauthor_display {
815: my %titles = &Apache::lonlocal::texthash (
816: approval => 'Yes, need approval',
817: automatic => 'Yes, automatic approval',
818: norequest => 'No',
819: );
820: return %titles;
821: }
822:
1.383 raeburn 823: sub requestchange_display {
824: my %titles = &Apache::lonlocal::texthash (
825: approval => "availability set to 'on' (approval required)",
826: automatic => "availability set to 'on' (automatic approval)",
827: norequest => "availability set to 'off'",
828: );
829: return %titles;
830: }
831:
1.362 raeburn 832: sub curr_requestauthor {
833: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
834: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
835: if ($uname eq '' || $udom eq '') {
836: $uname = $env{'user.name'};
837: $udom = $env{'user.domain'};
838: $isadv = $env{'user.adv'};
839: }
840: my (%userenv,%settings,$val);
841: my @options = ('automatic','approval');
842: %userenv =
843: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
844: if ($userenv{'requestauthor'}) {
845: $val = $userenv{'requestauthor'};
846: @{$inststatuses} = ('_custom_');
847: } else {
848: my %alltasks;
849: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
850: %settings = %{$domconfig->{'requestauthor'}};
851: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
852: $val = $settings{'_LC_adv'};
853: @{$inststatuses} = ('_LC_adv_');
854: } else {
855: if ($userenv{'inststatus'} ne '') {
856: @{$inststatuses} = split(',',$userenv{'inststatus'});
857: } else {
858: @{$inststatuses} = ('default');
859: }
860: foreach my $status (@{$inststatuses}) {
861: if (exists($settings{$status})) {
862: my $value = $settings{$status};
863: next unless ($value);
864: unless (exists($alltasks{$value})) {
865: if (ref($alltasks{$value}) eq 'ARRAY') {
866: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
867: push(@{$alltasks{$value}},$status);
868: }
869: } else {
870: @{$alltasks{$value}} = ($status);
871: }
872: }
873: }
874: }
875: foreach my $option (@options) {
876: if ($alltasks{$option}) {
877: $val = $option;
878: last;
879: }
880: }
881: }
882: }
883: }
884: return $val;
885: }
886:
1.2 www 887: # =================================================================== Phase one
1.1 www 888:
1.42 matthew 889: sub print_username_entry_form {
1.439 raeburn 890: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
891: $permission) = @_;
1.101 albertel 892: my $defdom=$env{'request.role.domain'};
1.160 raeburn 893: my $formtoset = 'crtuser';
894: if (exists($env{'form.startrolename'})) {
895: $formtoset = 'docustom';
896: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 897: } elsif ($env{'form.origform'} eq 'crtusername') {
898: $formtoset = $env{'form.origform'};
1.160 raeburn 899: }
900:
901: my ($jsback,$elements) = &crumb_utilities();
902:
903: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 904: '<script type="text/javascript">'."\n".
1.301 bisitz 905: '// <![CDATA['."\n".
906: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
907: '// ]]>'."\n".
1.162 raeburn 908: '</script>'."\n";
1.160 raeburn 909:
1.324 raeburn 910: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
911: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
912: && (&Apache::lonnet::allowed('mcr','/'))) {
913: $jscript .= &customrole_javascript();
914: }
1.224 raeburn 915: my $helpitem = 'Course_Change_Privileges';
916: if ($env{'form.action'} eq 'custom') {
1.439 raeburn 917: if ($context eq 'course') {
918: $helpitem = 'Course_Editing_Custom_Roles';
919: } elsif ($context eq 'domain') {
920: $helpitem = 'Domain_Editing_Custom_Roles';
921: }
1.224 raeburn 922: } elsif ($env{'form.action'} eq 'singlestudent') {
923: $helpitem = 'Course_Add_Student';
1.416 raeburn 924: } elsif ($env{'form.action'} eq 'accesslogs') {
925: $helpitem = 'Domain_User_Access_Logs';
1.439 raeburn 926: } elsif ($context eq 'author') {
927: $helpitem = 'Author_Change_Privileges';
928: } elsif ($context eq 'domain') {
929: if ($permission->{'cusr'}) {
930: $helpitem = 'Domain_Change_Privileges';
931: } elsif ($permission->{'view'}) {
932: $helpitem = 'Domain_View_Privileges';
933: } else {
934: undef($helpitem);
935: }
1.224 raeburn 936: }
1.422 raeburn 937: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 938: if ($env{'form.action'} eq 'custom') {
939: push(@{$brcrum},
940: {href=>"javascript:backPage(document.crtuser)",
941: text=>"Pick custom role",
942: help => $helpitem,}
943: );
944: } else {
945: push (@{$brcrum},
946: {href => "javascript:backPage(document.crtuser)",
947: text => $breadcrumb_text{'search'},
948: help => $helpitem,
949: faq => 282,
950: bug => 'Instructor Interface',}
951: );
952: }
953: my %loaditems = (
954: 'onload' => "javascript:setFormElements(document.$formtoset)",
955: );
956: my $args = {bread_crumbs => $brcrum,
957: bread_crumbs_component => 'User Management',
958: add_entries => \%loaditems,};
959: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
960:
1.71 sakharuk 961: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 962: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 963: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 964: 'srad' => 'Search for a user and modify/add user information or roles',
1.422 raeburn 965: 'srvu' => 'Search for a user and view user information and roles',
1.416 raeburn 966: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 967: 'usr' => "Username",
968: 'dom' => "Domain",
1.324 raeburn 969: 'ecrp' => "Define or Edit Custom Role",
970: 'nr' => "role name",
1.282 schafran 971: 'cre' => "Next",
1.71 sakharuk 972: );
1.351 raeburn 973:
1.214 raeburn 974: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 975: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 976: my $newroletext = &mt('Define new custom role:');
977: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
978: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
979: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
980: '<h3>'.$lt{'ecrp'}.'</h3>'.
981: &Apache::loncommon::start_data_table().
982: &Apache::loncommon::start_data_table_row().
983: '<td>');
984: if (keys(%existingroles) > 0) {
985: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
986: } else {
987: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
988: }
989: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
990: &Apache::loncommon::end_data_table_row());
991: if (keys(%existingroles) > 0) {
992: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
993: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
994: &mt('View/Modify existing role:').'</b></label></td>'.
995: '<td align="center"><br />'.
996: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 997: '<option value="" selected="selected">'.
1.324 raeburn 998: &mt('Select'));
999: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 1000: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 1001: }
1002: $r->print('</select>'.
1003: '</td>'.
1004: &Apache::loncommon::end_data_table_row());
1005: }
1006: $r->print(&Apache::loncommon::end_data_table().'<p>'.
1007: '<input name="customeditor" type="submit" value="'.
1008: $lt{'cre'}.'" /></p>'.
1009: '</form>');
1.190 raeburn 1010: }
1.213 raeburn 1011: } else {
1.229 raeburn 1012: my $actiontext = $lt{'srad'};
1.436 raeburn 1013: my $fixeddom;
1.213 raeburn 1014: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1015: if ($crstype eq 'Community') {
1016: $actiontext = $lt{'srme'};
1017: } else {
1018: $actiontext = $lt{'srst'};
1019: }
1.416 raeburn 1020: } elsif ($env{'form.action'} eq 'accesslogs') {
1.417 raeburn 1021: $actiontext = $lt{'srva'};
1.436 raeburn 1022: $fixeddom = 1;
1.422 raeburn 1023: } elsif (($env{'form.action'} eq 'singleuser') &&
1024: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
1025: $actiontext = $lt{'srvu'};
1.439 raeburn 1026: $fixeddom = 1;
1.213 raeburn 1027: }
1.324 raeburn 1028: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 1029: if ($env{'form.origform'} ne 'crtusername') {
1.415 raeburn 1030: if ($response) {
1031: $r->print("\n<div>$response</div>".
1032: '<br clear="all" />');
1033: }
1.213 raeburn 1034: }
1.436 raeburn 1035: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 1036: }
1.110 albertel 1037: }
1038:
1.324 raeburn 1039: sub customrole_javascript {
1040: my $js = <<"END";
1041: <script type="text/javascript">
1042: // <![CDATA[
1043:
1044: function setCustomFields() {
1045: if (document.docustom.customroleaction.length > 0) {
1046: for (var i=0; i<document.docustom.customroleaction.length; i++) {
1047: if (document.docustom.customroleaction[i].checked) {
1048: if (document.docustom.customroleaction[i].value == 'new') {
1049: document.docustom.rolename.selectedIndex = 0;
1050: } else {
1051: document.docustom.newrolename.value = '';
1052: }
1053: }
1054: }
1055: }
1056: return;
1057: }
1058:
1059: function setCustomAction(caller) {
1060: if (document.docustom.customroleaction.length > 0) {
1061: for (var i=0; i<document.docustom.customroleaction.length; i++) {
1062: if (document.docustom.customroleaction[i].value == caller) {
1063: document.docustom.customroleaction[i].checked = true;
1064: }
1065: }
1066: }
1067: setCustomFields();
1068: return;
1069: }
1070:
1071: // ]]>
1072: </script>
1073: END
1074: return $js;
1075: }
1076:
1.160 raeburn 1077: sub entry_form {
1.416 raeburn 1078: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 1079: my ($usertype,$inexact);
1.214 raeburn 1080: if (ref($srch) eq 'HASH') {
1081: if (($srch->{'srchin'} eq 'dom') &&
1082: ($srch->{'srchby'} eq 'uname') &&
1083: ($srch->{'srchtype'} eq 'exact') &&
1084: ($srch->{'srchdomain'} ne '') &&
1085: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 1086: my (%curr_rules,%got_rules);
1.214 raeburn 1087: my ($rules,$ruleorder) =
1088: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 1089: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 1090: } else {
1091: $inexact = 1;
1.214 raeburn 1092: }
1.207 raeburn 1093: }
1.438 raeburn 1094: my ($cancreate,$noinstd);
1095: if ($env{'form.action'} eq 'accesslogs') {
1096: $noinstd = 1;
1097: } else {
1098: $cancreate =
1099: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1100: }
1.412 raeburn 1101: my ($userpicker,$cansearch) =
1.179 raeburn 1102: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.438 raeburn 1103: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 1104: my $srchbutton = &mt('Search');
1.229 raeburn 1105: if ($env{'form.action'} eq 'singlestudent') {
1106: $srchbutton = &mt('Search and Enroll');
1.416 raeburn 1107: } elsif ($env{'form.action'} eq 'accesslogs') {
1108: $srchbutton = &mt('Search');
1.229 raeburn 1109: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
1110: $srchbutton = &mt('Search or Add New User');
1111: }
1.412 raeburn 1112: my $output;
1113: if ($cansearch) {
1114: $output = <<"ENDBLOCK";
1.160 raeburn 1115: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 1116: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 1117: <input type="hidden" name="phase" value="get_user_info" />
1118: $userpicker
1.179 raeburn 1119: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 1120: </form>
1.207 raeburn 1121: ENDBLOCK
1.412 raeburn 1122: } else {
1123: $output = '<p>'.$userpicker.'</p>';
1124: }
1.422 raeburn 1125: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
1.430 raeburn 1126: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1.422 raeburn 1127: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 1128: my $defdom=$env{'request.role.domain'};
1.446 raeburn 1129: my ($trusted,$untrusted);
1.444 raeburn 1130: if ($context eq 'course') {
1.446 raeburn 1131: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.444 raeburn 1132: } elsif ($context eq 'author') {
1.446 raeburn 1133: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.444 raeburn 1134: } elsif ($context eq 'domain') {
1.446 raeburn 1135: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.444 raeburn 1136: }
1.446 raeburn 1137: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain',undef,undef,undef,$trusted,$untrusted);
1.207 raeburn 1138: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 1139: 'enro' => 'Enroll one student',
1.318 raeburn 1140: 'enrm' => 'Enroll one member',
1.229 raeburn 1141: 'admo' => 'Add/modify a single user',
1142: 'crea' => 'create new user if required',
1143: 'uskn' => "username is known",
1.207 raeburn 1144: 'crnu' => 'Create a new user',
1145: 'usr' => 'Username',
1146: 'dom' => 'in domain',
1.229 raeburn 1147: 'enrl' => 'Enroll',
1148: 'cram' => 'Create/Modify user',
1.207 raeburn 1149: );
1.229 raeburn 1150: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
1151: my ($title,$buttontext,$showresponse);
1.318 raeburn 1152: if ($env{'form.action'} eq 'singlestudent') {
1153: if ($crstype eq 'Community') {
1154: $title = $lt{'enrm'};
1155: } else {
1156: $title = $lt{'enro'};
1157: }
1.229 raeburn 1158: $buttontext = $lt{'enrl'};
1159: } else {
1160: $title = $lt{'admo'};
1161: $buttontext = $lt{'cram'};
1162: }
1163: if ($cancreate) {
1164: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
1165: } else {
1166: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
1167: }
1168: if ($env{'form.origform'} eq 'crtusername') {
1169: $showresponse = $responsemsg;
1170: }
1.207 raeburn 1171: $output .= <<"ENDDOCUMENT";
1.229 raeburn 1172: <br />
1.207 raeburn 1173: <form action="/adm/createuser" method="post" name="crtusername">
1174: <input type="hidden" name="action" value="$env{'form.action'}" />
1175: <input type="hidden" name="phase" value="createnewuser" />
1176: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 1177: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 1178: <input type="hidden" name="srchin" value="dom" />
1179: <input type="hidden" name="forcenewuser" value="1" />
1180: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 1181: <h3>$title</h3>
1182: $showresponse
1.207 raeburn 1183: <table>
1184: <tr>
1185: <td>$lt{'usr'}:</td>
1186: <td><input type="text" size="15" name="srchterm" /></td>
1187: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 1188: <td> $sellink </td>
1189: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 1190: </tr>
1191: </table>
1192: </form>
1.160 raeburn 1193: ENDDOCUMENT
1.207 raeburn 1194: }
1.160 raeburn 1195: return $output;
1196: }
1.110 albertel 1197:
1198: sub user_modification_js {
1.113 raeburn 1199: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
1200:
1.110 albertel 1201: return <<END;
1202: <script type="text/javascript" language="Javascript">
1.301 bisitz 1203: // <![CDATA[
1.314 raeburn 1204:
1.110 albertel 1205: $pjump_def
1206: $dc_setcourse_code
1207:
1208: function dateset() {
1209: eval("document.cu."+document.cu.pres_marker.value+
1210: ".value=document.cu.pres_value.value");
1.359 www 1211: modalWindow.close();
1.110 albertel 1212: }
1213:
1.113 raeburn 1214: $nondc_setsection_code
1.301 bisitz 1215: // ]]>
1.110 albertel 1216: </script>
1217: END
1.2 www 1218: }
1219:
1220: # =================================================================== Phase two
1.160 raeburn 1221: sub print_user_selection_page {
1.351 raeburn 1222: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 1223: my @fields = ('username','domain','lastname','firstname','permanentemail');
1224: my $sortby = $env{'form.sortby'};
1225:
1226: if (!grep(/^\Q$sortby\E$/,@fields)) {
1227: $sortby = 'lastname';
1228: }
1229:
1230: my ($jsback,$elements) = &crumb_utilities();
1231:
1232: my $jscript = (<<ENDSCRIPT);
1233: <script type="text/javascript">
1.301 bisitz 1234: // <![CDATA[
1.160 raeburn 1235: function pickuser(uname,udom) {
1236: document.usersrchform.seluname.value=uname;
1237: document.usersrchform.seludom.value=udom;
1238: document.usersrchform.phase.value="userpicked";
1239: document.usersrchform.submit();
1240: }
1241:
1242: $jsback
1.301 bisitz 1243: // ]]>
1.160 raeburn 1244: </script>
1245: ENDSCRIPT
1246:
1247: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1248: 'usrch' => "User Search to add/modify roles",
1249: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1250: 'memsrch' => "User Search to enroll member",
1.416 raeburn 1251: 'srcva' => "Search for a user and view access log information",
1.422 raeburn 1252: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1253: 'usel' => "Select a user to add/modify roles",
1.422 raeburn 1254: 'suvr' => "Select a user to view roles",
1.318 raeburn 1255: 'stusel' => "Select a user to enroll as a student",
1256: 'memsel' => "Select a user to enroll as a member",
1.416 raeburn 1257: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1258: 'username' => "username",
1259: 'domain' => "domain",
1260: 'lastname' => "last name",
1261: 'firstname' => "first name",
1262: 'permanentemail' => "permanent e-mail",
1263: );
1.302 raeburn 1264: if ($context eq 'requestcrs') {
1265: $r->print('<div>');
1266: } else {
1.422 raeburn 1267: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1268: my $helpitem;
1269: if ($env{'form.action'} eq 'singleuser') {
1270: $helpitem = 'Course_Change_Privileges';
1271: } elsif ($env{'form.action'} eq 'singlestudent') {
1272: $helpitem = 'Course_Add_Student';
1.439 raeburn 1273: } elsif ($context eq 'author') {
1274: $helpitem = 'Author_Change_Privileges';
1275: } elsif ($context eq 'domain') {
1276: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1277: }
1278: push (@{$brcrum},
1279: {href => "javascript:backPage(document.usersrchform,'','')",
1280: text => $breadcrumb_text{'search'},
1281: faq => 282,
1282: bug => 'Instructor Interface',},
1283: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1284: text => $breadcrumb_text{'userpicked'},
1285: faq => 282,
1286: bug => 'Instructor Interface',
1287: help => $helpitem}
1288: );
1289: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1290: if ($env{'form.action'} eq 'singleuser') {
1.422 raeburn 1291: my $readonly;
1292: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1293: $readonly = 1;
1294: $r->print("<b>$lt{'usrvu'}</b><br />");
1295: } else {
1296: $r->print("<b>$lt{'usrch'}</b><br />");
1297: }
1.318 raeburn 1298: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.422 raeburn 1299: if ($readonly) {
1300: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1301: } else {
1302: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1303: }
1.302 raeburn 1304: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1305: $r->print($jscript."<b>");
1306: if ($crstype eq 'Community') {
1307: $r->print($lt{'memsrch'});
1308: } else {
1309: $r->print($lt{'stusrch'});
1310: }
1311: $r->print("</b><br />");
1312: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1313: $r->print('</form><h3>');
1314: if ($crstype eq 'Community') {
1315: $r->print($lt{'memsel'});
1316: } else {
1317: $r->print($lt{'stusel'});
1318: }
1319: $r->print('</h3>');
1.416 raeburn 1320: } elsif ($env{'form.action'} eq 'accesslogs') {
1321: $r->print("<b>$lt{'srcva'}</b><br />");
1.438 raeburn 1322: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.416 raeburn 1323: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1324: }
1.179 raeburn 1325: }
1.380 bisitz 1326: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1327: &Apache::loncommon::start_data_table()."\n".
1328: &Apache::loncommon::start_data_table_header_row()."\n".
1329: ' <th> </th>'."\n");
1330: foreach my $field (@fields) {
1331: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1332: "'".$field."'".';document.usersrchform.submit();">'.
1333: $lt{$field}.'</a></th>'."\n");
1334: }
1335: $r->print(&Apache::loncommon::end_data_table_header_row());
1336:
1337: my @sorted_users = sort {
1.167 albertel 1338: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1339: ||
1.167 albertel 1340: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1341: ||
1342: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1343: ||
1344: lc($a) cmp lc($b)
1.160 raeburn 1345: } (keys(%$srch_results));
1346:
1347: foreach my $user (@sorted_users) {
1348: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1349: my $onclick;
1350: if ($context eq 'requestcrs') {
1.314 raeburn 1351: $onclick =
1.302 raeburn 1352: 'onclick="javascript:gochoose('."'$uname','$udom',".
1353: "'$srch_results->{$user}->{firstname}',".
1354: "'$srch_results->{$user}->{lastname}',".
1355: "'$srch_results->{$user}->{permanentemail}'".');"';
1356: } else {
1.314 raeburn 1357: $onclick =
1.302 raeburn 1358: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1359: }
1.160 raeburn 1360: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1361: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1362: $onclick.' /></td>'.
1.160 raeburn 1363: '<td><tt>'.$uname.'</tt></td>'.
1364: '<td><tt>'.$udom.'</tt></td>');
1365: foreach my $field ('lastname','firstname','permanentemail') {
1366: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1367: }
1368: $r->print(&Apache::loncommon::end_data_table_row());
1369: }
1370: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1371: if (ref($srcharray) eq 'ARRAY') {
1372: foreach my $item (@{$srcharray}) {
1373: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1374: }
1375: }
1.160 raeburn 1376: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1377: ' <input type="hidden" name="seluname" value="" />'."\n".
1378: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1379: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1380: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1381: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1382: if ($context eq 'requestcrs') {
1383: $r->print($opener_elements.'</form></div>');
1384: } else {
1.351 raeburn 1385: $r->print($response.'</form>');
1.302 raeburn 1386: }
1.160 raeburn 1387: }
1388:
1389: sub print_user_query_page {
1.351 raeburn 1390: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1391: # FIXME - this is for a network-wide name search (similar to catalog search)
1392: # To use frames with similar behavior to catalog/portfolio search.
1393: # To be implemented.
1394: return;
1395: }
1396:
1.42 matthew 1397: sub print_user_modification_page {
1.375 raeburn 1398: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1399: $brcrum,$showcredits) = @_;
1.185 raeburn 1400: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1401: my $usermsg = &mt('No username and/or domain provided.');
1402: $env{'form.phase'} = '';
1.439 raeburn 1403: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1404: $permission);
1.58 www 1405: return;
1406: }
1.213 raeburn 1407: my ($form,$formname);
1408: if ($env{'form.action'} eq 'singlestudent') {
1409: $form = 'document.enrollstudent';
1410: $formname = 'enrollstudent';
1411: } else {
1412: $form = 'document.cu';
1413: $formname = 'cu';
1414: }
1.188 raeburn 1415: my %abv_auth = &auth_abbrev();
1.227 raeburn 1416: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1417: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1418: if ($uhome eq 'no_host') {
1.215 raeburn 1419: my $usertype;
1420: my ($rules,$ruleorder) =
1421: &Apache::lonnet::inst_userrules($ccdomain,'username');
1422: $usertype =
1.353 raeburn 1423: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1424: \%curr_rules,\%got_rules);
1.215 raeburn 1425: my $cancreate =
1426: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1427: $usertype);
1428: if (!$cancreate) {
1.292 bisitz 1429: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1430: my %usertypetext = (
1431: official => 'institutional',
1432: unofficial => 'non-institutional',
1433: );
1434: my $response;
1435: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1436: $response = '<span class="LC_warning">'.
1437: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1438: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1439: '</span><br />';
1440: }
1.292 bisitz 1441: $response .= '<p class="LC_warning">'
1442: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.418 raeburn 1443: .' ';
1444: if ($context eq 'domain') {
1445: $response .= &mt('Please contact a [_1] for assistance.',
1446: &Apache::lonnet::plaintext('dc'));
1447: } else {
1448: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1449: ,'<a href="'.$helplink.'">','</a>');
1450: }
1451: $response .= '</p><br />';
1.215 raeburn 1452: $env{'form.phase'} = '';
1.439 raeburn 1453: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1454: $permission);
1.215 raeburn 1455: return;
1456: }
1.188 raeburn 1457: $newuser = 1;
1.193 raeburn 1458: my $checkhash;
1459: my $checks = { 'username' => 1 };
1.196 raeburn 1460: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1461: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1462: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1463: if (ref($alerts{'username'}) eq 'HASH') {
1464: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1465: my $domdesc =
1.193 raeburn 1466: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1467: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1468: my $userchkmsg;
1469: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1470: $userchkmsg =
1471: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1472: $domdesc,1).
1473: &Apache::loncommon::user_rule_formats($ccdomain,
1474: $domdesc,$curr_rules{$ccdomain}{'username'},
1475: 'username');
1.196 raeburn 1476: }
1.215 raeburn 1477: $env{'form.phase'} = '';
1.439 raeburn 1478: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1479: $permission);
1.196 raeburn 1480: return;
1.215 raeburn 1481: }
1.193 raeburn 1482: }
1.185 raeburn 1483: }
1.187 raeburn 1484: } else {
1.188 raeburn 1485: $newuser = 0;
1.185 raeburn 1486: }
1.160 raeburn 1487: if ($response) {
1.215 raeburn 1488: $response = '<br />'.$response;
1.160 raeburn 1489: }
1.149 raeburn 1490:
1.52 matthew 1491: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1492: my $dc_setcourse_code = '';
1.119 raeburn 1493: my $nondc_setsection_code = '';
1.112 albertel 1494: my %loaditem;
1.114 albertel 1495:
1.216 raeburn 1496: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1497:
1.470 raeburn 1498: my $js = &validation_javascript($context,$ccdomain,$pjump_def,
1499: $crstype,$groupslist,$newuser,
1500: $formname,\%loaditem,$permission);
1.422 raeburn 1501: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1502: my $helpitem = 'Course_Change_Privileges';
1503: if ($env{'form.action'} eq 'singlestudent') {
1504: $helpitem = 'Course_Add_Student';
1.439 raeburn 1505: } elsif ($context eq 'author') {
1506: $helpitem = 'Author_Change_Privileges';
1507: } elsif ($context eq 'domain') {
1508: $helpitem = 'Domain_Change_Privileges';
1.470 raeburn 1509: $js .= &set_custom_js();
1.224 raeburn 1510: }
1.351 raeburn 1511: push (@{$brcrum},
1512: {href => "javascript:backPage($form)",
1513: text => $breadcrumb_text{'search'},
1514: faq => 282,
1515: bug => 'Instructor Interface',});
1516: if ($env{'form.phase'} eq 'userpicked') {
1517: push(@{$brcrum},
1518: {href => "javascript:backPage($form,'get_user_info','select')",
1519: text => $breadcrumb_text{'userpicked'},
1520: faq => 282,
1521: bug => 'Instructor Interface',});
1522: }
1523: push(@{$brcrum},
1524: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1525: text => $breadcrumb_text{'modify'},
1526: faq => 282,
1527: bug => 'Instructor Interface',
1528: help => $helpitem});
1529: my $args = {'add_entries' => \%loaditem,
1530: 'bread_crumbs' => $brcrum,
1531: 'bread_crumbs_component' => 'User Management'};
1532: if ($env{'form.popup'}) {
1533: $args->{'no_nav_bar'} = 1;
1.481 raeburn 1534: $args->{'add_modal'} = 1;
1.351 raeburn 1535: }
1.470 raeburn 1536: if (($context eq 'domain') && ($env{'request.role.domain'} eq $ccdomain)) {
1537: my @toggles;
1538: if (&Apache::lonnet::allowed('cau',$ccdomain)) {
1539: my ($isadv,$isauthor) =
1540: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1541: unless ($isauthor) {
1542: push(@toggles,'requestauthor');
1543: }
1.478 raeburn 1544: push(@toggles,('webdav','editors','archive'));
1.470 raeburn 1545: }
1546: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1547: push(@toggles,('aboutme','blog','portfolio','portaccess','timezone'));
1548: }
1549: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1550: push(@toggles,('official','unofficial','community','textbook','placement','lti'));
1551: }
1552: if (@toggles) {
1553: my $onload;
1554: foreach my $item (@toggles) {
1555: $onload .= "toggleCustom(document.cu,'customtext_$item','custom$item');";
1556: }
1557: $args->{'add_entries'} = {
1558: 'onload' => $onload,
1559: };
1560: }
1561: }
1.351 raeburn 1562: my $start_page =
1563: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1564:
1.25 matthew 1565: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1566: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1567: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1568: <input type="hidden" name="ccuname" value="$ccuname" />
1569: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1570: <input type="hidden" name="pres_value" value="" />
1571: <input type="hidden" name="pres_type" value="" />
1572: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1573: ENDFORMINFO
1.375 raeburn 1574: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1575: if ($context eq 'course') {
1576: $inccourses{$env{'request.course.id'}}=1;
1577: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1578: if ($showcredits) {
1579: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1580: }
1.329 raeburn 1581: } elsif ($context eq 'author') {
1582: $roledom = $env{'request.role.domain'};
1583: } elsif ($context eq 'domain') {
1584: foreach my $key (keys(%env)) {
1585: $roledom = $env{'request.role.domain'};
1586: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1587: $inccourses{$1.'_'.$2}=1;
1588: }
1589: }
1590: } else {
1591: foreach my $key (keys(%env)) {
1592: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1593: $inccourses{$1.'_'.$2}=1;
1594: }
1.2 www 1595: }
1.24 matthew 1596: }
1.389 bisitz 1597: my $title = '';
1.470 raeburn 1598: my $need_quota_js;
1.216 raeburn 1599: if ($newuser) {
1.427 raeburn 1600: my ($portfolioform,$domroleform);
1.267 raeburn 1601: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1602: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1603: # Current user has quota or user tools modification privileges
1.470 raeburn 1604: $portfolioform = '<br /><h3>'.
1605: &mt('User Tools').
1606: '</h3>'."\n".
1607: &Apache::loncommon::start_data_table();
1608: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1609: $portfolioform .= &build_tools_display($ccuname,$ccdomain,'tools');
1610: }
1611: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
1612: $portfolioform .= &user_quotas($ccuname,$ccdomain,'portfolio');
1613: $need_quota_js = 1;
1614: }
1615: $portfolioform .= &Apache::loncommon::end_data_table();
1.134 raeburn 1616: }
1.383 raeburn 1617: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1618: ($ccdomain eq $env{'request.role.domain'})) {
1.470 raeburn 1619: $domroleform = &domainrole_req($ccuname,$ccdomain).
1620: &authoring_defaults($ccuname,$ccdomain);
1621: $need_quota_js = 1;
1622: }
1623: my $readonly;
1624: unless ($permission->{'cusr'}) {
1625: $readonly = 1;
1.362 raeburn 1626: }
1.470 raeburn 1627: &initialize_authen_forms($ccdomain,$formname,'','',$readonly);
1.188 raeburn 1628: my %lt=&Apache::lonlocal::texthash(
1629: 'lg' => 'Login Data',
1.190 raeburn 1630: 'hs' => "Home Server",
1.188 raeburn 1631: );
1.185 raeburn 1632: $r->print(<<ENDTITLE);
1.110 albertel 1633: $start_page
1.160 raeburn 1634: $response
1.25 matthew 1635: $forminfo
1.31 matthew 1636: <script type="text/javascript" language="Javascript">
1.301 bisitz 1637: // <![CDATA[
1.20 harris41 1638: $loginscript
1.301 bisitz 1639: // ]]>
1.31 matthew 1640: </script>
1.20 harris41 1641: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1642: ENDTITLE
1.213 raeburn 1643: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1644: if ($crstype eq 'Community') {
1.389 bisitz 1645: $title = &mt('Create New User [_1] in domain [_2] as a member',
1646: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1647: } else {
1.389 bisitz 1648: $title = &mt('Create New User [_1] in domain [_2] as a student',
1649: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1650: }
1.389 bisitz 1651: } else {
1652: $title = &mt('Create New User [_1] in domain [_2]',
1653: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1654: }
1.389 bisitz 1655: $r->print('<h2>'.$title.'</h2>'."\n");
1656: $r->print('<div class="LC_left_float">');
1.393 raeburn 1657: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1.470 raeburn 1658: $inst_results{$ccuname.':'.$ccdomain},$readonly));
1.393 raeburn 1659: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1660: my ($home_server_pick,$numlib) =
1661: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1662: 'default','hide');
1663: if ($numlib > 1) {
1664: $r->print("
1.185 raeburn 1665: <br />
1.187 raeburn 1666: $lt{'hs'}: $home_server_pick
1667: <br />");
1668: } else {
1669: $r->print($home_server_pick);
1670: }
1.304 raeburn 1671: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1672: $r->print('<br /><h3>'.
1.470 raeburn 1673: &mt('Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1674: &Apache::loncommon::start_data_table().
1675: &build_tools_display($ccuname,$ccdomain,
1676: 'requestcourses').
1677: &Apache::loncommon::end_data_table());
1678: }
1.188 raeburn 1679: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1680: $lt{'lg'}.'</h3>');
1.185 raeburn 1681: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1682: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1683: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1684: my ($rules,$ruleorder) =
1685: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1686: if (ref($rules) eq 'HASH') {
1.193 raeburn 1687: if (ref($rules->{$matchedrule}) eq 'HASH') {
1688: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1689: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1690: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1691: } else {
1.193 raeburn 1692: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1693: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1694: if ($authtype =~ /^krb(4|5)$/) {
1695: my $ver = $1;
1696: if ($authparm ne '') {
1697: $fixedauth = <<"KERB";
1698: <input type="hidden" name="login" value="krb" />
1699: <input type="hidden" name="krbver" value="$ver" />
1700: <input type="hidden" name="krbarg" value="$authparm" />
1701: KERB
1702: }
1703: } else {
1704: $fixedauth =
1705: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1706: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1707: $fixedauth .=
1708: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1709: } else {
1.273 raeburn 1710: if ($authtype eq 'int') {
1711: $varauth = '<br />'.
1.301 bisitz 1712: &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>';
1.273 raeburn 1713: } elsif ($authtype eq 'loc') {
1714: $varauth = '<br />'.
1715: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1716: } else {
1717: $varauth =
1.185 raeburn 1718: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1719: }
1.185 raeburn 1720: }
1721: }
1722: }
1723: } else {
1.190 raeburn 1724: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1725: }
1726: }
1727: if ($authmsg) {
1728: $r->print(<<ENDAUTH);
1729: $fixedauth
1730: $authmsg
1731: $varauth
1732: ENDAUTH
1733: }
1734: } else {
1.190 raeburn 1735: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1736: }
1.427 raeburn 1737: $r->print($portfolioform.$domroleform);
1.215 raeburn 1738: if ($env{'form.action'} eq 'singlestudent') {
1739: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1740: $permission,$crstype,$ccuname,
1741: $ccdomain,$showcredits));
1.215 raeburn 1742: }
1743: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1744: } else { # user already exists
1.389 bisitz 1745: $r->print($start_page.$forminfo);
1.213 raeburn 1746: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1747: if ($crstype eq 'Community') {
1.389 bisitz 1748: $title = &mt('Enroll one member: [_1] in domain [_2]',
1749: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1750: } else {
1.389 bisitz 1751: $title = &mt('Enroll one student: [_1] in domain [_2]',
1752: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1753: }
1.213 raeburn 1754: } else {
1.418 raeburn 1755: if ($permission->{'cusr'}) {
1756: $title = &mt('Modify existing user: [_1] in domain [_2]',
1757: '"'.$ccuname.'"','"'.$ccdomain.'"');
1758: } else {
1759: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1760: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.418 raeburn 1761: }
1.213 raeburn 1762: }
1.389 bisitz 1763: $r->print('<h2>'.$title.'</h2>'."\n");
1764: $r->print('<div class="LC_left_float">');
1.393 raeburn 1765: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1766: $inst_results{$ccuname.':'.$ccdomain}));
1.430 raeburn 1767: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1.418 raeburn 1768: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.470 raeburn 1769: $r->print('<br /><h3>'.&mt('Can Request Creation of Courses/Communities in this Domain?').'</h3>'."\n");
1.450 raeburn 1770: if (($env{'request.role.domain'} eq $ccdomain) ||
1771: (&Apache::lonnet::will_trust('reqcrs',$ccdomain,$env{'request.role.domain'}))) {
1772: $r->print(&Apache::loncommon::start_data_table());
1773: if ($env{'request.role.domain'} eq $ccdomain) {
1774: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1775: } else {
1.444 raeburn 1776: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1777: $env{'request.role.domain'}));
1778: }
1.450 raeburn 1779: $r->print(&Apache::loncommon::end_data_table());
1780: } else {
1781: $r->print(&mt('Domain configuration for this domain prohibits course creation by users from domain: "[_1]"',
1782: &Apache::lonnet::domain($ccdomain,'description')));
1.300 raeburn 1783: }
1.275 raeburn 1784: }
1.199 raeburn 1785: $r->print('</div>');
1.470 raeburn 1786: my @order = ('auth','quota','tools','requestauthor','authordefaults');
1.362 raeburn 1787: my %user_text;
1788: my ($isadv,$isauthor) =
1.418 raeburn 1789: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.470 raeburn 1790: if (((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1.418 raeburn 1791: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1.470 raeburn 1792: ($env{'request.role.domain'} eq $ccdomain)) {
1793: if (!$isauthor) {
1794: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1795: }
1796: $user_text{'authordefaults'} = &authoring_defaults($ccuname,$ccdomain);
1797: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
1798: $need_quota_js = 1;
1799: }
1.362 raeburn 1800: }
1.451 raeburn 1801: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
1.267 raeburn 1802: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.418 raeburn 1803: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1804: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.470 raeburn 1805: $user_text{'quota'} = '<br /><h3>'.&mt('User Tools').'</h3>'."\n".
1806: &Apache::loncommon::start_data_table();
1807: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
1808: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1809: $user_text{'quota'} .= &build_tools_display($ccuname,$ccdomain,'tools');
1810: }
1.188 raeburn 1811: # Current user has quota modification privileges
1.470 raeburn 1812: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1813: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1814: $user_text{'quota'} .= &user_quotas($ccuname,$ccdomain,'portfolio');
1815: $need_quota_js = 1;
1816: }
1817: $user_text{'quota'} .= &Apache::loncommon::end_data_table();
1.267 raeburn 1818: }
1819: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1820: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1821: my %lt=&Apache::lonlocal::texthash(
1.470 raeburn 1822: 'dska' => "Disk quotas for user's portfolio",
1823: 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
1.267 raeburn 1824: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1825: );
1.362 raeburn 1826: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1827: <h3>$lt{'dska'}</h3>
1828: $lt{'youd'} $lt{'ichr'}: $ccdomain
1829: ENDNOPORTPRIV
1.267 raeburn 1830: }
1831: }
1832: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1833: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1834: my %lt=&Apache::lonlocal::texthash(
1835: 'utav' => "User Tools Availability",
1.470 raeburn 1836: 'yodo' => "You do not have privileges to modify Portfolio, Blog, Personal Information Page, or Time Zone settings for this user.",
1.267 raeburn 1837: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1838: );
1.362 raeburn 1839: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1840: <h3>$lt{'utav'}</h3>
1841: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1842: ENDNOTOOLSPRIV
1843: }
1.188 raeburn 1844: }
1.362 raeburn 1845: my $gotdiv = 0;
1846: foreach my $item (@order) {
1847: if ($user_text{$item} ne '') {
1848: unless ($gotdiv) {
1849: $r->print('<div class="LC_left_float">');
1850: $gotdiv = 1;
1851: }
1852: $r->print('<br />'.$user_text{$item});
1853: }
1854: }
1855: if ($env{'form.action'} eq 'singlestudent') {
1856: unless ($gotdiv) {
1857: $r->print('<div class="LC_left_float">');
1.213 raeburn 1858: }
1.375 raeburn 1859: my $credits;
1860: if ($showcredits) {
1861: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1862: if ($credits eq '') {
1863: $credits = $defaultcredits;
1864: }
1865: }
1.374 raeburn 1866: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1867: $permission,$crstype,$ccuname,
1868: $ccdomain,$showcredits));
1.374 raeburn 1869: }
1.362 raeburn 1870: if ($gotdiv) {
1871: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1872: }
1.418 raeburn 1873: my $statuses;
1874: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1875: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1876: $statuses = ['active'];
1877: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1878: ($env{'request.course.sec'} &&
1879: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1.430 raeburn 1880: $statuses = ['active'];
1.418 raeburn 1881: }
1.217 raeburn 1882: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1883: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.418 raeburn 1884: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1885: }
1.25 matthew 1886: } ## End of new user/old user logic
1.218 raeburn 1887: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1888: my $btntxt;
1889: if ($crstype eq 'Community') {
1890: $btntxt = &mt('Enroll Member');
1891: } else {
1892: $btntxt = &mt('Enroll Student');
1893: }
1894: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.418 raeburn 1895: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1896: $r->print('<div class="LC_left_float">'.
1897: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1898: my $addrolesdisplay = 0;
1899: if ($context eq 'domain' || $context eq 'author') {
1900: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1901: }
1902: if ($context eq 'domain') {
1.357 raeburn 1903: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1904: if (!$addrolesdisplay) {
1905: $addrolesdisplay = $add_domainroles;
1.2 www 1906: }
1.375 raeburn 1907: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1908: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1909: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1910: } elsif ($context eq 'author') {
1911: if ($addrolesdisplay) {
1.393 raeburn 1912: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1913: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1914: if ($newuser) {
1.301 bisitz 1915: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1916: } else {
1.461 raeburn 1917: $r->print(' onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1918: }
1.188 raeburn 1919: } else {
1.393 raeburn 1920: $r->print('</fieldset></div>'.
1921: '<div class="LC_clear_float_footer"></div>'.
1922: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1923: &mt('Back to previous page').'</a>');
1.188 raeburn 1924: }
1925: } else {
1.375 raeburn 1926: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1927: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1928: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1929: }
1.88 raeburn 1930: }
1.188 raeburn 1931: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1932: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1933: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.470 raeburn 1934: if ($need_quota_js) {
1935: $r->print(&user_quota_js());
1936: }
1.218 raeburn 1937: return;
1.2 www 1938: }
1.1 www 1939:
1.213 raeburn 1940: sub singleuser_breadcrumb {
1.422 raeburn 1941: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1942: my %breadcrumb_text;
1943: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1944: if ($crstype eq 'Community') {
1945: $breadcrumb_text{'search'} = 'Enroll a member';
1946: } else {
1947: $breadcrumb_text{'search'} = 'Enroll a student';
1948: }
1.422 raeburn 1949: $breadcrumb_text{'userpicked'} = 'Select a user';
1950: $breadcrumb_text{'modify'} = 'Set section/dates';
1.416 raeburn 1951: } elsif ($env{'form.action'} eq 'accesslogs') {
1952: $breadcrumb_text{'search'} = 'View access logs for a user';
1.422 raeburn 1953: $breadcrumb_text{'userpicked'} = 'Select a user';
1954: $breadcrumb_text{'activity'} = 'Activity';
1955: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1956: (!&Apache::lonnet::allowed('mau',$domain))) {
1957: $breadcrumb_text{'search'} = "View user's roles";
1958: $breadcrumb_text{'userpicked'} = 'Select a user';
1959: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1960: } else {
1.229 raeburn 1961: $breadcrumb_text{'search'} = 'Create/modify a user';
1.422 raeburn 1962: $breadcrumb_text{'userpicked'} = 'Select a user';
1963: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1964: }
1965: return %breadcrumb_text;
1966: }
1967:
1968: sub date_sections_select {
1.375 raeburn 1969: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1970: $showcredits) = @_;
1971: my $credits;
1972: if ($showcredits) {
1973: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1974: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1975: if ($credits eq '') {
1976: $credits = $defaultcredits;
1977: }
1978: }
1.213 raeburn 1979: my $cid = $env{'request.course.id'};
1980: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1981: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1982: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1983: undef,$formname,$permission);
1984: my $rowtitle = 'Section';
1.375 raeburn 1985: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1986: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1987: $permission,$context,'',$crstype,
1988: $showcredits,$credits);
1.213 raeburn 1989: my $output = $date_table.$secbox;
1990: return $output;
1991: }
1992:
1.216 raeburn 1993: sub validation_javascript {
1.375 raeburn 1994: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.470 raeburn 1995: $loaditem,$permission) = @_;
1.216 raeburn 1996: my $dc_setcourse_code = '';
1997: my $nondc_setsection_code = '';
1998: if ($context eq 'domain') {
1.470 raeburn 1999: if ((ref($permission) eq 'HASH') && ($permission->{'cusr'})) {
2000: my $dcdom = $env{'request.role.domain'};
2001: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
2002: $dc_setcourse_code =
2003: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
2004: }
1.216 raeburn 2005: } else {
1.227 raeburn 2006: my $checkauth;
2007: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
2008: $checkauth = 1;
2009: }
2010: if ($context eq 'course') {
2011: $nondc_setsection_code =
2012: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 2013: undef,$checkauth,
2014: $crstype);
1.227 raeburn 2015: }
2016: if ($checkauth) {
2017: $nondc_setsection_code .=
2018: &Apache::lonuserutils::verify_authen($formname,$context);
2019: }
1.216 raeburn 2020: }
2021: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
2022: $nondc_setsection_code,$groupslist);
2023: my ($jsback,$elements) = &crumb_utilities();
2024: $js .= "\n".
1.301 bisitz 2025: '<script type="text/javascript">'."\n".
2026: '// <![CDATA['."\n".
2027: $jsback."\n".
2028: '// ]]>'."\n".
2029: '</script>'."\n";
1.216 raeburn 2030: return $js;
2031: }
2032:
1.217 raeburn 2033: sub display_existing_roles {
1.375 raeburn 2034: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.418 raeburn 2035: $showcredits,$statuses) = @_;
1.329 raeburn 2036: my $now=time;
1.418 raeburn 2037: my $showall = 1;
2038: my ($showexpired,$showactive);
2039: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
2040: $showall = 0;
2041: if (grep(/^expired$/,@{$statuses})) {
2042: $showexpired = 1;
2043: }
2044: if (grep(/^active$/,@{$statuses})) {
2045: $showactive = 1;
2046: }
2047: if ($showexpired && $showactive) {
2048: $showall = 1;
2049: }
2050: }
1.329 raeburn 2051: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 2052: 'rer' => "Existing Roles",
2053: 'rev' => "Revoke",
2054: 'del' => "Delete",
2055: 'ren' => "Re-Enable",
2056: 'rol' => "Role",
2057: 'ext' => "Extent",
1.375 raeburn 2058: 'crd' => "Credits",
1.217 raeburn 2059: 'sta' => "Start",
2060: 'end' => "End",
2061: );
1.329 raeburn 2062: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
2063: if ($context eq 'course' || $context eq 'author') {
2064: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
2065: my %roleshash =
2066: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
2067: ['active','previous','future'],\@roles,$roledom,1);
2068: foreach my $key (keys(%roleshash)) {
2069: my ($start,$end) = split(':',$roleshash{$key});
2070: next if ($start eq '-1' || $end eq '-1');
2071: my ($rnum,$rdom,$role,$sec) = split(':',$key);
2072: if ($context eq 'course') {
2073: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
2074: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
2075: } elsif ($context eq 'author') {
1.470 raeburn 2076: if ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2077: my ($audom,$auname) = ($1,$2);
2078: next unless (($rnum eq $auname) && ($rdom eq $audom));
2079: } else {
2080: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
2081: }
1.329 raeburn 2082: }
2083: my ($newkey,$newvalue,$newrole);
2084: $newkey = '/'.$rdom.'/'.$rnum;
2085: if ($sec ne '') {
2086: $newkey .= '/'.$sec;
2087: }
2088: $newvalue = $role;
2089: if ($role =~ /^cr/) {
2090: $newrole = 'cr';
2091: } else {
2092: $newrole = $role;
2093: }
2094: $newkey .= '_'.$newrole;
2095: if ($start ne '' && $end ne '') {
2096: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 2097: } elsif ($end ne '') {
2098: $newvalue .= '_'.$end;
1.329 raeburn 2099: }
2100: $rolesdump{$newkey} = $newvalue;
2101: }
2102: } else {
1.360 raeburn 2103: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 2104: }
2105: # Build up table of user roles to allow revocation and re-enabling of roles.
2106: my ($tmp) = keys(%rolesdump);
2107: return if ($tmp =~ /^(con_lost|error)/i);
2108: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
2109: my $b1=join('_',(split('_',$b))[1,0]);
2110: return $a1 cmp $b1;
2111: } keys(%rolesdump)) {
2112: next if ($area =~ /^rolesdef/);
2113: my $envkey=$area;
2114: my $role = $rolesdump{$area};
2115: my $thisrole=$area;
2116: $area =~ s/\_\w\w$//;
2117: my ($role_code,$role_end_time,$role_start_time) =
2118: split(/_/,$role);
1.418 raeburn 2119: my $active=1;
2120: $active=0 if (($role_end_time) && ($now>$role_end_time));
2121: if ($active) {
2122: next unless($showall || $showactive);
2123: } else {
1.430 raeburn 2124: next unless($showall || $showexpired);
1.418 raeburn 2125: }
1.217 raeburn 2126: # Is this a custom role? Get role owner and title.
1.329 raeburn 2127: my ($croleudom,$croleuname,$croletitle)=
2128: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
2129: my $allowed=0;
2130: my $delallowed=0;
2131: my $sortkey=$role_code;
2132: my $class='Unknown';
1.375 raeburn 2133: my $credits='';
1.418 raeburn 2134: my $csec;
1.421 raeburn 2135: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 2136: $class='Course';
2137: my ($coursedom,$coursedir) = ($1,$2);
2138: my $cid = $1.'_'.$2;
2139: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.421 raeburn 2140: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 2141: my %coursedata=
2142: &Apache::lonnet::coursedescription($cid);
2143: if ($coursedir =~ /^$match_community$/) {
2144: $class='Community';
2145: }
2146: $sortkey.="\0$coursedom";
2147: my $carea;
2148: if (defined($coursedata{'description'})) {
2149: $carea=$coursedata{'description'}.
2150: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
2151: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
2152: $sortkey.="\0".$coursedata{'description'};
2153: } else {
2154: if ($class eq 'Community') {
2155: $carea=&mt('Unavailable community').': '.$area;
2156: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 2157: } else {
2158: $carea=&mt('Unavailable course').': '.$area;
2159: $sortkey.="\0".&mt('Unavailable course').': '.$area;
2160: }
1.329 raeburn 2161: }
2162: $sortkey.="\0$coursedir";
2163: $inccourses->{$cid}=1;
1.375 raeburn 2164: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
2165: my $defaultcredits = $coursedata{'internal.defaultcredits'};
2166: $credits =
2167: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
2168: $coursedom,$coursedir);
2169: if ($credits eq '') {
2170: $credits = $defaultcredits;
2171: }
2172: }
1.329 raeburn 2173: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
2174: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
2175: $allowed=1;
2176: }
2177: unless ($allowed) {
1.365 raeburn 2178: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 2179: if ($isowner) {
2180: if (($role_code eq 'co') && ($class eq 'Community')) {
2181: $allowed = 1;
2182: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
2183: $allowed = 1;
2184: }
1.217 raeburn 2185: }
1.329 raeburn 2186: }
2187: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
2188: (&Apache::lonnet::allowed('dro',$ccdomain))) {
2189: $delallowed=1;
2190: }
1.217 raeburn 2191: # - custom role. Needs more info, too
1.329 raeburn 2192: if ($croletitle) {
2193: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
2194: $allowed=1;
2195: $thisrole.='.'.$role_code;
1.217 raeburn 2196: }
1.329 raeburn 2197: }
1.418 raeburn 2198: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
2199: $csec = $2;
2200: $carea.='<br />'.&mt('Section: [_1]',$csec);
2201: $sortkey.="\0$csec";
1.329 raeburn 2202: if (!$allowed) {
1.418 raeburn 2203: if ($env{'request.course.sec'} eq $csec) {
2204: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 2205: $allowed = 1;
1.217 raeburn 2206: }
2207: }
2208: }
1.329 raeburn 2209: }
2210: $area=$carea;
2211: } else {
2212: $sortkey.="\0".$area;
2213: # Determine if current user is able to revoke privileges
2214: if ($area=~m{^/($match_domain)/}) {
2215: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
2216: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
2217: $allowed=1;
1.217 raeburn 2218: }
1.329 raeburn 2219: if (((&Apache::lonnet::allowed('dro',$1)) ||
2220: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
2221: ($role_code ne 'dc')) {
2222: $delallowed=1;
1.217 raeburn 2223: }
1.329 raeburn 2224: } else {
2225: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 2226: $allowed=1;
2227: }
2228: }
1.363 raeburn 2229: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 2230: $class='Authoring Space';
1.329 raeburn 2231: } elsif ($role_code eq 'su') {
2232: $class='System';
1.217 raeburn 2233: } else {
1.329 raeburn 2234: $class='Domain';
1.217 raeburn 2235: }
1.329 raeburn 2236: }
2237: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
2238: $area=~m{/($match_domain)/($match_username)};
2239: if (&Apache::lonuserutils::authorpriv($2,$1)) {
2240: $allowed=1;
1.470 raeburn 2241: } elsif (&Apache::lonuserutils::coauthorpriv($2,$1)) {
2242: $allowed=1;
1.217 raeburn 2243: } else {
1.329 raeburn 2244: $allowed=0;
1.217 raeburn 2245: }
1.329 raeburn 2246: }
2247: my $row = '';
1.418 raeburn 2248: if ($showall) {
2249: $row.= '<td>';
2250: if (($active) && ($allowed)) {
2251: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
2252: } else {
2253: if ($active) {
2254: $row.=' ';
2255: } else {
2256: $row.=&mt('expired or revoked');
2257: }
2258: }
2259: $row.='</td><td>';
2260: if ($allowed && !$active) {
2261: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
2262: } else {
2263: $row.=' ';
2264: }
2265: $row.='</td><td>';
2266: if ($delallowed) {
2267: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.217 raeburn 2268: } else {
1.418 raeburn 2269: $row.=' ';
1.217 raeburn 2270: }
1.430 raeburn 2271: $row.= '</td>';
1.329 raeburn 2272: }
2273: my $plaintext='';
2274: if (!$croletitle) {
1.375 raeburn 2275: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
2276: if (($showcredits) && ($credits ne '')) {
2277: $plaintext .= '<br/ ><span class="LC_nobreak">'.
2278: '<span class="LC_fontsize_small">'.
2279: &mt('Credits: [_1]',$credits).
2280: '</span></span>';
2281: }
1.329 raeburn 2282: } else {
2283: $plaintext=
1.395 bisitz 2284: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 2285: '"'.$croletitle.'"',
2286: '<br />',
2287: $croleuname.':'.$croleudom);
1.329 raeburn 2288: }
1.418 raeburn 2289: $row.= '<td>'.$plaintext.'</td>'.
2290: '<td>'.$area.'</td>'.
2291: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
2292: : ' ' ).'</td>'.
2293: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
2294: : ' ' ).'</td>';
1.329 raeburn 2295: $sortrole{$sortkey}=$envkey;
2296: $roletext{$envkey}=$row;
2297: $roleclass{$envkey}=$class;
1.418 raeburn 2298: if ($allowed) {
2299: $rolepriv{$envkey}='edit';
2300: } else {
2301: if ($context eq 'domain') {
1.420 raeburn 2302: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1.421 raeburn 2303: ($envkey=~m{^/$ccdomain/})) {
1.418 raeburn 2304: $rolepriv{$envkey}='view';
2305: }
2306: } elsif ($context eq 'course') {
2307: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
2308: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
2309: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
2310: $rolepriv{$envkey}='view';
2311: }
2312: }
2313: }
1.329 raeburn 2314: } # end of foreach (table building loop)
2315:
2316: my $rolesdisplay = 0;
2317: my %output = ();
1.377 raeburn 2318: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2319: $output{$type} = '';
2320: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2321: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2322: $output{$type}.=
2323: &Apache::loncommon::start_data_table_row().
2324: $roletext{$sortrole{$which}}.
2325: &Apache::loncommon::end_data_table_row();
1.217 raeburn 2326: }
1.329 raeburn 2327: }
2328: unless($output{$type} eq '') {
2329: $output{$type} = '<tr class="LC_info_row">'.
2330: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2331: $output{$type};
2332: $rolesdisplay = 1;
2333: }
2334: }
2335: if ($rolesdisplay == 1) {
2336: my $contextrole='';
2337: if ($env{'request.course.id'}) {
2338: if (&Apache::loncommon::course_type() eq 'Community') {
2339: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2340: } else {
1.329 raeburn 2341: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2342: }
1.329 raeburn 2343: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2344: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.470 raeburn 2345: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)/$}) {
2346: $contextrole = &mt('Existing Co-Author Roles in [_1] Authoring Space',
2347: '<i>'.$1.'_'.$2.'</i>');
1.329 raeburn 2348: } else {
1.418 raeburn 2349: if ($showall) {
2350: $contextrole = &mt('Existing Roles in this Domain');
2351: } elsif ($showactive) {
2352: $contextrole = &mt('Unexpired Roles in this Domain');
2353: } elsif ($showexpired) {
2354: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2355: }
1.329 raeburn 2356: }
1.393 raeburn 2357: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2358: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2359: &Apache::loncommon::start_data_table("LC_createuser").
1.418 raeburn 2360: &Apache::loncommon::start_data_table_header_row());
2361: if ($showall) {
2362: $r->print(
1.419 raeburn 2363: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1.418 raeburn 2364: );
2365: } elsif ($showexpired) {
2366: $r->print('<th>'.$lt{'rev'}.'</th>');
2367: }
2368: $r->print(
1.419 raeburn 2369: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2370: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2371: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2372: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2373: if ($output{$type}) {
2374: $r->print($output{$type}."\n");
1.217 raeburn 2375: }
2376: }
1.375 raeburn 2377: $r->print(&Apache::loncommon::end_data_table().
2378: '</fieldset></div>');
1.329 raeburn 2379: }
1.217 raeburn 2380: return;
2381: }
2382:
1.218 raeburn 2383: sub new_coauthor_roles {
2384: my ($r,$ccuname,$ccdomain) = @_;
2385: my $addrolesdisplay = 0;
2386: #
2387: # Co-Author
2388: #
1.470 raeburn 2389: my ($cuname,$cudom);
2390: if (($env{'request.role'} eq "au./$env{'user.domain'}/") ||
2391: ($env{'request.role'} eq "dc./$env{'user.domain'}/")) {
2392: $cuname=$env{'user.name'};
2393: $cudom=$env{'request.role.domain'};
1.218 raeburn 2394: # No sense in assigning co-author role to yourself
1.470 raeburn 2395: if ((&Apache::lonuserutils::authorpriv($cuname,$cudom)) &&
2396: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2397: $addrolesdisplay = 1;
2398: }
2399: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2400: ($cudom,$cuname) = ($1,$2);
2401: if ((&Apache::lonuserutils::coauthorpriv($cuname,$cudom)) &&
2402: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain) &&
2403: ($cudom ne $ccdomain || $cuname ne $ccuname)) {
2404: $addrolesdisplay = 1;
2405: }
2406: }
2407: if ($addrolesdisplay) {
1.218 raeburn 2408: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2409: 'cs' => "Authoring Space",
1.218 raeburn 2410: 'act' => "Activate",
2411: 'rol' => "Role",
2412: 'ext' => "Extent",
2413: 'sta' => "Start",
2414: 'end' => "End",
2415: 'cau' => "Co-Author",
2416: 'caa' => "Assistant Co-Author",
2417: 'ssd' => "Set Start Date",
2418: 'sed' => "Set End Date"
2419: );
2420: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2421: &Apache::loncommon::start_data_table()."\n".
2422: &Apache::loncommon::start_data_table_header_row()."\n".
2423: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2424: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2425: '<th>'.$lt{'end'}.'</th>'."\n".
2426: &Apache::loncommon::end_data_table_header_row()."\n".
2427: &Apache::loncommon::start_data_table_row().'
2428: <td>
1.291 bisitz 2429: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2430: </td>
2431: <td>'.$lt{'cau'}.'</td>
2432: <td>'.$cudom.'_'.$cuname.'</td>
2433: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2434: <a href=
2435: "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>
2436: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2437: <a href=
2438: "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".
2439: &Apache::loncommon::end_data_table_row()."\n".
2440: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2441: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2442: <td>'.$lt{'caa'}.'</td>
2443: <td>'.$cudom.'_'.$cuname.'</td>
2444: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2445: <a href=
2446: "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>
2447: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2448: <a href=
2449: "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".
2450: &Apache::loncommon::end_data_table_row()."\n".
2451: &Apache::loncommon::end_data_table());
2452: } elsif ($env{'request.role'} =~ /^au\./) {
2453: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2454: $env{'request.role.domain'}))) {
2455: $r->print('<span class="LC_error">'.
2456: &mt('You do not have privileges to assign co-author roles.').
2457: '</span>');
2458: } elsif (($env{'user.name'} eq $ccuname) &&
2459: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2460: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Authoring Space is not permitted'));
1.218 raeburn 2461: }
1.470 raeburn 2462: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2463: if (!(&Apache::lonuserutils::coauthorpriv($2,$1))) {
2464: $r->print('<span class="LC_error">'.
2465: &mt('You do not have privileges to assign co-author roles.').
2466: '</span>');
2467: } elsif (($env{'user.name'} eq $ccuname) &&
2468: ($env{'user.domain'} eq $ccdomain)) {
2469: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in an author area in Authoring Space in which you already have a co-author role is not permitted'));
2470: } elsif (($cudom eq $ccdomain) && ($cuname eq $ccuname)) {
2471: $r->print(&mt("Assigning a co-author or assistant co-author role to an Authoring Space's author is not permitted"));
2472: }
1.218 raeburn 2473: }
2474: return $addrolesdisplay;;
2475: }
2476:
2477: sub new_domain_roles {
1.357 raeburn 2478: my ($r,$ccdomain) = @_;
1.218 raeburn 2479: my $addrolesdisplay = 0;
2480: #
2481: # Domain level
2482: #
2483: my $num_domain_level = 0;
2484: my $domaintext =
2485: '<h4>'.&mt('Domain Level').'</h4>'.
2486: &Apache::loncommon::start_data_table().
2487: &Apache::loncommon::start_data_table_header_row().
2488: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2489: &mt('Extent').'</th>'.
2490: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2491: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2492: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.445 raeburn 2493: my $uprimary = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2494: my $uintdom = &Apache::lonnet::internet_dom($uprimary);
1.218 raeburn 2495: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2496: foreach my $role (@allroles) {
2497: next if ($role eq 'ad');
1.357 raeburn 2498: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2499: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1.445 raeburn 2500: if ($role eq 'dc') {
2501: unless ($thisdomain eq $env{'request.role.domain'}) {
2502: my $domprim = &Apache::lonnet::domain($thisdomain,'primary');
2503: my $intdom = &Apache::lonnet::internet_dom($domprim);
2504: next unless ($uintdom eq $intdom);
2505: }
2506: }
1.218 raeburn 2507: my $plrole=&Apache::lonnet::plaintext($role);
2508: my %lt=&Apache::lonlocal::texthash(
2509: 'ssd' => "Set Start Date",
2510: 'sed' => "Set End Date"
2511: );
2512: $num_domain_level ++;
2513: $domaintext .=
2514: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2515: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2516: <td>'.$plrole.'</td>
2517: <td>'.$thisdomain.'</td>
2518: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2519: <a href=
2520: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2521: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2522: <a href=
2523: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2524: &Apache::loncommon::end_data_table_row();
2525: }
2526: }
2527: }
2528: $domaintext.= &Apache::loncommon::end_data_table();
2529: if ($num_domain_level > 0) {
2530: $r->print($domaintext);
2531: $addrolesdisplay = 1;
2532: }
2533: return $addrolesdisplay;
2534: }
2535:
1.188 raeburn 2536: sub user_authentication {
1.451 raeburn 2537: my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
1.188 raeburn 2538: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2539: my $outcome;
1.418 raeburn 2540: my %lt=&Apache::lonlocal::texthash(
2541: 'err' => "ERROR",
2542: 'uuas' => "This user has an unrecognized authentication scheme",
2543: 'adcs' => "Please alert a domain coordinator of this situation",
2544: 'sldb' => "Please specify login data below",
2545: 'ld' => "Login Data"
2546: );
1.188 raeburn 2547: # Check for a bad authentication type
1.449 raeburn 2548: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth|lti):/) {
1.188 raeburn 2549: # bad authentication scheme
2550: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2551: &initialize_authen_forms($ccdomain,$formname);
2552:
1.190 raeburn 2553: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2554: $outcome = <<ENDBADAUTH;
2555: <script type="text/javascript" language="Javascript">
1.301 bisitz 2556: // <![CDATA[
1.188 raeburn 2557: $loginscript
1.301 bisitz 2558: // ]]>
1.188 raeburn 2559: </script>
2560: <span class="LC_error">$lt{'err'}:
2561: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2562: <h3>$lt{'ld'}</h3>
2563: $choices
2564: ENDBADAUTH
2565: } else {
2566: # This user is not allowed to modify the user's
2567: # authentication scheme, so just notify them of the problem
2568: $outcome = <<ENDBADAUTH;
2569: <span class="LC_error"> $lt{'err'}:
2570: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2571: </span>
2572: ENDBADAUTH
2573: }
2574: } else { # Authentication type is valid
1.418 raeburn 2575:
1.227 raeburn 2576: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2577: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2578: &modify_login_block($ccdomain,$currentauth);
2579: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2580: # Current user has login modification privileges
2581: $outcome =
2582: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2583: '// <![CDATA['."\n".
1.188 raeburn 2584: $loginscript."\n".
1.301 bisitz 2585: '// ]]>'."\n".
1.188 raeburn 2586: '</script>'."\n".
2587: '<h3>'.$lt{'ld'}.'</h3>'.
2588: &Apache::loncommon::start_data_table().
1.205 raeburn 2589: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2590: '<td>'.$authformnop;
1.418 raeburn 2591: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2592: $outcome .= '</td>'."\n".
2593: &Apache::loncommon::end_data_table_row().
2594: &Apache::loncommon::start_data_table_row().
2595: '<td>'.$authformcurrent.'</td>'.
2596: &Apache::loncommon::end_data_table_row()."\n";
2597: } else {
1.200 raeburn 2598: $outcome .= ' ('.$authformcurrent.')</td>'.
2599: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2600: }
1.418 raeburn 2601: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2602: foreach my $item (@authform_others) {
2603: $outcome .= &Apache::loncommon::start_data_table_row().
2604: '<td>'.$item.'</td>'.
2605: &Apache::loncommon::end_data_table_row()."\n";
2606: }
1.188 raeburn 2607: }
1.205 raeburn 2608: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2609: } else {
1.451 raeburn 2610: if (($currentauth =~ /^internal:/) &&
2611: (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
2612: $outcome = <<"ENDJS";
2613: <script type="text/javascript">
2614: // <![CDATA[
2615: function togglePwd(form) {
2616: if (form.newintpwd.length) {
2617: if (document.getElementById('LC_ownersetpwd')) {
2618: for (var i=0; i<form.newintpwd.length; i++) {
2619: if (form.newintpwd[i].checked) {
2620: if (form.newintpwd[i].value == 1) {
2621: document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
2622: } else {
2623: document.getElementById('LC_ownersetpwd').style.display = 'none';
2624: }
2625: }
2626: }
2627: }
2628: }
2629: }
2630: // ]]>
2631: </script>
2632: ENDJS
2633:
2634: $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
2635: &Apache::loncommon::start_data_table().
2636: &Apache::loncommon::start_data_table_row().
2637: '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
2638: '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
2639: &mt('No').'</label>'.(' 'x2).
2640: '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
2641: '<div id="LC_ownersetpwd" style="display:none">'.
2642: ' '.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
2643: '<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></div></td>'.
2644: &Apache::loncommon::end_data_table_row().
2645: &Apache::loncommon::end_data_table();
2646: }
1.418 raeburn 2647: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2648: # Current user has rights to view domain preferences for user's domain
2649: my $result;
2650: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2651: my ($krbver,$krbrealm) = ($1,$2);
2652: if ($krbrealm eq '') {
2653: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2654: } else {
2655: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.426 raeburn 2656: $krbrealm,$krbver);
1.418 raeburn 2657: }
2658: } elsif ($currentauth =~ /^internal:/) {
2659: $result = &mt('Currently internally authenticated.');
2660: } elsif ($currentauth =~ /^localauth:/) {
2661: $result = &mt('Currently using local (institutional) authentication.');
2662: } elsif ($currentauth =~ /^unix:/) {
2663: $result = &mt('Currently Filesystem Authenticated.');
1.449 raeburn 2664: } elsif ($currentauth =~ /^lti:/) {
1.451 raeburn 2665: $result = &mt('Currently LTI authenticated.');
1.418 raeburn 2666: }
2667: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2668: &Apache::loncommon::start_data_table().
2669: &Apache::loncommon::start_data_table_row().
2670: '<td>'.$result.'</td>'.
2671: &Apache::loncommon::end_data_table_row()."\n".
2672: &Apache::loncommon::end_data_table();
2673: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2674: my %lt=&Apache::lonlocal::texthash(
2675: 'ccld' => "Change Current Login Data",
2676: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2677: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2678: );
2679: $outcome .= <<ENDNOPRIV;
2680: <h3>$lt{'ccld'}</h3>
2681: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2682: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2683: ENDNOPRIV
2684: }
2685: }
2686: } ## End of "check for bad authentication type" logic
2687: return $outcome;
2688: }
2689:
1.187 raeburn 2690: sub modify_login_block {
2691: my ($dom,$currentauth) = @_;
2692: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2693: my ($authnum,%can_assign) =
2694: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2695: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2696: if ($currentauth=~/^krb(4|5):/) {
2697: $authformcurrent=$authformkrb;
2698: if ($can_assign{'int'}) {
1.205 raeburn 2699: push(@authform_others,$authformint);
1.187 raeburn 2700: }
2701: if ($can_assign{'loc'}) {
1.205 raeburn 2702: push(@authform_others,$authformloc);
1.187 raeburn 2703: }
1.449 raeburn 2704: if ($can_assign{'lti'}) {
2705: push(@authform_others,$authformlti);
2706: }
1.187 raeburn 2707: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2708: $show_override_msg = 1;
2709: }
2710: } elsif ($currentauth=~/^internal:/) {
2711: $authformcurrent=$authformint;
2712: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2713: push(@authform_others,$authformkrb);
1.187 raeburn 2714: }
2715: if ($can_assign{'loc'}) {
1.205 raeburn 2716: push(@authform_others,$authformloc);
1.187 raeburn 2717: }
1.449 raeburn 2718: if ($can_assign{'lti'}) {
2719: push(@authform_others,$authformlti);
2720: }
1.187 raeburn 2721: if ($can_assign{'int'}) {
2722: $show_override_msg = 1;
2723: }
2724: } elsif ($currentauth=~/^unix:/) {
2725: $authformcurrent=$authformfsys;
2726: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2727: push(@authform_others,$authformkrb);
1.187 raeburn 2728: }
2729: if ($can_assign{'int'}) {
1.205 raeburn 2730: push(@authform_others,$authformint);
1.187 raeburn 2731: }
2732: if ($can_assign{'loc'}) {
1.205 raeburn 2733: push(@authform_others,$authformloc);
1.187 raeburn 2734: }
1.449 raeburn 2735: if ($can_assign{'lti'}) {
2736: push(@authform_others,$authformlti);
2737: }
1.187 raeburn 2738: if ($can_assign{'fsys'}) {
2739: $show_override_msg = 1;
2740: }
2741: } elsif ($currentauth=~/^localauth:/) {
2742: $authformcurrent=$authformloc;
2743: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2744: push(@authform_others,$authformkrb);
1.187 raeburn 2745: }
2746: if ($can_assign{'int'}) {
1.205 raeburn 2747: push(@authform_others,$authformint);
1.187 raeburn 2748: }
1.449 raeburn 2749: if ($can_assign{'lti'}) {
2750: push(@authform_others,$authformlti);
2751: }
1.187 raeburn 2752: if ($can_assign{'loc'}) {
2753: $show_override_msg = 1;
2754: }
1.449 raeburn 2755: } elsif ($currentauth=~/^lti:/) {
2756: $authformcurrent=$authformlti;
2757: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2758: push(@authform_others,$authformkrb);
2759: }
2760: if ($can_assign{'int'}) {
2761: push(@authform_others,$authformint);
2762: }
2763: if ($can_assign{'loc'}) {
2764: push(@authform_others,$authformloc);
2765: }
1.187 raeburn 2766: }
2767: if ($show_override_msg) {
1.205 raeburn 2768: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2769: '</td></tr>'."\n".
2770: '<tr><td> </td>'.
2771: '<td><b>'.&mt('Currently in use').'</b></td>'.
2772: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2773: &mt('will override current values').
1.205 raeburn 2774: '</span></td></tr></table>';
1.187 raeburn 2775: }
1.205 raeburn 2776: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2777: }
2778:
1.188 raeburn 2779: sub personal_data_display {
1.470 raeburn 2780: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$readonly,$rolesarray,$now,
1.456 raeburn 2781: $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
1.470 raeburn 2782: my ($output,%userenv,%canmodify,%canmodify_status,$disabled);
1.219 raeburn 2783: my @userinfo = ('firstname','middlename','lastname','generation',
2784: 'permanentemail','id');
1.252 raeburn 2785: my $rowcount = 0;
2786: my $editable = 0;
1.391 raeburn 2787: my %textboxsize = (
2788: firstname => '15',
2789: middlename => '15',
2790: lastname => '15',
2791: generation => '5',
2792: permanentemail => '25',
2793: id => '15',
2794: );
2795:
2796: my %lt=&Apache::lonlocal::texthash(
2797: 'pd' => "Personal Data",
2798: 'firstname' => "First Name",
2799: 'middlename' => "Middle Name",
2800: 'lastname' => "Last Name",
2801: 'generation' => "Generation",
2802: 'permanentemail' => "Permanent e-mail address",
2803: 'id' => "Student/Employee ID",
2804: 'lg' => "Login Data",
2805: 'inststatus' => "Affiliation",
2806: 'email' => 'E-mail address',
2807: 'valid' => 'Validation',
1.442 raeburn 2808: 'username' => 'Username',
1.391 raeburn 2809: );
2810:
2811: %canmodify_status =
1.286 raeburn 2812: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2813: ['inststatus'],$rolesarray);
1.253 raeburn 2814: if (!$newuser) {
1.188 raeburn 2815: # Get the users information
2816: %userenv = &Apache::lonnet::get('environment',
2817: ['firstname','middlename','lastname','generation',
1.286 raeburn 2818: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2819: %canmodify =
2820: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2821: \@userinfo,$rolesarray);
1.257 raeburn 2822: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2823: if ($newuser eq 'email') {
1.396 raeburn 2824: if (ref($emailusername) eq 'HASH') {
2825: if (ref($emailusername->{$usertype}) eq 'HASH') {
2826: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.442 raeburn 2827: @userinfo = ();
1.396 raeburn 2828: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2829: foreach my $field (@{$infofields}) {
2830: if ($emailusername->{$usertype}->{$field}) {
2831: push(@userinfo,$field);
2832: $canmodify{$field} = 1;
2833: unless ($textboxsize{$field}) {
2834: $textboxsize{$field} = 25;
2835: }
2836: unless ($lt{$field}) {
2837: $lt{$field} = $infotitles->{$field};
2838: }
2839: if ($emailusername->{$usertype}->{$field} eq 'required') {
2840: $lt{$field} .= '<b>*</b>';
2841: }
1.391 raeburn 2842: }
2843: }
2844: }
2845: }
2846: }
2847: } else {
2848: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2849: $inst_results,$rolesarray);
2850: }
1.470 raeburn 2851: } elsif ($readonly) {
2852: $disabled = ' disabled="disabled"';
1.188 raeburn 2853: }
1.391 raeburn 2854:
1.188 raeburn 2855: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2856: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2857: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2858: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.443 raeburn 2859: my $size = 25;
1.442 raeburn 2860: if ($condition) {
1.443 raeburn 2861: if ($condition =~ /^\@[^\@]+$/) {
2862: $size = 10;
1.442 raeburn 2863: } else {
2864: undef($condition);
2865: }
1.443 raeburn 2866: }
2867: if ($excluded) {
2868: unless ($excluded =~ /^\@[^\@]+$/) {
2869: undef($condition);
2870: }
1.442 raeburn 2871: }
1.396 raeburn 2872: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2873: 'LC_oddrow_value')."\n".
1.443 raeburn 2874: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2875: if ($condition) {
2876: $output .= $condition;
2877: } elsif ($excluded) {
2878: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2879: $excluded).'</span>';
2880: }
2881: if ($usernameset eq 'first') {
2882: $output .= '<br /><span style="font-size: smaller">';
2883: if ($condition) {
2884: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2885: $condition);
2886: } else {
2887: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2888: }
2889: $output .= '</span>';
2890: }
1.391 raeburn 2891: $rowcount ++;
2892: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.460 raeburn 2893: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="new-password" />';
2894: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="new-password" />';
1.396 raeburn 2895: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2896: 'LC_pick_box_title',
2897: 'LC_oddrow_value')."\n".
2898: $upassone."\n".
2899: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2900: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2901: 'LC_pick_box_title',
2902: 'LC_oddrow_value')."\n".
2903: $upasstwo.
2904: &Apache::lonhtmlcommon::row_closure()."\n";
1.443 raeburn 2905: if ($usernameset eq 'free') {
2906: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
1.442 raeburn 2907: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
1.455 raeburn 2908: '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
2909: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
2910: &mt('Yes').'</label>'.(' 'x2).
2911: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
2912: &mt('No').'</label></span>'."\n".
1.442 raeburn 2913: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2914: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2915: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2916: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2917: $rowcount ++;
2918: }
1.391 raeburn 2919: }
1.188 raeburn 2920: foreach my $item (@userinfo) {
2921: my $rowtitle = $lt{$item};
1.252 raeburn 2922: my $hiderow = 0;
1.188 raeburn 2923: if ($item eq 'generation') {
2924: $rowtitle = $genhelp.$rowtitle;
2925: }
1.252 raeburn 2926: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2927: if ($newuser) {
1.210 raeburn 2928: if (ref($inst_results) eq 'HASH') {
2929: if ($inst_results->{$item} ne '') {
1.252 raeburn 2930: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2931: } else {
1.252 raeburn 2932: if ($context eq 'selfcreate') {
1.391 raeburn 2933: if ($canmodify{$item}) {
1.394 raeburn 2934: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2935: $editable ++;
2936: } else {
2937: $hiderow = 1;
2938: }
1.253 raeburn 2939: } else {
1.470 raeburn 2940: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value=""'.$disabled.' />';
1.252 raeburn 2941: }
1.210 raeburn 2942: }
1.188 raeburn 2943: } else {
1.252 raeburn 2944: if ($context eq 'selfcreate') {
1.401 raeburn 2945: if ($canmodify{$item}) {
2946: if ($newuser eq 'email') {
2947: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2948: } else {
1.401 raeburn 2949: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2950: }
1.401 raeburn 2951: $editable ++;
2952: } else {
2953: $hiderow = 1;
1.252 raeburn 2954: }
1.253 raeburn 2955: } else {
1.470 raeburn 2956: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value=""'.$disabled.' />';
1.252 raeburn 2957: }
1.188 raeburn 2958: }
2959: } else {
1.219 raeburn 2960: if ($canmodify{$item}) {
1.252 raeburn 2961: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2962: if (($item eq 'id') && (!$newuser)) {
2963: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2964: }
1.188 raeburn 2965: } else {
1.252 raeburn 2966: $row .= $userenv{$item};
1.188 raeburn 2967: }
2968: }
1.252 raeburn 2969: $row .= &Apache::lonhtmlcommon::row_closure(1);
2970: if (!$hiderow) {
2971: $output .= $row;
2972: $rowcount ++;
2973: }
1.188 raeburn 2974: }
1.286 raeburn 2975: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2976: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2977: if (ref($types) eq 'ARRAY') {
2978: if (@{$types} > 0) {
2979: my ($hiderow,$shown);
2980: if ($canmodify_status{'inststatus'}) {
2981: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2982: } else {
2983: if ($userenv{'inststatus'} eq '') {
2984: $hiderow = 1;
1.334 raeburn 2985: } else {
2986: my @showitems;
2987: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2988: if (exists($usertypes->{$item})) {
2989: push(@showitems,$usertypes->{$item});
2990: } else {
2991: push(@showitems,$item);
2992: }
2993: }
2994: if (@showitems) {
2995: $shown = join(', ',@showitems);
2996: } else {
2997: $hiderow = 1;
2998: }
1.286 raeburn 2999: }
3000: }
3001: if (!$hiderow) {
1.389 bisitz 3002: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 3003: $shown.&Apache::lonhtmlcommon::row_closure(1);
3004: if ($context eq 'selfcreate') {
3005: $rowcount ++;
3006: }
3007: $output .= $row;
3008: }
3009: }
3010: }
3011: }
1.391 raeburn 3012: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
3013: if ($captchaform) {
1.410 raeburn 3014: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
3015: 'LC_pick_box_title')."\n".
1.456 raeburn 3016: $captchaform."\n".'<br /><br />'.
1.391 raeburn 3017: &Apache::lonhtmlcommon::row_closure(1);
3018: $rowcount ++;
3019: }
1.456 raeburn 3020: if ($showsubmit) {
3021: my $submit_text = &mt('Create account');
3022: $output .= &Apache::lonhtmlcommon::row_title()."\n".
3023: '<br /><input type="submit" name="createaccount" value="'.
3024: $submit_text.'" />';
3025: if ($usertype ne '') {
3026: $output .= '<input type="hidden" name="type" value="'.
3027: &HTML::Entities::encode($usertype,'\'<>"&').'" />';
3028: }
3029: $output .= &Apache::lonhtmlcommon::row_closure(1);
3030: }
1.391 raeburn 3031: }
1.188 raeburn 3032: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 3033: if (wantarray) {
1.252 raeburn 3034: if ($context eq 'selfcreate') {
3035: return($output,$rowcount,$editable);
3036: } else {
1.388 bisitz 3037: return $output;
1.252 raeburn 3038: }
1.206 raeburn 3039: } else {
3040: return $output;
3041: }
1.188 raeburn 3042: }
3043:
1.286 raeburn 3044: sub pick_inst_statuses {
3045: my ($curr,$usertypes,$types) = @_;
3046: my ($output,$rem,@currtypes);
3047: if ($curr ne '') {
3048: @currtypes = map { &unescape($_); } split(/:/,$curr);
3049: }
3050: my $numinrow = 2;
3051: if (ref($types) eq 'ARRAY') {
3052: $output = '<table>';
3053: my $lastcolspan;
3054: for (my $i=0; $i<@{$types}; $i++) {
3055: if (defined($usertypes->{$types->[$i]})) {
3056: my $rem = $i%($numinrow);
3057: if ($rem == 0) {
3058: if ($i<@{$types}-1) {
3059: if ($i > 0) {
3060: $output .= '</tr>';
3061: }
3062: $output .= '<tr>';
3063: }
3064: } elsif ($i==@{$types}-1) {
3065: my $colsleft = $numinrow - $rem;
3066: if ($colsleft > 1) {
3067: $lastcolspan = ' colspan="'.$colsleft.'"';
3068: }
3069: }
3070: my $check = ' ';
3071: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
3072: $check = ' checked="checked" ';
3073: }
3074: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
3075: '<span class="LC_nobreak"><label>'.
3076: '<input type="checkbox" name="inststatus" '.
3077: 'value="'.$types->[$i].'"'.$check.'/>'.
3078: $usertypes->{$types->[$i]}.'</label></span></td>';
3079: }
3080: }
3081: $output .= '</tr></table>';
3082: }
3083: return $output;
3084: }
3085:
1.257 raeburn 3086: sub selfcreate_canmodify {
3087: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
3088: if (ref($inst_results) eq 'HASH') {
3089: my @inststatuses = &get_inststatuses($inst_results);
3090: if (@inststatuses == 0) {
3091: @inststatuses = ('default');
3092: }
3093: $rolesarray = \@inststatuses;
3094: }
3095: my %canmodify =
3096: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
3097: $rolesarray);
3098: return %canmodify;
3099: }
3100:
1.252 raeburn 3101: sub get_inststatuses {
3102: my ($insthashref) = @_;
3103: my @inststatuses = ();
3104: if (ref($insthashref) eq 'HASH') {
3105: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
3106: @inststatuses = @{$insthashref->{'inststatus'}};
3107: }
3108: }
3109: return @inststatuses;
3110: }
3111:
1.4 www 3112: # ================================================================= Phase Three
1.42 matthew 3113: sub update_user_data {
1.451 raeburn 3114: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 3115: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
3116: $env{'form.ccdomain'});
1.27 matthew 3117: # Error messages
1.188 raeburn 3118: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 3119: my $end = '</span><br /><br />';
3120: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 3121: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 3122: &mt('Return to previous page').'</a>'.
3123: &Apache::loncommon::end_page();
3124: my $now = time;
1.40 www 3125: my $title;
1.101 albertel 3126: if (exists($env{'form.makeuser'})) {
1.40 www 3127: $title='Set Privileges for New User';
3128: } else {
3129: $title='Modify User Privileges';
3130: }
1.213 raeburn 3131: my $newuser = 0;
1.160 raeburn 3132: my ($jsback,$elements) = &crumb_utilities();
3133: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 3134: '// <![CDATA['."\n".
3135: $jsback."\n".
3136: '// ]]>'."\n".
3137: '</script>'."\n";
1.422 raeburn 3138: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 3139: push (@{$brcrum},
3140: {href => "javascript:backPage(document.userupdate)",
3141: text => $breadcrumb_text{'search'},
3142: faq => 282,
3143: bug => 'Instructor Interface',}
3144: );
3145: if ($env{'form.prevphase'} eq 'userpicked') {
3146: push(@{$brcrum},
3147: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
3148: text => $breadcrumb_text{'userpicked'},
3149: faq => 282,
3150: bug => 'Instructor Interface',});
1.233 raeburn 3151: }
1.224 raeburn 3152: my $helpitem = 'Course_Change_Privileges';
3153: if ($env{'form.action'} eq 'singlestudent') {
3154: $helpitem = 'Course_Add_Student';
1.439 raeburn 3155: } elsif ($context eq 'author') {
3156: $helpitem = 'Author_Change_Privileges';
3157: } elsif ($context eq 'domain') {
3158: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 3159: }
1.351 raeburn 3160: push(@{$brcrum},
3161: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
3162: text => $breadcrumb_text{'modify'},
3163: faq => 282,
3164: bug => 'Instructor Interface',},
3165: {href => "/adm/createuser",
3166: text => "Result",
3167: faq => 282,
3168: bug => 'Instructor Interface',
3169: help => $helpitem});
3170: my $args = {bread_crumbs => $brcrum,
3171: bread_crumbs_component => 'User Management'};
3172: if ($env{'form.popup'}) {
3173: $args->{'no_nav_bar'} = 1;
3174: }
3175: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 3176: $r->print(&update_result_form($uhome));
1.27 matthew 3177: # Check Inputs
1.101 albertel 3178: if (! $env{'form.ccuname'} ) {
1.193 raeburn 3179: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 3180: return;
3181: }
1.138 albertel 3182: if ( $env{'form.ccuname'} ne
3183: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 3184: $r->print($error.&mt('Invalid login name.').' '.
3185: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 3186: $end.$rtnlink);
1.27 matthew 3187: return;
3188: }
1.101 albertel 3189: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 3190: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 3191: return;
3192: }
1.138 albertel 3193: if ( $env{'form.ccdomain'} ne
3194: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 3195: $r->print($error.&mt('Invalid domain name.').' '.
3196: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 3197: $end.$rtnlink);
1.27 matthew 3198: return;
3199: }
1.219 raeburn 3200: if ($uhome eq 'no_host') {
3201: $newuser = 1;
3202: }
1.101 albertel 3203: if (! exists($env{'form.makeuser'})) {
1.29 matthew 3204: # Modifying an existing user, so check the validity of the name
3205: if ($uhome eq 'no_host') {
1.389 bisitz 3206: $r->print(
3207: $error
3208: .'<p class="LC_error">'
3209: .&mt('Unable to determine home server for [_1] in domain [_2].',
3210: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
3211: .'</p>');
1.29 matthew 3212: return;
3213: }
3214: }
1.27 matthew 3215: # Determine authentication method and password for the user being modified
3216: my $amode='';
3217: my $genpwd='';
1.101 albertel 3218: if ($env{'form.login'} eq 'krb') {
1.41 albertel 3219: $amode='krb';
1.101 albertel 3220: $amode.=$env{'form.krbver'};
3221: $genpwd=$env{'form.krbarg'};
3222: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 3223: $amode='internal';
1.101 albertel 3224: $genpwd=$env{'form.intarg'};
3225: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 3226: $amode='unix';
1.101 albertel 3227: $genpwd=$env{'form.fsysarg'};
3228: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 3229: $amode='localauth';
1.101 albertel 3230: $genpwd=$env{'form.locarg'};
1.27 matthew 3231: $genpwd=" " if (!$genpwd);
1.449 raeburn 3232: } elsif ($env{'form.login'} eq 'lti') {
3233: $amode='lti';
3234: $genpwd=" ";
1.101 albertel 3235: } elsif (($env{'form.login'} eq 'nochange') ||
3236: ($env{'form.login'} eq '' )) {
1.34 matthew 3237: # There is no need to tell the user we did not change what they
3238: # did not ask us to change.
1.35 matthew 3239: # If they are creating a new user but have not specified login
3240: # information this will be caught below.
1.30 matthew 3241: } else {
1.367 golterma 3242: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
3243: return;
1.27 matthew 3244: }
1.164 albertel 3245:
1.188 raeburn 3246: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 3247: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
3248: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
3249: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 3250:
1.193 raeburn 3251: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 3252: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.470 raeburn 3253: my @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.449 raeburn 3254: my @requestcourses = ('official','unofficial','community','textbook','placement','lti');
1.362 raeburn 3255: my @requestauthor = ('requestauthor');
1.477 raeburn 3256: my @authordefaults = ('webdav','editors','archive');
1.286 raeburn 3257: my ($othertitle,$usertypes,$types) =
3258: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 3259: my %canmodify_status =
3260: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
3261: ['inststatus']);
1.101 albertel 3262: if ($env{'form.makeuser'}) {
1.164 albertel 3263: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 3264: # Check for the authentication mode and password
3265: if (! $amode || ! $genpwd) {
1.193 raeburn 3266: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 3267: return;
1.18 albertel 3268: }
1.29 matthew 3269: # Determine desired host
1.101 albertel 3270: my $desiredhost = $env{'form.hserver'};
1.29 matthew 3271: if (lc($desiredhost) eq 'default') {
3272: $desiredhost = undef;
3273: } else {
1.147 albertel 3274: my %home_servers =
3275: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 3276: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 3277: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
3278: return;
3279: }
3280: }
3281: # Check ID format
3282: my %checkhash;
3283: my %checks = ('id' => 1);
3284: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 3285: 'newuser' => $newuser,
1.196 raeburn 3286: 'id' => $env{'form.cid'},
1.193 raeburn 3287: );
1.196 raeburn 3288: if ($env{'form.cid'} ne '') {
3289: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
3290: \%rulematch,\%inst_results,\%curr_rules);
3291: if (ref($alerts{'id'}) eq 'HASH') {
3292: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
3293: my $domdesc =
3294: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
3295: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
3296: my $userchkmsg;
3297: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
3298: $userchkmsg =
3299: &Apache::loncommon::instrule_disallow_msg('id',
3300: $domdesc,1).
3301: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
3302: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
3303: }
3304: $r->print($error.&mt('Invalid ID format').$end.
3305: $userchkmsg.$rtnlink);
3306: return;
3307: }
3308: }
1.29 matthew 3309: }
3310: }
1.367 golterma 3311: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 3312: # Call modifyuser
3313: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 3314: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 3315: $amode,$genpwd,$env{'form.cfirstname'},
3316: $env{'form.cmiddlename'},$env{'form.clastname'},
3317: $env{'form.cgeneration'},undef,$desiredhost,
3318: $env{'form.cpermanentemail'});
1.77 www 3319: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 3320: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 3321: $env{'form.ccdomain'});
1.334 raeburn 3322: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 3323: if ($uhome ne 'no_host') {
1.334 raeburn 3324: if ($context eq 'domain') {
1.378 raeburn 3325: foreach my $name ('portfolio','author') {
3326: if ($env{'form.custom_'.$name.'quota'} == 1) {
3327: if ($env{'form.'.$name.'quota'} eq '') {
3328: $newcustom{$name.'quota'} = 0;
3329: } else {
3330: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
3331: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
3332: }
3333: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
3334: $changed{$name.'quota'} = 1;
3335: }
1.334 raeburn 3336: }
3337: }
3338: foreach my $item (@usertools) {
3339: if ($env{'form.custom'.$item} == 1) {
3340: $newcustom{$item} = $env{'form.tools_'.$item};
3341: $changed{$item} = &tool_admin($item,$newcustom{$item},
3342: \%changeHash,'tools');
3343: }
1.267 raeburn 3344: }
1.334 raeburn 3345: foreach my $item (@requestcourses) {
1.341 raeburn 3346: if ($env{'form.custom'.$item} == 1) {
3347: $newcustom{$item} = $env{'form.crsreq_'.$item};
3348: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
3349: $newcustom{$item} .= '=';
1.383 raeburn 3350: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
3351: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 3352: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
3353: }
1.334 raeburn 3354: }
1.341 raeburn 3355: $changed{$item} = &tool_admin($item,$newcustom{$item},
3356: \%changeHash,'requestcourses');
1.334 raeburn 3357: }
1.275 raeburn 3358: }
1.362 raeburn 3359: if ($env{'form.customrequestauthor'} == 1) {
3360: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
3361: $changed{'requestauthor'} = &tool_admin('requestauthor',
3362: $newcustom{'requestauthor'},
3363: \%changeHash,'requestauthor');
3364: }
1.470 raeburn 3365: if ($env{'form.customeditors'} == 1) {
3366: my @editors;
3367: my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
3368: if (@posseditors) {
3369: foreach my $editor (@posseditors) {
3370: if (grep(/^\Q$editor\E$/,@posseditors)) {
3371: unless (grep(/^\Q$editor\E$/,@editors)) {
3372: push(@editors,$editor);
3373: }
3374: }
3375: }
3376: }
3377: if (@editors) {
3378: @editors = sort(@editors);
3379: $changed{'editors'} = &tool_admin('editors',join(',',@editors),
3380: \%changeHash,'authordefaults');
3381: }
3382: }
3383: if ($env{'form.customwebdav'} == 1) {
3384: $newcustom{'webdav'} = $env{'form.authordefaults_webdav'};
3385: $changed{'webdav'} = &tool_admin('webdav',$newcustom{'webdav'},
1.479 raeburn 3386: \%changeHash,'authordefaults');
1.470 raeburn 3387: }
1.480 raeburn 3388: if ($env{'form.customarchive'} == 1) {
1.477 raeburn 3389: $newcustom{'archive'} = $env{'form.authordefaults_archive'};
3390: $changed{'archive'} = &tool_admin('archive',$newcustom{'archive'},
1.479 raeburn 3391: \%changeHash,'authordefaults');
1.477 raeburn 3392:
3393: }
1.275 raeburn 3394: }
1.334 raeburn 3395: if ($canmodify_status{'inststatus'}) {
3396: if (exists($env{'form.inststatus'})) {
3397: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3398: if (@inststatuses > 0) {
3399: $changeHash{'inststatus'} = join(',',@inststatuses);
3400: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 3401: }
3402: }
1.232 raeburn 3403: }
1.334 raeburn 3404: if (keys(%changed)) {
3405: foreach my $item (@userinfo) {
3406: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 3407: }
1.267 raeburn 3408: my $chgresult =
3409: &Apache::lonnet::put('environment',\%changeHash,
3410: $env{'form.ccdomain'},$env{'form.ccuname'});
1.470 raeburn 3411: }
1.232 raeburn 3412: }
1.454 raeburn 3413: $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
1.219 raeburn 3414: &Apache::lonnet::hostname($uhome));
1.101 albertel 3415: } elsif (($env{'form.login'} ne 'nochange') &&
3416: ($env{'form.login'} ne '' )) {
1.27 matthew 3417: # Modify user privileges
3418: if (! $amode || ! $genpwd) {
1.193 raeburn 3419: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 3420: return;
1.20 harris41 3421: }
1.395 bisitz 3422: # Only allow authentication modification if the person has authority
1.101 albertel 3423: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 3424: $r->print('Modifying authentication: '.
1.31 matthew 3425: &Apache::lonnet::modifyuserauth(
1.101 albertel 3426: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 3427: $amode,$genpwd));
1.454 raeburn 3428: $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
1.101 albertel 3429: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 3430: } else {
1.27 matthew 3431: # Okay, this is a non-fatal error.
1.452 raeburn 3432: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 3433: }
1.451 raeburn 3434: } elsif (($env{'form.intarg'} ne '') &&
3435: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
3436: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3437: $r->print('Modifying authentication: '.
3438: &Apache::lonnet::modifyuserauth(
3439: $env{'form.ccdomain'},$env{'form.ccuname'},
3440: 'internal',$env{'form.intarg'}));
1.28 matthew 3441: }
1.344 bisitz 3442: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3443: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3444: ##
1.375 raeburn 3445: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3446: if ($context eq 'course') {
1.375 raeburn 3447: ($cnum,$cdom) =
3448: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3449: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3450: if ($showcredits) {
3451: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3452: }
1.213 raeburn 3453: }
1.101 albertel 3454: if (! $env{'form.makeuser'} ) {
1.28 matthew 3455: # Check for need to change
3456: my %userenv = &Apache::lonnet::get
1.134 raeburn 3457: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3458: 'id','permanentemail','portfolioquota','authorquota','inststatus',
1.459 raeburn 3459: 'tools.aboutme','tools.blog','tools.webdav',
1.470 raeburn 3460: 'tools.portfolio','tools.timezone','tools.portaccess',
1.477 raeburn 3461: 'authormanagers','authoreditors','authorarchive','requestauthor',
1.361 raeburn 3462: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3463: 'requestcourses.community','requestcourses.textbook',
1.470 raeburn 3464: 'requestcourses.placement','requestcourses.lti',
1.384 raeburn 3465: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3466: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.471 raeburn 3467: 'reqcrsotherdom.placement','domcoord.author'],
1.160 raeburn 3468: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3469: my ($tmp) = keys(%userenv);
3470: if ($tmp =~ /^(con_lost|error)/i) {
3471: %userenv = ();
3472: }
1.471 raeburn 3473: unless (($userenv{'domcoord.author'} eq 'blocked') &&
3474: (($env{'user.name'} ne $env{'form.ccuname'}) ||
3475: ($env{'user.domain'} ne $env{'form.ccdomain'}))) {
3476: push(@authordefaults,'managers');
3477: }
1.206 raeburn 3478: my $no_forceid_alert;
3479: # Check to see if user information can be changed
3480: my %domconfig =
3481: &Apache::lonnet::get_dom('configuration',['usermodification'],
3482: $env{'form.ccdomain'});
1.213 raeburn 3483: my @statuses = ('active','future');
3484: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3485: my ($auname,$audom);
1.220 raeburn 3486: if ($context eq 'author') {
1.206 raeburn 3487: $auname = $env{'user.name'};
3488: $audom = $env{'user.domain'};
3489: }
3490: foreach my $item (keys(%roles)) {
1.220 raeburn 3491: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3492: if ($context eq 'course') {
3493: if ($cnum ne '' && $cdom ne '') {
3494: if ($rolenum eq $cnum && $roledom eq $cdom) {
3495: if (!grep(/^\Q$role\E$/,@userroles)) {
3496: push(@userroles,$role);
3497: }
3498: }
3499: }
3500: } elsif ($context eq 'author') {
3501: if ($rolenum eq $auname && $roledom eq $audom) {
1.461 raeburn 3502: if (!grep(/^\Q$role\E$/,@userroles)) {
1.206 raeburn 3503: push(@userroles,$role);
3504: }
3505: }
3506: }
3507: }
1.220 raeburn 3508: if ($env{'form.action'} eq 'singlestudent') {
3509: if (!grep(/^st$/,@userroles)) {
3510: push(@userroles,'st');
3511: }
3512: } else {
3513: # Check for course or co-author roles being activated or re-enabled
3514: if ($context eq 'author' || $context eq 'course') {
3515: foreach my $key (keys(%env)) {
3516: if ($context eq 'author') {
3517: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3518: if (!grep(/^\Q$1\E$/,@userroles)) {
3519: push(@userroles,$1);
3520: }
3521: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3522: if (!grep(/^\Q$1\E$/,@userroles)) {
3523: push(@userroles,$1);
3524: }
1.206 raeburn 3525: }
1.220 raeburn 3526: } elsif ($context eq 'course') {
3527: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3528: if (!grep(/^\Q$1\E$/,@userroles)) {
3529: push(@userroles,$1);
3530: }
3531: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3532: if (!grep(/^\Q$1\E$/,@userroles)) {
3533: push(@userroles,$1);
3534: }
1.206 raeburn 3535: }
3536: }
3537: }
3538: }
3539: }
3540: #Check to see if we can change personal data for the user
3541: my (@mod_disallowed,@longroles);
3542: foreach my $role (@userroles) {
3543: if ($role eq 'cr') {
3544: push(@longroles,'Custom');
3545: } else {
1.318 raeburn 3546: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3547: }
3548: }
1.219 raeburn 3549: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3550: foreach my $item (@userinfo) {
1.28 matthew 3551: # Strip leading and trailing whitespace
1.203 raeburn 3552: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3553: if (!$canmodify{$item}) {
1.207 raeburn 3554: if (defined($env{'form.c'.$item})) {
3555: if ($env{'form.c'.$item} ne $userenv{$item}) {
3556: push(@mod_disallowed,$item);
3557: }
1.206 raeburn 3558: }
3559: $env{'form.c'.$item} = $userenv{$item};
3560: }
1.28 matthew 3561: }
1.259 bisitz 3562: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3563: my $forceid = $env{'form.forceid'};
3564: my $recurseid = $env{'form.recurseid'};
3565: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3566: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3567: $env{'form.ccuname'});
3568: if (($uidhash{$env{'form.ccuname'}}) &&
3569: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3570: (!$forceid)) {
3571: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3572: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3573: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3574: .'<br />'
3575: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3576: .'<br />'."\n";
1.203 raeburn 3577: }
3578: }
3579: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3580: my $checkhash;
3581: my $checks = { 'id' => 1 };
3582: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3583: { 'newuser' => $newuser,
3584: 'id' => $env{'form.cid'},
3585: };
3586: &Apache::loncommon::user_rule_check($checkhash,$checks,
3587: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3588: if (ref($alerts{'id'}) eq 'HASH') {
3589: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3590: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3591: }
3592: }
3593: }
1.378 raeburn 3594: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3595: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3596: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3597: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3598: @disporder = ('inststatus');
3599: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.470 raeburn 3600: push(@disporder,('requestcourses','requestauthor','authordefaults'));
1.334 raeburn 3601: } else {
3602: push(@disporder,'reqcrsotherdom');
3603: }
3604: push(@disporder,('quota','tools'));
1.338 raeburn 3605: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3606: foreach my $name ('portfolio','author') {
3607: ($olddefquota{$name},$oldsettingstatus{$name}) =
3608: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3609: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3610: }
1.334 raeburn 3611: my %canshow;
1.220 raeburn 3612: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3613: $canshow{'quota'} = 1;
1.220 raeburn 3614: }
1.267 raeburn 3615: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3616: $canshow{'tools'} = 1;
1.267 raeburn 3617: }
1.275 raeburn 3618: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3619: $canshow{'requestcourses'} = 1;
1.300 raeburn 3620: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3621: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3622: }
1.286 raeburn 3623: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3624: $canshow{'inststatus'} = 1;
1.286 raeburn 3625: }
1.362 raeburn 3626: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3627: $canshow{'requestauthor'} = 1;
1.470 raeburn 3628: $canshow{'authordefaults'} = 1;
1.362 raeburn 3629: }
1.267 raeburn 3630: my (%changeHash,%changed);
1.286 raeburn 3631: if ($oldinststatus eq '') {
1.334 raeburn 3632: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3633: } else {
3634: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3635: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3636: } else {
1.334 raeburn 3637: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3638: }
3639: }
3640: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3641: if ($canmodify_status{'inststatus'}) {
3642: $canshow{'inststatus'} = 1;
1.286 raeburn 3643: if (exists($env{'form.inststatus'})) {
3644: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3645: if (@inststatuses > 0) {
3646: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3647: $changeHash{'inststatus'} = $newinststatus;
3648: if ($newinststatus ne $oldinststatus) {
3649: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3650: foreach my $name ('portfolio','author') {
3651: ($newdefquota{$name},$newsettingstatus{$name}) =
3652: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3653: }
1.286 raeburn 3654: }
3655: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3656: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3657: } else {
1.337 raeburn 3658: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3659: }
1.334 raeburn 3660: }
3661: } else {
3662: $newinststatus = '';
3663: $changeHash{'inststatus'} = $newinststatus;
3664: $newsettings{'inststatus'} = $othertitle;
3665: if ($newinststatus ne $oldinststatus) {
3666: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3667: foreach my $name ('portfolio','author') {
3668: ($newdefquota{$name},$newsettingstatus{$name}) =
3669: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3670: }
1.286 raeburn 3671: }
3672: }
1.334 raeburn 3673: } elsif ($context ne 'selfcreate') {
3674: $canshow{'inststatus'} = 1;
1.337 raeburn 3675: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3676: }
1.378 raeburn 3677: foreach my $name ('portfolio','author') {
3678: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3679: }
1.334 raeburn 3680: if ($context eq 'domain') {
1.378 raeburn 3681: foreach my $name ('portfolio','author') {
3682: if ($userenv{$name.'quota'} ne '') {
3683: $oldquota{$name} = $userenv{$name.'quota'};
3684: if ($env{'form.custom_'.$name.'quota'} == 1) {
3685: if ($env{'form.'.$name.'quota'} eq '') {
3686: $newquota{$name} = 0;
3687: } else {
3688: $newquota{$name} = $env{'form.'.$name.'quota'};
3689: $newquota{$name} =~ s/[^\d\.]//g;
3690: }
3691: if ($newquota{$name} != $oldquota{$name}) {
3692: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3693: $changed{$name.'quota'} = 1;
3694: }
3695: }
1.334 raeburn 3696: } else {
1.378 raeburn 3697: if ("a_admin('',\%changeHash,$name)) {
3698: $changed{$name.'quota'} = 1;
3699: $newquota{$name} = $newdefquota{$name};
3700: $newisdefault{$name} = 1;
3701: }
1.334 raeburn 3702: }
1.149 raeburn 3703: } else {
1.378 raeburn 3704: $oldisdefault{$name} = 1;
3705: $oldquota{$name} = $olddefquota{$name};
3706: if ($env{'form.custom_'.$name.'quota'} == 1) {
3707: if ($env{'form.'.$name.'quota'} eq '') {
3708: $newquota{$name} = 0;
3709: } else {
3710: $newquota{$name} = $env{'form.'.$name.'quota'};
3711: $newquota{$name} =~ s/[^\d\.]//g;
3712: }
3713: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3714: $changed{$name.'quota'} = 1;
3715: }
1.334 raeburn 3716: } else {
1.378 raeburn 3717: $newquota{$name} = $newdefquota{$name};
3718: $newisdefault{$name} = 1;
1.334 raeburn 3719: }
1.378 raeburn 3720: }
3721: if ($oldisdefault{$name}) {
3722: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3723: } else {
3724: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3725: }
3726: if ($newisdefault{$name}) {
3727: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3728: } else {
3729: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3730: }
3731: }
1.334 raeburn 3732: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3733: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3734: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3735: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3736: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.470 raeburn 3737: my ($isadv,$isauthor) =
3738: &Apache::lonnet::is_advanced_user($env{'form.ccdomain'},$env{'form.ccuname'});
3739: unless ($isauthor) {
3740: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3741: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3742: }
3743: &tool_changes('authordefaults',\@authordefaults,\%oldsettings,\%oldsettingstext,
3744: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3745: } else {
1.334 raeburn 3746: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3747: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3748: }
3749: }
1.334 raeburn 3750: foreach my $item (@userinfo) {
3751: if ($env{'form.c'.$item} ne $userenv{$item}) {
3752: $namechanged{$item} = 1;
3753: }
1.204 raeburn 3754: }
1.378 raeburn 3755: foreach my $name ('portfolio','author') {
1.390 bisitz 3756: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3757: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3758: }
1.334 raeburn 3759: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3760: my ($chgresult,$namechgresult);
3761: if (keys(%changed) > 0) {
1.470 raeburn 3762: $chgresult =
1.204 raeburn 3763: &Apache::lonnet::put('environment',\%changeHash,
3764: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3765: if ($chgresult eq 'ok') {
1.470 raeburn 3766: my ($ca_mgr_del,%ca_mgr_add);
3767: if ($changed{'managers'}) {
3768: my (@adds,@dels);
3769: if ($changeHash{'authormanagers'} eq '') {
3770: @dels = split(/,/,$userenv{'authormanagers'});
3771: } elsif ($userenv{'authormanagers'} eq '') {
3772: @adds = split(/,/,$changeHash{'authormanagers'});
3773: } else {
3774: my @old = split(/,/,$userenv{'authormanagers'});
3775: my @new = split(/,/,$changeHash{'authormanagers'});
3776: my @diffs = &Apache::loncommon::compare_arrays(\@old,\@new);
3777: if (@diffs) {
3778: foreach my $user (@diffs) {
3779: if (grep(/^\Q$user\E$/,@old)) {
3780: push(@dels,$user);
3781: } elsif (grep(/^\Q$user\E$/,@new)) {
3782: push(@adds,$user);
3783: }
3784: }
3785: }
3786: }
3787: my $key = "internal.manager./$env{'form.ccdomain'}/$env{'form.ccuname'}";
3788: if (@dels) {
3789: foreach my $user (@dels) {
3790: if ($user =~ /^($match_username):($match_domain)$/) {
3791: &Apache::lonnet::del('environment',[$key],$2,$1);
3792: }
3793: }
3794: my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
3795: if (grep(/^\Q$curruser\E$/,@dels)) {
3796: $ca_mgr_del = $key;
3797: }
3798: }
3799: if (@adds) {
3800: foreach my $user (@adds) {
3801: if ($user =~ /^($match_username):($match_domain)$/) {
3802: &Apache::lonnet::put('environment',{$key => 1},$2,$1);
3803: }
3804: }
3805: my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
3806: if (grep(/^\Q$curruser\E$/,@adds)) {
3807: $ca_mgr_add{$key} = 1;
3808: }
3809: }
3810: }
1.267 raeburn 3811: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3812: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.474 raeburn 3813: my (%newenvhash,$got_domdefs,%domdefaults,$got_userenv,
3814: %userenv);
3815: my @fromenv = keys(%changed);
3816: push(@fromenv,'inststatus');
1.270 raeburn 3817: foreach my $key (keys(%changed)) {
1.411 raeburn 3818: if (($key eq 'official') || ($key eq 'unofficial') ||
3819: ($key eq 'community') || ($key eq 'textbook') ||
1.449 raeburn 3820: ($key eq 'placement') || ($key eq 'lti')) {
1.279 raeburn 3821: $newenvhash{'environment.requestcourses.'.$key} =
3822: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3823: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3824: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3825: } else {
1.474 raeburn 3826: unless ($got_domdefs) {
3827: %domdefaults =
3828: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3829: $got_domdefs = 1;
3830: }
3831: unless ($got_userenv) {
3832: %userenv =
3833: &Apache::lonnet::userenvironment($env{'user.domain'},
3834: $env{'user.name'},@fromenv);
3835: $got_userenv = 1;
3836: }
1.279 raeburn 3837: $newenvhash{'environment.canrequest.'.$key} =
3838: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.474 raeburn 3839: $key,'reload','requestcourses',\%userenv,\%domdefaults);
1.279 raeburn 3840: }
1.362 raeburn 3841: } elsif ($key eq 'requestauthor') {
3842: $newenvhash{'environment.'.$key} = $changeHash{$key};
3843: if ($changeHash{$key}) {
3844: $newenvhash{'environment.canrequest.author'} = 1;
3845: } else {
1.474 raeburn 3846: unless ($got_domdefs) {
3847: %domdefaults =
3848: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3849: $got_domdefs = 1;
3850: }
3851: unless ($got_userenv) {
3852: %userenv =
3853: &Apache::lonnet::userenvironment($env{'user.domain'},
3854: $env{'user.name'},@fromenv);
3855: $got_userenv = 1;
3856: }
1.362 raeburn 3857: $newenvhash{'environment.canrequest.author'} =
3858: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.474 raeburn 3859: $key,'reload','requestauthor',\%userenv,\%domdefaults);
1.362 raeburn 3860: }
1.470 raeburn 3861: } elsif ($key eq 'editors') {
3862: $newenvhash{'environment.author'.$key} = $changeHash{'author'.$key};
1.474 raeburn 3863: if ($env{'form.customeditors'}) {
3864: $newenvhash{'environment.editors'} = $changeHash{'author'.$key};
3865: } else {
3866: unless ($got_domdefs) {
3867: %domdefaults =
3868: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3869: $got_domdefs = 1;
3870: }
3871: if ($domdefaults{'editors'} ne '') {
3872: $newenvhash{'environment.editors'} = $domdefaults{'editors'};
1.470 raeburn 3873: } else {
1.474 raeburn 3874: $newenvhash{'environment.editors'} = 'edit,xml';
1.470 raeburn 3875: }
3876: }
1.480 raeburn 3877: } elsif ($key eq 'archive') {
3878: $newenvhash{'environment.author.'.$key} =
3879: $changeHash{'author.'.$key};
3880: if ($changeHash{'author.'.$key} ne '') {
3881: $newenvhash{'environment.canarchive'} =
3882: $changeHash{'author.'.$key};
3883: } else {
3884: unless ($got_domdefs) {
3885: %domdefaults =
3886: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3887: $got_domdefs = 1;
3888: }
3889: $newenvhash{'environment.canarchive'} =
3890: $domdefaults{'archive'};
3891: }
1.275 raeburn 3892: } elsif ($key ne 'quota') {
1.270 raeburn 3893: $newenvhash{'environment.tools.'.$key} =
3894: $changeHash{'tools.'.$key};
1.279 raeburn 3895: if ($changeHash{'tools.'.$key} ne '') {
3896: $newenvhash{'environment.availabletools.'.$key} =
3897: $changeHash{'tools.'.$key};
3898: } else {
1.474 raeburn 3899: unless ($got_domdefs) {
3900: %domdefaults =
3901: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3902: $got_domdefs = 1;
3903: }
3904: unless ($got_userenv) {
3905: %userenv =
3906: &Apache::lonnet::userenvironment($env{'user.domain'},
3907: $env{'user.name'},@fromenv);
3908: $got_userenv = 1;
3909: }
1.279 raeburn 3910: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3911: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.474 raeburn 3912: $key,'reload','tools',\%userenv,\%domdefaults);
1.279 raeburn 3913: }
1.270 raeburn 3914: }
3915: }
1.271 raeburn 3916: if (keys(%newenvhash)) {
3917: &Apache::lonnet::appenv(\%newenvhash);
3918: }
1.470 raeburn 3919: } else {
3920: if ($ca_mgr_del) {
3921: &Apache::lonnet::delenv($ca_mgr_del);
3922: }
3923: if (keys(%ca_mgr_add)) {
3924: &Apache::lonnet::appenv(\%ca_mgr_add);
3925: }
1.267 raeburn 3926: }
1.463 raeburn 3927: if ($changed{'aboutme'}) {
3928: &Apache::loncommon::devalidate_aboutme_cache($env{'form.ccuname'},
3929: $env{'form.ccdomain'});
3930: }
1.267 raeburn 3931: }
1.204 raeburn 3932: }
1.334 raeburn 3933: if (keys(%namechanged) > 0) {
1.337 raeburn 3934: foreach my $field (@userinfo) {
3935: $changeHash{$field} = $env{'form.c'.$field};
3936: }
3937: # Make the change
1.204 raeburn 3938: $namechgresult =
3939: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3940: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3941: $changeHash{'firstname'},$changeHash{'middlename'},
3942: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3943: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3944: %userupdate = (
3945: lastname => $env{'form.clastname'},
3946: middlename => $env{'form.cmiddlename'},
3947: firstname => $env{'form.cfirstname'},
3948: generation => $env{'form.cgeneration'},
3949: id => $env{'form.cid'},
3950: );
1.204 raeburn 3951: }
1.334 raeburn 3952: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3953: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3954: # Tell the user we changed the name
1.334 raeburn 3955: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3956: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3957: \%oldsettings, \%oldsettingstext,\%newsettings,
3958: \%newsettingstext);
1.203 raeburn 3959: if ($env{'form.cid'} ne $userenv{'id'}) {
3960: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3961: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3962: if (($recurseid) &&
3963: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3964: my $idresult =
3965: &Apache::lonuserutils::propagate_id_change(
3966: $env{'form.ccuname'},$env{'form.ccdomain'},
3967: \%userupdate);
3968: $r->print('<br />'.$idresult.'<br />');
3969: }
1.196 raeburn 3970: }
1.149 raeburn 3971: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3972: ($env{'form.ccuname'} eq $env{'user.name'})) {
3973: my %newenvhash;
3974: foreach my $key (keys(%changeHash)) {
3975: $newenvhash{'environment.'.$key} = $changeHash{$key};
3976: }
1.238 raeburn 3977: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3978: }
1.28 matthew 3979: } else { # error occurred
1.389 bisitz 3980: $r->print(
3981: '<p class="LC_error">'
3982: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3983: '"'.$env{'form.ccuname'}.'"',
3984: '"'.$env{'form.ccdomain'}.'"')
3985: .'</p>');
1.28 matthew 3986: }
1.334 raeburn 3987: } else { # End of if ($env ... ) logic
1.275 raeburn 3988: # They did not want to change the users name, quota, tool availability,
3989: # or ability to request creation of courses,
1.267 raeburn 3990: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3991: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3992: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3993: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3994: }
1.206 raeburn 3995: if (@mod_disallowed) {
3996: my ($rolestr,$contextname);
3997: if (@longroles > 0) {
3998: $rolestr = join(', ',@longroles);
3999: } else {
4000: $rolestr = &mt('No roles');
4001: }
4002: if ($context eq 'course') {
1.399 bisitz 4003: $contextname = 'course';
1.206 raeburn 4004: } elsif ($context eq 'author') {
1.399 bisitz 4005: $contextname = 'co-author';
1.206 raeburn 4006: }
4007: $r->print(&mt('The following fields were not updated: ').'<ul>');
4008: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4009: foreach my $field (@mod_disallowed) {
4010: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
4011: }
1.207 raeburn 4012: $r->print('</ul>');
4013: if (@mod_disallowed == 1) {
1.399 bisitz 4014: $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future $contextname roles:"));
1.207 raeburn 4015: } else {
1.399 bisitz 4016: $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future $contextname roles:"));
1.207 raeburn 4017: }
1.292 bisitz 4018: my $helplink = 'javascript:helpMenu('."'display'".')';
4019: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
4020: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
4021: ,'<a href="'.$helplink.'">','</a>')
4022: .'<br />');
1.206 raeburn 4023: }
1.259 bisitz 4024: $r->print('<span class="LC_warning">'
4025: .$no_forceid_alert
4026: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
4027: .'</span>');
1.4 www 4028: }
1.367 golterma 4029: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 4030: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 4031: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
4032: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 4033: my $linktext = ($crstype eq 'Community' ?
4034: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
4035: $r->print(
4036: &Apache::lonhtmlcommon::actionbox([
4037: '<a href="javascript:backPage(document.userupdate)">'
4038: .($crstype eq 'Community' ?
4039: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
4040: .'</a>']));
1.220 raeburn 4041: } else {
1.375 raeburn 4042: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 4043: if (keys(%namechanged) > 0) {
1.220 raeburn 4044: if ($context eq 'course') {
4045: if (@userroles > 0) {
1.225 raeburn 4046: if ((@rolechanges == 0) ||
4047: (!(grep(/^st$/,@rolechanges)))) {
4048: if (grep(/^st$/,@userroles)) {
4049: my $classlistupdated =
4050: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 4051: $cnum,$env{'form.ccdomain'},
4052: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 4053: }
1.220 raeburn 4054: }
4055: }
4056: }
4057: }
1.226 raeburn 4058: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 4059: $env{'form.ccdomain'});
4060: if ($env{'form.popup'}) {
4061: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
4062: } else {
1.367 golterma 4063: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
4064: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
4065: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 4066: }
1.220 raeburn 4067: }
4068: }
4069:
1.334 raeburn 4070: sub display_userinfo {
1.362 raeburn 4071: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
4072: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 4073: $newsetting,$newsettingtext) = @_;
4074: return unless (ref($order) eq 'ARRAY' &&
4075: ref($canshow) eq 'HASH' &&
4076: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 4077: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 4078: ref($usertools) eq 'ARRAY' &&
4079: ref($userenv) eq 'HASH' &&
4080: ref($changedhash) eq 'HASH' &&
4081: ref($oldsetting) eq 'HASH' &&
4082: ref($oldsettingtext) eq 'HASH' &&
4083: ref($newsetting) eq 'HASH' &&
4084: ref($newsettingtext) eq 'HASH');
4085: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 4086: 'ui' => 'User Information',
1.334 raeburn 4087: 'uic' => 'User Information Changed',
4088: 'firstname' => 'First Name',
4089: 'middlename' => 'Middle Name',
4090: 'lastname' => 'Last Name',
4091: 'generation' => 'Generation',
4092: 'id' => 'Student/Employee ID',
4093: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 4094: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 4095: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 4096: 'blog' => 'Blog Availability',
1.361 raeburn 4097: 'webdav' => 'WebDAV Availability',
1.334 raeburn 4098: 'aboutme' => 'Personal Information Page Availability',
4099: 'portfolio' => 'Portfolio Availability',
1.470 raeburn 4100: 'portaccess' => 'Portfolio Shareable',
1.459 raeburn 4101: 'timezone' => 'Can set own Time Zone',
1.334 raeburn 4102: 'official' => 'Can Request Official Courses',
4103: 'unofficial' => 'Can Request Unofficial Courses',
4104: 'community' => 'Can Request Communities',
1.384 raeburn 4105: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 4106: 'placement' => 'Can Request Placement Tests',
1.449 raeburn 4107: 'lti' => 'Can Request LTI Courses',
1.362 raeburn 4108: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 4109: 'inststatus' => "Affiliation",
4110: 'prvs' => 'Previous Value:',
1.470 raeburn 4111: 'chto' => 'Changed To:',
4112: 'editors' => "Available Editors in Authoring Space",
1.473 raeburn 4113: 'managers' => "Co-authors who can add/revoke roles",
1.477 raeburn 4114: 'archive' => "Managers can download tar.gz file of Authoring Space",
1.470 raeburn 4115: 'edit' => 'Standard editor (Edit)',
4116: 'xml' => 'Text editor (EditXML)',
4117: 'daxe' => 'Daxe editor (Daxe)',
1.334 raeburn 4118: );
4119: if ($changed) {
1.372 raeburn 4120: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 4121: &Apache::loncommon::start_data_table().
4122: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 4123: $r->print("<th> </th>\n");
1.367 golterma 4124: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
4125: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
4126: $r->print(&Apache::loncommon::end_data_table_header_row());
4127: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
4128:
1.334 raeburn 4129: foreach my $item (@userinfo) {
4130: my $value = $env{'form.c'.$item};
1.367 golterma 4131: #show changes only:
1.383 raeburn 4132: unless ($value eq $userenv->{$item}){
1.367 golterma 4133: $r->print(&Apache::loncommon::start_data_table_row());
4134: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 4135: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 4136: $r->print("<td>$value </td>\n");
4137: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 4138: }
4139: }
4140: foreach my $entry (@{$order}) {
1.383 raeburn 4141: if ($canshow->{$entry}) {
1.470 raeburn 4142: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') ||
4143: ($entry eq 'requestauthor') || ($entry eq 'authordefaults')) {
1.383 raeburn 4144: my @items;
4145: if ($entry eq 'requestauthor') {
4146: @items = ($entry);
1.470 raeburn 4147: } elsif ($entry eq 'authordefaults') {
1.477 raeburn 4148: @items = ('webdav','managers','editors','archive');
1.383 raeburn 4149: } else {
4150: @items = @{$requestcourses};
1.384 raeburn 4151: }
1.383 raeburn 4152: foreach my $item (@items) {
4153: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
4154: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
4155: $r->print(&Apache::loncommon::start_data_table_row()."\n");
1.470 raeburn 4156: $r->print("<td>$lt{$item}</td><td>\n");
4157: unless ($item eq 'managers') {
4158: $r->print($oldsetting->{$item});
4159: }
1.383 raeburn 4160: if ($oldsettingtext->{$item}) {
4161: if ($oldsetting->{$item}) {
1.470 raeburn 4162: unless ($item eq 'managers') {
4163: $r->print(' -- ');
4164: }
1.383 raeburn 4165: }
4166: $r->print($oldsettingtext->{$item});
4167: }
1.470 raeburn 4168: $r->print("</td>\n<td>");
4169: unless ($item eq 'managers') {
4170: $r->print($newsetting->{$item});
4171: }
1.383 raeburn 4172: if ($newsettingtext->{$item}) {
4173: if ($newsetting->{$item}) {
1.470 raeburn 4174: unless ($item eq 'managers') {
4175: $r->print(' -- ');
4176: }
1.383 raeburn 4177: }
4178: $r->print($newsettingtext->{$item});
4179: }
4180: $r->print("</td>\n");
4181: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4182: }
4183: }
4184: } elsif ($entry eq 'tools') {
4185: foreach my $item (@{$usertools}) {
1.383 raeburn 4186: if ($newsetting->{$item} ne $oldsetting->{$item}) {
4187: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4188: $r->print("<td>$lt{$item}</td>\n");
4189: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
4190: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
4191: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4192: }
4193: }
1.378 raeburn 4194: } elsif ($entry eq 'quota') {
4195: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
4196: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
4197: foreach my $name ('portfolio','author') {
1.383 raeburn 4198: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
4199: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4200: $r->print("<td>$lt{$name.$entry}</td>\n");
4201: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
4202: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
4203: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 4204: }
4205: }
4206: }
1.334 raeburn 4207: } else {
1.383 raeburn 4208: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
4209: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4210: $r->print("<td>$lt{$entry}</td>\n");
4211: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
4212: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
4213: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4214: }
4215: }
4216: }
4217: }
1.367 golterma 4218: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 4219: } else {
4220: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
4221: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 4222: }
4223: return;
4224: }
4225:
1.275 raeburn 4226: sub tool_changes {
4227: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
4228: $changed,$newaccess,$newaccesstext) = @_;
4229: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
4230: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
4231: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
4232: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
4233: return;
4234: }
1.383 raeburn 4235: my %reqdisplay = &requestchange_display();
1.300 raeburn 4236: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 4237: my @options = ('approval','validate','autolimit');
1.306 raeburn 4238: my $optregex = join('|',@options);
1.300 raeburn 4239: my $cdom = $env{'request.role.domain'};
4240: foreach my $tool (@{$usertools}) {
1.383 raeburn 4241: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 4242: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 4243: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 4244: my ($newop,$limit);
1.314 raeburn 4245: if ($env{'form.'.$context.'_'.$tool}) {
4246: $newop = $env{'form.'.$context.'_'.$tool};
4247: if ($newop eq 'autolimit') {
1.383 raeburn 4248: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 4249: $limit =~ s/\D+//g;
4250: $newop .= '='.$limit;
4251: }
4252: }
1.300 raeburn 4253: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 4254: if ($newop) {
4255: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 4256: $changeHash,$context);
4257: if ($changed->{$tool}) {
1.383 raeburn 4258: if ($newop =~ /^autolimit/) {
4259: if ($limit) {
4260: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4261: } else {
4262: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4263: }
4264: } else {
4265: $newaccesstext->{$tool} = $reqdisplay{$newop};
4266: }
1.300 raeburn 4267: } else {
4268: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
4269: }
4270: }
4271: } else {
4272: my @curr = split(',',$userenv->{$context.'.'.$tool});
4273: my @new;
4274: my $changedoms;
1.314 raeburn 4275: foreach my $req (@curr) {
4276: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
4277: my $oldop = $1;
1.383 raeburn 4278: if ($oldop =~ /^autolimit=(\d*)/) {
4279: my $limit = $1;
4280: if ($limit) {
4281: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4282: } else {
4283: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4284: }
4285: } else {
4286: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
4287: }
1.314 raeburn 4288: if ($oldop ne $newop) {
4289: $changedoms = 1;
4290: foreach my $item (@curr) {
4291: my ($reqdom,$option) = split(':',$item);
4292: unless ($reqdom eq $cdom) {
4293: push(@new,$item);
4294: }
4295: }
4296: if ($newop) {
4297: push(@new,$cdom.':'.$newop);
1.300 raeburn 4298: }
1.314 raeburn 4299: @new = sort(@new);
1.300 raeburn 4300: }
1.314 raeburn 4301: last;
1.300 raeburn 4302: }
1.314 raeburn 4303: }
4304: if ((!$changedoms) && ($newop)) {
1.300 raeburn 4305: $changedoms = 1;
1.306 raeburn 4306: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 4307: }
4308: if ($changedoms) {
1.314 raeburn 4309: my $newdomstr;
1.300 raeburn 4310: if (@new) {
4311: $newdomstr = join(',',@new);
4312: }
4313: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
4314: $context);
4315: if ($changed->{$tool}) {
4316: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 4317: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 4318: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
4319: $limit =~ s/\D+//g;
4320: if ($limit) {
1.383 raeburn 4321: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 4322: } else {
1.383 raeburn 4323: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 4324: }
1.314 raeburn 4325: } else {
1.306 raeburn 4326: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
4327: }
1.300 raeburn 4328: } else {
1.383 raeburn 4329: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 4330: }
4331: }
4332: }
4333: }
4334: }
4335: return;
4336: }
1.470 raeburn 4337: my %tooldesc = &Apache::lonlocal::texthash(
4338: 'edit' => 'Standard editor (Edit)',
4339: 'xml' => 'Text editor (EditXML)',
4340: 'daxe' => 'Daxe editor (Daxe)',
4341: );
1.275 raeburn 4342: foreach my $tool (@{$usertools}) {
1.383 raeburn 4343: my ($newval,$limit,$envkey);
1.362 raeburn 4344: $envkey = $context.'.'.$tool;
1.306 raeburn 4345: if ($context eq 'requestcourses') {
4346: $newval = $env{'form.crsreq_'.$tool};
4347: if ($newval eq 'autolimit') {
1.383 raeburn 4348: $limit = $env{'form.crsreq_'.$tool.'_limit'};
4349: $limit =~ s/\D+//g;
4350: $newval .= '='.$limit;
1.306 raeburn 4351: }
1.362 raeburn 4352: } elsif ($context eq 'requestauthor') {
4353: $newval = $env{'form.'.$context};
4354: $envkey = $context;
1.470 raeburn 4355: } elsif ($context eq 'authordefaults') {
4356: if ($tool eq 'editors') {
4357: $envkey = 'authoreditors';
4358: if ($env{'form.customeditors'} == 1) {
4359: my @editors;
4360: my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
4361: if (@posseditors) {
4362: foreach my $editor (@posseditors) {
4363: if (grep(/^\Q$editor\E$/,@posseditors)) {
4364: unless (grep(/^\Q$editor\E$/,@editors)) {
4365: push(@editors,$editor);
4366: }
4367: }
4368: }
4369: }
4370: if (@editors) {
4371: $newval = join(',',(sort(@editors)));
4372: }
4373: }
4374: } elsif ($tool eq 'managers') {
4375: $envkey = 'authormanagers';
4376: my @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
4377: if (@possibles) {
4378: my %ca_roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},
4379: undef,['active','future'],['ca']);
4380: if (keys(%ca_roles)) {
4381: my @custommanagers;
4382: foreach my $user (@possibles) {
4383: if ($user =~ /^($match_username):($match_domain)$/) {
4384: if (exists($ca_roles{$user.':ca'})) {
4385: unless ($user eq $env{'form.ccuname'}.':'.$env{'form.ccdomain'}) {
4386: push(@custommanagers,$user);
4387: }
4388: }
4389: }
4390: }
4391: if (@custommanagers) {
4392: $newval = join(',',sort(@custommanagers));
4393: }
4394: }
4395: }
4396: } elsif ($tool eq 'webdav') {
4397: $envkey = 'tools.webdav';
4398: $newval = $env{'form.'.$context.'_'.$tool};
1.477 raeburn 4399: } elsif ($tool eq 'archive') {
4400: $envkey = 'authorarchive';
4401: $newval = $env{'form.'.$context.'_'.$tool};
1.470 raeburn 4402: }
1.314 raeburn 4403: } else {
1.306 raeburn 4404: $newval = $env{'form.'.$context.'_'.$tool};
4405: }
1.362 raeburn 4406: if ($userenv->{$envkey} ne '') {
1.275 raeburn 4407: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 4408: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4409: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
4410: my $currlimit = $1;
4411: if ($currlimit eq '') {
4412: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4413: } else {
4414: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
4415: }
4416: } elsif ($userenv->{$envkey}) {
4417: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
4418: } else {
4419: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4420: }
1.470 raeburn 4421: } elsif ($context eq 'authordefaults') {
4422: if ($tool eq 'managers') {
4423: if ($userenv->{$envkey} eq '') {
4424: $oldaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4425: } else {
4426: my $managers = $userenv->{$envkey};
4427: $managers =~ s/,/, /g;
4428: $oldaccesstext->{$tool} = $managers;
4429: }
4430: } elsif ($tool eq 'editors') {
4431: $oldaccesstext->{$tool} = &mt('can use: [_1]',
4432: join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
1.477 raeburn 4433: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4434: if ($userenv->{$envkey}) {
4435: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
4436: } else {
4437: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4438: }
4439: }
1.275 raeburn 4440: } else {
1.383 raeburn 4441: if ($userenv->{$envkey}) {
4442: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
4443: } else {
4444: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4445: }
1.275 raeburn 4446: }
1.362 raeburn 4447: $changeHash->{$envkey} = $userenv->{$envkey};
1.470 raeburn 4448: if (($env{'form.custom'.$tool} == 1) ||
4449: (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
1.362 raeburn 4450: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 4451: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
4452: $context);
1.275 raeburn 4453: if ($changed->{$tool}) {
4454: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 4455: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4456: if ($newval =~ /^autolimit/) {
4457: if ($limit) {
4458: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4459: } else {
4460: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4461: }
4462: } elsif ($newval) {
4463: $newaccesstext->{$tool} = $reqdisplay{$newval};
4464: } else {
4465: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4466: }
1.470 raeburn 4467: } elsif ($context eq 'authordefaults') {
4468: if ($tool eq 'editors') {
4469: $newaccesstext->{$tool} = &mt('can use: [_1]',
4470: join(', ', map { $tooldesc{$_} } split(/,/,$changeHash->{$envkey})));
4471: } elsif ($tool eq 'managers') {
4472: if ($changeHash->{$envkey} eq '') {
4473: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4474: } else {
4475: my $managers = $changeHash->{$envkey};
4476: $managers =~ s/,/, /g;
4477: $newaccesstext->{$tool} = $managers;
4478: }
1.477 raeburn 4479: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4480: if ($newval) {
4481: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4482: } else {
4483: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4484: }
4485: }
1.275 raeburn 4486: } else {
1.383 raeburn 4487: if ($newval) {
4488: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4489: } else {
4490: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4491: }
1.275 raeburn 4492: }
4493: } else {
4494: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 4495: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.470 raeburn 4496: if ($userenv->{$envkey} =~ /^autolimit/) {
1.383 raeburn 4497: if ($limit) {
4498: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4499: } else {
4500: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4501: }
1.470 raeburn 4502: } elsif ($userenv->{$envkey}) {
4503: $newaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
1.383 raeburn 4504: } else {
4505: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4506: }
1.470 raeburn 4507: } elsif ($context eq 'authordefaults') {
4508: if ($tool eq 'editors') {
4509: $newaccesstext->{$tool} = &mt('can use: [_1]',
4510: join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
4511: } elsif ($tool eq 'managers') {
4512: if ($userenv->{$envkey} eq '') {
4513: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4514: } else {
4515: my $managers = $userenv->{$envkey};
4516: $managers =~ s/,/, /g;
4517: $newaccesstext->{$tool} = $managers;
4518: }
1.477 raeburn 4519: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4520: if ($userenv->{$envkey}) {
4521: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4522: } else {
4523: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4524: }
4525: }
1.275 raeburn 4526: } else {
1.383 raeburn 4527: if ($userenv->{$context.'.'.$tool}) {
4528: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4529: } else {
4530: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4531: }
1.275 raeburn 4532: }
4533: }
4534: } else {
4535: $newaccess->{$tool} = $oldaccess->{$tool};
4536: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
4537: }
4538: } else {
4539: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
4540: if ($changed->{$tool}) {
4541: $newaccess->{$tool} = &mt('default');
4542: } else {
4543: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 4544: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4545: if ($newval =~ /^autolimit/) {
4546: if ($limit) {
4547: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4548: } else {
4549: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4550: }
4551: } elsif ($newval) {
4552: $newaccesstext->{$tool} = $reqdisplay{$newval};
4553: } else {
4554: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4555: }
1.470 raeburn 4556: } elsif ($context eq 'authordefaults') {
4557: if ($tool eq 'editors') {
4558: $newaccesstext->{$tool} = &mt('can use: [_1]',
4559: join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
4560: } elsif ($tool eq 'managers') {
4561: if ($newval eq '') {
4562: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4563: } else {
4564: my $managers = $newval;
4565: $managers =~ s/,/, /g;
4566: $newaccesstext->{$tool} = $managers;
4567: }
1.477 raeburn 4568: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4569: if ($userenv->{$envkey}) {
4570: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4571: } else {
4572: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4573: }
4574: }
1.275 raeburn 4575: } else {
1.383 raeburn 4576: if ($userenv->{$context.'.'.$tool}) {
4577: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4578: } else {
4579: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4580: }
1.275 raeburn 4581: }
4582: }
4583: }
4584: } else {
4585: $oldaccess->{$tool} = &mt('default');
1.470 raeburn 4586: if (($env{'form.custom'.$tool} == 1) ||
4587: (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
1.306 raeburn 4588: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
4589: $context);
1.275 raeburn 4590: if ($changed->{$tool}) {
4591: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 4592: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4593: if ($newval =~ /^autolimit/) {
4594: if ($limit) {
4595: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4596: } else {
4597: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4598: }
4599: } elsif ($newval) {
4600: $newaccesstext->{$tool} = $reqdisplay{$newval};
4601: } else {
4602: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4603: }
1.470 raeburn 4604: } elsif ($context eq 'authordefaults') {
4605: if ($tool eq 'managers') {
4606: if ($newval eq '') {
4607: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4608: } else {
4609: my $managers = $newval;
4610: $managers =~ s/,/, /g;
4611: $newaccesstext->{$tool} = $managers;
4612: }
4613: } elsif ($tool eq 'editors') {
4614: $newaccesstext->{$tool} = &mt('can use: [_1]',
4615: join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
1.477 raeburn 4616: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4617: if ($newval) {
4618: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4619: } else {
4620: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4621: }
4622: }
1.275 raeburn 4623: } else {
1.383 raeburn 4624: if ($newval) {
4625: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4626: } else {
4627: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4628: }
1.275 raeburn 4629: }
4630: } else {
4631: $newaccess->{$tool} = $oldaccess->{$tool};
4632: }
4633: } else {
4634: $newaccess->{$tool} = $oldaccess->{$tool};
4635: }
4636: }
4637: }
4638: return;
4639: }
4640:
1.220 raeburn 4641: sub update_roles {
1.375 raeburn 4642: my ($r,$context,$showcredits) = @_;
1.4 www 4643: my $now=time;
1.225 raeburn 4644: my @rolechanges;
1.465 raeburn 4645: my (%disallowed,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.466 raeburn 4646: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.465 raeburn 4647: $got_role_approvals{$context} = '';
4648: $process_by{$context} = {};
4649: my @domroles = &Apache::lonuserutils::domain_roles();
4650: my @cstrroles = &Apache::lonuserutils::construction_space_roles();
4651: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
1.73 sakharuk 4652: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 4653: foreach my $key (keys(%env)) {
1.135 raeburn 4654: next if (! $env{$key});
1.190 raeburn 4655: next if ($key eq 'form.action');
1.27 matthew 4656: # Revoke roles
1.135 raeburn 4657: if ($key=~/^form\.rev/) {
4658: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 4659: # Revoke standard role
1.170 albertel 4660: my ($scope,$role) = ($1,$2);
4661: my $result =
4662: &Apache::lonnet::revokerole($env{'form.ccdomain'},
4663: $env{'form.ccuname'},
1.239 raeburn 4664: $scope,$role,'','',$context);
1.367 golterma 4665: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4666: &mt('Revoking [_1] in [_2]',
4667: &Apache::lonnet::plaintext($role),
1.372 raeburn 4668: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4669: $result ne "ok").'<br />');
4670: if ($result ne "ok") {
4671: $r->print(&mt('Error: [_1]',$result).'<br />');
4672: }
1.170 albertel 4673: if ($role eq 'st') {
1.202 raeburn 4674: my $result =
1.198 raeburn 4675: &Apache::lonuserutils::classlist_drop($scope,
4676: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4677: $now);
1.367 golterma 4678: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 4679: }
1.225 raeburn 4680: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4681: push(@rolechanges,$role);
4682: }
1.196 raeburn 4683: }
1.195 raeburn 4684: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 4685: # Revoke custom role
1.369 bisitz 4686: my $result = &Apache::lonnet::revokecustomrole(
4687: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 4688: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4689: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 4690: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4691: $result ne 'ok').'<br />');
4692: if ($result ne "ok") {
4693: $r->print(&mt('Error: [_1]',$result).'<br />');
4694: }
1.225 raeburn 4695: if (!grep(/^cr$/,@rolechanges)) {
4696: push(@rolechanges,'cr');
4697: }
1.64 www 4698: }
1.135 raeburn 4699: } elsif ($key=~/^form\.del/) {
4700: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 4701: # Delete standard role
1.170 albertel 4702: my ($scope,$role) = ($1,$2);
4703: my $result =
4704: &Apache::lonnet::assignrole($env{'form.ccdomain'},
4705: $env{'form.ccuname'},
1.239 raeburn 4706: $scope,$role,$now,0,1,'',
4707: $context);
1.367 golterma 4708: $r->print(&Apache::lonhtmlcommon::confirm_success(
4709: &mt('Deleting [_1] in [_2]',
1.369 bisitz 4710: &Apache::lonnet::plaintext($role),
1.372 raeburn 4711: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4712: $result ne 'ok').'<br />');
4713: if ($result ne "ok") {
4714: $r->print(&mt('Error: [_1]',$result).'<br />');
4715: }
1.367 golterma 4716:
1.170 albertel 4717: if ($role eq 'st') {
1.202 raeburn 4718: my $result =
1.198 raeburn 4719: &Apache::lonuserutils::classlist_drop($scope,
4720: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4721: $now);
1.369 bisitz 4722: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 4723: }
1.225 raeburn 4724: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4725: push(@rolechanges,$role);
4726: }
1.116 raeburn 4727: }
1.139 albertel 4728: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4729: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4730: # Delete custom role
1.369 bisitz 4731: my $result =
4732: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
4733: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
4734: 0,1,$context);
4735: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 4736: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4737: $result ne "ok").'<br />');
4738: if ($result ne "ok") {
4739: $r->print(&mt('Error: [_1]',$result).'<br />');
4740: }
1.367 golterma 4741:
1.225 raeburn 4742: if (!grep(/^cr$/,@rolechanges)) {
4743: push(@rolechanges,'cr');
4744: }
1.116 raeburn 4745: }
1.135 raeburn 4746: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4747: my $udom = $env{'form.ccdomain'};
4748: my $uname = $env{'form.ccuname'};
1.116 raeburn 4749: # Re-enable standard role
1.135 raeburn 4750: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4751: my $url = $1;
4752: my $role = $2;
1.465 raeburn 4753: my $id = $url.'_'.$role;
1.89 raeburn 4754: my $logmsg;
4755: my $output;
4756: if ($role eq 'st') {
1.141 albertel 4757: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4758: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4759: my $credits;
4760: if ($showcredits) {
1.465 raeburn 4761: my $defaultcredits =
1.375 raeburn 4762: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4763: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4764: }
1.465 raeburn 4765: unless ($udom eq $cdom) {
4766: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4767: $uname,$role,$now,0,$cdom,$cnum,$csec,$credits,
4768: \%process_by,\%instdoms,\%got_role_approvals,
1.466 raeburn 4769: \%got_instdoms,\%reject,\%pending,\%notifydc,
4770: \%status,\%unauthorized,\%currqueued));
1.465 raeburn 4771: }
1.375 raeburn 4772: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4773: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4774: if ($result eq 'refused' && $logmsg) {
4775: $output = $logmsg;
4776: } else {
1.369 bisitz 4777: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4778: }
1.89 raeburn 4779: } else {
1.372 raeburn 4780: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4781: &Apache::lonnet::plaintext($role),
4782: &Apache::loncommon::show_role_extent($url,$context,'st'),
4783: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4784: }
4785: }
4786: } else {
1.465 raeburn 4787: my ($cdom,$cnum,$csec);
4788: if (grep(/^\Q$role\E$/,@cstrroles)) {
4789: ($cdom,$cnum) = ($url =~ m{^/($match_domain)/($match_username)$});
4790: } elsif (grep(/^\Q$role\E$/,@domroles)) {
4791: ($cdom) = ($url =~ m{^/($match_domain)/$});
4792: } elsif ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
4793: ($cdom,$cnum,$csec) = ($1,$2,$3);
4794: }
4795: if ($cdom ne '') {
4796: unless ($udom eq $cdom) {
4797: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4798: $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by,
4799: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4800: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4801: }
4802: }
1.101 albertel 4803: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4804: $env{'form.ccuname'},$url,$role,0,$now,'','',
4805: $context);
1.461 raeburn 4806: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
4807: &Apache::lonnet::plaintext($role),
4808: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4809: if ($result ne "ok") {
4810: $output .= &mt('Error: [_1]',$result).'<br />';
4811: }
4812: }
1.89 raeburn 4813: $r->print($output);
1.225 raeburn 4814: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4815: push(@rolechanges,$role);
4816: }
1.113 raeburn 4817: }
1.116 raeburn 4818: # Re-enable custom role
1.139 albertel 4819: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4820: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1.465 raeburn 4821: my $id = $url.'_cr'."/$rdom/$rnam/$rolename";
4822: my $role = "cr/$rdom/$rnam/$rolename";
4823: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
4824: my ($cdom,$cnum,$csec) = ($1,$2,$3);
4825: unless ($udom eq $cdom) {
4826: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4827: $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by,
4828: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4829: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4830: }
4831: }
1.116 raeburn 4832: my $result = &Apache::lonnet::assigncustomrole(
4833: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4834: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4835: $r->print(&Apache::lonhtmlcommon::confirm_success(
4836: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4837: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4838: $result ne "ok").'<br />');
4839: if ($result ne "ok") {
4840: $r->print(&mt('Error: [_1]',$result).'<br />');
4841: }
1.225 raeburn 4842: if (!grep(/^cr$/,@rolechanges)) {
4843: push(@rolechanges,'cr');
4844: }
1.116 raeburn 4845: }
1.135 raeburn 4846: } elsif ($key=~/^form\.act/) {
1.101 albertel 4847: my $udom = $env{'form.ccdomain'};
4848: my $uname = $env{'form.ccuname'};
1.141 albertel 4849: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4850: # Activate a custom role
1.83 albertel 4851: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4852: my $url='/'.$one.'/'.$two;
1.465 raeburn 4853: my $id = $url.'_cr/'."$three/$four/$five";
4854: my $role = "cr/$three/$four/$five";
1.83 albertel 4855: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4856:
1.101 albertel 4857: my $start = ( $env{'form.start_'.$full} ?
4858: $env{'form.start_'.$full} :
1.88 raeburn 4859: $now );
1.101 albertel 4860: my $end = ( $env{'form.end_'.$full} ?
4861: $env{'form.end_'.$full} :
1.88 raeburn 4862: 0 );
1.465 raeburn 4863:
1.88 raeburn 4864: # split multiple sections
4865: my %sections = ();
1.461 raeburn 4866: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$five);
1.88 raeburn 4867: if ($num_sections == 0) {
1.465 raeburn 4868: unless ($udom eq $one) {
4869: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4870: $uname,$role,$start,$end,$one,$two,'','',\%process_by,
4871: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4872: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4873: }
1.240 raeburn 4874: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4875: } else {
1.114 albertel 4876: my %curr_groups =
1.117 raeburn 4877: &Apache::longroup::coursegroups($one,$two);
1.465 raeburn 4878: my ($restricted,$numchanges);
1.404 raeburn 4879: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4880: if (($sec eq 'none') || ($sec eq 'all') ||
4881: exists($curr_groups{$sec})) {
4882: $disallowed{$sec} = $url;
4883: next;
4884: }
4885: my $securl = $url.'/'.$sec;
1.465 raeburn 4886: my $secid = $securl.'_cr'."/$three/$four/$five";
4887: undef($restricted);
4888: unless ($udom eq $one) {
4889: next if (&Apache::lonuserutils::restricted_dom($context,$secid,$udom,
4890: $uname,$role,$start,$end,$one,$two,$sec,'',\%process_by,
4891: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4892: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4893: }
4894: $numchanges ++;
1.240 raeburn 4895: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4896: }
1.465 raeburn 4897: next unless ($numchanges);
1.88 raeburn 4898: }
1.225 raeburn 4899: if (!grep(/^cr$/,@rolechanges)) {
4900: push(@rolechanges,'cr');
4901: }
1.142 raeburn 4902: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4903: # Activate roles for sections with 3 id numbers
4904: # set start, end times, and the url for the class
1.83 albertel 4905: my ($one,$two,$three)=($1,$2,$3);
1.461 raeburn 4906: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4907: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4908: $now );
1.461 raeburn 4909: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1.101 albertel 4910: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4911: 0 );
1.83 albertel 4912: my $url='/'.$one.'/'.$two;
1.465 raeburn 4913: my $id = $url.'_'.$three;
1.88 raeburn 4914: # split multiple sections
4915: my %sections = ();
1.101 albertel 4916: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.465 raeburn 4917: my ($credits,$numchanges);
1.375 raeburn 4918: if ($three eq 'st') {
1.461 raeburn 4919: if ($showcredits) {
1.375 raeburn 4920: my $defaultcredits =
4921: &Apache::lonuserutils::get_defaultcredits($one,$two);
4922: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4923: $credits =~ s/[^\d\.]//g;
4924: if ($credits eq $defaultcredits) {
4925: undef($credits);
4926: }
4927: }
4928: }
1.88 raeburn 4929: if ($num_sections == 0) {
1.465 raeburn 4930: unless ($udom eq $one) {
4931: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4932: $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by,
4933: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4934: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4935: }
4936: $numchanges ++;
1.375 raeburn 4937: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4938: } else {
1.114 albertel 4939: my %curr_groups =
1.117 raeburn 4940: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4941: my $emptysec = 0;
1.465 raeburn 4942: my $restricted;
1.404 raeburn 4943: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4944: $sec =~ s/\W//g;
1.113 raeburn 4945: if ($sec ne '') {
4946: if (($sec eq 'none') || ($sec eq 'all') ||
4947: exists($curr_groups{$sec})) {
4948: $disallowed{$sec} = $url;
4949: next;
4950: }
1.88 raeburn 4951: my $securl = $url.'/'.$sec;
1.465 raeburn 4952: my $secid = $securl.'_'.$three;
4953: unless ($udom eq $one) {
4954: undef($restricted);
4955: $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
4956: $uname,$three,$start,$end,$one,$two,$sec,$credits,\%process_by,
4957: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4958: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4959: next if ($restricted);
4960: }
4961: $numchanges ++;
1.375 raeburn 4962: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4963: } else {
4964: $emptysec = 1;
4965: }
4966: }
4967: if ($emptysec) {
1.465 raeburn 4968: unless ($udom eq $one) {
4969: undef($restricted);
4970: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
4971: $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by,
4972: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4973: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4974: next if ($restricted);
4975: }
4976: $numchanges ++;
1.375 raeburn 4977: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4978: }
1.465 raeburn 4979: next unless ($numchanges);
1.225 raeburn 4980: }
4981: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4982: push(@rolechanges,$three);
4983: }
1.135 raeburn 4984: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4985: # Activate roles for sections with two id numbers
4986: # set start, end times, and the url for the class
1.461 raeburn 4987: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4988: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4989: $now );
1.461 raeburn 4990: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1.101 albertel 4991: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4992: 0 );
1.225 raeburn 4993: my $one = $1;
4994: my $two = $2;
4995: my $url='/'.$one.'/';
1.465 raeburn 4996: my $id = $url.'_'.$two;
1.468 raeburn 4997: my ($cdom,$cnum) = split(/\//,$one);
1.88 raeburn 4998: # split multiple sections
4999: my %sections = ();
1.465 raeburn 5000: my ($restricted,$numchanges);
1.225 raeburn 5001: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 5002: if ($num_sections == 0) {
1.465 raeburn 5003: unless ($udom eq $one) {
5004: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
1.468 raeburn 5005: $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
1.465 raeburn 5006: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 5007: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 5008: next if ($restricted);
5009: }
5010: $numchanges ++;
1.240 raeburn 5011: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 5012: } else {
5013: my $emptysec = 0;
1.404 raeburn 5014: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 5015: if ($sec ne '') {
5016: my $securl = $url.'/'.$sec;
1.465 raeburn 5017: my $secid = $securl.'_'.$two;
5018: unless ($udom eq $one) {
5019: undef($restricted);
5020: $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
1.468 raeburn 5021: $uname,$two,$start,$end,$cdom,$cnum,$sec,'',\%process_by,
1.465 raeburn 5022: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 5023: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 5024: next if ($restricted);
5025: }
5026: $numchanges ++;
1.240 raeburn 5027: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 5028: } else {
5029: $emptysec = 1;
5030: }
5031: }
5032: if ($emptysec) {
1.465 raeburn 5033: unless ($udom eq $one) {
5034: undef($restricted);
5035: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
1.468 raeburn 5036: $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
1.465 raeburn 5037: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 5038: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 5039: next if ($restricted);
5040: }
5041: $numchanges ++;
1.240 raeburn 5042: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 5043: }
1.465 raeburn 5044: next unless ($numchanges);
1.88 raeburn 5045: }
1.225 raeburn 5046: if (!grep(/^\Q$two\E$/,@rolechanges)) {
5047: push(@rolechanges,$two);
5048: }
1.64 www 5049: } else {
1.190 raeburn 5050: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 5051: }
1.113 raeburn 5052: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 5053: $r->print('<p class="LC_warning">');
1.113 raeburn 5054: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 5055: $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.','<tt>'.$key.'</tt>'));
1.113 raeburn 5056: } else {
1.274 bisitz 5057: $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>'));
1.113 raeburn 5058: }
1.274 bisitz 5059: $r->print('</p><p>'
5060: .&mt('Please [_1]go back[_2] and choose a different section name.'
5061: ,'<a href="javascript:history.go(-1)'
5062: ,'</a>')
5063: .'</p><br />'
5064: );
1.113 raeburn 5065: }
5066: }
1.101 albertel 5067: } # End of foreach (keys(%env))
1.466 raeburn 5068: if ((keys(%reject)) || (keys(%unauthorized))) {
5069: $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized));
1.465 raeburn 5070: }
1.466 raeburn 5071: if ((keys(%pending)) || (keys(%currqueued))) {
5072: $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.465 raeburn 5073: }
1.75 www 5074: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 5075: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 5076: if (@rolechanges == 0) {
1.372 raeburn 5077: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 5078: }
1.225 raeburn 5079: return @rolechanges;
1.220 raeburn 5080: }
5081:
1.375 raeburn 5082: sub get_user_credits {
5083: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
5084: if ($cdom eq '' || $cnum eq '') {
5085: return unless ($env{'request.course.id'});
5086: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5087: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5088: }
5089: my $credits;
5090: my %currhash =
5091: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
5092: if (keys(%currhash) > 0) {
5093: my @items = split(/:/,$currhash{$uname.':'.$udom});
5094: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
5095: $credits = $items[$crdidx];
5096: $credits =~ s/[^\d\.]//g;
5097: }
5098: if ($credits eq $defaultcredits) {
5099: undef($credits);
5100: }
5101: return $credits;
5102: }
5103:
1.220 raeburn 5104: sub enroll_single_student {
1.375 raeburn 5105: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
5106: $showcredits,$defaultcredits) = @_;
1.318 raeburn 5107: $r->print('<h3>');
5108: if ($crstype eq 'Community') {
5109: $r->print(&mt('Enrolling Member'));
5110: } else {
5111: $r->print(&mt('Enrolling Student'));
5112: }
5113: $r->print('</h3>');
1.220 raeburn 5114:
5115: # Remove non alphanumeric values from section
5116: $env{'form.sections'}=~s/\W//g;
5117:
1.375 raeburn 5118: my $credits;
5119: if (($showcredits) && ($env{'form.credits'} ne '')) {
5120: $credits = $env{'form.credits'};
5121: $credits =~ s/[^\d\.]//g;
5122: if ($credits ne '') {
5123: if ($credits eq $defaultcredits) {
5124: undef($credits);
5125: }
5126: }
5127: }
1.465 raeburn 5128: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
1.466 raeburn 5129: my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,%pending,%reject,%notifydc,
5130: %status,%unauthorized,%currqueued);
1.465 raeburn 5131: unless ($env{'form.ccdomain'} eq $env{'course.'.$env{'request.course.id'}.'.domain'}) {
5132: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5133: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5134: my $csec = $env{'form.sections'};
5135: my $id = "/$cdom/$cnum";
5136: if ($csec ne '') {
5137: $id .= "/$csec";
5138: }
5139: $id .= '_st';
5140: if (&Apache::lonuserutils::restricted_dom($context,$id,$env{'form.ccdomain'},$env{'form.ccuname'},
5141: 'st',$startdate,$enddate,$cdom,$cnum,$csec,$credits,
5142: \%process_by,\%instdoms,\%got_role_approvals,\%got_instdoms,
1.466 raeburn 5143: \%reject,\%pending,\%notifydc,\%status,\%unauthorized,\%currqueued)) {
5144: if ((keys(%reject)) || (keys(%unauthorized))) {
5145: $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized));
1.465 raeburn 5146: }
1.466 raeburn 5147: if ((keys(%pending)) || (keys(%currqueued))) {
5148: $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.465 raeburn 5149: }
5150: return;
5151: }
5152: }
1.375 raeburn 5153:
1.220 raeburn 5154: # Clean out any old student roles the user has in this class.
5155: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
5156: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
5157: my $enroll_result =
5158: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
5159: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
5160: $env{'form.cmiddlename'},$env{'form.clastname'},
5161: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 5162: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
5163: $credits);
1.220 raeburn 5164: if ($enroll_result =~ /^ok/) {
1.381 bisitz 5165: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 5166: if ($env{'form.sections'} ne '') {
5167: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
5168: }
5169: my ($showstart,$showend);
5170: if ($startdate <= $now) {
5171: $showstart = &mt('Access starts immediately');
5172: } else {
5173: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
5174: }
5175: if ($enddate == 0) {
5176: $showend = &mt('ends: no ending date');
5177: } else {
5178: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
5179: }
5180: $r->print('.<br />'.$showstart.'; '.$showend);
5181: if ($startdate <= $now && !$newuser) {
1.386 bisitz 5182: $r->print('<p class="LC_info">');
1.318 raeburn 5183: if ($crstype eq 'Community') {
1.392 raeburn 5184: $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.'));
1.318 raeburn 5185: } else {
1.392 raeburn 5186: $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.'));
1.318 raeburn 5187: }
5188: $r->print('</p>');
1.220 raeburn 5189: }
5190: } else {
5191: $r->print(&mt('unable to enroll').": ".$enroll_result);
5192: }
5193: return;
1.188 raeburn 5194: }
5195:
1.204 raeburn 5196: sub get_defaultquota_text {
5197: my ($settingstatus) = @_;
5198: my $defquotatext;
5199: if ($settingstatus eq '') {
1.383 raeburn 5200: $defquotatext = &mt('default');
1.204 raeburn 5201: } else {
5202: my ($usertypes,$order) =
5203: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
5204: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 5205: $defquotatext = &mt('default');
1.204 raeburn 5206: } else {
1.383 raeburn 5207: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 5208: }
5209: }
5210: return $defquotatext;
5211: }
5212:
1.188 raeburn 5213: sub update_result_form {
5214: my ($uhome) = @_;
5215: my $outcome =
1.367 golterma 5216: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 5217: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 5218: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 5219: }
1.207 raeburn 5220: if ($env{'form.origname'} ne '') {
5221: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
5222: }
1.160 raeburn 5223: foreach my $item ('sortby','seluname','seludom') {
5224: if (exists($env{'form.'.$item})) {
1.188 raeburn 5225: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 5226: }
5227: }
1.188 raeburn 5228: if ($uhome eq 'no_host') {
5229: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
5230: }
5231: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 5232: '<input type="hidden" name="currstate" value="" />'."\n".
5233: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 5234: '</form>';
5235: return $outcome;
1.4 www 5236: }
5237:
1.149 raeburn 5238: sub quota_admin {
1.378 raeburn 5239: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 5240: my $quotachanged;
5241: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
5242: # Current user has quota modification privileges
1.267 raeburn 5243: if (ref($changeHash) eq 'HASH') {
5244: $quotachanged = 1;
1.378 raeburn 5245: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 5246: }
1.149 raeburn 5247: }
5248: return $quotachanged;
5249: }
5250:
1.267 raeburn 5251: sub tool_admin {
1.275 raeburn 5252: my ($tool,$settool,$changeHash,$context) = @_;
5253: my $canchange = 0;
1.279 raeburn 5254: if ($context eq 'requestcourses') {
1.275 raeburn 5255: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
5256: $canchange = 1;
5257: }
1.300 raeburn 5258: } elsif ($context eq 'reqcrsotherdom') {
5259: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
5260: $canchange = 1;
5261: }
1.362 raeburn 5262: } elsif ($context eq 'requestauthor') {
5263: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
5264: $canchange = 1;
5265: }
1.470 raeburn 5266: } elsif ($context eq 'authordefaults') {
5267: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
5268: $canchange = 1;
5269: }
1.275 raeburn 5270: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
5271: # Current user has quota modification privileges
5272: $canchange = 1;
5273: }
1.267 raeburn 5274: my $toolchanged;
1.275 raeburn 5275: if ($canchange) {
1.267 raeburn 5276: if (ref($changeHash) eq 'HASH') {
5277: $toolchanged = 1;
1.362 raeburn 5278: if ($tool eq 'requestauthor') {
5279: $changeHash->{$context} = $settool;
1.477 raeburn 5280: } elsif (($tool eq 'managers') || ($tool eq 'editors') || ($tool eq 'archive')) {
1.470 raeburn 5281: $changeHash->{'author'.$tool} = $settool;
5282: } elsif ($tool eq 'webdav') {
5283: $changeHash->{'tools.'.$tool} = $settool;
1.362 raeburn 5284: } else {
5285: $changeHash->{$context.'.'.$tool} = $settool;
5286: }
1.267 raeburn 5287: }
5288: }
5289: return $toolchanged;
5290: }
5291:
1.88 raeburn 5292: sub build_roles {
1.89 raeburn 5293: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 5294: my $num_sections = 0;
5295: if ($sectionstr=~ /,/) {
5296: my @secnums = split/,/,$sectionstr;
1.89 raeburn 5297: if ($role eq 'st') {
5298: $secnums[0] =~ s/\W//g;
5299: $$sections{$secnums[0]} = 1;
5300: $num_sections = 1;
5301: } else {
5302: foreach my $sec (@secnums) {
5303: $sec =~ ~s/\W//g;
1.150 banghart 5304: if (!($sec eq "")) {
1.89 raeburn 5305: if (exists($$sections{$sec})) {
5306: $$sections{$sec} ++;
5307: } else {
5308: $$sections{$sec} = 1;
5309: $num_sections ++;
5310: }
1.88 raeburn 5311: }
5312: }
5313: }
5314: } else {
5315: $sectionstr=~s/\W//g;
5316: unless ($sectionstr eq '') {
5317: $$sections{$sectionstr} = 1;
5318: $num_sections ++;
5319: }
5320: }
1.129 albertel 5321:
1.88 raeburn 5322: return $num_sections;
5323: }
5324:
1.58 www 5325: # ========================================================== Custom Role Editor
5326:
5327: sub custom_role_editor {
1.439 raeburn 5328: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 5329: my $action = $env{'form.customroleaction'};
1.439 raeburn 5330: my ($rolename,$helpitem);
1.324 raeburn 5331: if ($action eq 'new') {
5332: $rolename=$env{'form.newrolename'};
5333: } else {
5334: $rolename=$env{'form.rolename'};
1.59 www 5335: }
5336:
1.324 raeburn 5337: my ($crstype,$context);
5338: if ($env{'request.course.id'}) {
5339: $crstype = &Apache::loncommon::course_type();
5340: $context = 'course';
1.439 raeburn 5341: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 5342: } else {
5343: $context = 'domain';
1.414 raeburn 5344: $crstype = 'course';
1.439 raeburn 5345: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 5346: }
1.351 raeburn 5347:
5348: $rolename=~s/[^A-Za-z0-9]//gs;
5349: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 5350: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
5351: $permission);
1.351 raeburn 5352: return;
5353: }
5354:
1.414 raeburn 5355: my $formname = 'form1';
5356: my %privs=();
5357: my $body_top = '<h2>';
5358: # ------------------------------------------------------- Does this role exist?
1.59 www 5359: my ($rdummy,$roledef)=
5360: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
5361: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 5362: $body_top .= &mt('Existing Role').' "';
1.61 www 5363: # ------------------------------------------------- Get current role privileges
1.414 raeburn 5364: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
5365: if ($privs{'system'} =~ /bre\&S/) {
5366: if ($context eq 'domain') {
1.417 raeburn 5367: $crstype = 'Course';
1.414 raeburn 5368: } elsif ($crstype eq 'Community') {
5369: $privs{'system'} =~ s/bre\&S//;
5370: }
5371: } elsif ($context eq 'domain') {
5372: $crstype = 'Course';
1.324 raeburn 5373: }
1.59 www 5374: } else {
1.414 raeburn 5375: $body_top .= &mt('New Role').' "';
5376: $roledef='';
1.59 www 5377: }
1.153 banghart 5378: $body_top .= $rolename.'"</h2>';
1.414 raeburn 5379:
5380: # ------------------------------------------------------- What can be assigned?
5381: my %full=();
1.417 raeburn 5382: my %levels=(
1.414 raeburn 5383: course => {},
5384: domain => {},
5385: system => {},
5386: );
5387: my %levelscurrent=(
5388: course => {},
5389: domain => {},
5390: system => {},
5391: );
5392: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 5393: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 5394: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 5395: my $head_script =
1.414 raeburn 5396: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
5397: \%full,\@templateroles,$jsback);
1.351 raeburn 5398: push (@{$brcrum},
1.414 raeburn 5399: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 5400: text => "Pick custom role",
5401: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 5402: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 5403: text => "Edit custom role",
5404: faq => 282,
5405: bug => 'Instructor Interface',
1.439 raeburn 5406: help => $helpitem}
1.351 raeburn 5407: );
5408: my $args = { bread_crumbs => $brcrum,
5409: bread_crumbs_component => 'User Management'};
5410: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
5411: $head_script,$args).
5412: $body_top);
1.414 raeburn 5413: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
5414: &Apache::lonuserutils::custom_role_header($context,$crstype,
5415: \@templateroles,$prefix));
1.264 bisitz 5416:
1.61 www 5417: $r->print(<<ENDCCF);
5418: <input type="hidden" name="phase" value="set_custom_roles" />
5419: <input type="hidden" name="rolename" value="$rolename" />
5420: ENDCCF
1.414 raeburn 5421: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
5422: \%levelscurrent,$prefix));
1.135 raeburn 5423: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 5424: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 5425: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 5426: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 5427: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 5428: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 5429: }
1.414 raeburn 5430:
1.61 www 5431: # ---------------------------------------------------------- Call to definerole
5432: sub set_custom_role {
1.439 raeburn 5433: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 5434: my $rolename=$env{'form.rolename'};
1.63 www 5435: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 5436: if (!$rolename) {
1.439 raeburn 5437: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 5438: return;
5439: }
1.160 raeburn 5440: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 5441: my $jscript = '<script type="text/javascript">'
5442: .'// <![CDATA['."\n"
5443: .$jsback."\n"
5444: .'// ]]>'."\n"
5445: .'</script>'."\n";
1.439 raeburn 5446: my $helpitem = 'Course_Editing_Custom_Roles';
5447: if ($context eq 'domain') {
5448: $helpitem = 'Domain_Editing_Custom_Roles';
5449: }
1.352 raeburn 5450: push(@{$brcrum},
5451: {href => "javascript:backPage(document.customresult,'pickrole','')",
5452: text => "Pick custom role",
5453: faq => 282,
5454: bug => 'Instructor Interface',},
5455: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
5456: text => "Edit custom role",
5457: faq => 282,
5458: bug => 'Instructor Interface',},
5459: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
5460: text => "Result",
5461: faq => 282,
5462: bug => 'Instructor Interface',
1.439 raeburn 5463: help => $helpitem,}
1.352 raeburn 5464: );
5465: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 5466: bread_crumbs_component => 'User Management'};
1.351 raeburn 5467: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 5468:
1.393 raeburn 5469: my $newrole;
1.61 www 5470: my ($rdummy,$roledef)=
1.110 albertel 5471: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
5472:
1.61 www 5473: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 5474: $r->print('<h3>');
1.61 www 5475: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 5476: $r->print(&mt('Existing Role').' "');
1.61 www 5477: } else {
1.73 sakharuk 5478: $r->print(&mt('New Role').' "');
1.61 www 5479: $roledef='';
1.393 raeburn 5480: $newrole = 1;
1.61 www 5481: }
1.188 raeburn 5482: $r->print($rolename.'"</h3>');
1.414 raeburn 5483: # ------------------------------------------------- Assign role and show result
1.61 www 5484:
1.387 bisitz 5485: my $errmsg;
1.414 raeburn 5486: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
5487: # Assign role and return result
5488: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
5489: $newprivs{'c'});
1.387 bisitz 5490: if ($result ne 'ok') {
5491: $errmsg = ': '.$result;
5492: }
5493: my $message =
5494: &Apache::lonhtmlcommon::confirm_success(
5495: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 5496: if ($env{'request.course.id'}) {
5497: my $url='/'.$env{'request.course.id'};
1.63 www 5498: $url=~s/\_/\//g;
1.387 bisitz 5499: $result =
5500: &Apache::lonnet::assigncustomrole(
5501: $env{'user.domain'},$env{'user.name'},
5502: $url,
5503: $env{'user.domain'},$env{'user.name'},
5504: $rolename,undef,undef,undef,$context);
5505: if ($result ne 'ok') {
5506: $errmsg = ': '.$result;
5507: }
5508: $message .=
5509: '<br />'
5510: .&Apache::lonhtmlcommon::confirm_success(
5511: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 5512: }
1.380 bisitz 5513: $r->print(
1.387 bisitz 5514: &Apache::loncommon::confirmwrapper($message)
5515: .'<br />'
5516: .&Apache::lonhtmlcommon::actionbox([
5517: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
5518: .&mt('Create or edit another custom role')
5519: .'</a>'])
1.380 bisitz 5520: .'<form name="customresult" method="post" action="">'
1.387 bisitz 5521: .&Apache::lonhtmlcommon::echo_form_input([])
5522: .'</form>'
1.380 bisitz 5523: );
1.58 www 5524: }
5525:
1.465 raeburn 5526: sub show_role_requests {
5527: my ($caller,$dom) = @_;
5528: my $showrolereqs;
5529: my %domconfig = &Apache::lonnet::get_dom('configuration',['privacy'],$dom);
5530: if (ref($domconfig{'privacy'}) eq 'HASH') {
5531: if (ref($domconfig{'privacy'}{'approval'}) eq 'HASH') {
5532: my %approvalconf = %{$domconfig{'privacy'}{'approval'}};
5533: foreach my $key ('instdom','extdom') {
5534: if (ref($approvalconf{$key}) eq 'HASH') {
5535: if (keys(%{$approvalconf{$key}})) {
5536: foreach my $context ('domain','author','course','community') {
5537: if ($approvalconf{$key}{$context} eq $caller) {
5538: $showrolereqs = 1;
5539: last if ($showrolereqs);
5540: }
5541: }
5542: }
5543: }
5544: last if ($showrolereqs);
5545: }
5546: }
5547: }
5548: return $showrolereqs;
5549: }
5550:
1.470 raeburn 5551: sub display_coauthor_managers {
5552: my ($permission) = @_;
5553: my $output;
5554: if ((ref($permission) eq 'HASH') && ($permission->{'author'})) {
5555: $output = '<form action="/adm/createuser" method="post" name="camanagers">'.
5556: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
5557: '<p>';
5558: my (@possmanagers,@custommanagers);
5559: my %userenv =
5560: &Apache::lonnet::userenvironment($env{'user.domain'},
5561: $env{'user.name'},
5562: 'authormanagers');
5563: my %ca_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5564: ['active','future'],['ca']);
5565: if (keys(%ca_roles)) {
5566: foreach my $entry (sort(keys(%ca_roles))) {
5567: if ($entry =~ /^($match_username\:$match_domain):ca$/) {
5568: my $user = $1;
5569: unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5570: push(@possmanagers,$user);
5571: }
5572: }
5573: }
5574: }
5575: if ($userenv{'authormanagers'} eq '') {
5576: $output .= &mt('Currently author manages co-author roles');
5577: } else {
5578: if (keys(%ca_roles)) {
5579: foreach my $user (split(/,/,$userenv{'authormanagers'})) {
5580: if ($user =~ /^($match_username)\:($match_domain)$/) {
5581: if (exists($ca_roles{$user.':ca'})) {
5582: unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5583: push(@custommanagers,$user);
5584: }
5585: }
5586: }
5587: }
5588: }
5589: if (@custommanagers) {
5590: $output .= &mt('Co-authors with active or future roles who currently manage co-author roles: [_1]',
5591: '<br />'.join(', ',map { &Apache::loncommon::plainname(split(':',$_))." ($_)"; } @custommanagers));
5592: } else {
5593: $output .= &mt('Currently author manages co-author roles');
5594: }
5595: }
5596: $output .= "</p>\n";
5597: if (@possmanagers) {
1.472 raeburn 5598: $output .= '<p>'.&mt('If checked, can manage').': ';
1.470 raeburn 5599: foreach my $user (@possmanagers) {
5600: my $checked;
5601: if (grep(/^\Q$user\E$/,@custommanagers)) {
5602: $checked = ' checked="checked"';
5603: }
5604: $output .= '<span style="LC_nobreak"><label>'.
5605: '<input type="checkbox" name="custommanagers" '.
5606: 'value="'.&HTML::Entities::encode($user,'\'<>"&').'"'.$checked.' />'.
5607: &Apache::loncommon::plainname(split(/:/,$user))." ($user)".'</label></span> '."\n";
5608: }
5609: $output .= '<input type="hidden" name="state" value="process" /></p>'."\n".
5610: '<p><input type="submit" value="'.&mt('Save changes').'" /></p>'."\n";
5611: } else {
5612: $output .= '<p>'.&mt('No co-author roles assignable as manager').'</p>';
5613: }
5614: $output .= '</form>';
5615: } else {
5616: $output = '<span class="LC_warning">'.
5617: &mt('You do not have permission to perform this action').
5618: '</span>';
5619: }
5620: return $output;
5621: }
5622:
5623: sub update_coauthor_managers {
5624: my ($permission) = @_;
5625: my $output;
5626: if ((ref($permission) eq 'HASH') && ($permission->{'author'})) {
5627: my ($current,$newval,@possibles,@managers);
5628: my %userenv =
5629: &Apache::lonnet::userenvironment($env{'user.domain'},
5630: $env{'user.name'},
5631: 'authormanagers');
5632: $current = $userenv{'authormanagers'};
5633: @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
5634: if (@possibles) {
5635: my %ca_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5636: ['active','future'],['ca']);
5637: if (keys(%ca_roles)) {
5638: foreach my $user (@possibles) {
5639: if ($user =~ /^($match_username):($match_domain)$/) {
5640: if (exists($ca_roles{$user.':ca'})) {
5641: unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5642: push(@managers,$user);
5643: }
5644: }
5645: }
5646: }
5647: if (@managers) {
5648: $newval = join(',',sort(@managers));
5649: }
5650: }
5651: }
5652: if ($current eq $newval) {
5653: $output = &mt('No changes made to management of co-author roles');
5654: } else {
5655: my $chgresult =
5656: &Apache::lonnet::put('environment',{'authormanagers' => $newval},
5657: $env{'user.domain'},$env{'user.name'});
5658: if ($chgresult eq 'ok') {
5659: &Apache::lonnet::appenv({'environment.authormanagers' => $newval});
5660: my (@adds,@dels);
5661: if ($newval eq '') {
5662: @dels = split(/,/,$current);
5663: } elsif ($current eq '') {
5664: @adds = @managers;
5665: } else {
5666: my @old = split(/,/,$current);
5667: my @diffs = &Apache::loncommon::compare_arrays(\@old,\@managers);
5668: if (@diffs) {
5669: foreach my $user (@diffs) {
5670: if (grep(/^\Q$user\E$/,@old)) {
5671: push(@dels,$user);
5672: } elsif (grep(/^\Q$user\E$/,@managers)) {
5673: push(@adds,$user);
5674: }
5675: }
5676: }
5677: }
5678: my $key = "internal.manager./$env{'user.domain'}/$env{'user.name'}";
5679: if (@dels) {
5680: foreach my $user (@dels) {
5681: if ($user =~ /^($match_username):($match_domain)$/) {
5682: &Apache::lonnet::del('environment',[$key],$2,$1);
5683: }
5684: }
5685: }
5686: if (@adds) {
5687: foreach my $user (@adds) {
5688: if ($user =~ /^($match_username):($match_domain)$/) {
5689: &Apache::lonnet::put('environment',{$key => 1},$2,$1);
5690: }
5691: }
5692: }
5693: if ($newval eq '') {
5694: $output = &mt('Management of co-authors set to be author-only');
5695: } else {
5696: $output .= &mt('Co-authors who can manage co-author roles set to: [_1]',
5697: '<br />'.join(', ',map { &Apache::loncommon::plainname(split(':',$_))." ($_)"; } @managers));
5698: }
5699: }
5700: }
5701: } else {
5702: $output = '<span class="LC_warning">'.
5703: &mt('You do not have permission to perform this action').
5704: '</span>';
5705: }
5706: return $output;
5707: }
5708:
1.2 www 5709: # ================================================================ Main Handler
5710: sub handler {
5711: my $r = shift;
5712: if ($r->header_only) {
1.68 www 5713: &Apache::loncommon::content_type($r,'text/html');
1.2 www 5714: $r->send_http_header;
5715: return OK;
5716: }
1.439 raeburn 5717: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
5718:
1.190 raeburn 5719: if ($env{'request.course.id'}) {
5720: $context = 'course';
1.318 raeburn 5721: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 5722: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 5723: $context = 'author';
1.470 raeburn 5724: } elsif ($env{'request.role'} =~ m{^(ca|aa)\./$match_domain/$match_username$}) {
5725: $context = 'coauthor';
1.190 raeburn 5726: } else {
5727: $context = 'domain';
5728: }
1.375 raeburn 5729:
1.439 raeburn 5730: my ($permission,$allowed) =
5731: &Apache::lonuserutils::get_permission($context,$crstype);
1.470 raeburn 5732: if (($context eq 'coauthor') && ($allowed)) {
5733: $context = 'author';
5734: }
1.439 raeburn 5735:
5736: if ($allowed) {
5737: my @allhelp;
5738: if ($context eq 'course') {
5739: $cid = $env{'request.course.id'};
5740: $cdom = $env{'course.'.$cid.'.domain'};
5741: $cnum = $env{'course.'.$cid.'.num'};
5742:
5743: if ($permission->{'cusr'}) {
5744: push(@allhelp,'Course_Create_Class_List');
5745: }
5746: if ($permission->{'view'} || $permission->{'cusr'}) {
5747: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
5748: }
5749: if ($permission->{'custom'}) {
5750: push(@allhelp,'Course_Editing_Custom_Roles');
5751: }
5752: if ($permission->{'cusr'}) {
5753: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
5754: }
5755: unless ($permission->{'cusr_section'}) {
5756: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
5757: push(@allhelp,'Course_Automated_Enrollment');
5758: }
1.469 raeburn 5759: if (($permission->{'selfenrolladmin'}) || ($permission->{'selfenrollview'})) {
1.439 raeburn 5760: push(@allhelp,'Course_Approve_Selfenroll');
5761: }
5762: }
5763: if ($permission->{'grp_manage'}) {
5764: push(@allhelp,'Course_Manage_Group');
5765: }
5766: if ($permission->{'view'} || $permission->{'cusr'}) {
5767: push(@allhelp,'Course_User_Logs');
5768: }
5769: } elsif ($context eq 'author') {
5770: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
5771: 'Author_View_Coauthor_List','Author_User_Logs'));
1.470 raeburn 5772: } elsif ($context eq 'coauthor') {
5773: if ($permission->{'cusr'}) {
5774: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
5775: 'Author_View_Coauthor_List','Author_User_Logs'));
5776: } elsif ($permission->{'view'}) {
5777: push(@allhelp,'Author_View_Coauthor_List');
5778: }
1.439 raeburn 5779: } else {
5780: if ($permission->{'cusr'}) {
5781: push(@allhelp,'Domain_Change_Privileges');
5782: if ($permission->{'activity'}) {
5783: push(@allhelp,'Domain_User_Access_Logs');
5784: }
5785: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
5786: if ($permission->{'custom'}) {
5787: push(@allhelp,'Domain_Editing_Custom_Roles');
5788: }
5789: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
5790: } elsif ($permission->{'view'}) {
5791: push(@allhelp,'Domain_View_Privileges');
5792: if ($permission->{'activity'}) {
5793: push(@allhelp,'Domain_User_Access_Logs');
5794: }
5795: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
5796: }
5797: }
5798: if (@allhelp) {
5799: $allhelpitems = join(',',@allhelp);
5800: }
5801: }
5802:
1.190 raeburn 5803: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 5804: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.470 raeburn 5805: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue',
5806: 'forceedit']);
1.190 raeburn 5807: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 5808: my $args;
5809: my $brcrum = [];
5810: my $bread_crumbs_component = 'User Management';
1.391 raeburn 5811: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 5812: $brcrum = [{href=>"/adm/createuser",
5813: text=>"User Management",
1.439 raeburn 5814: help=>$allhelpitems}
1.351 raeburn 5815: ];
1.202 raeburn 5816: }
1.190 raeburn 5817: if (!$allowed) {
1.358 raeburn 5818: if ($context eq 'course') {
5819: $r->internal_redirect('/adm/viewclasslist');
5820: return OK;
1.470 raeburn 5821: } elsif ($context eq 'coauthor') {
5822: $r->internal_redirect('/adm/viewcoauthors');
5823: return OK;
1.358 raeburn 5824: }
1.190 raeburn 5825: $env{'user.error.msg'}=
5826: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
5827: "or view user status.";
5828: return HTTP_NOT_ACCEPTABLE;
5829: }
5830:
5831: &Apache::loncommon::content_type($r,'text/html');
5832: $r->send_http_header;
5833:
1.375 raeburn 5834: my $showcredits;
5835: if ((($context eq 'course') && ($crstype eq 'Course')) ||
5836: ($context eq 'domain')) {
5837: my %domdefaults =
5838: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
5839: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
5840: $showcredits = 1;
5841: }
5842: }
5843:
1.190 raeburn 5844: # Main switch on form.action and form.state, as appropriate
5845: if (! exists($env{'form.action'})) {
1.351 raeburn 5846: $args = {bread_crumbs => $brcrum,
5847: bread_crumbs_component => $bread_crumbs_component};
5848: $r->print(&header(undef,$args));
1.318 raeburn 5849: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5850: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 5851: my $helpitem = 'Course_Create_Class_List';
5852: if ($context eq 'author') {
5853: $helpitem = 'Author_Create_Coauthor_List';
5854: } elsif ($context eq 'domain') {
5855: $helpitem = 'Domain_Create_Users';
5856: }
1.351 raeburn 5857: push(@{$brcrum},
5858: { href => '/adm/createuser?action=upload&state=',
5859: text => 'Upload Users List',
1.439 raeburn 5860: help => $helpitem,
1.351 raeburn 5861: });
5862: $bread_crumbs_component = 'Upload Users List';
5863: $args = {bread_crumbs => $brcrum,
5864: bread_crumbs_component => $bread_crumbs_component};
5865: $r->print(&header(undef,$args));
1.190 raeburn 5866: $r->print('<form name="studentform" method="post" '.
5867: 'enctype="multipart/form-data" '.
5868: ' action="/adm/createuser">'."\n");
5869: if (! exists($env{'form.state'})) {
5870: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5871: } elsif ($env{'form.state'} eq 'got_file') {
1.448 raeburn 5872: my $result =
5873: &Apache::lonuserutils::print_upload_manager_form($r,$context,
5874: $permission,
5875: $crstype,$showcredits);
5876: if ($result eq 'missingdata') {
5877: delete($env{'form.state'});
5878: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5879: }
1.190 raeburn 5880: } elsif ($env{'form.state'} eq 'enrolling') {
5881: if ($env{'form.datatoken'}) {
1.448 raeburn 5882: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
5883: $permission,
5884: $showcredits);
5885: if ($result eq 'missingdata') {
5886: delete($env{'form.state'});
5887: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5888: } elsif ($result eq 'invalidhome') {
5889: $env{'form.state'} = 'got_file';
5890: delete($env{'form.lcserver'});
5891: my $result =
5892: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
5893: $crstype,$showcredits);
5894: if ($result eq 'missingdata') {
5895: delete($env{'form.state'});
5896: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5897: }
5898: }
5899: } else {
5900: delete($env{'form.state'});
5901: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 5902: }
5903: } else {
5904: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5905: }
1.447 raeburn 5906: $r->print('</form>');
1.416 raeburn 5907: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
5908: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 5909: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 5910: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 5911: my $phase = $env{'form.phase'};
5912: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 5913: &Apache::loncreateuser::restore_prev_selections();
5914: my $srch;
5915: foreach my $item (@search) {
5916: $srch->{$item} = $env{'form.'.$item};
5917: }
1.207 raeburn 5918: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 5919: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 5920: if ($env{'form.phase'} eq 'createnewuser') {
5921: my $response;
5922: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 5923: my $response =
5924: '<span class="LC_warning">'
5925: .&mt('You must specify a valid username. Only the following are allowed:'
5926: .' letters numbers - . @')
5927: .'</span>';
1.221 raeburn 5928: $env{'form.phase'} = '';
1.375 raeburn 5929: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 5930: $crstype,$brcrum,$permission);
1.207 raeburn 5931: } else {
5932: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
5933: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
5934: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 5935: $srch,$response,$context,
1.375 raeburn 5936: $permission,$crstype,$brcrum,
5937: $showcredits);
1.207 raeburn 5938: }
5939: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 5940: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 5941: &user_search_result($context,$srch);
1.190 raeburn 5942: if ($env{'form.currstate'} eq 'modify') {
5943: $currstate = $env{'form.currstate'};
5944: }
5945: if ($currstate eq 'select') {
5946: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 5947: \@search,$context,undef,$crstype,
5948: $brcrum);
1.416 raeburn 5949: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
5950: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 5951: if (($srch->{'srchby'} eq 'uname') &&
5952: ($srch->{'srchtype'} eq 'exact')) {
5953: $ccuname = $srch->{'srchterm'};
5954: $ccdomain= $srch->{'srchdomain'};
5955: } else {
5956: my @matchedunames = keys(%{$results});
5957: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
5958: }
5959: $ccuname =&LONCAPA::clean_username($ccuname);
5960: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 5961: if ($env{'form.action'} eq 'accesslogs') {
5962: my $uhome;
5963: if (($ccuname ne '') && ($ccdomain ne '')) {
5964: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
5965: }
5966: if (($uhome eq '') || ($uhome eq 'no_host')) {
5967: $env{'form.phase'} = '';
5968: undef($forcenewuser);
5969: #if ($response) {
5970: # unless ($response =~ m{\Q<br /><br />\E$}) {
5971: # $response .= '<br /><br />';
5972: # }
5973: #}
5974: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 5975: $forcenewuser,$crstype,$brcrum,
5976: $permission);
1.416 raeburn 5977: } else {
5978: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
5979: }
5980: } else {
5981: if ($env{'form.forcenewuser'}) {
5982: $response = '';
5983: }
5984: &print_user_modification_page($r,$ccuname,$ccdomain,
5985: $srch,$response,$context,
5986: $permission,$crstype,$brcrum);
1.190 raeburn 5987: }
5988: } elsif ($currstate eq 'query') {
1.351 raeburn 5989: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 5990: } else {
1.229 raeburn 5991: $env{'form.phase'} = '';
1.207 raeburn 5992: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 5993: $forcenewuser,$crstype,$brcrum,
5994: $permission);
1.190 raeburn 5995: }
5996: } elsif ($env{'form.phase'} eq 'userpicked') {
5997: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
5998: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 5999: if ($env{'form.action'} eq 'accesslogs') {
6000: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
6001: } else {
6002: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
6003: $context,$permission,$crstype,
6004: $brcrum);
6005: }
6006: } elsif ($env{'form.action'} eq 'accesslogs') {
6007: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
6008: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
6009: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 6010: }
6011: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.451 raeburn 6012: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 6013: } else {
1.351 raeburn 6014: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 6015: $brcrum,$permission);
1.190 raeburn 6016: }
6017: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 6018: my $prefix;
1.190 raeburn 6019: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 6020: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 6021: } else {
1.439 raeburn 6022: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 6023: }
1.362 raeburn 6024: } elsif (($env{'form.action'} eq 'processauthorreq') &&
6025: ($permission->{'cusr'}) &&
6026: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
6027: push(@{$brcrum},
6028: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 6029: text => 'Authoring Space requests',
1.362 raeburn 6030: help => 'Domain_Role_Approvals'});
6031: $bread_crumbs_component = 'Authoring requests';
6032: if ($env{'form.state'} eq 'done') {
6033: push(@{$brcrum},
6034: {href => '/adm/createuser?action=authorreqqueue',
6035: text => 'Result',
6036: help => 'Domain_Role_Approvals'});
6037: $bread_crumbs_component = 'Authoring request result';
6038: }
6039: $args = { bread_crumbs => $brcrum,
6040: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 6041: my $js = &usernamerequest_javascript();
6042: $r->print(&header(&add_script($js),$args));
1.362 raeburn 6043: if (!exists($env{'form.state'})) {
6044: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
6045: $env{'request.role.domain'}));
6046: } elsif ($env{'form.state'} eq 'done') {
6047: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
6048: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
6049: $env{'request.role.domain'}));
6050: }
1.391 raeburn 6051: } elsif (($env{'form.action'} eq 'processusernamereq') &&
6052: ($permission->{'cusr'}) &&
6053: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
6054: push(@{$brcrum},
6055: {href => '/adm/createuser?action=processusernamereq',
6056: text => 'LON-CAPA account requests',
6057: help => 'Domain_Username_Approvals'});
6058: $bread_crumbs_component = 'Account requests';
6059: if ($env{'form.state'} eq 'done') {
6060: push(@{$brcrum},
6061: {href => '/adm/createuser?action=usernamereqqueue',
6062: text => 'Result',
6063: help => 'Domain_Username_Approvals'});
6064: $bread_crumbs_component = 'LON-CAPA account request result';
6065: }
6066: $args = { bread_crumbs => $brcrum,
6067: bread_crumbs_component => $bread_crumbs_component};
6068: my $js = &usernamerequest_javascript();
6069: $r->print(&header(&add_script($js),$args));
6070: if (!exists($env{'form.state'})) {
6071: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
6072: $env{'request.role.domain'}));
6073: } elsif ($env{'form.state'} eq 'done') {
6074: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
6075: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
6076: $env{'request.role.domain'}));
6077: }
6078: } elsif (($env{'form.action'} eq 'displayuserreq') &&
6079: ($permission->{'cusr'})) {
6080: my $dom = $env{'form.domain'};
6081: my $uname = $env{'form.username'};
6082: my $warning;
6083: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
6084: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
6085: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
6086: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
6087: if ($uhome eq 'no_host') {
6088: my $queue = $env{'form.queue'};
6089: my $reqkey = &escape($uname).'_'.$queue;
6090: my $namespace = 'usernamequeue';
6091: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
6092: my %queued =
6093: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
6094: unless ($queued{$reqkey}) {
6095: $warning = &mt('No information was found for this LON-CAPA account request.');
6096: }
6097: } else {
6098: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
6099: }
6100: } else {
6101: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
6102: }
6103: } else {
6104: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
6105: }
6106: } else {
6107: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
6108: }
6109: my $args = { only_body => 1 };
6110: $r->print(&header(undef,$args).
6111: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
6112: if ($warning ne '') {
6113: $r->print('<div class="LC_warning">'.$warning.'</div>');
6114: } else {
6115: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
6116: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
6117: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6118: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6119: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
6120: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
6121: my %info =
6122: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
6123: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 6124: my $usertype = $info{$uname}{'inststatus'};
6125: unless ($usertype) {
6126: $usertype = 'default';
6127: }
1.442 raeburn 6128: my ($showstatus,$showemail,$pickstart);
6129: my $numextras = 0;
6130: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.443 raeburn 6131: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
6132: if (ref($usertypes) eq 'HASH') {
6133: if ($usertypes->{$usertype}) {
6134: $showstatus = $usertypes->{$usertype};
6135: } else {
6136: $showstatus = $othertitle;
6137: }
6138: if ($showstatus) {
6139: $numextras ++;
6140: }
1.442 raeburn 6141: }
6142: }
6143: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
6144: $showemail = $info{$uname}{'email'};
6145: $numextras ++;
6146: }
1.396 raeburn 6147: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
6148: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.442 raeburn 6149: $pickstart = 1;
1.396 raeburn 6150: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.442 raeburn 6151: my ($num,$count);
1.396 raeburn 6152: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.442 raeburn 6153: $count += $numextras;
1.396 raeburn 6154: foreach my $field (@{$infofields}) {
6155: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
6156: next unless ($infotitles->{$field});
6157: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
6158: $info{$uname}{$field});
6159: $num ++;
1.442 raeburn 6160: unless ($count == $num) {
1.396 raeburn 6161: $r->print(&Apache::lonhtmlcommon::row_closure());
6162: }
6163: }
1.442 raeburn 6164: }
6165: }
6166: if ($numextras) {
6167: unless ($pickstart) {
6168: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
6169: $pickstart = 1;
6170: }
6171: if ($showemail) {
6172: my $closure = '';
6173: unless ($showstatus) {
6174: $closure = 1;
1.391 raeburn 6175: }
1.442 raeburn 6176: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
6177: $showemail.
6178: &Apache::lonhtmlcommon::row_closure($closure));
1.391 raeburn 6179: }
1.442 raeburn 6180: if ($showstatus) {
6181: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
6182: $showstatus.
6183: &Apache::lonhtmlcommon::row_closure(1));
6184: }
6185: }
6186: if ($pickstart) {
6187: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
6188: } else {
6189: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
1.391 raeburn 6190: }
1.442 raeburn 6191: } else {
6192: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 6193: }
6194: }
6195: }
6196: }
6197: }
1.442 raeburn 6198: $r->print(&close_popup_form());
1.207 raeburn 6199: } elsif (($env{'form.action'} eq 'listusers') &&
6200: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 6201: my $helpitem = 'Course_View_Class_List';
6202: if ($context eq 'author') {
6203: $helpitem = 'Author_View_Coauthor_List';
6204: } elsif ($context eq 'domain') {
6205: $helpitem = 'Domain_View_Users_List';
6206: }
1.202 raeburn 6207: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 6208: push(@{$brcrum},
6209: {href => '/adm/createuser?action=listusers',
6210: text => "List Users"},
6211: {href => "/adm/createuser",
6212: text => "Result",
1.439 raeburn 6213: help => $helpitem});
1.351 raeburn 6214: $bread_crumbs_component = 'Update Users';
6215: $args = {bread_crumbs => $brcrum,
6216: bread_crumbs_component => $bread_crumbs_component};
6217: $r->print(&header(undef,$args));
1.202 raeburn 6218: my $setting = $env{'form.roletype'};
6219: my $choice = $env{'form.bulkaction'};
6220: if ($permission->{'cusr'}) {
1.336 raeburn 6221: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 6222: } else {
6223: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 6224: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 6225: }
6226: } else {
1.351 raeburn 6227: push(@{$brcrum},
6228: {href => '/adm/createuser?action=listusers',
6229: text => "List Users",
1.439 raeburn 6230: help => $helpitem});
1.351 raeburn 6231: $bread_crumbs_component = 'List Users';
6232: $args = {bread_crumbs => $brcrum,
6233: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 6234: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
6235: my $formname = 'studentform';
1.364 raeburn 6236: my $hidecall = "hide_searching();";
1.321 raeburn 6237: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
6238: ($env{'form.roletype'} eq 'community'))) {
6239: if ($env{'form.roletype'} eq 'course') {
6240: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
6241: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
6242: $formname);
6243: } elsif ($env{'form.roletype'} eq 'community') {
6244: $cb_jscript =
6245: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
6246: my %elements = (
6247: coursepick => 'radio',
6248: coursetotal => 'text',
6249: courselist => 'text',
6250: );
6251: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
6252: }
1.364 raeburn 6253: $jscript .= &verify_user_display($context)."\n".
6254: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 6255: my $js = &add_script($jscript).$cb_jscript;
6256: my $loadcode =
6257: &Apache::lonuserutils::course_selector_loadcode($formname);
6258: if ($loadcode ne '') {
1.364 raeburn 6259: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
6260: } else {
6261: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 6262: }
1.351 raeburn 6263: $r->print(&header($js,$args));
1.191 raeburn 6264: } else {
1.364 raeburn 6265: $args->{add_entries} = {onload => $hidecall};
6266: $jscript = &verify_user_display($context).
6267: &Apache::loncommon::check_uncheck_jscript();
6268: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 6269: }
1.202 raeburn 6270: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 6271: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
6272: $showcredits);
1.191 raeburn 6273: }
1.213 raeburn 6274: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 6275: my $brtext;
6276: if ($crstype eq 'Community') {
6277: $brtext = 'Drop Members';
6278: } else {
6279: $brtext = 'Drop Students';
6280: }
1.351 raeburn 6281: push(@{$brcrum},
6282: {href => '/adm/createuser?action=drop',
6283: text => $brtext,
6284: help => 'Course_Drop_Student'});
6285: if ($env{'form.state'} eq 'done') {
6286: push(@{$brcrum},
6287: {href=>'/adm/createuser?action=drop',
6288: text=>"Result"});
6289: }
6290: $bread_crumbs_component = $brtext;
6291: $args = {bread_crumbs => $brcrum,
6292: bread_crumbs_component => $bread_crumbs_component};
6293: $r->print(&header(undef,$args));
1.213 raeburn 6294: if (!exists($env{'form.state'})) {
1.318 raeburn 6295: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 6296: } elsif ($env{'form.state'} eq 'done') {
6297: &Apache::lonuserutils::update_user_list($r,$context,undef,
6298: $env{'form.action'});
6299: }
1.202 raeburn 6300: } elsif ($env{'form.action'} eq 'dateselect') {
6301: if ($permission->{'cusr'}) {
1.351 raeburn 6302: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 6303: &Apache::lonuserutils::date_section_selector($context,$permission,
6304: $crstype,$showcredits));
1.202 raeburn 6305: } else {
1.351 raeburn 6306: $r->print(&header(undef,{'no_nav_bar' => 1}).
6307: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 6308: }
1.237 raeburn 6309: } elsif ($env{'form.action'} eq 'selfenroll') {
1.469 raeburn 6310: my %currsettings;
6311: if ($permission->{selfenrolladmin} || $permission->{selfenrollview}) {
6312: %currsettings = (
1.398 raeburn 6313: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
6314: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
6315: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
6316: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
6317: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
6318: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
6319: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
6320: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
6321: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
6322: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
6323: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
6324: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
6325: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 6326: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 6327: );
1.469 raeburn 6328: }
6329: if ($permission->{selfenrolladmin}) {
1.398 raeburn 6330: push(@{$brcrum},
6331: {href => '/adm/createuser?action=selfenroll',
6332: text => "Configure Self-enrollment",
6333: help => 'Course_Self_Enrollment'});
6334: if (!exists($env{'form.state'})) {
6335: $args = { bread_crumbs => $brcrum,
6336: bread_crumbs_component => 'Configure Self-enrollment'};
6337: $r->print(&header(undef,$args));
6338: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
6339: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
6340: } elsif ($env{'form.state'} eq 'done') {
6341: push (@{$brcrum},
6342: {href=>'/adm/createuser?action=selfenroll',
6343: text=>"Result"});
6344: $args = { bread_crumbs => $brcrum,
6345: bread_crumbs_component => 'Self-enrollment result'};
6346: $r->print(&header(undef,$args));
6347: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 6348: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 6349: }
1.469 raeburn 6350: } elsif ($permission->{selfenrollview}) {
6351: push(@{$brcrum},
6352: {href => '/adm/createuser?action=selfenroll',
6353: text => "View Self-enrollment configuration",
6354: help => 'Course_Self_Enrollment'});
6355: $args = { bread_crumbs => $brcrum,
6356: bread_crumbs_component => 'Self-enrollment Settings'};
6357: $r->print(&header(undef,$args));
6358: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
6359: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings,'',1);
1.398 raeburn 6360: } else {
6361: $r->print(&header(undef,{'no_nav_bar' => 1}).
6362: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 6363: }
1.277 raeburn 6364: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 6365: if ($permission->{selfenrolladmin}) {
1.351 raeburn 6366: push(@{$brcrum},
6367: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 6368: text => 'Enrollment requests',
1.439 raeburn 6369: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 6370: $bread_crumbs_component = 'Enrollment requests';
6371: if ($env{'form.state'} eq 'done') {
6372: push(@{$brcrum},
6373: {href => '/adm/createuser?action=selfenrollqueue',
6374: text => 'Result',
1.439 raeburn 6375: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 6376: $bread_crumbs_component = 'Enrollment result';
6377: }
6378: $args = { bread_crumbs => $brcrum,
6379: bread_crumbs_component => $bread_crumbs_component};
6380: $r->print(&header(undef,$args));
6381: my $coursedesc = $env{'course.'.$cid.'.description'};
6382: if (!exists($env{'form.state'})) {
6383: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
6384: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
6385: $cdom,$cnum));
6386: } elsif ($env{'form.state'} eq 'done') {
6387: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
6388: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 6389: $cdom,$cnum,$coursedesc));
1.418 raeburn 6390: }
6391: } else {
6392: $r->print(&header(undef,{'no_nav_bar' => 1}).
6393: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 6394: }
1.418 raeburn 6395: } elsif ($env{'form.action'} eq 'changelogs') {
6396: if ($permission->{cusr} || $permission->{view}) {
6397: &print_userchangelogs_display($r,$context,$permission,$brcrum);
6398: } else {
6399: $r->print(&header(undef,{'no_nav_bar' => 1}).
6400: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 6401: }
1.428 raeburn 6402: } elsif ($env{'form.action'} eq 'helpdesk') {
1.464 raeburn 6403: if (($permission->{'owner'} || $permission->{'co-owner'}) &&
6404: ($permission->{'cusr'} || $permission->{'view'})) {
1.428 raeburn 6405: if ($env{'form.state'} eq 'process') {
6406: if ($permission->{'owner'}) {
6407: &update_helpdeskaccess($r,$permission,$brcrum);
6408: } else {
6409: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 6410: }
1.428 raeburn 6411: } else {
6412: &print_helpdeskaccess_display($r,$permission,$brcrum);
6413: }
6414: } else {
6415: $r->print(&header(undef,{'no_nav_bar' => 1}).
6416: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
6417: }
1.465 raeburn 6418: } elsif ($env{'form.action'} eq 'rolerequests') {
6419: if ($permission->{cusr} || $permission->{view}) {
6420: &print_queued_roles($r,$context,$permission,$brcrum);
6421: }
6422: } elsif ($env{'form.action'} eq 'queuedroles') {
6423: if (($permission->{cusr}) && ($context eq 'domain')) {
6424: if (&show_role_requests($context,$env{'request.role.domain'})) {
6425: if ($env{'form.state'} eq 'done') {
6426: &process_pendingroles($r,$context,$permission,$brcrum);
6427: } else {
6428: &print_pendingroles($r,$context,$permission,$brcrum);
6429: }
6430: } else {
6431: $r->print(&header(undef,{'no_nav_bar' => 1}).
6432: '<span class="LC_info">'.&mt('Domain coordinator approval of requests from other domains for assignment of roles to users from this domain not in use.').'</span>');
6433: }
6434: } else {
6435: $r->print(&header(undef,{'no_nav_bar' => 1}).
6436: '<span class="LC_error">'.&mt('You do not have permission to view queued requests from other domains for assignment of roles to users from this domain.').'</span>');
6437: }
1.470 raeburn 6438: } elsif ($env{'form.action'} eq 'camanagers') {
6439: if (($permission->{cusr}) && ($context eq 'author')) {
6440: push(@{$brcrum},
6441: {href => '/adm/createuser?action=camanagers',
1.473 raeburn 6442: text => 'Co-author Managers',
1.470 raeburn 6443: help => 'Author_Manage_Coauthors'});
6444: if ($env{'form.state'} eq 'process') {
6445: push(@{$brcrum},
6446: {href => '/adm/createuser?action=camanagers',
6447: text => 'Result',
6448: help => 'Author_Manage_Coauthors'});
6449: }
6450: $args = { bread_crumbs => $brcrum };
6451: $r->print(&header(undef,$args));
6452: my $coursedesc = $env{'course.'.$cid.'.description'};
6453: if (!exists($env{'form.state'})) {
6454: $r->print('<h3>'.&mt('Co-author Management').'</h3>'."\n".
6455: &display_coauthor_managers($permission));
6456: } elsif ($env{'form.state'} eq 'process') {
6457: $r->print('<h3>'.&mt('Co-author Management Update Result').'</h3>'."\n".
6458: &update_coauthor_managers($permission));
6459: }
6460: }
6461: } elsif (($env{'form.action'} eq 'calist') && ($context eq 'author')) {
6462: if ($permission->{'cusr'}) {
6463: my ($role,$audom,$auname,$canview,$canedit) =
6464: &Apache::lonviewcoauthors::get_allowable();
6465: if (($canedit) && ($env{'form.forceedit'})) {
6466: &Apache::lonviewcoauthors::get_editor_crumbs($brcrum,'/adm/createuser');
6467: my $args = { 'bread_crumbs' => $brcrum };
6468: $r->print(&Apache::loncommon::start_page('Configure co-author listing',undef,
6469: $args).
6470: &Apache::lonviewcoauthors::edit_settings($audom,$auname,$role,
6471: '/adm/createuser'));
6472: } else {
6473: push(@{$brcrum},
6474: {href => '/adm/createuser?action=calist',
6475: text => 'Coauthor-viewable list',
6476: help => 'Author_List_Coauthors'});
6477: my $args = { 'bread_crumbs' => $brcrum };
6478: $r->print(&Apache::loncommon::start_page('Coauthor-viewable list',undef,
6479: $args));
6480: my %viewsettings =
6481: &Apache::lonviewcoauthors::retrieve_view_settings($auname,$audom,$role);
6482: if ($viewsettings{'show'} eq 'none') {
6483: $r->print('<h3>'.&mt('Coauthor-viewable listing').'</h3>'.
6484: '<p class="LC_info">'.
6485: &mt('Listing of co-authors not enabled for this Authoring Space').
6486: '</p>');
6487: } else {
6488: &Apache::lonviewcoauthors::print_coauthors($r,$auname,$audom,$role,
6489: '/adm/createuser',\%viewsettings);
6490: }
6491: }
6492: } else {
6493: $r->internal_redirect('/adm/viewcoauthors');
6494: return OK;
6495: }
1.481 raeburn 6496: } elsif (($env{'form.action'} eq 'setenv') && ($context eq 'author')) {
6497: my ($role,$audom,$auname,$canview,$canedit) =
6498: &Apache::lonviewcoauthors::get_allowable();
6499: push(@{$brcrum},
6500: {href => '/adm/createuser?action=calist',
6501: text => 'Coauthor-viewable list',
6502: help => 'Author_List_Coauthors'});
6503: my $args = { 'bread_crumbs' => $brcrum };
6504: $r->print(&Apache::loncommon::start_page('Coauthor-viewable list',undef,
6505: $args));
6506: my %viewsettings =
6507: &Apache::lonviewcoauthors::retrieve_view_settings($auname,$audom,$role);
6508: if ($viewsettings{'show'} eq 'none') {
6509: $r->print('<h3>'.&mt('Coauthor-viewable listing').'</h3>'.
6510: '<p class="LC_info">'.
6511: &mt('Listing of co-authors not enabled for this Authoring Space').
6512: '</p>');
6513: } else {
6514: &Apache::lonviewcoauthors::print_coauthors($r,$auname,$audom,$role,
6515: '/adm/createuser',\%viewsettings);
6516: }
1.190 raeburn 6517: } else {
1.351 raeburn 6518: $bread_crumbs_component = 'User Management';
6519: $args = { bread_crumbs => $brcrum,
6520: bread_crumbs_component => $bread_crumbs_component};
6521: $r->print(&header(undef,$args));
1.318 raeburn 6522: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 6523: }
1.351 raeburn 6524: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 6525: return OK;
6526: }
6527:
6528: sub header {
1.351 raeburn 6529: my ($jscript,$args) = @_;
1.190 raeburn 6530: my $start_page;
1.351 raeburn 6531: if (ref($args) eq 'HASH') {
6532: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 6533: } else {
1.351 raeburn 6534: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 6535: }
6536: return $start_page;
6537: }
1.2 www 6538:
1.191 raeburn 6539: sub add_script {
6540: my ($js) = @_;
1.301 bisitz 6541: return '<script type="text/javascript">'."\n"
6542: .'// <![CDATA['."\n"
6543: .$js."\n"
6544: .'// ]]>'."\n"
6545: .'</script>'."\n";
1.191 raeburn 6546: }
6547:
1.391 raeburn 6548: sub usernamerequest_javascript {
6549: my $js = <<ENDJS;
6550:
6551: function openusernamereqdisplay(dom,uname,queue) {
6552: var url = '/adm/createuser?action=displayuserreq';
6553: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
6554: var title = 'Account_Request_Browser';
6555: var options = 'scrollbars=1,resizable=1,menubar=0';
6556: options += ',width=700,height=600';
6557: var stdeditbrowser = open(url,title,options,'1');
6558: stdeditbrowser.focus();
6559: return;
6560: }
6561:
6562: ENDJS
6563: }
6564:
6565: sub close_popup_form {
6566: my $close= &mt('Close Window');
6567: return << "END";
6568: <p><form name="displayreq" action="" method="post">
6569: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
6570: </form></p>
6571: END
6572: }
6573:
1.202 raeburn 6574: sub verify_user_display {
1.364 raeburn 6575: my ($context) = @_;
1.374 raeburn 6576: my %lt = &Apache::lonlocal::texthash (
6577: course => 'course(s): description, section(s), status',
6578: community => 'community(s): description, section(s), status',
6579: author => 'author',
6580: );
1.364 raeburn 6581: my $photos;
6582: if (($context eq 'course') && $env{'request.course.id'}) {
6583: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
6584: }
1.202 raeburn 6585: my $output = <<"END";
6586:
1.364 raeburn 6587: function hide_searching() {
6588: if (document.getElementById('searching')) {
6589: document.getElementById('searching').style.display = 'none';
6590: }
6591: return;
6592: }
6593:
1.202 raeburn 6594: function display_update() {
6595: document.studentform.action.value = 'listusers';
6596: document.studentform.phase.value = 'display';
6597: document.studentform.submit();
6598: }
6599:
1.364 raeburn 6600: function updateCols(caller) {
6601: var context = '$context';
6602: var photos = '$photos';
6603: if (caller == 'Status') {
1.374 raeburn 6604: if ((context == 'domain') &&
6605: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
6606: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 6607: document.getElementById('showcolstatus').checked = false;
6608: document.getElementById('showcolstatus').disabled = 'disabled';
6609: document.getElementById('showcolstart').checked = false;
6610: document.getElementById('showcolend').checked = false;
1.374 raeburn 6611: } else {
6612: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
6613: document.getElementById('showcolstatus').checked = true;
6614: document.getElementById('showcolstatus').disabled = '';
6615: document.getElementById('showcolstart').checked = true;
6616: document.getElementById('showcolend').checked = true;
6617: } else {
6618: document.getElementById('showcolstatus').checked = false;
6619: document.getElementById('showcolstatus').disabled = 'disabled';
6620: document.getElementById('showcolstart').checked = false;
6621: document.getElementById('showcolend').checked = false;
6622: }
1.472 raeburn 6623: if (context == 'author') {
6624: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Expired') {
6625: document.getElementById('showcolmanager').checked = false;
6626: document.getElementById('showcolmanager').disabled = 'disabled';
6627: } else if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value != 'aa') {
6628: document.getElementById('showcolmanager').checked = true;
6629: document.getElementById('showcolmanager').disabled = '';
6630: }
6631: }
1.364 raeburn 6632: }
6633: }
6634: if (caller == 'output') {
6635: if (photos == 1) {
6636: if (document.getElementById('showcolphoto')) {
6637: var photoitem = document.getElementById('showcolphoto');
6638: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
6639: photoitem.checked = true;
6640: photoitem.disabled = '';
6641: } else {
6642: photoitem.checked = false;
6643: photoitem.disabled = 'disabled';
6644: }
6645: }
6646: }
6647: }
6648: if (caller == 'showrole') {
1.371 raeburn 6649: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
6650: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 6651: document.getElementById('showcolrole').checked = true;
6652: document.getElementById('showcolrole').disabled = '';
6653: } else {
6654: document.getElementById('showcolrole').checked = false;
6655: document.getElementById('showcolrole').disabled = 'disabled';
6656: }
1.374 raeburn 6657: if (context == 'domain') {
1.382 raeburn 6658: var quotausageshow = 0;
1.374 raeburn 6659: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
6660: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
6661: document.getElementById('showcolstatus').checked = false;
6662: document.getElementById('showcolstatus').disabled = 'disabled';
6663: document.getElementById('showcolstart').checked = false;
6664: document.getElementById('showcolend').checked = false;
6665: } else {
6666: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
6667: document.getElementById('showcolstatus').checked = true;
6668: document.getElementById('showcolstatus').disabled = '';
6669: document.getElementById('showcolstart').checked = true;
6670: document.getElementById('showcolend').checked = true;
6671: }
6672: }
6673: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
6674: document.getElementById('showcolextent').disabled = 'disabled';
6675: document.getElementById('showcolextent').checked = 'false';
6676: document.getElementById('showextent').style.display='none';
6677: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 6678: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
6679: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
6680: if (document.getElementById('showcolauthorusage')) {
6681: document.getElementById('showcolauthorusage').disabled = '';
6682: }
6683: if (document.getElementById('showcolauthorquota')) {
6684: document.getElementById('showcolauthorquota').disabled = '';
6685: }
6686: quotausageshow = 1;
6687: }
1.374 raeburn 6688: } else {
6689: document.getElementById('showextent').style.display='block';
6690: document.getElementById('showextent').style.textAlign='left';
6691: document.getElementById('showextent').style.textFace='normal';
6692: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
6693: document.getElementById('showcolextent').disabled = '';
6694: document.getElementById('showcolextent').checked = 'true';
6695: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
6696: } else {
6697: document.getElementById('showcolextent').disabled = '';
6698: document.getElementById('showcolextent').checked = 'true';
6699: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
6700: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
6701: } else {
6702: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
6703: }
6704: }
6705: }
1.382 raeburn 6706: if (quotausageshow == 0) {
6707: if (document.getElementById('showcolauthorusage')) {
6708: document.getElementById('showcolauthorusage').checked = false;
6709: document.getElementById('showcolauthorusage').disabled = 'disabled';
6710: }
6711: if (document.getElementById('showcolauthorquota')) {
6712: document.getElementById('showcolauthorquota').checked = false;
6713: document.getElementById('showcolauthorquota').disabled = 'disabled';
6714: }
6715: }
1.374 raeburn 6716: }
1.472 raeburn 6717: if (context == 'author') {
6718: if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'aa') {
6719: document.getElementById('showcolmanager').checked = false;
6720: document.getElementById('showcolmanager').disabled = 'disabled';
6721: } else if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value != 'Expired') {
6722: document.getElementById('showcolmanager').checked = true;
6723: document.getElementById('showcolmanager').disabled = '';
6724: }
6725: }
1.364 raeburn 6726: }
6727: return;
6728: }
6729:
1.202 raeburn 6730: END
6731: return $output;
6732:
6733: }
6734:
1.190 raeburn 6735: ###############################################################
6736: ###############################################################
6737: # Menu Phase One
6738: sub print_main_menu {
1.318 raeburn 6739: my ($permission,$context,$crstype) = @_;
6740: my $linkcontext = $context;
6741: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
6742: if (($context eq 'course') && ($crstype eq 'Community')) {
6743: $linkcontext = lc($crstype);
6744: $stuterm = 'Members';
6745: }
1.208 raeburn 6746: my %links = (
1.298 droeschl 6747: domain => {
6748: upload => 'Upload a File of Users',
6749: singleuser => 'Add/Modify a User',
6750: listusers => 'Manage Users',
6751: },
6752: author => {
6753: upload => 'Upload a File of Co-authors',
6754: singleuser => 'Add/Modify a Co-author',
6755: listusers => 'Manage Co-authors',
6756: },
6757: course => {
6758: upload => 'Upload a File of Course Users',
6759: singleuser => 'Add/Modify a Course User',
1.354 www 6760: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 6761: },
1.318 raeburn 6762: community => {
6763: upload => 'Upload a File of Community Users',
6764: singleuser => 'Add/Modify a Community User',
1.354 www 6765: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 6766: },
6767: );
6768: my %linktitles = (
6769: domain => {
6770: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
6771: listusers => 'Show and manage users in this domain.',
6772: },
6773: author => {
6774: singleuser => 'Add a user with a co- or assistant author role.',
6775: listusers => 'Show and manage co- or assistant authors.',
6776: },
6777: course => {
6778: singleuser => 'Add a user with a certain role to this course.',
6779: listusers => 'Show and manage users in this course.',
6780: },
6781: community => {
6782: singleuser => 'Add a user with a certain role to this community.',
6783: listusers => 'Show and manage users in this community.',
6784: },
1.298 droeschl 6785: );
1.465 raeburn 6786:
1.418 raeburn 6787: if ($linkcontext eq 'domain') {
6788: unless ($permission->{'cusr'}) {
1.430 raeburn 6789: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 6790: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
6791: }
6792: } elsif ($linkcontext eq 'course') {
6793: unless ($permission->{'cusr'}) {
6794: $links{'course'}{'singleuser'} = 'View a Course User';
6795: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
6796: $links{'course'}{'listusers'} = 'List Course Users';
6797: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
6798: }
6799: } elsif ($linkcontext eq 'community') {
6800: unless ($permission->{'cusr'}) {
6801: $links{'community'}{'singleuser'} = 'View a Community User';
6802: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
6803: $links{'community'}{'listusers'} = 'List Community Users';
6804: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
6805: }
6806: }
1.298 droeschl 6807: my @menu = ( {categorytitle => 'Single Users',
6808: items =>
6809: [
6810: {
1.318 raeburn 6811: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 6812: icon => 'edit-redo.png',
6813: #help => 'Course_Change_Privileges',
6814: url => '/adm/createuser?action=singleuser',
1.418 raeburn 6815: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 6816: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 6817: },
6818: ]},
6819:
6820: {categorytitle => 'Multiple Users',
6821: items =>
6822: [
6823: {
1.318 raeburn 6824: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 6825: icon => 'uplusr.png',
1.298 droeschl 6826: #help => 'Course_Create_Class_List',
6827: url => '/adm/createuser?action=upload',
6828: permission => $permission->{'cusr'},
6829: linktitle => 'Upload a CSV or a text file containing users.',
6830: },
6831: {
1.318 raeburn 6832: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 6833: icon => 'mngcu.png',
1.298 droeschl 6834: #help => 'Course_View_Class_List',
6835: url => '/adm/createuser?action=listusers',
6836: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 6837: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 6838: },
6839:
6840: ]},
6841:
6842: {categorytitle => 'Administration',
6843: items => [ ]},
6844: );
1.415 raeburn 6845:
1.265 mielkec 6846: if ($context eq 'domain'){
1.416 raeburn 6847: push(@{ $menu[0]->{items} }, # Single Users
6848: {
6849: linktext => 'User Access Log',
1.417 raeburn 6850: icon => 'document-properties.png',
1.425 raeburn 6851: #help => 'Domain_User_Access_Logs',
1.416 raeburn 6852: url => '/adm/createuser?action=accesslogs',
6853: permission => $permission->{'activity'},
6854: linktitle => 'View user access log.',
6855: }
6856: );
1.298 droeschl 6857:
6858: push(@{ $menu[2]->{items} }, #Category: Administration
6859: {
6860: linktext => 'Custom Roles',
6861: icon => 'emblem-photos.png',
6862: #help => 'Course_Editing_Custom_Roles',
6863: url => '/adm/createuser?action=custom',
6864: permission => $permission->{'custom'},
6865: linktitle => 'Configure a custom role.',
6866: },
1.362 raeburn 6867: {
6868: linktext => 'Authoring Space Requests',
6869: icon => 'selfenrl-queue.png',
6870: #help => 'Domain_Role_Approvals',
6871: url => '/adm/createuser?action=processauthorreq',
6872: permission => $permission->{'cusr'},
6873: linktitle => 'Approve or reject author role requests',
6874: },
1.363 raeburn 6875: {
1.391 raeburn 6876: linktext => 'LON-CAPA Account Requests',
6877: icon => 'list-add.png',
6878: #help => 'Domain_Username_Approvals',
6879: url => '/adm/createuser?action=processusernamereq',
6880: permission => $permission->{'cusr'},
6881: linktitle => 'Approve or reject LON-CAPA account requests',
6882: },
6883: {
1.363 raeburn 6884: linktext => 'Change Log',
6885: icon => 'document-properties.png',
6886: #help => 'Course_User_Logs',
6887: url => '/adm/createuser?action=changelogs',
1.418 raeburn 6888: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 6889: linktitle => 'View change log.',
6890: },
1.298 droeschl 6891: );
6892:
1.265 mielkec 6893: }elsif ($context eq 'course'){
1.298 droeschl 6894: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 6895:
6896: my %linktext = (
6897: 'Course' => {
6898: single => 'Add/Modify a Student',
6899: drop => 'Drop Students',
6900: groups => 'Course Groups',
6901: },
6902: 'Community' => {
6903: single => 'Add/Modify a Member',
6904: drop => 'Drop Members',
6905: groups => 'Community Groups',
6906: },
6907: );
1.411 raeburn 6908: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 6909:
6910: my %linktitle = (
6911: 'Course' => {
6912: single => 'Add a user with the role of student to this course',
6913: drop => 'Remove a student from this course.',
6914: groups => 'Manage course groups',
6915: },
6916: 'Community' => {
6917: single => 'Add a user with the role of member to this community',
6918: drop => 'Remove a member from this community.',
6919: groups => 'Manage community groups',
6920: },
6921: );
6922:
1.411 raeburn 6923: $linktitle{'Placement'} = $linktitle{'Course'};
6924:
1.298 droeschl 6925: push(@{ $menu[0]->{items} }, #Category: Single Users
6926: {
1.318 raeburn 6927: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 6928: #help => 'Course_Add_Student',
6929: icon => 'list-add.png',
6930: url => '/adm/createuser?action=singlestudent',
6931: permission => $permission->{'cusr'},
1.318 raeburn 6932: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 6933: },
6934: );
6935:
6936: push(@{ $menu[1]->{items} }, #Category: Multiple Users
6937: {
1.318 raeburn 6938: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 6939: icon => 'edit-undo.png',
6940: #help => 'Course_Drop_Student',
6941: url => '/adm/createuser?action=drop',
6942: permission => $permission->{'cusr'},
1.318 raeburn 6943: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 6944: },
6945: );
6946: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 6947: {
6948: linktext => 'Helpdesk Access',
6949: icon => 'helpdesk-access.png',
6950: #help => 'Course_Helpdesk_Access',
6951: url => '/adm/createuser?action=helpdesk',
1.464 raeburn 6952: permission => (($permission->{'owner'} || $permission->{'co-owner'}) &&
6953: ($permission->{'view'} || $permission->{'cusr'})),
1.428 raeburn 6954: linktitle => 'Helpdesk access options',
6955: },
6956: {
1.298 droeschl 6957: linktext => 'Custom Roles',
6958: icon => 'emblem-photos.png',
6959: #help => 'Course_Editing_Custom_Roles',
6960: url => '/adm/createuser?action=custom',
6961: permission => $permission->{'custom'},
6962: linktitle => 'Configure a custom role.',
6963: },
6964: {
1.318 raeburn 6965: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 6966: icon => 'grps.png',
1.298 droeschl 6967: #help => 'Course_Manage_Group',
6968: url => '/adm/coursegroups?refpage=cusr',
6969: permission => $permission->{'grp_manage'},
1.318 raeburn 6970: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 6971: },
6972: {
1.328 wenzelju 6973: linktext => 'Change Log',
1.298 droeschl 6974: icon => 'document-properties.png',
6975: #help => 'Course_User_Logs',
6976: url => '/adm/createuser?action=changelogs',
1.418 raeburn 6977: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 6978: linktitle => 'View change log.',
6979: },
6980: );
1.277 raeburn 6981: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 6982: push(@{ $menu[2]->{items} },
1.398 raeburn 6983: {
1.298 droeschl 6984: linktext => 'Enrollment Requests',
6985: icon => 'selfenrl-queue.png',
6986: #help => 'Course_Approve_Selfenroll',
6987: url => '/adm/createuser?action=selfenrollqueue',
1.469 raeburn 6988: permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.298 droeschl 6989: linktitle =>'Approve or reject enrollment requests.',
6990: },
6991: );
1.277 raeburn 6992: }
1.298 droeschl 6993:
1.265 mielkec 6994: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 6995: if ($crstype ne 'Community') {
6996: push(@{ $menu[2]->{items} },
6997: {
6998: linktext => 'Automated Enrollment',
6999: icon => 'roles.png',
7000: #help => 'Course_Automated_Enrollment',
7001: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 7002: && (($permission->{'cusr'}) ||
7003: ($permission->{'view'}))),
1.320 raeburn 7004: url => '/adm/populate',
7005: linktitle => 'Automated enrollment manager.',
7006: }
7007: );
7008: }
7009: push(@{ $menu[2]->{items} },
1.298 droeschl 7010: {
7011: linktext => 'User Self-Enrollment',
1.342 wenzelju 7012: icon => 'self_enroll.png',
1.298 droeschl 7013: #help => 'Course_Self_Enrollment',
7014: url => '/adm/createuser?action=selfenroll',
1.469 raeburn 7015: permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.317 bisitz 7016: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 7017: },
7018: );
7019: }
1.363 raeburn 7020: } elsif ($context eq 'author') {
1.481 raeburn 7021: my $coauthorlist;
7022: if ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)$}) {
7023: if ($env{'environment.internal.coauthorlist./'.$1.'/'.$2}) {
7024: $coauthorlist = 1;
7025: }
7026: } elsif ($env{'request.role'} eq "au./$env{'user.domain'}/") {
7027: if ($env{'environment.coauthorlist'}) {
7028: $coauthorlist = 1;
7029: }
7030: }
7031: if ($coauthorlist) {
7032: push(@{ $menu[1]->{items} },
7033: {
7034: linktext => 'Co-author-viewable list',
7035: icon => 'clst.png',
7036: #help => 'Coauthor_Listing',
7037: url => '/adm/createuser?action=calist&forceedit=0',
7038: permission => $permission->{'cusr'},
7039: linktitle => 'Co-author-viewable listing',
7040: });
7041: }
1.370 raeburn 7042: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 7043: {
7044: linktext => 'Change Log',
7045: icon => 'document-properties.png',
7046: #help => 'Course_User_Logs',
7047: url => '/adm/createuser?action=changelogs',
7048: permission => $permission->{'cusr'},
7049: linktitle => 'View change log.',
7050: },
1.470 raeburn 7051: {
1.472 raeburn 7052: linktext => 'Co-author Managers',
1.473 raeburn 7053: icon => 'camanager.png',
1.470 raeburn 7054: #help => 'Coauthor_Management',
7055: url => '/adm/createuser?action=camanagers',
7056: permission => $permission->{'author'},
7057: linktitle => 'Assign/Revoke right to manage co-author roles',
7058: },
7059: {
1.473 raeburn 7060: linktext => 'Configure Co-author Listing',
7061: icon => 'coauthors.png',
1.470 raeburn 7062: #help => 'Coauthor_Settings',
7063: url => '/adm/createuser?action=calist&forceedit=1',
7064: permission => ($permission->{'cusr'}),
7065: linktitle => 'Set availability of coauthor-viewable user listing',
7066: },
1.370 raeburn 7067: );
1.363 raeburn 7068: }
1.465 raeburn 7069: push(@{ $menu[2]->{items} },
7070: {
7071: linktext => 'Role Requests (other domains)',
7072: icon => 'edit-find.png',
7073: #help => 'Role_Requests',
7074: url => '/adm/createuser?action=rolerequests',
7075: permission => $permission->{'cusr'},
7076: linktitle => 'Role requests for users in other domains',
7077: },
7078: );
7079: if (&show_role_requests($context,$env{'request.role.domain'})) {
7080: push(@{ $menu[2]->{items} },
7081: {
7082: linktext => 'Queued Role Assignments (this domain)',
7083: icon => 'edit-find.png',
7084: #help => 'Role_Approvals',
7085: url => '/adm/createuser?action=queuedroles',
7086: permission => $permission->{'cusr'},
7087: linktitle => "Role requests for this domain's users",
7088: },
7089: );
7090: }
1.363 raeburn 7091: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 7092: # { text => 'View Log-in History',
7093: # help => 'Course_User_Logins',
7094: # action => 'logins',
7095: # permission => $permission->{'cusr'},
7096: # });
1.190 raeburn 7097: }
7098:
1.189 albertel 7099: sub restore_prev_selections {
7100: my %saveable_parameters = ('srchby' => 'scalar',
7101: 'srchin' => 'scalar',
7102: 'srchtype' => 'scalar',
7103: );
7104: &Apache::loncommon::store_settings('user','user_picker',
7105: \%saveable_parameters);
7106: &Apache::loncommon::restore_settings('user','user_picker',
7107: \%saveable_parameters);
7108: }
7109:
1.237 raeburn 7110: sub print_selfenroll_menu {
1.418 raeburn 7111: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 7112: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 7113: my $formname = 'selfenroll';
1.237 raeburn 7114: my $nolink = 1;
1.398 raeburn 7115: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 7116: my $groupslist = &Apache::lonuserutils::get_groupslist();
7117: my $setsec_js =
7118: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 7119: my %alerts = &Apache::lonlocal::texthash(
7120: acto => 'Activation of self-enrollment was selected for the following domain(s)',
7121: butn => 'but no user types have been checked.',
7122: wilf => "Please uncheck 'activate' or check at least one type.",
7123: );
1.418 raeburn 7124: my $disabled;
7125: if ($readonly) {
7126: $disabled = ' disabled="disabled"';
7127: }
1.405 damieng 7128: &js_escape(\%alerts);
1.249 raeburn 7129: my $selfenroll_js = <<"ENDSCRIPT";
7130: function update_types(caller,num) {
7131: var delidx = getIndexByName('selfenroll_delete');
7132: var actidx = getIndexByName('selfenroll_activate');
7133: if (caller == 'selfenroll_all') {
7134: var selall;
7135: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
7136: if (document.$formname.selfenroll_all[i].checked) {
7137: selall = document.$formname.selfenroll_all[i].value;
7138: }
7139: }
7140: if (selall == 1) {
7141: if (delidx != -1) {
7142: if (document.$formname.selfenroll_delete.length) {
7143: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
7144: document.$formname.selfenroll_delete[j].checked = true;
7145: }
7146: } else {
7147: document.$formname.elements[delidx].checked = true;
7148: }
7149: }
7150: if (actidx != -1) {
7151: if (document.$formname.selfenroll_activate.length) {
7152: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
7153: document.$formname.selfenroll_activate[j].checked = false;
7154: }
7155: } else {
7156: document.$formname.elements[actidx].checked = false;
7157: }
7158: }
7159: document.$formname.selfenroll_newdom.selectedIndex = 0;
7160: }
7161: }
7162: if (caller == 'selfenroll_activate') {
7163: if (document.$formname.selfenroll_activate.length) {
7164: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
7165: if (document.$formname.selfenroll_activate[j].value == num) {
7166: if (document.$formname.selfenroll_activate[j].checked) {
7167: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
7168: if (document.$formname.selfenroll_all[i].value == '1') {
7169: document.$formname.selfenroll_all[i].checked = false;
7170: }
7171: if (document.$formname.selfenroll_all[i].value == '0') {
7172: document.$formname.selfenroll_all[i].checked = true;
7173: }
7174: }
7175: }
7176: }
7177: }
7178: } else {
7179: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
7180: if (document.$formname.selfenroll_all[i].value == '1') {
7181: document.$formname.selfenroll_all[i].checked = false;
7182: }
7183: if (document.$formname.selfenroll_all[i].value == '0') {
7184: document.$formname.selfenroll_all[i].checked = true;
7185: }
7186: }
7187: }
7188: }
7189: if (caller == 'selfenroll_delete') {
7190: if (document.$formname.selfenroll_delete.length) {
7191: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
7192: if (document.$formname.selfenroll_delete[j].value == num) {
7193: if (document.$formname.selfenroll_delete[j].checked) {
7194: var delindex = getIndexByName('selfenroll_types_'+num);
7195: if (delindex != -1) {
7196: if (document.$formname.elements[delindex].length) {
7197: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
7198: document.$formname.elements[delindex][k].checked = false;
7199: }
7200: } else {
7201: document.$formname.elements[delindex].checked = false;
7202: }
7203: }
7204: }
7205: }
7206: }
7207: } else {
7208: if (document.$formname.selfenroll_delete.checked) {
7209: var delindex = getIndexByName('selfenroll_types_'+num);
7210: if (delindex != -1) {
7211: if (document.$formname.elements[delindex].length) {
7212: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
7213: document.$formname.elements[delindex][k].checked = false;
7214: }
7215: } else {
7216: document.$formname.elements[delindex].checked = false;
7217: }
7218: }
7219: }
7220: }
7221: }
7222: return;
7223: }
7224:
7225: function validate_types(form) {
7226: var needaction = new Array();
7227: var countfail = 0;
7228: var actidx = getIndexByName('selfenroll_activate');
7229: if (actidx != -1) {
7230: if (document.$formname.selfenroll_activate.length) {
7231: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
7232: var num = document.$formname.selfenroll_activate[j].value;
7233: if (document.$formname.selfenroll_activate[j].checked) {
7234: countfail = check_types(num,countfail,needaction)
7235: }
7236: }
7237: } else {
7238: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 7239: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 7240: countfail = check_types(num,countfail,needaction)
7241: }
7242: }
7243: }
7244: if (countfail > 0) {
7245: var msg = "$alerts{'acto'}\\n";
7246: var loopend = needaction.length -1;
7247: if (loopend > 0) {
7248: for (var m=0; m<loopend; m++) {
7249: msg += needaction[m]+", ";
7250: }
7251: }
7252: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
7253: alert(msg);
7254: return;
7255: }
7256: setSections(form);
7257: }
7258:
7259: function check_types(num,countfail,needaction) {
1.441 raeburn 7260: var boxname = 'selfenroll_types_'+num;
7261: var typeidx = getIndexByName(boxname);
1.249 raeburn 7262: var count = 0;
7263: if (typeidx != -1) {
1.441 raeburn 7264: if (document.$formname.elements[boxname].length) {
7265: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
7266: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 7267: count ++;
7268: }
7269: }
7270: } else {
7271: if (document.$formname.elements[typeidx].checked) {
7272: count ++;
7273: }
7274: }
7275: if (count == 0) {
7276: var domidx = getIndexByName('selfenroll_dom_'+num);
7277: if (domidx != -1) {
7278: var domname = document.$formname.elements[domidx].value;
7279: needaction[countfail] = domname;
7280: countfail ++;
7281: }
7282: }
7283: }
7284: return countfail;
7285: }
7286:
1.398 raeburn 7287: function toggleNotify() {
7288: var selfenrollApproval = 0;
7289: if (document.$formname.selfenroll_approval.length) {
7290: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
7291: if (document.$formname.selfenroll_approval[i].checked) {
7292: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
7293: break;
7294: }
7295: }
7296: }
7297: if (document.getElementById('notified')) {
7298: if (selfenrollApproval == 0) {
7299: document.getElementById('notified').style.display='none';
7300: } else {
7301: document.getElementById('notified').style.display='block';
7302: }
7303: }
7304: return;
7305: }
7306:
1.249 raeburn 7307: function getIndexByName(item) {
7308: for (var i=0;i<document.$formname.elements.length;i++) {
7309: if (document.$formname.elements[i].name == item) {
7310: return i;
7311: }
7312: }
7313: return -1;
7314: }
7315: ENDSCRIPT
1.256 raeburn 7316:
1.237 raeburn 7317: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 7318: '// <![CDATA['."\n".
1.249 raeburn 7319: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 7320: '// ]]>'."\n".
1.237 raeburn 7321: '</script>'."\n".
1.256 raeburn 7322: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.469 raeburn 7323: my $visactions = &cat_visibility($cdom);
1.400 raeburn 7324: my ($cathash,%cattype);
7325: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
7326: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7327: $cathash = $domconfig{'coursecategories'}{'cats'};
7328: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
7329: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 7330: if ($cattype{'auth'} eq '') {
7331: $cattype{'auth'} = 'std';
7332: }
7333: if ($cattype{'unauth'} eq '') {
7334: $cattype{'unauth'} = 'std';
7335: }
1.400 raeburn 7336: } else {
7337: $cathash = {};
7338: $cattype{'auth'} = 'std';
7339: $cattype{'unauth'} = 'std';
7340: }
7341: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
7342: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7343: '<br />'.
7344: '<br />'.$visactions->{'take'}.'<ul>'.
7345: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
7346: '</ul>');
7347: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
7348: if ($currsettings->{'uniquecode'}) {
7349: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
7350: } else {
7351: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7352: '<br />'.
7353: '<br />'.$visactions->{'take'}.'<ul>'.
7354: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
7355: '</ul><br />');
7356: }
7357: } else {
7358: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
7359: if (ref($visactions) eq 'HASH') {
7360: if ($visible) {
7361: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
7362: } else {
7363: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
7364: .$visactions->{'yous'}.
7365: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
7366: if (ref($vismsgs) eq 'ARRAY') {
7367: $output .= '<br />'.$visactions->{'make'}.'<ul>';
7368: foreach my $item (@{$vismsgs}) {
7369: $output .= '<li>'.$visactions->{$item}.'</li>';
7370: }
7371: $output .= '</ul>';
1.256 raeburn 7372: }
1.400 raeburn 7373: $output .= '</p>';
1.256 raeburn 7374: }
7375: }
7376: }
1.398 raeburn 7377: my $actionhref = '/adm/createuser';
7378: if ($context eq 'domain') {
7379: $actionhref = '/adm/modifycourse';
7380: }
1.400 raeburn 7381:
7382: my %noedit;
7383: unless ($context eq 'domain') {
7384: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
7385: }
1.398 raeburn 7386: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 7387: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 7388: if (ref($row) eq 'ARRAY') {
7389: foreach my $item (@{$row}) {
7390: my $title = $item;
7391: if (ref($lt) eq 'HASH') {
7392: $title = $lt->{$item};
7393: }
1.297 bisitz 7394: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 7395: if ($item eq 'types') {
1.398 raeburn 7396: my $curr_types;
7397: if (ref($currsettings) eq 'HASH') {
7398: $curr_types = $currsettings->{'selfenroll_types'};
7399: }
1.400 raeburn 7400: if ($noedit{$item}) {
7401: if ($curr_types eq '*') {
7402: $output .= &mt('Any user in any domain');
7403: } else {
7404: my @entries = split(/;/,$curr_types);
7405: if (@entries > 0) {
7406: $output .= '<ul>';
7407: foreach my $entry (@entries) {
7408: my ($currdom,$typestr) = split(/:/,$entry);
7409: next if ($typestr eq '');
7410: my $domdesc = &Apache::lonnet::domain($currdom);
7411: my @currinsttypes = split(',',$typestr);
7412: my ($othertitle,$usertypes,$types) =
7413: &Apache::loncommon::sorted_inst_types($currdom);
7414: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7415: $usertypes->{'any'} = &mt('any user');
7416: if (keys(%{$usertypes}) > 0) {
7417: $usertypes->{'other'} = &mt('other users');
7418: }
7419: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
7420: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
7421: }
7422: }
7423: $output .= '</ul>';
7424: } else {
7425: $output .= &mt('None');
7426: }
7427: }
7428: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7429: next;
7430: }
1.241 raeburn 7431: my $showdomdesc = 1;
7432: my $includeempty = 1;
7433: my $num = 0;
7434: $output .= &Apache::loncommon::start_data_table().
7435: &Apache::loncommon::start_data_table_row()
7436: .'<td colspan="2"><span class="LC_nobreak"><label>'
7437: .&mt('Any user in any domain:')
7438: .' <input type="radio" name="selfenroll_all" value="1" ';
7439: if ($curr_types eq '*') {
7440: $output .= ' checked="checked" ';
7441: }
1.249 raeburn 7442: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 7443: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 7444: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 7445: if ($curr_types ne '*') {
7446: $output .= ' checked="checked" ';
7447: }
1.249 raeburn 7448: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 7449: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 7450: &Apache::loncommon::end_data_table_row().
7451: &Apache::loncommon::end_data_table().
7452: &mt('Or').'<br />'.
7453: &Apache::loncommon::start_data_table();
1.241 raeburn 7454: my %currdoms;
1.249 raeburn 7455: if ($curr_types eq '') {
1.241 raeburn 7456: $output .= &new_selfenroll_dom_row($cdom,'0');
7457: } elsif ($curr_types ne '*') {
7458: my @entries = split(/;/,$curr_types);
7459: if (@entries > 0) {
7460: foreach my $entry (@entries) {
7461: my ($currdom,$typestr) = split(/:/,$entry);
7462: $currdoms{$currdom} = 1;
7463: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 7464: my @currinsttypes = split(',',$typestr);
1.241 raeburn 7465: $output .= &Apache::loncommon::start_data_table_row()
7466: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
7467: .' '.$domdesc.' ('.$currdom.')'
7468: .'</b><input type="hidden" name="selfenroll_dom_'.$num
7469: .'" value="'.$currdom.'" /></span><br />'
7470: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 7471: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 7472: .&mt('Delete').'</label></span></td>';
1.249 raeburn 7473: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 7474: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 7475: .&Apache::loncommon::end_data_table_row();
7476: $num ++;
7477: }
7478: }
7479: }
1.249 raeburn 7480: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 7481: if ($curr_types eq '*') {
1.249 raeburn 7482: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 7483: } elsif ($curr_types eq '') {
1.249 raeburn 7484: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 7485: }
1.446 raeburn 7486: my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$cdom);
1.241 raeburn 7487: $output .= &Apache::loncommon::start_data_table_row()
7488: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
7489: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.446 raeburn 7490: $includeempty,$showdomdesc,'',$trusted,$untrusted,$readonly)
1.241 raeburn 7491: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
7492: .'</td>'.&Apache::loncommon::end_data_table_row()
7493: .&Apache::loncommon::end_data_table();
1.237 raeburn 7494: } elsif ($item eq 'registered') {
7495: my ($regon,$regoff);
1.398 raeburn 7496: my $registered;
7497: if (ref($currsettings) eq 'HASH') {
7498: $registered = $currsettings->{'selfenroll_registered'};
7499: }
1.400 raeburn 7500: if ($noedit{$item}) {
7501: if ($registered) {
7502: $output .= &mt('Must be registered in course');
7503: } else {
7504: $output .= &mt('No requirement');
7505: }
7506: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7507: next;
7508: }
1.398 raeburn 7509: if ($registered) {
1.237 raeburn 7510: $regon = ' checked="checked" ';
1.419 raeburn 7511: $regoff = '';
1.237 raeburn 7512: } else {
1.419 raeburn 7513: $regon = '';
1.237 raeburn 7514: $regoff = ' checked="checked" ';
7515: }
7516: $output .= '<label>'.
1.419 raeburn 7517: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 7518: &mt('Yes').'</label> <label>'.
1.419 raeburn 7519: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 7520: &mt('No').'</label>';
1.237 raeburn 7521: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 7522: my ($starttime,$endtime);
7523: if (ref($currsettings) eq 'HASH') {
7524: $starttime = $currsettings->{'selfenroll_start_date'};
7525: $endtime = $currsettings->{'selfenroll_end_date'};
7526: if ($starttime eq '') {
7527: $starttime = $currsettings->{'default_enrollment_start_date'};
7528: }
7529: if ($endtime eq '') {
7530: $endtime = $currsettings->{'default_enrollment_end_date'};
7531: }
1.237 raeburn 7532: }
1.400 raeburn 7533: if ($noedit{$item}) {
7534: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
7535: &Apache::lonlocal::locallocaltime($endtime));
7536: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7537: next;
7538: }
1.237 raeburn 7539: my $startform =
7540: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 7541: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7542: my $endform =
7543: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 7544: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7545: $output .= &selfenroll_date_forms($startform,$endform);
7546: } elsif ($item eq 'access_dates') {
1.398 raeburn 7547: my ($starttime,$endtime);
7548: if (ref($currsettings) eq 'HASH') {
7549: $starttime = $currsettings->{'selfenroll_start_access'};
7550: $endtime = $currsettings->{'selfenroll_end_access'};
7551: if ($starttime eq '') {
7552: $starttime = $currsettings->{'default_enrollment_start_date'};
7553: }
7554: if ($endtime eq '') {
7555: $endtime = $currsettings->{'default_enrollment_end_date'};
7556: }
1.237 raeburn 7557: }
1.400 raeburn 7558: if ($noedit{$item}) {
7559: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
7560: &Apache::lonlocal::locallocaltime($endtime));
7561: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7562: next;
7563: }
1.237 raeburn 7564: my $startform =
7565: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 7566: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7567: my $endform =
7568: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 7569: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7570: $output .= &selfenroll_date_forms($startform,$endform);
7571: } elsif ($item eq 'section') {
1.398 raeburn 7572: my $currsec;
7573: if (ref($currsettings) eq 'HASH') {
7574: $currsec = $currsettings->{'selfenroll_section'};
7575: }
1.237 raeburn 7576: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
7577: my $newsecval;
7578: if ($currsec ne 'none' && $currsec ne '') {
7579: if (!defined($sections_count{$currsec})) {
7580: $newsecval = $currsec;
7581: }
7582: }
1.400 raeburn 7583: if ($noedit{$item}) {
7584: if ($currsec ne '') {
7585: $output .= $currsec;
7586: } else {
7587: $output .= &mt('No specific section');
7588: }
7589: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7590: next;
7591: }
1.237 raeburn 7592: my $sections_select =
1.418 raeburn 7593: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 7594: $output .= '<table class="LC_createuser">'."\n".
7595: '<tr class="LC_section_row">'."\n".
7596: '<td align="center">'.&mt('Existing sections')."\n".
7597: '<br />'.$sections_select.'</td><td align="center">'.
7598: &mt('New section').'<br />'."\n".
1.418 raeburn 7599: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 7600: '<input type="hidden" name="sections" value="" />'."\n".
7601: '</td></tr></table>'."\n";
1.276 raeburn 7602: } elsif ($item eq 'approval') {
1.398 raeburn 7603: my ($currnotified,$currapproval,%appchecked);
7604: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 7605: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 7606: $currnotified = $currsettings->{'selfenroll_notifylist'};
7607: $currapproval = $currsettings->{'selfenroll_approval'};
7608: }
7609: if ($currapproval !~ /^[012]$/) {
7610: $currapproval = 0;
7611: }
1.400 raeburn 7612: if ($noedit{$item}) {
7613: $output .= $selfdescs{'approval'}{$currapproval}.
7614: '<br />'.&mt('(Set by Domain Coordinator)');
7615: next;
7616: }
1.398 raeburn 7617: $appchecked{$currapproval} = ' checked="checked"';
7618: for my $i (0..2) {
7619: $output .= '<label>'.
7620: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 7621: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
7622: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 7623: }
7624: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
7625: my (@ccs,%notified);
1.322 raeburn 7626: my $ccrole = 'cc';
7627: if ($crstype eq 'Community') {
7628: $ccrole = 'co';
7629: }
7630: if ($advhash{$ccrole}) {
7631: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 7632: }
7633: if ($currnotified) {
7634: foreach my $current (split(/,/,$currnotified)) {
7635: $notified{$current} = 1;
7636: if (!grep(/^\Q$current\E$/,@ccs)) {
7637: push(@ccs,$current);
7638: }
7639: }
7640: }
7641: if (@ccs) {
1.398 raeburn 7642: my $style;
7643: unless ($currapproval) {
7644: $style = ' style="display: none;"';
7645: }
7646: $output .= '<br /><div id="notified"'.$style.'>'.
7647: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
7648: &Apache::loncommon::start_data_table().
1.276 raeburn 7649: &Apache::loncommon::start_data_table_row();
7650: my $count = 0;
7651: my $numcols = 4;
7652: foreach my $cc (sort(@ccs)) {
7653: my $notifyon;
7654: my ($ccuname,$ccudom) = split(/:/,$cc);
7655: if ($notified{$cc}) {
7656: $notifyon = ' checked="checked" ';
7657: }
7658: if ($count && !$count%$numcols) {
7659: $output .= &Apache::loncommon::end_data_table_row().
7660: &Apache::loncommon::start_data_table_row()
7661: }
7662: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 7663: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 7664: &Apache::loncommon::plainname($ccuname,$ccudom).
7665: '</label></span></td>';
1.343 raeburn 7666: $count ++;
1.276 raeburn 7667: }
7668: my $rem = $count%$numcols;
7669: if ($rem) {
7670: my $emptycols = $numcols - $rem;
7671: for (my $i=0; $i<$emptycols; $i++) {
7672: $output .= '<td> </td>';
7673: }
7674: }
7675: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 7676: &Apache::loncommon::end_data_table().
7677: '</div>';
1.276 raeburn 7678: }
7679: } elsif ($item eq 'limit') {
1.398 raeburn 7680: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
7681: if (ref($currsettings) eq 'HASH') {
7682: $currlim = $currsettings->{'selfenroll_limit'};
7683: $currcap = $currsettings->{'selfenroll_cap'};
7684: }
1.400 raeburn 7685: if ($noedit{$item}) {
7686: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
7687: if ($currlim eq 'allstudents') {
7688: $output .= &mt('Limit by total students');
7689: } elsif ($currlim eq 'selfenrolled') {
7690: $output .= &mt('Limit by total self-enrolled students');
7691: }
7692: $output .= ' '.&mt('Maximum: [_1]',$currcap).
7693: '<br />'.&mt('(Set by Domain Coordinator)');
7694: } else {
7695: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
7696: }
7697: next;
7698: }
1.276 raeburn 7699: if ($currlim eq 'allstudents') {
7700: $crslimit = ' checked="checked" ';
7701: $selflimit = ' ';
7702: $nolimit = ' ';
7703: } elsif ($currlim eq 'selfenrolled') {
7704: $crslimit = ' ';
7705: $selflimit = ' checked="checked" ';
7706: $nolimit = ' ';
7707: } else {
7708: $crslimit = ' ';
7709: $selflimit = ' ';
1.398 raeburn 7710: $nolimit = ' checked="checked" ';
1.276 raeburn 7711: }
7712: $output .= '<table><tr><td><label>'.
1.418 raeburn 7713: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 7714: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 7715: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 7716: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 7717: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 7718: &mt('Limit by total self-enrolled students').
7719: '</td></tr><tr>'.
7720: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
7721: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 7722: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 7723: }
7724: $output .= &Apache::lonhtmlcommon::row_closure(1);
7725: }
7726: }
1.418 raeburn 7727: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
7728: unless ($readonly) {
7729: $output .= '<input type="button" name="selfenrollconf" value="'
7730: .&mt('Save').'" onclick="validate_types(this.form);" />';
7731: }
7732: $output .= '<input type="hidden" name="action" value="selfenroll" />'
7733: .'<input type="hidden" name="state" value="done" />'."\n"
7734: .$additional.'</form>';
1.237 raeburn 7735: $r->print($output);
7736: return;
7737: }
7738:
1.400 raeburn 7739: sub get_noedit_fields {
7740: my ($cdom,$cnum,$crstype,$row) = @_;
7741: my %noedit;
7742: if (ref($row) eq 'ARRAY') {
7743: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
7744: 'internal.selfenrollmgrdc',
7745: 'internal.selfenrollmgrcc'],$cdom,$cnum);
7746: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
7747: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
7748: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
7749: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
7750: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
7751: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
7752:
7753: foreach my $item (@{$row}) {
7754: next if ($specific_managebycc{$item});
7755: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
7756: $noedit{$item} = 1;
7757: }
7758: }
7759: }
7760: return %noedit;
1.470 raeburn 7761: }
1.400 raeburn 7762:
7763: sub visible_in_stdcat {
7764: my ($cdom,$cnum,$domconf) = @_;
7765: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
7766: unless (ref($domconf) eq 'HASH') {
7767: return ($visible,$cansetvis,\@vismsgs);
7768: }
7769: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7770: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 7771: $settable{'togglecats'} = 1;
7772: }
1.400 raeburn 7773: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 7774: $settable{'categorize'} = 1;
7775: }
1.400 raeburn 7776: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7777: }
1.260 raeburn 7778: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 7779: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
7780: } elsif ($settable{'togglecats'}) {
7781: $cansetvis = &mt('You are able to choose to exclude this course from the catalog, but only a Domain Coordinator may assign a course category.');
1.260 raeburn 7782: } elsif ($settable{'categorize'}) {
1.256 raeburn 7783: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
7784: } else {
7785: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
7786: }
7787:
7788: my %currsettings =
7789: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
7790: $cdom,$cnum);
1.400 raeburn 7791: $visible = 0;
1.256 raeburn 7792: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 7793: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7794: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7795: if (ref($cathash) eq 'HASH') {
7796: if ($cathash->{'instcode::0'} eq '') {
7797: push(@vismsgs,'dc_addinst');
7798: } else {
7799: $visible = 1;
7800: }
7801: } else {
7802: $visible = 1;
7803: }
7804: } else {
7805: $visible = 1;
7806: }
7807: } else {
7808: if (ref($cathash) eq 'HASH') {
7809: if ($cathash->{'instcode::0'} ne '') {
7810: push(@vismsgs,'dc_instcode');
7811: }
7812: } else {
7813: push(@vismsgs,'dc_instcode');
7814: }
7815: }
7816: if ($currsettings{'categories'} ne '') {
7817: my $cathash;
1.400 raeburn 7818: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7819: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7820: if (ref($cathash) eq 'HASH') {
7821: if (keys(%{$cathash}) == 0) {
7822: push(@vismsgs,'dc_catalog');
7823: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
7824: push(@vismsgs,'dc_categories');
7825: } else {
7826: my @currcategories = split('&',$currsettings{'categories'});
7827: my $matched = 0;
7828: foreach my $cat (@currcategories) {
7829: if ($cathash->{$cat} ne '') {
7830: $visible = 1;
7831: $matched = 1;
7832: last;
7833: }
7834: }
7835: if (!$matched) {
1.260 raeburn 7836: if ($settable{'categorize'}) {
1.256 raeburn 7837: push(@vismsgs,'chgcat');
7838: } else {
7839: push(@vismsgs,'dc_chgcat');
7840: }
7841: }
7842: }
7843: }
7844: }
7845: } else {
7846: if (ref($cathash) eq 'HASH') {
7847: if ((keys(%{$cathash}) > 1) ||
7848: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 7849: if ($settable{'categorize'}) {
1.256 raeburn 7850: push(@vismsgs,'addcat');
7851: } else {
7852: push(@vismsgs,'dc_addcat');
7853: }
7854: }
7855: }
7856: }
7857: if ($currsettings{'hidefromcat'} eq 'yes') {
7858: $visible = 0;
7859: if ($settable{'togglecats'}) {
7860: unshift(@vismsgs,'unhide');
7861: } else {
7862: unshift(@vismsgs,'dc_unhide')
7863: }
7864: }
1.400 raeburn 7865: return ($visible,$cansetvis,\@vismsgs);
7866: }
7867:
7868: sub cat_visibility {
1.469 raeburn 7869: my ($cdom) = @_;
1.400 raeburn 7870: my %visactions = &Apache::lonlocal::texthash(
7871: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
7872: 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.',
7873: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
7874: none => 'Display of a course catalog is disabled for this domain.',
7875: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
7876: 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.',
7877: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
7878: take => 'Take the following action to ensure the course appears in the Catalog:',
7879: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
7880: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
7881: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
1.469 raeburn 7882: dc_addinst => 'Ask a domain coordinator to enable catalog display of "Official courses (with institutional codes)".',
1.400 raeburn 7883: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
7884: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
7885: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
7886: 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',
7887: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
7888: );
1.469 raeburn 7889: if ($env{'request.role'} eq "dc./$cdom/") {
7890: $visactions{'dc_chgconf'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the Catalog type for this domain.','»');
7891: $visactions{'dc_setcode'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to assign a six character code to the course.','»');
7892: $visactions{'dc_unhide'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the "Exclude from course catalog" setting.','»');
7893: $visactions{'dc_addinst'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to enable catalog display of "Official courses (with institutional codes)".','»');
7894: $visactions{'dc_instcode'} = &mt('Use: "Main menu" [_1] "View or modify a course or community" [_1] "View/Modify course owner, institutional code ... " to assign an institutional code (if this is an official course).','»');
7895: $visactions{'dc_catalog'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to enable or create at least one course category in the domain.','»');
7896: $visactions{'dc_categories'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to create a hierarchy of categories and sub categories for courses in the domain.','»');
7897: $visactions{'dc_chgcat'} = &mt('Use: "Main menu" [_1] "View or modify a course or community" [_1] "View/Modify catalog settings for course" to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','»');
7898: $visactions{'dc_addcat'} = &mt('Use: "Main menu" [_1] "View or modify a course or community" [_1] "View/Modify catalog settings for course" to assign a category to the course.','»');
7899: }
1.400 raeburn 7900: $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>"');
7901: $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>"');
7902: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
7903: return \%visactions;
1.256 raeburn 7904: }
7905:
1.241 raeburn 7906: sub new_selfenroll_dom_row {
7907: my ($newdom,$num) = @_;
7908: my $domdesc = &Apache::lonnet::domain($newdom);
7909: my $output;
7910: if ($domdesc ne '') {
7911: $output .= &Apache::loncommon::start_data_table_row()
7912: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
7913: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 7914: .'" value="'.$newdom.'" /></span><br />'
7915: .'<span class="LC_nobreak"><label><input type="checkbox" '
7916: .'name="selfenroll_activate" value="'.$num.'" '
7917: .'onchange="javascript:update_types('
7918: ."'selfenroll_activate','$num'".');" />'
7919: .&mt('Activate').'</label></span></td>';
1.241 raeburn 7920: my @currinsttypes;
7921: $output .= '<td>'.&mt('User types:').'<br />'
7922: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
7923: .&Apache::loncommon::end_data_table_row();
7924: }
7925: return $output;
7926: }
7927:
7928: sub selfenroll_inst_types {
1.418 raeburn 7929: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 7930: my $output;
7931: my $numinrow = 4;
7932: my $count = 0;
7933: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 7934: my $othervalue = 'any';
1.418 raeburn 7935: my $disabled;
7936: if ($readonly) {
7937: $disabled = ' disabled="disabled"';
7938: }
1.241 raeburn 7939: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 7940: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 7941: $othervalue = 'other';
7942: }
1.241 raeburn 7943: $output .= '<table><tr>';
7944: foreach my $type (@{$types}) {
7945: if (($count > 0) && ($count%$numinrow == 0)) {
7946: $output .= '</tr><tr>';
7947: }
7948: if (defined($usertypes->{$type})) {
1.257 raeburn 7949: my $esc_type = &escape($type);
1.241 raeburn 7950: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 7951: $esc_type.'" ';
1.241 raeburn 7952: if (ref($currinsttypes) eq 'ARRAY') {
7953: if (@{$currinsttypes} > 0) {
1.249 raeburn 7954: if (grep(/^any$/,@{$currinsttypes})) {
7955: $output .= 'checked="checked"';
1.257 raeburn 7956: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 7957: $output .= 'checked="checked"';
7958: }
1.249 raeburn 7959: } else {
7960: $output .= 'checked="checked"';
1.241 raeburn 7961: }
7962: }
1.418 raeburn 7963: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 7964: }
7965: $count ++;
7966: }
7967: if (($count > 0) && ($count%$numinrow == 0)) {
7968: $output .= '</tr><tr>';
7969: }
1.249 raeburn 7970: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 7971: if (ref($currinsttypes) eq 'ARRAY') {
7972: if (@{$currinsttypes} > 0) {
1.249 raeburn 7973: if (grep(/^any$/,@{$currinsttypes})) {
7974: $output .= ' checked="checked"';
7975: } elsif ($othervalue eq 'other') {
7976: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
7977: $output .= ' checked="checked"';
7978: }
1.241 raeburn 7979: }
1.249 raeburn 7980: } else {
7981: $output .= ' checked="checked"';
1.241 raeburn 7982: }
1.249 raeburn 7983: } else {
7984: $output .= ' checked="checked"';
1.241 raeburn 7985: }
1.418 raeburn 7986: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 7987: }
7988: return $output;
7989: }
7990:
1.237 raeburn 7991: sub selfenroll_date_forms {
7992: my ($startform,$endform) = @_;
7993: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 7994: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 7995: 'LC_oddrow_value')."\n".
7996: $startform."\n".
7997: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 7998: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 7999: 'LC_oddrow_value')."\n".
8000: $endform."\n".
8001: &Apache::lonhtmlcommon::row_closure(1).
8002: &Apache::lonhtmlcommon::end_pick_box();
8003: return $output;
8004: }
8005:
1.239 raeburn 8006: sub print_userchangelogs_display {
1.415 raeburn 8007: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 8008: my $formname = 'rolelog';
1.418 raeburn 8009: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 8010: if ($context eq 'domain') {
8011: $domain = $env{'request.role.domain'};
8012: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
8013: } else {
8014: if ($context eq 'course') {
8015: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
8016: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
8017: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 8018: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 8019: my %saveable_parameters = ('show' => 'scalar',);
8020: &Apache::loncommon::store_course_settings('roles_log',
8021: \%saveable_parameters);
8022: &Apache::loncommon::restore_course_settings('roles_log',
8023: \%saveable_parameters);
8024: } elsif ($context eq 'author') {
1.470 raeburn 8025: $domain = $env{'user.domain'};
1.363 raeburn 8026: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
8027: $username = $env{'user.name'};
1.470 raeburn 8028: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
8029: ($domain,$username) = ($1,$2);
1.363 raeburn 8030: } else {
8031: undef($domain);
8032: }
8033: }
8034: if ($domain ne '' && $username ne '') {
8035: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
8036: }
8037: }
1.239 raeburn 8038: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
8039:
1.415 raeburn 8040: my $helpitem;
8041: if ($context eq 'course') {
8042: $helpitem = 'Course_User_Logs';
1.439 raeburn 8043: } elsif ($context eq 'domain') {
8044: $helpitem = 'Domain_Role_Logs';
8045: } elsif ($context eq 'author') {
8046: $helpitem = 'Author_User_Logs';
1.415 raeburn 8047: }
8048: push (@{$brcrum},
8049: {href => '/adm/createuser?action=changelogs',
8050: text => 'User Management Logs',
8051: help => $helpitem});
8052: my $bread_crumbs_component = 'User Changes';
8053: my $args = { bread_crumbs => $brcrum,
8054: bread_crumbs_component => $bread_crumbs_component};
8055:
8056: # Create navigation javascript
8057: my $jsnav = &userlogdisplay_js($formname);
8058:
8059: my $jscript = (<<ENDSCRIPT);
8060: <script type="text/javascript">
8061: // <![CDATA[
8062: $jsnav
8063: // ]]>
8064: </script>
8065: ENDSCRIPT
8066:
8067: # print page header
8068: $r->print(&header($jscript,$args));
8069:
1.239 raeburn 8070: # set defaults
8071: my $now = time();
8072: my $defstart = $now - (7*24*3600); #7 days ago
8073: my %defaults = (
8074: page => '1',
8075: show => '10',
8076: role => 'any',
8077: chgcontext => 'any',
8078: rolelog_start_date => $defstart,
8079: rolelog_end_date => $now,
1.468 raeburn 8080: approvals => 'any',
1.239 raeburn 8081: );
8082: my $more_records = 0;
8083:
8084: # set current
8085: my %curr;
1.468 raeburn 8086: foreach my $item ('show','page','role','chgcontext','approvals') {
1.239 raeburn 8087: $curr{$item} = $env{'form.'.$item};
8088: }
8089: my ($startdate,$enddate) =
8090: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
8091: $curr{'rolelog_start_date'} = $startdate;
8092: $curr{'rolelog_end_date'} = $enddate;
8093: foreach my $key (keys(%defaults)) {
8094: if ($curr{$key} eq '') {
8095: $curr{$key} = $defaults{$key};
8096: }
8097: }
1.248 raeburn 8098: my (%whodunit,%changed,$version);
8099: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 8100: my ($minshown,$maxshown);
1.255 raeburn 8101: $minshown = 1;
1.239 raeburn 8102: my $count = 0;
1.415 raeburn 8103: if ($curr{'show'} =~ /\D/) {
8104: $curr{'page'} = 1;
8105: } else {
1.239 raeburn 8106: $maxshown = $curr{'page'} * $curr{'show'};
8107: if ($curr{'page'} > 1) {
8108: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
8109: }
8110: }
1.301 bisitz 8111:
1.327 raeburn 8112: # Form Header
8113: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 8114: &role_display_filter($context,$formname,$domain,$username,\%curr,
8115: $version,$crstype));
1.327 raeburn 8116:
8117: my $showntableheader = 0;
8118:
8119: # Table Header
8120: my $tableheader =
8121: &Apache::loncommon::start_data_table_header_row()
8122: .'<th> </th>'
8123: .'<th>'.&mt('When').'</th>'
8124: .'<th>'.&mt('Who made the change').'</th>'
8125: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 8126: .'<th>'.&mt('Role').'</th>';
8127:
8128: if ($context eq 'course') {
8129: $tableheader .= '<th>'.&mt('Section').'</th>';
8130: }
8131: $tableheader .=
8132: '<th>'.&mt('Context').'</th>'
1.327 raeburn 8133: .'<th>'.&mt('Start').'</th>'
8134: .'<th>'.&mt('End').'</th>'
8135: .&Apache::loncommon::end_data_table_header_row();
8136:
8137: # Display user change log data
1.239 raeburn 8138: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
8139: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
8140: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 8141: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 8142: if ($count >= $curr{'page'} * $curr{'show'}) {
8143: $more_records = 1;
8144: last;
8145: }
8146: }
8147: if ($curr{'role'} ne 'any') {
8148: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
8149: }
8150: if ($curr{'chgcontext'} ne 'any') {
8151: if ($curr{'chgcontext'} eq 'selfenroll') {
8152: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
8153: } else {
8154: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
8155: }
8156: }
1.418 raeburn 8157: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 8158: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 8159: }
1.468 raeburn 8160: if ($curr{'approvals'} eq 'none') {
8161: next if ($roleslog{$id}{'logentry'}{'approval'});
8162: } elsif ($curr{'approvals'} ne 'any') {
8163: next if ($roleslog{$id}{'logentry'}{'approval'} ne $curr{'approvals'});
8164: }
1.239 raeburn 8165: $count ++;
8166: next if ($count < $minshown);
1.327 raeburn 8167: unless ($showntableheader) {
1.415 raeburn 8168: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 8169: .$tableheader);
8170: $r->rflush();
8171: $showntableheader = 1;
8172: }
1.239 raeburn 8173: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
8174: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
8175: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
8176: }
8177: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
8178: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
8179: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
8180: }
8181: my $sec = $roleslog{$id}{'logentry'}{'section'};
8182: if ($sec eq '') {
8183: $sec = &mt('None');
8184: }
8185: my ($rolestart,$roleend);
8186: if ($roleslog{$id}{'delflag'}) {
8187: $rolestart = &mt('deleted');
8188: $roleend = &mt('deleted');
8189: } else {
8190: $rolestart = $roleslog{$id}{'logentry'}{'start'};
8191: $roleend = $roleslog{$id}{'logentry'}{'end'};
8192: if ($rolestart eq '' || $rolestart == 0) {
8193: $rolestart = &mt('No start date');
8194: } else {
8195: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
8196: }
8197: if ($roleend eq '' || $roleend == 0) {
8198: $roleend = &mt('No end date');
8199: } else {
8200: $roleend = &Apache::lonlocal::locallocaltime($roleend);
8201: }
8202: }
8203: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
8204: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
8205: $chgcontext = 'selfenroll';
8206: }
1.363 raeburn 8207: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 8208: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
8209: $chgcontext = $lt{$chgcontext};
8210: }
1.468 raeburn 8211: my ($showreqby,%reqby);
8212: if (($roleslog{$id}{'logentry'}{'approval'}) &&
8213: ($roleslog{$id}{'logentry'}{'requester'})) {
8214: if ($reqby{$roleslog{$id}{'logentry'}{'requester'}} eq '') {
8215: my ($requname,$requdom) = split(/:/,$roleslog{$id}{'logentry'}{'requester'});
8216: $reqby{$roleslog{$id}{'logentry'}{'requester'}} =
8217: &Apache::loncommon::plainname($requname,$requdom);
8218: }
8219: $showreqby = &mt('Requester').': <span class="LC_nobreak">'.$reqby{$roleslog{$id}{'logentry'}{'requester'}}.'</span><br />';
8220: if ($roleslog{$id}{'logentry'}{'approval'} eq 'domain') {
8221: $showreqby .= &mt('Adjudicator').': <span class="LC_nobreak">'.
8222: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.
8223: '</span>';
8224: } else {
8225: $showreqby .= '<span class="LC_nobreak">'.&mt('User approved').'</span>';
8226: }
8227: } else {
8228: $showreqby = $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}};
8229: }
1.327 raeburn 8230: $r->print(
1.301 bisitz 8231: &Apache::loncommon::start_data_table_row()
8232: .'<td>'.$count.'</td>'
8233: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
1.468 raeburn 8234: .'<td>'.$showreqby.'</td>'
1.301 bisitz 8235: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 8236: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
8237: if ($context eq 'course') {
8238: $r->print('<td>'.$sec.'</td>');
8239: }
8240: $r->print(
8241: '<td>'.$chgcontext.'</td>'
1.301 bisitz 8242: .'<td>'.$rolestart.'</td>'
8243: .'<td>'.$roleend.'</td>'
1.327 raeburn 8244: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 8245: }
8246:
1.327 raeburn 8247: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 8248: $r->print(&Apache::loncommon::end_data_table().
8249: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 8250: } else { # No content displayed above
1.301 bisitz 8251: $r->print('<p class="LC_info">'
8252: .&mt('There are no records to display.')
8253: .'</p>'
8254: );
1.239 raeburn 8255: }
1.301 bisitz 8256:
1.327 raeburn 8257: # Form Footer
8258: $r->print(
8259: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
8260: .'<input type="hidden" name="action" value="changelogs" />'
8261: .'</form>');
8262: return;
8263: }
1.301 bisitz 8264:
1.416 raeburn 8265: sub print_useraccesslogs_display {
8266: my ($r,$uname,$udom,$permission,$brcrum) = @_;
8267: my $formname = 'accesslog';
8268: my $form = 'document.accesslog';
8269:
8270: # set breadcrumbs
1.422 raeburn 8271: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 8272: my $prevphasestr;
8273: if ($env{'form.popup'}) {
8274: $brcrum = [];
8275: } else {
8276: push (@{$brcrum},
8277: {href => "javascript:backPage($form)",
8278: text => $breadcrumb_text{'search'}});
8279: my @prevphases;
8280: if ($env{'form.prevphases'}) {
8281: @prevphases = split(/,/,$env{'form.prevphases'});
8282: $prevphasestr = $env{'form.prevphases'};
8283: }
8284: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
8285: push(@{$brcrum},
8286: {href => "javascript:backPage($form,'get_user_info','select')",
8287: text => $breadcrumb_text{'userpicked'}});
8288: if ($env{'form.phase'} eq 'userpicked') {
8289: $prevphasestr = 'userpicked';
8290: }
1.416 raeburn 8291: }
8292: }
8293: push(@{$brcrum},
8294: {href => '/adm/createuser?action=accesslogs',
8295: text => 'User access logs',
1.424 raeburn 8296: help => 'Domain_User_Access_Logs'});
1.416 raeburn 8297: my $bread_crumbs_component = 'User Access Logs';
8298: my $args = { bread_crumbs => $brcrum,
8299: bread_crumbs_component => 'User Management'};
1.423 raeburn 8300: if ($env{'form.popup'}) {
8301: $args->{'no_nav_bar'} = 1;
1.431 raeburn 8302: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 8303: }
1.416 raeburn 8304:
1.417 raeburn 8305: # set javascript
1.416 raeburn 8306: my ($jsback,$elements) = &crumb_utilities();
8307: my $jsnav = &userlogdisplay_js($formname);
8308:
8309: my $jscript = (<<ENDSCRIPT);
8310: <script type="text/javascript">
8311: // <![CDATA[
8312:
8313: $jsback
8314: $jsnav
8315:
8316: // ]]>
8317: </script>
8318:
8319: ENDSCRIPT
8320:
1.417 raeburn 8321: # print page header
1.416 raeburn 8322: $r->print(&header($jscript,$args));
8323:
8324: # early out unless log data can be displayed.
8325: unless ($permission->{'activity'}) {
8326: $r->print('<p class="LC_warning">'
8327: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 8328: .'</p>');
8329: if ($env{'form.popup'}) {
8330: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
8331: } else {
8332: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8333: }
1.416 raeburn 8334: return;
8335: }
8336:
8337: unless ($udom eq $env{'request.role.domain'}) {
8338: $r->print('<p class="LC_warning">'
8339: .&mt("User's domain must match role's domain")
8340: .'</p>'
8341: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 8342: return;
1.416 raeburn 8343: }
8344:
8345: if (($uname eq '') || ($udom eq '')) {
8346: $r->print('<p class="LC_warning">'
8347: .&mt('Invalid username or domain')
8348: .'</p>'
8349: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8350: return;
8351: }
8352:
1.437 raeburn 8353: if (&Apache::lonnet::privileged($uname,$udom,
8354: [$env{'request.role.domain'}],['dc','su'])) {
8355: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
8356: [$env{'request.role.domain'}],['dc','su'])) {
8357: $r->print('<p class="LC_warning">'
8358: .&mt('You need to be a privileged user to display user access logs for [_1]',
8359: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
8360: $uname,$udom))
8361: .'</p>');
8362: if ($env{'form.popup'}) {
8363: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
8364: } else {
8365: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8366: }
8367: return;
8368: }
8369: }
8370:
1.416 raeburn 8371: # set defaults
8372: my $now = time();
8373: my $defstart = $now - (7*24*3600);
8374: my %defaults = (
8375: page => '1',
8376: show => '10',
8377: activity => 'any',
8378: accesslog_start_date => $defstart,
8379: accesslog_end_date => $now,
8380: );
8381: my $more_records = 0;
8382:
8383: # set current
8384: my %curr;
8385: foreach my $item ('show','page','activity') {
8386: $curr{$item} = $env{'form.'.$item};
8387: }
8388: my ($startdate,$enddate) =
8389: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
8390: $curr{'accesslog_start_date'} = $startdate;
8391: $curr{'accesslog_end_date'} = $enddate;
8392: foreach my $key (keys(%defaults)) {
8393: if ($curr{$key} eq '') {
8394: $curr{$key} = $defaults{$key};
8395: }
8396: }
8397: my ($minshown,$maxshown);
8398: $minshown = 1;
8399: my $count = 0;
8400: if ($curr{'show'} =~ /\D/) {
8401: $curr{'page'} = 1;
8402: } else {
8403: $maxshown = $curr{'page'} * $curr{'show'};
8404: if ($curr{'page'} > 1) {
8405: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
8406: }
8407: }
8408:
8409: # form header
8410: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
8411: &activity_display_filter($formname,\%curr));
8412:
8413: my $showntableheader = 0;
8414: my ($nav_script,$nav_links);
8415:
8416: # table header
1.453 raeburn 8417: my $heading = '<h3>'.
1.431 raeburn 8418: &mt('User access logs for: [_1]',
1.453 raeburn 8419: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
8420: my $tableheader = $heading
1.431 raeburn 8421: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 8422: .'<th> </th>'
8423: .'<th>'.&mt('When').'</th>'
8424: .'<th>'.&mt('HostID').'</th>'
8425: .'<th>'.&mt('Event').'</th>'
8426: .'<th>'.&mt('Other data').'</th>'
8427: .&Apache::loncommon::end_data_table_header_row();
8428:
8429: my %filters=(
8430: start => $curr{'accesslog_start_date'},
8431: end => $curr{'accesslog_end_date'},
8432: action => $curr{'activity'},
8433: );
8434:
8435: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
8436: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
8437: my (%courses,%missing);
8438: my @results = split(/\&/,$reply);
8439: foreach my $item (reverse(@results)) {
8440: my ($timestamp,$host,$event) = split(/:/,$item);
8441: next unless ($event =~ /^(Log|Role)/);
8442: if ($curr{'show'} !~ /\D/) {
8443: if ($count >= $curr{'page'} * $curr{'show'}) {
8444: $more_records = 1;
8445: last;
8446: }
8447: }
8448: $count ++;
8449: next if ($count < $minshown);
8450: unless ($showntableheader) {
8451: $r->print($nav_script
8452: .&Apache::loncommon::start_data_table()
8453: .$tableheader);
8454: $r->rflush();
8455: $showntableheader = 1;
8456: }
1.418 raeburn 8457: my ($shown,$extra);
1.437 raeburn 8458: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 8459: if ($event eq 'Role') {
8460: my ($rolecode,$extent) = split(/\./,$data,2);
8461: next if ($extent eq '');
8462: my ($crstype,$desc,$info);
1.418 raeburn 8463: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
8464: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 8465: my $cid = $cdom.'_'.$cnum;
8466: if (exists($courses{$cid})) {
8467: $crstype = $courses{$cid}{'type'};
8468: $desc = $courses{$cid}{'description'};
8469: } elsif ($missing{$cid}) {
8470: $crstype = 'Course';
8471: $desc = 'Course/Community';
8472: } else {
8473: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
8474: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
8475: $courses{$cid} = $crsinfo{$cid};
8476: $crstype = $crsinfo{$cid}{'type'};
8477: $desc = $crsinfo{$cid}{'description'};
8478: } else {
8479: $missing{$cid} = 1;
8480: }
8481: }
8482: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 8483: if ($sec ne '') {
8484: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
8485: }
1.416 raeburn 8486: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
8487: my ($dom,$name) = ($1,$2);
8488: if ($rolecode eq 'au') {
8489: $extra = '';
8490: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 8491: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 8492: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
8493: $extra = &mt('Domain: [_1]',$dom);
8494: }
8495: }
8496: my $rolename;
8497: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
8498: my $role = $3;
1.417 raeburn 8499: my $owner = "($2:$1)";
1.416 raeburn 8500: if ($2 eq $1.'-domainconfig') {
8501: $owner = '(ad hoc)';
1.417 raeburn 8502: }
1.416 raeburn 8503: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
8504: } else {
8505: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
8506: }
8507: $shown = &mt('Role selection: [_1]',$rolename);
8508: } else {
8509: $shown = &mt($event);
1.437 raeburn 8510: if ($data =~ /^webdav/) {
8511: my ($path,$clientip) = split(/\s+/,$data,2);
8512: $path =~ s/^webdav//;
8513: if ($clientip ne '') {
8514: $extra = &mt('Client IP address: [_1]',$clientip);
8515: }
8516: if ($path ne '') {
8517: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
8518: }
8519: } elsif ($data ne '') {
8520: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 8521: }
8522: }
8523: $r->print(
8524: &Apache::loncommon::start_data_table_row()
8525: .'<td>'.$count.'</td>'
8526: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
8527: .'<td>'.$host.'</td>'
8528: .'<td>'.$shown.'</td>'
8529: .'<td>'.$extra.'</td>'
8530: .&Apache::loncommon::end_data_table_row()."\n");
8531: }
8532: }
8533:
8534: if ($showntableheader) { # Table footer, if content displayed above
8535: $r->print(&Apache::loncommon::end_data_table().
8536: &userlogdisplay_navlinks(\%curr,$more_records));
8537: } else { # No content displayed above
1.453 raeburn 8538: $r->print($heading.'<p class="LC_info">'
1.416 raeburn 8539: .&mt('There are no records to display.')
8540: .'</p>');
8541: }
8542:
1.423 raeburn 8543: if ($env{'form.popup'} == 1) {
8544: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
8545: }
8546:
1.416 raeburn 8547: # Form Footer
8548: $r->print(
8549: '<input type="hidden" name="currstate" value="" />'
8550: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
8551: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
8552: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
8553: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
8554: .'<input type="hidden" name="phase" value="activity" />'
8555: .'<input type="hidden" name="action" value="accesslogs" />'
8556: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
8557: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
8558: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
8559: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
8560: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
8561: .'</form>');
8562: return;
8563: }
8564:
8565: sub earlyout_accesslog_form {
8566: my ($formname,$prevphasestr,$udom) = @_;
8567: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
8568: return <<"END";
8569: <form action="/adm/createuser" method="post" name="$formname">
8570: <input type="hidden" name="currstate" value="" />
8571: <input type="hidden" name="prevphases" value="$prevphasestr" />
8572: <input type="hidden" name="phase" value="activity" />
8573: <input type="hidden" name="action" value="accesslogs" />
8574: <input type="hidden" name="srchdomain" value="$udom" />
8575: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
8576: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
8577: <input type="hidden" name="srchterm" value="$srchterm" />
8578: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
8579: </form>
8580: END
8581: }
8582:
8583: sub activity_display_filter {
8584: my ($formname,$curr) = @_;
8585: my $nolink = 1;
8586: my $output = '<table><tr><td valign="top">'.
8587: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
1.467 raeburn 8588: &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef,
1.416 raeburn 8589: (&mt('all'),5,10,20,50,100,1000,10000)).
8590: '</td><td> </td>';
8591: my $startform =
8592: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
8593: $curr->{'accesslog_start_date'},undef,
8594: undef,undef,undef,undef,undef,undef,$nolink);
8595: my $endform =
8596: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
8597: $curr->{'accesslog_end_date'},undef,
8598: undef,undef,undef,undef,undef,undef,$nolink);
8599: my %lt = &Apache::lonlocal::texthash (
8600: activity => 'Activity',
8601: Role => 'Role selection',
8602: log => 'Log-in or Logout',
8603: );
8604: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
8605: '<table><tr><td>'.&mt('After:').
8606: '</td><td>'.$startform.'</td></tr>'.
8607: '<tr><td>'.&mt('Before:').'</td>'.
8608: '<td>'.$endform.'</td></tr></table>'.
8609: '</td>'.
8610: '<td> </td>'.
8611: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
8612: '<select name="activity"><option value="any"';
8613: if ($curr->{'activity'} eq 'any') {
8614: $output .= ' selected="selected"';
8615: }
8616: $output .= '>'.&mt('Any').'</option>'."\n";
8617: foreach my $activity ('Role','log') {
8618: my $selstr = '';
8619: if ($activity eq $curr->{'activity'}) {
8620: $selstr = ' selected="selected"';
8621: }
8622: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
8623: }
8624: $output .= '</select></td>'.
8625: '</tr></table>';
8626: # Update Display button
8627: $output .= '<p>'
8628: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 8629: .'</p><hr />';
1.416 raeburn 8630: return $output;
8631: }
8632:
1.415 raeburn 8633: sub userlogdisplay_js {
8634: my ($formname) = @_;
8635: return <<"ENDSCRIPT";
8636:
1.239 raeburn 8637: function chgPage(caller) {
8638: if (caller == 'previous') {
8639: document.$formname.page.value --;
8640: }
8641: if (caller == 'next') {
8642: document.$formname.page.value ++;
8643: }
1.327 raeburn 8644: document.$formname.submit();
1.239 raeburn 8645: return;
8646: }
8647: ENDSCRIPT
1.415 raeburn 8648: }
8649:
8650: sub userlogdisplay_navlinks {
8651: my ($curr,$more_records) = @_;
8652: return unless(ref($curr) eq 'HASH');
8653: # Navigation Buttons
8654: my $nav_links = '<p>';
8655: if (($curr->{'page'} > 1) || ($more_records)) {
8656: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
8657: $nav_links .= '<input type="button"'
8658: .' onclick="javascript:chgPage('."'previous'".');"'
8659: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
8660: .'" /> ';
8661: }
8662: if ($more_records) {
8663: $nav_links .= '<input type="button"'
8664: .' onclick="javascript:chgPage('."'next'".');"'
8665: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
8666: .'" />';
1.301 bisitz 8667: }
8668: }
1.415 raeburn 8669: $nav_links .= '</p>';
8670: return $nav_links;
1.239 raeburn 8671: }
8672:
8673: sub role_display_filter {
1.363 raeburn 8674: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
1.239 raeburn 8675: my $nolink = 1;
8676: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 8677: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.467 raeburn 8678: &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef,
1.239 raeburn 8679: (&mt('all'),5,10,20,50,100,1000,10000)).
8680: '</td><td> </td>';
8681: my $startform =
8682: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
8683: $curr->{'rolelog_start_date'},undef,
8684: undef,undef,undef,undef,undef,undef,$nolink);
8685: my $endform =
8686: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
8687: $curr->{'rolelog_end_date'},undef,
8688: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 8689: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 8690: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
8691: '<table><tr><td>'.&mt('After:').
8692: '</td><td>'.$startform.'</td></tr>'.
8693: '<tr><td>'.&mt('Before:').'</td>'.
8694: '<td>'.$endform.'</td></tr></table>'.
8695: '</td>'.
8696: '<td> </td>'.
1.239 raeburn 8697: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
8698: '<select name="role"><option value="any"';
8699: if ($curr->{'role'} eq 'any') {
8700: $output .= ' selected="selected"';
8701: }
1.466 raeburn 8702: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 8703: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 8704: foreach my $role (@roles) {
8705: my $plrole;
8706: if ($role eq 'cr') {
8707: $plrole = &mt('Custom Role');
8708: } else {
1.318 raeburn 8709: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 8710: }
8711: my $selstr = '';
8712: if ($role eq $curr->{'role'}) {
8713: $selstr = ' selected="selected"';
8714: }
8715: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
8716: }
1.301 bisitz 8717: $output .= '</select></td>'.
8718: '<td> </td>'.
8719: '<td valign="top"><b>'.
1.239 raeburn 8720: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 8721: my @posscontexts;
8722: if ($context eq 'course') {
1.468 raeburn 8723: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype','ltienroll');
1.363 raeburn 8724: } elsif ($context eq 'domain') {
8725: @posscontexts = ('any','domain','requestauthor','domconfig','server');
8726: } else {
1.470 raeburn 8727: @posscontexts = ('any','author','coauthor','domain');
1.457 raeburn 8728: }
1.363 raeburn 8729: foreach my $chgtype (@posscontexts) {
1.239 raeburn 8730: my $selstr = '';
8731: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 8732: $selstr = ' selected="selected"';
1.239 raeburn 8733: }
1.363 raeburn 8734: if ($context eq 'course') {
1.376 raeburn 8735: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 8736: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
8737: }
1.239 raeburn 8738: }
8739: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 8740: }
1.468 raeburn 8741: my @possapprovals = ('any','none','domain','user');
8742: my %apptxt = &approval_types();
8743: $output .= '</select></td>'.
8744: '<td> </td>'.
8745: '<td valign="top"><b>'.
8746: &mt('Approvals:').'</b><br /><select name="approvals">';
8747: foreach my $approval (@possapprovals) {
8748: my $selstr = '';
8749: if ($curr->{'approvals'} eq $approval) {
8750: $selstr = ' selected="selected"';
8751: }
8752: $output .= '<option value="'.$approval.'"'.$selstr.'>'.$apptxt{$approval}.'</option>';
8753: }
8754: $output .= '</select></td></tr></table>';
1.303 bisitz 8755:
8756: # Update Display button
8757: $output .= '<p>'
8758: .'<input type="submit" value="'.&mt('Update Display').'" />'
8759: .'</p>';
8760:
8761: # Server version info
1.363 raeburn 8762: my $needsrev = '2.11.0';
8763: if ($context eq 'course') {
8764: $needsrev = '2.7.0';
8765: }
8766:
1.303 bisitz 8767: $output .= '<p class="LC_info">'
8768: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 8769: ,$needsrev);
1.248 raeburn 8770: if ($version) {
1.303 bisitz 8771: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
8772: }
8773: $output .= '</p><hr />';
1.239 raeburn 8774: return $output;
8775: }
8776:
8777: sub rolechg_contexts {
1.363 raeburn 8778: my ($context,$crstype) = @_;
8779: my %lt;
8780: if ($context eq 'course') {
8781: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 8782: any => 'Any',
1.376 raeburn 8783: automated => 'Automated Enrollment',
1.457 raeburn 8784: chgtype => 'Enrollment Type/Lock Change',
1.239 raeburn 8785: updatenow => 'Roster Update',
8786: createcourse => 'Course Creation',
8787: course => 'User Management in course',
8788: domain => 'User Management in domain',
1.313 raeburn 8789: selfenroll => 'Self-enrolled',
1.318 raeburn 8790: requestcourses => 'Course Request',
1.468 raeburn 8791: ltienroll => 'Enrollment via LTI',
1.239 raeburn 8792: );
1.363 raeburn 8793: if ($crstype eq 'Community') {
8794: $lt{'createcourse'} = &mt('Community Creation');
8795: $lt{'course'} = &mt('User Management in community');
8796: $lt{'requestcourses'} = &mt('Community Request');
8797: }
8798: } elsif ($context eq 'domain') {
8799: %lt = &Apache::lonlocal::texthash (
8800: any => 'Any',
8801: domain => 'User Management in domain',
8802: requestauthor => 'Authoring Request',
8803: server => 'Command line script (DC role)',
8804: domconfig => 'Self-enrolled',
8805: );
8806: } else {
8807: %lt = &Apache::lonlocal::texthash (
8808: any => 'Any',
8809: domain => 'User Management in domain',
8810: author => 'User Management by author',
1.470 raeburn 8811: coauthor => 'User Management by coauthor',
1.363 raeburn 8812: );
8813: }
1.239 raeburn 8814: return %lt;
8815: }
8816:
1.468 raeburn 8817: sub approval_types {
8818: return &Apache::lonlocal::texthash (
8819: any => 'Any',
8820: none => 'No approval needed',
8821: user => 'Role recipient approval',
8822: domain => 'Domain coordinator approval',
8823: );
8824: }
8825:
1.428 raeburn 8826: sub print_helpdeskaccess_display {
8827: my ($r,$permission,$brcrum) = @_;
8828: my $formname = 'helpdeskaccess';
8829: my $helpitem = 'Course_Helpdesk_Access';
8830: push (@{$brcrum},
8831: {href => '/adm/createuser?action=helpdesk',
8832: text => 'Helpdesk Access',
8833: help => $helpitem});
8834: my $bread_crumbs_component = 'Helpdesk Staff Access';
8835: my $args = { bread_crumbs => $brcrum,
8836: bread_crumbs_component => $bread_crumbs_component};
8837:
8838: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8839: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8840: my $confname = $cdom.'-domainconfig';
8841: my $crstype = &Apache::loncommon::course_type();
8842:
1.434 raeburn 8843: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 8844: my ($numstatustypes,@jsarray);
8845: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8846: if (ref($types) eq 'ARRAY') {
1.430 raeburn 8847: if (@{$types} > 0) {
1.428 raeburn 8848: $numstatustypes = scalar(@{$types});
8849: push(@accesstypes,'status');
8850: @jsarray = ('bystatus');
8851: }
8852: }
8853: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 8854: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8855: if (keys(%domhelpdesk)) {
8856: push(@accesstypes,('inc','exc'));
8857: push(@jsarray,('notinc','notexc'));
8858: }
8859: push(@jsarray,'privs');
8860: my $hiddenstr = join("','",@jsarray);
8861: my $rolestr = join("','",sort(keys(%customroles)));
8862:
8863: my $jscript;
8864: my (%settings,%overridden);
8865: if (keys(%customroles)) {
8866: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8867: $types,\%customroles,\%settings,\%overridden);
8868: my %jsfull=();
8869: my %jslevels= (
8870: course => {},
8871: domain => {},
8872: system => {},
8873: );
8874: my %jslevelscurrent=(
8875: course => {},
8876: domain => {},
8877: system => {},
8878: );
8879: my (%privs,%jsprivs);
8880: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
8881: foreach my $priv (keys(%jsfull)) {
8882: if ($jslevels{'course'}{$priv}) {
8883: $jsprivs{$priv} = 1;
8884: }
8885: }
8886: my (%elements,%stored);
8887: foreach my $role (keys(%customroles)) {
8888: $elements{$role.'_access'} = 'radio';
8889: $elements{$role.'_incrs'} = 'radio';
8890: if ($numstatustypes) {
8891: $elements{$role.'_status'} = 'checkbox';
8892: }
8893: if (keys(%domhelpdesk) > 0) {
8894: $elements{$role.'_staff_inc'} = 'checkbox';
8895: $elements{$role.'_staff_exc'} = 'checkbox';
8896: }
1.430 raeburn 8897: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 8898: if (ref($settings{$role}) eq 'HASH') {
8899: if ($settings{$role}{'access'} ne '') {
8900: my $curraccess = $settings{$role}{'access'};
8901: $stored{$role.'_access'} = $curraccess;
8902: $stored{$role.'_incrs'} = 1;
8903: if ($curraccess eq 'status') {
8904: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
8905: $stored{$role.'_status'} = $settings{$role}{'status'};
8906: }
8907: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8908: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
8909: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
8910: }
8911: }
8912: } else {
8913: $stored{$role.'_incrs'} = 0;
8914: }
8915: $stored{$role.'_override'} = [];
8916: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
8917: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
8918: foreach my $priv (@{$settings{$role}{'off'}}) {
8919: push(@{$stored{$role.'_override'}},$priv);
8920: }
8921: }
8922: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
8923: foreach my $priv (@{$settings{$role}{'on'}}) {
8924: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
8925: push(@{$stored{$role.'_override'}},$priv);
8926: }
8927: }
8928: }
8929: }
8930: } else {
8931: $stored{$role.'_incrs'} = 0;
8932: }
8933: }
8934: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
8935: }
8936:
8937: my $js = <<"ENDJS";
8938: <script type="text/javascript">
8939: // <![CDATA[
8940: $jscript;
8941:
8942: function switchRoleTab(caller,role) {
8943: if (document.getElementById(role+'_maindiv')) {
8944: if (caller.id != 'LC_current_minitab') {
8945: if (document.getElementById('LC_current_minitab')) {
8946: document.getElementById('LC_current_minitab').id=null;
8947: }
8948: var roledivs = Array('$rolestr');
8949: if (roledivs.length > 0) {
8950: for (var i=0; i<roledivs.length; i++) {
8951: if (document.getElementById(roledivs[i]+'_maindiv')) {
8952: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
8953: }
8954: }
8955: }
8956: caller.id = 'LC_current_minitab';
8957: document.getElementById(role+'_maindiv').style.display='block';
8958: }
8959: }
8960: return false;
1.430 raeburn 8961: }
1.428 raeburn 8962:
8963: function helpdeskAccess(role) {
8964: var curraccess = null;
8965: if (document.$formname.elements[role+'_access'].length) {
8966: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
8967: if (document.$formname.elements[role+'_access'][i].checked) {
8968: curraccess = document.$formname.elements[role+'_access'][i].value;
8969: }
8970: }
8971: }
8972: var shown = Array();
8973: var hidden = Array();
8974: if (curraccess == 'none') {
1.430 raeburn 8975: hidden = Array ('$hiddenstr');
1.428 raeburn 8976: } else {
8977: if (curraccess == 'status') {
1.430 raeburn 8978: shown = Array ('bystatus','privs');
8979: hidden = Array ('notinc','notexc');
1.428 raeburn 8980: } else {
8981: if (curraccess == 'exc') {
8982: shown = Array ('notexc','privs');
8983: hidden = Array ('notinc','bystatus');
8984: }
8985: if (curraccess == 'inc') {
8986: shown = Array ('notinc','privs');
8987: hidden = Array ('notexc','bystatus');
8988: }
8989: if (curraccess == 'all') {
8990: shown = Array ('privs');
8991: hidden = Array ('notinc','notexc','bystatus');
8992: }
8993: }
8994: }
8995: if (hidden.length > 0) {
8996: for (var i=0; i<hidden.length; i++) {
8997: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 8998: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 8999: }
9000: }
9001: }
9002: if (shown.length > 0) {
9003: for (var i=0; i<shown.length; i++) {
9004: if (document.getElementById(role+'_'+shown[i])) {
9005: if (shown[i] == 'privs') {
9006: document.getElementById(role+'_'+shown[i]).style.display = 'block';
9007: } else {
9008: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
9009: }
9010: }
9011: }
9012: }
9013: return;
9014: }
9015:
9016: function toggleAccess(role) {
9017: if ((document.getElementById(role+'_setincrs')) &&
9018: (document.getElementById(role+'_setindom'))) {
9019: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
9020: if (document.$formname.elements[role+'_incrs'][i].checked) {
9021: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
9022: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 9023: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 9024: } else {
9025: document.getElementById(role+'_setincrs').style.display = 'none';
9026: document.getElementById(role+'_setindom').style.display = 'block';
9027: }
9028: break;
9029: }
9030: }
9031: }
9032: return;
9033: }
9034:
9035: // ]]>
9036: </script>
9037: ENDJS
9038:
9039: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
9040:
9041: # print page header
9042: $r->print(&header($js,$args));
9043: # print form header
9044: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
9045:
9046: if (keys(%customroles)) {
9047: my %lt = &Apache::lonlocal::texthash(
9048: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
9049: 'rou' => 'Role usage',
9050: 'whi' => 'Which helpdesk personnel may use this role?',
9051: 'udd' => 'Use domain default',
1.433 raeburn 9052: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 9053: 'dh' => 'All with domain helpdesk role',
9054: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 9055: 'none' => 'None',
9056: 'status' => 'Determined based on institutional status',
1.430 raeburn 9057: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 9058: 'exc' => 'Exclude all, but include specific personnel',
9059: 'hel' => 'Helpdesk',
9060: 'rpr' => 'Role privileges',
9061: );
9062: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
9063: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
9064: my (%domcurrent,%ordered,%description,%domusage,$disabled);
9065: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9066: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
9067: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
9068: }
9069: }
9070: my $count = 0;
9071: foreach my $role (sort(keys(%customroles))) {
9072: my ($order,$desc,$access_in_dom);
9073: if (ref($domcurrent{$role}) eq 'HASH') {
9074: $order = $domcurrent{$role}{'order'};
9075: $desc = $domcurrent{$role}{'desc'};
9076: $access_in_dom = $domcurrent{$role}{'access'};
9077: }
9078: if ($order eq '') {
9079: $order = $count;
9080: }
9081: $ordered{$order} = $role;
9082: if ($desc ne '') {
9083: $description{$role} = $desc;
9084: } else {
9085: $description{$role}= $role;
9086: }
9087: $count++;
9088: }
9089: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
9090: my @roles_by_num = ();
9091: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
9092: push(@roles_by_num,$ordered{$item});
1.430 raeburn 9093: }
1.429 raeburn 9094: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 9095: if ($permission->{'owner'}) {
9096: $r->print('<br />'.$lt{'aco'}.'</p><p>');
9097: $r->print('<input type="hidden" name="state" value="process" />'.
9098: '<input type="submit" value="'.&mt('Save changes').'" />');
9099: } else {
9100: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
9101: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
9102: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
9103: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
9104: }
9105: $disabled = ' disabled="disabled"';
9106: }
9107: $r->print('</p>');
9108:
9109: $r->print('<div id="LC_minitab_header"><ul>');
9110: my $count = 0;
9111: my %visibility;
9112: foreach my $role (@roles_by_num) {
9113: my $id;
9114: if ($count == 0) {
9115: $id=' id="LC_current_minitab"';
1.430 raeburn 9116: $visibility{$role} = ' style="display:block"';
1.428 raeburn 9117: } else {
9118: $visibility{$role} = ' style="display:none"';
9119: }
9120: $count ++;
9121: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
9122: }
9123: $r->print('</ul></div>');
9124:
9125: foreach my $role (@roles_by_num) {
9126: my %usecheck = (
9127: all => ' checked="checked"',
9128: );
9129: my %displaydiv = (
9130: status => 'none',
9131: inc => 'none',
9132: exc => 'none',
9133: priv => 'block',
9134: );
9135: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 9136: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 9137: if ($settings{$role}{'access'} ne '') {
9138: $indomvis = ' style="display:none"';
9139: $incrsvis = ' style="display:block"';
1.430 raeburn 9140: $incrscheck = ' checked="checked"';
1.428 raeburn 9141: if ($settings{$role}{'access'} ne 'all') {
9142: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
9143: delete($usecheck{'all'});
9144: if ($settings{$role}{'access'} eq 'status') {
9145: my $access = 'status';
9146: $displaydiv{$access} = 'inline';
9147: if (ref($settings{$role}{$access}) eq 'ARRAY') {
9148: $selected{$access} = $settings{$role}{$access};
9149: }
9150: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
9151: my $access = $1;
9152: $displaydiv{$access} = 'inline';
9153: if (ref($settings{$role}{$access}) eq 'ARRAY') {
9154: $selected{$access} = $settings{$role}{$access};
9155: }
9156: } elsif ($settings{$role}{'access'} eq 'none') {
9157: $displaydiv{'priv'} = 'none';
9158: }
9159: }
9160: } else {
9161: $indomcheck = ' checked="checked"';
9162: $indomvis = ' style="display:block"';
9163: $incrsvis = ' style="display:none"';
9164: }
9165: } else {
9166: $indomcheck = ' checked="checked"';
1.430 raeburn 9167: $indomvis = ' style="display:block"';
1.428 raeburn 9168: $incrsvis = ' style="display:none"';
9169: }
9170: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
9171: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
9172: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
9173: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
9174: &mt('Set here in [_1]',lc($crstype)).'</label>'.
9175: '<span>'.(' 'x2).
9176: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
9177: $lt{'udd'}.'</label><span></p>'.
9178: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
9179: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
9180: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
9181: foreach my $access (@accesstypes) {
9182: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
9183: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
9184: if ($access eq 'status') {
9185: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
9186: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
9187: $othertitle,$usertypes,$types,$disabled).
9188: '</div>');
9189: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
9190: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
9191: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
9192: \%domhelpdesk,$disabled).
9193: '</div>');
9194: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
9195: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
9196: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
9197: \%domhelpdesk,$disabled).
9198: '</div>');
9199: }
9200: $r->print('</p>');
9201: }
9202: $r->print('</div></fieldset>');
9203: my %full=();
9204: my %levels= (
9205: course => {},
9206: domain => {},
9207: system => {},
9208: );
9209: my %levelscurrent=(
9210: course => {},
9211: domain => {},
9212: system => {},
9213: );
9214: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
9215: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
9216: '<legend>'.$lt{'rpr'}.'</legend>'.
9217: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
9218: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
9219: }
1.429 raeburn 9220: if ($permission->{'owner'}) {
9221: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
9222: }
1.428 raeburn 9223: } else {
9224: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
9225: }
9226: # Form Footer
9227: $r->print('<input type="hidden" name="action" value="helpdesk" />'
9228: .'</form>');
9229: return;
9230: }
9231:
1.465 raeburn 9232: sub print_queued_roles {
9233: my ($r,$context,$permission,$brcrum) = @_;
9234: push (@{$brcrum},
9235: {href => '/adm/createuser?action=rolerequests',
9236: text => 'Role Requests (other domains)',
9237: help => ''});
9238: my $bread_crumbs_component = 'Role Requests';
9239: my $args = { bread_crumbs => $brcrum,
9240: bread_crumbs_component => $bread_crumbs_component};
9241: # print page header
9242: $r->print(&header('',$args));
9243: my ($dom,$cnum);
9244: $dom = $env{'request.role.domain'};
9245: if ($context eq 'course') {
9246: if ($env{'request.course.id'}) {
9247: if (&Apache::loncommon::course_type() eq 'Community') {
9248: $context = 'community';
9249: }
9250: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9251: }
9252: } elsif ($context eq 'author') {
9253: $cnum = $env{'user.name'};
9254: }
9255: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('othdomqueue',$dom,$cnum,$context));
9256: return;
9257: }
9258:
9259: sub print_pendingroles {
9260: my ($r,$context,$permission,$brcrum) = @_;
9261: push (@{$brcrum},
9262: {href => '/adm/createuser?action=queuedroles',
9263: text => 'Queued Role Assignments (users in this domain)',
9264: help => ''});
9265: my $bread_crumbs_component = 'Queued Role Assignments';
9266: my $args = { bread_crumbs => $brcrum,
9267: bread_crumbs_component => $bread_crumbs_component};
9268: # print page header
9269: $r->print(&header('',$args));
9270: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('othdomaction',$env{'request.role.domain'},'','domain'));
9271: return;
9272: }
9273:
9274: sub process_pendingroles {
9275: my ($r,$context,$permission,$brcrum) = @_;
9276: push (@{$brcrum},
9277: {href => '/adm/createuser?action=queuedroles',
9278: text => 'Queued Role Assignments (users in this domain)',
9279: help => ''},
9280: {href => '/adm/createuser?action=processrolereq',
9281: text => 'Process Queue',
9282: help => ''});
9283: my $bread_crumbs_component = 'Queued Role Assignments';
9284: my $args = { bread_crumbs => $brcrum,
9285: bread_crumbs_component => $bread_crumbs_component};
9286: # print page header
9287: $r->print(&header('',$args));
9288: $r->print(&Apache::loncoursequeueadmin::update_request_queue('othdombydc',
9289: $env{'request.role.domain'}));
9290: return;
9291: }
9292:
1.428 raeburn 9293: sub domain_adhoc_access {
9294: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
9295: my %domusage;
9296: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
9297: foreach my $role (keys(%{$roles})) {
9298: if (ref($domcurrent->{$role}) eq 'HASH') {
9299: my $access = $domcurrent->{$role}{'access'};
9300: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
9301: $access = 'all';
1.432 raeburn 9302: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
9303: &Apache::lonnet::plaintext('da'));
1.428 raeburn 9304: } elsif ($access eq 'status') {
9305: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
9306: my @shown;
9307: foreach my $type (@{$domcurrent->{$role}{$access}}) {
9308: unless ($type eq 'default') {
9309: if ($usertypes->{$type}) {
9310: push(@shown,$usertypes->{$type});
9311: }
9312: }
9313: }
9314: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
9315: push(@shown,$othertitle);
9316: }
9317: if (@shown) {
9318: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 9319: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
9320: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 9321: } else {
9322: $domusage{$role} = &mt('No one in the domain');
9323: }
9324: }
9325: } elsif ($access eq 'inc') {
9326: my @dominc = ();
9327: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
9328: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
9329: my ($uname,$udom) = split(/:/,$user);
9330: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
9331: }
9332: my $showninc = join(', ',@dominc);
9333: if ($showninc ne '') {
1.432 raeburn 9334: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
9335: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 9336: } else {
1.432 raeburn 9337: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
9338: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 9339: }
9340: }
9341: } elsif ($access eq 'exc') {
9342: my @domexc = ();
9343: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
9344: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
9345: my ($uname,$udom) = split(/:/,$user);
9346: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
9347: }
9348: }
9349: my $shownexc = join(', ',@domexc);
9350: if ($shownexc ne '') {
1.432 raeburn 9351: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
9352: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 9353: } else {
9354: $domusage{$role} = &mt('No one in the domain');
9355: }
9356: } elsif ($access eq 'none') {
9357: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 9358: } elsif ($access eq 'dh') {
1.433 raeburn 9359: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 9360: } elsif ($access eq 'da') {
1.433 raeburn 9361: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 9362: } elsif ($access eq 'all') {
1.432 raeburn 9363: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
9364: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 9365: }
9366: } else {
1.432 raeburn 9367: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
9368: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 9369: }
9370: }
9371: return %domusage;
9372: }
9373:
9374: sub get_domain_customroles {
9375: my ($cdom,$confname) = @_;
9376: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
9377: my %customroles;
9378: foreach my $key (keys(%existing)) {
9379: if ($key=~/^rolesdef\_(\w+)$/) {
9380: my $rolename = $1;
9381: my %privs;
9382: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
9383: $customroles{$rolename} = \%privs;
9384: }
9385: }
9386: return %customroles;
9387: }
9388:
9389: sub role_priv_table {
9390: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
9391: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
9392: (ref($levelscurrent) eq 'HASH'));
9393: my %lt=&Apache::lonlocal::texthash (
9394: 'crl' => 'Course Level Privilege',
9395: 'def' => 'Domain Defaults',
9396: 'ove' => 'Override in Course',
9397: 'ine' => 'In effect',
9398: 'dis' => 'Disabled',
9399: 'ena' => 'Enabled',
9400: );
9401: if ($crstype eq 'Community') {
9402: $lt{'ove'} = 'Override in Community',
9403: }
9404: my @status = ('Disabled','Enabled');
9405: my (%on,%off);
9406: if (ref($overridden) eq 'HASH') {
9407: if (ref($overridden->{'on'}) eq 'ARRAY') {
9408: map { $on{$_} = 1; } (@{$overridden->{'on'}});
9409: }
9410: if (ref($overridden->{'off'}) eq 'ARRAY') {
9411: map { $off{$_} = 1; } (@{$overridden->{'off'}});
9412: }
9413: }
9414: my $output=&Apache::loncommon::start_data_table().
9415: &Apache::loncommon::start_data_table_header_row().
9416: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
9417: '</th><th>'.$lt{'ine'}.'</th>'.
9418: &Apache::loncommon::end_data_table_header_row();
9419: foreach my $priv (sort(keys(%{$full}))) {
9420: next unless ($levels->{'course'}{$priv});
9421: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
9422: my ($default,$ineffect);
9423: if ($levelscurrent->{'course'}{$priv}) {
9424: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
9425: $ineffect = $default;
9426: }
9427: my ($customstatus,$checked);
9428: $output .= &Apache::loncommon::start_data_table_row().
9429: '<td>'.$privtext.'</td>'.
9430: '<td>'.$default.'</td><td>';
9431: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
9432: if ($permission->{'owner'}) {
9433: $checked = ' checked="checked"';
9434: }
9435: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 9436: $ineffect = $customstatus;
1.428 raeburn 9437: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
9438: if ($permission->{'owner'}) {
1.430 raeburn 9439: $checked = ' checked="checked"';
1.428 raeburn 9440: }
9441: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 9442: $ineffect = $customstatus;
1.428 raeburn 9443: }
9444: if ($permission->{'owner'}) {
9445: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
9446: } else {
9447: $output .= $customstatus;
9448: }
9449: $output .= '</td><td>'.$ineffect.'</td>'.
9450: &Apache::loncommon::end_data_table_row();
9451: }
9452: $output .= &Apache::loncommon::end_data_table();
9453: return $output;
9454: }
9455:
9456: sub get_adhocrole_settings {
1.430 raeburn 9457: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 9458: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
9459: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
9460: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
9461: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
9462: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
9463: $settings->{$role}{'access'} = $curraccess;
9464: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
9465: my @status = split(/,/,$rest);
9466: my @currstatus;
9467: foreach my $type (@status) {
9468: if ($type eq 'default') {
9469: push(@currstatus,$type);
9470: } elsif (grep(/^\Q$type\E$/,@{$types})) {
9471: push(@currstatus,$type);
9472: }
9473: }
9474: if (@currstatus) {
9475: $settings->{$role}{$curraccess} = \@currstatus;
9476: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
9477: my @personnel = split(/,/,$rest);
9478: $settings->{$role}{$curraccess} = \@personnel;
9479: }
9480: }
9481: }
9482: }
9483: foreach my $role (keys(%{$customroles})) {
9484: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
9485: my %currentprivs;
9486: if (ref($customroles->{$role}) eq 'HASH') {
9487: if (exists($customroles->{$role}{'course'})) {
9488: my %full=();
9489: my %levels= (
9490: course => {},
9491: domain => {},
9492: system => {},
9493: );
9494: my %levelscurrent=(
9495: course => {},
9496: domain => {},
9497: system => {},
9498: );
9499: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
9500: %currentprivs = %{$levelscurrent{'course'}};
9501: }
9502: }
9503: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
9504: next if ($item eq '');
9505: my ($rule,$rest) = split(/=/,$item);
9506: next unless (($rule eq 'off') || ($rule eq 'on'));
9507: foreach my $priv (split(/:/,$rest)) {
9508: if ($priv ne '') {
9509: if ($rule eq 'off') {
9510: push(@{$overridden->{$role}{'off'}},$priv);
9511: if ($currentprivs{$priv}) {
9512: push(@{$settings->{$role}{'off'}},$priv);
9513: }
9514: } else {
9515: push(@{$overridden->{$role}{'on'}},$priv);
9516: unless ($currentprivs{$priv}) {
9517: push(@{$settings->{$role}{'on'}},$priv);
9518: }
9519: }
9520: }
9521: }
9522: }
9523: }
9524: }
9525: return;
9526: }
9527:
9528: sub update_helpdeskaccess {
9529: my ($r,$permission,$brcrum) = @_;
9530: my $helpitem = 'Course_Helpdesk_Access';
9531: push (@{$brcrum},
9532: {href => '/adm/createuser?action=helpdesk',
9533: text => 'Helpdesk Access',
9534: help => $helpitem},
9535: {href => '/adm/createuser?action=helpdesk',
9536: text => 'Result',
9537: help => $helpitem}
9538: );
9539: my $bread_crumbs_component = 'Helpdesk Staff Access';
9540: my $args = { bread_crumbs => $brcrum,
9541: bread_crumbs_component => $bread_crumbs_component};
9542:
9543: # print page header
9544: $r->print(&header('',$args));
9545: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
9546: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
9547: return;
9548: }
1.434 raeburn 9549: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 9550: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9551: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9552: my $confname = $cdom.'-domainconfig';
9553: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
9554: my $crstype = &Apache::loncommon::course_type();
9555: my %customroles = &get_domain_customroles($cdom,$confname);
9556: my (%settings,%overridden);
9557: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
9558: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 9559: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 9560: my (%changed,%storehash,@todelete);
9561:
9562: if (keys(%customroles)) {
9563: my (%newsettings,@incrs);
9564: foreach my $role (keys(%customroles)) {
9565: $newsettings{$role} = {
9566: access => '',
9567: status => '',
9568: exc => '',
9569: inc => '',
9570: on => '',
9571: off => '',
9572: };
9573: my %current;
9574: if (ref($settings{$role}) eq 'HASH') {
9575: %current = %{$settings{$role}};
9576: }
9577: if (ref($overridden{$role}) eq 'HASH') {
9578: $current{'overridden'} = $overridden{$role};
9579: }
9580: if ($env{'form.'.$role.'_incrs'}) {
9581: my $access = $env{'form.'.$role.'_access'};
9582: if (grep(/^\Q$access\E$/,@accesstypes)) {
9583: push(@incrs,$role);
9584: unless ($current{'access'} eq $access) {
9585: $changed{$role}{'access'} = 1;
1.430 raeburn 9586: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 9587: }
9588: if ($access eq 'status') {
9589: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
9590: my @stored;
9591: my @shownstatus;
9592: if (ref($types) eq 'ARRAY') {
9593: foreach my $type (sort(@statuses)) {
9594: if ($type eq 'default') {
9595: push(@stored,$type);
9596: } elsif (grep(/^\Q$type\E$/,@{$types})) {
9597: push(@stored,$type);
9598: push(@shownstatus,$usertypes->{$type});
9599: }
9600: }
9601: if (grep(/^default$/,@statuses)) {
9602: push(@shownstatus,$othertitle);
9603: }
9604: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
9605: }
9606: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
9607: if (ref($current{'status'}) eq 'ARRAY') {
9608: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
9609: if (@diffs) {
9610: $changed{$role}{'status'} = 1;
9611: }
9612: } elsif (@stored) {
9613: $changed{$role}{'status'} = 1;
9614: }
9615: } elsif (($access eq 'inc') || ($access eq 'exc')) {
9616: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
9617: my @newspecstaff;
9618: my @stored;
9619: my @currstaff;
9620: foreach my $person (sort(@personnel)) {
9621: if ($domhelpdesk{$person}) {
1.430 raeburn 9622: push(@stored,$person);
1.428 raeburn 9623: }
9624: }
9625: if (ref($current{$access}) eq 'ARRAY') {
9626: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
9627: if (@diffs) {
9628: $changed{$role}{$access} = 1;
9629: }
9630: } elsif (@stored) {
9631: $changed{$role}{$access} = 1;
9632: }
9633: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
9634: foreach my $person (@stored) {
9635: my ($uname,$udom) = split(/:/,$person);
9636: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
9637: }
9638: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
9639: }
9640: $newsettings{$role}{'access'} = $access;
9641: }
9642: } else {
9643: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
9644: $changed{$role}{'access'} = 1;
9645: $newsettings{$role} = {};
9646: push(@todelete,'internal.adhoc.'.$role);
9647: }
9648: }
9649: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
9650: if (ref($current{'overridden'}) eq 'HASH') {
9651: push(@todelete,'internal.adhocpriv.'.$role);
9652: }
9653: } else {
9654: my %full=();
9655: my %levels= (
9656: course => {},
9657: domain => {},
9658: system => {},
9659: );
9660: my %levelscurrent=(
9661: course => {},
9662: domain => {},
9663: system => {},
9664: );
9665: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
9666: my (@updatedon,@updatedoff,@override);
9667: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 9668: if (@override) {
1.428 raeburn 9669: foreach my $priv (sort(keys(%full))) {
9670: next unless ($levels{'course'}{$priv});
9671: if (grep(/^\Q$priv\E$/,@override)) {
9672: if ($levelscurrent{'course'}{$priv}) {
9673: push(@updatedoff,$priv);
9674: } else {
9675: push(@updatedon,$priv);
9676: }
9677: }
9678: }
9679: }
9680: if (@updatedon) {
1.430 raeburn 9681: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 9682: }
9683: if (@updatedoff) {
9684: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
9685: }
9686: if (ref($current{'overridden'}) eq 'HASH') {
9687: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
9688: if (@updatedon) {
9689: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
9690: if (@diffs) {
9691: $changed{$role}{'on'} = 1;
9692: }
9693: } else {
9694: $changed{$role}{'on'} = 1;
9695: }
9696: } elsif (@updatedon) {
9697: $changed{$role}{'on'} = 1;
9698: }
9699: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
9700: if (@updatedoff) {
9701: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
9702: if (@diffs) {
9703: $changed{$role}{'off'} = 1;
9704: }
9705: } else {
9706: $changed{$role}{'off'} = 1;
9707: }
9708: } elsif (@updatedoff) {
9709: $changed{$role}{'off'} = 1;
9710: }
9711: } else {
9712: if (@updatedon) {
9713: $changed{$role}{'on'} = 1;
9714: }
9715: if (@updatedoff) {
9716: $changed{$role}{'off'} = 1;
9717: }
9718: }
9719: if (ref($changed{$role}) eq 'HASH') {
9720: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
9721: my $newpriv;
9722: if (@updatedon) {
9723: $newpriv = 'on='.join(':',@updatedon);
9724: }
9725: if (@updatedoff) {
9726: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
9727: }
9728: if ($newpriv eq '') {
9729: push(@todelete,'internal.adhocpriv.'.$role);
9730: } else {
9731: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
9732: }
9733: }
9734: }
9735: }
9736: }
9737: if (@incrs) {
9738: $storehash{'internal.adhocaccess'} = join(',',@incrs);
9739: } elsif (@todelete) {
9740: push(@todelete,'internal.adhocaccess');
9741: }
9742: if (keys(%changed)) {
9743: my ($putres,$delres);
9744: if (keys(%storehash)) {
9745: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
9746: my %newenvhash;
9747: foreach my $key (keys(%storehash)) {
9748: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
9749: }
9750: &Apache::lonnet::appenv(\%newenvhash);
9751: }
9752: if (@todelete) {
9753: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
9754: foreach my $key (@todelete) {
9755: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
9756: }
9757: }
9758: if (($putres eq 'ok') || ($delres eq 'ok')) {
9759: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
9760: my (%domcurrent,%ordered,%description,%domusage);
9761: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9762: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
9763: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
9764: }
9765: }
9766: my $count = 0;
9767: foreach my $role (sort(keys(%customroles))) {
9768: my ($order,$desc);
9769: if (ref($domcurrent{$role}) eq 'HASH') {
9770: $order = $domcurrent{$role}{'order'};
9771: $desc = $domcurrent{$role}{'desc'};
9772: }
9773: if ($order eq '') {
9774: $order = $count;
9775: }
9776: $ordered{$order} = $role;
9777: if ($desc ne '') {
9778: $description{$role} = $desc;
9779: } else {
9780: $description{$role}= $role;
9781: }
9782: $count++;
9783: }
9784: my @roles_by_num = ();
9785: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
9786: push(@roles_by_num,$ordered{$item});
9787: }
9788: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 9789: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 9790: $r->print('<ul>');
9791: foreach my $role (@roles_by_num) {
9792: next unless (ref($changed{$role}) eq 'HASH');
9793: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
9794: '<ul>');
1.430 raeburn 9795: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 9796: $r->print('<li>');
9797: if ($env{'form.'.$role.'_incrs'}) {
9798: if ($newsettings{$role}{'access'} eq 'all') {
9799: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 9800: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 9801: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
9802: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 9803: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 9804: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
9805: &Apache::lonnet::plaintext('da')));
1.428 raeburn 9806: } elsif ($newsettings{$role}{'access'} eq 'none') {
9807: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9808: } elsif ($newsettings{$role}{'access'} eq 'status') {
9809: if ($newsettings{$role}{'status'}) {
9810: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 9811: if (split(/,/,$rest) > 1) {
1.428 raeburn 9812: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
9813: $newsettings{$role}{'status'}));
9814: } else {
9815: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
9816: $newsettings{$role}{'status'}));
9817: }
9818: } else {
9819: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9820: }
9821: } elsif ($newsettings{$role}{'access'} eq 'exc') {
9822: if ($newsettings{$role}{'exc'}) {
9823: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
9824: } else {
9825: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9826: }
9827: } elsif ($newsettings{$role}{'access'} eq 'inc') {
9828: if ($newsettings{$role}{'inc'}) {
9829: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
9830: } else {
9831: $r->print(&mt('All helpdesk staff may use this role.'));
9832: }
9833: }
9834: } else {
9835: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
9836: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
9837: }
9838: $r->print('</li>');
9839: }
9840: unless ($newsettings{$role}{'access'} eq 'none') {
9841: if ($changed{$role}{'off'}) {
9842: if ($newsettings{$role}{'off'}) {
9843: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
9844: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
9845: } else {
1.430 raeburn 9846: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 9847: }
9848: }
1.430 raeburn 9849: if ($changed{$role}{'on'}) {
1.428 raeburn 9850: if ($newsettings{$role}{'on'}) {
9851: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
9852: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
9853: } else {
1.430 raeburn 9854: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 9855: }
9856: }
9857: }
9858: $r->print('</ul></li>');
9859: }
9860: $r->print('</ul>');
9861: }
9862: } else {
1.430 raeburn 9863: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 9864: }
9865: }
9866: return;
9867: }
9868:
1.27 matthew 9869: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 9870: sub user_search_result {
1.221 raeburn 9871: my ($context,$srch) = @_;
1.160 raeburn 9872: my %allhomes;
9873: my %inst_matches;
9874: my %srch_results;
1.181 raeburn 9875: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 9876: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 9877: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 9878: $response = &mt('Invalid search.');
9879: }
9880: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
9881: $response = &mt('Invalid search.');
9882: }
1.177 raeburn 9883: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 9884: $response = &mt('Invalid search.');
9885: }
9886: if ($srch->{'srchterm'} eq '') {
9887: $response = &mt('You must enter a search term.');
9888: }
1.183 raeburn 9889: if ($srch->{'srchterm'} =~ /^\s+$/) {
9890: $response = &mt('Your search term must contain more than just spaces.');
9891: }
1.160 raeburn 9892: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
9893: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 9894: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 9895: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
9896: }
9897: }
9898: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
9899: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 9900: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 9901: my $unamecheck = $srch->{'srchterm'};
9902: if ($srch->{'srchtype'} eq 'contains') {
9903: if ($unamecheck !~ /^\w/) {
9904: $unamecheck = 'a'.$unamecheck;
9905: }
9906: }
9907: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 9908: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
9909: }
1.160 raeburn 9910: }
9911: }
1.180 raeburn 9912: if ($response ne '') {
1.413 raeburn 9913: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 9914: }
1.160 raeburn 9915: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 9916: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 9917: if ($instd_chk ne 'ok') {
1.412 raeburn 9918: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 9919: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 9920: if ($domd_chk eq 'ok') {
1.435 raeburn 9921: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 9922: }
1.415 raeburn 9923: $response .= '<br />';
1.412 raeburn 9924: }
9925: } else {
1.417 raeburn 9926: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 9927: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 9928: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 9929: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 9930: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 9931: if ($instd_chk eq 'ok') {
1.435 raeburn 9932: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 9933: }
1.415 raeburn 9934: $response .= '<br />';
1.412 raeburn 9935: }
1.160 raeburn 9936: }
9937: }
9938: if ($response ne '') {
1.180 raeburn 9939: return ($currstate,$response);
1.160 raeburn 9940: }
9941: if ($srch->{'srchby'} eq 'uname') {
9942: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
9943: if ($env{'form.forcenew'}) {
9944: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
9945: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
9946: if ($uhome eq 'no_host') {
9947: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 9948: my $showdom = &display_domain_info($env{'request.role.domain'});
9949: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 9950: } else {
1.179 raeburn 9951: $currstate = 'modify';
1.160 raeburn 9952: }
9953: } else {
1.179 raeburn 9954: $currstate = 'modify';
1.160 raeburn 9955: }
9956: } else {
9957: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 9958: if ($srch->{'srchtype'} eq 'exact') {
9959: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
9960: if ($uhome eq 'no_host') {
1.179 raeburn 9961: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9962: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 9963: } else {
1.179 raeburn 9964: $currstate = 'modify';
1.416 raeburn 9965: if ($env{'form.action'} eq 'accesslogs') {
9966: $currstate = 'activity';
9967: }
1.310 raeburn 9968: my $uname = $srch->{'srchterm'};
9969: my $udom = $srch->{'srchdomain'};
9970: $srch_results{$uname.':'.$udom} =
9971: { &Apache::lonnet::get('environment',
9972: ['firstname',
9973: 'lastname',
9974: 'permanentemail'],
9975: $udom,$uname)
9976: };
1.162 raeburn 9977: }
9978: } else {
9979: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 9980: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9981: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9982: }
9983: } else {
1.167 albertel 9984: my $courseusers = &get_courseusers();
1.162 raeburn 9985: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 9986: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 9987: $currstate = 'modify';
1.162 raeburn 9988: } else {
1.179 raeburn 9989: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9990: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 9991: }
1.160 raeburn 9992: } else {
1.167 albertel 9993: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 9994: my ($cuname,$cudomain) = split(/:/,$user);
9995: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 9996: my $matched = 0;
9997: if ($srch->{'srchtype'} eq 'begins') {
9998: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
9999: $matched = 1;
10000: }
10001: } else {
10002: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
10003: $matched = 1;
10004: }
10005: }
10006: if ($matched) {
1.167 albertel 10007: $srch_results{$user} =
10008: {&Apache::lonnet::get('environment',
10009: ['firstname',
10010: 'lastname',
1.194 albertel 10011: 'permanentemail'],
10012: $cudomain,$cuname)};
1.162 raeburn 10013: }
10014: }
10015: }
1.179 raeburn 10016: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10017: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 10018: }
10019: }
10020: }
10021: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 10022: $currstate = 'query';
1.160 raeburn 10023: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 10024: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
10025: if ($dirsrchres eq 'ok') {
10026: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10027: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 10028: } else {
10029: my $showdom = &display_domain_info($srch->{'srchdomain'});
10030: $response = '<span class="LC_warning">'.
10031: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
10032: '</span><br />'.
1.435 raeburn 10033: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 10034: '<br />';
1.181 raeburn 10035: }
1.160 raeburn 10036: }
10037: } else {
10038: if ($srch->{'srchin'} eq 'dom') {
10039: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 10040: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10041: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 10042: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 10043: my $courseusers = &get_courseusers();
10044: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 10045: my ($uname,$udom) = split(/:/,$user);
10046: my %names = &Apache::loncommon::getnames($uname,$udom);
10047: my %emails = &Apache::loncommon::getemails($uname,$udom);
10048: if ($srch->{'srchby'} eq 'lastname') {
10049: if ((($srch->{'srchtype'} eq 'exact') &&
10050: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 10051: (($srch->{'srchtype'} eq 'begins') &&
10052: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 10053: (($srch->{'srchtype'} eq 'contains') &&
10054: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
10055: $srch_results{$user} = {firstname => $names{'firstname'},
10056: lastname => $names{'lastname'},
10057: permanentemail => $emails{'permanentemail'},
10058: };
10059: }
10060: } elsif ($srch->{'srchby'} eq 'lastfirst') {
10061: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 10062: $srchlast =~ s/\s+$//;
10063: $srchfirst =~ s/^\s+//;
1.160 raeburn 10064: if ($srch->{'srchtype'} eq 'exact') {
10065: if (($names{'lastname'} eq $srchlast) &&
10066: ($names{'firstname'} eq $srchfirst)) {
10067: $srch_results{$user} = {firstname => $names{'firstname'},
10068: lastname => $names{'lastname'},
10069: permanentemail => $emails{'permanentemail'},
10070:
10071: };
10072: }
1.177 raeburn 10073: } elsif ($srch->{'srchtype'} eq 'begins') {
10074: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
10075: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
10076: $srch_results{$user} = {firstname => $names{'firstname'},
10077: lastname => $names{'lastname'},
10078: permanentemail => $emails{'permanentemail'},
10079: };
10080: }
10081: } else {
1.160 raeburn 10082: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
10083: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
10084: $srch_results{$user} = {firstname => $names{'firstname'},
10085: lastname => $names{'lastname'},
10086: permanentemail => $emails{'permanentemail'},
10087: };
10088: }
10089: }
10090: }
10091: }
1.179 raeburn 10092: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10093: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 10094: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 10095: $currstate = 'query';
1.160 raeburn 10096: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 10097: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
10098: if ($dirsrchres eq 'ok') {
10099: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10100: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 10101: } else {
1.412 raeburn 10102: my $showdom = &display_domain_info($srch->{'srchdomain'});
10103: $response = '<span class="LC_warning">'.
1.181 raeburn 10104: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
10105: '</span><br />'.
1.435 raeburn 10106: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 10107: '<br />';
1.181 raeburn 10108: }
1.160 raeburn 10109: }
10110: }
1.179 raeburn 10111: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 10112: }
10113:
1.412 raeburn 10114: sub domdirectorysrch_check {
10115: my ($srch) = @_;
10116: my $response;
10117: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
10118: ['directorysrch'],$srch->{'srchdomain'});
10119: my $showdom = &display_domain_info($srch->{'srchdomain'});
10120: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
10121: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
10122: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
10123: }
10124: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
10125: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
10126: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
10127: }
10128: }
10129: }
10130: return 'ok';
10131: }
10132:
10133: sub instdirectorysrch_check {
1.160 raeburn 10134: my ($srch) = @_;
10135: my $can_search = 0;
10136: my $response;
10137: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
10138: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 10139: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 10140: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
10141: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 10142: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 10143: }
10144: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
10145: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 10146: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 10147: }
10148: my @usertypes = split(/:/,$env{'environment.inststatus'});
10149: if (!@usertypes) {
10150: push(@usertypes,'default');
10151: }
10152: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
10153: foreach my $type (@usertypes) {
10154: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
10155: $can_search = 1;
10156: last;
10157: }
10158: }
10159: }
10160: if (!$can_search) {
10161: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
10162: my @longtypes;
10163: foreach my $item (@usertypes) {
1.229 raeburn 10164: if (defined($insttypes->{$item})) {
10165: push (@longtypes,$insttypes->{$item});
10166: } elsif ($item eq 'default') {
10167: push (@longtypes,&mt('other'));
10168: }
1.160 raeburn 10169: }
10170: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 10171: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 10172: }
1.160 raeburn 10173: } else {
10174: $can_search = 1;
10175: }
10176: } else {
1.180 raeburn 10177: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 10178: }
10179: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 10180: uname => 'username',
1.160 raeburn 10181: lastfirst => 'last name, first name',
1.167 albertel 10182: lastname => 'last name',
1.172 raeburn 10183: contains => 'contains',
1.178 raeburn 10184: exact => 'as exact match to',
10185: begins => 'begins with',
1.160 raeburn 10186: );
10187: if ($can_search) {
10188: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
10189: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 10190: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 10191: }
10192: } else {
1.180 raeburn 10193: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 10194: }
10195: }
10196: if ($can_search) {
1.178 raeburn 10197: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
10198: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
10199: return 'ok';
10200: } else {
1.180 raeburn 10201: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 10202: }
10203: } else {
10204: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
10205: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
10206: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
10207: return 'ok';
10208: } else {
1.180 raeburn 10209: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 10210: }
1.160 raeburn 10211: }
10212: }
10213: }
10214:
10215: sub get_courseusers {
10216: my %advhash;
1.167 albertel 10217: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 10218: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
10219: foreach my $role (sort(keys(%coursepersonnel))) {
10220: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 10221: if (!exists($classlist->{$user})) {
10222: $classlist->{$user} = [];
10223: }
1.160 raeburn 10224: }
10225: }
1.167 albertel 10226: return $classlist;
1.160 raeburn 10227: }
10228:
10229: sub build_search_response {
1.221 raeburn 10230: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 10231: my ($currstate,$response,$forcenewuser);
1.160 raeburn 10232: my %names = (
1.330 bisitz 10233: 'uname' => 'username',
10234: 'lastname' => 'last name',
1.160 raeburn 10235: 'lastfirst' => 'last name, first name',
1.330 bisitz 10236: 'crs' => 'this course',
10237: 'dom' => 'LON-CAPA domain',
10238: 'instd' => 'the institutional directory for domain',
1.160 raeburn 10239: );
10240:
10241: my %single = (
1.180 raeburn 10242: begins => 'A match',
1.160 raeburn 10243: contains => 'A match',
1.180 raeburn 10244: exact => 'An exact match',
1.160 raeburn 10245: );
10246: my %nomatch = (
1.180 raeburn 10247: begins => 'No match',
1.160 raeburn 10248: contains => 'No match',
1.180 raeburn 10249: exact => 'No exact match',
1.160 raeburn 10250: );
10251: if (keys(%srch_results) > 1) {
1.179 raeburn 10252: $currstate = 'select';
1.160 raeburn 10253: } else {
10254: if (keys(%srch_results) == 1) {
1.416 raeburn 10255: if ($env{'form.action'} eq 'accesslogs') {
10256: $currstate = 'activity';
10257: } else {
10258: $currstate = 'modify';
10259: }
1.180 raeburn 10260: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
10261: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 10262: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 10263: }
1.330 bisitz 10264: } else { # Search has nothing found. Prepare message to user.
10265: $response = '<span class="LC_warning">';
1.180 raeburn 10266: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 10267: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
10268: '<b>'.$srch->{'srchterm'}.'</b>',
10269: &display_domain_info($srch->{'srchdomain'}));
10270: } else {
10271: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
10272: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 10273: }
10274: $response .= '</span>';
1.330 bisitz 10275:
1.160 raeburn 10276: if ($srch->{'srchin'} ne 'alc') {
10277: $forcenewuser = 1;
10278: my $cansrchinst = 0;
1.438 raeburn 10279: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 10280: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
10281: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10282: if ($domconfig{'directorysrch'}{'available'}) {
10283: $cansrchinst = 1;
10284: }
10285: }
10286: }
1.180 raeburn 10287: if ((($srch->{'srchby'} eq 'lastfirst') ||
10288: ($srch->{'srchby'} eq 'lastname')) &&
10289: ($srch->{'srchin'} eq 'dom')) {
10290: if ($cansrchinst) {
10291: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 10292: }
10293: }
1.180 raeburn 10294: if ($srch->{'srchin'} eq 'crs') {
10295: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
10296: }
10297: }
1.305 raeburn 10298: my $createdom = $env{'request.role.domain'};
10299: if ($context eq 'requestcrs') {
10300: if ($env{'form.coursedom'} ne '') {
10301: $createdom = $env{'form.coursedom'};
10302: }
10303: }
1.416 raeburn 10304: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
10305: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 10306: my $cancreate =
1.305 raeburn 10307: &Apache::lonuserutils::can_create_user($createdom,$context);
10308: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 10309: if ($cancreate) {
1.305 raeburn 10310: my $showdom = &display_domain_info($createdom);
1.266 bisitz 10311: $response .= '<br /><br />'
10312: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 10313: .'<br />';
10314: if ($context eq 'requestcrs') {
10315: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
10316: } else {
10317: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
10318: }
10319: $response .='<ul><li>'
1.266 bisitz 10320: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
10321: .'</li><li>'
10322: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
10323: .'</li><li>'
10324: .&mt('Provide the proposed username')
10325: .'</li><li>'
10326: .&mt("Click 'Search'")
10327: .'</li></ul><br />';
1.221 raeburn 10328: } else {
1.422 raeburn 10329: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
10330: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
10331: $response .= '<br /><br />';
10332: if ($context eq 'requestcrs') {
10333: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
10334: } else {
10335: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
10336: }
10337: $response .= '<br />'
10338: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
10339: ,' <a'.$helplink.'>'
10340: ,'</a>')
10341: .'<br />';
1.305 raeburn 10342: }
1.221 raeburn 10343: }
1.160 raeburn 10344: }
10345: }
10346: }
1.179 raeburn 10347: return ($currstate,$response,$forcenewuser);
1.160 raeburn 10348: }
10349:
1.180 raeburn 10350: sub display_domain_info {
10351: my ($dom) = @_;
10352: my $output = $dom;
10353: if ($dom ne '') {
10354: my $domdesc = &Apache::lonnet::domain($dom,'description');
10355: if ($domdesc ne '') {
10356: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
10357: }
10358: }
10359: return $output;
10360: }
10361:
1.160 raeburn 10362: sub crumb_utilities {
10363: my %elements = (
10364: crtuser => {
10365: srchterm => 'text',
1.172 raeburn 10366: srchin => 'selectbox',
1.160 raeburn 10367: srchby => 'selectbox',
10368: srchtype => 'selectbox',
10369: srchdomain => 'selectbox',
10370: },
1.207 raeburn 10371: crtusername => {
10372: srchterm => 'text',
10373: srchdomain => 'selectbox',
10374: },
1.160 raeburn 10375: docustom => {
10376: rolename => 'selectbox',
10377: newrolename => 'textbox',
10378: },
1.179 raeburn 10379: studentform => {
10380: srchterm => 'text',
10381: srchin => 'selectbox',
10382: srchby => 'selectbox',
10383: srchtype => 'selectbox',
10384: srchdomain => 'selectbox',
10385: },
1.160 raeburn 10386: );
10387:
10388: my $jsback .= qq|
10389: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 10390: if (typeof prevphase == 'undefined') {
10391: formname.phase.value = '';
10392: }
10393: else {
10394: formname.phase.value = prevphase;
10395: }
10396: if (typeof prevstate == 'undefined') {
10397: formname.currstate.value = '';
10398: }
10399: else {
10400: formname.currstate.value = prevstate;
10401: }
1.160 raeburn 10402: formname.submit();
10403: }
10404: |;
10405: return ($jsback,\%elements);
10406: }
10407:
1.26 matthew 10408: sub course_level_table {
1.375 raeburn 10409: my ($inccourses,$showcredits,$defaultcredits) = @_;
10410: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 10411: my $table = '';
1.62 www 10412: # Custom Roles?
10413:
1.190 raeburn 10414: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 10415: my %lt=&Apache::lonlocal::texthash(
10416: 'exs' => "Existing sections",
10417: 'new' => "Define new section",
10418: 'ssd' => "Set Start Date",
10419: 'sed' => "Set End Date",
1.131 raeburn 10420: 'crl' => "Course Level",
1.89 raeburn 10421: 'act' => "Activate",
10422: 'rol' => "Role",
10423: 'ext' => "Extent",
1.113 raeburn 10424: 'grs' => "Section",
1.375 raeburn 10425: 'crd' => "Credits",
1.89 raeburn 10426: 'sta' => "Start",
10427: 'end' => "End"
10428: );
1.62 www 10429:
1.375 raeburn 10430: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 10431: my $thiscourse=$protectedcourse;
1.26 matthew 10432: $thiscourse=~s:_:/:g;
10433: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 10434: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 10435: my $area=$coursedata{'description'};
1.321 raeburn 10436: my $crstype=$coursedata{'type'};
1.135 raeburn 10437: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 10438: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 10439: my %sections_count;
1.101 albertel 10440: if (defined($env{'request.course.id'})) {
10441: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 10442: %sections_count =
10443: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 10444: }
10445: }
1.321 raeburn 10446: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 10447: foreach my $role (@roles) {
1.321 raeburn 10448: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 10449: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
10450: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 10451: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 10452: $plrole,\%sections_count,\%lt,
1.402 raeburn 10453: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 10454: } elsif ($env{'request.course.sec'} ne '') {
10455: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
10456: $env{'request.course.sec'})) {
10457: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 10458: $plrole,\%sections_count,\%lt,
1.402 raeburn 10459: $showcredits,$defaultcredits,$crstype);
1.26 matthew 10460: }
10461: }
10462: }
1.221 raeburn 10463: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 10464: foreach my $cust (sort(keys(%customroles))) {
10465: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 10466: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
10467: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 10468: $cust,\%sections_count,\%lt,
10469: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 10470: }
1.62 www 10471: }
1.26 matthew 10472: }
10473: return '' if ($table eq ''); # return nothing if there is nothing
10474: # in the table
1.188 raeburn 10475: my $result;
10476: if (!$env{'request.course.id'}) {
10477: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
10478: }
10479: $result .=
1.136 raeburn 10480: &Apache::loncommon::start_data_table().
10481: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 10482: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 10483: '<th>'.$lt{'ext'}.'</th><th>'."\n";
10484: if ($showcredits) {
10485: $result .= $lt{'crd'}.'</th>';
10486: }
10487: $result .=
1.375 raeburn 10488: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
10489: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 10490: &Apache::loncommon::end_data_table_header_row().
10491: $table.
10492: &Apache::loncommon::end_data_table();
1.26 matthew 10493: return $result;
10494: }
1.88 raeburn 10495:
1.221 raeburn 10496: sub course_level_row {
1.375 raeburn 10497: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 10498: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 10499: my $creditem;
1.222 raeburn 10500: my $row = &Apache::loncommon::start_data_table_row().
10501: ' <td><input type="checkbox" name="act_'.
10502: $protectedcourse.'_'.$role.'" /></td>'."\n".
10503: ' <td>'.$plrole.'</td>'."\n".
10504: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 10505: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 10506: $row .=
10507: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
10508: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
10509: } else {
10510: $row .= '<td> </td>';
10511: }
1.322 raeburn 10512: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 10513: $row .= '<td> </td>';
1.221 raeburn 10514: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 10515: $row .= ' <td><input type="hidden" value="'.
10516: $env{'request.course.sec'}.'" '.
10517: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
10518: $env{'request.course.sec'}.'</td>';
1.221 raeburn 10519: } else {
10520: if (ref($sections_count) eq 'HASH') {
10521: my $currsec =
10522: &Apache::lonuserutils::course_sections($sections_count,
10523: $protectedcourse.'_'.$role);
1.222 raeburn 10524: $row .= '<td><table class="LC_createuser">'."\n".
10525: '<tr class="LC_section_row">'."\n".
10526: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
10527: $currsec.'</td>'."\n".
10528: ' <td> </td>'."\n".
10529: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 10530: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
10531: '" value="" />'.
10532: '<input type="hidden" '.
10533: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 10534: '</tr></table></td>'."\n";
1.221 raeburn 10535: } else {
1.222 raeburn 10536: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 10537: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 10538: }
10539: }
1.222 raeburn 10540: $row .= <<ENDTIMEENTRY;
10541: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 10542: <a href=
10543: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$role.value,'start_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'ssd'}</a></td>
1.222 raeburn 10544: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 10545: <a href=
10546: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
10547: ENDTIMEENTRY
1.222 raeburn 10548: $row .= &Apache::loncommon::end_data_table_row();
10549: return $row;
1.221 raeburn 10550: }
10551:
1.88 raeburn 10552: sub course_level_dc {
1.375 raeburn 10553: my ($dcdom,$showcredits) = @_;
1.190 raeburn 10554: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 10555: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 10556: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
10557: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 10558: '<input type="hidden" name="dccourse" value="" />';
1.355 www 10559: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 10560: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 10561: my $credit_elem;
10562: if ($showcredits) {
10563: $credit_elem = 'credits';
10564: }
10565: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 10566: my %lt=&Apache::lonlocal::texthash(
10567: 'rol' => "Role",
1.113 raeburn 10568: 'grs' => "Section",
1.88 raeburn 10569: 'exs' => "Existing sections",
10570: 'new' => "Define new section",
10571: 'sta' => "Start",
10572: 'end' => "End",
10573: 'ssd' => "Set Start Date",
1.355 www 10574: 'sed' => "Set End Date",
1.375 raeburn 10575: 'scc' => "Course/Community",
10576: 'crd' => "Credits",
1.88 raeburn 10577: );
1.323 raeburn 10578: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 10579: &Apache::loncommon::start_data_table().
10580: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 10581: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 10582: '<th>'.$lt{'grs'}.'</th>'."\n";
10583: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
10584: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 10585: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 10586: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 10587: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
10588: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 10589: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 10590: foreach my $role (@roles) {
1.135 raeburn 10591: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 10592: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 10593: }
1.404 raeburn 10594: if ( keys(%customroles) > 0) {
10595: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 10596: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 10597: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 10598: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 10599: }
10600: }
10601: $otheritems .= '</select></td><td>'.
10602: '<table border="0" cellspacing="0" cellpadding="0">'.
10603: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 10604: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 10605: '<td> </td>'.
10606: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 10607: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 10608: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 10609: '<input type="hidden" name="groups" value="" />'.
10610: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 10611: '</tr></table></td>'."\n";
10612: if ($showcredits) {
10613: $otheritems .= '<td><br />'."\n".
1.397 bisitz 10614: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 10615: }
1.88 raeburn 10616: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 10617: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 10618: <a href=
10619: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 10620: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 10621: <a href=
10622: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
10623: ENDTIMEENTRY
1.136 raeburn 10624: $otheritems .= &Apache::loncommon::end_data_table_row().
10625: &Apache::loncommon::end_data_table()."\n";
1.470 raeburn 10626: return $cb_jscript.$hiddenitems.$header.$otheritems;
1.88 raeburn 10627: }
10628:
1.237 raeburn 10629: sub update_selfenroll_config {
1.400 raeburn 10630: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 10631: return unless (ref($currsettings) eq 'HASH');
10632: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
10633: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 10634: my (%changes,%warning);
1.241 raeburn 10635: my $curr_types;
1.400 raeburn 10636: my %noedit;
10637: unless ($context eq 'domain') {
10638: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
10639: }
1.237 raeburn 10640: if (ref($row) eq 'ARRAY') {
10641: foreach my $item (@{$row}) {
1.400 raeburn 10642: next if ($noedit{$item});
1.237 raeburn 10643: if ($item eq 'enroll_dates') {
10644: my (%currenrolldate,%newenrolldate);
10645: foreach my $type ('start','end') {
1.398 raeburn 10646: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 10647: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
10648: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
10649: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
10650: }
10651: }
10652: } elsif ($item eq 'access_dates') {
10653: my (%currdate,%newdate);
10654: foreach my $type ('start','end') {
1.398 raeburn 10655: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 10656: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
10657: if ($newdate{$type} ne $currdate{$type}) {
10658: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
10659: }
10660: }
1.241 raeburn 10661: } elsif ($item eq 'types') {
1.398 raeburn 10662: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 10663: if ($env{'form.selfenroll_all'}) {
10664: if ($curr_types ne '*') {
10665: $changes{'internal.selfenroll_types'} = '*';
10666: } else {
10667: next;
10668: }
10669: } else {
1.249 raeburn 10670: my %currdoms;
1.241 raeburn 10671: my @entries = split(/;/,$curr_types);
10672: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 10673: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 10674: my $newnum = 0;
1.249 raeburn 10675: my @latesttypes;
10676: foreach my $num (@activations) {
10677: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
10678: if (@types > 0) {
1.241 raeburn 10679: @types = sort(@types);
10680: my $typestr = join(',',@types);
1.249 raeburn 10681: my $typedom = $env{'form.selfenroll_dom_'.$num};
10682: $latesttypes[$newnum] = $typedom.':'.$typestr;
10683: $currdoms{$typedom} = 1;
1.241 raeburn 10684: $newnum ++;
10685: }
10686: }
1.338 raeburn 10687: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
10688: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 10689: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
10690: if (@types > 0) {
10691: @types = sort(@types);
10692: my $typestr = join(',',@types);
10693: my $typedom = $env{'form.selfenroll_dom_'.$j};
10694: $latesttypes[$newnum] = $typedom.':'.$typestr;
10695: $currdoms{$typedom} = 1;
10696: $newnum ++;
10697: }
10698: }
10699: }
10700: if ($env{'form.selfenroll_newdom'} ne '') {
10701: my $typedom = $env{'form.selfenroll_newdom'};
10702: if ((!defined($currdoms{$typedom})) &&
10703: (&Apache::lonnet::domain($typedom) ne '')) {
10704: my $typestr;
10705: my ($othertitle,$usertypes,$types) =
10706: &Apache::loncommon::sorted_inst_types($typedom);
10707: my $othervalue = 'any';
10708: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
10709: if (@{$types} > 0) {
1.257 raeburn 10710: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 10711: $othervalue = 'other';
1.258 raeburn 10712: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 10713: }
10714: $typestr = $othervalue;
10715: } else {
10716: $typestr = $othervalue;
10717: }
10718: $latesttypes[$newnum] = $typedom.':'.$typestr;
10719: $newnum ++ ;
10720: }
10721: }
1.241 raeburn 10722: my $selfenroll_types = join(';',@latesttypes);
10723: if ($selfenroll_types ne $curr_types) {
10724: $changes{'internal.selfenroll_types'} = $selfenroll_types;
10725: }
10726: }
1.276 raeburn 10727: } elsif ($item eq 'limit') {
10728: my $newlimit = $env{'form.selfenroll_limit'};
10729: my $newcap = $env{'form.selfenroll_cap'};
10730: $newcap =~s/\s+//g;
1.398 raeburn 10731: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 10732: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 10733: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 10734: if ($newlimit ne $currlimit) {
10735: if ($newlimit ne 'none') {
10736: if ($newcap =~ /^\d+$/) {
10737: if ($newcap ne $currcap) {
10738: $changes{'internal.selfenroll_cap'} = $newcap;
10739: }
10740: $changes{'internal.selfenroll_limit'} = $newlimit;
10741: } else {
1.398 raeburn 10742: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
10743: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 10744: }
10745: } elsif ($currcap ne '') {
10746: $changes{'internal.selfenroll_cap'} = '';
10747: $changes{'internal.selfenroll_limit'} = $newlimit;
10748: }
10749: } elsif ($currlimit ne 'none') {
10750: if ($newcap =~ /^\d+$/) {
10751: if ($newcap ne $currcap) {
10752: $changes{'internal.selfenroll_cap'} = $newcap;
10753: }
10754: } else {
1.398 raeburn 10755: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
10756: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 10757: }
10758: }
10759: } elsif ($item eq 'approval') {
10760: my (@currnotified,@newnotified);
1.398 raeburn 10761: my $currapproval = $currsettings->{'selfenroll_approval'};
10762: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 10763: if ($currnotifylist ne '') {
10764: @currnotified = split(/,/,$currnotifylist);
10765: @currnotified = sort(@currnotified);
10766: }
10767: my $newapproval = $env{'form.selfenroll_approval'};
10768: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
10769: @newnotified = sort(@newnotified);
10770: if ($newapproval ne $currapproval) {
10771: $changes{'internal.selfenroll_approval'} = $newapproval;
10772: if (!$newapproval) {
10773: if ($currnotifylist ne '') {
10774: $changes{'internal.selfenroll_notifylist'} = '';
10775: }
10776: } else {
10777: my @differences =
1.295 raeburn 10778: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 10779: if (@differences > 0) {
10780: if (@newnotified > 0) {
10781: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10782: } else {
10783: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10784: }
10785: }
10786: }
10787: } else {
1.295 raeburn 10788: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 10789: if (@differences > 0) {
10790: if (@newnotified > 0) {
10791: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10792: } else {
10793: $changes{'internal.selfenroll_notifylist'} = '';
10794: }
10795: }
10796: }
1.237 raeburn 10797: } else {
1.398 raeburn 10798: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 10799: my $newval = $env{'form.selfenroll_'.$item};
10800: if ($item eq 'section') {
10801: $newval = $env{'form.sections'};
1.241 raeburn 10802: if (defined($curr_groups{$newval})) {
1.237 raeburn 10803: $newval = $curr_val;
1.398 raeburn 10804: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
10805: &mt('Group names and section names must be distinct');
1.237 raeburn 10806: } elsif ($newval eq 'all') {
10807: $newval = $curr_val;
1.274 bisitz 10808: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 10809: }
10810: if ($newval eq '') {
10811: $newval = 'none';
10812: }
10813: }
10814: if ($newval ne $curr_val) {
10815: $changes{'internal.selfenroll_'.$item} = $newval;
10816: }
1.241 raeburn 10817: }
1.237 raeburn 10818: }
10819: if (keys(%warning) > 0) {
10820: foreach my $item (@{$row}) {
10821: if (exists($warning{$item})) {
10822: $r->print($warning{$item}.'<br />');
10823: }
10824: }
10825: }
10826: if (keys(%changes) > 0) {
10827: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
10828: if ($putresult eq 'ok') {
10829: if ((exists($changes{'internal.selfenroll_types'})) ||
10830: (exists($changes{'internal.selfenroll_start_date'})) ||
10831: (exists($changes{'internal.selfenroll_end_date'}))) {
10832: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
10833: $cnum,undef,undef,'Course');
10834: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 10835: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 10836: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
10837: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 10838: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 10839: }
10840: }
10841: my $crsputresult =
10842: &Apache::lonnet::courseidput($cdom,\%crsinfo,
10843: $chome,'notime');
10844: }
10845: }
10846: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
10847: foreach my $item (@{$row}) {
10848: my $title = $item;
10849: if (ref($lt) eq 'HASH') {
10850: $title = $lt->{$item};
10851: }
10852: if ($item eq 'enroll_dates') {
10853: foreach my $type ('start','end') {
10854: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
10855: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 10856: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 10857: $title,$type,$newdate).'</li>');
10858: }
10859: }
10860: } elsif ($item eq 'access_dates') {
10861: foreach my $type ('start','end') {
10862: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
10863: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 10864: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 10865: $title,$type,$newdate).'</li>');
10866: }
10867: }
1.276 raeburn 10868: } elsif ($item eq 'limit') {
10869: if ((exists($changes{'internal.selfenroll_limit'})) ||
10870: (exists($changes{'internal.selfenroll_cap'}))) {
10871: my ($newval,$newcap);
10872: if ($changes{'internal.selfenroll_cap'} ne '') {
10873: $newcap = $changes{'internal.selfenroll_cap'}
10874: } else {
1.398 raeburn 10875: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 10876: }
10877: if ($changes{'internal.selfenroll_limit'} eq 'none') {
10878: $newval = &mt('No limit');
10879: } elsif ($changes{'internal.selfenroll_limit'} eq
10880: 'allstudents') {
10881: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
10882: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
10883: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
10884: } else {
1.398 raeburn 10885: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 10886: if ($currlimit eq 'allstudents') {
10887: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
10888: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 10889: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 10890: }
10891: }
10892: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
10893: }
10894: } elsif ($item eq 'approval') {
10895: if ((exists($changes{'internal.selfenroll_approval'})) ||
10896: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 10897: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 10898: my ($newval,$newnotify);
10899: if (exists($changes{'internal.selfenroll_notifylist'})) {
10900: $newnotify = $changes{'internal.selfenroll_notifylist'};
10901: } else {
1.398 raeburn 10902: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 10903: }
1.398 raeburn 10904: if (exists($changes{'internal.selfenroll_approval'})) {
10905: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
10906: $changes{'internal.selfenroll_approval'} = '0';
10907: }
10908: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 10909: } else {
1.398 raeburn 10910: my $currapproval = $currsettings->{'selfenroll_approval'};
10911: if ($currapproval !~ /^[012]$/) {
10912: $currapproval = 0;
1.276 raeburn 10913: }
1.398 raeburn 10914: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 10915: }
10916: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
10917: if ($newnotify) {
1.277 raeburn 10918: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 10919: } else {
1.277 raeburn 10920: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 10921: }
10922: $r->print('</li>'."\n");
10923: }
1.237 raeburn 10924: } else {
10925: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 10926: my $newval = $changes{'internal.selfenroll_'.$item};
10927: if ($item eq 'types') {
10928: if ($newval eq '') {
10929: $newval = &mt('None');
10930: } elsif ($newval eq '*') {
10931: $newval = &mt('Any user in any domain');
10932: }
1.245 raeburn 10933: } elsif ($item eq 'registered') {
10934: if ($newval eq '1') {
10935: $newval = &mt('Yes');
10936: } elsif ($newval eq '0') {
10937: $newval = &mt('No');
10938: }
1.241 raeburn 10939: }
1.244 bisitz 10940: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 10941: }
10942: }
10943: }
10944: $r->print('</ul>');
1.398 raeburn 10945: if ($env{'course.'.$cid.'.description'} ne '') {
10946: my %newenvhash;
10947: foreach my $key (keys(%changes)) {
10948: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
10949: }
10950: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 10951: }
10952: } else {
1.398 raeburn 10953: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
10954: &mt('The error was: [_1].',$putresult));
1.237 raeburn 10955: }
10956: } else {
1.249 raeburn 10957: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 10958: }
10959: } else {
1.249 raeburn 10960: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 10961: }
1.469 raeburn 10962: my $visactions = &cat_visibility($cdom);
1.400 raeburn 10963: my ($cathash,%cattype);
10964: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
10965: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
10966: $cathash = $domconfig{'coursecategories'}{'cats'};
10967: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
10968: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
10969: } else {
10970: $cathash = {};
10971: $cattype{'auth'} = 'std';
10972: $cattype{'unauth'} = 'std';
10973: }
10974: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
10975: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
10976: '<br />'.
10977: '<br />'.$visactions->{'take'}.'<ul>'.
10978: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
10979: '</ul>');
10980: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
10981: if ($currsettings->{'uniquecode'}) {
10982: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
10983: } else {
1.366 bisitz 10984: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 10985: '<br />'.
10986: '<br />'.$visactions->{'take'}.'<ul>'.
10987: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
10988: '</ul><br />');
10989: }
10990: } else {
10991: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
10992: if (ref($visactions) eq 'HASH') {
10993: if (!$visible) {
10994: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
10995: '<br />');
10996: if (ref($vismsgs) eq 'ARRAY') {
10997: $r->print('<br />'.$visactions->{'take'}.'<ul>');
10998: foreach my $item (@{$vismsgs}) {
10999: $r->print('<li>'.$visactions->{$item}.'</li>');
11000: }
11001: $r->print('</ul>');
1.256 raeburn 11002: }
1.400 raeburn 11003: $r->print($cansetvis);
1.256 raeburn 11004: }
11005: }
11006: }
1.237 raeburn 11007: return;
11008: }
11009:
1.27 matthew 11010: #---------------------------------------------- end functions for &phase_two
1.29 matthew 11011:
11012: #--------------------------------- functions for &phase_two and &phase_three
11013:
11014: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 11015:
1.1 www 11016: 1;
11017: __END__
1.2 www 11018:
11019:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>