Annotation of loncom/interface/loncreateuser.pm, revision 1.479
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.479 ! raeburn 4: # $Id: loncreateuser.pm,v 1.478 2024/05/01 21:22:09 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 = '';
378: }
379: }
1.362 raeburn 380: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 381: $cust_on = ' checked="checked" ';
382: $cust_off = '';
383: }
384: if ($context eq 'requestcourses') {
385: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 386: $custom_access = &mt('Currently from default setting.');
1.470 raeburn 387: $customsty = ' style="display:none;"';
1.306 raeburn 388: } else {
389: $custom_access = &mt('Currently from custom setting.');
1.470 raeburn 390: $customsty = ' style="display:block;"';
1.275 raeburn 391: }
1.362 raeburn 392: } elsif ($context eq 'requestauthor') {
393: if ($userenv{$context} eq '') {
394: $custom_access = &mt('Currently from default setting.');
1.470 raeburn 395: $customsty = ' style="display:none;"';
396: } else {
397: $custom_access = &mt('Currently from custom setting.');
398: $customsty = ' style="display:block;"';
399: }
400: } elsif ($item eq 'editors') {
401: if ($userenv{'author'.$item} eq '') {
402: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
403: @defaulteditors = @{$domconfig{'authordefaults'}{'editors'}};
404: } else {
405: @defaulteditors = ('edit','xml');
406: }
407: $custom_access = &mt('Can use: [_1]',
408: join(', ', map { $lt{$_} } @defaulteditors));
409: $editorsty = ' style="display:none;"';
1.362 raeburn 410: } else {
411: $custom_access = &mt('Currently from custom setting.');
1.470 raeburn 412: foreach my $editor (split(/,/,$userenv{'author'.$item})) {
413: if ($editor =~ /^(edit|daxe|xml)$/) {
414: push(@customeditors,$editor);
415: }
416: }
417: if (@customeditors) {
418: if (@customeditors > 1) {
419: $custom_access .= '<br /><span>';
420: } else {
421: $custom_access .= ' <span class="LC_nobreak">';
422: }
423: $custom_access .= &mt('Can use: [_1]',
424: join(', ', map { $lt{$_} } @customeditors)).
425: '</span>';
426: } else {
427: $custom_access .= ' '.&mt('No available editors');
428: }
429: $editorsty = ' style="display:block;"';
430: }
431: } elsif ($item eq 'managers') {
432: my %ca_roles = &Apache::lonnet::get_my_roles($ccuname,$ccdomain,undef,
433: ['active','future'],['ca']);
434: if (keys(%ca_roles)) {
435: foreach my $entry (sort(keys(%ca_roles))) {
436: if ($entry =~ /^($match_username\:$match_domain):ca$/) {
437: my $user = $1;
438: unless ($user eq "$ccuname:$ccdomain") {
439: push(@possmanagers,$user);
440: }
441: }
442: }
443: }
444: if ($userenv{'author'.$item} eq '') {
445: $custom_access = &mt('Currently author manages co-author roles');
446: } else {
447: if (keys(%ca_roles)) {
448: foreach my $user (split(/,/,$userenv{'author'.$item})) {
449: if ($user =~ /^($match_username):($match_domain)$/) {
450: if (exists($ca_roles{$user.':ca'})) {
451: unless ($user eq "$ccuname:$ccdomain") {
452: push(@custommanagers,$user);
453: }
454: }
455: }
456: }
457: }
458: if (@custommanagers) {
459: $custom_access = &mt('Co-authors who manage co-author roles: [_1]',
460: join(', ',@custommanagers));
461: } else {
462: $custom_access = &mt('Currently author manages co-author roles');
463: }
1.362 raeburn 464: }
1.275 raeburn 465: } else {
1.470 raeburn 466: my $current = $userenv{$context.'.'.$item};
467: if ($item eq 'webdav') {
468: $current = $userenv{'tools.webdav'};
1.478 raeburn 469: } elsif ($item eq 'archive') {
470: $current = $userenv{'author'.$item};
1.470 raeburn 471: }
472: if ($current eq '') {
1.314 raeburn 473: $custom_access =
1.306 raeburn 474: &mt('Availability determined currently from default setting.');
475: if (!$curr_access) {
476: $tool_off = 'checked="checked" ';
477: $tool_on = '';
478: }
1.470 raeburn 479: $customsty = ' style="display:none;"';
1.306 raeburn 480: } else {
1.314 raeburn 481: $custom_access =
1.306 raeburn 482: &mt('Availability determined currently from custom setting.');
1.470 raeburn 483: if ($current == 0) {
1.306 raeburn 484: $tool_off = 'checked="checked" ';
485: $tool_on = '';
486: }
1.476 raeburn 487: $customsty = ' style="display:inline;"';
1.275 raeburn 488: }
489: }
490: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 491: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 492: ' </tr>'."\n".
1.306 raeburn 493: &Apache::loncommon::start_data_table_row()."\n";
1.362 raeburn 494: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.475 raeburn 495: my ($curroption,$currlimit);
1.362 raeburn 496: my $envkey = $context.'.'.$item;
497: if ($context eq 'requestauthor') {
498: $envkey = $context;
499: }
500: if ($userenv{$envkey} ne '') {
501: $curroption = $userenv{$envkey};
1.332 raeburn 502: } else {
503: my (@inststatuses);
1.362 raeburn 504: if ($context eq 'requestcourses') {
505: $curroption =
506: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
507: $isadv,$ccdomain,$item,
508: \@inststatuses,\%domconfig);
509: } else {
510: $curroption =
511: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
512: $isadv,$ccdomain,undef,
513: \@inststatuses,\%domconfig);
514: }
1.332 raeburn 515: }
1.306 raeburn 516: if (!$curroption) {
517: $curroption = 'norequest';
518: }
1.470 raeburn 519: my $name = 'crsreq_'.$item;
520: if ($context eq 'requestauthor') {
521: $name = $item;
522: }
523: $onclick = ' onclick="javascript:toggleCustom(this.form,'."'customtext_$item','custom$item'".');"';
1.306 raeburn 524: if ($curroption =~ /^autolimit=(\d*)$/) {
525: $currlimit = $1;
1.314 raeburn 526: if ($currlimit eq '') {
527: $currdisp = &mt('Yes, automatic creation');
528: } else {
529: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
530: }
1.306 raeburn 531: } else {
532: $currdisp = $reqdisplay{$curroption};
533: }
1.470 raeburn 534: $custdisp = '<fieldset id="customtext_'.$item.'"'.$customsty.'>';
1.306 raeburn 535: foreach my $option (@options) {
536: my $val = $option;
537: if ($option eq 'norequest') {
538: $val = 0;
539: }
540: if ($option eq 'validate') {
541: my $canvalidate = 0;
542: if (ref($validations{$item}) eq 'HASH') {
543: if ($validations{$item}{'_custom_'}) {
544: $canvalidate = 1;
545: }
546: }
547: next if (!$canvalidate);
548: }
549: my $checked = '';
550: if ($option eq $curroption) {
551: $checked = ' checked="checked"';
552: } elsif ($option eq 'autolimit') {
553: if ($curroption =~ /^autolimit/) {
554: $checked = ' checked="checked"';
555: }
556: }
1.470 raeburn 557: if ($option eq 'autolimit') {
558: $custdisp .= '<br />';
1.362 raeburn 559: }
1.470 raeburn 560: $custdisp .= '<span class="LC_nobreak"><label>'.
1.362 raeburn 561: '<input type="radio" name="'.$name.'" '.
562: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 563: $reqtitles{$option}.'</label> ';
564: if ($option eq 'autolimit') {
1.362 raeburn 565: $custdisp .= '<input type="text" name="'.$name.
566: '_limit" size="1" '.
1.470 raeburn 567: 'value="'.$currlimit.'" /> '.
568: $reqtitles{'unlimited'}.'</span>';
1.362 raeburn 569: } else {
570: $custdisp .= '</span>';
571: }
1.470 raeburn 572: $custdisp .= ' ';
573: }
574: $custdisp .= '</fieldset>';
575: $custradio = '<br />'.$custdisp;
576: } elsif ($item eq 'editors') {
577: $output .= '<td'.$colspan.'>'.$custom_access.'</td>'."\n".
578: &Apache::loncommon::end_data_table_row()."\n";
579: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
580: $output .= &Apache::loncommon::start_data_table_row()."\n".
581: '<td'.$colspan.'><span class="LC_nobreak">'.
582: $lt{'chse'}.': <label>'.
583: '<input type="radio" name="custom'.$item.'" value="0" '.
584: $cust_off.' onclick="toggleCustom(this.form,'."'customtext_$item','custom$item'".');" />'.
585: $lt{'usde'}.'</label>'.(' ' x3).
586: '<label><input type="radio" name="custom'.$item.'" value="1" '.
587: $cust_on.' onclick="toggleCustom(this.form,'."'customtext_$item','custom$item'".');" />'.
588: $lt{'uscu'}.'</label></span><br />'.
589: '<fieldset id="customtext_'.$item.'"'.$editorsty.'>';
590: foreach my $editor ('edit','xml','daxe') {
591: my $checked;
592: if ($userenv{'author'.$item} eq '') {
593: if (grep(/^\Q$editor\E$/,@defaulteditors)) {
594: $checked = ' checked="checked"';
595: }
596: } elsif (grep(/^\Q$editor\E$/,@customeditors)) {
597: $checked = ' checked="checked"';
598: }
599: $output .= '<span style="LC_nobreak"><label>'.
600: '<input type="checkbox" name="custom_editor" '.
601: 'value="'.$editor.'"'.$checked.' />'.
602: $lt{$editor}.'</label></span> ';
603: }
604: $output .= '</fieldset></td>'.
605: &Apache::loncommon::end_data_table_row()."\n";
606: }
607: } elsif ($item eq 'managers') {
608: $output .= '<td'.$colspan.'>'.$custom_access.'</td>'."\n".
609: &Apache::loncommon::end_data_table_row()."\n";
1.471 raeburn 610: unless ((&Apache::lonnet::allowed('udp',$ccdomain)) ||
611: (($userenv{'domcoord.author'} eq 'blocked') &&
612: (($env{'user.name'} ne $ccuname) || ($env{'user.domain'} ne $ccdomain)))) {
1.470 raeburn 613: $output .=
614: &Apache::loncommon::start_data_table_row()."\n".
615: '<td'.$colspan.'>';
616: if (@possmanagers) {
617: $output .= &mt('Select manager(s)').': ';
618: foreach my $user (@possmanagers) {
619: my $checked;
620: if (grep(/^\Q$user\E$/,@custommanagers)) {
621: $checked = ' checked="checked"';
622: }
623: $output .= '<span style="LC_nobreak"><label>'.
624: '<input type="checkbox" name="custommanagers" '.
625: 'value="'.&HTML::Entities::encode($user,'\'<>"&').'"'.$checked.' />'.
626: $user.'</label></span> ';
627: }
628: } else {
629: $output .= &mt('No co-author roles assignable as manager');
630: }
631: $output .= '</td>'.
632: &Apache::loncommon::end_data_table_row()."\n";
1.306 raeburn 633: }
634: } else {
635: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 636: my $name = $context.'_'.$item;
1.470 raeburn 637: $onclick = 'onclick="javascript:toggleCustom(this.form,'."'customtext_$item','custom$item'".');" ';
1.306 raeburn 638: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 639: '<input type="radio" name="'.$name.'"'.
1.470 raeburn 640: ' value="1" '.$tool_on.$onclick.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 641: '<input type="radio" name="'.$name.'" value="0" '.
1.470 raeburn 642: $tool_off.$onclick.'/>'.&mt('Off').'</label></span>';
643: $custradio = '<span id="customtext_'.$item.'"'.$customsty.' class="LC_nobreak">'.
644: '--'.$lt{'cusa'}.': '.$custdisp.'</span>';
645: }
646: unless (($item eq 'editors') || ($item eq 'managers')) {
647: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
648: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
649: &Apache::loncommon::end_data_table_row()."\n";
650: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
651: $output .=
1.275 raeburn 652: &Apache::loncommon::start_data_table_row()."\n".
1.470 raeburn 653: '<td><span class="LC_nobreak">'.
1.306 raeburn 654: $lt{'chse'}.': <label>'.
1.275 raeburn 655: '<input type="radio" name="custom'.$item.'" value="0" '.
1.470 raeburn 656: $cust_off.$onclick.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
1.306 raeburn 657: '<label><input type="radio" name="custom'.$item.'" value="1" '.
1.470 raeburn 658: $cust_on.$onclick.'/>'.$lt{'uscu'}.'</label></span>';
659: if ($colspan) {
660: $output .= '</td><td>';
661: }
662: $output .= $custradio.'</td>'.
663: &Apache::loncommon::end_data_table_row()."\n";
664: }
1.418 raeburn 665: }
1.275 raeburn 666: }
667: return $output;
668: }
669:
1.300 raeburn 670: sub coursereq_externaluser {
671: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 672: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 673: my %lt = &Apache::lonlocal::texthash (
674: 'official' => 'Can request creation of official courses',
675: 'unofficial' => 'Can request creation of unofficial courses',
676: 'community' => 'Can request creation of communities',
1.384 raeburn 677: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 678: 'placement' => 'Can request creation of placement tests',
1.300 raeburn 679: );
680:
681: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
682: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.411 raeburn 683: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
684: 'reqcrsotherdom.placement');
685: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 686: @options = ('approval','validate','autolimit');
1.306 raeburn 687: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
688: my $optregex = join('|',@options);
689: my %reqtitles = &courserequest_titles();
1.300 raeburn 690: foreach my $item (@usertools) {
1.306 raeburn 691: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 692: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
693: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 694: foreach my $req (@curr) {
695: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
696: $curroption = $1;
697: $currlimit = $2;
698: last;
1.306 raeburn 699: }
700: }
1.314 raeburn 701: if (!$curroption) {
702: $curroption = 'norequest';
703: $tooloff = ' checked="checked"';
704: }
1.306 raeburn 705: } else {
706: $curroption = 'norequest';
707: $tooloff = ' checked="checked"';
708: }
709: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 710: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
711: '<table><tr><td valign="top">'."\n".
1.306 raeburn 712: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 713: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
714: '</label></td>';
1.306 raeburn 715: foreach my $option (@options) {
716: if ($option eq 'validate') {
717: my $canvalidate = 0;
718: if (ref($validations{$item}) eq 'HASH') {
719: if ($validations{$item}{'_external_'}) {
720: $canvalidate = 1;
721: }
722: }
723: next if (!$canvalidate);
724: }
725: my $checked = '';
726: if ($option eq $curroption) {
727: $checked = ' checked="checked"';
728: }
1.314 raeburn 729: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 730: '<input type="radio" name="reqcrsotherdom_'.$item.
731: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 732: $reqtitles{$option}.'</label>';
1.306 raeburn 733: if ($option eq 'autolimit') {
1.314 raeburn 734: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 735: $item.'_limit" size="1" '.
1.314 raeburn 736: 'value="'.$currlimit.'" /></span>'.
737: '<br />'.$reqtitles{'unlimited'};
738: } else {
739: $output .= '</span>';
1.300 raeburn 740: }
1.314 raeburn 741: $output .= '</td>';
1.300 raeburn 742: }
1.314 raeburn 743: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 744: &Apache::loncommon::end_data_table_row()."\n";
745: }
746: return $output;
747: }
748:
1.362 raeburn 749: sub domainrole_req {
750: my ($ccuname,$ccdomain) = @_;
751: return '<br /><h3>'.
1.470 raeburn 752: &mt('Can Request Assignment of Domain Roles?').
1.362 raeburn 753: '</h3>'."\n".
754: &Apache::loncommon::start_data_table().
755: &build_tools_display($ccuname,$ccdomain,
756: 'requestauthor').
757: &Apache::loncommon::end_data_table();
758: }
759:
1.470 raeburn 760: sub authoring_defaults {
761: my ($ccuname,$ccdomain) = @_;
762: return '<br /><h3>'.
763: &mt('Authoring Space defaults (if role assigned)').
764: '</h3>'."\n".
765: &Apache::loncommon::start_data_table().
766: &build_tools_display($ccuname,$ccdomain,
767: 'authordefaults').
768: &user_quotas($ccuname,$ccdomain,'author').
769: &Apache::loncommon::end_data_table();
770: }
771:
1.306 raeburn 772: sub courserequest_titles {
773: my %titles = &Apache::lonlocal::texthash (
774: official => 'Official',
775: unofficial => 'Unofficial',
776: community => 'Communities',
1.384 raeburn 777: textbook => 'Textbook',
1.411 raeburn 778: placement => 'Placement Tests',
1.449 raeburn 779: lti => 'LTI Provider',
1.306 raeburn 780: norequest => 'Not allowed',
1.309 raeburn 781: approval => 'Approval by Dom. Coord.',
1.306 raeburn 782: validate => 'With validation',
783: autolimit => 'Numerical limit',
1.314 raeburn 784: unlimited => '(blank for unlimited)',
1.306 raeburn 785: );
786: return %titles;
787: }
788:
789: sub courserequest_display {
790: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 791: approval => 'Yes, need approval',
1.306 raeburn 792: validate => 'Yes, with validation',
793: norequest => 'No',
794: );
795: return %titles;
796: }
797:
1.362 raeburn 798: sub requestauthor_titles {
799: my %titles = &Apache::lonlocal::texthash (
800: norequest => 'Not allowed',
801: approval => 'Approval by Dom. Coord.',
802: automatic => 'Automatic approval',
803: );
804: return %titles;
805:
806: }
807:
808: sub requestauthor_display {
809: my %titles = &Apache::lonlocal::texthash (
810: approval => 'Yes, need approval',
811: automatic => 'Yes, automatic approval',
812: norequest => 'No',
813: );
814: return %titles;
815: }
816:
1.383 raeburn 817: sub requestchange_display {
818: my %titles = &Apache::lonlocal::texthash (
819: approval => "availability set to 'on' (approval required)",
820: automatic => "availability set to 'on' (automatic approval)",
821: norequest => "availability set to 'off'",
822: );
823: return %titles;
824: }
825:
1.362 raeburn 826: sub curr_requestauthor {
827: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
828: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
829: if ($uname eq '' || $udom eq '') {
830: $uname = $env{'user.name'};
831: $udom = $env{'user.domain'};
832: $isadv = $env{'user.adv'};
833: }
834: my (%userenv,%settings,$val);
835: my @options = ('automatic','approval');
836: %userenv =
837: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
838: if ($userenv{'requestauthor'}) {
839: $val = $userenv{'requestauthor'};
840: @{$inststatuses} = ('_custom_');
841: } else {
842: my %alltasks;
843: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
844: %settings = %{$domconfig->{'requestauthor'}};
845: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
846: $val = $settings{'_LC_adv'};
847: @{$inststatuses} = ('_LC_adv_');
848: } else {
849: if ($userenv{'inststatus'} ne '') {
850: @{$inststatuses} = split(',',$userenv{'inststatus'});
851: } else {
852: @{$inststatuses} = ('default');
853: }
854: foreach my $status (@{$inststatuses}) {
855: if (exists($settings{$status})) {
856: my $value = $settings{$status};
857: next unless ($value);
858: unless (exists($alltasks{$value})) {
859: if (ref($alltasks{$value}) eq 'ARRAY') {
860: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
861: push(@{$alltasks{$value}},$status);
862: }
863: } else {
864: @{$alltasks{$value}} = ($status);
865: }
866: }
867: }
868: }
869: foreach my $option (@options) {
870: if ($alltasks{$option}) {
871: $val = $option;
872: last;
873: }
874: }
875: }
876: }
877: }
878: return $val;
879: }
880:
1.2 www 881: # =================================================================== Phase one
1.1 www 882:
1.42 matthew 883: sub print_username_entry_form {
1.439 raeburn 884: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
885: $permission) = @_;
1.101 albertel 886: my $defdom=$env{'request.role.domain'};
1.160 raeburn 887: my $formtoset = 'crtuser';
888: if (exists($env{'form.startrolename'})) {
889: $formtoset = 'docustom';
890: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 891: } elsif ($env{'form.origform'} eq 'crtusername') {
892: $formtoset = $env{'form.origform'};
1.160 raeburn 893: }
894:
895: my ($jsback,$elements) = &crumb_utilities();
896:
897: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 898: '<script type="text/javascript">'."\n".
1.301 bisitz 899: '// <![CDATA['."\n".
900: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
901: '// ]]>'."\n".
1.162 raeburn 902: '</script>'."\n";
1.160 raeburn 903:
1.324 raeburn 904: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
905: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
906: && (&Apache::lonnet::allowed('mcr','/'))) {
907: $jscript .= &customrole_javascript();
908: }
1.224 raeburn 909: my $helpitem = 'Course_Change_Privileges';
910: if ($env{'form.action'} eq 'custom') {
1.439 raeburn 911: if ($context eq 'course') {
912: $helpitem = 'Course_Editing_Custom_Roles';
913: } elsif ($context eq 'domain') {
914: $helpitem = 'Domain_Editing_Custom_Roles';
915: }
1.224 raeburn 916: } elsif ($env{'form.action'} eq 'singlestudent') {
917: $helpitem = 'Course_Add_Student';
1.416 raeburn 918: } elsif ($env{'form.action'} eq 'accesslogs') {
919: $helpitem = 'Domain_User_Access_Logs';
1.439 raeburn 920: } elsif ($context eq 'author') {
921: $helpitem = 'Author_Change_Privileges';
922: } elsif ($context eq 'domain') {
923: if ($permission->{'cusr'}) {
924: $helpitem = 'Domain_Change_Privileges';
925: } elsif ($permission->{'view'}) {
926: $helpitem = 'Domain_View_Privileges';
927: } else {
928: undef($helpitem);
929: }
1.224 raeburn 930: }
1.422 raeburn 931: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 932: if ($env{'form.action'} eq 'custom') {
933: push(@{$brcrum},
934: {href=>"javascript:backPage(document.crtuser)",
935: text=>"Pick custom role",
936: help => $helpitem,}
937: );
938: } else {
939: push (@{$brcrum},
940: {href => "javascript:backPage(document.crtuser)",
941: text => $breadcrumb_text{'search'},
942: help => $helpitem,
943: faq => 282,
944: bug => 'Instructor Interface',}
945: );
946: }
947: my %loaditems = (
948: 'onload' => "javascript:setFormElements(document.$formtoset)",
949: );
950: my $args = {bread_crumbs => $brcrum,
951: bread_crumbs_component => 'User Management',
952: add_entries => \%loaditems,};
953: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
954:
1.71 sakharuk 955: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 956: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 957: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 958: 'srad' => 'Search for a user and modify/add user information or roles',
1.422 raeburn 959: 'srvu' => 'Search for a user and view user information and roles',
1.416 raeburn 960: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 961: 'usr' => "Username",
962: 'dom' => "Domain",
1.324 raeburn 963: 'ecrp' => "Define or Edit Custom Role",
964: 'nr' => "role name",
1.282 schafran 965: 'cre' => "Next",
1.71 sakharuk 966: );
1.351 raeburn 967:
1.214 raeburn 968: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 969: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 970: my $newroletext = &mt('Define new custom role:');
971: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
972: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
973: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
974: '<h3>'.$lt{'ecrp'}.'</h3>'.
975: &Apache::loncommon::start_data_table().
976: &Apache::loncommon::start_data_table_row().
977: '<td>');
978: if (keys(%existingroles) > 0) {
979: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
980: } else {
981: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
982: }
983: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
984: &Apache::loncommon::end_data_table_row());
985: if (keys(%existingroles) > 0) {
986: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
987: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
988: &mt('View/Modify existing role:').'</b></label></td>'.
989: '<td align="center"><br />'.
990: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 991: '<option value="" selected="selected">'.
1.324 raeburn 992: &mt('Select'));
993: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 994: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 995: }
996: $r->print('</select>'.
997: '</td>'.
998: &Apache::loncommon::end_data_table_row());
999: }
1000: $r->print(&Apache::loncommon::end_data_table().'<p>'.
1001: '<input name="customeditor" type="submit" value="'.
1002: $lt{'cre'}.'" /></p>'.
1003: '</form>');
1.190 raeburn 1004: }
1.213 raeburn 1005: } else {
1.229 raeburn 1006: my $actiontext = $lt{'srad'};
1.436 raeburn 1007: my $fixeddom;
1.213 raeburn 1008: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1009: if ($crstype eq 'Community') {
1010: $actiontext = $lt{'srme'};
1011: } else {
1012: $actiontext = $lt{'srst'};
1013: }
1.416 raeburn 1014: } elsif ($env{'form.action'} eq 'accesslogs') {
1.417 raeburn 1015: $actiontext = $lt{'srva'};
1.436 raeburn 1016: $fixeddom = 1;
1.422 raeburn 1017: } elsif (($env{'form.action'} eq 'singleuser') &&
1018: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
1019: $actiontext = $lt{'srvu'};
1.439 raeburn 1020: $fixeddom = 1;
1.213 raeburn 1021: }
1.324 raeburn 1022: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 1023: if ($env{'form.origform'} ne 'crtusername') {
1.415 raeburn 1024: if ($response) {
1025: $r->print("\n<div>$response</div>".
1026: '<br clear="all" />');
1027: }
1.213 raeburn 1028: }
1.436 raeburn 1029: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 1030: }
1.110 albertel 1031: }
1032:
1.324 raeburn 1033: sub customrole_javascript {
1034: my $js = <<"END";
1035: <script type="text/javascript">
1036: // <![CDATA[
1037:
1038: function setCustomFields() {
1039: if (document.docustom.customroleaction.length > 0) {
1040: for (var i=0; i<document.docustom.customroleaction.length; i++) {
1041: if (document.docustom.customroleaction[i].checked) {
1042: if (document.docustom.customroleaction[i].value == 'new') {
1043: document.docustom.rolename.selectedIndex = 0;
1044: } else {
1045: document.docustom.newrolename.value = '';
1046: }
1047: }
1048: }
1049: }
1050: return;
1051: }
1052:
1053: function setCustomAction(caller) {
1054: if (document.docustom.customroleaction.length > 0) {
1055: for (var i=0; i<document.docustom.customroleaction.length; i++) {
1056: if (document.docustom.customroleaction[i].value == caller) {
1057: document.docustom.customroleaction[i].checked = true;
1058: }
1059: }
1060: }
1061: setCustomFields();
1062: return;
1063: }
1064:
1065: // ]]>
1066: </script>
1067: END
1068: return $js;
1069: }
1070:
1.160 raeburn 1071: sub entry_form {
1.416 raeburn 1072: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 1073: my ($usertype,$inexact);
1.214 raeburn 1074: if (ref($srch) eq 'HASH') {
1075: if (($srch->{'srchin'} eq 'dom') &&
1076: ($srch->{'srchby'} eq 'uname') &&
1077: ($srch->{'srchtype'} eq 'exact') &&
1078: ($srch->{'srchdomain'} ne '') &&
1079: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 1080: my (%curr_rules,%got_rules);
1.214 raeburn 1081: my ($rules,$ruleorder) =
1082: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 1083: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 1084: } else {
1085: $inexact = 1;
1.214 raeburn 1086: }
1.207 raeburn 1087: }
1.438 raeburn 1088: my ($cancreate,$noinstd);
1089: if ($env{'form.action'} eq 'accesslogs') {
1090: $noinstd = 1;
1091: } else {
1092: $cancreate =
1093: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1094: }
1.412 raeburn 1095: my ($userpicker,$cansearch) =
1.179 raeburn 1096: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.438 raeburn 1097: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 1098: my $srchbutton = &mt('Search');
1.229 raeburn 1099: if ($env{'form.action'} eq 'singlestudent') {
1100: $srchbutton = &mt('Search and Enroll');
1.416 raeburn 1101: } elsif ($env{'form.action'} eq 'accesslogs') {
1102: $srchbutton = &mt('Search');
1.229 raeburn 1103: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
1104: $srchbutton = &mt('Search or Add New User');
1105: }
1.412 raeburn 1106: my $output;
1107: if ($cansearch) {
1108: $output = <<"ENDBLOCK";
1.160 raeburn 1109: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 1110: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 1111: <input type="hidden" name="phase" value="get_user_info" />
1112: $userpicker
1.179 raeburn 1113: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 1114: </form>
1.207 raeburn 1115: ENDBLOCK
1.412 raeburn 1116: } else {
1117: $output = '<p>'.$userpicker.'</p>';
1118: }
1.422 raeburn 1119: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
1.430 raeburn 1120: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1.422 raeburn 1121: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 1122: my $defdom=$env{'request.role.domain'};
1.446 raeburn 1123: my ($trusted,$untrusted);
1.444 raeburn 1124: if ($context eq 'course') {
1.446 raeburn 1125: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.444 raeburn 1126: } elsif ($context eq 'author') {
1.446 raeburn 1127: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.444 raeburn 1128: } elsif ($context eq 'domain') {
1.446 raeburn 1129: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.444 raeburn 1130: }
1.446 raeburn 1131: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain',undef,undef,undef,$trusted,$untrusted);
1.207 raeburn 1132: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 1133: 'enro' => 'Enroll one student',
1.318 raeburn 1134: 'enrm' => 'Enroll one member',
1.229 raeburn 1135: 'admo' => 'Add/modify a single user',
1136: 'crea' => 'create new user if required',
1137: 'uskn' => "username is known",
1.207 raeburn 1138: 'crnu' => 'Create a new user',
1139: 'usr' => 'Username',
1140: 'dom' => 'in domain',
1.229 raeburn 1141: 'enrl' => 'Enroll',
1142: 'cram' => 'Create/Modify user',
1.207 raeburn 1143: );
1.229 raeburn 1144: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
1145: my ($title,$buttontext,$showresponse);
1.318 raeburn 1146: if ($env{'form.action'} eq 'singlestudent') {
1147: if ($crstype eq 'Community') {
1148: $title = $lt{'enrm'};
1149: } else {
1150: $title = $lt{'enro'};
1151: }
1.229 raeburn 1152: $buttontext = $lt{'enrl'};
1153: } else {
1154: $title = $lt{'admo'};
1155: $buttontext = $lt{'cram'};
1156: }
1157: if ($cancreate) {
1158: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
1159: } else {
1160: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
1161: }
1162: if ($env{'form.origform'} eq 'crtusername') {
1163: $showresponse = $responsemsg;
1164: }
1.207 raeburn 1165: $output .= <<"ENDDOCUMENT";
1.229 raeburn 1166: <br />
1.207 raeburn 1167: <form action="/adm/createuser" method="post" name="crtusername">
1168: <input type="hidden" name="action" value="$env{'form.action'}" />
1169: <input type="hidden" name="phase" value="createnewuser" />
1170: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 1171: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 1172: <input type="hidden" name="srchin" value="dom" />
1173: <input type="hidden" name="forcenewuser" value="1" />
1174: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 1175: <h3>$title</h3>
1176: $showresponse
1.207 raeburn 1177: <table>
1178: <tr>
1179: <td>$lt{'usr'}:</td>
1180: <td><input type="text" size="15" name="srchterm" /></td>
1181: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 1182: <td> $sellink </td>
1183: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 1184: </tr>
1185: </table>
1186: </form>
1.160 raeburn 1187: ENDDOCUMENT
1.207 raeburn 1188: }
1.160 raeburn 1189: return $output;
1190: }
1.110 albertel 1191:
1192: sub user_modification_js {
1.113 raeburn 1193: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
1194:
1.110 albertel 1195: return <<END;
1196: <script type="text/javascript" language="Javascript">
1.301 bisitz 1197: // <![CDATA[
1.314 raeburn 1198:
1.110 albertel 1199: $pjump_def
1200: $dc_setcourse_code
1201:
1202: function dateset() {
1203: eval("document.cu."+document.cu.pres_marker.value+
1204: ".value=document.cu.pres_value.value");
1.359 www 1205: modalWindow.close();
1.110 albertel 1206: }
1207:
1.113 raeburn 1208: $nondc_setsection_code
1.301 bisitz 1209: // ]]>
1.110 albertel 1210: </script>
1211: END
1.2 www 1212: }
1213:
1214: # =================================================================== Phase two
1.160 raeburn 1215: sub print_user_selection_page {
1.351 raeburn 1216: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 1217: my @fields = ('username','domain','lastname','firstname','permanentemail');
1218: my $sortby = $env{'form.sortby'};
1219:
1220: if (!grep(/^\Q$sortby\E$/,@fields)) {
1221: $sortby = 'lastname';
1222: }
1223:
1224: my ($jsback,$elements) = &crumb_utilities();
1225:
1226: my $jscript = (<<ENDSCRIPT);
1227: <script type="text/javascript">
1.301 bisitz 1228: // <![CDATA[
1.160 raeburn 1229: function pickuser(uname,udom) {
1230: document.usersrchform.seluname.value=uname;
1231: document.usersrchform.seludom.value=udom;
1232: document.usersrchform.phase.value="userpicked";
1233: document.usersrchform.submit();
1234: }
1235:
1236: $jsback
1.301 bisitz 1237: // ]]>
1.160 raeburn 1238: </script>
1239: ENDSCRIPT
1240:
1241: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1242: 'usrch' => "User Search to add/modify roles",
1243: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1244: 'memsrch' => "User Search to enroll member",
1.416 raeburn 1245: 'srcva' => "Search for a user and view access log information",
1.422 raeburn 1246: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1247: 'usel' => "Select a user to add/modify roles",
1.422 raeburn 1248: 'suvr' => "Select a user to view roles",
1.318 raeburn 1249: 'stusel' => "Select a user to enroll as a student",
1250: 'memsel' => "Select a user to enroll as a member",
1.416 raeburn 1251: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1252: 'username' => "username",
1253: 'domain' => "domain",
1254: 'lastname' => "last name",
1255: 'firstname' => "first name",
1256: 'permanentemail' => "permanent e-mail",
1257: );
1.302 raeburn 1258: if ($context eq 'requestcrs') {
1259: $r->print('<div>');
1260: } else {
1.422 raeburn 1261: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1262: my $helpitem;
1263: if ($env{'form.action'} eq 'singleuser') {
1264: $helpitem = 'Course_Change_Privileges';
1265: } elsif ($env{'form.action'} eq 'singlestudent') {
1266: $helpitem = 'Course_Add_Student';
1.439 raeburn 1267: } elsif ($context eq 'author') {
1268: $helpitem = 'Author_Change_Privileges';
1269: } elsif ($context eq 'domain') {
1270: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1271: }
1272: push (@{$brcrum},
1273: {href => "javascript:backPage(document.usersrchform,'','')",
1274: text => $breadcrumb_text{'search'},
1275: faq => 282,
1276: bug => 'Instructor Interface',},
1277: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1278: text => $breadcrumb_text{'userpicked'},
1279: faq => 282,
1280: bug => 'Instructor Interface',
1281: help => $helpitem}
1282: );
1283: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1284: if ($env{'form.action'} eq 'singleuser') {
1.422 raeburn 1285: my $readonly;
1286: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1287: $readonly = 1;
1288: $r->print("<b>$lt{'usrvu'}</b><br />");
1289: } else {
1290: $r->print("<b>$lt{'usrch'}</b><br />");
1291: }
1.318 raeburn 1292: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.422 raeburn 1293: if ($readonly) {
1294: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1295: } else {
1296: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1297: }
1.302 raeburn 1298: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1299: $r->print($jscript."<b>");
1300: if ($crstype eq 'Community') {
1301: $r->print($lt{'memsrch'});
1302: } else {
1303: $r->print($lt{'stusrch'});
1304: }
1305: $r->print("</b><br />");
1306: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1307: $r->print('</form><h3>');
1308: if ($crstype eq 'Community') {
1309: $r->print($lt{'memsel'});
1310: } else {
1311: $r->print($lt{'stusel'});
1312: }
1313: $r->print('</h3>');
1.416 raeburn 1314: } elsif ($env{'form.action'} eq 'accesslogs') {
1315: $r->print("<b>$lt{'srcva'}</b><br />");
1.438 raeburn 1316: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.416 raeburn 1317: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1318: }
1.179 raeburn 1319: }
1.380 bisitz 1320: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1321: &Apache::loncommon::start_data_table()."\n".
1322: &Apache::loncommon::start_data_table_header_row()."\n".
1323: ' <th> </th>'."\n");
1324: foreach my $field (@fields) {
1325: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1326: "'".$field."'".';document.usersrchform.submit();">'.
1327: $lt{$field}.'</a></th>'."\n");
1328: }
1329: $r->print(&Apache::loncommon::end_data_table_header_row());
1330:
1331: my @sorted_users = sort {
1.167 albertel 1332: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1333: ||
1.167 albertel 1334: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1335: ||
1336: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1337: ||
1338: lc($a) cmp lc($b)
1.160 raeburn 1339: } (keys(%$srch_results));
1340:
1341: foreach my $user (@sorted_users) {
1342: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1343: my $onclick;
1344: if ($context eq 'requestcrs') {
1.314 raeburn 1345: $onclick =
1.302 raeburn 1346: 'onclick="javascript:gochoose('."'$uname','$udom',".
1347: "'$srch_results->{$user}->{firstname}',".
1348: "'$srch_results->{$user}->{lastname}',".
1349: "'$srch_results->{$user}->{permanentemail}'".');"';
1350: } else {
1.314 raeburn 1351: $onclick =
1.302 raeburn 1352: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1353: }
1.160 raeburn 1354: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1355: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1356: $onclick.' /></td>'.
1.160 raeburn 1357: '<td><tt>'.$uname.'</tt></td>'.
1358: '<td><tt>'.$udom.'</tt></td>');
1359: foreach my $field ('lastname','firstname','permanentemail') {
1360: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1361: }
1362: $r->print(&Apache::loncommon::end_data_table_row());
1363: }
1364: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1365: if (ref($srcharray) eq 'ARRAY') {
1366: foreach my $item (@{$srcharray}) {
1367: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1368: }
1369: }
1.160 raeburn 1370: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1371: ' <input type="hidden" name="seluname" value="" />'."\n".
1372: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1373: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1374: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1375: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1376: if ($context eq 'requestcrs') {
1377: $r->print($opener_elements.'</form></div>');
1378: } else {
1.351 raeburn 1379: $r->print($response.'</form>');
1.302 raeburn 1380: }
1.160 raeburn 1381: }
1382:
1383: sub print_user_query_page {
1.351 raeburn 1384: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1385: # FIXME - this is for a network-wide name search (similar to catalog search)
1386: # To use frames with similar behavior to catalog/portfolio search.
1387: # To be implemented.
1388: return;
1389: }
1390:
1.42 matthew 1391: sub print_user_modification_page {
1.375 raeburn 1392: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1393: $brcrum,$showcredits) = @_;
1.185 raeburn 1394: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1395: my $usermsg = &mt('No username and/or domain provided.');
1396: $env{'form.phase'} = '';
1.439 raeburn 1397: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1398: $permission);
1.58 www 1399: return;
1400: }
1.213 raeburn 1401: my ($form,$formname);
1402: if ($env{'form.action'} eq 'singlestudent') {
1403: $form = 'document.enrollstudent';
1404: $formname = 'enrollstudent';
1405: } else {
1406: $form = 'document.cu';
1407: $formname = 'cu';
1408: }
1.188 raeburn 1409: my %abv_auth = &auth_abbrev();
1.227 raeburn 1410: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1411: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1412: if ($uhome eq 'no_host') {
1.215 raeburn 1413: my $usertype;
1414: my ($rules,$ruleorder) =
1415: &Apache::lonnet::inst_userrules($ccdomain,'username');
1416: $usertype =
1.353 raeburn 1417: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1418: \%curr_rules,\%got_rules);
1.215 raeburn 1419: my $cancreate =
1420: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1421: $usertype);
1422: if (!$cancreate) {
1.292 bisitz 1423: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1424: my %usertypetext = (
1425: official => 'institutional',
1426: unofficial => 'non-institutional',
1427: );
1428: my $response;
1429: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1430: $response = '<span class="LC_warning">'.
1431: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1432: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1433: '</span><br />';
1434: }
1.292 bisitz 1435: $response .= '<p class="LC_warning">'
1436: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.418 raeburn 1437: .' ';
1438: if ($context eq 'domain') {
1439: $response .= &mt('Please contact a [_1] for assistance.',
1440: &Apache::lonnet::plaintext('dc'));
1441: } else {
1442: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1443: ,'<a href="'.$helplink.'">','</a>');
1444: }
1445: $response .= '</p><br />';
1.215 raeburn 1446: $env{'form.phase'} = '';
1.439 raeburn 1447: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1448: $permission);
1.215 raeburn 1449: return;
1450: }
1.188 raeburn 1451: $newuser = 1;
1.193 raeburn 1452: my $checkhash;
1453: my $checks = { 'username' => 1 };
1.196 raeburn 1454: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1455: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1456: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1457: if (ref($alerts{'username'}) eq 'HASH') {
1458: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1459: my $domdesc =
1.193 raeburn 1460: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1461: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1462: my $userchkmsg;
1463: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1464: $userchkmsg =
1465: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1466: $domdesc,1).
1467: &Apache::loncommon::user_rule_formats($ccdomain,
1468: $domdesc,$curr_rules{$ccdomain}{'username'},
1469: 'username');
1.196 raeburn 1470: }
1.215 raeburn 1471: $env{'form.phase'} = '';
1.439 raeburn 1472: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1473: $permission);
1.196 raeburn 1474: return;
1.215 raeburn 1475: }
1.193 raeburn 1476: }
1.185 raeburn 1477: }
1.187 raeburn 1478: } else {
1.188 raeburn 1479: $newuser = 0;
1.185 raeburn 1480: }
1.160 raeburn 1481: if ($response) {
1.215 raeburn 1482: $response = '<br />'.$response;
1.160 raeburn 1483: }
1.149 raeburn 1484:
1.52 matthew 1485: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1486: my $dc_setcourse_code = '';
1.119 raeburn 1487: my $nondc_setsection_code = '';
1.112 albertel 1488: my %loaditem;
1.114 albertel 1489:
1.216 raeburn 1490: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1491:
1.470 raeburn 1492: my $js = &validation_javascript($context,$ccdomain,$pjump_def,
1493: $crstype,$groupslist,$newuser,
1494: $formname,\%loaditem,$permission);
1.422 raeburn 1495: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1496: my $helpitem = 'Course_Change_Privileges';
1497: if ($env{'form.action'} eq 'singlestudent') {
1498: $helpitem = 'Course_Add_Student';
1.439 raeburn 1499: } elsif ($context eq 'author') {
1500: $helpitem = 'Author_Change_Privileges';
1501: } elsif ($context eq 'domain') {
1502: $helpitem = 'Domain_Change_Privileges';
1.470 raeburn 1503: $js .= &set_custom_js();
1.224 raeburn 1504: }
1.351 raeburn 1505: push (@{$brcrum},
1506: {href => "javascript:backPage($form)",
1507: text => $breadcrumb_text{'search'},
1508: faq => 282,
1509: bug => 'Instructor Interface',});
1510: if ($env{'form.phase'} eq 'userpicked') {
1511: push(@{$brcrum},
1512: {href => "javascript:backPage($form,'get_user_info','select')",
1513: text => $breadcrumb_text{'userpicked'},
1514: faq => 282,
1515: bug => 'Instructor Interface',});
1516: }
1517: push(@{$brcrum},
1518: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1519: text => $breadcrumb_text{'modify'},
1520: faq => 282,
1521: bug => 'Instructor Interface',
1522: help => $helpitem});
1523: my $args = {'add_entries' => \%loaditem,
1524: 'bread_crumbs' => $brcrum,
1525: 'bread_crumbs_component' => 'User Management'};
1526: if ($env{'form.popup'}) {
1527: $args->{'no_nav_bar'} = 1;
1528: }
1.470 raeburn 1529: if (($context eq 'domain') && ($env{'request.role.domain'} eq $ccdomain)) {
1530: my @toggles;
1531: if (&Apache::lonnet::allowed('cau',$ccdomain)) {
1532: my ($isadv,$isauthor) =
1533: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1534: unless ($isauthor) {
1535: push(@toggles,'requestauthor');
1536: }
1.478 raeburn 1537: push(@toggles,('webdav','editors','archive'));
1.470 raeburn 1538: }
1539: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1540: push(@toggles,('aboutme','blog','portfolio','portaccess','timezone'));
1541: }
1542: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1543: push(@toggles,('official','unofficial','community','textbook','placement','lti'));
1544: }
1545: if (@toggles) {
1546: my $onload;
1547: foreach my $item (@toggles) {
1548: $onload .= "toggleCustom(document.cu,'customtext_$item','custom$item');";
1549: }
1550: $args->{'add_entries'} = {
1551: 'onload' => $onload,
1552: };
1553: }
1554: }
1.351 raeburn 1555: my $start_page =
1556: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1557:
1.25 matthew 1558: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1559: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1560: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1561: <input type="hidden" name="ccuname" value="$ccuname" />
1562: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1563: <input type="hidden" name="pres_value" value="" />
1564: <input type="hidden" name="pres_type" value="" />
1565: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1566: ENDFORMINFO
1.375 raeburn 1567: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1568: if ($context eq 'course') {
1569: $inccourses{$env{'request.course.id'}}=1;
1570: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1571: if ($showcredits) {
1572: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1573: }
1.329 raeburn 1574: } elsif ($context eq 'author') {
1575: $roledom = $env{'request.role.domain'};
1576: } elsif ($context eq 'domain') {
1577: foreach my $key (keys(%env)) {
1578: $roledom = $env{'request.role.domain'};
1579: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1580: $inccourses{$1.'_'.$2}=1;
1581: }
1582: }
1583: } else {
1584: foreach my $key (keys(%env)) {
1585: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1586: $inccourses{$1.'_'.$2}=1;
1587: }
1.2 www 1588: }
1.24 matthew 1589: }
1.389 bisitz 1590: my $title = '';
1.470 raeburn 1591: my $need_quota_js;
1.216 raeburn 1592: if ($newuser) {
1.427 raeburn 1593: my ($portfolioform,$domroleform);
1.267 raeburn 1594: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1595: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1596: # Current user has quota or user tools modification privileges
1.470 raeburn 1597: $portfolioform = '<br /><h3>'.
1598: &mt('User Tools').
1599: '</h3>'."\n".
1600: &Apache::loncommon::start_data_table();
1601: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1602: $portfolioform .= &build_tools_display($ccuname,$ccdomain,'tools');
1603: }
1604: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
1605: $portfolioform .= &user_quotas($ccuname,$ccdomain,'portfolio');
1606: $need_quota_js = 1;
1607: }
1608: $portfolioform .= &Apache::loncommon::end_data_table();
1.134 raeburn 1609: }
1.383 raeburn 1610: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1611: ($ccdomain eq $env{'request.role.domain'})) {
1.470 raeburn 1612: $domroleform = &domainrole_req($ccuname,$ccdomain).
1613: &authoring_defaults($ccuname,$ccdomain);
1614: $need_quota_js = 1;
1615: }
1616: my $readonly;
1617: unless ($permission->{'cusr'}) {
1618: $readonly = 1;
1.362 raeburn 1619: }
1.470 raeburn 1620: &initialize_authen_forms($ccdomain,$formname,'','',$readonly);
1.188 raeburn 1621: my %lt=&Apache::lonlocal::texthash(
1622: 'lg' => 'Login Data',
1.190 raeburn 1623: 'hs' => "Home Server",
1.188 raeburn 1624: );
1.185 raeburn 1625: $r->print(<<ENDTITLE);
1.110 albertel 1626: $start_page
1.160 raeburn 1627: $response
1.25 matthew 1628: $forminfo
1.31 matthew 1629: <script type="text/javascript" language="Javascript">
1.301 bisitz 1630: // <![CDATA[
1.20 harris41 1631: $loginscript
1.301 bisitz 1632: // ]]>
1.31 matthew 1633: </script>
1.20 harris41 1634: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1635: ENDTITLE
1.213 raeburn 1636: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1637: if ($crstype eq 'Community') {
1.389 bisitz 1638: $title = &mt('Create New User [_1] in domain [_2] as a member',
1639: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1640: } else {
1.389 bisitz 1641: $title = &mt('Create New User [_1] in domain [_2] as a student',
1642: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1643: }
1.389 bisitz 1644: } else {
1645: $title = &mt('Create New User [_1] in domain [_2]',
1646: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1647: }
1.389 bisitz 1648: $r->print('<h2>'.$title.'</h2>'."\n");
1649: $r->print('<div class="LC_left_float">');
1.393 raeburn 1650: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1.470 raeburn 1651: $inst_results{$ccuname.':'.$ccdomain},$readonly));
1.393 raeburn 1652: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1653: my ($home_server_pick,$numlib) =
1654: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1655: 'default','hide');
1656: if ($numlib > 1) {
1657: $r->print("
1.185 raeburn 1658: <br />
1.187 raeburn 1659: $lt{'hs'}: $home_server_pick
1660: <br />");
1661: } else {
1662: $r->print($home_server_pick);
1663: }
1.304 raeburn 1664: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1665: $r->print('<br /><h3>'.
1.470 raeburn 1666: &mt('Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1667: &Apache::loncommon::start_data_table().
1668: &build_tools_display($ccuname,$ccdomain,
1669: 'requestcourses').
1670: &Apache::loncommon::end_data_table());
1671: }
1.188 raeburn 1672: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1673: $lt{'lg'}.'</h3>');
1.185 raeburn 1674: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1675: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1676: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1677: my ($rules,$ruleorder) =
1678: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1679: if (ref($rules) eq 'HASH') {
1.193 raeburn 1680: if (ref($rules->{$matchedrule}) eq 'HASH') {
1681: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1682: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1683: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1684: } else {
1.193 raeburn 1685: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1686: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1687: if ($authtype =~ /^krb(4|5)$/) {
1688: my $ver = $1;
1689: if ($authparm ne '') {
1690: $fixedauth = <<"KERB";
1691: <input type="hidden" name="login" value="krb" />
1692: <input type="hidden" name="krbver" value="$ver" />
1693: <input type="hidden" name="krbarg" value="$authparm" />
1694: KERB
1695: }
1696: } else {
1697: $fixedauth =
1698: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1699: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1700: $fixedauth .=
1701: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1702: } else {
1.273 raeburn 1703: if ($authtype eq 'int') {
1704: $varauth = '<br />'.
1.301 bisitz 1705: &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 1706: } elsif ($authtype eq 'loc') {
1707: $varauth = '<br />'.
1708: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1709: } else {
1710: $varauth =
1.185 raeburn 1711: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1712: }
1.185 raeburn 1713: }
1714: }
1715: }
1716: } else {
1.190 raeburn 1717: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1718: }
1719: }
1720: if ($authmsg) {
1721: $r->print(<<ENDAUTH);
1722: $fixedauth
1723: $authmsg
1724: $varauth
1725: ENDAUTH
1726: }
1727: } else {
1.190 raeburn 1728: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1729: }
1.427 raeburn 1730: $r->print($portfolioform.$domroleform);
1.215 raeburn 1731: if ($env{'form.action'} eq 'singlestudent') {
1732: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1733: $permission,$crstype,$ccuname,
1734: $ccdomain,$showcredits));
1.215 raeburn 1735: }
1736: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1737: } else { # user already exists
1.389 bisitz 1738: $r->print($start_page.$forminfo);
1.213 raeburn 1739: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1740: if ($crstype eq 'Community') {
1.389 bisitz 1741: $title = &mt('Enroll one member: [_1] in domain [_2]',
1742: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1743: } else {
1.389 bisitz 1744: $title = &mt('Enroll one student: [_1] in domain [_2]',
1745: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1746: }
1.213 raeburn 1747: } else {
1.418 raeburn 1748: if ($permission->{'cusr'}) {
1749: $title = &mt('Modify existing user: [_1] in domain [_2]',
1750: '"'.$ccuname.'"','"'.$ccdomain.'"');
1751: } else {
1752: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1753: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.418 raeburn 1754: }
1.213 raeburn 1755: }
1.389 bisitz 1756: $r->print('<h2>'.$title.'</h2>'."\n");
1757: $r->print('<div class="LC_left_float">');
1.393 raeburn 1758: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1759: $inst_results{$ccuname.':'.$ccdomain}));
1.430 raeburn 1760: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1.418 raeburn 1761: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.470 raeburn 1762: $r->print('<br /><h3>'.&mt('Can Request Creation of Courses/Communities in this Domain?').'</h3>'."\n");
1.450 raeburn 1763: if (($env{'request.role.domain'} eq $ccdomain) ||
1764: (&Apache::lonnet::will_trust('reqcrs',$ccdomain,$env{'request.role.domain'}))) {
1765: $r->print(&Apache::loncommon::start_data_table());
1766: if ($env{'request.role.domain'} eq $ccdomain) {
1767: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1768: } else {
1.444 raeburn 1769: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1770: $env{'request.role.domain'}));
1771: }
1.450 raeburn 1772: $r->print(&Apache::loncommon::end_data_table());
1773: } else {
1774: $r->print(&mt('Domain configuration for this domain prohibits course creation by users from domain: "[_1]"',
1775: &Apache::lonnet::domain($ccdomain,'description')));
1.300 raeburn 1776: }
1.275 raeburn 1777: }
1.199 raeburn 1778: $r->print('</div>');
1.470 raeburn 1779: my @order = ('auth','quota','tools','requestauthor','authordefaults');
1.362 raeburn 1780: my %user_text;
1781: my ($isadv,$isauthor) =
1.418 raeburn 1782: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.470 raeburn 1783: if (((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1.418 raeburn 1784: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1.470 raeburn 1785: ($env{'request.role.domain'} eq $ccdomain)) {
1786: if (!$isauthor) {
1787: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1788: }
1789: $user_text{'authordefaults'} = &authoring_defaults($ccuname,$ccdomain);
1790: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
1791: $need_quota_js = 1;
1792: }
1.362 raeburn 1793: }
1.451 raeburn 1794: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
1.267 raeburn 1795: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.418 raeburn 1796: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1797: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.470 raeburn 1798: $user_text{'quota'} = '<br /><h3>'.&mt('User Tools').'</h3>'."\n".
1799: &Apache::loncommon::start_data_table();
1800: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
1801: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1802: $user_text{'quota'} .= &build_tools_display($ccuname,$ccdomain,'tools');
1803: }
1.188 raeburn 1804: # Current user has quota modification privileges
1.470 raeburn 1805: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1806: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1807: $user_text{'quota'} .= &user_quotas($ccuname,$ccdomain,'portfolio');
1808: $need_quota_js = 1;
1809: }
1810: $user_text{'quota'} .= &Apache::loncommon::end_data_table();
1.267 raeburn 1811: }
1812: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1813: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1814: my %lt=&Apache::lonlocal::texthash(
1.470 raeburn 1815: 'dska' => "Disk quotas for user's portfolio",
1816: 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
1.267 raeburn 1817: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1818: );
1.362 raeburn 1819: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1820: <h3>$lt{'dska'}</h3>
1821: $lt{'youd'} $lt{'ichr'}: $ccdomain
1822: ENDNOPORTPRIV
1.267 raeburn 1823: }
1824: }
1825: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1826: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1827: my %lt=&Apache::lonlocal::texthash(
1828: 'utav' => "User Tools Availability",
1.470 raeburn 1829: 'yodo' => "You do not have privileges to modify Portfolio, Blog, Personal Information Page, or Time Zone settings for this user.",
1.267 raeburn 1830: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1831: );
1.362 raeburn 1832: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1833: <h3>$lt{'utav'}</h3>
1834: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1835: ENDNOTOOLSPRIV
1836: }
1.188 raeburn 1837: }
1.362 raeburn 1838: my $gotdiv = 0;
1839: foreach my $item (@order) {
1840: if ($user_text{$item} ne '') {
1841: unless ($gotdiv) {
1842: $r->print('<div class="LC_left_float">');
1843: $gotdiv = 1;
1844: }
1845: $r->print('<br />'.$user_text{$item});
1846: }
1847: }
1848: if ($env{'form.action'} eq 'singlestudent') {
1849: unless ($gotdiv) {
1850: $r->print('<div class="LC_left_float">');
1.213 raeburn 1851: }
1.375 raeburn 1852: my $credits;
1853: if ($showcredits) {
1854: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1855: if ($credits eq '') {
1856: $credits = $defaultcredits;
1857: }
1858: }
1.374 raeburn 1859: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1860: $permission,$crstype,$ccuname,
1861: $ccdomain,$showcredits));
1.374 raeburn 1862: }
1.362 raeburn 1863: if ($gotdiv) {
1864: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1865: }
1.418 raeburn 1866: my $statuses;
1867: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1868: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1869: $statuses = ['active'];
1870: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1871: ($env{'request.course.sec'} &&
1872: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1.430 raeburn 1873: $statuses = ['active'];
1.418 raeburn 1874: }
1.217 raeburn 1875: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1876: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.418 raeburn 1877: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1878: }
1.25 matthew 1879: } ## End of new user/old user logic
1.218 raeburn 1880: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1881: my $btntxt;
1882: if ($crstype eq 'Community') {
1883: $btntxt = &mt('Enroll Member');
1884: } else {
1885: $btntxt = &mt('Enroll Student');
1886: }
1887: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.418 raeburn 1888: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1889: $r->print('<div class="LC_left_float">'.
1890: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1891: my $addrolesdisplay = 0;
1892: if ($context eq 'domain' || $context eq 'author') {
1893: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1894: }
1895: if ($context eq 'domain') {
1.357 raeburn 1896: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1897: if (!$addrolesdisplay) {
1898: $addrolesdisplay = $add_domainroles;
1.2 www 1899: }
1.375 raeburn 1900: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1901: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1902: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1903: } elsif ($context eq 'author') {
1904: if ($addrolesdisplay) {
1.393 raeburn 1905: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1906: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1907: if ($newuser) {
1.301 bisitz 1908: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1909: } else {
1.461 raeburn 1910: $r->print(' onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1911: }
1.188 raeburn 1912: } else {
1.393 raeburn 1913: $r->print('</fieldset></div>'.
1914: '<div class="LC_clear_float_footer"></div>'.
1915: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1916: &mt('Back to previous page').'</a>');
1.188 raeburn 1917: }
1918: } else {
1.375 raeburn 1919: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1920: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1921: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1922: }
1.88 raeburn 1923: }
1.188 raeburn 1924: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1925: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1926: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.470 raeburn 1927: if ($need_quota_js) {
1928: $r->print(&user_quota_js());
1929: }
1.218 raeburn 1930: return;
1.2 www 1931: }
1.1 www 1932:
1.213 raeburn 1933: sub singleuser_breadcrumb {
1.422 raeburn 1934: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1935: my %breadcrumb_text;
1936: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1937: if ($crstype eq 'Community') {
1938: $breadcrumb_text{'search'} = 'Enroll a member';
1939: } else {
1940: $breadcrumb_text{'search'} = 'Enroll a student';
1941: }
1.422 raeburn 1942: $breadcrumb_text{'userpicked'} = 'Select a user';
1943: $breadcrumb_text{'modify'} = 'Set section/dates';
1.416 raeburn 1944: } elsif ($env{'form.action'} eq 'accesslogs') {
1945: $breadcrumb_text{'search'} = 'View access logs for a user';
1.422 raeburn 1946: $breadcrumb_text{'userpicked'} = 'Select a user';
1947: $breadcrumb_text{'activity'} = 'Activity';
1948: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1949: (!&Apache::lonnet::allowed('mau',$domain))) {
1950: $breadcrumb_text{'search'} = "View user's roles";
1951: $breadcrumb_text{'userpicked'} = 'Select a user';
1952: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1953: } else {
1.229 raeburn 1954: $breadcrumb_text{'search'} = 'Create/modify a user';
1.422 raeburn 1955: $breadcrumb_text{'userpicked'} = 'Select a user';
1956: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1957: }
1958: return %breadcrumb_text;
1959: }
1960:
1961: sub date_sections_select {
1.375 raeburn 1962: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1963: $showcredits) = @_;
1964: my $credits;
1965: if ($showcredits) {
1966: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1967: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1968: if ($credits eq '') {
1969: $credits = $defaultcredits;
1970: }
1971: }
1.213 raeburn 1972: my $cid = $env{'request.course.id'};
1973: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1974: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1975: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1976: undef,$formname,$permission);
1977: my $rowtitle = 'Section';
1.375 raeburn 1978: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1979: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1980: $permission,$context,'',$crstype,
1981: $showcredits,$credits);
1.213 raeburn 1982: my $output = $date_table.$secbox;
1983: return $output;
1984: }
1985:
1.216 raeburn 1986: sub validation_javascript {
1.375 raeburn 1987: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.470 raeburn 1988: $loaditem,$permission) = @_;
1.216 raeburn 1989: my $dc_setcourse_code = '';
1990: my $nondc_setsection_code = '';
1991: if ($context eq 'domain') {
1.470 raeburn 1992: if ((ref($permission) eq 'HASH') && ($permission->{'cusr'})) {
1993: my $dcdom = $env{'request.role.domain'};
1994: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1995: $dc_setcourse_code =
1996: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1997: }
1.216 raeburn 1998: } else {
1.227 raeburn 1999: my $checkauth;
2000: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
2001: $checkauth = 1;
2002: }
2003: if ($context eq 'course') {
2004: $nondc_setsection_code =
2005: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 2006: undef,$checkauth,
2007: $crstype);
1.227 raeburn 2008: }
2009: if ($checkauth) {
2010: $nondc_setsection_code .=
2011: &Apache::lonuserutils::verify_authen($formname,$context);
2012: }
1.216 raeburn 2013: }
2014: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
2015: $nondc_setsection_code,$groupslist);
2016: my ($jsback,$elements) = &crumb_utilities();
2017: $js .= "\n".
1.301 bisitz 2018: '<script type="text/javascript">'."\n".
2019: '// <![CDATA['."\n".
2020: $jsback."\n".
2021: '// ]]>'."\n".
2022: '</script>'."\n";
1.216 raeburn 2023: return $js;
2024: }
2025:
1.217 raeburn 2026: sub display_existing_roles {
1.375 raeburn 2027: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.418 raeburn 2028: $showcredits,$statuses) = @_;
1.329 raeburn 2029: my $now=time;
1.418 raeburn 2030: my $showall = 1;
2031: my ($showexpired,$showactive);
2032: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
2033: $showall = 0;
2034: if (grep(/^expired$/,@{$statuses})) {
2035: $showexpired = 1;
2036: }
2037: if (grep(/^active$/,@{$statuses})) {
2038: $showactive = 1;
2039: }
2040: if ($showexpired && $showactive) {
2041: $showall = 1;
2042: }
2043: }
1.329 raeburn 2044: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 2045: 'rer' => "Existing Roles",
2046: 'rev' => "Revoke",
2047: 'del' => "Delete",
2048: 'ren' => "Re-Enable",
2049: 'rol' => "Role",
2050: 'ext' => "Extent",
1.375 raeburn 2051: 'crd' => "Credits",
1.217 raeburn 2052: 'sta' => "Start",
2053: 'end' => "End",
2054: );
1.329 raeburn 2055: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
2056: if ($context eq 'course' || $context eq 'author') {
2057: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
2058: my %roleshash =
2059: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
2060: ['active','previous','future'],\@roles,$roledom,1);
2061: foreach my $key (keys(%roleshash)) {
2062: my ($start,$end) = split(':',$roleshash{$key});
2063: next if ($start eq '-1' || $end eq '-1');
2064: my ($rnum,$rdom,$role,$sec) = split(':',$key);
2065: if ($context eq 'course') {
2066: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
2067: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
2068: } elsif ($context eq 'author') {
1.470 raeburn 2069: if ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2070: my ($audom,$auname) = ($1,$2);
2071: next unless (($rnum eq $auname) && ($rdom eq $audom));
2072: } else {
2073: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
2074: }
1.329 raeburn 2075: }
2076: my ($newkey,$newvalue,$newrole);
2077: $newkey = '/'.$rdom.'/'.$rnum;
2078: if ($sec ne '') {
2079: $newkey .= '/'.$sec;
2080: }
2081: $newvalue = $role;
2082: if ($role =~ /^cr/) {
2083: $newrole = 'cr';
2084: } else {
2085: $newrole = $role;
2086: }
2087: $newkey .= '_'.$newrole;
2088: if ($start ne '' && $end ne '') {
2089: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 2090: } elsif ($end ne '') {
2091: $newvalue .= '_'.$end;
1.329 raeburn 2092: }
2093: $rolesdump{$newkey} = $newvalue;
2094: }
2095: } else {
1.360 raeburn 2096: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 2097: }
2098: # Build up table of user roles to allow revocation and re-enabling of roles.
2099: my ($tmp) = keys(%rolesdump);
2100: return if ($tmp =~ /^(con_lost|error)/i);
2101: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
2102: my $b1=join('_',(split('_',$b))[1,0]);
2103: return $a1 cmp $b1;
2104: } keys(%rolesdump)) {
2105: next if ($area =~ /^rolesdef/);
2106: my $envkey=$area;
2107: my $role = $rolesdump{$area};
2108: my $thisrole=$area;
2109: $area =~ s/\_\w\w$//;
2110: my ($role_code,$role_end_time,$role_start_time) =
2111: split(/_/,$role);
1.418 raeburn 2112: my $active=1;
2113: $active=0 if (($role_end_time) && ($now>$role_end_time));
2114: if ($active) {
2115: next unless($showall || $showactive);
2116: } else {
1.430 raeburn 2117: next unless($showall || $showexpired);
1.418 raeburn 2118: }
1.217 raeburn 2119: # Is this a custom role? Get role owner and title.
1.329 raeburn 2120: my ($croleudom,$croleuname,$croletitle)=
2121: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
2122: my $allowed=0;
2123: my $delallowed=0;
2124: my $sortkey=$role_code;
2125: my $class='Unknown';
1.375 raeburn 2126: my $credits='';
1.418 raeburn 2127: my $csec;
1.421 raeburn 2128: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 2129: $class='Course';
2130: my ($coursedom,$coursedir) = ($1,$2);
2131: my $cid = $1.'_'.$2;
2132: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.421 raeburn 2133: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 2134: my %coursedata=
2135: &Apache::lonnet::coursedescription($cid);
2136: if ($coursedir =~ /^$match_community$/) {
2137: $class='Community';
2138: }
2139: $sortkey.="\0$coursedom";
2140: my $carea;
2141: if (defined($coursedata{'description'})) {
2142: $carea=$coursedata{'description'}.
2143: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
2144: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
2145: $sortkey.="\0".$coursedata{'description'};
2146: } else {
2147: if ($class eq 'Community') {
2148: $carea=&mt('Unavailable community').': '.$area;
2149: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 2150: } else {
2151: $carea=&mt('Unavailable course').': '.$area;
2152: $sortkey.="\0".&mt('Unavailable course').': '.$area;
2153: }
1.329 raeburn 2154: }
2155: $sortkey.="\0$coursedir";
2156: $inccourses->{$cid}=1;
1.375 raeburn 2157: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
2158: my $defaultcredits = $coursedata{'internal.defaultcredits'};
2159: $credits =
2160: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
2161: $coursedom,$coursedir);
2162: if ($credits eq '') {
2163: $credits = $defaultcredits;
2164: }
2165: }
1.329 raeburn 2166: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
2167: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
2168: $allowed=1;
2169: }
2170: unless ($allowed) {
1.365 raeburn 2171: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 2172: if ($isowner) {
2173: if (($role_code eq 'co') && ($class eq 'Community')) {
2174: $allowed = 1;
2175: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
2176: $allowed = 1;
2177: }
1.217 raeburn 2178: }
1.329 raeburn 2179: }
2180: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
2181: (&Apache::lonnet::allowed('dro',$ccdomain))) {
2182: $delallowed=1;
2183: }
1.217 raeburn 2184: # - custom role. Needs more info, too
1.329 raeburn 2185: if ($croletitle) {
2186: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
2187: $allowed=1;
2188: $thisrole.='.'.$role_code;
1.217 raeburn 2189: }
1.329 raeburn 2190: }
1.418 raeburn 2191: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
2192: $csec = $2;
2193: $carea.='<br />'.&mt('Section: [_1]',$csec);
2194: $sortkey.="\0$csec";
1.329 raeburn 2195: if (!$allowed) {
1.418 raeburn 2196: if ($env{'request.course.sec'} eq $csec) {
2197: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 2198: $allowed = 1;
1.217 raeburn 2199: }
2200: }
2201: }
1.329 raeburn 2202: }
2203: $area=$carea;
2204: } else {
2205: $sortkey.="\0".$area;
2206: # Determine if current user is able to revoke privileges
2207: if ($area=~m{^/($match_domain)/}) {
2208: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
2209: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
2210: $allowed=1;
1.217 raeburn 2211: }
1.329 raeburn 2212: if (((&Apache::lonnet::allowed('dro',$1)) ||
2213: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
2214: ($role_code ne 'dc')) {
2215: $delallowed=1;
1.217 raeburn 2216: }
1.329 raeburn 2217: } else {
2218: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 2219: $allowed=1;
2220: }
2221: }
1.363 raeburn 2222: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 2223: $class='Authoring Space';
1.329 raeburn 2224: } elsif ($role_code eq 'su') {
2225: $class='System';
1.217 raeburn 2226: } else {
1.329 raeburn 2227: $class='Domain';
1.217 raeburn 2228: }
1.329 raeburn 2229: }
2230: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
2231: $area=~m{/($match_domain)/($match_username)};
2232: if (&Apache::lonuserutils::authorpriv($2,$1)) {
2233: $allowed=1;
1.470 raeburn 2234: } elsif (&Apache::lonuserutils::coauthorpriv($2,$1)) {
2235: $allowed=1;
1.217 raeburn 2236: } else {
1.329 raeburn 2237: $allowed=0;
1.217 raeburn 2238: }
1.329 raeburn 2239: }
2240: my $row = '';
1.418 raeburn 2241: if ($showall) {
2242: $row.= '<td>';
2243: if (($active) && ($allowed)) {
2244: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
2245: } else {
2246: if ($active) {
2247: $row.=' ';
2248: } else {
2249: $row.=&mt('expired or revoked');
2250: }
2251: }
2252: $row.='</td><td>';
2253: if ($allowed && !$active) {
2254: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
2255: } else {
2256: $row.=' ';
2257: }
2258: $row.='</td><td>';
2259: if ($delallowed) {
2260: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.217 raeburn 2261: } else {
1.418 raeburn 2262: $row.=' ';
1.217 raeburn 2263: }
1.430 raeburn 2264: $row.= '</td>';
1.329 raeburn 2265: }
2266: my $plaintext='';
2267: if (!$croletitle) {
1.375 raeburn 2268: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
2269: if (($showcredits) && ($credits ne '')) {
2270: $plaintext .= '<br/ ><span class="LC_nobreak">'.
2271: '<span class="LC_fontsize_small">'.
2272: &mt('Credits: [_1]',$credits).
2273: '</span></span>';
2274: }
1.329 raeburn 2275: } else {
2276: $plaintext=
1.395 bisitz 2277: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 2278: '"'.$croletitle.'"',
2279: '<br />',
2280: $croleuname.':'.$croleudom);
1.329 raeburn 2281: }
1.418 raeburn 2282: $row.= '<td>'.$plaintext.'</td>'.
2283: '<td>'.$area.'</td>'.
2284: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
2285: : ' ' ).'</td>'.
2286: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
2287: : ' ' ).'</td>';
1.329 raeburn 2288: $sortrole{$sortkey}=$envkey;
2289: $roletext{$envkey}=$row;
2290: $roleclass{$envkey}=$class;
1.418 raeburn 2291: if ($allowed) {
2292: $rolepriv{$envkey}='edit';
2293: } else {
2294: if ($context eq 'domain') {
1.420 raeburn 2295: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1.421 raeburn 2296: ($envkey=~m{^/$ccdomain/})) {
1.418 raeburn 2297: $rolepriv{$envkey}='view';
2298: }
2299: } elsif ($context eq 'course') {
2300: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
2301: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
2302: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
2303: $rolepriv{$envkey}='view';
2304: }
2305: }
2306: }
1.329 raeburn 2307: } # end of foreach (table building loop)
2308:
2309: my $rolesdisplay = 0;
2310: my %output = ();
1.377 raeburn 2311: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2312: $output{$type} = '';
2313: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2314: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2315: $output{$type}.=
2316: &Apache::loncommon::start_data_table_row().
2317: $roletext{$sortrole{$which}}.
2318: &Apache::loncommon::end_data_table_row();
1.217 raeburn 2319: }
1.329 raeburn 2320: }
2321: unless($output{$type} eq '') {
2322: $output{$type} = '<tr class="LC_info_row">'.
2323: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2324: $output{$type};
2325: $rolesdisplay = 1;
2326: }
2327: }
2328: if ($rolesdisplay == 1) {
2329: my $contextrole='';
2330: if ($env{'request.course.id'}) {
2331: if (&Apache::loncommon::course_type() eq 'Community') {
2332: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2333: } else {
1.329 raeburn 2334: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2335: }
1.329 raeburn 2336: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2337: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.470 raeburn 2338: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)/$}) {
2339: $contextrole = &mt('Existing Co-Author Roles in [_1] Authoring Space',
2340: '<i>'.$1.'_'.$2.'</i>');
1.329 raeburn 2341: } else {
1.418 raeburn 2342: if ($showall) {
2343: $contextrole = &mt('Existing Roles in this Domain');
2344: } elsif ($showactive) {
2345: $contextrole = &mt('Unexpired Roles in this Domain');
2346: } elsif ($showexpired) {
2347: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2348: }
1.329 raeburn 2349: }
1.393 raeburn 2350: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2351: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2352: &Apache::loncommon::start_data_table("LC_createuser").
1.418 raeburn 2353: &Apache::loncommon::start_data_table_header_row());
2354: if ($showall) {
2355: $r->print(
1.419 raeburn 2356: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1.418 raeburn 2357: );
2358: } elsif ($showexpired) {
2359: $r->print('<th>'.$lt{'rev'}.'</th>');
2360: }
2361: $r->print(
1.419 raeburn 2362: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2363: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2364: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2365: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2366: if ($output{$type}) {
2367: $r->print($output{$type}."\n");
1.217 raeburn 2368: }
2369: }
1.375 raeburn 2370: $r->print(&Apache::loncommon::end_data_table().
2371: '</fieldset></div>');
1.329 raeburn 2372: }
1.217 raeburn 2373: return;
2374: }
2375:
1.218 raeburn 2376: sub new_coauthor_roles {
2377: my ($r,$ccuname,$ccdomain) = @_;
2378: my $addrolesdisplay = 0;
2379: #
2380: # Co-Author
2381: #
1.470 raeburn 2382: my ($cuname,$cudom);
2383: if (($env{'request.role'} eq "au./$env{'user.domain'}/") ||
2384: ($env{'request.role'} eq "dc./$env{'user.domain'}/")) {
2385: $cuname=$env{'user.name'};
2386: $cudom=$env{'request.role.domain'};
1.218 raeburn 2387: # No sense in assigning co-author role to yourself
1.470 raeburn 2388: if ((&Apache::lonuserutils::authorpriv($cuname,$cudom)) &&
2389: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2390: $addrolesdisplay = 1;
2391: }
2392: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2393: ($cudom,$cuname) = ($1,$2);
2394: if ((&Apache::lonuserutils::coauthorpriv($cuname,$cudom)) &&
2395: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain) &&
2396: ($cudom ne $ccdomain || $cuname ne $ccuname)) {
2397: $addrolesdisplay = 1;
2398: }
2399: }
2400: if ($addrolesdisplay) {
1.218 raeburn 2401: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2402: 'cs' => "Authoring Space",
1.218 raeburn 2403: 'act' => "Activate",
2404: 'rol' => "Role",
2405: 'ext' => "Extent",
2406: 'sta' => "Start",
2407: 'end' => "End",
2408: 'cau' => "Co-Author",
2409: 'caa' => "Assistant Co-Author",
2410: 'ssd' => "Set Start Date",
2411: 'sed' => "Set End Date"
2412: );
2413: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2414: &Apache::loncommon::start_data_table()."\n".
2415: &Apache::loncommon::start_data_table_header_row()."\n".
2416: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2417: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2418: '<th>'.$lt{'end'}.'</th>'."\n".
2419: &Apache::loncommon::end_data_table_header_row()."\n".
2420: &Apache::loncommon::start_data_table_row().'
2421: <td>
1.291 bisitz 2422: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2423: </td>
2424: <td>'.$lt{'cau'}.'</td>
2425: <td>'.$cudom.'_'.$cuname.'</td>
2426: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2427: <a href=
2428: "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>
2429: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2430: <a href=
2431: "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".
2432: &Apache::loncommon::end_data_table_row()."\n".
2433: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2434: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2435: <td>'.$lt{'caa'}.'</td>
2436: <td>'.$cudom.'_'.$cuname.'</td>
2437: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2438: <a href=
2439: "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>
2440: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2441: <a href=
2442: "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".
2443: &Apache::loncommon::end_data_table_row()."\n".
2444: &Apache::loncommon::end_data_table());
2445: } elsif ($env{'request.role'} =~ /^au\./) {
2446: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2447: $env{'request.role.domain'}))) {
2448: $r->print('<span class="LC_error">'.
2449: &mt('You do not have privileges to assign co-author roles.').
2450: '</span>');
2451: } elsif (($env{'user.name'} eq $ccuname) &&
2452: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2453: $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 2454: }
1.470 raeburn 2455: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2456: if (!(&Apache::lonuserutils::coauthorpriv($2,$1))) {
2457: $r->print('<span class="LC_error">'.
2458: &mt('You do not have privileges to assign co-author roles.').
2459: '</span>');
2460: } elsif (($env{'user.name'} eq $ccuname) &&
2461: ($env{'user.domain'} eq $ccdomain)) {
2462: $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'));
2463: } elsif (($cudom eq $ccdomain) && ($cuname eq $ccuname)) {
2464: $r->print(&mt("Assigning a co-author or assistant co-author role to an Authoring Space's author is not permitted"));
2465: }
1.218 raeburn 2466: }
2467: return $addrolesdisplay;;
2468: }
2469:
2470: sub new_domain_roles {
1.357 raeburn 2471: my ($r,$ccdomain) = @_;
1.218 raeburn 2472: my $addrolesdisplay = 0;
2473: #
2474: # Domain level
2475: #
2476: my $num_domain_level = 0;
2477: my $domaintext =
2478: '<h4>'.&mt('Domain Level').'</h4>'.
2479: &Apache::loncommon::start_data_table().
2480: &Apache::loncommon::start_data_table_header_row().
2481: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2482: &mt('Extent').'</th>'.
2483: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2484: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2485: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.445 raeburn 2486: my $uprimary = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2487: my $uintdom = &Apache::lonnet::internet_dom($uprimary);
1.218 raeburn 2488: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2489: foreach my $role (@allroles) {
2490: next if ($role eq 'ad');
1.357 raeburn 2491: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2492: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1.445 raeburn 2493: if ($role eq 'dc') {
2494: unless ($thisdomain eq $env{'request.role.domain'}) {
2495: my $domprim = &Apache::lonnet::domain($thisdomain,'primary');
2496: my $intdom = &Apache::lonnet::internet_dom($domprim);
2497: next unless ($uintdom eq $intdom);
2498: }
2499: }
1.218 raeburn 2500: my $plrole=&Apache::lonnet::plaintext($role);
2501: my %lt=&Apache::lonlocal::texthash(
2502: 'ssd' => "Set Start Date",
2503: 'sed' => "Set End Date"
2504: );
2505: $num_domain_level ++;
2506: $domaintext .=
2507: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2508: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2509: <td>'.$plrole.'</td>
2510: <td>'.$thisdomain.'</td>
2511: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2512: <a href=
2513: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2514: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2515: <a href=
2516: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2517: &Apache::loncommon::end_data_table_row();
2518: }
2519: }
2520: }
2521: $domaintext.= &Apache::loncommon::end_data_table();
2522: if ($num_domain_level > 0) {
2523: $r->print($domaintext);
2524: $addrolesdisplay = 1;
2525: }
2526: return $addrolesdisplay;
2527: }
2528:
1.188 raeburn 2529: sub user_authentication {
1.451 raeburn 2530: my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
1.188 raeburn 2531: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2532: my $outcome;
1.418 raeburn 2533: my %lt=&Apache::lonlocal::texthash(
2534: 'err' => "ERROR",
2535: 'uuas' => "This user has an unrecognized authentication scheme",
2536: 'adcs' => "Please alert a domain coordinator of this situation",
2537: 'sldb' => "Please specify login data below",
2538: 'ld' => "Login Data"
2539: );
1.188 raeburn 2540: # Check for a bad authentication type
1.449 raeburn 2541: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth|lti):/) {
1.188 raeburn 2542: # bad authentication scheme
2543: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2544: &initialize_authen_forms($ccdomain,$formname);
2545:
1.190 raeburn 2546: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2547: $outcome = <<ENDBADAUTH;
2548: <script type="text/javascript" language="Javascript">
1.301 bisitz 2549: // <![CDATA[
1.188 raeburn 2550: $loginscript
1.301 bisitz 2551: // ]]>
1.188 raeburn 2552: </script>
2553: <span class="LC_error">$lt{'err'}:
2554: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2555: <h3>$lt{'ld'}</h3>
2556: $choices
2557: ENDBADAUTH
2558: } else {
2559: # This user is not allowed to modify the user's
2560: # authentication scheme, so just notify them of the problem
2561: $outcome = <<ENDBADAUTH;
2562: <span class="LC_error"> $lt{'err'}:
2563: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2564: </span>
2565: ENDBADAUTH
2566: }
2567: } else { # Authentication type is valid
1.418 raeburn 2568:
1.227 raeburn 2569: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2570: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2571: &modify_login_block($ccdomain,$currentauth);
2572: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2573: # Current user has login modification privileges
2574: $outcome =
2575: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2576: '// <![CDATA['."\n".
1.188 raeburn 2577: $loginscript."\n".
1.301 bisitz 2578: '// ]]>'."\n".
1.188 raeburn 2579: '</script>'."\n".
2580: '<h3>'.$lt{'ld'}.'</h3>'.
2581: &Apache::loncommon::start_data_table().
1.205 raeburn 2582: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2583: '<td>'.$authformnop;
1.418 raeburn 2584: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2585: $outcome .= '</td>'."\n".
2586: &Apache::loncommon::end_data_table_row().
2587: &Apache::loncommon::start_data_table_row().
2588: '<td>'.$authformcurrent.'</td>'.
2589: &Apache::loncommon::end_data_table_row()."\n";
2590: } else {
1.200 raeburn 2591: $outcome .= ' ('.$authformcurrent.')</td>'.
2592: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2593: }
1.418 raeburn 2594: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2595: foreach my $item (@authform_others) {
2596: $outcome .= &Apache::loncommon::start_data_table_row().
2597: '<td>'.$item.'</td>'.
2598: &Apache::loncommon::end_data_table_row()."\n";
2599: }
1.188 raeburn 2600: }
1.205 raeburn 2601: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2602: } else {
1.451 raeburn 2603: if (($currentauth =~ /^internal:/) &&
2604: (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
2605: $outcome = <<"ENDJS";
2606: <script type="text/javascript">
2607: // <![CDATA[
2608: function togglePwd(form) {
2609: if (form.newintpwd.length) {
2610: if (document.getElementById('LC_ownersetpwd')) {
2611: for (var i=0; i<form.newintpwd.length; i++) {
2612: if (form.newintpwd[i].checked) {
2613: if (form.newintpwd[i].value == 1) {
2614: document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
2615: } else {
2616: document.getElementById('LC_ownersetpwd').style.display = 'none';
2617: }
2618: }
2619: }
2620: }
2621: }
2622: }
2623: // ]]>
2624: </script>
2625: ENDJS
2626:
2627: $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
2628: &Apache::loncommon::start_data_table().
2629: &Apache::loncommon::start_data_table_row().
2630: '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
2631: '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
2632: &mt('No').'</label>'.(' 'x2).
2633: '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
2634: '<div id="LC_ownersetpwd" style="display:none">'.
2635: ' '.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
2636: '<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>'.
2637: &Apache::loncommon::end_data_table_row().
2638: &Apache::loncommon::end_data_table();
2639: }
1.418 raeburn 2640: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2641: # Current user has rights to view domain preferences for user's domain
2642: my $result;
2643: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2644: my ($krbver,$krbrealm) = ($1,$2);
2645: if ($krbrealm eq '') {
2646: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2647: } else {
2648: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.426 raeburn 2649: $krbrealm,$krbver);
1.418 raeburn 2650: }
2651: } elsif ($currentauth =~ /^internal:/) {
2652: $result = &mt('Currently internally authenticated.');
2653: } elsif ($currentauth =~ /^localauth:/) {
2654: $result = &mt('Currently using local (institutional) authentication.');
2655: } elsif ($currentauth =~ /^unix:/) {
2656: $result = &mt('Currently Filesystem Authenticated.');
1.449 raeburn 2657: } elsif ($currentauth =~ /^lti:/) {
1.451 raeburn 2658: $result = &mt('Currently LTI authenticated.');
1.418 raeburn 2659: }
2660: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2661: &Apache::loncommon::start_data_table().
2662: &Apache::loncommon::start_data_table_row().
2663: '<td>'.$result.'</td>'.
2664: &Apache::loncommon::end_data_table_row()."\n".
2665: &Apache::loncommon::end_data_table();
2666: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2667: my %lt=&Apache::lonlocal::texthash(
2668: 'ccld' => "Change Current Login Data",
2669: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2670: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2671: );
2672: $outcome .= <<ENDNOPRIV;
2673: <h3>$lt{'ccld'}</h3>
2674: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2675: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2676: ENDNOPRIV
2677: }
2678: }
2679: } ## End of "check for bad authentication type" logic
2680: return $outcome;
2681: }
2682:
1.187 raeburn 2683: sub modify_login_block {
2684: my ($dom,$currentauth) = @_;
2685: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2686: my ($authnum,%can_assign) =
2687: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2688: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2689: if ($currentauth=~/^krb(4|5):/) {
2690: $authformcurrent=$authformkrb;
2691: if ($can_assign{'int'}) {
1.205 raeburn 2692: push(@authform_others,$authformint);
1.187 raeburn 2693: }
2694: if ($can_assign{'loc'}) {
1.205 raeburn 2695: push(@authform_others,$authformloc);
1.187 raeburn 2696: }
1.449 raeburn 2697: if ($can_assign{'lti'}) {
2698: push(@authform_others,$authformlti);
2699: }
1.187 raeburn 2700: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2701: $show_override_msg = 1;
2702: }
2703: } elsif ($currentauth=~/^internal:/) {
2704: $authformcurrent=$authformint;
2705: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2706: push(@authform_others,$authformkrb);
1.187 raeburn 2707: }
2708: if ($can_assign{'loc'}) {
1.205 raeburn 2709: push(@authform_others,$authformloc);
1.187 raeburn 2710: }
1.449 raeburn 2711: if ($can_assign{'lti'}) {
2712: push(@authform_others,$authformlti);
2713: }
1.187 raeburn 2714: if ($can_assign{'int'}) {
2715: $show_override_msg = 1;
2716: }
2717: } elsif ($currentauth=~/^unix:/) {
2718: $authformcurrent=$authformfsys;
2719: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2720: push(@authform_others,$authformkrb);
1.187 raeburn 2721: }
2722: if ($can_assign{'int'}) {
1.205 raeburn 2723: push(@authform_others,$authformint);
1.187 raeburn 2724: }
2725: if ($can_assign{'loc'}) {
1.205 raeburn 2726: push(@authform_others,$authformloc);
1.187 raeburn 2727: }
1.449 raeburn 2728: if ($can_assign{'lti'}) {
2729: push(@authform_others,$authformlti);
2730: }
1.187 raeburn 2731: if ($can_assign{'fsys'}) {
2732: $show_override_msg = 1;
2733: }
2734: } elsif ($currentauth=~/^localauth:/) {
2735: $authformcurrent=$authformloc;
2736: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2737: push(@authform_others,$authformkrb);
1.187 raeburn 2738: }
2739: if ($can_assign{'int'}) {
1.205 raeburn 2740: push(@authform_others,$authformint);
1.187 raeburn 2741: }
1.449 raeburn 2742: if ($can_assign{'lti'}) {
2743: push(@authform_others,$authformlti);
2744: }
1.187 raeburn 2745: if ($can_assign{'loc'}) {
2746: $show_override_msg = 1;
2747: }
1.449 raeburn 2748: } elsif ($currentauth=~/^lti:/) {
2749: $authformcurrent=$authformlti;
2750: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2751: push(@authform_others,$authformkrb);
2752: }
2753: if ($can_assign{'int'}) {
2754: push(@authform_others,$authformint);
2755: }
2756: if ($can_assign{'loc'}) {
2757: push(@authform_others,$authformloc);
2758: }
1.187 raeburn 2759: }
2760: if ($show_override_msg) {
1.205 raeburn 2761: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2762: '</td></tr>'."\n".
2763: '<tr><td> </td>'.
2764: '<td><b>'.&mt('Currently in use').'</b></td>'.
2765: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2766: &mt('will override current values').
1.205 raeburn 2767: '</span></td></tr></table>';
1.187 raeburn 2768: }
1.205 raeburn 2769: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2770: }
2771:
1.188 raeburn 2772: sub personal_data_display {
1.470 raeburn 2773: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$readonly,$rolesarray,$now,
1.456 raeburn 2774: $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
1.470 raeburn 2775: my ($output,%userenv,%canmodify,%canmodify_status,$disabled);
1.219 raeburn 2776: my @userinfo = ('firstname','middlename','lastname','generation',
2777: 'permanentemail','id');
1.252 raeburn 2778: my $rowcount = 0;
2779: my $editable = 0;
1.391 raeburn 2780: my %textboxsize = (
2781: firstname => '15',
2782: middlename => '15',
2783: lastname => '15',
2784: generation => '5',
2785: permanentemail => '25',
2786: id => '15',
2787: );
2788:
2789: my %lt=&Apache::lonlocal::texthash(
2790: 'pd' => "Personal Data",
2791: 'firstname' => "First Name",
2792: 'middlename' => "Middle Name",
2793: 'lastname' => "Last Name",
2794: 'generation' => "Generation",
2795: 'permanentemail' => "Permanent e-mail address",
2796: 'id' => "Student/Employee ID",
2797: 'lg' => "Login Data",
2798: 'inststatus' => "Affiliation",
2799: 'email' => 'E-mail address',
2800: 'valid' => 'Validation',
1.442 raeburn 2801: 'username' => 'Username',
1.391 raeburn 2802: );
2803:
2804: %canmodify_status =
1.286 raeburn 2805: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2806: ['inststatus'],$rolesarray);
1.253 raeburn 2807: if (!$newuser) {
1.188 raeburn 2808: # Get the users information
2809: %userenv = &Apache::lonnet::get('environment',
2810: ['firstname','middlename','lastname','generation',
1.286 raeburn 2811: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2812: %canmodify =
2813: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2814: \@userinfo,$rolesarray);
1.257 raeburn 2815: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2816: if ($newuser eq 'email') {
1.396 raeburn 2817: if (ref($emailusername) eq 'HASH') {
2818: if (ref($emailusername->{$usertype}) eq 'HASH') {
2819: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.442 raeburn 2820: @userinfo = ();
1.396 raeburn 2821: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2822: foreach my $field (@{$infofields}) {
2823: if ($emailusername->{$usertype}->{$field}) {
2824: push(@userinfo,$field);
2825: $canmodify{$field} = 1;
2826: unless ($textboxsize{$field}) {
2827: $textboxsize{$field} = 25;
2828: }
2829: unless ($lt{$field}) {
2830: $lt{$field} = $infotitles->{$field};
2831: }
2832: if ($emailusername->{$usertype}->{$field} eq 'required') {
2833: $lt{$field} .= '<b>*</b>';
2834: }
1.391 raeburn 2835: }
2836: }
2837: }
2838: }
2839: }
2840: } else {
2841: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2842: $inst_results,$rolesarray);
2843: }
1.470 raeburn 2844: } elsif ($readonly) {
2845: $disabled = ' disabled="disabled"';
1.188 raeburn 2846: }
1.391 raeburn 2847:
1.188 raeburn 2848: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2849: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2850: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2851: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.443 raeburn 2852: my $size = 25;
1.442 raeburn 2853: if ($condition) {
1.443 raeburn 2854: if ($condition =~ /^\@[^\@]+$/) {
2855: $size = 10;
1.442 raeburn 2856: } else {
2857: undef($condition);
2858: }
1.443 raeburn 2859: }
2860: if ($excluded) {
2861: unless ($excluded =~ /^\@[^\@]+$/) {
2862: undef($condition);
2863: }
1.442 raeburn 2864: }
1.396 raeburn 2865: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2866: 'LC_oddrow_value')."\n".
1.443 raeburn 2867: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2868: if ($condition) {
2869: $output .= $condition;
2870: } elsif ($excluded) {
2871: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2872: $excluded).'</span>';
2873: }
2874: if ($usernameset eq 'first') {
2875: $output .= '<br /><span style="font-size: smaller">';
2876: if ($condition) {
2877: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2878: $condition);
2879: } else {
2880: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2881: }
2882: $output .= '</span>';
2883: }
1.391 raeburn 2884: $rowcount ++;
2885: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.460 raeburn 2886: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="new-password" />';
2887: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="new-password" />';
1.396 raeburn 2888: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2889: 'LC_pick_box_title',
2890: 'LC_oddrow_value')."\n".
2891: $upassone."\n".
2892: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2893: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2894: 'LC_pick_box_title',
2895: 'LC_oddrow_value')."\n".
2896: $upasstwo.
2897: &Apache::lonhtmlcommon::row_closure()."\n";
1.443 raeburn 2898: if ($usernameset eq 'free') {
2899: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
1.442 raeburn 2900: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
1.455 raeburn 2901: '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
2902: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
2903: &mt('Yes').'</label>'.(' 'x2).
2904: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
2905: &mt('No').'</label></span>'."\n".
1.442 raeburn 2906: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2907: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2908: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2909: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2910: $rowcount ++;
2911: }
1.391 raeburn 2912: }
1.188 raeburn 2913: foreach my $item (@userinfo) {
2914: my $rowtitle = $lt{$item};
1.252 raeburn 2915: my $hiderow = 0;
1.188 raeburn 2916: if ($item eq 'generation') {
2917: $rowtitle = $genhelp.$rowtitle;
2918: }
1.252 raeburn 2919: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2920: if ($newuser) {
1.210 raeburn 2921: if (ref($inst_results) eq 'HASH') {
2922: if ($inst_results->{$item} ne '') {
1.252 raeburn 2923: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2924: } else {
1.252 raeburn 2925: if ($context eq 'selfcreate') {
1.391 raeburn 2926: if ($canmodify{$item}) {
1.394 raeburn 2927: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2928: $editable ++;
2929: } else {
2930: $hiderow = 1;
2931: }
1.253 raeburn 2932: } else {
1.470 raeburn 2933: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value=""'.$disabled.' />';
1.252 raeburn 2934: }
1.210 raeburn 2935: }
1.188 raeburn 2936: } else {
1.252 raeburn 2937: if ($context eq 'selfcreate') {
1.401 raeburn 2938: if ($canmodify{$item}) {
2939: if ($newuser eq 'email') {
2940: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2941: } else {
1.401 raeburn 2942: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2943: }
1.401 raeburn 2944: $editable ++;
2945: } else {
2946: $hiderow = 1;
1.252 raeburn 2947: }
1.253 raeburn 2948: } else {
1.470 raeburn 2949: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value=""'.$disabled.' />';
1.252 raeburn 2950: }
1.188 raeburn 2951: }
2952: } else {
1.219 raeburn 2953: if ($canmodify{$item}) {
1.252 raeburn 2954: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2955: if (($item eq 'id') && (!$newuser)) {
2956: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2957: }
1.188 raeburn 2958: } else {
1.252 raeburn 2959: $row .= $userenv{$item};
1.188 raeburn 2960: }
2961: }
1.252 raeburn 2962: $row .= &Apache::lonhtmlcommon::row_closure(1);
2963: if (!$hiderow) {
2964: $output .= $row;
2965: $rowcount ++;
2966: }
1.188 raeburn 2967: }
1.286 raeburn 2968: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2969: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2970: if (ref($types) eq 'ARRAY') {
2971: if (@{$types} > 0) {
2972: my ($hiderow,$shown);
2973: if ($canmodify_status{'inststatus'}) {
2974: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2975: } else {
2976: if ($userenv{'inststatus'} eq '') {
2977: $hiderow = 1;
1.334 raeburn 2978: } else {
2979: my @showitems;
2980: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2981: if (exists($usertypes->{$item})) {
2982: push(@showitems,$usertypes->{$item});
2983: } else {
2984: push(@showitems,$item);
2985: }
2986: }
2987: if (@showitems) {
2988: $shown = join(', ',@showitems);
2989: } else {
2990: $hiderow = 1;
2991: }
1.286 raeburn 2992: }
2993: }
2994: if (!$hiderow) {
1.389 bisitz 2995: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2996: $shown.&Apache::lonhtmlcommon::row_closure(1);
2997: if ($context eq 'selfcreate') {
2998: $rowcount ++;
2999: }
3000: $output .= $row;
3001: }
3002: }
3003: }
3004: }
1.391 raeburn 3005: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
3006: if ($captchaform) {
1.410 raeburn 3007: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
3008: 'LC_pick_box_title')."\n".
1.456 raeburn 3009: $captchaform."\n".'<br /><br />'.
1.391 raeburn 3010: &Apache::lonhtmlcommon::row_closure(1);
3011: $rowcount ++;
3012: }
1.456 raeburn 3013: if ($showsubmit) {
3014: my $submit_text = &mt('Create account');
3015: $output .= &Apache::lonhtmlcommon::row_title()."\n".
3016: '<br /><input type="submit" name="createaccount" value="'.
3017: $submit_text.'" />';
3018: if ($usertype ne '') {
3019: $output .= '<input type="hidden" name="type" value="'.
3020: &HTML::Entities::encode($usertype,'\'<>"&').'" />';
3021: }
3022: $output .= &Apache::lonhtmlcommon::row_closure(1);
3023: }
1.391 raeburn 3024: }
1.188 raeburn 3025: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 3026: if (wantarray) {
1.252 raeburn 3027: if ($context eq 'selfcreate') {
3028: return($output,$rowcount,$editable);
3029: } else {
1.388 bisitz 3030: return $output;
1.252 raeburn 3031: }
1.206 raeburn 3032: } else {
3033: return $output;
3034: }
1.188 raeburn 3035: }
3036:
1.286 raeburn 3037: sub pick_inst_statuses {
3038: my ($curr,$usertypes,$types) = @_;
3039: my ($output,$rem,@currtypes);
3040: if ($curr ne '') {
3041: @currtypes = map { &unescape($_); } split(/:/,$curr);
3042: }
3043: my $numinrow = 2;
3044: if (ref($types) eq 'ARRAY') {
3045: $output = '<table>';
3046: my $lastcolspan;
3047: for (my $i=0; $i<@{$types}; $i++) {
3048: if (defined($usertypes->{$types->[$i]})) {
3049: my $rem = $i%($numinrow);
3050: if ($rem == 0) {
3051: if ($i<@{$types}-1) {
3052: if ($i > 0) {
3053: $output .= '</tr>';
3054: }
3055: $output .= '<tr>';
3056: }
3057: } elsif ($i==@{$types}-1) {
3058: my $colsleft = $numinrow - $rem;
3059: if ($colsleft > 1) {
3060: $lastcolspan = ' colspan="'.$colsleft.'"';
3061: }
3062: }
3063: my $check = ' ';
3064: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
3065: $check = ' checked="checked" ';
3066: }
3067: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
3068: '<span class="LC_nobreak"><label>'.
3069: '<input type="checkbox" name="inststatus" '.
3070: 'value="'.$types->[$i].'"'.$check.'/>'.
3071: $usertypes->{$types->[$i]}.'</label></span></td>';
3072: }
3073: }
3074: $output .= '</tr></table>';
3075: }
3076: return $output;
3077: }
3078:
1.257 raeburn 3079: sub selfcreate_canmodify {
3080: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
3081: if (ref($inst_results) eq 'HASH') {
3082: my @inststatuses = &get_inststatuses($inst_results);
3083: if (@inststatuses == 0) {
3084: @inststatuses = ('default');
3085: }
3086: $rolesarray = \@inststatuses;
3087: }
3088: my %canmodify =
3089: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
3090: $rolesarray);
3091: return %canmodify;
3092: }
3093:
1.252 raeburn 3094: sub get_inststatuses {
3095: my ($insthashref) = @_;
3096: my @inststatuses = ();
3097: if (ref($insthashref) eq 'HASH') {
3098: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
3099: @inststatuses = @{$insthashref->{'inststatus'}};
3100: }
3101: }
3102: return @inststatuses;
3103: }
3104:
1.4 www 3105: # ================================================================= Phase Three
1.42 matthew 3106: sub update_user_data {
1.451 raeburn 3107: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 3108: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
3109: $env{'form.ccdomain'});
1.27 matthew 3110: # Error messages
1.188 raeburn 3111: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 3112: my $end = '</span><br /><br />';
3113: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 3114: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 3115: &mt('Return to previous page').'</a>'.
3116: &Apache::loncommon::end_page();
3117: my $now = time;
1.40 www 3118: my $title;
1.101 albertel 3119: if (exists($env{'form.makeuser'})) {
1.40 www 3120: $title='Set Privileges for New User';
3121: } else {
3122: $title='Modify User Privileges';
3123: }
1.213 raeburn 3124: my $newuser = 0;
1.160 raeburn 3125: my ($jsback,$elements) = &crumb_utilities();
3126: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 3127: '// <![CDATA['."\n".
3128: $jsback."\n".
3129: '// ]]>'."\n".
3130: '</script>'."\n";
1.422 raeburn 3131: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 3132: push (@{$brcrum},
3133: {href => "javascript:backPage(document.userupdate)",
3134: text => $breadcrumb_text{'search'},
3135: faq => 282,
3136: bug => 'Instructor Interface',}
3137: );
3138: if ($env{'form.prevphase'} eq 'userpicked') {
3139: push(@{$brcrum},
3140: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
3141: text => $breadcrumb_text{'userpicked'},
3142: faq => 282,
3143: bug => 'Instructor Interface',});
1.233 raeburn 3144: }
1.224 raeburn 3145: my $helpitem = 'Course_Change_Privileges';
3146: if ($env{'form.action'} eq 'singlestudent') {
3147: $helpitem = 'Course_Add_Student';
1.439 raeburn 3148: } elsif ($context eq 'author') {
3149: $helpitem = 'Author_Change_Privileges';
3150: } elsif ($context eq 'domain') {
3151: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 3152: }
1.351 raeburn 3153: push(@{$brcrum},
3154: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
3155: text => $breadcrumb_text{'modify'},
3156: faq => 282,
3157: bug => 'Instructor Interface',},
3158: {href => "/adm/createuser",
3159: text => "Result",
3160: faq => 282,
3161: bug => 'Instructor Interface',
3162: help => $helpitem});
3163: my $args = {bread_crumbs => $brcrum,
3164: bread_crumbs_component => 'User Management'};
3165: if ($env{'form.popup'}) {
3166: $args->{'no_nav_bar'} = 1;
3167: }
3168: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 3169: $r->print(&update_result_form($uhome));
1.27 matthew 3170: # Check Inputs
1.101 albertel 3171: if (! $env{'form.ccuname'} ) {
1.193 raeburn 3172: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 3173: return;
3174: }
1.138 albertel 3175: if ( $env{'form.ccuname'} ne
3176: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 3177: $r->print($error.&mt('Invalid login name.').' '.
3178: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 3179: $end.$rtnlink);
1.27 matthew 3180: return;
3181: }
1.101 albertel 3182: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 3183: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 3184: return;
3185: }
1.138 albertel 3186: if ( $env{'form.ccdomain'} ne
3187: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 3188: $r->print($error.&mt('Invalid domain name.').' '.
3189: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 3190: $end.$rtnlink);
1.27 matthew 3191: return;
3192: }
1.219 raeburn 3193: if ($uhome eq 'no_host') {
3194: $newuser = 1;
3195: }
1.101 albertel 3196: if (! exists($env{'form.makeuser'})) {
1.29 matthew 3197: # Modifying an existing user, so check the validity of the name
3198: if ($uhome eq 'no_host') {
1.389 bisitz 3199: $r->print(
3200: $error
3201: .'<p class="LC_error">'
3202: .&mt('Unable to determine home server for [_1] in domain [_2].',
3203: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
3204: .'</p>');
1.29 matthew 3205: return;
3206: }
3207: }
1.27 matthew 3208: # Determine authentication method and password for the user being modified
3209: my $amode='';
3210: my $genpwd='';
1.101 albertel 3211: if ($env{'form.login'} eq 'krb') {
1.41 albertel 3212: $amode='krb';
1.101 albertel 3213: $amode.=$env{'form.krbver'};
3214: $genpwd=$env{'form.krbarg'};
3215: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 3216: $amode='internal';
1.101 albertel 3217: $genpwd=$env{'form.intarg'};
3218: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 3219: $amode='unix';
1.101 albertel 3220: $genpwd=$env{'form.fsysarg'};
3221: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 3222: $amode='localauth';
1.101 albertel 3223: $genpwd=$env{'form.locarg'};
1.27 matthew 3224: $genpwd=" " if (!$genpwd);
1.449 raeburn 3225: } elsif ($env{'form.login'} eq 'lti') {
3226: $amode='lti';
3227: $genpwd=" ";
1.101 albertel 3228: } elsif (($env{'form.login'} eq 'nochange') ||
3229: ($env{'form.login'} eq '' )) {
1.34 matthew 3230: # There is no need to tell the user we did not change what they
3231: # did not ask us to change.
1.35 matthew 3232: # If they are creating a new user but have not specified login
3233: # information this will be caught below.
1.30 matthew 3234: } else {
1.367 golterma 3235: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
3236: return;
1.27 matthew 3237: }
1.164 albertel 3238:
1.188 raeburn 3239: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 3240: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
3241: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
3242: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 3243:
1.193 raeburn 3244: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 3245: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.470 raeburn 3246: my @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.449 raeburn 3247: my @requestcourses = ('official','unofficial','community','textbook','placement','lti');
1.362 raeburn 3248: my @requestauthor = ('requestauthor');
1.477 raeburn 3249: my @authordefaults = ('webdav','editors','archive');
1.286 raeburn 3250: my ($othertitle,$usertypes,$types) =
3251: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 3252: my %canmodify_status =
3253: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
3254: ['inststatus']);
1.101 albertel 3255: if ($env{'form.makeuser'}) {
1.164 albertel 3256: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 3257: # Check for the authentication mode and password
3258: if (! $amode || ! $genpwd) {
1.193 raeburn 3259: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 3260: return;
1.18 albertel 3261: }
1.29 matthew 3262: # Determine desired host
1.101 albertel 3263: my $desiredhost = $env{'form.hserver'};
1.29 matthew 3264: if (lc($desiredhost) eq 'default') {
3265: $desiredhost = undef;
3266: } else {
1.147 albertel 3267: my %home_servers =
3268: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 3269: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 3270: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
3271: return;
3272: }
3273: }
3274: # Check ID format
3275: my %checkhash;
3276: my %checks = ('id' => 1);
3277: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 3278: 'newuser' => $newuser,
1.196 raeburn 3279: 'id' => $env{'form.cid'},
1.193 raeburn 3280: );
1.196 raeburn 3281: if ($env{'form.cid'} ne '') {
3282: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
3283: \%rulematch,\%inst_results,\%curr_rules);
3284: if (ref($alerts{'id'}) eq 'HASH') {
3285: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
3286: my $domdesc =
3287: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
3288: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
3289: my $userchkmsg;
3290: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
3291: $userchkmsg =
3292: &Apache::loncommon::instrule_disallow_msg('id',
3293: $domdesc,1).
3294: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
3295: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
3296: }
3297: $r->print($error.&mt('Invalid ID format').$end.
3298: $userchkmsg.$rtnlink);
3299: return;
3300: }
3301: }
1.29 matthew 3302: }
3303: }
1.367 golterma 3304: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 3305: # Call modifyuser
3306: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 3307: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 3308: $amode,$genpwd,$env{'form.cfirstname'},
3309: $env{'form.cmiddlename'},$env{'form.clastname'},
3310: $env{'form.cgeneration'},undef,$desiredhost,
3311: $env{'form.cpermanentemail'});
1.77 www 3312: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 3313: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 3314: $env{'form.ccdomain'});
1.334 raeburn 3315: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 3316: if ($uhome ne 'no_host') {
1.334 raeburn 3317: if ($context eq 'domain') {
1.378 raeburn 3318: foreach my $name ('portfolio','author') {
3319: if ($env{'form.custom_'.$name.'quota'} == 1) {
3320: if ($env{'form.'.$name.'quota'} eq '') {
3321: $newcustom{$name.'quota'} = 0;
3322: } else {
3323: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
3324: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
3325: }
3326: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
3327: $changed{$name.'quota'} = 1;
3328: }
1.334 raeburn 3329: }
3330: }
3331: foreach my $item (@usertools) {
3332: if ($env{'form.custom'.$item} == 1) {
3333: $newcustom{$item} = $env{'form.tools_'.$item};
3334: $changed{$item} = &tool_admin($item,$newcustom{$item},
3335: \%changeHash,'tools');
3336: }
1.267 raeburn 3337: }
1.334 raeburn 3338: foreach my $item (@requestcourses) {
1.341 raeburn 3339: if ($env{'form.custom'.$item} == 1) {
3340: $newcustom{$item} = $env{'form.crsreq_'.$item};
3341: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
3342: $newcustom{$item} .= '=';
1.383 raeburn 3343: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
3344: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 3345: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
3346: }
1.334 raeburn 3347: }
1.341 raeburn 3348: $changed{$item} = &tool_admin($item,$newcustom{$item},
3349: \%changeHash,'requestcourses');
1.334 raeburn 3350: }
1.275 raeburn 3351: }
1.362 raeburn 3352: if ($env{'form.customrequestauthor'} == 1) {
3353: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
3354: $changed{'requestauthor'} = &tool_admin('requestauthor',
3355: $newcustom{'requestauthor'},
3356: \%changeHash,'requestauthor');
3357: }
1.470 raeburn 3358: if ($env{'form.customeditors'} == 1) {
3359: my @editors;
3360: my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
3361: if (@posseditors) {
3362: foreach my $editor (@posseditors) {
3363: if (grep(/^\Q$editor\E$/,@posseditors)) {
3364: unless (grep(/^\Q$editor\E$/,@editors)) {
3365: push(@editors,$editor);
3366: }
3367: }
3368: }
3369: }
3370: if (@editors) {
3371: @editors = sort(@editors);
3372: $changed{'editors'} = &tool_admin('editors',join(',',@editors),
3373: \%changeHash,'authordefaults');
3374: }
3375: }
3376: if ($env{'form.customwebdav'} == 1) {
3377: $newcustom{'webdav'} = $env{'form.authordefaults_webdav'};
3378: $changed{'webdav'} = &tool_admin('webdav',$newcustom{'webdav'},
1.479 ! raeburn 3379: \%changeHash,'authordefaults');
1.470 raeburn 3380: }
1.477 raeburn 3381: if ($env{'for.customarchive'} == 1) {
3382: $newcustom{'archive'} = $env{'form.authordefaults_archive'};
3383: $changed{'archive'} = &tool_admin('archive',$newcustom{'archive'},
1.479 ! raeburn 3384: \%changeHash,'authordefaults');
1.477 raeburn 3385:
3386: }
1.275 raeburn 3387: }
1.334 raeburn 3388: if ($canmodify_status{'inststatus'}) {
3389: if (exists($env{'form.inststatus'})) {
3390: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3391: if (@inststatuses > 0) {
3392: $changeHash{'inststatus'} = join(',',@inststatuses);
3393: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 3394: }
3395: }
1.232 raeburn 3396: }
1.334 raeburn 3397: if (keys(%changed)) {
3398: foreach my $item (@userinfo) {
3399: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 3400: }
1.267 raeburn 3401: my $chgresult =
3402: &Apache::lonnet::put('environment',\%changeHash,
3403: $env{'form.ccdomain'},$env{'form.ccuname'});
1.470 raeburn 3404: }
1.232 raeburn 3405: }
1.454 raeburn 3406: $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
1.219 raeburn 3407: &Apache::lonnet::hostname($uhome));
1.101 albertel 3408: } elsif (($env{'form.login'} ne 'nochange') &&
3409: ($env{'form.login'} ne '' )) {
1.27 matthew 3410: # Modify user privileges
3411: if (! $amode || ! $genpwd) {
1.193 raeburn 3412: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 3413: return;
1.20 harris41 3414: }
1.395 bisitz 3415: # Only allow authentication modification if the person has authority
1.101 albertel 3416: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 3417: $r->print('Modifying authentication: '.
1.31 matthew 3418: &Apache::lonnet::modifyuserauth(
1.101 albertel 3419: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 3420: $amode,$genpwd));
1.454 raeburn 3421: $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
1.101 albertel 3422: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 3423: } else {
1.27 matthew 3424: # Okay, this is a non-fatal error.
1.452 raeburn 3425: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 3426: }
1.451 raeburn 3427: } elsif (($env{'form.intarg'} ne '') &&
3428: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
3429: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3430: $r->print('Modifying authentication: '.
3431: &Apache::lonnet::modifyuserauth(
3432: $env{'form.ccdomain'},$env{'form.ccuname'},
3433: 'internal',$env{'form.intarg'}));
1.28 matthew 3434: }
1.344 bisitz 3435: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3436: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3437: ##
1.375 raeburn 3438: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3439: if ($context eq 'course') {
1.375 raeburn 3440: ($cnum,$cdom) =
3441: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3442: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3443: if ($showcredits) {
3444: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3445: }
1.213 raeburn 3446: }
1.101 albertel 3447: if (! $env{'form.makeuser'} ) {
1.28 matthew 3448: # Check for need to change
3449: my %userenv = &Apache::lonnet::get
1.134 raeburn 3450: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3451: 'id','permanentemail','portfolioquota','authorquota','inststatus',
1.459 raeburn 3452: 'tools.aboutme','tools.blog','tools.webdav',
1.470 raeburn 3453: 'tools.portfolio','tools.timezone','tools.portaccess',
1.477 raeburn 3454: 'authormanagers','authoreditors','authorarchive','requestauthor',
1.361 raeburn 3455: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3456: 'requestcourses.community','requestcourses.textbook',
1.470 raeburn 3457: 'requestcourses.placement','requestcourses.lti',
1.384 raeburn 3458: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3459: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.471 raeburn 3460: 'reqcrsotherdom.placement','domcoord.author'],
1.160 raeburn 3461: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3462: my ($tmp) = keys(%userenv);
3463: if ($tmp =~ /^(con_lost|error)/i) {
3464: %userenv = ();
3465: }
1.471 raeburn 3466: unless (($userenv{'domcoord.author'} eq 'blocked') &&
3467: (($env{'user.name'} ne $env{'form.ccuname'}) ||
3468: ($env{'user.domain'} ne $env{'form.ccdomain'}))) {
3469: push(@authordefaults,'managers');
3470: }
1.206 raeburn 3471: my $no_forceid_alert;
3472: # Check to see if user information can be changed
3473: my %domconfig =
3474: &Apache::lonnet::get_dom('configuration',['usermodification'],
3475: $env{'form.ccdomain'});
1.213 raeburn 3476: my @statuses = ('active','future');
3477: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3478: my ($auname,$audom);
1.220 raeburn 3479: if ($context eq 'author') {
1.206 raeburn 3480: $auname = $env{'user.name'};
3481: $audom = $env{'user.domain'};
3482: }
3483: foreach my $item (keys(%roles)) {
1.220 raeburn 3484: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3485: if ($context eq 'course') {
3486: if ($cnum ne '' && $cdom ne '') {
3487: if ($rolenum eq $cnum && $roledom eq $cdom) {
3488: if (!grep(/^\Q$role\E$/,@userroles)) {
3489: push(@userroles,$role);
3490: }
3491: }
3492: }
3493: } elsif ($context eq 'author') {
3494: if ($rolenum eq $auname && $roledom eq $audom) {
1.461 raeburn 3495: if (!grep(/^\Q$role\E$/,@userroles)) {
1.206 raeburn 3496: push(@userroles,$role);
3497: }
3498: }
3499: }
3500: }
1.220 raeburn 3501: if ($env{'form.action'} eq 'singlestudent') {
3502: if (!grep(/^st$/,@userroles)) {
3503: push(@userroles,'st');
3504: }
3505: } else {
3506: # Check for course or co-author roles being activated or re-enabled
3507: if ($context eq 'author' || $context eq 'course') {
3508: foreach my $key (keys(%env)) {
3509: if ($context eq 'author') {
3510: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3511: if (!grep(/^\Q$1\E$/,@userroles)) {
3512: push(@userroles,$1);
3513: }
3514: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3515: if (!grep(/^\Q$1\E$/,@userroles)) {
3516: push(@userroles,$1);
3517: }
1.206 raeburn 3518: }
1.220 raeburn 3519: } elsif ($context eq 'course') {
3520: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3521: if (!grep(/^\Q$1\E$/,@userroles)) {
3522: push(@userroles,$1);
3523: }
3524: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3525: if (!grep(/^\Q$1\E$/,@userroles)) {
3526: push(@userroles,$1);
3527: }
1.206 raeburn 3528: }
3529: }
3530: }
3531: }
3532: }
3533: #Check to see if we can change personal data for the user
3534: my (@mod_disallowed,@longroles);
3535: foreach my $role (@userroles) {
3536: if ($role eq 'cr') {
3537: push(@longroles,'Custom');
3538: } else {
1.318 raeburn 3539: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3540: }
3541: }
1.219 raeburn 3542: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3543: foreach my $item (@userinfo) {
1.28 matthew 3544: # Strip leading and trailing whitespace
1.203 raeburn 3545: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3546: if (!$canmodify{$item}) {
1.207 raeburn 3547: if (defined($env{'form.c'.$item})) {
3548: if ($env{'form.c'.$item} ne $userenv{$item}) {
3549: push(@mod_disallowed,$item);
3550: }
1.206 raeburn 3551: }
3552: $env{'form.c'.$item} = $userenv{$item};
3553: }
1.28 matthew 3554: }
1.259 bisitz 3555: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3556: my $forceid = $env{'form.forceid'};
3557: my $recurseid = $env{'form.recurseid'};
3558: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3559: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3560: $env{'form.ccuname'});
3561: if (($uidhash{$env{'form.ccuname'}}) &&
3562: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3563: (!$forceid)) {
3564: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3565: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3566: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3567: .'<br />'
3568: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3569: .'<br />'."\n";
1.203 raeburn 3570: }
3571: }
3572: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3573: my $checkhash;
3574: my $checks = { 'id' => 1 };
3575: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3576: { 'newuser' => $newuser,
3577: 'id' => $env{'form.cid'},
3578: };
3579: &Apache::loncommon::user_rule_check($checkhash,$checks,
3580: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3581: if (ref($alerts{'id'}) eq 'HASH') {
3582: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3583: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3584: }
3585: }
3586: }
1.378 raeburn 3587: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3588: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3589: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3590: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3591: @disporder = ('inststatus');
3592: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.470 raeburn 3593: push(@disporder,('requestcourses','requestauthor','authordefaults'));
1.334 raeburn 3594: } else {
3595: push(@disporder,'reqcrsotherdom');
3596: }
3597: push(@disporder,('quota','tools'));
1.338 raeburn 3598: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3599: foreach my $name ('portfolio','author') {
3600: ($olddefquota{$name},$oldsettingstatus{$name}) =
3601: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3602: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3603: }
1.334 raeburn 3604: my %canshow;
1.220 raeburn 3605: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3606: $canshow{'quota'} = 1;
1.220 raeburn 3607: }
1.267 raeburn 3608: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3609: $canshow{'tools'} = 1;
1.267 raeburn 3610: }
1.275 raeburn 3611: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3612: $canshow{'requestcourses'} = 1;
1.300 raeburn 3613: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3614: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3615: }
1.286 raeburn 3616: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3617: $canshow{'inststatus'} = 1;
1.286 raeburn 3618: }
1.362 raeburn 3619: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3620: $canshow{'requestauthor'} = 1;
1.470 raeburn 3621: $canshow{'authordefaults'} = 1;
1.362 raeburn 3622: }
1.267 raeburn 3623: my (%changeHash,%changed);
1.286 raeburn 3624: if ($oldinststatus eq '') {
1.334 raeburn 3625: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3626: } else {
3627: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3628: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3629: } else {
1.334 raeburn 3630: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3631: }
3632: }
3633: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3634: if ($canmodify_status{'inststatus'}) {
3635: $canshow{'inststatus'} = 1;
1.286 raeburn 3636: if (exists($env{'form.inststatus'})) {
3637: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3638: if (@inststatuses > 0) {
3639: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3640: $changeHash{'inststatus'} = $newinststatus;
3641: if ($newinststatus ne $oldinststatus) {
3642: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3643: foreach my $name ('portfolio','author') {
3644: ($newdefquota{$name},$newsettingstatus{$name}) =
3645: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3646: }
1.286 raeburn 3647: }
3648: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3649: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3650: } else {
1.337 raeburn 3651: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3652: }
1.334 raeburn 3653: }
3654: } else {
3655: $newinststatus = '';
3656: $changeHash{'inststatus'} = $newinststatus;
3657: $newsettings{'inststatus'} = $othertitle;
3658: if ($newinststatus ne $oldinststatus) {
3659: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3660: foreach my $name ('portfolio','author') {
3661: ($newdefquota{$name},$newsettingstatus{$name}) =
3662: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3663: }
1.286 raeburn 3664: }
3665: }
1.334 raeburn 3666: } elsif ($context ne 'selfcreate') {
3667: $canshow{'inststatus'} = 1;
1.337 raeburn 3668: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3669: }
1.378 raeburn 3670: foreach my $name ('portfolio','author') {
3671: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3672: }
1.334 raeburn 3673: if ($context eq 'domain') {
1.378 raeburn 3674: foreach my $name ('portfolio','author') {
3675: if ($userenv{$name.'quota'} ne '') {
3676: $oldquota{$name} = $userenv{$name.'quota'};
3677: if ($env{'form.custom_'.$name.'quota'} == 1) {
3678: if ($env{'form.'.$name.'quota'} eq '') {
3679: $newquota{$name} = 0;
3680: } else {
3681: $newquota{$name} = $env{'form.'.$name.'quota'};
3682: $newquota{$name} =~ s/[^\d\.]//g;
3683: }
3684: if ($newquota{$name} != $oldquota{$name}) {
3685: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3686: $changed{$name.'quota'} = 1;
3687: }
3688: }
1.334 raeburn 3689: } else {
1.378 raeburn 3690: if ("a_admin('',\%changeHash,$name)) {
3691: $changed{$name.'quota'} = 1;
3692: $newquota{$name} = $newdefquota{$name};
3693: $newisdefault{$name} = 1;
3694: }
1.334 raeburn 3695: }
1.149 raeburn 3696: } else {
1.378 raeburn 3697: $oldisdefault{$name} = 1;
3698: $oldquota{$name} = $olddefquota{$name};
3699: if ($env{'form.custom_'.$name.'quota'} == 1) {
3700: if ($env{'form.'.$name.'quota'} eq '') {
3701: $newquota{$name} = 0;
3702: } else {
3703: $newquota{$name} = $env{'form.'.$name.'quota'};
3704: $newquota{$name} =~ s/[^\d\.]//g;
3705: }
3706: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3707: $changed{$name.'quota'} = 1;
3708: }
1.334 raeburn 3709: } else {
1.378 raeburn 3710: $newquota{$name} = $newdefquota{$name};
3711: $newisdefault{$name} = 1;
1.334 raeburn 3712: }
1.378 raeburn 3713: }
3714: if ($oldisdefault{$name}) {
3715: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3716: } else {
3717: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3718: }
3719: if ($newisdefault{$name}) {
3720: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3721: } else {
3722: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3723: }
3724: }
1.334 raeburn 3725: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3726: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3727: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3728: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3729: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.470 raeburn 3730: my ($isadv,$isauthor) =
3731: &Apache::lonnet::is_advanced_user($env{'form.ccdomain'},$env{'form.ccuname'});
3732: unless ($isauthor) {
3733: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3734: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3735: }
3736: &tool_changes('authordefaults',\@authordefaults,\%oldsettings,\%oldsettingstext,
3737: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3738: } else {
1.334 raeburn 3739: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3740: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3741: }
3742: }
1.334 raeburn 3743: foreach my $item (@userinfo) {
3744: if ($env{'form.c'.$item} ne $userenv{$item}) {
3745: $namechanged{$item} = 1;
3746: }
1.204 raeburn 3747: }
1.378 raeburn 3748: foreach my $name ('portfolio','author') {
1.390 bisitz 3749: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3750: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3751: }
1.334 raeburn 3752: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3753: my ($chgresult,$namechgresult);
3754: if (keys(%changed) > 0) {
1.470 raeburn 3755: $chgresult =
1.204 raeburn 3756: &Apache::lonnet::put('environment',\%changeHash,
3757: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3758: if ($chgresult eq 'ok') {
1.470 raeburn 3759: my ($ca_mgr_del,%ca_mgr_add);
3760: if ($changed{'managers'}) {
3761: my (@adds,@dels);
3762: if ($changeHash{'authormanagers'} eq '') {
3763: @dels = split(/,/,$userenv{'authormanagers'});
3764: } elsif ($userenv{'authormanagers'} eq '') {
3765: @adds = split(/,/,$changeHash{'authormanagers'});
3766: } else {
3767: my @old = split(/,/,$userenv{'authormanagers'});
3768: my @new = split(/,/,$changeHash{'authormanagers'});
3769: my @diffs = &Apache::loncommon::compare_arrays(\@old,\@new);
3770: if (@diffs) {
3771: foreach my $user (@diffs) {
3772: if (grep(/^\Q$user\E$/,@old)) {
3773: push(@dels,$user);
3774: } elsif (grep(/^\Q$user\E$/,@new)) {
3775: push(@adds,$user);
3776: }
3777: }
3778: }
3779: }
3780: my $key = "internal.manager./$env{'form.ccdomain'}/$env{'form.ccuname'}";
3781: if (@dels) {
3782: foreach my $user (@dels) {
3783: if ($user =~ /^($match_username):($match_domain)$/) {
3784: &Apache::lonnet::del('environment',[$key],$2,$1);
3785: }
3786: }
3787: my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
3788: if (grep(/^\Q$curruser\E$/,@dels)) {
3789: $ca_mgr_del = $key;
3790: }
3791: }
3792: if (@adds) {
3793: foreach my $user (@adds) {
3794: if ($user =~ /^($match_username):($match_domain)$/) {
3795: &Apache::lonnet::put('environment',{$key => 1},$2,$1);
3796: }
3797: }
3798: my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
3799: if (grep(/^\Q$curruser\E$/,@adds)) {
3800: $ca_mgr_add{$key} = 1;
3801: }
3802: }
3803: }
1.267 raeburn 3804: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3805: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.474 raeburn 3806: my (%newenvhash,$got_domdefs,%domdefaults,$got_userenv,
3807: %userenv);
3808: my @fromenv = keys(%changed);
3809: push(@fromenv,'inststatus');
1.270 raeburn 3810: foreach my $key (keys(%changed)) {
1.411 raeburn 3811: if (($key eq 'official') || ($key eq 'unofficial') ||
3812: ($key eq 'community') || ($key eq 'textbook') ||
1.449 raeburn 3813: ($key eq 'placement') || ($key eq 'lti')) {
1.279 raeburn 3814: $newenvhash{'environment.requestcourses.'.$key} =
3815: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3816: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3817: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3818: } else {
1.474 raeburn 3819: unless ($got_domdefs) {
3820: %domdefaults =
3821: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3822: $got_domdefs = 1;
3823: }
3824: unless ($got_userenv) {
3825: %userenv =
3826: &Apache::lonnet::userenvironment($env{'user.domain'},
3827: $env{'user.name'},@fromenv);
3828: $got_userenv = 1;
3829: }
1.279 raeburn 3830: $newenvhash{'environment.canrequest.'.$key} =
3831: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.474 raeburn 3832: $key,'reload','requestcourses',\%userenv,\%domdefaults);
1.279 raeburn 3833: }
1.362 raeburn 3834: } elsif ($key eq 'requestauthor') {
3835: $newenvhash{'environment.'.$key} = $changeHash{$key};
3836: if ($changeHash{$key}) {
3837: $newenvhash{'environment.canrequest.author'} = 1;
3838: } else {
1.474 raeburn 3839: unless ($got_domdefs) {
3840: %domdefaults =
3841: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3842: $got_domdefs = 1;
3843: }
3844: unless ($got_userenv) {
3845: %userenv =
3846: &Apache::lonnet::userenvironment($env{'user.domain'},
3847: $env{'user.name'},@fromenv);
3848: $got_userenv = 1;
3849: }
1.362 raeburn 3850: $newenvhash{'environment.canrequest.author'} =
3851: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.474 raeburn 3852: $key,'reload','requestauthor',\%userenv,\%domdefaults);
1.362 raeburn 3853: }
1.470 raeburn 3854: } elsif ($key eq 'editors') {
3855: $newenvhash{'environment.author'.$key} = $changeHash{'author'.$key};
1.474 raeburn 3856: if ($env{'form.customeditors'}) {
3857: $newenvhash{'environment.editors'} = $changeHash{'author'.$key};
3858: } else {
3859: unless ($got_domdefs) {
3860: %domdefaults =
3861: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3862: $got_domdefs = 1;
3863: }
3864: if ($domdefaults{'editors'} ne '') {
3865: $newenvhash{'environment.editors'} = $domdefaults{'editors'};
1.470 raeburn 3866: } else {
1.474 raeburn 3867: $newenvhash{'environment.editors'} = 'edit,xml';
1.470 raeburn 3868: }
3869: }
1.275 raeburn 3870: } elsif ($key ne 'quota') {
1.270 raeburn 3871: $newenvhash{'environment.tools.'.$key} =
3872: $changeHash{'tools.'.$key};
1.279 raeburn 3873: if ($changeHash{'tools.'.$key} ne '') {
3874: $newenvhash{'environment.availabletools.'.$key} =
3875: $changeHash{'tools.'.$key};
3876: } else {
1.474 raeburn 3877: unless ($got_domdefs) {
3878: %domdefaults =
3879: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3880: $got_domdefs = 1;
3881: }
3882: unless ($got_userenv) {
3883: %userenv =
3884: &Apache::lonnet::userenvironment($env{'user.domain'},
3885: $env{'user.name'},@fromenv);
3886: $got_userenv = 1;
3887: }
1.279 raeburn 3888: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3889: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.474 raeburn 3890: $key,'reload','tools',\%userenv,\%domdefaults);
1.279 raeburn 3891: }
1.270 raeburn 3892: }
3893: }
1.271 raeburn 3894: if (keys(%newenvhash)) {
3895: &Apache::lonnet::appenv(\%newenvhash);
3896: }
1.470 raeburn 3897: } else {
3898: if ($ca_mgr_del) {
3899: &Apache::lonnet::delenv($ca_mgr_del);
3900: }
3901: if (keys(%ca_mgr_add)) {
3902: &Apache::lonnet::appenv(\%ca_mgr_add);
3903: }
1.267 raeburn 3904: }
1.463 raeburn 3905: if ($changed{'aboutme'}) {
3906: &Apache::loncommon::devalidate_aboutme_cache($env{'form.ccuname'},
3907: $env{'form.ccdomain'});
3908: }
1.267 raeburn 3909: }
1.204 raeburn 3910: }
1.334 raeburn 3911: if (keys(%namechanged) > 0) {
1.337 raeburn 3912: foreach my $field (@userinfo) {
3913: $changeHash{$field} = $env{'form.c'.$field};
3914: }
3915: # Make the change
1.204 raeburn 3916: $namechgresult =
3917: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3918: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3919: $changeHash{'firstname'},$changeHash{'middlename'},
3920: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3921: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3922: %userupdate = (
3923: lastname => $env{'form.clastname'},
3924: middlename => $env{'form.cmiddlename'},
3925: firstname => $env{'form.cfirstname'},
3926: generation => $env{'form.cgeneration'},
3927: id => $env{'form.cid'},
3928: );
1.204 raeburn 3929: }
1.334 raeburn 3930: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3931: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3932: # Tell the user we changed the name
1.334 raeburn 3933: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3934: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3935: \%oldsettings, \%oldsettingstext,\%newsettings,
3936: \%newsettingstext);
1.203 raeburn 3937: if ($env{'form.cid'} ne $userenv{'id'}) {
3938: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3939: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3940: if (($recurseid) &&
3941: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3942: my $idresult =
3943: &Apache::lonuserutils::propagate_id_change(
3944: $env{'form.ccuname'},$env{'form.ccdomain'},
3945: \%userupdate);
3946: $r->print('<br />'.$idresult.'<br />');
3947: }
1.196 raeburn 3948: }
1.149 raeburn 3949: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3950: ($env{'form.ccuname'} eq $env{'user.name'})) {
3951: my %newenvhash;
3952: foreach my $key (keys(%changeHash)) {
3953: $newenvhash{'environment.'.$key} = $changeHash{$key};
3954: }
1.238 raeburn 3955: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3956: }
1.28 matthew 3957: } else { # error occurred
1.389 bisitz 3958: $r->print(
3959: '<p class="LC_error">'
3960: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3961: '"'.$env{'form.ccuname'}.'"',
3962: '"'.$env{'form.ccdomain'}.'"')
3963: .'</p>');
1.28 matthew 3964: }
1.334 raeburn 3965: } else { # End of if ($env ... ) logic
1.275 raeburn 3966: # They did not want to change the users name, quota, tool availability,
3967: # or ability to request creation of courses,
1.267 raeburn 3968: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3969: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3970: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3971: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3972: }
1.206 raeburn 3973: if (@mod_disallowed) {
3974: my ($rolestr,$contextname);
3975: if (@longroles > 0) {
3976: $rolestr = join(', ',@longroles);
3977: } else {
3978: $rolestr = &mt('No roles');
3979: }
3980: if ($context eq 'course') {
1.399 bisitz 3981: $contextname = 'course';
1.206 raeburn 3982: } elsif ($context eq 'author') {
1.399 bisitz 3983: $contextname = 'co-author';
1.206 raeburn 3984: }
3985: $r->print(&mt('The following fields were not updated: ').'<ul>');
3986: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3987: foreach my $field (@mod_disallowed) {
3988: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3989: }
1.207 raeburn 3990: $r->print('</ul>');
3991: if (@mod_disallowed == 1) {
1.399 bisitz 3992: $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 3993: } else {
1.399 bisitz 3994: $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 3995: }
1.292 bisitz 3996: my $helplink = 'javascript:helpMenu('."'display'".')';
3997: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3998: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3999: ,'<a href="'.$helplink.'">','</a>')
4000: .'<br />');
1.206 raeburn 4001: }
1.259 bisitz 4002: $r->print('<span class="LC_warning">'
4003: .$no_forceid_alert
4004: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
4005: .'</span>');
1.4 www 4006: }
1.367 golterma 4007: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 4008: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 4009: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
4010: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 4011: my $linktext = ($crstype eq 'Community' ?
4012: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
4013: $r->print(
4014: &Apache::lonhtmlcommon::actionbox([
4015: '<a href="javascript:backPage(document.userupdate)">'
4016: .($crstype eq 'Community' ?
4017: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
4018: .'</a>']));
1.220 raeburn 4019: } else {
1.375 raeburn 4020: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 4021: if (keys(%namechanged) > 0) {
1.220 raeburn 4022: if ($context eq 'course') {
4023: if (@userroles > 0) {
1.225 raeburn 4024: if ((@rolechanges == 0) ||
4025: (!(grep(/^st$/,@rolechanges)))) {
4026: if (grep(/^st$/,@userroles)) {
4027: my $classlistupdated =
4028: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 4029: $cnum,$env{'form.ccdomain'},
4030: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 4031: }
1.220 raeburn 4032: }
4033: }
4034: }
4035: }
1.226 raeburn 4036: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 4037: $env{'form.ccdomain'});
4038: if ($env{'form.popup'}) {
4039: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
4040: } else {
1.367 golterma 4041: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
4042: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
4043: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 4044: }
1.220 raeburn 4045: }
4046: }
4047:
1.334 raeburn 4048: sub display_userinfo {
1.362 raeburn 4049: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
4050: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 4051: $newsetting,$newsettingtext) = @_;
4052: return unless (ref($order) eq 'ARRAY' &&
4053: ref($canshow) eq 'HASH' &&
4054: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 4055: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 4056: ref($usertools) eq 'ARRAY' &&
4057: ref($userenv) eq 'HASH' &&
4058: ref($changedhash) eq 'HASH' &&
4059: ref($oldsetting) eq 'HASH' &&
4060: ref($oldsettingtext) eq 'HASH' &&
4061: ref($newsetting) eq 'HASH' &&
4062: ref($newsettingtext) eq 'HASH');
4063: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 4064: 'ui' => 'User Information',
1.334 raeburn 4065: 'uic' => 'User Information Changed',
4066: 'firstname' => 'First Name',
4067: 'middlename' => 'Middle Name',
4068: 'lastname' => 'Last Name',
4069: 'generation' => 'Generation',
4070: 'id' => 'Student/Employee ID',
4071: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 4072: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 4073: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 4074: 'blog' => 'Blog Availability',
1.361 raeburn 4075: 'webdav' => 'WebDAV Availability',
1.334 raeburn 4076: 'aboutme' => 'Personal Information Page Availability',
4077: 'portfolio' => 'Portfolio Availability',
1.470 raeburn 4078: 'portaccess' => 'Portfolio Shareable',
1.459 raeburn 4079: 'timezone' => 'Can set own Time Zone',
1.334 raeburn 4080: 'official' => 'Can Request Official Courses',
4081: 'unofficial' => 'Can Request Unofficial Courses',
4082: 'community' => 'Can Request Communities',
1.384 raeburn 4083: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 4084: 'placement' => 'Can Request Placement Tests',
1.449 raeburn 4085: 'lti' => 'Can Request LTI Courses',
1.362 raeburn 4086: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 4087: 'inststatus' => "Affiliation",
4088: 'prvs' => 'Previous Value:',
1.470 raeburn 4089: 'chto' => 'Changed To:',
4090: 'editors' => "Available Editors in Authoring Space",
1.473 raeburn 4091: 'managers' => "Co-authors who can add/revoke roles",
1.477 raeburn 4092: 'archive' => "Managers can download tar.gz file of Authoring Space",
1.470 raeburn 4093: 'edit' => 'Standard editor (Edit)',
4094: 'xml' => 'Text editor (EditXML)',
4095: 'daxe' => 'Daxe editor (Daxe)',
1.334 raeburn 4096: );
4097: if ($changed) {
1.372 raeburn 4098: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 4099: &Apache::loncommon::start_data_table().
4100: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 4101: $r->print("<th> </th>\n");
1.367 golterma 4102: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
4103: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
4104: $r->print(&Apache::loncommon::end_data_table_header_row());
4105: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
4106:
1.334 raeburn 4107: foreach my $item (@userinfo) {
4108: my $value = $env{'form.c'.$item};
1.367 golterma 4109: #show changes only:
1.383 raeburn 4110: unless ($value eq $userenv->{$item}){
1.367 golterma 4111: $r->print(&Apache::loncommon::start_data_table_row());
4112: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 4113: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 4114: $r->print("<td>$value </td>\n");
4115: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 4116: }
4117: }
4118: foreach my $entry (@{$order}) {
1.383 raeburn 4119: if ($canshow->{$entry}) {
1.470 raeburn 4120: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') ||
4121: ($entry eq 'requestauthor') || ($entry eq 'authordefaults')) {
1.383 raeburn 4122: my @items;
4123: if ($entry eq 'requestauthor') {
4124: @items = ($entry);
1.470 raeburn 4125: } elsif ($entry eq 'authordefaults') {
1.477 raeburn 4126: @items = ('webdav','managers','editors','archive');
1.383 raeburn 4127: } else {
4128: @items = @{$requestcourses};
1.384 raeburn 4129: }
1.383 raeburn 4130: foreach my $item (@items) {
4131: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
4132: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
4133: $r->print(&Apache::loncommon::start_data_table_row()."\n");
1.470 raeburn 4134: $r->print("<td>$lt{$item}</td><td>\n");
4135: unless ($item eq 'managers') {
4136: $r->print($oldsetting->{$item});
4137: }
1.383 raeburn 4138: if ($oldsettingtext->{$item}) {
4139: if ($oldsetting->{$item}) {
1.470 raeburn 4140: unless ($item eq 'managers') {
4141: $r->print(' -- ');
4142: }
1.383 raeburn 4143: }
4144: $r->print($oldsettingtext->{$item});
4145: }
1.470 raeburn 4146: $r->print("</td>\n<td>");
4147: unless ($item eq 'managers') {
4148: $r->print($newsetting->{$item});
4149: }
1.383 raeburn 4150: if ($newsettingtext->{$item}) {
4151: if ($newsetting->{$item}) {
1.470 raeburn 4152: unless ($item eq 'managers') {
4153: $r->print(' -- ');
4154: }
1.383 raeburn 4155: }
4156: $r->print($newsettingtext->{$item});
4157: }
4158: $r->print("</td>\n");
4159: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4160: }
4161: }
4162: } elsif ($entry eq 'tools') {
4163: foreach my $item (@{$usertools}) {
1.383 raeburn 4164: if ($newsetting->{$item} ne $oldsetting->{$item}) {
4165: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4166: $r->print("<td>$lt{$item}</td>\n");
4167: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
4168: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
4169: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4170: }
4171: }
1.378 raeburn 4172: } elsif ($entry eq 'quota') {
4173: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
4174: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
4175: foreach my $name ('portfolio','author') {
1.383 raeburn 4176: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
4177: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4178: $r->print("<td>$lt{$name.$entry}</td>\n");
4179: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
4180: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
4181: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 4182: }
4183: }
4184: }
1.334 raeburn 4185: } else {
1.383 raeburn 4186: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
4187: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4188: $r->print("<td>$lt{$entry}</td>\n");
4189: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
4190: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
4191: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4192: }
4193: }
4194: }
4195: }
1.367 golterma 4196: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 4197: } else {
4198: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
4199: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 4200: }
4201: return;
4202: }
4203:
1.275 raeburn 4204: sub tool_changes {
4205: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
4206: $changed,$newaccess,$newaccesstext) = @_;
4207: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
4208: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
4209: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
4210: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
4211: return;
4212: }
1.383 raeburn 4213: my %reqdisplay = &requestchange_display();
1.300 raeburn 4214: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 4215: my @options = ('approval','validate','autolimit');
1.306 raeburn 4216: my $optregex = join('|',@options);
1.300 raeburn 4217: my $cdom = $env{'request.role.domain'};
4218: foreach my $tool (@{$usertools}) {
1.383 raeburn 4219: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 4220: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 4221: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 4222: my ($newop,$limit);
1.314 raeburn 4223: if ($env{'form.'.$context.'_'.$tool}) {
4224: $newop = $env{'form.'.$context.'_'.$tool};
4225: if ($newop eq 'autolimit') {
1.383 raeburn 4226: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 4227: $limit =~ s/\D+//g;
4228: $newop .= '='.$limit;
4229: }
4230: }
1.300 raeburn 4231: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 4232: if ($newop) {
4233: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 4234: $changeHash,$context);
4235: if ($changed->{$tool}) {
1.383 raeburn 4236: if ($newop =~ /^autolimit/) {
4237: if ($limit) {
4238: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4239: } else {
4240: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4241: }
4242: } else {
4243: $newaccesstext->{$tool} = $reqdisplay{$newop};
4244: }
1.300 raeburn 4245: } else {
4246: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
4247: }
4248: }
4249: } else {
4250: my @curr = split(',',$userenv->{$context.'.'.$tool});
4251: my @new;
4252: my $changedoms;
1.314 raeburn 4253: foreach my $req (@curr) {
4254: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
4255: my $oldop = $1;
1.383 raeburn 4256: if ($oldop =~ /^autolimit=(\d*)/) {
4257: my $limit = $1;
4258: if ($limit) {
4259: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4260: } else {
4261: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4262: }
4263: } else {
4264: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
4265: }
1.314 raeburn 4266: if ($oldop ne $newop) {
4267: $changedoms = 1;
4268: foreach my $item (@curr) {
4269: my ($reqdom,$option) = split(':',$item);
4270: unless ($reqdom eq $cdom) {
4271: push(@new,$item);
4272: }
4273: }
4274: if ($newop) {
4275: push(@new,$cdom.':'.$newop);
1.300 raeburn 4276: }
1.314 raeburn 4277: @new = sort(@new);
1.300 raeburn 4278: }
1.314 raeburn 4279: last;
1.300 raeburn 4280: }
1.314 raeburn 4281: }
4282: if ((!$changedoms) && ($newop)) {
1.300 raeburn 4283: $changedoms = 1;
1.306 raeburn 4284: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 4285: }
4286: if ($changedoms) {
1.314 raeburn 4287: my $newdomstr;
1.300 raeburn 4288: if (@new) {
4289: $newdomstr = join(',',@new);
4290: }
4291: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
4292: $context);
4293: if ($changed->{$tool}) {
4294: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 4295: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 4296: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
4297: $limit =~ s/\D+//g;
4298: if ($limit) {
1.383 raeburn 4299: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 4300: } else {
1.383 raeburn 4301: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 4302: }
1.314 raeburn 4303: } else {
1.306 raeburn 4304: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
4305: }
1.300 raeburn 4306: } else {
1.383 raeburn 4307: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 4308: }
4309: }
4310: }
4311: }
4312: }
4313: return;
4314: }
1.470 raeburn 4315: my %tooldesc = &Apache::lonlocal::texthash(
4316: 'edit' => 'Standard editor (Edit)',
4317: 'xml' => 'Text editor (EditXML)',
4318: 'daxe' => 'Daxe editor (Daxe)',
4319: );
1.275 raeburn 4320: foreach my $tool (@{$usertools}) {
1.383 raeburn 4321: my ($newval,$limit,$envkey);
1.362 raeburn 4322: $envkey = $context.'.'.$tool;
1.306 raeburn 4323: if ($context eq 'requestcourses') {
4324: $newval = $env{'form.crsreq_'.$tool};
4325: if ($newval eq 'autolimit') {
1.383 raeburn 4326: $limit = $env{'form.crsreq_'.$tool.'_limit'};
4327: $limit =~ s/\D+//g;
4328: $newval .= '='.$limit;
1.306 raeburn 4329: }
1.362 raeburn 4330: } elsif ($context eq 'requestauthor') {
4331: $newval = $env{'form.'.$context};
4332: $envkey = $context;
1.470 raeburn 4333: } elsif ($context eq 'authordefaults') {
4334: if ($tool eq 'editors') {
4335: $envkey = 'authoreditors';
4336: if ($env{'form.customeditors'} == 1) {
4337: my @editors;
4338: my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
4339: if (@posseditors) {
4340: foreach my $editor (@posseditors) {
4341: if (grep(/^\Q$editor\E$/,@posseditors)) {
4342: unless (grep(/^\Q$editor\E$/,@editors)) {
4343: push(@editors,$editor);
4344: }
4345: }
4346: }
4347: }
4348: if (@editors) {
4349: $newval = join(',',(sort(@editors)));
4350: }
4351: }
4352: } elsif ($tool eq 'managers') {
4353: $envkey = 'authormanagers';
4354: my @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
4355: if (@possibles) {
4356: my %ca_roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},
4357: undef,['active','future'],['ca']);
4358: if (keys(%ca_roles)) {
4359: my @custommanagers;
4360: foreach my $user (@possibles) {
4361: if ($user =~ /^($match_username):($match_domain)$/) {
4362: if (exists($ca_roles{$user.':ca'})) {
4363: unless ($user eq $env{'form.ccuname'}.':'.$env{'form.ccdomain'}) {
4364: push(@custommanagers,$user);
4365: }
4366: }
4367: }
4368: }
4369: if (@custommanagers) {
4370: $newval = join(',',sort(@custommanagers));
4371: }
4372: }
4373: }
4374: } elsif ($tool eq 'webdav') {
4375: $envkey = 'tools.webdav';
4376: $newval = $env{'form.'.$context.'_'.$tool};
1.477 raeburn 4377: } elsif ($tool eq 'archive') {
4378: $envkey = 'authorarchive';
4379: $newval = $env{'form.'.$context.'_'.$tool};
1.470 raeburn 4380: }
1.314 raeburn 4381: } else {
1.306 raeburn 4382: $newval = $env{'form.'.$context.'_'.$tool};
4383: }
1.362 raeburn 4384: if ($userenv->{$envkey} ne '') {
1.275 raeburn 4385: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 4386: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4387: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
4388: my $currlimit = $1;
4389: if ($currlimit eq '') {
4390: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4391: } else {
4392: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
4393: }
4394: } elsif ($userenv->{$envkey}) {
4395: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
4396: } else {
4397: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4398: }
1.470 raeburn 4399: } elsif ($context eq 'authordefaults') {
4400: if ($tool eq 'managers') {
4401: if ($userenv->{$envkey} eq '') {
4402: $oldaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4403: } else {
4404: my $managers = $userenv->{$envkey};
4405: $managers =~ s/,/, /g;
4406: $oldaccesstext->{$tool} = $managers;
4407: }
4408: } elsif ($tool eq 'editors') {
4409: $oldaccesstext->{$tool} = &mt('can use: [_1]',
4410: join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
1.477 raeburn 4411: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4412: if ($userenv->{$envkey}) {
4413: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
4414: } else {
4415: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4416: }
4417: }
1.275 raeburn 4418: } else {
1.383 raeburn 4419: if ($userenv->{$envkey}) {
4420: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
4421: } else {
4422: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4423: }
1.275 raeburn 4424: }
1.362 raeburn 4425: $changeHash->{$envkey} = $userenv->{$envkey};
1.470 raeburn 4426: if (($env{'form.custom'.$tool} == 1) ||
4427: (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
1.362 raeburn 4428: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 4429: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
4430: $context);
1.275 raeburn 4431: if ($changed->{$tool}) {
4432: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 4433: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4434: if ($newval =~ /^autolimit/) {
4435: if ($limit) {
4436: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4437: } else {
4438: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4439: }
4440: } elsif ($newval) {
4441: $newaccesstext->{$tool} = $reqdisplay{$newval};
4442: } else {
4443: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4444: }
1.470 raeburn 4445: } elsif ($context eq 'authordefaults') {
4446: if ($tool eq 'editors') {
4447: $newaccesstext->{$tool} = &mt('can use: [_1]',
4448: join(', ', map { $tooldesc{$_} } split(/,/,$changeHash->{$envkey})));
4449: } elsif ($tool eq 'managers') {
4450: if ($changeHash->{$envkey} eq '') {
4451: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4452: } else {
4453: my $managers = $changeHash->{$envkey};
4454: $managers =~ s/,/, /g;
4455: $newaccesstext->{$tool} = $managers;
4456: }
1.477 raeburn 4457: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4458: if ($newval) {
4459: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4460: } else {
4461: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4462: }
4463: }
1.275 raeburn 4464: } else {
1.383 raeburn 4465: if ($newval) {
4466: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4467: } else {
4468: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4469: }
1.275 raeburn 4470: }
4471: } else {
4472: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 4473: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.470 raeburn 4474: if ($userenv->{$envkey} =~ /^autolimit/) {
1.383 raeburn 4475: if ($limit) {
4476: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4477: } else {
4478: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4479: }
1.470 raeburn 4480: } elsif ($userenv->{$envkey}) {
4481: $newaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
1.383 raeburn 4482: } else {
4483: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4484: }
1.470 raeburn 4485: } elsif ($context eq 'authordefaults') {
4486: if ($tool eq 'editors') {
4487: $newaccesstext->{$tool} = &mt('can use: [_1]',
4488: join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
4489: } elsif ($tool eq 'managers') {
4490: if ($userenv->{$envkey} eq '') {
4491: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4492: } else {
4493: my $managers = $userenv->{$envkey};
4494: $managers =~ s/,/, /g;
4495: $newaccesstext->{$tool} = $managers;
4496: }
1.477 raeburn 4497: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4498: if ($userenv->{$envkey}) {
4499: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4500: } else {
4501: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4502: }
4503: }
1.275 raeburn 4504: } else {
1.383 raeburn 4505: if ($userenv->{$context.'.'.$tool}) {
4506: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4507: } else {
4508: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4509: }
1.275 raeburn 4510: }
4511: }
4512: } else {
4513: $newaccess->{$tool} = $oldaccess->{$tool};
4514: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
4515: }
4516: } else {
4517: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
4518: if ($changed->{$tool}) {
4519: $newaccess->{$tool} = &mt('default');
4520: } else {
4521: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 4522: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4523: if ($newval =~ /^autolimit/) {
4524: if ($limit) {
4525: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4526: } else {
4527: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4528: }
4529: } elsif ($newval) {
4530: $newaccesstext->{$tool} = $reqdisplay{$newval};
4531: } else {
4532: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4533: }
1.470 raeburn 4534: } elsif ($context eq 'authordefaults') {
4535: if ($tool eq 'editors') {
4536: $newaccesstext->{$tool} = &mt('can use: [_1]',
4537: join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
4538: } elsif ($tool eq 'managers') {
4539: if ($newval eq '') {
4540: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4541: } else {
4542: my $managers = $newval;
4543: $managers =~ s/,/, /g;
4544: $newaccesstext->{$tool} = $managers;
4545: }
1.477 raeburn 4546: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4547: if ($userenv->{$envkey}) {
4548: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4549: } else {
4550: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4551: }
4552: }
1.275 raeburn 4553: } else {
1.383 raeburn 4554: if ($userenv->{$context.'.'.$tool}) {
4555: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4556: } else {
4557: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4558: }
1.275 raeburn 4559: }
4560: }
4561: }
4562: } else {
4563: $oldaccess->{$tool} = &mt('default');
1.470 raeburn 4564: if (($env{'form.custom'.$tool} == 1) ||
4565: (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
1.306 raeburn 4566: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
4567: $context);
1.275 raeburn 4568: if ($changed->{$tool}) {
4569: $newaccess->{$tool} = &mt('custom');
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 'managers') {
4584: if ($newval eq '') {
4585: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4586: } else {
4587: my $managers = $newval;
4588: $managers =~ s/,/, /g;
4589: $newaccesstext->{$tool} = $managers;
4590: }
4591: } elsif ($tool eq 'editors') {
4592: $newaccesstext->{$tool} = &mt('can use: [_1]',
4593: join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
1.477 raeburn 4594: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4595: if ($newval) {
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 ($newval) {
4603: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4604: } else {
4605: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4606: }
1.275 raeburn 4607: }
4608: } else {
4609: $newaccess->{$tool} = $oldaccess->{$tool};
4610: }
4611: } else {
4612: $newaccess->{$tool} = $oldaccess->{$tool};
4613: }
4614: }
4615: }
4616: return;
4617: }
4618:
1.220 raeburn 4619: sub update_roles {
1.375 raeburn 4620: my ($r,$context,$showcredits) = @_;
1.4 www 4621: my $now=time;
1.225 raeburn 4622: my @rolechanges;
1.465 raeburn 4623: my (%disallowed,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.466 raeburn 4624: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.465 raeburn 4625: $got_role_approvals{$context} = '';
4626: $process_by{$context} = {};
4627: my @domroles = &Apache::lonuserutils::domain_roles();
4628: my @cstrroles = &Apache::lonuserutils::construction_space_roles();
4629: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
1.73 sakharuk 4630: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 4631: foreach my $key (keys(%env)) {
1.135 raeburn 4632: next if (! $env{$key});
1.190 raeburn 4633: next if ($key eq 'form.action');
1.27 matthew 4634: # Revoke roles
1.135 raeburn 4635: if ($key=~/^form\.rev/) {
4636: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 4637: # Revoke standard role
1.170 albertel 4638: my ($scope,$role) = ($1,$2);
4639: my $result =
4640: &Apache::lonnet::revokerole($env{'form.ccdomain'},
4641: $env{'form.ccuname'},
1.239 raeburn 4642: $scope,$role,'','',$context);
1.367 golterma 4643: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4644: &mt('Revoking [_1] in [_2]',
4645: &Apache::lonnet::plaintext($role),
1.372 raeburn 4646: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4647: $result ne "ok").'<br />');
4648: if ($result ne "ok") {
4649: $r->print(&mt('Error: [_1]',$result).'<br />');
4650: }
1.170 albertel 4651: if ($role eq 'st') {
1.202 raeburn 4652: my $result =
1.198 raeburn 4653: &Apache::lonuserutils::classlist_drop($scope,
4654: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4655: $now);
1.367 golterma 4656: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 4657: }
1.225 raeburn 4658: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4659: push(@rolechanges,$role);
4660: }
1.196 raeburn 4661: }
1.195 raeburn 4662: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 4663: # Revoke custom role
1.369 bisitz 4664: my $result = &Apache::lonnet::revokecustomrole(
4665: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 4666: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4667: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 4668: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4669: $result ne 'ok').'<br />');
4670: if ($result ne "ok") {
4671: $r->print(&mt('Error: [_1]',$result).'<br />');
4672: }
1.225 raeburn 4673: if (!grep(/^cr$/,@rolechanges)) {
4674: push(@rolechanges,'cr');
4675: }
1.64 www 4676: }
1.135 raeburn 4677: } elsif ($key=~/^form\.del/) {
4678: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 4679: # Delete standard role
1.170 albertel 4680: my ($scope,$role) = ($1,$2);
4681: my $result =
4682: &Apache::lonnet::assignrole($env{'form.ccdomain'},
4683: $env{'form.ccuname'},
1.239 raeburn 4684: $scope,$role,$now,0,1,'',
4685: $context);
1.367 golterma 4686: $r->print(&Apache::lonhtmlcommon::confirm_success(
4687: &mt('Deleting [_1] in [_2]',
1.369 bisitz 4688: &Apache::lonnet::plaintext($role),
1.372 raeburn 4689: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4690: $result ne 'ok').'<br />');
4691: if ($result ne "ok") {
4692: $r->print(&mt('Error: [_1]',$result).'<br />');
4693: }
1.367 golterma 4694:
1.170 albertel 4695: if ($role eq 'st') {
1.202 raeburn 4696: my $result =
1.198 raeburn 4697: &Apache::lonuserutils::classlist_drop($scope,
4698: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4699: $now);
1.369 bisitz 4700: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 4701: }
1.225 raeburn 4702: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4703: push(@rolechanges,$role);
4704: }
1.116 raeburn 4705: }
1.139 albertel 4706: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4707: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4708: # Delete custom role
1.369 bisitz 4709: my $result =
4710: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
4711: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
4712: 0,1,$context);
4713: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 4714: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4715: $result ne "ok").'<br />');
4716: if ($result ne "ok") {
4717: $r->print(&mt('Error: [_1]',$result).'<br />');
4718: }
1.367 golterma 4719:
1.225 raeburn 4720: if (!grep(/^cr$/,@rolechanges)) {
4721: push(@rolechanges,'cr');
4722: }
1.116 raeburn 4723: }
1.135 raeburn 4724: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4725: my $udom = $env{'form.ccdomain'};
4726: my $uname = $env{'form.ccuname'};
1.116 raeburn 4727: # Re-enable standard role
1.135 raeburn 4728: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4729: my $url = $1;
4730: my $role = $2;
1.465 raeburn 4731: my $id = $url.'_'.$role;
1.89 raeburn 4732: my $logmsg;
4733: my $output;
4734: if ($role eq 'st') {
1.141 albertel 4735: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4736: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4737: my $credits;
4738: if ($showcredits) {
1.465 raeburn 4739: my $defaultcredits =
1.375 raeburn 4740: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4741: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4742: }
1.465 raeburn 4743: unless ($udom eq $cdom) {
4744: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4745: $uname,$role,$now,0,$cdom,$cnum,$csec,$credits,
4746: \%process_by,\%instdoms,\%got_role_approvals,
1.466 raeburn 4747: \%got_instdoms,\%reject,\%pending,\%notifydc,
4748: \%status,\%unauthorized,\%currqueued));
1.465 raeburn 4749: }
1.375 raeburn 4750: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4751: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4752: if ($result eq 'refused' && $logmsg) {
4753: $output = $logmsg;
4754: } else {
1.369 bisitz 4755: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4756: }
1.89 raeburn 4757: } else {
1.372 raeburn 4758: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4759: &Apache::lonnet::plaintext($role),
4760: &Apache::loncommon::show_role_extent($url,$context,'st'),
4761: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4762: }
4763: }
4764: } else {
1.465 raeburn 4765: my ($cdom,$cnum,$csec);
4766: if (grep(/^\Q$role\E$/,@cstrroles)) {
4767: ($cdom,$cnum) = ($url =~ m{^/($match_domain)/($match_username)$});
4768: } elsif (grep(/^\Q$role\E$/,@domroles)) {
4769: ($cdom) = ($url =~ m{^/($match_domain)/$});
4770: } elsif ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
4771: ($cdom,$cnum,$csec) = ($1,$2,$3);
4772: }
4773: if ($cdom ne '') {
4774: unless ($udom eq $cdom) {
4775: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4776: $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by,
4777: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4778: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4779: }
4780: }
1.101 albertel 4781: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4782: $env{'form.ccuname'},$url,$role,0,$now,'','',
4783: $context);
1.461 raeburn 4784: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
4785: &Apache::lonnet::plaintext($role),
4786: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4787: if ($result ne "ok") {
4788: $output .= &mt('Error: [_1]',$result).'<br />';
4789: }
4790: }
1.89 raeburn 4791: $r->print($output);
1.225 raeburn 4792: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4793: push(@rolechanges,$role);
4794: }
1.113 raeburn 4795: }
1.116 raeburn 4796: # Re-enable custom role
1.139 albertel 4797: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4798: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1.465 raeburn 4799: my $id = $url.'_cr'."/$rdom/$rnam/$rolename";
4800: my $role = "cr/$rdom/$rnam/$rolename";
4801: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
4802: my ($cdom,$cnum,$csec) = ($1,$2,$3);
4803: unless ($udom eq $cdom) {
4804: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4805: $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by,
4806: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4807: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4808: }
4809: }
1.116 raeburn 4810: my $result = &Apache::lonnet::assigncustomrole(
4811: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4812: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4813: $r->print(&Apache::lonhtmlcommon::confirm_success(
4814: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4815: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4816: $result ne "ok").'<br />');
4817: if ($result ne "ok") {
4818: $r->print(&mt('Error: [_1]',$result).'<br />');
4819: }
1.225 raeburn 4820: if (!grep(/^cr$/,@rolechanges)) {
4821: push(@rolechanges,'cr');
4822: }
1.116 raeburn 4823: }
1.135 raeburn 4824: } elsif ($key=~/^form\.act/) {
1.101 albertel 4825: my $udom = $env{'form.ccdomain'};
4826: my $uname = $env{'form.ccuname'};
1.141 albertel 4827: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4828: # Activate a custom role
1.83 albertel 4829: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4830: my $url='/'.$one.'/'.$two;
1.465 raeburn 4831: my $id = $url.'_cr/'."$three/$four/$five";
4832: my $role = "cr/$three/$four/$five";
1.83 albertel 4833: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4834:
1.101 albertel 4835: my $start = ( $env{'form.start_'.$full} ?
4836: $env{'form.start_'.$full} :
1.88 raeburn 4837: $now );
1.101 albertel 4838: my $end = ( $env{'form.end_'.$full} ?
4839: $env{'form.end_'.$full} :
1.88 raeburn 4840: 0 );
1.465 raeburn 4841:
1.88 raeburn 4842: # split multiple sections
4843: my %sections = ();
1.461 raeburn 4844: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$five);
1.88 raeburn 4845: if ($num_sections == 0) {
1.465 raeburn 4846: unless ($udom eq $one) {
4847: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4848: $uname,$role,$start,$end,$one,$two,'','',\%process_by,
4849: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4850: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4851: }
1.240 raeburn 4852: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4853: } else {
1.114 albertel 4854: my %curr_groups =
1.117 raeburn 4855: &Apache::longroup::coursegroups($one,$two);
1.465 raeburn 4856: my ($restricted,$numchanges);
1.404 raeburn 4857: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4858: if (($sec eq 'none') || ($sec eq 'all') ||
4859: exists($curr_groups{$sec})) {
4860: $disallowed{$sec} = $url;
4861: next;
4862: }
4863: my $securl = $url.'/'.$sec;
1.465 raeburn 4864: my $secid = $securl.'_cr'."/$three/$four/$five";
4865: undef($restricted);
4866: unless ($udom eq $one) {
4867: next if (&Apache::lonuserutils::restricted_dom($context,$secid,$udom,
4868: $uname,$role,$start,$end,$one,$two,$sec,'',\%process_by,
4869: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4870: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4871: }
4872: $numchanges ++;
1.240 raeburn 4873: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4874: }
1.465 raeburn 4875: next unless ($numchanges);
1.88 raeburn 4876: }
1.225 raeburn 4877: if (!grep(/^cr$/,@rolechanges)) {
4878: push(@rolechanges,'cr');
4879: }
1.142 raeburn 4880: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4881: # Activate roles for sections with 3 id numbers
4882: # set start, end times, and the url for the class
1.83 albertel 4883: my ($one,$two,$three)=($1,$2,$3);
1.461 raeburn 4884: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4885: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4886: $now );
1.461 raeburn 4887: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1.101 albertel 4888: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4889: 0 );
1.83 albertel 4890: my $url='/'.$one.'/'.$two;
1.465 raeburn 4891: my $id = $url.'_'.$three;
1.88 raeburn 4892: # split multiple sections
4893: my %sections = ();
1.101 albertel 4894: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.465 raeburn 4895: my ($credits,$numchanges);
1.375 raeburn 4896: if ($three eq 'st') {
1.461 raeburn 4897: if ($showcredits) {
1.375 raeburn 4898: my $defaultcredits =
4899: &Apache::lonuserutils::get_defaultcredits($one,$two);
4900: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4901: $credits =~ s/[^\d\.]//g;
4902: if ($credits eq $defaultcredits) {
4903: undef($credits);
4904: }
4905: }
4906: }
1.88 raeburn 4907: if ($num_sections == 0) {
1.465 raeburn 4908: unless ($udom eq $one) {
4909: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4910: $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by,
4911: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4912: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4913: }
4914: $numchanges ++;
1.375 raeburn 4915: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4916: } else {
1.114 albertel 4917: my %curr_groups =
1.117 raeburn 4918: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4919: my $emptysec = 0;
1.465 raeburn 4920: my $restricted;
1.404 raeburn 4921: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4922: $sec =~ s/\W//g;
1.113 raeburn 4923: if ($sec ne '') {
4924: if (($sec eq 'none') || ($sec eq 'all') ||
4925: exists($curr_groups{$sec})) {
4926: $disallowed{$sec} = $url;
4927: next;
4928: }
1.88 raeburn 4929: my $securl = $url.'/'.$sec;
1.465 raeburn 4930: my $secid = $securl.'_'.$three;
4931: unless ($udom eq $one) {
4932: undef($restricted);
4933: $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
4934: $uname,$three,$start,$end,$one,$two,$sec,$credits,\%process_by,
4935: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4936: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4937: next if ($restricted);
4938: }
4939: $numchanges ++;
1.375 raeburn 4940: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4941: } else {
4942: $emptysec = 1;
4943: }
4944: }
4945: if ($emptysec) {
1.465 raeburn 4946: unless ($udom eq $one) {
4947: undef($restricted);
4948: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
4949: $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by,
4950: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4951: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4952: next if ($restricted);
4953: }
4954: $numchanges ++;
1.375 raeburn 4955: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4956: }
1.465 raeburn 4957: next unless ($numchanges);
1.225 raeburn 4958: }
4959: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4960: push(@rolechanges,$three);
4961: }
1.135 raeburn 4962: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4963: # Activate roles for sections with two id numbers
4964: # set start, end times, and the url for the class
1.461 raeburn 4965: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4966: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4967: $now );
1.461 raeburn 4968: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1.101 albertel 4969: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4970: 0 );
1.225 raeburn 4971: my $one = $1;
4972: my $two = $2;
4973: my $url='/'.$one.'/';
1.465 raeburn 4974: my $id = $url.'_'.$two;
1.468 raeburn 4975: my ($cdom,$cnum) = split(/\//,$one);
1.88 raeburn 4976: # split multiple sections
4977: my %sections = ();
1.465 raeburn 4978: my ($restricted,$numchanges);
1.225 raeburn 4979: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4980: if ($num_sections == 0) {
1.465 raeburn 4981: unless ($udom eq $one) {
4982: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
1.468 raeburn 4983: $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
1.465 raeburn 4984: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4985: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4986: next if ($restricted);
4987: }
4988: $numchanges ++;
1.240 raeburn 4989: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4990: } else {
4991: my $emptysec = 0;
1.404 raeburn 4992: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4993: if ($sec ne '') {
4994: my $securl = $url.'/'.$sec;
1.465 raeburn 4995: my $secid = $securl.'_'.$two;
4996: unless ($udom eq $one) {
4997: undef($restricted);
4998: $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
1.468 raeburn 4999: $uname,$two,$start,$end,$cdom,$cnum,$sec,'',\%process_by,
1.465 raeburn 5000: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 5001: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 5002: next if ($restricted);
5003: }
5004: $numchanges ++;
1.240 raeburn 5005: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 5006: } else {
5007: $emptysec = 1;
5008: }
5009: }
5010: if ($emptysec) {
1.465 raeburn 5011: unless ($udom eq $one) {
5012: undef($restricted);
5013: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
1.468 raeburn 5014: $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
1.465 raeburn 5015: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 5016: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 5017: next if ($restricted);
5018: }
5019: $numchanges ++;
1.240 raeburn 5020: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 5021: }
1.465 raeburn 5022: next unless ($numchanges);
1.88 raeburn 5023: }
1.225 raeburn 5024: if (!grep(/^\Q$two\E$/,@rolechanges)) {
5025: push(@rolechanges,$two);
5026: }
1.64 www 5027: } else {
1.190 raeburn 5028: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 5029: }
1.113 raeburn 5030: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 5031: $r->print('<p class="LC_warning">');
1.113 raeburn 5032: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 5033: $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 5034: } else {
1.274 bisitz 5035: $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 5036: }
1.274 bisitz 5037: $r->print('</p><p>'
5038: .&mt('Please [_1]go back[_2] and choose a different section name.'
5039: ,'<a href="javascript:history.go(-1)'
5040: ,'</a>')
5041: .'</p><br />'
5042: );
1.113 raeburn 5043: }
5044: }
1.101 albertel 5045: } # End of foreach (keys(%env))
1.466 raeburn 5046: if ((keys(%reject)) || (keys(%unauthorized))) {
5047: $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized));
1.465 raeburn 5048: }
1.466 raeburn 5049: if ((keys(%pending)) || (keys(%currqueued))) {
5050: $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.465 raeburn 5051: }
1.75 www 5052: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 5053: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 5054: if (@rolechanges == 0) {
1.372 raeburn 5055: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 5056: }
1.225 raeburn 5057: return @rolechanges;
1.220 raeburn 5058: }
5059:
1.375 raeburn 5060: sub get_user_credits {
5061: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
5062: if ($cdom eq '' || $cnum eq '') {
5063: return unless ($env{'request.course.id'});
5064: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5065: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5066: }
5067: my $credits;
5068: my %currhash =
5069: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
5070: if (keys(%currhash) > 0) {
5071: my @items = split(/:/,$currhash{$uname.':'.$udom});
5072: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
5073: $credits = $items[$crdidx];
5074: $credits =~ s/[^\d\.]//g;
5075: }
5076: if ($credits eq $defaultcredits) {
5077: undef($credits);
5078: }
5079: return $credits;
5080: }
5081:
1.220 raeburn 5082: sub enroll_single_student {
1.375 raeburn 5083: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
5084: $showcredits,$defaultcredits) = @_;
1.318 raeburn 5085: $r->print('<h3>');
5086: if ($crstype eq 'Community') {
5087: $r->print(&mt('Enrolling Member'));
5088: } else {
5089: $r->print(&mt('Enrolling Student'));
5090: }
5091: $r->print('</h3>');
1.220 raeburn 5092:
5093: # Remove non alphanumeric values from section
5094: $env{'form.sections'}=~s/\W//g;
5095:
1.375 raeburn 5096: my $credits;
5097: if (($showcredits) && ($env{'form.credits'} ne '')) {
5098: $credits = $env{'form.credits'};
5099: $credits =~ s/[^\d\.]//g;
5100: if ($credits ne '') {
5101: if ($credits eq $defaultcredits) {
5102: undef($credits);
5103: }
5104: }
5105: }
1.465 raeburn 5106: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
1.466 raeburn 5107: my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,%pending,%reject,%notifydc,
5108: %status,%unauthorized,%currqueued);
1.465 raeburn 5109: unless ($env{'form.ccdomain'} eq $env{'course.'.$env{'request.course.id'}.'.domain'}) {
5110: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5111: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5112: my $csec = $env{'form.sections'};
5113: my $id = "/$cdom/$cnum";
5114: if ($csec ne '') {
5115: $id .= "/$csec";
5116: }
5117: $id .= '_st';
5118: if (&Apache::lonuserutils::restricted_dom($context,$id,$env{'form.ccdomain'},$env{'form.ccuname'},
5119: 'st',$startdate,$enddate,$cdom,$cnum,$csec,$credits,
5120: \%process_by,\%instdoms,\%got_role_approvals,\%got_instdoms,
1.466 raeburn 5121: \%reject,\%pending,\%notifydc,\%status,\%unauthorized,\%currqueued)) {
5122: if ((keys(%reject)) || (keys(%unauthorized))) {
5123: $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized));
1.465 raeburn 5124: }
1.466 raeburn 5125: if ((keys(%pending)) || (keys(%currqueued))) {
5126: $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.465 raeburn 5127: }
5128: return;
5129: }
5130: }
1.375 raeburn 5131:
1.220 raeburn 5132: # Clean out any old student roles the user has in this class.
5133: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
5134: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
5135: my $enroll_result =
5136: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
5137: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
5138: $env{'form.cmiddlename'},$env{'form.clastname'},
5139: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 5140: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
5141: $credits);
1.220 raeburn 5142: if ($enroll_result =~ /^ok/) {
1.381 bisitz 5143: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 5144: if ($env{'form.sections'} ne '') {
5145: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
5146: }
5147: my ($showstart,$showend);
5148: if ($startdate <= $now) {
5149: $showstart = &mt('Access starts immediately');
5150: } else {
5151: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
5152: }
5153: if ($enddate == 0) {
5154: $showend = &mt('ends: no ending date');
5155: } else {
5156: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
5157: }
5158: $r->print('.<br />'.$showstart.'; '.$showend);
5159: if ($startdate <= $now && !$newuser) {
1.386 bisitz 5160: $r->print('<p class="LC_info">');
1.318 raeburn 5161: if ($crstype eq 'Community') {
1.392 raeburn 5162: $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 5163: } else {
1.392 raeburn 5164: $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 5165: }
5166: $r->print('</p>');
1.220 raeburn 5167: }
5168: } else {
5169: $r->print(&mt('unable to enroll').": ".$enroll_result);
5170: }
5171: return;
1.188 raeburn 5172: }
5173:
1.204 raeburn 5174: sub get_defaultquota_text {
5175: my ($settingstatus) = @_;
5176: my $defquotatext;
5177: if ($settingstatus eq '') {
1.383 raeburn 5178: $defquotatext = &mt('default');
1.204 raeburn 5179: } else {
5180: my ($usertypes,$order) =
5181: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
5182: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 5183: $defquotatext = &mt('default');
1.204 raeburn 5184: } else {
1.383 raeburn 5185: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 5186: }
5187: }
5188: return $defquotatext;
5189: }
5190:
1.188 raeburn 5191: sub update_result_form {
5192: my ($uhome) = @_;
5193: my $outcome =
1.367 golterma 5194: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 5195: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 5196: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 5197: }
1.207 raeburn 5198: if ($env{'form.origname'} ne '') {
5199: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
5200: }
1.160 raeburn 5201: foreach my $item ('sortby','seluname','seludom') {
5202: if (exists($env{'form.'.$item})) {
1.188 raeburn 5203: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 5204: }
5205: }
1.188 raeburn 5206: if ($uhome eq 'no_host') {
5207: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
5208: }
5209: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 5210: '<input type="hidden" name="currstate" value="" />'."\n".
5211: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 5212: '</form>';
5213: return $outcome;
1.4 www 5214: }
5215:
1.149 raeburn 5216: sub quota_admin {
1.378 raeburn 5217: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 5218: my $quotachanged;
5219: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
5220: # Current user has quota modification privileges
1.267 raeburn 5221: if (ref($changeHash) eq 'HASH') {
5222: $quotachanged = 1;
1.378 raeburn 5223: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 5224: }
1.149 raeburn 5225: }
5226: return $quotachanged;
5227: }
5228:
1.267 raeburn 5229: sub tool_admin {
1.275 raeburn 5230: my ($tool,$settool,$changeHash,$context) = @_;
5231: my $canchange = 0;
1.279 raeburn 5232: if ($context eq 'requestcourses') {
1.275 raeburn 5233: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
5234: $canchange = 1;
5235: }
1.300 raeburn 5236: } elsif ($context eq 'reqcrsotherdom') {
5237: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
5238: $canchange = 1;
5239: }
1.362 raeburn 5240: } elsif ($context eq 'requestauthor') {
5241: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
5242: $canchange = 1;
5243: }
1.470 raeburn 5244: } elsif ($context eq 'authordefaults') {
5245: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
5246: $canchange = 1;
5247: }
1.275 raeburn 5248: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
5249: # Current user has quota modification privileges
5250: $canchange = 1;
5251: }
1.267 raeburn 5252: my $toolchanged;
1.275 raeburn 5253: if ($canchange) {
1.267 raeburn 5254: if (ref($changeHash) eq 'HASH') {
5255: $toolchanged = 1;
1.362 raeburn 5256: if ($tool eq 'requestauthor') {
5257: $changeHash->{$context} = $settool;
1.477 raeburn 5258: } elsif (($tool eq 'managers') || ($tool eq 'editors') || ($tool eq 'archive')) {
1.470 raeburn 5259: $changeHash->{'author'.$tool} = $settool;
5260: } elsif ($tool eq 'webdav') {
5261: $changeHash->{'tools.'.$tool} = $settool;
1.362 raeburn 5262: } else {
5263: $changeHash->{$context.'.'.$tool} = $settool;
5264: }
1.267 raeburn 5265: }
5266: }
5267: return $toolchanged;
5268: }
5269:
1.88 raeburn 5270: sub build_roles {
1.89 raeburn 5271: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 5272: my $num_sections = 0;
5273: if ($sectionstr=~ /,/) {
5274: my @secnums = split/,/,$sectionstr;
1.89 raeburn 5275: if ($role eq 'st') {
5276: $secnums[0] =~ s/\W//g;
5277: $$sections{$secnums[0]} = 1;
5278: $num_sections = 1;
5279: } else {
5280: foreach my $sec (@secnums) {
5281: $sec =~ ~s/\W//g;
1.150 banghart 5282: if (!($sec eq "")) {
1.89 raeburn 5283: if (exists($$sections{$sec})) {
5284: $$sections{$sec} ++;
5285: } else {
5286: $$sections{$sec} = 1;
5287: $num_sections ++;
5288: }
1.88 raeburn 5289: }
5290: }
5291: }
5292: } else {
5293: $sectionstr=~s/\W//g;
5294: unless ($sectionstr eq '') {
5295: $$sections{$sectionstr} = 1;
5296: $num_sections ++;
5297: }
5298: }
1.129 albertel 5299:
1.88 raeburn 5300: return $num_sections;
5301: }
5302:
1.58 www 5303: # ========================================================== Custom Role Editor
5304:
5305: sub custom_role_editor {
1.439 raeburn 5306: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 5307: my $action = $env{'form.customroleaction'};
1.439 raeburn 5308: my ($rolename,$helpitem);
1.324 raeburn 5309: if ($action eq 'new') {
5310: $rolename=$env{'form.newrolename'};
5311: } else {
5312: $rolename=$env{'form.rolename'};
1.59 www 5313: }
5314:
1.324 raeburn 5315: my ($crstype,$context);
5316: if ($env{'request.course.id'}) {
5317: $crstype = &Apache::loncommon::course_type();
5318: $context = 'course';
1.439 raeburn 5319: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 5320: } else {
5321: $context = 'domain';
1.414 raeburn 5322: $crstype = 'course';
1.439 raeburn 5323: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 5324: }
1.351 raeburn 5325:
5326: $rolename=~s/[^A-Za-z0-9]//gs;
5327: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 5328: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
5329: $permission);
1.351 raeburn 5330: return;
5331: }
5332:
1.414 raeburn 5333: my $formname = 'form1';
5334: my %privs=();
5335: my $body_top = '<h2>';
5336: # ------------------------------------------------------- Does this role exist?
1.59 www 5337: my ($rdummy,$roledef)=
5338: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
5339: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 5340: $body_top .= &mt('Existing Role').' "';
1.61 www 5341: # ------------------------------------------------- Get current role privileges
1.414 raeburn 5342: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
5343: if ($privs{'system'} =~ /bre\&S/) {
5344: if ($context eq 'domain') {
1.417 raeburn 5345: $crstype = 'Course';
1.414 raeburn 5346: } elsif ($crstype eq 'Community') {
5347: $privs{'system'} =~ s/bre\&S//;
5348: }
5349: } elsif ($context eq 'domain') {
5350: $crstype = 'Course';
1.324 raeburn 5351: }
1.59 www 5352: } else {
1.414 raeburn 5353: $body_top .= &mt('New Role').' "';
5354: $roledef='';
1.59 www 5355: }
1.153 banghart 5356: $body_top .= $rolename.'"</h2>';
1.414 raeburn 5357:
5358: # ------------------------------------------------------- What can be assigned?
5359: my %full=();
1.417 raeburn 5360: my %levels=(
1.414 raeburn 5361: course => {},
5362: domain => {},
5363: system => {},
5364: );
5365: my %levelscurrent=(
5366: course => {},
5367: domain => {},
5368: system => {},
5369: );
5370: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 5371: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 5372: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 5373: my $head_script =
1.414 raeburn 5374: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
5375: \%full,\@templateroles,$jsback);
1.351 raeburn 5376: push (@{$brcrum},
1.414 raeburn 5377: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 5378: text => "Pick custom role",
5379: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 5380: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 5381: text => "Edit custom role",
5382: faq => 282,
5383: bug => 'Instructor Interface',
1.439 raeburn 5384: help => $helpitem}
1.351 raeburn 5385: );
5386: my $args = { bread_crumbs => $brcrum,
5387: bread_crumbs_component => 'User Management'};
5388: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
5389: $head_script,$args).
5390: $body_top);
1.414 raeburn 5391: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
5392: &Apache::lonuserutils::custom_role_header($context,$crstype,
5393: \@templateroles,$prefix));
1.264 bisitz 5394:
1.61 www 5395: $r->print(<<ENDCCF);
5396: <input type="hidden" name="phase" value="set_custom_roles" />
5397: <input type="hidden" name="rolename" value="$rolename" />
5398: ENDCCF
1.414 raeburn 5399: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
5400: \%levelscurrent,$prefix));
1.135 raeburn 5401: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 5402: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 5403: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 5404: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 5405: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 5406: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 5407: }
1.414 raeburn 5408:
1.61 www 5409: # ---------------------------------------------------------- Call to definerole
5410: sub set_custom_role {
1.439 raeburn 5411: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 5412: my $rolename=$env{'form.rolename'};
1.63 www 5413: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 5414: if (!$rolename) {
1.439 raeburn 5415: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 5416: return;
5417: }
1.160 raeburn 5418: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 5419: my $jscript = '<script type="text/javascript">'
5420: .'// <![CDATA['."\n"
5421: .$jsback."\n"
5422: .'// ]]>'."\n"
5423: .'</script>'."\n";
1.439 raeburn 5424: my $helpitem = 'Course_Editing_Custom_Roles';
5425: if ($context eq 'domain') {
5426: $helpitem = 'Domain_Editing_Custom_Roles';
5427: }
1.352 raeburn 5428: push(@{$brcrum},
5429: {href => "javascript:backPage(document.customresult,'pickrole','')",
5430: text => "Pick custom role",
5431: faq => 282,
5432: bug => 'Instructor Interface',},
5433: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
5434: text => "Edit custom role",
5435: faq => 282,
5436: bug => 'Instructor Interface',},
5437: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
5438: text => "Result",
5439: faq => 282,
5440: bug => 'Instructor Interface',
1.439 raeburn 5441: help => $helpitem,}
1.352 raeburn 5442: );
5443: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 5444: bread_crumbs_component => 'User Management'};
1.351 raeburn 5445: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 5446:
1.393 raeburn 5447: my $newrole;
1.61 www 5448: my ($rdummy,$roledef)=
1.110 albertel 5449: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
5450:
1.61 www 5451: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 5452: $r->print('<h3>');
1.61 www 5453: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 5454: $r->print(&mt('Existing Role').' "');
1.61 www 5455: } else {
1.73 sakharuk 5456: $r->print(&mt('New Role').' "');
1.61 www 5457: $roledef='';
1.393 raeburn 5458: $newrole = 1;
1.61 www 5459: }
1.188 raeburn 5460: $r->print($rolename.'"</h3>');
1.414 raeburn 5461: # ------------------------------------------------- Assign role and show result
1.61 www 5462:
1.387 bisitz 5463: my $errmsg;
1.414 raeburn 5464: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
5465: # Assign role and return result
5466: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
5467: $newprivs{'c'});
1.387 bisitz 5468: if ($result ne 'ok') {
5469: $errmsg = ': '.$result;
5470: }
5471: my $message =
5472: &Apache::lonhtmlcommon::confirm_success(
5473: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 5474: if ($env{'request.course.id'}) {
5475: my $url='/'.$env{'request.course.id'};
1.63 www 5476: $url=~s/\_/\//g;
1.387 bisitz 5477: $result =
5478: &Apache::lonnet::assigncustomrole(
5479: $env{'user.domain'},$env{'user.name'},
5480: $url,
5481: $env{'user.domain'},$env{'user.name'},
5482: $rolename,undef,undef,undef,$context);
5483: if ($result ne 'ok') {
5484: $errmsg = ': '.$result;
5485: }
5486: $message .=
5487: '<br />'
5488: .&Apache::lonhtmlcommon::confirm_success(
5489: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 5490: }
1.380 bisitz 5491: $r->print(
1.387 bisitz 5492: &Apache::loncommon::confirmwrapper($message)
5493: .'<br />'
5494: .&Apache::lonhtmlcommon::actionbox([
5495: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
5496: .&mt('Create or edit another custom role')
5497: .'</a>'])
1.380 bisitz 5498: .'<form name="customresult" method="post" action="">'
1.387 bisitz 5499: .&Apache::lonhtmlcommon::echo_form_input([])
5500: .'</form>'
1.380 bisitz 5501: );
1.58 www 5502: }
5503:
1.465 raeburn 5504: sub show_role_requests {
5505: my ($caller,$dom) = @_;
5506: my $showrolereqs;
5507: my %domconfig = &Apache::lonnet::get_dom('configuration',['privacy'],$dom);
5508: if (ref($domconfig{'privacy'}) eq 'HASH') {
5509: if (ref($domconfig{'privacy'}{'approval'}) eq 'HASH') {
5510: my %approvalconf = %{$domconfig{'privacy'}{'approval'}};
5511: foreach my $key ('instdom','extdom') {
5512: if (ref($approvalconf{$key}) eq 'HASH') {
5513: if (keys(%{$approvalconf{$key}})) {
5514: foreach my $context ('domain','author','course','community') {
5515: if ($approvalconf{$key}{$context} eq $caller) {
5516: $showrolereqs = 1;
5517: last if ($showrolereqs);
5518: }
5519: }
5520: }
5521: }
5522: last if ($showrolereqs);
5523: }
5524: }
5525: }
5526: return $showrolereqs;
5527: }
5528:
1.470 raeburn 5529: sub display_coauthor_managers {
5530: my ($permission) = @_;
5531: my $output;
5532: if ((ref($permission) eq 'HASH') && ($permission->{'author'})) {
5533: $output = '<form action="/adm/createuser" method="post" name="camanagers">'.
5534: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
5535: '<p>';
5536: my (@possmanagers,@custommanagers);
5537: my %userenv =
5538: &Apache::lonnet::userenvironment($env{'user.domain'},
5539: $env{'user.name'},
5540: 'authormanagers');
5541: my %ca_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5542: ['active','future'],['ca']);
5543: if (keys(%ca_roles)) {
5544: foreach my $entry (sort(keys(%ca_roles))) {
5545: if ($entry =~ /^($match_username\:$match_domain):ca$/) {
5546: my $user = $1;
5547: unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5548: push(@possmanagers,$user);
5549: }
5550: }
5551: }
5552: }
5553: if ($userenv{'authormanagers'} eq '') {
5554: $output .= &mt('Currently author manages co-author roles');
5555: } else {
5556: if (keys(%ca_roles)) {
5557: foreach my $user (split(/,/,$userenv{'authormanagers'})) {
5558: if ($user =~ /^($match_username)\:($match_domain)$/) {
5559: if (exists($ca_roles{$user.':ca'})) {
5560: unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5561: push(@custommanagers,$user);
5562: }
5563: }
5564: }
5565: }
5566: }
5567: if (@custommanagers) {
5568: $output .= &mt('Co-authors with active or future roles who currently manage co-author roles: [_1]',
5569: '<br />'.join(', ',map { &Apache::loncommon::plainname(split(':',$_))." ($_)"; } @custommanagers));
5570: } else {
5571: $output .= &mt('Currently author manages co-author roles');
5572: }
5573: }
5574: $output .= "</p>\n";
5575: if (@possmanagers) {
1.472 raeburn 5576: $output .= '<p>'.&mt('If checked, can manage').': ';
1.470 raeburn 5577: foreach my $user (@possmanagers) {
5578: my $checked;
5579: if (grep(/^\Q$user\E$/,@custommanagers)) {
5580: $checked = ' checked="checked"';
5581: }
5582: $output .= '<span style="LC_nobreak"><label>'.
5583: '<input type="checkbox" name="custommanagers" '.
5584: 'value="'.&HTML::Entities::encode($user,'\'<>"&').'"'.$checked.' />'.
5585: &Apache::loncommon::plainname(split(/:/,$user))." ($user)".'</label></span> '."\n";
5586: }
5587: $output .= '<input type="hidden" name="state" value="process" /></p>'."\n".
5588: '<p><input type="submit" value="'.&mt('Save changes').'" /></p>'."\n";
5589: } else {
5590: $output .= '<p>'.&mt('No co-author roles assignable as manager').'</p>';
5591: }
5592: $output .= '</form>';
5593: } else {
5594: $output = '<span class="LC_warning">'.
5595: &mt('You do not have permission to perform this action').
5596: '</span>';
5597: }
5598: return $output;
5599: }
5600:
5601: sub update_coauthor_managers {
5602: my ($permission) = @_;
5603: my $output;
5604: if ((ref($permission) eq 'HASH') && ($permission->{'author'})) {
5605: my ($current,$newval,@possibles,@managers);
5606: my %userenv =
5607: &Apache::lonnet::userenvironment($env{'user.domain'},
5608: $env{'user.name'},
5609: 'authormanagers');
5610: $current = $userenv{'authormanagers'};
5611: @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
5612: if (@possibles) {
5613: my %ca_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5614: ['active','future'],['ca']);
5615: if (keys(%ca_roles)) {
5616: foreach my $user (@possibles) {
5617: if ($user =~ /^($match_username):($match_domain)$/) {
5618: if (exists($ca_roles{$user.':ca'})) {
5619: unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5620: push(@managers,$user);
5621: }
5622: }
5623: }
5624: }
5625: if (@managers) {
5626: $newval = join(',',sort(@managers));
5627: }
5628: }
5629: }
5630: if ($current eq $newval) {
5631: $output = &mt('No changes made to management of co-author roles');
5632: } else {
5633: my $chgresult =
5634: &Apache::lonnet::put('environment',{'authormanagers' => $newval},
5635: $env{'user.domain'},$env{'user.name'});
5636: if ($chgresult eq 'ok') {
5637: &Apache::lonnet::appenv({'environment.authormanagers' => $newval});
5638: my (@adds,@dels);
5639: if ($newval eq '') {
5640: @dels = split(/,/,$current);
5641: } elsif ($current eq '') {
5642: @adds = @managers;
5643: } else {
5644: my @old = split(/,/,$current);
5645: my @diffs = &Apache::loncommon::compare_arrays(\@old,\@managers);
5646: if (@diffs) {
5647: foreach my $user (@diffs) {
5648: if (grep(/^\Q$user\E$/,@old)) {
5649: push(@dels,$user);
5650: } elsif (grep(/^\Q$user\E$/,@managers)) {
5651: push(@adds,$user);
5652: }
5653: }
5654: }
5655: }
5656: my $key = "internal.manager./$env{'user.domain'}/$env{'user.name'}";
5657: if (@dels) {
5658: foreach my $user (@dels) {
5659: if ($user =~ /^($match_username):($match_domain)$/) {
5660: &Apache::lonnet::del('environment',[$key],$2,$1);
5661: }
5662: }
5663: }
5664: if (@adds) {
5665: foreach my $user (@adds) {
5666: if ($user =~ /^($match_username):($match_domain)$/) {
5667: &Apache::lonnet::put('environment',{$key => 1},$2,$1);
5668: }
5669: }
5670: }
5671: if ($newval eq '') {
5672: $output = &mt('Management of co-authors set to be author-only');
5673: } else {
5674: $output .= &mt('Co-authors who can manage co-author roles set to: [_1]',
5675: '<br />'.join(', ',map { &Apache::loncommon::plainname(split(':',$_))." ($_)"; } @managers));
5676: }
5677: }
5678: }
5679: } else {
5680: $output = '<span class="LC_warning">'.
5681: &mt('You do not have permission to perform this action').
5682: '</span>';
5683: }
5684: return $output;
5685: }
5686:
1.2 www 5687: # ================================================================ Main Handler
5688: sub handler {
5689: my $r = shift;
5690: if ($r->header_only) {
1.68 www 5691: &Apache::loncommon::content_type($r,'text/html');
1.2 www 5692: $r->send_http_header;
5693: return OK;
5694: }
1.439 raeburn 5695: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
5696:
1.190 raeburn 5697: if ($env{'request.course.id'}) {
5698: $context = 'course';
1.318 raeburn 5699: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 5700: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 5701: $context = 'author';
1.470 raeburn 5702: } elsif ($env{'request.role'} =~ m{^(ca|aa)\./$match_domain/$match_username$}) {
5703: $context = 'coauthor';
1.190 raeburn 5704: } else {
5705: $context = 'domain';
5706: }
1.375 raeburn 5707:
1.439 raeburn 5708: my ($permission,$allowed) =
5709: &Apache::lonuserutils::get_permission($context,$crstype);
1.470 raeburn 5710: if (($context eq 'coauthor') && ($allowed)) {
5711: $context = 'author';
5712: }
1.439 raeburn 5713:
5714: if ($allowed) {
5715: my @allhelp;
5716: if ($context eq 'course') {
5717: $cid = $env{'request.course.id'};
5718: $cdom = $env{'course.'.$cid.'.domain'};
5719: $cnum = $env{'course.'.$cid.'.num'};
5720:
5721: if ($permission->{'cusr'}) {
5722: push(@allhelp,'Course_Create_Class_List');
5723: }
5724: if ($permission->{'view'} || $permission->{'cusr'}) {
5725: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
5726: }
5727: if ($permission->{'custom'}) {
5728: push(@allhelp,'Course_Editing_Custom_Roles');
5729: }
5730: if ($permission->{'cusr'}) {
5731: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
5732: }
5733: unless ($permission->{'cusr_section'}) {
5734: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
5735: push(@allhelp,'Course_Automated_Enrollment');
5736: }
1.469 raeburn 5737: if (($permission->{'selfenrolladmin'}) || ($permission->{'selfenrollview'})) {
1.439 raeburn 5738: push(@allhelp,'Course_Approve_Selfenroll');
5739: }
5740: }
5741: if ($permission->{'grp_manage'}) {
5742: push(@allhelp,'Course_Manage_Group');
5743: }
5744: if ($permission->{'view'} || $permission->{'cusr'}) {
5745: push(@allhelp,'Course_User_Logs');
5746: }
5747: } elsif ($context eq 'author') {
5748: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
5749: 'Author_View_Coauthor_List','Author_User_Logs'));
1.470 raeburn 5750: } elsif ($context eq 'coauthor') {
5751: if ($permission->{'cusr'}) {
5752: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
5753: 'Author_View_Coauthor_List','Author_User_Logs'));
5754: } elsif ($permission->{'view'}) {
5755: push(@allhelp,'Author_View_Coauthor_List');
5756: }
1.439 raeburn 5757: } else {
5758: if ($permission->{'cusr'}) {
5759: push(@allhelp,'Domain_Change_Privileges');
5760: if ($permission->{'activity'}) {
5761: push(@allhelp,'Domain_User_Access_Logs');
5762: }
5763: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
5764: if ($permission->{'custom'}) {
5765: push(@allhelp,'Domain_Editing_Custom_Roles');
5766: }
5767: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
5768: } elsif ($permission->{'view'}) {
5769: push(@allhelp,'Domain_View_Privileges');
5770: if ($permission->{'activity'}) {
5771: push(@allhelp,'Domain_User_Access_Logs');
5772: }
5773: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
5774: }
5775: }
5776: if (@allhelp) {
5777: $allhelpitems = join(',',@allhelp);
5778: }
5779: }
5780:
1.190 raeburn 5781: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 5782: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.470 raeburn 5783: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue',
5784: 'forceedit']);
1.190 raeburn 5785: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 5786: my $args;
5787: my $brcrum = [];
5788: my $bread_crumbs_component = 'User Management';
1.391 raeburn 5789: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 5790: $brcrum = [{href=>"/adm/createuser",
5791: text=>"User Management",
1.439 raeburn 5792: help=>$allhelpitems}
1.351 raeburn 5793: ];
1.202 raeburn 5794: }
1.190 raeburn 5795: if (!$allowed) {
1.358 raeburn 5796: if ($context eq 'course') {
5797: $r->internal_redirect('/adm/viewclasslist');
5798: return OK;
1.470 raeburn 5799: } elsif ($context eq 'coauthor') {
5800: $r->internal_redirect('/adm/viewcoauthors');
5801: return OK;
1.358 raeburn 5802: }
1.190 raeburn 5803: $env{'user.error.msg'}=
5804: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
5805: "or view user status.";
5806: return HTTP_NOT_ACCEPTABLE;
5807: }
5808:
5809: &Apache::loncommon::content_type($r,'text/html');
5810: $r->send_http_header;
5811:
1.375 raeburn 5812: my $showcredits;
5813: if ((($context eq 'course') && ($crstype eq 'Course')) ||
5814: ($context eq 'domain')) {
5815: my %domdefaults =
5816: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
5817: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
5818: $showcredits = 1;
5819: }
5820: }
5821:
1.190 raeburn 5822: # Main switch on form.action and form.state, as appropriate
5823: if (! exists($env{'form.action'})) {
1.351 raeburn 5824: $args = {bread_crumbs => $brcrum,
5825: bread_crumbs_component => $bread_crumbs_component};
5826: $r->print(&header(undef,$args));
1.318 raeburn 5827: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5828: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 5829: my $helpitem = 'Course_Create_Class_List';
5830: if ($context eq 'author') {
5831: $helpitem = 'Author_Create_Coauthor_List';
5832: } elsif ($context eq 'domain') {
5833: $helpitem = 'Domain_Create_Users';
5834: }
1.351 raeburn 5835: push(@{$brcrum},
5836: { href => '/adm/createuser?action=upload&state=',
5837: text => 'Upload Users List',
1.439 raeburn 5838: help => $helpitem,
1.351 raeburn 5839: });
5840: $bread_crumbs_component = 'Upload Users List';
5841: $args = {bread_crumbs => $brcrum,
5842: bread_crumbs_component => $bread_crumbs_component};
5843: $r->print(&header(undef,$args));
1.190 raeburn 5844: $r->print('<form name="studentform" method="post" '.
5845: 'enctype="multipart/form-data" '.
5846: ' action="/adm/createuser">'."\n");
5847: if (! exists($env{'form.state'})) {
5848: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5849: } elsif ($env{'form.state'} eq 'got_file') {
1.448 raeburn 5850: my $result =
5851: &Apache::lonuserutils::print_upload_manager_form($r,$context,
5852: $permission,
5853: $crstype,$showcredits);
5854: if ($result eq 'missingdata') {
5855: delete($env{'form.state'});
5856: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5857: }
1.190 raeburn 5858: } elsif ($env{'form.state'} eq 'enrolling') {
5859: if ($env{'form.datatoken'}) {
1.448 raeburn 5860: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
5861: $permission,
5862: $showcredits);
5863: if ($result eq 'missingdata') {
5864: delete($env{'form.state'});
5865: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5866: } elsif ($result eq 'invalidhome') {
5867: $env{'form.state'} = 'got_file';
5868: delete($env{'form.lcserver'});
5869: my $result =
5870: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
5871: $crstype,$showcredits);
5872: if ($result eq 'missingdata') {
5873: delete($env{'form.state'});
5874: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5875: }
5876: }
5877: } else {
5878: delete($env{'form.state'});
5879: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 5880: }
5881: } else {
5882: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5883: }
1.447 raeburn 5884: $r->print('</form>');
1.416 raeburn 5885: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
5886: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 5887: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 5888: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 5889: my $phase = $env{'form.phase'};
5890: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 5891: &Apache::loncreateuser::restore_prev_selections();
5892: my $srch;
5893: foreach my $item (@search) {
5894: $srch->{$item} = $env{'form.'.$item};
5895: }
1.207 raeburn 5896: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 5897: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 5898: if ($env{'form.phase'} eq 'createnewuser') {
5899: my $response;
5900: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 5901: my $response =
5902: '<span class="LC_warning">'
5903: .&mt('You must specify a valid username. Only the following are allowed:'
5904: .' letters numbers - . @')
5905: .'</span>';
1.221 raeburn 5906: $env{'form.phase'} = '';
1.375 raeburn 5907: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 5908: $crstype,$brcrum,$permission);
1.207 raeburn 5909: } else {
5910: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
5911: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
5912: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 5913: $srch,$response,$context,
1.375 raeburn 5914: $permission,$crstype,$brcrum,
5915: $showcredits);
1.207 raeburn 5916: }
5917: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 5918: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 5919: &user_search_result($context,$srch);
1.190 raeburn 5920: if ($env{'form.currstate'} eq 'modify') {
5921: $currstate = $env{'form.currstate'};
5922: }
5923: if ($currstate eq 'select') {
5924: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 5925: \@search,$context,undef,$crstype,
5926: $brcrum);
1.416 raeburn 5927: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
5928: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 5929: if (($srch->{'srchby'} eq 'uname') &&
5930: ($srch->{'srchtype'} eq 'exact')) {
5931: $ccuname = $srch->{'srchterm'};
5932: $ccdomain= $srch->{'srchdomain'};
5933: } else {
5934: my @matchedunames = keys(%{$results});
5935: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
5936: }
5937: $ccuname =&LONCAPA::clean_username($ccuname);
5938: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 5939: if ($env{'form.action'} eq 'accesslogs') {
5940: my $uhome;
5941: if (($ccuname ne '') && ($ccdomain ne '')) {
5942: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
5943: }
5944: if (($uhome eq '') || ($uhome eq 'no_host')) {
5945: $env{'form.phase'} = '';
5946: undef($forcenewuser);
5947: #if ($response) {
5948: # unless ($response =~ m{\Q<br /><br />\E$}) {
5949: # $response .= '<br /><br />';
5950: # }
5951: #}
5952: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 5953: $forcenewuser,$crstype,$brcrum,
5954: $permission);
1.416 raeburn 5955: } else {
5956: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
5957: }
5958: } else {
5959: if ($env{'form.forcenewuser'}) {
5960: $response = '';
5961: }
5962: &print_user_modification_page($r,$ccuname,$ccdomain,
5963: $srch,$response,$context,
5964: $permission,$crstype,$brcrum);
1.190 raeburn 5965: }
5966: } elsif ($currstate eq 'query') {
1.351 raeburn 5967: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 5968: } else {
1.229 raeburn 5969: $env{'form.phase'} = '';
1.207 raeburn 5970: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 5971: $forcenewuser,$crstype,$brcrum,
5972: $permission);
1.190 raeburn 5973: }
5974: } elsif ($env{'form.phase'} eq 'userpicked') {
5975: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
5976: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 5977: if ($env{'form.action'} eq 'accesslogs') {
5978: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
5979: } else {
5980: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
5981: $context,$permission,$crstype,
5982: $brcrum);
5983: }
5984: } elsif ($env{'form.action'} eq 'accesslogs') {
5985: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
5986: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
5987: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 5988: }
5989: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.451 raeburn 5990: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 5991: } else {
1.351 raeburn 5992: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 5993: $brcrum,$permission);
1.190 raeburn 5994: }
5995: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 5996: my $prefix;
1.190 raeburn 5997: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 5998: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 5999: } else {
1.439 raeburn 6000: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 6001: }
1.362 raeburn 6002: } elsif (($env{'form.action'} eq 'processauthorreq') &&
6003: ($permission->{'cusr'}) &&
6004: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
6005: push(@{$brcrum},
6006: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 6007: text => 'Authoring Space requests',
1.362 raeburn 6008: help => 'Domain_Role_Approvals'});
6009: $bread_crumbs_component = 'Authoring requests';
6010: if ($env{'form.state'} eq 'done') {
6011: push(@{$brcrum},
6012: {href => '/adm/createuser?action=authorreqqueue',
6013: text => 'Result',
6014: help => 'Domain_Role_Approvals'});
6015: $bread_crumbs_component = 'Authoring request result';
6016: }
6017: $args = { bread_crumbs => $brcrum,
6018: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 6019: my $js = &usernamerequest_javascript();
6020: $r->print(&header(&add_script($js),$args));
1.362 raeburn 6021: if (!exists($env{'form.state'})) {
6022: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
6023: $env{'request.role.domain'}));
6024: } elsif ($env{'form.state'} eq 'done') {
6025: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
6026: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
6027: $env{'request.role.domain'}));
6028: }
1.391 raeburn 6029: } elsif (($env{'form.action'} eq 'processusernamereq') &&
6030: ($permission->{'cusr'}) &&
6031: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
6032: push(@{$brcrum},
6033: {href => '/adm/createuser?action=processusernamereq',
6034: text => 'LON-CAPA account requests',
6035: help => 'Domain_Username_Approvals'});
6036: $bread_crumbs_component = 'Account requests';
6037: if ($env{'form.state'} eq 'done') {
6038: push(@{$brcrum},
6039: {href => '/adm/createuser?action=usernamereqqueue',
6040: text => 'Result',
6041: help => 'Domain_Username_Approvals'});
6042: $bread_crumbs_component = 'LON-CAPA account request result';
6043: }
6044: $args = { bread_crumbs => $brcrum,
6045: bread_crumbs_component => $bread_crumbs_component};
6046: my $js = &usernamerequest_javascript();
6047: $r->print(&header(&add_script($js),$args));
6048: if (!exists($env{'form.state'})) {
6049: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
6050: $env{'request.role.domain'}));
6051: } elsif ($env{'form.state'} eq 'done') {
6052: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
6053: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
6054: $env{'request.role.domain'}));
6055: }
6056: } elsif (($env{'form.action'} eq 'displayuserreq') &&
6057: ($permission->{'cusr'})) {
6058: my $dom = $env{'form.domain'};
6059: my $uname = $env{'form.username'};
6060: my $warning;
6061: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
6062: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
6063: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
6064: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
6065: if ($uhome eq 'no_host') {
6066: my $queue = $env{'form.queue'};
6067: my $reqkey = &escape($uname).'_'.$queue;
6068: my $namespace = 'usernamequeue';
6069: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
6070: my %queued =
6071: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
6072: unless ($queued{$reqkey}) {
6073: $warning = &mt('No information was found for this LON-CAPA account request.');
6074: }
6075: } else {
6076: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
6077: }
6078: } else {
6079: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
6080: }
6081: } else {
6082: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
6083: }
6084: } else {
6085: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
6086: }
6087: my $args = { only_body => 1 };
6088: $r->print(&header(undef,$args).
6089: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
6090: if ($warning ne '') {
6091: $r->print('<div class="LC_warning">'.$warning.'</div>');
6092: } else {
6093: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
6094: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
6095: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6096: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6097: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
6098: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
6099: my %info =
6100: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
6101: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 6102: my $usertype = $info{$uname}{'inststatus'};
6103: unless ($usertype) {
6104: $usertype = 'default';
6105: }
1.442 raeburn 6106: my ($showstatus,$showemail,$pickstart);
6107: my $numextras = 0;
6108: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.443 raeburn 6109: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
6110: if (ref($usertypes) eq 'HASH') {
6111: if ($usertypes->{$usertype}) {
6112: $showstatus = $usertypes->{$usertype};
6113: } else {
6114: $showstatus = $othertitle;
6115: }
6116: if ($showstatus) {
6117: $numextras ++;
6118: }
1.442 raeburn 6119: }
6120: }
6121: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
6122: $showemail = $info{$uname}{'email'};
6123: $numextras ++;
6124: }
1.396 raeburn 6125: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
6126: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.442 raeburn 6127: $pickstart = 1;
1.396 raeburn 6128: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.442 raeburn 6129: my ($num,$count);
1.396 raeburn 6130: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.442 raeburn 6131: $count += $numextras;
1.396 raeburn 6132: foreach my $field (@{$infofields}) {
6133: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
6134: next unless ($infotitles->{$field});
6135: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
6136: $info{$uname}{$field});
6137: $num ++;
1.442 raeburn 6138: unless ($count == $num) {
1.396 raeburn 6139: $r->print(&Apache::lonhtmlcommon::row_closure());
6140: }
6141: }
1.442 raeburn 6142: }
6143: }
6144: if ($numextras) {
6145: unless ($pickstart) {
6146: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
6147: $pickstart = 1;
6148: }
6149: if ($showemail) {
6150: my $closure = '';
6151: unless ($showstatus) {
6152: $closure = 1;
1.391 raeburn 6153: }
1.442 raeburn 6154: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
6155: $showemail.
6156: &Apache::lonhtmlcommon::row_closure($closure));
1.391 raeburn 6157: }
1.442 raeburn 6158: if ($showstatus) {
6159: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
6160: $showstatus.
6161: &Apache::lonhtmlcommon::row_closure(1));
6162: }
6163: }
6164: if ($pickstart) {
6165: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
6166: } else {
6167: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
1.391 raeburn 6168: }
1.442 raeburn 6169: } else {
6170: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 6171: }
6172: }
6173: }
6174: }
6175: }
1.442 raeburn 6176: $r->print(&close_popup_form());
1.207 raeburn 6177: } elsif (($env{'form.action'} eq 'listusers') &&
6178: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 6179: my $helpitem = 'Course_View_Class_List';
6180: if ($context eq 'author') {
6181: $helpitem = 'Author_View_Coauthor_List';
6182: } elsif ($context eq 'domain') {
6183: $helpitem = 'Domain_View_Users_List';
6184: }
1.202 raeburn 6185: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 6186: push(@{$brcrum},
6187: {href => '/adm/createuser?action=listusers',
6188: text => "List Users"},
6189: {href => "/adm/createuser",
6190: text => "Result",
1.439 raeburn 6191: help => $helpitem});
1.351 raeburn 6192: $bread_crumbs_component = 'Update Users';
6193: $args = {bread_crumbs => $brcrum,
6194: bread_crumbs_component => $bread_crumbs_component};
6195: $r->print(&header(undef,$args));
1.202 raeburn 6196: my $setting = $env{'form.roletype'};
6197: my $choice = $env{'form.bulkaction'};
6198: if ($permission->{'cusr'}) {
1.336 raeburn 6199: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 6200: } else {
6201: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 6202: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 6203: }
6204: } else {
1.351 raeburn 6205: push(@{$brcrum},
6206: {href => '/adm/createuser?action=listusers',
6207: text => "List Users",
1.439 raeburn 6208: help => $helpitem});
1.351 raeburn 6209: $bread_crumbs_component = 'List Users';
6210: $args = {bread_crumbs => $brcrum,
6211: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 6212: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
6213: my $formname = 'studentform';
1.364 raeburn 6214: my $hidecall = "hide_searching();";
1.321 raeburn 6215: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
6216: ($env{'form.roletype'} eq 'community'))) {
6217: if ($env{'form.roletype'} eq 'course') {
6218: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
6219: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
6220: $formname);
6221: } elsif ($env{'form.roletype'} eq 'community') {
6222: $cb_jscript =
6223: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
6224: my %elements = (
6225: coursepick => 'radio',
6226: coursetotal => 'text',
6227: courselist => 'text',
6228: );
6229: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
6230: }
1.364 raeburn 6231: $jscript .= &verify_user_display($context)."\n".
6232: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 6233: my $js = &add_script($jscript).$cb_jscript;
6234: my $loadcode =
6235: &Apache::lonuserutils::course_selector_loadcode($formname);
6236: if ($loadcode ne '') {
1.364 raeburn 6237: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
6238: } else {
6239: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 6240: }
1.351 raeburn 6241: $r->print(&header($js,$args));
1.191 raeburn 6242: } else {
1.364 raeburn 6243: $args->{add_entries} = {onload => $hidecall};
6244: $jscript = &verify_user_display($context).
6245: &Apache::loncommon::check_uncheck_jscript();
6246: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 6247: }
1.202 raeburn 6248: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 6249: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
6250: $showcredits);
1.191 raeburn 6251: }
1.213 raeburn 6252: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 6253: my $brtext;
6254: if ($crstype eq 'Community') {
6255: $brtext = 'Drop Members';
6256: } else {
6257: $brtext = 'Drop Students';
6258: }
1.351 raeburn 6259: push(@{$brcrum},
6260: {href => '/adm/createuser?action=drop',
6261: text => $brtext,
6262: help => 'Course_Drop_Student'});
6263: if ($env{'form.state'} eq 'done') {
6264: push(@{$brcrum},
6265: {href=>'/adm/createuser?action=drop',
6266: text=>"Result"});
6267: }
6268: $bread_crumbs_component = $brtext;
6269: $args = {bread_crumbs => $brcrum,
6270: bread_crumbs_component => $bread_crumbs_component};
6271: $r->print(&header(undef,$args));
1.213 raeburn 6272: if (!exists($env{'form.state'})) {
1.318 raeburn 6273: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 6274: } elsif ($env{'form.state'} eq 'done') {
6275: &Apache::lonuserutils::update_user_list($r,$context,undef,
6276: $env{'form.action'});
6277: }
1.202 raeburn 6278: } elsif ($env{'form.action'} eq 'dateselect') {
6279: if ($permission->{'cusr'}) {
1.351 raeburn 6280: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 6281: &Apache::lonuserutils::date_section_selector($context,$permission,
6282: $crstype,$showcredits));
1.202 raeburn 6283: } else {
1.351 raeburn 6284: $r->print(&header(undef,{'no_nav_bar' => 1}).
6285: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 6286: }
1.237 raeburn 6287: } elsif ($env{'form.action'} eq 'selfenroll') {
1.469 raeburn 6288: my %currsettings;
6289: if ($permission->{selfenrolladmin} || $permission->{selfenrollview}) {
6290: %currsettings = (
1.398 raeburn 6291: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
6292: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
6293: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
6294: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
6295: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
6296: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
6297: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
6298: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
6299: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
6300: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
6301: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
6302: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
6303: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 6304: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 6305: );
1.469 raeburn 6306: }
6307: if ($permission->{selfenrolladmin}) {
1.398 raeburn 6308: push(@{$brcrum},
6309: {href => '/adm/createuser?action=selfenroll',
6310: text => "Configure Self-enrollment",
6311: help => 'Course_Self_Enrollment'});
6312: if (!exists($env{'form.state'})) {
6313: $args = { bread_crumbs => $brcrum,
6314: bread_crumbs_component => 'Configure Self-enrollment'};
6315: $r->print(&header(undef,$args));
6316: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
6317: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
6318: } elsif ($env{'form.state'} eq 'done') {
6319: push (@{$brcrum},
6320: {href=>'/adm/createuser?action=selfenroll',
6321: text=>"Result"});
6322: $args = { bread_crumbs => $brcrum,
6323: bread_crumbs_component => 'Self-enrollment result'};
6324: $r->print(&header(undef,$args));
6325: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 6326: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 6327: }
1.469 raeburn 6328: } elsif ($permission->{selfenrollview}) {
6329: push(@{$brcrum},
6330: {href => '/adm/createuser?action=selfenroll',
6331: text => "View Self-enrollment configuration",
6332: help => 'Course_Self_Enrollment'});
6333: $args = { bread_crumbs => $brcrum,
6334: bread_crumbs_component => 'Self-enrollment Settings'};
6335: $r->print(&header(undef,$args));
6336: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
6337: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings,'',1);
1.398 raeburn 6338: } else {
6339: $r->print(&header(undef,{'no_nav_bar' => 1}).
6340: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 6341: }
1.277 raeburn 6342: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 6343: if ($permission->{selfenrolladmin}) {
1.351 raeburn 6344: push(@{$brcrum},
6345: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 6346: text => 'Enrollment requests',
1.439 raeburn 6347: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 6348: $bread_crumbs_component = 'Enrollment requests';
6349: if ($env{'form.state'} eq 'done') {
6350: push(@{$brcrum},
6351: {href => '/adm/createuser?action=selfenrollqueue',
6352: text => 'Result',
1.439 raeburn 6353: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 6354: $bread_crumbs_component = 'Enrollment result';
6355: }
6356: $args = { bread_crumbs => $brcrum,
6357: bread_crumbs_component => $bread_crumbs_component};
6358: $r->print(&header(undef,$args));
6359: my $coursedesc = $env{'course.'.$cid.'.description'};
6360: if (!exists($env{'form.state'})) {
6361: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
6362: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
6363: $cdom,$cnum));
6364: } elsif ($env{'form.state'} eq 'done') {
6365: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
6366: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 6367: $cdom,$cnum,$coursedesc));
1.418 raeburn 6368: }
6369: } else {
6370: $r->print(&header(undef,{'no_nav_bar' => 1}).
6371: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 6372: }
1.418 raeburn 6373: } elsif ($env{'form.action'} eq 'changelogs') {
6374: if ($permission->{cusr} || $permission->{view}) {
6375: &print_userchangelogs_display($r,$context,$permission,$brcrum);
6376: } else {
6377: $r->print(&header(undef,{'no_nav_bar' => 1}).
6378: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 6379: }
1.428 raeburn 6380: } elsif ($env{'form.action'} eq 'helpdesk') {
1.464 raeburn 6381: if (($permission->{'owner'} || $permission->{'co-owner'}) &&
6382: ($permission->{'cusr'} || $permission->{'view'})) {
1.428 raeburn 6383: if ($env{'form.state'} eq 'process') {
6384: if ($permission->{'owner'}) {
6385: &update_helpdeskaccess($r,$permission,$brcrum);
6386: } else {
6387: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 6388: }
1.428 raeburn 6389: } else {
6390: &print_helpdeskaccess_display($r,$permission,$brcrum);
6391: }
6392: } else {
6393: $r->print(&header(undef,{'no_nav_bar' => 1}).
6394: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
6395: }
1.465 raeburn 6396: } elsif ($env{'form.action'} eq 'rolerequests') {
6397: if ($permission->{cusr} || $permission->{view}) {
6398: &print_queued_roles($r,$context,$permission,$brcrum);
6399: }
6400: } elsif ($env{'form.action'} eq 'queuedroles') {
6401: if (($permission->{cusr}) && ($context eq 'domain')) {
6402: if (&show_role_requests($context,$env{'request.role.domain'})) {
6403: if ($env{'form.state'} eq 'done') {
6404: &process_pendingroles($r,$context,$permission,$brcrum);
6405: } else {
6406: &print_pendingroles($r,$context,$permission,$brcrum);
6407: }
6408: } else {
6409: $r->print(&header(undef,{'no_nav_bar' => 1}).
6410: '<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>');
6411: }
6412: } else {
6413: $r->print(&header(undef,{'no_nav_bar' => 1}).
6414: '<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>');
6415: }
1.470 raeburn 6416: } elsif ($env{'form.action'} eq 'camanagers') {
6417: if (($permission->{cusr}) && ($context eq 'author')) {
6418: push(@{$brcrum},
6419: {href => '/adm/createuser?action=camanagers',
1.473 raeburn 6420: text => 'Co-author Managers',
1.470 raeburn 6421: help => 'Author_Manage_Coauthors'});
6422: if ($env{'form.state'} eq 'process') {
6423: push(@{$brcrum},
6424: {href => '/adm/createuser?action=camanagers',
6425: text => 'Result',
6426: help => 'Author_Manage_Coauthors'});
6427: }
6428: $args = { bread_crumbs => $brcrum };
6429: $r->print(&header(undef,$args));
6430: my $coursedesc = $env{'course.'.$cid.'.description'};
6431: if (!exists($env{'form.state'})) {
6432: $r->print('<h3>'.&mt('Co-author Management').'</h3>'."\n".
6433: &display_coauthor_managers($permission));
6434: } elsif ($env{'form.state'} eq 'process') {
6435: $r->print('<h3>'.&mt('Co-author Management Update Result').'</h3>'."\n".
6436: &update_coauthor_managers($permission));
6437: }
6438: }
6439: } elsif (($env{'form.action'} eq 'calist') && ($context eq 'author')) {
6440: if ($permission->{'cusr'}) {
6441: my ($role,$audom,$auname,$canview,$canedit) =
6442: &Apache::lonviewcoauthors::get_allowable();
6443: if (($canedit) && ($env{'form.forceedit'})) {
6444: &Apache::lonviewcoauthors::get_editor_crumbs($brcrum,'/adm/createuser');
6445: my $args = { 'bread_crumbs' => $brcrum };
6446: $r->print(&Apache::loncommon::start_page('Configure co-author listing',undef,
6447: $args).
6448: &Apache::lonviewcoauthors::edit_settings($audom,$auname,$role,
6449: '/adm/createuser'));
6450: } else {
6451: push(@{$brcrum},
6452: {href => '/adm/createuser?action=calist',
6453: text => 'Coauthor-viewable list',
6454: help => 'Author_List_Coauthors'});
6455: my $args = { 'bread_crumbs' => $brcrum };
6456: $r->print(&Apache::loncommon::start_page('Coauthor-viewable list',undef,
6457: $args));
6458: my %viewsettings =
6459: &Apache::lonviewcoauthors::retrieve_view_settings($auname,$audom,$role);
6460: if ($viewsettings{'show'} eq 'none') {
6461: $r->print('<h3>'.&mt('Coauthor-viewable listing').'</h3>'.
6462: '<p class="LC_info">'.
6463: &mt('Listing of co-authors not enabled for this Authoring Space').
6464: '</p>');
6465: } else {
6466: &Apache::lonviewcoauthors::print_coauthors($r,$auname,$audom,$role,
6467: '/adm/createuser',\%viewsettings);
6468: }
6469: }
6470: } else {
6471: $r->internal_redirect('/adm/viewcoauthors');
6472: return OK;
6473: }
1.190 raeburn 6474: } else {
1.351 raeburn 6475: $bread_crumbs_component = 'User Management';
6476: $args = { bread_crumbs => $brcrum,
6477: bread_crumbs_component => $bread_crumbs_component};
6478: $r->print(&header(undef,$args));
1.318 raeburn 6479: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 6480: }
1.351 raeburn 6481: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 6482: return OK;
6483: }
6484:
6485: sub header {
1.351 raeburn 6486: my ($jscript,$args) = @_;
1.190 raeburn 6487: my $start_page;
1.351 raeburn 6488: if (ref($args) eq 'HASH') {
6489: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 6490: } else {
1.351 raeburn 6491: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 6492: }
6493: return $start_page;
6494: }
1.2 www 6495:
1.191 raeburn 6496: sub add_script {
6497: my ($js) = @_;
1.301 bisitz 6498: return '<script type="text/javascript">'."\n"
6499: .'// <![CDATA['."\n"
6500: .$js."\n"
6501: .'// ]]>'."\n"
6502: .'</script>'."\n";
1.191 raeburn 6503: }
6504:
1.391 raeburn 6505: sub usernamerequest_javascript {
6506: my $js = <<ENDJS;
6507:
6508: function openusernamereqdisplay(dom,uname,queue) {
6509: var url = '/adm/createuser?action=displayuserreq';
6510: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
6511: var title = 'Account_Request_Browser';
6512: var options = 'scrollbars=1,resizable=1,menubar=0';
6513: options += ',width=700,height=600';
6514: var stdeditbrowser = open(url,title,options,'1');
6515: stdeditbrowser.focus();
6516: return;
6517: }
6518:
6519: ENDJS
6520: }
6521:
6522: sub close_popup_form {
6523: my $close= &mt('Close Window');
6524: return << "END";
6525: <p><form name="displayreq" action="" method="post">
6526: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
6527: </form></p>
6528: END
6529: }
6530:
1.202 raeburn 6531: sub verify_user_display {
1.364 raeburn 6532: my ($context) = @_;
1.374 raeburn 6533: my %lt = &Apache::lonlocal::texthash (
6534: course => 'course(s): description, section(s), status',
6535: community => 'community(s): description, section(s), status',
6536: author => 'author',
6537: );
1.364 raeburn 6538: my $photos;
6539: if (($context eq 'course') && $env{'request.course.id'}) {
6540: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
6541: }
1.202 raeburn 6542: my $output = <<"END";
6543:
1.364 raeburn 6544: function hide_searching() {
6545: if (document.getElementById('searching')) {
6546: document.getElementById('searching').style.display = 'none';
6547: }
6548: return;
6549: }
6550:
1.202 raeburn 6551: function display_update() {
6552: document.studentform.action.value = 'listusers';
6553: document.studentform.phase.value = 'display';
6554: document.studentform.submit();
6555: }
6556:
1.364 raeburn 6557: function updateCols(caller) {
6558: var context = '$context';
6559: var photos = '$photos';
6560: if (caller == 'Status') {
1.374 raeburn 6561: if ((context == 'domain') &&
6562: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
6563: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 6564: document.getElementById('showcolstatus').checked = false;
6565: document.getElementById('showcolstatus').disabled = 'disabled';
6566: document.getElementById('showcolstart').checked = false;
6567: document.getElementById('showcolend').checked = false;
1.374 raeburn 6568: } else {
6569: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
6570: document.getElementById('showcolstatus').checked = true;
6571: document.getElementById('showcolstatus').disabled = '';
6572: document.getElementById('showcolstart').checked = true;
6573: document.getElementById('showcolend').checked = true;
6574: } else {
6575: document.getElementById('showcolstatus').checked = false;
6576: document.getElementById('showcolstatus').disabled = 'disabled';
6577: document.getElementById('showcolstart').checked = false;
6578: document.getElementById('showcolend').checked = false;
6579: }
1.472 raeburn 6580: if (context == 'author') {
6581: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Expired') {
6582: document.getElementById('showcolmanager').checked = false;
6583: document.getElementById('showcolmanager').disabled = 'disabled';
6584: } else if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value != 'aa') {
6585: document.getElementById('showcolmanager').checked = true;
6586: document.getElementById('showcolmanager').disabled = '';
6587: }
6588: }
1.364 raeburn 6589: }
6590: }
6591: if (caller == 'output') {
6592: if (photos == 1) {
6593: if (document.getElementById('showcolphoto')) {
6594: var photoitem = document.getElementById('showcolphoto');
6595: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
6596: photoitem.checked = true;
6597: photoitem.disabled = '';
6598: } else {
6599: photoitem.checked = false;
6600: photoitem.disabled = 'disabled';
6601: }
6602: }
6603: }
6604: }
6605: if (caller == 'showrole') {
1.371 raeburn 6606: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
6607: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 6608: document.getElementById('showcolrole').checked = true;
6609: document.getElementById('showcolrole').disabled = '';
6610: } else {
6611: document.getElementById('showcolrole').checked = false;
6612: document.getElementById('showcolrole').disabled = 'disabled';
6613: }
1.374 raeburn 6614: if (context == 'domain') {
1.382 raeburn 6615: var quotausageshow = 0;
1.374 raeburn 6616: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
6617: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
6618: document.getElementById('showcolstatus').checked = false;
6619: document.getElementById('showcolstatus').disabled = 'disabled';
6620: document.getElementById('showcolstart').checked = false;
6621: document.getElementById('showcolend').checked = false;
6622: } else {
6623: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
6624: document.getElementById('showcolstatus').checked = true;
6625: document.getElementById('showcolstatus').disabled = '';
6626: document.getElementById('showcolstart').checked = true;
6627: document.getElementById('showcolend').checked = true;
6628: }
6629: }
6630: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
6631: document.getElementById('showcolextent').disabled = 'disabled';
6632: document.getElementById('showcolextent').checked = 'false';
6633: document.getElementById('showextent').style.display='none';
6634: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 6635: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
6636: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
6637: if (document.getElementById('showcolauthorusage')) {
6638: document.getElementById('showcolauthorusage').disabled = '';
6639: }
6640: if (document.getElementById('showcolauthorquota')) {
6641: document.getElementById('showcolauthorquota').disabled = '';
6642: }
6643: quotausageshow = 1;
6644: }
1.374 raeburn 6645: } else {
6646: document.getElementById('showextent').style.display='block';
6647: document.getElementById('showextent').style.textAlign='left';
6648: document.getElementById('showextent').style.textFace='normal';
6649: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
6650: document.getElementById('showcolextent').disabled = '';
6651: document.getElementById('showcolextent').checked = 'true';
6652: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
6653: } else {
6654: document.getElementById('showcolextent').disabled = '';
6655: document.getElementById('showcolextent').checked = 'true';
6656: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
6657: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
6658: } else {
6659: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
6660: }
6661: }
6662: }
1.382 raeburn 6663: if (quotausageshow == 0) {
6664: if (document.getElementById('showcolauthorusage')) {
6665: document.getElementById('showcolauthorusage').checked = false;
6666: document.getElementById('showcolauthorusage').disabled = 'disabled';
6667: }
6668: if (document.getElementById('showcolauthorquota')) {
6669: document.getElementById('showcolauthorquota').checked = false;
6670: document.getElementById('showcolauthorquota').disabled = 'disabled';
6671: }
6672: }
1.374 raeburn 6673: }
1.472 raeburn 6674: if (context == 'author') {
6675: if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'aa') {
6676: document.getElementById('showcolmanager').checked = false;
6677: document.getElementById('showcolmanager').disabled = 'disabled';
6678: } else if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value != 'Expired') {
6679: document.getElementById('showcolmanager').checked = true;
6680: document.getElementById('showcolmanager').disabled = '';
6681: }
6682: }
1.364 raeburn 6683: }
6684: return;
6685: }
6686:
1.202 raeburn 6687: END
6688: return $output;
6689:
6690: }
6691:
1.190 raeburn 6692: ###############################################################
6693: ###############################################################
6694: # Menu Phase One
6695: sub print_main_menu {
1.318 raeburn 6696: my ($permission,$context,$crstype) = @_;
6697: my $linkcontext = $context;
6698: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
6699: if (($context eq 'course') && ($crstype eq 'Community')) {
6700: $linkcontext = lc($crstype);
6701: $stuterm = 'Members';
6702: }
1.208 raeburn 6703: my %links = (
1.298 droeschl 6704: domain => {
6705: upload => 'Upload a File of Users',
6706: singleuser => 'Add/Modify a User',
6707: listusers => 'Manage Users',
6708: },
6709: author => {
6710: upload => 'Upload a File of Co-authors',
6711: singleuser => 'Add/Modify a Co-author',
6712: listusers => 'Manage Co-authors',
6713: },
6714: course => {
6715: upload => 'Upload a File of Course Users',
6716: singleuser => 'Add/Modify a Course User',
1.354 www 6717: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 6718: },
1.318 raeburn 6719: community => {
6720: upload => 'Upload a File of Community Users',
6721: singleuser => 'Add/Modify a Community User',
1.354 www 6722: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 6723: },
6724: );
6725: my %linktitles = (
6726: domain => {
6727: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
6728: listusers => 'Show and manage users in this domain.',
6729: },
6730: author => {
6731: singleuser => 'Add a user with a co- or assistant author role.',
6732: listusers => 'Show and manage co- or assistant authors.',
6733: },
6734: course => {
6735: singleuser => 'Add a user with a certain role to this course.',
6736: listusers => 'Show and manage users in this course.',
6737: },
6738: community => {
6739: singleuser => 'Add a user with a certain role to this community.',
6740: listusers => 'Show and manage users in this community.',
6741: },
1.298 droeschl 6742: );
1.465 raeburn 6743:
1.418 raeburn 6744: if ($linkcontext eq 'domain') {
6745: unless ($permission->{'cusr'}) {
1.430 raeburn 6746: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 6747: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
6748: }
6749: } elsif ($linkcontext eq 'course') {
6750: unless ($permission->{'cusr'}) {
6751: $links{'course'}{'singleuser'} = 'View a Course User';
6752: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
6753: $links{'course'}{'listusers'} = 'List Course Users';
6754: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
6755: }
6756: } elsif ($linkcontext eq 'community') {
6757: unless ($permission->{'cusr'}) {
6758: $links{'community'}{'singleuser'} = 'View a Community User';
6759: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
6760: $links{'community'}{'listusers'} = 'List Community Users';
6761: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
6762: }
6763: }
1.298 droeschl 6764: my @menu = ( {categorytitle => 'Single Users',
6765: items =>
6766: [
6767: {
1.318 raeburn 6768: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 6769: icon => 'edit-redo.png',
6770: #help => 'Course_Change_Privileges',
6771: url => '/adm/createuser?action=singleuser',
1.418 raeburn 6772: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 6773: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 6774: },
6775: ]},
6776:
6777: {categorytitle => 'Multiple Users',
6778: items =>
6779: [
6780: {
1.318 raeburn 6781: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 6782: icon => 'uplusr.png',
1.298 droeschl 6783: #help => 'Course_Create_Class_List',
6784: url => '/adm/createuser?action=upload',
6785: permission => $permission->{'cusr'},
6786: linktitle => 'Upload a CSV or a text file containing users.',
6787: },
6788: {
1.318 raeburn 6789: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 6790: icon => 'mngcu.png',
1.298 droeschl 6791: #help => 'Course_View_Class_List',
6792: url => '/adm/createuser?action=listusers',
6793: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 6794: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 6795: },
6796:
6797: ]},
6798:
6799: {categorytitle => 'Administration',
6800: items => [ ]},
6801: );
1.415 raeburn 6802:
1.265 mielkec 6803: if ($context eq 'domain'){
1.416 raeburn 6804: push(@{ $menu[0]->{items} }, # Single Users
6805: {
6806: linktext => 'User Access Log',
1.417 raeburn 6807: icon => 'document-properties.png',
1.425 raeburn 6808: #help => 'Domain_User_Access_Logs',
1.416 raeburn 6809: url => '/adm/createuser?action=accesslogs',
6810: permission => $permission->{'activity'},
6811: linktitle => 'View user access log.',
6812: }
6813: );
1.298 droeschl 6814:
6815: push(@{ $menu[2]->{items} }, #Category: Administration
6816: {
6817: linktext => 'Custom Roles',
6818: icon => 'emblem-photos.png',
6819: #help => 'Course_Editing_Custom_Roles',
6820: url => '/adm/createuser?action=custom',
6821: permission => $permission->{'custom'},
6822: linktitle => 'Configure a custom role.',
6823: },
1.362 raeburn 6824: {
6825: linktext => 'Authoring Space Requests',
6826: icon => 'selfenrl-queue.png',
6827: #help => 'Domain_Role_Approvals',
6828: url => '/adm/createuser?action=processauthorreq',
6829: permission => $permission->{'cusr'},
6830: linktitle => 'Approve or reject author role requests',
6831: },
1.363 raeburn 6832: {
1.391 raeburn 6833: linktext => 'LON-CAPA Account Requests',
6834: icon => 'list-add.png',
6835: #help => 'Domain_Username_Approvals',
6836: url => '/adm/createuser?action=processusernamereq',
6837: permission => $permission->{'cusr'},
6838: linktitle => 'Approve or reject LON-CAPA account requests',
6839: },
6840: {
1.363 raeburn 6841: linktext => 'Change Log',
6842: icon => 'document-properties.png',
6843: #help => 'Course_User_Logs',
6844: url => '/adm/createuser?action=changelogs',
1.418 raeburn 6845: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 6846: linktitle => 'View change log.',
6847: },
1.298 droeschl 6848: );
6849:
1.265 mielkec 6850: }elsif ($context eq 'course'){
1.298 droeschl 6851: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 6852:
6853: my %linktext = (
6854: 'Course' => {
6855: single => 'Add/Modify a Student',
6856: drop => 'Drop Students',
6857: groups => 'Course Groups',
6858: },
6859: 'Community' => {
6860: single => 'Add/Modify a Member',
6861: drop => 'Drop Members',
6862: groups => 'Community Groups',
6863: },
6864: );
1.411 raeburn 6865: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 6866:
6867: my %linktitle = (
6868: 'Course' => {
6869: single => 'Add a user with the role of student to this course',
6870: drop => 'Remove a student from this course.',
6871: groups => 'Manage course groups',
6872: },
6873: 'Community' => {
6874: single => 'Add a user with the role of member to this community',
6875: drop => 'Remove a member from this community.',
6876: groups => 'Manage community groups',
6877: },
6878: );
6879:
1.411 raeburn 6880: $linktitle{'Placement'} = $linktitle{'Course'};
6881:
1.298 droeschl 6882: push(@{ $menu[0]->{items} }, #Category: Single Users
6883: {
1.318 raeburn 6884: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 6885: #help => 'Course_Add_Student',
6886: icon => 'list-add.png',
6887: url => '/adm/createuser?action=singlestudent',
6888: permission => $permission->{'cusr'},
1.318 raeburn 6889: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 6890: },
6891: );
6892:
6893: push(@{ $menu[1]->{items} }, #Category: Multiple Users
6894: {
1.318 raeburn 6895: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 6896: icon => 'edit-undo.png',
6897: #help => 'Course_Drop_Student',
6898: url => '/adm/createuser?action=drop',
6899: permission => $permission->{'cusr'},
1.318 raeburn 6900: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 6901: },
6902: );
6903: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 6904: {
6905: linktext => 'Helpdesk Access',
6906: icon => 'helpdesk-access.png',
6907: #help => 'Course_Helpdesk_Access',
6908: url => '/adm/createuser?action=helpdesk',
1.464 raeburn 6909: permission => (($permission->{'owner'} || $permission->{'co-owner'}) &&
6910: ($permission->{'view'} || $permission->{'cusr'})),
1.428 raeburn 6911: linktitle => 'Helpdesk access options',
6912: },
6913: {
1.298 droeschl 6914: linktext => 'Custom Roles',
6915: icon => 'emblem-photos.png',
6916: #help => 'Course_Editing_Custom_Roles',
6917: url => '/adm/createuser?action=custom',
6918: permission => $permission->{'custom'},
6919: linktitle => 'Configure a custom role.',
6920: },
6921: {
1.318 raeburn 6922: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 6923: icon => 'grps.png',
1.298 droeschl 6924: #help => 'Course_Manage_Group',
6925: url => '/adm/coursegroups?refpage=cusr',
6926: permission => $permission->{'grp_manage'},
1.318 raeburn 6927: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 6928: },
6929: {
1.328 wenzelju 6930: linktext => 'Change Log',
1.298 droeschl 6931: icon => 'document-properties.png',
6932: #help => 'Course_User_Logs',
6933: url => '/adm/createuser?action=changelogs',
1.418 raeburn 6934: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 6935: linktitle => 'View change log.',
6936: },
6937: );
1.277 raeburn 6938: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 6939: push(@{ $menu[2]->{items} },
1.398 raeburn 6940: {
1.298 droeschl 6941: linktext => 'Enrollment Requests',
6942: icon => 'selfenrl-queue.png',
6943: #help => 'Course_Approve_Selfenroll',
6944: url => '/adm/createuser?action=selfenrollqueue',
1.469 raeburn 6945: permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.298 droeschl 6946: linktitle =>'Approve or reject enrollment requests.',
6947: },
6948: );
1.277 raeburn 6949: }
1.298 droeschl 6950:
1.265 mielkec 6951: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 6952: if ($crstype ne 'Community') {
6953: push(@{ $menu[2]->{items} },
6954: {
6955: linktext => 'Automated Enrollment',
6956: icon => 'roles.png',
6957: #help => 'Course_Automated_Enrollment',
6958: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 6959: && (($permission->{'cusr'}) ||
6960: ($permission->{'view'}))),
1.320 raeburn 6961: url => '/adm/populate',
6962: linktitle => 'Automated enrollment manager.',
6963: }
6964: );
6965: }
6966: push(@{ $menu[2]->{items} },
1.298 droeschl 6967: {
6968: linktext => 'User Self-Enrollment',
1.342 wenzelju 6969: icon => 'self_enroll.png',
1.298 droeschl 6970: #help => 'Course_Self_Enrollment',
6971: url => '/adm/createuser?action=selfenroll',
1.469 raeburn 6972: permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.317 bisitz 6973: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 6974: },
6975: );
6976: }
1.363 raeburn 6977: } elsif ($context eq 'author') {
1.370 raeburn 6978: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 6979: {
6980: linktext => 'Change Log',
6981: icon => 'document-properties.png',
6982: #help => 'Course_User_Logs',
6983: url => '/adm/createuser?action=changelogs',
6984: permission => $permission->{'cusr'},
6985: linktitle => 'View change log.',
6986: },
1.470 raeburn 6987: {
1.472 raeburn 6988: linktext => 'Co-author Managers',
1.473 raeburn 6989: icon => 'camanager.png',
1.470 raeburn 6990: #help => 'Coauthor_Management',
6991: url => '/adm/createuser?action=camanagers',
6992: permission => $permission->{'author'},
6993: linktitle => 'Assign/Revoke right to manage co-author roles',
6994: },
6995: {
1.473 raeburn 6996: linktext => 'Configure Co-author Listing',
6997: icon => 'coauthors.png',
1.470 raeburn 6998: #help => 'Coauthor_Settings',
6999: url => '/adm/createuser?action=calist&forceedit=1',
7000: permission => ($permission->{'cusr'}),
7001: linktitle => 'Set availability of coauthor-viewable user listing',
7002: },
1.370 raeburn 7003: );
1.363 raeburn 7004: }
1.465 raeburn 7005: push(@{ $menu[2]->{items} },
7006: {
7007: linktext => 'Role Requests (other domains)',
7008: icon => 'edit-find.png',
7009: #help => 'Role_Requests',
7010: url => '/adm/createuser?action=rolerequests',
7011: permission => $permission->{'cusr'},
7012: linktitle => 'Role requests for users in other domains',
7013: },
7014: );
7015: if (&show_role_requests($context,$env{'request.role.domain'})) {
7016: push(@{ $menu[2]->{items} },
7017: {
7018: linktext => 'Queued Role Assignments (this domain)',
7019: icon => 'edit-find.png',
7020: #help => 'Role_Approvals',
7021: url => '/adm/createuser?action=queuedroles',
7022: permission => $permission->{'cusr'},
7023: linktitle => "Role requests for this domain's users",
7024: },
7025: );
7026: }
1.363 raeburn 7027: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 7028: # { text => 'View Log-in History',
7029: # help => 'Course_User_Logins',
7030: # action => 'logins',
7031: # permission => $permission->{'cusr'},
7032: # });
1.190 raeburn 7033: }
7034:
1.189 albertel 7035: sub restore_prev_selections {
7036: my %saveable_parameters = ('srchby' => 'scalar',
7037: 'srchin' => 'scalar',
7038: 'srchtype' => 'scalar',
7039: );
7040: &Apache::loncommon::store_settings('user','user_picker',
7041: \%saveable_parameters);
7042: &Apache::loncommon::restore_settings('user','user_picker',
7043: \%saveable_parameters);
7044: }
7045:
1.237 raeburn 7046: sub print_selfenroll_menu {
1.418 raeburn 7047: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 7048: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 7049: my $formname = 'selfenroll';
1.237 raeburn 7050: my $nolink = 1;
1.398 raeburn 7051: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 7052: my $groupslist = &Apache::lonuserutils::get_groupslist();
7053: my $setsec_js =
7054: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 7055: my %alerts = &Apache::lonlocal::texthash(
7056: acto => 'Activation of self-enrollment was selected for the following domain(s)',
7057: butn => 'but no user types have been checked.',
7058: wilf => "Please uncheck 'activate' or check at least one type.",
7059: );
1.418 raeburn 7060: my $disabled;
7061: if ($readonly) {
7062: $disabled = ' disabled="disabled"';
7063: }
1.405 damieng 7064: &js_escape(\%alerts);
1.249 raeburn 7065: my $selfenroll_js = <<"ENDSCRIPT";
7066: function update_types(caller,num) {
7067: var delidx = getIndexByName('selfenroll_delete');
7068: var actidx = getIndexByName('selfenroll_activate');
7069: if (caller == 'selfenroll_all') {
7070: var selall;
7071: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
7072: if (document.$formname.selfenroll_all[i].checked) {
7073: selall = document.$formname.selfenroll_all[i].value;
7074: }
7075: }
7076: if (selall == 1) {
7077: if (delidx != -1) {
7078: if (document.$formname.selfenroll_delete.length) {
7079: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
7080: document.$formname.selfenroll_delete[j].checked = true;
7081: }
7082: } else {
7083: document.$formname.elements[delidx].checked = true;
7084: }
7085: }
7086: if (actidx != -1) {
7087: if (document.$formname.selfenroll_activate.length) {
7088: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
7089: document.$formname.selfenroll_activate[j].checked = false;
7090: }
7091: } else {
7092: document.$formname.elements[actidx].checked = false;
7093: }
7094: }
7095: document.$formname.selfenroll_newdom.selectedIndex = 0;
7096: }
7097: }
7098: if (caller == 'selfenroll_activate') {
7099: if (document.$formname.selfenroll_activate.length) {
7100: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
7101: if (document.$formname.selfenroll_activate[j].value == num) {
7102: if (document.$formname.selfenroll_activate[j].checked) {
7103: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
7104: if (document.$formname.selfenroll_all[i].value == '1') {
7105: document.$formname.selfenroll_all[i].checked = false;
7106: }
7107: if (document.$formname.selfenroll_all[i].value == '0') {
7108: document.$formname.selfenroll_all[i].checked = true;
7109: }
7110: }
7111: }
7112: }
7113: }
7114: } else {
7115: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
7116: if (document.$formname.selfenroll_all[i].value == '1') {
7117: document.$formname.selfenroll_all[i].checked = false;
7118: }
7119: if (document.$formname.selfenroll_all[i].value == '0') {
7120: document.$formname.selfenroll_all[i].checked = true;
7121: }
7122: }
7123: }
7124: }
7125: if (caller == 'selfenroll_delete') {
7126: if (document.$formname.selfenroll_delete.length) {
7127: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
7128: if (document.$formname.selfenroll_delete[j].value == num) {
7129: if (document.$formname.selfenroll_delete[j].checked) {
7130: var delindex = getIndexByName('selfenroll_types_'+num);
7131: if (delindex != -1) {
7132: if (document.$formname.elements[delindex].length) {
7133: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
7134: document.$formname.elements[delindex][k].checked = false;
7135: }
7136: } else {
7137: document.$formname.elements[delindex].checked = false;
7138: }
7139: }
7140: }
7141: }
7142: }
7143: } else {
7144: if (document.$formname.selfenroll_delete.checked) {
7145: var delindex = getIndexByName('selfenroll_types_'+num);
7146: if (delindex != -1) {
7147: if (document.$formname.elements[delindex].length) {
7148: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
7149: document.$formname.elements[delindex][k].checked = false;
7150: }
7151: } else {
7152: document.$formname.elements[delindex].checked = false;
7153: }
7154: }
7155: }
7156: }
7157: }
7158: return;
7159: }
7160:
7161: function validate_types(form) {
7162: var needaction = new Array();
7163: var countfail = 0;
7164: var actidx = getIndexByName('selfenroll_activate');
7165: if (actidx != -1) {
7166: if (document.$formname.selfenroll_activate.length) {
7167: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
7168: var num = document.$formname.selfenroll_activate[j].value;
7169: if (document.$formname.selfenroll_activate[j].checked) {
7170: countfail = check_types(num,countfail,needaction)
7171: }
7172: }
7173: } else {
7174: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 7175: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 7176: countfail = check_types(num,countfail,needaction)
7177: }
7178: }
7179: }
7180: if (countfail > 0) {
7181: var msg = "$alerts{'acto'}\\n";
7182: var loopend = needaction.length -1;
7183: if (loopend > 0) {
7184: for (var m=0; m<loopend; m++) {
7185: msg += needaction[m]+", ";
7186: }
7187: }
7188: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
7189: alert(msg);
7190: return;
7191: }
7192: setSections(form);
7193: }
7194:
7195: function check_types(num,countfail,needaction) {
1.441 raeburn 7196: var boxname = 'selfenroll_types_'+num;
7197: var typeidx = getIndexByName(boxname);
1.249 raeburn 7198: var count = 0;
7199: if (typeidx != -1) {
1.441 raeburn 7200: if (document.$formname.elements[boxname].length) {
7201: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
7202: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 7203: count ++;
7204: }
7205: }
7206: } else {
7207: if (document.$formname.elements[typeidx].checked) {
7208: count ++;
7209: }
7210: }
7211: if (count == 0) {
7212: var domidx = getIndexByName('selfenroll_dom_'+num);
7213: if (domidx != -1) {
7214: var domname = document.$formname.elements[domidx].value;
7215: needaction[countfail] = domname;
7216: countfail ++;
7217: }
7218: }
7219: }
7220: return countfail;
7221: }
7222:
1.398 raeburn 7223: function toggleNotify() {
7224: var selfenrollApproval = 0;
7225: if (document.$formname.selfenroll_approval.length) {
7226: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
7227: if (document.$formname.selfenroll_approval[i].checked) {
7228: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
7229: break;
7230: }
7231: }
7232: }
7233: if (document.getElementById('notified')) {
7234: if (selfenrollApproval == 0) {
7235: document.getElementById('notified').style.display='none';
7236: } else {
7237: document.getElementById('notified').style.display='block';
7238: }
7239: }
7240: return;
7241: }
7242:
1.249 raeburn 7243: function getIndexByName(item) {
7244: for (var i=0;i<document.$formname.elements.length;i++) {
7245: if (document.$formname.elements[i].name == item) {
7246: return i;
7247: }
7248: }
7249: return -1;
7250: }
7251: ENDSCRIPT
1.256 raeburn 7252:
1.237 raeburn 7253: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 7254: '// <![CDATA['."\n".
1.249 raeburn 7255: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 7256: '// ]]>'."\n".
1.237 raeburn 7257: '</script>'."\n".
1.256 raeburn 7258: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.469 raeburn 7259: my $visactions = &cat_visibility($cdom);
1.400 raeburn 7260: my ($cathash,%cattype);
7261: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
7262: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7263: $cathash = $domconfig{'coursecategories'}{'cats'};
7264: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
7265: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 7266: if ($cattype{'auth'} eq '') {
7267: $cattype{'auth'} = 'std';
7268: }
7269: if ($cattype{'unauth'} eq '') {
7270: $cattype{'unauth'} = 'std';
7271: }
1.400 raeburn 7272: } else {
7273: $cathash = {};
7274: $cattype{'auth'} = 'std';
7275: $cattype{'unauth'} = 'std';
7276: }
7277: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
7278: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7279: '<br />'.
7280: '<br />'.$visactions->{'take'}.'<ul>'.
7281: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
7282: '</ul>');
7283: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
7284: if ($currsettings->{'uniquecode'}) {
7285: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
7286: } else {
7287: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7288: '<br />'.
7289: '<br />'.$visactions->{'take'}.'<ul>'.
7290: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
7291: '</ul><br />');
7292: }
7293: } else {
7294: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
7295: if (ref($visactions) eq 'HASH') {
7296: if ($visible) {
7297: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
7298: } else {
7299: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
7300: .$visactions->{'yous'}.
7301: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
7302: if (ref($vismsgs) eq 'ARRAY') {
7303: $output .= '<br />'.$visactions->{'make'}.'<ul>';
7304: foreach my $item (@{$vismsgs}) {
7305: $output .= '<li>'.$visactions->{$item}.'</li>';
7306: }
7307: $output .= '</ul>';
1.256 raeburn 7308: }
1.400 raeburn 7309: $output .= '</p>';
1.256 raeburn 7310: }
7311: }
7312: }
1.398 raeburn 7313: my $actionhref = '/adm/createuser';
7314: if ($context eq 'domain') {
7315: $actionhref = '/adm/modifycourse';
7316: }
1.400 raeburn 7317:
7318: my %noedit;
7319: unless ($context eq 'domain') {
7320: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
7321: }
1.398 raeburn 7322: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 7323: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 7324: if (ref($row) eq 'ARRAY') {
7325: foreach my $item (@{$row}) {
7326: my $title = $item;
7327: if (ref($lt) eq 'HASH') {
7328: $title = $lt->{$item};
7329: }
1.297 bisitz 7330: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 7331: if ($item eq 'types') {
1.398 raeburn 7332: my $curr_types;
7333: if (ref($currsettings) eq 'HASH') {
7334: $curr_types = $currsettings->{'selfenroll_types'};
7335: }
1.400 raeburn 7336: if ($noedit{$item}) {
7337: if ($curr_types eq '*') {
7338: $output .= &mt('Any user in any domain');
7339: } else {
7340: my @entries = split(/;/,$curr_types);
7341: if (@entries > 0) {
7342: $output .= '<ul>';
7343: foreach my $entry (@entries) {
7344: my ($currdom,$typestr) = split(/:/,$entry);
7345: next if ($typestr eq '');
7346: my $domdesc = &Apache::lonnet::domain($currdom);
7347: my @currinsttypes = split(',',$typestr);
7348: my ($othertitle,$usertypes,$types) =
7349: &Apache::loncommon::sorted_inst_types($currdom);
7350: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7351: $usertypes->{'any'} = &mt('any user');
7352: if (keys(%{$usertypes}) > 0) {
7353: $usertypes->{'other'} = &mt('other users');
7354: }
7355: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
7356: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
7357: }
7358: }
7359: $output .= '</ul>';
7360: } else {
7361: $output .= &mt('None');
7362: }
7363: }
7364: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7365: next;
7366: }
1.241 raeburn 7367: my $showdomdesc = 1;
7368: my $includeempty = 1;
7369: my $num = 0;
7370: $output .= &Apache::loncommon::start_data_table().
7371: &Apache::loncommon::start_data_table_row()
7372: .'<td colspan="2"><span class="LC_nobreak"><label>'
7373: .&mt('Any user in any domain:')
7374: .' <input type="radio" name="selfenroll_all" value="1" ';
7375: if ($curr_types eq '*') {
7376: $output .= ' checked="checked" ';
7377: }
1.249 raeburn 7378: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 7379: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 7380: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 7381: if ($curr_types ne '*') {
7382: $output .= ' checked="checked" ';
7383: }
1.249 raeburn 7384: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 7385: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 7386: &Apache::loncommon::end_data_table_row().
7387: &Apache::loncommon::end_data_table().
7388: &mt('Or').'<br />'.
7389: &Apache::loncommon::start_data_table();
1.241 raeburn 7390: my %currdoms;
1.249 raeburn 7391: if ($curr_types eq '') {
1.241 raeburn 7392: $output .= &new_selfenroll_dom_row($cdom,'0');
7393: } elsif ($curr_types ne '*') {
7394: my @entries = split(/;/,$curr_types);
7395: if (@entries > 0) {
7396: foreach my $entry (@entries) {
7397: my ($currdom,$typestr) = split(/:/,$entry);
7398: $currdoms{$currdom} = 1;
7399: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 7400: my @currinsttypes = split(',',$typestr);
1.241 raeburn 7401: $output .= &Apache::loncommon::start_data_table_row()
7402: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
7403: .' '.$domdesc.' ('.$currdom.')'
7404: .'</b><input type="hidden" name="selfenroll_dom_'.$num
7405: .'" value="'.$currdom.'" /></span><br />'
7406: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 7407: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 7408: .&mt('Delete').'</label></span></td>';
1.249 raeburn 7409: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 7410: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 7411: .&Apache::loncommon::end_data_table_row();
7412: $num ++;
7413: }
7414: }
7415: }
1.249 raeburn 7416: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 7417: if ($curr_types eq '*') {
1.249 raeburn 7418: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 7419: } elsif ($curr_types eq '') {
1.249 raeburn 7420: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 7421: }
1.446 raeburn 7422: my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$cdom);
1.241 raeburn 7423: $output .= &Apache::loncommon::start_data_table_row()
7424: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
7425: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.446 raeburn 7426: $includeempty,$showdomdesc,'',$trusted,$untrusted,$readonly)
1.241 raeburn 7427: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
7428: .'</td>'.&Apache::loncommon::end_data_table_row()
7429: .&Apache::loncommon::end_data_table();
1.237 raeburn 7430: } elsif ($item eq 'registered') {
7431: my ($regon,$regoff);
1.398 raeburn 7432: my $registered;
7433: if (ref($currsettings) eq 'HASH') {
7434: $registered = $currsettings->{'selfenroll_registered'};
7435: }
1.400 raeburn 7436: if ($noedit{$item}) {
7437: if ($registered) {
7438: $output .= &mt('Must be registered in course');
7439: } else {
7440: $output .= &mt('No requirement');
7441: }
7442: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7443: next;
7444: }
1.398 raeburn 7445: if ($registered) {
1.237 raeburn 7446: $regon = ' checked="checked" ';
1.419 raeburn 7447: $regoff = '';
1.237 raeburn 7448: } else {
1.419 raeburn 7449: $regon = '';
1.237 raeburn 7450: $regoff = ' checked="checked" ';
7451: }
7452: $output .= '<label>'.
1.419 raeburn 7453: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 7454: &mt('Yes').'</label> <label>'.
1.419 raeburn 7455: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 7456: &mt('No').'</label>';
1.237 raeburn 7457: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 7458: my ($starttime,$endtime);
7459: if (ref($currsettings) eq 'HASH') {
7460: $starttime = $currsettings->{'selfenroll_start_date'};
7461: $endtime = $currsettings->{'selfenroll_end_date'};
7462: if ($starttime eq '') {
7463: $starttime = $currsettings->{'default_enrollment_start_date'};
7464: }
7465: if ($endtime eq '') {
7466: $endtime = $currsettings->{'default_enrollment_end_date'};
7467: }
1.237 raeburn 7468: }
1.400 raeburn 7469: if ($noedit{$item}) {
7470: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
7471: &Apache::lonlocal::locallocaltime($endtime));
7472: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7473: next;
7474: }
1.237 raeburn 7475: my $startform =
7476: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 7477: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7478: my $endform =
7479: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 7480: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7481: $output .= &selfenroll_date_forms($startform,$endform);
7482: } elsif ($item eq 'access_dates') {
1.398 raeburn 7483: my ($starttime,$endtime);
7484: if (ref($currsettings) eq 'HASH') {
7485: $starttime = $currsettings->{'selfenroll_start_access'};
7486: $endtime = $currsettings->{'selfenroll_end_access'};
7487: if ($starttime eq '') {
7488: $starttime = $currsettings->{'default_enrollment_start_date'};
7489: }
7490: if ($endtime eq '') {
7491: $endtime = $currsettings->{'default_enrollment_end_date'};
7492: }
1.237 raeburn 7493: }
1.400 raeburn 7494: if ($noedit{$item}) {
7495: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
7496: &Apache::lonlocal::locallocaltime($endtime));
7497: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7498: next;
7499: }
1.237 raeburn 7500: my $startform =
7501: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 7502: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7503: my $endform =
7504: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 7505: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7506: $output .= &selfenroll_date_forms($startform,$endform);
7507: } elsif ($item eq 'section') {
1.398 raeburn 7508: my $currsec;
7509: if (ref($currsettings) eq 'HASH') {
7510: $currsec = $currsettings->{'selfenroll_section'};
7511: }
1.237 raeburn 7512: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
7513: my $newsecval;
7514: if ($currsec ne 'none' && $currsec ne '') {
7515: if (!defined($sections_count{$currsec})) {
7516: $newsecval = $currsec;
7517: }
7518: }
1.400 raeburn 7519: if ($noedit{$item}) {
7520: if ($currsec ne '') {
7521: $output .= $currsec;
7522: } else {
7523: $output .= &mt('No specific section');
7524: }
7525: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7526: next;
7527: }
1.237 raeburn 7528: my $sections_select =
1.418 raeburn 7529: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 7530: $output .= '<table class="LC_createuser">'."\n".
7531: '<tr class="LC_section_row">'."\n".
7532: '<td align="center">'.&mt('Existing sections')."\n".
7533: '<br />'.$sections_select.'</td><td align="center">'.
7534: &mt('New section').'<br />'."\n".
1.418 raeburn 7535: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 7536: '<input type="hidden" name="sections" value="" />'."\n".
7537: '</td></tr></table>'."\n";
1.276 raeburn 7538: } elsif ($item eq 'approval') {
1.398 raeburn 7539: my ($currnotified,$currapproval,%appchecked);
7540: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 7541: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 7542: $currnotified = $currsettings->{'selfenroll_notifylist'};
7543: $currapproval = $currsettings->{'selfenroll_approval'};
7544: }
7545: if ($currapproval !~ /^[012]$/) {
7546: $currapproval = 0;
7547: }
1.400 raeburn 7548: if ($noedit{$item}) {
7549: $output .= $selfdescs{'approval'}{$currapproval}.
7550: '<br />'.&mt('(Set by Domain Coordinator)');
7551: next;
7552: }
1.398 raeburn 7553: $appchecked{$currapproval} = ' checked="checked"';
7554: for my $i (0..2) {
7555: $output .= '<label>'.
7556: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 7557: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
7558: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 7559: }
7560: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
7561: my (@ccs,%notified);
1.322 raeburn 7562: my $ccrole = 'cc';
7563: if ($crstype eq 'Community') {
7564: $ccrole = 'co';
7565: }
7566: if ($advhash{$ccrole}) {
7567: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 7568: }
7569: if ($currnotified) {
7570: foreach my $current (split(/,/,$currnotified)) {
7571: $notified{$current} = 1;
7572: if (!grep(/^\Q$current\E$/,@ccs)) {
7573: push(@ccs,$current);
7574: }
7575: }
7576: }
7577: if (@ccs) {
1.398 raeburn 7578: my $style;
7579: unless ($currapproval) {
7580: $style = ' style="display: none;"';
7581: }
7582: $output .= '<br /><div id="notified"'.$style.'>'.
7583: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
7584: &Apache::loncommon::start_data_table().
1.276 raeburn 7585: &Apache::loncommon::start_data_table_row();
7586: my $count = 0;
7587: my $numcols = 4;
7588: foreach my $cc (sort(@ccs)) {
7589: my $notifyon;
7590: my ($ccuname,$ccudom) = split(/:/,$cc);
7591: if ($notified{$cc}) {
7592: $notifyon = ' checked="checked" ';
7593: }
7594: if ($count && !$count%$numcols) {
7595: $output .= &Apache::loncommon::end_data_table_row().
7596: &Apache::loncommon::start_data_table_row()
7597: }
7598: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 7599: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 7600: &Apache::loncommon::plainname($ccuname,$ccudom).
7601: '</label></span></td>';
1.343 raeburn 7602: $count ++;
1.276 raeburn 7603: }
7604: my $rem = $count%$numcols;
7605: if ($rem) {
7606: my $emptycols = $numcols - $rem;
7607: for (my $i=0; $i<$emptycols; $i++) {
7608: $output .= '<td> </td>';
7609: }
7610: }
7611: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 7612: &Apache::loncommon::end_data_table().
7613: '</div>';
1.276 raeburn 7614: }
7615: } elsif ($item eq 'limit') {
1.398 raeburn 7616: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
7617: if (ref($currsettings) eq 'HASH') {
7618: $currlim = $currsettings->{'selfenroll_limit'};
7619: $currcap = $currsettings->{'selfenroll_cap'};
7620: }
1.400 raeburn 7621: if ($noedit{$item}) {
7622: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
7623: if ($currlim eq 'allstudents') {
7624: $output .= &mt('Limit by total students');
7625: } elsif ($currlim eq 'selfenrolled') {
7626: $output .= &mt('Limit by total self-enrolled students');
7627: }
7628: $output .= ' '.&mt('Maximum: [_1]',$currcap).
7629: '<br />'.&mt('(Set by Domain Coordinator)');
7630: } else {
7631: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
7632: }
7633: next;
7634: }
1.276 raeburn 7635: if ($currlim eq 'allstudents') {
7636: $crslimit = ' checked="checked" ';
7637: $selflimit = ' ';
7638: $nolimit = ' ';
7639: } elsif ($currlim eq 'selfenrolled') {
7640: $crslimit = ' ';
7641: $selflimit = ' checked="checked" ';
7642: $nolimit = ' ';
7643: } else {
7644: $crslimit = ' ';
7645: $selflimit = ' ';
1.398 raeburn 7646: $nolimit = ' checked="checked" ';
1.276 raeburn 7647: }
7648: $output .= '<table><tr><td><label>'.
1.418 raeburn 7649: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 7650: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 7651: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 7652: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 7653: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 7654: &mt('Limit by total self-enrolled students').
7655: '</td></tr><tr>'.
7656: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
7657: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 7658: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 7659: }
7660: $output .= &Apache::lonhtmlcommon::row_closure(1);
7661: }
7662: }
1.418 raeburn 7663: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
7664: unless ($readonly) {
7665: $output .= '<input type="button" name="selfenrollconf" value="'
7666: .&mt('Save').'" onclick="validate_types(this.form);" />';
7667: }
7668: $output .= '<input type="hidden" name="action" value="selfenroll" />'
7669: .'<input type="hidden" name="state" value="done" />'."\n"
7670: .$additional.'</form>';
1.237 raeburn 7671: $r->print($output);
7672: return;
7673: }
7674:
1.400 raeburn 7675: sub get_noedit_fields {
7676: my ($cdom,$cnum,$crstype,$row) = @_;
7677: my %noedit;
7678: if (ref($row) eq 'ARRAY') {
7679: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
7680: 'internal.selfenrollmgrdc',
7681: 'internal.selfenrollmgrcc'],$cdom,$cnum);
7682: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
7683: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
7684: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
7685: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
7686: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
7687: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
7688:
7689: foreach my $item (@{$row}) {
7690: next if ($specific_managebycc{$item});
7691: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
7692: $noedit{$item} = 1;
7693: }
7694: }
7695: }
7696: return %noedit;
1.470 raeburn 7697: }
1.400 raeburn 7698:
7699: sub visible_in_stdcat {
7700: my ($cdom,$cnum,$domconf) = @_;
7701: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
7702: unless (ref($domconf) eq 'HASH') {
7703: return ($visible,$cansetvis,\@vismsgs);
7704: }
7705: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7706: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 7707: $settable{'togglecats'} = 1;
7708: }
1.400 raeburn 7709: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 7710: $settable{'categorize'} = 1;
7711: }
1.400 raeburn 7712: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7713: }
1.260 raeburn 7714: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 7715: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
7716: } elsif ($settable{'togglecats'}) {
7717: $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 7718: } elsif ($settable{'categorize'}) {
1.256 raeburn 7719: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
7720: } else {
7721: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
7722: }
7723:
7724: my %currsettings =
7725: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
7726: $cdom,$cnum);
1.400 raeburn 7727: $visible = 0;
1.256 raeburn 7728: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 7729: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7730: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7731: if (ref($cathash) eq 'HASH') {
7732: if ($cathash->{'instcode::0'} eq '') {
7733: push(@vismsgs,'dc_addinst');
7734: } else {
7735: $visible = 1;
7736: }
7737: } else {
7738: $visible = 1;
7739: }
7740: } else {
7741: $visible = 1;
7742: }
7743: } else {
7744: if (ref($cathash) eq 'HASH') {
7745: if ($cathash->{'instcode::0'} ne '') {
7746: push(@vismsgs,'dc_instcode');
7747: }
7748: } else {
7749: push(@vismsgs,'dc_instcode');
7750: }
7751: }
7752: if ($currsettings{'categories'} ne '') {
7753: my $cathash;
1.400 raeburn 7754: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7755: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7756: if (ref($cathash) eq 'HASH') {
7757: if (keys(%{$cathash}) == 0) {
7758: push(@vismsgs,'dc_catalog');
7759: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
7760: push(@vismsgs,'dc_categories');
7761: } else {
7762: my @currcategories = split('&',$currsettings{'categories'});
7763: my $matched = 0;
7764: foreach my $cat (@currcategories) {
7765: if ($cathash->{$cat} ne '') {
7766: $visible = 1;
7767: $matched = 1;
7768: last;
7769: }
7770: }
7771: if (!$matched) {
1.260 raeburn 7772: if ($settable{'categorize'}) {
1.256 raeburn 7773: push(@vismsgs,'chgcat');
7774: } else {
7775: push(@vismsgs,'dc_chgcat');
7776: }
7777: }
7778: }
7779: }
7780: }
7781: } else {
7782: if (ref($cathash) eq 'HASH') {
7783: if ((keys(%{$cathash}) > 1) ||
7784: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 7785: if ($settable{'categorize'}) {
1.256 raeburn 7786: push(@vismsgs,'addcat');
7787: } else {
7788: push(@vismsgs,'dc_addcat');
7789: }
7790: }
7791: }
7792: }
7793: if ($currsettings{'hidefromcat'} eq 'yes') {
7794: $visible = 0;
7795: if ($settable{'togglecats'}) {
7796: unshift(@vismsgs,'unhide');
7797: } else {
7798: unshift(@vismsgs,'dc_unhide')
7799: }
7800: }
1.400 raeburn 7801: return ($visible,$cansetvis,\@vismsgs);
7802: }
7803:
7804: sub cat_visibility {
1.469 raeburn 7805: my ($cdom) = @_;
1.400 raeburn 7806: my %visactions = &Apache::lonlocal::texthash(
7807: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
7808: 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.',
7809: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
7810: none => 'Display of a course catalog is disabled for this domain.',
7811: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
7812: 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.',
7813: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
7814: take => 'Take the following action to ensure the course appears in the Catalog:',
7815: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
7816: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
7817: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
1.469 raeburn 7818: dc_addinst => 'Ask a domain coordinator to enable catalog display of "Official courses (with institutional codes)".',
1.400 raeburn 7819: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
7820: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
7821: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
7822: 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',
7823: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
7824: );
1.469 raeburn 7825: if ($env{'request.role'} eq "dc./$cdom/") {
7826: $visactions{'dc_chgconf'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the Catalog type for this domain.','»');
7827: $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.','»');
7828: $visactions{'dc_unhide'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the "Exclude from course catalog" setting.','»');
7829: $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)".','»');
7830: $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).','»');
7831: $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.','»');
7832: $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.','»');
7833: $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.','»');
7834: $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.','»');
7835: }
1.400 raeburn 7836: $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>"');
7837: $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>"');
7838: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
7839: return \%visactions;
1.256 raeburn 7840: }
7841:
1.241 raeburn 7842: sub new_selfenroll_dom_row {
7843: my ($newdom,$num) = @_;
7844: my $domdesc = &Apache::lonnet::domain($newdom);
7845: my $output;
7846: if ($domdesc ne '') {
7847: $output .= &Apache::loncommon::start_data_table_row()
7848: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
7849: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 7850: .'" value="'.$newdom.'" /></span><br />'
7851: .'<span class="LC_nobreak"><label><input type="checkbox" '
7852: .'name="selfenroll_activate" value="'.$num.'" '
7853: .'onchange="javascript:update_types('
7854: ."'selfenroll_activate','$num'".');" />'
7855: .&mt('Activate').'</label></span></td>';
1.241 raeburn 7856: my @currinsttypes;
7857: $output .= '<td>'.&mt('User types:').'<br />'
7858: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
7859: .&Apache::loncommon::end_data_table_row();
7860: }
7861: return $output;
7862: }
7863:
7864: sub selfenroll_inst_types {
1.418 raeburn 7865: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 7866: my $output;
7867: my $numinrow = 4;
7868: my $count = 0;
7869: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 7870: my $othervalue = 'any';
1.418 raeburn 7871: my $disabled;
7872: if ($readonly) {
7873: $disabled = ' disabled="disabled"';
7874: }
1.241 raeburn 7875: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 7876: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 7877: $othervalue = 'other';
7878: }
1.241 raeburn 7879: $output .= '<table><tr>';
7880: foreach my $type (@{$types}) {
7881: if (($count > 0) && ($count%$numinrow == 0)) {
7882: $output .= '</tr><tr>';
7883: }
7884: if (defined($usertypes->{$type})) {
1.257 raeburn 7885: my $esc_type = &escape($type);
1.241 raeburn 7886: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 7887: $esc_type.'" ';
1.241 raeburn 7888: if (ref($currinsttypes) eq 'ARRAY') {
7889: if (@{$currinsttypes} > 0) {
1.249 raeburn 7890: if (grep(/^any$/,@{$currinsttypes})) {
7891: $output .= 'checked="checked"';
1.257 raeburn 7892: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 7893: $output .= 'checked="checked"';
7894: }
1.249 raeburn 7895: } else {
7896: $output .= 'checked="checked"';
1.241 raeburn 7897: }
7898: }
1.418 raeburn 7899: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 7900: }
7901: $count ++;
7902: }
7903: if (($count > 0) && ($count%$numinrow == 0)) {
7904: $output .= '</tr><tr>';
7905: }
1.249 raeburn 7906: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 7907: if (ref($currinsttypes) eq 'ARRAY') {
7908: if (@{$currinsttypes} > 0) {
1.249 raeburn 7909: if (grep(/^any$/,@{$currinsttypes})) {
7910: $output .= ' checked="checked"';
7911: } elsif ($othervalue eq 'other') {
7912: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
7913: $output .= ' checked="checked"';
7914: }
1.241 raeburn 7915: }
1.249 raeburn 7916: } else {
7917: $output .= ' checked="checked"';
1.241 raeburn 7918: }
1.249 raeburn 7919: } else {
7920: $output .= ' checked="checked"';
1.241 raeburn 7921: }
1.418 raeburn 7922: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 7923: }
7924: return $output;
7925: }
7926:
1.237 raeburn 7927: sub selfenroll_date_forms {
7928: my ($startform,$endform) = @_;
7929: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 7930: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 7931: 'LC_oddrow_value')."\n".
7932: $startform."\n".
7933: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 7934: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 7935: 'LC_oddrow_value')."\n".
7936: $endform."\n".
7937: &Apache::lonhtmlcommon::row_closure(1).
7938: &Apache::lonhtmlcommon::end_pick_box();
7939: return $output;
7940: }
7941:
1.239 raeburn 7942: sub print_userchangelogs_display {
1.415 raeburn 7943: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 7944: my $formname = 'rolelog';
1.418 raeburn 7945: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 7946: if ($context eq 'domain') {
7947: $domain = $env{'request.role.domain'};
7948: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
7949: } else {
7950: if ($context eq 'course') {
7951: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
7952: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
7953: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 7954: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 7955: my %saveable_parameters = ('show' => 'scalar',);
7956: &Apache::loncommon::store_course_settings('roles_log',
7957: \%saveable_parameters);
7958: &Apache::loncommon::restore_course_settings('roles_log',
7959: \%saveable_parameters);
7960: } elsif ($context eq 'author') {
1.470 raeburn 7961: $domain = $env{'user.domain'};
1.363 raeburn 7962: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
7963: $username = $env{'user.name'};
1.470 raeburn 7964: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
7965: ($domain,$username) = ($1,$2);
1.363 raeburn 7966: } else {
7967: undef($domain);
7968: }
7969: }
7970: if ($domain ne '' && $username ne '') {
7971: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
7972: }
7973: }
1.239 raeburn 7974: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
7975:
1.415 raeburn 7976: my $helpitem;
7977: if ($context eq 'course') {
7978: $helpitem = 'Course_User_Logs';
1.439 raeburn 7979: } elsif ($context eq 'domain') {
7980: $helpitem = 'Domain_Role_Logs';
7981: } elsif ($context eq 'author') {
7982: $helpitem = 'Author_User_Logs';
1.415 raeburn 7983: }
7984: push (@{$brcrum},
7985: {href => '/adm/createuser?action=changelogs',
7986: text => 'User Management Logs',
7987: help => $helpitem});
7988: my $bread_crumbs_component = 'User Changes';
7989: my $args = { bread_crumbs => $brcrum,
7990: bread_crumbs_component => $bread_crumbs_component};
7991:
7992: # Create navigation javascript
7993: my $jsnav = &userlogdisplay_js($formname);
7994:
7995: my $jscript = (<<ENDSCRIPT);
7996: <script type="text/javascript">
7997: // <![CDATA[
7998: $jsnav
7999: // ]]>
8000: </script>
8001: ENDSCRIPT
8002:
8003: # print page header
8004: $r->print(&header($jscript,$args));
8005:
1.239 raeburn 8006: # set defaults
8007: my $now = time();
8008: my $defstart = $now - (7*24*3600); #7 days ago
8009: my %defaults = (
8010: page => '1',
8011: show => '10',
8012: role => 'any',
8013: chgcontext => 'any',
8014: rolelog_start_date => $defstart,
8015: rolelog_end_date => $now,
1.468 raeburn 8016: approvals => 'any',
1.239 raeburn 8017: );
8018: my $more_records = 0;
8019:
8020: # set current
8021: my %curr;
1.468 raeburn 8022: foreach my $item ('show','page','role','chgcontext','approvals') {
1.239 raeburn 8023: $curr{$item} = $env{'form.'.$item};
8024: }
8025: my ($startdate,$enddate) =
8026: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
8027: $curr{'rolelog_start_date'} = $startdate;
8028: $curr{'rolelog_end_date'} = $enddate;
8029: foreach my $key (keys(%defaults)) {
8030: if ($curr{$key} eq '') {
8031: $curr{$key} = $defaults{$key};
8032: }
8033: }
1.248 raeburn 8034: my (%whodunit,%changed,$version);
8035: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 8036: my ($minshown,$maxshown);
1.255 raeburn 8037: $minshown = 1;
1.239 raeburn 8038: my $count = 0;
1.415 raeburn 8039: if ($curr{'show'} =~ /\D/) {
8040: $curr{'page'} = 1;
8041: } else {
1.239 raeburn 8042: $maxshown = $curr{'page'} * $curr{'show'};
8043: if ($curr{'page'} > 1) {
8044: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
8045: }
8046: }
1.301 bisitz 8047:
1.327 raeburn 8048: # Form Header
8049: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 8050: &role_display_filter($context,$formname,$domain,$username,\%curr,
8051: $version,$crstype));
1.327 raeburn 8052:
8053: my $showntableheader = 0;
8054:
8055: # Table Header
8056: my $tableheader =
8057: &Apache::loncommon::start_data_table_header_row()
8058: .'<th> </th>'
8059: .'<th>'.&mt('When').'</th>'
8060: .'<th>'.&mt('Who made the change').'</th>'
8061: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 8062: .'<th>'.&mt('Role').'</th>';
8063:
8064: if ($context eq 'course') {
8065: $tableheader .= '<th>'.&mt('Section').'</th>';
8066: }
8067: $tableheader .=
8068: '<th>'.&mt('Context').'</th>'
1.327 raeburn 8069: .'<th>'.&mt('Start').'</th>'
8070: .'<th>'.&mt('End').'</th>'
8071: .&Apache::loncommon::end_data_table_header_row();
8072:
8073: # Display user change log data
1.239 raeburn 8074: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
8075: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
8076: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 8077: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 8078: if ($count >= $curr{'page'} * $curr{'show'}) {
8079: $more_records = 1;
8080: last;
8081: }
8082: }
8083: if ($curr{'role'} ne 'any') {
8084: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
8085: }
8086: if ($curr{'chgcontext'} ne 'any') {
8087: if ($curr{'chgcontext'} eq 'selfenroll') {
8088: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
8089: } else {
8090: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
8091: }
8092: }
1.418 raeburn 8093: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 8094: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 8095: }
1.468 raeburn 8096: if ($curr{'approvals'} eq 'none') {
8097: next if ($roleslog{$id}{'logentry'}{'approval'});
8098: } elsif ($curr{'approvals'} ne 'any') {
8099: next if ($roleslog{$id}{'logentry'}{'approval'} ne $curr{'approvals'});
8100: }
1.239 raeburn 8101: $count ++;
8102: next if ($count < $minshown);
1.327 raeburn 8103: unless ($showntableheader) {
1.415 raeburn 8104: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 8105: .$tableheader);
8106: $r->rflush();
8107: $showntableheader = 1;
8108: }
1.239 raeburn 8109: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
8110: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
8111: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
8112: }
8113: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
8114: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
8115: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
8116: }
8117: my $sec = $roleslog{$id}{'logentry'}{'section'};
8118: if ($sec eq '') {
8119: $sec = &mt('None');
8120: }
8121: my ($rolestart,$roleend);
8122: if ($roleslog{$id}{'delflag'}) {
8123: $rolestart = &mt('deleted');
8124: $roleend = &mt('deleted');
8125: } else {
8126: $rolestart = $roleslog{$id}{'logentry'}{'start'};
8127: $roleend = $roleslog{$id}{'logentry'}{'end'};
8128: if ($rolestart eq '' || $rolestart == 0) {
8129: $rolestart = &mt('No start date');
8130: } else {
8131: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
8132: }
8133: if ($roleend eq '' || $roleend == 0) {
8134: $roleend = &mt('No end date');
8135: } else {
8136: $roleend = &Apache::lonlocal::locallocaltime($roleend);
8137: }
8138: }
8139: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
8140: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
8141: $chgcontext = 'selfenroll';
8142: }
1.363 raeburn 8143: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 8144: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
8145: $chgcontext = $lt{$chgcontext};
8146: }
1.468 raeburn 8147: my ($showreqby,%reqby);
8148: if (($roleslog{$id}{'logentry'}{'approval'}) &&
8149: ($roleslog{$id}{'logentry'}{'requester'})) {
8150: if ($reqby{$roleslog{$id}{'logentry'}{'requester'}} eq '') {
8151: my ($requname,$requdom) = split(/:/,$roleslog{$id}{'logentry'}{'requester'});
8152: $reqby{$roleslog{$id}{'logentry'}{'requester'}} =
8153: &Apache::loncommon::plainname($requname,$requdom);
8154: }
8155: $showreqby = &mt('Requester').': <span class="LC_nobreak">'.$reqby{$roleslog{$id}{'logentry'}{'requester'}}.'</span><br />';
8156: if ($roleslog{$id}{'logentry'}{'approval'} eq 'domain') {
8157: $showreqby .= &mt('Adjudicator').': <span class="LC_nobreak">'.
8158: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.
8159: '</span>';
8160: } else {
8161: $showreqby .= '<span class="LC_nobreak">'.&mt('User approved').'</span>';
8162: }
8163: } else {
8164: $showreqby = $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}};
8165: }
1.327 raeburn 8166: $r->print(
1.301 bisitz 8167: &Apache::loncommon::start_data_table_row()
8168: .'<td>'.$count.'</td>'
8169: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
1.468 raeburn 8170: .'<td>'.$showreqby.'</td>'
1.301 bisitz 8171: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 8172: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
8173: if ($context eq 'course') {
8174: $r->print('<td>'.$sec.'</td>');
8175: }
8176: $r->print(
8177: '<td>'.$chgcontext.'</td>'
1.301 bisitz 8178: .'<td>'.$rolestart.'</td>'
8179: .'<td>'.$roleend.'</td>'
1.327 raeburn 8180: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 8181: }
8182:
1.327 raeburn 8183: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 8184: $r->print(&Apache::loncommon::end_data_table().
8185: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 8186: } else { # No content displayed above
1.301 bisitz 8187: $r->print('<p class="LC_info">'
8188: .&mt('There are no records to display.')
8189: .'</p>'
8190: );
1.239 raeburn 8191: }
1.301 bisitz 8192:
1.327 raeburn 8193: # Form Footer
8194: $r->print(
8195: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
8196: .'<input type="hidden" name="action" value="changelogs" />'
8197: .'</form>');
8198: return;
8199: }
1.301 bisitz 8200:
1.416 raeburn 8201: sub print_useraccesslogs_display {
8202: my ($r,$uname,$udom,$permission,$brcrum) = @_;
8203: my $formname = 'accesslog';
8204: my $form = 'document.accesslog';
8205:
8206: # set breadcrumbs
1.422 raeburn 8207: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 8208: my $prevphasestr;
8209: if ($env{'form.popup'}) {
8210: $brcrum = [];
8211: } else {
8212: push (@{$brcrum},
8213: {href => "javascript:backPage($form)",
8214: text => $breadcrumb_text{'search'}});
8215: my @prevphases;
8216: if ($env{'form.prevphases'}) {
8217: @prevphases = split(/,/,$env{'form.prevphases'});
8218: $prevphasestr = $env{'form.prevphases'};
8219: }
8220: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
8221: push(@{$brcrum},
8222: {href => "javascript:backPage($form,'get_user_info','select')",
8223: text => $breadcrumb_text{'userpicked'}});
8224: if ($env{'form.phase'} eq 'userpicked') {
8225: $prevphasestr = 'userpicked';
8226: }
1.416 raeburn 8227: }
8228: }
8229: push(@{$brcrum},
8230: {href => '/adm/createuser?action=accesslogs',
8231: text => 'User access logs',
1.424 raeburn 8232: help => 'Domain_User_Access_Logs'});
1.416 raeburn 8233: my $bread_crumbs_component = 'User Access Logs';
8234: my $args = { bread_crumbs => $brcrum,
8235: bread_crumbs_component => 'User Management'};
1.423 raeburn 8236: if ($env{'form.popup'}) {
8237: $args->{'no_nav_bar'} = 1;
1.431 raeburn 8238: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 8239: }
1.416 raeburn 8240:
1.417 raeburn 8241: # set javascript
1.416 raeburn 8242: my ($jsback,$elements) = &crumb_utilities();
8243: my $jsnav = &userlogdisplay_js($formname);
8244:
8245: my $jscript = (<<ENDSCRIPT);
8246: <script type="text/javascript">
8247: // <![CDATA[
8248:
8249: $jsback
8250: $jsnav
8251:
8252: // ]]>
8253: </script>
8254:
8255: ENDSCRIPT
8256:
1.417 raeburn 8257: # print page header
1.416 raeburn 8258: $r->print(&header($jscript,$args));
8259:
8260: # early out unless log data can be displayed.
8261: unless ($permission->{'activity'}) {
8262: $r->print('<p class="LC_warning">'
8263: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 8264: .'</p>');
8265: if ($env{'form.popup'}) {
8266: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
8267: } else {
8268: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8269: }
1.416 raeburn 8270: return;
8271: }
8272:
8273: unless ($udom eq $env{'request.role.domain'}) {
8274: $r->print('<p class="LC_warning">'
8275: .&mt("User's domain must match role's domain")
8276: .'</p>'
8277: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 8278: return;
1.416 raeburn 8279: }
8280:
8281: if (($uname eq '') || ($udom eq '')) {
8282: $r->print('<p class="LC_warning">'
8283: .&mt('Invalid username or domain')
8284: .'</p>'
8285: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8286: return;
8287: }
8288:
1.437 raeburn 8289: if (&Apache::lonnet::privileged($uname,$udom,
8290: [$env{'request.role.domain'}],['dc','su'])) {
8291: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
8292: [$env{'request.role.domain'}],['dc','su'])) {
8293: $r->print('<p class="LC_warning">'
8294: .&mt('You need to be a privileged user to display user access logs for [_1]',
8295: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
8296: $uname,$udom))
8297: .'</p>');
8298: if ($env{'form.popup'}) {
8299: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
8300: } else {
8301: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8302: }
8303: return;
8304: }
8305: }
8306:
1.416 raeburn 8307: # set defaults
8308: my $now = time();
8309: my $defstart = $now - (7*24*3600);
8310: my %defaults = (
8311: page => '1',
8312: show => '10',
8313: activity => 'any',
8314: accesslog_start_date => $defstart,
8315: accesslog_end_date => $now,
8316: );
8317: my $more_records = 0;
8318:
8319: # set current
8320: my %curr;
8321: foreach my $item ('show','page','activity') {
8322: $curr{$item} = $env{'form.'.$item};
8323: }
8324: my ($startdate,$enddate) =
8325: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
8326: $curr{'accesslog_start_date'} = $startdate;
8327: $curr{'accesslog_end_date'} = $enddate;
8328: foreach my $key (keys(%defaults)) {
8329: if ($curr{$key} eq '') {
8330: $curr{$key} = $defaults{$key};
8331: }
8332: }
8333: my ($minshown,$maxshown);
8334: $minshown = 1;
8335: my $count = 0;
8336: if ($curr{'show'} =~ /\D/) {
8337: $curr{'page'} = 1;
8338: } else {
8339: $maxshown = $curr{'page'} * $curr{'show'};
8340: if ($curr{'page'} > 1) {
8341: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
8342: }
8343: }
8344:
8345: # form header
8346: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
8347: &activity_display_filter($formname,\%curr));
8348:
8349: my $showntableheader = 0;
8350: my ($nav_script,$nav_links);
8351:
8352: # table header
1.453 raeburn 8353: my $heading = '<h3>'.
1.431 raeburn 8354: &mt('User access logs for: [_1]',
1.453 raeburn 8355: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
8356: my $tableheader = $heading
1.431 raeburn 8357: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 8358: .'<th> </th>'
8359: .'<th>'.&mt('When').'</th>'
8360: .'<th>'.&mt('HostID').'</th>'
8361: .'<th>'.&mt('Event').'</th>'
8362: .'<th>'.&mt('Other data').'</th>'
8363: .&Apache::loncommon::end_data_table_header_row();
8364:
8365: my %filters=(
8366: start => $curr{'accesslog_start_date'},
8367: end => $curr{'accesslog_end_date'},
8368: action => $curr{'activity'},
8369: );
8370:
8371: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
8372: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
8373: my (%courses,%missing);
8374: my @results = split(/\&/,$reply);
8375: foreach my $item (reverse(@results)) {
8376: my ($timestamp,$host,$event) = split(/:/,$item);
8377: next unless ($event =~ /^(Log|Role)/);
8378: if ($curr{'show'} !~ /\D/) {
8379: if ($count >= $curr{'page'} * $curr{'show'}) {
8380: $more_records = 1;
8381: last;
8382: }
8383: }
8384: $count ++;
8385: next if ($count < $minshown);
8386: unless ($showntableheader) {
8387: $r->print($nav_script
8388: .&Apache::loncommon::start_data_table()
8389: .$tableheader);
8390: $r->rflush();
8391: $showntableheader = 1;
8392: }
1.418 raeburn 8393: my ($shown,$extra);
1.437 raeburn 8394: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 8395: if ($event eq 'Role') {
8396: my ($rolecode,$extent) = split(/\./,$data,2);
8397: next if ($extent eq '');
8398: my ($crstype,$desc,$info);
1.418 raeburn 8399: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
8400: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 8401: my $cid = $cdom.'_'.$cnum;
8402: if (exists($courses{$cid})) {
8403: $crstype = $courses{$cid}{'type'};
8404: $desc = $courses{$cid}{'description'};
8405: } elsif ($missing{$cid}) {
8406: $crstype = 'Course';
8407: $desc = 'Course/Community';
8408: } else {
8409: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
8410: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
8411: $courses{$cid} = $crsinfo{$cid};
8412: $crstype = $crsinfo{$cid}{'type'};
8413: $desc = $crsinfo{$cid}{'description'};
8414: } else {
8415: $missing{$cid} = 1;
8416: }
8417: }
8418: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 8419: if ($sec ne '') {
8420: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
8421: }
1.416 raeburn 8422: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
8423: my ($dom,$name) = ($1,$2);
8424: if ($rolecode eq 'au') {
8425: $extra = '';
8426: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 8427: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 8428: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
8429: $extra = &mt('Domain: [_1]',$dom);
8430: }
8431: }
8432: my $rolename;
8433: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
8434: my $role = $3;
1.417 raeburn 8435: my $owner = "($2:$1)";
1.416 raeburn 8436: if ($2 eq $1.'-domainconfig') {
8437: $owner = '(ad hoc)';
1.417 raeburn 8438: }
1.416 raeburn 8439: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
8440: } else {
8441: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
8442: }
8443: $shown = &mt('Role selection: [_1]',$rolename);
8444: } else {
8445: $shown = &mt($event);
1.437 raeburn 8446: if ($data =~ /^webdav/) {
8447: my ($path,$clientip) = split(/\s+/,$data,2);
8448: $path =~ s/^webdav//;
8449: if ($clientip ne '') {
8450: $extra = &mt('Client IP address: [_1]',$clientip);
8451: }
8452: if ($path ne '') {
8453: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
8454: }
8455: } elsif ($data ne '') {
8456: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 8457: }
8458: }
8459: $r->print(
8460: &Apache::loncommon::start_data_table_row()
8461: .'<td>'.$count.'</td>'
8462: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
8463: .'<td>'.$host.'</td>'
8464: .'<td>'.$shown.'</td>'
8465: .'<td>'.$extra.'</td>'
8466: .&Apache::loncommon::end_data_table_row()."\n");
8467: }
8468: }
8469:
8470: if ($showntableheader) { # Table footer, if content displayed above
8471: $r->print(&Apache::loncommon::end_data_table().
8472: &userlogdisplay_navlinks(\%curr,$more_records));
8473: } else { # No content displayed above
1.453 raeburn 8474: $r->print($heading.'<p class="LC_info">'
1.416 raeburn 8475: .&mt('There are no records to display.')
8476: .'</p>');
8477: }
8478:
1.423 raeburn 8479: if ($env{'form.popup'} == 1) {
8480: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
8481: }
8482:
1.416 raeburn 8483: # Form Footer
8484: $r->print(
8485: '<input type="hidden" name="currstate" value="" />'
8486: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
8487: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
8488: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
8489: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
8490: .'<input type="hidden" name="phase" value="activity" />'
8491: .'<input type="hidden" name="action" value="accesslogs" />'
8492: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
8493: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
8494: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
8495: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
8496: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
8497: .'</form>');
8498: return;
8499: }
8500:
8501: sub earlyout_accesslog_form {
8502: my ($formname,$prevphasestr,$udom) = @_;
8503: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
8504: return <<"END";
8505: <form action="/adm/createuser" method="post" name="$formname">
8506: <input type="hidden" name="currstate" value="" />
8507: <input type="hidden" name="prevphases" value="$prevphasestr" />
8508: <input type="hidden" name="phase" value="activity" />
8509: <input type="hidden" name="action" value="accesslogs" />
8510: <input type="hidden" name="srchdomain" value="$udom" />
8511: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
8512: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
8513: <input type="hidden" name="srchterm" value="$srchterm" />
8514: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
8515: </form>
8516: END
8517: }
8518:
8519: sub activity_display_filter {
8520: my ($formname,$curr) = @_;
8521: my $nolink = 1;
8522: my $output = '<table><tr><td valign="top">'.
8523: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
1.467 raeburn 8524: &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef,
1.416 raeburn 8525: (&mt('all'),5,10,20,50,100,1000,10000)).
8526: '</td><td> </td>';
8527: my $startform =
8528: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
8529: $curr->{'accesslog_start_date'},undef,
8530: undef,undef,undef,undef,undef,undef,$nolink);
8531: my $endform =
8532: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
8533: $curr->{'accesslog_end_date'},undef,
8534: undef,undef,undef,undef,undef,undef,$nolink);
8535: my %lt = &Apache::lonlocal::texthash (
8536: activity => 'Activity',
8537: Role => 'Role selection',
8538: log => 'Log-in or Logout',
8539: );
8540: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
8541: '<table><tr><td>'.&mt('After:').
8542: '</td><td>'.$startform.'</td></tr>'.
8543: '<tr><td>'.&mt('Before:').'</td>'.
8544: '<td>'.$endform.'</td></tr></table>'.
8545: '</td>'.
8546: '<td> </td>'.
8547: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
8548: '<select name="activity"><option value="any"';
8549: if ($curr->{'activity'} eq 'any') {
8550: $output .= ' selected="selected"';
8551: }
8552: $output .= '>'.&mt('Any').'</option>'."\n";
8553: foreach my $activity ('Role','log') {
8554: my $selstr = '';
8555: if ($activity eq $curr->{'activity'}) {
8556: $selstr = ' selected="selected"';
8557: }
8558: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
8559: }
8560: $output .= '</select></td>'.
8561: '</tr></table>';
8562: # Update Display button
8563: $output .= '<p>'
8564: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 8565: .'</p><hr />';
1.416 raeburn 8566: return $output;
8567: }
8568:
1.415 raeburn 8569: sub userlogdisplay_js {
8570: my ($formname) = @_;
8571: return <<"ENDSCRIPT";
8572:
1.239 raeburn 8573: function chgPage(caller) {
8574: if (caller == 'previous') {
8575: document.$formname.page.value --;
8576: }
8577: if (caller == 'next') {
8578: document.$formname.page.value ++;
8579: }
1.327 raeburn 8580: document.$formname.submit();
1.239 raeburn 8581: return;
8582: }
8583: ENDSCRIPT
1.415 raeburn 8584: }
8585:
8586: sub userlogdisplay_navlinks {
8587: my ($curr,$more_records) = @_;
8588: return unless(ref($curr) eq 'HASH');
8589: # Navigation Buttons
8590: my $nav_links = '<p>';
8591: if (($curr->{'page'} > 1) || ($more_records)) {
8592: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
8593: $nav_links .= '<input type="button"'
8594: .' onclick="javascript:chgPage('."'previous'".');"'
8595: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
8596: .'" /> ';
8597: }
8598: if ($more_records) {
8599: $nav_links .= '<input type="button"'
8600: .' onclick="javascript:chgPage('."'next'".');"'
8601: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
8602: .'" />';
1.301 bisitz 8603: }
8604: }
1.415 raeburn 8605: $nav_links .= '</p>';
8606: return $nav_links;
1.239 raeburn 8607: }
8608:
8609: sub role_display_filter {
1.363 raeburn 8610: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
1.239 raeburn 8611: my $nolink = 1;
8612: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 8613: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.467 raeburn 8614: &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef,
1.239 raeburn 8615: (&mt('all'),5,10,20,50,100,1000,10000)).
8616: '</td><td> </td>';
8617: my $startform =
8618: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
8619: $curr->{'rolelog_start_date'},undef,
8620: undef,undef,undef,undef,undef,undef,$nolink);
8621: my $endform =
8622: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
8623: $curr->{'rolelog_end_date'},undef,
8624: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 8625: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 8626: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
8627: '<table><tr><td>'.&mt('After:').
8628: '</td><td>'.$startform.'</td></tr>'.
8629: '<tr><td>'.&mt('Before:').'</td>'.
8630: '<td>'.$endform.'</td></tr></table>'.
8631: '</td>'.
8632: '<td> </td>'.
1.239 raeburn 8633: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
8634: '<select name="role"><option value="any"';
8635: if ($curr->{'role'} eq 'any') {
8636: $output .= ' selected="selected"';
8637: }
1.466 raeburn 8638: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 8639: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 8640: foreach my $role (@roles) {
8641: my $plrole;
8642: if ($role eq 'cr') {
8643: $plrole = &mt('Custom Role');
8644: } else {
1.318 raeburn 8645: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 8646: }
8647: my $selstr = '';
8648: if ($role eq $curr->{'role'}) {
8649: $selstr = ' selected="selected"';
8650: }
8651: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
8652: }
1.301 bisitz 8653: $output .= '</select></td>'.
8654: '<td> </td>'.
8655: '<td valign="top"><b>'.
1.239 raeburn 8656: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 8657: my @posscontexts;
8658: if ($context eq 'course') {
1.468 raeburn 8659: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype','ltienroll');
1.363 raeburn 8660: } elsif ($context eq 'domain') {
8661: @posscontexts = ('any','domain','requestauthor','domconfig','server');
8662: } else {
1.470 raeburn 8663: @posscontexts = ('any','author','coauthor','domain');
1.457 raeburn 8664: }
1.363 raeburn 8665: foreach my $chgtype (@posscontexts) {
1.239 raeburn 8666: my $selstr = '';
8667: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 8668: $selstr = ' selected="selected"';
1.239 raeburn 8669: }
1.363 raeburn 8670: if ($context eq 'course') {
1.376 raeburn 8671: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 8672: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
8673: }
1.239 raeburn 8674: }
8675: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 8676: }
1.468 raeburn 8677: my @possapprovals = ('any','none','domain','user');
8678: my %apptxt = &approval_types();
8679: $output .= '</select></td>'.
8680: '<td> </td>'.
8681: '<td valign="top"><b>'.
8682: &mt('Approvals:').'</b><br /><select name="approvals">';
8683: foreach my $approval (@possapprovals) {
8684: my $selstr = '';
8685: if ($curr->{'approvals'} eq $approval) {
8686: $selstr = ' selected="selected"';
8687: }
8688: $output .= '<option value="'.$approval.'"'.$selstr.'>'.$apptxt{$approval}.'</option>';
8689: }
8690: $output .= '</select></td></tr></table>';
1.303 bisitz 8691:
8692: # Update Display button
8693: $output .= '<p>'
8694: .'<input type="submit" value="'.&mt('Update Display').'" />'
8695: .'</p>';
8696:
8697: # Server version info
1.363 raeburn 8698: my $needsrev = '2.11.0';
8699: if ($context eq 'course') {
8700: $needsrev = '2.7.0';
8701: }
8702:
1.303 bisitz 8703: $output .= '<p class="LC_info">'
8704: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 8705: ,$needsrev);
1.248 raeburn 8706: if ($version) {
1.303 bisitz 8707: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
8708: }
8709: $output .= '</p><hr />';
1.239 raeburn 8710: return $output;
8711: }
8712:
8713: sub rolechg_contexts {
1.363 raeburn 8714: my ($context,$crstype) = @_;
8715: my %lt;
8716: if ($context eq 'course') {
8717: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 8718: any => 'Any',
1.376 raeburn 8719: automated => 'Automated Enrollment',
1.457 raeburn 8720: chgtype => 'Enrollment Type/Lock Change',
1.239 raeburn 8721: updatenow => 'Roster Update',
8722: createcourse => 'Course Creation',
8723: course => 'User Management in course',
8724: domain => 'User Management in domain',
1.313 raeburn 8725: selfenroll => 'Self-enrolled',
1.318 raeburn 8726: requestcourses => 'Course Request',
1.468 raeburn 8727: ltienroll => 'Enrollment via LTI',
1.239 raeburn 8728: );
1.363 raeburn 8729: if ($crstype eq 'Community') {
8730: $lt{'createcourse'} = &mt('Community Creation');
8731: $lt{'course'} = &mt('User Management in community');
8732: $lt{'requestcourses'} = &mt('Community Request');
8733: }
8734: } elsif ($context eq 'domain') {
8735: %lt = &Apache::lonlocal::texthash (
8736: any => 'Any',
8737: domain => 'User Management in domain',
8738: requestauthor => 'Authoring Request',
8739: server => 'Command line script (DC role)',
8740: domconfig => 'Self-enrolled',
8741: );
8742: } else {
8743: %lt = &Apache::lonlocal::texthash (
8744: any => 'Any',
8745: domain => 'User Management in domain',
8746: author => 'User Management by author',
1.470 raeburn 8747: coauthor => 'User Management by coauthor',
1.363 raeburn 8748: );
8749: }
1.239 raeburn 8750: return %lt;
8751: }
8752:
1.468 raeburn 8753: sub approval_types {
8754: return &Apache::lonlocal::texthash (
8755: any => 'Any',
8756: none => 'No approval needed',
8757: user => 'Role recipient approval',
8758: domain => 'Domain coordinator approval',
8759: );
8760: }
8761:
1.428 raeburn 8762: sub print_helpdeskaccess_display {
8763: my ($r,$permission,$brcrum) = @_;
8764: my $formname = 'helpdeskaccess';
8765: my $helpitem = 'Course_Helpdesk_Access';
8766: push (@{$brcrum},
8767: {href => '/adm/createuser?action=helpdesk',
8768: text => 'Helpdesk Access',
8769: help => $helpitem});
8770: my $bread_crumbs_component = 'Helpdesk Staff Access';
8771: my $args = { bread_crumbs => $brcrum,
8772: bread_crumbs_component => $bread_crumbs_component};
8773:
8774: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8775: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8776: my $confname = $cdom.'-domainconfig';
8777: my $crstype = &Apache::loncommon::course_type();
8778:
1.434 raeburn 8779: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 8780: my ($numstatustypes,@jsarray);
8781: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8782: if (ref($types) eq 'ARRAY') {
1.430 raeburn 8783: if (@{$types} > 0) {
1.428 raeburn 8784: $numstatustypes = scalar(@{$types});
8785: push(@accesstypes,'status');
8786: @jsarray = ('bystatus');
8787: }
8788: }
8789: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 8790: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8791: if (keys(%domhelpdesk)) {
8792: push(@accesstypes,('inc','exc'));
8793: push(@jsarray,('notinc','notexc'));
8794: }
8795: push(@jsarray,'privs');
8796: my $hiddenstr = join("','",@jsarray);
8797: my $rolestr = join("','",sort(keys(%customroles)));
8798:
8799: my $jscript;
8800: my (%settings,%overridden);
8801: if (keys(%customroles)) {
8802: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8803: $types,\%customroles,\%settings,\%overridden);
8804: my %jsfull=();
8805: my %jslevels= (
8806: course => {},
8807: domain => {},
8808: system => {},
8809: );
8810: my %jslevelscurrent=(
8811: course => {},
8812: domain => {},
8813: system => {},
8814: );
8815: my (%privs,%jsprivs);
8816: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
8817: foreach my $priv (keys(%jsfull)) {
8818: if ($jslevels{'course'}{$priv}) {
8819: $jsprivs{$priv} = 1;
8820: }
8821: }
8822: my (%elements,%stored);
8823: foreach my $role (keys(%customroles)) {
8824: $elements{$role.'_access'} = 'radio';
8825: $elements{$role.'_incrs'} = 'radio';
8826: if ($numstatustypes) {
8827: $elements{$role.'_status'} = 'checkbox';
8828: }
8829: if (keys(%domhelpdesk) > 0) {
8830: $elements{$role.'_staff_inc'} = 'checkbox';
8831: $elements{$role.'_staff_exc'} = 'checkbox';
8832: }
1.430 raeburn 8833: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 8834: if (ref($settings{$role}) eq 'HASH') {
8835: if ($settings{$role}{'access'} ne '') {
8836: my $curraccess = $settings{$role}{'access'};
8837: $stored{$role.'_access'} = $curraccess;
8838: $stored{$role.'_incrs'} = 1;
8839: if ($curraccess eq 'status') {
8840: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
8841: $stored{$role.'_status'} = $settings{$role}{'status'};
8842: }
8843: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8844: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
8845: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
8846: }
8847: }
8848: } else {
8849: $stored{$role.'_incrs'} = 0;
8850: }
8851: $stored{$role.'_override'} = [];
8852: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
8853: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
8854: foreach my $priv (@{$settings{$role}{'off'}}) {
8855: push(@{$stored{$role.'_override'}},$priv);
8856: }
8857: }
8858: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
8859: foreach my $priv (@{$settings{$role}{'on'}}) {
8860: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
8861: push(@{$stored{$role.'_override'}},$priv);
8862: }
8863: }
8864: }
8865: }
8866: } else {
8867: $stored{$role.'_incrs'} = 0;
8868: }
8869: }
8870: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
8871: }
8872:
8873: my $js = <<"ENDJS";
8874: <script type="text/javascript">
8875: // <![CDATA[
8876: $jscript;
8877:
8878: function switchRoleTab(caller,role) {
8879: if (document.getElementById(role+'_maindiv')) {
8880: if (caller.id != 'LC_current_minitab') {
8881: if (document.getElementById('LC_current_minitab')) {
8882: document.getElementById('LC_current_minitab').id=null;
8883: }
8884: var roledivs = Array('$rolestr');
8885: if (roledivs.length > 0) {
8886: for (var i=0; i<roledivs.length; i++) {
8887: if (document.getElementById(roledivs[i]+'_maindiv')) {
8888: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
8889: }
8890: }
8891: }
8892: caller.id = 'LC_current_minitab';
8893: document.getElementById(role+'_maindiv').style.display='block';
8894: }
8895: }
8896: return false;
1.430 raeburn 8897: }
1.428 raeburn 8898:
8899: function helpdeskAccess(role) {
8900: var curraccess = null;
8901: if (document.$formname.elements[role+'_access'].length) {
8902: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
8903: if (document.$formname.elements[role+'_access'][i].checked) {
8904: curraccess = document.$formname.elements[role+'_access'][i].value;
8905: }
8906: }
8907: }
8908: var shown = Array();
8909: var hidden = Array();
8910: if (curraccess == 'none') {
1.430 raeburn 8911: hidden = Array ('$hiddenstr');
1.428 raeburn 8912: } else {
8913: if (curraccess == 'status') {
1.430 raeburn 8914: shown = Array ('bystatus','privs');
8915: hidden = Array ('notinc','notexc');
1.428 raeburn 8916: } else {
8917: if (curraccess == 'exc') {
8918: shown = Array ('notexc','privs');
8919: hidden = Array ('notinc','bystatus');
8920: }
8921: if (curraccess == 'inc') {
8922: shown = Array ('notinc','privs');
8923: hidden = Array ('notexc','bystatus');
8924: }
8925: if (curraccess == 'all') {
8926: shown = Array ('privs');
8927: hidden = Array ('notinc','notexc','bystatus');
8928: }
8929: }
8930: }
8931: if (hidden.length > 0) {
8932: for (var i=0; i<hidden.length; i++) {
8933: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 8934: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 8935: }
8936: }
8937: }
8938: if (shown.length > 0) {
8939: for (var i=0; i<shown.length; i++) {
8940: if (document.getElementById(role+'_'+shown[i])) {
8941: if (shown[i] == 'privs') {
8942: document.getElementById(role+'_'+shown[i]).style.display = 'block';
8943: } else {
8944: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
8945: }
8946: }
8947: }
8948: }
8949: return;
8950: }
8951:
8952: function toggleAccess(role) {
8953: if ((document.getElementById(role+'_setincrs')) &&
8954: (document.getElementById(role+'_setindom'))) {
8955: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
8956: if (document.$formname.elements[role+'_incrs'][i].checked) {
8957: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
8958: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 8959: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 8960: } else {
8961: document.getElementById(role+'_setincrs').style.display = 'none';
8962: document.getElementById(role+'_setindom').style.display = 'block';
8963: }
8964: break;
8965: }
8966: }
8967: }
8968: return;
8969: }
8970:
8971: // ]]>
8972: </script>
8973: ENDJS
8974:
8975: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
8976:
8977: # print page header
8978: $r->print(&header($js,$args));
8979: # print form header
8980: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
8981:
8982: if (keys(%customroles)) {
8983: my %lt = &Apache::lonlocal::texthash(
8984: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
8985: 'rou' => 'Role usage',
8986: 'whi' => 'Which helpdesk personnel may use this role?',
8987: 'udd' => 'Use domain default',
1.433 raeburn 8988: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 8989: 'dh' => 'All with domain helpdesk role',
8990: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 8991: 'none' => 'None',
8992: 'status' => 'Determined based on institutional status',
1.430 raeburn 8993: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 8994: 'exc' => 'Exclude all, but include specific personnel',
8995: 'hel' => 'Helpdesk',
8996: 'rpr' => 'Role privileges',
8997: );
8998: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
8999: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
9000: my (%domcurrent,%ordered,%description,%domusage,$disabled);
9001: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9002: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
9003: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
9004: }
9005: }
9006: my $count = 0;
9007: foreach my $role (sort(keys(%customroles))) {
9008: my ($order,$desc,$access_in_dom);
9009: if (ref($domcurrent{$role}) eq 'HASH') {
9010: $order = $domcurrent{$role}{'order'};
9011: $desc = $domcurrent{$role}{'desc'};
9012: $access_in_dom = $domcurrent{$role}{'access'};
9013: }
9014: if ($order eq '') {
9015: $order = $count;
9016: }
9017: $ordered{$order} = $role;
9018: if ($desc ne '') {
9019: $description{$role} = $desc;
9020: } else {
9021: $description{$role}= $role;
9022: }
9023: $count++;
9024: }
9025: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
9026: my @roles_by_num = ();
9027: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
9028: push(@roles_by_num,$ordered{$item});
1.430 raeburn 9029: }
1.429 raeburn 9030: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 9031: if ($permission->{'owner'}) {
9032: $r->print('<br />'.$lt{'aco'}.'</p><p>');
9033: $r->print('<input type="hidden" name="state" value="process" />'.
9034: '<input type="submit" value="'.&mt('Save changes').'" />');
9035: } else {
9036: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
9037: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
9038: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
9039: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
9040: }
9041: $disabled = ' disabled="disabled"';
9042: }
9043: $r->print('</p>');
9044:
9045: $r->print('<div id="LC_minitab_header"><ul>');
9046: my $count = 0;
9047: my %visibility;
9048: foreach my $role (@roles_by_num) {
9049: my $id;
9050: if ($count == 0) {
9051: $id=' id="LC_current_minitab"';
1.430 raeburn 9052: $visibility{$role} = ' style="display:block"';
1.428 raeburn 9053: } else {
9054: $visibility{$role} = ' style="display:none"';
9055: }
9056: $count ++;
9057: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
9058: }
9059: $r->print('</ul></div>');
9060:
9061: foreach my $role (@roles_by_num) {
9062: my %usecheck = (
9063: all => ' checked="checked"',
9064: );
9065: my %displaydiv = (
9066: status => 'none',
9067: inc => 'none',
9068: exc => 'none',
9069: priv => 'block',
9070: );
9071: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 9072: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 9073: if ($settings{$role}{'access'} ne '') {
9074: $indomvis = ' style="display:none"';
9075: $incrsvis = ' style="display:block"';
1.430 raeburn 9076: $incrscheck = ' checked="checked"';
1.428 raeburn 9077: if ($settings{$role}{'access'} ne 'all') {
9078: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
9079: delete($usecheck{'all'});
9080: if ($settings{$role}{'access'} eq 'status') {
9081: my $access = 'status';
9082: $displaydiv{$access} = 'inline';
9083: if (ref($settings{$role}{$access}) eq 'ARRAY') {
9084: $selected{$access} = $settings{$role}{$access};
9085: }
9086: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
9087: my $access = $1;
9088: $displaydiv{$access} = 'inline';
9089: if (ref($settings{$role}{$access}) eq 'ARRAY') {
9090: $selected{$access} = $settings{$role}{$access};
9091: }
9092: } elsif ($settings{$role}{'access'} eq 'none') {
9093: $displaydiv{'priv'} = 'none';
9094: }
9095: }
9096: } else {
9097: $indomcheck = ' checked="checked"';
9098: $indomvis = ' style="display:block"';
9099: $incrsvis = ' style="display:none"';
9100: }
9101: } else {
9102: $indomcheck = ' checked="checked"';
1.430 raeburn 9103: $indomvis = ' style="display:block"';
1.428 raeburn 9104: $incrsvis = ' style="display:none"';
9105: }
9106: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
9107: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
9108: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
9109: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
9110: &mt('Set here in [_1]',lc($crstype)).'</label>'.
9111: '<span>'.(' 'x2).
9112: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
9113: $lt{'udd'}.'</label><span></p>'.
9114: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
9115: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
9116: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
9117: foreach my $access (@accesstypes) {
9118: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
9119: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
9120: if ($access eq 'status') {
9121: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
9122: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
9123: $othertitle,$usertypes,$types,$disabled).
9124: '</div>');
9125: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
9126: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
9127: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
9128: \%domhelpdesk,$disabled).
9129: '</div>');
9130: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
9131: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
9132: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
9133: \%domhelpdesk,$disabled).
9134: '</div>');
9135: }
9136: $r->print('</p>');
9137: }
9138: $r->print('</div></fieldset>');
9139: my %full=();
9140: my %levels= (
9141: course => {},
9142: domain => {},
9143: system => {},
9144: );
9145: my %levelscurrent=(
9146: course => {},
9147: domain => {},
9148: system => {},
9149: );
9150: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
9151: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
9152: '<legend>'.$lt{'rpr'}.'</legend>'.
9153: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
9154: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
9155: }
1.429 raeburn 9156: if ($permission->{'owner'}) {
9157: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
9158: }
1.428 raeburn 9159: } else {
9160: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
9161: }
9162: # Form Footer
9163: $r->print('<input type="hidden" name="action" value="helpdesk" />'
9164: .'</form>');
9165: return;
9166: }
9167:
1.465 raeburn 9168: sub print_queued_roles {
9169: my ($r,$context,$permission,$brcrum) = @_;
9170: push (@{$brcrum},
9171: {href => '/adm/createuser?action=rolerequests',
9172: text => 'Role Requests (other domains)',
9173: help => ''});
9174: my $bread_crumbs_component = 'Role Requests';
9175: my $args = { bread_crumbs => $brcrum,
9176: bread_crumbs_component => $bread_crumbs_component};
9177: # print page header
9178: $r->print(&header('',$args));
9179: my ($dom,$cnum);
9180: $dom = $env{'request.role.domain'};
9181: if ($context eq 'course') {
9182: if ($env{'request.course.id'}) {
9183: if (&Apache::loncommon::course_type() eq 'Community') {
9184: $context = 'community';
9185: }
9186: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9187: }
9188: } elsif ($context eq 'author') {
9189: $cnum = $env{'user.name'};
9190: }
9191: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('othdomqueue',$dom,$cnum,$context));
9192: return;
9193: }
9194:
9195: sub print_pendingroles {
9196: my ($r,$context,$permission,$brcrum) = @_;
9197: push (@{$brcrum},
9198: {href => '/adm/createuser?action=queuedroles',
9199: text => 'Queued Role Assignments (users in this domain)',
9200: help => ''});
9201: my $bread_crumbs_component = 'Queued Role Assignments';
9202: my $args = { bread_crumbs => $brcrum,
9203: bread_crumbs_component => $bread_crumbs_component};
9204: # print page header
9205: $r->print(&header('',$args));
9206: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('othdomaction',$env{'request.role.domain'},'','domain'));
9207: return;
9208: }
9209:
9210: sub process_pendingroles {
9211: my ($r,$context,$permission,$brcrum) = @_;
9212: push (@{$brcrum},
9213: {href => '/adm/createuser?action=queuedroles',
9214: text => 'Queued Role Assignments (users in this domain)',
9215: help => ''},
9216: {href => '/adm/createuser?action=processrolereq',
9217: text => 'Process Queue',
9218: help => ''});
9219: my $bread_crumbs_component = 'Queued Role Assignments';
9220: my $args = { bread_crumbs => $brcrum,
9221: bread_crumbs_component => $bread_crumbs_component};
9222: # print page header
9223: $r->print(&header('',$args));
9224: $r->print(&Apache::loncoursequeueadmin::update_request_queue('othdombydc',
9225: $env{'request.role.domain'}));
9226: return;
9227: }
9228:
1.428 raeburn 9229: sub domain_adhoc_access {
9230: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
9231: my %domusage;
9232: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
9233: foreach my $role (keys(%{$roles})) {
9234: if (ref($domcurrent->{$role}) eq 'HASH') {
9235: my $access = $domcurrent->{$role}{'access'};
9236: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
9237: $access = 'all';
1.432 raeburn 9238: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
9239: &Apache::lonnet::plaintext('da'));
1.428 raeburn 9240: } elsif ($access eq 'status') {
9241: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
9242: my @shown;
9243: foreach my $type (@{$domcurrent->{$role}{$access}}) {
9244: unless ($type eq 'default') {
9245: if ($usertypes->{$type}) {
9246: push(@shown,$usertypes->{$type});
9247: }
9248: }
9249: }
9250: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
9251: push(@shown,$othertitle);
9252: }
9253: if (@shown) {
9254: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 9255: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
9256: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 9257: } else {
9258: $domusage{$role} = &mt('No one in the domain');
9259: }
9260: }
9261: } elsif ($access eq 'inc') {
9262: my @dominc = ();
9263: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
9264: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
9265: my ($uname,$udom) = split(/:/,$user);
9266: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
9267: }
9268: my $showninc = join(', ',@dominc);
9269: if ($showninc ne '') {
1.432 raeburn 9270: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
9271: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 9272: } else {
1.432 raeburn 9273: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
9274: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 9275: }
9276: }
9277: } elsif ($access eq 'exc') {
9278: my @domexc = ();
9279: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
9280: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
9281: my ($uname,$udom) = split(/:/,$user);
9282: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
9283: }
9284: }
9285: my $shownexc = join(', ',@domexc);
9286: if ($shownexc ne '') {
1.432 raeburn 9287: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
9288: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 9289: } else {
9290: $domusage{$role} = &mt('No one in the domain');
9291: }
9292: } elsif ($access eq 'none') {
9293: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 9294: } elsif ($access eq 'dh') {
1.433 raeburn 9295: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 9296: } elsif ($access eq 'da') {
1.433 raeburn 9297: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 9298: } elsif ($access eq 'all') {
1.432 raeburn 9299: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
9300: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 9301: }
9302: } else {
1.432 raeburn 9303: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
9304: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 9305: }
9306: }
9307: return %domusage;
9308: }
9309:
9310: sub get_domain_customroles {
9311: my ($cdom,$confname) = @_;
9312: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
9313: my %customroles;
9314: foreach my $key (keys(%existing)) {
9315: if ($key=~/^rolesdef\_(\w+)$/) {
9316: my $rolename = $1;
9317: my %privs;
9318: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
9319: $customroles{$rolename} = \%privs;
9320: }
9321: }
9322: return %customroles;
9323: }
9324:
9325: sub role_priv_table {
9326: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
9327: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
9328: (ref($levelscurrent) eq 'HASH'));
9329: my %lt=&Apache::lonlocal::texthash (
9330: 'crl' => 'Course Level Privilege',
9331: 'def' => 'Domain Defaults',
9332: 'ove' => 'Override in Course',
9333: 'ine' => 'In effect',
9334: 'dis' => 'Disabled',
9335: 'ena' => 'Enabled',
9336: );
9337: if ($crstype eq 'Community') {
9338: $lt{'ove'} = 'Override in Community',
9339: }
9340: my @status = ('Disabled','Enabled');
9341: my (%on,%off);
9342: if (ref($overridden) eq 'HASH') {
9343: if (ref($overridden->{'on'}) eq 'ARRAY') {
9344: map { $on{$_} = 1; } (@{$overridden->{'on'}});
9345: }
9346: if (ref($overridden->{'off'}) eq 'ARRAY') {
9347: map { $off{$_} = 1; } (@{$overridden->{'off'}});
9348: }
9349: }
9350: my $output=&Apache::loncommon::start_data_table().
9351: &Apache::loncommon::start_data_table_header_row().
9352: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
9353: '</th><th>'.$lt{'ine'}.'</th>'.
9354: &Apache::loncommon::end_data_table_header_row();
9355: foreach my $priv (sort(keys(%{$full}))) {
9356: next unless ($levels->{'course'}{$priv});
9357: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
9358: my ($default,$ineffect);
9359: if ($levelscurrent->{'course'}{$priv}) {
9360: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
9361: $ineffect = $default;
9362: }
9363: my ($customstatus,$checked);
9364: $output .= &Apache::loncommon::start_data_table_row().
9365: '<td>'.$privtext.'</td>'.
9366: '<td>'.$default.'</td><td>';
9367: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
9368: if ($permission->{'owner'}) {
9369: $checked = ' checked="checked"';
9370: }
9371: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 9372: $ineffect = $customstatus;
1.428 raeburn 9373: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
9374: if ($permission->{'owner'}) {
1.430 raeburn 9375: $checked = ' checked="checked"';
1.428 raeburn 9376: }
9377: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 9378: $ineffect = $customstatus;
1.428 raeburn 9379: }
9380: if ($permission->{'owner'}) {
9381: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
9382: } else {
9383: $output .= $customstatus;
9384: }
9385: $output .= '</td><td>'.$ineffect.'</td>'.
9386: &Apache::loncommon::end_data_table_row();
9387: }
9388: $output .= &Apache::loncommon::end_data_table();
9389: return $output;
9390: }
9391:
9392: sub get_adhocrole_settings {
1.430 raeburn 9393: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 9394: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
9395: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
9396: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
9397: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
9398: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
9399: $settings->{$role}{'access'} = $curraccess;
9400: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
9401: my @status = split(/,/,$rest);
9402: my @currstatus;
9403: foreach my $type (@status) {
9404: if ($type eq 'default') {
9405: push(@currstatus,$type);
9406: } elsif (grep(/^\Q$type\E$/,@{$types})) {
9407: push(@currstatus,$type);
9408: }
9409: }
9410: if (@currstatus) {
9411: $settings->{$role}{$curraccess} = \@currstatus;
9412: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
9413: my @personnel = split(/,/,$rest);
9414: $settings->{$role}{$curraccess} = \@personnel;
9415: }
9416: }
9417: }
9418: }
9419: foreach my $role (keys(%{$customroles})) {
9420: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
9421: my %currentprivs;
9422: if (ref($customroles->{$role}) eq 'HASH') {
9423: if (exists($customroles->{$role}{'course'})) {
9424: my %full=();
9425: my %levels= (
9426: course => {},
9427: domain => {},
9428: system => {},
9429: );
9430: my %levelscurrent=(
9431: course => {},
9432: domain => {},
9433: system => {},
9434: );
9435: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
9436: %currentprivs = %{$levelscurrent{'course'}};
9437: }
9438: }
9439: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
9440: next if ($item eq '');
9441: my ($rule,$rest) = split(/=/,$item);
9442: next unless (($rule eq 'off') || ($rule eq 'on'));
9443: foreach my $priv (split(/:/,$rest)) {
9444: if ($priv ne '') {
9445: if ($rule eq 'off') {
9446: push(@{$overridden->{$role}{'off'}},$priv);
9447: if ($currentprivs{$priv}) {
9448: push(@{$settings->{$role}{'off'}},$priv);
9449: }
9450: } else {
9451: push(@{$overridden->{$role}{'on'}},$priv);
9452: unless ($currentprivs{$priv}) {
9453: push(@{$settings->{$role}{'on'}},$priv);
9454: }
9455: }
9456: }
9457: }
9458: }
9459: }
9460: }
9461: return;
9462: }
9463:
9464: sub update_helpdeskaccess {
9465: my ($r,$permission,$brcrum) = @_;
9466: my $helpitem = 'Course_Helpdesk_Access';
9467: push (@{$brcrum},
9468: {href => '/adm/createuser?action=helpdesk',
9469: text => 'Helpdesk Access',
9470: help => $helpitem},
9471: {href => '/adm/createuser?action=helpdesk',
9472: text => 'Result',
9473: help => $helpitem}
9474: );
9475: my $bread_crumbs_component = 'Helpdesk Staff Access';
9476: my $args = { bread_crumbs => $brcrum,
9477: bread_crumbs_component => $bread_crumbs_component};
9478:
9479: # print page header
9480: $r->print(&header('',$args));
9481: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
9482: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
9483: return;
9484: }
1.434 raeburn 9485: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 9486: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9487: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9488: my $confname = $cdom.'-domainconfig';
9489: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
9490: my $crstype = &Apache::loncommon::course_type();
9491: my %customroles = &get_domain_customroles($cdom,$confname);
9492: my (%settings,%overridden);
9493: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
9494: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 9495: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 9496: my (%changed,%storehash,@todelete);
9497:
9498: if (keys(%customroles)) {
9499: my (%newsettings,@incrs);
9500: foreach my $role (keys(%customroles)) {
9501: $newsettings{$role} = {
9502: access => '',
9503: status => '',
9504: exc => '',
9505: inc => '',
9506: on => '',
9507: off => '',
9508: };
9509: my %current;
9510: if (ref($settings{$role}) eq 'HASH') {
9511: %current = %{$settings{$role}};
9512: }
9513: if (ref($overridden{$role}) eq 'HASH') {
9514: $current{'overridden'} = $overridden{$role};
9515: }
9516: if ($env{'form.'.$role.'_incrs'}) {
9517: my $access = $env{'form.'.$role.'_access'};
9518: if (grep(/^\Q$access\E$/,@accesstypes)) {
9519: push(@incrs,$role);
9520: unless ($current{'access'} eq $access) {
9521: $changed{$role}{'access'} = 1;
1.430 raeburn 9522: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 9523: }
9524: if ($access eq 'status') {
9525: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
9526: my @stored;
9527: my @shownstatus;
9528: if (ref($types) eq 'ARRAY') {
9529: foreach my $type (sort(@statuses)) {
9530: if ($type eq 'default') {
9531: push(@stored,$type);
9532: } elsif (grep(/^\Q$type\E$/,@{$types})) {
9533: push(@stored,$type);
9534: push(@shownstatus,$usertypes->{$type});
9535: }
9536: }
9537: if (grep(/^default$/,@statuses)) {
9538: push(@shownstatus,$othertitle);
9539: }
9540: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
9541: }
9542: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
9543: if (ref($current{'status'}) eq 'ARRAY') {
9544: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
9545: if (@diffs) {
9546: $changed{$role}{'status'} = 1;
9547: }
9548: } elsif (@stored) {
9549: $changed{$role}{'status'} = 1;
9550: }
9551: } elsif (($access eq 'inc') || ($access eq 'exc')) {
9552: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
9553: my @newspecstaff;
9554: my @stored;
9555: my @currstaff;
9556: foreach my $person (sort(@personnel)) {
9557: if ($domhelpdesk{$person}) {
1.430 raeburn 9558: push(@stored,$person);
1.428 raeburn 9559: }
9560: }
9561: if (ref($current{$access}) eq 'ARRAY') {
9562: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
9563: if (@diffs) {
9564: $changed{$role}{$access} = 1;
9565: }
9566: } elsif (@stored) {
9567: $changed{$role}{$access} = 1;
9568: }
9569: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
9570: foreach my $person (@stored) {
9571: my ($uname,$udom) = split(/:/,$person);
9572: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
9573: }
9574: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
9575: }
9576: $newsettings{$role}{'access'} = $access;
9577: }
9578: } else {
9579: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
9580: $changed{$role}{'access'} = 1;
9581: $newsettings{$role} = {};
9582: push(@todelete,'internal.adhoc.'.$role);
9583: }
9584: }
9585: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
9586: if (ref($current{'overridden'}) eq 'HASH') {
9587: push(@todelete,'internal.adhocpriv.'.$role);
9588: }
9589: } else {
9590: my %full=();
9591: my %levels= (
9592: course => {},
9593: domain => {},
9594: system => {},
9595: );
9596: my %levelscurrent=(
9597: course => {},
9598: domain => {},
9599: system => {},
9600: );
9601: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
9602: my (@updatedon,@updatedoff,@override);
9603: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 9604: if (@override) {
1.428 raeburn 9605: foreach my $priv (sort(keys(%full))) {
9606: next unless ($levels{'course'}{$priv});
9607: if (grep(/^\Q$priv\E$/,@override)) {
9608: if ($levelscurrent{'course'}{$priv}) {
9609: push(@updatedoff,$priv);
9610: } else {
9611: push(@updatedon,$priv);
9612: }
9613: }
9614: }
9615: }
9616: if (@updatedon) {
1.430 raeburn 9617: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 9618: }
9619: if (@updatedoff) {
9620: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
9621: }
9622: if (ref($current{'overridden'}) eq 'HASH') {
9623: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
9624: if (@updatedon) {
9625: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
9626: if (@diffs) {
9627: $changed{$role}{'on'} = 1;
9628: }
9629: } else {
9630: $changed{$role}{'on'} = 1;
9631: }
9632: } elsif (@updatedon) {
9633: $changed{$role}{'on'} = 1;
9634: }
9635: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
9636: if (@updatedoff) {
9637: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
9638: if (@diffs) {
9639: $changed{$role}{'off'} = 1;
9640: }
9641: } else {
9642: $changed{$role}{'off'} = 1;
9643: }
9644: } elsif (@updatedoff) {
9645: $changed{$role}{'off'} = 1;
9646: }
9647: } else {
9648: if (@updatedon) {
9649: $changed{$role}{'on'} = 1;
9650: }
9651: if (@updatedoff) {
9652: $changed{$role}{'off'} = 1;
9653: }
9654: }
9655: if (ref($changed{$role}) eq 'HASH') {
9656: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
9657: my $newpriv;
9658: if (@updatedon) {
9659: $newpriv = 'on='.join(':',@updatedon);
9660: }
9661: if (@updatedoff) {
9662: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
9663: }
9664: if ($newpriv eq '') {
9665: push(@todelete,'internal.adhocpriv.'.$role);
9666: } else {
9667: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
9668: }
9669: }
9670: }
9671: }
9672: }
9673: if (@incrs) {
9674: $storehash{'internal.adhocaccess'} = join(',',@incrs);
9675: } elsif (@todelete) {
9676: push(@todelete,'internal.adhocaccess');
9677: }
9678: if (keys(%changed)) {
9679: my ($putres,$delres);
9680: if (keys(%storehash)) {
9681: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
9682: my %newenvhash;
9683: foreach my $key (keys(%storehash)) {
9684: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
9685: }
9686: &Apache::lonnet::appenv(\%newenvhash);
9687: }
9688: if (@todelete) {
9689: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
9690: foreach my $key (@todelete) {
9691: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
9692: }
9693: }
9694: if (($putres eq 'ok') || ($delres eq 'ok')) {
9695: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
9696: my (%domcurrent,%ordered,%description,%domusage);
9697: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9698: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
9699: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
9700: }
9701: }
9702: my $count = 0;
9703: foreach my $role (sort(keys(%customroles))) {
9704: my ($order,$desc);
9705: if (ref($domcurrent{$role}) eq 'HASH') {
9706: $order = $domcurrent{$role}{'order'};
9707: $desc = $domcurrent{$role}{'desc'};
9708: }
9709: if ($order eq '') {
9710: $order = $count;
9711: }
9712: $ordered{$order} = $role;
9713: if ($desc ne '') {
9714: $description{$role} = $desc;
9715: } else {
9716: $description{$role}= $role;
9717: }
9718: $count++;
9719: }
9720: my @roles_by_num = ();
9721: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
9722: push(@roles_by_num,$ordered{$item});
9723: }
9724: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 9725: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 9726: $r->print('<ul>');
9727: foreach my $role (@roles_by_num) {
9728: next unless (ref($changed{$role}) eq 'HASH');
9729: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
9730: '<ul>');
1.430 raeburn 9731: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 9732: $r->print('<li>');
9733: if ($env{'form.'.$role.'_incrs'}) {
9734: if ($newsettings{$role}{'access'} eq 'all') {
9735: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 9736: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 9737: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
9738: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 9739: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 9740: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
9741: &Apache::lonnet::plaintext('da')));
1.428 raeburn 9742: } elsif ($newsettings{$role}{'access'} eq 'none') {
9743: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9744: } elsif ($newsettings{$role}{'access'} eq 'status') {
9745: if ($newsettings{$role}{'status'}) {
9746: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 9747: if (split(/,/,$rest) > 1) {
1.428 raeburn 9748: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
9749: $newsettings{$role}{'status'}));
9750: } else {
9751: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
9752: $newsettings{$role}{'status'}));
9753: }
9754: } else {
9755: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9756: }
9757: } elsif ($newsettings{$role}{'access'} eq 'exc') {
9758: if ($newsettings{$role}{'exc'}) {
9759: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
9760: } else {
9761: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9762: }
9763: } elsif ($newsettings{$role}{'access'} eq 'inc') {
9764: if ($newsettings{$role}{'inc'}) {
9765: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
9766: } else {
9767: $r->print(&mt('All helpdesk staff may use this role.'));
9768: }
9769: }
9770: } else {
9771: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
9772: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
9773: }
9774: $r->print('</li>');
9775: }
9776: unless ($newsettings{$role}{'access'} eq 'none') {
9777: if ($changed{$role}{'off'}) {
9778: if ($newsettings{$role}{'off'}) {
9779: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
9780: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
9781: } else {
1.430 raeburn 9782: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 9783: }
9784: }
1.430 raeburn 9785: if ($changed{$role}{'on'}) {
1.428 raeburn 9786: if ($newsettings{$role}{'on'}) {
9787: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
9788: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
9789: } else {
1.430 raeburn 9790: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 9791: }
9792: }
9793: }
9794: $r->print('</ul></li>');
9795: }
9796: $r->print('</ul>');
9797: }
9798: } else {
1.430 raeburn 9799: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 9800: }
9801: }
9802: return;
9803: }
9804:
1.27 matthew 9805: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 9806: sub user_search_result {
1.221 raeburn 9807: my ($context,$srch) = @_;
1.160 raeburn 9808: my %allhomes;
9809: my %inst_matches;
9810: my %srch_results;
1.181 raeburn 9811: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 9812: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 9813: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 9814: $response = &mt('Invalid search.');
9815: }
9816: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
9817: $response = &mt('Invalid search.');
9818: }
1.177 raeburn 9819: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 9820: $response = &mt('Invalid search.');
9821: }
9822: if ($srch->{'srchterm'} eq '') {
9823: $response = &mt('You must enter a search term.');
9824: }
1.183 raeburn 9825: if ($srch->{'srchterm'} =~ /^\s+$/) {
9826: $response = &mt('Your search term must contain more than just spaces.');
9827: }
1.160 raeburn 9828: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
9829: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 9830: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 9831: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
9832: }
9833: }
9834: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
9835: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 9836: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 9837: my $unamecheck = $srch->{'srchterm'};
9838: if ($srch->{'srchtype'} eq 'contains') {
9839: if ($unamecheck !~ /^\w/) {
9840: $unamecheck = 'a'.$unamecheck;
9841: }
9842: }
9843: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 9844: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
9845: }
1.160 raeburn 9846: }
9847: }
1.180 raeburn 9848: if ($response ne '') {
1.413 raeburn 9849: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 9850: }
1.160 raeburn 9851: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 9852: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 9853: if ($instd_chk ne 'ok') {
1.412 raeburn 9854: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 9855: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 9856: if ($domd_chk eq 'ok') {
1.435 raeburn 9857: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 9858: }
1.415 raeburn 9859: $response .= '<br />';
1.412 raeburn 9860: }
9861: } else {
1.417 raeburn 9862: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 9863: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 9864: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 9865: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 9866: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 9867: if ($instd_chk eq 'ok') {
1.435 raeburn 9868: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 9869: }
1.415 raeburn 9870: $response .= '<br />';
1.412 raeburn 9871: }
1.160 raeburn 9872: }
9873: }
9874: if ($response ne '') {
1.180 raeburn 9875: return ($currstate,$response);
1.160 raeburn 9876: }
9877: if ($srch->{'srchby'} eq 'uname') {
9878: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
9879: if ($env{'form.forcenew'}) {
9880: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
9881: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
9882: if ($uhome eq 'no_host') {
9883: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 9884: my $showdom = &display_domain_info($env{'request.role.domain'});
9885: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 9886: } else {
1.179 raeburn 9887: $currstate = 'modify';
1.160 raeburn 9888: }
9889: } else {
1.179 raeburn 9890: $currstate = 'modify';
1.160 raeburn 9891: }
9892: } else {
9893: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 9894: if ($srch->{'srchtype'} eq 'exact') {
9895: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
9896: if ($uhome eq 'no_host') {
1.179 raeburn 9897: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9898: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 9899: } else {
1.179 raeburn 9900: $currstate = 'modify';
1.416 raeburn 9901: if ($env{'form.action'} eq 'accesslogs') {
9902: $currstate = 'activity';
9903: }
1.310 raeburn 9904: my $uname = $srch->{'srchterm'};
9905: my $udom = $srch->{'srchdomain'};
9906: $srch_results{$uname.':'.$udom} =
9907: { &Apache::lonnet::get('environment',
9908: ['firstname',
9909: 'lastname',
9910: 'permanentemail'],
9911: $udom,$uname)
9912: };
1.162 raeburn 9913: }
9914: } else {
9915: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 9916: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9917: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9918: }
9919: } else {
1.167 albertel 9920: my $courseusers = &get_courseusers();
1.162 raeburn 9921: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 9922: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 9923: $currstate = 'modify';
1.162 raeburn 9924: } else {
1.179 raeburn 9925: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9926: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 9927: }
1.160 raeburn 9928: } else {
1.167 albertel 9929: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 9930: my ($cuname,$cudomain) = split(/:/,$user);
9931: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 9932: my $matched = 0;
9933: if ($srch->{'srchtype'} eq 'begins') {
9934: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
9935: $matched = 1;
9936: }
9937: } else {
9938: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
9939: $matched = 1;
9940: }
9941: }
9942: if ($matched) {
1.167 albertel 9943: $srch_results{$user} =
9944: {&Apache::lonnet::get('environment',
9945: ['firstname',
9946: 'lastname',
1.194 albertel 9947: 'permanentemail'],
9948: $cudomain,$cuname)};
1.162 raeburn 9949: }
9950: }
9951: }
1.179 raeburn 9952: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9953: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9954: }
9955: }
9956: }
9957: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 9958: $currstate = 'query';
1.160 raeburn 9959: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 9960: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
9961: if ($dirsrchres eq 'ok') {
9962: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9963: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 9964: } else {
9965: my $showdom = &display_domain_info($srch->{'srchdomain'});
9966: $response = '<span class="LC_warning">'.
9967: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
9968: '</span><br />'.
1.435 raeburn 9969: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 9970: '<br />';
1.181 raeburn 9971: }
1.160 raeburn 9972: }
9973: } else {
9974: if ($srch->{'srchin'} eq 'dom') {
9975: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 9976: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9977: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9978: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 9979: my $courseusers = &get_courseusers();
9980: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 9981: my ($uname,$udom) = split(/:/,$user);
9982: my %names = &Apache::loncommon::getnames($uname,$udom);
9983: my %emails = &Apache::loncommon::getemails($uname,$udom);
9984: if ($srch->{'srchby'} eq 'lastname') {
9985: if ((($srch->{'srchtype'} eq 'exact') &&
9986: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 9987: (($srch->{'srchtype'} eq 'begins') &&
9988: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 9989: (($srch->{'srchtype'} eq 'contains') &&
9990: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
9991: $srch_results{$user} = {firstname => $names{'firstname'},
9992: lastname => $names{'lastname'},
9993: permanentemail => $emails{'permanentemail'},
9994: };
9995: }
9996: } elsif ($srch->{'srchby'} eq 'lastfirst') {
9997: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 9998: $srchlast =~ s/\s+$//;
9999: $srchfirst =~ s/^\s+//;
1.160 raeburn 10000: if ($srch->{'srchtype'} eq 'exact') {
10001: if (($names{'lastname'} eq $srchlast) &&
10002: ($names{'firstname'} eq $srchfirst)) {
10003: $srch_results{$user} = {firstname => $names{'firstname'},
10004: lastname => $names{'lastname'},
10005: permanentemail => $emails{'permanentemail'},
10006:
10007: };
10008: }
1.177 raeburn 10009: } elsif ($srch->{'srchtype'} eq 'begins') {
10010: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
10011: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
10012: $srch_results{$user} = {firstname => $names{'firstname'},
10013: lastname => $names{'lastname'},
10014: permanentemail => $emails{'permanentemail'},
10015: };
10016: }
10017: } else {
1.160 raeburn 10018: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
10019: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
10020: $srch_results{$user} = {firstname => $names{'firstname'},
10021: lastname => $names{'lastname'},
10022: permanentemail => $emails{'permanentemail'},
10023: };
10024: }
10025: }
10026: }
10027: }
1.179 raeburn 10028: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10029: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 10030: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 10031: $currstate = 'query';
1.160 raeburn 10032: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 10033: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
10034: if ($dirsrchres eq 'ok') {
10035: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10036: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 10037: } else {
1.412 raeburn 10038: my $showdom = &display_domain_info($srch->{'srchdomain'});
10039: $response = '<span class="LC_warning">'.
1.181 raeburn 10040: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
10041: '</span><br />'.
1.435 raeburn 10042: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 10043: '<br />';
1.181 raeburn 10044: }
1.160 raeburn 10045: }
10046: }
1.179 raeburn 10047: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 10048: }
10049:
1.412 raeburn 10050: sub domdirectorysrch_check {
10051: my ($srch) = @_;
10052: my $response;
10053: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
10054: ['directorysrch'],$srch->{'srchdomain'});
10055: my $showdom = &display_domain_info($srch->{'srchdomain'});
10056: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
10057: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
10058: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
10059: }
10060: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
10061: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
10062: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
10063: }
10064: }
10065: }
10066: return 'ok';
10067: }
10068:
10069: sub instdirectorysrch_check {
1.160 raeburn 10070: my ($srch) = @_;
10071: my $can_search = 0;
10072: my $response;
10073: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
10074: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 10075: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 10076: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
10077: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 10078: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 10079: }
10080: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
10081: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 10082: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 10083: }
10084: my @usertypes = split(/:/,$env{'environment.inststatus'});
10085: if (!@usertypes) {
10086: push(@usertypes,'default');
10087: }
10088: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
10089: foreach my $type (@usertypes) {
10090: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
10091: $can_search = 1;
10092: last;
10093: }
10094: }
10095: }
10096: if (!$can_search) {
10097: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
10098: my @longtypes;
10099: foreach my $item (@usertypes) {
1.229 raeburn 10100: if (defined($insttypes->{$item})) {
10101: push (@longtypes,$insttypes->{$item});
10102: } elsif ($item eq 'default') {
10103: push (@longtypes,&mt('other'));
10104: }
1.160 raeburn 10105: }
10106: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 10107: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 10108: }
1.160 raeburn 10109: } else {
10110: $can_search = 1;
10111: }
10112: } else {
1.180 raeburn 10113: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 10114: }
10115: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 10116: uname => 'username',
1.160 raeburn 10117: lastfirst => 'last name, first name',
1.167 albertel 10118: lastname => 'last name',
1.172 raeburn 10119: contains => 'contains',
1.178 raeburn 10120: exact => 'as exact match to',
10121: begins => 'begins with',
1.160 raeburn 10122: );
10123: if ($can_search) {
10124: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
10125: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 10126: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 10127: }
10128: } else {
1.180 raeburn 10129: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 10130: }
10131: }
10132: if ($can_search) {
1.178 raeburn 10133: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
10134: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
10135: return 'ok';
10136: } else {
1.180 raeburn 10137: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 10138: }
10139: } else {
10140: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
10141: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
10142: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
10143: return 'ok';
10144: } else {
1.180 raeburn 10145: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 10146: }
1.160 raeburn 10147: }
10148: }
10149: }
10150:
10151: sub get_courseusers {
10152: my %advhash;
1.167 albertel 10153: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 10154: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
10155: foreach my $role (sort(keys(%coursepersonnel))) {
10156: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 10157: if (!exists($classlist->{$user})) {
10158: $classlist->{$user} = [];
10159: }
1.160 raeburn 10160: }
10161: }
1.167 albertel 10162: return $classlist;
1.160 raeburn 10163: }
10164:
10165: sub build_search_response {
1.221 raeburn 10166: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 10167: my ($currstate,$response,$forcenewuser);
1.160 raeburn 10168: my %names = (
1.330 bisitz 10169: 'uname' => 'username',
10170: 'lastname' => 'last name',
1.160 raeburn 10171: 'lastfirst' => 'last name, first name',
1.330 bisitz 10172: 'crs' => 'this course',
10173: 'dom' => 'LON-CAPA domain',
10174: 'instd' => 'the institutional directory for domain',
1.160 raeburn 10175: );
10176:
10177: my %single = (
1.180 raeburn 10178: begins => 'A match',
1.160 raeburn 10179: contains => 'A match',
1.180 raeburn 10180: exact => 'An exact match',
1.160 raeburn 10181: );
10182: my %nomatch = (
1.180 raeburn 10183: begins => 'No match',
1.160 raeburn 10184: contains => 'No match',
1.180 raeburn 10185: exact => 'No exact match',
1.160 raeburn 10186: );
10187: if (keys(%srch_results) > 1) {
1.179 raeburn 10188: $currstate = 'select';
1.160 raeburn 10189: } else {
10190: if (keys(%srch_results) == 1) {
1.416 raeburn 10191: if ($env{'form.action'} eq 'accesslogs') {
10192: $currstate = 'activity';
10193: } else {
10194: $currstate = 'modify';
10195: }
1.180 raeburn 10196: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
10197: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 10198: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 10199: }
1.330 bisitz 10200: } else { # Search has nothing found. Prepare message to user.
10201: $response = '<span class="LC_warning">';
1.180 raeburn 10202: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 10203: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
10204: '<b>'.$srch->{'srchterm'}.'</b>',
10205: &display_domain_info($srch->{'srchdomain'}));
10206: } else {
10207: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
10208: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 10209: }
10210: $response .= '</span>';
1.330 bisitz 10211:
1.160 raeburn 10212: if ($srch->{'srchin'} ne 'alc') {
10213: $forcenewuser = 1;
10214: my $cansrchinst = 0;
1.438 raeburn 10215: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 10216: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
10217: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10218: if ($domconfig{'directorysrch'}{'available'}) {
10219: $cansrchinst = 1;
10220: }
10221: }
10222: }
1.180 raeburn 10223: if ((($srch->{'srchby'} eq 'lastfirst') ||
10224: ($srch->{'srchby'} eq 'lastname')) &&
10225: ($srch->{'srchin'} eq 'dom')) {
10226: if ($cansrchinst) {
10227: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 10228: }
10229: }
1.180 raeburn 10230: if ($srch->{'srchin'} eq 'crs') {
10231: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
10232: }
10233: }
1.305 raeburn 10234: my $createdom = $env{'request.role.domain'};
10235: if ($context eq 'requestcrs') {
10236: if ($env{'form.coursedom'} ne '') {
10237: $createdom = $env{'form.coursedom'};
10238: }
10239: }
1.416 raeburn 10240: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
10241: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 10242: my $cancreate =
1.305 raeburn 10243: &Apache::lonuserutils::can_create_user($createdom,$context);
10244: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 10245: if ($cancreate) {
1.305 raeburn 10246: my $showdom = &display_domain_info($createdom);
1.266 bisitz 10247: $response .= '<br /><br />'
10248: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 10249: .'<br />';
10250: if ($context eq 'requestcrs') {
10251: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
10252: } else {
10253: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
10254: }
10255: $response .='<ul><li>'
1.266 bisitz 10256: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
10257: .'</li><li>'
10258: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
10259: .'</li><li>'
10260: .&mt('Provide the proposed username')
10261: .'</li><li>'
10262: .&mt("Click 'Search'")
10263: .'</li></ul><br />';
1.221 raeburn 10264: } else {
1.422 raeburn 10265: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
10266: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
10267: $response .= '<br /><br />';
10268: if ($context eq 'requestcrs') {
10269: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
10270: } else {
10271: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
10272: }
10273: $response .= '<br />'
10274: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
10275: ,' <a'.$helplink.'>'
10276: ,'</a>')
10277: .'<br />';
1.305 raeburn 10278: }
1.221 raeburn 10279: }
1.160 raeburn 10280: }
10281: }
10282: }
1.179 raeburn 10283: return ($currstate,$response,$forcenewuser);
1.160 raeburn 10284: }
10285:
1.180 raeburn 10286: sub display_domain_info {
10287: my ($dom) = @_;
10288: my $output = $dom;
10289: if ($dom ne '') {
10290: my $domdesc = &Apache::lonnet::domain($dom,'description');
10291: if ($domdesc ne '') {
10292: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
10293: }
10294: }
10295: return $output;
10296: }
10297:
1.160 raeburn 10298: sub crumb_utilities {
10299: my %elements = (
10300: crtuser => {
10301: srchterm => 'text',
1.172 raeburn 10302: srchin => 'selectbox',
1.160 raeburn 10303: srchby => 'selectbox',
10304: srchtype => 'selectbox',
10305: srchdomain => 'selectbox',
10306: },
1.207 raeburn 10307: crtusername => {
10308: srchterm => 'text',
10309: srchdomain => 'selectbox',
10310: },
1.160 raeburn 10311: docustom => {
10312: rolename => 'selectbox',
10313: newrolename => 'textbox',
10314: },
1.179 raeburn 10315: studentform => {
10316: srchterm => 'text',
10317: srchin => 'selectbox',
10318: srchby => 'selectbox',
10319: srchtype => 'selectbox',
10320: srchdomain => 'selectbox',
10321: },
1.160 raeburn 10322: );
10323:
10324: my $jsback .= qq|
10325: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 10326: if (typeof prevphase == 'undefined') {
10327: formname.phase.value = '';
10328: }
10329: else {
10330: formname.phase.value = prevphase;
10331: }
10332: if (typeof prevstate == 'undefined') {
10333: formname.currstate.value = '';
10334: }
10335: else {
10336: formname.currstate.value = prevstate;
10337: }
1.160 raeburn 10338: formname.submit();
10339: }
10340: |;
10341: return ($jsback,\%elements);
10342: }
10343:
1.26 matthew 10344: sub course_level_table {
1.375 raeburn 10345: my ($inccourses,$showcredits,$defaultcredits) = @_;
10346: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 10347: my $table = '';
1.62 www 10348: # Custom Roles?
10349:
1.190 raeburn 10350: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 10351: my %lt=&Apache::lonlocal::texthash(
10352: 'exs' => "Existing sections",
10353: 'new' => "Define new section",
10354: 'ssd' => "Set Start Date",
10355: 'sed' => "Set End Date",
1.131 raeburn 10356: 'crl' => "Course Level",
1.89 raeburn 10357: 'act' => "Activate",
10358: 'rol' => "Role",
10359: 'ext' => "Extent",
1.113 raeburn 10360: 'grs' => "Section",
1.375 raeburn 10361: 'crd' => "Credits",
1.89 raeburn 10362: 'sta' => "Start",
10363: 'end' => "End"
10364: );
1.62 www 10365:
1.375 raeburn 10366: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 10367: my $thiscourse=$protectedcourse;
1.26 matthew 10368: $thiscourse=~s:_:/:g;
10369: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 10370: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 10371: my $area=$coursedata{'description'};
1.321 raeburn 10372: my $crstype=$coursedata{'type'};
1.135 raeburn 10373: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 10374: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 10375: my %sections_count;
1.101 albertel 10376: if (defined($env{'request.course.id'})) {
10377: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 10378: %sections_count =
10379: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 10380: }
10381: }
1.321 raeburn 10382: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 10383: foreach my $role (@roles) {
1.321 raeburn 10384: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 10385: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
10386: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 10387: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 10388: $plrole,\%sections_count,\%lt,
1.402 raeburn 10389: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 10390: } elsif ($env{'request.course.sec'} ne '') {
10391: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
10392: $env{'request.course.sec'})) {
10393: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 10394: $plrole,\%sections_count,\%lt,
1.402 raeburn 10395: $showcredits,$defaultcredits,$crstype);
1.26 matthew 10396: }
10397: }
10398: }
1.221 raeburn 10399: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 10400: foreach my $cust (sort(keys(%customroles))) {
10401: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 10402: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
10403: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 10404: $cust,\%sections_count,\%lt,
10405: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 10406: }
1.62 www 10407: }
1.26 matthew 10408: }
10409: return '' if ($table eq ''); # return nothing if there is nothing
10410: # in the table
1.188 raeburn 10411: my $result;
10412: if (!$env{'request.course.id'}) {
10413: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
10414: }
10415: $result .=
1.136 raeburn 10416: &Apache::loncommon::start_data_table().
10417: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 10418: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 10419: '<th>'.$lt{'ext'}.'</th><th>'."\n";
10420: if ($showcredits) {
10421: $result .= $lt{'crd'}.'</th>';
10422: }
10423: $result .=
1.375 raeburn 10424: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
10425: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 10426: &Apache::loncommon::end_data_table_header_row().
10427: $table.
10428: &Apache::loncommon::end_data_table();
1.26 matthew 10429: return $result;
10430: }
1.88 raeburn 10431:
1.221 raeburn 10432: sub course_level_row {
1.375 raeburn 10433: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 10434: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 10435: my $creditem;
1.222 raeburn 10436: my $row = &Apache::loncommon::start_data_table_row().
10437: ' <td><input type="checkbox" name="act_'.
10438: $protectedcourse.'_'.$role.'" /></td>'."\n".
10439: ' <td>'.$plrole.'</td>'."\n".
10440: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 10441: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 10442: $row .=
10443: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
10444: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
10445: } else {
10446: $row .= '<td> </td>';
10447: }
1.322 raeburn 10448: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 10449: $row .= '<td> </td>';
1.221 raeburn 10450: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 10451: $row .= ' <td><input type="hidden" value="'.
10452: $env{'request.course.sec'}.'" '.
10453: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
10454: $env{'request.course.sec'}.'</td>';
1.221 raeburn 10455: } else {
10456: if (ref($sections_count) eq 'HASH') {
10457: my $currsec =
10458: &Apache::lonuserutils::course_sections($sections_count,
10459: $protectedcourse.'_'.$role);
1.222 raeburn 10460: $row .= '<td><table class="LC_createuser">'."\n".
10461: '<tr class="LC_section_row">'."\n".
10462: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
10463: $currsec.'</td>'."\n".
10464: ' <td> </td>'."\n".
10465: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 10466: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
10467: '" value="" />'.
10468: '<input type="hidden" '.
10469: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 10470: '</tr></table></td>'."\n";
1.221 raeburn 10471: } else {
1.222 raeburn 10472: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 10473: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 10474: }
10475: }
1.222 raeburn 10476: $row .= <<ENDTIMEENTRY;
10477: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 10478: <a href=
10479: "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 10480: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 10481: <a href=
10482: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
10483: ENDTIMEENTRY
1.222 raeburn 10484: $row .= &Apache::loncommon::end_data_table_row();
10485: return $row;
1.221 raeburn 10486: }
10487:
1.88 raeburn 10488: sub course_level_dc {
1.375 raeburn 10489: my ($dcdom,$showcredits) = @_;
1.190 raeburn 10490: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 10491: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 10492: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
10493: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 10494: '<input type="hidden" name="dccourse" value="" />';
1.355 www 10495: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 10496: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 10497: my $credit_elem;
10498: if ($showcredits) {
10499: $credit_elem = 'credits';
10500: }
10501: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 10502: my %lt=&Apache::lonlocal::texthash(
10503: 'rol' => "Role",
1.113 raeburn 10504: 'grs' => "Section",
1.88 raeburn 10505: 'exs' => "Existing sections",
10506: 'new' => "Define new section",
10507: 'sta' => "Start",
10508: 'end' => "End",
10509: 'ssd' => "Set Start Date",
1.355 www 10510: 'sed' => "Set End Date",
1.375 raeburn 10511: 'scc' => "Course/Community",
10512: 'crd' => "Credits",
1.88 raeburn 10513: );
1.323 raeburn 10514: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 10515: &Apache::loncommon::start_data_table().
10516: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 10517: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 10518: '<th>'.$lt{'grs'}.'</th>'."\n";
10519: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
10520: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 10521: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 10522: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 10523: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
10524: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 10525: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 10526: foreach my $role (@roles) {
1.135 raeburn 10527: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 10528: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 10529: }
1.404 raeburn 10530: if ( keys(%customroles) > 0) {
10531: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 10532: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 10533: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 10534: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 10535: }
10536: }
10537: $otheritems .= '</select></td><td>'.
10538: '<table border="0" cellspacing="0" cellpadding="0">'.
10539: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 10540: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 10541: '<td> </td>'.
10542: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 10543: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 10544: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 10545: '<input type="hidden" name="groups" value="" />'.
10546: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 10547: '</tr></table></td>'."\n";
10548: if ($showcredits) {
10549: $otheritems .= '<td><br />'."\n".
1.397 bisitz 10550: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 10551: }
1.88 raeburn 10552: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 10553: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 10554: <a href=
10555: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 10556: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 10557: <a href=
10558: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
10559: ENDTIMEENTRY
1.136 raeburn 10560: $otheritems .= &Apache::loncommon::end_data_table_row().
10561: &Apache::loncommon::end_data_table()."\n";
1.470 raeburn 10562: return $cb_jscript.$hiddenitems.$header.$otheritems;
1.88 raeburn 10563: }
10564:
1.237 raeburn 10565: sub update_selfenroll_config {
1.400 raeburn 10566: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 10567: return unless (ref($currsettings) eq 'HASH');
10568: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
10569: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 10570: my (%changes,%warning);
1.241 raeburn 10571: my $curr_types;
1.400 raeburn 10572: my %noedit;
10573: unless ($context eq 'domain') {
10574: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
10575: }
1.237 raeburn 10576: if (ref($row) eq 'ARRAY') {
10577: foreach my $item (@{$row}) {
1.400 raeburn 10578: next if ($noedit{$item});
1.237 raeburn 10579: if ($item eq 'enroll_dates') {
10580: my (%currenrolldate,%newenrolldate);
10581: foreach my $type ('start','end') {
1.398 raeburn 10582: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 10583: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
10584: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
10585: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
10586: }
10587: }
10588: } elsif ($item eq 'access_dates') {
10589: my (%currdate,%newdate);
10590: foreach my $type ('start','end') {
1.398 raeburn 10591: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 10592: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
10593: if ($newdate{$type} ne $currdate{$type}) {
10594: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
10595: }
10596: }
1.241 raeburn 10597: } elsif ($item eq 'types') {
1.398 raeburn 10598: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 10599: if ($env{'form.selfenroll_all'}) {
10600: if ($curr_types ne '*') {
10601: $changes{'internal.selfenroll_types'} = '*';
10602: } else {
10603: next;
10604: }
10605: } else {
1.249 raeburn 10606: my %currdoms;
1.241 raeburn 10607: my @entries = split(/;/,$curr_types);
10608: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 10609: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 10610: my $newnum = 0;
1.249 raeburn 10611: my @latesttypes;
10612: foreach my $num (@activations) {
10613: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
10614: if (@types > 0) {
1.241 raeburn 10615: @types = sort(@types);
10616: my $typestr = join(',',@types);
1.249 raeburn 10617: my $typedom = $env{'form.selfenroll_dom_'.$num};
10618: $latesttypes[$newnum] = $typedom.':'.$typestr;
10619: $currdoms{$typedom} = 1;
1.241 raeburn 10620: $newnum ++;
10621: }
10622: }
1.338 raeburn 10623: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
10624: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 10625: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
10626: if (@types > 0) {
10627: @types = sort(@types);
10628: my $typestr = join(',',@types);
10629: my $typedom = $env{'form.selfenroll_dom_'.$j};
10630: $latesttypes[$newnum] = $typedom.':'.$typestr;
10631: $currdoms{$typedom} = 1;
10632: $newnum ++;
10633: }
10634: }
10635: }
10636: if ($env{'form.selfenroll_newdom'} ne '') {
10637: my $typedom = $env{'form.selfenroll_newdom'};
10638: if ((!defined($currdoms{$typedom})) &&
10639: (&Apache::lonnet::domain($typedom) ne '')) {
10640: my $typestr;
10641: my ($othertitle,$usertypes,$types) =
10642: &Apache::loncommon::sorted_inst_types($typedom);
10643: my $othervalue = 'any';
10644: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
10645: if (@{$types} > 0) {
1.257 raeburn 10646: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 10647: $othervalue = 'other';
1.258 raeburn 10648: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 10649: }
10650: $typestr = $othervalue;
10651: } else {
10652: $typestr = $othervalue;
10653: }
10654: $latesttypes[$newnum] = $typedom.':'.$typestr;
10655: $newnum ++ ;
10656: }
10657: }
1.241 raeburn 10658: my $selfenroll_types = join(';',@latesttypes);
10659: if ($selfenroll_types ne $curr_types) {
10660: $changes{'internal.selfenroll_types'} = $selfenroll_types;
10661: }
10662: }
1.276 raeburn 10663: } elsif ($item eq 'limit') {
10664: my $newlimit = $env{'form.selfenroll_limit'};
10665: my $newcap = $env{'form.selfenroll_cap'};
10666: $newcap =~s/\s+//g;
1.398 raeburn 10667: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 10668: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 10669: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 10670: if ($newlimit ne $currlimit) {
10671: if ($newlimit ne 'none') {
10672: if ($newcap =~ /^\d+$/) {
10673: if ($newcap ne $currcap) {
10674: $changes{'internal.selfenroll_cap'} = $newcap;
10675: }
10676: $changes{'internal.selfenroll_limit'} = $newlimit;
10677: } else {
1.398 raeburn 10678: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
10679: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 10680: }
10681: } elsif ($currcap ne '') {
10682: $changes{'internal.selfenroll_cap'} = '';
10683: $changes{'internal.selfenroll_limit'} = $newlimit;
10684: }
10685: } elsif ($currlimit ne 'none') {
10686: if ($newcap =~ /^\d+$/) {
10687: if ($newcap ne $currcap) {
10688: $changes{'internal.selfenroll_cap'} = $newcap;
10689: }
10690: } else {
1.398 raeburn 10691: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
10692: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 10693: }
10694: }
10695: } elsif ($item eq 'approval') {
10696: my (@currnotified,@newnotified);
1.398 raeburn 10697: my $currapproval = $currsettings->{'selfenroll_approval'};
10698: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 10699: if ($currnotifylist ne '') {
10700: @currnotified = split(/,/,$currnotifylist);
10701: @currnotified = sort(@currnotified);
10702: }
10703: my $newapproval = $env{'form.selfenroll_approval'};
10704: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
10705: @newnotified = sort(@newnotified);
10706: if ($newapproval ne $currapproval) {
10707: $changes{'internal.selfenroll_approval'} = $newapproval;
10708: if (!$newapproval) {
10709: if ($currnotifylist ne '') {
10710: $changes{'internal.selfenroll_notifylist'} = '';
10711: }
10712: } else {
10713: my @differences =
1.295 raeburn 10714: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 10715: if (@differences > 0) {
10716: if (@newnotified > 0) {
10717: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10718: } else {
10719: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10720: }
10721: }
10722: }
10723: } else {
1.295 raeburn 10724: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 10725: if (@differences > 0) {
10726: if (@newnotified > 0) {
10727: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10728: } else {
10729: $changes{'internal.selfenroll_notifylist'} = '';
10730: }
10731: }
10732: }
1.237 raeburn 10733: } else {
1.398 raeburn 10734: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 10735: my $newval = $env{'form.selfenroll_'.$item};
10736: if ($item eq 'section') {
10737: $newval = $env{'form.sections'};
1.241 raeburn 10738: if (defined($curr_groups{$newval})) {
1.237 raeburn 10739: $newval = $curr_val;
1.398 raeburn 10740: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
10741: &mt('Group names and section names must be distinct');
1.237 raeburn 10742: } elsif ($newval eq 'all') {
10743: $newval = $curr_val;
1.274 bisitz 10744: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 10745: }
10746: if ($newval eq '') {
10747: $newval = 'none';
10748: }
10749: }
10750: if ($newval ne $curr_val) {
10751: $changes{'internal.selfenroll_'.$item} = $newval;
10752: }
1.241 raeburn 10753: }
1.237 raeburn 10754: }
10755: if (keys(%warning) > 0) {
10756: foreach my $item (@{$row}) {
10757: if (exists($warning{$item})) {
10758: $r->print($warning{$item}.'<br />');
10759: }
10760: }
10761: }
10762: if (keys(%changes) > 0) {
10763: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
10764: if ($putresult eq 'ok') {
10765: if ((exists($changes{'internal.selfenroll_types'})) ||
10766: (exists($changes{'internal.selfenroll_start_date'})) ||
10767: (exists($changes{'internal.selfenroll_end_date'}))) {
10768: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
10769: $cnum,undef,undef,'Course');
10770: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 10771: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 10772: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
10773: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 10774: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 10775: }
10776: }
10777: my $crsputresult =
10778: &Apache::lonnet::courseidput($cdom,\%crsinfo,
10779: $chome,'notime');
10780: }
10781: }
10782: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
10783: foreach my $item (@{$row}) {
10784: my $title = $item;
10785: if (ref($lt) eq 'HASH') {
10786: $title = $lt->{$item};
10787: }
10788: if ($item eq 'enroll_dates') {
10789: foreach my $type ('start','end') {
10790: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
10791: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 10792: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 10793: $title,$type,$newdate).'</li>');
10794: }
10795: }
10796: } elsif ($item eq 'access_dates') {
10797: foreach my $type ('start','end') {
10798: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
10799: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 10800: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 10801: $title,$type,$newdate).'</li>');
10802: }
10803: }
1.276 raeburn 10804: } elsif ($item eq 'limit') {
10805: if ((exists($changes{'internal.selfenroll_limit'})) ||
10806: (exists($changes{'internal.selfenroll_cap'}))) {
10807: my ($newval,$newcap);
10808: if ($changes{'internal.selfenroll_cap'} ne '') {
10809: $newcap = $changes{'internal.selfenroll_cap'}
10810: } else {
1.398 raeburn 10811: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 10812: }
10813: if ($changes{'internal.selfenroll_limit'} eq 'none') {
10814: $newval = &mt('No limit');
10815: } elsif ($changes{'internal.selfenroll_limit'} eq
10816: 'allstudents') {
10817: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
10818: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
10819: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
10820: } else {
1.398 raeburn 10821: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 10822: if ($currlimit eq 'allstudents') {
10823: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
10824: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 10825: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 10826: }
10827: }
10828: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
10829: }
10830: } elsif ($item eq 'approval') {
10831: if ((exists($changes{'internal.selfenroll_approval'})) ||
10832: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 10833: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 10834: my ($newval,$newnotify);
10835: if (exists($changes{'internal.selfenroll_notifylist'})) {
10836: $newnotify = $changes{'internal.selfenroll_notifylist'};
10837: } else {
1.398 raeburn 10838: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 10839: }
1.398 raeburn 10840: if (exists($changes{'internal.selfenroll_approval'})) {
10841: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
10842: $changes{'internal.selfenroll_approval'} = '0';
10843: }
10844: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 10845: } else {
1.398 raeburn 10846: my $currapproval = $currsettings->{'selfenroll_approval'};
10847: if ($currapproval !~ /^[012]$/) {
10848: $currapproval = 0;
1.276 raeburn 10849: }
1.398 raeburn 10850: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 10851: }
10852: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
10853: if ($newnotify) {
1.277 raeburn 10854: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 10855: } else {
1.277 raeburn 10856: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 10857: }
10858: $r->print('</li>'."\n");
10859: }
1.237 raeburn 10860: } else {
10861: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 10862: my $newval = $changes{'internal.selfenroll_'.$item};
10863: if ($item eq 'types') {
10864: if ($newval eq '') {
10865: $newval = &mt('None');
10866: } elsif ($newval eq '*') {
10867: $newval = &mt('Any user in any domain');
10868: }
1.245 raeburn 10869: } elsif ($item eq 'registered') {
10870: if ($newval eq '1') {
10871: $newval = &mt('Yes');
10872: } elsif ($newval eq '0') {
10873: $newval = &mt('No');
10874: }
1.241 raeburn 10875: }
1.244 bisitz 10876: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 10877: }
10878: }
10879: }
10880: $r->print('</ul>');
1.398 raeburn 10881: if ($env{'course.'.$cid.'.description'} ne '') {
10882: my %newenvhash;
10883: foreach my $key (keys(%changes)) {
10884: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
10885: }
10886: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 10887: }
10888: } else {
1.398 raeburn 10889: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
10890: &mt('The error was: [_1].',$putresult));
1.237 raeburn 10891: }
10892: } else {
1.249 raeburn 10893: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 10894: }
10895: } else {
1.249 raeburn 10896: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 10897: }
1.469 raeburn 10898: my $visactions = &cat_visibility($cdom);
1.400 raeburn 10899: my ($cathash,%cattype);
10900: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
10901: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
10902: $cathash = $domconfig{'coursecategories'}{'cats'};
10903: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
10904: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
10905: } else {
10906: $cathash = {};
10907: $cattype{'auth'} = 'std';
10908: $cattype{'unauth'} = 'std';
10909: }
10910: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
10911: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
10912: '<br />'.
10913: '<br />'.$visactions->{'take'}.'<ul>'.
10914: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
10915: '</ul>');
10916: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
10917: if ($currsettings->{'uniquecode'}) {
10918: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
10919: } else {
1.366 bisitz 10920: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 10921: '<br />'.
10922: '<br />'.$visactions->{'take'}.'<ul>'.
10923: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
10924: '</ul><br />');
10925: }
10926: } else {
10927: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
10928: if (ref($visactions) eq 'HASH') {
10929: if (!$visible) {
10930: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
10931: '<br />');
10932: if (ref($vismsgs) eq 'ARRAY') {
10933: $r->print('<br />'.$visactions->{'take'}.'<ul>');
10934: foreach my $item (@{$vismsgs}) {
10935: $r->print('<li>'.$visactions->{$item}.'</li>');
10936: }
10937: $r->print('</ul>');
1.256 raeburn 10938: }
1.400 raeburn 10939: $r->print($cansetvis);
1.256 raeburn 10940: }
10941: }
10942: }
1.237 raeburn 10943: return;
10944: }
10945:
1.27 matthew 10946: #---------------------------------------------- end functions for &phase_two
1.29 matthew 10947:
10948: #--------------------------------- functions for &phase_two and &phase_three
10949:
10950: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 10951:
1.1 www 10952: 1;
10953: __END__
1.2 www 10954:
10955:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>