Annotation of loncom/interface/loncreateuser.pm, revision 1.406.2.20.2.7
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.406.2.20.2. (raeburn 4:): # $Id: loncreateuser.pm,v 1.406.2.20.2.6 2024/08/24 15:09:55 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.406.2.20.2. (raeburn 73:): use Apache::lonviewcoauthors;
1.139 albertel 74: use LONCAPA qw(:DEFAULT :match);
1.406.2.20 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;
83:
1.94 matthew 84: sub initialize_authen_forms {
1.406.2.20.2. (raeburn 85:): my ($dom,$formname,$curr_authtype,$mode,$readonly) = @_;
1.227 raeburn 86: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
87: my %param = ( formname => $formname,
1.187 raeburn 88: kerb_def_dom => $krbdefdom,
1.227 raeburn 89: kerb_def_auth => $krbdef,
1.187 raeburn 90: domain => $dom,
91: );
1.188 raeburn 92: my %abv_auth = &auth_abbrev();
1.227 raeburn 93: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 94: my $long_auth = $1;
1.227 raeburn 95: my $curr_autharg = $2;
1.188 raeburn 96: my %abv_auth = &auth_abbrev();
97: $param{'curr_authtype'} = $abv_auth{$long_auth};
98: if ($long_auth =~ /^krb(4|5)$/) {
99: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 100: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 101: }
1.205 raeburn 102: if ($mode eq 'modifyuser') {
103: $param{'mode'} = $mode;
104: }
1.187 raeburn 105: }
1.406.2.20.2. (raeburn 106:): if ($readonly) {
107:): $param{'readonly'} = 1;
108:): }
1.227 raeburn 109: $loginscript = &Apache::loncommon::authform_header(%param);
110: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 111: $authformnop = &Apache::loncommon::authform_nochange(%param);
112: $authformint = &Apache::loncommon::authform_internal(%param);
113: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
114: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 115: }
116:
1.188 raeburn 117: sub auth_abbrev {
118: my %abv_auth = (
1.368 raeburn 119: krb5 => 'krb',
120: krb4 => 'krb',
121: internal => 'int',
122: localauth => 'loc',
123: unix => 'fsys',
1.188 raeburn 124: );
125: return %abv_auth;
126: }
1.43 www 127:
1.134 raeburn 128: # ====================================================
129:
1.378 raeburn 130: sub user_quotas {
1.406.2.20.2. (raeburn 131:): my ($ccuname,$ccdomain,$name) = @_;
1.134 raeburn 132: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 133: 'cust' => "Custom quota",
134: 'chqu' => "Change quota",
1.134 raeburn 135: );
1.406.2.20.2. (raeburn 136:): my ($output,$longinsttype);
137:): my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
138:): my %titles = &Apache::lonlocal::texthash (
139:): portfolio => "Disk space allocated to user's portfolio files",
140:): author => "Disk space allocated to user's Authoring Space",
141:): );
142:): my ($currquota,$quotatype,$inststatus,$defquota) =
143:): &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
144:): if ($longinsttype eq '') {
145:): if ($inststatus ne '') {
146:): if ($usertypes->{$inststatus} ne '') {
147:): $longinsttype = $usertypes->{$inststatus};
148:): }
149:): }
150:): }
151:): my ($showquota,$custom_on,$custom_off,$defaultinfo,$colspan);
152:): $custom_on = ' ';
153:): $custom_off = ' checked="checked" ';
154:): $colspan = ' colspan="2"';
155:): if ($quotatype eq 'custom') {
156:): $custom_on = $custom_off;
157:): $custom_off = ' ';
158:): $showquota = $currquota;
159:): if ($longinsttype eq '') {
160:): $defaultinfo = &mt('For this user, the default quota would be [_1]'
161:): .' MB.',$defquota);
162:): } else {
163:): $defaultinfo = &mt("For this user, the default quota would be [_1]".
164:): " MB,[_2]as determined by the user's institutional".
165:): " affiliation ([_3]).",$defquota,'<br />',$longinsttype);
166:): }
167:): } else {
168:): if ($longinsttype eq '') {
169:): $defaultinfo = &mt('For this user, the default quota is [_1]'
170:): .' MB.',$defquota);
171:): } else {
172:): $defaultinfo = &mt("For this user, the default quota of [_1]".
173:): " MB,[_2]is determined by the user's institutional".
174:): " affiliation ([_3]).",$defquota,'<br />',$longinsttype);
175:): }
176:): }
177:):
178:): if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
179:): $output .= '<tr class="LC_info_row">'."\n".
180:): ' <td'.$colspan.'>'.$titles{$name}.'</td>'."\n".
181:): ' </tr>'."\n".
182:): &Apache::loncommon::start_data_table_row()."\n".
183:): ' <td'.$colspan.'><span class="LC_nobreak">'.
184:): &mt('Current quota: [_1] MB',$currquota).'</span> '.
185:): $defaultinfo.'</td>'."\n".
186:): &Apache::loncommon::end_data_table_row()."\n".
187:): &Apache::loncommon::start_data_table_row()."\n".
188:): '<td'.$colspan.'><span class="LC_nobreak">'.$lt{'chqu'}.
189:): ': <label>'.
190:): '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
191:): 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
192:): ' /><span class="LC_nobreak">'.
193:): &mt('Default ([_1] MB)',$defquota).'</span></label> '.
194:): ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
195:): 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
196:): ' />'.$lt{'cust'}.':</label> '.
197:): '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
198:): 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
199:): ' /> '.&mt('MB').'</span></td>'."\n".
200:): &Apache::loncommon::end_data_table_row()."\n";
201:): }
202:): return $output;
203:): }
204:):
205:): sub user_quota_js {
206:): return <<"END_SCRIPT";
1.149 raeburn 207: <script type="text/javascript">
1.301 bisitz 208: // <![CDATA[
1.378 raeburn 209: function quota_changes(caller,context) {
210: var customoff = document.getElementById('custom_'+context+'quota_off');
211: var customon = document.getElementById('custom_'+context+'quota_on');
212: var number = document.getElementById(context+'quota');
1.149 raeburn 213: if (caller == "custom") {
1.378 raeburn 214: if (customoff) {
215: if (customoff.checked) {
216: number.value = "";
217: }
1.149 raeburn 218: }
219: }
220: if (caller == "quota") {
1.378 raeburn 221: if (customon) {
222: customon.checked = true;
223: }
1.149 raeburn 224: }
1.378 raeburn 225: return;
1.149 raeburn 226: }
1.301 bisitz 227: // ]]>
1.149 raeburn 228: </script>
229: END_SCRIPT
1.378 raeburn 230:
1.406.2.20.2. (raeburn 231:): }
232:):
233:): sub set_custom_js {
234:): return <<"END_SCRIPT";
235:):
236:): <script type="text/javascript">
237:): // <![CDATA[
238:): function toggleCustom(form,item,name) {
239:): if (document.getElementById(item)) {
240:): var divid = document.getElementById(item);
241:): var radioname = form.elements[name];
242:): if (radioname) {
243:): if (radioname.length > 0) {
244:): var setvis;
245:): var RegExp = /^customtext_(aboutme|blog|portfolio|portaccess|timezone|webdav|archive)\$/;
246:): for (var i=0; i<radioname.length; i++) {
247:): if (radioname[i].checked == true) {
248:): if (radioname[i].value == 1) {
249:): if (RegExp.test(item)) {
250:): divid.style.display = 'inline';
251:): } else {
252:): divid.style.display = 'block';
253:): }
254:): setvis = 1;
255:): }
256:): break;
257:): }
258:): }
259:): if (!setvis) {
260:): divid.style.display = 'none';
1.378 raeburn 261: }
262: }
263: }
264: }
1.406.2.20.2. (raeburn 265:): return;
266:): }
267:): // ]]>
268:): </script>
269:):
270:): END_SCRIPT
271:):
1.134 raeburn 272: }
273:
1.275 raeburn 274: sub build_tools_display {
275: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 276: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.406.2.20.2. (raeburn 277:): $colspan,$isadv,%domconfig,@defaulteditors,@customeditors,@custommanagers,
278:): @possmanagers);
1.275 raeburn 279: my %lt = &Apache::lonlocal::texthash (
280: 'blog' => "Personal User Blog",
281: 'aboutme' => "Personal Information Page",
1.406.2.20.2. (raeburn 282:): 'webdav' => "WebDAV access to Authoring Spaces (https)",
283:): 'editors' => "Available Editors",
284:): 'managers' => "Co-authors who can add/revoke roles",
285:): 'archive' => "Managers can download tar.gz file of Authoring Space",
1.275 raeburn 286: 'portfolio' => "Personal User Portfolio",
1.406.2.20.2. (raeburn 287:): 'portaccess' => "Portfolio Shareable",
288:): 'timezone' => "Can set Time Zone",
1.275 raeburn 289: 'avai' => "Available",
290: 'cusa' => "availability",
291: 'chse' => "Change setting",
292: 'usde' => "Use default",
293: 'uscu' => "Use custom",
294: 'official' => 'Can request creation of official courses',
1.299 raeburn 295: 'unofficial' => 'Can request creation of unofficial courses',
296: 'community' => 'Can request creation of communities',
1.384 raeburn 297: 'textbook' => 'Can request creation of textbook courses',
1.362 raeburn 298: 'requestauthor' => 'Can request author space',
1.406.2.20.2. (raeburn 299:): 'edit' => 'Standard editor (Edit)',
300:): 'xml' => 'Text editor (EditXML)',
301:): 'daxe' => 'Daxe editor (Daxe)',
1.275 raeburn 302: );
1.406.2.20.2. (raeburn 303:): $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.279 raeburn 304: if ($context eq 'requestcourses') {
1.275 raeburn 305: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 306: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 307: 'requestcourses.community','requestcourses.textbook');
308: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 309: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 310: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
311: %reqtitles = &courserequest_titles();
312: %reqdisplay = &courserequest_display();
1.332 raeburn 313: %domconfig =
314: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.362 raeburn 315: } elsif ($context eq 'requestauthor') {
1.406.2.20.2. (raeburn 316:): %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,'requestauthor');
1.362 raeburn 317: @usertools = ('requestauthor');
318: @options =('norequest','approval','automatic');
319: %reqtitles = &requestauthor_titles();
320: %reqdisplay = &requestauthor_display();
321: %domconfig =
322: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.406.2.20.2. (raeburn 323:): } elsif ($context eq 'authordefaults') {
324:): %domconfig =
325:): &Apache::lonnet::get_dom('configuration',['quotas','authordefaults'],$ccdomain);
326:): %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,'tools.webdav',
327:): 'authoreditors','authormanagers',
328:): 'authorarchive','domcoord.author');
329:): @usertools = ('webdav','editors','managers','archive');
330:): $colspan = ' colspan="2"';
1.275 raeburn 331: } else {
332: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 333: 'tools.aboutme','tools.portfolio','tools.blog',
1.406.2.20.2. (raeburn 334:): 'tools.timezone','tools.portaccess');
335:): @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
336:): $colspan = ' colspan="2"';
1.275 raeburn 337: }
338: foreach my $item (@usertools) {
1.306 raeburn 339: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
1.406.2.20.2. (raeburn 340:): $currdisp,$custdisp,$custradio,$onclick,$customsty,$editorsty);
1.275 raeburn 341: $cust_off = 'checked="checked" ';
342: $tool_on = 'checked="checked" ';
1.406.2.20.2. (raeburn 343:): unless (($context eq 'authordefaults') || ($item eq 'webdav')) {
344:): $curr_access =
345:): &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
346:): $context,\%userenv,'',
347:): {'is_adv' => $isadv});
348:): }
1.362 raeburn 349: if ($context eq 'requestauthor') {
350: if ($userenv{$context} ne '') {
351: $cust_on = ' checked="checked" ';
352: $cust_off = '';
1.406.2.20.2. (raeburn 353:): }
354:): } elsif ($context eq 'authordefaults') {
355:): if (($item eq 'editors') || ($item eq 'archive')) {
356:): if ($userenv{'author'.$item} ne '') {
357:): $cust_on = ' checked="checked" ';
358:): $cust_off = '';
359:): if ($item eq 'archive') {
360:): $curr_access = $userenv{'author'.$item};
361:): }
362:): } elsif ($item eq 'archive') {
363:): $curr_access = 0;
364:): if (ref($domconfig{'authordefaults'}) eq 'HASH') {
365:): $curr_access = $domconfig{'authordefaults'}{'archive'};
366:): }
367:): }
368:): } elsif ($item eq 'webdav') {
369:): if ($userenv{'tools.'.$item} ne '') {
370:): $cust_on = ' checked="checked" ';
371:): $cust_off = '';
372:): }
373:): }
1.362 raeburn 374: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 375: $cust_on = ' checked="checked" ';
376: $cust_off = '';
377: }
378: if ($context eq 'requestcourses') {
379: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 380: $custom_access = &mt('Currently from default setting.');
1.406.2.20.2. (raeburn 381:): $customsty = ' style="display:none;"';
1.306 raeburn 382: } else {
383: $custom_access = &mt('Currently from custom setting.');
1.406.2.20.2. (raeburn 384:): $customsty = ' style="display:block;"';
1.275 raeburn 385: }
1.362 raeburn 386: } elsif ($context eq 'requestauthor') {
387: if ($userenv{$context} eq '') {
388: $custom_access = &mt('Currently from default setting.');
1.406.2.20.2. (raeburn 389:): $customsty = ' style="display:none;"';
1.362 raeburn 390: } else {
391: $custom_access = &mt('Currently from custom setting.');
1.406.2.20.2. (raeburn 392:): $customsty = ' style="display:block;"';
393:): }
394:): } elsif ($item eq 'editors') {
395:): if ($userenv{'author'.$item} eq '') {
396:): if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
397:): @defaulteditors = @{$domconfig{'authordefaults'}{'editors'}};
398:): } else {
399:): @defaulteditors = ('edit','xml');
400:): }
401:): $custom_access = &mt('Can use: [_1]',
402:): join(', ', map { $lt{$_} } @defaulteditors));
403:): $editorsty = ' style="display:none;"';
404:): } else {
405:): $custom_access = &mt('Currently from custom setting.');
406:): foreach my $editor (split(/,/,$userenv{'author'.$item})) {
407:): if ($editor =~ /^(edit|daxe|xml)$/) {
408:): push(@customeditors,$editor);
409:): }
410:): }
411:): if (@customeditors) {
412:): if (@customeditors > 1) {
413:): $custom_access .= '<br /><span>';
414:): } else {
415:): $custom_access .= ' <span class="LC_nobreak">';
416:): }
417:): $custom_access .= &mt('Can use: [_1]',
418:): join(', ', map { $lt{$_} } @customeditors)).
419:): '</span>';
420:): } else {
421:): $custom_access .= ' '.&mt('No available editors');
422:): }
423:): $editorsty = ' style="display:block;"';
1.362 raeburn 424: }
1.406.2.20.2. (raeburn 425:): } elsif ($item eq 'managers') {
426:): my %ca_roles = &Apache::lonnet::get_my_roles($ccuname,$ccdomain,undef,
427:): ['active','future'],['ca']);
428:): if (keys(%ca_roles)) {
429:): foreach my $entry (sort(keys(%ca_roles))) {
430:): if ($entry =~ /^($match_username\:$match_domain):ca$/) {
431:): my $user = $1;
432:): unless ($user eq "$ccuname:$ccdomain") {
433:): push(@possmanagers,$user);
434:): }
435:): }
436:): }
437:): }
438:): if ($userenv{'author'.$item} eq '') {
439:): $custom_access = &mt('Currently author manages co-author roles');
440:): } else {
441:): if (keys(%ca_roles)) {
442:): foreach my $user (split(/,/,$userenv{'author'.$item})) {
443:): if ($user =~ /^($match_username):($match_domain)$/) {
444:): if (exists($ca_roles{$user.':ca'})) {
445:): unless ($user eq "$ccuname:$ccdomain") {
446:): push(@custommanagers,$user);
447:): }
448:): }
449:): }
450:): }
451:): }
452:): if (@custommanagers) {
453:): $custom_access = &mt('Co-authors who manage co-author roles: [_1]',
454:): join(', ',@custommanagers));
455:): } else {
456:): $custom_access = &mt('Currently author manages co-author roles');
457:): }
458:): }
1.275 raeburn 459: } else {
1.406.2.20.2. (raeburn 460:): my $current = $userenv{$context.'.'.$item};
461:): if ($item eq 'webdav') {
462:): $current = $userenv{'tools.webdav'};
463:): } elsif ($item eq 'archive') {
464:): $current = $userenv{'author'.$item};
465:): }
466:): if ($current eq '') {
1.314 raeburn 467: $custom_access =
1.306 raeburn 468: &mt('Availability determined currently from default setting.');
469: if (!$curr_access) {
470: $tool_off = 'checked="checked" ';
471: $tool_on = '';
472: }
1.406.2.20.2. (raeburn 473:): $customsty = ' style="display:none;"';
1.306 raeburn 474: } else {
1.314 raeburn 475: $custom_access =
1.306 raeburn 476: &mt('Availability determined currently from custom setting.');
1.406.2.20.2. (raeburn 477:): if ($current == 0) {
1.306 raeburn 478: $tool_off = 'checked="checked" ';
479: $tool_on = '';
480: }
1.406.2.20.2. (raeburn 481:): $customsty = ' style="display:inline;"';
1.275 raeburn 482: }
483: }
484: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 485: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 486: ' </tr>'."\n".
1.306 raeburn 487: &Apache::loncommon::start_data_table_row()."\n";
1.362 raeburn 488: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 489: my ($curroption,$currlimit);
1.362 raeburn 490: my $envkey = $context.'.'.$item;
491: if ($context eq 'requestauthor') {
492: $envkey = $context;
493: }
494: if ($userenv{$envkey} ne '') {
495: $curroption = $userenv{$envkey};
1.332 raeburn 496: } else {
497: my (@inststatuses);
1.362 raeburn 498: if ($context eq 'requestcourses') {
499: $curroption =
500: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
501: $isadv,$ccdomain,$item,
502: \@inststatuses,\%domconfig);
503: } else {
504: $curroption =
505: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
506: $isadv,$ccdomain,undef,
507: \@inststatuses,\%domconfig);
508: }
1.332 raeburn 509: }
1.306 raeburn 510: if (!$curroption) {
511: $curroption = 'norequest';
512: }
1.406.2.20.2. (raeburn 513:): my $name = 'crsreq_'.$item;
514:): if ($context eq 'requestauthor') {
515:): $name = $item;
516:): }
517:): $onclick = ' onclick="javascript:toggleCustom(this.form,'."'customtext_$item','custom$item'".');"';
1.306 raeburn 518: if ($curroption =~ /^autolimit=(\d*)$/) {
519: $currlimit = $1;
1.314 raeburn 520: if ($currlimit eq '') {
521: $currdisp = &mt('Yes, automatic creation');
522: } else {
523: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
524: }
1.306 raeburn 525: } else {
526: $currdisp = $reqdisplay{$curroption};
527: }
1.406.2.20.2. (raeburn 528:): $custdisp = '<fieldset id="customtext_'.$item.'"'.$customsty.'>';
1.306 raeburn 529: foreach my $option (@options) {
530: my $val = $option;
531: if ($option eq 'norequest') {
532: $val = 0;
533: }
534: if ($option eq 'validate') {
535: my $canvalidate = 0;
536: if (ref($validations{$item}) eq 'HASH') {
537: if ($validations{$item}{'_custom_'}) {
538: $canvalidate = 1;
539: }
540: }
541: next if (!$canvalidate);
542: }
543: my $checked = '';
544: if ($option eq $curroption) {
545: $checked = ' checked="checked"';
546: } elsif ($option eq 'autolimit') {
547: if ($curroption =~ /^autolimit/) {
548: $checked = ' checked="checked"';
549: }
550: }
1.406.2.20.2. (raeburn 551:): if ($option eq 'autolimit') {
552:): $custdisp .= '<br />';
1.362 raeburn 553: }
1.406.2.20.2. (raeburn 554:): $custdisp .= '<span class="LC_nobreak"><label>'.
1.362 raeburn 555: '<input type="radio" name="'.$name.'" '.
556: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 557: $reqtitles{$option}.'</label> ';
558: if ($option eq 'autolimit') {
1.362 raeburn 559: $custdisp .= '<input type="text" name="'.$name.
560: '_limit" size="1" '.
1.406.2.20.2. (raeburn 561:): 'value="'.$currlimit.'" /> '.
562:): $reqtitles{'unlimited'}.'</span>';
1.362 raeburn 563: } else {
564: $custdisp .= '</span>';
565: }
1.406.2.20.2. (raeburn 566:): $custdisp .= ' ';
567:): }
568:): $custdisp .= '</fieldset>';
569:): $custradio = '<br />'.$custdisp;
570:): } elsif ($item eq 'editors') {
571:): $output .= '<td'.$colspan.'>'.$custom_access.'</td>'."\n".
572:): &Apache::loncommon::end_data_table_row()."\n";
573:): unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
574:): $output .= &Apache::loncommon::start_data_table_row()."\n".
575:): '<td'.$colspan.'><span class="LC_nobreak">'.
576:): $lt{'chse'}.': <label>'.
577:): '<input type="radio" name="custom'.$item.'" value="0" '.
578:): $cust_off.' onclick="toggleCustom(this.form,'."'customtext_$item','custom$item'".');" />'.
579:): $lt{'usde'}.'</label>'.(' ' x3).
580:): '<label><input type="radio" name="custom'.$item.'" value="1" '.
581:): $cust_on.' onclick="toggleCustom(this.form,'."'customtext_$item','custom$item'".');" />'.
582:): $lt{'uscu'}.'</label></span><br />'.
583:): '<fieldset id="customtext_'.$item.'"'.$editorsty.'>';
584:): foreach my $editor ('edit','xml','daxe') {
585:): my $checked;
586:): if ($userenv{'author'.$item} eq '') {
587:): if (grep(/^\Q$editor\E$/,@defaulteditors)) {
588:): $checked = ' checked="checked"';
589:): }
590:): } elsif (grep(/^\Q$editor\E$/,@customeditors)) {
591:): $checked = ' checked="checked"';
592:): }
593:): $output .= '<span style="LC_nobreak"><label>'.
594:): '<input type="checkbox" name="custom_editor" '.
595:): 'value="'.$editor.'"'.$checked.' />'.
596:): $lt{$editor}.'</label></span> ';
597:): }
598:): $output .= '</fieldset></td>'.
599:): &Apache::loncommon::end_data_table_row()."\n";
1.306 raeburn 600: }
1.406.2.20.2. (raeburn 601:): } elsif ($item eq 'managers') {
602:): $output .= '<td'.$colspan.'>'.$custom_access.'</td>'."\n".
603:): &Apache::loncommon::end_data_table_row()."\n";
604:): unless ((&Apache::lonnet::allowed('udp',$ccdomain)) ||
605:): (($userenv{'domcoord.author'} eq 'blocked') &&
606:): (($env{'user.name'} ne $ccuname) || ($env{'user.domain'} ne $ccdomain)))) {
607:): $output .=
608:): &Apache::loncommon::start_data_table_row()."\n".
609:): '<td'.$colspan.'>';
610:): if (@possmanagers) {
611:): $output .= &mt('Select manager(s)').': ';
612:): foreach my $user (@possmanagers) {
613:): my $checked;
614:): if (grep(/^\Q$user\E$/,@custommanagers)) {
615:): $checked = ' checked="checked"';
616:): }
617:): $output .= '<span style="LC_nobreak"><label>'.
618:): '<input type="checkbox" name="custommanagers" '.
619:): 'value="'.&HTML::Entities::encode($user,'\'<>"&').'"'.$checked.' />'.
620:): $user.'</label></span> ';
621:): }
622:): } else {
623:): $output .= &mt('No co-author roles assignable as manager');
624:): }
625:): $output .= '</td>'.
626:): &Apache::loncommon::end_data_table_row()."\n";
627:): }
1.306 raeburn 628: } else {
629: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 630: my $name = $context.'_'.$item;
1.406.2.20.2. (raeburn 631:): $onclick = 'onclick="javascript:toggleCustom(this.form,'."'customtext_$item','custom$item'".');" ';
1.306 raeburn 632: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 633: '<input type="radio" name="'.$name.'"'.
1.406.2.20.2. (raeburn 634:): ' value="1" '.$tool_on.$onclick.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 635: '<input type="radio" name="'.$name.'" value="0" '.
1.406.2.20.2. (raeburn 636:): $tool_off.$onclick.'/>'.&mt('Off').'</label></span>';
637:): $custradio = '<span id="customtext_'.$item.'"'.$customsty.' class="LC_nobreak">'.
638:): '--'.$lt{'cusa'}.': '.$custdisp.'</span>';
639:): }
640:): unless (($item eq 'editors') || ($item eq 'managers')) {
641:): $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
642:): $lt{'avai'}.': '.$currdisp.'</td>'."\n".
643:): &Apache::loncommon::end_data_table_row()."\n";
644:): unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
645:): $output .=
1.275 raeburn 646: &Apache::loncommon::start_data_table_row()."\n".
1.406.2.20.2. (raeburn 647:): '<td><span class="LC_nobreak">'.
1.306 raeburn 648: $lt{'chse'}.': <label>'.
1.275 raeburn 649: '<input type="radio" name="custom'.$item.'" value="0" '.
1.406.2.20.2. (raeburn 650:): $cust_off.$onclick.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
1.306 raeburn 651: '<label><input type="radio" name="custom'.$item.'" value="1" '.
1.406.2.20.2. (raeburn 652:): $cust_on.$onclick.'/>'.$lt{'uscu'}.'</label></span>';
653:): if ($colspan) {
654:): $output .= '</td><td>';
655:): }
656:): $output .= $custradio.'</td>'.
657:): &Apache::loncommon::end_data_table_row()."\n";
658:): }
1.406.2.6 raeburn 659: }
1.275 raeburn 660: }
661: return $output;
662: }
663:
1.300 raeburn 664: sub coursereq_externaluser {
665: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 666: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 667: my %lt = &Apache::lonlocal::texthash (
668: 'official' => 'Can request creation of official courses',
669: 'unofficial' => 'Can request creation of unofficial courses',
670: 'community' => 'Can request creation of communities',
1.384 raeburn 671: 'textbook' => 'Can request creation of textbook courses',
1.300 raeburn 672: );
673:
674: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
675: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.384 raeburn 676: 'reqcrsotherdom.community','reqcrsotherdom.textbook');
677: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 678: @options = ('approval','validate','autolimit');
1.306 raeburn 679: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
680: my $optregex = join('|',@options);
681: my %reqtitles = &courserequest_titles();
1.300 raeburn 682: foreach my $item (@usertools) {
1.306 raeburn 683: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 684: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
685: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 686: foreach my $req (@curr) {
687: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
688: $curroption = $1;
689: $currlimit = $2;
690: last;
1.306 raeburn 691: }
692: }
1.314 raeburn 693: if (!$curroption) {
694: $curroption = 'norequest';
695: $tooloff = ' checked="checked"';
696: }
1.306 raeburn 697: } else {
698: $curroption = 'norequest';
699: $tooloff = ' checked="checked"';
700: }
701: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 702: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
703: '<table><tr><td valign="top">'."\n".
1.306 raeburn 704: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 705: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
706: '</label></td>';
1.306 raeburn 707: foreach my $option (@options) {
708: if ($option eq 'validate') {
709: my $canvalidate = 0;
710: if (ref($validations{$item}) eq 'HASH') {
711: if ($validations{$item}{'_external_'}) {
712: $canvalidate = 1;
713: }
714: }
715: next if (!$canvalidate);
716: }
717: my $checked = '';
718: if ($option eq $curroption) {
719: $checked = ' checked="checked"';
720: }
1.314 raeburn 721: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 722: '<input type="radio" name="reqcrsotherdom_'.$item.
723: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 724: $reqtitles{$option}.'</label>';
1.306 raeburn 725: if ($option eq 'autolimit') {
1.314 raeburn 726: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 727: $item.'_limit" size="1" '.
1.314 raeburn 728: 'value="'.$currlimit.'" /></span>'.
729: '<br />'.$reqtitles{'unlimited'};
730: } else {
731: $output .= '</span>';
1.300 raeburn 732: }
1.314 raeburn 733: $output .= '</td>';
1.300 raeburn 734: }
1.314 raeburn 735: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 736: &Apache::loncommon::end_data_table_row()."\n";
737: }
738: return $output;
739: }
740:
1.362 raeburn 741: sub domainrole_req {
742: my ($ccuname,$ccdomain) = @_;
743: return '<br /><h3>'.
1.406.2.20.2. (raeburn 744:): &mt('Can Request Assignment of Domain Roles?').
1.362 raeburn 745: '</h3>'."\n".
746: &Apache::loncommon::start_data_table().
747: &build_tools_display($ccuname,$ccdomain,
748: 'requestauthor').
749: &Apache::loncommon::end_data_table();
750: }
751:
1.406.2.20.2. (raeburn 752:): sub authoring_defaults {
753:): my ($ccuname,$ccdomain) = @_;
754:): return '<br /><h3>'.
755:): &mt('Authoring Space defaults (if role assigned)').
756:): '</h3>'."\n".
757:): &Apache::loncommon::start_data_table().
758:): &build_tools_display($ccuname,$ccdomain,
759:): 'authordefaults').
760:): &user_quotas($ccuname,$ccdomain,'author').
761:): &Apache::loncommon::end_data_table();
762:): }
763:):
1.306 raeburn 764: sub courserequest_titles {
765: my %titles = &Apache::lonlocal::texthash (
766: official => 'Official',
767: unofficial => 'Unofficial',
768: community => 'Communities',
1.384 raeburn 769: textbook => 'Textbook',
1.306 raeburn 770: norequest => 'Not allowed',
1.309 raeburn 771: approval => 'Approval by Dom. Coord.',
1.306 raeburn 772: validate => 'With validation',
773: autolimit => 'Numerical limit',
1.314 raeburn 774: unlimited => '(blank for unlimited)',
1.306 raeburn 775: );
776: return %titles;
777: }
778:
779: sub courserequest_display {
780: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 781: approval => 'Yes, need approval',
1.306 raeburn 782: validate => 'Yes, with validation',
783: norequest => 'No',
784: );
785: return %titles;
786: }
787:
1.362 raeburn 788: sub requestauthor_titles {
789: my %titles = &Apache::lonlocal::texthash (
790: norequest => 'Not allowed',
791: approval => 'Approval by Dom. Coord.',
792: automatic => 'Automatic approval',
793: );
794: return %titles;
795:
796: }
797:
798: sub requestauthor_display {
799: my %titles = &Apache::lonlocal::texthash (
800: approval => 'Yes, need approval',
801: automatic => 'Yes, automatic approval',
802: norequest => 'No',
803: );
804: return %titles;
805: }
806:
1.383 raeburn 807: sub requestchange_display {
808: my %titles = &Apache::lonlocal::texthash (
809: approval => "availability set to 'on' (approval required)",
810: automatic => "availability set to 'on' (automatic approval)",
811: norequest => "availability set to 'off'",
812: );
813: return %titles;
814: }
815:
1.362 raeburn 816: sub curr_requestauthor {
817: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
818: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
819: if ($uname eq '' || $udom eq '') {
820: $uname = $env{'user.name'};
821: $udom = $env{'user.domain'};
822: $isadv = $env{'user.adv'};
823: }
824: my (%userenv,%settings,$val);
825: my @options = ('automatic','approval');
826: %userenv =
827: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
828: if ($userenv{'requestauthor'}) {
829: $val = $userenv{'requestauthor'};
830: @{$inststatuses} = ('_custom_');
831: } else {
832: my %alltasks;
833: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
834: %settings = %{$domconfig->{'requestauthor'}};
835: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
836: $val = $settings{'_LC_adv'};
837: @{$inststatuses} = ('_LC_adv_');
838: } else {
839: if ($userenv{'inststatus'} ne '') {
840: @{$inststatuses} = split(',',$userenv{'inststatus'});
841: } else {
842: @{$inststatuses} = ('default');
843: }
844: foreach my $status (@{$inststatuses}) {
845: if (exists($settings{$status})) {
846: my $value = $settings{$status};
847: next unless ($value);
848: unless (exists($alltasks{$value})) {
849: if (ref($alltasks{$value}) eq 'ARRAY') {
850: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
851: push(@{$alltasks{$value}},$status);
852: }
853: } else {
854: @{$alltasks{$value}} = ($status);
855: }
856: }
857: }
858: }
859: foreach my $option (@options) {
860: if ($alltasks{$option}) {
861: $val = $option;
862: last;
863: }
864: }
865: }
866: }
867: }
868: return $val;
869: }
870:
1.2 www 871: # =================================================================== Phase one
1.1 www 872:
1.42 matthew 873: sub print_username_entry_form {
1.406.2.14 raeburn 874: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
875: $permission) = @_;
1.101 albertel 876: my $defdom=$env{'request.role.domain'};
1.160 raeburn 877: my $formtoset = 'crtuser';
878: if (exists($env{'form.startrolename'})) {
879: $formtoset = 'docustom';
880: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 881: } elsif ($env{'form.origform'} eq 'crtusername') {
882: $formtoset = $env{'form.origform'};
1.160 raeburn 883: }
884:
885: my ($jsback,$elements) = &crumb_utilities();
886:
887: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 888: '<script type="text/javascript">'."\n".
1.301 bisitz 889: '// <![CDATA['."\n".
890: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
891: '// ]]>'."\n".
1.162 raeburn 892: '</script>'."\n";
1.160 raeburn 893:
1.324 raeburn 894: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
895: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
896: && (&Apache::lonnet::allowed('mcr','/'))) {
897: $jscript .= &customrole_javascript();
898: }
1.224 raeburn 899: my $helpitem = 'Course_Change_Privileges';
900: if ($env{'form.action'} eq 'custom') {
1.406.2.14 raeburn 901: if ($context eq 'course') {
902: $helpitem = 'Course_Editing_Custom_Roles';
903: } elsif ($context eq 'domain') {
904: $helpitem = 'Domain_Editing_Custom_Roles';
905: }
1.224 raeburn 906: } elsif ($env{'form.action'} eq 'singlestudent') {
907: $helpitem = 'Course_Add_Student';
1.406.2.5 raeburn 908: } elsif ($env{'form.action'} eq 'accesslogs') {
909: $helpitem = 'Domain_User_Access_Logs';
1.406.2.14 raeburn 910: } elsif ($context eq 'author') {
911: $helpitem = 'Author_Change_Privileges';
912: } elsif ($context eq 'domain') {
913: if ($permission->{'cusr'}) {
914: $helpitem = 'Domain_Change_Privileges';
915: } elsif ($permission->{'view'}) {
916: $helpitem = 'Domain_View_Privileges';
917: } else {
918: undef($helpitem);
919: }
1.224 raeburn 920: }
1.406.2.7 raeburn 921: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 922: if ($env{'form.action'} eq 'custom') {
923: push(@{$brcrum},
924: {href=>"javascript:backPage(document.crtuser)",
925: text=>"Pick custom role",
926: help => $helpitem,}
927: );
928: } else {
929: push (@{$brcrum},
930: {href => "javascript:backPage(document.crtuser)",
931: text => $breadcrumb_text{'search'},
932: help => $helpitem,
933: faq => 282,
934: bug => 'Instructor Interface',}
935: );
936: }
937: my %loaditems = (
938: 'onload' => "javascript:setFormElements(document.$formtoset)",
939: );
940: my $args = {bread_crumbs => $brcrum,
941: bread_crumbs_component => 'User Management',
942: add_entries => \%loaditems,};
943: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
944:
1.71 sakharuk 945: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 946: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 947: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 948: 'srad' => 'Search for a user and modify/add user information or roles',
1.406.2.7 raeburn 949: 'srvu' => 'Search for a user and view user information and roles',
1.406.2.5 raeburn 950: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 951: 'usr' => "Username",
952: 'dom' => "Domain",
1.324 raeburn 953: 'ecrp' => "Define or Edit Custom Role",
954: 'nr' => "role name",
1.282 schafran 955: 'cre' => "Next",
1.71 sakharuk 956: );
1.351 raeburn 957:
1.214 raeburn 958: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 959: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 960: my $newroletext = &mt('Define new custom role:');
961: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
962: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
963: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
964: '<h3>'.$lt{'ecrp'}.'</h3>'.
965: &Apache::loncommon::start_data_table().
966: &Apache::loncommon::start_data_table_row().
967: '<td>');
968: if (keys(%existingroles) > 0) {
969: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
970: } else {
971: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
972: }
973: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
974: &Apache::loncommon::end_data_table_row());
975: if (keys(%existingroles) > 0) {
976: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
977: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
978: &mt('View/Modify existing role:').'</b></label></td>'.
979: '<td align="center"><br />'.
980: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 981: '<option value="" selected="selected">'.
1.324 raeburn 982: &mt('Select'));
983: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 984: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 985: }
986: $r->print('</select>'.
987: '</td>'.
988: &Apache::loncommon::end_data_table_row());
989: }
990: $r->print(&Apache::loncommon::end_data_table().'<p>'.
991: '<input name="customeditor" type="submit" value="'.
992: $lt{'cre'}.'" /></p>'.
993: '</form>');
1.190 raeburn 994: }
1.213 raeburn 995: } else {
1.229 raeburn 996: my $actiontext = $lt{'srad'};
1.406.2.13 raeburn 997: my $fixeddom;
1.213 raeburn 998: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 999: if ($crstype eq 'Community') {
1000: $actiontext = $lt{'srme'};
1001: } else {
1002: $actiontext = $lt{'srst'};
1003: }
1.406.2.5 raeburn 1004: } elsif ($env{'form.action'} eq 'accesslogs') {
1005: $actiontext = $lt{'srva'};
1.406.2.13 raeburn 1006: $fixeddom = 1;
1.406.2.7 raeburn 1007: } elsif (($env{'form.action'} eq 'singleuser') &&
1008: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
1009: $actiontext = $lt{'srvu'};
1.406.2.14 raeburn 1010: $fixeddom = 1;
1.213 raeburn 1011: }
1.324 raeburn 1012: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 1013: if ($env{'form.origform'} ne 'crtusername') {
1.406.2.5 raeburn 1014: if ($response) {
1015: $r->print("\n<div>$response</div>".
1016: '<br clear="all" />');
1017: }
1.213 raeburn 1018: }
1.406.2.13 raeburn 1019: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 1020: }
1.110 albertel 1021: }
1022:
1.324 raeburn 1023: sub customrole_javascript {
1024: my $js = <<"END";
1025: <script type="text/javascript">
1026: // <![CDATA[
1027:
1028: function setCustomFields() {
1029: if (document.docustom.customroleaction.length > 0) {
1030: for (var i=0; i<document.docustom.customroleaction.length; i++) {
1031: if (document.docustom.customroleaction[i].checked) {
1032: if (document.docustom.customroleaction[i].value == 'new') {
1033: document.docustom.rolename.selectedIndex = 0;
1034: } else {
1035: document.docustom.newrolename.value = '';
1036: }
1037: }
1038: }
1039: }
1040: return;
1041: }
1042:
1043: function setCustomAction(caller) {
1044: if (document.docustom.customroleaction.length > 0) {
1045: for (var i=0; i<document.docustom.customroleaction.length; i++) {
1046: if (document.docustom.customroleaction[i].value == caller) {
1047: document.docustom.customroleaction[i].checked = true;
1048: }
1049: }
1050: }
1051: setCustomFields();
1052: return;
1053: }
1054:
1055: // ]]>
1056: </script>
1057: END
1058: return $js;
1059: }
1060:
1.160 raeburn 1061: sub entry_form {
1.406.2.5 raeburn 1062: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 1063: my ($usertype,$inexact);
1.214 raeburn 1064: if (ref($srch) eq 'HASH') {
1065: if (($srch->{'srchin'} eq 'dom') &&
1066: ($srch->{'srchby'} eq 'uname') &&
1067: ($srch->{'srchtype'} eq 'exact') &&
1068: ($srch->{'srchdomain'} ne '') &&
1069: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 1070: my (%curr_rules,%got_rules);
1.214 raeburn 1071: my ($rules,$ruleorder) =
1072: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 1073: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 1074: } else {
1075: $inexact = 1;
1.214 raeburn 1076: }
1.207 raeburn 1077: }
1.406.2.14 raeburn 1078: my ($cancreate,$noinstd);
1079: if ($env{'form.action'} eq 'accesslogs') {
1080: $noinstd = 1;
1081: } else {
1082: $cancreate =
1083: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1084: }
1.406.2.3 raeburn 1085: my ($userpicker,$cansearch) =
1.179 raeburn 1086: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.406.2.14 raeburn 1087: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 1088: my $srchbutton = &mt('Search');
1.229 raeburn 1089: if ($env{'form.action'} eq 'singlestudent') {
1090: $srchbutton = &mt('Search and Enroll');
1.406.2.5 raeburn 1091: } elsif ($env{'form.action'} eq 'accesslogs') {
1092: $srchbutton = &mt('Search');
1.229 raeburn 1093: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
1094: $srchbutton = &mt('Search or Add New User');
1095: }
1.406.2.3 raeburn 1096: my $output;
1097: if ($cansearch) {
1098: $output = <<"ENDBLOCK";
1.160 raeburn 1099: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 1100: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 1101: <input type="hidden" name="phase" value="get_user_info" />
1102: $userpicker
1.179 raeburn 1103: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 1104: </form>
1.207 raeburn 1105: ENDBLOCK
1.406.2.3 raeburn 1106: } else {
1107: $output = '<p>'.$userpicker.'</p>';
1108: }
1.406.2.7 raeburn 1109: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
1110: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1111: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 1112: my $defdom=$env{'request.role.domain'};
1113: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
1114: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 1115: 'enro' => 'Enroll one student',
1.318 raeburn 1116: 'enrm' => 'Enroll one member',
1.229 raeburn 1117: 'admo' => 'Add/modify a single user',
1118: 'crea' => 'create new user if required',
1119: 'uskn' => "username is known",
1.207 raeburn 1120: 'crnu' => 'Create a new user',
1121: 'usr' => 'Username',
1122: 'dom' => 'in domain',
1.229 raeburn 1123: 'enrl' => 'Enroll',
1124: 'cram' => 'Create/Modify user',
1.207 raeburn 1125: );
1.229 raeburn 1126: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
1127: my ($title,$buttontext,$showresponse);
1.318 raeburn 1128: if ($env{'form.action'} eq 'singlestudent') {
1129: if ($crstype eq 'Community') {
1130: $title = $lt{'enrm'};
1131: } else {
1132: $title = $lt{'enro'};
1133: }
1.229 raeburn 1134: $buttontext = $lt{'enrl'};
1135: } else {
1136: $title = $lt{'admo'};
1137: $buttontext = $lt{'cram'};
1138: }
1139: if ($cancreate) {
1140: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
1141: } else {
1142: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
1143: }
1144: if ($env{'form.origform'} eq 'crtusername') {
1145: $showresponse = $responsemsg;
1146: }
1.207 raeburn 1147: $output .= <<"ENDDOCUMENT";
1.229 raeburn 1148: <br />
1.207 raeburn 1149: <form action="/adm/createuser" method="post" name="crtusername">
1150: <input type="hidden" name="action" value="$env{'form.action'}" />
1151: <input type="hidden" name="phase" value="createnewuser" />
1152: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 1153: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 1154: <input type="hidden" name="srchin" value="dom" />
1155: <input type="hidden" name="forcenewuser" value="1" />
1156: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 1157: <h3>$title</h3>
1158: $showresponse
1.207 raeburn 1159: <table>
1160: <tr>
1161: <td>$lt{'usr'}:</td>
1162: <td><input type="text" size="15" name="srchterm" /></td>
1163: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 1164: <td> $sellink </td>
1165: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 1166: </tr>
1167: </table>
1168: </form>
1.160 raeburn 1169: ENDDOCUMENT
1.207 raeburn 1170: }
1.160 raeburn 1171: return $output;
1172: }
1.110 albertel 1173:
1174: sub user_modification_js {
1.113 raeburn 1175: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
1176:
1.110 albertel 1177: return <<END;
1178: <script type="text/javascript" language="Javascript">
1.301 bisitz 1179: // <![CDATA[
1.314 raeburn 1180:
1.110 albertel 1181: $pjump_def
1182: $dc_setcourse_code
1183:
1184: function dateset() {
1185: eval("document.cu."+document.cu.pres_marker.value+
1186: ".value=document.cu.pres_value.value");
1.359 www 1187: modalWindow.close();
1.110 albertel 1188: }
1189:
1.113 raeburn 1190: $nondc_setsection_code
1.301 bisitz 1191: // ]]>
1.110 albertel 1192: </script>
1193: END
1.2 www 1194: }
1195:
1196: # =================================================================== Phase two
1.160 raeburn 1197: sub print_user_selection_page {
1.351 raeburn 1198: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 1199: my @fields = ('username','domain','lastname','firstname','permanentemail');
1200: my $sortby = $env{'form.sortby'};
1201:
1202: if (!grep(/^\Q$sortby\E$/,@fields)) {
1203: $sortby = 'lastname';
1204: }
1205:
1206: my ($jsback,$elements) = &crumb_utilities();
1207:
1208: my $jscript = (<<ENDSCRIPT);
1209: <script type="text/javascript">
1.301 bisitz 1210: // <![CDATA[
1.160 raeburn 1211: function pickuser(uname,udom) {
1212: document.usersrchform.seluname.value=uname;
1213: document.usersrchform.seludom.value=udom;
1214: document.usersrchform.phase.value="userpicked";
1215: document.usersrchform.submit();
1216: }
1217:
1218: $jsback
1.301 bisitz 1219: // ]]>
1.160 raeburn 1220: </script>
1221: ENDSCRIPT
1222:
1223: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1224: 'usrch' => "User Search to add/modify roles",
1225: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1226: 'memsrch' => "User Search to enroll member",
1.406.2.5 raeburn 1227: 'srcva' => "Search for a user and view access log information",
1.406.2.7 raeburn 1228: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1229: 'usel' => "Select a user to add/modify roles",
1.406.2.7 raeburn 1230: 'suvr' => "Select a user to view roles",
1.318 raeburn 1231: 'stusel' => "Select a user to enroll as a student",
1232: 'memsel' => "Select a user to enroll as a member",
1.406.2.5 raeburn 1233: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1234: 'username' => "username",
1235: 'domain' => "domain",
1236: 'lastname' => "last name",
1237: 'firstname' => "first name",
1238: 'permanentemail' => "permanent e-mail",
1239: );
1.302 raeburn 1240: if ($context eq 'requestcrs') {
1241: $r->print('<div>');
1242: } else {
1.406.2.7 raeburn 1243: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1244: my $helpitem;
1245: if ($env{'form.action'} eq 'singleuser') {
1246: $helpitem = 'Course_Change_Privileges';
1247: } elsif ($env{'form.action'} eq 'singlestudent') {
1248: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 1249: } elsif ($context eq 'author') {
1250: $helpitem = 'Author_Change_Privileges';
1251: } elsif ($context eq 'domain') {
1252: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1253: }
1254: push (@{$brcrum},
1255: {href => "javascript:backPage(document.usersrchform,'','')",
1256: text => $breadcrumb_text{'search'},
1257: faq => 282,
1258: bug => 'Instructor Interface',},
1259: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1260: text => $breadcrumb_text{'userpicked'},
1261: faq => 282,
1262: bug => 'Instructor Interface',
1263: help => $helpitem}
1264: );
1265: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1266: if ($env{'form.action'} eq 'singleuser') {
1.406.2.7 raeburn 1267: my $readonly;
1268: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1269: $readonly = 1;
1270: $r->print("<b>$lt{'usrvu'}</b><br />");
1271: } else {
1272: $r->print("<b>$lt{'usrch'}</b><br />");
1273: }
1.318 raeburn 1274: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.406.2.7 raeburn 1275: if ($readonly) {
1276: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1277: } else {
1278: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1279: }
1.302 raeburn 1280: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1281: $r->print($jscript."<b>");
1282: if ($crstype eq 'Community') {
1283: $r->print($lt{'memsrch'});
1284: } else {
1285: $r->print($lt{'stusrch'});
1286: }
1287: $r->print("</b><br />");
1288: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1289: $r->print('</form><h3>');
1290: if ($crstype eq 'Community') {
1291: $r->print($lt{'memsel'});
1292: } else {
1293: $r->print($lt{'stusel'});
1294: }
1295: $r->print('</h3>');
1.406.2.5 raeburn 1296: } elsif ($env{'form.action'} eq 'accesslogs') {
1297: $r->print("<b>$lt{'srcva'}</b><br />");
1.406.2.14 raeburn 1298: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.406.2.5 raeburn 1299: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1300: }
1.179 raeburn 1301: }
1.380 bisitz 1302: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1303: &Apache::loncommon::start_data_table()."\n".
1304: &Apache::loncommon::start_data_table_header_row()."\n".
1305: ' <th> </th>'."\n");
1306: foreach my $field (@fields) {
1307: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1308: "'".$field."'".';document.usersrchform.submit();">'.
1309: $lt{$field}.'</a></th>'."\n");
1310: }
1311: $r->print(&Apache::loncommon::end_data_table_header_row());
1312:
1313: my @sorted_users = sort {
1.167 albertel 1314: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1315: ||
1.167 albertel 1316: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1317: ||
1318: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1319: ||
1320: lc($a) cmp lc($b)
1.160 raeburn 1321: } (keys(%$srch_results));
1322:
1323: foreach my $user (@sorted_users) {
1324: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1325: my $onclick;
1326: if ($context eq 'requestcrs') {
1.314 raeburn 1327: $onclick =
1.302 raeburn 1328: 'onclick="javascript:gochoose('."'$uname','$udom',".
1329: "'$srch_results->{$user}->{firstname}',".
1330: "'$srch_results->{$user}->{lastname}',".
1331: "'$srch_results->{$user}->{permanentemail}'".');"';
1332: } else {
1.314 raeburn 1333: $onclick =
1.302 raeburn 1334: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1335: }
1.160 raeburn 1336: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1337: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1338: $onclick.' /></td>'.
1.160 raeburn 1339: '<td><tt>'.$uname.'</tt></td>'.
1340: '<td><tt>'.$udom.'</tt></td>');
1341: foreach my $field ('lastname','firstname','permanentemail') {
1342: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1343: }
1344: $r->print(&Apache::loncommon::end_data_table_row());
1345: }
1346: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1347: if (ref($srcharray) eq 'ARRAY') {
1348: foreach my $item (@{$srcharray}) {
1349: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1350: }
1351: }
1.160 raeburn 1352: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1353: ' <input type="hidden" name="seluname" value="" />'."\n".
1354: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1355: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1356: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1357: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1358: if ($context eq 'requestcrs') {
1359: $r->print($opener_elements.'</form></div>');
1360: } else {
1.351 raeburn 1361: $r->print($response.'</form>');
1.302 raeburn 1362: }
1.160 raeburn 1363: }
1364:
1365: sub print_user_query_page {
1.351 raeburn 1366: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1367: # FIXME - this is for a network-wide name search (similar to catalog search)
1368: # To use frames with similar behavior to catalog/portfolio search.
1369: # To be implemented.
1370: return;
1371: }
1372:
1.42 matthew 1373: sub print_user_modification_page {
1.375 raeburn 1374: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1375: $brcrum,$showcredits) = @_;
1.185 raeburn 1376: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1377: my $usermsg = &mt('No username and/or domain provided.');
1378: $env{'form.phase'} = '';
1.406.2.14 raeburn 1379: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1380: $permission);
1.58 www 1381: return;
1382: }
1.213 raeburn 1383: my ($form,$formname);
1384: if ($env{'form.action'} eq 'singlestudent') {
1385: $form = 'document.enrollstudent';
1386: $formname = 'enrollstudent';
1387: } else {
1388: $form = 'document.cu';
1389: $formname = 'cu';
1390: }
1.188 raeburn 1391: my %abv_auth = &auth_abbrev();
1.227 raeburn 1392: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1393: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1394: if ($uhome eq 'no_host') {
1.215 raeburn 1395: my $usertype;
1396: my ($rules,$ruleorder) =
1397: &Apache::lonnet::inst_userrules($ccdomain,'username');
1398: $usertype =
1.353 raeburn 1399: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1400: \%curr_rules,\%got_rules);
1.215 raeburn 1401: my $cancreate =
1402: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1403: $usertype);
1404: if (!$cancreate) {
1.292 bisitz 1405: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1406: my %usertypetext = (
1407: official => 'institutional',
1408: unofficial => 'non-institutional',
1409: );
1410: my $response;
1411: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1412: $response = '<span class="LC_warning">'.
1413: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1414: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1415: '</span><br />';
1416: }
1.292 bisitz 1417: $response .= '<p class="LC_warning">'
1418: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.406.2.6 raeburn 1419: .' ';
1420: if ($context eq 'domain') {
1421: $response .= &mt('Please contact a [_1] for assistance.',
1422: &Apache::lonnet::plaintext('dc'));
1423: } else {
1424: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1425: ,'<a href="'.$helplink.'">','</a>');
1426: }
1427: $response .= '</p><br />';
1.215 raeburn 1428: $env{'form.phase'} = '';
1.406.2.14 raeburn 1429: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1430: $permission);
1.215 raeburn 1431: return;
1432: }
1.188 raeburn 1433: $newuser = 1;
1.193 raeburn 1434: my $checkhash;
1435: my $checks = { 'username' => 1 };
1.196 raeburn 1436: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1437: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1438: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1439: if (ref($alerts{'username'}) eq 'HASH') {
1440: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1441: my $domdesc =
1.193 raeburn 1442: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1443: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1444: my $userchkmsg;
1445: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1446: $userchkmsg =
1447: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1448: $domdesc,1).
1449: &Apache::loncommon::user_rule_formats($ccdomain,
1450: $domdesc,$curr_rules{$ccdomain}{'username'},
1451: 'username');
1.196 raeburn 1452: }
1.215 raeburn 1453: $env{'form.phase'} = '';
1.406.2.14 raeburn 1454: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1455: $permission);
1.196 raeburn 1456: return;
1.215 raeburn 1457: }
1.193 raeburn 1458: }
1.185 raeburn 1459: }
1.187 raeburn 1460: } else {
1.188 raeburn 1461: $newuser = 0;
1.185 raeburn 1462: }
1.160 raeburn 1463: if ($response) {
1.215 raeburn 1464: $response = '<br />'.$response;
1.160 raeburn 1465: }
1.149 raeburn 1466:
1.52 matthew 1467: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1468: my $dc_setcourse_code = '';
1.119 raeburn 1469: my $nondc_setsection_code = '';
1.112 albertel 1470: my %loaditem;
1.114 albertel 1471:
1.216 raeburn 1472: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1473:
1.406.2.20.2. (raeburn 1474:): my $js = &validation_javascript($context,$ccdomain,$pjump_def,
1475:): $crstype,$groupslist,$newuser,
1476:): $formname,\%loaditem,$permission);
1.406.2.7 raeburn 1477: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1478: my $helpitem = 'Course_Change_Privileges';
1479: if ($env{'form.action'} eq 'singlestudent') {
1480: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 1481: } elsif ($context eq 'author') {
1482: $helpitem = 'Author_Change_Privileges';
1483: } elsif ($context eq 'domain') {
1484: $helpitem = 'Domain_Change_Privileges';
1.406.2.20.2. (raeburn 1485:): $js .= &set_custom_js();
1.224 raeburn 1486: }
1.351 raeburn 1487: push (@{$brcrum},
1488: {href => "javascript:backPage($form)",
1489: text => $breadcrumb_text{'search'},
1490: faq => 282,
1491: bug => 'Instructor Interface',});
1492: if ($env{'form.phase'} eq 'userpicked') {
1493: push(@{$brcrum},
1494: {href => "javascript:backPage($form,'get_user_info','select')",
1495: text => $breadcrumb_text{'userpicked'},
1496: faq => 282,
1497: bug => 'Instructor Interface',});
1498: }
1499: push(@{$brcrum},
1500: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1501: text => $breadcrumb_text{'modify'},
1502: faq => 282,
1503: bug => 'Instructor Interface',
1504: help => $helpitem});
1505: my $args = {'add_entries' => \%loaditem,
1506: 'bread_crumbs' => $brcrum,
1507: 'bread_crumbs_component' => 'User Management'};
1508: if ($env{'form.popup'}) {
1509: $args->{'no_nav_bar'} = 1;
1.406.2.20.2. (raeburn 1510:): $args->{'add_modal'} = 1;
1.351 raeburn 1511: }
1.406.2.20.2. (raeburn 1512:): if (($context eq 'domain') && ($env{'request.role.domain'} eq $ccdomain)) {
1513:): my @toggles;
1514:): if (&Apache::lonnet::allowed('cau',$ccdomain)) {
1515:): my ($isadv,$isauthor) =
1516:): &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1517:): unless ($isauthor) {
1518:): push(@toggles,'requestauthor');
1519:): }
1520:): push(@toggles,('webdav','editors','archive'));
1521:): }
1522:): if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1523:): push(@toggles,('aboutme','blog','portfolio','portaccess','timezone'));
1524:): }
1525:): if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1526:): push(@toggles,('official','unofficial','community','textbook'));
1527:): }
1528:): if (@toggles) {
1529:): my $onload;
1530:): foreach my $item (@toggles) {
1531:): $onload .= "toggleCustom(document.cu,'customtext_$item','custom$item');";
1532:): }
1533:): $args->{'add_entries'} = {
1534:): 'onload' => $onload,
1535:): };
1536:): }
1537:): }
1.351 raeburn 1538: my $start_page =
1539: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1540:
1.25 matthew 1541: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1542: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1543: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1544: <input type="hidden" name="ccuname" value="$ccuname" />
1545: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1546: <input type="hidden" name="pres_value" value="" />
1547: <input type="hidden" name="pres_type" value="" />
1548: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1549: ENDFORMINFO
1.375 raeburn 1550: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1551: if ($context eq 'course') {
1552: $inccourses{$env{'request.course.id'}}=1;
1553: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1554: if ($showcredits) {
1555: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1556: }
1.329 raeburn 1557: } elsif ($context eq 'author') {
1558: $roledom = $env{'request.role.domain'};
1559: } elsif ($context eq 'domain') {
1560: foreach my $key (keys(%env)) {
1561: $roledom = $env{'request.role.domain'};
1562: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1563: $inccourses{$1.'_'.$2}=1;
1564: }
1565: }
1566: } else {
1567: foreach my $key (keys(%env)) {
1568: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1569: $inccourses{$1.'_'.$2}=1;
1570: }
1.2 www 1571: }
1.24 matthew 1572: }
1.389 bisitz 1573: my $title = '';
1.406.2.20.2. (raeburn 1574:): my $need_quota_js;
1.216 raeburn 1575: if ($newuser) {
1.406.2.9 raeburn 1576: my ($portfolioform,$domroleform);
1.267 raeburn 1577: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1578: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1579: # Current user has quota or user tools modification privileges
1.406.2.20.2. (raeburn 1580:): $portfolioform = '<br /><h3>'.
1581:): &mt('User Tools').
1582:): '</h3>'."\n".
1583:): &Apache::loncommon::start_data_table();
1584:): if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1585:): $portfolioform .= &build_tools_display($ccuname,$ccdomain,'tools');
1586:): }
1587:): if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
1588:): $portfolioform .= &user_quotas($ccuname,$ccdomain,'portfolio');
1589:): $need_quota_js = 1;
1590:): }
1591:): $portfolioform .= &Apache::loncommon::end_data_table();
1.134 raeburn 1592: }
1.383 raeburn 1593: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1594: ($ccdomain eq $env{'request.role.domain'})) {
1.406.2.20.2. (raeburn 1595:): $domroleform = &domainrole_req($ccuname,$ccdomain).
1596:): &authoring_defaults($ccuname,$ccdomain);
1597:): $need_quota_js = 1;
1598:): }
1599:): my $readonly;
1600:): unless ($permission->{'cusr'}) {
1601:): $readonly = 1;
1.362 raeburn 1602: }
1.406.2.20.2. (raeburn 1603:): &initialize_authen_forms($ccdomain,$formname,'','',$readonly);
1.188 raeburn 1604: my %lt=&Apache::lonlocal::texthash(
1605: 'lg' => 'Login Data',
1.190 raeburn 1606: 'hs' => "Home Server",
1.188 raeburn 1607: );
1.185 raeburn 1608: $r->print(<<ENDTITLE);
1.110 albertel 1609: $start_page
1.160 raeburn 1610: $response
1.25 matthew 1611: $forminfo
1.31 matthew 1612: <script type="text/javascript" language="Javascript">
1.301 bisitz 1613: // <![CDATA[
1.20 harris41 1614: $loginscript
1.301 bisitz 1615: // ]]>
1.31 matthew 1616: </script>
1.20 harris41 1617: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1618: ENDTITLE
1.213 raeburn 1619: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1620: if ($crstype eq 'Community') {
1.389 bisitz 1621: $title = &mt('Create New User [_1] in domain [_2] as a member',
1622: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1623: } else {
1.389 bisitz 1624: $title = &mt('Create New User [_1] in domain [_2] as a student',
1625: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1626: }
1.389 bisitz 1627: } else {
1628: $title = &mt('Create New User [_1] in domain [_2]',
1629: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1630: }
1.389 bisitz 1631: $r->print('<h2>'.$title.'</h2>'."\n");
1632: $r->print('<div class="LC_left_float">');
1.393 raeburn 1633: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1.406.2.20.2. (raeburn 1634:): $inst_results{$ccuname.':'.$ccdomain},$readonly));
1.393 raeburn 1635: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1636: my ($home_server_pick,$numlib) =
1637: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1638: 'default','hide');
1639: if ($numlib > 1) {
1640: $r->print("
1.185 raeburn 1641: <br />
1.187 raeburn 1642: $lt{'hs'}: $home_server_pick
1643: <br />");
1644: } else {
1645: $r->print($home_server_pick);
1646: }
1.304 raeburn 1647: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1648: $r->print('<br /><h3>'.
1.406.2.20.2. (raeburn 1649:): &mt('Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1650: &Apache::loncommon::start_data_table().
1651: &build_tools_display($ccuname,$ccdomain,
1652: 'requestcourses').
1653: &Apache::loncommon::end_data_table());
1654: }
1.188 raeburn 1655: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1656: $lt{'lg'}.'</h3>');
1.185 raeburn 1657: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1658: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1659: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1660: my ($rules,$ruleorder) =
1661: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1662: if (ref($rules) eq 'HASH') {
1.193 raeburn 1663: if (ref($rules->{$matchedrule}) eq 'HASH') {
1664: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1665: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1666: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1667: } else {
1.193 raeburn 1668: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1669: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1670: if ($authtype =~ /^krb(4|5)$/) {
1671: my $ver = $1;
1672: if ($authparm ne '') {
1673: $fixedauth = <<"KERB";
1674: <input type="hidden" name="login" value="krb" />
1675: <input type="hidden" name="krbver" value="$ver" />
1676: <input type="hidden" name="krbarg" value="$authparm" />
1677: KERB
1678: }
1679: } else {
1680: $fixedauth =
1681: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1682: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1683: $fixedauth .=
1684: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1685: } else {
1.273 raeburn 1686: if ($authtype eq 'int') {
1687: $varauth = '<br />'.
1.301 bisitz 1688: &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 1689: } elsif ($authtype eq 'loc') {
1690: $varauth = '<br />'.
1691: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1692: } else {
1693: $varauth =
1.185 raeburn 1694: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1695: }
1.185 raeburn 1696: }
1697: }
1698: }
1699: } else {
1.190 raeburn 1700: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1701: }
1702: }
1703: if ($authmsg) {
1704: $r->print(<<ENDAUTH);
1705: $fixedauth
1706: $authmsg
1707: $varauth
1708: ENDAUTH
1709: }
1710: } else {
1.190 raeburn 1711: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1712: }
1.406.2.9 raeburn 1713: $r->print($portfolioform.$domroleform);
1.215 raeburn 1714: if ($env{'form.action'} eq 'singlestudent') {
1715: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1716: $permission,$crstype,$ccuname,
1717: $ccdomain,$showcredits));
1.215 raeburn 1718: }
1719: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1720: } else { # user already exists
1.389 bisitz 1721: $r->print($start_page.$forminfo);
1.213 raeburn 1722: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1723: if ($crstype eq 'Community') {
1.389 bisitz 1724: $title = &mt('Enroll one member: [_1] in domain [_2]',
1725: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1726: } else {
1.389 bisitz 1727: $title = &mt('Enroll one student: [_1] in domain [_2]',
1728: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1729: }
1.213 raeburn 1730: } else {
1.406.2.6 raeburn 1731: if ($permission->{'cusr'}) {
1732: $title = &mt('Modify existing user: [_1] in domain [_2]',
1733: '"'.$ccuname.'"','"'.$ccdomain.'"');
1734: } else {
1735: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1736: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.406.2.6 raeburn 1737: }
1.213 raeburn 1738: }
1.389 bisitz 1739: $r->print('<h2>'.$title.'</h2>'."\n");
1740: $r->print('<div class="LC_left_float">');
1.393 raeburn 1741: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1742: $inst_results{$ccuname.':'.$ccdomain}));
1.406.2.6 raeburn 1743: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1744: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.406.2.20.2. (raeburn 1745:): $r->print('<br /><h3>'.&mt('Can Request Creation of Courses/Communities in this Domain?').'</h3>'."\n".
1.300 raeburn 1746: &Apache::loncommon::start_data_table());
1.314 raeburn 1747: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1748: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1749: } else {
1750: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1751: $env{'request.role.domain'}));
1752: }
1753: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1754: }
1.199 raeburn 1755: $r->print('</div>');
1.406.2.20.2. (raeburn 1756:): my @order = ('auth','quota','tools','requestauthor','authordefaults');
1.362 raeburn 1757: my %user_text;
1758: my ($isadv,$isauthor) =
1.406.2.6 raeburn 1759: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.406.2.20.2. (raeburn 1760:): if (((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1.406.2.6 raeburn 1761: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1.406.2.20.2. (raeburn 1762:): ($env{'request.role.domain'} eq $ccdomain)) {
1763:): if (!$isauthor) {
1764:): $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1765:): }
1766:): $user_text{'authordefaults'} = &authoring_defaults($ccuname,$ccdomain);
1767:): if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
1768:): $need_quota_js = 1;
1769:): }
1.362 raeburn 1770: }
1.406.2.17 raeburn 1771: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
1.267 raeburn 1772: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.406.2.6 raeburn 1773: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1774: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.406.2.20.2. (raeburn 1775:): $user_text{'quota'} = '<br /><h3>'.&mt('User Tools').'</h3>'."\n".
1776:): &Apache::loncommon::start_data_table();
1777:): if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
1778:): (&Apache::lonnet::allowed('udp',$ccdomain))) {
1779:): $user_text{'quota'} .= &build_tools_display($ccuname,$ccdomain,'tools');
1780:): }
1.188 raeburn 1781: # Current user has quota modification privileges
1.406.2.20.2. (raeburn 1782:): if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1783:): (&Apache::lonnet::allowed('udp',$ccdomain))) {
1784:): $user_text{'quota'} .= &user_quotas($ccuname,$ccdomain,'portfolio');
1785:): $need_quota_js = 1;
1786:): }
1787:): $user_text{'quota'} .= &Apache::loncommon::end_data_table();
1.267 raeburn 1788: }
1789: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1790: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1791: my %lt=&Apache::lonlocal::texthash(
1.406.2.20.2. (raeburn 1792:): 'dska' => "Disk quotas for user's portfolio",
1793:): 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
1.267 raeburn 1794: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1795: );
1.362 raeburn 1796: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1797: <h3>$lt{'dska'}</h3>
1798: $lt{'youd'} $lt{'ichr'}: $ccdomain
1799: ENDNOPORTPRIV
1.267 raeburn 1800: }
1801: }
1802: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1803: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1804: my %lt=&Apache::lonlocal::texthash(
1805: 'utav' => "User Tools Availability",
1.406.2.20.2. (raeburn 1806:): 'yodo' => "You do not have privileges to modify Portfolio, Blog, Personal Information Page, or Time Zone settings for this user.",
1.267 raeburn 1807: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1808: );
1.362 raeburn 1809: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1810: <h3>$lt{'utav'}</h3>
1811: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1812: ENDNOTOOLSPRIV
1813: }
1.188 raeburn 1814: }
1.362 raeburn 1815: my $gotdiv = 0;
1816: foreach my $item (@order) {
1817: if ($user_text{$item} ne '') {
1818: unless ($gotdiv) {
1819: $r->print('<div class="LC_left_float">');
1820: $gotdiv = 1;
1821: }
1822: $r->print('<br />'.$user_text{$item});
1823: }
1824: }
1825: if ($env{'form.action'} eq 'singlestudent') {
1826: unless ($gotdiv) {
1827: $r->print('<div class="LC_left_float">');
1.213 raeburn 1828: }
1.375 raeburn 1829: my $credits;
1830: if ($showcredits) {
1831: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1832: if ($credits eq '') {
1833: $credits = $defaultcredits;
1834: }
1835: }
1.374 raeburn 1836: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1837: $permission,$crstype,$ccuname,
1838: $ccdomain,$showcredits));
1.374 raeburn 1839: }
1.362 raeburn 1840: if ($gotdiv) {
1841: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1842: }
1.406.2.6 raeburn 1843: my $statuses;
1844: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1845: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1846: $statuses = ['active'];
1847: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1848: ($env{'request.course.sec'} &&
1849: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1850: $statuses = ['active'];
1851: }
1.217 raeburn 1852: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1853: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.406.2.6 raeburn 1854: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1855: }
1.25 matthew 1856: } ## End of new user/old user logic
1.218 raeburn 1857: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1858: my $btntxt;
1859: if ($crstype eq 'Community') {
1860: $btntxt = &mt('Enroll Member');
1861: } else {
1862: $btntxt = &mt('Enroll Student');
1863: }
1864: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.406.2.6 raeburn 1865: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1866: $r->print('<div class="LC_left_float">'.
1867: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1868: my $addrolesdisplay = 0;
1869: if ($context eq 'domain' || $context eq 'author') {
1870: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1871: }
1872: if ($context eq 'domain') {
1.357 raeburn 1873: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1874: if (!$addrolesdisplay) {
1875: $addrolesdisplay = $add_domainroles;
1.2 www 1876: }
1.375 raeburn 1877: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1878: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1879: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1880: } elsif ($context eq 'author') {
1881: if ($addrolesdisplay) {
1.393 raeburn 1882: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1883: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1884: if ($newuser) {
1.301 bisitz 1885: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1886: } else {
1.406.2.20.2. (raeburn 1887:): $r->print(' onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1888: }
1.188 raeburn 1889: } else {
1.393 raeburn 1890: $r->print('</fieldset></div>'.
1891: '<div class="LC_clear_float_footer"></div>'.
1892: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1893: &mt('Back to previous page').'</a>');
1.188 raeburn 1894: }
1895: } else {
1.375 raeburn 1896: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1897: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1898: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1899: }
1.88 raeburn 1900: }
1.188 raeburn 1901: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1902: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1903: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.406.2.20.2. (raeburn 1904:): if ($need_quota_js) {
1905:): $r->print(&user_quota_js());
1906:): }
1.218 raeburn 1907: return;
1.2 www 1908: }
1.1 www 1909:
1.213 raeburn 1910: sub singleuser_breadcrumb {
1.406.2.7 raeburn 1911: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1912: my %breadcrumb_text;
1913: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1914: if ($crstype eq 'Community') {
1915: $breadcrumb_text{'search'} = 'Enroll a member';
1916: } else {
1917: $breadcrumb_text{'search'} = 'Enroll a student';
1918: }
1.406.2.7 raeburn 1919: $breadcrumb_text{'userpicked'} = 'Select a user';
1920: $breadcrumb_text{'modify'} = 'Set section/dates';
1.406.2.5 raeburn 1921: } elsif ($env{'form.action'} eq 'accesslogs') {
1922: $breadcrumb_text{'search'} = 'View access logs for a user';
1.406.2.7 raeburn 1923: $breadcrumb_text{'userpicked'} = 'Select a user';
1924: $breadcrumb_text{'activity'} = 'Activity';
1925: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1926: (!&Apache::lonnet::allowed('mau',$domain))) {
1927: $breadcrumb_text{'search'} = "View user's roles";
1928: $breadcrumb_text{'userpicked'} = 'Select a user';
1929: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1930: } else {
1.229 raeburn 1931: $breadcrumb_text{'search'} = 'Create/modify a user';
1.406.2.7 raeburn 1932: $breadcrumb_text{'userpicked'} = 'Select a user';
1933: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1934: }
1935: return %breadcrumb_text;
1936: }
1937:
1938: sub date_sections_select {
1.375 raeburn 1939: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1940: $showcredits) = @_;
1941: my $credits;
1942: if ($showcredits) {
1943: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1944: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1945: if ($credits eq '') {
1946: $credits = $defaultcredits;
1947: }
1948: }
1.213 raeburn 1949: my $cid = $env{'request.course.id'};
1950: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1951: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1952: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1953: undef,$formname,$permission);
1954: my $rowtitle = 'Section';
1.375 raeburn 1955: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1956: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1957: $permission,$context,'',$crstype,
1958: $showcredits,$credits);
1.213 raeburn 1959: my $output = $date_table.$secbox;
1960: return $output;
1961: }
1962:
1.216 raeburn 1963: sub validation_javascript {
1.375 raeburn 1964: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.406.2.20.2. (raeburn 1965:): $loaditem,$permission) = @_;
1.216 raeburn 1966: my $dc_setcourse_code = '';
1967: my $nondc_setsection_code = '';
1968: if ($context eq 'domain') {
1.406.2.20.2. (raeburn 1969:): if ((ref($permission) eq 'HASH') && ($permission->{'cusr'})) {
1970:): my $dcdom = $env{'request.role.domain'};
1971:): $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1972:): $dc_setcourse_code =
1973:): &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1974:): }
1.216 raeburn 1975: } else {
1.227 raeburn 1976: my $checkauth;
1977: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1978: $checkauth = 1;
1979: }
1980: if ($context eq 'course') {
1981: $nondc_setsection_code =
1982: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1983: undef,$checkauth,
1984: $crstype);
1.227 raeburn 1985: }
1986: if ($checkauth) {
1987: $nondc_setsection_code .=
1988: &Apache::lonuserutils::verify_authen($formname,$context);
1989: }
1.216 raeburn 1990: }
1991: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1992: $nondc_setsection_code,$groupslist);
1993: my ($jsback,$elements) = &crumb_utilities();
1994: $js .= "\n".
1.301 bisitz 1995: '<script type="text/javascript">'."\n".
1996: '// <![CDATA['."\n".
1997: $jsback."\n".
1998: '// ]]>'."\n".
1999: '</script>'."\n";
1.216 raeburn 2000: return $js;
2001: }
2002:
1.217 raeburn 2003: sub display_existing_roles {
1.375 raeburn 2004: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.406.2.6 raeburn 2005: $showcredits,$statuses) = @_;
1.329 raeburn 2006: my $now=time;
1.406.2.6 raeburn 2007: my $showall = 1;
2008: my ($showexpired,$showactive);
2009: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
2010: $showall = 0;
2011: if (grep(/^expired$/,@{$statuses})) {
2012: $showexpired = 1;
2013: }
2014: if (grep(/^active$/,@{$statuses})) {
2015: $showactive = 1;
2016: }
2017: if ($showexpired && $showactive) {
2018: $showall = 1;
2019: }
2020: }
1.329 raeburn 2021: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 2022: 'rer' => "Existing Roles",
2023: 'rev' => "Revoke",
2024: 'del' => "Delete",
2025: 'ren' => "Re-Enable",
2026: 'rol' => "Role",
2027: 'ext' => "Extent",
1.375 raeburn 2028: 'crd' => "Credits",
1.217 raeburn 2029: 'sta' => "Start",
2030: 'end' => "End",
2031: );
1.329 raeburn 2032: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
2033: if ($context eq 'course' || $context eq 'author') {
2034: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
2035: my %roleshash =
2036: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
2037: ['active','previous','future'],\@roles,$roledom,1);
2038: foreach my $key (keys(%roleshash)) {
2039: my ($start,$end) = split(':',$roleshash{$key});
2040: next if ($start eq '-1' || $end eq '-1');
2041: my ($rnum,$rdom,$role,$sec) = split(':',$key);
2042: if ($context eq 'course') {
2043: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
2044: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
2045: } elsif ($context eq 'author') {
1.406.2.20.2. (raeburn 2046:): if ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2047:): my ($audom,$auname) = ($1,$2);
2048:): next unless (($rnum eq $auname) && ($rdom eq $audom));
2049:): } else {
2050:): next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
2051:): }
1.329 raeburn 2052: }
2053: my ($newkey,$newvalue,$newrole);
2054: $newkey = '/'.$rdom.'/'.$rnum;
2055: if ($sec ne '') {
2056: $newkey .= '/'.$sec;
2057: }
2058: $newvalue = $role;
2059: if ($role =~ /^cr/) {
2060: $newrole = 'cr';
2061: } else {
2062: $newrole = $role;
2063: }
2064: $newkey .= '_'.$newrole;
2065: if ($start ne '' && $end ne '') {
2066: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 2067: } elsif ($end ne '') {
2068: $newvalue .= '_'.$end;
1.329 raeburn 2069: }
2070: $rolesdump{$newkey} = $newvalue;
2071: }
2072: } else {
1.360 raeburn 2073: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 2074: }
2075: # Build up table of user roles to allow revocation and re-enabling of roles.
2076: my ($tmp) = keys(%rolesdump);
2077: return if ($tmp =~ /^(con_lost|error)/i);
2078: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
2079: my $b1=join('_',(split('_',$b))[1,0]);
2080: return $a1 cmp $b1;
2081: } keys(%rolesdump)) {
2082: next if ($area =~ /^rolesdef/);
2083: my $envkey=$area;
2084: my $role = $rolesdump{$area};
2085: my $thisrole=$area;
2086: $area =~ s/\_\w\w$//;
2087: my ($role_code,$role_end_time,$role_start_time) =
2088: split(/_/,$role);
1.406.2.6 raeburn 2089: my $active=1;
2090: $active=0 if (($role_end_time) && ($now>$role_end_time));
2091: if ($active) {
2092: next unless($showall || $showactive);
2093: } else {
2094: next unless($showall || $showexpired);
2095: }
1.217 raeburn 2096: # Is this a custom role? Get role owner and title.
1.329 raeburn 2097: my ($croleudom,$croleuname,$croletitle)=
2098: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
2099: my $allowed=0;
2100: my $delallowed=0;
2101: my $sortkey=$role_code;
2102: my $class='Unknown';
1.375 raeburn 2103: my $credits='';
1.406.2.6 raeburn 2104: my $csec;
1.406.2.7 raeburn 2105: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 2106: $class='Course';
2107: my ($coursedom,$coursedir) = ($1,$2);
2108: my $cid = $1.'_'.$2;
2109: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.406.2.7 raeburn 2110: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 2111: my %coursedata=
2112: &Apache::lonnet::coursedescription($cid);
2113: if ($coursedir =~ /^$match_community$/) {
2114: $class='Community';
2115: }
2116: $sortkey.="\0$coursedom";
2117: my $carea;
2118: if (defined($coursedata{'description'})) {
2119: $carea=$coursedata{'description'}.
2120: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
2121: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
2122: $sortkey.="\0".$coursedata{'description'};
2123: } else {
2124: if ($class eq 'Community') {
2125: $carea=&mt('Unavailable community').': '.$area;
2126: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 2127: } else {
2128: $carea=&mt('Unavailable course').': '.$area;
2129: $sortkey.="\0".&mt('Unavailable course').': '.$area;
2130: }
1.329 raeburn 2131: }
2132: $sortkey.="\0$coursedir";
2133: $inccourses->{$cid}=1;
1.375 raeburn 2134: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
2135: my $defaultcredits = $coursedata{'internal.defaultcredits'};
2136: $credits =
2137: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
2138: $coursedom,$coursedir);
2139: if ($credits eq '') {
2140: $credits = $defaultcredits;
2141: }
2142: }
1.329 raeburn 2143: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
2144: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
2145: $allowed=1;
2146: }
2147: unless ($allowed) {
1.365 raeburn 2148: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 2149: if ($isowner) {
2150: if (($role_code eq 'co') && ($class eq 'Community')) {
2151: $allowed = 1;
2152: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
2153: $allowed = 1;
2154: }
1.217 raeburn 2155: }
1.329 raeburn 2156: }
2157: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
2158: (&Apache::lonnet::allowed('dro',$ccdomain))) {
2159: $delallowed=1;
2160: }
1.217 raeburn 2161: # - custom role. Needs more info, too
1.329 raeburn 2162: if ($croletitle) {
2163: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
2164: $allowed=1;
2165: $thisrole.='.'.$role_code;
1.217 raeburn 2166: }
1.329 raeburn 2167: }
1.406.2.6 raeburn 2168: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
2169: $csec = $2;
2170: $carea.='<br />'.&mt('Section: [_1]',$csec);
2171: $sortkey.="\0$csec";
1.329 raeburn 2172: if (!$allowed) {
1.406.2.6 raeburn 2173: if ($env{'request.course.sec'} eq $csec) {
2174: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 2175: $allowed = 1;
1.217 raeburn 2176: }
2177: }
2178: }
1.329 raeburn 2179: }
2180: $area=$carea;
2181: } else {
2182: $sortkey.="\0".$area;
2183: # Determine if current user is able to revoke privileges
2184: if ($area=~m{^/($match_domain)/}) {
2185: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
2186: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
2187: $allowed=1;
1.217 raeburn 2188: }
1.329 raeburn 2189: if (((&Apache::lonnet::allowed('dro',$1)) ||
2190: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
2191: ($role_code ne 'dc')) {
2192: $delallowed=1;
1.217 raeburn 2193: }
1.329 raeburn 2194: } else {
2195: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 2196: $allowed=1;
2197: }
2198: }
1.363 raeburn 2199: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 2200: $class='Authoring Space';
1.329 raeburn 2201: } elsif ($role_code eq 'su') {
2202: $class='System';
1.217 raeburn 2203: } else {
1.329 raeburn 2204: $class='Domain';
1.217 raeburn 2205: }
1.329 raeburn 2206: }
2207: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
2208: $area=~m{/($match_domain)/($match_username)};
2209: if (&Apache::lonuserutils::authorpriv($2,$1)) {
2210: $allowed=1;
1.406.2.20.2. (raeburn 2211:): } elsif (&Apache::lonuserutils::coauthorpriv($2,$1)) {
2212:): $allowed=1;
1.217 raeburn 2213: } else {
1.329 raeburn 2214: $allowed=0;
1.217 raeburn 2215: }
1.329 raeburn 2216: }
2217: my $row = '';
1.406.2.6 raeburn 2218: if ($showall) {
2219: $row.= '<td>';
2220: if (($active) && ($allowed)) {
2221: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1.217 raeburn 2222: } else {
1.406.2.6 raeburn 2223: if ($active) {
2224: $row.=' ';
2225: } else {
2226: $row.=&mt('expired or revoked');
2227: }
1.217 raeburn 2228: }
1.406.2.6 raeburn 2229: $row.='</td><td>';
2230: if ($allowed && !$active) {
2231: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
2232: } else {
2233: $row.=' ';
2234: }
2235: $row.='</td><td>';
2236: if ($delallowed) {
2237: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
2238: } else {
2239: $row.=' ';
2240: }
2241: $row.= '</td>';
1.329 raeburn 2242: }
2243: my $plaintext='';
2244: if (!$croletitle) {
1.375 raeburn 2245: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
2246: if (($showcredits) && ($credits ne '')) {
2247: $plaintext .= '<br/ ><span class="LC_nobreak">'.
2248: '<span class="LC_fontsize_small">'.
2249: &mt('Credits: [_1]',$credits).
2250: '</span></span>';
2251: }
1.329 raeburn 2252: } else {
2253: $plaintext=
1.395 bisitz 2254: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 2255: '"'.$croletitle.'"',
2256: '<br />',
2257: $croleuname.':'.$croleudom);
1.329 raeburn 2258: }
1.406.2.6 raeburn 2259: $row.= '<td>'.$plaintext.'</td>'.
2260: '<td>'.$area.'</td>'.
2261: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
2262: : ' ' ).'</td>'.
2263: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
2264: : ' ' ).'</td>';
1.329 raeburn 2265: $sortrole{$sortkey}=$envkey;
2266: $roletext{$envkey}=$row;
2267: $roleclass{$envkey}=$class;
1.406.2.6 raeburn 2268: if ($allowed) {
2269: $rolepriv{$envkey}='edit';
2270: } else {
2271: if ($context eq 'domain') {
1.406.2.7 raeburn 2272: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
2273: ($envkey=~m{^/$ccdomain/})) {
1.406.2.6 raeburn 2274: $rolepriv{$envkey}='view';
2275: }
2276: } elsif ($context eq 'course') {
2277: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
2278: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
2279: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
2280: $rolepriv{$envkey}='view';
2281: }
2282: }
2283: }
1.329 raeburn 2284: } # end of foreach (table building loop)
2285:
2286: my $rolesdisplay = 0;
2287: my %output = ();
1.377 raeburn 2288: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2289: $output{$type} = '';
2290: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2291: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2292: $output{$type}.=
2293: &Apache::loncommon::start_data_table_row().
2294: $roletext{$sortrole{$which}}.
2295: &Apache::loncommon::end_data_table_row();
1.217 raeburn 2296: }
1.329 raeburn 2297: }
2298: unless($output{$type} eq '') {
2299: $output{$type} = '<tr class="LC_info_row">'.
2300: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2301: $output{$type};
2302: $rolesdisplay = 1;
2303: }
2304: }
2305: if ($rolesdisplay == 1) {
2306: my $contextrole='';
2307: if ($env{'request.course.id'}) {
2308: if (&Apache::loncommon::course_type() eq 'Community') {
2309: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2310: } else {
1.329 raeburn 2311: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2312: }
1.329 raeburn 2313: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2314: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.406.2.20.2. (raeburn 2315:): } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)/$}) {
2316:): $contextrole = &mt('Existing Co-Author Roles in [_1] Authoring Space',
2317:): '<i>'.$1.'_'.$2.'</i>');
1.329 raeburn 2318: } else {
1.406.2.6 raeburn 2319: if ($showall) {
2320: $contextrole = &mt('Existing Roles in this Domain');
2321: } elsif ($showactive) {
2322: $contextrole = &mt('Unexpired Roles in this Domain');
2323: } elsif ($showexpired) {
2324: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2325: }
1.329 raeburn 2326: }
1.393 raeburn 2327: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2328: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2329: &Apache::loncommon::start_data_table("LC_createuser").
1.406.2.6 raeburn 2330: &Apache::loncommon::start_data_table_header_row());
2331: if ($showall) {
2332: $r->print(
2333: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
2334: );
2335: } elsif ($showexpired) {
2336: $r->print('<th>'.$lt{'rev'}.'</th>');
2337: }
2338: $r->print(
2339: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2340: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2341: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2342: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2343: if ($output{$type}) {
2344: $r->print($output{$type}."\n");
1.217 raeburn 2345: }
2346: }
1.375 raeburn 2347: $r->print(&Apache::loncommon::end_data_table().
2348: '</fieldset></div>');
1.329 raeburn 2349: }
1.217 raeburn 2350: return;
2351: }
2352:
1.218 raeburn 2353: sub new_coauthor_roles {
2354: my ($r,$ccuname,$ccdomain) = @_;
2355: my $addrolesdisplay = 0;
2356: #
2357: # Co-Author
2358: #
1.406.2.20.2. (raeburn 2359:): my ($cuname,$cudom);
2360:): if (($env{'request.role'} eq "au./$env{'user.domain'}/") ||
2361:): ($env{'request.role'} eq "dc./$env{'user.domain'}/")) {
2362:): $cuname=$env{'user.name'};
2363:): $cudom=$env{'request.role.domain'};
1.218 raeburn 2364: # No sense in assigning co-author role to yourself
1.406.2.20.2. (raeburn 2365:): if ((&Apache::lonuserutils::authorpriv($cuname,$cudom)) &&
2366:): ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2367:): $addrolesdisplay = 1;
2368:): }
2369:): } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2370:): ($cudom,$cuname) = ($1,$2);
2371:): if ((&Apache::lonuserutils::coauthorpriv($cuname,$cudom)) &&
2372:): ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain) &&
2373:): ($cudom ne $ccdomain || $cuname ne $ccuname)) {
2374:): $addrolesdisplay = 1;
2375:): }
2376:): }
2377:): if ($addrolesdisplay) {
1.218 raeburn 2378: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2379: 'cs' => "Authoring Space",
1.218 raeburn 2380: 'act' => "Activate",
2381: 'rol' => "Role",
2382: 'ext' => "Extent",
2383: 'sta' => "Start",
2384: 'end' => "End",
2385: 'cau' => "Co-Author",
2386: 'caa' => "Assistant Co-Author",
2387: 'ssd' => "Set Start Date",
2388: 'sed' => "Set End Date"
2389: );
2390: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2391: &Apache::loncommon::start_data_table()."\n".
2392: &Apache::loncommon::start_data_table_header_row()."\n".
2393: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2394: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2395: '<th>'.$lt{'end'}.'</th>'."\n".
2396: &Apache::loncommon::end_data_table_header_row()."\n".
2397: &Apache::loncommon::start_data_table_row().'
2398: <td>
1.291 bisitz 2399: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2400: </td>
2401: <td>'.$lt{'cau'}.'</td>
2402: <td>'.$cudom.'_'.$cuname.'</td>
2403: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2404: <a href=
2405: "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>
2406: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2407: <a href=
2408: "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".
2409: &Apache::loncommon::end_data_table_row()."\n".
2410: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2411: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2412: <td>'.$lt{'caa'}.'</td>
2413: <td>'.$cudom.'_'.$cuname.'</td>
2414: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2415: <a href=
2416: "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>
2417: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2418: <a href=
2419: "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".
2420: &Apache::loncommon::end_data_table_row()."\n".
2421: &Apache::loncommon::end_data_table());
2422: } elsif ($env{'request.role'} =~ /^au\./) {
2423: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2424: $env{'request.role.domain'}))) {
2425: $r->print('<span class="LC_error">'.
2426: &mt('You do not have privileges to assign co-author roles.').
2427: '</span>');
2428: } elsif (($env{'user.name'} eq $ccuname) &&
2429: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2430: $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 2431: }
1.406.2.20.2. (raeburn 2432:): } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2433:): if (!(&Apache::lonuserutils::coauthorpriv($2,$1))) {
2434:): $r->print('<span class="LC_error">'.
2435:): &mt('You do not have privileges to assign co-author roles.').
2436:): '</span>');
2437:): } elsif (($env{'user.name'} eq $ccuname) &&
2438:): ($env{'user.domain'} eq $ccdomain)) {
2439:): $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'));
2440:): } elsif (($cudom eq $ccdomain) && ($cuname eq $ccuname)) {
2441:): $r->print(&mt("Assigning a co-author or assistant co-author role to an Authoring Space's author is not permitted"));
2442:): }
1.218 raeburn 2443: }
2444: return $addrolesdisplay;;
2445: }
2446:
2447: sub new_domain_roles {
1.357 raeburn 2448: my ($r,$ccdomain) = @_;
1.218 raeburn 2449: my $addrolesdisplay = 0;
2450: #
2451: # Domain level
2452: #
2453: my $num_domain_level = 0;
2454: my $domaintext =
2455: '<h4>'.&mt('Domain Level').'</h4>'.
2456: &Apache::loncommon::start_data_table().
2457: &Apache::loncommon::start_data_table_header_row().
2458: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2459: &mt('Extent').'</th>'.
2460: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2461: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2462: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2463: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2464: foreach my $role (@allroles) {
2465: next if ($role eq 'ad');
1.357 raeburn 2466: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2467: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2468: my $plrole=&Apache::lonnet::plaintext($role);
2469: my %lt=&Apache::lonlocal::texthash(
2470: 'ssd' => "Set Start Date",
2471: 'sed' => "Set End Date"
2472: );
2473: $num_domain_level ++;
2474: $domaintext .=
2475: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2476: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2477: <td>'.$plrole.'</td>
2478: <td>'.$thisdomain.'</td>
2479: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2480: <a href=
2481: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2482: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2483: <a href=
2484: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2485: &Apache::loncommon::end_data_table_row();
2486: }
2487: }
2488: }
2489: $domaintext.= &Apache::loncommon::end_data_table();
2490: if ($num_domain_level > 0) {
2491: $r->print($domaintext);
2492: $addrolesdisplay = 1;
2493: }
2494: return $addrolesdisplay;
2495: }
2496:
1.188 raeburn 2497: sub user_authentication {
1.406.2.17 raeburn 2498: my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
1.188 raeburn 2499: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2500: my $outcome;
1.406.2.6 raeburn 2501: my %lt=&Apache::lonlocal::texthash(
2502: 'err' => "ERROR",
2503: 'uuas' => "This user has an unrecognized authentication scheme",
2504: 'adcs' => "Please alert a domain coordinator of this situation",
2505: 'sldb' => "Please specify login data below",
2506: 'ld' => "Login Data"
2507: );
1.188 raeburn 2508: # Check for a bad authentication type
2509: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2510: # bad authentication scheme
2511: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2512: &initialize_authen_forms($ccdomain,$formname);
2513:
1.190 raeburn 2514: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2515: $outcome = <<ENDBADAUTH;
2516: <script type="text/javascript" language="Javascript">
1.301 bisitz 2517: // <![CDATA[
1.188 raeburn 2518: $loginscript
1.301 bisitz 2519: // ]]>
1.188 raeburn 2520: </script>
2521: <span class="LC_error">$lt{'err'}:
2522: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2523: <h3>$lt{'ld'}</h3>
2524: $choices
2525: ENDBADAUTH
2526: } else {
2527: # This user is not allowed to modify the user's
2528: # authentication scheme, so just notify them of the problem
2529: $outcome = <<ENDBADAUTH;
2530: <span class="LC_error"> $lt{'err'}:
2531: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2532: </span>
2533: ENDBADAUTH
2534: }
2535: } else { # Authentication type is valid
1.227 raeburn 2536: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2537: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2538: &modify_login_block($ccdomain,$currentauth);
2539: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2540: # Current user has login modification privileges
2541: $outcome =
2542: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2543: '// <![CDATA['."\n".
1.188 raeburn 2544: $loginscript."\n".
1.301 bisitz 2545: '// ]]>'."\n".
1.188 raeburn 2546: '</script>'."\n".
2547: '<h3>'.$lt{'ld'}.'</h3>'.
2548: &Apache::loncommon::start_data_table().
1.205 raeburn 2549: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2550: '<td>'.$authformnop;
1.406.2.6 raeburn 2551: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2552: $outcome .= '</td>'."\n".
2553: &Apache::loncommon::end_data_table_row().
2554: &Apache::loncommon::start_data_table_row().
2555: '<td>'.$authformcurrent.'</td>'.
2556: &Apache::loncommon::end_data_table_row()."\n";
2557: } else {
1.200 raeburn 2558: $outcome .= ' ('.$authformcurrent.')</td>'.
2559: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2560: }
1.406.2.6 raeburn 2561: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2562: foreach my $item (@authform_others) {
2563: $outcome .= &Apache::loncommon::start_data_table_row().
2564: '<td>'.$item.'</td>'.
2565: &Apache::loncommon::end_data_table_row()."\n";
2566: }
1.188 raeburn 2567: }
1.205 raeburn 2568: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2569: } else {
1.406.2.17 raeburn 2570: if (($currentauth =~ /^internal:/) &&
2571: (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
2572: $outcome = <<"ENDJS";
2573: <script type="text/javascript">
2574: // <![CDATA[
2575: function togglePwd(form) {
2576: if (form.newintpwd.length) {
2577: if (document.getElementById('LC_ownersetpwd')) {
2578: for (var i=0; i<form.newintpwd.length; i++) {
2579: if (form.newintpwd[i].checked) {
2580: if (form.newintpwd[i].value == 1) {
2581: document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
2582: } else {
2583: document.getElementById('LC_ownersetpwd').style.display = 'none';
2584: }
2585: }
2586: }
2587: }
2588: }
2589: }
2590: // ]]>
2591: </script>
2592: ENDJS
2593:
2594: $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
2595: &Apache::loncommon::start_data_table().
2596: &Apache::loncommon::start_data_table_row().
2597: '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
2598: '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
2599: &mt('No').'</label>'.(' 'x2).
2600: '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
2601: '<div id="LC_ownersetpwd" style="display:none">'.
2602: ' '.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
2603: '<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>'.
2604: &Apache::loncommon::end_data_table_row().
2605: &Apache::loncommon::end_data_table();
2606: }
1.406.2.6 raeburn 2607: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2608: # Current user has rights to view domain preferences for user's domain
2609: my $result;
2610: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2611: my ($krbver,$krbrealm) = ($1,$2);
2612: if ($krbrealm eq '') {
2613: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2614: } else {
2615: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.406.2.9 raeburn 2616: $krbrealm,$krbver);
1.406.2.6 raeburn 2617: }
2618: } elsif ($currentauth =~ /^internal:/) {
2619: $result = &mt('Currently internally authenticated.');
2620: } elsif ($currentauth =~ /^localauth:/) {
2621: $result = &mt('Currently using local (institutional) authentication.');
2622: } elsif ($currentauth =~ /^unix:/) {
2623: $result = &mt('Currently Filesystem Authenticated.');
2624: }
2625: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2626: &Apache::loncommon::start_data_table().
2627: &Apache::loncommon::start_data_table_row().
2628: '<td>'.$result.'</td>'.
2629: &Apache::loncommon::end_data_table_row()."\n".
2630: &Apache::loncommon::end_data_table();
2631: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2632: my %lt=&Apache::lonlocal::texthash(
2633: 'ccld' => "Change Current Login Data",
2634: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2635: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2636: );
2637: $outcome .= <<ENDNOPRIV;
2638: <h3>$lt{'ccld'}</h3>
2639: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2640: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2641: ENDNOPRIV
2642: }
2643: }
2644: } ## End of "check for bad authentication type" logic
2645: return $outcome;
2646: }
2647:
1.187 raeburn 2648: sub modify_login_block {
2649: my ($dom,$currentauth) = @_;
2650: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2651: my ($authnum,%can_assign) =
2652: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2653: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2654: if ($currentauth=~/^krb(4|5):/) {
2655: $authformcurrent=$authformkrb;
2656: if ($can_assign{'int'}) {
1.205 raeburn 2657: push(@authform_others,$authformint);
1.187 raeburn 2658: }
2659: if ($can_assign{'loc'}) {
1.205 raeburn 2660: push(@authform_others,$authformloc);
1.187 raeburn 2661: }
2662: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2663: $show_override_msg = 1;
2664: }
2665: } elsif ($currentauth=~/^internal:/) {
2666: $authformcurrent=$authformint;
2667: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2668: push(@authform_others,$authformkrb);
1.187 raeburn 2669: }
2670: if ($can_assign{'loc'}) {
1.205 raeburn 2671: push(@authform_others,$authformloc);
1.187 raeburn 2672: }
2673: if ($can_assign{'int'}) {
2674: $show_override_msg = 1;
2675: }
2676: } elsif ($currentauth=~/^unix:/) {
2677: $authformcurrent=$authformfsys;
2678: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2679: push(@authform_others,$authformkrb);
1.187 raeburn 2680: }
2681: if ($can_assign{'int'}) {
1.205 raeburn 2682: push(@authform_others,$authformint);
1.187 raeburn 2683: }
2684: if ($can_assign{'loc'}) {
1.205 raeburn 2685: push(@authform_others,$authformloc);
1.187 raeburn 2686: }
2687: if ($can_assign{'fsys'}) {
2688: $show_override_msg = 1;
2689: }
2690: } elsif ($currentauth=~/^localauth:/) {
2691: $authformcurrent=$authformloc;
2692: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2693: push(@authform_others,$authformkrb);
1.187 raeburn 2694: }
2695: if ($can_assign{'int'}) {
1.205 raeburn 2696: push(@authform_others,$authformint);
1.187 raeburn 2697: }
2698: if ($can_assign{'loc'}) {
2699: $show_override_msg = 1;
2700: }
2701: }
2702: if ($show_override_msg) {
1.205 raeburn 2703: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2704: '</td></tr>'."\n".
2705: '<tr><td> </td>'.
2706: '<td><b>'.&mt('Currently in use').'</b></td>'.
2707: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2708: &mt('will override current values').
1.205 raeburn 2709: '</span></td></tr></table>';
1.187 raeburn 2710: }
1.205 raeburn 2711: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2712: }
2713:
1.188 raeburn 2714: sub personal_data_display {
1.406.2.20.2. (raeburn 2715:): my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$readonly,$rolesarray,$now,
1.406.2.20 raeburn 2716: $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
1.406.2.20.2. (raeburn 2717:): my ($output,%userenv,%canmodify,%canmodify_status,$disabled);
1.219 raeburn 2718: my @userinfo = ('firstname','middlename','lastname','generation',
2719: 'permanentemail','id');
1.252 raeburn 2720: my $rowcount = 0;
2721: my $editable = 0;
1.391 raeburn 2722: my %textboxsize = (
2723: firstname => '15',
2724: middlename => '15',
2725: lastname => '15',
2726: generation => '5',
2727: permanentemail => '25',
2728: id => '15',
2729: );
2730:
2731: my %lt=&Apache::lonlocal::texthash(
2732: 'pd' => "Personal Data",
2733: 'firstname' => "First Name",
2734: 'middlename' => "Middle Name",
2735: 'lastname' => "Last Name",
2736: 'generation' => "Generation",
2737: 'permanentemail' => "Permanent e-mail address",
2738: 'id' => "Student/Employee ID",
2739: 'lg' => "Login Data",
2740: 'inststatus' => "Affiliation",
2741: 'email' => 'E-mail address',
2742: 'valid' => 'Validation',
1.406.2.16 raeburn 2743: 'username' => 'Username',
1.391 raeburn 2744: );
2745:
2746: %canmodify_status =
1.286 raeburn 2747: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2748: ['inststatus'],$rolesarray);
1.253 raeburn 2749: if (!$newuser) {
1.188 raeburn 2750: # Get the users information
2751: %userenv = &Apache::lonnet::get('environment',
2752: ['firstname','middlename','lastname','generation',
1.286 raeburn 2753: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2754: %canmodify =
2755: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2756: \@userinfo,$rolesarray);
1.257 raeburn 2757: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2758: if ($newuser eq 'email') {
1.396 raeburn 2759: if (ref($emailusername) eq 'HASH') {
2760: if (ref($emailusername->{$usertype}) eq 'HASH') {
2761: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.406.2.16 raeburn 2762: @userinfo = ();
1.396 raeburn 2763: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2764: foreach my $field (@{$infofields}) {
2765: if ($emailusername->{$usertype}->{$field}) {
2766: push(@userinfo,$field);
2767: $canmodify{$field} = 1;
2768: unless ($textboxsize{$field}) {
2769: $textboxsize{$field} = 25;
2770: }
2771: unless ($lt{$field}) {
2772: $lt{$field} = $infotitles->{$field};
2773: }
2774: if ($emailusername->{$usertype}->{$field} eq 'required') {
2775: $lt{$field} .= '<b>*</b>';
2776: }
1.391 raeburn 2777: }
2778: }
2779: }
2780: }
2781: }
2782: } else {
2783: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2784: $inst_results,$rolesarray);
2785: }
1.406.2.20.2. (raeburn 2786:): } elsif ($readonly) {
2787:): $disabled = ' disabled="disabled"';
1.188 raeburn 2788: }
1.391 raeburn 2789:
1.188 raeburn 2790: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2791: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2792: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2793: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.406.2.16 raeburn 2794: my $size = 25;
2795: if ($condition) {
2796: if ($condition =~ /^\@[^\@]+$/) {
2797: $size = 10;
2798: } else {
2799: undef($condition);
2800: }
2801: }
2802: if ($excluded) {
2803: unless ($excluded =~ /^\@[^\@]+$/) {
2804: undef($condition);
2805: }
2806: }
1.396 raeburn 2807: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2808: 'LC_oddrow_value')."\n".
1.406.2.16 raeburn 2809: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2810: if ($condition) {
2811: $output .= $condition;
2812: } elsif ($excluded) {
2813: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2814: $excluded).'</span>';
2815: }
2816: if ($usernameset eq 'first') {
2817: $output .= '<br /><span style="font-size: smaller">';
2818: if ($condition) {
2819: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2820: $condition);
2821: } else {
2822: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2823: }
2824: $output .= '</span>';
2825: }
1.391 raeburn 2826: $rowcount ++;
2827: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.20.2. (raeburn 2828:): my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="new-password" />';
2829:): my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="new-password" />';
1.396 raeburn 2830: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2831: 'LC_pick_box_title',
2832: 'LC_oddrow_value')."\n".
2833: $upassone."\n".
2834: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2835: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2836: 'LC_pick_box_title',
2837: 'LC_oddrow_value')."\n".
2838: $upasstwo.
2839: &Apache::lonhtmlcommon::row_closure()."\n";
1.406.2.16 raeburn 2840: if ($usernameset eq 'free') {
2841: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
2842: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
1.406.2.20 raeburn 2843: '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
2844: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
2845: &mt('Yes').'</label>'.(' 'x2).
2846: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
2847: &mt('No').'</label></span>'."\n".
1.406.2.16 raeburn 2848: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2849: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2850: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2851: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2852: $rowcount ++;
2853: }
1.391 raeburn 2854: }
1.188 raeburn 2855: foreach my $item (@userinfo) {
2856: my $rowtitle = $lt{$item};
1.252 raeburn 2857: my $hiderow = 0;
1.188 raeburn 2858: if ($item eq 'generation') {
2859: $rowtitle = $genhelp.$rowtitle;
2860: }
1.252 raeburn 2861: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2862: if ($newuser) {
1.210 raeburn 2863: if (ref($inst_results) eq 'HASH') {
2864: if ($inst_results->{$item} ne '') {
1.252 raeburn 2865: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2866: } else {
1.252 raeburn 2867: if ($context eq 'selfcreate') {
1.391 raeburn 2868: if ($canmodify{$item}) {
1.394 raeburn 2869: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2870: $editable ++;
2871: } else {
2872: $hiderow = 1;
2873: }
1.253 raeburn 2874: } else {
1.406.2.20.2. (raeburn 2875:): $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value=""'.$disabled.' />';
1.252 raeburn 2876: }
1.210 raeburn 2877: }
1.188 raeburn 2878: } else {
1.252 raeburn 2879: if ($context eq 'selfcreate') {
1.401 raeburn 2880: if ($canmodify{$item}) {
2881: if ($newuser eq 'email') {
2882: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2883: } else {
1.401 raeburn 2884: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2885: }
1.401 raeburn 2886: $editable ++;
2887: } else {
2888: $hiderow = 1;
1.252 raeburn 2889: }
1.253 raeburn 2890: } else {
1.406.2.20.2. (raeburn 2891:): $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value=""'.$disabled.' />';
1.252 raeburn 2892: }
1.188 raeburn 2893: }
2894: } else {
1.219 raeburn 2895: if ($canmodify{$item}) {
1.252 raeburn 2896: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2897: if (($item eq 'id') && (!$newuser)) {
2898: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2899: }
1.188 raeburn 2900: } else {
1.252 raeburn 2901: $row .= $userenv{$item};
1.188 raeburn 2902: }
2903: }
1.252 raeburn 2904: $row .= &Apache::lonhtmlcommon::row_closure(1);
2905: if (!$hiderow) {
2906: $output .= $row;
2907: $rowcount ++;
2908: }
1.188 raeburn 2909: }
1.286 raeburn 2910: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2911: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2912: if (ref($types) eq 'ARRAY') {
2913: if (@{$types} > 0) {
2914: my ($hiderow,$shown);
2915: if ($canmodify_status{'inststatus'}) {
2916: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2917: } else {
2918: if ($userenv{'inststatus'} eq '') {
2919: $hiderow = 1;
1.334 raeburn 2920: } else {
2921: my @showitems;
2922: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2923: if (exists($usertypes->{$item})) {
2924: push(@showitems,$usertypes->{$item});
2925: } else {
2926: push(@showitems,$item);
2927: }
2928: }
2929: if (@showitems) {
2930: $shown = join(', ',@showitems);
2931: } else {
2932: $hiderow = 1;
2933: }
1.286 raeburn 2934: }
2935: }
2936: if (!$hiderow) {
1.389 bisitz 2937: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2938: $shown.&Apache::lonhtmlcommon::row_closure(1);
2939: if ($context eq 'selfcreate') {
2940: $rowcount ++;
2941: }
2942: $output .= $row;
2943: }
2944: }
2945: }
2946: }
1.391 raeburn 2947: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2948: if ($captchaform) {
1.406.2.2 raeburn 2949: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
1.391 raeburn 2950: 'LC_pick_box_title')."\n".
2951: $captchaform."\n".'<br /><br />'.
2952: &Apache::lonhtmlcommon::row_closure(1);
2953: $rowcount ++;
2954: }
1.406.2.20 raeburn 2955: if ($showsubmit) {
2956: my $submit_text = &mt('Create account');
2957: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2958: '<br /><input type="submit" name="createaccount" value="'.
2959: $submit_text.'" />';
2960: if ($usertype ne '') {
1.406.2.20.2. (raeburn 2961:): $output .= '<input type="hidden" name="type" value="'.
2962:): &HTML::Entities::encode($usertype,'\'<>"&').'" />';
1.406.2.20 raeburn 2963: }
1.406.2.20.2. (raeburn 2964:): $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.20 raeburn 2965: }
1.391 raeburn 2966: }
1.188 raeburn 2967: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2968: if (wantarray) {
1.252 raeburn 2969: if ($context eq 'selfcreate') {
2970: return($output,$rowcount,$editable);
2971: } else {
1.388 bisitz 2972: return $output;
1.252 raeburn 2973: }
1.206 raeburn 2974: } else {
2975: return $output;
2976: }
1.188 raeburn 2977: }
2978:
1.286 raeburn 2979: sub pick_inst_statuses {
2980: my ($curr,$usertypes,$types) = @_;
2981: my ($output,$rem,@currtypes);
2982: if ($curr ne '') {
2983: @currtypes = map { &unescape($_); } split(/:/,$curr);
2984: }
2985: my $numinrow = 2;
2986: if (ref($types) eq 'ARRAY') {
2987: $output = '<table>';
2988: my $lastcolspan;
2989: for (my $i=0; $i<@{$types}; $i++) {
2990: if (defined($usertypes->{$types->[$i]})) {
2991: my $rem = $i%($numinrow);
2992: if ($rem == 0) {
2993: if ($i<@{$types}-1) {
2994: if ($i > 0) {
2995: $output .= '</tr>';
2996: }
2997: $output .= '<tr>';
2998: }
2999: } elsif ($i==@{$types}-1) {
3000: my $colsleft = $numinrow - $rem;
3001: if ($colsleft > 1) {
3002: $lastcolspan = ' colspan="'.$colsleft.'"';
3003: }
3004: }
3005: my $check = ' ';
3006: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
3007: $check = ' checked="checked" ';
3008: }
3009: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
3010: '<span class="LC_nobreak"><label>'.
3011: '<input type="checkbox" name="inststatus" '.
3012: 'value="'.$types->[$i].'"'.$check.'/>'.
3013: $usertypes->{$types->[$i]}.'</label></span></td>';
3014: }
3015: }
3016: $output .= '</tr></table>';
3017: }
3018: return $output;
3019: }
3020:
1.257 raeburn 3021: sub selfcreate_canmodify {
3022: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
3023: if (ref($inst_results) eq 'HASH') {
3024: my @inststatuses = &get_inststatuses($inst_results);
3025: if (@inststatuses == 0) {
3026: @inststatuses = ('default');
3027: }
3028: $rolesarray = \@inststatuses;
3029: }
3030: my %canmodify =
3031: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
3032: $rolesarray);
3033: return %canmodify;
3034: }
3035:
1.252 raeburn 3036: sub get_inststatuses {
3037: my ($insthashref) = @_;
3038: my @inststatuses = ();
3039: if (ref($insthashref) eq 'HASH') {
3040: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
3041: @inststatuses = @{$insthashref->{'inststatus'}};
3042: }
3043: }
3044: return @inststatuses;
3045: }
3046:
1.4 www 3047: # ================================================================= Phase Three
1.42 matthew 3048: sub update_user_data {
1.406.2.17 raeburn 3049: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 3050: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
3051: $env{'form.ccdomain'});
1.27 matthew 3052: # Error messages
1.188 raeburn 3053: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 3054: my $end = '</span><br /><br />';
3055: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 3056: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 3057: &mt('Return to previous page').'</a>'.
3058: &Apache::loncommon::end_page();
3059: my $now = time;
1.40 www 3060: my $title;
1.101 albertel 3061: if (exists($env{'form.makeuser'})) {
1.40 www 3062: $title='Set Privileges for New User';
3063: } else {
3064: $title='Modify User Privileges';
3065: }
1.213 raeburn 3066: my $newuser = 0;
1.160 raeburn 3067: my ($jsback,$elements) = &crumb_utilities();
3068: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 3069: '// <![CDATA['."\n".
3070: $jsback."\n".
3071: '// ]]>'."\n".
3072: '</script>'."\n";
1.406.2.7 raeburn 3073: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 3074: push (@{$brcrum},
3075: {href => "javascript:backPage(document.userupdate)",
3076: text => $breadcrumb_text{'search'},
3077: faq => 282,
3078: bug => 'Instructor Interface',}
3079: );
3080: if ($env{'form.prevphase'} eq 'userpicked') {
3081: push(@{$brcrum},
3082: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
3083: text => $breadcrumb_text{'userpicked'},
3084: faq => 282,
3085: bug => 'Instructor Interface',});
1.233 raeburn 3086: }
1.224 raeburn 3087: my $helpitem = 'Course_Change_Privileges';
3088: if ($env{'form.action'} eq 'singlestudent') {
3089: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 3090: } elsif ($context eq 'author') {
3091: $helpitem = 'Author_Change_Privileges';
3092: } elsif ($context eq 'domain') {
3093: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 3094: }
1.351 raeburn 3095: push(@{$brcrum},
3096: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
3097: text => $breadcrumb_text{'modify'},
3098: faq => 282,
3099: bug => 'Instructor Interface',},
3100: {href => "/adm/createuser",
3101: text => "Result",
3102: faq => 282,
3103: bug => 'Instructor Interface',
3104: help => $helpitem});
3105: my $args = {bread_crumbs => $brcrum,
3106: bread_crumbs_component => 'User Management'};
3107: if ($env{'form.popup'}) {
3108: $args->{'no_nav_bar'} = 1;
3109: }
3110: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 3111: $r->print(&update_result_form($uhome));
1.27 matthew 3112: # Check Inputs
1.101 albertel 3113: if (! $env{'form.ccuname'} ) {
1.193 raeburn 3114: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 3115: return;
3116: }
1.138 albertel 3117: if ( $env{'form.ccuname'} ne
3118: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 3119: $r->print($error.&mt('Invalid login name.').' '.
3120: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 3121: $end.$rtnlink);
1.27 matthew 3122: return;
3123: }
1.101 albertel 3124: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 3125: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 3126: return;
3127: }
1.138 albertel 3128: if ( $env{'form.ccdomain'} ne
3129: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 3130: $r->print($error.&mt('Invalid domain name.').' '.
3131: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 3132: $end.$rtnlink);
1.27 matthew 3133: return;
3134: }
1.219 raeburn 3135: if ($uhome eq 'no_host') {
3136: $newuser = 1;
3137: }
1.101 albertel 3138: if (! exists($env{'form.makeuser'})) {
1.29 matthew 3139: # Modifying an existing user, so check the validity of the name
3140: if ($uhome eq 'no_host') {
1.389 bisitz 3141: $r->print(
3142: $error
3143: .'<p class="LC_error">'
3144: .&mt('Unable to determine home server for [_1] in domain [_2].',
3145: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
3146: .'</p>');
1.29 matthew 3147: return;
3148: }
3149: }
1.27 matthew 3150: # Determine authentication method and password for the user being modified
3151: my $amode='';
3152: my $genpwd='';
1.101 albertel 3153: if ($env{'form.login'} eq 'krb') {
1.41 albertel 3154: $amode='krb';
1.101 albertel 3155: $amode.=$env{'form.krbver'};
3156: $genpwd=$env{'form.krbarg'};
3157: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 3158: $amode='internal';
1.101 albertel 3159: $genpwd=$env{'form.intarg'};
3160: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 3161: $amode='unix';
1.101 albertel 3162: $genpwd=$env{'form.fsysarg'};
3163: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 3164: $amode='localauth';
1.101 albertel 3165: $genpwd=$env{'form.locarg'};
1.27 matthew 3166: $genpwd=" " if (!$genpwd);
1.101 albertel 3167: } elsif (($env{'form.login'} eq 'nochange') ||
3168: ($env{'form.login'} eq '' )) {
1.34 matthew 3169: # There is no need to tell the user we did not change what they
3170: # did not ask us to change.
1.35 matthew 3171: # If they are creating a new user but have not specified login
3172: # information this will be caught below.
1.30 matthew 3173: } else {
1.367 golterma 3174: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
3175: return;
1.27 matthew 3176: }
1.164 albertel 3177:
1.188 raeburn 3178: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 3179: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
3180: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
3181: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 3182:
1.193 raeburn 3183: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 3184: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.406.2.20.2. (raeburn 3185:): my @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.384 raeburn 3186: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 3187: my @requestauthor = ('requestauthor');
1.406.2.20.2. (raeburn 3188:): my @authordefaults = ('webdav','editors','archive');
1.286 raeburn 3189: my ($othertitle,$usertypes,$types) =
3190: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 3191: my %canmodify_status =
3192: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
3193: ['inststatus']);
1.101 albertel 3194: if ($env{'form.makeuser'}) {
1.164 albertel 3195: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 3196: # Check for the authentication mode and password
3197: if (! $amode || ! $genpwd) {
1.193 raeburn 3198: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 3199: return;
1.18 albertel 3200: }
1.29 matthew 3201: # Determine desired host
1.101 albertel 3202: my $desiredhost = $env{'form.hserver'};
1.29 matthew 3203: if (lc($desiredhost) eq 'default') {
3204: $desiredhost = undef;
3205: } else {
1.147 albertel 3206: my %home_servers =
3207: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 3208: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 3209: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
3210: return;
3211: }
3212: }
3213: # Check ID format
3214: my %checkhash;
3215: my %checks = ('id' => 1);
3216: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 3217: 'newuser' => $newuser,
1.196 raeburn 3218: 'id' => $env{'form.cid'},
1.193 raeburn 3219: );
1.196 raeburn 3220: if ($env{'form.cid'} ne '') {
3221: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
3222: \%rulematch,\%inst_results,\%curr_rules);
3223: if (ref($alerts{'id'}) eq 'HASH') {
3224: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
3225: my $domdesc =
3226: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
3227: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
3228: my $userchkmsg;
3229: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
3230: $userchkmsg =
3231: &Apache::loncommon::instrule_disallow_msg('id',
3232: $domdesc,1).
3233: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
3234: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
3235: }
3236: $r->print($error.&mt('Invalid ID format').$end.
3237: $userchkmsg.$rtnlink);
3238: return;
3239: }
3240: }
1.29 matthew 3241: }
3242: }
1.367 golterma 3243: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 3244: # Call modifyuser
3245: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 3246: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 3247: $amode,$genpwd,$env{'form.cfirstname'},
3248: $env{'form.cmiddlename'},$env{'form.clastname'},
3249: $env{'form.cgeneration'},undef,$desiredhost,
3250: $env{'form.cpermanentemail'});
1.77 www 3251: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 3252: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 3253: $env{'form.ccdomain'});
1.334 raeburn 3254: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 3255: if ($uhome ne 'no_host') {
1.334 raeburn 3256: if ($context eq 'domain') {
1.378 raeburn 3257: foreach my $name ('portfolio','author') {
3258: if ($env{'form.custom_'.$name.'quota'} == 1) {
3259: if ($env{'form.'.$name.'quota'} eq '') {
3260: $newcustom{$name.'quota'} = 0;
3261: } else {
3262: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
3263: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
3264: }
3265: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
3266: $changed{$name.'quota'} = 1;
3267: }
1.334 raeburn 3268: }
3269: }
3270: foreach my $item (@usertools) {
3271: if ($env{'form.custom'.$item} == 1) {
3272: $newcustom{$item} = $env{'form.tools_'.$item};
3273: $changed{$item} = &tool_admin($item,$newcustom{$item},
3274: \%changeHash,'tools');
3275: }
1.267 raeburn 3276: }
1.334 raeburn 3277: foreach my $item (@requestcourses) {
1.341 raeburn 3278: if ($env{'form.custom'.$item} == 1) {
3279: $newcustom{$item} = $env{'form.crsreq_'.$item};
3280: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
3281: $newcustom{$item} .= '=';
1.383 raeburn 3282: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
3283: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 3284: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
3285: }
1.334 raeburn 3286: }
1.341 raeburn 3287: $changed{$item} = &tool_admin($item,$newcustom{$item},
3288: \%changeHash,'requestcourses');
1.334 raeburn 3289: }
1.275 raeburn 3290: }
1.362 raeburn 3291: if ($env{'form.customrequestauthor'} == 1) {
3292: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
3293: $changed{'requestauthor'} = &tool_admin('requestauthor',
3294: $newcustom{'requestauthor'},
3295: \%changeHash,'requestauthor');
3296: }
1.406.2.20.2. (raeburn 3297:): if ($env{'form.customeditors'} == 1) {
3298:): my @editors;
3299:): my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
3300:): if (@posseditors) {
3301:): foreach my $editor (@posseditors) {
3302:): if (grep(/^\Q$editor\E$/,@posseditors)) {
3303:): unless (grep(/^\Q$editor\E$/,@editors)) {
3304:): push(@editors,$editor);
3305:): }
3306:): }
3307:): }
3308:): }
3309:): if (@editors) {
3310:): @editors = sort(@editors);
3311:): $changed{'editors'} = &tool_admin('editors',join(',',@editors),
3312:): \%changeHash,'authordefaults');
3313:): }
3314:): }
3315:): if ($env{'form.customwebdav'} == 1) {
3316:): $newcustom{'webdav'} = $env{'form.authordefaults_webdav'};
3317:): $changed{'webdav'} = &tool_admin('webdav',$newcustom{'webdav'},
3318:): \%changeHash,'authordefaults');
3319:): }
3320:): if ($env{'form.customarchive'} == 1) {
3321:): $newcustom{'archive'} = $env{'form.authordefaults_archive'};
3322:): $changed{'archive'} = &tool_admin('archive',$newcustom{'archive'},
3323:): \%changeHash,'authordefaults');
3324:):
3325:): }
1.275 raeburn 3326: }
1.334 raeburn 3327: if ($canmodify_status{'inststatus'}) {
3328: if (exists($env{'form.inststatus'})) {
3329: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3330: if (@inststatuses > 0) {
3331: $changeHash{'inststatus'} = join(',',@inststatuses);
3332: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 3333: }
3334: }
1.232 raeburn 3335: }
1.334 raeburn 3336: if (keys(%changed)) {
3337: foreach my $item (@userinfo) {
3338: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 3339: }
1.267 raeburn 3340: my $chgresult =
3341: &Apache::lonnet::put('environment',\%changeHash,
3342: $env{'form.ccdomain'},$env{'form.ccuname'});
3343: }
1.232 raeburn 3344: }
1.406.2.19 raeburn 3345: $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
1.219 raeburn 3346: &Apache::lonnet::hostname($uhome));
1.101 albertel 3347: } elsif (($env{'form.login'} ne 'nochange') &&
3348: ($env{'form.login'} ne '' )) {
1.27 matthew 3349: # Modify user privileges
3350: if (! $amode || ! $genpwd) {
1.193 raeburn 3351: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 3352: return;
1.20 harris41 3353: }
1.395 bisitz 3354: # Only allow authentication modification if the person has authority
1.101 albertel 3355: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 3356: $r->print('Modifying authentication: '.
1.31 matthew 3357: &Apache::lonnet::modifyuserauth(
1.101 albertel 3358: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 3359: $amode,$genpwd));
1.406.2.19 raeburn 3360: $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
1.101 albertel 3361: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 3362: } else {
1.27 matthew 3363: # Okay, this is a non-fatal error.
1.406.2.17 raeburn 3364: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 3365: }
1.406.2.17 raeburn 3366: } elsif (($env{'form.intarg'} ne '') &&
3367: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
3368: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3369: $r->print('Modifying authentication: '.
3370: &Apache::lonnet::modifyuserauth(
3371: $env{'form.ccdomain'},$env{'form.ccuname'},
3372: 'internal',$env{'form.intarg'}));
1.28 matthew 3373: }
1.344 bisitz 3374: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3375: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3376: ##
1.375 raeburn 3377: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3378: if ($context eq 'course') {
1.375 raeburn 3379: ($cnum,$cdom) =
3380: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3381: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3382: if ($showcredits) {
3383: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3384: }
1.213 raeburn 3385: }
1.101 albertel 3386: if (! $env{'form.makeuser'} ) {
1.28 matthew 3387: # Check for need to change
3388: my %userenv = &Apache::lonnet::get
1.134 raeburn 3389: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3390: 'id','permanentemail','portfolioquota','authorquota','inststatus',
1.406.2.20.2. (raeburn 3391:): 'tools.aboutme','tools.blog','tools.webdav',
3392:): 'tools.portfolio','tools.timezone','tools.portaccess',
3393:): 'authormanagers','authoreditors','authorarchive','requestauthor',
1.361 raeburn 3394: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3395: 'requestcourses.community','requestcourses.textbook',
3396: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.406.2.20.2. (raeburn 3397:): 'reqcrsotherdom.community','reqcrsotherdom.textbook',
3398:): 'domcoord.author'],
1.160 raeburn 3399: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3400: my ($tmp) = keys(%userenv);
3401: if ($tmp =~ /^(con_lost|error)/i) {
3402: %userenv = ();
3403: }
1.406.2.20.2. (raeburn 3404:): unless (($userenv{'domcoord.author'} eq 'blocked') &&
3405:): (($env{'user.name'} ne $env{'form.ccuname'}) ||
3406:): ($env{'user.domain'} ne $env{'form.ccdomain'}))) {
3407:): push(@authordefaults,'managers');
3408:): }
1.206 raeburn 3409: my $no_forceid_alert;
3410: # Check to see if user information can be changed
3411: my %domconfig =
3412: &Apache::lonnet::get_dom('configuration',['usermodification'],
3413: $env{'form.ccdomain'});
1.213 raeburn 3414: my @statuses = ('active','future');
3415: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3416: my ($auname,$audom);
1.220 raeburn 3417: if ($context eq 'author') {
1.206 raeburn 3418: $auname = $env{'user.name'};
3419: $audom = $env{'user.domain'};
3420: }
3421: foreach my $item (keys(%roles)) {
1.220 raeburn 3422: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3423: if ($context eq 'course') {
3424: if ($cnum ne '' && $cdom ne '') {
3425: if ($rolenum eq $cnum && $roledom eq $cdom) {
3426: if (!grep(/^\Q$role\E$/,@userroles)) {
3427: push(@userroles,$role);
3428: }
3429: }
3430: }
3431: } elsif ($context eq 'author') {
3432: if ($rolenum eq $auname && $roledom eq $audom) {
3433: if (!grep(/^\Q$role\E$/,@userroles)) {
3434: push(@userroles,$role);
3435: }
3436: }
3437: }
3438: }
1.220 raeburn 3439: if ($env{'form.action'} eq 'singlestudent') {
3440: if (!grep(/^st$/,@userroles)) {
3441: push(@userroles,'st');
3442: }
3443: } else {
3444: # Check for course or co-author roles being activated or re-enabled
3445: if ($context eq 'author' || $context eq 'course') {
3446: foreach my $key (keys(%env)) {
3447: if ($context eq 'author') {
3448: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3449: if (!grep(/^\Q$1\E$/,@userroles)) {
3450: push(@userroles,$1);
3451: }
3452: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3453: if (!grep(/^\Q$1\E$/,@userroles)) {
3454: push(@userroles,$1);
3455: }
1.206 raeburn 3456: }
1.220 raeburn 3457: } elsif ($context eq 'course') {
3458: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3459: if (!grep(/^\Q$1\E$/,@userroles)) {
3460: push(@userroles,$1);
3461: }
3462: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3463: if (!grep(/^\Q$1\E$/,@userroles)) {
3464: push(@userroles,$1);
3465: }
1.206 raeburn 3466: }
3467: }
3468: }
3469: }
3470: }
3471: #Check to see if we can change personal data for the user
3472: my (@mod_disallowed,@longroles);
3473: foreach my $role (@userroles) {
3474: if ($role eq 'cr') {
3475: push(@longroles,'Custom');
3476: } else {
1.318 raeburn 3477: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3478: }
3479: }
1.219 raeburn 3480: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3481: foreach my $item (@userinfo) {
1.28 matthew 3482: # Strip leading and trailing whitespace
1.203 raeburn 3483: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3484: if (!$canmodify{$item}) {
1.207 raeburn 3485: if (defined($env{'form.c'.$item})) {
3486: if ($env{'form.c'.$item} ne $userenv{$item}) {
3487: push(@mod_disallowed,$item);
3488: }
1.206 raeburn 3489: }
3490: $env{'form.c'.$item} = $userenv{$item};
3491: }
1.28 matthew 3492: }
1.259 bisitz 3493: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3494: my $forceid = $env{'form.forceid'};
3495: my $recurseid = $env{'form.recurseid'};
3496: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3497: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3498: $env{'form.ccuname'});
3499: if (($uidhash{$env{'form.ccuname'}}) &&
3500: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3501: (!$forceid)) {
3502: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3503: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3504: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3505: .'<br />'
3506: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3507: .'<br />'."\n";
1.203 raeburn 3508: }
3509: }
3510: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3511: my $checkhash;
3512: my $checks = { 'id' => 1 };
3513: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3514: { 'newuser' => $newuser,
3515: 'id' => $env{'form.cid'},
3516: };
3517: &Apache::loncommon::user_rule_check($checkhash,$checks,
3518: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3519: if (ref($alerts{'id'}) eq 'HASH') {
3520: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3521: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3522: }
3523: }
3524: }
1.378 raeburn 3525: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3526: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3527: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3528: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3529: @disporder = ('inststatus');
3530: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.406.2.20.2. (raeburn 3531:): push(@disporder,('requestcourses','requestauthor','authordefaults'));
1.334 raeburn 3532: } else {
3533: push(@disporder,'reqcrsotherdom');
3534: }
3535: push(@disporder,('quota','tools'));
1.338 raeburn 3536: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3537: foreach my $name ('portfolio','author') {
3538: ($olddefquota{$name},$oldsettingstatus{$name}) =
3539: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3540: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3541: }
1.334 raeburn 3542: my %canshow;
1.220 raeburn 3543: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3544: $canshow{'quota'} = 1;
1.220 raeburn 3545: }
1.267 raeburn 3546: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3547: $canshow{'tools'} = 1;
1.267 raeburn 3548: }
1.275 raeburn 3549: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3550: $canshow{'requestcourses'} = 1;
1.300 raeburn 3551: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3552: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3553: }
1.286 raeburn 3554: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3555: $canshow{'inststatus'} = 1;
1.286 raeburn 3556: }
1.362 raeburn 3557: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3558: $canshow{'requestauthor'} = 1;
1.406.2.20.2. (raeburn 3559:): $canshow{'authordefaults'} = 1;
1.362 raeburn 3560: }
1.267 raeburn 3561: my (%changeHash,%changed);
1.286 raeburn 3562: if ($oldinststatus eq '') {
1.334 raeburn 3563: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3564: } else {
3565: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3566: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3567: } else {
1.334 raeburn 3568: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3569: }
3570: }
3571: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3572: if ($canmodify_status{'inststatus'}) {
3573: $canshow{'inststatus'} = 1;
1.286 raeburn 3574: if (exists($env{'form.inststatus'})) {
3575: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3576: if (@inststatuses > 0) {
3577: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3578: $changeHash{'inststatus'} = $newinststatus;
3579: if ($newinststatus ne $oldinststatus) {
3580: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3581: foreach my $name ('portfolio','author') {
3582: ($newdefquota{$name},$newsettingstatus{$name}) =
3583: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3584: }
1.286 raeburn 3585: }
3586: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3587: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3588: } else {
1.337 raeburn 3589: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3590: }
1.334 raeburn 3591: }
3592: } else {
3593: $newinststatus = '';
3594: $changeHash{'inststatus'} = $newinststatus;
3595: $newsettings{'inststatus'} = $othertitle;
3596: if ($newinststatus ne $oldinststatus) {
3597: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3598: foreach my $name ('portfolio','author') {
3599: ($newdefquota{$name},$newsettingstatus{$name}) =
3600: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3601: }
1.286 raeburn 3602: }
3603: }
1.334 raeburn 3604: } elsif ($context ne 'selfcreate') {
3605: $canshow{'inststatus'} = 1;
1.337 raeburn 3606: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3607: }
1.378 raeburn 3608: foreach my $name ('portfolio','author') {
3609: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3610: }
1.334 raeburn 3611: if ($context eq 'domain') {
1.378 raeburn 3612: foreach my $name ('portfolio','author') {
3613: if ($userenv{$name.'quota'} ne '') {
3614: $oldquota{$name} = $userenv{$name.'quota'};
3615: if ($env{'form.custom_'.$name.'quota'} == 1) {
3616: if ($env{'form.'.$name.'quota'} eq '') {
3617: $newquota{$name} = 0;
3618: } else {
3619: $newquota{$name} = $env{'form.'.$name.'quota'};
3620: $newquota{$name} =~ s/[^\d\.]//g;
3621: }
3622: if ($newquota{$name} != $oldquota{$name}) {
3623: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3624: $changed{$name.'quota'} = 1;
3625: }
3626: }
1.334 raeburn 3627: } else {
1.378 raeburn 3628: if ("a_admin('',\%changeHash,$name)) {
3629: $changed{$name.'quota'} = 1;
3630: $newquota{$name} = $newdefquota{$name};
3631: $newisdefault{$name} = 1;
3632: }
1.334 raeburn 3633: }
1.149 raeburn 3634: } else {
1.378 raeburn 3635: $oldisdefault{$name} = 1;
3636: $oldquota{$name} = $olddefquota{$name};
3637: if ($env{'form.custom_'.$name.'quota'} == 1) {
3638: if ($env{'form.'.$name.'quota'} eq '') {
3639: $newquota{$name} = 0;
3640: } else {
3641: $newquota{$name} = $env{'form.'.$name.'quota'};
3642: $newquota{$name} =~ s/[^\d\.]//g;
3643: }
3644: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3645: $changed{$name.'quota'} = 1;
3646: }
1.334 raeburn 3647: } else {
1.378 raeburn 3648: $newquota{$name} = $newdefquota{$name};
3649: $newisdefault{$name} = 1;
1.334 raeburn 3650: }
1.378 raeburn 3651: }
3652: if ($oldisdefault{$name}) {
3653: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3654: } else {
3655: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3656: }
3657: if ($newisdefault{$name}) {
3658: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3659: } else {
3660: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3661: }
3662: }
1.334 raeburn 3663: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3664: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3665: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3666: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3667: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.406.2.20.2. (raeburn 3668:): my ($isadv,$isauthor) =
3669:): &Apache::lonnet::is_advanced_user($env{'form.ccdomain'},$env{'form.ccuname'});
3670:): unless ($isauthor) {
3671:): &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3672:): \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3673:): }
3674:): &tool_changes('authordefaults',\@authordefaults,\%oldsettings,\%oldsettingstext,
3675:): \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3676: } else {
1.334 raeburn 3677: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3678: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3679: }
3680: }
1.334 raeburn 3681: foreach my $item (@userinfo) {
3682: if ($env{'form.c'.$item} ne $userenv{$item}) {
3683: $namechanged{$item} = 1;
3684: }
1.204 raeburn 3685: }
1.378 raeburn 3686: foreach my $name ('portfolio','author') {
1.390 bisitz 3687: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3688: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3689: }
1.334 raeburn 3690: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3691: my ($chgresult,$namechgresult);
3692: if (keys(%changed) > 0) {
1.406.2.20.2. (raeburn 3693:): $chgresult =
1.204 raeburn 3694: &Apache::lonnet::put('environment',\%changeHash,
3695: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3696: if ($chgresult eq 'ok') {
1.406.2.20.2. (raeburn 3697:): my ($ca_mgr_del,%ca_mgr_add);
3698:): if ($changed{'managers'}) {
3699:): my (@adds,@dels);
3700:): if ($changeHash{'authormanagers'} eq '') {
3701:): @dels = split(/,/,$userenv{'authormanagers'});
3702:): } elsif ($userenv{'authormanagers'} eq '') {
3703:): @adds = split(/,/,$changeHash{'authormanagers'});
3704:): } else {
3705:): my @old = split(/,/,$userenv{'authormanagers'});
3706:): my @new = split(/,/,$changeHash{'authormanagers'});
3707:): my @diffs = &Apache::loncommon::compare_arrays(\@old,\@new);
3708:): if (@diffs) {
3709:): foreach my $user (@diffs) {
3710:): if (grep(/^\Q$user\E$/,@old)) {
3711:): push(@dels,$user);
3712:): } elsif (grep(/^\Q$user\E$/,@new)) {
3713:): push(@adds,$user);
3714:): }
3715:): }
3716:): }
3717:): }
3718:): my $key = "internal.manager./$env{'form.ccdomain'}/$env{'form.ccuname'}";
3719:): if (@dels) {
3720:): foreach my $user (@dels) {
3721:): if ($user =~ /^($match_username):($match_domain)$/) {
3722:): &Apache::lonnet::del('environment',[$key],$2,$1);
3723:): }
3724:): }
3725:): my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
3726:): if (grep(/^\Q$curruser\E$/,@dels)) {
3727:): $ca_mgr_del = $key;
3728:): }
3729:): }
3730:): if (@adds) {
3731:): foreach my $user (@adds) {
3732:): if ($user =~ /^($match_username):($match_domain)$/) {
3733:): &Apache::lonnet::put('environment',{$key => 1},$2,$1);
3734:): }
3735:): }
3736:): my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
3737:): if (grep(/^\Q$curruser\E$/,@adds)) {
3738:): $ca_mgr_add{$key} = 1;
3739:): }
3740:): }
3741:): }
1.267 raeburn 3742: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3743: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.406.2.20.2. (raeburn 3744:): my (%newenvhash,$got_domdefs,%domdefaults,$got_userenv,
3745:): %userenv);
3746:): my @fromenv = keys(%changed);
3747:): push(@fromenv,'inststatus');
1.270 raeburn 3748: foreach my $key (keys(%changed)) {
1.299 raeburn 3749: if (($key eq 'official') || ($key eq 'unofficial')
1.403 raeburn 3750: || ($key eq 'community') || ($key eq 'textbook')) {
1.279 raeburn 3751: $newenvhash{'environment.requestcourses.'.$key} =
3752: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3753: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3754: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3755: } else {
1.406.2.20.2. (raeburn 3756:): unless ($got_domdefs) {
3757:): %domdefaults =
3758:): &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3759:): $got_domdefs = 1;
3760:): }
3761:): unless ($got_userenv) {
3762:): %userenv =
3763:): &Apache::lonnet::userenvironment($env{'user.domain'},
3764:): $env{'user.name'},@fromenv);
3765:): $got_userenv = 1;
3766:): }
1.279 raeburn 3767: $newenvhash{'environment.canrequest.'.$key} =
3768: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.406.2.20.2. (raeburn 3769:): $key,'reload','requestcourses',\%userenv,\%domdefaults);
1.279 raeburn 3770: }
1.362 raeburn 3771: } elsif ($key eq 'requestauthor') {
3772: $newenvhash{'environment.'.$key} = $changeHash{$key};
3773: if ($changeHash{$key}) {
3774: $newenvhash{'environment.canrequest.author'} = 1;
3775: } else {
1.406.2.20.2. (raeburn 3776:): unless ($got_domdefs) {
3777:): %domdefaults =
3778:): &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3779:): $got_domdefs = 1;
3780:): }
3781:): unless ($got_userenv) {
3782:): %userenv =
3783:): &Apache::lonnet::userenvironment($env{'user.domain'},
3784:): $env{'user.name'},@fromenv);
3785:): $got_userenv = 1;
3786:): }
1.362 raeburn 3787: $newenvhash{'environment.canrequest.author'} =
3788: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.406.2.20.2. (raeburn 3789:): $key,'reload','requestauthor',\%userenv,\%domdefaults);
3790:): }
3791:): } elsif ($key eq 'editors') {
3792:): $newenvhash{'environment.author'.$key} = $changeHash{'author'.$key};
3793:): if ($env{'form.customeditors'}) {
3794:): $newenvhash{'environment.editors'} = $changeHash{'author'.$key};
3795:): } else {
3796:): unless ($got_domdefs) {
3797:): %domdefaults =
3798:): &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3799:): $got_domdefs = 1;
3800:): }
3801:): if ($domdefaults{'editors'} ne '') {
3802:): $newenvhash{'environment.editors'} = $domdefaults{'editors'};
3803:): } else {
3804:): $newenvhash{'environment.editors'} = 'edit,xml';
3805:): }
1.362 raeburn 3806: }
1.406.2.20.2. (raeburn 3807:): } elsif ($key eq 'archive') {
3808:): $newenvhash{'environment.author.'.$key} =
3809:): $changeHash{'author.'.$key};
3810:): if ($changeHash{'author.'.$key} ne '') {
3811:): $newenvhash{'environment.canarchive'} =
3812:): $changeHash{'author.'.$key};
3813:): } else {
3814:): unless ($got_domdefs) {
3815:): %domdefaults =
3816:): &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3817:): $got_domdefs = 1;
3818:): }
3819:): $newenvhash{'environment.canarchive'} =
3820:): $domdefaults{'archive'};
3821:): }
1.275 raeburn 3822: } elsif ($key ne 'quota') {
1.270 raeburn 3823: $newenvhash{'environment.tools.'.$key} =
3824: $changeHash{'tools.'.$key};
1.279 raeburn 3825: if ($changeHash{'tools.'.$key} ne '') {
3826: $newenvhash{'environment.availabletools.'.$key} =
3827: $changeHash{'tools.'.$key};
3828: } else {
1.406.2.20.2. (raeburn 3829:): unless ($got_domdefs) {
3830:): %domdefaults =
3831:): &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3832:): $got_domdefs = 1;
3833:): }
3834:): unless ($got_userenv) {
3835:): %userenv =
3836:): &Apache::lonnet::userenvironment($env{'user.domain'},
3837:): $env{'user.name'},@fromenv);
3838:): $got_userenv = 1;
3839:): }
1.279 raeburn 3840: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3841: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.406.2.20.2. (raeburn 3842:): $key,'reload','tools',\%userenv,\%domdefaults);
1.279 raeburn 3843: }
1.270 raeburn 3844: }
3845: }
1.271 raeburn 3846: if (keys(%newenvhash)) {
3847: &Apache::lonnet::appenv(\%newenvhash);
3848: }
1.406.2.20.2. (raeburn 3849:): } else {
3850:): if ($ca_mgr_del) {
3851:): &Apache::lonnet::delenv($ca_mgr_del);
3852:): }
3853:): if (keys(%ca_mgr_add)) {
3854:): &Apache::lonnet::appenv(\%ca_mgr_add);
3855:): }
1.267 raeburn 3856: }
1.406.2.20.2. (raeburn 3857:): if ($changed{'aboutme'}) {
3858:): &Apache::loncommon::devalidate_aboutme_cache($env{'form.ccuname'},
3859:): $env{'form.ccdomain'});
3860:): }
1.267 raeburn 3861: }
1.204 raeburn 3862: }
1.334 raeburn 3863: if (keys(%namechanged) > 0) {
1.337 raeburn 3864: foreach my $field (@userinfo) {
3865: $changeHash{$field} = $env{'form.c'.$field};
3866: }
3867: # Make the change
1.204 raeburn 3868: $namechgresult =
3869: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3870: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3871: $changeHash{'firstname'},$changeHash{'middlename'},
3872: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3873: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3874: %userupdate = (
3875: lastname => $env{'form.clastname'},
3876: middlename => $env{'form.cmiddlename'},
3877: firstname => $env{'form.cfirstname'},
3878: generation => $env{'form.cgeneration'},
3879: id => $env{'form.cid'},
3880: );
1.204 raeburn 3881: }
1.334 raeburn 3882: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3883: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3884: # Tell the user we changed the name
1.334 raeburn 3885: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3886: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3887: \%oldsettings, \%oldsettingstext,\%newsettings,
3888: \%newsettingstext);
1.203 raeburn 3889: if ($env{'form.cid'} ne $userenv{'id'}) {
3890: &Apache::lonnet::idput($env{'form.ccdomain'},
1.406.2.5 raeburn 3891: {$env{'form.ccuname'} => $env{'form.cid'}});
1.203 raeburn 3892: if (($recurseid) &&
3893: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3894: my $idresult =
3895: &Apache::lonuserutils::propagate_id_change(
3896: $env{'form.ccuname'},$env{'form.ccdomain'},
3897: \%userupdate);
3898: $r->print('<br />'.$idresult.'<br />');
3899: }
1.196 raeburn 3900: }
1.149 raeburn 3901: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3902: ($env{'form.ccuname'} eq $env{'user.name'})) {
3903: my %newenvhash;
3904: foreach my $key (keys(%changeHash)) {
3905: $newenvhash{'environment.'.$key} = $changeHash{$key};
3906: }
1.238 raeburn 3907: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3908: }
1.28 matthew 3909: } else { # error occurred
1.389 bisitz 3910: $r->print(
3911: '<p class="LC_error">'
3912: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3913: '"'.$env{'form.ccuname'}.'"',
3914: '"'.$env{'form.ccdomain'}.'"')
3915: .'</p>');
1.28 matthew 3916: }
1.334 raeburn 3917: } else { # End of if ($env ... ) logic
1.275 raeburn 3918: # They did not want to change the users name, quota, tool availability,
3919: # or ability to request creation of courses,
1.267 raeburn 3920: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3921: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3922: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3923: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3924: }
1.206 raeburn 3925: if (@mod_disallowed) {
3926: my ($rolestr,$contextname);
3927: if (@longroles > 0) {
3928: $rolestr = join(', ',@longroles);
3929: } else {
3930: $rolestr = &mt('No roles');
3931: }
3932: if ($context eq 'course') {
1.399 bisitz 3933: $contextname = 'course';
1.206 raeburn 3934: } elsif ($context eq 'author') {
1.399 bisitz 3935: $contextname = 'co-author';
1.206 raeburn 3936: }
3937: $r->print(&mt('The following fields were not updated: ').'<ul>');
3938: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3939: foreach my $field (@mod_disallowed) {
3940: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3941: }
1.207 raeburn 3942: $r->print('</ul>');
3943: if (@mod_disallowed == 1) {
1.399 bisitz 3944: $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 3945: } else {
1.399 bisitz 3946: $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 3947: }
1.292 bisitz 3948: my $helplink = 'javascript:helpMenu('."'display'".')';
3949: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3950: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3951: ,'<a href="'.$helplink.'">','</a>')
3952: .'<br />');
1.206 raeburn 3953: }
1.259 bisitz 3954: $r->print('<span class="LC_warning">'
3955: .$no_forceid_alert
3956: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3957: .'</span>');
1.4 www 3958: }
1.367 golterma 3959: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3960: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3961: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3962: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3963: my $linktext = ($crstype eq 'Community' ?
3964: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3965: $r->print(
3966: &Apache::lonhtmlcommon::actionbox([
3967: '<a href="javascript:backPage(document.userupdate)">'
3968: .($crstype eq 'Community' ?
3969: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3970: .'</a>']));
1.220 raeburn 3971: } else {
1.375 raeburn 3972: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3973: if (keys(%namechanged) > 0) {
1.220 raeburn 3974: if ($context eq 'course') {
3975: if (@userroles > 0) {
1.225 raeburn 3976: if ((@rolechanges == 0) ||
3977: (!(grep(/^st$/,@rolechanges)))) {
3978: if (grep(/^st$/,@userroles)) {
3979: my $classlistupdated =
3980: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3981: $cnum,$env{'form.ccdomain'},
3982: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3983: }
1.220 raeburn 3984: }
3985: }
3986: }
3987: }
1.226 raeburn 3988: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3989: $env{'form.ccdomain'});
3990: if ($env{'form.popup'}) {
3991: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3992: } else {
1.367 golterma 3993: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3994: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3995: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3996: }
1.220 raeburn 3997: }
3998: }
3999:
1.334 raeburn 4000: sub display_userinfo {
1.362 raeburn 4001: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
4002: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 4003: $newsetting,$newsettingtext) = @_;
4004: return unless (ref($order) eq 'ARRAY' &&
4005: ref($canshow) eq 'HASH' &&
4006: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 4007: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 4008: ref($usertools) eq 'ARRAY' &&
4009: ref($userenv) eq 'HASH' &&
4010: ref($changedhash) eq 'HASH' &&
4011: ref($oldsetting) eq 'HASH' &&
4012: ref($oldsettingtext) eq 'HASH' &&
4013: ref($newsetting) eq 'HASH' &&
4014: ref($newsettingtext) eq 'HASH');
4015: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 4016: 'ui' => 'User Information',
1.334 raeburn 4017: 'uic' => 'User Information Changed',
4018: 'firstname' => 'First Name',
4019: 'middlename' => 'Middle Name',
4020: 'lastname' => 'Last Name',
4021: 'generation' => 'Generation',
4022: 'id' => 'Student/Employee ID',
4023: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 4024: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 4025: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 4026: 'blog' => 'Blog Availability',
1.361 raeburn 4027: 'webdav' => 'WebDAV Availability',
1.334 raeburn 4028: 'aboutme' => 'Personal Information Page Availability',
4029: 'portfolio' => 'Portfolio Availability',
1.406.2.20.2. (raeburn 4030:): 'portaccess' => 'Portfolio Shareable',
4031:): 'timezone' => 'Can set own Time Zone',
1.334 raeburn 4032: 'official' => 'Can Request Official Courses',
4033: 'unofficial' => 'Can Request Unofficial Courses',
4034: 'community' => 'Can Request Communities',
1.384 raeburn 4035: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 4036: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 4037: 'inststatus' => "Affiliation",
4038: 'prvs' => 'Previous Value:',
1.406.2.20.2. (raeburn 4039:): 'chto' => 'Changed To:',
4040:): 'editors' => "Available Editors in Authoring Space",
4041:): 'managers' => "Co-authors who can add/revoke roles",
4042:): 'archive' => "Managers can download tar.gz file of Authoring Space",
4043:): 'edit' => 'Standard editor (Edit)',
4044:): 'xml' => 'Text editor (EditXML)',
4045:): 'daxe' => 'Daxe editor (Daxe)',
1.334 raeburn 4046: );
4047: if ($changed) {
1.372 raeburn 4048: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 4049: &Apache::loncommon::start_data_table().
4050: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 4051: $r->print("<th> </th>\n");
1.367 golterma 4052: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
4053: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
4054: $r->print(&Apache::loncommon::end_data_table_header_row());
4055: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
4056:
1.334 raeburn 4057: foreach my $item (@userinfo) {
4058: my $value = $env{'form.c'.$item};
1.367 golterma 4059: #show changes only:
1.383 raeburn 4060: unless ($value eq $userenv->{$item}){
1.367 golterma 4061: $r->print(&Apache::loncommon::start_data_table_row());
4062: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 4063: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 4064: $r->print("<td>$value </td>\n");
4065: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 4066: }
4067: }
4068: foreach my $entry (@{$order}) {
1.383 raeburn 4069: if ($canshow->{$entry}) {
1.406.2.20.2. (raeburn 4070:): if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') ||
4071:): ($entry eq 'requestauthor') || ($entry eq 'authordefaults')) {
1.383 raeburn 4072: my @items;
4073: if ($entry eq 'requestauthor') {
4074: @items = ($entry);
1.406.2.20.2. (raeburn 4075:): } elsif ($entry eq 'authordefaults') {
4076:): @items = ('webdav','managers','editors','archive');
1.383 raeburn 4077: } else {
4078: @items = @{$requestcourses};
1.384 raeburn 4079: }
1.383 raeburn 4080: foreach my $item (@items) {
4081: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
4082: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
4083: $r->print(&Apache::loncommon::start_data_table_row()."\n");
1.406.2.20.2. (raeburn 4084:): $r->print("<td>$lt{$item}</td><td>\n");
4085:): unless ($item eq 'managers') {
4086:): $r->print($oldsetting->{$item});
4087:): }
1.383 raeburn 4088: if ($oldsettingtext->{$item}) {
4089: if ($oldsetting->{$item}) {
1.406.2.20.2. (raeburn 4090:): unless ($item eq 'managers') {
4091:): $r->print(' -- ');
4092:): }
1.383 raeburn 4093: }
4094: $r->print($oldsettingtext->{$item});
4095: }
1.406.2.20.2. (raeburn 4096:): $r->print("</td>\n<td>");
4097:): unless ($item eq 'managers') {
4098:): $r->print($newsetting->{$item});
4099:): }
1.383 raeburn 4100: if ($newsettingtext->{$item}) {
4101: if ($newsetting->{$item}) {
1.406.2.20.2. (raeburn 4102:): unless ($item eq 'managers') {
4103:): $r->print(' -- ');
4104:): }
1.383 raeburn 4105: }
4106: $r->print($newsettingtext->{$item});
4107: }
4108: $r->print("</td>\n");
4109: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4110: }
4111: }
4112: } elsif ($entry eq 'tools') {
4113: foreach my $item (@{$usertools}) {
1.383 raeburn 4114: if ($newsetting->{$item} ne $oldsetting->{$item}) {
4115: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4116: $r->print("<td>$lt{$item}</td>\n");
4117: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
4118: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
4119: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4120: }
4121: }
1.378 raeburn 4122: } elsif ($entry eq 'quota') {
4123: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
4124: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
4125: foreach my $name ('portfolio','author') {
1.383 raeburn 4126: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
4127: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4128: $r->print("<td>$lt{$name.$entry}</td>\n");
4129: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
4130: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
4131: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 4132: }
4133: }
4134: }
1.334 raeburn 4135: } else {
1.383 raeburn 4136: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
4137: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4138: $r->print("<td>$lt{$entry}</td>\n");
4139: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
4140: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
4141: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4142: }
4143: }
4144: }
4145: }
1.367 golterma 4146: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 4147: } else {
4148: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
4149: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 4150: }
4151: return;
4152: }
4153:
1.275 raeburn 4154: sub tool_changes {
4155: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
4156: $changed,$newaccess,$newaccesstext) = @_;
4157: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
4158: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
4159: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
4160: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
4161: return;
4162: }
1.383 raeburn 4163: my %reqdisplay = &requestchange_display();
1.300 raeburn 4164: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 4165: my @options = ('approval','validate','autolimit');
1.306 raeburn 4166: my $optregex = join('|',@options);
1.300 raeburn 4167: my $cdom = $env{'request.role.domain'};
4168: foreach my $tool (@{$usertools}) {
1.383 raeburn 4169: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 4170: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 4171: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 4172: my ($newop,$limit);
1.314 raeburn 4173: if ($env{'form.'.$context.'_'.$tool}) {
4174: $newop = $env{'form.'.$context.'_'.$tool};
4175: if ($newop eq 'autolimit') {
1.383 raeburn 4176: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 4177: $limit =~ s/\D+//g;
4178: $newop .= '='.$limit;
4179: }
4180: }
1.300 raeburn 4181: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 4182: if ($newop) {
4183: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 4184: $changeHash,$context);
4185: if ($changed->{$tool}) {
1.383 raeburn 4186: if ($newop =~ /^autolimit/) {
4187: if ($limit) {
4188: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4189: } else {
4190: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4191: }
4192: } else {
4193: $newaccesstext->{$tool} = $reqdisplay{$newop};
4194: }
1.300 raeburn 4195: } else {
4196: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
4197: }
4198: }
4199: } else {
4200: my @curr = split(',',$userenv->{$context.'.'.$tool});
4201: my @new;
4202: my $changedoms;
1.314 raeburn 4203: foreach my $req (@curr) {
4204: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
4205: my $oldop = $1;
1.383 raeburn 4206: if ($oldop =~ /^autolimit=(\d*)/) {
4207: my $limit = $1;
4208: if ($limit) {
4209: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4210: } else {
4211: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4212: }
4213: } else {
4214: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
4215: }
1.314 raeburn 4216: if ($oldop ne $newop) {
4217: $changedoms = 1;
4218: foreach my $item (@curr) {
4219: my ($reqdom,$option) = split(':',$item);
4220: unless ($reqdom eq $cdom) {
4221: push(@new,$item);
4222: }
4223: }
4224: if ($newop) {
4225: push(@new,$cdom.':'.$newop);
1.300 raeburn 4226: }
1.314 raeburn 4227: @new = sort(@new);
1.300 raeburn 4228: }
1.314 raeburn 4229: last;
1.300 raeburn 4230: }
1.314 raeburn 4231: }
4232: if ((!$changedoms) && ($newop)) {
1.300 raeburn 4233: $changedoms = 1;
1.306 raeburn 4234: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 4235: }
4236: if ($changedoms) {
1.314 raeburn 4237: my $newdomstr;
1.300 raeburn 4238: if (@new) {
4239: $newdomstr = join(',',@new);
4240: }
4241: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
4242: $context);
4243: if ($changed->{$tool}) {
4244: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 4245: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 4246: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
4247: $limit =~ s/\D+//g;
4248: if ($limit) {
1.383 raeburn 4249: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 4250: } else {
1.383 raeburn 4251: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 4252: }
1.314 raeburn 4253: } else {
1.306 raeburn 4254: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
4255: }
1.300 raeburn 4256: } else {
1.383 raeburn 4257: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 4258: }
4259: }
4260: }
4261: }
4262: }
4263: return;
4264: }
1.406.2.20.2. (raeburn 4265:): my %tooldesc = &Apache::lonlocal::texthash(
4266:): 'edit' => 'Standard editor (Edit)',
4267:): 'xml' => 'Text editor (EditXML)',
4268:): 'daxe' => 'Daxe editor (Daxe)',
4269:): );
1.275 raeburn 4270: foreach my $tool (@{$usertools}) {
1.383 raeburn 4271: my ($newval,$limit,$envkey);
1.362 raeburn 4272: $envkey = $context.'.'.$tool;
1.306 raeburn 4273: if ($context eq 'requestcourses') {
4274: $newval = $env{'form.crsreq_'.$tool};
4275: if ($newval eq 'autolimit') {
1.383 raeburn 4276: $limit = $env{'form.crsreq_'.$tool.'_limit'};
4277: $limit =~ s/\D+//g;
4278: $newval .= '='.$limit;
1.306 raeburn 4279: }
1.362 raeburn 4280: } elsif ($context eq 'requestauthor') {
4281: $newval = $env{'form.'.$context};
4282: $envkey = $context;
1.406.2.20.2. (raeburn 4283:): } elsif ($context eq 'authordefaults') {
4284:): if ($tool eq 'editors') {
4285:): $envkey = 'authoreditors';
4286:): if ($env{'form.customeditors'} == 1) {
4287:): my @editors;
4288:): my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
4289:): if (@posseditors) {
4290:): foreach my $editor (@posseditors) {
4291:): if (grep(/^\Q$editor\E$/,@posseditors)) {
4292:): unless (grep(/^\Q$editor\E$/,@editors)) {
4293:): push(@editors,$editor);
4294:): }
4295:): }
4296:): }
4297:): }
4298:): if (@editors) {
4299:): $newval = join(',',(sort(@editors)));
4300:): }
4301:): }
4302:): } elsif ($tool eq 'managers') {
4303:): $envkey = 'authormanagers';
4304:): my @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
4305:): if (@possibles) {
4306:): my %ca_roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},
4307:): undef,['active','future'],['ca']);
4308:): if (keys(%ca_roles)) {
4309:): my @custommanagers;
4310:): foreach my $user (@possibles) {
4311:): if ($user =~ /^($match_username):($match_domain)$/) {
4312:): if (exists($ca_roles{$user.':ca'})) {
4313:): unless ($user eq $env{'form.ccuname'}.':'.$env{'form.ccdomain'}) {
4314:): push(@custommanagers,$user);
4315:): }
4316:): }
4317:): }
4318:): }
4319:): if (@custommanagers) {
4320:): $newval = join(',',sort(@custommanagers));
4321:): }
4322:): }
4323:): }
4324:): } elsif ($tool eq 'webdav') {
4325:): $envkey = 'tools.webdav';
4326:): $newval = $env{'form.'.$context.'_'.$tool};
4327:): } elsif ($tool eq 'archive') {
4328:): $envkey = 'authorarchive';
4329:): $newval = $env{'form.'.$context.'_'.$tool};
4330:): }
1.314 raeburn 4331: } else {
1.306 raeburn 4332: $newval = $env{'form.'.$context.'_'.$tool};
4333: }
1.362 raeburn 4334: if ($userenv->{$envkey} ne '') {
1.275 raeburn 4335: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 4336: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4337: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
4338: my $currlimit = $1;
4339: if ($currlimit eq '') {
4340: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4341: } else {
4342: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
4343: }
4344: } elsif ($userenv->{$envkey}) {
4345: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
4346: } else {
4347: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4348: }
1.406.2.20.2. (raeburn 4349:): } elsif ($context eq 'authordefaults') {
4350:): if ($tool eq 'managers') {
4351:): if ($userenv->{$envkey} eq '') {
4352:): $oldaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4353:): } else {
4354:): my $managers = $userenv->{$envkey};
4355:): $managers =~ s/,/, /g;
4356:): $oldaccesstext->{$tool} = $managers;
4357:): }
4358:): } elsif ($tool eq 'editors') {
4359:): $oldaccesstext->{$tool} = &mt('can use: [_1]',
4360:): join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
4361:): } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
4362:): if ($userenv->{$envkey}) {
4363:): $oldaccesstext->{$tool} = &mt("availability set to 'on'");
4364:): } else {
4365:): $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4366:): }
4367:): }
1.275 raeburn 4368: } else {
1.383 raeburn 4369: if ($userenv->{$envkey}) {
4370: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
4371: } else {
4372: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4373: }
1.275 raeburn 4374: }
1.362 raeburn 4375: $changeHash->{$envkey} = $userenv->{$envkey};
1.406.2.20.2. (raeburn 4376:): if (($env{'form.custom'.$tool} == 1) ||
4377:): (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
1.362 raeburn 4378: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 4379: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
4380: $context);
1.275 raeburn 4381: if ($changed->{$tool}) {
4382: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 4383: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4384: if ($newval =~ /^autolimit/) {
4385: if ($limit) {
4386: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4387: } else {
4388: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4389: }
4390: } elsif ($newval) {
4391: $newaccesstext->{$tool} = $reqdisplay{$newval};
4392: } else {
4393: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4394: }
1.406.2.20.2. (raeburn 4395:): } elsif ($context eq 'authordefaults') {
4396:): if ($tool eq 'editors') {
4397:): $newaccesstext->{$tool} = &mt('can use: [_1]',
4398:): join(', ', map { $tooldesc{$_} } split(/,/,$changeHash->{$envkey})));
4399:): } elsif ($tool eq 'managers') {
4400:): if ($changeHash->{$envkey} eq '') {
4401:): $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4402:): } else {
4403:): my $managers = $changeHash->{$envkey};
4404:): $managers =~ s/,/, /g;
4405:): $newaccesstext->{$tool} = $managers;
4406:): }
4407:): } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
4408:): if ($newval) {
4409:): $newaccesstext->{$tool} = &mt("availability set to 'on'");
4410:): } else {
4411:): $newaccesstext->{$tool} = &mt("availability set to 'off'");
4412:): }
4413:): }
1.275 raeburn 4414: } else {
1.383 raeburn 4415: if ($newval) {
4416: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4417: } else {
4418: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4419: }
1.275 raeburn 4420: }
4421: } else {
4422: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 4423: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.406.2.20.2. (raeburn 4424:): if ($userenv->{$envkey} =~ /^autolimit/) {
1.383 raeburn 4425: if ($limit) {
4426: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4427: } else {
4428: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4429: }
1.406.2.20.2. (raeburn 4430:): } elsif ($userenv->{$envkey}) {
4431:): $newaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
1.383 raeburn 4432: } else {
4433: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4434: }
1.406.2.20.2. (raeburn 4435:): } elsif ($context eq 'authordefaults') {
4436:): if ($tool eq 'editors') {
4437:): $newaccesstext->{$tool} = &mt('can use: [_1]',
4438:): join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
4439:): } elsif ($tool eq 'managers') {
4440:): if ($userenv->{$envkey} eq '') {
4441:): $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4442:): } else {
4443:): my $managers = $userenv->{$envkey};
4444:): $managers =~ s/,/, /g;
4445:): $newaccesstext->{$tool} = $managers;
4446:): }
4447:): } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
4448:): if ($userenv->{$envkey}) {
4449:): $newaccesstext->{$tool} = &mt("availability set to 'on'");
4450:): } else {
4451:): $newaccesstext->{$tool} = &mt("availability set to 'off'");
4452:): }
4453:): }
1.275 raeburn 4454: } else {
1.383 raeburn 4455: if ($userenv->{$context.'.'.$tool}) {
4456: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4457: } else {
4458: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4459: }
1.275 raeburn 4460: }
4461: }
4462: } else {
4463: $newaccess->{$tool} = $oldaccess->{$tool};
4464: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
4465: }
4466: } else {
4467: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
4468: if ($changed->{$tool}) {
4469: $newaccess->{$tool} = &mt('default');
4470: } else {
4471: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 4472: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4473: if ($newval =~ /^autolimit/) {
4474: if ($limit) {
4475: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4476: } else {
4477: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4478: }
4479: } elsif ($newval) {
4480: $newaccesstext->{$tool} = $reqdisplay{$newval};
4481: } else {
4482: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4483: }
1.406.2.20.2. (raeburn 4484:): } elsif ($context eq 'authordefaults') {
4485:): if ($tool eq 'editors') {
4486:): $newaccesstext->{$tool} = &mt('can use: [_1]',
4487:): join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
4488:): } elsif ($tool eq 'managers') {
4489:): if ($newval eq '') {
4490:): $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4491:): } else {
4492:): my $managers = $newval;
4493:): $managers =~ s/,/, /g;
4494:): $newaccesstext->{$tool} = $managers;
4495:): }
4496:): } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
4497:): if ($newval) {
4498:): $newaccesstext->{$tool} = &mt("availability set to 'on'");
4499:): } else {
4500:): $newaccesstext->{$tool} = &mt("availability set to 'off'");
4501:): }
4502:): }
1.275 raeburn 4503: } else {
1.383 raeburn 4504: if ($userenv->{$context.'.'.$tool}) {
4505: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4506: } else {
4507: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4508: }
1.275 raeburn 4509: }
4510: }
4511: }
4512: } else {
4513: $oldaccess->{$tool} = &mt('default');
1.406.2.20.2. (raeburn 4514:): if (($env{'form.custom'.$tool} == 1) ||
4515:): (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
1.306 raeburn 4516: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
4517: $context);
1.275 raeburn 4518: if ($changed->{$tool}) {
4519: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 4520: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4521: if ($newval =~ /^autolimit/) {
4522: if ($limit) {
4523: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4524: } else {
4525: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4526: }
4527: } elsif ($newval) {
4528: $newaccesstext->{$tool} = $reqdisplay{$newval};
4529: } else {
4530: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4531: }
1.406.2.20.2. (raeburn 4532:): } elsif ($context eq 'authordefaults') {
4533:): if ($tool eq 'managers') {
4534:): if ($newval eq '') {
4535:): $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4536:): } else {
4537:): my $managers = $newval;
4538:): $managers =~ s/,/, /g;
4539:): $newaccesstext->{$tool} = $managers;
4540:): }
4541:): } elsif ($tool eq 'editors') {
4542:): $newaccesstext->{$tool} = &mt('can use: [_1]',
4543:): join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
4544:): } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
4545:): if ($newval) {
4546:): $newaccesstext->{$tool} = &mt("availability set to 'on'");
4547:): } else {
4548:): $newaccesstext->{$tool} = &mt("availability set to 'off'");
4549:): }
4550:): }
1.275 raeburn 4551: } else {
1.383 raeburn 4552: if ($newval) {
4553: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4554: } else {
4555: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4556: }
1.275 raeburn 4557: }
4558: } else {
4559: $newaccess->{$tool} = $oldaccess->{$tool};
4560: }
4561: } else {
4562: $newaccess->{$tool} = $oldaccess->{$tool};
4563: }
4564: }
4565: }
4566: return;
4567: }
4568:
1.220 raeburn 4569: sub update_roles {
1.375 raeburn 4570: my ($r,$context,$showcredits) = @_;
1.4 www 4571: my $now=time;
1.225 raeburn 4572: my @rolechanges;
1.220 raeburn 4573: my %disallowed;
1.73 sakharuk 4574: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 4575: foreach my $key (keys(%env)) {
1.135 raeburn 4576: next if (! $env{$key});
1.190 raeburn 4577: next if ($key eq 'form.action');
1.27 matthew 4578: # Revoke roles
1.135 raeburn 4579: if ($key=~/^form\.rev/) {
4580: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 4581: # Revoke standard role
1.170 albertel 4582: my ($scope,$role) = ($1,$2);
4583: my $result =
4584: &Apache::lonnet::revokerole($env{'form.ccdomain'},
4585: $env{'form.ccuname'},
1.239 raeburn 4586: $scope,$role,'','',$context);
1.367 golterma 4587: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4588: &mt('Revoking [_1] in [_2]',
4589: &Apache::lonnet::plaintext($role),
1.372 raeburn 4590: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4591: $result ne "ok").'<br />');
4592: if ($result ne "ok") {
4593: $r->print(&mt('Error: [_1]',$result).'<br />');
4594: }
1.170 albertel 4595: if ($role eq 'st') {
1.202 raeburn 4596: my $result =
1.198 raeburn 4597: &Apache::lonuserutils::classlist_drop($scope,
4598: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4599: $now);
1.367 golterma 4600: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 4601: }
1.225 raeburn 4602: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4603: push(@rolechanges,$role);
4604: }
1.196 raeburn 4605: }
1.195 raeburn 4606: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 4607: # Revoke custom role
1.369 bisitz 4608: my $result = &Apache::lonnet::revokecustomrole(
4609: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 4610: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4611: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 4612: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4613: $result ne 'ok').'<br />');
4614: if ($result ne "ok") {
4615: $r->print(&mt('Error: [_1]',$result).'<br />');
4616: }
1.225 raeburn 4617: if (!grep(/^cr$/,@rolechanges)) {
4618: push(@rolechanges,'cr');
4619: }
1.64 www 4620: }
1.135 raeburn 4621: } elsif ($key=~/^form\.del/) {
4622: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 4623: # Delete standard role
1.170 albertel 4624: my ($scope,$role) = ($1,$2);
4625: my $result =
4626: &Apache::lonnet::assignrole($env{'form.ccdomain'},
4627: $env{'form.ccuname'},
1.239 raeburn 4628: $scope,$role,$now,0,1,'',
4629: $context);
1.367 golterma 4630: $r->print(&Apache::lonhtmlcommon::confirm_success(
4631: &mt('Deleting [_1] in [_2]',
1.369 bisitz 4632: &Apache::lonnet::plaintext($role),
1.372 raeburn 4633: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4634: $result ne 'ok').'<br />');
4635: if ($result ne "ok") {
4636: $r->print(&mt('Error: [_1]',$result).'<br />');
4637: }
1.367 golterma 4638:
1.170 albertel 4639: if ($role eq 'st') {
1.202 raeburn 4640: my $result =
1.198 raeburn 4641: &Apache::lonuserutils::classlist_drop($scope,
4642: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4643: $now);
1.369 bisitz 4644: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 4645: }
1.225 raeburn 4646: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4647: push(@rolechanges,$role);
4648: }
1.116 raeburn 4649: }
1.139 albertel 4650: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4651: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4652: # Delete custom role
1.369 bisitz 4653: my $result =
4654: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
4655: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
4656: 0,1,$context);
4657: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 4658: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4659: $result ne "ok").'<br />');
4660: if ($result ne "ok") {
4661: $r->print(&mt('Error: [_1]',$result).'<br />');
4662: }
1.367 golterma 4663:
1.225 raeburn 4664: if (!grep(/^cr$/,@rolechanges)) {
4665: push(@rolechanges,'cr');
4666: }
1.116 raeburn 4667: }
1.135 raeburn 4668: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4669: my $udom = $env{'form.ccdomain'};
4670: my $uname = $env{'form.ccuname'};
1.116 raeburn 4671: # Re-enable standard role
1.135 raeburn 4672: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4673: my $url = $1;
4674: my $role = $2;
4675: my $logmsg;
4676: my $output;
4677: if ($role eq 'st') {
1.141 albertel 4678: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4679: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4680: my $credits;
4681: if ($showcredits) {
4682: my $defaultcredits =
4683: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4684: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4685: }
4686: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4687: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4688: if ($result eq 'refused' && $logmsg) {
4689: $output = $logmsg;
4690: } else {
1.369 bisitz 4691: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4692: }
1.89 raeburn 4693: } else {
1.372 raeburn 4694: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4695: &Apache::lonnet::plaintext($role),
4696: &Apache::loncommon::show_role_extent($url,$context,'st'),
4697: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4698: }
4699: }
4700: } else {
1.101 albertel 4701: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4702: $env{'form.ccuname'},$url,$role,0,$now,'','',
4703: $context);
1.367 golterma 4704: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 4705: &Apache::lonnet::plaintext($role),
4706: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4707: if ($result ne "ok") {
4708: $output .= &mt('Error: [_1]',$result).'<br />';
4709: }
4710: }
1.89 raeburn 4711: $r->print($output);
1.225 raeburn 4712: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4713: push(@rolechanges,$role);
4714: }
1.113 raeburn 4715: }
1.116 raeburn 4716: # Re-enable custom role
1.139 albertel 4717: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4718: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4719: my $result = &Apache::lonnet::assigncustomrole(
4720: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4721: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4722: $r->print(&Apache::lonhtmlcommon::confirm_success(
4723: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4724: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4725: $result ne "ok").'<br />');
4726: if ($result ne "ok") {
4727: $r->print(&mt('Error: [_1]',$result).'<br />');
4728: }
1.225 raeburn 4729: if (!grep(/^cr$/,@rolechanges)) {
4730: push(@rolechanges,'cr');
4731: }
1.116 raeburn 4732: }
1.135 raeburn 4733: } elsif ($key=~/^form\.act/) {
1.101 albertel 4734: my $udom = $env{'form.ccdomain'};
4735: my $uname = $env{'form.ccuname'};
1.141 albertel 4736: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4737: # Activate a custom role
1.83 albertel 4738: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4739: my $url='/'.$one.'/'.$two;
4740: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4741:
1.101 albertel 4742: my $start = ( $env{'form.start_'.$full} ?
4743: $env{'form.start_'.$full} :
1.88 raeburn 4744: $now );
1.101 albertel 4745: my $end = ( $env{'form.end_'.$full} ?
4746: $env{'form.end_'.$full} :
1.88 raeburn 4747: 0 );
4748:
4749: # split multiple sections
4750: my %sections = ();
1.101 albertel 4751: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4752: if ($num_sections == 0) {
1.240 raeburn 4753: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4754: } else {
1.114 albertel 4755: my %curr_groups =
1.117 raeburn 4756: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4757: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4758: if (($sec eq 'none') || ($sec eq 'all') ||
4759: exists($curr_groups{$sec})) {
4760: $disallowed{$sec} = $url;
4761: next;
4762: }
4763: my $securl = $url.'/'.$sec;
1.240 raeburn 4764: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4765: }
4766: }
1.225 raeburn 4767: if (!grep(/^cr$/,@rolechanges)) {
4768: push(@rolechanges,'cr');
4769: }
1.142 raeburn 4770: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4771: # Activate roles for sections with 3 id numbers
4772: # set start, end times, and the url for the class
1.83 albertel 4773: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4774: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4775: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4776: $now );
1.101 albertel 4777: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4778: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4779: 0 );
1.83 albertel 4780: my $url='/'.$one.'/'.$two;
1.88 raeburn 4781: my $type = 'three';
4782: # split multiple sections
4783: my %sections = ();
1.101 albertel 4784: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4785: my $credits;
4786: if ($three eq 'st') {
4787: if ($showcredits) {
4788: my $defaultcredits =
4789: &Apache::lonuserutils::get_defaultcredits($one,$two);
4790: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4791: $credits =~ s/[^\d\.]//g;
4792: if ($credits eq $defaultcredits) {
4793: undef($credits);
4794: }
4795: }
4796: }
1.88 raeburn 4797: if ($num_sections == 0) {
1.375 raeburn 4798: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4799: } else {
1.114 albertel 4800: my %curr_groups =
1.117 raeburn 4801: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4802: my $emptysec = 0;
1.404 raeburn 4803: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4804: $sec =~ s/\W//g;
1.113 raeburn 4805: if ($sec ne '') {
4806: if (($sec eq 'none') || ($sec eq 'all') ||
4807: exists($curr_groups{$sec})) {
4808: $disallowed{$sec} = $url;
4809: next;
4810: }
1.88 raeburn 4811: my $securl = $url.'/'.$sec;
1.375 raeburn 4812: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4813: } else {
4814: $emptysec = 1;
4815: }
4816: }
4817: if ($emptysec) {
1.375 raeburn 4818: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4819: }
1.225 raeburn 4820: }
4821: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4822: push(@rolechanges,$three);
4823: }
1.135 raeburn 4824: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4825: # Activate roles for sections with two id numbers
4826: # set start, end times, and the url for the class
1.101 albertel 4827: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4828: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4829: $now );
1.101 albertel 4830: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4831: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4832: 0 );
1.225 raeburn 4833: my $one = $1;
4834: my $two = $2;
4835: my $url='/'.$one.'/';
1.88 raeburn 4836: # split multiple sections
4837: my %sections = ();
1.225 raeburn 4838: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4839: if ($num_sections == 0) {
1.240 raeburn 4840: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4841: } else {
4842: my $emptysec = 0;
1.404 raeburn 4843: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4844: if ($sec ne '') {
4845: my $securl = $url.'/'.$sec;
1.240 raeburn 4846: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4847: } else {
4848: $emptysec = 1;
4849: }
4850: }
4851: if ($emptysec) {
1.240 raeburn 4852: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4853: }
4854: }
1.225 raeburn 4855: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4856: push(@rolechanges,$two);
4857: }
1.64 www 4858: } else {
1.190 raeburn 4859: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4860: }
1.113 raeburn 4861: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4862: $r->print('<p class="LC_warning">');
1.113 raeburn 4863: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4864: $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 4865: } else {
1.274 bisitz 4866: $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 4867: }
1.274 bisitz 4868: $r->print('</p><p>'
4869: .&mt('Please [_1]go back[_2] and choose a different section name.'
4870: ,'<a href="javascript:history.go(-1)'
4871: ,'</a>')
4872: .'</p><br />'
4873: );
1.113 raeburn 4874: }
4875: }
1.101 albertel 4876: } # End of foreach (keys(%env))
1.75 www 4877: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4878: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4879: if (@rolechanges == 0) {
1.372 raeburn 4880: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4881: }
1.225 raeburn 4882: return @rolechanges;
1.220 raeburn 4883: }
4884:
1.375 raeburn 4885: sub get_user_credits {
4886: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4887: if ($cdom eq '' || $cnum eq '') {
4888: return unless ($env{'request.course.id'});
4889: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4890: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4891: }
4892: my $credits;
4893: my %currhash =
4894: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4895: if (keys(%currhash) > 0) {
4896: my @items = split(/:/,$currhash{$uname.':'.$udom});
4897: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4898: $credits = $items[$crdidx];
4899: $credits =~ s/[^\d\.]//g;
4900: }
4901: if ($credits eq $defaultcredits) {
4902: undef($credits);
4903: }
4904: return $credits;
4905: }
4906:
1.220 raeburn 4907: sub enroll_single_student {
1.375 raeburn 4908: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4909: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4910: $r->print('<h3>');
4911: if ($crstype eq 'Community') {
4912: $r->print(&mt('Enrolling Member'));
4913: } else {
4914: $r->print(&mt('Enrolling Student'));
4915: }
4916: $r->print('</h3>');
1.220 raeburn 4917:
4918: # Remove non alphanumeric values from section
4919: $env{'form.sections'}=~s/\W//g;
4920:
1.375 raeburn 4921: my $credits;
4922: if (($showcredits) && ($env{'form.credits'} ne '')) {
4923: $credits = $env{'form.credits'};
4924: $credits =~ s/[^\d\.]//g;
4925: if ($credits ne '') {
4926: if ($credits eq $defaultcredits) {
4927: undef($credits);
4928: }
4929: }
4930: }
4931:
1.220 raeburn 4932: # Clean out any old student roles the user has in this class.
4933: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4934: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4935: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4936: my $enroll_result =
4937: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4938: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4939: $env{'form.cmiddlename'},$env{'form.clastname'},
4940: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4941: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4942: $credits);
1.220 raeburn 4943: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4944: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4945: if ($env{'form.sections'} ne '') {
4946: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4947: }
4948: my ($showstart,$showend);
4949: if ($startdate <= $now) {
4950: $showstart = &mt('Access starts immediately');
4951: } else {
4952: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4953: }
4954: if ($enddate == 0) {
4955: $showend = &mt('ends: no ending date');
4956: } else {
4957: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4958: }
4959: $r->print('.<br />'.$showstart.'; '.$showend);
4960: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4961: $r->print('<p class="LC_info">');
1.318 raeburn 4962: if ($crstype eq 'Community') {
1.392 raeburn 4963: $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 4964: } else {
1.392 raeburn 4965: $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 4966: }
4967: $r->print('</p>');
1.220 raeburn 4968: }
4969: } else {
4970: $r->print(&mt('unable to enroll').": ".$enroll_result);
4971: }
4972: return;
1.188 raeburn 4973: }
4974:
1.204 raeburn 4975: sub get_defaultquota_text {
4976: my ($settingstatus) = @_;
4977: my $defquotatext;
4978: if ($settingstatus eq '') {
1.383 raeburn 4979: $defquotatext = &mt('default');
1.204 raeburn 4980: } else {
4981: my ($usertypes,$order) =
4982: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4983: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4984: $defquotatext = &mt('default');
1.204 raeburn 4985: } else {
1.383 raeburn 4986: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4987: }
4988: }
4989: return $defquotatext;
4990: }
4991:
1.188 raeburn 4992: sub update_result_form {
4993: my ($uhome) = @_;
4994: my $outcome =
1.367 golterma 4995: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4996: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4997: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4998: }
1.207 raeburn 4999: if ($env{'form.origname'} ne '') {
5000: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
5001: }
1.160 raeburn 5002: foreach my $item ('sortby','seluname','seludom') {
5003: if (exists($env{'form.'.$item})) {
1.188 raeburn 5004: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 5005: }
5006: }
1.188 raeburn 5007: if ($uhome eq 'no_host') {
5008: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
5009: }
5010: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 5011: '<input type="hidden" name="currstate" value="" />'."\n".
5012: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 5013: '</form>';
5014: return $outcome;
1.4 www 5015: }
5016:
1.149 raeburn 5017: sub quota_admin {
1.378 raeburn 5018: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 5019: my $quotachanged;
5020: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
5021: # Current user has quota modification privileges
1.267 raeburn 5022: if (ref($changeHash) eq 'HASH') {
5023: $quotachanged = 1;
1.378 raeburn 5024: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 5025: }
1.149 raeburn 5026: }
5027: return $quotachanged;
5028: }
5029:
1.267 raeburn 5030: sub tool_admin {
1.275 raeburn 5031: my ($tool,$settool,$changeHash,$context) = @_;
5032: my $canchange = 0;
1.279 raeburn 5033: if ($context eq 'requestcourses') {
1.275 raeburn 5034: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
5035: $canchange = 1;
5036: }
1.300 raeburn 5037: } elsif ($context eq 'reqcrsotherdom') {
5038: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
5039: $canchange = 1;
5040: }
1.362 raeburn 5041: } elsif ($context eq 'requestauthor') {
5042: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
5043: $canchange = 1;
5044: }
1.406.2.20.2. (raeburn 5045:): } elsif ($context eq 'authordefaults') {
5046:): if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
5047:): $canchange = 1;
5048:): }
1.275 raeburn 5049: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
5050: # Current user has quota modification privileges
5051: $canchange = 1;
5052: }
1.267 raeburn 5053: my $toolchanged;
1.275 raeburn 5054: if ($canchange) {
1.267 raeburn 5055: if (ref($changeHash) eq 'HASH') {
5056: $toolchanged = 1;
1.362 raeburn 5057: if ($tool eq 'requestauthor') {
5058: $changeHash->{$context} = $settool;
1.406.2.20.2. (raeburn 5059:): } elsif (($tool eq 'managers') || ($tool eq 'editors') || ($tool eq 'archive')) {
5060:): $changeHash->{'author'.$tool} = $settool;
5061:): } elsif ($tool eq 'webdav') {
5062:): $changeHash->{'tools.'.$tool} = $settool;
1.362 raeburn 5063: } else {
5064: $changeHash->{$context.'.'.$tool} = $settool;
5065: }
1.267 raeburn 5066: }
5067: }
5068: return $toolchanged;
5069: }
5070:
1.88 raeburn 5071: sub build_roles {
1.89 raeburn 5072: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 5073: my $num_sections = 0;
5074: if ($sectionstr=~ /,/) {
5075: my @secnums = split/,/,$sectionstr;
1.89 raeburn 5076: if ($role eq 'st') {
5077: $secnums[0] =~ s/\W//g;
5078: $$sections{$secnums[0]} = 1;
5079: $num_sections = 1;
5080: } else {
5081: foreach my $sec (@secnums) {
5082: $sec =~ ~s/\W//g;
1.150 banghart 5083: if (!($sec eq "")) {
1.89 raeburn 5084: if (exists($$sections{$sec})) {
5085: $$sections{$sec} ++;
5086: } else {
5087: $$sections{$sec} = 1;
5088: $num_sections ++;
5089: }
1.88 raeburn 5090: }
5091: }
5092: }
5093: } else {
5094: $sectionstr=~s/\W//g;
5095: unless ($sectionstr eq '') {
5096: $$sections{$sectionstr} = 1;
5097: $num_sections ++;
5098: }
5099: }
1.129 albertel 5100:
1.88 raeburn 5101: return $num_sections;
5102: }
5103:
1.58 www 5104: # ========================================================== Custom Role Editor
5105:
5106: sub custom_role_editor {
1.406.2.14 raeburn 5107: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 5108: my $action = $env{'form.customroleaction'};
1.406.2.14 raeburn 5109: my ($rolename,$helpitem);
1.324 raeburn 5110: if ($action eq 'new') {
5111: $rolename=$env{'form.newrolename'};
5112: } else {
5113: $rolename=$env{'form.rolename'};
1.59 www 5114: }
5115:
1.324 raeburn 5116: my ($crstype,$context);
5117: if ($env{'request.course.id'}) {
5118: $crstype = &Apache::loncommon::course_type();
5119: $context = 'course';
1.406.2.14 raeburn 5120: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 5121: } else {
5122: $context = 'domain';
1.406.2.5 raeburn 5123: $crstype = 'course';
1.406.2.14 raeburn 5124: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 5125: }
1.351 raeburn 5126:
5127: $rolename=~s/[^A-Za-z0-9]//gs;
5128: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.406.2.14 raeburn 5129: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
5130: $permission);
1.351 raeburn 5131: return;
5132: }
5133:
1.406.2.5 raeburn 5134: my $formname = 'form1';
5135: my %privs=();
5136: my $body_top = '<h2>';
5137: # ------------------------------------------------------- Does this role exist?
1.59 www 5138: my ($rdummy,$roledef)=
5139: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
5140: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.406.2.5 raeburn 5141: $body_top .= &mt('Existing Role').' "';
1.61 www 5142: # ------------------------------------------------- Get current role privileges
1.406.2.5 raeburn 5143: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
5144: if ($privs{'system'} =~ /bre\&S/) {
5145: if ($context eq 'domain') {
5146: $crstype = 'Course';
5147: } elsif ($crstype eq 'Community') {
5148: $privs{'system'} =~ s/bre\&S//;
5149: }
5150: } elsif ($context eq 'domain') {
5151: $crstype = 'Course';
1.324 raeburn 5152: }
1.59 www 5153: } else {
1.406.2.5 raeburn 5154: $body_top .= &mt('New Role').' "';
5155: $roledef='';
1.59 www 5156: }
1.153 banghart 5157: $body_top .= $rolename.'"</h2>';
1.406.2.5 raeburn 5158:
5159: # ------------------------------------------------------- What can be assigned?
5160: my %full=();
5161: my %levels=(
5162: course => {},
5163: domain => {},
5164: system => {},
5165: );
5166: my %levelscurrent=(
5167: course => {},
5168: domain => {},
5169: system => {},
5170: );
5171: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 5172: my ($jsback,$elements) = &crumb_utilities();
1.406.2.5 raeburn 5173: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
5174: my $head_script =
5175: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
5176: \%full,\@templateroles,$jsback);
1.351 raeburn 5177: push (@{$brcrum},
1.406.2.5 raeburn 5178: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 5179: text => "Pick custom role",
5180: faq => 282,bug=>'Instructor Interface',},
1.406.2.5 raeburn 5181: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 5182: text => "Edit custom role",
5183: faq => 282,
5184: bug => 'Instructor Interface',
1.406.2.14 raeburn 5185: help => $helpitem}
1.351 raeburn 5186: );
5187: my $args = { bread_crumbs => $brcrum,
5188: bread_crumbs_component => 'User Management'};
5189: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
5190: $head_script,$args).
5191: $body_top);
1.406.2.5 raeburn 5192: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
5193: &Apache::lonuserutils::custom_role_header($context,$crstype,
5194: \@templateroles,$prefix));
1.264 bisitz 5195:
1.61 www 5196: $r->print(<<ENDCCF);
5197: <input type="hidden" name="phase" value="set_custom_roles" />
5198: <input type="hidden" name="rolename" value="$rolename" />
5199: ENDCCF
1.406.2.5 raeburn 5200: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
5201: \%levelscurrent,$prefix));
1.135 raeburn 5202: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 5203: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 5204: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.406.2.5 raeburn 5205: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 5206: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 5207: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 5208: }
1.406.2.5 raeburn 5209:
1.61 www 5210: # ---------------------------------------------------------- Call to definerole
5211: sub set_custom_role {
1.406.2.14 raeburn 5212: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 5213: my $rolename=$env{'form.rolename'};
1.63 www 5214: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 5215: if (!$rolename) {
1.406.2.14 raeburn 5216: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 5217: return;
5218: }
1.160 raeburn 5219: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 5220: my $jscript = '<script type="text/javascript">'
5221: .'// <![CDATA['."\n"
5222: .$jsback."\n"
5223: .'// ]]>'."\n"
5224: .'</script>'."\n";
1.406.2.14 raeburn 5225: my $helpitem = 'Course_Editing_Custom_Roles';
5226: if ($context eq 'domain') {
5227: $helpitem = 'Domain_Editing_Custom_Roles';
5228: }
1.352 raeburn 5229: push(@{$brcrum},
5230: {href => "javascript:backPage(document.customresult,'pickrole','')",
5231: text => "Pick custom role",
5232: faq => 282,
5233: bug => 'Instructor Interface',},
5234: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
5235: text => "Edit custom role",
5236: faq => 282,
5237: bug => 'Instructor Interface',},
5238: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
5239: text => "Result",
5240: faq => 282,
5241: bug => 'Instructor Interface',
1.406.2.14 raeburn 5242: help => $helpitem,}
1.352 raeburn 5243: );
5244: my $args = { bread_crumbs => $brcrum,
1.406.2.5 raeburn 5245: bread_crumbs_component => 'User Management'};
1.351 raeburn 5246: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 5247:
1.393 raeburn 5248: my $newrole;
1.61 www 5249: my ($rdummy,$roledef)=
1.110 albertel 5250: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
5251:
1.61 www 5252: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 5253: $r->print('<h3>');
1.61 www 5254: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 5255: $r->print(&mt('Existing Role').' "');
1.61 www 5256: } else {
1.73 sakharuk 5257: $r->print(&mt('New Role').' "');
1.61 www 5258: $roledef='';
1.393 raeburn 5259: $newrole = 1;
1.61 www 5260: }
1.188 raeburn 5261: $r->print($rolename.'"</h3>');
1.406.2.5 raeburn 5262: # ------------------------------------------------- Assign role and show result
1.61 www 5263:
1.387 bisitz 5264: my $errmsg;
1.406.2.5 raeburn 5265: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
5266: # Assign role and return result
5267: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
5268: $newprivs{'c'});
1.387 bisitz 5269: if ($result ne 'ok') {
5270: $errmsg = ': '.$result;
5271: }
5272: my $message =
5273: &Apache::lonhtmlcommon::confirm_success(
5274: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 5275: if ($env{'request.course.id'}) {
5276: my $url='/'.$env{'request.course.id'};
1.63 www 5277: $url=~s/\_/\//g;
1.387 bisitz 5278: $result =
5279: &Apache::lonnet::assigncustomrole(
5280: $env{'user.domain'},$env{'user.name'},
5281: $url,
5282: $env{'user.domain'},$env{'user.name'},
5283: $rolename,undef,undef,undef,$context);
5284: if ($result ne 'ok') {
5285: $errmsg = ': '.$result;
5286: }
5287: $message .=
5288: '<br />'
5289: .&Apache::lonhtmlcommon::confirm_success(
5290: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 5291: }
1.380 bisitz 5292: $r->print(
1.387 bisitz 5293: &Apache::loncommon::confirmwrapper($message)
5294: .'<br />'
5295: .&Apache::lonhtmlcommon::actionbox([
5296: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
5297: .&mt('Create or edit another custom role')
5298: .'</a>'])
1.380 bisitz 5299: .'<form name="customresult" method="post" action="">'
1.387 bisitz 5300: .&Apache::lonhtmlcommon::echo_form_input([])
5301: .'</form>'
1.380 bisitz 5302: );
1.58 www 5303: }
5304:
1.406.2.20.2. (raeburn 5305:): sub display_coauthor_managers {
5306:): my ($permission) = @_;
5307:): my $output;
5308:): if ((ref($permission) eq 'HASH') && ($permission->{'author'})) {
5309:): $output = '<form action="/adm/createuser" method="post" name="camanagers">'.
5310:): '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
5311:): '<p>';
5312:): my (@possmanagers,@custommanagers);
5313:): my %userenv =
5314:): &Apache::lonnet::userenvironment($env{'user.domain'},
5315:): $env{'user.name'},
5316:): 'authormanagers');
5317:): my %ca_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5318:): ['active','future'],['ca']);
5319:): if (keys(%ca_roles)) {
5320:): foreach my $entry (sort(keys(%ca_roles))) {
5321:): if ($entry =~ /^($match_username\:$match_domain):ca$/) {
5322:): my $user = $1;
5323:): unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5324:): push(@possmanagers,$user);
5325:): }
5326:): }
5327:): }
5328:): }
5329:): if ($userenv{'authormanagers'} eq '') {
5330:): $output .= &mt('Currently author manages co-author roles');
5331:): } else {
5332:): if (keys(%ca_roles)) {
5333:): foreach my $user (split(/,/,$userenv{'authormanagers'})) {
5334:): if ($user =~ /^($match_username)\:($match_domain)$/) {
5335:): if (exists($ca_roles{$user.':ca'})) {
5336:): unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5337:): push(@custommanagers,$user);
5338:): }
5339:): }
5340:): }
5341:): }
5342:): }
5343:): if (@custommanagers) {
5344:): $output .= &mt('Co-authors with active or future roles who currently manage co-author roles: [_1]',
5345:): '<br />'.join(', ',map { &Apache::loncommon::plainname(split(':',$_))." ($_)"; } @custommanagers));
5346:): } else {
5347:): $output .= &mt('Currently author manages co-author roles');
5348:): }
5349:): }
5350:): $output .= "</p>\n";
5351:): if (@possmanagers) {
5352:): $output .= '<p>'.&mt('If checked, can manage').': ';
5353:): foreach my $user (@possmanagers) {
5354:): my $checked;
5355:): if (grep(/^\Q$user\E$/,@custommanagers)) {
5356:): $checked = ' checked="checked"';
5357:): }
5358:): $output .= '<span style="LC_nobreak"><label>'.
5359:): '<input type="checkbox" name="custommanagers" '.
5360:): 'value="'.&HTML::Entities::encode($user,'\'<>"&').'"'.$checked.' />'.
5361:): &Apache::loncommon::plainname(split(/:/,$user))." ($user)".'</label></span> '."\n";
5362:): }
5363:): $output .= '<input type="hidden" name="state" value="process" /></p>'."\n".
5364:): '<p><input type="submit" value="'.&mt('Save changes').'" /></p>'."\n";
5365:): } else {
5366:): $output .= '<p>'.&mt('No co-author roles assignable as manager').'</p>';
5367:): }
5368:): $output .= '</form>';
5369:): } else {
5370:): $output = '<span class="LC_warning">'.
5371:): &mt('You do not have permission to perform this action').
5372:): '</span>';
5373:): }
5374:): return $output;
5375:): }
5376:):
5377:): sub update_coauthor_managers {
5378:): my ($permission) = @_;
5379:): my $output;
5380:): if ((ref($permission) eq 'HASH') && ($permission->{'author'})) {
5381:): my ($current,$newval,@possibles,@managers);
5382:): my %userenv =
5383:): &Apache::lonnet::userenvironment($env{'user.domain'},
5384:): $env{'user.name'},
5385:): 'authormanagers');
5386:): $current = $userenv{'authormanagers'};
5387:): @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
5388:): if (@possibles) {
5389:): my %ca_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5390:): ['active','future'],['ca']);
5391:): if (keys(%ca_roles)) {
5392:): foreach my $user (@possibles) {
5393:): if ($user =~ /^($match_username):($match_domain)$/) {
5394:): if (exists($ca_roles{$user.':ca'})) {
5395:): unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5396:): push(@managers,$user);
5397:): }
5398:): }
5399:): }
5400:): }
5401:): if (@managers) {
5402:): $newval = join(',',sort(@managers));
5403:): }
5404:): }
5405:): }
5406:): if ($current eq $newval) {
5407:): $output = &mt('No changes made to management of co-author roles');
5408:): } else {
5409:): my $chgresult =
5410:): &Apache::lonnet::put('environment',{'authormanagers' => $newval},
5411:): $env{'user.domain'},$env{'user.name'});
5412:): if ($chgresult eq 'ok') {
5413:): &Apache::lonnet::appenv({'environment.authormanagers' => $newval});
5414:): my (@adds,@dels);
5415:): if ($newval eq '') {
5416:): @dels = split(/,/,$current);
5417:): } elsif ($current eq '') {
5418:): @adds = @managers;
5419:): } else {
5420:): my @old = split(/,/,$current);
5421:): my @diffs = &Apache::loncommon::compare_arrays(\@old,\@managers);
5422:): if (@diffs) {
5423:): foreach my $user (@diffs) {
5424:): if (grep(/^\Q$user\E$/,@old)) {
5425:): push(@dels,$user);
5426:): } elsif (grep(/^\Q$user\E$/,@managers)) {
5427:): push(@adds,$user);
5428:): }
5429:): }
5430:): }
5431:): }
5432:): my $key = "internal.manager./$env{'user.domain'}/$env{'user.name'}";
5433:): if (@dels) {
5434:): foreach my $user (@dels) {
5435:): if ($user =~ /^($match_username):($match_domain)$/) {
5436:): &Apache::lonnet::del('environment',[$key],$2,$1);
5437:): }
5438:): }
5439:): }
5440:): if (@adds) {
5441:): foreach my $user (@adds) {
5442:): if ($user =~ /^($match_username):($match_domain)$/) {
5443:): &Apache::lonnet::put('environment',{$key => 1},$2,$1);
5444:): }
5445:): }
5446:): }
5447:): if ($newval eq '') {
5448:): $output = &mt('Management of co-authors set to be author-only');
5449:): } else {
5450:): $output .= &mt('Co-authors who can manage co-author roles set to: [_1]',
5451:): '<br />'.join(', ',map { &Apache::loncommon::plainname(split(':',$_))." ($_)"; } @managers));
5452:): }
5453:): }
5454:): }
5455:): } else {
5456:): $output = '<span class="LC_warning">'.
5457:): &mt('You do not have permission to perform this action').
5458:): '</span>';
5459:): }
5460:): return $output;
5461:): }
5462:):
1.2 www 5463: # ================================================================ Main Handler
5464: sub handler {
5465: my $r = shift;
5466: if ($r->header_only) {
1.68 www 5467: &Apache::loncommon::content_type($r,'text/html');
1.2 www 5468: $r->send_http_header;
5469: return OK;
5470: }
1.406.2.14 raeburn 5471: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
5472:
1.190 raeburn 5473: if ($env{'request.course.id'}) {
5474: $context = 'course';
1.318 raeburn 5475: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 5476: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 5477: $context = 'author';
1.406.2.20.2. (raeburn 5478:): } elsif ($env{'request.role'} =~ m{^(ca|aa)\./$match_domain/$match_username$}) {
5479:): $context = 'coauthor';
1.190 raeburn 5480: } else {
5481: $context = 'domain';
5482: }
1.375 raeburn 5483:
1.406.2.14 raeburn 5484: my ($permission,$allowed) =
5485: &Apache::lonuserutils::get_permission($context,$crstype);
1.406.2.20.2. (raeburn 5486:): if (($context eq 'coauthor') && ($allowed)) {
5487:): $context = 'author';
5488:): }
1.406.2.14 raeburn 5489:
5490: if ($allowed) {
5491: my @allhelp;
5492: if ($context eq 'course') {
5493: $cid = $env{'request.course.id'};
5494: $cdom = $env{'course.'.$cid.'.domain'};
5495: $cnum = $env{'course.'.$cid.'.num'};
5496:
5497: if ($permission->{'cusr'}) {
5498: push(@allhelp,'Course_Create_Class_List');
5499: }
5500: if ($permission->{'view'} || $permission->{'cusr'}) {
5501: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
5502: }
5503: if ($permission->{'custom'}) {
5504: push(@allhelp,'Course_Editing_Custom_Roles');
5505: }
5506: if ($permission->{'cusr'}) {
5507: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
5508: }
5509: unless ($permission->{'cusr_section'}) {
5510: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
5511: push(@allhelp,'Course_Automated_Enrollment');
5512: }
1.406.2.20.2. (raeburn 5513:): if (($permission->{'selfenrolladmin'}) || ($permission->{'selfenrollview'})) {
1.406.2.14 raeburn 5514: push(@allhelp,'Course_Approve_Selfenroll');
5515: }
5516: }
5517: if ($permission->{'grp_manage'}) {
5518: push(@allhelp,'Course_Manage_Group');
5519: }
5520: if ($permission->{'view'} || $permission->{'cusr'}) {
5521: push(@allhelp,'Course_User_Logs');
5522: }
5523: } elsif ($context eq 'author') {
5524: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
5525: 'Author_View_Coauthor_List','Author_User_Logs'));
1.406.2.20.2. (raeburn 5526:): } elsif ($context eq 'coauthor') {
5527:): if ($permission->{'cusr'}) {
5528:): push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
5529:): 'Author_View_Coauthor_List','Author_User_Logs'));
5530:): } elsif ($permission->{'view'}) {
5531:): push(@allhelp,'Author_View_Coauthor_List');
5532:): }
1.406.2.14 raeburn 5533: } else {
5534: if ($permission->{'cusr'}) {
5535: push(@allhelp,'Domain_Change_Privileges');
5536: if ($permission->{'activity'}) {
5537: push(@allhelp,'Domain_User_Access_Logs');
5538: }
5539: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
5540: if ($permission->{'custom'}) {
5541: push(@allhelp,'Domain_Editing_Custom_Roles');
5542: }
5543: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
5544: } elsif ($permission->{'view'}) {
5545: push(@allhelp,'Domain_View_Privileges');
5546: if ($permission->{'activity'}) {
5547: push(@allhelp,'Domain_User_Access_Logs');
5548: }
5549: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
5550: }
5551: }
5552: if (@allhelp) {
5553: $allhelpitems = join(',',@allhelp);
5554: }
5555: }
5556:
1.190 raeburn 5557: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 5558: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.406.2.20.2. (raeburn 5559:): 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue',
5560:): 'forceedit']);
1.190 raeburn 5561: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 5562: my $args;
5563: my $brcrum = [];
5564: my $bread_crumbs_component = 'User Management';
1.391 raeburn 5565: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 5566: $brcrum = [{href=>"/adm/createuser",
5567: text=>"User Management",
1.406.2.14 raeburn 5568: help=>$allhelpitems}
1.351 raeburn 5569: ];
1.202 raeburn 5570: }
1.190 raeburn 5571: if (!$allowed) {
1.358 raeburn 5572: if ($context eq 'course') {
5573: $r->internal_redirect('/adm/viewclasslist');
5574: return OK;
1.406.2.20.2. (raeburn 5575:): } elsif ($context eq 'coauthor') {
5576:): $r->internal_redirect('/adm/viewcoauthors');
5577:): return OK;
1.358 raeburn 5578: }
1.190 raeburn 5579: $env{'user.error.msg'}=
5580: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
5581: "or view user status.";
5582: return HTTP_NOT_ACCEPTABLE;
5583: }
5584:
5585: &Apache::loncommon::content_type($r,'text/html');
5586: $r->send_http_header;
5587:
1.375 raeburn 5588: my $showcredits;
5589: if ((($context eq 'course') && ($crstype eq 'Course')) ||
5590: ($context eq 'domain')) {
5591: my %domdefaults =
5592: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
5593: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
5594: $showcredits = 1;
5595: }
5596: }
5597:
1.190 raeburn 5598: # Main switch on form.action and form.state, as appropriate
5599: if (! exists($env{'form.action'})) {
1.351 raeburn 5600: $args = {bread_crumbs => $brcrum,
5601: bread_crumbs_component => $bread_crumbs_component};
5602: $r->print(&header(undef,$args));
1.318 raeburn 5603: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5604: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.406.2.14 raeburn 5605: my $helpitem = 'Course_Create_Class_List';
5606: if ($context eq 'author') {
5607: $helpitem = 'Author_Create_Coauthor_List';
5608: } elsif ($context eq 'domain') {
5609: $helpitem = 'Domain_Create_Users';
5610: }
1.351 raeburn 5611: push(@{$brcrum},
5612: { href => '/adm/createuser?action=upload&state=',
5613: text => 'Upload Users List',
1.406.2.14 raeburn 5614: help => $helpitem,
1.351 raeburn 5615: });
5616: $bread_crumbs_component = 'Upload Users List';
5617: $args = {bread_crumbs => $brcrum,
5618: bread_crumbs_component => $bread_crumbs_component};
5619: $r->print(&header(undef,$args));
1.190 raeburn 5620: $r->print('<form name="studentform" method="post" '.
5621: 'enctype="multipart/form-data" '.
5622: ' action="/adm/createuser">'."\n");
5623: if (! exists($env{'form.state'})) {
5624: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5625: } elsif ($env{'form.state'} eq 'got_file') {
1.406.2.15 raeburn 5626: my $result =
5627: &Apache::lonuserutils::print_upload_manager_form($r,$context,
5628: $permission,
5629: $crstype,$showcredits);
5630: if ($result eq 'missingdata') {
5631: delete($env{'form.state'});
5632: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5633: }
1.190 raeburn 5634: } elsif ($env{'form.state'} eq 'enrolling') {
5635: if ($env{'form.datatoken'}) {
1.406.2.15 raeburn 5636: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
5637: $permission,
5638: $showcredits);
5639: if ($result eq 'missingdata') {
5640: delete($env{'form.state'});
5641: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5642: } elsif ($result eq 'invalidhome') {
5643: $env{'form.state'} = 'got_file';
5644: delete($env{'form.lcserver'});
5645: my $result =
5646: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
5647: $crstype,$showcredits);
5648: if ($result eq 'missingdata') {
5649: delete($env{'form.state'});
5650: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5651: }
5652: }
5653: } else {
5654: delete($env{'form.state'});
5655: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 5656: }
5657: } else {
5658: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5659: }
1.406.2.15 raeburn 5660: $r->print('</form>');
1.406.2.5 raeburn 5661: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
5662: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.406.2.6 raeburn 5663: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.406.2.5 raeburn 5664: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 5665: my $phase = $env{'form.phase'};
5666: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 5667: &Apache::loncreateuser::restore_prev_selections();
5668: my $srch;
5669: foreach my $item (@search) {
5670: $srch->{$item} = $env{'form.'.$item};
5671: }
1.207 raeburn 5672: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.406.2.5 raeburn 5673: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 5674: if ($env{'form.phase'} eq 'createnewuser') {
5675: my $response;
5676: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 5677: my $response =
5678: '<span class="LC_warning">'
5679: .&mt('You must specify a valid username. Only the following are allowed:'
5680: .' letters numbers - . @')
5681: .'</span>';
1.221 raeburn 5682: $env{'form.phase'} = '';
1.375 raeburn 5683: &print_username_entry_form($r,$context,$response,$srch,undef,
1.406.2.14 raeburn 5684: $crstype,$brcrum,$permission);
1.207 raeburn 5685: } else {
5686: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
5687: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
5688: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 5689: $srch,$response,$context,
1.375 raeburn 5690: $permission,$crstype,$brcrum,
5691: $showcredits);
1.207 raeburn 5692: }
5693: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 5694: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 5695: &user_search_result($context,$srch);
1.190 raeburn 5696: if ($env{'form.currstate'} eq 'modify') {
5697: $currstate = $env{'form.currstate'};
5698: }
5699: if ($currstate eq 'select') {
5700: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 5701: \@search,$context,undef,$crstype,
5702: $brcrum);
1.406.2.5 raeburn 5703: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
5704: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 5705: if (($srch->{'srchby'} eq 'uname') &&
5706: ($srch->{'srchtype'} eq 'exact')) {
5707: $ccuname = $srch->{'srchterm'};
5708: $ccdomain= $srch->{'srchdomain'};
5709: } else {
5710: my @matchedunames = keys(%{$results});
5711: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
5712: }
5713: $ccuname =&LONCAPA::clean_username($ccuname);
5714: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.406.2.5 raeburn 5715: if ($env{'form.action'} eq 'accesslogs') {
5716: my $uhome;
5717: if (($ccuname ne '') && ($ccdomain ne '')) {
5718: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
5719: }
5720: if (($uhome eq '') || ($uhome eq 'no_host')) {
5721: $env{'form.phase'} = '';
5722: undef($forcenewuser);
5723: #if ($response) {
5724: # unless ($response =~ m{\Q<br /><br />\E$}) {
5725: # $response .= '<br /><br />';
5726: # }
5727: #}
5728: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 5729: $forcenewuser,$crstype,$brcrum,
5730: $permission);
1.406.2.5 raeburn 5731: } else {
5732: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
5733: }
5734: } else {
5735: if ($env{'form.forcenewuser'}) {
5736: $response = '';
5737: }
5738: &print_user_modification_page($r,$ccuname,$ccdomain,
5739: $srch,$response,$context,
5740: $permission,$crstype,$brcrum);
1.190 raeburn 5741: }
5742: } elsif ($currstate eq 'query') {
1.351 raeburn 5743: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 5744: } else {
1.229 raeburn 5745: $env{'form.phase'} = '';
1.207 raeburn 5746: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 5747: $forcenewuser,$crstype,$brcrum,
5748: $permission);
1.190 raeburn 5749: }
5750: } elsif ($env{'form.phase'} eq 'userpicked') {
5751: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
5752: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.406.2.5 raeburn 5753: if ($env{'form.action'} eq 'accesslogs') {
5754: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
5755: } else {
5756: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
5757: $context,$permission,$crstype,
5758: $brcrum);
5759: }
5760: } elsif ($env{'form.action'} eq 'accesslogs') {
5761: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
5762: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
5763: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 5764: }
5765: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.406.2.17 raeburn 5766: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 5767: } else {
1.351 raeburn 5768: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.406.2.14 raeburn 5769: $brcrum,$permission);
1.190 raeburn 5770: }
5771: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.406.2.5 raeburn 5772: my $prefix;
1.190 raeburn 5773: if ($env{'form.phase'} eq 'set_custom_roles') {
1.406.2.14 raeburn 5774: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 5775: } else {
1.406.2.14 raeburn 5776: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 5777: }
1.362 raeburn 5778: } elsif (($env{'form.action'} eq 'processauthorreq') &&
5779: ($permission->{'cusr'}) &&
5780: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
5781: push(@{$brcrum},
5782: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 5783: text => 'Authoring Space requests',
1.362 raeburn 5784: help => 'Domain_Role_Approvals'});
5785: $bread_crumbs_component = 'Authoring requests';
5786: if ($env{'form.state'} eq 'done') {
5787: push(@{$brcrum},
5788: {href => '/adm/createuser?action=authorreqqueue',
5789: text => 'Result',
5790: help => 'Domain_Role_Approvals'});
5791: $bread_crumbs_component = 'Authoring request result';
5792: }
5793: $args = { bread_crumbs => $brcrum,
5794: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 5795: my $js = &usernamerequest_javascript();
5796: $r->print(&header(&add_script($js),$args));
1.362 raeburn 5797: if (!exists($env{'form.state'})) {
5798: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
5799: $env{'request.role.domain'}));
5800: } elsif ($env{'form.state'} eq 'done') {
5801: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
5802: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
5803: $env{'request.role.domain'}));
5804: }
1.391 raeburn 5805: } elsif (($env{'form.action'} eq 'processusernamereq') &&
5806: ($permission->{'cusr'}) &&
5807: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
5808: push(@{$brcrum},
5809: {href => '/adm/createuser?action=processusernamereq',
5810: text => 'LON-CAPA account requests',
5811: help => 'Domain_Username_Approvals'});
5812: $bread_crumbs_component = 'Account requests';
5813: if ($env{'form.state'} eq 'done') {
5814: push(@{$brcrum},
5815: {href => '/adm/createuser?action=usernamereqqueue',
5816: text => 'Result',
5817: help => 'Domain_Username_Approvals'});
5818: $bread_crumbs_component = 'LON-CAPA account request result';
5819: }
5820: $args = { bread_crumbs => $brcrum,
5821: bread_crumbs_component => $bread_crumbs_component};
5822: my $js = &usernamerequest_javascript();
5823: $r->print(&header(&add_script($js),$args));
5824: if (!exists($env{'form.state'})) {
5825: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
5826: $env{'request.role.domain'}));
5827: } elsif ($env{'form.state'} eq 'done') {
5828: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
5829: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
5830: $env{'request.role.domain'}));
5831: }
5832: } elsif (($env{'form.action'} eq 'displayuserreq') &&
5833: ($permission->{'cusr'})) {
5834: my $dom = $env{'form.domain'};
5835: my $uname = $env{'form.username'};
5836: my $warning;
5837: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
5838: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
5839: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
5840: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
5841: if ($uhome eq 'no_host') {
5842: my $queue = $env{'form.queue'};
5843: my $reqkey = &escape($uname).'_'.$queue;
5844: my $namespace = 'usernamequeue';
5845: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
5846: my %queued =
5847: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
5848: unless ($queued{$reqkey}) {
5849: $warning = &mt('No information was found for this LON-CAPA account request.');
5850: }
5851: } else {
5852: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
5853: }
5854: } else {
5855: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
5856: }
5857: } else {
5858: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
5859: }
5860: } else {
5861: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
5862: }
5863: my $args = { only_body => 1 };
5864: $r->print(&header(undef,$args).
5865: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
5866: if ($warning ne '') {
5867: $r->print('<div class="LC_warning">'.$warning.'</div>');
5868: } else {
5869: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5870: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
5871: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5872: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5873: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
5874: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
5875: my %info =
5876: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
5877: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 5878: my $usertype = $info{$uname}{'inststatus'};
5879: unless ($usertype) {
5880: $usertype = 'default';
5881: }
1.406.2.16 raeburn 5882: my ($showstatus,$showemail,$pickstart);
5883: my $numextras = 0;
5884: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5885: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
5886: if (ref($usertypes) eq 'HASH') {
5887: if ($usertypes->{$usertype}) {
5888: $showstatus = $usertypes->{$usertype};
5889: } else {
5890: $showstatus = $othertitle;
5891: }
5892: if ($showstatus) {
5893: $numextras ++;
5894: }
5895: }
5896: }
5897: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5898: $showemail = $info{$uname}{'email'};
5899: $numextras ++;
5900: }
1.396 raeburn 5901: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5902: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.406.2.16 raeburn 5903: $pickstart = 1;
1.396 raeburn 5904: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.406.2.16 raeburn 5905: my ($num,$count);
1.396 raeburn 5906: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.406.2.16 raeburn 5907: $count += $numextras;
1.396 raeburn 5908: foreach my $field (@{$infofields}) {
5909: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5910: next unless ($infotitles->{$field});
5911: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5912: $info{$uname}{$field});
5913: $num ++;
1.406.2.16 raeburn 5914: unless ($count == $num) {
1.396 raeburn 5915: $r->print(&Apache::lonhtmlcommon::row_closure());
5916: }
5917: }
1.406.2.16 raeburn 5918: }
5919: }
5920: if ($numextras) {
5921: unless ($pickstart) {
5922: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5923: $pickstart = 1;
5924: }
5925: if ($showemail) {
5926: my $closure = '';
5927: unless ($showstatus) {
5928: $closure = 1;
1.391 raeburn 5929: }
1.406.2.16 raeburn 5930: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5931: $showemail.
5932: &Apache::lonhtmlcommon::row_closure($closure));
5933: }
5934: if ($showstatus) {
5935: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5936: $showstatus.
5937: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 5938: }
5939: }
1.406.2.16 raeburn 5940: if ($pickstart) {
5941: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5942: } else {
5943: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
5944: }
5945: } else {
5946: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5947: }
5948: }
5949: }
5950: }
5951: }
1.406.2.16 raeburn 5952: $r->print(&close_popup_form());
1.207 raeburn 5953: } elsif (($env{'form.action'} eq 'listusers') &&
5954: ($permission->{'view'} || $permission->{'cusr'})) {
1.406.2.14 raeburn 5955: my $helpitem = 'Course_View_Class_List';
5956: if ($context eq 'author') {
5957: $helpitem = 'Author_View_Coauthor_List';
5958: } elsif ($context eq 'domain') {
5959: $helpitem = 'Domain_View_Users_List';
5960: }
1.202 raeburn 5961: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5962: push(@{$brcrum},
5963: {href => '/adm/createuser?action=listusers',
5964: text => "List Users"},
5965: {href => "/adm/createuser",
5966: text => "Result",
1.406.2.14 raeburn 5967: help => $helpitem});
1.351 raeburn 5968: $bread_crumbs_component = 'Update Users';
5969: $args = {bread_crumbs => $brcrum,
5970: bread_crumbs_component => $bread_crumbs_component};
5971: $r->print(&header(undef,$args));
1.202 raeburn 5972: my $setting = $env{'form.roletype'};
5973: my $choice = $env{'form.bulkaction'};
5974: if ($permission->{'cusr'}) {
1.336 raeburn 5975: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5976: } else {
5977: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5978: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5979: }
5980: } else {
1.351 raeburn 5981: push(@{$brcrum},
5982: {href => '/adm/createuser?action=listusers',
5983: text => "List Users",
1.406.2.14 raeburn 5984: help => $helpitem});
1.351 raeburn 5985: $bread_crumbs_component = 'List Users';
5986: $args = {bread_crumbs => $brcrum,
5987: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5988: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5989: my $formname = 'studentform';
1.364 raeburn 5990: my $hidecall = "hide_searching();";
1.321 raeburn 5991: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5992: ($env{'form.roletype'} eq 'community'))) {
5993: if ($env{'form.roletype'} eq 'course') {
5994: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5995: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5996: $formname);
5997: } elsif ($env{'form.roletype'} eq 'community') {
5998: $cb_jscript =
5999: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
6000: my %elements = (
6001: coursepick => 'radio',
6002: coursetotal => 'text',
6003: courselist => 'text',
6004: );
6005: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
6006: }
1.364 raeburn 6007: $jscript .= &verify_user_display($context)."\n".
6008: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 6009: my $js = &add_script($jscript).$cb_jscript;
6010: my $loadcode =
6011: &Apache::lonuserutils::course_selector_loadcode($formname);
6012: if ($loadcode ne '') {
1.364 raeburn 6013: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
6014: } else {
6015: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 6016: }
1.351 raeburn 6017: $r->print(&header($js,$args));
1.191 raeburn 6018: } else {
1.364 raeburn 6019: $args->{add_entries} = {onload => $hidecall};
6020: $jscript = &verify_user_display($context).
6021: &Apache::loncommon::check_uncheck_jscript();
6022: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 6023: }
1.202 raeburn 6024: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 6025: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
6026: $showcredits);
1.191 raeburn 6027: }
1.213 raeburn 6028: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 6029: my $brtext;
6030: if ($crstype eq 'Community') {
6031: $brtext = 'Drop Members';
6032: } else {
6033: $brtext = 'Drop Students';
6034: }
1.351 raeburn 6035: push(@{$brcrum},
6036: {href => '/adm/createuser?action=drop',
6037: text => $brtext,
6038: help => 'Course_Drop_Student'});
6039: if ($env{'form.state'} eq 'done') {
6040: push(@{$brcrum},
6041: {href=>'/adm/createuser?action=drop',
6042: text=>"Result"});
6043: }
6044: $bread_crumbs_component = $brtext;
6045: $args = {bread_crumbs => $brcrum,
6046: bread_crumbs_component => $bread_crumbs_component};
6047: $r->print(&header(undef,$args));
1.213 raeburn 6048: if (!exists($env{'form.state'})) {
1.318 raeburn 6049: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 6050: } elsif ($env{'form.state'} eq 'done') {
6051: &Apache::lonuserutils::update_user_list($r,$context,undef,
6052: $env{'form.action'});
6053: }
1.202 raeburn 6054: } elsif ($env{'form.action'} eq 'dateselect') {
6055: if ($permission->{'cusr'}) {
1.351 raeburn 6056: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 6057: &Apache::lonuserutils::date_section_selector($context,$permission,
6058: $crstype,$showcredits));
1.202 raeburn 6059: } else {
1.351 raeburn 6060: $r->print(&header(undef,{'no_nav_bar' => 1}).
6061: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 6062: }
1.237 raeburn 6063: } elsif ($env{'form.action'} eq 'selfenroll') {
1.406.2.20.2. (raeburn 6064:): my %currsettings;
6065:): if ($permission->{selfenrolladmin} || $permission->{selfenrollview}) {
6066:): %currsettings = (
1.398 raeburn 6067: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
6068: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
6069: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
6070: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
6071: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
6072: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
6073: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
6074: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
6075: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
6076: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
6077: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
6078: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
6079: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 6080: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 6081: );
1.406.2.20.2. (raeburn 6082:): }
6083:): if ($permission->{selfenrolladmin}) {
1.398 raeburn 6084: push(@{$brcrum},
6085: {href => '/adm/createuser?action=selfenroll',
6086: text => "Configure Self-enrollment",
6087: help => 'Course_Self_Enrollment'});
6088: if (!exists($env{'form.state'})) {
6089: $args = { bread_crumbs => $brcrum,
6090: bread_crumbs_component => 'Configure Self-enrollment'};
6091: $r->print(&header(undef,$args));
6092: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
6093: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
6094: } elsif ($env{'form.state'} eq 'done') {
6095: push (@{$brcrum},
6096: {href=>'/adm/createuser?action=selfenroll',
6097: text=>"Result"});
6098: $args = { bread_crumbs => $brcrum,
6099: bread_crumbs_component => 'Self-enrollment result'};
6100: $r->print(&header(undef,$args));
6101: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 6102: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 6103: }
1.406.2.20.2. (raeburn 6104:): } elsif ($permission->{selfenrollview}) {
6105:): push(@{$brcrum},
6106:): {href => '/adm/createuser?action=selfenroll',
6107:): text => "View Self-enrollment configuration",
6108:): help => 'Course_Self_Enrollment'});
6109:): $args = { bread_crumbs => $brcrum,
6110:): bread_crumbs_component => 'Self-enrollment Settings'};
6111:): $r->print(&header(undef,$args));
6112:): $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
6113:): &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings,'',1);
1.398 raeburn 6114: } else {
6115: $r->print(&header(undef,{'no_nav_bar' => 1}).
6116: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 6117: }
1.277 raeburn 6118: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.406.2.6 raeburn 6119: if ($permission->{selfenrolladmin}) {
1.351 raeburn 6120: push(@{$brcrum},
6121: {href => '/adm/createuser?action=selfenrollqueue',
1.406.2.6 raeburn 6122: text => 'Enrollment requests',
1.406.2.14 raeburn 6123: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 6124: $bread_crumbs_component = 'Enrollment requests';
6125: if ($env{'form.state'} eq 'done') {
6126: push(@{$brcrum},
6127: {href => '/adm/createuser?action=selfenrollqueue',
6128: text => 'Result',
1.406.2.14 raeburn 6129: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 6130: $bread_crumbs_component = 'Enrollment result';
6131: }
6132: $args = { bread_crumbs => $brcrum,
6133: bread_crumbs_component => $bread_crumbs_component};
6134: $r->print(&header(undef,$args));
6135: my $coursedesc = $env{'course.'.$cid.'.description'};
6136: if (!exists($env{'form.state'})) {
6137: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
6138: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
6139: $cdom,$cnum));
6140: } elsif ($env{'form.state'} eq 'done') {
6141: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
6142: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
6143: $cdom,$cnum,$coursedesc));
6144: }
6145: } else {
6146: $r->print(&header(undef,{'no_nav_bar' => 1}).
6147: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.277 raeburn 6148: }
1.239 raeburn 6149: } elsif ($env{'form.action'} eq 'changelogs') {
1.406.2.6 raeburn 6150: if ($permission->{cusr} || $permission->{view}) {
6151: &print_userchangelogs_display($r,$context,$permission,$brcrum);
6152: } else {
6153: $r->print(&header(undef,{'no_nav_bar' => 1}).
6154: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
6155: }
1.406.2.10 raeburn 6156: } elsif ($env{'form.action'} eq 'helpdesk') {
1.406.2.20.2. (raeburn 6157:): if (($permission->{'owner'} || $permission->{'co-owner'}) &&
6158:): ($permission->{'cusr'} || $permission->{'view'})) {
1.406.2.10 raeburn 6159: if ($env{'form.state'} eq 'process') {
6160: if ($permission->{'owner'}) {
6161: &update_helpdeskaccess($r,$permission,$brcrum);
6162: } else {
6163: &print_helpdeskaccess_display($r,$permission,$brcrum);
6164: }
6165: } else {
6166: &print_helpdeskaccess_display($r,$permission,$brcrum);
6167: }
6168: } else {
6169: $r->print(&header(undef,{'no_nav_bar' => 1}).
6170: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
6171: }
1.406.2.20.2. (raeburn 6172:): } elsif ($env{'form.action'} eq 'camanagers') {
6173:): if (($permission->{cusr}) && ($context eq 'author')) {
6174:): push(@{$brcrum},
6175:): {href => '/adm/createuser?action=camanagers',
6176:): text => 'Co-author Managers',
6177:): help => 'Author_Manage_Coauthors'});
6178:): if ($env{'form.state'} eq 'process') {
6179:): push(@{$brcrum},
6180:): {href => '/adm/createuser?action=camanagers',
6181:): text => 'Result',
6182:): help => 'Author_Manage_Coauthors'});
6183:): }
6184:): $args = { bread_crumbs => $brcrum };
6185:): $r->print(&header(undef,$args));
6186:): my $coursedesc = $env{'course.'.$cid.'.description'};
6187:): if (!exists($env{'form.state'})) {
6188:): $r->print('<h3>'.&mt('Co-author Management').'</h3>'."\n".
6189:): &display_coauthor_managers($permission));
6190:): } elsif ($env{'form.state'} eq 'process') {
6191:): $r->print('<h3>'.&mt('Co-author Management Update Result').'</h3>'."\n".
6192:): &update_coauthor_managers($permission));
6193:): }
6194:): }
6195:): } elsif (($env{'form.action'} eq 'calist') && ($context eq 'author')) {
6196:): if ($permission->{'cusr'}) {
6197:): my ($role,$audom,$auname,$canview,$canedit) =
6198:): &Apache::lonviewcoauthors::get_allowable();
6199:): if (($canedit) && ($env{'form.forceedit'})) {
6200:): &Apache::lonviewcoauthors::get_editor_crumbs($brcrum,'/adm/createuser');
6201:): my $args = { 'bread_crumbs' => $brcrum };
6202:): $r->print(&Apache::loncommon::start_page('Configure co-author listing',undef,
6203:): $args).
6204:): &Apache::lonviewcoauthors::edit_settings($audom,$auname,$role,
6205:): '/adm/createuser'));
6206:): } else {
6207:): push(@{$brcrum},
6208:): {href => '/adm/createuser?action=calist',
6209:): text => 'Coauthor-viewable list',
6210:): help => 'Author_List_Coauthors'});
6211:): my $args = { 'bread_crumbs' => $brcrum };
6212:): $r->print(&Apache::loncommon::start_page('Coauthor-viewable list',undef,
6213:): $args));
6214:): my %viewsettings =
6215:): &Apache::lonviewcoauthors::retrieve_view_settings($auname,$audom,$role);
6216:): if ($viewsettings{'show'} eq 'none') {
6217:): $r->print('<h3>'.&mt('Coauthor-viewable listing').'</h3>'.
6218:): '<p class="LC_info">'.
6219:): &mt('Listing of co-authors not enabled for this Authoring Space').
6220:): '</p>');
6221:): } else {
6222:): &Apache::lonviewcoauthors::print_coauthors($r,$auname,$audom,$role,
6223:): '/adm/createuser',\%viewsettings);
6224:): }
6225:): }
6226:): } else {
6227:): $r->internal_redirect('/adm/viewcoauthors');
6228:): return OK;
6229:): }
6230:): } elsif (($env{'form.action'} eq 'setenv') && ($context eq 'author')) {
6231:): my ($role,$audom,$auname,$canview,$canedit) =
6232:): &Apache::lonviewcoauthors::get_allowable();
6233:): push(@{$brcrum},
6234:): {href => '/adm/createuser?action=calist',
6235:): text => 'Coauthor-viewable list',
6236:): help => 'Author_List_Coauthors'});
6237:): my $args = { 'bread_crumbs' => $brcrum };
6238:): $r->print(&Apache::loncommon::start_page('Coauthor-viewable list',undef,
6239:): $args));
6240:): my %viewsettings =
6241:): &Apache::lonviewcoauthors::retrieve_view_settings($auname,$audom,$role);
6242:): if ($viewsettings{'show'} eq 'none') {
6243:): $r->print('<h3>'.&mt('Coauthor-viewable listing').'</h3>'.
6244:): '<p class="LC_info">'.
6245:): &mt('Listing of co-authors not enabled for this Authoring Space').
6246:): '</p>');
6247:): } else {
6248:): &Apache::lonviewcoauthors::print_coauthors($r,$auname,$audom,$role,
6249:): '/adm/createuser',\%viewsettings);
6250:): }
1.190 raeburn 6251: } else {
1.351 raeburn 6252: $bread_crumbs_component = 'User Management';
6253: $args = { bread_crumbs => $brcrum,
6254: bread_crumbs_component => $bread_crumbs_component};
6255: $r->print(&header(undef,$args));
1.318 raeburn 6256: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 6257: }
1.351 raeburn 6258: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 6259: return OK;
6260: }
6261:
6262: sub header {
1.351 raeburn 6263: my ($jscript,$args) = @_;
1.190 raeburn 6264: my $start_page;
1.351 raeburn 6265: if (ref($args) eq 'HASH') {
6266: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 6267: } else {
1.351 raeburn 6268: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 6269: }
6270: return $start_page;
6271: }
1.2 www 6272:
1.191 raeburn 6273: sub add_script {
6274: my ($js) = @_;
1.301 bisitz 6275: return '<script type="text/javascript">'."\n"
6276: .'// <![CDATA['."\n"
6277: .$js."\n"
6278: .'// ]]>'."\n"
6279: .'</script>'."\n";
1.191 raeburn 6280: }
6281:
1.391 raeburn 6282: sub usernamerequest_javascript {
6283: my $js = <<ENDJS;
6284:
6285: function openusernamereqdisplay(dom,uname,queue) {
6286: var url = '/adm/createuser?action=displayuserreq';
6287: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
6288: var title = 'Account_Request_Browser';
6289: var options = 'scrollbars=1,resizable=1,menubar=0';
6290: options += ',width=700,height=600';
6291: var stdeditbrowser = open(url,title,options,'1');
6292: stdeditbrowser.focus();
6293: return;
6294: }
6295:
6296: ENDJS
6297: }
6298:
6299: sub close_popup_form {
6300: my $close= &mt('Close Window');
6301: return << "END";
6302: <p><form name="displayreq" action="" method="post">
6303: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
6304: </form></p>
6305: END
6306: }
6307:
1.202 raeburn 6308: sub verify_user_display {
1.364 raeburn 6309: my ($context) = @_;
1.374 raeburn 6310: my %lt = &Apache::lonlocal::texthash (
6311: course => 'course(s): description, section(s), status',
6312: community => 'community(s): description, section(s), status',
6313: author => 'author',
6314: );
1.364 raeburn 6315: my $photos;
6316: if (($context eq 'course') && $env{'request.course.id'}) {
6317: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
6318: }
1.202 raeburn 6319: my $output = <<"END";
6320:
1.364 raeburn 6321: function hide_searching() {
6322: if (document.getElementById('searching')) {
6323: document.getElementById('searching').style.display = 'none';
6324: }
6325: return;
6326: }
6327:
1.202 raeburn 6328: function display_update() {
6329: document.studentform.action.value = 'listusers';
6330: document.studentform.phase.value = 'display';
6331: document.studentform.submit();
6332: }
6333:
1.364 raeburn 6334: function updateCols(caller) {
6335: var context = '$context';
6336: var photos = '$photos';
6337: if (caller == 'Status') {
1.374 raeburn 6338: if ((context == 'domain') &&
6339: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
6340: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 6341: document.getElementById('showcolstatus').checked = false;
6342: document.getElementById('showcolstatus').disabled = 'disabled';
6343: document.getElementById('showcolstart').checked = false;
6344: document.getElementById('showcolend').checked = false;
1.374 raeburn 6345: } else {
6346: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
6347: document.getElementById('showcolstatus').checked = true;
6348: document.getElementById('showcolstatus').disabled = '';
6349: document.getElementById('showcolstart').checked = true;
6350: document.getElementById('showcolend').checked = true;
6351: } else {
6352: document.getElementById('showcolstatus').checked = false;
6353: document.getElementById('showcolstatus').disabled = 'disabled';
6354: document.getElementById('showcolstart').checked = false;
6355: document.getElementById('showcolend').checked = false;
6356: }
1.406.2.20.2. (raeburn 6357:): if (context == 'author') {
6358:): if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Expired') {
6359:): document.getElementById('showcolmanager').checked = false;
6360:): document.getElementById('showcolmanager').disabled = 'disabled';
6361:): } else if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value != 'aa') {
6362:): document.getElementById('showcolmanager').checked = true;
6363:): document.getElementById('showcolmanager').disabled = '';
6364:): }
6365:): }
1.364 raeburn 6366: }
6367: }
6368: if (caller == 'output') {
6369: if (photos == 1) {
6370: if (document.getElementById('showcolphoto')) {
6371: var photoitem = document.getElementById('showcolphoto');
6372: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
6373: photoitem.checked = true;
6374: photoitem.disabled = '';
6375: } else {
6376: photoitem.checked = false;
6377: photoitem.disabled = 'disabled';
6378: }
6379: }
6380: }
6381: }
6382: if (caller == 'showrole') {
1.371 raeburn 6383: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
6384: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 6385: document.getElementById('showcolrole').checked = true;
6386: document.getElementById('showcolrole').disabled = '';
6387: } else {
6388: document.getElementById('showcolrole').checked = false;
6389: document.getElementById('showcolrole').disabled = 'disabled';
6390: }
1.374 raeburn 6391: if (context == 'domain') {
1.382 raeburn 6392: var quotausageshow = 0;
1.374 raeburn 6393: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
6394: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
6395: document.getElementById('showcolstatus').checked = false;
6396: document.getElementById('showcolstatus').disabled = 'disabled';
6397: document.getElementById('showcolstart').checked = false;
6398: document.getElementById('showcolend').checked = false;
6399: } else {
6400: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
6401: document.getElementById('showcolstatus').checked = true;
6402: document.getElementById('showcolstatus').disabled = '';
6403: document.getElementById('showcolstart').checked = true;
6404: document.getElementById('showcolend').checked = true;
6405: }
6406: }
6407: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
6408: document.getElementById('showcolextent').disabled = 'disabled';
6409: document.getElementById('showcolextent').checked = 'false';
6410: document.getElementById('showextent').style.display='none';
6411: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 6412: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
6413: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
6414: if (document.getElementById('showcolauthorusage')) {
6415: document.getElementById('showcolauthorusage').disabled = '';
6416: }
6417: if (document.getElementById('showcolauthorquota')) {
6418: document.getElementById('showcolauthorquota').disabled = '';
6419: }
6420: quotausageshow = 1;
6421: }
1.374 raeburn 6422: } else {
6423: document.getElementById('showextent').style.display='block';
6424: document.getElementById('showextent').style.textAlign='left';
6425: document.getElementById('showextent').style.textFace='normal';
6426: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
6427: document.getElementById('showcolextent').disabled = '';
6428: document.getElementById('showcolextent').checked = 'true';
6429: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
6430: } else {
6431: document.getElementById('showcolextent').disabled = '';
6432: document.getElementById('showcolextent').checked = 'true';
6433: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
6434: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
6435: } else {
6436: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
6437: }
6438: }
6439: }
1.382 raeburn 6440: if (quotausageshow == 0) {
6441: if (document.getElementById('showcolauthorusage')) {
6442: document.getElementById('showcolauthorusage').checked = false;
6443: document.getElementById('showcolauthorusage').disabled = 'disabled';
6444: }
6445: if (document.getElementById('showcolauthorquota')) {
6446: document.getElementById('showcolauthorquota').checked = false;
6447: document.getElementById('showcolauthorquota').disabled = 'disabled';
6448: }
6449: }
1.374 raeburn 6450: }
1.406.2.20.2. (raeburn 6451:): if (context == 'author') {
6452:): if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'aa') {
6453:): document.getElementById('showcolmanager').checked = false;
6454:): document.getElementById('showcolmanager').disabled = 'disabled';
6455:): } else if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value != 'Expired') {
6456:): document.getElementById('showcolmanager').checked = true;
6457:): document.getElementById('showcolmanager').disabled = '';
6458:): }
6459:): }
1.364 raeburn 6460: }
6461: return;
6462: }
6463:
1.202 raeburn 6464: END
6465: return $output;
6466:
6467: }
6468:
1.190 raeburn 6469: ###############################################################
6470: ###############################################################
6471: # Menu Phase One
6472: sub print_main_menu {
1.318 raeburn 6473: my ($permission,$context,$crstype) = @_;
6474: my $linkcontext = $context;
6475: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
6476: if (($context eq 'course') && ($crstype eq 'Community')) {
6477: $linkcontext = lc($crstype);
6478: $stuterm = 'Members';
6479: }
1.208 raeburn 6480: my %links = (
1.298 droeschl 6481: domain => {
6482: upload => 'Upload a File of Users',
6483: singleuser => 'Add/Modify a User',
6484: listusers => 'Manage Users',
6485: },
6486: author => {
6487: upload => 'Upload a File of Co-authors',
6488: singleuser => 'Add/Modify a Co-author',
6489: listusers => 'Manage Co-authors',
6490: },
6491: course => {
6492: upload => 'Upload a File of Course Users',
6493: singleuser => 'Add/Modify a Course User',
1.354 www 6494: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 6495: },
1.318 raeburn 6496: community => {
6497: upload => 'Upload a File of Community Users',
6498: singleuser => 'Add/Modify a Community User',
1.354 www 6499: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 6500: },
6501: );
6502: my %linktitles = (
6503: domain => {
6504: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
6505: listusers => 'Show and manage users in this domain.',
6506: },
6507: author => {
6508: singleuser => 'Add a user with a co- or assistant author role.',
6509: listusers => 'Show and manage co- or assistant authors.',
6510: },
6511: course => {
6512: singleuser => 'Add a user with a certain role to this course.',
6513: listusers => 'Show and manage users in this course.',
6514: },
6515: community => {
6516: singleuser => 'Add a user with a certain role to this community.',
6517: listusers => 'Show and manage users in this community.',
6518: },
1.298 droeschl 6519: );
1.406.2.6 raeburn 6520: if ($linkcontext eq 'domain') {
6521: unless ($permission->{'cusr'}) {
6522: $links{'domain'}{'singleuser'} = 'View a User';
6523: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
6524: }
6525: } elsif ($linkcontext eq 'course') {
6526: unless ($permission->{'cusr'}) {
6527: $links{'course'}{'singleuser'} = 'View a Course User';
6528: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
6529: $links{'course'}{'listusers'} = 'List Course Users';
6530: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
6531: }
6532: } elsif ($linkcontext eq 'community') {
6533: unless ($permission->{'cusr'}) {
6534: $links{'community'}{'singleuser'} = 'View a Community User';
6535: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
6536: $links{'community'}{'listusers'} = 'List Community Users';
6537: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
6538: }
6539: }
1.298 droeschl 6540: my @menu = ( {categorytitle => 'Single Users',
6541: items =>
6542: [
6543: {
1.318 raeburn 6544: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 6545: icon => 'edit-redo.png',
6546: #help => 'Course_Change_Privileges',
6547: url => '/adm/createuser?action=singleuser',
1.406.2.6 raeburn 6548: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 6549: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 6550: },
6551: ]},
6552:
6553: {categorytitle => 'Multiple Users',
6554: items =>
6555: [
6556: {
1.318 raeburn 6557: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 6558: icon => 'uplusr.png',
1.298 droeschl 6559: #help => 'Course_Create_Class_List',
6560: url => '/adm/createuser?action=upload',
6561: permission => $permission->{'cusr'},
6562: linktitle => 'Upload a CSV or a text file containing users.',
6563: },
6564: {
1.318 raeburn 6565: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 6566: icon => 'mngcu.png',
1.298 droeschl 6567: #help => 'Course_View_Class_List',
6568: url => '/adm/createuser?action=listusers',
6569: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 6570: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 6571: },
6572:
6573: ]},
6574:
6575: {categorytitle => 'Administration',
6576: items => [ ]},
6577: );
1.406.2.5 raeburn 6578:
1.265 mielkec 6579: if ($context eq 'domain'){
1.406.2.5 raeburn 6580: push(@{ $menu[0]->{items} }, # Single Users
6581: {
6582: linktext => 'User Access Log',
6583: icon => 'document-properties.png',
1.406.2.8 raeburn 6584: #help => 'Domain_User_Access_Logs',
1.406.2.5 raeburn 6585: url => '/adm/createuser?action=accesslogs',
6586: permission => $permission->{'activity'},
6587: linktitle => 'View user access log.',
6588: }
6589: );
1.298 droeschl 6590:
6591: push(@{ $menu[2]->{items} }, #Category: Administration
6592: {
6593: linktext => 'Custom Roles',
6594: icon => 'emblem-photos.png',
6595: #help => 'Course_Editing_Custom_Roles',
6596: url => '/adm/createuser?action=custom',
6597: permission => $permission->{'custom'},
6598: linktitle => 'Configure a custom role.',
6599: },
1.362 raeburn 6600: {
6601: linktext => 'Authoring Space Requests',
6602: icon => 'selfenrl-queue.png',
6603: #help => 'Domain_Role_Approvals',
6604: url => '/adm/createuser?action=processauthorreq',
6605: permission => $permission->{'cusr'},
6606: linktitle => 'Approve or reject author role requests',
6607: },
1.363 raeburn 6608: {
1.391 raeburn 6609: linktext => 'LON-CAPA Account Requests',
6610: icon => 'list-add.png',
6611: #help => 'Domain_Username_Approvals',
6612: url => '/adm/createuser?action=processusernamereq',
6613: permission => $permission->{'cusr'},
6614: linktitle => 'Approve or reject LON-CAPA account requests',
6615: },
6616: {
1.363 raeburn 6617: linktext => 'Change Log',
6618: icon => 'document-properties.png',
6619: #help => 'Course_User_Logs',
6620: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 6621: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 6622: linktitle => 'View change log.',
6623: },
1.298 droeschl 6624: );
6625:
1.265 mielkec 6626: }elsif ($context eq 'course'){
1.298 droeschl 6627: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 6628:
6629: my %linktext = (
6630: 'Course' => {
6631: single => 'Add/Modify a Student',
6632: drop => 'Drop Students',
6633: groups => 'Course Groups',
6634: },
6635: 'Community' => {
6636: single => 'Add/Modify a Member',
6637: drop => 'Drop Members',
6638: groups => 'Community Groups',
6639: },
6640: );
6641:
6642: my %linktitle = (
6643: 'Course' => {
6644: single => 'Add a user with the role of student to this course',
6645: drop => 'Remove a student from this course.',
6646: groups => 'Manage course groups',
6647: },
6648: 'Community' => {
6649: single => 'Add a user with the role of member to this community',
6650: drop => 'Remove a member from this community.',
6651: groups => 'Manage community groups',
6652: },
6653: );
6654:
1.298 droeschl 6655: push(@{ $menu[0]->{items} }, #Category: Single Users
6656: {
1.318 raeburn 6657: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 6658: #help => 'Course_Add_Student',
6659: icon => 'list-add.png',
6660: url => '/adm/createuser?action=singlestudent',
6661: permission => $permission->{'cusr'},
1.318 raeburn 6662: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 6663: },
6664: );
6665:
6666: push(@{ $menu[1]->{items} }, #Category: Multiple Users
6667: {
1.318 raeburn 6668: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 6669: icon => 'edit-undo.png',
6670: #help => 'Course_Drop_Student',
6671: url => '/adm/createuser?action=drop',
6672: permission => $permission->{'cusr'},
1.318 raeburn 6673: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 6674: },
6675: );
6676: push(@{ $menu[2]->{items} }, #Category: Administration
1.406.2.11 raeburn 6677: {
6678: linktext => 'Helpdesk Access',
6679: icon => 'helpdesk-access.png',
6680: #help => 'Course_Helpdesk_Access',
6681: url => '/adm/createuser?action=helpdesk',
1.406.2.20.2. (raeburn 6682:): permission => (($permission->{'owner'} || $permission->{'co-owner'}) &&
6683:): ($permission->{'view'} || $permission->{'cusr'})),
1.406.2.11 raeburn 6684: linktitle => 'Helpdesk access options',
6685: },
6686: {
1.298 droeschl 6687: linktext => 'Custom Roles',
6688: icon => 'emblem-photos.png',
6689: #help => 'Course_Editing_Custom_Roles',
6690: url => '/adm/createuser?action=custom',
6691: permission => $permission->{'custom'},
6692: linktitle => 'Configure a custom role.',
6693: },
6694: {
1.318 raeburn 6695: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 6696: icon => 'grps.png',
1.298 droeschl 6697: #help => 'Course_Manage_Group',
6698: url => '/adm/coursegroups?refpage=cusr',
6699: permission => $permission->{'grp_manage'},
1.318 raeburn 6700: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 6701: },
6702: {
1.328 wenzelju 6703: linktext => 'Change Log',
1.298 droeschl 6704: icon => 'document-properties.png',
6705: #help => 'Course_User_Logs',
6706: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 6707: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 6708: linktitle => 'View change log.',
6709: },
6710: );
1.277 raeburn 6711: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 6712: push(@{ $menu[2]->{items} },
1.398 raeburn 6713: {
1.298 droeschl 6714: linktext => 'Enrollment Requests',
6715: icon => 'selfenrl-queue.png',
6716: #help => 'Course_Approve_Selfenroll',
6717: url => '/adm/createuser?action=selfenrollqueue',
1.406.2.20.2. (raeburn 6718:): permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.298 droeschl 6719: linktitle =>'Approve or reject enrollment requests.',
6720: },
6721: );
1.277 raeburn 6722: }
1.298 droeschl 6723:
1.265 mielkec 6724: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 6725: if ($crstype ne 'Community') {
6726: push(@{ $menu[2]->{items} },
6727: {
6728: linktext => 'Automated Enrollment',
6729: icon => 'roles.png',
6730: #help => 'Course_Automated_Enrollment',
6731: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.406.2.6 raeburn 6732: && (($permission->{'cusr'}) ||
6733: ($permission->{'view'}))),
1.320 raeburn 6734: url => '/adm/populate',
6735: linktitle => 'Automated enrollment manager.',
6736: }
6737: );
6738: }
6739: push(@{ $menu[2]->{items} },
1.298 droeschl 6740: {
6741: linktext => 'User Self-Enrollment',
1.342 wenzelju 6742: icon => 'self_enroll.png',
1.298 droeschl 6743: #help => 'Course_Self_Enrollment',
6744: url => '/adm/createuser?action=selfenroll',
1.406.2.20.2. (raeburn 6745:): permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.317 bisitz 6746: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 6747: },
6748: );
6749: }
1.363 raeburn 6750: } elsif ($context eq 'author') {
1.406.2.20.2. (raeburn 6751:): my $coauthorlist;
6752:): if ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)$}) {
6753:): if ($env{'environment.internal.coauthorlist./'.$1.'/'.$2}) {
6754:): $coauthorlist = 1;
6755:): }
6756:): } elsif ($env{'request.role'} eq "au./$env{'user.domain'}/") {
6757:): if ($env{'environment.coauthorlist'}) {
6758:): $coauthorlist = 1;
6759:): }
6760:): }
6761:): if ($coauthorlist) {
6762:): push(@{ $menu[1]->{items} },
6763:): {
6764:): linktext => 'Co-author-viewable list',
6765:): icon => 'clst.png',
6766:): #help => 'Coauthor_Listing',
6767:): url => '/adm/createuser?action=calist&forceedit=0',
6768:): permission => $permission->{'cusr'},
6769:): linktitle => 'Co-author-viewable listing',
6770:): });
6771:): }
1.370 raeburn 6772: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 6773: {
6774: linktext => 'Change Log',
6775: icon => 'document-properties.png',
6776: #help => 'Course_User_Logs',
6777: url => '/adm/createuser?action=changelogs',
6778: permission => $permission->{'cusr'},
6779: linktitle => 'View change log.',
6780: },
1.406.2.20.2. (raeburn 6781:): {
6782:): linktext => 'Co-author Managers',
6783:): icon => 'camanager.png',
6784:): #help => 'Coauthor_Management',
6785:): url => '/adm/createuser?action=camanagers',
6786:): permission => $permission->{'author'},
6787:): linktitle => 'Assign/Revoke right to manage co-author roles',
6788:): },
6789:): {
6790:): linktext => 'Configure Co-author Listing',
6791:): icon => 'coauthors.png',
6792:): #help => 'Coauthor_Settings',
6793:): url => '/adm/createuser?action=calist&forceedit=1',
6794:): permission => ($permission->{'cusr'}),
6795:): linktitle => 'Set availability of coauthor-viewable user listing',
6796:): },
1.370 raeburn 6797: );
1.363 raeburn 6798: }
6799: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 6800: # { text => 'View Log-in History',
6801: # help => 'Course_User_Logins',
6802: # action => 'logins',
6803: # permission => $permission->{'cusr'},
6804: # });
1.190 raeburn 6805: }
6806:
1.189 albertel 6807: sub restore_prev_selections {
6808: my %saveable_parameters = ('srchby' => 'scalar',
6809: 'srchin' => 'scalar',
6810: 'srchtype' => 'scalar',
6811: );
6812: &Apache::loncommon::store_settings('user','user_picker',
6813: \%saveable_parameters);
6814: &Apache::loncommon::restore_settings('user','user_picker',
6815: \%saveable_parameters);
6816: }
6817:
1.237 raeburn 6818: sub print_selfenroll_menu {
1.406.2.6 raeburn 6819: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 6820: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 6821: my $formname = 'selfenroll';
1.237 raeburn 6822: my $nolink = 1;
1.398 raeburn 6823: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 6824: my $groupslist = &Apache::lonuserutils::get_groupslist();
6825: my $setsec_js =
6826: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 6827: my %alerts = &Apache::lonlocal::texthash(
6828: acto => 'Activation of self-enrollment was selected for the following domain(s)',
6829: butn => 'but no user types have been checked.',
6830: wilf => "Please uncheck 'activate' or check at least one type.",
6831: );
1.406.2.6 raeburn 6832: my $disabled;
6833: if ($readonly) {
6834: $disabled = ' disabled="disabled"';
6835: }
1.405 damieng 6836: &js_escape(\%alerts);
1.249 raeburn 6837: my $selfenroll_js = <<"ENDSCRIPT";
6838: function update_types(caller,num) {
6839: var delidx = getIndexByName('selfenroll_delete');
6840: var actidx = getIndexByName('selfenroll_activate');
6841: if (caller == 'selfenroll_all') {
6842: var selall;
6843: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
6844: if (document.$formname.selfenroll_all[i].checked) {
6845: selall = document.$formname.selfenroll_all[i].value;
6846: }
6847: }
6848: if (selall == 1) {
6849: if (delidx != -1) {
6850: if (document.$formname.selfenroll_delete.length) {
6851: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
6852: document.$formname.selfenroll_delete[j].checked = true;
6853: }
6854: } else {
6855: document.$formname.elements[delidx].checked = true;
6856: }
6857: }
6858: if (actidx != -1) {
6859: if (document.$formname.selfenroll_activate.length) {
6860: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
6861: document.$formname.selfenroll_activate[j].checked = false;
6862: }
6863: } else {
6864: document.$formname.elements[actidx].checked = false;
6865: }
6866: }
6867: document.$formname.selfenroll_newdom.selectedIndex = 0;
6868: }
6869: }
6870: if (caller == 'selfenroll_activate') {
6871: if (document.$formname.selfenroll_activate.length) {
6872: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
6873: if (document.$formname.selfenroll_activate[j].value == num) {
6874: if (document.$formname.selfenroll_activate[j].checked) {
6875: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
6876: if (document.$formname.selfenroll_all[i].value == '1') {
6877: document.$formname.selfenroll_all[i].checked = false;
6878: }
6879: if (document.$formname.selfenroll_all[i].value == '0') {
6880: document.$formname.selfenroll_all[i].checked = true;
6881: }
6882: }
6883: }
6884: }
6885: }
6886: } else {
6887: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
6888: if (document.$formname.selfenroll_all[i].value == '1') {
6889: document.$formname.selfenroll_all[i].checked = false;
6890: }
6891: if (document.$formname.selfenroll_all[i].value == '0') {
6892: document.$formname.selfenroll_all[i].checked = true;
6893: }
6894: }
6895: }
6896: }
6897: if (caller == 'selfenroll_delete') {
6898: if (document.$formname.selfenroll_delete.length) {
6899: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
6900: if (document.$formname.selfenroll_delete[j].value == num) {
6901: if (document.$formname.selfenroll_delete[j].checked) {
6902: var delindex = getIndexByName('selfenroll_types_'+num);
6903: if (delindex != -1) {
6904: if (document.$formname.elements[delindex].length) {
6905: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
6906: document.$formname.elements[delindex][k].checked = false;
6907: }
6908: } else {
6909: document.$formname.elements[delindex].checked = false;
6910: }
6911: }
6912: }
6913: }
6914: }
6915: } else {
6916: if (document.$formname.selfenroll_delete.checked) {
6917: var delindex = getIndexByName('selfenroll_types_'+num);
6918: if (delindex != -1) {
6919: if (document.$formname.elements[delindex].length) {
6920: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
6921: document.$formname.elements[delindex][k].checked = false;
6922: }
6923: } else {
6924: document.$formname.elements[delindex].checked = false;
6925: }
6926: }
6927: }
6928: }
6929: }
6930: return;
6931: }
6932:
6933: function validate_types(form) {
6934: var needaction = new Array();
6935: var countfail = 0;
6936: var actidx = getIndexByName('selfenroll_activate');
6937: if (actidx != -1) {
6938: if (document.$formname.selfenroll_activate.length) {
6939: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
6940: var num = document.$formname.selfenroll_activate[j].value;
6941: if (document.$formname.selfenroll_activate[j].checked) {
6942: countfail = check_types(num,countfail,needaction)
6943: }
6944: }
6945: } else {
6946: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 6947: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 6948: countfail = check_types(num,countfail,needaction)
6949: }
6950: }
6951: }
6952: if (countfail > 0) {
6953: var msg = "$alerts{'acto'}\\n";
6954: var loopend = needaction.length -1;
6955: if (loopend > 0) {
6956: for (var m=0; m<loopend; m++) {
6957: msg += needaction[m]+", ";
6958: }
6959: }
6960: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
6961: alert(msg);
6962: return;
6963: }
6964: setSections(form);
6965: }
6966:
6967: function check_types(num,countfail,needaction) {
1.406.2.15 raeburn 6968: var boxname = 'selfenroll_types_'+num;
6969: var typeidx = getIndexByName(boxname);
1.249 raeburn 6970: var count = 0;
6971: if (typeidx != -1) {
1.406.2.15 raeburn 6972: if (document.$formname.elements[boxname].length) {
6973: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
6974: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 6975: count ++;
6976: }
6977: }
6978: } else {
6979: if (document.$formname.elements[typeidx].checked) {
6980: count ++;
6981: }
6982: }
6983: if (count == 0) {
6984: var domidx = getIndexByName('selfenroll_dom_'+num);
6985: if (domidx != -1) {
6986: var domname = document.$formname.elements[domidx].value;
6987: needaction[countfail] = domname;
6988: countfail ++;
6989: }
6990: }
6991: }
6992: return countfail;
6993: }
6994:
1.398 raeburn 6995: function toggleNotify() {
6996: var selfenrollApproval = 0;
6997: if (document.$formname.selfenroll_approval.length) {
6998: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
6999: if (document.$formname.selfenroll_approval[i].checked) {
7000: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
7001: break;
7002: }
7003: }
7004: }
7005: if (document.getElementById('notified')) {
7006: if (selfenrollApproval == 0) {
7007: document.getElementById('notified').style.display='none';
7008: } else {
7009: document.getElementById('notified').style.display='block';
7010: }
7011: }
7012: return;
7013: }
7014:
1.249 raeburn 7015: function getIndexByName(item) {
7016: for (var i=0;i<document.$formname.elements.length;i++) {
7017: if (document.$formname.elements[i].name == item) {
7018: return i;
7019: }
7020: }
7021: return -1;
7022: }
7023: ENDSCRIPT
1.256 raeburn 7024:
1.237 raeburn 7025: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 7026: '// <![CDATA['."\n".
1.249 raeburn 7027: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 7028: '// ]]>'."\n".
1.237 raeburn 7029: '</script>'."\n".
1.256 raeburn 7030: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.406.2.20.2. (raeburn 7031:): my $visactions = &cat_visibility($cdom);
1.400 raeburn 7032: my ($cathash,%cattype);
7033: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
7034: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7035: $cathash = $domconfig{'coursecategories'}{'cats'};
7036: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
7037: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 7038: if ($cattype{'auth'} eq '') {
7039: $cattype{'auth'} = 'std';
7040: }
7041: if ($cattype{'unauth'} eq '') {
7042: $cattype{'unauth'} = 'std';
7043: }
1.400 raeburn 7044: } else {
7045: $cathash = {};
7046: $cattype{'auth'} = 'std';
7047: $cattype{'unauth'} = 'std';
7048: }
7049: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
7050: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7051: '<br />'.
7052: '<br />'.$visactions->{'take'}.'<ul>'.
7053: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
7054: '</ul>');
7055: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
7056: if ($currsettings->{'uniquecode'}) {
7057: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
7058: } else {
7059: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7060: '<br />'.
7061: '<br />'.$visactions->{'take'}.'<ul>'.
7062: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
7063: '</ul><br />');
7064: }
7065: } else {
7066: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
7067: if (ref($visactions) eq 'HASH') {
7068: if ($visible) {
7069: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
7070: } else {
7071: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
7072: .$visactions->{'yous'}.
7073: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
7074: if (ref($vismsgs) eq 'ARRAY') {
7075: $output .= '<br />'.$visactions->{'make'}.'<ul>';
7076: foreach my $item (@{$vismsgs}) {
7077: $output .= '<li>'.$visactions->{$item}.'</li>';
7078: }
7079: $output .= '</ul>';
1.256 raeburn 7080: }
1.400 raeburn 7081: $output .= '</p>';
1.256 raeburn 7082: }
7083: }
7084: }
1.398 raeburn 7085: my $actionhref = '/adm/createuser';
7086: if ($context eq 'domain') {
7087: $actionhref = '/adm/modifycourse';
7088: }
1.400 raeburn 7089:
7090: my %noedit;
7091: unless ($context eq 'domain') {
7092: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
7093: }
1.398 raeburn 7094: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 7095: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 7096: if (ref($row) eq 'ARRAY') {
7097: foreach my $item (@{$row}) {
7098: my $title = $item;
7099: if (ref($lt) eq 'HASH') {
7100: $title = $lt->{$item};
7101: }
1.297 bisitz 7102: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 7103: if ($item eq 'types') {
1.398 raeburn 7104: my $curr_types;
7105: if (ref($currsettings) eq 'HASH') {
7106: $curr_types = $currsettings->{'selfenroll_types'};
7107: }
1.400 raeburn 7108: if ($noedit{$item}) {
7109: if ($curr_types eq '*') {
7110: $output .= &mt('Any user in any domain');
7111: } else {
7112: my @entries = split(/;/,$curr_types);
7113: if (@entries > 0) {
7114: $output .= '<ul>';
7115: foreach my $entry (@entries) {
7116: my ($currdom,$typestr) = split(/:/,$entry);
7117: next if ($typestr eq '');
7118: my $domdesc = &Apache::lonnet::domain($currdom);
7119: my @currinsttypes = split(',',$typestr);
7120: my ($othertitle,$usertypes,$types) =
7121: &Apache::loncommon::sorted_inst_types($currdom);
7122: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7123: $usertypes->{'any'} = &mt('any user');
7124: if (keys(%{$usertypes}) > 0) {
7125: $usertypes->{'other'} = &mt('other users');
7126: }
7127: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
7128: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
7129: }
7130: }
7131: $output .= '</ul>';
7132: } else {
7133: $output .= &mt('None');
7134: }
7135: }
7136: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7137: next;
7138: }
1.241 raeburn 7139: my $showdomdesc = 1;
7140: my $includeempty = 1;
7141: my $num = 0;
7142: $output .= &Apache::loncommon::start_data_table().
7143: &Apache::loncommon::start_data_table_row()
7144: .'<td colspan="2"><span class="LC_nobreak"><label>'
7145: .&mt('Any user in any domain:')
7146: .' <input type="radio" name="selfenroll_all" value="1" ';
7147: if ($curr_types eq '*') {
7148: $output .= ' checked="checked" ';
7149: }
1.249 raeburn 7150: $output .= 'onchange="javascript:update_types('.
1.406.2.6 raeburn 7151: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 7152: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 7153: if ($curr_types ne '*') {
7154: $output .= ' checked="checked" ';
7155: }
1.249 raeburn 7156: $output .= ' onchange="javascript:update_types('.
1.406.2.6 raeburn 7157: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 7158: &Apache::loncommon::end_data_table_row().
7159: &Apache::loncommon::end_data_table().
7160: &mt('Or').'<br />'.
7161: &Apache::loncommon::start_data_table();
1.241 raeburn 7162: my %currdoms;
1.249 raeburn 7163: if ($curr_types eq '') {
1.241 raeburn 7164: $output .= &new_selfenroll_dom_row($cdom,'0');
7165: } elsif ($curr_types ne '*') {
7166: my @entries = split(/;/,$curr_types);
7167: if (@entries > 0) {
7168: foreach my $entry (@entries) {
7169: my ($currdom,$typestr) = split(/:/,$entry);
7170: $currdoms{$currdom} = 1;
7171: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 7172: my @currinsttypes = split(',',$typestr);
1.241 raeburn 7173: $output .= &Apache::loncommon::start_data_table_row()
7174: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
7175: .' '.$domdesc.' ('.$currdom.')'
7176: .'</b><input type="hidden" name="selfenroll_dom_'.$num
7177: .'" value="'.$currdom.'" /></span><br />'
7178: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.406.2.6 raeburn 7179: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 7180: .&mt('Delete').'</label></span></td>';
1.249 raeburn 7181: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.406.2.6 raeburn 7182: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 7183: .&Apache::loncommon::end_data_table_row();
7184: $num ++;
7185: }
7186: }
7187: }
1.249 raeburn 7188: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 7189: if ($curr_types eq '*') {
1.249 raeburn 7190: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 7191: } elsif ($curr_types eq '') {
1.249 raeburn 7192: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 7193: }
7194: $output .= &Apache::loncommon::start_data_table_row()
7195: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
7196: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.406.2.6 raeburn 7197: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 7198: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
7199: .'</td>'.&Apache::loncommon::end_data_table_row()
7200: .&Apache::loncommon::end_data_table();
1.237 raeburn 7201: } elsif ($item eq 'registered') {
7202: my ($regon,$regoff);
1.398 raeburn 7203: my $registered;
7204: if (ref($currsettings) eq 'HASH') {
7205: $registered = $currsettings->{'selfenroll_registered'};
7206: }
1.400 raeburn 7207: if ($noedit{$item}) {
7208: if ($registered) {
7209: $output .= &mt('Must be registered in course');
7210: } else {
7211: $output .= &mt('No requirement');
7212: }
7213: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7214: next;
7215: }
1.398 raeburn 7216: if ($registered) {
1.237 raeburn 7217: $regon = ' checked="checked" ';
1.406.2.6 raeburn 7218: $regoff = '';
1.237 raeburn 7219: } else {
1.406.2.6 raeburn 7220: $regon = '';
1.237 raeburn 7221: $regoff = ' checked="checked" ';
7222: }
7223: $output .= '<label>'.
1.406.2.6 raeburn 7224: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 7225: &mt('Yes').'</label> <label>'.
1.406.2.6 raeburn 7226: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 7227: &mt('No').'</label>';
1.237 raeburn 7228: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 7229: my ($starttime,$endtime);
7230: if (ref($currsettings) eq 'HASH') {
7231: $starttime = $currsettings->{'selfenroll_start_date'};
7232: $endtime = $currsettings->{'selfenroll_end_date'};
7233: if ($starttime eq '') {
7234: $starttime = $currsettings->{'default_enrollment_start_date'};
7235: }
7236: if ($endtime eq '') {
7237: $endtime = $currsettings->{'default_enrollment_end_date'};
7238: }
1.237 raeburn 7239: }
1.400 raeburn 7240: if ($noedit{$item}) {
7241: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
7242: &Apache::lonlocal::locallocaltime($endtime));
7243: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7244: next;
7245: }
1.237 raeburn 7246: my $startform =
7247: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.406.2.6 raeburn 7248: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7249: my $endform =
7250: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.406.2.6 raeburn 7251: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7252: $output .= &selfenroll_date_forms($startform,$endform);
7253: } elsif ($item eq 'access_dates') {
1.398 raeburn 7254: my ($starttime,$endtime);
7255: if (ref($currsettings) eq 'HASH') {
7256: $starttime = $currsettings->{'selfenroll_start_access'};
7257: $endtime = $currsettings->{'selfenroll_end_access'};
7258: if ($starttime eq '') {
7259: $starttime = $currsettings->{'default_enrollment_start_date'};
7260: }
7261: if ($endtime eq '') {
7262: $endtime = $currsettings->{'default_enrollment_end_date'};
7263: }
1.237 raeburn 7264: }
1.400 raeburn 7265: if ($noedit{$item}) {
7266: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
7267: &Apache::lonlocal::locallocaltime($endtime));
7268: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7269: next;
7270: }
1.237 raeburn 7271: my $startform =
7272: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.406.2.6 raeburn 7273: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7274: my $endform =
7275: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.406.2.6 raeburn 7276: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7277: $output .= &selfenroll_date_forms($startform,$endform);
7278: } elsif ($item eq 'section') {
1.398 raeburn 7279: my $currsec;
7280: if (ref($currsettings) eq 'HASH') {
7281: $currsec = $currsettings->{'selfenroll_section'};
7282: }
1.237 raeburn 7283: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
7284: my $newsecval;
7285: if ($currsec ne 'none' && $currsec ne '') {
7286: if (!defined($sections_count{$currsec})) {
7287: $newsecval = $currsec;
7288: }
7289: }
1.400 raeburn 7290: if ($noedit{$item}) {
7291: if ($currsec ne '') {
7292: $output .= $currsec;
7293: } else {
7294: $output .= &mt('No specific section');
7295: }
7296: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7297: next;
7298: }
1.237 raeburn 7299: my $sections_select =
1.406.2.6 raeburn 7300: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 7301: $output .= '<table class="LC_createuser">'."\n".
7302: '<tr class="LC_section_row">'."\n".
7303: '<td align="center">'.&mt('Existing sections')."\n".
7304: '<br />'.$sections_select.'</td><td align="center">'.
7305: &mt('New section').'<br />'."\n".
1.406.2.6 raeburn 7306: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 7307: '<input type="hidden" name="sections" value="" />'."\n".
7308: '</td></tr></table>'."\n";
1.276 raeburn 7309: } elsif ($item eq 'approval') {
1.398 raeburn 7310: my ($currnotified,$currapproval,%appchecked);
7311: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.406.2.6 raeburn 7312: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 7313: $currnotified = $currsettings->{'selfenroll_notifylist'};
7314: $currapproval = $currsettings->{'selfenroll_approval'};
7315: }
7316: if ($currapproval !~ /^[012]$/) {
7317: $currapproval = 0;
7318: }
1.400 raeburn 7319: if ($noedit{$item}) {
7320: $output .= $selfdescs{'approval'}{$currapproval}.
7321: '<br />'.&mt('(Set by Domain Coordinator)');
7322: next;
7323: }
1.398 raeburn 7324: $appchecked{$currapproval} = ' checked="checked"';
7325: for my $i (0..2) {
7326: $output .= '<label>'.
7327: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.406.2.6 raeburn 7328: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
7329: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 7330: }
7331: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
7332: my (@ccs,%notified);
1.322 raeburn 7333: my $ccrole = 'cc';
7334: if ($crstype eq 'Community') {
7335: $ccrole = 'co';
7336: }
7337: if ($advhash{$ccrole}) {
7338: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 7339: }
7340: if ($currnotified) {
7341: foreach my $current (split(/,/,$currnotified)) {
7342: $notified{$current} = 1;
7343: if (!grep(/^\Q$current\E$/,@ccs)) {
7344: push(@ccs,$current);
7345: }
7346: }
7347: }
7348: if (@ccs) {
1.398 raeburn 7349: my $style;
7350: unless ($currapproval) {
7351: $style = ' style="display: none;"';
7352: }
7353: $output .= '<br /><div id="notified"'.$style.'>'.
7354: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
7355: &Apache::loncommon::start_data_table().
1.276 raeburn 7356: &Apache::loncommon::start_data_table_row();
7357: my $count = 0;
7358: my $numcols = 4;
7359: foreach my $cc (sort(@ccs)) {
7360: my $notifyon;
7361: my ($ccuname,$ccudom) = split(/:/,$cc);
7362: if ($notified{$cc}) {
7363: $notifyon = ' checked="checked" ';
7364: }
7365: if ($count && !$count%$numcols) {
7366: $output .= &Apache::loncommon::end_data_table_row().
7367: &Apache::loncommon::start_data_table_row()
7368: }
7369: $output .= '<td><span class="LC_nobreak"><label>'.
1.406.2.6 raeburn 7370: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 7371: &Apache::loncommon::plainname($ccuname,$ccudom).
7372: '</label></span></td>';
1.343 raeburn 7373: $count ++;
1.276 raeburn 7374: }
7375: my $rem = $count%$numcols;
7376: if ($rem) {
7377: my $emptycols = $numcols - $rem;
7378: for (my $i=0; $i<$emptycols; $i++) {
7379: $output .= '<td> </td>';
7380: }
7381: }
7382: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 7383: &Apache::loncommon::end_data_table().
7384: '</div>';
1.276 raeburn 7385: }
7386: } elsif ($item eq 'limit') {
1.398 raeburn 7387: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
7388: if (ref($currsettings) eq 'HASH') {
7389: $currlim = $currsettings->{'selfenroll_limit'};
7390: $currcap = $currsettings->{'selfenroll_cap'};
7391: }
1.400 raeburn 7392: if ($noedit{$item}) {
7393: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
7394: if ($currlim eq 'allstudents') {
7395: $output .= &mt('Limit by total students');
7396: } elsif ($currlim eq 'selfenrolled') {
7397: $output .= &mt('Limit by total self-enrolled students');
7398: }
7399: $output .= ' '.&mt('Maximum: [_1]',$currcap).
7400: '<br />'.&mt('(Set by Domain Coordinator)');
7401: } else {
7402: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
7403: }
7404: next;
7405: }
1.276 raeburn 7406: if ($currlim eq 'allstudents') {
7407: $crslimit = ' checked="checked" ';
7408: $selflimit = ' ';
7409: $nolimit = ' ';
7410: } elsif ($currlim eq 'selfenrolled') {
7411: $crslimit = ' ';
7412: $selflimit = ' checked="checked" ';
7413: $nolimit = ' ';
7414: } else {
7415: $crslimit = ' ';
7416: $selflimit = ' ';
1.398 raeburn 7417: $nolimit = ' checked="checked" ';
1.276 raeburn 7418: }
7419: $output .= '<table><tr><td><label>'.
1.406.2.6 raeburn 7420: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 7421: &mt('No limit').'</label></td><td><label>'.
1.406.2.6 raeburn 7422: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 7423: &mt('Limit by total students').'</label></td><td><label>'.
1.406.2.6 raeburn 7424: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 7425: &mt('Limit by total self-enrolled students').
7426: '</td></tr><tr>'.
7427: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
7428: (' 'x3).&mt('Maximum number allowed: ').
1.406.2.6 raeburn 7429: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 7430: }
7431: $output .= &Apache::lonhtmlcommon::row_closure(1);
7432: }
7433: }
1.406.2.6 raeburn 7434: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
7435: unless ($readonly) {
7436: $output .= '<input type="button" name="selfenrollconf" value="'
7437: .&mt('Save').'" onclick="validate_types(this.form);" />';
7438: }
7439: $output .= '<input type="hidden" name="action" value="selfenroll" />'
1.406.2.11 raeburn 7440: .'<input type="hidden" name="state" value="done" />'."\n"
7441: .$additional.'</form>';
1.237 raeburn 7442: $r->print($output);
7443: return;
7444: }
7445:
1.400 raeburn 7446: sub get_noedit_fields {
7447: my ($cdom,$cnum,$crstype,$row) = @_;
7448: my %noedit;
7449: if (ref($row) eq 'ARRAY') {
7450: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
7451: 'internal.selfenrollmgrdc',
7452: 'internal.selfenrollmgrcc'],$cdom,$cnum);
7453: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
7454: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
7455: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
7456: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
7457: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
7458: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
7459:
7460: foreach my $item (@{$row}) {
7461: next if ($specific_managebycc{$item});
7462: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
7463: $noedit{$item} = 1;
7464: }
7465: }
7466: }
7467: return %noedit;
7468: }
7469:
7470: sub visible_in_stdcat {
7471: my ($cdom,$cnum,$domconf) = @_;
7472: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
7473: unless (ref($domconf) eq 'HASH') {
7474: return ($visible,$cansetvis,\@vismsgs);
7475: }
7476: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7477: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 7478: $settable{'togglecats'} = 1;
7479: }
1.400 raeburn 7480: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 7481: $settable{'categorize'} = 1;
7482: }
1.400 raeburn 7483: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7484: }
1.260 raeburn 7485: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 7486: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
7487: } elsif ($settable{'togglecats'}) {
7488: $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 7489: } elsif ($settable{'categorize'}) {
1.256 raeburn 7490: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
7491: } else {
7492: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
7493: }
7494:
7495: my %currsettings =
7496: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
7497: $cdom,$cnum);
1.400 raeburn 7498: $visible = 0;
1.256 raeburn 7499: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 7500: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7501: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7502: if (ref($cathash) eq 'HASH') {
7503: if ($cathash->{'instcode::0'} eq '') {
7504: push(@vismsgs,'dc_addinst');
7505: } else {
7506: $visible = 1;
7507: }
7508: } else {
7509: $visible = 1;
7510: }
7511: } else {
7512: $visible = 1;
7513: }
7514: } else {
7515: if (ref($cathash) eq 'HASH') {
7516: if ($cathash->{'instcode::0'} ne '') {
7517: push(@vismsgs,'dc_instcode');
7518: }
7519: } else {
7520: push(@vismsgs,'dc_instcode');
7521: }
7522: }
7523: if ($currsettings{'categories'} ne '') {
7524: my $cathash;
1.400 raeburn 7525: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7526: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7527: if (ref($cathash) eq 'HASH') {
7528: if (keys(%{$cathash}) == 0) {
7529: push(@vismsgs,'dc_catalog');
7530: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
7531: push(@vismsgs,'dc_categories');
7532: } else {
7533: my @currcategories = split('&',$currsettings{'categories'});
7534: my $matched = 0;
7535: foreach my $cat (@currcategories) {
7536: if ($cathash->{$cat} ne '') {
7537: $visible = 1;
7538: $matched = 1;
7539: last;
7540: }
7541: }
7542: if (!$matched) {
1.260 raeburn 7543: if ($settable{'categorize'}) {
1.256 raeburn 7544: push(@vismsgs,'chgcat');
7545: } else {
7546: push(@vismsgs,'dc_chgcat');
7547: }
7548: }
7549: }
7550: }
7551: }
7552: } else {
7553: if (ref($cathash) eq 'HASH') {
7554: if ((keys(%{$cathash}) > 1) ||
7555: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 7556: if ($settable{'categorize'}) {
1.256 raeburn 7557: push(@vismsgs,'addcat');
7558: } else {
7559: push(@vismsgs,'dc_addcat');
7560: }
7561: }
7562: }
7563: }
7564: if ($currsettings{'hidefromcat'} eq 'yes') {
7565: $visible = 0;
7566: if ($settable{'togglecats'}) {
7567: unshift(@vismsgs,'unhide');
7568: } else {
7569: unshift(@vismsgs,'dc_unhide')
7570: }
7571: }
1.400 raeburn 7572: return ($visible,$cansetvis,\@vismsgs);
7573: }
7574:
7575: sub cat_visibility {
1.406.2.20.2. (raeburn 7576:): my ($cdom) = @_;
1.400 raeburn 7577: my %visactions = &Apache::lonlocal::texthash(
7578: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
7579: 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.',
7580: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
7581: none => 'Display of a course catalog is disabled for this domain.',
7582: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
7583: 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.',
7584: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
7585: take => 'Take the following action to ensure the course appears in the Catalog:',
7586: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
7587: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
7588: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
1.406.2.20.2. (raeburn 7589:): dc_addinst => 'Ask a domain coordinator to enable catalog display of "Official courses (with institutional codes)".',
1.400 raeburn 7590: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
7591: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
7592: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
7593: 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',
7594: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
7595: );
1.406.2.20.2. (raeburn 7596:): if ($env{'request.role'} eq "dc./$cdom/") {
7597:): $visactions{'dc_chgconf'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the Catalog type for this domain.','»');
7598:): $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.','»');
7599:): $visactions{'dc_unhide'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the "Exclude from course catalog" setting.','»');
7600:): $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)".','»');
7601:): $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).','»');
7602:): $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.','»');
7603:): $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.','»');
7604:): $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.','»');
7605:): $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.','»');
7606:): }
1.400 raeburn 7607: $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>"');
7608: $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>"');
7609: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
7610: return \%visactions;
1.256 raeburn 7611: }
7612:
1.241 raeburn 7613: sub new_selfenroll_dom_row {
7614: my ($newdom,$num) = @_;
7615: my $domdesc = &Apache::lonnet::domain($newdom);
7616: my $output;
7617: if ($domdesc ne '') {
7618: $output .= &Apache::loncommon::start_data_table_row()
7619: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
7620: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 7621: .'" value="'.$newdom.'" /></span><br />'
7622: .'<span class="LC_nobreak"><label><input type="checkbox" '
7623: .'name="selfenroll_activate" value="'.$num.'" '
7624: .'onchange="javascript:update_types('
7625: ."'selfenroll_activate','$num'".');" />'
7626: .&mt('Activate').'</label></span></td>';
1.241 raeburn 7627: my @currinsttypes;
7628: $output .= '<td>'.&mt('User types:').'<br />'
7629: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
7630: .&Apache::loncommon::end_data_table_row();
7631: }
7632: return $output;
7633: }
7634:
7635: sub selfenroll_inst_types {
1.406.2.6 raeburn 7636: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 7637: my $output;
7638: my $numinrow = 4;
7639: my $count = 0;
7640: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 7641: my $othervalue = 'any';
1.406.2.6 raeburn 7642: my $disabled;
7643: if ($readonly) {
7644: $disabled = ' disabled="disabled"';
7645: }
1.241 raeburn 7646: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 7647: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 7648: $othervalue = 'other';
7649: }
1.241 raeburn 7650: $output .= '<table><tr>';
7651: foreach my $type (@{$types}) {
7652: if (($count > 0) && ($count%$numinrow == 0)) {
7653: $output .= '</tr><tr>';
7654: }
7655: if (defined($usertypes->{$type})) {
1.257 raeburn 7656: my $esc_type = &escape($type);
1.241 raeburn 7657: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 7658: $esc_type.'" ';
1.241 raeburn 7659: if (ref($currinsttypes) eq 'ARRAY') {
7660: if (@{$currinsttypes} > 0) {
1.249 raeburn 7661: if (grep(/^any$/,@{$currinsttypes})) {
7662: $output .= 'checked="checked"';
1.257 raeburn 7663: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 7664: $output .= 'checked="checked"';
7665: }
1.249 raeburn 7666: } else {
7667: $output .= 'checked="checked"';
1.241 raeburn 7668: }
7669: }
1.406.2.6 raeburn 7670: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 7671: }
7672: $count ++;
7673: }
7674: if (($count > 0) && ($count%$numinrow == 0)) {
7675: $output .= '</tr><tr>';
7676: }
1.249 raeburn 7677: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 7678: if (ref($currinsttypes) eq 'ARRAY') {
7679: if (@{$currinsttypes} > 0) {
1.249 raeburn 7680: if (grep(/^any$/,@{$currinsttypes})) {
7681: $output .= ' checked="checked"';
7682: } elsif ($othervalue eq 'other') {
7683: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
7684: $output .= ' checked="checked"';
7685: }
1.241 raeburn 7686: }
1.249 raeburn 7687: } else {
7688: $output .= ' checked="checked"';
1.241 raeburn 7689: }
1.249 raeburn 7690: } else {
7691: $output .= ' checked="checked"';
1.241 raeburn 7692: }
1.406.2.6 raeburn 7693: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 7694: }
7695: return $output;
7696: }
7697:
1.237 raeburn 7698: sub selfenroll_date_forms {
7699: my ($startform,$endform) = @_;
7700: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 7701: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 7702: 'LC_oddrow_value')."\n".
7703: $startform."\n".
7704: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 7705: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 7706: 'LC_oddrow_value')."\n".
7707: $endform."\n".
7708: &Apache::lonhtmlcommon::row_closure(1).
7709: &Apache::lonhtmlcommon::end_pick_box();
7710: return $output;
7711: }
7712:
1.239 raeburn 7713: sub print_userchangelogs_display {
1.406.2.5 raeburn 7714: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 7715: my $formname = 'rolelog';
1.406.2.6 raeburn 7716: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 7717: if ($context eq 'domain') {
7718: $domain = $env{'request.role.domain'};
7719: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
7720: } else {
7721: if ($context eq 'course') {
7722: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
7723: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
7724: $crstype = &Apache::loncommon::course_type();
1.406.2.6 raeburn 7725: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 7726: my %saveable_parameters = ('show' => 'scalar',);
7727: &Apache::loncommon::store_course_settings('roles_log',
7728: \%saveable_parameters);
7729: &Apache::loncommon::restore_course_settings('roles_log',
7730: \%saveable_parameters);
7731: } elsif ($context eq 'author') {
1.406.2.20.2. (raeburn 7732:): $domain = $env{'user.domain'};
1.363 raeburn 7733: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
7734: $username = $env{'user.name'};
1.406.2.20.2. (raeburn 7735:): } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
7736:): ($domain,$username) = ($1,$2);
1.363 raeburn 7737: } else {
7738: undef($domain);
7739: }
7740: }
7741: if ($domain ne '' && $username ne '') {
7742: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
7743: }
7744: }
1.239 raeburn 7745: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
7746:
1.406.2.5 raeburn 7747: my $helpitem;
7748: if ($context eq 'course') {
7749: $helpitem = 'Course_User_Logs';
1.406.2.14 raeburn 7750: } elsif ($context eq 'domain') {
7751: $helpitem = 'Domain_Role_Logs';
7752: } elsif ($context eq 'author') {
7753: $helpitem = 'Author_User_Logs';
1.406.2.5 raeburn 7754: }
7755: push (@{$brcrum},
7756: {href => '/adm/createuser?action=changelogs',
7757: text => 'User Management Logs',
7758: help => $helpitem});
7759: my $bread_crumbs_component = 'User Changes';
7760: my $args = { bread_crumbs => $brcrum,
7761: bread_crumbs_component => $bread_crumbs_component};
7762:
7763: # Create navigation javascript
7764: my $jsnav = &userlogdisplay_js($formname);
7765:
7766: my $jscript = (<<ENDSCRIPT);
7767: <script type="text/javascript">
7768: // <![CDATA[
7769: $jsnav
7770: // ]]>
7771: </script>
7772: ENDSCRIPT
7773:
7774: # print page header
7775: $r->print(&header($jscript,$args));
7776:
1.239 raeburn 7777: # set defaults
7778: my $now = time();
7779: my $defstart = $now - (7*24*3600); #7 days ago
7780: my %defaults = (
7781: page => '1',
7782: show => '10',
7783: role => 'any',
7784: chgcontext => 'any',
7785: rolelog_start_date => $defstart,
7786: rolelog_end_date => $now,
7787: );
7788: my $more_records = 0;
7789:
7790: # set current
7791: my %curr;
7792: foreach my $item ('show','page','role','chgcontext') {
7793: $curr{$item} = $env{'form.'.$item};
7794: }
7795: my ($startdate,$enddate) =
7796: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
7797: $curr{'rolelog_start_date'} = $startdate;
7798: $curr{'rolelog_end_date'} = $enddate;
7799: foreach my $key (keys(%defaults)) {
7800: if ($curr{$key} eq '') {
7801: $curr{$key} = $defaults{$key};
7802: }
7803: }
1.248 raeburn 7804: my (%whodunit,%changed,$version);
7805: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 7806: my ($minshown,$maxshown);
1.255 raeburn 7807: $minshown = 1;
1.239 raeburn 7808: my $count = 0;
1.406.2.5 raeburn 7809: if ($curr{'show'} =~ /\D/) {
7810: $curr{'page'} = 1;
7811: } else {
1.239 raeburn 7812: $maxshown = $curr{'page'} * $curr{'show'};
7813: if ($curr{'page'} > 1) {
7814: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7815: }
7816: }
1.301 bisitz 7817:
1.327 raeburn 7818: # Form Header
7819: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 7820: &role_display_filter($context,$formname,$domain,$username,\%curr,
7821: $version,$crstype));
1.327 raeburn 7822:
7823: my $showntableheader = 0;
7824:
7825: # Table Header
7826: my $tableheader =
7827: &Apache::loncommon::start_data_table_header_row()
7828: .'<th> </th>'
7829: .'<th>'.&mt('When').'</th>'
7830: .'<th>'.&mt('Who made the change').'</th>'
7831: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 7832: .'<th>'.&mt('Role').'</th>';
7833:
7834: if ($context eq 'course') {
7835: $tableheader .= '<th>'.&mt('Section').'</th>';
7836: }
7837: $tableheader .=
7838: '<th>'.&mt('Context').'</th>'
1.327 raeburn 7839: .'<th>'.&mt('Start').'</th>'
7840: .'<th>'.&mt('End').'</th>'
7841: .&Apache::loncommon::end_data_table_header_row();
7842:
7843: # Display user change log data
1.239 raeburn 7844: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
7845: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
7846: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.406.2.5 raeburn 7847: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 7848: if ($count >= $curr{'page'} * $curr{'show'}) {
7849: $more_records = 1;
7850: last;
7851: }
7852: }
7853: if ($curr{'role'} ne 'any') {
7854: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
7855: }
7856: if ($curr{'chgcontext'} ne 'any') {
7857: if ($curr{'chgcontext'} eq 'selfenroll') {
7858: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
7859: } else {
7860: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
7861: }
7862: }
1.406.2.6 raeburn 7863: if (($context eq 'course') && ($viewablesec ne '')) {
7864: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
7865: }
1.239 raeburn 7866: $count ++;
7867: next if ($count < $minshown);
1.327 raeburn 7868: unless ($showntableheader) {
1.406.2.5 raeburn 7869: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 7870: .$tableheader);
7871: $r->rflush();
7872: $showntableheader = 1;
7873: }
1.239 raeburn 7874: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
7875: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
7876: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
7877: }
7878: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
7879: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
7880: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
7881: }
7882: my $sec = $roleslog{$id}{'logentry'}{'section'};
7883: if ($sec eq '') {
7884: $sec = &mt('None');
7885: }
7886: my ($rolestart,$roleend);
7887: if ($roleslog{$id}{'delflag'}) {
7888: $rolestart = &mt('deleted');
7889: $roleend = &mt('deleted');
7890: } else {
7891: $rolestart = $roleslog{$id}{'logentry'}{'start'};
7892: $roleend = $roleslog{$id}{'logentry'}{'end'};
7893: if ($rolestart eq '' || $rolestart == 0) {
7894: $rolestart = &mt('No start date');
7895: } else {
7896: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
7897: }
7898: if ($roleend eq '' || $roleend == 0) {
7899: $roleend = &mt('No end date');
7900: } else {
7901: $roleend = &Apache::lonlocal::locallocaltime($roleend);
7902: }
7903: }
7904: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
7905: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
7906: $chgcontext = 'selfenroll';
7907: }
1.363 raeburn 7908: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 7909: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
7910: $chgcontext = $lt{$chgcontext};
7911: }
1.327 raeburn 7912: $r->print(
1.301 bisitz 7913: &Apache::loncommon::start_data_table_row()
7914: .'<td>'.$count.'</td>'
7915: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
7916: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
7917: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 7918: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
7919: if ($context eq 'course') {
7920: $r->print('<td>'.$sec.'</td>');
7921: }
7922: $r->print(
7923: '<td>'.$chgcontext.'</td>'
1.301 bisitz 7924: .'<td>'.$rolestart.'</td>'
7925: .'<td>'.$roleend.'</td>'
1.327 raeburn 7926: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 7927: }
7928:
1.327 raeburn 7929: if ($showntableheader) { # Table footer, if content displayed above
1.406.2.5 raeburn 7930: $r->print(&Apache::loncommon::end_data_table().
7931: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 7932: } else { # No content displayed above
1.301 bisitz 7933: $r->print('<p class="LC_info">'
7934: .&mt('There are no records to display.')
7935: .'</p>'
7936: );
1.239 raeburn 7937: }
1.301 bisitz 7938:
1.327 raeburn 7939: # Form Footer
7940: $r->print(
7941: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7942: .'<input type="hidden" name="action" value="changelogs" />'
7943: .'</form>');
7944: return;
7945: }
1.301 bisitz 7946:
1.406.2.5 raeburn 7947: sub print_useraccesslogs_display {
7948: my ($r,$uname,$udom,$permission,$brcrum) = @_;
7949: my $formname = 'accesslog';
7950: my $form = 'document.accesslog';
7951:
7952: # set breadcrumbs
1.406.2.7 raeburn 7953: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.406.2.12 raeburn 7954: my $prevphasestr;
7955: if ($env{'form.popup'}) {
7956: $brcrum = [];
7957: } else {
7958: push (@{$brcrum},
7959: {href => "javascript:backPage($form)",
7960: text => $breadcrumb_text{'search'}});
7961: my @prevphases;
7962: if ($env{'form.prevphases'}) {
7963: @prevphases = split(/,/,$env{'form.prevphases'});
7964: $prevphasestr = $env{'form.prevphases'};
7965: }
7966: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
7967: push(@{$brcrum},
7968: {href => "javascript:backPage($form,'get_user_info','select')",
7969: text => $breadcrumb_text{'userpicked'}});
7970: if ($env{'form.phase'} eq 'userpicked') {
7971: $prevphasestr = 'userpicked';
7972: }
1.406.2.5 raeburn 7973: }
7974: }
7975: push(@{$brcrum},
7976: {href => '/adm/createuser?action=accesslogs',
7977: text => 'User access logs',
1.406.2.8 raeburn 7978: help => 'Domain_User_Access_Logs'});
1.406.2.5 raeburn 7979: my $bread_crumbs_component = 'User Access Logs';
7980: my $args = { bread_crumbs => $brcrum,
7981: bread_crumbs_component => 'User Management'};
1.406.2.8 raeburn 7982: if ($env{'form.popup'}) {
7983: $args->{'no_nav_bar'} = 1;
1.406.2.12 raeburn 7984: $args->{'bread_crumbs_nomenu'} = 1;
1.406.2.8 raeburn 7985: }
1.406.2.5 raeburn 7986:
7987: # set javascript
7988: my ($jsback,$elements) = &crumb_utilities();
7989: my $jsnav = &userlogdisplay_js($formname);
7990:
7991: my $jscript = (<<ENDSCRIPT);
1.239 raeburn 7992: <script type="text/javascript">
1.301 bisitz 7993: // <![CDATA[
1.406.2.5 raeburn 7994:
7995: $jsback
7996: $jsnav
7997:
7998: // ]]>
7999: </script>
8000:
8001: ENDSCRIPT
8002:
8003: # print page header
8004: $r->print(&header($jscript,$args));
8005:
8006: # early out unless log data can be displayed.
8007: unless ($permission->{'activity'}) {
8008: $r->print('<p class="LC_warning">'
8009: .&mt('You do not have rights to display user access logs.')
1.406.2.12 raeburn 8010: .'</p>');
8011: if ($env{'form.popup'}) {
8012: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
8013: } else {
8014: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8015: }
1.406.2.5 raeburn 8016: return;
8017: }
8018:
8019: unless ($udom eq $env{'request.role.domain'}) {
8020: $r->print('<p class="LC_warning">'
8021: .&mt("User's domain must match role's domain")
8022: .'</p>'
8023: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8024: return;
8025: }
8026:
8027: if (($uname eq '') || ($udom eq '')) {
8028: $r->print('<p class="LC_warning">'
8029: .&mt('Invalid username or domain')
8030: .'</p>'
8031: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8032: return;
8033: }
8034:
1.406.2.13 raeburn 8035: if (&Apache::lonnet::privileged($uname,$udom,
8036: [$env{'request.role.domain'}],['dc','su'])) {
8037: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
8038: [$env{'request.role.domain'}],['dc','su'])) {
8039: $r->print('<p class="LC_warning">'
8040: .&mt('You need to be a privileged user to display user access logs for [_1]',
8041: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
8042: $uname,$udom))
8043: .'</p>');
8044: if ($env{'form.popup'}) {
8045: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
8046: } else {
8047: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8048: }
8049: return;
8050: }
8051: }
8052:
1.406.2.5 raeburn 8053: # set defaults
8054: my $now = time();
8055: my $defstart = $now - (7*24*3600);
8056: my %defaults = (
8057: page => '1',
8058: show => '10',
8059: activity => 'any',
8060: accesslog_start_date => $defstart,
8061: accesslog_end_date => $now,
8062: );
8063: my $more_records = 0;
8064:
8065: # set current
8066: my %curr;
8067: foreach my $item ('show','page','activity') {
8068: $curr{$item} = $env{'form.'.$item};
8069: }
8070: my ($startdate,$enddate) =
8071: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
8072: $curr{'accesslog_start_date'} = $startdate;
8073: $curr{'accesslog_end_date'} = $enddate;
8074: foreach my $key (keys(%defaults)) {
8075: if ($curr{$key} eq '') {
8076: $curr{$key} = $defaults{$key};
8077: }
8078: }
8079: my ($minshown,$maxshown);
8080: $minshown = 1;
8081: my $count = 0;
8082: if ($curr{'show'} =~ /\D/) {
8083: $curr{'page'} = 1;
8084: } else {
8085: $maxshown = $curr{'page'} * $curr{'show'};
8086: if ($curr{'page'} > 1) {
8087: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
8088: }
8089: }
8090:
8091: # form header
8092: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
8093: &activity_display_filter($formname,\%curr));
8094:
8095: my $showntableheader = 0;
8096: my ($nav_script,$nav_links);
8097:
8098: # table header
1.406.2.18 raeburn 8099: my $heading = '<h3>'.
1.406.2.12 raeburn 8100: &mt('User access logs for: [_1]',
1.406.2.18 raeburn 8101: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
8102: my $tableheader = $heading
1.406.2.12 raeburn 8103: .&Apache::loncommon::start_data_table_header_row()
1.406.2.5 raeburn 8104: .'<th> </th>'
8105: .'<th>'.&mt('When').'</th>'
8106: .'<th>'.&mt('HostID').'</th>'
8107: .'<th>'.&mt('Event').'</th>'
8108: .'<th>'.&mt('Other data').'</th>'
8109: .&Apache::loncommon::end_data_table_header_row();
8110:
8111: my %filters=(
8112: start => $curr{'accesslog_start_date'},
8113: end => $curr{'accesslog_end_date'},
8114: action => $curr{'activity'},
8115: );
8116:
8117: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
8118: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
8119: my (%courses,%missing);
8120: my @results = split(/\&/,$reply);
8121: foreach my $item (reverse(@results)) {
8122: my ($timestamp,$host,$event) = split(/:/,$item);
8123: next unless ($event =~ /^(Log|Role)/);
8124: if ($curr{'show'} !~ /\D/) {
8125: if ($count >= $curr{'page'} * $curr{'show'}) {
8126: $more_records = 1;
8127: last;
8128: }
8129: }
8130: $count ++;
8131: next if ($count < $minshown);
8132: unless ($showntableheader) {
8133: $r->print($nav_script
8134: .&Apache::loncommon::start_data_table()
8135: .$tableheader);
8136: $r->rflush();
8137: $showntableheader = 1;
8138: }
1.406.2.6 raeburn 8139: my ($shown,$extra);
1.406.2.13 raeburn 8140: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.406.2.5 raeburn 8141: if ($event eq 'Role') {
8142: my ($rolecode,$extent) = split(/\./,$data,2);
8143: next if ($extent eq '');
8144: my ($crstype,$desc,$info);
1.406.2.6 raeburn 8145: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
8146: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.406.2.5 raeburn 8147: my $cid = $cdom.'_'.$cnum;
8148: if (exists($courses{$cid})) {
8149: $crstype = $courses{$cid}{'type'};
8150: $desc = $courses{$cid}{'description'};
8151: } elsif ($missing{$cid}) {
8152: $crstype = 'Course';
8153: $desc = 'Course/Community';
8154: } else {
8155: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
8156: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
8157: $courses{$cid} = $crsinfo{$cid};
8158: $crstype = $crsinfo{$cid}{'type'};
8159: $desc = $crsinfo{$cid}{'description'};
8160: } else {
8161: $missing{$cid} = 1;
8162: }
8163: }
8164: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.406.2.6 raeburn 8165: if ($sec ne '') {
8166: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
8167: }
1.406.2.5 raeburn 8168: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
8169: my ($dom,$name) = ($1,$2);
8170: if ($rolecode eq 'au') {
8171: $extra = '';
8172: } elsif ($rolecode =~ /^(ca|aa)$/) {
8173: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
8174: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
8175: $extra = &mt('Domain: [_1]',$dom);
8176: }
8177: }
8178: my $rolename;
8179: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
8180: my $role = $3;
8181: my $owner = "($2:$1)";
8182: if ($2 eq $1.'-domainconfig') {
8183: $owner = '(ad hoc)';
8184: }
8185: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
8186: } else {
8187: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
8188: }
8189: $shown = &mt('Role selection: [_1]',$rolename);
8190: } else {
8191: $shown = &mt($event);
1.406.2.13 raeburn 8192: if ($data =~ /^webdav/) {
8193: my ($path,$clientip) = split(/\s+/,$data,2);
8194: $path =~ s/^webdav//;
8195: if ($clientip ne '') {
8196: $extra = &mt('Client IP address: [_1]',$clientip);
8197: }
8198: if ($path ne '') {
8199: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
8200: }
8201: } elsif ($data ne '') {
8202: $extra = &mt('Client IP address: [_1]',$data);
1.406.2.5 raeburn 8203: }
8204: }
8205: $r->print(
8206: &Apache::loncommon::start_data_table_row()
8207: .'<td>'.$count.'</td>'
8208: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
8209: .'<td>'.$host.'</td>'
8210: .'<td>'.$shown.'</td>'
8211: .'<td>'.$extra.'</td>'
8212: .&Apache::loncommon::end_data_table_row()."\n");
8213: }
8214: }
8215:
8216: if ($showntableheader) { # Table footer, if content displayed above
8217: $r->print(&Apache::loncommon::end_data_table().
8218: &userlogdisplay_navlinks(\%curr,$more_records));
8219: } else { # No content displayed above
1.406.2.18 raeburn 8220: $r->print($heading.'<p class="LC_info">'
1.406.2.5 raeburn 8221: .&mt('There are no records to display.')
8222: .'</p>');
8223: }
8224:
1.406.2.8 raeburn 8225: if ($env{'form.popup'} == 1) {
8226: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
8227: }
8228:
1.406.2.5 raeburn 8229: # Form Footer
8230: $r->print(
8231: '<input type="hidden" name="currstate" value="" />'
8232: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
8233: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
8234: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
8235: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
8236: .'<input type="hidden" name="phase" value="activity" />'
8237: .'<input type="hidden" name="action" value="accesslogs" />'
8238: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
8239: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
8240: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
8241: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
8242: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
8243: .'</form>');
8244: return;
8245: }
8246:
8247: sub earlyout_accesslog_form {
8248: my ($formname,$prevphasestr,$udom) = @_;
8249: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
8250: return <<"END";
8251: <form action="/adm/createuser" method="post" name="$formname">
8252: <input type="hidden" name="currstate" value="" />
8253: <input type="hidden" name="prevphases" value="$prevphasestr" />
8254: <input type="hidden" name="phase" value="activity" />
8255: <input type="hidden" name="action" value="accesslogs" />
8256: <input type="hidden" name="srchdomain" value="$udom" />
8257: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
8258: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
8259: <input type="hidden" name="srchterm" value="$srchterm" />
8260: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
8261: </form>
8262: END
8263: }
8264:
8265: sub activity_display_filter {
8266: my ($formname,$curr) = @_;
8267: my $nolink = 1;
8268: my $output = '<table><tr><td valign="top">'.
8269: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
8270: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
8271: (&mt('all'),5,10,20,50,100,1000,10000)).
8272: '</td><td> </td>';
8273: my $startform =
8274: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
8275: $curr->{'accesslog_start_date'},undef,
8276: undef,undef,undef,undef,undef,undef,$nolink);
8277: my $endform =
8278: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
8279: $curr->{'accesslog_end_date'},undef,
8280: undef,undef,undef,undef,undef,undef,$nolink);
8281: my %lt = &Apache::lonlocal::texthash (
8282: activity => 'Activity',
8283: Role => 'Role selection',
8284: log => 'Log-in or Logout',
8285: );
8286: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
8287: '<table><tr><td>'.&mt('After:').
8288: '</td><td>'.$startform.'</td></tr>'.
8289: '<tr><td>'.&mt('Before:').'</td>'.
8290: '<td>'.$endform.'</td></tr></table>'.
8291: '</td>'.
8292: '<td> </td>'.
8293: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
8294: '<select name="activity"><option value="any"';
8295: if ($curr->{'activity'} eq 'any') {
8296: $output .= ' selected="selected"';
8297: }
8298: $output .= '>'.&mt('Any').'</option>'."\n";
8299: foreach my $activity ('Role','log') {
8300: my $selstr = '';
8301: if ($activity eq $curr->{'activity'}) {
8302: $selstr = ' selected="selected"';
8303: }
8304: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
8305: }
8306: $output .= '</select></td>'.
8307: '</tr></table>';
8308: # Update Display button
8309: $output .= '<p>'
8310: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.406.2.12 raeburn 8311: .'</p><hr />';
1.406.2.5 raeburn 8312: return $output;
8313: }
8314:
8315: sub userlogdisplay_js {
8316: my ($formname) = @_;
8317: return <<"ENDSCRIPT";
8318:
1.239 raeburn 8319: function chgPage(caller) {
8320: if (caller == 'previous') {
8321: document.$formname.page.value --;
8322: }
8323: if (caller == 'next') {
8324: document.$formname.page.value ++;
8325: }
1.327 raeburn 8326: document.$formname.submit();
1.239 raeburn 8327: return;
8328: }
8329: ENDSCRIPT
1.406.2.5 raeburn 8330: }
8331:
8332: sub userlogdisplay_navlinks {
8333: my ($curr,$more_records) = @_;
8334: return unless(ref($curr) eq 'HASH');
8335: # Navigation Buttons
8336: my $nav_links = '<p>';
8337: if (($curr->{'page'} > 1) || ($more_records)) {
8338: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
8339: $nav_links .= '<input type="button"'
8340: .' onclick="javascript:chgPage('."'previous'".');"'
8341: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
8342: .'" /> ';
8343: }
8344: if ($more_records) {
8345: $nav_links .= '<input type="button"'
8346: .' onclick="javascript:chgPage('."'next'".');"'
8347: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
8348: .'" />';
1.301 bisitz 8349: }
8350: }
1.406.2.5 raeburn 8351: $nav_links .= '</p>';
8352: return $nav_links;
1.239 raeburn 8353: }
8354:
8355: sub role_display_filter {
1.363 raeburn 8356: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
8357: my $lctype;
8358: if ($context eq 'course') {
8359: $lctype = lc($crstype);
8360: }
1.239 raeburn 8361: my $nolink = 1;
8362: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 8363: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 8364: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
8365: (&mt('all'),5,10,20,50,100,1000,10000)).
8366: '</td><td> </td>';
8367: my $startform =
8368: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
8369: $curr->{'rolelog_start_date'},undef,
8370: undef,undef,undef,undef,undef,undef,$nolink);
8371: my $endform =
8372: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
8373: $curr->{'rolelog_end_date'},undef,
8374: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 8375: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 8376: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
8377: '<table><tr><td>'.&mt('After:').
8378: '</td><td>'.$startform.'</td></tr>'.
8379: '<tr><td>'.&mt('Before:').'</td>'.
8380: '<td>'.$endform.'</td></tr></table>'.
8381: '</td>'.
8382: '<td> </td>'.
1.239 raeburn 8383: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
8384: '<select name="role"><option value="any"';
8385: if ($curr->{'role'} eq 'any') {
8386: $output .= ' selected="selected"';
8387: }
8388: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 8389: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 8390: foreach my $role (@roles) {
8391: my $plrole;
8392: if ($role eq 'cr') {
8393: $plrole = &mt('Custom Role');
8394: } else {
1.318 raeburn 8395: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 8396: }
8397: my $selstr = '';
8398: if ($role eq $curr->{'role'}) {
8399: $selstr = ' selected="selected"';
8400: }
8401: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
8402: }
1.301 bisitz 8403: $output .= '</select></td>'.
8404: '<td> </td>'.
8405: '<td valign="top"><b>'.
1.239 raeburn 8406: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 8407: my @posscontexts;
8408: if ($context eq 'course') {
1.406.2.20 raeburn 8409: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype');
1.363 raeburn 8410: } elsif ($context eq 'domain') {
8411: @posscontexts = ('any','domain','requestauthor','domconfig','server');
8412: } else {
1.406.2.20.2. (raeburn 8413:): @posscontexts = ('any','author','coauthor','domain');
1.406.2.20 raeburn 8414: }
1.363 raeburn 8415: foreach my $chgtype (@posscontexts) {
1.239 raeburn 8416: my $selstr = '';
8417: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 8418: $selstr = ' selected="selected"';
1.239 raeburn 8419: }
1.363 raeburn 8420: if ($context eq 'course') {
1.376 raeburn 8421: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 8422: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
8423: }
1.239 raeburn 8424: }
8425: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 8426: }
1.303 bisitz 8427: $output .= '</select></td>'
8428: .'</tr></table>';
8429:
8430: # Update Display button
8431: $output .= '<p>'
8432: .'<input type="submit" value="'.&mt('Update Display').'" />'
8433: .'</p>';
8434:
8435: # Server version info
1.363 raeburn 8436: my $needsrev = '2.11.0';
8437: if ($context eq 'course') {
8438: $needsrev = '2.7.0';
8439: }
8440:
1.303 bisitz 8441: $output .= '<p class="LC_info">'
8442: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 8443: ,$needsrev);
1.248 raeburn 8444: if ($version) {
1.303 bisitz 8445: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
8446: }
8447: $output .= '</p><hr />';
1.239 raeburn 8448: return $output;
8449: }
8450:
8451: sub rolechg_contexts {
1.363 raeburn 8452: my ($context,$crstype) = @_;
8453: my %lt;
8454: if ($context eq 'course') {
8455: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 8456: any => 'Any',
1.376 raeburn 8457: automated => 'Automated Enrollment',
1.406.2.20 raeburn 8458: chgtype => 'Enrollment Type/Lock Change',
1.239 raeburn 8459: updatenow => 'Roster Update',
8460: createcourse => 'Course Creation',
8461: course => 'User Management in course',
8462: domain => 'User Management in domain',
1.313 raeburn 8463: selfenroll => 'Self-enrolled',
1.318 raeburn 8464: requestcourses => 'Course Request',
1.239 raeburn 8465: );
1.363 raeburn 8466: if ($crstype eq 'Community') {
8467: $lt{'createcourse'} = &mt('Community Creation');
8468: $lt{'course'} = &mt('User Management in community');
8469: $lt{'requestcourses'} = &mt('Community Request');
8470: }
8471: } elsif ($context eq 'domain') {
8472: %lt = &Apache::lonlocal::texthash (
8473: any => 'Any',
8474: domain => 'User Management in domain',
8475: requestauthor => 'Authoring Request',
8476: server => 'Command line script (DC role)',
8477: domconfig => 'Self-enrolled',
8478: );
8479: } else {
8480: %lt = &Apache::lonlocal::texthash (
8481: any => 'Any',
8482: domain => 'User Management in domain',
8483: author => 'User Management by author',
1.406.2.20.2. (raeburn 8484:): coauthor => 'User Management by coauthor',
1.363 raeburn 8485: );
8486: }
1.239 raeburn 8487: return %lt;
8488: }
8489:
1.406.2.10 raeburn 8490: sub print_helpdeskaccess_display {
8491: my ($r,$permission,$brcrum) = @_;
8492: my $formname = 'helpdeskaccess';
8493: my $helpitem = 'Course_Helpdesk_Access';
8494: push (@{$brcrum},
8495: {href => '/adm/createuser?action=helpdesk',
8496: text => 'Helpdesk Access',
8497: help => $helpitem});
8498: my $bread_crumbs_component = 'Helpdesk Staff Access';
8499: my $args = { bread_crumbs => $brcrum,
8500: bread_crumbs_component => $bread_crumbs_component};
8501:
8502: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8503: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8504: my $confname = $cdom.'-domainconfig';
8505: my $crstype = &Apache::loncommon::course_type();
8506:
1.406.2.12 raeburn 8507: my @accesstypes = ('all','dh','da','none');
1.406.2.10 raeburn 8508: my ($numstatustypes,@jsarray);
8509: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8510: if (ref($types) eq 'ARRAY') {
8511: if (@{$types} > 0) {
8512: $numstatustypes = scalar(@{$types});
8513: push(@accesstypes,'status');
8514: @jsarray = ('bystatus');
8515: }
8516: }
8517: my %customroles = &get_domain_customroles($cdom,$confname);
1.406.2.12 raeburn 8518: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 8519: if (keys(%domhelpdesk)) {
8520: push(@accesstypes,('inc','exc'));
8521: push(@jsarray,('notinc','notexc'));
8522: }
8523: push(@jsarray,'privs');
8524: my $hiddenstr = join("','",@jsarray);
8525: my $rolestr = join("','",sort(keys(%customroles)));
8526:
8527: my $jscript;
8528: my (%settings,%overridden);
8529: if (keys(%customroles)) {
8530: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8531: $types,\%customroles,\%settings,\%overridden);
8532: my %jsfull=();
8533: my %jslevels= (
8534: course => {},
8535: domain => {},
8536: system => {},
8537: );
8538: my %jslevelscurrent=(
8539: course => {},
8540: domain => {},
8541: system => {},
8542: );
8543: my (%privs,%jsprivs);
8544: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
8545: foreach my $priv (keys(%jsfull)) {
8546: if ($jslevels{'course'}{$priv}) {
8547: $jsprivs{$priv} = 1;
8548: }
8549: }
8550: my (%elements,%stored);
8551: foreach my $role (keys(%customroles)) {
8552: $elements{$role.'_access'} = 'radio';
8553: $elements{$role.'_incrs'} = 'radio';
8554: if ($numstatustypes) {
8555: $elements{$role.'_status'} = 'checkbox';
8556: }
8557: if (keys(%domhelpdesk) > 0) {
8558: $elements{$role.'_staff_inc'} = 'checkbox';
8559: $elements{$role.'_staff_exc'} = 'checkbox';
8560: }
8561: $elements{$role.'_override'} = 'checkbox';
8562: if (ref($settings{$role}) eq 'HASH') {
8563: if ($settings{$role}{'access'} ne '') {
8564: my $curraccess = $settings{$role}{'access'};
8565: $stored{$role.'_access'} = $curraccess;
8566: $stored{$role.'_incrs'} = 1;
8567: if ($curraccess eq 'status') {
8568: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
8569: $stored{$role.'_status'} = $settings{$role}{'status'};
8570: }
8571: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8572: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
8573: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
8574: }
8575: }
8576: } else {
8577: $stored{$role.'_incrs'} = 0;
8578: }
8579: $stored{$role.'_override'} = [];
8580: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
8581: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
8582: foreach my $priv (@{$settings{$role}{'off'}}) {
8583: push(@{$stored{$role.'_override'}},$priv);
8584: }
8585: }
8586: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
8587: foreach my $priv (@{$settings{$role}{'on'}}) {
8588: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
8589: push(@{$stored{$role.'_override'}},$priv);
8590: }
8591: }
8592: }
8593: }
8594: } else {
8595: $stored{$role.'_incrs'} = 0;
8596: }
8597: }
8598: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
8599: }
8600:
8601: my $js = <<"ENDJS";
8602: <script type="text/javascript">
8603: // <![CDATA[
8604: $jscript;
8605:
8606: function switchRoleTab(caller,role) {
8607: if (document.getElementById(role+'_maindiv')) {
8608: if (caller.id != 'LC_current_minitab') {
8609: if (document.getElementById('LC_current_minitab')) {
8610: document.getElementById('LC_current_minitab').id=null;
8611: }
8612: var roledivs = Array('$rolestr');
8613: if (roledivs.length > 0) {
8614: for (var i=0; i<roledivs.length; i++) {
8615: if (document.getElementById(roledivs[i]+'_maindiv')) {
8616: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
8617: }
8618: }
8619: }
8620: caller.id = 'LC_current_minitab';
8621: document.getElementById(role+'_maindiv').style.display='block';
8622: }
8623: }
8624: return false;
8625: }
8626:
8627: function helpdeskAccess(role) {
8628: var curraccess = null;
8629: if (document.$formname.elements[role+'_access'].length) {
8630: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
8631: if (document.$formname.elements[role+'_access'][i].checked) {
8632: curraccess = document.$formname.elements[role+'_access'][i].value;
8633: }
8634: }
8635: }
8636: var shown = Array();
8637: var hidden = Array();
8638: if (curraccess == 'none') {
8639: hidden = Array ('$hiddenstr');
8640: } else {
8641: if (curraccess == 'status') {
8642: shown = Array ('bystatus','privs');
8643: hidden = Array ('notinc','notexc');
8644: } else {
8645: if (curraccess == 'exc') {
8646: shown = Array ('notexc','privs');
8647: hidden = Array ('notinc','bystatus');
8648: }
8649: if (curraccess == 'inc') {
8650: shown = Array ('notinc','privs');
8651: hidden = Array ('notexc','bystatus');
8652: }
8653: if (curraccess == 'all') {
8654: shown = Array ('privs');
8655: hidden = Array ('notinc','notexc','bystatus');
8656: }
8657: }
8658: }
8659: if (hidden.length > 0) {
8660: for (var i=0; i<hidden.length; i++) {
8661: if (document.getElementById(role+'_'+hidden[i])) {
8662: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
8663: }
8664: }
8665: }
8666: if (shown.length > 0) {
8667: for (var i=0; i<shown.length; i++) {
8668: if (document.getElementById(role+'_'+shown[i])) {
8669: if (shown[i] == 'privs') {
8670: document.getElementById(role+'_'+shown[i]).style.display = 'block';
8671: } else {
8672: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
8673: }
8674: }
8675: }
8676: }
8677: return;
8678: }
8679:
8680: function toggleAccess(role) {
8681: if ((document.getElementById(role+'_setincrs')) &&
8682: (document.getElementById(role+'_setindom'))) {
8683: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
8684: if (document.$formname.elements[role+'_incrs'][i].checked) {
8685: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
8686: document.getElementById(role+'_setindom').style.display = 'none';
8687: document.getElementById(role+'_setincrs').style.display = 'block';
8688: } else {
8689: document.getElementById(role+'_setincrs').style.display = 'none';
8690: document.getElementById(role+'_setindom').style.display = 'block';
8691: }
8692: break;
8693: }
8694: }
8695: }
8696: return;
8697: }
8698:
8699: // ]]>
8700: </script>
8701: ENDJS
8702:
8703: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
8704:
8705: # print page header
8706: $r->print(&header($js,$args));
8707: # print form header
8708: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
8709:
8710: if (keys(%customroles)) {
8711: my %lt = &Apache::lonlocal::texthash(
8712: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
8713: 'rou' => 'Role usage',
8714: 'whi' => 'Which helpdesk personnel may use this role?',
8715: 'udd' => 'Use domain default',
1.406.2.12 raeburn 8716: 'all' => 'All with domain helpdesk or helpdesk assistant role',
8717: 'dh' => 'All with domain helpdesk role',
8718: 'da' => 'All with domain helpdesk assistant role',
1.406.2.10 raeburn 8719: 'none' => 'None',
8720: 'status' => 'Determined based on institutional status',
8721: 'inc' => 'Include all, but exclude specific personnel',
8722: 'exc' => 'Exclude all, but include specific personnel',
8723: 'hel' => 'Helpdesk',
8724: 'rpr' => 'Role privileges',
8725: );
8726: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
8727: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8728: my (%domcurrent,%ordered,%description,%domusage,$disabled);
8729: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8730: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8731: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8732: }
8733: }
8734: my $count = 0;
8735: foreach my $role (sort(keys(%customroles))) {
8736: my ($order,$desc,$access_in_dom);
8737: if (ref($domcurrent{$role}) eq 'HASH') {
8738: $order = $domcurrent{$role}{'order'};
8739: $desc = $domcurrent{$role}{'desc'};
8740: $access_in_dom = $domcurrent{$role}{'access'};
8741: }
8742: if ($order eq '') {
8743: $order = $count;
8744: }
8745: $ordered{$order} = $role;
8746: if ($desc ne '') {
8747: $description{$role} = $desc;
8748: } else {
8749: $description{$role}= $role;
8750: }
8751: $count++;
8752: }
8753: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8754: my @roles_by_num = ();
8755: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8756: push(@roles_by_num,$ordered{$item});
8757: }
8758: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
8759: if ($permission->{'owner'}) {
8760: $r->print('<br />'.$lt{'aco'}.'</p><p>');
8761: $r->print('<input type="hidden" name="state" value="process" />'.
8762: '<input type="submit" value="'.&mt('Save changes').'" />');
8763: } else {
8764: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
8765: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
8766: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
8767: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
8768: }
8769: $disabled = ' disabled="disabled"';
8770: }
8771: $r->print('</p>');
8772:
8773: $r->print('<div id="LC_minitab_header"><ul>');
8774: my $count = 0;
8775: my %visibility;
8776: foreach my $role (@roles_by_num) {
8777: my $id;
8778: if ($count == 0) {
8779: $id=' id="LC_current_minitab"';
8780: $visibility{$role} = ' style="display:block"';
8781: } else {
8782: $visibility{$role} = ' style="display:none"';
8783: }
8784: $count ++;
8785: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
8786: }
8787: $r->print('</ul></div>');
8788:
8789: foreach my $role (@roles_by_num) {
8790: my %usecheck = (
8791: all => ' checked="checked"',
8792: );
8793: my %displaydiv = (
8794: status => 'none',
8795: inc => 'none',
8796: exc => 'none',
8797: priv => 'block',
8798: );
8799: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
8800: if (ref($settings{$role}) eq 'HASH') {
8801: if ($settings{$role}{'access'} ne '') {
8802: $indomvis = ' style="display:none"';
8803: $incrsvis = ' style="display:block"';
8804: $incrscheck = ' checked="checked"';
8805: if ($settings{$role}{'access'} ne 'all') {
8806: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
8807: delete($usecheck{'all'});
8808: if ($settings{$role}{'access'} eq 'status') {
8809: my $access = 'status';
8810: $displaydiv{$access} = 'inline';
8811: if (ref($settings{$role}{$access}) eq 'ARRAY') {
8812: $selected{$access} = $settings{$role}{$access};
8813: }
8814: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
8815: my $access = $1;
8816: $displaydiv{$access} = 'inline';
8817: if (ref($settings{$role}{$access}) eq 'ARRAY') {
8818: $selected{$access} = $settings{$role}{$access};
8819: }
8820: } elsif ($settings{$role}{'access'} eq 'none') {
8821: $displaydiv{'priv'} = 'none';
8822: }
8823: }
8824: } else {
8825: $indomcheck = ' checked="checked"';
8826: $indomvis = ' style="display:block"';
8827: $incrsvis = ' style="display:none"';
8828: }
8829: } else {
8830: $indomcheck = ' checked="checked"';
8831: $indomvis = ' style="display:block"';
8832: $incrsvis = ' style="display:none"';
8833: }
8834: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
8835: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
8836: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
8837: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
8838: &mt('Set here in [_1]',lc($crstype)).'</label>'.
8839: '<span>'.(' 'x2).
8840: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
8841: $lt{'udd'}.'</label><span></p>'.
8842: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
8843: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
8844: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
8845: foreach my $access (@accesstypes) {
8846: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
8847: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
8848: if ($access eq 'status') {
8849: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
8850: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
8851: $othertitle,$usertypes,$types,$disabled).
8852: '</div>');
8853: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
8854: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
8855: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
8856: \%domhelpdesk,$disabled).
8857: '</div>');
8858: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
8859: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
8860: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
8861: \%domhelpdesk,$disabled).
8862: '</div>');
8863: }
8864: $r->print('</p>');
8865: }
8866: $r->print('</div></fieldset>');
8867: my %full=();
8868: my %levels= (
8869: course => {},
8870: domain => {},
8871: system => {},
8872: );
8873: my %levelscurrent=(
8874: course => {},
8875: domain => {},
8876: system => {},
8877: );
8878: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8879: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
8880: '<legend>'.$lt{'rpr'}.'</legend>'.
8881: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
8882: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
8883: }
8884: if ($permission->{'owner'}) {
8885: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
8886: }
8887: } else {
8888: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
8889: }
8890: # Form Footer
8891: $r->print('<input type="hidden" name="action" value="helpdesk" />'
8892: .'</form>');
8893: return;
8894: }
8895:
8896: sub domain_adhoc_access {
8897: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
8898: my %domusage;
8899: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
8900: foreach my $role (keys(%{$roles})) {
8901: if (ref($domcurrent->{$role}) eq 'HASH') {
8902: my $access = $domcurrent->{$role}{'access'};
8903: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
8904: $access = 'all';
1.406.2.12 raeburn 8905: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
8906: &Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 8907: } elsif ($access eq 'status') {
8908: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
8909: my @shown;
8910: foreach my $type (@{$domcurrent->{$role}{$access}}) {
8911: unless ($type eq 'default') {
8912: if ($usertypes->{$type}) {
8913: push(@shown,$usertypes->{$type});
8914: }
8915: }
8916: }
8917: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
8918: push(@shown,$othertitle);
8919: }
8920: if (@shown) {
8921: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.406.2.12 raeburn 8922: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
8923: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.406.2.10 raeburn 8924: } else {
8925: $domusage{$role} = &mt('No one in the domain');
8926: }
8927: }
8928: } elsif ($access eq 'inc') {
8929: my @dominc = ();
8930: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
8931: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
8932: my ($uname,$udom) = split(/:/,$user);
8933: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
8934: }
8935: my $showninc = join(', ',@dominc);
8936: if ($showninc ne '') {
1.406.2.12 raeburn 8937: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
8938: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.406.2.10 raeburn 8939: } else {
1.406.2.12 raeburn 8940: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8941: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 8942: }
8943: }
8944: } elsif ($access eq 'exc') {
8945: my @domexc = ();
8946: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
8947: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
8948: my ($uname,$udom) = split(/:/,$user);
8949: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
8950: }
8951: }
8952: my $shownexc = join(', ',@domexc);
8953: if ($shownexc ne '') {
1.406.2.12 raeburn 8954: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
8955: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.406.2.10 raeburn 8956: } else {
8957: $domusage{$role} = &mt('No one in the domain');
8958: }
8959: } elsif ($access eq 'none') {
8960: $domusage{$role} = &mt('No one in the domain');
1.406.2.12 raeburn 8961: } elsif ($access eq 'dh') {
1.406.2.10 raeburn 8962: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.406.2.12 raeburn 8963: } elsif ($access eq 'da') {
8964: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
8965: } elsif ($access eq 'all') {
8966: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8967: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 8968: }
8969: } else {
1.406.2.12 raeburn 8970: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8971: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 8972: }
8973: }
8974: return %domusage;
8975: }
8976:
8977: sub get_domain_customroles {
8978: my ($cdom,$confname) = @_;
8979: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
8980: my %customroles;
8981: foreach my $key (keys(%existing)) {
8982: if ($key=~/^rolesdef\_(\w+)$/) {
8983: my $rolename = $1;
8984: my %privs;
8985: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
8986: $customroles{$rolename} = \%privs;
8987: }
8988: }
8989: return %customroles;
8990: }
8991:
8992: sub role_priv_table {
8993: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
8994: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
8995: (ref($levelscurrent) eq 'HASH'));
8996: my %lt=&Apache::lonlocal::texthash (
8997: 'crl' => 'Course Level Privilege',
8998: 'def' => 'Domain Defaults',
8999: 'ove' => 'Override in Course',
9000: 'ine' => 'In effect',
9001: 'dis' => 'Disabled',
9002: 'ena' => 'Enabled',
9003: );
9004: if ($crstype eq 'Community') {
9005: $lt{'ove'} = 'Override in Community',
9006: }
9007: my @status = ('Disabled','Enabled');
9008: my (%on,%off);
9009: if (ref($overridden) eq 'HASH') {
9010: if (ref($overridden->{'on'}) eq 'ARRAY') {
9011: map { $on{$_} = 1; } (@{$overridden->{'on'}});
9012: }
9013: if (ref($overridden->{'off'}) eq 'ARRAY') {
9014: map { $off{$_} = 1; } (@{$overridden->{'off'}});
9015: }
9016: }
9017: my $output=&Apache::loncommon::start_data_table().
9018: &Apache::loncommon::start_data_table_header_row().
9019: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
9020: '</th><th>'.$lt{'ine'}.'</th>'.
9021: &Apache::loncommon::end_data_table_header_row();
9022: foreach my $priv (sort(keys(%{$full}))) {
9023: next unless ($levels->{'course'}{$priv});
9024: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
9025: my ($default,$ineffect);
9026: if ($levelscurrent->{'course'}{$priv}) {
9027: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
9028: $ineffect = $default;
9029: }
9030: my ($customstatus,$checked);
9031: $output .= &Apache::loncommon::start_data_table_row().
9032: '<td>'.$privtext.'</td>'.
9033: '<td>'.$default.'</td><td>';
9034: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
9035: if ($permission->{'owner'}) {
9036: $checked = ' checked="checked"';
9037: }
9038: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
9039: $ineffect = $customstatus;
9040: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
9041: if ($permission->{'owner'}) {
9042: $checked = ' checked="checked"';
9043: }
9044: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
9045: $ineffect = $customstatus;
9046: }
9047: if ($permission->{'owner'}) {
9048: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
9049: } else {
9050: $output .= $customstatus;
9051: }
9052: $output .= '</td><td>'.$ineffect.'</td>'.
9053: &Apache::loncommon::end_data_table_row();
9054: }
9055: $output .= &Apache::loncommon::end_data_table();
9056: return $output;
9057: }
9058:
9059: sub get_adhocrole_settings {
9060: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
9061: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
9062: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
9063: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
9064: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
9065: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
9066: $settings->{$role}{'access'} = $curraccess;
9067: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
9068: my @status = split(/,/,$rest);
9069: my @currstatus;
9070: foreach my $type (@status) {
9071: if ($type eq 'default') {
9072: push(@currstatus,$type);
9073: } elsif (grep(/^\Q$type\E$/,@{$types})) {
9074: push(@currstatus,$type);
9075: }
9076: }
9077: if (@currstatus) {
9078: $settings->{$role}{$curraccess} = \@currstatus;
9079: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
9080: my @personnel = split(/,/,$rest);
9081: $settings->{$role}{$curraccess} = \@personnel;
9082: }
9083: }
9084: }
9085: }
9086: foreach my $role (keys(%{$customroles})) {
9087: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
9088: my %currentprivs;
9089: if (ref($customroles->{$role}) eq 'HASH') {
9090: if (exists($customroles->{$role}{'course'})) {
9091: my %full=();
9092: my %levels= (
9093: course => {},
9094: domain => {},
9095: system => {},
9096: );
9097: my %levelscurrent=(
9098: course => {},
9099: domain => {},
9100: system => {},
9101: );
9102: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
9103: %currentprivs = %{$levelscurrent{'course'}};
9104: }
9105: }
9106: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
9107: next if ($item eq '');
9108: my ($rule,$rest) = split(/=/,$item);
9109: next unless (($rule eq 'off') || ($rule eq 'on'));
9110: foreach my $priv (split(/:/,$rest)) {
9111: if ($priv ne '') {
9112: if ($rule eq 'off') {
9113: push(@{$overridden->{$role}{'off'}},$priv);
9114: if ($currentprivs{$priv}) {
9115: push(@{$settings->{$role}{'off'}},$priv);
9116: }
9117: } else {
9118: push(@{$overridden->{$role}{'on'}},$priv);
9119: unless ($currentprivs{$priv}) {
9120: push(@{$settings->{$role}{'on'}},$priv);
9121: }
9122: }
9123: }
9124: }
9125: }
9126: }
9127: }
9128: return;
9129: }
9130:
9131: sub update_helpdeskaccess {
9132: my ($r,$permission,$brcrum) = @_;
9133: my $helpitem = 'Course_Helpdesk_Access';
9134: push (@{$brcrum},
9135: {href => '/adm/createuser?action=helpdesk',
9136: text => 'Helpdesk Access',
9137: help => $helpitem},
9138: {href => '/adm/createuser?action=helpdesk',
9139: text => 'Result',
9140: help => $helpitem}
9141: );
9142: my $bread_crumbs_component = 'Helpdesk Staff Access';
9143: my $args = { bread_crumbs => $brcrum,
9144: bread_crumbs_component => $bread_crumbs_component};
9145:
9146: # print page header
9147: $r->print(&header('',$args));
9148: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
9149: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
9150: return;
9151: }
1.406.2.12 raeburn 9152: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.406.2.10 raeburn 9153: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9154: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9155: my $confname = $cdom.'-domainconfig';
9156: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
9157: my $crstype = &Apache::loncommon::course_type();
9158: my %customroles = &get_domain_customroles($cdom,$confname);
9159: my (%settings,%overridden);
9160: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
9161: $types,\%customroles,\%settings,\%overridden);
1.406.2.12 raeburn 9162: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 9163: my (%changed,%storehash,@todelete);
9164:
9165: if (keys(%customroles)) {
9166: my (%newsettings,@incrs);
9167: foreach my $role (keys(%customroles)) {
9168: $newsettings{$role} = {
9169: access => '',
9170: status => '',
9171: exc => '',
9172: inc => '',
9173: on => '',
9174: off => '',
9175: };
9176: my %current;
9177: if (ref($settings{$role}) eq 'HASH') {
9178: %current = %{$settings{$role}};
9179: }
9180: if (ref($overridden{$role}) eq 'HASH') {
9181: $current{'overridden'} = $overridden{$role};
9182: }
9183: if ($env{'form.'.$role.'_incrs'}) {
9184: my $access = $env{'form.'.$role.'_access'};
9185: if (grep(/^\Q$access\E$/,@accesstypes)) {
9186: push(@incrs,$role);
9187: unless ($current{'access'} eq $access) {
9188: $changed{$role}{'access'} = 1;
9189: $storehash{'internal.adhoc.'.$role} = $access;
9190: }
9191: if ($access eq 'status') {
9192: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
9193: my @stored;
9194: my @shownstatus;
9195: if (ref($types) eq 'ARRAY') {
9196: foreach my $type (sort(@statuses)) {
9197: if ($type eq 'default') {
9198: push(@stored,$type);
9199: } elsif (grep(/^\Q$type\E$/,@{$types})) {
9200: push(@stored,$type);
9201: push(@shownstatus,$usertypes->{$type});
9202: }
9203: }
9204: if (grep(/^default$/,@statuses)) {
9205: push(@shownstatus,$othertitle);
9206: }
9207: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
9208: }
9209: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
9210: if (ref($current{'status'}) eq 'ARRAY') {
9211: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
9212: if (@diffs) {
9213: $changed{$role}{'status'} = 1;
9214: }
9215: } elsif (@stored) {
9216: $changed{$role}{'status'} = 1;
9217: }
9218: } elsif (($access eq 'inc') || ($access eq 'exc')) {
9219: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
9220: my @newspecstaff;
9221: my @stored;
9222: my @currstaff;
9223: foreach my $person (sort(@personnel)) {
9224: if ($domhelpdesk{$person}) {
9225: push(@stored,$person);
9226: }
9227: }
9228: if (ref($current{$access}) eq 'ARRAY') {
9229: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
9230: if (@diffs) {
9231: $changed{$role}{$access} = 1;
9232: }
9233: } elsif (@stored) {
9234: $changed{$role}{$access} = 1;
9235: }
9236: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
9237: foreach my $person (@stored) {
9238: my ($uname,$udom) = split(/:/,$person);
9239: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
9240: }
9241: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
9242: }
9243: $newsettings{$role}{'access'} = $access;
9244: }
9245: } else {
9246: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
9247: $changed{$role}{'access'} = 1;
9248: $newsettings{$role} = {};
9249: push(@todelete,'internal.adhoc.'.$role);
9250: }
9251: }
9252: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
9253: if (ref($current{'overridden'}) eq 'HASH') {
9254: push(@todelete,'internal.adhocpriv.'.$role);
9255: }
9256: } else {
9257: my %full=();
9258: my %levels= (
9259: course => {},
9260: domain => {},
9261: system => {},
9262: );
9263: my %levelscurrent=(
9264: course => {},
9265: domain => {},
9266: system => {},
9267: );
9268: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
9269: my (@updatedon,@updatedoff,@override);
9270: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
9271: if (@override) {
9272: foreach my $priv (sort(keys(%full))) {
9273: next unless ($levels{'course'}{$priv});
9274: if (grep(/^\Q$priv\E$/,@override)) {
9275: if ($levelscurrent{'course'}{$priv}) {
9276: push(@updatedoff,$priv);
9277: } else {
9278: push(@updatedon,$priv);
9279: }
9280: }
9281: }
9282: }
9283: if (@updatedon) {
9284: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
9285: }
9286: if (@updatedoff) {
9287: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
9288: }
9289: if (ref($current{'overridden'}) eq 'HASH') {
9290: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
9291: if (@updatedon) {
9292: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
9293: if (@diffs) {
9294: $changed{$role}{'on'} = 1;
9295: }
9296: } else {
9297: $changed{$role}{'on'} = 1;
9298: }
9299: } elsif (@updatedon) {
9300: $changed{$role}{'on'} = 1;
9301: }
9302: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
9303: if (@updatedoff) {
9304: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
9305: if (@diffs) {
9306: $changed{$role}{'off'} = 1;
9307: }
9308: } else {
9309: $changed{$role}{'off'} = 1;
9310: }
9311: } elsif (@updatedoff) {
9312: $changed{$role}{'off'} = 1;
9313: }
9314: } else {
9315: if (@updatedon) {
9316: $changed{$role}{'on'} = 1;
9317: }
9318: if (@updatedoff) {
9319: $changed{$role}{'off'} = 1;
9320: }
9321: }
9322: if (ref($changed{$role}) eq 'HASH') {
9323: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
9324: my $newpriv;
9325: if (@updatedon) {
9326: $newpriv = 'on='.join(':',@updatedon);
9327: }
9328: if (@updatedoff) {
9329: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
9330: }
9331: if ($newpriv eq '') {
9332: push(@todelete,'internal.adhocpriv.'.$role);
9333: } else {
9334: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
9335: }
9336: }
9337: }
9338: }
9339: }
9340: if (@incrs) {
9341: $storehash{'internal.adhocaccess'} = join(',',@incrs);
9342: } elsif (@todelete) {
9343: push(@todelete,'internal.adhocaccess');
9344: }
9345: if (keys(%changed)) {
9346: my ($putres,$delres);
9347: if (keys(%storehash)) {
9348: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
9349: my %newenvhash;
9350: foreach my $key (keys(%storehash)) {
9351: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
9352: }
9353: &Apache::lonnet::appenv(\%newenvhash);
9354: }
9355: if (@todelete) {
9356: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
9357: foreach my $key (@todelete) {
9358: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
9359: }
9360: }
9361: if (($putres eq 'ok') || ($delres eq 'ok')) {
9362: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
9363: my (%domcurrent,%ordered,%description,%domusage);
9364: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9365: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
9366: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
9367: }
9368: }
9369: my $count = 0;
9370: foreach my $role (sort(keys(%customroles))) {
9371: my ($order,$desc);
9372: if (ref($domcurrent{$role}) eq 'HASH') {
9373: $order = $domcurrent{$role}{'order'};
9374: $desc = $domcurrent{$role}{'desc'};
9375: }
9376: if ($order eq '') {
9377: $order = $count;
9378: }
9379: $ordered{$order} = $role;
9380: if ($desc ne '') {
9381: $description{$role} = $desc;
9382: } else {
9383: $description{$role}= $role;
9384: }
9385: $count++;
9386: }
9387: my @roles_by_num = ();
9388: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
9389: push(@roles_by_num,$ordered{$item});
9390: }
9391: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
9392: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
9393: $r->print('<ul>');
9394: foreach my $role (@roles_by_num) {
9395: next unless (ref($changed{$role}) eq 'HASH');
9396: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
9397: '<ul>');
9398: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
9399: $r->print('<li>');
9400: if ($env{'form.'.$role.'_incrs'}) {
9401: if ($newsettings{$role}{'access'} eq 'all') {
9402: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.406.2.12 raeburn 9403: } elsif ($newsettings{$role}{'access'} eq 'dh') {
9404: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
9405: &Apache::lonnet::plaintext('dh')));
9406: } elsif ($newsettings{$role}{'access'} eq 'da') {
9407: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
9408: &Apache::lonnet::plaintext('da')));
1.406.2.10 raeburn 9409: } elsif ($newsettings{$role}{'access'} eq 'none') {
9410: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9411: } elsif ($newsettings{$role}{'access'} eq 'status') {
9412: if ($newsettings{$role}{'status'}) {
9413: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
9414: if (split(/,/,$rest) > 1) {
9415: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
9416: $newsettings{$role}{'status'}));
9417: } else {
9418: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
9419: $newsettings{$role}{'status'}));
9420: }
9421: } else {
9422: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9423: }
9424: } elsif ($newsettings{$role}{'access'} eq 'exc') {
9425: if ($newsettings{$role}{'exc'}) {
9426: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
9427: } else {
9428: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9429: }
9430: } elsif ($newsettings{$role}{'access'} eq 'inc') {
9431: if ($newsettings{$role}{'inc'}) {
9432: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
9433: } else {
9434: $r->print(&mt('All helpdesk staff may use this role.'));
9435: }
9436: }
9437: } else {
9438: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
9439: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
9440: }
9441: $r->print('</li>');
9442: }
9443: unless ($newsettings{$role}{'access'} eq 'none') {
9444: if ($changed{$role}{'off'}) {
9445: if ($newsettings{$role}{'off'}) {
9446: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
9447: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
9448: } else {
9449: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
9450: }
9451: }
9452: if ($changed{$role}{'on'}) {
9453: if ($newsettings{$role}{'on'}) {
9454: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
9455: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
9456: } else {
9457: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
9458: }
9459: }
9460: }
9461: $r->print('</ul></li>');
9462: }
9463: $r->print('</ul>');
9464: }
9465: } else {
9466: $r->print(&mt('No changes made to helpdesk access settings.'));
9467: }
9468: }
9469: return;
9470: }
9471:
1.27 matthew 9472: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 9473: sub user_search_result {
1.221 raeburn 9474: my ($context,$srch) = @_;
1.160 raeburn 9475: my %allhomes;
9476: my %inst_matches;
9477: my %srch_results;
1.181 raeburn 9478: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 9479: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 9480: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 9481: $response = &mt('Invalid search.');
9482: }
9483: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
9484: $response = &mt('Invalid search.');
9485: }
1.177 raeburn 9486: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 9487: $response = &mt('Invalid search.');
9488: }
9489: if ($srch->{'srchterm'} eq '') {
9490: $response = &mt('You must enter a search term.');
9491: }
1.183 raeburn 9492: if ($srch->{'srchterm'} =~ /^\s+$/) {
9493: $response = &mt('Your search term must contain more than just spaces.');
9494: }
1.160 raeburn 9495: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
9496: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 9497: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 9498: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
9499: }
9500: }
9501: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
9502: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 9503: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 9504: my $unamecheck = $srch->{'srchterm'};
9505: if ($srch->{'srchtype'} eq 'contains') {
9506: if ($unamecheck !~ /^\w/) {
9507: $unamecheck = 'a'.$unamecheck;
9508: }
9509: }
9510: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 9511: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
9512: }
1.160 raeburn 9513: }
9514: }
1.180 raeburn 9515: if ($response ne '') {
1.406.2.4 raeburn 9516: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 9517: }
1.160 raeburn 9518: if ($srch->{'srchin'} eq 'instd') {
1.406.2.3 raeburn 9519: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 9520: if ($instd_chk ne 'ok') {
1.406.2.3 raeburn 9521: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.4 raeburn 9522: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.406.2.3 raeburn 9523: if ($domd_chk eq 'ok') {
1.406.2.4 raeburn 9524: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.406.2.3 raeburn 9525: }
1.406.2.5 raeburn 9526: $response .= '<br />';
1.406.2.3 raeburn 9527: }
9528: } else {
9529: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
9530: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.14 raeburn 9531: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.406.2.3 raeburn 9532: my $instd_chk = &instdirectorysrch_check($srch);
1.406.2.4 raeburn 9533: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.406.2.3 raeburn 9534: if ($instd_chk eq 'ok') {
1.406.2.4 raeburn 9535: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.406.2.3 raeburn 9536: }
1.406.2.5 raeburn 9537: $response .= '<br />';
1.406.2.3 raeburn 9538: }
1.160 raeburn 9539: }
9540: }
9541: if ($response ne '') {
1.180 raeburn 9542: return ($currstate,$response);
1.160 raeburn 9543: }
9544: if ($srch->{'srchby'} eq 'uname') {
9545: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
9546: if ($env{'form.forcenew'}) {
9547: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
9548: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
9549: if ($uhome eq 'no_host') {
9550: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 9551: my $showdom = &display_domain_info($env{'request.role.domain'});
9552: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 9553: } else {
1.179 raeburn 9554: $currstate = 'modify';
1.160 raeburn 9555: }
9556: } else {
1.179 raeburn 9557: $currstate = 'modify';
1.160 raeburn 9558: }
9559: } else {
9560: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 9561: if ($srch->{'srchtype'} eq 'exact') {
9562: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
9563: if ($uhome eq 'no_host') {
1.179 raeburn 9564: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9565: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 9566: } else {
1.179 raeburn 9567: $currstate = 'modify';
1.406.2.5 raeburn 9568: if ($env{'form.action'} eq 'accesslogs') {
9569: $currstate = 'activity';
9570: }
1.310 raeburn 9571: my $uname = $srch->{'srchterm'};
9572: my $udom = $srch->{'srchdomain'};
9573: $srch_results{$uname.':'.$udom} =
9574: { &Apache::lonnet::get('environment',
9575: ['firstname',
9576: 'lastname',
9577: 'permanentemail'],
9578: $udom,$uname)
9579: };
1.162 raeburn 9580: }
9581: } else {
9582: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 9583: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9584: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9585: }
9586: } else {
1.167 albertel 9587: my $courseusers = &get_courseusers();
1.162 raeburn 9588: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 9589: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 9590: $currstate = 'modify';
1.162 raeburn 9591: } else {
1.179 raeburn 9592: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9593: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 9594: }
1.160 raeburn 9595: } else {
1.167 albertel 9596: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 9597: my ($cuname,$cudomain) = split(/:/,$user);
9598: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 9599: my $matched = 0;
9600: if ($srch->{'srchtype'} eq 'begins') {
9601: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
9602: $matched = 1;
9603: }
9604: } else {
9605: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
9606: $matched = 1;
9607: }
9608: }
9609: if ($matched) {
1.167 albertel 9610: $srch_results{$user} =
9611: {&Apache::lonnet::get('environment',
9612: ['firstname',
9613: 'lastname',
1.194 albertel 9614: 'permanentemail'],
9615: $cudomain,$cuname)};
1.162 raeburn 9616: }
9617: }
9618: }
1.179 raeburn 9619: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9620: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9621: }
9622: }
9623: }
9624: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 9625: $currstate = 'query';
1.160 raeburn 9626: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 9627: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
9628: if ($dirsrchres eq 'ok') {
9629: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9630: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 9631: } else {
9632: my $showdom = &display_domain_info($srch->{'srchdomain'});
9633: $response = '<span class="LC_warning">'.
9634: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
9635: '</span><br />'.
9636: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 9637: '<br />';
1.181 raeburn 9638: }
1.160 raeburn 9639: }
9640: } else {
9641: if ($srch->{'srchin'} eq 'dom') {
9642: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 9643: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9644: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9645: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 9646: my $courseusers = &get_courseusers();
9647: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 9648: my ($uname,$udom) = split(/:/,$user);
9649: my %names = &Apache::loncommon::getnames($uname,$udom);
9650: my %emails = &Apache::loncommon::getemails($uname,$udom);
9651: if ($srch->{'srchby'} eq 'lastname') {
9652: if ((($srch->{'srchtype'} eq 'exact') &&
9653: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 9654: (($srch->{'srchtype'} eq 'begins') &&
9655: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 9656: (($srch->{'srchtype'} eq 'contains') &&
9657: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
9658: $srch_results{$user} = {firstname => $names{'firstname'},
9659: lastname => $names{'lastname'},
9660: permanentemail => $emails{'permanentemail'},
9661: };
9662: }
9663: } elsif ($srch->{'srchby'} eq 'lastfirst') {
9664: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 9665: $srchlast =~ s/\s+$//;
9666: $srchfirst =~ s/^\s+//;
1.160 raeburn 9667: if ($srch->{'srchtype'} eq 'exact') {
9668: if (($names{'lastname'} eq $srchlast) &&
9669: ($names{'firstname'} eq $srchfirst)) {
9670: $srch_results{$user} = {firstname => $names{'firstname'},
9671: lastname => $names{'lastname'},
9672: permanentemail => $emails{'permanentemail'},
9673:
9674: };
9675: }
1.177 raeburn 9676: } elsif ($srch->{'srchtype'} eq 'begins') {
9677: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
9678: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
9679: $srch_results{$user} = {firstname => $names{'firstname'},
9680: lastname => $names{'lastname'},
9681: permanentemail => $emails{'permanentemail'},
9682: };
9683: }
9684: } else {
1.160 raeburn 9685: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
9686: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
9687: $srch_results{$user} = {firstname => $names{'firstname'},
9688: lastname => $names{'lastname'},
9689: permanentemail => $emails{'permanentemail'},
9690: };
9691: }
9692: }
9693: }
9694: }
1.179 raeburn 9695: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9696: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9697: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 9698: $currstate = 'query';
1.160 raeburn 9699: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 9700: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
9701: if ($dirsrchres eq 'ok') {
9702: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9703: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 9704: } else {
1.406.2.5 raeburn 9705: my $showdom = &display_domain_info($srch->{'srchdomain'});
9706: $response = '<span class="LC_warning">'.
1.181 raeburn 9707: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
9708: '</span><br />'.
9709: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 9710: '<br />';
1.181 raeburn 9711: }
1.160 raeburn 9712: }
9713: }
1.179 raeburn 9714: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 9715: }
9716:
1.406.2.3 raeburn 9717: sub domdirectorysrch_check {
9718: my ($srch) = @_;
9719: my $response;
9720: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
9721: ['directorysrch'],$srch->{'srchdomain'});
9722: my $showdom = &display_domain_info($srch->{'srchdomain'});
9723: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
9724: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
9725: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
9726: }
9727: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
9728: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
9729: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
9730: }
9731: }
9732: }
9733: return 'ok';
9734: }
9735:
9736: sub instdirectorysrch_check {
1.160 raeburn 9737: my ($srch) = @_;
9738: my $can_search = 0;
9739: my $response;
9740: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
9741: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 9742: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 9743: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
9744: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 9745: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 9746: }
9747: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
9748: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 9749: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 9750: }
9751: my @usertypes = split(/:/,$env{'environment.inststatus'});
9752: if (!@usertypes) {
9753: push(@usertypes,'default');
9754: }
9755: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
9756: foreach my $type (@usertypes) {
9757: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
9758: $can_search = 1;
9759: last;
9760: }
9761: }
9762: }
9763: if (!$can_search) {
9764: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
9765: my @longtypes;
9766: foreach my $item (@usertypes) {
1.229 raeburn 9767: if (defined($insttypes->{$item})) {
9768: push (@longtypes,$insttypes->{$item});
9769: } elsif ($item eq 'default') {
9770: push (@longtypes,&mt('other'));
9771: }
1.160 raeburn 9772: }
9773: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 9774: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 9775: }
1.160 raeburn 9776: } else {
9777: $can_search = 1;
9778: }
9779: } else {
1.180 raeburn 9780: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 9781: }
9782: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 9783: uname => 'username',
1.160 raeburn 9784: lastfirst => 'last name, first name',
1.167 albertel 9785: lastname => 'last name',
1.172 raeburn 9786: contains => 'contains',
1.178 raeburn 9787: exact => 'as exact match to',
9788: begins => 'begins with',
1.160 raeburn 9789: );
9790: if ($can_search) {
9791: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
9792: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 9793: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 9794: }
9795: } else {
1.180 raeburn 9796: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 9797: }
9798: }
9799: if ($can_search) {
1.178 raeburn 9800: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
9801: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
9802: return 'ok';
9803: } else {
1.180 raeburn 9804: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 9805: }
9806: } else {
9807: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
9808: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
9809: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
9810: return 'ok';
9811: } else {
1.180 raeburn 9812: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 9813: }
1.160 raeburn 9814: }
9815: }
9816: }
9817:
9818: sub get_courseusers {
9819: my %advhash;
1.167 albertel 9820: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 9821: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
9822: foreach my $role (sort(keys(%coursepersonnel))) {
9823: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 9824: if (!exists($classlist->{$user})) {
9825: $classlist->{$user} = [];
9826: }
1.160 raeburn 9827: }
9828: }
1.167 albertel 9829: return $classlist;
1.160 raeburn 9830: }
9831:
9832: sub build_search_response {
1.221 raeburn 9833: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 9834: my ($currstate,$response,$forcenewuser);
1.160 raeburn 9835: my %names = (
1.330 bisitz 9836: 'uname' => 'username',
9837: 'lastname' => 'last name',
1.160 raeburn 9838: 'lastfirst' => 'last name, first name',
1.330 bisitz 9839: 'crs' => 'this course',
9840: 'dom' => 'LON-CAPA domain',
9841: 'instd' => 'the institutional directory for domain',
1.160 raeburn 9842: );
9843:
9844: my %single = (
1.180 raeburn 9845: begins => 'A match',
1.160 raeburn 9846: contains => 'A match',
1.180 raeburn 9847: exact => 'An exact match',
1.160 raeburn 9848: );
9849: my %nomatch = (
1.180 raeburn 9850: begins => 'No match',
1.160 raeburn 9851: contains => 'No match',
1.180 raeburn 9852: exact => 'No exact match',
1.160 raeburn 9853: );
9854: if (keys(%srch_results) > 1) {
1.179 raeburn 9855: $currstate = 'select';
1.160 raeburn 9856: } else {
9857: if (keys(%srch_results) == 1) {
1.406.2.5 raeburn 9858: if ($env{'form.action'} eq 'accesslogs') {
9859: $currstate = 'activity';
9860: } else {
9861: $currstate = 'modify';
9862: }
1.180 raeburn 9863: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
9864: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 9865: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 9866: }
1.330 bisitz 9867: } else { # Search has nothing found. Prepare message to user.
9868: $response = '<span class="LC_warning">';
1.180 raeburn 9869: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 9870: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
9871: '<b>'.$srch->{'srchterm'}.'</b>',
9872: &display_domain_info($srch->{'srchdomain'}));
9873: } else {
9874: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
9875: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 9876: }
9877: $response .= '</span>';
1.330 bisitz 9878:
1.160 raeburn 9879: if ($srch->{'srchin'} ne 'alc') {
9880: $forcenewuser = 1;
9881: my $cansrchinst = 0;
1.406.2.14 raeburn 9882: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 9883: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
9884: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9885: if ($domconfig{'directorysrch'}{'available'}) {
9886: $cansrchinst = 1;
9887: }
9888: }
9889: }
1.180 raeburn 9890: if ((($srch->{'srchby'} eq 'lastfirst') ||
9891: ($srch->{'srchby'} eq 'lastname')) &&
9892: ($srch->{'srchin'} eq 'dom')) {
9893: if ($cansrchinst) {
9894: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 9895: }
9896: }
1.180 raeburn 9897: if ($srch->{'srchin'} eq 'crs') {
9898: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
9899: }
9900: }
1.305 raeburn 9901: my $createdom = $env{'request.role.domain'};
9902: if ($context eq 'requestcrs') {
9903: if ($env{'form.coursedom'} ne '') {
9904: $createdom = $env{'form.coursedom'};
9905: }
9906: }
1.406.2.5 raeburn 9907: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
9908: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 9909: my $cancreate =
1.305 raeburn 9910: &Apache::lonuserutils::can_create_user($createdom,$context);
9911: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 9912: if ($cancreate) {
1.305 raeburn 9913: my $showdom = &display_domain_info($createdom);
1.266 bisitz 9914: $response .= '<br /><br />'
9915: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 9916: .'<br />';
9917: if ($context eq 'requestcrs') {
9918: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
9919: } else {
9920: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
9921: }
9922: $response .='<ul><li>'
1.266 bisitz 9923: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
9924: .'</li><li>'
9925: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
9926: .'</li><li>'
9927: .&mt('Provide the proposed username')
9928: .'</li><li>'
9929: .&mt("Click 'Search'")
9930: .'</li></ul><br />';
1.221 raeburn 9931: } else {
1.406.2.7 raeburn 9932: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
9933: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
9934: $response .= '<br /><br />';
9935: if ($context eq 'requestcrs') {
9936: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
9937: } else {
9938: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
9939: }
9940: $response .= '<br />'
9941: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
9942: ,' <a'.$helplink.'>'
9943: ,'</a>')
9944: .'<br />';
1.305 raeburn 9945: }
1.221 raeburn 9946: }
1.160 raeburn 9947: }
9948: }
9949: }
1.179 raeburn 9950: return ($currstate,$response,$forcenewuser);
1.160 raeburn 9951: }
9952:
1.180 raeburn 9953: sub display_domain_info {
9954: my ($dom) = @_;
9955: my $output = $dom;
9956: if ($dom ne '') {
9957: my $domdesc = &Apache::lonnet::domain($dom,'description');
9958: if ($domdesc ne '') {
9959: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
9960: }
9961: }
9962: return $output;
9963: }
9964:
1.160 raeburn 9965: sub crumb_utilities {
9966: my %elements = (
9967: crtuser => {
9968: srchterm => 'text',
1.172 raeburn 9969: srchin => 'selectbox',
1.160 raeburn 9970: srchby => 'selectbox',
9971: srchtype => 'selectbox',
9972: srchdomain => 'selectbox',
9973: },
1.207 raeburn 9974: crtusername => {
9975: srchterm => 'text',
9976: srchdomain => 'selectbox',
9977: },
1.160 raeburn 9978: docustom => {
9979: rolename => 'selectbox',
9980: newrolename => 'textbox',
9981: },
1.179 raeburn 9982: studentform => {
9983: srchterm => 'text',
9984: srchin => 'selectbox',
9985: srchby => 'selectbox',
9986: srchtype => 'selectbox',
9987: srchdomain => 'selectbox',
9988: },
1.160 raeburn 9989: );
9990:
9991: my $jsback .= qq|
9992: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 9993: if (typeof prevphase == 'undefined') {
9994: formname.phase.value = '';
9995: }
9996: else {
9997: formname.phase.value = prevphase;
9998: }
9999: if (typeof prevstate == 'undefined') {
10000: formname.currstate.value = '';
10001: }
10002: else {
10003: formname.currstate.value = prevstate;
10004: }
1.160 raeburn 10005: formname.submit();
10006: }
10007: |;
10008: return ($jsback,\%elements);
10009: }
10010:
1.26 matthew 10011: sub course_level_table {
1.375 raeburn 10012: my ($inccourses,$showcredits,$defaultcredits) = @_;
10013: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 10014: my $table = '';
1.62 www 10015: # Custom Roles?
10016:
1.190 raeburn 10017: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 10018: my %lt=&Apache::lonlocal::texthash(
10019: 'exs' => "Existing sections",
10020: 'new' => "Define new section",
10021: 'ssd' => "Set Start Date",
10022: 'sed' => "Set End Date",
1.131 raeburn 10023: 'crl' => "Course Level",
1.89 raeburn 10024: 'act' => "Activate",
10025: 'rol' => "Role",
10026: 'ext' => "Extent",
1.113 raeburn 10027: 'grs' => "Section",
1.375 raeburn 10028: 'crd' => "Credits",
1.89 raeburn 10029: 'sta' => "Start",
10030: 'end' => "End"
10031: );
1.62 www 10032:
1.375 raeburn 10033: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 10034: my $thiscourse=$protectedcourse;
1.26 matthew 10035: $thiscourse=~s:_:/:g;
10036: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 10037: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 10038: my $area=$coursedata{'description'};
1.321 raeburn 10039: my $crstype=$coursedata{'type'};
1.135 raeburn 10040: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 10041: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 10042: my %sections_count;
1.101 albertel 10043: if (defined($env{'request.course.id'})) {
10044: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 10045: %sections_count =
10046: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 10047: }
10048: }
1.321 raeburn 10049: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 10050: foreach my $role (@roles) {
1.321 raeburn 10051: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 10052: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
10053: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 10054: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 10055: $plrole,\%sections_count,\%lt,
1.402 raeburn 10056: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 10057: } elsif ($env{'request.course.sec'} ne '') {
10058: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
10059: $env{'request.course.sec'})) {
10060: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 10061: $plrole,\%sections_count,\%lt,
1.402 raeburn 10062: $showcredits,$defaultcredits,$crstype);
1.26 matthew 10063: }
10064: }
10065: }
1.221 raeburn 10066: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 10067: foreach my $cust (sort(keys(%customroles))) {
10068: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 10069: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
10070: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 10071: $cust,\%sections_count,\%lt,
10072: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 10073: }
1.62 www 10074: }
1.26 matthew 10075: }
10076: return '' if ($table eq ''); # return nothing if there is nothing
10077: # in the table
1.188 raeburn 10078: my $result;
10079: if (!$env{'request.course.id'}) {
10080: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
10081: }
10082: $result .=
1.136 raeburn 10083: &Apache::loncommon::start_data_table().
10084: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 10085: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 10086: '<th>'.$lt{'ext'}.'</th><th>'."\n";
10087: if ($showcredits) {
10088: $result .= $lt{'crd'}.'</th>';
10089: }
10090: $result .=
1.375 raeburn 10091: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
10092: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 10093: &Apache::loncommon::end_data_table_header_row().
10094: $table.
10095: &Apache::loncommon::end_data_table();
1.26 matthew 10096: return $result;
10097: }
1.88 raeburn 10098:
1.221 raeburn 10099: sub course_level_row {
1.375 raeburn 10100: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 10101: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 10102: my $creditem;
1.222 raeburn 10103: my $row = &Apache::loncommon::start_data_table_row().
10104: ' <td><input type="checkbox" name="act_'.
10105: $protectedcourse.'_'.$role.'" /></td>'."\n".
10106: ' <td>'.$plrole.'</td>'."\n".
10107: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 10108: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 10109: $row .=
10110: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
10111: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
10112: } else {
10113: $row .= '<td> </td>';
10114: }
1.322 raeburn 10115: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 10116: $row .= '<td> </td>';
1.221 raeburn 10117: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 10118: $row .= ' <td><input type="hidden" value="'.
10119: $env{'request.course.sec'}.'" '.
10120: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
10121: $env{'request.course.sec'}.'</td>';
1.221 raeburn 10122: } else {
10123: if (ref($sections_count) eq 'HASH') {
10124: my $currsec =
10125: &Apache::lonuserutils::course_sections($sections_count,
10126: $protectedcourse.'_'.$role);
1.222 raeburn 10127: $row .= '<td><table class="LC_createuser">'."\n".
10128: '<tr class="LC_section_row">'."\n".
10129: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
10130: $currsec.'</td>'."\n".
10131: ' <td> </td>'."\n".
10132: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 10133: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
10134: '" value="" />'.
10135: '<input type="hidden" '.
10136: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 10137: '</tr></table></td>'."\n";
1.221 raeburn 10138: } else {
1.222 raeburn 10139: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 10140: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 10141: }
10142: }
1.222 raeburn 10143: $row .= <<ENDTIMEENTRY;
10144: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 10145: <a href=
10146: "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 10147: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 10148: <a href=
10149: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
10150: ENDTIMEENTRY
1.222 raeburn 10151: $row .= &Apache::loncommon::end_data_table_row();
10152: return $row;
1.221 raeburn 10153: }
10154:
1.88 raeburn 10155: sub course_level_dc {
1.375 raeburn 10156: my ($dcdom,$showcredits) = @_;
1.190 raeburn 10157: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 10158: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 10159: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
10160: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 10161: '<input type="hidden" name="dccourse" value="" />';
1.355 www 10162: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 10163: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 10164: my $credit_elem;
10165: if ($showcredits) {
10166: $credit_elem = 'credits';
10167: }
10168: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 10169: my %lt=&Apache::lonlocal::texthash(
10170: 'rol' => "Role",
1.113 raeburn 10171: 'grs' => "Section",
1.88 raeburn 10172: 'exs' => "Existing sections",
10173: 'new' => "Define new section",
10174: 'sta' => "Start",
10175: 'end' => "End",
10176: 'ssd' => "Set Start Date",
1.355 www 10177: 'sed' => "Set End Date",
1.375 raeburn 10178: 'scc' => "Course/Community",
10179: 'crd' => "Credits",
1.88 raeburn 10180: );
1.323 raeburn 10181: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 10182: &Apache::loncommon::start_data_table().
10183: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 10184: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 10185: '<th>'.$lt{'grs'}.'</th>'."\n";
10186: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
10187: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 10188: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 10189: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 10190: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
10191: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 10192: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 10193: foreach my $role (@roles) {
1.135 raeburn 10194: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 10195: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 10196: }
1.404 raeburn 10197: if ( keys(%customroles) > 0) {
10198: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 10199: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 10200: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 10201: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 10202: }
10203: }
10204: $otheritems .= '</select></td><td>'.
10205: '<table border="0" cellspacing="0" cellpadding="0">'.
10206: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 10207: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 10208: '<td> </td>'.
10209: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 10210: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 10211: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 10212: '<input type="hidden" name="groups" value="" />'.
10213: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 10214: '</tr></table></td>'."\n";
10215: if ($showcredits) {
10216: $otheritems .= '<td><br />'."\n".
1.397 bisitz 10217: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 10218: }
1.88 raeburn 10219: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 10220: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 10221: <a href=
10222: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 10223: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 10224: <a href=
10225: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
10226: ENDTIMEENTRY
1.136 raeburn 10227: $otheritems .= &Apache::loncommon::end_data_table_row().
10228: &Apache::loncommon::end_data_table()."\n";
1.406.2.20.2. (raeburn 10229:): return $cb_jscript.$hiddenitems.$header.$otheritems;
1.88 raeburn 10230: }
10231:
1.237 raeburn 10232: sub update_selfenroll_config {
1.400 raeburn 10233: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 10234: return unless (ref($currsettings) eq 'HASH');
10235: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
10236: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 10237: my (%changes,%warning);
1.241 raeburn 10238: my $curr_types;
1.400 raeburn 10239: my %noedit;
10240: unless ($context eq 'domain') {
10241: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
10242: }
1.237 raeburn 10243: if (ref($row) eq 'ARRAY') {
10244: foreach my $item (@{$row}) {
1.400 raeburn 10245: next if ($noedit{$item});
1.237 raeburn 10246: if ($item eq 'enroll_dates') {
10247: my (%currenrolldate,%newenrolldate);
10248: foreach my $type ('start','end') {
1.398 raeburn 10249: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 10250: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
10251: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
10252: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
10253: }
10254: }
10255: } elsif ($item eq 'access_dates') {
10256: my (%currdate,%newdate);
10257: foreach my $type ('start','end') {
1.398 raeburn 10258: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 10259: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
10260: if ($newdate{$type} ne $currdate{$type}) {
10261: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
10262: }
10263: }
1.241 raeburn 10264: } elsif ($item eq 'types') {
1.398 raeburn 10265: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 10266: if ($env{'form.selfenroll_all'}) {
10267: if ($curr_types ne '*') {
10268: $changes{'internal.selfenroll_types'} = '*';
10269: } else {
10270: next;
10271: }
10272: } else {
1.249 raeburn 10273: my %currdoms;
1.241 raeburn 10274: my @entries = split(/;/,$curr_types);
10275: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 10276: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 10277: my $newnum = 0;
1.249 raeburn 10278: my @latesttypes;
10279: foreach my $num (@activations) {
10280: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
10281: if (@types > 0) {
1.241 raeburn 10282: @types = sort(@types);
10283: my $typestr = join(',',@types);
1.249 raeburn 10284: my $typedom = $env{'form.selfenroll_dom_'.$num};
10285: $latesttypes[$newnum] = $typedom.':'.$typestr;
10286: $currdoms{$typedom} = 1;
1.241 raeburn 10287: $newnum ++;
10288: }
10289: }
1.338 raeburn 10290: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
10291: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 10292: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
10293: if (@types > 0) {
10294: @types = sort(@types);
10295: my $typestr = join(',',@types);
10296: my $typedom = $env{'form.selfenroll_dom_'.$j};
10297: $latesttypes[$newnum] = $typedom.':'.$typestr;
10298: $currdoms{$typedom} = 1;
10299: $newnum ++;
10300: }
10301: }
10302: }
10303: if ($env{'form.selfenroll_newdom'} ne '') {
10304: my $typedom = $env{'form.selfenroll_newdom'};
10305: if ((!defined($currdoms{$typedom})) &&
10306: (&Apache::lonnet::domain($typedom) ne '')) {
10307: my $typestr;
10308: my ($othertitle,$usertypes,$types) =
10309: &Apache::loncommon::sorted_inst_types($typedom);
10310: my $othervalue = 'any';
10311: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
10312: if (@{$types} > 0) {
1.257 raeburn 10313: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 10314: $othervalue = 'other';
1.258 raeburn 10315: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 10316: }
10317: $typestr = $othervalue;
10318: } else {
10319: $typestr = $othervalue;
10320: }
10321: $latesttypes[$newnum] = $typedom.':'.$typestr;
10322: $newnum ++ ;
10323: }
10324: }
1.241 raeburn 10325: my $selfenroll_types = join(';',@latesttypes);
10326: if ($selfenroll_types ne $curr_types) {
10327: $changes{'internal.selfenroll_types'} = $selfenroll_types;
10328: }
10329: }
1.276 raeburn 10330: } elsif ($item eq 'limit') {
10331: my $newlimit = $env{'form.selfenroll_limit'};
10332: my $newcap = $env{'form.selfenroll_cap'};
10333: $newcap =~s/\s+//g;
1.398 raeburn 10334: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 10335: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 10336: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 10337: if ($newlimit ne $currlimit) {
10338: if ($newlimit ne 'none') {
10339: if ($newcap =~ /^\d+$/) {
10340: if ($newcap ne $currcap) {
10341: $changes{'internal.selfenroll_cap'} = $newcap;
10342: }
10343: $changes{'internal.selfenroll_limit'} = $newlimit;
10344: } else {
1.398 raeburn 10345: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
10346: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 10347: }
10348: } elsif ($currcap ne '') {
10349: $changes{'internal.selfenroll_cap'} = '';
10350: $changes{'internal.selfenroll_limit'} = $newlimit;
10351: }
10352: } elsif ($currlimit ne 'none') {
10353: if ($newcap =~ /^\d+$/) {
10354: if ($newcap ne $currcap) {
10355: $changes{'internal.selfenroll_cap'} = $newcap;
10356: }
10357: } else {
1.398 raeburn 10358: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
10359: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 10360: }
10361: }
10362: } elsif ($item eq 'approval') {
10363: my (@currnotified,@newnotified);
1.398 raeburn 10364: my $currapproval = $currsettings->{'selfenroll_approval'};
10365: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 10366: if ($currnotifylist ne '') {
10367: @currnotified = split(/,/,$currnotifylist);
10368: @currnotified = sort(@currnotified);
10369: }
10370: my $newapproval = $env{'form.selfenroll_approval'};
10371: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
10372: @newnotified = sort(@newnotified);
10373: if ($newapproval ne $currapproval) {
10374: $changes{'internal.selfenroll_approval'} = $newapproval;
10375: if (!$newapproval) {
10376: if ($currnotifylist ne '') {
10377: $changes{'internal.selfenroll_notifylist'} = '';
10378: }
10379: } else {
10380: my @differences =
1.295 raeburn 10381: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 10382: if (@differences > 0) {
10383: if (@newnotified > 0) {
10384: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10385: } else {
10386: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10387: }
10388: }
10389: }
10390: } else {
1.295 raeburn 10391: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 10392: if (@differences > 0) {
10393: if (@newnotified > 0) {
10394: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10395: } else {
10396: $changes{'internal.selfenroll_notifylist'} = '';
10397: }
10398: }
10399: }
1.237 raeburn 10400: } else {
1.398 raeburn 10401: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 10402: my $newval = $env{'form.selfenroll_'.$item};
10403: if ($item eq 'section') {
10404: $newval = $env{'form.sections'};
1.241 raeburn 10405: if (defined($curr_groups{$newval})) {
1.237 raeburn 10406: $newval = $curr_val;
1.398 raeburn 10407: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
10408: &mt('Group names and section names must be distinct');
1.237 raeburn 10409: } elsif ($newval eq 'all') {
10410: $newval = $curr_val;
1.274 bisitz 10411: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 10412: }
10413: if ($newval eq '') {
10414: $newval = 'none';
10415: }
10416: }
10417: if ($newval ne $curr_val) {
10418: $changes{'internal.selfenroll_'.$item} = $newval;
10419: }
1.241 raeburn 10420: }
1.237 raeburn 10421: }
10422: if (keys(%warning) > 0) {
10423: foreach my $item (@{$row}) {
10424: if (exists($warning{$item})) {
10425: $r->print($warning{$item}.'<br />');
10426: }
10427: }
10428: }
10429: if (keys(%changes) > 0) {
10430: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
10431: if ($putresult eq 'ok') {
10432: if ((exists($changes{'internal.selfenroll_types'})) ||
10433: (exists($changes{'internal.selfenroll_start_date'})) ||
10434: (exists($changes{'internal.selfenroll_end_date'}))) {
10435: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
10436: $cnum,undef,undef,'Course');
10437: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 10438: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 10439: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
10440: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 10441: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 10442: }
10443: }
10444: my $crsputresult =
10445: &Apache::lonnet::courseidput($cdom,\%crsinfo,
10446: $chome,'notime');
10447: }
10448: }
10449: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
10450: foreach my $item (@{$row}) {
10451: my $title = $item;
10452: if (ref($lt) eq 'HASH') {
10453: $title = $lt->{$item};
10454: }
10455: if ($item eq 'enroll_dates') {
10456: foreach my $type ('start','end') {
10457: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
10458: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 10459: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 10460: $title,$type,$newdate).'</li>');
10461: }
10462: }
10463: } elsif ($item eq 'access_dates') {
10464: foreach my $type ('start','end') {
10465: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
10466: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 10467: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 10468: $title,$type,$newdate).'</li>');
10469: }
10470: }
1.276 raeburn 10471: } elsif ($item eq 'limit') {
10472: if ((exists($changes{'internal.selfenroll_limit'})) ||
10473: (exists($changes{'internal.selfenroll_cap'}))) {
10474: my ($newval,$newcap);
10475: if ($changes{'internal.selfenroll_cap'} ne '') {
10476: $newcap = $changes{'internal.selfenroll_cap'}
10477: } else {
1.398 raeburn 10478: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 10479: }
10480: if ($changes{'internal.selfenroll_limit'} eq 'none') {
10481: $newval = &mt('No limit');
10482: } elsif ($changes{'internal.selfenroll_limit'} eq
10483: 'allstudents') {
10484: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
10485: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
10486: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
10487: } else {
1.398 raeburn 10488: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 10489: if ($currlimit eq 'allstudents') {
10490: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
10491: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 10492: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 10493: }
10494: }
10495: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
10496: }
10497: } elsif ($item eq 'approval') {
10498: if ((exists($changes{'internal.selfenroll_approval'})) ||
10499: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 10500: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 10501: my ($newval,$newnotify);
10502: if (exists($changes{'internal.selfenroll_notifylist'})) {
10503: $newnotify = $changes{'internal.selfenroll_notifylist'};
10504: } else {
1.398 raeburn 10505: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 10506: }
1.398 raeburn 10507: if (exists($changes{'internal.selfenroll_approval'})) {
10508: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
10509: $changes{'internal.selfenroll_approval'} = '0';
10510: }
10511: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 10512: } else {
1.398 raeburn 10513: my $currapproval = $currsettings->{'selfenroll_approval'};
10514: if ($currapproval !~ /^[012]$/) {
10515: $currapproval = 0;
1.276 raeburn 10516: }
1.398 raeburn 10517: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 10518: }
10519: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
10520: if ($newnotify) {
1.277 raeburn 10521: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 10522: } else {
1.277 raeburn 10523: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 10524: }
10525: $r->print('</li>'."\n");
10526: }
1.237 raeburn 10527: } else {
10528: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 10529: my $newval = $changes{'internal.selfenroll_'.$item};
10530: if ($item eq 'types') {
10531: if ($newval eq '') {
10532: $newval = &mt('None');
10533: } elsif ($newval eq '*') {
10534: $newval = &mt('Any user in any domain');
10535: }
1.245 raeburn 10536: } elsif ($item eq 'registered') {
10537: if ($newval eq '1') {
10538: $newval = &mt('Yes');
10539: } elsif ($newval eq '0') {
10540: $newval = &mt('No');
10541: }
1.241 raeburn 10542: }
1.244 bisitz 10543: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 10544: }
10545: }
10546: }
10547: $r->print('</ul>');
1.398 raeburn 10548: if ($env{'course.'.$cid.'.description'} ne '') {
10549: my %newenvhash;
10550: foreach my $key (keys(%changes)) {
10551: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
10552: }
10553: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 10554: }
10555: } else {
1.398 raeburn 10556: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
10557: &mt('The error was: [_1].',$putresult));
1.237 raeburn 10558: }
10559: } else {
1.249 raeburn 10560: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 10561: }
10562: } else {
1.249 raeburn 10563: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 10564: }
1.406.2.20.2. (raeburn 10565:): my $visactions = &cat_visibility($cdom);
1.400 raeburn 10566: my ($cathash,%cattype);
10567: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
10568: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
10569: $cathash = $domconfig{'coursecategories'}{'cats'};
10570: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
10571: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
10572: } else {
10573: $cathash = {};
10574: $cattype{'auth'} = 'std';
10575: $cattype{'unauth'} = 'std';
10576: }
10577: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
10578: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
10579: '<br />'.
10580: '<br />'.$visactions->{'take'}.'<ul>'.
10581: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
10582: '</ul>');
10583: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
10584: if ($currsettings->{'uniquecode'}) {
10585: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
10586: } else {
1.366 bisitz 10587: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 10588: '<br />'.
10589: '<br />'.$visactions->{'take'}.'<ul>'.
10590: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
10591: '</ul><br />');
10592: }
10593: } else {
10594: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
10595: if (ref($visactions) eq 'HASH') {
10596: if (!$visible) {
10597: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
10598: '<br />');
10599: if (ref($vismsgs) eq 'ARRAY') {
10600: $r->print('<br />'.$visactions->{'take'}.'<ul>');
10601: foreach my $item (@{$vismsgs}) {
10602: $r->print('<li>'.$visactions->{$item}.'</li>');
10603: }
10604: $r->print('</ul>');
1.256 raeburn 10605: }
1.400 raeburn 10606: $r->print($cansetvis);
1.256 raeburn 10607: }
10608: }
10609: }
1.237 raeburn 10610: return;
10611: }
10612:
1.27 matthew 10613: #---------------------------------------------- end functions for &phase_two
1.29 matthew 10614:
10615: #--------------------------------- functions for &phase_two and &phase_three
10616:
10617: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 10618:
1.1 www 10619: 1;
10620: __END__
1.2 www 10621:
10622:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>