Annotation of loncom/interface/loncreateuser.pm, revision 1.483
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.483 ! raeburn 4: # $Id: loncreateuser.pm,v 1.482 2024/09/03 03:45:35 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.483 ! raeburn 2920: my %shownfields;
! 2921: if ($env{'request.role.domain'} ne $ccdomain) {
! 2922: my %shownfields_by_type =
! 2923: &Apache::lonuserutils::get_othdom_shownfields($ccdomain,\@userinfo);
! 2924: my @types = split(/:/,$userenv{'inststatus'});
! 2925: if (@types == 0) {
! 2926: @types = ('default');
! 2927: }
! 2928: foreach my $type (@types) {
! 2929: if (ref($shownfields_by_type{$type}) eq 'HASH') {
! 2930: foreach my $field (keys(%{$shownfields_by_type{$type}})) {
! 2931: if ($shownfields_by_type{$type}{$field}) {
! 2932: $shownfields{$field} = 1;
! 2933: }
! 2934: }
! 2935: }
! 2936: }
! 2937: }
1.188 raeburn 2938: foreach my $item (@userinfo) {
2939: my $rowtitle = $lt{$item};
1.252 raeburn 2940: my $hiderow = 0;
1.188 raeburn 2941: if ($item eq 'generation') {
2942: $rowtitle = $genhelp.$rowtitle;
2943: }
1.252 raeburn 2944: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2945: if ($newuser) {
1.210 raeburn 2946: if (ref($inst_results) eq 'HASH') {
2947: if ($inst_results->{$item} ne '') {
1.252 raeburn 2948: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2949: } else {
1.252 raeburn 2950: if ($context eq 'selfcreate') {
1.391 raeburn 2951: if ($canmodify{$item}) {
1.394 raeburn 2952: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2953: $editable ++;
2954: } else {
2955: $hiderow = 1;
2956: }
1.253 raeburn 2957: } else {
1.470 raeburn 2958: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value=""'.$disabled.' />';
1.252 raeburn 2959: }
1.210 raeburn 2960: }
1.188 raeburn 2961: } else {
1.252 raeburn 2962: if ($context eq 'selfcreate') {
1.401 raeburn 2963: if ($canmodify{$item}) {
2964: if ($newuser eq 'email') {
2965: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2966: } else {
1.401 raeburn 2967: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2968: }
1.401 raeburn 2969: $editable ++;
2970: } else {
2971: $hiderow = 1;
1.252 raeburn 2972: }
1.253 raeburn 2973: } else {
1.470 raeburn 2974: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value=""'.$disabled.' />';
1.252 raeburn 2975: }
1.188 raeburn 2976: }
2977: } else {
1.219 raeburn 2978: if ($canmodify{$item}) {
1.252 raeburn 2979: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2980: if (($item eq 'id') && (!$newuser)) {
2981: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2982: }
1.188 raeburn 2983: } else {
1.483 ! raeburn 2984: if ($env{'request.role.domain'} ne $ccdomain) {
! 2985: if ($shownfields{$item}) {
! 2986: $row .= $userenv{$item};
! 2987: } else {
! 2988: $row .= &mt('not shown');
! 2989: }
! 2990: } else {
! 2991: $row .= $userenv{$item};
! 2992: }
1.188 raeburn 2993: }
2994: }
1.252 raeburn 2995: $row .= &Apache::lonhtmlcommon::row_closure(1);
2996: if (!$hiderow) {
2997: $output .= $row;
2998: $rowcount ++;
2999: }
1.188 raeburn 3000: }
1.286 raeburn 3001: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
3002: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
3003: if (ref($types) eq 'ARRAY') {
3004: if (@{$types} > 0) {
3005: my ($hiderow,$shown);
3006: if ($canmodify_status{'inststatus'}) {
3007: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
3008: } else {
3009: if ($userenv{'inststatus'} eq '') {
3010: $hiderow = 1;
1.334 raeburn 3011: } else {
3012: my @showitems;
3013: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
3014: if (exists($usertypes->{$item})) {
3015: push(@showitems,$usertypes->{$item});
3016: } else {
3017: push(@showitems,$item);
3018: }
3019: }
3020: if (@showitems) {
3021: $shown = join(', ',@showitems);
3022: } else {
3023: $hiderow = 1;
3024: }
1.286 raeburn 3025: }
3026: }
3027: if (!$hiderow) {
1.389 bisitz 3028: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 3029: $shown.&Apache::lonhtmlcommon::row_closure(1);
3030: if ($context eq 'selfcreate') {
3031: $rowcount ++;
3032: }
3033: $output .= $row;
3034: }
3035: }
3036: }
3037: }
1.391 raeburn 3038: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
3039: if ($captchaform) {
1.410 raeburn 3040: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
3041: 'LC_pick_box_title')."\n".
1.456 raeburn 3042: $captchaform."\n".'<br /><br />'.
1.391 raeburn 3043: &Apache::lonhtmlcommon::row_closure(1);
3044: $rowcount ++;
3045: }
1.456 raeburn 3046: if ($showsubmit) {
3047: my $submit_text = &mt('Create account');
3048: $output .= &Apache::lonhtmlcommon::row_title()."\n".
3049: '<br /><input type="submit" name="createaccount" value="'.
3050: $submit_text.'" />';
3051: if ($usertype ne '') {
3052: $output .= '<input type="hidden" name="type" value="'.
3053: &HTML::Entities::encode($usertype,'\'<>"&').'" />';
3054: }
3055: $output .= &Apache::lonhtmlcommon::row_closure(1);
3056: }
1.391 raeburn 3057: }
1.188 raeburn 3058: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 3059: if (wantarray) {
1.252 raeburn 3060: if ($context eq 'selfcreate') {
3061: return($output,$rowcount,$editable);
3062: } else {
1.388 bisitz 3063: return $output;
1.252 raeburn 3064: }
1.206 raeburn 3065: } else {
3066: return $output;
3067: }
1.188 raeburn 3068: }
3069:
1.286 raeburn 3070: sub pick_inst_statuses {
3071: my ($curr,$usertypes,$types) = @_;
3072: my ($output,$rem,@currtypes);
3073: if ($curr ne '') {
3074: @currtypes = map { &unescape($_); } split(/:/,$curr);
3075: }
3076: my $numinrow = 2;
3077: if (ref($types) eq 'ARRAY') {
3078: $output = '<table>';
3079: my $lastcolspan;
3080: for (my $i=0; $i<@{$types}; $i++) {
3081: if (defined($usertypes->{$types->[$i]})) {
3082: my $rem = $i%($numinrow);
3083: if ($rem == 0) {
3084: if ($i<@{$types}-1) {
3085: if ($i > 0) {
3086: $output .= '</tr>';
3087: }
3088: $output .= '<tr>';
3089: }
3090: } elsif ($i==@{$types}-1) {
3091: my $colsleft = $numinrow - $rem;
3092: if ($colsleft > 1) {
3093: $lastcolspan = ' colspan="'.$colsleft.'"';
3094: }
3095: }
3096: my $check = ' ';
3097: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
3098: $check = ' checked="checked" ';
3099: }
3100: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
3101: '<span class="LC_nobreak"><label>'.
3102: '<input type="checkbox" name="inststatus" '.
3103: 'value="'.$types->[$i].'"'.$check.'/>'.
3104: $usertypes->{$types->[$i]}.'</label></span></td>';
3105: }
3106: }
3107: $output .= '</tr></table>';
3108: }
3109: return $output;
3110: }
3111:
1.257 raeburn 3112: sub selfcreate_canmodify {
3113: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
3114: if (ref($inst_results) eq 'HASH') {
3115: my @inststatuses = &get_inststatuses($inst_results);
3116: if (@inststatuses == 0) {
3117: @inststatuses = ('default');
3118: }
3119: $rolesarray = \@inststatuses;
3120: }
3121: my %canmodify =
3122: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
3123: $rolesarray);
3124: return %canmodify;
3125: }
3126:
1.252 raeburn 3127: sub get_inststatuses {
3128: my ($insthashref) = @_;
3129: my @inststatuses = ();
3130: if (ref($insthashref) eq 'HASH') {
3131: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
3132: @inststatuses = @{$insthashref->{'inststatus'}};
3133: }
3134: }
3135: return @inststatuses;
3136: }
3137:
1.4 www 3138: # ================================================================= Phase Three
1.42 matthew 3139: sub update_user_data {
1.451 raeburn 3140: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 3141: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
3142: $env{'form.ccdomain'});
1.27 matthew 3143: # Error messages
1.188 raeburn 3144: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 3145: my $end = '</span><br /><br />';
3146: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 3147: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 3148: &mt('Return to previous page').'</a>'.
3149: &Apache::loncommon::end_page();
3150: my $now = time;
1.40 www 3151: my $title;
1.101 albertel 3152: if (exists($env{'form.makeuser'})) {
1.40 www 3153: $title='Set Privileges for New User';
3154: } else {
3155: $title='Modify User Privileges';
3156: }
1.213 raeburn 3157: my $newuser = 0;
1.160 raeburn 3158: my ($jsback,$elements) = &crumb_utilities();
3159: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 3160: '// <![CDATA['."\n".
3161: $jsback."\n".
3162: '// ]]>'."\n".
3163: '</script>'."\n";
1.422 raeburn 3164: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 3165: push (@{$brcrum},
3166: {href => "javascript:backPage(document.userupdate)",
3167: text => $breadcrumb_text{'search'},
3168: faq => 282,
3169: bug => 'Instructor Interface',}
3170: );
3171: if ($env{'form.prevphase'} eq 'userpicked') {
3172: push(@{$brcrum},
3173: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
3174: text => $breadcrumb_text{'userpicked'},
3175: faq => 282,
3176: bug => 'Instructor Interface',});
1.233 raeburn 3177: }
1.224 raeburn 3178: my $helpitem = 'Course_Change_Privileges';
3179: if ($env{'form.action'} eq 'singlestudent') {
3180: $helpitem = 'Course_Add_Student';
1.439 raeburn 3181: } elsif ($context eq 'author') {
3182: $helpitem = 'Author_Change_Privileges';
3183: } elsif ($context eq 'domain') {
3184: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 3185: }
1.351 raeburn 3186: push(@{$brcrum},
3187: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
3188: text => $breadcrumb_text{'modify'},
3189: faq => 282,
3190: bug => 'Instructor Interface',},
3191: {href => "/adm/createuser",
3192: text => "Result",
3193: faq => 282,
3194: bug => 'Instructor Interface',
3195: help => $helpitem});
3196: my $args = {bread_crumbs => $brcrum,
3197: bread_crumbs_component => 'User Management'};
3198: if ($env{'form.popup'}) {
3199: $args->{'no_nav_bar'} = 1;
3200: }
3201: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 3202: $r->print(&update_result_form($uhome));
1.27 matthew 3203: # Check Inputs
1.101 albertel 3204: if (! $env{'form.ccuname'} ) {
1.193 raeburn 3205: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 3206: return;
3207: }
1.138 albertel 3208: if ( $env{'form.ccuname'} ne
3209: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 3210: $r->print($error.&mt('Invalid login name.').' '.
3211: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 3212: $end.$rtnlink);
1.27 matthew 3213: return;
3214: }
1.101 albertel 3215: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 3216: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 3217: return;
3218: }
1.138 albertel 3219: if ( $env{'form.ccdomain'} ne
3220: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 3221: $r->print($error.&mt('Invalid domain name.').' '.
3222: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 3223: $end.$rtnlink);
1.27 matthew 3224: return;
3225: }
1.219 raeburn 3226: if ($uhome eq 'no_host') {
3227: $newuser = 1;
3228: }
1.101 albertel 3229: if (! exists($env{'form.makeuser'})) {
1.29 matthew 3230: # Modifying an existing user, so check the validity of the name
3231: if ($uhome eq 'no_host') {
1.389 bisitz 3232: $r->print(
3233: $error
3234: .'<p class="LC_error">'
3235: .&mt('Unable to determine home server for [_1] in domain [_2].',
3236: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
3237: .'</p>');
1.29 matthew 3238: return;
3239: }
3240: }
1.27 matthew 3241: # Determine authentication method and password for the user being modified
3242: my $amode='';
3243: my $genpwd='';
1.101 albertel 3244: if ($env{'form.login'} eq 'krb') {
1.41 albertel 3245: $amode='krb';
1.101 albertel 3246: $amode.=$env{'form.krbver'};
3247: $genpwd=$env{'form.krbarg'};
3248: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 3249: $amode='internal';
1.101 albertel 3250: $genpwd=$env{'form.intarg'};
3251: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 3252: $amode='unix';
1.101 albertel 3253: $genpwd=$env{'form.fsysarg'};
3254: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 3255: $amode='localauth';
1.101 albertel 3256: $genpwd=$env{'form.locarg'};
1.27 matthew 3257: $genpwd=" " if (!$genpwd);
1.449 raeburn 3258: } elsif ($env{'form.login'} eq 'lti') {
3259: $amode='lti';
3260: $genpwd=" ";
1.101 albertel 3261: } elsif (($env{'form.login'} eq 'nochange') ||
3262: ($env{'form.login'} eq '' )) {
1.34 matthew 3263: # There is no need to tell the user we did not change what they
3264: # did not ask us to change.
1.35 matthew 3265: # If they are creating a new user but have not specified login
3266: # information this will be caught below.
1.30 matthew 3267: } else {
1.367 golterma 3268: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
3269: return;
1.27 matthew 3270: }
1.164 albertel 3271:
1.188 raeburn 3272: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 3273: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
3274: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
3275: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 3276:
1.193 raeburn 3277: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 3278: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.470 raeburn 3279: my @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.449 raeburn 3280: my @requestcourses = ('official','unofficial','community','textbook','placement','lti');
1.362 raeburn 3281: my @requestauthor = ('requestauthor');
1.477 raeburn 3282: my @authordefaults = ('webdav','editors','archive');
1.286 raeburn 3283: my ($othertitle,$usertypes,$types) =
3284: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 3285: my %canmodify_status =
3286: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
3287: ['inststatus']);
1.101 albertel 3288: if ($env{'form.makeuser'}) {
1.164 albertel 3289: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 3290: # Check for the authentication mode and password
3291: if (! $amode || ! $genpwd) {
1.193 raeburn 3292: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 3293: return;
1.18 albertel 3294: }
1.29 matthew 3295: # Determine desired host
1.101 albertel 3296: my $desiredhost = $env{'form.hserver'};
1.29 matthew 3297: if (lc($desiredhost) eq 'default') {
3298: $desiredhost = undef;
3299: } else {
1.147 albertel 3300: my %home_servers =
3301: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 3302: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 3303: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
3304: return;
3305: }
3306: }
3307: # Check ID format
3308: my %checkhash;
3309: my %checks = ('id' => 1);
3310: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 3311: 'newuser' => $newuser,
1.196 raeburn 3312: 'id' => $env{'form.cid'},
1.193 raeburn 3313: );
1.196 raeburn 3314: if ($env{'form.cid'} ne '') {
3315: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
3316: \%rulematch,\%inst_results,\%curr_rules);
3317: if (ref($alerts{'id'}) eq 'HASH') {
3318: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
3319: my $domdesc =
3320: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
3321: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
3322: my $userchkmsg;
3323: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
3324: $userchkmsg =
3325: &Apache::loncommon::instrule_disallow_msg('id',
3326: $domdesc,1).
3327: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
3328: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
3329: }
3330: $r->print($error.&mt('Invalid ID format').$end.
3331: $userchkmsg.$rtnlink);
3332: return;
3333: }
3334: }
1.29 matthew 3335: }
3336: }
1.367 golterma 3337: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 3338: # Call modifyuser
3339: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 3340: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 3341: $amode,$genpwd,$env{'form.cfirstname'},
3342: $env{'form.cmiddlename'},$env{'form.clastname'},
3343: $env{'form.cgeneration'},undef,$desiredhost,
3344: $env{'form.cpermanentemail'});
1.77 www 3345: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 3346: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 3347: $env{'form.ccdomain'});
1.334 raeburn 3348: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 3349: if ($uhome ne 'no_host') {
1.334 raeburn 3350: if ($context eq 'domain') {
1.378 raeburn 3351: foreach my $name ('portfolio','author') {
3352: if ($env{'form.custom_'.$name.'quota'} == 1) {
3353: if ($env{'form.'.$name.'quota'} eq '') {
3354: $newcustom{$name.'quota'} = 0;
3355: } else {
3356: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
3357: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
3358: }
3359: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
3360: $changed{$name.'quota'} = 1;
3361: }
1.334 raeburn 3362: }
3363: }
3364: foreach my $item (@usertools) {
3365: if ($env{'form.custom'.$item} == 1) {
3366: $newcustom{$item} = $env{'form.tools_'.$item};
3367: $changed{$item} = &tool_admin($item,$newcustom{$item},
3368: \%changeHash,'tools');
3369: }
1.267 raeburn 3370: }
1.334 raeburn 3371: foreach my $item (@requestcourses) {
1.341 raeburn 3372: if ($env{'form.custom'.$item} == 1) {
3373: $newcustom{$item} = $env{'form.crsreq_'.$item};
3374: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
3375: $newcustom{$item} .= '=';
1.383 raeburn 3376: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
3377: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 3378: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
3379: }
1.334 raeburn 3380: }
1.341 raeburn 3381: $changed{$item} = &tool_admin($item,$newcustom{$item},
3382: \%changeHash,'requestcourses');
1.334 raeburn 3383: }
1.275 raeburn 3384: }
1.362 raeburn 3385: if ($env{'form.customrequestauthor'} == 1) {
3386: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
3387: $changed{'requestauthor'} = &tool_admin('requestauthor',
3388: $newcustom{'requestauthor'},
3389: \%changeHash,'requestauthor');
3390: }
1.470 raeburn 3391: if ($env{'form.customeditors'} == 1) {
3392: my @editors;
3393: my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
3394: if (@posseditors) {
3395: foreach my $editor (@posseditors) {
3396: if (grep(/^\Q$editor\E$/,@posseditors)) {
3397: unless (grep(/^\Q$editor\E$/,@editors)) {
3398: push(@editors,$editor);
3399: }
3400: }
3401: }
3402: }
3403: if (@editors) {
3404: @editors = sort(@editors);
3405: $changed{'editors'} = &tool_admin('editors',join(',',@editors),
3406: \%changeHash,'authordefaults');
3407: }
3408: }
3409: if ($env{'form.customwebdav'} == 1) {
3410: $newcustom{'webdav'} = $env{'form.authordefaults_webdav'};
3411: $changed{'webdav'} = &tool_admin('webdav',$newcustom{'webdav'},
1.479 raeburn 3412: \%changeHash,'authordefaults');
1.470 raeburn 3413: }
1.480 raeburn 3414: if ($env{'form.customarchive'} == 1) {
1.477 raeburn 3415: $newcustom{'archive'} = $env{'form.authordefaults_archive'};
3416: $changed{'archive'} = &tool_admin('archive',$newcustom{'archive'},
1.479 raeburn 3417: \%changeHash,'authordefaults');
1.477 raeburn 3418:
3419: }
1.275 raeburn 3420: }
1.334 raeburn 3421: if ($canmodify_status{'inststatus'}) {
3422: if (exists($env{'form.inststatus'})) {
3423: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3424: if (@inststatuses > 0) {
3425: $changeHash{'inststatus'} = join(',',@inststatuses);
3426: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 3427: }
3428: }
1.232 raeburn 3429: }
1.334 raeburn 3430: if (keys(%changed)) {
3431: foreach my $item (@userinfo) {
3432: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 3433: }
1.267 raeburn 3434: my $chgresult =
3435: &Apache::lonnet::put('environment',\%changeHash,
3436: $env{'form.ccdomain'},$env{'form.ccuname'});
1.470 raeburn 3437: }
1.232 raeburn 3438: }
1.454 raeburn 3439: $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
1.219 raeburn 3440: &Apache::lonnet::hostname($uhome));
1.101 albertel 3441: } elsif (($env{'form.login'} ne 'nochange') &&
3442: ($env{'form.login'} ne '' )) {
1.27 matthew 3443: # Modify user privileges
3444: if (! $amode || ! $genpwd) {
1.193 raeburn 3445: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 3446: return;
1.20 harris41 3447: }
1.395 bisitz 3448: # Only allow authentication modification if the person has authority
1.101 albertel 3449: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 3450: $r->print('Modifying authentication: '.
1.31 matthew 3451: &Apache::lonnet::modifyuserauth(
1.101 albertel 3452: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 3453: $amode,$genpwd));
1.454 raeburn 3454: $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
1.101 albertel 3455: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 3456: } else {
1.27 matthew 3457: # Okay, this is a non-fatal error.
1.452 raeburn 3458: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 3459: }
1.451 raeburn 3460: } elsif (($env{'form.intarg'} ne '') &&
3461: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
3462: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3463: $r->print('Modifying authentication: '.
3464: &Apache::lonnet::modifyuserauth(
3465: $env{'form.ccdomain'},$env{'form.ccuname'},
3466: 'internal',$env{'form.intarg'}));
1.28 matthew 3467: }
1.344 bisitz 3468: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3469: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3470: ##
1.375 raeburn 3471: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3472: if ($context eq 'course') {
1.375 raeburn 3473: ($cnum,$cdom) =
3474: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3475: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3476: if ($showcredits) {
3477: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3478: }
1.213 raeburn 3479: }
1.101 albertel 3480: if (! $env{'form.makeuser'} ) {
1.28 matthew 3481: # Check for need to change
3482: my %userenv = &Apache::lonnet::get
1.134 raeburn 3483: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3484: 'id','permanentemail','portfolioquota','authorquota','inststatus',
1.459 raeburn 3485: 'tools.aboutme','tools.blog','tools.webdav',
1.470 raeburn 3486: 'tools.portfolio','tools.timezone','tools.portaccess',
1.477 raeburn 3487: 'authormanagers','authoreditors','authorarchive','requestauthor',
1.361 raeburn 3488: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3489: 'requestcourses.community','requestcourses.textbook',
1.470 raeburn 3490: 'requestcourses.placement','requestcourses.lti',
1.384 raeburn 3491: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3492: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.471 raeburn 3493: 'reqcrsotherdom.placement','domcoord.author'],
1.160 raeburn 3494: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3495: my ($tmp) = keys(%userenv);
3496: if ($tmp =~ /^(con_lost|error)/i) {
3497: %userenv = ();
3498: }
1.471 raeburn 3499: unless (($userenv{'domcoord.author'} eq 'blocked') &&
3500: (($env{'user.name'} ne $env{'form.ccuname'}) ||
3501: ($env{'user.domain'} ne $env{'form.ccdomain'}))) {
3502: push(@authordefaults,'managers');
3503: }
1.206 raeburn 3504: my $no_forceid_alert;
3505: # Check to see if user information can be changed
3506: my %domconfig =
3507: &Apache::lonnet::get_dom('configuration',['usermodification'],
3508: $env{'form.ccdomain'});
1.213 raeburn 3509: my @statuses = ('active','future');
3510: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3511: my ($auname,$audom);
1.220 raeburn 3512: if ($context eq 'author') {
1.206 raeburn 3513: $auname = $env{'user.name'};
3514: $audom = $env{'user.domain'};
3515: }
3516: foreach my $item (keys(%roles)) {
1.220 raeburn 3517: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3518: if ($context eq 'course') {
3519: if ($cnum ne '' && $cdom ne '') {
3520: if ($rolenum eq $cnum && $roledom eq $cdom) {
3521: if (!grep(/^\Q$role\E$/,@userroles)) {
3522: push(@userroles,$role);
3523: }
3524: }
3525: }
3526: } elsif ($context eq 'author') {
3527: if ($rolenum eq $auname && $roledom eq $audom) {
1.461 raeburn 3528: if (!grep(/^\Q$role\E$/,@userroles)) {
1.206 raeburn 3529: push(@userroles,$role);
3530: }
3531: }
3532: }
3533: }
1.220 raeburn 3534: if ($env{'form.action'} eq 'singlestudent') {
3535: if (!grep(/^st$/,@userroles)) {
3536: push(@userroles,'st');
3537: }
3538: } else {
3539: # Check for course or co-author roles being activated or re-enabled
3540: if ($context eq 'author' || $context eq 'course') {
3541: foreach my $key (keys(%env)) {
3542: if ($context eq 'author') {
3543: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3544: if (!grep(/^\Q$1\E$/,@userroles)) {
3545: push(@userroles,$1);
3546: }
3547: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3548: if (!grep(/^\Q$1\E$/,@userroles)) {
3549: push(@userroles,$1);
3550: }
1.206 raeburn 3551: }
1.220 raeburn 3552: } elsif ($context eq 'course') {
3553: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3554: if (!grep(/^\Q$1\E$/,@userroles)) {
3555: push(@userroles,$1);
3556: }
3557: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3558: if (!grep(/^\Q$1\E$/,@userroles)) {
3559: push(@userroles,$1);
3560: }
1.206 raeburn 3561: }
3562: }
3563: }
3564: }
3565: }
3566: #Check to see if we can change personal data for the user
3567: my (@mod_disallowed,@longroles);
3568: foreach my $role (@userroles) {
3569: if ($role eq 'cr') {
3570: push(@longroles,'Custom');
3571: } else {
1.318 raeburn 3572: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3573: }
3574: }
1.219 raeburn 3575: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3576: foreach my $item (@userinfo) {
1.28 matthew 3577: # Strip leading and trailing whitespace
1.203 raeburn 3578: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3579: if (!$canmodify{$item}) {
1.207 raeburn 3580: if (defined($env{'form.c'.$item})) {
3581: if ($env{'form.c'.$item} ne $userenv{$item}) {
3582: push(@mod_disallowed,$item);
3583: }
1.206 raeburn 3584: }
3585: $env{'form.c'.$item} = $userenv{$item};
3586: }
1.28 matthew 3587: }
1.259 bisitz 3588: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3589: my $forceid = $env{'form.forceid'};
3590: my $recurseid = $env{'form.recurseid'};
3591: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3592: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3593: $env{'form.ccuname'});
3594: if (($uidhash{$env{'form.ccuname'}}) &&
3595: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3596: (!$forceid)) {
3597: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3598: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3599: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3600: .'<br />'
3601: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3602: .'<br />'."\n";
1.203 raeburn 3603: }
3604: }
3605: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3606: my $checkhash;
3607: my $checks = { 'id' => 1 };
3608: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3609: { 'newuser' => $newuser,
3610: 'id' => $env{'form.cid'},
3611: };
3612: &Apache::loncommon::user_rule_check($checkhash,$checks,
3613: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3614: if (ref($alerts{'id'}) eq 'HASH') {
3615: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3616: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3617: }
3618: }
3619: }
1.378 raeburn 3620: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3621: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3622: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3623: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3624: @disporder = ('inststatus');
3625: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.470 raeburn 3626: push(@disporder,('requestcourses','requestauthor','authordefaults'));
1.334 raeburn 3627: } else {
3628: push(@disporder,'reqcrsotherdom');
3629: }
3630: push(@disporder,('quota','tools'));
1.338 raeburn 3631: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3632: foreach my $name ('portfolio','author') {
3633: ($olddefquota{$name},$oldsettingstatus{$name}) =
3634: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3635: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3636: }
1.334 raeburn 3637: my %canshow;
1.220 raeburn 3638: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3639: $canshow{'quota'} = 1;
1.220 raeburn 3640: }
1.267 raeburn 3641: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3642: $canshow{'tools'} = 1;
1.267 raeburn 3643: }
1.275 raeburn 3644: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3645: $canshow{'requestcourses'} = 1;
1.300 raeburn 3646: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3647: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3648: }
1.286 raeburn 3649: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3650: $canshow{'inststatus'} = 1;
1.286 raeburn 3651: }
1.362 raeburn 3652: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3653: $canshow{'requestauthor'} = 1;
1.470 raeburn 3654: $canshow{'authordefaults'} = 1;
1.362 raeburn 3655: }
1.267 raeburn 3656: my (%changeHash,%changed);
1.286 raeburn 3657: if ($oldinststatus eq '') {
1.334 raeburn 3658: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3659: } else {
3660: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3661: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3662: } else {
1.334 raeburn 3663: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3664: }
3665: }
3666: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3667: if ($canmodify_status{'inststatus'}) {
3668: $canshow{'inststatus'} = 1;
1.286 raeburn 3669: if (exists($env{'form.inststatus'})) {
3670: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3671: if (@inststatuses > 0) {
3672: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3673: $changeHash{'inststatus'} = $newinststatus;
3674: if ($newinststatus ne $oldinststatus) {
3675: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3676: foreach my $name ('portfolio','author') {
3677: ($newdefquota{$name},$newsettingstatus{$name}) =
3678: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3679: }
1.286 raeburn 3680: }
3681: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3682: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3683: } else {
1.337 raeburn 3684: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3685: }
1.334 raeburn 3686: }
3687: } else {
3688: $newinststatus = '';
3689: $changeHash{'inststatus'} = $newinststatus;
3690: $newsettings{'inststatus'} = $othertitle;
3691: if ($newinststatus ne $oldinststatus) {
3692: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3693: foreach my $name ('portfolio','author') {
3694: ($newdefquota{$name},$newsettingstatus{$name}) =
3695: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3696: }
1.286 raeburn 3697: }
3698: }
1.334 raeburn 3699: } elsif ($context ne 'selfcreate') {
3700: $canshow{'inststatus'} = 1;
1.337 raeburn 3701: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3702: }
1.378 raeburn 3703: foreach my $name ('portfolio','author') {
3704: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3705: }
1.334 raeburn 3706: if ($context eq 'domain') {
1.378 raeburn 3707: foreach my $name ('portfolio','author') {
3708: if ($userenv{$name.'quota'} ne '') {
3709: $oldquota{$name} = $userenv{$name.'quota'};
3710: if ($env{'form.custom_'.$name.'quota'} == 1) {
3711: if ($env{'form.'.$name.'quota'} eq '') {
3712: $newquota{$name} = 0;
3713: } else {
3714: $newquota{$name} = $env{'form.'.$name.'quota'};
3715: $newquota{$name} =~ s/[^\d\.]//g;
3716: }
3717: if ($newquota{$name} != $oldquota{$name}) {
3718: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3719: $changed{$name.'quota'} = 1;
3720: }
3721: }
1.334 raeburn 3722: } else {
1.378 raeburn 3723: if ("a_admin('',\%changeHash,$name)) {
3724: $changed{$name.'quota'} = 1;
3725: $newquota{$name} = $newdefquota{$name};
3726: $newisdefault{$name} = 1;
3727: }
1.334 raeburn 3728: }
1.149 raeburn 3729: } else {
1.378 raeburn 3730: $oldisdefault{$name} = 1;
3731: $oldquota{$name} = $olddefquota{$name};
3732: if ($env{'form.custom_'.$name.'quota'} == 1) {
3733: if ($env{'form.'.$name.'quota'} eq '') {
3734: $newquota{$name} = 0;
3735: } else {
3736: $newquota{$name} = $env{'form.'.$name.'quota'};
3737: $newquota{$name} =~ s/[^\d\.]//g;
3738: }
3739: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3740: $changed{$name.'quota'} = 1;
3741: }
1.334 raeburn 3742: } else {
1.378 raeburn 3743: $newquota{$name} = $newdefquota{$name};
3744: $newisdefault{$name} = 1;
1.334 raeburn 3745: }
1.378 raeburn 3746: }
3747: if ($oldisdefault{$name}) {
3748: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3749: } else {
3750: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3751: }
3752: if ($newisdefault{$name}) {
3753: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3754: } else {
3755: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3756: }
3757: }
1.334 raeburn 3758: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3759: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3760: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3761: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3762: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.470 raeburn 3763: my ($isadv,$isauthor) =
3764: &Apache::lonnet::is_advanced_user($env{'form.ccdomain'},$env{'form.ccuname'});
3765: unless ($isauthor) {
3766: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3767: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3768: }
3769: &tool_changes('authordefaults',\@authordefaults,\%oldsettings,\%oldsettingstext,
3770: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3771: } else {
1.334 raeburn 3772: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3773: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3774: }
3775: }
1.334 raeburn 3776: foreach my $item (@userinfo) {
3777: if ($env{'form.c'.$item} ne $userenv{$item}) {
3778: $namechanged{$item} = 1;
3779: }
1.204 raeburn 3780: }
1.378 raeburn 3781: foreach my $name ('portfolio','author') {
1.390 bisitz 3782: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3783: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3784: }
1.334 raeburn 3785: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3786: my ($chgresult,$namechgresult);
3787: if (keys(%changed) > 0) {
1.470 raeburn 3788: $chgresult =
1.204 raeburn 3789: &Apache::lonnet::put('environment',\%changeHash,
3790: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3791: if ($chgresult eq 'ok') {
1.470 raeburn 3792: my ($ca_mgr_del,%ca_mgr_add);
3793: if ($changed{'managers'}) {
3794: my (@adds,@dels);
3795: if ($changeHash{'authormanagers'} eq '') {
3796: @dels = split(/,/,$userenv{'authormanagers'});
3797: } elsif ($userenv{'authormanagers'} eq '') {
3798: @adds = split(/,/,$changeHash{'authormanagers'});
3799: } else {
3800: my @old = split(/,/,$userenv{'authormanagers'});
3801: my @new = split(/,/,$changeHash{'authormanagers'});
3802: my @diffs = &Apache::loncommon::compare_arrays(\@old,\@new);
3803: if (@diffs) {
3804: foreach my $user (@diffs) {
3805: if (grep(/^\Q$user\E$/,@old)) {
3806: push(@dels,$user);
3807: } elsif (grep(/^\Q$user\E$/,@new)) {
3808: push(@adds,$user);
3809: }
3810: }
3811: }
3812: }
3813: my $key = "internal.manager./$env{'form.ccdomain'}/$env{'form.ccuname'}";
3814: if (@dels) {
3815: foreach my $user (@dels) {
3816: if ($user =~ /^($match_username):($match_domain)$/) {
3817: &Apache::lonnet::del('environment',[$key],$2,$1);
3818: }
3819: }
3820: my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
3821: if (grep(/^\Q$curruser\E$/,@dels)) {
3822: $ca_mgr_del = $key;
3823: }
3824: }
3825: if (@adds) {
3826: foreach my $user (@adds) {
3827: if ($user =~ /^($match_username):($match_domain)$/) {
3828: &Apache::lonnet::put('environment',{$key => 1},$2,$1);
3829: }
3830: }
3831: my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
3832: if (grep(/^\Q$curruser\E$/,@adds)) {
3833: $ca_mgr_add{$key} = 1;
3834: }
3835: }
3836: }
1.267 raeburn 3837: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3838: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.474 raeburn 3839: my (%newenvhash,$got_domdefs,%domdefaults,$got_userenv,
3840: %userenv);
3841: my @fromenv = keys(%changed);
3842: push(@fromenv,'inststatus');
1.270 raeburn 3843: foreach my $key (keys(%changed)) {
1.411 raeburn 3844: if (($key eq 'official') || ($key eq 'unofficial') ||
3845: ($key eq 'community') || ($key eq 'textbook') ||
1.449 raeburn 3846: ($key eq 'placement') || ($key eq 'lti')) {
1.279 raeburn 3847: $newenvhash{'environment.requestcourses.'.$key} =
3848: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3849: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3850: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3851: } else {
1.474 raeburn 3852: unless ($got_domdefs) {
3853: %domdefaults =
3854: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3855: $got_domdefs = 1;
3856: }
3857: unless ($got_userenv) {
3858: %userenv =
3859: &Apache::lonnet::userenvironment($env{'user.domain'},
3860: $env{'user.name'},@fromenv);
3861: $got_userenv = 1;
3862: }
1.279 raeburn 3863: $newenvhash{'environment.canrequest.'.$key} =
3864: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.474 raeburn 3865: $key,'reload','requestcourses',\%userenv,\%domdefaults);
1.279 raeburn 3866: }
1.362 raeburn 3867: } elsif ($key eq 'requestauthor') {
3868: $newenvhash{'environment.'.$key} = $changeHash{$key};
3869: if ($changeHash{$key}) {
3870: $newenvhash{'environment.canrequest.author'} = 1;
3871: } else {
1.474 raeburn 3872: unless ($got_domdefs) {
3873: %domdefaults =
3874: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3875: $got_domdefs = 1;
3876: }
3877: unless ($got_userenv) {
3878: %userenv =
3879: &Apache::lonnet::userenvironment($env{'user.domain'},
3880: $env{'user.name'},@fromenv);
3881: $got_userenv = 1;
3882: }
1.362 raeburn 3883: $newenvhash{'environment.canrequest.author'} =
3884: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.474 raeburn 3885: $key,'reload','requestauthor',\%userenv,\%domdefaults);
1.362 raeburn 3886: }
1.470 raeburn 3887: } elsif ($key eq 'editors') {
3888: $newenvhash{'environment.author'.$key} = $changeHash{'author'.$key};
1.474 raeburn 3889: if ($env{'form.customeditors'}) {
3890: $newenvhash{'environment.editors'} = $changeHash{'author'.$key};
3891: } else {
3892: unless ($got_domdefs) {
3893: %domdefaults =
3894: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3895: $got_domdefs = 1;
3896: }
3897: if ($domdefaults{'editors'} ne '') {
3898: $newenvhash{'environment.editors'} = $domdefaults{'editors'};
1.470 raeburn 3899: } else {
1.474 raeburn 3900: $newenvhash{'environment.editors'} = 'edit,xml';
1.470 raeburn 3901: }
3902: }
1.480 raeburn 3903: } elsif ($key eq 'archive') {
3904: $newenvhash{'environment.author.'.$key} =
3905: $changeHash{'author.'.$key};
3906: if ($changeHash{'author.'.$key} ne '') {
3907: $newenvhash{'environment.canarchive'} =
3908: $changeHash{'author.'.$key};
3909: } else {
3910: unless ($got_domdefs) {
3911: %domdefaults =
3912: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3913: $got_domdefs = 1;
3914: }
3915: $newenvhash{'environment.canarchive'} =
3916: $domdefaults{'archive'};
3917: }
1.275 raeburn 3918: } elsif ($key ne 'quota') {
1.270 raeburn 3919: $newenvhash{'environment.tools.'.$key} =
3920: $changeHash{'tools.'.$key};
1.279 raeburn 3921: if ($changeHash{'tools.'.$key} ne '') {
3922: $newenvhash{'environment.availabletools.'.$key} =
3923: $changeHash{'tools.'.$key};
3924: } else {
1.474 raeburn 3925: unless ($got_domdefs) {
3926: %domdefaults =
3927: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3928: $got_domdefs = 1;
3929: }
3930: unless ($got_userenv) {
3931: %userenv =
3932: &Apache::lonnet::userenvironment($env{'user.domain'},
3933: $env{'user.name'},@fromenv);
3934: $got_userenv = 1;
3935: }
1.279 raeburn 3936: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3937: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.474 raeburn 3938: $key,'reload','tools',\%userenv,\%domdefaults);
1.279 raeburn 3939: }
1.270 raeburn 3940: }
3941: }
1.271 raeburn 3942: if (keys(%newenvhash)) {
3943: &Apache::lonnet::appenv(\%newenvhash);
3944: }
1.470 raeburn 3945: } else {
3946: if ($ca_mgr_del) {
3947: &Apache::lonnet::delenv($ca_mgr_del);
3948: }
3949: if (keys(%ca_mgr_add)) {
3950: &Apache::lonnet::appenv(\%ca_mgr_add);
3951: }
1.267 raeburn 3952: }
1.463 raeburn 3953: if ($changed{'aboutme'}) {
3954: &Apache::loncommon::devalidate_aboutme_cache($env{'form.ccuname'},
3955: $env{'form.ccdomain'});
3956: }
1.267 raeburn 3957: }
1.204 raeburn 3958: }
1.334 raeburn 3959: if (keys(%namechanged) > 0) {
1.337 raeburn 3960: foreach my $field (@userinfo) {
3961: $changeHash{$field} = $env{'form.c'.$field};
3962: }
3963: # Make the change
1.204 raeburn 3964: $namechgresult =
3965: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3966: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3967: $changeHash{'firstname'},$changeHash{'middlename'},
3968: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3969: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3970: %userupdate = (
3971: lastname => $env{'form.clastname'},
3972: middlename => $env{'form.cmiddlename'},
3973: firstname => $env{'form.cfirstname'},
3974: generation => $env{'form.cgeneration'},
3975: id => $env{'form.cid'},
3976: );
1.204 raeburn 3977: }
1.334 raeburn 3978: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3979: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3980: # Tell the user we changed the name
1.334 raeburn 3981: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3982: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3983: \%oldsettings, \%oldsettingstext,\%newsettings,
3984: \%newsettingstext);
1.203 raeburn 3985: if ($env{'form.cid'} ne $userenv{'id'}) {
3986: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3987: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3988: if (($recurseid) &&
3989: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3990: my $idresult =
3991: &Apache::lonuserutils::propagate_id_change(
3992: $env{'form.ccuname'},$env{'form.ccdomain'},
3993: \%userupdate);
3994: $r->print('<br />'.$idresult.'<br />');
3995: }
1.196 raeburn 3996: }
1.149 raeburn 3997: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3998: ($env{'form.ccuname'} eq $env{'user.name'})) {
3999: my %newenvhash;
4000: foreach my $key (keys(%changeHash)) {
4001: $newenvhash{'environment.'.$key} = $changeHash{$key};
4002: }
1.238 raeburn 4003: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 4004: }
1.28 matthew 4005: } else { # error occurred
1.389 bisitz 4006: $r->print(
4007: '<p class="LC_error">'
4008: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
4009: '"'.$env{'form.ccuname'}.'"',
4010: '"'.$env{'form.ccdomain'}.'"')
4011: .'</p>');
1.28 matthew 4012: }
1.334 raeburn 4013: } else { # End of if ($env ... ) logic
1.275 raeburn 4014: # They did not want to change the users name, quota, tool availability,
4015: # or ability to request creation of courses,
1.267 raeburn 4016: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 4017: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 4018: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 4019: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 4020: }
1.206 raeburn 4021: if (@mod_disallowed) {
4022: my ($rolestr,$contextname);
4023: if (@longroles > 0) {
4024: $rolestr = join(', ',@longroles);
4025: } else {
4026: $rolestr = &mt('No roles');
4027: }
4028: if ($context eq 'course') {
1.399 bisitz 4029: $contextname = 'course';
1.206 raeburn 4030: } elsif ($context eq 'author') {
1.399 bisitz 4031: $contextname = 'co-author';
1.206 raeburn 4032: }
4033: $r->print(&mt('The following fields were not updated: ').'<ul>');
4034: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4035: foreach my $field (@mod_disallowed) {
4036: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
4037: }
1.207 raeburn 4038: $r->print('</ul>');
4039: if (@mod_disallowed == 1) {
1.399 bisitz 4040: $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 4041: } else {
1.399 bisitz 4042: $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 4043: }
1.292 bisitz 4044: my $helplink = 'javascript:helpMenu('."'display'".')';
4045: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
4046: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
4047: ,'<a href="'.$helplink.'">','</a>')
4048: .'<br />');
1.206 raeburn 4049: }
1.259 bisitz 4050: $r->print('<span class="LC_warning">'
4051: .$no_forceid_alert
4052: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
4053: .'</span>');
1.4 www 4054: }
1.367 golterma 4055: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 4056: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 4057: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
4058: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 4059: my $linktext = ($crstype eq 'Community' ?
4060: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
4061: $r->print(
4062: &Apache::lonhtmlcommon::actionbox([
4063: '<a href="javascript:backPage(document.userupdate)">'
4064: .($crstype eq 'Community' ?
4065: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
4066: .'</a>']));
1.220 raeburn 4067: } else {
1.375 raeburn 4068: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 4069: if (keys(%namechanged) > 0) {
1.220 raeburn 4070: if ($context eq 'course') {
4071: if (@userroles > 0) {
1.225 raeburn 4072: if ((@rolechanges == 0) ||
4073: (!(grep(/^st$/,@rolechanges)))) {
4074: if (grep(/^st$/,@userroles)) {
4075: my $classlistupdated =
4076: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 4077: $cnum,$env{'form.ccdomain'},
4078: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 4079: }
1.220 raeburn 4080: }
4081: }
4082: }
4083: }
1.226 raeburn 4084: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 4085: $env{'form.ccdomain'});
4086: if ($env{'form.popup'}) {
4087: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
4088: } else {
1.367 golterma 4089: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
4090: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
4091: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 4092: }
1.220 raeburn 4093: }
4094: }
4095:
1.334 raeburn 4096: sub display_userinfo {
1.362 raeburn 4097: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
4098: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 4099: $newsetting,$newsettingtext) = @_;
4100: return unless (ref($order) eq 'ARRAY' &&
4101: ref($canshow) eq 'HASH' &&
4102: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 4103: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 4104: ref($usertools) eq 'ARRAY' &&
4105: ref($userenv) eq 'HASH' &&
4106: ref($changedhash) eq 'HASH' &&
4107: ref($oldsetting) eq 'HASH' &&
4108: ref($oldsettingtext) eq 'HASH' &&
4109: ref($newsetting) eq 'HASH' &&
4110: ref($newsettingtext) eq 'HASH');
4111: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 4112: 'ui' => 'User Information',
1.334 raeburn 4113: 'uic' => 'User Information Changed',
4114: 'firstname' => 'First Name',
4115: 'middlename' => 'Middle Name',
4116: 'lastname' => 'Last Name',
4117: 'generation' => 'Generation',
4118: 'id' => 'Student/Employee ID',
4119: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 4120: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 4121: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 4122: 'blog' => 'Blog Availability',
1.361 raeburn 4123: 'webdav' => 'WebDAV Availability',
1.334 raeburn 4124: 'aboutme' => 'Personal Information Page Availability',
4125: 'portfolio' => 'Portfolio Availability',
1.470 raeburn 4126: 'portaccess' => 'Portfolio Shareable',
1.459 raeburn 4127: 'timezone' => 'Can set own Time Zone',
1.334 raeburn 4128: 'official' => 'Can Request Official Courses',
4129: 'unofficial' => 'Can Request Unofficial Courses',
4130: 'community' => 'Can Request Communities',
1.384 raeburn 4131: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 4132: 'placement' => 'Can Request Placement Tests',
1.449 raeburn 4133: 'lti' => 'Can Request LTI Courses',
1.362 raeburn 4134: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 4135: 'inststatus' => "Affiliation",
4136: 'prvs' => 'Previous Value:',
1.470 raeburn 4137: 'chto' => 'Changed To:',
4138: 'editors' => "Available Editors in Authoring Space",
1.473 raeburn 4139: 'managers' => "Co-authors who can add/revoke roles",
1.477 raeburn 4140: 'archive' => "Managers can download tar.gz file of Authoring Space",
1.470 raeburn 4141: 'edit' => 'Standard editor (Edit)',
4142: 'xml' => 'Text editor (EditXML)',
4143: 'daxe' => 'Daxe editor (Daxe)',
1.334 raeburn 4144: );
4145: if ($changed) {
1.372 raeburn 4146: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 4147: &Apache::loncommon::start_data_table().
4148: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 4149: $r->print("<th> </th>\n");
1.367 golterma 4150: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
4151: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
4152: $r->print(&Apache::loncommon::end_data_table_header_row());
4153: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
4154:
1.334 raeburn 4155: foreach my $item (@userinfo) {
4156: my $value = $env{'form.c'.$item};
1.367 golterma 4157: #show changes only:
1.383 raeburn 4158: unless ($value eq $userenv->{$item}){
1.367 golterma 4159: $r->print(&Apache::loncommon::start_data_table_row());
4160: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 4161: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 4162: $r->print("<td>$value </td>\n");
4163: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 4164: }
4165: }
4166: foreach my $entry (@{$order}) {
1.383 raeburn 4167: if ($canshow->{$entry}) {
1.470 raeburn 4168: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') ||
4169: ($entry eq 'requestauthor') || ($entry eq 'authordefaults')) {
1.383 raeburn 4170: my @items;
4171: if ($entry eq 'requestauthor') {
4172: @items = ($entry);
1.470 raeburn 4173: } elsif ($entry eq 'authordefaults') {
1.477 raeburn 4174: @items = ('webdav','managers','editors','archive');
1.383 raeburn 4175: } else {
4176: @items = @{$requestcourses};
1.384 raeburn 4177: }
1.383 raeburn 4178: foreach my $item (@items) {
4179: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
4180: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
4181: $r->print(&Apache::loncommon::start_data_table_row()."\n");
1.470 raeburn 4182: $r->print("<td>$lt{$item}</td><td>\n");
4183: unless ($item eq 'managers') {
4184: $r->print($oldsetting->{$item});
4185: }
1.383 raeburn 4186: if ($oldsettingtext->{$item}) {
4187: if ($oldsetting->{$item}) {
1.470 raeburn 4188: unless ($item eq 'managers') {
4189: $r->print(' -- ');
4190: }
1.383 raeburn 4191: }
4192: $r->print($oldsettingtext->{$item});
4193: }
1.470 raeburn 4194: $r->print("</td>\n<td>");
4195: unless ($item eq 'managers') {
4196: $r->print($newsetting->{$item});
4197: }
1.383 raeburn 4198: if ($newsettingtext->{$item}) {
4199: if ($newsetting->{$item}) {
1.470 raeburn 4200: unless ($item eq 'managers') {
4201: $r->print(' -- ');
4202: }
1.383 raeburn 4203: }
4204: $r->print($newsettingtext->{$item});
4205: }
4206: $r->print("</td>\n");
4207: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4208: }
4209: }
4210: } elsif ($entry eq 'tools') {
4211: foreach my $item (@{$usertools}) {
1.383 raeburn 4212: if ($newsetting->{$item} ne $oldsetting->{$item}) {
4213: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4214: $r->print("<td>$lt{$item}</td>\n");
4215: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
4216: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
4217: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4218: }
4219: }
1.378 raeburn 4220: } elsif ($entry eq 'quota') {
4221: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
4222: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
4223: foreach my $name ('portfolio','author') {
1.383 raeburn 4224: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
4225: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4226: $r->print("<td>$lt{$name.$entry}</td>\n");
4227: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
4228: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
4229: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 4230: }
4231: }
4232: }
1.334 raeburn 4233: } else {
1.383 raeburn 4234: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
4235: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4236: $r->print("<td>$lt{$entry}</td>\n");
4237: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
4238: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
4239: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4240: }
4241: }
4242: }
4243: }
1.367 golterma 4244: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 4245: } else {
4246: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
4247: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 4248: }
4249: return;
4250: }
4251:
1.275 raeburn 4252: sub tool_changes {
4253: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
4254: $changed,$newaccess,$newaccesstext) = @_;
4255: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
4256: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
4257: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
4258: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
4259: return;
4260: }
1.383 raeburn 4261: my %reqdisplay = &requestchange_display();
1.300 raeburn 4262: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 4263: my @options = ('approval','validate','autolimit');
1.306 raeburn 4264: my $optregex = join('|',@options);
1.300 raeburn 4265: my $cdom = $env{'request.role.domain'};
4266: foreach my $tool (@{$usertools}) {
1.383 raeburn 4267: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 4268: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 4269: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 4270: my ($newop,$limit);
1.314 raeburn 4271: if ($env{'form.'.$context.'_'.$tool}) {
4272: $newop = $env{'form.'.$context.'_'.$tool};
4273: if ($newop eq 'autolimit') {
1.383 raeburn 4274: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 4275: $limit =~ s/\D+//g;
4276: $newop .= '='.$limit;
4277: }
4278: }
1.300 raeburn 4279: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 4280: if ($newop) {
4281: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 4282: $changeHash,$context);
4283: if ($changed->{$tool}) {
1.383 raeburn 4284: if ($newop =~ /^autolimit/) {
4285: if ($limit) {
4286: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4287: } else {
4288: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4289: }
4290: } else {
4291: $newaccesstext->{$tool} = $reqdisplay{$newop};
4292: }
1.300 raeburn 4293: } else {
4294: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
4295: }
4296: }
4297: } else {
4298: my @curr = split(',',$userenv->{$context.'.'.$tool});
4299: my @new;
4300: my $changedoms;
1.314 raeburn 4301: foreach my $req (@curr) {
4302: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
4303: my $oldop = $1;
1.383 raeburn 4304: if ($oldop =~ /^autolimit=(\d*)/) {
4305: my $limit = $1;
4306: if ($limit) {
4307: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4308: } else {
4309: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4310: }
4311: } else {
4312: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
4313: }
1.314 raeburn 4314: if ($oldop ne $newop) {
4315: $changedoms = 1;
4316: foreach my $item (@curr) {
4317: my ($reqdom,$option) = split(':',$item);
4318: unless ($reqdom eq $cdom) {
4319: push(@new,$item);
4320: }
4321: }
4322: if ($newop) {
4323: push(@new,$cdom.':'.$newop);
1.300 raeburn 4324: }
1.314 raeburn 4325: @new = sort(@new);
1.300 raeburn 4326: }
1.314 raeburn 4327: last;
1.300 raeburn 4328: }
1.314 raeburn 4329: }
4330: if ((!$changedoms) && ($newop)) {
1.300 raeburn 4331: $changedoms = 1;
1.306 raeburn 4332: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 4333: }
4334: if ($changedoms) {
1.314 raeburn 4335: my $newdomstr;
1.300 raeburn 4336: if (@new) {
4337: $newdomstr = join(',',@new);
4338: }
4339: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
4340: $context);
4341: if ($changed->{$tool}) {
4342: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 4343: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 4344: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
4345: $limit =~ s/\D+//g;
4346: if ($limit) {
1.383 raeburn 4347: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 4348: } else {
1.383 raeburn 4349: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 4350: }
1.314 raeburn 4351: } else {
1.306 raeburn 4352: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
4353: }
1.300 raeburn 4354: } else {
1.383 raeburn 4355: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 4356: }
4357: }
4358: }
4359: }
4360: }
4361: return;
4362: }
1.470 raeburn 4363: my %tooldesc = &Apache::lonlocal::texthash(
4364: 'edit' => 'Standard editor (Edit)',
4365: 'xml' => 'Text editor (EditXML)',
4366: 'daxe' => 'Daxe editor (Daxe)',
4367: );
1.275 raeburn 4368: foreach my $tool (@{$usertools}) {
1.383 raeburn 4369: my ($newval,$limit,$envkey);
1.362 raeburn 4370: $envkey = $context.'.'.$tool;
1.306 raeburn 4371: if ($context eq 'requestcourses') {
4372: $newval = $env{'form.crsreq_'.$tool};
4373: if ($newval eq 'autolimit') {
1.383 raeburn 4374: $limit = $env{'form.crsreq_'.$tool.'_limit'};
4375: $limit =~ s/\D+//g;
4376: $newval .= '='.$limit;
1.306 raeburn 4377: }
1.362 raeburn 4378: } elsif ($context eq 'requestauthor') {
4379: $newval = $env{'form.'.$context};
4380: $envkey = $context;
1.470 raeburn 4381: } elsif ($context eq 'authordefaults') {
4382: if ($tool eq 'editors') {
4383: $envkey = 'authoreditors';
4384: if ($env{'form.customeditors'} == 1) {
4385: my @editors;
4386: my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
4387: if (@posseditors) {
4388: foreach my $editor (@posseditors) {
4389: if (grep(/^\Q$editor\E$/,@posseditors)) {
4390: unless (grep(/^\Q$editor\E$/,@editors)) {
4391: push(@editors,$editor);
4392: }
4393: }
4394: }
4395: }
4396: if (@editors) {
4397: $newval = join(',',(sort(@editors)));
4398: }
4399: }
4400: } elsif ($tool eq 'managers') {
4401: $envkey = 'authormanagers';
4402: my @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
4403: if (@possibles) {
4404: my %ca_roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},
4405: undef,['active','future'],['ca']);
4406: if (keys(%ca_roles)) {
4407: my @custommanagers;
4408: foreach my $user (@possibles) {
4409: if ($user =~ /^($match_username):($match_domain)$/) {
4410: if (exists($ca_roles{$user.':ca'})) {
4411: unless ($user eq $env{'form.ccuname'}.':'.$env{'form.ccdomain'}) {
4412: push(@custommanagers,$user);
4413: }
4414: }
4415: }
4416: }
4417: if (@custommanagers) {
4418: $newval = join(',',sort(@custommanagers));
4419: }
4420: }
4421: }
4422: } elsif ($tool eq 'webdav') {
4423: $envkey = 'tools.webdav';
4424: $newval = $env{'form.'.$context.'_'.$tool};
1.477 raeburn 4425: } elsif ($tool eq 'archive') {
4426: $envkey = 'authorarchive';
4427: $newval = $env{'form.'.$context.'_'.$tool};
1.470 raeburn 4428: }
1.314 raeburn 4429: } else {
1.306 raeburn 4430: $newval = $env{'form.'.$context.'_'.$tool};
4431: }
1.362 raeburn 4432: if ($userenv->{$envkey} ne '') {
1.275 raeburn 4433: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 4434: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4435: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
4436: my $currlimit = $1;
4437: if ($currlimit eq '') {
4438: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4439: } else {
4440: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
4441: }
4442: } elsif ($userenv->{$envkey}) {
4443: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
4444: } else {
4445: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4446: }
1.470 raeburn 4447: } elsif ($context eq 'authordefaults') {
4448: if ($tool eq 'managers') {
4449: if ($userenv->{$envkey} eq '') {
4450: $oldaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4451: } else {
4452: my $managers = $userenv->{$envkey};
4453: $managers =~ s/,/, /g;
4454: $oldaccesstext->{$tool} = $managers;
4455: }
4456: } elsif ($tool eq 'editors') {
4457: $oldaccesstext->{$tool} = &mt('can use: [_1]',
4458: join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
1.477 raeburn 4459: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4460: if ($userenv->{$envkey}) {
4461: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
4462: } else {
4463: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4464: }
4465: }
1.275 raeburn 4466: } else {
1.383 raeburn 4467: if ($userenv->{$envkey}) {
4468: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
4469: } else {
4470: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4471: }
1.275 raeburn 4472: }
1.362 raeburn 4473: $changeHash->{$envkey} = $userenv->{$envkey};
1.470 raeburn 4474: if (($env{'form.custom'.$tool} == 1) ||
4475: (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
1.362 raeburn 4476: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 4477: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
4478: $context);
1.275 raeburn 4479: if ($changed->{$tool}) {
4480: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 4481: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4482: if ($newval =~ /^autolimit/) {
4483: if ($limit) {
4484: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4485: } else {
4486: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4487: }
4488: } elsif ($newval) {
4489: $newaccesstext->{$tool} = $reqdisplay{$newval};
4490: } else {
4491: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4492: }
1.470 raeburn 4493: } elsif ($context eq 'authordefaults') {
4494: if ($tool eq 'editors') {
4495: $newaccesstext->{$tool} = &mt('can use: [_1]',
4496: join(', ', map { $tooldesc{$_} } split(/,/,$changeHash->{$envkey})));
4497: } elsif ($tool eq 'managers') {
4498: if ($changeHash->{$envkey} eq '') {
4499: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4500: } else {
4501: my $managers = $changeHash->{$envkey};
4502: $managers =~ s/,/, /g;
4503: $newaccesstext->{$tool} = $managers;
4504: }
1.477 raeburn 4505: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4506: if ($newval) {
4507: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4508: } else {
4509: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4510: }
4511: }
1.275 raeburn 4512: } else {
1.383 raeburn 4513: if ($newval) {
4514: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4515: } else {
4516: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4517: }
1.275 raeburn 4518: }
4519: } else {
4520: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 4521: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.470 raeburn 4522: if ($userenv->{$envkey} =~ /^autolimit/) {
1.383 raeburn 4523: if ($limit) {
4524: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4525: } else {
4526: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4527: }
1.470 raeburn 4528: } elsif ($userenv->{$envkey}) {
4529: $newaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
1.383 raeburn 4530: } else {
4531: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4532: }
1.470 raeburn 4533: } elsif ($context eq 'authordefaults') {
4534: if ($tool eq 'editors') {
4535: $newaccesstext->{$tool} = &mt('can use: [_1]',
4536: join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
4537: } elsif ($tool eq 'managers') {
4538: if ($userenv->{$envkey} eq '') {
4539: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4540: } else {
4541: my $managers = $userenv->{$envkey};
4542: $managers =~ s/,/, /g;
4543: $newaccesstext->{$tool} = $managers;
4544: }
1.477 raeburn 4545: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4546: if ($userenv->{$envkey}) {
4547: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4548: } else {
4549: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4550: }
4551: }
1.275 raeburn 4552: } else {
1.383 raeburn 4553: if ($userenv->{$context.'.'.$tool}) {
4554: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4555: } else {
4556: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4557: }
1.275 raeburn 4558: }
4559: }
4560: } else {
4561: $newaccess->{$tool} = $oldaccess->{$tool};
4562: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
4563: }
4564: } else {
4565: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
4566: if ($changed->{$tool}) {
4567: $newaccess->{$tool} = &mt('default');
4568: } else {
4569: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 4570: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4571: if ($newval =~ /^autolimit/) {
4572: if ($limit) {
4573: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4574: } else {
4575: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4576: }
4577: } elsif ($newval) {
4578: $newaccesstext->{$tool} = $reqdisplay{$newval};
4579: } else {
4580: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4581: }
1.470 raeburn 4582: } elsif ($context eq 'authordefaults') {
4583: if ($tool eq 'editors') {
4584: $newaccesstext->{$tool} = &mt('can use: [_1]',
4585: join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
4586: } elsif ($tool eq 'managers') {
4587: if ($newval eq '') {
4588: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4589: } else {
4590: my $managers = $newval;
4591: $managers =~ s/,/, /g;
4592: $newaccesstext->{$tool} = $managers;
4593: }
1.477 raeburn 4594: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4595: if ($userenv->{$envkey}) {
4596: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4597: } else {
4598: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4599: }
4600: }
1.275 raeburn 4601: } else {
1.383 raeburn 4602: if ($userenv->{$context.'.'.$tool}) {
4603: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4604: } else {
4605: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4606: }
1.275 raeburn 4607: }
4608: }
4609: }
4610: } else {
4611: $oldaccess->{$tool} = &mt('default');
1.470 raeburn 4612: if (($env{'form.custom'.$tool} == 1) ||
4613: (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
1.306 raeburn 4614: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
4615: $context);
1.275 raeburn 4616: if ($changed->{$tool}) {
4617: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 4618: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4619: if ($newval =~ /^autolimit/) {
4620: if ($limit) {
4621: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4622: } else {
4623: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4624: }
4625: } elsif ($newval) {
4626: $newaccesstext->{$tool} = $reqdisplay{$newval};
4627: } else {
4628: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4629: }
1.470 raeburn 4630: } elsif ($context eq 'authordefaults') {
4631: if ($tool eq 'managers') {
4632: if ($newval eq '') {
4633: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4634: } else {
4635: my $managers = $newval;
4636: $managers =~ s/,/, /g;
4637: $newaccesstext->{$tool} = $managers;
4638: }
4639: } elsif ($tool eq 'editors') {
4640: $newaccesstext->{$tool} = &mt('can use: [_1]',
4641: join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
1.477 raeburn 4642: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4643: if ($newval) {
4644: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4645: } else {
4646: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4647: }
4648: }
1.275 raeburn 4649: } else {
1.383 raeburn 4650: if ($newval) {
4651: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4652: } else {
4653: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4654: }
1.275 raeburn 4655: }
4656: } else {
4657: $newaccess->{$tool} = $oldaccess->{$tool};
4658: }
4659: } else {
4660: $newaccess->{$tool} = $oldaccess->{$tool};
4661: }
4662: }
4663: }
4664: return;
4665: }
4666:
1.220 raeburn 4667: sub update_roles {
1.375 raeburn 4668: my ($r,$context,$showcredits) = @_;
1.4 www 4669: my $now=time;
1.225 raeburn 4670: my @rolechanges;
1.465 raeburn 4671: my (%disallowed,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.466 raeburn 4672: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.465 raeburn 4673: $got_role_approvals{$context} = '';
4674: $process_by{$context} = {};
4675: my @domroles = &Apache::lonuserutils::domain_roles();
4676: my @cstrroles = &Apache::lonuserutils::construction_space_roles();
4677: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
1.73 sakharuk 4678: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 4679: foreach my $key (keys(%env)) {
1.135 raeburn 4680: next if (! $env{$key});
1.190 raeburn 4681: next if ($key eq 'form.action');
1.27 matthew 4682: # Revoke roles
1.135 raeburn 4683: if ($key=~/^form\.rev/) {
4684: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 4685: # Revoke standard role
1.170 albertel 4686: my ($scope,$role) = ($1,$2);
4687: my $result =
4688: &Apache::lonnet::revokerole($env{'form.ccdomain'},
4689: $env{'form.ccuname'},
1.239 raeburn 4690: $scope,$role,'','',$context);
1.367 golterma 4691: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4692: &mt('Revoking [_1] in [_2]',
4693: &Apache::lonnet::plaintext($role),
1.372 raeburn 4694: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4695: $result ne "ok").'<br />');
4696: if ($result ne "ok") {
4697: $r->print(&mt('Error: [_1]',$result).'<br />');
4698: }
1.170 albertel 4699: if ($role eq 'st') {
1.202 raeburn 4700: my $result =
1.198 raeburn 4701: &Apache::lonuserutils::classlist_drop($scope,
4702: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4703: $now);
1.367 golterma 4704: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 4705: }
1.225 raeburn 4706: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4707: push(@rolechanges,$role);
4708: }
1.196 raeburn 4709: }
1.195 raeburn 4710: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 4711: # Revoke custom role
1.369 bisitz 4712: my $result = &Apache::lonnet::revokecustomrole(
4713: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 4714: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4715: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 4716: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4717: $result ne 'ok').'<br />');
4718: if ($result ne "ok") {
4719: $r->print(&mt('Error: [_1]',$result).'<br />');
4720: }
1.225 raeburn 4721: if (!grep(/^cr$/,@rolechanges)) {
4722: push(@rolechanges,'cr');
4723: }
1.64 www 4724: }
1.135 raeburn 4725: } elsif ($key=~/^form\.del/) {
4726: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 4727: # Delete standard role
1.170 albertel 4728: my ($scope,$role) = ($1,$2);
4729: my $result =
4730: &Apache::lonnet::assignrole($env{'form.ccdomain'},
4731: $env{'form.ccuname'},
1.239 raeburn 4732: $scope,$role,$now,0,1,'',
4733: $context);
1.367 golterma 4734: $r->print(&Apache::lonhtmlcommon::confirm_success(
4735: &mt('Deleting [_1] in [_2]',
1.369 bisitz 4736: &Apache::lonnet::plaintext($role),
1.372 raeburn 4737: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4738: $result ne 'ok').'<br />');
4739: if ($result ne "ok") {
4740: $r->print(&mt('Error: [_1]',$result).'<br />');
4741: }
1.367 golterma 4742:
1.170 albertel 4743: if ($role eq 'st') {
1.202 raeburn 4744: my $result =
1.198 raeburn 4745: &Apache::lonuserutils::classlist_drop($scope,
4746: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4747: $now);
1.369 bisitz 4748: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 4749: }
1.225 raeburn 4750: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4751: push(@rolechanges,$role);
4752: }
1.116 raeburn 4753: }
1.139 albertel 4754: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4755: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4756: # Delete custom role
1.369 bisitz 4757: my $result =
4758: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
4759: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
4760: 0,1,$context);
4761: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 4762: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4763: $result ne "ok").'<br />');
4764: if ($result ne "ok") {
4765: $r->print(&mt('Error: [_1]',$result).'<br />');
4766: }
1.367 golterma 4767:
1.225 raeburn 4768: if (!grep(/^cr$/,@rolechanges)) {
4769: push(@rolechanges,'cr');
4770: }
1.116 raeburn 4771: }
1.135 raeburn 4772: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4773: my $udom = $env{'form.ccdomain'};
4774: my $uname = $env{'form.ccuname'};
1.116 raeburn 4775: # Re-enable standard role
1.135 raeburn 4776: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4777: my $url = $1;
4778: my $role = $2;
1.465 raeburn 4779: my $id = $url.'_'.$role;
1.89 raeburn 4780: my $logmsg;
4781: my $output;
4782: if ($role eq 'st') {
1.141 albertel 4783: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4784: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4785: my $credits;
4786: if ($showcredits) {
1.465 raeburn 4787: my $defaultcredits =
1.375 raeburn 4788: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4789: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4790: }
1.465 raeburn 4791: unless ($udom eq $cdom) {
4792: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4793: $uname,$role,$now,0,$cdom,$cnum,$csec,$credits,
4794: \%process_by,\%instdoms,\%got_role_approvals,
1.466 raeburn 4795: \%got_instdoms,\%reject,\%pending,\%notifydc,
4796: \%status,\%unauthorized,\%currqueued));
1.465 raeburn 4797: }
1.375 raeburn 4798: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4799: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4800: if ($result eq 'refused' && $logmsg) {
4801: $output = $logmsg;
4802: } else {
1.369 bisitz 4803: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4804: }
1.89 raeburn 4805: } else {
1.372 raeburn 4806: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4807: &Apache::lonnet::plaintext($role),
4808: &Apache::loncommon::show_role_extent($url,$context,'st'),
4809: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4810: }
4811: }
4812: } else {
1.465 raeburn 4813: my ($cdom,$cnum,$csec);
4814: if (grep(/^\Q$role\E$/,@cstrroles)) {
4815: ($cdom,$cnum) = ($url =~ m{^/($match_domain)/($match_username)$});
4816: } elsif (grep(/^\Q$role\E$/,@domroles)) {
4817: ($cdom) = ($url =~ m{^/($match_domain)/$});
4818: } elsif ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
4819: ($cdom,$cnum,$csec) = ($1,$2,$3);
4820: }
4821: if ($cdom ne '') {
4822: unless ($udom eq $cdom) {
4823: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4824: $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by,
4825: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4826: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4827: }
4828: }
1.101 albertel 4829: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4830: $env{'form.ccuname'},$url,$role,0,$now,'','',
4831: $context);
1.461 raeburn 4832: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
4833: &Apache::lonnet::plaintext($role),
4834: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4835: if ($result ne "ok") {
4836: $output .= &mt('Error: [_1]',$result).'<br />';
4837: }
4838: }
1.89 raeburn 4839: $r->print($output);
1.225 raeburn 4840: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4841: push(@rolechanges,$role);
4842: }
1.113 raeburn 4843: }
1.116 raeburn 4844: # Re-enable custom role
1.139 albertel 4845: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4846: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1.465 raeburn 4847: my $id = $url.'_cr'."/$rdom/$rnam/$rolename";
4848: my $role = "cr/$rdom/$rnam/$rolename";
4849: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
4850: my ($cdom,$cnum,$csec) = ($1,$2,$3);
4851: unless ($udom eq $cdom) {
4852: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4853: $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by,
4854: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4855: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4856: }
4857: }
1.116 raeburn 4858: my $result = &Apache::lonnet::assigncustomrole(
4859: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4860: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4861: $r->print(&Apache::lonhtmlcommon::confirm_success(
4862: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4863: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4864: $result ne "ok").'<br />');
4865: if ($result ne "ok") {
4866: $r->print(&mt('Error: [_1]',$result).'<br />');
4867: }
1.225 raeburn 4868: if (!grep(/^cr$/,@rolechanges)) {
4869: push(@rolechanges,'cr');
4870: }
1.116 raeburn 4871: }
1.135 raeburn 4872: } elsif ($key=~/^form\.act/) {
1.101 albertel 4873: my $udom = $env{'form.ccdomain'};
4874: my $uname = $env{'form.ccuname'};
1.141 albertel 4875: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4876: # Activate a custom role
1.83 albertel 4877: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4878: my $url='/'.$one.'/'.$two;
1.465 raeburn 4879: my $id = $url.'_cr/'."$three/$four/$five";
4880: my $role = "cr/$three/$four/$five";
1.83 albertel 4881: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4882:
1.101 albertel 4883: my $start = ( $env{'form.start_'.$full} ?
4884: $env{'form.start_'.$full} :
1.88 raeburn 4885: $now );
1.101 albertel 4886: my $end = ( $env{'form.end_'.$full} ?
4887: $env{'form.end_'.$full} :
1.88 raeburn 4888: 0 );
1.465 raeburn 4889:
1.88 raeburn 4890: # split multiple sections
4891: my %sections = ();
1.461 raeburn 4892: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$five);
1.88 raeburn 4893: if ($num_sections == 0) {
1.465 raeburn 4894: unless ($udom eq $one) {
4895: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4896: $uname,$role,$start,$end,$one,$two,'','',\%process_by,
4897: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4898: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4899: }
1.240 raeburn 4900: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4901: } else {
1.114 albertel 4902: my %curr_groups =
1.117 raeburn 4903: &Apache::longroup::coursegroups($one,$two);
1.465 raeburn 4904: my ($restricted,$numchanges);
1.404 raeburn 4905: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4906: if (($sec eq 'none') || ($sec eq 'all') ||
4907: exists($curr_groups{$sec})) {
4908: $disallowed{$sec} = $url;
4909: next;
4910: }
4911: my $securl = $url.'/'.$sec;
1.465 raeburn 4912: my $secid = $securl.'_cr'."/$three/$four/$five";
4913: undef($restricted);
4914: unless ($udom eq $one) {
4915: next if (&Apache::lonuserutils::restricted_dom($context,$secid,$udom,
4916: $uname,$role,$start,$end,$one,$two,$sec,'',\%process_by,
4917: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4918: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4919: }
4920: $numchanges ++;
1.240 raeburn 4921: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4922: }
1.465 raeburn 4923: next unless ($numchanges);
1.88 raeburn 4924: }
1.225 raeburn 4925: if (!grep(/^cr$/,@rolechanges)) {
4926: push(@rolechanges,'cr');
4927: }
1.142 raeburn 4928: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4929: # Activate roles for sections with 3 id numbers
4930: # set start, end times, and the url for the class
1.83 albertel 4931: my ($one,$two,$three)=($1,$2,$3);
1.461 raeburn 4932: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4933: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4934: $now );
1.461 raeburn 4935: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1.101 albertel 4936: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4937: 0 );
1.83 albertel 4938: my $url='/'.$one.'/'.$two;
1.465 raeburn 4939: my $id = $url.'_'.$three;
1.88 raeburn 4940: # split multiple sections
4941: my %sections = ();
1.101 albertel 4942: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.465 raeburn 4943: my ($credits,$numchanges);
1.375 raeburn 4944: if ($three eq 'st') {
1.461 raeburn 4945: if ($showcredits) {
1.375 raeburn 4946: my $defaultcredits =
4947: &Apache::lonuserutils::get_defaultcredits($one,$two);
4948: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4949: $credits =~ s/[^\d\.]//g;
4950: if ($credits eq $defaultcredits) {
4951: undef($credits);
4952: }
4953: }
4954: }
1.88 raeburn 4955: if ($num_sections == 0) {
1.465 raeburn 4956: unless ($udom eq $one) {
4957: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4958: $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by,
4959: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4960: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4961: }
4962: $numchanges ++;
1.375 raeburn 4963: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4964: } else {
1.114 albertel 4965: my %curr_groups =
1.117 raeburn 4966: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4967: my $emptysec = 0;
1.465 raeburn 4968: my $restricted;
1.404 raeburn 4969: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4970: $sec =~ s/\W//g;
1.113 raeburn 4971: if ($sec ne '') {
4972: if (($sec eq 'none') || ($sec eq 'all') ||
4973: exists($curr_groups{$sec})) {
4974: $disallowed{$sec} = $url;
4975: next;
4976: }
1.88 raeburn 4977: my $securl = $url.'/'.$sec;
1.465 raeburn 4978: my $secid = $securl.'_'.$three;
4979: unless ($udom eq $one) {
4980: undef($restricted);
4981: $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
4982: $uname,$three,$start,$end,$one,$two,$sec,$credits,\%process_by,
4983: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4984: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4985: next if ($restricted);
4986: }
4987: $numchanges ++;
1.375 raeburn 4988: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4989: } else {
4990: $emptysec = 1;
4991: }
4992: }
4993: if ($emptysec) {
1.465 raeburn 4994: unless ($udom eq $one) {
4995: undef($restricted);
4996: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
4997: $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by,
4998: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4999: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 5000: next if ($restricted);
5001: }
5002: $numchanges ++;
1.375 raeburn 5003: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 5004: }
1.465 raeburn 5005: next unless ($numchanges);
1.225 raeburn 5006: }
5007: if (!grep(/^\Q$three\E$/,@rolechanges)) {
5008: push(@rolechanges,$three);
5009: }
1.135 raeburn 5010: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 5011: # Activate roles for sections with two id numbers
5012: # set start, end times, and the url for the class
1.461 raeburn 5013: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
5014: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 5015: $now );
1.461 raeburn 5016: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1.101 albertel 5017: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 5018: 0 );
1.225 raeburn 5019: my $one = $1;
5020: my $two = $2;
5021: my $url='/'.$one.'/';
1.465 raeburn 5022: my $id = $url.'_'.$two;
1.468 raeburn 5023: my ($cdom,$cnum) = split(/\//,$one);
1.88 raeburn 5024: # split multiple sections
5025: my %sections = ();
1.465 raeburn 5026: my ($restricted,$numchanges);
1.225 raeburn 5027: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 5028: if ($num_sections == 0) {
1.465 raeburn 5029: unless ($udom eq $one) {
5030: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
1.468 raeburn 5031: $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
1.465 raeburn 5032: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 5033: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 5034: next if ($restricted);
5035: }
5036: $numchanges ++;
1.240 raeburn 5037: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 5038: } else {
5039: my $emptysec = 0;
1.404 raeburn 5040: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 5041: if ($sec ne '') {
5042: my $securl = $url.'/'.$sec;
1.465 raeburn 5043: my $secid = $securl.'_'.$two;
5044: unless ($udom eq $one) {
5045: undef($restricted);
5046: $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
1.468 raeburn 5047: $uname,$two,$start,$end,$cdom,$cnum,$sec,'',\%process_by,
1.465 raeburn 5048: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 5049: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 5050: next if ($restricted);
5051: }
5052: $numchanges ++;
1.240 raeburn 5053: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 5054: } else {
5055: $emptysec = 1;
5056: }
5057: }
5058: if ($emptysec) {
1.465 raeburn 5059: unless ($udom eq $one) {
5060: undef($restricted);
5061: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
1.468 raeburn 5062: $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
1.465 raeburn 5063: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 5064: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 5065: next if ($restricted);
5066: }
5067: $numchanges ++;
1.240 raeburn 5068: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 5069: }
1.465 raeburn 5070: next unless ($numchanges);
1.88 raeburn 5071: }
1.225 raeburn 5072: if (!grep(/^\Q$two\E$/,@rolechanges)) {
5073: push(@rolechanges,$two);
5074: }
1.64 www 5075: } else {
1.190 raeburn 5076: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 5077: }
1.113 raeburn 5078: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 5079: $r->print('<p class="LC_warning">');
1.113 raeburn 5080: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 5081: $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 5082: } else {
1.274 bisitz 5083: $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 5084: }
1.274 bisitz 5085: $r->print('</p><p>'
5086: .&mt('Please [_1]go back[_2] and choose a different section name.'
5087: ,'<a href="javascript:history.go(-1)'
5088: ,'</a>')
5089: .'</p><br />'
5090: );
1.113 raeburn 5091: }
5092: }
1.101 albertel 5093: } # End of foreach (keys(%env))
1.466 raeburn 5094: if ((keys(%reject)) || (keys(%unauthorized))) {
5095: $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized));
1.465 raeburn 5096: }
1.466 raeburn 5097: if ((keys(%pending)) || (keys(%currqueued))) {
5098: $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.465 raeburn 5099: }
1.75 www 5100: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 5101: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 5102: if (@rolechanges == 0) {
1.372 raeburn 5103: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 5104: }
1.225 raeburn 5105: return @rolechanges;
1.220 raeburn 5106: }
5107:
1.375 raeburn 5108: sub get_user_credits {
5109: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
5110: if ($cdom eq '' || $cnum eq '') {
5111: return unless ($env{'request.course.id'});
5112: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5113: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5114: }
5115: my $credits;
5116: my %currhash =
5117: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
5118: if (keys(%currhash) > 0) {
5119: my @items = split(/:/,$currhash{$uname.':'.$udom});
5120: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
5121: $credits = $items[$crdidx];
5122: $credits =~ s/[^\d\.]//g;
5123: }
5124: if ($credits eq $defaultcredits) {
5125: undef($credits);
5126: }
5127: return $credits;
5128: }
5129:
1.220 raeburn 5130: sub enroll_single_student {
1.375 raeburn 5131: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
5132: $showcredits,$defaultcredits) = @_;
1.318 raeburn 5133: $r->print('<h3>');
5134: if ($crstype eq 'Community') {
5135: $r->print(&mt('Enrolling Member'));
5136: } else {
5137: $r->print(&mt('Enrolling Student'));
5138: }
5139: $r->print('</h3>');
1.220 raeburn 5140:
5141: # Remove non alphanumeric values from section
5142: $env{'form.sections'}=~s/\W//g;
5143:
1.375 raeburn 5144: my $credits;
5145: if (($showcredits) && ($env{'form.credits'} ne '')) {
5146: $credits = $env{'form.credits'};
5147: $credits =~ s/[^\d\.]//g;
5148: if ($credits ne '') {
5149: if ($credits eq $defaultcredits) {
5150: undef($credits);
5151: }
5152: }
5153: }
1.465 raeburn 5154: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
1.466 raeburn 5155: my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,%pending,%reject,%notifydc,
5156: %status,%unauthorized,%currqueued);
1.465 raeburn 5157: unless ($env{'form.ccdomain'} eq $env{'course.'.$env{'request.course.id'}.'.domain'}) {
5158: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5159: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5160: my $csec = $env{'form.sections'};
5161: my $id = "/$cdom/$cnum";
5162: if ($csec ne '') {
5163: $id .= "/$csec";
5164: }
5165: $id .= '_st';
5166: if (&Apache::lonuserutils::restricted_dom($context,$id,$env{'form.ccdomain'},$env{'form.ccuname'},
5167: 'st',$startdate,$enddate,$cdom,$cnum,$csec,$credits,
5168: \%process_by,\%instdoms,\%got_role_approvals,\%got_instdoms,
1.466 raeburn 5169: \%reject,\%pending,\%notifydc,\%status,\%unauthorized,\%currqueued)) {
5170: if ((keys(%reject)) || (keys(%unauthorized))) {
5171: $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized));
1.465 raeburn 5172: }
1.466 raeburn 5173: if ((keys(%pending)) || (keys(%currqueued))) {
5174: $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.465 raeburn 5175: }
5176: return;
5177: }
5178: }
1.375 raeburn 5179:
1.220 raeburn 5180: # Clean out any old student roles the user has in this class.
5181: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
5182: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
5183: my $enroll_result =
5184: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
5185: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
5186: $env{'form.cmiddlename'},$env{'form.clastname'},
5187: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 5188: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
5189: $credits);
1.220 raeburn 5190: if ($enroll_result =~ /^ok/) {
1.381 bisitz 5191: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 5192: if ($env{'form.sections'} ne '') {
5193: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
5194: }
5195: my ($showstart,$showend);
5196: if ($startdate <= $now) {
5197: $showstart = &mt('Access starts immediately');
5198: } else {
5199: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
5200: }
5201: if ($enddate == 0) {
5202: $showend = &mt('ends: no ending date');
5203: } else {
5204: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
5205: }
5206: $r->print('.<br />'.$showstart.'; '.$showend);
5207: if ($startdate <= $now && !$newuser) {
1.386 bisitz 5208: $r->print('<p class="LC_info">');
1.318 raeburn 5209: if ($crstype eq 'Community') {
1.392 raeburn 5210: $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 5211: } else {
1.392 raeburn 5212: $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 5213: }
5214: $r->print('</p>');
1.220 raeburn 5215: }
5216: } else {
5217: $r->print(&mt('unable to enroll').": ".$enroll_result);
5218: }
5219: return;
1.188 raeburn 5220: }
5221:
1.204 raeburn 5222: sub get_defaultquota_text {
5223: my ($settingstatus) = @_;
5224: my $defquotatext;
5225: if ($settingstatus eq '') {
1.383 raeburn 5226: $defquotatext = &mt('default');
1.204 raeburn 5227: } else {
5228: my ($usertypes,$order) =
5229: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
5230: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 5231: $defquotatext = &mt('default');
1.204 raeburn 5232: } else {
1.383 raeburn 5233: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 5234: }
5235: }
5236: return $defquotatext;
5237: }
5238:
1.188 raeburn 5239: sub update_result_form {
5240: my ($uhome) = @_;
5241: my $outcome =
1.367 golterma 5242: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 5243: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 5244: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 5245: }
1.207 raeburn 5246: if ($env{'form.origname'} ne '') {
5247: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
5248: }
1.160 raeburn 5249: foreach my $item ('sortby','seluname','seludom') {
5250: if (exists($env{'form.'.$item})) {
1.188 raeburn 5251: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 5252: }
5253: }
1.188 raeburn 5254: if ($uhome eq 'no_host') {
5255: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
5256: }
5257: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 5258: '<input type="hidden" name="currstate" value="" />'."\n".
5259: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 5260: '</form>';
5261: return $outcome;
1.4 www 5262: }
5263:
1.149 raeburn 5264: sub quota_admin {
1.378 raeburn 5265: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 5266: my $quotachanged;
5267: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
5268: # Current user has quota modification privileges
1.267 raeburn 5269: if (ref($changeHash) eq 'HASH') {
5270: $quotachanged = 1;
1.378 raeburn 5271: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 5272: }
1.149 raeburn 5273: }
5274: return $quotachanged;
5275: }
5276:
1.267 raeburn 5277: sub tool_admin {
1.275 raeburn 5278: my ($tool,$settool,$changeHash,$context) = @_;
5279: my $canchange = 0;
1.279 raeburn 5280: if ($context eq 'requestcourses') {
1.275 raeburn 5281: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
5282: $canchange = 1;
5283: }
1.300 raeburn 5284: } elsif ($context eq 'reqcrsotherdom') {
5285: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
5286: $canchange = 1;
5287: }
1.362 raeburn 5288: } elsif ($context eq 'requestauthor') {
5289: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
5290: $canchange = 1;
5291: }
1.470 raeburn 5292: } elsif ($context eq 'authordefaults') {
5293: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
5294: $canchange = 1;
5295: }
1.275 raeburn 5296: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
5297: # Current user has quota modification privileges
5298: $canchange = 1;
5299: }
1.267 raeburn 5300: my $toolchanged;
1.275 raeburn 5301: if ($canchange) {
1.267 raeburn 5302: if (ref($changeHash) eq 'HASH') {
5303: $toolchanged = 1;
1.362 raeburn 5304: if ($tool eq 'requestauthor') {
5305: $changeHash->{$context} = $settool;
1.477 raeburn 5306: } elsif (($tool eq 'managers') || ($tool eq 'editors') || ($tool eq 'archive')) {
1.470 raeburn 5307: $changeHash->{'author'.$tool} = $settool;
5308: } elsif ($tool eq 'webdav') {
5309: $changeHash->{'tools.'.$tool} = $settool;
1.362 raeburn 5310: } else {
5311: $changeHash->{$context.'.'.$tool} = $settool;
5312: }
1.267 raeburn 5313: }
5314: }
5315: return $toolchanged;
5316: }
5317:
1.88 raeburn 5318: sub build_roles {
1.89 raeburn 5319: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 5320: my $num_sections = 0;
5321: if ($sectionstr=~ /,/) {
5322: my @secnums = split/,/,$sectionstr;
1.89 raeburn 5323: if ($role eq 'st') {
5324: $secnums[0] =~ s/\W//g;
5325: $$sections{$secnums[0]} = 1;
5326: $num_sections = 1;
5327: } else {
5328: foreach my $sec (@secnums) {
5329: $sec =~ ~s/\W//g;
1.150 banghart 5330: if (!($sec eq "")) {
1.89 raeburn 5331: if (exists($$sections{$sec})) {
5332: $$sections{$sec} ++;
5333: } else {
5334: $$sections{$sec} = 1;
5335: $num_sections ++;
5336: }
1.88 raeburn 5337: }
5338: }
5339: }
5340: } else {
5341: $sectionstr=~s/\W//g;
5342: unless ($sectionstr eq '') {
5343: $$sections{$sectionstr} = 1;
5344: $num_sections ++;
5345: }
5346: }
1.129 albertel 5347:
1.88 raeburn 5348: return $num_sections;
5349: }
5350:
1.58 www 5351: # ========================================================== Custom Role Editor
5352:
5353: sub custom_role_editor {
1.439 raeburn 5354: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 5355: my $action = $env{'form.customroleaction'};
1.439 raeburn 5356: my ($rolename,$helpitem);
1.324 raeburn 5357: if ($action eq 'new') {
5358: $rolename=$env{'form.newrolename'};
5359: } else {
5360: $rolename=$env{'form.rolename'};
1.59 www 5361: }
5362:
1.324 raeburn 5363: my ($crstype,$context);
5364: if ($env{'request.course.id'}) {
5365: $crstype = &Apache::loncommon::course_type();
5366: $context = 'course';
1.439 raeburn 5367: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 5368: } else {
5369: $context = 'domain';
1.414 raeburn 5370: $crstype = 'course';
1.439 raeburn 5371: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 5372: }
1.351 raeburn 5373:
5374: $rolename=~s/[^A-Za-z0-9]//gs;
5375: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 5376: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
5377: $permission);
1.351 raeburn 5378: return;
5379: }
5380:
1.414 raeburn 5381: my $formname = 'form1';
5382: my %privs=();
5383: my $body_top = '<h2>';
5384: # ------------------------------------------------------- Does this role exist?
1.59 www 5385: my ($rdummy,$roledef)=
5386: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
5387: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 5388: $body_top .= &mt('Existing Role').' "';
1.61 www 5389: # ------------------------------------------------- Get current role privileges
1.414 raeburn 5390: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
5391: if ($privs{'system'} =~ /bre\&S/) {
5392: if ($context eq 'domain') {
1.417 raeburn 5393: $crstype = 'Course';
1.414 raeburn 5394: } elsif ($crstype eq 'Community') {
5395: $privs{'system'} =~ s/bre\&S//;
5396: }
5397: } elsif ($context eq 'domain') {
5398: $crstype = 'Course';
1.324 raeburn 5399: }
1.59 www 5400: } else {
1.414 raeburn 5401: $body_top .= &mt('New Role').' "';
5402: $roledef='';
1.59 www 5403: }
1.153 banghart 5404: $body_top .= $rolename.'"</h2>';
1.414 raeburn 5405:
5406: # ------------------------------------------------------- What can be assigned?
5407: my %full=();
1.417 raeburn 5408: my %levels=(
1.414 raeburn 5409: course => {},
5410: domain => {},
5411: system => {},
5412: );
5413: my %levelscurrent=(
5414: course => {},
5415: domain => {},
5416: system => {},
5417: );
5418: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 5419: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 5420: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 5421: my $head_script =
1.414 raeburn 5422: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
5423: \%full,\@templateroles,$jsback);
1.351 raeburn 5424: push (@{$brcrum},
1.414 raeburn 5425: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 5426: text => "Pick custom role",
5427: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 5428: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 5429: text => "Edit custom role",
5430: faq => 282,
5431: bug => 'Instructor Interface',
1.439 raeburn 5432: help => $helpitem}
1.351 raeburn 5433: );
5434: my $args = { bread_crumbs => $brcrum,
5435: bread_crumbs_component => 'User Management'};
5436: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
5437: $head_script,$args).
5438: $body_top);
1.414 raeburn 5439: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
5440: &Apache::lonuserutils::custom_role_header($context,$crstype,
5441: \@templateroles,$prefix));
1.264 bisitz 5442:
1.61 www 5443: $r->print(<<ENDCCF);
5444: <input type="hidden" name="phase" value="set_custom_roles" />
5445: <input type="hidden" name="rolename" value="$rolename" />
5446: ENDCCF
1.414 raeburn 5447: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
5448: \%levelscurrent,$prefix));
1.135 raeburn 5449: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 5450: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 5451: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 5452: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 5453: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 5454: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 5455: }
1.414 raeburn 5456:
1.61 www 5457: # ---------------------------------------------------------- Call to definerole
5458: sub set_custom_role {
1.439 raeburn 5459: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 5460: my $rolename=$env{'form.rolename'};
1.63 www 5461: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 5462: if (!$rolename) {
1.439 raeburn 5463: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 5464: return;
5465: }
1.160 raeburn 5466: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 5467: my $jscript = '<script type="text/javascript">'
5468: .'// <![CDATA['."\n"
5469: .$jsback."\n"
5470: .'// ]]>'."\n"
5471: .'</script>'."\n";
1.439 raeburn 5472: my $helpitem = 'Course_Editing_Custom_Roles';
5473: if ($context eq 'domain') {
5474: $helpitem = 'Domain_Editing_Custom_Roles';
5475: }
1.352 raeburn 5476: push(@{$brcrum},
5477: {href => "javascript:backPage(document.customresult,'pickrole','')",
5478: text => "Pick custom role",
5479: faq => 282,
5480: bug => 'Instructor Interface',},
5481: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
5482: text => "Edit custom role",
5483: faq => 282,
5484: bug => 'Instructor Interface',},
5485: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
5486: text => "Result",
5487: faq => 282,
5488: bug => 'Instructor Interface',
1.439 raeburn 5489: help => $helpitem,}
1.352 raeburn 5490: );
5491: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 5492: bread_crumbs_component => 'User Management'};
1.351 raeburn 5493: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 5494:
1.393 raeburn 5495: my $newrole;
1.61 www 5496: my ($rdummy,$roledef)=
1.110 albertel 5497: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
5498:
1.61 www 5499: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 5500: $r->print('<h3>');
1.61 www 5501: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 5502: $r->print(&mt('Existing Role').' "');
1.61 www 5503: } else {
1.73 sakharuk 5504: $r->print(&mt('New Role').' "');
1.61 www 5505: $roledef='';
1.393 raeburn 5506: $newrole = 1;
1.61 www 5507: }
1.188 raeburn 5508: $r->print($rolename.'"</h3>');
1.414 raeburn 5509: # ------------------------------------------------- Assign role and show result
1.61 www 5510:
1.387 bisitz 5511: my $errmsg;
1.414 raeburn 5512: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
5513: # Assign role and return result
5514: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
5515: $newprivs{'c'});
1.387 bisitz 5516: if ($result ne 'ok') {
5517: $errmsg = ': '.$result;
5518: }
5519: my $message =
5520: &Apache::lonhtmlcommon::confirm_success(
5521: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 5522: if ($env{'request.course.id'}) {
5523: my $url='/'.$env{'request.course.id'};
1.63 www 5524: $url=~s/\_/\//g;
1.387 bisitz 5525: $result =
5526: &Apache::lonnet::assigncustomrole(
5527: $env{'user.domain'},$env{'user.name'},
5528: $url,
5529: $env{'user.domain'},$env{'user.name'},
5530: $rolename,undef,undef,undef,$context);
5531: if ($result ne 'ok') {
5532: $errmsg = ': '.$result;
5533: }
5534: $message .=
5535: '<br />'
5536: .&Apache::lonhtmlcommon::confirm_success(
5537: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 5538: }
1.380 bisitz 5539: $r->print(
1.387 bisitz 5540: &Apache::loncommon::confirmwrapper($message)
5541: .'<br />'
5542: .&Apache::lonhtmlcommon::actionbox([
5543: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
5544: .&mt('Create or edit another custom role')
5545: .'</a>'])
1.380 bisitz 5546: .'<form name="customresult" method="post" action="">'
1.387 bisitz 5547: .&Apache::lonhtmlcommon::echo_form_input([])
5548: .'</form>'
1.380 bisitz 5549: );
1.58 www 5550: }
5551:
1.465 raeburn 5552: sub show_role_requests {
5553: my ($caller,$dom) = @_;
5554: my $showrolereqs;
5555: my %domconfig = &Apache::lonnet::get_dom('configuration',['privacy'],$dom);
5556: if (ref($domconfig{'privacy'}) eq 'HASH') {
5557: if (ref($domconfig{'privacy'}{'approval'}) eq 'HASH') {
5558: my %approvalconf = %{$domconfig{'privacy'}{'approval'}};
5559: foreach my $key ('instdom','extdom') {
5560: if (ref($approvalconf{$key}) eq 'HASH') {
5561: if (keys(%{$approvalconf{$key}})) {
5562: foreach my $context ('domain','author','course','community') {
5563: if ($approvalconf{$key}{$context} eq $caller) {
5564: $showrolereqs = 1;
5565: last if ($showrolereqs);
5566: }
5567: }
5568: }
5569: }
5570: last if ($showrolereqs);
5571: }
5572: }
5573: }
5574: return $showrolereqs;
5575: }
5576:
1.470 raeburn 5577: sub display_coauthor_managers {
5578: my ($permission) = @_;
5579: my $output;
5580: if ((ref($permission) eq 'HASH') && ($permission->{'author'})) {
5581: $output = '<form action="/adm/createuser" method="post" name="camanagers">'.
5582: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
5583: '<p>';
5584: my (@possmanagers,@custommanagers);
5585: my %userenv =
5586: &Apache::lonnet::userenvironment($env{'user.domain'},
5587: $env{'user.name'},
5588: 'authormanagers');
5589: my %ca_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5590: ['active','future'],['ca']);
5591: if (keys(%ca_roles)) {
5592: foreach my $entry (sort(keys(%ca_roles))) {
5593: if ($entry =~ /^($match_username\:$match_domain):ca$/) {
5594: my $user = $1;
5595: unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5596: push(@possmanagers,$user);
5597: }
5598: }
5599: }
5600: }
5601: if ($userenv{'authormanagers'} eq '') {
5602: $output .= &mt('Currently author manages co-author roles');
5603: } else {
5604: if (keys(%ca_roles)) {
5605: foreach my $user (split(/,/,$userenv{'authormanagers'})) {
5606: if ($user =~ /^($match_username)\:($match_domain)$/) {
5607: if (exists($ca_roles{$user.':ca'})) {
5608: unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5609: push(@custommanagers,$user);
5610: }
5611: }
5612: }
5613: }
5614: }
5615: if (@custommanagers) {
5616: $output .= &mt('Co-authors with active or future roles who currently manage co-author roles: [_1]',
5617: '<br />'.join(', ',map { &Apache::loncommon::plainname(split(':',$_))." ($_)"; } @custommanagers));
5618: } else {
5619: $output .= &mt('Currently author manages co-author roles');
5620: }
5621: }
5622: $output .= "</p>\n";
5623: if (@possmanagers) {
1.472 raeburn 5624: $output .= '<p>'.&mt('If checked, can manage').': ';
1.470 raeburn 5625: foreach my $user (@possmanagers) {
5626: my $checked;
5627: if (grep(/^\Q$user\E$/,@custommanagers)) {
5628: $checked = ' checked="checked"';
5629: }
5630: $output .= '<span style="LC_nobreak"><label>'.
5631: '<input type="checkbox" name="custommanagers" '.
5632: 'value="'.&HTML::Entities::encode($user,'\'<>"&').'"'.$checked.' />'.
5633: &Apache::loncommon::plainname(split(/:/,$user))." ($user)".'</label></span> '."\n";
5634: }
5635: $output .= '<input type="hidden" name="state" value="process" /></p>'."\n".
5636: '<p><input type="submit" value="'.&mt('Save changes').'" /></p>'."\n";
5637: } else {
5638: $output .= '<p>'.&mt('No co-author roles assignable as manager').'</p>';
5639: }
5640: $output .= '</form>';
5641: } else {
5642: $output = '<span class="LC_warning">'.
5643: &mt('You do not have permission to perform this action').
5644: '</span>';
5645: }
5646: return $output;
5647: }
5648:
5649: sub update_coauthor_managers {
5650: my ($permission) = @_;
5651: my $output;
5652: if ((ref($permission) eq 'HASH') && ($permission->{'author'})) {
5653: my ($current,$newval,@possibles,@managers);
5654: my %userenv =
5655: &Apache::lonnet::userenvironment($env{'user.domain'},
5656: $env{'user.name'},
5657: 'authormanagers');
5658: $current = $userenv{'authormanagers'};
5659: @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
5660: if (@possibles) {
5661: my %ca_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5662: ['active','future'],['ca']);
5663: if (keys(%ca_roles)) {
5664: foreach my $user (@possibles) {
5665: if ($user =~ /^($match_username):($match_domain)$/) {
5666: if (exists($ca_roles{$user.':ca'})) {
5667: unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5668: push(@managers,$user);
5669: }
5670: }
5671: }
5672: }
5673: if (@managers) {
5674: $newval = join(',',sort(@managers));
5675: }
5676: }
5677: }
5678: if ($current eq $newval) {
5679: $output = &mt('No changes made to management of co-author roles');
5680: } else {
5681: my $chgresult =
5682: &Apache::lonnet::put('environment',{'authormanagers' => $newval},
5683: $env{'user.domain'},$env{'user.name'});
5684: if ($chgresult eq 'ok') {
5685: &Apache::lonnet::appenv({'environment.authormanagers' => $newval});
5686: my (@adds,@dels);
5687: if ($newval eq '') {
5688: @dels = split(/,/,$current);
5689: } elsif ($current eq '') {
5690: @adds = @managers;
5691: } else {
5692: my @old = split(/,/,$current);
5693: my @diffs = &Apache::loncommon::compare_arrays(\@old,\@managers);
5694: if (@diffs) {
5695: foreach my $user (@diffs) {
5696: if (grep(/^\Q$user\E$/,@old)) {
5697: push(@dels,$user);
5698: } elsif (grep(/^\Q$user\E$/,@managers)) {
5699: push(@adds,$user);
5700: }
5701: }
5702: }
5703: }
5704: my $key = "internal.manager./$env{'user.domain'}/$env{'user.name'}";
5705: if (@dels) {
5706: foreach my $user (@dels) {
5707: if ($user =~ /^($match_username):($match_domain)$/) {
5708: &Apache::lonnet::del('environment',[$key],$2,$1);
5709: }
5710: }
5711: }
5712: if (@adds) {
5713: foreach my $user (@adds) {
5714: if ($user =~ /^($match_username):($match_domain)$/) {
5715: &Apache::lonnet::put('environment',{$key => 1},$2,$1);
5716: }
5717: }
5718: }
5719: if ($newval eq '') {
5720: $output = &mt('Management of co-authors set to be author-only');
5721: } else {
5722: $output .= &mt('Co-authors who can manage co-author roles set to: [_1]',
5723: '<br />'.join(', ',map { &Apache::loncommon::plainname(split(':',$_))." ($_)"; } @managers));
5724: }
5725: }
5726: }
5727: } else {
5728: $output = '<span class="LC_warning">'.
5729: &mt('You do not have permission to perform this action').
5730: '</span>';
5731: }
5732: return $output;
5733: }
5734:
1.2 www 5735: # ================================================================ Main Handler
5736: sub handler {
5737: my $r = shift;
5738: if ($r->header_only) {
1.68 www 5739: &Apache::loncommon::content_type($r,'text/html');
1.2 www 5740: $r->send_http_header;
5741: return OK;
5742: }
1.439 raeburn 5743: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
5744:
1.190 raeburn 5745: if ($env{'request.course.id'}) {
5746: $context = 'course';
1.318 raeburn 5747: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 5748: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 5749: $context = 'author';
1.470 raeburn 5750: } elsif ($env{'request.role'} =~ m{^(ca|aa)\./$match_domain/$match_username$}) {
5751: $context = 'coauthor';
1.190 raeburn 5752: } else {
5753: $context = 'domain';
5754: }
1.375 raeburn 5755:
1.439 raeburn 5756: my ($permission,$allowed) =
5757: &Apache::lonuserutils::get_permission($context,$crstype);
1.470 raeburn 5758: if (($context eq 'coauthor') && ($allowed)) {
5759: $context = 'author';
5760: }
1.439 raeburn 5761:
5762: if ($allowed) {
5763: my @allhelp;
5764: if ($context eq 'course') {
5765: $cid = $env{'request.course.id'};
5766: $cdom = $env{'course.'.$cid.'.domain'};
5767: $cnum = $env{'course.'.$cid.'.num'};
5768:
5769: if ($permission->{'cusr'}) {
5770: push(@allhelp,'Course_Create_Class_List');
5771: }
5772: if ($permission->{'view'} || $permission->{'cusr'}) {
5773: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
5774: }
5775: if ($permission->{'custom'}) {
5776: push(@allhelp,'Course_Editing_Custom_Roles');
5777: }
5778: if ($permission->{'cusr'}) {
5779: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
5780: }
5781: unless ($permission->{'cusr_section'}) {
5782: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
5783: push(@allhelp,'Course_Automated_Enrollment');
5784: }
1.469 raeburn 5785: if (($permission->{'selfenrolladmin'}) || ($permission->{'selfenrollview'})) {
1.439 raeburn 5786: push(@allhelp,'Course_Approve_Selfenroll');
5787: }
5788: }
5789: if ($permission->{'grp_manage'}) {
5790: push(@allhelp,'Course_Manage_Group');
5791: }
5792: if ($permission->{'view'} || $permission->{'cusr'}) {
5793: push(@allhelp,'Course_User_Logs');
5794: }
5795: } elsif ($context eq 'author') {
5796: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
5797: 'Author_View_Coauthor_List','Author_User_Logs'));
1.470 raeburn 5798: } elsif ($context eq 'coauthor') {
5799: if ($permission->{'cusr'}) {
5800: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
5801: 'Author_View_Coauthor_List','Author_User_Logs'));
5802: } elsif ($permission->{'view'}) {
5803: push(@allhelp,'Author_View_Coauthor_List');
5804: }
1.439 raeburn 5805: } else {
5806: if ($permission->{'cusr'}) {
5807: push(@allhelp,'Domain_Change_Privileges');
5808: if ($permission->{'activity'}) {
5809: push(@allhelp,'Domain_User_Access_Logs');
5810: }
5811: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
5812: if ($permission->{'custom'}) {
5813: push(@allhelp,'Domain_Editing_Custom_Roles');
5814: }
5815: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
5816: } elsif ($permission->{'view'}) {
5817: push(@allhelp,'Domain_View_Privileges');
5818: if ($permission->{'activity'}) {
5819: push(@allhelp,'Domain_User_Access_Logs');
5820: }
5821: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
5822: }
5823: }
5824: if (@allhelp) {
5825: $allhelpitems = join(',',@allhelp);
5826: }
5827: }
5828:
1.190 raeburn 5829: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 5830: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.470 raeburn 5831: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue',
5832: 'forceedit']);
1.190 raeburn 5833: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 5834: my $args;
5835: my $brcrum = [];
5836: my $bread_crumbs_component = 'User Management';
1.391 raeburn 5837: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 5838: $brcrum = [{href=>"/adm/createuser",
5839: text=>"User Management",
1.439 raeburn 5840: help=>$allhelpitems}
1.351 raeburn 5841: ];
1.202 raeburn 5842: }
1.190 raeburn 5843: if (!$allowed) {
1.358 raeburn 5844: if ($context eq 'course') {
5845: $r->internal_redirect('/adm/viewclasslist');
5846: return OK;
1.470 raeburn 5847: } elsif ($context eq 'coauthor') {
5848: $r->internal_redirect('/adm/viewcoauthors');
5849: return OK;
1.358 raeburn 5850: }
1.190 raeburn 5851: $env{'user.error.msg'}=
5852: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
5853: "or view user status.";
5854: return HTTP_NOT_ACCEPTABLE;
5855: }
5856:
5857: &Apache::loncommon::content_type($r,'text/html');
5858: $r->send_http_header;
5859:
1.375 raeburn 5860: my $showcredits;
5861: if ((($context eq 'course') && ($crstype eq 'Course')) ||
5862: ($context eq 'domain')) {
5863: my %domdefaults =
5864: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
5865: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
5866: $showcredits = 1;
5867: }
5868: }
5869:
1.190 raeburn 5870: # Main switch on form.action and form.state, as appropriate
5871: if (! exists($env{'form.action'})) {
1.351 raeburn 5872: $args = {bread_crumbs => $brcrum,
5873: bread_crumbs_component => $bread_crumbs_component};
5874: $r->print(&header(undef,$args));
1.318 raeburn 5875: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5876: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 5877: my $helpitem = 'Course_Create_Class_List';
5878: if ($context eq 'author') {
5879: $helpitem = 'Author_Create_Coauthor_List';
5880: } elsif ($context eq 'domain') {
5881: $helpitem = 'Domain_Create_Users';
5882: }
1.351 raeburn 5883: push(@{$brcrum},
5884: { href => '/adm/createuser?action=upload&state=',
5885: text => 'Upload Users List',
1.439 raeburn 5886: help => $helpitem,
1.351 raeburn 5887: });
5888: $bread_crumbs_component = 'Upload Users List';
5889: $args = {bread_crumbs => $brcrum,
5890: bread_crumbs_component => $bread_crumbs_component};
5891: $r->print(&header(undef,$args));
1.190 raeburn 5892: $r->print('<form name="studentform" method="post" '.
5893: 'enctype="multipart/form-data" '.
5894: ' action="/adm/createuser">'."\n");
5895: if (! exists($env{'form.state'})) {
5896: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5897: } elsif ($env{'form.state'} eq 'got_file') {
1.448 raeburn 5898: my $result =
5899: &Apache::lonuserutils::print_upload_manager_form($r,$context,
5900: $permission,
5901: $crstype,$showcredits);
5902: if ($result eq 'missingdata') {
5903: delete($env{'form.state'});
5904: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5905: }
1.190 raeburn 5906: } elsif ($env{'form.state'} eq 'enrolling') {
5907: if ($env{'form.datatoken'}) {
1.448 raeburn 5908: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
5909: $permission,
5910: $showcredits);
5911: if ($result eq 'missingdata') {
5912: delete($env{'form.state'});
5913: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5914: } elsif ($result eq 'invalidhome') {
5915: $env{'form.state'} = 'got_file';
5916: delete($env{'form.lcserver'});
5917: my $result =
5918: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
5919: $crstype,$showcredits);
5920: if ($result eq 'missingdata') {
5921: delete($env{'form.state'});
5922: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5923: }
5924: }
5925: } else {
5926: delete($env{'form.state'});
5927: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 5928: }
5929: } else {
5930: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5931: }
1.447 raeburn 5932: $r->print('</form>');
1.416 raeburn 5933: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
5934: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 5935: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 5936: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 5937: my $phase = $env{'form.phase'};
5938: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 5939: &Apache::loncreateuser::restore_prev_selections();
5940: my $srch;
5941: foreach my $item (@search) {
5942: $srch->{$item} = $env{'form.'.$item};
5943: }
1.207 raeburn 5944: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 5945: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 5946: if ($env{'form.phase'} eq 'createnewuser') {
5947: my $response;
5948: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 5949: my $response =
5950: '<span class="LC_warning">'
5951: .&mt('You must specify a valid username. Only the following are allowed:'
5952: .' letters numbers - . @')
5953: .'</span>';
1.221 raeburn 5954: $env{'form.phase'} = '';
1.375 raeburn 5955: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 5956: $crstype,$brcrum,$permission);
1.207 raeburn 5957: } else {
5958: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
5959: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
5960: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 5961: $srch,$response,$context,
1.375 raeburn 5962: $permission,$crstype,$brcrum,
5963: $showcredits);
1.207 raeburn 5964: }
5965: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 5966: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 5967: &user_search_result($context,$srch);
1.190 raeburn 5968: if ($env{'form.currstate'} eq 'modify') {
5969: $currstate = $env{'form.currstate'};
5970: }
5971: if ($currstate eq 'select') {
5972: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 5973: \@search,$context,undef,$crstype,
5974: $brcrum);
1.416 raeburn 5975: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
5976: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 5977: if (($srch->{'srchby'} eq 'uname') &&
5978: ($srch->{'srchtype'} eq 'exact')) {
5979: $ccuname = $srch->{'srchterm'};
5980: $ccdomain= $srch->{'srchdomain'};
5981: } else {
5982: my @matchedunames = keys(%{$results});
5983: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
5984: }
5985: $ccuname =&LONCAPA::clean_username($ccuname);
5986: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 5987: if ($env{'form.action'} eq 'accesslogs') {
5988: my $uhome;
5989: if (($ccuname ne '') && ($ccdomain ne '')) {
5990: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
5991: }
5992: if (($uhome eq '') || ($uhome eq 'no_host')) {
5993: $env{'form.phase'} = '';
5994: undef($forcenewuser);
5995: #if ($response) {
5996: # unless ($response =~ m{\Q<br /><br />\E$}) {
5997: # $response .= '<br /><br />';
5998: # }
5999: #}
6000: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 6001: $forcenewuser,$crstype,$brcrum,
6002: $permission);
1.416 raeburn 6003: } else {
6004: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
6005: }
6006: } else {
6007: if ($env{'form.forcenewuser'}) {
6008: $response = '';
6009: }
6010: &print_user_modification_page($r,$ccuname,$ccdomain,
6011: $srch,$response,$context,
6012: $permission,$crstype,$brcrum);
1.190 raeburn 6013: }
6014: } elsif ($currstate eq 'query') {
1.351 raeburn 6015: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 6016: } else {
1.229 raeburn 6017: $env{'form.phase'} = '';
1.207 raeburn 6018: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 6019: $forcenewuser,$crstype,$brcrum,
6020: $permission);
1.190 raeburn 6021: }
6022: } elsif ($env{'form.phase'} eq 'userpicked') {
6023: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
6024: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 6025: if ($env{'form.action'} eq 'accesslogs') {
6026: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
6027: } else {
6028: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
6029: $context,$permission,$crstype,
6030: $brcrum);
6031: }
6032: } elsif ($env{'form.action'} eq 'accesslogs') {
6033: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
6034: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
6035: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 6036: }
6037: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.451 raeburn 6038: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 6039: } else {
1.351 raeburn 6040: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 6041: $brcrum,$permission);
1.190 raeburn 6042: }
6043: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 6044: my $prefix;
1.190 raeburn 6045: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 6046: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 6047: } else {
1.439 raeburn 6048: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 6049: }
1.362 raeburn 6050: } elsif (($env{'form.action'} eq 'processauthorreq') &&
6051: ($permission->{'cusr'}) &&
6052: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
6053: push(@{$brcrum},
6054: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 6055: text => 'Authoring Space requests',
1.362 raeburn 6056: help => 'Domain_Role_Approvals'});
6057: $bread_crumbs_component = 'Authoring requests';
6058: if ($env{'form.state'} eq 'done') {
6059: push(@{$brcrum},
6060: {href => '/adm/createuser?action=authorreqqueue',
6061: text => 'Result',
6062: help => 'Domain_Role_Approvals'});
6063: $bread_crumbs_component = 'Authoring request result';
6064: }
6065: $args = { bread_crumbs => $brcrum,
6066: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 6067: my $js = &usernamerequest_javascript();
6068: $r->print(&header(&add_script($js),$args));
1.362 raeburn 6069: if (!exists($env{'form.state'})) {
6070: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
6071: $env{'request.role.domain'}));
6072: } elsif ($env{'form.state'} eq 'done') {
6073: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
6074: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
6075: $env{'request.role.domain'}));
6076: }
1.391 raeburn 6077: } elsif (($env{'form.action'} eq 'processusernamereq') &&
6078: ($permission->{'cusr'}) &&
6079: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
6080: push(@{$brcrum},
6081: {href => '/adm/createuser?action=processusernamereq',
6082: text => 'LON-CAPA account requests',
6083: help => 'Domain_Username_Approvals'});
6084: $bread_crumbs_component = 'Account requests';
6085: if ($env{'form.state'} eq 'done') {
6086: push(@{$brcrum},
6087: {href => '/adm/createuser?action=usernamereqqueue',
6088: text => 'Result',
6089: help => 'Domain_Username_Approvals'});
6090: $bread_crumbs_component = 'LON-CAPA account request result';
6091: }
6092: $args = { bread_crumbs => $brcrum,
6093: bread_crumbs_component => $bread_crumbs_component};
6094: my $js = &usernamerequest_javascript();
6095: $r->print(&header(&add_script($js),$args));
6096: if (!exists($env{'form.state'})) {
6097: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
6098: $env{'request.role.domain'}));
6099: } elsif ($env{'form.state'} eq 'done') {
6100: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
6101: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
6102: $env{'request.role.domain'}));
6103: }
6104: } elsif (($env{'form.action'} eq 'displayuserreq') &&
6105: ($permission->{'cusr'})) {
6106: my $dom = $env{'form.domain'};
6107: my $uname = $env{'form.username'};
6108: my $warning;
6109: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
6110: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
6111: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
6112: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
6113: if ($uhome eq 'no_host') {
6114: my $queue = $env{'form.queue'};
6115: my $reqkey = &escape($uname).'_'.$queue;
6116: my $namespace = 'usernamequeue';
6117: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
6118: my %queued =
6119: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
6120: unless ($queued{$reqkey}) {
6121: $warning = &mt('No information was found for this LON-CAPA account request.');
6122: }
6123: } else {
6124: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
6125: }
6126: } else {
6127: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
6128: }
6129: } else {
6130: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
6131: }
6132: } else {
6133: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
6134: }
6135: my $args = { only_body => 1 };
6136: $r->print(&header(undef,$args).
6137: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
6138: if ($warning ne '') {
6139: $r->print('<div class="LC_warning">'.$warning.'</div>');
6140: } else {
6141: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
6142: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
6143: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6144: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6145: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
6146: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
6147: my %info =
6148: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
6149: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 6150: my $usertype = $info{$uname}{'inststatus'};
6151: unless ($usertype) {
6152: $usertype = 'default';
6153: }
1.442 raeburn 6154: my ($showstatus,$showemail,$pickstart);
6155: my $numextras = 0;
6156: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.443 raeburn 6157: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
6158: if (ref($usertypes) eq 'HASH') {
6159: if ($usertypes->{$usertype}) {
6160: $showstatus = $usertypes->{$usertype};
6161: } else {
6162: $showstatus = $othertitle;
6163: }
6164: if ($showstatus) {
6165: $numextras ++;
6166: }
1.442 raeburn 6167: }
6168: }
6169: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
6170: $showemail = $info{$uname}{'email'};
6171: $numextras ++;
6172: }
1.396 raeburn 6173: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
6174: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.442 raeburn 6175: $pickstart = 1;
1.396 raeburn 6176: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.442 raeburn 6177: my ($num,$count);
1.396 raeburn 6178: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.442 raeburn 6179: $count += $numextras;
1.396 raeburn 6180: foreach my $field (@{$infofields}) {
6181: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
6182: next unless ($infotitles->{$field});
6183: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
6184: $info{$uname}{$field});
6185: $num ++;
1.442 raeburn 6186: unless ($count == $num) {
1.396 raeburn 6187: $r->print(&Apache::lonhtmlcommon::row_closure());
6188: }
6189: }
1.442 raeburn 6190: }
6191: }
6192: if ($numextras) {
6193: unless ($pickstart) {
6194: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
6195: $pickstart = 1;
6196: }
6197: if ($showemail) {
6198: my $closure = '';
6199: unless ($showstatus) {
6200: $closure = 1;
1.391 raeburn 6201: }
1.442 raeburn 6202: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
6203: $showemail.
6204: &Apache::lonhtmlcommon::row_closure($closure));
1.391 raeburn 6205: }
1.442 raeburn 6206: if ($showstatus) {
6207: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
6208: $showstatus.
6209: &Apache::lonhtmlcommon::row_closure(1));
6210: }
6211: }
6212: if ($pickstart) {
6213: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
6214: } else {
6215: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
1.391 raeburn 6216: }
1.442 raeburn 6217: } else {
6218: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 6219: }
6220: }
6221: }
6222: }
6223: }
1.442 raeburn 6224: $r->print(&close_popup_form());
1.207 raeburn 6225: } elsif (($env{'form.action'} eq 'listusers') &&
6226: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 6227: my $helpitem = 'Course_View_Class_List';
6228: if ($context eq 'author') {
6229: $helpitem = 'Author_View_Coauthor_List';
6230: } elsif ($context eq 'domain') {
6231: $helpitem = 'Domain_View_Users_List';
6232: }
1.202 raeburn 6233: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 6234: push(@{$brcrum},
6235: {href => '/adm/createuser?action=listusers',
6236: text => "List Users"},
6237: {href => "/adm/createuser",
6238: text => "Result",
1.439 raeburn 6239: help => $helpitem});
1.351 raeburn 6240: $bread_crumbs_component = 'Update Users';
6241: $args = {bread_crumbs => $brcrum,
6242: bread_crumbs_component => $bread_crumbs_component};
6243: $r->print(&header(undef,$args));
1.202 raeburn 6244: my $setting = $env{'form.roletype'};
6245: my $choice = $env{'form.bulkaction'};
6246: if ($permission->{'cusr'}) {
1.336 raeburn 6247: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 6248: } else {
6249: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 6250: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 6251: }
6252: } else {
1.351 raeburn 6253: push(@{$brcrum},
6254: {href => '/adm/createuser?action=listusers',
6255: text => "List Users",
1.439 raeburn 6256: help => $helpitem});
1.351 raeburn 6257: $bread_crumbs_component = 'List Users';
6258: $args = {bread_crumbs => $brcrum,
6259: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 6260: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
6261: my $formname = 'studentform';
1.364 raeburn 6262: my $hidecall = "hide_searching();";
1.321 raeburn 6263: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
6264: ($env{'form.roletype'} eq 'community'))) {
6265: if ($env{'form.roletype'} eq 'course') {
6266: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
6267: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
6268: $formname);
6269: } elsif ($env{'form.roletype'} eq 'community') {
6270: $cb_jscript =
6271: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
6272: my %elements = (
6273: coursepick => 'radio',
6274: coursetotal => 'text',
6275: courselist => 'text',
6276: );
6277: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
6278: }
1.364 raeburn 6279: $jscript .= &verify_user_display($context)."\n".
6280: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 6281: my $js = &add_script($jscript).$cb_jscript;
6282: my $loadcode =
6283: &Apache::lonuserutils::course_selector_loadcode($formname);
6284: if ($loadcode ne '') {
1.364 raeburn 6285: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
6286: } else {
6287: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 6288: }
1.351 raeburn 6289: $r->print(&header($js,$args));
1.191 raeburn 6290: } else {
1.364 raeburn 6291: $args->{add_entries} = {onload => $hidecall};
6292: $jscript = &verify_user_display($context).
6293: &Apache::loncommon::check_uncheck_jscript();
6294: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 6295: }
1.202 raeburn 6296: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 6297: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
6298: $showcredits);
1.191 raeburn 6299: }
1.213 raeburn 6300: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 6301: my $brtext;
6302: if ($crstype eq 'Community') {
6303: $brtext = 'Drop Members';
6304: } else {
6305: $brtext = 'Drop Students';
6306: }
1.351 raeburn 6307: push(@{$brcrum},
6308: {href => '/adm/createuser?action=drop',
6309: text => $brtext,
6310: help => 'Course_Drop_Student'});
6311: if ($env{'form.state'} eq 'done') {
6312: push(@{$brcrum},
6313: {href=>'/adm/createuser?action=drop',
6314: text=>"Result"});
6315: }
6316: $bread_crumbs_component = $brtext;
6317: $args = {bread_crumbs => $brcrum,
6318: bread_crumbs_component => $bread_crumbs_component};
6319: $r->print(&header(undef,$args));
1.213 raeburn 6320: if (!exists($env{'form.state'})) {
1.318 raeburn 6321: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 6322: } elsif ($env{'form.state'} eq 'done') {
6323: &Apache::lonuserutils::update_user_list($r,$context,undef,
6324: $env{'form.action'});
6325: }
1.202 raeburn 6326: } elsif ($env{'form.action'} eq 'dateselect') {
6327: if ($permission->{'cusr'}) {
1.351 raeburn 6328: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 6329: &Apache::lonuserutils::date_section_selector($context,$permission,
6330: $crstype,$showcredits));
1.202 raeburn 6331: } else {
1.351 raeburn 6332: $r->print(&header(undef,{'no_nav_bar' => 1}).
6333: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 6334: }
1.237 raeburn 6335: } elsif ($env{'form.action'} eq 'selfenroll') {
1.469 raeburn 6336: my %currsettings;
6337: if ($permission->{selfenrolladmin} || $permission->{selfenrollview}) {
6338: %currsettings = (
1.398 raeburn 6339: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
6340: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
6341: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
6342: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
6343: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
6344: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
6345: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
6346: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
6347: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
6348: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
6349: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
6350: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
6351: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 6352: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 6353: );
1.469 raeburn 6354: }
6355: if ($permission->{selfenrolladmin}) {
1.398 raeburn 6356: push(@{$brcrum},
6357: {href => '/adm/createuser?action=selfenroll',
6358: text => "Configure Self-enrollment",
6359: help => 'Course_Self_Enrollment'});
6360: if (!exists($env{'form.state'})) {
6361: $args = { bread_crumbs => $brcrum,
6362: bread_crumbs_component => 'Configure Self-enrollment'};
6363: $r->print(&header(undef,$args));
6364: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
6365: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
6366: } elsif ($env{'form.state'} eq 'done') {
6367: push (@{$brcrum},
6368: {href=>'/adm/createuser?action=selfenroll',
6369: text=>"Result"});
6370: $args = { bread_crumbs => $brcrum,
6371: bread_crumbs_component => 'Self-enrollment result'};
6372: $r->print(&header(undef,$args));
6373: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 6374: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 6375: }
1.469 raeburn 6376: } elsif ($permission->{selfenrollview}) {
6377: push(@{$brcrum},
6378: {href => '/adm/createuser?action=selfenroll',
6379: text => "View Self-enrollment configuration",
6380: help => 'Course_Self_Enrollment'});
6381: $args = { bread_crumbs => $brcrum,
6382: bread_crumbs_component => 'Self-enrollment Settings'};
6383: $r->print(&header(undef,$args));
6384: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
6385: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings,'',1);
1.398 raeburn 6386: } else {
6387: $r->print(&header(undef,{'no_nav_bar' => 1}).
6388: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 6389: }
1.277 raeburn 6390: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 6391: if ($permission->{selfenrolladmin}) {
1.351 raeburn 6392: push(@{$brcrum},
6393: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 6394: text => 'Enrollment requests',
1.439 raeburn 6395: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 6396: $bread_crumbs_component = 'Enrollment requests';
6397: if ($env{'form.state'} eq 'done') {
6398: push(@{$brcrum},
6399: {href => '/adm/createuser?action=selfenrollqueue',
6400: text => 'Result',
1.439 raeburn 6401: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 6402: $bread_crumbs_component = 'Enrollment result';
6403: }
6404: $args = { bread_crumbs => $brcrum,
6405: bread_crumbs_component => $bread_crumbs_component};
6406: $r->print(&header(undef,$args));
6407: my $coursedesc = $env{'course.'.$cid.'.description'};
6408: if (!exists($env{'form.state'})) {
6409: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
6410: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
6411: $cdom,$cnum));
6412: } elsif ($env{'form.state'} eq 'done') {
6413: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
6414: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 6415: $cdom,$cnum,$coursedesc));
1.418 raeburn 6416: }
6417: } else {
6418: $r->print(&header(undef,{'no_nav_bar' => 1}).
6419: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 6420: }
1.418 raeburn 6421: } elsif ($env{'form.action'} eq 'changelogs') {
6422: if ($permission->{cusr} || $permission->{view}) {
6423: &print_userchangelogs_display($r,$context,$permission,$brcrum);
6424: } else {
6425: $r->print(&header(undef,{'no_nav_bar' => 1}).
6426: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 6427: }
1.428 raeburn 6428: } elsif ($env{'form.action'} eq 'helpdesk') {
1.464 raeburn 6429: if (($permission->{'owner'} || $permission->{'co-owner'}) &&
6430: ($permission->{'cusr'} || $permission->{'view'})) {
1.428 raeburn 6431: if ($env{'form.state'} eq 'process') {
6432: if ($permission->{'owner'}) {
6433: &update_helpdeskaccess($r,$permission,$brcrum);
6434: } else {
6435: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 6436: }
1.428 raeburn 6437: } else {
6438: &print_helpdeskaccess_display($r,$permission,$brcrum);
6439: }
6440: } else {
6441: $r->print(&header(undef,{'no_nav_bar' => 1}).
6442: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
6443: }
1.465 raeburn 6444: } elsif ($env{'form.action'} eq 'rolerequests') {
6445: if ($permission->{cusr} || $permission->{view}) {
6446: &print_queued_roles($r,$context,$permission,$brcrum);
6447: }
6448: } elsif ($env{'form.action'} eq 'queuedroles') {
6449: if (($permission->{cusr}) && ($context eq 'domain')) {
6450: if (&show_role_requests($context,$env{'request.role.domain'})) {
6451: if ($env{'form.state'} eq 'done') {
6452: &process_pendingroles($r,$context,$permission,$brcrum);
6453: } else {
6454: &print_pendingroles($r,$context,$permission,$brcrum);
6455: }
6456: } else {
6457: $r->print(&header(undef,{'no_nav_bar' => 1}).
6458: '<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>');
6459: }
6460: } else {
6461: $r->print(&header(undef,{'no_nav_bar' => 1}).
6462: '<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>');
6463: }
1.470 raeburn 6464: } elsif ($env{'form.action'} eq 'camanagers') {
6465: if (($permission->{cusr}) && ($context eq 'author')) {
6466: push(@{$brcrum},
6467: {href => '/adm/createuser?action=camanagers',
1.473 raeburn 6468: text => 'Co-author Managers',
1.470 raeburn 6469: help => 'Author_Manage_Coauthors'});
6470: if ($env{'form.state'} eq 'process') {
6471: push(@{$brcrum},
6472: {href => '/adm/createuser?action=camanagers',
6473: text => 'Result',
6474: help => 'Author_Manage_Coauthors'});
6475: }
6476: $args = { bread_crumbs => $brcrum };
6477: $r->print(&header(undef,$args));
6478: my $coursedesc = $env{'course.'.$cid.'.description'};
6479: if (!exists($env{'form.state'})) {
6480: $r->print('<h3>'.&mt('Co-author Management').'</h3>'."\n".
6481: &display_coauthor_managers($permission));
6482: } elsif ($env{'form.state'} eq 'process') {
6483: $r->print('<h3>'.&mt('Co-author Management Update Result').'</h3>'."\n".
6484: &update_coauthor_managers($permission));
6485: }
6486: }
6487: } elsif (($env{'form.action'} eq 'calist') && ($context eq 'author')) {
6488: if ($permission->{'cusr'}) {
6489: my ($role,$audom,$auname,$canview,$canedit) =
6490: &Apache::lonviewcoauthors::get_allowable();
6491: if (($canedit) && ($env{'form.forceedit'})) {
6492: &Apache::lonviewcoauthors::get_editor_crumbs($brcrum,'/adm/createuser');
6493: my $args = { 'bread_crumbs' => $brcrum };
6494: $r->print(&Apache::loncommon::start_page('Configure co-author listing',undef,
6495: $args).
6496: &Apache::lonviewcoauthors::edit_settings($audom,$auname,$role,
6497: '/adm/createuser'));
6498: } else {
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: }
6517: }
6518: } else {
6519: $r->internal_redirect('/adm/viewcoauthors');
6520: return OK;
6521: }
1.481 raeburn 6522: } elsif (($env{'form.action'} eq 'setenv') && ($context eq 'author')) {
6523: my ($role,$audom,$auname,$canview,$canedit) =
6524: &Apache::lonviewcoauthors::get_allowable();
6525: push(@{$brcrum},
6526: {href => '/adm/createuser?action=calist',
6527: text => 'Coauthor-viewable list',
6528: help => 'Author_List_Coauthors'});
6529: my $args = { 'bread_crumbs' => $brcrum };
6530: $r->print(&Apache::loncommon::start_page('Coauthor-viewable list',undef,
6531: $args));
6532: my %viewsettings =
6533: &Apache::lonviewcoauthors::retrieve_view_settings($auname,$audom,$role);
6534: if ($viewsettings{'show'} eq 'none') {
6535: $r->print('<h3>'.&mt('Coauthor-viewable listing').'</h3>'.
6536: '<p class="LC_info">'.
6537: &mt('Listing of co-authors not enabled for this Authoring Space').
6538: '</p>');
6539: } else {
6540: &Apache::lonviewcoauthors::print_coauthors($r,$auname,$audom,$role,
6541: '/adm/createuser',\%viewsettings);
6542: }
1.190 raeburn 6543: } else {
1.351 raeburn 6544: $bread_crumbs_component = 'User Management';
6545: $args = { bread_crumbs => $brcrum,
6546: bread_crumbs_component => $bread_crumbs_component};
6547: $r->print(&header(undef,$args));
1.318 raeburn 6548: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 6549: }
1.351 raeburn 6550: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 6551: return OK;
6552: }
6553:
6554: sub header {
1.351 raeburn 6555: my ($jscript,$args) = @_;
1.190 raeburn 6556: my $start_page;
1.351 raeburn 6557: if (ref($args) eq 'HASH') {
6558: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 6559: } else {
1.351 raeburn 6560: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 6561: }
6562: return $start_page;
6563: }
1.2 www 6564:
1.191 raeburn 6565: sub add_script {
6566: my ($js) = @_;
1.301 bisitz 6567: return '<script type="text/javascript">'."\n"
6568: .'// <![CDATA['."\n"
6569: .$js."\n"
6570: .'// ]]>'."\n"
6571: .'</script>'."\n";
1.191 raeburn 6572: }
6573:
1.391 raeburn 6574: sub usernamerequest_javascript {
6575: my $js = <<ENDJS;
6576:
6577: function openusernamereqdisplay(dom,uname,queue) {
6578: var url = '/adm/createuser?action=displayuserreq';
6579: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
6580: var title = 'Account_Request_Browser';
6581: var options = 'scrollbars=1,resizable=1,menubar=0';
6582: options += ',width=700,height=600';
6583: var stdeditbrowser = open(url,title,options,'1');
6584: stdeditbrowser.focus();
6585: return;
6586: }
6587:
6588: ENDJS
6589: }
6590:
6591: sub close_popup_form {
6592: my $close= &mt('Close Window');
6593: return << "END";
6594: <p><form name="displayreq" action="" method="post">
6595: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
6596: </form></p>
6597: END
6598: }
6599:
1.202 raeburn 6600: sub verify_user_display {
1.364 raeburn 6601: my ($context) = @_;
1.374 raeburn 6602: my %lt = &Apache::lonlocal::texthash (
6603: course => 'course(s): description, section(s), status',
6604: community => 'community(s): description, section(s), status',
6605: author => 'author',
6606: );
1.364 raeburn 6607: my $photos;
6608: if (($context eq 'course') && $env{'request.course.id'}) {
6609: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
6610: }
1.202 raeburn 6611: my $output = <<"END";
6612:
1.364 raeburn 6613: function hide_searching() {
6614: if (document.getElementById('searching')) {
6615: document.getElementById('searching').style.display = 'none';
6616: }
6617: return;
6618: }
6619:
1.202 raeburn 6620: function display_update() {
6621: document.studentform.action.value = 'listusers';
6622: document.studentform.phase.value = 'display';
6623: document.studentform.submit();
6624: }
6625:
1.364 raeburn 6626: function updateCols(caller) {
6627: var context = '$context';
6628: var photos = '$photos';
6629: if (caller == 'Status') {
1.374 raeburn 6630: if ((context == 'domain') &&
6631: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
6632: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 6633: document.getElementById('showcolstatus').checked = false;
6634: document.getElementById('showcolstatus').disabled = 'disabled';
6635: document.getElementById('showcolstart').checked = false;
6636: document.getElementById('showcolend').checked = false;
1.374 raeburn 6637: } else {
6638: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
6639: document.getElementById('showcolstatus').checked = true;
6640: document.getElementById('showcolstatus').disabled = '';
6641: document.getElementById('showcolstart').checked = true;
6642: document.getElementById('showcolend').checked = true;
6643: } else {
6644: document.getElementById('showcolstatus').checked = false;
6645: document.getElementById('showcolstatus').disabled = 'disabled';
6646: document.getElementById('showcolstart').checked = false;
6647: document.getElementById('showcolend').checked = false;
6648: }
1.472 raeburn 6649: if (context == 'author') {
6650: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Expired') {
6651: document.getElementById('showcolmanager').checked = false;
6652: document.getElementById('showcolmanager').disabled = 'disabled';
6653: } else if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value != 'aa') {
6654: document.getElementById('showcolmanager').checked = true;
6655: document.getElementById('showcolmanager').disabled = '';
6656: }
6657: }
1.364 raeburn 6658: }
6659: }
6660: if (caller == 'output') {
6661: if (photos == 1) {
6662: if (document.getElementById('showcolphoto')) {
6663: var photoitem = document.getElementById('showcolphoto');
6664: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
6665: photoitem.checked = true;
6666: photoitem.disabled = '';
6667: } else {
6668: photoitem.checked = false;
6669: photoitem.disabled = 'disabled';
6670: }
6671: }
6672: }
6673: }
6674: if (caller == 'showrole') {
1.371 raeburn 6675: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
6676: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 6677: document.getElementById('showcolrole').checked = true;
6678: document.getElementById('showcolrole').disabled = '';
6679: } else {
6680: document.getElementById('showcolrole').checked = false;
6681: document.getElementById('showcolrole').disabled = 'disabled';
6682: }
1.374 raeburn 6683: if (context == 'domain') {
1.382 raeburn 6684: var quotausageshow = 0;
1.374 raeburn 6685: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
6686: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
6687: document.getElementById('showcolstatus').checked = false;
6688: document.getElementById('showcolstatus').disabled = 'disabled';
6689: document.getElementById('showcolstart').checked = false;
6690: document.getElementById('showcolend').checked = false;
6691: } else {
6692: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
6693: document.getElementById('showcolstatus').checked = true;
6694: document.getElementById('showcolstatus').disabled = '';
6695: document.getElementById('showcolstart').checked = true;
6696: document.getElementById('showcolend').checked = true;
6697: }
6698: }
6699: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
6700: document.getElementById('showcolextent').disabled = 'disabled';
6701: document.getElementById('showcolextent').checked = 'false';
6702: document.getElementById('showextent').style.display='none';
6703: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 6704: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
6705: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
6706: if (document.getElementById('showcolauthorusage')) {
6707: document.getElementById('showcolauthorusage').disabled = '';
6708: }
6709: if (document.getElementById('showcolauthorquota')) {
6710: document.getElementById('showcolauthorquota').disabled = '';
6711: }
6712: quotausageshow = 1;
6713: }
1.374 raeburn 6714: } else {
6715: document.getElementById('showextent').style.display='block';
6716: document.getElementById('showextent').style.textAlign='left';
6717: document.getElementById('showextent').style.textFace='normal';
6718: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
6719: document.getElementById('showcolextent').disabled = '';
6720: document.getElementById('showcolextent').checked = 'true';
6721: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
6722: } else {
6723: document.getElementById('showcolextent').disabled = '';
6724: document.getElementById('showcolextent').checked = 'true';
6725: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
6726: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
6727: } else {
6728: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
6729: }
6730: }
6731: }
1.382 raeburn 6732: if (quotausageshow == 0) {
6733: if (document.getElementById('showcolauthorusage')) {
6734: document.getElementById('showcolauthorusage').checked = false;
6735: document.getElementById('showcolauthorusage').disabled = 'disabled';
6736: }
6737: if (document.getElementById('showcolauthorquota')) {
6738: document.getElementById('showcolauthorquota').checked = false;
6739: document.getElementById('showcolauthorquota').disabled = 'disabled';
6740: }
6741: }
1.374 raeburn 6742: }
1.472 raeburn 6743: if (context == 'author') {
6744: if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'aa') {
6745: document.getElementById('showcolmanager').checked = false;
6746: document.getElementById('showcolmanager').disabled = 'disabled';
6747: } else if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value != 'Expired') {
6748: document.getElementById('showcolmanager').checked = true;
6749: document.getElementById('showcolmanager').disabled = '';
6750: }
6751: }
1.364 raeburn 6752: }
6753: return;
6754: }
6755:
1.202 raeburn 6756: END
6757: return $output;
6758:
6759: }
6760:
1.190 raeburn 6761: ###############################################################
6762: ###############################################################
6763: # Menu Phase One
6764: sub print_main_menu {
1.318 raeburn 6765: my ($permission,$context,$crstype) = @_;
6766: my $linkcontext = $context;
6767: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
6768: if (($context eq 'course') && ($crstype eq 'Community')) {
6769: $linkcontext = lc($crstype);
6770: $stuterm = 'Members';
6771: }
1.208 raeburn 6772: my %links = (
1.298 droeschl 6773: domain => {
6774: upload => 'Upload a File of Users',
6775: singleuser => 'Add/Modify a User',
6776: listusers => 'Manage Users',
6777: },
6778: author => {
6779: upload => 'Upload a File of Co-authors',
6780: singleuser => 'Add/Modify a Co-author',
6781: listusers => 'Manage Co-authors',
6782: },
6783: course => {
6784: upload => 'Upload a File of Course Users',
6785: singleuser => 'Add/Modify a Course User',
1.354 www 6786: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 6787: },
1.318 raeburn 6788: community => {
6789: upload => 'Upload a File of Community Users',
6790: singleuser => 'Add/Modify a Community User',
1.354 www 6791: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 6792: },
6793: );
6794: my %linktitles = (
6795: domain => {
6796: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
6797: listusers => 'Show and manage users in this domain.',
6798: },
6799: author => {
6800: singleuser => 'Add a user with a co- or assistant author role.',
6801: listusers => 'Show and manage co- or assistant authors.',
6802: },
6803: course => {
6804: singleuser => 'Add a user with a certain role to this course.',
6805: listusers => 'Show and manage users in this course.',
6806: },
6807: community => {
6808: singleuser => 'Add a user with a certain role to this community.',
6809: listusers => 'Show and manage users in this community.',
6810: },
1.298 droeschl 6811: );
1.465 raeburn 6812:
1.418 raeburn 6813: if ($linkcontext eq 'domain') {
6814: unless ($permission->{'cusr'}) {
1.430 raeburn 6815: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 6816: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
6817: }
6818: } elsif ($linkcontext eq 'course') {
6819: unless ($permission->{'cusr'}) {
6820: $links{'course'}{'singleuser'} = 'View a Course User';
6821: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
6822: $links{'course'}{'listusers'} = 'List Course Users';
6823: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
6824: }
6825: } elsif ($linkcontext eq 'community') {
6826: unless ($permission->{'cusr'}) {
6827: $links{'community'}{'singleuser'} = 'View a Community User';
6828: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
6829: $links{'community'}{'listusers'} = 'List Community Users';
6830: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
6831: }
6832: }
1.298 droeschl 6833: my @menu = ( {categorytitle => 'Single Users',
6834: items =>
6835: [
6836: {
1.318 raeburn 6837: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 6838: icon => 'edit-redo.png',
6839: #help => 'Course_Change_Privileges',
6840: url => '/adm/createuser?action=singleuser',
1.418 raeburn 6841: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 6842: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 6843: },
6844: ]},
6845:
6846: {categorytitle => 'Multiple Users',
6847: items =>
6848: [
6849: {
1.318 raeburn 6850: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 6851: icon => 'uplusr.png',
1.298 droeschl 6852: #help => 'Course_Create_Class_List',
6853: url => '/adm/createuser?action=upload',
6854: permission => $permission->{'cusr'},
6855: linktitle => 'Upload a CSV or a text file containing users.',
6856: },
6857: {
1.318 raeburn 6858: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 6859: icon => 'mngcu.png',
1.298 droeschl 6860: #help => 'Course_View_Class_List',
6861: url => '/adm/createuser?action=listusers',
6862: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 6863: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 6864: },
6865:
6866: ]},
6867:
6868: {categorytitle => 'Administration',
6869: items => [ ]},
6870: );
1.415 raeburn 6871:
1.265 mielkec 6872: if ($context eq 'domain'){
1.416 raeburn 6873: push(@{ $menu[0]->{items} }, # Single Users
6874: {
6875: linktext => 'User Access Log',
1.417 raeburn 6876: icon => 'document-properties.png',
1.425 raeburn 6877: #help => 'Domain_User_Access_Logs',
1.416 raeburn 6878: url => '/adm/createuser?action=accesslogs',
6879: permission => $permission->{'activity'},
6880: linktitle => 'View user access log.',
6881: }
6882: );
1.298 droeschl 6883:
6884: push(@{ $menu[2]->{items} }, #Category: Administration
6885: {
6886: linktext => 'Custom Roles',
6887: icon => 'emblem-photos.png',
6888: #help => 'Course_Editing_Custom_Roles',
6889: url => '/adm/createuser?action=custom',
6890: permission => $permission->{'custom'},
6891: linktitle => 'Configure a custom role.',
6892: },
1.362 raeburn 6893: {
6894: linktext => 'Authoring Space Requests',
6895: icon => 'selfenrl-queue.png',
6896: #help => 'Domain_Role_Approvals',
6897: url => '/adm/createuser?action=processauthorreq',
6898: permission => $permission->{'cusr'},
6899: linktitle => 'Approve or reject author role requests',
6900: },
1.363 raeburn 6901: {
1.391 raeburn 6902: linktext => 'LON-CAPA Account Requests',
6903: icon => 'list-add.png',
6904: #help => 'Domain_Username_Approvals',
6905: url => '/adm/createuser?action=processusernamereq',
6906: permission => $permission->{'cusr'},
6907: linktitle => 'Approve or reject LON-CAPA account requests',
6908: },
6909: {
1.363 raeburn 6910: linktext => 'Change Log',
6911: icon => 'document-properties.png',
6912: #help => 'Course_User_Logs',
6913: url => '/adm/createuser?action=changelogs',
1.418 raeburn 6914: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 6915: linktitle => 'View change log.',
6916: },
1.298 droeschl 6917: );
6918:
1.265 mielkec 6919: }elsif ($context eq 'course'){
1.298 droeschl 6920: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 6921:
6922: my %linktext = (
6923: 'Course' => {
6924: single => 'Add/Modify a Student',
6925: drop => 'Drop Students',
6926: groups => 'Course Groups',
6927: },
6928: 'Community' => {
6929: single => 'Add/Modify a Member',
6930: drop => 'Drop Members',
6931: groups => 'Community Groups',
6932: },
6933: );
1.411 raeburn 6934: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 6935:
6936: my %linktitle = (
6937: 'Course' => {
6938: single => 'Add a user with the role of student to this course',
6939: drop => 'Remove a student from this course.',
6940: groups => 'Manage course groups',
6941: },
6942: 'Community' => {
6943: single => 'Add a user with the role of member to this community',
6944: drop => 'Remove a member from this community.',
6945: groups => 'Manage community groups',
6946: },
6947: );
6948:
1.411 raeburn 6949: $linktitle{'Placement'} = $linktitle{'Course'};
6950:
1.298 droeschl 6951: push(@{ $menu[0]->{items} }, #Category: Single Users
6952: {
1.318 raeburn 6953: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 6954: #help => 'Course_Add_Student',
6955: icon => 'list-add.png',
6956: url => '/adm/createuser?action=singlestudent',
6957: permission => $permission->{'cusr'},
1.318 raeburn 6958: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 6959: },
6960: );
6961:
6962: push(@{ $menu[1]->{items} }, #Category: Multiple Users
6963: {
1.318 raeburn 6964: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 6965: icon => 'edit-undo.png',
6966: #help => 'Course_Drop_Student',
6967: url => '/adm/createuser?action=drop',
6968: permission => $permission->{'cusr'},
1.318 raeburn 6969: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 6970: },
6971: );
6972: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 6973: {
6974: linktext => 'Helpdesk Access',
6975: icon => 'helpdesk-access.png',
6976: #help => 'Course_Helpdesk_Access',
6977: url => '/adm/createuser?action=helpdesk',
1.464 raeburn 6978: permission => (($permission->{'owner'} || $permission->{'co-owner'}) &&
6979: ($permission->{'view'} || $permission->{'cusr'})),
1.428 raeburn 6980: linktitle => 'Helpdesk access options',
6981: },
6982: {
1.298 droeschl 6983: linktext => 'Custom Roles',
6984: icon => 'emblem-photos.png',
6985: #help => 'Course_Editing_Custom_Roles',
6986: url => '/adm/createuser?action=custom',
6987: permission => $permission->{'custom'},
6988: linktitle => 'Configure a custom role.',
6989: },
6990: {
1.318 raeburn 6991: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 6992: icon => 'grps.png',
1.298 droeschl 6993: #help => 'Course_Manage_Group',
6994: url => '/adm/coursegroups?refpage=cusr',
6995: permission => $permission->{'grp_manage'},
1.318 raeburn 6996: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 6997: },
6998: {
1.328 wenzelju 6999: linktext => 'Change Log',
1.298 droeschl 7000: icon => 'document-properties.png',
7001: #help => 'Course_User_Logs',
7002: url => '/adm/createuser?action=changelogs',
1.418 raeburn 7003: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 7004: linktitle => 'View change log.',
7005: },
7006: );
1.277 raeburn 7007: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 7008: push(@{ $menu[2]->{items} },
1.398 raeburn 7009: {
1.298 droeschl 7010: linktext => 'Enrollment Requests',
7011: icon => 'selfenrl-queue.png',
7012: #help => 'Course_Approve_Selfenroll',
7013: url => '/adm/createuser?action=selfenrollqueue',
1.469 raeburn 7014: permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.298 droeschl 7015: linktitle =>'Approve or reject enrollment requests.',
7016: },
7017: );
1.277 raeburn 7018: }
1.298 droeschl 7019:
1.265 mielkec 7020: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 7021: if ($crstype ne 'Community') {
7022: push(@{ $menu[2]->{items} },
7023: {
7024: linktext => 'Automated Enrollment',
7025: icon => 'roles.png',
7026: #help => 'Course_Automated_Enrollment',
7027: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 7028: && (($permission->{'cusr'}) ||
7029: ($permission->{'view'}))),
1.320 raeburn 7030: url => '/adm/populate',
7031: linktitle => 'Automated enrollment manager.',
7032: }
7033: );
7034: }
7035: push(@{ $menu[2]->{items} },
1.298 droeschl 7036: {
7037: linktext => 'User Self-Enrollment',
1.342 wenzelju 7038: icon => 'self_enroll.png',
1.298 droeschl 7039: #help => 'Course_Self_Enrollment',
7040: url => '/adm/createuser?action=selfenroll',
1.469 raeburn 7041: permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.317 bisitz 7042: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 7043: },
7044: );
7045: }
1.363 raeburn 7046: } elsif ($context eq 'author') {
1.481 raeburn 7047: my $coauthorlist;
7048: if ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)$}) {
7049: if ($env{'environment.internal.coauthorlist./'.$1.'/'.$2}) {
7050: $coauthorlist = 1;
7051: }
7052: } elsif ($env{'request.role'} eq "au./$env{'user.domain'}/") {
7053: if ($env{'environment.coauthorlist'}) {
7054: $coauthorlist = 1;
7055: }
7056: }
7057: if ($coauthorlist) {
7058: push(@{ $menu[1]->{items} },
7059: {
7060: linktext => 'Co-author-viewable list',
7061: icon => 'clst.png',
7062: #help => 'Coauthor_Listing',
7063: url => '/adm/createuser?action=calist&forceedit=0',
7064: permission => $permission->{'cusr'},
7065: linktitle => 'Co-author-viewable listing',
7066: });
7067: }
1.370 raeburn 7068: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 7069: {
7070: linktext => 'Change Log',
7071: icon => 'document-properties.png',
7072: #help => 'Course_User_Logs',
7073: url => '/adm/createuser?action=changelogs',
7074: permission => $permission->{'cusr'},
7075: linktitle => 'View change log.',
7076: },
1.470 raeburn 7077: {
1.472 raeburn 7078: linktext => 'Co-author Managers',
1.473 raeburn 7079: icon => 'camanager.png',
1.470 raeburn 7080: #help => 'Coauthor_Management',
7081: url => '/adm/createuser?action=camanagers',
7082: permission => $permission->{'author'},
7083: linktitle => 'Assign/Revoke right to manage co-author roles',
7084: },
7085: {
1.473 raeburn 7086: linktext => 'Configure Co-author Listing',
7087: icon => 'coauthors.png',
1.470 raeburn 7088: #help => 'Coauthor_Settings',
7089: url => '/adm/createuser?action=calist&forceedit=1',
7090: permission => ($permission->{'cusr'}),
7091: linktitle => 'Set availability of coauthor-viewable user listing',
7092: },
1.370 raeburn 7093: );
1.363 raeburn 7094: }
1.465 raeburn 7095: push(@{ $menu[2]->{items} },
7096: {
7097: linktext => 'Role Requests (other domains)',
7098: icon => 'edit-find.png',
7099: #help => 'Role_Requests',
7100: url => '/adm/createuser?action=rolerequests',
7101: permission => $permission->{'cusr'},
7102: linktitle => 'Role requests for users in other domains',
7103: },
7104: );
7105: if (&show_role_requests($context,$env{'request.role.domain'})) {
7106: push(@{ $menu[2]->{items} },
7107: {
7108: linktext => 'Queued Role Assignments (this domain)',
7109: icon => 'edit-find.png',
7110: #help => 'Role_Approvals',
7111: url => '/adm/createuser?action=queuedroles',
7112: permission => $permission->{'cusr'},
7113: linktitle => "Role requests for this domain's users",
7114: },
7115: );
7116: }
1.363 raeburn 7117: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 7118: # { text => 'View Log-in History',
7119: # help => 'Course_User_Logins',
7120: # action => 'logins',
7121: # permission => $permission->{'cusr'},
7122: # });
1.190 raeburn 7123: }
7124:
1.189 albertel 7125: sub restore_prev_selections {
7126: my %saveable_parameters = ('srchby' => 'scalar',
7127: 'srchin' => 'scalar',
7128: 'srchtype' => 'scalar',
7129: );
7130: &Apache::loncommon::store_settings('user','user_picker',
7131: \%saveable_parameters);
7132: &Apache::loncommon::restore_settings('user','user_picker',
7133: \%saveable_parameters);
7134: }
7135:
1.237 raeburn 7136: sub print_selfenroll_menu {
1.418 raeburn 7137: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 7138: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 7139: my $formname = 'selfenroll';
1.237 raeburn 7140: my $nolink = 1;
1.398 raeburn 7141: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 7142: my $groupslist = &Apache::lonuserutils::get_groupslist();
7143: my $setsec_js =
7144: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 7145: my %alerts = &Apache::lonlocal::texthash(
7146: acto => 'Activation of self-enrollment was selected for the following domain(s)',
7147: butn => 'but no user types have been checked.',
7148: wilf => "Please uncheck 'activate' or check at least one type.",
7149: );
1.418 raeburn 7150: my $disabled;
7151: if ($readonly) {
7152: $disabled = ' disabled="disabled"';
7153: }
1.405 damieng 7154: &js_escape(\%alerts);
1.249 raeburn 7155: my $selfenroll_js = <<"ENDSCRIPT";
7156: function update_types(caller,num) {
7157: var delidx = getIndexByName('selfenroll_delete');
7158: var actidx = getIndexByName('selfenroll_activate');
7159: if (caller == 'selfenroll_all') {
7160: var selall;
7161: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
7162: if (document.$formname.selfenroll_all[i].checked) {
7163: selall = document.$formname.selfenroll_all[i].value;
7164: }
7165: }
7166: if (selall == 1) {
7167: if (delidx != -1) {
7168: if (document.$formname.selfenroll_delete.length) {
7169: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
7170: document.$formname.selfenroll_delete[j].checked = true;
7171: }
7172: } else {
7173: document.$formname.elements[delidx].checked = true;
7174: }
7175: }
7176: if (actidx != -1) {
7177: if (document.$formname.selfenroll_activate.length) {
7178: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
7179: document.$formname.selfenroll_activate[j].checked = false;
7180: }
7181: } else {
7182: document.$formname.elements[actidx].checked = false;
7183: }
7184: }
7185: document.$formname.selfenroll_newdom.selectedIndex = 0;
7186: }
7187: }
7188: if (caller == 'selfenroll_activate') {
7189: if (document.$formname.selfenroll_activate.length) {
7190: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
7191: if (document.$formname.selfenroll_activate[j].value == num) {
7192: if (document.$formname.selfenroll_activate[j].checked) {
7193: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
7194: if (document.$formname.selfenroll_all[i].value == '1') {
7195: document.$formname.selfenroll_all[i].checked = false;
7196: }
7197: if (document.$formname.selfenroll_all[i].value == '0') {
7198: document.$formname.selfenroll_all[i].checked = true;
7199: }
7200: }
7201: }
7202: }
7203: }
7204: } else {
7205: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
7206: if (document.$formname.selfenroll_all[i].value == '1') {
7207: document.$formname.selfenroll_all[i].checked = false;
7208: }
7209: if (document.$formname.selfenroll_all[i].value == '0') {
7210: document.$formname.selfenroll_all[i].checked = true;
7211: }
7212: }
7213: }
7214: }
7215: if (caller == 'selfenroll_delete') {
7216: if (document.$formname.selfenroll_delete.length) {
7217: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
7218: if (document.$formname.selfenroll_delete[j].value == num) {
7219: if (document.$formname.selfenroll_delete[j].checked) {
7220: var delindex = getIndexByName('selfenroll_types_'+num);
7221: if (delindex != -1) {
7222: if (document.$formname.elements[delindex].length) {
7223: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
7224: document.$formname.elements[delindex][k].checked = false;
7225: }
7226: } else {
7227: document.$formname.elements[delindex].checked = false;
7228: }
7229: }
7230: }
7231: }
7232: }
7233: } else {
7234: if (document.$formname.selfenroll_delete.checked) {
7235: var delindex = getIndexByName('selfenroll_types_'+num);
7236: if (delindex != -1) {
7237: if (document.$formname.elements[delindex].length) {
7238: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
7239: document.$formname.elements[delindex][k].checked = false;
7240: }
7241: } else {
7242: document.$formname.elements[delindex].checked = false;
7243: }
7244: }
7245: }
7246: }
7247: }
7248: return;
7249: }
7250:
7251: function validate_types(form) {
7252: var needaction = new Array();
7253: var countfail = 0;
7254: var actidx = getIndexByName('selfenroll_activate');
7255: if (actidx != -1) {
7256: if (document.$formname.selfenroll_activate.length) {
7257: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
7258: var num = document.$formname.selfenroll_activate[j].value;
7259: if (document.$formname.selfenroll_activate[j].checked) {
7260: countfail = check_types(num,countfail,needaction)
7261: }
7262: }
7263: } else {
7264: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 7265: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 7266: countfail = check_types(num,countfail,needaction)
7267: }
7268: }
7269: }
7270: if (countfail > 0) {
7271: var msg = "$alerts{'acto'}\\n";
7272: var loopend = needaction.length -1;
7273: if (loopend > 0) {
7274: for (var m=0; m<loopend; m++) {
7275: msg += needaction[m]+", ";
7276: }
7277: }
7278: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
7279: alert(msg);
7280: return;
7281: }
7282: setSections(form);
7283: }
7284:
7285: function check_types(num,countfail,needaction) {
1.441 raeburn 7286: var boxname = 'selfenroll_types_'+num;
7287: var typeidx = getIndexByName(boxname);
1.249 raeburn 7288: var count = 0;
7289: if (typeidx != -1) {
1.441 raeburn 7290: if (document.$formname.elements[boxname].length) {
7291: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
7292: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 7293: count ++;
7294: }
7295: }
7296: } else {
7297: if (document.$formname.elements[typeidx].checked) {
7298: count ++;
7299: }
7300: }
7301: if (count == 0) {
7302: var domidx = getIndexByName('selfenroll_dom_'+num);
7303: if (domidx != -1) {
7304: var domname = document.$formname.elements[domidx].value;
7305: needaction[countfail] = domname;
7306: countfail ++;
7307: }
7308: }
7309: }
7310: return countfail;
7311: }
7312:
1.398 raeburn 7313: function toggleNotify() {
7314: var selfenrollApproval = 0;
7315: if (document.$formname.selfenroll_approval.length) {
7316: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
7317: if (document.$formname.selfenroll_approval[i].checked) {
7318: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
7319: break;
7320: }
7321: }
7322: }
7323: if (document.getElementById('notified')) {
7324: if (selfenrollApproval == 0) {
7325: document.getElementById('notified').style.display='none';
7326: } else {
7327: document.getElementById('notified').style.display='block';
7328: }
7329: }
7330: return;
7331: }
7332:
1.249 raeburn 7333: function getIndexByName(item) {
7334: for (var i=0;i<document.$formname.elements.length;i++) {
7335: if (document.$formname.elements[i].name == item) {
7336: return i;
7337: }
7338: }
7339: return -1;
7340: }
7341: ENDSCRIPT
1.256 raeburn 7342:
1.237 raeburn 7343: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 7344: '// <![CDATA['."\n".
1.249 raeburn 7345: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 7346: '// ]]>'."\n".
1.237 raeburn 7347: '</script>'."\n".
1.256 raeburn 7348: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.469 raeburn 7349: my $visactions = &cat_visibility($cdom);
1.400 raeburn 7350: my ($cathash,%cattype);
7351: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
7352: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7353: $cathash = $domconfig{'coursecategories'}{'cats'};
7354: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
7355: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 7356: if ($cattype{'auth'} eq '') {
7357: $cattype{'auth'} = 'std';
7358: }
7359: if ($cattype{'unauth'} eq '') {
7360: $cattype{'unauth'} = 'std';
7361: }
1.400 raeburn 7362: } else {
7363: $cathash = {};
7364: $cattype{'auth'} = 'std';
7365: $cattype{'unauth'} = 'std';
7366: }
7367: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
7368: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7369: '<br />'.
7370: '<br />'.$visactions->{'take'}.'<ul>'.
7371: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
7372: '</ul>');
7373: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
7374: if ($currsettings->{'uniquecode'}) {
7375: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
7376: } else {
7377: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7378: '<br />'.
7379: '<br />'.$visactions->{'take'}.'<ul>'.
7380: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
7381: '</ul><br />');
7382: }
7383: } else {
7384: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
7385: if (ref($visactions) eq 'HASH') {
7386: if ($visible) {
7387: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
7388: } else {
7389: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
7390: .$visactions->{'yous'}.
7391: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
7392: if (ref($vismsgs) eq 'ARRAY') {
7393: $output .= '<br />'.$visactions->{'make'}.'<ul>';
7394: foreach my $item (@{$vismsgs}) {
7395: $output .= '<li>'.$visactions->{$item}.'</li>';
7396: }
7397: $output .= '</ul>';
1.256 raeburn 7398: }
1.400 raeburn 7399: $output .= '</p>';
1.256 raeburn 7400: }
7401: }
7402: }
1.398 raeburn 7403: my $actionhref = '/adm/createuser';
7404: if ($context eq 'domain') {
7405: $actionhref = '/adm/modifycourse';
7406: }
1.400 raeburn 7407:
7408: my %noedit;
7409: unless ($context eq 'domain') {
7410: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
7411: }
1.398 raeburn 7412: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 7413: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 7414: if (ref($row) eq 'ARRAY') {
7415: foreach my $item (@{$row}) {
7416: my $title = $item;
7417: if (ref($lt) eq 'HASH') {
7418: $title = $lt->{$item};
7419: }
1.297 bisitz 7420: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 7421: if ($item eq 'types') {
1.398 raeburn 7422: my $curr_types;
7423: if (ref($currsettings) eq 'HASH') {
7424: $curr_types = $currsettings->{'selfenroll_types'};
7425: }
1.400 raeburn 7426: if ($noedit{$item}) {
7427: if ($curr_types eq '*') {
7428: $output .= &mt('Any user in any domain');
7429: } else {
7430: my @entries = split(/;/,$curr_types);
7431: if (@entries > 0) {
7432: $output .= '<ul>';
7433: foreach my $entry (@entries) {
7434: my ($currdom,$typestr) = split(/:/,$entry);
7435: next if ($typestr eq '');
7436: my $domdesc = &Apache::lonnet::domain($currdom);
7437: my @currinsttypes = split(',',$typestr);
7438: my ($othertitle,$usertypes,$types) =
7439: &Apache::loncommon::sorted_inst_types($currdom);
7440: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7441: $usertypes->{'any'} = &mt('any user');
7442: if (keys(%{$usertypes}) > 0) {
7443: $usertypes->{'other'} = &mt('other users');
7444: }
7445: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
7446: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
7447: }
7448: }
7449: $output .= '</ul>';
7450: } else {
7451: $output .= &mt('None');
7452: }
7453: }
7454: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7455: next;
7456: }
1.241 raeburn 7457: my $showdomdesc = 1;
7458: my $includeempty = 1;
7459: my $num = 0;
7460: $output .= &Apache::loncommon::start_data_table().
7461: &Apache::loncommon::start_data_table_row()
7462: .'<td colspan="2"><span class="LC_nobreak"><label>'
7463: .&mt('Any user in any domain:')
7464: .' <input type="radio" name="selfenroll_all" value="1" ';
7465: if ($curr_types eq '*') {
7466: $output .= ' checked="checked" ';
7467: }
1.249 raeburn 7468: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 7469: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 7470: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 7471: if ($curr_types ne '*') {
7472: $output .= ' checked="checked" ';
7473: }
1.249 raeburn 7474: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 7475: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 7476: &Apache::loncommon::end_data_table_row().
7477: &Apache::loncommon::end_data_table().
7478: &mt('Or').'<br />'.
7479: &Apache::loncommon::start_data_table();
1.241 raeburn 7480: my %currdoms;
1.249 raeburn 7481: if ($curr_types eq '') {
1.241 raeburn 7482: $output .= &new_selfenroll_dom_row($cdom,'0');
7483: } elsif ($curr_types ne '*') {
7484: my @entries = split(/;/,$curr_types);
7485: if (@entries > 0) {
7486: foreach my $entry (@entries) {
7487: my ($currdom,$typestr) = split(/:/,$entry);
7488: $currdoms{$currdom} = 1;
7489: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 7490: my @currinsttypes = split(',',$typestr);
1.241 raeburn 7491: $output .= &Apache::loncommon::start_data_table_row()
7492: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
7493: .' '.$domdesc.' ('.$currdom.')'
7494: .'</b><input type="hidden" name="selfenroll_dom_'.$num
7495: .'" value="'.$currdom.'" /></span><br />'
7496: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 7497: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 7498: .&mt('Delete').'</label></span></td>';
1.249 raeburn 7499: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 7500: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 7501: .&Apache::loncommon::end_data_table_row();
7502: $num ++;
7503: }
7504: }
7505: }
1.249 raeburn 7506: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 7507: if ($curr_types eq '*') {
1.249 raeburn 7508: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 7509: } elsif ($curr_types eq '') {
1.249 raeburn 7510: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 7511: }
1.446 raeburn 7512: my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$cdom);
1.241 raeburn 7513: $output .= &Apache::loncommon::start_data_table_row()
7514: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
7515: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.446 raeburn 7516: $includeempty,$showdomdesc,'',$trusted,$untrusted,$readonly)
1.241 raeburn 7517: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
7518: .'</td>'.&Apache::loncommon::end_data_table_row()
7519: .&Apache::loncommon::end_data_table();
1.237 raeburn 7520: } elsif ($item eq 'registered') {
7521: my ($regon,$regoff);
1.398 raeburn 7522: my $registered;
7523: if (ref($currsettings) eq 'HASH') {
7524: $registered = $currsettings->{'selfenroll_registered'};
7525: }
1.400 raeburn 7526: if ($noedit{$item}) {
7527: if ($registered) {
7528: $output .= &mt('Must be registered in course');
7529: } else {
7530: $output .= &mt('No requirement');
7531: }
7532: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7533: next;
7534: }
1.398 raeburn 7535: if ($registered) {
1.237 raeburn 7536: $regon = ' checked="checked" ';
1.419 raeburn 7537: $regoff = '';
1.237 raeburn 7538: } else {
1.419 raeburn 7539: $regon = '';
1.237 raeburn 7540: $regoff = ' checked="checked" ';
7541: }
7542: $output .= '<label>'.
1.419 raeburn 7543: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 7544: &mt('Yes').'</label> <label>'.
1.419 raeburn 7545: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 7546: &mt('No').'</label>';
1.237 raeburn 7547: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 7548: my ($starttime,$endtime);
7549: if (ref($currsettings) eq 'HASH') {
7550: $starttime = $currsettings->{'selfenroll_start_date'};
7551: $endtime = $currsettings->{'selfenroll_end_date'};
7552: if ($starttime eq '') {
7553: $starttime = $currsettings->{'default_enrollment_start_date'};
7554: }
7555: if ($endtime eq '') {
7556: $endtime = $currsettings->{'default_enrollment_end_date'};
7557: }
1.237 raeburn 7558: }
1.400 raeburn 7559: if ($noedit{$item}) {
7560: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
7561: &Apache::lonlocal::locallocaltime($endtime));
7562: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7563: next;
7564: }
1.237 raeburn 7565: my $startform =
7566: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 7567: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7568: my $endform =
7569: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 7570: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7571: $output .= &selfenroll_date_forms($startform,$endform);
7572: } elsif ($item eq 'access_dates') {
1.398 raeburn 7573: my ($starttime,$endtime);
7574: if (ref($currsettings) eq 'HASH') {
7575: $starttime = $currsettings->{'selfenroll_start_access'};
7576: $endtime = $currsettings->{'selfenroll_end_access'};
7577: if ($starttime eq '') {
7578: $starttime = $currsettings->{'default_enrollment_start_date'};
7579: }
7580: if ($endtime eq '') {
7581: $endtime = $currsettings->{'default_enrollment_end_date'};
7582: }
1.237 raeburn 7583: }
1.400 raeburn 7584: if ($noedit{$item}) {
7585: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
7586: &Apache::lonlocal::locallocaltime($endtime));
7587: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7588: next;
7589: }
1.237 raeburn 7590: my $startform =
7591: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 7592: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7593: my $endform =
7594: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 7595: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7596: $output .= &selfenroll_date_forms($startform,$endform);
7597: } elsif ($item eq 'section') {
1.398 raeburn 7598: my $currsec;
7599: if (ref($currsettings) eq 'HASH') {
7600: $currsec = $currsettings->{'selfenroll_section'};
7601: }
1.237 raeburn 7602: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
7603: my $newsecval;
7604: if ($currsec ne 'none' && $currsec ne '') {
7605: if (!defined($sections_count{$currsec})) {
7606: $newsecval = $currsec;
7607: }
7608: }
1.400 raeburn 7609: if ($noedit{$item}) {
7610: if ($currsec ne '') {
7611: $output .= $currsec;
7612: } else {
7613: $output .= &mt('No specific section');
7614: }
7615: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7616: next;
7617: }
1.237 raeburn 7618: my $sections_select =
1.418 raeburn 7619: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 7620: $output .= '<table class="LC_createuser">'."\n".
7621: '<tr class="LC_section_row">'."\n".
7622: '<td align="center">'.&mt('Existing sections')."\n".
7623: '<br />'.$sections_select.'</td><td align="center">'.
7624: &mt('New section').'<br />'."\n".
1.418 raeburn 7625: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 7626: '<input type="hidden" name="sections" value="" />'."\n".
7627: '</td></tr></table>'."\n";
1.276 raeburn 7628: } elsif ($item eq 'approval') {
1.398 raeburn 7629: my ($currnotified,$currapproval,%appchecked);
7630: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 7631: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 7632: $currnotified = $currsettings->{'selfenroll_notifylist'};
7633: $currapproval = $currsettings->{'selfenroll_approval'};
7634: }
7635: if ($currapproval !~ /^[012]$/) {
7636: $currapproval = 0;
7637: }
1.400 raeburn 7638: if ($noedit{$item}) {
7639: $output .= $selfdescs{'approval'}{$currapproval}.
7640: '<br />'.&mt('(Set by Domain Coordinator)');
7641: next;
7642: }
1.398 raeburn 7643: $appchecked{$currapproval} = ' checked="checked"';
7644: for my $i (0..2) {
7645: $output .= '<label>'.
7646: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 7647: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
7648: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 7649: }
7650: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
7651: my (@ccs,%notified);
1.322 raeburn 7652: my $ccrole = 'cc';
7653: if ($crstype eq 'Community') {
7654: $ccrole = 'co';
7655: }
7656: if ($advhash{$ccrole}) {
7657: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 7658: }
7659: if ($currnotified) {
7660: foreach my $current (split(/,/,$currnotified)) {
7661: $notified{$current} = 1;
7662: if (!grep(/^\Q$current\E$/,@ccs)) {
7663: push(@ccs,$current);
7664: }
7665: }
7666: }
7667: if (@ccs) {
1.398 raeburn 7668: my $style;
7669: unless ($currapproval) {
7670: $style = ' style="display: none;"';
7671: }
7672: $output .= '<br /><div id="notified"'.$style.'>'.
7673: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
7674: &Apache::loncommon::start_data_table().
1.276 raeburn 7675: &Apache::loncommon::start_data_table_row();
7676: my $count = 0;
7677: my $numcols = 4;
7678: foreach my $cc (sort(@ccs)) {
7679: my $notifyon;
7680: my ($ccuname,$ccudom) = split(/:/,$cc);
7681: if ($notified{$cc}) {
7682: $notifyon = ' checked="checked" ';
7683: }
7684: if ($count && !$count%$numcols) {
7685: $output .= &Apache::loncommon::end_data_table_row().
7686: &Apache::loncommon::start_data_table_row()
7687: }
7688: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 7689: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 7690: &Apache::loncommon::plainname($ccuname,$ccudom).
7691: '</label></span></td>';
1.343 raeburn 7692: $count ++;
1.276 raeburn 7693: }
7694: my $rem = $count%$numcols;
7695: if ($rem) {
7696: my $emptycols = $numcols - $rem;
7697: for (my $i=0; $i<$emptycols; $i++) {
7698: $output .= '<td> </td>';
7699: }
7700: }
7701: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 7702: &Apache::loncommon::end_data_table().
7703: '</div>';
1.276 raeburn 7704: }
7705: } elsif ($item eq 'limit') {
1.398 raeburn 7706: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
7707: if (ref($currsettings) eq 'HASH') {
7708: $currlim = $currsettings->{'selfenroll_limit'};
7709: $currcap = $currsettings->{'selfenroll_cap'};
7710: }
1.400 raeburn 7711: if ($noedit{$item}) {
7712: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
7713: if ($currlim eq 'allstudents') {
7714: $output .= &mt('Limit by total students');
7715: } elsif ($currlim eq 'selfenrolled') {
7716: $output .= &mt('Limit by total self-enrolled students');
7717: }
7718: $output .= ' '.&mt('Maximum: [_1]',$currcap).
7719: '<br />'.&mt('(Set by Domain Coordinator)');
7720: } else {
7721: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
7722: }
7723: next;
7724: }
1.276 raeburn 7725: if ($currlim eq 'allstudents') {
7726: $crslimit = ' checked="checked" ';
7727: $selflimit = ' ';
7728: $nolimit = ' ';
7729: } elsif ($currlim eq 'selfenrolled') {
7730: $crslimit = ' ';
7731: $selflimit = ' checked="checked" ';
7732: $nolimit = ' ';
7733: } else {
7734: $crslimit = ' ';
7735: $selflimit = ' ';
1.398 raeburn 7736: $nolimit = ' checked="checked" ';
1.276 raeburn 7737: }
7738: $output .= '<table><tr><td><label>'.
1.418 raeburn 7739: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 7740: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 7741: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 7742: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 7743: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 7744: &mt('Limit by total self-enrolled students').
7745: '</td></tr><tr>'.
7746: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
7747: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 7748: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 7749: }
7750: $output .= &Apache::lonhtmlcommon::row_closure(1);
7751: }
7752: }
1.418 raeburn 7753: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
7754: unless ($readonly) {
7755: $output .= '<input type="button" name="selfenrollconf" value="'
7756: .&mt('Save').'" onclick="validate_types(this.form);" />';
7757: }
7758: $output .= '<input type="hidden" name="action" value="selfenroll" />'
7759: .'<input type="hidden" name="state" value="done" />'."\n"
7760: .$additional.'</form>';
1.237 raeburn 7761: $r->print($output);
7762: return;
7763: }
7764:
1.400 raeburn 7765: sub get_noedit_fields {
7766: my ($cdom,$cnum,$crstype,$row) = @_;
7767: my %noedit;
7768: if (ref($row) eq 'ARRAY') {
7769: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
7770: 'internal.selfenrollmgrdc',
7771: 'internal.selfenrollmgrcc'],$cdom,$cnum);
7772: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
7773: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
7774: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
7775: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
7776: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
7777: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
7778:
7779: foreach my $item (@{$row}) {
7780: next if ($specific_managebycc{$item});
7781: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
7782: $noedit{$item} = 1;
7783: }
7784: }
7785: }
7786: return %noedit;
1.470 raeburn 7787: }
1.400 raeburn 7788:
7789: sub visible_in_stdcat {
7790: my ($cdom,$cnum,$domconf) = @_;
7791: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
7792: unless (ref($domconf) eq 'HASH') {
7793: return ($visible,$cansetvis,\@vismsgs);
7794: }
7795: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7796: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 7797: $settable{'togglecats'} = 1;
7798: }
1.400 raeburn 7799: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 7800: $settable{'categorize'} = 1;
7801: }
1.400 raeburn 7802: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7803: }
1.260 raeburn 7804: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 7805: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
7806: } elsif ($settable{'togglecats'}) {
7807: $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 7808: } elsif ($settable{'categorize'}) {
1.256 raeburn 7809: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
7810: } else {
7811: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
7812: }
7813:
7814: my %currsettings =
7815: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
7816: $cdom,$cnum);
1.400 raeburn 7817: $visible = 0;
1.256 raeburn 7818: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 7819: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7820: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7821: if (ref($cathash) eq 'HASH') {
7822: if ($cathash->{'instcode::0'} eq '') {
7823: push(@vismsgs,'dc_addinst');
7824: } else {
7825: $visible = 1;
7826: }
7827: } else {
7828: $visible = 1;
7829: }
7830: } else {
7831: $visible = 1;
7832: }
7833: } else {
7834: if (ref($cathash) eq 'HASH') {
7835: if ($cathash->{'instcode::0'} ne '') {
7836: push(@vismsgs,'dc_instcode');
7837: }
7838: } else {
7839: push(@vismsgs,'dc_instcode');
7840: }
7841: }
7842: if ($currsettings{'categories'} ne '') {
7843: my $cathash;
1.400 raeburn 7844: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7845: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7846: if (ref($cathash) eq 'HASH') {
7847: if (keys(%{$cathash}) == 0) {
7848: push(@vismsgs,'dc_catalog');
7849: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
7850: push(@vismsgs,'dc_categories');
7851: } else {
7852: my @currcategories = split('&',$currsettings{'categories'});
7853: my $matched = 0;
7854: foreach my $cat (@currcategories) {
7855: if ($cathash->{$cat} ne '') {
7856: $visible = 1;
7857: $matched = 1;
7858: last;
7859: }
7860: }
7861: if (!$matched) {
1.260 raeburn 7862: if ($settable{'categorize'}) {
1.256 raeburn 7863: push(@vismsgs,'chgcat');
7864: } else {
7865: push(@vismsgs,'dc_chgcat');
7866: }
7867: }
7868: }
7869: }
7870: }
7871: } else {
7872: if (ref($cathash) eq 'HASH') {
7873: if ((keys(%{$cathash}) > 1) ||
7874: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 7875: if ($settable{'categorize'}) {
1.256 raeburn 7876: push(@vismsgs,'addcat');
7877: } else {
7878: push(@vismsgs,'dc_addcat');
7879: }
7880: }
7881: }
7882: }
7883: if ($currsettings{'hidefromcat'} eq 'yes') {
7884: $visible = 0;
7885: if ($settable{'togglecats'}) {
7886: unshift(@vismsgs,'unhide');
7887: } else {
7888: unshift(@vismsgs,'dc_unhide')
7889: }
7890: }
1.400 raeburn 7891: return ($visible,$cansetvis,\@vismsgs);
7892: }
7893:
7894: sub cat_visibility {
1.469 raeburn 7895: my ($cdom) = @_;
1.400 raeburn 7896: my %visactions = &Apache::lonlocal::texthash(
7897: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
7898: 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.',
7899: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
7900: none => 'Display of a course catalog is disabled for this domain.',
7901: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
7902: 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.',
7903: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
7904: take => 'Take the following action to ensure the course appears in the Catalog:',
7905: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
7906: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
7907: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
1.469 raeburn 7908: dc_addinst => 'Ask a domain coordinator to enable catalog display of "Official courses (with institutional codes)".',
1.400 raeburn 7909: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
7910: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
7911: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
7912: 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',
7913: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
7914: );
1.469 raeburn 7915: if ($env{'request.role'} eq "dc./$cdom/") {
7916: $visactions{'dc_chgconf'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the Catalog type for this domain.','»');
7917: $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.','»');
7918: $visactions{'dc_unhide'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the "Exclude from course catalog" setting.','»');
7919: $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)".','»');
7920: $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).','»');
7921: $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.','»');
7922: $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.','»');
7923: $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.','»');
7924: $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.','»');
7925: }
1.400 raeburn 7926: $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>"');
7927: $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>"');
7928: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
7929: return \%visactions;
1.256 raeburn 7930: }
7931:
1.241 raeburn 7932: sub new_selfenroll_dom_row {
7933: my ($newdom,$num) = @_;
7934: my $domdesc = &Apache::lonnet::domain($newdom);
7935: my $output;
7936: if ($domdesc ne '') {
7937: $output .= &Apache::loncommon::start_data_table_row()
7938: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
7939: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 7940: .'" value="'.$newdom.'" /></span><br />'
7941: .'<span class="LC_nobreak"><label><input type="checkbox" '
7942: .'name="selfenroll_activate" value="'.$num.'" '
7943: .'onchange="javascript:update_types('
7944: ."'selfenroll_activate','$num'".');" />'
7945: .&mt('Activate').'</label></span></td>';
1.241 raeburn 7946: my @currinsttypes;
7947: $output .= '<td>'.&mt('User types:').'<br />'
7948: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
7949: .&Apache::loncommon::end_data_table_row();
7950: }
7951: return $output;
7952: }
7953:
7954: sub selfenroll_inst_types {
1.418 raeburn 7955: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 7956: my $output;
7957: my $numinrow = 4;
7958: my $count = 0;
7959: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 7960: my $othervalue = 'any';
1.418 raeburn 7961: my $disabled;
7962: if ($readonly) {
7963: $disabled = ' disabled="disabled"';
7964: }
1.241 raeburn 7965: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 7966: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 7967: $othervalue = 'other';
7968: }
1.241 raeburn 7969: $output .= '<table><tr>';
7970: foreach my $type (@{$types}) {
7971: if (($count > 0) && ($count%$numinrow == 0)) {
7972: $output .= '</tr><tr>';
7973: }
7974: if (defined($usertypes->{$type})) {
1.257 raeburn 7975: my $esc_type = &escape($type);
1.241 raeburn 7976: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 7977: $esc_type.'" ';
1.241 raeburn 7978: if (ref($currinsttypes) eq 'ARRAY') {
7979: if (@{$currinsttypes} > 0) {
1.249 raeburn 7980: if (grep(/^any$/,@{$currinsttypes})) {
7981: $output .= 'checked="checked"';
1.257 raeburn 7982: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 7983: $output .= 'checked="checked"';
7984: }
1.249 raeburn 7985: } else {
7986: $output .= 'checked="checked"';
1.241 raeburn 7987: }
7988: }
1.418 raeburn 7989: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 7990: }
7991: $count ++;
7992: }
7993: if (($count > 0) && ($count%$numinrow == 0)) {
7994: $output .= '</tr><tr>';
7995: }
1.249 raeburn 7996: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 7997: if (ref($currinsttypes) eq 'ARRAY') {
7998: if (@{$currinsttypes} > 0) {
1.249 raeburn 7999: if (grep(/^any$/,@{$currinsttypes})) {
8000: $output .= ' checked="checked"';
8001: } elsif ($othervalue eq 'other') {
8002: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
8003: $output .= ' checked="checked"';
8004: }
1.241 raeburn 8005: }
1.249 raeburn 8006: } else {
8007: $output .= ' checked="checked"';
1.241 raeburn 8008: }
1.249 raeburn 8009: } else {
8010: $output .= ' checked="checked"';
1.241 raeburn 8011: }
1.418 raeburn 8012: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 8013: }
8014: return $output;
8015: }
8016:
1.237 raeburn 8017: sub selfenroll_date_forms {
8018: my ($startform,$endform) = @_;
8019: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 8020: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 8021: 'LC_oddrow_value')."\n".
8022: $startform."\n".
8023: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 8024: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 8025: 'LC_oddrow_value')."\n".
8026: $endform."\n".
8027: &Apache::lonhtmlcommon::row_closure(1).
8028: &Apache::lonhtmlcommon::end_pick_box();
8029: return $output;
8030: }
8031:
1.239 raeburn 8032: sub print_userchangelogs_display {
1.415 raeburn 8033: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 8034: my $formname = 'rolelog';
1.418 raeburn 8035: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 8036: if ($context eq 'domain') {
8037: $domain = $env{'request.role.domain'};
8038: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
8039: } else {
8040: if ($context eq 'course') {
8041: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
8042: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
8043: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 8044: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 8045: my %saveable_parameters = ('show' => 'scalar',);
8046: &Apache::loncommon::store_course_settings('roles_log',
8047: \%saveable_parameters);
8048: &Apache::loncommon::restore_course_settings('roles_log',
8049: \%saveable_parameters);
8050: } elsif ($context eq 'author') {
1.470 raeburn 8051: $domain = $env{'user.domain'};
1.363 raeburn 8052: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
8053: $username = $env{'user.name'};
1.470 raeburn 8054: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
8055: ($domain,$username) = ($1,$2);
1.363 raeburn 8056: } else {
8057: undef($domain);
8058: }
8059: }
8060: if ($domain ne '' && $username ne '') {
8061: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
8062: }
8063: }
1.239 raeburn 8064: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
8065:
1.415 raeburn 8066: my $helpitem;
8067: if ($context eq 'course') {
8068: $helpitem = 'Course_User_Logs';
1.439 raeburn 8069: } elsif ($context eq 'domain') {
8070: $helpitem = 'Domain_Role_Logs';
8071: } elsif ($context eq 'author') {
8072: $helpitem = 'Author_User_Logs';
1.415 raeburn 8073: }
8074: push (@{$brcrum},
8075: {href => '/adm/createuser?action=changelogs',
8076: text => 'User Management Logs',
8077: help => $helpitem});
8078: my $bread_crumbs_component = 'User Changes';
8079: my $args = { bread_crumbs => $brcrum,
8080: bread_crumbs_component => $bread_crumbs_component};
8081:
8082: # Create navigation javascript
8083: my $jsnav = &userlogdisplay_js($formname);
8084:
8085: my $jscript = (<<ENDSCRIPT);
8086: <script type="text/javascript">
8087: // <![CDATA[
8088: $jsnav
8089: // ]]>
8090: </script>
8091: ENDSCRIPT
8092:
8093: # print page header
8094: $r->print(&header($jscript,$args));
8095:
1.239 raeburn 8096: # set defaults
8097: my $now = time();
8098: my $defstart = $now - (7*24*3600); #7 days ago
8099: my %defaults = (
8100: page => '1',
8101: show => '10',
8102: role => 'any',
8103: chgcontext => 'any',
8104: rolelog_start_date => $defstart,
8105: rolelog_end_date => $now,
1.468 raeburn 8106: approvals => 'any',
1.239 raeburn 8107: );
8108: my $more_records = 0;
8109:
8110: # set current
8111: my %curr;
1.468 raeburn 8112: foreach my $item ('show','page','role','chgcontext','approvals') {
1.239 raeburn 8113: $curr{$item} = $env{'form.'.$item};
8114: }
8115: my ($startdate,$enddate) =
8116: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
8117: $curr{'rolelog_start_date'} = $startdate;
8118: $curr{'rolelog_end_date'} = $enddate;
8119: foreach my $key (keys(%defaults)) {
8120: if ($curr{$key} eq '') {
8121: $curr{$key} = $defaults{$key};
8122: }
8123: }
1.248 raeburn 8124: my (%whodunit,%changed,$version);
8125: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 8126: my ($minshown,$maxshown);
1.255 raeburn 8127: $minshown = 1;
1.239 raeburn 8128: my $count = 0;
1.415 raeburn 8129: if ($curr{'show'} =~ /\D/) {
8130: $curr{'page'} = 1;
8131: } else {
1.239 raeburn 8132: $maxshown = $curr{'page'} * $curr{'show'};
8133: if ($curr{'page'} > 1) {
8134: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
8135: }
8136: }
1.301 bisitz 8137:
1.327 raeburn 8138: # Form Header
8139: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 8140: &role_display_filter($context,$formname,$domain,$username,\%curr,
8141: $version,$crstype));
1.327 raeburn 8142:
8143: my $showntableheader = 0;
8144:
8145: # Table Header
8146: my $tableheader =
8147: &Apache::loncommon::start_data_table_header_row()
8148: .'<th> </th>'
8149: .'<th>'.&mt('When').'</th>'
8150: .'<th>'.&mt('Who made the change').'</th>'
8151: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 8152: .'<th>'.&mt('Role').'</th>';
8153:
8154: if ($context eq 'course') {
8155: $tableheader .= '<th>'.&mt('Section').'</th>';
8156: }
8157: $tableheader .=
8158: '<th>'.&mt('Context').'</th>'
1.327 raeburn 8159: .'<th>'.&mt('Start').'</th>'
8160: .'<th>'.&mt('End').'</th>'
8161: .&Apache::loncommon::end_data_table_header_row();
8162:
8163: # Display user change log data
1.239 raeburn 8164: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
8165: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
8166: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 8167: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 8168: if ($count >= $curr{'page'} * $curr{'show'}) {
8169: $more_records = 1;
8170: last;
8171: }
8172: }
8173: if ($curr{'role'} ne 'any') {
8174: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
8175: }
8176: if ($curr{'chgcontext'} ne 'any') {
8177: if ($curr{'chgcontext'} eq 'selfenroll') {
8178: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
8179: } else {
8180: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
8181: }
8182: }
1.418 raeburn 8183: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 8184: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 8185: }
1.468 raeburn 8186: if ($curr{'approvals'} eq 'none') {
8187: next if ($roleslog{$id}{'logentry'}{'approval'});
8188: } elsif ($curr{'approvals'} ne 'any') {
8189: next if ($roleslog{$id}{'logentry'}{'approval'} ne $curr{'approvals'});
8190: }
1.239 raeburn 8191: $count ++;
8192: next if ($count < $minshown);
1.327 raeburn 8193: unless ($showntableheader) {
1.415 raeburn 8194: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 8195: .$tableheader);
8196: $r->rflush();
8197: $showntableheader = 1;
8198: }
1.239 raeburn 8199: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
8200: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
8201: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
8202: }
8203: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
8204: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
8205: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
8206: }
8207: my $sec = $roleslog{$id}{'logentry'}{'section'};
8208: if ($sec eq '') {
8209: $sec = &mt('None');
8210: }
8211: my ($rolestart,$roleend);
8212: if ($roleslog{$id}{'delflag'}) {
8213: $rolestart = &mt('deleted');
8214: $roleend = &mt('deleted');
8215: } else {
8216: $rolestart = $roleslog{$id}{'logentry'}{'start'};
8217: $roleend = $roleslog{$id}{'logentry'}{'end'};
8218: if ($rolestart eq '' || $rolestart == 0) {
8219: $rolestart = &mt('No start date');
8220: } else {
8221: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
8222: }
8223: if ($roleend eq '' || $roleend == 0) {
8224: $roleend = &mt('No end date');
8225: } else {
8226: $roleend = &Apache::lonlocal::locallocaltime($roleend);
8227: }
8228: }
8229: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
8230: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
8231: $chgcontext = 'selfenroll';
8232: }
1.363 raeburn 8233: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 8234: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
8235: $chgcontext = $lt{$chgcontext};
8236: }
1.468 raeburn 8237: my ($showreqby,%reqby);
8238: if (($roleslog{$id}{'logentry'}{'approval'}) &&
8239: ($roleslog{$id}{'logentry'}{'requester'})) {
8240: if ($reqby{$roleslog{$id}{'logentry'}{'requester'}} eq '') {
8241: my ($requname,$requdom) = split(/:/,$roleslog{$id}{'logentry'}{'requester'});
8242: $reqby{$roleslog{$id}{'logentry'}{'requester'}} =
8243: &Apache::loncommon::plainname($requname,$requdom);
8244: }
8245: $showreqby = &mt('Requester').': <span class="LC_nobreak">'.$reqby{$roleslog{$id}{'logentry'}{'requester'}}.'</span><br />';
8246: if ($roleslog{$id}{'logentry'}{'approval'} eq 'domain') {
8247: $showreqby .= &mt('Adjudicator').': <span class="LC_nobreak">'.
8248: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.
8249: '</span>';
8250: } else {
8251: $showreqby .= '<span class="LC_nobreak">'.&mt('User approved').'</span>';
8252: }
8253: } else {
8254: $showreqby = $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}};
8255: }
1.327 raeburn 8256: $r->print(
1.301 bisitz 8257: &Apache::loncommon::start_data_table_row()
8258: .'<td>'.$count.'</td>'
8259: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
1.468 raeburn 8260: .'<td>'.$showreqby.'</td>'
1.301 bisitz 8261: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 8262: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
8263: if ($context eq 'course') {
8264: $r->print('<td>'.$sec.'</td>');
8265: }
8266: $r->print(
8267: '<td>'.$chgcontext.'</td>'
1.301 bisitz 8268: .'<td>'.$rolestart.'</td>'
8269: .'<td>'.$roleend.'</td>'
1.327 raeburn 8270: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 8271: }
8272:
1.327 raeburn 8273: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 8274: $r->print(&Apache::loncommon::end_data_table().
8275: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 8276: } else { # No content displayed above
1.301 bisitz 8277: $r->print('<p class="LC_info">'
8278: .&mt('There are no records to display.')
8279: .'</p>'
8280: );
1.239 raeburn 8281: }
1.301 bisitz 8282:
1.327 raeburn 8283: # Form Footer
8284: $r->print(
8285: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
8286: .'<input type="hidden" name="action" value="changelogs" />'
8287: .'</form>');
8288: return;
8289: }
1.301 bisitz 8290:
1.416 raeburn 8291: sub print_useraccesslogs_display {
8292: my ($r,$uname,$udom,$permission,$brcrum) = @_;
8293: my $formname = 'accesslog';
8294: my $form = 'document.accesslog';
8295:
8296: # set breadcrumbs
1.422 raeburn 8297: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 8298: my $prevphasestr;
8299: if ($env{'form.popup'}) {
8300: $brcrum = [];
8301: } else {
8302: push (@{$brcrum},
8303: {href => "javascript:backPage($form)",
8304: text => $breadcrumb_text{'search'}});
8305: my @prevphases;
8306: if ($env{'form.prevphases'}) {
8307: @prevphases = split(/,/,$env{'form.prevphases'});
8308: $prevphasestr = $env{'form.prevphases'};
8309: }
8310: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
8311: push(@{$brcrum},
8312: {href => "javascript:backPage($form,'get_user_info','select')",
8313: text => $breadcrumb_text{'userpicked'}});
8314: if ($env{'form.phase'} eq 'userpicked') {
8315: $prevphasestr = 'userpicked';
8316: }
1.416 raeburn 8317: }
8318: }
8319: push(@{$brcrum},
8320: {href => '/adm/createuser?action=accesslogs',
8321: text => 'User access logs',
1.424 raeburn 8322: help => 'Domain_User_Access_Logs'});
1.416 raeburn 8323: my $bread_crumbs_component = 'User Access Logs';
8324: my $args = { bread_crumbs => $brcrum,
8325: bread_crumbs_component => 'User Management'};
1.423 raeburn 8326: if ($env{'form.popup'}) {
8327: $args->{'no_nav_bar'} = 1;
1.431 raeburn 8328: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 8329: }
1.416 raeburn 8330:
1.417 raeburn 8331: # set javascript
1.416 raeburn 8332: my ($jsback,$elements) = &crumb_utilities();
8333: my $jsnav = &userlogdisplay_js($formname);
8334:
8335: my $jscript = (<<ENDSCRIPT);
8336: <script type="text/javascript">
8337: // <![CDATA[
8338:
8339: $jsback
8340: $jsnav
8341:
8342: // ]]>
8343: </script>
8344:
8345: ENDSCRIPT
8346:
1.417 raeburn 8347: # print page header
1.416 raeburn 8348: $r->print(&header($jscript,$args));
8349:
8350: # early out unless log data can be displayed.
8351: unless ($permission->{'activity'}) {
8352: $r->print('<p class="LC_warning">'
8353: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 8354: .'</p>');
8355: if ($env{'form.popup'}) {
8356: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
8357: } else {
8358: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8359: }
1.416 raeburn 8360: return;
8361: }
8362:
8363: unless ($udom eq $env{'request.role.domain'}) {
8364: $r->print('<p class="LC_warning">'
8365: .&mt("User's domain must match role's domain")
8366: .'</p>'
8367: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 8368: return;
1.416 raeburn 8369: }
8370:
8371: if (($uname eq '') || ($udom eq '')) {
8372: $r->print('<p class="LC_warning">'
8373: .&mt('Invalid username or domain')
8374: .'</p>'
8375: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8376: return;
8377: }
8378:
1.437 raeburn 8379: if (&Apache::lonnet::privileged($uname,$udom,
8380: [$env{'request.role.domain'}],['dc','su'])) {
8381: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
8382: [$env{'request.role.domain'}],['dc','su'])) {
8383: $r->print('<p class="LC_warning">'
8384: .&mt('You need to be a privileged user to display user access logs for [_1]',
8385: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
8386: $uname,$udom))
8387: .'</p>');
8388: if ($env{'form.popup'}) {
8389: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
8390: } else {
8391: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8392: }
8393: return;
8394: }
8395: }
8396:
1.416 raeburn 8397: # set defaults
8398: my $now = time();
8399: my $defstart = $now - (7*24*3600);
8400: my %defaults = (
8401: page => '1',
8402: show => '10',
8403: activity => 'any',
8404: accesslog_start_date => $defstart,
8405: accesslog_end_date => $now,
8406: );
8407: my $more_records = 0;
8408:
8409: # set current
8410: my %curr;
8411: foreach my $item ('show','page','activity') {
8412: $curr{$item} = $env{'form.'.$item};
8413: }
8414: my ($startdate,$enddate) =
8415: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
8416: $curr{'accesslog_start_date'} = $startdate;
8417: $curr{'accesslog_end_date'} = $enddate;
8418: foreach my $key (keys(%defaults)) {
8419: if ($curr{$key} eq '') {
8420: $curr{$key} = $defaults{$key};
8421: }
8422: }
8423: my ($minshown,$maxshown);
8424: $minshown = 1;
8425: my $count = 0;
8426: if ($curr{'show'} =~ /\D/) {
8427: $curr{'page'} = 1;
8428: } else {
8429: $maxshown = $curr{'page'} * $curr{'show'};
8430: if ($curr{'page'} > 1) {
8431: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
8432: }
8433: }
8434:
8435: # form header
8436: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
8437: &activity_display_filter($formname,\%curr));
8438:
8439: my $showntableheader = 0;
8440: my ($nav_script,$nav_links);
8441:
8442: # table header
1.453 raeburn 8443: my $heading = '<h3>'.
1.431 raeburn 8444: &mt('User access logs for: [_1]',
1.453 raeburn 8445: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
8446: my $tableheader = $heading
1.431 raeburn 8447: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 8448: .'<th> </th>'
8449: .'<th>'.&mt('When').'</th>'
8450: .'<th>'.&mt('HostID').'</th>'
8451: .'<th>'.&mt('Event').'</th>'
8452: .'<th>'.&mt('Other data').'</th>'
8453: .&Apache::loncommon::end_data_table_header_row();
8454:
8455: my %filters=(
8456: start => $curr{'accesslog_start_date'},
8457: end => $curr{'accesslog_end_date'},
8458: action => $curr{'activity'},
8459: );
8460:
8461: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
8462: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
8463: my (%courses,%missing);
8464: my @results = split(/\&/,$reply);
8465: foreach my $item (reverse(@results)) {
8466: my ($timestamp,$host,$event) = split(/:/,$item);
8467: next unless ($event =~ /^(Log|Role)/);
8468: if ($curr{'show'} !~ /\D/) {
8469: if ($count >= $curr{'page'} * $curr{'show'}) {
8470: $more_records = 1;
8471: last;
8472: }
8473: }
8474: $count ++;
8475: next if ($count < $minshown);
8476: unless ($showntableheader) {
8477: $r->print($nav_script
8478: .&Apache::loncommon::start_data_table()
8479: .$tableheader);
8480: $r->rflush();
8481: $showntableheader = 1;
8482: }
1.418 raeburn 8483: my ($shown,$extra);
1.437 raeburn 8484: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 8485: if ($event eq 'Role') {
8486: my ($rolecode,$extent) = split(/\./,$data,2);
8487: next if ($extent eq '');
8488: my ($crstype,$desc,$info);
1.418 raeburn 8489: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
8490: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 8491: my $cid = $cdom.'_'.$cnum;
8492: if (exists($courses{$cid})) {
8493: $crstype = $courses{$cid}{'type'};
8494: $desc = $courses{$cid}{'description'};
8495: } elsif ($missing{$cid}) {
8496: $crstype = 'Course';
8497: $desc = 'Course/Community';
8498: } else {
8499: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
8500: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
8501: $courses{$cid} = $crsinfo{$cid};
8502: $crstype = $crsinfo{$cid}{'type'};
8503: $desc = $crsinfo{$cid}{'description'};
8504: } else {
8505: $missing{$cid} = 1;
8506: }
8507: }
8508: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 8509: if ($sec ne '') {
8510: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
8511: }
1.416 raeburn 8512: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
8513: my ($dom,$name) = ($1,$2);
8514: if ($rolecode eq 'au') {
8515: $extra = '';
8516: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 8517: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 8518: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
8519: $extra = &mt('Domain: [_1]',$dom);
8520: }
8521: }
8522: my $rolename;
8523: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
8524: my $role = $3;
1.417 raeburn 8525: my $owner = "($2:$1)";
1.416 raeburn 8526: if ($2 eq $1.'-domainconfig') {
8527: $owner = '(ad hoc)';
1.417 raeburn 8528: }
1.416 raeburn 8529: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
8530: } else {
8531: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
8532: }
8533: $shown = &mt('Role selection: [_1]',$rolename);
8534: } else {
8535: $shown = &mt($event);
1.437 raeburn 8536: if ($data =~ /^webdav/) {
8537: my ($path,$clientip) = split(/\s+/,$data,2);
8538: $path =~ s/^webdav//;
8539: if ($clientip ne '') {
8540: $extra = &mt('Client IP address: [_1]',$clientip);
8541: }
8542: if ($path ne '') {
8543: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
8544: }
8545: } elsif ($data ne '') {
8546: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 8547: }
8548: }
8549: $r->print(
8550: &Apache::loncommon::start_data_table_row()
8551: .'<td>'.$count.'</td>'
8552: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
8553: .'<td>'.$host.'</td>'
8554: .'<td>'.$shown.'</td>'
8555: .'<td>'.$extra.'</td>'
8556: .&Apache::loncommon::end_data_table_row()."\n");
8557: }
8558: }
8559:
8560: if ($showntableheader) { # Table footer, if content displayed above
8561: $r->print(&Apache::loncommon::end_data_table().
8562: &userlogdisplay_navlinks(\%curr,$more_records));
8563: } else { # No content displayed above
1.453 raeburn 8564: $r->print($heading.'<p class="LC_info">'
1.416 raeburn 8565: .&mt('There are no records to display.')
8566: .'</p>');
8567: }
8568:
1.423 raeburn 8569: if ($env{'form.popup'} == 1) {
8570: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
8571: }
8572:
1.416 raeburn 8573: # Form Footer
8574: $r->print(
8575: '<input type="hidden" name="currstate" value="" />'
8576: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
8577: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
8578: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
8579: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
8580: .'<input type="hidden" name="phase" value="activity" />'
8581: .'<input type="hidden" name="action" value="accesslogs" />'
8582: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
8583: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
8584: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
8585: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
8586: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
8587: .'</form>');
8588: return;
8589: }
8590:
8591: sub earlyout_accesslog_form {
8592: my ($formname,$prevphasestr,$udom) = @_;
8593: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
8594: return <<"END";
8595: <form action="/adm/createuser" method="post" name="$formname">
8596: <input type="hidden" name="currstate" value="" />
8597: <input type="hidden" name="prevphases" value="$prevphasestr" />
8598: <input type="hidden" name="phase" value="activity" />
8599: <input type="hidden" name="action" value="accesslogs" />
8600: <input type="hidden" name="srchdomain" value="$udom" />
8601: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
8602: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
8603: <input type="hidden" name="srchterm" value="$srchterm" />
8604: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
8605: </form>
8606: END
8607: }
8608:
8609: sub activity_display_filter {
8610: my ($formname,$curr) = @_;
8611: my $nolink = 1;
8612: my $output = '<table><tr><td valign="top">'.
8613: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
1.467 raeburn 8614: &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef,
1.416 raeburn 8615: (&mt('all'),5,10,20,50,100,1000,10000)).
8616: '</td><td> </td>';
8617: my $startform =
8618: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
8619: $curr->{'accesslog_start_date'},undef,
8620: undef,undef,undef,undef,undef,undef,$nolink);
8621: my $endform =
8622: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
8623: $curr->{'accesslog_end_date'},undef,
8624: undef,undef,undef,undef,undef,undef,$nolink);
8625: my %lt = &Apache::lonlocal::texthash (
8626: activity => 'Activity',
8627: Role => 'Role selection',
8628: log => 'Log-in or Logout',
8629: );
8630: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
8631: '<table><tr><td>'.&mt('After:').
8632: '</td><td>'.$startform.'</td></tr>'.
8633: '<tr><td>'.&mt('Before:').'</td>'.
8634: '<td>'.$endform.'</td></tr></table>'.
8635: '</td>'.
8636: '<td> </td>'.
8637: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
8638: '<select name="activity"><option value="any"';
8639: if ($curr->{'activity'} eq 'any') {
8640: $output .= ' selected="selected"';
8641: }
8642: $output .= '>'.&mt('Any').'</option>'."\n";
8643: foreach my $activity ('Role','log') {
8644: my $selstr = '';
8645: if ($activity eq $curr->{'activity'}) {
8646: $selstr = ' selected="selected"';
8647: }
8648: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
8649: }
8650: $output .= '</select></td>'.
8651: '</tr></table>';
8652: # Update Display button
8653: $output .= '<p>'
8654: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 8655: .'</p><hr />';
1.416 raeburn 8656: return $output;
8657: }
8658:
1.415 raeburn 8659: sub userlogdisplay_js {
8660: my ($formname) = @_;
8661: return <<"ENDSCRIPT";
8662:
1.239 raeburn 8663: function chgPage(caller) {
8664: if (caller == 'previous') {
8665: document.$formname.page.value --;
8666: }
8667: if (caller == 'next') {
8668: document.$formname.page.value ++;
8669: }
1.327 raeburn 8670: document.$formname.submit();
1.239 raeburn 8671: return;
8672: }
8673: ENDSCRIPT
1.415 raeburn 8674: }
8675:
8676: sub userlogdisplay_navlinks {
8677: my ($curr,$more_records) = @_;
8678: return unless(ref($curr) eq 'HASH');
8679: # Navigation Buttons
8680: my $nav_links = '<p>';
8681: if (($curr->{'page'} > 1) || ($more_records)) {
8682: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
8683: $nav_links .= '<input type="button"'
8684: .' onclick="javascript:chgPage('."'previous'".');"'
8685: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
8686: .'" /> ';
8687: }
8688: if ($more_records) {
8689: $nav_links .= '<input type="button"'
8690: .' onclick="javascript:chgPage('."'next'".');"'
8691: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
8692: .'" />';
1.301 bisitz 8693: }
8694: }
1.415 raeburn 8695: $nav_links .= '</p>';
8696: return $nav_links;
1.239 raeburn 8697: }
8698:
8699: sub role_display_filter {
1.363 raeburn 8700: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
1.239 raeburn 8701: my $nolink = 1;
8702: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 8703: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.467 raeburn 8704: &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef,
1.239 raeburn 8705: (&mt('all'),5,10,20,50,100,1000,10000)).
8706: '</td><td> </td>';
8707: my $startform =
8708: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
8709: $curr->{'rolelog_start_date'},undef,
8710: undef,undef,undef,undef,undef,undef,$nolink);
8711: my $endform =
8712: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
8713: $curr->{'rolelog_end_date'},undef,
8714: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 8715: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 8716: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
8717: '<table><tr><td>'.&mt('After:').
8718: '</td><td>'.$startform.'</td></tr>'.
8719: '<tr><td>'.&mt('Before:').'</td>'.
8720: '<td>'.$endform.'</td></tr></table>'.
8721: '</td>'.
8722: '<td> </td>'.
1.239 raeburn 8723: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
8724: '<select name="role"><option value="any"';
8725: if ($curr->{'role'} eq 'any') {
8726: $output .= ' selected="selected"';
8727: }
1.466 raeburn 8728: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 8729: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 8730: foreach my $role (@roles) {
8731: my $plrole;
8732: if ($role eq 'cr') {
8733: $plrole = &mt('Custom Role');
8734: } else {
1.318 raeburn 8735: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 8736: }
8737: my $selstr = '';
8738: if ($role eq $curr->{'role'}) {
8739: $selstr = ' selected="selected"';
8740: }
8741: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
8742: }
1.301 bisitz 8743: $output .= '</select></td>'.
8744: '<td> </td>'.
8745: '<td valign="top"><b>'.
1.239 raeburn 8746: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 8747: my @posscontexts;
8748: if ($context eq 'course') {
1.468 raeburn 8749: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype','ltienroll');
1.363 raeburn 8750: } elsif ($context eq 'domain') {
8751: @posscontexts = ('any','domain','requestauthor','domconfig','server');
8752: } else {
1.470 raeburn 8753: @posscontexts = ('any','author','coauthor','domain');
1.457 raeburn 8754: }
1.363 raeburn 8755: foreach my $chgtype (@posscontexts) {
1.239 raeburn 8756: my $selstr = '';
8757: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 8758: $selstr = ' selected="selected"';
1.239 raeburn 8759: }
1.363 raeburn 8760: if ($context eq 'course') {
1.376 raeburn 8761: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 8762: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
8763: }
1.239 raeburn 8764: }
8765: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 8766: }
1.468 raeburn 8767: my @possapprovals = ('any','none','domain','user');
8768: my %apptxt = &approval_types();
8769: $output .= '</select></td>'.
8770: '<td> </td>'.
8771: '<td valign="top"><b>'.
8772: &mt('Approvals:').'</b><br /><select name="approvals">';
8773: foreach my $approval (@possapprovals) {
8774: my $selstr = '';
8775: if ($curr->{'approvals'} eq $approval) {
8776: $selstr = ' selected="selected"';
8777: }
8778: $output .= '<option value="'.$approval.'"'.$selstr.'>'.$apptxt{$approval}.'</option>';
8779: }
8780: $output .= '</select></td></tr></table>';
1.303 bisitz 8781:
8782: # Update Display button
8783: $output .= '<p>'
8784: .'<input type="submit" value="'.&mt('Update Display').'" />'
8785: .'</p>';
8786:
8787: # Server version info
1.363 raeburn 8788: my $needsrev = '2.11.0';
8789: if ($context eq 'course') {
8790: $needsrev = '2.7.0';
8791: }
8792:
1.303 bisitz 8793: $output .= '<p class="LC_info">'
8794: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 8795: ,$needsrev);
1.248 raeburn 8796: if ($version) {
1.303 bisitz 8797: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
8798: }
8799: $output .= '</p><hr />';
1.239 raeburn 8800: return $output;
8801: }
8802:
8803: sub rolechg_contexts {
1.363 raeburn 8804: my ($context,$crstype) = @_;
8805: my %lt;
8806: if ($context eq 'course') {
8807: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 8808: any => 'Any',
1.376 raeburn 8809: automated => 'Automated Enrollment',
1.457 raeburn 8810: chgtype => 'Enrollment Type/Lock Change',
1.239 raeburn 8811: updatenow => 'Roster Update',
8812: createcourse => 'Course Creation',
8813: course => 'User Management in course',
8814: domain => 'User Management in domain',
1.313 raeburn 8815: selfenroll => 'Self-enrolled',
1.318 raeburn 8816: requestcourses => 'Course Request',
1.468 raeburn 8817: ltienroll => 'Enrollment via LTI',
1.239 raeburn 8818: );
1.363 raeburn 8819: if ($crstype eq 'Community') {
8820: $lt{'createcourse'} = &mt('Community Creation');
8821: $lt{'course'} = &mt('User Management in community');
8822: $lt{'requestcourses'} = &mt('Community Request');
8823: }
8824: } elsif ($context eq 'domain') {
8825: %lt = &Apache::lonlocal::texthash (
8826: any => 'Any',
8827: domain => 'User Management in domain',
8828: requestauthor => 'Authoring Request',
8829: server => 'Command line script (DC role)',
8830: domconfig => 'Self-enrolled',
8831: );
8832: } else {
8833: %lt = &Apache::lonlocal::texthash (
8834: any => 'Any',
8835: domain => 'User Management in domain',
8836: author => 'User Management by author',
1.470 raeburn 8837: coauthor => 'User Management by coauthor',
1.363 raeburn 8838: );
8839: }
1.239 raeburn 8840: return %lt;
8841: }
8842:
1.468 raeburn 8843: sub approval_types {
8844: return &Apache::lonlocal::texthash (
8845: any => 'Any',
8846: none => 'No approval needed',
8847: user => 'Role recipient approval',
8848: domain => 'Domain coordinator approval',
8849: );
8850: }
8851:
1.428 raeburn 8852: sub print_helpdeskaccess_display {
8853: my ($r,$permission,$brcrum) = @_;
8854: my $formname = 'helpdeskaccess';
8855: my $helpitem = 'Course_Helpdesk_Access';
8856: push (@{$brcrum},
8857: {href => '/adm/createuser?action=helpdesk',
8858: text => 'Helpdesk Access',
8859: help => $helpitem});
8860: my $bread_crumbs_component = 'Helpdesk Staff Access';
8861: my $args = { bread_crumbs => $brcrum,
8862: bread_crumbs_component => $bread_crumbs_component};
8863:
8864: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8865: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8866: my $confname = $cdom.'-domainconfig';
8867: my $crstype = &Apache::loncommon::course_type();
8868:
1.434 raeburn 8869: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 8870: my ($numstatustypes,@jsarray);
8871: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8872: if (ref($types) eq 'ARRAY') {
1.430 raeburn 8873: if (@{$types} > 0) {
1.428 raeburn 8874: $numstatustypes = scalar(@{$types});
8875: push(@accesstypes,'status');
8876: @jsarray = ('bystatus');
8877: }
8878: }
8879: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 8880: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8881: if (keys(%domhelpdesk)) {
8882: push(@accesstypes,('inc','exc'));
8883: push(@jsarray,('notinc','notexc'));
8884: }
8885: push(@jsarray,'privs');
8886: my $hiddenstr = join("','",@jsarray);
8887: my $rolestr = join("','",sort(keys(%customroles)));
8888:
8889: my $jscript;
8890: my (%settings,%overridden);
8891: if (keys(%customroles)) {
8892: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8893: $types,\%customroles,\%settings,\%overridden);
8894: my %jsfull=();
8895: my %jslevels= (
8896: course => {},
8897: domain => {},
8898: system => {},
8899: );
8900: my %jslevelscurrent=(
8901: course => {},
8902: domain => {},
8903: system => {},
8904: );
8905: my (%privs,%jsprivs);
8906: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
8907: foreach my $priv (keys(%jsfull)) {
8908: if ($jslevels{'course'}{$priv}) {
8909: $jsprivs{$priv} = 1;
8910: }
8911: }
8912: my (%elements,%stored);
8913: foreach my $role (keys(%customroles)) {
8914: $elements{$role.'_access'} = 'radio';
8915: $elements{$role.'_incrs'} = 'radio';
8916: if ($numstatustypes) {
8917: $elements{$role.'_status'} = 'checkbox';
8918: }
8919: if (keys(%domhelpdesk) > 0) {
8920: $elements{$role.'_staff_inc'} = 'checkbox';
8921: $elements{$role.'_staff_exc'} = 'checkbox';
8922: }
1.430 raeburn 8923: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 8924: if (ref($settings{$role}) eq 'HASH') {
8925: if ($settings{$role}{'access'} ne '') {
8926: my $curraccess = $settings{$role}{'access'};
8927: $stored{$role.'_access'} = $curraccess;
8928: $stored{$role.'_incrs'} = 1;
8929: if ($curraccess eq 'status') {
8930: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
8931: $stored{$role.'_status'} = $settings{$role}{'status'};
8932: }
8933: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8934: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
8935: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
8936: }
8937: }
8938: } else {
8939: $stored{$role.'_incrs'} = 0;
8940: }
8941: $stored{$role.'_override'} = [];
8942: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
8943: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
8944: foreach my $priv (@{$settings{$role}{'off'}}) {
8945: push(@{$stored{$role.'_override'}},$priv);
8946: }
8947: }
8948: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
8949: foreach my $priv (@{$settings{$role}{'on'}}) {
8950: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
8951: push(@{$stored{$role.'_override'}},$priv);
8952: }
8953: }
8954: }
8955: }
8956: } else {
8957: $stored{$role.'_incrs'} = 0;
8958: }
8959: }
8960: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
8961: }
8962:
8963: my $js = <<"ENDJS";
8964: <script type="text/javascript">
8965: // <![CDATA[
8966: $jscript;
8967:
8968: function switchRoleTab(caller,role) {
8969: if (document.getElementById(role+'_maindiv')) {
8970: if (caller.id != 'LC_current_minitab') {
8971: if (document.getElementById('LC_current_minitab')) {
8972: document.getElementById('LC_current_minitab').id=null;
8973: }
8974: var roledivs = Array('$rolestr');
8975: if (roledivs.length > 0) {
8976: for (var i=0; i<roledivs.length; i++) {
8977: if (document.getElementById(roledivs[i]+'_maindiv')) {
8978: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
8979: }
8980: }
8981: }
8982: caller.id = 'LC_current_minitab';
8983: document.getElementById(role+'_maindiv').style.display='block';
8984: }
8985: }
8986: return false;
1.430 raeburn 8987: }
1.428 raeburn 8988:
8989: function helpdeskAccess(role) {
8990: var curraccess = null;
8991: if (document.$formname.elements[role+'_access'].length) {
8992: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
8993: if (document.$formname.elements[role+'_access'][i].checked) {
8994: curraccess = document.$formname.elements[role+'_access'][i].value;
8995: }
8996: }
8997: }
8998: var shown = Array();
8999: var hidden = Array();
9000: if (curraccess == 'none') {
1.430 raeburn 9001: hidden = Array ('$hiddenstr');
1.428 raeburn 9002: } else {
9003: if (curraccess == 'status') {
1.430 raeburn 9004: shown = Array ('bystatus','privs');
9005: hidden = Array ('notinc','notexc');
1.428 raeburn 9006: } else {
9007: if (curraccess == 'exc') {
9008: shown = Array ('notexc','privs');
9009: hidden = Array ('notinc','bystatus');
9010: }
9011: if (curraccess == 'inc') {
9012: shown = Array ('notinc','privs');
9013: hidden = Array ('notexc','bystatus');
9014: }
9015: if (curraccess == 'all') {
9016: shown = Array ('privs');
9017: hidden = Array ('notinc','notexc','bystatus');
9018: }
9019: }
9020: }
9021: if (hidden.length > 0) {
9022: for (var i=0; i<hidden.length; i++) {
9023: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 9024: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 9025: }
9026: }
9027: }
9028: if (shown.length > 0) {
9029: for (var i=0; i<shown.length; i++) {
9030: if (document.getElementById(role+'_'+shown[i])) {
9031: if (shown[i] == 'privs') {
9032: document.getElementById(role+'_'+shown[i]).style.display = 'block';
9033: } else {
9034: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
9035: }
9036: }
9037: }
9038: }
9039: return;
9040: }
9041:
9042: function toggleAccess(role) {
9043: if ((document.getElementById(role+'_setincrs')) &&
9044: (document.getElementById(role+'_setindom'))) {
9045: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
9046: if (document.$formname.elements[role+'_incrs'][i].checked) {
9047: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
9048: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 9049: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 9050: } else {
9051: document.getElementById(role+'_setincrs').style.display = 'none';
9052: document.getElementById(role+'_setindom').style.display = 'block';
9053: }
9054: break;
9055: }
9056: }
9057: }
9058: return;
9059: }
9060:
9061: // ]]>
9062: </script>
9063: ENDJS
9064:
9065: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
9066:
9067: # print page header
9068: $r->print(&header($js,$args));
9069: # print form header
9070: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
9071:
9072: if (keys(%customroles)) {
9073: my %lt = &Apache::lonlocal::texthash(
9074: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
9075: 'rou' => 'Role usage',
9076: 'whi' => 'Which helpdesk personnel may use this role?',
9077: 'udd' => 'Use domain default',
1.433 raeburn 9078: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 9079: 'dh' => 'All with domain helpdesk role',
9080: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 9081: 'none' => 'None',
9082: 'status' => 'Determined based on institutional status',
1.430 raeburn 9083: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 9084: 'exc' => 'Exclude all, but include specific personnel',
9085: 'hel' => 'Helpdesk',
9086: 'rpr' => 'Role privileges',
9087: );
9088: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
9089: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
9090: my (%domcurrent,%ordered,%description,%domusage,$disabled);
9091: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9092: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
9093: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
9094: }
9095: }
9096: my $count = 0;
9097: foreach my $role (sort(keys(%customroles))) {
9098: my ($order,$desc,$access_in_dom);
9099: if (ref($domcurrent{$role}) eq 'HASH') {
9100: $order = $domcurrent{$role}{'order'};
9101: $desc = $domcurrent{$role}{'desc'};
9102: $access_in_dom = $domcurrent{$role}{'access'};
9103: }
9104: if ($order eq '') {
9105: $order = $count;
9106: }
9107: $ordered{$order} = $role;
9108: if ($desc ne '') {
9109: $description{$role} = $desc;
9110: } else {
9111: $description{$role}= $role;
9112: }
9113: $count++;
9114: }
9115: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
9116: my @roles_by_num = ();
9117: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
9118: push(@roles_by_num,$ordered{$item});
1.430 raeburn 9119: }
1.429 raeburn 9120: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 9121: if ($permission->{'owner'}) {
9122: $r->print('<br />'.$lt{'aco'}.'</p><p>');
9123: $r->print('<input type="hidden" name="state" value="process" />'.
9124: '<input type="submit" value="'.&mt('Save changes').'" />');
9125: } else {
9126: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
9127: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
9128: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
9129: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
9130: }
9131: $disabled = ' disabled="disabled"';
9132: }
9133: $r->print('</p>');
9134:
9135: $r->print('<div id="LC_minitab_header"><ul>');
9136: my $count = 0;
9137: my %visibility;
9138: foreach my $role (@roles_by_num) {
9139: my $id;
9140: if ($count == 0) {
9141: $id=' id="LC_current_minitab"';
1.430 raeburn 9142: $visibility{$role} = ' style="display:block"';
1.428 raeburn 9143: } else {
9144: $visibility{$role} = ' style="display:none"';
9145: }
9146: $count ++;
9147: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
9148: }
9149: $r->print('</ul></div>');
9150:
9151: foreach my $role (@roles_by_num) {
9152: my %usecheck = (
9153: all => ' checked="checked"',
9154: );
9155: my %displaydiv = (
9156: status => 'none',
9157: inc => 'none',
9158: exc => 'none',
9159: priv => 'block',
9160: );
9161: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 9162: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 9163: if ($settings{$role}{'access'} ne '') {
9164: $indomvis = ' style="display:none"';
9165: $incrsvis = ' style="display:block"';
1.430 raeburn 9166: $incrscheck = ' checked="checked"';
1.428 raeburn 9167: if ($settings{$role}{'access'} ne 'all') {
9168: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
9169: delete($usecheck{'all'});
9170: if ($settings{$role}{'access'} eq 'status') {
9171: my $access = 'status';
9172: $displaydiv{$access} = 'inline';
9173: if (ref($settings{$role}{$access}) eq 'ARRAY') {
9174: $selected{$access} = $settings{$role}{$access};
9175: }
9176: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
9177: my $access = $1;
9178: $displaydiv{$access} = 'inline';
9179: if (ref($settings{$role}{$access}) eq 'ARRAY') {
9180: $selected{$access} = $settings{$role}{$access};
9181: }
9182: } elsif ($settings{$role}{'access'} eq 'none') {
9183: $displaydiv{'priv'} = 'none';
9184: }
9185: }
9186: } else {
9187: $indomcheck = ' checked="checked"';
9188: $indomvis = ' style="display:block"';
9189: $incrsvis = ' style="display:none"';
9190: }
9191: } else {
9192: $indomcheck = ' checked="checked"';
1.430 raeburn 9193: $indomvis = ' style="display:block"';
1.428 raeburn 9194: $incrsvis = ' style="display:none"';
9195: }
9196: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
9197: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
9198: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
9199: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
9200: &mt('Set here in [_1]',lc($crstype)).'</label>'.
9201: '<span>'.(' 'x2).
9202: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
9203: $lt{'udd'}.'</label><span></p>'.
9204: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
9205: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
9206: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
9207: foreach my $access (@accesstypes) {
9208: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
9209: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
9210: if ($access eq 'status') {
9211: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
9212: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
9213: $othertitle,$usertypes,$types,$disabled).
9214: '</div>');
9215: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
9216: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
9217: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
9218: \%domhelpdesk,$disabled).
9219: '</div>');
9220: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
9221: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
9222: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
9223: \%domhelpdesk,$disabled).
9224: '</div>');
9225: }
9226: $r->print('</p>');
9227: }
9228: $r->print('</div></fieldset>');
9229: my %full=();
9230: my %levels= (
9231: course => {},
9232: domain => {},
9233: system => {},
9234: );
9235: my %levelscurrent=(
9236: course => {},
9237: domain => {},
9238: system => {},
9239: );
9240: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
9241: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
9242: '<legend>'.$lt{'rpr'}.'</legend>'.
9243: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
9244: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
9245: }
1.429 raeburn 9246: if ($permission->{'owner'}) {
9247: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
9248: }
1.428 raeburn 9249: } else {
9250: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
9251: }
9252: # Form Footer
9253: $r->print('<input type="hidden" name="action" value="helpdesk" />'
9254: .'</form>');
9255: return;
9256: }
9257:
1.465 raeburn 9258: sub print_queued_roles {
9259: my ($r,$context,$permission,$brcrum) = @_;
9260: push (@{$brcrum},
9261: {href => '/adm/createuser?action=rolerequests',
9262: text => 'Role Requests (other domains)',
9263: help => ''});
9264: my $bread_crumbs_component = 'Role Requests';
9265: my $args = { bread_crumbs => $brcrum,
9266: bread_crumbs_component => $bread_crumbs_component};
9267: # print page header
9268: $r->print(&header('',$args));
9269: my ($dom,$cnum);
9270: $dom = $env{'request.role.domain'};
9271: if ($context eq 'course') {
9272: if ($env{'request.course.id'}) {
9273: if (&Apache::loncommon::course_type() eq 'Community') {
9274: $context = 'community';
9275: }
9276: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9277: }
9278: } elsif ($context eq 'author') {
9279: $cnum = $env{'user.name'};
9280: }
9281: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('othdomqueue',$dom,$cnum,$context));
9282: return;
9283: }
9284:
9285: sub print_pendingroles {
9286: my ($r,$context,$permission,$brcrum) = @_;
9287: push (@{$brcrum},
9288: {href => '/adm/createuser?action=queuedroles',
9289: text => 'Queued Role Assignments (users in this domain)',
9290: help => ''});
9291: my $bread_crumbs_component = 'Queued Role Assignments';
9292: my $args = { bread_crumbs => $brcrum,
9293: bread_crumbs_component => $bread_crumbs_component};
9294: # print page header
9295: $r->print(&header('',$args));
9296: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('othdomaction',$env{'request.role.domain'},'','domain'));
9297: return;
9298: }
9299:
9300: sub process_pendingroles {
9301: my ($r,$context,$permission,$brcrum) = @_;
9302: push (@{$brcrum},
9303: {href => '/adm/createuser?action=queuedroles',
9304: text => 'Queued Role Assignments (users in this domain)',
9305: help => ''},
9306: {href => '/adm/createuser?action=processrolereq',
9307: text => 'Process Queue',
9308: help => ''});
9309: my $bread_crumbs_component = 'Queued Role Assignments';
9310: my $args = { bread_crumbs => $brcrum,
9311: bread_crumbs_component => $bread_crumbs_component};
9312: # print page header
9313: $r->print(&header('',$args));
9314: $r->print(&Apache::loncoursequeueadmin::update_request_queue('othdombydc',
9315: $env{'request.role.domain'}));
9316: return;
9317: }
9318:
1.428 raeburn 9319: sub domain_adhoc_access {
9320: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
9321: my %domusage;
9322: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
9323: foreach my $role (keys(%{$roles})) {
9324: if (ref($domcurrent->{$role}) eq 'HASH') {
9325: my $access = $domcurrent->{$role}{'access'};
9326: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
9327: $access = 'all';
1.432 raeburn 9328: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
9329: &Apache::lonnet::plaintext('da'));
1.428 raeburn 9330: } elsif ($access eq 'status') {
9331: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
9332: my @shown;
9333: foreach my $type (@{$domcurrent->{$role}{$access}}) {
9334: unless ($type eq 'default') {
9335: if ($usertypes->{$type}) {
9336: push(@shown,$usertypes->{$type});
9337: }
9338: }
9339: }
9340: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
9341: push(@shown,$othertitle);
9342: }
9343: if (@shown) {
9344: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 9345: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
9346: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 9347: } else {
9348: $domusage{$role} = &mt('No one in the domain');
9349: }
9350: }
9351: } elsif ($access eq 'inc') {
9352: my @dominc = ();
9353: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
9354: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
9355: my ($uname,$udom) = split(/:/,$user);
9356: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
9357: }
9358: my $showninc = join(', ',@dominc);
9359: if ($showninc ne '') {
1.432 raeburn 9360: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
9361: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 9362: } else {
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: }
9367: } elsif ($access eq 'exc') {
9368: my @domexc = ();
9369: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
9370: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
9371: my ($uname,$udom) = split(/:/,$user);
9372: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
9373: }
9374: }
9375: my $shownexc = join(', ',@domexc);
9376: if ($shownexc ne '') {
1.432 raeburn 9377: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
9378: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 9379: } else {
9380: $domusage{$role} = &mt('No one in the domain');
9381: }
9382: } elsif ($access eq 'none') {
9383: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 9384: } elsif ($access eq 'dh') {
1.433 raeburn 9385: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 9386: } elsif ($access eq 'da') {
1.433 raeburn 9387: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 9388: } elsif ($access eq 'all') {
1.432 raeburn 9389: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
9390: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 9391: }
9392: } else {
1.432 raeburn 9393: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
9394: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 9395: }
9396: }
9397: return %domusage;
9398: }
9399:
9400: sub get_domain_customroles {
9401: my ($cdom,$confname) = @_;
9402: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
9403: my %customroles;
9404: foreach my $key (keys(%existing)) {
9405: if ($key=~/^rolesdef\_(\w+)$/) {
9406: my $rolename = $1;
9407: my %privs;
9408: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
9409: $customroles{$rolename} = \%privs;
9410: }
9411: }
9412: return %customroles;
9413: }
9414:
9415: sub role_priv_table {
9416: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
9417: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
9418: (ref($levelscurrent) eq 'HASH'));
9419: my %lt=&Apache::lonlocal::texthash (
9420: 'crl' => 'Course Level Privilege',
9421: 'def' => 'Domain Defaults',
9422: 'ove' => 'Override in Course',
9423: 'ine' => 'In effect',
9424: 'dis' => 'Disabled',
9425: 'ena' => 'Enabled',
9426: );
9427: if ($crstype eq 'Community') {
9428: $lt{'ove'} = 'Override in Community',
9429: }
9430: my @status = ('Disabled','Enabled');
9431: my (%on,%off);
9432: if (ref($overridden) eq 'HASH') {
9433: if (ref($overridden->{'on'}) eq 'ARRAY') {
9434: map { $on{$_} = 1; } (@{$overridden->{'on'}});
9435: }
9436: if (ref($overridden->{'off'}) eq 'ARRAY') {
9437: map { $off{$_} = 1; } (@{$overridden->{'off'}});
9438: }
9439: }
9440: my $output=&Apache::loncommon::start_data_table().
9441: &Apache::loncommon::start_data_table_header_row().
9442: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
9443: '</th><th>'.$lt{'ine'}.'</th>'.
9444: &Apache::loncommon::end_data_table_header_row();
9445: foreach my $priv (sort(keys(%{$full}))) {
9446: next unless ($levels->{'course'}{$priv});
9447: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
9448: my ($default,$ineffect);
9449: if ($levelscurrent->{'course'}{$priv}) {
9450: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
9451: $ineffect = $default;
9452: }
9453: my ($customstatus,$checked);
9454: $output .= &Apache::loncommon::start_data_table_row().
9455: '<td>'.$privtext.'</td>'.
9456: '<td>'.$default.'</td><td>';
9457: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
9458: if ($permission->{'owner'}) {
9459: $checked = ' checked="checked"';
9460: }
9461: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 9462: $ineffect = $customstatus;
1.428 raeburn 9463: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
9464: if ($permission->{'owner'}) {
1.430 raeburn 9465: $checked = ' checked="checked"';
1.428 raeburn 9466: }
9467: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 9468: $ineffect = $customstatus;
1.428 raeburn 9469: }
9470: if ($permission->{'owner'}) {
9471: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
9472: } else {
9473: $output .= $customstatus;
9474: }
9475: $output .= '</td><td>'.$ineffect.'</td>'.
9476: &Apache::loncommon::end_data_table_row();
9477: }
9478: $output .= &Apache::loncommon::end_data_table();
9479: return $output;
9480: }
9481:
9482: sub get_adhocrole_settings {
1.430 raeburn 9483: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 9484: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
9485: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
9486: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
9487: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
9488: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
9489: $settings->{$role}{'access'} = $curraccess;
9490: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
9491: my @status = split(/,/,$rest);
9492: my @currstatus;
9493: foreach my $type (@status) {
9494: if ($type eq 'default') {
9495: push(@currstatus,$type);
9496: } elsif (grep(/^\Q$type\E$/,@{$types})) {
9497: push(@currstatus,$type);
9498: }
9499: }
9500: if (@currstatus) {
9501: $settings->{$role}{$curraccess} = \@currstatus;
9502: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
9503: my @personnel = split(/,/,$rest);
9504: $settings->{$role}{$curraccess} = \@personnel;
9505: }
9506: }
9507: }
9508: }
9509: foreach my $role (keys(%{$customroles})) {
9510: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
9511: my %currentprivs;
9512: if (ref($customroles->{$role}) eq 'HASH') {
9513: if (exists($customroles->{$role}{'course'})) {
9514: my %full=();
9515: my %levels= (
9516: course => {},
9517: domain => {},
9518: system => {},
9519: );
9520: my %levelscurrent=(
9521: course => {},
9522: domain => {},
9523: system => {},
9524: );
9525: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
9526: %currentprivs = %{$levelscurrent{'course'}};
9527: }
9528: }
9529: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
9530: next if ($item eq '');
9531: my ($rule,$rest) = split(/=/,$item);
9532: next unless (($rule eq 'off') || ($rule eq 'on'));
9533: foreach my $priv (split(/:/,$rest)) {
9534: if ($priv ne '') {
9535: if ($rule eq 'off') {
9536: push(@{$overridden->{$role}{'off'}},$priv);
9537: if ($currentprivs{$priv}) {
9538: push(@{$settings->{$role}{'off'}},$priv);
9539: }
9540: } else {
9541: push(@{$overridden->{$role}{'on'}},$priv);
9542: unless ($currentprivs{$priv}) {
9543: push(@{$settings->{$role}{'on'}},$priv);
9544: }
9545: }
9546: }
9547: }
9548: }
9549: }
9550: }
9551: return;
9552: }
9553:
9554: sub update_helpdeskaccess {
9555: my ($r,$permission,$brcrum) = @_;
9556: my $helpitem = 'Course_Helpdesk_Access';
9557: push (@{$brcrum},
9558: {href => '/adm/createuser?action=helpdesk',
9559: text => 'Helpdesk Access',
9560: help => $helpitem},
9561: {href => '/adm/createuser?action=helpdesk',
9562: text => 'Result',
9563: help => $helpitem}
9564: );
9565: my $bread_crumbs_component = 'Helpdesk Staff Access';
9566: my $args = { bread_crumbs => $brcrum,
9567: bread_crumbs_component => $bread_crumbs_component};
9568:
9569: # print page header
9570: $r->print(&header('',$args));
9571: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
9572: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
9573: return;
9574: }
1.434 raeburn 9575: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 9576: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9577: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9578: my $confname = $cdom.'-domainconfig';
9579: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
9580: my $crstype = &Apache::loncommon::course_type();
9581: my %customroles = &get_domain_customroles($cdom,$confname);
9582: my (%settings,%overridden);
9583: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
9584: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 9585: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 9586: my (%changed,%storehash,@todelete);
9587:
9588: if (keys(%customroles)) {
9589: my (%newsettings,@incrs);
9590: foreach my $role (keys(%customroles)) {
9591: $newsettings{$role} = {
9592: access => '',
9593: status => '',
9594: exc => '',
9595: inc => '',
9596: on => '',
9597: off => '',
9598: };
9599: my %current;
9600: if (ref($settings{$role}) eq 'HASH') {
9601: %current = %{$settings{$role}};
9602: }
9603: if (ref($overridden{$role}) eq 'HASH') {
9604: $current{'overridden'} = $overridden{$role};
9605: }
9606: if ($env{'form.'.$role.'_incrs'}) {
9607: my $access = $env{'form.'.$role.'_access'};
9608: if (grep(/^\Q$access\E$/,@accesstypes)) {
9609: push(@incrs,$role);
9610: unless ($current{'access'} eq $access) {
9611: $changed{$role}{'access'} = 1;
1.430 raeburn 9612: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 9613: }
9614: if ($access eq 'status') {
9615: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
9616: my @stored;
9617: my @shownstatus;
9618: if (ref($types) eq 'ARRAY') {
9619: foreach my $type (sort(@statuses)) {
9620: if ($type eq 'default') {
9621: push(@stored,$type);
9622: } elsif (grep(/^\Q$type\E$/,@{$types})) {
9623: push(@stored,$type);
9624: push(@shownstatus,$usertypes->{$type});
9625: }
9626: }
9627: if (grep(/^default$/,@statuses)) {
9628: push(@shownstatus,$othertitle);
9629: }
9630: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
9631: }
9632: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
9633: if (ref($current{'status'}) eq 'ARRAY') {
9634: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
9635: if (@diffs) {
9636: $changed{$role}{'status'} = 1;
9637: }
9638: } elsif (@stored) {
9639: $changed{$role}{'status'} = 1;
9640: }
9641: } elsif (($access eq 'inc') || ($access eq 'exc')) {
9642: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
9643: my @newspecstaff;
9644: my @stored;
9645: my @currstaff;
9646: foreach my $person (sort(@personnel)) {
9647: if ($domhelpdesk{$person}) {
1.430 raeburn 9648: push(@stored,$person);
1.428 raeburn 9649: }
9650: }
9651: if (ref($current{$access}) eq 'ARRAY') {
9652: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
9653: if (@diffs) {
9654: $changed{$role}{$access} = 1;
9655: }
9656: } elsif (@stored) {
9657: $changed{$role}{$access} = 1;
9658: }
9659: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
9660: foreach my $person (@stored) {
9661: my ($uname,$udom) = split(/:/,$person);
9662: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
9663: }
9664: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
9665: }
9666: $newsettings{$role}{'access'} = $access;
9667: }
9668: } else {
9669: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
9670: $changed{$role}{'access'} = 1;
9671: $newsettings{$role} = {};
9672: push(@todelete,'internal.adhoc.'.$role);
9673: }
9674: }
9675: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
9676: if (ref($current{'overridden'}) eq 'HASH') {
9677: push(@todelete,'internal.adhocpriv.'.$role);
9678: }
9679: } else {
9680: my %full=();
9681: my %levels= (
9682: course => {},
9683: domain => {},
9684: system => {},
9685: );
9686: my %levelscurrent=(
9687: course => {},
9688: domain => {},
9689: system => {},
9690: );
9691: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
9692: my (@updatedon,@updatedoff,@override);
9693: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 9694: if (@override) {
1.428 raeburn 9695: foreach my $priv (sort(keys(%full))) {
9696: next unless ($levels{'course'}{$priv});
9697: if (grep(/^\Q$priv\E$/,@override)) {
9698: if ($levelscurrent{'course'}{$priv}) {
9699: push(@updatedoff,$priv);
9700: } else {
9701: push(@updatedon,$priv);
9702: }
9703: }
9704: }
9705: }
9706: if (@updatedon) {
1.430 raeburn 9707: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 9708: }
9709: if (@updatedoff) {
9710: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
9711: }
9712: if (ref($current{'overridden'}) eq 'HASH') {
9713: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
9714: if (@updatedon) {
9715: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
9716: if (@diffs) {
9717: $changed{$role}{'on'} = 1;
9718: }
9719: } else {
9720: $changed{$role}{'on'} = 1;
9721: }
9722: } elsif (@updatedon) {
9723: $changed{$role}{'on'} = 1;
9724: }
9725: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
9726: if (@updatedoff) {
9727: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
9728: if (@diffs) {
9729: $changed{$role}{'off'} = 1;
9730: }
9731: } else {
9732: $changed{$role}{'off'} = 1;
9733: }
9734: } elsif (@updatedoff) {
9735: $changed{$role}{'off'} = 1;
9736: }
9737: } else {
9738: if (@updatedon) {
9739: $changed{$role}{'on'} = 1;
9740: }
9741: if (@updatedoff) {
9742: $changed{$role}{'off'} = 1;
9743: }
9744: }
9745: if (ref($changed{$role}) eq 'HASH') {
9746: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
9747: my $newpriv;
9748: if (@updatedon) {
9749: $newpriv = 'on='.join(':',@updatedon);
9750: }
9751: if (@updatedoff) {
9752: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
9753: }
9754: if ($newpriv eq '') {
9755: push(@todelete,'internal.adhocpriv.'.$role);
9756: } else {
9757: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
9758: }
9759: }
9760: }
9761: }
9762: }
9763: if (@incrs) {
9764: $storehash{'internal.adhocaccess'} = join(',',@incrs);
9765: } elsif (@todelete) {
9766: push(@todelete,'internal.adhocaccess');
9767: }
9768: if (keys(%changed)) {
9769: my ($putres,$delres);
9770: if (keys(%storehash)) {
9771: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
9772: my %newenvhash;
9773: foreach my $key (keys(%storehash)) {
9774: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
9775: }
9776: &Apache::lonnet::appenv(\%newenvhash);
9777: }
9778: if (@todelete) {
9779: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
9780: foreach my $key (@todelete) {
9781: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
9782: }
9783: }
9784: if (($putres eq 'ok') || ($delres eq 'ok')) {
9785: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
9786: my (%domcurrent,%ordered,%description,%domusage);
9787: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9788: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
9789: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
9790: }
9791: }
9792: my $count = 0;
9793: foreach my $role (sort(keys(%customroles))) {
9794: my ($order,$desc);
9795: if (ref($domcurrent{$role}) eq 'HASH') {
9796: $order = $domcurrent{$role}{'order'};
9797: $desc = $domcurrent{$role}{'desc'};
9798: }
9799: if ($order eq '') {
9800: $order = $count;
9801: }
9802: $ordered{$order} = $role;
9803: if ($desc ne '') {
9804: $description{$role} = $desc;
9805: } else {
9806: $description{$role}= $role;
9807: }
9808: $count++;
9809: }
9810: my @roles_by_num = ();
9811: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
9812: push(@roles_by_num,$ordered{$item});
9813: }
9814: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 9815: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 9816: $r->print('<ul>');
9817: foreach my $role (@roles_by_num) {
9818: next unless (ref($changed{$role}) eq 'HASH');
9819: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
9820: '<ul>');
1.430 raeburn 9821: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 9822: $r->print('<li>');
9823: if ($env{'form.'.$role.'_incrs'}) {
9824: if ($newsettings{$role}{'access'} eq 'all') {
9825: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 9826: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 9827: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
9828: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 9829: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 9830: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
9831: &Apache::lonnet::plaintext('da')));
1.428 raeburn 9832: } elsif ($newsettings{$role}{'access'} eq 'none') {
9833: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9834: } elsif ($newsettings{$role}{'access'} eq 'status') {
9835: if ($newsettings{$role}{'status'}) {
9836: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 9837: if (split(/,/,$rest) > 1) {
1.428 raeburn 9838: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
9839: $newsettings{$role}{'status'}));
9840: } else {
9841: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
9842: $newsettings{$role}{'status'}));
9843: }
9844: } else {
9845: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9846: }
9847: } elsif ($newsettings{$role}{'access'} eq 'exc') {
9848: if ($newsettings{$role}{'exc'}) {
9849: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
9850: } else {
9851: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9852: }
9853: } elsif ($newsettings{$role}{'access'} eq 'inc') {
9854: if ($newsettings{$role}{'inc'}) {
9855: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
9856: } else {
9857: $r->print(&mt('All helpdesk staff may use this role.'));
9858: }
9859: }
9860: } else {
9861: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
9862: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
9863: }
9864: $r->print('</li>');
9865: }
9866: unless ($newsettings{$role}{'access'} eq 'none') {
9867: if ($changed{$role}{'off'}) {
9868: if ($newsettings{$role}{'off'}) {
9869: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
9870: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
9871: } else {
1.430 raeburn 9872: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 9873: }
9874: }
1.430 raeburn 9875: if ($changed{$role}{'on'}) {
1.428 raeburn 9876: if ($newsettings{$role}{'on'}) {
9877: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
9878: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
9879: } else {
1.430 raeburn 9880: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 9881: }
9882: }
9883: }
9884: $r->print('</ul></li>');
9885: }
9886: $r->print('</ul>');
9887: }
9888: } else {
1.430 raeburn 9889: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 9890: }
9891: }
9892: return;
9893: }
9894:
1.27 matthew 9895: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 9896: sub user_search_result {
1.221 raeburn 9897: my ($context,$srch) = @_;
1.160 raeburn 9898: my %allhomes;
9899: my %inst_matches;
9900: my %srch_results;
1.181 raeburn 9901: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 9902: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 9903: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 9904: $response = &mt('Invalid search.');
9905: }
9906: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
9907: $response = &mt('Invalid search.');
9908: }
1.177 raeburn 9909: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 9910: $response = &mt('Invalid search.');
9911: }
9912: if ($srch->{'srchterm'} eq '') {
9913: $response = &mt('You must enter a search term.');
9914: }
1.183 raeburn 9915: if ($srch->{'srchterm'} =~ /^\s+$/) {
9916: $response = &mt('Your search term must contain more than just spaces.');
9917: }
1.160 raeburn 9918: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
9919: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 9920: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 9921: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
9922: }
9923: }
9924: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
9925: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 9926: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 9927: my $unamecheck = $srch->{'srchterm'};
9928: if ($srch->{'srchtype'} eq 'contains') {
9929: if ($unamecheck !~ /^\w/) {
9930: $unamecheck = 'a'.$unamecheck;
9931: }
9932: }
9933: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 9934: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
9935: }
1.160 raeburn 9936: }
9937: }
1.180 raeburn 9938: if ($response ne '') {
1.413 raeburn 9939: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 9940: }
1.160 raeburn 9941: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 9942: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 9943: if ($instd_chk ne 'ok') {
1.412 raeburn 9944: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 9945: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 9946: if ($domd_chk eq 'ok') {
1.435 raeburn 9947: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 9948: }
1.415 raeburn 9949: $response .= '<br />';
1.412 raeburn 9950: }
9951: } else {
1.417 raeburn 9952: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 9953: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 9954: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 9955: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 9956: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 9957: if ($instd_chk eq 'ok') {
1.435 raeburn 9958: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 9959: }
1.415 raeburn 9960: $response .= '<br />';
1.412 raeburn 9961: }
1.160 raeburn 9962: }
9963: }
9964: if ($response ne '') {
1.180 raeburn 9965: return ($currstate,$response);
1.160 raeburn 9966: }
9967: if ($srch->{'srchby'} eq 'uname') {
9968: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
9969: if ($env{'form.forcenew'}) {
9970: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
9971: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
9972: if ($uhome eq 'no_host') {
9973: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 9974: my $showdom = &display_domain_info($env{'request.role.domain'});
9975: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 9976: } else {
1.179 raeburn 9977: $currstate = 'modify';
1.160 raeburn 9978: }
9979: } else {
1.179 raeburn 9980: $currstate = 'modify';
1.160 raeburn 9981: }
9982: } else {
9983: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 9984: if ($srch->{'srchtype'} eq 'exact') {
9985: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
9986: if ($uhome eq 'no_host') {
1.179 raeburn 9987: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9988: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 9989: } else {
1.179 raeburn 9990: $currstate = 'modify';
1.416 raeburn 9991: if ($env{'form.action'} eq 'accesslogs') {
9992: $currstate = 'activity';
9993: }
1.310 raeburn 9994: my $uname = $srch->{'srchterm'};
9995: my $udom = $srch->{'srchdomain'};
9996: $srch_results{$uname.':'.$udom} =
9997: { &Apache::lonnet::get('environment',
9998: ['firstname',
9999: 'lastname',
10000: 'permanentemail'],
10001: $udom,$uname)
10002: };
1.162 raeburn 10003: }
10004: } else {
10005: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 10006: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10007: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 10008: }
10009: } else {
1.167 albertel 10010: my $courseusers = &get_courseusers();
1.162 raeburn 10011: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 10012: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 10013: $currstate = 'modify';
1.162 raeburn 10014: } else {
1.179 raeburn 10015: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10016: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 10017: }
1.160 raeburn 10018: } else {
1.167 albertel 10019: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 10020: my ($cuname,$cudomain) = split(/:/,$user);
10021: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 10022: my $matched = 0;
10023: if ($srch->{'srchtype'} eq 'begins') {
10024: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
10025: $matched = 1;
10026: }
10027: } else {
10028: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
10029: $matched = 1;
10030: }
10031: }
10032: if ($matched) {
1.167 albertel 10033: $srch_results{$user} =
10034: {&Apache::lonnet::get('environment',
10035: ['firstname',
10036: 'lastname',
1.194 albertel 10037: 'permanentemail'],
10038: $cudomain,$cuname)};
1.162 raeburn 10039: }
10040: }
10041: }
1.179 raeburn 10042: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10043: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 10044: }
10045: }
10046: }
10047: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 10048: $currstate = 'query';
1.160 raeburn 10049: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 10050: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
10051: if ($dirsrchres eq 'ok') {
10052: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10053: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 10054: } else {
10055: my $showdom = &display_domain_info($srch->{'srchdomain'});
10056: $response = '<span class="LC_warning">'.
10057: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
10058: '</span><br />'.
1.435 raeburn 10059: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 10060: '<br />';
1.181 raeburn 10061: }
1.160 raeburn 10062: }
10063: } else {
10064: if ($srch->{'srchin'} eq 'dom') {
10065: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 10066: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10067: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 10068: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 10069: my $courseusers = &get_courseusers();
10070: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 10071: my ($uname,$udom) = split(/:/,$user);
10072: my %names = &Apache::loncommon::getnames($uname,$udom);
10073: my %emails = &Apache::loncommon::getemails($uname,$udom);
10074: if ($srch->{'srchby'} eq 'lastname') {
10075: if ((($srch->{'srchtype'} eq 'exact') &&
10076: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 10077: (($srch->{'srchtype'} eq 'begins') &&
10078: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 10079: (($srch->{'srchtype'} eq 'contains') &&
10080: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
10081: $srch_results{$user} = {firstname => $names{'firstname'},
10082: lastname => $names{'lastname'},
10083: permanentemail => $emails{'permanentemail'},
10084: };
10085: }
10086: } elsif ($srch->{'srchby'} eq 'lastfirst') {
10087: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 10088: $srchlast =~ s/\s+$//;
10089: $srchfirst =~ s/^\s+//;
1.160 raeburn 10090: if ($srch->{'srchtype'} eq 'exact') {
10091: if (($names{'lastname'} eq $srchlast) &&
10092: ($names{'firstname'} eq $srchfirst)) {
10093: $srch_results{$user} = {firstname => $names{'firstname'},
10094: lastname => $names{'lastname'},
10095: permanentemail => $emails{'permanentemail'},
10096:
10097: };
10098: }
1.177 raeburn 10099: } elsif ($srch->{'srchtype'} eq 'begins') {
10100: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
10101: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
10102: $srch_results{$user} = {firstname => $names{'firstname'},
10103: lastname => $names{'lastname'},
10104: permanentemail => $emails{'permanentemail'},
10105: };
10106: }
10107: } else {
1.160 raeburn 10108: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
10109: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
10110: $srch_results{$user} = {firstname => $names{'firstname'},
10111: lastname => $names{'lastname'},
10112: permanentemail => $emails{'permanentemail'},
10113: };
10114: }
10115: }
10116: }
10117: }
1.179 raeburn 10118: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10119: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 10120: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 10121: $currstate = 'query';
1.160 raeburn 10122: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 10123: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
10124: if ($dirsrchres eq 'ok') {
10125: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10126: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 10127: } else {
1.412 raeburn 10128: my $showdom = &display_domain_info($srch->{'srchdomain'});
10129: $response = '<span class="LC_warning">'.
1.181 raeburn 10130: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
10131: '</span><br />'.
1.435 raeburn 10132: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 10133: '<br />';
1.181 raeburn 10134: }
1.160 raeburn 10135: }
10136: }
1.179 raeburn 10137: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 10138: }
10139:
1.412 raeburn 10140: sub domdirectorysrch_check {
10141: my ($srch) = @_;
10142: my $response;
10143: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
10144: ['directorysrch'],$srch->{'srchdomain'});
10145: my $showdom = &display_domain_info($srch->{'srchdomain'});
10146: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
10147: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
10148: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
10149: }
10150: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
10151: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
10152: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
10153: }
10154: }
10155: }
10156: return 'ok';
10157: }
10158:
10159: sub instdirectorysrch_check {
1.160 raeburn 10160: my ($srch) = @_;
10161: my $can_search = 0;
10162: my $response;
10163: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
10164: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 10165: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 10166: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
10167: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 10168: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 10169: }
10170: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
10171: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 10172: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 10173: }
10174: my @usertypes = split(/:/,$env{'environment.inststatus'});
10175: if (!@usertypes) {
10176: push(@usertypes,'default');
10177: }
10178: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
10179: foreach my $type (@usertypes) {
10180: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
10181: $can_search = 1;
10182: last;
10183: }
10184: }
10185: }
10186: if (!$can_search) {
10187: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
10188: my @longtypes;
10189: foreach my $item (@usertypes) {
1.229 raeburn 10190: if (defined($insttypes->{$item})) {
10191: push (@longtypes,$insttypes->{$item});
10192: } elsif ($item eq 'default') {
10193: push (@longtypes,&mt('other'));
10194: }
1.160 raeburn 10195: }
10196: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 10197: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 10198: }
1.160 raeburn 10199: } else {
10200: $can_search = 1;
10201: }
10202: } else {
1.180 raeburn 10203: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 10204: }
10205: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 10206: uname => 'username',
1.160 raeburn 10207: lastfirst => 'last name, first name',
1.167 albertel 10208: lastname => 'last name',
1.172 raeburn 10209: contains => 'contains',
1.178 raeburn 10210: exact => 'as exact match to',
10211: begins => 'begins with',
1.160 raeburn 10212: );
10213: if ($can_search) {
10214: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
10215: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 10216: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 10217: }
10218: } else {
1.180 raeburn 10219: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 10220: }
10221: }
10222: if ($can_search) {
1.178 raeburn 10223: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
10224: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
10225: return 'ok';
10226: } else {
1.180 raeburn 10227: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 10228: }
10229: } else {
10230: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
10231: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
10232: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
10233: return 'ok';
10234: } else {
1.180 raeburn 10235: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 10236: }
1.160 raeburn 10237: }
10238: }
10239: }
10240:
10241: sub get_courseusers {
10242: my %advhash;
1.167 albertel 10243: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 10244: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
10245: foreach my $role (sort(keys(%coursepersonnel))) {
10246: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 10247: if (!exists($classlist->{$user})) {
10248: $classlist->{$user} = [];
10249: }
1.160 raeburn 10250: }
10251: }
1.167 albertel 10252: return $classlist;
1.160 raeburn 10253: }
10254:
10255: sub build_search_response {
1.221 raeburn 10256: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 10257: my ($currstate,$response,$forcenewuser);
1.160 raeburn 10258: my %names = (
1.330 bisitz 10259: 'uname' => 'username',
10260: 'lastname' => 'last name',
1.160 raeburn 10261: 'lastfirst' => 'last name, first name',
1.330 bisitz 10262: 'crs' => 'this course',
10263: 'dom' => 'LON-CAPA domain',
10264: 'instd' => 'the institutional directory for domain',
1.160 raeburn 10265: );
10266:
10267: my %single = (
1.180 raeburn 10268: begins => 'A match',
1.160 raeburn 10269: contains => 'A match',
1.180 raeburn 10270: exact => 'An exact match',
1.160 raeburn 10271: );
10272: my %nomatch = (
1.180 raeburn 10273: begins => 'No match',
1.160 raeburn 10274: contains => 'No match',
1.180 raeburn 10275: exact => 'No exact match',
1.160 raeburn 10276: );
10277: if (keys(%srch_results) > 1) {
1.179 raeburn 10278: $currstate = 'select';
1.160 raeburn 10279: } else {
10280: if (keys(%srch_results) == 1) {
1.416 raeburn 10281: if ($env{'form.action'} eq 'accesslogs') {
10282: $currstate = 'activity';
10283: } else {
10284: $currstate = 'modify';
10285: }
1.180 raeburn 10286: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
10287: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 10288: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 10289: }
1.330 bisitz 10290: } else { # Search has nothing found. Prepare message to user.
10291: $response = '<span class="LC_warning">';
1.180 raeburn 10292: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 10293: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
10294: '<b>'.$srch->{'srchterm'}.'</b>',
10295: &display_domain_info($srch->{'srchdomain'}));
10296: } else {
10297: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
10298: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 10299: }
10300: $response .= '</span>';
1.330 bisitz 10301:
1.160 raeburn 10302: if ($srch->{'srchin'} ne 'alc') {
10303: $forcenewuser = 1;
10304: my $cansrchinst = 0;
1.438 raeburn 10305: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 10306: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
10307: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10308: if ($domconfig{'directorysrch'}{'available'}) {
10309: $cansrchinst = 1;
10310: }
10311: }
10312: }
1.180 raeburn 10313: if ((($srch->{'srchby'} eq 'lastfirst') ||
10314: ($srch->{'srchby'} eq 'lastname')) &&
10315: ($srch->{'srchin'} eq 'dom')) {
10316: if ($cansrchinst) {
10317: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 10318: }
10319: }
1.180 raeburn 10320: if ($srch->{'srchin'} eq 'crs') {
10321: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
10322: }
10323: }
1.305 raeburn 10324: my $createdom = $env{'request.role.domain'};
10325: if ($context eq 'requestcrs') {
10326: if ($env{'form.coursedom'} ne '') {
10327: $createdom = $env{'form.coursedom'};
10328: }
10329: }
1.416 raeburn 10330: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
10331: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 10332: my $cancreate =
1.305 raeburn 10333: &Apache::lonuserutils::can_create_user($createdom,$context);
10334: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 10335: if ($cancreate) {
1.305 raeburn 10336: my $showdom = &display_domain_info($createdom);
1.266 bisitz 10337: $response .= '<br /><br />'
10338: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 10339: .'<br />';
10340: if ($context eq 'requestcrs') {
10341: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
10342: } else {
10343: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
10344: }
10345: $response .='<ul><li>'
1.266 bisitz 10346: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
10347: .'</li><li>'
10348: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
10349: .'</li><li>'
10350: .&mt('Provide the proposed username')
10351: .'</li><li>'
10352: .&mt("Click 'Search'")
10353: .'</li></ul><br />';
1.221 raeburn 10354: } else {
1.422 raeburn 10355: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
10356: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
10357: $response .= '<br /><br />';
10358: if ($context eq 'requestcrs') {
10359: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
10360: } else {
10361: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
10362: }
10363: $response .= '<br />'
10364: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
10365: ,' <a'.$helplink.'>'
10366: ,'</a>')
10367: .'<br />';
1.305 raeburn 10368: }
1.221 raeburn 10369: }
1.160 raeburn 10370: }
10371: }
10372: }
1.179 raeburn 10373: return ($currstate,$response,$forcenewuser);
1.160 raeburn 10374: }
10375:
1.180 raeburn 10376: sub display_domain_info {
10377: my ($dom) = @_;
10378: my $output = $dom;
10379: if ($dom ne '') {
10380: my $domdesc = &Apache::lonnet::domain($dom,'description');
10381: if ($domdesc ne '') {
10382: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
10383: }
10384: }
10385: return $output;
10386: }
10387:
1.160 raeburn 10388: sub crumb_utilities {
10389: my %elements = (
10390: crtuser => {
10391: srchterm => 'text',
1.172 raeburn 10392: srchin => 'selectbox',
1.160 raeburn 10393: srchby => 'selectbox',
10394: srchtype => 'selectbox',
10395: srchdomain => 'selectbox',
10396: },
1.207 raeburn 10397: crtusername => {
10398: srchterm => 'text',
10399: srchdomain => 'selectbox',
10400: },
1.160 raeburn 10401: docustom => {
10402: rolename => 'selectbox',
10403: newrolename => 'textbox',
10404: },
1.179 raeburn 10405: studentform => {
10406: srchterm => 'text',
10407: srchin => 'selectbox',
10408: srchby => 'selectbox',
10409: srchtype => 'selectbox',
10410: srchdomain => 'selectbox',
10411: },
1.160 raeburn 10412: );
10413:
10414: my $jsback .= qq|
10415: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 10416: if (typeof prevphase == 'undefined') {
10417: formname.phase.value = '';
10418: }
10419: else {
10420: formname.phase.value = prevphase;
10421: }
10422: if (typeof prevstate == 'undefined') {
10423: formname.currstate.value = '';
10424: }
10425: else {
10426: formname.currstate.value = prevstate;
10427: }
1.160 raeburn 10428: formname.submit();
10429: }
10430: |;
10431: return ($jsback,\%elements);
10432: }
10433:
1.26 matthew 10434: sub course_level_table {
1.375 raeburn 10435: my ($inccourses,$showcredits,$defaultcredits) = @_;
10436: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 10437: my $table = '';
1.62 www 10438: # Custom Roles?
10439:
1.190 raeburn 10440: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 10441: my %lt=&Apache::lonlocal::texthash(
10442: 'exs' => "Existing sections",
10443: 'new' => "Define new section",
10444: 'ssd' => "Set Start Date",
10445: 'sed' => "Set End Date",
1.131 raeburn 10446: 'crl' => "Course Level",
1.89 raeburn 10447: 'act' => "Activate",
10448: 'rol' => "Role",
10449: 'ext' => "Extent",
1.113 raeburn 10450: 'grs' => "Section",
1.375 raeburn 10451: 'crd' => "Credits",
1.89 raeburn 10452: 'sta' => "Start",
10453: 'end' => "End"
10454: );
1.62 www 10455:
1.375 raeburn 10456: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 10457: my $thiscourse=$protectedcourse;
1.26 matthew 10458: $thiscourse=~s:_:/:g;
10459: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 10460: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 10461: my $area=$coursedata{'description'};
1.321 raeburn 10462: my $crstype=$coursedata{'type'};
1.135 raeburn 10463: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 10464: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 10465: my %sections_count;
1.101 albertel 10466: if (defined($env{'request.course.id'})) {
10467: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 10468: %sections_count =
10469: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 10470: }
10471: }
1.321 raeburn 10472: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 10473: foreach my $role (@roles) {
1.321 raeburn 10474: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 10475: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
10476: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 10477: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 10478: $plrole,\%sections_count,\%lt,
1.402 raeburn 10479: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 10480: } elsif ($env{'request.course.sec'} ne '') {
10481: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
10482: $env{'request.course.sec'})) {
10483: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 10484: $plrole,\%sections_count,\%lt,
1.402 raeburn 10485: $showcredits,$defaultcredits,$crstype);
1.26 matthew 10486: }
10487: }
10488: }
1.221 raeburn 10489: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 10490: foreach my $cust (sort(keys(%customroles))) {
10491: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 10492: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
10493: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 10494: $cust,\%sections_count,\%lt,
10495: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 10496: }
1.62 www 10497: }
1.26 matthew 10498: }
10499: return '' if ($table eq ''); # return nothing if there is nothing
10500: # in the table
1.188 raeburn 10501: my $result;
10502: if (!$env{'request.course.id'}) {
10503: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
10504: }
10505: $result .=
1.136 raeburn 10506: &Apache::loncommon::start_data_table().
10507: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 10508: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 10509: '<th>'.$lt{'ext'}.'</th><th>'."\n";
10510: if ($showcredits) {
10511: $result .= $lt{'crd'}.'</th>';
10512: }
10513: $result .=
1.375 raeburn 10514: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
10515: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 10516: &Apache::loncommon::end_data_table_header_row().
10517: $table.
10518: &Apache::loncommon::end_data_table();
1.26 matthew 10519: return $result;
10520: }
1.88 raeburn 10521:
1.221 raeburn 10522: sub course_level_row {
1.375 raeburn 10523: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 10524: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 10525: my $creditem;
1.222 raeburn 10526: my $row = &Apache::loncommon::start_data_table_row().
10527: ' <td><input type="checkbox" name="act_'.
10528: $protectedcourse.'_'.$role.'" /></td>'."\n".
10529: ' <td>'.$plrole.'</td>'."\n".
10530: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 10531: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 10532: $row .=
10533: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
10534: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
10535: } else {
10536: $row .= '<td> </td>';
10537: }
1.322 raeburn 10538: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 10539: $row .= '<td> </td>';
1.221 raeburn 10540: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 10541: $row .= ' <td><input type="hidden" value="'.
10542: $env{'request.course.sec'}.'" '.
10543: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
10544: $env{'request.course.sec'}.'</td>';
1.221 raeburn 10545: } else {
10546: if (ref($sections_count) eq 'HASH') {
10547: my $currsec =
10548: &Apache::lonuserutils::course_sections($sections_count,
10549: $protectedcourse.'_'.$role);
1.222 raeburn 10550: $row .= '<td><table class="LC_createuser">'."\n".
10551: '<tr class="LC_section_row">'."\n".
10552: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
10553: $currsec.'</td>'."\n".
10554: ' <td> </td>'."\n".
10555: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 10556: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
10557: '" value="" />'.
10558: '<input type="hidden" '.
10559: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 10560: '</tr></table></td>'."\n";
1.221 raeburn 10561: } else {
1.222 raeburn 10562: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 10563: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 10564: }
10565: }
1.222 raeburn 10566: $row .= <<ENDTIMEENTRY;
10567: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 10568: <a href=
10569: "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 10570: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 10571: <a href=
10572: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
10573: ENDTIMEENTRY
1.222 raeburn 10574: $row .= &Apache::loncommon::end_data_table_row();
10575: return $row;
1.221 raeburn 10576: }
10577:
1.88 raeburn 10578: sub course_level_dc {
1.375 raeburn 10579: my ($dcdom,$showcredits) = @_;
1.190 raeburn 10580: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 10581: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 10582: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
10583: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 10584: '<input type="hidden" name="dccourse" value="" />';
1.355 www 10585: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 10586: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 10587: my $credit_elem;
10588: if ($showcredits) {
10589: $credit_elem = 'credits';
10590: }
10591: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 10592: my %lt=&Apache::lonlocal::texthash(
10593: 'rol' => "Role",
1.113 raeburn 10594: 'grs' => "Section",
1.88 raeburn 10595: 'exs' => "Existing sections",
10596: 'new' => "Define new section",
10597: 'sta' => "Start",
10598: 'end' => "End",
10599: 'ssd' => "Set Start Date",
1.355 www 10600: 'sed' => "Set End Date",
1.375 raeburn 10601: 'scc' => "Course/Community",
10602: 'crd' => "Credits",
1.88 raeburn 10603: );
1.323 raeburn 10604: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 10605: &Apache::loncommon::start_data_table().
10606: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 10607: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 10608: '<th>'.$lt{'grs'}.'</th>'."\n";
10609: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
10610: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 10611: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 10612: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 10613: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
10614: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 10615: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 10616: foreach my $role (@roles) {
1.135 raeburn 10617: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 10618: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 10619: }
1.404 raeburn 10620: if ( keys(%customroles) > 0) {
10621: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 10622: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 10623: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 10624: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 10625: }
10626: }
10627: $otheritems .= '</select></td><td>'.
10628: '<table border="0" cellspacing="0" cellpadding="0">'.
10629: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 10630: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 10631: '<td> </td>'.
10632: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 10633: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 10634: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 10635: '<input type="hidden" name="groups" value="" />'.
10636: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 10637: '</tr></table></td>'."\n";
10638: if ($showcredits) {
10639: $otheritems .= '<td><br />'."\n".
1.397 bisitz 10640: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 10641: }
1.88 raeburn 10642: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 10643: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 10644: <a href=
10645: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 10646: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 10647: <a href=
10648: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
10649: ENDTIMEENTRY
1.136 raeburn 10650: $otheritems .= &Apache::loncommon::end_data_table_row().
10651: &Apache::loncommon::end_data_table()."\n";
1.470 raeburn 10652: return $cb_jscript.$hiddenitems.$header.$otheritems;
1.88 raeburn 10653: }
10654:
1.237 raeburn 10655: sub update_selfenroll_config {
1.400 raeburn 10656: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 10657: return unless (ref($currsettings) eq 'HASH');
10658: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
10659: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 10660: my (%changes,%warning);
1.241 raeburn 10661: my $curr_types;
1.400 raeburn 10662: my %noedit;
10663: unless ($context eq 'domain') {
10664: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
10665: }
1.237 raeburn 10666: if (ref($row) eq 'ARRAY') {
10667: foreach my $item (@{$row}) {
1.400 raeburn 10668: next if ($noedit{$item});
1.237 raeburn 10669: if ($item eq 'enroll_dates') {
10670: my (%currenrolldate,%newenrolldate);
10671: foreach my $type ('start','end') {
1.398 raeburn 10672: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 10673: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
10674: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
10675: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
10676: }
10677: }
10678: } elsif ($item eq 'access_dates') {
10679: my (%currdate,%newdate);
10680: foreach my $type ('start','end') {
1.398 raeburn 10681: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 10682: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
10683: if ($newdate{$type} ne $currdate{$type}) {
10684: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
10685: }
10686: }
1.241 raeburn 10687: } elsif ($item eq 'types') {
1.398 raeburn 10688: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 10689: if ($env{'form.selfenroll_all'}) {
10690: if ($curr_types ne '*') {
10691: $changes{'internal.selfenroll_types'} = '*';
10692: } else {
10693: next;
10694: }
10695: } else {
1.249 raeburn 10696: my %currdoms;
1.241 raeburn 10697: my @entries = split(/;/,$curr_types);
10698: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 10699: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 10700: my $newnum = 0;
1.249 raeburn 10701: my @latesttypes;
10702: foreach my $num (@activations) {
10703: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
10704: if (@types > 0) {
1.241 raeburn 10705: @types = sort(@types);
10706: my $typestr = join(',',@types);
1.249 raeburn 10707: my $typedom = $env{'form.selfenroll_dom_'.$num};
10708: $latesttypes[$newnum] = $typedom.':'.$typestr;
10709: $currdoms{$typedom} = 1;
1.241 raeburn 10710: $newnum ++;
10711: }
10712: }
1.338 raeburn 10713: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
10714: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 10715: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
10716: if (@types > 0) {
10717: @types = sort(@types);
10718: my $typestr = join(',',@types);
10719: my $typedom = $env{'form.selfenroll_dom_'.$j};
10720: $latesttypes[$newnum] = $typedom.':'.$typestr;
10721: $currdoms{$typedom} = 1;
10722: $newnum ++;
10723: }
10724: }
10725: }
10726: if ($env{'form.selfenroll_newdom'} ne '') {
10727: my $typedom = $env{'form.selfenroll_newdom'};
10728: if ((!defined($currdoms{$typedom})) &&
10729: (&Apache::lonnet::domain($typedom) ne '')) {
10730: my $typestr;
10731: my ($othertitle,$usertypes,$types) =
10732: &Apache::loncommon::sorted_inst_types($typedom);
10733: my $othervalue = 'any';
10734: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
10735: if (@{$types} > 0) {
1.257 raeburn 10736: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 10737: $othervalue = 'other';
1.258 raeburn 10738: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 10739: }
10740: $typestr = $othervalue;
10741: } else {
10742: $typestr = $othervalue;
10743: }
10744: $latesttypes[$newnum] = $typedom.':'.$typestr;
10745: $newnum ++ ;
10746: }
10747: }
1.241 raeburn 10748: my $selfenroll_types = join(';',@latesttypes);
10749: if ($selfenroll_types ne $curr_types) {
10750: $changes{'internal.selfenroll_types'} = $selfenroll_types;
10751: }
10752: }
1.276 raeburn 10753: } elsif ($item eq 'limit') {
10754: my $newlimit = $env{'form.selfenroll_limit'};
10755: my $newcap = $env{'form.selfenroll_cap'};
10756: $newcap =~s/\s+//g;
1.398 raeburn 10757: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 10758: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 10759: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 10760: if ($newlimit ne $currlimit) {
10761: if ($newlimit ne 'none') {
10762: if ($newcap =~ /^\d+$/) {
10763: if ($newcap ne $currcap) {
10764: $changes{'internal.selfenroll_cap'} = $newcap;
10765: }
10766: $changes{'internal.selfenroll_limit'} = $newlimit;
10767: } else {
1.398 raeburn 10768: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
10769: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 10770: }
10771: } elsif ($currcap ne '') {
10772: $changes{'internal.selfenroll_cap'} = '';
10773: $changes{'internal.selfenroll_limit'} = $newlimit;
10774: }
10775: } elsif ($currlimit ne 'none') {
10776: if ($newcap =~ /^\d+$/) {
10777: if ($newcap ne $currcap) {
10778: $changes{'internal.selfenroll_cap'} = $newcap;
10779: }
10780: } else {
1.398 raeburn 10781: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
10782: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 10783: }
10784: }
10785: } elsif ($item eq 'approval') {
10786: my (@currnotified,@newnotified);
1.398 raeburn 10787: my $currapproval = $currsettings->{'selfenroll_approval'};
10788: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 10789: if ($currnotifylist ne '') {
10790: @currnotified = split(/,/,$currnotifylist);
10791: @currnotified = sort(@currnotified);
10792: }
10793: my $newapproval = $env{'form.selfenroll_approval'};
10794: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
10795: @newnotified = sort(@newnotified);
10796: if ($newapproval ne $currapproval) {
10797: $changes{'internal.selfenroll_approval'} = $newapproval;
10798: if (!$newapproval) {
10799: if ($currnotifylist ne '') {
10800: $changes{'internal.selfenroll_notifylist'} = '';
10801: }
10802: } else {
10803: my @differences =
1.295 raeburn 10804: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 10805: if (@differences > 0) {
10806: if (@newnotified > 0) {
10807: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10808: } else {
10809: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10810: }
10811: }
10812: }
10813: } else {
1.295 raeburn 10814: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 10815: if (@differences > 0) {
10816: if (@newnotified > 0) {
10817: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10818: } else {
10819: $changes{'internal.selfenroll_notifylist'} = '';
10820: }
10821: }
10822: }
1.237 raeburn 10823: } else {
1.398 raeburn 10824: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 10825: my $newval = $env{'form.selfenroll_'.$item};
10826: if ($item eq 'section') {
10827: $newval = $env{'form.sections'};
1.241 raeburn 10828: if (defined($curr_groups{$newval})) {
1.237 raeburn 10829: $newval = $curr_val;
1.398 raeburn 10830: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
10831: &mt('Group names and section names must be distinct');
1.237 raeburn 10832: } elsif ($newval eq 'all') {
10833: $newval = $curr_val;
1.274 bisitz 10834: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 10835: }
10836: if ($newval eq '') {
10837: $newval = 'none';
10838: }
10839: }
10840: if ($newval ne $curr_val) {
10841: $changes{'internal.selfenroll_'.$item} = $newval;
10842: }
1.241 raeburn 10843: }
1.237 raeburn 10844: }
10845: if (keys(%warning) > 0) {
10846: foreach my $item (@{$row}) {
10847: if (exists($warning{$item})) {
10848: $r->print($warning{$item}.'<br />');
10849: }
10850: }
10851: }
10852: if (keys(%changes) > 0) {
10853: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
10854: if ($putresult eq 'ok') {
10855: if ((exists($changes{'internal.selfenroll_types'})) ||
10856: (exists($changes{'internal.selfenroll_start_date'})) ||
10857: (exists($changes{'internal.selfenroll_end_date'}))) {
10858: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
10859: $cnum,undef,undef,'Course');
10860: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 10861: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 10862: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
10863: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 10864: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 10865: }
10866: }
10867: my $crsputresult =
10868: &Apache::lonnet::courseidput($cdom,\%crsinfo,
10869: $chome,'notime');
10870: }
10871: }
10872: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
10873: foreach my $item (@{$row}) {
10874: my $title = $item;
10875: if (ref($lt) eq 'HASH') {
10876: $title = $lt->{$item};
10877: }
10878: if ($item eq 'enroll_dates') {
10879: foreach my $type ('start','end') {
10880: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
10881: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 10882: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 10883: $title,$type,$newdate).'</li>');
10884: }
10885: }
10886: } elsif ($item eq 'access_dates') {
10887: foreach my $type ('start','end') {
10888: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
10889: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 10890: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 10891: $title,$type,$newdate).'</li>');
10892: }
10893: }
1.276 raeburn 10894: } elsif ($item eq 'limit') {
10895: if ((exists($changes{'internal.selfenroll_limit'})) ||
10896: (exists($changes{'internal.selfenroll_cap'}))) {
10897: my ($newval,$newcap);
10898: if ($changes{'internal.selfenroll_cap'} ne '') {
10899: $newcap = $changes{'internal.selfenroll_cap'}
10900: } else {
1.398 raeburn 10901: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 10902: }
10903: if ($changes{'internal.selfenroll_limit'} eq 'none') {
10904: $newval = &mt('No limit');
10905: } elsif ($changes{'internal.selfenroll_limit'} eq
10906: 'allstudents') {
10907: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
10908: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
10909: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
10910: } else {
1.398 raeburn 10911: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 10912: if ($currlimit eq 'allstudents') {
10913: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
10914: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 10915: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 10916: }
10917: }
10918: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
10919: }
10920: } elsif ($item eq 'approval') {
10921: if ((exists($changes{'internal.selfenroll_approval'})) ||
10922: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 10923: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 10924: my ($newval,$newnotify);
10925: if (exists($changes{'internal.selfenroll_notifylist'})) {
10926: $newnotify = $changes{'internal.selfenroll_notifylist'};
10927: } else {
1.398 raeburn 10928: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 10929: }
1.398 raeburn 10930: if (exists($changes{'internal.selfenroll_approval'})) {
10931: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
10932: $changes{'internal.selfenroll_approval'} = '0';
10933: }
10934: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 10935: } else {
1.398 raeburn 10936: my $currapproval = $currsettings->{'selfenroll_approval'};
10937: if ($currapproval !~ /^[012]$/) {
10938: $currapproval = 0;
1.276 raeburn 10939: }
1.398 raeburn 10940: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 10941: }
10942: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
10943: if ($newnotify) {
1.277 raeburn 10944: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 10945: } else {
1.277 raeburn 10946: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 10947: }
10948: $r->print('</li>'."\n");
10949: }
1.237 raeburn 10950: } else {
10951: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 10952: my $newval = $changes{'internal.selfenroll_'.$item};
10953: if ($item eq 'types') {
10954: if ($newval eq '') {
10955: $newval = &mt('None');
10956: } elsif ($newval eq '*') {
10957: $newval = &mt('Any user in any domain');
10958: }
1.245 raeburn 10959: } elsif ($item eq 'registered') {
10960: if ($newval eq '1') {
10961: $newval = &mt('Yes');
10962: } elsif ($newval eq '0') {
10963: $newval = &mt('No');
10964: }
1.241 raeburn 10965: }
1.244 bisitz 10966: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 10967: }
10968: }
10969: }
10970: $r->print('</ul>');
1.398 raeburn 10971: if ($env{'course.'.$cid.'.description'} ne '') {
10972: my %newenvhash;
10973: foreach my $key (keys(%changes)) {
10974: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
10975: }
10976: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 10977: }
10978: } else {
1.398 raeburn 10979: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
10980: &mt('The error was: [_1].',$putresult));
1.237 raeburn 10981: }
10982: } else {
1.249 raeburn 10983: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 10984: }
10985: } else {
1.249 raeburn 10986: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 10987: }
1.469 raeburn 10988: my $visactions = &cat_visibility($cdom);
1.400 raeburn 10989: my ($cathash,%cattype);
10990: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
10991: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
10992: $cathash = $domconfig{'coursecategories'}{'cats'};
10993: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
10994: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
10995: } else {
10996: $cathash = {};
10997: $cattype{'auth'} = 'std';
10998: $cattype{'unauth'} = 'std';
10999: }
11000: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
11001: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
11002: '<br />'.
11003: '<br />'.$visactions->{'take'}.'<ul>'.
11004: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
11005: '</ul>');
11006: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
11007: if ($currsettings->{'uniquecode'}) {
11008: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
11009: } else {
1.366 bisitz 11010: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 11011: '<br />'.
11012: '<br />'.$visactions->{'take'}.'<ul>'.
11013: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
11014: '</ul><br />');
11015: }
11016: } else {
11017: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
11018: if (ref($visactions) eq 'HASH') {
11019: if (!$visible) {
11020: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
11021: '<br />');
11022: if (ref($vismsgs) eq 'ARRAY') {
11023: $r->print('<br />'.$visactions->{'take'}.'<ul>');
11024: foreach my $item (@{$vismsgs}) {
11025: $r->print('<li>'.$visactions->{$item}.'</li>');
11026: }
11027: $r->print('</ul>');
1.256 raeburn 11028: }
1.400 raeburn 11029: $r->print($cansetvis);
1.256 raeburn 11030: }
11031: }
11032: }
1.237 raeburn 11033: return;
11034: }
11035:
1.27 matthew 11036: #---------------------------------------------- end functions for &phase_two
1.29 matthew 11037:
11038: #--------------------------------- functions for &phase_two and &phase_three
11039:
11040: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 11041:
1.1 www 11042: 1;
11043: __END__
1.2 www 11044:
11045:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>