Annotation of loncom/interface/loncreateuser.pm, revision 1.481
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.481 ! raeburn 4: # $Id: loncreateuser.pm,v 1.480 2024/05/21 02:57:15 raeburn Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
1.324 raeburn 54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
1.66 bowersj2 59:
1.324 raeburn 60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
1.66 bowersj2 62:
63: =cut
1.1 www 64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
1.54 bowersj2 68: use Apache::loncommon;
1.68 www 69: use Apache::lonlocal;
1.117 raeburn 70: use Apache::longroup;
1.190 raeburn 71: use Apache::lonuserutils;
1.307 raeburn 72: use Apache::loncoursequeueadmin;
1.470 raeburn 73: use Apache::lonviewcoauthors;
1.139 albertel 74: use LONCAPA qw(:DEFAULT :match);
1.456 raeburn 75: use HTML::Entities;
1.1 www 76:
1.20 harris41 77: my $loginscript; # piece of javascript used in two separate instances
78: my $authformnop;
79: my $authformkrb;
80: my $authformint;
81: my $authformfsys;
82: my $authformloc;
1.449 raeburn 83: my $authformlti;
1.20 harris41 84:
1.94 matthew 85: sub initialize_authen_forms {
1.470 raeburn 86: my ($dom,$formname,$curr_authtype,$mode,$readonly) = @_;
1.227 raeburn 87: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
88: my %param = ( formname => $formname,
1.187 raeburn 89: kerb_def_dom => $krbdefdom,
1.227 raeburn 90: kerb_def_auth => $krbdef,
1.187 raeburn 91: domain => $dom,
92: );
1.188 raeburn 93: my %abv_auth = &auth_abbrev();
1.449 raeburn 94: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix|lti):(.*)$/) {
1.188 raeburn 95: my $long_auth = $1;
1.227 raeburn 96: my $curr_autharg = $2;
1.188 raeburn 97: my %abv_auth = &auth_abbrev();
98: $param{'curr_authtype'} = $abv_auth{$long_auth};
99: if ($long_auth =~ /^krb(4|5)$/) {
100: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 101: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 102: }
1.205 raeburn 103: if ($mode eq 'modifyuser') {
104: $param{'mode'} = $mode;
105: }
1.187 raeburn 106: }
1.470 raeburn 107: if ($readonly) {
108: $param{'readonly'} = 1;
109: }
1.227 raeburn 110: $loginscript = &Apache::loncommon::authform_header(%param);
111: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 112: $authformnop = &Apache::loncommon::authform_nochange(%param);
113: $authformint = &Apache::loncommon::authform_internal(%param);
114: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
115: $authformloc = &Apache::loncommon::authform_local(%param);
1.449 raeburn 116: $authformlti = &Apache::loncommon::authform_lti(%param);
1.20 harris41 117: }
118:
1.188 raeburn 119: sub auth_abbrev {
120: my %abv_auth = (
1.368 raeburn 121: krb5 => 'krb',
122: krb4 => 'krb',
123: internal => 'int',
124: localauth => 'loc',
125: unix => 'fsys',
1.449 raeburn 126: lti => 'lti',
1.188 raeburn 127: );
128: return %abv_auth;
129: }
1.43 www 130:
1.134 raeburn 131: # ====================================================
132:
1.378 raeburn 133: sub user_quotas {
1.470 raeburn 134: my ($ccuname,$ccdomain,$name) = @_;
1.134 raeburn 135: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 136: 'cust' => "Custom quota",
137: 'chqu' => "Change quota",
1.134 raeburn 138: );
1.470 raeburn 139: my ($output,$longinsttype);
140: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
141: my %titles = &Apache::lonlocal::texthash (
142: portfolio => "Disk space allocated to user's portfolio files",
143: author => "Disk space allocated to user's Authoring Space",
144: );
145: my ($currquota,$quotatype,$inststatus,$defquota) =
146: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
147: if ($longinsttype eq '') {
148: if ($inststatus ne '') {
149: if ($usertypes->{$inststatus} ne '') {
150: $longinsttype = $usertypes->{$inststatus};
151: }
152: }
153: }
154: my ($showquota,$custom_on,$custom_off,$defaultinfo,$colspan);
155: $custom_on = ' ';
156: $custom_off = ' checked="checked" ';
157: $colspan = ' colspan="2"';
158: if ($quotatype eq 'custom') {
159: $custom_on = $custom_off;
160: $custom_off = ' ';
161: $showquota = $currquota;
162: if ($longinsttype eq '') {
163: $defaultinfo = &mt('For this user, the default quota would be [_1]'
164: .' MB.',$defquota);
165: } else {
166: $defaultinfo = &mt("For this user, the default quota would be [_1]".
167: " MB,[_2]as determined by the user's institutional".
168: " affiliation ([_3]).",$defquota,'<br />',$longinsttype);
169: }
170: } else {
171: if ($longinsttype eq '') {
172: $defaultinfo = &mt('For this user, the default quota is [_1]'
173: .' MB.',$defquota);
174: } else {
175: $defaultinfo = &mt("For this user, the default quota of [_1]".
176: " MB,[_2]is determined by the user's institutional".
177: " affiliation ([_3]).",$defquota,'<br />'.$longinsttype);
178: }
179: }
180:
181: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
182: $output .= '<tr class="LC_info_row">'."\n".
183: ' <td'.$colspan.'>'.$titles{$name}.'</td>'."\n".
184: ' </tr>'."\n".
185: &Apache::loncommon::start_data_table_row()."\n".
186: ' <td'.$colspan.'><span class="LC_nobreak">'.
187: &mt('Current quota: [_1] MB',$currquota).'</span> '.
188: $defaultinfo.'</td>'."\n".
189: &Apache::loncommon::end_data_table_row()."\n".
190: &Apache::loncommon::start_data_table_row()."\n".
191: '<td'.$colspan.'><span class="LC_nobreak">'.$lt{'chqu'}.
192: ': <label>'.
193: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
194: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
195: ' /><span class="LC_nobreak">'.
196: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
197: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
198: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
199: ' />'.$lt{'cust'}.':</label> '.
200: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
201: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
202: ' /> '.&mt('MB').'</span></td>'."\n".
203: &Apache::loncommon::end_data_table_row()."\n";
204: }
205: return $output;
206: }
207:
208: sub user_quota_js {
209: return <<"END_SCRIPT";
1.149 raeburn 210: <script type="text/javascript">
1.301 bisitz 211: // <![CDATA[
1.378 raeburn 212: function quota_changes(caller,context) {
213: var customoff = document.getElementById('custom_'+context+'quota_off');
214: var customon = document.getElementById('custom_'+context+'quota_on');
215: var number = document.getElementById(context+'quota');
1.149 raeburn 216: if (caller == "custom") {
1.378 raeburn 217: if (customoff) {
218: if (customoff.checked) {
219: number.value = "";
220: }
1.149 raeburn 221: }
222: }
223: if (caller == "quota") {
1.378 raeburn 224: if (customon) {
225: customon.checked = true;
226: }
1.149 raeburn 227: }
1.378 raeburn 228: return;
1.149 raeburn 229: }
1.301 bisitz 230: // ]]>
1.149 raeburn 231: </script>
232: END_SCRIPT
1.378 raeburn 233:
1.470 raeburn 234: }
235:
236: sub set_custom_js {
237: return <<"END_SCRIPT";
238:
239: <script type="text/javascript">
240: // <![CDATA[
241: function toggleCustom(form,item,name) {
242: if (document.getElementById(item)) {
243: var divid = document.getElementById(item);
244: var radioname = form.elements[name];
245: if (radioname) {
246: if (radioname.length > 0) {
247: var setvis;
1.478 raeburn 248: var RegExp = /^customtext_(aboutme|blog|portfolio|portaccess|timezone|webdav|archive)\$/;
1.470 raeburn 249: for (var i=0; i<radioname.length; i++) {
250: if (radioname[i].checked == true) {
251: if (radioname[i].value == 1) {
1.476 raeburn 252: if (RegExp.test(item)) {
253: divid.style.display = 'inline';
254: } else {
255: divid.style.display = 'block';
256: }
1.470 raeburn 257: setvis = 1;
258: }
259: break;
260: }
261: }
262: if (!setvis) {
263: divid.style.display = 'none';
1.378 raeburn 264: }
265: }
266: }
1.470 raeburn 267: }
268: return;
269: }
270: // ]]>
271: </script>
272:
273: END_SCRIPT
1.378 raeburn 274:
1.134 raeburn 275: }
276:
1.275 raeburn 277: sub build_tools_display {
278: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 279: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.470 raeburn 280: $colspan,$isadv,%domconfig,@defaulteditors,@customeditors,@custommanagers,
1.475 raeburn 281: @possmanagers);
1.275 raeburn 282: my %lt = &Apache::lonlocal::texthash (
283: 'blog' => "Personal User Blog",
284: 'aboutme' => "Personal Information Page",
1.470 raeburn 285: 'webdav' => "WebDAV access to Authoring Spaces (https)",
286: 'editors' => "Available Editors",
1.473 raeburn 287: 'managers' => "Co-authors who can add/revoke roles",
1.479 raeburn 288: 'archive' => "Managers can download tar.gz file of Authoring Space",
1.275 raeburn 289: 'portfolio' => "Personal User Portfolio",
1.470 raeburn 290: 'portaccess' => "Portfolio Shareable",
1.459 raeburn 291: 'timezone' => "Can set Time Zone",
1.275 raeburn 292: 'avai' => "Available",
293: 'cusa' => "availability",
294: 'chse' => "Change setting",
295: 'usde' => "Use default",
296: 'uscu' => "Use custom",
297: 'official' => 'Can request creation of official courses',
1.299 raeburn 298: 'unofficial' => 'Can request creation of unofficial courses',
299: 'community' => 'Can request creation of communities',
1.384 raeburn 300: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 301: 'placement' => 'Can request creation of placement tests',
1.449 raeburn 302: 'lti' => 'Can request creation of LTI courses',
1.362 raeburn 303: 'requestauthor' => 'Can request author space',
1.470 raeburn 304: 'edit' => 'Standard editor (Edit)',
305: 'xml' => 'Text editor (EditXML)',
306: 'daxe' => 'Daxe editor (Daxe)',
1.275 raeburn 307: );
1.462 raeburn 308: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.279 raeburn 309: if ($context eq 'requestcourses') {
1.275 raeburn 310: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 311: 'requestcourses.official','requestcourses.unofficial',
1.411 raeburn 312: 'requestcourses.community','requestcourses.textbook',
1.449 raeburn 313: 'requestcourses.placement','requestcourses.lti');
314: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.309 raeburn 315: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 316: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
317: %reqtitles = &courserequest_titles();
318: %reqdisplay = &courserequest_display();
1.332 raeburn 319: %domconfig =
320: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.362 raeburn 321: } elsif ($context eq 'requestauthor') {
1.470 raeburn 322: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,'requestauthor');
1.362 raeburn 323: @usertools = ('requestauthor');
324: @options =('norequest','approval','automatic');
325: %reqtitles = &requestauthor_titles();
326: %reqdisplay = &requestauthor_display();
327: %domconfig =
328: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.470 raeburn 329: } elsif ($context eq 'authordefaults') {
330: %domconfig =
331: &Apache::lonnet::get_dom('configuration',['quotas','authordefaults'],$ccdomain);
332: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,'tools.webdav',
1.471 raeburn 333: 'authoreditors','authormanagers',
1.477 raeburn 334: 'authorarchive','domcoord.author');
335: @usertools = ('webdav','editors','managers','archive');
1.470 raeburn 336: $colspan = ' colspan="2"';
1.275 raeburn 337: } else {
338: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 339: 'tools.aboutme','tools.portfolio','tools.blog',
1.470 raeburn 340: 'tools.timezone','tools.portaccess');
341: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
342: $colspan = ' colspan="2"';
1.275 raeburn 343: }
344: foreach my $item (@usertools) {
1.306 raeburn 345: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
1.475 raeburn 346: $currdisp,$custdisp,$custradio,$onclick,$customsty,$editorsty);
1.275 raeburn 347: $cust_off = 'checked="checked" ';
348: $tool_on = 'checked="checked" ';
1.477 raeburn 349: unless (($context eq 'authordefaults') || ($item eq 'webdav')) {
1.474 raeburn 350: $curr_access =
351: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
352: $context,\%userenv,'',
353: {'is_adv' => $isadv});
354: }
1.362 raeburn 355: if ($context eq 'requestauthor') {
356: if ($userenv{$context} ne '') {
357: $cust_on = ' checked="checked" ';
358: $cust_off = '';
1.470 raeburn 359: }
360: } elsif ($context eq 'authordefaults') {
1.477 raeburn 361: if (($item eq 'editors') || ($item eq 'archive')) {
1.470 raeburn 362: if ($userenv{'author'.$item} ne '') {
363: $cust_on = ' checked="checked" ';
364: $cust_off = '';
1.478 raeburn 365: if ($item eq 'archive') {
366: $curr_access = $userenv{'author'.$item};
367: }
368: } elsif ($item eq 'archive') {
369: $curr_access = 0;
370: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
371: $curr_access = $domconfig{'authordefaults'}{'archive'};
372: }
1.470 raeburn 373: }
374: } elsif ($item eq 'webdav') {
375: if ($userenv{'tools.'.$item} ne '') {
376: $cust_on = ' checked="checked" ';
377: $cust_off = '';
378: }
379: }
1.362 raeburn 380: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 381: $cust_on = ' checked="checked" ';
382: $cust_off = '';
383: }
384: if ($context eq 'requestcourses') {
385: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 386: $custom_access = &mt('Currently from default setting.');
1.470 raeburn 387: $customsty = ' style="display:none;"';
1.306 raeburn 388: } else {
389: $custom_access = &mt('Currently from custom setting.');
1.470 raeburn 390: $customsty = ' style="display:block;"';
1.275 raeburn 391: }
1.362 raeburn 392: } elsif ($context eq 'requestauthor') {
393: if ($userenv{$context} eq '') {
394: $custom_access = &mt('Currently from default setting.');
1.470 raeburn 395: $customsty = ' style="display:none;"';
396: } else {
397: $custom_access = &mt('Currently from custom setting.');
398: $customsty = ' style="display:block;"';
399: }
400: } elsif ($item eq 'editors') {
401: if ($userenv{'author'.$item} eq '') {
402: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
403: @defaulteditors = @{$domconfig{'authordefaults'}{'editors'}};
404: } else {
405: @defaulteditors = ('edit','xml');
406: }
407: $custom_access = &mt('Can use: [_1]',
408: join(', ', map { $lt{$_} } @defaulteditors));
409: $editorsty = ' style="display:none;"';
1.362 raeburn 410: } else {
411: $custom_access = &mt('Currently from custom setting.');
1.470 raeburn 412: foreach my $editor (split(/,/,$userenv{'author'.$item})) {
413: if ($editor =~ /^(edit|daxe|xml)$/) {
414: push(@customeditors,$editor);
415: }
416: }
417: if (@customeditors) {
418: if (@customeditors > 1) {
419: $custom_access .= '<br /><span>';
420: } else {
421: $custom_access .= ' <span class="LC_nobreak">';
422: }
423: $custom_access .= &mt('Can use: [_1]',
424: join(', ', map { $lt{$_} } @customeditors)).
425: '</span>';
426: } else {
427: $custom_access .= ' '.&mt('No available editors');
428: }
429: $editorsty = ' style="display:block;"';
430: }
431: } elsif ($item eq 'managers') {
432: my %ca_roles = &Apache::lonnet::get_my_roles($ccuname,$ccdomain,undef,
433: ['active','future'],['ca']);
434: if (keys(%ca_roles)) {
435: foreach my $entry (sort(keys(%ca_roles))) {
436: if ($entry =~ /^($match_username\:$match_domain):ca$/) {
437: my $user = $1;
438: unless ($user eq "$ccuname:$ccdomain") {
439: push(@possmanagers,$user);
440: }
441: }
442: }
443: }
444: if ($userenv{'author'.$item} eq '') {
445: $custom_access = &mt('Currently author manages co-author roles');
446: } else {
447: if (keys(%ca_roles)) {
448: foreach my $user (split(/,/,$userenv{'author'.$item})) {
449: if ($user =~ /^($match_username):($match_domain)$/) {
450: if (exists($ca_roles{$user.':ca'})) {
451: unless ($user eq "$ccuname:$ccdomain") {
452: push(@custommanagers,$user);
453: }
454: }
455: }
456: }
457: }
458: if (@custommanagers) {
459: $custom_access = &mt('Co-authors who manage co-author roles: [_1]',
460: join(', ',@custommanagers));
461: } else {
462: $custom_access = &mt('Currently author manages co-author roles');
463: }
1.362 raeburn 464: }
1.275 raeburn 465: } else {
1.470 raeburn 466: my $current = $userenv{$context.'.'.$item};
467: if ($item eq 'webdav') {
468: $current = $userenv{'tools.webdav'};
1.478 raeburn 469: } elsif ($item eq 'archive') {
470: $current = $userenv{'author'.$item};
1.470 raeburn 471: }
472: if ($current eq '') {
1.314 raeburn 473: $custom_access =
1.306 raeburn 474: &mt('Availability determined currently from default setting.');
475: if (!$curr_access) {
476: $tool_off = 'checked="checked" ';
477: $tool_on = '';
478: }
1.470 raeburn 479: $customsty = ' style="display:none;"';
1.306 raeburn 480: } else {
1.314 raeburn 481: $custom_access =
1.306 raeburn 482: &mt('Availability determined currently from custom setting.');
1.470 raeburn 483: if ($current == 0) {
1.306 raeburn 484: $tool_off = 'checked="checked" ';
485: $tool_on = '';
486: }
1.476 raeburn 487: $customsty = ' style="display:inline;"';
1.275 raeburn 488: }
489: }
490: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 491: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 492: ' </tr>'."\n".
1.306 raeburn 493: &Apache::loncommon::start_data_table_row()."\n";
1.362 raeburn 494: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.475 raeburn 495: my ($curroption,$currlimit);
1.362 raeburn 496: my $envkey = $context.'.'.$item;
497: if ($context eq 'requestauthor') {
498: $envkey = $context;
499: }
500: if ($userenv{$envkey} ne '') {
501: $curroption = $userenv{$envkey};
1.332 raeburn 502: } else {
503: my (@inststatuses);
1.362 raeburn 504: if ($context eq 'requestcourses') {
505: $curroption =
506: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
507: $isadv,$ccdomain,$item,
508: \@inststatuses,\%domconfig);
509: } else {
510: $curroption =
511: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
512: $isadv,$ccdomain,undef,
513: \@inststatuses,\%domconfig);
514: }
1.332 raeburn 515: }
1.306 raeburn 516: if (!$curroption) {
517: $curroption = 'norequest';
518: }
1.470 raeburn 519: my $name = 'crsreq_'.$item;
520: if ($context eq 'requestauthor') {
521: $name = $item;
522: }
523: $onclick = ' onclick="javascript:toggleCustom(this.form,'."'customtext_$item','custom$item'".');"';
1.306 raeburn 524: if ($curroption =~ /^autolimit=(\d*)$/) {
525: $currlimit = $1;
1.314 raeburn 526: if ($currlimit eq '') {
527: $currdisp = &mt('Yes, automatic creation');
528: } else {
529: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
530: }
1.306 raeburn 531: } else {
532: $currdisp = $reqdisplay{$curroption};
533: }
1.470 raeburn 534: $custdisp = '<fieldset id="customtext_'.$item.'"'.$customsty.'>';
1.306 raeburn 535: foreach my $option (@options) {
536: my $val = $option;
537: if ($option eq 'norequest') {
538: $val = 0;
539: }
540: if ($option eq 'validate') {
541: my $canvalidate = 0;
542: if (ref($validations{$item}) eq 'HASH') {
543: if ($validations{$item}{'_custom_'}) {
544: $canvalidate = 1;
545: }
546: }
547: next if (!$canvalidate);
548: }
549: my $checked = '';
550: if ($option eq $curroption) {
551: $checked = ' checked="checked"';
552: } elsif ($option eq 'autolimit') {
553: if ($curroption =~ /^autolimit/) {
554: $checked = ' checked="checked"';
555: }
556: }
1.470 raeburn 557: if ($option eq 'autolimit') {
558: $custdisp .= '<br />';
1.362 raeburn 559: }
1.470 raeburn 560: $custdisp .= '<span class="LC_nobreak"><label>'.
1.362 raeburn 561: '<input type="radio" name="'.$name.'" '.
562: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 563: $reqtitles{$option}.'</label> ';
564: if ($option eq 'autolimit') {
1.362 raeburn 565: $custdisp .= '<input type="text" name="'.$name.
566: '_limit" size="1" '.
1.470 raeburn 567: 'value="'.$currlimit.'" /> '.
568: $reqtitles{'unlimited'}.'</span>';
1.362 raeburn 569: } else {
570: $custdisp .= '</span>';
571: }
1.470 raeburn 572: $custdisp .= ' ';
573: }
574: $custdisp .= '</fieldset>';
575: $custradio = '<br />'.$custdisp;
576: } elsif ($item eq 'editors') {
577: $output .= '<td'.$colspan.'>'.$custom_access.'</td>'."\n".
578: &Apache::loncommon::end_data_table_row()."\n";
579: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
580: $output .= &Apache::loncommon::start_data_table_row()."\n".
581: '<td'.$colspan.'><span class="LC_nobreak">'.
582: $lt{'chse'}.': <label>'.
583: '<input type="radio" name="custom'.$item.'" value="0" '.
584: $cust_off.' onclick="toggleCustom(this.form,'."'customtext_$item','custom$item'".');" />'.
585: $lt{'usde'}.'</label>'.(' ' x3).
586: '<label><input type="radio" name="custom'.$item.'" value="1" '.
587: $cust_on.' onclick="toggleCustom(this.form,'."'customtext_$item','custom$item'".');" />'.
588: $lt{'uscu'}.'</label></span><br />'.
589: '<fieldset id="customtext_'.$item.'"'.$editorsty.'>';
590: foreach my $editor ('edit','xml','daxe') {
591: my $checked;
592: if ($userenv{'author'.$item} eq '') {
593: if (grep(/^\Q$editor\E$/,@defaulteditors)) {
594: $checked = ' checked="checked"';
595: }
596: } elsif (grep(/^\Q$editor\E$/,@customeditors)) {
597: $checked = ' checked="checked"';
598: }
599: $output .= '<span style="LC_nobreak"><label>'.
600: '<input type="checkbox" name="custom_editor" '.
601: 'value="'.$editor.'"'.$checked.' />'.
602: $lt{$editor}.'</label></span> ';
603: }
604: $output .= '</fieldset></td>'.
605: &Apache::loncommon::end_data_table_row()."\n";
606: }
607: } elsif ($item eq 'managers') {
608: $output .= '<td'.$colspan.'>'.$custom_access.'</td>'."\n".
609: &Apache::loncommon::end_data_table_row()."\n";
1.471 raeburn 610: unless ((&Apache::lonnet::allowed('udp',$ccdomain)) ||
611: (($userenv{'domcoord.author'} eq 'blocked') &&
612: (($env{'user.name'} ne $ccuname) || ($env{'user.domain'} ne $ccdomain)))) {
1.470 raeburn 613: $output .=
614: &Apache::loncommon::start_data_table_row()."\n".
615: '<td'.$colspan.'>';
616: if (@possmanagers) {
617: $output .= &mt('Select manager(s)').': ';
618: foreach my $user (@possmanagers) {
619: my $checked;
620: if (grep(/^\Q$user\E$/,@custommanagers)) {
621: $checked = ' checked="checked"';
622: }
623: $output .= '<span style="LC_nobreak"><label>'.
624: '<input type="checkbox" name="custommanagers" '.
625: 'value="'.&HTML::Entities::encode($user,'\'<>"&').'"'.$checked.' />'.
626: $user.'</label></span> ';
627: }
628: } else {
629: $output .= &mt('No co-author roles assignable as manager');
630: }
631: $output .= '</td>'.
632: &Apache::loncommon::end_data_table_row()."\n";
1.306 raeburn 633: }
634: } else {
635: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 636: my $name = $context.'_'.$item;
1.470 raeburn 637: $onclick = 'onclick="javascript:toggleCustom(this.form,'."'customtext_$item','custom$item'".');" ';
1.306 raeburn 638: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 639: '<input type="radio" name="'.$name.'"'.
1.470 raeburn 640: ' value="1" '.$tool_on.$onclick.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 641: '<input type="radio" name="'.$name.'" value="0" '.
1.470 raeburn 642: $tool_off.$onclick.'/>'.&mt('Off').'</label></span>';
643: $custradio = '<span id="customtext_'.$item.'"'.$customsty.' class="LC_nobreak">'.
644: '--'.$lt{'cusa'}.': '.$custdisp.'</span>';
645: }
646: unless (($item eq 'editors') || ($item eq 'managers')) {
647: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
648: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
649: &Apache::loncommon::end_data_table_row()."\n";
650: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
651: $output .=
1.275 raeburn 652: &Apache::loncommon::start_data_table_row()."\n".
1.470 raeburn 653: '<td><span class="LC_nobreak">'.
1.306 raeburn 654: $lt{'chse'}.': <label>'.
1.275 raeburn 655: '<input type="radio" name="custom'.$item.'" value="0" '.
1.470 raeburn 656: $cust_off.$onclick.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
1.306 raeburn 657: '<label><input type="radio" name="custom'.$item.'" value="1" '.
1.470 raeburn 658: $cust_on.$onclick.'/>'.$lt{'uscu'}.'</label></span>';
659: if ($colspan) {
660: $output .= '</td><td>';
661: }
662: $output .= $custradio.'</td>'.
663: &Apache::loncommon::end_data_table_row()."\n";
664: }
1.418 raeburn 665: }
1.275 raeburn 666: }
667: return $output;
668: }
669:
1.300 raeburn 670: sub coursereq_externaluser {
671: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 672: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 673: my %lt = &Apache::lonlocal::texthash (
674: 'official' => 'Can request creation of official courses',
675: 'unofficial' => 'Can request creation of unofficial courses',
676: 'community' => 'Can request creation of communities',
1.384 raeburn 677: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 678: 'placement' => 'Can request creation of placement tests',
1.300 raeburn 679: );
680:
681: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
682: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.411 raeburn 683: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
684: 'reqcrsotherdom.placement');
685: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 686: @options = ('approval','validate','autolimit');
1.306 raeburn 687: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
688: my $optregex = join('|',@options);
689: my %reqtitles = &courserequest_titles();
1.300 raeburn 690: foreach my $item (@usertools) {
1.306 raeburn 691: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 692: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
693: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 694: foreach my $req (@curr) {
695: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
696: $curroption = $1;
697: $currlimit = $2;
698: last;
1.306 raeburn 699: }
700: }
1.314 raeburn 701: if (!$curroption) {
702: $curroption = 'norequest';
703: $tooloff = ' checked="checked"';
704: }
1.306 raeburn 705: } else {
706: $curroption = 'norequest';
707: $tooloff = ' checked="checked"';
708: }
709: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 710: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
711: '<table><tr><td valign="top">'."\n".
1.306 raeburn 712: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 713: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
714: '</label></td>';
1.306 raeburn 715: foreach my $option (@options) {
716: if ($option eq 'validate') {
717: my $canvalidate = 0;
718: if (ref($validations{$item}) eq 'HASH') {
719: if ($validations{$item}{'_external_'}) {
720: $canvalidate = 1;
721: }
722: }
723: next if (!$canvalidate);
724: }
725: my $checked = '';
726: if ($option eq $curroption) {
727: $checked = ' checked="checked"';
728: }
1.314 raeburn 729: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 730: '<input type="radio" name="reqcrsotherdom_'.$item.
731: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 732: $reqtitles{$option}.'</label>';
1.306 raeburn 733: if ($option eq 'autolimit') {
1.314 raeburn 734: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 735: $item.'_limit" size="1" '.
1.314 raeburn 736: 'value="'.$currlimit.'" /></span>'.
737: '<br />'.$reqtitles{'unlimited'};
738: } else {
739: $output .= '</span>';
1.300 raeburn 740: }
1.314 raeburn 741: $output .= '</td>';
1.300 raeburn 742: }
1.314 raeburn 743: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 744: &Apache::loncommon::end_data_table_row()."\n";
745: }
746: return $output;
747: }
748:
1.362 raeburn 749: sub domainrole_req {
750: my ($ccuname,$ccdomain) = @_;
751: return '<br /><h3>'.
1.470 raeburn 752: &mt('Can Request Assignment of Domain Roles?').
1.362 raeburn 753: '</h3>'."\n".
754: &Apache::loncommon::start_data_table().
755: &build_tools_display($ccuname,$ccdomain,
756: 'requestauthor').
757: &Apache::loncommon::end_data_table();
758: }
759:
1.470 raeburn 760: sub authoring_defaults {
761: my ($ccuname,$ccdomain) = @_;
762: return '<br /><h3>'.
763: &mt('Authoring Space defaults (if role assigned)').
764: '</h3>'."\n".
765: &Apache::loncommon::start_data_table().
766: &build_tools_display($ccuname,$ccdomain,
767: 'authordefaults').
768: &user_quotas($ccuname,$ccdomain,'author').
769: &Apache::loncommon::end_data_table();
770: }
771:
1.306 raeburn 772: sub courserequest_titles {
773: my %titles = &Apache::lonlocal::texthash (
774: official => 'Official',
775: unofficial => 'Unofficial',
776: community => 'Communities',
1.384 raeburn 777: textbook => 'Textbook',
1.411 raeburn 778: placement => 'Placement Tests',
1.449 raeburn 779: lti => 'LTI Provider',
1.306 raeburn 780: norequest => 'Not allowed',
1.309 raeburn 781: approval => 'Approval by Dom. Coord.',
1.306 raeburn 782: validate => 'With validation',
783: autolimit => 'Numerical limit',
1.314 raeburn 784: unlimited => '(blank for unlimited)',
1.306 raeburn 785: );
786: return %titles;
787: }
788:
789: sub courserequest_display {
790: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 791: approval => 'Yes, need approval',
1.306 raeburn 792: validate => 'Yes, with validation',
793: norequest => 'No',
794: );
795: return %titles;
796: }
797:
1.362 raeburn 798: sub requestauthor_titles {
799: my %titles = &Apache::lonlocal::texthash (
800: norequest => 'Not allowed',
801: approval => 'Approval by Dom. Coord.',
802: automatic => 'Automatic approval',
803: );
804: return %titles;
805:
806: }
807:
808: sub requestauthor_display {
809: my %titles = &Apache::lonlocal::texthash (
810: approval => 'Yes, need approval',
811: automatic => 'Yes, automatic approval',
812: norequest => 'No',
813: );
814: return %titles;
815: }
816:
1.383 raeburn 817: sub requestchange_display {
818: my %titles = &Apache::lonlocal::texthash (
819: approval => "availability set to 'on' (approval required)",
820: automatic => "availability set to 'on' (automatic approval)",
821: norequest => "availability set to 'off'",
822: );
823: return %titles;
824: }
825:
1.362 raeburn 826: sub curr_requestauthor {
827: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
828: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
829: if ($uname eq '' || $udom eq '') {
830: $uname = $env{'user.name'};
831: $udom = $env{'user.domain'};
832: $isadv = $env{'user.adv'};
833: }
834: my (%userenv,%settings,$val);
835: my @options = ('automatic','approval');
836: %userenv =
837: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
838: if ($userenv{'requestauthor'}) {
839: $val = $userenv{'requestauthor'};
840: @{$inststatuses} = ('_custom_');
841: } else {
842: my %alltasks;
843: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
844: %settings = %{$domconfig->{'requestauthor'}};
845: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
846: $val = $settings{'_LC_adv'};
847: @{$inststatuses} = ('_LC_adv_');
848: } else {
849: if ($userenv{'inststatus'} ne '') {
850: @{$inststatuses} = split(',',$userenv{'inststatus'});
851: } else {
852: @{$inststatuses} = ('default');
853: }
854: foreach my $status (@{$inststatuses}) {
855: if (exists($settings{$status})) {
856: my $value = $settings{$status};
857: next unless ($value);
858: unless (exists($alltasks{$value})) {
859: if (ref($alltasks{$value}) eq 'ARRAY') {
860: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
861: push(@{$alltasks{$value}},$status);
862: }
863: } else {
864: @{$alltasks{$value}} = ($status);
865: }
866: }
867: }
868: }
869: foreach my $option (@options) {
870: if ($alltasks{$option}) {
871: $val = $option;
872: last;
873: }
874: }
875: }
876: }
877: }
878: return $val;
879: }
880:
1.2 www 881: # =================================================================== Phase one
1.1 www 882:
1.42 matthew 883: sub print_username_entry_form {
1.439 raeburn 884: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
885: $permission) = @_;
1.101 albertel 886: my $defdom=$env{'request.role.domain'};
1.160 raeburn 887: my $formtoset = 'crtuser';
888: if (exists($env{'form.startrolename'})) {
889: $formtoset = 'docustom';
890: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 891: } elsif ($env{'form.origform'} eq 'crtusername') {
892: $formtoset = $env{'form.origform'};
1.160 raeburn 893: }
894:
895: my ($jsback,$elements) = &crumb_utilities();
896:
897: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 898: '<script type="text/javascript">'."\n".
1.301 bisitz 899: '// <![CDATA['."\n".
900: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
901: '// ]]>'."\n".
1.162 raeburn 902: '</script>'."\n";
1.160 raeburn 903:
1.324 raeburn 904: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
905: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
906: && (&Apache::lonnet::allowed('mcr','/'))) {
907: $jscript .= &customrole_javascript();
908: }
1.224 raeburn 909: my $helpitem = 'Course_Change_Privileges';
910: if ($env{'form.action'} eq 'custom') {
1.439 raeburn 911: if ($context eq 'course') {
912: $helpitem = 'Course_Editing_Custom_Roles';
913: } elsif ($context eq 'domain') {
914: $helpitem = 'Domain_Editing_Custom_Roles';
915: }
1.224 raeburn 916: } elsif ($env{'form.action'} eq 'singlestudent') {
917: $helpitem = 'Course_Add_Student';
1.416 raeburn 918: } elsif ($env{'form.action'} eq 'accesslogs') {
919: $helpitem = 'Domain_User_Access_Logs';
1.439 raeburn 920: } elsif ($context eq 'author') {
921: $helpitem = 'Author_Change_Privileges';
922: } elsif ($context eq 'domain') {
923: if ($permission->{'cusr'}) {
924: $helpitem = 'Domain_Change_Privileges';
925: } elsif ($permission->{'view'}) {
926: $helpitem = 'Domain_View_Privileges';
927: } else {
928: undef($helpitem);
929: }
1.224 raeburn 930: }
1.422 raeburn 931: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 932: if ($env{'form.action'} eq 'custom') {
933: push(@{$brcrum},
934: {href=>"javascript:backPage(document.crtuser)",
935: text=>"Pick custom role",
936: help => $helpitem,}
937: );
938: } else {
939: push (@{$brcrum},
940: {href => "javascript:backPage(document.crtuser)",
941: text => $breadcrumb_text{'search'},
942: help => $helpitem,
943: faq => 282,
944: bug => 'Instructor Interface',}
945: );
946: }
947: my %loaditems = (
948: 'onload' => "javascript:setFormElements(document.$formtoset)",
949: );
950: my $args = {bread_crumbs => $brcrum,
951: bread_crumbs_component => 'User Management',
952: add_entries => \%loaditems,};
953: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
954:
1.71 sakharuk 955: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 956: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 957: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 958: 'srad' => 'Search for a user and modify/add user information or roles',
1.422 raeburn 959: 'srvu' => 'Search for a user and view user information and roles',
1.416 raeburn 960: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 961: 'usr' => "Username",
962: 'dom' => "Domain",
1.324 raeburn 963: 'ecrp' => "Define or Edit Custom Role",
964: 'nr' => "role name",
1.282 schafran 965: 'cre' => "Next",
1.71 sakharuk 966: );
1.351 raeburn 967:
1.214 raeburn 968: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 969: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 970: my $newroletext = &mt('Define new custom role:');
971: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
972: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
973: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
974: '<h3>'.$lt{'ecrp'}.'</h3>'.
975: &Apache::loncommon::start_data_table().
976: &Apache::loncommon::start_data_table_row().
977: '<td>');
978: if (keys(%existingroles) > 0) {
979: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
980: } else {
981: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
982: }
983: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
984: &Apache::loncommon::end_data_table_row());
985: if (keys(%existingroles) > 0) {
986: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
987: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
988: &mt('View/Modify existing role:').'</b></label></td>'.
989: '<td align="center"><br />'.
990: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 991: '<option value="" selected="selected">'.
1.324 raeburn 992: &mt('Select'));
993: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 994: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 995: }
996: $r->print('</select>'.
997: '</td>'.
998: &Apache::loncommon::end_data_table_row());
999: }
1000: $r->print(&Apache::loncommon::end_data_table().'<p>'.
1001: '<input name="customeditor" type="submit" value="'.
1002: $lt{'cre'}.'" /></p>'.
1003: '</form>');
1.190 raeburn 1004: }
1.213 raeburn 1005: } else {
1.229 raeburn 1006: my $actiontext = $lt{'srad'};
1.436 raeburn 1007: my $fixeddom;
1.213 raeburn 1008: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1009: if ($crstype eq 'Community') {
1010: $actiontext = $lt{'srme'};
1011: } else {
1012: $actiontext = $lt{'srst'};
1013: }
1.416 raeburn 1014: } elsif ($env{'form.action'} eq 'accesslogs') {
1.417 raeburn 1015: $actiontext = $lt{'srva'};
1.436 raeburn 1016: $fixeddom = 1;
1.422 raeburn 1017: } elsif (($env{'form.action'} eq 'singleuser') &&
1018: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
1019: $actiontext = $lt{'srvu'};
1.439 raeburn 1020: $fixeddom = 1;
1.213 raeburn 1021: }
1.324 raeburn 1022: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 1023: if ($env{'form.origform'} ne 'crtusername') {
1.415 raeburn 1024: if ($response) {
1025: $r->print("\n<div>$response</div>".
1026: '<br clear="all" />');
1027: }
1.213 raeburn 1028: }
1.436 raeburn 1029: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 1030: }
1.110 albertel 1031: }
1032:
1.324 raeburn 1033: sub customrole_javascript {
1034: my $js = <<"END";
1035: <script type="text/javascript">
1036: // <![CDATA[
1037:
1038: function setCustomFields() {
1039: if (document.docustom.customroleaction.length > 0) {
1040: for (var i=0; i<document.docustom.customroleaction.length; i++) {
1041: if (document.docustom.customroleaction[i].checked) {
1042: if (document.docustom.customroleaction[i].value == 'new') {
1043: document.docustom.rolename.selectedIndex = 0;
1044: } else {
1045: document.docustom.newrolename.value = '';
1046: }
1047: }
1048: }
1049: }
1050: return;
1051: }
1052:
1053: function setCustomAction(caller) {
1054: if (document.docustom.customroleaction.length > 0) {
1055: for (var i=0; i<document.docustom.customroleaction.length; i++) {
1056: if (document.docustom.customroleaction[i].value == caller) {
1057: document.docustom.customroleaction[i].checked = true;
1058: }
1059: }
1060: }
1061: setCustomFields();
1062: return;
1063: }
1064:
1065: // ]]>
1066: </script>
1067: END
1068: return $js;
1069: }
1070:
1.160 raeburn 1071: sub entry_form {
1.416 raeburn 1072: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 1073: my ($usertype,$inexact);
1.214 raeburn 1074: if (ref($srch) eq 'HASH') {
1075: if (($srch->{'srchin'} eq 'dom') &&
1076: ($srch->{'srchby'} eq 'uname') &&
1077: ($srch->{'srchtype'} eq 'exact') &&
1078: ($srch->{'srchdomain'} ne '') &&
1079: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 1080: my (%curr_rules,%got_rules);
1.214 raeburn 1081: my ($rules,$ruleorder) =
1082: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 1083: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 1084: } else {
1085: $inexact = 1;
1.214 raeburn 1086: }
1.207 raeburn 1087: }
1.438 raeburn 1088: my ($cancreate,$noinstd);
1089: if ($env{'form.action'} eq 'accesslogs') {
1090: $noinstd = 1;
1091: } else {
1092: $cancreate =
1093: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1094: }
1.412 raeburn 1095: my ($userpicker,$cansearch) =
1.179 raeburn 1096: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.438 raeburn 1097: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 1098: my $srchbutton = &mt('Search');
1.229 raeburn 1099: if ($env{'form.action'} eq 'singlestudent') {
1100: $srchbutton = &mt('Search and Enroll');
1.416 raeburn 1101: } elsif ($env{'form.action'} eq 'accesslogs') {
1102: $srchbutton = &mt('Search');
1.229 raeburn 1103: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
1104: $srchbutton = &mt('Search or Add New User');
1105: }
1.412 raeburn 1106: my $output;
1107: if ($cansearch) {
1108: $output = <<"ENDBLOCK";
1.160 raeburn 1109: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 1110: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 1111: <input type="hidden" name="phase" value="get_user_info" />
1112: $userpicker
1.179 raeburn 1113: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 1114: </form>
1.207 raeburn 1115: ENDBLOCK
1.412 raeburn 1116: } else {
1117: $output = '<p>'.$userpicker.'</p>';
1118: }
1.422 raeburn 1119: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
1.430 raeburn 1120: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1.422 raeburn 1121: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 1122: my $defdom=$env{'request.role.domain'};
1.446 raeburn 1123: my ($trusted,$untrusted);
1.444 raeburn 1124: if ($context eq 'course') {
1.446 raeburn 1125: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.444 raeburn 1126: } elsif ($context eq 'author') {
1.446 raeburn 1127: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.444 raeburn 1128: } elsif ($context eq 'domain') {
1.446 raeburn 1129: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.444 raeburn 1130: }
1.446 raeburn 1131: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain',undef,undef,undef,$trusted,$untrusted);
1.207 raeburn 1132: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 1133: 'enro' => 'Enroll one student',
1.318 raeburn 1134: 'enrm' => 'Enroll one member',
1.229 raeburn 1135: 'admo' => 'Add/modify a single user',
1136: 'crea' => 'create new user if required',
1137: 'uskn' => "username is known",
1.207 raeburn 1138: 'crnu' => 'Create a new user',
1139: 'usr' => 'Username',
1140: 'dom' => 'in domain',
1.229 raeburn 1141: 'enrl' => 'Enroll',
1142: 'cram' => 'Create/Modify user',
1.207 raeburn 1143: );
1.229 raeburn 1144: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
1145: my ($title,$buttontext,$showresponse);
1.318 raeburn 1146: if ($env{'form.action'} eq 'singlestudent') {
1147: if ($crstype eq 'Community') {
1148: $title = $lt{'enrm'};
1149: } else {
1150: $title = $lt{'enro'};
1151: }
1.229 raeburn 1152: $buttontext = $lt{'enrl'};
1153: } else {
1154: $title = $lt{'admo'};
1155: $buttontext = $lt{'cram'};
1156: }
1157: if ($cancreate) {
1158: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
1159: } else {
1160: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
1161: }
1162: if ($env{'form.origform'} eq 'crtusername') {
1163: $showresponse = $responsemsg;
1164: }
1.207 raeburn 1165: $output .= <<"ENDDOCUMENT";
1.229 raeburn 1166: <br />
1.207 raeburn 1167: <form action="/adm/createuser" method="post" name="crtusername">
1168: <input type="hidden" name="action" value="$env{'form.action'}" />
1169: <input type="hidden" name="phase" value="createnewuser" />
1170: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 1171: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 1172: <input type="hidden" name="srchin" value="dom" />
1173: <input type="hidden" name="forcenewuser" value="1" />
1174: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 1175: <h3>$title</h3>
1176: $showresponse
1.207 raeburn 1177: <table>
1178: <tr>
1179: <td>$lt{'usr'}:</td>
1180: <td><input type="text" size="15" name="srchterm" /></td>
1181: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 1182: <td> $sellink </td>
1183: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 1184: </tr>
1185: </table>
1186: </form>
1.160 raeburn 1187: ENDDOCUMENT
1.207 raeburn 1188: }
1.160 raeburn 1189: return $output;
1190: }
1.110 albertel 1191:
1192: sub user_modification_js {
1.113 raeburn 1193: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
1194:
1.110 albertel 1195: return <<END;
1196: <script type="text/javascript" language="Javascript">
1.301 bisitz 1197: // <![CDATA[
1.314 raeburn 1198:
1.110 albertel 1199: $pjump_def
1200: $dc_setcourse_code
1201:
1202: function dateset() {
1203: eval("document.cu."+document.cu.pres_marker.value+
1204: ".value=document.cu.pres_value.value");
1.359 www 1205: modalWindow.close();
1.110 albertel 1206: }
1207:
1.113 raeburn 1208: $nondc_setsection_code
1.301 bisitz 1209: // ]]>
1.110 albertel 1210: </script>
1211: END
1.2 www 1212: }
1213:
1214: # =================================================================== Phase two
1.160 raeburn 1215: sub print_user_selection_page {
1.351 raeburn 1216: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 1217: my @fields = ('username','domain','lastname','firstname','permanentemail');
1218: my $sortby = $env{'form.sortby'};
1219:
1220: if (!grep(/^\Q$sortby\E$/,@fields)) {
1221: $sortby = 'lastname';
1222: }
1223:
1224: my ($jsback,$elements) = &crumb_utilities();
1225:
1226: my $jscript = (<<ENDSCRIPT);
1227: <script type="text/javascript">
1.301 bisitz 1228: // <![CDATA[
1.160 raeburn 1229: function pickuser(uname,udom) {
1230: document.usersrchform.seluname.value=uname;
1231: document.usersrchform.seludom.value=udom;
1232: document.usersrchform.phase.value="userpicked";
1233: document.usersrchform.submit();
1234: }
1235:
1236: $jsback
1.301 bisitz 1237: // ]]>
1.160 raeburn 1238: </script>
1239: ENDSCRIPT
1240:
1241: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1242: 'usrch' => "User Search to add/modify roles",
1243: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1244: 'memsrch' => "User Search to enroll member",
1.416 raeburn 1245: 'srcva' => "Search for a user and view access log information",
1.422 raeburn 1246: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1247: 'usel' => "Select a user to add/modify roles",
1.422 raeburn 1248: 'suvr' => "Select a user to view roles",
1.318 raeburn 1249: 'stusel' => "Select a user to enroll as a student",
1250: 'memsel' => "Select a user to enroll as a member",
1.416 raeburn 1251: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1252: 'username' => "username",
1253: 'domain' => "domain",
1254: 'lastname' => "last name",
1255: 'firstname' => "first name",
1256: 'permanentemail' => "permanent e-mail",
1257: );
1.302 raeburn 1258: if ($context eq 'requestcrs') {
1259: $r->print('<div>');
1260: } else {
1.422 raeburn 1261: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1262: my $helpitem;
1263: if ($env{'form.action'} eq 'singleuser') {
1264: $helpitem = 'Course_Change_Privileges';
1265: } elsif ($env{'form.action'} eq 'singlestudent') {
1266: $helpitem = 'Course_Add_Student';
1.439 raeburn 1267: } elsif ($context eq 'author') {
1268: $helpitem = 'Author_Change_Privileges';
1269: } elsif ($context eq 'domain') {
1270: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1271: }
1272: push (@{$brcrum},
1273: {href => "javascript:backPage(document.usersrchform,'','')",
1274: text => $breadcrumb_text{'search'},
1275: faq => 282,
1276: bug => 'Instructor Interface',},
1277: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1278: text => $breadcrumb_text{'userpicked'},
1279: faq => 282,
1280: bug => 'Instructor Interface',
1281: help => $helpitem}
1282: );
1283: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1284: if ($env{'form.action'} eq 'singleuser') {
1.422 raeburn 1285: my $readonly;
1286: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1287: $readonly = 1;
1288: $r->print("<b>$lt{'usrvu'}</b><br />");
1289: } else {
1290: $r->print("<b>$lt{'usrch'}</b><br />");
1291: }
1.318 raeburn 1292: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.422 raeburn 1293: if ($readonly) {
1294: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1295: } else {
1296: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1297: }
1.302 raeburn 1298: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1299: $r->print($jscript."<b>");
1300: if ($crstype eq 'Community') {
1301: $r->print($lt{'memsrch'});
1302: } else {
1303: $r->print($lt{'stusrch'});
1304: }
1305: $r->print("</b><br />");
1306: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1307: $r->print('</form><h3>');
1308: if ($crstype eq 'Community') {
1309: $r->print($lt{'memsel'});
1310: } else {
1311: $r->print($lt{'stusel'});
1312: }
1313: $r->print('</h3>');
1.416 raeburn 1314: } elsif ($env{'form.action'} eq 'accesslogs') {
1315: $r->print("<b>$lt{'srcva'}</b><br />");
1.438 raeburn 1316: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.416 raeburn 1317: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1318: }
1.179 raeburn 1319: }
1.380 bisitz 1320: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1321: &Apache::loncommon::start_data_table()."\n".
1322: &Apache::loncommon::start_data_table_header_row()."\n".
1323: ' <th> </th>'."\n");
1324: foreach my $field (@fields) {
1325: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1326: "'".$field."'".';document.usersrchform.submit();">'.
1327: $lt{$field}.'</a></th>'."\n");
1328: }
1329: $r->print(&Apache::loncommon::end_data_table_header_row());
1330:
1331: my @sorted_users = sort {
1.167 albertel 1332: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1333: ||
1.167 albertel 1334: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1335: ||
1336: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1337: ||
1338: lc($a) cmp lc($b)
1.160 raeburn 1339: } (keys(%$srch_results));
1340:
1341: foreach my $user (@sorted_users) {
1342: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1343: my $onclick;
1344: if ($context eq 'requestcrs') {
1.314 raeburn 1345: $onclick =
1.302 raeburn 1346: 'onclick="javascript:gochoose('."'$uname','$udom',".
1347: "'$srch_results->{$user}->{firstname}',".
1348: "'$srch_results->{$user}->{lastname}',".
1349: "'$srch_results->{$user}->{permanentemail}'".');"';
1350: } else {
1.314 raeburn 1351: $onclick =
1.302 raeburn 1352: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1353: }
1.160 raeburn 1354: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1355: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1356: $onclick.' /></td>'.
1.160 raeburn 1357: '<td><tt>'.$uname.'</tt></td>'.
1358: '<td><tt>'.$udom.'</tt></td>');
1359: foreach my $field ('lastname','firstname','permanentemail') {
1360: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1361: }
1362: $r->print(&Apache::loncommon::end_data_table_row());
1363: }
1364: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1365: if (ref($srcharray) eq 'ARRAY') {
1366: foreach my $item (@{$srcharray}) {
1367: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1368: }
1369: }
1.160 raeburn 1370: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1371: ' <input type="hidden" name="seluname" value="" />'."\n".
1372: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1373: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1374: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1375: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1376: if ($context eq 'requestcrs') {
1377: $r->print($opener_elements.'</form></div>');
1378: } else {
1.351 raeburn 1379: $r->print($response.'</form>');
1.302 raeburn 1380: }
1.160 raeburn 1381: }
1382:
1383: sub print_user_query_page {
1.351 raeburn 1384: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1385: # FIXME - this is for a network-wide name search (similar to catalog search)
1386: # To use frames with similar behavior to catalog/portfolio search.
1387: # To be implemented.
1388: return;
1389: }
1390:
1.42 matthew 1391: sub print_user_modification_page {
1.375 raeburn 1392: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1393: $brcrum,$showcredits) = @_;
1.185 raeburn 1394: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1395: my $usermsg = &mt('No username and/or domain provided.');
1396: $env{'form.phase'} = '';
1.439 raeburn 1397: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1398: $permission);
1.58 www 1399: return;
1400: }
1.213 raeburn 1401: my ($form,$formname);
1402: if ($env{'form.action'} eq 'singlestudent') {
1403: $form = 'document.enrollstudent';
1404: $formname = 'enrollstudent';
1405: } else {
1406: $form = 'document.cu';
1407: $formname = 'cu';
1408: }
1.188 raeburn 1409: my %abv_auth = &auth_abbrev();
1.227 raeburn 1410: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1411: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1412: if ($uhome eq 'no_host') {
1.215 raeburn 1413: my $usertype;
1414: my ($rules,$ruleorder) =
1415: &Apache::lonnet::inst_userrules($ccdomain,'username');
1416: $usertype =
1.353 raeburn 1417: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1418: \%curr_rules,\%got_rules);
1.215 raeburn 1419: my $cancreate =
1420: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1421: $usertype);
1422: if (!$cancreate) {
1.292 bisitz 1423: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1424: my %usertypetext = (
1425: official => 'institutional',
1426: unofficial => 'non-institutional',
1427: );
1428: my $response;
1429: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1430: $response = '<span class="LC_warning">'.
1431: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1432: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1433: '</span><br />';
1434: }
1.292 bisitz 1435: $response .= '<p class="LC_warning">'
1436: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.418 raeburn 1437: .' ';
1438: if ($context eq 'domain') {
1439: $response .= &mt('Please contact a [_1] for assistance.',
1440: &Apache::lonnet::plaintext('dc'));
1441: } else {
1442: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1443: ,'<a href="'.$helplink.'">','</a>');
1444: }
1445: $response .= '</p><br />';
1.215 raeburn 1446: $env{'form.phase'} = '';
1.439 raeburn 1447: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1448: $permission);
1.215 raeburn 1449: return;
1450: }
1.188 raeburn 1451: $newuser = 1;
1.193 raeburn 1452: my $checkhash;
1453: my $checks = { 'username' => 1 };
1.196 raeburn 1454: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1455: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1456: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1457: if (ref($alerts{'username'}) eq 'HASH') {
1458: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1459: my $domdesc =
1.193 raeburn 1460: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1461: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1462: my $userchkmsg;
1463: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1464: $userchkmsg =
1465: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1466: $domdesc,1).
1467: &Apache::loncommon::user_rule_formats($ccdomain,
1468: $domdesc,$curr_rules{$ccdomain}{'username'},
1469: 'username');
1.196 raeburn 1470: }
1.215 raeburn 1471: $env{'form.phase'} = '';
1.439 raeburn 1472: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1473: $permission);
1.196 raeburn 1474: return;
1.215 raeburn 1475: }
1.193 raeburn 1476: }
1.185 raeburn 1477: }
1.187 raeburn 1478: } else {
1.188 raeburn 1479: $newuser = 0;
1.185 raeburn 1480: }
1.160 raeburn 1481: if ($response) {
1.215 raeburn 1482: $response = '<br />'.$response;
1.160 raeburn 1483: }
1.149 raeburn 1484:
1.52 matthew 1485: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1486: my $dc_setcourse_code = '';
1.119 raeburn 1487: my $nondc_setsection_code = '';
1.112 albertel 1488: my %loaditem;
1.114 albertel 1489:
1.216 raeburn 1490: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1491:
1.470 raeburn 1492: my $js = &validation_javascript($context,$ccdomain,$pjump_def,
1493: $crstype,$groupslist,$newuser,
1494: $formname,\%loaditem,$permission);
1.422 raeburn 1495: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1496: my $helpitem = 'Course_Change_Privileges';
1497: if ($env{'form.action'} eq 'singlestudent') {
1498: $helpitem = 'Course_Add_Student';
1.439 raeburn 1499: } elsif ($context eq 'author') {
1500: $helpitem = 'Author_Change_Privileges';
1501: } elsif ($context eq 'domain') {
1502: $helpitem = 'Domain_Change_Privileges';
1.470 raeburn 1503: $js .= &set_custom_js();
1.224 raeburn 1504: }
1.351 raeburn 1505: push (@{$brcrum},
1506: {href => "javascript:backPage($form)",
1507: text => $breadcrumb_text{'search'},
1508: faq => 282,
1509: bug => 'Instructor Interface',});
1510: if ($env{'form.phase'} eq 'userpicked') {
1511: push(@{$brcrum},
1512: {href => "javascript:backPage($form,'get_user_info','select')",
1513: text => $breadcrumb_text{'userpicked'},
1514: faq => 282,
1515: bug => 'Instructor Interface',});
1516: }
1517: push(@{$brcrum},
1518: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1519: text => $breadcrumb_text{'modify'},
1520: faq => 282,
1521: bug => 'Instructor Interface',
1522: help => $helpitem});
1523: my $args = {'add_entries' => \%loaditem,
1524: 'bread_crumbs' => $brcrum,
1525: 'bread_crumbs_component' => 'User Management'};
1526: if ($env{'form.popup'}) {
1527: $args->{'no_nav_bar'} = 1;
1.481 ! raeburn 1528: $args->{'add_modal'} = 1;
1.351 raeburn 1529: }
1.470 raeburn 1530: if (($context eq 'domain') && ($env{'request.role.domain'} eq $ccdomain)) {
1531: my @toggles;
1532: if (&Apache::lonnet::allowed('cau',$ccdomain)) {
1533: my ($isadv,$isauthor) =
1534: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1535: unless ($isauthor) {
1536: push(@toggles,'requestauthor');
1537: }
1.478 raeburn 1538: push(@toggles,('webdav','editors','archive'));
1.470 raeburn 1539: }
1540: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1541: push(@toggles,('aboutme','blog','portfolio','portaccess','timezone'));
1542: }
1543: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1544: push(@toggles,('official','unofficial','community','textbook','placement','lti'));
1545: }
1546: if (@toggles) {
1547: my $onload;
1548: foreach my $item (@toggles) {
1549: $onload .= "toggleCustom(document.cu,'customtext_$item','custom$item');";
1550: }
1551: $args->{'add_entries'} = {
1552: 'onload' => $onload,
1553: };
1554: }
1555: }
1.351 raeburn 1556: my $start_page =
1557: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1558:
1.25 matthew 1559: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1560: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1561: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1562: <input type="hidden" name="ccuname" value="$ccuname" />
1563: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1564: <input type="hidden" name="pres_value" value="" />
1565: <input type="hidden" name="pres_type" value="" />
1566: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1567: ENDFORMINFO
1.375 raeburn 1568: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1569: if ($context eq 'course') {
1570: $inccourses{$env{'request.course.id'}}=1;
1571: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1572: if ($showcredits) {
1573: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1574: }
1.329 raeburn 1575: } elsif ($context eq 'author') {
1576: $roledom = $env{'request.role.domain'};
1577: } elsif ($context eq 'domain') {
1578: foreach my $key (keys(%env)) {
1579: $roledom = $env{'request.role.domain'};
1580: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1581: $inccourses{$1.'_'.$2}=1;
1582: }
1583: }
1584: } else {
1585: foreach my $key (keys(%env)) {
1586: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1587: $inccourses{$1.'_'.$2}=1;
1588: }
1.2 www 1589: }
1.24 matthew 1590: }
1.389 bisitz 1591: my $title = '';
1.470 raeburn 1592: my $need_quota_js;
1.216 raeburn 1593: if ($newuser) {
1.427 raeburn 1594: my ($portfolioform,$domroleform);
1.267 raeburn 1595: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1596: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1597: # Current user has quota or user tools modification privileges
1.470 raeburn 1598: $portfolioform = '<br /><h3>'.
1599: &mt('User Tools').
1600: '</h3>'."\n".
1601: &Apache::loncommon::start_data_table();
1602: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1603: $portfolioform .= &build_tools_display($ccuname,$ccdomain,'tools');
1604: }
1605: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
1606: $portfolioform .= &user_quotas($ccuname,$ccdomain,'portfolio');
1607: $need_quota_js = 1;
1608: }
1609: $portfolioform .= &Apache::loncommon::end_data_table();
1.134 raeburn 1610: }
1.383 raeburn 1611: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1612: ($ccdomain eq $env{'request.role.domain'})) {
1.470 raeburn 1613: $domroleform = &domainrole_req($ccuname,$ccdomain).
1614: &authoring_defaults($ccuname,$ccdomain);
1615: $need_quota_js = 1;
1616: }
1617: my $readonly;
1618: unless ($permission->{'cusr'}) {
1619: $readonly = 1;
1.362 raeburn 1620: }
1.470 raeburn 1621: &initialize_authen_forms($ccdomain,$formname,'','',$readonly);
1.188 raeburn 1622: my %lt=&Apache::lonlocal::texthash(
1623: 'lg' => 'Login Data',
1.190 raeburn 1624: 'hs' => "Home Server",
1.188 raeburn 1625: );
1.185 raeburn 1626: $r->print(<<ENDTITLE);
1.110 albertel 1627: $start_page
1.160 raeburn 1628: $response
1.25 matthew 1629: $forminfo
1.31 matthew 1630: <script type="text/javascript" language="Javascript">
1.301 bisitz 1631: // <![CDATA[
1.20 harris41 1632: $loginscript
1.301 bisitz 1633: // ]]>
1.31 matthew 1634: </script>
1.20 harris41 1635: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1636: ENDTITLE
1.213 raeburn 1637: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1638: if ($crstype eq 'Community') {
1.389 bisitz 1639: $title = &mt('Create New User [_1] in domain [_2] as a member',
1640: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1641: } else {
1.389 bisitz 1642: $title = &mt('Create New User [_1] in domain [_2] as a student',
1643: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1644: }
1.389 bisitz 1645: } else {
1646: $title = &mt('Create New User [_1] in domain [_2]',
1647: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1648: }
1.389 bisitz 1649: $r->print('<h2>'.$title.'</h2>'."\n");
1650: $r->print('<div class="LC_left_float">');
1.393 raeburn 1651: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1.470 raeburn 1652: $inst_results{$ccuname.':'.$ccdomain},$readonly));
1.393 raeburn 1653: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1654: my ($home_server_pick,$numlib) =
1655: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1656: 'default','hide');
1657: if ($numlib > 1) {
1658: $r->print("
1.185 raeburn 1659: <br />
1.187 raeburn 1660: $lt{'hs'}: $home_server_pick
1661: <br />");
1662: } else {
1663: $r->print($home_server_pick);
1664: }
1.304 raeburn 1665: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1666: $r->print('<br /><h3>'.
1.470 raeburn 1667: &mt('Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1668: &Apache::loncommon::start_data_table().
1669: &build_tools_display($ccuname,$ccdomain,
1670: 'requestcourses').
1671: &Apache::loncommon::end_data_table());
1672: }
1.188 raeburn 1673: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1674: $lt{'lg'}.'</h3>');
1.185 raeburn 1675: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1676: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1677: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1678: my ($rules,$ruleorder) =
1679: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1680: if (ref($rules) eq 'HASH') {
1.193 raeburn 1681: if (ref($rules->{$matchedrule}) eq 'HASH') {
1682: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1683: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1684: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1685: } else {
1.193 raeburn 1686: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1687: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1688: if ($authtype =~ /^krb(4|5)$/) {
1689: my $ver = $1;
1690: if ($authparm ne '') {
1691: $fixedauth = <<"KERB";
1692: <input type="hidden" name="login" value="krb" />
1693: <input type="hidden" name="krbver" value="$ver" />
1694: <input type="hidden" name="krbarg" value="$authparm" />
1695: KERB
1696: }
1697: } else {
1698: $fixedauth =
1699: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1700: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1701: $fixedauth .=
1702: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1703: } else {
1.273 raeburn 1704: if ($authtype eq 'int') {
1705: $varauth = '<br />'.
1.301 bisitz 1706: &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 1707: } elsif ($authtype eq 'loc') {
1708: $varauth = '<br />'.
1709: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1710: } else {
1711: $varauth =
1.185 raeburn 1712: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1713: }
1.185 raeburn 1714: }
1715: }
1716: }
1717: } else {
1.190 raeburn 1718: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1719: }
1720: }
1721: if ($authmsg) {
1722: $r->print(<<ENDAUTH);
1723: $fixedauth
1724: $authmsg
1725: $varauth
1726: ENDAUTH
1727: }
1728: } else {
1.190 raeburn 1729: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1730: }
1.427 raeburn 1731: $r->print($portfolioform.$domroleform);
1.215 raeburn 1732: if ($env{'form.action'} eq 'singlestudent') {
1733: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1734: $permission,$crstype,$ccuname,
1735: $ccdomain,$showcredits));
1.215 raeburn 1736: }
1737: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1738: } else { # user already exists
1.389 bisitz 1739: $r->print($start_page.$forminfo);
1.213 raeburn 1740: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1741: if ($crstype eq 'Community') {
1.389 bisitz 1742: $title = &mt('Enroll one member: [_1] in domain [_2]',
1743: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1744: } else {
1.389 bisitz 1745: $title = &mt('Enroll one student: [_1] in domain [_2]',
1746: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1747: }
1.213 raeburn 1748: } else {
1.418 raeburn 1749: if ($permission->{'cusr'}) {
1750: $title = &mt('Modify existing user: [_1] in domain [_2]',
1751: '"'.$ccuname.'"','"'.$ccdomain.'"');
1752: } else {
1753: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1754: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.418 raeburn 1755: }
1.213 raeburn 1756: }
1.389 bisitz 1757: $r->print('<h2>'.$title.'</h2>'."\n");
1758: $r->print('<div class="LC_left_float">');
1.393 raeburn 1759: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1760: $inst_results{$ccuname.':'.$ccdomain}));
1.430 raeburn 1761: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1.418 raeburn 1762: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.470 raeburn 1763: $r->print('<br /><h3>'.&mt('Can Request Creation of Courses/Communities in this Domain?').'</h3>'."\n");
1.450 raeburn 1764: if (($env{'request.role.domain'} eq $ccdomain) ||
1765: (&Apache::lonnet::will_trust('reqcrs',$ccdomain,$env{'request.role.domain'}))) {
1766: $r->print(&Apache::loncommon::start_data_table());
1767: if ($env{'request.role.domain'} eq $ccdomain) {
1768: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1769: } else {
1.444 raeburn 1770: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1771: $env{'request.role.domain'}));
1772: }
1.450 raeburn 1773: $r->print(&Apache::loncommon::end_data_table());
1774: } else {
1775: $r->print(&mt('Domain configuration for this domain prohibits course creation by users from domain: "[_1]"',
1776: &Apache::lonnet::domain($ccdomain,'description')));
1.300 raeburn 1777: }
1.275 raeburn 1778: }
1.199 raeburn 1779: $r->print('</div>');
1.470 raeburn 1780: my @order = ('auth','quota','tools','requestauthor','authordefaults');
1.362 raeburn 1781: my %user_text;
1782: my ($isadv,$isauthor) =
1.418 raeburn 1783: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.470 raeburn 1784: if (((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1.418 raeburn 1785: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1.470 raeburn 1786: ($env{'request.role.domain'} eq $ccdomain)) {
1787: if (!$isauthor) {
1788: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1789: }
1790: $user_text{'authordefaults'} = &authoring_defaults($ccuname,$ccdomain);
1791: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
1792: $need_quota_js = 1;
1793: }
1.362 raeburn 1794: }
1.451 raeburn 1795: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
1.267 raeburn 1796: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.418 raeburn 1797: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1798: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.470 raeburn 1799: $user_text{'quota'} = '<br /><h3>'.&mt('User Tools').'</h3>'."\n".
1800: &Apache::loncommon::start_data_table();
1801: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
1802: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1803: $user_text{'quota'} .= &build_tools_display($ccuname,$ccdomain,'tools');
1804: }
1.188 raeburn 1805: # Current user has quota modification privileges
1.470 raeburn 1806: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1807: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1808: $user_text{'quota'} .= &user_quotas($ccuname,$ccdomain,'portfolio');
1809: $need_quota_js = 1;
1810: }
1811: $user_text{'quota'} .= &Apache::loncommon::end_data_table();
1.267 raeburn 1812: }
1813: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1814: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1815: my %lt=&Apache::lonlocal::texthash(
1.470 raeburn 1816: 'dska' => "Disk quotas for user's portfolio",
1817: 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
1.267 raeburn 1818: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1819: );
1.362 raeburn 1820: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1821: <h3>$lt{'dska'}</h3>
1822: $lt{'youd'} $lt{'ichr'}: $ccdomain
1823: ENDNOPORTPRIV
1.267 raeburn 1824: }
1825: }
1826: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1827: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1828: my %lt=&Apache::lonlocal::texthash(
1829: 'utav' => "User Tools Availability",
1.470 raeburn 1830: 'yodo' => "You do not have privileges to modify Portfolio, Blog, Personal Information Page, or Time Zone settings for this user.",
1.267 raeburn 1831: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1832: );
1.362 raeburn 1833: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1834: <h3>$lt{'utav'}</h3>
1835: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1836: ENDNOTOOLSPRIV
1837: }
1.188 raeburn 1838: }
1.362 raeburn 1839: my $gotdiv = 0;
1840: foreach my $item (@order) {
1841: if ($user_text{$item} ne '') {
1842: unless ($gotdiv) {
1843: $r->print('<div class="LC_left_float">');
1844: $gotdiv = 1;
1845: }
1846: $r->print('<br />'.$user_text{$item});
1847: }
1848: }
1849: if ($env{'form.action'} eq 'singlestudent') {
1850: unless ($gotdiv) {
1851: $r->print('<div class="LC_left_float">');
1.213 raeburn 1852: }
1.375 raeburn 1853: my $credits;
1854: if ($showcredits) {
1855: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1856: if ($credits eq '') {
1857: $credits = $defaultcredits;
1858: }
1859: }
1.374 raeburn 1860: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1861: $permission,$crstype,$ccuname,
1862: $ccdomain,$showcredits));
1.374 raeburn 1863: }
1.362 raeburn 1864: if ($gotdiv) {
1865: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1866: }
1.418 raeburn 1867: my $statuses;
1868: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1869: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1870: $statuses = ['active'];
1871: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1872: ($env{'request.course.sec'} &&
1873: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1.430 raeburn 1874: $statuses = ['active'];
1.418 raeburn 1875: }
1.217 raeburn 1876: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1877: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.418 raeburn 1878: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1879: }
1.25 matthew 1880: } ## End of new user/old user logic
1.218 raeburn 1881: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1882: my $btntxt;
1883: if ($crstype eq 'Community') {
1884: $btntxt = &mt('Enroll Member');
1885: } else {
1886: $btntxt = &mt('Enroll Student');
1887: }
1888: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.418 raeburn 1889: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1890: $r->print('<div class="LC_left_float">'.
1891: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1892: my $addrolesdisplay = 0;
1893: if ($context eq 'domain' || $context eq 'author') {
1894: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1895: }
1896: if ($context eq 'domain') {
1.357 raeburn 1897: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1898: if (!$addrolesdisplay) {
1899: $addrolesdisplay = $add_domainroles;
1.2 www 1900: }
1.375 raeburn 1901: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1902: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1903: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1904: } elsif ($context eq 'author') {
1905: if ($addrolesdisplay) {
1.393 raeburn 1906: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1907: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1908: if ($newuser) {
1.301 bisitz 1909: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1910: } else {
1.461 raeburn 1911: $r->print(' onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1912: }
1.188 raeburn 1913: } else {
1.393 raeburn 1914: $r->print('</fieldset></div>'.
1915: '<div class="LC_clear_float_footer"></div>'.
1916: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1917: &mt('Back to previous page').'</a>');
1.188 raeburn 1918: }
1919: } else {
1.375 raeburn 1920: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1921: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1922: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1923: }
1.88 raeburn 1924: }
1.188 raeburn 1925: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1926: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1927: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.470 raeburn 1928: if ($need_quota_js) {
1929: $r->print(&user_quota_js());
1930: }
1.218 raeburn 1931: return;
1.2 www 1932: }
1.1 www 1933:
1.213 raeburn 1934: sub singleuser_breadcrumb {
1.422 raeburn 1935: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1936: my %breadcrumb_text;
1937: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1938: if ($crstype eq 'Community') {
1939: $breadcrumb_text{'search'} = 'Enroll a member';
1940: } else {
1941: $breadcrumb_text{'search'} = 'Enroll a student';
1942: }
1.422 raeburn 1943: $breadcrumb_text{'userpicked'} = 'Select a user';
1944: $breadcrumb_text{'modify'} = 'Set section/dates';
1.416 raeburn 1945: } elsif ($env{'form.action'} eq 'accesslogs') {
1946: $breadcrumb_text{'search'} = 'View access logs for a user';
1.422 raeburn 1947: $breadcrumb_text{'userpicked'} = 'Select a user';
1948: $breadcrumb_text{'activity'} = 'Activity';
1949: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1950: (!&Apache::lonnet::allowed('mau',$domain))) {
1951: $breadcrumb_text{'search'} = "View user's roles";
1952: $breadcrumb_text{'userpicked'} = 'Select a user';
1953: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1954: } else {
1.229 raeburn 1955: $breadcrumb_text{'search'} = 'Create/modify a user';
1.422 raeburn 1956: $breadcrumb_text{'userpicked'} = 'Select a user';
1957: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1958: }
1959: return %breadcrumb_text;
1960: }
1961:
1962: sub date_sections_select {
1.375 raeburn 1963: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1964: $showcredits) = @_;
1965: my $credits;
1966: if ($showcredits) {
1967: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1968: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1969: if ($credits eq '') {
1970: $credits = $defaultcredits;
1971: }
1972: }
1.213 raeburn 1973: my $cid = $env{'request.course.id'};
1974: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1975: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1976: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1977: undef,$formname,$permission);
1978: my $rowtitle = 'Section';
1.375 raeburn 1979: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1980: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1981: $permission,$context,'',$crstype,
1982: $showcredits,$credits);
1.213 raeburn 1983: my $output = $date_table.$secbox;
1984: return $output;
1985: }
1986:
1.216 raeburn 1987: sub validation_javascript {
1.375 raeburn 1988: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.470 raeburn 1989: $loaditem,$permission) = @_;
1.216 raeburn 1990: my $dc_setcourse_code = '';
1991: my $nondc_setsection_code = '';
1992: if ($context eq 'domain') {
1.470 raeburn 1993: if ((ref($permission) eq 'HASH') && ($permission->{'cusr'})) {
1994: my $dcdom = $env{'request.role.domain'};
1995: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1996: $dc_setcourse_code =
1997: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1998: }
1.216 raeburn 1999: } else {
1.227 raeburn 2000: my $checkauth;
2001: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
2002: $checkauth = 1;
2003: }
2004: if ($context eq 'course') {
2005: $nondc_setsection_code =
2006: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 2007: undef,$checkauth,
2008: $crstype);
1.227 raeburn 2009: }
2010: if ($checkauth) {
2011: $nondc_setsection_code .=
2012: &Apache::lonuserutils::verify_authen($formname,$context);
2013: }
1.216 raeburn 2014: }
2015: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
2016: $nondc_setsection_code,$groupslist);
2017: my ($jsback,$elements) = &crumb_utilities();
2018: $js .= "\n".
1.301 bisitz 2019: '<script type="text/javascript">'."\n".
2020: '// <![CDATA['."\n".
2021: $jsback."\n".
2022: '// ]]>'."\n".
2023: '</script>'."\n";
1.216 raeburn 2024: return $js;
2025: }
2026:
1.217 raeburn 2027: sub display_existing_roles {
1.375 raeburn 2028: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.418 raeburn 2029: $showcredits,$statuses) = @_;
1.329 raeburn 2030: my $now=time;
1.418 raeburn 2031: my $showall = 1;
2032: my ($showexpired,$showactive);
2033: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
2034: $showall = 0;
2035: if (grep(/^expired$/,@{$statuses})) {
2036: $showexpired = 1;
2037: }
2038: if (grep(/^active$/,@{$statuses})) {
2039: $showactive = 1;
2040: }
2041: if ($showexpired && $showactive) {
2042: $showall = 1;
2043: }
2044: }
1.329 raeburn 2045: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 2046: 'rer' => "Existing Roles",
2047: 'rev' => "Revoke",
2048: 'del' => "Delete",
2049: 'ren' => "Re-Enable",
2050: 'rol' => "Role",
2051: 'ext' => "Extent",
1.375 raeburn 2052: 'crd' => "Credits",
1.217 raeburn 2053: 'sta' => "Start",
2054: 'end' => "End",
2055: );
1.329 raeburn 2056: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
2057: if ($context eq 'course' || $context eq 'author') {
2058: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
2059: my %roleshash =
2060: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
2061: ['active','previous','future'],\@roles,$roledom,1);
2062: foreach my $key (keys(%roleshash)) {
2063: my ($start,$end) = split(':',$roleshash{$key});
2064: next if ($start eq '-1' || $end eq '-1');
2065: my ($rnum,$rdom,$role,$sec) = split(':',$key);
2066: if ($context eq 'course') {
2067: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
2068: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
2069: } elsif ($context eq 'author') {
1.470 raeburn 2070: if ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2071: my ($audom,$auname) = ($1,$2);
2072: next unless (($rnum eq $auname) && ($rdom eq $audom));
2073: } else {
2074: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
2075: }
1.329 raeburn 2076: }
2077: my ($newkey,$newvalue,$newrole);
2078: $newkey = '/'.$rdom.'/'.$rnum;
2079: if ($sec ne '') {
2080: $newkey .= '/'.$sec;
2081: }
2082: $newvalue = $role;
2083: if ($role =~ /^cr/) {
2084: $newrole = 'cr';
2085: } else {
2086: $newrole = $role;
2087: }
2088: $newkey .= '_'.$newrole;
2089: if ($start ne '' && $end ne '') {
2090: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 2091: } elsif ($end ne '') {
2092: $newvalue .= '_'.$end;
1.329 raeburn 2093: }
2094: $rolesdump{$newkey} = $newvalue;
2095: }
2096: } else {
1.360 raeburn 2097: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 2098: }
2099: # Build up table of user roles to allow revocation and re-enabling of roles.
2100: my ($tmp) = keys(%rolesdump);
2101: return if ($tmp =~ /^(con_lost|error)/i);
2102: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
2103: my $b1=join('_',(split('_',$b))[1,0]);
2104: return $a1 cmp $b1;
2105: } keys(%rolesdump)) {
2106: next if ($area =~ /^rolesdef/);
2107: my $envkey=$area;
2108: my $role = $rolesdump{$area};
2109: my $thisrole=$area;
2110: $area =~ s/\_\w\w$//;
2111: my ($role_code,$role_end_time,$role_start_time) =
2112: split(/_/,$role);
1.418 raeburn 2113: my $active=1;
2114: $active=0 if (($role_end_time) && ($now>$role_end_time));
2115: if ($active) {
2116: next unless($showall || $showactive);
2117: } else {
1.430 raeburn 2118: next unless($showall || $showexpired);
1.418 raeburn 2119: }
1.217 raeburn 2120: # Is this a custom role? Get role owner and title.
1.329 raeburn 2121: my ($croleudom,$croleuname,$croletitle)=
2122: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
2123: my $allowed=0;
2124: my $delallowed=0;
2125: my $sortkey=$role_code;
2126: my $class='Unknown';
1.375 raeburn 2127: my $credits='';
1.418 raeburn 2128: my $csec;
1.421 raeburn 2129: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 2130: $class='Course';
2131: my ($coursedom,$coursedir) = ($1,$2);
2132: my $cid = $1.'_'.$2;
2133: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.421 raeburn 2134: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 2135: my %coursedata=
2136: &Apache::lonnet::coursedescription($cid);
2137: if ($coursedir =~ /^$match_community$/) {
2138: $class='Community';
2139: }
2140: $sortkey.="\0$coursedom";
2141: my $carea;
2142: if (defined($coursedata{'description'})) {
2143: $carea=$coursedata{'description'}.
2144: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
2145: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
2146: $sortkey.="\0".$coursedata{'description'};
2147: } else {
2148: if ($class eq 'Community') {
2149: $carea=&mt('Unavailable community').': '.$area;
2150: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 2151: } else {
2152: $carea=&mt('Unavailable course').': '.$area;
2153: $sortkey.="\0".&mt('Unavailable course').': '.$area;
2154: }
1.329 raeburn 2155: }
2156: $sortkey.="\0$coursedir";
2157: $inccourses->{$cid}=1;
1.375 raeburn 2158: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
2159: my $defaultcredits = $coursedata{'internal.defaultcredits'};
2160: $credits =
2161: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
2162: $coursedom,$coursedir);
2163: if ($credits eq '') {
2164: $credits = $defaultcredits;
2165: }
2166: }
1.329 raeburn 2167: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
2168: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
2169: $allowed=1;
2170: }
2171: unless ($allowed) {
1.365 raeburn 2172: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 2173: if ($isowner) {
2174: if (($role_code eq 'co') && ($class eq 'Community')) {
2175: $allowed = 1;
2176: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
2177: $allowed = 1;
2178: }
1.217 raeburn 2179: }
1.329 raeburn 2180: }
2181: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
2182: (&Apache::lonnet::allowed('dro',$ccdomain))) {
2183: $delallowed=1;
2184: }
1.217 raeburn 2185: # - custom role. Needs more info, too
1.329 raeburn 2186: if ($croletitle) {
2187: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
2188: $allowed=1;
2189: $thisrole.='.'.$role_code;
1.217 raeburn 2190: }
1.329 raeburn 2191: }
1.418 raeburn 2192: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
2193: $csec = $2;
2194: $carea.='<br />'.&mt('Section: [_1]',$csec);
2195: $sortkey.="\0$csec";
1.329 raeburn 2196: if (!$allowed) {
1.418 raeburn 2197: if ($env{'request.course.sec'} eq $csec) {
2198: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 2199: $allowed = 1;
1.217 raeburn 2200: }
2201: }
2202: }
1.329 raeburn 2203: }
2204: $area=$carea;
2205: } else {
2206: $sortkey.="\0".$area;
2207: # Determine if current user is able to revoke privileges
2208: if ($area=~m{^/($match_domain)/}) {
2209: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
2210: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
2211: $allowed=1;
1.217 raeburn 2212: }
1.329 raeburn 2213: if (((&Apache::lonnet::allowed('dro',$1)) ||
2214: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
2215: ($role_code ne 'dc')) {
2216: $delallowed=1;
1.217 raeburn 2217: }
1.329 raeburn 2218: } else {
2219: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 2220: $allowed=1;
2221: }
2222: }
1.363 raeburn 2223: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 2224: $class='Authoring Space';
1.329 raeburn 2225: } elsif ($role_code eq 'su') {
2226: $class='System';
1.217 raeburn 2227: } else {
1.329 raeburn 2228: $class='Domain';
1.217 raeburn 2229: }
1.329 raeburn 2230: }
2231: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
2232: $area=~m{/($match_domain)/($match_username)};
2233: if (&Apache::lonuserutils::authorpriv($2,$1)) {
2234: $allowed=1;
1.470 raeburn 2235: } elsif (&Apache::lonuserutils::coauthorpriv($2,$1)) {
2236: $allowed=1;
1.217 raeburn 2237: } else {
1.329 raeburn 2238: $allowed=0;
1.217 raeburn 2239: }
1.329 raeburn 2240: }
2241: my $row = '';
1.418 raeburn 2242: if ($showall) {
2243: $row.= '<td>';
2244: if (($active) && ($allowed)) {
2245: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
2246: } else {
2247: if ($active) {
2248: $row.=' ';
2249: } else {
2250: $row.=&mt('expired or revoked');
2251: }
2252: }
2253: $row.='</td><td>';
2254: if ($allowed && !$active) {
2255: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
2256: } else {
2257: $row.=' ';
2258: }
2259: $row.='</td><td>';
2260: if ($delallowed) {
2261: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.217 raeburn 2262: } else {
1.418 raeburn 2263: $row.=' ';
1.217 raeburn 2264: }
1.430 raeburn 2265: $row.= '</td>';
1.329 raeburn 2266: }
2267: my $plaintext='';
2268: if (!$croletitle) {
1.375 raeburn 2269: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
2270: if (($showcredits) && ($credits ne '')) {
2271: $plaintext .= '<br/ ><span class="LC_nobreak">'.
2272: '<span class="LC_fontsize_small">'.
2273: &mt('Credits: [_1]',$credits).
2274: '</span></span>';
2275: }
1.329 raeburn 2276: } else {
2277: $plaintext=
1.395 bisitz 2278: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 2279: '"'.$croletitle.'"',
2280: '<br />',
2281: $croleuname.':'.$croleudom);
1.329 raeburn 2282: }
1.418 raeburn 2283: $row.= '<td>'.$plaintext.'</td>'.
2284: '<td>'.$area.'</td>'.
2285: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
2286: : ' ' ).'</td>'.
2287: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
2288: : ' ' ).'</td>';
1.329 raeburn 2289: $sortrole{$sortkey}=$envkey;
2290: $roletext{$envkey}=$row;
2291: $roleclass{$envkey}=$class;
1.418 raeburn 2292: if ($allowed) {
2293: $rolepriv{$envkey}='edit';
2294: } else {
2295: if ($context eq 'domain') {
1.420 raeburn 2296: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1.421 raeburn 2297: ($envkey=~m{^/$ccdomain/})) {
1.418 raeburn 2298: $rolepriv{$envkey}='view';
2299: }
2300: } elsif ($context eq 'course') {
2301: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
2302: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
2303: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
2304: $rolepriv{$envkey}='view';
2305: }
2306: }
2307: }
1.329 raeburn 2308: } # end of foreach (table building loop)
2309:
2310: my $rolesdisplay = 0;
2311: my %output = ();
1.377 raeburn 2312: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2313: $output{$type} = '';
2314: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2315: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2316: $output{$type}.=
2317: &Apache::loncommon::start_data_table_row().
2318: $roletext{$sortrole{$which}}.
2319: &Apache::loncommon::end_data_table_row();
1.217 raeburn 2320: }
1.329 raeburn 2321: }
2322: unless($output{$type} eq '') {
2323: $output{$type} = '<tr class="LC_info_row">'.
2324: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2325: $output{$type};
2326: $rolesdisplay = 1;
2327: }
2328: }
2329: if ($rolesdisplay == 1) {
2330: my $contextrole='';
2331: if ($env{'request.course.id'}) {
2332: if (&Apache::loncommon::course_type() eq 'Community') {
2333: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2334: } else {
1.329 raeburn 2335: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2336: }
1.329 raeburn 2337: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2338: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.470 raeburn 2339: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)/$}) {
2340: $contextrole = &mt('Existing Co-Author Roles in [_1] Authoring Space',
2341: '<i>'.$1.'_'.$2.'</i>');
1.329 raeburn 2342: } else {
1.418 raeburn 2343: if ($showall) {
2344: $contextrole = &mt('Existing Roles in this Domain');
2345: } elsif ($showactive) {
2346: $contextrole = &mt('Unexpired Roles in this Domain');
2347: } elsif ($showexpired) {
2348: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2349: }
1.329 raeburn 2350: }
1.393 raeburn 2351: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2352: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2353: &Apache::loncommon::start_data_table("LC_createuser").
1.418 raeburn 2354: &Apache::loncommon::start_data_table_header_row());
2355: if ($showall) {
2356: $r->print(
1.419 raeburn 2357: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1.418 raeburn 2358: );
2359: } elsif ($showexpired) {
2360: $r->print('<th>'.$lt{'rev'}.'</th>');
2361: }
2362: $r->print(
1.419 raeburn 2363: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2364: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2365: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2366: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2367: if ($output{$type}) {
2368: $r->print($output{$type}."\n");
1.217 raeburn 2369: }
2370: }
1.375 raeburn 2371: $r->print(&Apache::loncommon::end_data_table().
2372: '</fieldset></div>');
1.329 raeburn 2373: }
1.217 raeburn 2374: return;
2375: }
2376:
1.218 raeburn 2377: sub new_coauthor_roles {
2378: my ($r,$ccuname,$ccdomain) = @_;
2379: my $addrolesdisplay = 0;
2380: #
2381: # Co-Author
2382: #
1.470 raeburn 2383: my ($cuname,$cudom);
2384: if (($env{'request.role'} eq "au./$env{'user.domain'}/") ||
2385: ($env{'request.role'} eq "dc./$env{'user.domain'}/")) {
2386: $cuname=$env{'user.name'};
2387: $cudom=$env{'request.role.domain'};
1.218 raeburn 2388: # No sense in assigning co-author role to yourself
1.470 raeburn 2389: if ((&Apache::lonuserutils::authorpriv($cuname,$cudom)) &&
2390: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2391: $addrolesdisplay = 1;
2392: }
2393: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2394: ($cudom,$cuname) = ($1,$2);
2395: if ((&Apache::lonuserutils::coauthorpriv($cuname,$cudom)) &&
2396: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain) &&
2397: ($cudom ne $ccdomain || $cuname ne $ccuname)) {
2398: $addrolesdisplay = 1;
2399: }
2400: }
2401: if ($addrolesdisplay) {
1.218 raeburn 2402: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2403: 'cs' => "Authoring Space",
1.218 raeburn 2404: 'act' => "Activate",
2405: 'rol' => "Role",
2406: 'ext' => "Extent",
2407: 'sta' => "Start",
2408: 'end' => "End",
2409: 'cau' => "Co-Author",
2410: 'caa' => "Assistant Co-Author",
2411: 'ssd' => "Set Start Date",
2412: 'sed' => "Set End Date"
2413: );
2414: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2415: &Apache::loncommon::start_data_table()."\n".
2416: &Apache::loncommon::start_data_table_header_row()."\n".
2417: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2418: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2419: '<th>'.$lt{'end'}.'</th>'."\n".
2420: &Apache::loncommon::end_data_table_header_row()."\n".
2421: &Apache::loncommon::start_data_table_row().'
2422: <td>
1.291 bisitz 2423: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2424: </td>
2425: <td>'.$lt{'cau'}.'</td>
2426: <td>'.$cudom.'_'.$cuname.'</td>
2427: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2428: <a href=
2429: "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>
2430: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2431: <a href=
2432: "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".
2433: &Apache::loncommon::end_data_table_row()."\n".
2434: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2435: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2436: <td>'.$lt{'caa'}.'</td>
2437: <td>'.$cudom.'_'.$cuname.'</td>
2438: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2439: <a href=
2440: "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>
2441: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2442: <a href=
2443: "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".
2444: &Apache::loncommon::end_data_table_row()."\n".
2445: &Apache::loncommon::end_data_table());
2446: } elsif ($env{'request.role'} =~ /^au\./) {
2447: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2448: $env{'request.role.domain'}))) {
2449: $r->print('<span class="LC_error">'.
2450: &mt('You do not have privileges to assign co-author roles.').
2451: '</span>');
2452: } elsif (($env{'user.name'} eq $ccuname) &&
2453: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2454: $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 2455: }
1.470 raeburn 2456: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2457: if (!(&Apache::lonuserutils::coauthorpriv($2,$1))) {
2458: $r->print('<span class="LC_error">'.
2459: &mt('You do not have privileges to assign co-author roles.').
2460: '</span>');
2461: } elsif (($env{'user.name'} eq $ccuname) &&
2462: ($env{'user.domain'} eq $ccdomain)) {
2463: $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'));
2464: } elsif (($cudom eq $ccdomain) && ($cuname eq $ccuname)) {
2465: $r->print(&mt("Assigning a co-author or assistant co-author role to an Authoring Space's author is not permitted"));
2466: }
1.218 raeburn 2467: }
2468: return $addrolesdisplay;;
2469: }
2470:
2471: sub new_domain_roles {
1.357 raeburn 2472: my ($r,$ccdomain) = @_;
1.218 raeburn 2473: my $addrolesdisplay = 0;
2474: #
2475: # Domain level
2476: #
2477: my $num_domain_level = 0;
2478: my $domaintext =
2479: '<h4>'.&mt('Domain Level').'</h4>'.
2480: &Apache::loncommon::start_data_table().
2481: &Apache::loncommon::start_data_table_header_row().
2482: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2483: &mt('Extent').'</th>'.
2484: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2485: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2486: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.445 raeburn 2487: my $uprimary = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2488: my $uintdom = &Apache::lonnet::internet_dom($uprimary);
1.218 raeburn 2489: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2490: foreach my $role (@allroles) {
2491: next if ($role eq 'ad');
1.357 raeburn 2492: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2493: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1.445 raeburn 2494: if ($role eq 'dc') {
2495: unless ($thisdomain eq $env{'request.role.domain'}) {
2496: my $domprim = &Apache::lonnet::domain($thisdomain,'primary');
2497: my $intdom = &Apache::lonnet::internet_dom($domprim);
2498: next unless ($uintdom eq $intdom);
2499: }
2500: }
1.218 raeburn 2501: my $plrole=&Apache::lonnet::plaintext($role);
2502: my %lt=&Apache::lonlocal::texthash(
2503: 'ssd' => "Set Start Date",
2504: 'sed' => "Set End Date"
2505: );
2506: $num_domain_level ++;
2507: $domaintext .=
2508: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2509: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2510: <td>'.$plrole.'</td>
2511: <td>'.$thisdomain.'</td>
2512: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2513: <a href=
2514: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2515: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2516: <a href=
2517: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2518: &Apache::loncommon::end_data_table_row();
2519: }
2520: }
2521: }
2522: $domaintext.= &Apache::loncommon::end_data_table();
2523: if ($num_domain_level > 0) {
2524: $r->print($domaintext);
2525: $addrolesdisplay = 1;
2526: }
2527: return $addrolesdisplay;
2528: }
2529:
1.188 raeburn 2530: sub user_authentication {
1.451 raeburn 2531: my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
1.188 raeburn 2532: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2533: my $outcome;
1.418 raeburn 2534: my %lt=&Apache::lonlocal::texthash(
2535: 'err' => "ERROR",
2536: 'uuas' => "This user has an unrecognized authentication scheme",
2537: 'adcs' => "Please alert a domain coordinator of this situation",
2538: 'sldb' => "Please specify login data below",
2539: 'ld' => "Login Data"
2540: );
1.188 raeburn 2541: # Check for a bad authentication type
1.449 raeburn 2542: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth|lti):/) {
1.188 raeburn 2543: # bad authentication scheme
2544: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2545: &initialize_authen_forms($ccdomain,$formname);
2546:
1.190 raeburn 2547: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2548: $outcome = <<ENDBADAUTH;
2549: <script type="text/javascript" language="Javascript">
1.301 bisitz 2550: // <![CDATA[
1.188 raeburn 2551: $loginscript
1.301 bisitz 2552: // ]]>
1.188 raeburn 2553: </script>
2554: <span class="LC_error">$lt{'err'}:
2555: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2556: <h3>$lt{'ld'}</h3>
2557: $choices
2558: ENDBADAUTH
2559: } else {
2560: # This user is not allowed to modify the user's
2561: # authentication scheme, so just notify them of the problem
2562: $outcome = <<ENDBADAUTH;
2563: <span class="LC_error"> $lt{'err'}:
2564: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2565: </span>
2566: ENDBADAUTH
2567: }
2568: } else { # Authentication type is valid
1.418 raeburn 2569:
1.227 raeburn 2570: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2571: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2572: &modify_login_block($ccdomain,$currentauth);
2573: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2574: # Current user has login modification privileges
2575: $outcome =
2576: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2577: '// <![CDATA['."\n".
1.188 raeburn 2578: $loginscript."\n".
1.301 bisitz 2579: '// ]]>'."\n".
1.188 raeburn 2580: '</script>'."\n".
2581: '<h3>'.$lt{'ld'}.'</h3>'.
2582: &Apache::loncommon::start_data_table().
1.205 raeburn 2583: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2584: '<td>'.$authformnop;
1.418 raeburn 2585: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2586: $outcome .= '</td>'."\n".
2587: &Apache::loncommon::end_data_table_row().
2588: &Apache::loncommon::start_data_table_row().
2589: '<td>'.$authformcurrent.'</td>'.
2590: &Apache::loncommon::end_data_table_row()."\n";
2591: } else {
1.200 raeburn 2592: $outcome .= ' ('.$authformcurrent.')</td>'.
2593: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2594: }
1.418 raeburn 2595: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2596: foreach my $item (@authform_others) {
2597: $outcome .= &Apache::loncommon::start_data_table_row().
2598: '<td>'.$item.'</td>'.
2599: &Apache::loncommon::end_data_table_row()."\n";
2600: }
1.188 raeburn 2601: }
1.205 raeburn 2602: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2603: } else {
1.451 raeburn 2604: if (($currentauth =~ /^internal:/) &&
2605: (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
2606: $outcome = <<"ENDJS";
2607: <script type="text/javascript">
2608: // <![CDATA[
2609: function togglePwd(form) {
2610: if (form.newintpwd.length) {
2611: if (document.getElementById('LC_ownersetpwd')) {
2612: for (var i=0; i<form.newintpwd.length; i++) {
2613: if (form.newintpwd[i].checked) {
2614: if (form.newintpwd[i].value == 1) {
2615: document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
2616: } else {
2617: document.getElementById('LC_ownersetpwd').style.display = 'none';
2618: }
2619: }
2620: }
2621: }
2622: }
2623: }
2624: // ]]>
2625: </script>
2626: ENDJS
2627:
2628: $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
2629: &Apache::loncommon::start_data_table().
2630: &Apache::loncommon::start_data_table_row().
2631: '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
2632: '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
2633: &mt('No').'</label>'.(' 'x2).
2634: '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
2635: '<div id="LC_ownersetpwd" style="display:none">'.
2636: ' '.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
2637: '<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>'.
2638: &Apache::loncommon::end_data_table_row().
2639: &Apache::loncommon::end_data_table();
2640: }
1.418 raeburn 2641: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2642: # Current user has rights to view domain preferences for user's domain
2643: my $result;
2644: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2645: my ($krbver,$krbrealm) = ($1,$2);
2646: if ($krbrealm eq '') {
2647: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2648: } else {
2649: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.426 raeburn 2650: $krbrealm,$krbver);
1.418 raeburn 2651: }
2652: } elsif ($currentauth =~ /^internal:/) {
2653: $result = &mt('Currently internally authenticated.');
2654: } elsif ($currentauth =~ /^localauth:/) {
2655: $result = &mt('Currently using local (institutional) authentication.');
2656: } elsif ($currentauth =~ /^unix:/) {
2657: $result = &mt('Currently Filesystem Authenticated.');
1.449 raeburn 2658: } elsif ($currentauth =~ /^lti:/) {
1.451 raeburn 2659: $result = &mt('Currently LTI authenticated.');
1.418 raeburn 2660: }
2661: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2662: &Apache::loncommon::start_data_table().
2663: &Apache::loncommon::start_data_table_row().
2664: '<td>'.$result.'</td>'.
2665: &Apache::loncommon::end_data_table_row()."\n".
2666: &Apache::loncommon::end_data_table();
2667: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2668: my %lt=&Apache::lonlocal::texthash(
2669: 'ccld' => "Change Current Login Data",
2670: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2671: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2672: );
2673: $outcome .= <<ENDNOPRIV;
2674: <h3>$lt{'ccld'}</h3>
2675: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2676: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2677: ENDNOPRIV
2678: }
2679: }
2680: } ## End of "check for bad authentication type" logic
2681: return $outcome;
2682: }
2683:
1.187 raeburn 2684: sub modify_login_block {
2685: my ($dom,$currentauth) = @_;
2686: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2687: my ($authnum,%can_assign) =
2688: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2689: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2690: if ($currentauth=~/^krb(4|5):/) {
2691: $authformcurrent=$authformkrb;
2692: if ($can_assign{'int'}) {
1.205 raeburn 2693: push(@authform_others,$authformint);
1.187 raeburn 2694: }
2695: if ($can_assign{'loc'}) {
1.205 raeburn 2696: push(@authform_others,$authformloc);
1.187 raeburn 2697: }
1.449 raeburn 2698: if ($can_assign{'lti'}) {
2699: push(@authform_others,$authformlti);
2700: }
1.187 raeburn 2701: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2702: $show_override_msg = 1;
2703: }
2704: } elsif ($currentauth=~/^internal:/) {
2705: $authformcurrent=$authformint;
2706: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2707: push(@authform_others,$authformkrb);
1.187 raeburn 2708: }
2709: if ($can_assign{'loc'}) {
1.205 raeburn 2710: push(@authform_others,$authformloc);
1.187 raeburn 2711: }
1.449 raeburn 2712: if ($can_assign{'lti'}) {
2713: push(@authform_others,$authformlti);
2714: }
1.187 raeburn 2715: if ($can_assign{'int'}) {
2716: $show_override_msg = 1;
2717: }
2718: } elsif ($currentauth=~/^unix:/) {
2719: $authformcurrent=$authformfsys;
2720: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2721: push(@authform_others,$authformkrb);
1.187 raeburn 2722: }
2723: if ($can_assign{'int'}) {
1.205 raeburn 2724: push(@authform_others,$authformint);
1.187 raeburn 2725: }
2726: if ($can_assign{'loc'}) {
1.205 raeburn 2727: push(@authform_others,$authformloc);
1.187 raeburn 2728: }
1.449 raeburn 2729: if ($can_assign{'lti'}) {
2730: push(@authform_others,$authformlti);
2731: }
1.187 raeburn 2732: if ($can_assign{'fsys'}) {
2733: $show_override_msg = 1;
2734: }
2735: } elsif ($currentauth=~/^localauth:/) {
2736: $authformcurrent=$authformloc;
2737: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2738: push(@authform_others,$authformkrb);
1.187 raeburn 2739: }
2740: if ($can_assign{'int'}) {
1.205 raeburn 2741: push(@authform_others,$authformint);
1.187 raeburn 2742: }
1.449 raeburn 2743: if ($can_assign{'lti'}) {
2744: push(@authform_others,$authformlti);
2745: }
1.187 raeburn 2746: if ($can_assign{'loc'}) {
2747: $show_override_msg = 1;
2748: }
1.449 raeburn 2749: } elsif ($currentauth=~/^lti:/) {
2750: $authformcurrent=$authformlti;
2751: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2752: push(@authform_others,$authformkrb);
2753: }
2754: if ($can_assign{'int'}) {
2755: push(@authform_others,$authformint);
2756: }
2757: if ($can_assign{'loc'}) {
2758: push(@authform_others,$authformloc);
2759: }
1.187 raeburn 2760: }
2761: if ($show_override_msg) {
1.205 raeburn 2762: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2763: '</td></tr>'."\n".
2764: '<tr><td> </td>'.
2765: '<td><b>'.&mt('Currently in use').'</b></td>'.
2766: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2767: &mt('will override current values').
1.205 raeburn 2768: '</span></td></tr></table>';
1.187 raeburn 2769: }
1.205 raeburn 2770: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2771: }
2772:
1.188 raeburn 2773: sub personal_data_display {
1.470 raeburn 2774: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$readonly,$rolesarray,$now,
1.456 raeburn 2775: $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
1.470 raeburn 2776: my ($output,%userenv,%canmodify,%canmodify_status,$disabled);
1.219 raeburn 2777: my @userinfo = ('firstname','middlename','lastname','generation',
2778: 'permanentemail','id');
1.252 raeburn 2779: my $rowcount = 0;
2780: my $editable = 0;
1.391 raeburn 2781: my %textboxsize = (
2782: firstname => '15',
2783: middlename => '15',
2784: lastname => '15',
2785: generation => '5',
2786: permanentemail => '25',
2787: id => '15',
2788: );
2789:
2790: my %lt=&Apache::lonlocal::texthash(
2791: 'pd' => "Personal Data",
2792: 'firstname' => "First Name",
2793: 'middlename' => "Middle Name",
2794: 'lastname' => "Last Name",
2795: 'generation' => "Generation",
2796: 'permanentemail' => "Permanent e-mail address",
2797: 'id' => "Student/Employee ID",
2798: 'lg' => "Login Data",
2799: 'inststatus' => "Affiliation",
2800: 'email' => 'E-mail address',
2801: 'valid' => 'Validation',
1.442 raeburn 2802: 'username' => 'Username',
1.391 raeburn 2803: );
2804:
2805: %canmodify_status =
1.286 raeburn 2806: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2807: ['inststatus'],$rolesarray);
1.253 raeburn 2808: if (!$newuser) {
1.188 raeburn 2809: # Get the users information
2810: %userenv = &Apache::lonnet::get('environment',
2811: ['firstname','middlename','lastname','generation',
1.286 raeburn 2812: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2813: %canmodify =
2814: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2815: \@userinfo,$rolesarray);
1.257 raeburn 2816: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2817: if ($newuser eq 'email') {
1.396 raeburn 2818: if (ref($emailusername) eq 'HASH') {
2819: if (ref($emailusername->{$usertype}) eq 'HASH') {
2820: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.442 raeburn 2821: @userinfo = ();
1.396 raeburn 2822: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2823: foreach my $field (@{$infofields}) {
2824: if ($emailusername->{$usertype}->{$field}) {
2825: push(@userinfo,$field);
2826: $canmodify{$field} = 1;
2827: unless ($textboxsize{$field}) {
2828: $textboxsize{$field} = 25;
2829: }
2830: unless ($lt{$field}) {
2831: $lt{$field} = $infotitles->{$field};
2832: }
2833: if ($emailusername->{$usertype}->{$field} eq 'required') {
2834: $lt{$field} .= '<b>*</b>';
2835: }
1.391 raeburn 2836: }
2837: }
2838: }
2839: }
2840: }
2841: } else {
2842: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2843: $inst_results,$rolesarray);
2844: }
1.470 raeburn 2845: } elsif ($readonly) {
2846: $disabled = ' disabled="disabled"';
1.188 raeburn 2847: }
1.391 raeburn 2848:
1.188 raeburn 2849: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2850: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2851: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2852: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.443 raeburn 2853: my $size = 25;
1.442 raeburn 2854: if ($condition) {
1.443 raeburn 2855: if ($condition =~ /^\@[^\@]+$/) {
2856: $size = 10;
1.442 raeburn 2857: } else {
2858: undef($condition);
2859: }
1.443 raeburn 2860: }
2861: if ($excluded) {
2862: unless ($excluded =~ /^\@[^\@]+$/) {
2863: undef($condition);
2864: }
1.442 raeburn 2865: }
1.396 raeburn 2866: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2867: 'LC_oddrow_value')."\n".
1.443 raeburn 2868: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2869: if ($condition) {
2870: $output .= $condition;
2871: } elsif ($excluded) {
2872: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2873: $excluded).'</span>';
2874: }
2875: if ($usernameset eq 'first') {
2876: $output .= '<br /><span style="font-size: smaller">';
2877: if ($condition) {
2878: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2879: $condition);
2880: } else {
2881: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2882: }
2883: $output .= '</span>';
2884: }
1.391 raeburn 2885: $rowcount ++;
2886: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.460 raeburn 2887: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="new-password" />';
2888: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="new-password" />';
1.396 raeburn 2889: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2890: 'LC_pick_box_title',
2891: 'LC_oddrow_value')."\n".
2892: $upassone."\n".
2893: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2894: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2895: 'LC_pick_box_title',
2896: 'LC_oddrow_value')."\n".
2897: $upasstwo.
2898: &Apache::lonhtmlcommon::row_closure()."\n";
1.443 raeburn 2899: if ($usernameset eq 'free') {
2900: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
1.442 raeburn 2901: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
1.455 raeburn 2902: '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
2903: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
2904: &mt('Yes').'</label>'.(' 'x2).
2905: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
2906: &mt('No').'</label></span>'."\n".
1.442 raeburn 2907: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2908: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2909: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2910: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2911: $rowcount ++;
2912: }
1.391 raeburn 2913: }
1.188 raeburn 2914: foreach my $item (@userinfo) {
2915: my $rowtitle = $lt{$item};
1.252 raeburn 2916: my $hiderow = 0;
1.188 raeburn 2917: if ($item eq 'generation') {
2918: $rowtitle = $genhelp.$rowtitle;
2919: }
1.252 raeburn 2920: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2921: if ($newuser) {
1.210 raeburn 2922: if (ref($inst_results) eq 'HASH') {
2923: if ($inst_results->{$item} ne '') {
1.252 raeburn 2924: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2925: } else {
1.252 raeburn 2926: if ($context eq 'selfcreate') {
1.391 raeburn 2927: if ($canmodify{$item}) {
1.394 raeburn 2928: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2929: $editable ++;
2930: } else {
2931: $hiderow = 1;
2932: }
1.253 raeburn 2933: } else {
1.470 raeburn 2934: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value=""'.$disabled.' />';
1.252 raeburn 2935: }
1.210 raeburn 2936: }
1.188 raeburn 2937: } else {
1.252 raeburn 2938: if ($context eq 'selfcreate') {
1.401 raeburn 2939: if ($canmodify{$item}) {
2940: if ($newuser eq 'email') {
2941: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2942: } else {
1.401 raeburn 2943: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2944: }
1.401 raeburn 2945: $editable ++;
2946: } else {
2947: $hiderow = 1;
1.252 raeburn 2948: }
1.253 raeburn 2949: } else {
1.470 raeburn 2950: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value=""'.$disabled.' />';
1.252 raeburn 2951: }
1.188 raeburn 2952: }
2953: } else {
1.219 raeburn 2954: if ($canmodify{$item}) {
1.252 raeburn 2955: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2956: if (($item eq 'id') && (!$newuser)) {
2957: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2958: }
1.188 raeburn 2959: } else {
1.252 raeburn 2960: $row .= $userenv{$item};
1.188 raeburn 2961: }
2962: }
1.252 raeburn 2963: $row .= &Apache::lonhtmlcommon::row_closure(1);
2964: if (!$hiderow) {
2965: $output .= $row;
2966: $rowcount ++;
2967: }
1.188 raeburn 2968: }
1.286 raeburn 2969: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2970: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2971: if (ref($types) eq 'ARRAY') {
2972: if (@{$types} > 0) {
2973: my ($hiderow,$shown);
2974: if ($canmodify_status{'inststatus'}) {
2975: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2976: } else {
2977: if ($userenv{'inststatus'} eq '') {
2978: $hiderow = 1;
1.334 raeburn 2979: } else {
2980: my @showitems;
2981: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2982: if (exists($usertypes->{$item})) {
2983: push(@showitems,$usertypes->{$item});
2984: } else {
2985: push(@showitems,$item);
2986: }
2987: }
2988: if (@showitems) {
2989: $shown = join(', ',@showitems);
2990: } else {
2991: $hiderow = 1;
2992: }
1.286 raeburn 2993: }
2994: }
2995: if (!$hiderow) {
1.389 bisitz 2996: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2997: $shown.&Apache::lonhtmlcommon::row_closure(1);
2998: if ($context eq 'selfcreate') {
2999: $rowcount ++;
3000: }
3001: $output .= $row;
3002: }
3003: }
3004: }
3005: }
1.391 raeburn 3006: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
3007: if ($captchaform) {
1.410 raeburn 3008: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
3009: 'LC_pick_box_title')."\n".
1.456 raeburn 3010: $captchaform."\n".'<br /><br />'.
1.391 raeburn 3011: &Apache::lonhtmlcommon::row_closure(1);
3012: $rowcount ++;
3013: }
1.456 raeburn 3014: if ($showsubmit) {
3015: my $submit_text = &mt('Create account');
3016: $output .= &Apache::lonhtmlcommon::row_title()."\n".
3017: '<br /><input type="submit" name="createaccount" value="'.
3018: $submit_text.'" />';
3019: if ($usertype ne '') {
3020: $output .= '<input type="hidden" name="type" value="'.
3021: &HTML::Entities::encode($usertype,'\'<>"&').'" />';
3022: }
3023: $output .= &Apache::lonhtmlcommon::row_closure(1);
3024: }
1.391 raeburn 3025: }
1.188 raeburn 3026: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 3027: if (wantarray) {
1.252 raeburn 3028: if ($context eq 'selfcreate') {
3029: return($output,$rowcount,$editable);
3030: } else {
1.388 bisitz 3031: return $output;
1.252 raeburn 3032: }
1.206 raeburn 3033: } else {
3034: return $output;
3035: }
1.188 raeburn 3036: }
3037:
1.286 raeburn 3038: sub pick_inst_statuses {
3039: my ($curr,$usertypes,$types) = @_;
3040: my ($output,$rem,@currtypes);
3041: if ($curr ne '') {
3042: @currtypes = map { &unescape($_); } split(/:/,$curr);
3043: }
3044: my $numinrow = 2;
3045: if (ref($types) eq 'ARRAY') {
3046: $output = '<table>';
3047: my $lastcolspan;
3048: for (my $i=0; $i<@{$types}; $i++) {
3049: if (defined($usertypes->{$types->[$i]})) {
3050: my $rem = $i%($numinrow);
3051: if ($rem == 0) {
3052: if ($i<@{$types}-1) {
3053: if ($i > 0) {
3054: $output .= '</tr>';
3055: }
3056: $output .= '<tr>';
3057: }
3058: } elsif ($i==@{$types}-1) {
3059: my $colsleft = $numinrow - $rem;
3060: if ($colsleft > 1) {
3061: $lastcolspan = ' colspan="'.$colsleft.'"';
3062: }
3063: }
3064: my $check = ' ';
3065: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
3066: $check = ' checked="checked" ';
3067: }
3068: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
3069: '<span class="LC_nobreak"><label>'.
3070: '<input type="checkbox" name="inststatus" '.
3071: 'value="'.$types->[$i].'"'.$check.'/>'.
3072: $usertypes->{$types->[$i]}.'</label></span></td>';
3073: }
3074: }
3075: $output .= '</tr></table>';
3076: }
3077: return $output;
3078: }
3079:
1.257 raeburn 3080: sub selfcreate_canmodify {
3081: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
3082: if (ref($inst_results) eq 'HASH') {
3083: my @inststatuses = &get_inststatuses($inst_results);
3084: if (@inststatuses == 0) {
3085: @inststatuses = ('default');
3086: }
3087: $rolesarray = \@inststatuses;
3088: }
3089: my %canmodify =
3090: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
3091: $rolesarray);
3092: return %canmodify;
3093: }
3094:
1.252 raeburn 3095: sub get_inststatuses {
3096: my ($insthashref) = @_;
3097: my @inststatuses = ();
3098: if (ref($insthashref) eq 'HASH') {
3099: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
3100: @inststatuses = @{$insthashref->{'inststatus'}};
3101: }
3102: }
3103: return @inststatuses;
3104: }
3105:
1.4 www 3106: # ================================================================= Phase Three
1.42 matthew 3107: sub update_user_data {
1.451 raeburn 3108: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 3109: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
3110: $env{'form.ccdomain'});
1.27 matthew 3111: # Error messages
1.188 raeburn 3112: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 3113: my $end = '</span><br /><br />';
3114: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 3115: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 3116: &mt('Return to previous page').'</a>'.
3117: &Apache::loncommon::end_page();
3118: my $now = time;
1.40 www 3119: my $title;
1.101 albertel 3120: if (exists($env{'form.makeuser'})) {
1.40 www 3121: $title='Set Privileges for New User';
3122: } else {
3123: $title='Modify User Privileges';
3124: }
1.213 raeburn 3125: my $newuser = 0;
1.160 raeburn 3126: my ($jsback,$elements) = &crumb_utilities();
3127: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 3128: '// <![CDATA['."\n".
3129: $jsback."\n".
3130: '// ]]>'."\n".
3131: '</script>'."\n";
1.422 raeburn 3132: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 3133: push (@{$brcrum},
3134: {href => "javascript:backPage(document.userupdate)",
3135: text => $breadcrumb_text{'search'},
3136: faq => 282,
3137: bug => 'Instructor Interface',}
3138: );
3139: if ($env{'form.prevphase'} eq 'userpicked') {
3140: push(@{$brcrum},
3141: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
3142: text => $breadcrumb_text{'userpicked'},
3143: faq => 282,
3144: bug => 'Instructor Interface',});
1.233 raeburn 3145: }
1.224 raeburn 3146: my $helpitem = 'Course_Change_Privileges';
3147: if ($env{'form.action'} eq 'singlestudent') {
3148: $helpitem = 'Course_Add_Student';
1.439 raeburn 3149: } elsif ($context eq 'author') {
3150: $helpitem = 'Author_Change_Privileges';
3151: } elsif ($context eq 'domain') {
3152: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 3153: }
1.351 raeburn 3154: push(@{$brcrum},
3155: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
3156: text => $breadcrumb_text{'modify'},
3157: faq => 282,
3158: bug => 'Instructor Interface',},
3159: {href => "/adm/createuser",
3160: text => "Result",
3161: faq => 282,
3162: bug => 'Instructor Interface',
3163: help => $helpitem});
3164: my $args = {bread_crumbs => $brcrum,
3165: bread_crumbs_component => 'User Management'};
3166: if ($env{'form.popup'}) {
3167: $args->{'no_nav_bar'} = 1;
3168: }
3169: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 3170: $r->print(&update_result_form($uhome));
1.27 matthew 3171: # Check Inputs
1.101 albertel 3172: if (! $env{'form.ccuname'} ) {
1.193 raeburn 3173: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 3174: return;
3175: }
1.138 albertel 3176: if ( $env{'form.ccuname'} ne
3177: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 3178: $r->print($error.&mt('Invalid login name.').' '.
3179: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 3180: $end.$rtnlink);
1.27 matthew 3181: return;
3182: }
1.101 albertel 3183: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 3184: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 3185: return;
3186: }
1.138 albertel 3187: if ( $env{'form.ccdomain'} ne
3188: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 3189: $r->print($error.&mt('Invalid domain name.').' '.
3190: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 3191: $end.$rtnlink);
1.27 matthew 3192: return;
3193: }
1.219 raeburn 3194: if ($uhome eq 'no_host') {
3195: $newuser = 1;
3196: }
1.101 albertel 3197: if (! exists($env{'form.makeuser'})) {
1.29 matthew 3198: # Modifying an existing user, so check the validity of the name
3199: if ($uhome eq 'no_host') {
1.389 bisitz 3200: $r->print(
3201: $error
3202: .'<p class="LC_error">'
3203: .&mt('Unable to determine home server for [_1] in domain [_2].',
3204: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
3205: .'</p>');
1.29 matthew 3206: return;
3207: }
3208: }
1.27 matthew 3209: # Determine authentication method and password for the user being modified
3210: my $amode='';
3211: my $genpwd='';
1.101 albertel 3212: if ($env{'form.login'} eq 'krb') {
1.41 albertel 3213: $amode='krb';
1.101 albertel 3214: $amode.=$env{'form.krbver'};
3215: $genpwd=$env{'form.krbarg'};
3216: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 3217: $amode='internal';
1.101 albertel 3218: $genpwd=$env{'form.intarg'};
3219: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 3220: $amode='unix';
1.101 albertel 3221: $genpwd=$env{'form.fsysarg'};
3222: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 3223: $amode='localauth';
1.101 albertel 3224: $genpwd=$env{'form.locarg'};
1.27 matthew 3225: $genpwd=" " if (!$genpwd);
1.449 raeburn 3226: } elsif ($env{'form.login'} eq 'lti') {
3227: $amode='lti';
3228: $genpwd=" ";
1.101 albertel 3229: } elsif (($env{'form.login'} eq 'nochange') ||
3230: ($env{'form.login'} eq '' )) {
1.34 matthew 3231: # There is no need to tell the user we did not change what they
3232: # did not ask us to change.
1.35 matthew 3233: # If they are creating a new user but have not specified login
3234: # information this will be caught below.
1.30 matthew 3235: } else {
1.367 golterma 3236: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
3237: return;
1.27 matthew 3238: }
1.164 albertel 3239:
1.188 raeburn 3240: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 3241: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
3242: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
3243: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 3244:
1.193 raeburn 3245: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 3246: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.470 raeburn 3247: my @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.449 raeburn 3248: my @requestcourses = ('official','unofficial','community','textbook','placement','lti');
1.362 raeburn 3249: my @requestauthor = ('requestauthor');
1.477 raeburn 3250: my @authordefaults = ('webdav','editors','archive');
1.286 raeburn 3251: my ($othertitle,$usertypes,$types) =
3252: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 3253: my %canmodify_status =
3254: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
3255: ['inststatus']);
1.101 albertel 3256: if ($env{'form.makeuser'}) {
1.164 albertel 3257: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 3258: # Check for the authentication mode and password
3259: if (! $amode || ! $genpwd) {
1.193 raeburn 3260: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 3261: return;
1.18 albertel 3262: }
1.29 matthew 3263: # Determine desired host
1.101 albertel 3264: my $desiredhost = $env{'form.hserver'};
1.29 matthew 3265: if (lc($desiredhost) eq 'default') {
3266: $desiredhost = undef;
3267: } else {
1.147 albertel 3268: my %home_servers =
3269: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 3270: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 3271: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
3272: return;
3273: }
3274: }
3275: # Check ID format
3276: my %checkhash;
3277: my %checks = ('id' => 1);
3278: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 3279: 'newuser' => $newuser,
1.196 raeburn 3280: 'id' => $env{'form.cid'},
1.193 raeburn 3281: );
1.196 raeburn 3282: if ($env{'form.cid'} ne '') {
3283: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
3284: \%rulematch,\%inst_results,\%curr_rules);
3285: if (ref($alerts{'id'}) eq 'HASH') {
3286: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
3287: my $domdesc =
3288: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
3289: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
3290: my $userchkmsg;
3291: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
3292: $userchkmsg =
3293: &Apache::loncommon::instrule_disallow_msg('id',
3294: $domdesc,1).
3295: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
3296: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
3297: }
3298: $r->print($error.&mt('Invalid ID format').$end.
3299: $userchkmsg.$rtnlink);
3300: return;
3301: }
3302: }
1.29 matthew 3303: }
3304: }
1.367 golterma 3305: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 3306: # Call modifyuser
3307: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 3308: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 3309: $amode,$genpwd,$env{'form.cfirstname'},
3310: $env{'form.cmiddlename'},$env{'form.clastname'},
3311: $env{'form.cgeneration'},undef,$desiredhost,
3312: $env{'form.cpermanentemail'});
1.77 www 3313: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 3314: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 3315: $env{'form.ccdomain'});
1.334 raeburn 3316: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 3317: if ($uhome ne 'no_host') {
1.334 raeburn 3318: if ($context eq 'domain') {
1.378 raeburn 3319: foreach my $name ('portfolio','author') {
3320: if ($env{'form.custom_'.$name.'quota'} == 1) {
3321: if ($env{'form.'.$name.'quota'} eq '') {
3322: $newcustom{$name.'quota'} = 0;
3323: } else {
3324: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
3325: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
3326: }
3327: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
3328: $changed{$name.'quota'} = 1;
3329: }
1.334 raeburn 3330: }
3331: }
3332: foreach my $item (@usertools) {
3333: if ($env{'form.custom'.$item} == 1) {
3334: $newcustom{$item} = $env{'form.tools_'.$item};
3335: $changed{$item} = &tool_admin($item,$newcustom{$item},
3336: \%changeHash,'tools');
3337: }
1.267 raeburn 3338: }
1.334 raeburn 3339: foreach my $item (@requestcourses) {
1.341 raeburn 3340: if ($env{'form.custom'.$item} == 1) {
3341: $newcustom{$item} = $env{'form.crsreq_'.$item};
3342: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
3343: $newcustom{$item} .= '=';
1.383 raeburn 3344: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
3345: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 3346: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
3347: }
1.334 raeburn 3348: }
1.341 raeburn 3349: $changed{$item} = &tool_admin($item,$newcustom{$item},
3350: \%changeHash,'requestcourses');
1.334 raeburn 3351: }
1.275 raeburn 3352: }
1.362 raeburn 3353: if ($env{'form.customrequestauthor'} == 1) {
3354: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
3355: $changed{'requestauthor'} = &tool_admin('requestauthor',
3356: $newcustom{'requestauthor'},
3357: \%changeHash,'requestauthor');
3358: }
1.470 raeburn 3359: if ($env{'form.customeditors'} == 1) {
3360: my @editors;
3361: my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
3362: if (@posseditors) {
3363: foreach my $editor (@posseditors) {
3364: if (grep(/^\Q$editor\E$/,@posseditors)) {
3365: unless (grep(/^\Q$editor\E$/,@editors)) {
3366: push(@editors,$editor);
3367: }
3368: }
3369: }
3370: }
3371: if (@editors) {
3372: @editors = sort(@editors);
3373: $changed{'editors'} = &tool_admin('editors',join(',',@editors),
3374: \%changeHash,'authordefaults');
3375: }
3376: }
3377: if ($env{'form.customwebdav'} == 1) {
3378: $newcustom{'webdav'} = $env{'form.authordefaults_webdav'};
3379: $changed{'webdav'} = &tool_admin('webdav',$newcustom{'webdav'},
1.479 raeburn 3380: \%changeHash,'authordefaults');
1.470 raeburn 3381: }
1.480 raeburn 3382: if ($env{'form.customarchive'} == 1) {
1.477 raeburn 3383: $newcustom{'archive'} = $env{'form.authordefaults_archive'};
3384: $changed{'archive'} = &tool_admin('archive',$newcustom{'archive'},
1.479 raeburn 3385: \%changeHash,'authordefaults');
1.477 raeburn 3386:
3387: }
1.275 raeburn 3388: }
1.334 raeburn 3389: if ($canmodify_status{'inststatus'}) {
3390: if (exists($env{'form.inststatus'})) {
3391: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3392: if (@inststatuses > 0) {
3393: $changeHash{'inststatus'} = join(',',@inststatuses);
3394: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 3395: }
3396: }
1.232 raeburn 3397: }
1.334 raeburn 3398: if (keys(%changed)) {
3399: foreach my $item (@userinfo) {
3400: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 3401: }
1.267 raeburn 3402: my $chgresult =
3403: &Apache::lonnet::put('environment',\%changeHash,
3404: $env{'form.ccdomain'},$env{'form.ccuname'});
1.470 raeburn 3405: }
1.232 raeburn 3406: }
1.454 raeburn 3407: $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
1.219 raeburn 3408: &Apache::lonnet::hostname($uhome));
1.101 albertel 3409: } elsif (($env{'form.login'} ne 'nochange') &&
3410: ($env{'form.login'} ne '' )) {
1.27 matthew 3411: # Modify user privileges
3412: if (! $amode || ! $genpwd) {
1.193 raeburn 3413: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 3414: return;
1.20 harris41 3415: }
1.395 bisitz 3416: # Only allow authentication modification if the person has authority
1.101 albertel 3417: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 3418: $r->print('Modifying authentication: '.
1.31 matthew 3419: &Apache::lonnet::modifyuserauth(
1.101 albertel 3420: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 3421: $amode,$genpwd));
1.454 raeburn 3422: $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
1.101 albertel 3423: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 3424: } else {
1.27 matthew 3425: # Okay, this is a non-fatal error.
1.452 raeburn 3426: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 3427: }
1.451 raeburn 3428: } elsif (($env{'form.intarg'} ne '') &&
3429: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
3430: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3431: $r->print('Modifying authentication: '.
3432: &Apache::lonnet::modifyuserauth(
3433: $env{'form.ccdomain'},$env{'form.ccuname'},
3434: 'internal',$env{'form.intarg'}));
1.28 matthew 3435: }
1.344 bisitz 3436: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3437: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3438: ##
1.375 raeburn 3439: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3440: if ($context eq 'course') {
1.375 raeburn 3441: ($cnum,$cdom) =
3442: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3443: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3444: if ($showcredits) {
3445: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3446: }
1.213 raeburn 3447: }
1.101 albertel 3448: if (! $env{'form.makeuser'} ) {
1.28 matthew 3449: # Check for need to change
3450: my %userenv = &Apache::lonnet::get
1.134 raeburn 3451: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3452: 'id','permanentemail','portfolioquota','authorquota','inststatus',
1.459 raeburn 3453: 'tools.aboutme','tools.blog','tools.webdav',
1.470 raeburn 3454: 'tools.portfolio','tools.timezone','tools.portaccess',
1.477 raeburn 3455: 'authormanagers','authoreditors','authorarchive','requestauthor',
1.361 raeburn 3456: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3457: 'requestcourses.community','requestcourses.textbook',
1.470 raeburn 3458: 'requestcourses.placement','requestcourses.lti',
1.384 raeburn 3459: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3460: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.471 raeburn 3461: 'reqcrsotherdom.placement','domcoord.author'],
1.160 raeburn 3462: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3463: my ($tmp) = keys(%userenv);
3464: if ($tmp =~ /^(con_lost|error)/i) {
3465: %userenv = ();
3466: }
1.471 raeburn 3467: unless (($userenv{'domcoord.author'} eq 'blocked') &&
3468: (($env{'user.name'} ne $env{'form.ccuname'}) ||
3469: ($env{'user.domain'} ne $env{'form.ccdomain'}))) {
3470: push(@authordefaults,'managers');
3471: }
1.206 raeburn 3472: my $no_forceid_alert;
3473: # Check to see if user information can be changed
3474: my %domconfig =
3475: &Apache::lonnet::get_dom('configuration',['usermodification'],
3476: $env{'form.ccdomain'});
1.213 raeburn 3477: my @statuses = ('active','future');
3478: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3479: my ($auname,$audom);
1.220 raeburn 3480: if ($context eq 'author') {
1.206 raeburn 3481: $auname = $env{'user.name'};
3482: $audom = $env{'user.domain'};
3483: }
3484: foreach my $item (keys(%roles)) {
1.220 raeburn 3485: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3486: if ($context eq 'course') {
3487: if ($cnum ne '' && $cdom ne '') {
3488: if ($rolenum eq $cnum && $roledom eq $cdom) {
3489: if (!grep(/^\Q$role\E$/,@userroles)) {
3490: push(@userroles,$role);
3491: }
3492: }
3493: }
3494: } elsif ($context eq 'author') {
3495: if ($rolenum eq $auname && $roledom eq $audom) {
1.461 raeburn 3496: if (!grep(/^\Q$role\E$/,@userroles)) {
1.206 raeburn 3497: push(@userroles,$role);
3498: }
3499: }
3500: }
3501: }
1.220 raeburn 3502: if ($env{'form.action'} eq 'singlestudent') {
3503: if (!grep(/^st$/,@userroles)) {
3504: push(@userroles,'st');
3505: }
3506: } else {
3507: # Check for course or co-author roles being activated or re-enabled
3508: if ($context eq 'author' || $context eq 'course') {
3509: foreach my $key (keys(%env)) {
3510: if ($context eq 'author') {
3511: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3512: if (!grep(/^\Q$1\E$/,@userroles)) {
3513: push(@userroles,$1);
3514: }
3515: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3516: if (!grep(/^\Q$1\E$/,@userroles)) {
3517: push(@userroles,$1);
3518: }
1.206 raeburn 3519: }
1.220 raeburn 3520: } elsif ($context eq 'course') {
3521: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3522: if (!grep(/^\Q$1\E$/,@userroles)) {
3523: push(@userroles,$1);
3524: }
3525: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3526: if (!grep(/^\Q$1\E$/,@userroles)) {
3527: push(@userroles,$1);
3528: }
1.206 raeburn 3529: }
3530: }
3531: }
3532: }
3533: }
3534: #Check to see if we can change personal data for the user
3535: my (@mod_disallowed,@longroles);
3536: foreach my $role (@userroles) {
3537: if ($role eq 'cr') {
3538: push(@longroles,'Custom');
3539: } else {
1.318 raeburn 3540: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3541: }
3542: }
1.219 raeburn 3543: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3544: foreach my $item (@userinfo) {
1.28 matthew 3545: # Strip leading and trailing whitespace
1.203 raeburn 3546: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3547: if (!$canmodify{$item}) {
1.207 raeburn 3548: if (defined($env{'form.c'.$item})) {
3549: if ($env{'form.c'.$item} ne $userenv{$item}) {
3550: push(@mod_disallowed,$item);
3551: }
1.206 raeburn 3552: }
3553: $env{'form.c'.$item} = $userenv{$item};
3554: }
1.28 matthew 3555: }
1.259 bisitz 3556: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3557: my $forceid = $env{'form.forceid'};
3558: my $recurseid = $env{'form.recurseid'};
3559: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3560: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3561: $env{'form.ccuname'});
3562: if (($uidhash{$env{'form.ccuname'}}) &&
3563: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3564: (!$forceid)) {
3565: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3566: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3567: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3568: .'<br />'
3569: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3570: .'<br />'."\n";
1.203 raeburn 3571: }
3572: }
3573: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3574: my $checkhash;
3575: my $checks = { 'id' => 1 };
3576: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3577: { 'newuser' => $newuser,
3578: 'id' => $env{'form.cid'},
3579: };
3580: &Apache::loncommon::user_rule_check($checkhash,$checks,
3581: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3582: if (ref($alerts{'id'}) eq 'HASH') {
3583: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3584: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3585: }
3586: }
3587: }
1.378 raeburn 3588: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3589: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3590: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3591: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3592: @disporder = ('inststatus');
3593: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.470 raeburn 3594: push(@disporder,('requestcourses','requestauthor','authordefaults'));
1.334 raeburn 3595: } else {
3596: push(@disporder,'reqcrsotherdom');
3597: }
3598: push(@disporder,('quota','tools'));
1.338 raeburn 3599: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3600: foreach my $name ('portfolio','author') {
3601: ($olddefquota{$name},$oldsettingstatus{$name}) =
3602: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3603: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3604: }
1.334 raeburn 3605: my %canshow;
1.220 raeburn 3606: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3607: $canshow{'quota'} = 1;
1.220 raeburn 3608: }
1.267 raeburn 3609: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3610: $canshow{'tools'} = 1;
1.267 raeburn 3611: }
1.275 raeburn 3612: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3613: $canshow{'requestcourses'} = 1;
1.300 raeburn 3614: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3615: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3616: }
1.286 raeburn 3617: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3618: $canshow{'inststatus'} = 1;
1.286 raeburn 3619: }
1.362 raeburn 3620: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3621: $canshow{'requestauthor'} = 1;
1.470 raeburn 3622: $canshow{'authordefaults'} = 1;
1.362 raeburn 3623: }
1.267 raeburn 3624: my (%changeHash,%changed);
1.286 raeburn 3625: if ($oldinststatus eq '') {
1.334 raeburn 3626: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3627: } else {
3628: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3629: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3630: } else {
1.334 raeburn 3631: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3632: }
3633: }
3634: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3635: if ($canmodify_status{'inststatus'}) {
3636: $canshow{'inststatus'} = 1;
1.286 raeburn 3637: if (exists($env{'form.inststatus'})) {
3638: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3639: if (@inststatuses > 0) {
3640: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3641: $changeHash{'inststatus'} = $newinststatus;
3642: if ($newinststatus ne $oldinststatus) {
3643: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3644: foreach my $name ('portfolio','author') {
3645: ($newdefquota{$name},$newsettingstatus{$name}) =
3646: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3647: }
1.286 raeburn 3648: }
3649: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3650: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3651: } else {
1.337 raeburn 3652: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3653: }
1.334 raeburn 3654: }
3655: } else {
3656: $newinststatus = '';
3657: $changeHash{'inststatus'} = $newinststatus;
3658: $newsettings{'inststatus'} = $othertitle;
3659: if ($newinststatus ne $oldinststatus) {
3660: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3661: foreach my $name ('portfolio','author') {
3662: ($newdefquota{$name},$newsettingstatus{$name}) =
3663: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3664: }
1.286 raeburn 3665: }
3666: }
1.334 raeburn 3667: } elsif ($context ne 'selfcreate') {
3668: $canshow{'inststatus'} = 1;
1.337 raeburn 3669: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3670: }
1.378 raeburn 3671: foreach my $name ('portfolio','author') {
3672: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3673: }
1.334 raeburn 3674: if ($context eq 'domain') {
1.378 raeburn 3675: foreach my $name ('portfolio','author') {
3676: if ($userenv{$name.'quota'} ne '') {
3677: $oldquota{$name} = $userenv{$name.'quota'};
3678: if ($env{'form.custom_'.$name.'quota'} == 1) {
3679: if ($env{'form.'.$name.'quota'} eq '') {
3680: $newquota{$name} = 0;
3681: } else {
3682: $newquota{$name} = $env{'form.'.$name.'quota'};
3683: $newquota{$name} =~ s/[^\d\.]//g;
3684: }
3685: if ($newquota{$name} != $oldquota{$name}) {
3686: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3687: $changed{$name.'quota'} = 1;
3688: }
3689: }
1.334 raeburn 3690: } else {
1.378 raeburn 3691: if ("a_admin('',\%changeHash,$name)) {
3692: $changed{$name.'quota'} = 1;
3693: $newquota{$name} = $newdefquota{$name};
3694: $newisdefault{$name} = 1;
3695: }
1.334 raeburn 3696: }
1.149 raeburn 3697: } else {
1.378 raeburn 3698: $oldisdefault{$name} = 1;
3699: $oldquota{$name} = $olddefquota{$name};
3700: if ($env{'form.custom_'.$name.'quota'} == 1) {
3701: if ($env{'form.'.$name.'quota'} eq '') {
3702: $newquota{$name} = 0;
3703: } else {
3704: $newquota{$name} = $env{'form.'.$name.'quota'};
3705: $newquota{$name} =~ s/[^\d\.]//g;
3706: }
3707: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3708: $changed{$name.'quota'} = 1;
3709: }
1.334 raeburn 3710: } else {
1.378 raeburn 3711: $newquota{$name} = $newdefquota{$name};
3712: $newisdefault{$name} = 1;
1.334 raeburn 3713: }
1.378 raeburn 3714: }
3715: if ($oldisdefault{$name}) {
3716: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3717: } else {
3718: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3719: }
3720: if ($newisdefault{$name}) {
3721: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3722: } else {
3723: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3724: }
3725: }
1.334 raeburn 3726: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3727: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3728: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3729: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3730: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.470 raeburn 3731: my ($isadv,$isauthor) =
3732: &Apache::lonnet::is_advanced_user($env{'form.ccdomain'},$env{'form.ccuname'});
3733: unless ($isauthor) {
3734: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3735: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3736: }
3737: &tool_changes('authordefaults',\@authordefaults,\%oldsettings,\%oldsettingstext,
3738: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3739: } else {
1.334 raeburn 3740: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3741: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3742: }
3743: }
1.334 raeburn 3744: foreach my $item (@userinfo) {
3745: if ($env{'form.c'.$item} ne $userenv{$item}) {
3746: $namechanged{$item} = 1;
3747: }
1.204 raeburn 3748: }
1.378 raeburn 3749: foreach my $name ('portfolio','author') {
1.390 bisitz 3750: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3751: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3752: }
1.334 raeburn 3753: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3754: my ($chgresult,$namechgresult);
3755: if (keys(%changed) > 0) {
1.470 raeburn 3756: $chgresult =
1.204 raeburn 3757: &Apache::lonnet::put('environment',\%changeHash,
3758: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3759: if ($chgresult eq 'ok') {
1.470 raeburn 3760: my ($ca_mgr_del,%ca_mgr_add);
3761: if ($changed{'managers'}) {
3762: my (@adds,@dels);
3763: if ($changeHash{'authormanagers'} eq '') {
3764: @dels = split(/,/,$userenv{'authormanagers'});
3765: } elsif ($userenv{'authormanagers'} eq '') {
3766: @adds = split(/,/,$changeHash{'authormanagers'});
3767: } else {
3768: my @old = split(/,/,$userenv{'authormanagers'});
3769: my @new = split(/,/,$changeHash{'authormanagers'});
3770: my @diffs = &Apache::loncommon::compare_arrays(\@old,\@new);
3771: if (@diffs) {
3772: foreach my $user (@diffs) {
3773: if (grep(/^\Q$user\E$/,@old)) {
3774: push(@dels,$user);
3775: } elsif (grep(/^\Q$user\E$/,@new)) {
3776: push(@adds,$user);
3777: }
3778: }
3779: }
3780: }
3781: my $key = "internal.manager./$env{'form.ccdomain'}/$env{'form.ccuname'}";
3782: if (@dels) {
3783: foreach my $user (@dels) {
3784: if ($user =~ /^($match_username):($match_domain)$/) {
3785: &Apache::lonnet::del('environment',[$key],$2,$1);
3786: }
3787: }
3788: my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
3789: if (grep(/^\Q$curruser\E$/,@dels)) {
3790: $ca_mgr_del = $key;
3791: }
3792: }
3793: if (@adds) {
3794: foreach my $user (@adds) {
3795: if ($user =~ /^($match_username):($match_domain)$/) {
3796: &Apache::lonnet::put('environment',{$key => 1},$2,$1);
3797: }
3798: }
3799: my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
3800: if (grep(/^\Q$curruser\E$/,@adds)) {
3801: $ca_mgr_add{$key} = 1;
3802: }
3803: }
3804: }
1.267 raeburn 3805: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3806: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.474 raeburn 3807: my (%newenvhash,$got_domdefs,%domdefaults,$got_userenv,
3808: %userenv);
3809: my @fromenv = keys(%changed);
3810: push(@fromenv,'inststatus');
1.270 raeburn 3811: foreach my $key (keys(%changed)) {
1.411 raeburn 3812: if (($key eq 'official') || ($key eq 'unofficial') ||
3813: ($key eq 'community') || ($key eq 'textbook') ||
1.449 raeburn 3814: ($key eq 'placement') || ($key eq 'lti')) {
1.279 raeburn 3815: $newenvhash{'environment.requestcourses.'.$key} =
3816: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3817: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3818: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3819: } else {
1.474 raeburn 3820: unless ($got_domdefs) {
3821: %domdefaults =
3822: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3823: $got_domdefs = 1;
3824: }
3825: unless ($got_userenv) {
3826: %userenv =
3827: &Apache::lonnet::userenvironment($env{'user.domain'},
3828: $env{'user.name'},@fromenv);
3829: $got_userenv = 1;
3830: }
1.279 raeburn 3831: $newenvhash{'environment.canrequest.'.$key} =
3832: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.474 raeburn 3833: $key,'reload','requestcourses',\%userenv,\%domdefaults);
1.279 raeburn 3834: }
1.362 raeburn 3835: } elsif ($key eq 'requestauthor') {
3836: $newenvhash{'environment.'.$key} = $changeHash{$key};
3837: if ($changeHash{$key}) {
3838: $newenvhash{'environment.canrequest.author'} = 1;
3839: } else {
1.474 raeburn 3840: unless ($got_domdefs) {
3841: %domdefaults =
3842: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3843: $got_domdefs = 1;
3844: }
3845: unless ($got_userenv) {
3846: %userenv =
3847: &Apache::lonnet::userenvironment($env{'user.domain'},
3848: $env{'user.name'},@fromenv);
3849: $got_userenv = 1;
3850: }
1.362 raeburn 3851: $newenvhash{'environment.canrequest.author'} =
3852: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.474 raeburn 3853: $key,'reload','requestauthor',\%userenv,\%domdefaults);
1.362 raeburn 3854: }
1.470 raeburn 3855: } elsif ($key eq 'editors') {
3856: $newenvhash{'environment.author'.$key} = $changeHash{'author'.$key};
1.474 raeburn 3857: if ($env{'form.customeditors'}) {
3858: $newenvhash{'environment.editors'} = $changeHash{'author'.$key};
3859: } else {
3860: unless ($got_domdefs) {
3861: %domdefaults =
3862: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3863: $got_domdefs = 1;
3864: }
3865: if ($domdefaults{'editors'} ne '') {
3866: $newenvhash{'environment.editors'} = $domdefaults{'editors'};
1.470 raeburn 3867: } else {
1.474 raeburn 3868: $newenvhash{'environment.editors'} = 'edit,xml';
1.470 raeburn 3869: }
3870: }
1.480 raeburn 3871: } elsif ($key eq 'archive') {
3872: $newenvhash{'environment.author.'.$key} =
3873: $changeHash{'author.'.$key};
3874: if ($changeHash{'author.'.$key} ne '') {
3875: $newenvhash{'environment.canarchive'} =
3876: $changeHash{'author.'.$key};
3877: } else {
3878: unless ($got_domdefs) {
3879: %domdefaults =
3880: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3881: $got_domdefs = 1;
3882: }
3883: $newenvhash{'environment.canarchive'} =
3884: $domdefaults{'archive'};
3885: }
1.275 raeburn 3886: } elsif ($key ne 'quota') {
1.270 raeburn 3887: $newenvhash{'environment.tools.'.$key} =
3888: $changeHash{'tools.'.$key};
1.279 raeburn 3889: if ($changeHash{'tools.'.$key} ne '') {
3890: $newenvhash{'environment.availabletools.'.$key} =
3891: $changeHash{'tools.'.$key};
3892: } else {
1.474 raeburn 3893: unless ($got_domdefs) {
3894: %domdefaults =
3895: &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3896: $got_domdefs = 1;
3897: }
3898: unless ($got_userenv) {
3899: %userenv =
3900: &Apache::lonnet::userenvironment($env{'user.domain'},
3901: $env{'user.name'},@fromenv);
3902: $got_userenv = 1;
3903: }
1.279 raeburn 3904: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3905: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.474 raeburn 3906: $key,'reload','tools',\%userenv,\%domdefaults);
1.279 raeburn 3907: }
1.270 raeburn 3908: }
3909: }
1.271 raeburn 3910: if (keys(%newenvhash)) {
3911: &Apache::lonnet::appenv(\%newenvhash);
3912: }
1.470 raeburn 3913: } else {
3914: if ($ca_mgr_del) {
3915: &Apache::lonnet::delenv($ca_mgr_del);
3916: }
3917: if (keys(%ca_mgr_add)) {
3918: &Apache::lonnet::appenv(\%ca_mgr_add);
3919: }
1.267 raeburn 3920: }
1.463 raeburn 3921: if ($changed{'aboutme'}) {
3922: &Apache::loncommon::devalidate_aboutme_cache($env{'form.ccuname'},
3923: $env{'form.ccdomain'});
3924: }
1.267 raeburn 3925: }
1.204 raeburn 3926: }
1.334 raeburn 3927: if (keys(%namechanged) > 0) {
1.337 raeburn 3928: foreach my $field (@userinfo) {
3929: $changeHash{$field} = $env{'form.c'.$field};
3930: }
3931: # Make the change
1.204 raeburn 3932: $namechgresult =
3933: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3934: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3935: $changeHash{'firstname'},$changeHash{'middlename'},
3936: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3937: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3938: %userupdate = (
3939: lastname => $env{'form.clastname'},
3940: middlename => $env{'form.cmiddlename'},
3941: firstname => $env{'form.cfirstname'},
3942: generation => $env{'form.cgeneration'},
3943: id => $env{'form.cid'},
3944: );
1.204 raeburn 3945: }
1.334 raeburn 3946: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3947: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3948: # Tell the user we changed the name
1.334 raeburn 3949: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3950: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3951: \%oldsettings, \%oldsettingstext,\%newsettings,
3952: \%newsettingstext);
1.203 raeburn 3953: if ($env{'form.cid'} ne $userenv{'id'}) {
3954: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3955: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3956: if (($recurseid) &&
3957: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3958: my $idresult =
3959: &Apache::lonuserutils::propagate_id_change(
3960: $env{'form.ccuname'},$env{'form.ccdomain'},
3961: \%userupdate);
3962: $r->print('<br />'.$idresult.'<br />');
3963: }
1.196 raeburn 3964: }
1.149 raeburn 3965: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3966: ($env{'form.ccuname'} eq $env{'user.name'})) {
3967: my %newenvhash;
3968: foreach my $key (keys(%changeHash)) {
3969: $newenvhash{'environment.'.$key} = $changeHash{$key};
3970: }
1.238 raeburn 3971: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3972: }
1.28 matthew 3973: } else { # error occurred
1.389 bisitz 3974: $r->print(
3975: '<p class="LC_error">'
3976: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3977: '"'.$env{'form.ccuname'}.'"',
3978: '"'.$env{'form.ccdomain'}.'"')
3979: .'</p>');
1.28 matthew 3980: }
1.334 raeburn 3981: } else { # End of if ($env ... ) logic
1.275 raeburn 3982: # They did not want to change the users name, quota, tool availability,
3983: # or ability to request creation of courses,
1.267 raeburn 3984: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3985: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3986: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3987: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3988: }
1.206 raeburn 3989: if (@mod_disallowed) {
3990: my ($rolestr,$contextname);
3991: if (@longroles > 0) {
3992: $rolestr = join(', ',@longroles);
3993: } else {
3994: $rolestr = &mt('No roles');
3995: }
3996: if ($context eq 'course') {
1.399 bisitz 3997: $contextname = 'course';
1.206 raeburn 3998: } elsif ($context eq 'author') {
1.399 bisitz 3999: $contextname = 'co-author';
1.206 raeburn 4000: }
4001: $r->print(&mt('The following fields were not updated: ').'<ul>');
4002: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4003: foreach my $field (@mod_disallowed) {
4004: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
4005: }
1.207 raeburn 4006: $r->print('</ul>');
4007: if (@mod_disallowed == 1) {
1.399 bisitz 4008: $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 4009: } else {
1.399 bisitz 4010: $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 4011: }
1.292 bisitz 4012: my $helplink = 'javascript:helpMenu('."'display'".')';
4013: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
4014: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
4015: ,'<a href="'.$helplink.'">','</a>')
4016: .'<br />');
1.206 raeburn 4017: }
1.259 bisitz 4018: $r->print('<span class="LC_warning">'
4019: .$no_forceid_alert
4020: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
4021: .'</span>');
1.4 www 4022: }
1.367 golterma 4023: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 4024: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 4025: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
4026: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 4027: my $linktext = ($crstype eq 'Community' ?
4028: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
4029: $r->print(
4030: &Apache::lonhtmlcommon::actionbox([
4031: '<a href="javascript:backPage(document.userupdate)">'
4032: .($crstype eq 'Community' ?
4033: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
4034: .'</a>']));
1.220 raeburn 4035: } else {
1.375 raeburn 4036: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 4037: if (keys(%namechanged) > 0) {
1.220 raeburn 4038: if ($context eq 'course') {
4039: if (@userroles > 0) {
1.225 raeburn 4040: if ((@rolechanges == 0) ||
4041: (!(grep(/^st$/,@rolechanges)))) {
4042: if (grep(/^st$/,@userroles)) {
4043: my $classlistupdated =
4044: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 4045: $cnum,$env{'form.ccdomain'},
4046: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 4047: }
1.220 raeburn 4048: }
4049: }
4050: }
4051: }
1.226 raeburn 4052: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 4053: $env{'form.ccdomain'});
4054: if ($env{'form.popup'}) {
4055: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
4056: } else {
1.367 golterma 4057: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
4058: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
4059: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 4060: }
1.220 raeburn 4061: }
4062: }
4063:
1.334 raeburn 4064: sub display_userinfo {
1.362 raeburn 4065: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
4066: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 4067: $newsetting,$newsettingtext) = @_;
4068: return unless (ref($order) eq 'ARRAY' &&
4069: ref($canshow) eq 'HASH' &&
4070: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 4071: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 4072: ref($usertools) eq 'ARRAY' &&
4073: ref($userenv) eq 'HASH' &&
4074: ref($changedhash) eq 'HASH' &&
4075: ref($oldsetting) eq 'HASH' &&
4076: ref($oldsettingtext) eq 'HASH' &&
4077: ref($newsetting) eq 'HASH' &&
4078: ref($newsettingtext) eq 'HASH');
4079: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 4080: 'ui' => 'User Information',
1.334 raeburn 4081: 'uic' => 'User Information Changed',
4082: 'firstname' => 'First Name',
4083: 'middlename' => 'Middle Name',
4084: 'lastname' => 'Last Name',
4085: 'generation' => 'Generation',
4086: 'id' => 'Student/Employee ID',
4087: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 4088: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 4089: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 4090: 'blog' => 'Blog Availability',
1.361 raeburn 4091: 'webdav' => 'WebDAV Availability',
1.334 raeburn 4092: 'aboutme' => 'Personal Information Page Availability',
4093: 'portfolio' => 'Portfolio Availability',
1.470 raeburn 4094: 'portaccess' => 'Portfolio Shareable',
1.459 raeburn 4095: 'timezone' => 'Can set own Time Zone',
1.334 raeburn 4096: 'official' => 'Can Request Official Courses',
4097: 'unofficial' => 'Can Request Unofficial Courses',
4098: 'community' => 'Can Request Communities',
1.384 raeburn 4099: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 4100: 'placement' => 'Can Request Placement Tests',
1.449 raeburn 4101: 'lti' => 'Can Request LTI Courses',
1.362 raeburn 4102: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 4103: 'inststatus' => "Affiliation",
4104: 'prvs' => 'Previous Value:',
1.470 raeburn 4105: 'chto' => 'Changed To:',
4106: 'editors' => "Available Editors in Authoring Space",
1.473 raeburn 4107: 'managers' => "Co-authors who can add/revoke roles",
1.477 raeburn 4108: 'archive' => "Managers can download tar.gz file of Authoring Space",
1.470 raeburn 4109: 'edit' => 'Standard editor (Edit)',
4110: 'xml' => 'Text editor (EditXML)',
4111: 'daxe' => 'Daxe editor (Daxe)',
1.334 raeburn 4112: );
4113: if ($changed) {
1.372 raeburn 4114: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 4115: &Apache::loncommon::start_data_table().
4116: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 4117: $r->print("<th> </th>\n");
1.367 golterma 4118: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
4119: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
4120: $r->print(&Apache::loncommon::end_data_table_header_row());
4121: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
4122:
1.334 raeburn 4123: foreach my $item (@userinfo) {
4124: my $value = $env{'form.c'.$item};
1.367 golterma 4125: #show changes only:
1.383 raeburn 4126: unless ($value eq $userenv->{$item}){
1.367 golterma 4127: $r->print(&Apache::loncommon::start_data_table_row());
4128: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 4129: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 4130: $r->print("<td>$value </td>\n");
4131: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 4132: }
4133: }
4134: foreach my $entry (@{$order}) {
1.383 raeburn 4135: if ($canshow->{$entry}) {
1.470 raeburn 4136: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') ||
4137: ($entry eq 'requestauthor') || ($entry eq 'authordefaults')) {
1.383 raeburn 4138: my @items;
4139: if ($entry eq 'requestauthor') {
4140: @items = ($entry);
1.470 raeburn 4141: } elsif ($entry eq 'authordefaults') {
1.477 raeburn 4142: @items = ('webdav','managers','editors','archive');
1.383 raeburn 4143: } else {
4144: @items = @{$requestcourses};
1.384 raeburn 4145: }
1.383 raeburn 4146: foreach my $item (@items) {
4147: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
4148: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
4149: $r->print(&Apache::loncommon::start_data_table_row()."\n");
1.470 raeburn 4150: $r->print("<td>$lt{$item}</td><td>\n");
4151: unless ($item eq 'managers') {
4152: $r->print($oldsetting->{$item});
4153: }
1.383 raeburn 4154: if ($oldsettingtext->{$item}) {
4155: if ($oldsetting->{$item}) {
1.470 raeburn 4156: unless ($item eq 'managers') {
4157: $r->print(' -- ');
4158: }
1.383 raeburn 4159: }
4160: $r->print($oldsettingtext->{$item});
4161: }
1.470 raeburn 4162: $r->print("</td>\n<td>");
4163: unless ($item eq 'managers') {
4164: $r->print($newsetting->{$item});
4165: }
1.383 raeburn 4166: if ($newsettingtext->{$item}) {
4167: if ($newsetting->{$item}) {
1.470 raeburn 4168: unless ($item eq 'managers') {
4169: $r->print(' -- ');
4170: }
1.383 raeburn 4171: }
4172: $r->print($newsettingtext->{$item});
4173: }
4174: $r->print("</td>\n");
4175: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4176: }
4177: }
4178: } elsif ($entry eq 'tools') {
4179: foreach my $item (@{$usertools}) {
1.383 raeburn 4180: if ($newsetting->{$item} ne $oldsetting->{$item}) {
4181: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4182: $r->print("<td>$lt{$item}</td>\n");
4183: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
4184: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
4185: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4186: }
4187: }
1.378 raeburn 4188: } elsif ($entry eq 'quota') {
4189: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
4190: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
4191: foreach my $name ('portfolio','author') {
1.383 raeburn 4192: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
4193: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4194: $r->print("<td>$lt{$name.$entry}</td>\n");
4195: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
4196: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
4197: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 4198: }
4199: }
4200: }
1.334 raeburn 4201: } else {
1.383 raeburn 4202: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
4203: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4204: $r->print("<td>$lt{$entry}</td>\n");
4205: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
4206: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
4207: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4208: }
4209: }
4210: }
4211: }
1.367 golterma 4212: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 4213: } else {
4214: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
4215: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 4216: }
4217: return;
4218: }
4219:
1.275 raeburn 4220: sub tool_changes {
4221: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
4222: $changed,$newaccess,$newaccesstext) = @_;
4223: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
4224: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
4225: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
4226: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
4227: return;
4228: }
1.383 raeburn 4229: my %reqdisplay = &requestchange_display();
1.300 raeburn 4230: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 4231: my @options = ('approval','validate','autolimit');
1.306 raeburn 4232: my $optregex = join('|',@options);
1.300 raeburn 4233: my $cdom = $env{'request.role.domain'};
4234: foreach my $tool (@{$usertools}) {
1.383 raeburn 4235: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 4236: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 4237: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 4238: my ($newop,$limit);
1.314 raeburn 4239: if ($env{'form.'.$context.'_'.$tool}) {
4240: $newop = $env{'form.'.$context.'_'.$tool};
4241: if ($newop eq 'autolimit') {
1.383 raeburn 4242: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 4243: $limit =~ s/\D+//g;
4244: $newop .= '='.$limit;
4245: }
4246: }
1.300 raeburn 4247: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 4248: if ($newop) {
4249: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 4250: $changeHash,$context);
4251: if ($changed->{$tool}) {
1.383 raeburn 4252: if ($newop =~ /^autolimit/) {
4253: if ($limit) {
4254: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4255: } else {
4256: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4257: }
4258: } else {
4259: $newaccesstext->{$tool} = $reqdisplay{$newop};
4260: }
1.300 raeburn 4261: } else {
4262: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
4263: }
4264: }
4265: } else {
4266: my @curr = split(',',$userenv->{$context.'.'.$tool});
4267: my @new;
4268: my $changedoms;
1.314 raeburn 4269: foreach my $req (@curr) {
4270: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
4271: my $oldop = $1;
1.383 raeburn 4272: if ($oldop =~ /^autolimit=(\d*)/) {
4273: my $limit = $1;
4274: if ($limit) {
4275: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4276: } else {
4277: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4278: }
4279: } else {
4280: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
4281: }
1.314 raeburn 4282: if ($oldop ne $newop) {
4283: $changedoms = 1;
4284: foreach my $item (@curr) {
4285: my ($reqdom,$option) = split(':',$item);
4286: unless ($reqdom eq $cdom) {
4287: push(@new,$item);
4288: }
4289: }
4290: if ($newop) {
4291: push(@new,$cdom.':'.$newop);
1.300 raeburn 4292: }
1.314 raeburn 4293: @new = sort(@new);
1.300 raeburn 4294: }
1.314 raeburn 4295: last;
1.300 raeburn 4296: }
1.314 raeburn 4297: }
4298: if ((!$changedoms) && ($newop)) {
1.300 raeburn 4299: $changedoms = 1;
1.306 raeburn 4300: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 4301: }
4302: if ($changedoms) {
1.314 raeburn 4303: my $newdomstr;
1.300 raeburn 4304: if (@new) {
4305: $newdomstr = join(',',@new);
4306: }
4307: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
4308: $context);
4309: if ($changed->{$tool}) {
4310: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 4311: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 4312: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
4313: $limit =~ s/\D+//g;
4314: if ($limit) {
1.383 raeburn 4315: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 4316: } else {
1.383 raeburn 4317: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 4318: }
1.314 raeburn 4319: } else {
1.306 raeburn 4320: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
4321: }
1.300 raeburn 4322: } else {
1.383 raeburn 4323: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 4324: }
4325: }
4326: }
4327: }
4328: }
4329: return;
4330: }
1.470 raeburn 4331: my %tooldesc = &Apache::lonlocal::texthash(
4332: 'edit' => 'Standard editor (Edit)',
4333: 'xml' => 'Text editor (EditXML)',
4334: 'daxe' => 'Daxe editor (Daxe)',
4335: );
1.275 raeburn 4336: foreach my $tool (@{$usertools}) {
1.383 raeburn 4337: my ($newval,$limit,$envkey);
1.362 raeburn 4338: $envkey = $context.'.'.$tool;
1.306 raeburn 4339: if ($context eq 'requestcourses') {
4340: $newval = $env{'form.crsreq_'.$tool};
4341: if ($newval eq 'autolimit') {
1.383 raeburn 4342: $limit = $env{'form.crsreq_'.$tool.'_limit'};
4343: $limit =~ s/\D+//g;
4344: $newval .= '='.$limit;
1.306 raeburn 4345: }
1.362 raeburn 4346: } elsif ($context eq 'requestauthor') {
4347: $newval = $env{'form.'.$context};
4348: $envkey = $context;
1.470 raeburn 4349: } elsif ($context eq 'authordefaults') {
4350: if ($tool eq 'editors') {
4351: $envkey = 'authoreditors';
4352: if ($env{'form.customeditors'} == 1) {
4353: my @editors;
4354: my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
4355: if (@posseditors) {
4356: foreach my $editor (@posseditors) {
4357: if (grep(/^\Q$editor\E$/,@posseditors)) {
4358: unless (grep(/^\Q$editor\E$/,@editors)) {
4359: push(@editors,$editor);
4360: }
4361: }
4362: }
4363: }
4364: if (@editors) {
4365: $newval = join(',',(sort(@editors)));
4366: }
4367: }
4368: } elsif ($tool eq 'managers') {
4369: $envkey = 'authormanagers';
4370: my @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
4371: if (@possibles) {
4372: my %ca_roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},
4373: undef,['active','future'],['ca']);
4374: if (keys(%ca_roles)) {
4375: my @custommanagers;
4376: foreach my $user (@possibles) {
4377: if ($user =~ /^($match_username):($match_domain)$/) {
4378: if (exists($ca_roles{$user.':ca'})) {
4379: unless ($user eq $env{'form.ccuname'}.':'.$env{'form.ccdomain'}) {
4380: push(@custommanagers,$user);
4381: }
4382: }
4383: }
4384: }
4385: if (@custommanagers) {
4386: $newval = join(',',sort(@custommanagers));
4387: }
4388: }
4389: }
4390: } elsif ($tool eq 'webdav') {
4391: $envkey = 'tools.webdav';
4392: $newval = $env{'form.'.$context.'_'.$tool};
1.477 raeburn 4393: } elsif ($tool eq 'archive') {
4394: $envkey = 'authorarchive';
4395: $newval = $env{'form.'.$context.'_'.$tool};
1.470 raeburn 4396: }
1.314 raeburn 4397: } else {
1.306 raeburn 4398: $newval = $env{'form.'.$context.'_'.$tool};
4399: }
1.362 raeburn 4400: if ($userenv->{$envkey} ne '') {
1.275 raeburn 4401: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 4402: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4403: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
4404: my $currlimit = $1;
4405: if ($currlimit eq '') {
4406: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4407: } else {
4408: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
4409: }
4410: } elsif ($userenv->{$envkey}) {
4411: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
4412: } else {
4413: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4414: }
1.470 raeburn 4415: } elsif ($context eq 'authordefaults') {
4416: if ($tool eq 'managers') {
4417: if ($userenv->{$envkey} eq '') {
4418: $oldaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4419: } else {
4420: my $managers = $userenv->{$envkey};
4421: $managers =~ s/,/, /g;
4422: $oldaccesstext->{$tool} = $managers;
4423: }
4424: } elsif ($tool eq 'editors') {
4425: $oldaccesstext->{$tool} = &mt('can use: [_1]',
4426: join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
1.477 raeburn 4427: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4428: if ($userenv->{$envkey}) {
4429: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
4430: } else {
4431: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4432: }
4433: }
1.275 raeburn 4434: } else {
1.383 raeburn 4435: if ($userenv->{$envkey}) {
4436: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
4437: } else {
4438: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4439: }
1.275 raeburn 4440: }
1.362 raeburn 4441: $changeHash->{$envkey} = $userenv->{$envkey};
1.470 raeburn 4442: if (($env{'form.custom'.$tool} == 1) ||
4443: (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
1.362 raeburn 4444: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 4445: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
4446: $context);
1.275 raeburn 4447: if ($changed->{$tool}) {
4448: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 4449: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4450: if ($newval =~ /^autolimit/) {
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: }
4456: } elsif ($newval) {
4457: $newaccesstext->{$tool} = $reqdisplay{$newval};
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(/,/,$changeHash->{$envkey})));
4465: } elsif ($tool eq 'managers') {
4466: if ($changeHash->{$envkey} eq '') {
4467: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4468: } else {
4469: my $managers = $changeHash->{$envkey};
4470: $managers =~ s/,/, /g;
4471: $newaccesstext->{$tool} = $managers;
4472: }
1.477 raeburn 4473: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4474: if ($newval) {
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 ($newval) {
4482: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4483: } else {
4484: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4485: }
1.275 raeburn 4486: }
4487: } else {
4488: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 4489: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.470 raeburn 4490: if ($userenv->{$envkey} =~ /^autolimit/) {
1.383 raeburn 4491: if ($limit) {
4492: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4493: } else {
4494: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4495: }
1.470 raeburn 4496: } elsif ($userenv->{$envkey}) {
4497: $newaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
1.383 raeburn 4498: } else {
4499: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4500: }
1.470 raeburn 4501: } elsif ($context eq 'authordefaults') {
4502: if ($tool eq 'editors') {
4503: $newaccesstext->{$tool} = &mt('can use: [_1]',
4504: join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
4505: } elsif ($tool eq 'managers') {
4506: if ($userenv->{$envkey} eq '') {
4507: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4508: } else {
4509: my $managers = $userenv->{$envkey};
4510: $managers =~ s/,/, /g;
4511: $newaccesstext->{$tool} = $managers;
4512: }
1.477 raeburn 4513: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4514: if ($userenv->{$envkey}) {
4515: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4516: } else {
4517: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4518: }
4519: }
1.275 raeburn 4520: } else {
1.383 raeburn 4521: if ($userenv->{$context.'.'.$tool}) {
4522: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4523: } else {
4524: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4525: }
1.275 raeburn 4526: }
4527: }
4528: } else {
4529: $newaccess->{$tool} = $oldaccess->{$tool};
4530: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
4531: }
4532: } else {
4533: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
4534: if ($changed->{$tool}) {
4535: $newaccess->{$tool} = &mt('default');
4536: } else {
4537: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 4538: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4539: if ($newval =~ /^autolimit/) {
4540: if ($limit) {
4541: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4542: } else {
4543: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4544: }
4545: } elsif ($newval) {
4546: $newaccesstext->{$tool} = $reqdisplay{$newval};
4547: } else {
4548: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4549: }
1.470 raeburn 4550: } elsif ($context eq 'authordefaults') {
4551: if ($tool eq 'editors') {
4552: $newaccesstext->{$tool} = &mt('can use: [_1]',
4553: join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
4554: } elsif ($tool eq 'managers') {
4555: if ($newval eq '') {
4556: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4557: } else {
4558: my $managers = $newval;
4559: $managers =~ s/,/, /g;
4560: $newaccesstext->{$tool} = $managers;
4561: }
1.477 raeburn 4562: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4563: if ($userenv->{$envkey}) {
4564: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4565: } else {
4566: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4567: }
4568: }
1.275 raeburn 4569: } else {
1.383 raeburn 4570: if ($userenv->{$context.'.'.$tool}) {
4571: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4572: } else {
4573: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4574: }
1.275 raeburn 4575: }
4576: }
4577: }
4578: } else {
4579: $oldaccess->{$tool} = &mt('default');
1.470 raeburn 4580: if (($env{'form.custom'.$tool} == 1) ||
4581: (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
1.306 raeburn 4582: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
4583: $context);
1.275 raeburn 4584: if ($changed->{$tool}) {
4585: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 4586: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4587: if ($newval =~ /^autolimit/) {
4588: if ($limit) {
4589: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4590: } else {
4591: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4592: }
4593: } elsif ($newval) {
4594: $newaccesstext->{$tool} = $reqdisplay{$newval};
4595: } else {
4596: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4597: }
1.470 raeburn 4598: } elsif ($context eq 'authordefaults') {
4599: if ($tool eq 'managers') {
4600: if ($newval eq '') {
4601: $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4602: } else {
4603: my $managers = $newval;
4604: $managers =~ s/,/, /g;
4605: $newaccesstext->{$tool} = $managers;
4606: }
4607: } elsif ($tool eq 'editors') {
4608: $newaccesstext->{$tool} = &mt('can use: [_1]',
4609: join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
1.477 raeburn 4610: } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
1.470 raeburn 4611: if ($newval) {
4612: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4613: } else {
4614: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4615: }
4616: }
1.275 raeburn 4617: } else {
1.383 raeburn 4618: if ($newval) {
4619: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4620: } else {
4621: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4622: }
1.275 raeburn 4623: }
4624: } else {
4625: $newaccess->{$tool} = $oldaccess->{$tool};
4626: }
4627: } else {
4628: $newaccess->{$tool} = $oldaccess->{$tool};
4629: }
4630: }
4631: }
4632: return;
4633: }
4634:
1.220 raeburn 4635: sub update_roles {
1.375 raeburn 4636: my ($r,$context,$showcredits) = @_;
1.4 www 4637: my $now=time;
1.225 raeburn 4638: my @rolechanges;
1.465 raeburn 4639: my (%disallowed,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.466 raeburn 4640: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.465 raeburn 4641: $got_role_approvals{$context} = '';
4642: $process_by{$context} = {};
4643: my @domroles = &Apache::lonuserutils::domain_roles();
4644: my @cstrroles = &Apache::lonuserutils::construction_space_roles();
4645: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
1.73 sakharuk 4646: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 4647: foreach my $key (keys(%env)) {
1.135 raeburn 4648: next if (! $env{$key});
1.190 raeburn 4649: next if ($key eq 'form.action');
1.27 matthew 4650: # Revoke roles
1.135 raeburn 4651: if ($key=~/^form\.rev/) {
4652: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 4653: # Revoke standard role
1.170 albertel 4654: my ($scope,$role) = ($1,$2);
4655: my $result =
4656: &Apache::lonnet::revokerole($env{'form.ccdomain'},
4657: $env{'form.ccuname'},
1.239 raeburn 4658: $scope,$role,'','',$context);
1.367 golterma 4659: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4660: &mt('Revoking [_1] in [_2]',
4661: &Apache::lonnet::plaintext($role),
1.372 raeburn 4662: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4663: $result ne "ok").'<br />');
4664: if ($result ne "ok") {
4665: $r->print(&mt('Error: [_1]',$result).'<br />');
4666: }
1.170 albertel 4667: if ($role eq 'st') {
1.202 raeburn 4668: my $result =
1.198 raeburn 4669: &Apache::lonuserutils::classlist_drop($scope,
4670: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4671: $now);
1.367 golterma 4672: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 4673: }
1.225 raeburn 4674: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4675: push(@rolechanges,$role);
4676: }
1.196 raeburn 4677: }
1.195 raeburn 4678: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 4679: # Revoke custom role
1.369 bisitz 4680: my $result = &Apache::lonnet::revokecustomrole(
4681: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 4682: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4683: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 4684: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4685: $result ne 'ok').'<br />');
4686: if ($result ne "ok") {
4687: $r->print(&mt('Error: [_1]',$result).'<br />');
4688: }
1.225 raeburn 4689: if (!grep(/^cr$/,@rolechanges)) {
4690: push(@rolechanges,'cr');
4691: }
1.64 www 4692: }
1.135 raeburn 4693: } elsif ($key=~/^form\.del/) {
4694: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 4695: # Delete standard role
1.170 albertel 4696: my ($scope,$role) = ($1,$2);
4697: my $result =
4698: &Apache::lonnet::assignrole($env{'form.ccdomain'},
4699: $env{'form.ccuname'},
1.239 raeburn 4700: $scope,$role,$now,0,1,'',
4701: $context);
1.367 golterma 4702: $r->print(&Apache::lonhtmlcommon::confirm_success(
4703: &mt('Deleting [_1] in [_2]',
1.369 bisitz 4704: &Apache::lonnet::plaintext($role),
1.372 raeburn 4705: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4706: $result ne 'ok').'<br />');
4707: if ($result ne "ok") {
4708: $r->print(&mt('Error: [_1]',$result).'<br />');
4709: }
1.367 golterma 4710:
1.170 albertel 4711: if ($role eq 'st') {
1.202 raeburn 4712: my $result =
1.198 raeburn 4713: &Apache::lonuserutils::classlist_drop($scope,
4714: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4715: $now);
1.369 bisitz 4716: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 4717: }
1.225 raeburn 4718: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4719: push(@rolechanges,$role);
4720: }
1.116 raeburn 4721: }
1.139 albertel 4722: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4723: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4724: # Delete custom role
1.369 bisitz 4725: my $result =
4726: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
4727: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
4728: 0,1,$context);
4729: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 4730: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4731: $result ne "ok").'<br />');
4732: if ($result ne "ok") {
4733: $r->print(&mt('Error: [_1]',$result).'<br />');
4734: }
1.367 golterma 4735:
1.225 raeburn 4736: if (!grep(/^cr$/,@rolechanges)) {
4737: push(@rolechanges,'cr');
4738: }
1.116 raeburn 4739: }
1.135 raeburn 4740: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4741: my $udom = $env{'form.ccdomain'};
4742: my $uname = $env{'form.ccuname'};
1.116 raeburn 4743: # Re-enable standard role
1.135 raeburn 4744: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4745: my $url = $1;
4746: my $role = $2;
1.465 raeburn 4747: my $id = $url.'_'.$role;
1.89 raeburn 4748: my $logmsg;
4749: my $output;
4750: if ($role eq 'st') {
1.141 albertel 4751: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4752: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4753: my $credits;
4754: if ($showcredits) {
1.465 raeburn 4755: my $defaultcredits =
1.375 raeburn 4756: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4757: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4758: }
1.465 raeburn 4759: unless ($udom eq $cdom) {
4760: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4761: $uname,$role,$now,0,$cdom,$cnum,$csec,$credits,
4762: \%process_by,\%instdoms,\%got_role_approvals,
1.466 raeburn 4763: \%got_instdoms,\%reject,\%pending,\%notifydc,
4764: \%status,\%unauthorized,\%currqueued));
1.465 raeburn 4765: }
1.375 raeburn 4766: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4767: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4768: if ($result eq 'refused' && $logmsg) {
4769: $output = $logmsg;
4770: } else {
1.369 bisitz 4771: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4772: }
1.89 raeburn 4773: } else {
1.372 raeburn 4774: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4775: &Apache::lonnet::plaintext($role),
4776: &Apache::loncommon::show_role_extent($url,$context,'st'),
4777: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4778: }
4779: }
4780: } else {
1.465 raeburn 4781: my ($cdom,$cnum,$csec);
4782: if (grep(/^\Q$role\E$/,@cstrroles)) {
4783: ($cdom,$cnum) = ($url =~ m{^/($match_domain)/($match_username)$});
4784: } elsif (grep(/^\Q$role\E$/,@domroles)) {
4785: ($cdom) = ($url =~ m{^/($match_domain)/$});
4786: } elsif ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
4787: ($cdom,$cnum,$csec) = ($1,$2,$3);
4788: }
4789: if ($cdom ne '') {
4790: unless ($udom eq $cdom) {
4791: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4792: $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by,
4793: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4794: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4795: }
4796: }
1.101 albertel 4797: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4798: $env{'form.ccuname'},$url,$role,0,$now,'','',
4799: $context);
1.461 raeburn 4800: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
4801: &Apache::lonnet::plaintext($role),
4802: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4803: if ($result ne "ok") {
4804: $output .= &mt('Error: [_1]',$result).'<br />';
4805: }
4806: }
1.89 raeburn 4807: $r->print($output);
1.225 raeburn 4808: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4809: push(@rolechanges,$role);
4810: }
1.113 raeburn 4811: }
1.116 raeburn 4812: # Re-enable custom role
1.139 albertel 4813: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4814: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1.465 raeburn 4815: my $id = $url.'_cr'."/$rdom/$rnam/$rolename";
4816: my $role = "cr/$rdom/$rnam/$rolename";
4817: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
4818: my ($cdom,$cnum,$csec) = ($1,$2,$3);
4819: unless ($udom eq $cdom) {
4820: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4821: $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by,
4822: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4823: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4824: }
4825: }
1.116 raeburn 4826: my $result = &Apache::lonnet::assigncustomrole(
4827: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4828: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4829: $r->print(&Apache::lonhtmlcommon::confirm_success(
4830: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4831: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4832: $result ne "ok").'<br />');
4833: if ($result ne "ok") {
4834: $r->print(&mt('Error: [_1]',$result).'<br />');
4835: }
1.225 raeburn 4836: if (!grep(/^cr$/,@rolechanges)) {
4837: push(@rolechanges,'cr');
4838: }
1.116 raeburn 4839: }
1.135 raeburn 4840: } elsif ($key=~/^form\.act/) {
1.101 albertel 4841: my $udom = $env{'form.ccdomain'};
4842: my $uname = $env{'form.ccuname'};
1.141 albertel 4843: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4844: # Activate a custom role
1.83 albertel 4845: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4846: my $url='/'.$one.'/'.$two;
1.465 raeburn 4847: my $id = $url.'_cr/'."$three/$four/$five";
4848: my $role = "cr/$three/$four/$five";
1.83 albertel 4849: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4850:
1.101 albertel 4851: my $start = ( $env{'form.start_'.$full} ?
4852: $env{'form.start_'.$full} :
1.88 raeburn 4853: $now );
1.101 albertel 4854: my $end = ( $env{'form.end_'.$full} ?
4855: $env{'form.end_'.$full} :
1.88 raeburn 4856: 0 );
1.465 raeburn 4857:
1.88 raeburn 4858: # split multiple sections
4859: my %sections = ();
1.461 raeburn 4860: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$five);
1.88 raeburn 4861: if ($num_sections == 0) {
1.465 raeburn 4862: unless ($udom eq $one) {
4863: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4864: $uname,$role,$start,$end,$one,$two,'','',\%process_by,
4865: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4866: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4867: }
1.240 raeburn 4868: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4869: } else {
1.114 albertel 4870: my %curr_groups =
1.117 raeburn 4871: &Apache::longroup::coursegroups($one,$two);
1.465 raeburn 4872: my ($restricted,$numchanges);
1.404 raeburn 4873: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4874: if (($sec eq 'none') || ($sec eq 'all') ||
4875: exists($curr_groups{$sec})) {
4876: $disallowed{$sec} = $url;
4877: next;
4878: }
4879: my $securl = $url.'/'.$sec;
1.465 raeburn 4880: my $secid = $securl.'_cr'."/$three/$four/$five";
4881: undef($restricted);
4882: unless ($udom eq $one) {
4883: next if (&Apache::lonuserutils::restricted_dom($context,$secid,$udom,
4884: $uname,$role,$start,$end,$one,$two,$sec,'',\%process_by,
4885: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4886: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4887: }
4888: $numchanges ++;
1.240 raeburn 4889: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4890: }
1.465 raeburn 4891: next unless ($numchanges);
1.88 raeburn 4892: }
1.225 raeburn 4893: if (!grep(/^cr$/,@rolechanges)) {
4894: push(@rolechanges,'cr');
4895: }
1.142 raeburn 4896: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4897: # Activate roles for sections with 3 id numbers
4898: # set start, end times, and the url for the class
1.83 albertel 4899: my ($one,$two,$three)=($1,$2,$3);
1.461 raeburn 4900: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4901: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4902: $now );
1.461 raeburn 4903: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1.101 albertel 4904: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4905: 0 );
1.83 albertel 4906: my $url='/'.$one.'/'.$two;
1.465 raeburn 4907: my $id = $url.'_'.$three;
1.88 raeburn 4908: # split multiple sections
4909: my %sections = ();
1.101 albertel 4910: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.465 raeburn 4911: my ($credits,$numchanges);
1.375 raeburn 4912: if ($three eq 'st') {
1.461 raeburn 4913: if ($showcredits) {
1.375 raeburn 4914: my $defaultcredits =
4915: &Apache::lonuserutils::get_defaultcredits($one,$two);
4916: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4917: $credits =~ s/[^\d\.]//g;
4918: if ($credits eq $defaultcredits) {
4919: undef($credits);
4920: }
4921: }
4922: }
1.88 raeburn 4923: if ($num_sections == 0) {
1.465 raeburn 4924: unless ($udom eq $one) {
4925: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4926: $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by,
4927: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4928: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 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: } else {
1.114 albertel 4933: my %curr_groups =
1.117 raeburn 4934: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4935: my $emptysec = 0;
1.465 raeburn 4936: my $restricted;
1.404 raeburn 4937: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4938: $sec =~ s/\W//g;
1.113 raeburn 4939: if ($sec ne '') {
4940: if (($sec eq 'none') || ($sec eq 'all') ||
4941: exists($curr_groups{$sec})) {
4942: $disallowed{$sec} = $url;
4943: next;
4944: }
1.88 raeburn 4945: my $securl = $url.'/'.$sec;
1.465 raeburn 4946: my $secid = $securl.'_'.$three;
4947: unless ($udom eq $one) {
4948: undef($restricted);
4949: $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
4950: $uname,$three,$start,$end,$one,$two,$sec,$credits,\%process_by,
4951: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4952: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4953: next if ($restricted);
4954: }
4955: $numchanges ++;
1.375 raeburn 4956: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4957: } else {
4958: $emptysec = 1;
4959: }
4960: }
4961: if ($emptysec) {
1.465 raeburn 4962: unless ($udom eq $one) {
4963: undef($restricted);
4964: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
4965: $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by,
4966: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4967: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4968: next if ($restricted);
4969: }
4970: $numchanges ++;
1.375 raeburn 4971: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4972: }
1.465 raeburn 4973: next unless ($numchanges);
1.225 raeburn 4974: }
4975: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4976: push(@rolechanges,$three);
4977: }
1.135 raeburn 4978: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4979: # Activate roles for sections with two id numbers
4980: # set start, end times, and the url for the class
1.461 raeburn 4981: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4982: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4983: $now );
1.461 raeburn 4984: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1.101 albertel 4985: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4986: 0 );
1.225 raeburn 4987: my $one = $1;
4988: my $two = $2;
4989: my $url='/'.$one.'/';
1.465 raeburn 4990: my $id = $url.'_'.$two;
1.468 raeburn 4991: my ($cdom,$cnum) = split(/\//,$one);
1.88 raeburn 4992: # split multiple sections
4993: my %sections = ();
1.465 raeburn 4994: my ($restricted,$numchanges);
1.225 raeburn 4995: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4996: if ($num_sections == 0) {
1.465 raeburn 4997: unless ($udom eq $one) {
4998: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
1.468 raeburn 4999: $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
1.465 raeburn 5000: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 5001: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 5002: next if ($restricted);
5003: }
5004: $numchanges ++;
1.240 raeburn 5005: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 5006: } else {
5007: my $emptysec = 0;
1.404 raeburn 5008: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 5009: if ($sec ne '') {
5010: my $securl = $url.'/'.$sec;
1.465 raeburn 5011: my $secid = $securl.'_'.$two;
5012: unless ($udom eq $one) {
5013: undef($restricted);
5014: $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
1.468 raeburn 5015: $uname,$two,$start,$end,$cdom,$cnum,$sec,'',\%process_by,
1.465 raeburn 5016: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 5017: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 5018: next if ($restricted);
5019: }
5020: $numchanges ++;
1.240 raeburn 5021: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 5022: } else {
5023: $emptysec = 1;
5024: }
5025: }
5026: if ($emptysec) {
1.465 raeburn 5027: unless ($udom eq $one) {
5028: undef($restricted);
5029: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
1.468 raeburn 5030: $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
1.465 raeburn 5031: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 5032: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 5033: next if ($restricted);
5034: }
5035: $numchanges ++;
1.240 raeburn 5036: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 5037: }
1.465 raeburn 5038: next unless ($numchanges);
1.88 raeburn 5039: }
1.225 raeburn 5040: if (!grep(/^\Q$two\E$/,@rolechanges)) {
5041: push(@rolechanges,$two);
5042: }
1.64 www 5043: } else {
1.190 raeburn 5044: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 5045: }
1.113 raeburn 5046: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 5047: $r->print('<p class="LC_warning">');
1.113 raeburn 5048: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 5049: $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 5050: } else {
1.274 bisitz 5051: $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 5052: }
1.274 bisitz 5053: $r->print('</p><p>'
5054: .&mt('Please [_1]go back[_2] and choose a different section name.'
5055: ,'<a href="javascript:history.go(-1)'
5056: ,'</a>')
5057: .'</p><br />'
5058: );
1.113 raeburn 5059: }
5060: }
1.101 albertel 5061: } # End of foreach (keys(%env))
1.466 raeburn 5062: if ((keys(%reject)) || (keys(%unauthorized))) {
5063: $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized));
1.465 raeburn 5064: }
1.466 raeburn 5065: if ((keys(%pending)) || (keys(%currqueued))) {
5066: $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.465 raeburn 5067: }
1.75 www 5068: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 5069: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 5070: if (@rolechanges == 0) {
1.372 raeburn 5071: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 5072: }
1.225 raeburn 5073: return @rolechanges;
1.220 raeburn 5074: }
5075:
1.375 raeburn 5076: sub get_user_credits {
5077: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
5078: if ($cdom eq '' || $cnum eq '') {
5079: return unless ($env{'request.course.id'});
5080: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5081: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5082: }
5083: my $credits;
5084: my %currhash =
5085: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
5086: if (keys(%currhash) > 0) {
5087: my @items = split(/:/,$currhash{$uname.':'.$udom});
5088: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
5089: $credits = $items[$crdidx];
5090: $credits =~ s/[^\d\.]//g;
5091: }
5092: if ($credits eq $defaultcredits) {
5093: undef($credits);
5094: }
5095: return $credits;
5096: }
5097:
1.220 raeburn 5098: sub enroll_single_student {
1.375 raeburn 5099: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
5100: $showcredits,$defaultcredits) = @_;
1.318 raeburn 5101: $r->print('<h3>');
5102: if ($crstype eq 'Community') {
5103: $r->print(&mt('Enrolling Member'));
5104: } else {
5105: $r->print(&mt('Enrolling Student'));
5106: }
5107: $r->print('</h3>');
1.220 raeburn 5108:
5109: # Remove non alphanumeric values from section
5110: $env{'form.sections'}=~s/\W//g;
5111:
1.375 raeburn 5112: my $credits;
5113: if (($showcredits) && ($env{'form.credits'} ne '')) {
5114: $credits = $env{'form.credits'};
5115: $credits =~ s/[^\d\.]//g;
5116: if ($credits ne '') {
5117: if ($credits eq $defaultcredits) {
5118: undef($credits);
5119: }
5120: }
5121: }
1.465 raeburn 5122: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
1.466 raeburn 5123: my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,%pending,%reject,%notifydc,
5124: %status,%unauthorized,%currqueued);
1.465 raeburn 5125: unless ($env{'form.ccdomain'} eq $env{'course.'.$env{'request.course.id'}.'.domain'}) {
5126: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5127: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5128: my $csec = $env{'form.sections'};
5129: my $id = "/$cdom/$cnum";
5130: if ($csec ne '') {
5131: $id .= "/$csec";
5132: }
5133: $id .= '_st';
5134: if (&Apache::lonuserutils::restricted_dom($context,$id,$env{'form.ccdomain'},$env{'form.ccuname'},
5135: 'st',$startdate,$enddate,$cdom,$cnum,$csec,$credits,
5136: \%process_by,\%instdoms,\%got_role_approvals,\%got_instdoms,
1.466 raeburn 5137: \%reject,\%pending,\%notifydc,\%status,\%unauthorized,\%currqueued)) {
5138: if ((keys(%reject)) || (keys(%unauthorized))) {
5139: $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized));
1.465 raeburn 5140: }
1.466 raeburn 5141: if ((keys(%pending)) || (keys(%currqueued))) {
5142: $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.465 raeburn 5143: }
5144: return;
5145: }
5146: }
1.375 raeburn 5147:
1.220 raeburn 5148: # Clean out any old student roles the user has in this class.
5149: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
5150: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
5151: my $enroll_result =
5152: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
5153: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
5154: $env{'form.cmiddlename'},$env{'form.clastname'},
5155: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 5156: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
5157: $credits);
1.220 raeburn 5158: if ($enroll_result =~ /^ok/) {
1.381 bisitz 5159: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 5160: if ($env{'form.sections'} ne '') {
5161: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
5162: }
5163: my ($showstart,$showend);
5164: if ($startdate <= $now) {
5165: $showstart = &mt('Access starts immediately');
5166: } else {
5167: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
5168: }
5169: if ($enddate == 0) {
5170: $showend = &mt('ends: no ending date');
5171: } else {
5172: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
5173: }
5174: $r->print('.<br />'.$showstart.'; '.$showend);
5175: if ($startdate <= $now && !$newuser) {
1.386 bisitz 5176: $r->print('<p class="LC_info">');
1.318 raeburn 5177: if ($crstype eq 'Community') {
1.392 raeburn 5178: $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 5179: } else {
1.392 raeburn 5180: $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 5181: }
5182: $r->print('</p>');
1.220 raeburn 5183: }
5184: } else {
5185: $r->print(&mt('unable to enroll').": ".$enroll_result);
5186: }
5187: return;
1.188 raeburn 5188: }
5189:
1.204 raeburn 5190: sub get_defaultquota_text {
5191: my ($settingstatus) = @_;
5192: my $defquotatext;
5193: if ($settingstatus eq '') {
1.383 raeburn 5194: $defquotatext = &mt('default');
1.204 raeburn 5195: } else {
5196: my ($usertypes,$order) =
5197: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
5198: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 5199: $defquotatext = &mt('default');
1.204 raeburn 5200: } else {
1.383 raeburn 5201: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 5202: }
5203: }
5204: return $defquotatext;
5205: }
5206:
1.188 raeburn 5207: sub update_result_form {
5208: my ($uhome) = @_;
5209: my $outcome =
1.367 golterma 5210: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 5211: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 5212: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 5213: }
1.207 raeburn 5214: if ($env{'form.origname'} ne '') {
5215: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
5216: }
1.160 raeburn 5217: foreach my $item ('sortby','seluname','seludom') {
5218: if (exists($env{'form.'.$item})) {
1.188 raeburn 5219: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 5220: }
5221: }
1.188 raeburn 5222: if ($uhome eq 'no_host') {
5223: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
5224: }
5225: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 5226: '<input type="hidden" name="currstate" value="" />'."\n".
5227: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 5228: '</form>';
5229: return $outcome;
1.4 www 5230: }
5231:
1.149 raeburn 5232: sub quota_admin {
1.378 raeburn 5233: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 5234: my $quotachanged;
5235: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
5236: # Current user has quota modification privileges
1.267 raeburn 5237: if (ref($changeHash) eq 'HASH') {
5238: $quotachanged = 1;
1.378 raeburn 5239: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 5240: }
1.149 raeburn 5241: }
5242: return $quotachanged;
5243: }
5244:
1.267 raeburn 5245: sub tool_admin {
1.275 raeburn 5246: my ($tool,$settool,$changeHash,$context) = @_;
5247: my $canchange = 0;
1.279 raeburn 5248: if ($context eq 'requestcourses') {
1.275 raeburn 5249: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
5250: $canchange = 1;
5251: }
1.300 raeburn 5252: } elsif ($context eq 'reqcrsotherdom') {
5253: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
5254: $canchange = 1;
5255: }
1.362 raeburn 5256: } elsif ($context eq 'requestauthor') {
5257: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
5258: $canchange = 1;
5259: }
1.470 raeburn 5260: } elsif ($context eq 'authordefaults') {
5261: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
5262: $canchange = 1;
5263: }
1.275 raeburn 5264: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
5265: # Current user has quota modification privileges
5266: $canchange = 1;
5267: }
1.267 raeburn 5268: my $toolchanged;
1.275 raeburn 5269: if ($canchange) {
1.267 raeburn 5270: if (ref($changeHash) eq 'HASH') {
5271: $toolchanged = 1;
1.362 raeburn 5272: if ($tool eq 'requestauthor') {
5273: $changeHash->{$context} = $settool;
1.477 raeburn 5274: } elsif (($tool eq 'managers') || ($tool eq 'editors') || ($tool eq 'archive')) {
1.470 raeburn 5275: $changeHash->{'author'.$tool} = $settool;
5276: } elsif ($tool eq 'webdav') {
5277: $changeHash->{'tools.'.$tool} = $settool;
1.362 raeburn 5278: } else {
5279: $changeHash->{$context.'.'.$tool} = $settool;
5280: }
1.267 raeburn 5281: }
5282: }
5283: return $toolchanged;
5284: }
5285:
1.88 raeburn 5286: sub build_roles {
1.89 raeburn 5287: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 5288: my $num_sections = 0;
5289: if ($sectionstr=~ /,/) {
5290: my @secnums = split/,/,$sectionstr;
1.89 raeburn 5291: if ($role eq 'st') {
5292: $secnums[0] =~ s/\W//g;
5293: $$sections{$secnums[0]} = 1;
5294: $num_sections = 1;
5295: } else {
5296: foreach my $sec (@secnums) {
5297: $sec =~ ~s/\W//g;
1.150 banghart 5298: if (!($sec eq "")) {
1.89 raeburn 5299: if (exists($$sections{$sec})) {
5300: $$sections{$sec} ++;
5301: } else {
5302: $$sections{$sec} = 1;
5303: $num_sections ++;
5304: }
1.88 raeburn 5305: }
5306: }
5307: }
5308: } else {
5309: $sectionstr=~s/\W//g;
5310: unless ($sectionstr eq '') {
5311: $$sections{$sectionstr} = 1;
5312: $num_sections ++;
5313: }
5314: }
1.129 albertel 5315:
1.88 raeburn 5316: return $num_sections;
5317: }
5318:
1.58 www 5319: # ========================================================== Custom Role Editor
5320:
5321: sub custom_role_editor {
1.439 raeburn 5322: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 5323: my $action = $env{'form.customroleaction'};
1.439 raeburn 5324: my ($rolename,$helpitem);
1.324 raeburn 5325: if ($action eq 'new') {
5326: $rolename=$env{'form.newrolename'};
5327: } else {
5328: $rolename=$env{'form.rolename'};
1.59 www 5329: }
5330:
1.324 raeburn 5331: my ($crstype,$context);
5332: if ($env{'request.course.id'}) {
5333: $crstype = &Apache::loncommon::course_type();
5334: $context = 'course';
1.439 raeburn 5335: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 5336: } else {
5337: $context = 'domain';
1.414 raeburn 5338: $crstype = 'course';
1.439 raeburn 5339: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 5340: }
1.351 raeburn 5341:
5342: $rolename=~s/[^A-Za-z0-9]//gs;
5343: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 5344: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
5345: $permission);
1.351 raeburn 5346: return;
5347: }
5348:
1.414 raeburn 5349: my $formname = 'form1';
5350: my %privs=();
5351: my $body_top = '<h2>';
5352: # ------------------------------------------------------- Does this role exist?
1.59 www 5353: my ($rdummy,$roledef)=
5354: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
5355: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 5356: $body_top .= &mt('Existing Role').' "';
1.61 www 5357: # ------------------------------------------------- Get current role privileges
1.414 raeburn 5358: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
5359: if ($privs{'system'} =~ /bre\&S/) {
5360: if ($context eq 'domain') {
1.417 raeburn 5361: $crstype = 'Course';
1.414 raeburn 5362: } elsif ($crstype eq 'Community') {
5363: $privs{'system'} =~ s/bre\&S//;
5364: }
5365: } elsif ($context eq 'domain') {
5366: $crstype = 'Course';
1.324 raeburn 5367: }
1.59 www 5368: } else {
1.414 raeburn 5369: $body_top .= &mt('New Role').' "';
5370: $roledef='';
1.59 www 5371: }
1.153 banghart 5372: $body_top .= $rolename.'"</h2>';
1.414 raeburn 5373:
5374: # ------------------------------------------------------- What can be assigned?
5375: my %full=();
1.417 raeburn 5376: my %levels=(
1.414 raeburn 5377: course => {},
5378: domain => {},
5379: system => {},
5380: );
5381: my %levelscurrent=(
5382: course => {},
5383: domain => {},
5384: system => {},
5385: );
5386: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 5387: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 5388: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 5389: my $head_script =
1.414 raeburn 5390: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
5391: \%full,\@templateroles,$jsback);
1.351 raeburn 5392: push (@{$brcrum},
1.414 raeburn 5393: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 5394: text => "Pick custom role",
5395: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 5396: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 5397: text => "Edit custom role",
5398: faq => 282,
5399: bug => 'Instructor Interface',
1.439 raeburn 5400: help => $helpitem}
1.351 raeburn 5401: );
5402: my $args = { bread_crumbs => $brcrum,
5403: bread_crumbs_component => 'User Management'};
5404: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
5405: $head_script,$args).
5406: $body_top);
1.414 raeburn 5407: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
5408: &Apache::lonuserutils::custom_role_header($context,$crstype,
5409: \@templateroles,$prefix));
1.264 bisitz 5410:
1.61 www 5411: $r->print(<<ENDCCF);
5412: <input type="hidden" name="phase" value="set_custom_roles" />
5413: <input type="hidden" name="rolename" value="$rolename" />
5414: ENDCCF
1.414 raeburn 5415: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
5416: \%levelscurrent,$prefix));
1.135 raeburn 5417: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 5418: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 5419: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 5420: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 5421: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 5422: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 5423: }
1.414 raeburn 5424:
1.61 www 5425: # ---------------------------------------------------------- Call to definerole
5426: sub set_custom_role {
1.439 raeburn 5427: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 5428: my $rolename=$env{'form.rolename'};
1.63 www 5429: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 5430: if (!$rolename) {
1.439 raeburn 5431: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 5432: return;
5433: }
1.160 raeburn 5434: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 5435: my $jscript = '<script type="text/javascript">'
5436: .'// <![CDATA['."\n"
5437: .$jsback."\n"
5438: .'// ]]>'."\n"
5439: .'</script>'."\n";
1.439 raeburn 5440: my $helpitem = 'Course_Editing_Custom_Roles';
5441: if ($context eq 'domain') {
5442: $helpitem = 'Domain_Editing_Custom_Roles';
5443: }
1.352 raeburn 5444: push(@{$brcrum},
5445: {href => "javascript:backPage(document.customresult,'pickrole','')",
5446: text => "Pick custom role",
5447: faq => 282,
5448: bug => 'Instructor Interface',},
5449: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
5450: text => "Edit custom role",
5451: faq => 282,
5452: bug => 'Instructor Interface',},
5453: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
5454: text => "Result",
5455: faq => 282,
5456: bug => 'Instructor Interface',
1.439 raeburn 5457: help => $helpitem,}
1.352 raeburn 5458: );
5459: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 5460: bread_crumbs_component => 'User Management'};
1.351 raeburn 5461: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 5462:
1.393 raeburn 5463: my $newrole;
1.61 www 5464: my ($rdummy,$roledef)=
1.110 albertel 5465: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
5466:
1.61 www 5467: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 5468: $r->print('<h3>');
1.61 www 5469: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 5470: $r->print(&mt('Existing Role').' "');
1.61 www 5471: } else {
1.73 sakharuk 5472: $r->print(&mt('New Role').' "');
1.61 www 5473: $roledef='';
1.393 raeburn 5474: $newrole = 1;
1.61 www 5475: }
1.188 raeburn 5476: $r->print($rolename.'"</h3>');
1.414 raeburn 5477: # ------------------------------------------------- Assign role and show result
1.61 www 5478:
1.387 bisitz 5479: my $errmsg;
1.414 raeburn 5480: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
5481: # Assign role and return result
5482: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
5483: $newprivs{'c'});
1.387 bisitz 5484: if ($result ne 'ok') {
5485: $errmsg = ': '.$result;
5486: }
5487: my $message =
5488: &Apache::lonhtmlcommon::confirm_success(
5489: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 5490: if ($env{'request.course.id'}) {
5491: my $url='/'.$env{'request.course.id'};
1.63 www 5492: $url=~s/\_/\//g;
1.387 bisitz 5493: $result =
5494: &Apache::lonnet::assigncustomrole(
5495: $env{'user.domain'},$env{'user.name'},
5496: $url,
5497: $env{'user.domain'},$env{'user.name'},
5498: $rolename,undef,undef,undef,$context);
5499: if ($result ne 'ok') {
5500: $errmsg = ': '.$result;
5501: }
5502: $message .=
5503: '<br />'
5504: .&Apache::lonhtmlcommon::confirm_success(
5505: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 5506: }
1.380 bisitz 5507: $r->print(
1.387 bisitz 5508: &Apache::loncommon::confirmwrapper($message)
5509: .'<br />'
5510: .&Apache::lonhtmlcommon::actionbox([
5511: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
5512: .&mt('Create or edit another custom role')
5513: .'</a>'])
1.380 bisitz 5514: .'<form name="customresult" method="post" action="">'
1.387 bisitz 5515: .&Apache::lonhtmlcommon::echo_form_input([])
5516: .'</form>'
1.380 bisitz 5517: );
1.58 www 5518: }
5519:
1.465 raeburn 5520: sub show_role_requests {
5521: my ($caller,$dom) = @_;
5522: my $showrolereqs;
5523: my %domconfig = &Apache::lonnet::get_dom('configuration',['privacy'],$dom);
5524: if (ref($domconfig{'privacy'}) eq 'HASH') {
5525: if (ref($domconfig{'privacy'}{'approval'}) eq 'HASH') {
5526: my %approvalconf = %{$domconfig{'privacy'}{'approval'}};
5527: foreach my $key ('instdom','extdom') {
5528: if (ref($approvalconf{$key}) eq 'HASH') {
5529: if (keys(%{$approvalconf{$key}})) {
5530: foreach my $context ('domain','author','course','community') {
5531: if ($approvalconf{$key}{$context} eq $caller) {
5532: $showrolereqs = 1;
5533: last if ($showrolereqs);
5534: }
5535: }
5536: }
5537: }
5538: last if ($showrolereqs);
5539: }
5540: }
5541: }
5542: return $showrolereqs;
5543: }
5544:
1.470 raeburn 5545: sub display_coauthor_managers {
5546: my ($permission) = @_;
5547: my $output;
5548: if ((ref($permission) eq 'HASH') && ($permission->{'author'})) {
5549: $output = '<form action="/adm/createuser" method="post" name="camanagers">'.
5550: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
5551: '<p>';
5552: my (@possmanagers,@custommanagers);
5553: my %userenv =
5554: &Apache::lonnet::userenvironment($env{'user.domain'},
5555: $env{'user.name'},
5556: 'authormanagers');
5557: my %ca_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5558: ['active','future'],['ca']);
5559: if (keys(%ca_roles)) {
5560: foreach my $entry (sort(keys(%ca_roles))) {
5561: if ($entry =~ /^($match_username\:$match_domain):ca$/) {
5562: my $user = $1;
5563: unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5564: push(@possmanagers,$user);
5565: }
5566: }
5567: }
5568: }
5569: if ($userenv{'authormanagers'} eq '') {
5570: $output .= &mt('Currently author manages co-author roles');
5571: } else {
5572: if (keys(%ca_roles)) {
5573: foreach my $user (split(/,/,$userenv{'authormanagers'})) {
5574: if ($user =~ /^($match_username)\:($match_domain)$/) {
5575: if (exists($ca_roles{$user.':ca'})) {
5576: unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5577: push(@custommanagers,$user);
5578: }
5579: }
5580: }
5581: }
5582: }
5583: if (@custommanagers) {
5584: $output .= &mt('Co-authors with active or future roles who currently manage co-author roles: [_1]',
5585: '<br />'.join(', ',map { &Apache::loncommon::plainname(split(':',$_))." ($_)"; } @custommanagers));
5586: } else {
5587: $output .= &mt('Currently author manages co-author roles');
5588: }
5589: }
5590: $output .= "</p>\n";
5591: if (@possmanagers) {
1.472 raeburn 5592: $output .= '<p>'.&mt('If checked, can manage').': ';
1.470 raeburn 5593: foreach my $user (@possmanagers) {
5594: my $checked;
5595: if (grep(/^\Q$user\E$/,@custommanagers)) {
5596: $checked = ' checked="checked"';
5597: }
5598: $output .= '<span style="LC_nobreak"><label>'.
5599: '<input type="checkbox" name="custommanagers" '.
5600: 'value="'.&HTML::Entities::encode($user,'\'<>"&').'"'.$checked.' />'.
5601: &Apache::loncommon::plainname(split(/:/,$user))." ($user)".'</label></span> '."\n";
5602: }
5603: $output .= '<input type="hidden" name="state" value="process" /></p>'."\n".
5604: '<p><input type="submit" value="'.&mt('Save changes').'" /></p>'."\n";
5605: } else {
5606: $output .= '<p>'.&mt('No co-author roles assignable as manager').'</p>';
5607: }
5608: $output .= '</form>';
5609: } else {
5610: $output = '<span class="LC_warning">'.
5611: &mt('You do not have permission to perform this action').
5612: '</span>';
5613: }
5614: return $output;
5615: }
5616:
5617: sub update_coauthor_managers {
5618: my ($permission) = @_;
5619: my $output;
5620: if ((ref($permission) eq 'HASH') && ($permission->{'author'})) {
5621: my ($current,$newval,@possibles,@managers);
5622: my %userenv =
5623: &Apache::lonnet::userenvironment($env{'user.domain'},
5624: $env{'user.name'},
5625: 'authormanagers');
5626: $current = $userenv{'authormanagers'};
5627: @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
5628: if (@possibles) {
5629: my %ca_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5630: ['active','future'],['ca']);
5631: if (keys(%ca_roles)) {
5632: foreach my $user (@possibles) {
5633: if ($user =~ /^($match_username):($match_domain)$/) {
5634: if (exists($ca_roles{$user.':ca'})) {
5635: unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5636: push(@managers,$user);
5637: }
5638: }
5639: }
5640: }
5641: if (@managers) {
5642: $newval = join(',',sort(@managers));
5643: }
5644: }
5645: }
5646: if ($current eq $newval) {
5647: $output = &mt('No changes made to management of co-author roles');
5648: } else {
5649: my $chgresult =
5650: &Apache::lonnet::put('environment',{'authormanagers' => $newval},
5651: $env{'user.domain'},$env{'user.name'});
5652: if ($chgresult eq 'ok') {
5653: &Apache::lonnet::appenv({'environment.authormanagers' => $newval});
5654: my (@adds,@dels);
5655: if ($newval eq '') {
5656: @dels = split(/,/,$current);
5657: } elsif ($current eq '') {
5658: @adds = @managers;
5659: } else {
5660: my @old = split(/,/,$current);
5661: my @diffs = &Apache::loncommon::compare_arrays(\@old,\@managers);
5662: if (@diffs) {
5663: foreach my $user (@diffs) {
5664: if (grep(/^\Q$user\E$/,@old)) {
5665: push(@dels,$user);
5666: } elsif (grep(/^\Q$user\E$/,@managers)) {
5667: push(@adds,$user);
5668: }
5669: }
5670: }
5671: }
5672: my $key = "internal.manager./$env{'user.domain'}/$env{'user.name'}";
5673: if (@dels) {
5674: foreach my $user (@dels) {
5675: if ($user =~ /^($match_username):($match_domain)$/) {
5676: &Apache::lonnet::del('environment',[$key],$2,$1);
5677: }
5678: }
5679: }
5680: if (@adds) {
5681: foreach my $user (@adds) {
5682: if ($user =~ /^($match_username):($match_domain)$/) {
5683: &Apache::lonnet::put('environment',{$key => 1},$2,$1);
5684: }
5685: }
5686: }
5687: if ($newval eq '') {
5688: $output = &mt('Management of co-authors set to be author-only');
5689: } else {
5690: $output .= &mt('Co-authors who can manage co-author roles set to: [_1]',
5691: '<br />'.join(', ',map { &Apache::loncommon::plainname(split(':',$_))." ($_)"; } @managers));
5692: }
5693: }
5694: }
5695: } else {
5696: $output = '<span class="LC_warning">'.
5697: &mt('You do not have permission to perform this action').
5698: '</span>';
5699: }
5700: return $output;
5701: }
5702:
1.2 www 5703: # ================================================================ Main Handler
5704: sub handler {
5705: my $r = shift;
5706: if ($r->header_only) {
1.68 www 5707: &Apache::loncommon::content_type($r,'text/html');
1.2 www 5708: $r->send_http_header;
5709: return OK;
5710: }
1.439 raeburn 5711: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
5712:
1.190 raeburn 5713: if ($env{'request.course.id'}) {
5714: $context = 'course';
1.318 raeburn 5715: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 5716: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 5717: $context = 'author';
1.470 raeburn 5718: } elsif ($env{'request.role'} =~ m{^(ca|aa)\./$match_domain/$match_username$}) {
5719: $context = 'coauthor';
1.190 raeburn 5720: } else {
5721: $context = 'domain';
5722: }
1.375 raeburn 5723:
1.439 raeburn 5724: my ($permission,$allowed) =
5725: &Apache::lonuserutils::get_permission($context,$crstype);
1.470 raeburn 5726: if (($context eq 'coauthor') && ($allowed)) {
5727: $context = 'author';
5728: }
1.439 raeburn 5729:
5730: if ($allowed) {
5731: my @allhelp;
5732: if ($context eq 'course') {
5733: $cid = $env{'request.course.id'};
5734: $cdom = $env{'course.'.$cid.'.domain'};
5735: $cnum = $env{'course.'.$cid.'.num'};
5736:
5737: if ($permission->{'cusr'}) {
5738: push(@allhelp,'Course_Create_Class_List');
5739: }
5740: if ($permission->{'view'} || $permission->{'cusr'}) {
5741: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
5742: }
5743: if ($permission->{'custom'}) {
5744: push(@allhelp,'Course_Editing_Custom_Roles');
5745: }
5746: if ($permission->{'cusr'}) {
5747: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
5748: }
5749: unless ($permission->{'cusr_section'}) {
5750: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
5751: push(@allhelp,'Course_Automated_Enrollment');
5752: }
1.469 raeburn 5753: if (($permission->{'selfenrolladmin'}) || ($permission->{'selfenrollview'})) {
1.439 raeburn 5754: push(@allhelp,'Course_Approve_Selfenroll');
5755: }
5756: }
5757: if ($permission->{'grp_manage'}) {
5758: push(@allhelp,'Course_Manage_Group');
5759: }
5760: if ($permission->{'view'} || $permission->{'cusr'}) {
5761: push(@allhelp,'Course_User_Logs');
5762: }
5763: } elsif ($context eq 'author') {
5764: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
5765: 'Author_View_Coauthor_List','Author_User_Logs'));
1.470 raeburn 5766: } elsif ($context eq 'coauthor') {
5767: if ($permission->{'cusr'}) {
5768: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
5769: 'Author_View_Coauthor_List','Author_User_Logs'));
5770: } elsif ($permission->{'view'}) {
5771: push(@allhelp,'Author_View_Coauthor_List');
5772: }
1.439 raeburn 5773: } else {
5774: if ($permission->{'cusr'}) {
5775: push(@allhelp,'Domain_Change_Privileges');
5776: if ($permission->{'activity'}) {
5777: push(@allhelp,'Domain_User_Access_Logs');
5778: }
5779: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
5780: if ($permission->{'custom'}) {
5781: push(@allhelp,'Domain_Editing_Custom_Roles');
5782: }
5783: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
5784: } elsif ($permission->{'view'}) {
5785: push(@allhelp,'Domain_View_Privileges');
5786: if ($permission->{'activity'}) {
5787: push(@allhelp,'Domain_User_Access_Logs');
5788: }
5789: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
5790: }
5791: }
5792: if (@allhelp) {
5793: $allhelpitems = join(',',@allhelp);
5794: }
5795: }
5796:
1.190 raeburn 5797: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 5798: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.470 raeburn 5799: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue',
5800: 'forceedit']);
1.190 raeburn 5801: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 5802: my $args;
5803: my $brcrum = [];
5804: my $bread_crumbs_component = 'User Management';
1.391 raeburn 5805: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 5806: $brcrum = [{href=>"/adm/createuser",
5807: text=>"User Management",
1.439 raeburn 5808: help=>$allhelpitems}
1.351 raeburn 5809: ];
1.202 raeburn 5810: }
1.190 raeburn 5811: if (!$allowed) {
1.358 raeburn 5812: if ($context eq 'course') {
5813: $r->internal_redirect('/adm/viewclasslist');
5814: return OK;
1.470 raeburn 5815: } elsif ($context eq 'coauthor') {
5816: $r->internal_redirect('/adm/viewcoauthors');
5817: return OK;
1.358 raeburn 5818: }
1.190 raeburn 5819: $env{'user.error.msg'}=
5820: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
5821: "or view user status.";
5822: return HTTP_NOT_ACCEPTABLE;
5823: }
5824:
5825: &Apache::loncommon::content_type($r,'text/html');
5826: $r->send_http_header;
5827:
1.375 raeburn 5828: my $showcredits;
5829: if ((($context eq 'course') && ($crstype eq 'Course')) ||
5830: ($context eq 'domain')) {
5831: my %domdefaults =
5832: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
5833: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
5834: $showcredits = 1;
5835: }
5836: }
5837:
1.190 raeburn 5838: # Main switch on form.action and form.state, as appropriate
5839: if (! exists($env{'form.action'})) {
1.351 raeburn 5840: $args = {bread_crumbs => $brcrum,
5841: bread_crumbs_component => $bread_crumbs_component};
5842: $r->print(&header(undef,$args));
1.318 raeburn 5843: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5844: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 5845: my $helpitem = 'Course_Create_Class_List';
5846: if ($context eq 'author') {
5847: $helpitem = 'Author_Create_Coauthor_List';
5848: } elsif ($context eq 'domain') {
5849: $helpitem = 'Domain_Create_Users';
5850: }
1.351 raeburn 5851: push(@{$brcrum},
5852: { href => '/adm/createuser?action=upload&state=',
5853: text => 'Upload Users List',
1.439 raeburn 5854: help => $helpitem,
1.351 raeburn 5855: });
5856: $bread_crumbs_component = 'Upload Users List';
5857: $args = {bread_crumbs => $brcrum,
5858: bread_crumbs_component => $bread_crumbs_component};
5859: $r->print(&header(undef,$args));
1.190 raeburn 5860: $r->print('<form name="studentform" method="post" '.
5861: 'enctype="multipart/form-data" '.
5862: ' action="/adm/createuser">'."\n");
5863: if (! exists($env{'form.state'})) {
5864: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5865: } elsif ($env{'form.state'} eq 'got_file') {
1.448 raeburn 5866: my $result =
5867: &Apache::lonuserutils::print_upload_manager_form($r,$context,
5868: $permission,
5869: $crstype,$showcredits);
5870: if ($result eq 'missingdata') {
5871: delete($env{'form.state'});
5872: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5873: }
1.190 raeburn 5874: } elsif ($env{'form.state'} eq 'enrolling') {
5875: if ($env{'form.datatoken'}) {
1.448 raeburn 5876: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
5877: $permission,
5878: $showcredits);
5879: if ($result eq 'missingdata') {
5880: delete($env{'form.state'});
5881: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5882: } elsif ($result eq 'invalidhome') {
5883: $env{'form.state'} = 'got_file';
5884: delete($env{'form.lcserver'});
5885: my $result =
5886: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
5887: $crstype,$showcredits);
5888: if ($result eq 'missingdata') {
5889: delete($env{'form.state'});
5890: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5891: }
5892: }
5893: } else {
5894: delete($env{'form.state'});
5895: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 5896: }
5897: } else {
5898: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5899: }
1.447 raeburn 5900: $r->print('</form>');
1.416 raeburn 5901: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
5902: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 5903: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 5904: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 5905: my $phase = $env{'form.phase'};
5906: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 5907: &Apache::loncreateuser::restore_prev_selections();
5908: my $srch;
5909: foreach my $item (@search) {
5910: $srch->{$item} = $env{'form.'.$item};
5911: }
1.207 raeburn 5912: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 5913: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 5914: if ($env{'form.phase'} eq 'createnewuser') {
5915: my $response;
5916: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 5917: my $response =
5918: '<span class="LC_warning">'
5919: .&mt('You must specify a valid username. Only the following are allowed:'
5920: .' letters numbers - . @')
5921: .'</span>';
1.221 raeburn 5922: $env{'form.phase'} = '';
1.375 raeburn 5923: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 5924: $crstype,$brcrum,$permission);
1.207 raeburn 5925: } else {
5926: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
5927: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
5928: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 5929: $srch,$response,$context,
1.375 raeburn 5930: $permission,$crstype,$brcrum,
5931: $showcredits);
1.207 raeburn 5932: }
5933: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 5934: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 5935: &user_search_result($context,$srch);
1.190 raeburn 5936: if ($env{'form.currstate'} eq 'modify') {
5937: $currstate = $env{'form.currstate'};
5938: }
5939: if ($currstate eq 'select') {
5940: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 5941: \@search,$context,undef,$crstype,
5942: $brcrum);
1.416 raeburn 5943: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
5944: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 5945: if (($srch->{'srchby'} eq 'uname') &&
5946: ($srch->{'srchtype'} eq 'exact')) {
5947: $ccuname = $srch->{'srchterm'};
5948: $ccdomain= $srch->{'srchdomain'};
5949: } else {
5950: my @matchedunames = keys(%{$results});
5951: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
5952: }
5953: $ccuname =&LONCAPA::clean_username($ccuname);
5954: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 5955: if ($env{'form.action'} eq 'accesslogs') {
5956: my $uhome;
5957: if (($ccuname ne '') && ($ccdomain ne '')) {
5958: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
5959: }
5960: if (($uhome eq '') || ($uhome eq 'no_host')) {
5961: $env{'form.phase'} = '';
5962: undef($forcenewuser);
5963: #if ($response) {
5964: # unless ($response =~ m{\Q<br /><br />\E$}) {
5965: # $response .= '<br /><br />';
5966: # }
5967: #}
5968: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 5969: $forcenewuser,$crstype,$brcrum,
5970: $permission);
1.416 raeburn 5971: } else {
5972: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
5973: }
5974: } else {
5975: if ($env{'form.forcenewuser'}) {
5976: $response = '';
5977: }
5978: &print_user_modification_page($r,$ccuname,$ccdomain,
5979: $srch,$response,$context,
5980: $permission,$crstype,$brcrum);
1.190 raeburn 5981: }
5982: } elsif ($currstate eq 'query') {
1.351 raeburn 5983: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 5984: } else {
1.229 raeburn 5985: $env{'form.phase'} = '';
1.207 raeburn 5986: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 5987: $forcenewuser,$crstype,$brcrum,
5988: $permission);
1.190 raeburn 5989: }
5990: } elsif ($env{'form.phase'} eq 'userpicked') {
5991: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
5992: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 5993: if ($env{'form.action'} eq 'accesslogs') {
5994: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
5995: } else {
5996: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
5997: $context,$permission,$crstype,
5998: $brcrum);
5999: }
6000: } elsif ($env{'form.action'} eq 'accesslogs') {
6001: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
6002: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
6003: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 6004: }
6005: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.451 raeburn 6006: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 6007: } else {
1.351 raeburn 6008: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 6009: $brcrum,$permission);
1.190 raeburn 6010: }
6011: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 6012: my $prefix;
1.190 raeburn 6013: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 6014: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 6015: } else {
1.439 raeburn 6016: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 6017: }
1.362 raeburn 6018: } elsif (($env{'form.action'} eq 'processauthorreq') &&
6019: ($permission->{'cusr'}) &&
6020: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
6021: push(@{$brcrum},
6022: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 6023: text => 'Authoring Space requests',
1.362 raeburn 6024: help => 'Domain_Role_Approvals'});
6025: $bread_crumbs_component = 'Authoring requests';
6026: if ($env{'form.state'} eq 'done') {
6027: push(@{$brcrum},
6028: {href => '/adm/createuser?action=authorreqqueue',
6029: text => 'Result',
6030: help => 'Domain_Role_Approvals'});
6031: $bread_crumbs_component = 'Authoring request result';
6032: }
6033: $args = { bread_crumbs => $brcrum,
6034: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 6035: my $js = &usernamerequest_javascript();
6036: $r->print(&header(&add_script($js),$args));
1.362 raeburn 6037: if (!exists($env{'form.state'})) {
6038: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
6039: $env{'request.role.domain'}));
6040: } elsif ($env{'form.state'} eq 'done') {
6041: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
6042: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
6043: $env{'request.role.domain'}));
6044: }
1.391 raeburn 6045: } elsif (($env{'form.action'} eq 'processusernamereq') &&
6046: ($permission->{'cusr'}) &&
6047: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
6048: push(@{$brcrum},
6049: {href => '/adm/createuser?action=processusernamereq',
6050: text => 'LON-CAPA account requests',
6051: help => 'Domain_Username_Approvals'});
6052: $bread_crumbs_component = 'Account requests';
6053: if ($env{'form.state'} eq 'done') {
6054: push(@{$brcrum},
6055: {href => '/adm/createuser?action=usernamereqqueue',
6056: text => 'Result',
6057: help => 'Domain_Username_Approvals'});
6058: $bread_crumbs_component = 'LON-CAPA account request result';
6059: }
6060: $args = { bread_crumbs => $brcrum,
6061: bread_crumbs_component => $bread_crumbs_component};
6062: my $js = &usernamerequest_javascript();
6063: $r->print(&header(&add_script($js),$args));
6064: if (!exists($env{'form.state'})) {
6065: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
6066: $env{'request.role.domain'}));
6067: } elsif ($env{'form.state'} eq 'done') {
6068: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
6069: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
6070: $env{'request.role.domain'}));
6071: }
6072: } elsif (($env{'form.action'} eq 'displayuserreq') &&
6073: ($permission->{'cusr'})) {
6074: my $dom = $env{'form.domain'};
6075: my $uname = $env{'form.username'};
6076: my $warning;
6077: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
6078: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
6079: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
6080: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
6081: if ($uhome eq 'no_host') {
6082: my $queue = $env{'form.queue'};
6083: my $reqkey = &escape($uname).'_'.$queue;
6084: my $namespace = 'usernamequeue';
6085: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
6086: my %queued =
6087: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
6088: unless ($queued{$reqkey}) {
6089: $warning = &mt('No information was found for this LON-CAPA account request.');
6090: }
6091: } else {
6092: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
6093: }
6094: } else {
6095: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
6096: }
6097: } else {
6098: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
6099: }
6100: } else {
6101: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
6102: }
6103: my $args = { only_body => 1 };
6104: $r->print(&header(undef,$args).
6105: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
6106: if ($warning ne '') {
6107: $r->print('<div class="LC_warning">'.$warning.'</div>');
6108: } else {
6109: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
6110: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
6111: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6112: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6113: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
6114: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
6115: my %info =
6116: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
6117: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 6118: my $usertype = $info{$uname}{'inststatus'};
6119: unless ($usertype) {
6120: $usertype = 'default';
6121: }
1.442 raeburn 6122: my ($showstatus,$showemail,$pickstart);
6123: my $numextras = 0;
6124: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.443 raeburn 6125: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
6126: if (ref($usertypes) eq 'HASH') {
6127: if ($usertypes->{$usertype}) {
6128: $showstatus = $usertypes->{$usertype};
6129: } else {
6130: $showstatus = $othertitle;
6131: }
6132: if ($showstatus) {
6133: $numextras ++;
6134: }
1.442 raeburn 6135: }
6136: }
6137: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
6138: $showemail = $info{$uname}{'email'};
6139: $numextras ++;
6140: }
1.396 raeburn 6141: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
6142: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.442 raeburn 6143: $pickstart = 1;
1.396 raeburn 6144: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.442 raeburn 6145: my ($num,$count);
1.396 raeburn 6146: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.442 raeburn 6147: $count += $numextras;
1.396 raeburn 6148: foreach my $field (@{$infofields}) {
6149: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
6150: next unless ($infotitles->{$field});
6151: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
6152: $info{$uname}{$field});
6153: $num ++;
1.442 raeburn 6154: unless ($count == $num) {
1.396 raeburn 6155: $r->print(&Apache::lonhtmlcommon::row_closure());
6156: }
6157: }
1.442 raeburn 6158: }
6159: }
6160: if ($numextras) {
6161: unless ($pickstart) {
6162: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
6163: $pickstart = 1;
6164: }
6165: if ($showemail) {
6166: my $closure = '';
6167: unless ($showstatus) {
6168: $closure = 1;
1.391 raeburn 6169: }
1.442 raeburn 6170: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
6171: $showemail.
6172: &Apache::lonhtmlcommon::row_closure($closure));
1.391 raeburn 6173: }
1.442 raeburn 6174: if ($showstatus) {
6175: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
6176: $showstatus.
6177: &Apache::lonhtmlcommon::row_closure(1));
6178: }
6179: }
6180: if ($pickstart) {
6181: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
6182: } else {
6183: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
1.391 raeburn 6184: }
1.442 raeburn 6185: } else {
6186: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 6187: }
6188: }
6189: }
6190: }
6191: }
1.442 raeburn 6192: $r->print(&close_popup_form());
1.207 raeburn 6193: } elsif (($env{'form.action'} eq 'listusers') &&
6194: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 6195: my $helpitem = 'Course_View_Class_List';
6196: if ($context eq 'author') {
6197: $helpitem = 'Author_View_Coauthor_List';
6198: } elsif ($context eq 'domain') {
6199: $helpitem = 'Domain_View_Users_List';
6200: }
1.202 raeburn 6201: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 6202: push(@{$brcrum},
6203: {href => '/adm/createuser?action=listusers',
6204: text => "List Users"},
6205: {href => "/adm/createuser",
6206: text => "Result",
1.439 raeburn 6207: help => $helpitem});
1.351 raeburn 6208: $bread_crumbs_component = 'Update Users';
6209: $args = {bread_crumbs => $brcrum,
6210: bread_crumbs_component => $bread_crumbs_component};
6211: $r->print(&header(undef,$args));
1.202 raeburn 6212: my $setting = $env{'form.roletype'};
6213: my $choice = $env{'form.bulkaction'};
6214: if ($permission->{'cusr'}) {
1.336 raeburn 6215: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 6216: } else {
6217: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 6218: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 6219: }
6220: } else {
1.351 raeburn 6221: push(@{$brcrum},
6222: {href => '/adm/createuser?action=listusers',
6223: text => "List Users",
1.439 raeburn 6224: help => $helpitem});
1.351 raeburn 6225: $bread_crumbs_component = 'List Users';
6226: $args = {bread_crumbs => $brcrum,
6227: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 6228: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
6229: my $formname = 'studentform';
1.364 raeburn 6230: my $hidecall = "hide_searching();";
1.321 raeburn 6231: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
6232: ($env{'form.roletype'} eq 'community'))) {
6233: if ($env{'form.roletype'} eq 'course') {
6234: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
6235: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
6236: $formname);
6237: } elsif ($env{'form.roletype'} eq 'community') {
6238: $cb_jscript =
6239: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
6240: my %elements = (
6241: coursepick => 'radio',
6242: coursetotal => 'text',
6243: courselist => 'text',
6244: );
6245: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
6246: }
1.364 raeburn 6247: $jscript .= &verify_user_display($context)."\n".
6248: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 6249: my $js = &add_script($jscript).$cb_jscript;
6250: my $loadcode =
6251: &Apache::lonuserutils::course_selector_loadcode($formname);
6252: if ($loadcode ne '') {
1.364 raeburn 6253: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
6254: } else {
6255: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 6256: }
1.351 raeburn 6257: $r->print(&header($js,$args));
1.191 raeburn 6258: } else {
1.364 raeburn 6259: $args->{add_entries} = {onload => $hidecall};
6260: $jscript = &verify_user_display($context).
6261: &Apache::loncommon::check_uncheck_jscript();
6262: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 6263: }
1.202 raeburn 6264: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 6265: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
6266: $showcredits);
1.191 raeburn 6267: }
1.213 raeburn 6268: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 6269: my $brtext;
6270: if ($crstype eq 'Community') {
6271: $brtext = 'Drop Members';
6272: } else {
6273: $brtext = 'Drop Students';
6274: }
1.351 raeburn 6275: push(@{$brcrum},
6276: {href => '/adm/createuser?action=drop',
6277: text => $brtext,
6278: help => 'Course_Drop_Student'});
6279: if ($env{'form.state'} eq 'done') {
6280: push(@{$brcrum},
6281: {href=>'/adm/createuser?action=drop',
6282: text=>"Result"});
6283: }
6284: $bread_crumbs_component = $brtext;
6285: $args = {bread_crumbs => $brcrum,
6286: bread_crumbs_component => $bread_crumbs_component};
6287: $r->print(&header(undef,$args));
1.213 raeburn 6288: if (!exists($env{'form.state'})) {
1.318 raeburn 6289: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 6290: } elsif ($env{'form.state'} eq 'done') {
6291: &Apache::lonuserutils::update_user_list($r,$context,undef,
6292: $env{'form.action'});
6293: }
1.202 raeburn 6294: } elsif ($env{'form.action'} eq 'dateselect') {
6295: if ($permission->{'cusr'}) {
1.351 raeburn 6296: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 6297: &Apache::lonuserutils::date_section_selector($context,$permission,
6298: $crstype,$showcredits));
1.202 raeburn 6299: } else {
1.351 raeburn 6300: $r->print(&header(undef,{'no_nav_bar' => 1}).
6301: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 6302: }
1.237 raeburn 6303: } elsif ($env{'form.action'} eq 'selfenroll') {
1.469 raeburn 6304: my %currsettings;
6305: if ($permission->{selfenrolladmin} || $permission->{selfenrollview}) {
6306: %currsettings = (
1.398 raeburn 6307: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
6308: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
6309: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
6310: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
6311: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
6312: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
6313: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
6314: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
6315: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
6316: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
6317: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
6318: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
6319: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 6320: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 6321: );
1.469 raeburn 6322: }
6323: if ($permission->{selfenrolladmin}) {
1.398 raeburn 6324: push(@{$brcrum},
6325: {href => '/adm/createuser?action=selfenroll',
6326: text => "Configure Self-enrollment",
6327: help => 'Course_Self_Enrollment'});
6328: if (!exists($env{'form.state'})) {
6329: $args = { bread_crumbs => $brcrum,
6330: bread_crumbs_component => 'Configure Self-enrollment'};
6331: $r->print(&header(undef,$args));
6332: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
6333: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
6334: } elsif ($env{'form.state'} eq 'done') {
6335: push (@{$brcrum},
6336: {href=>'/adm/createuser?action=selfenroll',
6337: text=>"Result"});
6338: $args = { bread_crumbs => $brcrum,
6339: bread_crumbs_component => 'Self-enrollment result'};
6340: $r->print(&header(undef,$args));
6341: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 6342: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 6343: }
1.469 raeburn 6344: } elsif ($permission->{selfenrollview}) {
6345: push(@{$brcrum},
6346: {href => '/adm/createuser?action=selfenroll',
6347: text => "View Self-enrollment configuration",
6348: help => 'Course_Self_Enrollment'});
6349: $args = { bread_crumbs => $brcrum,
6350: bread_crumbs_component => 'Self-enrollment Settings'};
6351: $r->print(&header(undef,$args));
6352: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
6353: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings,'',1);
1.398 raeburn 6354: } else {
6355: $r->print(&header(undef,{'no_nav_bar' => 1}).
6356: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 6357: }
1.277 raeburn 6358: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 6359: if ($permission->{selfenrolladmin}) {
1.351 raeburn 6360: push(@{$brcrum},
6361: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 6362: text => 'Enrollment requests',
1.439 raeburn 6363: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 6364: $bread_crumbs_component = 'Enrollment requests';
6365: if ($env{'form.state'} eq 'done') {
6366: push(@{$brcrum},
6367: {href => '/adm/createuser?action=selfenrollqueue',
6368: text => 'Result',
1.439 raeburn 6369: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 6370: $bread_crumbs_component = 'Enrollment result';
6371: }
6372: $args = { bread_crumbs => $brcrum,
6373: bread_crumbs_component => $bread_crumbs_component};
6374: $r->print(&header(undef,$args));
6375: my $coursedesc = $env{'course.'.$cid.'.description'};
6376: if (!exists($env{'form.state'})) {
6377: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
6378: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
6379: $cdom,$cnum));
6380: } elsif ($env{'form.state'} eq 'done') {
6381: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
6382: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 6383: $cdom,$cnum,$coursedesc));
1.418 raeburn 6384: }
6385: } else {
6386: $r->print(&header(undef,{'no_nav_bar' => 1}).
6387: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 6388: }
1.418 raeburn 6389: } elsif ($env{'form.action'} eq 'changelogs') {
6390: if ($permission->{cusr} || $permission->{view}) {
6391: &print_userchangelogs_display($r,$context,$permission,$brcrum);
6392: } else {
6393: $r->print(&header(undef,{'no_nav_bar' => 1}).
6394: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 6395: }
1.428 raeburn 6396: } elsif ($env{'form.action'} eq 'helpdesk') {
1.464 raeburn 6397: if (($permission->{'owner'} || $permission->{'co-owner'}) &&
6398: ($permission->{'cusr'} || $permission->{'view'})) {
1.428 raeburn 6399: if ($env{'form.state'} eq 'process') {
6400: if ($permission->{'owner'}) {
6401: &update_helpdeskaccess($r,$permission,$brcrum);
6402: } else {
6403: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 6404: }
1.428 raeburn 6405: } else {
6406: &print_helpdeskaccess_display($r,$permission,$brcrum);
6407: }
6408: } else {
6409: $r->print(&header(undef,{'no_nav_bar' => 1}).
6410: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
6411: }
1.465 raeburn 6412: } elsif ($env{'form.action'} eq 'rolerequests') {
6413: if ($permission->{cusr} || $permission->{view}) {
6414: &print_queued_roles($r,$context,$permission,$brcrum);
6415: }
6416: } elsif ($env{'form.action'} eq 'queuedroles') {
6417: if (($permission->{cusr}) && ($context eq 'domain')) {
6418: if (&show_role_requests($context,$env{'request.role.domain'})) {
6419: if ($env{'form.state'} eq 'done') {
6420: &process_pendingroles($r,$context,$permission,$brcrum);
6421: } else {
6422: &print_pendingroles($r,$context,$permission,$brcrum);
6423: }
6424: } else {
6425: $r->print(&header(undef,{'no_nav_bar' => 1}).
6426: '<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>');
6427: }
6428: } else {
6429: $r->print(&header(undef,{'no_nav_bar' => 1}).
6430: '<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>');
6431: }
1.470 raeburn 6432: } elsif ($env{'form.action'} eq 'camanagers') {
6433: if (($permission->{cusr}) && ($context eq 'author')) {
6434: push(@{$brcrum},
6435: {href => '/adm/createuser?action=camanagers',
1.473 raeburn 6436: text => 'Co-author Managers',
1.470 raeburn 6437: help => 'Author_Manage_Coauthors'});
6438: if ($env{'form.state'} eq 'process') {
6439: push(@{$brcrum},
6440: {href => '/adm/createuser?action=camanagers',
6441: text => 'Result',
6442: help => 'Author_Manage_Coauthors'});
6443: }
6444: $args = { bread_crumbs => $brcrum };
6445: $r->print(&header(undef,$args));
6446: my $coursedesc = $env{'course.'.$cid.'.description'};
6447: if (!exists($env{'form.state'})) {
6448: $r->print('<h3>'.&mt('Co-author Management').'</h3>'."\n".
6449: &display_coauthor_managers($permission));
6450: } elsif ($env{'form.state'} eq 'process') {
6451: $r->print('<h3>'.&mt('Co-author Management Update Result').'</h3>'."\n".
6452: &update_coauthor_managers($permission));
6453: }
6454: }
6455: } elsif (($env{'form.action'} eq 'calist') && ($context eq 'author')) {
6456: if ($permission->{'cusr'}) {
6457: my ($role,$audom,$auname,$canview,$canedit) =
6458: &Apache::lonviewcoauthors::get_allowable();
6459: if (($canedit) && ($env{'form.forceedit'})) {
6460: &Apache::lonviewcoauthors::get_editor_crumbs($brcrum,'/adm/createuser');
6461: my $args = { 'bread_crumbs' => $brcrum };
6462: $r->print(&Apache::loncommon::start_page('Configure co-author listing',undef,
6463: $args).
6464: &Apache::lonviewcoauthors::edit_settings($audom,$auname,$role,
6465: '/adm/createuser'));
6466: } else {
6467: push(@{$brcrum},
6468: {href => '/adm/createuser?action=calist',
6469: text => 'Coauthor-viewable list',
6470: help => 'Author_List_Coauthors'});
6471: my $args = { 'bread_crumbs' => $brcrum };
6472: $r->print(&Apache::loncommon::start_page('Coauthor-viewable list',undef,
6473: $args));
6474: my %viewsettings =
6475: &Apache::lonviewcoauthors::retrieve_view_settings($auname,$audom,$role);
6476: if ($viewsettings{'show'} eq 'none') {
6477: $r->print('<h3>'.&mt('Coauthor-viewable listing').'</h3>'.
6478: '<p class="LC_info">'.
6479: &mt('Listing of co-authors not enabled for this Authoring Space').
6480: '</p>');
6481: } else {
6482: &Apache::lonviewcoauthors::print_coauthors($r,$auname,$audom,$role,
6483: '/adm/createuser',\%viewsettings);
6484: }
6485: }
6486: } else {
6487: $r->internal_redirect('/adm/viewcoauthors');
6488: return OK;
6489: }
1.481 ! raeburn 6490: } elsif (($env{'form.action'} eq 'setenv') && ($context eq 'author')) {
! 6491: my ($role,$audom,$auname,$canview,$canedit) =
! 6492: &Apache::lonviewcoauthors::get_allowable();
! 6493: push(@{$brcrum},
! 6494: {href => '/adm/createuser?action=calist',
! 6495: text => 'Coauthor-viewable list',
! 6496: help => 'Author_List_Coauthors'});
! 6497: my $args = { 'bread_crumbs' => $brcrum };
! 6498: $r->print(&Apache::loncommon::start_page('Coauthor-viewable list',undef,
! 6499: $args));
! 6500: my %viewsettings =
! 6501: &Apache::lonviewcoauthors::retrieve_view_settings($auname,$audom,$role);
! 6502: if ($viewsettings{'show'} eq 'none') {
! 6503: $r->print('<h3>'.&mt('Coauthor-viewable listing').'</h3>'.
! 6504: '<p class="LC_info">'.
! 6505: &mt('Listing of co-authors not enabled for this Authoring Space').
! 6506: '</p>');
! 6507: } else {
! 6508: &Apache::lonviewcoauthors::print_coauthors($r,$auname,$audom,$role,
! 6509: '/adm/createuser',\%viewsettings);
! 6510: }
1.190 raeburn 6511: } else {
1.351 raeburn 6512: $bread_crumbs_component = 'User Management';
6513: $args = { bread_crumbs => $brcrum,
6514: bread_crumbs_component => $bread_crumbs_component};
6515: $r->print(&header(undef,$args));
1.318 raeburn 6516: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 6517: }
1.351 raeburn 6518: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 6519: return OK;
6520: }
6521:
6522: sub header {
1.351 raeburn 6523: my ($jscript,$args) = @_;
1.190 raeburn 6524: my $start_page;
1.351 raeburn 6525: if (ref($args) eq 'HASH') {
6526: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 6527: } else {
1.351 raeburn 6528: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 6529: }
6530: return $start_page;
6531: }
1.2 www 6532:
1.191 raeburn 6533: sub add_script {
6534: my ($js) = @_;
1.301 bisitz 6535: return '<script type="text/javascript">'."\n"
6536: .'// <![CDATA['."\n"
6537: .$js."\n"
6538: .'// ]]>'."\n"
6539: .'</script>'."\n";
1.191 raeburn 6540: }
6541:
1.391 raeburn 6542: sub usernamerequest_javascript {
6543: my $js = <<ENDJS;
6544:
6545: function openusernamereqdisplay(dom,uname,queue) {
6546: var url = '/adm/createuser?action=displayuserreq';
6547: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
6548: var title = 'Account_Request_Browser';
6549: var options = 'scrollbars=1,resizable=1,menubar=0';
6550: options += ',width=700,height=600';
6551: var stdeditbrowser = open(url,title,options,'1');
6552: stdeditbrowser.focus();
6553: return;
6554: }
6555:
6556: ENDJS
6557: }
6558:
6559: sub close_popup_form {
6560: my $close= &mt('Close Window');
6561: return << "END";
6562: <p><form name="displayreq" action="" method="post">
6563: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
6564: </form></p>
6565: END
6566: }
6567:
1.202 raeburn 6568: sub verify_user_display {
1.364 raeburn 6569: my ($context) = @_;
1.374 raeburn 6570: my %lt = &Apache::lonlocal::texthash (
6571: course => 'course(s): description, section(s), status',
6572: community => 'community(s): description, section(s), status',
6573: author => 'author',
6574: );
1.364 raeburn 6575: my $photos;
6576: if (($context eq 'course') && $env{'request.course.id'}) {
6577: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
6578: }
1.202 raeburn 6579: my $output = <<"END";
6580:
1.364 raeburn 6581: function hide_searching() {
6582: if (document.getElementById('searching')) {
6583: document.getElementById('searching').style.display = 'none';
6584: }
6585: return;
6586: }
6587:
1.202 raeburn 6588: function display_update() {
6589: document.studentform.action.value = 'listusers';
6590: document.studentform.phase.value = 'display';
6591: document.studentform.submit();
6592: }
6593:
1.364 raeburn 6594: function updateCols(caller) {
6595: var context = '$context';
6596: var photos = '$photos';
6597: if (caller == 'Status') {
1.374 raeburn 6598: if ((context == 'domain') &&
6599: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
6600: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 6601: document.getElementById('showcolstatus').checked = false;
6602: document.getElementById('showcolstatus').disabled = 'disabled';
6603: document.getElementById('showcolstart').checked = false;
6604: document.getElementById('showcolend').checked = false;
1.374 raeburn 6605: } else {
6606: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
6607: document.getElementById('showcolstatus').checked = true;
6608: document.getElementById('showcolstatus').disabled = '';
6609: document.getElementById('showcolstart').checked = true;
6610: document.getElementById('showcolend').checked = true;
6611: } else {
6612: document.getElementById('showcolstatus').checked = false;
6613: document.getElementById('showcolstatus').disabled = 'disabled';
6614: document.getElementById('showcolstart').checked = false;
6615: document.getElementById('showcolend').checked = false;
6616: }
1.472 raeburn 6617: if (context == 'author') {
6618: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Expired') {
6619: document.getElementById('showcolmanager').checked = false;
6620: document.getElementById('showcolmanager').disabled = 'disabled';
6621: } else if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value != 'aa') {
6622: document.getElementById('showcolmanager').checked = true;
6623: document.getElementById('showcolmanager').disabled = '';
6624: }
6625: }
1.364 raeburn 6626: }
6627: }
6628: if (caller == 'output') {
6629: if (photos == 1) {
6630: if (document.getElementById('showcolphoto')) {
6631: var photoitem = document.getElementById('showcolphoto');
6632: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
6633: photoitem.checked = true;
6634: photoitem.disabled = '';
6635: } else {
6636: photoitem.checked = false;
6637: photoitem.disabled = 'disabled';
6638: }
6639: }
6640: }
6641: }
6642: if (caller == 'showrole') {
1.371 raeburn 6643: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
6644: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 6645: document.getElementById('showcolrole').checked = true;
6646: document.getElementById('showcolrole').disabled = '';
6647: } else {
6648: document.getElementById('showcolrole').checked = false;
6649: document.getElementById('showcolrole').disabled = 'disabled';
6650: }
1.374 raeburn 6651: if (context == 'domain') {
1.382 raeburn 6652: var quotausageshow = 0;
1.374 raeburn 6653: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
6654: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
6655: document.getElementById('showcolstatus').checked = false;
6656: document.getElementById('showcolstatus').disabled = 'disabled';
6657: document.getElementById('showcolstart').checked = false;
6658: document.getElementById('showcolend').checked = false;
6659: } else {
6660: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
6661: document.getElementById('showcolstatus').checked = true;
6662: document.getElementById('showcolstatus').disabled = '';
6663: document.getElementById('showcolstart').checked = true;
6664: document.getElementById('showcolend').checked = true;
6665: }
6666: }
6667: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
6668: document.getElementById('showcolextent').disabled = 'disabled';
6669: document.getElementById('showcolextent').checked = 'false';
6670: document.getElementById('showextent').style.display='none';
6671: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 6672: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
6673: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
6674: if (document.getElementById('showcolauthorusage')) {
6675: document.getElementById('showcolauthorusage').disabled = '';
6676: }
6677: if (document.getElementById('showcolauthorquota')) {
6678: document.getElementById('showcolauthorquota').disabled = '';
6679: }
6680: quotausageshow = 1;
6681: }
1.374 raeburn 6682: } else {
6683: document.getElementById('showextent').style.display='block';
6684: document.getElementById('showextent').style.textAlign='left';
6685: document.getElementById('showextent').style.textFace='normal';
6686: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
6687: document.getElementById('showcolextent').disabled = '';
6688: document.getElementById('showcolextent').checked = 'true';
6689: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
6690: } else {
6691: document.getElementById('showcolextent').disabled = '';
6692: document.getElementById('showcolextent').checked = 'true';
6693: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
6694: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
6695: } else {
6696: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
6697: }
6698: }
6699: }
1.382 raeburn 6700: if (quotausageshow == 0) {
6701: if (document.getElementById('showcolauthorusage')) {
6702: document.getElementById('showcolauthorusage').checked = false;
6703: document.getElementById('showcolauthorusage').disabled = 'disabled';
6704: }
6705: if (document.getElementById('showcolauthorquota')) {
6706: document.getElementById('showcolauthorquota').checked = false;
6707: document.getElementById('showcolauthorquota').disabled = 'disabled';
6708: }
6709: }
1.374 raeburn 6710: }
1.472 raeburn 6711: if (context == 'author') {
6712: if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'aa') {
6713: document.getElementById('showcolmanager').checked = false;
6714: document.getElementById('showcolmanager').disabled = 'disabled';
6715: } else if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value != 'Expired') {
6716: document.getElementById('showcolmanager').checked = true;
6717: document.getElementById('showcolmanager').disabled = '';
6718: }
6719: }
1.364 raeburn 6720: }
6721: return;
6722: }
6723:
1.202 raeburn 6724: END
6725: return $output;
6726:
6727: }
6728:
1.190 raeburn 6729: ###############################################################
6730: ###############################################################
6731: # Menu Phase One
6732: sub print_main_menu {
1.318 raeburn 6733: my ($permission,$context,$crstype) = @_;
6734: my $linkcontext = $context;
6735: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
6736: if (($context eq 'course') && ($crstype eq 'Community')) {
6737: $linkcontext = lc($crstype);
6738: $stuterm = 'Members';
6739: }
1.208 raeburn 6740: my %links = (
1.298 droeschl 6741: domain => {
6742: upload => 'Upload a File of Users',
6743: singleuser => 'Add/Modify a User',
6744: listusers => 'Manage Users',
6745: },
6746: author => {
6747: upload => 'Upload a File of Co-authors',
6748: singleuser => 'Add/Modify a Co-author',
6749: listusers => 'Manage Co-authors',
6750: },
6751: course => {
6752: upload => 'Upload a File of Course Users',
6753: singleuser => 'Add/Modify a Course User',
1.354 www 6754: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 6755: },
1.318 raeburn 6756: community => {
6757: upload => 'Upload a File of Community Users',
6758: singleuser => 'Add/Modify a Community User',
1.354 www 6759: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 6760: },
6761: );
6762: my %linktitles = (
6763: domain => {
6764: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
6765: listusers => 'Show and manage users in this domain.',
6766: },
6767: author => {
6768: singleuser => 'Add a user with a co- or assistant author role.',
6769: listusers => 'Show and manage co- or assistant authors.',
6770: },
6771: course => {
6772: singleuser => 'Add a user with a certain role to this course.',
6773: listusers => 'Show and manage users in this course.',
6774: },
6775: community => {
6776: singleuser => 'Add a user with a certain role to this community.',
6777: listusers => 'Show and manage users in this community.',
6778: },
1.298 droeschl 6779: );
1.465 raeburn 6780:
1.418 raeburn 6781: if ($linkcontext eq 'domain') {
6782: unless ($permission->{'cusr'}) {
1.430 raeburn 6783: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 6784: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
6785: }
6786: } elsif ($linkcontext eq 'course') {
6787: unless ($permission->{'cusr'}) {
6788: $links{'course'}{'singleuser'} = 'View a Course User';
6789: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
6790: $links{'course'}{'listusers'} = 'List Course Users';
6791: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
6792: }
6793: } elsif ($linkcontext eq 'community') {
6794: unless ($permission->{'cusr'}) {
6795: $links{'community'}{'singleuser'} = 'View a Community User';
6796: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
6797: $links{'community'}{'listusers'} = 'List Community Users';
6798: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
6799: }
6800: }
1.298 droeschl 6801: my @menu = ( {categorytitle => 'Single Users',
6802: items =>
6803: [
6804: {
1.318 raeburn 6805: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 6806: icon => 'edit-redo.png',
6807: #help => 'Course_Change_Privileges',
6808: url => '/adm/createuser?action=singleuser',
1.418 raeburn 6809: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 6810: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 6811: },
6812: ]},
6813:
6814: {categorytitle => 'Multiple Users',
6815: items =>
6816: [
6817: {
1.318 raeburn 6818: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 6819: icon => 'uplusr.png',
1.298 droeschl 6820: #help => 'Course_Create_Class_List',
6821: url => '/adm/createuser?action=upload',
6822: permission => $permission->{'cusr'},
6823: linktitle => 'Upload a CSV or a text file containing users.',
6824: },
6825: {
1.318 raeburn 6826: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 6827: icon => 'mngcu.png',
1.298 droeschl 6828: #help => 'Course_View_Class_List',
6829: url => '/adm/createuser?action=listusers',
6830: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 6831: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 6832: },
6833:
6834: ]},
6835:
6836: {categorytitle => 'Administration',
6837: items => [ ]},
6838: );
1.415 raeburn 6839:
1.265 mielkec 6840: if ($context eq 'domain'){
1.416 raeburn 6841: push(@{ $menu[0]->{items} }, # Single Users
6842: {
6843: linktext => 'User Access Log',
1.417 raeburn 6844: icon => 'document-properties.png',
1.425 raeburn 6845: #help => 'Domain_User_Access_Logs',
1.416 raeburn 6846: url => '/adm/createuser?action=accesslogs',
6847: permission => $permission->{'activity'},
6848: linktitle => 'View user access log.',
6849: }
6850: );
1.298 droeschl 6851:
6852: push(@{ $menu[2]->{items} }, #Category: Administration
6853: {
6854: linktext => 'Custom Roles',
6855: icon => 'emblem-photos.png',
6856: #help => 'Course_Editing_Custom_Roles',
6857: url => '/adm/createuser?action=custom',
6858: permission => $permission->{'custom'},
6859: linktitle => 'Configure a custom role.',
6860: },
1.362 raeburn 6861: {
6862: linktext => 'Authoring Space Requests',
6863: icon => 'selfenrl-queue.png',
6864: #help => 'Domain_Role_Approvals',
6865: url => '/adm/createuser?action=processauthorreq',
6866: permission => $permission->{'cusr'},
6867: linktitle => 'Approve or reject author role requests',
6868: },
1.363 raeburn 6869: {
1.391 raeburn 6870: linktext => 'LON-CAPA Account Requests',
6871: icon => 'list-add.png',
6872: #help => 'Domain_Username_Approvals',
6873: url => '/adm/createuser?action=processusernamereq',
6874: permission => $permission->{'cusr'},
6875: linktitle => 'Approve or reject LON-CAPA account requests',
6876: },
6877: {
1.363 raeburn 6878: linktext => 'Change Log',
6879: icon => 'document-properties.png',
6880: #help => 'Course_User_Logs',
6881: url => '/adm/createuser?action=changelogs',
1.418 raeburn 6882: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 6883: linktitle => 'View change log.',
6884: },
1.298 droeschl 6885: );
6886:
1.265 mielkec 6887: }elsif ($context eq 'course'){
1.298 droeschl 6888: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 6889:
6890: my %linktext = (
6891: 'Course' => {
6892: single => 'Add/Modify a Student',
6893: drop => 'Drop Students',
6894: groups => 'Course Groups',
6895: },
6896: 'Community' => {
6897: single => 'Add/Modify a Member',
6898: drop => 'Drop Members',
6899: groups => 'Community Groups',
6900: },
6901: );
1.411 raeburn 6902: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 6903:
6904: my %linktitle = (
6905: 'Course' => {
6906: single => 'Add a user with the role of student to this course',
6907: drop => 'Remove a student from this course.',
6908: groups => 'Manage course groups',
6909: },
6910: 'Community' => {
6911: single => 'Add a user with the role of member to this community',
6912: drop => 'Remove a member from this community.',
6913: groups => 'Manage community groups',
6914: },
6915: );
6916:
1.411 raeburn 6917: $linktitle{'Placement'} = $linktitle{'Course'};
6918:
1.298 droeschl 6919: push(@{ $menu[0]->{items} }, #Category: Single Users
6920: {
1.318 raeburn 6921: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 6922: #help => 'Course_Add_Student',
6923: icon => 'list-add.png',
6924: url => '/adm/createuser?action=singlestudent',
6925: permission => $permission->{'cusr'},
1.318 raeburn 6926: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 6927: },
6928: );
6929:
6930: push(@{ $menu[1]->{items} }, #Category: Multiple Users
6931: {
1.318 raeburn 6932: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 6933: icon => 'edit-undo.png',
6934: #help => 'Course_Drop_Student',
6935: url => '/adm/createuser?action=drop',
6936: permission => $permission->{'cusr'},
1.318 raeburn 6937: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 6938: },
6939: );
6940: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 6941: {
6942: linktext => 'Helpdesk Access',
6943: icon => 'helpdesk-access.png',
6944: #help => 'Course_Helpdesk_Access',
6945: url => '/adm/createuser?action=helpdesk',
1.464 raeburn 6946: permission => (($permission->{'owner'} || $permission->{'co-owner'}) &&
6947: ($permission->{'view'} || $permission->{'cusr'})),
1.428 raeburn 6948: linktitle => 'Helpdesk access options',
6949: },
6950: {
1.298 droeschl 6951: linktext => 'Custom Roles',
6952: icon => 'emblem-photos.png',
6953: #help => 'Course_Editing_Custom_Roles',
6954: url => '/adm/createuser?action=custom',
6955: permission => $permission->{'custom'},
6956: linktitle => 'Configure a custom role.',
6957: },
6958: {
1.318 raeburn 6959: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 6960: icon => 'grps.png',
1.298 droeschl 6961: #help => 'Course_Manage_Group',
6962: url => '/adm/coursegroups?refpage=cusr',
6963: permission => $permission->{'grp_manage'},
1.318 raeburn 6964: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 6965: },
6966: {
1.328 wenzelju 6967: linktext => 'Change Log',
1.298 droeschl 6968: icon => 'document-properties.png',
6969: #help => 'Course_User_Logs',
6970: url => '/adm/createuser?action=changelogs',
1.418 raeburn 6971: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 6972: linktitle => 'View change log.',
6973: },
6974: );
1.277 raeburn 6975: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 6976: push(@{ $menu[2]->{items} },
1.398 raeburn 6977: {
1.298 droeschl 6978: linktext => 'Enrollment Requests',
6979: icon => 'selfenrl-queue.png',
6980: #help => 'Course_Approve_Selfenroll',
6981: url => '/adm/createuser?action=selfenrollqueue',
1.469 raeburn 6982: permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.298 droeschl 6983: linktitle =>'Approve or reject enrollment requests.',
6984: },
6985: );
1.277 raeburn 6986: }
1.298 droeschl 6987:
1.265 mielkec 6988: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 6989: if ($crstype ne 'Community') {
6990: push(@{ $menu[2]->{items} },
6991: {
6992: linktext => 'Automated Enrollment',
6993: icon => 'roles.png',
6994: #help => 'Course_Automated_Enrollment',
6995: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 6996: && (($permission->{'cusr'}) ||
6997: ($permission->{'view'}))),
1.320 raeburn 6998: url => '/adm/populate',
6999: linktitle => 'Automated enrollment manager.',
7000: }
7001: );
7002: }
7003: push(@{ $menu[2]->{items} },
1.298 droeschl 7004: {
7005: linktext => 'User Self-Enrollment',
1.342 wenzelju 7006: icon => 'self_enroll.png',
1.298 droeschl 7007: #help => 'Course_Self_Enrollment',
7008: url => '/adm/createuser?action=selfenroll',
1.469 raeburn 7009: permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.317 bisitz 7010: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 7011: },
7012: );
7013: }
1.363 raeburn 7014: } elsif ($context eq 'author') {
1.481 ! raeburn 7015: my $coauthorlist;
! 7016: if ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)$}) {
! 7017: if ($env{'environment.internal.coauthorlist./'.$1.'/'.$2}) {
! 7018: $coauthorlist = 1;
! 7019: }
! 7020: } elsif ($env{'request.role'} eq "au./$env{'user.domain'}/") {
! 7021: if ($env{'environment.coauthorlist'}) {
! 7022: $coauthorlist = 1;
! 7023: }
! 7024: }
! 7025: if ($coauthorlist) {
! 7026: push(@{ $menu[1]->{items} },
! 7027: {
! 7028: linktext => 'Co-author-viewable list',
! 7029: icon => 'clst.png',
! 7030: #help => 'Coauthor_Listing',
! 7031: url => '/adm/createuser?action=calist&forceedit=0',
! 7032: permission => $permission->{'cusr'},
! 7033: linktitle => 'Co-author-viewable listing',
! 7034: });
! 7035: }
1.370 raeburn 7036: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 7037: {
7038: linktext => 'Change Log',
7039: icon => 'document-properties.png',
7040: #help => 'Course_User_Logs',
7041: url => '/adm/createuser?action=changelogs',
7042: permission => $permission->{'cusr'},
7043: linktitle => 'View change log.',
7044: },
1.470 raeburn 7045: {
1.472 raeburn 7046: linktext => 'Co-author Managers',
1.473 raeburn 7047: icon => 'camanager.png',
1.470 raeburn 7048: #help => 'Coauthor_Management',
7049: url => '/adm/createuser?action=camanagers',
7050: permission => $permission->{'author'},
7051: linktitle => 'Assign/Revoke right to manage co-author roles',
7052: },
7053: {
1.473 raeburn 7054: linktext => 'Configure Co-author Listing',
7055: icon => 'coauthors.png',
1.470 raeburn 7056: #help => 'Coauthor_Settings',
7057: url => '/adm/createuser?action=calist&forceedit=1',
7058: permission => ($permission->{'cusr'}),
7059: linktitle => 'Set availability of coauthor-viewable user listing',
7060: },
1.370 raeburn 7061: );
1.363 raeburn 7062: }
1.465 raeburn 7063: push(@{ $menu[2]->{items} },
7064: {
7065: linktext => 'Role Requests (other domains)',
7066: icon => 'edit-find.png',
7067: #help => 'Role_Requests',
7068: url => '/adm/createuser?action=rolerequests',
7069: permission => $permission->{'cusr'},
7070: linktitle => 'Role requests for users in other domains',
7071: },
7072: );
7073: if (&show_role_requests($context,$env{'request.role.domain'})) {
7074: push(@{ $menu[2]->{items} },
7075: {
7076: linktext => 'Queued Role Assignments (this domain)',
7077: icon => 'edit-find.png',
7078: #help => 'Role_Approvals',
7079: url => '/adm/createuser?action=queuedroles',
7080: permission => $permission->{'cusr'},
7081: linktitle => "Role requests for this domain's users",
7082: },
7083: );
7084: }
1.363 raeburn 7085: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 7086: # { text => 'View Log-in History',
7087: # help => 'Course_User_Logins',
7088: # action => 'logins',
7089: # permission => $permission->{'cusr'},
7090: # });
1.190 raeburn 7091: }
7092:
1.189 albertel 7093: sub restore_prev_selections {
7094: my %saveable_parameters = ('srchby' => 'scalar',
7095: 'srchin' => 'scalar',
7096: 'srchtype' => 'scalar',
7097: );
7098: &Apache::loncommon::store_settings('user','user_picker',
7099: \%saveable_parameters);
7100: &Apache::loncommon::restore_settings('user','user_picker',
7101: \%saveable_parameters);
7102: }
7103:
1.237 raeburn 7104: sub print_selfenroll_menu {
1.418 raeburn 7105: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 7106: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 7107: my $formname = 'selfenroll';
1.237 raeburn 7108: my $nolink = 1;
1.398 raeburn 7109: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 7110: my $groupslist = &Apache::lonuserutils::get_groupslist();
7111: my $setsec_js =
7112: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 7113: my %alerts = &Apache::lonlocal::texthash(
7114: acto => 'Activation of self-enrollment was selected for the following domain(s)',
7115: butn => 'but no user types have been checked.',
7116: wilf => "Please uncheck 'activate' or check at least one type.",
7117: );
1.418 raeburn 7118: my $disabled;
7119: if ($readonly) {
7120: $disabled = ' disabled="disabled"';
7121: }
1.405 damieng 7122: &js_escape(\%alerts);
1.249 raeburn 7123: my $selfenroll_js = <<"ENDSCRIPT";
7124: function update_types(caller,num) {
7125: var delidx = getIndexByName('selfenroll_delete');
7126: var actidx = getIndexByName('selfenroll_activate');
7127: if (caller == 'selfenroll_all') {
7128: var selall;
7129: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
7130: if (document.$formname.selfenroll_all[i].checked) {
7131: selall = document.$formname.selfenroll_all[i].value;
7132: }
7133: }
7134: if (selall == 1) {
7135: if (delidx != -1) {
7136: if (document.$formname.selfenroll_delete.length) {
7137: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
7138: document.$formname.selfenroll_delete[j].checked = true;
7139: }
7140: } else {
7141: document.$formname.elements[delidx].checked = true;
7142: }
7143: }
7144: if (actidx != -1) {
7145: if (document.$formname.selfenroll_activate.length) {
7146: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
7147: document.$formname.selfenroll_activate[j].checked = false;
7148: }
7149: } else {
7150: document.$formname.elements[actidx].checked = false;
7151: }
7152: }
7153: document.$formname.selfenroll_newdom.selectedIndex = 0;
7154: }
7155: }
7156: if (caller == 'selfenroll_activate') {
7157: if (document.$formname.selfenroll_activate.length) {
7158: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
7159: if (document.$formname.selfenroll_activate[j].value == num) {
7160: if (document.$formname.selfenroll_activate[j].checked) {
7161: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
7162: if (document.$formname.selfenroll_all[i].value == '1') {
7163: document.$formname.selfenroll_all[i].checked = false;
7164: }
7165: if (document.$formname.selfenroll_all[i].value == '0') {
7166: document.$formname.selfenroll_all[i].checked = true;
7167: }
7168: }
7169: }
7170: }
7171: }
7172: } else {
7173: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
7174: if (document.$formname.selfenroll_all[i].value == '1') {
7175: document.$formname.selfenroll_all[i].checked = false;
7176: }
7177: if (document.$formname.selfenroll_all[i].value == '0') {
7178: document.$formname.selfenroll_all[i].checked = true;
7179: }
7180: }
7181: }
7182: }
7183: if (caller == 'selfenroll_delete') {
7184: if (document.$formname.selfenroll_delete.length) {
7185: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
7186: if (document.$formname.selfenroll_delete[j].value == num) {
7187: if (document.$formname.selfenroll_delete[j].checked) {
7188: var delindex = getIndexByName('selfenroll_types_'+num);
7189: if (delindex != -1) {
7190: if (document.$formname.elements[delindex].length) {
7191: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
7192: document.$formname.elements[delindex][k].checked = false;
7193: }
7194: } else {
7195: document.$formname.elements[delindex].checked = false;
7196: }
7197: }
7198: }
7199: }
7200: }
7201: } else {
7202: if (document.$formname.selfenroll_delete.checked) {
7203: var delindex = getIndexByName('selfenroll_types_'+num);
7204: if (delindex != -1) {
7205: if (document.$formname.elements[delindex].length) {
7206: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
7207: document.$formname.elements[delindex][k].checked = false;
7208: }
7209: } else {
7210: document.$formname.elements[delindex].checked = false;
7211: }
7212: }
7213: }
7214: }
7215: }
7216: return;
7217: }
7218:
7219: function validate_types(form) {
7220: var needaction = new Array();
7221: var countfail = 0;
7222: var actidx = getIndexByName('selfenroll_activate');
7223: if (actidx != -1) {
7224: if (document.$formname.selfenroll_activate.length) {
7225: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
7226: var num = document.$formname.selfenroll_activate[j].value;
7227: if (document.$formname.selfenroll_activate[j].checked) {
7228: countfail = check_types(num,countfail,needaction)
7229: }
7230: }
7231: } else {
7232: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 7233: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 7234: countfail = check_types(num,countfail,needaction)
7235: }
7236: }
7237: }
7238: if (countfail > 0) {
7239: var msg = "$alerts{'acto'}\\n";
7240: var loopend = needaction.length -1;
7241: if (loopend > 0) {
7242: for (var m=0; m<loopend; m++) {
7243: msg += needaction[m]+", ";
7244: }
7245: }
7246: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
7247: alert(msg);
7248: return;
7249: }
7250: setSections(form);
7251: }
7252:
7253: function check_types(num,countfail,needaction) {
1.441 raeburn 7254: var boxname = 'selfenroll_types_'+num;
7255: var typeidx = getIndexByName(boxname);
1.249 raeburn 7256: var count = 0;
7257: if (typeidx != -1) {
1.441 raeburn 7258: if (document.$formname.elements[boxname].length) {
7259: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
7260: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 7261: count ++;
7262: }
7263: }
7264: } else {
7265: if (document.$formname.elements[typeidx].checked) {
7266: count ++;
7267: }
7268: }
7269: if (count == 0) {
7270: var domidx = getIndexByName('selfenroll_dom_'+num);
7271: if (domidx != -1) {
7272: var domname = document.$formname.elements[domidx].value;
7273: needaction[countfail] = domname;
7274: countfail ++;
7275: }
7276: }
7277: }
7278: return countfail;
7279: }
7280:
1.398 raeburn 7281: function toggleNotify() {
7282: var selfenrollApproval = 0;
7283: if (document.$formname.selfenroll_approval.length) {
7284: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
7285: if (document.$formname.selfenroll_approval[i].checked) {
7286: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
7287: break;
7288: }
7289: }
7290: }
7291: if (document.getElementById('notified')) {
7292: if (selfenrollApproval == 0) {
7293: document.getElementById('notified').style.display='none';
7294: } else {
7295: document.getElementById('notified').style.display='block';
7296: }
7297: }
7298: return;
7299: }
7300:
1.249 raeburn 7301: function getIndexByName(item) {
7302: for (var i=0;i<document.$formname.elements.length;i++) {
7303: if (document.$formname.elements[i].name == item) {
7304: return i;
7305: }
7306: }
7307: return -1;
7308: }
7309: ENDSCRIPT
1.256 raeburn 7310:
1.237 raeburn 7311: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 7312: '// <![CDATA['."\n".
1.249 raeburn 7313: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 7314: '// ]]>'."\n".
1.237 raeburn 7315: '</script>'."\n".
1.256 raeburn 7316: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.469 raeburn 7317: my $visactions = &cat_visibility($cdom);
1.400 raeburn 7318: my ($cathash,%cattype);
7319: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
7320: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7321: $cathash = $domconfig{'coursecategories'}{'cats'};
7322: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
7323: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 7324: if ($cattype{'auth'} eq '') {
7325: $cattype{'auth'} = 'std';
7326: }
7327: if ($cattype{'unauth'} eq '') {
7328: $cattype{'unauth'} = 'std';
7329: }
1.400 raeburn 7330: } else {
7331: $cathash = {};
7332: $cattype{'auth'} = 'std';
7333: $cattype{'unauth'} = 'std';
7334: }
7335: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
7336: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7337: '<br />'.
7338: '<br />'.$visactions->{'take'}.'<ul>'.
7339: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
7340: '</ul>');
7341: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
7342: if ($currsettings->{'uniquecode'}) {
7343: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
7344: } else {
7345: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7346: '<br />'.
7347: '<br />'.$visactions->{'take'}.'<ul>'.
7348: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
7349: '</ul><br />');
7350: }
7351: } else {
7352: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
7353: if (ref($visactions) eq 'HASH') {
7354: if ($visible) {
7355: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
7356: } else {
7357: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
7358: .$visactions->{'yous'}.
7359: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
7360: if (ref($vismsgs) eq 'ARRAY') {
7361: $output .= '<br />'.$visactions->{'make'}.'<ul>';
7362: foreach my $item (@{$vismsgs}) {
7363: $output .= '<li>'.$visactions->{$item}.'</li>';
7364: }
7365: $output .= '</ul>';
1.256 raeburn 7366: }
1.400 raeburn 7367: $output .= '</p>';
1.256 raeburn 7368: }
7369: }
7370: }
1.398 raeburn 7371: my $actionhref = '/adm/createuser';
7372: if ($context eq 'domain') {
7373: $actionhref = '/adm/modifycourse';
7374: }
1.400 raeburn 7375:
7376: my %noedit;
7377: unless ($context eq 'domain') {
7378: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
7379: }
1.398 raeburn 7380: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 7381: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 7382: if (ref($row) eq 'ARRAY') {
7383: foreach my $item (@{$row}) {
7384: my $title = $item;
7385: if (ref($lt) eq 'HASH') {
7386: $title = $lt->{$item};
7387: }
1.297 bisitz 7388: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 7389: if ($item eq 'types') {
1.398 raeburn 7390: my $curr_types;
7391: if (ref($currsettings) eq 'HASH') {
7392: $curr_types = $currsettings->{'selfenroll_types'};
7393: }
1.400 raeburn 7394: if ($noedit{$item}) {
7395: if ($curr_types eq '*') {
7396: $output .= &mt('Any user in any domain');
7397: } else {
7398: my @entries = split(/;/,$curr_types);
7399: if (@entries > 0) {
7400: $output .= '<ul>';
7401: foreach my $entry (@entries) {
7402: my ($currdom,$typestr) = split(/:/,$entry);
7403: next if ($typestr eq '');
7404: my $domdesc = &Apache::lonnet::domain($currdom);
7405: my @currinsttypes = split(',',$typestr);
7406: my ($othertitle,$usertypes,$types) =
7407: &Apache::loncommon::sorted_inst_types($currdom);
7408: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7409: $usertypes->{'any'} = &mt('any user');
7410: if (keys(%{$usertypes}) > 0) {
7411: $usertypes->{'other'} = &mt('other users');
7412: }
7413: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
7414: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
7415: }
7416: }
7417: $output .= '</ul>';
7418: } else {
7419: $output .= &mt('None');
7420: }
7421: }
7422: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7423: next;
7424: }
1.241 raeburn 7425: my $showdomdesc = 1;
7426: my $includeempty = 1;
7427: my $num = 0;
7428: $output .= &Apache::loncommon::start_data_table().
7429: &Apache::loncommon::start_data_table_row()
7430: .'<td colspan="2"><span class="LC_nobreak"><label>'
7431: .&mt('Any user in any domain:')
7432: .' <input type="radio" name="selfenroll_all" value="1" ';
7433: if ($curr_types eq '*') {
7434: $output .= ' checked="checked" ';
7435: }
1.249 raeburn 7436: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 7437: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 7438: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 7439: if ($curr_types ne '*') {
7440: $output .= ' checked="checked" ';
7441: }
1.249 raeburn 7442: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 7443: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 7444: &Apache::loncommon::end_data_table_row().
7445: &Apache::loncommon::end_data_table().
7446: &mt('Or').'<br />'.
7447: &Apache::loncommon::start_data_table();
1.241 raeburn 7448: my %currdoms;
1.249 raeburn 7449: if ($curr_types eq '') {
1.241 raeburn 7450: $output .= &new_selfenroll_dom_row($cdom,'0');
7451: } elsif ($curr_types ne '*') {
7452: my @entries = split(/;/,$curr_types);
7453: if (@entries > 0) {
7454: foreach my $entry (@entries) {
7455: my ($currdom,$typestr) = split(/:/,$entry);
7456: $currdoms{$currdom} = 1;
7457: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 7458: my @currinsttypes = split(',',$typestr);
1.241 raeburn 7459: $output .= &Apache::loncommon::start_data_table_row()
7460: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
7461: .' '.$domdesc.' ('.$currdom.')'
7462: .'</b><input type="hidden" name="selfenroll_dom_'.$num
7463: .'" value="'.$currdom.'" /></span><br />'
7464: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 7465: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 7466: .&mt('Delete').'</label></span></td>';
1.249 raeburn 7467: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 7468: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 7469: .&Apache::loncommon::end_data_table_row();
7470: $num ++;
7471: }
7472: }
7473: }
1.249 raeburn 7474: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 7475: if ($curr_types eq '*') {
1.249 raeburn 7476: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 7477: } elsif ($curr_types eq '') {
1.249 raeburn 7478: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 7479: }
1.446 raeburn 7480: my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$cdom);
1.241 raeburn 7481: $output .= &Apache::loncommon::start_data_table_row()
7482: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
7483: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.446 raeburn 7484: $includeempty,$showdomdesc,'',$trusted,$untrusted,$readonly)
1.241 raeburn 7485: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
7486: .'</td>'.&Apache::loncommon::end_data_table_row()
7487: .&Apache::loncommon::end_data_table();
1.237 raeburn 7488: } elsif ($item eq 'registered') {
7489: my ($regon,$regoff);
1.398 raeburn 7490: my $registered;
7491: if (ref($currsettings) eq 'HASH') {
7492: $registered = $currsettings->{'selfenroll_registered'};
7493: }
1.400 raeburn 7494: if ($noedit{$item}) {
7495: if ($registered) {
7496: $output .= &mt('Must be registered in course');
7497: } else {
7498: $output .= &mt('No requirement');
7499: }
7500: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7501: next;
7502: }
1.398 raeburn 7503: if ($registered) {
1.237 raeburn 7504: $regon = ' checked="checked" ';
1.419 raeburn 7505: $regoff = '';
1.237 raeburn 7506: } else {
1.419 raeburn 7507: $regon = '';
1.237 raeburn 7508: $regoff = ' checked="checked" ';
7509: }
7510: $output .= '<label>'.
1.419 raeburn 7511: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 7512: &mt('Yes').'</label> <label>'.
1.419 raeburn 7513: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 7514: &mt('No').'</label>';
1.237 raeburn 7515: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 7516: my ($starttime,$endtime);
7517: if (ref($currsettings) eq 'HASH') {
7518: $starttime = $currsettings->{'selfenroll_start_date'};
7519: $endtime = $currsettings->{'selfenroll_end_date'};
7520: if ($starttime eq '') {
7521: $starttime = $currsettings->{'default_enrollment_start_date'};
7522: }
7523: if ($endtime eq '') {
7524: $endtime = $currsettings->{'default_enrollment_end_date'};
7525: }
1.237 raeburn 7526: }
1.400 raeburn 7527: if ($noedit{$item}) {
7528: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
7529: &Apache::lonlocal::locallocaltime($endtime));
7530: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7531: next;
7532: }
1.237 raeburn 7533: my $startform =
7534: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 7535: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7536: my $endform =
7537: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 7538: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7539: $output .= &selfenroll_date_forms($startform,$endform);
7540: } elsif ($item eq 'access_dates') {
1.398 raeburn 7541: my ($starttime,$endtime);
7542: if (ref($currsettings) eq 'HASH') {
7543: $starttime = $currsettings->{'selfenroll_start_access'};
7544: $endtime = $currsettings->{'selfenroll_end_access'};
7545: if ($starttime eq '') {
7546: $starttime = $currsettings->{'default_enrollment_start_date'};
7547: }
7548: if ($endtime eq '') {
7549: $endtime = $currsettings->{'default_enrollment_end_date'};
7550: }
1.237 raeburn 7551: }
1.400 raeburn 7552: if ($noedit{$item}) {
7553: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
7554: &Apache::lonlocal::locallocaltime($endtime));
7555: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7556: next;
7557: }
1.237 raeburn 7558: my $startform =
7559: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 7560: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7561: my $endform =
7562: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 7563: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7564: $output .= &selfenroll_date_forms($startform,$endform);
7565: } elsif ($item eq 'section') {
1.398 raeburn 7566: my $currsec;
7567: if (ref($currsettings) eq 'HASH') {
7568: $currsec = $currsettings->{'selfenroll_section'};
7569: }
1.237 raeburn 7570: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
7571: my $newsecval;
7572: if ($currsec ne 'none' && $currsec ne '') {
7573: if (!defined($sections_count{$currsec})) {
7574: $newsecval = $currsec;
7575: }
7576: }
1.400 raeburn 7577: if ($noedit{$item}) {
7578: if ($currsec ne '') {
7579: $output .= $currsec;
7580: } else {
7581: $output .= &mt('No specific section');
7582: }
7583: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7584: next;
7585: }
1.237 raeburn 7586: my $sections_select =
1.418 raeburn 7587: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 7588: $output .= '<table class="LC_createuser">'."\n".
7589: '<tr class="LC_section_row">'."\n".
7590: '<td align="center">'.&mt('Existing sections')."\n".
7591: '<br />'.$sections_select.'</td><td align="center">'.
7592: &mt('New section').'<br />'."\n".
1.418 raeburn 7593: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 7594: '<input type="hidden" name="sections" value="" />'."\n".
7595: '</td></tr></table>'."\n";
1.276 raeburn 7596: } elsif ($item eq 'approval') {
1.398 raeburn 7597: my ($currnotified,$currapproval,%appchecked);
7598: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 7599: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 7600: $currnotified = $currsettings->{'selfenroll_notifylist'};
7601: $currapproval = $currsettings->{'selfenroll_approval'};
7602: }
7603: if ($currapproval !~ /^[012]$/) {
7604: $currapproval = 0;
7605: }
1.400 raeburn 7606: if ($noedit{$item}) {
7607: $output .= $selfdescs{'approval'}{$currapproval}.
7608: '<br />'.&mt('(Set by Domain Coordinator)');
7609: next;
7610: }
1.398 raeburn 7611: $appchecked{$currapproval} = ' checked="checked"';
7612: for my $i (0..2) {
7613: $output .= '<label>'.
7614: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 7615: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
7616: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 7617: }
7618: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
7619: my (@ccs,%notified);
1.322 raeburn 7620: my $ccrole = 'cc';
7621: if ($crstype eq 'Community') {
7622: $ccrole = 'co';
7623: }
7624: if ($advhash{$ccrole}) {
7625: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 7626: }
7627: if ($currnotified) {
7628: foreach my $current (split(/,/,$currnotified)) {
7629: $notified{$current} = 1;
7630: if (!grep(/^\Q$current\E$/,@ccs)) {
7631: push(@ccs,$current);
7632: }
7633: }
7634: }
7635: if (@ccs) {
1.398 raeburn 7636: my $style;
7637: unless ($currapproval) {
7638: $style = ' style="display: none;"';
7639: }
7640: $output .= '<br /><div id="notified"'.$style.'>'.
7641: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
7642: &Apache::loncommon::start_data_table().
1.276 raeburn 7643: &Apache::loncommon::start_data_table_row();
7644: my $count = 0;
7645: my $numcols = 4;
7646: foreach my $cc (sort(@ccs)) {
7647: my $notifyon;
7648: my ($ccuname,$ccudom) = split(/:/,$cc);
7649: if ($notified{$cc}) {
7650: $notifyon = ' checked="checked" ';
7651: }
7652: if ($count && !$count%$numcols) {
7653: $output .= &Apache::loncommon::end_data_table_row().
7654: &Apache::loncommon::start_data_table_row()
7655: }
7656: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 7657: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 7658: &Apache::loncommon::plainname($ccuname,$ccudom).
7659: '</label></span></td>';
1.343 raeburn 7660: $count ++;
1.276 raeburn 7661: }
7662: my $rem = $count%$numcols;
7663: if ($rem) {
7664: my $emptycols = $numcols - $rem;
7665: for (my $i=0; $i<$emptycols; $i++) {
7666: $output .= '<td> </td>';
7667: }
7668: }
7669: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 7670: &Apache::loncommon::end_data_table().
7671: '</div>';
1.276 raeburn 7672: }
7673: } elsif ($item eq 'limit') {
1.398 raeburn 7674: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
7675: if (ref($currsettings) eq 'HASH') {
7676: $currlim = $currsettings->{'selfenroll_limit'};
7677: $currcap = $currsettings->{'selfenroll_cap'};
7678: }
1.400 raeburn 7679: if ($noedit{$item}) {
7680: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
7681: if ($currlim eq 'allstudents') {
7682: $output .= &mt('Limit by total students');
7683: } elsif ($currlim eq 'selfenrolled') {
7684: $output .= &mt('Limit by total self-enrolled students');
7685: }
7686: $output .= ' '.&mt('Maximum: [_1]',$currcap).
7687: '<br />'.&mt('(Set by Domain Coordinator)');
7688: } else {
7689: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
7690: }
7691: next;
7692: }
1.276 raeburn 7693: if ($currlim eq 'allstudents') {
7694: $crslimit = ' checked="checked" ';
7695: $selflimit = ' ';
7696: $nolimit = ' ';
7697: } elsif ($currlim eq 'selfenrolled') {
7698: $crslimit = ' ';
7699: $selflimit = ' checked="checked" ';
7700: $nolimit = ' ';
7701: } else {
7702: $crslimit = ' ';
7703: $selflimit = ' ';
1.398 raeburn 7704: $nolimit = ' checked="checked" ';
1.276 raeburn 7705: }
7706: $output .= '<table><tr><td><label>'.
1.418 raeburn 7707: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 7708: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 7709: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 7710: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 7711: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 7712: &mt('Limit by total self-enrolled students').
7713: '</td></tr><tr>'.
7714: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
7715: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 7716: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 7717: }
7718: $output .= &Apache::lonhtmlcommon::row_closure(1);
7719: }
7720: }
1.418 raeburn 7721: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
7722: unless ($readonly) {
7723: $output .= '<input type="button" name="selfenrollconf" value="'
7724: .&mt('Save').'" onclick="validate_types(this.form);" />';
7725: }
7726: $output .= '<input type="hidden" name="action" value="selfenroll" />'
7727: .'<input type="hidden" name="state" value="done" />'."\n"
7728: .$additional.'</form>';
1.237 raeburn 7729: $r->print($output);
7730: return;
7731: }
7732:
1.400 raeburn 7733: sub get_noedit_fields {
7734: my ($cdom,$cnum,$crstype,$row) = @_;
7735: my %noedit;
7736: if (ref($row) eq 'ARRAY') {
7737: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
7738: 'internal.selfenrollmgrdc',
7739: 'internal.selfenrollmgrcc'],$cdom,$cnum);
7740: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
7741: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
7742: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
7743: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
7744: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
7745: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
7746:
7747: foreach my $item (@{$row}) {
7748: next if ($specific_managebycc{$item});
7749: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
7750: $noedit{$item} = 1;
7751: }
7752: }
7753: }
7754: return %noedit;
1.470 raeburn 7755: }
1.400 raeburn 7756:
7757: sub visible_in_stdcat {
7758: my ($cdom,$cnum,$domconf) = @_;
7759: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
7760: unless (ref($domconf) eq 'HASH') {
7761: return ($visible,$cansetvis,\@vismsgs);
7762: }
7763: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7764: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 7765: $settable{'togglecats'} = 1;
7766: }
1.400 raeburn 7767: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 7768: $settable{'categorize'} = 1;
7769: }
1.400 raeburn 7770: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7771: }
1.260 raeburn 7772: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 7773: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
7774: } elsif ($settable{'togglecats'}) {
7775: $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 7776: } elsif ($settable{'categorize'}) {
1.256 raeburn 7777: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
7778: } else {
7779: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
7780: }
7781:
7782: my %currsettings =
7783: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
7784: $cdom,$cnum);
1.400 raeburn 7785: $visible = 0;
1.256 raeburn 7786: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 7787: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7788: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7789: if (ref($cathash) eq 'HASH') {
7790: if ($cathash->{'instcode::0'} eq '') {
7791: push(@vismsgs,'dc_addinst');
7792: } else {
7793: $visible = 1;
7794: }
7795: } else {
7796: $visible = 1;
7797: }
7798: } else {
7799: $visible = 1;
7800: }
7801: } else {
7802: if (ref($cathash) eq 'HASH') {
7803: if ($cathash->{'instcode::0'} ne '') {
7804: push(@vismsgs,'dc_instcode');
7805: }
7806: } else {
7807: push(@vismsgs,'dc_instcode');
7808: }
7809: }
7810: if ($currsettings{'categories'} ne '') {
7811: my $cathash;
1.400 raeburn 7812: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7813: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7814: if (ref($cathash) eq 'HASH') {
7815: if (keys(%{$cathash}) == 0) {
7816: push(@vismsgs,'dc_catalog');
7817: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
7818: push(@vismsgs,'dc_categories');
7819: } else {
7820: my @currcategories = split('&',$currsettings{'categories'});
7821: my $matched = 0;
7822: foreach my $cat (@currcategories) {
7823: if ($cathash->{$cat} ne '') {
7824: $visible = 1;
7825: $matched = 1;
7826: last;
7827: }
7828: }
7829: if (!$matched) {
1.260 raeburn 7830: if ($settable{'categorize'}) {
1.256 raeburn 7831: push(@vismsgs,'chgcat');
7832: } else {
7833: push(@vismsgs,'dc_chgcat');
7834: }
7835: }
7836: }
7837: }
7838: }
7839: } else {
7840: if (ref($cathash) eq 'HASH') {
7841: if ((keys(%{$cathash}) > 1) ||
7842: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 7843: if ($settable{'categorize'}) {
1.256 raeburn 7844: push(@vismsgs,'addcat');
7845: } else {
7846: push(@vismsgs,'dc_addcat');
7847: }
7848: }
7849: }
7850: }
7851: if ($currsettings{'hidefromcat'} eq 'yes') {
7852: $visible = 0;
7853: if ($settable{'togglecats'}) {
7854: unshift(@vismsgs,'unhide');
7855: } else {
7856: unshift(@vismsgs,'dc_unhide')
7857: }
7858: }
1.400 raeburn 7859: return ($visible,$cansetvis,\@vismsgs);
7860: }
7861:
7862: sub cat_visibility {
1.469 raeburn 7863: my ($cdom) = @_;
1.400 raeburn 7864: my %visactions = &Apache::lonlocal::texthash(
7865: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
7866: 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.',
7867: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
7868: none => 'Display of a course catalog is disabled for this domain.',
7869: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
7870: 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.',
7871: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
7872: take => 'Take the following action to ensure the course appears in the Catalog:',
7873: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
7874: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
7875: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
1.469 raeburn 7876: dc_addinst => 'Ask a domain coordinator to enable catalog display of "Official courses (with institutional codes)".',
1.400 raeburn 7877: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
7878: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
7879: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
7880: 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',
7881: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
7882: );
1.469 raeburn 7883: if ($env{'request.role'} eq "dc./$cdom/") {
7884: $visactions{'dc_chgconf'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the Catalog type for this domain.','»');
7885: $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.','»');
7886: $visactions{'dc_unhide'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the "Exclude from course catalog" setting.','»');
7887: $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)".','»');
7888: $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).','»');
7889: $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.','»');
7890: $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.','»');
7891: $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.','»');
7892: $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.','»');
7893: }
1.400 raeburn 7894: $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>"');
7895: $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>"');
7896: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
7897: return \%visactions;
1.256 raeburn 7898: }
7899:
1.241 raeburn 7900: sub new_selfenroll_dom_row {
7901: my ($newdom,$num) = @_;
7902: my $domdesc = &Apache::lonnet::domain($newdom);
7903: my $output;
7904: if ($domdesc ne '') {
7905: $output .= &Apache::loncommon::start_data_table_row()
7906: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
7907: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 7908: .'" value="'.$newdom.'" /></span><br />'
7909: .'<span class="LC_nobreak"><label><input type="checkbox" '
7910: .'name="selfenroll_activate" value="'.$num.'" '
7911: .'onchange="javascript:update_types('
7912: ."'selfenroll_activate','$num'".');" />'
7913: .&mt('Activate').'</label></span></td>';
1.241 raeburn 7914: my @currinsttypes;
7915: $output .= '<td>'.&mt('User types:').'<br />'
7916: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
7917: .&Apache::loncommon::end_data_table_row();
7918: }
7919: return $output;
7920: }
7921:
7922: sub selfenroll_inst_types {
1.418 raeburn 7923: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 7924: my $output;
7925: my $numinrow = 4;
7926: my $count = 0;
7927: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 7928: my $othervalue = 'any';
1.418 raeburn 7929: my $disabled;
7930: if ($readonly) {
7931: $disabled = ' disabled="disabled"';
7932: }
1.241 raeburn 7933: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 7934: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 7935: $othervalue = 'other';
7936: }
1.241 raeburn 7937: $output .= '<table><tr>';
7938: foreach my $type (@{$types}) {
7939: if (($count > 0) && ($count%$numinrow == 0)) {
7940: $output .= '</tr><tr>';
7941: }
7942: if (defined($usertypes->{$type})) {
1.257 raeburn 7943: my $esc_type = &escape($type);
1.241 raeburn 7944: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 7945: $esc_type.'" ';
1.241 raeburn 7946: if (ref($currinsttypes) eq 'ARRAY') {
7947: if (@{$currinsttypes} > 0) {
1.249 raeburn 7948: if (grep(/^any$/,@{$currinsttypes})) {
7949: $output .= 'checked="checked"';
1.257 raeburn 7950: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 7951: $output .= 'checked="checked"';
7952: }
1.249 raeburn 7953: } else {
7954: $output .= 'checked="checked"';
1.241 raeburn 7955: }
7956: }
1.418 raeburn 7957: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 7958: }
7959: $count ++;
7960: }
7961: if (($count > 0) && ($count%$numinrow == 0)) {
7962: $output .= '</tr><tr>';
7963: }
1.249 raeburn 7964: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 7965: if (ref($currinsttypes) eq 'ARRAY') {
7966: if (@{$currinsttypes} > 0) {
1.249 raeburn 7967: if (grep(/^any$/,@{$currinsttypes})) {
7968: $output .= ' checked="checked"';
7969: } elsif ($othervalue eq 'other') {
7970: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
7971: $output .= ' checked="checked"';
7972: }
1.241 raeburn 7973: }
1.249 raeburn 7974: } else {
7975: $output .= ' checked="checked"';
1.241 raeburn 7976: }
1.249 raeburn 7977: } else {
7978: $output .= ' checked="checked"';
1.241 raeburn 7979: }
1.418 raeburn 7980: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 7981: }
7982: return $output;
7983: }
7984:
1.237 raeburn 7985: sub selfenroll_date_forms {
7986: my ($startform,$endform) = @_;
7987: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 7988: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 7989: 'LC_oddrow_value')."\n".
7990: $startform."\n".
7991: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 7992: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 7993: 'LC_oddrow_value')."\n".
7994: $endform."\n".
7995: &Apache::lonhtmlcommon::row_closure(1).
7996: &Apache::lonhtmlcommon::end_pick_box();
7997: return $output;
7998: }
7999:
1.239 raeburn 8000: sub print_userchangelogs_display {
1.415 raeburn 8001: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 8002: my $formname = 'rolelog';
1.418 raeburn 8003: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 8004: if ($context eq 'domain') {
8005: $domain = $env{'request.role.domain'};
8006: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
8007: } else {
8008: if ($context eq 'course') {
8009: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
8010: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
8011: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 8012: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 8013: my %saveable_parameters = ('show' => 'scalar',);
8014: &Apache::loncommon::store_course_settings('roles_log',
8015: \%saveable_parameters);
8016: &Apache::loncommon::restore_course_settings('roles_log',
8017: \%saveable_parameters);
8018: } elsif ($context eq 'author') {
1.470 raeburn 8019: $domain = $env{'user.domain'};
1.363 raeburn 8020: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
8021: $username = $env{'user.name'};
1.470 raeburn 8022: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
8023: ($domain,$username) = ($1,$2);
1.363 raeburn 8024: } else {
8025: undef($domain);
8026: }
8027: }
8028: if ($domain ne '' && $username ne '') {
8029: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
8030: }
8031: }
1.239 raeburn 8032: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
8033:
1.415 raeburn 8034: my $helpitem;
8035: if ($context eq 'course') {
8036: $helpitem = 'Course_User_Logs';
1.439 raeburn 8037: } elsif ($context eq 'domain') {
8038: $helpitem = 'Domain_Role_Logs';
8039: } elsif ($context eq 'author') {
8040: $helpitem = 'Author_User_Logs';
1.415 raeburn 8041: }
8042: push (@{$brcrum},
8043: {href => '/adm/createuser?action=changelogs',
8044: text => 'User Management Logs',
8045: help => $helpitem});
8046: my $bread_crumbs_component = 'User Changes';
8047: my $args = { bread_crumbs => $brcrum,
8048: bread_crumbs_component => $bread_crumbs_component};
8049:
8050: # Create navigation javascript
8051: my $jsnav = &userlogdisplay_js($formname);
8052:
8053: my $jscript = (<<ENDSCRIPT);
8054: <script type="text/javascript">
8055: // <![CDATA[
8056: $jsnav
8057: // ]]>
8058: </script>
8059: ENDSCRIPT
8060:
8061: # print page header
8062: $r->print(&header($jscript,$args));
8063:
1.239 raeburn 8064: # set defaults
8065: my $now = time();
8066: my $defstart = $now - (7*24*3600); #7 days ago
8067: my %defaults = (
8068: page => '1',
8069: show => '10',
8070: role => 'any',
8071: chgcontext => 'any',
8072: rolelog_start_date => $defstart,
8073: rolelog_end_date => $now,
1.468 raeburn 8074: approvals => 'any',
1.239 raeburn 8075: );
8076: my $more_records = 0;
8077:
8078: # set current
8079: my %curr;
1.468 raeburn 8080: foreach my $item ('show','page','role','chgcontext','approvals') {
1.239 raeburn 8081: $curr{$item} = $env{'form.'.$item};
8082: }
8083: my ($startdate,$enddate) =
8084: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
8085: $curr{'rolelog_start_date'} = $startdate;
8086: $curr{'rolelog_end_date'} = $enddate;
8087: foreach my $key (keys(%defaults)) {
8088: if ($curr{$key} eq '') {
8089: $curr{$key} = $defaults{$key};
8090: }
8091: }
1.248 raeburn 8092: my (%whodunit,%changed,$version);
8093: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 8094: my ($minshown,$maxshown);
1.255 raeburn 8095: $minshown = 1;
1.239 raeburn 8096: my $count = 0;
1.415 raeburn 8097: if ($curr{'show'} =~ /\D/) {
8098: $curr{'page'} = 1;
8099: } else {
1.239 raeburn 8100: $maxshown = $curr{'page'} * $curr{'show'};
8101: if ($curr{'page'} > 1) {
8102: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
8103: }
8104: }
1.301 bisitz 8105:
1.327 raeburn 8106: # Form Header
8107: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 8108: &role_display_filter($context,$formname,$domain,$username,\%curr,
8109: $version,$crstype));
1.327 raeburn 8110:
8111: my $showntableheader = 0;
8112:
8113: # Table Header
8114: my $tableheader =
8115: &Apache::loncommon::start_data_table_header_row()
8116: .'<th> </th>'
8117: .'<th>'.&mt('When').'</th>'
8118: .'<th>'.&mt('Who made the change').'</th>'
8119: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 8120: .'<th>'.&mt('Role').'</th>';
8121:
8122: if ($context eq 'course') {
8123: $tableheader .= '<th>'.&mt('Section').'</th>';
8124: }
8125: $tableheader .=
8126: '<th>'.&mt('Context').'</th>'
1.327 raeburn 8127: .'<th>'.&mt('Start').'</th>'
8128: .'<th>'.&mt('End').'</th>'
8129: .&Apache::loncommon::end_data_table_header_row();
8130:
8131: # Display user change log data
1.239 raeburn 8132: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
8133: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
8134: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 8135: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 8136: if ($count >= $curr{'page'} * $curr{'show'}) {
8137: $more_records = 1;
8138: last;
8139: }
8140: }
8141: if ($curr{'role'} ne 'any') {
8142: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
8143: }
8144: if ($curr{'chgcontext'} ne 'any') {
8145: if ($curr{'chgcontext'} eq 'selfenroll') {
8146: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
8147: } else {
8148: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
8149: }
8150: }
1.418 raeburn 8151: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 8152: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 8153: }
1.468 raeburn 8154: if ($curr{'approvals'} eq 'none') {
8155: next if ($roleslog{$id}{'logentry'}{'approval'});
8156: } elsif ($curr{'approvals'} ne 'any') {
8157: next if ($roleslog{$id}{'logentry'}{'approval'} ne $curr{'approvals'});
8158: }
1.239 raeburn 8159: $count ++;
8160: next if ($count < $minshown);
1.327 raeburn 8161: unless ($showntableheader) {
1.415 raeburn 8162: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 8163: .$tableheader);
8164: $r->rflush();
8165: $showntableheader = 1;
8166: }
1.239 raeburn 8167: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
8168: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
8169: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
8170: }
8171: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
8172: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
8173: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
8174: }
8175: my $sec = $roleslog{$id}{'logentry'}{'section'};
8176: if ($sec eq '') {
8177: $sec = &mt('None');
8178: }
8179: my ($rolestart,$roleend);
8180: if ($roleslog{$id}{'delflag'}) {
8181: $rolestart = &mt('deleted');
8182: $roleend = &mt('deleted');
8183: } else {
8184: $rolestart = $roleslog{$id}{'logentry'}{'start'};
8185: $roleend = $roleslog{$id}{'logentry'}{'end'};
8186: if ($rolestart eq '' || $rolestart == 0) {
8187: $rolestart = &mt('No start date');
8188: } else {
8189: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
8190: }
8191: if ($roleend eq '' || $roleend == 0) {
8192: $roleend = &mt('No end date');
8193: } else {
8194: $roleend = &Apache::lonlocal::locallocaltime($roleend);
8195: }
8196: }
8197: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
8198: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
8199: $chgcontext = 'selfenroll';
8200: }
1.363 raeburn 8201: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 8202: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
8203: $chgcontext = $lt{$chgcontext};
8204: }
1.468 raeburn 8205: my ($showreqby,%reqby);
8206: if (($roleslog{$id}{'logentry'}{'approval'}) &&
8207: ($roleslog{$id}{'logentry'}{'requester'})) {
8208: if ($reqby{$roleslog{$id}{'logentry'}{'requester'}} eq '') {
8209: my ($requname,$requdom) = split(/:/,$roleslog{$id}{'logentry'}{'requester'});
8210: $reqby{$roleslog{$id}{'logentry'}{'requester'}} =
8211: &Apache::loncommon::plainname($requname,$requdom);
8212: }
8213: $showreqby = &mt('Requester').': <span class="LC_nobreak">'.$reqby{$roleslog{$id}{'logentry'}{'requester'}}.'</span><br />';
8214: if ($roleslog{$id}{'logentry'}{'approval'} eq 'domain') {
8215: $showreqby .= &mt('Adjudicator').': <span class="LC_nobreak">'.
8216: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.
8217: '</span>';
8218: } else {
8219: $showreqby .= '<span class="LC_nobreak">'.&mt('User approved').'</span>';
8220: }
8221: } else {
8222: $showreqby = $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}};
8223: }
1.327 raeburn 8224: $r->print(
1.301 bisitz 8225: &Apache::loncommon::start_data_table_row()
8226: .'<td>'.$count.'</td>'
8227: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
1.468 raeburn 8228: .'<td>'.$showreqby.'</td>'
1.301 bisitz 8229: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 8230: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
8231: if ($context eq 'course') {
8232: $r->print('<td>'.$sec.'</td>');
8233: }
8234: $r->print(
8235: '<td>'.$chgcontext.'</td>'
1.301 bisitz 8236: .'<td>'.$rolestart.'</td>'
8237: .'<td>'.$roleend.'</td>'
1.327 raeburn 8238: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 8239: }
8240:
1.327 raeburn 8241: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 8242: $r->print(&Apache::loncommon::end_data_table().
8243: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 8244: } else { # No content displayed above
1.301 bisitz 8245: $r->print('<p class="LC_info">'
8246: .&mt('There are no records to display.')
8247: .'</p>'
8248: );
1.239 raeburn 8249: }
1.301 bisitz 8250:
1.327 raeburn 8251: # Form Footer
8252: $r->print(
8253: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
8254: .'<input type="hidden" name="action" value="changelogs" />'
8255: .'</form>');
8256: return;
8257: }
1.301 bisitz 8258:
1.416 raeburn 8259: sub print_useraccesslogs_display {
8260: my ($r,$uname,$udom,$permission,$brcrum) = @_;
8261: my $formname = 'accesslog';
8262: my $form = 'document.accesslog';
8263:
8264: # set breadcrumbs
1.422 raeburn 8265: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 8266: my $prevphasestr;
8267: if ($env{'form.popup'}) {
8268: $brcrum = [];
8269: } else {
8270: push (@{$brcrum},
8271: {href => "javascript:backPage($form)",
8272: text => $breadcrumb_text{'search'}});
8273: my @prevphases;
8274: if ($env{'form.prevphases'}) {
8275: @prevphases = split(/,/,$env{'form.prevphases'});
8276: $prevphasestr = $env{'form.prevphases'};
8277: }
8278: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
8279: push(@{$brcrum},
8280: {href => "javascript:backPage($form,'get_user_info','select')",
8281: text => $breadcrumb_text{'userpicked'}});
8282: if ($env{'form.phase'} eq 'userpicked') {
8283: $prevphasestr = 'userpicked';
8284: }
1.416 raeburn 8285: }
8286: }
8287: push(@{$brcrum},
8288: {href => '/adm/createuser?action=accesslogs',
8289: text => 'User access logs',
1.424 raeburn 8290: help => 'Domain_User_Access_Logs'});
1.416 raeburn 8291: my $bread_crumbs_component = 'User Access Logs';
8292: my $args = { bread_crumbs => $brcrum,
8293: bread_crumbs_component => 'User Management'};
1.423 raeburn 8294: if ($env{'form.popup'}) {
8295: $args->{'no_nav_bar'} = 1;
1.431 raeburn 8296: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 8297: }
1.416 raeburn 8298:
1.417 raeburn 8299: # set javascript
1.416 raeburn 8300: my ($jsback,$elements) = &crumb_utilities();
8301: my $jsnav = &userlogdisplay_js($formname);
8302:
8303: my $jscript = (<<ENDSCRIPT);
8304: <script type="text/javascript">
8305: // <![CDATA[
8306:
8307: $jsback
8308: $jsnav
8309:
8310: // ]]>
8311: </script>
8312:
8313: ENDSCRIPT
8314:
1.417 raeburn 8315: # print page header
1.416 raeburn 8316: $r->print(&header($jscript,$args));
8317:
8318: # early out unless log data can be displayed.
8319: unless ($permission->{'activity'}) {
8320: $r->print('<p class="LC_warning">'
8321: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 8322: .'</p>');
8323: if ($env{'form.popup'}) {
8324: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
8325: } else {
8326: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8327: }
1.416 raeburn 8328: return;
8329: }
8330:
8331: unless ($udom eq $env{'request.role.domain'}) {
8332: $r->print('<p class="LC_warning">'
8333: .&mt("User's domain must match role's domain")
8334: .'</p>'
8335: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 8336: return;
1.416 raeburn 8337: }
8338:
8339: if (($uname eq '') || ($udom eq '')) {
8340: $r->print('<p class="LC_warning">'
8341: .&mt('Invalid username or domain')
8342: .'</p>'
8343: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8344: return;
8345: }
8346:
1.437 raeburn 8347: if (&Apache::lonnet::privileged($uname,$udom,
8348: [$env{'request.role.domain'}],['dc','su'])) {
8349: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
8350: [$env{'request.role.domain'}],['dc','su'])) {
8351: $r->print('<p class="LC_warning">'
8352: .&mt('You need to be a privileged user to display user access logs for [_1]',
8353: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
8354: $uname,$udom))
8355: .'</p>');
8356: if ($env{'form.popup'}) {
8357: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
8358: } else {
8359: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8360: }
8361: return;
8362: }
8363: }
8364:
1.416 raeburn 8365: # set defaults
8366: my $now = time();
8367: my $defstart = $now - (7*24*3600);
8368: my %defaults = (
8369: page => '1',
8370: show => '10',
8371: activity => 'any',
8372: accesslog_start_date => $defstart,
8373: accesslog_end_date => $now,
8374: );
8375: my $more_records = 0;
8376:
8377: # set current
8378: my %curr;
8379: foreach my $item ('show','page','activity') {
8380: $curr{$item} = $env{'form.'.$item};
8381: }
8382: my ($startdate,$enddate) =
8383: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
8384: $curr{'accesslog_start_date'} = $startdate;
8385: $curr{'accesslog_end_date'} = $enddate;
8386: foreach my $key (keys(%defaults)) {
8387: if ($curr{$key} eq '') {
8388: $curr{$key} = $defaults{$key};
8389: }
8390: }
8391: my ($minshown,$maxshown);
8392: $minshown = 1;
8393: my $count = 0;
8394: if ($curr{'show'} =~ /\D/) {
8395: $curr{'page'} = 1;
8396: } else {
8397: $maxshown = $curr{'page'} * $curr{'show'};
8398: if ($curr{'page'} > 1) {
8399: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
8400: }
8401: }
8402:
8403: # form header
8404: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
8405: &activity_display_filter($formname,\%curr));
8406:
8407: my $showntableheader = 0;
8408: my ($nav_script,$nav_links);
8409:
8410: # table header
1.453 raeburn 8411: my $heading = '<h3>'.
1.431 raeburn 8412: &mt('User access logs for: [_1]',
1.453 raeburn 8413: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
8414: my $tableheader = $heading
1.431 raeburn 8415: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 8416: .'<th> </th>'
8417: .'<th>'.&mt('When').'</th>'
8418: .'<th>'.&mt('HostID').'</th>'
8419: .'<th>'.&mt('Event').'</th>'
8420: .'<th>'.&mt('Other data').'</th>'
8421: .&Apache::loncommon::end_data_table_header_row();
8422:
8423: my %filters=(
8424: start => $curr{'accesslog_start_date'},
8425: end => $curr{'accesslog_end_date'},
8426: action => $curr{'activity'},
8427: );
8428:
8429: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
8430: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
8431: my (%courses,%missing);
8432: my @results = split(/\&/,$reply);
8433: foreach my $item (reverse(@results)) {
8434: my ($timestamp,$host,$event) = split(/:/,$item);
8435: next unless ($event =~ /^(Log|Role)/);
8436: if ($curr{'show'} !~ /\D/) {
8437: if ($count >= $curr{'page'} * $curr{'show'}) {
8438: $more_records = 1;
8439: last;
8440: }
8441: }
8442: $count ++;
8443: next if ($count < $minshown);
8444: unless ($showntableheader) {
8445: $r->print($nav_script
8446: .&Apache::loncommon::start_data_table()
8447: .$tableheader);
8448: $r->rflush();
8449: $showntableheader = 1;
8450: }
1.418 raeburn 8451: my ($shown,$extra);
1.437 raeburn 8452: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 8453: if ($event eq 'Role') {
8454: my ($rolecode,$extent) = split(/\./,$data,2);
8455: next if ($extent eq '');
8456: my ($crstype,$desc,$info);
1.418 raeburn 8457: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
8458: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 8459: my $cid = $cdom.'_'.$cnum;
8460: if (exists($courses{$cid})) {
8461: $crstype = $courses{$cid}{'type'};
8462: $desc = $courses{$cid}{'description'};
8463: } elsif ($missing{$cid}) {
8464: $crstype = 'Course';
8465: $desc = 'Course/Community';
8466: } else {
8467: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
8468: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
8469: $courses{$cid} = $crsinfo{$cid};
8470: $crstype = $crsinfo{$cid}{'type'};
8471: $desc = $crsinfo{$cid}{'description'};
8472: } else {
8473: $missing{$cid} = 1;
8474: }
8475: }
8476: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 8477: if ($sec ne '') {
8478: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
8479: }
1.416 raeburn 8480: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
8481: my ($dom,$name) = ($1,$2);
8482: if ($rolecode eq 'au') {
8483: $extra = '';
8484: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 8485: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 8486: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
8487: $extra = &mt('Domain: [_1]',$dom);
8488: }
8489: }
8490: my $rolename;
8491: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
8492: my $role = $3;
1.417 raeburn 8493: my $owner = "($2:$1)";
1.416 raeburn 8494: if ($2 eq $1.'-domainconfig') {
8495: $owner = '(ad hoc)';
1.417 raeburn 8496: }
1.416 raeburn 8497: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
8498: } else {
8499: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
8500: }
8501: $shown = &mt('Role selection: [_1]',$rolename);
8502: } else {
8503: $shown = &mt($event);
1.437 raeburn 8504: if ($data =~ /^webdav/) {
8505: my ($path,$clientip) = split(/\s+/,$data,2);
8506: $path =~ s/^webdav//;
8507: if ($clientip ne '') {
8508: $extra = &mt('Client IP address: [_1]',$clientip);
8509: }
8510: if ($path ne '') {
8511: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
8512: }
8513: } elsif ($data ne '') {
8514: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 8515: }
8516: }
8517: $r->print(
8518: &Apache::loncommon::start_data_table_row()
8519: .'<td>'.$count.'</td>'
8520: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
8521: .'<td>'.$host.'</td>'
8522: .'<td>'.$shown.'</td>'
8523: .'<td>'.$extra.'</td>'
8524: .&Apache::loncommon::end_data_table_row()."\n");
8525: }
8526: }
8527:
8528: if ($showntableheader) { # Table footer, if content displayed above
8529: $r->print(&Apache::loncommon::end_data_table().
8530: &userlogdisplay_navlinks(\%curr,$more_records));
8531: } else { # No content displayed above
1.453 raeburn 8532: $r->print($heading.'<p class="LC_info">'
1.416 raeburn 8533: .&mt('There are no records to display.')
8534: .'</p>');
8535: }
8536:
1.423 raeburn 8537: if ($env{'form.popup'} == 1) {
8538: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
8539: }
8540:
1.416 raeburn 8541: # Form Footer
8542: $r->print(
8543: '<input type="hidden" name="currstate" value="" />'
8544: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
8545: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
8546: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
8547: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
8548: .'<input type="hidden" name="phase" value="activity" />'
8549: .'<input type="hidden" name="action" value="accesslogs" />'
8550: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
8551: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
8552: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
8553: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
8554: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
8555: .'</form>');
8556: return;
8557: }
8558:
8559: sub earlyout_accesslog_form {
8560: my ($formname,$prevphasestr,$udom) = @_;
8561: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
8562: return <<"END";
8563: <form action="/adm/createuser" method="post" name="$formname">
8564: <input type="hidden" name="currstate" value="" />
8565: <input type="hidden" name="prevphases" value="$prevphasestr" />
8566: <input type="hidden" name="phase" value="activity" />
8567: <input type="hidden" name="action" value="accesslogs" />
8568: <input type="hidden" name="srchdomain" value="$udom" />
8569: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
8570: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
8571: <input type="hidden" name="srchterm" value="$srchterm" />
8572: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
8573: </form>
8574: END
8575: }
8576:
8577: sub activity_display_filter {
8578: my ($formname,$curr) = @_;
8579: my $nolink = 1;
8580: my $output = '<table><tr><td valign="top">'.
8581: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
1.467 raeburn 8582: &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef,
1.416 raeburn 8583: (&mt('all'),5,10,20,50,100,1000,10000)).
8584: '</td><td> </td>';
8585: my $startform =
8586: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
8587: $curr->{'accesslog_start_date'},undef,
8588: undef,undef,undef,undef,undef,undef,$nolink);
8589: my $endform =
8590: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
8591: $curr->{'accesslog_end_date'},undef,
8592: undef,undef,undef,undef,undef,undef,$nolink);
8593: my %lt = &Apache::lonlocal::texthash (
8594: activity => 'Activity',
8595: Role => 'Role selection',
8596: log => 'Log-in or Logout',
8597: );
8598: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
8599: '<table><tr><td>'.&mt('After:').
8600: '</td><td>'.$startform.'</td></tr>'.
8601: '<tr><td>'.&mt('Before:').'</td>'.
8602: '<td>'.$endform.'</td></tr></table>'.
8603: '</td>'.
8604: '<td> </td>'.
8605: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
8606: '<select name="activity"><option value="any"';
8607: if ($curr->{'activity'} eq 'any') {
8608: $output .= ' selected="selected"';
8609: }
8610: $output .= '>'.&mt('Any').'</option>'."\n";
8611: foreach my $activity ('Role','log') {
8612: my $selstr = '';
8613: if ($activity eq $curr->{'activity'}) {
8614: $selstr = ' selected="selected"';
8615: }
8616: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
8617: }
8618: $output .= '</select></td>'.
8619: '</tr></table>';
8620: # Update Display button
8621: $output .= '<p>'
8622: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 8623: .'</p><hr />';
1.416 raeburn 8624: return $output;
8625: }
8626:
1.415 raeburn 8627: sub userlogdisplay_js {
8628: my ($formname) = @_;
8629: return <<"ENDSCRIPT";
8630:
1.239 raeburn 8631: function chgPage(caller) {
8632: if (caller == 'previous') {
8633: document.$formname.page.value --;
8634: }
8635: if (caller == 'next') {
8636: document.$formname.page.value ++;
8637: }
1.327 raeburn 8638: document.$formname.submit();
1.239 raeburn 8639: return;
8640: }
8641: ENDSCRIPT
1.415 raeburn 8642: }
8643:
8644: sub userlogdisplay_navlinks {
8645: my ($curr,$more_records) = @_;
8646: return unless(ref($curr) eq 'HASH');
8647: # Navigation Buttons
8648: my $nav_links = '<p>';
8649: if (($curr->{'page'} > 1) || ($more_records)) {
8650: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
8651: $nav_links .= '<input type="button"'
8652: .' onclick="javascript:chgPage('."'previous'".');"'
8653: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
8654: .'" /> ';
8655: }
8656: if ($more_records) {
8657: $nav_links .= '<input type="button"'
8658: .' onclick="javascript:chgPage('."'next'".');"'
8659: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
8660: .'" />';
1.301 bisitz 8661: }
8662: }
1.415 raeburn 8663: $nav_links .= '</p>';
8664: return $nav_links;
1.239 raeburn 8665: }
8666:
8667: sub role_display_filter {
1.363 raeburn 8668: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
1.239 raeburn 8669: my $nolink = 1;
8670: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 8671: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.467 raeburn 8672: &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef,
1.239 raeburn 8673: (&mt('all'),5,10,20,50,100,1000,10000)).
8674: '</td><td> </td>';
8675: my $startform =
8676: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
8677: $curr->{'rolelog_start_date'},undef,
8678: undef,undef,undef,undef,undef,undef,$nolink);
8679: my $endform =
8680: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
8681: $curr->{'rolelog_end_date'},undef,
8682: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 8683: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 8684: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
8685: '<table><tr><td>'.&mt('After:').
8686: '</td><td>'.$startform.'</td></tr>'.
8687: '<tr><td>'.&mt('Before:').'</td>'.
8688: '<td>'.$endform.'</td></tr></table>'.
8689: '</td>'.
8690: '<td> </td>'.
1.239 raeburn 8691: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
8692: '<select name="role"><option value="any"';
8693: if ($curr->{'role'} eq 'any') {
8694: $output .= ' selected="selected"';
8695: }
1.466 raeburn 8696: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 8697: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 8698: foreach my $role (@roles) {
8699: my $plrole;
8700: if ($role eq 'cr') {
8701: $plrole = &mt('Custom Role');
8702: } else {
1.318 raeburn 8703: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 8704: }
8705: my $selstr = '';
8706: if ($role eq $curr->{'role'}) {
8707: $selstr = ' selected="selected"';
8708: }
8709: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
8710: }
1.301 bisitz 8711: $output .= '</select></td>'.
8712: '<td> </td>'.
8713: '<td valign="top"><b>'.
1.239 raeburn 8714: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 8715: my @posscontexts;
8716: if ($context eq 'course') {
1.468 raeburn 8717: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype','ltienroll');
1.363 raeburn 8718: } elsif ($context eq 'domain') {
8719: @posscontexts = ('any','domain','requestauthor','domconfig','server');
8720: } else {
1.470 raeburn 8721: @posscontexts = ('any','author','coauthor','domain');
1.457 raeburn 8722: }
1.363 raeburn 8723: foreach my $chgtype (@posscontexts) {
1.239 raeburn 8724: my $selstr = '';
8725: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 8726: $selstr = ' selected="selected"';
1.239 raeburn 8727: }
1.363 raeburn 8728: if ($context eq 'course') {
1.376 raeburn 8729: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 8730: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
8731: }
1.239 raeburn 8732: }
8733: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 8734: }
1.468 raeburn 8735: my @possapprovals = ('any','none','domain','user');
8736: my %apptxt = &approval_types();
8737: $output .= '</select></td>'.
8738: '<td> </td>'.
8739: '<td valign="top"><b>'.
8740: &mt('Approvals:').'</b><br /><select name="approvals">';
8741: foreach my $approval (@possapprovals) {
8742: my $selstr = '';
8743: if ($curr->{'approvals'} eq $approval) {
8744: $selstr = ' selected="selected"';
8745: }
8746: $output .= '<option value="'.$approval.'"'.$selstr.'>'.$apptxt{$approval}.'</option>';
8747: }
8748: $output .= '</select></td></tr></table>';
1.303 bisitz 8749:
8750: # Update Display button
8751: $output .= '<p>'
8752: .'<input type="submit" value="'.&mt('Update Display').'" />'
8753: .'</p>';
8754:
8755: # Server version info
1.363 raeburn 8756: my $needsrev = '2.11.0';
8757: if ($context eq 'course') {
8758: $needsrev = '2.7.0';
8759: }
8760:
1.303 bisitz 8761: $output .= '<p class="LC_info">'
8762: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 8763: ,$needsrev);
1.248 raeburn 8764: if ($version) {
1.303 bisitz 8765: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
8766: }
8767: $output .= '</p><hr />';
1.239 raeburn 8768: return $output;
8769: }
8770:
8771: sub rolechg_contexts {
1.363 raeburn 8772: my ($context,$crstype) = @_;
8773: my %lt;
8774: if ($context eq 'course') {
8775: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 8776: any => 'Any',
1.376 raeburn 8777: automated => 'Automated Enrollment',
1.457 raeburn 8778: chgtype => 'Enrollment Type/Lock Change',
1.239 raeburn 8779: updatenow => 'Roster Update',
8780: createcourse => 'Course Creation',
8781: course => 'User Management in course',
8782: domain => 'User Management in domain',
1.313 raeburn 8783: selfenroll => 'Self-enrolled',
1.318 raeburn 8784: requestcourses => 'Course Request',
1.468 raeburn 8785: ltienroll => 'Enrollment via LTI',
1.239 raeburn 8786: );
1.363 raeburn 8787: if ($crstype eq 'Community') {
8788: $lt{'createcourse'} = &mt('Community Creation');
8789: $lt{'course'} = &mt('User Management in community');
8790: $lt{'requestcourses'} = &mt('Community Request');
8791: }
8792: } elsif ($context eq 'domain') {
8793: %lt = &Apache::lonlocal::texthash (
8794: any => 'Any',
8795: domain => 'User Management in domain',
8796: requestauthor => 'Authoring Request',
8797: server => 'Command line script (DC role)',
8798: domconfig => 'Self-enrolled',
8799: );
8800: } else {
8801: %lt = &Apache::lonlocal::texthash (
8802: any => 'Any',
8803: domain => 'User Management in domain',
8804: author => 'User Management by author',
1.470 raeburn 8805: coauthor => 'User Management by coauthor',
1.363 raeburn 8806: );
8807: }
1.239 raeburn 8808: return %lt;
8809: }
8810:
1.468 raeburn 8811: sub approval_types {
8812: return &Apache::lonlocal::texthash (
8813: any => 'Any',
8814: none => 'No approval needed',
8815: user => 'Role recipient approval',
8816: domain => 'Domain coordinator approval',
8817: );
8818: }
8819:
1.428 raeburn 8820: sub print_helpdeskaccess_display {
8821: my ($r,$permission,$brcrum) = @_;
8822: my $formname = 'helpdeskaccess';
8823: my $helpitem = 'Course_Helpdesk_Access';
8824: push (@{$brcrum},
8825: {href => '/adm/createuser?action=helpdesk',
8826: text => 'Helpdesk Access',
8827: help => $helpitem});
8828: my $bread_crumbs_component = 'Helpdesk Staff Access';
8829: my $args = { bread_crumbs => $brcrum,
8830: bread_crumbs_component => $bread_crumbs_component};
8831:
8832: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8833: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8834: my $confname = $cdom.'-domainconfig';
8835: my $crstype = &Apache::loncommon::course_type();
8836:
1.434 raeburn 8837: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 8838: my ($numstatustypes,@jsarray);
8839: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8840: if (ref($types) eq 'ARRAY') {
1.430 raeburn 8841: if (@{$types} > 0) {
1.428 raeburn 8842: $numstatustypes = scalar(@{$types});
8843: push(@accesstypes,'status');
8844: @jsarray = ('bystatus');
8845: }
8846: }
8847: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 8848: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8849: if (keys(%domhelpdesk)) {
8850: push(@accesstypes,('inc','exc'));
8851: push(@jsarray,('notinc','notexc'));
8852: }
8853: push(@jsarray,'privs');
8854: my $hiddenstr = join("','",@jsarray);
8855: my $rolestr = join("','",sort(keys(%customroles)));
8856:
8857: my $jscript;
8858: my (%settings,%overridden);
8859: if (keys(%customroles)) {
8860: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8861: $types,\%customroles,\%settings,\%overridden);
8862: my %jsfull=();
8863: my %jslevels= (
8864: course => {},
8865: domain => {},
8866: system => {},
8867: );
8868: my %jslevelscurrent=(
8869: course => {},
8870: domain => {},
8871: system => {},
8872: );
8873: my (%privs,%jsprivs);
8874: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
8875: foreach my $priv (keys(%jsfull)) {
8876: if ($jslevels{'course'}{$priv}) {
8877: $jsprivs{$priv} = 1;
8878: }
8879: }
8880: my (%elements,%stored);
8881: foreach my $role (keys(%customroles)) {
8882: $elements{$role.'_access'} = 'radio';
8883: $elements{$role.'_incrs'} = 'radio';
8884: if ($numstatustypes) {
8885: $elements{$role.'_status'} = 'checkbox';
8886: }
8887: if (keys(%domhelpdesk) > 0) {
8888: $elements{$role.'_staff_inc'} = 'checkbox';
8889: $elements{$role.'_staff_exc'} = 'checkbox';
8890: }
1.430 raeburn 8891: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 8892: if (ref($settings{$role}) eq 'HASH') {
8893: if ($settings{$role}{'access'} ne '') {
8894: my $curraccess = $settings{$role}{'access'};
8895: $stored{$role.'_access'} = $curraccess;
8896: $stored{$role.'_incrs'} = 1;
8897: if ($curraccess eq 'status') {
8898: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
8899: $stored{$role.'_status'} = $settings{$role}{'status'};
8900: }
8901: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8902: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
8903: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
8904: }
8905: }
8906: } else {
8907: $stored{$role.'_incrs'} = 0;
8908: }
8909: $stored{$role.'_override'} = [];
8910: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
8911: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
8912: foreach my $priv (@{$settings{$role}{'off'}}) {
8913: push(@{$stored{$role.'_override'}},$priv);
8914: }
8915: }
8916: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
8917: foreach my $priv (@{$settings{$role}{'on'}}) {
8918: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
8919: push(@{$stored{$role.'_override'}},$priv);
8920: }
8921: }
8922: }
8923: }
8924: } else {
8925: $stored{$role.'_incrs'} = 0;
8926: }
8927: }
8928: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
8929: }
8930:
8931: my $js = <<"ENDJS";
8932: <script type="text/javascript">
8933: // <![CDATA[
8934: $jscript;
8935:
8936: function switchRoleTab(caller,role) {
8937: if (document.getElementById(role+'_maindiv')) {
8938: if (caller.id != 'LC_current_minitab') {
8939: if (document.getElementById('LC_current_minitab')) {
8940: document.getElementById('LC_current_minitab').id=null;
8941: }
8942: var roledivs = Array('$rolestr');
8943: if (roledivs.length > 0) {
8944: for (var i=0; i<roledivs.length; i++) {
8945: if (document.getElementById(roledivs[i]+'_maindiv')) {
8946: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
8947: }
8948: }
8949: }
8950: caller.id = 'LC_current_minitab';
8951: document.getElementById(role+'_maindiv').style.display='block';
8952: }
8953: }
8954: return false;
1.430 raeburn 8955: }
1.428 raeburn 8956:
8957: function helpdeskAccess(role) {
8958: var curraccess = null;
8959: if (document.$formname.elements[role+'_access'].length) {
8960: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
8961: if (document.$formname.elements[role+'_access'][i].checked) {
8962: curraccess = document.$formname.elements[role+'_access'][i].value;
8963: }
8964: }
8965: }
8966: var shown = Array();
8967: var hidden = Array();
8968: if (curraccess == 'none') {
1.430 raeburn 8969: hidden = Array ('$hiddenstr');
1.428 raeburn 8970: } else {
8971: if (curraccess == 'status') {
1.430 raeburn 8972: shown = Array ('bystatus','privs');
8973: hidden = Array ('notinc','notexc');
1.428 raeburn 8974: } else {
8975: if (curraccess == 'exc') {
8976: shown = Array ('notexc','privs');
8977: hidden = Array ('notinc','bystatus');
8978: }
8979: if (curraccess == 'inc') {
8980: shown = Array ('notinc','privs');
8981: hidden = Array ('notexc','bystatus');
8982: }
8983: if (curraccess == 'all') {
8984: shown = Array ('privs');
8985: hidden = Array ('notinc','notexc','bystatus');
8986: }
8987: }
8988: }
8989: if (hidden.length > 0) {
8990: for (var i=0; i<hidden.length; i++) {
8991: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 8992: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 8993: }
8994: }
8995: }
8996: if (shown.length > 0) {
8997: for (var i=0; i<shown.length; i++) {
8998: if (document.getElementById(role+'_'+shown[i])) {
8999: if (shown[i] == 'privs') {
9000: document.getElementById(role+'_'+shown[i]).style.display = 'block';
9001: } else {
9002: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
9003: }
9004: }
9005: }
9006: }
9007: return;
9008: }
9009:
9010: function toggleAccess(role) {
9011: if ((document.getElementById(role+'_setincrs')) &&
9012: (document.getElementById(role+'_setindom'))) {
9013: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
9014: if (document.$formname.elements[role+'_incrs'][i].checked) {
9015: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
9016: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 9017: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 9018: } else {
9019: document.getElementById(role+'_setincrs').style.display = 'none';
9020: document.getElementById(role+'_setindom').style.display = 'block';
9021: }
9022: break;
9023: }
9024: }
9025: }
9026: return;
9027: }
9028:
9029: // ]]>
9030: </script>
9031: ENDJS
9032:
9033: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
9034:
9035: # print page header
9036: $r->print(&header($js,$args));
9037: # print form header
9038: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
9039:
9040: if (keys(%customroles)) {
9041: my %lt = &Apache::lonlocal::texthash(
9042: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
9043: 'rou' => 'Role usage',
9044: 'whi' => 'Which helpdesk personnel may use this role?',
9045: 'udd' => 'Use domain default',
1.433 raeburn 9046: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 9047: 'dh' => 'All with domain helpdesk role',
9048: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 9049: 'none' => 'None',
9050: 'status' => 'Determined based on institutional status',
1.430 raeburn 9051: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 9052: 'exc' => 'Exclude all, but include specific personnel',
9053: 'hel' => 'Helpdesk',
9054: 'rpr' => 'Role privileges',
9055: );
9056: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
9057: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
9058: my (%domcurrent,%ordered,%description,%domusage,$disabled);
9059: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9060: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
9061: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
9062: }
9063: }
9064: my $count = 0;
9065: foreach my $role (sort(keys(%customroles))) {
9066: my ($order,$desc,$access_in_dom);
9067: if (ref($domcurrent{$role}) eq 'HASH') {
9068: $order = $domcurrent{$role}{'order'};
9069: $desc = $domcurrent{$role}{'desc'};
9070: $access_in_dom = $domcurrent{$role}{'access'};
9071: }
9072: if ($order eq '') {
9073: $order = $count;
9074: }
9075: $ordered{$order} = $role;
9076: if ($desc ne '') {
9077: $description{$role} = $desc;
9078: } else {
9079: $description{$role}= $role;
9080: }
9081: $count++;
9082: }
9083: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
9084: my @roles_by_num = ();
9085: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
9086: push(@roles_by_num,$ordered{$item});
1.430 raeburn 9087: }
1.429 raeburn 9088: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 9089: if ($permission->{'owner'}) {
9090: $r->print('<br />'.$lt{'aco'}.'</p><p>');
9091: $r->print('<input type="hidden" name="state" value="process" />'.
9092: '<input type="submit" value="'.&mt('Save changes').'" />');
9093: } else {
9094: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
9095: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
9096: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
9097: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
9098: }
9099: $disabled = ' disabled="disabled"';
9100: }
9101: $r->print('</p>');
9102:
9103: $r->print('<div id="LC_minitab_header"><ul>');
9104: my $count = 0;
9105: my %visibility;
9106: foreach my $role (@roles_by_num) {
9107: my $id;
9108: if ($count == 0) {
9109: $id=' id="LC_current_minitab"';
1.430 raeburn 9110: $visibility{$role} = ' style="display:block"';
1.428 raeburn 9111: } else {
9112: $visibility{$role} = ' style="display:none"';
9113: }
9114: $count ++;
9115: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
9116: }
9117: $r->print('</ul></div>');
9118:
9119: foreach my $role (@roles_by_num) {
9120: my %usecheck = (
9121: all => ' checked="checked"',
9122: );
9123: my %displaydiv = (
9124: status => 'none',
9125: inc => 'none',
9126: exc => 'none',
9127: priv => 'block',
9128: );
9129: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 9130: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 9131: if ($settings{$role}{'access'} ne '') {
9132: $indomvis = ' style="display:none"';
9133: $incrsvis = ' style="display:block"';
1.430 raeburn 9134: $incrscheck = ' checked="checked"';
1.428 raeburn 9135: if ($settings{$role}{'access'} ne 'all') {
9136: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
9137: delete($usecheck{'all'});
9138: if ($settings{$role}{'access'} eq 'status') {
9139: my $access = 'status';
9140: $displaydiv{$access} = 'inline';
9141: if (ref($settings{$role}{$access}) eq 'ARRAY') {
9142: $selected{$access} = $settings{$role}{$access};
9143: }
9144: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
9145: my $access = $1;
9146: $displaydiv{$access} = 'inline';
9147: if (ref($settings{$role}{$access}) eq 'ARRAY') {
9148: $selected{$access} = $settings{$role}{$access};
9149: }
9150: } elsif ($settings{$role}{'access'} eq 'none') {
9151: $displaydiv{'priv'} = 'none';
9152: }
9153: }
9154: } else {
9155: $indomcheck = ' checked="checked"';
9156: $indomvis = ' style="display:block"';
9157: $incrsvis = ' style="display:none"';
9158: }
9159: } else {
9160: $indomcheck = ' checked="checked"';
1.430 raeburn 9161: $indomvis = ' style="display:block"';
1.428 raeburn 9162: $incrsvis = ' style="display:none"';
9163: }
9164: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
9165: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
9166: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
9167: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
9168: &mt('Set here in [_1]',lc($crstype)).'</label>'.
9169: '<span>'.(' 'x2).
9170: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
9171: $lt{'udd'}.'</label><span></p>'.
9172: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
9173: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
9174: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
9175: foreach my $access (@accesstypes) {
9176: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
9177: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
9178: if ($access eq 'status') {
9179: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
9180: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
9181: $othertitle,$usertypes,$types,$disabled).
9182: '</div>');
9183: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
9184: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
9185: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
9186: \%domhelpdesk,$disabled).
9187: '</div>');
9188: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
9189: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
9190: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
9191: \%domhelpdesk,$disabled).
9192: '</div>');
9193: }
9194: $r->print('</p>');
9195: }
9196: $r->print('</div></fieldset>');
9197: my %full=();
9198: my %levels= (
9199: course => {},
9200: domain => {},
9201: system => {},
9202: );
9203: my %levelscurrent=(
9204: course => {},
9205: domain => {},
9206: system => {},
9207: );
9208: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
9209: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
9210: '<legend>'.$lt{'rpr'}.'</legend>'.
9211: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
9212: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
9213: }
1.429 raeburn 9214: if ($permission->{'owner'}) {
9215: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
9216: }
1.428 raeburn 9217: } else {
9218: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
9219: }
9220: # Form Footer
9221: $r->print('<input type="hidden" name="action" value="helpdesk" />'
9222: .'</form>');
9223: return;
9224: }
9225:
1.465 raeburn 9226: sub print_queued_roles {
9227: my ($r,$context,$permission,$brcrum) = @_;
9228: push (@{$brcrum},
9229: {href => '/adm/createuser?action=rolerequests',
9230: text => 'Role Requests (other domains)',
9231: help => ''});
9232: my $bread_crumbs_component = 'Role Requests';
9233: my $args = { bread_crumbs => $brcrum,
9234: bread_crumbs_component => $bread_crumbs_component};
9235: # print page header
9236: $r->print(&header('',$args));
9237: my ($dom,$cnum);
9238: $dom = $env{'request.role.domain'};
9239: if ($context eq 'course') {
9240: if ($env{'request.course.id'}) {
9241: if (&Apache::loncommon::course_type() eq 'Community') {
9242: $context = 'community';
9243: }
9244: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9245: }
9246: } elsif ($context eq 'author') {
9247: $cnum = $env{'user.name'};
9248: }
9249: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('othdomqueue',$dom,$cnum,$context));
9250: return;
9251: }
9252:
9253: sub print_pendingroles {
9254: my ($r,$context,$permission,$brcrum) = @_;
9255: push (@{$brcrum},
9256: {href => '/adm/createuser?action=queuedroles',
9257: text => 'Queued Role Assignments (users in this domain)',
9258: help => ''});
9259: my $bread_crumbs_component = 'Queued Role Assignments';
9260: my $args = { bread_crumbs => $brcrum,
9261: bread_crumbs_component => $bread_crumbs_component};
9262: # print page header
9263: $r->print(&header('',$args));
9264: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('othdomaction',$env{'request.role.domain'},'','domain'));
9265: return;
9266: }
9267:
9268: sub process_pendingroles {
9269: my ($r,$context,$permission,$brcrum) = @_;
9270: push (@{$brcrum},
9271: {href => '/adm/createuser?action=queuedroles',
9272: text => 'Queued Role Assignments (users in this domain)',
9273: help => ''},
9274: {href => '/adm/createuser?action=processrolereq',
9275: text => 'Process Queue',
9276: help => ''});
9277: my $bread_crumbs_component = 'Queued Role Assignments';
9278: my $args = { bread_crumbs => $brcrum,
9279: bread_crumbs_component => $bread_crumbs_component};
9280: # print page header
9281: $r->print(&header('',$args));
9282: $r->print(&Apache::loncoursequeueadmin::update_request_queue('othdombydc',
9283: $env{'request.role.domain'}));
9284: return;
9285: }
9286:
1.428 raeburn 9287: sub domain_adhoc_access {
9288: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
9289: my %domusage;
9290: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
9291: foreach my $role (keys(%{$roles})) {
9292: if (ref($domcurrent->{$role}) eq 'HASH') {
9293: my $access = $domcurrent->{$role}{'access'};
9294: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
9295: $access = 'all';
1.432 raeburn 9296: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
9297: &Apache::lonnet::plaintext('da'));
1.428 raeburn 9298: } elsif ($access eq 'status') {
9299: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
9300: my @shown;
9301: foreach my $type (@{$domcurrent->{$role}{$access}}) {
9302: unless ($type eq 'default') {
9303: if ($usertypes->{$type}) {
9304: push(@shown,$usertypes->{$type});
9305: }
9306: }
9307: }
9308: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
9309: push(@shown,$othertitle);
9310: }
9311: if (@shown) {
9312: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 9313: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
9314: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 9315: } else {
9316: $domusage{$role} = &mt('No one in the domain');
9317: }
9318: }
9319: } elsif ($access eq 'inc') {
9320: my @dominc = ();
9321: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
9322: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
9323: my ($uname,$udom) = split(/:/,$user);
9324: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
9325: }
9326: my $showninc = join(', ',@dominc);
9327: if ($showninc ne '') {
1.432 raeburn 9328: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
9329: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 9330: } else {
1.432 raeburn 9331: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
9332: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 9333: }
9334: }
9335: } elsif ($access eq 'exc') {
9336: my @domexc = ();
9337: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
9338: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
9339: my ($uname,$udom) = split(/:/,$user);
9340: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
9341: }
9342: }
9343: my $shownexc = join(', ',@domexc);
9344: if ($shownexc ne '') {
1.432 raeburn 9345: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
9346: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 9347: } else {
9348: $domusage{$role} = &mt('No one in the domain');
9349: }
9350: } elsif ($access eq 'none') {
9351: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 9352: } elsif ($access eq 'dh') {
1.433 raeburn 9353: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 9354: } elsif ($access eq 'da') {
1.433 raeburn 9355: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 9356: } elsif ($access eq 'all') {
1.432 raeburn 9357: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
9358: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 9359: }
9360: } else {
1.432 raeburn 9361: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
9362: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 9363: }
9364: }
9365: return %domusage;
9366: }
9367:
9368: sub get_domain_customroles {
9369: my ($cdom,$confname) = @_;
9370: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
9371: my %customroles;
9372: foreach my $key (keys(%existing)) {
9373: if ($key=~/^rolesdef\_(\w+)$/) {
9374: my $rolename = $1;
9375: my %privs;
9376: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
9377: $customroles{$rolename} = \%privs;
9378: }
9379: }
9380: return %customroles;
9381: }
9382:
9383: sub role_priv_table {
9384: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
9385: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
9386: (ref($levelscurrent) eq 'HASH'));
9387: my %lt=&Apache::lonlocal::texthash (
9388: 'crl' => 'Course Level Privilege',
9389: 'def' => 'Domain Defaults',
9390: 'ove' => 'Override in Course',
9391: 'ine' => 'In effect',
9392: 'dis' => 'Disabled',
9393: 'ena' => 'Enabled',
9394: );
9395: if ($crstype eq 'Community') {
9396: $lt{'ove'} = 'Override in Community',
9397: }
9398: my @status = ('Disabled','Enabled');
9399: my (%on,%off);
9400: if (ref($overridden) eq 'HASH') {
9401: if (ref($overridden->{'on'}) eq 'ARRAY') {
9402: map { $on{$_} = 1; } (@{$overridden->{'on'}});
9403: }
9404: if (ref($overridden->{'off'}) eq 'ARRAY') {
9405: map { $off{$_} = 1; } (@{$overridden->{'off'}});
9406: }
9407: }
9408: my $output=&Apache::loncommon::start_data_table().
9409: &Apache::loncommon::start_data_table_header_row().
9410: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
9411: '</th><th>'.$lt{'ine'}.'</th>'.
9412: &Apache::loncommon::end_data_table_header_row();
9413: foreach my $priv (sort(keys(%{$full}))) {
9414: next unless ($levels->{'course'}{$priv});
9415: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
9416: my ($default,$ineffect);
9417: if ($levelscurrent->{'course'}{$priv}) {
9418: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
9419: $ineffect = $default;
9420: }
9421: my ($customstatus,$checked);
9422: $output .= &Apache::loncommon::start_data_table_row().
9423: '<td>'.$privtext.'</td>'.
9424: '<td>'.$default.'</td><td>';
9425: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
9426: if ($permission->{'owner'}) {
9427: $checked = ' checked="checked"';
9428: }
9429: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 9430: $ineffect = $customstatus;
1.428 raeburn 9431: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
9432: if ($permission->{'owner'}) {
1.430 raeburn 9433: $checked = ' checked="checked"';
1.428 raeburn 9434: }
9435: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 9436: $ineffect = $customstatus;
1.428 raeburn 9437: }
9438: if ($permission->{'owner'}) {
9439: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
9440: } else {
9441: $output .= $customstatus;
9442: }
9443: $output .= '</td><td>'.$ineffect.'</td>'.
9444: &Apache::loncommon::end_data_table_row();
9445: }
9446: $output .= &Apache::loncommon::end_data_table();
9447: return $output;
9448: }
9449:
9450: sub get_adhocrole_settings {
1.430 raeburn 9451: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 9452: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
9453: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
9454: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
9455: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
9456: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
9457: $settings->{$role}{'access'} = $curraccess;
9458: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
9459: my @status = split(/,/,$rest);
9460: my @currstatus;
9461: foreach my $type (@status) {
9462: if ($type eq 'default') {
9463: push(@currstatus,$type);
9464: } elsif (grep(/^\Q$type\E$/,@{$types})) {
9465: push(@currstatus,$type);
9466: }
9467: }
9468: if (@currstatus) {
9469: $settings->{$role}{$curraccess} = \@currstatus;
9470: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
9471: my @personnel = split(/,/,$rest);
9472: $settings->{$role}{$curraccess} = \@personnel;
9473: }
9474: }
9475: }
9476: }
9477: foreach my $role (keys(%{$customroles})) {
9478: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
9479: my %currentprivs;
9480: if (ref($customroles->{$role}) eq 'HASH') {
9481: if (exists($customroles->{$role}{'course'})) {
9482: my %full=();
9483: my %levels= (
9484: course => {},
9485: domain => {},
9486: system => {},
9487: );
9488: my %levelscurrent=(
9489: course => {},
9490: domain => {},
9491: system => {},
9492: );
9493: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
9494: %currentprivs = %{$levelscurrent{'course'}};
9495: }
9496: }
9497: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
9498: next if ($item eq '');
9499: my ($rule,$rest) = split(/=/,$item);
9500: next unless (($rule eq 'off') || ($rule eq 'on'));
9501: foreach my $priv (split(/:/,$rest)) {
9502: if ($priv ne '') {
9503: if ($rule eq 'off') {
9504: push(@{$overridden->{$role}{'off'}},$priv);
9505: if ($currentprivs{$priv}) {
9506: push(@{$settings->{$role}{'off'}},$priv);
9507: }
9508: } else {
9509: push(@{$overridden->{$role}{'on'}},$priv);
9510: unless ($currentprivs{$priv}) {
9511: push(@{$settings->{$role}{'on'}},$priv);
9512: }
9513: }
9514: }
9515: }
9516: }
9517: }
9518: }
9519: return;
9520: }
9521:
9522: sub update_helpdeskaccess {
9523: my ($r,$permission,$brcrum) = @_;
9524: my $helpitem = 'Course_Helpdesk_Access';
9525: push (@{$brcrum},
9526: {href => '/adm/createuser?action=helpdesk',
9527: text => 'Helpdesk Access',
9528: help => $helpitem},
9529: {href => '/adm/createuser?action=helpdesk',
9530: text => 'Result',
9531: help => $helpitem}
9532: );
9533: my $bread_crumbs_component = 'Helpdesk Staff Access';
9534: my $args = { bread_crumbs => $brcrum,
9535: bread_crumbs_component => $bread_crumbs_component};
9536:
9537: # print page header
9538: $r->print(&header('',$args));
9539: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
9540: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
9541: return;
9542: }
1.434 raeburn 9543: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 9544: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9545: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9546: my $confname = $cdom.'-domainconfig';
9547: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
9548: my $crstype = &Apache::loncommon::course_type();
9549: my %customroles = &get_domain_customroles($cdom,$confname);
9550: my (%settings,%overridden);
9551: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
9552: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 9553: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 9554: my (%changed,%storehash,@todelete);
9555:
9556: if (keys(%customroles)) {
9557: my (%newsettings,@incrs);
9558: foreach my $role (keys(%customroles)) {
9559: $newsettings{$role} = {
9560: access => '',
9561: status => '',
9562: exc => '',
9563: inc => '',
9564: on => '',
9565: off => '',
9566: };
9567: my %current;
9568: if (ref($settings{$role}) eq 'HASH') {
9569: %current = %{$settings{$role}};
9570: }
9571: if (ref($overridden{$role}) eq 'HASH') {
9572: $current{'overridden'} = $overridden{$role};
9573: }
9574: if ($env{'form.'.$role.'_incrs'}) {
9575: my $access = $env{'form.'.$role.'_access'};
9576: if (grep(/^\Q$access\E$/,@accesstypes)) {
9577: push(@incrs,$role);
9578: unless ($current{'access'} eq $access) {
9579: $changed{$role}{'access'} = 1;
1.430 raeburn 9580: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 9581: }
9582: if ($access eq 'status') {
9583: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
9584: my @stored;
9585: my @shownstatus;
9586: if (ref($types) eq 'ARRAY') {
9587: foreach my $type (sort(@statuses)) {
9588: if ($type eq 'default') {
9589: push(@stored,$type);
9590: } elsif (grep(/^\Q$type\E$/,@{$types})) {
9591: push(@stored,$type);
9592: push(@shownstatus,$usertypes->{$type});
9593: }
9594: }
9595: if (grep(/^default$/,@statuses)) {
9596: push(@shownstatus,$othertitle);
9597: }
9598: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
9599: }
9600: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
9601: if (ref($current{'status'}) eq 'ARRAY') {
9602: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
9603: if (@diffs) {
9604: $changed{$role}{'status'} = 1;
9605: }
9606: } elsif (@stored) {
9607: $changed{$role}{'status'} = 1;
9608: }
9609: } elsif (($access eq 'inc') || ($access eq 'exc')) {
9610: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
9611: my @newspecstaff;
9612: my @stored;
9613: my @currstaff;
9614: foreach my $person (sort(@personnel)) {
9615: if ($domhelpdesk{$person}) {
1.430 raeburn 9616: push(@stored,$person);
1.428 raeburn 9617: }
9618: }
9619: if (ref($current{$access}) eq 'ARRAY') {
9620: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
9621: if (@diffs) {
9622: $changed{$role}{$access} = 1;
9623: }
9624: } elsif (@stored) {
9625: $changed{$role}{$access} = 1;
9626: }
9627: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
9628: foreach my $person (@stored) {
9629: my ($uname,$udom) = split(/:/,$person);
9630: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
9631: }
9632: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
9633: }
9634: $newsettings{$role}{'access'} = $access;
9635: }
9636: } else {
9637: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
9638: $changed{$role}{'access'} = 1;
9639: $newsettings{$role} = {};
9640: push(@todelete,'internal.adhoc.'.$role);
9641: }
9642: }
9643: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
9644: if (ref($current{'overridden'}) eq 'HASH') {
9645: push(@todelete,'internal.adhocpriv.'.$role);
9646: }
9647: } else {
9648: my %full=();
9649: my %levels= (
9650: course => {},
9651: domain => {},
9652: system => {},
9653: );
9654: my %levelscurrent=(
9655: course => {},
9656: domain => {},
9657: system => {},
9658: );
9659: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
9660: my (@updatedon,@updatedoff,@override);
9661: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 9662: if (@override) {
1.428 raeburn 9663: foreach my $priv (sort(keys(%full))) {
9664: next unless ($levels{'course'}{$priv});
9665: if (grep(/^\Q$priv\E$/,@override)) {
9666: if ($levelscurrent{'course'}{$priv}) {
9667: push(@updatedoff,$priv);
9668: } else {
9669: push(@updatedon,$priv);
9670: }
9671: }
9672: }
9673: }
9674: if (@updatedon) {
1.430 raeburn 9675: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 9676: }
9677: if (@updatedoff) {
9678: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
9679: }
9680: if (ref($current{'overridden'}) eq 'HASH') {
9681: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
9682: if (@updatedon) {
9683: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
9684: if (@diffs) {
9685: $changed{$role}{'on'} = 1;
9686: }
9687: } else {
9688: $changed{$role}{'on'} = 1;
9689: }
9690: } elsif (@updatedon) {
9691: $changed{$role}{'on'} = 1;
9692: }
9693: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
9694: if (@updatedoff) {
9695: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
9696: if (@diffs) {
9697: $changed{$role}{'off'} = 1;
9698: }
9699: } else {
9700: $changed{$role}{'off'} = 1;
9701: }
9702: } elsif (@updatedoff) {
9703: $changed{$role}{'off'} = 1;
9704: }
9705: } else {
9706: if (@updatedon) {
9707: $changed{$role}{'on'} = 1;
9708: }
9709: if (@updatedoff) {
9710: $changed{$role}{'off'} = 1;
9711: }
9712: }
9713: if (ref($changed{$role}) eq 'HASH') {
9714: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
9715: my $newpriv;
9716: if (@updatedon) {
9717: $newpriv = 'on='.join(':',@updatedon);
9718: }
9719: if (@updatedoff) {
9720: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
9721: }
9722: if ($newpriv eq '') {
9723: push(@todelete,'internal.adhocpriv.'.$role);
9724: } else {
9725: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
9726: }
9727: }
9728: }
9729: }
9730: }
9731: if (@incrs) {
9732: $storehash{'internal.adhocaccess'} = join(',',@incrs);
9733: } elsif (@todelete) {
9734: push(@todelete,'internal.adhocaccess');
9735: }
9736: if (keys(%changed)) {
9737: my ($putres,$delres);
9738: if (keys(%storehash)) {
9739: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
9740: my %newenvhash;
9741: foreach my $key (keys(%storehash)) {
9742: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
9743: }
9744: &Apache::lonnet::appenv(\%newenvhash);
9745: }
9746: if (@todelete) {
9747: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
9748: foreach my $key (@todelete) {
9749: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
9750: }
9751: }
9752: if (($putres eq 'ok') || ($delres eq 'ok')) {
9753: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
9754: my (%domcurrent,%ordered,%description,%domusage);
9755: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9756: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
9757: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
9758: }
9759: }
9760: my $count = 0;
9761: foreach my $role (sort(keys(%customroles))) {
9762: my ($order,$desc);
9763: if (ref($domcurrent{$role}) eq 'HASH') {
9764: $order = $domcurrent{$role}{'order'};
9765: $desc = $domcurrent{$role}{'desc'};
9766: }
9767: if ($order eq '') {
9768: $order = $count;
9769: }
9770: $ordered{$order} = $role;
9771: if ($desc ne '') {
9772: $description{$role} = $desc;
9773: } else {
9774: $description{$role}= $role;
9775: }
9776: $count++;
9777: }
9778: my @roles_by_num = ();
9779: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
9780: push(@roles_by_num,$ordered{$item});
9781: }
9782: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 9783: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 9784: $r->print('<ul>');
9785: foreach my $role (@roles_by_num) {
9786: next unless (ref($changed{$role}) eq 'HASH');
9787: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
9788: '<ul>');
1.430 raeburn 9789: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 9790: $r->print('<li>');
9791: if ($env{'form.'.$role.'_incrs'}) {
9792: if ($newsettings{$role}{'access'} eq 'all') {
9793: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 9794: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 9795: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
9796: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 9797: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 9798: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
9799: &Apache::lonnet::plaintext('da')));
1.428 raeburn 9800: } elsif ($newsettings{$role}{'access'} eq 'none') {
9801: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9802: } elsif ($newsettings{$role}{'access'} eq 'status') {
9803: if ($newsettings{$role}{'status'}) {
9804: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 9805: if (split(/,/,$rest) > 1) {
1.428 raeburn 9806: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
9807: $newsettings{$role}{'status'}));
9808: } else {
9809: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
9810: $newsettings{$role}{'status'}));
9811: }
9812: } else {
9813: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9814: }
9815: } elsif ($newsettings{$role}{'access'} eq 'exc') {
9816: if ($newsettings{$role}{'exc'}) {
9817: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
9818: } else {
9819: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9820: }
9821: } elsif ($newsettings{$role}{'access'} eq 'inc') {
9822: if ($newsettings{$role}{'inc'}) {
9823: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
9824: } else {
9825: $r->print(&mt('All helpdesk staff may use this role.'));
9826: }
9827: }
9828: } else {
9829: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
9830: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
9831: }
9832: $r->print('</li>');
9833: }
9834: unless ($newsettings{$role}{'access'} eq 'none') {
9835: if ($changed{$role}{'off'}) {
9836: if ($newsettings{$role}{'off'}) {
9837: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
9838: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
9839: } else {
1.430 raeburn 9840: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 9841: }
9842: }
1.430 raeburn 9843: if ($changed{$role}{'on'}) {
1.428 raeburn 9844: if ($newsettings{$role}{'on'}) {
9845: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
9846: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
9847: } else {
1.430 raeburn 9848: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 9849: }
9850: }
9851: }
9852: $r->print('</ul></li>');
9853: }
9854: $r->print('</ul>');
9855: }
9856: } else {
1.430 raeburn 9857: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 9858: }
9859: }
9860: return;
9861: }
9862:
1.27 matthew 9863: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 9864: sub user_search_result {
1.221 raeburn 9865: my ($context,$srch) = @_;
1.160 raeburn 9866: my %allhomes;
9867: my %inst_matches;
9868: my %srch_results;
1.181 raeburn 9869: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 9870: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 9871: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 9872: $response = &mt('Invalid search.');
9873: }
9874: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
9875: $response = &mt('Invalid search.');
9876: }
1.177 raeburn 9877: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 9878: $response = &mt('Invalid search.');
9879: }
9880: if ($srch->{'srchterm'} eq '') {
9881: $response = &mt('You must enter a search term.');
9882: }
1.183 raeburn 9883: if ($srch->{'srchterm'} =~ /^\s+$/) {
9884: $response = &mt('Your search term must contain more than just spaces.');
9885: }
1.160 raeburn 9886: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
9887: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 9888: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 9889: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
9890: }
9891: }
9892: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
9893: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 9894: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 9895: my $unamecheck = $srch->{'srchterm'};
9896: if ($srch->{'srchtype'} eq 'contains') {
9897: if ($unamecheck !~ /^\w/) {
9898: $unamecheck = 'a'.$unamecheck;
9899: }
9900: }
9901: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 9902: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
9903: }
1.160 raeburn 9904: }
9905: }
1.180 raeburn 9906: if ($response ne '') {
1.413 raeburn 9907: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 9908: }
1.160 raeburn 9909: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 9910: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 9911: if ($instd_chk ne 'ok') {
1.412 raeburn 9912: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 9913: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 9914: if ($domd_chk eq 'ok') {
1.435 raeburn 9915: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 9916: }
1.415 raeburn 9917: $response .= '<br />';
1.412 raeburn 9918: }
9919: } else {
1.417 raeburn 9920: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 9921: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 9922: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 9923: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 9924: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 9925: if ($instd_chk eq 'ok') {
1.435 raeburn 9926: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 9927: }
1.415 raeburn 9928: $response .= '<br />';
1.412 raeburn 9929: }
1.160 raeburn 9930: }
9931: }
9932: if ($response ne '') {
1.180 raeburn 9933: return ($currstate,$response);
1.160 raeburn 9934: }
9935: if ($srch->{'srchby'} eq 'uname') {
9936: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
9937: if ($env{'form.forcenew'}) {
9938: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
9939: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
9940: if ($uhome eq 'no_host') {
9941: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 9942: my $showdom = &display_domain_info($env{'request.role.domain'});
9943: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 9944: } else {
1.179 raeburn 9945: $currstate = 'modify';
1.160 raeburn 9946: }
9947: } else {
1.179 raeburn 9948: $currstate = 'modify';
1.160 raeburn 9949: }
9950: } else {
9951: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 9952: if ($srch->{'srchtype'} eq 'exact') {
9953: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
9954: if ($uhome eq 'no_host') {
1.179 raeburn 9955: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9956: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 9957: } else {
1.179 raeburn 9958: $currstate = 'modify';
1.416 raeburn 9959: if ($env{'form.action'} eq 'accesslogs') {
9960: $currstate = 'activity';
9961: }
1.310 raeburn 9962: my $uname = $srch->{'srchterm'};
9963: my $udom = $srch->{'srchdomain'};
9964: $srch_results{$uname.':'.$udom} =
9965: { &Apache::lonnet::get('environment',
9966: ['firstname',
9967: 'lastname',
9968: 'permanentemail'],
9969: $udom,$uname)
9970: };
1.162 raeburn 9971: }
9972: } else {
9973: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 9974: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9975: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9976: }
9977: } else {
1.167 albertel 9978: my $courseusers = &get_courseusers();
1.162 raeburn 9979: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 9980: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 9981: $currstate = 'modify';
1.162 raeburn 9982: } else {
1.179 raeburn 9983: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9984: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 9985: }
1.160 raeburn 9986: } else {
1.167 albertel 9987: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 9988: my ($cuname,$cudomain) = split(/:/,$user);
9989: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 9990: my $matched = 0;
9991: if ($srch->{'srchtype'} eq 'begins') {
9992: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
9993: $matched = 1;
9994: }
9995: } else {
9996: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
9997: $matched = 1;
9998: }
9999: }
10000: if ($matched) {
1.167 albertel 10001: $srch_results{$user} =
10002: {&Apache::lonnet::get('environment',
10003: ['firstname',
10004: 'lastname',
1.194 albertel 10005: 'permanentemail'],
10006: $cudomain,$cuname)};
1.162 raeburn 10007: }
10008: }
10009: }
1.179 raeburn 10010: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10011: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 10012: }
10013: }
10014: }
10015: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 10016: $currstate = 'query';
1.160 raeburn 10017: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 10018: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
10019: if ($dirsrchres eq 'ok') {
10020: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10021: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 10022: } else {
10023: my $showdom = &display_domain_info($srch->{'srchdomain'});
10024: $response = '<span class="LC_warning">'.
10025: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
10026: '</span><br />'.
1.435 raeburn 10027: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 10028: '<br />';
1.181 raeburn 10029: }
1.160 raeburn 10030: }
10031: } else {
10032: if ($srch->{'srchin'} eq 'dom') {
10033: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 10034: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10035: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 10036: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 10037: my $courseusers = &get_courseusers();
10038: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 10039: my ($uname,$udom) = split(/:/,$user);
10040: my %names = &Apache::loncommon::getnames($uname,$udom);
10041: my %emails = &Apache::loncommon::getemails($uname,$udom);
10042: if ($srch->{'srchby'} eq 'lastname') {
10043: if ((($srch->{'srchtype'} eq 'exact') &&
10044: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 10045: (($srch->{'srchtype'} eq 'begins') &&
10046: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 10047: (($srch->{'srchtype'} eq 'contains') &&
10048: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
10049: $srch_results{$user} = {firstname => $names{'firstname'},
10050: lastname => $names{'lastname'},
10051: permanentemail => $emails{'permanentemail'},
10052: };
10053: }
10054: } elsif ($srch->{'srchby'} eq 'lastfirst') {
10055: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 10056: $srchlast =~ s/\s+$//;
10057: $srchfirst =~ s/^\s+//;
1.160 raeburn 10058: if ($srch->{'srchtype'} eq 'exact') {
10059: if (($names{'lastname'} eq $srchlast) &&
10060: ($names{'firstname'} eq $srchfirst)) {
10061: $srch_results{$user} = {firstname => $names{'firstname'},
10062: lastname => $names{'lastname'},
10063: permanentemail => $emails{'permanentemail'},
10064:
10065: };
10066: }
1.177 raeburn 10067: } elsif ($srch->{'srchtype'} eq 'begins') {
10068: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
10069: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
10070: $srch_results{$user} = {firstname => $names{'firstname'},
10071: lastname => $names{'lastname'},
10072: permanentemail => $emails{'permanentemail'},
10073: };
10074: }
10075: } else {
1.160 raeburn 10076: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
10077: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
10078: $srch_results{$user} = {firstname => $names{'firstname'},
10079: lastname => $names{'lastname'},
10080: permanentemail => $emails{'permanentemail'},
10081: };
10082: }
10083: }
10084: }
10085: }
1.179 raeburn 10086: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10087: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 10088: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 10089: $currstate = 'query';
1.160 raeburn 10090: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 10091: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
10092: if ($dirsrchres eq 'ok') {
10093: ($currstate,$response,$forcenewuser) =
1.221 raeburn 10094: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 10095: } else {
1.412 raeburn 10096: my $showdom = &display_domain_info($srch->{'srchdomain'});
10097: $response = '<span class="LC_warning">'.
1.181 raeburn 10098: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
10099: '</span><br />'.
1.435 raeburn 10100: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 10101: '<br />';
1.181 raeburn 10102: }
1.160 raeburn 10103: }
10104: }
1.179 raeburn 10105: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 10106: }
10107:
1.412 raeburn 10108: sub domdirectorysrch_check {
10109: my ($srch) = @_;
10110: my $response;
10111: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
10112: ['directorysrch'],$srch->{'srchdomain'});
10113: my $showdom = &display_domain_info($srch->{'srchdomain'});
10114: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
10115: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
10116: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
10117: }
10118: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
10119: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
10120: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
10121: }
10122: }
10123: }
10124: return 'ok';
10125: }
10126:
10127: sub instdirectorysrch_check {
1.160 raeburn 10128: my ($srch) = @_;
10129: my $can_search = 0;
10130: my $response;
10131: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
10132: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 10133: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 10134: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
10135: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 10136: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 10137: }
10138: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
10139: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 10140: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 10141: }
10142: my @usertypes = split(/:/,$env{'environment.inststatus'});
10143: if (!@usertypes) {
10144: push(@usertypes,'default');
10145: }
10146: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
10147: foreach my $type (@usertypes) {
10148: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
10149: $can_search = 1;
10150: last;
10151: }
10152: }
10153: }
10154: if (!$can_search) {
10155: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
10156: my @longtypes;
10157: foreach my $item (@usertypes) {
1.229 raeburn 10158: if (defined($insttypes->{$item})) {
10159: push (@longtypes,$insttypes->{$item});
10160: } elsif ($item eq 'default') {
10161: push (@longtypes,&mt('other'));
10162: }
1.160 raeburn 10163: }
10164: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 10165: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 10166: }
1.160 raeburn 10167: } else {
10168: $can_search = 1;
10169: }
10170: } else {
1.180 raeburn 10171: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 10172: }
10173: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 10174: uname => 'username',
1.160 raeburn 10175: lastfirst => 'last name, first name',
1.167 albertel 10176: lastname => 'last name',
1.172 raeburn 10177: contains => 'contains',
1.178 raeburn 10178: exact => 'as exact match to',
10179: begins => 'begins with',
1.160 raeburn 10180: );
10181: if ($can_search) {
10182: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
10183: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 10184: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 10185: }
10186: } else {
1.180 raeburn 10187: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 10188: }
10189: }
10190: if ($can_search) {
1.178 raeburn 10191: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
10192: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
10193: return 'ok';
10194: } else {
1.180 raeburn 10195: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 10196: }
10197: } else {
10198: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
10199: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
10200: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
10201: return 'ok';
10202: } else {
1.180 raeburn 10203: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 10204: }
1.160 raeburn 10205: }
10206: }
10207: }
10208:
10209: sub get_courseusers {
10210: my %advhash;
1.167 albertel 10211: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 10212: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
10213: foreach my $role (sort(keys(%coursepersonnel))) {
10214: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 10215: if (!exists($classlist->{$user})) {
10216: $classlist->{$user} = [];
10217: }
1.160 raeburn 10218: }
10219: }
1.167 albertel 10220: return $classlist;
1.160 raeburn 10221: }
10222:
10223: sub build_search_response {
1.221 raeburn 10224: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 10225: my ($currstate,$response,$forcenewuser);
1.160 raeburn 10226: my %names = (
1.330 bisitz 10227: 'uname' => 'username',
10228: 'lastname' => 'last name',
1.160 raeburn 10229: 'lastfirst' => 'last name, first name',
1.330 bisitz 10230: 'crs' => 'this course',
10231: 'dom' => 'LON-CAPA domain',
10232: 'instd' => 'the institutional directory for domain',
1.160 raeburn 10233: );
10234:
10235: my %single = (
1.180 raeburn 10236: begins => 'A match',
1.160 raeburn 10237: contains => 'A match',
1.180 raeburn 10238: exact => 'An exact match',
1.160 raeburn 10239: );
10240: my %nomatch = (
1.180 raeburn 10241: begins => 'No match',
1.160 raeburn 10242: contains => 'No match',
1.180 raeburn 10243: exact => 'No exact match',
1.160 raeburn 10244: );
10245: if (keys(%srch_results) > 1) {
1.179 raeburn 10246: $currstate = 'select';
1.160 raeburn 10247: } else {
10248: if (keys(%srch_results) == 1) {
1.416 raeburn 10249: if ($env{'form.action'} eq 'accesslogs') {
10250: $currstate = 'activity';
10251: } else {
10252: $currstate = 'modify';
10253: }
1.180 raeburn 10254: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
10255: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 10256: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 10257: }
1.330 bisitz 10258: } else { # Search has nothing found. Prepare message to user.
10259: $response = '<span class="LC_warning">';
1.180 raeburn 10260: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 10261: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
10262: '<b>'.$srch->{'srchterm'}.'</b>',
10263: &display_domain_info($srch->{'srchdomain'}));
10264: } else {
10265: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
10266: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 10267: }
10268: $response .= '</span>';
1.330 bisitz 10269:
1.160 raeburn 10270: if ($srch->{'srchin'} ne 'alc') {
10271: $forcenewuser = 1;
10272: my $cansrchinst = 0;
1.438 raeburn 10273: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 10274: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
10275: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10276: if ($domconfig{'directorysrch'}{'available'}) {
10277: $cansrchinst = 1;
10278: }
10279: }
10280: }
1.180 raeburn 10281: if ((($srch->{'srchby'} eq 'lastfirst') ||
10282: ($srch->{'srchby'} eq 'lastname')) &&
10283: ($srch->{'srchin'} eq 'dom')) {
10284: if ($cansrchinst) {
10285: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 10286: }
10287: }
1.180 raeburn 10288: if ($srch->{'srchin'} eq 'crs') {
10289: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
10290: }
10291: }
1.305 raeburn 10292: my $createdom = $env{'request.role.domain'};
10293: if ($context eq 'requestcrs') {
10294: if ($env{'form.coursedom'} ne '') {
10295: $createdom = $env{'form.coursedom'};
10296: }
10297: }
1.416 raeburn 10298: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
10299: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 10300: my $cancreate =
1.305 raeburn 10301: &Apache::lonuserutils::can_create_user($createdom,$context);
10302: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 10303: if ($cancreate) {
1.305 raeburn 10304: my $showdom = &display_domain_info($createdom);
1.266 bisitz 10305: $response .= '<br /><br />'
10306: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 10307: .'<br />';
10308: if ($context eq 'requestcrs') {
10309: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
10310: } else {
10311: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
10312: }
10313: $response .='<ul><li>'
1.266 bisitz 10314: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
10315: .'</li><li>'
10316: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
10317: .'</li><li>'
10318: .&mt('Provide the proposed username')
10319: .'</li><li>'
10320: .&mt("Click 'Search'")
10321: .'</li></ul><br />';
1.221 raeburn 10322: } else {
1.422 raeburn 10323: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
10324: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
10325: $response .= '<br /><br />';
10326: if ($context eq 'requestcrs') {
10327: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
10328: } else {
10329: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
10330: }
10331: $response .= '<br />'
10332: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
10333: ,' <a'.$helplink.'>'
10334: ,'</a>')
10335: .'<br />';
1.305 raeburn 10336: }
1.221 raeburn 10337: }
1.160 raeburn 10338: }
10339: }
10340: }
1.179 raeburn 10341: return ($currstate,$response,$forcenewuser);
1.160 raeburn 10342: }
10343:
1.180 raeburn 10344: sub display_domain_info {
10345: my ($dom) = @_;
10346: my $output = $dom;
10347: if ($dom ne '') {
10348: my $domdesc = &Apache::lonnet::domain($dom,'description');
10349: if ($domdesc ne '') {
10350: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
10351: }
10352: }
10353: return $output;
10354: }
10355:
1.160 raeburn 10356: sub crumb_utilities {
10357: my %elements = (
10358: crtuser => {
10359: srchterm => 'text',
1.172 raeburn 10360: srchin => 'selectbox',
1.160 raeburn 10361: srchby => 'selectbox',
10362: srchtype => 'selectbox',
10363: srchdomain => 'selectbox',
10364: },
1.207 raeburn 10365: crtusername => {
10366: srchterm => 'text',
10367: srchdomain => 'selectbox',
10368: },
1.160 raeburn 10369: docustom => {
10370: rolename => 'selectbox',
10371: newrolename => 'textbox',
10372: },
1.179 raeburn 10373: studentform => {
10374: srchterm => 'text',
10375: srchin => 'selectbox',
10376: srchby => 'selectbox',
10377: srchtype => 'selectbox',
10378: srchdomain => 'selectbox',
10379: },
1.160 raeburn 10380: );
10381:
10382: my $jsback .= qq|
10383: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 10384: if (typeof prevphase == 'undefined') {
10385: formname.phase.value = '';
10386: }
10387: else {
10388: formname.phase.value = prevphase;
10389: }
10390: if (typeof prevstate == 'undefined') {
10391: formname.currstate.value = '';
10392: }
10393: else {
10394: formname.currstate.value = prevstate;
10395: }
1.160 raeburn 10396: formname.submit();
10397: }
10398: |;
10399: return ($jsback,\%elements);
10400: }
10401:
1.26 matthew 10402: sub course_level_table {
1.375 raeburn 10403: my ($inccourses,$showcredits,$defaultcredits) = @_;
10404: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 10405: my $table = '';
1.62 www 10406: # Custom Roles?
10407:
1.190 raeburn 10408: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 10409: my %lt=&Apache::lonlocal::texthash(
10410: 'exs' => "Existing sections",
10411: 'new' => "Define new section",
10412: 'ssd' => "Set Start Date",
10413: 'sed' => "Set End Date",
1.131 raeburn 10414: 'crl' => "Course Level",
1.89 raeburn 10415: 'act' => "Activate",
10416: 'rol' => "Role",
10417: 'ext' => "Extent",
1.113 raeburn 10418: 'grs' => "Section",
1.375 raeburn 10419: 'crd' => "Credits",
1.89 raeburn 10420: 'sta' => "Start",
10421: 'end' => "End"
10422: );
1.62 www 10423:
1.375 raeburn 10424: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 10425: my $thiscourse=$protectedcourse;
1.26 matthew 10426: $thiscourse=~s:_:/:g;
10427: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 10428: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 10429: my $area=$coursedata{'description'};
1.321 raeburn 10430: my $crstype=$coursedata{'type'};
1.135 raeburn 10431: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 10432: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 10433: my %sections_count;
1.101 albertel 10434: if (defined($env{'request.course.id'})) {
10435: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 10436: %sections_count =
10437: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 10438: }
10439: }
1.321 raeburn 10440: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 10441: foreach my $role (@roles) {
1.321 raeburn 10442: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 10443: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
10444: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 10445: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 10446: $plrole,\%sections_count,\%lt,
1.402 raeburn 10447: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 10448: } elsif ($env{'request.course.sec'} ne '') {
10449: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
10450: $env{'request.course.sec'})) {
10451: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 10452: $plrole,\%sections_count,\%lt,
1.402 raeburn 10453: $showcredits,$defaultcredits,$crstype);
1.26 matthew 10454: }
10455: }
10456: }
1.221 raeburn 10457: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 10458: foreach my $cust (sort(keys(%customroles))) {
10459: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 10460: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
10461: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 10462: $cust,\%sections_count,\%lt,
10463: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 10464: }
1.62 www 10465: }
1.26 matthew 10466: }
10467: return '' if ($table eq ''); # return nothing if there is nothing
10468: # in the table
1.188 raeburn 10469: my $result;
10470: if (!$env{'request.course.id'}) {
10471: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
10472: }
10473: $result .=
1.136 raeburn 10474: &Apache::loncommon::start_data_table().
10475: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 10476: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 10477: '<th>'.$lt{'ext'}.'</th><th>'."\n";
10478: if ($showcredits) {
10479: $result .= $lt{'crd'}.'</th>';
10480: }
10481: $result .=
1.375 raeburn 10482: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
10483: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 10484: &Apache::loncommon::end_data_table_header_row().
10485: $table.
10486: &Apache::loncommon::end_data_table();
1.26 matthew 10487: return $result;
10488: }
1.88 raeburn 10489:
1.221 raeburn 10490: sub course_level_row {
1.375 raeburn 10491: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 10492: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 10493: my $creditem;
1.222 raeburn 10494: my $row = &Apache::loncommon::start_data_table_row().
10495: ' <td><input type="checkbox" name="act_'.
10496: $protectedcourse.'_'.$role.'" /></td>'."\n".
10497: ' <td>'.$plrole.'</td>'."\n".
10498: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 10499: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 10500: $row .=
10501: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
10502: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
10503: } else {
10504: $row .= '<td> </td>';
10505: }
1.322 raeburn 10506: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 10507: $row .= '<td> </td>';
1.221 raeburn 10508: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 10509: $row .= ' <td><input type="hidden" value="'.
10510: $env{'request.course.sec'}.'" '.
10511: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
10512: $env{'request.course.sec'}.'</td>';
1.221 raeburn 10513: } else {
10514: if (ref($sections_count) eq 'HASH') {
10515: my $currsec =
10516: &Apache::lonuserutils::course_sections($sections_count,
10517: $protectedcourse.'_'.$role);
1.222 raeburn 10518: $row .= '<td><table class="LC_createuser">'."\n".
10519: '<tr class="LC_section_row">'."\n".
10520: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
10521: $currsec.'</td>'."\n".
10522: ' <td> </td>'."\n".
10523: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 10524: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
10525: '" value="" />'.
10526: '<input type="hidden" '.
10527: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 10528: '</tr></table></td>'."\n";
1.221 raeburn 10529: } else {
1.222 raeburn 10530: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 10531: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 10532: }
10533: }
1.222 raeburn 10534: $row .= <<ENDTIMEENTRY;
10535: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 10536: <a href=
10537: "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 10538: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 10539: <a href=
10540: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
10541: ENDTIMEENTRY
1.222 raeburn 10542: $row .= &Apache::loncommon::end_data_table_row();
10543: return $row;
1.221 raeburn 10544: }
10545:
1.88 raeburn 10546: sub course_level_dc {
1.375 raeburn 10547: my ($dcdom,$showcredits) = @_;
1.190 raeburn 10548: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 10549: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 10550: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
10551: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 10552: '<input type="hidden" name="dccourse" value="" />';
1.355 www 10553: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 10554: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 10555: my $credit_elem;
10556: if ($showcredits) {
10557: $credit_elem = 'credits';
10558: }
10559: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 10560: my %lt=&Apache::lonlocal::texthash(
10561: 'rol' => "Role",
1.113 raeburn 10562: 'grs' => "Section",
1.88 raeburn 10563: 'exs' => "Existing sections",
10564: 'new' => "Define new section",
10565: 'sta' => "Start",
10566: 'end' => "End",
10567: 'ssd' => "Set Start Date",
1.355 www 10568: 'sed' => "Set End Date",
1.375 raeburn 10569: 'scc' => "Course/Community",
10570: 'crd' => "Credits",
1.88 raeburn 10571: );
1.323 raeburn 10572: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 10573: &Apache::loncommon::start_data_table().
10574: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 10575: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 10576: '<th>'.$lt{'grs'}.'</th>'."\n";
10577: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
10578: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 10579: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 10580: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 10581: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
10582: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 10583: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 10584: foreach my $role (@roles) {
1.135 raeburn 10585: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 10586: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 10587: }
1.404 raeburn 10588: if ( keys(%customroles) > 0) {
10589: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 10590: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 10591: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 10592: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 10593: }
10594: }
10595: $otheritems .= '</select></td><td>'.
10596: '<table border="0" cellspacing="0" cellpadding="0">'.
10597: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 10598: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 10599: '<td> </td>'.
10600: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 10601: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 10602: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 10603: '<input type="hidden" name="groups" value="" />'.
10604: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 10605: '</tr></table></td>'."\n";
10606: if ($showcredits) {
10607: $otheritems .= '<td><br />'."\n".
1.397 bisitz 10608: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 10609: }
1.88 raeburn 10610: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 10611: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 10612: <a href=
10613: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 10614: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 10615: <a href=
10616: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
10617: ENDTIMEENTRY
1.136 raeburn 10618: $otheritems .= &Apache::loncommon::end_data_table_row().
10619: &Apache::loncommon::end_data_table()."\n";
1.470 raeburn 10620: return $cb_jscript.$hiddenitems.$header.$otheritems;
1.88 raeburn 10621: }
10622:
1.237 raeburn 10623: sub update_selfenroll_config {
1.400 raeburn 10624: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 10625: return unless (ref($currsettings) eq 'HASH');
10626: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
10627: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 10628: my (%changes,%warning);
1.241 raeburn 10629: my $curr_types;
1.400 raeburn 10630: my %noedit;
10631: unless ($context eq 'domain') {
10632: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
10633: }
1.237 raeburn 10634: if (ref($row) eq 'ARRAY') {
10635: foreach my $item (@{$row}) {
1.400 raeburn 10636: next if ($noedit{$item});
1.237 raeburn 10637: if ($item eq 'enroll_dates') {
10638: my (%currenrolldate,%newenrolldate);
10639: foreach my $type ('start','end') {
1.398 raeburn 10640: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 10641: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
10642: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
10643: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
10644: }
10645: }
10646: } elsif ($item eq 'access_dates') {
10647: my (%currdate,%newdate);
10648: foreach my $type ('start','end') {
1.398 raeburn 10649: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 10650: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
10651: if ($newdate{$type} ne $currdate{$type}) {
10652: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
10653: }
10654: }
1.241 raeburn 10655: } elsif ($item eq 'types') {
1.398 raeburn 10656: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 10657: if ($env{'form.selfenroll_all'}) {
10658: if ($curr_types ne '*') {
10659: $changes{'internal.selfenroll_types'} = '*';
10660: } else {
10661: next;
10662: }
10663: } else {
1.249 raeburn 10664: my %currdoms;
1.241 raeburn 10665: my @entries = split(/;/,$curr_types);
10666: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 10667: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 10668: my $newnum = 0;
1.249 raeburn 10669: my @latesttypes;
10670: foreach my $num (@activations) {
10671: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
10672: if (@types > 0) {
1.241 raeburn 10673: @types = sort(@types);
10674: my $typestr = join(',',@types);
1.249 raeburn 10675: my $typedom = $env{'form.selfenroll_dom_'.$num};
10676: $latesttypes[$newnum] = $typedom.':'.$typestr;
10677: $currdoms{$typedom} = 1;
1.241 raeburn 10678: $newnum ++;
10679: }
10680: }
1.338 raeburn 10681: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
10682: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 10683: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
10684: if (@types > 0) {
10685: @types = sort(@types);
10686: my $typestr = join(',',@types);
10687: my $typedom = $env{'form.selfenroll_dom_'.$j};
10688: $latesttypes[$newnum] = $typedom.':'.$typestr;
10689: $currdoms{$typedom} = 1;
10690: $newnum ++;
10691: }
10692: }
10693: }
10694: if ($env{'form.selfenroll_newdom'} ne '') {
10695: my $typedom = $env{'form.selfenroll_newdom'};
10696: if ((!defined($currdoms{$typedom})) &&
10697: (&Apache::lonnet::domain($typedom) ne '')) {
10698: my $typestr;
10699: my ($othertitle,$usertypes,$types) =
10700: &Apache::loncommon::sorted_inst_types($typedom);
10701: my $othervalue = 'any';
10702: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
10703: if (@{$types} > 0) {
1.257 raeburn 10704: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 10705: $othervalue = 'other';
1.258 raeburn 10706: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 10707: }
10708: $typestr = $othervalue;
10709: } else {
10710: $typestr = $othervalue;
10711: }
10712: $latesttypes[$newnum] = $typedom.':'.$typestr;
10713: $newnum ++ ;
10714: }
10715: }
1.241 raeburn 10716: my $selfenroll_types = join(';',@latesttypes);
10717: if ($selfenroll_types ne $curr_types) {
10718: $changes{'internal.selfenroll_types'} = $selfenroll_types;
10719: }
10720: }
1.276 raeburn 10721: } elsif ($item eq 'limit') {
10722: my $newlimit = $env{'form.selfenroll_limit'};
10723: my $newcap = $env{'form.selfenroll_cap'};
10724: $newcap =~s/\s+//g;
1.398 raeburn 10725: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 10726: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 10727: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 10728: if ($newlimit ne $currlimit) {
10729: if ($newlimit ne 'none') {
10730: if ($newcap =~ /^\d+$/) {
10731: if ($newcap ne $currcap) {
10732: $changes{'internal.selfenroll_cap'} = $newcap;
10733: }
10734: $changes{'internal.selfenroll_limit'} = $newlimit;
10735: } else {
1.398 raeburn 10736: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
10737: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 10738: }
10739: } elsif ($currcap ne '') {
10740: $changes{'internal.selfenroll_cap'} = '';
10741: $changes{'internal.selfenroll_limit'} = $newlimit;
10742: }
10743: } elsif ($currlimit ne 'none') {
10744: if ($newcap =~ /^\d+$/) {
10745: if ($newcap ne $currcap) {
10746: $changes{'internal.selfenroll_cap'} = $newcap;
10747: }
10748: } else {
1.398 raeburn 10749: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
10750: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 10751: }
10752: }
10753: } elsif ($item eq 'approval') {
10754: my (@currnotified,@newnotified);
1.398 raeburn 10755: my $currapproval = $currsettings->{'selfenroll_approval'};
10756: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 10757: if ($currnotifylist ne '') {
10758: @currnotified = split(/,/,$currnotifylist);
10759: @currnotified = sort(@currnotified);
10760: }
10761: my $newapproval = $env{'form.selfenroll_approval'};
10762: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
10763: @newnotified = sort(@newnotified);
10764: if ($newapproval ne $currapproval) {
10765: $changes{'internal.selfenroll_approval'} = $newapproval;
10766: if (!$newapproval) {
10767: if ($currnotifylist ne '') {
10768: $changes{'internal.selfenroll_notifylist'} = '';
10769: }
10770: } else {
10771: my @differences =
1.295 raeburn 10772: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 10773: if (@differences > 0) {
10774: if (@newnotified > 0) {
10775: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10776: } else {
10777: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10778: }
10779: }
10780: }
10781: } else {
1.295 raeburn 10782: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 10783: if (@differences > 0) {
10784: if (@newnotified > 0) {
10785: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10786: } else {
10787: $changes{'internal.selfenroll_notifylist'} = '';
10788: }
10789: }
10790: }
1.237 raeburn 10791: } else {
1.398 raeburn 10792: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 10793: my $newval = $env{'form.selfenroll_'.$item};
10794: if ($item eq 'section') {
10795: $newval = $env{'form.sections'};
1.241 raeburn 10796: if (defined($curr_groups{$newval})) {
1.237 raeburn 10797: $newval = $curr_val;
1.398 raeburn 10798: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
10799: &mt('Group names and section names must be distinct');
1.237 raeburn 10800: } elsif ($newval eq 'all') {
10801: $newval = $curr_val;
1.274 bisitz 10802: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 10803: }
10804: if ($newval eq '') {
10805: $newval = 'none';
10806: }
10807: }
10808: if ($newval ne $curr_val) {
10809: $changes{'internal.selfenroll_'.$item} = $newval;
10810: }
1.241 raeburn 10811: }
1.237 raeburn 10812: }
10813: if (keys(%warning) > 0) {
10814: foreach my $item (@{$row}) {
10815: if (exists($warning{$item})) {
10816: $r->print($warning{$item}.'<br />');
10817: }
10818: }
10819: }
10820: if (keys(%changes) > 0) {
10821: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
10822: if ($putresult eq 'ok') {
10823: if ((exists($changes{'internal.selfenroll_types'})) ||
10824: (exists($changes{'internal.selfenroll_start_date'})) ||
10825: (exists($changes{'internal.selfenroll_end_date'}))) {
10826: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
10827: $cnum,undef,undef,'Course');
10828: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 10829: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 10830: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
10831: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 10832: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 10833: }
10834: }
10835: my $crsputresult =
10836: &Apache::lonnet::courseidput($cdom,\%crsinfo,
10837: $chome,'notime');
10838: }
10839: }
10840: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
10841: foreach my $item (@{$row}) {
10842: my $title = $item;
10843: if (ref($lt) eq 'HASH') {
10844: $title = $lt->{$item};
10845: }
10846: if ($item eq 'enroll_dates') {
10847: foreach my $type ('start','end') {
10848: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
10849: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 10850: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 10851: $title,$type,$newdate).'</li>');
10852: }
10853: }
10854: } elsif ($item eq 'access_dates') {
10855: foreach my $type ('start','end') {
10856: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
10857: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 10858: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 10859: $title,$type,$newdate).'</li>');
10860: }
10861: }
1.276 raeburn 10862: } elsif ($item eq 'limit') {
10863: if ((exists($changes{'internal.selfenroll_limit'})) ||
10864: (exists($changes{'internal.selfenroll_cap'}))) {
10865: my ($newval,$newcap);
10866: if ($changes{'internal.selfenroll_cap'} ne '') {
10867: $newcap = $changes{'internal.selfenroll_cap'}
10868: } else {
1.398 raeburn 10869: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 10870: }
10871: if ($changes{'internal.selfenroll_limit'} eq 'none') {
10872: $newval = &mt('No limit');
10873: } elsif ($changes{'internal.selfenroll_limit'} eq
10874: 'allstudents') {
10875: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
10876: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
10877: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
10878: } else {
1.398 raeburn 10879: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 10880: if ($currlimit eq 'allstudents') {
10881: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
10882: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 10883: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 10884: }
10885: }
10886: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
10887: }
10888: } elsif ($item eq 'approval') {
10889: if ((exists($changes{'internal.selfenroll_approval'})) ||
10890: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 10891: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 10892: my ($newval,$newnotify);
10893: if (exists($changes{'internal.selfenroll_notifylist'})) {
10894: $newnotify = $changes{'internal.selfenroll_notifylist'};
10895: } else {
1.398 raeburn 10896: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 10897: }
1.398 raeburn 10898: if (exists($changes{'internal.selfenroll_approval'})) {
10899: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
10900: $changes{'internal.selfenroll_approval'} = '0';
10901: }
10902: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 10903: } else {
1.398 raeburn 10904: my $currapproval = $currsettings->{'selfenroll_approval'};
10905: if ($currapproval !~ /^[012]$/) {
10906: $currapproval = 0;
1.276 raeburn 10907: }
1.398 raeburn 10908: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 10909: }
10910: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
10911: if ($newnotify) {
1.277 raeburn 10912: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 10913: } else {
1.277 raeburn 10914: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 10915: }
10916: $r->print('</li>'."\n");
10917: }
1.237 raeburn 10918: } else {
10919: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 10920: my $newval = $changes{'internal.selfenroll_'.$item};
10921: if ($item eq 'types') {
10922: if ($newval eq '') {
10923: $newval = &mt('None');
10924: } elsif ($newval eq '*') {
10925: $newval = &mt('Any user in any domain');
10926: }
1.245 raeburn 10927: } elsif ($item eq 'registered') {
10928: if ($newval eq '1') {
10929: $newval = &mt('Yes');
10930: } elsif ($newval eq '0') {
10931: $newval = &mt('No');
10932: }
1.241 raeburn 10933: }
1.244 bisitz 10934: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 10935: }
10936: }
10937: }
10938: $r->print('</ul>');
1.398 raeburn 10939: if ($env{'course.'.$cid.'.description'} ne '') {
10940: my %newenvhash;
10941: foreach my $key (keys(%changes)) {
10942: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
10943: }
10944: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 10945: }
10946: } else {
1.398 raeburn 10947: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
10948: &mt('The error was: [_1].',$putresult));
1.237 raeburn 10949: }
10950: } else {
1.249 raeburn 10951: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 10952: }
10953: } else {
1.249 raeburn 10954: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 10955: }
1.469 raeburn 10956: my $visactions = &cat_visibility($cdom);
1.400 raeburn 10957: my ($cathash,%cattype);
10958: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
10959: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
10960: $cathash = $domconfig{'coursecategories'}{'cats'};
10961: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
10962: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
10963: } else {
10964: $cathash = {};
10965: $cattype{'auth'} = 'std';
10966: $cattype{'unauth'} = 'std';
10967: }
10968: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
10969: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
10970: '<br />'.
10971: '<br />'.$visactions->{'take'}.'<ul>'.
10972: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
10973: '</ul>');
10974: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
10975: if ($currsettings->{'uniquecode'}) {
10976: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
10977: } else {
1.366 bisitz 10978: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 10979: '<br />'.
10980: '<br />'.$visactions->{'take'}.'<ul>'.
10981: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
10982: '</ul><br />');
10983: }
10984: } else {
10985: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
10986: if (ref($visactions) eq 'HASH') {
10987: if (!$visible) {
10988: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
10989: '<br />');
10990: if (ref($vismsgs) eq 'ARRAY') {
10991: $r->print('<br />'.$visactions->{'take'}.'<ul>');
10992: foreach my $item (@{$vismsgs}) {
10993: $r->print('<li>'.$visactions->{$item}.'</li>');
10994: }
10995: $r->print('</ul>');
1.256 raeburn 10996: }
1.400 raeburn 10997: $r->print($cansetvis);
1.256 raeburn 10998: }
10999: }
11000: }
1.237 raeburn 11001: return;
11002: }
11003:
1.27 matthew 11004: #---------------------------------------------- end functions for &phase_two
1.29 matthew 11005:
11006: #--------------------------------- functions for &phase_two and &phase_three
11007:
11008: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 11009:
1.1 www 11010: 1;
11011: __END__
1.2 www 11012:
11013:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>