Annotation of loncom/interface/loncreateuser.pm, revision 1.474
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.474 ! raeburn 4: # $Id: loncreateuser.pm,v 1.473 2023/11/05 20:06:04 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;
248: for (var i=0; i<radioname.length; i++) {
249: if (radioname[i].checked == true) {
250: if (radioname[i].value == 1) {
251: divid.style.display = 'block';
252: setvis = 1;
253: }
254: break;
255: }
256: }
257: if (!setvis) {
258: divid.style.display = 'none';
1.378 raeburn 259: }
260: }
261: }
1.470 raeburn 262: }
263: return;
264: }
265: // ]]>
266: </script>
267:
268: END_SCRIPT
1.378 raeburn 269:
1.134 raeburn 270: }
271:
1.275 raeburn 272: sub build_tools_display {
273: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 274: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.470 raeburn 275: $colspan,$isadv,%domconfig,@defaulteditors,@customeditors,@custommanagers,
276: @possmanagers,$editorsty,$customsty);
1.275 raeburn 277: my %lt = &Apache::lonlocal::texthash (
278: 'blog' => "Personal User Blog",
279: 'aboutme' => "Personal Information Page",
1.470 raeburn 280: 'webdav' => "WebDAV access to Authoring Spaces (https)",
281: 'editors' => "Available Editors",
1.473 raeburn 282: 'managers' => "Co-authors who can add/revoke roles",
1.275 raeburn 283: 'portfolio' => "Personal User Portfolio",
1.470 raeburn 284: 'portaccess' => "Portfolio Shareable",
1.459 raeburn 285: 'timezone' => "Can set Time Zone",
1.275 raeburn 286: 'avai' => "Available",
287: 'cusa' => "availability",
288: 'chse' => "Change setting",
289: 'usde' => "Use default",
290: 'uscu' => "Use custom",
291: 'official' => 'Can request creation of official courses',
1.299 raeburn 292: 'unofficial' => 'Can request creation of unofficial courses',
293: 'community' => 'Can request creation of communities',
1.384 raeburn 294: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 295: 'placement' => 'Can request creation of placement tests',
1.449 raeburn 296: 'lti' => 'Can request creation of LTI courses',
1.362 raeburn 297: 'requestauthor' => 'Can request author space',
1.470 raeburn 298: 'edit' => 'Standard editor (Edit)',
299: 'xml' => 'Text editor (EditXML)',
300: 'daxe' => 'Daxe editor (Daxe)',
1.275 raeburn 301: );
1.462 raeburn 302: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.279 raeburn 303: if ($context eq 'requestcourses') {
1.275 raeburn 304: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 305: 'requestcourses.official','requestcourses.unofficial',
1.411 raeburn 306: 'requestcourses.community','requestcourses.textbook',
1.449 raeburn 307: 'requestcourses.placement','requestcourses.lti');
308: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.309 raeburn 309: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 310: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
311: %reqtitles = &courserequest_titles();
312: %reqdisplay = &courserequest_display();
1.332 raeburn 313: %domconfig =
314: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.362 raeburn 315: } elsif ($context eq 'requestauthor') {
1.470 raeburn 316: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,'requestauthor');
1.362 raeburn 317: @usertools = ('requestauthor');
318: @options =('norequest','approval','automatic');
319: %reqtitles = &requestauthor_titles();
320: %reqdisplay = &requestauthor_display();
321: %domconfig =
322: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.470 raeburn 323: } elsif ($context eq 'authordefaults') {
324: %domconfig =
325: &Apache::lonnet::get_dom('configuration',['quotas','authordefaults'],$ccdomain);
326: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,'tools.webdav',
1.471 raeburn 327: 'authoreditors','authormanagers',
328: 'domcoord.author');
1.470 raeburn 329: @usertools = ('webdav','editors','managers');
330: $colspan = ' colspan="2"';
1.275 raeburn 331: } else {
332: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 333: 'tools.aboutme','tools.portfolio','tools.blog',
1.470 raeburn 334: 'tools.timezone','tools.portaccess');
335: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
336: $colspan = ' colspan="2"';
1.275 raeburn 337: }
338: foreach my $item (@usertools) {
1.306 raeburn 339: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
1.470 raeburn 340: $currdisp,$custdisp,$custradio,$onclick);
1.275 raeburn 341: $cust_off = 'checked="checked" ';
342: $tool_on = 'checked="checked" ';
1.474 ! raeburn 343: unless (($context eq 'authordefaults') && ($item ne 'webdav')) {
! 344: $curr_access =
! 345: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
! 346: $context,\%userenv,'',
! 347: {'is_adv' => $isadv});
! 348: }
1.362 raeburn 349: if ($context eq 'requestauthor') {
350: if ($userenv{$context} ne '') {
351: $cust_on = ' checked="checked" ';
352: $cust_off = '';
1.470 raeburn 353: }
354: } elsif ($context eq 'authordefaults') {
355: if ($item eq 'editors') {
356: if ($userenv{'author'.$item} ne '') {
357: $cust_on = ' checked="checked" ';
358: $cust_off = '';
359: }
360: } elsif ($item eq 'webdav') {
361: if ($userenv{'tools.'.$item} ne '') {
362: $cust_on = ' checked="checked" ';
363: $cust_off = '';
364: }
365: }
1.362 raeburn 366: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 367: $cust_on = ' checked="checked" ';
368: $cust_off = '';
369: }
370: if ($context eq 'requestcourses') {
371: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 372: $custom_access = &mt('Currently from default setting.');
1.470 raeburn 373: $customsty = ' style="display:none;"';
1.306 raeburn 374: } else {
375: $custom_access = &mt('Currently from custom setting.');
1.470 raeburn 376: $customsty = ' style="display:block;"';
1.275 raeburn 377: }
1.362 raeburn 378: } elsif ($context eq 'requestauthor') {
379: if ($userenv{$context} eq '') {
380: $custom_access = &mt('Currently from default setting.');
1.470 raeburn 381: $customsty = ' style="display:none;"';
382: } else {
383: $custom_access = &mt('Currently from custom setting.');
384: $customsty = ' style="display:block;"';
385: }
386: } elsif ($item eq 'editors') {
387: if ($userenv{'author'.$item} eq '') {
388: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
389: @defaulteditors = @{$domconfig{'authordefaults'}{'editors'}};
390: } else {
391: @defaulteditors = ('edit','xml');
392: }
393: $custom_access = &mt('Can use: [_1]',
394: join(', ', map { $lt{$_} } @defaulteditors));
395: $editorsty = ' style="display:none;"';
1.362 raeburn 396: } else {
397: $custom_access = &mt('Currently from custom setting.');
1.470 raeburn 398: foreach my $editor (split(/,/,$userenv{'author'.$item})) {
399: if ($editor =~ /^(edit|daxe|xml)$/) {
400: push(@customeditors,$editor);
401: }
402: }
403: if (@customeditors) {
404: if (@customeditors > 1) {
405: $custom_access .= '<br /><span>';
406: } else {
407: $custom_access .= ' <span class="LC_nobreak">';
408: }
409: $custom_access .= &mt('Can use: [_1]',
410: join(', ', map { $lt{$_} } @customeditors)).
411: '</span>';
412: } else {
413: $custom_access .= ' '.&mt('No available editors');
414: }
415: $editorsty = ' style="display:block;"';
416: }
417: } elsif ($item eq 'managers') {
418: my %ca_roles = &Apache::lonnet::get_my_roles($ccuname,$ccdomain,undef,
419: ['active','future'],['ca']);
420: if (keys(%ca_roles)) {
421: foreach my $entry (sort(keys(%ca_roles))) {
422: if ($entry =~ /^($match_username\:$match_domain):ca$/) {
423: my $user = $1;
424: unless ($user eq "$ccuname:$ccdomain") {
425: push(@possmanagers,$user);
426: }
427: }
428: }
429: }
430: if ($userenv{'author'.$item} eq '') {
431: $custom_access = &mt('Currently author manages co-author roles');
432: } else {
433: if (keys(%ca_roles)) {
434: foreach my $user (split(/,/,$userenv{'author'.$item})) {
435: if ($user =~ /^($match_username):($match_domain)$/) {
436: if (exists($ca_roles{$user.':ca'})) {
437: unless ($user eq "$ccuname:$ccdomain") {
438: push(@custommanagers,$user);
439: }
440: }
441: }
442: }
443: }
444: if (@custommanagers) {
445: $custom_access = &mt('Co-authors who manage co-author roles: [_1]',
446: join(', ',@custommanagers));
447: } else {
448: $custom_access = &mt('Currently author manages co-author roles');
449: }
1.362 raeburn 450: }
1.275 raeburn 451: } else {
1.470 raeburn 452: my $current = $userenv{$context.'.'.$item};
453: if ($item eq 'webdav') {
454: $current = $userenv{'tools.webdav'};
455: }
456: if ($current eq '') {
1.314 raeburn 457: $custom_access =
1.306 raeburn 458: &mt('Availability determined currently from default setting.');
459: if (!$curr_access) {
460: $tool_off = 'checked="checked" ';
461: $tool_on = '';
462: }
1.470 raeburn 463: $customsty = ' style="display:none;"';
1.306 raeburn 464: } else {
1.314 raeburn 465: $custom_access =
1.306 raeburn 466: &mt('Availability determined currently from custom setting.');
1.470 raeburn 467: if ($current == 0) {
1.306 raeburn 468: $tool_off = 'checked="checked" ';
469: $tool_on = '';
470: }
1.470 raeburn 471: $customsty = ' style="display:inline;"';
1.275 raeburn 472: }
473: }
474: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 475: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 476: ' </tr>'."\n".
1.306 raeburn 477: &Apache::loncommon::start_data_table_row()."\n";
1.362 raeburn 478: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.470 raeburn 479: my ($curroption,$currlimit,$customsty);
1.362 raeburn 480: my $envkey = $context.'.'.$item;
481: if ($context eq 'requestauthor') {
482: $envkey = $context;
483: }
484: if ($userenv{$envkey} ne '') {
485: $curroption = $userenv{$envkey};
1.470 raeburn 486: $customsty = ' style="display:block"';
1.332 raeburn 487: } else {
1.470 raeburn 488: $customsty = ' style="display:none"';
1.332 raeburn 489: my (@inststatuses);
1.362 raeburn 490: if ($context eq 'requestcourses') {
491: $curroption =
492: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
493: $isadv,$ccdomain,$item,
494: \@inststatuses,\%domconfig);
495: } else {
496: $curroption =
497: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
498: $isadv,$ccdomain,undef,
499: \@inststatuses,\%domconfig);
500: }
1.332 raeburn 501: }
1.306 raeburn 502: if (!$curroption) {
503: $curroption = 'norequest';
504: }
1.470 raeburn 505: my $name = 'crsreq_'.$item;
506: if ($context eq 'requestauthor') {
507: $name = $item;
508: }
509: $onclick = ' onclick="javascript:toggleCustom(this.form,'."'customtext_$item','custom$item'".');"';
1.306 raeburn 510: if ($curroption =~ /^autolimit=(\d*)$/) {
511: $currlimit = $1;
1.314 raeburn 512: if ($currlimit eq '') {
513: $currdisp = &mt('Yes, automatic creation');
514: } else {
515: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
516: }
1.306 raeburn 517: } else {
518: $currdisp = $reqdisplay{$curroption};
519: }
1.470 raeburn 520: $custdisp = '<fieldset id="customtext_'.$item.'"'.$customsty.'>';
1.306 raeburn 521: foreach my $option (@options) {
522: my $val = $option;
523: if ($option eq 'norequest') {
524: $val = 0;
525: }
526: if ($option eq 'validate') {
527: my $canvalidate = 0;
528: if (ref($validations{$item}) eq 'HASH') {
529: if ($validations{$item}{'_custom_'}) {
530: $canvalidate = 1;
531: }
532: }
533: next if (!$canvalidate);
534: }
535: my $checked = '';
536: if ($option eq $curroption) {
537: $checked = ' checked="checked"';
538: } elsif ($option eq 'autolimit') {
539: if ($curroption =~ /^autolimit/) {
540: $checked = ' checked="checked"';
541: }
542: }
1.470 raeburn 543: if ($option eq 'autolimit') {
544: $custdisp .= '<br />';
1.362 raeburn 545: }
1.470 raeburn 546: $custdisp .= '<span class="LC_nobreak"><label>'.
1.362 raeburn 547: '<input type="radio" name="'.$name.'" '.
548: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 549: $reqtitles{$option}.'</label> ';
550: if ($option eq 'autolimit') {
1.362 raeburn 551: $custdisp .= '<input type="text" name="'.$name.
552: '_limit" size="1" '.
1.470 raeburn 553: 'value="'.$currlimit.'" /> '.
554: $reqtitles{'unlimited'}.'</span>';
1.362 raeburn 555: } else {
556: $custdisp .= '</span>';
557: }
1.470 raeburn 558: $custdisp .= ' ';
559: }
560: $custdisp .= '</fieldset>';
561: $custradio = '<br />'.$custdisp;
562: } elsif ($item eq 'editors') {
563: $output .= '<td'.$colspan.'>'.$custom_access.'</td>'."\n".
564: &Apache::loncommon::end_data_table_row()."\n";
565: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
566: $output .= &Apache::loncommon::start_data_table_row()."\n".
567: '<td'.$colspan.'><span class="LC_nobreak">'.
568: $lt{'chse'}.': <label>'.
569: '<input type="radio" name="custom'.$item.'" value="0" '.
570: $cust_off.' onclick="toggleCustom(this.form,'."'customtext_$item','custom$item'".');" />'.
571: $lt{'usde'}.'</label>'.(' ' x3).
572: '<label><input type="radio" name="custom'.$item.'" value="1" '.
573: $cust_on.' onclick="toggleCustom(this.form,'."'customtext_$item','custom$item'".');" />'.
574: $lt{'uscu'}.'</label></span><br />'.
575: '<fieldset id="customtext_'.$item.'"'.$editorsty.'>';
576: foreach my $editor ('edit','xml','daxe') {
577: my $checked;
578: if ($userenv{'author'.$item} eq '') {
579: if (grep(/^\Q$editor\E$/,@defaulteditors)) {
580: $checked = ' checked="checked"';
581: }
582: } elsif (grep(/^\Q$editor\E$/,@customeditors)) {
583: $checked = ' checked="checked"';
584: }
585: $output .= '<span style="LC_nobreak"><label>'.
586: '<input type="checkbox" name="custom_editor" '.
587: 'value="'.$editor.'"'.$checked.' />'.
588: $lt{$editor}.'</label></span> ';
589: }
590: $output .= '</fieldset></td>'.
591: &Apache::loncommon::end_data_table_row()."\n";
592: }
593: } elsif ($item eq 'managers') {
594: $output .= '<td'.$colspan.'>'.$custom_access.'</td>'."\n".
595: &Apache::loncommon::end_data_table_row()."\n";
1.471 raeburn 596: unless ((&Apache::lonnet::allowed('udp',$ccdomain)) ||
597: (($userenv{'domcoord.author'} eq 'blocked') &&
598: (($env{'user.name'} ne $ccuname) || ($env{'user.domain'} ne $ccdomain)))) {
1.470 raeburn 599: $output .=
600: &Apache::loncommon::start_data_table_row()."\n".
601: '<td'.$colspan.'>';
602: if (@possmanagers) {
603: $output .= &mt('Select manager(s)').': ';
604: foreach my $user (@possmanagers) {
605: my $checked;
606: if (grep(/^\Q$user\E$/,@custommanagers)) {
607: $checked = ' checked="checked"';
608: }
609: $output .= '<span style="LC_nobreak"><label>'.
610: '<input type="checkbox" name="custommanagers" '.
611: 'value="'.&HTML::Entities::encode($user,'\'<>"&').'"'.$checked.' />'.
612: $user.'</label></span> ';
613: }
614: } else {
615: $output .= &mt('No co-author roles assignable as manager');
616: }
617: $output .= '</td>'.
618: &Apache::loncommon::end_data_table_row()."\n";
1.306 raeburn 619: }
620: } else {
621: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 622: my $name = $context.'_'.$item;
1.470 raeburn 623: $onclick = 'onclick="javascript:toggleCustom(this.form,'."'customtext_$item','custom$item'".');" ';
1.306 raeburn 624: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 625: '<input type="radio" name="'.$name.'"'.
1.470 raeburn 626: ' value="1" '.$tool_on.$onclick.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 627: '<input type="radio" name="'.$name.'" value="0" '.
1.470 raeburn 628: $tool_off.$onclick.'/>'.&mt('Off').'</label></span>';
629: $custradio = '<span id="customtext_'.$item.'"'.$customsty.' class="LC_nobreak">'.
630: '--'.$lt{'cusa'}.': '.$custdisp.'</span>';
631: }
632: unless (($item eq 'editors') || ($item eq 'managers')) {
633: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
634: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
635: &Apache::loncommon::end_data_table_row()."\n";
636: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
637: $output .=
1.275 raeburn 638: &Apache::loncommon::start_data_table_row()."\n".
1.470 raeburn 639: '<td><span class="LC_nobreak">'.
1.306 raeburn 640: $lt{'chse'}.': <label>'.
1.275 raeburn 641: '<input type="radio" name="custom'.$item.'" value="0" '.
1.470 raeburn 642: $cust_off.$onclick.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
1.306 raeburn 643: '<label><input type="radio" name="custom'.$item.'" value="1" '.
1.470 raeburn 644: $cust_on.$onclick.'/>'.$lt{'uscu'}.'</label></span>';
645: if ($colspan) {
646: $output .= '</td><td>';
647: }
648: $output .= $custradio.'</td>'.
649: &Apache::loncommon::end_data_table_row()."\n";
650: }
1.418 raeburn 651: }
1.275 raeburn 652: }
653: return $output;
654: }
655:
1.300 raeburn 656: sub coursereq_externaluser {
657: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 658: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 659: my %lt = &Apache::lonlocal::texthash (
660: 'official' => 'Can request creation of official courses',
661: 'unofficial' => 'Can request creation of unofficial courses',
662: 'community' => 'Can request creation of communities',
1.384 raeburn 663: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 664: 'placement' => 'Can request creation of placement tests',
1.300 raeburn 665: );
666:
667: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
668: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.411 raeburn 669: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
670: 'reqcrsotherdom.placement');
671: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 672: @options = ('approval','validate','autolimit');
1.306 raeburn 673: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
674: my $optregex = join('|',@options);
675: my %reqtitles = &courserequest_titles();
1.300 raeburn 676: foreach my $item (@usertools) {
1.306 raeburn 677: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 678: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
679: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 680: foreach my $req (@curr) {
681: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
682: $curroption = $1;
683: $currlimit = $2;
684: last;
1.306 raeburn 685: }
686: }
1.314 raeburn 687: if (!$curroption) {
688: $curroption = 'norequest';
689: $tooloff = ' checked="checked"';
690: }
1.306 raeburn 691: } else {
692: $curroption = 'norequest';
693: $tooloff = ' checked="checked"';
694: }
695: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 696: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
697: '<table><tr><td valign="top">'."\n".
1.306 raeburn 698: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 699: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
700: '</label></td>';
1.306 raeburn 701: foreach my $option (@options) {
702: if ($option eq 'validate') {
703: my $canvalidate = 0;
704: if (ref($validations{$item}) eq 'HASH') {
705: if ($validations{$item}{'_external_'}) {
706: $canvalidate = 1;
707: }
708: }
709: next if (!$canvalidate);
710: }
711: my $checked = '';
712: if ($option eq $curroption) {
713: $checked = ' checked="checked"';
714: }
1.314 raeburn 715: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 716: '<input type="radio" name="reqcrsotherdom_'.$item.
717: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 718: $reqtitles{$option}.'</label>';
1.306 raeburn 719: if ($option eq 'autolimit') {
1.314 raeburn 720: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 721: $item.'_limit" size="1" '.
1.314 raeburn 722: 'value="'.$currlimit.'" /></span>'.
723: '<br />'.$reqtitles{'unlimited'};
724: } else {
725: $output .= '</span>';
1.300 raeburn 726: }
1.314 raeburn 727: $output .= '</td>';
1.300 raeburn 728: }
1.314 raeburn 729: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 730: &Apache::loncommon::end_data_table_row()."\n";
731: }
732: return $output;
733: }
734:
1.362 raeburn 735: sub domainrole_req {
736: my ($ccuname,$ccdomain) = @_;
737: return '<br /><h3>'.
1.470 raeburn 738: &mt('Can Request Assignment of Domain Roles?').
1.362 raeburn 739: '</h3>'."\n".
740: &Apache::loncommon::start_data_table().
741: &build_tools_display($ccuname,$ccdomain,
742: 'requestauthor').
743: &Apache::loncommon::end_data_table();
744: }
745:
1.470 raeburn 746: sub authoring_defaults {
747: my ($ccuname,$ccdomain) = @_;
748: return '<br /><h3>'.
749: &mt('Authoring Space defaults (if role assigned)').
750: '</h3>'."\n".
751: &Apache::loncommon::start_data_table().
752: &build_tools_display($ccuname,$ccdomain,
753: 'authordefaults').
754: &user_quotas($ccuname,$ccdomain,'author').
755: &Apache::loncommon::end_data_table();
756: }
757:
1.306 raeburn 758: sub courserequest_titles {
759: my %titles = &Apache::lonlocal::texthash (
760: official => 'Official',
761: unofficial => 'Unofficial',
762: community => 'Communities',
1.384 raeburn 763: textbook => 'Textbook',
1.411 raeburn 764: placement => 'Placement Tests',
1.449 raeburn 765: lti => 'LTI Provider',
1.306 raeburn 766: norequest => 'Not allowed',
1.309 raeburn 767: approval => 'Approval by Dom. Coord.',
1.306 raeburn 768: validate => 'With validation',
769: autolimit => 'Numerical limit',
1.314 raeburn 770: unlimited => '(blank for unlimited)',
1.306 raeburn 771: );
772: return %titles;
773: }
774:
775: sub courserequest_display {
776: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 777: approval => 'Yes, need approval',
1.306 raeburn 778: validate => 'Yes, with validation',
779: norequest => 'No',
780: );
781: return %titles;
782: }
783:
1.362 raeburn 784: sub requestauthor_titles {
785: my %titles = &Apache::lonlocal::texthash (
786: norequest => 'Not allowed',
787: approval => 'Approval by Dom. Coord.',
788: automatic => 'Automatic approval',
789: );
790: return %titles;
791:
792: }
793:
794: sub requestauthor_display {
795: my %titles = &Apache::lonlocal::texthash (
796: approval => 'Yes, need approval',
797: automatic => 'Yes, automatic approval',
798: norequest => 'No',
799: );
800: return %titles;
801: }
802:
1.383 raeburn 803: sub requestchange_display {
804: my %titles = &Apache::lonlocal::texthash (
805: approval => "availability set to 'on' (approval required)",
806: automatic => "availability set to 'on' (automatic approval)",
807: norequest => "availability set to 'off'",
808: );
809: return %titles;
810: }
811:
1.362 raeburn 812: sub curr_requestauthor {
813: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
814: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
815: if ($uname eq '' || $udom eq '') {
816: $uname = $env{'user.name'};
817: $udom = $env{'user.domain'};
818: $isadv = $env{'user.adv'};
819: }
820: my (%userenv,%settings,$val);
821: my @options = ('automatic','approval');
822: %userenv =
823: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
824: if ($userenv{'requestauthor'}) {
825: $val = $userenv{'requestauthor'};
826: @{$inststatuses} = ('_custom_');
827: } else {
828: my %alltasks;
829: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
830: %settings = %{$domconfig->{'requestauthor'}};
831: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
832: $val = $settings{'_LC_adv'};
833: @{$inststatuses} = ('_LC_adv_');
834: } else {
835: if ($userenv{'inststatus'} ne '') {
836: @{$inststatuses} = split(',',$userenv{'inststatus'});
837: } else {
838: @{$inststatuses} = ('default');
839: }
840: foreach my $status (@{$inststatuses}) {
841: if (exists($settings{$status})) {
842: my $value = $settings{$status};
843: next unless ($value);
844: unless (exists($alltasks{$value})) {
845: if (ref($alltasks{$value}) eq 'ARRAY') {
846: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
847: push(@{$alltasks{$value}},$status);
848: }
849: } else {
850: @{$alltasks{$value}} = ($status);
851: }
852: }
853: }
854: }
855: foreach my $option (@options) {
856: if ($alltasks{$option}) {
857: $val = $option;
858: last;
859: }
860: }
861: }
862: }
863: }
864: return $val;
865: }
866:
1.2 www 867: # =================================================================== Phase one
1.1 www 868:
1.42 matthew 869: sub print_username_entry_form {
1.439 raeburn 870: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
871: $permission) = @_;
1.101 albertel 872: my $defdom=$env{'request.role.domain'};
1.160 raeburn 873: my $formtoset = 'crtuser';
874: if (exists($env{'form.startrolename'})) {
875: $formtoset = 'docustom';
876: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 877: } elsif ($env{'form.origform'} eq 'crtusername') {
878: $formtoset = $env{'form.origform'};
1.160 raeburn 879: }
880:
881: my ($jsback,$elements) = &crumb_utilities();
882:
883: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 884: '<script type="text/javascript">'."\n".
1.301 bisitz 885: '// <![CDATA['."\n".
886: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
887: '// ]]>'."\n".
1.162 raeburn 888: '</script>'."\n";
1.160 raeburn 889:
1.324 raeburn 890: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
891: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
892: && (&Apache::lonnet::allowed('mcr','/'))) {
893: $jscript .= &customrole_javascript();
894: }
1.224 raeburn 895: my $helpitem = 'Course_Change_Privileges';
896: if ($env{'form.action'} eq 'custom') {
1.439 raeburn 897: if ($context eq 'course') {
898: $helpitem = 'Course_Editing_Custom_Roles';
899: } elsif ($context eq 'domain') {
900: $helpitem = 'Domain_Editing_Custom_Roles';
901: }
1.224 raeburn 902: } elsif ($env{'form.action'} eq 'singlestudent') {
903: $helpitem = 'Course_Add_Student';
1.416 raeburn 904: } elsif ($env{'form.action'} eq 'accesslogs') {
905: $helpitem = 'Domain_User_Access_Logs';
1.439 raeburn 906: } elsif ($context eq 'author') {
907: $helpitem = 'Author_Change_Privileges';
908: } elsif ($context eq 'domain') {
909: if ($permission->{'cusr'}) {
910: $helpitem = 'Domain_Change_Privileges';
911: } elsif ($permission->{'view'}) {
912: $helpitem = 'Domain_View_Privileges';
913: } else {
914: undef($helpitem);
915: }
1.224 raeburn 916: }
1.422 raeburn 917: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 918: if ($env{'form.action'} eq 'custom') {
919: push(@{$brcrum},
920: {href=>"javascript:backPage(document.crtuser)",
921: text=>"Pick custom role",
922: help => $helpitem,}
923: );
924: } else {
925: push (@{$brcrum},
926: {href => "javascript:backPage(document.crtuser)",
927: text => $breadcrumb_text{'search'},
928: help => $helpitem,
929: faq => 282,
930: bug => 'Instructor Interface',}
931: );
932: }
933: my %loaditems = (
934: 'onload' => "javascript:setFormElements(document.$formtoset)",
935: );
936: my $args = {bread_crumbs => $brcrum,
937: bread_crumbs_component => 'User Management',
938: add_entries => \%loaditems,};
939: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
940:
1.71 sakharuk 941: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 942: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 943: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 944: 'srad' => 'Search for a user and modify/add user information or roles',
1.422 raeburn 945: 'srvu' => 'Search for a user and view user information and roles',
1.416 raeburn 946: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 947: 'usr' => "Username",
948: 'dom' => "Domain",
1.324 raeburn 949: 'ecrp' => "Define or Edit Custom Role",
950: 'nr' => "role name",
1.282 schafran 951: 'cre' => "Next",
1.71 sakharuk 952: );
1.351 raeburn 953:
1.214 raeburn 954: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 955: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 956: my $newroletext = &mt('Define new custom role:');
957: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
958: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
959: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
960: '<h3>'.$lt{'ecrp'}.'</h3>'.
961: &Apache::loncommon::start_data_table().
962: &Apache::loncommon::start_data_table_row().
963: '<td>');
964: if (keys(%existingroles) > 0) {
965: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
966: } else {
967: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
968: }
969: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
970: &Apache::loncommon::end_data_table_row());
971: if (keys(%existingroles) > 0) {
972: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
973: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
974: &mt('View/Modify existing role:').'</b></label></td>'.
975: '<td align="center"><br />'.
976: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 977: '<option value="" selected="selected">'.
1.324 raeburn 978: &mt('Select'));
979: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 980: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 981: }
982: $r->print('</select>'.
983: '</td>'.
984: &Apache::loncommon::end_data_table_row());
985: }
986: $r->print(&Apache::loncommon::end_data_table().'<p>'.
987: '<input name="customeditor" type="submit" value="'.
988: $lt{'cre'}.'" /></p>'.
989: '</form>');
1.190 raeburn 990: }
1.213 raeburn 991: } else {
1.229 raeburn 992: my $actiontext = $lt{'srad'};
1.436 raeburn 993: my $fixeddom;
1.213 raeburn 994: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 995: if ($crstype eq 'Community') {
996: $actiontext = $lt{'srme'};
997: } else {
998: $actiontext = $lt{'srst'};
999: }
1.416 raeburn 1000: } elsif ($env{'form.action'} eq 'accesslogs') {
1.417 raeburn 1001: $actiontext = $lt{'srva'};
1.436 raeburn 1002: $fixeddom = 1;
1.422 raeburn 1003: } elsif (($env{'form.action'} eq 'singleuser') &&
1004: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
1005: $actiontext = $lt{'srvu'};
1.439 raeburn 1006: $fixeddom = 1;
1.213 raeburn 1007: }
1.324 raeburn 1008: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 1009: if ($env{'form.origform'} ne 'crtusername') {
1.415 raeburn 1010: if ($response) {
1011: $r->print("\n<div>$response</div>".
1012: '<br clear="all" />');
1013: }
1.213 raeburn 1014: }
1.436 raeburn 1015: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 1016: }
1.110 albertel 1017: }
1018:
1.324 raeburn 1019: sub customrole_javascript {
1020: my $js = <<"END";
1021: <script type="text/javascript">
1022: // <![CDATA[
1023:
1024: function setCustomFields() {
1025: if (document.docustom.customroleaction.length > 0) {
1026: for (var i=0; i<document.docustom.customroleaction.length; i++) {
1027: if (document.docustom.customroleaction[i].checked) {
1028: if (document.docustom.customroleaction[i].value == 'new') {
1029: document.docustom.rolename.selectedIndex = 0;
1030: } else {
1031: document.docustom.newrolename.value = '';
1032: }
1033: }
1034: }
1035: }
1036: return;
1037: }
1038:
1039: function setCustomAction(caller) {
1040: if (document.docustom.customroleaction.length > 0) {
1041: for (var i=0; i<document.docustom.customroleaction.length; i++) {
1042: if (document.docustom.customroleaction[i].value == caller) {
1043: document.docustom.customroleaction[i].checked = true;
1044: }
1045: }
1046: }
1047: setCustomFields();
1048: return;
1049: }
1050:
1051: // ]]>
1052: </script>
1053: END
1054: return $js;
1055: }
1056:
1.160 raeburn 1057: sub entry_form {
1.416 raeburn 1058: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 1059: my ($usertype,$inexact);
1.214 raeburn 1060: if (ref($srch) eq 'HASH') {
1061: if (($srch->{'srchin'} eq 'dom') &&
1062: ($srch->{'srchby'} eq 'uname') &&
1063: ($srch->{'srchtype'} eq 'exact') &&
1064: ($srch->{'srchdomain'} ne '') &&
1065: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 1066: my (%curr_rules,%got_rules);
1.214 raeburn 1067: my ($rules,$ruleorder) =
1068: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 1069: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 1070: } else {
1071: $inexact = 1;
1.214 raeburn 1072: }
1.207 raeburn 1073: }
1.438 raeburn 1074: my ($cancreate,$noinstd);
1075: if ($env{'form.action'} eq 'accesslogs') {
1076: $noinstd = 1;
1077: } else {
1078: $cancreate =
1079: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1080: }
1.412 raeburn 1081: my ($userpicker,$cansearch) =
1.179 raeburn 1082: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.438 raeburn 1083: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 1084: my $srchbutton = &mt('Search');
1.229 raeburn 1085: if ($env{'form.action'} eq 'singlestudent') {
1086: $srchbutton = &mt('Search and Enroll');
1.416 raeburn 1087: } elsif ($env{'form.action'} eq 'accesslogs') {
1088: $srchbutton = &mt('Search');
1.229 raeburn 1089: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
1090: $srchbutton = &mt('Search or Add New User');
1091: }
1.412 raeburn 1092: my $output;
1093: if ($cansearch) {
1094: $output = <<"ENDBLOCK";
1.160 raeburn 1095: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 1096: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 1097: <input type="hidden" name="phase" value="get_user_info" />
1098: $userpicker
1.179 raeburn 1099: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 1100: </form>
1.207 raeburn 1101: ENDBLOCK
1.412 raeburn 1102: } else {
1103: $output = '<p>'.$userpicker.'</p>';
1104: }
1.422 raeburn 1105: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
1.430 raeburn 1106: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1.422 raeburn 1107: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 1108: my $defdom=$env{'request.role.domain'};
1.446 raeburn 1109: my ($trusted,$untrusted);
1.444 raeburn 1110: if ($context eq 'course') {
1.446 raeburn 1111: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.444 raeburn 1112: } elsif ($context eq 'author') {
1.446 raeburn 1113: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.444 raeburn 1114: } elsif ($context eq 'domain') {
1.446 raeburn 1115: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.444 raeburn 1116: }
1.446 raeburn 1117: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain',undef,undef,undef,$trusted,$untrusted);
1.207 raeburn 1118: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 1119: 'enro' => 'Enroll one student',
1.318 raeburn 1120: 'enrm' => 'Enroll one member',
1.229 raeburn 1121: 'admo' => 'Add/modify a single user',
1122: 'crea' => 'create new user if required',
1123: 'uskn' => "username is known",
1.207 raeburn 1124: 'crnu' => 'Create a new user',
1125: 'usr' => 'Username',
1126: 'dom' => 'in domain',
1.229 raeburn 1127: 'enrl' => 'Enroll',
1128: 'cram' => 'Create/Modify user',
1.207 raeburn 1129: );
1.229 raeburn 1130: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
1131: my ($title,$buttontext,$showresponse);
1.318 raeburn 1132: if ($env{'form.action'} eq 'singlestudent') {
1133: if ($crstype eq 'Community') {
1134: $title = $lt{'enrm'};
1135: } else {
1136: $title = $lt{'enro'};
1137: }
1.229 raeburn 1138: $buttontext = $lt{'enrl'};
1139: } else {
1140: $title = $lt{'admo'};
1141: $buttontext = $lt{'cram'};
1142: }
1143: if ($cancreate) {
1144: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
1145: } else {
1146: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
1147: }
1148: if ($env{'form.origform'} eq 'crtusername') {
1149: $showresponse = $responsemsg;
1150: }
1.207 raeburn 1151: $output .= <<"ENDDOCUMENT";
1.229 raeburn 1152: <br />
1.207 raeburn 1153: <form action="/adm/createuser" method="post" name="crtusername">
1154: <input type="hidden" name="action" value="$env{'form.action'}" />
1155: <input type="hidden" name="phase" value="createnewuser" />
1156: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 1157: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 1158: <input type="hidden" name="srchin" value="dom" />
1159: <input type="hidden" name="forcenewuser" value="1" />
1160: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 1161: <h3>$title</h3>
1162: $showresponse
1.207 raeburn 1163: <table>
1164: <tr>
1165: <td>$lt{'usr'}:</td>
1166: <td><input type="text" size="15" name="srchterm" /></td>
1167: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 1168: <td> $sellink </td>
1169: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 1170: </tr>
1171: </table>
1172: </form>
1.160 raeburn 1173: ENDDOCUMENT
1.207 raeburn 1174: }
1.160 raeburn 1175: return $output;
1176: }
1.110 albertel 1177:
1178: sub user_modification_js {
1.113 raeburn 1179: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
1180:
1.110 albertel 1181: return <<END;
1182: <script type="text/javascript" language="Javascript">
1.301 bisitz 1183: // <![CDATA[
1.314 raeburn 1184:
1.110 albertel 1185: $pjump_def
1186: $dc_setcourse_code
1187:
1188: function dateset() {
1189: eval("document.cu."+document.cu.pres_marker.value+
1190: ".value=document.cu.pres_value.value");
1.359 www 1191: modalWindow.close();
1.110 albertel 1192: }
1193:
1.113 raeburn 1194: $nondc_setsection_code
1.301 bisitz 1195: // ]]>
1.110 albertel 1196: </script>
1197: END
1.2 www 1198: }
1199:
1200: # =================================================================== Phase two
1.160 raeburn 1201: sub print_user_selection_page {
1.351 raeburn 1202: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 1203: my @fields = ('username','domain','lastname','firstname','permanentemail');
1204: my $sortby = $env{'form.sortby'};
1205:
1206: if (!grep(/^\Q$sortby\E$/,@fields)) {
1207: $sortby = 'lastname';
1208: }
1209:
1210: my ($jsback,$elements) = &crumb_utilities();
1211:
1212: my $jscript = (<<ENDSCRIPT);
1213: <script type="text/javascript">
1.301 bisitz 1214: // <![CDATA[
1.160 raeburn 1215: function pickuser(uname,udom) {
1216: document.usersrchform.seluname.value=uname;
1217: document.usersrchform.seludom.value=udom;
1218: document.usersrchform.phase.value="userpicked";
1219: document.usersrchform.submit();
1220: }
1221:
1222: $jsback
1.301 bisitz 1223: // ]]>
1.160 raeburn 1224: </script>
1225: ENDSCRIPT
1226:
1227: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1228: 'usrch' => "User Search to add/modify roles",
1229: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1230: 'memsrch' => "User Search to enroll member",
1.416 raeburn 1231: 'srcva' => "Search for a user and view access log information",
1.422 raeburn 1232: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1233: 'usel' => "Select a user to add/modify roles",
1.422 raeburn 1234: 'suvr' => "Select a user to view roles",
1.318 raeburn 1235: 'stusel' => "Select a user to enroll as a student",
1236: 'memsel' => "Select a user to enroll as a member",
1.416 raeburn 1237: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1238: 'username' => "username",
1239: 'domain' => "domain",
1240: 'lastname' => "last name",
1241: 'firstname' => "first name",
1242: 'permanentemail' => "permanent e-mail",
1243: );
1.302 raeburn 1244: if ($context eq 'requestcrs') {
1245: $r->print('<div>');
1246: } else {
1.422 raeburn 1247: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1248: my $helpitem;
1249: if ($env{'form.action'} eq 'singleuser') {
1250: $helpitem = 'Course_Change_Privileges';
1251: } elsif ($env{'form.action'} eq 'singlestudent') {
1252: $helpitem = 'Course_Add_Student';
1.439 raeburn 1253: } elsif ($context eq 'author') {
1254: $helpitem = 'Author_Change_Privileges';
1255: } elsif ($context eq 'domain') {
1256: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1257: }
1258: push (@{$brcrum},
1259: {href => "javascript:backPage(document.usersrchform,'','')",
1260: text => $breadcrumb_text{'search'},
1261: faq => 282,
1262: bug => 'Instructor Interface',},
1263: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1264: text => $breadcrumb_text{'userpicked'},
1265: faq => 282,
1266: bug => 'Instructor Interface',
1267: help => $helpitem}
1268: );
1269: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1270: if ($env{'form.action'} eq 'singleuser') {
1.422 raeburn 1271: my $readonly;
1272: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1273: $readonly = 1;
1274: $r->print("<b>$lt{'usrvu'}</b><br />");
1275: } else {
1276: $r->print("<b>$lt{'usrch'}</b><br />");
1277: }
1.318 raeburn 1278: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.422 raeburn 1279: if ($readonly) {
1280: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1281: } else {
1282: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1283: }
1.302 raeburn 1284: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1285: $r->print($jscript."<b>");
1286: if ($crstype eq 'Community') {
1287: $r->print($lt{'memsrch'});
1288: } else {
1289: $r->print($lt{'stusrch'});
1290: }
1291: $r->print("</b><br />");
1292: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1293: $r->print('</form><h3>');
1294: if ($crstype eq 'Community') {
1295: $r->print($lt{'memsel'});
1296: } else {
1297: $r->print($lt{'stusel'});
1298: }
1299: $r->print('</h3>');
1.416 raeburn 1300: } elsif ($env{'form.action'} eq 'accesslogs') {
1301: $r->print("<b>$lt{'srcva'}</b><br />");
1.438 raeburn 1302: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.416 raeburn 1303: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1304: }
1.179 raeburn 1305: }
1.380 bisitz 1306: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1307: &Apache::loncommon::start_data_table()."\n".
1308: &Apache::loncommon::start_data_table_header_row()."\n".
1309: ' <th> </th>'."\n");
1310: foreach my $field (@fields) {
1311: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1312: "'".$field."'".';document.usersrchform.submit();">'.
1313: $lt{$field}.'</a></th>'."\n");
1314: }
1315: $r->print(&Apache::loncommon::end_data_table_header_row());
1316:
1317: my @sorted_users = sort {
1.167 albertel 1318: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1319: ||
1.167 albertel 1320: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1321: ||
1322: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1323: ||
1324: lc($a) cmp lc($b)
1.160 raeburn 1325: } (keys(%$srch_results));
1326:
1327: foreach my $user (@sorted_users) {
1328: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1329: my $onclick;
1330: if ($context eq 'requestcrs') {
1.314 raeburn 1331: $onclick =
1.302 raeburn 1332: 'onclick="javascript:gochoose('."'$uname','$udom',".
1333: "'$srch_results->{$user}->{firstname}',".
1334: "'$srch_results->{$user}->{lastname}',".
1335: "'$srch_results->{$user}->{permanentemail}'".');"';
1336: } else {
1.314 raeburn 1337: $onclick =
1.302 raeburn 1338: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1339: }
1.160 raeburn 1340: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1341: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1342: $onclick.' /></td>'.
1.160 raeburn 1343: '<td><tt>'.$uname.'</tt></td>'.
1344: '<td><tt>'.$udom.'</tt></td>');
1345: foreach my $field ('lastname','firstname','permanentemail') {
1346: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1347: }
1348: $r->print(&Apache::loncommon::end_data_table_row());
1349: }
1350: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1351: if (ref($srcharray) eq 'ARRAY') {
1352: foreach my $item (@{$srcharray}) {
1353: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1354: }
1355: }
1.160 raeburn 1356: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1357: ' <input type="hidden" name="seluname" value="" />'."\n".
1358: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1359: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1360: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1361: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1362: if ($context eq 'requestcrs') {
1363: $r->print($opener_elements.'</form></div>');
1364: } else {
1.351 raeburn 1365: $r->print($response.'</form>');
1.302 raeburn 1366: }
1.160 raeburn 1367: }
1368:
1369: sub print_user_query_page {
1.351 raeburn 1370: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1371: # FIXME - this is for a network-wide name search (similar to catalog search)
1372: # To use frames with similar behavior to catalog/portfolio search.
1373: # To be implemented.
1374: return;
1375: }
1376:
1.42 matthew 1377: sub print_user_modification_page {
1.375 raeburn 1378: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1379: $brcrum,$showcredits) = @_;
1.185 raeburn 1380: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1381: my $usermsg = &mt('No username and/or domain provided.');
1382: $env{'form.phase'} = '';
1.439 raeburn 1383: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1384: $permission);
1.58 www 1385: return;
1386: }
1.213 raeburn 1387: my ($form,$formname);
1388: if ($env{'form.action'} eq 'singlestudent') {
1389: $form = 'document.enrollstudent';
1390: $formname = 'enrollstudent';
1391: } else {
1392: $form = 'document.cu';
1393: $formname = 'cu';
1394: }
1.188 raeburn 1395: my %abv_auth = &auth_abbrev();
1.227 raeburn 1396: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1397: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1398: if ($uhome eq 'no_host') {
1.215 raeburn 1399: my $usertype;
1400: my ($rules,$ruleorder) =
1401: &Apache::lonnet::inst_userrules($ccdomain,'username');
1402: $usertype =
1.353 raeburn 1403: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1404: \%curr_rules,\%got_rules);
1.215 raeburn 1405: my $cancreate =
1406: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1407: $usertype);
1408: if (!$cancreate) {
1.292 bisitz 1409: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1410: my %usertypetext = (
1411: official => 'institutional',
1412: unofficial => 'non-institutional',
1413: );
1414: my $response;
1415: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1416: $response = '<span class="LC_warning">'.
1417: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1418: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1419: '</span><br />';
1420: }
1.292 bisitz 1421: $response .= '<p class="LC_warning">'
1422: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.418 raeburn 1423: .' ';
1424: if ($context eq 'domain') {
1425: $response .= &mt('Please contact a [_1] for assistance.',
1426: &Apache::lonnet::plaintext('dc'));
1427: } else {
1428: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1429: ,'<a href="'.$helplink.'">','</a>');
1430: }
1431: $response .= '</p><br />';
1.215 raeburn 1432: $env{'form.phase'} = '';
1.439 raeburn 1433: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1434: $permission);
1.215 raeburn 1435: return;
1436: }
1.188 raeburn 1437: $newuser = 1;
1.193 raeburn 1438: my $checkhash;
1439: my $checks = { 'username' => 1 };
1.196 raeburn 1440: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1441: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1442: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1443: if (ref($alerts{'username'}) eq 'HASH') {
1444: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1445: my $domdesc =
1.193 raeburn 1446: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1447: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1448: my $userchkmsg;
1449: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1450: $userchkmsg =
1451: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1452: $domdesc,1).
1453: &Apache::loncommon::user_rule_formats($ccdomain,
1454: $domdesc,$curr_rules{$ccdomain}{'username'},
1455: 'username');
1.196 raeburn 1456: }
1.215 raeburn 1457: $env{'form.phase'} = '';
1.439 raeburn 1458: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1459: $permission);
1.196 raeburn 1460: return;
1.215 raeburn 1461: }
1.193 raeburn 1462: }
1.185 raeburn 1463: }
1.187 raeburn 1464: } else {
1.188 raeburn 1465: $newuser = 0;
1.185 raeburn 1466: }
1.160 raeburn 1467: if ($response) {
1.215 raeburn 1468: $response = '<br />'.$response;
1.160 raeburn 1469: }
1.149 raeburn 1470:
1.52 matthew 1471: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1472: my $dc_setcourse_code = '';
1.119 raeburn 1473: my $nondc_setsection_code = '';
1.112 albertel 1474: my %loaditem;
1.114 albertel 1475:
1.216 raeburn 1476: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1477:
1.470 raeburn 1478: my $js = &validation_javascript($context,$ccdomain,$pjump_def,
1479: $crstype,$groupslist,$newuser,
1480: $formname,\%loaditem,$permission);
1.422 raeburn 1481: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1482: my $helpitem = 'Course_Change_Privileges';
1483: if ($env{'form.action'} eq 'singlestudent') {
1484: $helpitem = 'Course_Add_Student';
1.439 raeburn 1485: } elsif ($context eq 'author') {
1486: $helpitem = 'Author_Change_Privileges';
1487: } elsif ($context eq 'domain') {
1488: $helpitem = 'Domain_Change_Privileges';
1.470 raeburn 1489: $js .= &set_custom_js();
1.224 raeburn 1490: }
1.351 raeburn 1491: push (@{$brcrum},
1492: {href => "javascript:backPage($form)",
1493: text => $breadcrumb_text{'search'},
1494: faq => 282,
1495: bug => 'Instructor Interface',});
1496: if ($env{'form.phase'} eq 'userpicked') {
1497: push(@{$brcrum},
1498: {href => "javascript:backPage($form,'get_user_info','select')",
1499: text => $breadcrumb_text{'userpicked'},
1500: faq => 282,
1501: bug => 'Instructor Interface',});
1502: }
1503: push(@{$brcrum},
1504: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1505: text => $breadcrumb_text{'modify'},
1506: faq => 282,
1507: bug => 'Instructor Interface',
1508: help => $helpitem});
1509: my $args = {'add_entries' => \%loaditem,
1510: 'bread_crumbs' => $brcrum,
1511: 'bread_crumbs_component' => 'User Management'};
1512: if ($env{'form.popup'}) {
1513: $args->{'no_nav_bar'} = 1;
1514: }
1.470 raeburn 1515: if (($context eq 'domain') && ($env{'request.role.domain'} eq $ccdomain)) {
1516: my @toggles;
1517: if (&Apache::lonnet::allowed('cau',$ccdomain)) {
1518: my ($isadv,$isauthor) =
1519: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1520: unless ($isauthor) {
1521: push(@toggles,'requestauthor');
1522: }
1523: push(@toggles,('webdav','editors'));
1524: }
1525: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1526: push(@toggles,('aboutme','blog','portfolio','portaccess','timezone'));
1527: }
1528: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1529: push(@toggles,('official','unofficial','community','textbook','placement','lti'));
1530: }
1531: if (@toggles) {
1532: my $onload;
1533: foreach my $item (@toggles) {
1534: $onload .= "toggleCustom(document.cu,'customtext_$item','custom$item');";
1535: }
1536: $args->{'add_entries'} = {
1537: 'onload' => $onload,
1538: };
1539: }
1540: }
1.351 raeburn 1541: my $start_page =
1542: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1543:
1.25 matthew 1544: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1545: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1546: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1547: <input type="hidden" name="ccuname" value="$ccuname" />
1548: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1549: <input type="hidden" name="pres_value" value="" />
1550: <input type="hidden" name="pres_type" value="" />
1551: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1552: ENDFORMINFO
1.375 raeburn 1553: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1554: if ($context eq 'course') {
1555: $inccourses{$env{'request.course.id'}}=1;
1556: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1557: if ($showcredits) {
1558: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1559: }
1.329 raeburn 1560: } elsif ($context eq 'author') {
1561: $roledom = $env{'request.role.domain'};
1562: } elsif ($context eq 'domain') {
1563: foreach my $key (keys(%env)) {
1564: $roledom = $env{'request.role.domain'};
1565: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1566: $inccourses{$1.'_'.$2}=1;
1567: }
1568: }
1569: } else {
1570: foreach my $key (keys(%env)) {
1571: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1572: $inccourses{$1.'_'.$2}=1;
1573: }
1.2 www 1574: }
1.24 matthew 1575: }
1.389 bisitz 1576: my $title = '';
1.470 raeburn 1577: my $need_quota_js;
1.216 raeburn 1578: if ($newuser) {
1.427 raeburn 1579: my ($portfolioform,$domroleform);
1.267 raeburn 1580: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1581: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1582: # Current user has quota or user tools modification privileges
1.470 raeburn 1583: $portfolioform = '<br /><h3>'.
1584: &mt('User Tools').
1585: '</h3>'."\n".
1586: &Apache::loncommon::start_data_table();
1587: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1588: $portfolioform .= &build_tools_display($ccuname,$ccdomain,'tools');
1589: }
1590: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
1591: $portfolioform .= &user_quotas($ccuname,$ccdomain,'portfolio');
1592: $need_quota_js = 1;
1593: }
1594: $portfolioform .= &Apache::loncommon::end_data_table();
1.134 raeburn 1595: }
1.383 raeburn 1596: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1597: ($ccdomain eq $env{'request.role.domain'})) {
1.470 raeburn 1598: $domroleform = &domainrole_req($ccuname,$ccdomain).
1599: &authoring_defaults($ccuname,$ccdomain);
1600: $need_quota_js = 1;
1601: }
1602: my $readonly;
1603: unless ($permission->{'cusr'}) {
1604: $readonly = 1;
1.362 raeburn 1605: }
1.470 raeburn 1606: &initialize_authen_forms($ccdomain,$formname,'','',$readonly);
1.188 raeburn 1607: my %lt=&Apache::lonlocal::texthash(
1608: 'lg' => 'Login Data',
1.190 raeburn 1609: 'hs' => "Home Server",
1.188 raeburn 1610: );
1.185 raeburn 1611: $r->print(<<ENDTITLE);
1.110 albertel 1612: $start_page
1.160 raeburn 1613: $response
1.25 matthew 1614: $forminfo
1.31 matthew 1615: <script type="text/javascript" language="Javascript">
1.301 bisitz 1616: // <![CDATA[
1.20 harris41 1617: $loginscript
1.301 bisitz 1618: // ]]>
1.31 matthew 1619: </script>
1.20 harris41 1620: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1621: ENDTITLE
1.213 raeburn 1622: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1623: if ($crstype eq 'Community') {
1.389 bisitz 1624: $title = &mt('Create New User [_1] in domain [_2] as a member',
1625: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1626: } else {
1.389 bisitz 1627: $title = &mt('Create New User [_1] in domain [_2] as a student',
1628: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1629: }
1.389 bisitz 1630: } else {
1631: $title = &mt('Create New User [_1] in domain [_2]',
1632: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1633: }
1.389 bisitz 1634: $r->print('<h2>'.$title.'</h2>'."\n");
1635: $r->print('<div class="LC_left_float">');
1.393 raeburn 1636: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1.470 raeburn 1637: $inst_results{$ccuname.':'.$ccdomain},$readonly));
1.393 raeburn 1638: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1639: my ($home_server_pick,$numlib) =
1640: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1641: 'default','hide');
1642: if ($numlib > 1) {
1643: $r->print("
1.185 raeburn 1644: <br />
1.187 raeburn 1645: $lt{'hs'}: $home_server_pick
1646: <br />");
1647: } else {
1648: $r->print($home_server_pick);
1649: }
1.304 raeburn 1650: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1651: $r->print('<br /><h3>'.
1.470 raeburn 1652: &mt('Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1653: &Apache::loncommon::start_data_table().
1654: &build_tools_display($ccuname,$ccdomain,
1655: 'requestcourses').
1656: &Apache::loncommon::end_data_table());
1657: }
1.188 raeburn 1658: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1659: $lt{'lg'}.'</h3>');
1.185 raeburn 1660: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1661: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1662: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1663: my ($rules,$ruleorder) =
1664: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1665: if (ref($rules) eq 'HASH') {
1.193 raeburn 1666: if (ref($rules->{$matchedrule}) eq 'HASH') {
1667: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1668: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1669: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1670: } else {
1.193 raeburn 1671: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1672: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1673: if ($authtype =~ /^krb(4|5)$/) {
1674: my $ver = $1;
1675: if ($authparm ne '') {
1676: $fixedauth = <<"KERB";
1677: <input type="hidden" name="login" value="krb" />
1678: <input type="hidden" name="krbver" value="$ver" />
1679: <input type="hidden" name="krbarg" value="$authparm" />
1680: KERB
1681: }
1682: } else {
1683: $fixedauth =
1684: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1685: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1686: $fixedauth .=
1687: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1688: } else {
1.273 raeburn 1689: if ($authtype eq 'int') {
1690: $varauth = '<br />'.
1.301 bisitz 1691: &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 1692: } elsif ($authtype eq 'loc') {
1693: $varauth = '<br />'.
1694: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1695: } else {
1696: $varauth =
1.185 raeburn 1697: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1698: }
1.185 raeburn 1699: }
1700: }
1701: }
1702: } else {
1.190 raeburn 1703: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1704: }
1705: }
1706: if ($authmsg) {
1707: $r->print(<<ENDAUTH);
1708: $fixedauth
1709: $authmsg
1710: $varauth
1711: ENDAUTH
1712: }
1713: } else {
1.190 raeburn 1714: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1715: }
1.427 raeburn 1716: $r->print($portfolioform.$domroleform);
1.215 raeburn 1717: if ($env{'form.action'} eq 'singlestudent') {
1718: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1719: $permission,$crstype,$ccuname,
1720: $ccdomain,$showcredits));
1.215 raeburn 1721: }
1722: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1723: } else { # user already exists
1.389 bisitz 1724: $r->print($start_page.$forminfo);
1.213 raeburn 1725: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1726: if ($crstype eq 'Community') {
1.389 bisitz 1727: $title = &mt('Enroll one member: [_1] in domain [_2]',
1728: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1729: } else {
1.389 bisitz 1730: $title = &mt('Enroll one student: [_1] in domain [_2]',
1731: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1732: }
1.213 raeburn 1733: } else {
1.418 raeburn 1734: if ($permission->{'cusr'}) {
1735: $title = &mt('Modify existing user: [_1] in domain [_2]',
1736: '"'.$ccuname.'"','"'.$ccdomain.'"');
1737: } else {
1738: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1739: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.418 raeburn 1740: }
1.213 raeburn 1741: }
1.389 bisitz 1742: $r->print('<h2>'.$title.'</h2>'."\n");
1743: $r->print('<div class="LC_left_float">');
1.393 raeburn 1744: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1745: $inst_results{$ccuname.':'.$ccdomain}));
1.430 raeburn 1746: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1.418 raeburn 1747: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.470 raeburn 1748: $r->print('<br /><h3>'.&mt('Can Request Creation of Courses/Communities in this Domain?').'</h3>'."\n");
1.450 raeburn 1749: if (($env{'request.role.domain'} eq $ccdomain) ||
1750: (&Apache::lonnet::will_trust('reqcrs',$ccdomain,$env{'request.role.domain'}))) {
1751: $r->print(&Apache::loncommon::start_data_table());
1752: if ($env{'request.role.domain'} eq $ccdomain) {
1753: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1754: } else {
1.444 raeburn 1755: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1756: $env{'request.role.domain'}));
1757: }
1.450 raeburn 1758: $r->print(&Apache::loncommon::end_data_table());
1759: } else {
1760: $r->print(&mt('Domain configuration for this domain prohibits course creation by users from domain: "[_1]"',
1761: &Apache::lonnet::domain($ccdomain,'description')));
1.300 raeburn 1762: }
1.275 raeburn 1763: }
1.199 raeburn 1764: $r->print('</div>');
1.470 raeburn 1765: my @order = ('auth','quota','tools','requestauthor','authordefaults');
1.362 raeburn 1766: my %user_text;
1767: my ($isadv,$isauthor) =
1.418 raeburn 1768: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.470 raeburn 1769: if (((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1.418 raeburn 1770: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1.470 raeburn 1771: ($env{'request.role.domain'} eq $ccdomain)) {
1772: if (!$isauthor) {
1773: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1774: }
1775: $user_text{'authordefaults'} = &authoring_defaults($ccuname,$ccdomain);
1776: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
1777: $need_quota_js = 1;
1778: }
1.362 raeburn 1779: }
1.451 raeburn 1780: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
1.267 raeburn 1781: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.418 raeburn 1782: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1783: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.470 raeburn 1784: $user_text{'quota'} = '<br /><h3>'.&mt('User Tools').'</h3>'."\n".
1785: &Apache::loncommon::start_data_table();
1786: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
1787: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1788: $user_text{'quota'} .= &build_tools_display($ccuname,$ccdomain,'tools');
1789: }
1.188 raeburn 1790: # Current user has quota modification privileges
1.470 raeburn 1791: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1792: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1793: $user_text{'quota'} .= &user_quotas($ccuname,$ccdomain,'portfolio');
1794: $need_quota_js = 1;
1795: }
1796: $user_text{'quota'} .= &Apache::loncommon::end_data_table();
1.267 raeburn 1797: }
1798: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1799: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1800: my %lt=&Apache::lonlocal::texthash(
1.470 raeburn 1801: 'dska' => "Disk quotas for user's portfolio",
1802: 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
1.267 raeburn 1803: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1804: );
1.362 raeburn 1805: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1806: <h3>$lt{'dska'}</h3>
1807: $lt{'youd'} $lt{'ichr'}: $ccdomain
1808: ENDNOPORTPRIV
1.267 raeburn 1809: }
1810: }
1811: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1812: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1813: my %lt=&Apache::lonlocal::texthash(
1814: 'utav' => "User Tools Availability",
1.470 raeburn 1815: 'yodo' => "You do not have privileges to modify Portfolio, Blog, Personal Information Page, or Time Zone settings for this user.",
1.267 raeburn 1816: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1817: );
1.362 raeburn 1818: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1819: <h3>$lt{'utav'}</h3>
1820: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1821: ENDNOTOOLSPRIV
1822: }
1.188 raeburn 1823: }
1.362 raeburn 1824: my $gotdiv = 0;
1825: foreach my $item (@order) {
1826: if ($user_text{$item} ne '') {
1827: unless ($gotdiv) {
1828: $r->print('<div class="LC_left_float">');
1829: $gotdiv = 1;
1830: }
1831: $r->print('<br />'.$user_text{$item});
1832: }
1833: }
1834: if ($env{'form.action'} eq 'singlestudent') {
1835: unless ($gotdiv) {
1836: $r->print('<div class="LC_left_float">');
1.213 raeburn 1837: }
1.375 raeburn 1838: my $credits;
1839: if ($showcredits) {
1840: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1841: if ($credits eq '') {
1842: $credits = $defaultcredits;
1843: }
1844: }
1.374 raeburn 1845: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1846: $permission,$crstype,$ccuname,
1847: $ccdomain,$showcredits));
1.374 raeburn 1848: }
1.362 raeburn 1849: if ($gotdiv) {
1850: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1851: }
1.418 raeburn 1852: my $statuses;
1853: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1854: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1855: $statuses = ['active'];
1856: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1857: ($env{'request.course.sec'} &&
1858: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1.430 raeburn 1859: $statuses = ['active'];
1.418 raeburn 1860: }
1.217 raeburn 1861: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1862: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.418 raeburn 1863: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1864: }
1.25 matthew 1865: } ## End of new user/old user logic
1.218 raeburn 1866: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1867: my $btntxt;
1868: if ($crstype eq 'Community') {
1869: $btntxt = &mt('Enroll Member');
1870: } else {
1871: $btntxt = &mt('Enroll Student');
1872: }
1873: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.418 raeburn 1874: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1875: $r->print('<div class="LC_left_float">'.
1876: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1877: my $addrolesdisplay = 0;
1878: if ($context eq 'domain' || $context eq 'author') {
1879: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1880: }
1881: if ($context eq 'domain') {
1.357 raeburn 1882: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1883: if (!$addrolesdisplay) {
1884: $addrolesdisplay = $add_domainroles;
1.2 www 1885: }
1.375 raeburn 1886: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1887: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1888: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1889: } elsif ($context eq 'author') {
1890: if ($addrolesdisplay) {
1.393 raeburn 1891: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1892: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1893: if ($newuser) {
1.301 bisitz 1894: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1895: } else {
1.461 raeburn 1896: $r->print(' onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1897: }
1.188 raeburn 1898: } else {
1.393 raeburn 1899: $r->print('</fieldset></div>'.
1900: '<div class="LC_clear_float_footer"></div>'.
1901: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1902: &mt('Back to previous page').'</a>');
1.188 raeburn 1903: }
1904: } else {
1.375 raeburn 1905: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1906: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1907: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1908: }
1.88 raeburn 1909: }
1.188 raeburn 1910: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1911: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1912: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.470 raeburn 1913: if ($need_quota_js) {
1914: $r->print(&user_quota_js());
1915: }
1.218 raeburn 1916: return;
1.2 www 1917: }
1.1 www 1918:
1.213 raeburn 1919: sub singleuser_breadcrumb {
1.422 raeburn 1920: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1921: my %breadcrumb_text;
1922: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1923: if ($crstype eq 'Community') {
1924: $breadcrumb_text{'search'} = 'Enroll a member';
1925: } else {
1926: $breadcrumb_text{'search'} = 'Enroll a student';
1927: }
1.422 raeburn 1928: $breadcrumb_text{'userpicked'} = 'Select a user';
1929: $breadcrumb_text{'modify'} = 'Set section/dates';
1.416 raeburn 1930: } elsif ($env{'form.action'} eq 'accesslogs') {
1931: $breadcrumb_text{'search'} = 'View access logs for a user';
1.422 raeburn 1932: $breadcrumb_text{'userpicked'} = 'Select a user';
1933: $breadcrumb_text{'activity'} = 'Activity';
1934: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1935: (!&Apache::lonnet::allowed('mau',$domain))) {
1936: $breadcrumb_text{'search'} = "View user's roles";
1937: $breadcrumb_text{'userpicked'} = 'Select a user';
1938: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1939: } else {
1.229 raeburn 1940: $breadcrumb_text{'search'} = 'Create/modify a user';
1.422 raeburn 1941: $breadcrumb_text{'userpicked'} = 'Select a user';
1942: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1943: }
1944: return %breadcrumb_text;
1945: }
1946:
1947: sub date_sections_select {
1.375 raeburn 1948: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1949: $showcredits) = @_;
1950: my $credits;
1951: if ($showcredits) {
1952: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1953: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1954: if ($credits eq '') {
1955: $credits = $defaultcredits;
1956: }
1957: }
1.213 raeburn 1958: my $cid = $env{'request.course.id'};
1959: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1960: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1961: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1962: undef,$formname,$permission);
1963: my $rowtitle = 'Section';
1.375 raeburn 1964: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1965: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1966: $permission,$context,'',$crstype,
1967: $showcredits,$credits);
1.213 raeburn 1968: my $output = $date_table.$secbox;
1969: return $output;
1970: }
1971:
1.216 raeburn 1972: sub validation_javascript {
1.375 raeburn 1973: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.470 raeburn 1974: $loaditem,$permission) = @_;
1.216 raeburn 1975: my $dc_setcourse_code = '';
1976: my $nondc_setsection_code = '';
1977: if ($context eq 'domain') {
1.470 raeburn 1978: if ((ref($permission) eq 'HASH') && ($permission->{'cusr'})) {
1979: my $dcdom = $env{'request.role.domain'};
1980: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1981: $dc_setcourse_code =
1982: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1983: }
1.216 raeburn 1984: } else {
1.227 raeburn 1985: my $checkauth;
1986: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1987: $checkauth = 1;
1988: }
1989: if ($context eq 'course') {
1990: $nondc_setsection_code =
1991: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1992: undef,$checkauth,
1993: $crstype);
1.227 raeburn 1994: }
1995: if ($checkauth) {
1996: $nondc_setsection_code .=
1997: &Apache::lonuserutils::verify_authen($formname,$context);
1998: }
1.216 raeburn 1999: }
2000: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
2001: $nondc_setsection_code,$groupslist);
2002: my ($jsback,$elements) = &crumb_utilities();
2003: $js .= "\n".
1.301 bisitz 2004: '<script type="text/javascript">'."\n".
2005: '// <![CDATA['."\n".
2006: $jsback."\n".
2007: '// ]]>'."\n".
2008: '</script>'."\n";
1.216 raeburn 2009: return $js;
2010: }
2011:
1.217 raeburn 2012: sub display_existing_roles {
1.375 raeburn 2013: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.418 raeburn 2014: $showcredits,$statuses) = @_;
1.329 raeburn 2015: my $now=time;
1.418 raeburn 2016: my $showall = 1;
2017: my ($showexpired,$showactive);
2018: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
2019: $showall = 0;
2020: if (grep(/^expired$/,@{$statuses})) {
2021: $showexpired = 1;
2022: }
2023: if (grep(/^active$/,@{$statuses})) {
2024: $showactive = 1;
2025: }
2026: if ($showexpired && $showactive) {
2027: $showall = 1;
2028: }
2029: }
1.329 raeburn 2030: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 2031: 'rer' => "Existing Roles",
2032: 'rev' => "Revoke",
2033: 'del' => "Delete",
2034: 'ren' => "Re-Enable",
2035: 'rol' => "Role",
2036: 'ext' => "Extent",
1.375 raeburn 2037: 'crd' => "Credits",
1.217 raeburn 2038: 'sta' => "Start",
2039: 'end' => "End",
2040: );
1.329 raeburn 2041: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
2042: if ($context eq 'course' || $context eq 'author') {
2043: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
2044: my %roleshash =
2045: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
2046: ['active','previous','future'],\@roles,$roledom,1);
2047: foreach my $key (keys(%roleshash)) {
2048: my ($start,$end) = split(':',$roleshash{$key});
2049: next if ($start eq '-1' || $end eq '-1');
2050: my ($rnum,$rdom,$role,$sec) = split(':',$key);
2051: if ($context eq 'course') {
2052: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
2053: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
2054: } elsif ($context eq 'author') {
1.470 raeburn 2055: if ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2056: my ($audom,$auname) = ($1,$2);
2057: next unless (($rnum eq $auname) && ($rdom eq $audom));
2058: } else {
2059: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
2060: }
1.329 raeburn 2061: }
2062: my ($newkey,$newvalue,$newrole);
2063: $newkey = '/'.$rdom.'/'.$rnum;
2064: if ($sec ne '') {
2065: $newkey .= '/'.$sec;
2066: }
2067: $newvalue = $role;
2068: if ($role =~ /^cr/) {
2069: $newrole = 'cr';
2070: } else {
2071: $newrole = $role;
2072: }
2073: $newkey .= '_'.$newrole;
2074: if ($start ne '' && $end ne '') {
2075: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 2076: } elsif ($end ne '') {
2077: $newvalue .= '_'.$end;
1.329 raeburn 2078: }
2079: $rolesdump{$newkey} = $newvalue;
2080: }
2081: } else {
1.360 raeburn 2082: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 2083: }
2084: # Build up table of user roles to allow revocation and re-enabling of roles.
2085: my ($tmp) = keys(%rolesdump);
2086: return if ($tmp =~ /^(con_lost|error)/i);
2087: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
2088: my $b1=join('_',(split('_',$b))[1,0]);
2089: return $a1 cmp $b1;
2090: } keys(%rolesdump)) {
2091: next if ($area =~ /^rolesdef/);
2092: my $envkey=$area;
2093: my $role = $rolesdump{$area};
2094: my $thisrole=$area;
2095: $area =~ s/\_\w\w$//;
2096: my ($role_code,$role_end_time,$role_start_time) =
2097: split(/_/,$role);
1.418 raeburn 2098: my $active=1;
2099: $active=0 if (($role_end_time) && ($now>$role_end_time));
2100: if ($active) {
2101: next unless($showall || $showactive);
2102: } else {
1.430 raeburn 2103: next unless($showall || $showexpired);
1.418 raeburn 2104: }
1.217 raeburn 2105: # Is this a custom role? Get role owner and title.
1.329 raeburn 2106: my ($croleudom,$croleuname,$croletitle)=
2107: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
2108: my $allowed=0;
2109: my $delallowed=0;
2110: my $sortkey=$role_code;
2111: my $class='Unknown';
1.375 raeburn 2112: my $credits='';
1.418 raeburn 2113: my $csec;
1.421 raeburn 2114: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 2115: $class='Course';
2116: my ($coursedom,$coursedir) = ($1,$2);
2117: my $cid = $1.'_'.$2;
2118: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.421 raeburn 2119: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 2120: my %coursedata=
2121: &Apache::lonnet::coursedescription($cid);
2122: if ($coursedir =~ /^$match_community$/) {
2123: $class='Community';
2124: }
2125: $sortkey.="\0$coursedom";
2126: my $carea;
2127: if (defined($coursedata{'description'})) {
2128: $carea=$coursedata{'description'}.
2129: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
2130: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
2131: $sortkey.="\0".$coursedata{'description'};
2132: } else {
2133: if ($class eq 'Community') {
2134: $carea=&mt('Unavailable community').': '.$area;
2135: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 2136: } else {
2137: $carea=&mt('Unavailable course').': '.$area;
2138: $sortkey.="\0".&mt('Unavailable course').': '.$area;
2139: }
1.329 raeburn 2140: }
2141: $sortkey.="\0$coursedir";
2142: $inccourses->{$cid}=1;
1.375 raeburn 2143: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
2144: my $defaultcredits = $coursedata{'internal.defaultcredits'};
2145: $credits =
2146: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
2147: $coursedom,$coursedir);
2148: if ($credits eq '') {
2149: $credits = $defaultcredits;
2150: }
2151: }
1.329 raeburn 2152: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
2153: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
2154: $allowed=1;
2155: }
2156: unless ($allowed) {
1.365 raeburn 2157: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 2158: if ($isowner) {
2159: if (($role_code eq 'co') && ($class eq 'Community')) {
2160: $allowed = 1;
2161: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
2162: $allowed = 1;
2163: }
1.217 raeburn 2164: }
1.329 raeburn 2165: }
2166: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
2167: (&Apache::lonnet::allowed('dro',$ccdomain))) {
2168: $delallowed=1;
2169: }
1.217 raeburn 2170: # - custom role. Needs more info, too
1.329 raeburn 2171: if ($croletitle) {
2172: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
2173: $allowed=1;
2174: $thisrole.='.'.$role_code;
1.217 raeburn 2175: }
1.329 raeburn 2176: }
1.418 raeburn 2177: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
2178: $csec = $2;
2179: $carea.='<br />'.&mt('Section: [_1]',$csec);
2180: $sortkey.="\0$csec";
1.329 raeburn 2181: if (!$allowed) {
1.418 raeburn 2182: if ($env{'request.course.sec'} eq $csec) {
2183: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 2184: $allowed = 1;
1.217 raeburn 2185: }
2186: }
2187: }
1.329 raeburn 2188: }
2189: $area=$carea;
2190: } else {
2191: $sortkey.="\0".$area;
2192: # Determine if current user is able to revoke privileges
2193: if ($area=~m{^/($match_domain)/}) {
2194: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
2195: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
2196: $allowed=1;
1.217 raeburn 2197: }
1.329 raeburn 2198: if (((&Apache::lonnet::allowed('dro',$1)) ||
2199: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
2200: ($role_code ne 'dc')) {
2201: $delallowed=1;
1.217 raeburn 2202: }
1.329 raeburn 2203: } else {
2204: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 2205: $allowed=1;
2206: }
2207: }
1.363 raeburn 2208: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 2209: $class='Authoring Space';
1.329 raeburn 2210: } elsif ($role_code eq 'su') {
2211: $class='System';
1.217 raeburn 2212: } else {
1.329 raeburn 2213: $class='Domain';
1.217 raeburn 2214: }
1.329 raeburn 2215: }
2216: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
2217: $area=~m{/($match_domain)/($match_username)};
2218: if (&Apache::lonuserutils::authorpriv($2,$1)) {
2219: $allowed=1;
1.470 raeburn 2220: } elsif (&Apache::lonuserutils::coauthorpriv($2,$1)) {
2221: $allowed=1;
1.217 raeburn 2222: } else {
1.329 raeburn 2223: $allowed=0;
1.217 raeburn 2224: }
1.329 raeburn 2225: }
2226: my $row = '';
1.418 raeburn 2227: if ($showall) {
2228: $row.= '<td>';
2229: if (($active) && ($allowed)) {
2230: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
2231: } else {
2232: if ($active) {
2233: $row.=' ';
2234: } else {
2235: $row.=&mt('expired or revoked');
2236: }
2237: }
2238: $row.='</td><td>';
2239: if ($allowed && !$active) {
2240: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
2241: } else {
2242: $row.=' ';
2243: }
2244: $row.='</td><td>';
2245: if ($delallowed) {
2246: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.217 raeburn 2247: } else {
1.418 raeburn 2248: $row.=' ';
1.217 raeburn 2249: }
1.430 raeburn 2250: $row.= '</td>';
1.329 raeburn 2251: }
2252: my $plaintext='';
2253: if (!$croletitle) {
1.375 raeburn 2254: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
2255: if (($showcredits) && ($credits ne '')) {
2256: $plaintext .= '<br/ ><span class="LC_nobreak">'.
2257: '<span class="LC_fontsize_small">'.
2258: &mt('Credits: [_1]',$credits).
2259: '</span></span>';
2260: }
1.329 raeburn 2261: } else {
2262: $plaintext=
1.395 bisitz 2263: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 2264: '"'.$croletitle.'"',
2265: '<br />',
2266: $croleuname.':'.$croleudom);
1.329 raeburn 2267: }
1.418 raeburn 2268: $row.= '<td>'.$plaintext.'</td>'.
2269: '<td>'.$area.'</td>'.
2270: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
2271: : ' ' ).'</td>'.
2272: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
2273: : ' ' ).'</td>';
1.329 raeburn 2274: $sortrole{$sortkey}=$envkey;
2275: $roletext{$envkey}=$row;
2276: $roleclass{$envkey}=$class;
1.418 raeburn 2277: if ($allowed) {
2278: $rolepriv{$envkey}='edit';
2279: } else {
2280: if ($context eq 'domain') {
1.420 raeburn 2281: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1.421 raeburn 2282: ($envkey=~m{^/$ccdomain/})) {
1.418 raeburn 2283: $rolepriv{$envkey}='view';
2284: }
2285: } elsif ($context eq 'course') {
2286: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
2287: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
2288: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
2289: $rolepriv{$envkey}='view';
2290: }
2291: }
2292: }
1.329 raeburn 2293: } # end of foreach (table building loop)
2294:
2295: my $rolesdisplay = 0;
2296: my %output = ();
1.377 raeburn 2297: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2298: $output{$type} = '';
2299: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2300: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2301: $output{$type}.=
2302: &Apache::loncommon::start_data_table_row().
2303: $roletext{$sortrole{$which}}.
2304: &Apache::loncommon::end_data_table_row();
1.217 raeburn 2305: }
1.329 raeburn 2306: }
2307: unless($output{$type} eq '') {
2308: $output{$type} = '<tr class="LC_info_row">'.
2309: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2310: $output{$type};
2311: $rolesdisplay = 1;
2312: }
2313: }
2314: if ($rolesdisplay == 1) {
2315: my $contextrole='';
2316: if ($env{'request.course.id'}) {
2317: if (&Apache::loncommon::course_type() eq 'Community') {
2318: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2319: } else {
1.329 raeburn 2320: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2321: }
1.329 raeburn 2322: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2323: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.470 raeburn 2324: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)/$}) {
2325: $contextrole = &mt('Existing Co-Author Roles in [_1] Authoring Space',
2326: '<i>'.$1.'_'.$2.'</i>');
1.329 raeburn 2327: } else {
1.418 raeburn 2328: if ($showall) {
2329: $contextrole = &mt('Existing Roles in this Domain');
2330: } elsif ($showactive) {
2331: $contextrole = &mt('Unexpired Roles in this Domain');
2332: } elsif ($showexpired) {
2333: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2334: }
1.329 raeburn 2335: }
1.393 raeburn 2336: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2337: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2338: &Apache::loncommon::start_data_table("LC_createuser").
1.418 raeburn 2339: &Apache::loncommon::start_data_table_header_row());
2340: if ($showall) {
2341: $r->print(
1.419 raeburn 2342: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1.418 raeburn 2343: );
2344: } elsif ($showexpired) {
2345: $r->print('<th>'.$lt{'rev'}.'</th>');
2346: }
2347: $r->print(
1.419 raeburn 2348: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2349: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2350: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2351: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2352: if ($output{$type}) {
2353: $r->print($output{$type}."\n");
1.217 raeburn 2354: }
2355: }
1.375 raeburn 2356: $r->print(&Apache::loncommon::end_data_table().
2357: '</fieldset></div>');
1.329 raeburn 2358: }
1.217 raeburn 2359: return;
2360: }
2361:
1.218 raeburn 2362: sub new_coauthor_roles {
2363: my ($r,$ccuname,$ccdomain) = @_;
2364: my $addrolesdisplay = 0;
2365: #
2366: # Co-Author
2367: #
1.470 raeburn 2368: my ($cuname,$cudom);
2369: if (($env{'request.role'} eq "au./$env{'user.domain'}/") ||
2370: ($env{'request.role'} eq "dc./$env{'user.domain'}/")) {
2371: $cuname=$env{'user.name'};
2372: $cudom=$env{'request.role.domain'};
1.218 raeburn 2373: # No sense in assigning co-author role to yourself
1.470 raeburn 2374: if ((&Apache::lonuserutils::authorpriv($cuname,$cudom)) &&
2375: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2376: $addrolesdisplay = 1;
2377: }
2378: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2379: ($cudom,$cuname) = ($1,$2);
2380: if ((&Apache::lonuserutils::coauthorpriv($cuname,$cudom)) &&
2381: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain) &&
2382: ($cudom ne $ccdomain || $cuname ne $ccuname)) {
2383: $addrolesdisplay = 1;
2384: }
2385: }
2386: if ($addrolesdisplay) {
1.218 raeburn 2387: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2388: 'cs' => "Authoring Space",
1.218 raeburn 2389: 'act' => "Activate",
2390: 'rol' => "Role",
2391: 'ext' => "Extent",
2392: 'sta' => "Start",
2393: 'end' => "End",
2394: 'cau' => "Co-Author",
2395: 'caa' => "Assistant Co-Author",
2396: 'ssd' => "Set Start Date",
2397: 'sed' => "Set End Date"
2398: );
2399: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2400: &Apache::loncommon::start_data_table()."\n".
2401: &Apache::loncommon::start_data_table_header_row()."\n".
2402: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2403: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2404: '<th>'.$lt{'end'}.'</th>'."\n".
2405: &Apache::loncommon::end_data_table_header_row()."\n".
2406: &Apache::loncommon::start_data_table_row().'
2407: <td>
1.291 bisitz 2408: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2409: </td>
2410: <td>'.$lt{'cau'}.'</td>
2411: <td>'.$cudom.'_'.$cuname.'</td>
2412: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2413: <a href=
2414: "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>
2415: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2416: <a href=
2417: "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".
2418: &Apache::loncommon::end_data_table_row()."\n".
2419: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2420: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2421: <td>'.$lt{'caa'}.'</td>
2422: <td>'.$cudom.'_'.$cuname.'</td>
2423: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2424: <a href=
2425: "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>
2426: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2427: <a href=
2428: "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".
2429: &Apache::loncommon::end_data_table_row()."\n".
2430: &Apache::loncommon::end_data_table());
2431: } elsif ($env{'request.role'} =~ /^au\./) {
2432: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2433: $env{'request.role.domain'}))) {
2434: $r->print('<span class="LC_error">'.
2435: &mt('You do not have privileges to assign co-author roles.').
2436: '</span>');
2437: } elsif (($env{'user.name'} eq $ccuname) &&
2438: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2439: $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 2440: }
1.470 raeburn 2441: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2442: if (!(&Apache::lonuserutils::coauthorpriv($2,$1))) {
2443: $r->print('<span class="LC_error">'.
2444: &mt('You do not have privileges to assign co-author roles.').
2445: '</span>');
2446: } elsif (($env{'user.name'} eq $ccuname) &&
2447: ($env{'user.domain'} eq $ccdomain)) {
2448: $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'));
2449: } elsif (($cudom eq $ccdomain) && ($cuname eq $ccuname)) {
2450: $r->print(&mt("Assigning a co-author or assistant co-author role to an Authoring Space's author is not permitted"));
2451: }
1.218 raeburn 2452: }
2453: return $addrolesdisplay;;
2454: }
2455:
2456: sub new_domain_roles {
1.357 raeburn 2457: my ($r,$ccdomain) = @_;
1.218 raeburn 2458: my $addrolesdisplay = 0;
2459: #
2460: # Domain level
2461: #
2462: my $num_domain_level = 0;
2463: my $domaintext =
2464: '<h4>'.&mt('Domain Level').'</h4>'.
2465: &Apache::loncommon::start_data_table().
2466: &Apache::loncommon::start_data_table_header_row().
2467: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2468: &mt('Extent').'</th>'.
2469: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2470: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2471: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.445 raeburn 2472: my $uprimary = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2473: my $uintdom = &Apache::lonnet::internet_dom($uprimary);
1.218 raeburn 2474: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2475: foreach my $role (@allroles) {
2476: next if ($role eq 'ad');
1.357 raeburn 2477: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2478: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1.445 raeburn 2479: if ($role eq 'dc') {
2480: unless ($thisdomain eq $env{'request.role.domain'}) {
2481: my $domprim = &Apache::lonnet::domain($thisdomain,'primary');
2482: my $intdom = &Apache::lonnet::internet_dom($domprim);
2483: next unless ($uintdom eq $intdom);
2484: }
2485: }
1.218 raeburn 2486: my $plrole=&Apache::lonnet::plaintext($role);
2487: my %lt=&Apache::lonlocal::texthash(
2488: 'ssd' => "Set Start Date",
2489: 'sed' => "Set End Date"
2490: );
2491: $num_domain_level ++;
2492: $domaintext .=
2493: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2494: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2495: <td>'.$plrole.'</td>
2496: <td>'.$thisdomain.'</td>
2497: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2498: <a href=
2499: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2500: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2501: <a href=
2502: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2503: &Apache::loncommon::end_data_table_row();
2504: }
2505: }
2506: }
2507: $domaintext.= &Apache::loncommon::end_data_table();
2508: if ($num_domain_level > 0) {
2509: $r->print($domaintext);
2510: $addrolesdisplay = 1;
2511: }
2512: return $addrolesdisplay;
2513: }
2514:
1.188 raeburn 2515: sub user_authentication {
1.451 raeburn 2516: my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
1.188 raeburn 2517: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2518: my $outcome;
1.418 raeburn 2519: my %lt=&Apache::lonlocal::texthash(
2520: 'err' => "ERROR",
2521: 'uuas' => "This user has an unrecognized authentication scheme",
2522: 'adcs' => "Please alert a domain coordinator of this situation",
2523: 'sldb' => "Please specify login data below",
2524: 'ld' => "Login Data"
2525: );
1.188 raeburn 2526: # Check for a bad authentication type
1.449 raeburn 2527: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth|lti):/) {
1.188 raeburn 2528: # bad authentication scheme
2529: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2530: &initialize_authen_forms($ccdomain,$formname);
2531:
1.190 raeburn 2532: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2533: $outcome = <<ENDBADAUTH;
2534: <script type="text/javascript" language="Javascript">
1.301 bisitz 2535: // <![CDATA[
1.188 raeburn 2536: $loginscript
1.301 bisitz 2537: // ]]>
1.188 raeburn 2538: </script>
2539: <span class="LC_error">$lt{'err'}:
2540: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2541: <h3>$lt{'ld'}</h3>
2542: $choices
2543: ENDBADAUTH
2544: } else {
2545: # This user is not allowed to modify the user's
2546: # authentication scheme, so just notify them of the problem
2547: $outcome = <<ENDBADAUTH;
2548: <span class="LC_error"> $lt{'err'}:
2549: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2550: </span>
2551: ENDBADAUTH
2552: }
2553: } else { # Authentication type is valid
1.418 raeburn 2554:
1.227 raeburn 2555: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2556: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2557: &modify_login_block($ccdomain,$currentauth);
2558: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2559: # Current user has login modification privileges
2560: $outcome =
2561: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2562: '// <![CDATA['."\n".
1.188 raeburn 2563: $loginscript."\n".
1.301 bisitz 2564: '// ]]>'."\n".
1.188 raeburn 2565: '</script>'."\n".
2566: '<h3>'.$lt{'ld'}.'</h3>'.
2567: &Apache::loncommon::start_data_table().
1.205 raeburn 2568: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2569: '<td>'.$authformnop;
1.418 raeburn 2570: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2571: $outcome .= '</td>'."\n".
2572: &Apache::loncommon::end_data_table_row().
2573: &Apache::loncommon::start_data_table_row().
2574: '<td>'.$authformcurrent.'</td>'.
2575: &Apache::loncommon::end_data_table_row()."\n";
2576: } else {
1.200 raeburn 2577: $outcome .= ' ('.$authformcurrent.')</td>'.
2578: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2579: }
1.418 raeburn 2580: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2581: foreach my $item (@authform_others) {
2582: $outcome .= &Apache::loncommon::start_data_table_row().
2583: '<td>'.$item.'</td>'.
2584: &Apache::loncommon::end_data_table_row()."\n";
2585: }
1.188 raeburn 2586: }
1.205 raeburn 2587: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2588: } else {
1.451 raeburn 2589: if (($currentauth =~ /^internal:/) &&
2590: (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
2591: $outcome = <<"ENDJS";
2592: <script type="text/javascript">
2593: // <![CDATA[
2594: function togglePwd(form) {
2595: if (form.newintpwd.length) {
2596: if (document.getElementById('LC_ownersetpwd')) {
2597: for (var i=0; i<form.newintpwd.length; i++) {
2598: if (form.newintpwd[i].checked) {
2599: if (form.newintpwd[i].value == 1) {
2600: document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
2601: } else {
2602: document.getElementById('LC_ownersetpwd').style.display = 'none';
2603: }
2604: }
2605: }
2606: }
2607: }
2608: }
2609: // ]]>
2610: </script>
2611: ENDJS
2612:
2613: $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
2614: &Apache::loncommon::start_data_table().
2615: &Apache::loncommon::start_data_table_row().
2616: '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
2617: '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
2618: &mt('No').'</label>'.(' 'x2).
2619: '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
2620: '<div id="LC_ownersetpwd" style="display:none">'.
2621: ' '.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
2622: '<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>'.
2623: &Apache::loncommon::end_data_table_row().
2624: &Apache::loncommon::end_data_table();
2625: }
1.418 raeburn 2626: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2627: # Current user has rights to view domain preferences for user's domain
2628: my $result;
2629: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2630: my ($krbver,$krbrealm) = ($1,$2);
2631: if ($krbrealm eq '') {
2632: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2633: } else {
2634: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.426 raeburn 2635: $krbrealm,$krbver);
1.418 raeburn 2636: }
2637: } elsif ($currentauth =~ /^internal:/) {
2638: $result = &mt('Currently internally authenticated.');
2639: } elsif ($currentauth =~ /^localauth:/) {
2640: $result = &mt('Currently using local (institutional) authentication.');
2641: } elsif ($currentauth =~ /^unix:/) {
2642: $result = &mt('Currently Filesystem Authenticated.');
1.449 raeburn 2643: } elsif ($currentauth =~ /^lti:/) {
1.451 raeburn 2644: $result = &mt('Currently LTI authenticated.');
1.418 raeburn 2645: }
2646: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2647: &Apache::loncommon::start_data_table().
2648: &Apache::loncommon::start_data_table_row().
2649: '<td>'.$result.'</td>'.
2650: &Apache::loncommon::end_data_table_row()."\n".
2651: &Apache::loncommon::end_data_table();
2652: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2653: my %lt=&Apache::lonlocal::texthash(
2654: 'ccld' => "Change Current Login Data",
2655: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2656: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2657: );
2658: $outcome .= <<ENDNOPRIV;
2659: <h3>$lt{'ccld'}</h3>
2660: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2661: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2662: ENDNOPRIV
2663: }
2664: }
2665: } ## End of "check for bad authentication type" logic
2666: return $outcome;
2667: }
2668:
1.187 raeburn 2669: sub modify_login_block {
2670: my ($dom,$currentauth) = @_;
2671: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2672: my ($authnum,%can_assign) =
2673: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2674: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2675: if ($currentauth=~/^krb(4|5):/) {
2676: $authformcurrent=$authformkrb;
2677: if ($can_assign{'int'}) {
1.205 raeburn 2678: push(@authform_others,$authformint);
1.187 raeburn 2679: }
2680: if ($can_assign{'loc'}) {
1.205 raeburn 2681: push(@authform_others,$authformloc);
1.187 raeburn 2682: }
1.449 raeburn 2683: if ($can_assign{'lti'}) {
2684: push(@authform_others,$authformlti);
2685: }
1.187 raeburn 2686: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2687: $show_override_msg = 1;
2688: }
2689: } elsif ($currentauth=~/^internal:/) {
2690: $authformcurrent=$authformint;
2691: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2692: push(@authform_others,$authformkrb);
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{'int'}) {
2701: $show_override_msg = 1;
2702: }
2703: } elsif ($currentauth=~/^unix:/) {
2704: $authformcurrent=$authformfsys;
2705: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2706: push(@authform_others,$authformkrb);
1.187 raeburn 2707: }
2708: if ($can_assign{'int'}) {
1.205 raeburn 2709: push(@authform_others,$authformint);
1.187 raeburn 2710: }
2711: if ($can_assign{'loc'}) {
1.205 raeburn 2712: push(@authform_others,$authformloc);
1.187 raeburn 2713: }
1.449 raeburn 2714: if ($can_assign{'lti'}) {
2715: push(@authform_others,$authformlti);
2716: }
1.187 raeburn 2717: if ($can_assign{'fsys'}) {
2718: $show_override_msg = 1;
2719: }
2720: } elsif ($currentauth=~/^localauth:/) {
2721: $authformcurrent=$authformloc;
2722: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2723: push(@authform_others,$authformkrb);
1.187 raeburn 2724: }
2725: if ($can_assign{'int'}) {
1.205 raeburn 2726: push(@authform_others,$authformint);
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{'loc'}) {
2732: $show_override_msg = 1;
2733: }
1.449 raeburn 2734: } elsif ($currentauth=~/^lti:/) {
2735: $authformcurrent=$authformlti;
2736: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2737: push(@authform_others,$authformkrb);
2738: }
2739: if ($can_assign{'int'}) {
2740: push(@authform_others,$authformint);
2741: }
2742: if ($can_assign{'loc'}) {
2743: push(@authform_others,$authformloc);
2744: }
1.187 raeburn 2745: }
2746: if ($show_override_msg) {
1.205 raeburn 2747: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2748: '</td></tr>'."\n".
2749: '<tr><td> </td>'.
2750: '<td><b>'.&mt('Currently in use').'</b></td>'.
2751: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2752: &mt('will override current values').
1.205 raeburn 2753: '</span></td></tr></table>';
1.187 raeburn 2754: }
1.205 raeburn 2755: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2756: }
2757:
1.188 raeburn 2758: sub personal_data_display {
1.470 raeburn 2759: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$readonly,$rolesarray,$now,
1.456 raeburn 2760: $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
1.470 raeburn 2761: my ($output,%userenv,%canmodify,%canmodify_status,$disabled);
1.219 raeburn 2762: my @userinfo = ('firstname','middlename','lastname','generation',
2763: 'permanentemail','id');
1.252 raeburn 2764: my $rowcount = 0;
2765: my $editable = 0;
1.391 raeburn 2766: my %textboxsize = (
2767: firstname => '15',
2768: middlename => '15',
2769: lastname => '15',
2770: generation => '5',
2771: permanentemail => '25',
2772: id => '15',
2773: );
2774:
2775: my %lt=&Apache::lonlocal::texthash(
2776: 'pd' => "Personal Data",
2777: 'firstname' => "First Name",
2778: 'middlename' => "Middle Name",
2779: 'lastname' => "Last Name",
2780: 'generation' => "Generation",
2781: 'permanentemail' => "Permanent e-mail address",
2782: 'id' => "Student/Employee ID",
2783: 'lg' => "Login Data",
2784: 'inststatus' => "Affiliation",
2785: 'email' => 'E-mail address',
2786: 'valid' => 'Validation',
1.442 raeburn 2787: 'username' => 'Username',
1.391 raeburn 2788: );
2789:
2790: %canmodify_status =
1.286 raeburn 2791: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2792: ['inststatus'],$rolesarray);
1.253 raeburn 2793: if (!$newuser) {
1.188 raeburn 2794: # Get the users information
2795: %userenv = &Apache::lonnet::get('environment',
2796: ['firstname','middlename','lastname','generation',
1.286 raeburn 2797: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2798: %canmodify =
2799: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2800: \@userinfo,$rolesarray);
1.257 raeburn 2801: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2802: if ($newuser eq 'email') {
1.396 raeburn 2803: if (ref($emailusername) eq 'HASH') {
2804: if (ref($emailusername->{$usertype}) eq 'HASH') {
2805: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.442 raeburn 2806: @userinfo = ();
1.396 raeburn 2807: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2808: foreach my $field (@{$infofields}) {
2809: if ($emailusername->{$usertype}->{$field}) {
2810: push(@userinfo,$field);
2811: $canmodify{$field} = 1;
2812: unless ($textboxsize{$field}) {
2813: $textboxsize{$field} = 25;
2814: }
2815: unless ($lt{$field}) {
2816: $lt{$field} = $infotitles->{$field};
2817: }
2818: if ($emailusername->{$usertype}->{$field} eq 'required') {
2819: $lt{$field} .= '<b>*</b>';
2820: }
1.391 raeburn 2821: }
2822: }
2823: }
2824: }
2825: }
2826: } else {
2827: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2828: $inst_results,$rolesarray);
2829: }
1.470 raeburn 2830: } elsif ($readonly) {
2831: $disabled = ' disabled="disabled"';
1.188 raeburn 2832: }
1.391 raeburn 2833:
1.188 raeburn 2834: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2835: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2836: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2837: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.443 raeburn 2838: my $size = 25;
1.442 raeburn 2839: if ($condition) {
1.443 raeburn 2840: if ($condition =~ /^\@[^\@]+$/) {
2841: $size = 10;
1.442 raeburn 2842: } else {
2843: undef($condition);
2844: }
1.443 raeburn 2845: }
2846: if ($excluded) {
2847: unless ($excluded =~ /^\@[^\@]+$/) {
2848: undef($condition);
2849: }
1.442 raeburn 2850: }
1.396 raeburn 2851: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2852: 'LC_oddrow_value')."\n".
1.443 raeburn 2853: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2854: if ($condition) {
2855: $output .= $condition;
2856: } elsif ($excluded) {
2857: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2858: $excluded).'</span>';
2859: }
2860: if ($usernameset eq 'first') {
2861: $output .= '<br /><span style="font-size: smaller">';
2862: if ($condition) {
2863: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2864: $condition);
2865: } else {
2866: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2867: }
2868: $output .= '</span>';
2869: }
1.391 raeburn 2870: $rowcount ++;
2871: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.460 raeburn 2872: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="new-password" />';
2873: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="new-password" />';
1.396 raeburn 2874: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2875: 'LC_pick_box_title',
2876: 'LC_oddrow_value')."\n".
2877: $upassone."\n".
2878: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2879: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2880: 'LC_pick_box_title',
2881: 'LC_oddrow_value')."\n".
2882: $upasstwo.
2883: &Apache::lonhtmlcommon::row_closure()."\n";
1.443 raeburn 2884: if ($usernameset eq 'free') {
2885: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
1.442 raeburn 2886: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
1.455 raeburn 2887: '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
2888: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
2889: &mt('Yes').'</label>'.(' 'x2).
2890: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
2891: &mt('No').'</label></span>'."\n".
1.442 raeburn 2892: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2893: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2894: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2895: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2896: $rowcount ++;
2897: }
1.391 raeburn 2898: }
1.188 raeburn 2899: foreach my $item (@userinfo) {
2900: my $rowtitle = $lt{$item};
1.252 raeburn 2901: my $hiderow = 0;
1.188 raeburn 2902: if ($item eq 'generation') {
2903: $rowtitle = $genhelp.$rowtitle;
2904: }
1.252 raeburn 2905: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2906: if ($newuser) {
1.210 raeburn 2907: if (ref($inst_results) eq 'HASH') {
2908: if ($inst_results->{$item} ne '') {
1.252 raeburn 2909: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2910: } else {
1.252 raeburn 2911: if ($context eq 'selfcreate') {
1.391 raeburn 2912: if ($canmodify{$item}) {
1.394 raeburn 2913: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2914: $editable ++;
2915: } else {
2916: $hiderow = 1;
2917: }
1.253 raeburn 2918: } else {
1.470 raeburn 2919: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value=""'.$disabled.' />';
1.252 raeburn 2920: }
1.210 raeburn 2921: }
1.188 raeburn 2922: } else {
1.252 raeburn 2923: if ($context eq 'selfcreate') {
1.401 raeburn 2924: if ($canmodify{$item}) {
2925: if ($newuser eq 'email') {
2926: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2927: } else {
1.401 raeburn 2928: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2929: }
1.401 raeburn 2930: $editable ++;
2931: } else {
2932: $hiderow = 1;
1.252 raeburn 2933: }
1.253 raeburn 2934: } else {
1.470 raeburn 2935: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value=""'.$disabled.' />';
1.252 raeburn 2936: }
1.188 raeburn 2937: }
2938: } else {
1.219 raeburn 2939: if ($canmodify{$item}) {
1.252 raeburn 2940: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2941: if (($item eq 'id') && (!$newuser)) {
2942: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2943: }
1.188 raeburn 2944: } else {
1.252 raeburn 2945: $row .= $userenv{$item};
1.188 raeburn 2946: }
2947: }
1.252 raeburn 2948: $row .= &Apache::lonhtmlcommon::row_closure(1);
2949: if (!$hiderow) {
2950: $output .= $row;
2951: $rowcount ++;
2952: }
1.188 raeburn 2953: }
1.286 raeburn 2954: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2955: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2956: if (ref($types) eq 'ARRAY') {
2957: if (@{$types} > 0) {
2958: my ($hiderow,$shown);
2959: if ($canmodify_status{'inststatus'}) {
2960: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2961: } else {
2962: if ($userenv{'inststatus'} eq '') {
2963: $hiderow = 1;
1.334 raeburn 2964: } else {
2965: my @showitems;
2966: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2967: if (exists($usertypes->{$item})) {
2968: push(@showitems,$usertypes->{$item});
2969: } else {
2970: push(@showitems,$item);
2971: }
2972: }
2973: if (@showitems) {
2974: $shown = join(', ',@showitems);
2975: } else {
2976: $hiderow = 1;
2977: }
1.286 raeburn 2978: }
2979: }
2980: if (!$hiderow) {
1.389 bisitz 2981: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2982: $shown.&Apache::lonhtmlcommon::row_closure(1);
2983: if ($context eq 'selfcreate') {
2984: $rowcount ++;
2985: }
2986: $output .= $row;
2987: }
2988: }
2989: }
2990: }
1.391 raeburn 2991: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2992: if ($captchaform) {
1.410 raeburn 2993: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2994: 'LC_pick_box_title')."\n".
1.456 raeburn 2995: $captchaform."\n".'<br /><br />'.
1.391 raeburn 2996: &Apache::lonhtmlcommon::row_closure(1);
2997: $rowcount ++;
2998: }
1.456 raeburn 2999: if ($showsubmit) {
3000: my $submit_text = &mt('Create account');
3001: $output .= &Apache::lonhtmlcommon::row_title()."\n".
3002: '<br /><input type="submit" name="createaccount" value="'.
3003: $submit_text.'" />';
3004: if ($usertype ne '') {
3005: $output .= '<input type="hidden" name="type" value="'.
3006: &HTML::Entities::encode($usertype,'\'<>"&').'" />';
3007: }
3008: $output .= &Apache::lonhtmlcommon::row_closure(1);
3009: }
1.391 raeburn 3010: }
1.188 raeburn 3011: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 3012: if (wantarray) {
1.252 raeburn 3013: if ($context eq 'selfcreate') {
3014: return($output,$rowcount,$editable);
3015: } else {
1.388 bisitz 3016: return $output;
1.252 raeburn 3017: }
1.206 raeburn 3018: } else {
3019: return $output;
3020: }
1.188 raeburn 3021: }
3022:
1.286 raeburn 3023: sub pick_inst_statuses {
3024: my ($curr,$usertypes,$types) = @_;
3025: my ($output,$rem,@currtypes);
3026: if ($curr ne '') {
3027: @currtypes = map { &unescape($_); } split(/:/,$curr);
3028: }
3029: my $numinrow = 2;
3030: if (ref($types) eq 'ARRAY') {
3031: $output = '<table>';
3032: my $lastcolspan;
3033: for (my $i=0; $i<@{$types}; $i++) {
3034: if (defined($usertypes->{$types->[$i]})) {
3035: my $rem = $i%($numinrow);
3036: if ($rem == 0) {
3037: if ($i<@{$types}-1) {
3038: if ($i > 0) {
3039: $output .= '</tr>';
3040: }
3041: $output .= '<tr>';
3042: }
3043: } elsif ($i==@{$types}-1) {
3044: my $colsleft = $numinrow - $rem;
3045: if ($colsleft > 1) {
3046: $lastcolspan = ' colspan="'.$colsleft.'"';
3047: }
3048: }
3049: my $check = ' ';
3050: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
3051: $check = ' checked="checked" ';
3052: }
3053: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
3054: '<span class="LC_nobreak"><label>'.
3055: '<input type="checkbox" name="inststatus" '.
3056: 'value="'.$types->[$i].'"'.$check.'/>'.
3057: $usertypes->{$types->[$i]}.'</label></span></td>';
3058: }
3059: }
3060: $output .= '</tr></table>';
3061: }
3062: return $output;
3063: }
3064:
1.257 raeburn 3065: sub selfcreate_canmodify {
3066: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
3067: if (ref($inst_results) eq 'HASH') {
3068: my @inststatuses = &get_inststatuses($inst_results);
3069: if (@inststatuses == 0) {
3070: @inststatuses = ('default');
3071: }
3072: $rolesarray = \@inststatuses;
3073: }
3074: my %canmodify =
3075: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
3076: $rolesarray);
3077: return %canmodify;
3078: }
3079:
1.252 raeburn 3080: sub get_inststatuses {
3081: my ($insthashref) = @_;
3082: my @inststatuses = ();
3083: if (ref($insthashref) eq 'HASH') {
3084: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
3085: @inststatuses = @{$insthashref->{'inststatus'}};
3086: }
3087: }
3088: return @inststatuses;
3089: }
3090:
1.4 www 3091: # ================================================================= Phase Three
1.42 matthew 3092: sub update_user_data {
1.451 raeburn 3093: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 3094: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
3095: $env{'form.ccdomain'});
1.27 matthew 3096: # Error messages
1.188 raeburn 3097: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 3098: my $end = '</span><br /><br />';
3099: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 3100: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 3101: &mt('Return to previous page').'</a>'.
3102: &Apache::loncommon::end_page();
3103: my $now = time;
1.40 www 3104: my $title;
1.101 albertel 3105: if (exists($env{'form.makeuser'})) {
1.40 www 3106: $title='Set Privileges for New User';
3107: } else {
3108: $title='Modify User Privileges';
3109: }
1.213 raeburn 3110: my $newuser = 0;
1.160 raeburn 3111: my ($jsback,$elements) = &crumb_utilities();
3112: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 3113: '// <![CDATA['."\n".
3114: $jsback."\n".
3115: '// ]]>'."\n".
3116: '</script>'."\n";
1.422 raeburn 3117: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 3118: push (@{$brcrum},
3119: {href => "javascript:backPage(document.userupdate)",
3120: text => $breadcrumb_text{'search'},
3121: faq => 282,
3122: bug => 'Instructor Interface',}
3123: );
3124: if ($env{'form.prevphase'} eq 'userpicked') {
3125: push(@{$brcrum},
3126: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
3127: text => $breadcrumb_text{'userpicked'},
3128: faq => 282,
3129: bug => 'Instructor Interface',});
1.233 raeburn 3130: }
1.224 raeburn 3131: my $helpitem = 'Course_Change_Privileges';
3132: if ($env{'form.action'} eq 'singlestudent') {
3133: $helpitem = 'Course_Add_Student';
1.439 raeburn 3134: } elsif ($context eq 'author') {
3135: $helpitem = 'Author_Change_Privileges';
3136: } elsif ($context eq 'domain') {
3137: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 3138: }
1.351 raeburn 3139: push(@{$brcrum},
3140: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
3141: text => $breadcrumb_text{'modify'},
3142: faq => 282,
3143: bug => 'Instructor Interface',},
3144: {href => "/adm/createuser",
3145: text => "Result",
3146: faq => 282,
3147: bug => 'Instructor Interface',
3148: help => $helpitem});
3149: my $args = {bread_crumbs => $brcrum,
3150: bread_crumbs_component => 'User Management'};
3151: if ($env{'form.popup'}) {
3152: $args->{'no_nav_bar'} = 1;
3153: }
3154: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 3155: $r->print(&update_result_form($uhome));
1.27 matthew 3156: # Check Inputs
1.101 albertel 3157: if (! $env{'form.ccuname'} ) {
1.193 raeburn 3158: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 3159: return;
3160: }
1.138 albertel 3161: if ( $env{'form.ccuname'} ne
3162: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 3163: $r->print($error.&mt('Invalid login name.').' '.
3164: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 3165: $end.$rtnlink);
1.27 matthew 3166: return;
3167: }
1.101 albertel 3168: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 3169: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 3170: return;
3171: }
1.138 albertel 3172: if ( $env{'form.ccdomain'} ne
3173: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 3174: $r->print($error.&mt('Invalid domain name.').' '.
3175: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 3176: $end.$rtnlink);
1.27 matthew 3177: return;
3178: }
1.219 raeburn 3179: if ($uhome eq 'no_host') {
3180: $newuser = 1;
3181: }
1.101 albertel 3182: if (! exists($env{'form.makeuser'})) {
1.29 matthew 3183: # Modifying an existing user, so check the validity of the name
3184: if ($uhome eq 'no_host') {
1.389 bisitz 3185: $r->print(
3186: $error
3187: .'<p class="LC_error">'
3188: .&mt('Unable to determine home server for [_1] in domain [_2].',
3189: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
3190: .'</p>');
1.29 matthew 3191: return;
3192: }
3193: }
1.27 matthew 3194: # Determine authentication method and password for the user being modified
3195: my $amode='';
3196: my $genpwd='';
1.101 albertel 3197: if ($env{'form.login'} eq 'krb') {
1.41 albertel 3198: $amode='krb';
1.101 albertel 3199: $amode.=$env{'form.krbver'};
3200: $genpwd=$env{'form.krbarg'};
3201: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 3202: $amode='internal';
1.101 albertel 3203: $genpwd=$env{'form.intarg'};
3204: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 3205: $amode='unix';
1.101 albertel 3206: $genpwd=$env{'form.fsysarg'};
3207: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 3208: $amode='localauth';
1.101 albertel 3209: $genpwd=$env{'form.locarg'};
1.27 matthew 3210: $genpwd=" " if (!$genpwd);
1.449 raeburn 3211: } elsif ($env{'form.login'} eq 'lti') {
3212: $amode='lti';
3213: $genpwd=" ";
1.101 albertel 3214: } elsif (($env{'form.login'} eq 'nochange') ||
3215: ($env{'form.login'} eq '' )) {
1.34 matthew 3216: # There is no need to tell the user we did not change what they
3217: # did not ask us to change.
1.35 matthew 3218: # If they are creating a new user but have not specified login
3219: # information this will be caught below.
1.30 matthew 3220: } else {
1.367 golterma 3221: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
3222: return;
1.27 matthew 3223: }
1.164 albertel 3224:
1.188 raeburn 3225: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 3226: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
3227: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
3228: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 3229:
1.193 raeburn 3230: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 3231: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.470 raeburn 3232: my @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.449 raeburn 3233: my @requestcourses = ('official','unofficial','community','textbook','placement','lti');
1.362 raeburn 3234: my @requestauthor = ('requestauthor');
1.471 raeburn 3235: my @authordefaults = ('webdav','editors');
1.286 raeburn 3236: my ($othertitle,$usertypes,$types) =
3237: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 3238: my %canmodify_status =
3239: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
3240: ['inststatus']);
1.101 albertel 3241: if ($env{'form.makeuser'}) {
1.164 albertel 3242: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 3243: # Check for the authentication mode and password
3244: if (! $amode || ! $genpwd) {
1.193 raeburn 3245: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 3246: return;
1.18 albertel 3247: }
1.29 matthew 3248: # Determine desired host
1.101 albertel 3249: my $desiredhost = $env{'form.hserver'};
1.29 matthew 3250: if (lc($desiredhost) eq 'default') {
3251: $desiredhost = undef;
3252: } else {
1.147 albertel 3253: my %home_servers =
3254: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 3255: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 3256: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
3257: return;
3258: }
3259: }
3260: # Check ID format
3261: my %checkhash;
3262: my %checks = ('id' => 1);
3263: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 3264: 'newuser' => $newuser,
1.196 raeburn 3265: 'id' => $env{'form.cid'},
1.193 raeburn 3266: );
1.196 raeburn 3267: if ($env{'form.cid'} ne '') {
3268: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
3269: \%rulematch,\%inst_results,\%curr_rules);
3270: if (ref($alerts{'id'}) eq 'HASH') {
3271: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
3272: my $domdesc =
3273: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
3274: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
3275: my $userchkmsg;
3276: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
3277: $userchkmsg =
3278: &Apache::loncommon::instrule_disallow_msg('id',
3279: $domdesc,1).
3280: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
3281: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
3282: }
3283: $r->print($error.&mt('Invalid ID format').$end.
3284: $userchkmsg.$rtnlink);
3285: return;
3286: }
3287: }
1.29 matthew 3288: }
3289: }
1.367 golterma 3290: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 3291: # Call modifyuser
3292: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 3293: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 3294: $amode,$genpwd,$env{'form.cfirstname'},
3295: $env{'form.cmiddlename'},$env{'form.clastname'},
3296: $env{'form.cgeneration'},undef,$desiredhost,
3297: $env{'form.cpermanentemail'});
1.77 www 3298: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 3299: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 3300: $env{'form.ccdomain'});
1.334 raeburn 3301: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 3302: if ($uhome ne 'no_host') {
1.334 raeburn 3303: if ($context eq 'domain') {
1.378 raeburn 3304: foreach my $name ('portfolio','author') {
3305: if ($env{'form.custom_'.$name.'quota'} == 1) {
3306: if ($env{'form.'.$name.'quota'} eq '') {
3307: $newcustom{$name.'quota'} = 0;
3308: } else {
3309: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
3310: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
3311: }
3312: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
3313: $changed{$name.'quota'} = 1;
3314: }
1.334 raeburn 3315: }
3316: }
3317: foreach my $item (@usertools) {
3318: if ($env{'form.custom'.$item} == 1) {
3319: $newcustom{$item} = $env{'form.tools_'.$item};
3320: $changed{$item} = &tool_admin($item,$newcustom{$item},
3321: \%changeHash,'tools');
3322: }
1.267 raeburn 3323: }
1.334 raeburn 3324: foreach my $item (@requestcourses) {
1.341 raeburn 3325: if ($env{'form.custom'.$item} == 1) {
3326: $newcustom{$item} = $env{'form.crsreq_'.$item};
3327: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
3328: $newcustom{$item} .= '=';
1.383 raeburn 3329: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
3330: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 3331: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
3332: }
1.334 raeburn 3333: }
1.341 raeburn 3334: $changed{$item} = &tool_admin($item,$newcustom{$item},
3335: \%changeHash,'requestcourses');
1.334 raeburn 3336: }
1.275 raeburn 3337: }
1.362 raeburn 3338: if ($env{'form.customrequestauthor'} == 1) {
3339: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
3340: $changed{'requestauthor'} = &tool_admin('requestauthor',
3341: $newcustom{'requestauthor'},
3342: \%changeHash,'requestauthor');
3343: }
1.470 raeburn 3344: if ($env{'form.customeditors'} == 1) {
3345: my @editors;
3346: my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
3347: if (@posseditors) {
3348: foreach my $editor (@posseditors) {
3349: if (grep(/^\Q$editor\E$/,@posseditors)) {
3350: unless (grep(/^\Q$editor\E$/,@editors)) {
3351: push(@editors,$editor);
3352: }
3353: }
3354: }
3355: }
3356: if (@editors) {
3357: @editors = sort(@editors);
3358: $changed{'editors'} = &tool_admin('editors',join(',',@editors),
3359: \%changeHash,'authordefaults');
3360: }
3361: }
3362: if ($env{'form.customwebdav'} == 1) {
3363: $newcustom{'webdav'} = $env{'form.authordefaults_webdav'};
3364: $changed{'webdav'} = &tool_admin('webdav',$newcustom{'webdav'},
3365: \%changeHash,'authordefaults');
3366: }
1.275 raeburn 3367: }
1.334 raeburn 3368: if ($canmodify_status{'inststatus'}) {
3369: if (exists($env{'form.inststatus'})) {
3370: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3371: if (@inststatuses > 0) {
3372: $changeHash{'inststatus'} = join(',',@inststatuses);
3373: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 3374: }
3375: }
1.232 raeburn 3376: }
1.334 raeburn 3377: if (keys(%changed)) {
3378: foreach my $item (@userinfo) {
3379: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 3380: }
1.267 raeburn 3381: my $chgresult =
3382: &Apache::lonnet::put('environment',\%changeHash,
3383: $env{'form.ccdomain'},$env{'form.ccuname'});
1.470 raeburn 3384: }
1.232 raeburn 3385: }
1.454 raeburn 3386: $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
1.219 raeburn 3387: &Apache::lonnet::hostname($uhome));
1.101 albertel 3388: } elsif (($env{'form.login'} ne 'nochange') &&
3389: ($env{'form.login'} ne '' )) {
1.27 matthew 3390: # Modify user privileges
3391: if (! $amode || ! $genpwd) {
1.193 raeburn 3392: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 3393: return;
1.20 harris41 3394: }
1.395 bisitz 3395: # Only allow authentication modification if the person has authority
1.101 albertel 3396: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 3397: $r->print('Modifying authentication: '.
1.31 matthew 3398: &Apache::lonnet::modifyuserauth(
1.101 albertel 3399: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 3400: $amode,$genpwd));
1.454 raeburn 3401: $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
1.101 albertel 3402: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 3403: } else {
1.27 matthew 3404: # Okay, this is a non-fatal error.
1.452 raeburn 3405: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 3406: }
1.451 raeburn 3407: } elsif (($env{'form.intarg'} ne '') &&
3408: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
3409: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3410: $r->print('Modifying authentication: '.
3411: &Apache::lonnet::modifyuserauth(
3412: $env{'form.ccdomain'},$env{'form.ccuname'},
3413: 'internal',$env{'form.intarg'}));
1.28 matthew 3414: }
1.344 bisitz 3415: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3416: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3417: ##
1.375 raeburn 3418: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3419: if ($context eq 'course') {
1.375 raeburn 3420: ($cnum,$cdom) =
3421: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3422: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3423: if ($showcredits) {
3424: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3425: }
1.213 raeburn 3426: }
1.101 albertel 3427: if (! $env{'form.makeuser'} ) {
1.28 matthew 3428: # Check for need to change
3429: my %userenv = &Apache::lonnet::get
1.134 raeburn 3430: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3431: 'id','permanentemail','portfolioquota','authorquota','inststatus',
1.459 raeburn 3432: 'tools.aboutme','tools.blog','tools.webdav',
1.470 raeburn 3433: 'tools.portfolio','tools.timezone','tools.portaccess',
3434: 'authormanagers','authoreditors','requestauthor',
1.361 raeburn 3435: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3436: 'requestcourses.community','requestcourses.textbook',
1.470 raeburn 3437: 'requestcourses.placement','requestcourses.lti',
1.384 raeburn 3438: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3439: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.471 raeburn 3440: 'reqcrsotherdom.placement','domcoord.author'],
1.160 raeburn 3441: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3442: my ($tmp) = keys(%userenv);
3443: if ($tmp =~ /^(con_lost|error)/i) {
3444: %userenv = ();
3445: }
1.471 raeburn 3446: unless (($userenv{'domcoord.author'} eq 'blocked') &&
3447: (($env{'user.name'} ne $env{'form.ccuname'}) ||
3448: ($env{'user.domain'} ne $env{'form.ccdomain'}))) {
3449: push(@authordefaults,'managers');
3450: }
1.206 raeburn 3451: my $no_forceid_alert;
3452: # Check to see if user information can be changed
3453: my %domconfig =
3454: &Apache::lonnet::get_dom('configuration',['usermodification'],
3455: $env{'form.ccdomain'});
1.213 raeburn 3456: my @statuses = ('active','future');
3457: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3458: my ($auname,$audom);
1.220 raeburn 3459: if ($context eq 'author') {
1.206 raeburn 3460: $auname = $env{'user.name'};
3461: $audom = $env{'user.domain'};
3462: }
3463: foreach my $item (keys(%roles)) {
1.220 raeburn 3464: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3465: if ($context eq 'course') {
3466: if ($cnum ne '' && $cdom ne '') {
3467: if ($rolenum eq $cnum && $roledom eq $cdom) {
3468: if (!grep(/^\Q$role\E$/,@userroles)) {
3469: push(@userroles,$role);
3470: }
3471: }
3472: }
3473: } elsif ($context eq 'author') {
3474: if ($rolenum eq $auname && $roledom eq $audom) {
1.461 raeburn 3475: if (!grep(/^\Q$role\E$/,@userroles)) {
1.206 raeburn 3476: push(@userroles,$role);
3477: }
3478: }
3479: }
3480: }
1.220 raeburn 3481: if ($env{'form.action'} eq 'singlestudent') {
3482: if (!grep(/^st$/,@userroles)) {
3483: push(@userroles,'st');
3484: }
3485: } else {
3486: # Check for course or co-author roles being activated or re-enabled
3487: if ($context eq 'author' || $context eq 'course') {
3488: foreach my $key (keys(%env)) {
3489: if ($context eq 'author') {
3490: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3491: if (!grep(/^\Q$1\E$/,@userroles)) {
3492: push(@userroles,$1);
3493: }
3494: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3495: if (!grep(/^\Q$1\E$/,@userroles)) {
3496: push(@userroles,$1);
3497: }
1.206 raeburn 3498: }
1.220 raeburn 3499: } elsif ($context eq 'course') {
3500: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3501: if (!grep(/^\Q$1\E$/,@userroles)) {
3502: push(@userroles,$1);
3503: }
3504: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3505: if (!grep(/^\Q$1\E$/,@userroles)) {
3506: push(@userroles,$1);
3507: }
1.206 raeburn 3508: }
3509: }
3510: }
3511: }
3512: }
3513: #Check to see if we can change personal data for the user
3514: my (@mod_disallowed,@longroles);
3515: foreach my $role (@userroles) {
3516: if ($role eq 'cr') {
3517: push(@longroles,'Custom');
3518: } else {
1.318 raeburn 3519: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3520: }
3521: }
1.219 raeburn 3522: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3523: foreach my $item (@userinfo) {
1.28 matthew 3524: # Strip leading and trailing whitespace
1.203 raeburn 3525: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3526: if (!$canmodify{$item}) {
1.207 raeburn 3527: if (defined($env{'form.c'.$item})) {
3528: if ($env{'form.c'.$item} ne $userenv{$item}) {
3529: push(@mod_disallowed,$item);
3530: }
1.206 raeburn 3531: }
3532: $env{'form.c'.$item} = $userenv{$item};
3533: }
1.28 matthew 3534: }
1.259 bisitz 3535: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3536: my $forceid = $env{'form.forceid'};
3537: my $recurseid = $env{'form.recurseid'};
3538: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3539: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3540: $env{'form.ccuname'});
3541: if (($uidhash{$env{'form.ccuname'}}) &&
3542: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3543: (!$forceid)) {
3544: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3545: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3546: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3547: .'<br />'
3548: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3549: .'<br />'."\n";
1.203 raeburn 3550: }
3551: }
3552: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3553: my $checkhash;
3554: my $checks = { 'id' => 1 };
3555: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3556: { 'newuser' => $newuser,
3557: 'id' => $env{'form.cid'},
3558: };
3559: &Apache::loncommon::user_rule_check($checkhash,$checks,
3560: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3561: if (ref($alerts{'id'}) eq 'HASH') {
3562: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3563: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3564: }
3565: }
3566: }
1.378 raeburn 3567: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3568: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3569: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3570: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3571: @disporder = ('inststatus');
3572: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.470 raeburn 3573: push(@disporder,('requestcourses','requestauthor','authordefaults'));
1.334 raeburn 3574: } else {
3575: push(@disporder,'reqcrsotherdom');
3576: }
3577: push(@disporder,('quota','tools'));
1.338 raeburn 3578: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3579: foreach my $name ('portfolio','author') {
3580: ($olddefquota{$name},$oldsettingstatus{$name}) =
3581: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3582: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3583: }
1.334 raeburn 3584: my %canshow;
1.220 raeburn 3585: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3586: $canshow{'quota'} = 1;
1.220 raeburn 3587: }
1.267 raeburn 3588: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3589: $canshow{'tools'} = 1;
1.267 raeburn 3590: }
1.275 raeburn 3591: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3592: $canshow{'requestcourses'} = 1;
1.300 raeburn 3593: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3594: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3595: }
1.286 raeburn 3596: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3597: $canshow{'inststatus'} = 1;
1.286 raeburn 3598: }
1.362 raeburn 3599: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3600: $canshow{'requestauthor'} = 1;
1.470 raeburn 3601: $canshow{'authordefaults'} = 1;
1.362 raeburn 3602: }
1.267 raeburn 3603: my (%changeHash,%changed);
1.286 raeburn 3604: if ($oldinststatus eq '') {
1.334 raeburn 3605: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3606: } else {
3607: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3608: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3609: } else {
1.334 raeburn 3610: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3611: }
3612: }
3613: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3614: if ($canmodify_status{'inststatus'}) {
3615: $canshow{'inststatus'} = 1;
1.286 raeburn 3616: if (exists($env{'form.inststatus'})) {
3617: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3618: if (@inststatuses > 0) {
3619: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3620: $changeHash{'inststatus'} = $newinststatus;
3621: if ($newinststatus ne $oldinststatus) {
3622: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3623: foreach my $name ('portfolio','author') {
3624: ($newdefquota{$name},$newsettingstatus{$name}) =
3625: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3626: }
1.286 raeburn 3627: }
3628: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3629: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3630: } else {
1.337 raeburn 3631: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3632: }
1.334 raeburn 3633: }
3634: } else {
3635: $newinststatus = '';
3636: $changeHash{'inststatus'} = $newinststatus;
3637: $newsettings{'inststatus'} = $othertitle;
3638: if ($newinststatus ne $oldinststatus) {
3639: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3640: foreach my $name ('portfolio','author') {
3641: ($newdefquota{$name},$newsettingstatus{$name}) =
3642: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3643: }
1.286 raeburn 3644: }
3645: }
1.334 raeburn 3646: } elsif ($context ne 'selfcreate') {
3647: $canshow{'inststatus'} = 1;
1.337 raeburn 3648: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3649: }
1.378 raeburn 3650: foreach my $name ('portfolio','author') {
3651: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3652: }
1.334 raeburn 3653: if ($context eq 'domain') {
1.378 raeburn 3654: foreach my $name ('portfolio','author') {
3655: if ($userenv{$name.'quota'} ne '') {
3656: $oldquota{$name} = $userenv{$name.'quota'};
3657: if ($env{'form.custom_'.$name.'quota'} == 1) {
3658: if ($env{'form.'.$name.'quota'} eq '') {
3659: $newquota{$name} = 0;
3660: } else {
3661: $newquota{$name} = $env{'form.'.$name.'quota'};
3662: $newquota{$name} =~ s/[^\d\.]//g;
3663: }
3664: if ($newquota{$name} != $oldquota{$name}) {
3665: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3666: $changed{$name.'quota'} = 1;
3667: }
3668: }
1.334 raeburn 3669: } else {
1.378 raeburn 3670: if ("a_admin('',\%changeHash,$name)) {
3671: $changed{$name.'quota'} = 1;
3672: $newquota{$name} = $newdefquota{$name};
3673: $newisdefault{$name} = 1;
3674: }
1.334 raeburn 3675: }
1.149 raeburn 3676: } else {
1.378 raeburn 3677: $oldisdefault{$name} = 1;
3678: $oldquota{$name} = $olddefquota{$name};
3679: if ($env{'form.custom_'.$name.'quota'} == 1) {
3680: if ($env{'form.'.$name.'quota'} eq '') {
3681: $newquota{$name} = 0;
3682: } else {
3683: $newquota{$name} = $env{'form.'.$name.'quota'};
3684: $newquota{$name} =~ s/[^\d\.]//g;
3685: }
3686: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3687: $changed{$name.'quota'} = 1;
3688: }
1.334 raeburn 3689: } else {
1.378 raeburn 3690: $newquota{$name} = $newdefquota{$name};
3691: $newisdefault{$name} = 1;
1.334 raeburn 3692: }
1.378 raeburn 3693: }
3694: if ($oldisdefault{$name}) {
3695: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3696: } else {
3697: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3698: }
3699: if ($newisdefault{$name}) {
3700: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3701: } else {
3702: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3703: }
3704: }
1.334 raeburn 3705: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3706: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3707: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3708: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3709: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.470 raeburn 3710: my ($isadv,$isauthor) =
3711: &Apache::lonnet::is_advanced_user($env{'form.ccdomain'},$env{'form.ccuname'});
3712: unless ($isauthor) {
3713: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3714: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3715: }
3716: &tool_changes('authordefaults',\@authordefaults,\%oldsettings,\%oldsettingstext,
3717: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3718: } else {
1.334 raeburn 3719: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3720: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3721: }
3722: }
1.334 raeburn 3723: foreach my $item (@userinfo) {
3724: if ($env{'form.c'.$item} ne $userenv{$item}) {
3725: $namechanged{$item} = 1;
3726: }
1.204 raeburn 3727: }
1.378 raeburn 3728: foreach my $name ('portfolio','author') {
1.390 bisitz 3729: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3730: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3731: }
1.334 raeburn 3732: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3733: my ($chgresult,$namechgresult);
3734: if (keys(%changed) > 0) {
1.470 raeburn 3735: $chgresult =
1.204 raeburn 3736: &Apache::lonnet::put('environment',\%changeHash,
3737: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3738: if ($chgresult eq 'ok') {
1.470 raeburn 3739: my ($ca_mgr_del,%ca_mgr_add);
3740: if ($changed{'managers'}) {
3741: my (@adds,@dels);
3742: if ($changeHash{'authormanagers'} eq '') {
3743: @dels = split(/,/,$userenv{'authormanagers'});
3744: } elsif ($userenv{'authormanagers'} eq '') {
3745: @adds = split(/,/,$changeHash{'authormanagers'});
3746: } else {
3747: my @old = split(/,/,$userenv{'authormanagers'});
3748: my @new = split(/,/,$changeHash{'authormanagers'});
3749: my @diffs = &Apache::loncommon::compare_arrays(\@old,\@new);
3750: if (@diffs) {
3751: foreach my $user (@diffs) {
3752: if (grep(/^\Q$user\E$/,@old)) {
3753: push(@dels,$user);
3754: } elsif (grep(/^\Q$user\E$/,@new)) {
3755: push(@adds,$user);
3756: }
3757: }
3758: }
3759: }
3760: my $key = "internal.manager./$env{'form.ccdomain'}/$env{'form.ccuname'}";
3761: if (@dels) {
3762: foreach my $user (@dels) {
3763: if ($user =~ /^($match_username):($match_domain)$/) {
3764: &Apache::lonnet::del('environment',[$key],$2,$1);
3765: }
3766: }
3767: my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
3768: if (grep(/^\Q$curruser\E$/,@dels)) {
3769: $ca_mgr_del = $key;
3770: }
3771: }
3772: if (@adds) {
3773: foreach my $user (@adds) {
3774: if ($user =~ /^($match_username):($match_domain)$/) {
3775: &Apache::lonnet::put('environment',{$key => 1},$2,$1);
3776: }
3777: }
3778: my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
3779: if (grep(/^\Q$curruser\E$/,@adds)) {
3780: $ca_mgr_add{$key} = 1;
3781: }
3782: }
3783: }
1.267 raeburn 3784: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3785: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.474 ! raeburn 3786: my (%newenvhash,$got_domdefs,%domdefaults,$got_userenv,
! 3787: %userenv);
! 3788: my @fromenv = keys(%changed);
! 3789: push(@fromenv,'inststatus');
1.270 raeburn 3790: foreach my $key (keys(%changed)) {
1.411 raeburn 3791: if (($key eq 'official') || ($key eq 'unofficial') ||
3792: ($key eq 'community') || ($key eq 'textbook') ||
1.449 raeburn 3793: ($key eq 'placement') || ($key eq 'lti')) {
1.279 raeburn 3794: $newenvhash{'environment.requestcourses.'.$key} =
3795: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3796: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3797: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3798: } else {
1.474 ! raeburn 3799: unless ($got_domdefs) {
! 3800: %domdefaults =
! 3801: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
! 3802: $got_domdefs = 1;
! 3803: }
! 3804: unless ($got_userenv) {
! 3805: %userenv =
! 3806: &Apache::lonnet::userenvironment($env{'user.domain'},
! 3807: $env{'user.name'},@fromenv);
! 3808: $got_userenv = 1;
! 3809: }
1.279 raeburn 3810: $newenvhash{'environment.canrequest.'.$key} =
3811: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.474 ! raeburn 3812: $key,'reload','requestcourses',\%userenv,\%domdefaults);
1.279 raeburn 3813: }
1.362 raeburn 3814: } elsif ($key eq 'requestauthor') {
3815: $newenvhash{'environment.'.$key} = $changeHash{$key};
3816: if ($changeHash{$key}) {
3817: $newenvhash{'environment.canrequest.author'} = 1;
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.362 raeburn 3830: $newenvhash{'environment.canrequest.author'} =
3831: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.474 ! raeburn 3832: $key,'reload','requestauthor',\%userenv,\%domdefaults);
1.362 raeburn 3833: }
1.470 raeburn 3834: } elsif ($key eq 'editors') {
3835: $newenvhash{'environment.author'.$key} = $changeHash{'author'.$key};
1.474 ! raeburn 3836: if ($env{'form.customeditors'}) {
! 3837: $newenvhash{'environment.editors'} = $changeHash{'author'.$key};
! 3838: } else {
! 3839: unless ($got_domdefs) {
! 3840: %domdefaults =
! 3841: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
! 3842: $got_domdefs = 1;
! 3843: }
! 3844: if ($domdefaults{'editors'} ne '') {
! 3845: $newenvhash{'environment.editors'} = $domdefaults{'editors'};
1.470 raeburn 3846: } else {
1.474 ! raeburn 3847: $newenvhash{'environment.editors'} = 'edit,xml';
1.470 raeburn 3848: }
3849: }
1.275 raeburn 3850: } elsif ($key ne 'quota') {
1.270 raeburn 3851: $newenvhash{'environment.tools.'.$key} =
3852: $changeHash{'tools.'.$key};
1.279 raeburn 3853: if ($changeHash{'tools.'.$key} ne '') {
3854: $newenvhash{'environment.availabletools.'.$key} =
3855: $changeHash{'tools.'.$key};
3856: } else {
1.474 ! raeburn 3857: unless ($got_domdefs) {
! 3858: %domdefaults =
! 3859: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
! 3860: $got_domdefs = 1;
! 3861: }
! 3862: unless ($got_userenv) {
! 3863: %userenv =
! 3864: &Apache::lonnet::userenvironment($env{'user.domain'},
! 3865: $env{'user.name'},@fromenv);
! 3866: $got_userenv = 1;
! 3867: }
1.279 raeburn 3868: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3869: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.474 ! raeburn 3870: $key,'reload','tools',\%userenv,\%domdefaults);
1.279 raeburn 3871: }
1.270 raeburn 3872: }
3873: }
1.271 raeburn 3874: if (keys(%newenvhash)) {
3875: &Apache::lonnet::appenv(\%newenvhash);
3876: }
1.470 raeburn 3877: } else {
3878: if ($ca_mgr_del) {
3879: &Apache::lonnet::delenv($ca_mgr_del);
3880: }
3881: if (keys(%ca_mgr_add)) {
3882: &Apache::lonnet::appenv(\%ca_mgr_add);
3883: }
1.267 raeburn 3884: }
1.463 raeburn 3885: if ($changed{'aboutme'}) {
3886: &Apache::loncommon::devalidate_aboutme_cache($env{'form.ccuname'},
3887: $env{'form.ccdomain'});
3888: }
1.267 raeburn 3889: }
1.204 raeburn 3890: }
1.334 raeburn 3891: if (keys(%namechanged) > 0) {
1.337 raeburn 3892: foreach my $field (@userinfo) {
3893: $changeHash{$field} = $env{'form.c'.$field};
3894: }
3895: # Make the change
1.204 raeburn 3896: $namechgresult =
3897: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3898: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3899: $changeHash{'firstname'},$changeHash{'middlename'},
3900: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3901: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3902: %userupdate = (
3903: lastname => $env{'form.clastname'},
3904: middlename => $env{'form.cmiddlename'},
3905: firstname => $env{'form.cfirstname'},
3906: generation => $env{'form.cgeneration'},
3907: id => $env{'form.cid'},
3908: );
1.204 raeburn 3909: }
1.334 raeburn 3910: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3911: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3912: # Tell the user we changed the name
1.334 raeburn 3913: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3914: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3915: \%oldsettings, \%oldsettingstext,\%newsettings,
3916: \%newsettingstext);
1.203 raeburn 3917: if ($env{'form.cid'} ne $userenv{'id'}) {
3918: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3919: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3920: if (($recurseid) &&
3921: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3922: my $idresult =
3923: &Apache::lonuserutils::propagate_id_change(
3924: $env{'form.ccuname'},$env{'form.ccdomain'},
3925: \%userupdate);
3926: $r->print('<br />'.$idresult.'<br />');
3927: }
1.196 raeburn 3928: }
1.149 raeburn 3929: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3930: ($env{'form.ccuname'} eq $env{'user.name'})) {
3931: my %newenvhash;
3932: foreach my $key (keys(%changeHash)) {
3933: $newenvhash{'environment.'.$key} = $changeHash{$key};
3934: }
1.238 raeburn 3935: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3936: }
1.28 matthew 3937: } else { # error occurred
1.389 bisitz 3938: $r->print(
3939: '<p class="LC_error">'
3940: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3941: '"'.$env{'form.ccuname'}.'"',
3942: '"'.$env{'form.ccdomain'}.'"')
3943: .'</p>');
1.28 matthew 3944: }
1.334 raeburn 3945: } else { # End of if ($env ... ) logic
1.275 raeburn 3946: # They did not want to change the users name, quota, tool availability,
3947: # or ability to request creation of courses,
1.267 raeburn 3948: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3949: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3950: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3951: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3952: }
1.206 raeburn 3953: if (@mod_disallowed) {
3954: my ($rolestr,$contextname);
3955: if (@longroles > 0) {
3956: $rolestr = join(', ',@longroles);
3957: } else {
3958: $rolestr = &mt('No roles');
3959: }
3960: if ($context eq 'course') {
1.399 bisitz 3961: $contextname = 'course';
1.206 raeburn 3962: } elsif ($context eq 'author') {
1.399 bisitz 3963: $contextname = 'co-author';
1.206 raeburn 3964: }
3965: $r->print(&mt('The following fields were not updated: ').'<ul>');
3966: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3967: foreach my $field (@mod_disallowed) {
3968: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3969: }
1.207 raeburn 3970: $r->print('</ul>');
3971: if (@mod_disallowed == 1) {
1.399 bisitz 3972: $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 3973: } else {
1.399 bisitz 3974: $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 3975: }
1.292 bisitz 3976: my $helplink = 'javascript:helpMenu('."'display'".')';
3977: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3978: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3979: ,'<a href="'.$helplink.'">','</a>')
3980: .'<br />');
1.206 raeburn 3981: }
1.259 bisitz 3982: $r->print('<span class="LC_warning">'
3983: .$no_forceid_alert
3984: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3985: .'</span>');
1.4 www 3986: }
1.367 golterma 3987: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3988: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3989: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3990: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3991: my $linktext = ($crstype eq 'Community' ?
3992: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3993: $r->print(
3994: &Apache::lonhtmlcommon::actionbox([
3995: '<a href="javascript:backPage(document.userupdate)">'
3996: .($crstype eq 'Community' ?
3997: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3998: .'</a>']));
1.220 raeburn 3999: } else {
1.375 raeburn 4000: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 4001: if (keys(%namechanged) > 0) {
1.220 raeburn 4002: if ($context eq 'course') {
4003: if (@userroles > 0) {
1.225 raeburn 4004: if ((@rolechanges == 0) ||
4005: (!(grep(/^st$/,@rolechanges)))) {
4006: if (grep(/^st$/,@userroles)) {
4007: my $classlistupdated =
4008: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 4009: $cnum,$env{'form.ccdomain'},
4010: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 4011: }
1.220 raeburn 4012: }
4013: }
4014: }
4015: }
1.226 raeburn 4016: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 4017: $env{'form.ccdomain'});
4018: if ($env{'form.popup'}) {
4019: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
4020: } else {
1.367 golterma 4021: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
4022: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
4023: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 4024: }
1.220 raeburn 4025: }
4026: }
4027:
1.334 raeburn 4028: sub display_userinfo {
1.362 raeburn 4029: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
4030: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 4031: $newsetting,$newsettingtext) = @_;
4032: return unless (ref($order) eq 'ARRAY' &&
4033: ref($canshow) eq 'HASH' &&
4034: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 4035: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 4036: ref($usertools) eq 'ARRAY' &&
4037: ref($userenv) eq 'HASH' &&
4038: ref($changedhash) eq 'HASH' &&
4039: ref($oldsetting) eq 'HASH' &&
4040: ref($oldsettingtext) eq 'HASH' &&
4041: ref($newsetting) eq 'HASH' &&
4042: ref($newsettingtext) eq 'HASH');
4043: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 4044: 'ui' => 'User Information',
1.334 raeburn 4045: 'uic' => 'User Information Changed',
4046: 'firstname' => 'First Name',
4047: 'middlename' => 'Middle Name',
4048: 'lastname' => 'Last Name',
4049: 'generation' => 'Generation',
4050: 'id' => 'Student/Employee ID',
4051: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 4052: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 4053: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 4054: 'blog' => 'Blog Availability',
1.361 raeburn 4055: 'webdav' => 'WebDAV Availability',
1.334 raeburn 4056: 'aboutme' => 'Personal Information Page Availability',
4057: 'portfolio' => 'Portfolio Availability',
1.470 raeburn 4058: 'portaccess' => 'Portfolio Shareable',
1.459 raeburn 4059: 'timezone' => 'Can set own Time Zone',
1.334 raeburn 4060: 'official' => 'Can Request Official Courses',
4061: 'unofficial' => 'Can Request Unofficial Courses',
4062: 'community' => 'Can Request Communities',
1.384 raeburn 4063: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 4064: 'placement' => 'Can Request Placement Tests',
1.449 raeburn 4065: 'lti' => 'Can Request LTI Courses',
1.362 raeburn 4066: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 4067: 'inststatus' => "Affiliation",
4068: 'prvs' => 'Previous Value:',
1.470 raeburn 4069: 'chto' => 'Changed To:',
4070: 'editors' => "Available Editors in Authoring Space",
1.473 raeburn 4071: 'managers' => "Co-authors who can add/revoke roles",
1.470 raeburn 4072: 'edit' => 'Standard editor (Edit)',
4073: 'xml' => 'Text editor (EditXML)',
4074: 'daxe' => 'Daxe editor (Daxe)',
1.334 raeburn 4075: );
4076: if ($changed) {
1.372 raeburn 4077: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 4078: &Apache::loncommon::start_data_table().
4079: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 4080: $r->print("<th> </th>\n");
1.367 golterma 4081: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
4082: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
4083: $r->print(&Apache::loncommon::end_data_table_header_row());
4084: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
4085:
1.334 raeburn 4086: foreach my $item (@userinfo) {
4087: my $value = $env{'form.c'.$item};
1.367 golterma 4088: #show changes only:
1.383 raeburn 4089: unless ($value eq $userenv->{$item}){
1.367 golterma 4090: $r->print(&Apache::loncommon::start_data_table_row());
4091: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 4092: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 4093: $r->print("<td>$value </td>\n");
4094: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 4095: }
4096: }
4097: foreach my $entry (@{$order}) {
1.383 raeburn 4098: if ($canshow->{$entry}) {
1.470 raeburn 4099: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') ||
4100: ($entry eq 'requestauthor') || ($entry eq 'authordefaults')) {
1.383 raeburn 4101: my @items;
4102: if ($entry eq 'requestauthor') {
4103: @items = ($entry);
1.470 raeburn 4104: } elsif ($entry eq 'authordefaults') {
4105: @items = ('webdav','managers','editors');
1.383 raeburn 4106: } else {
4107: @items = @{$requestcourses};
1.384 raeburn 4108: }
1.383 raeburn 4109: foreach my $item (@items) {
4110: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
4111: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
4112: $r->print(&Apache::loncommon::start_data_table_row()."\n");
1.470 raeburn 4113: $r->print("<td>$lt{$item}</td><td>\n");
4114: unless ($item eq 'managers') {
4115: $r->print($oldsetting->{$item});
4116: }
1.383 raeburn 4117: if ($oldsettingtext->{$item}) {
4118: if ($oldsetting->{$item}) {
1.470 raeburn 4119: unless ($item eq 'managers') {
4120: $r->print(' -- ');
4121: }
1.383 raeburn 4122: }
4123: $r->print($oldsettingtext->{$item});
4124: }
1.470 raeburn 4125: $r->print("</td>\n<td>");
4126: unless ($item eq 'managers') {
4127: $r->print($newsetting->{$item});
4128: }
1.383 raeburn 4129: if ($newsettingtext->{$item}) {
4130: if ($newsetting->{$item}) {
1.470 raeburn 4131: unless ($item eq 'managers') {
4132: $r->print(' -- ');
4133: }
1.383 raeburn 4134: }
4135: $r->print($newsettingtext->{$item});
4136: }
4137: $r->print("</td>\n");
4138: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4139: }
4140: }
4141: } elsif ($entry eq 'tools') {
4142: foreach my $item (@{$usertools}) {
1.383 raeburn 4143: if ($newsetting->{$item} ne $oldsetting->{$item}) {
4144: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4145: $r->print("<td>$lt{$item}</td>\n");
4146: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
4147: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
4148: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4149: }
4150: }
1.378 raeburn 4151: } elsif ($entry eq 'quota') {
4152: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
4153: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
4154: foreach my $name ('portfolio','author') {
1.383 raeburn 4155: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
4156: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4157: $r->print("<td>$lt{$name.$entry}</td>\n");
4158: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
4159: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
4160: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 4161: }
4162: }
4163: }
1.334 raeburn 4164: } else {
1.383 raeburn 4165: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
4166: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4167: $r->print("<td>$lt{$entry}</td>\n");
4168: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
4169: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
4170: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4171: }
4172: }
4173: }
4174: }
1.367 golterma 4175: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 4176: } else {
4177: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
4178: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 4179: }
4180: return;
4181: }
4182:
1.275 raeburn 4183: sub tool_changes {
4184: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
4185: $changed,$newaccess,$newaccesstext) = @_;
4186: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
4187: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
4188: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
4189: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
4190: return;
4191: }
1.383 raeburn 4192: my %reqdisplay = &requestchange_display();
1.300 raeburn 4193: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 4194: my @options = ('approval','validate','autolimit');
1.306 raeburn 4195: my $optregex = join('|',@options);
1.300 raeburn 4196: my $cdom = $env{'request.role.domain'};
4197: foreach my $tool (@{$usertools}) {
1.383 raeburn 4198: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 4199: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 4200: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 4201: my ($newop,$limit);
1.314 raeburn 4202: if ($env{'form.'.$context.'_'.$tool}) {
4203: $newop = $env{'form.'.$context.'_'.$tool};
4204: if ($newop eq 'autolimit') {
1.383 raeburn 4205: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 4206: $limit =~ s/\D+//g;
4207: $newop .= '='.$limit;
4208: }
4209: }
1.300 raeburn 4210: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 4211: if ($newop) {
4212: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 4213: $changeHash,$context);
4214: if ($changed->{$tool}) {
1.383 raeburn 4215: if ($newop =~ /^autolimit/) {
4216: if ($limit) {
4217: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4218: } else {
4219: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4220: }
4221: } else {
4222: $newaccesstext->{$tool} = $reqdisplay{$newop};
4223: }
1.300 raeburn 4224: } else {
4225: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
4226: }
4227: }
4228: } else {
4229: my @curr = split(',',$userenv->{$context.'.'.$tool});
4230: my @new;
4231: my $changedoms;
1.314 raeburn 4232: foreach my $req (@curr) {
4233: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
4234: my $oldop = $1;
1.383 raeburn 4235: if ($oldop =~ /^autolimit=(\d*)/) {
4236: my $limit = $1;
4237: if ($limit) {
4238: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4239: } else {
4240: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4241: }
4242: } else {
4243: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
4244: }
1.314 raeburn 4245: if ($oldop ne $newop) {
4246: $changedoms = 1;
4247: foreach my $item (@curr) {
4248: my ($reqdom,$option) = split(':',$item);
4249: unless ($reqdom eq $cdom) {
4250: push(@new,$item);
4251: }
4252: }
4253: if ($newop) {
4254: push(@new,$cdom.':'.$newop);
1.300 raeburn 4255: }
1.314 raeburn 4256: @new = sort(@new);
1.300 raeburn 4257: }
1.314 raeburn 4258: last;
1.300 raeburn 4259: }
1.314 raeburn 4260: }
4261: if ((!$changedoms) && ($newop)) {
1.300 raeburn 4262: $changedoms = 1;
1.306 raeburn 4263: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 4264: }
4265: if ($changedoms) {
1.314 raeburn 4266: my $newdomstr;
1.300 raeburn 4267: if (@new) {
4268: $newdomstr = join(',',@new);
4269: }
4270: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
4271: $context);
4272: if ($changed->{$tool}) {
4273: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 4274: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 4275: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
4276: $limit =~ s/\D+//g;
4277: if ($limit) {
1.383 raeburn 4278: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 4279: } else {
1.383 raeburn 4280: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 4281: }
1.314 raeburn 4282: } else {
1.306 raeburn 4283: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
4284: }
1.300 raeburn 4285: } else {
1.383 raeburn 4286: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 4287: }
4288: }
4289: }
4290: }
4291: }
4292: return;
4293: }
1.470 raeburn 4294: my %tooldesc = &Apache::lonlocal::texthash(
4295: 'edit' => 'Standard editor (Edit)',
4296: 'xml' => 'Text editor (EditXML)',
4297: 'daxe' => 'Daxe editor (Daxe)',
4298: );
1.275 raeburn 4299: foreach my $tool (@{$usertools}) {
1.383 raeburn 4300: my ($newval,$limit,$envkey);
1.362 raeburn 4301: $envkey = $context.'.'.$tool;
1.306 raeburn 4302: if ($context eq 'requestcourses') {
4303: $newval = $env{'form.crsreq_'.$tool};
4304: if ($newval eq 'autolimit') {
1.383 raeburn 4305: $limit = $env{'form.crsreq_'.$tool.'_limit'};
4306: $limit =~ s/\D+//g;
4307: $newval .= '='.$limit;
1.306 raeburn 4308: }
1.362 raeburn 4309: } elsif ($context eq 'requestauthor') {
4310: $newval = $env{'form.'.$context};
4311: $envkey = $context;
1.470 raeburn 4312: } elsif ($context eq 'authordefaults') {
4313: if ($tool eq 'editors') {
4314: $envkey = 'authoreditors';
4315: if ($env{'form.customeditors'} == 1) {
4316: my @editors;
4317: my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
4318: if (@posseditors) {
4319: foreach my $editor (@posseditors) {
4320: if (grep(/^\Q$editor\E$/,@posseditors)) {
4321: unless (grep(/^\Q$editor\E$/,@editors)) {
4322: push(@editors,$editor);
4323: }
4324: }
4325: }
4326: }
4327: if (@editors) {
4328: $newval = join(',',(sort(@editors)));
4329: }
4330: }
4331: } elsif ($tool eq 'managers') {
4332: $envkey = 'authormanagers';
4333: my @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
4334: if (@possibles) {
4335: my %ca_roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},
4336: undef,['active','future'],['ca']);
4337: if (keys(%ca_roles)) {
4338: my @custommanagers;
4339: foreach my $user (@possibles) {
4340: if ($user =~ /^($match_username):($match_domain)$/) {
4341: if (exists($ca_roles{$user.':ca'})) {
4342: unless ($user eq $env{'form.ccuname'}.':'.$env{'form.ccdomain'}) {
4343: push(@custommanagers,$user);
4344: }
4345: }
4346: }
4347: }
4348: if (@custommanagers) {
4349: $newval = join(',',sort(@custommanagers));
4350: }
4351: }
4352: }
4353: } elsif ($tool eq 'webdav') {
4354: $envkey = 'tools.webdav';
4355: $newval = $env{'form.'.$context.'_'.$tool};
4356: }
1.314 raeburn 4357: } else {
1.306 raeburn 4358: $newval = $env{'form.'.$context.'_'.$tool};
4359: }
1.362 raeburn 4360: if ($userenv->{$envkey} ne '') {
1.275 raeburn 4361: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 4362: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4363: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
4364: my $currlimit = $1;
4365: if ($currlimit eq '') {
4366: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4367: } else {
4368: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
4369: }
4370: } elsif ($userenv->{$envkey}) {
4371: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
4372: } else {
4373: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4374: }
1.470 raeburn 4375: } elsif ($context eq 'authordefaults') {
4376: if ($tool eq 'managers') {
4377: if ($userenv->{$envkey} eq '') {
4378: $oldaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4379: } else {
4380: my $managers = $userenv->{$envkey};
4381: $managers =~ s/,/, /g;
4382: $oldaccesstext->{$tool} = $managers;
4383: }
4384: } elsif ($tool eq 'editors') {
4385: $oldaccesstext->{$tool} = &mt('can use: [_1]',
4386: join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
4387: } elsif ($tool eq 'webdav') {
4388: if ($userenv->{$envkey}) {
4389: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
4390: } else {
4391: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4392: }
4393: }
1.275 raeburn 4394: } else {
1.383 raeburn 4395: if ($userenv->{$envkey}) {
4396: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
4397: } else {
4398: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4399: }
1.275 raeburn 4400: }
1.362 raeburn 4401: $changeHash->{$envkey} = $userenv->{$envkey};
1.470 raeburn 4402: if (($env{'form.custom'.$tool} == 1) ||
4403: (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
1.362 raeburn 4404: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 4405: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
4406: $context);
1.275 raeburn 4407: if ($changed->{$tool}) {
4408: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 4409: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4410: if ($newval =~ /^autolimit/) {
4411: if ($limit) {
4412: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4413: } else {
4414: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4415: }
4416: } elsif ($newval) {
4417: $newaccesstext->{$tool} = $reqdisplay{$newval};
4418: } else {
4419: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4420: }
1.470 raeburn 4421: } elsif ($context eq 'authordefaults') {
4422: if ($tool eq 'editors') {
4423: $newaccesstext->{$tool} = &mt('can use: [_1]',
4424: join(', ', map { $tooldesc{$_} } split(/,/,$changeHash->{$envkey})));
4425: } elsif ($tool eq 'managers') {
4426: if ($changeHash->{$envkey} eq '') {
4427: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4428: } else {
4429: my $managers = $changeHash->{$envkey};
4430: $managers =~ s/,/, /g;
4431: $newaccesstext->{$tool} = $managers;
4432: }
4433: } elsif ($tool eq 'webdav') {
4434: if ($newval) {
4435: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4436: } else {
4437: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4438: }
4439: }
1.275 raeburn 4440: } else {
1.383 raeburn 4441: if ($newval) {
4442: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4443: } else {
4444: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4445: }
1.275 raeburn 4446: }
4447: } else {
4448: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 4449: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.470 raeburn 4450: if ($userenv->{$envkey} =~ /^autolimit/) {
1.383 raeburn 4451: if ($limit) {
4452: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4453: } else {
4454: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4455: }
1.470 raeburn 4456: } elsif ($userenv->{$envkey}) {
4457: $newaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
1.383 raeburn 4458: } else {
4459: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4460: }
1.470 raeburn 4461: } elsif ($context eq 'authordefaults') {
4462: if ($tool eq 'editors') {
4463: $newaccesstext->{$tool} = &mt('can use: [_1]',
4464: join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
4465: } elsif ($tool eq 'managers') {
4466: if ($userenv->{$envkey} eq '') {
4467: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4468: } else {
4469: my $managers = $userenv->{$envkey};
4470: $managers =~ s/,/, /g;
4471: $newaccesstext->{$tool} = $managers;
4472: }
4473: } elsif ($tool eq 'webdav') {
4474: if ($userenv->{$envkey}) {
4475: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4476: } else {
4477: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4478: }
4479: }
1.275 raeburn 4480: } else {
1.383 raeburn 4481: if ($userenv->{$context.'.'.$tool}) {
4482: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4483: } else {
4484: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4485: }
1.275 raeburn 4486: }
4487: }
4488: } else {
4489: $newaccess->{$tool} = $oldaccess->{$tool};
4490: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
4491: }
4492: } else {
4493: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
4494: if ($changed->{$tool}) {
4495: $newaccess->{$tool} = &mt('default');
4496: } else {
4497: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 4498: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4499: if ($newval =~ /^autolimit/) {
4500: if ($limit) {
4501: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4502: } else {
4503: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4504: }
4505: } elsif ($newval) {
4506: $newaccesstext->{$tool} = $reqdisplay{$newval};
4507: } else {
4508: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4509: }
1.470 raeburn 4510: } elsif ($context eq 'authordefaults') {
4511: if ($tool eq 'editors') {
4512: $newaccesstext->{$tool} = &mt('can use: [_1]',
4513: join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
4514: } elsif ($tool eq 'managers') {
4515: if ($newval eq '') {
4516: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4517: } else {
4518: my $managers = $newval;
4519: $managers =~ s/,/, /g;
4520: $newaccesstext->{$tool} = $managers;
4521: }
4522: } elsif ($tool eq 'webdav') {
4523: if ($userenv->{$envkey}) {
4524: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4525: } else {
4526: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4527: }
4528: }
1.275 raeburn 4529: } else {
1.383 raeburn 4530: if ($userenv->{$context.'.'.$tool}) {
4531: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4532: } else {
4533: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4534: }
1.275 raeburn 4535: }
4536: }
4537: }
4538: } else {
4539: $oldaccess->{$tool} = &mt('default');
1.470 raeburn 4540: if (($env{'form.custom'.$tool} == 1) ||
4541: (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
1.306 raeburn 4542: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
4543: $context);
1.275 raeburn 4544: if ($changed->{$tool}) {
4545: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 4546: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4547: if ($newval =~ /^autolimit/) {
4548: if ($limit) {
4549: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4550: } else {
4551: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4552: }
4553: } elsif ($newval) {
4554: $newaccesstext->{$tool} = $reqdisplay{$newval};
4555: } else {
4556: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4557: }
1.470 raeburn 4558: } elsif ($context eq 'authordefaults') {
4559: if ($tool eq 'managers') {
4560: if ($newval eq '') {
4561: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4562: } else {
4563: my $managers = $newval;
4564: $managers =~ s/,/, /g;
4565: $newaccesstext->{$tool} = $managers;
4566: }
4567: } elsif ($tool eq 'editors') {
4568: $newaccesstext->{$tool} = &mt('can use: [_1]',
4569: join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
4570: } elsif ($tool eq 'webdav') {
4571: if ($newval) {
4572: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4573: } else {
4574: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4575: }
4576: }
1.275 raeburn 4577: } else {
1.383 raeburn 4578: if ($newval) {
4579: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4580: } else {
4581: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4582: }
1.275 raeburn 4583: }
4584: } else {
4585: $newaccess->{$tool} = $oldaccess->{$tool};
4586: }
4587: } else {
4588: $newaccess->{$tool} = $oldaccess->{$tool};
4589: }
4590: }
4591: }
4592: return;
4593: }
4594:
1.220 raeburn 4595: sub update_roles {
1.375 raeburn 4596: my ($r,$context,$showcredits) = @_;
1.4 www 4597: my $now=time;
1.225 raeburn 4598: my @rolechanges;
1.465 raeburn 4599: my (%disallowed,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.466 raeburn 4600: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.465 raeburn 4601: $got_role_approvals{$context} = '';
4602: $process_by{$context} = {};
4603: my @domroles = &Apache::lonuserutils::domain_roles();
4604: my @cstrroles = &Apache::lonuserutils::construction_space_roles();
4605: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
1.73 sakharuk 4606: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 4607: foreach my $key (keys(%env)) {
1.135 raeburn 4608: next if (! $env{$key});
1.190 raeburn 4609: next if ($key eq 'form.action');
1.27 matthew 4610: # Revoke roles
1.135 raeburn 4611: if ($key=~/^form\.rev/) {
4612: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 4613: # Revoke standard role
1.170 albertel 4614: my ($scope,$role) = ($1,$2);
4615: my $result =
4616: &Apache::lonnet::revokerole($env{'form.ccdomain'},
4617: $env{'form.ccuname'},
1.239 raeburn 4618: $scope,$role,'','',$context);
1.367 golterma 4619: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4620: &mt('Revoking [_1] in [_2]',
4621: &Apache::lonnet::plaintext($role),
1.372 raeburn 4622: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4623: $result ne "ok").'<br />');
4624: if ($result ne "ok") {
4625: $r->print(&mt('Error: [_1]',$result).'<br />');
4626: }
1.170 albertel 4627: if ($role eq 'st') {
1.202 raeburn 4628: my $result =
1.198 raeburn 4629: &Apache::lonuserutils::classlist_drop($scope,
4630: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4631: $now);
1.367 golterma 4632: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 4633: }
1.225 raeburn 4634: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4635: push(@rolechanges,$role);
4636: }
1.196 raeburn 4637: }
1.195 raeburn 4638: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 4639: # Revoke custom role
1.369 bisitz 4640: my $result = &Apache::lonnet::revokecustomrole(
4641: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 4642: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4643: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 4644: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4645: $result ne 'ok').'<br />');
4646: if ($result ne "ok") {
4647: $r->print(&mt('Error: [_1]',$result).'<br />');
4648: }
1.225 raeburn 4649: if (!grep(/^cr$/,@rolechanges)) {
4650: push(@rolechanges,'cr');
4651: }
1.64 www 4652: }
1.135 raeburn 4653: } elsif ($key=~/^form\.del/) {
4654: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 4655: # Delete standard role
1.170 albertel 4656: my ($scope,$role) = ($1,$2);
4657: my $result =
4658: &Apache::lonnet::assignrole($env{'form.ccdomain'},
4659: $env{'form.ccuname'},
1.239 raeburn 4660: $scope,$role,$now,0,1,'',
4661: $context);
1.367 golterma 4662: $r->print(&Apache::lonhtmlcommon::confirm_success(
4663: &mt('Deleting [_1] in [_2]',
1.369 bisitz 4664: &Apache::lonnet::plaintext($role),
1.372 raeburn 4665: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4666: $result ne 'ok').'<br />');
4667: if ($result ne "ok") {
4668: $r->print(&mt('Error: [_1]',$result).'<br />');
4669: }
1.367 golterma 4670:
1.170 albertel 4671: if ($role eq 'st') {
1.202 raeburn 4672: my $result =
1.198 raeburn 4673: &Apache::lonuserutils::classlist_drop($scope,
4674: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4675: $now);
1.369 bisitz 4676: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 4677: }
1.225 raeburn 4678: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4679: push(@rolechanges,$role);
4680: }
1.116 raeburn 4681: }
1.139 albertel 4682: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4683: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4684: # Delete custom role
1.369 bisitz 4685: my $result =
4686: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
4687: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
4688: 0,1,$context);
4689: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 4690: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4691: $result ne "ok").'<br />');
4692: if ($result ne "ok") {
4693: $r->print(&mt('Error: [_1]',$result).'<br />');
4694: }
1.367 golterma 4695:
1.225 raeburn 4696: if (!grep(/^cr$/,@rolechanges)) {
4697: push(@rolechanges,'cr');
4698: }
1.116 raeburn 4699: }
1.135 raeburn 4700: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4701: my $udom = $env{'form.ccdomain'};
4702: my $uname = $env{'form.ccuname'};
1.116 raeburn 4703: # Re-enable standard role
1.135 raeburn 4704: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4705: my $url = $1;
4706: my $role = $2;
1.465 raeburn 4707: my $id = $url.'_'.$role;
1.89 raeburn 4708: my $logmsg;
4709: my $output;
4710: if ($role eq 'st') {
1.141 albertel 4711: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4712: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4713: my $credits;
4714: if ($showcredits) {
1.465 raeburn 4715: my $defaultcredits =
1.375 raeburn 4716: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4717: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4718: }
1.465 raeburn 4719: unless ($udom eq $cdom) {
4720: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4721: $uname,$role,$now,0,$cdom,$cnum,$csec,$credits,
4722: \%process_by,\%instdoms,\%got_role_approvals,
1.466 raeburn 4723: \%got_instdoms,\%reject,\%pending,\%notifydc,
4724: \%status,\%unauthorized,\%currqueued));
1.465 raeburn 4725: }
1.375 raeburn 4726: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4727: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4728: if ($result eq 'refused' && $logmsg) {
4729: $output = $logmsg;
4730: } else {
1.369 bisitz 4731: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4732: }
1.89 raeburn 4733: } else {
1.372 raeburn 4734: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4735: &Apache::lonnet::plaintext($role),
4736: &Apache::loncommon::show_role_extent($url,$context,'st'),
4737: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4738: }
4739: }
4740: } else {
1.465 raeburn 4741: my ($cdom,$cnum,$csec);
4742: if (grep(/^\Q$role\E$/,@cstrroles)) {
4743: ($cdom,$cnum) = ($url =~ m{^/($match_domain)/($match_username)$});
4744: } elsif (grep(/^\Q$role\E$/,@domroles)) {
4745: ($cdom) = ($url =~ m{^/($match_domain)/$});
4746: } elsif ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
4747: ($cdom,$cnum,$csec) = ($1,$2,$3);
4748: }
4749: if ($cdom ne '') {
4750: unless ($udom eq $cdom) {
4751: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4752: $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by,
4753: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4754: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4755: }
4756: }
1.101 albertel 4757: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4758: $env{'form.ccuname'},$url,$role,0,$now,'','',
4759: $context);
1.461 raeburn 4760: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
4761: &Apache::lonnet::plaintext($role),
4762: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4763: if ($result ne "ok") {
4764: $output .= &mt('Error: [_1]',$result).'<br />';
4765: }
4766: }
1.89 raeburn 4767: $r->print($output);
1.225 raeburn 4768: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4769: push(@rolechanges,$role);
4770: }
1.113 raeburn 4771: }
1.116 raeburn 4772: # Re-enable custom role
1.139 albertel 4773: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4774: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1.465 raeburn 4775: my $id = $url.'_cr'."/$rdom/$rnam/$rolename";
4776: my $role = "cr/$rdom/$rnam/$rolename";
4777: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
4778: my ($cdom,$cnum,$csec) = ($1,$2,$3);
4779: unless ($udom eq $cdom) {
4780: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4781: $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by,
4782: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4783: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4784: }
4785: }
1.116 raeburn 4786: my $result = &Apache::lonnet::assigncustomrole(
4787: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4788: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4789: $r->print(&Apache::lonhtmlcommon::confirm_success(
4790: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4791: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4792: $result ne "ok").'<br />');
4793: if ($result ne "ok") {
4794: $r->print(&mt('Error: [_1]',$result).'<br />');
4795: }
1.225 raeburn 4796: if (!grep(/^cr$/,@rolechanges)) {
4797: push(@rolechanges,'cr');
4798: }
1.116 raeburn 4799: }
1.135 raeburn 4800: } elsif ($key=~/^form\.act/) {
1.101 albertel 4801: my $udom = $env{'form.ccdomain'};
4802: my $uname = $env{'form.ccuname'};
1.141 albertel 4803: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4804: # Activate a custom role
1.83 albertel 4805: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4806: my $url='/'.$one.'/'.$two;
1.465 raeburn 4807: my $id = $url.'_cr/'."$three/$four/$five";
4808: my $role = "cr/$three/$four/$five";
1.83 albertel 4809: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4810:
1.101 albertel 4811: my $start = ( $env{'form.start_'.$full} ?
4812: $env{'form.start_'.$full} :
1.88 raeburn 4813: $now );
1.101 albertel 4814: my $end = ( $env{'form.end_'.$full} ?
4815: $env{'form.end_'.$full} :
1.88 raeburn 4816: 0 );
1.465 raeburn 4817:
1.88 raeburn 4818: # split multiple sections
4819: my %sections = ();
1.461 raeburn 4820: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$five);
1.88 raeburn 4821: if ($num_sections == 0) {
1.465 raeburn 4822: unless ($udom eq $one) {
4823: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4824: $uname,$role,$start,$end,$one,$two,'','',\%process_by,
4825: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4826: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4827: }
1.240 raeburn 4828: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4829: } else {
1.114 albertel 4830: my %curr_groups =
1.117 raeburn 4831: &Apache::longroup::coursegroups($one,$two);
1.465 raeburn 4832: my ($restricted,$numchanges);
1.404 raeburn 4833: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4834: if (($sec eq 'none') || ($sec eq 'all') ||
4835: exists($curr_groups{$sec})) {
4836: $disallowed{$sec} = $url;
4837: next;
4838: }
4839: my $securl = $url.'/'.$sec;
1.465 raeburn 4840: my $secid = $securl.'_cr'."/$three/$four/$five";
4841: undef($restricted);
4842: unless ($udom eq $one) {
4843: next if (&Apache::lonuserutils::restricted_dom($context,$secid,$udom,
4844: $uname,$role,$start,$end,$one,$two,$sec,'',\%process_by,
4845: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4846: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4847: }
4848: $numchanges ++;
1.240 raeburn 4849: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4850: }
1.465 raeburn 4851: next unless ($numchanges);
1.88 raeburn 4852: }
1.225 raeburn 4853: if (!grep(/^cr$/,@rolechanges)) {
4854: push(@rolechanges,'cr');
4855: }
1.142 raeburn 4856: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4857: # Activate roles for sections with 3 id numbers
4858: # set start, end times, and the url for the class
1.83 albertel 4859: my ($one,$two,$three)=($1,$2,$3);
1.461 raeburn 4860: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4861: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4862: $now );
1.461 raeburn 4863: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1.101 albertel 4864: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4865: 0 );
1.83 albertel 4866: my $url='/'.$one.'/'.$two;
1.465 raeburn 4867: my $id = $url.'_'.$three;
1.88 raeburn 4868: # split multiple sections
4869: my %sections = ();
1.101 albertel 4870: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.465 raeburn 4871: my ($credits,$numchanges);
1.375 raeburn 4872: if ($three eq 'st') {
1.461 raeburn 4873: if ($showcredits) {
1.375 raeburn 4874: my $defaultcredits =
4875: &Apache::lonuserutils::get_defaultcredits($one,$two);
4876: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4877: $credits =~ s/[^\d\.]//g;
4878: if ($credits eq $defaultcredits) {
4879: undef($credits);
4880: }
4881: }
4882: }
1.88 raeburn 4883: if ($num_sections == 0) {
1.465 raeburn 4884: unless ($udom eq $one) {
4885: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4886: $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by,
4887: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4888: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4889: }
4890: $numchanges ++;
1.375 raeburn 4891: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4892: } else {
1.114 albertel 4893: my %curr_groups =
1.117 raeburn 4894: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4895: my $emptysec = 0;
1.465 raeburn 4896: my $restricted;
1.404 raeburn 4897: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4898: $sec =~ s/\W//g;
1.113 raeburn 4899: if ($sec ne '') {
4900: if (($sec eq 'none') || ($sec eq 'all') ||
4901: exists($curr_groups{$sec})) {
4902: $disallowed{$sec} = $url;
4903: next;
4904: }
1.88 raeburn 4905: my $securl = $url.'/'.$sec;
1.465 raeburn 4906: my $secid = $securl.'_'.$three;
4907: unless ($udom eq $one) {
4908: undef($restricted);
4909: $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
4910: $uname,$three,$start,$end,$one,$two,$sec,$credits,\%process_by,
4911: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4912: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4913: next if ($restricted);
4914: }
4915: $numchanges ++;
1.375 raeburn 4916: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4917: } else {
4918: $emptysec = 1;
4919: }
4920: }
4921: if ($emptysec) {
1.465 raeburn 4922: unless ($udom eq $one) {
4923: undef($restricted);
4924: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
4925: $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by,
4926: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4927: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4928: next if ($restricted);
4929: }
4930: $numchanges ++;
1.375 raeburn 4931: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4932: }
1.465 raeburn 4933: next unless ($numchanges);
1.225 raeburn 4934: }
4935: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4936: push(@rolechanges,$three);
4937: }
1.135 raeburn 4938: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4939: # Activate roles for sections with two id numbers
4940: # set start, end times, and the url for the class
1.461 raeburn 4941: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4942: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4943: $now );
1.461 raeburn 4944: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1.101 albertel 4945: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4946: 0 );
1.225 raeburn 4947: my $one = $1;
4948: my $two = $2;
4949: my $url='/'.$one.'/';
1.465 raeburn 4950: my $id = $url.'_'.$two;
1.468 raeburn 4951: my ($cdom,$cnum) = split(/\//,$one);
1.88 raeburn 4952: # split multiple sections
4953: my %sections = ();
1.465 raeburn 4954: my ($restricted,$numchanges);
1.225 raeburn 4955: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4956: if ($num_sections == 0) {
1.465 raeburn 4957: unless ($udom eq $one) {
4958: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
1.468 raeburn 4959: $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
1.465 raeburn 4960: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4961: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4962: next if ($restricted);
4963: }
4964: $numchanges ++;
1.240 raeburn 4965: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4966: } else {
4967: my $emptysec = 0;
1.404 raeburn 4968: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4969: if ($sec ne '') {
4970: my $securl = $url.'/'.$sec;
1.465 raeburn 4971: my $secid = $securl.'_'.$two;
4972: unless ($udom eq $one) {
4973: undef($restricted);
4974: $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
1.468 raeburn 4975: $uname,$two,$start,$end,$cdom,$cnum,$sec,'',\%process_by,
1.465 raeburn 4976: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4977: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4978: next if ($restricted);
4979: }
4980: $numchanges ++;
1.240 raeburn 4981: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4982: } else {
4983: $emptysec = 1;
4984: }
4985: }
4986: if ($emptysec) {
1.465 raeburn 4987: unless ($udom eq $one) {
4988: undef($restricted);
4989: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
1.468 raeburn 4990: $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
1.465 raeburn 4991: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4992: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4993: next if ($restricted);
4994: }
4995: $numchanges ++;
1.240 raeburn 4996: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4997: }
1.465 raeburn 4998: next unless ($numchanges);
1.88 raeburn 4999: }
1.225 raeburn 5000: if (!grep(/^\Q$two\E$/,@rolechanges)) {
5001: push(@rolechanges,$two);
5002: }
1.64 www 5003: } else {
1.190 raeburn 5004: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 5005: }
1.113 raeburn 5006: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 5007: $r->print('<p class="LC_warning">');
1.113 raeburn 5008: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 5009: $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 5010: } else {
1.274 bisitz 5011: $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 5012: }
1.274 bisitz 5013: $r->print('</p><p>'
5014: .&mt('Please [_1]go back[_2] and choose a different section name.'
5015: ,'<a href="javascript:history.go(-1)'
5016: ,'</a>')
5017: .'</p><br />'
5018: );
1.113 raeburn 5019: }
5020: }
1.101 albertel 5021: } # End of foreach (keys(%env))
1.466 raeburn 5022: if ((keys(%reject)) || (keys(%unauthorized))) {
5023: $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized));
1.465 raeburn 5024: }
1.466 raeburn 5025: if ((keys(%pending)) || (keys(%currqueued))) {
5026: $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.465 raeburn 5027: }
1.75 www 5028: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 5029: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 5030: if (@rolechanges == 0) {
1.372 raeburn 5031: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 5032: }
1.225 raeburn 5033: return @rolechanges;
1.220 raeburn 5034: }
5035:
1.375 raeburn 5036: sub get_user_credits {
5037: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
5038: if ($cdom eq '' || $cnum eq '') {
5039: return unless ($env{'request.course.id'});
5040: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5041: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5042: }
5043: my $credits;
5044: my %currhash =
5045: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
5046: if (keys(%currhash) > 0) {
5047: my @items = split(/:/,$currhash{$uname.':'.$udom});
5048: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
5049: $credits = $items[$crdidx];
5050: $credits =~ s/[^\d\.]//g;
5051: }
5052: if ($credits eq $defaultcredits) {
5053: undef($credits);
5054: }
5055: return $credits;
5056: }
5057:
1.220 raeburn 5058: sub enroll_single_student {
1.375 raeburn 5059: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
5060: $showcredits,$defaultcredits) = @_;
1.318 raeburn 5061: $r->print('<h3>');
5062: if ($crstype eq 'Community') {
5063: $r->print(&mt('Enrolling Member'));
5064: } else {
5065: $r->print(&mt('Enrolling Student'));
5066: }
5067: $r->print('</h3>');
1.220 raeburn 5068:
5069: # Remove non alphanumeric values from section
5070: $env{'form.sections'}=~s/\W//g;
5071:
1.375 raeburn 5072: my $credits;
5073: if (($showcredits) && ($env{'form.credits'} ne '')) {
5074: $credits = $env{'form.credits'};
5075: $credits =~ s/[^\d\.]//g;
5076: if ($credits ne '') {
5077: if ($credits eq $defaultcredits) {
5078: undef($credits);
5079: }
5080: }
5081: }
1.465 raeburn 5082: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
1.466 raeburn 5083: my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,%pending,%reject,%notifydc,
5084: %status,%unauthorized,%currqueued);
1.465 raeburn 5085: unless ($env{'form.ccdomain'} eq $env{'course.'.$env{'request.course.id'}.'.domain'}) {
5086: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5087: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5088: my $csec = $env{'form.sections'};
5089: my $id = "/$cdom/$cnum";
5090: if ($csec ne '') {
5091: $id .= "/$csec";
5092: }
5093: $id .= '_st';
5094: if (&Apache::lonuserutils::restricted_dom($context,$id,$env{'form.ccdomain'},$env{'form.ccuname'},
5095: 'st',$startdate,$enddate,$cdom,$cnum,$csec,$credits,
5096: \%process_by,\%instdoms,\%got_role_approvals,\%got_instdoms,
1.466 raeburn 5097: \%reject,\%pending,\%notifydc,\%status,\%unauthorized,\%currqueued)) {
5098: if ((keys(%reject)) || (keys(%unauthorized))) {
5099: $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized));
1.465 raeburn 5100: }
1.466 raeburn 5101: if ((keys(%pending)) || (keys(%currqueued))) {
5102: $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.465 raeburn 5103: }
5104: return;
5105: }
5106: }
1.375 raeburn 5107:
1.220 raeburn 5108: # Clean out any old student roles the user has in this class.
5109: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
5110: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
5111: my $enroll_result =
5112: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
5113: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
5114: $env{'form.cmiddlename'},$env{'form.clastname'},
5115: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 5116: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
5117: $credits);
1.220 raeburn 5118: if ($enroll_result =~ /^ok/) {
1.381 bisitz 5119: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 5120: if ($env{'form.sections'} ne '') {
5121: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
5122: }
5123: my ($showstart,$showend);
5124: if ($startdate <= $now) {
5125: $showstart = &mt('Access starts immediately');
5126: } else {
5127: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
5128: }
5129: if ($enddate == 0) {
5130: $showend = &mt('ends: no ending date');
5131: } else {
5132: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
5133: }
5134: $r->print('.<br />'.$showstart.'; '.$showend);
5135: if ($startdate <= $now && !$newuser) {
1.386 bisitz 5136: $r->print('<p class="LC_info">');
1.318 raeburn 5137: if ($crstype eq 'Community') {
1.392 raeburn 5138: $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 5139: } else {
1.392 raeburn 5140: $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 5141: }
5142: $r->print('</p>');
1.220 raeburn 5143: }
5144: } else {
5145: $r->print(&mt('unable to enroll').": ".$enroll_result);
5146: }
5147: return;
1.188 raeburn 5148: }
5149:
1.204 raeburn 5150: sub get_defaultquota_text {
5151: my ($settingstatus) = @_;
5152: my $defquotatext;
5153: if ($settingstatus eq '') {
1.383 raeburn 5154: $defquotatext = &mt('default');
1.204 raeburn 5155: } else {
5156: my ($usertypes,$order) =
5157: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
5158: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 5159: $defquotatext = &mt('default');
1.204 raeburn 5160: } else {
1.383 raeburn 5161: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 5162: }
5163: }
5164: return $defquotatext;
5165: }
5166:
1.188 raeburn 5167: sub update_result_form {
5168: my ($uhome) = @_;
5169: my $outcome =
1.367 golterma 5170: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 5171: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 5172: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 5173: }
1.207 raeburn 5174: if ($env{'form.origname'} ne '') {
5175: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
5176: }
1.160 raeburn 5177: foreach my $item ('sortby','seluname','seludom') {
5178: if (exists($env{'form.'.$item})) {
1.188 raeburn 5179: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 5180: }
5181: }
1.188 raeburn 5182: if ($uhome eq 'no_host') {
5183: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
5184: }
5185: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 5186: '<input type="hidden" name="currstate" value="" />'."\n".
5187: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 5188: '</form>';
5189: return $outcome;
1.4 www 5190: }
5191:
1.149 raeburn 5192: sub quota_admin {
1.378 raeburn 5193: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 5194: my $quotachanged;
5195: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
5196: # Current user has quota modification privileges
1.267 raeburn 5197: if (ref($changeHash) eq 'HASH') {
5198: $quotachanged = 1;
1.378 raeburn 5199: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 5200: }
1.149 raeburn 5201: }
5202: return $quotachanged;
5203: }
5204:
1.267 raeburn 5205: sub tool_admin {
1.275 raeburn 5206: my ($tool,$settool,$changeHash,$context) = @_;
5207: my $canchange = 0;
1.279 raeburn 5208: if ($context eq 'requestcourses') {
1.275 raeburn 5209: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
5210: $canchange = 1;
5211: }
1.300 raeburn 5212: } elsif ($context eq 'reqcrsotherdom') {
5213: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
5214: $canchange = 1;
5215: }
1.362 raeburn 5216: } elsif ($context eq 'requestauthor') {
5217: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
5218: $canchange = 1;
5219: }
1.470 raeburn 5220: } elsif ($context eq 'authordefaults') {
5221: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
5222: $canchange = 1;
5223: }
1.275 raeburn 5224: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
5225: # Current user has quota modification privileges
5226: $canchange = 1;
5227: }
1.267 raeburn 5228: my $toolchanged;
1.275 raeburn 5229: if ($canchange) {
1.267 raeburn 5230: if (ref($changeHash) eq 'HASH') {
5231: $toolchanged = 1;
1.362 raeburn 5232: if ($tool eq 'requestauthor') {
5233: $changeHash->{$context} = $settool;
1.470 raeburn 5234: } elsif (($tool eq 'managers') || ($tool eq 'editors')) {
5235: $changeHash->{'author'.$tool} = $settool;
5236: } elsif ($tool eq 'webdav') {
5237: $changeHash->{'tools.'.$tool} = $settool;
1.362 raeburn 5238: } else {
5239: $changeHash->{$context.'.'.$tool} = $settool;
5240: }
1.267 raeburn 5241: }
5242: }
5243: return $toolchanged;
5244: }
5245:
1.88 raeburn 5246: sub build_roles {
1.89 raeburn 5247: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 5248: my $num_sections = 0;
5249: if ($sectionstr=~ /,/) {
5250: my @secnums = split/,/,$sectionstr;
1.89 raeburn 5251: if ($role eq 'st') {
5252: $secnums[0] =~ s/\W//g;
5253: $$sections{$secnums[0]} = 1;
5254: $num_sections = 1;
5255: } else {
5256: foreach my $sec (@secnums) {
5257: $sec =~ ~s/\W//g;
1.150 banghart 5258: if (!($sec eq "")) {
1.89 raeburn 5259: if (exists($$sections{$sec})) {
5260: $$sections{$sec} ++;
5261: } else {
5262: $$sections{$sec} = 1;
5263: $num_sections ++;
5264: }
1.88 raeburn 5265: }
5266: }
5267: }
5268: } else {
5269: $sectionstr=~s/\W//g;
5270: unless ($sectionstr eq '') {
5271: $$sections{$sectionstr} = 1;
5272: $num_sections ++;
5273: }
5274: }
1.129 albertel 5275:
1.88 raeburn 5276: return $num_sections;
5277: }
5278:
1.58 www 5279: # ========================================================== Custom Role Editor
5280:
5281: sub custom_role_editor {
1.439 raeburn 5282: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 5283: my $action = $env{'form.customroleaction'};
1.439 raeburn 5284: my ($rolename,$helpitem);
1.324 raeburn 5285: if ($action eq 'new') {
5286: $rolename=$env{'form.newrolename'};
5287: } else {
5288: $rolename=$env{'form.rolename'};
1.59 www 5289: }
5290:
1.324 raeburn 5291: my ($crstype,$context);
5292: if ($env{'request.course.id'}) {
5293: $crstype = &Apache::loncommon::course_type();
5294: $context = 'course';
1.439 raeburn 5295: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 5296: } else {
5297: $context = 'domain';
1.414 raeburn 5298: $crstype = 'course';
1.439 raeburn 5299: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 5300: }
1.351 raeburn 5301:
5302: $rolename=~s/[^A-Za-z0-9]//gs;
5303: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 5304: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
5305: $permission);
1.351 raeburn 5306: return;
5307: }
5308:
1.414 raeburn 5309: my $formname = 'form1';
5310: my %privs=();
5311: my $body_top = '<h2>';
5312: # ------------------------------------------------------- Does this role exist?
1.59 www 5313: my ($rdummy,$roledef)=
5314: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
5315: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 5316: $body_top .= &mt('Existing Role').' "';
1.61 www 5317: # ------------------------------------------------- Get current role privileges
1.414 raeburn 5318: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
5319: if ($privs{'system'} =~ /bre\&S/) {
5320: if ($context eq 'domain') {
1.417 raeburn 5321: $crstype = 'Course';
1.414 raeburn 5322: } elsif ($crstype eq 'Community') {
5323: $privs{'system'} =~ s/bre\&S//;
5324: }
5325: } elsif ($context eq 'domain') {
5326: $crstype = 'Course';
1.324 raeburn 5327: }
1.59 www 5328: } else {
1.414 raeburn 5329: $body_top .= &mt('New Role').' "';
5330: $roledef='';
1.59 www 5331: }
1.153 banghart 5332: $body_top .= $rolename.'"</h2>';
1.414 raeburn 5333:
5334: # ------------------------------------------------------- What can be assigned?
5335: my %full=();
1.417 raeburn 5336: my %levels=(
1.414 raeburn 5337: course => {},
5338: domain => {},
5339: system => {},
5340: );
5341: my %levelscurrent=(
5342: course => {},
5343: domain => {},
5344: system => {},
5345: );
5346: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 5347: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 5348: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 5349: my $head_script =
1.414 raeburn 5350: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
5351: \%full,\@templateroles,$jsback);
1.351 raeburn 5352: push (@{$brcrum},
1.414 raeburn 5353: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 5354: text => "Pick custom role",
5355: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 5356: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 5357: text => "Edit custom role",
5358: faq => 282,
5359: bug => 'Instructor Interface',
1.439 raeburn 5360: help => $helpitem}
1.351 raeburn 5361: );
5362: my $args = { bread_crumbs => $brcrum,
5363: bread_crumbs_component => 'User Management'};
5364: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
5365: $head_script,$args).
5366: $body_top);
1.414 raeburn 5367: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
5368: &Apache::lonuserutils::custom_role_header($context,$crstype,
5369: \@templateroles,$prefix));
1.264 bisitz 5370:
1.61 www 5371: $r->print(<<ENDCCF);
5372: <input type="hidden" name="phase" value="set_custom_roles" />
5373: <input type="hidden" name="rolename" value="$rolename" />
5374: ENDCCF
1.414 raeburn 5375: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
5376: \%levelscurrent,$prefix));
1.135 raeburn 5377: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 5378: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 5379: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 5380: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 5381: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 5382: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 5383: }
1.414 raeburn 5384:
1.61 www 5385: # ---------------------------------------------------------- Call to definerole
5386: sub set_custom_role {
1.439 raeburn 5387: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 5388: my $rolename=$env{'form.rolename'};
1.63 www 5389: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 5390: if (!$rolename) {
1.439 raeburn 5391: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 5392: return;
5393: }
1.160 raeburn 5394: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 5395: my $jscript = '<script type="text/javascript">'
5396: .'// <![CDATA['."\n"
5397: .$jsback."\n"
5398: .'// ]]>'."\n"
5399: .'</script>'."\n";
1.439 raeburn 5400: my $helpitem = 'Course_Editing_Custom_Roles';
5401: if ($context eq 'domain') {
5402: $helpitem = 'Domain_Editing_Custom_Roles';
5403: }
1.352 raeburn 5404: push(@{$brcrum},
5405: {href => "javascript:backPage(document.customresult,'pickrole','')",
5406: text => "Pick custom role",
5407: faq => 282,
5408: bug => 'Instructor Interface',},
5409: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
5410: text => "Edit custom role",
5411: faq => 282,
5412: bug => 'Instructor Interface',},
5413: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
5414: text => "Result",
5415: faq => 282,
5416: bug => 'Instructor Interface',
1.439 raeburn 5417: help => $helpitem,}
1.352 raeburn 5418: );
5419: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 5420: bread_crumbs_component => 'User Management'};
1.351 raeburn 5421: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 5422:
1.393 raeburn 5423: my $newrole;
1.61 www 5424: my ($rdummy,$roledef)=
1.110 albertel 5425: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
5426:
1.61 www 5427: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 5428: $r->print('<h3>');
1.61 www 5429: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 5430: $r->print(&mt('Existing Role').' "');
1.61 www 5431: } else {
1.73 sakharuk 5432: $r->print(&mt('New Role').' "');
1.61 www 5433: $roledef='';
1.393 raeburn 5434: $newrole = 1;
1.61 www 5435: }
1.188 raeburn 5436: $r->print($rolename.'"</h3>');
1.414 raeburn 5437: # ------------------------------------------------- Assign role and show result
1.61 www 5438:
1.387 bisitz 5439: my $errmsg;
1.414 raeburn 5440: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
5441: # Assign role and return result
5442: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
5443: $newprivs{'c'});
1.387 bisitz 5444: if ($result ne 'ok') {
5445: $errmsg = ': '.$result;
5446: }
5447: my $message =
5448: &Apache::lonhtmlcommon::confirm_success(
5449: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 5450: if ($env{'request.course.id'}) {
5451: my $url='/'.$env{'request.course.id'};
1.63 www 5452: $url=~s/\_/\//g;
1.387 bisitz 5453: $result =
5454: &Apache::lonnet::assigncustomrole(
5455: $env{'user.domain'},$env{'user.name'},
5456: $url,
5457: $env{'user.domain'},$env{'user.name'},
5458: $rolename,undef,undef,undef,$context);
5459: if ($result ne 'ok') {
5460: $errmsg = ': '.$result;
5461: }
5462: $message .=
5463: '<br />'
5464: .&Apache::lonhtmlcommon::confirm_success(
5465: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 5466: }
1.380 bisitz 5467: $r->print(
1.387 bisitz 5468: &Apache::loncommon::confirmwrapper($message)
5469: .'<br />'
5470: .&Apache::lonhtmlcommon::actionbox([
5471: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
5472: .&mt('Create or edit another custom role')
5473: .'</a>'])
1.380 bisitz 5474: .'<form name="customresult" method="post" action="">'
1.387 bisitz 5475: .&Apache::lonhtmlcommon::echo_form_input([])
5476: .'</form>'
1.380 bisitz 5477: );
1.58 www 5478: }
5479:
1.465 raeburn 5480: sub show_role_requests {
5481: my ($caller,$dom) = @_;
5482: my $showrolereqs;
5483: my %domconfig = &Apache::lonnet::get_dom('configuration',['privacy'],$dom);
5484: if (ref($domconfig{'privacy'}) eq 'HASH') {
5485: if (ref($domconfig{'privacy'}{'approval'}) eq 'HASH') {
5486: my %approvalconf = %{$domconfig{'privacy'}{'approval'}};
5487: foreach my $key ('instdom','extdom') {
5488: if (ref($approvalconf{$key}) eq 'HASH') {
5489: if (keys(%{$approvalconf{$key}})) {
5490: foreach my $context ('domain','author','course','community') {
5491: if ($approvalconf{$key}{$context} eq $caller) {
5492: $showrolereqs = 1;
5493: last if ($showrolereqs);
5494: }
5495: }
5496: }
5497: }
5498: last if ($showrolereqs);
5499: }
5500: }
5501: }
5502: return $showrolereqs;
5503: }
5504:
1.470 raeburn 5505: sub display_coauthor_managers {
5506: my ($permission) = @_;
5507: my $output;
5508: if ((ref($permission) eq 'HASH') && ($permission->{'author'})) {
5509: $output = '<form action="/adm/createuser" method="post" name="camanagers">'.
5510: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
5511: '<p>';
5512: my (@possmanagers,@custommanagers);
5513: my %userenv =
5514: &Apache::lonnet::userenvironment($env{'user.domain'},
5515: $env{'user.name'},
5516: 'authormanagers');
5517: my %ca_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5518: ['active','future'],['ca']);
5519: if (keys(%ca_roles)) {
5520: foreach my $entry (sort(keys(%ca_roles))) {
5521: if ($entry =~ /^($match_username\:$match_domain):ca$/) {
5522: my $user = $1;
5523: unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5524: push(@possmanagers,$user);
5525: }
5526: }
5527: }
5528: }
5529: if ($userenv{'authormanagers'} eq '') {
5530: $output .= &mt('Currently author manages co-author roles');
5531: } else {
5532: if (keys(%ca_roles)) {
5533: foreach my $user (split(/,/,$userenv{'authormanagers'})) {
5534: if ($user =~ /^($match_username)\:($match_domain)$/) {
5535: if (exists($ca_roles{$user.':ca'})) {
5536: unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5537: push(@custommanagers,$user);
5538: }
5539: }
5540: }
5541: }
5542: }
5543: if (@custommanagers) {
5544: $output .= &mt('Co-authors with active or future roles who currently manage co-author roles: [_1]',
5545: '<br />'.join(', ',map { &Apache::loncommon::plainname(split(':',$_))." ($_)"; } @custommanagers));
5546: } else {
5547: $output .= &mt('Currently author manages co-author roles');
5548: }
5549: }
5550: $output .= "</p>\n";
5551: if (@possmanagers) {
1.472 raeburn 5552: $output .= '<p>'.&mt('If checked, can manage').': ';
1.470 raeburn 5553: foreach my $user (@possmanagers) {
5554: my $checked;
5555: if (grep(/^\Q$user\E$/,@custommanagers)) {
5556: $checked = ' checked="checked"';
5557: }
5558: $output .= '<span style="LC_nobreak"><label>'.
5559: '<input type="checkbox" name="custommanagers" '.
5560: 'value="'.&HTML::Entities::encode($user,'\'<>"&').'"'.$checked.' />'.
5561: &Apache::loncommon::plainname(split(/:/,$user))." ($user)".'</label></span> '."\n";
5562: }
5563: $output .= '<input type="hidden" name="state" value="process" /></p>'."\n".
5564: '<p><input type="submit" value="'.&mt('Save changes').'" /></p>'."\n";
5565: } else {
5566: $output .= '<p>'.&mt('No co-author roles assignable as manager').'</p>';
5567: }
5568: $output .= '</form>';
5569: } else {
5570: $output = '<span class="LC_warning">'.
5571: &mt('You do not have permission to perform this action').
5572: '</span>';
5573: }
5574: return $output;
5575: }
5576:
5577: sub update_coauthor_managers {
5578: my ($permission) = @_;
5579: my $output;
5580: if ((ref($permission) eq 'HASH') && ($permission->{'author'})) {
5581: my ($current,$newval,@possibles,@managers);
5582: my %userenv =
5583: &Apache::lonnet::userenvironment($env{'user.domain'},
5584: $env{'user.name'},
5585: 'authormanagers');
5586: $current = $userenv{'authormanagers'};
5587: @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
5588: if (@possibles) {
5589: my %ca_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5590: ['active','future'],['ca']);
5591: if (keys(%ca_roles)) {
5592: foreach my $user (@possibles) {
5593: if ($user =~ /^($match_username):($match_domain)$/) {
5594: if (exists($ca_roles{$user.':ca'})) {
5595: unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5596: push(@managers,$user);
5597: }
5598: }
5599: }
5600: }
5601: if (@managers) {
5602: $newval = join(',',sort(@managers));
5603: }
5604: }
5605: }
5606: if ($current eq $newval) {
5607: $output = &mt('No changes made to management of co-author roles');
5608: } else {
5609: my $chgresult =
5610: &Apache::lonnet::put('environment',{'authormanagers' => $newval},
5611: $env{'user.domain'},$env{'user.name'});
5612: if ($chgresult eq 'ok') {
5613: &Apache::lonnet::appenv({'environment.authormanagers' => $newval});
5614: my (@adds,@dels);
5615: if ($newval eq '') {
5616: @dels = split(/,/,$current);
5617: } elsif ($current eq '') {
5618: @adds = @managers;
5619: } else {
5620: my @old = split(/,/,$current);
5621: my @diffs = &Apache::loncommon::compare_arrays(\@old,\@managers);
5622: if (@diffs) {
5623: foreach my $user (@diffs) {
5624: if (grep(/^\Q$user\E$/,@old)) {
5625: push(@dels,$user);
5626: } elsif (grep(/^\Q$user\E$/,@managers)) {
5627: push(@adds,$user);
5628: }
5629: }
5630: }
5631: }
5632: my $key = "internal.manager./$env{'user.domain'}/$env{'user.name'}";
5633: if (@dels) {
5634: foreach my $user (@dels) {
5635: if ($user =~ /^($match_username):($match_domain)$/) {
5636: &Apache::lonnet::del('environment',[$key],$2,$1);
5637: }
5638: }
5639: }
5640: if (@adds) {
5641: foreach my $user (@adds) {
5642: if ($user =~ /^($match_username):($match_domain)$/) {
5643: &Apache::lonnet::put('environment',{$key => 1},$2,$1);
5644: }
5645: }
5646: }
5647: if ($newval eq '') {
5648: $output = &mt('Management of co-authors set to be author-only');
5649: } else {
5650: $output .= &mt('Co-authors who can manage co-author roles set to: [_1]',
5651: '<br />'.join(', ',map { &Apache::loncommon::plainname(split(':',$_))." ($_)"; } @managers));
5652: }
5653: }
5654: }
5655: } else {
5656: $output = '<span class="LC_warning">'.
5657: &mt('You do not have permission to perform this action').
5658: '</span>';
5659: }
5660: return $output;
5661: }
5662:
1.2 www 5663: # ================================================================ Main Handler
5664: sub handler {
5665: my $r = shift;
5666: if ($r->header_only) {
1.68 www 5667: &Apache::loncommon::content_type($r,'text/html');
1.2 www 5668: $r->send_http_header;
5669: return OK;
5670: }
1.439 raeburn 5671: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
5672:
1.190 raeburn 5673: if ($env{'request.course.id'}) {
5674: $context = 'course';
1.318 raeburn 5675: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 5676: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 5677: $context = 'author';
1.470 raeburn 5678: } elsif ($env{'request.role'} =~ m{^(ca|aa)\./$match_domain/$match_username$}) {
5679: $context = 'coauthor';
1.190 raeburn 5680: } else {
5681: $context = 'domain';
5682: }
1.375 raeburn 5683:
1.439 raeburn 5684: my ($permission,$allowed) =
5685: &Apache::lonuserutils::get_permission($context,$crstype);
1.470 raeburn 5686: if (($context eq 'coauthor') && ($allowed)) {
5687: $context = 'author';
5688: }
1.439 raeburn 5689:
5690: if ($allowed) {
5691: my @allhelp;
5692: if ($context eq 'course') {
5693: $cid = $env{'request.course.id'};
5694: $cdom = $env{'course.'.$cid.'.domain'};
5695: $cnum = $env{'course.'.$cid.'.num'};
5696:
5697: if ($permission->{'cusr'}) {
5698: push(@allhelp,'Course_Create_Class_List');
5699: }
5700: if ($permission->{'view'} || $permission->{'cusr'}) {
5701: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
5702: }
5703: if ($permission->{'custom'}) {
5704: push(@allhelp,'Course_Editing_Custom_Roles');
5705: }
5706: if ($permission->{'cusr'}) {
5707: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
5708: }
5709: unless ($permission->{'cusr_section'}) {
5710: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
5711: push(@allhelp,'Course_Automated_Enrollment');
5712: }
1.469 raeburn 5713: if (($permission->{'selfenrolladmin'}) || ($permission->{'selfenrollview'})) {
1.439 raeburn 5714: push(@allhelp,'Course_Approve_Selfenroll');
5715: }
5716: }
5717: if ($permission->{'grp_manage'}) {
5718: push(@allhelp,'Course_Manage_Group');
5719: }
5720: if ($permission->{'view'} || $permission->{'cusr'}) {
5721: push(@allhelp,'Course_User_Logs');
5722: }
5723: } elsif ($context eq 'author') {
5724: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
5725: 'Author_View_Coauthor_List','Author_User_Logs'));
1.470 raeburn 5726: } elsif ($context eq 'coauthor') {
5727: if ($permission->{'cusr'}) {
5728: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
5729: 'Author_View_Coauthor_List','Author_User_Logs'));
5730: } elsif ($permission->{'view'}) {
5731: push(@allhelp,'Author_View_Coauthor_List');
5732: }
1.439 raeburn 5733: } else {
5734: if ($permission->{'cusr'}) {
5735: push(@allhelp,'Domain_Change_Privileges');
5736: if ($permission->{'activity'}) {
5737: push(@allhelp,'Domain_User_Access_Logs');
5738: }
5739: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
5740: if ($permission->{'custom'}) {
5741: push(@allhelp,'Domain_Editing_Custom_Roles');
5742: }
5743: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
5744: } elsif ($permission->{'view'}) {
5745: push(@allhelp,'Domain_View_Privileges');
5746: if ($permission->{'activity'}) {
5747: push(@allhelp,'Domain_User_Access_Logs');
5748: }
5749: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
5750: }
5751: }
5752: if (@allhelp) {
5753: $allhelpitems = join(',',@allhelp);
5754: }
5755: }
5756:
1.190 raeburn 5757: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 5758: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.470 raeburn 5759: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue',
5760: 'forceedit']);
1.190 raeburn 5761: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 5762: my $args;
5763: my $brcrum = [];
5764: my $bread_crumbs_component = 'User Management';
1.391 raeburn 5765: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 5766: $brcrum = [{href=>"/adm/createuser",
5767: text=>"User Management",
1.439 raeburn 5768: help=>$allhelpitems}
1.351 raeburn 5769: ];
1.202 raeburn 5770: }
1.190 raeburn 5771: if (!$allowed) {
1.358 raeburn 5772: if ($context eq 'course') {
5773: $r->internal_redirect('/adm/viewclasslist');
5774: return OK;
1.470 raeburn 5775: } elsif ($context eq 'coauthor') {
5776: $r->internal_redirect('/adm/viewcoauthors');
5777: return OK;
1.358 raeburn 5778: }
1.190 raeburn 5779: $env{'user.error.msg'}=
5780: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
5781: "or view user status.";
5782: return HTTP_NOT_ACCEPTABLE;
5783: }
5784:
5785: &Apache::loncommon::content_type($r,'text/html');
5786: $r->send_http_header;
5787:
1.375 raeburn 5788: my $showcredits;
5789: if ((($context eq 'course') && ($crstype eq 'Course')) ||
5790: ($context eq 'domain')) {
5791: my %domdefaults =
5792: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
5793: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
5794: $showcredits = 1;
5795: }
5796: }
5797:
1.190 raeburn 5798: # Main switch on form.action and form.state, as appropriate
5799: if (! exists($env{'form.action'})) {
1.351 raeburn 5800: $args = {bread_crumbs => $brcrum,
5801: bread_crumbs_component => $bread_crumbs_component};
5802: $r->print(&header(undef,$args));
1.318 raeburn 5803: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5804: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 5805: my $helpitem = 'Course_Create_Class_List';
5806: if ($context eq 'author') {
5807: $helpitem = 'Author_Create_Coauthor_List';
5808: } elsif ($context eq 'domain') {
5809: $helpitem = 'Domain_Create_Users';
5810: }
1.351 raeburn 5811: push(@{$brcrum},
5812: { href => '/adm/createuser?action=upload&state=',
5813: text => 'Upload Users List',
1.439 raeburn 5814: help => $helpitem,
1.351 raeburn 5815: });
5816: $bread_crumbs_component = 'Upload Users List';
5817: $args = {bread_crumbs => $brcrum,
5818: bread_crumbs_component => $bread_crumbs_component};
5819: $r->print(&header(undef,$args));
1.190 raeburn 5820: $r->print('<form name="studentform" method="post" '.
5821: 'enctype="multipart/form-data" '.
5822: ' action="/adm/createuser">'."\n");
5823: if (! exists($env{'form.state'})) {
5824: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5825: } elsif ($env{'form.state'} eq 'got_file') {
1.448 raeburn 5826: my $result =
5827: &Apache::lonuserutils::print_upload_manager_form($r,$context,
5828: $permission,
5829: $crstype,$showcredits);
5830: if ($result eq 'missingdata') {
5831: delete($env{'form.state'});
5832: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5833: }
1.190 raeburn 5834: } elsif ($env{'form.state'} eq 'enrolling') {
5835: if ($env{'form.datatoken'}) {
1.448 raeburn 5836: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
5837: $permission,
5838: $showcredits);
5839: if ($result eq 'missingdata') {
5840: delete($env{'form.state'});
5841: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5842: } elsif ($result eq 'invalidhome') {
5843: $env{'form.state'} = 'got_file';
5844: delete($env{'form.lcserver'});
5845: my $result =
5846: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
5847: $crstype,$showcredits);
5848: if ($result eq 'missingdata') {
5849: delete($env{'form.state'});
5850: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5851: }
5852: }
5853: } else {
5854: delete($env{'form.state'});
5855: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 5856: }
5857: } else {
5858: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5859: }
1.447 raeburn 5860: $r->print('</form>');
1.416 raeburn 5861: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
5862: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 5863: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 5864: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 5865: my $phase = $env{'form.phase'};
5866: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 5867: &Apache::loncreateuser::restore_prev_selections();
5868: my $srch;
5869: foreach my $item (@search) {
5870: $srch->{$item} = $env{'form.'.$item};
5871: }
1.207 raeburn 5872: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 5873: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 5874: if ($env{'form.phase'} eq 'createnewuser') {
5875: my $response;
5876: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 5877: my $response =
5878: '<span class="LC_warning">'
5879: .&mt('You must specify a valid username. Only the following are allowed:'
5880: .' letters numbers - . @')
5881: .'</span>';
1.221 raeburn 5882: $env{'form.phase'} = '';
1.375 raeburn 5883: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 5884: $crstype,$brcrum,$permission);
1.207 raeburn 5885: } else {
5886: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
5887: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
5888: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 5889: $srch,$response,$context,
1.375 raeburn 5890: $permission,$crstype,$brcrum,
5891: $showcredits);
1.207 raeburn 5892: }
5893: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 5894: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 5895: &user_search_result($context,$srch);
1.190 raeburn 5896: if ($env{'form.currstate'} eq 'modify') {
5897: $currstate = $env{'form.currstate'};
5898: }
5899: if ($currstate eq 'select') {
5900: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 5901: \@search,$context,undef,$crstype,
5902: $brcrum);
1.416 raeburn 5903: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
5904: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 5905: if (($srch->{'srchby'} eq 'uname') &&
5906: ($srch->{'srchtype'} eq 'exact')) {
5907: $ccuname = $srch->{'srchterm'};
5908: $ccdomain= $srch->{'srchdomain'};
5909: } else {
5910: my @matchedunames = keys(%{$results});
5911: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
5912: }
5913: $ccuname =&LONCAPA::clean_username($ccuname);
5914: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 5915: if ($env{'form.action'} eq 'accesslogs') {
5916: my $uhome;
5917: if (($ccuname ne '') && ($ccdomain ne '')) {
5918: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
5919: }
5920: if (($uhome eq '') || ($uhome eq 'no_host')) {
5921: $env{'form.phase'} = '';
5922: undef($forcenewuser);
5923: #if ($response) {
5924: # unless ($response =~ m{\Q<br /><br />\E$}) {
5925: # $response .= '<br /><br />';
5926: # }
5927: #}
5928: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 5929: $forcenewuser,$crstype,$brcrum,
5930: $permission);
1.416 raeburn 5931: } else {
5932: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
5933: }
5934: } else {
5935: if ($env{'form.forcenewuser'}) {
5936: $response = '';
5937: }
5938: &print_user_modification_page($r,$ccuname,$ccdomain,
5939: $srch,$response,$context,
5940: $permission,$crstype,$brcrum);
1.190 raeburn 5941: }
5942: } elsif ($currstate eq 'query') {
1.351 raeburn 5943: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 5944: } else {
1.229 raeburn 5945: $env{'form.phase'} = '';
1.207 raeburn 5946: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 5947: $forcenewuser,$crstype,$brcrum,
5948: $permission);
1.190 raeburn 5949: }
5950: } elsif ($env{'form.phase'} eq 'userpicked') {
5951: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
5952: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 5953: if ($env{'form.action'} eq 'accesslogs') {
5954: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
5955: } else {
5956: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
5957: $context,$permission,$crstype,
5958: $brcrum);
5959: }
5960: } elsif ($env{'form.action'} eq 'accesslogs') {
5961: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
5962: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
5963: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 5964: }
5965: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.451 raeburn 5966: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 5967: } else {
1.351 raeburn 5968: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 5969: $brcrum,$permission);
1.190 raeburn 5970: }
5971: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 5972: my $prefix;
1.190 raeburn 5973: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 5974: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 5975: } else {
1.439 raeburn 5976: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 5977: }
1.362 raeburn 5978: } elsif (($env{'form.action'} eq 'processauthorreq') &&
5979: ($permission->{'cusr'}) &&
5980: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
5981: push(@{$brcrum},
5982: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 5983: text => 'Authoring Space requests',
1.362 raeburn 5984: help => 'Domain_Role_Approvals'});
5985: $bread_crumbs_component = 'Authoring requests';
5986: if ($env{'form.state'} eq 'done') {
5987: push(@{$brcrum},
5988: {href => '/adm/createuser?action=authorreqqueue',
5989: text => 'Result',
5990: help => 'Domain_Role_Approvals'});
5991: $bread_crumbs_component = 'Authoring request result';
5992: }
5993: $args = { bread_crumbs => $brcrum,
5994: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 5995: my $js = &usernamerequest_javascript();
5996: $r->print(&header(&add_script($js),$args));
1.362 raeburn 5997: if (!exists($env{'form.state'})) {
5998: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
5999: $env{'request.role.domain'}));
6000: } elsif ($env{'form.state'} eq 'done') {
6001: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
6002: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
6003: $env{'request.role.domain'}));
6004: }
1.391 raeburn 6005: } elsif (($env{'form.action'} eq 'processusernamereq') &&
6006: ($permission->{'cusr'}) &&
6007: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
6008: push(@{$brcrum},
6009: {href => '/adm/createuser?action=processusernamereq',
6010: text => 'LON-CAPA account requests',
6011: help => 'Domain_Username_Approvals'});
6012: $bread_crumbs_component = 'Account requests';
6013: if ($env{'form.state'} eq 'done') {
6014: push(@{$brcrum},
6015: {href => '/adm/createuser?action=usernamereqqueue',
6016: text => 'Result',
6017: help => 'Domain_Username_Approvals'});
6018: $bread_crumbs_component = 'LON-CAPA account request result';
6019: }
6020: $args = { bread_crumbs => $brcrum,
6021: bread_crumbs_component => $bread_crumbs_component};
6022: my $js = &usernamerequest_javascript();
6023: $r->print(&header(&add_script($js),$args));
6024: if (!exists($env{'form.state'})) {
6025: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
6026: $env{'request.role.domain'}));
6027: } elsif ($env{'form.state'} eq 'done') {
6028: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
6029: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
6030: $env{'request.role.domain'}));
6031: }
6032: } elsif (($env{'form.action'} eq 'displayuserreq') &&
6033: ($permission->{'cusr'})) {
6034: my $dom = $env{'form.domain'};
6035: my $uname = $env{'form.username'};
6036: my $warning;
6037: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
6038: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
6039: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
6040: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
6041: if ($uhome eq 'no_host') {
6042: my $queue = $env{'form.queue'};
6043: my $reqkey = &escape($uname).'_'.$queue;
6044: my $namespace = 'usernamequeue';
6045: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
6046: my %queued =
6047: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
6048: unless ($queued{$reqkey}) {
6049: $warning = &mt('No information was found for this LON-CAPA account request.');
6050: }
6051: } else {
6052: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
6053: }
6054: } else {
6055: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
6056: }
6057: } else {
6058: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
6059: }
6060: } else {
6061: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
6062: }
6063: my $args = { only_body => 1 };
6064: $r->print(&header(undef,$args).
6065: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
6066: if ($warning ne '') {
6067: $r->print('<div class="LC_warning">'.$warning.'</div>');
6068: } else {
6069: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
6070: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
6071: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6072: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6073: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
6074: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
6075: my %info =
6076: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
6077: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 6078: my $usertype = $info{$uname}{'inststatus'};
6079: unless ($usertype) {
6080: $usertype = 'default';
6081: }
1.442 raeburn 6082: my ($showstatus,$showemail,$pickstart);
6083: my $numextras = 0;
6084: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.443 raeburn 6085: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
6086: if (ref($usertypes) eq 'HASH') {
6087: if ($usertypes->{$usertype}) {
6088: $showstatus = $usertypes->{$usertype};
6089: } else {
6090: $showstatus = $othertitle;
6091: }
6092: if ($showstatus) {
6093: $numextras ++;
6094: }
1.442 raeburn 6095: }
6096: }
6097: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
6098: $showemail = $info{$uname}{'email'};
6099: $numextras ++;
6100: }
1.396 raeburn 6101: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
6102: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.442 raeburn 6103: $pickstart = 1;
1.396 raeburn 6104: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.442 raeburn 6105: my ($num,$count);
1.396 raeburn 6106: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.442 raeburn 6107: $count += $numextras;
1.396 raeburn 6108: foreach my $field (@{$infofields}) {
6109: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
6110: next unless ($infotitles->{$field});
6111: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
6112: $info{$uname}{$field});
6113: $num ++;
1.442 raeburn 6114: unless ($count == $num) {
1.396 raeburn 6115: $r->print(&Apache::lonhtmlcommon::row_closure());
6116: }
6117: }
1.442 raeburn 6118: }
6119: }
6120: if ($numextras) {
6121: unless ($pickstart) {
6122: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
6123: $pickstart = 1;
6124: }
6125: if ($showemail) {
6126: my $closure = '';
6127: unless ($showstatus) {
6128: $closure = 1;
1.391 raeburn 6129: }
1.442 raeburn 6130: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
6131: $showemail.
6132: &Apache::lonhtmlcommon::row_closure($closure));
1.391 raeburn 6133: }
1.442 raeburn 6134: if ($showstatus) {
6135: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
6136: $showstatus.
6137: &Apache::lonhtmlcommon::row_closure(1));
6138: }
6139: }
6140: if ($pickstart) {
6141: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
6142: } else {
6143: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
1.391 raeburn 6144: }
1.442 raeburn 6145: } else {
6146: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 6147: }
6148: }
6149: }
6150: }
6151: }
1.442 raeburn 6152: $r->print(&close_popup_form());
1.207 raeburn 6153: } elsif (($env{'form.action'} eq 'listusers') &&
6154: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 6155: my $helpitem = 'Course_View_Class_List';
6156: if ($context eq 'author') {
6157: $helpitem = 'Author_View_Coauthor_List';
6158: } elsif ($context eq 'domain') {
6159: $helpitem = 'Domain_View_Users_List';
6160: }
1.202 raeburn 6161: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 6162: push(@{$brcrum},
6163: {href => '/adm/createuser?action=listusers',
6164: text => "List Users"},
6165: {href => "/adm/createuser",
6166: text => "Result",
1.439 raeburn 6167: help => $helpitem});
1.351 raeburn 6168: $bread_crumbs_component = 'Update Users';
6169: $args = {bread_crumbs => $brcrum,
6170: bread_crumbs_component => $bread_crumbs_component};
6171: $r->print(&header(undef,$args));
1.202 raeburn 6172: my $setting = $env{'form.roletype'};
6173: my $choice = $env{'form.bulkaction'};
6174: if ($permission->{'cusr'}) {
1.336 raeburn 6175: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 6176: } else {
6177: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 6178: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 6179: }
6180: } else {
1.351 raeburn 6181: push(@{$brcrum},
6182: {href => '/adm/createuser?action=listusers',
6183: text => "List Users",
1.439 raeburn 6184: help => $helpitem});
1.351 raeburn 6185: $bread_crumbs_component = 'List Users';
6186: $args = {bread_crumbs => $brcrum,
6187: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 6188: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
6189: my $formname = 'studentform';
1.364 raeburn 6190: my $hidecall = "hide_searching();";
1.321 raeburn 6191: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
6192: ($env{'form.roletype'} eq 'community'))) {
6193: if ($env{'form.roletype'} eq 'course') {
6194: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
6195: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
6196: $formname);
6197: } elsif ($env{'form.roletype'} eq 'community') {
6198: $cb_jscript =
6199: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
6200: my %elements = (
6201: coursepick => 'radio',
6202: coursetotal => 'text',
6203: courselist => 'text',
6204: );
6205: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
6206: }
1.364 raeburn 6207: $jscript .= &verify_user_display($context)."\n".
6208: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 6209: my $js = &add_script($jscript).$cb_jscript;
6210: my $loadcode =
6211: &Apache::lonuserutils::course_selector_loadcode($formname);
6212: if ($loadcode ne '') {
1.364 raeburn 6213: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
6214: } else {
6215: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 6216: }
1.351 raeburn 6217: $r->print(&header($js,$args));
1.191 raeburn 6218: } else {
1.364 raeburn 6219: $args->{add_entries} = {onload => $hidecall};
6220: $jscript = &verify_user_display($context).
6221: &Apache::loncommon::check_uncheck_jscript();
6222: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 6223: }
1.202 raeburn 6224: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 6225: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
6226: $showcredits);
1.191 raeburn 6227: }
1.213 raeburn 6228: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 6229: my $brtext;
6230: if ($crstype eq 'Community') {
6231: $brtext = 'Drop Members';
6232: } else {
6233: $brtext = 'Drop Students';
6234: }
1.351 raeburn 6235: push(@{$brcrum},
6236: {href => '/adm/createuser?action=drop',
6237: text => $brtext,
6238: help => 'Course_Drop_Student'});
6239: if ($env{'form.state'} eq 'done') {
6240: push(@{$brcrum},
6241: {href=>'/adm/createuser?action=drop',
6242: text=>"Result"});
6243: }
6244: $bread_crumbs_component = $brtext;
6245: $args = {bread_crumbs => $brcrum,
6246: bread_crumbs_component => $bread_crumbs_component};
6247: $r->print(&header(undef,$args));
1.213 raeburn 6248: if (!exists($env{'form.state'})) {
1.318 raeburn 6249: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 6250: } elsif ($env{'form.state'} eq 'done') {
6251: &Apache::lonuserutils::update_user_list($r,$context,undef,
6252: $env{'form.action'});
6253: }
1.202 raeburn 6254: } elsif ($env{'form.action'} eq 'dateselect') {
6255: if ($permission->{'cusr'}) {
1.351 raeburn 6256: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 6257: &Apache::lonuserutils::date_section_selector($context,$permission,
6258: $crstype,$showcredits));
1.202 raeburn 6259: } else {
1.351 raeburn 6260: $r->print(&header(undef,{'no_nav_bar' => 1}).
6261: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 6262: }
1.237 raeburn 6263: } elsif ($env{'form.action'} eq 'selfenroll') {
1.469 raeburn 6264: my %currsettings;
6265: if ($permission->{selfenrolladmin} || $permission->{selfenrollview}) {
6266: %currsettings = (
1.398 raeburn 6267: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
6268: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
6269: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
6270: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
6271: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
6272: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
6273: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
6274: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
6275: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
6276: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
6277: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
6278: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
6279: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 6280: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 6281: );
1.469 raeburn 6282: }
6283: if ($permission->{selfenrolladmin}) {
1.398 raeburn 6284: push(@{$brcrum},
6285: {href => '/adm/createuser?action=selfenroll',
6286: text => "Configure Self-enrollment",
6287: help => 'Course_Self_Enrollment'});
6288: if (!exists($env{'form.state'})) {
6289: $args = { bread_crumbs => $brcrum,
6290: bread_crumbs_component => 'Configure Self-enrollment'};
6291: $r->print(&header(undef,$args));
6292: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
6293: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
6294: } elsif ($env{'form.state'} eq 'done') {
6295: push (@{$brcrum},
6296: {href=>'/adm/createuser?action=selfenroll',
6297: text=>"Result"});
6298: $args = { bread_crumbs => $brcrum,
6299: bread_crumbs_component => 'Self-enrollment result'};
6300: $r->print(&header(undef,$args));
6301: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 6302: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 6303: }
1.469 raeburn 6304: } elsif ($permission->{selfenrollview}) {
6305: push(@{$brcrum},
6306: {href => '/adm/createuser?action=selfenroll',
6307: text => "View Self-enrollment configuration",
6308: help => 'Course_Self_Enrollment'});
6309: $args = { bread_crumbs => $brcrum,
6310: bread_crumbs_component => 'Self-enrollment Settings'};
6311: $r->print(&header(undef,$args));
6312: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
6313: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings,'',1);
1.398 raeburn 6314: } else {
6315: $r->print(&header(undef,{'no_nav_bar' => 1}).
6316: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 6317: }
1.277 raeburn 6318: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 6319: if ($permission->{selfenrolladmin}) {
1.351 raeburn 6320: push(@{$brcrum},
6321: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 6322: text => 'Enrollment requests',
1.439 raeburn 6323: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 6324: $bread_crumbs_component = 'Enrollment requests';
6325: if ($env{'form.state'} eq 'done') {
6326: push(@{$brcrum},
6327: {href => '/adm/createuser?action=selfenrollqueue',
6328: text => 'Result',
1.439 raeburn 6329: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 6330: $bread_crumbs_component = 'Enrollment result';
6331: }
6332: $args = { bread_crumbs => $brcrum,
6333: bread_crumbs_component => $bread_crumbs_component};
6334: $r->print(&header(undef,$args));
6335: my $coursedesc = $env{'course.'.$cid.'.description'};
6336: if (!exists($env{'form.state'})) {
6337: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
6338: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
6339: $cdom,$cnum));
6340: } elsif ($env{'form.state'} eq 'done') {
6341: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
6342: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 6343: $cdom,$cnum,$coursedesc));
1.418 raeburn 6344: }
6345: } else {
6346: $r->print(&header(undef,{'no_nav_bar' => 1}).
6347: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 6348: }
1.418 raeburn 6349: } elsif ($env{'form.action'} eq 'changelogs') {
6350: if ($permission->{cusr} || $permission->{view}) {
6351: &print_userchangelogs_display($r,$context,$permission,$brcrum);
6352: } else {
6353: $r->print(&header(undef,{'no_nav_bar' => 1}).
6354: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 6355: }
1.428 raeburn 6356: } elsif ($env{'form.action'} eq 'helpdesk') {
1.464 raeburn 6357: if (($permission->{'owner'} || $permission->{'co-owner'}) &&
6358: ($permission->{'cusr'} || $permission->{'view'})) {
1.428 raeburn 6359: if ($env{'form.state'} eq 'process') {
6360: if ($permission->{'owner'}) {
6361: &update_helpdeskaccess($r,$permission,$brcrum);
6362: } else {
6363: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 6364: }
1.428 raeburn 6365: } else {
6366: &print_helpdeskaccess_display($r,$permission,$brcrum);
6367: }
6368: } else {
6369: $r->print(&header(undef,{'no_nav_bar' => 1}).
6370: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
6371: }
1.465 raeburn 6372: } elsif ($env{'form.action'} eq 'rolerequests') {
6373: if ($permission->{cusr} || $permission->{view}) {
6374: &print_queued_roles($r,$context,$permission,$brcrum);
6375: }
6376: } elsif ($env{'form.action'} eq 'queuedroles') {
6377: if (($permission->{cusr}) && ($context eq 'domain')) {
6378: if (&show_role_requests($context,$env{'request.role.domain'})) {
6379: if ($env{'form.state'} eq 'done') {
6380: &process_pendingroles($r,$context,$permission,$brcrum);
6381: } else {
6382: &print_pendingroles($r,$context,$permission,$brcrum);
6383: }
6384: } else {
6385: $r->print(&header(undef,{'no_nav_bar' => 1}).
6386: '<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>');
6387: }
6388: } else {
6389: $r->print(&header(undef,{'no_nav_bar' => 1}).
6390: '<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>');
6391: }
1.470 raeburn 6392: } elsif ($env{'form.action'} eq 'camanagers') {
6393: if (($permission->{cusr}) && ($context eq 'author')) {
6394: push(@{$brcrum},
6395: {href => '/adm/createuser?action=camanagers',
1.473 raeburn 6396: text => 'Co-author Managers',
1.470 raeburn 6397: help => 'Author_Manage_Coauthors'});
6398: if ($env{'form.state'} eq 'process') {
6399: push(@{$brcrum},
6400: {href => '/adm/createuser?action=camanagers',
6401: text => 'Result',
6402: help => 'Author_Manage_Coauthors'});
6403: }
6404: $args = { bread_crumbs => $brcrum };
6405: $r->print(&header(undef,$args));
6406: my $coursedesc = $env{'course.'.$cid.'.description'};
6407: if (!exists($env{'form.state'})) {
6408: $r->print('<h3>'.&mt('Co-author Management').'</h3>'."\n".
6409: &display_coauthor_managers($permission));
6410: } elsif ($env{'form.state'} eq 'process') {
6411: $r->print('<h3>'.&mt('Co-author Management Update Result').'</h3>'."\n".
6412: &update_coauthor_managers($permission));
6413: }
6414: }
6415: } elsif (($env{'form.action'} eq 'calist') && ($context eq 'author')) {
6416: if ($permission->{'cusr'}) {
6417: my ($role,$audom,$auname,$canview,$canedit) =
6418: &Apache::lonviewcoauthors::get_allowable();
6419: if (($canedit) && ($env{'form.forceedit'})) {
6420: &Apache::lonviewcoauthors::get_editor_crumbs($brcrum,'/adm/createuser');
6421: my $args = { 'bread_crumbs' => $brcrum };
6422: $r->print(&Apache::loncommon::start_page('Configure co-author listing',undef,
6423: $args).
6424: &Apache::lonviewcoauthors::edit_settings($audom,$auname,$role,
6425: '/adm/createuser'));
6426: } else {
6427: push(@{$brcrum},
6428: {href => '/adm/createuser?action=calist',
6429: text => 'Coauthor-viewable list',
6430: help => 'Author_List_Coauthors'});
6431: my $args = { 'bread_crumbs' => $brcrum };
6432: $r->print(&Apache::loncommon::start_page('Coauthor-viewable list',undef,
6433: $args));
6434: my %viewsettings =
6435: &Apache::lonviewcoauthors::retrieve_view_settings($auname,$audom,$role);
6436: if ($viewsettings{'show'} eq 'none') {
6437: $r->print('<h3>'.&mt('Coauthor-viewable listing').'</h3>'.
6438: '<p class="LC_info">'.
6439: &mt('Listing of co-authors not enabled for this Authoring Space').
6440: '</p>');
6441: } else {
6442: &Apache::lonviewcoauthors::print_coauthors($r,$auname,$audom,$role,
6443: '/adm/createuser',\%viewsettings);
6444: }
6445: }
6446: } else {
6447: $r->internal_redirect('/adm/viewcoauthors');
6448: return OK;
6449: }
1.190 raeburn 6450: } else {
1.351 raeburn 6451: $bread_crumbs_component = 'User Management';
6452: $args = { bread_crumbs => $brcrum,
6453: bread_crumbs_component => $bread_crumbs_component};
6454: $r->print(&header(undef,$args));
1.318 raeburn 6455: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 6456: }
1.351 raeburn 6457: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 6458: return OK;
6459: }
6460:
6461: sub header {
1.351 raeburn 6462: my ($jscript,$args) = @_;
1.190 raeburn 6463: my $start_page;
1.351 raeburn 6464: if (ref($args) eq 'HASH') {
6465: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 6466: } else {
1.351 raeburn 6467: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 6468: }
6469: return $start_page;
6470: }
1.2 www 6471:
1.191 raeburn 6472: sub add_script {
6473: my ($js) = @_;
1.301 bisitz 6474: return '<script type="text/javascript">'."\n"
6475: .'// <![CDATA['."\n"
6476: .$js."\n"
6477: .'// ]]>'."\n"
6478: .'</script>'."\n";
1.191 raeburn 6479: }
6480:
1.391 raeburn 6481: sub usernamerequest_javascript {
6482: my $js = <<ENDJS;
6483:
6484: function openusernamereqdisplay(dom,uname,queue) {
6485: var url = '/adm/createuser?action=displayuserreq';
6486: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
6487: var title = 'Account_Request_Browser';
6488: var options = 'scrollbars=1,resizable=1,menubar=0';
6489: options += ',width=700,height=600';
6490: var stdeditbrowser = open(url,title,options,'1');
6491: stdeditbrowser.focus();
6492: return;
6493: }
6494:
6495: ENDJS
6496: }
6497:
6498: sub close_popup_form {
6499: my $close= &mt('Close Window');
6500: return << "END";
6501: <p><form name="displayreq" action="" method="post">
6502: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
6503: </form></p>
6504: END
6505: }
6506:
1.202 raeburn 6507: sub verify_user_display {
1.364 raeburn 6508: my ($context) = @_;
1.374 raeburn 6509: my %lt = &Apache::lonlocal::texthash (
6510: course => 'course(s): description, section(s), status',
6511: community => 'community(s): description, section(s), status',
6512: author => 'author',
6513: );
1.364 raeburn 6514: my $photos;
6515: if (($context eq 'course') && $env{'request.course.id'}) {
6516: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
6517: }
1.202 raeburn 6518: my $output = <<"END";
6519:
1.364 raeburn 6520: function hide_searching() {
6521: if (document.getElementById('searching')) {
6522: document.getElementById('searching').style.display = 'none';
6523: }
6524: return;
6525: }
6526:
1.202 raeburn 6527: function display_update() {
6528: document.studentform.action.value = 'listusers';
6529: document.studentform.phase.value = 'display';
6530: document.studentform.submit();
6531: }
6532:
1.364 raeburn 6533: function updateCols(caller) {
6534: var context = '$context';
6535: var photos = '$photos';
6536: if (caller == 'Status') {
1.374 raeburn 6537: if ((context == 'domain') &&
6538: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
6539: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 6540: document.getElementById('showcolstatus').checked = false;
6541: document.getElementById('showcolstatus').disabled = 'disabled';
6542: document.getElementById('showcolstart').checked = false;
6543: document.getElementById('showcolend').checked = false;
1.374 raeburn 6544: } else {
6545: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
6546: document.getElementById('showcolstatus').checked = true;
6547: document.getElementById('showcolstatus').disabled = '';
6548: document.getElementById('showcolstart').checked = true;
6549: document.getElementById('showcolend').checked = true;
6550: } else {
6551: document.getElementById('showcolstatus').checked = false;
6552: document.getElementById('showcolstatus').disabled = 'disabled';
6553: document.getElementById('showcolstart').checked = false;
6554: document.getElementById('showcolend').checked = false;
6555: }
1.472 raeburn 6556: if (context == 'author') {
6557: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Expired') {
6558: document.getElementById('showcolmanager').checked = false;
6559: document.getElementById('showcolmanager').disabled = 'disabled';
6560: } else if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value != 'aa') {
6561: document.getElementById('showcolmanager').checked = true;
6562: document.getElementById('showcolmanager').disabled = '';
6563: }
6564: }
1.364 raeburn 6565: }
6566: }
6567: if (caller == 'output') {
6568: if (photos == 1) {
6569: if (document.getElementById('showcolphoto')) {
6570: var photoitem = document.getElementById('showcolphoto');
6571: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
6572: photoitem.checked = true;
6573: photoitem.disabled = '';
6574: } else {
6575: photoitem.checked = false;
6576: photoitem.disabled = 'disabled';
6577: }
6578: }
6579: }
6580: }
6581: if (caller == 'showrole') {
1.371 raeburn 6582: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
6583: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 6584: document.getElementById('showcolrole').checked = true;
6585: document.getElementById('showcolrole').disabled = '';
6586: } else {
6587: document.getElementById('showcolrole').checked = false;
6588: document.getElementById('showcolrole').disabled = 'disabled';
6589: }
1.374 raeburn 6590: if (context == 'domain') {
1.382 raeburn 6591: var quotausageshow = 0;
1.374 raeburn 6592: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
6593: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
6594: document.getElementById('showcolstatus').checked = false;
6595: document.getElementById('showcolstatus').disabled = 'disabled';
6596: document.getElementById('showcolstart').checked = false;
6597: document.getElementById('showcolend').checked = false;
6598: } else {
6599: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
6600: document.getElementById('showcolstatus').checked = true;
6601: document.getElementById('showcolstatus').disabled = '';
6602: document.getElementById('showcolstart').checked = true;
6603: document.getElementById('showcolend').checked = true;
6604: }
6605: }
6606: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
6607: document.getElementById('showcolextent').disabled = 'disabled';
6608: document.getElementById('showcolextent').checked = 'false';
6609: document.getElementById('showextent').style.display='none';
6610: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 6611: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
6612: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
6613: if (document.getElementById('showcolauthorusage')) {
6614: document.getElementById('showcolauthorusage').disabled = '';
6615: }
6616: if (document.getElementById('showcolauthorquota')) {
6617: document.getElementById('showcolauthorquota').disabled = '';
6618: }
6619: quotausageshow = 1;
6620: }
1.374 raeburn 6621: } else {
6622: document.getElementById('showextent').style.display='block';
6623: document.getElementById('showextent').style.textAlign='left';
6624: document.getElementById('showextent').style.textFace='normal';
6625: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
6626: document.getElementById('showcolextent').disabled = '';
6627: document.getElementById('showcolextent').checked = 'true';
6628: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
6629: } else {
6630: document.getElementById('showcolextent').disabled = '';
6631: document.getElementById('showcolextent').checked = 'true';
6632: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
6633: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
6634: } else {
6635: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
6636: }
6637: }
6638: }
1.382 raeburn 6639: if (quotausageshow == 0) {
6640: if (document.getElementById('showcolauthorusage')) {
6641: document.getElementById('showcolauthorusage').checked = false;
6642: document.getElementById('showcolauthorusage').disabled = 'disabled';
6643: }
6644: if (document.getElementById('showcolauthorquota')) {
6645: document.getElementById('showcolauthorquota').checked = false;
6646: document.getElementById('showcolauthorquota').disabled = 'disabled';
6647: }
6648: }
1.374 raeburn 6649: }
1.472 raeburn 6650: if (context == 'author') {
6651: if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'aa') {
6652: document.getElementById('showcolmanager').checked = false;
6653: document.getElementById('showcolmanager').disabled = 'disabled';
6654: } else if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value != 'Expired') {
6655: document.getElementById('showcolmanager').checked = true;
6656: document.getElementById('showcolmanager').disabled = '';
6657: }
6658: }
1.364 raeburn 6659: }
6660: return;
6661: }
6662:
1.202 raeburn 6663: END
6664: return $output;
6665:
6666: }
6667:
1.190 raeburn 6668: ###############################################################
6669: ###############################################################
6670: # Menu Phase One
6671: sub print_main_menu {
1.318 raeburn 6672: my ($permission,$context,$crstype) = @_;
6673: my $linkcontext = $context;
6674: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
6675: if (($context eq 'course') && ($crstype eq 'Community')) {
6676: $linkcontext = lc($crstype);
6677: $stuterm = 'Members';
6678: }
1.208 raeburn 6679: my %links = (
1.298 droeschl 6680: domain => {
6681: upload => 'Upload a File of Users',
6682: singleuser => 'Add/Modify a User',
6683: listusers => 'Manage Users',
6684: },
6685: author => {
6686: upload => 'Upload a File of Co-authors',
6687: singleuser => 'Add/Modify a Co-author',
6688: listusers => 'Manage Co-authors',
6689: },
6690: course => {
6691: upload => 'Upload a File of Course Users',
6692: singleuser => 'Add/Modify a Course User',
1.354 www 6693: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 6694: },
1.318 raeburn 6695: community => {
6696: upload => 'Upload a File of Community Users',
6697: singleuser => 'Add/Modify a Community User',
1.354 www 6698: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 6699: },
6700: );
6701: my %linktitles = (
6702: domain => {
6703: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
6704: listusers => 'Show and manage users in this domain.',
6705: },
6706: author => {
6707: singleuser => 'Add a user with a co- or assistant author role.',
6708: listusers => 'Show and manage co- or assistant authors.',
6709: },
6710: course => {
6711: singleuser => 'Add a user with a certain role to this course.',
6712: listusers => 'Show and manage users in this course.',
6713: },
6714: community => {
6715: singleuser => 'Add a user with a certain role to this community.',
6716: listusers => 'Show and manage users in this community.',
6717: },
1.298 droeschl 6718: );
1.465 raeburn 6719:
1.418 raeburn 6720: if ($linkcontext eq 'domain') {
6721: unless ($permission->{'cusr'}) {
1.430 raeburn 6722: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 6723: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
6724: }
6725: } elsif ($linkcontext eq 'course') {
6726: unless ($permission->{'cusr'}) {
6727: $links{'course'}{'singleuser'} = 'View a Course User';
6728: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
6729: $links{'course'}{'listusers'} = 'List Course Users';
6730: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
6731: }
6732: } elsif ($linkcontext eq 'community') {
6733: unless ($permission->{'cusr'}) {
6734: $links{'community'}{'singleuser'} = 'View a Community User';
6735: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
6736: $links{'community'}{'listusers'} = 'List Community Users';
6737: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
6738: }
6739: }
1.298 droeschl 6740: my @menu = ( {categorytitle => 'Single Users',
6741: items =>
6742: [
6743: {
1.318 raeburn 6744: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 6745: icon => 'edit-redo.png',
6746: #help => 'Course_Change_Privileges',
6747: url => '/adm/createuser?action=singleuser',
1.418 raeburn 6748: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 6749: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 6750: },
6751: ]},
6752:
6753: {categorytitle => 'Multiple Users',
6754: items =>
6755: [
6756: {
1.318 raeburn 6757: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 6758: icon => 'uplusr.png',
1.298 droeschl 6759: #help => 'Course_Create_Class_List',
6760: url => '/adm/createuser?action=upload',
6761: permission => $permission->{'cusr'},
6762: linktitle => 'Upload a CSV or a text file containing users.',
6763: },
6764: {
1.318 raeburn 6765: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 6766: icon => 'mngcu.png',
1.298 droeschl 6767: #help => 'Course_View_Class_List',
6768: url => '/adm/createuser?action=listusers',
6769: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 6770: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 6771: },
6772:
6773: ]},
6774:
6775: {categorytitle => 'Administration',
6776: items => [ ]},
6777: );
1.415 raeburn 6778:
1.265 mielkec 6779: if ($context eq 'domain'){
1.416 raeburn 6780: push(@{ $menu[0]->{items} }, # Single Users
6781: {
6782: linktext => 'User Access Log',
1.417 raeburn 6783: icon => 'document-properties.png',
1.425 raeburn 6784: #help => 'Domain_User_Access_Logs',
1.416 raeburn 6785: url => '/adm/createuser?action=accesslogs',
6786: permission => $permission->{'activity'},
6787: linktitle => 'View user access log.',
6788: }
6789: );
1.298 droeschl 6790:
6791: push(@{ $menu[2]->{items} }, #Category: Administration
6792: {
6793: linktext => 'Custom Roles',
6794: icon => 'emblem-photos.png',
6795: #help => 'Course_Editing_Custom_Roles',
6796: url => '/adm/createuser?action=custom',
6797: permission => $permission->{'custom'},
6798: linktitle => 'Configure a custom role.',
6799: },
1.362 raeburn 6800: {
6801: linktext => 'Authoring Space Requests',
6802: icon => 'selfenrl-queue.png',
6803: #help => 'Domain_Role_Approvals',
6804: url => '/adm/createuser?action=processauthorreq',
6805: permission => $permission->{'cusr'},
6806: linktitle => 'Approve or reject author role requests',
6807: },
1.363 raeburn 6808: {
1.391 raeburn 6809: linktext => 'LON-CAPA Account Requests',
6810: icon => 'list-add.png',
6811: #help => 'Domain_Username_Approvals',
6812: url => '/adm/createuser?action=processusernamereq',
6813: permission => $permission->{'cusr'},
6814: linktitle => 'Approve or reject LON-CAPA account requests',
6815: },
6816: {
1.363 raeburn 6817: linktext => 'Change Log',
6818: icon => 'document-properties.png',
6819: #help => 'Course_User_Logs',
6820: url => '/adm/createuser?action=changelogs',
1.418 raeburn 6821: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 6822: linktitle => 'View change log.',
6823: },
1.298 droeschl 6824: );
6825:
1.265 mielkec 6826: }elsif ($context eq 'course'){
1.298 droeschl 6827: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 6828:
6829: my %linktext = (
6830: 'Course' => {
6831: single => 'Add/Modify a Student',
6832: drop => 'Drop Students',
6833: groups => 'Course Groups',
6834: },
6835: 'Community' => {
6836: single => 'Add/Modify a Member',
6837: drop => 'Drop Members',
6838: groups => 'Community Groups',
6839: },
6840: );
1.411 raeburn 6841: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 6842:
6843: my %linktitle = (
6844: 'Course' => {
6845: single => 'Add a user with the role of student to this course',
6846: drop => 'Remove a student from this course.',
6847: groups => 'Manage course groups',
6848: },
6849: 'Community' => {
6850: single => 'Add a user with the role of member to this community',
6851: drop => 'Remove a member from this community.',
6852: groups => 'Manage community groups',
6853: },
6854: );
6855:
1.411 raeburn 6856: $linktitle{'Placement'} = $linktitle{'Course'};
6857:
1.298 droeschl 6858: push(@{ $menu[0]->{items} }, #Category: Single Users
6859: {
1.318 raeburn 6860: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 6861: #help => 'Course_Add_Student',
6862: icon => 'list-add.png',
6863: url => '/adm/createuser?action=singlestudent',
6864: permission => $permission->{'cusr'},
1.318 raeburn 6865: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 6866: },
6867: );
6868:
6869: push(@{ $menu[1]->{items} }, #Category: Multiple Users
6870: {
1.318 raeburn 6871: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 6872: icon => 'edit-undo.png',
6873: #help => 'Course_Drop_Student',
6874: url => '/adm/createuser?action=drop',
6875: permission => $permission->{'cusr'},
1.318 raeburn 6876: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 6877: },
6878: );
6879: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 6880: {
6881: linktext => 'Helpdesk Access',
6882: icon => 'helpdesk-access.png',
6883: #help => 'Course_Helpdesk_Access',
6884: url => '/adm/createuser?action=helpdesk',
1.464 raeburn 6885: permission => (($permission->{'owner'} || $permission->{'co-owner'}) &&
6886: ($permission->{'view'} || $permission->{'cusr'})),
1.428 raeburn 6887: linktitle => 'Helpdesk access options',
6888: },
6889: {
1.298 droeschl 6890: linktext => 'Custom Roles',
6891: icon => 'emblem-photos.png',
6892: #help => 'Course_Editing_Custom_Roles',
6893: url => '/adm/createuser?action=custom',
6894: permission => $permission->{'custom'},
6895: linktitle => 'Configure a custom role.',
6896: },
6897: {
1.318 raeburn 6898: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 6899: icon => 'grps.png',
1.298 droeschl 6900: #help => 'Course_Manage_Group',
6901: url => '/adm/coursegroups?refpage=cusr',
6902: permission => $permission->{'grp_manage'},
1.318 raeburn 6903: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 6904: },
6905: {
1.328 wenzelju 6906: linktext => 'Change Log',
1.298 droeschl 6907: icon => 'document-properties.png',
6908: #help => 'Course_User_Logs',
6909: url => '/adm/createuser?action=changelogs',
1.418 raeburn 6910: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 6911: linktitle => 'View change log.',
6912: },
6913: );
1.277 raeburn 6914: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 6915: push(@{ $menu[2]->{items} },
1.398 raeburn 6916: {
1.298 droeschl 6917: linktext => 'Enrollment Requests',
6918: icon => 'selfenrl-queue.png',
6919: #help => 'Course_Approve_Selfenroll',
6920: url => '/adm/createuser?action=selfenrollqueue',
1.469 raeburn 6921: permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.298 droeschl 6922: linktitle =>'Approve or reject enrollment requests.',
6923: },
6924: );
1.277 raeburn 6925: }
1.298 droeschl 6926:
1.265 mielkec 6927: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 6928: if ($crstype ne 'Community') {
6929: push(@{ $menu[2]->{items} },
6930: {
6931: linktext => 'Automated Enrollment',
6932: icon => 'roles.png',
6933: #help => 'Course_Automated_Enrollment',
6934: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 6935: && (($permission->{'cusr'}) ||
6936: ($permission->{'view'}))),
1.320 raeburn 6937: url => '/adm/populate',
6938: linktitle => 'Automated enrollment manager.',
6939: }
6940: );
6941: }
6942: push(@{ $menu[2]->{items} },
1.298 droeschl 6943: {
6944: linktext => 'User Self-Enrollment',
1.342 wenzelju 6945: icon => 'self_enroll.png',
1.298 droeschl 6946: #help => 'Course_Self_Enrollment',
6947: url => '/adm/createuser?action=selfenroll',
1.469 raeburn 6948: permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.317 bisitz 6949: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 6950: },
6951: );
6952: }
1.363 raeburn 6953: } elsif ($context eq 'author') {
1.370 raeburn 6954: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 6955: {
6956: linktext => 'Change Log',
6957: icon => 'document-properties.png',
6958: #help => 'Course_User_Logs',
6959: url => '/adm/createuser?action=changelogs',
6960: permission => $permission->{'cusr'},
6961: linktitle => 'View change log.',
6962: },
1.470 raeburn 6963: {
1.472 raeburn 6964: linktext => 'Co-author Managers',
1.473 raeburn 6965: icon => 'camanager.png',
1.470 raeburn 6966: #help => 'Coauthor_Management',
6967: url => '/adm/createuser?action=camanagers',
6968: permission => $permission->{'author'},
6969: linktitle => 'Assign/Revoke right to manage co-author roles',
6970: },
6971: {
1.473 raeburn 6972: linktext => 'Configure Co-author Listing',
6973: icon => 'coauthors.png',
1.470 raeburn 6974: #help => 'Coauthor_Settings',
6975: url => '/adm/createuser?action=calist&forceedit=1',
6976: permission => ($permission->{'cusr'}),
6977: linktitle => 'Set availability of coauthor-viewable user listing',
6978: },
1.370 raeburn 6979: );
1.363 raeburn 6980: }
1.465 raeburn 6981: push(@{ $menu[2]->{items} },
6982: {
6983: linktext => 'Role Requests (other domains)',
6984: icon => 'edit-find.png',
6985: #help => 'Role_Requests',
6986: url => '/adm/createuser?action=rolerequests',
6987: permission => $permission->{'cusr'},
6988: linktitle => 'Role requests for users in other domains',
6989: },
6990: );
6991: if (&show_role_requests($context,$env{'request.role.domain'})) {
6992: push(@{ $menu[2]->{items} },
6993: {
6994: linktext => 'Queued Role Assignments (this domain)',
6995: icon => 'edit-find.png',
6996: #help => 'Role_Approvals',
6997: url => '/adm/createuser?action=queuedroles',
6998: permission => $permission->{'cusr'},
6999: linktitle => "Role requests for this domain's users",
7000: },
7001: );
7002: }
1.363 raeburn 7003: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 7004: # { text => 'View Log-in History',
7005: # help => 'Course_User_Logins',
7006: # action => 'logins',
7007: # permission => $permission->{'cusr'},
7008: # });
1.190 raeburn 7009: }
7010:
1.189 albertel 7011: sub restore_prev_selections {
7012: my %saveable_parameters = ('srchby' => 'scalar',
7013: 'srchin' => 'scalar',
7014: 'srchtype' => 'scalar',
7015: );
7016: &Apache::loncommon::store_settings('user','user_picker',
7017: \%saveable_parameters);
7018: &Apache::loncommon::restore_settings('user','user_picker',
7019: \%saveable_parameters);
7020: }
7021:
1.237 raeburn 7022: sub print_selfenroll_menu {
1.418 raeburn 7023: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 7024: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 7025: my $formname = 'selfenroll';
1.237 raeburn 7026: my $nolink = 1;
1.398 raeburn 7027: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 7028: my $groupslist = &Apache::lonuserutils::get_groupslist();
7029: my $setsec_js =
7030: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 7031: my %alerts = &Apache::lonlocal::texthash(
7032: acto => 'Activation of self-enrollment was selected for the following domain(s)',
7033: butn => 'but no user types have been checked.',
7034: wilf => "Please uncheck 'activate' or check at least one type.",
7035: );
1.418 raeburn 7036: my $disabled;
7037: if ($readonly) {
7038: $disabled = ' disabled="disabled"';
7039: }
1.405 damieng 7040: &js_escape(\%alerts);
1.249 raeburn 7041: my $selfenroll_js = <<"ENDSCRIPT";
7042: function update_types(caller,num) {
7043: var delidx = getIndexByName('selfenroll_delete');
7044: var actidx = getIndexByName('selfenroll_activate');
7045: if (caller == 'selfenroll_all') {
7046: var selall;
7047: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
7048: if (document.$formname.selfenroll_all[i].checked) {
7049: selall = document.$formname.selfenroll_all[i].value;
7050: }
7051: }
7052: if (selall == 1) {
7053: if (delidx != -1) {
7054: if (document.$formname.selfenroll_delete.length) {
7055: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
7056: document.$formname.selfenroll_delete[j].checked = true;
7057: }
7058: } else {
7059: document.$formname.elements[delidx].checked = true;
7060: }
7061: }
7062: if (actidx != -1) {
7063: if (document.$formname.selfenroll_activate.length) {
7064: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
7065: document.$formname.selfenroll_activate[j].checked = false;
7066: }
7067: } else {
7068: document.$formname.elements[actidx].checked = false;
7069: }
7070: }
7071: document.$formname.selfenroll_newdom.selectedIndex = 0;
7072: }
7073: }
7074: if (caller == 'selfenroll_activate') {
7075: if (document.$formname.selfenroll_activate.length) {
7076: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
7077: if (document.$formname.selfenroll_activate[j].value == num) {
7078: if (document.$formname.selfenroll_activate[j].checked) {
7079: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
7080: if (document.$formname.selfenroll_all[i].value == '1') {
7081: document.$formname.selfenroll_all[i].checked = false;
7082: }
7083: if (document.$formname.selfenroll_all[i].value == '0') {
7084: document.$formname.selfenroll_all[i].checked = true;
7085: }
7086: }
7087: }
7088: }
7089: }
7090: } else {
7091: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
7092: if (document.$formname.selfenroll_all[i].value == '1') {
7093: document.$formname.selfenroll_all[i].checked = false;
7094: }
7095: if (document.$formname.selfenroll_all[i].value == '0') {
7096: document.$formname.selfenroll_all[i].checked = true;
7097: }
7098: }
7099: }
7100: }
7101: if (caller == 'selfenroll_delete') {
7102: if (document.$formname.selfenroll_delete.length) {
7103: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
7104: if (document.$formname.selfenroll_delete[j].value == num) {
7105: if (document.$formname.selfenroll_delete[j].checked) {
7106: var delindex = getIndexByName('selfenroll_types_'+num);
7107: if (delindex != -1) {
7108: if (document.$formname.elements[delindex].length) {
7109: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
7110: document.$formname.elements[delindex][k].checked = false;
7111: }
7112: } else {
7113: document.$formname.elements[delindex].checked = false;
7114: }
7115: }
7116: }
7117: }
7118: }
7119: } else {
7120: if (document.$formname.selfenroll_delete.checked) {
7121: var delindex = getIndexByName('selfenroll_types_'+num);
7122: if (delindex != -1) {
7123: if (document.$formname.elements[delindex].length) {
7124: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
7125: document.$formname.elements[delindex][k].checked = false;
7126: }
7127: } else {
7128: document.$formname.elements[delindex].checked = false;
7129: }
7130: }
7131: }
7132: }
7133: }
7134: return;
7135: }
7136:
7137: function validate_types(form) {
7138: var needaction = new Array();
7139: var countfail = 0;
7140: var actidx = getIndexByName('selfenroll_activate');
7141: if (actidx != -1) {
7142: if (document.$formname.selfenroll_activate.length) {
7143: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
7144: var num = document.$formname.selfenroll_activate[j].value;
7145: if (document.$formname.selfenroll_activate[j].checked) {
7146: countfail = check_types(num,countfail,needaction)
7147: }
7148: }
7149: } else {
7150: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 7151: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 7152: countfail = check_types(num,countfail,needaction)
7153: }
7154: }
7155: }
7156: if (countfail > 0) {
7157: var msg = "$alerts{'acto'}\\n";
7158: var loopend = needaction.length -1;
7159: if (loopend > 0) {
7160: for (var m=0; m<loopend; m++) {
7161: msg += needaction[m]+", ";
7162: }
7163: }
7164: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
7165: alert(msg);
7166: return;
7167: }
7168: setSections(form);
7169: }
7170:
7171: function check_types(num,countfail,needaction) {
1.441 raeburn 7172: var boxname = 'selfenroll_types_'+num;
7173: var typeidx = getIndexByName(boxname);
1.249 raeburn 7174: var count = 0;
7175: if (typeidx != -1) {
1.441 raeburn 7176: if (document.$formname.elements[boxname].length) {
7177: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
7178: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 7179: count ++;
7180: }
7181: }
7182: } else {
7183: if (document.$formname.elements[typeidx].checked) {
7184: count ++;
7185: }
7186: }
7187: if (count == 0) {
7188: var domidx = getIndexByName('selfenroll_dom_'+num);
7189: if (domidx != -1) {
7190: var domname = document.$formname.elements[domidx].value;
7191: needaction[countfail] = domname;
7192: countfail ++;
7193: }
7194: }
7195: }
7196: return countfail;
7197: }
7198:
1.398 raeburn 7199: function toggleNotify() {
7200: var selfenrollApproval = 0;
7201: if (document.$formname.selfenroll_approval.length) {
7202: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
7203: if (document.$formname.selfenroll_approval[i].checked) {
7204: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
7205: break;
7206: }
7207: }
7208: }
7209: if (document.getElementById('notified')) {
7210: if (selfenrollApproval == 0) {
7211: document.getElementById('notified').style.display='none';
7212: } else {
7213: document.getElementById('notified').style.display='block';
7214: }
7215: }
7216: return;
7217: }
7218:
1.249 raeburn 7219: function getIndexByName(item) {
7220: for (var i=0;i<document.$formname.elements.length;i++) {
7221: if (document.$formname.elements[i].name == item) {
7222: return i;
7223: }
7224: }
7225: return -1;
7226: }
7227: ENDSCRIPT
1.256 raeburn 7228:
1.237 raeburn 7229: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 7230: '// <![CDATA['."\n".
1.249 raeburn 7231: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 7232: '// ]]>'."\n".
1.237 raeburn 7233: '</script>'."\n".
1.256 raeburn 7234: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.469 raeburn 7235: my $visactions = &cat_visibility($cdom);
1.400 raeburn 7236: my ($cathash,%cattype);
7237: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
7238: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7239: $cathash = $domconfig{'coursecategories'}{'cats'};
7240: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
7241: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 7242: if ($cattype{'auth'} eq '') {
7243: $cattype{'auth'} = 'std';
7244: }
7245: if ($cattype{'unauth'} eq '') {
7246: $cattype{'unauth'} = 'std';
7247: }
1.400 raeburn 7248: } else {
7249: $cathash = {};
7250: $cattype{'auth'} = 'std';
7251: $cattype{'unauth'} = 'std';
7252: }
7253: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
7254: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7255: '<br />'.
7256: '<br />'.$visactions->{'take'}.'<ul>'.
7257: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
7258: '</ul>');
7259: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
7260: if ($currsettings->{'uniquecode'}) {
7261: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
7262: } else {
7263: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7264: '<br />'.
7265: '<br />'.$visactions->{'take'}.'<ul>'.
7266: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
7267: '</ul><br />');
7268: }
7269: } else {
7270: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
7271: if (ref($visactions) eq 'HASH') {
7272: if ($visible) {
7273: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
7274: } else {
7275: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
7276: .$visactions->{'yous'}.
7277: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
7278: if (ref($vismsgs) eq 'ARRAY') {
7279: $output .= '<br />'.$visactions->{'make'}.'<ul>';
7280: foreach my $item (@{$vismsgs}) {
7281: $output .= '<li>'.$visactions->{$item}.'</li>';
7282: }
7283: $output .= '</ul>';
1.256 raeburn 7284: }
1.400 raeburn 7285: $output .= '</p>';
1.256 raeburn 7286: }
7287: }
7288: }
1.398 raeburn 7289: my $actionhref = '/adm/createuser';
7290: if ($context eq 'domain') {
7291: $actionhref = '/adm/modifycourse';
7292: }
1.400 raeburn 7293:
7294: my %noedit;
7295: unless ($context eq 'domain') {
7296: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
7297: }
1.398 raeburn 7298: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 7299: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 7300: if (ref($row) eq 'ARRAY') {
7301: foreach my $item (@{$row}) {
7302: my $title = $item;
7303: if (ref($lt) eq 'HASH') {
7304: $title = $lt->{$item};
7305: }
1.297 bisitz 7306: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 7307: if ($item eq 'types') {
1.398 raeburn 7308: my $curr_types;
7309: if (ref($currsettings) eq 'HASH') {
7310: $curr_types = $currsettings->{'selfenroll_types'};
7311: }
1.400 raeburn 7312: if ($noedit{$item}) {
7313: if ($curr_types eq '*') {
7314: $output .= &mt('Any user in any domain');
7315: } else {
7316: my @entries = split(/;/,$curr_types);
7317: if (@entries > 0) {
7318: $output .= '<ul>';
7319: foreach my $entry (@entries) {
7320: my ($currdom,$typestr) = split(/:/,$entry);
7321: next if ($typestr eq '');
7322: my $domdesc = &Apache::lonnet::domain($currdom);
7323: my @currinsttypes = split(',',$typestr);
7324: my ($othertitle,$usertypes,$types) =
7325: &Apache::loncommon::sorted_inst_types($currdom);
7326: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7327: $usertypes->{'any'} = &mt('any user');
7328: if (keys(%{$usertypes}) > 0) {
7329: $usertypes->{'other'} = &mt('other users');
7330: }
7331: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
7332: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
7333: }
7334: }
7335: $output .= '</ul>';
7336: } else {
7337: $output .= &mt('None');
7338: }
7339: }
7340: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7341: next;
7342: }
1.241 raeburn 7343: my $showdomdesc = 1;
7344: my $includeempty = 1;
7345: my $num = 0;
7346: $output .= &Apache::loncommon::start_data_table().
7347: &Apache::loncommon::start_data_table_row()
7348: .'<td colspan="2"><span class="LC_nobreak"><label>'
7349: .&mt('Any user in any domain:')
7350: .' <input type="radio" name="selfenroll_all" value="1" ';
7351: if ($curr_types eq '*') {
7352: $output .= ' checked="checked" ';
7353: }
1.249 raeburn 7354: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 7355: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 7356: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 7357: if ($curr_types ne '*') {
7358: $output .= ' checked="checked" ';
7359: }
1.249 raeburn 7360: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 7361: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 7362: &Apache::loncommon::end_data_table_row().
7363: &Apache::loncommon::end_data_table().
7364: &mt('Or').'<br />'.
7365: &Apache::loncommon::start_data_table();
1.241 raeburn 7366: my %currdoms;
1.249 raeburn 7367: if ($curr_types eq '') {
1.241 raeburn 7368: $output .= &new_selfenroll_dom_row($cdom,'0');
7369: } elsif ($curr_types ne '*') {
7370: my @entries = split(/;/,$curr_types);
7371: if (@entries > 0) {
7372: foreach my $entry (@entries) {
7373: my ($currdom,$typestr) = split(/:/,$entry);
7374: $currdoms{$currdom} = 1;
7375: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 7376: my @currinsttypes = split(',',$typestr);
1.241 raeburn 7377: $output .= &Apache::loncommon::start_data_table_row()
7378: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
7379: .' '.$domdesc.' ('.$currdom.')'
7380: .'</b><input type="hidden" name="selfenroll_dom_'.$num
7381: .'" value="'.$currdom.'" /></span><br />'
7382: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 7383: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 7384: .&mt('Delete').'</label></span></td>';
1.249 raeburn 7385: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 7386: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 7387: .&Apache::loncommon::end_data_table_row();
7388: $num ++;
7389: }
7390: }
7391: }
1.249 raeburn 7392: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 7393: if ($curr_types eq '*') {
1.249 raeburn 7394: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 7395: } elsif ($curr_types eq '') {
1.249 raeburn 7396: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 7397: }
1.446 raeburn 7398: my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$cdom);
1.241 raeburn 7399: $output .= &Apache::loncommon::start_data_table_row()
7400: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
7401: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.446 raeburn 7402: $includeempty,$showdomdesc,'',$trusted,$untrusted,$readonly)
1.241 raeburn 7403: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
7404: .'</td>'.&Apache::loncommon::end_data_table_row()
7405: .&Apache::loncommon::end_data_table();
1.237 raeburn 7406: } elsif ($item eq 'registered') {
7407: my ($regon,$regoff);
1.398 raeburn 7408: my $registered;
7409: if (ref($currsettings) eq 'HASH') {
7410: $registered = $currsettings->{'selfenroll_registered'};
7411: }
1.400 raeburn 7412: if ($noedit{$item}) {
7413: if ($registered) {
7414: $output .= &mt('Must be registered in course');
7415: } else {
7416: $output .= &mt('No requirement');
7417: }
7418: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7419: next;
7420: }
1.398 raeburn 7421: if ($registered) {
1.237 raeburn 7422: $regon = ' checked="checked" ';
1.419 raeburn 7423: $regoff = '';
1.237 raeburn 7424: } else {
1.419 raeburn 7425: $regon = '';
1.237 raeburn 7426: $regoff = ' checked="checked" ';
7427: }
7428: $output .= '<label>'.
1.419 raeburn 7429: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 7430: &mt('Yes').'</label> <label>'.
1.419 raeburn 7431: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 7432: &mt('No').'</label>';
1.237 raeburn 7433: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 7434: my ($starttime,$endtime);
7435: if (ref($currsettings) eq 'HASH') {
7436: $starttime = $currsettings->{'selfenroll_start_date'};
7437: $endtime = $currsettings->{'selfenroll_end_date'};
7438: if ($starttime eq '') {
7439: $starttime = $currsettings->{'default_enrollment_start_date'};
7440: }
7441: if ($endtime eq '') {
7442: $endtime = $currsettings->{'default_enrollment_end_date'};
7443: }
1.237 raeburn 7444: }
1.400 raeburn 7445: if ($noedit{$item}) {
7446: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
7447: &Apache::lonlocal::locallocaltime($endtime));
7448: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7449: next;
7450: }
1.237 raeburn 7451: my $startform =
7452: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 7453: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7454: my $endform =
7455: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 7456: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7457: $output .= &selfenroll_date_forms($startform,$endform);
7458: } elsif ($item eq 'access_dates') {
1.398 raeburn 7459: my ($starttime,$endtime);
7460: if (ref($currsettings) eq 'HASH') {
7461: $starttime = $currsettings->{'selfenroll_start_access'};
7462: $endtime = $currsettings->{'selfenroll_end_access'};
7463: if ($starttime eq '') {
7464: $starttime = $currsettings->{'default_enrollment_start_date'};
7465: }
7466: if ($endtime eq '') {
7467: $endtime = $currsettings->{'default_enrollment_end_date'};
7468: }
1.237 raeburn 7469: }
1.400 raeburn 7470: if ($noedit{$item}) {
7471: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
7472: &Apache::lonlocal::locallocaltime($endtime));
7473: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7474: next;
7475: }
1.237 raeburn 7476: my $startform =
7477: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 7478: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7479: my $endform =
7480: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 7481: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7482: $output .= &selfenroll_date_forms($startform,$endform);
7483: } elsif ($item eq 'section') {
1.398 raeburn 7484: my $currsec;
7485: if (ref($currsettings) eq 'HASH') {
7486: $currsec = $currsettings->{'selfenroll_section'};
7487: }
1.237 raeburn 7488: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
7489: my $newsecval;
7490: if ($currsec ne 'none' && $currsec ne '') {
7491: if (!defined($sections_count{$currsec})) {
7492: $newsecval = $currsec;
7493: }
7494: }
1.400 raeburn 7495: if ($noedit{$item}) {
7496: if ($currsec ne '') {
7497: $output .= $currsec;
7498: } else {
7499: $output .= &mt('No specific section');
7500: }
7501: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7502: next;
7503: }
1.237 raeburn 7504: my $sections_select =
1.418 raeburn 7505: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 7506: $output .= '<table class="LC_createuser">'."\n".
7507: '<tr class="LC_section_row">'."\n".
7508: '<td align="center">'.&mt('Existing sections')."\n".
7509: '<br />'.$sections_select.'</td><td align="center">'.
7510: &mt('New section').'<br />'."\n".
1.418 raeburn 7511: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 7512: '<input type="hidden" name="sections" value="" />'."\n".
7513: '</td></tr></table>'."\n";
1.276 raeburn 7514: } elsif ($item eq 'approval') {
1.398 raeburn 7515: my ($currnotified,$currapproval,%appchecked);
7516: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 7517: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 7518: $currnotified = $currsettings->{'selfenroll_notifylist'};
7519: $currapproval = $currsettings->{'selfenroll_approval'};
7520: }
7521: if ($currapproval !~ /^[012]$/) {
7522: $currapproval = 0;
7523: }
1.400 raeburn 7524: if ($noedit{$item}) {
7525: $output .= $selfdescs{'approval'}{$currapproval}.
7526: '<br />'.&mt('(Set by Domain Coordinator)');
7527: next;
7528: }
1.398 raeburn 7529: $appchecked{$currapproval} = ' checked="checked"';
7530: for my $i (0..2) {
7531: $output .= '<label>'.
7532: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 7533: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
7534: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 7535: }
7536: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
7537: my (@ccs,%notified);
1.322 raeburn 7538: my $ccrole = 'cc';
7539: if ($crstype eq 'Community') {
7540: $ccrole = 'co';
7541: }
7542: if ($advhash{$ccrole}) {
7543: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 7544: }
7545: if ($currnotified) {
7546: foreach my $current (split(/,/,$currnotified)) {
7547: $notified{$current} = 1;
7548: if (!grep(/^\Q$current\E$/,@ccs)) {
7549: push(@ccs,$current);
7550: }
7551: }
7552: }
7553: if (@ccs) {
1.398 raeburn 7554: my $style;
7555: unless ($currapproval) {
7556: $style = ' style="display: none;"';
7557: }
7558: $output .= '<br /><div id="notified"'.$style.'>'.
7559: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
7560: &Apache::loncommon::start_data_table().
1.276 raeburn 7561: &Apache::loncommon::start_data_table_row();
7562: my $count = 0;
7563: my $numcols = 4;
7564: foreach my $cc (sort(@ccs)) {
7565: my $notifyon;
7566: my ($ccuname,$ccudom) = split(/:/,$cc);
7567: if ($notified{$cc}) {
7568: $notifyon = ' checked="checked" ';
7569: }
7570: if ($count && !$count%$numcols) {
7571: $output .= &Apache::loncommon::end_data_table_row().
7572: &Apache::loncommon::start_data_table_row()
7573: }
7574: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 7575: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 7576: &Apache::loncommon::plainname($ccuname,$ccudom).
7577: '</label></span></td>';
1.343 raeburn 7578: $count ++;
1.276 raeburn 7579: }
7580: my $rem = $count%$numcols;
7581: if ($rem) {
7582: my $emptycols = $numcols - $rem;
7583: for (my $i=0; $i<$emptycols; $i++) {
7584: $output .= '<td> </td>';
7585: }
7586: }
7587: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 7588: &Apache::loncommon::end_data_table().
7589: '</div>';
1.276 raeburn 7590: }
7591: } elsif ($item eq 'limit') {
1.398 raeburn 7592: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
7593: if (ref($currsettings) eq 'HASH') {
7594: $currlim = $currsettings->{'selfenroll_limit'};
7595: $currcap = $currsettings->{'selfenroll_cap'};
7596: }
1.400 raeburn 7597: if ($noedit{$item}) {
7598: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
7599: if ($currlim eq 'allstudents') {
7600: $output .= &mt('Limit by total students');
7601: } elsif ($currlim eq 'selfenrolled') {
7602: $output .= &mt('Limit by total self-enrolled students');
7603: }
7604: $output .= ' '.&mt('Maximum: [_1]',$currcap).
7605: '<br />'.&mt('(Set by Domain Coordinator)');
7606: } else {
7607: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
7608: }
7609: next;
7610: }
1.276 raeburn 7611: if ($currlim eq 'allstudents') {
7612: $crslimit = ' checked="checked" ';
7613: $selflimit = ' ';
7614: $nolimit = ' ';
7615: } elsif ($currlim eq 'selfenrolled') {
7616: $crslimit = ' ';
7617: $selflimit = ' checked="checked" ';
7618: $nolimit = ' ';
7619: } else {
7620: $crslimit = ' ';
7621: $selflimit = ' ';
1.398 raeburn 7622: $nolimit = ' checked="checked" ';
1.276 raeburn 7623: }
7624: $output .= '<table><tr><td><label>'.
1.418 raeburn 7625: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 7626: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 7627: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 7628: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 7629: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 7630: &mt('Limit by total self-enrolled students').
7631: '</td></tr><tr>'.
7632: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
7633: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 7634: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 7635: }
7636: $output .= &Apache::lonhtmlcommon::row_closure(1);
7637: }
7638: }
1.418 raeburn 7639: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
7640: unless ($readonly) {
7641: $output .= '<input type="button" name="selfenrollconf" value="'
7642: .&mt('Save').'" onclick="validate_types(this.form);" />';
7643: }
7644: $output .= '<input type="hidden" name="action" value="selfenroll" />'
7645: .'<input type="hidden" name="state" value="done" />'."\n"
7646: .$additional.'</form>';
1.237 raeburn 7647: $r->print($output);
7648: return;
7649: }
7650:
1.400 raeburn 7651: sub get_noedit_fields {
7652: my ($cdom,$cnum,$crstype,$row) = @_;
7653: my %noedit;
7654: if (ref($row) eq 'ARRAY') {
7655: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
7656: 'internal.selfenrollmgrdc',
7657: 'internal.selfenrollmgrcc'],$cdom,$cnum);
7658: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
7659: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
7660: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
7661: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
7662: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
7663: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
7664:
7665: foreach my $item (@{$row}) {
7666: next if ($specific_managebycc{$item});
7667: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
7668: $noedit{$item} = 1;
7669: }
7670: }
7671: }
7672: return %noedit;
1.470 raeburn 7673: }
1.400 raeburn 7674:
7675: sub visible_in_stdcat {
7676: my ($cdom,$cnum,$domconf) = @_;
7677: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
7678: unless (ref($domconf) eq 'HASH') {
7679: return ($visible,$cansetvis,\@vismsgs);
7680: }
7681: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7682: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 7683: $settable{'togglecats'} = 1;
7684: }
1.400 raeburn 7685: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 7686: $settable{'categorize'} = 1;
7687: }
1.400 raeburn 7688: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7689: }
1.260 raeburn 7690: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 7691: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
7692: } elsif ($settable{'togglecats'}) {
7693: $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 7694: } elsif ($settable{'categorize'}) {
1.256 raeburn 7695: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
7696: } else {
7697: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
7698: }
7699:
7700: my %currsettings =
7701: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
7702: $cdom,$cnum);
1.400 raeburn 7703: $visible = 0;
1.256 raeburn 7704: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 7705: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7706: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7707: if (ref($cathash) eq 'HASH') {
7708: if ($cathash->{'instcode::0'} eq '') {
7709: push(@vismsgs,'dc_addinst');
7710: } else {
7711: $visible = 1;
7712: }
7713: } else {
7714: $visible = 1;
7715: }
7716: } else {
7717: $visible = 1;
7718: }
7719: } else {
7720: if (ref($cathash) eq 'HASH') {
7721: if ($cathash->{'instcode::0'} ne '') {
7722: push(@vismsgs,'dc_instcode');
7723: }
7724: } else {
7725: push(@vismsgs,'dc_instcode');
7726: }
7727: }
7728: if ($currsettings{'categories'} ne '') {
7729: my $cathash;
1.400 raeburn 7730: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7731: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7732: if (ref($cathash) eq 'HASH') {
7733: if (keys(%{$cathash}) == 0) {
7734: push(@vismsgs,'dc_catalog');
7735: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
7736: push(@vismsgs,'dc_categories');
7737: } else {
7738: my @currcategories = split('&',$currsettings{'categories'});
7739: my $matched = 0;
7740: foreach my $cat (@currcategories) {
7741: if ($cathash->{$cat} ne '') {
7742: $visible = 1;
7743: $matched = 1;
7744: last;
7745: }
7746: }
7747: if (!$matched) {
1.260 raeburn 7748: if ($settable{'categorize'}) {
1.256 raeburn 7749: push(@vismsgs,'chgcat');
7750: } else {
7751: push(@vismsgs,'dc_chgcat');
7752: }
7753: }
7754: }
7755: }
7756: }
7757: } else {
7758: if (ref($cathash) eq 'HASH') {
7759: if ((keys(%{$cathash}) > 1) ||
7760: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 7761: if ($settable{'categorize'}) {
1.256 raeburn 7762: push(@vismsgs,'addcat');
7763: } else {
7764: push(@vismsgs,'dc_addcat');
7765: }
7766: }
7767: }
7768: }
7769: if ($currsettings{'hidefromcat'} eq 'yes') {
7770: $visible = 0;
7771: if ($settable{'togglecats'}) {
7772: unshift(@vismsgs,'unhide');
7773: } else {
7774: unshift(@vismsgs,'dc_unhide')
7775: }
7776: }
1.400 raeburn 7777: return ($visible,$cansetvis,\@vismsgs);
7778: }
7779:
7780: sub cat_visibility {
1.469 raeburn 7781: my ($cdom) = @_;
1.400 raeburn 7782: my %visactions = &Apache::lonlocal::texthash(
7783: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
7784: 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.',
7785: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
7786: none => 'Display of a course catalog is disabled for this domain.',
7787: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
7788: 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.',
7789: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
7790: take => 'Take the following action to ensure the course appears in the Catalog:',
7791: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
7792: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
7793: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
1.469 raeburn 7794: dc_addinst => 'Ask a domain coordinator to enable catalog display of "Official courses (with institutional codes)".',
1.400 raeburn 7795: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
7796: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
7797: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
7798: 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',
7799: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
7800: );
1.469 raeburn 7801: if ($env{'request.role'} eq "dc./$cdom/") {
7802: $visactions{'dc_chgconf'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the Catalog type for this domain.','»');
7803: $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.','»');
7804: $visactions{'dc_unhide'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the "Exclude from course catalog" setting.','»');
7805: $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)".','»');
7806: $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).','»');
7807: $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.','»');
7808: $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.','»');
7809: $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.','»');
7810: $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.','»');
7811: }
1.400 raeburn 7812: $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>"');
7813: $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>"');
7814: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
7815: return \%visactions;
1.256 raeburn 7816: }
7817:
1.241 raeburn 7818: sub new_selfenroll_dom_row {
7819: my ($newdom,$num) = @_;
7820: my $domdesc = &Apache::lonnet::domain($newdom);
7821: my $output;
7822: if ($domdesc ne '') {
7823: $output .= &Apache::loncommon::start_data_table_row()
7824: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
7825: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 7826: .'" value="'.$newdom.'" /></span><br />'
7827: .'<span class="LC_nobreak"><label><input type="checkbox" '
7828: .'name="selfenroll_activate" value="'.$num.'" '
7829: .'onchange="javascript:update_types('
7830: ."'selfenroll_activate','$num'".');" />'
7831: .&mt('Activate').'</label></span></td>';
1.241 raeburn 7832: my @currinsttypes;
7833: $output .= '<td>'.&mt('User types:').'<br />'
7834: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
7835: .&Apache::loncommon::end_data_table_row();
7836: }
7837: return $output;
7838: }
7839:
7840: sub selfenroll_inst_types {
1.418 raeburn 7841: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 7842: my $output;
7843: my $numinrow = 4;
7844: my $count = 0;
7845: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 7846: my $othervalue = 'any';
1.418 raeburn 7847: my $disabled;
7848: if ($readonly) {
7849: $disabled = ' disabled="disabled"';
7850: }
1.241 raeburn 7851: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 7852: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 7853: $othervalue = 'other';
7854: }
1.241 raeburn 7855: $output .= '<table><tr>';
7856: foreach my $type (@{$types}) {
7857: if (($count > 0) && ($count%$numinrow == 0)) {
7858: $output .= '</tr><tr>';
7859: }
7860: if (defined($usertypes->{$type})) {
1.257 raeburn 7861: my $esc_type = &escape($type);
1.241 raeburn 7862: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 7863: $esc_type.'" ';
1.241 raeburn 7864: if (ref($currinsttypes) eq 'ARRAY') {
7865: if (@{$currinsttypes} > 0) {
1.249 raeburn 7866: if (grep(/^any$/,@{$currinsttypes})) {
7867: $output .= 'checked="checked"';
1.257 raeburn 7868: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 7869: $output .= 'checked="checked"';
7870: }
1.249 raeburn 7871: } else {
7872: $output .= 'checked="checked"';
1.241 raeburn 7873: }
7874: }
1.418 raeburn 7875: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 7876: }
7877: $count ++;
7878: }
7879: if (($count > 0) && ($count%$numinrow == 0)) {
7880: $output .= '</tr><tr>';
7881: }
1.249 raeburn 7882: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 7883: if (ref($currinsttypes) eq 'ARRAY') {
7884: if (@{$currinsttypes} > 0) {
1.249 raeburn 7885: if (grep(/^any$/,@{$currinsttypes})) {
7886: $output .= ' checked="checked"';
7887: } elsif ($othervalue eq 'other') {
7888: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
7889: $output .= ' checked="checked"';
7890: }
1.241 raeburn 7891: }
1.249 raeburn 7892: } else {
7893: $output .= ' checked="checked"';
1.241 raeburn 7894: }
1.249 raeburn 7895: } else {
7896: $output .= ' checked="checked"';
1.241 raeburn 7897: }
1.418 raeburn 7898: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 7899: }
7900: return $output;
7901: }
7902:
1.237 raeburn 7903: sub selfenroll_date_forms {
7904: my ($startform,$endform) = @_;
7905: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 7906: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 7907: 'LC_oddrow_value')."\n".
7908: $startform."\n".
7909: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 7910: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 7911: 'LC_oddrow_value')."\n".
7912: $endform."\n".
7913: &Apache::lonhtmlcommon::row_closure(1).
7914: &Apache::lonhtmlcommon::end_pick_box();
7915: return $output;
7916: }
7917:
1.239 raeburn 7918: sub print_userchangelogs_display {
1.415 raeburn 7919: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 7920: my $formname = 'rolelog';
1.418 raeburn 7921: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 7922: if ($context eq 'domain') {
7923: $domain = $env{'request.role.domain'};
7924: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
7925: } else {
7926: if ($context eq 'course') {
7927: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
7928: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
7929: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 7930: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 7931: my %saveable_parameters = ('show' => 'scalar',);
7932: &Apache::loncommon::store_course_settings('roles_log',
7933: \%saveable_parameters);
7934: &Apache::loncommon::restore_course_settings('roles_log',
7935: \%saveable_parameters);
7936: } elsif ($context eq 'author') {
1.470 raeburn 7937: $domain = $env{'user.domain'};
1.363 raeburn 7938: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
7939: $username = $env{'user.name'};
1.470 raeburn 7940: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
7941: ($domain,$username) = ($1,$2);
1.363 raeburn 7942: } else {
7943: undef($domain);
7944: }
7945: }
7946: if ($domain ne '' && $username ne '') {
7947: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
7948: }
7949: }
1.239 raeburn 7950: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
7951:
1.415 raeburn 7952: my $helpitem;
7953: if ($context eq 'course') {
7954: $helpitem = 'Course_User_Logs';
1.439 raeburn 7955: } elsif ($context eq 'domain') {
7956: $helpitem = 'Domain_Role_Logs';
7957: } elsif ($context eq 'author') {
7958: $helpitem = 'Author_User_Logs';
1.415 raeburn 7959: }
7960: push (@{$brcrum},
7961: {href => '/adm/createuser?action=changelogs',
7962: text => 'User Management Logs',
7963: help => $helpitem});
7964: my $bread_crumbs_component = 'User Changes';
7965: my $args = { bread_crumbs => $brcrum,
7966: bread_crumbs_component => $bread_crumbs_component};
7967:
7968: # Create navigation javascript
7969: my $jsnav = &userlogdisplay_js($formname);
7970:
7971: my $jscript = (<<ENDSCRIPT);
7972: <script type="text/javascript">
7973: // <![CDATA[
7974: $jsnav
7975: // ]]>
7976: </script>
7977: ENDSCRIPT
7978:
7979: # print page header
7980: $r->print(&header($jscript,$args));
7981:
1.239 raeburn 7982: # set defaults
7983: my $now = time();
7984: my $defstart = $now - (7*24*3600); #7 days ago
7985: my %defaults = (
7986: page => '1',
7987: show => '10',
7988: role => 'any',
7989: chgcontext => 'any',
7990: rolelog_start_date => $defstart,
7991: rolelog_end_date => $now,
1.468 raeburn 7992: approvals => 'any',
1.239 raeburn 7993: );
7994: my $more_records = 0;
7995:
7996: # set current
7997: my %curr;
1.468 raeburn 7998: foreach my $item ('show','page','role','chgcontext','approvals') {
1.239 raeburn 7999: $curr{$item} = $env{'form.'.$item};
8000: }
8001: my ($startdate,$enddate) =
8002: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
8003: $curr{'rolelog_start_date'} = $startdate;
8004: $curr{'rolelog_end_date'} = $enddate;
8005: foreach my $key (keys(%defaults)) {
8006: if ($curr{$key} eq '') {
8007: $curr{$key} = $defaults{$key};
8008: }
8009: }
1.248 raeburn 8010: my (%whodunit,%changed,$version);
8011: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 8012: my ($minshown,$maxshown);
1.255 raeburn 8013: $minshown = 1;
1.239 raeburn 8014: my $count = 0;
1.415 raeburn 8015: if ($curr{'show'} =~ /\D/) {
8016: $curr{'page'} = 1;
8017: } else {
1.239 raeburn 8018: $maxshown = $curr{'page'} * $curr{'show'};
8019: if ($curr{'page'} > 1) {
8020: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
8021: }
8022: }
1.301 bisitz 8023:
1.327 raeburn 8024: # Form Header
8025: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 8026: &role_display_filter($context,$formname,$domain,$username,\%curr,
8027: $version,$crstype));
1.327 raeburn 8028:
8029: my $showntableheader = 0;
8030:
8031: # Table Header
8032: my $tableheader =
8033: &Apache::loncommon::start_data_table_header_row()
8034: .'<th> </th>'
8035: .'<th>'.&mt('When').'</th>'
8036: .'<th>'.&mt('Who made the change').'</th>'
8037: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 8038: .'<th>'.&mt('Role').'</th>';
8039:
8040: if ($context eq 'course') {
8041: $tableheader .= '<th>'.&mt('Section').'</th>';
8042: }
8043: $tableheader .=
8044: '<th>'.&mt('Context').'</th>'
1.327 raeburn 8045: .'<th>'.&mt('Start').'</th>'
8046: .'<th>'.&mt('End').'</th>'
8047: .&Apache::loncommon::end_data_table_header_row();
8048:
8049: # Display user change log data
1.239 raeburn 8050: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
8051: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
8052: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 8053: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 8054: if ($count >= $curr{'page'} * $curr{'show'}) {
8055: $more_records = 1;
8056: last;
8057: }
8058: }
8059: if ($curr{'role'} ne 'any') {
8060: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
8061: }
8062: if ($curr{'chgcontext'} ne 'any') {
8063: if ($curr{'chgcontext'} eq 'selfenroll') {
8064: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
8065: } else {
8066: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
8067: }
8068: }
1.418 raeburn 8069: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 8070: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 8071: }
1.468 raeburn 8072: if ($curr{'approvals'} eq 'none') {
8073: next if ($roleslog{$id}{'logentry'}{'approval'});
8074: } elsif ($curr{'approvals'} ne 'any') {
8075: next if ($roleslog{$id}{'logentry'}{'approval'} ne $curr{'approvals'});
8076: }
1.239 raeburn 8077: $count ++;
8078: next if ($count < $minshown);
1.327 raeburn 8079: unless ($showntableheader) {
1.415 raeburn 8080: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 8081: .$tableheader);
8082: $r->rflush();
8083: $showntableheader = 1;
8084: }
1.239 raeburn 8085: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
8086: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
8087: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
8088: }
8089: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
8090: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
8091: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
8092: }
8093: my $sec = $roleslog{$id}{'logentry'}{'section'};
8094: if ($sec eq '') {
8095: $sec = &mt('None');
8096: }
8097: my ($rolestart,$roleend);
8098: if ($roleslog{$id}{'delflag'}) {
8099: $rolestart = &mt('deleted');
8100: $roleend = &mt('deleted');
8101: } else {
8102: $rolestart = $roleslog{$id}{'logentry'}{'start'};
8103: $roleend = $roleslog{$id}{'logentry'}{'end'};
8104: if ($rolestart eq '' || $rolestart == 0) {
8105: $rolestart = &mt('No start date');
8106: } else {
8107: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
8108: }
8109: if ($roleend eq '' || $roleend == 0) {
8110: $roleend = &mt('No end date');
8111: } else {
8112: $roleend = &Apache::lonlocal::locallocaltime($roleend);
8113: }
8114: }
8115: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
8116: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
8117: $chgcontext = 'selfenroll';
8118: }
1.363 raeburn 8119: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 8120: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
8121: $chgcontext = $lt{$chgcontext};
8122: }
1.468 raeburn 8123: my ($showreqby,%reqby);
8124: if (($roleslog{$id}{'logentry'}{'approval'}) &&
8125: ($roleslog{$id}{'logentry'}{'requester'})) {
8126: if ($reqby{$roleslog{$id}{'logentry'}{'requester'}} eq '') {
8127: my ($requname,$requdom) = split(/:/,$roleslog{$id}{'logentry'}{'requester'});
8128: $reqby{$roleslog{$id}{'logentry'}{'requester'}} =
8129: &Apache::loncommon::plainname($requname,$requdom);
8130: }
8131: $showreqby = &mt('Requester').': <span class="LC_nobreak">'.$reqby{$roleslog{$id}{'logentry'}{'requester'}}.'</span><br />';
8132: if ($roleslog{$id}{'logentry'}{'approval'} eq 'domain') {
8133: $showreqby .= &mt('Adjudicator').': <span class="LC_nobreak">'.
8134: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.
8135: '</span>';
8136: } else {
8137: $showreqby .= '<span class="LC_nobreak">'.&mt('User approved').'</span>';
8138: }
8139: } else {
8140: $showreqby = $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}};
8141: }
1.327 raeburn 8142: $r->print(
1.301 bisitz 8143: &Apache::loncommon::start_data_table_row()
8144: .'<td>'.$count.'</td>'
8145: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
1.468 raeburn 8146: .'<td>'.$showreqby.'</td>'
1.301 bisitz 8147: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 8148: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
8149: if ($context eq 'course') {
8150: $r->print('<td>'.$sec.'</td>');
8151: }
8152: $r->print(
8153: '<td>'.$chgcontext.'</td>'
1.301 bisitz 8154: .'<td>'.$rolestart.'</td>'
8155: .'<td>'.$roleend.'</td>'
1.327 raeburn 8156: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 8157: }
8158:
1.327 raeburn 8159: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 8160: $r->print(&Apache::loncommon::end_data_table().
8161: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 8162: } else { # No content displayed above
1.301 bisitz 8163: $r->print('<p class="LC_info">'
8164: .&mt('There are no records to display.')
8165: .'</p>'
8166: );
1.239 raeburn 8167: }
1.301 bisitz 8168:
1.327 raeburn 8169: # Form Footer
8170: $r->print(
8171: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
8172: .'<input type="hidden" name="action" value="changelogs" />'
8173: .'</form>');
8174: return;
8175: }
1.301 bisitz 8176:
1.416 raeburn 8177: sub print_useraccesslogs_display {
8178: my ($r,$uname,$udom,$permission,$brcrum) = @_;
8179: my $formname = 'accesslog';
8180: my $form = 'document.accesslog';
8181:
8182: # set breadcrumbs
1.422 raeburn 8183: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 8184: my $prevphasestr;
8185: if ($env{'form.popup'}) {
8186: $brcrum = [];
8187: } else {
8188: push (@{$brcrum},
8189: {href => "javascript:backPage($form)",
8190: text => $breadcrumb_text{'search'}});
8191: my @prevphases;
8192: if ($env{'form.prevphases'}) {
8193: @prevphases = split(/,/,$env{'form.prevphases'});
8194: $prevphasestr = $env{'form.prevphases'};
8195: }
8196: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
8197: push(@{$brcrum},
8198: {href => "javascript:backPage($form,'get_user_info','select')",
8199: text => $breadcrumb_text{'userpicked'}});
8200: if ($env{'form.phase'} eq 'userpicked') {
8201: $prevphasestr = 'userpicked';
8202: }
1.416 raeburn 8203: }
8204: }
8205: push(@{$brcrum},
8206: {href => '/adm/createuser?action=accesslogs',
8207: text => 'User access logs',
1.424 raeburn 8208: help => 'Domain_User_Access_Logs'});
1.416 raeburn 8209: my $bread_crumbs_component = 'User Access Logs';
8210: my $args = { bread_crumbs => $brcrum,
8211: bread_crumbs_component => 'User Management'};
1.423 raeburn 8212: if ($env{'form.popup'}) {
8213: $args->{'no_nav_bar'} = 1;
1.431 raeburn 8214: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 8215: }
1.416 raeburn 8216:
1.417 raeburn 8217: # set javascript
1.416 raeburn 8218: my ($jsback,$elements) = &crumb_utilities();
8219: my $jsnav = &userlogdisplay_js($formname);
8220:
8221: my $jscript = (<<ENDSCRIPT);
8222: <script type="text/javascript">
8223: // <![CDATA[
8224:
8225: $jsback
8226: $jsnav
8227:
8228: // ]]>
8229: </script>
8230:
8231: ENDSCRIPT
8232:
1.417 raeburn 8233: # print page header
1.416 raeburn 8234: $r->print(&header($jscript,$args));
8235:
8236: # early out unless log data can be displayed.
8237: unless ($permission->{'activity'}) {
8238: $r->print('<p class="LC_warning">'
8239: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 8240: .'</p>');
8241: if ($env{'form.popup'}) {
8242: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
8243: } else {
8244: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8245: }
1.416 raeburn 8246: return;
8247: }
8248:
8249: unless ($udom eq $env{'request.role.domain'}) {
8250: $r->print('<p class="LC_warning">'
8251: .&mt("User's domain must match role's domain")
8252: .'</p>'
8253: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 8254: return;
1.416 raeburn 8255: }
8256:
8257: if (($uname eq '') || ($udom eq '')) {
8258: $r->print('<p class="LC_warning">'
8259: .&mt('Invalid username or domain')
8260: .'</p>'
8261: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8262: return;
8263: }
8264:
1.437 raeburn 8265: if (&Apache::lonnet::privileged($uname,$udom,
8266: [$env{'request.role.domain'}],['dc','su'])) {
8267: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
8268: [$env{'request.role.domain'}],['dc','su'])) {
8269: $r->print('<p class="LC_warning">'
8270: .&mt('You need to be a privileged user to display user access logs for [_1]',
8271: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
8272: $uname,$udom))
8273: .'</p>');
8274: if ($env{'form.popup'}) {
8275: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
8276: } else {
8277: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8278: }
8279: return;
8280: }
8281: }
8282:
1.416 raeburn 8283: # set defaults
8284: my $now = time();
8285: my $defstart = $now - (7*24*3600);
8286: my %defaults = (
8287: page => '1',
8288: show => '10',
8289: activity => 'any',
8290: accesslog_start_date => $defstart,
8291: accesslog_end_date => $now,
8292: );
8293: my $more_records = 0;
8294:
8295: # set current
8296: my %curr;
8297: foreach my $item ('show','page','activity') {
8298: $curr{$item} = $env{'form.'.$item};
8299: }
8300: my ($startdate,$enddate) =
8301: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
8302: $curr{'accesslog_start_date'} = $startdate;
8303: $curr{'accesslog_end_date'} = $enddate;
8304: foreach my $key (keys(%defaults)) {
8305: if ($curr{$key} eq '') {
8306: $curr{$key} = $defaults{$key};
8307: }
8308: }
8309: my ($minshown,$maxshown);
8310: $minshown = 1;
8311: my $count = 0;
8312: if ($curr{'show'} =~ /\D/) {
8313: $curr{'page'} = 1;
8314: } else {
8315: $maxshown = $curr{'page'} * $curr{'show'};
8316: if ($curr{'page'} > 1) {
8317: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
8318: }
8319: }
8320:
8321: # form header
8322: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
8323: &activity_display_filter($formname,\%curr));
8324:
8325: my $showntableheader = 0;
8326: my ($nav_script,$nav_links);
8327:
8328: # table header
1.453 raeburn 8329: my $heading = '<h3>'.
1.431 raeburn 8330: &mt('User access logs for: [_1]',
1.453 raeburn 8331: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
8332: my $tableheader = $heading
1.431 raeburn 8333: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 8334: .'<th> </th>'
8335: .'<th>'.&mt('When').'</th>'
8336: .'<th>'.&mt('HostID').'</th>'
8337: .'<th>'.&mt('Event').'</th>'
8338: .'<th>'.&mt('Other data').'</th>'
8339: .&Apache::loncommon::end_data_table_header_row();
8340:
8341: my %filters=(
8342: start => $curr{'accesslog_start_date'},
8343: end => $curr{'accesslog_end_date'},
8344: action => $curr{'activity'},
8345: );
8346:
8347: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
8348: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
8349: my (%courses,%missing);
8350: my @results = split(/\&/,$reply);
8351: foreach my $item (reverse(@results)) {
8352: my ($timestamp,$host,$event) = split(/:/,$item);
8353: next unless ($event =~ /^(Log|Role)/);
8354: if ($curr{'show'} !~ /\D/) {
8355: if ($count >= $curr{'page'} * $curr{'show'}) {
8356: $more_records = 1;
8357: last;
8358: }
8359: }
8360: $count ++;
8361: next if ($count < $minshown);
8362: unless ($showntableheader) {
8363: $r->print($nav_script
8364: .&Apache::loncommon::start_data_table()
8365: .$tableheader);
8366: $r->rflush();
8367: $showntableheader = 1;
8368: }
1.418 raeburn 8369: my ($shown,$extra);
1.437 raeburn 8370: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 8371: if ($event eq 'Role') {
8372: my ($rolecode,$extent) = split(/\./,$data,2);
8373: next if ($extent eq '');
8374: my ($crstype,$desc,$info);
1.418 raeburn 8375: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
8376: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 8377: my $cid = $cdom.'_'.$cnum;
8378: if (exists($courses{$cid})) {
8379: $crstype = $courses{$cid}{'type'};
8380: $desc = $courses{$cid}{'description'};
8381: } elsif ($missing{$cid}) {
8382: $crstype = 'Course';
8383: $desc = 'Course/Community';
8384: } else {
8385: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
8386: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
8387: $courses{$cid} = $crsinfo{$cid};
8388: $crstype = $crsinfo{$cid}{'type'};
8389: $desc = $crsinfo{$cid}{'description'};
8390: } else {
8391: $missing{$cid} = 1;
8392: }
8393: }
8394: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 8395: if ($sec ne '') {
8396: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
8397: }
1.416 raeburn 8398: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
8399: my ($dom,$name) = ($1,$2);
8400: if ($rolecode eq 'au') {
8401: $extra = '';
8402: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 8403: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 8404: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
8405: $extra = &mt('Domain: [_1]',$dom);
8406: }
8407: }
8408: my $rolename;
8409: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
8410: my $role = $3;
1.417 raeburn 8411: my $owner = "($2:$1)";
1.416 raeburn 8412: if ($2 eq $1.'-domainconfig') {
8413: $owner = '(ad hoc)';
1.417 raeburn 8414: }
1.416 raeburn 8415: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
8416: } else {
8417: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
8418: }
8419: $shown = &mt('Role selection: [_1]',$rolename);
8420: } else {
8421: $shown = &mt($event);
1.437 raeburn 8422: if ($data =~ /^webdav/) {
8423: my ($path,$clientip) = split(/\s+/,$data,2);
8424: $path =~ s/^webdav//;
8425: if ($clientip ne '') {
8426: $extra = &mt('Client IP address: [_1]',$clientip);
8427: }
8428: if ($path ne '') {
8429: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
8430: }
8431: } elsif ($data ne '') {
8432: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 8433: }
8434: }
8435: $r->print(
8436: &Apache::loncommon::start_data_table_row()
8437: .'<td>'.$count.'</td>'
8438: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
8439: .'<td>'.$host.'</td>'
8440: .'<td>'.$shown.'</td>'
8441: .'<td>'.$extra.'</td>'
8442: .&Apache::loncommon::end_data_table_row()."\n");
8443: }
8444: }
8445:
8446: if ($showntableheader) { # Table footer, if content displayed above
8447: $r->print(&Apache::loncommon::end_data_table().
8448: &userlogdisplay_navlinks(\%curr,$more_records));
8449: } else { # No content displayed above
1.453 raeburn 8450: $r->print($heading.'<p class="LC_info">'
1.416 raeburn 8451: .&mt('There are no records to display.')
8452: .'</p>');
8453: }
8454:
1.423 raeburn 8455: if ($env{'form.popup'} == 1) {
8456: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
8457: }
8458:
1.416 raeburn 8459: # Form Footer
8460: $r->print(
8461: '<input type="hidden" name="currstate" value="" />'
8462: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
8463: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
8464: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
8465: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
8466: .'<input type="hidden" name="phase" value="activity" />'
8467: .'<input type="hidden" name="action" value="accesslogs" />'
8468: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
8469: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
8470: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
8471: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
8472: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
8473: .'</form>');
8474: return;
8475: }
8476:
8477: sub earlyout_accesslog_form {
8478: my ($formname,$prevphasestr,$udom) = @_;
8479: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
8480: return <<"END";
8481: <form action="/adm/createuser" method="post" name="$formname">
8482: <input type="hidden" name="currstate" value="" />
8483: <input type="hidden" name="prevphases" value="$prevphasestr" />
8484: <input type="hidden" name="phase" value="activity" />
8485: <input type="hidden" name="action" value="accesslogs" />
8486: <input type="hidden" name="srchdomain" value="$udom" />
8487: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
8488: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
8489: <input type="hidden" name="srchterm" value="$srchterm" />
8490: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
8491: </form>
8492: END
8493: }
8494:
8495: sub activity_display_filter {
8496: my ($formname,$curr) = @_;
8497: my $nolink = 1;
8498: my $output = '<table><tr><td valign="top">'.
8499: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
1.467 raeburn 8500: &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef,
1.416 raeburn 8501: (&mt('all'),5,10,20,50,100,1000,10000)).
8502: '</td><td> </td>';
8503: my $startform =
8504: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
8505: $curr->{'accesslog_start_date'},undef,
8506: undef,undef,undef,undef,undef,undef,$nolink);
8507: my $endform =
8508: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
8509: $curr->{'accesslog_end_date'},undef,
8510: undef,undef,undef,undef,undef,undef,$nolink);
8511: my %lt = &Apache::lonlocal::texthash (
8512: activity => 'Activity',
8513: Role => 'Role selection',
8514: log => 'Log-in or Logout',
8515: );
8516: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
8517: '<table><tr><td>'.&mt('After:').
8518: '</td><td>'.$startform.'</td></tr>'.
8519: '<tr><td>'.&mt('Before:').'</td>'.
8520: '<td>'.$endform.'</td></tr></table>'.
8521: '</td>'.
8522: '<td> </td>'.
8523: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
8524: '<select name="activity"><option value="any"';
8525: if ($curr->{'activity'} eq 'any') {
8526: $output .= ' selected="selected"';
8527: }
8528: $output .= '>'.&mt('Any').'</option>'."\n";
8529: foreach my $activity ('Role','log') {
8530: my $selstr = '';
8531: if ($activity eq $curr->{'activity'}) {
8532: $selstr = ' selected="selected"';
8533: }
8534: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
8535: }
8536: $output .= '</select></td>'.
8537: '</tr></table>';
8538: # Update Display button
8539: $output .= '<p>'
8540: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 8541: .'</p><hr />';
1.416 raeburn 8542: return $output;
8543: }
8544:
1.415 raeburn 8545: sub userlogdisplay_js {
8546: my ($formname) = @_;
8547: return <<"ENDSCRIPT";
8548:
1.239 raeburn 8549: function chgPage(caller) {
8550: if (caller == 'previous') {
8551: document.$formname.page.value --;
8552: }
8553: if (caller == 'next') {
8554: document.$formname.page.value ++;
8555: }
1.327 raeburn 8556: document.$formname.submit();
1.239 raeburn 8557: return;
8558: }
8559: ENDSCRIPT
1.415 raeburn 8560: }
8561:
8562: sub userlogdisplay_navlinks {
8563: my ($curr,$more_records) = @_;
8564: return unless(ref($curr) eq 'HASH');
8565: # Navigation Buttons
8566: my $nav_links = '<p>';
8567: if (($curr->{'page'} > 1) || ($more_records)) {
8568: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
8569: $nav_links .= '<input type="button"'
8570: .' onclick="javascript:chgPage('."'previous'".');"'
8571: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
8572: .'" /> ';
8573: }
8574: if ($more_records) {
8575: $nav_links .= '<input type="button"'
8576: .' onclick="javascript:chgPage('."'next'".');"'
8577: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
8578: .'" />';
1.301 bisitz 8579: }
8580: }
1.415 raeburn 8581: $nav_links .= '</p>';
8582: return $nav_links;
1.239 raeburn 8583: }
8584:
8585: sub role_display_filter {
1.363 raeburn 8586: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
1.239 raeburn 8587: my $nolink = 1;
8588: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 8589: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.467 raeburn 8590: &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef,
1.239 raeburn 8591: (&mt('all'),5,10,20,50,100,1000,10000)).
8592: '</td><td> </td>';
8593: my $startform =
8594: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
8595: $curr->{'rolelog_start_date'},undef,
8596: undef,undef,undef,undef,undef,undef,$nolink);
8597: my $endform =
8598: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
8599: $curr->{'rolelog_end_date'},undef,
8600: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 8601: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 8602: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
8603: '<table><tr><td>'.&mt('After:').
8604: '</td><td>'.$startform.'</td></tr>'.
8605: '<tr><td>'.&mt('Before:').'</td>'.
8606: '<td>'.$endform.'</td></tr></table>'.
8607: '</td>'.
8608: '<td> </td>'.
1.239 raeburn 8609: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
8610: '<select name="role"><option value="any"';
8611: if ($curr->{'role'} eq 'any') {
8612: $output .= ' selected="selected"';
8613: }
1.466 raeburn 8614: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 8615: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 8616: foreach my $role (@roles) {
8617: my $plrole;
8618: if ($role eq 'cr') {
8619: $plrole = &mt('Custom Role');
8620: } else {
1.318 raeburn 8621: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 8622: }
8623: my $selstr = '';
8624: if ($role eq $curr->{'role'}) {
8625: $selstr = ' selected="selected"';
8626: }
8627: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
8628: }
1.301 bisitz 8629: $output .= '</select></td>'.
8630: '<td> </td>'.
8631: '<td valign="top"><b>'.
1.239 raeburn 8632: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 8633: my @posscontexts;
8634: if ($context eq 'course') {
1.468 raeburn 8635: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype','ltienroll');
1.363 raeburn 8636: } elsif ($context eq 'domain') {
8637: @posscontexts = ('any','domain','requestauthor','domconfig','server');
8638: } else {
1.470 raeburn 8639: @posscontexts = ('any','author','coauthor','domain');
1.457 raeburn 8640: }
1.363 raeburn 8641: foreach my $chgtype (@posscontexts) {
1.239 raeburn 8642: my $selstr = '';
8643: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 8644: $selstr = ' selected="selected"';
1.239 raeburn 8645: }
1.363 raeburn 8646: if ($context eq 'course') {
1.376 raeburn 8647: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 8648: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
8649: }
1.239 raeburn 8650: }
8651: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 8652: }
1.468 raeburn 8653: my @possapprovals = ('any','none','domain','user');
8654: my %apptxt = &approval_types();
8655: $output .= '</select></td>'.
8656: '<td> </td>'.
8657: '<td valign="top"><b>'.
8658: &mt('Approvals:').'</b><br /><select name="approvals">';
8659: foreach my $approval (@possapprovals) {
8660: my $selstr = '';
8661: if ($curr->{'approvals'} eq $approval) {
8662: $selstr = ' selected="selected"';
8663: }
8664: $output .= '<option value="'.$approval.'"'.$selstr.'>'.$apptxt{$approval}.'</option>';
8665: }
8666: $output .= '</select></td></tr></table>';
1.303 bisitz 8667:
8668: # Update Display button
8669: $output .= '<p>'
8670: .'<input type="submit" value="'.&mt('Update Display').'" />'
8671: .'</p>';
8672:
8673: # Server version info
1.363 raeburn 8674: my $needsrev = '2.11.0';
8675: if ($context eq 'course') {
8676: $needsrev = '2.7.0';
8677: }
8678:
1.303 bisitz 8679: $output .= '<p class="LC_info">'
8680: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 8681: ,$needsrev);
1.248 raeburn 8682: if ($version) {
1.303 bisitz 8683: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
8684: }
8685: $output .= '</p><hr />';
1.239 raeburn 8686: return $output;
8687: }
8688:
8689: sub rolechg_contexts {
1.363 raeburn 8690: my ($context,$crstype) = @_;
8691: my %lt;
8692: if ($context eq 'course') {
8693: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 8694: any => 'Any',
1.376 raeburn 8695: automated => 'Automated Enrollment',
1.457 raeburn 8696: chgtype => 'Enrollment Type/Lock Change',
1.239 raeburn 8697: updatenow => 'Roster Update',
8698: createcourse => 'Course Creation',
8699: course => 'User Management in course',
8700: domain => 'User Management in domain',
1.313 raeburn 8701: selfenroll => 'Self-enrolled',
1.318 raeburn 8702: requestcourses => 'Course Request',
1.468 raeburn 8703: ltienroll => 'Enrollment via LTI',
1.239 raeburn 8704: );
1.363 raeburn 8705: if ($crstype eq 'Community') {
8706: $lt{'createcourse'} = &mt('Community Creation');
8707: $lt{'course'} = &mt('User Management in community');
8708: $lt{'requestcourses'} = &mt('Community Request');
8709: }
8710: } elsif ($context eq 'domain') {
8711: %lt = &Apache::lonlocal::texthash (
8712: any => 'Any',
8713: domain => 'User Management in domain',
8714: requestauthor => 'Authoring Request',
8715: server => 'Command line script (DC role)',
8716: domconfig => 'Self-enrolled',
8717: );
8718: } else {
8719: %lt = &Apache::lonlocal::texthash (
8720: any => 'Any',
8721: domain => 'User Management in domain',
8722: author => 'User Management by author',
1.470 raeburn 8723: coauthor => 'User Management by coauthor',
1.363 raeburn 8724: );
8725: }
1.239 raeburn 8726: return %lt;
8727: }
8728:
1.468 raeburn 8729: sub approval_types {
8730: return &Apache::lonlocal::texthash (
8731: any => 'Any',
8732: none => 'No approval needed',
8733: user => 'Role recipient approval',
8734: domain => 'Domain coordinator approval',
8735: );
8736: }
8737:
1.428 raeburn 8738: sub print_helpdeskaccess_display {
8739: my ($r,$permission,$brcrum) = @_;
8740: my $formname = 'helpdeskaccess';
8741: my $helpitem = 'Course_Helpdesk_Access';
8742: push (@{$brcrum},
8743: {href => '/adm/createuser?action=helpdesk',
8744: text => 'Helpdesk Access',
8745: help => $helpitem});
8746: my $bread_crumbs_component = 'Helpdesk Staff Access';
8747: my $args = { bread_crumbs => $brcrum,
8748: bread_crumbs_component => $bread_crumbs_component};
8749:
8750: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8751: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8752: my $confname = $cdom.'-domainconfig';
8753: my $crstype = &Apache::loncommon::course_type();
8754:
1.434 raeburn 8755: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 8756: my ($numstatustypes,@jsarray);
8757: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8758: if (ref($types) eq 'ARRAY') {
1.430 raeburn 8759: if (@{$types} > 0) {
1.428 raeburn 8760: $numstatustypes = scalar(@{$types});
8761: push(@accesstypes,'status');
8762: @jsarray = ('bystatus');
8763: }
8764: }
8765: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 8766: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8767: if (keys(%domhelpdesk)) {
8768: push(@accesstypes,('inc','exc'));
8769: push(@jsarray,('notinc','notexc'));
8770: }
8771: push(@jsarray,'privs');
8772: my $hiddenstr = join("','",@jsarray);
8773: my $rolestr = join("','",sort(keys(%customroles)));
8774:
8775: my $jscript;
8776: my (%settings,%overridden);
8777: if (keys(%customroles)) {
8778: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8779: $types,\%customroles,\%settings,\%overridden);
8780: my %jsfull=();
8781: my %jslevels= (
8782: course => {},
8783: domain => {},
8784: system => {},
8785: );
8786: my %jslevelscurrent=(
8787: course => {},
8788: domain => {},
8789: system => {},
8790: );
8791: my (%privs,%jsprivs);
8792: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
8793: foreach my $priv (keys(%jsfull)) {
8794: if ($jslevels{'course'}{$priv}) {
8795: $jsprivs{$priv} = 1;
8796: }
8797: }
8798: my (%elements,%stored);
8799: foreach my $role (keys(%customroles)) {
8800: $elements{$role.'_access'} = 'radio';
8801: $elements{$role.'_incrs'} = 'radio';
8802: if ($numstatustypes) {
8803: $elements{$role.'_status'} = 'checkbox';
8804: }
8805: if (keys(%domhelpdesk) > 0) {
8806: $elements{$role.'_staff_inc'} = 'checkbox';
8807: $elements{$role.'_staff_exc'} = 'checkbox';
8808: }
1.430 raeburn 8809: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 8810: if (ref($settings{$role}) eq 'HASH') {
8811: if ($settings{$role}{'access'} ne '') {
8812: my $curraccess = $settings{$role}{'access'};
8813: $stored{$role.'_access'} = $curraccess;
8814: $stored{$role.'_incrs'} = 1;
8815: if ($curraccess eq 'status') {
8816: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
8817: $stored{$role.'_status'} = $settings{$role}{'status'};
8818: }
8819: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8820: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
8821: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
8822: }
8823: }
8824: } else {
8825: $stored{$role.'_incrs'} = 0;
8826: }
8827: $stored{$role.'_override'} = [];
8828: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
8829: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
8830: foreach my $priv (@{$settings{$role}{'off'}}) {
8831: push(@{$stored{$role.'_override'}},$priv);
8832: }
8833: }
8834: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
8835: foreach my $priv (@{$settings{$role}{'on'}}) {
8836: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
8837: push(@{$stored{$role.'_override'}},$priv);
8838: }
8839: }
8840: }
8841: }
8842: } else {
8843: $stored{$role.'_incrs'} = 0;
8844: }
8845: }
8846: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
8847: }
8848:
8849: my $js = <<"ENDJS";
8850: <script type="text/javascript">
8851: // <![CDATA[
8852: $jscript;
8853:
8854: function switchRoleTab(caller,role) {
8855: if (document.getElementById(role+'_maindiv')) {
8856: if (caller.id != 'LC_current_minitab') {
8857: if (document.getElementById('LC_current_minitab')) {
8858: document.getElementById('LC_current_minitab').id=null;
8859: }
8860: var roledivs = Array('$rolestr');
8861: if (roledivs.length > 0) {
8862: for (var i=0; i<roledivs.length; i++) {
8863: if (document.getElementById(roledivs[i]+'_maindiv')) {
8864: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
8865: }
8866: }
8867: }
8868: caller.id = 'LC_current_minitab';
8869: document.getElementById(role+'_maindiv').style.display='block';
8870: }
8871: }
8872: return false;
1.430 raeburn 8873: }
1.428 raeburn 8874:
8875: function helpdeskAccess(role) {
8876: var curraccess = null;
8877: if (document.$formname.elements[role+'_access'].length) {
8878: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
8879: if (document.$formname.elements[role+'_access'][i].checked) {
8880: curraccess = document.$formname.elements[role+'_access'][i].value;
8881: }
8882: }
8883: }
8884: var shown = Array();
8885: var hidden = Array();
8886: if (curraccess == 'none') {
1.430 raeburn 8887: hidden = Array ('$hiddenstr');
1.428 raeburn 8888: } else {
8889: if (curraccess == 'status') {
1.430 raeburn 8890: shown = Array ('bystatus','privs');
8891: hidden = Array ('notinc','notexc');
1.428 raeburn 8892: } else {
8893: if (curraccess == 'exc') {
8894: shown = Array ('notexc','privs');
8895: hidden = Array ('notinc','bystatus');
8896: }
8897: if (curraccess == 'inc') {
8898: shown = Array ('notinc','privs');
8899: hidden = Array ('notexc','bystatus');
8900: }
8901: if (curraccess == 'all') {
8902: shown = Array ('privs');
8903: hidden = Array ('notinc','notexc','bystatus');
8904: }
8905: }
8906: }
8907: if (hidden.length > 0) {
8908: for (var i=0; i<hidden.length; i++) {
8909: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 8910: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 8911: }
8912: }
8913: }
8914: if (shown.length > 0) {
8915: for (var i=0; i<shown.length; i++) {
8916: if (document.getElementById(role+'_'+shown[i])) {
8917: if (shown[i] == 'privs') {
8918: document.getElementById(role+'_'+shown[i]).style.display = 'block';
8919: } else {
8920: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
8921: }
8922: }
8923: }
8924: }
8925: return;
8926: }
8927:
8928: function toggleAccess(role) {
8929: if ((document.getElementById(role+'_setincrs')) &&
8930: (document.getElementById(role+'_setindom'))) {
8931: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
8932: if (document.$formname.elements[role+'_incrs'][i].checked) {
8933: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
8934: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 8935: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 8936: } else {
8937: document.getElementById(role+'_setincrs').style.display = 'none';
8938: document.getElementById(role+'_setindom').style.display = 'block';
8939: }
8940: break;
8941: }
8942: }
8943: }
8944: return;
8945: }
8946:
8947: // ]]>
8948: </script>
8949: ENDJS
8950:
8951: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
8952:
8953: # print page header
8954: $r->print(&header($js,$args));
8955: # print form header
8956: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
8957:
8958: if (keys(%customroles)) {
8959: my %lt = &Apache::lonlocal::texthash(
8960: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
8961: 'rou' => 'Role usage',
8962: 'whi' => 'Which helpdesk personnel may use this role?',
8963: 'udd' => 'Use domain default',
1.433 raeburn 8964: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 8965: 'dh' => 'All with domain helpdesk role',
8966: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 8967: 'none' => 'None',
8968: 'status' => 'Determined based on institutional status',
1.430 raeburn 8969: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 8970: 'exc' => 'Exclude all, but include specific personnel',
8971: 'hel' => 'Helpdesk',
8972: 'rpr' => 'Role privileges',
8973: );
8974: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
8975: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8976: my (%domcurrent,%ordered,%description,%domusage,$disabled);
8977: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8978: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8979: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8980: }
8981: }
8982: my $count = 0;
8983: foreach my $role (sort(keys(%customroles))) {
8984: my ($order,$desc,$access_in_dom);
8985: if (ref($domcurrent{$role}) eq 'HASH') {
8986: $order = $domcurrent{$role}{'order'};
8987: $desc = $domcurrent{$role}{'desc'};
8988: $access_in_dom = $domcurrent{$role}{'access'};
8989: }
8990: if ($order eq '') {
8991: $order = $count;
8992: }
8993: $ordered{$order} = $role;
8994: if ($desc ne '') {
8995: $description{$role} = $desc;
8996: } else {
8997: $description{$role}= $role;
8998: }
8999: $count++;
9000: }
9001: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
9002: my @roles_by_num = ();
9003: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
9004: push(@roles_by_num,$ordered{$item});
1.430 raeburn 9005: }
1.429 raeburn 9006: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 9007: if ($permission->{'owner'}) {
9008: $r->print('<br />'.$lt{'aco'}.'</p><p>');
9009: $r->print('<input type="hidden" name="state" value="process" />'.
9010: '<input type="submit" value="'.&mt('Save changes').'" />');
9011: } else {
9012: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
9013: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
9014: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
9015: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
9016: }
9017: $disabled = ' disabled="disabled"';
9018: }
9019: $r->print('</p>');
9020:
9021: $r->print('<div id="LC_minitab_header"><ul>');
9022: my $count = 0;
9023: my %visibility;
9024: foreach my $role (@roles_by_num) {
9025: my $id;
9026: if ($count == 0) {
9027: $id=' id="LC_current_minitab"';
1.430 raeburn 9028: $visibility{$role} = ' style="display:block"';
1.428 raeburn 9029: } else {
9030: $visibility{$role} = ' style="display:none"';
9031: }
9032: $count ++;
9033: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
9034: }
9035: $r->print('</ul></div>');
9036:
9037: foreach my $role (@roles_by_num) {
9038: my %usecheck = (
9039: all => ' checked="checked"',
9040: );
9041: my %displaydiv = (
9042: status => 'none',
9043: inc => 'none',
9044: exc => 'none',
9045: priv => 'block',
9046: );
9047: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 9048: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 9049: if ($settings{$role}{'access'} ne '') {
9050: $indomvis = ' style="display:none"';
9051: $incrsvis = ' style="display:block"';
1.430 raeburn 9052: $incrscheck = ' checked="checked"';
1.428 raeburn 9053: if ($settings{$role}{'access'} ne 'all') {
9054: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
9055: delete($usecheck{'all'});
9056: if ($settings{$role}{'access'} eq 'status') {
9057: my $access = 'status';
9058: $displaydiv{$access} = 'inline';
9059: if (ref($settings{$role}{$access}) eq 'ARRAY') {
9060: $selected{$access} = $settings{$role}{$access};
9061: }
9062: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
9063: my $access = $1;
9064: $displaydiv{$access} = 'inline';
9065: if (ref($settings{$role}{$access}) eq 'ARRAY') {
9066: $selected{$access} = $settings{$role}{$access};
9067: }
9068: } elsif ($settings{$role}{'access'} eq 'none') {
9069: $displaydiv{'priv'} = 'none';
9070: }
9071: }
9072: } else {
9073: $indomcheck = ' checked="checked"';
9074: $indomvis = ' style="display:block"';
9075: $incrsvis = ' style="display:none"';
9076: }
9077: } else {
9078: $indomcheck = ' checked="checked"';
1.430 raeburn 9079: $indomvis = ' style="display:block"';
1.428 raeburn 9080: $incrsvis = ' style="display:none"';
9081: }
9082: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
9083: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
9084: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
9085: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
9086: &mt('Set here in [_1]',lc($crstype)).'</label>'.
9087: '<span>'.(' 'x2).
9088: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
9089: $lt{'udd'}.'</label><span></p>'.
9090: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
9091: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
9092: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
9093: foreach my $access (@accesstypes) {
9094: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
9095: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
9096: if ($access eq 'status') {
9097: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
9098: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
9099: $othertitle,$usertypes,$types,$disabled).
9100: '</div>');
9101: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
9102: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
9103: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
9104: \%domhelpdesk,$disabled).
9105: '</div>');
9106: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
9107: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
9108: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
9109: \%domhelpdesk,$disabled).
9110: '</div>');
9111: }
9112: $r->print('</p>');
9113: }
9114: $r->print('</div></fieldset>');
9115: my %full=();
9116: my %levels= (
9117: course => {},
9118: domain => {},
9119: system => {},
9120: );
9121: my %levelscurrent=(
9122: course => {},
9123: domain => {},
9124: system => {},
9125: );
9126: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
9127: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
9128: '<legend>'.$lt{'rpr'}.'</legend>'.
9129: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
9130: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
9131: }
1.429 raeburn 9132: if ($permission->{'owner'}) {
9133: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
9134: }
1.428 raeburn 9135: } else {
9136: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
9137: }
9138: # Form Footer
9139: $r->print('<input type="hidden" name="action" value="helpdesk" />'
9140: .'</form>');
9141: return;
9142: }
9143:
1.465 raeburn 9144: sub print_queued_roles {
9145: my ($r,$context,$permission,$brcrum) = @_;
9146: push (@{$brcrum},
9147: {href => '/adm/createuser?action=rolerequests',
9148: text => 'Role Requests (other domains)',
9149: help => ''});
9150: my $bread_crumbs_component = 'Role Requests';
9151: my $args = { bread_crumbs => $brcrum,
9152: bread_crumbs_component => $bread_crumbs_component};
9153: # print page header
9154: $r->print(&header('',$args));
9155: my ($dom,$cnum);
9156: $dom = $env{'request.role.domain'};
9157: if ($context eq 'course') {
9158: if ($env{'request.course.id'}) {
9159: if (&Apache::loncommon::course_type() eq 'Community') {
9160: $context = 'community';
9161: }
9162: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9163: }
9164: } elsif ($context eq 'author') {
9165: $cnum = $env{'user.name'};
9166: }
9167: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('othdomqueue',$dom,$cnum,$context));
9168: return;
9169: }
9170:
9171: sub print_pendingroles {
9172: my ($r,$context,$permission,$brcrum) = @_;
9173: push (@{$brcrum},
9174: {href => '/adm/createuser?action=queuedroles',
9175: text => 'Queued Role Assignments (users in this domain)',
9176: help => ''});
9177: my $bread_crumbs_component = 'Queued Role Assignments';
9178: my $args = { bread_crumbs => $brcrum,
9179: bread_crumbs_component => $bread_crumbs_component};
9180: # print page header
9181: $r->print(&header('',$args));
9182: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('othdomaction',$env{'request.role.domain'},'','domain'));
9183: return;
9184: }
9185:
9186: sub process_pendingroles {
9187: my ($r,$context,$permission,$brcrum) = @_;
9188: push (@{$brcrum},
9189: {href => '/adm/createuser?action=queuedroles',
9190: text => 'Queued Role Assignments (users in this domain)',
9191: help => ''},
9192: {href => '/adm/createuser?action=processrolereq',
9193: text => 'Process Queue',
9194: help => ''});
9195: my $bread_crumbs_component = 'Queued Role Assignments';
9196: my $args = { bread_crumbs => $brcrum,
9197: bread_crumbs_component => $bread_crumbs_component};
9198: # print page header
9199: $r->print(&header('',$args));
9200: $r->print(&Apache::loncoursequeueadmin::update_request_queue('othdombydc',
9201: $env{'request.role.domain'}));
9202: return;
9203: }
9204:
1.428 raeburn 9205: sub domain_adhoc_access {
9206: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
9207: my %domusage;
9208: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
9209: foreach my $role (keys(%{$roles})) {
9210: if (ref($domcurrent->{$role}) eq 'HASH') {
9211: my $access = $domcurrent->{$role}{'access'};
9212: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
9213: $access = 'all';
1.432 raeburn 9214: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
9215: &Apache::lonnet::plaintext('da'));
1.428 raeburn 9216: } elsif ($access eq 'status') {
9217: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
9218: my @shown;
9219: foreach my $type (@{$domcurrent->{$role}{$access}}) {
9220: unless ($type eq 'default') {
9221: if ($usertypes->{$type}) {
9222: push(@shown,$usertypes->{$type});
9223: }
9224: }
9225: }
9226: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
9227: push(@shown,$othertitle);
9228: }
9229: if (@shown) {
9230: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 9231: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
9232: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 9233: } else {
9234: $domusage{$role} = &mt('No one in the domain');
9235: }
9236: }
9237: } elsif ($access eq 'inc') {
9238: my @dominc = ();
9239: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
9240: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
9241: my ($uname,$udom) = split(/:/,$user);
9242: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
9243: }
9244: my $showninc = join(', ',@dominc);
9245: if ($showninc ne '') {
1.432 raeburn 9246: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
9247: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 9248: } else {
1.432 raeburn 9249: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
9250: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 9251: }
9252: }
9253: } elsif ($access eq 'exc') {
9254: my @domexc = ();
9255: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
9256: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
9257: my ($uname,$udom) = split(/:/,$user);
9258: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
9259: }
9260: }
9261: my $shownexc = join(', ',@domexc);
9262: if ($shownexc ne '') {
1.432 raeburn 9263: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
9264: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 9265: } else {
9266: $domusage{$role} = &mt('No one in the domain');
9267: }
9268: } elsif ($access eq 'none') {
9269: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 9270: } elsif ($access eq 'dh') {
1.433 raeburn 9271: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 9272: } elsif ($access eq 'da') {
1.433 raeburn 9273: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 9274: } elsif ($access eq 'all') {
1.432 raeburn 9275: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
9276: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 9277: }
9278: } else {
1.432 raeburn 9279: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
9280: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 9281: }
9282: }
9283: return %domusage;
9284: }
9285:
9286: sub get_domain_customroles {
9287: my ($cdom,$confname) = @_;
9288: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
9289: my %customroles;
9290: foreach my $key (keys(%existing)) {
9291: if ($key=~/^rolesdef\_(\w+)$/) {
9292: my $rolename = $1;
9293: my %privs;
9294: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
9295: $customroles{$rolename} = \%privs;
9296: }
9297: }
9298: return %customroles;
9299: }
9300:
9301: sub role_priv_table {
9302: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
9303: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
9304: (ref($levelscurrent) eq 'HASH'));
9305: my %lt=&Apache::lonlocal::texthash (
9306: 'crl' => 'Course Level Privilege',
9307: 'def' => 'Domain Defaults',
9308: 'ove' => 'Override in Course',
9309: 'ine' => 'In effect',
9310: 'dis' => 'Disabled',
9311: 'ena' => 'Enabled',
9312: );
9313: if ($crstype eq 'Community') {
9314: $lt{'ove'} = 'Override in Community',
9315: }
9316: my @status = ('Disabled','Enabled');
9317: my (%on,%off);
9318: if (ref($overridden) eq 'HASH') {
9319: if (ref($overridden->{'on'}) eq 'ARRAY') {
9320: map { $on{$_} = 1; } (@{$overridden->{'on'}});
9321: }
9322: if (ref($overridden->{'off'}) eq 'ARRAY') {
9323: map { $off{$_} = 1; } (@{$overridden->{'off'}});
9324: }
9325: }
9326: my $output=&Apache::loncommon::start_data_table().
9327: &Apache::loncommon::start_data_table_header_row().
9328: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
9329: '</th><th>'.$lt{'ine'}.'</th>'.
9330: &Apache::loncommon::end_data_table_header_row();
9331: foreach my $priv (sort(keys(%{$full}))) {
9332: next unless ($levels->{'course'}{$priv});
9333: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
9334: my ($default,$ineffect);
9335: if ($levelscurrent->{'course'}{$priv}) {
9336: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
9337: $ineffect = $default;
9338: }
9339: my ($customstatus,$checked);
9340: $output .= &Apache::loncommon::start_data_table_row().
9341: '<td>'.$privtext.'</td>'.
9342: '<td>'.$default.'</td><td>';
9343: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
9344: if ($permission->{'owner'}) {
9345: $checked = ' checked="checked"';
9346: }
9347: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 9348: $ineffect = $customstatus;
1.428 raeburn 9349: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
9350: if ($permission->{'owner'}) {
1.430 raeburn 9351: $checked = ' checked="checked"';
1.428 raeburn 9352: }
9353: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 9354: $ineffect = $customstatus;
1.428 raeburn 9355: }
9356: if ($permission->{'owner'}) {
9357: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
9358: } else {
9359: $output .= $customstatus;
9360: }
9361: $output .= '</td><td>'.$ineffect.'</td>'.
9362: &Apache::loncommon::end_data_table_row();
9363: }
9364: $output .= &Apache::loncommon::end_data_table();
9365: return $output;
9366: }
9367:
9368: sub get_adhocrole_settings {
1.430 raeburn 9369: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 9370: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
9371: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
9372: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
9373: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
9374: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
9375: $settings->{$role}{'access'} = $curraccess;
9376: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
9377: my @status = split(/,/,$rest);
9378: my @currstatus;
9379: foreach my $type (@status) {
9380: if ($type eq 'default') {
9381: push(@currstatus,$type);
9382: } elsif (grep(/^\Q$type\E$/,@{$types})) {
9383: push(@currstatus,$type);
9384: }
9385: }
9386: if (@currstatus) {
9387: $settings->{$role}{$curraccess} = \@currstatus;
9388: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
9389: my @personnel = split(/,/,$rest);
9390: $settings->{$role}{$curraccess} = \@personnel;
9391: }
9392: }
9393: }
9394: }
9395: foreach my $role (keys(%{$customroles})) {
9396: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
9397: my %currentprivs;
9398: if (ref($customroles->{$role}) eq 'HASH') {
9399: if (exists($customroles->{$role}{'course'})) {
9400: my %full=();
9401: my %levels= (
9402: course => {},
9403: domain => {},
9404: system => {},
9405: );
9406: my %levelscurrent=(
9407: course => {},
9408: domain => {},
9409: system => {},
9410: );
9411: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
9412: %currentprivs = %{$levelscurrent{'course'}};
9413: }
9414: }
9415: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
9416: next if ($item eq '');
9417: my ($rule,$rest) = split(/=/,$item);
9418: next unless (($rule eq 'off') || ($rule eq 'on'));
9419: foreach my $priv (split(/:/,$rest)) {
9420: if ($priv ne '') {
9421: if ($rule eq 'off') {
9422: push(@{$overridden->{$role}{'off'}},$priv);
9423: if ($currentprivs{$priv}) {
9424: push(@{$settings->{$role}{'off'}},$priv);
9425: }
9426: } else {
9427: push(@{$overridden->{$role}{'on'}},$priv);
9428: unless ($currentprivs{$priv}) {
9429: push(@{$settings->{$role}{'on'}},$priv);
9430: }
9431: }
9432: }
9433: }
9434: }
9435: }
9436: }
9437: return;
9438: }
9439:
9440: sub update_helpdeskaccess {
9441: my ($r,$permission,$brcrum) = @_;
9442: my $helpitem = 'Course_Helpdesk_Access';
9443: push (@{$brcrum},
9444: {href => '/adm/createuser?action=helpdesk',
9445: text => 'Helpdesk Access',
9446: help => $helpitem},
9447: {href => '/adm/createuser?action=helpdesk',
9448: text => 'Result',
9449: help => $helpitem}
9450: );
9451: my $bread_crumbs_component = 'Helpdesk Staff Access';
9452: my $args = { bread_crumbs => $brcrum,
9453: bread_crumbs_component => $bread_crumbs_component};
9454:
9455: # print page header
9456: $r->print(&header('',$args));
9457: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
9458: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
9459: return;
9460: }
1.434 raeburn 9461: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 9462: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9463: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9464: my $confname = $cdom.'-domainconfig';
9465: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
9466: my $crstype = &Apache::loncommon::course_type();
9467: my %customroles = &get_domain_customroles($cdom,$confname);
9468: my (%settings,%overridden);
9469: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
9470: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 9471: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 9472: my (%changed,%storehash,@todelete);
9473:
9474: if (keys(%customroles)) {
9475: my (%newsettings,@incrs);
9476: foreach my $role (keys(%customroles)) {
9477: $newsettings{$role} = {
9478: access => '',
9479: status => '',
9480: exc => '',
9481: inc => '',
9482: on => '',
9483: off => '',
9484: };
9485: my %current;
9486: if (ref($settings{$role}) eq 'HASH') {
9487: %current = %{$settings{$role}};
9488: }
9489: if (ref($overridden{$role}) eq 'HASH') {
9490: $current{'overridden'} = $overridden{$role};
9491: }
9492: if ($env{'form.'.$role.'_incrs'}) {
9493: my $access = $env{'form.'.$role.'_access'};
9494: if (grep(/^\Q$access\E$/,@accesstypes)) {
9495: push(@incrs,$role);
9496: unless ($current{'access'} eq $access) {
9497: $changed{$role}{'access'} = 1;
1.430 raeburn 9498: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 9499: }
9500: if ($access eq 'status') {
9501: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
9502: my @stored;
9503: my @shownstatus;
9504: if (ref($types) eq 'ARRAY') {
9505: foreach my $type (sort(@statuses)) {
9506: if ($type eq 'default') {
9507: push(@stored,$type);
9508: } elsif (grep(/^\Q$type\E$/,@{$types})) {
9509: push(@stored,$type);
9510: push(@shownstatus,$usertypes->{$type});
9511: }
9512: }
9513: if (grep(/^default$/,@statuses)) {
9514: push(@shownstatus,$othertitle);
9515: }
9516: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
9517: }
9518: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
9519: if (ref($current{'status'}) eq 'ARRAY') {
9520: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
9521: if (@diffs) {
9522: $changed{$role}{'status'} = 1;
9523: }
9524: } elsif (@stored) {
9525: $changed{$role}{'status'} = 1;
9526: }
9527: } elsif (($access eq 'inc') || ($access eq 'exc')) {
9528: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
9529: my @newspecstaff;
9530: my @stored;
9531: my @currstaff;
9532: foreach my $person (sort(@personnel)) {
9533: if ($domhelpdesk{$person}) {
1.430 raeburn 9534: push(@stored,$person);
1.428 raeburn 9535: }
9536: }
9537: if (ref($current{$access}) eq 'ARRAY') {
9538: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
9539: if (@diffs) {
9540: $changed{$role}{$access} = 1;
9541: }
9542: } elsif (@stored) {
9543: $changed{$role}{$access} = 1;
9544: }
9545: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
9546: foreach my $person (@stored) {
9547: my ($uname,$udom) = split(/:/,$person);
9548: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
9549: }
9550: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
9551: }
9552: $newsettings{$role}{'access'} = $access;
9553: }
9554: } else {
9555: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
9556: $changed{$role}{'access'} = 1;
9557: $newsettings{$role} = {};
9558: push(@todelete,'internal.adhoc.'.$role);
9559: }
9560: }
9561: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
9562: if (ref($current{'overridden'}) eq 'HASH') {
9563: push(@todelete,'internal.adhocpriv.'.$role);
9564: }
9565: } else {
9566: my %full=();
9567: my %levels= (
9568: course => {},
9569: domain => {},
9570: system => {},
9571: );
9572: my %levelscurrent=(
9573: course => {},
9574: domain => {},
9575: system => {},
9576: );
9577: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
9578: my (@updatedon,@updatedoff,@override);
9579: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 9580: if (@override) {
1.428 raeburn 9581: foreach my $priv (sort(keys(%full))) {
9582: next unless ($levels{'course'}{$priv});
9583: if (grep(/^\Q$priv\E$/,@override)) {
9584: if ($levelscurrent{'course'}{$priv}) {
9585: push(@updatedoff,$priv);
9586: } else {
9587: push(@updatedon,$priv);
9588: }
9589: }
9590: }
9591: }
9592: if (@updatedon) {
1.430 raeburn 9593: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 9594: }
9595: if (@updatedoff) {
9596: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
9597: }
9598: if (ref($current{'overridden'}) eq 'HASH') {
9599: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
9600: if (@updatedon) {
9601: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
9602: if (@diffs) {
9603: $changed{$role}{'on'} = 1;
9604: }
9605: } else {
9606: $changed{$role}{'on'} = 1;
9607: }
9608: } elsif (@updatedon) {
9609: $changed{$role}{'on'} = 1;
9610: }
9611: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
9612: if (@updatedoff) {
9613: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
9614: if (@diffs) {
9615: $changed{$role}{'off'} = 1;
9616: }
9617: } else {
9618: $changed{$role}{'off'} = 1;
9619: }
9620: } elsif (@updatedoff) {
9621: $changed{$role}{'off'} = 1;
9622: }
9623: } else {
9624: if (@updatedon) {
9625: $changed{$role}{'on'} = 1;
9626: }
9627: if (@updatedoff) {
9628: $changed{$role}{'off'} = 1;
9629: }
9630: }
9631: if (ref($changed{$role}) eq 'HASH') {
9632: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
9633: my $newpriv;
9634: if (@updatedon) {
9635: $newpriv = 'on='.join(':',@updatedon);
9636: }
9637: if (@updatedoff) {
9638: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
9639: }
9640: if ($newpriv eq '') {
9641: push(@todelete,'internal.adhocpriv.'.$role);
9642: } else {
9643: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
9644: }
9645: }
9646: }
9647: }
9648: }
9649: if (@incrs) {
9650: $storehash{'internal.adhocaccess'} = join(',',@incrs);
9651: } elsif (@todelete) {
9652: push(@todelete,'internal.adhocaccess');
9653: }
9654: if (keys(%changed)) {
9655: my ($putres,$delres);
9656: if (keys(%storehash)) {
9657: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
9658: my %newenvhash;
9659: foreach my $key (keys(%storehash)) {
9660: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
9661: }
9662: &Apache::lonnet::appenv(\%newenvhash);
9663: }
9664: if (@todelete) {
9665: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
9666: foreach my $key (@todelete) {
9667: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
9668: }
9669: }
9670: if (($putres eq 'ok') || ($delres eq 'ok')) {
9671: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
9672: my (%domcurrent,%ordered,%description,%domusage);
9673: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9674: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
9675: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
9676: }
9677: }
9678: my $count = 0;
9679: foreach my $role (sort(keys(%customroles))) {
9680: my ($order,$desc);
9681: if (ref($domcurrent{$role}) eq 'HASH') {
9682: $order = $domcurrent{$role}{'order'};
9683: $desc = $domcurrent{$role}{'desc'};
9684: }
9685: if ($order eq '') {
9686: $order = $count;
9687: }
9688: $ordered{$order} = $role;
9689: if ($desc ne '') {
9690: $description{$role} = $desc;
9691: } else {
9692: $description{$role}= $role;
9693: }
9694: $count++;
9695: }
9696: my @roles_by_num = ();
9697: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
9698: push(@roles_by_num,$ordered{$item});
9699: }
9700: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 9701: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 9702: $r->print('<ul>');
9703: foreach my $role (@roles_by_num) {
9704: next unless (ref($changed{$role}) eq 'HASH');
9705: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
9706: '<ul>');
1.430 raeburn 9707: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 9708: $r->print('<li>');
9709: if ($env{'form.'.$role.'_incrs'}) {
9710: if ($newsettings{$role}{'access'} eq 'all') {
9711: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 9712: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 9713: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
9714: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 9715: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 9716: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
9717: &Apache::lonnet::plaintext('da')));
1.428 raeburn 9718: } elsif ($newsettings{$role}{'access'} eq 'none') {
9719: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9720: } elsif ($newsettings{$role}{'access'} eq 'status') {
9721: if ($newsettings{$role}{'status'}) {
9722: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 9723: if (split(/,/,$rest) > 1) {
1.428 raeburn 9724: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
9725: $newsettings{$role}{'status'}));
9726: } else {
9727: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
9728: $newsettings{$role}{'status'}));
9729: }
9730: } else {
9731: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9732: }
9733: } elsif ($newsettings{$role}{'access'} eq 'exc') {
9734: if ($newsettings{$role}{'exc'}) {
9735: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
9736: } else {
9737: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9738: }
9739: } elsif ($newsettings{$role}{'access'} eq 'inc') {
9740: if ($newsettings{$role}{'inc'}) {
9741: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
9742: } else {
9743: $r->print(&mt('All helpdesk staff may use this role.'));
9744: }
9745: }
9746: } else {
9747: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
9748: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
9749: }
9750: $r->print('</li>');
9751: }
9752: unless ($newsettings{$role}{'access'} eq 'none') {
9753: if ($changed{$role}{'off'}) {
9754: if ($newsettings{$role}{'off'}) {
9755: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
9756: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
9757: } else {
1.430 raeburn 9758: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 9759: }
9760: }
1.430 raeburn 9761: if ($changed{$role}{'on'}) {
1.428 raeburn 9762: if ($newsettings{$role}{'on'}) {
9763: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
9764: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
9765: } else {
1.430 raeburn 9766: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 9767: }
9768: }
9769: }
9770: $r->print('</ul></li>');
9771: }
9772: $r->print('</ul>');
9773: }
9774: } else {
1.430 raeburn 9775: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 9776: }
9777: }
9778: return;
9779: }
9780:
1.27 matthew 9781: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 9782: sub user_search_result {
1.221 raeburn 9783: my ($context,$srch) = @_;
1.160 raeburn 9784: my %allhomes;
9785: my %inst_matches;
9786: my %srch_results;
1.181 raeburn 9787: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 9788: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 9789: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 9790: $response = &mt('Invalid search.');
9791: }
9792: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
9793: $response = &mt('Invalid search.');
9794: }
1.177 raeburn 9795: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 9796: $response = &mt('Invalid search.');
9797: }
9798: if ($srch->{'srchterm'} eq '') {
9799: $response = &mt('You must enter a search term.');
9800: }
1.183 raeburn 9801: if ($srch->{'srchterm'} =~ /^\s+$/) {
9802: $response = &mt('Your search term must contain more than just spaces.');
9803: }
1.160 raeburn 9804: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
9805: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 9806: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 9807: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
9808: }
9809: }
9810: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
9811: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 9812: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 9813: my $unamecheck = $srch->{'srchterm'};
9814: if ($srch->{'srchtype'} eq 'contains') {
9815: if ($unamecheck !~ /^\w/) {
9816: $unamecheck = 'a'.$unamecheck;
9817: }
9818: }
9819: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 9820: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
9821: }
1.160 raeburn 9822: }
9823: }
1.180 raeburn 9824: if ($response ne '') {
1.413 raeburn 9825: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 9826: }
1.160 raeburn 9827: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 9828: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 9829: if ($instd_chk ne 'ok') {
1.412 raeburn 9830: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 9831: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 9832: if ($domd_chk eq 'ok') {
1.435 raeburn 9833: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 9834: }
1.415 raeburn 9835: $response .= '<br />';
1.412 raeburn 9836: }
9837: } else {
1.417 raeburn 9838: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 9839: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 9840: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 9841: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 9842: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 9843: if ($instd_chk eq 'ok') {
1.435 raeburn 9844: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 9845: }
1.415 raeburn 9846: $response .= '<br />';
1.412 raeburn 9847: }
1.160 raeburn 9848: }
9849: }
9850: if ($response ne '') {
1.180 raeburn 9851: return ($currstate,$response);
1.160 raeburn 9852: }
9853: if ($srch->{'srchby'} eq 'uname') {
9854: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
9855: if ($env{'form.forcenew'}) {
9856: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
9857: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
9858: if ($uhome eq 'no_host') {
9859: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 9860: my $showdom = &display_domain_info($env{'request.role.domain'});
9861: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 9862: } else {
1.179 raeburn 9863: $currstate = 'modify';
1.160 raeburn 9864: }
9865: } else {
1.179 raeburn 9866: $currstate = 'modify';
1.160 raeburn 9867: }
9868: } else {
9869: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 9870: if ($srch->{'srchtype'} eq 'exact') {
9871: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
9872: if ($uhome eq 'no_host') {
1.179 raeburn 9873: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9874: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 9875: } else {
1.179 raeburn 9876: $currstate = 'modify';
1.416 raeburn 9877: if ($env{'form.action'} eq 'accesslogs') {
9878: $currstate = 'activity';
9879: }
1.310 raeburn 9880: my $uname = $srch->{'srchterm'};
9881: my $udom = $srch->{'srchdomain'};
9882: $srch_results{$uname.':'.$udom} =
9883: { &Apache::lonnet::get('environment',
9884: ['firstname',
9885: 'lastname',
9886: 'permanentemail'],
9887: $udom,$uname)
9888: };
1.162 raeburn 9889: }
9890: } else {
9891: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 9892: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9893: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9894: }
9895: } else {
1.167 albertel 9896: my $courseusers = &get_courseusers();
1.162 raeburn 9897: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 9898: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 9899: $currstate = 'modify';
1.162 raeburn 9900: } else {
1.179 raeburn 9901: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9902: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 9903: }
1.160 raeburn 9904: } else {
1.167 albertel 9905: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 9906: my ($cuname,$cudomain) = split(/:/,$user);
9907: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 9908: my $matched = 0;
9909: if ($srch->{'srchtype'} eq 'begins') {
9910: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
9911: $matched = 1;
9912: }
9913: } else {
9914: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
9915: $matched = 1;
9916: }
9917: }
9918: if ($matched) {
1.167 albertel 9919: $srch_results{$user} =
9920: {&Apache::lonnet::get('environment',
9921: ['firstname',
9922: 'lastname',
1.194 albertel 9923: 'permanentemail'],
9924: $cudomain,$cuname)};
1.162 raeburn 9925: }
9926: }
9927: }
1.179 raeburn 9928: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9929: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9930: }
9931: }
9932: }
9933: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 9934: $currstate = 'query';
1.160 raeburn 9935: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 9936: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
9937: if ($dirsrchres eq 'ok') {
9938: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9939: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 9940: } else {
9941: my $showdom = &display_domain_info($srch->{'srchdomain'});
9942: $response = '<span class="LC_warning">'.
9943: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
9944: '</span><br />'.
1.435 raeburn 9945: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 9946: '<br />';
1.181 raeburn 9947: }
1.160 raeburn 9948: }
9949: } else {
9950: if ($srch->{'srchin'} eq 'dom') {
9951: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 9952: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9953: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9954: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 9955: my $courseusers = &get_courseusers();
9956: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 9957: my ($uname,$udom) = split(/:/,$user);
9958: my %names = &Apache::loncommon::getnames($uname,$udom);
9959: my %emails = &Apache::loncommon::getemails($uname,$udom);
9960: if ($srch->{'srchby'} eq 'lastname') {
9961: if ((($srch->{'srchtype'} eq 'exact') &&
9962: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 9963: (($srch->{'srchtype'} eq 'begins') &&
9964: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 9965: (($srch->{'srchtype'} eq 'contains') &&
9966: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
9967: $srch_results{$user} = {firstname => $names{'firstname'},
9968: lastname => $names{'lastname'},
9969: permanentemail => $emails{'permanentemail'},
9970: };
9971: }
9972: } elsif ($srch->{'srchby'} eq 'lastfirst') {
9973: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 9974: $srchlast =~ s/\s+$//;
9975: $srchfirst =~ s/^\s+//;
1.160 raeburn 9976: if ($srch->{'srchtype'} eq 'exact') {
9977: if (($names{'lastname'} eq $srchlast) &&
9978: ($names{'firstname'} eq $srchfirst)) {
9979: $srch_results{$user} = {firstname => $names{'firstname'},
9980: lastname => $names{'lastname'},
9981: permanentemail => $emails{'permanentemail'},
9982:
9983: };
9984: }
1.177 raeburn 9985: } elsif ($srch->{'srchtype'} eq 'begins') {
9986: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
9987: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
9988: $srch_results{$user} = {firstname => $names{'firstname'},
9989: lastname => $names{'lastname'},
9990: permanentemail => $emails{'permanentemail'},
9991: };
9992: }
9993: } else {
1.160 raeburn 9994: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
9995: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
9996: $srch_results{$user} = {firstname => $names{'firstname'},
9997: lastname => $names{'lastname'},
9998: permanentemail => $emails{'permanentemail'},
9999: };
10000: }
10001: }
10002: }
10003: }
1.179 raeburn 10004: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10005: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 10006: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 10007: $currstate = 'query';
1.160 raeburn 10008: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 10009: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
10010: if ($dirsrchres eq 'ok') {
10011: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10012: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 10013: } else {
1.412 raeburn 10014: my $showdom = &display_domain_info($srch->{'srchdomain'});
10015: $response = '<span class="LC_warning">'.
1.181 raeburn 10016: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
10017: '</span><br />'.
1.435 raeburn 10018: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 10019: '<br />';
1.181 raeburn 10020: }
1.160 raeburn 10021: }
10022: }
1.179 raeburn 10023: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 10024: }
10025:
1.412 raeburn 10026: sub domdirectorysrch_check {
10027: my ($srch) = @_;
10028: my $response;
10029: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
10030: ['directorysrch'],$srch->{'srchdomain'});
10031: my $showdom = &display_domain_info($srch->{'srchdomain'});
10032: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
10033: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
10034: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
10035: }
10036: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
10037: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
10038: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
10039: }
10040: }
10041: }
10042: return 'ok';
10043: }
10044:
10045: sub instdirectorysrch_check {
1.160 raeburn 10046: my ($srch) = @_;
10047: my $can_search = 0;
10048: my $response;
10049: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
10050: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 10051: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 10052: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
10053: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 10054: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 10055: }
10056: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
10057: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 10058: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 10059: }
10060: my @usertypes = split(/:/,$env{'environment.inststatus'});
10061: if (!@usertypes) {
10062: push(@usertypes,'default');
10063: }
10064: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
10065: foreach my $type (@usertypes) {
10066: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
10067: $can_search = 1;
10068: last;
10069: }
10070: }
10071: }
10072: if (!$can_search) {
10073: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
10074: my @longtypes;
10075: foreach my $item (@usertypes) {
1.229 raeburn 10076: if (defined($insttypes->{$item})) {
10077: push (@longtypes,$insttypes->{$item});
10078: } elsif ($item eq 'default') {
10079: push (@longtypes,&mt('other'));
10080: }
1.160 raeburn 10081: }
10082: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 10083: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 10084: }
1.160 raeburn 10085: } else {
10086: $can_search = 1;
10087: }
10088: } else {
1.180 raeburn 10089: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 10090: }
10091: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 10092: uname => 'username',
1.160 raeburn 10093: lastfirst => 'last name, first name',
1.167 albertel 10094: lastname => 'last name',
1.172 raeburn 10095: contains => 'contains',
1.178 raeburn 10096: exact => 'as exact match to',
10097: begins => 'begins with',
1.160 raeburn 10098: );
10099: if ($can_search) {
10100: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
10101: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 10102: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 10103: }
10104: } else {
1.180 raeburn 10105: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 10106: }
10107: }
10108: if ($can_search) {
1.178 raeburn 10109: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
10110: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
10111: return 'ok';
10112: } else {
1.180 raeburn 10113: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 10114: }
10115: } else {
10116: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
10117: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
10118: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
10119: return 'ok';
10120: } else {
1.180 raeburn 10121: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 10122: }
1.160 raeburn 10123: }
10124: }
10125: }
10126:
10127: sub get_courseusers {
10128: my %advhash;
1.167 albertel 10129: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 10130: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
10131: foreach my $role (sort(keys(%coursepersonnel))) {
10132: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 10133: if (!exists($classlist->{$user})) {
10134: $classlist->{$user} = [];
10135: }
1.160 raeburn 10136: }
10137: }
1.167 albertel 10138: return $classlist;
1.160 raeburn 10139: }
10140:
10141: sub build_search_response {
1.221 raeburn 10142: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 10143: my ($currstate,$response,$forcenewuser);
1.160 raeburn 10144: my %names = (
1.330 bisitz 10145: 'uname' => 'username',
10146: 'lastname' => 'last name',
1.160 raeburn 10147: 'lastfirst' => 'last name, first name',
1.330 bisitz 10148: 'crs' => 'this course',
10149: 'dom' => 'LON-CAPA domain',
10150: 'instd' => 'the institutional directory for domain',
1.160 raeburn 10151: );
10152:
10153: my %single = (
1.180 raeburn 10154: begins => 'A match',
1.160 raeburn 10155: contains => 'A match',
1.180 raeburn 10156: exact => 'An exact match',
1.160 raeburn 10157: );
10158: my %nomatch = (
1.180 raeburn 10159: begins => 'No match',
1.160 raeburn 10160: contains => 'No match',
1.180 raeburn 10161: exact => 'No exact match',
1.160 raeburn 10162: );
10163: if (keys(%srch_results) > 1) {
1.179 raeburn 10164: $currstate = 'select';
1.160 raeburn 10165: } else {
10166: if (keys(%srch_results) == 1) {
1.416 raeburn 10167: if ($env{'form.action'} eq 'accesslogs') {
10168: $currstate = 'activity';
10169: } else {
10170: $currstate = 'modify';
10171: }
1.180 raeburn 10172: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
10173: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 10174: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 10175: }
1.330 bisitz 10176: } else { # Search has nothing found. Prepare message to user.
10177: $response = '<span class="LC_warning">';
1.180 raeburn 10178: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 10179: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
10180: '<b>'.$srch->{'srchterm'}.'</b>',
10181: &display_domain_info($srch->{'srchdomain'}));
10182: } else {
10183: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
10184: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 10185: }
10186: $response .= '</span>';
1.330 bisitz 10187:
1.160 raeburn 10188: if ($srch->{'srchin'} ne 'alc') {
10189: $forcenewuser = 1;
10190: my $cansrchinst = 0;
1.438 raeburn 10191: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 10192: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
10193: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10194: if ($domconfig{'directorysrch'}{'available'}) {
10195: $cansrchinst = 1;
10196: }
10197: }
10198: }
1.180 raeburn 10199: if ((($srch->{'srchby'} eq 'lastfirst') ||
10200: ($srch->{'srchby'} eq 'lastname')) &&
10201: ($srch->{'srchin'} eq 'dom')) {
10202: if ($cansrchinst) {
10203: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 10204: }
10205: }
1.180 raeburn 10206: if ($srch->{'srchin'} eq 'crs') {
10207: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
10208: }
10209: }
1.305 raeburn 10210: my $createdom = $env{'request.role.domain'};
10211: if ($context eq 'requestcrs') {
10212: if ($env{'form.coursedom'} ne '') {
10213: $createdom = $env{'form.coursedom'};
10214: }
10215: }
1.416 raeburn 10216: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
10217: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 10218: my $cancreate =
1.305 raeburn 10219: &Apache::lonuserutils::can_create_user($createdom,$context);
10220: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 10221: if ($cancreate) {
1.305 raeburn 10222: my $showdom = &display_domain_info($createdom);
1.266 bisitz 10223: $response .= '<br /><br />'
10224: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 10225: .'<br />';
10226: if ($context eq 'requestcrs') {
10227: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
10228: } else {
10229: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
10230: }
10231: $response .='<ul><li>'
1.266 bisitz 10232: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
10233: .'</li><li>'
10234: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
10235: .'</li><li>'
10236: .&mt('Provide the proposed username')
10237: .'</li><li>'
10238: .&mt("Click 'Search'")
10239: .'</li></ul><br />';
1.221 raeburn 10240: } else {
1.422 raeburn 10241: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
10242: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
10243: $response .= '<br /><br />';
10244: if ($context eq 'requestcrs') {
10245: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
10246: } else {
10247: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
10248: }
10249: $response .= '<br />'
10250: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
10251: ,' <a'.$helplink.'>'
10252: ,'</a>')
10253: .'<br />';
1.305 raeburn 10254: }
1.221 raeburn 10255: }
1.160 raeburn 10256: }
10257: }
10258: }
1.179 raeburn 10259: return ($currstate,$response,$forcenewuser);
1.160 raeburn 10260: }
10261:
1.180 raeburn 10262: sub display_domain_info {
10263: my ($dom) = @_;
10264: my $output = $dom;
10265: if ($dom ne '') {
10266: my $domdesc = &Apache::lonnet::domain($dom,'description');
10267: if ($domdesc ne '') {
10268: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
10269: }
10270: }
10271: return $output;
10272: }
10273:
1.160 raeburn 10274: sub crumb_utilities {
10275: my %elements = (
10276: crtuser => {
10277: srchterm => 'text',
1.172 raeburn 10278: srchin => 'selectbox',
1.160 raeburn 10279: srchby => 'selectbox',
10280: srchtype => 'selectbox',
10281: srchdomain => 'selectbox',
10282: },
1.207 raeburn 10283: crtusername => {
10284: srchterm => 'text',
10285: srchdomain => 'selectbox',
10286: },
1.160 raeburn 10287: docustom => {
10288: rolename => 'selectbox',
10289: newrolename => 'textbox',
10290: },
1.179 raeburn 10291: studentform => {
10292: srchterm => 'text',
10293: srchin => 'selectbox',
10294: srchby => 'selectbox',
10295: srchtype => 'selectbox',
10296: srchdomain => 'selectbox',
10297: },
1.160 raeburn 10298: );
10299:
10300: my $jsback .= qq|
10301: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 10302: if (typeof prevphase == 'undefined') {
10303: formname.phase.value = '';
10304: }
10305: else {
10306: formname.phase.value = prevphase;
10307: }
10308: if (typeof prevstate == 'undefined') {
10309: formname.currstate.value = '';
10310: }
10311: else {
10312: formname.currstate.value = prevstate;
10313: }
1.160 raeburn 10314: formname.submit();
10315: }
10316: |;
10317: return ($jsback,\%elements);
10318: }
10319:
1.26 matthew 10320: sub course_level_table {
1.375 raeburn 10321: my ($inccourses,$showcredits,$defaultcredits) = @_;
10322: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 10323: my $table = '';
1.62 www 10324: # Custom Roles?
10325:
1.190 raeburn 10326: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 10327: my %lt=&Apache::lonlocal::texthash(
10328: 'exs' => "Existing sections",
10329: 'new' => "Define new section",
10330: 'ssd' => "Set Start Date",
10331: 'sed' => "Set End Date",
1.131 raeburn 10332: 'crl' => "Course Level",
1.89 raeburn 10333: 'act' => "Activate",
10334: 'rol' => "Role",
10335: 'ext' => "Extent",
1.113 raeburn 10336: 'grs' => "Section",
1.375 raeburn 10337: 'crd' => "Credits",
1.89 raeburn 10338: 'sta' => "Start",
10339: 'end' => "End"
10340: );
1.62 www 10341:
1.375 raeburn 10342: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 10343: my $thiscourse=$protectedcourse;
1.26 matthew 10344: $thiscourse=~s:_:/:g;
10345: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 10346: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 10347: my $area=$coursedata{'description'};
1.321 raeburn 10348: my $crstype=$coursedata{'type'};
1.135 raeburn 10349: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 10350: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 10351: my %sections_count;
1.101 albertel 10352: if (defined($env{'request.course.id'})) {
10353: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 10354: %sections_count =
10355: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 10356: }
10357: }
1.321 raeburn 10358: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 10359: foreach my $role (@roles) {
1.321 raeburn 10360: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 10361: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
10362: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 10363: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 10364: $plrole,\%sections_count,\%lt,
1.402 raeburn 10365: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 10366: } elsif ($env{'request.course.sec'} ne '') {
10367: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
10368: $env{'request.course.sec'})) {
10369: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 10370: $plrole,\%sections_count,\%lt,
1.402 raeburn 10371: $showcredits,$defaultcredits,$crstype);
1.26 matthew 10372: }
10373: }
10374: }
1.221 raeburn 10375: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 10376: foreach my $cust (sort(keys(%customroles))) {
10377: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 10378: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
10379: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 10380: $cust,\%sections_count,\%lt,
10381: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 10382: }
1.62 www 10383: }
1.26 matthew 10384: }
10385: return '' if ($table eq ''); # return nothing if there is nothing
10386: # in the table
1.188 raeburn 10387: my $result;
10388: if (!$env{'request.course.id'}) {
10389: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
10390: }
10391: $result .=
1.136 raeburn 10392: &Apache::loncommon::start_data_table().
10393: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 10394: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 10395: '<th>'.$lt{'ext'}.'</th><th>'."\n";
10396: if ($showcredits) {
10397: $result .= $lt{'crd'}.'</th>';
10398: }
10399: $result .=
1.375 raeburn 10400: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
10401: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 10402: &Apache::loncommon::end_data_table_header_row().
10403: $table.
10404: &Apache::loncommon::end_data_table();
1.26 matthew 10405: return $result;
10406: }
1.88 raeburn 10407:
1.221 raeburn 10408: sub course_level_row {
1.375 raeburn 10409: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 10410: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 10411: my $creditem;
1.222 raeburn 10412: my $row = &Apache::loncommon::start_data_table_row().
10413: ' <td><input type="checkbox" name="act_'.
10414: $protectedcourse.'_'.$role.'" /></td>'."\n".
10415: ' <td>'.$plrole.'</td>'."\n".
10416: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 10417: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 10418: $row .=
10419: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
10420: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
10421: } else {
10422: $row .= '<td> </td>';
10423: }
1.322 raeburn 10424: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 10425: $row .= '<td> </td>';
1.221 raeburn 10426: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 10427: $row .= ' <td><input type="hidden" value="'.
10428: $env{'request.course.sec'}.'" '.
10429: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
10430: $env{'request.course.sec'}.'</td>';
1.221 raeburn 10431: } else {
10432: if (ref($sections_count) eq 'HASH') {
10433: my $currsec =
10434: &Apache::lonuserutils::course_sections($sections_count,
10435: $protectedcourse.'_'.$role);
1.222 raeburn 10436: $row .= '<td><table class="LC_createuser">'."\n".
10437: '<tr class="LC_section_row">'."\n".
10438: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
10439: $currsec.'</td>'."\n".
10440: ' <td> </td>'."\n".
10441: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 10442: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
10443: '" value="" />'.
10444: '<input type="hidden" '.
10445: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 10446: '</tr></table></td>'."\n";
1.221 raeburn 10447: } else {
1.222 raeburn 10448: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 10449: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 10450: }
10451: }
1.222 raeburn 10452: $row .= <<ENDTIMEENTRY;
10453: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 10454: <a href=
10455: "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 10456: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 10457: <a href=
10458: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
10459: ENDTIMEENTRY
1.222 raeburn 10460: $row .= &Apache::loncommon::end_data_table_row();
10461: return $row;
1.221 raeburn 10462: }
10463:
1.88 raeburn 10464: sub course_level_dc {
1.375 raeburn 10465: my ($dcdom,$showcredits) = @_;
1.190 raeburn 10466: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 10467: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 10468: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
10469: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 10470: '<input type="hidden" name="dccourse" value="" />';
1.355 www 10471: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 10472: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 10473: my $credit_elem;
10474: if ($showcredits) {
10475: $credit_elem = 'credits';
10476: }
10477: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 10478: my %lt=&Apache::lonlocal::texthash(
10479: 'rol' => "Role",
1.113 raeburn 10480: 'grs' => "Section",
1.88 raeburn 10481: 'exs' => "Existing sections",
10482: 'new' => "Define new section",
10483: 'sta' => "Start",
10484: 'end' => "End",
10485: 'ssd' => "Set Start Date",
1.355 www 10486: 'sed' => "Set End Date",
1.375 raeburn 10487: 'scc' => "Course/Community",
10488: 'crd' => "Credits",
1.88 raeburn 10489: );
1.323 raeburn 10490: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 10491: &Apache::loncommon::start_data_table().
10492: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 10493: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 10494: '<th>'.$lt{'grs'}.'</th>'."\n";
10495: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
10496: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 10497: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 10498: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 10499: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
10500: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 10501: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 10502: foreach my $role (@roles) {
1.135 raeburn 10503: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 10504: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 10505: }
1.404 raeburn 10506: if ( keys(%customroles) > 0) {
10507: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 10508: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 10509: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 10510: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 10511: }
10512: }
10513: $otheritems .= '</select></td><td>'.
10514: '<table border="0" cellspacing="0" cellpadding="0">'.
10515: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 10516: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 10517: '<td> </td>'.
10518: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 10519: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 10520: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 10521: '<input type="hidden" name="groups" value="" />'.
10522: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 10523: '</tr></table></td>'."\n";
10524: if ($showcredits) {
10525: $otheritems .= '<td><br />'."\n".
1.397 bisitz 10526: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 10527: }
1.88 raeburn 10528: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 10529: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 10530: <a href=
10531: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 10532: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 10533: <a href=
10534: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
10535: ENDTIMEENTRY
1.136 raeburn 10536: $otheritems .= &Apache::loncommon::end_data_table_row().
10537: &Apache::loncommon::end_data_table()."\n";
1.470 raeburn 10538: return $cb_jscript.$hiddenitems.$header.$otheritems;
1.88 raeburn 10539: }
10540:
1.237 raeburn 10541: sub update_selfenroll_config {
1.400 raeburn 10542: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 10543: return unless (ref($currsettings) eq 'HASH');
10544: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
10545: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 10546: my (%changes,%warning);
1.241 raeburn 10547: my $curr_types;
1.400 raeburn 10548: my %noedit;
10549: unless ($context eq 'domain') {
10550: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
10551: }
1.237 raeburn 10552: if (ref($row) eq 'ARRAY') {
10553: foreach my $item (@{$row}) {
1.400 raeburn 10554: next if ($noedit{$item});
1.237 raeburn 10555: if ($item eq 'enroll_dates') {
10556: my (%currenrolldate,%newenrolldate);
10557: foreach my $type ('start','end') {
1.398 raeburn 10558: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 10559: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
10560: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
10561: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
10562: }
10563: }
10564: } elsif ($item eq 'access_dates') {
10565: my (%currdate,%newdate);
10566: foreach my $type ('start','end') {
1.398 raeburn 10567: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 10568: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
10569: if ($newdate{$type} ne $currdate{$type}) {
10570: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
10571: }
10572: }
1.241 raeburn 10573: } elsif ($item eq 'types') {
1.398 raeburn 10574: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 10575: if ($env{'form.selfenroll_all'}) {
10576: if ($curr_types ne '*') {
10577: $changes{'internal.selfenroll_types'} = '*';
10578: } else {
10579: next;
10580: }
10581: } else {
1.249 raeburn 10582: my %currdoms;
1.241 raeburn 10583: my @entries = split(/;/,$curr_types);
10584: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 10585: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 10586: my $newnum = 0;
1.249 raeburn 10587: my @latesttypes;
10588: foreach my $num (@activations) {
10589: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
10590: if (@types > 0) {
1.241 raeburn 10591: @types = sort(@types);
10592: my $typestr = join(',',@types);
1.249 raeburn 10593: my $typedom = $env{'form.selfenroll_dom_'.$num};
10594: $latesttypes[$newnum] = $typedom.':'.$typestr;
10595: $currdoms{$typedom} = 1;
1.241 raeburn 10596: $newnum ++;
10597: }
10598: }
1.338 raeburn 10599: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
10600: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 10601: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
10602: if (@types > 0) {
10603: @types = sort(@types);
10604: my $typestr = join(',',@types);
10605: my $typedom = $env{'form.selfenroll_dom_'.$j};
10606: $latesttypes[$newnum] = $typedom.':'.$typestr;
10607: $currdoms{$typedom} = 1;
10608: $newnum ++;
10609: }
10610: }
10611: }
10612: if ($env{'form.selfenroll_newdom'} ne '') {
10613: my $typedom = $env{'form.selfenroll_newdom'};
10614: if ((!defined($currdoms{$typedom})) &&
10615: (&Apache::lonnet::domain($typedom) ne '')) {
10616: my $typestr;
10617: my ($othertitle,$usertypes,$types) =
10618: &Apache::loncommon::sorted_inst_types($typedom);
10619: my $othervalue = 'any';
10620: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
10621: if (@{$types} > 0) {
1.257 raeburn 10622: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 10623: $othervalue = 'other';
1.258 raeburn 10624: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 10625: }
10626: $typestr = $othervalue;
10627: } else {
10628: $typestr = $othervalue;
10629: }
10630: $latesttypes[$newnum] = $typedom.':'.$typestr;
10631: $newnum ++ ;
10632: }
10633: }
1.241 raeburn 10634: my $selfenroll_types = join(';',@latesttypes);
10635: if ($selfenroll_types ne $curr_types) {
10636: $changes{'internal.selfenroll_types'} = $selfenroll_types;
10637: }
10638: }
1.276 raeburn 10639: } elsif ($item eq 'limit') {
10640: my $newlimit = $env{'form.selfenroll_limit'};
10641: my $newcap = $env{'form.selfenroll_cap'};
10642: $newcap =~s/\s+//g;
1.398 raeburn 10643: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 10644: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 10645: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 10646: if ($newlimit ne $currlimit) {
10647: if ($newlimit ne 'none') {
10648: if ($newcap =~ /^\d+$/) {
10649: if ($newcap ne $currcap) {
10650: $changes{'internal.selfenroll_cap'} = $newcap;
10651: }
10652: $changes{'internal.selfenroll_limit'} = $newlimit;
10653: } else {
1.398 raeburn 10654: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
10655: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 10656: }
10657: } elsif ($currcap ne '') {
10658: $changes{'internal.selfenroll_cap'} = '';
10659: $changes{'internal.selfenroll_limit'} = $newlimit;
10660: }
10661: } elsif ($currlimit ne 'none') {
10662: if ($newcap =~ /^\d+$/) {
10663: if ($newcap ne $currcap) {
10664: $changes{'internal.selfenroll_cap'} = $newcap;
10665: }
10666: } else {
1.398 raeburn 10667: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
10668: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 10669: }
10670: }
10671: } elsif ($item eq 'approval') {
10672: my (@currnotified,@newnotified);
1.398 raeburn 10673: my $currapproval = $currsettings->{'selfenroll_approval'};
10674: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 10675: if ($currnotifylist ne '') {
10676: @currnotified = split(/,/,$currnotifylist);
10677: @currnotified = sort(@currnotified);
10678: }
10679: my $newapproval = $env{'form.selfenroll_approval'};
10680: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
10681: @newnotified = sort(@newnotified);
10682: if ($newapproval ne $currapproval) {
10683: $changes{'internal.selfenroll_approval'} = $newapproval;
10684: if (!$newapproval) {
10685: if ($currnotifylist ne '') {
10686: $changes{'internal.selfenroll_notifylist'} = '';
10687: }
10688: } else {
10689: my @differences =
1.295 raeburn 10690: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 10691: if (@differences > 0) {
10692: if (@newnotified > 0) {
10693: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10694: } else {
10695: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10696: }
10697: }
10698: }
10699: } else {
1.295 raeburn 10700: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 10701: if (@differences > 0) {
10702: if (@newnotified > 0) {
10703: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10704: } else {
10705: $changes{'internal.selfenroll_notifylist'} = '';
10706: }
10707: }
10708: }
1.237 raeburn 10709: } else {
1.398 raeburn 10710: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 10711: my $newval = $env{'form.selfenroll_'.$item};
10712: if ($item eq 'section') {
10713: $newval = $env{'form.sections'};
1.241 raeburn 10714: if (defined($curr_groups{$newval})) {
1.237 raeburn 10715: $newval = $curr_val;
1.398 raeburn 10716: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
10717: &mt('Group names and section names must be distinct');
1.237 raeburn 10718: } elsif ($newval eq 'all') {
10719: $newval = $curr_val;
1.274 bisitz 10720: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 10721: }
10722: if ($newval eq '') {
10723: $newval = 'none';
10724: }
10725: }
10726: if ($newval ne $curr_val) {
10727: $changes{'internal.selfenroll_'.$item} = $newval;
10728: }
1.241 raeburn 10729: }
1.237 raeburn 10730: }
10731: if (keys(%warning) > 0) {
10732: foreach my $item (@{$row}) {
10733: if (exists($warning{$item})) {
10734: $r->print($warning{$item}.'<br />');
10735: }
10736: }
10737: }
10738: if (keys(%changes) > 0) {
10739: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
10740: if ($putresult eq 'ok') {
10741: if ((exists($changes{'internal.selfenroll_types'})) ||
10742: (exists($changes{'internal.selfenroll_start_date'})) ||
10743: (exists($changes{'internal.selfenroll_end_date'}))) {
10744: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
10745: $cnum,undef,undef,'Course');
10746: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 10747: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 10748: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
10749: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 10750: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 10751: }
10752: }
10753: my $crsputresult =
10754: &Apache::lonnet::courseidput($cdom,\%crsinfo,
10755: $chome,'notime');
10756: }
10757: }
10758: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
10759: foreach my $item (@{$row}) {
10760: my $title = $item;
10761: if (ref($lt) eq 'HASH') {
10762: $title = $lt->{$item};
10763: }
10764: if ($item eq 'enroll_dates') {
10765: foreach my $type ('start','end') {
10766: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
10767: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 10768: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 10769: $title,$type,$newdate).'</li>');
10770: }
10771: }
10772: } elsif ($item eq 'access_dates') {
10773: foreach my $type ('start','end') {
10774: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
10775: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 10776: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 10777: $title,$type,$newdate).'</li>');
10778: }
10779: }
1.276 raeburn 10780: } elsif ($item eq 'limit') {
10781: if ((exists($changes{'internal.selfenroll_limit'})) ||
10782: (exists($changes{'internal.selfenroll_cap'}))) {
10783: my ($newval,$newcap);
10784: if ($changes{'internal.selfenroll_cap'} ne '') {
10785: $newcap = $changes{'internal.selfenroll_cap'}
10786: } else {
1.398 raeburn 10787: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 10788: }
10789: if ($changes{'internal.selfenroll_limit'} eq 'none') {
10790: $newval = &mt('No limit');
10791: } elsif ($changes{'internal.selfenroll_limit'} eq
10792: 'allstudents') {
10793: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
10794: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
10795: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
10796: } else {
1.398 raeburn 10797: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 10798: if ($currlimit eq 'allstudents') {
10799: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
10800: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 10801: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 10802: }
10803: }
10804: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
10805: }
10806: } elsif ($item eq 'approval') {
10807: if ((exists($changes{'internal.selfenroll_approval'})) ||
10808: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 10809: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 10810: my ($newval,$newnotify);
10811: if (exists($changes{'internal.selfenroll_notifylist'})) {
10812: $newnotify = $changes{'internal.selfenroll_notifylist'};
10813: } else {
1.398 raeburn 10814: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 10815: }
1.398 raeburn 10816: if (exists($changes{'internal.selfenroll_approval'})) {
10817: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
10818: $changes{'internal.selfenroll_approval'} = '0';
10819: }
10820: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 10821: } else {
1.398 raeburn 10822: my $currapproval = $currsettings->{'selfenroll_approval'};
10823: if ($currapproval !~ /^[012]$/) {
10824: $currapproval = 0;
1.276 raeburn 10825: }
1.398 raeburn 10826: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 10827: }
10828: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
10829: if ($newnotify) {
1.277 raeburn 10830: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 10831: } else {
1.277 raeburn 10832: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 10833: }
10834: $r->print('</li>'."\n");
10835: }
1.237 raeburn 10836: } else {
10837: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 10838: my $newval = $changes{'internal.selfenroll_'.$item};
10839: if ($item eq 'types') {
10840: if ($newval eq '') {
10841: $newval = &mt('None');
10842: } elsif ($newval eq '*') {
10843: $newval = &mt('Any user in any domain');
10844: }
1.245 raeburn 10845: } elsif ($item eq 'registered') {
10846: if ($newval eq '1') {
10847: $newval = &mt('Yes');
10848: } elsif ($newval eq '0') {
10849: $newval = &mt('No');
10850: }
1.241 raeburn 10851: }
1.244 bisitz 10852: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 10853: }
10854: }
10855: }
10856: $r->print('</ul>');
1.398 raeburn 10857: if ($env{'course.'.$cid.'.description'} ne '') {
10858: my %newenvhash;
10859: foreach my $key (keys(%changes)) {
10860: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
10861: }
10862: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 10863: }
10864: } else {
1.398 raeburn 10865: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
10866: &mt('The error was: [_1].',$putresult));
1.237 raeburn 10867: }
10868: } else {
1.249 raeburn 10869: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 10870: }
10871: } else {
1.249 raeburn 10872: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 10873: }
1.469 raeburn 10874: my $visactions = &cat_visibility($cdom);
1.400 raeburn 10875: my ($cathash,%cattype);
10876: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
10877: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
10878: $cathash = $domconfig{'coursecategories'}{'cats'};
10879: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
10880: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
10881: } else {
10882: $cathash = {};
10883: $cattype{'auth'} = 'std';
10884: $cattype{'unauth'} = 'std';
10885: }
10886: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
10887: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
10888: '<br />'.
10889: '<br />'.$visactions->{'take'}.'<ul>'.
10890: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
10891: '</ul>');
10892: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
10893: if ($currsettings->{'uniquecode'}) {
10894: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
10895: } else {
1.366 bisitz 10896: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 10897: '<br />'.
10898: '<br />'.$visactions->{'take'}.'<ul>'.
10899: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
10900: '</ul><br />');
10901: }
10902: } else {
10903: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
10904: if (ref($visactions) eq 'HASH') {
10905: if (!$visible) {
10906: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
10907: '<br />');
10908: if (ref($vismsgs) eq 'ARRAY') {
10909: $r->print('<br />'.$visactions->{'take'}.'<ul>');
10910: foreach my $item (@{$vismsgs}) {
10911: $r->print('<li>'.$visactions->{$item}.'</li>');
10912: }
10913: $r->print('</ul>');
1.256 raeburn 10914: }
1.400 raeburn 10915: $r->print($cansetvis);
1.256 raeburn 10916: }
10917: }
10918: }
1.237 raeburn 10919: return;
10920: }
10921:
1.27 matthew 10922: #---------------------------------------------- end functions for &phase_two
1.29 matthew 10923:
10924: #--------------------------------- functions for &phase_two and &phase_three
10925:
10926: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 10927:
1.1 www 10928: 1;
10929: __END__
1.2 www 10930:
10931:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>